@metago-ai/engine 2.1.2 → 2.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BOUNDARIES.md +109 -0
- package/CHANGES.md +4 -4
- package/CONSTITUTION/AXIOMS.md +72 -110
- package/CORE/ATOMS.md +611 -0
- package/CORE/ATTRIBUTES.md +70 -101
- package/CORE/PROTOCOLS.md +134 -116
- package/ENGINE.md +6 -6
- package/ENGINES/engine-runtime.cjs +318 -0
- package/ENGINES/final-engines-runtime.cjs +683 -0
- package/ENGINES/governance-runtime.cjs +582 -0
- package/ENGINES/math-capability-runtime.cjs +451 -0
- package/ENGINES/philosophy-runtime.cjs +427 -0
- package/ENGINES/yili/data/yaoci-1.js +24 -0
- package/ENGINES/yili/data/yaoci-2.js +21 -0
- package/ENGINES/yili/data/yaoci-3.js +21 -0
- package/ENGINES/yili/data/yaoci-4.js +21 -0
- package/ENGINES/yili/data/yaoci.js +17 -0
- package/ENGINES/yili/lib/almanac.js +416 -0
- package/ENGINES/yili/lib/bazi.js +127 -0
- package/ENGINES/yili/lib/diagnose.js +71 -0
- package/ENGINES/yili/lib/hetu-luoshu.js +123 -0
- package/ENGINES/yili/lib/index.js +23 -0
- package/ENGINES/yili/lib/liuyao.js +226 -0
- package/ENGINES/yili/lib/qimen.js +167 -0
- package/ENGINES/yili/lib/shushu-calculus.js +85 -0
- package/ENGINES/yili/lib/taiyi.js +83 -0
- package/ENGINES/yili/lib/vendor/shouxing-core.js +627 -0
- package/ENGINES/yili/lib/wuxing.js +106 -0
- package/ENGINES/yili/lib/yijing.js +226 -0
- package/ENGINES/yili/lib/zeri.js +80 -0
- package/ENGINES/yili/lib/ziwei.js +145 -0
- package/ENGINES/yili/package.json +1 -0
- package/EXECUTORS.md +85 -0
- package/GENOME.json +11 -10
- package/INDEX/ENGINES.md +168 -0
- package/INDEX/engines.json +161 -161
- package/INDEX/knowledge.json +2 -2
- package/INDEX/skills.json +29 -5
- package/INDEX/tools.json +64 -64
- package/PATENTS.md +1 -1
- package/PROTOCOLS/closure-runtime.cjs +288 -0
- package/PROTOCOLS/covenant-runtime.cjs +409 -0
- package/PROTOCOLS/final-runtime.cjs +680 -0
- package/PROTOCOLS/formula-runtime.cjs +399 -0
- package/PROTOCOLS/proactive-runtime.cjs +368 -0
- package/PROTOCOLS/rule-runtime.cjs +448 -0
- package/PROTOCOLS/runtime.cjs +441 -0
- package/README.md +5 -5
- package/RUNTIME/dist/kmwi-memory.d.ts.map +1 -1
- package/RUNTIME/dist/kmwi-memory.js +14 -2
- package/RUNTIME/dist/kmwi-memory.js.map +1 -1
- package/RUNTIME/dist/validators.d.ts +2 -2
- package/RUNTIME/dist/validators.js +19 -10
- package/atoms/approx.cjs +293 -0
- package/atoms/atom-factory.cjs +550 -0
- package/atoms/atoms-cosmic-bio.cjs +340 -0
- package/atoms/atoms-crypto-emotion.cjs +215 -0
- package/atoms/atoms_engines.json +5821 -0
- package/atoms/blueprint-atoms-2.cjs +583 -0
- package/atoms/blueprint-atoms.cjs +975 -0
- package/atoms/constraints.cjs +257 -0
- package/atoms/contract-validator.cjs +213 -0
- package/atoms/engine.cjs +849 -0
- package/atoms/specialized.cjs +530 -0
- package/atoms/verify.cjs +94 -0
- package/package.json +97 -91
- package/scripts/verify-dist.cjs +80 -0
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* P6-B2 · 易理工程学引擎运行时(EngineRuntime · YILI 组)
|
|
4
|
+
*
|
|
5
|
+
* 覆盖 V37.0 新增的 10 个易数引擎(ENGINE_*_126..135)+ 择日 + 象数诊断 = 12 条执行体
|
|
6
|
+
*
|
|
7
|
+
* 实现来源:D:\DH工作区\易理工程学\lib\ 的确定性实现(寿星天文历公版公式 + 规则表 + 状态机),
|
|
8
|
+
* 已搬运至 packages/engine/ENGINES/yili/(167 KB,13 lib + 1 vendor + 5 data)。
|
|
9
|
+
* MCP 服务器 mcp__yili__* 读同一份引擎,故本地实现与 MCP 输出可交叉校验。
|
|
10
|
+
*
|
|
11
|
+
* 设计:
|
|
12
|
+
* - CJS 桥接 ESM(ENGINES/yili/ 有局部 package.json type:module)
|
|
13
|
+
* - 首次调用时惰性加载并缓存 ESM 模块
|
|
14
|
+
* - 与协议运行时同构的 ExecResult:success/kind/output/provenance/traceId/durationMs
|
|
15
|
+
* - 一切断言带置信度与规则编号(引擎自身素养,直传不修饰)
|
|
16
|
+
*/
|
|
17
|
+
'use strict';
|
|
18
|
+
const path = require('path');
|
|
19
|
+
const { pathToFileURL } = require('url');
|
|
20
|
+
|
|
21
|
+
const LIB = pathToFileURL(path.join(__dirname, 'yili', 'lib')).href + '/';
|
|
22
|
+
const _cache = new Map();
|
|
23
|
+
|
|
24
|
+
async function mod(name) {
|
|
25
|
+
if (_cache.has(name)) return _cache.get(name);
|
|
26
|
+
const m = await import(LIB + name + '.js');
|
|
27
|
+
_cache.set(name, m);
|
|
28
|
+
return m;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let __seq = 0;
|
|
32
|
+
function newTraceId() {
|
|
33
|
+
const d = new Date(), p = (n, w = 2) => String(n).padStart(w, '0');
|
|
34
|
+
return `${d.getFullYear()}${p(d.getMonth() + 1)}${p(d.getDate())}-${p(d.getHours())}${p(d.getMinutes())}${p(d.getSeconds())}-Y${p((++__seq) % 10000, 4)}`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/* ══════════════════════════════════════════════════════════
|
|
38
|
+
* 12 条引擎执行体
|
|
39
|
+
* ══════════════════════════════════════════════════════════ */
|
|
40
|
+
const ENGINES = [
|
|
41
|
+
/* ── 126 历法引擎 ── */
|
|
42
|
+
{
|
|
43
|
+
id: 'ENGINE_SHUSHU_ALMANAC_126', name: '历法引擎', kind: 'calendar', family: '历法',
|
|
44
|
+
source: '易理工程学 lib/almanac.js(寿星天文历公版公式 Sxing)',
|
|
45
|
+
api: ['jieqiOfYear', 'ganzhiDayOfDate', 'ganzhiYearOf', 'ganzhiMonthOf', 'ganzhiHourOf', 'nayin', 'changsheng', 'dayXunKong', 'jianchu'],
|
|
46
|
+
async exec(input, tid) {
|
|
47
|
+
const a = await mod('almanac');
|
|
48
|
+
const { y = 2026, m = 10, d = 27, hour = 12 } = input || {};
|
|
49
|
+
const gzYear = a.ganzhiYearOf(y, m, d, hour); // 签名: (y,m,d,hour=12)
|
|
50
|
+
const gzDay = a.ganzhiDayOfDate(y, m, d); // 签名: (y,m,d)
|
|
51
|
+
const out = {
|
|
52
|
+
ganzhiYear: gzYear,
|
|
53
|
+
ganzhiMonth: a.ganzhiMonthOf(gzYear, y, m, d, hour), // 签名: (yearGanZhi,y,m,d,hour)
|
|
54
|
+
ganzhiDay: gzDay,
|
|
55
|
+
ganzhiHour: a.ganzhiHourOf(gzDay, hour), // 签名: (dayGanZhi,hour)
|
|
56
|
+
jieqi: a.jieqiOfYear(y),
|
|
57
|
+
xunKong: a.dayXunKong(y, m, d),
|
|
58
|
+
jianchu: a.jianchu(y, m, d),
|
|
59
|
+
nayin: a.nayin(gzDay),
|
|
60
|
+
changsheng: a.changsheng(gzDay),
|
|
61
|
+
};
|
|
62
|
+
return { success: true, kind: 'calendar', output: out, provenance: [`[${tid}] almanac: 4 柱 + 24 节气 + 旬空 + 纳音 + 十二长生`] };
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
/* ── 127 周易引擎 ── */
|
|
66
|
+
{
|
|
67
|
+
id: 'ENGINE_YIJING_127', name: '周易引擎', kind: 'stateful', family: '周易',
|
|
68
|
+
source: '易理工程学 lib/yijing.js(64 卦状态机 + 384 爻辞)',
|
|
69
|
+
api: ['divine', 'coinDivination', 'changeGua', 'huGua', 'zongGua', 'cuoGua', 'yaoCi'],
|
|
70
|
+
async exec(input, tid) {
|
|
71
|
+
const y = await mod('yijing');
|
|
72
|
+
const seed = (input && input.seed) || 20261027;
|
|
73
|
+
const r = y.divine(seed, (input && input.opts) || {}); // 签名: divine(seed, opts={})
|
|
74
|
+
/* divine() 已内联算出 hu/zong/cuo,直接取用;
|
|
75
|
+
注意 zongGua(lines)/cuoGua(lines)/huGua(lines) 收的是 lines 数组,不能传整个结果对象。 */
|
|
76
|
+
const out = {
|
|
77
|
+
ben: r.ben, bian: r.bian, hu: r.hu, zong: r.zong, cuo: r.cuo,
|
|
78
|
+
moving: r.moving || [], movingTitles: r.movingTitles || [],
|
|
79
|
+
seed: r.seed,
|
|
80
|
+
};
|
|
81
|
+
return { success: true, kind: 'stateful', output: out, provenance: [`[${tid}] yijing: 64 卦状态机 · 本卦/变卦/互卦/综卦/错卦`] };
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
/* ── 128 五行引擎 ── */
|
|
85
|
+
{
|
|
86
|
+
id: 'ENGINE_WUXING_128', name: '五行引擎', kind: 'formula', family: '五行八卦',
|
|
87
|
+
source: '易理工程学 lib/wuxing.js',
|
|
88
|
+
api: ['wuxingMatrix', 'relation', 'wangxiangOfSeason', 'circuitAnalysis'],
|
|
89
|
+
async exec(input, tid) {
|
|
90
|
+
const w = await mod('wuxing');
|
|
91
|
+
const els = (input && input.elements) || ['木', '火', '土', '金', '水'];
|
|
92
|
+
const season = (input && input.season) || '秋';
|
|
93
|
+
/* 季节 → 五行映射(wangxiangOfSeason 签名为 (seasonWuxing)) */
|
|
94
|
+
const SEASON_WUXING = { '春': '木', '夏': '火', '长夏': '土', '秋': '金', '冬': '水' };
|
|
95
|
+
const sw = SEASON_WUXING[season] || '金';
|
|
96
|
+
const out = {
|
|
97
|
+
elements: els, season, seasonWuxing: sw,
|
|
98
|
+
wangxiang: w.wangxiangOfSeason(sw),
|
|
99
|
+
matrix: w.wuxingMatrix(),
|
|
100
|
+
circuit: w.circuitAnalysis(els), /* 签名: circuitAnalysis(elements) */
|
|
101
|
+
relations: els.slice(0, 3).map((a) => els.slice(0, 3).map((b) => ({ a, b, rel: w.relation(a, b) }))),
|
|
102
|
+
};
|
|
103
|
+
return { success: true, kind: 'formula', output: out, provenance: [`[${tid}] wuxing: 旺相休囚死 + 生克矩阵 + 回路`] };
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
/* ── 129 河图洛书引擎 ── */
|
|
107
|
+
{
|
|
108
|
+
id: 'ENGINE_HETU_LUOSHU_129', name: '河图洛书引擎', kind: 'formula', family: '河图洛书',
|
|
109
|
+
source: '易理工程学 lib/hetu-luoshu.js',
|
|
110
|
+
api: ['magicSquare', 'luoshuWithGua', 'luoshuDirection', 'verifyMagicSquare'],
|
|
111
|
+
async exec(input, tid) {
|
|
112
|
+
const h = await mod('hetu-luoshu');
|
|
113
|
+
const n = (input && input.n) || 3;
|
|
114
|
+
const ms = h.magicSquare(n);
|
|
115
|
+
return {
|
|
116
|
+
success: true, kind: 'formula',
|
|
117
|
+
output: {
|
|
118
|
+
n, magicSquare: ms, verified: h.verifyMagicSquare(ms),
|
|
119
|
+
luoshuWithGua: h.luoshuWithGua(), directions: h.luoshuDirection(),
|
|
120
|
+
hetuPairs: h.HETU_PAIRS, grid: h.LUOSHU_GRID,
|
|
121
|
+
},
|
|
122
|
+
provenance: [`[${tid}] hetu-luoshu: ${n} 阶幻方 + 九宫配卦 + 河图生成数对`],
|
|
123
|
+
};
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
/* ── 130 六爻引擎 ── */
|
|
127
|
+
{
|
|
128
|
+
id: 'ENGINE_LIUYAO_130', name: '六爻引擎', kind: 'stateful', family: '六爻',
|
|
129
|
+
source: '易理工程学 lib/liuyao.js(装卦/用神/旺衰/应期)',
|
|
130
|
+
api: ['zhuanggua', 'liuyaoAnalysis', 'yongshenFor', 'yingqiHints', 'liuShen'],
|
|
131
|
+
async exec(input, tid) {
|
|
132
|
+
const l = await mod('liuyao');
|
|
133
|
+
const a = await mod('almanac');
|
|
134
|
+
const topic = (input && input.topic) || '事业';
|
|
135
|
+
const y = (input && input.y) || 2026, m = (input && input.m) || 10, d = (input && input.d) || 27, hour = (input && input.hour) || 12;
|
|
136
|
+
/* 签名: zhuanggua(fullName, dayGanZhi, monthZhi, dayGan) */
|
|
137
|
+
const fullName = (input && input.fullName) || '乾为天'; // 须全卦名,'乾' 会让 NAJIA[lower] 为 undefined
|
|
138
|
+
const gzDay = a.ganzhiDayOfDate(y, m, d);
|
|
139
|
+
const gzMonth = a.ganzhiMonthOf(a.ganzhiYearOf(y, m, d, hour), y, m, d, hour);
|
|
140
|
+
const dayGan = String(gzDay).charAt(0);
|
|
141
|
+
const monthZhi = String(gzMonth).slice(-1);
|
|
142
|
+
const g = l.zhuanggua(fullName, gzDay, monthZhi, dayGan);
|
|
143
|
+
const safe = (fn, label) => { try { const v = fn(); return (v && typeof v === 'object' && v.rows && !Array.isArray(v.rows)) ? { _unavailable: label, reason: 'rows 非数组' } : v; } catch (e) { return { _unavailable: label, error: String(e.message).slice(0, 140) }; } };
|
|
144
|
+
const out = {
|
|
145
|
+
gua: g, topic, fullName, dayGanZhi: gzDay, monthZhi, dayGan,
|
|
146
|
+
yongshen: safe(() => l.yongshenFor(topic), 'yongshen'),
|
|
147
|
+
liuqin: safe(() => g.rows.map((r) => l.liuqin ? l.liuqin(String(gzDay).charAt(0), r.zhi || r.zhiWuxing) : null), 'liuqin'),
|
|
148
|
+
analysis: safe(() => l.liuyaoAnalysis({ fullName, dayGanZhi: gzDay, monthZhi, dayGan, topic, hour }), 'analysis'),
|
|
149
|
+
yingqi: safe(() => l.yingqiHints({ fullName, dayGanZhi: gzDay, monthZhi, dayGan, topic }), 'yingqi'),
|
|
150
|
+
};
|
|
151
|
+
return { success: true, kind: 'stateful', output: out, provenance: [`[${tid}] liuyao: 装卦 + 用神 + 旺衰 + 应期(${topic})`] };
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
/* ── 131 四柱引擎 ── */
|
|
155
|
+
{
|
|
156
|
+
id: 'ENGINE_BAZI_131', name: '四柱引擎', kind: 'compute', family: '四柱',
|
|
157
|
+
source: '易理工程学 lib/bazi.js(排盘/十神/大运/流年)',
|
|
158
|
+
api: ['baziCalc', 'shishen', 'dayunCalc', 'liunianCalc', 'balanceOf'],
|
|
159
|
+
async exec(input, tid) {
|
|
160
|
+
const b = await mod('bazi');
|
|
161
|
+
const safe = (fn, label) => { try { return fn(); } catch (e) { return { _unavailable: label, error: String(e.message).slice(0, 120) }; } };
|
|
162
|
+
const { y = 1990, m = 6, d = 15, hour = 10, gender = '男' } = input || {};
|
|
163
|
+
const chart = b.baziCalc(y, m, d, hour);
|
|
164
|
+
return {
|
|
165
|
+
success: true, kind: 'compute',
|
|
166
|
+
output: {
|
|
167
|
+
chart,
|
|
168
|
+
gender,
|
|
169
|
+
shishen: (() => { const dg = chart.dayGan || (chart.pillars && chart.pillars.day && chart.pillars.day.gan) || chart.day && chart.day.gan; return dg ? Object.entries(b.CANG_GAN).slice(0, 10).map(([zhi, gans]) => ({ zhi, shishen: gans.map((g) => b.shishen(dg, g)) })) : null; })(),
|
|
170
|
+
dayun: safe(() => b.dayunCalc(y, m, d, hour, gender), 'dayun'),
|
|
171
|
+
liunian: safe(() => b.liunianCalc(y), 'liunian'),
|
|
172
|
+
balance: safe(() => b.balanceOf(chart), 'balance'),
|
|
173
|
+
},
|
|
174
|
+
provenance: [`[${tid}] bazi: 四柱排盘 + 十神 + 大运 + 流年 + 五行平衡`],
|
|
175
|
+
};
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
/* ── 132 紫微引擎 ── */
|
|
179
|
+
{
|
|
180
|
+
id: 'ENGINE_ZIWEI_132', name: '紫微引擎', kind: 'stateful', family: '紫微',
|
|
181
|
+
source: '易理工程学 lib/ziwei.js(安星全盘/四化/三方四正)',
|
|
182
|
+
api: ['ziweiCalc', 'mainStars', 'sanfangSizheng', 'mingShenGong', 'wuxingJu'],
|
|
183
|
+
async exec(input, tid) {
|
|
184
|
+
const z = await mod('ziwei');
|
|
185
|
+
const { lunarYear = 1990, month = 6, day = 15, hour = 10, yearGanZhi = '庚午', nayinYear = '路旁土' } = input || {};
|
|
186
|
+
const pan = z.ziweiCalc({ lunarYear, birthMonth: month, birthDay: day, birthHour: hour, yearGanZhi, nayinYear });
|
|
187
|
+
return {
|
|
188
|
+
success: true, kind: 'stateful',
|
|
189
|
+
output: { pan, mingShenGong: z.mingShenGong({ lunarYear, birthMonth: month, birthDay: day, birthHour: hour }), wuxingJu: z.wuxingJu({ lunarYear, yearGanZhi, nayinYear }), sanfang: pan && pan.board ? Object.fromEntries(Object.keys(pan.board).map((k) => [k, z.sanfangSizheng(k)])) : null },
|
|
190
|
+
provenance: [`[${tid}] ziwei: 安星全盘 + 四化 + 三方四正 + 命身宫 + 五行局`],
|
|
191
|
+
};
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
/* ── 133 奇门引擎 ── */
|
|
195
|
+
{
|
|
196
|
+
id: 'ENGINE_QIMEN_133', name: '奇门引擎', kind: 'stateful', family: '奇门',
|
|
197
|
+
source: '易理工程学 lib/qimen.js(时家奇门 1080 局/三奇六仪/值符值使/九星八门八神)',
|
|
198
|
+
api: ['qimenCalc', 'dingJu', 'sanqiLiuyi', 'xunShou', 'yuanOfDay'],
|
|
199
|
+
async exec(input, tid) {
|
|
200
|
+
const q = await mod('qimen');
|
|
201
|
+
const { y = 2026, m = 10, d = 27, hour = 12 } = input || {};
|
|
202
|
+
const pan = q.qimenCalc(y, m, d, hour); // 签名: (y,m,d,hour)
|
|
203
|
+
return {
|
|
204
|
+
success: true, kind: 'stateful',
|
|
205
|
+
output: {
|
|
206
|
+
pan,
|
|
207
|
+
ju: q.dingJu ? q.dingJu(y, m, d) : (pan && pan.ju), // 签名: (y,m,d)
|
|
208
|
+
sanqiLiuyi: q.sanqiLiuyi ? q.sanqiLiuyi(y, m, d, hour) : null,
|
|
209
|
+
xunShou: q.xunShou ? q.xunShou(y, m, d, hour) : null,
|
|
210
|
+
yuan: q.yuanOfDay ? q.yuanOfDay(y, m, d) : null,
|
|
211
|
+
},
|
|
212
|
+
provenance: [`[${tid}] qimen: 时家奇门 · 定局(阴阳遁18局) + 三奇六仪 + 值符值使 + 九星八门八神`],
|
|
213
|
+
};
|
|
214
|
+
},
|
|
215
|
+
},
|
|
216
|
+
/* ── 134 太乙引擎 ── */
|
|
217
|
+
{
|
|
218
|
+
id: 'ENGINE_TAIYI_134', name: '太乙引擎', kind: 'compute', family: '太乙',
|
|
219
|
+
source: '易理工程学 lib/taiyi.js(积年/十六神/分歧登记)',
|
|
220
|
+
api: ['taiyiCalc', 'taiyiJinian', 'taiyiYearInCycle', 'shiliushenBoard', 'taiyiBaMen', 'taiyiPalace'],
|
|
221
|
+
async exec(input, tid) {
|
|
222
|
+
const t = await mod('taiyi');
|
|
223
|
+
const year = (input && input.year) || 2026;
|
|
224
|
+
const school = (input && input.school) || '金镜式经(主本)';
|
|
225
|
+
return {
|
|
226
|
+
success: true, kind: 'compute',
|
|
227
|
+
output: {
|
|
228
|
+
year, school,
|
|
229
|
+
jinian: t.taiyiJinian(year, school),
|
|
230
|
+
yearInCycle: t.taiyiYearInCycle(year, school),
|
|
231
|
+
palace: t.taiyiPalace ? t.taiyiPalace(year, school) : null,
|
|
232
|
+
baMen: t.taiyiBaMen ? t.taiyiBaMen(year, school) : null,
|
|
233
|
+
shiliushen: t.shiliushenBoard ? t.shiliushenBoard(year, school) : null,
|
|
234
|
+
schools: Object.keys(t.JINIAN_SCHOOLS),
|
|
235
|
+
},
|
|
236
|
+
provenance: [`[${tid}] taiyi: 积年(${school}) + 十六神 + 八门 + 分歧登记`],
|
|
237
|
+
};
|
|
238
|
+
},
|
|
239
|
+
},
|
|
240
|
+
/* ── 135 文言微积分引擎 ── */
|
|
241
|
+
{
|
|
242
|
+
id: 'ENGINE_SHUSHU_CALCULUS_135', name: '文言微积分引擎', kind: 'formula', family: '文言微积分',
|
|
243
|
+
source: '易理工程学 lib/shushu-calculus.js(察机/应期/禾势)',
|
|
244
|
+
api: ['shushuCalculus', 'potential', 'chaJi', 'yingqi', 'heShi'],
|
|
245
|
+
async exec(input, tid) {
|
|
246
|
+
const c = await mod('shushu-calculus');
|
|
247
|
+
const state = (input && input.state) || { wood: 0.8, fire: 0.6, earth: 0.5, metal: 0.4, water: 0.7 };
|
|
248
|
+
const season = (input && input.season) || '秋';
|
|
249
|
+
const threshold = Number((input && input.threshold) ?? 0.75);
|
|
250
|
+
return {
|
|
251
|
+
success: true, kind: 'formula',
|
|
252
|
+
output: {
|
|
253
|
+
state, season, threshold,
|
|
254
|
+
potential: c.potential(state, 0, 1),
|
|
255
|
+
chaJi: c.chaJi ? c.chaJi(state, 1) : null,
|
|
256
|
+
yingqi: c.yingqi ? c.yingqi(state, 1, threshold) : null,
|
|
257
|
+
heShi: c.heShi ? c.heShi(state, 1) : null,
|
|
258
|
+
full: c.shushuCalculus ? c.shushuCalculus({ state, season, threshold }) : null,
|
|
259
|
+
},
|
|
260
|
+
provenance: [`[${tid}] shushu-calculus: 势函数 + 察机(临界点) + 应期求解 + 禾势(累积势能)`],
|
|
261
|
+
};
|
|
262
|
+
},
|
|
263
|
+
},
|
|
264
|
+
/* ── 附加:择日(PROTOCOL/技能层引用) ── */
|
|
265
|
+
{
|
|
266
|
+
id: 'ENGINE_SHUSHU_ZERI_136', name: '择日引擎', kind: 'compute', family: '择日',
|
|
267
|
+
source: '易理工程学 lib/zeri.js(约束满足搜索)',
|
|
268
|
+
api: ['zeriPick', 'zeriReport', 'huangheiDao'],
|
|
269
|
+
async exec(input, tid) {
|
|
270
|
+
const z = await mod('zeri');
|
|
271
|
+
const { y = 2026, m = 10, d = 27, days = 30, constraints = {} } = input || {};
|
|
272
|
+
return {
|
|
273
|
+
success: true, kind: 'compute',
|
|
274
|
+
output: { from: { y, m, d }, days, constraints, picked: z.zeriPick(y, m, d, days, constraints), report: z.zeriReport ? z.zeriReport(y, m, d, days, constraints) : null },
|
|
275
|
+
provenance: [`[${tid}] zeri: 约束满足搜索(建除/黄黑道/避冲)`],
|
|
276
|
+
};
|
|
277
|
+
},
|
|
278
|
+
},
|
|
279
|
+
/* ── 附加:象数诊断 ── */
|
|
280
|
+
{
|
|
281
|
+
id: 'ENGINE_SHUSHU_DIAGNOSE_137', name: '象数诊断引擎', kind: 'formula', family: '象数诊断',
|
|
282
|
+
source: '易理工程学 lib/diagnose.js(五行透镜/杠杆点)',
|
|
283
|
+
api: ['shushuDiagnose', 'detectWuxing'],
|
|
284
|
+
async exec(input, tid) {
|
|
285
|
+
const dg = await mod('diagnose');
|
|
286
|
+
const elements = (input && input.elements) || [{ name: '战略', value: 0.8 }, { name: '执行', value: 0.4 }, { name: '技术', value: 0.7 }];
|
|
287
|
+
const season = (input && input.season) || '秋';
|
|
288
|
+
return {
|
|
289
|
+
success: true, kind: 'formula',
|
|
290
|
+
output: { elements: elements.map((e) => ({ ...e, wuxing: dg.detectWuxing(e.name) })), season, diagnose: dg.shushuDiagnose(elements, season) },
|
|
291
|
+
provenance: [`[${tid}] diagnose: 五行透镜 + 生克回路 + 杠杆点(最小干预)`],
|
|
292
|
+
};
|
|
293
|
+
},
|
|
294
|
+
},
|
|
295
|
+
];
|
|
296
|
+
|
|
297
|
+
/* ══════════════════════════════════════════════════════════
|
|
298
|
+
* 运行时接口
|
|
299
|
+
* ══════════════════════════════════════════════════════════ */
|
|
300
|
+
const INDEX = new Map(ENGINES.map((e) => [e.id, e]));
|
|
301
|
+
|
|
302
|
+
function kindOf(id) { const e = INDEX.get(id); return e ? e.kind : 'declared'; }
|
|
303
|
+
function getRegistry() { return ENGINES.map((e) => ({ id: e.id, name: e.name, kind: e.kind, family: e.family, source: e.source, api: e.api })); }
|
|
304
|
+
|
|
305
|
+
async function execute(id, input) {
|
|
306
|
+
const t0 = Date.now();
|
|
307
|
+
const tid = newTraceId();
|
|
308
|
+
const e = INDEX.get(id);
|
|
309
|
+
if (!e) return { success: false, kind: 'declared', reason: 'NOT_FOUND', error: `引擎 ${id} 未登记`, provenance: [], traceId: tid, durationMs: 0 };
|
|
310
|
+
try {
|
|
311
|
+
const r = await e.exec(input || {}, tid);
|
|
312
|
+
return { ...r, engineId: id, engineName: e.name, traceId: tid, durationMs: Date.now() - t0 };
|
|
313
|
+
} catch (err) {
|
|
314
|
+
return { success: false, kind: e.kind, error: 'THROW: ' + err.message, provenance: [`[${tid}] THROW`], engineId: id, traceId: tid, durationMs: Date.now() - t0 };
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
module.exports = { execute, kindOf, getRegistry, ENGINES, INDEX, newTraceId, mod };
|