feat: 梅花易数 + 梅花心易 算法层 v1.0

- 八卦基础数据(先天数/五行/方位/生克关系)
- 六十四卦完整数据(卦名/卦辞/象辞/吉凶/关键词)
- 体用分析引擎(动爻→体用→五行生克→旺衰判定)
- 变卦/互卦计算
- 三种起卦方式:数字法、时间法、外应法(梅花心易)
- CLI入口:JSON/文本双格式输出
- 断卦分析 prompt + 梅花心易 prompt + 海报版 prompt
- HTML海报模板(古风暗色系)
This commit is contained in:
小钰 committed 2026-08-03 07:12:25 +08:00
commit 4ff76822ad
294 files changed
+501964

No files matched your search

+89
View File
@@ -0,0 +1,89 @@
import { calculateHua } from './analysis.js';
// CLI 入口
const args = process.argv.slice(2);
function getArg(name) {
const found = args.find(a => a.startsWith(`--${name}=`));
return found ? found.split('=')[1] : undefined;
}
const method = (getArg('method') || 'time');
const question = getArg('question') || undefined;
const numbersStr = getArg('numbers');
const observation = getArg('observation') || undefined;
const trigramsStr = getArg('trigrams');
const outputFormat = getArg('output') || 'json'; // json | text
const input = { method, question };
if (method === 'number' && numbersStr) {
input.numbers = numbersStr.split(',').map(Number);
}
else if (method === 'observation') {
input.observation = observation;
if (trigramsStr) {
input.observedTrigrams = trigramsStr.split(',').map(Number);
}
}
try {
const result = calculateHua(input);
if (outputFormat === 'text') {
// 文本输出(供 LLM 阅读)
console.log(formatAsText(result));
}
else {
console.log(JSON.stringify(result, null, 2));
}
}
catch (e) {
console.error('排盘错误:', e.message);
process.exit(1);
}
function formatAsText(r) {
const main = r.mainHexagram;
const changed = r.changedHexagram;
const mutual = r.mutualHexagram;
const ti = r.tiGua;
const yong = r.yongGua;
let text = `═══════════════════════════════════
梅花易数 排盘结果
═══════════════════════════════════
【起卦方式】${r.meta.method === 'number' ? '数字起卦' : r.meta.method === 'time' ? '时间起卦' : '梅花心易(外应)'}
${r.meta.question ? `【问事】${r.meta.question}` : ''}
【起卦时间】${r.meta.timestamp}
───────────────────────────────────
主 卦
───────────────────────────────────
${main.hexagram.fullName} (${main.hexagram.symbol})
上卦:${main.upper.name}(${main.upper.element}) 下卦:${main.lower.name}(${main.lower.element})
卦辞:${main.hexagram.judgment}
象辞:${main.hexagram.image}
吉凶:${main.hexagram.nature}
───────────────────────────────────
体 用 分 析
───────────────────────────────────
动爻:第${r.dongYao}爻
体卦:${ti.trigram.name}(${ti.trigram.element}) — ${ti.position === 'upper' ? '上卦' : '下卦'}(不动之卦)
用卦:${yong.trigram.name}(${yong.trigram.element}) — ${yong.position === 'upper' ? '上卦' : '下卦'}(动爻所在)
五行关系:${r.wuxingAnalysis.relation}
判定:${r.wuxingAnalysis.verdict}
───────────────────────────────────
旺 衰
───────────────────────────────────
${r.wangShuai.analysis}
───────────────────────────────────
变 卦(趋势走向)
───────────────────────────────────
${changed.fullName} (${changed.symbol})
卦辞:${changed.judgment}
象辞:${changed.image}
───────────────────────────────────
互 卦(内在因素)
───────────────────────────────────
${mutual.fullName} (${mutual.symbol})
卦辞:${mutual.judgment}
`;
return text;
}