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
@@ -17,29 +17,30 @@ import {
17
17
  writeState,
18
18
  } from '../lib/test-helpers.mjs';
19
19
  import {
20
+ assertGitignoreManaged,
21
+ bridgeIdentityEnv,
20
22
  BUILTIN_PROTOCOL_SOURCE,
21
23
  CHANGE_ID,
22
24
  GUARD,
23
25
  HOOK,
24
26
  LEGACY_RUNTIME_DIR,
25
- MIGRATION_CHANGE,
26
- PREPARE_ENV,
27
- REPO_ROOT,
28
- RUNTIME_DIR,
29
- RUNTIME_STATE_NAME,
30
- SCRIPTS_DIR,
31
- assertGitignoreManaged,
32
- bridgeIdentityEnv,
33
27
  makeTmp,
34
28
  migratableStateBytes,
29
+ MIGRATION_CHANGE,
35
30
  migrationBackups,
36
31
  normalizeRoot,
32
+ PREPARE_ENV,
33
+ REPO_ROOT,
37
34
  runGitignoreForm,
38
35
  runInstalled,
39
36
  runPrepareEnv,
37
+ RUNTIME_DIR,
38
+ RUNTIME_STATE_NAME,
39
+ SCRIPTS_DIR,
40
40
  writeClassicCometAssets,
41
41
  writeIntakeArtifacts,
42
42
  writeMigratedProjectArtifacts,
43
+ writeNodeDeclarationMarkers,
43
44
  writeSharedCometDir,
44
45
  } from '../lib/test-fixtures.mjs';
45
46
  import {
@@ -328,6 +329,7 @@ export const ENTRIES = [
328
329
  st.status = 'running';
329
330
  st.evidence.open = { summary: 'intake complete' };
330
331
  writeState(proj, st);
332
+ writeNodeDeclarationMarkers(proj, 'open');
331
333
  if (withClassic) writeClassicCometAssets(proj);
332
334
  return proj;
333
335
  };
@@ -378,6 +380,7 @@ export const ENTRIES = [
378
380
  st.status = 'running';
379
381
  st.evidence.open = { summary: 'intake complete' };
380
382
  writeState(proj, st);
383
+ writeNodeDeclarationMarkers(proj, 'open');
381
384
  writeClassicCometAssets(proj); // 叠加分支的前置(classic 活动 change)在场
382
385
  return proj;
383
386
  };
@@ -1278,10 +1281,283 @@ export const ENTRIES = [
1278
1281
  '## intel-scan 元数据 ##', '- **last_intel_scan**: x', '- **scanner**: x', '- **下次重扫建议**: x',
1279
1282
  '',
1280
1283
  ].join('\n'));
1281
- const boundary = runStateWithProtocol(dir, ['init', CHANGE_ID + '-2', '--init-context']);
1284
+ const boundary = runStateWithProtocol(dir, ['init', CHANGE_ID + '-2', '--init-context', '--replace', CHANGE_ID, '--reason', '验证段标题闭合标记判定']);
1282
1285
  assertExit(boundary, 0);
1283
1286
  assertOut(boundary, 'INIT-VALIDATE-FAILED');
1284
1287
  assertOut(boundary, '项目概要');
1285
1288
  },
1286
1289
  },
1290
+
1291
+ // 243: 写目标按**物理落点**判定——白名单目录里的链接曾把写入引流到源码目录:
1292
+ // `.specs/j` 指向 `src` 时,写 `.specs/j/x` 词法命中白名单,真实落点却是 src。
1293
+ // 修复后白名单 / 包含性 / 保护集三处都按 realpath 后的相对路径判定,报文回显调用方拼写。
1294
+ // 硬链接是路径判定的盲区(没有可解析的目标、realpath 仍指向自己),按"共享文件对象"fail-closed。
1295
+ {
1296
+ name: '243 hook 写目标物理判定:链接不再把白名单写入引流到源码目录,硬链接拒绝',
1297
+ run: (dir) => {
1298
+ writeState(dir, { ...baseState('subagent-execute'), status: 'running' });
1299
+ const posix = (p) => p.split(path.sep).join('/');
1300
+ const specs = path.join(dir, '.specs');
1301
+ const srcDir = path.join(dir, 'src');
1302
+ fs.mkdirSync(specs, { recursive: true });
1303
+ fs.mkdirSync(srcDir, { recursive: true });
1304
+ fs.writeFileSync(path.join(srcDir, 'app.js'), 'console.log(1);\n', 'utf8');
1305
+ const linkInto = path.join(specs, 'j');
1306
+ try {
1307
+ fs.symlinkSync(srcDir, linkInto, process.platform === 'win32' ? 'junction' : 'dir');
1308
+ } catch (error) {
1309
+ console.error('WARN: 无法创建目录链接,链接断言跳过(' + (error.code || error.message) + ')');
1310
+ return;
1311
+ }
1312
+ // ① file_path:白名单内的链接路径 → 按物理落点拒绝(修复前词法放行 = RED)
1313
+ const viaWrite = runHook(['before_tool'], dir, {
1314
+ tool_name: 'Write',
1315
+ tool_input: { file_path: path.join(linkInto, 'w.txt') },
1316
+ });
1317
+ assertExit(viaWrite, 2);
1318
+ assertOut(viaWrite, 'BLOCKED');
1319
+ assertOut(viaWrite, 'src/w.txt'); // 报文点名物理相对路径,便于定位真实落点
1320
+ // ② Bash 命令目标:同一路径同一结论(两条判定共用解析)
1321
+ const viaBash = runHook(['before_tool'], dir, {
1322
+ tool_name: 'Bash',
1323
+ tool_input: { command: 'printf x > "' + posix(path.join(linkInto, 'v.txt')) + '"' },
1324
+ });
1325
+ assertExit(viaBash, 2);
1326
+ assertOut(viaBash, 'BLOCKED');
1327
+ // ③ 放行面不受影响:白名单内的普通写入仍放行
1328
+ const plain = runHook(['before_tool'], dir, {
1329
+ tool_name: 'Write',
1330
+ tool_input: { file_path: path.join(specs, 'plain.txt') },
1331
+ });
1332
+ assertExit(plain, 0);
1333
+ assertOut(plain, 'workflow-hook-guard-ok');
1334
+ // ④ 两端都在白名单内的链接仍放行(不能退化成"链接一律拒绝")
1335
+ const realDir = path.join(specs, 'real');
1336
+ fs.mkdirSync(realDir, { recursive: true });
1337
+ const alias = path.join(specs, 'alias');
1338
+ try { fs.symlinkSync(realDir, alias, process.platform === 'win32' ? 'junction' : 'dir'); } catch { /* 上方已降级过 */ }
1339
+ if (fs.existsSync(alias)) {
1340
+ const viaAlias = runHook(['before_tool'], dir, {
1341
+ tool_name: 'Write',
1342
+ tool_input: { file_path: path.join(alias, 'ok.md') },
1343
+ });
1344
+ assertExit(viaAlias, 0);
1345
+ assertOut(viaAlias, 'workflow-hook-guard-ok');
1346
+ }
1347
+ // ⑤ 链接指向**项目根之外**:包含性子句的锚(删掉协议层的物理包含性判定 ⇒ 此条必红)
1348
+ // 真·项目根之外(此前夹具建在根内,断言 'outside' 被目录名喂饱 —— 判别力为零)
1349
+ const outsideDir = path.join(path.dirname(dir), 'outside-' + path.basename(dir));
1350
+ fs.mkdirSync(outsideDir, { recursive: true });
1351
+ const outLink = path.join(specs, 'out');
1352
+ try { fs.symlinkSync(outsideDir, outLink, process.platform === 'win32' ? 'junction' : 'dir'); } catch { /* 已降级 */ }
1353
+ if (fs.existsSync(outLink)) {
1354
+ const viaOut = runHook(['before_tool'], dir, {
1355
+ tool_name: 'Write',
1356
+ tool_input: { file_path: path.join(outLink, 'escaped.md') },
1357
+ });
1358
+ assertExit(viaOut, 2);
1359
+ assertOut(viaOut, 'BLOCKED');
1360
+ // 报文来自物理包含性判定(写目标解析越界),不是白名单前缀
1361
+ assertOut(viaOut, 'resolves outside');
1362
+ }
1363
+ // ⑥ 最小保护集:协调者经链接写状态文件 → 拒绝(物理相对路径命中保护集)
1364
+ const stateLink = path.join(specs, 's');
1365
+ try { fs.symlinkSync(path.join(dir, '.flow-comet'), stateLink, process.platform === 'win32' ? 'junction' : 'dir'); } catch { /* 同上 */ }
1366
+ if (fs.existsSync(stateLink)) {
1367
+ const viaState = runHook(['before_tool'], dir, {
1368
+ tool_name: 'Write',
1369
+ tool_input: { file_path: path.join(stateLink, 'flow-comet-state.json') },
1370
+ });
1371
+ assertExit(viaState, 2);
1372
+ assertOut(viaState, 'BLOCKED');
1373
+ }
1374
+ // ⑦b 协议文件:经链接写它同样要拒(此前协议身份判定零断言)
1375
+ const protoDir = path.join(dir, 'reference');
1376
+ if (fs.existsSync(protoDir)) {
1377
+ const protoLink = path.join(specs, 'p');
1378
+ try { fs.symlinkSync(protoDir, protoLink, process.platform === 'win32' ? 'junction' : 'dir'); } catch { /* 已降级 */ }
1379
+ if (fs.existsSync(protoLink)) {
1380
+ const viaProto = runHook(['before_tool'], dir, {
1381
+ tool_name: 'Write',
1382
+ tool_input: { file_path: path.join(protoLink, 'workflow-protocol.json') },
1383
+ });
1384
+ assertExit(viaProto, 2);
1385
+ assertOut(viaProto, 'BLOCKED');
1386
+ assertOut(viaProto, '协议文件');
1387
+ }
1388
+ }
1389
+ // ⑦b-2 Bash 通道同判:同一目标不因所选工具而异(此前这两条在两级套件里零断言——
1390
+ // 撤掉 Bash 分支的协议判定与 blocked 判定,套件仍然全绿,等于行为无人看守)。
1391
+ {
1392
+ const bashProtoTarget = posix(path.join(dir, 'reference', 'workflow-protocol.json'));
1393
+ const viaBashProto = runHook(['before_tool'], dir, {
1394
+ tool_name: 'Bash',
1395
+ tool_input: { command: 'printf x > "' + bashProtoTarget + '"' },
1396
+ });
1397
+ assertExit(viaBashProto, 2);
1398
+ assertOut(viaBashProto, 'BLOCKED');
1399
+ assertOut(viaBashProto, '协议文件');
1400
+ }
1401
+ // ⑦c 目录目标不得被硬链接判据误拦(POSIX 上目录 nlink 恒 ≥2,判据只认普通文件)
1402
+ const dirTarget = path.join(specs, 'dir-target');
1403
+ fs.mkdirSync(dirTarget, { recursive: true });
1404
+ const viaDir = runHook(['before_tool'], dir, {
1405
+ tool_name: 'Write',
1406
+ tool_input: { file_path: dirTarget },
1407
+ });
1408
+ assertExit(viaDir, 0);
1409
+ assertOut(viaDir, 'workflow-hook-guard-ok');
1410
+
1411
+ // ⑦d worktree 隔离区只豁免白名单,不豁免保护集:worktrees 下指向 state 的硬链必须拒绝
1412
+ // (协调者通道的 worktree 早退曾绕过保护集判定——实测放行,现前置判定后拒绝)
1413
+ {
1414
+ const wtDir = path.join(dir, '.claude', 'worktrees', 'w');
1415
+ fs.mkdirSync(wtDir, { recursive: true });
1416
+ const wtState = path.join(wtDir, 'state-hl.json');
1417
+ let wtReady = false;
1418
+ try { fs.linkSync(path.join(dir, '.flow-comet', 'flow-comet-state.json'), wtState); wtReady = true; } catch { wtReady = false; }
1419
+ if (!wtReady) {
1420
+ console.error('SKIP: worktree 硬链断言不适用(本机无法创建硬链接)——未覆盖,不是通过');
1421
+ } else {
1422
+ const viaWt = runHook(['before_tool'], dir, {
1423
+ tool_name: 'Write',
1424
+ tool_input: { file_path: wtState },
1425
+ });
1426
+ assertExit(viaWt, 2);
1427
+ assertOut(viaWt, 'BLOCKED');
1428
+ }
1429
+ // 对照:worktree 内的普通写入仍放行(隔离区放行不得被这条判据误伤)
1430
+ const viaWtOk = runHook(['before_tool'], dir, {
1431
+ tool_name: 'Write',
1432
+ tool_input: { file_path: path.join(wtDir, 'src', 'ok.mjs') },
1433
+ });
1434
+ assertExit(viaWtOk, 0);
1435
+ assertOut(viaWtOk, 'workflow-hook-guard-ok');
1436
+ }
1437
+
1438
+ // ⑧ 硬链接:同一文件对象的第二个名字,路径判定看不出来 → 一律拒绝
1439
+ // (硬链接不需要符号链接特权,Windows 普通用户即可创建)
1440
+ const hardTarget = path.join(specs, 'hard.js');
1441
+ let hardKind = 'file';
1442
+ try {
1443
+ fs.linkSync(path.join(srcDir, 'app.js'), hardTarget);
1444
+ } catch {
1445
+ // 跨卷/文件系统不支持时退回目录 junction + 文件对(保持同一类判据仍被覆盖)
1446
+ try { fs.symlinkSync(path.join(srcDir, 'app.js'), hardTarget, 'file'); hardKind = 'symlink'; } catch { hardKind = null; }
1447
+ }
1448
+ if (!hardKind) {
1449
+ console.error('SKIP: 硬链接断言不适用(本机无法创建硬链接或文件符号链接)——未覆盖,不是通过');
1450
+ }
1451
+ if (hardKind) {
1452
+ const viaHard = runHook(['before_tool'], dir, {
1453
+ tool_name: 'Write',
1454
+ tool_input: { file_path: hardTarget },
1455
+ });
1456
+ assertExit(viaHard, 2);
1457
+ assertOut(viaHard, 'BLOCKED');
1458
+ // 撤掉 nlink 判定后,硬链接形态会退化成"白名单内普通文件"⇒ 此断言必红(判别力锚)
1459
+ // 回退形态(文件符号链接)不走 nlink 判据,落点解析到 src/app.js ⇒ 报文是白名单拒绝,
1460
+ // 这里按实际成因断言,避免"支持符号链接但不支持硬链接"的文件系统上整套件必红。
1461
+ assertOut(viaHard, hardKind === 'file' ? '硬链接' : 'src/app.js');
1462
+ // ⑦c-2 Bash 通道同判(此前该分支的 blocked 判定零断言,撤掉实现套件仍全绿)
1463
+ const bashHard = runHook(['before_tool'], dir, {
1464
+ tool_name: 'Bash',
1465
+ tool_input: { command: 'printf x > "' + posix(hardTarget) + '"' },
1466
+ });
1467
+ assertExit(bashHard, 2);
1468
+ assertOut(bashHard, 'BLOCKED');
1469
+ assertOut(bashHard, hardKind === 'file' ? '硬链接' : 'src/app.js');
1470
+ }
1471
+ // ⑨ 同一实体不同拼写:win32 大小写不敏感 ⇒ 放行;非 win32 显式声明不适用(不静默跳过)
1472
+ if (process.platform === 'win32') {
1473
+ const viaCase = runHook(['before_tool'], dir, {
1474
+ tool_name: 'Write',
1475
+ tool_input: { file_path: path.join(dir, '.SPECS', 'case.md') },
1476
+ });
1477
+ assertExit(viaCase, 0);
1478
+ assertOut(viaCase, 'workflow-hook-guard-ok');
1479
+ } else {
1480
+ console.error('SKIP: 大小写等价拼写断言不适用(非 win32 大小写敏感文件系统)——未覆盖,不是通过');
1481
+ }
1482
+ // ⑩ 恢复:移除链接后同一路径恢复放行(拦截不是永久状态)
1483
+ try { fs.rmdirSync(linkInto); } catch { try { fs.unlinkSync(linkInto); } catch { /* 忽略 */ } }
1484
+ if (fs.existsSync(linkInto)) throw new Error('恢复夹具:链接未被移除');
1485
+ const recovered = runHook(['before_tool'], dir, {
1486
+ tool_name: 'Write',
1487
+ tool_input: { file_path: path.join(linkInto, 'again.txt') },
1488
+ });
1489
+ assertExit(recovered, 0);
1490
+ assertOut(recovered, 'workflow-hook-guard-ok');
1491
+
1492
+ // ⑪ 空闲态只保留一条拦截:state 文件(用户裁决:空闲零拦截,最多只拦 state)。
1493
+ // 实测链条:删除 state 后守卫降为空闲;若连 state 也能写,就能重建
1494
+ // executionMode=direct 的状态造成持久降级。协议文件在空闲态放行(下次运行的协议由
1495
+ // 人工/安装器通道维护)。反向构造:把状态判定退回 currentNode 门内 ⇒ ⑪b 必红;
1496
+ // 把协议判定移出活跃流程门 ⇒ ⑪b 的协议放行用例必红;把链接拒绝移出流程态门 ⇒ ⑪c 必红。
1497
+ const stateTarget = path.join(dir, '.flow-comet', 'flow-comet-state.json');
1498
+ const protoTarget = path.join(dir, 'reference', 'workflow-protocol.json');
1499
+ // ⑪a 空闲态(state 在盘但无 activeChange / currentNode)+ 指向 state 的硬链接:
1500
+ // 路径前缀看不见同一文件的第二个名字,只有物理身份判据能拦(空闲态下硬链的
1501
+ // blocked 拒绝按空闲放行语义不生效,故本断言与 ⑧ 的活跃态硬链断言相互独立)。
1502
+ writeState(dir, { ...baseState('review'), activeChange: null, currentNode: null, status: 'completed' });
1503
+ const idleStateLink = path.join(specs, 'idle-state-link.json');
1504
+ let idleLinkKind = null;
1505
+ try { fs.linkSync(stateTarget, idleStateLink); idleLinkKind = 'hard'; }
1506
+ catch { try { fs.symlinkSync(stateTarget, idleStateLink, 'file'); idleLinkKind = 'symlink'; } catch { idleLinkKind = null; } }
1507
+ if (idleLinkKind) {
1508
+ const idleLinkBash = runHook(['before_tool'], dir, {
1509
+ tool_name: 'Bash',
1510
+ tool_input: { command: 'printf x > "' + posix(idleStateLink) + '"' },
1511
+ });
1512
+ assertExit(idleLinkBash, 2);
1513
+ assertOut(idleLinkBash, 'state 文件');
1514
+ const idleLinkWrite = runHook(['before_tool'], dir, {
1515
+ tool_name: 'Write',
1516
+ tool_input: { file_path: idleStateLink },
1517
+ });
1518
+ assertExit(idleLinkWrite, 2);
1519
+ assertOut(idleLinkWrite, 'state 文件');
1520
+ } else {
1521
+ console.error('SKIP: 空闲态保护集别名断言不适用(本机无法创建硬链接或文件符号链接)——未覆盖,不是通过');
1522
+ }
1523
+ // ⑪b 无 state(空闲)时:写 state 仍拒绝(两通道同判);写协议放行——空闲态零拦截,
1524
+ // 最多只拦 state 文件(用户裁决)。反向构造:把协议判定移进活跃流程门 ⇒ 本条必红。
1525
+ fs.rmSync(stateTarget);
1526
+ for (const [label, toolName, toolInput] of [
1527
+ ['state 文件(file_path)', 'Write', { file_path: stateTarget }],
1528
+ ['state 文件(Bash)', 'Bash', { command: 'printf x > "' + posix(stateTarget) + '"' }],
1529
+ ]) {
1530
+ const idleProtected = runHook(['before_tool'], dir, { tool_name: toolName, tool_input: toolInput });
1531
+ if (idleProtected.status !== 2 || !idleProtected.output.includes('state 文件')) {
1532
+ throw new Error('空闲态写 state 文件应拒绝并点名(' + label + '),实际输出: ' + JSON.stringify(idleProtected.output));
1533
+ }
1534
+ }
1535
+ for (const [label, toolName, toolInput] of [
1536
+ ['协议文件(file_path)', 'Write', { file_path: protoTarget }],
1537
+ ['协议文件(Bash)', 'Bash', { command: 'printf x > "' + posix(protoTarget) + '"' }],
1538
+ ]) {
1539
+ const idleProtocol = runHook(['before_tool'], dir, { tool_name: toolName, tool_input: toolInput });
1540
+ if (idleProtocol.status !== 0 || !idleProtocol.output.includes('no active workflow')) {
1541
+ throw new Error('空闲态写协议文件应放行(' + label + ';用户裁决:空闲零拦截),实际输出: ' + JSON.stringify(idleProtocol.output));
1542
+ }
1543
+ }
1544
+ // ⑪c 对照:空闲态经链接逃逸的目标仍放行(空闲放行语义不变)。普通源码目标的空闲放行
1545
+ // 由场景 30a / 67 覆盖,此处不再重复(同一行为三份断言 = 噪音)。
1546
+ if (fs.existsSync(outLink)) {
1547
+ // 两通道都不得在空闲态拒绝链接逃逸目标(Bash 的 blocked 拒绝必须留在流程态门之后)
1548
+ const idleEscapeBash = runHook(['before_tool'], dir, {
1549
+ tool_name: 'Bash',
1550
+ tool_input: { command: 'printf x > "' + posix(path.join(outLink, 'idle-escaped.txt')) + '"' },
1551
+ });
1552
+ assertExit(idleEscapeBash, 0);
1553
+ assertOut(idleEscapeBash, 'no active workflow');
1554
+ const idleEscape = runHook(['before_tool'], dir, {
1555
+ tool_name: 'Write',
1556
+ tool_input: { file_path: path.join(outLink, 'idle-escaped.md') },
1557
+ });
1558
+ assertExit(idleEscape, 0);
1559
+ assertOut(idleEscape, 'no active workflow');
1560
+ }
1561
+ },
1562
+ },
1287
1563
  ];
@@ -705,7 +705,6 @@ export const ENTRIES = [
705
705
  activeChange: CHANGE_ID,
706
706
  currentNode: 'review',
707
707
  evidence: { review: { summary: 'pending fix' } },
708
- newChange: true,
709
708
  };
710
709
  const pendingDecision = { kind: 'pending', target: 'execute' };
711
710
  for (let round = 1; round <= 3; round += 1) {
@@ -767,7 +766,7 @@ export const ENTRIES = [
767
766
  throw new Error('授权放行后计数器应为 4,实际 ' + JSON.stringify(roundState.fixRoundsByChange));
768
767
  }
769
768
  // 旧 change 缺轮次字段 → 缺省 0、不因计数 BLOCK
770
- const legacyRoundState = { activeChange: CHANGE_ID, currentNode: 'review', evidence: {}, newChange: false };
769
+ const legacyRoundState = { activeChange: CHANGE_ID, currentNode: 'review', evidence: {} };
771
770
  const legacyRound = applyRound({ state: legacyRoundState, sourceNode: 'review', decision: pendingDecision });
772
771
  if (!legacyRound.counted || legacyRound.blocked || legacyRound.round !== 1) {
773
772
  throw new Error('旧 change 缺省 0 应可从第 1 轮计数,实际 ' + JSON.stringify(legacyRound));
@@ -776,7 +775,7 @@ export const ENTRIES = [
776
775
  throw new Error('旧 change 第 1 轮应写入缺省容器,实际 ' + JSON.stringify(legacyRoundState.fixRoundsByChange));
777
776
  }
778
777
  // 分支② done-but-unclosed 不计数(计数语义 = 一次受控归位)
779
- const unclosedState = { activeChange: CHANGE_ID, currentNode: 'review', evidence: {}, newChange: true };
778
+ const unclosedState = { activeChange: CHANGE_ID, currentNode: 'review', evidence: {} };
780
779
  const unclosedRound = applyRound({ state: unclosedState, sourceNode: 'review', decision: { kind: 'unclosed', target: 'execute' } });
781
780
  if (unclosedRound.counted || unclosedRound.round !== null || unclosedState.fixRoundsByChange) {
782
781
  throw new Error('done-but-unclosed 分支不得计数/建容器,实际 '
@@ -1074,7 +1073,6 @@ export const ENTRIES = [
1074
1073
  verifyFailures: 0,
1075
1074
  executionMode: 'subagent',
1076
1075
  directOverride: false,
1077
- newChange: true,
1078
1076
  };
1079
1077
  // ① 正例:pending Fix 任务在场 → 受控归位 + 审计行 + 真实写盘
1080
1078
  writeFile(dir, taskPath, fixBatchTaskText('pending'));
@@ -1193,7 +1191,6 @@ export const ENTRIES = [
1193
1191
  verifyFailures: 0,
1194
1192
  executionMode: 'subagent',
1195
1193
  directOverride: false,
1196
- newChange: true,
1197
1194
  };
1198
1195
  writeFile(dir, taskPath, fixBatchTaskText('pending'));
1199
1196
  writeState(dir, st);
@@ -1280,7 +1277,6 @@ export const ENTRIES = [
1280
1277
  verifyFailures: 0,
1281
1278
  executionMode: 'subagent',
1282
1279
  directOverride: false,
1283
- newChange: true,
1284
1280
  });
1285
1281
  // 声明标记:真实流程里由协调者 / record 写;夹具直接写 state,须补同一份事实(否则先撞覆盖门)
1286
1282
  writeNodeDeclarationMarkers(dir, 'execute');
@@ -199,7 +199,6 @@ export const ENTRIES = [
199
199
  verifyFailures: 0,
200
200
  executionMode: 'subagent',
201
201
  directOverride: false,
202
- newChange: true,
203
202
  });
204
203
  writeNodeDeclarationMarkers(dir, 'execute');
205
204
  const res = runGuard(['exit', 'execute', '--apply'], dir);
@@ -242,7 +241,6 @@ export const ENTRIES = [
242
241
  verifyFailures: 0,
243
242
  executionMode: 'subagent',
244
243
  directOverride: false,
245
- newChange: true,
246
244
  };
247
245
  // ① 新 change:review 源直接 exit review --apply → BLOCKED + 恢复指引(不得静默放行)
248
246
  writeFile(dir, taskPath, fixBatchTaskText('pending'));
@@ -414,13 +412,13 @@ export const ENTRIES = [
414
412
  if (!fs.existsSync(gateMarker) || fs.readFileSync(gateMarker, 'utf8') !== 'GATE-RAN') {
415
413
  throw new Error('闭合后 verify 出口未真实执行 TEST.md 验证命令(副作用文件缺失/内容不符)');
416
414
  }
417
- // ④ 旧 change(无 newChange 标记)pending 同路径:渐进 WARN 不阻断(向后兼容)
415
+ // ④ 同一形态(无任何新旧标记字段)pending 同路径:同判 BLOCKED(单轨,无渐进侧)
418
416
  writeFile(dir, taskPath, fixBatchTaskText('pending'));
419
- writeState(dir, { ...reviewState, newChange: false });
417
+ writeState(dir, { ...reviewState });
420
418
  const resOld = runGuard(['exit', 'review'], dir);
421
- assertExit(resOld, 0);
422
- assertOut(resOld, 'FIX-BATCH WARN');
423
- assertOut(resOld, 'ALL CHECKS PASSED');
419
+ assertExit(resOld, 1);
420
+ assertOut(resOld, 'BLOCKED: 存在未归位/未跑出口的 Fix 批次');
421
+ assertNotOut(resOld, 'ALL CHECKS PASSED');
424
422
  // ④b 过渡态渐进(feature 之前创建的 state 无 exit execute 签名字段):全 done 也不得
425
423
  // 仅凭「签名缺席」误判未闭合——无签名记录 → done 变体不成立,源节点出口保持可走
426
424
  writeFile(dir, taskPath, fixBatchTaskText('done'));
@@ -562,7 +560,6 @@ export const ENTRIES = [
562
560
  verifyFailures: 0,
563
561
  executionMode: 'subagent',
564
562
  directOverride: false,
565
- newChange: true,
566
563
  };
567
564
  // ① review 源:pending Fix 任务在场 → NODE: execute + 审计行 + 机器字段归位写盘
568
565
  writeFile(dir, taskPath, fixBatchTaskText('pending'));
@@ -619,7 +616,6 @@ export const ENTRIES = [
619
616
  verifyFailures: 0,
620
617
  executionMode: 'subagent',
621
618
  directOverride: false,
622
- newChange: true,
623
619
  };
624
620
  // ③ 反例:全 done(无 pending Fix 任务)→ 非回退态,不得归位 execute(回程逻辑另行覆盖)
625
621
  let after;
@@ -663,7 +659,6 @@ export const ENTRIES = [
663
659
  verifyFailures: 0,
664
660
  executionMode: 'subagent',
665
661
  directOverride: false,
666
- newChange: true,
667
662
  };
668
663
  // ④ done-but-unclosed 回退态(全 done + history 最新 exit execute 签名仍是追加前值):
669
664
  // next 同样显式归位 execute(修复前 done 变体无恢复通道,next 停在源节点)。
@@ -707,7 +702,6 @@ export const ENTRIES = [
707
702
  verifyFailures: 0,
708
703
  executionMode: 'subagent',
709
704
  directOverride: false,
710
- newChange: true,
711
705
  };
712
706
  // ⑤ review 源 + 并行 pending Fix 任务:next 必须归位 subagent-execute(并行路由目标),
713
707
  // 不得停在源节点,也不得错配回 execute。
@@ -781,7 +775,6 @@ export const ENTRIES = [
781
775
  verifyFailures: 0,
782
776
  executionMode: 'subagent',
783
777
  directOverride: false,
784
- newChange: true,
785
778
  };
786
779
  // ⑧ m-12 next 入口第 1~3 轮递增:逐轮重置驻留 review,审计后缀第 n/3 轮且计数器同步 +1
787
780
  writeFile(dir, taskPath, fixBatchTaskText('pending'));
@@ -872,7 +865,6 @@ export const ENTRIES = [
872
865
  verifyFailures: 0,
873
866
  executionMode: 'subagent',
874
867
  directOverride: false,
875
- newChange: true,
876
868
  };
877
869
  // ① 真实回程态(review 已 entry)→ 审计行 + NODE: review + state 只读不改写
878
870
  writeState(dir, base);
@@ -945,7 +937,6 @@ export const ENTRIES = [
945
937
  verifyFailures: 0,
946
938
  executionMode: 'subagent',
947
939
  directOverride: false,
948
- newChange: true,
949
940
  };
950
941
  // ① 真实回程态(verify 已 entry)→ 审计行 + NODE: verify + state 只读不改写
951
942
  writeState(dir, base);
@@ -1010,7 +1001,6 @@ export const ENTRIES = [
1010
1001
  verifyFailures: 0,
1011
1002
  executionMode: 'subagent',
1012
1003
  directOverride: false,
1013
- newChange: true,
1014
1004
  });
1015
1005
  const res = runStateWithProtocol(dir, ['next']);
1016
1006
  assertExit(res, 0);
@@ -371,7 +371,6 @@ export const ENTRIES = [
371
371
  run: (dir) => {
372
372
  writeReentryChangeDir(dir);
373
373
  const legacyState = reentryArchiveState();
374
- delete legacyState.newChange;
375
374
  writeState(dir, legacyState);
376
375
  const blockedBytes = readStateBytes(dir);
377
376
  const resBlocked = runReenter(dir, 'verify');
@@ -636,7 +635,6 @@ export const ENTRIES = [
636
635
  // ① plan 出口(既有判定路径)对同一输入的机器分类
637
636
  const planState = baseState('plan');
638
637
  planState.evidence.plan = { summary: 'plan done' };
639
- planState.newChange = true;
640
638
  writeState(dir, planState);
641
639
  const planRes = runPlanExit(dir, taskContent);
642
640
  assertExit(planRes, 1);
@@ -904,8 +902,12 @@ export const ENTRIES = [
904
902
  }
905
903
  }
906
904
  if (replanProblems(stateText).length !== 0) throw new Error('反向构造还原后未复绿');
907
- if (!/WARN: TASK\.md 同文件跨任务且无依赖路径(旧 change 渐进不阻断)/.test(stateText)) {
908
- throw new Error('replan 的第三族必须保留旧 change 渐进分支(WARN 不阻断)');
905
+ // 单轨:replan 的第三族不再有渐进分支——源码里必须是 BLOCKED 且带「replan 不做校验豁免」口径
906
+ if (!/BLOCKED: TASK\.md 同文件跨任务且无依赖路径/.test(stateText)) {
907
+ throw new Error('replan 的第三族必须是单轨 BLOCKED(无渐进分支)');
908
+ }
909
+ if (/旧 change 渐进不阻断/.test(stateText)) {
910
+ throw new Error('replan 的第三族不得残留旧 change 渐进分支');
909
911
  }
910
912
  },
911
913
  },
@@ -950,7 +952,6 @@ export const ENTRIES = [
950
952
  // 修复族对 → exit 0 且不出现该族消息(BLOCKED / WARN 两形态都不许有)。
951
953
  const crossState = baseState('plan');
952
954
  crossState.evidence.plan = { summary: 'plan done' };
953
- crossState.newChange = true;
954
955
  writeState(dir, crossState);
955
956
  const plainRes = runPlanExit(dir, CROSS_TASK_PLAIN_PAIR);
956
957
  assertExit(plainRes, 1);