flow-comet 1.7.0 → 1.8.0

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 (78) hide show
  1. package/.flow-comet/skills/flow-comet/INSTALLED_VERSION +1 -1
  2. package/.flow-comet/skills/flow-comet/SKILL.md +16 -14
  3. package/.flow-comet/skills/flow-comet/reference/commit-discipline.md +1 -1
  4. package/.flow-comet/skills/flow-comet/reference/decision-points.md +5 -5
  5. package/.flow-comet/skills/flow-comet/reference/dirty-worktree.md +1 -1
  6. package/.flow-comet/skills/flow-comet/reference/entry-detail.md +9 -9
  7. package/.flow-comet/skills/flow-comet/reference/fix-loop.md +4 -4
  8. package/.flow-comet/skills/flow-comet/reference/init-detection.md +1 -1
  9. package/.flow-comet/skills/flow-comet/reference/platform-facts.md +2 -2
  10. package/.flow-comet/skills/flow-comet/reference/post-archive-handoff.md +264 -0
  11. package/.flow-comet/skills/flow-comet/reference/recovery.md +1 -1
  12. package/.flow-comet/skills/flow-comet/reference/replan.md +1 -1
  13. package/.flow-comet/skills/flow-comet/scripts/comet-check.mjs +1 -0
  14. package/.flow-comet/skills/flow-comet/scripts/comet-hook-guard.mjs +270 -30
  15. package/.flow-comet/skills/flow-comet/scripts/items/a.mjs +25 -8
  16. package/.flow-comet/skills/flow-comet/scripts/items/b.mjs +41 -38
  17. package/.flow-comet/skills/flow-comet/scripts/items/c.mjs +11 -9
  18. package/.flow-comet/skills/flow-comet/scripts/items/e.mjs +2 -2
  19. package/.flow-comet/skills/flow-comet/scripts/items/f.mjs +1 -1
  20. package/.flow-comet/skills/flow-comet/scripts/items/h.mjs +112 -53
  21. package/.flow-comet/skills/flow-comet/scripts/items/k.mjs +357 -3
  22. package/.flow-comet/skills/flow-comet/scripts/items/l.mjs +24 -1
  23. package/.flow-comet/skills/flow-comet/scripts/items/m.mjs +2 -2
  24. package/.flow-comet/skills/flow-comet/scripts/items/n.mjs +9 -10
  25. package/.flow-comet/skills/flow-comet/scripts/lib/ac-coverage.mjs +8 -8
  26. package/.flow-comet/skills/flow-comet/scripts/lib/fix-loop-node.mjs +4 -15
  27. package/.flow-comet/skills/flow-comet/scripts/lib/guard-evidence-gates.mjs +79 -107
  28. package/.flow-comet/skills/flow-comet/scripts/lib/guard-gates.mjs +183 -232
  29. package/.flow-comet/skills/flow-comet/scripts/lib/guard-routing.mjs +91 -14
  30. package/.flow-comet/skills/flow-comet/scripts/lib/guard-template-fidelity.mjs +20 -32
  31. package/.flow-comet/skills/flow-comet/scripts/lib/guard-uidesign.mjs +10 -19
  32. package/.flow-comet/skills/flow-comet/scripts/lib/state-commands-admin.mjs +27 -17
  33. package/.flow-comet/skills/flow-comet/scripts/lib/state-commands-flow.mjs +240 -87
  34. package/.flow-comet/skills/flow-comet/scripts/lib/state-commands-recovery.mjs +15 -22
  35. package/.flow-comet/skills/flow-comet/scripts/lib/state-determine.mjs +11 -4
  36. package/.flow-comet/skills/flow-comet/scripts/lib/state-io.mjs +192 -24
  37. package/.flow-comet/skills/flow-comet/scripts/lib/state-skillmarkers.mjs +55 -44
  38. package/.flow-comet/skills/flow-comet/scripts/lib/system-fixtures.mjs +2 -4
  39. package/.flow-comet/skills/flow-comet/scripts/lib/test-assertions.mjs +0 -3
  40. package/.flow-comet/skills/flow-comet/scripts/lib/test-fixtures.mjs +191 -17
  41. package/.flow-comet/skills/flow-comet/scripts/lib/test-helpers.mjs +3 -0
  42. package/.flow-comet/skills/flow-comet/scripts/lib/text-anchor-checks.mjs +23 -5
  43. package/.flow-comet/skills/flow-comet/scripts/lib/wave-projection.mjs +10 -11
  44. package/.flow-comet/skills/flow-comet/scripts/protocol-utils.mjs +40 -3
  45. package/.flow-comet/skills/flow-comet/scripts/route-node.mjs +12 -5
  46. package/.flow-comet/skills/flow-comet/scripts/scenarios/a.mjs +193 -111
  47. package/.flow-comet/skills/flow-comet/scripts/scenarios/b.mjs +314 -57
  48. package/.flow-comet/skills/flow-comet/scripts/scenarios/c.mjs +311 -216
  49. package/.flow-comet/skills/flow-comet/scripts/scenarios/d.mjs +33 -62
  50. package/.flow-comet/skills/flow-comet/scripts/scenarios/e.mjs +188 -91
  51. package/.flow-comet/skills/flow-comet/scripts/scenarios/f.mjs +94 -37
  52. package/.flow-comet/skills/flow-comet/scripts/scenarios/g.mjs +36 -27
  53. package/.flow-comet/skills/flow-comet/scripts/scenarios/h.mjs +285 -9
  54. package/.flow-comet/skills/flow-comet/scripts/scenarios/i.mjs +2 -6
  55. package/.flow-comet/skills/flow-comet/scripts/scenarios/j.mjs +5 -15
  56. package/.flow-comet/skills/flow-comet/scripts/scenarios/k.mjs +6 -5
  57. package/.flow-comet/skills/flow-comet/scripts/scenarios/l.mjs +40 -36
  58. package/.flow-comet/skills/flow-comet/scripts/scenarios/m.mjs +2 -2
  59. package/.flow-comet/skills/flow-comet/scripts/scenarios/n.mjs +346 -25
  60. package/.flow-comet/skills/flow-comet/scripts/state-schema.mjs +0 -2
  61. package/.flow-comet/skills/flow-comet/scripts/workflow-handoff.mjs +41 -54
  62. package/.flow-comet/skills/flow-comet-archive/SKILL.md +33 -11
  63. package/.flow-comet/skills/flow-comet-change/SKILL.md +1 -1
  64. package/.flow-comet/skills/flow-comet-design/SKILL.md +5 -3
  65. package/.flow-comet/skills/flow-comet-dev/SKILL.md +2 -2
  66. package/.flow-comet/skills/flow-comet-execute/SKILL.md +11 -11
  67. package/.flow-comet/skills/flow-comet-integration/SKILL.md +10 -4
  68. package/.flow-comet/skills/flow-comet-plan/GUIDANCE.md +1 -1
  69. package/.flow-comet/skills/flow-comet-plan/SKILL.md +8 -8
  70. package/.flow-comet/skills/flow-comet-review/SKILL.md +8 -8
  71. package/.flow-comet/skills/flow-comet-subagent-execute/GUIDANCE.md +1 -1
  72. package/.flow-comet/skills/flow-comet-subagent-execute/SKILL.md +14 -14
  73. package/.flow-comet/skills/flow-comet-task/SKILL.md +3 -2
  74. package/.flow-comet/skills/flow-comet-ui-design/SKILL.md +2 -2
  75. package/.flow-comet/skills/flow-comet-verify/SKILL.md +1 -1
  76. package/README.md +2 -2
  77. package/package.json +1 -1
  78. package/scripts/dsh-bridge.mjs +238 -21
@@ -38,6 +38,7 @@ import {
38
38
  engineScriptTexts,
39
39
  handoffFor,
40
40
  scriptTreeFiles,
41
+ strictSummary,
41
42
  summaryContent,
42
43
  writeCustomProtocol,
43
44
  writeNodeDeclarationMarkers,
@@ -46,6 +47,7 @@ import {
46
47
  import { singleSourceImportProblems } from '../lib/text-anchor-checks.mjs';
47
48
  import {
48
49
  assertStateBytesUnchanged,
50
+ parseStatusJson,
49
51
  readStateBytes,
50
52
  requireRouteNodeExport,
51
53
  runGuardWithProtocol,
@@ -152,6 +154,8 @@ export const ENTRIES = [
152
154
  {
153
155
  name: '34 subagent-execute exit 通过:handoff 含 completedChecks + 缺证据恢复命令可照抄执行',
154
156
  run: (dir) => {
157
+ writeNodeDeclarationMarkers(dir, 'subagent-execute');
158
+ writeFile(dir, '.specs/' + CHANGE_ID + '/P01-SUMMARY.md', strictSummary('P01'));
155
159
  const st = baseState('subagent-execute');
156
160
  st.evidence['subagent-execute'] = {
157
161
  summary: 'delegated and collected',
@@ -172,6 +176,8 @@ export const ENTRIES = [
172
176
  writeState(dir, stNoEvidence);
173
177
  // 前提:本节点还没有技能加载声明标记(record 的前置门)——报文必须把这道前置条件一并给全。
174
178
  const loadsDir = path.join(dir, '.specs', CHANGE_ID, '.skill-loads');
179
+ // ① 的正例已写入声明标记;② 要测「缺声明」分支,故显式清掉(单轨下声明是出口硬前置)
180
+ fs.rmSync(loadsDir, { recursive: true, force: true });
175
181
  if (fs.existsSync(loadsDir)) {
176
182
  throw new Error('夹具前提不成立:缺声明分支要求 .skill-loads/ 不存在(实际: ' + loadsDir + ')');
177
183
  }
@@ -325,7 +331,7 @@ export const ENTRIES = [
325
331
  + '<task id="P01" status="done" parallel="true"><action>改模板保真门禁</action>'
326
332
  + '<write_files>scripts/lib/guard-template-fidelity.mjs</write_files>'
327
333
  + '<verify>node --check src/p1.mjs</verify></task>\n');
328
- writeFile(dir, '.specs/' + CHANGE_ID + '/P01-SUMMARY.md', summaryContent());
334
+ writeFile(dir, '.specs/' + CHANGE_ID + '/P01-SUMMARY.md', strictSummary('T01'));
329
335
  // ① 出口重算:扫描段没回应命中条目 → 逐条列出编号(旧 change 渐进不阻断)
330
336
  const exitLessons = runGuard(['exit', 'subagent-execute'], dir);
331
337
  assertOut(exitLessons, '未回应命中条目 L-501');
@@ -362,27 +368,21 @@ export const ENTRIES = [
362
368
  + '<verify>node --check src/p3.mjs</verify></task>\n'
363
369
  + '<task id="P04" status="pending" parallel="true"><action>相邻任务</action>'
364
370
  + '<write_files>src/p04.mjs</write_files><verify>node --check src/p04.mjs</verify></task>\n');
371
+ // 单轨:写面不可解析一律 BLOCK(不再有「旧 change 渐进记录」这一侧)
365
372
  const reqNoWriteFiles = runHandoff(['request', 'P03', 'no write files'], dir);
366
- assertExit(reqNoWriteFiles, 0);
367
- assertOut(reqNoWriteFiles, '无可回应条目(任务 P03 未声明 write_files)');
368
- // 同一次 request 的另一半:写面不可解析 → 渐进提示(旧 change 不阻断),且不记录写面
369
- assertOut(reqNoWriteFiles, '委托任务不可解析');
373
+ assertExit(reqNoWriteFiles, 1);
374
+ assertOut(reqNoWriteFiles, 'BLOCKED: 委托任务不可解析');
370
375
  const stNoWrite = JSON.parse(readStateBytes(dir));
371
- const reqNoWrite = stNoWrite.evidence?.['subagent-execute']?.handoffRequests?.P03;
372
- if (!reqNoWrite) {
373
- throw new Error('写面不可解析的 request 仍应照常记录(旧 change 渐进),实际 evidence: '
376
+ if (stNoWrite.evidence?.['subagent-execute']?.handoffRequests?.P03) {
377
+ throw new Error('写面不可解析的 request 不得落库,实际 evidence: '
374
378
  + JSON.stringify(stNoWrite.evidence));
375
379
  }
376
- if (Array.isArray(reqNoWrite.writeFiles) && reqNoWrite.writeFiles.length > 0) {
377
- throw new Error('未声明写面的任务不得记录写面,实际: ' + JSON.stringify(reqNoWrite.writeFiles));
378
- }
379
380
  if (JSON.stringify(stNoWrite).includes('src/p04.mjs')) {
380
- throw new Error('未声明写面的任务把相邻任务的路径记进了 state(跨任务取值): ' + JSON.stringify(reqNoWrite));
381
+ throw new Error('未声明写面的任务把相邻任务的路径记进了 state(跨任务取值): ' + JSON.stringify(stNoWrite));
381
382
  }
382
383
  // 同一份 TASK 在**新 change** 下:写面缺失必须在入口 BLOCK——旧实现借来相邻任务的写面,request
383
384
  // 因而放行,越界要等到提交子集校验才炸。BLOCK 路径 state 字节零改写。
384
385
  const newChangeState = baseState('subagent-execute');
385
- newChangeState.newChange = true;
386
386
  writeState(dir, newChangeState);
387
387
  const bytesBeforeBlock = readStateBytes(dir);
388
388
  const reqNoWriteNew = runHandoff(['request', 'P03', 'no write files new change'], dir);
@@ -479,6 +479,9 @@ export const ENTRIES = [
479
479
  if (fs.existsSync(boundLoadsDir)) {
480
480
  throw new Error('夹具前提不成立:缺声明分支要求 .skill-loads/ 不存在(实际: ' + boundLoadsDir + ')');
481
481
  }
482
+ const boundState = JSON.parse(fs.readFileSync(path.join(dir, '.flow-comet', 'flow-comet-state.json'), 'utf8'));
483
+ boundState.enteredNodes = ['brainstorm'];
484
+ writeState(dir, boundState);
482
485
  const boundBlocked = runGuard(['exit', 'brainstorm'], dir, { FLOW_COMET_PROTOCOL: '' });
483
486
  assertExit(boundBlocked, 1);
484
487
  assertOut(boundBlocked, 'BLOCKED: missing Output Schema evidence: compose.notes.v1.notes-summary');
@@ -520,7 +523,7 @@ export const ENTRIES = [
520
523
  // ④ 第三种来源:--protocol CLI(state 无绑定、环境变量为空)——判据不看来源,命令同样自带该
521
524
  // 协议路径。这正是缺陷形态的原点:用 --protocol 调 guard 时,恢复命令曾不带协议上下文,照抄
522
525
  // 一步就落到 env/默认协议(自定义协议里才有的节点名在那份协议里不存在)。
523
- writeState(dir, composeState({ currentNode: 'brainstorm', evidence: { brainstorm: {} } }));
526
+ writeState(dir, composeState({ currentNode: 'brainstorm', evidence: { brainstorm: {} }, enteredNodes: ['brainstorm'] }));
524
527
  const cliBlocked = runGuard(['exit', 'brainstorm', '--protocol', boundProtocolRel], dir, { FLOW_COMET_PROTOCOL: '' });
525
528
  assertExit(cliBlocked, 1);
526
529
  assertOut(cliBlocked, 'BLOCKED: missing Output Schema evidence: compose.notes.v1.notes-summary');
@@ -739,9 +742,11 @@ export const ENTRIES = [
739
742
  {
740
743
  name: '38 handoff red 先于 green 通过(recordedAt)+ result PREFLIGHT 命令平台化并被真实执行',
741
744
  run: (dir) => {
745
+ writeNodeDeclarationMarkers(dir, 'subagent-execute');
742
746
  writeState(dir, baseState('subagent-execute'));
743
747
  fs.mkdirSync(path.join(dir, '.specs', CHANGE_ID), { recursive: true });
744
748
  const redOnly = '{"redEvidence":{"command":"node --check src/p1.mjs"}}';
749
+ assertExit(runHandoff(['request', 'P01', 'delegate', '--write-files', 'src/p1.mjs'], dir, { FLOW_COMET_PROTOCOL: scenarioProtocolPath(dir) }), 0);
745
750
  const res1 = runHandoff(['result', 'P01', redOnly], dir, {
746
751
  FLOW_COMET_PROTOCOL: scenarioProtocolPath(dir),
747
752
  });
@@ -869,9 +874,11 @@ export const ENTRIES = [
869
874
  {
870
875
  name: '39 handoff BLOCKED:greenEvidence 后同批补录 redEvidence',
871
876
  run: (dir) => {
877
+ writeNodeDeclarationMarkers(dir, 'subagent-execute');
872
878
  writeState(dir, baseState('subagent-execute'));
873
879
  fs.mkdirSync(path.join(dir, '.specs', CHANGE_ID), { recursive: true });
874
880
  const greenOnly = '{"greenEvidence":{"command":"node --check src/p1.mjs"}}';
881
+ assertExit(runHandoff(['request', 'P01', 'delegate', '--write-files', 'src/p1.mjs'], dir, { FLOW_COMET_PROTOCOL: scenarioProtocolPath(dir) }), 0);
875
882
  const res1 = runHandoff(['result', 'P01', greenOnly], dir);
876
883
  assertExit(res1, 0);
877
884
  const backfill = '{"greenEvidence":{"command":"node --check src/p1.mjs"},"redEvidence":{"command":"node --check src/p1.mjs"}}';
@@ -890,7 +897,10 @@ export const ENTRIES = [
890
897
  {
891
898
  name: '40 execute exit 通过:TASK LF→CRLF 行尾变化签名一致',
892
899
  run: (dir) => {
900
+ // 单轨夹具前置:direct 模式(本格测签名判定,不涉及委托归属)+ 声明齐备
901
+ writeNodeDeclarationMarkers(dir, 'execute');
893
902
  const st = baseState('execute');
903
+ st.executionMode = 'direct';
894
904
  st.evidence.execute = { summary: 'executed' };
895
905
  writeState(dir, st);
896
906
  // LF 版本任务集(enter 时记录签名)
@@ -899,8 +909,8 @@ export const ENTRIES = [
899
909
  assertExit(runGuard(['entry', 'execute'], dir), 0);
900
910
  // 同一任务集改写为 CRLF 行尾(仅行尾差异,逻辑内容不变)
901
911
  writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', taskLF.replace(/\n/g, '\r\n'));
902
- writeFile(dir, '.specs/' + CHANGE_ID + '/T01-SUMMARY.md', summaryContent());
903
- writeFile(dir, '.specs/' + CHANGE_ID + '/P01-SUMMARY.md', summaryContent()); // M2: 新 change 强制 done 任务须有 SUMMARY
912
+ writeFile(dir, '.specs/' + CHANGE_ID + '/T01-SUMMARY.md', strictSummary('T01'));
913
+ writeFile(dir, '.specs/' + CHANGE_ID + '/P01-SUMMARY.md', strictSummary('T01')); // M2: 新 change 强制 done 任务须有 SUMMARY
904
914
  const st2 = JSON.parse(fs.readFileSync(path.join(dir, '.flow-comet', 'flow-comet-state.json'), 'utf8'));
905
915
  st2.evidence['subagent-execute'] = { handoffResult: handoffFor(['T01', 'P01']) };
906
916
  writeState(dir, st2);
@@ -923,7 +933,7 @@ export const ENTRIES = [
923
933
  // 逻辑内容变化(T01 action 文本被改),行尾保持 LF 不变
924
934
  const changed = taskLF.replace('实现 T01', '实现 T01 并补充单元测试');
925
935
  writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', changed);
926
- writeFile(dir, '.specs/' + CHANGE_ID + '/T01-SUMMARY.md', summaryContent());
936
+ writeFile(dir, '.specs/' + CHANGE_ID + '/T01-SUMMARY.md', strictSummary('T01'));
927
937
  const st2 = JSON.parse(fs.readFileSync(path.join(dir, '.flow-comet', 'flow-comet-state.json'), 'utf8'));
928
938
  st2.evidence['subagent-execute'] = { handoffResult: handoffFor(['T01', 'P01']) };
929
939
  writeState(dir, st2);
@@ -1018,7 +1028,10 @@ export const ENTRIES = [
1018
1028
  {
1019
1029
  name: '44 execute exit 通过:追加 completed_at 标记属性签名一致',
1020
1030
  run: (dir) => {
1031
+ // 单轨夹具前置:direct 模式 + 声明齐备(同上)
1032
+ writeNodeDeclarationMarkers(dir, 'execute');
1021
1033
  const st = baseState('execute');
1034
+ st.executionMode = 'direct';
1022
1035
  st.evidence.execute = { summary: 'executed' };
1023
1036
  writeState(dir, st);
1024
1037
  const taskLF = '# TASK\n\n' + TASK_DONE + TASK_P1;
@@ -1027,8 +1040,8 @@ export const ENTRIES = [
1027
1040
  // 子代理标记 task done:T01 开标签追加 completed_at 属性(其余逻辑内容不变)
1028
1041
  const marked = taskLF.replace('id="T01"', 'id="T01" completed_at="2026-08-07"');
1029
1042
  writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', marked);
1030
- writeFile(dir, '.specs/' + CHANGE_ID + '/T01-SUMMARY.md', summaryContent());
1031
- writeFile(dir, '.specs/' + CHANGE_ID + '/P01-SUMMARY.md', summaryContent()); // M2: 新 change 强制 done 任务须有 SUMMARY
1043
+ writeFile(dir, '.specs/' + CHANGE_ID + '/T01-SUMMARY.md', strictSummary('T01'));
1044
+ writeFile(dir, '.specs/' + CHANGE_ID + '/P01-SUMMARY.md', strictSummary('T01')); // M2: 新 change 强制 done 任务须有 SUMMARY
1032
1045
  const st2 = JSON.parse(fs.readFileSync(path.join(dir, '.flow-comet', 'flow-comet-state.json'), 'utf8'));
1033
1046
  st2.evidence['subagent-execute'] = { handoffResult: handoffFor(['T01', 'P01']) };
1034
1047
  writeState(dir, st2);
@@ -1054,7 +1067,7 @@ export const ENTRIES = [
1054
1067
  .replace('id="T01"', 'id="T01" completed_at="2026-08-07"')
1055
1068
  .replace('实现 T01', '实现 T01(改)');
1056
1069
  writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', changed);
1057
- writeFile(dir, '.specs/' + CHANGE_ID + '/T01-SUMMARY.md', summaryContent());
1070
+ writeFile(dir, '.specs/' + CHANGE_ID + '/T01-SUMMARY.md', strictSummary('T01'));
1058
1071
  const st2 = JSON.parse(fs.readFileSync(path.join(dir, '.flow-comet', 'flow-comet-state.json'), 'utf8'));
1059
1072
  st2.evidence['subagent-execute'] = { handoffResult: handoffFor(['T01', 'P01']) };
1060
1073
  writeState(dir, st2);
@@ -1117,12 +1130,19 @@ export const ENTRIES = [
1117
1130
  {
1118
1131
  name: '48 execute exit BLOCKED:record 覆盖 handoff(越俎代庖)',
1119
1132
  run: (dir) => {
1133
+ writeNodeDeclarationMarkers(dir, 'execute');
1134
+ writeNodeDeclarationMarkers(dir, 'subagent-execute');
1120
1135
  const st = baseState('execute');
1121
1136
  st.evidence.execute = { summary: 'executed' };
1122
1137
  writeState(dir, st);
1123
1138
  writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', '# TASK\n\n' + TASK_DONE);
1124
- writeFile(dir, '.specs/' + CHANGE_ID + '/T01-SUMMARY.md', summaryContent());
1139
+ writeFile(dir, '.specs/' + CHANGE_ID + '/T01-SUMMARY.md', strictSummary('T01'));
1125
1140
  // ① workflow-handoff result 正确记录 T01 的 Return Contract(含 completedChecks)
1141
+ // 单轨:result 必须有对应 request(未记录的委托不能回传结果)——夹具补同一份事实
1142
+ const pre48 = JSON.parse(fs.readFileSync(path.join(dir, '.flow-comet', 'flow-comet-state.json'), 'utf8'));
1143
+ pre48.evidence['subagent-execute'] = pre48.evidence['subagent-execute'] || {};
1144
+ pre48.evidence['subagent-execute'].handoffRequests = { T01: { description: 'delegate', writeFiles: ['src/t1.mjs'] } };
1145
+ writeState(dir, pre48);
1126
1146
  const res = runHandoff(['result', 'T01', JSON.stringify({
1127
1147
  commitHash: 'abcd1234',
1128
1148
  completedChecks: ['required-skill:subagent-execute.flow-comet-dev'],
@@ -1140,6 +1160,10 @@ export const ENTRIES = [
1140
1160
  throw new Error('record 未整体覆盖 handoffResult(T01 应被覆盖丢失): ' + JSON.stringify(st2.evidence['subagent-execute']));
1141
1161
  }
1142
1162
  // ③ exit execute:T01 done 但 handoff 已被覆盖丢失 → 越俎代庖 BLOCK
1163
+ // (单轨:record 的覆盖写把 request 一起清掉,否则先撞「在飞委托」——被测的是越俎代庖这一门)
1164
+ const preExit2 = JSON.parse(fs.readFileSync(path.join(dir, '.flow-comet', 'flow-comet-state.json'), 'utf8'));
1165
+ delete preExit2.evidence['subagent-execute'].handoffRequests;
1166
+ writeState(dir, preExit2);
1143
1167
  const res2 = runGuard(['exit', 'execute'], dir);
1144
1168
  assertExit(res2, 1);
1145
1169
  assertOut(res2, '越俎代庖');
@@ -1199,7 +1223,6 @@ export const ENTRIES = [
1199
1223
  + ' <depends_on></depends_on>\n'
1200
1224
  + '</task>\n');
1201
1225
  const reqState = baseState('subagent-execute');
1202
- reqState.newChange = true;
1203
1226
  reqState.completedNodes = ['open', 'design', 'plan'];
1204
1227
  reqState.evidence = {
1205
1228
  open: { summary: 'open done' },
@@ -1438,11 +1461,14 @@ export const ENTRIES = [
1438
1461
  },
1439
1462
  },
1440
1463
 
1441
- // ---------- 场景(归档完成态不兜底识别残留目录) ----------
1464
+ // ---------- 场景(归档完成态不兜底识别残留目录 / 身份只由状态判定) ----------
1442
1465
 
1443
- // 59: state 为归档完成态(completed + activeChange null)→ .specs/ 顶层残留目录(含 TASK.md)不被兜底识别
1466
+ // 59: state 为归档完成态(completed + activeChange null)→ .specs/ 顶层残留目录(含 TASK.md)不被兜底识别。
1467
+ // 原位扩展(身份与位置分离):在办只由状态判定(activeChange 非空 ∧ status≠completed),目录位置
1468
+ // 只是存储位置;`.specs/` 扫描是「state 丢失」的恢复通道,**不是第二身份来源**。移入同一场景的理由 =
1469
+ // 判据同一:本场景已是「身份从哪里来」的锚点,位置解析只是同一事实的另一半(不新增场景)。
1444
1470
  {
1445
- name: '59 归档后残留目录不误判为 active',
1471
+ name: '59 归档后残留目录不误判为 active + 身份只由状态判定(目录缺失/移动后)',
1446
1472
  run: (dir) => {
1447
1473
  writeState(dir, composeState({ status: 'completed', activeChange: null, currentNode: null }));
1448
1474
  writeFile(dir, '.specs/stale/CHANGE.md', '# CHANGE\n## Why\nx\n');
@@ -1451,6 +1477,153 @@ export const ENTRIES = [
1451
1477
  assertExit(res, 0);
1452
1478
  assertOut(res, 'no-change');
1453
1479
  assertNotOut(res, 'stale');
1480
+
1481
+ // ---------- 身份与位置(原位扩展 · ① 目录缺失 fail-closed / ② 移动后同一结论 / ③ 推导读归档产物) ----------
1482
+ // 三格按「修复前会得到什么答案」构造:修复前 findActiveChange 把「进行中」绑在**活动目录存在**上,
1483
+ // 活动目录不在就落到 `.specs/` 扫描分支——上一步留下的 .specs/stale(有 TASK.md)因此会接管身份
1484
+ // (把 stale 当成本 change)或干脆返回 null(打 no-change)。两种都是假答案:身份来自 state,位置
1485
+ // 解析不到时必须 fail-closed 点名两处路径,不得假装「没有在办 change」。
1486
+ const MOVED = 'loc-moved';
1487
+ const ARCHIVE_REL = '.specs/archive/2026-11-05-' + MOVED;
1488
+ const completedAll = ['open', 'design', 'plan', 'execute', 'subagent-execute', 'review', 'verify'];
1489
+ const locationState = (changeName) => {
1490
+ const evidence = {};
1491
+ for (const nodeId of completedAll) evidence[nodeId] = { summary: nodeId + ' done' };
1492
+ return {
1493
+ activeChange: changeName,
1494
+ currentNode: 'archive',
1495
+ completedNodes: completedAll.slice(),
1496
+ evidence,
1497
+ verifyFailures: 0,
1498
+ executionMode: 'subagent',
1499
+ directOverride: false,
1500
+ enteredNodes: completedAll.concat('archive'),
1501
+ status: 'running',
1502
+ createdAt: '2026-11-01T00:00:00Z',
1503
+ branchMode: false,
1504
+ enablePrReview: false,
1505
+ branchPrefix: 'change/',
1506
+ };
1507
+ };
1508
+ // ① running-orphan:两处目录都没有(活动目录 + 归档目录)→ 三命令 fail-closed,且不得假装 no-change。
1509
+ // 诱饵 .specs/stale 仍在场:state 有在办 change 时扫描结果不得接管身份(否则 status 报 stale)。
1510
+ writeState(dir, locationState('loc-orphan'));
1511
+ const orphanBytes = readStateBytes(dir);
1512
+ const orphanStatus = runStateWithProtocol(dir, ['status']);
1513
+ assertExit(orphanStatus, 1);
1514
+ assertOut(orphanStatus, 'BLOCKED: change 目录缺失');
1515
+ assertOut(orphanStatus, '.specs/loc-orphan');
1516
+ assertOut(orphanStatus, '.specs/archive/');
1517
+ assertNotOut(orphanStatus, 'no-change');
1518
+ assertNotOut(orphanStatus, '"change": "stale"');
1519
+ const orphanNext = runStateWithProtocol(dir, ['next']);
1520
+ assertExit(orphanNext, 1);
1521
+ assertOut(orphanNext, 'BLOCKED: change 目录缺失');
1522
+ assertNotOut(orphanNext, 'NEXT: done');
1523
+ assertNotOut(orphanNext, 'NODE: ');
1524
+ const orphanRecord = runStateWithProtocol(dir, ['record', 'archive', '{"summary":"orphan"}']);
1525
+ assertExit(orphanRecord, 1);
1526
+ assertOut(orphanRecord, 'BLOCKED: change 目录缺失');
1527
+ assertStateBytesUnchanged(dir, orphanBytes, '目录缺失时 record 不得改写 state');
1528
+
1529
+ // ② running-moved:同一份 state + 同一份完整产物集,先跑「移动前」再跑「移动后」——两条命令在
1530
+ // 两种位置下必须给出**同一结论**(在办 / archive 节点 / 下一步 exit),差别只在落点路径。
1531
+ const artifacts = {
1532
+ 'CHANGE.md': '# CHANGE\n\n## Why\n\nx\n',
1533
+ 'REQUIREMENT.md': '# REQUIREMENT\n\n## 用户故事\n\nx\n\n## 验收准则(AC)\n\n- Given x When y Then z\n',
1534
+ 'DESIGN.md': '# DESIGN\n\n## 决策清单\n\n- 单轨\n',
1535
+ 'TASK.md': '# TASK\n\n' + TASK_DONE,
1536
+ 'T01-SUMMARY.md': '# SUMMARY: T01 - 夹具\n\n## 做了什么\n\nx\n',
1537
+ 'REVIEW.md': '# REVIEW\n\n## 汇总\n\n- 通过\n',
1538
+ 'TEST.md': '# TEST\n\n## 验证命令\n\n```bash\necho ok\n```\n',
1539
+ 'UAT.md': '# UAT\n\n## 验收结果\n\n- 通过\n',
1540
+ 'KNOWN-ISSUES.md': '# KNOWN-ISSUES\n\n无遗留问题\n',
1541
+ };
1542
+ for (const [name, content] of Object.entries(artifacts)) {
1543
+ writeFile(dir, '.specs/' + MOVED + '/' + name, content);
1544
+ }
1545
+ // 归档节点的技能加载声明(随目录一起搬家——真实归档动作下标记天然跟随)
1546
+ writeNodeDeclarationMarkers(dir, 'archive', { changeId: MOVED });
1547
+ writeState(dir, locationState(MOVED));
1548
+ const beforeStatus = runStateWithProtocol(dir, ['status']);
1549
+ assertExit(beforeStatus, 0);
1550
+ const beforeJson = parseStatusJson(beforeStatus);
1551
+ assertEqual(beforeJson.status, 'running', '移动前 status.status');
1552
+ assertEqual(beforeJson.change, MOVED, '移动前 status.change');
1553
+ assertEqual(beforeJson.currentNode, 'archive', '移动前 status.currentNode(产物推导)');
1554
+ assertEqual(beforeJson.routeNode, 'archive', '移动前 status.routeNode');
1555
+ assertEqual(beforeJson.artifactRoot, '.specs/' + MOVED, '移动前 artifactRoot = 活动目录');
1556
+ const beforeNext = runStateWithProtocol(dir, ['next']);
1557
+ assertExit(beforeNext, 0);
1558
+ assertTrue(/^NODE: archive$/m.test(beforeNext.output), '移动前 next 应报 NODE: archive\n' + beforeNext.output);
1559
+ // 真实归档动作:目录整体搬进 .specs/archive/<日期>-<change-id>/
1560
+ fs.mkdirSync(path.join(dir, '.specs', 'archive'), { recursive: true });
1561
+ fs.renameSync(path.join(dir, '.specs', MOVED), path.join(dir, '.specs', 'archive', '2026-11-05-' + MOVED));
1562
+ const movedStatus = runStateWithProtocol(dir, ['status']);
1563
+ assertExit(movedStatus, 0);
1564
+ const movedJson = parseStatusJson(movedStatus);
1565
+ assertEqual(movedJson.status, 'running', '移动后 status 仍报进行中(不得回落到 no-change)');
1566
+ assertEqual(movedJson.change, MOVED, '移动后的身份 = state.activeChange');
1567
+ // ③ 节点推导读归档产物:产物随目录搬进归档后仍被认到 ⇒ 推导落在 archive;读不到会回退 open。
1568
+ assertEqual(movedJson.currentNode, 'archive', '移动后 currentNode 必须按归档产物推导(不得回退 open)');
1569
+ assertEqual(movedJson.routeNode, 'archive', '移动后 routeNode(= next 的 NODE 行)');
1570
+ assertEqual(movedJson.artifactRoot, ARCHIVE_REL, '移动后 artifactRoot = 解析到的归档目录');
1571
+ assertNotOut(movedStatus, 'no-change');
1572
+ assertOut(movedStatus, 'ROUTE: ');
1573
+ const movedNext = runStateWithProtocol(dir, ['next']);
1574
+ assertExit(movedNext, 0);
1575
+ assertTrue(/^NODE: archive$/m.test(movedNext.output), '移动后 next 应报 NODE: archive(不推 open)\n' + movedNext.output);
1576
+ assertNotOut(movedNext, 'NEXT: done');
1577
+ assertNotOut(movedNext, 'NODE: open');
1578
+ // record 的尾部节点视图与 next / status 同源:移动后不得打印 NODE: open(那是「归档产物没被认到」的
1579
+ // 典型假答案),证据照常写入 state,且不得重建活动目录(位置只读)。
1580
+ const movedRecord = runStateWithProtocol(dir, ['record', 'archive', '{"summary":"archived"}']);
1581
+ assertExit(movedRecord, 0);
1582
+ assertOut(movedRecord, 'EVIDENCE: archive');
1583
+ assertTrue(/^NODE: archive$/m.test(movedRecord.output), '移动后 record 的尾部视图不得回退 open\n' + movedRecord.output);
1584
+ if (fs.existsSync(path.join(dir, '.specs', MOVED))) {
1585
+ throw new Error('移动后 record 重建了活动目录: .specs/' + MOVED + '/');
1586
+ }
1587
+ if (!fs.existsSync(path.join(dir, '.specs', 'archive', '2026-11-05-' + MOVED))) {
1588
+ throw new Error('移动后归档目录应仍在: ' + ARCHIVE_REL);
1589
+ }
1590
+
1591
+ // ---------- ④ 节点顺序门禁的恢复句同样按目录在哪分叉(原位扩展:同一分叉的第四处消费方) ----------
1592
+ // 第四次出现的同一问题:这条 BLOCK 报告的是「该节点从未 exit」,出口侧(guard-gates /
1593
+ // guard-evidence-gates)早已按目录在哪换一种说法,next 侧却还在固定推销 advance / select。
1594
+ // 归档态下 select 要求活动目录在场、advance 的产物推导读活动路径——两条都走不通,报文只能给
1595
+ // 可执行的那一步(把目录移回活动位置)。活动态对照必须**逐字不变**(同一句话仍给 advance /
1596
+ // select),否则「归档态收敛」是用活动态退化换来的。
1597
+ const ORDER = 'loc-order';
1598
+ const orderState = () => {
1599
+ const state = locationState(ORDER);
1600
+ // 顺序门禁的触发条件 = currentNode 未 exit(不在 completedNodes)且无任何证据。已完成节点
1601
+ // 的证据必须在场,否则 lastEvidence 校验不通过、判定会落到别的分支。
1602
+ state.currentNode = 'execute';
1603
+ state.completedNodes = ['open', 'design'];
1604
+ state.evidence = { open: { summary: 'open done' }, design: { summary: 'design done' } };
1605
+ state.enteredNodes = ['open', 'design'];
1606
+ return state;
1607
+ };
1608
+ // 活动态对照:活动目录在场 → 恢复句仍是 advance / select
1609
+ fs.mkdirSync(path.join(dir, '.specs', ORDER), { recursive: true });
1610
+ writeState(dir, orderState());
1611
+ const activeOrderNext = runStateWithProtocol(dir, ['next']);
1612
+ assertExit(activeOrderNext, 1);
1613
+ assertOut(activeOrderNext, 'BLOCKED: 疑似未 exit 节点 execute');
1614
+ assertOut(activeOrderNext, 'advance');
1615
+ assertOut(activeOrderNext, 'select(切换 change)');
1616
+ assertNotOut(activeOrderNext, '移回活动位置');
1617
+ // 归档态:目录真实搬进归档 → 恢复句换成唯一可执行的那一步,不再推荐 advance / select
1618
+ fs.renameSync(path.join(dir, '.specs', ORDER), path.join(dir, '.specs', 'archive', '2026-11-06-' + ORDER));
1619
+ writeState(dir, orderState());
1620
+ const archivedOrderNext = runStateWithProtocol(dir, ['next']);
1621
+ assertExit(archivedOrderNext, 1);
1622
+ assertOut(archivedOrderNext, 'BLOCKED: 疑似未 exit 节点 execute');
1623
+ assertOut(archivedOrderNext, '移回活动位置');
1624
+ assertOut(archivedOrderNext, '.specs/' + ORDER + '/');
1625
+ assertNotOut(archivedOrderNext, 'advance');
1626
+ assertNotOut(archivedOrderNext, 'select(切换 change)');
1454
1627
  },
1455
1628
  },
1456
1629
 
@@ -1729,10 +1902,10 @@ export const ENTRIES = [
1729
1902
 
1730
1903
  // ---------- 场景(builtin 降级须含缓存尝试证据) ----------
1731
1904
 
1732
- // 74: builtin-quickcheck 声明 + 不可用原因但无缓存尝试证据 → BROOKS-LINT WARN
1733
- // (:防「未尝试 Read 插件缓存协议文件」的偷懒降级——修复前不校验 = RED)
1905
+ // 74: builtin-quickcheck 声明 + 不可用原因但无缓存尝试证据 → BLOCKED
1906
+ // (防「未尝试 Read 插件缓存协议文件」的偷懒降级——判据为 BLOCK,无渐进侧)
1734
1907
  {
1735
- name: '74 builtin 无缓存尝试证据 → WARN',
1908
+ name: '74 builtin 无缓存尝试证据 → BLOCKED',
1736
1909
  run: (dir) => {
1737
1910
  const st = baseState('execute');
1738
1911
  st.evidence.execute = { summary: 'executed' };
@@ -1743,8 +1916,9 @@ export const ENTRIES = [
1743
1916
  method: '## 自检方法\n\nbuiltin-quickcheck — brooks-lint 不可用(Skill 仅返回占位,插件执行体未加载),按协议降级内置 R1~R6 快查',
1744
1917
  }));
1745
1918
  const res = runGuard(['exit', 'execute'], dir);
1746
- assertExit(res, 0);
1747
- assertOut(res, 'BROOKS-LINT WARN');
1919
+ assertExit(res, 1);
1920
+ assertOut(res, 'BLOCKED');
1921
+ assertOut(res, '缓存尝试证据');
1748
1922
  },
1749
1923
  },
1750
1924
 
@@ -1753,6 +1927,7 @@ export const ENTRIES = [
1753
1927
  {
1754
1928
  name: '75 cache-brooks 声明 → 放行',
1755
1929
  run: (dir) => {
1930
+ writeNodeDeclarationMarkers(dir, 'execute');
1756
1931
  const st = baseState('execute');
1757
1932
  st.evidence.execute = { summary: 'executed' };
1758
1933
  st.evidence['subagent-execute'] = { handoffResult: handoffFor(['T01']) };
@@ -1774,6 +1949,7 @@ export const ENTRIES = [
1774
1949
  {
1775
1950
  name: '76 builtin 含缓存尝试证据 → 无 WARN',
1776
1951
  run: (dir) => {
1952
+ writeNodeDeclarationMarkers(dir, 'execute');
1777
1953
  const st = baseState('execute');
1778
1954
  st.evidence.execute = { summary: 'executed' };
1779
1955
  st.evidence['subagent-execute'] = { handoffResult: handoffFor(['T01']) };
@@ -1814,6 +1990,7 @@ export const ENTRIES = [
1814
1990
  {
1815
1991
  name: '78 路由诊断:有 pending 无可委托并行 WARN 在场 / 无可解析 pending 静默',
1816
1992
  run: (dir) => {
1993
+ writeNodeDeclarationMarkers(dir, 'plan');
1817
1994
  const st = baseState('plan');
1818
1995
  st.completedNodes = ['open', 'design'];
1819
1996
  st.evidence.plan = { summary: 'executed' };
@@ -1861,6 +2038,7 @@ export const ENTRIES = [
1861
2038
  {
1862
2039
  name: '80 handoff result 契约校验:无效 commitHash → ERROR;非对象与畸形形状写入前拒绝',
1863
2040
  run: (dir) => {
2041
+ writeNodeDeclarationMarkers(dir, 'subagent-execute');
1864
2042
  writeState(dir, baseState('subagent-execute'));
1865
2043
  fs.mkdirSync(path.join(dir, '.specs', CHANGE_ID), { recursive: true });
1866
2044
  execFileSync('git', ['init', '-q'], { cwd: dir });
@@ -1873,6 +2051,7 @@ export const ENTRIES = [
1873
2051
  completedChecks: ['required-skill:subagent-execute.flow-comet-dev'],
1874
2052
  riskSignals: ['none'],
1875
2053
  });
2054
+ assertExit(runHandoff(['request', 'T01', 'delegate', '--write-files', 'src/t1.mjs'], dir, { FLOW_COMET_PROTOCOL: scenarioProtocolPath(dir) }), 0);
1876
2055
  const res = runHandoff(['result', 'T01', payload], dir);
1877
2056
  assertExit(res, 0);
1878
2057
  assertOut(res, 'HANDOFF ERROR: commitHash 无效或 git show 失败');
@@ -1967,7 +2146,6 @@ export const ENTRIES = [
1967
2146
  execFileSync('git', ['-c', 'user.email=t@t', '-c', 'user.name=t', 'commit', '-q', '-m', 'summary only'], { cwd: dir });
1968
2147
  const summaryHash = execFileSync('git', ['rev-parse', 'HEAD'], { cwd: dir, encoding: 'utf8' }).trim();
1969
2148
  const ledgerState = JSON.parse(readStateBytes(dir));
1970
- ledgerState.newChange = true;
1971
2149
  const ledgerRequests = ledgerState.evidence['subagent-execute'].handoffRequests || {};
1972
2150
  if (Object.prototype.hasOwnProperty.call(ledgerRequests, 'T06')) {
1973
2151
  throw new Error('夹具前提不成立:T06 不应已有 request(本段构造的是缺 request 的 result)');
@@ -2001,18 +2179,14 @@ export const ENTRIES = [
2001
2179
  assertTrue(typeof requestRecoveryLine === 'string',
2002
2180
  '缺 request 的恢复段必须给出可照抄的 request 命令(行首 = node + 引号脚本路径):\n' + missingRequestOutput);
2003
2181
  assertRecoveryCommandLines(missingRequestRecovery, [requestRecoveryLine], '缺 request 的 result 恢复段');
2004
- // 旧 change 同样的输入只 WARN(渐进,不阻断既有流程)
2182
+ // 同一输入(无任何新旧标记字段)→ 同判 BLOCKED(单轨:无渐进放行侧)
2005
2183
  const legacyLedger = JSON.parse(ledgerBytes);
2006
- delete legacyLedger.newChange;
2007
2184
  writeState(dir, legacyLedger);
2008
2185
  const legacy = runHandoff(['result', 'T06', ledgerPayload('T06', summaryHash)], dir);
2009
- assertExit(legacy, 0);
2010
- assertOut(legacy, 'HANDOFF WARN: T06');
2011
- assertOut(legacy, '没有对应的委托 request');
2012
- assertOut(legacy, 'HANDOFF RESULT: T06');
2186
+ assertExit(legacy, 1);
2187
+ assertOut(legacy, 'BLOCKED: 任务 T06 的 result 没有对应的委托 request');
2013
2188
  // 有 request 的 result 照常通过(零提交语义不变:noCommit 请求 + 无 commitHash 契约)
2014
2189
  const withRequest = JSON.parse(readStateBytes(dir));
2015
- withRequest.newChange = true;
2016
2190
  withRequest.evidence['subagent-execute'].handoffRequests = {
2017
2191
  ...withRequest.evidence['subagent-execute'].handoffRequests,
2018
2192
  T08: { description: 'delegated', noCommit: true },
@@ -2031,7 +2205,6 @@ export const ENTRIES = [
2031
2205
  + '<write_files>src/t06.mjs</write_files><verify>node --check src/t06.mjs</verify>'
2032
2206
  + '<depends_on></depends_on></task>\n');
2033
2207
  const execState = baseState('subagent-execute');
2034
- execState.newChange = true;
2035
2208
  execState.evidence['subagent-execute'] = { summary: 'delegated' };
2036
2209
  writeState(dir, execState);
2037
2210
  writeNodeDeclarationMarkers(dir, 'subagent-execute');
@@ -2074,7 +2247,6 @@ export const ENTRIES = [
2074
2247
  + taskWithWriteFiles('T09', ['allowed.js', 'rogue.js'])
2075
2248
  + taskWithWriteFiles('T10', ['allowed.js']));
2076
2249
  const replanState = baseState('subagent-execute');
2077
- replanState.newChange = true;
2078
2250
  replanState.evidence['subagent-execute'] = {
2079
2251
  handoffRequests: {
2080
2252
  T09: { description: 'replan 扩写面前的快照', writeFiles: ['allowed.js'] },
@@ -2116,34 +2288,33 @@ export const ENTRIES = [
2116
2288
  assertOut(genuineOverrun, 'BLOCKED: 提交文件超出 writeFiles 范围: stray.js');
2117
2289
  assertOut(genuineOverrun, '恢复: 回退越界文件或扩展 write_files');
2118
2290
  assertNotOut(genuineOverrun, staleSnapshotFact);
2119
- // ③ 判定语义不变:同一份旧快照在旧 change 上只 WARN(诊断行随报文出现,结果照常落库)
2291
+ // ③ 同一份旧快照(无任何新旧标记字段)→ 同判 BLOCKED(单轨:无渐进放行侧)
2120
2292
  const legacySnapshot = JSON.parse(readStateBytes(dir));
2121
- delete legacySnapshot.newChange;
2122
2293
  writeState(dir, legacySnapshot);
2123
2294
  const legacyWarn = runHandoff(['result', 'T09', boundaryPayload('T09', replannedHash)], dir);
2124
- assertExit(legacyWarn, 0);
2125
- assertOut(legacyWarn, 'HANDOFF WARN: 提交文件超出 writeFiles 范围: rogue.js');
2295
+ assertExit(legacyWarn, 1);
2296
+ assertOut(legacyWarn, 'BLOCKED: 提交文件超出 writeFiles 范围: rogue.js');
2126
2297
  assertOut(legacyWarn, staleSnapshotCause);
2127
- assertOut(legacyWarn, 'HANDOFF RESULT: T09');
2128
2298
  },
2129
2299
  },
2130
2300
 
2131
- // 81: entry/exit WARN COUNT 汇总行——构造 BROOKS-LINT WARN → exit 输出 WARN COUNT
2132
- // ( F:可观测性——修复前无汇总行 = RED)
2301
+ // 81: entry/exit WARN COUNT 汇总行——构造 SIGNATURE-ALGO WARN(跨算法版本签名,提示级)→ exit 输出
2302
+ // WARN COUNT(可观测性:提示级判据不静默)
2133
2303
  {
2134
2304
  name: '81 exit 输出 WARN COUNT 汇总',
2135
2305
  run: (dir) => {
2306
+ writeNodeDeclarationMarkers(dir, 'execute');
2136
2307
  const st = baseState('execute');
2137
2308
  st.evidence.execute = { summary: 'executed' };
2138
2309
  st.evidence['subagent-execute'] = { handoffResult: handoffFor(['T01']) };
2310
+ // 跨算法版本的签名:值不可比 → SIGNATURE-ALGO WARN(仍为提示级),用来驱动 WARN COUNT 汇总行
2311
+ st.taskHash = 'v0:' + '0'.repeat(64);
2139
2312
  writeState(dir, st);
2140
2313
  writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', '# TASK\n\n' + TASK_DONE);
2141
- writeFile(dir, '.specs/' + CHANGE_ID + '/T01-SUMMARY.md', summaryContent({
2142
- method: '## 自检方法\n\nbuiltin-quickcheck — brooks-lint 不可用(Skill 仅返回占位,插件执行体未加载),按协议降级内置 R1~R6 快查',
2143
- }));
2314
+ writeFile(dir, '.specs/' + CHANGE_ID + '/T01-SUMMARY.md', strictSummary('T01'));
2144
2315
  const res = runGuardWithProtocol(dir, ['exit', 'execute']);
2145
2316
  assertExit(res, 0);
2146
- assertOut(res, 'BROOKS-LINT WARN');
2317
+ assertOut(res, 'SIGNATURE-ALGO WARN');
2147
2318
  assertOut(res, 'WARN COUNT:');
2148
2319
  },
2149
2320
  },
@@ -2185,7 +2356,7 @@ export const ENTRIES = [
2185
2356
  runStateWithProtocol(dir, ['init', CHANGE_ID, '--init-skip']);
2186
2357
  const st1 = JSON.parse(fs.readFileSync(path.join(dir, '.flow-comet', 'flow-comet-state.json'), 'utf8'));
2187
2358
  if (st1.ai_context_doc !== 'none') throw new Error('ai_context_doc 应为 none');
2188
- const res2 = runStateWithProtocol(dir, ['init', CHANGE_ID + '-2']);
2359
+ const res2 = runStateWithProtocol(dir, ['init', CHANGE_ID + '-2', '--replace', CHANGE_ID, '--reason', '验证跳过记忆跨 change 生效']);
2189
2360
  if (res2.output.includes('INIT-NEEDED') || res2.output.includes('INIT-HINT')) throw new Error('下次 init 不应再提示');
2190
2361
  },
2191
2362
  },
@@ -2284,7 +2455,7 @@ export const ENTRIES = [
2284
2455
  if (st.last_intel_scan) throw new Error('校验失败不应写 last_intel_scan');
2285
2456
  // ② 段名变体(含正文提及)不满足必填段
2286
2457
  writeFile(dir, '.specs/CONTEXT.md', '# CONTEXT\n## 项目概要\nx\n## 技术栈补充\nx\n## 域语言说明\n| 术语 | 定义 |\n|---|---|\n| 例 | 定义 |\n## 已锁决策说明\n- [2026-08-01] 决策一\n## 默认偏好补充\nx\n## 既有抽象索引附录\nx\n## intel-scan 元数据附录\n- **last_intel_scan**: x\n- **scanner**: x\n- **下次重扫建议**: x\n正文提及 域语言 与 默认偏好 与 既有抽象索引(文本非标题)。\n');
2287
- res = runStateWithProtocol(dir, ['init', CHANGE_ID + '-2', '--init-context']);
2458
+ res = runStateWithProtocol(dir, ['init', CHANGE_ID + '-2', '--init-context', '--replace', CHANGE_ID, '--reason', '验证 CONTEXT 校验跨 change 复跑']);
2288
2459
  assertExit(res, 0);
2289
2460
  assertOut(res, 'INIT-VALIDATE-FAILED');
2290
2461
  st = JSON.parse(fs.readFileSync(path.join(dir, '.flow-comet', 'flow-comet-state.json'), 'utf8'));
@@ -2306,7 +2477,7 @@ export const ENTRIES = [
2306
2477
  '~~~text', '## 默认偏好', '~~~',
2307
2478
  '',
2308
2479
  ].join('\n'));
2309
- res = runStateWithProtocol(dir, ['init', CHANGE_ID + '-3', '--init-context']);
2480
+ res = runStateWithProtocol(dir, ['init', CHANGE_ID + '-3', '--init-context', '--replace', CHANGE_ID + '-2', '--reason', '验证围栏段名判定跨 change 复跑']);
2310
2481
  assertExit(res, 0);
2311
2482
  assertOut(res, 'INIT-VALIDATE-FAILED');
2312
2483
  st = JSON.parse(fs.readFileSync(path.join(dir, '.flow-comet', 'flow-comet-state.json'), 'utf8'));
@@ -2358,16 +2529,101 @@ export const ENTRIES = [
2358
2529
  },
2359
2530
  },
2360
2531
 
2361
- // 95: init 同 id 重跑(.specs/<id>/ 已存在)→ WARN 防护输出且不阻断(F)
2532
+ // 95: init 与既有 change 的关系——同 id 重跑仍是 WARN 不阻断;**另一个 change 在途**时
2533
+ // 默认阻断(state 字节零改写 + 两条可照抄的出路);只有 --replace <在途 change> --reason <非空
2534
+ // 原因> 才放行,放行前把旧 state **按原始字节**快照到旧 change 目录的 recovery/(BOM / CRLF 一律
2535
+ // 不改)并写同前缀 .md 记录;RECOVERY 块给出快照路径与回滚命令,回滚命令照抄真执行后旧状态逐
2536
+ // 字节恢复。反向构造:闸门缺席(实现退化为直接覆盖)时第一条阻断断言必红。
2362
2537
  {
2363
- name: '95 init 同 id 重跑 → WARN 防护不阻断',
2538
+ name: '95 init 与既有 change:同 id 重跑不阻断 / 在途 change 默认阻断 / --replace 留档与回滚可执行',
2364
2539
  run: (dir) => {
2540
+ const stateFile = path.join(dir, '.flow-comet', 'flow-comet-state.json');
2541
+ const recoveryDirOf = (changeName) => path.join(dir, '.specs', changeName, 'recovery');
2542
+ // RECOVERY 块按行标签取值(快照 / 记录 / 回滚)——取值形态就是执行者要照抄的文本
2543
+ const recoveryLine = (res, label) => {
2544
+ const line = res.output.split('\n').find((row) => row.startsWith('RECOVERY: ' + label + ' '));
2545
+ if (!line) throw new Error('输出缺少 RECOVERY: ' + label + ' 行\n实际输出:\n' + res.output);
2546
+ return line.slice(('RECOVERY: ' + label + ' ').length).trim();
2547
+ };
2548
+ const runRootPath = (displayPath) => path.join(dir, ...displayPath.split('/'));
2549
+
2365
2550
  writeFile(dir, 'package.json', '{"name":"x"}');
2366
- runStateWithProtocol(dir, ['init', CHANGE_ID]);
2551
+ // ① 正常 init(无在途 change):零留档、零新参数要求——输出与既有断言一致
2552
+ const first = runStateWithProtocol(dir, ['init', CHANGE_ID]);
2553
+ assertExit(first, 0);
2554
+ assertOut(first, 'Initialized: ' + CHANGE_ID);
2555
+ assertNotOut(first, 'RECOVERY');
2556
+ assertTrue(!fs.existsSync(recoveryDirOf(CHANGE_ID)), '无在途 change 的正常 init 不应创建 recovery/');
2557
+
2558
+ // ② 同 id 重跑:既有 WARN 防护不阻断(行为不变,也不留档)
2367
2559
  const res = runStateWithProtocol(dir, ['init', CHANGE_ID]);
2368
2560
  assertExit(res, 0);
2369
2561
  assertOut(res, 'WARN: change ' + CHANGE_ID + ' 已存在');
2370
2562
  assertOut(res, '重置节点状态');
2563
+ assertNotOut(res, 'BLOCKED');
2564
+ assertTrue(!fs.existsSync(recoveryDirOf(CHANGE_ID)), '同 id 重跑不应留档');
2565
+
2566
+ // ③ 另一个 change 在途 → 默认阻断:非零退出 + 点名在途 change + 两条出路;state 字节零改写
2567
+ const blockedBytes = readStateBytes(dir);
2568
+ const blocked = runStateWithProtocol(dir, ['init', 'other-change']);
2569
+ assertExit(blocked, 1);
2570
+ assertOut(blocked, 'BLOCKED: 在途 change "' + CHANGE_ID + '" 尚未完成');
2571
+ assertOut(blocked, '--replace ' + CHANGE_ID);
2572
+ assertOut(blocked, '--reason');
2573
+ assertOut(blocked, 'workflow-state.mjs" status');
2574
+ assertStateBytesUnchanged(dir, blockedBytes, '在途 change + init 默认阻断');
2575
+ assertTrue(!fs.existsSync(recoveryDirOf('other-change')), '阻断路径不得创建留档');
2576
+
2577
+ // ④ 显式放行的形态约束(缺 --reason / 空白 reason / --replace 名不符 / 空 --replace 值):
2578
+ // 一律 BLOCK 且零改写、零留档
2579
+ const badShapes = [
2580
+ { args: ['init', 'other-change', '--replace', CHANGE_ID], label: '缺 --reason' },
2581
+ { args: ['init', 'other-change', '--replace', CHANGE_ID, '--reason', ' '], label: '空白 --reason' },
2582
+ { args: ['init', 'other-change', '--replace', 'not-the-active-one', '--reason', 'x'], label: '--replace 名不符' },
2583
+ { args: ['init', 'other-change', '--replace'], label: '空 --replace 值' },
2584
+ { args: ['init', 'other-change', '--replace', CHANGE_ID, '--reason', '--init-skip'], label: '--reason 的值位是另一个选项' },
2585
+ ];
2586
+ for (const shape of badShapes) {
2587
+ const bad = runStateWithProtocol(dir, shape.args);
2588
+ assertExit(bad, 1);
2589
+ assertOut(bad, 'BLOCKED');
2590
+ assertStateBytesUnchanged(dir, blockedBytes, '放行形态不合法(' + shape.label + ')');
2591
+ assertTrue(!fs.existsSync(recoveryDirOf(CHANGE_ID)), '形态不合法不得留档(' + shape.label + ')');
2592
+ }
2593
+
2594
+ // ⑤ 旧状态换成可辨识形态(BOM + CRLF):逐字节判据必须能看见这两类字节,否则「逐字节」退化成「JSON 相等」
2595
+ const oldState = { ...baseState('design'), status: 'running', evidence: { design: { summary: '旧进度' } } };
2596
+ const oldBytes = Buffer.from('\uFEFF' + JSON.stringify(oldState, null, 2).replace(/\n/g, '\r\n') + '\r\n', 'utf8');
2597
+ fs.writeFileSync(stateFile, oldBytes);
2598
+
2599
+ // ⑥ 正确 --replace + --reason → 留档(逐字节)+ 记录 + RECOVERY 块 + 新 change 正常初始化
2600
+ const replaced = runStateWithProtocol(dir, ['init', 'new-change', '--replace', CHANGE_ID, '--reason', '切换到新 change']);
2601
+ assertExit(replaced, 0);
2602
+ assertOut(replaced, 'Initialized: new-change');
2603
+ assertOut(replaced, 'RECOVERY: 在途 change "' + CHANGE_ID + '" 的状态已留档');
2604
+ const snapshotDisplay = recoveryLine(replaced, '快照');
2605
+ const recordDisplay = recoveryLine(replaced, '记录');
2606
+ const rollbackCommand = recoveryLine(replaced, '回滚');
2607
+ assertTrue(snapshotDisplay.endsWith('-pre-init.state.json'), '快照文件名应为 <时间戳>-pre-init.state.json: ' + snapshotDisplay);
2608
+ assertEqual(snapshotDisplay.replace(/-pre-init\.state\.json$/, '-pre-init.md'), recordDisplay, '记录与快照同前缀');
2609
+ assertTrue(snapshotDisplay.startsWith('.specs/' + CHANGE_ID + '/recovery/'), '快照应落在旧 change 目录的 recovery/: ' + snapshotDisplay);
2610
+ assertTrue(Buffer.compare(fs.readFileSync(runRootPath(snapshotDisplay)), oldBytes) === 0,
2611
+ '快照必须是旧状态文件的逐字节副本(BOM / 行尾不得改写)');
2612
+ const recordText = fs.readFileSync(runRootPath(recordDisplay), 'utf8');
2613
+ assertTrue(recordText.includes('init 目标') && recordText.includes('new-change'), '记录缺 init 目标');
2614
+ assertTrue(recordText.includes('currentNode') && recordText.includes('design'), '记录缺旧 currentNode');
2615
+ assertTrue(recordText.includes('running'), '记录缺旧 status');
2616
+ assertTrue(recordText.includes('切换到新 change'), '记录缺原因');
2617
+ assertTrue(recordText.includes(snapshotDisplay), '记录缺快照路径');
2618
+ assertTrue(recordText.includes(rollbackCommand), '记录缺回滚命令');
2619
+ const newState = JSON.parse(fs.readFileSync(stateFile, 'utf8'));
2620
+ assertEqual(newState.activeChange, 'new-change', '放行后新 change 应正常初始化');
2621
+ assertEqual(newState.currentNode, 'open', '新 change 节点应为协议首节点');
2622
+
2623
+ // ⑦ 回滚命令照抄真执行 → 旧状态逐字节恢复(打印出来的文本本身就是可执行命令)
2624
+ const rolled = runPrintedCommand(rollbackCommand, dir);
2625
+ assertExit(rolled, 0);
2626
+ assertTrue(Buffer.compare(fs.readFileSync(stateFile), oldBytes) === 0, '回滚命令未把旧状态逐字节恢复');
2371
2627
  },
2372
2628
  },
2373
2629
 
@@ -2377,6 +2633,7 @@ export const ENTRIES = [
2377
2633
  {
2378
2634
  name: '96 自检方法段后续行声明 → 放行',
2379
2635
  run: (dir) => {
2636
+ writeNodeDeclarationMarkers(dir, 'execute');
2380
2637
  const st = baseState('execute');
2381
2638
  st.evidence.execute = { summary: 'executed' };
2382
2639
  st.evidence['subagent-execute'] = { handoffResult: handoffFor(['T01']) };