flow-comet 1.6.3 → 1.6.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/.flow-comet/skills/flow-comet/INSTALLED_VERSION +1 -1
- package/.flow-comet/skills/flow-comet/scripts/comet-hook-guard.mjs +11 -13
- package/.flow-comet/skills/flow-comet/scripts/context-init.mjs +2 -2
- package/.flow-comet/skills/flow-comet/scripts/evolve.mjs +6 -6
- package/.flow-comet/skills/flow-comet/scripts/guard-self-test.mjs +67 -18878
- package/.flow-comet/skills/flow-comet/scripts/health.mjs +1 -1
- package/.flow-comet/skills/flow-comet/scripts/items/a.mjs +1030 -0
- package/.flow-comet/skills/flow-comet/scripts/items/b.mjs +830 -0
- package/.flow-comet/skills/flow-comet/scripts/items/c.mjs +781 -0
- package/.flow-comet/skills/flow-comet/scripts/items/d.mjs +99 -0
- package/.flow-comet/skills/flow-comet/scripts/items/e.mjs +185 -0
- package/.flow-comet/skills/flow-comet/scripts/items/f.mjs +90 -0
- package/.flow-comet/skills/flow-comet/scripts/items/g.mjs +59 -0
- package/.flow-comet/skills/flow-comet/scripts/items/h.mjs +815 -0
- package/.flow-comet/skills/flow-comet/scripts/items/i.mjs +77 -0
- package/.flow-comet/skills/flow-comet/scripts/items/j.mjs +75 -0
- package/.flow-comet/skills/flow-comet/scripts/items/k.mjs +1427 -0
- package/.flow-comet/skills/flow-comet/scripts/items/l.mjs +275 -0
- package/.flow-comet/skills/flow-comet/scripts/items/m.mjs +614 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/count-derivation.mjs +97 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/fix-loop-node.mjs +196 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-evidence-gates.mjs +553 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-gates.mjs +837 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-routing.mjs +404 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-state-io.mjs +404 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-template-fidelity.mjs +302 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-uidesign.mjs +133 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/reentry-node.mjs +237 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/replan-node.mjs +209 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-branch.mjs +49 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-bridgecheck.mjs +201 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-commands-admin.mjs +141 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-commands-flow.mjs +700 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-commands-recovery.mjs +578 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-determine.mjs +52 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-evolve-hint.mjs +55 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-explain.mjs +106 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-intelscan.mjs +58 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-io.mjs +147 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-skillmarkers.mjs +189 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/system-fixtures.mjs +1441 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/task-graph.mjs +471 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/test-assertions.mjs +509 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/test-fixtures.mjs +1228 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/test-helpers.mjs +237 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/text-anchor-checks.mjs +2484 -0
- package/.flow-comet/skills/flow-comet/scripts/protocol-utils.mjs +2 -2
- package/.flow-comet/skills/flow-comet/scripts/route-node.mjs +72 -1123
- package/.flow-comet/skills/flow-comet/scripts/scenarios/a.mjs +966 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/b.mjs +1233 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/c.mjs +1382 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/d.mjs +483 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/e.mjs +1388 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/f.mjs +1466 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/g.mjs +1364 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/h.mjs +1287 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/i.mjs +1436 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/j.mjs +1384 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/k.mjs +1338 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/l.mjs +1484 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/m.mjs +971 -0
- package/.flow-comet/skills/flow-comet/scripts/state-schema.mjs +1 -1
- package/.flow-comet/skills/flow-comet/scripts/system-test.mjs +58 -7559
- package/.flow-comet/skills/flow-comet/scripts/time-utils.mjs +4 -4
- package/.flow-comet/skills/flow-comet/scripts/workflow-guard.mjs +151 -2476
- package/.flow-comet/skills/flow-comet/scripts/workflow-handoff.mjs +5 -5
- package/.flow-comet/skills/flow-comet/scripts/workflow-state.mjs +27 -2190
- package/.flow-comet/skills/flow-comet-plan/GUIDANCE.md +1 -1
- package/README.md +52 -69
- package/package.json +3 -2
- package/scripts/dsh-bridge.mjs +2 -2
- package/scripts/lib/installer-cleanup.mjs +152 -0
- package/scripts/lib/installer-flowkit.mjs +119 -0
- package/scripts/lib/installer-hooks.mjs +363 -0
- package/scripts/lib/installer-loader.mjs +220 -0
- package/scripts/lib/installer-migrate.mjs +236 -0
- package/scripts/lib/installer-platforms.mjs +314 -0
- package/scripts/prepare-env.mjs +21 -1313
|
@@ -0,0 +1,509 @@
|
|
|
1
|
+
// test-assertions.mjs — 引擎套件的断言助手与受控链路夹具(单一来源)
|
|
2
|
+
//
|
|
3
|
+
// 定位:`guard-self-test.mjs` 的断言与「修复回路 / 受控重入 / 计划重校」三条受控链路的夹具
|
|
4
|
+
// 材料。`outputText`(spawn 结果的输出归一)在此单源导出:断言与文本锚判据共用同一归一
|
|
5
|
+
// 表达,消费方一律从本模块 import,不再各写一份。
|
|
6
|
+
|
|
7
|
+
import fs from 'fs';
|
|
8
|
+
import path from 'path';
|
|
9
|
+
import { isDeepStrictEqual } from 'util';
|
|
10
|
+
import {
|
|
11
|
+
assertExit,
|
|
12
|
+
assertOut,
|
|
13
|
+
runGuard,
|
|
14
|
+
runState,
|
|
15
|
+
writeFile,
|
|
16
|
+
} from './test-helpers.mjs';
|
|
17
|
+
import {
|
|
18
|
+
CHANGE_ID,
|
|
19
|
+
handoffFor,
|
|
20
|
+
routeNodeModule,
|
|
21
|
+
runBridgeCheckFromCopy,
|
|
22
|
+
strictSummary,
|
|
23
|
+
writeInstalledCopyBridgeFixture,
|
|
24
|
+
} from './test-fixtures.mjs';
|
|
25
|
+
|
|
26
|
+
// 输出字符串归一化:spawnSync 原始结果的 .output 恒为数组 [null, stdout, stderr]
|
|
27
|
+
// (.includes 逐元素比较永不中关键字);run* 助手已归一化为字符串。两种形态都归一后再
|
|
28
|
+
// 断言,保证共享助手对「数组(stdout+stderr 拼接)」与「既有字符串」形态都成立(回归兼容)。
|
|
29
|
+
export function outputText(res) {
|
|
30
|
+
return Array.isArray(res?.output)
|
|
31
|
+
? String(res.stdout || '') + String(res.stderr || '')
|
|
32
|
+
: String(res?.output || '');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// result 重验撤销审计断言(共享单一来源):撤销后 request evidence 必须 noCommit=false,
|
|
36
|
+
// 且含非空、可被 Date 解析的 revokedAt 与失败类别对应的 revokeReason(缺任一即审计缺口)。
|
|
37
|
+
export function assertRevocationAudit(req, expectedReason, label) {
|
|
38
|
+
if (!req || req.noCommit !== false) {
|
|
39
|
+
throw new Error(label + ':撤销后 request evidence 应为 noCommit=false,实际 ' + JSON.stringify(req));
|
|
40
|
+
}
|
|
41
|
+
if (typeof req.revokedAt !== 'string' || req.revokedAt.trim() === '' || Number.isNaN(Date.parse(req.revokedAt))) {
|
|
42
|
+
throw new Error(label + ':撤销应记录非空且可被 Date 解析的 revokedAt,实际 ' + JSON.stringify(req.revokedAt));
|
|
43
|
+
}
|
|
44
|
+
if (req.revokeReason !== expectedReason) {
|
|
45
|
+
throw new Error(label + ':撤销应记录 revokeReason=' + expectedReason + ',实际 ' + JSON.stringify(req.revokeReason));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// state 不变量断言(m-09 / AC-4 / AC-12):白名单外深比 + history 旧前缀稳定 + 恰新增一条
|
|
50
|
+
// exit-applied 事件。白名单为点分路径(如 'currentNode' / 'evidence.execute.completedChecks')。
|
|
51
|
+
// 判别力:实现若顺手写白名单外字段、重写 history 旧条目、多推/漏推出口事件即抛错。
|
|
52
|
+
export function omitStatePath(root, dottedPath) {
|
|
53
|
+
const parts = String(dottedPath).split('.');
|
|
54
|
+
let cursor = root;
|
|
55
|
+
for (let i = 0; i < parts.length - 1; i += 1) {
|
|
56
|
+
if (!cursor || typeof cursor !== 'object') return;
|
|
57
|
+
cursor = cursor[parts[i]];
|
|
58
|
+
}
|
|
59
|
+
if (cursor && typeof cursor === 'object') delete cursor[parts[parts.length - 1]];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function assertStateOnlyChanged(before, after, options = {}) {
|
|
63
|
+
const label = options.label ? '[' + options.label + '] ' : '';
|
|
64
|
+
const allowed = Array.isArray(options.allowed) ? options.allowed : [];
|
|
65
|
+
const expectNewExitApplied = options.expectNewExitApplied === undefined ? 1 : options.expectNewExitApplied;
|
|
66
|
+
const beforeCmp = JSON.parse(JSON.stringify(before));
|
|
67
|
+
const afterCmp = JSON.parse(JSON.stringify(after));
|
|
68
|
+
for (const p of allowed) {
|
|
69
|
+
omitStatePath(beforeCmp, p);
|
|
70
|
+
omitStatePath(afterCmp, p);
|
|
71
|
+
}
|
|
72
|
+
if (!isDeepStrictEqual(beforeCmp, afterCmp)) {
|
|
73
|
+
throw new Error(label + '白名单外 state 深度不变量被破坏(allowed=' + JSON.stringify(allowed) + ')\n'
|
|
74
|
+
+ 'before=' + JSON.stringify(beforeCmp) + '\nafter=' + JSON.stringify(afterCmp));
|
|
75
|
+
}
|
|
76
|
+
const beforeHistory = Array.isArray(before?.history) ? before.history : [];
|
|
77
|
+
const afterHistory = Array.isArray(after?.history) ? after.history : [];
|
|
78
|
+
if (!isDeepStrictEqual(afterHistory.slice(0, beforeHistory.length), beforeHistory)) {
|
|
79
|
+
throw new Error(label + 'history 旧前缀被改写(旧条目必须逐字稳定)');
|
|
80
|
+
}
|
|
81
|
+
const appended = afterHistory.slice(beforeHistory.length);
|
|
82
|
+
if (appended.length !== expectNewExitApplied) {
|
|
83
|
+
throw new Error(label + 'history 应恰新增 ' + expectNewExitApplied + ' 条,实际 ' + appended.length
|
|
84
|
+
+ ':' + JSON.stringify(appended));
|
|
85
|
+
}
|
|
86
|
+
for (const event of appended) {
|
|
87
|
+
if (!event || event.event !== 'exit-applied') {
|
|
88
|
+
throw new Error(label + '新增 history 条目应为 exit-applied:' + JSON.stringify(event));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return appended;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// 安装副本版本比较断言单点(场景 193 多子锚共用):构造安装副本夹具 → 以副本脚本跑真实
|
|
95
|
+
// bridge-check CLI → 断言 exit 与全部关键词(失败附子锚标签便于定位)。helper 只声明期望,
|
|
96
|
+
// bridge-check 语义仍由 CLI 真实输出承载。
|
|
97
|
+
export function assertInstalledCopyBridgeVersionCase(dir, { label, installedVersion, loaderStamp, expectedExit, expectedKeywords }) {
|
|
98
|
+
const fixture = writeInstalledCopyBridgeFixture(dir, { installedVersion, loaderStamp });
|
|
99
|
+
const res = runBridgeCheckFromCopy(dir, fixture.dshHome, fixture.skillCopy);
|
|
100
|
+
try {
|
|
101
|
+
assertExit(res, expectedExit);
|
|
102
|
+
for (const keyword of expectedKeywords) assertOut(res, keyword);
|
|
103
|
+
} catch (e) {
|
|
104
|
+
throw new Error('[' + label + '] ' + e.message);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// 子锚表构造:单字段对象工厂 + 表函数(run 回调保持线性短小;子锚增长不再推动回调膨胀)。
|
|
109
|
+
export function bridgeCopyVersionCase(label, installedVersion, loaderStamp, expectedExit, ...expectedKeywords) {
|
|
110
|
+
return { label, installedVersion, loaderStamp, expectedExit, expectedKeywords };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// 场景 193 的安装副本版本比较子锚表——期望值全部从载体基础版本 baseVersion 派生:
|
|
114
|
+
// ② release 态严格相等;③ dev 态安装副本形态同基础健康;④ 两侧 dev 后缀同基础健康;
|
|
115
|
+
// ⑤ 基础版本失配仍 FAIL;⑥ 预发布标识不剥离仍 FAIL;⑦ release 对 release 失配仍 FAIL。
|
|
116
|
+
export function bridgeCopyVersionSubAnchorCases(baseVersion, devVersion) {
|
|
117
|
+
const major = parseInt(baseVersion.split('.')[0], 10);
|
|
118
|
+
const otherBase = (major + 9) + '.0.0';
|
|
119
|
+
return [
|
|
120
|
+
// ② release 态严格相等:两原始戳逐字相同 → 沿用 `==` 报告。
|
|
121
|
+
bridgeCopyVersionCase('release 严格相等', baseVersion, baseVersion, 0,
|
|
122
|
+
'[OK] 版本一致性: loader BRIDGE_VERSION=' + baseVersion + ' == 项目 INSTALLED_VERSION=' + baseVersion,
|
|
123
|
+
'bridge-check: 健康(全部检查通过)——exit 0'),
|
|
124
|
+
// ③ dev 态安装副本形态:载体戳为本副本自身形态(安装副本为 git describe 戳;权威源以发布
|
|
125
|
+
// 标记 + 同构 dev 后缀构造)→ 归一后与同基础 loader 判健康。
|
|
126
|
+
bridgeCopyVersionCase('dev 态安装副本同基础健康', devVersion, baseVersion, 0,
|
|
127
|
+
'[OK] 版本一致性: loader BRIDGE_VERSION=' + baseVersion + ' ~= 项目 INSTALLED_VERSION=' + devVersion + '(dev 态后缀归一后基础版本 ' + baseVersion + ' 一致)',
|
|
128
|
+
'bridge-check: 健康(全部检查通过)——exit 0'),
|
|
129
|
+
// ④ 两侧 dev 后缀同基础:归一后健康(后缀位置无关性)。
|
|
130
|
+
bridgeCopyVersionCase('两侧 dev 后缀同基础健康', baseVersion + '-3-gabcdef0', baseVersion + '-2-g1234567', 0,
|
|
131
|
+
'[OK] 版本一致性: loader BRIDGE_VERSION=' + baseVersion + '-2-g1234567 ~= 项目 INSTALLED_VERSION=' + baseVersion + '-3-gabcdef0(dev 态后缀归一后基础版本 ' + baseVersion + ' 一致)',
|
|
132
|
+
'bridge-check: 健康(全部检查通过)——exit 0'),
|
|
133
|
+
// ⑤ 基础版本失配:两侧 dev 后缀归一后仍不同 → 原始戳配对 + 双方归一值 FAIL exit 1。
|
|
134
|
+
bridgeCopyVersionCase('基础版本失配', otherBase + '-3-gabcdef0', baseVersion + '-2-g1234567', 1,
|
|
135
|
+
'[FAIL] 版本偏斜: loader BRIDGE_VERSION=' + baseVersion + '-2-g1234567 != 项目 INSTALLED_VERSION=' + otherBase + '-3-gabcdef0(归一基础版本: loader=' + baseVersion + ' / installed=' + otherBase + ')——两值如上',
|
|
136
|
+
'bridge-check: 失配 1 项——exit 1'),
|
|
137
|
+
// ⑥ 预发布标识不剥离:-rc.N 不属 dev 态后缀 → 仍报偏斜 FAIL exit 1。
|
|
138
|
+
bridgeCopyVersionCase('预发布标识不剥离', baseVersion, baseVersion + '-rc.3', 1,
|
|
139
|
+
'[FAIL] 版本偏斜: loader BRIDGE_VERSION=' + baseVersion + '-rc.3 != 项目 INSTALLED_VERSION=' + baseVersion + '(归一基础版本: loader=' + baseVersion + '-rc.3 / installed=' + baseVersion + ')——两值如上',
|
|
140
|
+
'bridge-check: 失配 1 项——exit 1'),
|
|
141
|
+
// ⑦ release 对 release 失配:两侧均无 dev 后缀且不同 → 仍 FAIL exit 1。
|
|
142
|
+
bridgeCopyVersionCase('release 对 release 失配', baseVersion, '9.9.9-fixture-skew', 1,
|
|
143
|
+
'[FAIL] 版本偏斜: loader BRIDGE_VERSION=9.9.9-fixture-skew != 项目 INSTALLED_VERSION=' + baseVersion + '(归一基础版本: loader=9.9.9-fixture-skew / installed=' + baseVersion + ')——两值如上',
|
|
144
|
+
'bridge-check: 失配 1 项——exit 1'),
|
|
145
|
+
];
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// ---------- route-node 共享 Fix 判定纯函数锚(直接调用) ----------
|
|
149
|
+
|
|
150
|
+
// 协议副本由运行器在场景执行前复制到 <dir>/reference/(见底部运行段)。
|
|
151
|
+
export function readScenarioProtocol(dir) {
|
|
152
|
+
return JSON.parse(fs.readFileSync(scenarioProtocolPath(dir), 'utf8'));
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// 245~247 场景直接调用 route-node 纯函数:缺失导出在此显式报告(RED 定位到具体场景,
|
|
156
|
+
// 而不是整套件在模块加载期因命名绑定失败 abort)。
|
|
157
|
+
export function requireRouteNodeExport(name) {
|
|
158
|
+
const fn = routeNodeModule?.[name];
|
|
159
|
+
if (typeof fn !== 'function') {
|
|
160
|
+
throw new Error('route-node.mjs 未导出共享 Fix 判定纯函数 ' + name + '(待实现)');
|
|
161
|
+
}
|
|
162
|
+
return fn;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Fix 夹具任务块(串行;字段齐全以通过 task-parsing 解析)
|
|
166
|
+
export function fixTaskBlock(id, status) {
|
|
167
|
+
return '<task id="' + id + '" parallel="false" status="' + status + '">'
|
|
168
|
+
+ '<action>实现 ' + id + '</action><write_files>src/' + id.toLowerCase() + '.mjs</write_files>'
|
|
169
|
+
+ '<verify>node --check src/' + id.toLowerCase() + '.mjs</verify></task>';
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Fix 批次(248~252)场景公共任务集:既有任务 T01 done + 修复任务(状态由参数指定)
|
|
173
|
+
export function fixBatchTaskText(fixStatus) {
|
|
174
|
+
return '# TASK\n\n' + fixTaskBlock('T01', 'done') + '\n' + fixTaskBlock('T-FIX-01', fixStatus) + '\n';
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// exit execute 二次完成回源场景公共夹具(场景族拆分后由三个顶层场景共享;每个场景仍在独立
|
|
178
|
+
// 临时目录运行,状态不跨场景共享):家族证据与基础 state 的字段基线在此单一表达。
|
|
179
|
+
export function fixReturnFamilyEvidence(taskIds) {
|
|
180
|
+
return {
|
|
181
|
+
execute: { summary: 'fix batch executed', completedChecks: ['required-skill:execute.flow-comet-dev'] },
|
|
182
|
+
'subagent-execute': { summary: 'delegated', handoffResult: handoffFor(taskIds) },
|
|
183
|
+
review: { summary: 'review in progress' },
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export function fixReturnBaseState(overrides = {}) {
|
|
188
|
+
return {
|
|
189
|
+
activeChange: CHANGE_ID,
|
|
190
|
+
currentNode: 'execute',
|
|
191
|
+
completedNodes: ['open', 'design', 'plan', 'execute', 'subagent-execute'],
|
|
192
|
+
enteredNodes: ['open', 'design', 'plan', 'execute', 'subagent-execute', 'review'],
|
|
193
|
+
evidence: fixReturnFamilyEvidence(['T01']),
|
|
194
|
+
verifyFailures: 0,
|
|
195
|
+
executionMode: 'subagent',
|
|
196
|
+
directOverride: false,
|
|
197
|
+
newChange: true,
|
|
198
|
+
...overrides,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export const FIX_RETURN_FAMILY_COMPLETED = 'open,design,plan,execute,subagent-execute';
|
|
203
|
+
|
|
204
|
+
// 回源夹具的 REVIEW.md 正文:内容表达「审查未完成、Fix 批次待回源出口」,文件在场即触发
|
|
205
|
+
// 路由按产物跳过 review 的行为。
|
|
206
|
+
export const FIX_RETURN_REVIEW_TEXT = '# REVIEW\n\n## 发现\n\n### Critical\n\n- 无\n\n### Major\n\n- 无\n\n### Minor\n\n- 无\n\n## 结论\n\n审查结论已记录;Fix 批次由 execute 完成,待回源重新出口。\n';
|
|
207
|
+
|
|
208
|
+
// 逐任务写入摘要夹具(id 列表由调用场景给出,未列出的任务不会凭空出现摘要)。
|
|
209
|
+
export function writeFixReturnSummaries(dir, taskIds) {
|
|
210
|
+
for (const id of taskIds) {
|
|
211
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/' + id + '-SUMMARY.md', strictSummary(id));
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// 并行 Fix 任务集(无依赖 → 可委托):既有任务 T01 done + parallel 修复任务(状态由参数指定)。
|
|
216
|
+
export function fixBatchParallelTaskText(fixStatus) {
|
|
217
|
+
return '# TASK\n\n' + fixTaskBlock('T01', 'done') + '\n'
|
|
218
|
+
+ '<task id="P-FIX-01" parallel="true" status="' + fixStatus + '">'
|
|
219
|
+
+ '<action>实现 P-FIX-01</action><write_files>src/p-fix-01.mjs</write_files>'
|
|
220
|
+
+ '<verify>node --check src/p-fix-01.mjs</verify></task>\n';
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// 家族出口事件过时回放:最新 exit-applied 事件节点为 execute / subagent-execute,
|
|
224
|
+
// 签名仍是修复任务追加前的占位值(本批生命周期未闭合的信号;change 缺省 = 旧 state 兼容)。
|
|
225
|
+
export function fixBatchHistoryWithStaleFamilyExit(node = 'execute') {
|
|
226
|
+
return [{ event: 'exit-applied', node, at: '2026-09-20T00:00:00.000Z', taskSetSignature: STALE_FIX_BATCH_SIGNATURE }];
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// done-but-unclosed 回放夹具(历史事故形态):history 中最新 exit-applied execute 事件记录的
|
|
230
|
+
// 签名仍是追加修复任务之前的占位值(与「既有任务 + 追加修复任务」当前任务集签名必然不等)——
|
|
231
|
+
// 机器信号 =「修复任务已标 done,但本批 execute 出口从未重新通过」。追加前的真实哈希值不影响
|
|
232
|
+
// 判据(只比较是否相等),占位常量让夹具与哈希算法实现解耦;旧 state 无该字段 → 渐进放行。
|
|
233
|
+
export const STALE_FIX_BATCH_SIGNATURE = '0'.repeat(64);
|
|
234
|
+
export function fixBatchHistoryWithStaleExecuteExit() {
|
|
235
|
+
return [{ event: 'exit-applied', node: 'execute', at: '2026-09-20T00:00:00.000Z', taskSetSignature: STALE_FIX_BATCH_SIGNATURE }];
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// 读取场景 state 的机器字段(Fix 批次场景的写盘断言:归位/回程真实落盘,不是只看输出)
|
|
239
|
+
export function readScenarioState(dir) {
|
|
240
|
+
return JSON.parse(fs.readFileSync(path.join(dir, '.flow-comet', 'flow-comet-state.json'), 'utf8'));
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// ---------- 受控重入(archive 源回边)场景材料(先写期望后执行) ----------
|
|
244
|
+
// archive 已 entry 且归档目录仍在原位时的受控重入契约(设计决策清单全部条目 /
|
|
245
|
+
// REQUIREMENT AC-1~AC-10):CLI 入口为
|
|
246
|
+
// `workflow-state.mjs reenter <target> --authorized-by <source> --reason <text>`。
|
|
247
|
+
// 本段只装配夹具与断言助手;判定语义的唯一权威在 route-node.mjs(测试侧不复制生产判定);
|
|
248
|
+
// 前驱交集期望值由内置协议 success 边独立推导,是测试判据的独立复算。
|
|
249
|
+
|
|
250
|
+
// 内置协议(route 顺序 open→design→plan→execute→subagent-execute→review→verify→archive)
|
|
251
|
+
// 下 predecessors(target) 的期望交集:success 边反向传递闭包,按协议顺序输出。
|
|
252
|
+
export const REENTRY_EXPECTED_INTERSECTION = {
|
|
253
|
+
'execute': ['open', 'design', 'plan'],
|
|
254
|
+
'subagent-execute': ['open', 'design', 'plan', 'execute'],
|
|
255
|
+
'review': ['open', 'design', 'plan', 'execute', 'subagent-execute'],
|
|
256
|
+
'verify': ['open', 'design', 'plan', 'execute', 'subagent-execute', 'review'],
|
|
257
|
+
};
|
|
258
|
+
export const REENTRY_FULL_COMPLETED = ['open', 'design', 'plan', 'execute', 'subagent-execute', 'review', 'verify'];
|
|
259
|
+
|
|
260
|
+
// archive 已 entry 夹具(AC-1 初始状态):归档目录仍在原位、status=running、前驱全已完成;
|
|
261
|
+
// overrides 覆盖旧 change(无 newChange 字段)/ status=completed / 轮次事件等形态。
|
|
262
|
+
// branchMode / enablePrReview / branchPrefix 显式在场——避免 readState 的旧 state 默认补齐
|
|
263
|
+
// 让「白名单外字段零改写」断言混入实现细节噪音。
|
|
264
|
+
export function reentryArchiveState(overrides = {}) {
|
|
265
|
+
return {
|
|
266
|
+
activeChange: CHANGE_ID,
|
|
267
|
+
currentNode: 'archive',
|
|
268
|
+
completedNodes: [...REENTRY_FULL_COMPLETED],
|
|
269
|
+
enteredNodes: [...REENTRY_FULL_COMPLETED, 'archive'],
|
|
270
|
+
evidence: {},
|
|
271
|
+
verifyFailures: 0,
|
|
272
|
+
executionMode: 'subagent',
|
|
273
|
+
directOverride: false,
|
|
274
|
+
newChange: true,
|
|
275
|
+
status: 'running',
|
|
276
|
+
branchMode: true,
|
|
277
|
+
enablePrReview: false,
|
|
278
|
+
branchPrefix: 'change/',
|
|
279
|
+
history: [{ event: 'exit-applied', node: 'verify', at: '2026-09-20T00:00:00.000Z', change: CHANGE_ID }],
|
|
280
|
+
...overrides,
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// 归档目录仍在原位(移动边界判定的前提之一):CHANGE.md + TASK.md 在场
|
|
285
|
+
export function writeReentryChangeDir(dir, changeName = CHANGE_ID) {
|
|
286
|
+
writeFile(dir, '.specs/' + changeName + '/CHANGE.md', '# CHANGE\n\n## Why\n\n受控重入夹具。\n');
|
|
287
|
+
writeFile(dir, '.specs/' + changeName + '/TASK.md', '# TASK\n\n' + fixTaskBlock('T01', 'done') + '\n');
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// 受控重入 CLI(真实命令路径):env 显式注入协议路径(门禁不得静默跳过);
|
|
291
|
+
// extra 供 --protocol 等追加参数;reenter 未落地前本路径因 unknown subcommand 必然 RED。
|
|
292
|
+
export function runReenter(dir, target, options = {}) {
|
|
293
|
+
const args = ['reenter', target];
|
|
294
|
+
if (options.source !== undefined) args.push('--authorized-by', options.source);
|
|
295
|
+
if (options.reason !== undefined) args.push('--reason', options.reason);
|
|
296
|
+
if (Array.isArray(options.extra)) args.push(...options.extra);
|
|
297
|
+
return runState(args, dir, {
|
|
298
|
+
FLOW_COMET_PROTOCOL: options.protocol || scenarioProtocolPath(dir),
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// state 原始字节:BLOCK / 空操作路径的「字节零改写」判据(JSON 深比会漏掉格式化、键序与
|
|
303
|
+
// 序列化表示漂移——字节比较才是契约)。
|
|
304
|
+
export function readStateBytes(dir) {
|
|
305
|
+
const file = path.join(dir, '.flow-comet', 'flow-comet-state.json');
|
|
306
|
+
if (!fs.existsSync(file)) {
|
|
307
|
+
throw new Error('state 文件缺失(夹具错误或命令删除了 state): ' + file);
|
|
308
|
+
}
|
|
309
|
+
return fs.readFileSync(file, 'utf8');
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
export function assertStateBytesUnchanged(dir, before, label) {
|
|
313
|
+
const after = readStateBytes(dir);
|
|
314
|
+
if (after !== before) {
|
|
315
|
+
throw new Error(label + ':要求 state 字节零改写,实际发生变化\nbefore:\n' + before + '\nafter:\n' + after);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// 备份文件清单(备份路径规则 .specs/<change-id>/.reentry-backups/):BLOCK / 空操作路径必须零新增。
|
|
320
|
+
export function reentryBackupFiles(dir, changeName = CHANGE_ID) {
|
|
321
|
+
const backupDir = path.join(dir, '.specs', changeName, '.reentry-backups');
|
|
322
|
+
if (!fs.existsSync(backupDir)) return [];
|
|
323
|
+
return fs.readdirSync(backupDir).sort();
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// 轮次事件夹具:change 归属字段是跨 change 隔离的唯一依据(写侧必须带 change)——
|
|
327
|
+
// 不带 change 的旧事件按 legacy 形态参与(reentry-applied 为新事件类型,实际不会出现)。
|
|
328
|
+
export function reentryHistoryEvent(roundNumber, changeName = CHANGE_ID) {
|
|
329
|
+
return {
|
|
330
|
+
event: 'reentry-applied',
|
|
331
|
+
from: 'archive',
|
|
332
|
+
to: 'verify',
|
|
333
|
+
round: roundNumber,
|
|
334
|
+
change: changeName,
|
|
335
|
+
authorization: { round: roundNumber, at: '2026-09-20T00:00:00.000Z', source: 'user-approval', target: 'verify' },
|
|
336
|
+
backup: '.specs/' + changeName + '/.reentry-backups/2026-09-20T00-00-00.000Z-pre-verify.json',
|
|
337
|
+
fingerprint: '0'.repeat(64),
|
|
338
|
+
at: '2026-09-20T00:00:00.000Z',
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// 授权形态纯函数锚(AC-2 的 guard-self-test 验证方式):形态合法性由 route-node 的
|
|
343
|
+
// parseReentryAuthorization 单一权威判定,本助手只声明期望(malformed → ok:false)。
|
|
344
|
+
export function assertReentryAuthorizationShape(authorization, target, expectedOk, label) {
|
|
345
|
+
const parse = requireRouteNodeExport('parseReentryAuthorization');
|
|
346
|
+
const result = parse({ authorization, target });
|
|
347
|
+
if (!result || result.ok !== expectedOk) {
|
|
348
|
+
throw new Error('[' + label + '] 授权形态判定应为 ok=' + expectedOk + ',实际 ' + JSON.stringify(result));
|
|
349
|
+
}
|
|
350
|
+
return result;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// 输出正则断言(BLOCK 指引类断言的共享助手;精确关键词断言用 assertOut)。
|
|
354
|
+
export function assertOutMatches(res, pattern, label) {
|
|
355
|
+
const text = outputText(res);
|
|
356
|
+
if (!pattern.test(text)) {
|
|
357
|
+
throw new Error((label || '输出') + ' 应匹配 ' + pattern + ',实际输出:\n' + text);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// ---------- 受控计划重校重签(replan)与强制推进留痕(advance-forced)场景材料 ----------
|
|
362
|
+
// replan 是"计划在执行中被证明有缺陷"时的受控通道(ADR-013):仅 execute / subagent-execute
|
|
363
|
+
// 相位可用、停原位、不跳节点——重新校验任务图与任务字段 → 重录 state.taskHash → 双写留痕
|
|
364
|
+
// (evidence.<node>.replanAuthorization + history 事件 replan-applied)。判定语义的唯一权威在
|
|
365
|
+
// route-node.mjs(测试侧不复制生产判定);本段只装配夹具与断言助手。纯函数契约按
|
|
366
|
+
// reentry 族同构声明:
|
|
367
|
+
// parseReplanAuthorization({ authorization, node }) // authorization = { round, at, source, reason, node }
|
|
368
|
+
// replanRoundCount({ history, changeName })
|
|
369
|
+
// replanRoundDecision({ history, changeName, continuationAuthorized })
|
|
370
|
+
// replanNoOpDecision({ state, taskContent })
|
|
371
|
+
// resolveReplanDecision({ protocol, state, authorization, continuationRound })
|
|
372
|
+
// 缺失导出由 requireRouteNodeExport 在场景内显式报告(RED 可定位到具体场景,不整套件 abort)。
|
|
373
|
+
|
|
374
|
+
// 修订前的任务集(entry 形态):一个串行待办任务
|
|
375
|
+
export const REPLAN_TASK_INITIAL =
|
|
376
|
+
'<task id="S01" status="pending" parallel="false"><action>实现 S01</action>'
|
|
377
|
+
+ '<write_files>src/s01.mjs</write_files><verify>node --check src/s01.mjs</verify></task>\n';
|
|
378
|
+
// 修订后的任务集(死锁现场):原任务完成 + 计划外新增的并行就绪任务
|
|
379
|
+
export const REPLAN_TASK_REVISED =
|
|
380
|
+
'<task id="S01" status="done" parallel="false"><action>实现 S01</action>'
|
|
381
|
+
+ '<write_files>src/s01.mjs</write_files><verify>node --check src/s01.mjs</verify></task>\n'
|
|
382
|
+
+ '<task id="P02" status="pending" parallel="true"><action>实现计划外新增的 P02</action>'
|
|
383
|
+
+ '<write_files>src/p02.mjs</write_files><verify>node --check src/p02.mjs</verify></task>\n';
|
|
384
|
+
// 缺 <verify> 字段的负例任务集(plan 出口与 replan 共用的任务字段校验)
|
|
385
|
+
export const REPLAN_TASK_NO_VERIFY =
|
|
386
|
+
'<task id="S01" status="pending" parallel="false"><action>实现 S01</action>'
|
|
387
|
+
+ '<write_files>src/s01.mjs</write_files></task>\n';
|
|
388
|
+
// 过期签名占位(与哈希算法实现解耦:只比较是否相等/同版本,不依赖真实摘要值)
|
|
389
|
+
export const REPLAN_STALE_SIGNATURE = 'v1:' + '0'.repeat(64);
|
|
390
|
+
|
|
391
|
+
// replan 相位夹具:execute 已 entry、前序完成、证据齐备(execute 出口可通过)、TASK.md 在场。
|
|
392
|
+
// branchMode / enablePrReview / branchPrefix 显式在场——避免 readState 兼容默认值让「零改写」
|
|
393
|
+
// 口径混入实现细节噪音(与受控重入夹具同做法)。
|
|
394
|
+
export function replanExecuteState(overrides = {}) {
|
|
395
|
+
return {
|
|
396
|
+
activeChange: CHANGE_ID,
|
|
397
|
+
currentNode: 'execute',
|
|
398
|
+
completedNodes: ['open', 'design', 'plan'],
|
|
399
|
+
enteredNodes: ['open', 'design', 'plan', 'execute'],
|
|
400
|
+
evidence: {
|
|
401
|
+
open: { summary: 'open done' },
|
|
402
|
+
design: { summary: 'design done' },
|
|
403
|
+
plan: { summary: 'plan done' },
|
|
404
|
+
execute: { summary: 'implementation recorded' },
|
|
405
|
+
'subagent-execute': { handoffResult: handoffFor(['S01']) },
|
|
406
|
+
},
|
|
407
|
+
verifyFailures: 0,
|
|
408
|
+
executionMode: 'subagent',
|
|
409
|
+
directOverride: false,
|
|
410
|
+
newChange: true,
|
|
411
|
+
status: 'running',
|
|
412
|
+
branchMode: false,
|
|
413
|
+
enablePrReview: false,
|
|
414
|
+
branchPrefix: 'change/',
|
|
415
|
+
history: [{ event: 'exit-applied', node: 'plan', at: '2026-09-27T00:00:00.000Z', change: CHANGE_ID }],
|
|
416
|
+
...overrides,
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// 备份目录/清单(replan 备份规则 .specs/<change-id>/replan-backups/):BLOCK / 空操作路径零新增。
|
|
421
|
+
export function replanBackupFiles(dir, changeName = CHANGE_ID) {
|
|
422
|
+
const backupDir = path.join(dir, '.specs', changeName, 'replan-backups');
|
|
423
|
+
return fs.existsSync(backupDir) ? fs.readdirSync(backupDir).sort() : [];
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
// replan-applied 事件过滤(轮次按 change 从 history 派生——与受控重入同计数法)
|
|
427
|
+
export function replanEventsOf(state) {
|
|
428
|
+
return (state.history || []).filter((e) => e && e.event === 'replan-applied');
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
// 轮次事件夹具:change 归属字段是跨 change 隔离的唯一依据(写侧必须带 change)
|
|
432
|
+
export function replanHistoryEvent(roundNumber, changeName = CHANGE_ID) {
|
|
433
|
+
return {
|
|
434
|
+
event: 'replan-applied',
|
|
435
|
+
node: 'execute',
|
|
436
|
+
round: roundNumber,
|
|
437
|
+
change: changeName,
|
|
438
|
+
reason: '计划重校',
|
|
439
|
+
authorizedBy: 'user-approval',
|
|
440
|
+
taskSetSignature: REPLAN_STALE_SIGNATURE,
|
|
441
|
+
at: '2026-09-27T00:00:00.000Z',
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
// advance-forced 事件夹具(status.forcedNodes 事件判据):change 归属过滤与 advance 写侧同形——
|
|
446
|
+
// 派生只取 event / change / node,skipped 等字段保留以贴近真实事件。
|
|
447
|
+
export function advanceForcedEvent(node, changeName = CHANGE_ID) {
|
|
448
|
+
return {
|
|
449
|
+
event: 'advance-forced',
|
|
450
|
+
change: changeName,
|
|
451
|
+
node,
|
|
452
|
+
skipped: ['exit:' + node],
|
|
453
|
+
reason: 'advance',
|
|
454
|
+
at: '2026-09-28T00:00:00.000Z',
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
// 授权形态纯函数锚(AC-2 的 guard-self-test 验证方式):形态合法性由 route-node 的
|
|
459
|
+
// parseReplanAuthorization 单一权威判定,本助手只声明期望(malformed → ok:false)。
|
|
460
|
+
export function assertReplanAuthorizationShape(authorization, node, expectedOk, label) {
|
|
461
|
+
const parse = requireRouteNodeExport('parseReplanAuthorization');
|
|
462
|
+
const result = parse({ authorization, node });
|
|
463
|
+
if (!result || result.ok !== expectedOk) {
|
|
464
|
+
throw new Error('[' + label + '] replan 授权形态判定应为 ok=' + expectedOk + ',实际 ' + JSON.stringify(result));
|
|
465
|
+
}
|
|
466
|
+
return result;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
// 重签复核:state.taskHash 必须等于当前 TASK.md 的签名(同版本比较复用 route-node 既有实现,
|
|
470
|
+
// 不在此内联第二份判据)。
|
|
471
|
+
export function assertReplanSignatureRecorded(state, taskContent, label) {
|
|
472
|
+
const same = requireRouteNodeExport('sameTaskSetSignature');
|
|
473
|
+
const signature = requireRouteNodeExport('taskSetSignature')(taskContent);
|
|
474
|
+
if (!same(state.taskHash, signature)) {
|
|
475
|
+
throw new Error(label + ':state.taskHash 应重签为当前 TASK.md 的签名,实际 '
|
|
476
|
+
+ JSON.stringify(state.taskHash) + ',期望 ' + JSON.stringify(signature));
|
|
477
|
+
}
|
|
478
|
+
return signature;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
// status 输出(JSON 块 + 尾巴行)解析:只取首个 { 到末个 } 之间的 JSON 对象。
|
|
482
|
+
export function parseStatusJson(res) {
|
|
483
|
+
const text = outputText(res);
|
|
484
|
+
const start = text.indexOf('{');
|
|
485
|
+
const end = text.lastIndexOf('}');
|
|
486
|
+
if (start < 0 || end <= start) throw new Error('status 输出缺少 JSON 块:\n' + text);
|
|
487
|
+
return JSON.parse(text.slice(start, end + 1));
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
// 场景协议副本路径(单一来源):以 dir 为基准的协议路径表达式只在此处出现一次;
|
|
491
|
+
// 调用面统一走下方助手。跨树(root)/ 安装副本(skillCopy)/ 自定义协议(options.protocol 或
|
|
492
|
+
// --protocol CLI)场景仍各自显式传路径,不经本助手(数据点保留)。
|
|
493
|
+
export function scenarioProtocolPath(dir) {
|
|
494
|
+
return path.join(dir, 'reference', 'workflow-protocol.json');
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
// 场景内受控命令(replan / advance / status / next):显式注入场景协议副本路径
|
|
498
|
+
// (依赖协议解析的门禁不得静默跳过;副本由运行器预置在 <dir>/reference/)。
|
|
499
|
+
export function runStateWithProtocol(dir, args) {
|
|
500
|
+
return runState(args, dir, { FLOW_COMET_PROTOCOL: scenarioProtocolPath(dir) });
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
// 同形 runGuard 助手(入口/出口门禁场景):注入与 runStateWithProtocol 同一 FLOW_COMET_PROTOCOL 表达。
|
|
504
|
+
export function runGuardWithProtocol(dir, args) {
|
|
505
|
+
return runGuard(args, dir, { FLOW_COMET_PROTOCOL: scenarioProtocolPath(dir) });
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
// ---------- 伪造材料 ----------
|
|
509
|
+
|