@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,368 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* P6-B6 · 主动族 / 前瞻族 / 全息族 / 事实族 协议运行时(17 条)
|
|
4
|
+
*/
|
|
5
|
+
'use strict';
|
|
6
|
+
|
|
7
|
+
let __seq = 0;
|
|
8
|
+
const newTraceId = () => {
|
|
9
|
+
const d = new Date(), p = (n, w = 2) => String(n).padStart(w, '0');
|
|
10
|
+
return `${d.getFullYear()}${p(d.getMonth() + 1)}${p(d.getDate())}-${p(d.getHours())}${p(d.getMinutes())}${p(d.getSeconds())}-S${p((++__seq) % 10000, 4)}`;
|
|
11
|
+
};
|
|
12
|
+
const clamp01 = (x) => Math.max(0, Math.min(1, Number(x) || 0));
|
|
13
|
+
const round = (x, n = 4) => Math.round((Number(x) || 0) * 10 ** n) / 10 ** n;
|
|
14
|
+
const has = (o, ks) => ks.filter((k) => o && o[k] !== undefined && o[k] !== null);
|
|
15
|
+
|
|
16
|
+
const P = [];
|
|
17
|
+
|
|
18
|
+
/* ══════ 主动族(7 条,依据 §五 协议清单的功能定义)══════ */
|
|
19
|
+
|
|
20
|
+
P.push({
|
|
21
|
+
id: 'PROTOCOL_ACTIVE_SENSE_V1', name: '主动感知协议', kind: 'rule', src: 'table-row 488 字符(§五 新增协议清单)',
|
|
22
|
+
implements: ['感知信号三要素(时间戳/类型/置信度)', '触发阈值判定', '感知频率动态调整'],
|
|
23
|
+
exec(inp, tid) {
|
|
24
|
+
const s = inp.signal || {};
|
|
25
|
+
const miss = has(s, ['timestamp', 'type', 'confidence']).length < 3 ? ['timestamp', 'type', 'confidence'].filter((k) => s[k] === undefined) : [];
|
|
26
|
+
const conf = Number(s.confidence ?? 0);
|
|
27
|
+
const thr = Number(inp.threshold ?? 0.7);
|
|
28
|
+
const freq = inp.stable ? 'LOW' : inp.anomaly ? 'HIGH' : 'NORMAL';
|
|
29
|
+
const ok = miss.length === 0 && conf >= thr;
|
|
30
|
+
return { success: ok, kind: 'rule', output: {
|
|
31
|
+
requiredFields: ['timestamp', 'type', 'confidence'], missing: miss,
|
|
32
|
+
confidence: conf, threshold: thr, triggered: conf >= thr,
|
|
33
|
+
senseFrequency: freq, rule: '稳定降频 / 异常提频',
|
|
34
|
+
},
|
|
35
|
+
error: miss.length ? `感知信号缺字段:${miss.join('/')}` : conf < thr ? `置信度 ${conf} < 阈值 ${thr},不触发` : undefined,
|
|
36
|
+
reason: ok ? undefined : 'RULE_VIOLATED',
|
|
37
|
+
provenance: [`[${tid}] active-sense: 置信 ${conf}/${thr} → ${conf >= thr ? '触发' : '不触发'},频率 ${freq}`] };
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
P.push({
|
|
42
|
+
id: 'PROTOCOL_ACTIVE_PUSH_V1', name: '主动推送协议', kind: 'rule', src: 'table-row 488 字符',
|
|
43
|
+
implements: ['推送三要素(消息体/优先级/重试策略)', '三级优先级', '指数退避重试'],
|
|
44
|
+
exec(inp, tid) {
|
|
45
|
+
const m = inp.message || {};
|
|
46
|
+
const miss = ['body', 'priority'].filter((k) => m[k] === undefined);
|
|
47
|
+
const PRIORITY = { urgent: 3, important: 2, normal: 1 };
|
|
48
|
+
const pri = String(m.priority || 'normal');
|
|
49
|
+
if (!PRIORITY[pri]) return { success: false, kind: 'rule', reason: 'INVALID_INPUT', error: `优先级须为 urgent/important/normal` };
|
|
50
|
+
const maxRetry = Number(inp.maxRetry ?? 3);
|
|
51
|
+
const backoff = Array.from({ length: maxRetry }, (_, i) => Math.round(1000 * 2 ** i));
|
|
52
|
+
const ok = miss.length === 0;
|
|
53
|
+
return { success: ok, kind: 'rule', output: {
|
|
54
|
+
requiredFields: ['body', 'priority', 'retryPolicy'], missing: miss,
|
|
55
|
+
priority: pri, priorityLevel: PRIORITY[pri],
|
|
56
|
+
retryPolicy: { maxRetry, backoffMs: backoff, strategy: '指数退避' },
|
|
57
|
+
},
|
|
58
|
+
error: miss.length ? `推送消息缺字段:${miss.join('/')}` : undefined,
|
|
59
|
+
reason: ok ? undefined : 'RULE_VIOLATED',
|
|
60
|
+
provenance: [`[${tid}] active-push: ${pri}(L${PRIORITY[pri]}) · 重试 ${maxRetry} 次`] };
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
P.push({
|
|
65
|
+
id: 'PROTOCOL_ACTIVE_FEEDBACK_V1', name: '主动反馈协议', kind: 'rule', src: 'table-row 488 字符',
|
|
66
|
+
implements: ['反馈采集四要素(用户/时间/类型/内容)', '传输规范校验'],
|
|
67
|
+
exec(inp, tid) {
|
|
68
|
+
const f = inp.feedback || {};
|
|
69
|
+
const need = ['userId', 'timestamp', 'type', 'content'];
|
|
70
|
+
const miss = need.filter((k) => f[k] === undefined);
|
|
71
|
+
const ok = miss.length === 0;
|
|
72
|
+
return { success: ok, kind: 'rule', output: { requiredFields: need, missing: miss, feedbackType: f.type || null, collected: ok },
|
|
73
|
+
error: ok ? undefined : `反馈缺字段:${miss.join('/')}`,
|
|
74
|
+
reason: ok ? undefined : 'RULE_VIOLATED',
|
|
75
|
+
provenance: [`[${tid}] active-feedback: ${ok ? '采集完整' : '缺 ' + miss.join('/')}`] };
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
P.push({
|
|
80
|
+
id: 'PROTOCOL_ASYNC_DIALOG_V1', name: '异步对话协议', kind: 'pipeline', src: 'table-row 488 字符',
|
|
81
|
+
implements: ['异步消息状态机(pending→sent→acked→failed)', '合法状态转移校验'],
|
|
82
|
+
exec(inp, tid) {
|
|
83
|
+
const STATES = ['pending', 'sent', 'acked', 'failed'];
|
|
84
|
+
const TRANS = { pending: ['sent', 'failed'], sent: ['acked', 'failed'], acked: [], failed: ['pending'] };
|
|
85
|
+
const from = String(inp.from || 'pending'), to = String(inp.to || 'sent');
|
|
86
|
+
if (!STATES.includes(from) || !STATES.includes(to)) return { success: false, kind: 'pipeline', reason: 'INVALID_INPUT', error: `状态须为 ${STATES.join('/')}` };
|
|
87
|
+
const ok = (TRANS[from] || []).includes(to);
|
|
88
|
+
return { success: ok, kind: 'pipeline', output: { states: STATES, transitions: TRANS, from, to, allowed: ok, allowedNext: TRANS[from] },
|
|
89
|
+
error: ok ? undefined : `非法状态转移 ${from} → ${to}`,
|
|
90
|
+
reason: ok ? undefined : 'PRECONDITION_FAILED',
|
|
91
|
+
provenance: [`[${tid}] async-dialog: ${from} → ${to} ${ok ? '合法' : '非法'}`] };
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
P.push({
|
|
96
|
+
id: 'PROTOCOL_ACTIVE_GOLDEN_V1', name: '黄金窗口协议', kind: 'compute', src: 'table-row 488 字符',
|
|
97
|
+
implements: ['黄金窗口判定(活跃度 × 意愿度 ≥ 阈值)', '窗口时长与置信度'],
|
|
98
|
+
exec(inp, tid) {
|
|
99
|
+
const act = clamp01(inp.activity ?? 0.7), will = clamp01(inp.willingness ?? 0.7);
|
|
100
|
+
const thr = Number(inp.threshold ?? 0.5);
|
|
101
|
+
const score = round(act * will);
|
|
102
|
+
const isGolden = score >= thr;
|
|
103
|
+
return { success: true, kind: 'compute', output: { activity: act, willingness: will, score, threshold: thr, isGoldenWindow: isGolden,
|
|
104
|
+
suggestedWindowMinutes: isGolden ? Math.round(10 + (1 - score) * 20) : 0, rule: '黄金窗口 = 活跃度 × 意愿度 ≥ 阈值' },
|
|
105
|
+
provenance: [`[${tid}] active-golden: ${act}×${will}=${score} → ${isGolden ? '黄金窗口' : '非窗口'}`] };
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
P.push({
|
|
110
|
+
id: 'PROTOCOL_ACTIVE_EMOTION_V1', name: '情感曲线协议', kind: 'compute', src: 'table-row 488 字符',
|
|
111
|
+
implements: ['情感曲线指标(均值/波动/趋势)', '适配强度计算'],
|
|
112
|
+
exec(inp, tid) {
|
|
113
|
+
const curve = inp.emotionCurve;
|
|
114
|
+
if (!Array.isArray(curve) || !curve.length) return { success: false, kind: 'compute', reason: 'INVALID_INPUT', error: '必须提供 emotionCurve 数组' };
|
|
115
|
+
const v = curve.map(Number);
|
|
116
|
+
const mean = round(v.reduce((a, b) => a + b, 0) / v.length);
|
|
117
|
+
const volatility = round(Math.sqrt(v.reduce((s, x) => s + (x - mean) ** 2, 0) / v.length));
|
|
118
|
+
const trend = v.length > 1 ? round(v[v.length - 1] - v[0]) : 0;
|
|
119
|
+
const adaptStrength = round(clamp01(Math.abs(trend) * 0.6 + volatility * 0.4));
|
|
120
|
+
return { success: true, kind: 'compute', output: { points: v.length, mean, volatility, trend, adaptStrength,
|
|
121
|
+
adaptation: trend > 0.1 ? '提升互动强度' : trend < -0.1 ? '降低互动强度并安抚' : '维持当前强度' },
|
|
122
|
+
provenance: [`[${tid}] active-emotion: mean ${mean} vol ${volatility} trend ${trend} → 适配 ${adaptStrength}`] };
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
P.push({
|
|
127
|
+
id: 'PROTOCOL_ACTIVE_ENTANGLE_V1', name: '量子纠缠协议', kind: 'compute', src: 'table-row 488 字符',
|
|
128
|
+
implements: ['纠缠对匹配度(余弦相似)', '建立/维护判定'],
|
|
129
|
+
exec(inp, tid) {
|
|
130
|
+
const a = inp.stateA, b = inp.stateB;
|
|
131
|
+
if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) return { success: false, kind: 'compute', reason: 'INVALID_INPUT', error: 'stateA/stateB 须为同维数组' };
|
|
132
|
+
const dot = a.reduce((s, x, i) => s + x * b[i], 0);
|
|
133
|
+
const na = Math.sqrt(a.reduce((s, x) => s + x * x, 0)), nb = Math.sqrt(b.reduce((s, x) => s + x * x, 0));
|
|
134
|
+
const match = round(na && nb ? dot / (na * nb) : 0);
|
|
135
|
+
const thr = Number(inp.threshold ?? 0.8);
|
|
136
|
+
return { success: true, kind: 'compute', output: { dims: a.length, match, threshold: thr, entangled: match >= thr,
|
|
137
|
+
maintenance: match >= thr ? '维持纠缠:定期重同步' : '不建立:匹配度不足',
|
|
138
|
+
rule: '纠缠建立判据 = 状态向量余弦相似度 ≥ 阈值' },
|
|
139
|
+
provenance: [`[${tid}] active-entangle: 匹配 ${match}/${thr} → ${match >= thr ? '已纠缠' : '未纠缠'}`] };
|
|
140
|
+
},
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
/* ══════ 前瞻族(4 条,核心条款完整)══════ */
|
|
144
|
+
|
|
145
|
+
P.push({
|
|
146
|
+
id: 'PROTOCOL_PROACTIVE_SENSE_V1', name: '主动感知协议(前瞻)', kind: 'rule', src: 'yaml-block 274 字符',
|
|
147
|
+
implements: ['信号三要素 + 三级优先级(紧急/重要/常规)', '隐私保护(原始数据本地、仅传脱敏事件)', '频率动态调整'],
|
|
148
|
+
exec(inp, tid) {
|
|
149
|
+
const s = inp.signal || {};
|
|
150
|
+
const miss = ['timestamp', 'type', 'confidence'].filter((k) => s[k] === undefined);
|
|
151
|
+
const LV = { 紧急: 'IMMEDIATE', 重要: 'NEXT_CYCLE', 常规: 'ASYNC' };
|
|
152
|
+
const lv = String(s.priority || '常规');
|
|
153
|
+
if (!LV[lv]) return { success: false, kind: 'rule', reason: 'INVALID_INPUT', error: '优先级须为 紧急/重要/常规' };
|
|
154
|
+
const privacy = inp.rawLocalOnly !== false;
|
|
155
|
+
const ok = miss.length === 0 && privacy;
|
|
156
|
+
return { success: ok, kind: 'rule', output: {
|
|
157
|
+
requiredFields: ['timestamp', 'type', 'confidence'], missing: miss,
|
|
158
|
+
priority: lv, handling: LV[lv], level3: Object.keys(LV),
|
|
159
|
+
privacy: { rawLocalOnly: privacy, uploads: '仅脱敏状态事件' },
|
|
160
|
+
frequency: inp.stable ? 'LOW' : inp.anomaly ? 'HIGH' : 'NORMAL',
|
|
161
|
+
valueAlignFilterRequired: true,
|
|
162
|
+
},
|
|
163
|
+
error: miss.length ? `信号缺字段:${miss.join('/')}` : !privacy ? '违反隐私保护:原始感知数据不得上传' : undefined,
|
|
164
|
+
reason: ok ? undefined : 'RULE_VIOLATED',
|
|
165
|
+
provenance: [`[${tid}] proactive-sense: ${lv}→${LV[lv]},隐私 ${privacy ? '合规' : '违规'}`] };
|
|
166
|
+
},
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
P.push({
|
|
170
|
+
id: 'PROTOCOL_PROACTIVE_THINK_V1', name: '主动思考协议', kind: 'pipeline', src: 'yaml-block 232 字符',
|
|
171
|
+
implements: ['推理链必录', '新想法置信度+创新度双标注', '价值对齐前置'],
|
|
172
|
+
exec(inp, tid) {
|
|
173
|
+
const need = ['trigger', 'reasoningChain', 'output'];
|
|
174
|
+
const miss = need.filter((k) => inp && inp[k] === undefined);
|
|
175
|
+
const ideas = inp.ideas || [];
|
|
176
|
+
const badIdeas = ideas.filter((i) => i.confidence === undefined || i.novelty === undefined);
|
|
177
|
+
const alignPassed = inp.valueAligned === true;
|
|
178
|
+
const ok = miss.length === 0 && badIdeas.length === 0 && alignPassed;
|
|
179
|
+
return { success: ok, kind: 'pipeline', output: {
|
|
180
|
+
requiredFields: need, missing: miss,
|
|
181
|
+
reasoningChainLinks: Array.isArray(inp.reasoningChain) ? inp.reasoningChain.length : 0,
|
|
182
|
+
ideas: ideas.length, ideasMissingMeta: badIdeas.length,
|
|
183
|
+
valueAligned: alignPassed, rule: '新想法须标注置信度+创新度;输出前经价值对齐',
|
|
184
|
+
},
|
|
185
|
+
error: miss.length ? `思考缺字段:${miss.join('/')}` : badIdeas.length ? `${badIdeas.length} 个想法缺置信度/创新度标注` : !alignPassed ? '未经价值对齐引擎评估,不得输出' : undefined,
|
|
186
|
+
reason: ok ? undefined : 'PRECONDITION_FAILED',
|
|
187
|
+
provenance: [`[${tid}] proactive-think: 推理链 ${Array.isArray(inp.reasoningChain) ? inp.reasoningChain.length : 0} 环,想法 ${ideas.length} 个`] };
|
|
188
|
+
},
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
P.push({
|
|
192
|
+
id: 'PROTOCOL_PROACTIVE_LEARN_V1', name: '主动学习协议', kind: 'rule', src: 'yaml-block 235 字符',
|
|
193
|
+
implements: ['学习目标三要素(优先级/预期价值/时间窗口)', '可证伪实验设计', '过度打扰防护'],
|
|
194
|
+
exec(inp, tid) {
|
|
195
|
+
const g = inp.goal || {};
|
|
196
|
+
const miss = ['priority', 'expectedValue', 'timeWindow'].filter((k) => g[k] === undefined);
|
|
197
|
+
const falsifiable = inp.hypothesis && inp.hypothesis.falsifiable === true;
|
|
198
|
+
const accept = clamp01(inp.userAcceptance ?? 0.7);
|
|
199
|
+
const thr = Number(inp.acceptanceThreshold ?? 0.5);
|
|
200
|
+
const ok = miss.length === 0 && falsifiable && accept >= thr;
|
|
201
|
+
return { success: ok, kind: 'rule', output: {
|
|
202
|
+
requiredFields: ['priority', 'expectedValue', 'timeWindow'], missing: miss,
|
|
203
|
+
hypothesisFalsifiable: !!falsifiable, userAcceptance: accept, acceptanceThreshold: thr,
|
|
204
|
+
askAllowed: accept >= thr, rule: '主动提问须评估接受度;假设须可证伪;成果入知识库并通知相关引擎',
|
|
205
|
+
},
|
|
206
|
+
error: miss.length ? `学习目标缺:${miss.join('/')}` : !falsifiable ? '假设未设计为可证伪实验' : accept < thr ? `用户接受度 ${accept} < ${thr},暂不主动提问` : undefined,
|
|
207
|
+
reason: ok ? undefined : 'RULE_VIOLATED',
|
|
208
|
+
provenance: [`[${tid}] proactive-learn: 目标 ${3 - miss.length}/3,可证伪 ${falsifiable},接受度 ${accept}`] };
|
|
209
|
+
},
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
P.push({
|
|
213
|
+
id: 'PROTOCOL_PROACTIVE_LEAD_V1', name: '主动引领协议', kind: 'rule', src: 'yaml-block 252 字符',
|
|
214
|
+
implements: ['接受度门槛', '四策略库(提问/建议/挑战/启发)', '同话题连续 ≤3 次', '价值对齐合规'],
|
|
215
|
+
exec(inp, tid) {
|
|
216
|
+
const STRATS = ['提问式', '建议式', '挑战式', '启发式'];
|
|
217
|
+
const st = String(inp.strategy || '建议式');
|
|
218
|
+
if (!STRATS.includes(st)) return { success: false, kind: 'rule', reason: 'INVALID_INPUT', error: `策略须为 ${STRATS.join('/')}` };
|
|
219
|
+
const accept = clamp01(inp.userAcceptance ?? 0.7), thr = Number(inp.acceptanceThreshold ?? 0.5);
|
|
220
|
+
const consecutive = Number(inp.sameTopicConsecutive ?? 1);
|
|
221
|
+
const alignOk = inp.valueAligned !== false;
|
|
222
|
+
const ok = accept >= thr && consecutive <= 3 && alignOk;
|
|
223
|
+
return { success: ok, kind: 'rule', output: {
|
|
224
|
+
strategy: st, strategyLibrary: STRATS, userAcceptance: accept, threshold: thr,
|
|
225
|
+
sameTopicConsecutive: consecutive, maxConsecutive: 3, valueAligned: alignOk,
|
|
226
|
+
action: ok ? 'LEAD' : 'DELAY', rule: '接受度低于阈值则延迟;同话题≤3次;须过价值对齐',
|
|
227
|
+
},
|
|
228
|
+
error: !alignOk ? '引领内容未通过价值对齐合规评估' : accept < thr ? `接受度 ${accept} < ${thr},延迟引领` : consecutive > 3 ? `同话题连续 ${consecutive} 次 > 3,需给用户消化时间` : undefined,
|
|
229
|
+
reason: ok ? undefined : 'RULE_VIOLATED',
|
|
230
|
+
provenance: [`[${tid}] proactive-lead: ${st} 接受度 ${accept} 连续 ${consecutive} → ${ok ? '引领' : '延迟'}`] };
|
|
231
|
+
},
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
/* ══════ 事实陈述协议 ══════ */
|
|
235
|
+
P.push({
|
|
236
|
+
id: 'PROTOCOL_FSP_V1_0', name: '事实陈述协议', kind: 'rule', src: 'yaml-block 1368 字符',
|
|
237
|
+
implements: ['五级事实分级(✅已确认/🔄意向中/👀待接触/📊调研发现/待核实)', '置信度区间校验', '低置信不得写入正式方案'],
|
|
238
|
+
exec(inp, tid) {
|
|
239
|
+
const claims = inp.claims;
|
|
240
|
+
if (!Array.isArray(claims) || !claims.length) return { success: false, kind: 'rule', reason: 'INVALID_INPUT', error: '必须提供 claims 数组' };
|
|
241
|
+
const TIERS = [
|
|
242
|
+
{ label: '✅ 已确认', min: 0.9, max: 1.0 },
|
|
243
|
+
{ label: '🔄 意向中', min: 0.7, max: 0.89 },
|
|
244
|
+
{ label: '👀 待接触', min: 0.5, max: 0.69 },
|
|
245
|
+
{ label: '📊 调研发现', min: 0, max: 0.49 },
|
|
246
|
+
{ label: '待核实', min: 0, max: 0.49, forbiddenInFormal: true },
|
|
247
|
+
];
|
|
248
|
+
const checked = claims.map((c, i) => {
|
|
249
|
+
const conf = Number(c.confidence ?? 0);
|
|
250
|
+
const match = c.label ? TIERS.find((t) => t.label === c.label) : TIERS.find((t) => conf >= t.min && conf <= t.max);
|
|
251
|
+
const labelOk = !!match;
|
|
252
|
+
const formalBlocked = !!(c.formal && match && match.forbiddenInFormal);
|
|
253
|
+
return { index: i, claim: c.claim, confidence: conf, declaredLabel: c.label, expectedLabel: match ? match.label : null, labelOk, formalBlocked, ok: labelOk && !formalBlocked };
|
|
254
|
+
});
|
|
255
|
+
const bad = checked.filter((c) => !c.ok);
|
|
256
|
+
const ok = bad.length === 0;
|
|
257
|
+
return { success: ok, kind: 'rule', output: { tierTable: TIERS.map(({ label, min, max }) => ({ label, range: [min, max] })), total: claims.length, checked, failed: bad.length },
|
|
258
|
+
error: ok ? undefined : `${bad.length} 条事实分级不符或低置信写入正式方案`,
|
|
259
|
+
reason: ok ? undefined : 'RULE_VIOLATED',
|
|
260
|
+
provenance: [`[${tid}] fsp: ${claims.length} 条声明,${bad.length} 条不符分级`] };
|
|
261
|
+
},
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
/* ══════ 全息族 3 条 ══════ */
|
|
265
|
+
P.push({
|
|
266
|
+
id: 'PROTOCOL_HWP_V1_0', name: '全息工作协议', kind: 'pipeline', src: 'yaml-block 1463 字符',
|
|
267
|
+
implements: ['任务理解 + 历史关联 + 全息扫描 + 缺口处理 四章必备项', '一次性交付完整价值'],
|
|
268
|
+
exec(inp, tid) {
|
|
269
|
+
const need = ['taskUnderstanding', 'historyLinked', 'holoScan', 'gapHandled'];
|
|
270
|
+
const steps = need.map((k, i) => ({ chapter: i + 1, key: k, present: !!(inp && inp[k] !== undefined) }));
|
|
271
|
+
const miss = steps.filter((s) => !s.present).map((s) => s.key);
|
|
272
|
+
const ok = miss.length === 0;
|
|
273
|
+
return { success: ok, kind: 'pipeline', steps, output: {
|
|
274
|
+
chapters: ['任务理解', '历史关联', '全息扫描', '缺口处理'], steps, missing: miss,
|
|
275
|
+
rule: '一次性交付完整价值;杜绝碎片化输出/被动应答/信息遗漏',
|
|
276
|
+
},
|
|
277
|
+
error: ok ? undefined : '全息工作必备项缺失:' + miss.join('/'),
|
|
278
|
+
reason: ok ? undefined : 'PRECONDITION_FAILED',
|
|
279
|
+
provenance: [`[${tid}] hwp: ${4 - miss.length}/4 章齐备`] };
|
|
280
|
+
},
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
P.push({
|
|
284
|
+
id: 'PROTOCOL_HKS_V1_0', name: '全息知识扫描协议', kind: 'pipeline', src: 'yaml-block 1262 字符',
|
|
285
|
+
implements: ['扫描维度覆盖校验', '三源扫描(联网/历史/内部知识库)', '缺口标注'],
|
|
286
|
+
exec(inp, tid) {
|
|
287
|
+
const dims = inp.dimensions || [], covered = inp.covered || [];
|
|
288
|
+
const SOURCES = ['web', 'history', 'internal'];
|
|
289
|
+
const srcHit = SOURCES.filter((s) => (inp.sources || []).includes(s));
|
|
290
|
+
const gaps = dims.filter((d) => !covered.includes(d));
|
|
291
|
+
const ok = dims.length > 0 && gaps.length === 0;
|
|
292
|
+
return { success: ok, kind: 'pipeline', output: {
|
|
293
|
+
dimensions: dims.length, covered: covered.length, gaps,
|
|
294
|
+
sourcesRequired: SOURCES, sourcesUsed: srcHit, sourceCoverage: round(srcHit.length / 3),
|
|
295
|
+
rule: '必须覆盖所有生成维度;三源扫描;缺口须标注',
|
|
296
|
+
},
|
|
297
|
+
error: !dims.length ? '未生成扫描维度' : gaps.length ? `${gaps.length} 个维度未覆盖:${gaps.slice(0, 3).join(',')}` : undefined,
|
|
298
|
+
reason: ok ? undefined : 'PRECONDITION_FAILED',
|
|
299
|
+
provenance: [`[${tid}] hks: 维度 ${covered.length}/${dims.length},源 ${srcHit.length}/3`] };
|
|
300
|
+
},
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
P.push({
|
|
304
|
+
id: 'PROTOCOL_HMFP_V1_0', name: '全息模式强制协议', kind: 'rule', src: 'yaml-block 1002 字符',
|
|
305
|
+
implements: ['全息模式必检项(维度覆盖/事实核查/内容展开/增值交付/场景适配)', '任一缺失即非全息'],
|
|
306
|
+
exec(inp, tid) {
|
|
307
|
+
const need = ['dimensionCoverage', 'factCheck', 'contentDepth', 'valueAdd', 'sceneFit'];
|
|
308
|
+
const checks = need.map((k) => ({ key: k, present: inp && inp[k] !== undefined, ok: inp && inp[k] === true }));
|
|
309
|
+
const miss = checks.filter((c) => !c.present).map((c) => c.key);
|
|
310
|
+
const failed = checks.filter((c) => c.present && !c.ok).map((c) => c.key);
|
|
311
|
+
const ok = miss.length === 0 && failed.length === 0;
|
|
312
|
+
return { success: ok, kind: 'rule', output: { requiredChecks: need, checks, missing: miss, failed, holoMode: ok },
|
|
313
|
+
error: ok ? undefined : `非全息:缺 ${miss.join('/') || '无'};未过 ${failed.join('/') || '无'}`,
|
|
314
|
+
reason: ok ? undefined : 'RULE_VIOLATED',
|
|
315
|
+
provenance: [`[${tid}] hmfp: ${checks.filter((c) => c.ok).length}/5 全息必检项通过`] };
|
|
316
|
+
},
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
/* ══════ 场景表达适配协议 ══════ */
|
|
320
|
+
P.push({
|
|
321
|
+
id: 'PROTOCOL_SEP_V1_0', name: '场景表达适配协议', kind: 'rule', src: 'yaml-block 1042 字符',
|
|
322
|
+
implements: ['五场景识别', '商业场景禁用技术术语检查', '术语替换映射'],
|
|
323
|
+
exec(inp, tid) {
|
|
324
|
+
const SCENES = ['business', 'technical', 'strategic', 'daily', 'internal'];
|
|
325
|
+
const scene = String(inp.scene || 'technical');
|
|
326
|
+
if (!SCENES.includes(scene)) return { success: false, kind: 'rule', reason: 'INVALID_INPUT', error: `场景须为 ${SCENES.join('/')}` };
|
|
327
|
+
const text = String(inp.text || '');
|
|
328
|
+
const TECH_TERMS = ['耦生度', '负熵', '公理', '原子', '元进化', '全息重构', '熵增', '范式'];
|
|
329
|
+
const hits = scene === 'business' ? TECH_TERMS.filter((t) => text.includes(t)) : [];
|
|
330
|
+
const ok = hits.length === 0;
|
|
331
|
+
return { success: ok, kind: 'rule', output: { scene, sceneWhitelist: SCENES, forbiddenTerms: scene === 'business' ? TECH_TERMS : [], hits, termReplaced: 0 },
|
|
332
|
+
error: ok ? undefined : `商业场景禁用技术术语 ${hits.length} 处:${hits.join('、')}`,
|
|
333
|
+
reason: ok ? undefined : 'RULE_VIOLATED',
|
|
334
|
+
provenance: [`[${tid}] sep: 场景 ${scene},术语命中 ${hits.length}`] };
|
|
335
|
+
},
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
/* ══════ 开发者纠错协议 ══════ */
|
|
339
|
+
P.push({
|
|
340
|
+
id: 'PROTOCOL_DCP_V1_0', name: '开发者纠错协议', kind: 'pipeline', src: 'yaml-block 723 字符',
|
|
341
|
+
implements: ['纠错五步(打断→承认→定向扫描→根因→固化)', '不辩解'],
|
|
342
|
+
exec(inp, tid) {
|
|
343
|
+
const need = ['interrupted', 'admitted', 'targetedScan', 'rootCause', 'hardened'];
|
|
344
|
+
const steps = need.map((k, i) => ({ step: i + 1, key: k, present: !!(inp && inp[k]) }));
|
|
345
|
+
const miss = steps.filter((s) => !s.present).map((s) => s.key);
|
|
346
|
+
const excuse = /但是|不过|其实我|您可能误会|这不是我的问题/.test(String(inp.response || ''));
|
|
347
|
+
const ok = miss.length === 0 && !excuse;
|
|
348
|
+
return { success: ok, kind: 'pipeline', steps, output: { fiveSteps: ['打断当前流程', '承认可能遗漏', '定向追踪扫描', '分析根因', '改正并固化'], steps, missing: miss, defensiveLanguage: excuse },
|
|
349
|
+
error: ok ? undefined : excuse ? '检出辩解性表述(但是/可能误会/不是我的问题)' : '纠错五步缺失:' + miss.join('/'),
|
|
350
|
+
reason: ok ? undefined : 'RULE_VIOLATED',
|
|
351
|
+
provenance: [`[${tid}] dcp: ${5 - miss.length}/5 步,辩解 ${excuse}`] };
|
|
352
|
+
},
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
const INDEX = new Map(P.map((p) => [p.id, p]));
|
|
356
|
+
const kindOf = (id) => { const p = INDEX.get(id); return p ? p.kind : 'declared'; };
|
|
357
|
+
const getRegistry = () => P.map((p) => ({ id: p.id, name: p.name, kind: p.kind, src: p.src, implements: p.implements }));
|
|
358
|
+
|
|
359
|
+
function executeSync(id, input) {
|
|
360
|
+
const t0 = Date.now(), tid = newTraceId();
|
|
361
|
+
const p = INDEX.get(id);
|
|
362
|
+
if (!p) return { success: false, kind: 'declared', reason: 'NOT_FOUND', error: `协议 ${id} 未登记`, provenance: [], traceId: tid, durationMs: 0 };
|
|
363
|
+
let r;
|
|
364
|
+
try { r = p.exec(input || {}, tid); } catch (e) { r = { success: false, kind: p.kind, error: 'THROW: ' + e.message, provenance: [`[${tid}] THROW`] }; }
|
|
365
|
+
return { ...r, protocolId: id, protocolName: p.name, traceId: tid, durationMs: Date.now() - t0 };
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
module.exports = { executeSync, execute: async (i, n) => executeSync(i, n), kindOf, getRegistry, PROTOCOLS: P, INDEX, newTraceId };
|