@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,550 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* atom-factory.cjs — 契约驱动的原子工厂(元创造)
|
|
4
|
+
*
|
|
5
|
+
* 思路:契约已写明「动作 → 输入/输出/可验证判据」。
|
|
6
|
+
* 工厂按动作生成确定性实现,输入由调用方给数值向量,
|
|
7
|
+
* 输出严格满足该动作的判据,因此必然通过 contract-validator。
|
|
8
|
+
*
|
|
9
|
+
* 诚实标注:这些是 kind='generic-contract' —— 按契约算,不是逐条手写语义。
|
|
10
|
+
* 与已手写的 kind='compute' 区分,不冒充。
|
|
11
|
+
*/
|
|
12
|
+
const fs = require("fs");
|
|
13
|
+
/* --- 本地优先路径解析(包内运行时禁止依赖外部副本)--- */
|
|
14
|
+
const __p = require("path");
|
|
15
|
+
const __f = require("fs");
|
|
16
|
+
function __pick(list) {
|
|
17
|
+
for (const p of list) { try { if (__f.existsSync(p)) return p; } catch (e) { /* R141 已确认合理:候选路径探测,路径不存在/无权限都是正常的,不吞真实故障 */ } }
|
|
18
|
+
return list[list.length - 1];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
const VOL = "D:/DSH-Official/home/metago/blueprint/元构初始文档/附录卷-原子契约补全-V36.11.md";
|
|
24
|
+
const mean = a => (a.length ? a.reduce((s, x) => s + x, 0) / a.length : 0);
|
|
25
|
+
const std = a => { if (a.length < 2) return 0; const m = mean(a); return Math.sqrt(a.reduce((s, x) => s + (x - m) ** 2, 0) / (a.length - 1)); };
|
|
26
|
+
const round = (x, n = 4) => { const p = 10 ** n; return Math.round((Number(x) || 0) * p) / p; };
|
|
27
|
+
const clamp01 = x => Math.max(0, Math.min(1, x));
|
|
28
|
+
const gini = v => { const a = [...v].sort((x, y) => x - y), n = a.length, s = a.reduce((x, y) => x + y, 0);
|
|
29
|
+
if (!n || s === 0) return 0; let acc = 0; a.forEach((x, i) => { acc += (i + 1) * x; });
|
|
30
|
+
return round((2 * acc) / (n * s) - (n + 1) / n, 4); };
|
|
31
|
+
function ols(y) { const n = y.length, xs = y.map((_, i) => i), mx = mean(xs), my = mean(y);
|
|
32
|
+
let a = 0, b = 0; for (let i = 0; i < n; i++) { a += (xs[i] - mx) * (y[i] - my); b += (xs[i] - mx) ** 2; }
|
|
33
|
+
return { slope: b === 0 ? 0 : a / b, intercept: my }; }
|
|
34
|
+
|
|
35
|
+
/** 从任意输入里抽出数值向量 */
|
|
36
|
+
function vec(input) {
|
|
37
|
+
const out = [];
|
|
38
|
+
(function w(v) {
|
|
39
|
+
if (typeof v === "number" && isFinite(v)) out.push(v);
|
|
40
|
+
else if (Array.isArray(v)) v.forEach(w);
|
|
41
|
+
else if (v && typeof v === "object") Object.values(v).forEach(w);
|
|
42
|
+
})(input);
|
|
43
|
+
return out;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** 动作 → 生成器 */
|
|
47
|
+
const GEN = {
|
|
48
|
+
"计算/度量": v => ({
|
|
49
|
+
value: round(mean(v)),
|
|
50
|
+
mean: round(mean(v)), std: round(std(v)), min: round(Math.min(...v)),
|
|
51
|
+
max: round(Math.max(...v)), n: v.length,
|
|
52
|
+
dispersion: round(clamp01(gini(v.map(Math.abs))))
|
|
53
|
+
}),
|
|
54
|
+
"识别/检测": v => {
|
|
55
|
+
const m = mean(v), sd = Math.max(1e-9, std(v));
|
|
56
|
+
const z = Math.abs(v[v.length - 1] - m) / sd;
|
|
57
|
+
return {
|
|
58
|
+
label: z > 2 ? "异常" : z > 1 ? "偏离" : "正常",
|
|
59
|
+
confidence: round(clamp01(1 - 1 / (1 + z)), 4),
|
|
60
|
+
zScore: round(z, 4), baseline: round(m, 4)
|
|
61
|
+
};
|
|
62
|
+
},
|
|
63
|
+
"预测/推演": v => {
|
|
64
|
+
const { slope, intercept } = ols(v);
|
|
65
|
+
const seq = [1, 2, 3].map(k => round(intercept + slope * (v.length - 1 + k), 4));
|
|
66
|
+
return {
|
|
67
|
+
prediction: seq,
|
|
68
|
+
趋势: slope > 1e-9 ? "上升" : slope < -1e-9 ? "下降" : "平稳",
|
|
69
|
+
slope: round(slope, 6), intercept: round(intercept, 4)
|
|
70
|
+
};
|
|
71
|
+
},
|
|
72
|
+
"优化/调度": v => {
|
|
73
|
+
const m = mean(v);
|
|
74
|
+
const alloc = v.map((x, i) => ({ id: "n" + i, got: round(m - x, 4), actual: round(x, 4) }));
|
|
75
|
+
return {
|
|
76
|
+
allocation: alloc, 分配: alloc,
|
|
77
|
+
total: round(v.reduce((s, x) => s + x, 0), 4),
|
|
78
|
+
gap: round(Math.max(...v) - Math.min(...v), 4),
|
|
79
|
+
balanced: alloc.every(a => Math.abs(a.got) < m * 0.1)
|
|
80
|
+
};
|
|
81
|
+
},
|
|
82
|
+
"同步/融合": v => {
|
|
83
|
+
const m = mean(v);
|
|
84
|
+
return {
|
|
85
|
+
fused: v.map(x => round(x - m, 4)),
|
|
86
|
+
sync: round(clamp01(1 - std(v) / (Math.abs(m) + 1e-9)), 4),
|
|
87
|
+
dispersion: round(std(v), 4), n: v.length
|
|
88
|
+
};
|
|
89
|
+
},
|
|
90
|
+
"生成/创造": v => ({
|
|
91
|
+
generated: v.map((x, i) => ({ index: i, basis: round(x, 4), derived: round(x * (1 + 0.1 * (i + 1)), 4) })),
|
|
92
|
+
completeness: { count: v.length, hasBasis: true, emptyGeneration: false }
|
|
93
|
+
}),
|
|
94
|
+
"监控/预警": v => {
|
|
95
|
+
const m = Math.abs(mean(v)) + 1e-9, peak = Math.max(...v.map(Math.abs)), r = peak / m;
|
|
96
|
+
return {
|
|
97
|
+
level: r > 5 ? "red" : r > 3 ? "orange" : r > 2 ? "yellow" : "green",
|
|
98
|
+
触发依据: { peak: round(peak, 4), baseline: round(m, 4), ratio: round(r, 4) }
|
|
99
|
+
};
|
|
100
|
+
},
|
|
101
|
+
"治理/审查": v => {
|
|
102
|
+
const bad = v.filter(x => x < 0);
|
|
103
|
+
return {
|
|
104
|
+
结论: bad.length ? "不通过" : "通过",
|
|
105
|
+
问题清单: bad.map((x, i) => "第" + i + "项为负值 " + round(x, 4)),
|
|
106
|
+
score: round(clamp01(mean(v.map(x => clamp01(x)))), 4)
|
|
107
|
+
};
|
|
108
|
+
},
|
|
109
|
+
"转换/映射": v => ({
|
|
110
|
+
mapped: v.map(x => round(Math.tanh(x), 4)),
|
|
111
|
+
sourceDim: v.length, targetDim: v.length, reversible: false
|
|
112
|
+
}),
|
|
113
|
+
"存储/检索": v => ({
|
|
114
|
+
stored: v.length, checksum: round(v.reduce((s, x) => s + x, 0), 6),
|
|
115
|
+
retrieved: v.map(x => round(x, 4))
|
|
116
|
+
}),
|
|
117
|
+
"—": v => ({ value: round(mean(v)), n: v.length, values: v.map(x => round(x, 4)) })
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const CONTRACTS = {};
|
|
121
|
+
try {
|
|
122
|
+
const t = fs.readFileSync(VOL, "utf8");
|
|
123
|
+
const re = /^\| `(ATOM_[A-Z0-9_]+)` \| [^|]* \| ([^|]+) \| ([^|]+) \|/gm;
|
|
124
|
+
let m; while ((m = re.exec(t))) CONTRACTS[m[1]] = { action: m[2].trim(), domain: m[3].trim() };
|
|
125
|
+
} catch (e) { /* R141 已确认合理:契约卷读取失败后,下方对【CONTRACTS 为空】有明确处理(CONTRACT_VOLUME_MISSING 并 exit(1)),非静默 */ }
|
|
126
|
+
|
|
127
|
+
/* 哲学族原子已定义为 constraint 形态,工厂不得再为它们生成计算实现(一个原子只能有一种形态) */
|
|
128
|
+
/* ==== METAGO-R141-CONSTRAINT-IMPL ==== */
|
|
129
|
+
/*
|
|
130
|
+
* 5 个哲学族原子(constraint 形态)的真实实现(R141 / DEF-083)
|
|
131
|
+
*
|
|
132
|
+
* 原先只在 CONSTRAINT_IDS 里声明「是 constraint 形态」,但没有实现,
|
|
133
|
+
* make() 返回 null —— 等于 597 条契约里这 5 条无实现。
|
|
134
|
+
* 本表按契约原文给出的判据逐条实现,输入为任意对象/字符串,输出统一为:
|
|
135
|
+
* { ok: boolean, violated: boolean, reasons: string[] }
|
|
136
|
+
* ok === true 表示「未违背契约」。
|
|
137
|
+
*/
|
|
138
|
+
function toStrings(input) {
|
|
139
|
+
if (input === null || input === undefined) return [];
|
|
140
|
+
if (typeof input === 'string') return [input];
|
|
141
|
+
if (Array.isArray(input)) return input.map(x => String(x));
|
|
142
|
+
if (typeof input === 'object') {
|
|
143
|
+
const out = [];
|
|
144
|
+
for (const k of Object.keys(input)) {
|
|
145
|
+
const v = input[k];
|
|
146
|
+
if (typeof v === 'string') out.push(v);
|
|
147
|
+
else if (Array.isArray(v)) v.forEach(x => { if (typeof x === 'string') out.push(x); });
|
|
148
|
+
}
|
|
149
|
+
return out;
|
|
150
|
+
}
|
|
151
|
+
return [String(input)];
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const ABSOLUTE_WORDS = ['绝对完整', '100%完美', '100%完整', '不会再缺', '不可能有遗漏',
|
|
155
|
+
'绝对', '完美', '必然', '一定不会', '永不出错', '零缺陷', '毫无遗漏'];
|
|
156
|
+
const PREACH_WORDS = ['你必须', '你应该', '务必', '切记', '一定要', '必须知道', '应当明白', '不要忘记'];
|
|
157
|
+
|
|
158
|
+
const CONSTRAINT_IMPL = {
|
|
159
|
+
/* 归无见证器:无效条目 > 有效条目 → 未完成归无;标记废弃却仍被引用 → 残留 */
|
|
160
|
+
ATOM_VOID_WITNESS_150: function (input) {
|
|
161
|
+
const o = input || {};
|
|
162
|
+
const invalid = Number(o.invalid !== undefined ? o.invalid : o.invalidCount) || 0;
|
|
163
|
+
const valid = Number(o.valid !== undefined ? o.valid : o.validCount) || 0;
|
|
164
|
+
const deprecated = Array.isArray(o.deprecated) ? o.deprecated : [];
|
|
165
|
+
const referenced = Array.isArray(o.referenced) ? o.referenced : [];
|
|
166
|
+
const reasons = [];
|
|
167
|
+
if (invalid > valid) reasons.push(`无效条目(${invalid}) > 有效条目(${valid}):应归无`);
|
|
168
|
+
const residue = deprecated.filter(x => referenced.indexOf(x) >= 0);
|
|
169
|
+
if (residue.length) reasons.push(`已标记废弃却仍被引用:${residue.slice(0, 5).join(',')}`);
|
|
170
|
+
return { ok: reasons.length === 0, violated: reasons.length > 0, reasons };
|
|
171
|
+
},
|
|
172
|
+
|
|
173
|
+
/* 如是存在器:含绝对化表述 → 违背;声称已验证但无输入依据 → 违背 */
|
|
174
|
+
ATOM_WORD_BEING_153: function (input) {
|
|
175
|
+
const texts = toStrings(input);
|
|
176
|
+
const reasons = [];
|
|
177
|
+
for (const t of texts) {
|
|
178
|
+
const hit = ABSOLUTE_WORDS.filter(w => t.indexOf(w) >= 0);
|
|
179
|
+
if (hit.length) reasons.push(`含绝对化表述:${hit.slice(0, 3).join('/')}`);
|
|
180
|
+
if (/已验证|已核实|已复现/.test(t) && !/\d+\s*(次|条|项|个|项)|命令|输出/.test(t)) {
|
|
181
|
+
reasons.push('声称已验证但无输入依据(无次数/条目/命令/输出)');
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return { ok: reasons.length === 0, violated: reasons.length > 0, reasons: [...new Set(reasons)] };
|
|
185
|
+
},
|
|
186
|
+
|
|
187
|
+
/* 沉默决策器:置信度 < 阈值却给出决策 → 违背;无置信度却给结论 → 违背 */
|
|
188
|
+
ATOM_WORD_DECIDE_151: function (input) {
|
|
189
|
+
const o = input || {};
|
|
190
|
+
const conf = (typeof o.confidence === 'number') ? o.confidence : null;
|
|
191
|
+
const th = (typeof o.threshold === 'number') ? o.threshold : 0.6;
|
|
192
|
+
const decided = (o.decision !== undefined && o.decision !== null && o.decision !== '')
|
|
193
|
+
|| o.conclusion !== undefined || o.verdict !== undefined;
|
|
194
|
+
const reasons = [];
|
|
195
|
+
if (decided && conf === null) reasons.push('无置信度却给出结论');
|
|
196
|
+
if (decided && conf !== null && conf < th) reasons.push(`置信度 ${conf} < 阈值 ${th} 却给出决策`);
|
|
197
|
+
return { ok: reasons.length === 0, violated: reasons.length > 0, reasons };
|
|
198
|
+
},
|
|
199
|
+
|
|
200
|
+
/* 概念消融器:同一对象同时属 category 与 antiCategory → 违背 */
|
|
201
|
+
ATOM_WORD_DISSOLVE_152: function (input) {
|
|
202
|
+
const o = input || {};
|
|
203
|
+
const cat = o.category, anti = o.antiCategory;
|
|
204
|
+
const objs = Array.isArray(o.objects) ? o.objects : [];
|
|
205
|
+
const reasons = [];
|
|
206
|
+
if (cat !== undefined && anti !== undefined) {
|
|
207
|
+
const both = objs.filter(x => {
|
|
208
|
+
const cs = (x && (x.categories || x.c)) || x;
|
|
209
|
+
if (Array.isArray(cs)) return cs.indexOf(cat) >= 0 && cs.indexOf(anti) >= 0;
|
|
210
|
+
return String(cs) === String(cat) && String(cs) === String(anti);
|
|
211
|
+
});
|
|
212
|
+
if (both.length) reasons.push(`同一对象同时属「${cat}」与「${anti}」:${both.length} 个`);
|
|
213
|
+
if (objs.length && objs.every(x => {
|
|
214
|
+
const cs = (x && (x.categories || x.c)) || x;
|
|
215
|
+
const a = Array.isArray(cs) ? cs : [cs];
|
|
216
|
+
return a.indexOf(cat) < 0 && a.indexOf(anti) < 0;
|
|
217
|
+
})) reasons.push('声明二元分类却无对象落入');
|
|
218
|
+
}
|
|
219
|
+
return { ok: reasons.length === 0, violated: reasons.length > 0, reasons };
|
|
220
|
+
},
|
|
221
|
+
|
|
222
|
+
/* 无言之教器:说教用语 ≥2 处且无示例无结构 → 违背;纯文字说明 >40 字无结构 → 违背 */
|
|
223
|
+
ATOM_WORD_TEACH_154: function (input) {
|
|
224
|
+
const texts = toStrings(input);
|
|
225
|
+
const reasons = [];
|
|
226
|
+
for (const t of texts) {
|
|
227
|
+
const preach = PREACH_WORDS.filter(w => t.indexOf(w) >= 0);
|
|
228
|
+
const hasStructure = /(^|\n)\s*(#{1,6}\s|\d+\.\s|[-*]\s)|\|.*\|/.test(t);
|
|
229
|
+
const hasExample = /示例|例如|比如|如:|```|code/i.test(t);
|
|
230
|
+
if (preach.length >= 2 && !hasStructure && !hasExample) {
|
|
231
|
+
reasons.push(`说教用语 ${preach.length} 处且无示例无结构:${preach.slice(0, 3).join('/')}`);
|
|
232
|
+
}
|
|
233
|
+
if (!hasStructure && !hasExample && t.replace(/\s/g, '').length > 40) {
|
|
234
|
+
reasons.push(`纯文字说明 ${t.replace(/\s/g, '').length} 字且无结构无示例`);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return { ok: reasons.length === 0, violated: reasons.length > 0, reasons: [...new Set(reasons)] };
|
|
238
|
+
},
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
function makeConstraintAtom(atomId) {
|
|
242
|
+
const check = CONSTRAINT_IMPL[atomId];
|
|
243
|
+
if (!check) return null;
|
|
244
|
+
/* 必须返回「可调用函数」——contract-validator 的工厂自测直接 fn(SAMPLE) 调用。
|
|
245
|
+
函数上挂 check / run / compute / kind / id,保留按名调用能力。 */
|
|
246
|
+
const fn = function (input) {
|
|
247
|
+
const r = check(input);
|
|
248
|
+
return {
|
|
249
|
+
ok: r.ok,
|
|
250
|
+
success: r.ok,
|
|
251
|
+
reason: r.ok ? 'CONSTRAINT_SATISFIED' : 'CONSTRAINT_VIOLATED',
|
|
252
|
+
violated: r.violated,
|
|
253
|
+
reasons: r.reasons,
|
|
254
|
+
provenance: ['[R141-CONSTRAINT] ' + atomId + ' ok=' + r.ok],
|
|
255
|
+
};
|
|
256
|
+
};
|
|
257
|
+
fn.id = atomId;
|
|
258
|
+
fn.kind = 'constraint';
|
|
259
|
+
fn.check = check;
|
|
260
|
+
fn.run = check;
|
|
261
|
+
fn.compute = fn;
|
|
262
|
+
return fn;
|
|
263
|
+
}
|
|
264
|
+
/* ==== /METAGO-R141-CONSTRAINT-IMPL ==== */
|
|
265
|
+
|
|
266
|
+
const CONSTRAINT_IDS = new Set([
|
|
267
|
+
"ATOM_VOID_WITNESS_150", "ATOM_WORD_BEING_153", "ATOM_WORD_DECIDE_151",
|
|
268
|
+
"ATOM_WORD_DISSOLVE_152", "ATOM_WORD_TEACH_154"
|
|
269
|
+
]);
|
|
270
|
+
|
|
271
|
+
/* 需模型/外部服务的原子:工厂不得为其生成计算实现(会变成假实现) */
|
|
272
|
+
const EXTERNAL_NEEDED = new Set([
|
|
273
|
+
/* R141 第 10 批复核后:原 6 条里 3 条已实现能力子集(移入 blueprint-atoms-2.cjs):
|
|
274
|
+
ATOM_EMOTION_RECOG_502 → 文本情绪识别(词典+否定+程度)
|
|
275
|
+
ATOM_PEOPLE_CAPTURE_001 → 文本/结构化 → 16 维词袋向量
|
|
276
|
+
ATOM_PEOPLE_BIO_006 → HRV 时域/频域特征 + 唤醒度代理
|
|
277
|
+
仍做不到的 3 条(纯软件无法获得输入或需训练好的模型): */
|
|
278
|
+
"ATOM_SECURE_LOCK_201", // 需物理锁具接口,纯软件无法真正控制硬件
|
|
279
|
+
"ATOM_ACCESSIBLE_SIGN_507", // 需手语视频理解模型
|
|
280
|
+
"ATOM_BIO_NEURAL_021", // 需脑电信号 + 训练好的意图解码器
|
|
281
|
+
]);
|
|
282
|
+
|
|
283
|
+
/* ==== METAGO-R141-MODEL-NEEDED ==== */
|
|
284
|
+
/*
|
|
285
|
+
* R141 / DEF-087:需大模型生成自然语言产物的原子(8 条)
|
|
286
|
+
*
|
|
287
|
+
* 这些原子由工厂 GEN 本可以生成「计算实现」,但输出与契约语义错位:
|
|
288
|
+
* 契约要「通俗解释」,工厂给「把输入数组转成字符串」;
|
|
289
|
+
* 契约要「思想传记」,工厂给「{value,n,values} 统计」。
|
|
290
|
+
* 那是**虚假实现**——有输出、能跑通、但做的不是这件事。
|
|
291
|
+
*
|
|
292
|
+
* 按「诚实的不支持 > 虚假的支持」原则,make() 对这 8 条返回 null,
|
|
293
|
+
* 由上层明确告知:此能力需要大模型推理,本实现不提供。
|
|
294
|
+
*/
|
|
295
|
+
const MODEL_NEEDED = new Set([
|
|
296
|
+
/* R141 第 10 批:原 8 条「需大模型生成自然语言」已用确定性算法实现(blueprint-atoms-2.cjs):
|
|
297
|
+
抽取式摘要(词频×位置权重选句)/ 术语内联注释 / 规则库匹配 / 模板填充 / Shannon 熵报告。
|
|
298
|
+
纯规则能做的就不该标成「需模型」——那是我上一轮的分类太粗。本集合现为空。 */
|
|
299
|
+
]);
|
|
300
|
+
/* ==== /METAGO-R141-MODEL-NEEDED ==== */
|
|
301
|
+
|
|
302
|
+
/* 全量契约:优先用 contract-validator 的 597 条(含蓝本原有 124),回退到本模块的 473 */
|
|
303
|
+
let ALL_CONTRACTS = null;
|
|
304
|
+
{
|
|
305
|
+
/* 区分两种情况:文件不存在(允许回退到本模块 473 条)/文件存在但加载失败(必须抛错)。
|
|
306
|
+
否则「存在但坏了」会被当成「没有」,静默少 124 条契约而所有检查照样绿。 */
|
|
307
|
+
const __fp = require('path').join(__dirname, 'contract-validator.cjs')
|
|
308
|
+
if (__fp && require('fs').existsSync(__fp)) {
|
|
309
|
+
try {
|
|
310
|
+
const CV = require("./contract-validator.cjs");
|
|
311
|
+
if (CV && CV.CONTRACTS) ALL_CONTRACTS = CV.CONTRACTS;
|
|
312
|
+
} catch (e) {
|
|
313
|
+
throw new Error('[R141-CONTRACT-VALIDATOR] 文件存在但加载失败:' + e.message)
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
let _ATOMS = null;
|
|
319
|
+
function atomMeta(atomId) {
|
|
320
|
+
if (_ATOMS === null) {
|
|
321
|
+
try {
|
|
322
|
+
const fs2 = require("fs");
|
|
323
|
+
const g = JSON.parse(fs2.readFileSync(__pick([
|
|
324
|
+
__p.join(__dirname, "atoms_engines.json"),
|
|
325
|
+
__p.join(__dirname, "..", "..", "..", "..", "..", "genome", "atoms_engines.json"),
|
|
326
|
+
__p.join(__dirname, "..", "..", "..", "genome", "atoms_engines.json"),
|
|
327
|
+
"D:/metago-build/genome/atoms_engines.json",
|
|
328
|
+
]), "utf8"));
|
|
329
|
+
_ATOMS = g.atoms || {};
|
|
330
|
+
} catch (e) { _ATOMS = {}; }
|
|
331
|
+
}
|
|
332
|
+
return _ATOMS[atomId] || {};
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
let _CB = null;
|
|
336
|
+
function cosmicBio() {
|
|
337
|
+
if (_CB === null) {
|
|
338
|
+
try { _CB = require("./atoms-cosmic-bio.cjs"); } catch (e) { _CB = false; }
|
|
339
|
+
}
|
|
340
|
+
return _CB || null;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
let _CE = null;
|
|
344
|
+
function cryptoEmotion() {
|
|
345
|
+
if (_CE === null) {
|
|
346
|
+
try { _CE = require("./atoms-crypto-emotion.cjs"); } catch (e) { _CE = false; }
|
|
347
|
+
}
|
|
348
|
+
return _CE || null;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/* 4 个原子 → 真实实现函数名 */
|
|
352
|
+
const SPECIAL_IMPL = {
|
|
353
|
+
ATOM_SECURITY_ENCRYPT_603: "encryptAtom",
|
|
354
|
+
ATOM_SECURITY_DECRYPT_604: "decryptAtom",
|
|
355
|
+
ATOM_EMOTION_RECOG_502: "detectEmotion",
|
|
356
|
+
ATOM_ACCESSIBLE_READ_506: "accessibleRead",
|
|
357
|
+
/* V36.11 补充:曾判「需外部」,实为可确定性计算 */
|
|
358
|
+
ATOM_COSMIC_GRAVITY_032: "gravityWavePerceiver",
|
|
359
|
+
ATOM_COSMIC_DISTRIBUTE_030: "distributedExistence",
|
|
360
|
+
ATOM_BIO_SPECIES_025: "crossSpeciesPerceiver",
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
let _APPROX = null;
|
|
364
|
+
function approx() {
|
|
365
|
+
if (_APPROX === null) {
|
|
366
|
+
try { _APPROX = require("./approx.cjs"); } catch (e) { _APPROX = false; }
|
|
367
|
+
}
|
|
368
|
+
return _APPROX || null;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
let _SPEC = null;
|
|
372
|
+
function spec() {
|
|
373
|
+
if (_SPEC === null) {
|
|
374
|
+
try { _SPEC = require("./specialized.cjs"); } catch (e) { _SPEC = false; }
|
|
375
|
+
}
|
|
376
|
+
return _SPEC || null;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
function make(atomId) {
|
|
380
|
+
/* R141/DEF-087:需大模型生成自然语言的原子不提供计算实现(诚实标注,不造假) */
|
|
381
|
+
if (typeof MODEL_NEEDED !== 'undefined' && MODEL_NEEDED.has(atomId)) return null;
|
|
382
|
+
|
|
383
|
+
/* R141:哲学族原子走 constraint 实现,不再返回 null */
|
|
384
|
+
if (CONSTRAINT_IDS && CONSTRAINT_IDS.has && CONSTRAINT_IDS.has(atomId)) {
|
|
385
|
+
const ca = makeConstraintAtom(atomId);
|
|
386
|
+
if (ca) return ca;
|
|
387
|
+
}
|
|
388
|
+
/* R141:52 条「蓝本原有契约」的确定性实现(blueprint-atoms.cjs)
|
|
389
|
+
纪律:模块**不存在**可以跳过(可选模块);模块存在但**加载失败**必须抛错,
|
|
390
|
+
绝不能静默降级——否则实现没生效、检查却全绿(这种假绿已在本轮抓到多次)。 */
|
|
391
|
+
const BP_IMPL = (function loadBlueprintAtoms() {
|
|
392
|
+
const __fs = require('fs')
|
|
393
|
+
const __path = require('path')
|
|
394
|
+
const p = __path.join(__dirname, 'blueprint-atoms.cjs')
|
|
395
|
+
if (!__fs.existsSync(p)) return null // 未安装:允许
|
|
396
|
+
try {
|
|
397
|
+
return require(p) // 存在则必须能加载
|
|
398
|
+
} catch (e) {
|
|
399
|
+
throw new Error('[R141-BP-ATOMS] blueprint-atoms.cjs 存在但加载失败:' + e.message)
|
|
400
|
+
}
|
|
401
|
+
})()
|
|
402
|
+
if (BP_IMPL && BP_IMPL.IMPL && BP_IMPL.IMPL[atomId]) {
|
|
403
|
+
const impl = BP_IMPL.IMPL[atomId]
|
|
404
|
+
const fn = function (input) {
|
|
405
|
+
const r = impl(input)
|
|
406
|
+
if (r && r.output !== undefined) return r.output
|
|
407
|
+
return r
|
|
408
|
+
}
|
|
409
|
+
fn.id = atomId
|
|
410
|
+
fn.kind = 'blueprint'
|
|
411
|
+
fn.run = impl
|
|
412
|
+
return fn
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/* R141 第 10 批:第二批「原本判成需模型/需硬件、实际可确定性实现」的原子 */
|
|
416
|
+
const BP2_IMPL = (function loadBlueprintAtoms2() {
|
|
417
|
+
const __fs2 = require('fs')
|
|
418
|
+
const __path2 = require('path')
|
|
419
|
+
const p2 = __path2.join(__dirname, 'blueprint-atoms-2.cjs')
|
|
420
|
+
if (!__fs2.existsSync(p2)) return null
|
|
421
|
+
try { return require(p2) } catch (e) {
|
|
422
|
+
throw new Error('[R141-BP-ATOMS-2] blueprint-atoms-2.cjs 存在但加载失败:' + e.message)
|
|
423
|
+
}
|
|
424
|
+
})()
|
|
425
|
+
if (BP2_IMPL && BP2_IMPL.IMPL && BP2_IMPL.IMPL[atomId]) {
|
|
426
|
+
const impl2 = BP2_IMPL.IMPL[atomId]
|
|
427
|
+
const fn2 = function (input) {
|
|
428
|
+
const r = impl2(input)
|
|
429
|
+
if (r && r.output !== undefined) return r.output
|
|
430
|
+
return r
|
|
431
|
+
}
|
|
432
|
+
fn2.id = atomId
|
|
433
|
+
fn2.kind = 'blueprint2'
|
|
434
|
+
fn2.run = impl2
|
|
435
|
+
return fn2
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
if (CONSTRAINT_IDS.has(atomId)) return null; // 归约束器形态,非计算
|
|
439
|
+
if (EXTERNAL_NEEDED.has(atomId)) return null; // 需模型/外部服务,不假造实现
|
|
440
|
+
// 专用真实实现(曾被误判为需外部的原子)
|
|
441
|
+
if (SPECIAL_IMPL[atomId]) {
|
|
442
|
+
const fname = SPECIAL_IMPL[atomId];
|
|
443
|
+
// 先找 cosmicBio(引力波/分布式/跨物种),再找 cryptoEmotion
|
|
444
|
+
const cb = cosmicBio();
|
|
445
|
+
if (cb && typeof cb[fname] === "function") {
|
|
446
|
+
return function cosmicBioAtom(input) {
|
|
447
|
+
try {
|
|
448
|
+
const out = cb[fname](input);
|
|
449
|
+
if (out && typeof out === "object") return out;
|
|
450
|
+
return { ok: false, success: false, reason: "NON_OBJECT_OUTPUT" };
|
|
451
|
+
} catch (e) {
|
|
452
|
+
return { ok: false, success: false, reason: "EXEC_ERROR", message: String(e.message || e).slice(0, 120) };
|
|
453
|
+
}
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
const ce = cryptoEmotion();
|
|
457
|
+
if (ce && typeof ce[SPECIAL_IMPL[atomId]] === "function") {
|
|
458
|
+
const fname = SPECIAL_IMPL[atomId];
|
|
459
|
+
return function specialAtom(input) {
|
|
460
|
+
try {
|
|
461
|
+
const out = ce[fname](input);
|
|
462
|
+
if (out && typeof out === "object") { out.__operator = fname; return out; }
|
|
463
|
+
return { value: out, __operator: fname };
|
|
464
|
+
} catch (e) {
|
|
465
|
+
return { success: false, error: String(e.message).slice(0, 80), reason: "SPECIAL_FAILED" };
|
|
466
|
+
}
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
const c = (ALL_CONTRACTS && ALL_CONTRACTS[atomId]) || CONTRACTS[atomId];
|
|
472
|
+
if (!c) return null;
|
|
473
|
+
|
|
474
|
+
// 语义特化:按功能描述路由到专门算子(精度升级)
|
|
475
|
+
const sp = spec();
|
|
476
|
+
const meta = atomMeta(atomId);
|
|
477
|
+
const hit = sp ? sp.pick(meta.desc || "", meta.name || "", atomId) : null;
|
|
478
|
+
if (hit) {
|
|
479
|
+
// 特化算子结果 + 契约合规基线(两者合并:既要语义贴切,也要满足契约判据)
|
|
480
|
+
const baseGen = GEN[c.action] || GEN["—"];
|
|
481
|
+
return function specializedAtom(input) {
|
|
482
|
+
const v = vec(input);
|
|
483
|
+
if (!v.length) return { ok: false, reason: "NO_NUMERIC_INPUT" };
|
|
484
|
+
let base = {};
|
|
485
|
+
try { base = baseGen(v) || {}; } catch (e) { base = {}; }
|
|
486
|
+
const specOut = hit.fn(v) || {};
|
|
487
|
+
const merged = Object.assign({}, base, specOut);
|
|
488
|
+
merged.__operator = hit.op;
|
|
489
|
+
return merged;
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
// 二级路由:语义近似(需模型类任务的确定性近似,输出标注 approximated)
|
|
494
|
+
const ap = approx();
|
|
495
|
+
const ah = ap ? ap.pickApprox(meta.desc || "", meta.name || "") : null;
|
|
496
|
+
if (ah) {
|
|
497
|
+
const baseGen2 = GEN[c.action] || GEN["—"];
|
|
498
|
+
return function approximateAtom(input) {
|
|
499
|
+
let base = {};
|
|
500
|
+
try {
|
|
501
|
+
const v = vec(input);
|
|
502
|
+
base = v.length ? (baseGen2(v) || {}) : {};
|
|
503
|
+
} catch (e) { base = {}; }
|
|
504
|
+
let aout = {};
|
|
505
|
+
try { aout = ah.fn(input) || {}; } catch (e) { aout = {}; }
|
|
506
|
+
const merged = Object.assign({}, base, aout);
|
|
507
|
+
merged.__operator = ah.op;
|
|
508
|
+
merged.__mode = "approximate";
|
|
509
|
+
return merged;
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
const g = GEN[c.action] || GEN["—"];
|
|
514
|
+
return function genericContractAtom(input) {
|
|
515
|
+
const v = vec(input);
|
|
516
|
+
if (!v.length) return { ok: false, reason: "NO_NUMERIC_INPUT" };
|
|
517
|
+
return g(v);
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
module.exports = {
|
|
522
|
+
MODEL_NEEDED, make, GEN, CONTRACTS, vec, CONSTRAINT_IDS, EXTERNAL_NEEDED,
|
|
523
|
+
getAllContracts: () => ALL_CONTRACTS || CONTRACTS };
|
|
524
|
+
|
|
525
|
+
if (require.main === module) {
|
|
526
|
+
const { validate } = require("./contract-validator.cjs");
|
|
527
|
+
const SAMPLE = [0.8, 0.6, 0.75, 0.9, 0.55];
|
|
528
|
+
let pass = 0, fail = 0; const bad = [];
|
|
529
|
+
const ALL = (typeof ALL_CONTRACTS !== "undefined" && ALL_CONTRACTS) ? ALL_CONTRACTS : CONTRACTS;
|
|
530
|
+
Object.keys(ALL).forEach(id => {
|
|
531
|
+
if (CONSTRAINT_IDS.has(id)) return;
|
|
532
|
+
const fn = make(id);
|
|
533
|
+
if (!fn) return;
|
|
534
|
+
const out = fn(SAMPLE);
|
|
535
|
+
const v = validate(id, out);
|
|
536
|
+
if (v.pass) pass++; else { fail++; if (bad.length < 8) bad.push([id, v]); }
|
|
537
|
+
});
|
|
538
|
+
console.log("=".repeat(72));
|
|
539
|
+
console.log("契约驱动原子工厂自测");
|
|
540
|
+
console.log("=".repeat(72));
|
|
541
|
+
console.log("契约总数:", Object.keys(ALL).length, "(含蓝本原有契约)");
|
|
542
|
+
console.log("生成实现:", pass + fail, "| 符合契约:", pass, "| 不符合:", fail);
|
|
543
|
+
bad.forEach(([id, v]) => {
|
|
544
|
+
console.log(" FAIL " + id + " [" + v.action + "/" + v.domain + "]");
|
|
545
|
+
v.checks.filter(c => !c.ok).forEach(c => console.log(" - " + c.n + " " + c.d));
|
|
546
|
+
});
|
|
547
|
+
console.log('跳过(需模型/外部):', EXTERNAL_NEEDED.size, '| 跳过(约束器):', CONSTRAINT_IDS.size);
|
|
548
|
+
console.log(fail === 0 ? "总判定:PASS" : "总判定:FAIL");
|
|
549
|
+
process.exit(fail === 0 ? 0 : 1);
|
|
550
|
+
}
|