@aibyzero/cm-workflow 0.16.3 → 0.16.5

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 (177) hide show
  1. package/.codex-plugin/plugin.json +1 -1
  2. package/AGENTS.md +8 -0
  3. package/CHANGELOG.md +59 -0
  4. package/README.md +55 -3
  5. package/VERSION +1 -1
  6. package/docs/installation.md +21 -1
  7. package/docs/js-workflow-control.md +245 -33
  8. package/docs/next-steps.md +14 -24
  9. package/docs/runtime-failover.md +1 -1
  10. package/package.json +1 -1
  11. package/runtime/js/cm-ai/accepted-fix.mjs +23 -5
  12. package/runtime/js/cm-ai/bootstrap-feature.mjs +15 -0
  13. package/runtime/js/cm-ai/claude-review-stream.mjs +30 -0
  14. package/runtime/js/cm-ai/cm-ai-admission.mjs +116 -41
  15. package/runtime/js/cm-ai/cm-ai-context-refresh.mjs +3 -2
  16. package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +137 -22
  17. package/runtime/js/cm-ai/cm-ai-learning-handoff-writer.mjs +11 -9
  18. package/runtime/js/cm-ai/cm-ai-learning-writer.mjs +22 -5
  19. package/runtime/js/cm-ai/cm-ai-qa-log.mjs +180 -53
  20. package/runtime/js/cm-ai/cm-ai-run-finalizer.mjs +2 -1
  21. package/runtime/js/cm-ai/codex-review-adapter.mjs +24 -4
  22. package/runtime/js/cm-ai/developer-adapter.mjs +6 -2
  23. package/runtime/js/cm-ai/diagnostic-reason.mjs +10 -0
  24. package/runtime/js/cm-ai/drive-bootstrap.mjs +305 -0
  25. package/runtime/js/cm-ai/drive-core.mjs +39 -7
  26. package/runtime/js/cm-ai/durable-runner-state.mjs +307 -53
  27. package/runtime/js/cm-ai/effect-abandon-log.mjs +19 -0
  28. package/runtime/js/cm-ai/effect-contract.mjs +44 -2
  29. package/runtime/js/cm-ai/execution-store-limits.mjs +18 -0
  30. package/runtime/js/cm-ai/execution-store.mjs +6 -4
  31. package/runtime/js/cm-ai/fix-code-association.mjs +171 -18
  32. package/runtime/js/cm-ai/host-bootstrap.mjs +68 -21
  33. package/runtime/js/cm-ai/host-conversation-execution.mjs +16 -4
  34. package/runtime/js/cm-ai/host-handoff.mjs +13 -6
  35. package/runtime/js/cm-ai/host-qa-executor.mjs +21 -7
  36. package/runtime/js/cm-ai/host-qa-fix-owner.mjs +4 -4
  37. package/runtime/js/cm-ai/host-qa-policy.mjs +16 -7
  38. package/runtime/js/cm-ai/host-session.mjs +20 -5
  39. package/runtime/js/cm-ai/host-tool-bridge.mjs +1 -1
  40. package/runtime/js/cm-ai/host-workflow-capabilities.mjs +13 -4
  41. package/runtime/js/cm-ai/host.mjs +1 -1
  42. package/runtime/js/cm-ai/launch-mismatch.mjs +42 -0
  43. package/runtime/js/cm-ai/log-rows.mjs +21 -0
  44. package/runtime/js/cm-ai/project-qa-gate.mjs +84 -0
  45. package/runtime/js/cm-ai/provider-review-observation.mjs +53 -9
  46. package/runtime/js/cm-ai/qa-config-revision.mjs +44 -10
  47. package/runtime/js/cm-ai/review-abandon-log.mjs +21 -0
  48. package/runtime/js/cm-ai/review-package.mjs +427 -31
  49. package/runtime/js/cm-ai/review-runner.mjs +47 -1
  50. package/runtime/js/cm-ai/reviewed-deliveries.mjs +97 -0
  51. package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +104 -10
  52. package/runtime/js/cm-ai/reviewed-evidence-supersession-record.mjs +42 -3
  53. package/runtime/js/cm-ai/specification-material.mjs +154 -12
  54. package/runtime/js/cm-ai/task-commit.mjs +2 -2
  55. package/runtime/js/cm-ai/task-runner.mjs +502 -65
  56. package/runtime/js/cm-ai/worker-claude-developer.mjs +16 -7
  57. package/runtime/js/cm-fix/execution.mjs +109 -25
  58. package/runtime/js/cm-fix/host-review.mjs +7 -3
  59. package/runtime/js/cm-fix/host.mjs +3 -1
  60. package/runtime/js/cm-fix/progress.mjs +1 -0
  61. package/runtime/js/cm-fix/protected-edits.mjs +15 -4
  62. package/runtime/js/cm-fix/qa-source.mjs +6 -4
  63. package/runtime/js/cm-prd/analysis.mjs +2 -1
  64. package/runtime/js/cm-prd/change.mjs +28 -10
  65. package/runtime/js/cm-prd/draft.mjs +5 -2
  66. package/runtime/js/cm-prd/review-preparation.mjs +10 -3
  67. package/runtime/js/cm-prd/review-publication.mjs +4 -2
  68. package/runtime/js/cm-prd/self-check.mjs +6 -3
  69. package/runtime/js/cm-prd/summary.mjs +6 -2
  70. package/runtime/js/cm-prd/validation-reason.mjs +20 -0
  71. package/runtime/js/spec-task-line.mjs +117 -0
  72. package/runtime/js/specs-status.mjs +14 -3
  73. package/scripts/cm-ai-abandon-effect-position.test.mjs +201 -0
  74. package/scripts/cm-ai-admission.mjs +19 -10
  75. package/scripts/cm-ai-admission.test.mjs +65 -1
  76. package/scripts/cm-ai-batch-drive.mjs +93 -21
  77. package/scripts/cm-ai-batch-drive.test.mjs +171 -3
  78. package/scripts/cm-ai-batch-host.mjs +37 -13
  79. package/scripts/cm-ai-batch-host.test.mjs +26 -0
  80. package/scripts/cm-ai-batch-run.mjs +33 -10
  81. package/scripts/cm-ai-batch-run.test.mjs +56 -5
  82. package/scripts/cm-ai-bootstrap-driver-preflight.test.mjs +45 -0
  83. package/scripts/cm-ai-bootstrap-flow.test.mjs +158 -0
  84. package/scripts/cm-ai-bootstrap-merge.test.mjs +45 -0
  85. package/scripts/cm-ai-bootstrap.test.mjs +99 -7
  86. package/scripts/cm-ai-conversation-entry-ops.test.mjs +82 -2
  87. package/scripts/cm-ai-develop-driver-gaps.test.mjs +822 -0
  88. package/scripts/cm-ai-drive-bootstrap-rules.test.mjs +468 -0
  89. package/scripts/cm-ai-drive-timeout.test.mjs +17 -0
  90. package/scripts/cm-ai-drive.mjs +480 -47
  91. package/scripts/cm-ai-drive.test.mjs +247 -10
  92. package/scripts/cm-ai-fix-later-delivery.test.mjs +383 -0
  93. package/scripts/cm-ai-host.mjs +89 -25
  94. package/scripts/cm-ai-host.test.mjs +274 -12
  95. package/scripts/cm-ai-launch-diagnostics.test.mjs +142 -0
  96. package/scripts/cm-ai-multi-root.test.mjs +9 -3
  97. package/scripts/cm-ai-project-qa-gate.test.mjs +308 -0
  98. package/scripts/cm-ai-qa-config-revision.test.mjs +166 -15
  99. package/scripts/cm-ai-qa-fingerprint-config.test.mjs +157 -0
  100. package/scripts/cm-ai-qa-fix-cross-session.test.mjs +27 -2
  101. package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +400 -0
  102. package/scripts/cm-ai-review-drift-precedence.test.mjs +90 -0
  103. package/scripts/cm-ai-review-failure.test.mjs +917 -0
  104. package/scripts/cm-ai-review-timeout-config.test.mjs +29 -7
  105. package/scripts/cm-ai-review-timeout.test.mjs +199 -4
  106. package/scripts/cm-ai-run.mjs +160 -60
  107. package/scripts/cm-ai-run.test.mjs +4 -3
  108. package/scripts/cm-ai-runner-error-code-regression.test.mjs +219 -0
  109. package/scripts/cm-ai-selection-guard.test.mjs +100 -0
  110. package/scripts/cm-ai-session-chain.test.mjs +7 -3
  111. package/scripts/cm-ai-spec-rebind.test.mjs +481 -0
  112. package/scripts/cm-ai-supersede.test.mjs +571 -17
  113. package/scripts/cm-ai-verification-gate.test.mjs +2 -1
  114. package/scripts/cm-capability-gate.test.mjs +21 -2
  115. package/scripts/cm-check-drive.mjs +4 -3
  116. package/scripts/cm-check-drive.test.mjs +17 -1
  117. package/scripts/cm-check-entry.mjs +13 -2
  118. package/scripts/cm-check-host.mjs +2 -2
  119. package/scripts/cm-check-host.test.mjs +57 -1
  120. package/scripts/cm-check-runtime.sh +16 -7
  121. package/scripts/cm-claude-developer-worker.test.mjs +43 -2
  122. package/scripts/cm-claude-probe.test.mjs +9 -1
  123. package/scripts/cm-claude-review-stream.test.mjs +68 -0
  124. package/scripts/cm-claude-worker.test.mjs +11 -4
  125. package/scripts/cm-codex-developer-worker.test.mjs +4 -2
  126. package/scripts/cm-failover.mjs +8 -8
  127. package/scripts/cm-fix-abandon.test.mjs +123 -5
  128. package/scripts/cm-fix-cause-package.test.mjs +2 -0
  129. package/scripts/cm-fix-drive.mjs +45 -13
  130. package/scripts/cm-fix-drive.test.mjs +36 -1
  131. package/scripts/cm-fix-host.mjs +9 -6
  132. package/scripts/cm-fix-review-budget.test.mjs +141 -0
  133. package/scripts/cm-fixture-process-cleanup.test.mjs +95 -0
  134. package/scripts/cm-host-check.test.mjs +6 -3
  135. package/scripts/cm-host-qa-executor.test.mjs +192 -17
  136. package/scripts/cm-host-session-diagnostic.test.mjs +10 -0
  137. package/scripts/cm-interactive-qa-diagnostic.test.mjs +53 -0
  138. package/scripts/cm-log-event.mjs +17 -0
  139. package/scripts/cm-log-event.test.mjs +31 -0
  140. package/scripts/cm-prd-completion.test.mjs +105 -2
  141. package/scripts/cm-prd-draft.test.mjs +14 -0
  142. package/scripts/cm-prd-drive.mjs +13 -7
  143. package/scripts/cm-prd-drive.test.mjs +10 -0
  144. package/scripts/cm-prd-gate-diagnostic.test.mjs +100 -0
  145. package/scripts/cm-prd-review-gate.mjs +126 -81
  146. package/scripts/cm-prd-review-gate.test.mjs +105 -1
  147. package/scripts/cm-prd-review-preparation.test.mjs +15 -0
  148. package/scripts/cm-prd-review-publication.test.mjs +6 -0
  149. package/scripts/cm-prd-self-check.test.mjs +6 -0
  150. package/scripts/cm-prd-summary.test.mjs +40 -0
  151. package/scripts/cm-review-dependency-snapshot.test.mjs +15 -0
  152. package/scripts/cm-review-inventory.test.mjs +253 -1
  153. package/scripts/cm-spec-manifest.mjs +28 -10
  154. package/scripts/cm-spec-manifest.test.mjs +8 -4
  155. package/scripts/cm-spec-task-line.test.mjs +138 -0
  156. package/scripts/cm-specs-status.test.mjs +31 -1
  157. package/scripts/cm-task-gate.mjs +18 -10
  158. package/scripts/cm-task-gate.py +1 -1
  159. package/scripts/cm-test-branch-impact.test.mjs +6 -3
  160. package/scripts/fixtures/claude-review-process.mjs +1 -0
  161. package/scripts/fixtures/process-cleanup.mjs +99 -0
  162. package/scripts/test-cm-log-event.py +2 -0
  163. package/scripts/test-cm-prd-review-gate.py +2 -1
  164. package/scripts/test-npm-install.py +1 -1
  165. package/scripts/test-scan-public-safety.py +1 -1
  166. package/scripts/test-shell-compat.sh +67 -0
  167. package/scripts/test-spec-manifest.py +16 -8
  168. package/scripts/test-task-gate.py +2 -2
  169. package/scripts/test-workflow-config.py +1 -0
  170. package/scripts/validate-public-repo.py +1 -0
  171. package/skills/cm-ai/references/N1-init.md +1 -1
  172. package/skills/cm-ai/references/js-host.md +264 -40
  173. package/skills/cm-check/SKILL.md +6 -1
  174. package/skills/cm-check/references/js-host.md +3 -3
  175. package/skills/cm-fix/references/js-host.md +22 -1
  176. package/skills/cm-prd/references/js-change-recovery.md +30 -0
  177. package/skills/cm-prd/references/js-host.md +6 -0
@@ -1,22 +1,14 @@
1
1
  # 接下来要做的事
2
2
 
3
- 写于 2026-09-22,0.16.2 发布之后。按优先级排,每条写清:为什么要做、做完是什么样、动手前要先弄清什么。
3
+ 写于 2026-09-22,2026-09-26 在 0.16.3 发布后更新。按优先级排,每条写清:为什么要做、做完是什么样、动手前要先弄清什么。
4
4
 
5
5
  ## 现状
6
6
 
7
- - npm 上是 **0.16.2**。
8
- - 主干已有这些改动,**还没发布**:
9
- - #114 半路死掉的运行让出任务编号(审查过的仍占住)
10
- - #115 cm-fix 驾驶员 `scripts/cm-fix-drive.mjs`
11
- - #116 补上 `auto_fix: never` 和视觉证据 `video` 两条测试
12
- - #117 整理后续工作文档
13
- - #118 + #120 cm-fix 在签授权前记下每个接手会话,并修好交叉审查发现的两处缺陷
14
- - #119 cm-ai 父运行可以换会话接着跑
15
- - #121 QA 修复子运行也能换会话接着跑
16
- - 已补齐 cm-check 可选能力三态、cm-test 中断步骤恢复;本次补齐 cm-refactor 规则三态和四个停机码,A 类清单已完成
17
- - 自动检查:每个 PR 跑 119 份,发版时跑满 126 份。
18
- - 盘点脚本 `scripts/audit-untested-enums.mjs` 报告:**38 个取值缺覆盖,分布在 40 处**(本次由 45 个、42 处降下)。
19
- - 已完成两份「归档让路」实现的收拢:单一实现位于 `runtime/js/cm-ai/review-evidence-file.mjs`,`host-handoff.mjs` 与 cm-fix 共用;交接文件归档行为逐字节保持不变。
7
+ - npm 上是 **0.16.3**(2026-09-26 发布,标记 `v0.16.3`)。下载回来拆包核对过,本次改动都在包里。
8
+ - 主干在发版之后只有文档更新(#150 README、#151 本文件及其审查修正),没有未发布的功能改动。
9
+ - 自动检查:每个 PR 跑 `scripts/` 下 138 份,另有不阻断合并的历史兼容夹具任务跑 `experiments/` 下 24 份;发版时由 `cm-release-smoke.sh` 补跑 CI 跑不了的 7 份。
10
+ - 盘点脚本 `scripts/audit-untested-enums.mjs` 报告:**24 个取值缺覆盖,分布在 22 处**(上次记录为 38 个、40 处)。
11
+ - 已在真实环境验证:「已审交接后 QA 卡住的任务作废重跑」在 e2e 存量项目和全真模型临时项目上各跑通一次(2026-09-25);公司项目上的原始事故尚待维护者本人跑一次确认。
20
12
 
21
13
  ---
22
14
 
@@ -43,7 +35,7 @@
43
35
 
44
36
  ## 第二档:已拍板的设计问题
45
37
 
46
- ### 1. cm-fix 本地 unknown 步骤的显式放弃与重做(已决定,未发布)
38
+ ### 1. cm-fix 本地 unknown 步骤的显式放弃与重做(已发布于 0.16.3)
47
39
 
48
40
  **决定**:保留所有 `unknown` 的默认不重派。仅对复现、诊断、测试编写与运行、修复、回归、复盘、走查及对应第二轮本地步骤,
49
41
  在原运行中增加带原因和独立启动旗标的 `abandon_step`;每次保留旧 intent,追加绑定摘要的记录和日志,再用新的 retry ID 重做。
@@ -56,7 +48,7 @@
56
48
 
57
49
  ## 第三档:已知缺口,值得做但不急
58
50
 
59
- ### 2. QA 修复子运行换会话恢复(已补齐,未发布)
51
+ ### 2. QA 修复子运行换会话恢复(已发布于 0.16.3)
60
52
 
61
53
  cm-ai 的 V3 会话父运行用 `--original-host-context` 恢复后,QA 修复子运行也使用当前真实会话打开和签审查授权;已有子配置保持不变。新建子运行只接受当前会话或父运行的持久创建会话,runtime 仍须匹配。父子运行继续串行交接同一把锁,原逐项授权不变。
62
54
 
@@ -78,7 +70,7 @@ cm-ai 的 V3 会话父运行用 `--original-host-context` 恢复后,QA 修复
78
70
 
79
71
  - **受保护模式跑不了 `tsx` / `vitest` 这类命令**。它们要开本地 socket,而沙箱把这个和「联网」放在同一个开关下。放开就等于给测试命令开整个外网,不划算。替代写法见 `skills/cm-fix/references/js-host.md`。驾驶员在建运行前会预警。
80
72
  - **有 7 份测试只在发版时跑**。它们要启动 Codex 沙箱,GitHub 的机器不给这个权限。已接进 `cm-release-smoke.sh`,发版必过;CI 里有一句断言钉死这 7 份的名单,不会悄悄变多。
81
- - **盘点脚本只认一种写法**(`['a','b'].includes(x)`),`switch`、对象查表、`Set.has` 都漏掉了。所以「38」是下限。
73
+ - **盘点脚本只认一种写法**(`['a','b'].includes(x)`),`switch`、对象查表、`Set.has` 都漏掉了。所以「24」是下限。
82
74
  - **读代码找不到所有问题**。0.16.1 修的四个缺陷全是跑真实项目跑出来的。拿工作流去跑真实项目,仍然是发现问题最有效的办法。
83
75
 
84
76
  ---
@@ -97,14 +89,12 @@ cm-ai 的 V3 会话父运行用 `--original-host-context` 恢复后,QA 修复
97
89
 
98
90
  ---
99
91
 
100
- ## 发版(等决定时再做)
92
+ ## 发版
101
93
 
102
- 是否发布 0.16.3、什么时候发,由维护者决定;决定之前先做前面的事。
94
+ 0.16.3 已于 2026-09-26 发布。下一版是否发、什么时候发,由维护者决定。
103
95
 
104
- **为什么**:上面这些改动还没进 npm 包。其中驾驶员是实打实省事的东西,#114 修的是上一版自己造出来的摩擦。
96
+ **流程**(0.16.1~0.16.3 都这样走):改六处版本号(`package.json`、`VERSION`、`.codex-plugin/plugin.json`、README 两处、`docs/installation.md`)→ 把 CHANGELOG「未发布」切成新版本 → 跑全套检查和 `cm-release-smoke.sh` → 开 PR 合并 → 在 `cm-workflow-dev` 目录的终端 `npm publish` 并过两步验证(这一步必须本人做)→ 下载包核对 → 在发版提交上打标记 → 两端重新安装。
105
97
 
106
- **做完是什么样**:npm 上是 0.16.3;把包从 npm 下载回来拆开,确认本次纳入发布的改动都在;打上 `v0.16.3` 标记。
98
+ **README 的「最近更新」要重写正文,不能只换版本号**。0.16.0~0.16.2 发版时只替换了版本号,结果那段一直挂着 0.15.5 的内容,直到 #150 才改回来。
107
99
 
108
- **流程**(和前两次一样):改六处版本号 → 跑全套检查和 `cm-release-smoke.sh` → 开 PR 合并 → 在终端 `npm publish` 并过两步验证(这一步必须本人做)→ 补标记 → 两端重新安装。
109
-
110
- **注意**:npm 登录会过期。`npm whoami` 报 401 时,先 `npm login`,确认打印出 `aibyzero` 再发。过期时 npm 报的是 404「找不到包」,很容易误判成包出了问题。
100
+ **注意**:npm 登录会过期。`npm whoami` 报 401 时,先 `npm login`,确认打印出 `aibyzero` 再发。过期时 npm 报的是 404「找不到包」,很容易误判成包出了问题。浏览器登录那一步超时时,可以改用 `npm login --auth-type=legacy`,在终端里依次输入用户名、密码和两步验证码。`npm publish` 过程中还会再弹一次网页确认,链接出来就尽快打开,别让它过期。
@@ -58,7 +58,7 @@ node scripts/cm-failover.mjs probe
58
58
 
59
59
  ```bash
60
60
  node scripts/cm-ai-host.mjs serve --config {CONFIG} --mode create \
61
- --host-context {ID} --allow-development --failover
61
+ --host-context {ID} --allow-development --review-config {REVIEW_CONFIG} --failover
62
62
  ```
63
63
 
64
64
  传入后,host 在构造 execution **之前**按 `developer` 角色选路。**声明为主、探测为校验**:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aibyzero/cm-workflow",
3
- "version": "0.16.3",
3
+ "version": "0.16.5",
4
4
  "description": "Spec-driven business development workflow for Pi, Codex, and Claude Code",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -1,9 +1,13 @@
1
1
  // Journal data grammar. Only the trusted serial host supplies original owner evidence.
2
2
  import {digest,hex,id,json,need,shape,validIdentity} from './effect-contract.mjs';
3
3
  import {qaFixIdentity} from '../cm-fix/qa-source.mjs';
4
- import {composeFixCode} from './fix-code-association.mjs';
4
+ import {associationRecord,composeFixCode,readSteps} from './fix-code-association.mjs';
5
5
 
6
- export function validateAcceptedFix({record,previous,baseline,parentPackage,feature}){
6
+ // resolveSteps: steps -> resolved steps from the named runs' verified stores, or
7
+ // null when a store is absent. Pure journal replay has no stores: a version 2
8
+ // record is then checked for shape and chain only, and the runner re-proves its
9
+ // composition against the stores (and every live use refuses what it cannot).
10
+ export function validateAcceptedFix({record,previous,baseline,parentPackage,feature,resolveSteps=null}){
7
11
  shape(record,['evidence','association','qaRound']);
8
12
  const {evidence:e,association:a,qaRound}=record;
9
13
  shape(e,['version','kind','identity','qaSource','checkpointRevision','reviewPackage','reviewRegistrationDigest',
@@ -21,8 +25,22 @@ export function validateAcceptedFix({record,previous,baseline,parentPackage,feat
21
25
  }
22
26
  need(qaRound===previous.length+1&&qaRound<=2,'fix_chain_invalid');
23
27
  need(!previous.some(item=>item.evidence.qaSource.testRunId===e.qaSource.testRunId),'fix_chain_invalid');
24
- const {files}=composeFixCode({baseline,parentPackage,fixPackages:[...previous.map(item=>item.evidence.reviewPackage),e.reviewPackage]});
25
- need(digest(a)===digest({version:1,kind:'cm-fix-code-association',parentPackageDigest:parentPackage.packageDigest,
26
- fixPackageDigest:e.reviewPackage.packageDigest,currentFilesDigest:digest(files)}),'fix_association_invalid');
28
+ // Version 1: strict chain. Version 2 keeps the previous record's interleaved
29
+ // deliveries as an exact prefix and may add only steps preceding this fix.
30
+ const steps=a?.version===2?a.laterDeliveries:[],prior=previous.at(-1)?.association.laterDeliveries??[];
31
+ need(Array.isArray(steps)&&(a?.version!==2||steps.length>0)&&steps.length>=prior.length
32
+ &&digest(steps.slice(0,prior.length))===digest(prior)
33
+ &&steps.slice(prior.length).every(step=>step?.beforeFix===previous.length),'fix_association_invalid');
34
+ const fixPackages=[...previous.map(item=>item.evidence.reviewPackage),e.reviewPackage];
35
+ readSteps(steps,fixPackages.length);
36
+ const resolved=steps.length?(typeof resolveSteps==='function'?resolveSteps(steps):null):[];
37
+ if(resolved){
38
+ const composed=composeFixCode({baseline,parentPackage,fixPackages,steps:resolved});
39
+ need(digest(a)===digest(associationRecord({...composed,steps})),'fix_association_invalid');
40
+ }else{
41
+ shape(a,['version','kind','parentPackageDigest','fixPackageDigest','currentFilesDigest','laterDeliveries']);
42
+ need(a.kind==='cm-fix-code-association'&&a.parentPackageDigest===parentPackage.packageDigest
43
+ &&a.fixPackageDigest===e.reviewPackage.packageDigest,'fix_association_invalid');hex(a.currentFilesDigest);
44
+ }
27
45
  return json(record,12*1024*1024);
28
46
  }
@@ -0,0 +1,15 @@
1
+ import {readSpecsStatus} from '../specs-status.mjs';
2
+
3
+ // One feature-name decision. A specs path reads its approved manifest;
4
+ // data-only replay callers pass their already-bound feature list.
5
+ export function identifyApprovedBootstrapFeature(source){
6
+ const status=typeof source==='string'?readSpecsStatus(source):null;
7
+ if(status&&!(status.kind==='valid'&&status.value.status==='approved'))
8
+ throw Object.assign(new Error('bootstrap_approval_required'),{code:'bootstrap_approval_required'});
9
+ const features=status?status.value.features:source;
10
+ if(!Array.isArray(features)||!features.every(name=>typeof name==='string'))
11
+ throw Object.assign(new Error('bootstrap_approval_required'),{code:'bootstrap_approval_required'});
12
+ const candidates=features.filter(name=>/^\d+\.bootstrap$/.test(name));
13
+ if(candidates.length>1)throw Object.assign(new Error('bootstrap_feature_ambiguous'),{code:'bootstrap_feature_ambiguous'});
14
+ return candidates[0]??null;
15
+ }
@@ -10,6 +10,16 @@ export function reportClaudeRateLimitNotice(raw, onNotice) {
10
10
  try { onNotice({kind:'rate_limit', info}); } catch {}
11
11
  }
12
12
 
13
+ export function reportClaudeDevIntentNotice(onNotice) {
14
+ if (typeof onNotice !== 'function') return;
15
+ try { onNotice({kind:'claude_system_notice', subtype:'dev_intent'}); } catch {}
16
+ }
17
+
18
+ // Error classes observed from Claude CLI 2.1.274; anything else is reviewer_api_error.
19
+ const API_ERROR_CLASSES = Object.freeze({authentication_failed:'reviewer_auth_failed',
20
+ billing_error:'reviewer_billing_error', rate_limit:'reviewer_rate_limited',
21
+ server_error:'reviewer_server_error', model_not_found:'reviewer_model_not_found'});
22
+
13
23
  export function createClaudeReviewStream(onEvent, onNotice = null) {
14
24
  let session = null, stage = 'init', value, noticeCount = 0, thinkingCount = 0, rejectedAttempts = 0;
15
25
  const pendingTools = new Map(), toolIds = new Set();
@@ -22,6 +32,13 @@ export function createClaudeReviewStream(onEvent, onNotice = null) {
22
32
  || message.session_id.length > 256) reject('invalid_session');
23
33
  if (session !== null && session !== message.session_id) reject('session_mismatch');
24
34
  if (stage === 'init') {
35
+ if (message.type === 'system' && message.subtype === 'dev_intent') {
36
+ if (noticeCount >= 32) reject('unexpected_event');
37
+ noticeCount++;
38
+ session = message.session_id;
39
+ reportClaudeDevIntentNotice(onNotice);
40
+ return;
41
+ }
25
42
  if (message.type !== 'system' || message.subtype !== 'init') reject('missing_init');
26
43
  session = message.session_id;
27
44
  stage = 'assistant';
@@ -36,6 +53,12 @@ export function createClaudeReviewStream(onEvent, onNotice = null) {
36
53
  return;
37
54
  }
38
55
  if (message.type === 'system') {
56
+ if (message.subtype === 'dev_intent') {
57
+ if (noticeCount >= 32) reject('unexpected_event');
58
+ noticeCount++;
59
+ reportClaudeDevIntentNotice(onNotice);
60
+ return;
61
+ }
39
62
  if (message.subtype === 'thinking_tokens') {
40
63
  // Long reviews emit usage heartbeats; worker-claude also caps total output at 1 MB.
41
64
  if (thinkingCount >= 4096) reject('unexpected_event');
@@ -55,6 +78,13 @@ export function createClaudeReviewStream(onEvent, onNotice = null) {
55
78
  return;
56
79
  }
57
80
  if (message.type === 'assistant') {
81
+ // CLI 2.1.x reports an API failure as a synthetic assistant message with
82
+ // a string error class, then an is_error result. Before any tool call it
83
+ // carries no verdict: stop with the class so the user knows what to fix.
84
+ if (typeof message.error === 'string' && message.parent_tool_use_id === null
85
+ && message.message?.role === 'assistant' && toolIds.size === 0) {
86
+ reject(Object.hasOwn(API_ERROR_CLASSES, message.error) ? API_ERROR_CLASSES[message.error] : 'reviewer_api_error');
87
+ }
58
88
  if (message.parent_tool_use_id !== null || message.error != null
59
89
  || message.message?.role !== 'assistant') reject('unexpected_assistant');
60
90
  const content = message.message.content;
@@ -5,27 +5,27 @@ import { createHash } from 'node:crypto';
5
5
  import { spawnSync } from 'node:child_process';
6
6
  import { fileURLToPath } from 'node:url';
7
7
  import {readSpecsStatus,writeSpecsStatus} from '../specs-status.mjs';
8
- import {buildManifest,verifyManifest} from '../../../scripts/cm-spec-manifest.mjs';
8
+ import {identifyApprovedBootstrapFeature} from './bootstrap-feature.mjs';
9
+ import {buildManifest,verifyApprovedManifest} from '../../../scripts/cm-spec-manifest.mjs';
10
+ import {outstandingFeatureQa,describeOutstandingQa} from './project-qa-gate.mjs';
11
+ import {taskLines,taskDeclarations,approvedTaskGrammar,TASK_GRAMMAR,LEGACY_TASK_GRAMMAR} from '../spec-task-line.mjs';
12
+ export {identifyApprovedBootstrapFeature} from './bootstrap-feature.mjs';
9
13
 
10
- const TASK=/^\s*-\s*\[([ xX])\]\s+(?:~~)?(T-[A-Za-z0-9][A-Za-z0-9._-]*)(?=[:\s])[:\s]*(.*)$/;
11
- const DEPENDENCY=/^\s*-\s*(T-[A-Za-z0-9][A-Za-z0-9._-]*)\s+依赖\s+(.+)$/;
14
+ export const DEPENDENCY=/^\s*-\s*(T-[A-Za-z0-9][A-Za-z0-9._-]*)\s+依赖\s+(.+)$/;
12
15
  const TASK_ID=/^T-[A-Za-z0-9][A-Za-z0-9._-]*$/;
13
16
  const ACCEPTANCE=/^\s*[-*]\s+(?:\[[ xX]\]\s+)?(?:\[(AC-\d{3,})\]|(AC-\d{3,}))(?=[:\s])/;
14
17
  const FEATURE=/^(\d+)\.(.+)$/;
15
18
  const TEST_CASE_VALIDATOR=fileURLToPath(new URL('../../../scripts/validate-test-cases.mjs',import.meta.url));
16
19
 
17
- export function parseCmAiTaskLine(line){
18
- const match=line.match(TASK);
19
- return match?{id:match[2],completed:match[1].toLowerCase()==='x'}:null;
20
- }
21
-
22
20
  // Greenfield's T-001 scaffolds; its subsequent instruction task (normally
23
21
  // T-002) owns init-equivalent rules. Use the existing parser and approval gate.
24
22
  export function inspectCmAiBootstrapTask({specsDir,codeProject,taskId},inProgress=false) {
25
23
  const admission=admissionFor({specsDir,codeProject},inProgress?taskId:null);
26
24
  const fail=code=>{throw Object.assign(new Error(code),{code});};
27
25
  if(!['ready','complete'].includes(admission.state))fail(admission.reason);
28
- const parsed=readFeature(admission.specsDir,'0.bootstrap');if(parsed.error)fail(parsed.error);
26
+ const feature=identifyApprovedBootstrapFeature(readSpecsStatus(admission.specsDir).value.features);
27
+ if(feature===null)fail('bootstrap_task_required');
28
+ const parsed=readFeature(admission.specsDir,feature);if(parsed.error)fail(parsed.error);
29
29
  const task=parsed.tasks.find(item=>item.id===taskId&&!item.dropped);
30
30
  const mode=task?.id==='T-001'&&/(?:脚手架|骨架|scaffold)/i.test(task.description)?'scaffold':'instructions';
31
31
  if(!task||mode==='instructions'&&(!/(?:cm-init|\.claude\/|AGENTS\.md)/i.test(task.description)
@@ -87,7 +87,9 @@ function directory(value){
87
87
  function approvalIntent(response,assumeYes){
88
88
  if(assumeYes===true)return 'explicit';
89
89
  if(response===undefined||response===null||response==='')return 'none';
90
- return typeof response==='string'&&response.trim()==='开始'?'explicit':'not_approval';
90
+ if(typeof response!=='string')return 'not_approval';
91
+ const normalized=response.trim().replace(/[。!!.~~\s]+$/gu,'');
92
+ return new Set(['开始','开始吧','可以开始','确认开始','开始执行','现在开始']).has(normalized)?'explicit':'not_approval';
91
93
  }
92
94
 
93
95
 
@@ -102,12 +104,13 @@ function discoverFeatures(specsDir){
102
104
  .filter(entry=>entry.isDirectory()&&FEATURE.test(entry.name))
103
105
  .map(entry=>entry.name)
104
106
  .sort((a,b)=>{
105
- if(a==='0.bootstrap')return b==='0.bootstrap'?0:-1;
106
- if(b==='0.bootstrap')return 1;
107
+ if(/^\d+\.bootstrap$/.test(a))return /^\d+\.bootstrap$/.test(b)?0:-1;
108
+ if(/^\d+\.bootstrap$/.test(b))return 1;
107
109
  const an=Number(a.match(FEATURE)[1]),bn=Number(b.match(FEATURE)[1]);
108
110
  return an-bn||(a<b?-1:a>b?1:0);
109
111
  });
110
112
  if(!names.length)return {error:'features_missing'};
113
+ try{identifyApprovedBootstrapFeature(names);}catch(error){return {error:error.code};}
111
114
  const reviewKeys=names.flatMap(name=>[name,name.replace(/^\d+\./,'')]);
112
115
  if(new Set(reviewKeys).size!==reviewKeys.length)return {error:'feature_contract_invalid'};
113
116
  for(const name of names){
@@ -151,7 +154,7 @@ function validTestContract(target,featureName){
151
154
  try{sources=['requirements.md','design.md','tasks.md'].map(file=>fs.readFileSync(path.join(featureRoot,file),'utf8'));}
152
155
  catch{return false;}
153
156
  const acIds=new Set(sources.flatMap(source=>source.split(/\r?\n/).map(line=>line.match(ACCEPTANCE)).filter(Boolean).map(match=>match[1]||match[2])));
154
- const taskIds=new Set(sources[2].split(/\r?\n/).map(line=>line.match(TASK)).filter(Boolean).map(match=>match[2]));
157
+ const taskIds=new Set(taskDeclarations(sources[2],{grammar:approvedTaskGrammar(path.dirname(featureRoot))}).map(task=>task.id));
155
158
  return data.cases.every(item=>item.acIds.every(id=>acIds.has(id))&&item.taskIds.every(id=>taskIds.has(id)));
156
159
  }
157
160
 
@@ -197,7 +200,8 @@ function validateTestCases(specsDir,status,names){
197
200
  }
198
201
 
199
202
  function readFeature(specsDir,name){
200
- const parsed=parseFeatureTaskText(fs.readFileSync(path.join(specsDir,name,'tasks.md'),'utf8'),{allowDependencyPunctuation:true});
203
+ const parsed=parseFeatureTaskText(fs.readFileSync(path.join(specsDir,name,'tasks.md'),'utf8'),
204
+ {allowDependencyPunctuation:true,grammar:approvedTaskGrammar(specsDir)});
201
205
  if(parsed.error)parsed.detail={feature:name,...parsed.detail};
202
206
  return parsed;
203
207
  }
@@ -206,24 +210,26 @@ export function declaredAcceptanceIds(source){
206
210
  return new Set(source.split(/\r?\n/).map(line=>line.match(ACCEPTANCE)).filter(Boolean).map(match=>match[1]||match[2]));
207
211
  }
208
212
 
209
- export function parseFeatureTaskText(source,{allowDependencyPunctuation=false}={}){
210
- const lines=source.split(/\r?\n/);
213
+ // Shared declaration grammar (spec-task-line.mjs), versioned by the approval.
214
+ export function parseFeatureTaskText(source,{allowDependencyPunctuation=false,grammar=TASK_GRAMMAR}={}){
215
+ const lines=taskLines(source,{grammar});
211
216
  const tasks=[];
212
217
  const taskIds=new Set();
213
218
  const dependencies=new Map();
214
219
  const dependencyLocations=new Map();
215
- const location=index=>({line:index+1,text:lines[index].slice(0,120)});
220
+ const location=index=>({line:index+1,text:lines[index].body.slice(0,120)});
216
221
  const invalid=(error,index)=>({error,detail:location(index)});
217
- for(const [index,line] of lines.entries()){
218
- const task=line.match(TASK);
222
+ for(const {index,body:line,fenced,declaration:task} of lines){
223
+ if(fenced)continue;
219
224
  if(task){
220
- if(taskIds.has(task[2]))return invalid('tasks_invalid',index);
221
- taskIds.add(task[2]);
222
- const dropped=/\[DROPPED(?:\s[^\]]*)?\]/.test(task[3]);
225
+ if(taskIds.has(task.id))return invalid('tasks_invalid',index);
226
+ taskIds.add(task.id);
227
+ const rest=task.description;
228
+ const dropped=/\[DROPPED(?:\s[^\]]*)?\]/.test(rest);
223
229
  tasks.push({
224
- id:task[2],
225
- description:task[3].replace(/~~\s*\[DROPPED(?:\s[^\]]*)?\].*$/,'').trim(),
226
- completed:task[1].toLowerCase()==='x',
230
+ id:task.id,
231
+ description:rest.replace(/~~\s*\[DROPPED(?:\s[^\]]*)?\].*$/,'').trim(),
232
+ completed:task.completed,
227
233
  dropped,
228
234
  });
229
235
  continue;
@@ -239,7 +245,7 @@ export function parseFeatureTaskText(source,{allowDependencyPunctuation=false}={
239
245
  dependencyLocations.set(dependency[1],location(index));
240
246
  }
241
247
  }
242
- if(!tasks.length)return invalid('tasks_invalid',Math.max(0,lines.findIndex(line=>line.trim())));
248
+ if(!tasks.length)return invalid('tasks_invalid',Math.max(0,lines.findIndex(line=>line.body.trim())));
243
249
  return {tasks,dependencies,dependencyLocations};
244
250
  }
245
251
 
@@ -267,10 +273,10 @@ function invalidDependency(tasks,dependencies){
267
273
 
268
274
  function validateBootstrap(codeProject,specsDir,names){
269
275
  const empty=fs.readdirSync(codeProject).length===0;
270
- const hasBootstrap=names.includes('0.bootstrap');
271
- if(empty&&!hasBootstrap)return 'bootstrap_required';
272
- if(!empty&&hasBootstrap){
273
- const parsed=readFeature(specsDir,'0.bootstrap');
276
+ const bootstrap=identifyApprovedBootstrapFeature(names);
277
+ if(empty&&!bootstrap)return 'bootstrap_required';
278
+ if(!empty&&bootstrap){
279
+ const parsed=readFeature(specsDir,bootstrap);
274
280
  if(parsed.error)return null; // Let selection retain the parser's location and feature summaries.
275
281
  const bootstrapTask=parsed.tasks.find(task=>task.id==='T-001');
276
282
  if(bootstrapTask&&!bootstrapTask.completed&&!bootstrapTask.dropped)return 'bootstrap_conflict';
@@ -298,6 +304,13 @@ function missingReviewIds(featureName,tasks,evidenceNames){
298
304
  });
299
305
  }
300
306
 
307
+ function dependenciesSatisfied(task,parsed,byId){
308
+ return (parsed.dependencies.get(task.id)||[]).every(id=>{
309
+ const dependency=byId.get(id);
310
+ return dependency&&(dependency.completed||dependency.dropped);
311
+ });
312
+ }
313
+
301
314
  function selectTask(specsDir,names){
302
315
  const features=[];
303
316
  const warnings=[];
@@ -322,18 +335,26 @@ function selectTask(specsDir,names){
322
335
  pending:pending.length,
323
336
  });
324
337
  if(!pending.length)continue;
325
- const eligible=pending.find(task=>(parsed.dependencies.get(task.id)||[]).every(id=>{
326
- const dependency=byId.get(id);
327
- return dependency&&(dependency.completed||dependency.dropped);
328
- }));
338
+ // One dependency rule for nextTask and --task/parallel eligibility: a
339
+ // prerequisite is satisfied once it is completed or DROPPED.
340
+ const ready=task=>dependenciesSatisfied(task,parsed,byId);
341
+ const eligible=pending.find(ready);
329
342
  if(!eligible)return {error:'dependencies_not_ready',features,warnings};
330
343
  return {features,warnings,nextTask:{feature:name,id:eligible.id,description:eligible.description},
331
- eligibleTasks:pending.filter(task=>(parsed.dependencies.get(task.id)||[]).every(id=>byId.get(id)?.completed))
332
- .map(task=>({feature:name,id:task.id}))};
344
+ eligibleTasks:pending.filter(ready).map(task=>({feature:name,id:task.id}))};
333
345
  }
334
346
  return {features,warnings,nextTask:null};
335
347
  }
336
348
 
349
+ // Selection stays tasks.md-driven; an earlier feature's unfinished QA is surfaced
350
+ // here and enforced at N8 (finish/run_finalize), never by reordering tasks.
351
+ function featureQaWarnings(specsDir,features){
352
+ try{
353
+ return outstandingFeatureQa({specsDir,features:features.map(({name,pending})=>({name,pending}))}).map(item=>
354
+ `⚠ QA 未通过: ${describeOutstandingQa(item)};它通过之前项目不能收尾(run_done)`);
355
+ }catch{return ['⚠ QA 日志无法读取,未能确认各 feature 的最新 QA 是否通过'];}
356
+ }
357
+
337
358
  export function inspectCmAiAdmission(options){
338
359
  return admissionFor(options);
339
360
  }
@@ -343,7 +364,7 @@ export function approveCmAiSpecs(options){
343
364
  const projects=options.codeProjects??[options.codeProject];
344
365
  const inspect=()=>projects.map(codeProject=>inspectCmAiAdmission({...options,codeProject}));
345
366
  const projectResults=inspect();
346
- const refuse=approveRefused=>({projectResults,approveRefused});
367
+ const refuse=(approveRefused,approveReason=null)=>({projectResults,approveRefused,...(approveReason?{approveReason}:{})});
347
368
  if(options.assumeYes)return refuse('assume_yes_not_allowed');
348
369
  if(typeof options.approvalResponse!=='string'||!options.approvalResponse.trim())
349
370
  return refuse('approval_response_required');
@@ -356,10 +377,37 @@ export function approveCmAiSpecs(options){
356
377
  try{
357
378
  const discovered=discoverFeatures(specsDir);
358
379
  if(discovered.error)return refuse(discovered.error);
380
+ // An approval binds grammar 2 to every feature, including ones this change
381
+ // did not touch. Refuse rather than silently re-reading bytes that an older
382
+ // approval parsed differently (e.g. an unfenced `- [ ] T-001:例` becoming a
383
+ // duplicate of the real T-001), and rather than keeping grammar 1, which
384
+ // would leave newly drafted full-width task lines silently not tasks.
385
+ // Moving from the pre-grammar parse must not change which lines are tasks
386
+ // either (e.g. a unique `- [ ] T-099:示例` would become a pending task). The
387
+ // status carries the last approval's grammar through cm-prd publication;
388
+ // once a project is on grammar 2 there is nothing to reconcile.
389
+ // No status at all means nothing was approved before: no earlier meaning to keep.
390
+ const fromLegacy=status.kind==='valid'&&status.value.taskGrammar!==TASK_GRAMMAR;
391
+ for(const name of discovered.names){
392
+ const source=fs.readFileSync(path.join(specsDir,name,'tasks.md'),'utf8');
393
+ const parsed=parseFeatureTaskText(source,{allowDependencyPunctuation:true,grammar:TASK_GRAMMAR});
394
+ if(parsed.error)return refuse('task_grammar_conflict',`${name}/tasks.md 第 ${parsed.detail.line} 行在新任务行语法下无效(${parsed.error}):`
395
+ +`${parsed.detail.text}。此前的批准把它当作说明文字;把这类示例放进 \`\`\` 围栏或删去后再批准。`);
396
+ if(!fromLegacy)continue;
397
+ const view=grammar=>taskDeclarations(source,{grammar}).map(item=>({line:item.index+1,key:`${item.id}\0${item.completed}\0${item.body.trim()}`,text:item.body.trim()}));
398
+ const legacy=view(LEGACY_TASK_GRAMMAR),current=view(TASK_GRAMMAR);
399
+ const legacyKeys=new Set(legacy.map(item=>item.key)),currentKeys=new Set(current.map(item=>item.key));
400
+ const differing=[...current.filter(item=>!legacyKeys.has(item.key)),...legacy.filter(item=>!currentKeys.has(item.key))]
401
+ .sort((a,b)=>a.line-b.line);
402
+ if(differing.length)return refuse('task_grammar_conflict',`${name}/tasks.md 在新任务行语法下任务集合会变化:`
403
+ +differing.slice(0,5).map(item=>`第 ${item.line} 行 ${item.text}`).join(';')+`${differing.length>5?` 等 ${differing.length} 行`:''}`
404
+ +'。此前的批准不把这些行当任务(或反之);是示例就放进 ``` 围栏或删去,是任务就改用英文冒号「:」写法后再批准。');
405
+ }
359
406
  const specFiles=buildManifest(specsDir),at=new Date().toISOString();
360
407
  writeSpecsStatus(specsDir,{status:'approved',summaryDigest:status.value?.summaryDigest??null,at,
361
408
  features:discovered.names,specFiles,testCases:specFiles.filter(item=>item.path.endsWith('/test-cases.json')),
362
- approval:{response:options.approvalResponse,at}});
409
+ approval:{response:options.approvalResponse,at},taskGrammar:TASK_GRAMMAR,
410
+ ...(status.value&&Object.hasOwn(status.value,'revisionDigest')?{revisionDigest:status.value.revisionDigest}:{})});
363
411
  }catch(error){return refuse(error.code??error.message);}
364
412
  return {projectResults:inspect()};
365
413
  }
@@ -382,7 +430,7 @@ function admissionFor(options,inProgressBootstrap=null){
382
430
  if(featuresProblem==='spec_features_changed')return result(base,'awaiting_spec_approval',featuresProblem);
383
431
  if(featuresProblem)return result(base,'blocked',featuresProblem);
384
432
  if(Object.hasOwn(status.value,'specFiles')){
385
- try{verifyManifest(buildManifest(specsDir),path.join(specsDir,'.cm-specs-status'));}
433
+ try{verifyApprovedManifest(specsDir,path.join(specsDir,'.cm-specs-status'));}
386
434
  catch{return result(base,'blocked','spec_drift');}
387
435
  }
388
436
  const testCasesProblem=validateTestCases(specsDir,status.value,discovered.names);
@@ -394,8 +442,32 @@ function admissionFor(options,inProgressBootstrap=null){
394
442
  const selection=selectTask(specsDir,discovered.names);
395
443
  if(selection.error)return result(base,'blocked',selection.error,{features:selection.features,warnings:selection.warnings,
396
444
  ...(selection.detail?{detail:selection.detail}:{})});
397
- if(!selection.nextTask)return result(base,'complete','all_tasks_terminal',{features:selection.features,warnings:selection.warnings});
398
- return result(base,'ready','task_selected',{features:selection.features,nextTask:selection.nextTask,eligibleTasks:selection.eligibleTasks,warnings:selection.warnings});
445
+ const warnings=[...selection.warnings,...featureQaWarnings(specsDir,selection.features)];
446
+ if(!selection.nextTask)return result(base,'complete','all_tasks_terminal',{features:selection.features,warnings});
447
+ return result(base,'ready','task_selected',{features:selection.features,nextTask:selection.nextTask,eligibleTasks:selection.eligibleTasks,warnings});
448
+ }
449
+
450
+ // Diagnostic only: why an explicit --task selection is not eligible. Never used
451
+ // to grant a selection; matchesCmAiTaskSelection remains the sole gate.
452
+ export function explainCmAiTaskSelection(admission,{feature,taskId,selection=null}){
453
+ if(admission.state!=='ready')return `当前准入状态为 ${admission.state}/${admission.reason},不能选择任务`;
454
+ const next=admission.nextTask;
455
+ if(next&&next.feature!==feature)return `--task 只能选择当前 feature ${next.feature} 的任务(运行定义为 ${feature})`;
456
+ if(!admission.specsDir)return `${taskId} 不在可选任务中`;
457
+ let parsed;
458
+ try{parsed=readFeature(admission.specsDir,feature);}catch{return `无法读取 ${feature}/tasks.md`;}
459
+ if(parsed.error)return `${feature}/tasks.md 无法解析(${parsed.error})`;
460
+ const byId=new Map(parsed.tasks.map(task=>[task.id,task]));
461
+ const task=byId.get(taskId);
462
+ if(!task)return `${feature}/tasks.md 中没有任务 ${taskId}`;
463
+ if(task.dropped)return `${taskId} 已标记 DROPPED`;
464
+ if(task.completed)return `${taskId} 已勾选完成`;
465
+ const waiting=(parsed.dependencies.get(taskId)||[]).filter(id=>{const item=byId.get(id);return !item||!item.completed&&!item.dropped;});
466
+ if(waiting.length)return `${taskId} 依赖的 ${waiting.join('、')} 尚未完成`;
467
+ const eligible=(admission.eligibleTasks??[]).filter(item=>item.feature===feature).map(item=>item.id);
468
+ if(selection===null&&next&&next.id!==taskId&&eligible.includes(taskId))
469
+ return `运行定义未写 taskSelection,只能运行 nextTask ${next.id};改选 ${taskId} 请用 cm-ai-admission.mjs --print-run-definition --task ${taskId} 重新生成运行定义`;
470
+ return `${taskId} 不在可选任务中;当前可选:${eligible.join('、')||'无'}`;
399
471
  }
400
472
 
401
473
  // Trusted caller selection is data bound by openControlRun, never message authority.
@@ -403,6 +475,9 @@ export function matchesCmAiTaskSelection(admission,feature,taskId,parallelSelect
403
475
  if(parallelSelection===null)return admission.state==='ready'
404
476
  &&admission.nextTask?.feature===feature&&admission.nextTask.id===taskId;
405
477
  const value=parallelSelection;
478
+ if(value?.version===1&&Object.keys(value).sort().join(',')==='taskId,version')
479
+ return value.taskId===taskId&&admission.state==='ready'
480
+ &&admission.eligibleTasks?.some(task=>task.feature===feature&&task.id===taskId)===true;
406
481
  return admission.state==='ready'&&value?.version===1
407
482
  &&Object.keys(value).sort().join(',')==='group,version'&&Array.isArray(value.group)
408
483
  &&value.group.length>=2&&new Set(value.group).size===value.group.length
@@ -2,7 +2,7 @@
2
2
  import {createHash} from 'node:crypto';
3
3
  import fs from 'node:fs';
4
4
  import path from 'node:path';
5
- import {inspectCmAiAdmission,matchesCmAiTaskSelection} from './cm-ai-admission.mjs';
5
+ import {inspectCmAiAdmission,matchesCmAiTaskSelection,identifyApprovedBootstrapFeature} from './cm-ai-admission.mjs';
6
6
  import {arrayItems,digest,freeze,hex,json,need,shape,text,validIdentity,validTaskLearningInput} from './effect-contract.mjs';
7
7
 
8
8
  const BASELINE_RULES=['coding-style.md','testing.md','security.md'];
@@ -62,7 +62,8 @@ export function inspectCmAiContextRefresh(input,{admission:trustedAdmission=null
62
62
  shape(input,['specsDir','codeProject','feature','applicableAgentFiles']);
63
63
  text(input.specsDir);text(input.codeProject);text(input.feature);
64
64
  const admission=trustedAdmission??inspectCmAiAdmission({specsDir:input.specsDir,codeProject:input.codeProject});
65
- if(trustedAdmission!==null)need(input.feature==='0.bootstrap'
65
+ if(trustedAdmission!==null)need(input.feature===identifyApprovedBootstrapFeature(
66
+ trustedAdmission.features.map(item=>item.name))
66
67
  &&admission.specsDir===input.specsDir&&admission.codeProject===input.codeProject,'context_invalid');
67
68
  if(!['ready','complete'].includes(admission.state))return freeze({state:admission.state,reason:admission.reason,
68
69
  nextTask:null,eligibleTasks:[],contextDigest:null,contextFiles:[]});