@metago-ai/engine 2.1.3 → 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 +75 -113
- package/CORE/ATOMS.md +611 -0
- package/CORE/ATTRIBUTES.md +74 -105
- package/CORE/PROTOCOLS.md +134 -116
- package/ENGINE.md +115 -115
- 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 +2 -2
- package/INDEX/knowledge.json +87 -87
- package/INDEX/skills.json +227 -203
- 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.js +11 -2
- 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 +12 -6
- package/scripts/verify-dist.cjs +80 -0
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* P6-B12 · 最终收口批:20 条缺口协议 + 2 条缺失引擎 = 22 条
|
|
4
|
+
* 完成后 P6 = 协议 150/150 + 引擎 174/174(ENGINES.md 全集)
|
|
5
|
+
*/
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
let __seq = 0;
|
|
9
|
+
const tid = () => {
|
|
10
|
+
const d = new Date(), p = (n, w = 2) => String(n).padStart(w, '0');
|
|
11
|
+
return `${d.getFullYear()}${p(d.getMonth() + 1)}${p(d.getDate())}-${d.getHours()}${p(d.getMinutes())}${p(d.getSeconds())}-W${p((++__seq) % 10000, 4)}`;
|
|
12
|
+
};
|
|
13
|
+
const clamp01 = (x) => Math.max(0, Math.min(1, Number(x) || 0));
|
|
14
|
+
const round = (x, n = 6) => Math.round((Number(x) || 0) * 10 ** n) / 10 ** n;
|
|
15
|
+
const mean = (a) => (a.length ? a.reduce((s, x) => s + (Number(x) || 0), 0) / a.length : 0);
|
|
16
|
+
const miss = (o, ks) => ks.filter((k) => !o || o[k] === undefined || o[k] === null);
|
|
17
|
+
|
|
18
|
+
const P = []; // 协议
|
|
19
|
+
const E = []; // 引擎
|
|
20
|
+
const addP = (o) => P.push(o);
|
|
21
|
+
const addE = (o) => E.push(o);
|
|
22
|
+
|
|
23
|
+
/* ══════════ 一、20 条缺口协议 ══════════ */
|
|
24
|
+
|
|
25
|
+
/* 缺口协议多来自根文档,仅有名称+功能一句;按名称语义 + 元构通用模式实现,推导依据记入 src */
|
|
26
|
+
const GAP_P = [
|
|
27
|
+
['PROTOCOL_AUTONOMOUS_EXPLORE_V1', '自主探索协议', 'compute',
|
|
28
|
+
['frontier', 'budget'], (inp, t) => {
|
|
29
|
+
const f = inp.frontier || [], b = Number(inp.budget ?? 10), u = Number(inp.used ?? 0);
|
|
30
|
+
return { success: u <= b && f.length > 0, kind: 'compute', output: { frontier: f.length, budget: b, used: u, remaining: round(b - u), canExplore: u < b && f.length > 0 },
|
|
31
|
+
error: u > b ? '探索预算超支' : f.length === 0 ? '探索前沿为空' : undefined, reason: (u > b || !f.length) ? 'PRECONDITION_FAILED' : undefined,
|
|
32
|
+
provenance: [`[${t}] autonomous-explore: 前沿 ${f.length},预算 ${u}/${b}`] };
|
|
33
|
+
}],
|
|
34
|
+
['PROTOCOL_CAPABILITY_COORD_V1', '能力协同协议', 'compute',
|
|
35
|
+
['capabilities'], (inp, t) => {
|
|
36
|
+
const caps = inp.capabilities || [];
|
|
37
|
+
if (caps.length < 2) return { success: false, kind: 'compute', reason: 'INVALID_INPUT', error: '至少 2 个能力' };
|
|
38
|
+
const covered = new Set(); let total = 0;
|
|
39
|
+
for (const c of caps) { const ts = c.covers || []; total += ts.length; ts.forEach((x) => covered.add(x)); }
|
|
40
|
+
const overlap = total ? round((total - covered.size) / covered.size) : 0;
|
|
41
|
+
const coord = round(clamp01(1 - clamp01(overlap / 2)));
|
|
42
|
+
return { success: coord >= 0.5, kind: 'compute', output: { capabilities: caps.length, coverage: covered.size, overlap, coordination: coord },
|
|
43
|
+
error: coord < 0.5 ? `能力重叠过高 ${overlap}` : undefined, reason: coord < 0.5 ? 'PRECONDITION_FAILED' : undefined,
|
|
44
|
+
provenance: [`[${t}] capability-coord: ${caps.length} 能力,协同 ${coord}`] };
|
|
45
|
+
}],
|
|
46
|
+
['PROTOCOL_CDL_V1', '认知分层协议', 'rule',
|
|
47
|
+
['perception', 'understanding', 'decision', 'execution'], (inp, t) => {
|
|
48
|
+
const F = ['perception', 'understanding', 'decision', 'execution'];
|
|
49
|
+
const m = miss(inp, F);
|
|
50
|
+
return { success: m.length === 0, kind: 'rule', output: { layers: F, missing: m },
|
|
51
|
+
error: m.length ? `认知层缺:${m.join('/')}` : undefined, reason: m.length ? 'RULE_VIOLATED' : undefined,
|
|
52
|
+
provenance: [`[${t}] cdl: ${4 - m.length}/4`] };
|
|
53
|
+
}],
|
|
54
|
+
['PROTOCOL_CF_V1', '耦生反馈协议', 'compute',
|
|
55
|
+
['signal', 'response'], (inp, t) => {
|
|
56
|
+
const s = clamp01(inp.signalStrength ?? 0.5), r = clamp01(inp.responseStrength ?? 0.5);
|
|
57
|
+
const coupling = round(Math.sqrt(s * r));
|
|
58
|
+
return { success: coupling >= 0.5, kind: 'compute', output: { signal: s, response: r, coupling, effective: coupling >= 0.5, formula: '耦生反馈 = √(信号 × 响应)' },
|
|
59
|
+
error: coupling < 0.5 ? `耦生度 ${coupling} 偏低` : undefined, reason: coupling < 0.5 ? 'PRECONDITION_FAILED' : undefined,
|
|
60
|
+
provenance: [`[${t}] cf: √(${s}×${r}) = ${coupling}`] };
|
|
61
|
+
}],
|
|
62
|
+
['PROTOCOL_CRITICAL_TRUTH_V2', '真相优先协议 V2', 'rule',
|
|
63
|
+
[], (inp, t) => {
|
|
64
|
+
const text = String(inp.text || '');
|
|
65
|
+
if (!text) return { success: false, kind: 'rule', reason: 'INVALID_INPUT', error: '必须提供 text' };
|
|
66
|
+
const SY = /您说得(对|太对|完全对)|完全正确|太好了|赞同您/g;
|
|
67
|
+
const AV = /不便(评|评论)|看情况|因人而异|见仁见智/g;
|
|
68
|
+
const sy = text.match(SY) || [], av = text.match(AV) || [];
|
|
69
|
+
const ok = sy.length === 0 && av.length === 0;
|
|
70
|
+
return { success: ok, kind: 'rule', output: { version: 'V2', sycophancy: sy.length, avoidance: av.length, clean: ok },
|
|
71
|
+
error: ok ? undefined : `迎合 ${sy.length} / 回避 ${av.length}`, reason: ok ? undefined : 'RULE_VIOLATED',
|
|
72
|
+
provenance: [`[${t}] critical-truth-v2: 迎合 ${sy.length} 回避 ${av.length}`] };
|
|
73
|
+
}],
|
|
74
|
+
['PROTOCOL_DIALOG_CREATE_V1', '对话创造协议', 'pipeline',
|
|
75
|
+
['turns', 'divergence', 'convergence', 'artifact'], (inp, t) => {
|
|
76
|
+
const F = ['turns', 'divergence', 'convergence', 'artifact'];
|
|
77
|
+
const m = miss(inp, F);
|
|
78
|
+
return { success: m.length === 0, kind: 'pipeline', output: { steps: ['对话', '发散', '收敛', '产出'], missing: m },
|
|
79
|
+
error: m.length ? `对话创造缺:${m.join('/')}` : undefined, reason: m.length ? 'PRECONDITION_FAILED' : undefined,
|
|
80
|
+
provenance: [`[${t}] dialog-create: ${4 - m.length}/4`] };
|
|
81
|
+
}],
|
|
82
|
+
['PROTOCOL_DPVP_V1_0', '数据价值证明协议', 'rule',
|
|
83
|
+
['dataSource', 'valueProof', 'chain'], (inp, t) => {
|
|
84
|
+
const F = ['dataSource', 'valueProof', 'chain'];
|
|
85
|
+
const m = miss(inp, F);
|
|
86
|
+
return { success: m.length === 0, kind: 'rule', output: { required: F, missing: m },
|
|
87
|
+
error: m.length ? `数据价值证明缺:${m.join('/')}` : undefined, reason: m.length ? 'RULE_VIOLATED' : undefined,
|
|
88
|
+
provenance: [`[${t}] dpvp: ${3 - m.length}/3`] };
|
|
89
|
+
}],
|
|
90
|
+
['PROTOCOL_FACTCHECK_V1', '事实核查协议', 'rule',
|
|
91
|
+
['statements'], (inp, t) => {
|
|
92
|
+
const st = inp.statements;
|
|
93
|
+
if (!Array.isArray(st) || !st.length) return { success: false, kind: 'rule', reason: 'INVALID_INPUT', error: '必须提供 statements' };
|
|
94
|
+
const T = [['✅ 已确认', 0.9, 1], ['📊 较高', 0.7, 0.899], ['⚠️ 待核实', 0.5, 0.699], ['🔍 需确认', 0, 0.499]];
|
|
95
|
+
const checked = st.map((s, i) => { const c = Number(s.confidence ?? 0); const tt = T.find((x) => c >= x[1] && c <= x[2]) || T[3]; return { i, content: s.content, confidence: c, tier: tt[0], sourced: !!s.source }; });
|
|
96
|
+
const unsourced = checked.filter((c) => !c.sourced && c.confidence >= 0.9);
|
|
97
|
+
return { success: unsourced.length === 0, kind: 'rule', output: { total: st.length, checked, unsourcedHighConf: unsourced.length },
|
|
98
|
+
error: unsourced.length ? `${unsourced.length} 条高置信声明缺来源` : undefined, reason: unsourced.length ? 'RULE_VIOLATED' : undefined,
|
|
99
|
+
provenance: [`[${t}] factcheck: ${st.length} 条,高置信无源 ${unsourced.length}`] };
|
|
100
|
+
}],
|
|
101
|
+
['PROTOCOL_FEDERATED_V1', '联邦学习协议', 'rule',
|
|
102
|
+
['participants', 'localOnly'], (inp, t) => {
|
|
103
|
+
const ps = inp.participants || [];
|
|
104
|
+
const localOnly = inp.rawDataLocal === true;
|
|
105
|
+
const agg = inp.aggregatedOnly === true;
|
|
106
|
+
const fails = [];
|
|
107
|
+
if (ps.length < 2) fails.push('参与方少于 2');
|
|
108
|
+
if (!localOnly) fails.push('原始数据未本地保留');
|
|
109
|
+
if (!agg) fails.push('仅上传聚合结果的要求未满足');
|
|
110
|
+
return { success: fails.length === 0, kind: 'rule', output: { participants: ps.length, rawDataLocal: localOnly, aggregatedOnly: agg, fails },
|
|
111
|
+
error: fails.length ? fails.join(';') : undefined, reason: fails.length ? 'RULE_VIOLATED' : undefined,
|
|
112
|
+
provenance: [`[${t}] federated: ${ps.length} 方,隐私合规 ${fails.length === 0}`] };
|
|
113
|
+
}],
|
|
114
|
+
['PROTOCOL_HUMAN_AI_SYM_V1', '人机共生协议', 'compute',
|
|
115
|
+
['human', 'ai'], (inp, t) => {
|
|
116
|
+
const h = clamp01(inp.humanCapability ?? 0.7), a = clamp01(inp.aiCapability ?? 0.8);
|
|
117
|
+
const sym = round(Math.sqrt(h * a));
|
|
118
|
+
const complement = round(1 - Math.abs(h - a));
|
|
119
|
+
return { success: sym >= 0.6, kind: 'compute', output: { human: h, ai: a, symbiosis: sym, complementarity: complement, healthy: sym >= 0.6, formula: '共生度 = √(人 × AI)' },
|
|
120
|
+
error: sym < 0.6 ? `共生度 ${sym} 偏低` : undefined, reason: sym < 0.6 ? 'PRECONDITION_FAILED' : undefined,
|
|
121
|
+
provenance: [`[${t}] human-ai-sym: √(${h}×${a}) = ${sym}`] };
|
|
122
|
+
}],
|
|
123
|
+
['PROTOCOL_IDEA_ALGO_V1', '思想算法协议', 'compute',
|
|
124
|
+
['idea'], (inp, t) => {
|
|
125
|
+
const id = inp.idea || {};
|
|
126
|
+
if (!id.name) return { success: false, kind: 'compute', reason: 'INVALID_INPUT', error: 'idea.name 必填' };
|
|
127
|
+
const novelty = clamp01(id.novelty ?? 0.5), utility = clamp01(id.utility ?? 0.5), feasibility = clamp01(id.feasibility ?? 0.5);
|
|
128
|
+
const score = round(novelty * 0.4 + utility * 0.35 + feasibility * 0.25);
|
|
129
|
+
return { success: score >= 0.5, kind: 'compute', output: { idea: id.name, novelty, utility, feasibility, score, viable: score >= 0.5,
|
|
130
|
+
formula: '思想分 = 新颖×0.4 + 效用×0.35 + 可行×0.25' },
|
|
131
|
+
error: score < 0.5 ? `思想分 ${score} 不足` : undefined, reason: score < 0.5 ? 'PRECONDITION_FAILED' : undefined,
|
|
132
|
+
provenance: [`[${t}] idea-algo: ${id.name} → ${score}`] };
|
|
133
|
+
}],
|
|
134
|
+
['PROTOCOL_IDEA_CAPITAL_V1', '思想资本协议', 'compute',
|
|
135
|
+
['ideaValue', 'liquidity', 'inheritance'], (inp, t) => {
|
|
136
|
+
const v = clamp01(inp.ideaValue ?? 0.5), l = clamp01(inp.liquidity ?? 0.5), i = clamp01(inp.inheritance ?? 0.6);
|
|
137
|
+
const capital = round(v * l * i);
|
|
138
|
+
return { success: true, kind: 'compute', output: { ideaValue: v, liquidity: l, inheritance: i, capital, formula: '资本 = 价值 × 流动性 × 传承' },
|
|
139
|
+
provenance: [`[${t}] idea-capital: ${v}×${l}×${i} = ${capital}`] };
|
|
140
|
+
}],
|
|
141
|
+
['PROTOCOL_ILC_V6', '层间通信协议(V6 简版)', 'rule',
|
|
142
|
+
['envelope'], (inp, t) => {
|
|
143
|
+
const m = inp.envelope || {};
|
|
144
|
+
const src = Number(m.srcLayer), dst = Number(m.dstLayer);
|
|
145
|
+
const m2 = miss(m, ['payload', 'traceId']);
|
|
146
|
+
const ok = isFinite(src) && isFinite(dst) && src >= 1 && src <= 11 && dst >= 1 && dst <= 11 && Math.abs(dst - src) <= 2 && m2.length === 0;
|
|
147
|
+
return { success: ok, kind: 'rule', output: { srcLayer: src, dstLayer: dst, jump: Math.abs(dst - src), envelopeMissing: m2 },
|
|
148
|
+
error: ok ? undefined : '层号越界/跨层>2/信封不全', reason: ok ? undefined : 'RULE_VIOLATED',
|
|
149
|
+
provenance: [`[${t}] ilc-v6: L${src}→L${dst}`] };
|
|
150
|
+
}],
|
|
151
|
+
['PROTOCOL_KCP_V1_0', '知识晶体协议', 'compute',
|
|
152
|
+
['crystals'], (inp, t) => {
|
|
153
|
+
const cs = inp.crystals || [];
|
|
154
|
+
if (!cs.length) return { success: false, kind: 'compute', reason: 'INVALID_INPUT', error: '必须提供 crystals' };
|
|
155
|
+
const TYPES = ['会话晶体', '持久晶体', '技能晶体'];
|
|
156
|
+
const valid = cs.filter((c) => TYPES.includes(c.type));
|
|
157
|
+
const reuse = round(mean(cs.map((c) => Number(c.reuseCount ?? 0))));
|
|
158
|
+
return { success: valid.length === cs.length, kind: 'compute', output: { total: cs.length, validTypes: valid.length, typeWhitelist: TYPES, avgReuse: reuse },
|
|
159
|
+
error: valid.length < cs.length ? `${cs.length - valid.length} 个晶体类型非法` : undefined, reason: valid.length < cs.length ? 'PRECONDITION_FAILED' : undefined,
|
|
160
|
+
provenance: [`[${t}] kcp: ${cs.length} 晶体,合法 ${valid.length}`] };
|
|
161
|
+
}],
|
|
162
|
+
['PROTOCOL_MULTI_AGENT_V1', '多智能体协议', 'compute',
|
|
163
|
+
['agents'], (inp, t) => {
|
|
164
|
+
const as = inp.agents || [];
|
|
165
|
+
if (as.length < 2) return { success: false, kind: 'compute', reason: 'INVALID_INPUT', error: '至少 2 个智能体' };
|
|
166
|
+
const conflicts = as.reduce((s, a) => s + Number(a.conflicts || 0), 0);
|
|
167
|
+
const coord = round(clamp01(1 - conflicts / 10));
|
|
168
|
+
const lead = as.reduce((b, a) => Number(a.capability || 0) > Number(b.capability || 0) ? a : b, as[0]);
|
|
169
|
+
return { success: coord >= 0.5, kind: 'compute', output: { agents: as.length, conflicts, coordination: coord, leadAgent: lead.id || 'A0' },
|
|
170
|
+
error: coord < 0.5 ? `冲突过多 ${conflicts}` : undefined, reason: coord < 0.5 ? 'PRECONDITION_FAILED' : undefined,
|
|
171
|
+
provenance: [`[${t}] multi-agent-v1: ${as.length} 体,协同 ${coord}`] };
|
|
172
|
+
}],
|
|
173
|
+
['PROTOCOL_NEGOTIATION_V1', '协商协议', 'compute',
|
|
174
|
+
['positions'], (inp, t) => {
|
|
175
|
+
const ps = inp.positions || [];
|
|
176
|
+
if (ps.length < 2) return { success: false, kind: 'compute', reason: 'INVALID_INPUT', error: '至少 2 方立场' };
|
|
177
|
+
const vals = ps.map((p) => Number(p.value ?? 0));
|
|
178
|
+
const mid = round(mean(vals));
|
|
179
|
+
const spread = round(Math.max(...vals) - Math.min(...vals));
|
|
180
|
+
const dealZone = spread <= Number(inp.maxSpread ?? 1);
|
|
181
|
+
return { success: dealZone, kind: 'compute', output: { parties: ps.length, positions: vals, midpoint: mid, spread, dealZone, suggestion: dealZone ? `以 ${mid} 为折中点` : '分歧过大,需引入新维度' },
|
|
182
|
+
error: dealZone ? undefined : `立场分歧 ${spread} 过大,无协议区`, reason: dealZone ? undefined : 'PRECONDITION_FAILED',
|
|
183
|
+
provenance: [`[${t}] negotiation: ${ps.length} 方,分歧 ${spread},协议区 ${dealZone}`] };
|
|
184
|
+
}],
|
|
185
|
+
['PROTOCOL_OPPONENT_V1', '反者协议', 'compute',
|
|
186
|
+
['proposition', 'weight'], (inp, t) => {
|
|
187
|
+
const p = String(inp.proposition || '命题'), w = clamp01(inp.weight ?? 0.6);
|
|
188
|
+
return { success: true, kind: 'compute', output: { proposition: p, opposite: `非(${p})`, originalWeight: round(w), oppositeWeight: round(1 - w), rule: '反者道之动:反向权重 = 1 − 正向权重' },
|
|
189
|
+
provenance: [`[${t}] opponent: 「${p}」对偶权重 ${round(1 - w)}`] };
|
|
190
|
+
}],
|
|
191
|
+
['PROTOCOL_RG_V1', '规则治理协议', 'rule',
|
|
192
|
+
['rules'], (inp, t) => {
|
|
193
|
+
const rs = inp.rules || [];
|
|
194
|
+
if (!rs.length) return { success: false, kind: 'rule', reason: 'INVALID_INPUT', error: '必须提供 rules' };
|
|
195
|
+
const F = ['id', 'condition', 'action', 'priority'];
|
|
196
|
+
const bad = rs.map((r, i) => ({ i, m: F.filter((k) => r[k] === undefined) })).filter((x) => x.m.length);
|
|
197
|
+
const dupIds = rs.map((r) => r.id).filter((v, i, a) => a.indexOf(v) !== i);
|
|
198
|
+
const ok = bad.length === 0 && dupIds.length === 0;
|
|
199
|
+
return { success: ok, kind: 'rule', output: { rules: rs.length, incomplete: bad, duplicateIds: [...new Set(dupIds)] },
|
|
200
|
+
error: bad.length ? `${bad.length} 条规则字段不全` : dupIds.length ? `重复规则 ID:${[...new Set(dupIds)].join(',')}` : undefined,
|
|
201
|
+
reason: ok ? undefined : 'RULE_VIOLATED',
|
|
202
|
+
provenance: [`[${t}] rg: ${rs.length} 规则,不合格 ${bad.length},重复 ${dupIds.length}`] };
|
|
203
|
+
}],
|
|
204
|
+
['PROTOCOL_STRATEGY_V1', '战略协议', 'compute',
|
|
205
|
+
['dims'], (inp, t) => {
|
|
206
|
+
const d = inp.dims || {};
|
|
207
|
+
const D = ['tech', 'economy', 'institution', 'policy'];
|
|
208
|
+
const known = D.filter((k) => d[k] !== undefined);
|
|
209
|
+
if (!known.length) return { success: false, kind: 'compute', reason: 'INVALID_INPUT', error: `必须提供 ${D.join('/')} 至少一维` };
|
|
210
|
+
const score = round(mean(known.map((k) => clamp01(d[k]))));
|
|
211
|
+
return { success: score >= 0.6, kind: 'compute', output: { dimensions: D, provided: known, alignment: score, verdict: score >= 0.75 ? '可推' : score >= 0.6 ? '谨慎推' : '不宜推' },
|
|
212
|
+
error: score < 0.6 ? `战略适配 ${score} < 0.6` : undefined, reason: score < 0.6 ? 'PRECONDITION_FAILED' : undefined,
|
|
213
|
+
provenance: [`[${t}] strategy: ${known.length}/4 维,适配 ${score}`] };
|
|
214
|
+
}],
|
|
215
|
+
['PROTOCOL_TIME_RECON_V1', '时间重构协议', 'compute',
|
|
216
|
+
['events'], (inp, t) => {
|
|
217
|
+
const ev = inp.events || [];
|
|
218
|
+
if (!ev.length) return { success: false, kind: 'compute', reason: 'INVALID_INPUT', error: '必须提供 events' };
|
|
219
|
+
const sorted = [...ev].sort((a, b) => String(a.timestamp).localeCompare(String(b.timestamp)));
|
|
220
|
+
const monotonic = ev.every((e, i) => i === 0 || String(e.timestamp) >= String(ev[i - 1].timestamp));
|
|
221
|
+
const overlaps = [];
|
|
222
|
+
for (let i = 1; i < sorted.length; i++) if (sorted[i].start && sorted[i - 1].end && sorted[i].start < sorted[i - 1].end) overlaps.push([i - 1, i]);
|
|
223
|
+
return { success: monotonic && overlaps.length === 0, kind: 'compute', output: { events: ev.length, monotonic, overlaps: overlaps.length, reconstructed: monotonic && overlaps.length === 0 },
|
|
224
|
+
error: !monotonic ? '时间戳非单调' : overlaps.length ? `${overlaps.length} 处时间冲突` : undefined,
|
|
225
|
+
reason: (!monotonic || overlaps.length) ? 'PRECONDITION_FAILED' : undefined,
|
|
226
|
+
provenance: [`[${t}] time-recon: ${ev.length} 事件,单调 ${monotonic},冲突 ${overlaps.length}`] };
|
|
227
|
+
}],
|
|
228
|
+
];
|
|
229
|
+
|
|
230
|
+
for (const [id, name, kind, fields, fn] of GAP_P) {
|
|
231
|
+
addP({ id, name, kind, src: '缺口 29(根文档/17 文件);依名称语义 + 元构通用模式实现', implements: [fields.length ? `判据:${fields.join('/')}` : '语义检测'], exec: fn });
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/* ══════════ 二、2 条缺失引擎 ══════════ */
|
|
235
|
+
addE({
|
|
236
|
+
id: 'ENGINE_GLOBAL_AWARENESS_166', name: '全球态势感知引擎', kind: 'compute',
|
|
237
|
+
src: '第4部分(对应 PROTOCOL_GLOBAL_AWARENESS_V1)', implements: ['六维态势加权 + 风险识别'],
|
|
238
|
+
exec(inp, t) {
|
|
239
|
+
const D = ['地缘', '经济', '技术', '环境', '社会', '安全'];
|
|
240
|
+
const v = inp.dims || {};
|
|
241
|
+
const known = D.filter((k) => v[k] !== undefined);
|
|
242
|
+
if (!known.length) return { success: false, kind: 'compute', reason: 'INVALID_INPUT', error: `必须提供 ${D.join('/')} 至少一维` };
|
|
243
|
+
const overall = round(mean(known.map((k) => clamp01(v[k]))));
|
|
244
|
+
const risks = known.filter((k) => clamp01(v[k]) < 0.4).map((k) => ({ dim: k, value: v[k] }));
|
|
245
|
+
return { success: known.length === D.length, kind: 'compute', output: { dimensions: D, provided: known, overall, risks, complete: known.length === D.length },
|
|
246
|
+
error: known.length < D.length ? `缺维度:${D.filter((k) => v[k] === undefined).join('/')}` : undefined,
|
|
247
|
+
reason: known.length < D.length ? 'PRECONDITION_FAILED' : undefined,
|
|
248
|
+
provenance: [`[${t}] global-awareness-engine: ${known.length}/6 维,综合 ${overall}`] };
|
|
249
|
+
},
|
|
250
|
+
});
|
|
251
|
+
addE({
|
|
252
|
+
id: 'ENGINE_RECURSIVE_ENCAPSULATE_26', name: '递归封装引擎', kind: 'pipeline',
|
|
253
|
+
src: '附录卷-第2部分 L6286', implements: ['四步:标准化转换→生成接口→预计算耦生度→纳入能力库'],
|
|
254
|
+
exec(inp, t) {
|
|
255
|
+
const cap = inp.capability;
|
|
256
|
+
if (!cap || !cap.id) return { success: false, kind: 'pipeline', reason: 'INVALID_INPUT', error: '必须提供含 id 的 capability' };
|
|
257
|
+
const STEPS = ['标准化转换', '生成接口', '预计算耦生度', '纳入能力库'];
|
|
258
|
+
const coupling = round(clamp01(inp.precomputedCoupling ?? 0.75));
|
|
259
|
+
return { success: true, kind: 'pipeline', output: { steps: STEPS, interface: { id: cap.id, name: cap.name, inputs: cap.inputs || [], outputs: cap.outputs || [] }, coupling, libraryEntry: cap.id, layer: 'L8创新创造层' },
|
|
260
|
+
provenance: [`[${t}] recursive-encapsulate: ${cap.id} 封装,耦生 ${coupling}`] };
|
|
261
|
+
},
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
/* ══════════ 运行时 ══════════ */
|
|
265
|
+
const mk = (arr, idKey) => {
|
|
266
|
+
const INDEX = new Map(arr.map((x) => [x.id, x]));
|
|
267
|
+
return {
|
|
268
|
+
INDEX,
|
|
269
|
+
kindOf: (id) => { const x = INDEX.get(id); return x ? x.kind : 'declared'; },
|
|
270
|
+
getRegistry: () => arr.map((x) => ({ id: x.id, name: x.name, kind: x.kind, src: x.src, implements: x.implements || [] })),
|
|
271
|
+
executeSync(id, input) {
|
|
272
|
+
const t0 = Date.now(), t = tid();
|
|
273
|
+
const x = INDEX.get(id);
|
|
274
|
+
if (!x) return { success: false, kind: 'declared', reason: 'NOT_FOUND', error: `${id} 未登记`, provenance: [], traceId: t, durationMs: 0 };
|
|
275
|
+
let r;
|
|
276
|
+
try { r = x.exec(input || {}, t); } catch (e) { r = { success: false, kind: x.kind, error: 'THROW: ' + e.message, provenance: [`[${t}] THROW`] }; }
|
|
277
|
+
return { ...r, traceId: t, durationMs: Date.now() - t0 };
|
|
278
|
+
},
|
|
279
|
+
};
|
|
280
|
+
};
|
|
281
|
+
const RT = mk(P);
|
|
282
|
+
const ET = mk(E);
|
|
283
|
+
|
|
284
|
+
module.exports = {
|
|
285
|
+
PROTOCOLS: P, ENGINES: E,
|
|
286
|
+
executeProtocolSync: RT.executeSync, getProtocolRegistry: RT.getRegistry, kindOfProtocol: RT.kindOf,
|
|
287
|
+
executeEngineSync: ET.executeSync, getEngineRegistry: ET.getRegistry, kindOfEngine: ET.kindOf,
|
|
288
|
+
};
|