@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,680 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* P6-B10 · 协议收尾批(49 条)—— 实现后协议层达 130/150 = 86.7%
|
|
4
|
+
* 数学族协议复用 B8 引擎(单一真相源);其余依 definitionText 条款实现。
|
|
5
|
+
*/
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
let __seq = 0;
|
|
9
|
+
const tidGen = (tag) => () => {
|
|
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())}-${tag}${p((++__seq) % 10000, 4)}`;
|
|
12
|
+
};
|
|
13
|
+
const tid = tidGen('X');
|
|
14
|
+
const clamp01 = (x) => Math.max(0, Math.min(1, Number(x) || 0));
|
|
15
|
+
const round = (x, n = 6) => Math.round((Number(x) || 0) * 10 ** n) / 10 ** n;
|
|
16
|
+
const mean = (a) => (a.length ? a.reduce((s, x) => s + (Number(x) || 0), 0) / a.length : 0);
|
|
17
|
+
const req = (o, ks) => ks.filter((k) => !o || o[k] === undefined || o[k] === null);
|
|
18
|
+
|
|
19
|
+
/** 委托到引擎运行时(跨 B8/B9 解析,单一真相源) */
|
|
20
|
+
const ENGINE_RTS = [];
|
|
21
|
+
for (const f of ['math-capability-runtime', 'governance-runtime', 'philosophy-runtime', 'engine-runtime']) {
|
|
22
|
+
try { ENGINE_RTS.push(require('./../ENGINES/' + f + '.cjs')); } catch (e) { /* 可选模块 */ }
|
|
23
|
+
}
|
|
24
|
+
function delegateEngine(eid, inp, t) {
|
|
25
|
+
for (const rt of ENGINE_RTS) {
|
|
26
|
+
if (rt.INDEX && rt.INDEX.has(eid)) {
|
|
27
|
+
const r = rt.executeSync(eid, inp);
|
|
28
|
+
return { ...r, provenance: [...(r.provenance || []), `[${t}] 委托 ${eid}(${rt.getRegistry ? '已注册' : 'ok'})`] };
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return { success: false, kind: 'compute', reason: 'DEPENDENCY_MISSING', error: `引擎 ${eid} 在所有运行时中均未登记`, provenance: [`[${t}] 委托失败 ${eid}`] };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const P = [];
|
|
35
|
+
const add = (o) => P.push(o);
|
|
36
|
+
|
|
37
|
+
/* ══════ 一、数学族协议 8 条(委托 B8 引擎)══════ */
|
|
38
|
+
const MATH_MAP = [
|
|
39
|
+
['PROTOCOL_COMPLEX_INTEGRAL_V1', '复分析积分计算协议', 'ENGINE_COMPLEX_INTEGRAL_47', '第部分 §2.1 表行 888 字符'],
|
|
40
|
+
['PROTOCOL_ZERO_DENSITY_V1', '零点密度推理协议', 'ENGINE_ZERO_DENSITY_49', '第部分 §2.1 表行 888 字符'],
|
|
41
|
+
['PROTOCOL_PROOF_STRATEGY_V1', '证明策略协作协议', 'ENGINE_PROOF_STRATEGY_51', '第部分 §2.2 表行 888 字符'],
|
|
42
|
+
['PROTOCOL_INTEGRAL_SYMMETRY_V2', '积分对称性增强协议', 'ENGINE_SYMMETRY_AUTO_55', '第部分 §2.2 表行 888 字符(V16.4)'],
|
|
43
|
+
['PROTOCOL_META_ANALYSIS_V1', '元数学分析协议', 'ENGINE_META_MATH_67', '第部分 §2.2 表行 888 字符(V17.0-TP)'],
|
|
44
|
+
];
|
|
45
|
+
for (const [pid, pname, eid, src] of MATH_MAP) {
|
|
46
|
+
add({
|
|
47
|
+
id: pid, name: pname, kind: 'compute', src,
|
|
48
|
+
implements: [`委托引擎 ${eid}(单一真相源,避免两套标准)`],
|
|
49
|
+
exec(inp, t) {
|
|
50
|
+
const r = delegateEngine(eid, inp, t);
|
|
51
|
+
return { ...r, provenance: [...(r.provenance || []), `[${t}] ${pid} → 委托 ${eid}`] };
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/* ══════ 二、世界模型族 6 条 ══════ */
|
|
57
|
+
add({
|
|
58
|
+
id: 'PROTOCOL_WORLD_SIM_V1', name: '世界模拟协议', kind: 'compute', src: 'yaml-block 823 字符',
|
|
59
|
+
implements: ['状态转移模拟(s_{t+1} = T(s_t, a_t))+ 轨迹记录'],
|
|
60
|
+
exec(inp, t) {
|
|
61
|
+
const s0 = inp.initialState, actions = inp.actions || [], T = inp.transition;
|
|
62
|
+
if (!Array.isArray(s0)) return { success: false, kind: 'compute', reason: 'INVALID_INPUT', error: '必须提供 initialState 数组' };
|
|
63
|
+
if (typeof T !== 'function' && !inp.transitionTable) return { success: false, kind: 'compute', reason: 'INVALID_INPUT', error: '必须提供 transition 函数或 transitionTable' };
|
|
64
|
+
let s = [...s0]; const traj = [{ step: 0, state: [...s], action: null }];
|
|
65
|
+
for (let i = 0; i < actions.length; i++) {
|
|
66
|
+
const a = actions[i];
|
|
67
|
+
s = typeof T === 'function' ? T(s, a) : (inp.transitionTable[a] || s);
|
|
68
|
+
traj.push({ step: i + 1, state: [...s], action: a });
|
|
69
|
+
}
|
|
70
|
+
return { success: true, kind: 'compute', output: { steps: actions.length, trajectory: traj, finalState: s, formula: 's_{t+1} = T(s_t, a_t)' },
|
|
71
|
+
provenance: [`[${t}] world-sim: ${actions.length} 步模拟`] };
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
add({
|
|
75
|
+
id: 'PROTOCOL_WORLD_SIM_EVO_V1', name: '世界模型进化协同协议', kind: 'pipeline', src: 'yaml-block 764 字符',
|
|
76
|
+
implements: ['四步:模拟→偏差检测→模型更新→再验证'],
|
|
77
|
+
exec(inp, t) {
|
|
78
|
+
const need = ['prediction', 'observation', 'update', 'revalidation'];
|
|
79
|
+
const miss = req(inp, need);
|
|
80
|
+
const ok = miss.length === 0;
|
|
81
|
+
return { success: ok, kind: 'pipeline', output: { steps: need, missing: miss }, error: ok ? undefined : `进化协同缺:${miss.join('/')}`, reason: ok ? undefined : 'PRECONDITION_FAILED',
|
|
82
|
+
provenance: [`[${t}] world-sim-evo: ${4 - miss.length}/4`] };
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
add({
|
|
86
|
+
id: 'PROTOCOL_WORLD_SIM_EVO_V2', name: '世界模拟演化协议', kind: 'compute', src: 'table-row 274 字符',
|
|
87
|
+
implements: ['演化度 = 1 − 预测误差率'],
|
|
88
|
+
exec(inp, t) {
|
|
89
|
+
const err = clamp01(inp.predictionError ?? 0.2);
|
|
90
|
+
return { success: true, kind: 'compute', output: { predictionError: err, evolutionScore: round(1 - err), formula: '演化度 = 1 − 预测误差率', threshold: 0.8, pass: 1 - err >= 0.8 },
|
|
91
|
+
provenance: [`[${t}] world-sim-evo-v2: 误差 ${err} → 演化度 ${round(1 - err)}`] };
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
add({
|
|
95
|
+
id: 'PROTOCOL_WORLD_SIM_EVO_V3', name: '世界模型进化协同协议 V3.0', kind: 'rule', src: 'yaml-block 490 字符',
|
|
96
|
+
implements: ['V3 新增:多模型协同演化 + 一致性校验'],
|
|
97
|
+
exec(inp, t) {
|
|
98
|
+
const models = inp.models || [];
|
|
99
|
+
if (models.length < 2) return { success: false, kind: 'rule', reason: 'INVALID_INPUT', error: 'V3 要求至少 2 个世界模型协同' };
|
|
100
|
+
const accs = models.map((m) => clamp01(m.accuracy ?? 0.5));
|
|
101
|
+
const spread = Math.max(...accs) - Math.min(...accs);
|
|
102
|
+
const consistent = spread <= Number(inp.consistencyThreshold ?? 0.2);
|
|
103
|
+
return { success: consistent, kind: 'rule', output: { models: models.length, accuracies: accs, spread: round(spread), consistent, ensembleAccuracy: round(mean(accs)) },
|
|
104
|
+
error: consistent ? undefined : `模型精度分歧 ${round(spread)} > 阈值`, reason: consistent ? undefined : 'RULE_VIOLATED',
|
|
105
|
+
provenance: [`[${t}] world-sim-evo-v3: ${models.length} 模型,分歧 ${round(spread)}`] };
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
add({
|
|
109
|
+
id: 'PROTOCOL_WORLD_SIM_SAFE_V1', name: '世界模型安全验证协议', kind: 'rule', src: 'yaml-block 804 字符',
|
|
110
|
+
implements: ['四项安全验证(越界/不可逆/欺骗/失控)'],
|
|
111
|
+
exec(inp, t) {
|
|
112
|
+
const CHECKS = ['noOverreach', 'noIrreversible', 'noDeception', 'noLossOfControl'];
|
|
113
|
+
const res = CHECKS.map((k) => ({ check: k, passed: inp[k] === true }));
|
|
114
|
+
const failed = res.filter((r) => !r.passed).map((r) => r.check);
|
|
115
|
+
return { success: failed.length === 0, kind: 'rule', output: { checks: res, failed }, error: failed.length ? `世界模型安全验证未过:${failed.join('/')}` : undefined,
|
|
116
|
+
reason: failed.length ? 'RULE_VIOLATED' : undefined, provenance: [`[${t}] world-sim-safe: ${4 - failed.length}/4`] };
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
add({
|
|
120
|
+
id: 'PROTOCOL_WORLD_CLOSED_LOOP_V1', name: '世界模型实时闭环协同协议', kind: 'compute', src: 'yaml-block 542 字符',
|
|
121
|
+
implements: ['闭环延迟 = 感知 + 推理 + 执行;须 < 预算'],
|
|
122
|
+
exec(inp, t) {
|
|
123
|
+
const sense = Number(inp.senseMs ?? 10), think = Number(inp.thinkMs ?? 20), act = Number(inp.actMs ?? 15);
|
|
124
|
+
const budget = Number(inp.budgetMs ?? 50);
|
|
125
|
+
const total = sense + think + act;
|
|
126
|
+
return { success: total <= budget, kind: 'compute', output: { senseMs: sense, thinkMs: think, actMs: act, totalMs: total, budgetMs: budget, closed: total <= budget,
|
|
127
|
+
formula: '总延迟 = 感知 + 推理 + 执行 ≤ 预算' },
|
|
128
|
+
error: total > budget ? `闭环延迟 ${total}ms > 预算 ${budget}ms` : undefined,
|
|
129
|
+
reason: total > budget ? 'PRECONDITION_FAILED' : undefined,
|
|
130
|
+
provenance: [`[${t}] world-closed-loop: ${total}/${budget}ms`] };
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
/* ══════ 三、价值族 3 条 ══════ */
|
|
135
|
+
add({
|
|
136
|
+
id: 'PROTOCOL_VALUE_METRICS_V1', name: '价值度量协议', kind: 'formula', src: 'table-row 888 字符(V18.0)',
|
|
137
|
+
implements: ['31 维加权求和 V_total = Σ(W_i × V_i)', '超导态判定(>0.85)'],
|
|
138
|
+
exec(inp, t) {
|
|
139
|
+
const dims = inp.dimensions;
|
|
140
|
+
if (!dims || typeof dims !== 'object') return { success: false, kind: 'formula', reason: 'INVALID_INPUT', error: '必须提供 dimensions 对象(维度名→0-1 值)' };
|
|
141
|
+
const W = { 国家战略:0.035, 产教双轨:0.030, 乡村振兴:0.030, 无障碍包容:0.025, 区块链贡献:0.030, 联邦学习:0.030, 社会主义伦理:0.040, 共同富裕:0.030, 数据要素:0.030, 安全发展:0.040, 文化强国:0.025, 区域协调:0.025, 科学进步:0.030, 符号连接耦生:0.030, 群体单体耦生:0.030, 物理数字耦生:0.035, 人机耦合度:0.035, 群体智能度:0.030, 耦生深度:0.030, 创造贡献:0.035, 保护贡献:0.030, 负熵贡献:0.040, 生物元:0.025, 量子元:0.025, 宇宙元:0.020, 融合元:0.030, 归无元:0.025, 永恒元:0.025, 溯源深度:0.035, ROI周期:0.035, 客户价值实现度:0.035 };
|
|
142
|
+
const keys = Object.keys(W);
|
|
143
|
+
const given = keys.filter((k) => dims[k] !== undefined);
|
|
144
|
+
if (!given.length) return { success: false, kind: 'formula', reason: 'INVALID_INPUT', error: '未提供任何已登记的 31 维名称' };
|
|
145
|
+
const sumW = given.reduce((s, k) => s + W[k], 0);
|
|
146
|
+
const V = round(given.reduce((s, k) => s + W[k] * clamp01(dims[k]), 0) / sumW);
|
|
147
|
+
return { success: true, kind: 'formula', output: { evaluatedDims: given.length, totalDims: 31, V_total: V, superconductive: V > 0.85,
|
|
148
|
+
formula: 'V_total = Σ(W_i × V_i) / ΣW_i(按已提供维度归一);>0.85 为超导态', missingDims: keys.filter((k) => dims[k] === undefined) },
|
|
149
|
+
provenance: [`[${t}] value-metrics: ${given.length}/31 维 → V=${V}`] };
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
add({
|
|
153
|
+
id: 'PROTOCOL_VALUE_PREDICT_V1', name: '价值预测协议', kind: 'compute', src: 'yaml-block 740 字符',
|
|
154
|
+
implements: ['线性趋势外推 + 置信区间'],
|
|
155
|
+
exec(inp, t) {
|
|
156
|
+
const s = inp.history;
|
|
157
|
+
if (!Array.isArray(s) || s.length < 2) return { success: false, kind: 'compute', reason: 'INVALID_INPUT', error: '必须提供长度≥2 的 history' };
|
|
158
|
+
const n = s.length, xs = s.map((_, i) => i), ys = s.map(Number);
|
|
159
|
+
const mx = mean(xs), my = mean(ys);
|
|
160
|
+
const slope = xs.reduce((acc, x, i) => acc + (x - mx) * (ys[i] - my), 0) / (xs.reduce((acc, x) => acc + (x - mx) ** 2, 0) || 1);
|
|
161
|
+
const k = Number(inp.horizon ?? 3);
|
|
162
|
+
const pred = round(my + slope * (n - 1 + k - mx));
|
|
163
|
+
const resid = ys.map((y, i) => y - (my + slope * (xs[i] - mx)));
|
|
164
|
+
const sd = Math.sqrt(resid.reduce((a, r) => a + r * r, 0) / Math.max(1, n - 2));
|
|
165
|
+
return { success: true, kind: 'compute', output: { points: n, slope: round(slope), intercept: round(my - slope * mx), horizon: k, prediction: pred, residualSd: round(sd), ci95: [round(pred - 1.96 * sd), round(pred + 1.96 * sd)], caveat: '线性外推,趋势转折时失效' },
|
|
166
|
+
provenance: [`[${t}] value-predict: 斜率 ${round(slope)},${k} 步后 ${pred}`] };
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
add({
|
|
170
|
+
id: 'PROTOCOL_VALUE_REALIZE_V1', name: '价值实现协议', kind: 'pipeline', src: 'table-row 888 字符(V18.0)',
|
|
171
|
+
implements: ['猜想→价值转换四步(验证→量化→确权→入账)'],
|
|
172
|
+
exec(inp, t) {
|
|
173
|
+
const need = ['verified', 'quantified', 'attributed', 'recorded'];
|
|
174
|
+
const miss = need.filter((k) => !(inp && inp[k]));
|
|
175
|
+
const ok = miss.length === 0;
|
|
176
|
+
return { success: ok, kind: 'pipeline', output: { steps: need, missing: miss, value: inp.value ?? null },
|
|
177
|
+
error: ok ? undefined : `价值实现缺步骤:${miss.join('/')}`, reason: ok ? undefined : 'PRECONDITION_FAILED',
|
|
178
|
+
provenance: [`[${t}] value-realize: ${4 - miss.length}/4`] };
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
/* ══════ 四、A2A / 交易 / Token 5 条 ══════ */
|
|
183
|
+
add({
|
|
184
|
+
id: 'PROTOCOL_A2A_NATIVE_V1', name: 'A2A原生兼容协议', kind: 'rule', src: 'yaml-block 512 字符',
|
|
185
|
+
implements: ['A2A 消息三要素(from/to/payload)+ 能力声明校验'],
|
|
186
|
+
exec(inp, t) {
|
|
187
|
+
const m = inp.message || {};
|
|
188
|
+
const miss = ['from', 'to', 'payload'].filter((k) => m[k] === undefined);
|
|
189
|
+
const caps = inp.capabilityDeclaration || [];
|
|
190
|
+
const ok = miss.length === 0 && caps.length > 0;
|
|
191
|
+
return { success: ok, kind: 'rule', output: { requiredFields: ['from', 'to', 'payload'], missing: miss, capabilityDeclared: caps.length },
|
|
192
|
+
error: miss.length ? `A2A 消息缺:${miss.join('/')}` : caps.length === 0 ? '未声明能力,A2A 无法路由' : undefined,
|
|
193
|
+
reason: ok ? undefined : 'RULE_VIOLATED', provenance: [`[${t}] a2a-native: ${ok ? '兼容' : '不合规'}`] };
|
|
194
|
+
},
|
|
195
|
+
});
|
|
196
|
+
add({
|
|
197
|
+
id: 'PROTOCOL_A2A_AUTO_TRADE_V1', name: 'A2A自动交易协议', kind: 'rule', src: 'table-row 315 字符',
|
|
198
|
+
implements: ['交易前置:层级差披露 + 托管 + 限额'],
|
|
199
|
+
exec(inp, t) {
|
|
200
|
+
const gap = Math.abs(Number(inp.tierA ?? 0) - Number(inp.tierB ?? 0));
|
|
201
|
+
const escrow = inp.escrowUsed === true;
|
|
202
|
+
const amount = Number(inp.amount ?? 0), limit = Number(inp.limit ?? 1000);
|
|
203
|
+
const disclosed = inp.tierDisclosed === true;
|
|
204
|
+
const fails = [];
|
|
205
|
+
if (!disclosed) fails.push('未披露层级差');
|
|
206
|
+
if (!escrow && amount > limit * 0.5) fails.push('超过限额一半但未用托管');
|
|
207
|
+
if (amount > limit) fails.push('超出交易限额');
|
|
208
|
+
return { success: fails.length === 0, kind: 'rule', output: { tierGap: round(gap), tierDisclosed: disclosed, escrowUsed: escrow, amount, limit, failReasons: fails },
|
|
209
|
+
error: fails.length ? fails.join(';') : undefined, reason: fails.length ? 'RULE_VIOLATED' : undefined,
|
|
210
|
+
provenance: [`[${t}] a2a-trade: 金额 ${amount}/${limit},托管 ${escrow},${fails.length ? '拒绝' : '允许'}`] };
|
|
211
|
+
},
|
|
212
|
+
});
|
|
213
|
+
add({
|
|
214
|
+
id: 'PROTOCOL_ESCROW_SETTLE_V1', name: '托管结算协议', kind: 'pipeline', src: 'yaml-block 496 字符',
|
|
215
|
+
implements: ['五步结算(锁仓→交付确认→验收→放款→对账)'],
|
|
216
|
+
exec(inp, t) {
|
|
217
|
+
const need = ['locked', 'delivered', 'accepted', 'released', 'reconciled'];
|
|
218
|
+
const miss = need.filter((k) => !(inp && inp[k]));
|
|
219
|
+
const ok = miss.length === 0;
|
|
220
|
+
return { success: ok, kind: 'pipeline', output: { steps: need, missing: miss, amount: inp.amount ?? null },
|
|
221
|
+
error: ok ? undefined : `结算未完成,缺:${miss.join('/')}`, reason: ok ? undefined : 'PRECONDITION_FAILED',
|
|
222
|
+
provenance: [`[${t}] escrow-settle: ${5 - miss.length}/5`] };
|
|
223
|
+
},
|
|
224
|
+
});
|
|
225
|
+
add({
|
|
226
|
+
id: 'PROTOCOL_TOKEN_ECONOMY_V1', name: '全面Token经济激活协议', kind: 'compute', src: 'yaml-block 589 字符',
|
|
227
|
+
implements: ['Token 发行/流通/回收三率 + 通缩判定'],
|
|
228
|
+
exec(inp, t) {
|
|
229
|
+
const issued = Number(inp.issued ?? 0), circulated = Number(inp.circulated ?? 0), burned = Number(inp.burned ?? 0);
|
|
230
|
+
if (issued <= 0) return { success: false, kind: 'compute', reason: 'INVALID_INPUT', error: 'issued 必须 > 0' };
|
|
231
|
+
const circRate = round(clamp01(circulated / issued));
|
|
232
|
+
const burnRate = round(clamp01(burned / issued));
|
|
233
|
+
const netSupply = round(issued - burned);
|
|
234
|
+
const deflationary = burnRate > 0.05;
|
|
235
|
+
return { success: true, kind: 'compute', output: { issued, circulated, burned, netSupply, circulationRate: circRate, burnRate, deflationary,
|
|
236
|
+
activationScore: round(circRate * 0.6 + (1 - Math.abs(burnRate - 0.05)) * 0.4) },
|
|
237
|
+
provenance: [`[${t}] token-economy: 流通 ${circRate} 销毁 ${burnRate},通缩 ${deflationary}`] };
|
|
238
|
+
},
|
|
239
|
+
});
|
|
240
|
+
add({
|
|
241
|
+
id: 'PROTOCOL_SKILL_MARKET_V1', name: 'Skill市场协议', kind: 'rule', src: 'yaml-block 272 字符',
|
|
242
|
+
implements: ['上架四要素(能力/定价/验证/许可)'],
|
|
243
|
+
exec(inp, t) {
|
|
244
|
+
const s = inp.skill || {};
|
|
245
|
+
const miss = ['capability', 'pricing', 'verification', 'license'].filter((k) => s[k] === undefined);
|
|
246
|
+
return { success: miss.length === 0, kind: 'rule', output: { requiredFields: ['capability', 'pricing', 'verification', 'license'], missing: miss },
|
|
247
|
+
error: miss.length ? `Skill 上架缺:${miss.join('/')}` : undefined, reason: miss.length ? 'RULE_VIOLATED' : undefined,
|
|
248
|
+
provenance: [`[${t}] skill-market: ${4 - miss.length}/4`] };
|
|
249
|
+
},
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
/* ══════ 五、工业族 3 条 ══════ */
|
|
253
|
+
add({
|
|
254
|
+
id: 'PROTOCOL_INDUSTRIAL_DEVICE_V1', name: '工业设备接入协议', kind: 'rule', src: 'yaml-block 243 字符',
|
|
255
|
+
implements: ['接入五要素(设备ID/协议/点表/安全/心跳)'],
|
|
256
|
+
exec(inp, t) {
|
|
257
|
+
const d = inp.device || {};
|
|
258
|
+
const miss = ['deviceId', 'protocol', 'pointTable', 'security', 'heartbeat'].filter((k) => d[k] === undefined);
|
|
259
|
+
return { success: miss.length === 0, kind: 'rule', output: { requiredFields: ['deviceId', 'protocol', 'pointTable', 'security', 'heartbeat'], missing: miss, protocol: d.protocol || null },
|
|
260
|
+
error: miss.length ? `设备接入缺:${miss.join('/')}` : undefined, reason: miss.length ? 'RULE_VIOLATED' : undefined,
|
|
261
|
+
provenance: [`[${t}] industrial-device: ${5 - miss.length}/5`] };
|
|
262
|
+
},
|
|
263
|
+
});
|
|
264
|
+
add({
|
|
265
|
+
id: 'PROTOCOL_INDUSTRY_DATA_V1', name: '工业数据交换协议', kind: 'rule', src: 'yaml-block 1185 字符',
|
|
266
|
+
implements: ['数据交换四校验(完整性/时效/单位/编码)'],
|
|
267
|
+
exec(inp, t) {
|
|
268
|
+
const d = inp.dataPacket || {};
|
|
269
|
+
const miss = ['timestamp', 'payload', 'unit', 'encoding'].filter((k) => d[k] === undefined);
|
|
270
|
+
const ageMs = Date.now() - (d.timestamp ? new Date(d.timestamp).getTime() : 0);
|
|
271
|
+
const stale = d.timestamp ? ageMs > Number(inp.maxAgeMs ?? 60000) : false;
|
|
272
|
+
const ok = miss.length === 0 && !stale;
|
|
273
|
+
return { success: ok, kind: 'rule', output: { requiredFields: ['timestamp', 'payload', 'unit', 'encoding'], missing: miss, ageMs: d.timestamp ? ageMs : null, stale },
|
|
274
|
+
error: miss.length ? `数据包缺:${miss.join('/')}` : stale ? `数据过期 ${ageMs}ms` : undefined,
|
|
275
|
+
reason: ok ? undefined : 'RULE_VIOLATED', provenance: [`[${t}] industry-data: ${ok ? '合规' : '不合规'}`] };
|
|
276
|
+
},
|
|
277
|
+
});
|
|
278
|
+
add({
|
|
279
|
+
id: 'PROTOCOL_SUPPLY_TRACE_V1', name: '供应链溯源协议', kind: 'compute', src: 'yaml-block 237 字符',
|
|
280
|
+
implements: ['溯源链完整性(哈希链)+ 断链检测'],
|
|
281
|
+
exec(inp, t) {
|
|
282
|
+
const chain = inp.chain || [];
|
|
283
|
+
if (!chain.length) return { success: false, kind: 'compute', reason: 'INVALID_INPUT', error: '必须提供 chain 数组' };
|
|
284
|
+
let broken = 0;
|
|
285
|
+
for (let i = 1; i < chain.length; i++) if (chain[i].prevHash !== chain[i - 1].hash) broken++;
|
|
286
|
+
const ok = broken === 0;
|
|
287
|
+
return { success: ok, kind: 'compute', output: { links: chain.length, brokenLinks: broken, complete: ok },
|
|
288
|
+
error: ok ? undefined : `${broken} 处断链`, reason: ok ? undefined : 'PRECONDITION_FAILED',
|
|
289
|
+
provenance: [`[${t}] supply-trace: ${chain.length} 环节,断链 ${broken}`] };
|
|
290
|
+
},
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
/* ══════ 六、安全族 4 条 ══════ */
|
|
294
|
+
add({
|
|
295
|
+
id: 'PROTOCOL_FIRMWARE_SEC_V1', name: '固件安全扫描协议', kind: 'rule', src: 'yaml-block 218 字符',
|
|
296
|
+
implements: ['固件四项扫描(签名/版本/CVE/完整性)'],
|
|
297
|
+
exec(inp, t) {
|
|
298
|
+
const f = inp.firmware || {};
|
|
299
|
+
const CHECKS = [
|
|
300
|
+
{ k: 'signed', ok: f.signed === true, label: '签名验证' },
|
|
301
|
+
{ k: 'versionCurrent', ok: f.versionCurrent === true, label: '版本最新' },
|
|
302
|
+
{ k: 'noKnownCve', ok: f.noKnownCve === true, label: '无已知 CVE' },
|
|
303
|
+
{ k: 'integrityOk', ok: f.integrityOk === true, label: '完整性校验' },
|
|
304
|
+
];
|
|
305
|
+
const failed = CHECKS.filter((c) => !c.ok).map((c) => c.label);
|
|
306
|
+
return { success: failed.length === 0, kind: 'rule', output: { checks: CHECKS, failed },
|
|
307
|
+
error: failed.length ? `固件扫描未过:${failed.join('/')}` : undefined, reason: failed.length ? 'RULE_VIOLATED' : undefined,
|
|
308
|
+
provenance: [`[${t}] firmware-sec: ${4 - failed.length}/4`] };
|
|
309
|
+
},
|
|
310
|
+
});
|
|
311
|
+
add({
|
|
312
|
+
id: 'PROTOCOL_KILL_CHAIN_MONITOR_V1', name: 'Promptware杀伤链监控协议', kind: 'rule', src: 'yaml-block 704 字符',
|
|
313
|
+
implements: ['七阶段杀伤链监控(侦察→武器化→投递→利用→安装→C2→行动)'],
|
|
314
|
+
exec(inp, t) {
|
|
315
|
+
const STAGES = ['侦察', '武器化', '投递', '利用', '安装', 'C2', '行动'];
|
|
316
|
+
const observed = inp.observedStages || [];
|
|
317
|
+
const hit = STAGES.filter((s) => observed.includes(s));
|
|
318
|
+
const level = hit.length >= 5 ? 'CRITICAL' : hit.length >= 3 ? 'HIGH' : hit.length >= 1 ? 'MEDIUM' : 'LOW';
|
|
319
|
+
return { success: level === 'LOW', kind: 'rule', output: { stages: STAGES, observed: hit, stageCount: hit.length, level,
|
|
320
|
+
recommendation: hit.length ? `在「${STAGES[Math.min(STAGES.length - 1, hit.length)]}」阶段阻断` : '无杀伤链迹象' },
|
|
321
|
+
error: level !== 'LOW' ? `检出杀伤链 ${hit.length} 阶段(${level})` : undefined,
|
|
322
|
+
reason: level !== 'LOW' ? 'RULE_VIOLATED' : undefined,
|
|
323
|
+
provenance: [`[${t}] kill-chain: ${hit.length}/7 阶段 → ${level}`] };
|
|
324
|
+
},
|
|
325
|
+
});
|
|
326
|
+
add({
|
|
327
|
+
id: 'PROTOCOL_SALTING_DEFENSE_V1', name: 'LLM Salting安全轮换协议', kind: 'rule', src: 'yaml-block 704 字符',
|
|
328
|
+
implements: ['盐值轮换(周期/熵/唯一性)'],
|
|
329
|
+
exec(inp, t) {
|
|
330
|
+
const age = Number(inp.saltAgeHours ?? 0), period = Number(inp.rotationPeriodHours ?? 24);
|
|
331
|
+
const entropy = Number(inp.saltEntropyBits ?? 128), minEntropy = Number(inp.minEntropyBits ?? 128);
|
|
332
|
+
const reused = inp.reused === true;
|
|
333
|
+
const fails = [];
|
|
334
|
+
if (age > period) fails.push(`盐值已用 ${age}h > 周期 ${period}h`);
|
|
335
|
+
if (entropy < minEntropy) fails.push(`熵 ${entropy} < ${minEntropy} bits`);
|
|
336
|
+
if (reused) fails.push('盐值重复使用');
|
|
337
|
+
return { success: fails.length === 0, kind: 'rule', output: { saltAgeHours: age, rotationPeriodHours: period, entropyBits: entropy, minEntropyBits: minEntropy, reused, fails },
|
|
338
|
+
error: fails.length ? fails.join(';') : undefined, reason: fails.length ? 'RULE_VIOLATED' : undefined,
|
|
339
|
+
provenance: [`[${t}] salting: ${fails.length ? '需轮换' : '合规'}`] };
|
|
340
|
+
},
|
|
341
|
+
});
|
|
342
|
+
add({
|
|
343
|
+
id: 'PROTOCOL_IMMUNE_NETWORK_V1', name: '免疫网络同步协议', kind: 'compute', src: 'yaml-block 1143 字符',
|
|
344
|
+
implements: ['免疫覆盖率 + 同步延迟 + 冲突决议'],
|
|
345
|
+
exec(inp, t) {
|
|
346
|
+
const nodes = inp.nodes || [];
|
|
347
|
+
if (!nodes.length) return { success: false, kind: 'compute', reason: 'INVALID_INPUT', error: '必须提供 nodes 数组' };
|
|
348
|
+
const synced = nodes.filter((n) => n.synced === true).length;
|
|
349
|
+
const coverage = round(synced / nodes.length);
|
|
350
|
+
const maxDelay = Math.max(...nodes.map((n) => Number(n.delayMs ?? 0)));
|
|
351
|
+
const budget = Number(inp.delayBudgetMs ?? 5000);
|
|
352
|
+
return { success: coverage >= 0.95 && maxDelay <= budget, kind: 'compute', output: { nodes: nodes.length, synced, coverage, maxDelayMs: maxDelay, delayBudgetMs: budget, conflicts: nodes.filter((n) => n.conflict === true).length },
|
|
353
|
+
error: coverage < 0.95 ? `免疫覆盖率 ${coverage} < 0.95` : maxDelay > budget ? `同步延迟 ${maxDelay}ms > ${budget}ms` : undefined,
|
|
354
|
+
reason: (coverage < 0.95 || maxDelay > budget) ? 'PRECONDITION_FAILED' : undefined,
|
|
355
|
+
provenance: [`[${t}] immune-network: 覆盖 ${coverage},最大延迟 ${maxDelay}ms`] };
|
|
356
|
+
},
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
/* ══════ 七、组织/智能体 4 条 ══════ */
|
|
360
|
+
add({
|
|
361
|
+
id: 'PROTOCOL_ORG_AGENT_V2', name: '组织智能体演进协议', kind: 'pipeline', src: 'yaml-block 1215 字符',
|
|
362
|
+
implements: ['四阶段演进(工具化→协同化→自主化→共生化)'],
|
|
363
|
+
exec(inp, t) {
|
|
364
|
+
const STAGES = ['工具化', '协同化', '自主化', '共生化'];
|
|
365
|
+
const cur = String(inp.stage || '');
|
|
366
|
+
if (!STAGES.includes(cur)) return { success: false, kind: 'pipeline', reason: 'INVALID_INPUT', error: `stage 须为 ${STAGES.join('/')}` };
|
|
367
|
+
const i = STAGES.indexOf(cur);
|
|
368
|
+
return { success: true, kind: 'pipeline', output: { stage: cur, level: i + 1, stages: STAGES, next: STAGES[i + 1] || null, final: i === 3 },
|
|
369
|
+
provenance: [`[${t}] org-agent: ${cur} (${i + 1}/4)`] };
|
|
370
|
+
},
|
|
371
|
+
});
|
|
372
|
+
add({
|
|
373
|
+
id: 'PROTOCOL_ENCAPSULATE_V1', name: '组织封装协议', kind: 'rule', src: 'yaml-block 783 字符',
|
|
374
|
+
implements: ['封装五要素(边界/接口/权限/审计/退出)'],
|
|
375
|
+
exec(inp, t) {
|
|
376
|
+
const o = inp.org || {};
|
|
377
|
+
const miss = ['boundary', 'interface', 'permission', 'audit', 'exit'].filter((k) => o[k] === undefined);
|
|
378
|
+
return { success: miss.length === 0, kind: 'rule', output: { requiredFields: ['boundary', 'interface', 'permission', 'audit', 'exit'], missing: miss },
|
|
379
|
+
error: miss.length ? `组织封装缺:${miss.join('/')}` : undefined, reason: miss.length ? 'RULE_VIOLATED' : undefined,
|
|
380
|
+
provenance: [`[${t}] encapsulate: ${5 - miss.length}/5`] };
|
|
381
|
+
},
|
|
382
|
+
});
|
|
383
|
+
add({
|
|
384
|
+
id: 'PROTOCOL_HUMAN_ORG_AGENT_V1', name: '人-组织智能体共生协议', kind: 'compute', src: 'yaml-block 1060 字符',
|
|
385
|
+
implements: ['三元耦生度 = 人×组织×智能体(几何平均)'],
|
|
386
|
+
exec(inp, t) {
|
|
387
|
+
const h = clamp01(inp.humanCoupling ?? 0.8), o = clamp01(inp.orgCoupling ?? 0.75), a = clamp01(inp.agentCoupling ?? 0.7);
|
|
388
|
+
const tri = round(Math.cbrt(h * o * a));
|
|
389
|
+
const thr = Number(inp.threshold ?? 0.7);
|
|
390
|
+
return { success: tri >= thr, kind: 'compute', output: { human: h, org: o, agent: a, tripleCoupling: tri, threshold: thr, symbiotic: tri >= thr,
|
|
391
|
+
formula: '三元耦生度 = ∛(人 × 组织 × 智能体)' },
|
|
392
|
+
provenance: [`[${t}] human-org-agent: ∛(${h}×${o}×${a}) = ${tri}`] };
|
|
393
|
+
},
|
|
394
|
+
});
|
|
395
|
+
add({
|
|
396
|
+
id: 'PROTOCOL_AGENTIVE_DIFFERENTIATION_V1', name: 'Agentive OS 品类定义与差异化验证协议', kind: 'rule', src: 'yaml-block 938 字符',
|
|
397
|
+
implements: ['五维差异化(OS性/原生性/智能原生/自主性/生态性)'],
|
|
398
|
+
exec(inp, t) {
|
|
399
|
+
const DIM = ['osNativity', 'agentNative', 'intelligenceNative', 'autonomy', 'ecosystem'];
|
|
400
|
+
const d = inp.dimensions || {};
|
|
401
|
+
const scores = DIM.map((k) => ({ dim: k, score: d[k] === undefined ? null : clamp01(d[k]) }));
|
|
402
|
+
const known = scores.filter((s) => s.score !== null);
|
|
403
|
+
const avg = known.length ? round(mean(known.map((s) => s.score))) : null;
|
|
404
|
+
const ok = known.length === DIM.length && avg >= 0.7;
|
|
405
|
+
return { success: ok, kind: 'rule', output: { dimensions: scores, average: avg, threshold: 0.7, qualifies: ok },
|
|
406
|
+
error: known.length < DIM.length ? `缺维度:${DIM.filter((k) => d[k] === undefined).join('/')}` : avg < 0.7 ? `均分 ${avg} < 0.7` : undefined,
|
|
407
|
+
reason: ok ? undefined : 'RULE_VIOLATED', provenance: [`[${t}] agentive-diff: 五维均分 ${avg}`] };
|
|
408
|
+
},
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
/* ══════ 八、通信族 3 条 ══════ */
|
|
412
|
+
add({
|
|
413
|
+
id: 'PROTOCOL_ILC_V6_0', name: '层间通信协议 V6.0', kind: 'rule', src: 'yaml-block 4207 字符(最长定义)',
|
|
414
|
+
implements: ['11 层编号校验 + 消息信封(srcLayer/dstLayer/payload/traceId)+ 跨层跳跃限制(≤2 层)'],
|
|
415
|
+
exec(inp, t) {
|
|
416
|
+
const LAYERS = 11;
|
|
417
|
+
const m = inp.envelope || {};
|
|
418
|
+
const src = Number(m.srcLayer), dst = Number(m.dstLayer);
|
|
419
|
+
if (!isFinite(src) || !isFinite(dst)) return { success: false, kind: 'rule', reason: 'INVALID_INPUT', error: '必须提供 envelope.srcLayer / dstLayer' };
|
|
420
|
+
const rangeOk = src >= 1 && src <= LAYERS && dst >= 1 && dst <= LAYERS;
|
|
421
|
+
const jump = Math.abs(dst - src);
|
|
422
|
+
const maxJump = Number(inp.maxLayerJump ?? 2);
|
|
423
|
+
const envelopeOk = !req(m, ['payload', 'traceId']).length;
|
|
424
|
+
const fails = [];
|
|
425
|
+
if (!rangeOk) fails.push(`层号越界(应为 1–${LAYERS})`);
|
|
426
|
+
if (jump > maxJump) fails.push(`跨层跳跃 ${jump} > ${maxJump}`);
|
|
427
|
+
if (!envelopeOk) fails.push(`信封缺:${req(m, ['payload', 'traceId']).join('/')}`);
|
|
428
|
+
return { success: fails.length === 0, kind: 'rule', output: { layers: LAYERS, srcLayer: src, dstLayer: dst, jump, maxJump, envelopeOk, fails,
|
|
429
|
+
direction: dst > src ? '向上' : dst < src ? '向下' : '同层' },
|
|
430
|
+
error: fails.length ? fails.join(';') : undefined, reason: fails.length ? 'RULE_VIOLATED' : undefined,
|
|
431
|
+
provenance: [`[${t}] ilc-v6: L${src}→L${dst}(${Math.abs(dst - src)} 层)`] };
|
|
432
|
+
},
|
|
433
|
+
});
|
|
434
|
+
add({
|
|
435
|
+
id: 'PROTOCOL_IECP_V1_0', name: '引擎间协作协议', kind: 'rule', src: 'yaml-block 2590 字符',
|
|
436
|
+
implements: ['协作请求四要素 + 循环依赖检测 + 超时'],
|
|
437
|
+
exec(inp, t) {
|
|
438
|
+
const r = inp.request || {};
|
|
439
|
+
const miss = ['fromEngine', 'toEngine', 'payload', 'deadline'].filter((k) => r[k] === undefined);
|
|
440
|
+
const graph = inp.dependencyGraph || [];
|
|
441
|
+
/* 简单环检测 */
|
|
442
|
+
const adj = {};
|
|
443
|
+
for (const e of graph) { (adj[e.from] = adj[e.from] || []).push(e.to); }
|
|
444
|
+
const hasCycle = (() => {
|
|
445
|
+
const state = {};
|
|
446
|
+
const dfs = (n) => {
|
|
447
|
+
if (state[n] === 1) return true;
|
|
448
|
+
if (state[n] === 2) return false;
|
|
449
|
+
state[n] = 1;
|
|
450
|
+
for (const m of (adj[n] || [])) if (dfs(m)) return true;
|
|
451
|
+
state[n] = 2; return false;
|
|
452
|
+
};
|
|
453
|
+
return Object.keys(adj).some((n) => dfs(n));
|
|
454
|
+
})();
|
|
455
|
+
const ok = miss.length === 0 && !hasCycle;
|
|
456
|
+
return { success: ok, kind: 'rule', output: { requiredFields: ['fromEngine', 'toEngine', 'payload', 'deadline'], missing: miss, cycleDetected: hasCycle },
|
|
457
|
+
error: miss.length ? `协作请求缺:${miss.join('/')}` : hasCycle ? '引擎依赖存在循环,协作被拒' : undefined,
|
|
458
|
+
reason: ok ? undefined : 'RULE_VIOLATED',
|
|
459
|
+
provenance: [`[${t}] iecp: 请求 ${4 - miss.length}/4,环 ${hasCycle}`] };
|
|
460
|
+
},
|
|
461
|
+
});
|
|
462
|
+
add({
|
|
463
|
+
id: 'PROTOCOL_A2T_ACCESS_V1', name: '智能体与工具/设备/平台/数据服务接入协议', kind: 'rule', src: 'yaml-block 1326 字符',
|
|
464
|
+
implements: ['四类接入点(工具/设备/平台/数据)+ 能力握手'],
|
|
465
|
+
exec(inp, t) {
|
|
466
|
+
const TYPES = ['tool', 'device', 'platform', 'data'];
|
|
467
|
+
const type = String(inp.accessType || '');
|
|
468
|
+
if (!TYPES.includes(type)) return { success: false, kind: 'rule', reason: 'INVALID_INPUT', error: `accessType 须为 ${TYPES.join('/')}` };
|
|
469
|
+
const miss = ['endpoint', 'capability', 'auth'].filter((k) => !inp[k]);
|
|
470
|
+
const ok = miss.length === 0;
|
|
471
|
+
return { success: ok, kind: 'rule', output: { accessType: type, requiredFields: ['endpoint', 'capability', 'auth'], missing: miss },
|
|
472
|
+
error: miss.length ? `接入缺:${miss.join('/')}` : undefined, reason: ok ? undefined : 'RULE_VIOLATED',
|
|
473
|
+
provenance: [`[${t}] a2t-access: ${type} 接入 ${ok ? '合规' : '不合规'}`] };
|
|
474
|
+
},
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
/* ══════ 九、其余 15 条 ══════ */
|
|
478
|
+
add({ id: 'PROTOCOL_3STEP_V1', name: '三步进化协议', kind: 'pipeline', src: 'yaml-block 874 字符',
|
|
479
|
+
implements: ['三步(使用→成为→进化)阶段推进'],
|
|
480
|
+
exec(inp, t) {
|
|
481
|
+
const S = ['使用智能体', '成为智能体', '进化智能体'];
|
|
482
|
+
const c = String(inp.stage || '');
|
|
483
|
+
if (!S.includes(c)) return { success: false, kind: 'pipeline', reason: 'INVALID_INPUT', error: `stage 须为 ${S.join('/')}` };
|
|
484
|
+
const i = S.indexOf(c);
|
|
485
|
+
return { success: true, kind: 'pipeline', output: { stage: c, step: i + 1, steps: S, next: S[i + 1] || null }, provenance: [`[${t}] 3step: ${c} (${i + 1}/3)`] };
|
|
486
|
+
} });
|
|
487
|
+
add({ id: 'PROTOCOL_AI_FIRST_V1', name: 'AI First组织设计协议', kind: 'rule', src: 'clause 2523 字符',
|
|
488
|
+
implements: ['AI First 五原则(AI优先/人机分工/数据贯通/自动决策/持续演化)'],
|
|
489
|
+
exec(inp, t) {
|
|
490
|
+
const NEED = ['aiFirst', 'humanMachineSplit', 'dataThrough', 'autoDecision', 'continuousEvolution'];
|
|
491
|
+
const res = NEED.map((k) => ({ principle: k, met: inp[k] === true }));
|
|
492
|
+
const miss = res.filter((r) => !r.met).map((r) => r.principle);
|
|
493
|
+
return { success: miss.length === 0, kind: 'rule', output: { principles: res, unmet: miss },
|
|
494
|
+
error: miss.length ? `AI First 未落实:${miss.join('/')}` : undefined, reason: miss.length ? 'RULE_VIOLATED' : undefined,
|
|
495
|
+
provenance: [`[${t}] ai-first: ${5 - miss.length}/5`] };
|
|
496
|
+
} });
|
|
497
|
+
add({ id: 'PROTOCOL_CREATION_GOVERN_V1', name: '创造治理协议', kind: 'pipeline', src: 'section 5531 字符(最长)',
|
|
498
|
+
implements: ['六步创造治理(缺口证明→内生生成→最小性→验证→谱系→固化)'],
|
|
499
|
+
exec(inp, t) {
|
|
500
|
+
const NEED = ['gapProven', 'endogenous', 'minimal', 'verified', 'lineage', 'frozen'];
|
|
501
|
+
const steps = NEED.map((k, i) => ({ no: i + 1, key: k, present: !!(inp && inp[k]) }));
|
|
502
|
+
const miss = steps.filter((s) => !s.present).map((s) => s.key);
|
|
503
|
+
const ok = miss.length === 0;
|
|
504
|
+
return { success: ok, kind: 'pipeline', steps, output: { steps: NEED, missing: miss },
|
|
505
|
+
error: ok ? undefined : `创造治理缺步骤:${miss.join('/')}`, reason: ok ? undefined : 'PRECONDITION_FAILED',
|
|
506
|
+
provenance: [`[${t}] creation-govern: ${6 - miss.length}/6`] };
|
|
507
|
+
} });
|
|
508
|
+
add({ id: 'PROTOCOL_DIALOG_STATE_V1', name: '对话流状态持久化协议', kind: 'rule', src: 'yaml-block 924 字符',
|
|
509
|
+
implements: ['状态快照四要素 + 恢复一致性'],
|
|
510
|
+
exec(inp, t) {
|
|
511
|
+
const s = inp.snapshot || {};
|
|
512
|
+
const miss = ['sessionId', 'turns', 'timestamp', 'checksum'].filter((k) => s[k] === undefined);
|
|
513
|
+
const recoverable = !!(inp.restored === true || inp.canRestore === true);
|
|
514
|
+
const ok = miss.length === 0 && recoverable;
|
|
515
|
+
return { success: ok, kind: 'rule', output: { requiredFields: ['sessionId', 'turns', 'timestamp', 'checksum'], missing: miss, recoverable },
|
|
516
|
+
error: miss.length ? `快照缺:${miss.join('/')}` : !recoverable ? '快照不可恢复' : undefined,
|
|
517
|
+
reason: ok ? undefined : 'RULE_VIOLATED', provenance: [`[${t}] dialog-state: ${ok ? '可持久化' : '不合规'}`] };
|
|
518
|
+
} });
|
|
519
|
+
add({ id: 'PROTOCOL_EDGE_DEPLOY_V1', name: '边缘部署协议', kind: 'rule', src: 'yaml-block 775 字符',
|
|
520
|
+
implements: ['五资源校验(算力/带宽/存储/功耗/连通)'],
|
|
521
|
+
exec(inp, t) {
|
|
522
|
+
const REQ = { compute: 1, bandwidth: 2, storage: 512, power: 5 };
|
|
523
|
+
const e = inp.edge || {};
|
|
524
|
+
const checks = Object.keys(REQ).map((k) => ({ item: k, required: REQ[k], actual: e[k] ?? null, ok: Number(e[k] ?? 0) >= REQ[k] }));
|
|
525
|
+
checks.push({ item: 'connectivity', required: true, actual: e.connectivity, ok: e.connectivity !== false });
|
|
526
|
+
const failed = checks.filter((c) => !c.ok).map((c) => c.item);
|
|
527
|
+
return { success: failed.length === 0, kind: 'rule', output: { requirements: REQ, checks, failed },
|
|
528
|
+
error: failed.length ? `边缘资源不足:${failed.join('/')}` : undefined, reason: failed.length ? 'RULE_VIOLATED' : undefined,
|
|
529
|
+
provenance: [`[${t}] edge-deploy: ${5 - failed.length}/5`] };
|
|
530
|
+
} });
|
|
531
|
+
add({ id: 'PROTOCOL_EXPLORE_EXTERNAL_V1', name: '自主探索外部交互协议', kind: 'rule', src: 'table-row 201 字符',
|
|
532
|
+
implements: ['外部探索三约束(预算/边界/回报)'],
|
|
533
|
+
exec(inp, t) {
|
|
534
|
+
const budget = Number(inp.budget ?? 0), used = Number(inp.used ?? 0);
|
|
535
|
+
const inBoundary = inp.withinBoundary !== false;
|
|
536
|
+
const hasReturn = inp.returnValue !== undefined;
|
|
537
|
+
const fails = [];
|
|
538
|
+
if (used > budget) fails.push(`超预算 ${used}/${budget}`);
|
|
539
|
+
if (!inBoundary) fails.push('越出探索边界');
|
|
540
|
+
if (!hasReturn) fails.push('未记录探索回报');
|
|
541
|
+
return { success: fails.length === 0, kind: 'rule', output: { budget, used, inBoundary, hasReturn, fails },
|
|
542
|
+
error: fails.length ? fails.join(';') : undefined, reason: fails.length ? 'RULE_VIOLATED' : undefined,
|
|
543
|
+
provenance: [`[${t}] explore-external: ${fails.length ? '拒绝' : '允许'}`] };
|
|
544
|
+
} });
|
|
545
|
+
add({ id: 'PROTOCOL_EXPLORE_INTERNAL_V1', name: '自主探索内部协同协议', kind: 'rule', src: 'table-row 201 字符',
|
|
546
|
+
implements: ['内部探索:影响面评估 + 可回滚'],
|
|
547
|
+
exec(inp, t) {
|
|
548
|
+
const impact = clamp01(inp.impactScope ?? 0.3);
|
|
549
|
+
const rollback = inp.rollbackReady === true;
|
|
550
|
+
const maxImpact = Number(inp.maxImpact ?? 0.5);
|
|
551
|
+
const fails = [];
|
|
552
|
+
if (impact > maxImpact) fails.push(`影响面 ${impact} > ${maxImpact}`);
|
|
553
|
+
if (!rollback) fails.push('未准备回滚方案');
|
|
554
|
+
return { success: fails.length === 0, kind: 'rule', output: { impactScope: impact, maxImpact, rollbackReady: rollback, fails },
|
|
555
|
+
error: fails.length ? fails.join(';') : undefined, reason: fails.length ? 'RULE_VIOLATED' : undefined,
|
|
556
|
+
provenance: [`[${t}] explore-internal: 影响 ${impact},回滚 ${rollback}`] };
|
|
557
|
+
} });
|
|
558
|
+
add({ id: 'PROTOCOL_GLOBAL_AWARENESS_V1', name: '全球态势感知协议', kind: 'compute', src: 'yaml-block 376 字符',
|
|
559
|
+
implements: ['态势六维加权(地缘/经济/技术/环境/社会/安全)'],
|
|
560
|
+
exec(inp, t) {
|
|
561
|
+
const D = ['地缘', '经济', '技术', '环境', '社会', '安全'];
|
|
562
|
+
const v = inp.dims || {};
|
|
563
|
+
const known = D.filter((k) => v[k] !== undefined);
|
|
564
|
+
const score = known.length ? round(mean(known.map((k) => clamp01(v[k])))) : null;
|
|
565
|
+
const risks = known.filter((k) => clamp01(v[k]) < 0.4).map((k) => ({ dim: k, value: v[k] }));
|
|
566
|
+
return { success: known.length === D.length, kind: 'compute', output: { dimensions: D, provided: known, overall: score, risks },
|
|
567
|
+
error: known.length < D.length ? `缺维度:${D.filter((k) => v[k] === undefined).join('/')}` : undefined,
|
|
568
|
+
reason: known.length < D.length ? 'PRECONDITION_FAILED' : undefined,
|
|
569
|
+
provenance: [`[${t}] global-awareness: ${known.length}/6 维,综合 ${score}`] };
|
|
570
|
+
} });
|
|
571
|
+
add({ id: 'PROTOCOL_IDEA_DRIVEN_V1', name: '思想驱动开发协议', kind: 'pipeline', src: 'clause 1645 字符',
|
|
572
|
+
implements: ['四步(思想→设计→实现→验证)'],
|
|
573
|
+
exec(inp, t) {
|
|
574
|
+
const N = ['idea', 'design', 'implementation', 'verification'];
|
|
575
|
+
const steps = N.map((k, i) => ({ no: i + 1, key: k, present: !!(inp && inp[k]) }));
|
|
576
|
+
const miss = steps.filter((s) => !s.present).map((s) => s.key);
|
|
577
|
+
return { success: miss.length === 0, kind: 'pipeline', steps, output: { steps: N, missing: miss },
|
|
578
|
+
error: miss.length ? `思想驱动缺:${miss.join('/')}` : undefined, reason: miss.length ? 'PRECONDITION_FAILED' : undefined,
|
|
579
|
+
provenance: [`[${t}] idea-driven: ${4 - miss.length}/4`] };
|
|
580
|
+
} });
|
|
581
|
+
add({ id: 'PROTOCOL_MODE_RESONANCE_SPACE_V1', name: '「模数共振」空间运营协议', kind: 'compute', src: 'yaml-block 1586 字符',
|
|
582
|
+
implements: ['模数共振度 = 数字密度 × 物理密度 几何平均'],
|
|
583
|
+
exec(inp, t) {
|
|
584
|
+
const dm = clamp01(inp.digitalDensity ?? 0.7), pm = clamp01(inp.physicalDensity ?? 0.6);
|
|
585
|
+
const resonance = round(Math.sqrt(dm * pm));
|
|
586
|
+
return { success: true, kind: 'compute', output: { digitalDensity: dm, physicalDensity: pm, resonance, threshold: 0.7, effective: resonance >= 0.7, formula: '共振度 = √(数字密度 × 物理密度)' },
|
|
587
|
+
provenance: [`[${t}] mode-resonance: √(${dm}×${pm}) = ${resonance}`] };
|
|
588
|
+
} });
|
|
589
|
+
add({ id: 'PROTOCOL_OSP_V1_0', name: '反者共生协议', kind: 'compute', src: 'yaml-block 1562 字符',
|
|
590
|
+
implements: ['反者道之动:对立面互转条件 + 共生度'],
|
|
591
|
+
exec(inp, t) {
|
|
592
|
+
const a = clamp01(inp.positionA ?? 0.7), b = clamp01(inp.positionB ?? 0.3);
|
|
593
|
+
const complement = round(1 - Math.abs(a + b - 1)); // 互补度:和为 1 时最高
|
|
594
|
+
const tension = round(Math.abs(a - b));
|
|
595
|
+
const symbiosis = round(clamp01(complement * 0.6 + (1 - tension) * 0.4));
|
|
596
|
+
return { success: true, kind: 'compute', output: { positionA: a, positionB: b, complementarity: complement, tension, symbiosis, threshold: 0.6, symbiotic: symbiosis >= 0.6,
|
|
597
|
+
formula: '互补度 = 1 − |a+b−1|;共生度 = 互补×0.6 + (1−张力)×0.4' },
|
|
598
|
+
provenance: [`[${t}] osp: 互补 ${complement},共生 ${symbiosis}`] };
|
|
599
|
+
} });
|
|
600
|
+
add({ id: 'PROTOCOL_TDCP_V1_0', name: '道在日常协议', kind: 'compute', src: 'yaml-block 1815 字符',
|
|
601
|
+
implements: ['日常行为 → 道之映射(场景/行为/映射/启示 四元组)'],
|
|
602
|
+
exec(inp, t) {
|
|
603
|
+
const scene = String(inp.scene || '日常');
|
|
604
|
+
const TABLE = [
|
|
605
|
+
{ pat: /决策|选择/, action: '慎断', mapping: '知止而后有定', insight: '先界定边界再做选择' },
|
|
606
|
+
{ pat: /协作|团队/, action: '和同', mapping: '和而不同', insight: '保留差异才能协同' },
|
|
607
|
+
{ pat: /变化|调整/, action: '顺势', mapping: '穷则变,变则通', insight: '遇阻即转,不硬顶' },
|
|
608
|
+
{ pat: /积累|坚持/, action: '渐进', mapping: '合抱之木生于毫末', insight: '从小处积累' },
|
|
609
|
+
{ pat: /.*/, action: '守常', mapping: '道在日常', insight: '平常心即道' },
|
|
610
|
+
];
|
|
611
|
+
const hit = TABLE.find((x) => x.pat.test(scene)) || TABLE[TABLE.length - 1];
|
|
612
|
+
return { success: true, kind: 'compute', output: { scene, action: hit.action, mapping: hit.mapping, insight: hit.insight, rule: '仅映射不预测' },
|
|
613
|
+
provenance: [`[${t}] tdcp: 「${scene}」→ ${hit.mapping}`] };
|
|
614
|
+
} });
|
|
615
|
+
add({ id: 'PROTOCOL_TIME_TRAVEL_V1', name: '时空回溯协议', kind: 'compute', src: 'yaml-block 739 字符',
|
|
616
|
+
implements: ['快照回溯(检查点校验 + 状态恢复)'],
|
|
617
|
+
exec(inp, t) {
|
|
618
|
+
const snaps = inp.snapshots || [];
|
|
619
|
+
if (!snaps.length) return { success: false, kind: 'compute', reason: 'INVALID_INPUT', error: '必须提供 snapshots 数组' };
|
|
620
|
+
const idx = Number(inp.targetIndex ?? snaps.length - 1);
|
|
621
|
+
if (idx < 0 || idx >= snaps.length) return { success: false, kind: 'compute', reason: 'INVALID_INPUT', error: `targetIndex ${idx} 越界(0–${snaps.length - 1})` };
|
|
622
|
+
const target = snaps[idx];
|
|
623
|
+
const valid = !!(target && target.checksum);
|
|
624
|
+
return { success: valid, kind: 'compute', output: { snapshots: snaps.length, targetIndex: idx, targetChecksum: target.checksum || null, restorable: valid, state: target.state || null },
|
|
625
|
+
error: valid ? undefined : '目标快照缺 checksum,不可回溯', reason: valid ? undefined : 'PRECONDITION_FAILED',
|
|
626
|
+
provenance: [`[${t}] time-travel: 回溯到 #${idx}/${snaps.length - 1}`] };
|
|
627
|
+
} });
|
|
628
|
+
add({ id: 'PROTOCOL_COMPLIANCE_AUDIT_V1', name: '年度合规审计协议', kind: 'rule', src: 'yaml-block 291 字符',
|
|
629
|
+
implements: ['年度审计三项(范围/发现/整改)'],
|
|
630
|
+
exec(inp, t) {
|
|
631
|
+
const miss = ['scope', 'findings', 'remediation'].filter((k) => inp[k] === undefined);
|
|
632
|
+
const openFindings = (inp.findings || []).filter((f) => !f.closed).length;
|
|
633
|
+
const ok = miss.length === 0 && openFindings === 0;
|
|
634
|
+
return { success: ok, kind: 'rule', output: { requiredFields: ['scope', 'findings', 'remediation'], missing: miss, openFindings },
|
|
635
|
+
error: miss.length ? `审计缺:${miss.join('/')}` : openFindings ? `${openFindings} 项发现未整改` : undefined,
|
|
636
|
+
reason: ok ? undefined : 'RULE_VIOLATED', provenance: [`[${t}] compliance-audit: 未整改 ${openFindings}`] };
|
|
637
|
+
} });
|
|
638
|
+
add({ id: 'PROTOCOL_CRYPTO_API_V1', name: '密码学API协议', kind: 'compute', src: 'table-row 888 字符',
|
|
639
|
+
implements: ['哈希/对称加密可用性 + 强度校验'],
|
|
640
|
+
exec(inp, t) {
|
|
641
|
+
const algo = String(inp.algorithm || 'sha256');
|
|
642
|
+
const WEAK = ['md5', 'sha1', 'des', 'rc4'];
|
|
643
|
+
const STRONG = ['sha256', 'sha384', 'sha512', 'aes-256-gcm', 'chacha20-poly1305'];
|
|
644
|
+
const a = algo.toLowerCase();
|
|
645
|
+
const weak = WEAK.includes(a);
|
|
646
|
+
const strong = STRONG.includes(a);
|
|
647
|
+
const out = { algorithm: algo, weak, strong, allowed: !weak };
|
|
648
|
+
if (inp.data !== undefined && a.startsWith('sha')) out.digest = require('crypto').createHash(a).update(String(inp.data)).digest('hex');
|
|
649
|
+
return { success: !weak, kind: 'compute', output: out,
|
|
650
|
+
error: weak ? `算法 ${algo} 已不安全` : undefined, reason: weak ? 'RULE_VIOLATED' : undefined,
|
|
651
|
+
provenance: [`[${t}] crypto-api: ${algo} ${weak ? '禁用' : '可用'}`] };
|
|
652
|
+
} });
|
|
653
|
+
add({ id: 'PROTOCOL_GUE_API_V1', name: 'GUE API协议', kind: 'compute', src: 'table-row 888 字符',
|
|
654
|
+
implements: ['GUE 统计:能级间距分布比(Poisson vs Wigner)'],
|
|
655
|
+
exec(inp, t) {
|
|
656
|
+
const s = inp.spacings;
|
|
657
|
+
if (!Array.isArray(s) || s.length < 3) return { success: false, kind: 'compute', reason: 'INVALID_INPUT', error: '必须提供长度≥3 的 spacings' };
|
|
658
|
+
const v = s.map(Number), m = mean(v);
|
|
659
|
+
const r = round(Math.sqrt(mean(v.map((x) => (x - m) ** 2))) / (m || 1));
|
|
660
|
+
/* Poisson: <r>≈0.386;GUE(Wigner): <r>≈0.53 */
|
|
661
|
+
const guess = Math.abs(r - 0.386) < Math.abs(r - 0.53) ? 'Poisson(可积)' : 'GUE(混沌/不可积)';
|
|
662
|
+
return { success: true, kind: 'compute', output: { spacings: v.length, meanSpacing: round(m), ratioR: r, statistics: guess, refs: { Poisson: 0.386, GUE: 0.53 } },
|
|
663
|
+
provenance: [`[${t}] gue-api: ⟨r⟩=${r} → ${guess}`] };
|
|
664
|
+
} });
|
|
665
|
+
|
|
666
|
+
/* ══════ 运行时 ══════ */
|
|
667
|
+
const INDEX = new Map(P.map((p) => [p.id, p]));
|
|
668
|
+
const kindOf = (id) => { const p = INDEX.get(id); return p ? p.kind : 'declared'; };
|
|
669
|
+
const getRegistry = () => P.map((p) => ({ id: p.id, name: p.name, kind: p.kind, src: p.src, implements: p.implements || [] }));
|
|
670
|
+
|
|
671
|
+
function executeSync(id, input) {
|
|
672
|
+
const t0 = Date.now(), t = tid();
|
|
673
|
+
const p = INDEX.get(id);
|
|
674
|
+
if (!p) return { success: false, kind: 'declared', reason: 'NOT_FOUND', error: `协议 ${id} 未登记`, provenance: [], traceId: t, durationMs: 0 };
|
|
675
|
+
let r;
|
|
676
|
+
try { r = p.exec(input || {}, t); } catch (e) { r = { success: false, kind: p.kind, error: 'THROW: ' + e.message, provenance: [`[${t}] THROW`] }; }
|
|
677
|
+
return { ...r, protocolId: id, protocolName: p.name, traceId: t, durationMs: Date.now() - t0 };
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
module.exports = { executeSync, execute: async (i, n) => executeSync(i, n), kindOf, getRegistry, PROTOCOLS: P, INDEX };
|