flow-comet 1.6.2 → 1.6.3

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 (43) 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 +260 -17
  12. package/.flow-comet/skills/flow-comet/scripts/guard-self-test.mjs +2714 -161
  13. package/.flow-comet/skills/flow-comet/scripts/route-node.mjs +51 -4
  14. package/.flow-comet/skills/flow-comet/scripts/state-schema.mjs +13 -0
  15. package/.flow-comet/skills/flow-comet/scripts/system-test.mjs +877 -10
  16. package/.flow-comet/skills/flow-comet/scripts/workflow-guard.mjs +52 -4
  17. package/.flow-comet/skills/flow-comet/scripts/workflow-handoff.mjs +111 -4
  18. package/.flow-comet/skills/flow-comet/scripts/workflow-state.mjs +108 -2
  19. package/.flow-comet/skills/flow-comet-archive/SKILL.md +10 -19
  20. package/.flow-comet/skills/flow-comet-change/SKILL.md +2 -3
  21. package/.flow-comet/skills/flow-comet-compose/SKILL.md +1 -1
  22. package/.flow-comet/skills/flow-comet-design/SKILL.md +6 -6
  23. package/.flow-comet/skills/flow-comet-execute/SKILL.md +58 -16
  24. package/.flow-comet/skills/flow-comet-integration/SKILL.md +8 -5
  25. package/.flow-comet/skills/flow-comet-open/SKILL.md +5 -1
  26. package/.flow-comet/skills/flow-comet-plan/GUIDANCE.md +1 -1
  27. package/.flow-comet/skills/flow-comet-plan/SKILL.md +8 -8
  28. package/.flow-comet/skills/flow-comet-review/SKILL.md +9 -12
  29. package/.flow-comet/skills/flow-comet-subagent-execute/SKILL.md +59 -16
  30. package/.flow-comet/skills/flow-comet-task/SKILL.md +3 -2
  31. package/.flow-comet/skills/flow-comet-ui-design/SKILL.md +3 -3
  32. package/.flow-comet/skills/flow-comet-verify/SKILL.md +8 -17
  33. package/README.md +4 -4
  34. package/package.json +1 -1
  35. package/scripts/dsh-bridge.mjs +59 -26
  36. package/scripts/prepare-env.mjs +165 -1
  37. package/.flow-comet/skills/flow-comet/reference/TEST-MATRIX.md +0 -116
  38. package/.flow-comet/skills/flow-comet/reference/composition-report.md +0 -65
  39. package/.flow-comet/skills/flow-comet/reference/dsh-platform.md +0 -184
  40. package/.flow-comet/skills/flow-comet/reference/resolved-skills.json +0 -661
  41. package/.flow-comet/skills/flow-comet/reference/skill-review.md +0 -13
  42. package/.flow-comet/skills/flow-comet/reference/subagents/script-author.md +0 -7
  43. package/.flow-comet/skills/flow-comet/reference/worktree-notes.md +0 -70
@@ -83,6 +83,27 @@ function resolveComponentSkillFile(nodeSkill, scriptsDir = __dirname) {
83
83
  return file;
84
84
  }
85
85
 
86
+ // 技能树分发面文档遍历(返回 [相对 skillsRoot 的斜杠路径, 绝对路径]):全部 `*.md`
87
+ //(各册 `SKILL.md` + `flow-comet/reference/**.md`)。用于「持某锚句的文本集合」「相对路径引用
88
+ // 可解析性」这类**跨册面**判据——单一册判据不用它,避免判据面被无谓放大。
89
+ function skillTreeDocFiles(scriptsDir = __dirname) {
90
+ const root = skillsRootForScriptsDir(scriptsDir);
91
+ const out = [];
92
+ const walk = (dir) => {
93
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
94
+ const abs = path.join(dir, entry.name);
95
+ if (entry.isDirectory()) {
96
+ walk(abs);
97
+ continue;
98
+ }
99
+ if (!entry.name.endsWith('.md')) continue;
100
+ out.push([path.relative(root, abs).replaceAll('\\', '/'), abs]);
101
+ }
102
+ };
103
+ walk(root);
104
+ return out;
105
+ }
106
+
86
107
  // 公开产物零代号判据(与 .githooks/internal-codes.mjs 的 BANNED 保持同步——单一来源约定:
87
108
  // 本文件随技能包分发,不能 import 主仓私有的 .githooks;改动词表时两份同改,行为必须一致)。
88
109
  // 等价性不只靠注释约定:底部自检在权威源检出下读该私有件**逐字符比对**(主仓形态),安装副本
@@ -453,11 +474,17 @@ function matchesRetiredNamespaceEntry(entry, rel, ref) {
453
474
  }
454
475
  return false;
455
476
  }
456
- // ③ 示例形态允许面(逐条 {file, ref, reason}):文档里的示意路径。**当前为空清单**——
457
- // 空清单的语义是「无任何示例允许项」(未登记即报,fail-closed),不是「该判据不生效」;
458
- // 查询带长度短路(零条目时不进入匹配),避免把零条目扩展点当成隐式权限。
459
- // 出现新示例时在此登记(未登记即报,不再静默跳过)。
460
- const EXAMPLE_REF_ALLOWLIST = [];
477
+ // ③ 示例形态允许面(逐条 {file, ref, reason}):文档里的示意路径。清单**逐条登记**——
478
+ // 未登记即报(fail-closed),不是「该判据不生效」;查询带长度短路(零条目时不进入匹配),
479
+ // 避免把零条目扩展点当成隐式权限。出现新示例时在此登记(登记即把边界显式化:文档措辞
480
+ // 不动,只声明「该路径是示意、不是真实文件」)。
481
+ const EXAMPLE_REF_ALLOWLIST = [
482
+ {
483
+ file: '.specs/adr/ADR-014-parallel-delegation-contract.md',
484
+ ref: 'src/foo.mjs',
485
+ reason: '写冲突盲区的示例路径(非真实文件)',
486
+ },
487
+ ];
461
488
  function isDeclaredReferenceSkip(rel, ref) {
462
489
  if (EXTERNAL_NAMESPACE_PREFIXES.some((prefix) => ref.startsWith(prefix))) return true;
463
490
  if (RETIRED_NAMESPACE_ALLOWLIST.some((e) => matchesRetiredNamespaceEntry(e, rel, ref))) return true;
@@ -820,6 +847,17 @@ function runHook(args, root, input, envOverrides = {}) {
820
847
  return { status: res.status ?? 1, output: String(res.stdout || '') + String(res.stderr || '') };
821
848
  }
822
849
 
850
+ // 桥接身份透传契约(套件侧单一构造点,与真实桥接同形):dsh 桥接在注入身份深度的**同时**注入
851
+ // 通道标记 FLOW_COMET_AGENT_DEPTH_SOURCE='dsh-bridge';守卫要求两者同时在场才接受 env 面身份。
852
+ // 套件里凡是要表达「经桥接通道的子代理身份」,一律经本函数构造 env——变量名/标记值只此一处,
853
+ // 免得各处手抄而与守卫或桥接漂移。反向形态(只注入深度、不注入标记)由身份族的继承形态断言覆盖。
854
+ function bridgeIdentityEnv(depthValue) {
855
+ return {
856
+ FLOW_COMET_AGENT_DEPTH: depthValue,
857
+ FLOW_COMET_AGENT_DEPTH_SOURCE: 'dsh-bridge',
858
+ };
859
+ }
860
+
823
861
  // 跑 scripts/prepare-env.mjs(真实安装器——平台选择链场景)。cwd=临时目录;
824
862
  // envOverrides 可覆盖 DSH_HOME(dsh 平台 installHooks 写 $DSH_HOME——场景必须设
825
863
  // DSH_HOME=临时目录环境变量,禁止污染真实 ~/.dsh;spawn 非 TTY:走探测/默认路径,不触发交互)
@@ -2366,6 +2404,862 @@ function timeSingleSourceConsumerProblems(text, symbols, file = '') {
2366
2404
  return problems;
2367
2405
  }
2368
2406
 
2407
+ // 两层加载模型的**入口层**判据(场景 167 使用;纯函数 + 合成输入可驱动):入口册与入口展开册
2408
+ // 各须含入口层锚点句(「Skill 工具加载该节点的 Implementation 技能」)与「前置门」表述,且不得含
2409
+ // Implementation/Required 混淆句式与无限定自动补表述。返回问题描述数组。
2410
+ function twoLayerEntryProblems(rel, text) {
2411
+ const out = [];
2412
+ if (text.includes('见上方 Required Calls 表')) out.push(rel + ' 含 Implementation/Required 混淆句式');
2413
+ if (text.includes('record 会自动补写缺失的声明标记')) out.push(rel + ' 含无限定自动补表述');
2414
+ if (!text.includes('Skill 工具加载该节点的 Implementation 技能')) out.push(rel + ' 缺入口层锚点句');
2415
+ if (!text.includes('前置门')) out.push(rel + ' 缺前置门表述');
2416
+ return out;
2417
+ }
2418
+
2419
+ // 技能加载措辞判据(场景 164 使用;纯函数 + 合成输入可驱动):主 SKILL / 入口展开册 / 八个节点册
2420
+ // 各须含「Skill 工具」与「不得跳过 / 禁止跳过」两条存在级锚点句(加载 = Skill 工具注入会话,
2421
+ // 只读文件不叫加载)。返回问题描述数组(空 = 两条齐备);判别力由场景内的逐条抽掉构造常驻证明。
2422
+ function skillLoadingWordingProblems(rel, text) {
2423
+ const out = [];
2424
+ if (!text.includes('Skill 工具')) out.push(rel + ' 缺「Skill 工具」');
2425
+ if (!text.includes('不得跳过') && !text.includes('禁止跳过')) out.push(rel + ' 缺「不得跳过/禁止跳过」');
2426
+ return out;
2427
+ }
2428
+
2429
+ // 委托纪律三块归一处(场景 184 的 ⑥ 使用;纯函数 + 合成输入可驱动):ADR-016 把「两册三块逐字
2430
+ // 一致(切片 ≥400 字符)+ 两册各持 41 条判别句」重定向为「两册各自的要点句在场 + 权威处唯一 +
2431
+ // 留正文的判别句逐句留原文但**不再要求两册相同**」。归一处:pathspec 五要素与集成四要素的**全文**
2432
+ // → `reference/commit-discipline.md`;四属性契约(能力契约锚)→ 两册正文 + 入口册 + 平台事实册。
2433
+ // ① 要素级 token 组:措辞可分叉(逐字锁已作废),但**要素一条不得缺**(两册 + 权威处同时受限);
2434
+ // ② 权威处正文在场:权威处独有的判别句必须在该文件(缺句即红);
2435
+ // ③ 权威处唯一:权威处正文**回流任一册即红**——这一侧原逐字锁完全没有(它**要求**两册各持一份);
2436
+ // ④ 证据与判级类判别句(随平台事实移走):只在权威处,回流册子即红;
2437
+ // ⑤ 条件句指针:两册各自须指向 commit-discipline / platform-facts / fix-loop 三个权威文件。
2438
+ const COMMIT_DISCIPLINE_REL = 'flow-comet/reference/commit-discipline.md';
2439
+ const PLATFORM_FACTS_REL = 'flow-comet/reference/platform-facts.md';
2440
+ const COMMIT_DISCIPLINE_ELEMENT_GROUPS = [
2441
+ ['提交面 pathspec 纪律 · 适用条件', ['**各自独立工作区(worktree 等)内的局部 `reset` / `clean` 不在禁令内**']],
2442
+ ['提交面 pathspec 纪律 · 要素 1(字面路径集)',
2443
+ ['`git add -- <自己字面路径>`', '`git commit -- <同一路径>`', 'write_files']],
2444
+ ['提交面 pathspec 纪律 · 要素 2(锁失败重试)', ['锁失败重试', 'index.lock', '失败即重试']],
2445
+ ['提交面 pathspec 纪律 · 要素 3(禁裸命令)',
2446
+ ['禁裸', '`commit -a`', '`stash`', '`clean`', '`reset`']],
2447
+ ['提交面 pathspec 纪律 · 要素 4(为什么 · 索引竞态)', ['并发索引竞态', '索引与工作树']],
2448
+ ['提交面 pathspec 纪律 · 要素 5(并行波次附加两条)', ['`git commit --amend`', '`--soft`']],
2449
+ ['集成纪律 · 要素 1(机制选择)', ['`git merge --no-ff`', 'cherry-pick']],
2450
+ ['集成纪律 · 要素 2(顺序)', ['拓扑序', 'task id 升序']],
2451
+ ['集成纪律 · 要素 3(审计留痕)', ['INTEGRATE: <task-id> <commitHash> → <集成提交>']],
2452
+ ['集成纪律 · 要素 4(冲突处置两类)', ['机械冲突', '语义冲突', '上抛']],
2453
+ ];
2454
+ // 权威处**正文**(逐字搬运进 `commit-discipline.md` 的原句;实测两册均无这些整句——回流即红)。
2455
+ const COMMIT_DISCIPLINE_AUTHORITY_PHRASES = [
2456
+ '2. **`git commit -- <同一路径>`**:提交以 pathspec 限定范围,保证提交只含自己的文件;路径集与上一步**逐字一致**。',
2457
+ '3. **锁失败重试**:并发提交会撞 `index.lock` / `cannot lock ref`——**失败即重试**(临时仓真并发实测:20 提交 / 25 次锁失败全部重试成功);不得因锁失败改用宽泛命令。',
2458
+ '5. **为什么**:并发写者共享**同一个索引与工作树**——宽泛命令存在**并发索引竞态**:一方 `add -A` 会把另一方的半成品纳入自己的提交(串味 / 多文件提交);`stash` / `clean` / `reset` 更会直接破坏同伴的未提交工作。',
2459
+ '**并行波次附加两条(与上列五要素并列适用 · 不改其语义与适用条件)**:',
2460
+ '- **并行波次禁用 `git commit --amend`**:共享工作区下 HEAD 会被并行写者推进——`--amend` 改的是 **HEAD 指向的提交**、不一定是「你的提交」,会把同伴的提交连同提交信息一并改写(本仓实测撞过:amend 误改了另一并行任务的提交,经 `reset --soft` 复原,内容零损失)。确需修正时必须**先断言 `git rev-parse HEAD` 等于自己刚提交的哈希**,否则一律改用**新提交追加**。',
2461
+ '- **误改后的自救通道(与上列第 4 条的定向例外)**:合法修复路径 = **先断言** `git rev-parse HEAD` 即被误改的那次提交,再 `git reset --soft <自己的父提交>` 回退(**只用 `--soft`**:只移动 HEAD、不动索引与工作树,同伴的未提交工作零影响),最后以 **pathspec** 重建自己的提交。纪律必须留出这条明路——让执行者**不必违规**(force-push / 手改历史)即可收拾;**无合法修复通道时人会暗改**(见 ADR-013 记录的同型教训)。',
2462
+ '2. **顺序(确定性规则)**:先按 `depends_on` 的**拓扑序**集成(被依赖者先入);同一拓扑层内按 **task id 升序**(计划期固定的稳定键,与完成先后无关)。**不得依赖书写顺序** / 提交到达顺序 / 完成先后等运行期不确定量。',
2463
+ '3. **审计留痕**:每次集成输出一行审计行 `INTEGRATE: <task-id> <commitHash> → <集成提交>`;降级路径为 `INTEGRATE: <task-id> <commitHash> via cherry-pick -- 降级原因:<原因>`。映射(task-id → commitHash → 集成提交)记入该趟流程记录(`<task-id>-SUMMARY.md` / handoff evidence 文本字段)。**判级**:审计行是**执行纪律**(review 把关),本节点不声称存在机械门禁校验它。',
2464
+ ' - **机械冲突**(不改用户可见行为:同一文件不同区域 / 相邻行 / 纯格式):执行者**可自行解决**——解决后必须跑**合并后验证**(该任务 `verify` + 受影响任务的判据),并在审计行记录冲突与解决方式。',
2465
+ ' - **语义冲突**(两侧对同一行为 / 契约 / 接口给出不同语义:同一函数语义分叉、同一 AC 的两种实现、公共 API 形状不一致):**必须中止集成并上抛**(记 BLOCKED + 恢复指引),**不得**由执行者自行拍板;由协调者 / 用户裁决(补 `depends_on`、拆任务或开新 change)。',
2466
+ ];
2467
+ // 四属性契约(能力契约锚 · ADR-016 明示「该怎么干」类 ⇒ 留两册正文;两册不再要求逐字相同)。
2468
+ const PARALLEL_CONTRACT_BOOK_PHRASES = [
2469
+ '> **并行安全四属性契约**:契约对象是**四属性**,不是 worktree',
2470
+ '| ① | **写权限** | 每个写者必须有一条被守卫认可的写入通道 |',
2471
+ '| ③ | **验证隔离** | 同一时刻只有一个写者:全量判据不得与在飞写者并行 |',
2472
+ '出口校验锚 = `handoffRequests` 有 request 无对应 `handoffResult` ⇒ 新 change BLOCKED / 旧 change WARN;全部有 result ⇒ 放行;无证据 ⇒ 零输出',
2473
+ '**已撤回的 request 不构成在飞委托**',
2474
+ '`workflow-handoff.mjs withdraw <task-id> --by <来源>` 在原记录上留痕 `withdrawnAt` + `withdrawnBy`,已撤回 = 终态、历史不删',
2475
+ '**并同时注入桥接通道标记 `FLOW_COMET_AGENT_DEPTH_SOURCE`——守卫要求标记与深度同时在场才接受该通道**',
2476
+ '**写面含 gitignored 面的任务(四属性映射 · 与其他任务同一判据)**',
2477
+ '① **写权限**仍走**身份通道**',
2478
+ '② **提交隔离**走既有 **`noCommit` 资格**',
2479
+ '**并行 × 零提交**因此合法',
2480
+ '**留痕的边界(诚实声明 · 与 `directOverride` / `completedChecks` / `reentryAuthorization` 同族)**',
2481
+ '留痕记录的是「**发生过委派**」,**不是**对执行者身份的物理证明',
2482
+ '与 `completedChecks` 只能记录声明、`directOverride` 只能记录授权、`reentryAuthorization` 只能记录授权源同理',
2483
+ ];
2484
+ // 四属性的四个属性名(硬约束要求保留的能力契约锚;两册正文逐册在场)。
2485
+ const PARALLEL_CONTRACT_ATTRIBUTE_NAMES = ['**写权限**', '**提交隔离**', '**验证隔离**', '**集成纪律**'];
2486
+ // 证据与判级类判别句(ADR-016 ⑥:随平台事实移走)——只在 `platform-facts.md`,回流册子即红。
2487
+ const CONTRACT_EVIDENCE_AUTHORITY_PHRASES = [
2488
+ '**+ 通道标记 `FLOW_COMET_AGENT_DEPTH_SOURCE`**;0 / 缺失 / 无标记 = 协调者',
2489
+ '**证实**——Codex 交互式会话的原生子代理载荷含 `agent_id`',
2490
+ '**推翻**——「Codex 载荷无身份字段」只对 `codex exec` headless 主线程成立,**不得外推**为平台结论。',
2491
+ '**未覆盖(显式标注,不得写成已支持)**',
2492
+ '> | **Claude Code** | 身份分派(载荷含 `agent_id` / `agent_type`——**证实**:真机实测子代理载荷含二者、主会话载荷不含,与 Codex 同一判据)',
2493
+ 'CC 子代理载荷含 `agent_id` / `agent_type`(真机实测:子代理载荷含二者、主会话载荷不含,与 Codex 同一判据)',
2494
+ '非 `bypassPermissions` 权限模式下的载荷形态',
2495
+ ];
2496
+ // 两册各自须持的三个条件句指针(`reference/fix-loop.md` 属修复回路段,见场景 258)。
2497
+ const DELEGATION_POINTER_RELS = [
2498
+ 'reference/commit-discipline.md', 'reference/platform-facts.md', 'reference/fix-loop.md',
2499
+ ];
2500
+ function delegationDisciplineProblems({ books, elementDocs, authorityTexts }) {
2501
+ const problems = [];
2502
+ for (const [rel, text] of elementDocs) {
2503
+ for (const [label, tokens] of COMMIT_DISCIPLINE_ELEMENT_GROUPS) {
2504
+ const missing = tokens.filter((token) => !text.includes(token));
2505
+ if (missing.length > 0) {
2506
+ problems.push(rel + ' 缺「' + label + '」要点句(缺 token: ' + missing.join(' / ') + ')');
2507
+ }
2508
+ }
2509
+ }
2510
+ const authorityText = authorityTexts.get(COMMIT_DISCIPLINE_REL);
2511
+ for (const phrase of COMMIT_DISCIPLINE_AUTHORITY_PHRASES) {
2512
+ if (!authorityText.includes(phrase)) {
2513
+ problems.push(COMMIT_DISCIPLINE_REL + ' 缺权威处判别句:' + phrase.slice(0, 40) + '…');
2514
+ }
2515
+ for (const [rel, text] of books) {
2516
+ if (text.includes(phrase)) {
2517
+ problems.push(rel + ' 回流了 ' + COMMIT_DISCIPLINE_REL + ' 的权威处正文:' + phrase.slice(0, 40) + '…');
2518
+ }
2519
+ }
2520
+ }
2521
+ for (const [rel, text] of books) {
2522
+ for (const phrase of PARALLEL_CONTRACT_BOOK_PHRASES) {
2523
+ if (!text.includes(phrase)) {
2524
+ problems.push(rel + ' 缺四属性契约判别句:' + phrase.slice(0, 40) + '…');
2525
+ }
2526
+ }
2527
+ for (const attribute of PARALLEL_CONTRACT_ATTRIBUTE_NAMES) {
2528
+ if (!text.includes(attribute)) {
2529
+ problems.push(rel + ' 缺四属性契约属性名:' + attribute);
2530
+ }
2531
+ }
2532
+ for (const pointer of DELEGATION_POINTER_RELS) {
2533
+ if (!text.includes(pointer)) {
2534
+ problems.push(rel + ' 缺条件句(指针不在场): ' + pointer);
2535
+ }
2536
+ }
2537
+ }
2538
+ const evidenceText = authorityTexts.get(PLATFORM_FACTS_REL);
2539
+ for (const phrase of CONTRACT_EVIDENCE_AUTHORITY_PHRASES) {
2540
+ if (!evidenceText.includes(phrase)) {
2541
+ problems.push(PLATFORM_FACTS_REL + ' 缺证据与判级判别句:' + phrase.slice(0, 40) + '…');
2542
+ }
2543
+ for (const [rel, text] of books) {
2544
+ if (text.includes(phrase)) {
2545
+ problems.push(rel + ' 回流了证据与判级判别句:' + phrase.slice(0, 40) + '…(权威处唯一)');
2546
+ }
2547
+ }
2548
+ }
2549
+ return problems;
2550
+ }
2551
+
2552
+ // 前端判据散文口径(场景 286 使用;纯函数 + 合成文本面可驱动):ADR-016 把原「五份文本**各自**
2553
+ // 陈述五个结构 token」重定向为「**一处权威**(`flow-comet-ui-design` 册的「触发与跳过」段陈述
2554
+ // 结构形态三种 + 词形边界 + 命中片段回显)+ **各引用册指针在场**(条件句指向该册,缺即红)+
2555
+ // **该口径正文唯一**(块级跨距:任何其它分发文本不得含权威口径段的 ≥ `FRONTEND_CRITERION_BLOCK_SPAN`
2556
+ // 字符逐字副本——短片段(要素名 / 命令形态 / 互指指针 / 压缩要点句)天然重合,按 T-03 实测建议
2557
+ // 取块级跨距,避免必然假红)。反向构造的目标随之从「每份文本」改到**权威处**。
2558
+ const FRONTEND_CRITERION_AUTHORITY_REL = 'flow-comet-ui-design/SKILL.md';
2559
+ const FRONTEND_CRITERION_BLOCK_SPAN = 120;
2560
+ // 各引用册的指针判别句式(逐册 token 组:必须同指该唯一权威,缺一册即红)。
2561
+ const FRONTEND_CRITERION_POINTER_RELS = [
2562
+ ['flow-comet/SKILL.md', ['唯一权威是 `flow-comet-ui-design` 册']],
2563
+ ['flow-comet-design/SKILL.md', ['唯一权威 → `flow-comet-ui-design` 册', '「触发与跳过」段']],
2564
+ ['flow-comet-change/SKILL.md', ['**判据与强制等级(唯一权威)**', '`flow-comet-ui-design` 册的「触发与跳过」段']],
2565
+ ];
2566
+ function frontendCriterionAuthorityBlock(text) {
2567
+ const match = /「结构形态」的三种任一[\s\S]*?仍判前端。/.exec(text);
2568
+ return match ? match[0] : null;
2569
+ }
2570
+ function frontendCriterionRedirectProblems({ authorityRel, authorityText, pointerDocs, docs }) {
2571
+ const problems = [];
2572
+ // ① 一处权威:结构形态五 token 齐备(同一判据前端散文函数)+ 旧口径零残留。
2573
+ problems.push(...frontendCriterionProseProblems(authorityRel, authorityText));
2574
+ const block = frontendCriterionAuthorityBlock(authorityText);
2575
+ if (block === null) {
2576
+ problems.push(authorityRel + ' 缺权威口径段(「结构形态」三种任一 → 仍判前端 的整段)');
2577
+ } else if (block.length < FRONTEND_CRITERION_BLOCK_SPAN) {
2578
+ problems.push(authorityRel + ' 权威口径段过短(' + block.length + ' 字符 < '
2579
+ + FRONTEND_CRITERION_BLOCK_SPAN + ')——正文唯一性判据无从成立');
2580
+ }
2581
+ // ② 各引用册指针在场:每册须含指向该权威的条件句(缺任一册即红)。
2582
+ for (const [rel, tokens] of FRONTEND_CRITERION_POINTER_RELS) {
2583
+ const text = pointerDocs.get(rel);
2584
+ if (text === undefined) {
2585
+ problems.push(rel + ' 不在场(前端判据的引用册指针无从校验)');
2586
+ continue;
2587
+ }
2588
+ const missing = tokens.filter((token) => !text.includes(token));
2589
+ if (missing.length > 0) {
2590
+ problems.push(rel + ' 指针不在场(缺指向 ' + authorityRel + ' 的条件句 token: ' + missing.join(' / ') + ')');
2591
+ }
2592
+ }
2593
+ // ③ 正文唯一:权威口径段不得在第二份分发文本里逐字出现(块级跨距)。
2594
+ if (block !== null) {
2595
+ for (const [rel, text] of docs) {
2596
+ if (rel === authorityRel) continue;
2597
+ const span = longestCommonSpan(block, text);
2598
+ if (span.length >= FRONTEND_CRITERION_BLOCK_SPAN) {
2599
+ problems.push(rel + ' 出现结构判据口径的第二份正文(连续同文 ' + span.length + ' 字符 ≥ '
2600
+ + FRONTEND_CRITERION_BLOCK_SPAN + ')——权威处唯一');
2601
+ }
2602
+ }
2603
+ }
2604
+ return problems;
2605
+ }
2606
+
2607
+ // 修复回路状态机路径(场景 258 使用;纯函数 + 合成输入可驱动):ADR-016 把「三册段正文 sha256
2608
+ // 完全一致」的逐字锁重定向为「三册各含要点句与条件句 + 该段正文**仅一处**(权威 =
2609
+ // `reference/fix-loop.md`)+ 原 6 个关键词与『禁 `advance` 作正常路径』断言**迁到权威处**」。
2610
+ // 要点句取**要素级 token 组**(措辞可分叉——ADR-016 明示三册口径一致但不再要求逐字相同);
2611
+ // 「仅一处」用块级跨距(连续同文 ≥ `FIX_LOOP_BLOCK_SPAN` 字符)判:册子的要点句与权威段落天然
2612
+ // 局部重合(公式化命令形态 / 要素名),短片段不计——只有把权威段落**整段复制回册子**才红。
2613
+ const FIX_LOOP_AUTHORITY_REL = 'flow-comet/reference/fix-loop.md';
2614
+ const FIX_LOOP_SECTION_HEADING = '## 修复回路状态机路径';
2615
+ const FIX_LOOP_AUTHORITY_KEYWORDS = [
2616
+ '受控归位', 'NODE: execute', '回源节点跑出口', 'entry <源节点>', 'exit <源节点> --apply', '禁止绕过',
2617
+ ];
2618
+ const FIX_LOOP_BLOCK_SPAN = 120;
2619
+ const FIX_LOOP_BOOK_ELEMENT_GROUPS = [
2620
+ ['追加 Fix 任务', ['## Fix 任务', '禁止文件尾追加']],
2621
+ ['受控归位 execute', ['受控归位', 'NODE: execute']],
2622
+ ['execute 四类出口', ['record execute', 'exit execute --apply', '任务集签名']],
2623
+ ['回源节点跑出口', ['回源节点跑出口', 'entry <源节点>', 'exit <源节点> --apply']],
2624
+ ['禁止绕过', ['禁止绕过', 'BLOCKED']],
2625
+ ['条件句指针', ['reference/fix-loop.md']],
2626
+ ];
2627
+ // 段切片(同一区间:首个 `## 修复回路状态机路径` → 下一 `##` 或 EOF,标题不计入)。
2628
+ function fixLoopStateMachineSectionOf(text) {
2629
+ const match = text.match(/(?:^|\r?\n)## 修复回路状态机路径\r?\n([\s\S]*?)(?=\r?\n## |$)/);
2630
+ return match ? match[1].replace(/\r\n/g, '\n') : null;
2631
+ }
2632
+ function fixLoopStateMachineProblems({ books, authority }) {
2633
+ const problems = [];
2634
+ for (const [rel, text] of books) {
2635
+ const section = fixLoopStateMachineSectionOf(text);
2636
+ if (section === null) {
2637
+ problems.push(rel + ' SKILL.md 缺「' + FIX_LOOP_SECTION_HEADING + '」段');
2638
+ continue;
2639
+ }
2640
+ if (section.trim() === '') problems.push(rel + ' 修复回路状态机路径段不得为空');
2641
+ for (const [label, tokens] of FIX_LOOP_BOOK_ELEMENT_GROUPS) {
2642
+ const missing = tokens.filter((token) => !section.includes(token));
2643
+ if (missing.length > 0) {
2644
+ problems.push(rel + ' 缺「' + label + '」要点句(缺 token: ' + missing.join(' / ') + ')');
2645
+ }
2646
+ }
2647
+ // 反捷径(册内一侧):`advance` 不作正常路径;「直接 exit 源节点收场」只允许以被禁形态出现。
2648
+ if (section.includes('advance')) {
2649
+ problems.push(rel + ' 修复回路状态机路径段不得把 advance 作为正常路径');
2650
+ }
2651
+ for (const line of section.split(/\r?\n/)) {
2652
+ if (line.includes('直接') && line.includes('exit') && !/禁止|不得|会被 BLOCKED/.test(line)) {
2653
+ problems.push(rel + ' 修复回路状态机路径段不得把直接 exit 源节点收场作为正常路径: ' + line.trim());
2654
+ }
2655
+ }
2656
+ }
2657
+ // 权威处:原 6 个关键词 + 反 advance + 「禁止直接 exit 收场」断言全部迁到该文件。
2658
+ const authoritySection = fixLoopStateMachineSectionOf(authority);
2659
+ if (authoritySection === null) {
2660
+ problems.push(FIX_LOOP_AUTHORITY_REL + ' 缺「' + FIX_LOOP_SECTION_HEADING + '」段(唯一权威处缺失)');
2661
+ return problems;
2662
+ }
2663
+ for (const keyword of FIX_LOOP_AUTHORITY_KEYWORDS) {
2664
+ if (!authoritySection.includes(keyword)) {
2665
+ problems.push(FIX_LOOP_AUTHORITY_REL + ' 修复回路段缺关键词: ' + keyword);
2666
+ }
2667
+ }
2668
+ if (authoritySection.includes('advance')) {
2669
+ problems.push(FIX_LOOP_AUTHORITY_REL + ' 修复回路段不得把 advance 作为正常路径');
2670
+ }
2671
+ let hasForbiddenForm = false;
2672
+ for (const line of authoritySection.split(/\r?\n/)) {
2673
+ if (line.includes('直接') && line.includes('exit') && /禁止|不得|会被 BLOCKED/.test(line)) hasForbiddenForm = true;
2674
+ if (line.includes('直接') && line.includes('exit') && !/禁止|不得|会被 BLOCKED/.test(line)) {
2675
+ problems.push(FIX_LOOP_AUTHORITY_REL + ' 修复回路段不得把直接 exit 源节点收场作为正常路径: ' + line.trim());
2676
+ }
2677
+ }
2678
+ if (!hasForbiddenForm) {
2679
+ problems.push(FIX_LOOP_AUTHORITY_REL + ' 修复回路段缺「禁止直接 exit 源节点收场」的显式断言(原册内断言未随迁)');
2680
+ }
2681
+ // 正文唯一:权威段落整段回流任一册即红(块级跨距 ≥ FIX_LOOP_BLOCK_SPAN)。比对面取**整册正文**:
2682
+ // 复制回流的落点不限于同名小节(换个标题贴进别处同样算第二份正文)。
2683
+ for (const [rel, text] of books) {
2684
+ const span = longestCommonSpan(authoritySection, text);
2685
+ if (span.length >= FIX_LOOP_BLOCK_SPAN) {
2686
+ problems.push(rel + ' 出现 ' + FIX_LOOP_AUTHORITY_REL + ' 的第二份正文(该段正文仅一处;连续同文 '
2687
+ + span.length + ' 字符 ≥ ' + FIX_LOOP_BLOCK_SPAN + ')');
2688
+ }
2689
+ }
2690
+ return problems;
2691
+ }
2692
+
2693
+ // 技能树正文里的**相对路径引用必须解析得到**(场景 184 附;纯函数 + 合成输入可驱动):本轮
2694
+ // `GUIDANCE.md` → `reference/entry-detail.md` 的改名曾造成 5 册死引用而**零红灯**——技能树正文的
2695
+ // 相对引用此前没有任何机检覆盖(只能靠人工/子代理顺带发现)。判据面刻意收窄到技能树内的
2696
+ // `reference/**.md|json` 相对引用。
2697
+ // **解析基准 = 引用处所在册的册根**(不是「任何册都按入口册册根解析」):裸形态 `reference/<file>`
2698
+ // 是**册根相对**形态,故候选 = ① 引用处文件所在目录(入口册 `SKILL.md` 与入口册 `reference/**`
2699
+ // 展开面正是这一形态);② 引用处**所在册的册根**(`<册>/reference/<file>`,覆盖展开面文件引用
2700
+ // 同册兄弟文件的写法)。跨册引用必须写**显式形态** `../flow-comet/reference/<file>`(先例 =
2701
+ // `flow-comet-compose` 引 `../flow-comet/reference/workflow-protocol.json`),只对该形态接受
2702
+ // **入口册册根**这一额外候选——裸形态在节点册里因此**解析不到即红**:节点册没有 `reference/`
2703
+ // 目录,而旧实现给每个引用合成「入口册册根」第二候选,把节点册里的裸指针一律静默判绿
2704
+ //(**为抓这一类而写的锚放过了这一类的实例**,2026-10-11 实测)。
2705
+ // `flow-kit/**` 一类**技能树外**引用不在判据面(其根随安装形态变化,由项目根决定)。
2706
+ const SKILL_TREE_REFERENCE_RE = /(?<!flow-kit\/)(?<![\w./-])(?:\.\.\/flow-comet\/)?reference\/[A-Za-z0-9._-]+\.(?:md|json)/g;
2707
+ const SKILL_TREE_ENTRY_BOOK = 'flow-comet';
2708
+ const SKILL_TREE_EXPLICIT_REFERENCE_PREFIX = '../flow-comet/';
2709
+ function skillTreeReferenceCandidates(rel, ref) {
2710
+ const tail = ref.replace(/^\.\.\/flow-comet\//, '');
2711
+ const explicit = ref.startsWith(SKILL_TREE_EXPLICIT_REFERENCE_PREFIX);
2712
+ // 裸形态按**引用处所在册的册根**解析;跨册解析只对显式形态开放(收窄点)。
2713
+ const crossBookRoot = explicit ? SKILL_TREE_ENTRY_BOOK : rel.split('/')[0];
2714
+ return [
2715
+ path.posix.normalize(path.posix.join(path.posix.dirname(rel), ref)),
2716
+ path.posix.normalize(path.posix.join(crossBookRoot, tail)),
2717
+ ];
2718
+ }
2719
+ function skillTreeReferenceProblems(docs, skillsRoot) {
2720
+ const problems = [];
2721
+ for (const [rel, text] of docs) {
2722
+ for (const ref of new Set(text.match(SKILL_TREE_REFERENCE_RE) ?? [])) {
2723
+ const candidates = skillTreeReferenceCandidates(rel, ref);
2724
+ if (!candidates.some((candidate) => fs.existsSync(path.join(skillsRoot, candidate)))) {
2725
+ problems.push(rel + ' 的相对路径引用解析不到: ' + ref + '(候选: ' + candidates.join(' / ') + ')');
2726
+ }
2727
+ }
2728
+ }
2729
+ return problems;
2730
+ }
2731
+
2732
+ // **成对展开文件的指针不得指错**(场景 184 附 2;纯函数 + 合成输入可驱动):本仓是「`SKILL.md` 手写区 +
2733
+ // **同目录同名 `GUIDANCE.md` 展开版**」的成对形态——册首注释里的**裸文件名**指本册自己那份。修"死引用"
2734
+ // 的过程里四册曾被改成指向**入口册**的展开版(`../flow-comet/reference/entry-detail.md`):目标确实存在、
2735
+ // 上面那条解析判据全绿,但它**指错了文档**,各册展开版里的独有内容从此再无入口可读——「**能解析 ≠ 指对了**」。
2736
+ // 判据 = ① 同目录有同名 `GUIDANCE.md` 的册 ⇒ 指针必须是裸文件名 `GUIDANCE.md`(本册那份);
2737
+ // ② 入口册(无同名展开版,展开版为 `reference/entry-detail.md`)⇒ **唯一例外**,指针必须是该文件;
2738
+ // ③ 既无同名展开版又非入口册的册 ⇒ 不允许出现该指针(在册里指谁都是指错)。
2739
+ // 取目标用**注释整句的捕获组**(不是"是否含 `GUIDANCE.md` 子串")——裸子串判据会被同文件其它
2740
+ // 上下文满足而恒真空过(L-106),下文的反向构造即证「换成别处的展开版必红」。
2741
+ const PAIRED_GUIDANCE_ENTRY_REL = 'flow-comet/SKILL.md';
2742
+ const PAIRED_GUIDANCE_ENTRY_TARGET = 'reference/entry-detail.md';
2743
+ const PAIRED_GUIDANCE_POINTER_RE = /<!--\s*手写区详细协议见\s*([^\s()]+)(可选阅读)\s*-->/g;
2744
+ function pairedGuidancePointerProblems(docs, skillsRoot) {
2745
+ const problems = [];
2746
+ for (const [rel, text] of docs) {
2747
+ if (!rel.endsWith('/SKILL.md')) continue;
2748
+ const dir = path.posix.dirname(rel);
2749
+ if (dir.includes('/')) continue; // 只判册根层(`<册>/SKILL.md`)
2750
+ const targets = [...text.matchAll(PAIRED_GUIDANCE_POINTER_RE)].map((match) => match[1]);
2751
+ const hasOwnGuidance = fs.existsSync(path.join(skillsRoot, dir, 'GUIDANCE.md'));
2752
+ if (targets.length === 0) {
2753
+ if (hasOwnGuidance) {
2754
+ problems.push(rel + ' 缺「手写区详细协议见 …」指针(同目录有 GUIDANCE.md ⇒ 指针须在场且指向本册)');
2755
+ }
2756
+ continue;
2757
+ }
2758
+ if (targets.length > 1) {
2759
+ problems.push(rel + ' 的「手写区详细协议见 …」指针出现 ' + targets.length + ' 处(只允许 1 处)');
2760
+ }
2761
+ const expected = hasOwnGuidance ? 'GUIDANCE.md'
2762
+ : (rel === PAIRED_GUIDANCE_ENTRY_REL ? PAIRED_GUIDANCE_ENTRY_TARGET : null);
2763
+ if (expected === null) {
2764
+ problems.push(rel + ' 的「手写区详细协议见 …」指针指向 ' + targets.join(' / ')
2765
+ + ',但该册既无同目录 GUIDANCE.md 也非入口册(无配对展开版即不得保留指针)');
2766
+ continue;
2767
+ }
2768
+ for (const target of targets) {
2769
+ if (target !== expected) {
2770
+ problems.push(rel + ' 的「手写区详细协议见 ' + target + '」指错文档(应为 ' + expected + ')');
2771
+ }
2772
+ }
2773
+ }
2774
+ return problems;
2775
+ }
2776
+
2777
+ // CC 行判级升格 + 三平台 cwd 语义对照(场景 184 的 ⑦ 使用;纯函数 + 合成文本面可驱动):判级由
2778
+ // 「未覆盖」升为「证实」后,落地形态由**两处**承载——入口册(用户可见总表 + 已知边界旁的三平台
2779
+ // `cwd` 对照,7 条字面量是能力契约锚,本批明文保留)与 `reference/platform-facts.md`(原
2780
+ // `reference/worktree-notes.md` 的同一批整句随文件移出技能树后**逐字搬入**的新落点)。判据:
2781
+ // 「两处正文在场 + 其余册零回流(唯一处)+ 旧「未覆盖」判级句零残留」。
2782
+ const IDENTITY_UPGRADE_ENTRY_PHRASES = [
2783
+ '| ① 写权限 | 载荷 `agent_id` / `agent_type`——**证实**(真机实测:子代理载荷含二者、主会话载荷不含;与 Codex 同一判据) |',
2784
+ '**三平台 `cwd` 语义对照(真机实测新增的精确事实 · 「身份先于路径」的精确理由)**',
2785
+ '| **Claude Code** | **子代理的工作目录**(`…\\.claude\\worktrees\\<agent-id>`) | **路径判定是正确的** |',
2786
+ '| **Codex** | **恒等于会话根**(子代理在 worktree 写入而 `cwd` 仍是主工程) | **路径判定必错** |',
2787
+ '| **dsh** | 载荷**无** `cwd`(桥接另读会话 header cwd) | 路径判定**不适用** |',
2788
+ '三平台 `cwd` 语义各不相同(正确 / 恒错 / 无)——只有身份判据是三平台同义的',
2789
+ '非 `bypassPermissions` 权限模式**均未覆盖**',
2790
+ ];
2791
+ const IDENTITY_UPGRADE_AUTHORITY_PHRASES = [
2792
+ '载荷 `agent_id` / `agent_type`——**证实**(真机实测:子代理载荷含二者、主会话载荷不含;与 Codex 同一判据)',
2793
+ '**三平台 `cwd` 语义对照(真机实测新增的精确事实 · 「身份先于路径」的精确理由)**——同为载荷 `cwd`,三平台语义各不相同;下表**三行各自独立**,缺一行即口径残缺:',
2794
+ '| **Claude Code** | **子代理的工作目录**(`…\\.claude\\worktrees\\<agent-id>`) | **路径判定是正确的** |',
2795
+ '| **Codex** | **恒等于会话根**(子代理在 worktree 写入而 `cwd` 仍是主工程) | **路径判定必错** |',
2796
+ '| **dsh** | 载荷**无** `cwd`(桥接另读会话 header cwd) | 路径判定**不适用** |',
2797
+ '三平台 `cwd` 语义各不相同(正确 / 恒错 / 无)——只有身份判据是三平台同义的',
2798
+ ];
2799
+ const IDENTITY_UPGRADE_STALE_PHRASES = ['该次实测只覆盖 Codex', '真机会话复核待补', 'CC 隔离树的真实落点探针待补'];
2800
+ function identityUpgradeProblems({ entry, facts, others }) {
2801
+ const problems = [];
2802
+ for (const phrase of IDENTITY_UPGRADE_ENTRY_PHRASES) {
2803
+ if (!entry.includes(phrase)) {
2804
+ problems.push('flow-comet/SKILL.md 缺「CC 行升格 / 三平台 cwd 对照」判别句式:' + phrase.slice(0, 40) + '…');
2805
+ }
2806
+ }
2807
+ for (const phrase of IDENTITY_UPGRADE_AUTHORITY_PHRASES) {
2808
+ if (!facts.includes(phrase)) {
2809
+ problems.push(PLATFORM_FACTS_REL + ' 缺「CC 行升格 / 三平台 cwd 对照」判别句式:' + phrase.slice(0, 40) + '…');
2810
+ }
2811
+ }
2812
+ const carried = [...IDENTITY_UPGRADE_ENTRY_PHRASES, ...IDENTITY_UPGRADE_AUTHORITY_PHRASES];
2813
+ for (const [rel, text] of others) {
2814
+ for (const phrase of carried) {
2815
+ if (text.includes(phrase)) {
2816
+ problems.push(rel + ' 回流了 cwd 对照 / CC 判级句(唯一处 = 入口册 + 平台事实册):'
2817
+ + phrase.slice(0, 40) + '…');
2818
+ }
2819
+ }
2820
+ }
2821
+ for (const [rel, text] of [['flow-comet/SKILL.md', entry], [PLATFORM_FACTS_REL, facts]]) {
2822
+ for (const stale of IDENTITY_UPGRADE_STALE_PHRASES) {
2823
+ if (text.includes(stale)) {
2824
+ problems.push(rel + ' 残留 CC 行旧「未覆盖」判级表述:' + stale);
2825
+ }
2826
+ }
2827
+ }
2828
+ return problems;
2829
+ }
2830
+
2831
+ // 平台事实(场景 184 的 ⑤ / ⑦ 使用;纯函数 + 合成输入可驱动):Codex 平台事实与支持面的判别句
2832
+ // 随 `worktree-notes.md` 移出技能树后**唯一权威处** = `flow-comet/reference/platform-facts.md`
2833
+ //(T07 已按「逐字搬运,不重写」搬入)。判据三侧:① 权威处在场(判别句 + 旧独断句只允许被反驳
2834
+ // 引用形态 + 适用范围限定 + fail-open / 未闭合的现判据);② 各引用册**指针在场**;③ **证据正文
2835
+ // 不回流册子**(权威处唯一——原逐字锁「多处各持一份」的方向已反转)。
2836
+ // `PLATFORM_FACTS_ONLY_PHRASES` 是**证据与过程记录**类判别句(按 ADR-016 的「证据与判级随平台事实
2837
+ // 移走」分类):它们只允许出现在权威处,回流任一册即红。
2838
+ const PLATFORM_FACTS_ONLY_PHRASES = [
2839
+ '**旧结论(实测 2026-08-13;证据已不可复核',
2840
+ '`codex features list` 可查',
2841
+ '本机真实交互式会话日志中记录到 `spawn_agent` / `wait_agent` / `close_agent` 的实际调用',
2842
+ '**静态喂测(独立复现)**',
2843
+ '**hook 触发条件**:隔离 `CODEX_HOME` 无持久信任时默认 headless **不执行**项目 hook',
2844
+ '实测 3/21;补 `--dangerously-bypass-approvals-and-sandbox` 后 5/5',
2845
+ '**交互式 Codex 实测口径',
2846
+ ];
2847
+ function platformFactsAuthorityProblems(rel, facts, pointerBooks) {
2848
+ const problems = [];
2849
+ const refutedClaim = '「Codex 不能委派 / 不使用并行委托」';
2850
+ for (const keyword of ['multi_agent', '机制缺口']) {
2851
+ if (!facts.includes(keyword)) {
2852
+ problems.push(rel + ' 缺「' + keyword + '」(Codex 平台事实与支持面判别锚)');
2853
+ }
2854
+ }
2855
+ // 旧独断句只允许以被反驳引用的完整形态出现:剥离该引用后不得再有残句。
2856
+ if (facts.split(refutedClaim).join('').includes('不使用并行委托')) {
2857
+ problems.push(rel + ' 残留旧独断句「不使用并行委托」(非被反驳引用形态)');
2858
+ }
2859
+ if (!facts.includes('不得外推') && !facts.includes('不可外推')) {
2860
+ problems.push(rel + ' 缺「不得外推 / 不可外推」适用范围限定');
2861
+ }
2862
+ for (const keyword of ['fail-open', '未闭合']) {
2863
+ if (!facts.includes(keyword)) {
2864
+ problems.push(rel + ' 缺「' + keyword + '」(Codex/worktree 订正限定)');
2865
+ }
2866
+ }
2867
+ for (const [stale, label] of [
2868
+ ['受支持的工作流仍是串行执行', '旧独断句'],
2869
+ ['写入仍会被协调者白名单拦截', '旧过宽句'],
2870
+ ]) {
2871
+ if (facts.includes(stale)) problems.push(rel + ' 残留「' + stale + '」' + label);
2872
+ }
2873
+ for (const phrase of PLATFORM_FACTS_ONLY_PHRASES) {
2874
+ if (!facts.includes(phrase)) {
2875
+ problems.push(rel + ' 缺证据与过程记录判别句:' + phrase.slice(0, 40) + '…');
2876
+ }
2877
+ }
2878
+ for (const [bookRel, text] of pointerBooks) {
2879
+ if (!text.includes('reference/platform-facts.md')) {
2880
+ problems.push(bookRel + ' 缺「reference/platform-facts.md」条件句(平台事实的引用册指针不在场)');
2881
+ }
2882
+ for (const phrase of PLATFORM_FACTS_ONLY_PHRASES) {
2883
+ if (text.includes(phrase)) {
2884
+ problems.push(bookRel + ' 回流了平台事实的证据正文:' + phrase.slice(0, 40) + '…(权威处唯一)');
2885
+ }
2886
+ }
2887
+ if (text.includes('写入会被协调者白名单拦截')) {
2888
+ problems.push(bookRel + ' 残留「写入会被协调者白名单拦截」旧过宽句');
2889
+ }
2890
+ }
2891
+ return problems;
2892
+ }
2893
+
2894
+ // 模板权威声明(场景 184 的 ② 使用;纯函数 + 合成文档面可驱动):ADR-016 把原「14 册同持整句」
2895
+ // 的逐字锁重定向为「单一权威 + 指针在场 + 正文唯一」三件套。本函数是**单一实现**——真实判据与
2896
+ // 反向构造探针共用,逐条对应重定向后的一侧:
2897
+ // · 指针在场:每份文档须含模板权威锚句,句内按序组合五个锚点(整句语义组合,防拆句 / 半句);
2898
+ // · 该句只在 1 处(册内一侧):同一文档出现第二处锚行即红(重复回潮的同册形态);
2899
+ // · 单一权威:持锚行必须点名 `flow-kit/templates/**`——段形权威只能指向这一个来源;
2900
+ // · 正文唯一(声明块的**正文部分**):判据面 = 锚行所在的 `>` 块**减去锚行本身**——锚行是全册
2901
+ // **按形态要求必须持有**的指针句(「本节点」9 册 / 「本技能」5 册逐字同文属**设计要求**,不是
2902
+ // 重复),把它算进判据面必然要么假红要么恒真;块内锚行之外的正文行才是「第二份正文」的入口。
2903
+ // 阈值**按对派生自受保护内容**:一对正文以**较短一侧的实际块长**为界——只要一侧的正文整段
2904
+ // (或更长)出现在另一侧即红,两侧各写各的措辞不误伤。**旧写死阈值 400 的教训**(`LESSONS`
2905
+ // 候选取证):旧判据面含锚行且阈值写死 400,而实测块长只有 109 / 211(入口册与
2906
+ // `reference/entry-detail.md` 曾各持同一段 211 字符块 = 锚行 + archive 读法行)⇒ 锚**数学
2907
+ // 不可触发**、真实重复就在眼前却恒绿(Coverage Illusion 型假绿);阈值改为从受保护内容派生
2908
+ // 后,该对真实重复当场变红,本批同批把重复收成「一处 + 指针」。
2909
+ const TEMPLATE_AUTHORITY_SKILLS = [
2910
+ 'flow-comet-open', 'flow-comet-design', 'flow-comet-plan', 'flow-comet-execute',
2911
+ 'flow-comet-subagent-execute', 'flow-comet-review', 'flow-comet-verify', 'flow-comet-archive',
2912
+ 'flow-comet-task',
2913
+ 'flow-comet-change', 'flow-comet-requirement', 'flow-comet-dev', 'flow-comet-test',
2914
+ 'flow-comet-integration',
2915
+ ];
2916
+ const TEMPLATE_AUTHORITY_ANCHORS = [
2917
+ '唯一权威 = ', '`flow-kit/templates/**`', '是历史证据', '不是模板来源', '上一轮就是这么写的',
2918
+ ];
2919
+ // 整句形态**专有**的展开锚点(短指针形态不含):出现任一条即要求整句按序齐备(半句 / 拆句防护)。
2920
+ const TEMPLATE_AUTHORITY_EXPANSION_ANCHORS = [
2921
+ '唯一权威 = ', '是历史证据', '不是模板来源', '上一轮就是这么写的',
2922
+ ];
2923
+ // 「模板权威」声明的**段落切片**:锚行所在的那一段连续引用行(`>` 块)——正文唯一判据的判据面。
2924
+ function templateAuthorityParagraphs(text) {
2925
+ const lines = text.split(/\r?\n/);
2926
+ const out = [];
2927
+ for (let i = 0; i < lines.length; i += 1) {
2928
+ if (!lines[i].includes('模板权威')) continue;
2929
+ let start = i;
2930
+ while (start > 0 && lines[start - 1].startsWith('>')) start -= 1;
2931
+ let end = i;
2932
+ while (end + 1 < lines.length && lines[end + 1].startsWith('>')) end += 1;
2933
+ out.push(lines.slice(start, end + 1).join('\n'));
2934
+ }
2935
+ return out;
2936
+ }
2937
+ // 声明块的**正文部分** = 块内锚行之外的引用行(锚行是每册必须逐字持有的指针句,见上;空串 =
2938
+ // 该册只有锚行一行,正文唯一判据对它不发声——「只持指针」是设计要求,不是重复)。
2939
+ function templateAuthorityBody(paragraph) {
2940
+ return paragraph.split('\n').filter((line) => !line.includes('模板权威')).join('\n');
2941
+ }
2942
+ // 最长连续同文跨距(返回该片段本身;空串 = 无重合)。
2943
+ function longestCommonSpan(a, b) {
2944
+ const left = String(a);
2945
+ const right = String(b);
2946
+ let best = '';
2947
+ const dp = new Array(right.length + 1).fill(0);
2948
+ for (let i = 1; i <= left.length; i += 1) {
2949
+ let prev = 0;
2950
+ for (let j = 1; j <= right.length; j += 1) {
2951
+ const tmp = dp[j];
2952
+ if (left[i - 1] === right[j - 1]) {
2953
+ dp[j] = prev + 1;
2954
+ if (dp[j] > best.length) best = left.slice(i - dp[j], i);
2955
+ } else {
2956
+ dp[j] = 0;
2957
+ }
2958
+ prev = tmp;
2959
+ }
2960
+ }
2961
+ return best;
2962
+ }
2963
+ function templateAuthorityProblems(docs) {
2964
+ const problems = [];
2965
+ const paragraphs = [];
2966
+ for (const [rel, text] of docs) {
2967
+ const lines = text.split(/\r?\n/).filter((line) => line.includes('模板权威'));
2968
+ if (lines.length === 0) {
2969
+ problems.push(rel + ' 缺模板权威整句声明(正向权威 + 反向历史证据组合缺失)');
2970
+ continue;
2971
+ }
2972
+ if (lines.length > 1) {
2973
+ problems.push(rel + ' 模板权威锚句出现 ' + lines.length + ' 处(同一册只允许 1 处)');
2974
+ }
2975
+ const line = lines[0];
2976
+ // 指针在场(两形态皆算、缺一即红):① **短指针形态**——点名唯一权威 `flow-kit/templates/**`;
2977
+ // ② **整句形态**——锚点按序组合(正向权威 + 反向历史证据)。ADR-016 的方向是「13 册留短指针」,
2978
+ // 故两种形态都必须算通过(当前 14 册为整句形态、入口册与入口展开册为短指针形态,判据对**两种
2979
+ // 布局都成立**——书籍侧若按 ADR 收敛成短指针,本锚不会因此变红)。
2980
+ if (!line.includes('`flow-kit/templates/**`')) {
2981
+ problems.push(rel + ' 的模板权威行未指向 `flow-kit/templates/**`(段形权威被指到别处)');
2982
+ }
2983
+ if (!line.includes('唯一权威')) {
2984
+ problems.push(rel + ' 的模板权威行未声明「唯一权威」(指针未指向唯一来源)');
2985
+ }
2986
+ // 半句 / 拆句防护:一旦行内出现**整句形态专有**的展开锚点(历史证据 / 反向声明 / 收口句),
2987
+ // 五个锚点必须按序齐备(不得只留半句)——短指针形态只点名唯一权威,不触发本项。
2988
+ const expansionAnchors = TEMPLATE_AUTHORITY_EXPANSION_ANCHORS.filter((anchor) => line.includes(anchor));
2989
+ if (expansionAnchors.length > 0) {
2990
+ let cursor = -1;
2991
+ for (const anchor of TEMPLATE_AUTHORITY_ANCHORS) {
2992
+ const at = line.indexOf(anchor, cursor + 1);
2993
+ if (at < 0) {
2994
+ problems.push(rel + ' 模板权威整句缺「' + anchor + '」(整句语义组合)');
2995
+ } else {
2996
+ cursor = at;
2997
+ }
2998
+ }
2999
+ }
3000
+ if (text.includes('archive 是模板来源')) {
3001
+ problems.push(rel + ' 含「archive 是模板来源」旧反向声明');
3002
+ }
3003
+ for (const paragraph of templateAuthorityParagraphs(text)) {
3004
+ paragraphs.push([rel, templateAuthorityBody(paragraph)]);
3005
+ }
3006
+ }
3007
+ for (let i = 0; i < paragraphs.length; i += 1) {
3008
+ for (let j = i + 1; j < paragraphs.length; j += 1) {
3009
+ const [relA, bodyA] = paragraphs[i];
3010
+ const [relB, bodyB] = paragraphs[j];
3011
+ if (relA === relB || bodyA === '' || bodyB === '') continue;
3012
+ const span = longestCommonSpan(bodyA, bodyB);
3013
+ // 阈值**按对派生自受保护内容**(较短一侧的实际正文块长):一侧的正文整段出现在另一侧即红。
3014
+ const derived = Math.min(bodyA.length, bodyB.length);
3015
+ if (span.length >= derived) {
3016
+ problems.push('模板权威声明出现第二份展开正文(' + relA + ' ↔ ' + relB
3017
+ + ',连续同文 ' + span.length + ' 字符 ≥ 较短一侧正文块长 ' + derived + ')');
3018
+ }
3019
+ }
3020
+ }
3021
+ return problems;
3022
+ }
3023
+ // 作者面完备性判据(纯函数;真实判据与反向构造探针共用):实际持「模板权威」声明的技能树文本
3024
+ // 必须**登记**在受检面(`TEMPLATE_AUTHORITY_SKILLS` + 入口册两件)里;未登记 ⇒ 报「未登记的
3025
+ // 权威声明」,报错指向真实动作(登记新册)。**单向判定**:受检面成员**缺**声明由
3026
+ // `templateAuthorityProblems` 的逐份「缺模板权威整句声明」覆盖,故不需要计数相等——计数相等
3027
+ // 正是同文件别处判据注释明确反对的「以总量取红」自锁探针(合法扩册先撞红,报错指向锚)。
3028
+ function templateAuthorityRegistrationProblems(actualHolders, expectedHolders) {
3029
+ const problems = [];
3030
+ for (const rel of actualHolders) {
3031
+ if (!expectedHolders.includes(rel)) {
3032
+ problems.push(rel + ' 持有「模板权威」声明但未登记在受检面(新增册须同批登记 TEMPLATE_AUTHORITY_SKILLS)');
3033
+ }
3034
+ }
3035
+ return problems;
3036
+ }
3037
+
3038
+ // ——— 7 字段集合的文本 ↔ 实现一致锚(场景 184 使用) ———
3039
+ // 唯一权威 = `workflow-guard.mjs` 的 `TASK7_REQUIRED` 常量(plan 出口判据的集合来源)。锚**从常量派生**
3040
+ // 集合后再与技能树文本逐处对账:任一处枚举与判据分叉即红——「两册三处而两级基线全绿」的成因正是
3041
+ // 「同一口径另写一份、且没有断言绑定」(`LESSONS` L-067);锚里**不得把集合再抄一遍**(抄一遍就是
3042
+ // 又造一处同口径表达)。
3043
+ const TASK7_AUTHORITY_CONSTANT = 'TASK7_REQUIRED';
3044
+ // 「7 字段」标记(中文 / 英文两形态):标记与枚举**同行**是当前唯一形态;标记行不带枚举(指针形态,
3045
+ // 如「集合见上表」)不算缺席——判据只对「标记 + 枚举」同场的行发声。
3046
+ const TASK7_MARKER_RE = /7\s*个?\s*字段|7 required fields|7-field set/;
3047
+ // 斜杠枚举形态(`` `name` / `read_files` / … ``;同时覆盖无引号的裸形态)。
3048
+ const TASK7_RUN_RE = /(?:`?[a-z][a-z_]*`?[ \t]*\/[ \t]*)+`?[a-z][a-z_]*`?/g;
3049
+ // **已知站点基线**(每站 = 该枚举行上独有的判别句式,即站点的身份):锚**逐站点**断言「该站点仍持与派生
3050
+ // 集合一致的枚举」——任一处丢失(改成指针 / 删掉该行 / 抽掉枚举)即红;**新增站点不受限**(自动进入逐处
3051
+ // 对账,不因新增而红)。身份**不用 `file:line`**:行号随无关编辑漂移,会把「无关改动」误判成「站点丢失」
3052
+ // (同族自锁——报错方向指向锚而非真实原因)。**站点集合是处数的唯一事实源**(无独立处数常量)。
3053
+ const TASK7_KNOWN_SITES = [
3054
+ { rel: 'flow-comet-plan/SKILL.md', anchor: '| TASK.md | 至少一个' },
3055
+ { rel: 'flow-comet-plan/SKILL.md', anchor: 'Populate 7 required fields per task' },
3056
+ { rel: 'flow-comet-plan/SKILL.md', anchor: 'the 7-field set' },
3057
+ { rel: 'flow-comet-task/SKILL.md', anchor: '**每任务 7 字段**' },
3058
+ ];
3059
+ // 探针期望哨兵:该探针要求**零问题**(合法新增站点不得被判违规)——与「必报某问题」的期望区分。
3060
+ const TASK7_ZERO_PROBLEMS = '(该探针要求零问题)';
3061
+
3062
+ // 从实现侧常量**派生** 7 字段集合(null = 权威常量缺席 ⇒ 由调用方报红,锚里不写第二份集合)。
3063
+ function task7RequiredSet(guardSrc) {
3064
+ const match = guardSrc.match(new RegExp('const\\s+' + TASK7_AUTHORITY_CONSTANT + '\\s*=\\s*\\[([^\\]]*)\\]'));
3065
+ if (!match) return null;
3066
+ const fields = match[1].split(',')
3067
+ .map((part) => part.trim().replace(/^['"]|['"]$/g, ''))
3068
+ .filter((part) => part !== '');
3069
+ return fields.length > 0 ? fields : null;
3070
+ }
3071
+
3072
+ // 值恰好等于权威集合的常量名(断言 BLOCKED 文案**从常量派生**用——文案里再写字面集合即第二处同口径表达)。
3073
+ function task7ConstantNames(src, fieldSet) {
3074
+ const names = [];
3075
+ const re = /const\s+([A-Za-z_$][\w$]*)\s*=\s*\[([^\]]*)\];/g;
3076
+ let match;
3077
+ while ((match = re.exec(src)) !== null) {
3078
+ const fields = match[2].split(',')
3079
+ .map((part) => part.trim().replace(/^['"]|['"]$/g, ''))
3080
+ .filter((part) => part !== '');
3081
+ if (fields.length === fieldSet.length && fields.every((field, index) => field === fieldSet[index])) {
3082
+ names.push(match[1]);
3083
+ }
3084
+ }
3085
+ return names;
3086
+ }
3087
+
3088
+ // 单行「标记同行枚举」提取(逐处对账与站点断言共用同一实现):返回 { raw, tokens } 列表。
3089
+ function task7LineEnumerationTokens(fieldSet, line) {
3090
+ if (!TASK7_MARKER_RE.test(line)) return [];
3091
+ const out = [];
3092
+ for (const raw of line.match(TASK7_RUN_RE) ?? []) {
3093
+ const tokens = raw.split('/').map((token) => token.trim().replace(/`/g, ''));
3094
+ if (tokens.length < 3) continue;
3095
+ // 只认「字段枚举」:过半数 token 落在派生集合内(同行的其它斜杠短语不参与)。
3096
+ if (tokens.filter((token) => fieldSet.includes(token)).length * 2 <= tokens.length) continue;
3097
+ out.push({ raw, tokens });
3098
+ }
3099
+ return out;
3100
+ }
3101
+
3102
+ // 技能树「7 字段」枚举行扫描(真实判据与反向构造探针共用同一实现;每处记原始片段供探针精确改行)。
3103
+ function task7EnumerationRuns(fieldSet, docs) {
3104
+ const runs = [];
3105
+ for (const [rel, text] of docs) {
3106
+ text.split(/\r?\n/).forEach((line, index) => {
3107
+ for (const { raw, tokens } of task7LineEnumerationTokens(fieldSet, line)) {
3108
+ runs.push({ rel, line: index + 1, raw, tokens });
3109
+ }
3110
+ });
3111
+ }
3112
+ return runs;
3113
+ }
3114
+
3115
+ // 已知站点上的枚举行(站点在场断言与站点级反向构造探针共用同一实现)。
3116
+ function task7KnownSiteRuns(fieldSet, docs) {
3117
+ const runs = [];
3118
+ for (const site of TASK7_KNOWN_SITES) {
3119
+ const text = docs.get(site.rel);
3120
+ if (typeof text !== 'string') continue;
3121
+ text.split(/\r?\n/).forEach((line, index) => {
3122
+ if (!line.includes(site.anchor)) return;
3123
+ for (const { raw, tokens } of task7LineEnumerationTokens(fieldSet, line)) {
3124
+ runs.push({ site, rel: site.rel, line: index + 1, raw, tokens });
3125
+ }
3126
+ });
3127
+ }
3128
+ return runs;
3129
+ }
3130
+
3131
+ // 判据:① 每处「标记同行枚举」须与派生集合**逐字同序同值**(含新增站点);② 每个**已知站点**仍须持有
3132
+ // 这样的枚举——站点丢失即红(这才是「处数下降即红」的站点级实现,且不与「新增站点」对冲)。
3133
+ function task7EnumerationProblems(fieldSet, docs) {
3134
+ const out = [];
3135
+ const expected = fieldSet.join('/');
3136
+ for (const run of task7EnumerationRuns(fieldSet, docs)) {
3137
+ const actual = run.tokens.join('/');
3138
+ if (actual !== expected) {
3139
+ out.push(run.rel + ':' + run.line + ' 的 7 字段枚举与实现集合不一致(文本 ' + actual + ' / 实现 ' + expected + ')');
3140
+ }
3141
+ }
3142
+ const siteRuns = task7KnownSiteRuns(fieldSet, docs);
3143
+ for (const site of TASK7_KNOWN_SITES) {
3144
+ if (siteRuns.some((run) => run.site === site)) continue;
3145
+ out.push('已知 7 字段站点「' + site.anchor + '」(' + site.rel + ')的标记同行枚举不在场'
3146
+ + '(该行已改为指针 / 被删 / 枚举被抽掉,或已不含实现集合的多数项)');
3147
+ }
3148
+ return out;
3149
+ }
3150
+
3151
+ // 判据:「文案落后于判据」静默面——两处 BLOCKED 文案的集合字符串必须从判据常量派生(文案区域须出现
3152
+ // 「值等于权威集合的常量」的 .join('/'),且不得再现该集合的字面拼接)。构造方式变了、渲染结果不变。
3153
+ function task7MessageDerivationProblems(fieldSet, sources) {
3154
+ const out = [];
3155
+ const joined = fieldSet.join('/');
3156
+ for (const [rel, src] of Object.entries(sources)) {
3157
+ const at = src.indexOf('任务缺 7 字段(');
3158
+ if (at < 0) {
3159
+ out.push(rel + ' 未找到「任务缺 7 字段」文案锚点(文案派生判据无从对账)');
3160
+ continue;
3161
+ }
3162
+ const region = src.slice(at, at + 240);
3163
+ const constants = task7ConstantNames(src, fieldSet);
3164
+ if (constants.length === 0) {
3165
+ out.push(rel + ' 未找到值等于权威集合的常量(判据与文案的共同来源缺席)');
3166
+ continue;
3167
+ }
3168
+ if (!constants.some((name) => region.includes(name + ".join('/')"))) {
3169
+ out.push(rel + ' 的 7 字段 BLOCKED 文案未从判据常量派生(缺 <常量>.join(\'/\'))——文案会静默落后于判据');
3170
+ }
3171
+ if (region.includes(joined)) {
3172
+ out.push(rel + ' 的 7 字段 BLOCKED 文案又写了一遍字面集合(' + joined + ')——第二处同口径表达');
3173
+ }
3174
+ }
3175
+ return out;
3176
+ }
3177
+
3178
+ // 7 字段集合锚的聚合判据(真实判据 + 反向构造探针;场景 184 调用,返回问题描述数组)。
3179
+ function task7SetAnchorProblems({ guardSrc, stateSrc, docs }) {
3180
+ const out = [];
3181
+ const fieldSet = task7RequiredSet(guardSrc);
3182
+ if (fieldSet === null || fieldSet.length !== 7) {
3183
+ out.push('workflow-guard.mjs 的 ' + TASK7_AUTHORITY_CONSTANT
3184
+ + ' 常量缺席或元素数 ≠ 7(7 字段集合的唯一权威不在场,文本侧无从对账)');
3185
+ return out;
3186
+ }
3187
+ const sources = { 'workflow-guard.mjs': guardSrc, 'workflow-state.mjs': stateSrc };
3188
+ out.push(...task7EnumerationProblems(fieldSet, docs));
3189
+ out.push(...task7MessageDerivationProblems(fieldSet, sources));
3190
+ out.push(...task7ReverseConstructionProblems(fieldSet, docs, sources));
3191
+ return out;
3192
+ }
3193
+
3194
+ // 反向构造(`LESSONS` L-106:判别句式 + 反向构造;与真实判据同一实现驱动):逐项把锚的输入改坏 ⇒ 必红;
3195
+ // 另含**判别力方向**探针——合法新增站点必须**零问题**(防「全局计数地板」式自锁:以总量取红的探针会让
3196
+ // 「新增一处」与「丢失一处」对冲,且把报错方向指向探针而非真实原因)。
3197
+ function task7ReverseConstructionProblems(fieldSet, docs, sources) {
3198
+ const out = [];
3199
+ const replaceRunLine = (targetDocs, run, mutate) => new Map(targetDocs).set(run.rel,
3200
+ (targetDocs.get(run.rel) ?? '').split(/\r?\n/)
3201
+ .map((line, index) => (index === run.line - 1 ? mutate(line) : line)).join('\n'));
3202
+ const dropRunLine = (targetDocs, run) => new Map(targetDocs).set(run.rel,
3203
+ (targetDocs.get(run.rel) ?? '').split(/\r?\n/)
3204
+ .filter((line, index) => index !== run.line - 1).join('\n'));
3205
+ const appendSite = (targetDocs, rel, fields) => new Map(targetDocs).set(rel,
3206
+ (targetDocs.get(rel) ?? '') + '\n(反向构造:新增站点)7 字段:' + fields.join(' / ') + '\n');
3207
+ const sample = task7KnownSiteRuns(fieldSet, docs)[0];
3208
+ if (sample === undefined) {
3209
+ out.push('7 字段枚举反向构造的前提不成立:已知站点上找不到与派生集合一致的枚举');
3210
+ return out;
3211
+ }
3212
+ const siteLabel = '已知站点「' + sample.site.anchor + '」(' + sample.rel + ':' + sample.line + ')';
3213
+ const probes = [
3214
+ // 站点丢失面(「处数下降即红」的站点级实现):抽掉该站点整处枚举 / 删掉整行 ⇒ 必红
3215
+ ['抽掉 ' + siteLabel + ' 的整处枚举(改指针形态)',
3216
+ () => task7EnumerationProblems(fieldSet, replaceRunLine(docs, sample,
3217
+ (line) => line.replace(sample.raw, '(反向构造:改为指针形态)'))), '已知 7 字段站点'],
3218
+ ['删掉 ' + siteLabel + ' 整行',
3219
+ () => task7EnumerationProblems(fieldSet, dropRunLine(docs, sample)), '已知 7 字段站点'],
3220
+ // 新增站点面(自锁回归):合法新增必须零问题;错误新增仍必红
3221
+ ['新增一处集合正确的站点(不得被判违规)',
3222
+ () => task7EnumerationProblems(fieldSet, appendSite(docs, sample.rel, fieldSet)), TASK7_ZERO_PROBLEMS],
3223
+ ['新增一处集合错误的新站点',
3224
+ () => task7EnumerationProblems(fieldSet, appendSite(docs, sample.rel,
3225
+ fieldSet.map((field) => (field === 'depends_on' ? 'id' : field)))), '与实现集合不一致'],
3226
+ // 集合分叉面
3227
+ ['把 ' + siteLabel + ' 的 depends_on 换成 id',
3228
+ () => task7EnumerationProblems(fieldSet, replaceRunLine(docs, sample,
3229
+ (line) => line.replace(sample.raw, sample.raw.replace('depends_on', 'id')))), '与实现集合不一致'],
3230
+ ['把 id 追加成第 8 项',
3231
+ () => task7EnumerationProblems(fieldSet, replaceRunLine(docs, sample,
3232
+ (line) => line.replace(sample.raw, sample.raw + ' / id'))), '与实现集合不一致'],
3233
+ ['实现侧常量把 depends_on 改成 dependsOn',
3234
+ () => task7EnumerationProblems(fieldSet.map((field) => (field === 'depends_on' ? 'dependsOn' : field)), docs),
3235
+ '与实现集合不一致'],
3236
+ // 文案派生面(⑧):构造方式回退 / 派生被抽掉 ⇒ 必红
3237
+ ['文案回写字面集合',
3238
+ () => task7MessageDerivationProblems(fieldSet, { ...sources,
3239
+ 'workflow-guard.mjs': sources['workflow-guard.mjs'].replace(
3240
+ TASK7_AUTHORITY_CONSTANT + ".join('/')", "'" + fieldSet.join('/') + "'") }), '又写了一遍字面集合'],
3241
+ ['文案抽掉派生',
3242
+ () => task7MessageDerivationProblems(fieldSet, { ...sources,
3243
+ 'workflow-state.mjs': sources['workflow-state.mjs'].replace("replanTask7Required.join('/')", "'7 字段'") }),
3244
+ '未从判据常量派生'],
3245
+ ];
3246
+ // 探针判定只看**相对当前文本的新增问题**(`ambient` 差分):工作树本身已红时,探针不得把
3247
+ // 「环境里已有的问题」记成自己的判别力(否则报错方向会指向探针,而不是指向真实原因)。
3248
+ const ambient = task7EnumerationProblems(fieldSet, docs);
3249
+ for (const [label, probe, expected] of probes) {
3250
+ const added = probe().filter((problem) => !ambient.includes(problem));
3251
+ const passed = expected === TASK7_ZERO_PROBLEMS
3252
+ ? added.length === 0
3253
+ : added.some((problem) => problem.includes(expected));
3254
+ if (!passed) {
3255
+ out.push(expected === TASK7_ZERO_PROBLEMS
3256
+ ? '反向构造判别力缺失(' + label + ' 被判违规——锚对合法扩展自锁): ' + added.join('; ')
3257
+ : '反向构造判别力缺失(' + label + ' 未被判违规)');
3258
+ }
3259
+ }
3260
+ return out;
3261
+ }
3262
+
2369
3263
  // 前端判据**散文口径**判据(场景 286 使用;纯函数 + 合成输入可驱动):引擎侧判据已升为结构形态
2370
3264
  // (独立行 / 行首 / 适用性标签的字段值位 + 词形边界 + 命中片段回显),五份分发文本是它的散文副本——
2371
3265
  // 副本必须陈述**结构形态**,不得残留旧口径(「段内不含 / 未标注字面『不适用』」这类把判据说成
@@ -2635,7 +3529,7 @@ const BARE_ISO_ENGINE_WHITELIST = [
2635
3529
  {
2636
3530
  file: 'workflow-handoff.mjs',
2637
3531
  count: 4,
2638
- reason: 'handoff 请求 / 结果的机器字段(requestedAt / revokedAt / completedAt):Z 形是既有 handoff 工件契约,须与 workflow-state 同批迁移',
3532
+ reason: 'handoff 请求 / 结果的机器字段(requestedAt / revokedAt / completedAt):Z 形是既有 handoff 工件契约,须与 workflow-state 同批迁移;新增的撤回留痕不走本条——withdrawnAt 由 time-utils 的 nowTimestamp 生成(本地时间 + 显式偏移),人可见回显亦按标准形态格式化',
2639
3533
  },
2640
3534
  {
2641
3535
  file: 'workflow-guard.mjs',
@@ -2870,6 +3764,197 @@ function writeDesignExitFixture(dir, {
2870
3764
  }
2871
3765
  }
2872
3766
 
3767
+ // ---------- 锚助手(模块级具名实现:场景主体只调用,避免长体内插) ----------
3768
+
3769
+ // apply_patch heredoc 目标解析的耐久锚。载荷形态 = Codex 承载补丁的真实调用
3770
+ // (tool_name="Bash"、补丁正文在 tool_input.command、载荷无 file_path):四类补丁摘要行
3771
+ // (Update / Add / Delete / Move to)× 身份 / 协调者白名单两态 × 定界符变体 × 反例组。
3772
+ // 判据含**内建反向构造**(L-064):把守卫副本的补丁解析停用(解析器入口早退)后,同一组
3773
+ // 载荷里预期拦截的用例必须**全部**翻成放行——证明本锚断言的不是恒真形态。副本落在场景临时
3774
+ // 目录(只复制守卫与其三个同包依赖),不触碰权威源文件(零写入、零临时改名)。
3775
+ // 保护集第二目标按**本次运行实际生效的协议文件**取值(FLOW_COMET_PROTOCOL 的解析结果),
3776
+ // 不是「任意名为 workflow-protocol.json 的文件」——同名异路径用例(allow)即该边界的判别锚。
3777
+ function applyPatchPayloadMatrix() {
3778
+ const stateTarget = '.flow-comet/flow-comet-state.json';
3779
+ const protocolTarget = 'reference/workflow-protocol.json'; // = 本场景实际生效的协议路径
3780
+ const sameNameElsewhere = '.specs/' + CHANGE_ID + '/workflow-protocol.json';
3781
+ const srcTarget = 'src/patched.mjs';
3782
+ const specsTarget = '.specs/' + CHANGE_ID + '/patched.md';
3783
+ const identity = { agent_id: 'agent-abc123' };
3784
+ // 补丁承载形态:`apply_patch <<'PATCH'` + 正文 + 定界行;dash / 引号形态按 shell 语义拼装。
3785
+ const patchCommand = (bodyLines, { delimiter = "'PATCH'", dash = false, close = true } = {}) => {
3786
+ const closing = (dash ? '\t' : '') + delimiter.replace(/^["']|["']$/g, '');
3787
+ const lines = ['apply_patch <<' + (dash ? '-' : '') + delimiter, '*** Begin Patch', ...bodyLines];
3788
+ if (close) lines.push(closing);
3789
+ return lines.join('\n');
3790
+ };
3791
+ const payloads = [];
3792
+ const add = (label, command, expect, withIdentity = true) =>
3793
+ payloads.push({ label, command, expect, identity: withIdentity ? identity : {} });
3794
+ // ① 四类摘要行 × 身份态 → 机器状态文件仍受拦(保护集,身份放行不放行它)
3795
+ for (const header of ['*** Update File:', '*** Add File:', '*** Delete File:', '*** Move to:']) {
3796
+ add('身份 + ' + header + ' state 文件', patchCommand([header + ' ' + stateTarget]), 'block');
3797
+ }
3798
+ // ② 身份态对照:普通源码放行(不过宽);实际生效的协议文件受拦;**同名异路径**放行(判据是
3799
+ // 解析结果而非文件名——保护集第二目标的边界)
3800
+ add('身份 + Update File 普通源码', patchCommand(['*** Update File: ' + srcTarget]), 'allow');
3801
+ add('身份 + Update File 生效协议文件', patchCommand(['*** Update File: ' + protocolTarget]), 'block');
3802
+ add('身份 + Update File 同名异路径协议文件', patchCommand(['*** Update File: ' + sameNameElsewhere]), 'allow');
3803
+ // ③ 协调者白名单态(无身份):.specs/ 放行;源码拦截;state 文件仍受拦(保护集无条件)
3804
+ add('无身份 + Update File .specs/ 工件', patchCommand(['*** Update File: ' + specsTarget]), 'allow', false);
3805
+ add('无身份 + Update File 源码', patchCommand(['*** Update File: ' + srcTarget]), 'block', false);
3806
+ add('无身份 + Update File state 文件', patchCommand(['*** Update File: ' + stateTarget]), 'block', false);
3807
+ // ④ 定界符变体 × state 文件 × 身份态 → 仍受拦
3808
+ add('双引号定界符', patchCommand(['*** Update File: ' + stateTarget], { delimiter: '"PATCH"' }), 'block');
3809
+ add('裸定界符', patchCommand(['*** Update File: ' + stateTarget], { delimiter: 'PATCH' }), 'block');
3810
+ add('<<- 制表符定界行', patchCommand(['*** Update File: ' + stateTarget], { delimiter: "'PATCH'", dash: true }), 'block');
3811
+ // ⑤ 反例:定界符之后的散行不得被吞并(吞并会把下游命令的参数读成写入目标);正文无摘要行、
3812
+ // 非 heredoc 的内联文本、引号内同名文本、无命令名的摘要行一律不误报
3813
+ add('定界符后散行不吞并',
3814
+ patchCommand(['*** Update File: ' + specsTarget]) + '\n*** Update File: ' + stateTarget, 'allow');
3815
+ add('正文无摘要行', patchCommand(['@@ -1 +1 @@', '-old', '+new']), 'allow');
3816
+ add('内联文本无 heredoc', 'echo "*** Update File: ' + stateTarget + '"', 'allow');
3817
+ add('引号内 apply_patch 文本', 'echo "apply_patch <<\'PATCH\'"', 'allow');
3818
+ add('无 apply_patch 命令名', 'grep -n "*** Update File: ' + stateTarget + '" patch.diff', 'allow');
3819
+ // ⑥ 未闭合 heredoc:按「正文到命令末尾」处理(偏拦截方向的 fail-closed),摘要行仍被抽出
3820
+ add('未闭合 heredoc', patchCommand(['*** Update File: ' + stateTarget], { close: false }), 'block');
3821
+ return payloads;
3822
+ }
3823
+
3824
+ // 单组载荷求值(真实守卫与反向构造副本共用):cwd / runRoot / 协议路径与场景夹具一致。
3825
+ function runApplyPatchPayload(dir, hookPath, payload) {
3826
+ const res = spawnSync(process.execPath, [hookPath, 'before_tool'], {
3827
+ cwd: dir,
3828
+ input: JSON.stringify({ tool_name: 'Bash', tool_input: { command: payload.command }, ...payload.identity }),
3829
+ env: {
3830
+ ...process.env,
3831
+ FLOW_COMET_RUN_ROOT: dir,
3832
+ FLOW_COMET_PROTOCOL: path.join(dir, 'reference', 'workflow-protocol.json'),
3833
+ },
3834
+ encoding: 'utf8',
3835
+ timeout: 60000,
3836
+ });
3837
+ return { status: res.status ?? 1, output: String(res.stdout || '') + String(res.stderr || '') };
3838
+ }
3839
+
3840
+ // 矩阵求值(单一实现):逐组比对期望出口码与拦截报文,返回问题串。
3841
+ function applyPatchVerdictProblems(dir, hookPath, payloads) {
3842
+ const problems = [];
3843
+ for (const payload of payloads) {
3844
+ const expected = payload.expect === 'block' ? 2 : 0;
3845
+ const res = runApplyPatchPayload(dir, hookPath, payload);
3846
+ if (res.status !== expected) {
3847
+ problems.push('apply_patch 锚(' + payload.label + ')预期 exit ' + expected
3848
+ + ',实际 exit ' + res.status + ':' + res.output.trim().slice(0, 120));
3849
+ } else if (payload.expect === 'block' && !res.output.includes('BLOCKED')) {
3850
+ problems.push('apply_patch 锚(' + payload.label + ')拦截报文缺 BLOCKED:' + res.output.trim().slice(0, 120));
3851
+ }
3852
+ }
3853
+ return problems;
3854
+ }
3855
+
3856
+ // 耐久锚主体:真实矩阵 + 内建反向构造(L-064)。
3857
+ function applyPatchAnchorProblems(dir) {
3858
+ const payloads = applyPatchPayloadMatrix();
3859
+ const problems = applyPatchVerdictProblems(dir, HOOK, payloads);
3860
+ // 内建反向构造(L-064):停用补丁解析 ⇒ 依赖该解析的拦截用例必须全部变红(此处判红)。
3861
+ const probeDir = path.join(dir, 'probe-scripts');
3862
+ fs.mkdirSync(probeDir, { recursive: true });
3863
+ for (const rel of ['comet-hook-guard.mjs', 'protocol-utils.mjs', 'state-schema.mjs', 'time-utils.mjs']) {
3864
+ fs.copyFileSync(path.join(__dirname, rel), path.join(probeDir, rel));
3865
+ }
3866
+ const probeHookPath = path.join(probeDir, 'comet-hook-guard.mjs');
3867
+ const probeSource = fs.readFileSync(probeHookPath, 'utf8');
3868
+ const entry = probeSource.indexOf('function applyPatchHeredocs(command) {');
3869
+ if (entry < 0) {
3870
+ problems.push('反向构造探针无法定位补丁解析入口(实现已改名——锚与实现漂移)');
3871
+ return problems;
3872
+ }
3873
+ const brace = probeSource.indexOf('{', entry);
3874
+ fs.writeFileSync(probeHookPath,
3875
+ probeSource.slice(0, brace + 1) + '\n return []; // 反向构造:停用补丁解析\n' + probeSource.slice(brace + 1), 'utf8');
3876
+ let flipped = 0;
3877
+ for (const payload of payloads) {
3878
+ const res = runApplyPatchPayload(dir, probeHookPath, payload);
3879
+ if (payload.expect === 'block') {
3880
+ if (res.status === 0) flipped += 1;
3881
+ else problems.push('反向构造判别力缺失(' + payload.label + ' 在解析停用后仍拦截)');
3882
+ } else if (res.status !== 0) {
3883
+ problems.push('反向构造引入新拦截(' + payload.label + ' 在解析停用后被拦)');
3884
+ }
3885
+ }
3886
+ const blockCases = payloads.filter((p) => p.expect === 'block').length;
3887
+ if (flipped !== blockCases) {
3888
+ problems.push('反向构造未覆盖全部拦截用例(' + flipped + '/' + blockCases + ' 翻红)');
3889
+ }
3890
+ console.log('ANCHOR: apply_patch 目标解析矩阵 ' + payloads.length + ' 组(四类摘要行 × 身份/白名单两态 × '
3891
+ + '定界符变体 × 反例;反向构造停用解析后 ' + flipped + '/' + blockCases + ' 组拦截用例全部翻红)');
3892
+ fs.rmSync(probeDir, { recursive: true, force: true });
3893
+ return problems;
3894
+ }
3895
+
3896
+ // 段内 glob 语义两处实现的等价性锚(route-node 的计划期重叠判定 ↔ workflow-handoff 的提交
3897
+ // 子集校验):同一 (声明, 字面) 矩阵两侧求值必须同判——否则「形态同源 + 漂移可见」无凭据。
3898
+ // 等价域 = **已归一**声明 × git 报告的**字面**路径(route-node 侧入参经计划期归一;handoff 侧
3899
+ // 的文件名来自 git,永不含 glob)。域外边界显式声明:双侧 glob 的保守重叠判定在 handoff 侧无
3900
+ // 对应物(提交文件名不可能是 glob),不在等价断言内。
3901
+ function globEquivalenceProblems(dir) {
3902
+ const problems = [];
3903
+ const overlaps = requireRouteNodeExport('collectPathOverlaps');
3904
+ execFileSync('git', ['init', '-q'], { cwd: dir, stdio: 'ignore' });
3905
+ const git = (...args) => execFileSync('git', args, { cwd: dir, stdio: 'ignore' });
3906
+ const commitFile = (rel) => {
3907
+ writeFile(dir, rel, 'export const probe = 1;\n');
3908
+ git('add', '--', rel);
3909
+ git('-c', 'user.name=t', '-c', 'user.email=t@t', 'commit', '-qm', 'chore: glob probe ' + rel);
3910
+ return execFileSync('git', ['rev-parse', 'HEAD'], { cwd: dir, encoding: 'utf8' }).trim();
3911
+ };
3912
+ const hashes = new Map();
3913
+ const hashFor = (rel) => {
3914
+ if (!hashes.has(rel)) hashes.set(rel, commitFile(rel));
3915
+ return hashes.get(rel);
3916
+ };
3917
+ // 矩阵:{ pattern: 已归一声明, literal: 真实提交路径, covered: 两侧应同判的结论 }
3918
+ const matrix = [
3919
+ { pattern: 'src/*.mjs', literal: 'src/a.mjs', covered: true, label: '段内通配命中' },
3920
+ { pattern: 'src/*.mjs', literal: 'src/b.ts', covered: false, label: '段内通配扩展名不符' },
3921
+ { pattern: 'src/*.mjs', literal: 'src/deep/a.mjs', covered: false, label: '段数不等不跨 /' },
3922
+ { pattern: 'src/*', literal: 'src/a.mjs', covered: true, label: '整段通配' },
3923
+ { pattern: 'src/a.mjs', literal: 'src/a.mjs', covered: true, label: '字面相等' },
3924
+ { pattern: 'src/foo.mjs', literal: 'src/foobar.mjs', covered: false, label: '字面非前缀匹配' },
3925
+ { pattern: 'SRC/*.mjs', literal: 'src/a.mjs', covered: false, label: '大小写不同不命中' },
3926
+ { pattern: 'src/a?.mjs', literal: 'src/a1.mjs', covered: false, label: '非 * 元字符按字面(两侧同口径)' },
3927
+ ];
3928
+ let index = 0;
3929
+ for (const cell of matrix) {
3930
+ index += 1;
3931
+ const taskId = 'E' + String(index).padStart(2, '0');
3932
+ const routeSide = overlaps([cell.pattern], [cell.literal]).length > 0;
3933
+ assertExit(runHandoff(['request', taskId, '--write-files', cell.pattern], dir), 0);
3934
+ const handoffSide = runHandoff(['result', taskId, JSON.stringify({
3935
+ status: 'DONE', taskId, commitHash: hashFor(cell.literal),
3936
+ completedChecks: ['required-skill:subagent-execute.flow-comet-dev'],
3937
+ redEvidence: { command: 'echo ok' },
3938
+ greenEvidence: { command: 'echo ok', output: 'ok' },
3939
+ })], dir);
3940
+ const handoffCovered = handoffSide.status === 0;
3941
+ if (!handoffCovered && !handoffSide.output.includes('超出 writeFiles 范围')) {
3942
+ problems.push('等价性锚(' + cell.label + ')提交子集校验未给出可判定结论:'
3943
+ + handoffSide.output.trim().slice(0, 120));
3944
+ continue;
3945
+ }
3946
+ if (routeSide !== cell.covered || handoffCovered !== cell.covered) {
3947
+ problems.push('glob 语义两处实现不一致(' + cell.label + '):声明 ' + cell.pattern + ' × 字面 '
3948
+ + cell.literal + ' 期望 ' + cell.covered + ',route-node=' + routeSide + ',handoff=' + handoffCovered);
3949
+ }
3950
+ }
3951
+ const coveredCount = matrix.filter((c) => c.covered).length;
3952
+ console.log('ANCHOR: 段内 glob 等价性矩阵 ' + matrix.length + ' 格(命中 ' + coveredCount + ' / 不命中 '
3953
+ + (matrix.length - coveredCount) + ')——route-node 计划期重叠判定与 workflow-handoff 提交子集校验同判;'
3954
+ + '任一恒真或恒假实现即红');
3955
+ return problems;
3956
+ }
3957
+
2873
3958
  // ---------- 场景表 ----------
2874
3959
 
2875
3960
  const SCENARIOS = [
@@ -3124,8 +4209,12 @@ const SCENARIOS = [
3124
4209
  },
3125
4210
 
3126
4211
  // 15: subagent-execute exit 通过(parallel 全 done + handoff 齐 + Return Contract 完整)
4212
+ // in-place 扩展(验证隔离三态 + 派遣留痕):① 全部收工 ⇒ 放行(原断言);② 有 request 无对应
4213
+ // result(写者未收工的既有可判形态)⇒ 新 change BLOCKED + 恢复指引 / 旧 change 渐进 WARN;
4214
+ // ③ 无该证据对象 ⇒ 零输出(不制造噪音);④ 派遣留痕落在既有嵌套字段(零新增 state 顶层字段)
4215
+ // 的静态锚。反向构造:把出口校验的判据从「有 request 无 result」放宽成恒空 ⇒ ② 必红。
3127
4216
  {
3128
- name: '15 subagent-execute exit 通过(parallel done + handoff 齐)',
4217
+ name: '15 subagent-execute exit 三态(在飞委托 BLOCK·全部收工放行·无证据零输出)+ 留痕嵌套锚',
3129
4218
  run: (dir) => {
3130
4219
  const st = baseState('subagent-execute');
3131
4220
  st.evidence['subagent-execute'] = {
@@ -3137,6 +4226,258 @@ const SCENARIOS = [
3137
4226
  const res = runGuard(['exit', 'subagent-execute'], dir);
3138
4227
  assertExit(res, 0);
3139
4228
  assertOut(res, 'ALL CHECKS PASSED');
4229
+ assertNotOut(res, '在飞委托');
4230
+
4231
+ // ①b 并行 × 零提交通过出口(AC-9):parallel done 任务的留痕为「request 记 noCommit:true +
4232
+ // result 回传无 commitHash 的零提交契约」⇒ 出口按该资格豁免缺 commitHash,不因并行维度
4233
+ // 而拦。判别力内建对照:同一并行任务去掉 request 的 noCommit 资格 ⇒ 必按缺 commitHash
4234
+ // 拦截——证明豁免由资格驱动,不是并行维度的恒真形态。
4235
+ const zeroParallelTask = '<task id="P01" status="done" parallel="true"><action>并行零提交</action>'
4236
+ + '<write_files>.specs/' + CHANGE_ID + '/P01-SUMMARY.md</write_files><verify>echo ok</verify></task>\n';
4237
+ const zeroParallelResult = (taskId) => ({
4238
+ result: {
4239
+ status: 'DONE', taskId, noCommit: true,
4240
+ completedChecks: ['required-skill:subagent-execute.flow-comet-dev'],
4241
+ redEvidence: { command: 'echo ok' },
4242
+ greenEvidence: { command: 'echo ok', output: 'ok' },
4243
+ },
4244
+ });
4245
+ const zeroParallel = { ...baseState('subagent-execute') };
4246
+ zeroParallel.evidence['subagent-execute'] = {
4247
+ summary: 'parallel zero-commit task collected',
4248
+ handoffRequests: { P01: { writeFiles: ['.specs/' + CHANGE_ID + '/P01-SUMMARY.md'], noCommit: true } },
4249
+ handoffResult: { P01: zeroParallelResult('P01') },
4250
+ };
4251
+ writeState(dir, zeroParallel);
4252
+ writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', '# TASK\n\n' + zeroParallelTask);
4253
+ const zeroParallelExit = runGuard(['exit', 'subagent-execute'], dir);
4254
+ assertExit(zeroParallelExit, 0);
4255
+ assertNotOut(zeroParallelExit, '缺 commitHash');
4256
+ const unqualifiedParallel = JSON.parse(JSON.stringify(zeroParallel));
4257
+ delete unqualifiedParallel.evidence['subagent-execute'].handoffRequests.P01.noCommit;
4258
+ writeState(dir, unqualifiedParallel);
4259
+ const unqualifiedExit = runGuard(['exit', 'subagent-execute'], dir);
4260
+ assertExit(unqualifiedExit, 1);
4261
+ assertOut(unqualifiedExit, '缺 commitHash');
4262
+
4263
+ // ② 在飞委托(有 request 无对应 result)⇒ 新 change BLOCKED,报文点名未收工任务并给恢复指引
4264
+ const inFlight = { ...baseState('subagent-execute'), newChange: true };
4265
+ inFlight.enteredNodes = ['subagent-execute'];
4266
+ inFlight.evidence['subagent-execute'] = {
4267
+ summary: 'delegated, one writer still running',
4268
+ handoffRequests: {
4269
+ P01: { writeFiles: ['src/p1.mjs'] },
4270
+ P03: { writeFiles: ['src/p3.mjs'] },
4271
+ },
4272
+ handoffResult: handoffFor(['P01']),
4273
+ };
4274
+ writeState(dir, inFlight);
4275
+ const blocked = runGuard(['exit', 'subagent-execute'], dir);
4276
+ assertExit(blocked, 1);
4277
+ assertOut(blocked, '在飞委托');
4278
+ assertOut(blocked, '待写入者收工后重跑');
4279
+ assertOut(blocked, 'P03');
4280
+ assertNotOut(blocked, 'P01(');
4281
+ // ②b 旧 change 同形态 ⇒ 渐进 WARN 不阻断(向后兼容硬约束),指引仍在
4282
+ const inFlightOld = { ...inFlight };
4283
+ delete inFlightOld.newChange;
4284
+ writeState(dir, inFlightOld);
4285
+ const warned = runGuard(['exit', 'subagent-execute'], dir);
4286
+ assertExit(warned, 0);
4287
+ assertOut(warned, 'WARN');
4288
+ assertOut(warned, '在飞委托');
4289
+ assertOut(warned, '待写入者收工后重跑');
4290
+ // ③ 无该证据对象(从未进入委托节点)⇒ 零输出:判据不得在无证据形态下制造噪音
4291
+ const noEvidence = { ...baseState('subagent-execute') };
4292
+ noEvidence.evidence = {};
4293
+ writeState(dir, noEvidence);
4294
+ const silent = runGuard(['exit', 'subagent-execute'], dir);
4295
+ assertNotOut(silent, '在飞委托');
4296
+ assertNotOut(silent, '待写入者收工后重跑');
4297
+
4298
+ // ②c 撤回通道(在飞委托族的 in-place 扩展):被遗弃的 request 可经受支持接口撤回——撤回在
4299
+ // **原记录**上加法式落留痕(withdrawnAt 时间戳 + withdrawnBy 来源),守卫按同一判据把已撤回
4300
+ // 的 request 移出在飞集合 ⇒ 出口放行;记录本身不删除(历史留痕),重新委托时撤回落痕转入
4301
+ // previousWithdrawals 而非被静默丢弃。已撤回 = **终态**:重复撤回被拒、撤回后 result 被拒。
4302
+ // 判据要求留痕**两字段齐备**才成立(只写时间戳的手改形态仍按在飞处理——fail-closed)。
4303
+ // 反向构造:守卫不忽略已撤回的 request ⇒ ②c-3 必红;判据只看单一字段 ⇒ ②c-6 必红。
4304
+ const withdrawRequests = () => ({
4305
+ P01: { writeFiles: ['src/p1.mjs'] },
4306
+ P02: { writeFiles: ['src/p2.mjs'], requestedAt: '2026-10-07T00:00:00.000Z' },
4307
+ });
4308
+ const withdrawCase = { ...baseState('subagent-execute'), newChange: true };
4309
+ withdrawCase.enteredNodes = ['subagent-execute'];
4310
+ withdrawCase.evidence['subagent-execute'] = {
4311
+ summary: 'delegated, one request abandoned',
4312
+ handoffRequests: withdrawRequests(),
4313
+ handoffResult: handoffFor(['P01']),
4314
+ };
4315
+ writeState(dir, withdrawCase);
4316
+ writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', '# TASK\n\n' + TASK_P1 + TASK_P2);
4317
+ // 严格形态(newChange:true)下 done 任务须有对应 SUMMARY——补两份,使「撤回 ⇒ 出口放行」
4318
+ // 的断言落在**唯一**阻塞点(在飞委托)上,而不是被无关门禁干扰。
4319
+ writeFile(dir, '.specs/' + CHANGE_ID + '/P01-SUMMARY.md', strictSummary('P01'));
4320
+ writeFile(dir, '.specs/' + CHANGE_ID + '/P02-SUMMARY.md', strictSummary('P02'));
4321
+ // ②c-0 撤回前:P02 在飞 ⇒ 出口拦(撤回通道的必要性前提 + 恢复指引点名该命令)
4322
+ const beforeWithdraw = runGuard(['exit', 'subagent-execute'], dir);
4323
+ assertExit(beforeWithdraw, 1);
4324
+ assertOut(beforeWithdraw, 'P02');
4325
+ assertOut(beforeWithdraw, 'workflow-handoff.mjs withdraw');
4326
+ // ②c-0b 前置拒绝(适用面自洽):P01 已收工(handoffResult 在场)⇒ 撤回被拒(非零退出 + 报文
4327
+ // 写清为何拒 + 恢复指引),且 state 字节零改写(不落留痕、不动既有 request / result——
4328
+ // 撤回的适用面是「在飞且被遗弃的 request」,与动作自述一致)。
4329
+ // 反向构造:把该前置拒绝去掉 ⇒「撤回已收工的委托」又变 exit 0,本格必红。
4330
+ const bytesBeforeCompletedWithdraw = readStateBytes(dir);
4331
+ const completedWithdraw = runHandoff(['withdraw', 'P01', '--by', 'user'], dir);
4332
+ assertExit(completedWithdraw, 1);
4333
+ assertOut(completedWithdraw, '已收工');
4334
+ assertOut(completedWithdraw, 'handoffResult 在场');
4335
+ assertOut(completedWithdraw, '撤回只适用于被遗弃的 request');
4336
+ assertOut(completedWithdraw, '恢复:');
4337
+ assertNotOut(completedWithdraw, 'HANDOFF WITHDRAW');
4338
+ assertStateBytesUnchanged(dir, bytesBeforeCompletedWithdraw, '撤回已收工的委托被拒');
4339
+ // ②c-1 真实 CLI 撤回:缺 --by 先被拒(留痕来源不可缺省)⇒ 补齐后撤回成功
4340
+ const noBy = runHandoff(['withdraw', 'P02'], dir);
4341
+ assertExit(noBy, 1);
4342
+ assertOut(noBy, '--by');
4343
+ const withdrawn = runHandoff(['withdraw', 'P02', '--by', 'coordinator', '--reason', '零提交复验失败后作废'], dir);
4344
+ assertExit(withdrawn, 0);
4345
+ assertOut(withdrawn, 'HANDOFF WITHDRAW: P02');
4346
+ assertOut(withdrawn, 'withdrawnAt=');
4347
+ // ②c-2 留痕在场且历史不删:撤回两字段齐备,原 request 字段(writeFiles / requestedAt)原样保留
4348
+ const stWithdrawn = JSON.parse(readStateBytes(dir));
4349
+ const p02Withdrawn = stWithdrawn.evidence['subagent-execute'].handoffRequests.P02;
4350
+ if (typeof p02Withdrawn.withdrawnAt !== 'string' || p02Withdrawn.withdrawnAt.trim() === '') {
4351
+ throw new Error('撤回应落 withdrawnAt 时间戳: ' + JSON.stringify(p02Withdrawn));
4352
+ }
4353
+ // 时间纪律:新写入路径走 time-utils 单一权威 ⇒ 标准形态为本地时间 + 显式偏移;裸 Z 形态
4354
+ // (自行拼接的产物)在此必红,且 298 的白名单代数会同时漂移(两条判据互相印证)。
4355
+ if (!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{2}:\d{2}$/.test(p02Withdrawn.withdrawnAt)) {
4356
+ throw new Error('withdrawnAt 应为标准形态(本地时间 + 显式偏移,走 time-utils 的 nowTimestamp): '
4357
+ + JSON.stringify(p02Withdrawn.withdrawnAt));
4358
+ }
4359
+ if (Number.isNaN(timeUtilsModule.parseTimestamp(p02Withdrawn.withdrawnAt))) {
4360
+ throw new Error('withdrawnAt 应可被时间单一权威解析: ' + JSON.stringify(p02Withdrawn.withdrawnAt));
4361
+ }
4362
+ if (p02Withdrawn.withdrawnBy !== 'coordinator') {
4363
+ throw new Error('撤回应落 withdrawnBy 来源: ' + JSON.stringify(p02Withdrawn));
4364
+ }
4365
+ if (p02Withdrawn.withdrawReason !== '零提交复验失败后作废') {
4366
+ throw new Error('撤回原因应留痕: ' + JSON.stringify(p02Withdrawn));
4367
+ }
4368
+ if (!Array.isArray(p02Withdrawn.writeFiles) || p02Withdrawn.writeFiles[0] !== 'src/p2.mjs'
4369
+ || p02Withdrawn.requestedAt !== '2026-10-07T00:00:00.000Z') {
4370
+ throw new Error('撤回不得删除原 request 字段(writeFiles / requestedAt 应原样保留): ' + JSON.stringify(p02Withdrawn));
4371
+ }
4372
+ // ②c-3 撤回后 ⇒ 出口放行(守卫忽略已撤回的 request;同一出口、同一 state 其余字段不变)
4373
+ const afterWithdraw = runGuard(['exit', 'subagent-execute'], dir);
4374
+ assertExit(afterWithdraw, 0);
4375
+ assertOut(afterWithdraw, 'ALL CHECKS PASSED');
4376
+ assertNotOut(afterWithdraw, '在飞委托');
4377
+ // ②c-4 终态之一:重复撤回被拒,且不改写既有留痕
4378
+ const withdrawAgain = runHandoff(['withdraw', 'P02', '--by', 'coordinator'], dir);
4379
+ assertExit(withdrawAgain, 1);
4380
+ assertOut(withdrawAgain, '终态');
4381
+ const stAfterAgain = JSON.parse(readStateBytes(dir));
4382
+ if (stAfterAgain.evidence['subagent-execute'].handoffRequests.P02.withdrawnAt !== p02Withdrawn.withdrawnAt) {
4383
+ throw new Error('重复撤回不得改写既有撤回留痕');
4384
+ }
4385
+ // ②c-5 终态之二:已撤回的 request 不再接受 result(撤回语义不被事后「复活」绕过)
4386
+ const resultAfterWithdraw = runHandoff(['result', 'P02', '{"commitHash":"deadbee","completedChecks":[]}'], dir);
4387
+ assertExit(resultAfterWithdraw, 1);
4388
+ assertOut(resultAfterWithdraw, '已撤回(终态)');
4389
+ // ②c-6 判据要求留痕两字段齐备:抽掉 withdrawnBy(手改形态)⇒ 重新计为在飞委托 ⇒ 出口回收
4390
+ const strippedWithdraw = JSON.parse(readStateBytes(dir));
4391
+ delete strippedWithdraw.evidence['subagent-execute'].handoffRequests.P02.withdrawnBy;
4392
+ writeState(dir, strippedWithdraw);
4393
+ const restripped = runGuard(['exit', 'subagent-execute'], dir);
4394
+ assertExit(restripped, 1);
4395
+ assertOut(restripped, '在飞委托');
4396
+ // ②c-7 撤回 → 重新委托:撤回落痕转入 previousWithdrawals,不被静默丢弃
4397
+ // (先补回 ②c-6 抽掉的来源字段——那一抽是为验证判据要求两字段齐备,不是状态终态)
4398
+ strippedWithdraw.evidence['subagent-execute'].handoffRequests.P02.withdrawnBy = 'coordinator';
4399
+ writeState(dir, strippedWithdraw);
4400
+ writeFile(dir, '.specs/' + CHANGE_ID + '/.skill-loads/subagent-execute-flow-comet-dev.json',
4401
+ JSON.stringify({ node: 'subagent-execute', skill: 'flow-comet-dev', at: '2026-10-07T00:00:00.000Z' }, null, 2) + '\n');
4402
+ assertExit(runHandoff(['request', 'P02', '重新委托 P02', '--write-files', 'src/p2.mjs'], dir), 0);
4403
+ const stReRequest = JSON.parse(readStateBytes(dir));
4404
+ const p02ReRequested = stReRequest.evidence['subagent-execute'].handoffRequests.P02;
4405
+ if (p02ReRequested.withdrawnAt !== undefined) {
4406
+ throw new Error('重新委托应重置当前态(withdrawnAt 不得残留在当前字段): ' + JSON.stringify(p02ReRequested));
4407
+ }
4408
+ if (!Array.isArray(p02ReRequested.previousWithdrawals) || p02ReRequested.previousWithdrawals.length !== 1
4409
+ || p02ReRequested.previousWithdrawals[0].withdrawnBy !== 'coordinator') {
4410
+ throw new Error('重新委托不得静默丢弃撤回落痕(应转入 previousWithdrawals): ' + JSON.stringify(p02ReRequested));
4411
+ }
4412
+ // ②c-8 撤回只作用于已记录的 request:未知任务被拒、不新建记录
4413
+ const withdrawUnknown = runHandoff(['withdraw', 'P99', '--by', 'coordinator'], dir);
4414
+ assertExit(withdrawUnknown, 1);
4415
+ assertOut(withdrawUnknown, '无对应 request 记录');
4416
+ // ②c-9 前置拒绝的边界(与守卫同一把尺子):handoffResult 的**显式 null 占位**读作未收工——
4417
+ // 守卫的两处消费方(在飞判据按 undefined / null,越俎代庖检测按 falsy)都把它读作
4418
+ // 「无结果」,故撤回仍可用,不给「出口拦 + 撤回拒」留下无出口的死角
4419
+ // (真实链路:先 request,再落空占位,再撤回)。
4420
+ assertExit(runHandoff(['request', 'P03', '遗弃的在飞委托', '--write-files', 'src/p3.mjs'], dir), 0);
4421
+ const nullPlaceholderState = JSON.parse(readStateBytes(dir));
4422
+ nullPlaceholderState.evidence['subagent-execute'].handoffResult.P03 = null;
4423
+ writeState(dir, nullPlaceholderState);
4424
+ const nullPlaceholderWithdraw = runHandoff(['withdraw', 'P03', '--by', 'coordinator'], dir);
4425
+ assertExit(nullPlaceholderWithdraw, 0);
4426
+ assertOut(nullPlaceholderWithdraw, 'HANDOFF WITHDRAW: P03');
4427
+
4428
+ // ④ 派遣留痕的静态锚(零新增 state 顶层字段):留痕只允许落在既有嵌套字段
4429
+ // evidence['subagent-execute'] 下——引擎脚本不得出现顶层留痕键赋值;顶层字段清单
4430
+ // 以状态字段校验器为单一来源(新增顶层字段必须先过校验器,否则本锚即红)。
4431
+ const engineScripts = [
4432
+ 'workflow-state.mjs', 'workflow-guard.mjs', 'workflow-handoff.mjs',
4433
+ 'route-node.mjs', 'comet-hook-guard.mjs', 'state-schema.mjs',
4434
+ ];
4435
+ const traceShapeProblems = ({ scripts, handoff, schema }) => {
4436
+ const out = [];
4437
+ const topLevelTraceWriteRe = /\bstate\.(handoffRequests|handoffResult|delegationTrace|dispatchTrace|delegations)\b/;
4438
+ for (const [script, src] of Object.entries(scripts)) {
4439
+ const hit = src.match(topLevelTraceWriteRe);
4440
+ if (hit) {
4441
+ out.push(script + ' 出现留痕键的顶层形态「' + hit[0] + '」——留痕必须落在 evidence 嵌套字段(零新增 state 顶层字段)');
4442
+ }
4443
+ }
4444
+ if (!handoff.includes("state.evidence['subagent-execute'].handoffRequests")) {
4445
+ out.push('留痕未落在嵌套证据字段(既有同族形态)——顶层字段禁令的正面锚缺失');
4446
+ }
4447
+ const declaredFields = [...schema.matchAll(/\{ field: '([A-Za-z_$][\w$]*)'/g)].map((m) => m[1]);
4448
+ for (const traceKey of ['handoffRequests', 'handoffResult', 'delegationTrace', 'dispatchTrace']) {
4449
+ if (declaredFields.includes(traceKey)) {
4450
+ out.push('状态字段校验器声明了留痕顶层字段「' + traceKey + '」(应保持嵌套、零新增顶层字段)');
4451
+ }
4452
+ }
4453
+ const writtenTopLevel = [...handoff.matchAll(/\bstate\.([A-Za-z_$][\w$]*)\s*=/g)].map((m) => m[1]);
4454
+ const undeclared = [...new Set(writtenTopLevel)].filter((key) => !declaredFields.includes(key));
4455
+ if (undeclared.length > 0) {
4456
+ out.push('workflow-handoff.mjs 写入了未在状态字段校验器声明的顶层字段: ' + undeclared.join(', '));
4457
+ }
4458
+ return out;
4459
+ };
4460
+ const engineSources = Object.fromEntries(engineScripts.map((script) => [script, fs.readFileSync(path.join(__dirname, script), 'utf8')]));
4461
+ const handoffSource = engineSources['workflow-handoff.mjs'];
4462
+ const schemaSource = engineSources['state-schema.mjs'];
4463
+ const traceSources = { scripts: engineSources, handoff: handoffSource, schema: schemaSource };
4464
+ for (const problem of traceShapeProblems(traceSources)) throw new Error(problem);
4465
+ // 反向构造(同一判据驱动):逐项注入退化形态 ⇒ 必报(判据不恒真空过)。
4466
+ const traceProbes = [
4467
+ ['留痕键顶层赋值注入', {
4468
+ scripts: { ...engineSources, 'workflow-handoff.mjs': handoffSource + '\nstate.delegationTrace = {};\n' },
4469
+ handoff: handoffSource + '\nstate.delegationTrace = {};\n',
4470
+ }, '顶层形态'],
4471
+ ['嵌套落点改顶层', { handoff: handoffSource.replaceAll("state.evidence['subagent-execute'].handoffRequests", 'state.handoffRequests') }, '留痕未落在嵌套证据字段'],
4472
+ ['校验器声明留痕顶层字段', { schema: schemaSource.replace('export const STATE_FIELD_VALIDATORS = [', "export const STATE_FIELD_VALIDATORS = [\n { field: 'delegationTrace', check: () => true },") }, '声明了留痕顶层字段'],
4473
+ ['未声明顶层字段写入', { handoff: handoffSource + '\nstate.undeclaredProbe = 1;\n' }, '未在状态字段校验器声明'],
4474
+ ];
4475
+ for (const [probeLabel, override, expected] of traceProbes) {
4476
+ const probed = { ...traceSources, ...override };
4477
+ if (!traceShapeProblems(probed).some((p) => p.includes(expected))) {
4478
+ throw new Error('反向构造判别力缺失(' + probeLabel + ' 未被判违规)');
4479
+ }
4480
+ }
3140
4481
  },
3141
4482
  },
3142
4483
 
@@ -5218,8 +6559,10 @@ const SCENARIOS = [
5218
6559
  // 113: plan 出口波次散文一致性检测——TASK 的 ## 波次划分 Wave 行任务带 [P]
5219
6560
  // 标记(并行语义)但 XML 任务无 parallel="true" → WARN(散文与机器路由依据不一致,
5220
6561
  // 以任务标记为准);XML 补齐 parallel → 无 WARN。容错:无并行语义的 Wave 行不参与比对。
6562
+ // ③④ 追加同判据的段尾分支回归锚(波次段即文末,新 change 形态 ⇒ 必 BLOCK):段尾判定若
6563
+ // 不成立,该检查会被整段静默跳过——下一条 [P] 行漏扫的同族形态见上一场景。
5221
6564
  {
5222
- name: '113 plan exit:波次散文与并行标记不一致 → WARN',
6565
+ name: '113 plan exit:波次散文与并行标记不一致 → WARN(旧 change)/ BLOCK(新 change,含段即文末形态)',
5223
6566
  run: (dir) => {
5224
6567
  const st = baseState('plan');
5225
6568
  st.evidence.plan = { summary: 'plan done' };
@@ -5242,6 +6585,30 @@ const SCENARIOS = [
5242
6585
  assertExit(res2, 0);
5243
6586
  assertNotOut(res2, '波次散文');
5244
6587
  assertOut(res2, 'ALL CHECKS PASSED');
6588
+ // ③ 段即文末形态(新 change):段提取的段尾判定第三个分支——波次段**即文末**(其后再无段
6589
+ // 标题、亦无分隔线)。先跑「抽掉必报」对照:同 ④ 夹具仅去掉散文行的 [P] 标记 ⇒ 无并行
6590
+ // 语义行 ⇒ 放行(该对照因此在任一态都可观测到)。
6591
+ const stEof = baseState('plan');
6592
+ stEof.evidence.plan = { summary: 'plan done' };
6593
+ stEof.newChange = true;
6594
+ writeState(dir, stEof);
6595
+ assertExit(runGuard(['entry', 'plan'], dir), 0);
6596
+ const taskT01Eof = '<task id="T01"><action>a</action><write_files>f</write_files><verify>v</verify><done>d</done></task>\n';
6597
+ const eofHead = '# TASK\n\n## 波次划分\n\nWave 1 (parallel): ';
6598
+ writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', eofHead + 'T01\n\n' + taskT01Eof);
6599
+ const resEofControl = runGuard(['exit', 'plan'], dir);
6600
+ assertExit(resEofControl, 0);
6601
+ assertNotOut(resEofControl, 'BLOCKED');
6602
+ // ④ 同 ③ 夹具补回 [P] 标记(唯一变量)→ 段尾判定须成立、该检查不得被整段静默跳过 ⇒ BLOCK。
6603
+ // 夹具形态自证(判别力前提):波次段之后不得再出现段标题 / 分隔线——否则该夹具退化为
6604
+ // 「段后有下一段标题」形态,段尾第三分支失去覆盖而断言在两种写法下都成立(假绿)。
6605
+ const eofFixture = eofHead + 'T01[P]\n\n' + taskT01Eof;
6606
+ assertTrue(!/\n##\s|\n---/.test(eofFixture.slice(eofFixture.indexOf('## 波次划分'))),
6607
+ '夹具形态前提不成立:波次段须为文末(其后不得再出现段标题或分隔线),否则段尾分支无覆盖');
6608
+ writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', eofFixture);
6609
+ const resEof = runGuard(['exit', 'plan'], dir);
6610
+ assertExit(resEof, 1);
6611
+ assertOutMatches(resEof, /波次散文标记任务为并行(\[P\])但任务无 parallel="true"/, '波次段即文末时检查被整段跳过');
5245
6612
  },
5246
6613
  },
5247
6614
 
@@ -5630,19 +6997,49 @@ const SCENARIOS = [
5630
6997
  },
5631
6998
  },
5632
6999
 
5633
- // 127: R1——新 change 波次散文不一致 → BLOCKED
7000
+ // 127: R1——新 change 波次散文不一致 → BLOCKED。波次段提取的「段尾」判定在此留一格判别夹具 +
7001
+ // 一格单变量对照:① 段后紧跟下一段标题、段内无大写 Z(阳性对照,检查本身在场,两态同判);
7002
+ // ② 段内**早于** [P] 行出现大写 Z(机检标记字面量形态)但散文行无 [P] 标记(「抽掉必报」对照:
7003
+ // 去掉 [P] 这一个变量 ⇒ 无并行语义行 ⇒ 放行,两态同判);③ 同 ② 的夹具补回 [P] 标记 ⇒ 段体
7004
+ // 若在段内首个大写 Z 处提前收尾,该 [P] 行整行漏扫 ⇒ 本应 BLOCK 却静默放过(③ 即该形态的
7005
+ // 常驻回归锚)。段即文末的第二形态见下一场景(同判据、另一段尾分支,独立成景以便单轮同时可见)。
7006
+ // 两格夹具各自带「形态前提」断言(Z 早于 [P] 行)——形态漂移会让锚静默退化成假绿。
5634
7007
  {
5635
- name: '127 plan exit BLOCKED:新 change 波次散文不一致(R1)',
7008
+ name: '127 plan exit BLOCKED:新 change 波次散文不一致(R1;段内大写 Z 早于 [P] 行形态)',
5636
7009
  run: (dir) => {
5637
7010
  const st = baseState('plan');
5638
7011
  st.evidence.plan = { summary: 'planned' };
5639
7012
  st.newChange = true;
5640
7013
  writeState(dir, st);
5641
7014
  assertExit(runGuard(['entry', 'plan'], dir), 0);
5642
- writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', '# TASK\n\n## 波次划分\n\nWave 1 (parallel): T01[P]\n\n## 任务清单\n\n<task id="T01"><action>a</action><write_files>f</write_files><verify>v</verify><done>d</done></task>\n');
7015
+ const planTask = (text) => writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', text);
7016
+ const taskT01 = '<task id="T01"><action>a</action><write_files>f</write_files><verify>v</verify><done>d</done></task>\n';
7017
+ // 判别句式锚(非裸子串):拦因句 + 判据分支,抽掉该句即红
7018
+ const waveBlocked = /波次散文标记任务为并行(\[P\])但任务无 parallel="true"/;
7019
+ // 大写 Z 说明行:段内早于 [P] 行,且自身不含并行语义词(避免截断态/完整态的行筛选差异)
7020
+ const waveZNote = '- 机检标记形态说明(ZERO-LOGIC-CHANGE-OK)';
7021
+ // ① 段后有下一段标题、段内无 Z → BLOCK(阳性对照:两态同判)
7022
+ planTask('# TASK\n\n## 波次划分\n\nWave 1 (parallel): T01[P]\n\n## 任务清单\n\n' + taskT01);
5643
7023
  const res = runGuard(['exit', 'plan'], dir);
5644
7024
  assertExit(res, 1);
5645
- assertOut(res, '波次');
7025
+ assertOutMatches(res, waveBlocked, '波次散文不一致');
7026
+ // 段内大写 Z 说明行 + 散文行共用夹具(散文行的 [P] 标记为唯一变量):② 不带 [P](抽掉必报
7027
+ // 对照)、③ 带 [P](判别夹具)。形态自证:大写 Z 必须**早于** [P] 行——若 Z 排在 [P] 行之后,
7028
+ // 段体截断点落在该行之后、该行仍会被扫描,本族断言在两种写法下都成立(假绿 ⇒ 零判别力)。
7029
+ const zWaveFixture = (marker) => '# TASK\n\n## 波次划分\n\n' + waveZNote + '\n\nWave 1 (parallel): T01' + marker + '\n\n## 任务清单\n\n' + taskT01;
7030
+ assertTrue(zWaveFixture('[P]').indexOf(waveZNote) < zWaveFixture('[P]').indexOf('T01[P]'),
7031
+ '夹具形态前提不成立:大写 Z 说明行须早于 [P] 行,否则段尾截断不影响该行扫描(锚零判别力)');
7032
+ // ② 抽掉必报自证(单变量对照):段内大写 Z 说明行在场、散文行无 [P] 标记 → 放行
7033
+ planTask(zWaveFixture(''));
7034
+ const resNoMarker = runGuard(['exit', 'plan'], dir);
7035
+ assertExit(resNoMarker, 0);
7036
+ assertNotOut(resNoMarker, 'BLOCKED');
7037
+ assertOut(resNoMarker, 'ALL CHECKS PASSED');
7038
+ // ③ 同一夹具补回散文行的 [P] 标记(唯一变量)→ 段内大写 Z 之后的 [P] 行不得漏扫 ⇒ BLOCK
7039
+ planTask(zWaveFixture('[P]'));
7040
+ const resZ = runGuard(['exit', 'plan'], dir);
7041
+ assertExit(resZ, 1);
7042
+ assertOutMatches(resZ, waveBlocked, '段内大写 Z 之后的 [P] 行漏扫');
5646
7043
  },
5647
7044
  },
5648
7045
 
@@ -6792,8 +8189,10 @@ const SCENARIOS = [
6792
8189
  // 首部 4 字段(Change ID/Task ID/完成时间/AI 角色)+ 段序(含 flow-comet 增量 ## 自检方法 段)。
6793
8190
  // 缺任一:新 change BLOCK(exit 1 + 缺失点与恢复指引);合法变体(编号前缀/括号后缀/大小写)通过;
6794
8191
  // 旧 change → WARN 渐进。当前 guard 只查 verify输出/6维自查/越界检查 3 段存在 → 缺标题等场景 RED。
8192
+ // ⑫⑬ 追加 6 维自查段提取的段尾判定回归锚(段内大写 Z 早于方法名 ⇒ 不得误拦;方法声明真缺席 ⇒
8193
+ // 仍须 BLOCK)——与模板保真共用同一新 change 严格出口链路。
6795
8194
  {
6796
- name: '159 execute exit SUMMARY 模板保真:缺标题/首部/段序新 BLOCK,合法变体通过,旧 WARN',
8195
+ name: '159 execute exit SUMMARY 模板保真:缺标题/首部/段序新 BLOCK,合法变体通过,旧 WARN;6 维段内大写 Z 不误拦 + 未声明仍 BLOCK',
6797
8196
  run: (dir) => {
6798
8197
  const marker = () => {
6799
8198
  fs.mkdirSync(path.join(dir, '.specs', CHANGE_ID, '.skill-loads'), { recursive: true });
@@ -6956,6 +8355,39 @@ const SCENARIOS = [
6956
8355
  assertExit(res11, 1);
6957
8356
  assertOut(res11, 'BLOCKED');
6958
8357
  assertOut(res11, '自检方法');
8358
+ // ⑫ 6 维自查段提取的段尾判定(常驻回归锚 · 假阳性误拦位点):段内**早于**方法名出现大写 Z
8359
+ // (机检标记字面量形态)——串尾若被写成字面字符 Z,惰性段体在段内首个 Z 处提前收尾,
8360
+ // 段内的方法声明被截掉 ⇒ 出口误判「6 维自查未声明自检方法」而 BLOCK。
8361
+ // 单变量对照:与 ⑨/⑩ 的无 Z 合规基线相比只多一行 Z 说明(同一份 dims 原文逐字不变),
8362
+ // 两者都必须 PASS——即该行不得改变判定(既不放宽也不误拦)。
8363
+ const zNote = '> 本任务 diff 属零逻辑改动(机检标记 ZERO-LOGIC-CHANGE-OK),按协议执行 PR Review。';
8364
+ const withSixDim = (six) => fullSections.map((s) => (s === sectionText.sixDim ? six : s));
8365
+ const sixDimZFirst = sectionText.sixDim.replace('## 6 维自查\n\n', '## 6 维自查\n\n' + zNote + '\n\n');
8366
+ assertTrue(sixDimZFirst !== sectionText.sixDim, '单变量前提不成立:6 维自查段标题形态变化,Z 说明行未插入');
8367
+ assertEqual(sixDimZFirst.replace('## 6 维自查\n\n' + zNote + '\n\n', '## 6 维自查\n\n'),
8368
+ sectionText.sixDim, '单变量前提不成立:Z 说明行不是与无 Z 基线的唯一差异');
8369
+ assertTrue(sixDimZFirst.indexOf(zNote) < sixDimZFirst.indexOf('brooks-review'),
8370
+ '夹具形态前提不成立:Z 说明行须早于方法声明,否则段尾截断不影响该声明(锚零判别力)');
8371
+ setupExecute(true);
8372
+ writeFile(dir, '.specs/' + CHANGE_ID + '/T01-SUMMARY.md', compose('# SUMMARY: T01 - 实现 T01', fullSections));
8373
+ const res12Base = runGuard(['exit', 'execute'], dir);
8374
+ assertExit(res12Base, 0);
8375
+ assertOut(res12Base, 'ALL CHECKS PASSED');
8376
+ setupExecute(true);
8377
+ writeFile(dir, '.specs/' + CHANGE_ID + '/T01-SUMMARY.md', compose('# SUMMARY: T01 - 实现 T01', withSixDim(sixDimZFirst)));
8378
+ const res12 = runGuard(['exit', 'execute'], dir);
8379
+ assertExit(res12, 0);
8380
+ assertOut(res12, 'ALL CHECKS PASSED');
8381
+ assertNotOut(res12, 'BLOCKED');
8382
+ // ⑬ 判据未放宽对照 + 抽掉必报自证:同 ⑫ 夹具仅抽掉 6 维段内的方法声明行(其余逐字不变)
8383
+ // ⇒ 6 维自查段确实未声明自检方法 ⇒ 仍须 BLOCK,且拦因须落在该判据上(而非段空 / 段缺席)。
8384
+ const sixDimNoDecl = sixDimZFirst.replace('- 功能: 通过(brooks-review 已跑)', '- 功能: 通过(内置快查)');
8385
+ assertTrue(sixDimNoDecl !== sixDimZFirst, '对照夹具前提不成立:6 维段内方法声明行未命中');
8386
+ setupExecute(true);
8387
+ writeFile(dir, '.specs/' + CHANGE_ID + '/T01-SUMMARY.md', compose('# SUMMARY: T01 - 实现 T01', withSixDim(sixDimNoDecl)));
8388
+ const res13 = runGuard(['exit', 'execute'], dir);
8389
+ assertExit(res13, 1);
8390
+ assertOut(res13, '6 维自查未声明使用 /brooks-review');
6959
8391
  },
6960
8392
  },
6961
8393
 
@@ -7373,28 +8805,34 @@ const SCENARIOS = [
7373
8805
  },
7374
8806
  },
7375
8807
 
7376
- // 164: 技能加载措辞(设计语义 / AC-16)——主 SKILL(SKILL.md / GUIDANCE.md)与节点 SKILL
7377
- // 须含「Skill 工具」与「不得跳过/禁止跳过」。当前主 SKILL 已含、部分节点 SKILL 已含,但
7378
- // open/design/plan/verify/archive 等节点 SKILL 缺 → 预期 RED。
8808
+ // 164: 技能加载措辞(设计语义 / AC-16)——主 SKILL(SKILL.md + 入口展开册)与节点 SKILL
8809
+ // 须含「Skill 工具」与「不得跳过/禁止跳过」。入口展开册随 `GUIDANCE.md` 改名同步为
8810
+ // `reference/entry-detail.md`(判据强度不变:仍是同两条存在级锚点句,只是文件名换了)。
8811
+ // 判据抽成纯函数(单一实现):真实判据与反向构造探针共用,逐份抽掉任一条锚点必红。
7379
8812
  {
7380
8813
  name: '164 技能加载措辞:主 SKILL 与节点 SKILL 含 Skill 工具 + 不得/禁止跳过',
7381
8814
  run: (dir) => {
7382
8815
  const files = [
7383
- path.join(__dirname, '..', 'SKILL.md'),
7384
- path.join(__dirname, '..', 'GUIDANCE.md'),
8816
+ [path.join('flow-comet', 'SKILL.md'), path.join(__dirname, '..', 'SKILL.md')],
8817
+ [path.join('flow-comet', 'reference', 'entry-detail.md'),
8818
+ path.join(__dirname, '..', 'reference', 'entry-detail.md')],
7385
8819
  ...['flow-comet-open', 'flow-comet-design', 'flow-comet-plan', 'flow-comet-execute',
7386
8820
  'flow-comet-subagent-execute', 'flow-comet-review', 'flow-comet-verify', 'flow-comet-archive']
7387
- .map((s) => path.join(__dirname, '..', '..', s, 'SKILL.md')),
8821
+ .map((s) => [path.join(s, 'SKILL.md'), path.join(__dirname, '..', '..', s, 'SKILL.md')]),
7388
8822
  ];
7389
- const relativeBase = path.join(__dirname, '..', '..', '..');
7390
8823
  const missing = [];
7391
- for (const f of files) {
8824
+ for (const [rel, f] of files) {
7392
8825
  const text = fs.readFileSync(f, 'utf8');
7393
- const hasTool = text.includes('Skill 工具');
7394
- const hasSkip = text.includes('不得跳过') || text.includes('禁止跳过');
7395
- if (!hasTool || !hasSkip) {
7396
- const why = !hasTool && !hasSkip ? '缺「Skill 工具」与「不得/禁止跳过」' : (hasTool ? '缺「不得/禁止跳过」' : '缺「Skill 工具」');
7397
- missing.push(path.relative(relativeBase, f) + ' ' + why);
8826
+ missing.push(...skillLoadingWordingProblems(rel, text));
8827
+ // 反向构造(同一判据驱动):逐条锚点句抽掉 ⇒ 必报该条缺失——存在级锚点不得恒真空过。
8828
+ for (const [label, stripped] of [
8829
+ ['Skill 工具', text.split('Skill 工具').join('(反向构造:抽掉)')],
8830
+ ['不得跳过/禁止跳过', text.split('禁止跳过').join('(反向构造:抽掉)').split('不得跳过').join('(反向构造:抽掉)')],
8831
+ ]) {
8832
+ if (stripped === text) continue; // 该条本就不在场,缺失已由真实判据报告
8833
+ if (!skillLoadingWordingProblems(rel, stripped).some((p) => p.includes(label))) {
8834
+ missing.push(rel + ' 反向构造判别力缺失(抽掉「' + label + '」未被判缺失)');
8835
+ }
7398
8836
  }
7399
8837
  }
7400
8838
  if (missing.length > 0) {
@@ -7475,6 +8913,7 @@ const SCENARIOS = [
7475
8913
  // 167: 两层加载模型措辞——阶段层禁止在节点 SKILL 内指示用 Skill 工具加载任何节点实现技能
7476
8914
  //(本节点技能已由入口路由经 Skill 工具加载);入口层禁止 Implementation/Required 混淆句式;
7477
8915
  // 全部 10 文件禁止无限定「record 会自动补写缺失的声明标记」表述(与新 change 技能加载前置门矛盾)。
8916
+ // 入口层的第二份随 `GUIDANCE.md` 改名同步为 `reference/entry-detail.md`(判据强度不变)。
7478
8917
  {
7479
8918
  name: '167 两层加载模型措辞:禁自加载句式/禁混淆句式/自动补分新旧',
7480
8919
  run: () => {
@@ -7491,12 +8930,30 @@ const SCENARIOS = [
7491
8930
  if (text.includes(autoFill)) problems.push(id + ' 含无限定自动补表述');
7492
8931
  if (!text.includes(stageAnchor)) problems.push(id + ' 缺阶段层锚点句');
7493
8932
  }
7494
- for (const name of ['SKILL.md', 'GUIDANCE.md']) {
7495
- const text = fs.readFileSync(path.join(__dirname, '..', name), 'utf8');
7496
- if (text.includes('见上方 Required Calls 表')) problems.push(name + ' 含 Implementation/Required 混淆句式');
7497
- if (text.includes(autoFill)) problems.push(name + ' 含无限定自动补表述');
7498
- if (!text.includes(entryAnchor)) problems.push(name + ' 缺入口层锚点句');
7499
- if (!text.includes('前置门')) problems.push(name + ' 缺前置门表述');
8933
+ const entryLevelFiles = [
8934
+ ['flow-comet/SKILL.md', path.join(__dirname, '..', 'SKILL.md')],
8935
+ ['flow-comet/reference/entry-detail.md', path.join(__dirname, '..', 'reference', 'entry-detail.md')],
8936
+ ];
8937
+ for (const [rel, file] of entryLevelFiles) {
8938
+ const text = fs.readFileSync(file, 'utf8');
8939
+ problems.push(...twoLayerEntryProblems(rel, text));
8940
+ // 反向构造(同一判据驱动):逐条锚点句抽掉 ⇒ 必报;还原混淆句式 / 无限定自动补表述 ⇒ 必报。
8941
+ for (const [label, stripped] of [
8942
+ ['入口层锚点句', text.split(entryAnchor).join('(反向构造:抽掉)')],
8943
+ ['前置门', text.split('前置门').join('(反向构造:抽掉)')],
8944
+ ]) {
8945
+ if (stripped === text) continue; // 该条本就不在场,缺失已由真实判据报告
8946
+ if (!twoLayerEntryProblems(rel, stripped).some((p) => p.includes(label))) {
8947
+ problems.push(rel + ' 反向构造判别力缺失(抽掉「' + label + '」未被判缺失)');
8948
+ }
8949
+ }
8950
+ const regressed = text + '\n见上方 Required Calls 表。' + autoFill + '。\n';
8951
+ const regressedProblems = twoLayerEntryProblems(rel, regressed);
8952
+ for (const label of ['Implementation/Required 混淆句式', '无限定自动补表述']) {
8953
+ if (!regressedProblems.some((p) => p.includes(label))) {
8954
+ problems.push(rel + ' 反向构造判别力缺失(还原「' + label + '」未被判违规)');
8955
+ }
8956
+ }
7500
8957
  }
7501
8958
  if (problems.length > 0) throw new Error('两层加载模型措辞不符: ' + problems.join('; '));
7502
8959
  },
@@ -8205,19 +9662,33 @@ const SCENARIOS = [
8205
9662
  },
8206
9663
 
8207
9664
  // 184: 技能文本混排合法化语义文本锁(in-place 扩展:模板权威整句 / 入口 archive 读法 /
8208
- // 规划约束 / Codex-worktree 订正)——plan 与 subagent-execute 两 SKILL 权威源不得再含
9665
+ // 规划约束 / Codex 平台事实)——plan 与 subagent-execute 两 SKILL 权威源不得再含
8209
9666
  // 「连续块」「居首」旧波次形态约束表述,且依赖图语义描述(depends_on)在场、「用 Skill 工具」
8210
- // 两层加载句式保持(措辞锁族既有锚不破坏);模板权威声明覆盖 9 个既有成员(8 产出节点 + task)
8211
- // 与 5 个 flow-kit 阶段协议技能 = 14 个真实成员(题面 13 按 8+5 计数漏计 task;保留既有断言
8212
- // 优先,实际按 14 文件落地,成员边界见收口证据)——每份须在同一声明行内按序组合出现
8213
- // 「唯一权威 = 」/「`flow-kit/templates/**`」/「是历史证据」/「不是模板来源」/「上一轮就是这么写的」
8214
- // 且全数零命中旧反向声明「archive 是模板来源」;入口 SKILL 含 archive 三要素读法;plan / task
8215
- // 含规划约束判别句式与各自边界锚(以本节为准 / 以本节点为准),旧同层并行句零残留;
8216
- // worktree-notes / subagent-execute 含平台事实(multi_agent)与支持面(机制缺口)判别锚、
8217
- // 适用范围限定(不得外推 / 不可外推),旧独断句只允许以被反驳引用形态出现。
9667
+ // 两层加载句式保持(措辞锁族既有锚不破坏)。
9668
+ // **逐字锁重定向(ADR-016)**:原「同一文字须在多册出现」的硬锁一律改为「单一权威 + 指针在场 +
9669
+ // 正文唯一」三件套,每条新锚自带反向构造(抽掉目标文字必红——`LESSONS` L-106 判别句式,非裸子串):
9670
+ // ② 模板权威:14 册各自的锚句**即指向唯一权威 `flow-kit/templates/**` 的指针**(整句语义组合
9671
+ // 仍在场,缺任一册即红);「该句只在 1 处」落在**册内一侧**(每册恰一处——同册复制第二份即红),
9672
+ // 并补「作者面唯一」:全部持锚行的分发文本必须同指 `flow-kit/templates/**`(指向别处即红)。
9673
+ // ⑤ 平台事实:判别句随 `worktree-notes.md` 移出而迁入 `reference/platform-facts.md`(T07 已搬入)
9674
+ // ——判据改为「权威文件在场 + 判别句在权威处 + 各引用册指针在场 + 判别句**不再回流册子**」。
9675
+ // ⑥ 三块归一处:`reference/commit-discipline.md` 持 pathspec 五要素与集成四要素**全文**(权威处),
9676
+ // 两册只留要点句(**不再要求逐字一致**,逐字锁已作废);权威处独有的「证据与判级」判别句
9677
+ // 回流任一册即红。
9678
+ // ⑦ 入口册的 7 条字面量与「建树适用面两句」保留(能力契约锚);`worktree-notes.md` 的 6 条整句
9679
+ // 随文件移出改锚到 `reference/platform-facts.md`,并断言各引用册指针在场。
9680
+ // ⑧ 文本↔实现一致(文本不得说谎):**保留原样**——它不是「多册同文字」类锁,本批不动。
9681
+ // 附:技能树正文的相对路径引用必须解析得到(本轮 `GUIDANCE.md` 改名曾造成 5 册死引用而零红灯)。
9682
+ // 附 2:成对展开文件的指针**不得指错**——「能解析 ≠ 指对了」:同目录带同名 `GUIDANCE.md` 的册,
9683
+ // 册首「手写区详细协议见 …」必须是本册裸文件名;入口册(展开版为 `reference/entry-detail.md`)
9684
+ // 是唯一例外。解析判据只证明目标**存在**,证明不了**指对了**——本附与之互补。
8218
9685
  // 文本存在级断言(结构级由其余场景族覆盖)。
9686
+ // in-place 扩展(委托契约纪律文本锁):两册(委托册 / 串行册)各自须含四属性契约、提交面 pathspec
9687
+ // 纪律与集成纪律的**要点句与条件句**;旧表述零残留(无条件 worktree 口号仅允许被反驳形态、
9688
+ // 「未获机制明文放行」清零);文本点名的实现常量 / 载荷键名 / 受保护目标与引擎实现逐项对照
9689
+ //(文本说 A、实现说 B 即红)。
8219
9690
  {
8220
- name: '184 技能文本锁:旧连续块/居首表述清零且依赖图语义描述在场',
9691
+ name: '184 技能文本锁:模板权威指针在场 + 三块归一处 + 纪律判别句式 + 文本↔实现一致',
8221
9692
  run: () => {
8222
9693
  const problems = [];
8223
9694
  // —— 既有锚(原文语义与失败消息保持)——
@@ -8228,37 +9699,175 @@ const SCENARIOS = [
8228
9699
  if (!text.includes('depends_on')) problems.push(skillDir + ' 缺依赖图语义描述(depends_on)');
8229
9700
  if (!text.includes('用 Skill 工具')) problems.push(skillDir + ' 缺「用 Skill 工具」两层加载句式');
8230
9701
  }
8231
- // —— 模板权威整句声明:9 个既有成员 + 5 个 flow-kit 阶段协议技能(真实成员 14)——
8232
- const templateAuthoritySkills = [
8233
- 'flow-comet-open', 'flow-comet-design', 'flow-comet-plan', 'flow-comet-execute',
8234
- 'flow-comet-subagent-execute', 'flow-comet-review', 'flow-comet-verify', 'flow-comet-archive',
8235
- 'flow-comet-task',
8236
- 'flow-comet-change', 'flow-comet-requirement', 'flow-comet-dev', 'flow-comet-test',
8237
- 'flow-comet-integration',
8238
- ];
8239
- // 整句级语义组合:同一段声明行内按序出现下列锚点,防止只留半句或把锚点拆到不同段落。
8240
- const authoritySentenceAnchors = [
8241
- '唯一权威 = ', '`flow-kit/templates/**`', '是历史证据', '不是模板来源', '上一轮就是这么写的',
8242
- ];
9702
+ // —— ② 模板权威(重定向后的三件套)——成员面与整句锚点取自模块级常量(单一来源):
9703
+ // 9 个既有成员 + 5 个 flow-kit 阶段协议技能 = 14 个真实成员(含 task);受检面另加
9704
+ // 入口册与入口展开册(两者是「短指针」形态的既有持有者)。
9705
+ const templateAuthoritySkills = TEMPLATE_AUTHORITY_SKILLS;
9706
+ const templateAuthorityDocs = new Map();
8243
9707
  for (const skillDir of templateAuthoritySkills) {
8244
- const rel = skillDir + '/SKILL.md';
8245
- const text = fs.readFileSync(path.join(__dirname, '..', '..', skillDir, 'SKILL.md'), 'utf8');
8246
- const authorityLine = text.split(/\r?\n/).find((line) => line.includes('模板权威'));
8247
- if (!authorityLine) {
8248
- problems.push(rel + ' 缺模板权威整句声明(正向权威 + 反向历史证据组合缺失)');
8249
- continue;
9708
+ templateAuthorityDocs.set(skillDir + '/SKILL.md',
9709
+ fs.readFileSync(path.join(__dirname, '..', '..', skillDir, 'SKILL.md'), 'utf8'));
9710
+ }
9711
+ templateAuthorityDocs.set('flow-comet/SKILL.md', fs.readFileSync(path.join(__dirname, '..', 'SKILL.md'), 'utf8'));
9712
+ templateAuthorityDocs.set('flow-comet/reference/entry-detail.md',
9713
+ fs.readFileSync(path.join(__dirname, '..', 'reference', 'entry-detail.md'), 'utf8'));
9714
+ problems.push(...templateAuthorityProblems(templateAuthorityDocs));
9715
+ // 反向构造(同一判据驱动,逐条对应重定向后的两侧):
9716
+ // ① 同一册复制第二份锚行 ⇒ 必报「只允许 1 处」(重复回潮的同册形态);
9717
+ // ② 权威目标改指别处 ⇒ 必报「未指向」(单一权威侧);
9718
+ // ③ **真实文本变异**(不再用合成 `'y'.repeat(n)` 串):把入口册的声明块**原样**搬进另一册
9719
+ // ——判据面里的那册原块被**替换**掉,故不触发「同册第二处锚句」,只可能由正文唯一判据
9720
+ // 发声 ⇒ 必报「第二份展开正文」(旧探针只证明比较器能用,证不了判据面选得对);
9721
+ // ④ 抽掉某册锚句 ⇒ 必报该册缺声明(指针在场侧)。
9722
+ {
9723
+ const openRel = 'flow-comet-open/SKILL.md';
9724
+ const openText = templateAuthorityDocs.get(openRel);
9725
+ const anchorLine = openText.split(/\r?\n/).find((l) => l.includes('模板权威'));
9726
+ const entryBlock = templateAuthorityParagraphs(templateAuthorityDocs.get('flow-comet/SKILL.md'))[0] ?? '';
9727
+ const openBlock = templateAuthorityParagraphs(openText)[0] ?? '';
9728
+ if (entryBlock === '' || openBlock === '' || templateAuthorityBody(entryBlock) === '') {
9729
+ problems.push('正文唯一反向构造的前提不成立:入口册声明块缺失 / 无正文行(无法构造真实变异探针)');
8250
9730
  }
8251
- let cursor = -1;
8252
- for (const anchor of authoritySentenceAnchors) {
8253
- const at = authorityLine.indexOf(anchor, cursor + 1);
8254
- if (at < 0) {
8255
- problems.push(rel + ' 模板权威整句缺「' + anchor + '」(整句语义组合)');
8256
- } else {
8257
- cursor = at;
9731
+ const probes = [
9732
+ ['同册复制第二份锚行', new Map(templateAuthorityDocs).set(openRel, openText + '\n' + anchorLine + '\n'),
9733
+ '只允许 1 处'],
9734
+ ['权威目标改指别处', new Map(templateAuthorityDocs).set(openRel,
9735
+ openText.split('`flow-kit/templates/**`').join('`.specs/archive/**`')), '未指向'],
9736
+ ['入口册声明块原样搬进另一册', new Map(templateAuthorityDocs)
9737
+ .set(openRel, openText.split(openBlock).join(entryBlock)), '第二份展开正文'],
9738
+ ['抽掉某册锚句', new Map(templateAuthorityDocs).set(openRel,
9739
+ openText.split(anchorLine).join('(反向构造:抽掉锚句)')), '缺模板权威'],
9740
+ ];
9741
+ for (const [label, probed, expected] of probes) {
9742
+ if (!templateAuthorityProblems(probed).some((p) => p.includes(expected))) {
9743
+ problems.push('反向构造判别力缺失(模板权威: ' + label + ' 未被判违规)');
8258
9744
  }
8259
9745
  }
8260
- if (text.includes('archive 是模板来源')) {
8261
- problems.push(rel + ' 含「archive 是模板来源」旧反向声明');
9746
+ }
9747
+ // 作者面完备性(判据 = **登记**,不是**计数相等**):新增持锚文本必须**显式登记**在受检面
9748
+ // 常量里,否则报「未登记的权威声明」——报错指向真实动作(把新册登记进 `TEMPLATE_AUTHORITY_SKILLS`
9749
+ // 并同批加声明)。**不做计数相等**:同文件别处的判据注释明确反对「以总量取红」的自锁探针
9750
+ //(合法扩册会先撞红、报错方向指向锚而非真实动作);受检面成员**缺**声明由
9751
+ // `templateAuthorityProblems` 的逐份「缺模板权威整句声明」覆盖,故登记判据**单向**判定即可。
9752
+ {
9753
+ const expectedHolders = [...templateAuthorityDocs.keys()].sort();
9754
+ const actualHolders = skillTreeDocFiles()
9755
+ .filter(([, file]) => fs.readFileSync(file, 'utf8').includes('模板权威'))
9756
+ .map(([rel]) => rel)
9757
+ .sort();
9758
+ problems.push(...templateAuthorityRegistrationProblems(actualHolders, expectedHolders));
9759
+ // 反向构造(同一判据驱动):① 未登记的新持有者 ⇒ 必报「未登记」;② 同批登记(把新册加进
9760
+ // 受检面常量)⇒ **零问题**(合法扩册不再先红——旧计数相等判据正是在这一步撞红)。
9761
+ const registeredProbe = 'flow-comet-probe-node/SKILL.md';
9762
+ for (const [label, holders, expected, shouldReport] of [
9763
+ ['未登记的新持有者', [...actualHolders, registeredProbe], expectedHolders, true],
9764
+ ['同批登记后的新持有者', [...actualHolders, registeredProbe], [...expectedHolders, registeredProbe], false],
9765
+ ]) {
9766
+ const reported = templateAuthorityRegistrationProblems(holders, expected)
9767
+ .some((p) => p.includes(registeredProbe));
9768
+ if (reported !== shouldReport) {
9769
+ problems.push('反向构造判别力缺失(模板权威登记: ' + label + (shouldReport ? ' 未被判违规' : ' 被误判违规') + ')');
9770
+ }
9771
+ }
9772
+ }
9773
+ // —— 附:技能树正文的相对路径引用必须解析得到(本轮改名造成 5 册死引用而**零红灯**)——
9774
+ {
9775
+ const skillsRootAbs = path.join(__dirname, '..', '..');
9776
+ const treeDocs = new Map(skillTreeDocFiles().map(([rel, file]) => [rel, fs.readFileSync(file, 'utf8')]));
9777
+ problems.push(...skillTreeReferenceProblems(treeDocs, skillsRootAbs));
9778
+ // 反向构造(同一判据驱动):① 把引用改写成不存在的目标 ⇒ 必报「解析不到」;
9779
+ // ② 抽掉引用 ⇒ 判据面收缩但**不误报**(证明判据只在引用在场时发声,不恒真);
9780
+ // ③ **形态收窄侧**:把节点册里的一处**显式跨册**指针改回**裸形态** ⇒ 必报「解析不到」
9781
+ //(旧实现给裸形态合成「入口册册根」候选,这一改法当时**判绿**——正是假绿本身)。
9782
+ const sampleEntry = [...treeDocs].find(([, text]) => SKILL_TREE_REFERENCE_RE.test(text));
9783
+ SKILL_TREE_REFERENCE_RE.lastIndex = 0;
9784
+ if (!sampleEntry) {
9785
+ problems.push('相对路径引用判据的前提不成立:技能树里找不到任何 reference/ 相对引用');
9786
+ } else {
9787
+ const [sampleRel, sampleText] = sampleEntry;
9788
+ const sampleRef = sampleText.match(SKILL_TREE_REFERENCE_RE)[0];
9789
+ const broken = new Map(treeDocs).set(sampleRel,
9790
+ sampleText.split(sampleRef).join('reference/renamed-away-fixture.md'));
9791
+ if (!skillTreeReferenceProblems(broken, skillsRootAbs).some((p) => p.includes('解析不到'))) {
9792
+ problems.push('反向构造判别力缺失(死引用未被判「解析不到」): ' + sampleRel + ' → ' + sampleRef);
9793
+ }
9794
+ const dropped = new Map(treeDocs).set(sampleRel, sampleText.split(sampleRef).join(''));
9795
+ if (skillTreeReferenceProblems(dropped, skillsRootAbs).some((p) => p.startsWith(sampleRel))) {
9796
+ problems.push('相对路径引用判据误报(抽掉引用后仍报该册): ' + sampleRel);
9797
+ }
9798
+ }
9799
+ const explicitEntry = [...treeDocs].find(([rel, text]) => !rel.startsWith(SKILL_TREE_ENTRY_BOOK + '/')
9800
+ && text.includes(SKILL_TREE_EXPLICIT_REFERENCE_PREFIX));
9801
+ if (!explicitEntry) {
9802
+ problems.push('形态收窄反向构造的前提不成立:节点册里找不到显式跨册指针'
9803
+ + '(`' + SKILL_TREE_EXPLICIT_REFERENCE_PREFIX + 'reference/…`)');
9804
+ } else {
9805
+ const [nodeRel, nodeText] = explicitEntry;
9806
+ const explicitRef = nodeText.match(
9807
+ new RegExp('\\.\\.\\/flow-comet\\/reference\\/[A-Za-z0-9._-]+\\.(?:md|json)'))[0];
9808
+ const reverted = new Map(treeDocs).set(nodeRel,
9809
+ nodeText.split(explicitRef).join(explicitRef.replace(SKILL_TREE_EXPLICIT_REFERENCE_PREFIX, '')));
9810
+ if (!skillTreeReferenceProblems(reverted, skillsRootAbs).some((p) => p.includes('解析不到'))) {
9811
+ problems.push('反向构造判别力缺失(节点册指针改回裸形态未被判违规): ' + nodeRel + ' → ' + explicitRef);
9812
+ }
9813
+ }
9814
+ // —— 附 2:成对展开文件的指针不得指错(上一条只证明目标**存在**,本条判**指对了**)——
9815
+ {
9816
+ const bookRels = [...treeDocs.keys()].filter((rel) => rel.endsWith('/SKILL.md')
9817
+ && !path.posix.dirname(rel).includes('/'));
9818
+ const hasOwnGuidance = (rel) => fs.existsSync(path.join(skillsRootAbs, path.posix.dirname(rel), 'GUIDANCE.md'));
9819
+ const pairedRels = bookRels.filter(hasOwnGuidance);
9820
+ const entryHasOwn = hasOwnGuidance(PAIRED_GUIDANCE_ENTRY_REL);
9821
+ // 前提:成对形态在场(否则判据空转)+ 入口册的例外目标在场(入口册无同名展开版时)。
9822
+ if (pairedRels.length === 0) {
9823
+ problems.push('成对指针判据的前提不成立:技能树里找不到任何带同目录 GUIDANCE.md 的册');
9824
+ }
9825
+ if (!entryHasOwn
9826
+ && !fs.existsSync(path.join(skillsRootAbs, path.posix.dirname(PAIRED_GUIDANCE_ENTRY_REL),
9827
+ PAIRED_GUIDANCE_ENTRY_TARGET))) {
9828
+ problems.push('成对指针判据的前提不成立:入口册展开版 ' + PAIRED_GUIDANCE_ENTRY_TARGET + ' 不在场(唯一例外无处指向)');
9829
+ }
9830
+ problems.push(...pairedGuidancePointerProblems(treeDocs, skillsRootAbs));
9831
+ // 反向构造(同一判据驱动):① 带同目录 GUIDANCE 的册改指**入口册**展开版 ⇒ 必报「指错文档」;
9832
+ // ② 改指**另一册**的展开版 ⇒ 必报(另一侧形态,证明判据不靠"是否含 GUIDANCE.md 子串"恒真);
9833
+ // ③ 入口册改指裸文件名 ⇒ 必报(唯一例外侧);④ 抽掉指针 ⇒ 必报缺指针;⑤ 同册第二处指针 ⇒ 必报
9834
+ // 重复;⑥ 无配对展开版的册带指针 ⇒ 必报;⑦ 无配对展开版的册不带指针 ⇒ **零误报**(判据不恒真)。
9835
+ const pointerProbe = (rel, target) => new Map(treeDocs).set(rel,
9836
+ (treeDocs.get(rel) ?? '').replace(PAIRED_GUIDANCE_POINTER_RE,
9837
+ '<!-- 手写区详细协议见 ' + target + '(可选阅读) -->'));
9838
+ const probeRel = pairedRels.find((rel) => rel !== PAIRED_GUIDANCE_ENTRY_REL);
9839
+ const otherProbeRel = pairedRels.find((rel) => rel !== probeRel);
9840
+ const quietRel = bookRels.find((rel) => rel !== PAIRED_GUIDANCE_ENTRY_REL && !hasOwnGuidance(rel));
9841
+ const probeText = treeDocs.get(probeRel) ?? '';
9842
+ const pointerLine = probeText.match(PAIRED_GUIDANCE_POINTER_RE)?.[0] ?? '';
9843
+ if (!probeRel || !otherProbeRel || !quietRel || !pointerLine) {
9844
+ problems.push('成对指针反向构造的前提不成立:成对册不足两册 / 无无配对展开版的非入口册 / 探针册无指针行');
9845
+ } else {
9846
+ const probes = [
9847
+ ['册改指入口册展开版', pointerProbe(probeRel, '../flow-comet/reference/entry-detail.md'), '指错文档'],
9848
+ ['册改指另一册展开版', pointerProbe(probeRel,
9849
+ '../' + path.posix.dirname(otherProbeRel) + '/GUIDANCE.md'), '指错文档'],
9850
+ ['抽掉指针', new Map(treeDocs).set(probeRel, probeText.replace(PAIRED_GUIDANCE_POINTER_RE, '')),
9851
+ '缺「手写区详细协议见 …」指针'],
9852
+ ['同册第二处指针', new Map(treeDocs).set(probeRel, probeText + '\n' + pointerLine), '只允许 1 处'],
9853
+ ['无配对展开版的册带指针', new Map(treeDocs).set(quietRel,
9854
+ (treeDocs.get(quietRel) ?? '') + '\n' + pointerLine), '既无同目录 GUIDANCE.md 也非入口册'],
9855
+ ];
9856
+ if (!entryHasOwn) {
9857
+ probes.push(['入口册改指裸文件名', pointerProbe(PAIRED_GUIDANCE_ENTRY_REL, 'GUIDANCE.md'), '指错文档']);
9858
+ }
9859
+ for (const [label, probed, expected] of probes) {
9860
+ if (!pairedGuidancePointerProblems(probed, skillsRootAbs).some((p) => p.includes(expected))) {
9861
+ problems.push('反向构造判别力缺失(成对指针: ' + label + ' 未被判违规)');
9862
+ }
9863
+ }
9864
+ }
9865
+ if (!quietRel) {
9866
+ problems.push('成对指针反向构造的前提不成立:找不到无配对展开版的非入口册');
9867
+ } else if (pairedGuidancePointerProblems(new Map([[quietRel,
9868
+ (treeDocs.get(quietRel) ?? '').replace(PAIRED_GUIDANCE_POINTER_RE, '')]]), skillsRootAbs).length !== 0) {
9869
+ problems.push('成对指针判据误报(无配对展开版且不带指针的册被判违规): ' + quietRel);
9870
+ }
8262
9871
  }
8263
9872
  }
8264
9873
  // —— 入口 archive 读法:三要素关键词在场 ——
@@ -8299,47 +9908,614 @@ const SCENARIOS = [
8299
9908
  if (!taskText.includes('以本节点为准')) {
8300
9909
  problems.push('flow-comet-task/SKILL.md 缺「以本节点为准」(上游宽松语义显式覆盖锚)');
8301
9910
  }
8302
- const guidance = fs.readFileSync(path.join(__dirname, '..', 'GUIDANCE.md'), 'utf8');
9911
+ const guidanceRel = 'flow-comet/reference/entry-detail.md';
9912
+ const guidance = fs.readFileSync(path.join(__dirname, '..', 'reference', 'entry-detail.md'), 'utf8');
8303
9913
  if (!guidance.includes('仍必须由 subagent-execute 委托消化')) {
8304
- problems.push('flow-comet/GUIDANCE.md 缺「仍必须由 subagent-execute 委托消化」(direct 委托消化判别句)');
9914
+ problems.push(guidanceRel + ' 缺「仍必须由 subagent-execute 委托消化」(direct 委托消化判别句)');
8305
9915
  }
8306
9916
  }
8307
- // —— Codex / worktree 订正:平台事实 + 支持面判别锚与适用范围限定在场、旧独断句
8308
- // 只允许以被反驳引用形态出现、fail-open 与未闭合限定在场、旧过宽句零残留 ——
9917
+ // —— ⑤ Codex 平台事实与支持面(**判别句随 `worktree-notes.md` 移出技能树而迁入
9918
+ // `reference/platform-facts.md`**,ADR-016):判据 = 权威文件在场 + 判别句在权威处
9919
+ //(含被反驳引用形态、适用范围限定、fail-open / 未闭合的现判据)+ 各引用册指针在场 +
9920
+ // **判别句不再回流册子**(权威处唯一——原「两处各自须含」的逐字锁已作废)。
8309
9921
  {
8310
- const codexTexts = new Map([
8311
- ['reference/worktree-notes.md', fs.readFileSync(path.join(__dirname, '..', 'reference', 'worktree-notes.md'), 'utf8')],
9922
+ const platformFactsRel = 'flow-comet/reference/platform-facts.md';
9923
+ const factsFile = path.join(__dirname, '..', 'reference', 'platform-facts.md');
9924
+ const pointerBooks = [
8312
9925
  ['flow-comet-subagent-execute/SKILL.md', fs.readFileSync(path.join(__dirname, '..', '..', 'flow-comet-subagent-execute', 'SKILL.md'), 'utf8')],
8313
- ]);
8314
- const refutedClaim = '「Codex 不能委派 / 不使用并行委托」';
8315
- for (const [rel, text] of codexTexts) {
8316
- for (const keyword of ['multi_agent', '机制缺口']) {
8317
- if (!text.includes(keyword)) {
8318
- problems.push(rel + ' 缺「' + keyword + '」(Codex 平台事实与支持面判别锚)');
9926
+ ['flow-comet-execute/SKILL.md', fs.readFileSync(path.join(__dirname, '..', '..', 'flow-comet-execute', 'SKILL.md'), 'utf8')],
9927
+ ['flow-comet/SKILL.md', fs.readFileSync(path.join(__dirname, '..', 'SKILL.md'), 'utf8')],
9928
+ ];
9929
+ if (!fs.existsSync(factsFile)) {
9930
+ problems.push(platformFactsRel + ' 不在场(判别句的唯一权威处缺失——原 worktree-notes 的锚无处可寻)');
9931
+ } else {
9932
+ const facts = fs.readFileSync(factsFile, 'utf8');
9933
+ problems.push(...platformFactsAuthorityProblems(platformFactsRel, facts, pointerBooks));
9934
+ // 反向构造(同一判据驱动):① 权威处逐条抽掉判别句 ⇒ 必报缺句;② 判别句回流任一册 ⇒ 必报
9935
+ //(「权威处唯一」——原逐字锁**要求**两处各持一份,恰恰抓不到回流);③ 旧独断句 / 旧过宽句
9936
+ // 还原进权威处 ⇒ 必报残留。
9937
+ for (const phrase of [...PLATFORM_FACTS_ONLY_PHRASES, 'fail-open', '未闭合']) {
9938
+ const stripped = facts.split(phrase).join('(反向构造:抽掉)');
9939
+ if (stripped === facts) continue;
9940
+ if (!platformFactsAuthorityProblems(platformFactsRel, stripped, pointerBooks)
9941
+ .some((p) => p.includes(phrase.slice(0, 20)))) {
9942
+ problems.push('反向构造判别力缺失(平台事实: 抽掉「' + phrase.slice(0, 20) + '…」未被判缺失)');
9943
+ }
9944
+ }
9945
+ for (const phrase of PLATFORM_FACTS_ONLY_PHRASES) {
9946
+ const injected = pointerBooks.map(([rel, text]) => [rel, text + '\n' + phrase + '\n']);
9947
+ if (!platformFactsAuthorityProblems(platformFactsRel, facts, injected)
9948
+ .some((p) => p.includes('回流了平台事实的证据正文'))) {
9949
+ problems.push('反向构造判别力缺失(平台事实: 把证据正文复制回册子未被判违规)');
8319
9950
  }
8320
9951
  }
8321
- // 旧独断句只允许以被反驳引用的完整形态出现:剥离该引用后不得再有残句。
8322
- if (text.split(refutedClaim).join('').includes('不使用并行委托')) {
8323
- problems.push(rel + ' 残留旧独断句「不使用并行委托」(非被反驳引用形态)');
9952
+ const revertedFacts = platformFactsAuthorityProblems(platformFactsRel,
9953
+ facts + '\n受支持的工作流仍是串行执行。写入仍会被协调者白名单拦截。\n', pointerBooks);
9954
+ for (const label of ['旧独断句', '旧过宽句']) {
9955
+ if (!revertedFacts.some((p) => p.includes(label))) {
9956
+ problems.push('反向构造判别力缺失(平台事实: 还原' + label + '未被判残留)');
9957
+ }
9958
+ }
9959
+ const revertedClaimFacts = platformFactsAuthorityProblems(platformFactsRel,
9960
+ facts + '\n不使用并行委托。\n', pointerBooks);
9961
+ if (!revertedClaimFacts.some((p) => p.includes('非被反驳引用形态'))) {
9962
+ problems.push('反向构造判别力缺失(平台事实: 还原裸旧独断句未被判违规)');
9963
+ }
9964
+ if (!platformFactsAuthorityProblems(platformFactsRel, facts, [
9965
+ // 抽掉指针按**文件名子串**(不带反引号、不带前缀)——指针形态从裸形态统一为显式跨册形态
9966
+ // 时本探针仍有效(形态变化不得让反向构造静默失效)。
9967
+ ...pointerBooks.slice(0, 1).map(([rel, text]) => [rel, text.split('reference/platform-facts.md').join('(反向构造:抽掉指针)')]),
9968
+ ...pointerBooks.slice(1),
9969
+ ]).some((p) => p.includes('引用册指针不在场'))) {
9970
+ problems.push('反向构造判别力缺失(平台事实: 抽掉引用册指针未被判违规)');
9971
+ }
9972
+ }
9973
+ }
9974
+ // —— ⑥ 三块归一处(ADR-016):原「两册三块逐字一致(切片 ≥400 字符)+ 两册各持 41 条判别句」
9975
+ // 的逐字锁**作废**,改为「两册各自的要点句在场 + 权威处唯一 + 留正文的判别句逐句留原文但
9976
+ // **不再要求两册相同**」。归一处:pathspec 与集成 → `reference/commit-discipline.md` 全文;
9977
+ // 四属性契约 → 入口册 + `reference/platform-facts.md`。判别句按性质分流:属「该怎么干」的
9978
+ // 留两册正文(外部原则:非显然的坑留正文),属「证据与判级」的随平台事实移走。
9979
+ {
9980
+ const bookTexts = new Map([
9981
+ ['flow-comet-subagent-execute/SKILL.md', fs.readFileSync(path.join(__dirname, '..', '..', 'flow-comet-subagent-execute', 'SKILL.md'), 'utf8')],
9982
+ ['flow-comet-execute/SKILL.md', fs.readFileSync(path.join(__dirname, '..', '..', 'flow-comet-execute', 'SKILL.md'), 'utf8')],
9983
+ ]);
9984
+ const commitDisciplineText = fs.readFileSync(
9985
+ path.join(__dirname, '..', 'reference', 'commit-discipline.md'), 'utf8');
9986
+ const elementDocs = new Map([...bookTexts, [COMMIT_DISCIPLINE_REL, commitDisciplineText]]);
9987
+ const authorityTexts = new Map([
9988
+ [COMMIT_DISCIPLINE_REL, commitDisciplineText],
9989
+ [PLATFORM_FACTS_REL, fs.readFileSync(path.join(__dirname, '..', 'reference', 'platform-facts.md'), 'utf8')],
9990
+ ['flow-comet/SKILL.md', fs.readFileSync(path.join(__dirname, '..', 'SKILL.md'), 'utf8')],
9991
+ ]);
9992
+ const disciplineSources = { books: bookTexts, elementDocs, authorityTexts };
9993
+ problems.push(...delegationDisciplineProblems(disciplineSources));
9994
+ // 反向构造(同一判据驱动):逐条抽掉 ⇒ 必报;逐条回流 ⇒ 必报。判别力不依赖人工实验:
9995
+ // 要素级 token / 权威处判别句 / 能力契约判别句 / 条件句指针 / 证据与判级判别句五组各取全量。
9996
+ const subRel = 'flow-comet-subagent-execute/SKILL.md';
9997
+ const exRel = 'flow-comet-execute/SKILL.md';
9998
+ const strip = (text, phrase) => text.split(phrase).join('(反向构造:抽掉)');
9999
+ const withBook = (rel, text) => ({ ...disciplineSources, books: new Map(bookTexts).set(rel, text) });
10000
+ const withElementDoc = (rel, text) => ({ ...disciplineSources, elementDocs: new Map(elementDocs).set(rel, text) });
10001
+ const withAuthority = (rel, text) => ({ ...disciplineSources, authorityTexts: new Map(authorityTexts).set(rel, text) });
10002
+ for (const [label, tokens] of COMMIT_DISCIPLINE_ELEMENT_GROUPS) {
10003
+ const stripped = strip(elementDocs.get(subRel), tokens[0]);
10004
+ if (stripped === elementDocs.get(subRel)) continue;
10005
+ if (!delegationDisciplineProblems(withElementDoc(subRel, stripped)).some((p) => p.includes(label))) {
10006
+ problems.push('反向构造判别力缺失(' + label + ' 的要点 token 被抽掉未被判缺)');
10007
+ }
10008
+ }
10009
+ for (const phrase of COMMIT_DISCIPLINE_AUTHORITY_PHRASES) {
10010
+ if (!commitDisciplineText.includes(phrase)) continue; // 缺失已由真实判据报告
10011
+ if (!delegationDisciplineProblems(withAuthority(COMMIT_DISCIPLINE_REL, strip(commitDisciplineText, phrase)))
10012
+ .some((p) => p.includes(phrase.slice(0, 40)))) {
10013
+ problems.push('反向构造判别力缺失(抽掉 ' + COMMIT_DISCIPLINE_REL + ' 权威处判别句未被判缺): '
10014
+ + phrase.slice(0, 40) + '…');
10015
+ }
10016
+ if (!delegationDisciplineProblems(withBook(subRel, bookTexts.get(subRel) + '\n' + phrase + '\n'))
10017
+ .some((p) => p.includes('回流了'))) {
10018
+ problems.push('反向构造判别力缺失(权威处正文回流册子未被判违规): ' + phrase.slice(0, 40) + '…');
10019
+ }
10020
+ }
10021
+ for (const phrase of PARALLEL_CONTRACT_BOOK_PHRASES) {
10022
+ if (!bookTexts.get(exRel).includes(phrase)) continue;
10023
+ if (!delegationDisciplineProblems(withBook(exRel, strip(bookTexts.get(exRel), phrase)))
10024
+ .some((p) => p.includes(phrase.slice(0, 40)))) {
10025
+ problems.push('反向构造判别力缺失(抽掉四属性契约判别句未被判缺): ' + phrase.slice(0, 40) + '…');
10026
+ }
10027
+ }
10028
+ for (const pointer of DELEGATION_POINTER_RELS) {
10029
+ const stripped = bookTexts.get(subRel).split(pointer).join('(反向构造:抽掉指针)');
10030
+ if (!delegationDisciplineProblems(withBook(subRel, stripped)).some((p) => p.includes('指针不在场'))) {
10031
+ problems.push('反向构造判别力缺失(抽掉条件句指针未被判违规): ' + pointer);
10032
+ }
10033
+ }
10034
+ for (const phrase of CONTRACT_EVIDENCE_AUTHORITY_PHRASES) {
10035
+ if (!authorityTexts.get(PLATFORM_FACTS_REL).includes(phrase)) continue;
10036
+ if (!delegationDisciplineProblems(withAuthority(PLATFORM_FACTS_REL,
10037
+ strip(authorityTexts.get(PLATFORM_FACTS_REL), phrase))).some((p) => p.includes(phrase.slice(0, 40)))) {
10038
+ problems.push('反向构造判别力缺失(抽掉证据与判级判别句未被判缺): ' + phrase.slice(0, 40) + '…');
8324
10039
  }
8325
- if (!text.includes('不得外推') && !text.includes('不可外推')) {
8326
- problems.push(rel + ' 缺「不得外推 / 不可外推」适用范围限定');
10040
+ if (!delegationDisciplineProblems(withBook(subRel, bookTexts.get(subRel) + '\n' + phrase + '\n'))
10041
+ .some((p) => p.includes('回流了证据与判级判别句'))) {
10042
+ problems.push('反向构造判别力缺失(证据与判级判别句回流册子未被判违规): ' + phrase.slice(0, 40) + '…');
8327
10043
  }
8328
10044
  }
8329
- const worktreeNotes = codexTexts.get('reference/worktree-notes.md');
8330
- for (const keyword of ['fail-open', '未闭合']) {
8331
- if (!worktreeNotes.includes(keyword)) {
8332
- problems.push('reference/worktree-notes.md 缺「' + keyword + '」(Codex/worktree 订正限定)');
10045
+ // 旧表述零残留(原文语义与失败消息保持):无条件 worktree 口号只允许以「已作废」的被反驳
10046
+ // 形态出现;「未获机制明文放行」现状表述一律清零(集成纪律已成文)。配逐条反向构造。
10047
+ const staleResidueProblems = (rel, text) => {
10048
+ const out = [];
10049
+ if (text.split('「一律 worktree」的口号已作废').join('').includes('一律 worktree')) {
10050
+ out.push(rel + ' 残留无条件 worktree 口号(非被反驳形态)');
10051
+ }
10052
+ if (text.includes('未获机制明文放行')) {
10053
+ out.push(rel + ' 残留「未获机制明文放行」现状表述(集成纪律已成文)');
10054
+ }
10055
+ return out;
10056
+ };
10057
+ for (const [rel, text] of bookTexts) {
10058
+ problems.push(...staleResidueProblems(rel, text));
10059
+ const revertedSlogan = text.split('「一律 worktree」的口号已作废').join('一律 worktree 是必须的');
10060
+ if (!staleResidueProblems(rel, revertedSlogan).some((p) => p.includes('无条件 worktree 口号'))) {
10061
+ problems.push(rel + ' 反向构造判别力缺失(还原无条件 worktree 口号未被判违规)');
10062
+ }
10063
+ const revertedStatus = text + '\n未获机制明文放行。\n';
10064
+ if (!staleResidueProblems(rel, revertedStatus).some((p) => p.includes('未获机制明文放行'))) {
10065
+ problems.push(rel + ' 反向构造判别力缺失(还原现状表述未被判违规)');
10066
+ }
10067
+ }
10068
+ // —— ⑦ CC 行判级升格 + 三平台 cwd 语义对照(真机实测落地)——重定向后判据 = 「权威处
10069
+ // 正文在场 + 各引用册指针在场 + **仅两处承载**」:入口册的 7 条字面量是**能力契约锚**(本
10070
+ // 批明文保留),原 `reference/worktree-notes.md` 的 6 条整句随文件移出技能树而改锚到
10071
+ // `reference/platform-facts.md`(T07 逐字搬入);两组文本都不得散进其余册(唯一处 = 入口册
10072
+ // + 平台事实册)。锚一律取**段内独有判别句式**(裸子串会被同文件其它上下文满足而恒真——
10073
+ // `L-106`);cwd 对照表**逐行有锚**(三行各自独立,缺任一行即判残缺);旧「未覆盖」判级句零残留。
10074
+ const entrySkillText = fs.readFileSync(path.join(__dirname, '..', 'SKILL.md'), 'utf8');
10075
+ const platformFactsText = fs.readFileSync(path.join(__dirname, '..', 'reference', 'platform-facts.md'), 'utf8');
10076
+ const otherBooks = new Map([
10077
+ ['flow-comet-subagent-execute/SKILL.md', bookTexts.get('flow-comet-subagent-execute/SKILL.md')],
10078
+ ['flow-comet-execute/SKILL.md', bookTexts.get('flow-comet-execute/SKILL.md')],
10079
+ ]);
10080
+ for (const [, file] of skillTreeDocFiles()) {
10081
+ const rel = path.relative(path.join(__dirname, '..', '..'), file).replaceAll('\\', '/');
10082
+ if (rel === 'flow-comet/SKILL.md' || rel === 'flow-comet/reference/platform-facts.md') continue;
10083
+ if (otherBooks.has(rel)) continue;
10084
+ otherBooks.set(rel, fs.readFileSync(file, 'utf8'));
10085
+ }
10086
+ const upgradeSources = { entry: entrySkillText, facts: platformFactsText, others: otherBooks };
10087
+ problems.push(...identityUpgradeProblems(upgradeSources));
10088
+ // 反向构造(同一判据驱动):① 权威处 / 入口册逐句抽掉 ⇒ 必报该句缺失;② 把整句复制进
10089
+ // 其余任一册 ⇒ 必报「回流」(唯一处的方向——原两处锁**要求**多份,抓不到散播);③ 旧判级
10090
+ // 句还原 ⇒ 必报残留。
10091
+ for (const [side, phrase] of [
10092
+ ...IDENTITY_UPGRADE_ENTRY_PHRASES.map((p) => ['entry', p]),
10093
+ ...IDENTITY_UPGRADE_AUTHORITY_PHRASES.map((p) => ['facts', p]),
10094
+ ]) {
10095
+ const source = side === 'entry' ? entrySkillText : platformFactsText;
10096
+ if (!source.includes(phrase)) continue; // 缺失已由真实判据报告
10097
+ const stripped = identityUpgradeProblems({
10098
+ ...upgradeSources, [side]: source.split(phrase).join('(反向构造:抽掉)'),
10099
+ });
10100
+ if (!stripped.some((p) => p.includes(phrase.slice(0, 40)))) {
10101
+ problems.push('反向构造判别力缺失(抽掉「CC 行升格 / 三平台 cwd 对照」判别句未被判缺): '
10102
+ + phrase.slice(0, 40) + '…');
8333
10103
  }
8334
10104
  }
8335
- if (worktreeNotes.includes('受支持的工作流仍是串行执行')) {
8336
- problems.push('reference/worktree-notes.md 残留「受支持的工作流仍是串行执行」旧独断句');
10105
+ const injectedBookRel = 'flow-comet-subagent-execute/SKILL.md';
10106
+ for (const phrase of [...IDENTITY_UPGRADE_ENTRY_PHRASES, ...IDENTITY_UPGRADE_AUTHORITY_PHRASES]) {
10107
+ const injected = identityUpgradeProblems({
10108
+ ...upgradeSources,
10109
+ others: new Map(otherBooks).set(injectedBookRel, otherBooks.get(injectedBookRel) + '\n' + phrase + '\n'),
10110
+ });
10111
+ if (!injected.some((p) => p.includes('回流'))) {
10112
+ problems.push('反向构造判别力缺失(cwd 对照 / CC 判级句散进其余册未被判违规): ' + phrase.slice(0, 40) + '…');
10113
+ }
10114
+ }
10115
+ for (const stale of IDENTITY_UPGRADE_STALE_PHRASES) {
10116
+ const revertedUpgrade = identityUpgradeProblems({
10117
+ ...upgradeSources,
10118
+ entry: entrySkillText + '\n' + stale + '。\n',
10119
+ facts: platformFactsText + '\n' + stale + '。\n',
10120
+ });
10121
+ if (!revertedUpgrade.some((p) => p.includes('旧「未覆盖」判级表述'))) {
10122
+ problems.push('反向构造判别力缺失(还原旧「未覆盖」判级句未被判残留): ' + stale);
10123
+ }
10124
+ }
10125
+ // —— 文本 ↔ 实现一致锚:文本点名的实现常量 / 载荷键名 / 受保护目标必须与引擎同值 ——
10126
+ const guardSrc = fs.readFileSync(path.join(__dirname, 'comet-hook-guard.mjs'), 'utf8');
10127
+ // 桥接源位于**仓库根** scripts/(分发面脚本,非技能包内)——安装副本形态(目标项目)该面
10128
+ // 结构性缺席:缺席时该侧锚不适用,但必须**显式可见**(未验证 ≠ 通过),不得静默跳过。
10129
+ const bridgePath = path.join(REPO_ROOT, 'scripts', 'dsh-bridge.mjs');
10130
+ const bridgeSrc = fs.existsSync(bridgePath) ? fs.readFileSync(bridgePath, 'utf8') : null;
10131
+ if (bridgeSrc === null) {
10132
+ console.log('SKIP: 184 的桥接侧一致锚(仓库根 scripts/dsh-bridge.mjs 为权威源检出面)'
10133
+ + '——本次未校验「文本点名的身份透传变量与桥接注入处同值」,请在权威源检出重跑本套件');
10134
+ }
10135
+ const stateSchemaSrc = fs.readFileSync(path.join(__dirname, 'state-schema.mjs'), 'utf8');
10136
+ const handoffSrc = fs.readFileSync(path.join(__dirname, 'workflow-handoff.mjs'), 'utf8');
10137
+ // 出口校验(节点门禁)脚本的另一册:在飞委托判据落在 workflow-guard.mjs(hook 守卫只做写入
10138
+ // 拦截,两者同包不同册)——撤回留痕被判据消费这一条须在**该**源上核对。
10139
+ const workflowGuardSrc = fs.readFileSync(path.join(__dirname, 'workflow-guard.mjs'), 'utf8');
10140
+ // 一致性判据(单一实现:真实判据与反向构造探针共用本函数)。
10141
+ const consistencyProblems = ({ guard, bridge, schema, handoff, workflowGuard, books }) => {
10142
+ const out = [];
10143
+ // ① 身份判据的载荷键:文本声称判据 = agent_id;引擎身份判据段必须读取该键。
10144
+ const regionStart = guard.indexOf('function payloadAgentIdentity');
10145
+ const regionEnd = guard.indexOf('const __dirname');
10146
+ if (regionStart < 0 || regionEnd <= regionStart) {
10147
+ out.push('comet-hook-guard.mjs 未找到身份判据段(文本与实现无法对照)');
10148
+ } else {
10149
+ const identityRegion = guard.slice(regionStart, regionEnd);
10150
+ if (!identityRegion.includes('input.agent_id')) {
10151
+ out.push('身份判据段未读取载荷 agent_id(文本声称的判据键与实现不一致)');
10152
+ }
10153
+ // ② agent_type 只是载荷形态描述、不是判据:身份判据段零使用(文本与实现逐字一致)。
10154
+ if (identityRegion.includes('agent_type')) {
10155
+ out.push('身份判据段使用了 agent_type(文本声称判据 = agent_id,二者不一致)');
10156
+ }
10157
+ }
10158
+ // ③ 身份透传的环境变量名单一:守卫读取处与桥接注入处同值(文本两侧同值)。
10159
+ if (!guard.includes('process.env.FLOW_COMET_AGENT_DEPTH')) {
10160
+ out.push('守卫未读取环境变量身份深度(与文本 / 桥接不一致)');
10161
+ }
10162
+ if (bridge === null) {
10163
+ // 结构性缺席(安装副本形态无仓库根 scripts/):该侧锚不适用——可见 SKIP 由场景主体输出,
10164
+ // 此处不判违规也不静默当通过(未验证 ≠ 通过)。
10165
+ } else if (!bridge.includes('FLOW_COMET_AGENT_DEPTH')) {
10166
+ out.push('桥接未透传环境变量身份深度(与文本 / 守卫不一致)');
10167
+ }
10168
+ // ③b 桥接通道标记的名单一与值单一(env 面身份的作用域收紧):守卫读取处、守卫判据常量、
10169
+ // 桥接注入处三处同值;缺任一处即「文本声称需标记自证、实现却直接认深度」的分叉。
10170
+ // 文本侧的判据由两册同锁块承载(见上方 contractLockPhrases 的标记判别句)。
10171
+ if (!guard.includes('process.env.FLOW_COMET_AGENT_DEPTH_SOURCE')) {
10172
+ out.push('守卫未读取桥接通道标记(env 面身份的作用域收紧无实现承载)');
10173
+ }
10174
+ if (!guard.includes("BRIDGE_DEPTH_CHANNEL_MARKER = 'dsh-bridge'")) {
10175
+ out.push('守卫缺桥接通道标记的判据常量(标记值无单一来源)');
10176
+ }
10177
+ if (bridge === null) {
10178
+ // 同上:安装副本形态无仓库根 scripts/,该侧锚不适用。
10179
+ } else if (!/FLOW_COMET_AGENT_DEPTH_SOURCE:\s*'dsh-bridge'/.test(bridge)) {
10180
+ out.push('桥接未注入桥接通道标记 ' + "'dsh-bridge'" + '(守卫要求标记在场,桥接不注入即通道失效)');
10181
+ }
10182
+ // ③c 撤回留痕的字段名与判据落点:文本点名的两个字段由单一实现判定,且守卫的在飞判据
10183
+ // 必须消费该实现(缺一即「文本说撤回可放行、实现仍按在飞拦」)。
10184
+ if (!schema.includes('withdrawnAt') || !schema.includes('withdrawnBy')) {
10185
+ out.push('撤回留痕字段名未落在单一判据实现(与文本声称的 withdrawnAt / withdrawnBy 不一致)');
10186
+ }
10187
+ if (!/handoffRequestWithdrawn\(requests\[taskId\]\)/.test(workflowGuard)) {
10188
+ out.push('在飞委托判据未消费撤回留痕判据(撤回的 request 仍会被计为在飞)');
10189
+ }
10190
+ // ④ 最小保护集的两个目标:实现侧取值来源(状态文件路径常量 + 协议解析结果)与文本字面同值。
10191
+ if (!schema.includes("RUNTIME_DIR = '.flow-comet'")
10192
+ || !schema.includes("RUNTIME_STATE_FILE_NAME = 'flow-comet-state.json'")) {
10193
+ out.push('状态文件路径常量与文本声称的受保护目标不一致');
10194
+ }
10195
+ if (!guard.includes('blockedStateFileTarget') || !guard.includes('blockedProtocolFileTarget')) {
10196
+ out.push('守卫缺最小保护集判定入口(文本声称的两个受保护目标无实现承载)');
10197
+ }
10198
+ // ⑤ 留痕字段与落点:文本点名的既有字段 = 实现写入的嵌套键(零新增 state 顶层字段)。
10199
+ if (!handoff.includes("state.evidence['subagent-execute'].handoffRequests")) {
10200
+ out.push('留痕未落在嵌套证据(与文本声称的同族嵌套形态不一致)');
10201
+ }
10202
+ // ⑥ 零提交资格字段与落库形态:文本声称「提交隔离走既有 noCommit 资格」——实现必须在
10203
+ // request 侧真实记录该字段(文本说 A、实现说 B 即红)。
10204
+ if (!handoff.includes('noCommit: true')) {
10205
+ out.push('零提交资格落库形态与文本声称的 request 记录不一致(缺 noCommit: true)');
10206
+ }
10207
+ for (const [rel, text] of books) {
10208
+ if (!text.includes('.flow-comet/flow-comet-state.json')) {
10209
+ out.push(rel + ' 缺最小保护集目标字面(机器状态文件)');
10210
+ }
10211
+ if (!text.includes('reference/workflow-protocol.json')) {
10212
+ out.push(rel + ' 缺最小保护集目标字面(协议保护路径)');
10213
+ }
10214
+ if (!text.includes('handoffRequests') || !text.includes('handoffResult')) {
10215
+ out.push(rel + ' 缺留痕字段名(handoffRequests / handoffResult)');
10216
+ }
10217
+ if (!text.includes('noCommit')) {
10218
+ out.push(rel + ' 缺零提交资格字段名(noCommit)');
10219
+ }
10220
+ // 桥接通道标记名(env 面身份的作用域收紧):两册文本须点名标记本身——只说「env 透传
10221
+ // 深度」会让读者以为继承来的深度变量也能当身份用(正是收紧前的缺口表述)。
10222
+ if (!text.includes('FLOW_COMET_AGENT_DEPTH_SOURCE')) {
10223
+ out.push(rel + ' 缺桥接通道标记名(文本声称 env 面身份需标记自证,却未点名标记)');
10224
+ }
10225
+ }
10226
+ return out;
10227
+ };
10228
+ const consistencySources = { guard: guardSrc, bridge: bridgeSrc, schema: stateSchemaSrc, handoff: handoffSrc, workflowGuard: workflowGuardSrc, books: bookTexts };
10229
+ problems.push(...consistencyProblems(consistencySources));
10230
+ // 反向构造(同一判据驱动):逐项把实现侧常量改成与文本不同的值 ⇒ 必报(文本说 A、实现说 B 即红)。
10231
+ const consistencyProbes = [
10232
+ ['载荷键改名', { guard: guardSrc.replace('input.agent_id', 'input.agentId') }, 'agent_id'],
10233
+ ['agent_type 混入判据段', {
10234
+ guard: guardSrc.replace('function payloadAgentIdentity',
10235
+ "function payloadAgentIdentity(input) { const probe = input.agent_type;\n"),
10236
+ }, 'agent_type'],
10237
+ ['环境变量改名', { guard: guardSrc.replaceAll('FLOW_COMET_AGENT_DEPTH', 'FLOW_COMET_DEPTH') }, '环境变量身份深度'],
10238
+ // 桥接通道标记(env 面身份的作用域收紧)与撤回通道:逐项抽掉实现侧或文本侧的承载 ⇒ 必报。
10239
+ ['桥接标记读取抽掉', { guard: guardSrc.replaceAll('process.env.FLOW_COMET_AGENT_DEPTH_SOURCE', 'process.env.FLOW_COMET_DEPTH_SOURCE') }, '桥接通道标记'],
10240
+ ['桥接标记判据常量改名', { guard: guardSrc.replace("BRIDGE_DEPTH_CHANNEL_MARKER = 'dsh-bridge'", "BRIDGE_DEPTH_CHANNEL_MARKER = 'bridge'") }, '标记值无单一来源'],
10241
+ // 桥接源在安装副本形态结构性缺席(见上方 SKIP 行):该探针不构造——未验证 ≠ 通过,
10242
+ // 由 SKIP 行显式声明;不构造也不得让整块判据崩掉(缺席面不得变成套件错误)。
10243
+ ...(bridgeSrc === null ? [] : [['桥接注入标记值漂移', { bridge: bridgeSrc.replaceAll("FLOW_COMET_AGENT_DEPTH_SOURCE: 'dsh-bridge'", "FLOW_COMET_AGENT_DEPTH_SOURCE: 'other'") }, '桥接未注入桥接通道标记']]),
10244
+ ['撤回留痕字段改名', { schema: stateSchemaSrc.replaceAll('withdrawnBy', 'cancelledBy') }, '撤回留痕字段名未落在单一判据实现'],
10245
+ ['在飞判据不消费撤回留痕', { workflowGuard: workflowGuardSrc.replace('handoffRequestWithdrawn(requests[taskId])', 'false') }, '在飞委托判据未消费撤回留痕判据'],
10246
+ ['文本侧桥接标记名缺失', { books: new Map([...bookTexts].map(([rel, text]) => [rel, text.split('FLOW_COMET_AGENT_DEPTH_SOURCE').join('(反向构造:抽掉)')])) }, '桥接通道标记名'],
10247
+ ['状态文件路径常量改名', { schema: stateSchemaSrc.replace("RUNTIME_STATE_FILE_NAME = 'flow-comet-state.json'", "RUNTIME_STATE_FILE_NAME = 'state.json'") }, '状态文件路径常量'],
10248
+ ['留痕落点改顶层', { handoff: handoffSrc.replaceAll("state.evidence['subagent-execute'].handoffRequests", 'state.handoffRequests') }, '留痕未落在嵌套证据'],
10249
+ ['零提交落库形态改名', { handoff: handoffSrc.replaceAll('noCommit: true', 'zeroCommitFlag: true') }, '零提交资格落库形态'],
10250
+ ['文本侧目标字面缺失', { books: new Map([...bookTexts].map(([rel, text]) => [rel, text.split('.flow-comet/flow-comet-state.json').join('(反向构造:抽掉)')])) }, '机器状态文件'],
10251
+ ['文本侧零提交字段缺失', { books: new Map([...bookTexts].map(([rel, text]) => [rel, text.split('noCommit').join('(反向构造:抽掉)')])) }, '零提交资格字段名'],
10252
+ ];
10253
+ for (const [probeLabel, override, expected] of consistencyProbes) {
10254
+ const probed = { ...consistencySources, ...override };
10255
+ if (!consistencyProblems(probed).some((p) => p.includes(expected))) {
10256
+ problems.push('反向构造判别力缺失(' + probeLabel + ' 未被判不一致)');
10257
+ }
10258
+ }
10259
+ }
10260
+ // —— 7 字段集合的文本 ↔ 实现一致锚(文本不得说谎的**根治**面:任一处枚举分叉即红)——
10261
+ // 判据与反向构造探针见模块级 `task7SetAnchorProblems`(单一实现):唯一权威 = `workflow-guard.mjs`
10262
+ // 的 `TASK7_REQUIRED` 常量(plan 出口判据的集合来源),技能树侧枚举**从该常量派生**后逐处对账——
10263
+ // 锚里不写第二份集合(第二份同口径表达会在判据演进时分叉,`LESSONS` L-067);覆盖双语形态与斜杠
10264
+ // 枚举形态,同批固化「文案落后于判据」静默面(两处 BLOCKED 文案从判据常量派生)。反向构造(L-106):
10265
+ // 任一处枚举改字段名(depends_on → id)/ 抽掉整处枚举 / 常量侧改名 / 文案回写字面集合 ⇒ 必红。
10266
+ problems.push(...task7SetAnchorProblems({
10267
+ guardSrc: fs.readFileSync(path.join(__dirname, 'workflow-guard.mjs'), 'utf8'),
10268
+ stateSrc: fs.readFileSync(path.join(__dirname, 'workflow-state.mjs'), 'utf8'),
10269
+ docs: new Map(skillTreeDocFiles().map(([rel, file]) => [rel, fs.readFileSync(file, 'utf8')])),
10270
+ }));
10271
+ // —— 公开面口径机检(文档不说假话):公开机制册的判级须与技能册一致、公开变更日志的新增
10272
+ // 条目须带**编号** PR 链接、技能册的已关闭缺口与建树适用面须写成本文。三面各自可判,
10273
+ // 并配反向构造(抽掉新表述 / 还原旧表述 ⇒ 必报)。公开面在安装副本形态结构性缺席:
10274
+ // 缺席时输出可见 SKIP(未验证 ≠ 通过),不得静默当通过。
10275
+ {
10276
+ const publicDocRelPaths = ['docs/MECHANISM.md', 'docs/MECHANISM-zh.md', 'CHANGELOG.md', 'CHANGELOG-zh.md'];
10277
+ const publicDocs = new Map(publicDocRelPaths.map((rel) => {
10278
+ const abs = path.join(REPO_ROOT, rel);
10279
+ return [rel, fs.existsSync(abs) ? fs.readFileSync(abs, 'utf8') : null];
10280
+ }));
10281
+ const missingDocFaces = [...publicDocs].filter(([, text]) => text === null).map(([rel]) => rel);
10282
+ if (missingDocFaces.length > 0) {
10283
+ console.log('SKIP: 184 的公开面口径锚(' + missingDocFaces.join(', ') + ')——本次检出无该公开文档面,'
10284
+ + '未校验「公开机制册判级与技能册一致 / 变更日志新增条目链接带编号 / 建树适用面成文」,请在权威源检出重跑本套件');
10285
+ }
10286
+ const subagentFaceText = fs.readFileSync(
10287
+ path.join(__dirname, '..', '..', 'flow-comet-subagent-execute', 'SKILL.md'), 'utf8');
10288
+ const entryFaceText = fs.readFileSync(path.join(__dirname, '..', 'SKILL.md'), 'utf8');
10289
+ // 第三面随 `worktree-notes.md` 移出技能树改读 `reference/platform-facts.md`(判别句新落点)。
10290
+ const factsFaceText = fs.readFileSync(path.join(__dirname, '..', 'reference', 'platform-facts.md'), 'utf8');
10291
+ const treeScopeSentence = '**建树选择的适用面**';
10292
+ const treeBypassSentence = '**以建树绕过边界**不受支持';
10293
+ const staleTreeBan = '手工 `git worktree add <任意路径>` **不是受支持路径**';
10294
+ const gapClosureSentence = '该缺口现已被守卫关闭';
10295
+ // 公开变更日志的段切片(止于下一个版本标题)。
10296
+ const sectionAt = (text, start) => {
10297
+ const next = text.indexOf('\n## [', start + 1);
10298
+ return text.slice(start, next < 0 ? text.length : next);
10299
+ };
10300
+ const unreleasedSectionOf = (text) => {
10301
+ const start = text.indexOf('## [Unreleased]');
10302
+ return start < 0 ? null : sectionAt(text, start);
10303
+ };
10304
+ // 「最新条目段」(判据与反向构造共用同一切片,单一实现):dev 态新增条目在 `## [Unreleased]`;
10305
+ // 发布结算把条目移入最新版本段、Unreleased 只留空标题——这是仓库既有发布形态(`v1.6.2` tag 即
10306
+ // 「空 Unreleased + 版本段」,`v1.6.1` tag 甚至无 Unreleased 段)。只切 Unreleased 段的实现
10307
+ // 在发布态必然失配,故:Unreleased 段有条目则取之,否则回退到最新版本段。
10308
+ const newestEntriesSectionOf = (text) => {
10309
+ const unreleased = unreleasedSectionOf(text);
10310
+ if (unreleased !== null && /^- /m.test(unreleased)) return unreleased;
10311
+ const versioned = text.search(/^## \[\d+\.\d+\.\d+/m);
10312
+ if (versioned >= 0) return sectionAt(text, versioned);
10313
+ return unreleased;
10314
+ };
10315
+ // 一致性判据(单一实现:真实判据与反向构造探针共用本函数)。
10316
+ const publicFaceProblems = ({ mechanism, mechanismZh, changelog, changelogZh, subagentBook, entryBook, factsBook }) => {
10317
+ const out = [];
10318
+ // 公开机制册双语判级:CC 行「证实 + 限定形态」,未覆盖项照旧标注,旧判级句零残留。
10319
+ const gradeCases = [
10320
+ ['docs/MECHANISM.md', mechanism,
10321
+ 'payload `agent_id` / `agent_type` — **verified**, in a stated shape only',
10322
+ ['`agent_type`', 'nested delegations', 'non-Windows environments', 'remain uncovered'],
10323
+ 'payload `agent_id` — **not yet covered**'],
10324
+ ['docs/MECHANISM-zh.md', mechanismZh,
10325
+ '载荷 `agent_id` / `agent_type`——**证实**,且**限定形态**',
10326
+ ['`agent_type` 取值域', '嵌套委派载荷', '非 Windows 环境', '仍未覆盖'],
10327
+ '载荷 `agent_id`——真机会话**尚未覆盖**'],
10328
+ ];
10329
+ for (const [rel, text, phrase, keep, stale] of gradeCases) {
10330
+ if (text === null) continue;
10331
+ if (!text.includes(phrase)) out.push(rel + ' 未把 CC 身份通道标为证实(缺判别句:' + phrase.slice(0, 30) + '…)');
10332
+ for (const item of keep) {
10333
+ if (!text.includes(item)) out.push(rel + ' 判级升格时丢了限定形态 / 未覆盖项(缺「' + item + '」)');
10334
+ }
10335
+ if (text.includes(stale)) out.push(rel + ' 残留旧判级表述「' + stale + '」');
10336
+ }
10337
+ // 公开变更日志:最新条目段的条目数与**条目行内**带编号 PR 链接数一致,且不得有空链接。
10338
+ // 计数面限定在条目行——版本段的摘要行另按惯例携带 PR 链接,段级计数会把摘要行读成条目失配。
10339
+ for (const [rel, text] of [['CHANGELOG.md', changelog], ['CHANGELOG-zh.md', changelogZh]]) {
10340
+ if (text === null) continue;
10341
+ const section = newestEntriesSectionOf(text);
10342
+ if (section === null) { out.push(rel + ' 缺 Unreleased 段与版本段(新增条目无处登记)'); continue; }
10343
+ const entryLines = section.split('\n').filter((line) => line.startsWith('- '));
10344
+ const entries = entryLines.length;
10345
+ const numbered = entryLines.reduce((n, line) => n + (line.match(/\/pull\/\d+/g) ?? []).length, 0);
10346
+ const bare = entryLines.reduce((n, line) => n + (line.match(/\/pull\/\)/g) ?? []).length, 0);
10347
+ if (bare > 0) out.push(rel + ' 新增条目含空 PR 链接(pull/ 无编号)×' + bare);
10348
+ if (entries > 0 && numbered !== entries) {
10349
+ out.push(rel + ' 新增条目与带编号 PR 链接数不一致(条目 ' + entries + ' / 链接 ' + numbered + ')');
10350
+ }
10351
+ }
10352
+ // 已关闭缺口:**权威处**(`reference/platform-facts.md`)的陈旧注释须以「已关闭 + 当前判据」
10353
+ // 形态在场(边界陈述保留);两册**不得**再持该证据段正文(随平台事实移走——回流即红)。
10354
+ const gapCases = [
10355
+ [PLATFORM_FACTS_REL, factsBook, ['**fail-open**', '**未闭合**', '补丁体按行语义解析出']],
10356
+ ];
10357
+ for (const [rel, text, keep] of gapCases) {
10358
+ if (text === null) continue;
10359
+ if (!text.includes(gapClosureSentence)) {
10360
+ out.push(rel + ' 未把已关闭的守卫缺口写成本文(缺「' + gapClosureSentence + '」——陈旧注释仍在描述现状)');
10361
+ }
10362
+ for (const item of keep) {
10363
+ if (!text.includes(item)) out.push(rel + ' 已关闭缺口的当前判据 / 边界陈述缺失(缺「' + item + '」)');
10364
+ }
10365
+ }
10366
+ for (const [rel, text] of [['flow-comet-subagent-execute/SKILL.md', subagentBook]]) {
10367
+ if (text === null) continue;
10368
+ if (text.includes(gapClosureSentence)) {
10369
+ out.push(rel + ' 回流了已关闭缺口的证据段正文(缺「' + gapClosureSentence + '」段的权威处唯一)');
10370
+ }
10371
+ }
10372
+ // 建树适用面:三处同写「显式建树受支持 / 以建树绕过边界不受支持」(能力契约锚,ADR-016 保留),
10373
+ // 旧一刀切禁令零残留。
10374
+ for (const [rel, text] of [
10375
+ ['flow-comet/SKILL.md', entryBook],
10376
+ ['flow-comet-subagent-execute/SKILL.md', subagentBook],
10377
+ [PLATFORM_FACTS_REL, factsBook],
10378
+ ]) {
10379
+ if (text === null) continue;
10380
+ if (!text.includes(treeScopeSentence)) out.push(rel + ' 未写清建树适用面(缺「' + treeScopeSentence + '」)');
10381
+ if (!text.includes(treeBypassSentence)) out.push(rel + ' 未写清绕过面边界(缺「' + treeBypassSentence + '」)');
10382
+ if (text.includes(staleTreeBan)) {
10383
+ out.push(rel + ' 残留一刀切禁令「' + staleTreeBan + '…」(与入口册平台通道表口径相反)');
10384
+ }
10385
+ }
10386
+ return out;
10387
+ };
10388
+ // 面缺席(安装副本形态)时的 null 安全改写:缺席面既无真实判据也无反向构造,
10389
+ // 由上方 SKIP 行显式声明未验证;探针循环再跳过含缺席面的探针(不静默当通过)。
10390
+ const patchText = (text, from, to) => (text === null ? null : text.split(from).join(to));
10391
+ const publicFaceSources = {
10392
+ mechanism: publicDocs.get('docs/MECHANISM.md'),
10393
+ mechanismZh: publicDocs.get('docs/MECHANISM-zh.md'),
10394
+ changelog: publicDocs.get('CHANGELOG.md'),
10395
+ changelogZh: publicDocs.get('CHANGELOG-zh.md'),
10396
+ subagentBook: subagentFaceText,
10397
+ entryBook: entryFaceText,
10398
+ factsBook: factsFaceText,
10399
+ };
10400
+ problems.push(...publicFaceProblems(publicFaceSources));
10401
+ // 反向构造(同一判据驱动):逐项抽掉新表述 / 还原旧表述 ⇒ 必报该问题。
10402
+ const publicFaceProbes = [
10403
+ ['公开册判级回退', {
10404
+ mechanism: patchText(publicFaceSources.mechanism, 'payload `agent_id` / `agent_type` — **verified**, in a stated shape only', 'payload `agent_id` — **not yet covered** in a real session, in a stated shape only'),
10405
+ mechanismZh: patchText(publicFaceSources.mechanismZh, '载荷 `agent_id` / `agent_type`——**证实**,且**限定形态**', '载荷 `agent_id`——真机会话**尚未覆盖**,且**限定形态**'),
10406
+ }, '残留旧判级表述'],
10407
+ ['公开册限定形态抽掉', {
10408
+ mechanism: patchText(publicFaceSources.mechanism, 'nested delegations', 'REMOVED'),
10409
+ mechanismZh: patchText(publicFaceSources.mechanismZh, '嵌套委派载荷', 'REMOVED'),
10410
+ }, '丢了限定形态'],
10411
+ ['已关闭缺口注解抽掉', {
10412
+ factsBook: publicFaceSources.factsBook.split(gapClosureSentence).join('REMOVED'),
10413
+ }, '未把已关闭的守卫缺口写成本文'],
10414
+ ['已关闭缺口证据回流册子', {
10415
+ subagentBook: publicFaceSources.subagentBook + '\n' + gapClosureSentence + ':补丁体按行语义解析出。\n',
10416
+ }, '回流了已关闭缺口的证据段正文'],
10417
+ ['建树适用面句抽掉', {
10418
+ entryBook: publicFaceSources.entryBook.split(treeScopeSentence).join('REMOVED'),
10419
+ subagentBook: publicFaceSources.subagentBook.split(treeScopeSentence).join('REMOVED'),
10420
+ factsBook: publicFaceSources.factsBook.split(treeScopeSentence).join('REMOVED'),
10421
+ }, '未写清建树适用面'],
10422
+ ['旧一刀切禁令还原', {
10423
+ subagentBook: publicFaceSources.subagentBook + '\n' + staleTreeBan + ',不得作为绕过手段。\n',
10424
+ }, '残留一刀切禁令'],
10425
+ ];
10426
+ // 链接编号反向构造(**两面各自取目标、各自断言**):目标数据驱动——取「最新条目段」条目行内第一处
10427
+ // `/pull/<编号>`,两面各按自己的取值抽掉编号,两面都须报出空链接。写死批次编号的实现会在结算把
10428
+ // 条目移入版本段后恒不命中(判别力静默归零),批次更替后同样过期;只取英文侧编号的实现会让中文侧
10429
+ // 的判据在编号分叉或回归时不被覆盖。
10430
+ // 公开面缺席(安装副本形态)时不做该探针——上方 SKIP 行已显式声明未验证,不在此另报。
10431
+ const newestEntryLinkOf = (text) => ((newestEntriesSectionOf(text) ?? '')
10432
+ .split('\n').filter((line) => line.startsWith('- ')).join('\n')
10433
+ .match(/\/pull\/\d+/) ?? [null])[0];
10434
+ const changelogFacesPresent = publicFaceSources.changelog !== null && publicFaceSources.changelogZh !== null;
10435
+ if (changelogFacesPresent) {
10436
+ const linkEn = newestEntryLinkOf(publicFaceSources.changelog);
10437
+ const linkZh = newestEntryLinkOf(publicFaceSources.changelogZh);
10438
+ if (linkEn === null || linkZh === null) {
10439
+ problems.push('公开面口径反向构造目标缺失:最新条目段内无带编号 PR 链接(无从反证,不表示为通过)');
10440
+ } else {
10441
+ const strippedProblems = publicFaceProblems({
10442
+ ...publicFaceSources,
10443
+ changelog: patchText(publicFaceSources.changelog, linkEn, '/pull/'),
10444
+ changelogZh: patchText(publicFaceSources.changelogZh, linkZh, '/pull/'),
10445
+ });
10446
+ for (const rel of ['CHANGELOG.md', 'CHANGELOG-zh.md']) {
10447
+ if (!strippedProblems.some((problem) => problem.startsWith(rel + ' 新增条目含空 PR 链接'))) {
10448
+ problems.push('公开面口径反向构造判别力缺失(变更日志链接编号抽掉:' + rel + ' 未被判违规)');
10449
+ }
10450
+ }
10451
+ }
8337
10452
  }
8338
- if (worktreeNotes.includes('写入仍会被协调者白名单拦截')) {
8339
- problems.push('reference/worktree-notes.md 残留「写入仍会被协调者白名单拦截」旧过宽句');
10453
+ for (const [probeLabel, override, expected] of publicFaceProbes) {
10454
+ const probed = { ...publicFaceSources, ...override };
10455
+ // 含缺席面的探针不执行(该面既无真实判据也无反向构造)——上方 SKIP 行已显式声明未验证。
10456
+ if (Object.values(probed).some((value) => value === null)) continue;
10457
+ if (!publicFaceProblems(probed).some((problem) => problem.includes(expected))) {
10458
+ problems.push('公开面口径反向构造判别力缺失(' + probeLabel + ' 未被判违规)');
10459
+ }
8340
10460
  }
8341
- if (codexTexts.get('flow-comet-subagent-execute/SKILL.md').includes('写入会被协调者白名单拦截')) {
8342
- problems.push('flow-comet-subagent-execute/SKILL.md 残留「写入会被协调者白名单拦截」旧过宽句');
10461
+ // 发布结算形态锚(本判据在发布态失配的回归锚):把 dev 态变更日志改写成发布结算后的形态——
10462
+ // Unreleased 只留空标题、条目连同条目行内的 PR 链接落在最新版本段——判据须零问题,且链接编号
10463
+ // 反向构造在此形态下仍必报(只切 Unreleased 段 + 写死批次编号的实现在此形态下必红)。
10464
+ {
10465
+ const settled = (text) => {
10466
+ if (text === null) return null;
10467
+ const section = unreleasedSectionOf(text);
10468
+ if (section === null) return null;
10469
+ // 树本身已是发布态(Unreleased 无条目)时无从构造该转换:此时真实判据与数据驱动探针
10470
+ // 已直接覆盖发布态,本锚跳过(不静默当通过——覆盖由上方真实判据承担)。
10471
+ if (!/^- /m.test(section)) return null;
10472
+ const headingStart = text.indexOf('## [Unreleased]');
10473
+ const nextVersion = text.indexOf('\n## [', headingStart + 1);
10474
+ if (nextVersion < 0) return null;
10475
+ const body = section.slice(section.indexOf('\n') + 1).replace(/^\n+/, '');
10476
+ // 前缀止于 Unreleased 标题行末——条目**只**出现在合成的版本段下(前缀若带到条目,判据仍会
10477
+ // 选中 Unreleased 段,本锚就变成空转的恒真锚)。
10478
+ return text.slice(0, headingStart + '## [Unreleased]'.length)
10479
+ + '\n\n## [9.9.9] - 2099-01-01\n\nA release gathering the settled work.\n\n' + body
10480
+ + text.slice(nextVersion);
10481
+ };
10482
+ const settledSources = {
10483
+ ...publicFaceSources,
10484
+ changelog: settled(publicFaceSources.changelog),
10485
+ changelogZh: settled(publicFaceSources.changelogZh),
10486
+ };
10487
+ if (Object.values(settledSources).every((value) => value !== null)) {
10488
+ // 构造自证:合成后 Unreleased 段须为空、最新条目段须是合成的版本段——否则本锚没有真正构造
10489
+ // 出发布形态(静默空转),直接判红。
10490
+ for (const [rel, text] of [['CHANGELOG.md', settledSources.changelog], ['CHANGELOG-zh.md', settledSources.changelogZh]]) {
10491
+ if (/^- /m.test(unreleasedSectionOf(text) ?? '')) {
10492
+ problems.push('发布结算形态锚构造失效(' + rel + '):合成后 Unreleased 段仍带条目,未真正构造发布形态');
10493
+ }
10494
+ if (!/^## \[9\.9\.9\]/m.test(newestEntriesSectionOf(text) ?? '')) {
10495
+ problems.push('发布结算形态锚构造失效(' + rel + '):最新条目段未回退到合成的版本段');
10496
+ }
10497
+ }
10498
+ const settledProblems = publicFaceProblems(settledSources);
10499
+ if (settledProblems.length > 0) {
10500
+ problems.push('发布结算形态(Unreleased 空标题 + 条目在最新版本段)下判据误报: ' + settledProblems.join('; '));
10501
+ }
10502
+ const settledLinkEn = newestEntryLinkOf(settledSources.changelog);
10503
+ const settledLinkZh = newestEntryLinkOf(settledSources.changelogZh);
10504
+ if (settledLinkEn === null || settledLinkZh === null) {
10505
+ problems.push('发布结算形态下链接编号反向构造目标缺失:最新条目段内无带编号 PR 链接');
10506
+ } else {
10507
+ const reversedProblems = publicFaceProblems({
10508
+ ...settledSources,
10509
+ changelog: patchText(settledSources.changelog, settledLinkEn, '/pull/'),
10510
+ changelogZh: patchText(settledSources.changelogZh, settledLinkZh, '/pull/'),
10511
+ });
10512
+ for (const rel of ['CHANGELOG.md', 'CHANGELOG-zh.md']) {
10513
+ if (!reversedProblems.some((problem) => problem.startsWith(rel + ' 新增条目含空 PR 链接'))) {
10514
+ problems.push('发布结算形态下链接编号反向构造判别力缺失(抽掉条目行内编号:' + rel + ' 未被判违规)');
10515
+ }
10516
+ }
10517
+ }
10518
+ }
8343
10519
  }
8344
10520
  }
8345
10521
  if (problems.length > 0) throw new Error('技能文本混排合法化语义不符: ' + problems.join('; '));
@@ -8923,8 +11099,11 @@ const SCENARIOS = [
8923
11099
  // 「补显式 depends_on 或拆串行」)。修复前 plan 出口无此检测 = 预期 RED(重叠静默放行)。
8924
11100
  // 引号形态:P02 用单引号属性(XML 合法形态)——属性不解析会让 P02 退化为非并行 → 重叠漏判
8925
11101
  // (本场景退出码/消息断言即 RED),与 TASK_VALID_PS 的路由断言构成两条下游消费路径的覆盖。
11102
+ // in-place 扩展(glob 形态盲区闭合):单侧含元字符 ⇒ 用该侧模式匹配另一侧字面路径(段内 `*`
11103
+ // 不跨 `/`);段数不等 / 段内不匹配 ⇒ 不重叠放行;双侧 glob ⇒ 保守判重叠;补依赖路径 ⇒ 放行
11104
+ // (判据不恒真空过)。反向构造:把重叠判定回退成逐字相等 ⇒ ③/③d 必红。
8926
11105
  {
8927
- name: '202 plan exit BLOCKED:新 change 写写重叠(链式重命名 .txt 事故面)',
11106
+ name: '202 plan exit 写写重叠:字面/glob 单侧与双侧/段内不跨斜杠/补依赖路径(含恢复)',
8928
11107
  run: (dir) => {
8929
11108
  const st = baseState('plan');
8930
11109
  st.evidence.plan = { summary: 'plan done' };
@@ -8939,6 +11118,52 @@ const SCENARIOS = [
8939
11118
  assertOut(res, 'P01×P02');
8940
11119
  assertOut(res, 'bak_a.txt');
8941
11120
  assertOut(res, 'depends_on');
11121
+
11122
+ // ③ glob 形态重叠(单侧元字符 × 字面路径):修复前逐字相等判定漏检 ⇒ 静默放行
11123
+ const globTasks = (firstWrite, secondWrite, secondDeps = '') =>
11124
+ '<task id="G01" parallel="true" status="pending"><action>实现 G01</action><write_files>' + firstWrite + '</write_files><verify>node --check src/x.mjs</verify></task>\n' +
11125
+ '<task id="G02" parallel="true" status="pending"><action>实现 G02</action><write_files>' + secondWrite + '</write_files><verify>node --check src/x.mjs</verify>' + secondDeps + '</task>\n';
11126
+ const globOverlap = runPlanExit(dir, globTasks('src/*.mjs', 'src/foo.mjs'));
11127
+ assertExit(globOverlap, 1);
11128
+ assertOut(globOverlap, 'BLOCKED');
11129
+ assertOut(globOverlap, 'G01×G02');
11130
+ assertOut(globOverlap, 'src/*.mjs');
11131
+ assertOut(globOverlap, 'src/foo.mjs');
11132
+ assertOut(globOverlap, 'depends_on');
11133
+ // ③b 段内 `*` 不跨 `/`:段数不等 ⇒ 不重叠 ⇒ 放行
11134
+ const depthMismatch = runPlanExit(dir, globTasks('src/*.mjs', 'src/deep/foo.mjs'));
11135
+ assertExit(depthMismatch, 0);
11136
+ assertNotOut(depthMismatch, 'BLOCKED');
11137
+ // ③c 段内模式不匹配(扩展名不符)⇒ 不重叠 ⇒ 放行
11138
+ const suffixMismatch = runPlanExit(dir, globTasks('src/*.mjs', 'src/foo.js'));
11139
+ assertExit(suffixMismatch, 0);
11140
+ assertNotOut(suffixMismatch, 'BLOCKED');
11141
+ // ③d 双侧 glob ⇒ 保守视为重叠(宁可误拦不可漏检——漏检正是本判据要修的缺陷)
11142
+ const doubleGlob = runPlanExit(dir, globTasks('src/*.mjs', 'src/*.js'));
11143
+ assertExit(doubleGlob, 1);
11144
+ assertOut(doubleGlob, 'BLOCKED');
11145
+ assertOut(doubleGlob, 'G01×G02');
11146
+ assertOut(doubleGlob, '∩');
11147
+ // ③e 恢复路径一:补显式 depends_on(重叠路径不改,不是靠改路径避开重叠)⇒ 放行
11148
+ const directDep = runPlanExit(dir, globTasks('src/*.mjs', 'src/foo.mjs', '<depends_on>G01</depends_on>'));
11149
+ assertExit(directDep, 0);
11150
+ assertNotOut(directDep, 'BLOCKED');
11151
+ // ③f 恢复路径二:经中间任务补依赖路径(G02 → M01 → G01)⇒ 依赖拓扑下不再同趟 ⇒ 放行
11152
+ const transitiveDep = runPlanExit(dir,
11153
+ '<task id="G01" parallel="true" status="pending"><action>实现 G01</action><write_files>src/*.mjs</write_files><verify>node --check src/x.mjs</verify></task>\n' +
11154
+ '<task id="M01" status="pending"><action>实现 M01</action><write_files>src/mid.mjs</write_files><verify>node --check src/mid.mjs</verify><depends_on>G01</depends_on></task>\n' +
11155
+ '<task id="G02" parallel="true" status="pending"><action>实现 G02</action><write_files>src/foo.mjs</write_files><verify>node --check src/x.mjs</verify><depends_on>M01</depends_on></task>\n');
11156
+ assertExit(transitiveDep, 0);
11157
+ assertNotOut(transitiveDep, 'BLOCKED');
11158
+
11159
+ // ③g 等价性锚(in-place 扩展):段内 glob 语义的两处实现——route-node 的计划期重叠判定
11160
+ // (collectPathOverlaps)与 workflow-handoff 的提交子集校验(matchWriteFilePattern)
11161
+ // ——对同一 (声明, 字面) 矩阵必须同判。两侧各测一侧不叫等价:此锚同一矩阵两侧求值。
11162
+ // 反向构造内建:矩阵里每一格都先断「两侧同判」,任一侧语义漂移即红(判别力由同一判据驱动)。
11163
+ const globProblems = globEquivalenceProblems(dir);
11164
+ if (globProblems.length > 0) {
11165
+ throw new Error('段内 glob 语义两处实现等价性锚失败: ' + globProblems.join('; '));
11166
+ }
8942
11167
  },
8943
11168
  },
8944
11169
 
@@ -10004,7 +12229,7 @@ const SCENARIOS = [
10004
12229
  // ④ 追加(物理包含性):隔离区**内**指向区外的符号链接/junction 是同一前缀下的第二种逃逸——
10005
12230
  // 词法归一化对它无能为力(路径字符串确实以隔离区前缀开头),必须按真实落点判定。
10006
12231
  {
10007
- name: '232 hook worktree 放行:Bash 与 file_path 判定一致,穿越形态与区外链接落点仍拦',
12232
+ name: '232 hook 判定一致性:worktree 放行双分支一致 + 穿越仍拦 + 身份三态 × 桥接标记在场判据 × 最小保护集 + runRoot 外对称',
10008
12233
  run: (dir) => {
10009
12234
  writeState(dir, { ...baseState('subagent-execute'), status: 'running' });
10010
12235
  const insideWorktree = path.join(dir, '.claude', 'worktrees', 'agent-abc123', 'src', 'x.mjs');
@@ -10069,6 +12294,274 @@ const SCENARIOS = [
10069
12294
  { tool_name: 'Write', tool_input: { file_path: path.join(dir, 'src', 'evil.mjs') } });
10070
12295
  assertExit(viaWriteOutside, 2);
10071
12296
  assertOut(viaWriteOutside, 'BLOCKED');
12297
+
12298
+ // ---------- in-place 扩展:身份分派 × 最小保护集 × 顺序锚 × 两分支对称 ----------
12299
+ // ⑥ 身份三态(子代理语义的增量通道):载荷 agent_id 在场(CC / Codex 原生子代理的载荷形态)
12300
+ // 或环境变量身份深度为正整数(dsh 桥接透传)⇒ 子代理语义放行;两者皆缺(主线程)⇒
12301
+ // 维持既有路径判定——新判据是增量通道,不是对旧语义的替换(不放宽也不误拦)。
12302
+ // 反向构造:把身份短路回退成纯路径判定 ⇒ ⑥a / ⑥c / ⑦a / ⑦c 必红(判别力见交付证据)。
12303
+ const whitelistOutside = path.join(dir, 'src', 'foo.mjs');
12304
+ const identityPayload = (extra) => ({
12305
+ tool_name: 'Write',
12306
+ tool_input: { file_path: whitelistOutside },
12307
+ ...extra,
12308
+ });
12309
+ // ⑥a 含 agent_id(子代理)⇒ 放行(路径在协调者白名单之外,身份未短路时必 BLOCK ⇒ RED)
12310
+ const viaAgentId = runHook(['before_tool'], dir, identityPayload({ agent_id: 'agent-abc123' }));
12311
+ assertExit(viaAgentId, 0);
12312
+ assertOut(viaAgentId, 'workflow-hook-guard-ok');
12313
+ assertOut(viaAgentId, '(subagent identity)');
12314
+ // ⑥b 不含 agent_id(主线程)⇒ 维持既有路径判定:白名单外源码仍 BLOCK
12315
+ const viaMainThread = runHook(['before_tool'], dir, identityPayload({}));
12316
+ assertExit(viaMainThread, 2);
12317
+ assertOut(viaMainThread, 'BLOCKED');
12318
+ // ⑥c dsh 桥接身份透传(环境变量正整数 + 桥接通道标记)⇒ 与载荷面归并为同一判据 ⇒ 放行
12319
+ const viaDepth = runHook(['before_tool'], dir, identityPayload({}), bridgeIdentityEnv('1'));
12320
+ assertExit(viaDepth, 0);
12321
+ assertOut(viaDepth, '(subagent identity)');
12322
+ // ⑥c2 env 面作用域收紧:**只有深度变量在场、桥接通道标记不在场** ⇒ 按协调者语义(白名单外
12323
+ // 源码仍 BLOCK)——CC / Codex 生成的 hook 直接调用本文件、并不自证是桥接,继承来的深度
12324
+ // 变量不得据此走子代理路径(否则守卫在 phase / worktree / runRoot 检查之前就返回)。
12325
+ // 反向构造:守卫去掉标记要求 ⇒ ⑥c2 必红(同载荷被误判为子代理而放行)。
12326
+ for (const inheritedDepth of ['1', '2', '9']) {
12327
+ const inherited = runHook(['before_tool'], dir, identityPayload({}), { FLOW_COMET_AGENT_DEPTH: inheritedDepth });
12328
+ assertExit(inherited, 2);
12329
+ assertOut(inherited, 'BLOCKED');
12330
+ assertNotOut(inherited, '(subagent identity)');
12331
+ }
12332
+ // ⑥c3 标记形态收窄(fail-closed):值不符 / 大小写变体 / 空白变体 / 空串 / 非桥接来源一律不算
12333
+ for (const marker of ['', ' ', 'dsh', 'DSH-BRIDGE', 'Dsh-Bridge', 'dsh-bridge ', ' dsh-bridge', 'bridged']) {
12334
+ const res = runHook(['before_tool'], dir, identityPayload({}),
12335
+ { FLOW_COMET_AGENT_DEPTH: '1', FLOW_COMET_AGENT_DEPTH_SOURCE: marker });
12336
+ assertExit(res, 2);
12337
+ assertOut(res, 'BLOCKED');
12338
+ }
12339
+ // ⑥c4 标记在场但深度非法 ⇒ 仍非身份(两条判据都闭合:标记只证明通道,不代替取值形态收窄)
12340
+ for (const raw of ['0', '', 'abc', '-1']) {
12341
+ const res = runHook(['before_tool'], dir, identityPayload({}),
12342
+ { FLOW_COMET_AGENT_DEPTH: raw, FLOW_COMET_AGENT_DEPTH_SOURCE: 'dsh-bridge' });
12343
+ assertExit(res, 2);
12344
+ assertOut(res, 'BLOCKED');
12345
+ }
12346
+ // ⑥d 取值形态收窄(fail-closed 方向):'0'(协调者)/ 空串 / 纯空白 / 非十进制 / 负数 /
12347
+ // 小数 / 科学计数 / 带符号 一律非身份 ⇒ 退回路径判定(不得读成放宽)
12348
+ for (const raw of ['0', '', ' ', 'abc', '-1', '1.5', '1e1', '+1', '2x']) {
12349
+ const res = runHook(['before_tool'], dir, identityPayload({}), bridgeIdentityEnv(raw));
12350
+ assertExit(res, 2);
12351
+ assertOut(res, 'BLOCKED');
12352
+ }
12353
+ // ⑥e 载荷面收窄:agent_id 非字符串 / 空串 / 纯空白 ⇒ 非身份;agent_type 单独在场不构成
12354
+ // 身份(实现判据只认 agent_id——文本与实现一致锚见技能文本锁场景)
12355
+ for (const bad of [undefined, null, 42, '', ' ']) {
12356
+ const res = runHook(['before_tool'], dir, identityPayload({ agent_id: bad }));
12357
+ assertExit(res, 2);
12358
+ assertOut(res, 'BLOCKED');
12359
+ }
12360
+ const viaAgentTypeOnly = runHook(['before_tool'], dir, identityPayload({ agent_type: 'codex-subagent' }));
12361
+ assertExit(viaAgentTypeOnly, 2);
12362
+ assertOut(viaAgentTypeOnly, 'BLOCKED');
12363
+ // ⑥f 两平台对照(同一判据、无平台分支):codex 分支放行输出严格 JSON `{}`、拦截输出
12364
+ // decision:block 且 exit 0;claude-code 分支放行输出既有文本、拦截 exit 2(见 ⑥a / ⑥b)
12365
+ const codexAllow = runHook(['before_tool', '--platform', 'codex'], dir, identityPayload({ agent_id: 'agent-abc123' }));
12366
+ assertExit(codexAllow, 0);
12367
+ if (codexAllow.output.trim() !== '{}') {
12368
+ throw new Error('codex 分支放行应输出严格 JSON {},实际: ' + JSON.stringify(codexAllow.output));
12369
+ }
12370
+ const codexBlock = runHook(['before_tool', '--platform', 'codex'], dir, identityPayload({}));
12371
+ assertExit(codexBlock, 0);
12372
+ assertOut(codexBlock, '"decision":"block"');
12373
+
12374
+ // ⑦ 顺序锚:身份判据**先于**路径判据求值——身份在场且目标在 runRoot 之外 ⇒ 放行。
12375
+ // 顺序若反转(先解析路径)该目标必 BLOCK ⇒ 本断言本身即顺序判据(判定顺序可断言)。
12376
+ const outsideRoot = path.join(dir, '..', 'outside-232', 'src', 'x.mjs');
12377
+ const orderViaWrite = runHook(['before_tool'], dir,
12378
+ { tool_name: 'Write', tool_input: { file_path: outsideRoot }, agent_id: 'agent-abc123' });
12379
+ assertExit(orderViaWrite, 0);
12380
+ assertOut(orderViaWrite, '(subagent identity)');
12381
+ const orderViaBash = runHook(['before_tool'], dir,
12382
+ { tool_name: 'Bash', tool_input: { command: 'echo x > "' + posix(outsideRoot) + '"' }, agent_id: 'agent-abc123' });
12383
+ assertExit(orderViaBash, 0);
12384
+ // ⑦b 载荷 cwd 不参与路径解释(会话 cwd 与实际工作目录不一致的实测形态):身份在场时
12385
+ // cwd 指向别处 + 相对路径 ⇒ 仍按身份放行(不因 cwd 不一致而误拦)
12386
+ const viaCwdDrift = runHook(['before_tool'], dir, {
12387
+ tool_name: 'Write',
12388
+ tool_input: { file_path: 'src/rel.mjs' },
12389
+ cwd: path.join(dir, '..', 'elsewhere-232'),
12390
+ agent_id: 'agent-abc123',
12391
+ });
12392
+ assertExit(viaCwdDrift, 0);
12393
+ // ⑦c 同载荷无身份 ⇒ 相对路径按 runRoot 解析(cwd 不参与)⇒ 白名单外 BLOCK,且报文中不出现
12394
+ // 按 cwd 解析出的错路径(cwd 漂移不得改变判定依据)
12395
+ const cwdDriftMain = runHook(['before_tool'], dir, {
12396
+ tool_name: 'Write',
12397
+ tool_input: { file_path: 'src/rel.mjs' },
12398
+ cwd: path.join(dir, '..', 'elsewhere-232'),
12399
+ });
12400
+ assertExit(cwdDriftMain, 2);
12401
+ assertOut(cwdDriftMain, 'BLOCKED');
12402
+ assertNotOut(cwdDriftMain, 'elsewhere-232');
12403
+
12404
+ // ⑧ runRoot 外写入的关断,两分支对称:同一目标经 Write / Edit(file_path 分支)与 Bash
12405
+ // (命令级写入)同判 BLOCK——修复前 file_path 分支静默放行(fail-open)而 Bash 分支拦截。
12406
+ // 反向构造:恢复 file_path 分支的静默放行 ⇒ ⑧a / ⑧b 必红。
12407
+ const outsideWrite = runHook(['before_tool'], dir,
12408
+ { tool_name: 'Write', tool_input: { file_path: outsideRoot } });
12409
+ assertExit(outsideWrite, 2);
12410
+ assertOut(outsideWrite, 'BLOCKED');
12411
+ assertOut(outsideWrite, '项目根之外');
12412
+ const outsideEdit = runHook(['before_tool'], dir,
12413
+ { tool_name: 'Edit', tool_input: { file_path: outsideRoot } });
12414
+ assertExit(outsideEdit, 2);
12415
+ assertOut(outsideEdit, 'BLOCKED');
12416
+ const outsideBash = runHook(['before_tool'], dir,
12417
+ { tool_name: 'Bash', tool_input: { command: 'echo x > "' + posix(outsideRoot) + '"' } });
12418
+ assertExit(outsideBash, 2);
12419
+ assertOut(outsideBash, 'BLOCKED');
12420
+ // ⑧b 身份在场时两分支同样对称放行(顺序锚在 Bash 分支上的对照——见 ⑦a 第二例)
12421
+
12422
+ // ⑨ 最小保护集:身份放行**不放行**两个机器面目标——机器状态文件与本次运行实际生效的
12423
+ // 协议文件(三平台身份形态一致受拦)。反向构造:身份短路时跳过保护集判定 ⇒ ⑨ 必红。
12424
+ const stateFileTarget = path.join(dir, '.flow-comet', 'flow-comet-state.json');
12425
+ const protocolFileTarget = path.join(dir, 'reference', 'workflow-protocol.json');
12426
+ for (const [label, target] of [['机器状态文件', stateFileTarget], ['协议保护路径', protocolFileTarget]]) {
12427
+ const viaIdentityWrite = runHook(['before_tool'], dir,
12428
+ { tool_name: 'Write', tool_input: { file_path: target }, agent_id: 'agent-abc123' });
12429
+ assertExit(viaIdentityWrite, 2);
12430
+ assertOut(viaIdentityWrite, 'BLOCKED');
12431
+ const viaIdentityEdit = runHook(['before_tool'], dir,
12432
+ { tool_name: 'Edit', tool_input: { file_path: target }, agent_id: 'agent-abc123' });
12433
+ assertExit(viaIdentityEdit, 2);
12434
+ assertOut(viaIdentityEdit, 'BLOCKED');
12435
+ const viaIdentityBash = runHook(['before_tool'], dir,
12436
+ { tool_name: 'Bash', tool_input: { command: 'echo x > "' + posix(target) + '"' }, agent_id: 'agent-abc123' });
12437
+ assertExit(viaIdentityBash, 2);
12438
+ assertOut(viaIdentityBash, 'BLOCKED');
12439
+ const viaDepthWrite = runHook(['before_tool'], dir,
12440
+ { tool_name: 'Write', tool_input: { file_path: target } }, bridgeIdentityEnv('2'));
12441
+ assertExit(viaDepthWrite, 2);
12442
+ assertOut(viaDepthWrite, 'BLOCKED');
12443
+ // 报文须点名保护集类别(经桥接通道身份放行下的拦截理由):协调者路径的报语文义不同
12444
+ // (state 文件另有同族点名的协调者分支,协议面则是「不在允许范围」)⇒ 本断言锁住「身份
12445
+ // 在场仍走保护集判定」而非靠白名单兜底(判别力见 ⑥c2 的继承形态对照)。
12446
+ assertOut(viaDepthWrite, label === '机器状态文件' ? 'state 文件' : '协议文件');
12447
+ const codexIdentityBlock = runHook(['before_tool', '--platform', 'codex'], dir,
12448
+ { tool_name: 'Write', tool_input: { file_path: target }, agent_id: 'agent-abc123' });
12449
+ assertExit(codexIdentityBlock, 0);
12450
+ assertOut(codexIdentityBlock, '"decision":"block"');
12451
+ if (!codexIdentityBlock.output.includes(label === '机器状态文件' ? 'state 文件' : '协议文件')) {
12452
+ throw new Error('保护集拦截报文应点名目标类别(' + label + '): ' + JSON.stringify(codexIdentityBlock.output));
12453
+ }
12454
+ }
12455
+ // ⑨b 对照:同一身份写普通源码 / 工件路径 ⇒ 放行(保护集不扩大——只此两个目标)
12456
+ const identityAllowedSource = runHook(['before_tool'], dir,
12457
+ { tool_name: 'Write', tool_input: { file_path: whitelistOutside }, agent_id: 'agent-abc123' });
12458
+ assertExit(identityAllowedSource, 0);
12459
+ const identityAllowedArtifact = runHook(['before_tool'], dir,
12460
+ { tool_name: 'Write', tool_input: { file_path: path.join(dir, '.specs', CHANGE_ID, 'note.md') }, agent_id: 'agent-abc123' });
12461
+ assertExit(identityAllowedArtifact, 0);
12462
+ // ⑨c 别名形态闭合(物理同一性):经 8.3 短路径 / 符号链接拼写的同一状态文件同样受拦
12463
+ // (词法比较看不见别名——身份放行下保护集是唯一防线,故须闭合)。平台无法构造链接时
12464
+ // 如实降级为可见提示,不静默跳过。
12465
+ const stateAliasDir = path.join(dir, '.flow-comet-alias');
12466
+ let aliasLinkCreated = false;
12467
+ try {
12468
+ fs.symlinkSync(path.join(dir, '.flow-comet'), stateAliasDir,
12469
+ process.platform === 'win32' ? 'junction' : 'dir');
12470
+ aliasLinkCreated = true;
12471
+ } catch { aliasLinkCreated = false; }
12472
+ if (aliasLinkCreated) {
12473
+ const viaAlias = runHook(['before_tool'], dir,
12474
+ { tool_name: 'Write', tool_input: { file_path: path.join(stateAliasDir, 'flow-comet-state.json') }, agent_id: 'agent-abc123' });
12475
+ assertExit(viaAlias, 2);
12476
+ assertOut(viaAlias, 'BLOCKED');
12477
+ } else {
12478
+ console.error('WARN: 当前平台无法构造目录链接,保护集别名形态断言降级(词法判定仍由 ⑨ 覆盖)');
12479
+ }
12480
+ // ⑨d 盘符根拼写(Windows 上 Git-Bash 类 shell 的 `/d/<剩余>` 形态)与盘符拼写**同判**:
12481
+ // win32 的目标解析把 `/d/<剩余>` 读成「当前盘根下的 \d\<剩余>」而非 `D:\<剩余>` ⇒
12482
+ // 词法相对化判为根外(相对路径为空)⇒ 状态文件判据被跳过;物理判据对错解路径 stat
12483
+ // 失败 ⇒ 两道判据同时失守——身份放行下保护集形同虚设(fail-open)。归一入口唯一
12484
+ // (既有写入目标解析),故两条判据同时闭合、各等价拼写同判。
12485
+ // 该拼写是 Windows 上 Git-Bash 类 shell 的自然产物;非 win32 平台它是普通 POSIX
12486
+ // 绝对路径,语义不同 ⇒ 显式不适用(不静默跳过——未验证 ≠ 通过)。
12487
+ const hasDriveRoot = /^[A-Za-z]:[\\/]/.test(dir);
12488
+ if (process.platform === 'win32' && hasDriveRoot) {
12489
+ const driveRootSpelling = (p) => '/' + p[0].toLowerCase() + p.slice(2).replaceAll('\\', '/');
12490
+ for (const [label, target, marker] of [
12491
+ ['机器状态文件', stateFileTarget, 'state 文件'],
12492
+ ['协议保护路径', protocolFileTarget, '协议文件'],
12493
+ ]) {
12494
+ const exits = [];
12495
+ const forms = [['盘符根拼写', driveRootSpelling(target)], ['盘符拼写', posix(target)]];
12496
+ for (const [formLabel, form] of forms) {
12497
+ const viaWrite = runHook(['before_tool'], dir,
12498
+ { tool_name: 'Write', tool_input: { file_path: form }, agent_id: 'agent-abc123' });
12499
+ assertExit(viaWrite, 2);
12500
+ assertOut(viaWrite, marker);
12501
+ const viaBash = runHook(['before_tool'], dir,
12502
+ { tool_name: 'Bash', tool_input: { command: 'cp "' + form + '" "' + form + '"' }, agent_id: 'agent-abc123' });
12503
+ assertExit(viaBash, 2);
12504
+ assertOut(viaBash, marker);
12505
+ exits.push(viaWrite.status, viaBash.status);
12506
+ if (formLabel === '盘符根拼写') {
12507
+ // 盘符字母大写变体同归一(同族拼写不得因大小写漏判)
12508
+ const upper = runHook(['before_tool'], dir,
12509
+ { tool_name: 'Write', tool_input: { file_path: '/' + form[1].toUpperCase() + form.slice(2) }, agent_id: 'agent-abc123' });
12510
+ assertExit(upper, 2);
12511
+ assertOut(upper, marker);
12512
+ }
12513
+ }
12514
+ if (exits.some((code) => code !== exits[0])) {
12515
+ throw new Error(label + ' 的两种拼写应同判,实际 exit: ' + JSON.stringify(exits));
12516
+ }
12517
+ if (label === '机器状态文件') {
12518
+ // 协调者路径(无身份)同样闭合:命令级写入的盘符根拼写命中状态文件判据 ⇒ 报文点名
12519
+ // 目标类别(修复前落到「不在允许范围」兜底分支——证明目标确被抽取,缺口在判定)
12520
+ const msysMain = driveRootSpelling(target);
12521
+ const asMain = runHook(['before_tool'], dir,
12522
+ { tool_name: 'Bash', tool_input: { command: 'cp "' + msysMain + '" "' + msysMain + '"' } });
12523
+ assertExit(asMain, 2);
12524
+ assertOut(asMain, marker);
12525
+ }
12526
+ }
12527
+ // ⑨e 对照:同一身份写普通源码的盘符根拼写 ⇒ 放行(归一不得把保护集扩大到其余路径)
12528
+ const msysSource = driveRootSpelling(whitelistOutside);
12529
+ const msysSourceWrite = runHook(['before_tool'], dir,
12530
+ { tool_name: 'Write', tool_input: { file_path: msysSource }, agent_id: 'agent-abc123' });
12531
+ assertExit(msysSourceWrite, 0);
12532
+ assertOut(msysSourceWrite, '(subagent identity)');
12533
+ const msysSourceBash = runHook(['before_tool'], dir,
12534
+ { tool_name: 'Bash', tool_input: { command: 'cp "' + msysSource + '" "' + msysSource + '"' }, agent_id: 'agent-abc123' });
12535
+ assertExit(msysSourceBash, 0);
12536
+ // ⑨f 单字母限定(`/dev`、`/etc` 一类多字母首段不得被当作盘符根):该目标按「当前盘根下的
12537
+ // 同名目录」解析 ⇒ 项目根之外 ⇒ 协调者拦截报文带根外语义。若归一放宽为「首字母后不要求
12538
+ // 分隔符」,目标被改写成盘符相对形态后落在项目根内 ⇒ 报文语义改变 ⇒ 本断言必红。
12539
+ const notDriveRoot = '/' + dir[0].toLowerCase() + 'ev/probe.md';
12540
+ const notDriveRootRes = runHook(['before_tool'], dir,
12541
+ { tool_name: 'Write', tool_input: { file_path: notDriveRoot } });
12542
+ assertExit(notDriveRootRes, 2);
12543
+ assertOut(notDriveRootRes, '项目根之外');
12544
+ } else {
12545
+ // 非 win32:该拼写是**普通 POSIX 绝对路径**,归一只许在 win32 生效(否则同一目标会被改写成
12546
+ // 项目根内的相对形态,报文失去根外语义)。本断言锁的是「平台限定」这半边——正向断言在
12547
+ // 本平台不适用,故此处改为可判别的替代锚(断言失败即说明归一变无条件)。
12548
+ const posixSpelling = '/d/probe.md';
12549
+ const posixRes = runHook(['before_tool'], dir,
12550
+ { tool_name: 'Write', tool_input: { file_path: posixSpelling } });
12551
+ assertExit(posixRes, 2);
12552
+ assertOut(posixRes, '项目根之外');
12553
+ console.error('注意: 本平台无盘符根形态,盘符根拼写的归一等价性断言**显式不适用**'
12554
+ + '(dsh/pwsh 与 Codex/cmd 不产生该拼写;win32 侧为唯一判别面)——已改为断言平台限定半边'
12555
+ + '(该拼写在本平台不得被归一到项目根内);未验证 ≠ 通过');
12556
+ }
12557
+
12558
+ // ⑩ apply_patch 承载形态的耐久锚(in-place 扩展):补丁正文写在 tool_input.command、
12559
+ // 载荷无 file_path——目标须由补丁摘要行抽出后才进入既有判定入口(白名单与最小保护集
12560
+ // 共用同一返回值)。判据与内建反向构造见模块级 applyPatchAnchorProblems。
12561
+ const patchProblems = applyPatchAnchorProblems(dir);
12562
+ if (patchProblems.length > 0) {
12563
+ throw new Error('apply_patch 目标解析锚失败: ' + patchProblems.join('; '));
12564
+ }
10072
12565
  },
10073
12566
  },
10074
12567
 
@@ -12784,52 +15277,75 @@ const SCENARIOS = [
12784
15277
  || !missingError.includes(path.join('flow-comet-execute', 'SKILL.md'))) {
12785
15278
  throw new Error('组件技能缺失时未显式失败并给指引: ' + JSON.stringify(missingError));
12786
15279
  }
12787
- // 真实三节点文本锁:从本 suite 自身位置推导技能树(不假定权威源布局)。逐份断言:
12788
- // 段在场 + 6 关键词 + 反 advance 捷径 + 不得把直接 exit 源节点收场当正常路径;同时收集
12789
- // 段正文(同一区间:首个 ## 修复回路状态机路径 → 下一 ## 或 EOF,标题不计入)供 F-4 互比。
12790
- const sectionEntries = [];
15280
+ // 真实三节点文本锁(ADR-016 重定向):原「三册段正文 sha256 完全一致」的逐字锁**作废**,
15281
+ // 改为「三册各含要点句与条件句 + 该段正文**仅一处**(权威 = `reference/fix-loop.md`)+
15282
+ // 原 6 关键词与「禁 `advance` 作正常路径」断言**迁到权威处**」。判据抽成纯函数(单一实现:
15283
+ // 真实判据与反向构造探针共用),逐条自带反向构造。
15284
+ const componentTexts = new Map();
12791
15285
  for (const nodeSkill of componentSkills) {
12792
- const file = resolveComponentSkillFile(nodeSkill);
12793
- const text = fs.readFileSync(file, 'utf8');
12794
- const match = text.match(/(?:^|\r?\n)## 修复回路状态机路径\r?\n([\s\S]*?)(?=\r?\n## |$)/);
12795
- if (!match) {
12796
- throw new Error(nodeSkill + ' SKILL.md 缺「## 修复回路状态机路径」段');
12797
- }
12798
- const section = match[1];
12799
- for (const keyword of ['受控归位', 'NODE: execute', '回源节点跑出口', 'entry <源节点>', 'exit <源节点> --apply', '禁止绕过']) {
12800
- if (!section.includes(keyword)) {
12801
- throw new Error(nodeSkill + ' 修复回路状态机路径段缺关键词: ' + keyword);
15286
+ componentTexts.set(nodeSkill, fs.readFileSync(resolveComponentSkillFile(nodeSkill), 'utf8'));
15287
+ }
15288
+ const fixLoopAuthorityPath = path.join(__dirname, '..', 'reference', 'fix-loop.md');
15289
+ if (!fs.existsSync(fixLoopAuthorityPath)) {
15290
+ throw new Error(FIX_LOOP_AUTHORITY_REL + ' 不在场(修复回路段的唯一权威处缺失)');
15291
+ }
15292
+ const fixLoopAuthorityText = fs.readFileSync(fixLoopAuthorityPath, 'utf8');
15293
+ const fixLoopSources = { books: componentTexts, authority: fixLoopAuthorityText };
15294
+ const fixLoopProblems = fixLoopStateMachineProblems(fixLoopSources);
15295
+ if (fixLoopProblems.length > 0) {
15296
+ throw new Error('修复回路状态机路径文本锁不符(重定向后判据): ' + fixLoopProblems.join('; '));
15297
+ }
15298
+ // 反向构造(同一判据驱动,逐条对应重定向后的两侧):
15299
+ // ① 逐册抽掉任一要点 token ⇒ 必报(三册各自的要点句在场);
15300
+ // ② 权威处逐条抽掉关键词 ⇒ 必报(原 6 关键词已迁到权威处);
15301
+ // ③ 把权威段落复制进任一册 ⇒ 必报「第二份正文」(正文唯一——原 sha256 锁**要求**三份一致,
15302
+ // 恰恰抓不到这一侧);④ 册内还原 `advance` 捷径 / 直接 exit 收场 ⇒ 必报。
15303
+ const stripFixLoopToken = (text, token) => text.split(token).join('(反向构造:抽掉)');
15304
+ for (const [nodeSkill, text] of componentTexts) {
15305
+ for (const [label, tokens] of FIX_LOOP_BOOK_ELEMENT_GROUPS) {
15306
+ const probed = new Map(componentTexts).set(nodeSkill, stripFixLoopToken(text, tokens[0]));
15307
+ if (probed.get(nodeSkill) === text) continue;
15308
+ if (!fixLoopStateMachineProblems({ ...fixLoopSources, books: probed }).some((p) => p.includes(label))) {
15309
+ throw new Error('反向构造判别力缺失(' + nodeSkill + ' 抽掉「' + label + '」要点 token 未被判违规)');
12802
15310
  }
12803
15311
  }
12804
- if (section.includes('advance')) {
12805
- throw new Error(nodeSkill + ' 修复回路状态机路径段不得把 advance 作为正常路径');
12806
- }
12807
- for (const line of section.split(/\r?\n/)) {
12808
- if (line.includes('直接') && line.includes('exit') && !/禁止|不得|会被 BLOCKED/.test(line)) {
12809
- throw new Error(nodeSkill + ' 修复回路状态机路径段不得把直接 exit 源节点收场作为正常路径: ' + line.trim());
12810
- }
15312
+ }
15313
+ for (const keyword of FIX_LOOP_AUTHORITY_KEYWORDS) {
15314
+ if (!fixLoopAuthorityText.includes(keyword)) continue; // 缺失已由真实判据报告
15315
+ if (!fixLoopStateMachineProblems({
15316
+ ...fixLoopSources, authority: stripFixLoopToken(fixLoopAuthorityText, keyword),
15317
+ }).some((p) => p.includes(keyword))) {
15318
+ throw new Error('反向构造判别力缺失(权威处抽掉关键词 «' + keyword + '» 未被判违规)');
12811
15319
  }
12812
- // F-4 段一致性锁:CRLF→LF 归一、不 trim(行尾/空白差异同样算漂移),正文参与三份互比。
12813
- const normalized = section.replace(/\r\n/g, '\n');
12814
- sectionEntries.push({ nodeSkill, body: normalized, hash: createHash('sha256').update(normalized, 'utf8').digest('hex') });
12815
15320
  }
12816
- // F-4:三份段正文必须非空且逐字完全一致(当前无合法 per-node 差异)——任一单文件漂移即
12817
- // 套件失败;失败信息给出三份 hash 与首处差异位置/上下文(L-064 反向构造证明判别力)。
12818
- const emptyEntry = sectionEntries.find((entry) => entry.body.trim() === '');
12819
- if (emptyEntry) {
12820
- throw new Error('修复回路状态机路径段不得为空: ' + emptyEntry.nodeSkill);
15321
+ const fixLoopAuthoritySection = fixLoopStateMachineSectionOf(fixLoopAuthorityText);
15322
+ const copyInto = 'flow-comet-review';
15323
+ const reviewText = componentTexts.get(copyInto).replace(/\r\n/g, '\n');
15324
+ const reviewSection = fixLoopStateMachineSectionOf(reviewText);
15325
+ const duplicated = fixLoopStateMachineProblems({
15326
+ ...fixLoopSources,
15327
+ books: new Map(componentTexts).set(copyInto, reviewText.split(reviewSection).join(fixLoopAuthoritySection)),
15328
+ });
15329
+ if (!duplicated.some((p) => p.includes('第二份正文'))) {
15330
+ throw new Error('反向构造判别力缺失(权威段落整段回流册子未被判「第二份正文」)');
12821
15331
  }
12822
- const baselineEntry = sectionEntries[0];
12823
- for (const entry of sectionEntries.slice(1)) {
12824
- if (entry.body === baselineEntry.body) continue;
12825
- const limit = Math.min(baselineEntry.body.length, entry.body.length);
12826
- let diffIndex = 0;
12827
- while (diffIndex < limit && baselineEntry.body[diffIndex] === entry.body[diffIndex]) diffIndex += 1;
12828
- const context = baselineEntry.body.slice(Math.max(0, diffIndex - 40), diffIndex + 40);
12829
- throw new Error('修复回路状态机路径段三份 SKILL 正文不一致(F-4 段一致性锁):'
12830
- + baselineEntry.nodeSkill + ' sha256=' + baselineEntry.hash
12831
- + ' vs ' + entry.nodeSkill + ' sha256=' + entry.hash
12832
- + ';首处差异 @' + diffIndex + '(基准上下文: ' + JSON.stringify(context) + ')');
15332
+ const advanceRel = 'flow-comet-verify';
15333
+ const advanceText = componentTexts.get(advanceRel).replace(/\r\n/g, '\n');
15334
+ const advanceSection = fixLoopStateMachineSectionOf(advanceText);
15335
+ const advanceProbe = new Map(componentTexts).set(advanceRel,
15336
+ advanceText.split(advanceSection).join(advanceSection + '\n用 advance 直接推进即可。\n'));
15337
+ if (!fixLoopStateMachineProblems({ ...fixLoopSources, books: advanceProbe })
15338
+ .some((p) => p.includes('advance'))) {
15339
+ throw new Error('反向构造判别力缺失(册内还原 advance 捷径未被判违规)');
15340
+ }
15341
+ const exitRel = 'flow-comet-review';
15342
+ const exitText = componentTexts.get(exitRel).replace(/\r\n/g, '\n');
15343
+ const exitSection = fixLoopStateMachineSectionOf(exitText);
15344
+ const directExitProbe = new Map(componentTexts).set(exitRel,
15345
+ exitText.split(exitSection).join(exitSection + '\n直接跑 exit review 收场即可。\n'));
15346
+ if (!fixLoopStateMachineProblems({ ...fixLoopSources, books: directExitProbe })
15347
+ .some((p) => p.includes('直接 exit'))) {
15348
+ throw new Error('反向构造判别力缺失(册内还原「直接 exit 收场」未被判违规)');
12833
15349
  }
12834
15350
  },
12835
15351
  },
@@ -14781,11 +17297,14 @@ const SCENARIOS = [
14781
17297
 
14782
17298
  // 286: ui-design 强制等级的文本一致性锚——协议 `design.requiredSkillCalls[flow-comet-ui-design]`
14783
17299
  // 为 `guarded`,**五份**技能文本(ui-design 技能 / 入口 SKILL / design 节点 SKILL / 入口展开册
14784
- // GUIDANCE / change 阶段 SKILL)不得残留 `advisory` 表述且须同时点名该绑定与 `guarded`。等级只在
14785
- // 协议里表达一次,文本是它的散文副本:副本漂移即红(旧表述「advisory,不要求声明」正是被本锚拦下
14786
- // 的形态)。另锚**判据散文口径**:五份文本必须陈述引擎收紧后的**结构形态**(独立行 / 行首 /
14787
- // 适用性标签的字段值位 + 词形边界 + 命中片段回显),不得残留旧口径(「段内不含 / 未标注字面
14788
- // 『不适用』」——把判据说成段内任意位置子串,是「一处措辞即关闸」fail-open 的文字版)。
17300
+ // `reference/entry-detail.md` / change 阶段 SKILL)不得残留 `advisory` 表述且须同时点名该绑定与
17301
+ // `guarded`。等级只在协议里表达一次,文本是它的散文副本:副本漂移即红(旧表述「advisory,不要求
17302
+ // 声明」正是被本锚拦下的形态)。
17303
+ // **判据散文口径(ADR-016 重定向)**:原判据要求**五份文本各自**陈述五个结构 token,且反向构造
17304
+ // 断言**每份**文本都含「词形边界」——T05 把口径收归 `flow-comet-ui-design` 册一处权威后,那一侧
17305
+ // 会以两种方式失败(五份各自的 token 缺失 + 反向构造前提不成立)。新判据三件套:**一处权威**
17306
+ //(ui-design 册陈述五个结构 token 且零旧口径)+ **入口册指针在场**(各引用册以条件句指向该册)
17307
+ // + **该口径正文唯一**(块级跨距:任何其它分发文本不得含权威口径段的 ≥120 字符逐字副本)。
14789
17308
  {
14790
17309
  name: '286 ui-design 强制等级一致性锚:协议 guarded + 五处技能文本零 advisory 残留 + 结构判据散文口径',
14791
17310
  run: () => {
@@ -14801,19 +17320,30 @@ const SCENARIOS = [
14801
17320
  'flow-comet-ui-design/SKILL.md': path.join(skillsRoot, 'flow-comet-ui-design', 'SKILL.md'),
14802
17321
  'flow-comet/SKILL.md': path.join(skillsRoot, 'flow-comet', 'SKILL.md'),
14803
17322
  'flow-comet-design/SKILL.md': path.join(skillsRoot, 'flow-comet-design', 'SKILL.md'),
14804
- 'flow-comet/GUIDANCE.md': path.join(skillsRoot, 'flow-comet', 'GUIDANCE.md'),
17323
+ 'flow-comet/reference/entry-detail.md': path.join(skillsRoot, 'flow-comet', 'reference', 'entry-detail.md'),
14805
17324
  'flow-comet-change/SKILL.md': path.join(skillsRoot, 'flow-comet-change', 'SKILL.md'),
14806
17325
  };
17326
+ const textByRel = new Map();
14807
17327
  for (const [label, file] of Object.entries(texts)) {
14808
17328
  const text = fs.readFileSync(file, 'utf8');
17329
+ textByRel.set(label, text);
14809
17330
  assertTrue(!/advisory/i.test(text), label + ' 残留 advisory 等级表述(协议为 guarded)');
14810
17331
  assertTrue(text.includes('guarded'), label + ' 未点名 guarded 等级');
14811
17332
  assertTrue(text.includes('flow-comet-ui-design'), label + ' 未点名 flow-comet-ui-design 绑定');
14812
- const proseProblems = frontendCriterionProseProblems(label, text);
14813
- assertEqual(proseProblems.length, 0, '判据散文口径未对齐: ' + proseProblems.join(' | '));
14814
17333
  }
14815
- // 反向构造(合成输入驱动同一判据,证明判据不恒真空过):① 旧口径句逐条注入任一文本 → 必报;
14816
- // ② 结构词缺一 → 必报;③ 原地加回旧口径的真实文本副本 → 必报(「把旧口径加回任一文本即红」)。
17334
+ // —— 结构判据散文口径的三件套(重定向后判据;纯函数 + 合成文本面驱动)——
17335
+ const criterionSources = {
17336
+ authorityRel: FRONTEND_CRITERION_AUTHORITY_REL,
17337
+ authorityText: textByRel.get(FRONTEND_CRITERION_AUTHORITY_REL),
17338
+ pointerDocs: new Map(FRONTEND_CRITERION_POINTER_RELS.map(([rel]) => [rel, textByRel.get(rel)])),
17339
+ docs: new Map(skillTreeDocFiles().map(([rel, file]) => [rel, fs.readFileSync(file, 'utf8')])),
17340
+ };
17341
+ const criterionProblems = frontendCriterionRedirectProblems(criterionSources);
17342
+ assertEqual(criterionProblems.length, 0, '判据散文口径未对齐: ' + criterionProblems.join(' | '));
17343
+ // 反向构造(合成输入驱动同一判据,证明它不恒真空过):
17344
+ // ① 结构词缺一 → 必报;② 旧口径句注入权威处 → 必报「残留旧口径」;
17345
+ // ③ 权威口径段复制进第二册 → 必报「第二份正文」(原「五份各自陈述」的方向已反转);
17346
+ // ④ 抽掉入口册指针 → 必报「指针不在场」。
14817
17347
  const structuralSample = '前端判据是结构级的:独立行 / 行首 / 适用性标签的字段值位三种形态,'
14818
17348
  + '标记后须成词形边界,命中片段回显。\n';
14819
17349
  assertEqual(frontendCriterionProseProblems('sample', structuralSample).length, 0,
@@ -14824,18 +17354,40 @@ const SCENARIOS = [
14824
17354
  '非前端项目:在段内标注「不适用」两个字面。',
14825
17355
  ];
14826
17356
  for (const stale of staleSamples) {
14827
- const problems = frontendCriterionProseProblems('sample', structuralSample + stale + '\n');
14828
- assertTrue(problems.some((problem) => problem.includes('残留旧口径')),
14829
- '旧口径样本未被判违规: ' + JSON.stringify(stale) + ' → ' + JSON.stringify(problems));
14830
- }
14831
- for (const text of Object.values(texts)) {
14832
- const original = fs.readFileSync(text, 'utf8');
14833
- const regressed = original.replace('词形边界', '段内未标注「不适用」');
14834
- assertTrue(regressed !== original, '反向构造前提不成立:' + text + ' 缺「词形边界」字样');
14835
- assertTrue(frontendCriterionProseProblems('regressed', regressed)
14836
- .some((problem) => problem.includes('残留旧口径') || problem.includes('未陈述结构形态')),
14837
- '把旧口径加回真实文本未被判违规: ' + text);
14838
- }
17357
+ const probed = frontendCriterionRedirectProblems({
17358
+ ...criterionSources,
17359
+ authorityText: criterionSources.authorityText + '\n' + stale + '\n',
17360
+ });
17361
+ assertTrue(probed.some((problem) => problem.includes('残留旧口径')),
17362
+ '旧口径样本未被判违规: ' + JSON.stringify(stale) + ' → ' + JSON.stringify(probed));
17363
+ }
17364
+ for (const group of FRONTEND_CRITERION_STRUCTURE_GROUPS) {
17365
+ // OR 组的反向构造必须抽掉**整组** token(只抽一个会被组内另一形态满足而恒真)。
17366
+ const strippedText = group.reduce((acc, token) => acc.split(token).join('(反向构造:抽掉)'),
17367
+ criterionSources.authorityText);
17368
+ const stripped = frontendCriterionRedirectProblems({
17369
+ ...criterionSources,
17370
+ authorityText: strippedText,
17371
+ });
17372
+ assertTrue(stripped.some((problem) => problem.includes('未陈述结构形态')),
17373
+ '权威处抽掉结构形态组「' + group.join(' / ') + '」未被判违规: ' + JSON.stringify(stripped));
17374
+ }
17375
+ const criterionBlock = frontendCriterionAuthorityBlock(criterionSources.authorityText);
17376
+ assertTrue(criterionBlock !== null, '权威口径段切片为空(缺「结构形态」三种任一 → 仍判前端 的整段)');
17377
+ const copied = frontendCriterionRedirectProblems({
17378
+ ...criterionSources,
17379
+ docs: new Map(criterionSources.docs).set('flow-comet-design/SKILL.md',
17380
+ criterionSources.docs.get('flow-comet-design/SKILL.md') + '\n' + criterionBlock + '\n'),
17381
+ });
17382
+ assertTrue(copied.some((problem) => problem.includes('第二份正文')),
17383
+ '权威口径段复制进第二册未被判违规: ' + JSON.stringify(copied));
17384
+ const pointerStripped = frontendCriterionRedirectProblems({
17385
+ ...criterionSources,
17386
+ pointerDocs: new Map([...criterionSources.pointerDocs].map(([rel, text]) => [rel,
17387
+ text.split('唯一权威').join('(反向构造:抽掉指针)')])),
17388
+ });
17389
+ assertTrue(pointerStripped.some((problem) => problem.includes('指针不在场')),
17390
+ '抽掉各册指针未被判违规: ' + JSON.stringify(pointerStripped));
14839
17391
  // 行为口径的散文锚:非前端可见跳过 + 旧 change 渐进(与 285 的行为断言同源)
14840
17392
  const uiDesignSkill = fs.readFileSync(texts['flow-comet-ui-design/SKILL.md'], 'utf8');
14841
17393
  assertTrue(uiDesignSkill.includes('UI-DESIGN: skipped(非前端)'), 'ui-design 技能缺非前端跳过口径');
@@ -15649,7 +18201,8 @@ const SCENARIOS = [
15649
18201
 
15650
18202
  // 298: 禁裸拼接静态锚(DESIGN R4 的落地)——时间形态 / 格式化的唯一权威是 time-utils.mjs:
15651
18203
  // 三条侧命令零容忍(人可见报告 / CLI 摘要行 / 备份名);其余引擎脚本走**显式白名单 + 逐条理由**
15652
- // (既有 13 处都是已持久化的机器字段,迁移留专门窗口)。判别力两条:① 白名单判定是纯函数,
18204
+ // (既有 13 处都是已持久化的机器字段,迁移留专门窗口;新增写入路径一律走 time-utils,不得把
18205
+ // 白名单当增量口——撤回留痕 withdrawnAt 即按此落 nowTimestamp)。判别力两条:① 白名单判定是纯函数,
15653
18206
  // 合成输入可驱动「条数漂移(增 / 减)」与「未登记文件」三态必报;② 合成引擎目录注入第二处
15654
18207
  // 裸拼接 → 检出必增(证明真实面判据不恒真空过)。
15655
18208
  {