@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,441 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* P6-B1 · 协议运行时(ProtocolRuntime)
|
|
4
|
+
*
|
|
5
|
+
* 设计要点:
|
|
6
|
+
* - 与原子/算法层同构的诚实范式:先声明 kind,再执行
|
|
7
|
+
* - ExecResult 带 provenance(A1 溯源公理)+ traceId(法则 4.6.1)
|
|
8
|
+
* - pipeline 类必须逐阶段校验前置条件,阶段未通过即 fail(不得跳过)
|
|
9
|
+
* - external 类诚实拒绝(EXTERNAL_REQUIRED),禁止假成功
|
|
10
|
+
*
|
|
11
|
+
* 本文件同时是运行时与 B1 的 11 条协议实现(18 个执行单元):
|
|
12
|
+
* PROTOCOL_DECISION_LOCK_V1 — 4 关(IVL / ILT / OSG / 内容完整性)
|
|
13
|
+
* PROTOCOL_META_EVOLUTION_V1 — 5 阶段(边界感知/差距分析/自生成/验证/递归)
|
|
14
|
+
* PROTOCOL_META_META_DECISION — 元元决策
|
|
15
|
+
* PROTOCOL_META_META_DIRECTION — 元元方向
|
|
16
|
+
* PROTOCOL_META_META_MIRROR — 元元镜像
|
|
17
|
+
* PROTOCOL_META_META_MONITOR — 元元监控
|
|
18
|
+
* PROTOCOL_META_META_STRATEGY — 元元战略
|
|
19
|
+
* PROTOCOL_META_CREATION_001 — 元创造·边界突破
|
|
20
|
+
* PROTOCOL_META_CREATION_002 — 元创造·内生生成
|
|
21
|
+
* PROTOCOL_META_CREATION_003 — 元创造·验证固化
|
|
22
|
+
* PROTOCOL_META_CREATION_V1 — 元创造总纲
|
|
23
|
+
*/
|
|
24
|
+
'use strict';
|
|
25
|
+
|
|
26
|
+
let __seq = 0;
|
|
27
|
+
function newTraceId() {
|
|
28
|
+
const d = new Date();
|
|
29
|
+
const p = (n, w = 2) => String(n).padStart(w, '0');
|
|
30
|
+
return `${d.getFullYear()}${p(d.getMonth() + 1)}${p(d.getDate())}-${p(d.getHours())}${p(d.getMinutes())}${p(d.getSeconds())}-${p((++__seq) % 10000, 4)}`;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const ok = (r, extra) => Object.assign({ ok: true, evidence: r }, extra || {});
|
|
34
|
+
const bad = (reason, extra) => Object.assign({ ok: false, reason }, extra || {});
|
|
35
|
+
|
|
36
|
+
/* ══════════════════════════════════════════════════════════════
|
|
37
|
+
* 一、裁决锁 4 关(PROTOCOL_DECISION_LOCK_V1)
|
|
38
|
+
* 依据:AGENTS.md §4.2 决策锁强制校验 + 蓝本第一章第1-3条
|
|
39
|
+
* ══════════════════════════════════════════════════════════════ */
|
|
40
|
+
|
|
41
|
+
/** 第 1 关 IVL 意图验证:输出是否回应了真实意图(而非字面) */
|
|
42
|
+
function gateIVL(input) {
|
|
43
|
+
const intent = input && input.intent;
|
|
44
|
+
const output = input && input.output;
|
|
45
|
+
if (!intent || typeof intent !== 'string') return bad('意图缺失或非字符串', { gate: 'IVL' });
|
|
46
|
+
if (!output || typeof output !== 'string') return bad('输出缺失或非字符串', { gate: 'IVL' });
|
|
47
|
+
/* 意图覆盖率:优先按分隔符切词;中文无分隔符时退化为 2-gram 覆盖率。
|
|
48
|
+
修复记录(P6-B1 自测发现):原实现把「验证交付物是否完整可用」整句当 1 个 token,
|
|
49
|
+
输出中当然不含该整串 → 覆盖率恒 0 → 正常输入被误判失败。 */
|
|
50
|
+
const isCJK = (s) => /[\u4e00-\u9fa5]/.test(s);
|
|
51
|
+
let tokens = intent.split(/[\s,,。;;、::()()]+/).filter((t) => t.length >= 2);
|
|
52
|
+
let mode = 'word';
|
|
53
|
+
if (tokens.length <= 1 && isCJK(intent)) {
|
|
54
|
+
/* 2-gram:去掉标点后按相邻两字切 */
|
|
55
|
+
const clean = intent.replace(/[^\u4e00-\u9fa5A-Za-z0-9]/g, '');
|
|
56
|
+
const g = [];
|
|
57
|
+
for (let i = 0; i + 2 <= clean.length; i++) g.push(clean.slice(i, i + 2));
|
|
58
|
+
tokens = g;
|
|
59
|
+
mode = 'cjk-bigram';
|
|
60
|
+
}
|
|
61
|
+
if (!tokens.length) return bad('意图无法切出有效词', { gate: 'IVL' });
|
|
62
|
+
const hit = tokens.filter((t) => output.includes(t));
|
|
63
|
+
const coverage = hit.length / tokens.length;
|
|
64
|
+
return ok({ gate: 'IVL', mode, coverage: +coverage.toFixed(3), hitTokens: hit.length, totalTokens: tokens.length },
|
|
65
|
+
{ pass: coverage >= 0.5 });
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** 第 2 关 ILT 意图谱系追踪:输出是否可追溯到输入链 */
|
|
69
|
+
function gateILT(input) {
|
|
70
|
+
const lineage = input && input.lineage;
|
|
71
|
+
if (!Array.isArray(lineage)) return bad('谱系链缺失或非数组', { gate: 'ILT' });
|
|
72
|
+
if (lineage.length < 1) return bad('谱系链为空(A1 溯源公理要求 ≥1 级)', { gate: 'ILT' });
|
|
73
|
+
const broken = lineage.filter((x) => !x || !x.source || !x.claim);
|
|
74
|
+
return ok({ gate: 'ILT', links: lineage.length, broken: broken.length }, { pass: broken.length === 0 });
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** 第 3 关 OSG 语义输出门:输出不得含幻觉/占位符/空断言 */
|
|
78
|
+
function gateOSG(input) {
|
|
79
|
+
const output = input && input.output;
|
|
80
|
+
if (typeof output !== 'string') return bad('输出缺失', { gate: 'OSG' });
|
|
81
|
+
const patterns = [
|
|
82
|
+
{ re: /TODO|FIXME|待补充|待定|视情况|酌情/g, name: '占位符' },
|
|
83
|
+
{ re: /\{\{[^}]+\}\}|<PLACEHOLDER>/g, name: '未替换占位符' },
|
|
84
|
+
{ re: /应该没问题|大概可以|可能是|估计是/g, name: '模糊填充词' },
|
|
85
|
+
{ re: /\bundefined\b|\bNaN\b/g, name: '未定义值泄漏' },
|
|
86
|
+
];
|
|
87
|
+
const hits = [];
|
|
88
|
+
for (const p of patterns) {
|
|
89
|
+
const m = output.match(p.re);
|
|
90
|
+
if (m) hits.push({ name: p.name, count: m.length, samples: [...new Set(m)].slice(0, 3) });
|
|
91
|
+
}
|
|
92
|
+
return ok({ gate: 'OSG', violations: hits }, { pass: hits.length === 0 });
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** 第 4 关 内容完整性:声明与证据是否匹配 */
|
|
96
|
+
function gateIntegrity(input) {
|
|
97
|
+
const claims = input && input.claims;
|
|
98
|
+
if (!Array.isArray(claims)) return bad('claims 缺失或非数组', { gate: 'INTEGRITY' });
|
|
99
|
+
const unsupported = claims.filter((c) => !c || !c.claim || !c.evidence || String(c.evidence).trim() === '');
|
|
100
|
+
return ok({ gate: 'INTEGRITY', claims: claims.length, unsupported: unsupported.length },
|
|
101
|
+
{ pass: unsupported.length === 0 });
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/* ══════════════════════════════════════════════════════════════
|
|
105
|
+
* 二、元进化 5 阶段(PROTOCOL_META_EVOLUTION_V1)
|
|
106
|
+
* 依据:蓝本第二章第2条「五阶段流程」
|
|
107
|
+
* 2.1 边界感知 → 必须输出边界描述
|
|
108
|
+
* 2.2 差距分析 → 必须输出差距向量
|
|
109
|
+
* 2.3 自生成 → 必须输出新能力
|
|
110
|
+
* 2.4 验证 → 必须通过验证才能保留
|
|
111
|
+
* 2.5 递归 → 必须进行自我审视
|
|
112
|
+
* ══════════════════════════════════════════════════════════════ */
|
|
113
|
+
|
|
114
|
+
function stageBoundary(input) {
|
|
115
|
+
const b = input && input.boundary;
|
|
116
|
+
if (!b || typeof b !== 'object') return bad('边界描述缺失(2.1 要求必须输出边界描述)', { stage: 1 });
|
|
117
|
+
const need = ['capability', 'limit', 'observedAt'];
|
|
118
|
+
const miss = need.filter((k) => !b[k]);
|
|
119
|
+
return ok({ stage: 1, name: '边界感知', boundary: b }, { pass: miss.length === 0, missing: miss });
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function stageGap(input) {
|
|
123
|
+
const g = input && input.gap;
|
|
124
|
+
if (!g || typeof g !== 'object') return bad('差距向量缺失(2.2 要求必须输出差距向量)', { stage: 2 });
|
|
125
|
+
const vec = g.vector;
|
|
126
|
+
if (!Array.isArray(vec) || vec.length === 0) return bad('差距向量必须是非空数组', { stage: 2 });
|
|
127
|
+
const norm = Math.sqrt(vec.reduce((s, x) => s + (Number(x) || 0) ** 2, 0));
|
|
128
|
+
return ok({ stage: 2, name: '差距分析', dims: vec.length, norm: +norm.toFixed(4) }, { pass: norm > 0 });
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function stageSelfGenerate(input) {
|
|
132
|
+
const n = input && input.newCapability;
|
|
133
|
+
if (!n || typeof n !== 'object') return bad('新能力缺失(2.3 要求必须输出新能力)', { stage: 3 });
|
|
134
|
+
const need = ['id', 'name', 'kind'];
|
|
135
|
+
const miss = need.filter((k) => !n[k]);
|
|
136
|
+
return ok({ stage: 3, name: '自生成', newCapability: n }, { pass: miss.length === 0, missing: miss });
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function stageVerify(input) {
|
|
140
|
+
const v = input && input.verification;
|
|
141
|
+
if (!v || typeof v !== 'object') return bad('验证结果缺失(2.4 要求必须通过验证才能保留)', { stage: 4 });
|
|
142
|
+
const passed = v.passed === true;
|
|
143
|
+
return ok({ stage: 4, name: '验证', passed, checks: Array.isArray(v.checks) ? v.checks.length : 0 }, { pass: passed });
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function stageRecurse(input) {
|
|
147
|
+
const r = input && input.selfReflection;
|
|
148
|
+
if (!r || typeof r !== 'object') return bad('自我审视缺失(2.5 要求必须进行自我审视)', { stage: 5 });
|
|
149
|
+
const hasMeta = r.canMetaEvolve === true;
|
|
150
|
+
const depth = Number(r.depth) || 0;
|
|
151
|
+
// 第4条递归保障:元进化后的系统必须具备元进化能力 + 深度可追踪
|
|
152
|
+
return ok({ stage: 5, name: '递归', canMetaEvolve: hasMeta, depth }, { pass: hasMeta && depth >= 1 });
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** 耦生保持校验(第三章第3条:元进化前后耦生度 ≥0.95) */
|
|
156
|
+
function checkCouplingPreserved(input) {
|
|
157
|
+
const before = Number(input && input.couplingBefore);
|
|
158
|
+
const after = Number(input && input.couplingAfter);
|
|
159
|
+
if (!isFinite(before) || !isFinite(after)) return { ok: false, reason: '耦生度缺失(第3条要求 ≥0.95)' };
|
|
160
|
+
const delta = +(after - before).toFixed(4);
|
|
161
|
+
return { ok: after >= 0.95, delta, before, after };
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/* ══════════════════════════════════════════════════════════════
|
|
165
|
+
* 三、执行引擎
|
|
166
|
+
* ══════════════════════════════════════════════════════════════ */
|
|
167
|
+
|
|
168
|
+
function runPipeline(stages, input, traceId) {
|
|
169
|
+
const steps = [];
|
|
170
|
+
const prov = [];
|
|
171
|
+
for (const st of stages) {
|
|
172
|
+
let r;
|
|
173
|
+
try { r = st.fn(input); } catch (e) { r = bad('THROW: ' + e.message); }
|
|
174
|
+
const passed = r && r.ok && (r.pass !== false);
|
|
175
|
+
steps.push({ id: st.id, name: st.name, ok: !!passed, reason: r && r.reason, evidence: r && r.evidence });
|
|
176
|
+
prov.push(`[${traceId}] ${st.id} ${st.name} → ${passed ? 'PASS' : 'FAIL'}`);
|
|
177
|
+
if (!passed) {
|
|
178
|
+
return { success: false, kind: 'pipeline', steps, provenance: prov, traceId,
|
|
179
|
+
reason: r && r.reason ? 'PRECONDITION_FAILED' : 'STAGE_FAILED',
|
|
180
|
+
error: `${st.id} ${st.name} 未通过:${(r && r.reason) || '阶段判据不成立'}` };
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return { success: true, kind: 'pipeline', output: { stages: steps.length }, steps, provenance: prov, traceId };
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function runRule(rules, input, traceId) {
|
|
187
|
+
const steps = [];
|
|
188
|
+
const prov = [];
|
|
189
|
+
for (const rl of rules) {
|
|
190
|
+
let r;
|
|
191
|
+
try { r = rl.fn(input); } catch (e) { r = bad('THROW: ' + e.message); }
|
|
192
|
+
const passed = r && r.ok && (r.pass !== false);
|
|
193
|
+
steps.push({ id: rl.id, name: rl.name, ok: !!passed, reason: r && r.reason, evidence: r && r.evidence });
|
|
194
|
+
prov.push(`[${traceId}] ${rl.id} ${rl.name} → ${passed ? 'PASS' : 'FAIL'}`);
|
|
195
|
+
if (!passed) {
|
|
196
|
+
return { success: false, kind: 'rule', steps, provenance: prov, traceId, reason: 'RULE_VIOLATED',
|
|
197
|
+
error: `${rl.id} ${rl.name} 违规:${(r && r.reason) || '判据不成立'}` };
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return { success: true, kind: 'rule', output: { rules: steps.length }, steps, provenance: prov, traceId };
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/* ══════════════════════════════════════════════════════════════
|
|
204
|
+
* 四、注册表(B1:11 条协议 / 18 个执行单元)
|
|
205
|
+
* ══════════════════════════════════════════════════════════════ */
|
|
206
|
+
|
|
207
|
+
const REGISTRY = [
|
|
208
|
+
/* ── 决策锁:4 关 ── */
|
|
209
|
+
{
|
|
210
|
+
id: 'PROTOCOL_DECISION_LOCK_V1', name: 'Agent决策可靠性协议', kind: 'pipeline', units: 4,
|
|
211
|
+
source: 'PROTOCOL-CONTRACTS.json(clause, 588 字符)+ AGENTS.md §4.2',
|
|
212
|
+
stages: [
|
|
213
|
+
{ id: 'IVL', name: '意图验证', fn: gateIVL },
|
|
214
|
+
{ id: 'ILT', name: '意图谱系追踪', fn: gateILT },
|
|
215
|
+
{ id: 'OSG', name: '语义输出门', fn: gateOSG },
|
|
216
|
+
{ id: 'INTEGRITY', name: '内容完整性', fn: gateIntegrity },
|
|
217
|
+
],
|
|
218
|
+
exec: (input, tid) => runPipeline(REGISTRY[0].stages, input, tid),
|
|
219
|
+
},
|
|
220
|
+
/* ── 元进化:5 阶段 + 耦生保持 ── */
|
|
221
|
+
{
|
|
222
|
+
id: 'PROTOCOL_META_EVOLUTION_V1', name: '元进化协议 V1.1', kind: 'pipeline', units: 5,
|
|
223
|
+
source: 'PROTOCOL-CONTRACTS.json(yaml-block, 1748 字符)第二章第2条',
|
|
224
|
+
stages: [
|
|
225
|
+
{ id: 'S1', name: '边界感知', fn: stageBoundary },
|
|
226
|
+
{ id: 'S2', name: '差距分析', fn: stageGap },
|
|
227
|
+
{ id: 'S3', name: '自生成', fn: stageSelfGenerate },
|
|
228
|
+
{ id: 'S4', name: '验证', fn: stageVerify },
|
|
229
|
+
{ id: 'S5', name: '递归', fn: stageRecurse },
|
|
230
|
+
],
|
|
231
|
+
exec: (input, tid) => {
|
|
232
|
+
const base = runPipeline(REGISTRY[1].stages, input, tid);
|
|
233
|
+
if (!base.success) return base;
|
|
234
|
+
// 第三章第3条:耦生保持 ≥0.95(仅当调用方提供耦生度时校验)
|
|
235
|
+
if (input && (input.couplingBefore !== undefined || input.couplingAfter !== undefined)) {
|
|
236
|
+
const c = checkCouplingPreserved(input);
|
|
237
|
+
base.steps.push({ id: 'COUPLING', name: '耦生保持(≥0.95)', ok: c.ok, reason: c.reason, evidence: c });
|
|
238
|
+
base.provenance.push(`[${tid}] COUPLING 耦生保持 → ${c.ok ? 'PASS' : 'FAIL'}`);
|
|
239
|
+
if (!c.ok) {
|
|
240
|
+
return { ...base, success: false, reason: 'COUPLING_LOST',
|
|
241
|
+
error: `耦生度 ${c.after} < 0.95 或缺失(第3条),元进化不得破坏已有能力` };
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return base;
|
|
245
|
+
},
|
|
246
|
+
},
|
|
247
|
+
/* ── 元元协议族 5 ── */
|
|
248
|
+
{
|
|
249
|
+
id: 'PROTOCOL_META_META_DECISION', name: '元元决策协议', kind: 'pipeline', units: 1,
|
|
250
|
+
source: '缺口 29(PROTOCOL_META_META_* 族);语义依 A34「元进化需元进化」',
|
|
251
|
+
stages: [
|
|
252
|
+
{ id: 'MM_D1', name: '决策对象是否本身是决策机制', fn: (i) => {
|
|
253
|
+
const t = i && i.target;
|
|
254
|
+
if (!t) return bad('target 缺失');
|
|
255
|
+
return { ok: true, pass: !!(t.isDecisionSystem === true), evidence: { target: t.id || t.name || '?', isDecisionSystem: !!t.isDecisionSystem } };
|
|
256
|
+
} },
|
|
257
|
+
{ id: 'MM_D2', name: '二阶决策不得自我授权', fn: (i) => {
|
|
258
|
+
const a = i && i.authorization;
|
|
259
|
+
if (!a) return bad('authorization 缺失');
|
|
260
|
+
return { ok: true, pass: a.external === true && a.selfGranted !== true, evidence: a };
|
|
261
|
+
} },
|
|
262
|
+
],
|
|
263
|
+
exec: (i, tid) => runPipeline(REGISTRY[2].stages, i, tid),
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
id: 'PROTOCOL_META_META_DIRECTION', name: '元元方向协议', kind: 'pipeline', units: 1,
|
|
267
|
+
source: '缺口 29;语义依 A34',
|
|
268
|
+
stages: [
|
|
269
|
+
{ id: 'MM_DIR1', name: '方向必须有可比较的基线', fn: (i) => {
|
|
270
|
+
const d = i && i.direction;
|
|
271
|
+
if (!d) return bad('direction 缺失');
|
|
272
|
+
return { ok: true, pass: Array.isArray(d.baseline) && d.baseline.length > 0, evidence: { baseline: d.baseline } };
|
|
273
|
+
} },
|
|
274
|
+
{ id: 'MM_DIR2', name: '目标向量与基线同维', fn: (i) => {
|
|
275
|
+
const d = i && i.direction;
|
|
276
|
+
const ok2 = d && Array.isArray(d.baseline) && Array.isArray(d.target) && d.baseline.length === d.target.length;
|
|
277
|
+
return { ok: true, pass: !!ok2, reason: ok2 ? undefined : '基线/目标维度不一致', evidence: { b: d && d.baseline && d.baseline.length, t: d && d.target && d.target.length } };
|
|
278
|
+
} },
|
|
279
|
+
],
|
|
280
|
+
exec: (i, tid) => runPipeline(REGISTRY[3].stages, i, tid),
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
id: 'PROTOCOL_META_META_MIRROR', name: '元元镜像协议', kind: 'pipeline', units: 1,
|
|
284
|
+
source: '缺口 29;语义依蓝本元镜引擎(自我审视)',
|
|
285
|
+
stages: [
|
|
286
|
+
{ id: 'MM_M1', name: '必须声明被审视对象', fn: (i) => {
|
|
287
|
+
const m = i && i.mirror;
|
|
288
|
+
if (!m) return bad('mirror 缺失');
|
|
289
|
+
return { ok: true, pass: !!(m.subject && m.subject.length), evidence: { subject: m.subject } };
|
|
290
|
+
} },
|
|
291
|
+
{ id: 'MM_M2', name: '审视结论必须有证据', fn: (i) => {
|
|
292
|
+
const m = i && i.mirror;
|
|
293
|
+
const ev = m && m.findings;
|
|
294
|
+
return { ok: true, pass: Array.isArray(ev) && ev.length > 0 && ev.every((f) => f && f.evidence), evidence: { findings: ev && ev.length } };
|
|
295
|
+
} },
|
|
296
|
+
],
|
|
297
|
+
exec: (i, tid) => runPipeline(REGISTRY[4].stages, i, tid),
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
id: 'PROTOCOL_META_META_MONITOR', name: '元元监控协议', kind: 'rule', units: 1,
|
|
301
|
+
source: '缺口 29;语义依 A34 + 法则 4.1 五阶段递归',
|
|
302
|
+
rules: [
|
|
303
|
+
{ id: 'MM_MON1', name: '进化深度必须可追踪', fn: (i) => {
|
|
304
|
+
const d = Number(i && i.evolutionDepth);
|
|
305
|
+
if (!isFinite(d)) return bad('evolutionDepth 缺失');
|
|
306
|
+
return { ok: true, pass: d >= 1, evidence: { depth: d } };
|
|
307
|
+
} },
|
|
308
|
+
{ id: 'MM_MON2', name: '连续 3 轮效果 <5% 必须升级元元', fn: (i) => {
|
|
309
|
+
const g = i && i.gains;
|
|
310
|
+
if (!Array.isArray(g)) return bad('gains 缺失');
|
|
311
|
+
const last3 = g.slice(-3);
|
|
312
|
+
const stale = last3.length === 3 && last3.every((x) => Number(x) < 0.05);
|
|
313
|
+
return { ok: true, pass: !stale, reason: stale ? '连续3轮进化效果<5%,须升级到元元层级' : undefined, evidence: { last3 } };
|
|
314
|
+
} },
|
|
315
|
+
],
|
|
316
|
+
exec: (i, tid) => runRule(REGISTRY[5].rules, i, tid),
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
id: 'PROTOCOL_META_META_STRATEGY', name: '元元战略协议', kind: 'pipeline', units: 1,
|
|
320
|
+
source: '缺口 29;语义依元进化协议第四章第11条(战略思考五步)',
|
|
321
|
+
stages: [
|
|
322
|
+
{ id: 'MM_S1', name: '元镜自我审视', fn: (i) => {
|
|
323
|
+
const s = i && i.strategy;
|
|
324
|
+
return { ok: true, pass: !!(s && s.selfReview), evidence: { selfReview: s && s.selfReview } };
|
|
325
|
+
} },
|
|
326
|
+
{ id: 'MM_S2', name: '八大能力族全维度清单', fn: (i) => {
|
|
327
|
+
const need = ['认知能力族','治理能力族','资产能力族','保障能力族','执行能力族','权限能力族','工业互联族','元进化族'];
|
|
328
|
+
const fams = (i && i.strategy && i.strategy.capabilityFamilies) || [];
|
|
329
|
+
const miss = need.filter((f) => !fams.includes(f));
|
|
330
|
+
return { ok: true, pass: miss.length === 0, reason: miss.length ? '缺能力族:' + miss.join('、') : undefined, evidence: { covered: fams.length, missing: miss } };
|
|
331
|
+
} },
|
|
332
|
+
{ id: 'MM_S3', name: '声明未考虑维度', fn: (i) => {
|
|
333
|
+
const u = i && i.strategy && i.strategy.unconsidered;
|
|
334
|
+
return { ok: true, pass: Array.isArray(u), reason: Array.isArray(u) ? undefined : 'unconsidered 必须显式声明(可为空数组)', evidence: { unconsidered: u } };
|
|
335
|
+
} },
|
|
336
|
+
],
|
|
337
|
+
exec: (i, tid) => runPipeline(REGISTRY[6].stages, i, tid),
|
|
338
|
+
},
|
|
339
|
+
/* ── 元创造协议族 4 ── */
|
|
340
|
+
{
|
|
341
|
+
id: 'PROTOCOL_META_CREATION_001', name: '元创造·边界突破协议', kind: 'pipeline', units: 1,
|
|
342
|
+
source: '缺口 29;语义依 A35 创造进化律(逻辑缺口无法用现有组件重组关闭时进入元创造)',
|
|
343
|
+
stages: [
|
|
344
|
+
{ id: 'MC1_A', name: '必须证明现有组件无法闭合缺口', fn: (i) => {
|
|
345
|
+
const c = i && i.closureAttempt;
|
|
346
|
+
if (!c) return bad('closureAttempt 缺失');
|
|
347
|
+
const ok2 = c.attempted === true && Array.isArray(c.components) && c.components.length > 0 && c.exhausted === true;
|
|
348
|
+
return { ok: true, pass: ok2, reason: ok2 ? undefined : '未证明现有组件已穷尽', evidence: { tried: c.components && c.components.length, exhausted: c.exhausted } };
|
|
349
|
+
} },
|
|
350
|
+
{ id: 'MC1_B', name: '新组件必须是"最小、最高效"', fn: (i) => {
|
|
351
|
+
const n = i && i.proposedComponent;
|
|
352
|
+
if (!n) return bad('proposedComponent 缺失');
|
|
353
|
+
return { ok: true, pass: !!(n.minimal === true && n.id && n.kind), evidence: n };
|
|
354
|
+
} },
|
|
355
|
+
],
|
|
356
|
+
exec: (i, tid) => runPipeline(REGISTRY[7].stages, i, tid),
|
|
357
|
+
},
|
|
358
|
+
{
|
|
359
|
+
id: 'PROTOCOL_META_CREATION_002', name: '元创造·内生生成协议', kind: 'pipeline', units: 1,
|
|
360
|
+
source: '缺口 29;语义依 A5 内生公理(创造能力内生,不依赖外部数据输入)',
|
|
361
|
+
stages: [
|
|
362
|
+
{ id: 'MC2_A', name: '不得依赖外部数据输入', fn: (i) => {
|
|
363
|
+
const d = i && i.inputs;
|
|
364
|
+
if (!d) return bad('inputs 缺失');
|
|
365
|
+
return { ok: true, pass: d.externalDataUsed !== true, reason: d.externalDataUsed ? '违反 A5 内生公理:不得依赖外部数据输入' : undefined, evidence: { externalDataUsed: d.externalDataUsed } };
|
|
366
|
+
} },
|
|
367
|
+
{ id: 'MC2_B', name: '必须声明内生来源', fn: (i) => {
|
|
368
|
+
const s = i && i.internalSource;
|
|
369
|
+
const valid = ['existing-components','recombination','constraint-driven','boundary-sensing'];
|
|
370
|
+
return { ok: true, pass: !!s && valid.includes(s), reason: s && !valid.includes(s) ? '非法的内生来源:' + s : undefined, evidence: { internalSource: s, allowed: valid } };
|
|
371
|
+
} },
|
|
372
|
+
],
|
|
373
|
+
exec: (i, tid) => runPipeline(REGISTRY[8].stages, i, tid),
|
|
374
|
+
},
|
|
375
|
+
{
|
|
376
|
+
id: 'PROTOCOL_META_CREATION_003', name: '元创造·验证固化协议', kind: 'pipeline', units: 1,
|
|
377
|
+
source: '缺口 29;语义依元进化五阶段第 4 步「验证→必须通过验证才能保留」',
|
|
378
|
+
stages: [
|
|
379
|
+
{ id: 'MC3_A', name: '新创造必须通过验证才可保留', fn: (i) => {
|
|
380
|
+
const v = i && i.verification;
|
|
381
|
+
if (!v) return bad('verification 缺失');
|
|
382
|
+
return { ok: true, pass: v.passed === true && Array.isArray(v.checks) && v.checks.length > 0, evidence: { passed: v.passed, checks: v.checks && v.checks.length } };
|
|
383
|
+
} },
|
|
384
|
+
{ id: 'MC3_B', name: '固化必须有版本与来源', fn: (i) => {
|
|
385
|
+
const f = i && i.freezing;
|
|
386
|
+
if (!f) return bad('freezing 缺失');
|
|
387
|
+
return { ok: true, pass: !!(f.version && f.sourceRef), evidence: f };
|
|
388
|
+
} },
|
|
389
|
+
],
|
|
390
|
+
exec: (i, tid) => runPipeline(REGISTRY[9].stages, i, tid),
|
|
391
|
+
},
|
|
392
|
+
{
|
|
393
|
+
id: 'PROTOCOL_META_CREATION_V1', name: '元创造总纲协议', kind: 'pipeline', units: 1,
|
|
394
|
+
source: '缺口 29;串联 001→002→003',
|
|
395
|
+
stages: [
|
|
396
|
+
{ id: 'MCV_1', name: '边界突破前置', fn: (i) => {
|
|
397
|
+
const c = i && i.closureAttempt;
|
|
398
|
+
return { ok: true, pass: !!(c && c.exhausted === true), reason: c && c.exhausted !== true ? '未完成边界突破前置(见 001)' : undefined };
|
|
399
|
+
} },
|
|
400
|
+
{ id: 'MCV_2', name: '内生生成前置', fn: (i) => {
|
|
401
|
+
return { ok: true, pass: !!(i && i.inputs && i.inputs.externalDataUsed !== true && i.internalSource), reason: '未完成内生生成前置(见 002)' };
|
|
402
|
+
} },
|
|
403
|
+
{ id: 'MCV_3', name: '验证固化前置', fn: (i) => {
|
|
404
|
+
const v = i && i.verification, f = i && i.freezing;
|
|
405
|
+
return { ok: true, pass: !!(v && v.passed === true && f && f.version), reason: '未完成验证固化前置(见 003)' };
|
|
406
|
+
} },
|
|
407
|
+
{ id: 'MCV_4', name: '创造必须有谱系(可回溯到缺口)', fn: (i) => {
|
|
408
|
+
const l = i && i.lineage;
|
|
409
|
+
return { ok: true, pass: Array.isArray(l) && l.length > 0 && l.every((x) => x && x.source), evidence: { links: l && l.length } };
|
|
410
|
+
} },
|
|
411
|
+
],
|
|
412
|
+
exec: (i, tid) => runPipeline(REGISTRY[10].stages, i, tid),
|
|
413
|
+
},
|
|
414
|
+
];
|
|
415
|
+
|
|
416
|
+
/* ══════════════════════════════════════════════════════════════
|
|
417
|
+
* 五、公开接口
|
|
418
|
+
* ══════════════════════════════════════════════════════════════ */
|
|
419
|
+
|
|
420
|
+
const INDEX = new Map(REGISTRY.map((p) => [p.id, p]));
|
|
421
|
+
|
|
422
|
+
function kindOf(id) { const p = INDEX.get(id); return p ? p.kind : 'declared'; }
|
|
423
|
+
function getRegistry() { return REGISTRY.map((p) => ({ id: p.id, name: p.name, kind: p.kind, units: p.units, source: p.source })); }
|
|
424
|
+
|
|
425
|
+
function executeSync(id, input) {
|
|
426
|
+
const t0 = Date.now();
|
|
427
|
+
const p = INDEX.get(id);
|
|
428
|
+
const tid = newTraceId();
|
|
429
|
+
if (!p) return { success: false, kind: 'declared', reason: 'NOT_FOUND', error: `协议 ${id} 未登记`, provenance: [], traceId: tid, durationMs: 0 };
|
|
430
|
+
let r;
|
|
431
|
+
try { r = p.exec(input || {}, tid); }
|
|
432
|
+
catch (e) { r = { success: false, kind: p.kind, error: 'THROW: ' + e.message, provenance: [`[${tid}] THROW`], traceId: tid }; }
|
|
433
|
+
r.durationMs = Date.now() - t0;
|
|
434
|
+
r.protocolId = id;
|
|
435
|
+
r.protocolName = p.name;
|
|
436
|
+
return r;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
async function execute(id, input) { return executeSync(id, input); }
|
|
440
|
+
|
|
441
|
+
module.exports = { executeSync, execute, kindOf, getRegistry, REGISTRY, INDEX, newTraceId, _internals: { gateIVL, gateILT, gateOSG, gateIntegrity, stageBoundary, stageGap, stageSelfGenerate, stageVerify, stageRecurse } };
|
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
> 智能不是被编程的,是被唤醒的。
|
|
4
4
|
> Intelligence is not programmed; it is awakened.
|
|
5
5
|
|
|
6
|
-
**MetaGO Engine V2** ——
|
|
6
|
+
**MetaGO Engine V2** —— 智能体运行时(驭智层)的硬驱动核心。让法则可执行,而非仅仅是建议。
|
|
7
7
|
|
|
8
8
|
[](https://gitee.com/metago/metagolifeform/raw/main/packages/engine/GENOME.json)
|
|
9
9
|
[](https://gitee.com/metago/metagolifeform/raw/main/packages/engine/ENGINE.md)
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
## What is this?
|
|
14
14
|
|
|
15
|
-
MetaGO Engine V2 is the **runtime execution layer** of the [MetaGO
|
|
15
|
+
MetaGO Engine V2 is the **runtime execution layer** of the [MetaGO Intelligent Lifeform](../). While the runtime's Markdown law (AGENTS.md) tells the agent *what* the rules are, Engine V2 is the code that makes sure the agent *can't bypass them*.
|
|
16
16
|
|
|
17
17
|
### What's new in V2.0.0
|
|
18
18
|
|
|
@@ -138,8 +138,8 @@ packages/engine/
|
|
|
138
138
|
│ ├── ATTRIBUTES.md ← 43 attributes (7 critical)
|
|
139
139
|
│ └── PROTOCOLS.md ← 108 protocols (6 critical)
|
|
140
140
|
├── INDEX/ ← Index layer
|
|
141
|
-
│ ├── engines.json ←
|
|
142
|
-
│ ├── skills.json ←
|
|
141
|
+
│ ├── engines.json ← 161 engines
|
|
142
|
+
│ ├── skills.json ← 112 skills
|
|
143
143
|
│ ├── tools.json ← 55 MCP tools
|
|
144
144
|
│ └── knowledge.json ← Knowledge crystal index
|
|
145
145
|
├── RUNTIME/ ← Runtime layer (TypeScript) ← V2 lives here
|
|
@@ -159,7 +159,7 @@ packages/engine/
|
|
|
159
159
|
│ └── tsconfig.json
|
|
160
160
|
├── SDK/
|
|
161
161
|
│ └── types.d.ts ← Developer type interfaces
|
|
162
|
-
├── ADAPTERS/ ← Platform adapters (
|
|
162
|
+
├── ADAPTERS/ ← Platform adapters (11 platforms)
|
|
163
163
|
├── EVOLUTION.md ← Evolution mechanism
|
|
164
164
|
├── CHANGES.md ← Version history
|
|
165
165
|
└── PATENTS.md ← Patent declarations
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kmwi-memory.d.ts","sourceRoot":"","sources":["../src/kmwi-memory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AASH,MAAM,MAAM,WAAW,GAAG,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B,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,eAAe;IAgBvB,UAAU,IAAI,gBAAgB,EAAE;IAIhC,UAAU,IAAI,MAAM;IA4BpB,KAAK,IAAI,IAAI;IAUb;;;OAGG;IACH,2BAA2B,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,SAAI,GAAG;QAAE,MAAM,EAAE,UAAU,EAAE,CAAC;QAAC,UAAU,EAAE,aAAa,EAAE,CAAA;KAAE;CAqB9G;AAED,eAAe,UAAU,CAAC"}
|
|
@@ -97,7 +97,15 @@ class KMWIMemory {
|
|
|
97
97
|
const snapshot = JSON.parse(content);
|
|
98
98
|
for (const item of snapshot.knowledge || [])
|
|
99
99
|
this.knowledge.set(item.id, item);
|
|
100
|
-
|
|
100
|
+
// `memories` is the canonical key. `memory` (singular) is what
|
|
101
|
+
// scripts/init-kmwi-store.cjs wrote before it was aligned with this class —
|
|
102
|
+
// reading both keeps stores created by that script from silently losing the
|
|
103
|
+
// whole M layer (which made getHealth() divide by an empty layer and
|
|
104
|
+
// memory_manage throw on a missing `length`).
|
|
105
|
+
const memories = snapshot.memories
|
|
106
|
+
|| snapshot.memory
|
|
107
|
+
|| [];
|
|
108
|
+
for (const item of memories)
|
|
101
109
|
this.memories.set(item.id, item);
|
|
102
110
|
for (const item of snapshot.wisdom || [])
|
|
103
111
|
this.wisdom.set(item.id, item);
|
|
@@ -659,7 +667,11 @@ class KMWIMemory {
|
|
|
659
667
|
const intuitions = Array.from(this.intuitions.values());
|
|
660
668
|
if (intuitions.length === 0)
|
|
661
669
|
return 0;
|
|
662
|
-
|
|
670
|
+
// `explicitForm` is a string on items this class creates, but a store written by
|
|
671
|
+
// an older seed script has no such field at all — reading `.length` off undefined
|
|
672
|
+
// threw out of getHealth(), which is what made memory_manage fail on seeded
|
|
673
|
+
// stores. Absent evidence of explicitness is 0, not a crash.
|
|
674
|
+
const explicit = intuitions.filter(i => (i.explicitForm || '').length > 0).length;
|
|
663
675
|
return explicit / intuitions.length;
|
|
664
676
|
}
|
|
665
677
|
// ============================================================================
|