flow-comet 1.6.0 → 1.6.1

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 (34) hide show
  1. package/.flow-comet/skills/flow-comet/GUIDANCE.md +22 -3
  2. package/.flow-comet/skills/flow-comet/INSTALLED_VERSION +1 -1
  3. package/.flow-comet/skills/flow-comet/SKILL.md +20 -1
  4. package/.flow-comet/skills/flow-comet/reference/KNOWN-ISSUES-template.md +3 -3
  5. package/.flow-comet/skills/flow-comet/reference/TEST-MATRIX.md +15 -15
  6. package/.flow-comet/skills/flow-comet/reference/dsh-platform.md +19 -11
  7. package/.flow-comet/skills/flow-comet/reference/recovery.md +1 -7
  8. package/.flow-comet/skills/flow-comet/reference/worktree-notes.md +21 -3
  9. package/.flow-comet/skills/flow-comet/scripts/contract-check.mjs +41 -31
  10. package/.flow-comet/skills/flow-comet/scripts/guard-self-test.mjs +2513 -295
  11. package/.flow-comet/skills/flow-comet/scripts/protocol-utils.mjs +1 -1
  12. package/.flow-comet/skills/flow-comet/scripts/route-node.mjs +459 -11
  13. package/.flow-comet/skills/flow-comet/scripts/state-schema.mjs +3 -3
  14. package/.flow-comet/skills/flow-comet/scripts/system-test.mjs +422 -10
  15. package/.flow-comet/skills/flow-comet/scripts/workflow-guard.mjs +140 -226
  16. package/.flow-comet/skills/flow-comet/scripts/workflow-handoff.mjs +1 -1
  17. package/.flow-comet/skills/flow-comet/scripts/workflow-state.mjs +362 -4
  18. package/.flow-comet/skills/flow-comet-archive/SKILL.md +2 -0
  19. package/.flow-comet/skills/flow-comet-change/SKILL.md +2 -0
  20. package/.flow-comet/skills/flow-comet-design/SKILL.md +2 -0
  21. package/.flow-comet/skills/flow-comet-dev/SKILL.md +3 -1
  22. package/.flow-comet/skills/flow-comet-execute/SKILL.md +6 -4
  23. package/.flow-comet/skills/flow-comet-integration/SKILL.md +2 -0
  24. package/.flow-comet/skills/flow-comet-open/SKILL.md +2 -0
  25. package/.flow-comet/skills/flow-comet-plan/SKILL.md +17 -6
  26. package/.flow-comet/skills/flow-comet-requirement/SKILL.md +2 -0
  27. package/.flow-comet/skills/flow-comet-review/SKILL.md +7 -5
  28. package/.flow-comet/skills/flow-comet-subagent-execute/SKILL.md +12 -9
  29. package/.flow-comet/skills/flow-comet-task/SKILL.md +7 -3
  30. package/.flow-comet/skills/flow-comet-test/SKILL.md +2 -0
  31. package/.flow-comet/skills/flow-comet-verify/SKILL.md +7 -5
  32. package/README.md +45 -119
  33. package/package.json +1 -1
  34. package/scripts/dsh-bridge.mjs +2 -2
@@ -5,7 +5,7 @@ import { fileURLToPath } from 'url';
5
5
  import { validateStateFields, verifyFailuresFor, setVerifyFailuresFor, RUNTIME_STATE_PATH, LEGACY_RUNTIME_STATE_PATH, resolveProtocolPathWithState, hasProtocolCliArg } from './state-schema.mjs';
6
6
  import { readProtocolFile, validateProtocolSchema, NODE_PROTOCOL_FILES, workflowPathInside, inspectWorkflowProtectedPath, readWorkflowProtectedFile, workflowFileObjectIdentity, workflowSameFileObject, workflowSameFileStat } from './protocol-utils.mjs';
7
7
  import { taskOpeningAttrs, taskBlocks as extractTaskBlocks } from './task-parsing.mjs';
8
- import { resolveNextNode, resolveFixRollbackDecision, resolveFixRollbackState, applyFixRollbackRound, resolveFixReturnNode, EXECUTE_FAMILY_NODE_IDS, TASK_SET_SIGNATURE_ALGO, taskSetSignature, parseTaskSetSignature, sameTaskSetSignature, taskSetSignatureVersionSkew, classifyFixReturnCause, normalizeHeading, FIX_SECTION_TITLE_FALLBACK } from './route-node.mjs';
8
+ import { resolveNextNode, resolveFixRollbackDecision, resolveFixRollbackState, applyFixRollbackRound, resolveFixReturnNode, EXECUTE_FAMILY_NODE_IDS, TASK_SET_SIGNATURE_ALGO, taskSetSignature, parseTaskSetSignature, sameTaskSetSignature, taskSetSignatureVersionSkew, classifyFixReturnCause, normalizeHeading, FIX_SECTION_TITLE_FALLBACK, analyzeDependencyGraph, findParallelWriteConflicts } from './route-node.mjs';
9
9
 
10
10
  const command = process.argv[2] ?? 'verify';
11
11
  const nodeId = process.argv[3] ?? null;
@@ -590,48 +590,6 @@ function eligibleParallelBlocks(blocks, doneIds) {
590
590
  });
591
591
  }
592
592
 
593
- // 依赖图分析:对全部 <task> 块建依赖图(deps 边),Kahn 拓扑排序判环 + 缺失依赖收集。
594
- // 返回 { ids, depsById, missing: [{id, dep}], cyclic, cycleIds }(cycleIds = 拓扑排序无解的
595
- // 任务集合,含被环传递拖累的下游任务)。plan 出口波次校验与 subagent-execute 出口孤儿检测
596
- // 共用同一实现(单一语义:依赖图无环 + 依赖链可满足)。
597
- function analyzeDependencyGraph(blocks) {
598
- const parsed = blocks
599
- .map((block) => ({ block, attrs: taskOpeningAttrs(block) }))
600
- .filter((x) => x.attrs && x.attrs.id);
601
- const ids = new Set(parsed.map((x) => x.attrs.id));
602
- const depsById = new Map();
603
- const missing = [];
604
- for (const x of parsed) {
605
- const deps = [...new Set(taskDependsOn(x.block))];
606
- depsById.set(x.attrs.id, deps);
607
- for (const d of deps) {
608
- if (!ids.has(d)) missing.push({ id: x.attrs.id, dep: d });
609
- }
610
- }
611
- const indegree = new Map([...ids].map((id) => [id, 0]));
612
- const dependents = new Map([...ids].map((id) => [id, []]));
613
- for (const [id, deps] of depsById) {
614
- for (const d of deps) {
615
- if (!ids.has(d)) continue;
616
- indegree.set(id, indegree.get(id) + 1);
617
- dependents.get(d).push(id);
618
- }
619
- }
620
- let queue = [...ids].filter((id) => indegree.get(id) === 0);
621
- const sorted = [];
622
- while (queue.length > 0) {
623
- const n = queue.shift();
624
- sorted.push(n);
625
- for (const m of dependents.get(n)) {
626
- indegree.set(m, indegree.get(m) - 1);
627
- if (indegree.get(m) === 0) queue.push(m);
628
- }
629
- }
630
- const cyclic = sorted.length < ids.size;
631
- const cycleIds = cyclic ? [...ids].filter((id) => !sorted.includes(id)) : [];
632
- return { ids, depsById, missing, cyclic, cycleIds };
633
- }
634
-
635
593
  function printNext(protocol, node) {
636
594
  if (!node) {
637
595
  console.log('NEXT: done');
@@ -707,90 +665,6 @@ function missingRequiredSchemaEvidence(protocol, node, evidence) {
707
665
  return missing;
708
666
  }
709
667
 
710
- // 并行文件依赖检测——解析 TASK.md 中本趟可运行的 parallel=pending 任务的 read/write_files 声明,
711
- // 分两级返回:write∩write(写写绝对冲突,强判)与 read∩write(共享读写嫌疑,弱判——仅对彼此
712
- // 无显式 depends_on 关联的并行对探测,有显式关联=依赖已声明,跳过→合法拓扑零新增告警)。
713
- // 路径解析按声明实际内容(换行切分 → 分号二次切分 → trim → 滤空与 HTML 注释),不做扩展名
714
- // 白名单过滤——txt/log/无扩展名路径同等检出(链式重命名的 .txt 事故面闭合;与既有自动解析
715
- // 同源实现)。开标签属性解析与 workflow-state 路由共享 taskOpeningAttrs(属性序无关;不读块内文本)。
716
- async function findParallelWriteConflicts(changeDir) {
717
- const taskFile = path.join(changeDir, 'TASK.md');
718
- let text;
719
- try { text = await fs.readFile(taskFile, 'utf8'); } catch { return { writeConflicts: [], readWarnings: [] }; }
720
- const allBlocks = extractTaskBlocks(text);
721
- // 依赖资格收窄:仅统计「本趟可运行」的并行任务——deps ⊆ doneIds;
722
- // 等待后续趟次的并行任务(依赖未满足)与已交付任务不参与同趟冲突判定,
723
- // 使 A→B 同写路径的跨趟合法计划不再被首趟误拦(与路由谓词同一口径)。
724
- const doneIds = new Set(allBlocks
725
- .map((b) => taskOpeningAttrs(b))
726
- .filter((a) => a && a.id && a.status === 'done')
727
- .map((a) => a.id));
728
- const dependsOnOf = (b) => {
729
- const m = b.match(/<depends_on>([\s\S]*?)<\/depends_on>/);
730
- return m ? m[1].trim().split(/[,\s]+/).filter(Boolean) : [];
731
- };
732
- const blocks = allBlocks.filter((b) => {
733
- const a = taskOpeningAttrs(b);
734
- if (!a || !a.parallel || a.status !== 'pending') return false;
735
- return dependsOnOf(b).every((d) => doneIds.has(d));
736
- });
737
- // 路径解析与既有自动解析同源:剥 HTML 注释 → 换行切分 → 分号二次切分 → trim → 滤空
738
- // 路径归一化(CodeRabbit 采纳):分隔符统一 '/'、解 '.' 段(`./` / `a/./b`)、`..` 逃出项目根
739
- // 按越界处理(返回 null 不参与重叠比较)——`src/a.mjs` vs `src/./a.mjs` / `src\a.mjs` 变体不再
740
- // 绕过写写强判与读写弱判;与委托入口共用同一函数(两侧同语义)。
741
- const normalizeTaskPath = (raw) => {
742
- const p = String(raw).trim();
743
- if (p === '') return null;
744
- const segments = p.replace(/\\/g, '/').split('/').filter((s) => s !== '' && s !== '.');
745
- const out = [];
746
- for (const seg of segments) {
747
- if (seg === '..') {
748
- if (out.length === 0) return null; // 逃出项目根 → 越界(不参与比较)
749
- out.pop();
750
- } else {
751
- out.push(seg);
752
- }
753
- }
754
- return out.join('/');
755
- };
756
- const parsePaths = (matchText) => String(matchText ?? '')
757
- .replace(/<!--[\s\S]*?-->/g, '')
758
- .trim().split(/\s*\n\s*/).map((l) => l.trim()).filter(Boolean)
759
- .flatMap((l) => l.split(';')).map((l) => l.trim()).filter(Boolean)
760
- .map(normalizeTaskPath)
761
- .filter((p) => p !== null && p !== '');
762
- const perTask = [];
763
- for (const b of blocks) {
764
- const a = taskOpeningAttrs(b);
765
- if (!a || !a.id) continue;
766
- const wf = b.match(/<write_files>([\s\S]*?)<\/write_files>/);
767
- const rf = b.match(/<read_files>([\s\S]*?)<\/read_files>/);
768
- if (!wf && !rf) continue;
769
- perTask.push({
770
- id: a.id,
771
- deps: new Set(dependsOnOf(b)),
772
- writes: new Set(parsePaths(wf && wf[1])),
773
- reads: new Set(parsePaths(rf && rf[1])),
774
- });
775
- }
776
- const writeConflicts = [];
777
- const readWarnings = [];
778
- for (let i = 0; i < perTask.length; i++) {
779
- for (let j = i + 1; j < perTask.length; j++) {
780
- const overlap = [...perTask[i].writes].filter((f) => perTask[j].writes.has(f));
781
- if (overlap.length) writeConflicts.push({ a: perTask[i].id, b: perTask[j].id, files: overlap });
782
- // 读写弱判触发面:仅无显式 depends_on 关联的并行对(有显式关联=依赖已声明,跳过)
783
- const associated = perTask[i].deps.has(perTask[j].id) || perTask[j].deps.has(perTask[i].id);
784
- if (associated) continue;
785
- const readOverlap = [...perTask[i].reads].filter((f) => perTask[j].writes.has(f));
786
- if (readOverlap.length) readWarnings.push({ a: perTask[i].id, b: perTask[j].id, files: readOverlap });
787
- const readOverlap2 = [...perTask[j].reads].filter((f) => perTask[i].writes.has(f));
788
- if (readOverlap2.length) readWarnings.push({ a: perTask[j].id, b: perTask[i].id, files: readOverlap2 });
789
- }
790
- }
791
- return { writeConflicts, readWarnings };
792
- }
793
-
794
668
  function escapeRegExp(value) {
795
669
  return String(value).replace(/[|\\{}()[\]^$+?.]/gu, '\\$&');
796
670
  }
@@ -1619,108 +1493,130 @@ async function main() {
1619
1493
  // plan exit 校验 TASK 含 task 块和 verify 字段
1620
1494
  if (node.id === 'plan' && state.activeChange) {
1621
1495
  const taskFile = path.join(runRoot, '.specs', state.activeChange, 'TASK.md');
1622
- try {
1623
- const content = await fs.readFile(taskFile, 'utf8');
1624
- // <task> 块提取与属性解析统一走 task-parsing.mjs(开标签语义,属性序无关)
1625
- const taskList = extractTaskBlocks(content);
1626
- if (taskList.length === 0) {
1627
- console.error('BLOCKED: TASK.md 无 <task> 块');
1628
- process.exit(1);
1629
- }
1630
- const missingVerify = taskList.filter(b => !/<verify>/.test(b));
1631
- if (missingVerify.length > 0) {
1632
- console.error('BLOCKED: TASK.md 中 ' + missingVerify.length + ' 个 task 缺 <verify> 字段');
1633
- process.exit(1);
1634
- }
1635
- // 波次散文一致性检测: 波次散文一致性检测(WARN 渐进)——## 波次划分 的 Wave 行任务带 [P] 标记
1636
- // (并行语义)但 XML 任务无 parallel="true" → WARN(散文与机器路由依据不一致,以任务
1637
- // 标记为准)。容错:无并行语义的 Wave 行不参与比对;解析不到波次段跳过(不误报)。
1638
- const waveSection = content.match(/##\s*波次划分\s*\n([\s\S]*?)(?=\n##\s|\n---|\Z)/);
1639
- if (waveSection) {
1640
- const proseParallelIds = [];
1641
- for (const line of waveSection[1].split('\n')) {
1642
- if (!/(Wave|\d+\s*波|parallel|并行)/i.test(line)) continue; // 无并行语义行跳过
1643
- for (const m of line.matchAll(/([A-Z][A-Z0-9-]*)\[P\]/g)) proseParallelIds.push(m[1]);
1496
+ // 读文件是唯一需要容错的动作(TASK.md 缺失 → 无内容可判,判据段不适用,保持既有语义);
1497
+ // 判据段独立成层——判据自身抛错不得被空 catch 吞掉:空 catch 会让整段文件依赖门禁(含既有
1498
+ // 写写强判 BLOCK)静默失效,与「未验证 ≠ 通过」相悖。命中即显式报出原因并按 fail-closed 拒绝。
1499
+ let content = null;
1500
+ try { content = await fs.readFile(taskFile, 'utf8'); } catch { content = null; }
1501
+ if (content !== null) {
1502
+ try {
1503
+ // <task> 块提取与属性解析统一走 task-parsing.mjs(开标签语义,属性序无关)
1504
+ const taskList = extractTaskBlocks(content);
1505
+ if (taskList.length === 0) {
1506
+ console.error('BLOCKED: TASK.md 无 <task> 块');
1507
+ process.exit(1);
1644
1508
  }
1645
- if (proseParallelIds.length > 0) {
1646
- const xmlParallelIds = taskList
1647
- .filter(b => { const a = taskOpeningAttrs(b); return a && a.parallel; })
1648
- .map(b => (taskOpeningAttrs(b) || {}).id)
1649
- .filter(Boolean);
1650
- const missing = proseParallelIds.filter(id => !xmlParallelIds.includes(id));
1651
- if (missing.length > 0) {
1652
- if (isNewChange(state)) {
1653
- console.error('BLOCKED: 波次散文标记任务为并行([P])但任务无 parallel="true"(新 change 强制散文与任务标记一致);恢复: 对齐散文或任务标记');
1509
+ const missingVerify = taskList.filter(b => !/<verify>/.test(b));
1510
+ if (missingVerify.length > 0) {
1511
+ console.error('BLOCKED: TASK.md 中 ' + missingVerify.length + ' 个 task 缺 <verify> 字段');
1654
1512
  process.exit(1);
1655
1513
  }
1656
- console.error('WARN: 波次散文标记为并行([P])但任务无 parallel="true"——散文与任务标记不一致(以任务标记为准): ' + missing.join(', '));
1514
+ // 波次散文一致性检测: 波次散文一致性检测(WARN 渐进)——## 波次划分 的 Wave 行任务带 [P] 标记
1515
+ // (并行语义)但 XML 任务无 parallel="true" → WARN(散文与机器路由依据不一致,以任务
1516
+ // 标记为准)。容错:无并行语义的 Wave 行不参与比对;解析不到波次段跳过(不误报)。
1517
+ const waveSection = content.match(/##\s*波次划分\s*\n([\s\S]*?)(?=\n##\s|\n---|\Z)/);
1518
+ if (waveSection) {
1519
+ const proseParallelIds = [];
1520
+ for (const line of waveSection[1].split('\n')) {
1521
+ if (!/(Wave|\d+\s*波|parallel|并行)/i.test(line)) continue; // 无并行语义行跳过
1522
+ for (const m of line.matchAll(/([A-Z][A-Z0-9-]*)\[P\]/g)) proseParallelIds.push(m[1]);
1523
+ }
1524
+ if (proseParallelIds.length > 0) {
1525
+ const xmlParallelIds = taskList
1526
+ .filter(b => { const a = taskOpeningAttrs(b); return a && a.parallel; })
1527
+ .map(b => (taskOpeningAttrs(b) || {}).id)
1528
+ .filter(Boolean);
1529
+ const missing = proseParallelIds.filter(id => !xmlParallelIds.includes(id));
1530
+ if (missing.length > 0) {
1531
+ if (isNewChange(state)) {
1532
+ console.error('BLOCKED: 波次散文标记任务为并行([P])但任务无 parallel="true"(新 change 强制散文与任务标记一致);恢复: 对齐散文或任务标记');
1533
+ process.exit(1);
1534
+ }
1535
+ console.error('WARN: 波次散文标记为并行([P])但任务无 parallel="true"——散文与任务标记不一致(以任务标记为准): ' + missing.join(', '));
1536
+ }
1657
1537
  }
1658
1538
  }
1659
- }
1660
- // 波次分组校验重定义(依赖图校验决策 · 混排合法化):原「并行块必须单个连续且居首/尾」形态约束废除——
1661
- // 串行任务位置不再受限,串→并→串 / 并→串→并 / 多波混合均合法(多趟循环路由按依赖拓扑分趟)。
1662
- // 改为依赖图校验:① 全部任务建依赖图(deps 边)做 Kahn 拓扑排序判环——有环即规划结构性死锁;
1663
- // ② 全部引用的任务 id 必须存在(无环图下「每个 parallel 任务的全部传递依赖存在且非环」
1664
- // ⟺ 直接引用都存在)。违规分级:新 change BLOCKED(含「依赖环」/缺失依赖明细 + depends_on
1665
- // 调整恢复指引);旧 change 渐进 WARN 不阻断。波次散文一致性检测保留不动(与形态约束正交的既有独立检测,维持不变)。
1666
- const depGraph = analyzeDependencyGraph(taskList);
1667
- if (depGraph.cyclic || depGraph.missing.length > 0) {
1668
- const detail = depGraph.cyclic
1669
- ? '依赖环(拓扑排序无解,涉及任务: ' + depGraph.cycleIds.join(', ') + ')'
1670
- : '依赖不存在的任务: ' + depGraph.missing.map((m) => m.id + '→' + m.dep).join(', ');
1671
- const guide = ';恢复: 调整任务 depends_on——移除成环引用或改为真实存在的任务 id 后重试';
1672
- if (isNewChange(state)) {
1673
- console.error('BLOCKED: TASK.md ' + detail + '——依赖图不可满足(任务的依赖链必须存在且无环)' + guide);
1674
- process.exit(1);
1539
+ // 波次分组校验重定义(依赖图校验决策 · 混排合法化):原「并行块必须单个连续且居首/尾」形态约束废除——
1540
+ // 串行任务位置不再受限,串→并→串 / 并→串→并 / 多波混合均合法(多趟循环路由按依赖拓扑分趟)。
1541
+ // 改为依赖图校验:① 全部任务建依赖图(deps 边)做 Kahn 拓扑排序判环——有环即规划结构性死锁;
1542
+ // ② 全部引用的任务 id 必须存在(无环图下「每个 parallel 任务的全部传递依赖存在且非环」
1543
+ // ⟺ 直接引用都存在)。违规分级:新 change BLOCKED(含「依赖环」/缺失依赖明细 + depends_on
1544
+ // 调整恢复指引);旧 change 渐进 WARN 不阻断。波次散文一致性检测保留不动(与形态约束正交的既有独立检测,维持不变)。
1545
+ const depGraph = analyzeDependencyGraph(taskList);
1546
+ if (depGraph.cyclic || depGraph.missing.length > 0) {
1547
+ const detail = depGraph.cyclic
1548
+ ? '依赖环(拓扑排序无解,涉及任务: ' + depGraph.cycleIds.join(', ') + ')'
1549
+ : '依赖不存在的任务: ' + depGraph.missing.map((m) => m.id + '→' + m.dep).join(', ');
1550
+ const guide = ';恢复: 调整任务 depends_on——移除成环引用或改为真实存在的任务 id 后重试';
1551
+ if (isNewChange(state)) {
1552
+ console.error('BLOCKED: TASK.md ' + detail + '——依赖图不可满足(任务的依赖链必须存在且无环)' + guide);
1553
+ process.exit(1);
1554
+ }
1555
+ console.error('WARN: TASK.md ' + detail + '——依赖图不可满足(旧 change 渐进不阻断)' + guide);
1675
1556
  }
1676
- console.error('WARN: TASK.md ' + detail + '——依赖图不可满足(旧 change 渐进不阻断)' + guide);
1677
- }
1678
- // 伪并行检测(真实载体验证暴露的设计盲区兜底):如果一个标记为并行的任务只写测试文件
1679
- // 而无任何生产代码文件,它很可能隐式依赖某个实现类并行任务的产出(如测试 import
1680
- // 尚未存在的函数)。这种"伪并行"在多趟路由下会导致委托后测试失败。
1681
- // 启发式:并行任务的 write_files 全部匹配 tests/ 或 test_ 前缀 → 视为疑似伪并行。
1682
- // WARN 渐进不阻断——由执行者判断是否真独立(纯测试基础设施改动可合法全测试面)。
1683
- const testOnlyParallelIds = [];
1684
- for (const block of taskList) {
1685
- const attrs = taskOpeningAttrs(block);
1686
- if (!attrs || !attrs.parallel || attrs.status !== 'pending') continue;
1687
- const wfMatch = block.match(/<write_files>([\s\S]*?)<\/write_files>/);
1688
- if (!wfMatch) continue;
1689
- // 分号容错:与 workflow-handoff.mjs 自动解析同源实现(分号容错双点内联,与 workflow-handoff.mjs 同源互锚)——
1690
- // 换行切分后逐段按 ';' 二次切分、trim、滤空与 HTML 注释行(路径含分号的极端形态不支持,须换行书写)
1691
- const blockContent = wfMatch[1].replace(/<!--[\s\S]*?-->/g, '');
1692
- const filePaths = blockContent.trim().split(/\s*\n\s*/).map(l => l.trim()).filter(Boolean)
1693
- .flatMap(l => l.split(';')).map(l => l.trim()).filter(Boolean);
1694
- if (filePaths.length === 0) continue;
1695
- const prodFiles = filePaths.filter(f => !/(?:^|[\/\\])(?:__tests__\/|test_|tests?\/)|\.(?:test|spec)\.(?:mjs|js|jsx|ts|tsx|cjs)$/.test(f));
1696
- if (prodFiles.length === 0) {
1697
- testOnlyParallelIds.push(attrs.id || 'unknown');
1557
+ // 伪并行检测(真实载体验证暴露的设计盲区兜底):如果一个标记为并行的任务只写测试文件
1558
+ // 而无任何生产代码文件,它很可能隐式依赖某个实现类并行任务的产出(如测试 import
1559
+ // 尚未存在的函数)。这种"伪并行"在多趟路由下会导致委托后测试失败。
1560
+ // 启发式:并行任务的 write_files 全部匹配 tests/ 或 test_ 前缀 → 视为疑似伪并行。
1561
+ // WARN 渐进不阻断——由执行者判断是否真独立(纯测试基础设施改动可合法全测试面)。
1562
+ const testOnlyParallelIds = [];
1563
+ for (const block of taskList) {
1564
+ const attrs = taskOpeningAttrs(block);
1565
+ if (!attrs || !attrs.parallel || attrs.status !== 'pending') continue;
1566
+ const wfMatch = block.match(/<write_files>([\s\S]*?)<\/write_files>/);
1567
+ if (!wfMatch) continue;
1568
+ // 分号容错:与 workflow-handoff.mjs 自动解析同源实现(分号容错双点内联,与 workflow-handoff.mjs 同源互锚)——
1569
+ // 换行切分后逐段按 ';' 二次切分、trim、滤空与 HTML 注释行(路径含分号的极端形态不支持,须换行书写)
1570
+ const blockContent = wfMatch[1].replace(/<!--[\s\S]*?-->/g, '');
1571
+ const filePaths = blockContent.trim().split(/\s*\n\s*/).map(l => l.trim()).filter(Boolean)
1572
+ .flatMap(l => l.split(';')).map(l => l.trim()).filter(Boolean);
1573
+ if (filePaths.length === 0) continue;
1574
+ const prodFiles = filePaths.filter(f => !/(?:^|[\/\\])(?:__tests__\/|test_|tests?\/)|\.(?:test|spec)\.(?:mjs|js|jsx|ts|tsx|cjs)$/.test(f));
1575
+ if (prodFiles.length === 0) {
1576
+ testOnlyParallelIds.push(attrs.id || 'unknown');
1577
+ }
1698
1578
  }
1699
- }
1700
- if (testOnlyParallelIds.length > 0) {
1701
- console.error('WARN: 伪并行检测——以下并行任务仅写测试文件而无生产代码文件: '
1702
- + testOnlyParallelIds.join(', ')
1703
- + '。测试通常依赖实现产出的符号,可能存在隐式依赖;建议添加 depends_on 声明或合并为垂直切片');
1704
- }
1705
- // 并行文件依赖检测前移(触发面):write∩write 写写强判(新 change BLOCKED / 旧 change
1706
- // WARN 渐进,与依赖环分级同先例)+ read∩write 读写弱判(仅无显式 depends_on 关联的并行对;
1707
- // WARN 提示级,新/旧均不 BLOCK——渐进提示)。与委托前既有拦截并存(委托前为第二道写写锚,
1708
- // 行为与消息保持既有语义不变)。
1709
- const { writeConflicts, readWarnings } = await findParallelWriteConflicts(path.join(runRoot, '.specs', state.activeChange));
1710
- if (writeConflicts.length > 0) {
1711
- const detail = writeConflicts.map((c) => `${c.a}×${c.b}(${c.files.join(',')})`).join('; ');
1712
- const guide = ';恢复: 补显式 depends_on 或拆为串行任务后重试';
1713
- if (isNewChange(state)) {
1714
- console.error('BLOCKED: TASK.md 并行任务 write_files 重叠(写写冲突,同波次并行会竞态覆盖): ' + detail + guide);
1715
- process.exit(1);
1579
+ if (testOnlyParallelIds.length > 0) {
1580
+ console.error('WARN: 伪并行检测——以下并行任务仅写测试文件而无生产代码文件: '
1581
+ + testOnlyParallelIds.join(', ')
1582
+ + '。测试通常依赖实现产出的符号,可能存在隐式依赖;建议添加 depends_on 声明或合并为垂直切片');
1716
1583
  }
1717
- console.error('WARN: TASK.md 并行任务 write_files 重叠(写写冲突,建议补显式 depends_on 或拆为串行任务): ' + detail + guide);
1718
- }
1719
- if (readWarnings.length > 0) {
1720
- console.error('WARN: TASK.md 并行任务 read∩write 隐式依赖嫌疑(一方读取对方写路径,建议补显式 depends_on 声明): '
1721
- + readWarnings.map((c) => `${c.a}×${c.b}(${c.files.join(',')})`).join('; '));
1584
+ // 并行文件依赖检测前移(触发面):write∩write 写写强判(新 change BLOCKED / 旧 change
1585
+ // WARN 渐进,与依赖环分级同先例)+ read∩write 读写弱判(仅无显式 depends_on 关联的并行对;
1586
+ // WARN 提示级,新/旧均不 BLOCK——渐进提示)+ 同文件跨任务且无依赖路径(未完成任务写入面
1587
+ // 重叠而两任务间无依赖路径——新 change BLOCKED / 旧 change WARN 渐进;串行拆分同样命中,
1588
+ // 修复任务族不参与,族语义见 route-node 判定块注释)。与委托前既有拦截并存(委托前为第二道
1589
+ // 写写锚,行为与消息保持既有语义不变)。
1590
+ const { writeConflicts, readWarnings, crossTaskConflicts } = await findParallelWriteConflicts(path.join(runRoot, '.specs', state.activeChange));
1591
+ if (writeConflicts.length > 0) {
1592
+ const detail = writeConflicts.map((c) => `${c.a}×${c.b}(${c.files.join(',')})`).join('; ');
1593
+ const guide = ';恢复: 补显式 depends_on 或拆为串行任务后重试';
1594
+ if (isNewChange(state)) {
1595
+ console.error('BLOCKED: TASK.md 并行任务 write_files 重叠(写写冲突,同波次并行会竞态覆盖): ' + detail + guide);
1596
+ process.exit(1);
1597
+ }
1598
+ console.error('WARN: TASK.md 并行任务 write_files 重叠(写写冲突,建议补显式 depends_on 或拆为串行任务): ' + detail + guide);
1599
+ }
1600
+ if (crossTaskConflicts.length > 0) {
1601
+ const detail = crossTaskConflicts.map((c) => `${c.a}×${c.b}(${c.files.join(',')})`).join('; ');
1602
+ const guide = ';恢复: 补显式 depends_on 或合并为一个任务后重试';
1603
+ if (isNewChange(state)) {
1604
+ console.error('BLOCKED: TASK.md 同文件跨任务且无依赖路径: ' + detail + guide);
1605
+ process.exit(1);
1606
+ }
1607
+ console.error('WARN: TASK.md 同文件跨任务且无依赖路径(建议补显式 depends_on 或合并为一个任务): ' + detail + guide);
1608
+ }
1609
+ if (readWarnings.length > 0) {
1610
+ console.error('WARN: TASK.md 并行任务 read∩write 隐式依赖嫌疑(一方读取对方写路径,建议补显式 depends_on 声明): '
1611
+ + readWarnings.map((c) => `${c.a}×${c.b}(${c.files.join(',')})`).join('; '));
1612
+ }
1613
+ } catch (judgeError) {
1614
+ console.error('BLOCKED: TASK.md 文件依赖判据未执行: '
1615
+ + (judgeError && judgeError.message ? judgeError.message : String(judgeError))
1616
+ + '——门禁无法完成校验,按 fail-closed 拒绝通过(未验证 ≠ 通过)');
1617
+ process.exit(1);
1722
1618
  }
1723
- } catch {}
1619
+ }
1724
1620
  }
1725
1621
  // review exit 校验 REVIEW 含实质内容 + 发现区条目处置状态结构级校验
1726
1622
  if (node.id === 'review' && state.activeChange) {
@@ -1851,6 +1747,12 @@ async function main() {
1851
1747
  process.exit(1);
1852
1748
  }
1853
1749
  }
1750
+ // execute 出口空退出豁免(M6 收窄)——豁免仅适用于「无任何串行任务」的全并行 change;
1751
+ // 含串行任务(parallel!=="true",缺省串行——与 task-parsing.mjs 同语义)时豁免不生效,
1752
+ // 后续产物校验照常执行(陈旧 emptyExitApproved 不得静默放行)。
1753
+ // 判据单一来源:evidence 谓词只在此处求值一次,execute 出口块与 M6 共用(L-067)。
1754
+ const executeEmptyExitApproved = node.id === 'execute' && !!(state.evidence?.execute?.emptyExitApproved);
1755
+ let executeEmptyExitExempt = false;
1854
1756
  // execute 出口校验——统一委托后所有 done 任务需 handoff(越俎代庖检测覆盖串行/并行)
1855
1757
  if (node.id === 'execute' && state.activeChange) {
1856
1758
  const taskFile = path.join(runRoot, '.specs', state.activeChange, 'TASK.md');
@@ -1867,9 +1769,15 @@ async function main() {
1867
1769
  // 串行 pending → BLOCKED(execute 任务没做完)——emptyExitApproved 不豁免串行 pending:
1868
1770
  // 豁免语义是"全 parallel 无串行可做时空退出";存在未完成串行任务时豁免不应生效
1869
1771
  // (防规划错误被豁免掩盖;豁免仅作用于后续产物校验跳过,审计提示保留)
1870
- const emptyExitApproved = !!(state.evidence?.execute && state.evidence.execute.emptyExitApproved);
1871
- if (emptyExitApproved) {
1872
- console.error('EMPTY-EXIT: execute 空退出豁免已生效(evidence.execute.emptyExitApproved)——审计记录:该 change 在无串行任务时显式豁免空退出');
1772
+ if (executeEmptyExitApproved) {
1773
+ // M6 前置条件(收窄):TASK 存在任一串行任务块(parallel!=="true",含缺省)时豁免不生效,
1774
+ // 无论该串行任务 pending 还是 done——陈旧标记不得跳过产物/摘要校验。
1775
+ if (tasks.some(t => !t.parallel)) {
1776
+ console.error('EMPTY-EXIT 未生效:本 change 含串行任务,豁免仅适用于全并行 change');
1777
+ } else {
1778
+ executeEmptyExitExempt = true;
1779
+ console.error('EMPTY-EXIT: execute 空退出豁免已生效(evidence.execute.emptyExitApproved)——审计记录:该 change 在无串行任务时显式豁免空退出');
1780
+ }
1873
1781
  }
1874
1782
  // serialPending 收窄为「可运行串行」(出口拦截集合收窄):仅 deps ⊆ doneIds 的
1875
1783
  // 未完成串行计入拦截——deps 未满足的串行 pending 是等后续波次的合法中间态,放行由多趟
@@ -2405,9 +2313,15 @@ async function main() {
2405
2313
  console.error('BLOCKED: missing Output Schema evidence: ' + missingSchemaEvidence.join(', '));
2406
2314
  process.exit(1);
2407
2315
  }
2408
- // M6: execute 显式空退出豁免——evidence.execute.emptyExitApproved 时跳过产物校验(全 parallel 无 SUMMARY 属预期)
2409
- const missingArtifacts = (node.id === 'execute' && state.evidence?.execute?.emptyExitApproved)
2410
- ? [] : await missingRequiredArtifacts(protocol, node, state.activeChange);
2316
+ // M6: execute 显式空退出豁免——仅当豁免活性成立(executeEmptyExitApproved 且 TASK 无任何
2317
+ // 串行任务)时跳过产物校验(全 parallel 无 SUMMARY 属预期);含串行任务的 change 豁免不生效,
2318
+ // 照常校验,不得静默放行。生效时追加被跳过项清单(EMPTY-EXIT-SKIPPED)。
2319
+ const checkedArtifacts = await missingRequiredArtifacts(protocol, node, state.activeChange);
2320
+ let missingArtifacts = checkedArtifacts;
2321
+ if (executeEmptyExitApproved && executeEmptyExitExempt) {
2322
+ console.error('EMPTY-EXIT-SKIPPED: ' + (checkedArtifacts.length > 0 ? checkedArtifacts.join(', ') : '(无缺失产物项)'));
2323
+ missingArtifacts = [];
2324
+ }
2411
2325
  if (missingArtifacts.length > 0) {
2412
2326
  console.error('BLOCKED: missing Output Schema artifacts: ' + missingArtifacts.join(', '));
2413
2327
  process.exit(1);
@@ -683,7 +683,7 @@ async function main() {
683
683
  console.log(JSON.stringify({
684
684
  activeChange: state.activeChange,
685
685
  handoffRequests: handoff.handoffRequests || {},
686
- handoffResults: handoff.handoffResult || {}
686
+ handoffResult: handoff.handoffResult || {}
687
687
  }, null, 2));
688
688
  return;
689
689
  }