flow-comet 1.6.2 → 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.
Files changed (107) hide show
  1. package/.flow-comet/skills/flow-comet/INSTALLED_VERSION +1 -1
  2. package/.flow-comet/skills/flow-comet/SKILL.md +64 -46
  3. package/.flow-comet/skills/flow-comet/reference/KNOWN-ISSUES-template.md +1 -1
  4. package/.flow-comet/skills/flow-comet/reference/commit-discipline.md +32 -0
  5. package/.flow-comet/skills/flow-comet/reference/dirty-worktree.md +1 -1
  6. package/.flow-comet/skills/flow-comet/{GUIDANCE.md → reference/entry-detail.md} +18 -28
  7. package/.flow-comet/skills/flow-comet/reference/fix-loop.md +57 -0
  8. package/.flow-comet/skills/flow-comet/reference/platform-facts.md +58 -0
  9. package/.flow-comet/skills/flow-comet/reference/replan.md +23 -0
  10. package/.flow-comet/skills/flow-comet/scripts/comet-check.mjs +5 -4
  11. package/.flow-comet/skills/flow-comet/scripts/comet-hook-guard.mjs +266 -25
  12. package/.flow-comet/skills/flow-comet/scripts/context-init.mjs +2 -2
  13. package/.flow-comet/skills/flow-comet/scripts/evolve.mjs +6 -6
  14. package/.flow-comet/skills/flow-comet/scripts/guard-self-test.mjs +67 -16325
  15. package/.flow-comet/skills/flow-comet/scripts/health.mjs +1 -1
  16. package/.flow-comet/skills/flow-comet/scripts/items/a.mjs +1030 -0
  17. package/.flow-comet/skills/flow-comet/scripts/items/b.mjs +830 -0
  18. package/.flow-comet/skills/flow-comet/scripts/items/c.mjs +781 -0
  19. package/.flow-comet/skills/flow-comet/scripts/items/d.mjs +99 -0
  20. package/.flow-comet/skills/flow-comet/scripts/items/e.mjs +185 -0
  21. package/.flow-comet/skills/flow-comet/scripts/items/f.mjs +90 -0
  22. package/.flow-comet/skills/flow-comet/scripts/items/g.mjs +59 -0
  23. package/.flow-comet/skills/flow-comet/scripts/items/h.mjs +815 -0
  24. package/.flow-comet/skills/flow-comet/scripts/items/i.mjs +77 -0
  25. package/.flow-comet/skills/flow-comet/scripts/items/j.mjs +75 -0
  26. package/.flow-comet/skills/flow-comet/scripts/items/k.mjs +1427 -0
  27. package/.flow-comet/skills/flow-comet/scripts/items/l.mjs +275 -0
  28. package/.flow-comet/skills/flow-comet/scripts/items/m.mjs +614 -0
  29. package/.flow-comet/skills/flow-comet/scripts/lib/count-derivation.mjs +97 -0
  30. package/.flow-comet/skills/flow-comet/scripts/lib/fix-loop-node.mjs +196 -0
  31. package/.flow-comet/skills/flow-comet/scripts/lib/guard-evidence-gates.mjs +553 -0
  32. package/.flow-comet/skills/flow-comet/scripts/lib/guard-gates.mjs +837 -0
  33. package/.flow-comet/skills/flow-comet/scripts/lib/guard-routing.mjs +404 -0
  34. package/.flow-comet/skills/flow-comet/scripts/lib/guard-state-io.mjs +404 -0
  35. package/.flow-comet/skills/flow-comet/scripts/lib/guard-template-fidelity.mjs +302 -0
  36. package/.flow-comet/skills/flow-comet/scripts/lib/guard-uidesign.mjs +133 -0
  37. package/.flow-comet/skills/flow-comet/scripts/lib/reentry-node.mjs +237 -0
  38. package/.flow-comet/skills/flow-comet/scripts/lib/replan-node.mjs +209 -0
  39. package/.flow-comet/skills/flow-comet/scripts/lib/state-branch.mjs +49 -0
  40. package/.flow-comet/skills/flow-comet/scripts/lib/state-bridgecheck.mjs +201 -0
  41. package/.flow-comet/skills/flow-comet/scripts/lib/state-commands-admin.mjs +141 -0
  42. package/.flow-comet/skills/flow-comet/scripts/lib/state-commands-flow.mjs +700 -0
  43. package/.flow-comet/skills/flow-comet/scripts/lib/state-commands-recovery.mjs +578 -0
  44. package/.flow-comet/skills/flow-comet/scripts/lib/state-determine.mjs +52 -0
  45. package/.flow-comet/skills/flow-comet/scripts/lib/state-evolve-hint.mjs +55 -0
  46. package/.flow-comet/skills/flow-comet/scripts/lib/state-explain.mjs +106 -0
  47. package/.flow-comet/skills/flow-comet/scripts/lib/state-intelscan.mjs +58 -0
  48. package/.flow-comet/skills/flow-comet/scripts/lib/state-io.mjs +147 -0
  49. package/.flow-comet/skills/flow-comet/scripts/lib/state-skillmarkers.mjs +189 -0
  50. package/.flow-comet/skills/flow-comet/scripts/lib/system-fixtures.mjs +1441 -0
  51. package/.flow-comet/skills/flow-comet/scripts/lib/task-graph.mjs +471 -0
  52. package/.flow-comet/skills/flow-comet/scripts/lib/test-assertions.mjs +509 -0
  53. package/.flow-comet/skills/flow-comet/scripts/lib/test-fixtures.mjs +1228 -0
  54. package/.flow-comet/skills/flow-comet/scripts/lib/test-helpers.mjs +237 -0
  55. package/.flow-comet/skills/flow-comet/scripts/lib/text-anchor-checks.mjs +2484 -0
  56. package/.flow-comet/skills/flow-comet/scripts/protocol-utils.mjs +2 -2
  57. package/.flow-comet/skills/flow-comet/scripts/route-node.mjs +73 -1077
  58. package/.flow-comet/skills/flow-comet/scripts/scenarios/a.mjs +966 -0
  59. package/.flow-comet/skills/flow-comet/scripts/scenarios/b.mjs +1233 -0
  60. package/.flow-comet/skills/flow-comet/scripts/scenarios/c.mjs +1382 -0
  61. package/.flow-comet/skills/flow-comet/scripts/scenarios/d.mjs +483 -0
  62. package/.flow-comet/skills/flow-comet/scripts/scenarios/e.mjs +1388 -0
  63. package/.flow-comet/skills/flow-comet/scripts/scenarios/f.mjs +1466 -0
  64. package/.flow-comet/skills/flow-comet/scripts/scenarios/g.mjs +1364 -0
  65. package/.flow-comet/skills/flow-comet/scripts/scenarios/h.mjs +1287 -0
  66. package/.flow-comet/skills/flow-comet/scripts/scenarios/i.mjs +1436 -0
  67. package/.flow-comet/skills/flow-comet/scripts/scenarios/j.mjs +1384 -0
  68. package/.flow-comet/skills/flow-comet/scripts/scenarios/k.mjs +1338 -0
  69. package/.flow-comet/skills/flow-comet/scripts/scenarios/l.mjs +1484 -0
  70. package/.flow-comet/skills/flow-comet/scripts/scenarios/m.mjs +971 -0
  71. package/.flow-comet/skills/flow-comet/scripts/state-schema.mjs +14 -1
  72. package/.flow-comet/skills/flow-comet/scripts/system-test.mjs +58 -6692
  73. package/.flow-comet/skills/flow-comet/scripts/time-utils.mjs +4 -4
  74. package/.flow-comet/skills/flow-comet/scripts/workflow-guard.mjs +151 -2428
  75. package/.flow-comet/skills/flow-comet/scripts/workflow-handoff.mjs +116 -9
  76. package/.flow-comet/skills/flow-comet/scripts/workflow-state.mjs +29 -2086
  77. package/.flow-comet/skills/flow-comet-archive/SKILL.md +10 -19
  78. package/.flow-comet/skills/flow-comet-change/SKILL.md +2 -3
  79. package/.flow-comet/skills/flow-comet-compose/SKILL.md +1 -1
  80. package/.flow-comet/skills/flow-comet-design/SKILL.md +6 -6
  81. package/.flow-comet/skills/flow-comet-execute/SKILL.md +58 -16
  82. package/.flow-comet/skills/flow-comet-integration/SKILL.md +8 -5
  83. package/.flow-comet/skills/flow-comet-open/SKILL.md +5 -1
  84. package/.flow-comet/skills/flow-comet-plan/GUIDANCE.md +1 -1
  85. package/.flow-comet/skills/flow-comet-plan/SKILL.md +8 -8
  86. package/.flow-comet/skills/flow-comet-review/SKILL.md +9 -12
  87. package/.flow-comet/skills/flow-comet-subagent-execute/SKILL.md +59 -16
  88. package/.flow-comet/skills/flow-comet-task/SKILL.md +3 -2
  89. package/.flow-comet/skills/flow-comet-ui-design/SKILL.md +3 -3
  90. package/.flow-comet/skills/flow-comet-verify/SKILL.md +8 -17
  91. package/README.md +53 -70
  92. package/package.json +3 -2
  93. package/scripts/dsh-bridge.mjs +59 -26
  94. package/scripts/lib/installer-cleanup.mjs +152 -0
  95. package/scripts/lib/installer-flowkit.mjs +119 -0
  96. package/scripts/lib/installer-hooks.mjs +363 -0
  97. package/scripts/lib/installer-loader.mjs +220 -0
  98. package/scripts/lib/installer-migrate.mjs +236 -0
  99. package/scripts/lib/installer-platforms.mjs +314 -0
  100. package/scripts/prepare-env.mjs +36 -1164
  101. package/.flow-comet/skills/flow-comet/reference/TEST-MATRIX.md +0 -116
  102. package/.flow-comet/skills/flow-comet/reference/composition-report.md +0 -65
  103. package/.flow-comet/skills/flow-comet/reference/dsh-platform.md +0 -184
  104. package/.flow-comet/skills/flow-comet/reference/resolved-skills.json +0 -661
  105. package/.flow-comet/skills/flow-comet/reference/skill-review.md +0 -13
  106. package/.flow-comet/skills/flow-comet/reference/subagents/script-author.md +0 -7
  107. package/.flow-comet/skills/flow-comet/reference/worktree-notes.md +0 -70
@@ -0,0 +1,614 @@
1
+ // items/m.mjs — M 组条目(侧命令与 ui-design 门)
2
+ //
3
+ // 组文件约定:`export const ENTRIES = [...]`(元素含 name 与 run;计数派生按此聚合,见 lib/count-derivation.mjs)。
4
+ // 跨组共用夹具在 lib/system-fixtures.mjs(组文件只承载 ENTRIES 数据与组内私有夹具,组文件之间零 import)。
5
+
6
+ import fs from 'fs';
7
+ import path from 'path';
8
+ import { execFileSync, spawnSync } from 'child_process';
9
+ import { createHash } from 'crypto';
10
+ import { fileURLToPath, pathToFileURL } from 'url';
11
+ import { assertEqual, assertExit, assertNotOut, assertOut, assertTrue, baseState, runGuard, runState, writeFile, writeState } from '../lib/test-helpers.mjs';
12
+ import { CHANGE_ID, parseStatusOutput, readStateBytes, readStateFile, writeIntakeArtifacts } from '../lib/system-fixtures.mjs';
13
+
14
+ // 路径推导基准:技能包 scripts/ 目录(与套件入口同基准)
15
+ const SCRIPTS_DIR = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
16
+ // 内置协议源文件(技能包 reference/):绑定声明类用例需要把协议副本落到夹具根外再引用
17
+ const BUILTIN_PROTOCOL_SOURCE = path.join(SCRIPTS_DIR, '..', 'reference', 'workflow-protocol.json');
18
+
19
+ // ---------- 侧命令(evolve / health / context-scan)与 ui-design 门:真实命令链路材料 ----------
20
+ // 与 guard-self-test 同构:判据走真实 CLI;零写入判据用树指纹(相对路径清单 + 文件 sha256)。
21
+ const SIDE_EVOLVE = path.join(SCRIPTS_DIR, 'evolve.mjs');
22
+ const SIDE_HEALTH = path.join(SCRIPTS_DIR, 'health.mjs');
23
+ const SIDE_CONTEXT_SCAN = path.join(SCRIPTS_DIR, 'context-scan.mjs');
24
+ // 时间形态的单一来源:侧命令产物的日期分量按同一实现推导(测试侧不复制第二份格式化)
25
+ const timeUtilsModule = await import(pathToFileURL(path.join(SCRIPTS_DIR, 'time-utils.mjs')).href);
26
+ const localDate = (value = new Date()) => timeUtilsModule.formatLocalDate(value);
27
+
28
+ // 侧命令真实调用:协议环境与 runState / runGuard / runHook 同形(FLOW_COMET_PROTOCOL 指向场景内副本)
29
+ // ——协议路径的唯一权威是 state-schema 的选择器(state.protocolPath > 环境变量 > 内置默认),侧命令
30
+ // 的 state 通道子进程必须看到与门禁同一份来源。构造「无环境变量」的场景用 `{ FLOW_COMET_PROTOCOL: '' }`。
31
+ function runSideScript(script, args, root, envOverrides = {}) {
32
+ const res = spawnSync(process.execPath, [script, ...args], {
33
+ cwd: root,
34
+ env: {
35
+ ...process.env,
36
+ FLOW_COMET_PROTOCOL: path.join(root, 'reference', 'workflow-protocol.json'),
37
+ ...envOverrides,
38
+ },
39
+ encoding: 'utf8',
40
+ timeout: 120000,
41
+ });
42
+ return { status: res.status ?? 1, output: String(res.stdout || '') + String(res.stderr || '') };
43
+ }
44
+
45
+ function treeFingerprint(root) {
46
+ const rows = [];
47
+ const walk = (dir) => {
48
+ const entries = fs.readdirSync(dir, { withFileTypes: true })
49
+ .sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
50
+ for (const entry of entries) {
51
+ const full = path.join(dir, entry.name);
52
+ const rel = path.relative(root, full).split(path.sep).join('/');
53
+ if (entry.isDirectory()) { rows.push(rel + '/'); walk(full); continue; }
54
+ rows.push(rel + ' ' + createHash('sha256').update(fs.readFileSync(full)).digest('hex'));
55
+ }
56
+ };
57
+ walk(root);
58
+ return rows.join('\n');
59
+ }
60
+
61
+ function readText(root, rel) {
62
+ return fs.readFileSync(path.join(root, rel), 'utf8');
63
+ }
64
+
65
+
66
+ // 跨过下一个秒边界(`last_intel_scan` 为秒级精度:同一秒内的两次写入取值可能相同,双落点漂移不可判)。
67
+ // 轮询到「严格晚于目标秒」才返回——等待上限约 1.05s,比固定 sleep 短且不受调用时刻影响。
68
+ function waitForNextSecond() {
69
+ const target = Math.floor(Date.now() / 1000) + 1;
70
+ while (Math.floor(Date.now() / 1000) <= target) {
71
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 20);
72
+ }
73
+ }
74
+
75
+ // 七段 CONTEXT 骨架(域语言段带模板表格表头;intel-scan 元数据段三字段齐——结构校验的通过形态)。
76
+ // 与 guard-self-test.mjs 的同名夹具**同形镜像**(两份载体刻意独立、不互相 import:夹具若从被测模块
77
+ // 派生,锚点会退化成同义反复)——改段名 / 字段名时必须两份同改(与词表镜像同纪律)。
78
+ // `last_intel_scan` 行取**真实生成件形态**:取值词元 + 行尾说明(`--init-context` 的生成物即此形;
79
+ // 写侧 `context-scan` 只替换首个取值词元、说明原样保留)——裸取值词元夹具下「读侧取整行剩余文本」
80
+ // 的口径缺陷在本项不可见(见 M7 的单变量对照)。
81
+ const INTEL_FIELD_SUFFIX = ' (首次接入生成时留占位;由 `init --init-context` 或 `context-scan` 记录扫描时间)';
82
+ function contextFixtureText() {
83
+ return [
84
+ '# 项目上下文', '',
85
+ '## 项目概要', '', '- 夹具概要', '',
86
+ '## 技术栈', '', '- Node.js(ESM)', '',
87
+ '## 域语言', '', '| 术语 | 定义 |', '|---|---|', '| 夹具 | 测试用 |', '',
88
+ '## 已锁决策', '', '- [2026-09-01] 夹具决策 — 来自 @.specs/CONTEXT.md', '',
89
+ '## 默认偏好', '', '- 夹具偏好', '',
90
+ '## 既有抽象索引', '', '- 夹具既有抽象', '',
91
+ '## intel-scan 元数据', '',
92
+ '- **last_intel_scan**: 2026-09-01T10:00:00+08:00' + INTEL_FIELD_SUFFIX,
93
+ '- **scanner**: flow-comet',
94
+ '- **下次重扫建议**: 3 个月后', '',
95
+ ].join('\n');
96
+ }
97
+
98
+ // ---------- 系统测试项(A~M 十三类) ----------
99
+
100
+ // AC-2:EVOLVE 报告的三个子句(`## 扫描范围` / `已扫 change 清单` / `未应用` 记账 + 未应用项段)
101
+ // 判据——纯函数,合成输入可驱动判别力(缺任一子句 → 必报,见 M1 的反向构造)。
102
+ function evolveReportClauseProblems(reportText) {
103
+ const problems = [];
104
+ if (!reportText.includes('## 扫描范围')) problems.push('缺「## 扫描范围」段');
105
+ if (!reportText.includes('- 已扫 change 清单:')) problems.push('缺「已扫 change 清单」行');
106
+ if (!/未应用 \d+ 条/.test(reportText)) problems.push('缺「未应用 N 条」记账');
107
+ if (!reportText.includes('## 未应用项')) problems.push('缺「## 未应用项」段');
108
+ return problems;
109
+ }
110
+
111
+ // AC-3:`## evolve 元数据` 三字段端到端判据(段在场 + 三字段齐备 + 取值与 state / 本次执行工具一致)。
112
+ function evolveSectionFieldProblems(contextText, ts, scanner) {
113
+ const section = /## evolve 元数据[\s\S]*?(?=\n## |\s*$)/.exec(contextText);
114
+ if (section === null) return ['缺 `## evolve 元数据` 段'];
115
+ const body = section[0];
116
+ const problems = [];
117
+ for (const [key, value] of [['last_evolve_at', ts], ['scanner', scanner]]) {
118
+ const found = new RegExp('- \\*\\*' + key + '\\*\\*: `([^`]*)`').exec(body);
119
+ if (found === null) problems.push('段内缺字段 ' + key);
120
+ else if (found[1] !== value) problems.push('段内 ' + key + ' 取值不符: ' + JSON.stringify(found[1]));
121
+ }
122
+ if (!/- \*\*下次建议\*\*: `[^`]+`/.test(body)) problems.push('段内缺非空的 `下次建议` 字段');
123
+ return problems;
124
+ }
125
+
126
+
127
+ export const ENTRIES = [
128
+ // ---------- M. 侧命令(evolve / health / context-scan)与 ui-design 门:真实命令链路 ----------
129
+
130
+ {
131
+ name: 'M1 evolve 真实链路:scan 零写入 → apply 落盘·报告·双落点 → 幂等 → 反例零改动',
132
+ run: (dir) => {
133
+ writeFile(dir, '.specs/archive/2026-09-10-fixture/DESIGN.md',
134
+ '# DESIGN\n\n## 5. 其它段\n\nOTHER-SECTION-MARKER\n\n## 9. 架构沉淀\n\n### 可复用抽象\n\n- 夹具抽象条目(真实链路)\n');
135
+ // 第二个归档 change 提供第二条候选(同段同类):AC-2 的「只批准一项 → 其余候选零改动 +
136
+ // 报告按「未应用 N 条」记账」需要一条**未被批准**的真实候选,否则该子句恒为 0 条。
137
+ writeFile(dir, '.specs/archive/2026-09-10b-fixture/DESIGN.md',
138
+ '# DESIGN\n\n## 9. 架构沉淀\n\n### 可复用抽象\n\n- 未被批准的夹具条目(其余候选零改动)\n');
139
+ writeFile(dir, '.specs/CONTEXT.md', contextFixtureText());
140
+ writeState(dir, baseState('open'));
141
+
142
+ const before = treeFingerprint(dir);
143
+ const scan = runSideScript(SIDE_EVOLVE, ['scan', '--root', dir], dir);
144
+ assertExit(scan, 0);
145
+ assertOut(scan, 'EVOLVE: 窗口');
146
+ assertOut(scan, '2026-09-10-fixture#1');
147
+ assertNotOut(scan, 'OTHER-SECTION-MARKER');
148
+ if (treeFingerprint(dir) !== before) throw new Error('scan 必须零写入(树指纹应逐项一致)');
149
+
150
+ const apply = runSideScript(SIDE_EVOLVE,
151
+ ['apply', '2026-09-10-fixture#1', '--root', dir, '--scanner', 'flow-comet-evolve'], dir);
152
+ assertExit(apply, 0);
153
+ assertOut(apply, 'EVOLVE-OK');
154
+ assertOut(apply, 'EVOLVE: 双落点一致 state = ');
155
+ const contextText = readText(dir, '.specs/CONTEXT.md');
156
+ if (!contextText.includes('夹具抽象条目(真实链路)')) throw new Error('目标段未出现已批准的条目');
157
+ if (!contextText.includes('来源 @.specs/archive/2026-09-10-fixture/DESIGN.md')) {
158
+ throw new Error('条目缺来源标注');
159
+ }
160
+ if (contextText.includes('未被批准的夹具条目')) {
161
+ throw new Error('未批准的候选被写入了目标文档(AC-2「仅该项被写入」被破坏)');
162
+ }
163
+ const evolveReport = path.join(dir, '.specs', 'evolve', localDate() + '-EVOLVE.md');
164
+ if (!fs.existsSync(evolveReport)) throw new Error('EVOLVE 报告未落盘: ' + evolveReport);
165
+
166
+ // AC-2 报告子句(此前只断言「报告存在」):扫描范围 + 已扫 change 清单 + 未应用记账。
167
+ const reportText = fs.readFileSync(evolveReport, 'utf8');
168
+ const clauseProblems = evolveReportClauseProblems(reportText);
169
+ assertEqual(clauseProblems.length, 0, 'EVOLVE 报告缺 AC-2 声明的子句: ' + clauseProblems.join(' | '));
170
+ assertTrue(reportText.includes('2026-09-10b-fixture'),
171
+ '报告的「已扫 change 清单」未列出第二个归档 change');
172
+ assertTrue(reportText.includes('未应用 1 条'), '报告未按「本次应用 1 / 未应用 1」记账');
173
+ assertTrue(reportText.includes('2026-09-10b-fixture#1'), '「未应用项」段未列出未批准的候选 id');
174
+ // 判别力(合成输入驱动同一判据):逐个子句从真实报告里移除 → 必报(判据不恒真空过)
175
+ for (const clause of ['## 扫描范围', '- 已扫 change 清单:', '## 未应用项']) {
176
+ const mutated = reportText.replace(clause, '(反向构造:子句被移除)');
177
+ assertTrue(mutated !== reportText, '反向构造前提不成立(真实报告缺子句): ' + clause);
178
+ assertTrue(evolveReportClauseProblems(mutated).length > 0,
179
+ '报告缺子句未被判违规(判别力缺失): ' + clause);
180
+ }
181
+
182
+ const state = readStateFile(dir);
183
+ if (!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{2}:\d{2}$/.test(String(state.last_evolve_at))) {
184
+ throw new Error('双落点 state 侧形态非法: ' + JSON.stringify(state.last_evolve_at));
185
+ }
186
+ if (!contextText.includes(state.last_evolve_at)) throw new Error('双落点取值不一致(段侧与 state)');
187
+ // AC-3 三字段端到端(此前只断言时间戳一个):段在场 + `last_evolve_at` / `scanner` /
188
+ // `下次建议` 齐备且取值与 state、本次执行工具一致。
189
+ const fieldProblems = evolveSectionFieldProblems(contextText, state.last_evolve_at, 'flow-comet-evolve');
190
+ assertEqual(fieldProblems.length, 0, 'AC-3 三字段端到端: ' + fieldProblems.join(' | '));
191
+ // 判别力(合成输入驱动同一判据):三字段各自移除 / 取值写错 → 必报
192
+ const withoutField = contextText.replace(/- \*\*下次建议\*\*: `[^`]*`\n/, '');
193
+ assertTrue(withoutField !== contextText, '反向构造前提不成立(段内无「下次建议」字段)');
194
+ assertTrue(evolveSectionFieldProblems(withoutField, state.last_evolve_at, 'flow-comet-evolve').length > 0,
195
+ '段内缺「下次建议」字段未被判违规');
196
+ assertTrue(evolveSectionFieldProblems(contextText, state.last_evolve_at, 'other-scanner').length > 0,
197
+ '段内 scanner 取值与本次执行工具不符未被判违规');
198
+ assertTrue(evolveSectionFieldProblems(contextText.replace('## evolve 元数据', '## 其它段'),
199
+ state.last_evolve_at, 'flow-comet-evolve').length > 0, '段缺席未被判违规');
200
+
201
+ const again = runSideScript(SIDE_EVOLVE, ['apply', '2026-09-10-fixture#1', '--root', dir], dir);
202
+ assertExit(again, 0);
203
+ assertOut(again, 'EVOLVE-OK');
204
+ const occurrences = readText(dir, '.specs/CONTEXT.md').split('夹具抽象条目(真实链路)').length - 1;
205
+ assertEqual(occurrences, 1, '重复应用同一候选的条目出现次数(幂等)');
206
+
207
+ // 幂等判据不得依赖**当天日期**:标记注释里写的是当次运行的本地日期,隔天重跑时它必然失配;
208
+ // 而条目文本一旦被人工改写,`body.includes(entry)` 也同时失配 ⇒ 同一候选被二次插入。
209
+ // 两臂同变异、单变量——对照臂只改条目文本(标记保持当天),处理臂再把标记日期改到过去
210
+ // (= 隔天重跑的等效输入):后者若仍幂等,就说明判别依据与日期无关,而对照臂同时证明
211
+ // 「条目被改写」本身不会让判据失效(不是靠变异把两臂都弄红)。
212
+ // 变异必须**打断条目文本本身**(在来源标注之前插入):只往行尾追加的话,`entry` 仍是该行的
213
+ // 连续子串,`body.includes(entry)` 照旧命中——变异就没碰到要考的那条判据(锚会恒绿)。
214
+ const editEntry = (text) => {
215
+ const lines = text.split('\n');
216
+ const at = lines.findIndex((line) => line.includes('夹具抽象条目(真实链路)'));
217
+ assertTrue(at >= 0, '反向构造前提不成立(目标段无该条目行)');
218
+ lines[at] = lines[at].replace(' · 来源 @.specs/', ' · 人工改写 · 来源 @.specs/');
219
+ assertTrue(lines[at].includes(' · 人工改写 · 来源 @.specs/'),
220
+ '反向构造前提不成立(条目行未含来源标注,变异无处落点)');
221
+ return lines.join('\n');
222
+ };
223
+ const backdate = (text, date) => {
224
+ const from = '<!-- flow-comet-evolve ' + localDate() + ':';
225
+ assertTrue(text.includes(from), '反向构造前提不成立(目标段无当日标记注释)');
226
+ return text.replace(from, '<!-- flow-comet-evolve ' + date + ':');
227
+ };
228
+ const countEntry = () => readText(dir, '.specs/CONTEXT.md').split('夹具抽象条目(真实链路)').length - 1;
229
+ const edited = editEntry(readText(dir, '.specs/CONTEXT.md'));
230
+ assertTrue(!edited.includes('- 夹具抽象条目(真实链路) · 来源 @.specs/'),
231
+ '反向构造前提不成立(条目文本仍是连续子串,entry 判据未被扰动)');
232
+ writeFile(dir, '.specs/CONTEXT.md', edited);
233
+ const sameDay = runSideScript(SIDE_EVOLVE, ['apply', '2026-09-10-fixture#1', '--root', dir], dir);
234
+ assertExit(sameDay, 0);
235
+ assertOut(sameDay, 'EVOLVE-OK');
236
+ assertNotOut(sameDay, 'EVOLVE-APPLY: [2026-09-10-fixture#1]');
237
+ assertEqual(countEntry(), 1, '条目文本被改写后同日重跑:同一候选被二次插入');
238
+
239
+ writeFile(dir, '.specs/CONTEXT.md',
240
+ backdate(editEntry(readText(dir, '.specs/CONTEXT.md')), '2000-01-01'));
241
+ const crossDay = runSideScript(SIDE_EVOLVE, ['apply', '2026-09-10-fixture#1', '--root', dir], dir);
242
+ assertExit(crossDay, 0);
243
+ assertOut(crossDay, 'EVOLVE-OK');
244
+ assertNotOut(crossDay, 'EVOLVE-APPLY: [2026-09-10-fixture#1]');
245
+ assertEqual(countEntry(), 1, '跨日重跑同一候选:标记的日期分量失配 → 条目被二次插入');
246
+
247
+ const stateBefore = readStateBytes(dir);
248
+ const contextBefore = readText(dir, '.specs/CONTEXT.md');
249
+ const unknown = runSideScript(SIDE_EVOLVE, ['apply', 'no-such-id#1', '--root', dir], dir);
250
+ assertExit(unknown, 1);
251
+ assertOut(unknown, '候选 id 未找到');
252
+ if (!readStateBytes(dir).equals(stateBefore)) throw new Error('未知 id 反例改写了 state');
253
+ assertEqual(readText(dir, '.specs/CONTEXT.md'), contextBefore, '未知 id 反例改写了目标文档');
254
+
255
+ writeFile(dir, '.specs/archive/2026-09-11-contract/DESIGN.md',
256
+ '# DESIGN\n\n## 9. 架构沉淀\n\n### 跨模块契约\n\n- 夹具契约条目\n');
257
+ const absent = runSideScript(SIDE_EVOLVE, ['apply', '2026-09-11-contract#1', '--root', dir], dir);
258
+ assertExit(absent, 1);
259
+ assertOut(absent, '目标文档不在场');
260
+ if (!readStateBytes(dir).equals(stateBefore)) throw new Error('目标文档缺席反例改写了 state');
261
+ assertEqual(readText(dir, '.specs/CONTEXT.md'), contextBefore, '目标文档缺席反例改写了目标文档');
262
+ },
263
+ },
264
+
265
+ {
266
+ name: 'M2 health 真实链路:确定性层 + 增补层两态自洽 + --stdout 与落盘一致 + 不写 state',
267
+ run: (dir) => {
268
+ writeFile(dir, '.specs/CONTEXT.md', contextFixtureText());
269
+ writeFile(dir, '.specs/LESSONS.md', '# LESSONS\n\n### L-001 首条\n\n### L-002 次条\n');
270
+ writeState(dir, baseState('open'));
271
+ const stateBytes = readStateBytes(dir);
272
+
273
+ const res = runSideScript(SIDE_HEALTH, ['--root', dir, '--stdout'], dir);
274
+ assertExit(res, 0);
275
+ assertOut(res, '## 确定性层(机器可判)');
276
+ assertOut(res, '- 缺失编号(0):无');
277
+ assertOut(res, '## 增补层(代码体检工具的 4 维结果 · 可选)');
278
+ assertOut(res, '## 降级声明');
279
+ assertOut(res, '## 易变行声明(两次运行的允许差异集合)');
280
+ // 两态自洽:在场判定与降级声明必须同向(环境决定哪一态,形态不得自相矛盾)
281
+ const present = res.output.includes('- **在场判定**:在场');
282
+ assertEqual(res.output.includes('- **brooks-lint**:在场'), present, '增补层在场判定与降级声明的同向性');
283
+ assertOut(res, present ? '- **来源标注(必填)**' : '- **brooks-lint**:不可用——探测面逐项未命中');
284
+
285
+ const reportFile = path.join(dir, '.specs', 'health', localDate() + '-HEALTH.md');
286
+ assertTrue(fs.existsSync(reportFile), '报告未按 <日期>-HEALTH.md 形态落盘: ' + reportFile);
287
+ // `--stdout` = 落盘报告正文原样在前 + `HEALTH:` 审计行追加在后(审计行是 CLI 摘要,
288
+ // 不进报告字节——报告仍是唯一写入面;正文部分与落盘逐字节一致)
289
+ const reportText = fs.readFileSync(reportFile, 'utf8');
290
+ assertTrue(res.output.startsWith(reportText), '--stdout 的报告正文应与落盘逐字节一致(审计行追加在后)');
291
+ assertOut(res, 'HEALTH: 报告 `.specs/health/' + localDate() + '-HEALTH.md`');
292
+ assertOut(res, 'HEALTH-DONE');
293
+ if (!readStateBytes(dir).equals(stateBytes)) throw new Error('health 改写了运行状态文件');
294
+
295
+ // 审计行与报告路径**恒输出**:不带 `--stdout` 时 stdout 只给摘要(报告正文不回流),
296
+ // 调用方据此确认「跑没跑、落在哪」——此前该形态 stdout 为空、报告路径无处可见。
297
+ const quiet = runSideScript(SIDE_HEALTH, ['--root', dir], dir);
298
+ assertExit(quiet, 0);
299
+ assertOut(quiet, 'HEALTH: 报告 `.specs/health/' + localDate() + '-HEALTH.md`');
300
+ assertOut(quiet, 'HEALTH-DONE');
301
+ assertTrue(!quiet.output.includes('## 确定性层(机器可判)'), '不带 --stdout 时报告正文不应回流到标准输出');
302
+ if (!readStateBytes(dir).equals(stateBytes)) throw new Error('不带 --stdout 的一轮改写了运行状态文件');
303
+
304
+ // 对照态:隔离 HOME/USERPROFILE(用户级落点全部缺席)→ 增补层逐项不在场仍 exit 0
305
+ const isolatedHome = path.join(dir, 'isolated-home');
306
+ fs.mkdirSync(isolatedHome, { recursive: true });
307
+ const isolated = runSideScript(SIDE_HEALTH, ['--root', dir, '--stdout'], dir,
308
+ { HOME: isolatedHome, USERPROFILE: isolatedHome });
309
+ assertExit(isolated, 0);
310
+ assertOut(isolated, '- **在场判定**:不在场——下列探测面逐项未命中(未安装 / 未加载)');
311
+ assertOut(isolated, '- **brooks-lint**:不可用——探测面逐项未命中');
312
+ assertOut(isolated, '## 确定性层(机器可判)');
313
+ if (!readStateBytes(dir).equals(stateBytes)) throw new Error('health 对照态改写了运行状态文件');
314
+ },
315
+ },
316
+
317
+ {
318
+ name: 'M3 context-scan 真实链路:init 后首扫建基线 → 工件变化 → 重扫出差分 + 双落点 + 不扰动路由',
319
+ run: (dir) => {
320
+ assertExit(runState(['init', CHANGE_ID, '--init-skip'], dir), 0);
321
+ writeFile(dir, '.specs/CONTEXT.md', contextFixtureText());
322
+
323
+ const first = runSideScript(SIDE_CONTEXT_SCAN, ['--root', dir], dir);
324
+ assertExit(first, 0);
325
+ assertOut(first, 'CONTEXT-SCAN: 基线 无(本次为基线,无差异可比)');
326
+ assertOut(first, 'CONTEXT-SCAN-DONE');
327
+ const stateAfterFirst = readStateFile(dir);
328
+ assertEqual(stateAfterFirst.currentNode, 'open', '重扫不得改动路由字段 currentNode');
329
+ assertEqual(stateAfterFirst.activeChange, CHANGE_ID, '重扫不得改动 activeChange');
330
+
331
+ const contextText = readText(dir, '.specs/CONTEXT.md');
332
+ writeFile(dir, '.specs/CONTEXT.md',
333
+ contextText.replace('## 既有抽象索引\n', '## 既有抽象索引\n\n- 新增抽象条目(真实链路)\n'));
334
+ const second = runSideScript(SIDE_CONTEXT_SCAN, ['--root', dir], dir);
335
+ assertExit(second, 0);
336
+ assertOut(second, '差异 新增 1 ');
337
+ assertOut(second, 'CONTEXT-SCAN-DONE');
338
+
339
+ const report = readText(dir, '.specs/context-scan/' + localDate() + '-SCAN.md');
340
+ assertTrue(report.includes('### 新增(1)'), '工件缺「新增(1)」段');
341
+ assertTrue(report.includes('新增抽象条目(真实链路)'), '工件的新增段未列出新增的抽象索引条目');
342
+ const stateAfterSecond = readStateFile(dir);
343
+ assertTrue(report.includes(stateAfterSecond.last_intel_scan), '工件与 state 的扫描时刻不一致');
344
+ assertTrue(readText(dir, '.specs/CONTEXT.md').includes(stateAfterSecond.last_intel_scan),
345
+ 'CONTEXT 段侧与 state 的扫描时刻不一致(双落点)');
346
+
347
+ const status = runState(['status'], dir);
348
+ assertExit(status, 0);
349
+ assertEqual(parseStatusOutput(dir).currentNode, 'open', '重扫后 status 的节点推导');
350
+ },
351
+ },
352
+
353
+ {
354
+ name: 'M4 ui-design 门真实链路:entry design → 缺件 BLOCK → 补件·声明 → exit --apply 放行',
355
+ run: (dir) => {
356
+ assertExit(runState(['init', CHANGE_ID], dir), 0);
357
+ assertExit(runState(['skill-load', 'open', 'flow-comet-change', '--prompt', 'flow-kit/prompts/0-change.md'], dir), 0);
358
+ writeIntakeArtifacts(dir);
359
+ fs.appendFileSync(path.join(dir, '.specs', CHANGE_ID, 'CHANGE.md'),
360
+ '\n## 视觉调性(Visual Tone)\n\n现代、克制的工具型界面。\n');
361
+ assertExit(runState(['record', 'open', '{"summary":"intake complete"}'], dir), 0);
362
+ assertExit(runGuard(['entry', 'open'], dir), 0);
363
+ assertExit(runGuard(['exit', 'open', '--apply'], dir), 0);
364
+
365
+ assertExit(runState(['skill-load', 'design', 'flow-comet-design', '--prompt', 'flow-kit/prompts/2-design.md'], dir), 0);
366
+ writeFile(dir, '.specs/' + CHANGE_ID + '/DESIGN.md',
367
+ '# DESIGN\n\n- **Change ID**: ' + CHANGE_ID + '\n\n## 0. 技术栈选定\n\nNode.js(ESM)\n\n## 决策清单\n\n- [ ] 循环路由\n');
368
+ assertExit(runState(['record', 'design', '{"summary":"design done"}'], dir), 0);
369
+ assertExit(runGuard(['entry', 'design'], dir), 0);
370
+
371
+ // 负例:前端判据成立(「视觉调性」段在场且未标不适用)而工件缺席 → BLOCKED + 恢复路径
372
+ const blocked = runGuard(['exit', 'design'], dir);
373
+ assertExit(blocked, 1);
374
+ assertOut(blocked, 'BLOCKED: design 出口缺 UI-DESIGN.md');
375
+ assertOut(blocked, '恢复: 补 .specs/' + CHANGE_ID + '/UI-DESIGN.md');
376
+
377
+ // 恢复:补工件 + 真实 skill-load 声明(出口不再自动补写该绑定)→ 出口放行并落状态
378
+ writeFile(dir, '.specs/' + CHANGE_ID + '/UI-DESIGN.md',
379
+ '# UI-DESIGN\n\n## 1. 设计 token\n\n- 主色 `oklch(0.6 0.1 250)`\n');
380
+ const undeclared = runGuard(['exit', 'design'], dir);
381
+ assertExit(undeclared, 1);
382
+ assertOut(undeclared, 'required-skill:design.flow-comet-ui-design');
383
+ assertOut(undeclared, '不再由出口自动补写');
384
+ assertExit(runState(['skill-load', 'design', 'flow-comet-ui-design', '--prompt', 'flow-kit/prompts/2a-ui-design.md'], dir), 0);
385
+ assertExit(runState(['record', 'design',
386
+ '{"summary":"design done with ui-design","completedChecks":["required-skill:design.flow-comet-design","required-skill:design.flow-comet-ui-design"]}'], dir), 0);
387
+ const passed = runGuard(['exit', 'design', '--apply'], dir);
388
+ assertExit(passed, 0);
389
+ assertOut(passed, 'ALL CHECKS PASSED');
390
+ assertNotOut(passed, 'UI-DESIGN: skipped');
391
+
392
+ // AC-10 的「跳过」半(此前只在 L1):第二个 change 走完整真实命令链路到 design 出口——
393
+ // ① fail-open 反向控制:段内自然句子「不适用于暗色主题…」不是结构形态 → 仍判前端、缺件 BLOCKED;
394
+ // ② 结构形态(`适用性` 标签的字段值位)→ 可见跳过 + 命中片段回显,且不要求工件与该声明。
395
+ const nfChange = CHANGE_ID + '-nf';
396
+ const nfChangeFile = path.join(dir, '.specs', nfChange, 'CHANGE.md');
397
+ assertExit(runState(['init', nfChange, '--init-skip'], dir), 0);
398
+ assertExit(runState(['skill-load', 'open', 'flow-comet-change', '--prompt', 'flow-kit/prompts/0-change.md'], dir), 0);
399
+ writeIntakeArtifacts(dir, nfChange);
400
+ fs.appendFileSync(nfChangeFile,
401
+ '\n## 视觉调性(Visual Tone)\n\n不适用于暗色主题,本 change 仅覆盖浅色分支。\n');
402
+ assertExit(runState(['record', 'open', '{"summary":"intake complete"}'], dir), 0);
403
+ assertExit(runGuard(['entry', 'open'], dir), 0);
404
+ assertExit(runGuard(['exit', 'open', '--apply'], dir), 0);
405
+ assertExit(runState(['skill-load', 'design', 'flow-comet-design', '--prompt', 'flow-kit/prompts/2-design.md'], dir), 0);
406
+ writeFile(dir, '.specs/' + nfChange + '/DESIGN.md',
407
+ '# DESIGN\n\n- **Change ID**: ' + nfChange + '\n\n## 0. 技术栈选定\n\nNode.js(ESM)\n\n## 决策清单\n\n- [ ] 循环路由\n');
408
+ assertExit(runState(['record', 'design', '{"summary":"design done"}'], dir), 0);
409
+ assertExit(runGuard(['entry', 'design'], dir), 0);
410
+
411
+ const failOpen = runGuard(['exit', 'design'], dir);
412
+ assertExit(failOpen, 1);
413
+ assertOut(failOpen, 'BLOCKED: design 出口缺 UI-DESIGN.md');
414
+ assertNotOut(failOpen, 'UI-DESIGN: skipped');
415
+
416
+ // 恢复:改段为结构形态(`- 适用性:不适用(…)`)→ 同一 change 出口放行并回显命中片段
417
+ writeFile(dir, '.specs/' + nfChange + '/CHANGE.md',
418
+ '# CHANGE\n\n- **Change ID**: ' + nfChange + '\n\n## Why(为什么做)\n\n变更目标。\n\n'
419
+ + '## 视觉调性(Visual Tone)\n\n- 适用性:不适用(CLI 工具,无用户可见界面)\n');
420
+ const skipped = runGuard(['exit', 'design', '--apply'], dir);
421
+ assertExit(skipped, 0);
422
+ assertOut(skipped, 'UI-DESIGN: skipped(非前端)');
423
+ assertOut(skipped, '命中片段: - 适用性:不适用(CLI 工具,无用户可见界面)');
424
+ assertNotOut(skipped, 'required-skill:design.flow-comet-ui-design');
425
+ assertNotOut(skipped, 'BLOCKED');
426
+ },
427
+ },
428
+
429
+ {
430
+ name: 'M5 evolve 基线跨 change 保留:真实 init 换 change → 基线在场 + 到期提示 + 窗口过滤',
431
+ run: (dir) => {
432
+ const formatStamp = timeUtilsModule.formatLocalTimestamp;
433
+ const dayMs = 24 * 60 * 60 * 1000;
434
+ const dateDaysAgo = (days) => localDate(new Date(Date.now() - days * dayMs));
435
+ // 窗口两侧各一条带 §9 的归档 change;基线落在两者之间(窗口过滤按目录名日期前缀)
436
+ writeFile(dir, '.specs/archive/' + dateDaysAgo(101) + '-before-baseline/DESIGN.md',
437
+ '# DESIGN\n\n## 9. 架构沉淀\n\n- 窗口外条目\n');
438
+ writeFile(dir, '.specs/archive/' + dateDaysAgo(99) + '-after-baseline/DESIGN.md',
439
+ '# DESIGN\n\n## 9. 架构沉淀\n\n- 窗口内条目\n');
440
+ writeFile(dir, '.specs/CONTEXT.md', contextFixtureText());
441
+
442
+ // 跨 change 的持久性只走真实命令:init 首个 change → 唯一写通道落基线 → init 换 change
443
+ assertExit(runState(['init', CHANGE_ID, '--init-skip'], dir), 0);
444
+ const baseline = formatStamp(new Date(Date.now() - 100 * dayMs));
445
+ const setRes = runState(['config', 'set', 'last_evolve_at', baseline], dir);
446
+ assertExit(setRes, 0);
447
+ assertOut(setRes, 'CONFIG: last_evolve_at = ' + baseline);
448
+ assertExit(runState(['init', CHANGE_ID + '-2', '--init-skip'], dir), 0);
449
+ const state = readStateFile(dir);
450
+ assertEqual(state.activeChange, CHANGE_ID + '-2', 'init 后 activeChange');
451
+ assertEqual(state.last_evolve_at, baseline, 'init 跨 change 保留 last_evolve_at');
452
+
453
+ const status = runState(['status'], dir);
454
+ assertExit(status, 0);
455
+ assertOut(status, 'EVOLVE-DUE: 上次架构沉淀 ' + baseline);
456
+ assertOut(status, '超阈值 60 天');
457
+ assertEqual(parseStatusOutput(dir).status, 'running', '提示行在场时 status 的 JSON 块解析');
458
+
459
+ const scan = runSideScript(SIDE_EVOLVE, ['scan', '--root', dir], dir);
460
+ assertExit(scan, 0);
461
+ assertOut(scan, '窗口 起始 = ' + baseline);
462
+ assertOut(scan, '归档 2 个 · 窗口内 1 个 · 含沉淀段 1 个');
463
+ assertOut(scan, 'after-baseline#1');
464
+ assertNotOut(scan, 'before-baseline#');
465
+ assertNotOut(scan, '无基线(首次运行,全量扫描)');
466
+
467
+ // AC-18 的第二个触发因(该时刻之后新增 ≥ 5 个带 §9 的归档 change)——同一条真实 `status` 链路:
468
+ // 基线换成新鲜值(未达天数阈值)→ 其后补 5 个带 §9 的归档 change → 提示改按新增数给出;
469
+ // 取走一个(4 个)→ 回到静默(零噪音)。基线换值仍走 `config set` 唯一写通道。
470
+ const freshBaseline = formatStamp(new Date(Date.now() - 30 * dayMs));
471
+ const setFresh = runState(['config', 'set', 'last_evolve_at', freshBaseline], dir);
472
+ assertExit(setFresh, 0);
473
+ assertOut(setFresh, 'CONFIG: last_evolve_at = ' + freshBaseline);
474
+ const freshStatus = runState(['status'], dir);
475
+ assertExit(freshStatus, 0);
476
+ assertNotOut(freshStatus, 'EVOLVE-DUE'); // 天数阈值未达 + 新基线之后新增 0(既有两条归档早于它)
477
+ const countArchive = (offset) => dateDaysAgo(30 - offset) + '-count-' + offset;
478
+ for (let offset = 1; offset <= 5; offset += 1) {
479
+ writeFile(dir, '.specs/archive/' + countArchive(offset) + '/DESIGN.md',
480
+ '# DESIGN\n\n## 9. 架构沉淀\n\n- 计数触发条目 ' + offset + '\n');
481
+ }
482
+ const byCount = runState(['status'], dir);
483
+ assertExit(byCount, 0);
484
+ assertOut(byCount, 'EVOLVE-DUE: 上次架构沉淀 ' + freshBaseline);
485
+ assertOut(byCount, '其后新增 5 个带 §9 的归档 change,达阈值 5 个');
486
+ assertEqual(parseStatusOutput(dir).status, 'running', '按新增数提示时 status 的 JSON 块解析');
487
+ fs.rmSync(path.join(dir, '.specs', 'archive', countArchive(5)), { recursive: true, force: true });
488
+ assertNotOut(runState(['status'], dir), 'EVOLVE-DUE');
489
+ },
490
+ },
491
+
492
+ {
493
+ name: 'M6 侧命令 CLI 契约真实链路:--root 两形态·--help·未知参数一致 + 损坏 state fail-closed + 协议绑定独占',
494
+ run: (dir) => {
495
+ writeFile(dir, '.specs/archive/2026-10-02-fixture/DESIGN.md',
496
+ '# DESIGN\n\n## 9. 架构沉淀\n\n### 可复用抽象\n\n- 契约夹具条目(真实链路)\n');
497
+ writeFile(dir, '.specs/CONTEXT.md', contextFixtureText());
498
+ writeState(dir, baseState('open'));
499
+
500
+ // ① 三命令等号形与空格形等价(修复前 evolve 的等号形报「未知参数」exit 1)
501
+ const evolveEq = runSideScript(SIDE_EVOLVE, ['scan', '--root=' + dir], dir);
502
+ assertExit(evolveEq, 0);
503
+ assertOut(evolveEq, '2026-10-02-fixture#1');
504
+ const evolveSpace = runSideScript(SIDE_EVOLVE, ['scan', '--root', dir], dir);
505
+ assertExit(evolveSpace, 0);
506
+ assertOut(evolveSpace, 'EVOLVE: 窗口');
507
+ assertExit(runSideScript(SIDE_HEALTH, ['--root=' + dir], dir), 0);
508
+ assertExit(runSideScript(SIDE_CONTEXT_SCAN, ['--root=' + dir], dir), 0);
509
+
510
+ // ② `--help` 三命令一致(各列自身命令形态);未知参数三命令一致(exit 1)
511
+ assertOut(runSideScript(SIDE_EVOLVE, ['--help'], dir), 'evolve.mjs apply');
512
+ assertOut(runSideScript(SIDE_HEALTH, ['-h'], dir), 'health.mjs');
513
+ assertOut(runSideScript(SIDE_CONTEXT_SCAN, ['--help'], dir), 'context-scan.mjs');
514
+ for (const script of [SIDE_EVOLVE, SIDE_HEALTH, SIDE_CONTEXT_SCAN]) {
515
+ const unknown = runSideScript(script, ['--bogus'], dir);
516
+ assertExit(unknown, 1);
517
+ assertOut(unknown, '未知参数: --bogus');
518
+ }
519
+
520
+ // ③ 损坏 state 的真实链路:scan 必须 BLOCKED 且零写入,不再输出「无基线(首次运行,全量扫描)」
521
+ const stateFile = path.join(dir, '.flow-comet', 'flow-comet-state.json');
522
+ const stateText = fs.readFileSync(stateFile, 'utf8');
523
+ fs.writeFileSync(stateFile, stateText.slice(0, Math.floor(stateText.length / 2)), 'utf8');
524
+ const before = treeFingerprint(dir);
525
+ const blocked = runSideScript(SIDE_EVOLVE, ['scan', '--root', dir], dir);
526
+ assertExit(blocked, 1);
527
+ assertOut(blocked, 'BLOCKED');
528
+ assertNotOut(blocked, '无基线(首次运行,全量扫描)');
529
+ if (treeFingerprint(dir) !== before) throw new Error('损坏 state 的 scan 轮有写入(树指纹应逐项一致)');
530
+
531
+ // ④ 协议绑定独占的真实链路:项目内约定副本坏掉 + state.protocolPath 好 → apply 必须成功
532
+ fs.copyFileSync(BUILTIN_PROTOCOL_SOURCE, path.join(dir, 'bound-protocol.json'));
533
+ fs.writeFileSync(path.join(dir, 'reference', 'workflow-protocol.json'),
534
+ '{"schemaVersion": 99, "nodes": []}\n', 'utf8');
535
+ writeState(dir, { ...baseState('open'), protocolPath: 'bound-protocol.json' });
536
+ const applied = runSideScript(SIDE_EVOLVE, ['apply', '2026-10-02-fixture#1', '--root', dir], dir,
537
+ { FLOW_COMET_PROTOCOL: '' });
538
+ assertExit(applied, 0);
539
+ assertOut(applied, 'EVOLVE-OK');
540
+ assertOut(applied, '双落点一致 state = ');
541
+ assertTrue(fs.existsSync(path.join(dir, '.specs', 'evolve', localDate() + '-EVOLVE.md')),
542
+ '协议绑定链路下 EVOLVE 报告未落盘');
543
+ },
544
+ },
545
+
546
+ // M7 扫描时刻双落点真实链路(夹具段行 = 真实生成件形态:取值词元 + 行尾说明)——① 首扫后同刻同
547
+ // 形态即**静默**(整行口径的读侧在此恒亮)② 真漂移必须提示且**类别正确**(不得误报「段内取值
548
+ // 不是合法时间戳」)③ 提示点名的 `context-scan` 跑过后,未刷新路径的 `init` **静默**(收敛可达)
549
+ // ④ 单变量对照:只剥掉行尾说明仍静默(判别条件是词元口径,不是有没有说明)。
550
+ {
551
+ name: 'M7 扫描时刻双落点真实链路:带说明行同刻静默 + 漂移类别正确 + 重扫收敛 + 单变量对照',
552
+ run: (dir) => {
553
+ const parse = timeUtilsModule.parseTimestamp;
554
+ assertExit(runState(['init', CHANGE_ID, '--init-skip'], dir), 0);
555
+ writeFile(dir, '.specs/CONTEXT.md', contextFixtureText());
556
+
557
+ // ① 首扫:双落点建立(段侧与 state 同刻同形态);段行的行尾说明原样保留(写侧只换取值词元)
558
+ const scan = runSideScript(SIDE_CONTEXT_SCAN, ['--root', dir], dir);
559
+ assertExit(scan, 0);
560
+ assertOut(scan, 'CONTEXT-SCAN-DONE');
561
+ const scanned = readStateFile(dir).last_intel_scan;
562
+ assertTrue(readText(dir, '.specs/CONTEXT.md').includes(scanned), '首扫后段侧应与 state 同刻同形态');
563
+ assertTrue(readText(dir, '.specs/CONTEXT.md').includes(INTEL_FIELD_SUFFIX),
564
+ '重扫改写了段行的行尾说明(写侧只应替换取值词元)');
565
+
566
+ // ①' 带说明行的同刻同形态 ⇒ 静默(未刷新路径的 init 不改写既有取值)
567
+ const quietLanded = runState(['init', CHANGE_ID], dir);
568
+ assertExit(quietLanded, 0);
569
+ assertEqual(readStateFile(dir).last_intel_scan, scanned, '未刷新路径应原样保留既有扫描时刻');
570
+ assertNotOut(quietLanded, 'INIT-NOTICE');
571
+
572
+ // ② 真实时间流逝(跨过下一个秒边界)——秒级精度下同一秒内的两次写入取值可能相同,漂移不可判
573
+ waitForNextSecond();
574
+
575
+ // ③ 原症状顺序:`init --init-context` 记录扫描时刻——形态统一(本地时间 + 显式偏移)+ 漂移可见
576
+ // 且类别正确(两侧同为本地+偏移形态、仅时刻不同 ⇒ 「刻与形态均不一致」)
577
+ const reinit = runState(['init', CHANGE_ID, '--init-context'], dir);
578
+ assertExit(reinit, 0);
579
+ assertOut(reinit, 'INIT-DONE');
580
+ const stateAfter = readStateFile(dir).last_intel_scan;
581
+ assertTrue(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{2}:\d{2}$/.test(stateAfter),
582
+ 'init 写入的扫描时刻形态非「本地时间 + 显式偏移」: ' + stateAfter);
583
+ assertTrue(parse(stateAfter) > parse(scanned),
584
+ 'init 写入的扫描时刻应晚于首扫(不得回退): ' + stateAfter + ' vs ' + scanned);
585
+ assertTrue(readText(dir, '.specs/CONTEXT.md').includes(scanned),
586
+ 'init 不应改写 CONTEXT 段(该段行的写通道是 context-scan)');
587
+ assertOut(reinit, 'INIT-NOTICE');
588
+ assertOut(reinit, stateAfter);
589
+ assertOut(reinit, scanned);
590
+ assertOut(reinit, '刻与形态均不一致');
591
+ assertNotOut(reinit, '段内取值不是合法时间戳');
592
+ assertOut(reinit, 'context-scan');
593
+
594
+ // ④ 重扫收敛 → 双落点一致(行尾说明仍在);此后未刷新路径的 init 零提示(不误报)
595
+ const converge = runSideScript(SIDE_CONTEXT_SCAN, ['--root', dir], dir);
596
+ assertExit(converge, 0);
597
+ assertOut(converge, 'CONTEXT-SCAN-DONE');
598
+ const converged = readStateFile(dir).last_intel_scan;
599
+ assertTrue(readText(dir, '.specs/CONTEXT.md').includes(converged), '重扫后双落点应收敛');
600
+ const quiet = runState(['init', CHANGE_ID], dir);
601
+ assertExit(quiet, 0);
602
+ assertEqual(readStateFile(dir).last_intel_scan, converged, '未刷新路径应原样保留既有扫描时刻');
603
+ assertNotOut(quiet, 'INIT-NOTICE');
604
+
605
+ // ⑤ 单变量对照:**只**剥掉段行的行尾说明(取值词元不变、state 不变)→ 仍然静默
606
+ const bare = readText(dir, '.specs/CONTEXT.md').replace(INTEL_FIELD_SUFFIX, '');
607
+ assertTrue(bare !== readText(dir, '.specs/CONTEXT.md'), '单变量对照前提不成立:段行不含夹具行尾说明');
608
+ writeFile(dir, '.specs/CONTEXT.md', bare);
609
+ const quietBare = runState(['init', CHANGE_ID], dir);
610
+ assertExit(quietBare, 0);
611
+ assertNotOut(quietBare, 'INIT-NOTICE');
612
+ },
613
+ },
614
+ ];