@aibyzero/cm-workflow 0.17.0 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (372) hide show
  1. package/.codex-plugin/plugin.json +1 -1
  2. package/AGENTS.md +27 -0
  3. package/CHANGELOG.md +230 -1
  4. package/CONTRIBUTING.md +47 -0
  5. package/README.md +21 -3
  6. package/THIRD_PARTY_NOTICES.md +13 -0
  7. package/VERSION +1 -1
  8. package/compat/claude-commands/cm-challenge.md +3 -0
  9. package/docs/architecture.md +40 -13
  10. package/docs/cm-control-policy-v2.md +127 -9
  11. package/docs/fixes/20261013-claude-preinit-ui-invalidate.md +48 -0
  12. package/docs/installation.md +310 -4
  13. package/docs/js-workflow-control.md +153 -16
  14. package/docs/live-evidence-drivers.md +28 -4
  15. package/docs/out-of-scope/README.md +25 -0
  16. package/docs/out-of-scope/background-supervisor.md +32 -0
  17. package/docs/reviewed-integration.md +48 -0
  18. package/docs/user-guide.md +50 -21
  19. package/install-codex.sh +331 -18
  20. package/install.ps1 +28 -2
  21. package/install.sh +321 -17
  22. package/package.json +2 -1
  23. package/runtime/js/cm-ai/batch-location.mjs +55 -0
  24. package/runtime/js/cm-ai/batch-plan.mjs +242 -0
  25. package/runtime/js/cm-ai/checkpoint-package-material.mjs +162 -0
  26. package/runtime/js/cm-ai/claude-developer-proposal.schema.json +55 -1
  27. package/runtime/js/cm-ai/claude-review-stream.mjs +94 -21
  28. package/runtime/js/cm-ai/claude-tool-preview.mjs +11 -9
  29. package/runtime/js/cm-ai/cm-ai-admission.mjs +18 -12
  30. package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +91 -6
  31. package/runtime/js/cm-ai/cm-ai-qa-log.mjs +5 -1
  32. package/runtime/js/cm-ai/codex-config.mjs +6 -2
  33. package/runtime/js/cm-ai/codex-developer-basic-output.schema.json +3 -2
  34. package/runtime/js/cm-ai/codex-developer-output.schema.json +2 -1
  35. package/runtime/js/cm-ai/codex-reconnect-notice.mjs +6 -0
  36. package/runtime/js/cm-ai/codex-review-adapter.mjs +27 -7
  37. package/runtime/js/cm-ai/control-policy.mjs +24 -6
  38. package/runtime/js/cm-ai/developer-adapter.mjs +19 -5
  39. package/runtime/js/cm-ai/drive-core.mjs +236 -34
  40. package/runtime/js/cm-ai/drive-rate-limit.mjs +105 -0
  41. package/runtime/js/cm-ai/durable-runner-state.mjs +234 -33
  42. package/runtime/js/cm-ai/effect-contract.mjs +11 -2
  43. package/runtime/js/cm-ai/execution-policy.mjs +3 -1
  44. package/runtime/js/cm-ai/execution-snapshot.mjs +4 -2
  45. package/runtime/js/cm-ai/execution-store-limits.mjs +14 -7
  46. package/runtime/js/cm-ai/execution-store.mjs +60 -17
  47. package/runtime/js/cm-ai/fix-code-association.mjs +73 -2
  48. package/runtime/js/cm-ai/host-check.mjs +14 -6
  49. package/runtime/js/cm-ai/host-conversation-execution.mjs +70 -28
  50. package/runtime/js/cm-ai/host-qa-executor.mjs +38 -5
  51. package/runtime/js/cm-ai/host-qa-fix-owner.mjs +2 -2
  52. package/runtime/js/cm-ai/host-qa-policy.mjs +19 -2
  53. package/runtime/js/cm-ai/host-replay.mjs +148 -0
  54. package/runtime/js/cm-ai/host-session.mjs +42 -9
  55. package/runtime/js/cm-ai/host-stage-observer.mjs +26 -0
  56. package/runtime/js/cm-ai/host-tool-bridge.mjs +22 -9
  57. package/runtime/js/cm-ai/host-workflow-capabilities.mjs +19 -2
  58. package/runtime/js/cm-ai/host.mjs +1 -1
  59. package/runtime/js/cm-ai/implicit-qa-decision.mjs +5 -0
  60. package/runtime/js/cm-ai/integration-snapshots.mjs +50 -0
  61. package/runtime/js/cm-ai/live-evidence.mjs +28 -6
  62. package/runtime/js/cm-ai/operator-guidance.mjs +63 -30
  63. package/runtime/js/cm-ai/owned-process-cleanup.mjs +27 -9
  64. package/runtime/js/cm-ai/process-group-exit.mjs +46 -0
  65. package/runtime/js/cm-ai/provider-review-observation.mjs +3 -2
  66. package/runtime/js/cm-ai/qa-attachment.mjs +22 -0
  67. package/runtime/js/cm-ai/qa-config-revision.mjs +7 -2
  68. package/runtime/js/cm-ai/requirement-evidence.mjs +102 -0
  69. package/runtime/js/cm-ai/review-package.mjs +79 -7
  70. package/runtime/js/cm-ai/review-presentation-delta.mjs +166 -0
  71. package/runtime/js/cm-ai/review-presentation.mjs +177 -8
  72. package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +70 -2
  73. package/runtime/js/cm-ai/reviewed-integration.mjs +260 -0
  74. package/runtime/js/cm-ai/scope-revision.mjs +38 -0
  75. package/runtime/js/cm-ai/specification-material.mjs +2 -2
  76. package/runtime/js/cm-ai/task-runner.mjs +247 -41
  77. package/runtime/js/cm-ai/verification-auto.mjs +38 -0
  78. package/runtime/js/cm-ai/worker-claude-developer.mjs +39 -15
  79. package/runtime/js/cm-ai/worker-claude.mjs +35 -13
  80. package/runtime/js/cm-ai/worker-codex-developer.mjs +43 -17
  81. package/runtime/js/cm-ai/worker-codex.mjs +41 -7
  82. package/runtime/js/cm-fix/cause-invocation.mjs +16 -2
  83. package/runtime/js/cm-fix/cause-package.mjs +46 -1
  84. package/runtime/js/cm-fix/command-correction.mjs +37 -0
  85. package/runtime/js/cm-fix/cooperative.mjs +12 -0
  86. package/runtime/js/cm-fix/dossier.mjs +8 -2
  87. package/runtime/js/cm-fix/execution.mjs +578 -100
  88. package/runtime/js/cm-fix/final-review.mjs +39 -8
  89. package/runtime/js/cm-fix/finish.mjs +15 -11
  90. package/runtime/js/cm-fix/host-review.mjs +65 -10
  91. package/runtime/js/cm-fix/host.mjs +35 -12
  92. package/runtime/js/cm-fix/jest-command-correction.mjs +69 -0
  93. package/runtime/js/cm-fix/metrics.mjs +18 -5
  94. package/runtime/js/cm-fix/regression-evidence.mjs +3 -2
  95. package/runtime/js/cm-fix/regression.mjs +16 -7
  96. package/runtime/js/cm-fix/repair.mjs +29 -8
  97. package/runtime/js/cm-fix/review-verification-command.mjs +135 -0
  98. package/runtime/js/cm-fix/review-verification-contract.mjs +54 -0
  99. package/runtime/js/cm-fix/review-verification-diagnostic.mjs +75 -0
  100. package/runtime/js/cm-fix/review-verification-recovery.mjs +44 -0
  101. package/runtime/js/cm-fix/review-verification-server.mjs +38 -0
  102. package/runtime/js/cm-fix/review-verification.mjs +214 -0
  103. package/runtime/js/cm-fix/source-correction-recovery.mjs +65 -0
  104. package/runtime/js/cm-fix/start.mjs +6 -3
  105. package/runtime/js/cm-fix/test-type-correction.mjs +86 -0
  106. package/runtime/js/cm-fix/test-type-recovery.mjs +51 -0
  107. package/runtime/js/cm-fix/type-import-correction.mjs +89 -0
  108. package/runtime/js/cm-prd/accepted-design.mjs +8 -0
  109. package/runtime/js/cm-prd/analysis.mjs +13 -9
  110. package/runtime/js/cm-prd/change.mjs +37 -16
  111. package/runtime/js/cm-prd/draft-save.mjs +13 -6
  112. package/runtime/js/cm-prd/draft.mjs +31 -3
  113. package/runtime/js/cm-prd/failed-correction.mjs +19 -3
  114. package/runtime/js/cm-prd/inputs-replaced.mjs +3 -0
  115. package/runtime/js/cm-prd/review-correction.mjs +6 -4
  116. package/runtime/js/cm-prd/review-disposition.mjs +7 -1
  117. package/runtime/js/cm-prd/self-check-revision.mjs +2 -2
  118. package/runtime/js/cm-prd/self-check.mjs +125 -6
  119. package/runtime/js/cm-prd/session.mjs +30 -1
  120. package/runtime/js/cm-prd/summary.mjs +38 -17
  121. package/runtime/js/cm-prd/task-scope-record.mjs +97 -0
  122. package/runtime/js/cm-prd/tree-digest.mjs +34 -0
  123. package/runtime/js/cm-prd/validation-reason.mjs +8 -4
  124. package/runtime/js/cm-security/scan.mjs +1 -1
  125. package/runtime/js/commander/decision.mjs +44 -0
  126. package/runtime/js/commander/dispatch-registry.mjs +110 -0
  127. package/runtime/js/commander/ledger.mjs +265 -0
  128. package/runtime/js/commander/preflight.mjs +107 -0
  129. package/runtime/js/notify-later.mjs +13 -0
  130. package/runtime/js/notify-send.mjs +6 -2
  131. package/runtime/js/notify.mjs +570 -63
  132. package/runtime/js/review-findings.mjs +38 -0
  133. package/runtime/js/session-boundary.mjs +56 -0
  134. package/runtime/js/session-handoff.mjs +68 -0
  135. package/runtime/js/spec-task-line.mjs +27 -13
  136. package/runtime/js/specs-status.mjs +1 -1
  137. package/runtime/js/task-scope.mjs +197 -0
  138. package/runtime/logging.md +6 -1
  139. package/runtime/model-efficiency.md +69 -10
  140. package/runtime/orchestration.md +3 -1
  141. package/runtime/project-learning.md +2 -0
  142. package/runtime/review.md +12 -2
  143. package/runtime/test-contract.md +1 -0
  144. package/scripts/ci-test-weights.json +3 -0
  145. package/scripts/cm-ai-admission.mjs +11 -5
  146. package/scripts/cm-ai-admission.test.mjs +23 -2
  147. package/scripts/cm-ai-batch-drive.mjs +79 -18
  148. package/scripts/cm-ai-batch-drive.test.mjs +169 -3
  149. package/scripts/cm-ai-batch-host.mjs +38 -9
  150. package/scripts/cm-ai-batch-host.test.mjs +27 -14
  151. package/scripts/cm-ai-batch-learning-merge.test.mjs +36 -0
  152. package/scripts/cm-ai-batch-location.test.mjs +57 -0
  153. package/scripts/cm-ai-batch-plan.mjs +52 -0
  154. package/scripts/cm-ai-batch-plan.test.mjs +397 -0
  155. package/scripts/cm-ai-batch-run-fixture.mjs +446 -35
  156. package/scripts/cm-ai-batch-run-member-stops.test.mjs +16 -0
  157. package/scripts/cm-ai-batch-run-parallel.test.mjs +28 -1
  158. package/scripts/cm-ai-batch-run.mjs +483 -63
  159. package/scripts/cm-ai-batch-run.test.mjs +23 -4
  160. package/scripts/cm-ai-batch-session-e2e.test.mjs +235 -0
  161. package/scripts/cm-ai-batch-session-member.test.mjs +293 -0
  162. package/scripts/cm-ai-batch-session-recovery.test.mjs +423 -0
  163. package/scripts/cm-ai-check-recheck-cancellation.test.mjs +247 -0
  164. package/scripts/cm-ai-checklist-coverage.test.mjs +4 -2
  165. package/scripts/cm-ai-checkpoint-package-material.test.mjs +221 -0
  166. package/scripts/cm-ai-checkpoint-package-owner.test.mjs +193 -0
  167. package/scripts/cm-ai-control-launch.test.mjs +21 -0
  168. package/scripts/cm-ai-control-policy.test.mjs +82 -0
  169. package/scripts/cm-ai-control-v2-drive.test.mjs +398 -3
  170. package/scripts/cm-ai-control-v2-supersede-race.mjs +25 -0
  171. package/scripts/cm-ai-control-v2-supersede.test.mjs +318 -0
  172. package/scripts/cm-ai-develop-driver-gaps.test.mjs +163 -0
  173. package/scripts/cm-ai-development-rework.test.mjs +423 -0
  174. package/scripts/cm-ai-drive-bootstrap-rules.test.mjs +3 -2
  175. package/scripts/cm-ai-drive.mjs +73 -17
  176. package/scripts/cm-ai-drive.test.mjs +37 -5
  177. package/scripts/cm-ai-execution-store-legacy-probe.test.mjs +84 -0
  178. package/scripts/cm-ai-host-fixture.mjs +9 -6
  179. package/scripts/cm-ai-host-protected.test.mjs +1 -1
  180. package/scripts/cm-ai-host.mjs +60 -19
  181. package/scripts/cm-ai-host.test.mjs +15 -0
  182. package/scripts/cm-ai-integration-adoption.test.mjs +223 -0
  183. package/scripts/cm-ai-integration-independence.test.mjs +23 -0
  184. package/scripts/cm-ai-integration-launch.test.mjs +240 -0
  185. package/scripts/cm-ai-integration-preview.mjs +41 -0
  186. package/scripts/cm-ai-integration-snapshots.test.mjs +197 -0
  187. package/scripts/cm-ai-nested-execution.test.mjs +29 -1
  188. package/scripts/cm-ai-operator-guidance.test.mjs +71 -0
  189. package/scripts/cm-ai-prefinal-delivery.test.mjs +278 -0
  190. package/scripts/cm-ai-project-qa-gate.test.mjs +56 -0
  191. package/scripts/cm-ai-qa-fingerprint-config.test.mjs +28 -0
  192. package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +36 -2
  193. package/scripts/cm-ai-requirement-evidence.test.mjs +65 -0
  194. package/scripts/cm-ai-review-failure.test.mjs +150 -5
  195. package/scripts/cm-ai-review-timeout.test.mjs +20 -0
  196. package/scripts/cm-ai-run.mjs +88 -21
  197. package/scripts/cm-ai-scope-revision.test.mjs +341 -0
  198. package/scripts/cm-ai-spec-rebind.test.mjs +13 -0
  199. package/scripts/cm-ai-supersede.test.mjs +28 -0
  200. package/scripts/cm-ai-verification-auto.test.mjs +99 -0
  201. package/scripts/cm-announce-hook.mjs +35 -8
  202. package/scripts/cm-announce-hook.test.mjs +25 -0
  203. package/scripts/cm-challenge.test.mjs +61 -0
  204. package/scripts/cm-check-drive-files.mjs +2 -2
  205. package/scripts/cm-check-host.test.mjs +1 -1
  206. package/scripts/cm-check-runtime.sh +58 -1
  207. package/scripts/cm-claude-developer-worker.test.mjs +56 -7
  208. package/scripts/cm-claude-install-layout.test.mjs +1 -1
  209. package/scripts/cm-claude-probe.test.mjs +26 -0
  210. package/scripts/cm-claude-review-diagnostics.test.mjs +235 -0
  211. package/scripts/cm-claude-review-stream.test.mjs +49 -0
  212. package/scripts/cm-claude-worker.test.mjs +16 -0
  213. package/scripts/cm-codex-developer-reconnect-notice.test.mjs +98 -0
  214. package/scripts/cm-codex-developer-worker.test.mjs +120 -0
  215. package/scripts/cm-codex-install-local-edit-guard.test.mjs +436 -0
  216. package/scripts/cm-codex-prompt-input.test.mjs +153 -0
  217. package/scripts/cm-codex-reconnect-notice.test.mjs +167 -0
  218. package/scripts/cm-commander-ledger.test.mjs +260 -0
  219. package/scripts/cm-commander-p2.test.mjs +295 -0
  220. package/scripts/cm-commander-preflight.mjs +84 -0
  221. package/scripts/cm-commander.mjs +116 -0
  222. package/scripts/cm-config-lock.mjs +35 -0
  223. package/scripts/cm-controlled-correction.test.mjs +10 -1
  224. package/scripts/cm-developer-failure-code.test.mjs +62 -0
  225. package/scripts/cm-display-task-id.test.mjs +41 -0
  226. package/scripts/cm-drive-liveness.test.mjs +83 -0
  227. package/scripts/cm-efficiency-presentation-delta.test.mjs +218 -0
  228. package/scripts/cm-execution-snapshot-reuse.test.mjs +115 -0
  229. package/scripts/cm-external-batch-host.test.mjs +12 -9
  230. package/scripts/cm-external-process-cleanup.test.mjs +128 -0
  231. package/scripts/cm-external-qa-fix.test.mjs +89 -7
  232. package/scripts/cm-external-review-reconciliation.test.mjs +11 -0
  233. package/scripts/cm-failover.mjs +48 -10
  234. package/scripts/cm-failover.test.mjs +46 -0
  235. package/scripts/cm-fix-cause-invocation.test.mjs +19 -4
  236. package/scripts/cm-fix-command-correction.mjs +17 -0
  237. package/scripts/cm-fix-command-correction.test.mjs +211 -0
  238. package/scripts/cm-fix-cooperative-closeout.test.mjs +87 -0
  239. package/scripts/cm-fix-diagnosis-module-correction.test.mjs +217 -0
  240. package/scripts/cm-fix-drive.mjs +33 -5
  241. package/scripts/cm-fix-drive.test.mjs +49 -0
  242. package/scripts/cm-fix-host-review-assembly.test.mjs +197 -1
  243. package/scripts/cm-fix-host-review.test.mjs +21 -9
  244. package/scripts/cm-fix-host.mjs +26 -8
  245. package/scripts/cm-fix-monorepo-map.test.mjs +92 -0
  246. package/scripts/cm-fix-observation-task-id.test.mjs +122 -0
  247. package/scripts/cm-fix-regression-input-budget.test.mjs +111 -0
  248. package/scripts/cm-fix-repair-input-budget.test.mjs +119 -0
  249. package/scripts/cm-fix-review-file-paging.test.mjs +91 -0
  250. package/scripts/cm-fix-review-preflight.mjs +24 -0
  251. package/scripts/cm-fix-review-storage.test.mjs +233 -0
  252. package/scripts/cm-fix-review-verification-command.test.mjs +242 -0
  253. package/scripts/cm-fix-review-verification-evidence.test.mjs +218 -0
  254. package/scripts/cm-fix-review-verification-integration.test.mjs +81 -0
  255. package/scripts/cm-fix-review-verification-recovery.test.mjs +198 -0
  256. package/scripts/cm-fix-review-verification.test.mjs +146 -0
  257. package/scripts/cm-fix-revision-transport.test.mjs +81 -0
  258. package/scripts/cm-fix-source-correction.test.mjs +296 -0
  259. package/scripts/cm-fix-test-type-correction.mjs +18 -0
  260. package/scripts/cm-fix-test-type-correction.test.mjs +123 -0
  261. package/scripts/cm-fix-test-type-owner.test.mjs +208 -0
  262. package/scripts/cm-fix-test-type-verification-cost.test.mjs +66 -0
  263. package/scripts/cm-fix-type-import-correction.test.mjs +95 -0
  264. package/scripts/cm-fix-verification-diagnostic.test.mjs +200 -0
  265. package/scripts/cm-fix-verification-recovery.mjs +33 -0
  266. package/scripts/cm-host-diagnostic.test.mjs +33 -0
  267. package/scripts/cm-host-liveness.test.mjs +150 -0
  268. package/scripts/cm-host-qa-executor.test.mjs +77 -0
  269. package/scripts/cm-host-replay.test.mjs +176 -0
  270. package/scripts/cm-host-stage-observer.test.mjs +41 -0
  271. package/scripts/cm-install-local-edit-guard.test.mjs +621 -0
  272. package/scripts/cm-install-manifest.sh +351 -0
  273. package/scripts/cm-live-evidence.test.mjs +59 -1
  274. package/scripts/cm-log-event.mjs +61 -10
  275. package/scripts/cm-log-event.test.mjs +121 -1
  276. package/scripts/cm-matt-skills.mjs +576 -0
  277. package/scripts/cm-matt-skills.test.mjs +550 -0
  278. package/scripts/cm-notify-command.test.mjs +42 -10
  279. package/scripts/cm-notify.mjs +14 -10
  280. package/scripts/cm-notify.test.mjs +625 -75
  281. package/scripts/cm-patrol.mjs +4 -1
  282. package/scripts/cm-patrol.test.mjs +23 -5
  283. package/scripts/cm-prd-answer-gaps.test.mjs +2 -2
  284. package/scripts/cm-prd-completion.test.mjs +56 -13
  285. package/scripts/cm-prd-design-phase.test.mjs +78 -8
  286. package/scripts/cm-prd-draft-save.test.mjs +12 -0
  287. package/scripts/cm-prd-draft.test.mjs +1 -1
  288. package/scripts/cm-prd-drive.mjs +13 -6
  289. package/scripts/cm-prd-drive.test.mjs +46 -2
  290. package/scripts/cm-prd-gate-diagnostic.test.mjs +2 -2
  291. package/scripts/cm-prd-host.mjs +10 -5
  292. package/scripts/cm-prd-host.test.mjs +4 -2
  293. package/scripts/cm-prd-inputs-replaced.test.mjs +1 -1
  294. package/scripts/cm-prd-review-disposition.test.mjs +124 -8
  295. package/scripts/cm-prd-revision.test.mjs +1 -1
  296. package/scripts/cm-prd-self-check-revision.test.mjs +16 -1
  297. package/scripts/cm-prd-self-check-rules.test.mjs +239 -0
  298. package/scripts/cm-prd-self-check.test.mjs +105 -5
  299. package/scripts/cm-prd-session-recovery.test.mjs +5 -3
  300. package/scripts/cm-prd-summary.test.mjs +55 -3
  301. package/scripts/cm-prd-task-grouping.test.mjs +6 -6
  302. package/scripts/cm-prd-tree-digest.test.mjs +74 -0
  303. package/scripts/cm-refactor-drive.mjs +2 -1
  304. package/scripts/cm-refactor-drive.test.mjs +9 -0
  305. package/scripts/cm-release-smoke.sh +3 -15
  306. package/scripts/cm-skill-hints-autowire.test.mjs +394 -0
  307. package/scripts/cm-skill-hints-exam.mjs +149 -0
  308. package/scripts/cm-skill-hints-install.test.mjs +168 -0
  309. package/scripts/cm-skill-hints.exam.json +706 -0
  310. package/scripts/cm-skill-hints.json +119 -0
  311. package/scripts/cm-skill-hints.mjs +669 -0
  312. package/scripts/cm-skill-hints.test.mjs +831 -0
  313. package/scripts/cm-skill-judge.mjs +181 -0
  314. package/scripts/cm-skill-judge.test.mjs +255 -0
  315. package/scripts/cm-specs-status.test.mjs +4 -2
  316. package/scripts/cm-start-check.mjs +208 -0
  317. package/scripts/cm-start-check.test.mjs +321 -0
  318. package/scripts/cm-task-gate.mjs +150 -29
  319. package/scripts/cm-task-gate.test.mjs +73 -1
  320. package/scripts/cm-task-id-grammar.test.mjs +66 -0
  321. package/scripts/cm-task-scope.test.mjs +308 -0
  322. package/scripts/cm-test-suite.mjs +109 -0
  323. package/scripts/cm-test-suite.test.mjs +162 -0
  324. package/scripts/cm-upgrade-compat-batch.test.mjs +172 -0
  325. package/scripts/cm-upgrade-compat.test.mjs +239 -0
  326. package/scripts/cm-workflow-config.mjs +12 -2
  327. package/scripts/fixtures/fix-verification-claude.mjs +44 -0
  328. package/scripts/fixtures/host-diagnostic.mjs +33 -0
  329. package/scripts/fixtures/reviewed-integration.mjs +202 -0
  330. package/scripts/scan-public-safety.py +1 -0
  331. package/scripts/session-boundary.test.mjs +170 -0
  332. package/scripts/test-npm-install.py +14 -3
  333. package/scripts/test-shell-compat.sh +2 -0
  334. package/scripts/validate-public-repo.py +1 -0
  335. package/scripts/validate-test-cases.mjs +3 -2
  336. package/skills/cm-ai/SKILL.md +5 -2
  337. package/skills/cm-ai/references/N4-review.md +2 -1
  338. package/skills/cm-ai/references/N6-qa-eval.md +3 -1
  339. package/skills/cm-ai/references/N8-finish.md +22 -0
  340. package/skills/cm-ai/references/js-host-qa-recovery.md +1 -1
  341. package/skills/cm-ai/references/js-host-recovery.md +79 -3
  342. package/skills/cm-ai/references/js-host.md +89 -17
  343. package/skills/cm-challenge/SKILL.md +65 -0
  344. package/skills/cm-challenge/evals/README.md +18 -0
  345. package/skills/cm-challenge/evals/trigger-cases.json +20 -0
  346. package/skills/cm-challenge/evals/trigger-config.json +28 -0
  347. package/skills/cm-challenge/references/examples.md +15 -0
  348. package/skills/cm-check/SKILL.md +5 -0
  349. package/skills/cm-check/references/js-host.md +2 -0
  350. package/skills/cm-fix/SKILL.md +12 -3
  351. package/skills/cm-fix/references/command-correction.md +67 -0
  352. package/skills/cm-fix/references/isolated-review.md +54 -0
  353. package/skills/cm-fix/references/js-host.md +62 -2
  354. package/skills/cm-fix/references/test-type-correction.md +72 -0
  355. package/skills/cm-fix/references/verification-recovery.md +114 -0
  356. package/skills/cm-idea/SKILL.md +2 -0
  357. package/skills/cm-idea/references/js-host.md +2 -0
  358. package/skills/cm-notify/SKILL.md +2 -0
  359. package/skills/cm-prd/SKILL.md +12 -8
  360. package/skills/cm-prd/references/brownfield.md +8 -1
  361. package/skills/cm-prd/references/change-mode.md +6 -0
  362. package/skills/cm-prd/references/greenfield.md +4 -0
  363. package/skills/cm-prd/references/js-host.md +4 -2
  364. package/skills/cm-prd/references/spec-self-check.md +5 -1
  365. package/skills/cm-refactor/SKILL.md +8 -0
  366. package/skills/cm-refactor/references/js-host.md +2 -0
  367. package/skills/cm-test/SKILL.md +4 -0
  368. package/templates/dashboard/dashboard.html +2 -2
  369. package/templates/pixel/cm-pixel.html +1 -1
  370. package/templates/pixel/cm-pixel.sh +1 -1
  371. package/templates/pixel/dev/template.html +1 -1
  372. package/templates/statusline/cm-statusline.sh +1 -1
@@ -8,13 +8,18 @@ import childProcess from 'node:child_process';
8
8
  import {fileURLToPath} from 'node:url';
9
9
  import {inspectFixWalkthrough,readFixWalkthrough,fixWalkthroughBinding} from '../runtime/js/cm-fix/walkthrough.mjs';
10
10
  import {inspectFixRegressionFailure} from '../runtime/js/cm-fix/regression-evidence.mjs';
11
- import {taskDeclarations,approvedTaskGrammar,TASK_GRAMMAR} from '../runtime/js/spec-task-line.mjs';
11
+ import {taskDeclarations,approvedTaskGrammar,LEGACY_TASK_GRAMMAR} from '../runtime/js/spec-task-line.mjs';
12
+ import {statesZeroBlockingFindings,ZERO_BLOCKING_PHRASES,REVIEWER_SOURCES} from '../runtime/js/review-findings.mjs';
12
13
  import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
14
+ import {readExecutionSnapshot} from '../runtime/js/cm-ai/execution-snapshot.mjs';
15
+ import {readRunnerHistory} from '../runtime/js/cm-ai/durable-runner-state.mjs';
16
+ import {resolveCheckpointPackage} from '../runtime/js/cm-ai/checkpoint-package-material.mjs';
17
+ import {publishHostReview} from '../runtime/js/cm-ai/host-review-file.mjs';
13
18
  import {snapshot,rootPath,reviewSpecsPath,stableIgnorePolicy,stablePublicPolicy,stableSnapshotPolicy,
14
19
  comparableFiles,validateStablePolicy,filePath,INVENTORY_COUNT,INVENTORY_LIMIT} from '../runtime/js/cm-ai/review-package.mjs';
15
20
 
16
21
  const TASK_RE=/^T-[A-Za-z0-9][A-Za-z0-9._-]*$/;
17
- const REVIEWERS=new Set(['codex-subagent','codex-cli','claude-cli','self-degraded']);
22
+ const REVIEWERS=new Set(REVIEWER_SOURCES);
18
23
  const VERDICTS=new Set(['approved','changes_requested','blocked']);
19
24
  const PREPARATION_FILE_LIMIT=256*1024;
20
25
  let preparationReadLimit=null;
@@ -398,9 +403,9 @@ function parseReview(review){
398
403
  }
399
404
  if(scope.length===0)throw new GateError(`review evidence scope must contain at least one entry: ${review}`);
400
405
  if(new Set(scope).size!==scope.length)throw new GateError(`review evidence scope must not contain duplicates: ${review}`);
401
- const body=lines.slice(end+1).join('\n').trim();
406
+ const rawBody=lines.slice(end+1).join('\n'),body=rawBody.trim();
402
407
  if(!body)throw new GateError(`review evidence body must not be empty: ${review}`);
403
- return {header:scalars,scope,body};
408
+ return {header:scalars,scope,body,rawBody};
404
409
  }
405
410
 
406
411
  function sha256(file){
@@ -417,7 +422,7 @@ function integerHeader(value,label){
417
422
  }
418
423
 
419
424
  export function validateReview(review,{task,attempt,handoff,changedFiles}){
420
- const {header,scope,body}=parseReview(review);
425
+ const {header,scope,rawBody}=parseReview(review);
421
426
  const required=['at','reviewer','independent','task','attempt','round','verdict','handoff','handoff_sha256','blocking_findings'];
422
427
  const missing=required.filter(field=>!Object.hasOwn(header,field)).sort();
423
428
  if(missing.length)throw new GateError(`review header missing fields: ${missing.join(', ')}`);
@@ -429,7 +434,7 @@ export function validateReview(review,{task,attempt,handoff,changedFiles}){
429
434
  if(reviewAttempt!==BigInt(attempt)||reviewRound!==BigInt(attempt))
430
435
  throw new GateError('review attempt and round must match the handoff attempt');
431
436
  // Source declarations only: validate spelling and consistency, not reviewer identity.
432
- if(!REVIEWERS.has(header.reviewer))throw new GateError(`unsupported reviewer source declaration: ${header.reviewer}`);
437
+ if(!REVIEWERS.has(header.reviewer))throw new GateError(`unsupported reviewer source declaration: ${header.reviewer} (write exactly one of ${REVIEWER_SOURCES.join(', ')}; put model or other notes in the body; ask the reviewer to regenerate the evidence, do not edit it yourself)`);
433
438
  const independent=header.independent.toLowerCase();
434
439
  if(!['true','false'].includes(independent))throw new GateError('review independent declaration must be true or false');
435
440
  if(header.reviewer==='self-degraded'&&independent!=='false')
@@ -445,8 +450,8 @@ export function validateReview(review,{task,attempt,handoff,changedFiles}){
445
450
  throw new GateError('non-approved review must declare at least one blocking finding');
446
451
  if(header.reviewer==='self-degraded'&&!header.degraded_reason?.trim())
447
452
  throw new GateError('self-degraded review must include degraded_reason');
448
- if(header.verdict==='approved'&&!/(零发现|无阻塞发现|未发现阻塞|zero findings|no findings|no blocking findings)/i.test(body))
449
- throw new GateError('approved review body must explicitly state zero blocking findings');
453
+ if(header.verdict==='approved'&&!statesZeroBlockingFindings(rawBody,{at:header.at}))
454
+ throw new GateError(`approved review body must explicitly state zero blocking findings as its first line, unindented and containing only the conclusion, e.g. "结论:零阻塞发现。" (accepted phrases: ${ZERO_BLOCKING_PHRASES.join(' / ')}); ask the reviewer to regenerate the evidence, do not edit it yourself)`);
450
455
  if(attempt===2&&header.verdict==='changes_requested')
451
456
  throw new GateError('round 2 blocking findings must use verdict: blocked');
452
457
  if(header.handoff!==path.basename(handoff))
@@ -524,8 +529,94 @@ function validateFixWalkthroughRetry({prior,payload,priorPayload,priorReview,fea
524
529
  }
525
530
  }
526
531
 
527
- function validateAttemptChain(reviewsDir,feature,task,attempt,payload,projectRoot){
532
+ // Discover this task's recovery from retained owner records, so deleting a
533
+ // handoff marker or changing a Markdown verdict cannot select legacy gates.
534
+ function completionReworkOwner(reviewsDir,feature,task,projectRoot){
535
+ const root=path.join(reviewsDir,'.execution');let names;
536
+ try{const stat=fs.lstatSync(root);if(!stat.isDirectory()||stat.isSymbolicLink()||fs.realpathSync(root)!==root)
537
+ throw new GateError('invalid completion rework owner directory');
538
+ names=fs.readdirSync(root);}catch(error){if(error.code==='ENOENT')return null;throw error;}
539
+ if(names.length>1024)throw new GateError('completion rework owner inventory exceeds bound');
540
+ const candidates=[];
541
+ for(const name of names){
542
+ const dir=path.join(root,name),stat=fs.lstatSync(dir);
543
+ if(stat.isSymbolicLink())throw new GateError('invalid completion rework owner directory');
544
+ if(!stat.isDirectory())continue;
545
+ const file=path.join(dir,'state.json');let raw;
546
+ try{fs.lstatSync(file);}catch(error){if(error.code==='ENOENT')continue;throw error;}
547
+ try{raw=JSON.parse(fileRevision(file,16*1024*1024).bytes.toString('utf8'));}
548
+ catch(error){if(error.code==='ENOENT')continue;throw error;}
549
+ const config=raw.records?.[0]?.payload?.config;
550
+ if(config?.identity?.taskId!==task||config.taskLearning?.feature.replace(/^\d+\./,'')!==feature
551
+ ||projectRoot!==null&&config.root!==projectRoot
552
+ ||!raw.records.some(row=>['completion-rework-requested','evidence-superseded'].includes(row.payload.type)))continue;
553
+ const snapshot=readExecutionSnapshot({specsRoot:path.dirname(reviewsDir),identity:raw.identity});
554
+ const history=readRunnerHistory(snapshot.records,config,3);candidates.push({snapshot,history});
555
+ }
556
+ return activeCompletionReworkOwner(candidates);
557
+ }
558
+ // Called only after strict snapshot/replay validation. Supersession never
559
+ // deletes the old evidence; it prevents a retired owner blocking its successor.
560
+ export function activeCompletionReworkOwner(candidates){
561
+ const retired=new Set(candidates.flatMap(({history})=>history.supersession?.previousRunIds??[]));
562
+ const owners=candidates.filter(({snapshot})=>!retired.has(snapshot.identity.runId)
563
+ &&snapshot.records.some(row=>row.payload.type==='completion-rework-requested'));
564
+ if(owners.length>1)throw new GateError('ambiguous completion rework owner');
565
+ return owners[0]?.snapshot??null;
566
+ }
567
+
568
+ // This marker locates the real owner journal; it is never itself approval.
569
+ function validateCompletionRework({payload,priorPayload,feature,task,projectRoot,reviewsDir,stage,owner}){
570
+ const prefix='cm-completion-rework-v1: ',markers=payload.evidence.filter(item=>item.startsWith(prefix));
571
+ if(markers.length!==1)throw new GateError('approved r1 requires a bound completion rework');
572
+ try{
573
+ const marker=JSON.parse(markers[0].slice(prefix.length));
574
+ if(canonical(Object.keys(marker).sort())!==canonical(['identity','recordDigest'])
575
+ ||marker.identity.taskId!==task||marker.identity.attempt!==2)throw new GateError('invalid completion rework');
576
+ const snapshot=readExecutionSnapshot({specsRoot:fs.realpathSync(reviewsDir+'/..'),
577
+ identity:{repositoryId:marker.identity.repositoryId,runId:marker.identity.runId}});
578
+ if(owner&&owner.revision!==snapshot.revision)throw new GateError('completion rework owner changed');
579
+ const config=snapshot.records[0].payload.config;
580
+ const records=snapshot.records.filter(row=>row.payload.type==='completion-rework-requested');
581
+ if(records.length!==1||records[0].digest!==marker.recordDigest||config.taskLearning?.feature.replace(/^\d+\./,'')!==feature
582
+ ||config.identity.taskId!==task||config.root!==fs.realpathSync(projectRoot))throw new GateError('unbound completion rework');
583
+ const history=readRunnerHistory(snapshot.records,config,3),record=records[0].payload;
584
+ const prior=history.state.receipts.find(item=>item.identity.attempt===1);
585
+ if(!prior||prior.result.verdict!=='approved'||prior.receiptDigest!==record.receiptDigest
586
+ ||prior.packageDigest!==record.packageDigest||history.state.attempt!==2
587
+ ||history.state.reviewPackage?.identity.attempt!==2
588
+ ||history.state.reviewPackage.handoff?.sha256!==sha256(expectedHandoff(reviewsDir,feature,task,2))
589
+ ||history.state.reviewPackage.artifactDigest===record.artifactDigest)
590
+ throw new GateError('completion rework must bind a new reviewed delivery');
591
+ // A large package may be stored once and referenced by later checkpoints;
592
+ // resolve it with the same validation replay uses.
593
+ const originalReview=snapshot.records.map((row,index)=>row.payload.type==='effect-checkpoint'
594
+ &&row.payload.checkpoint.receipt?.receiptDigest===prior.receiptDigest
595
+ ?{payload:{checkpoint:resolveCheckpointPackage(row.payload,snapshot.records.slice(0,index),config.identity)}}:null)
596
+ .find(row=>row?.payload.checkpoint.reviewPackage?.identity.attempt===1);
597
+ const originalRegistration=snapshot.records.find(row=>row.payload.type==='review-invocation-registered'
598
+ &&row.payload.binding.invocationId===prior.id);
599
+ if(!originalReview||!originalRegistration)throw new GateError('missing original approved review');
600
+ publishHostReview({reviewsDir,feature,handoffPath:expectedHandoff(reviewsDir,feature,task,1),
601
+ reviewPackage:originalReview.payload.checkpoint.reviewPackage,receipt:prior,registered:prior,
602
+ at:originalRegistration.payload.registeredAt,inspectOnly:true});
603
+ if(stage==='n5'){
604
+ const receipt=history.state.receipt,pkg=history.state.reviewPackage;
605
+ if(receipt?.identity.attempt!==2||receipt.result.verdict!=='approved'||receipt.packageDigest!==pkg.packageDigest)
606
+ throw new GateError('completion rework requires the real approved a2 receipt');
607
+ publishHostReview({reviewsDir,feature,handoffPath:expectedHandoff(reviewsDir,feature,task,2),reviewPackage:pkg,
608
+ receipt,registered:receipt,at:history.state.reviewInvocation.registration.registeredAt,inspectOnly:true});
609
+ }
610
+
611
+ }catch(error){throw new GateError('invalid completion rework owner evidence: '+error.message);}
612
+ }
613
+
614
+ function validateAttemptChain(reviewsDir,feature,task,attempt,payload,projectRoot,stage='n4'){
528
615
  if(attempt!==2)return;
616
+ if(projectRoot!==null)projectRoot=fs.realpathSync(path.resolve(projectRoot));
617
+ const requestedReviews=path.resolve(reviewsDir),reviewStat=fs.lstatSync(requestedReviews);
618
+ if(!reviewStat.isDirectory()||reviewStat.isSymbolicLink())throw new GateError('invalid completion rework review directory');
619
+ reviewsDir=fs.realpathSync(requestedReviews);
529
620
  const priorHandoff=expectedHandoff(reviewsDir,feature,task,1);
530
621
  requireExpectedHandoff(priorHandoff,{reviewsDir,feature,task,attempt:1});
531
622
  const priorPayload=loadHandoff(priorHandoff,{task,attempt:1});
@@ -534,9 +625,12 @@ function validateAttemptChain(reviewsDir,feature,task,attempt,payload,projectRoo
534
625
  const prior=validateReview(reviewPath(reviewsDir,feature,task,1),{
535
626
  task,attempt:1,handoff:priorHandoff,changedFiles:priorPayload.changed_files,
536
627
  });
537
- if(prior.verdict==='approved'){
628
+ const owner=completionReworkOwner(reviewsDir,feature,task,projectRoot);
629
+ if(owner||payload.evidence.some(item=>item.startsWith('cm-completion-rework-v1: ')))
630
+ validateCompletionRework({payload,priorPayload,feature,task,projectRoot,reviewsDir,stage,owner});
631
+ else if(prior.verdict==='approved')
538
632
  validateFixWalkthroughRetry({prior,payload,priorPayload,priorReview:reviewPath(reviewsDir,feature,task,1),feature,task,projectRoot});
539
- }else if(prior.verdict!=='changes_requested')
633
+ else if(prior.verdict!=='changes_requested')
540
634
  throw new GateError('attempt 2 requires round 1 verdict: changes_requested');
541
635
  }
542
636
 
@@ -947,7 +1041,7 @@ export function checkN5({handoff,reviewsDir,feature,task,projectRoot=null,allowL
947
1041
  if(requireLearning)verifyLearningRecord(payload,projectRoot);
948
1042
  const attempt=payload.attempt;
949
1043
  requireExpectedHandoff(handoff,{reviewsDir,feature,task,attempt});
950
- validateAttemptChain(reviewsDir,feature,task,attempt,payload,projectRoot);
1044
+ validateAttemptChain(reviewsDir,feature,task,attempt,payload,projectRoot,'n5');
951
1045
  const contentBound=verifyImplementationBinding(payload,{projectRoot,allowLegacyUnbound});
952
1046
  const inventoryResult=inventory==='required'?verifyInventory(payload,{projectRoot,reviewsDir,feature,task,allowLegacyUnbound}):{};
953
1047
  const review=reviewPath(reviewsDir,feature,task,attempt);
@@ -1066,7 +1160,7 @@ function splitLinesKeepEnds(text){
1066
1160
  function withoutLineEnding(line){return line.replace(/(?:\r\n|[\n\r\v\f\x1c-\x1e\x85\u2028\u2029])$/,'');}
1067
1161
  function escapeRegExp(value){return value.replace(/[.*+?^${}()|[\]\\]/g,'\\$&');}
1068
1162
 
1069
- // An approval recorded with taskGrammar 2 uses the shared declaration grammar
1163
+ // An approval recorded with taskGrammar 2 or 3 uses the shared declaration grammar
1070
1164
  // (spec-task-line.mjs): fenced examples are never flipped. Approvals recorded
1071
1165
  // earlier keep the exact original mark-done match on the bytes they approved.
1072
1166
  function parseTaskTarget(task,tasksPath,revision){
@@ -1074,7 +1168,7 @@ function parseTaskTarget(task,tasksPath,revision){
1074
1168
  try{text=new TextDecoder('utf-8',{fatal:true,ignoreBOM:true}).decode(revision.bytes);}
1075
1169
  catch(error){throw new GateError(`cannot read tasks file ${tasksPath}: ${error.message}`);}
1076
1170
  let matches;
1077
- if(approvedTaskGrammar(path.dirname(path.dirname(tasksPath)))===TASK_GRAMMAR)
1171
+ if(approvedTaskGrammar(path.dirname(path.dirname(tasksPath)))!==LEGACY_TASK_GRAMMAR)
1078
1172
  matches=taskDeclarations(text).filter(item=>item.id===task).map(item=>({start:item.start,markOffset:item.markOffset,completed:item.completed}));
1079
1173
  else{
1080
1174
  const pattern=new RegExp(`^(\\s*-\\s*)\\[([ xX])\\](\\s+${escapeRegExp(task)}(?=[:\\s]|$).*)$`);
@@ -1233,10 +1327,25 @@ function parseAssignment(raw){
1233
1327
  catch(error){throw new GateError(`cannot resolve assignment path ${rawPath}: ${error.message}`);}
1234
1328
  }
1235
1329
 
1236
- export function checkParallelWrite({repo,assignment}){
1237
- let repository;
1238
- try{repository=fs.realpathSync.native(repo);}
1330
+ function resolveRepository(repo){
1331
+ try{return fs.realpathSync.native(repo);}
1239
1332
  catch(error){throw new GateError(`cannot resolve repository ${repo}: ${error.message}`);}
1333
+ }
1334
+ // One writer's worktree: registered, of this repository, on its own named branch.
1335
+ function checkAssignedWorktree(item,{baseCommon,registered}){
1336
+ const metadata=registered.get(pathKey(item.worktree));
1337
+ if(!metadata)throw new GateError(`${item.task} path is not a registered worktree: ${item.worktree}`);
1338
+ if(commonGitDir(item.worktree)!==baseCommon)
1339
+ throw new GateError(`${item.task} worktree belongs to a different repository`);
1340
+ const observed=runGit(item.worktree,'branch','--show-current');
1341
+ if(metadata.detached||!metadata.branch||!observed)
1342
+ throw new GateError(`${item.task} worktree must use a non-detached branch`);
1343
+ if(metadata.branch!==observed)throw new GateError(`${item.task} branch metadata does not match the worktree`);
1344
+ return {...item,branch:metadata.branch};
1345
+ }
1346
+
1347
+ export function checkParallelWrite({repo,assignment}){
1348
+ const repository=resolveRepository(repo);
1240
1349
  if(!Array.isArray(assignment)||assignment.length<2)
1241
1350
  throw new GateError('parallel write guard requires at least two assignments');
1242
1351
  const baseCommon=commonGitDir(repository),registered=registeredWorktrees(repository);
@@ -1245,23 +1354,35 @@ export function checkParallelWrite({repo,assignment}){
1245
1354
  throw new GateError('parallel write assignments must use unique task ids');
1246
1355
  if(new Set(assignments.map(item=>pathKey(item.worktree))).size!==assignments.length)
1247
1356
  throw new GateError('parallel write assignments must use distinct worktree paths');
1248
- const result=[];
1249
- for(const item of assignments){
1250
- const metadata=registered.get(pathKey(item.worktree));
1251
- if(!metadata)throw new GateError(`${item.task} path is not a registered worktree: ${item.worktree}`);
1252
- if(commonGitDir(item.worktree)!==baseCommon)
1253
- throw new GateError(`${item.task} worktree belongs to a different repository`);
1254
- const observed=runGit(item.worktree,'branch','--show-current');
1255
- if(metadata.detached||!metadata.branch||!observed)
1256
- throw new GateError(`${item.task} worktree must use a non-detached branch`);
1257
- if(metadata.branch!==observed)throw new GateError(`${item.task} branch metadata does not match the worktree`);
1258
- result.push({...item,branch:metadata.branch});
1259
- }
1357
+ const result=assignments.map(item=>checkAssignedWorktree(item,{baseCommon,registered}));
1260
1358
  if(new Set(result.map(item=>item.branch)).size!==result.length)
1261
1359
  throw new GateError('parallel write assignments must use distinct branches');
1262
1360
  return {gate:'parallel-write',outcome:'isolated',assignments:result};
1263
1361
  }
1264
1362
 
1363
+ // A single writer in its own worktree while the main checkout only waits to merge it
1364
+ // (a one-member batch group). The worktree gets the same checks as a parallel
1365
+ // assignment, and it must not share the main checkout's branch. The main checkout
1366
+ // itself writes nothing meanwhile, so it may sit on a detached HEAD (map ticket 04:
1367
+ // it used to be padded in as a second assignment and had to be on a branch).
1368
+ export function checkSoloWrite({repo,assignment}){
1369
+ const repository=resolveRepository(repo);
1370
+ const registered=registeredWorktrees(repository);
1371
+ // Review 2026-10-27 round 1: the old padding also proved the main checkout is itself a
1372
+ // registered worktree. A copied linked worktree is not, yet shares the original's index
1373
+ // and HEAD, so merges there would write another checkout's state. Only the branch
1374
+ // requirement is relaxed: registration and matching metadata stay.
1375
+ const mainMetadata=registered.get(pathKey(repository));
1376
+ if(!mainMetadata)throw new GateError(`main checkout is not a registered worktree: ${repository}`);
1377
+ const main=runGit(repository,'branch','--show-current');
1378
+ if(mainMetadata.detached?main!=='':(!main||mainMetadata.branch!==main))
1379
+ throw new GateError('main checkout branch metadata does not match the worktree');
1380
+ const item=checkAssignedWorktree(parseAssignment(assignment),{baseCommon:commonGitDir(repository),registered});
1381
+ if(pathKey(item.worktree)===pathKey(repository))throw new GateError(`${item.task} must use its own worktree, not the main checkout`);
1382
+ if(main&&main===item.branch)throw new GateError(`${item.task} worktree must not use the main checkout's branch`);
1383
+ return {gate:'solo-write',outcome:'isolated',assignments:[item]};
1384
+ }
1385
+
1265
1386
  function usage(){return 'usage: cm-task-gate.mjs {capture-baseline|validate-handoff|hash-implementation|check-n4|check-n5|prepare-mark-done|verify-mark-done-plan|prepare-human-correction|publish-human-correction-review|prepare-controlled-correction|publish-controlled-correction-review|check-parallel-write} [options]';}
1266
1387
 
1267
1388
  function parseCli(argv){
@@ -9,7 +9,7 @@ import {fileURLToPath} from 'node:url';
9
9
 
10
10
  import {
11
11
  GateError,checkN4,checkN5,implementationSha256,loadHandoff,prepareMarkDone,verifyMarkDonePlan,validateReview,
12
- checkParallelWrite,markDoneLocked,
12
+ checkParallelWrite,checkSoloWrite,markDoneLocked,
13
13
  } from './cm-task-gate.mjs';
14
14
 
15
15
  const scriptsRoot=fileURLToPath(new URL('.',import.meta.url));
@@ -183,6 +183,43 @@ test('JS parallel-write gate accepts isolated worktrees and rejects duplicate as
183
183
  assert.throws(()=>checkParallelWrite({repo,assignment:[assignments[0],`T-001=${worktree}`]}),GateError);
184
184
  }));
185
185
 
186
+ // Map ticket 04: one writer while the main checkout only waits to merge it.
187
+ test('JS solo-write gate: the worker needs its own branch; the main checkout may be detached',()=>fixture(root=>{
188
+ const repo=path.join(root,'repo'),worktree=path.join(root,'worker'),other=path.join(root,'other');fs.mkdirSync(repo);
189
+ const git=(directory,...args)=>{
190
+ const result=spawnSync('git',['-C',directory,...args],{encoding:'utf8'});
191
+ assert.equal(result.status,0,result.stderr);return result.stdout.trim();
192
+ };
193
+ git(repo,'init','-b','main');git(repo,'config','user.name','CM Fixture');git(repo,'config','user.email','fixture@example.invalid');
194
+ fs.writeFileSync(path.join(repo,'fixture.txt'),'fixture\n');git(repo,'add','fixture.txt');git(repo,'commit','-m','fixture');
195
+ git(repo,'worktree','add','-b','worker',worktree);
196
+ assert.deepEqual(checkSoloWrite({repo,assignment:`T-001=${worktree}`}),
197
+ {gate:'solo-write',outcome:'isolated',assignments:[{task:'T-001',worktree:fs.realpathSync.native(worktree),branch:'worker'}]});
198
+ // The old padding stopped here: the main checkout on a detached HEAD.
199
+ git(repo,'checkout','-q','--detach');
200
+ assert.throws(()=>checkParallelWrite({repo,assignment:[`T-001=${worktree}`,`T-batch-main=${repo}`]}),/T-batch-main worktree must use a non-detached branch/);
201
+ assert.equal(checkSoloWrite({repo,assignment:`T-001=${worktree}`}).outcome,'isolated');
202
+ // The worker itself still needs a branch, its own worktree and this repository.
203
+ assert.throws(()=>checkSoloWrite({repo,assignment:`T-001=${repo}`}),/non-detached branch/);
204
+ git(repo,'checkout','-q','main');
205
+ assert.throws(()=>checkSoloWrite({repo,assignment:`T-001=${repo}`}),/must use its own worktree, not the main checkout/);
206
+ git(worktree,'checkout','-q','--detach');
207
+ assert.throws(()=>checkSoloWrite({repo,assignment:`T-001=${worktree}`}),/non-detached branch/);
208
+ fs.mkdirSync(other);
209
+ assert.throws(()=>checkSoloWrite({repo,assignment:`T-001=${other}`}),/not a registered worktree/);
210
+ assert.throws(()=>checkSoloWrite({repo,assignment:'T-001=relative/path'}),/must be absolute/);
211
+ // Review round 1: a copy of a linked worktree as the main checkout shares that
212
+ // worktree's index and HEAD but is not registered; it is refused, as the old padding did.
213
+ git(worktree,'checkout','-q','worker');
214
+ const second=path.join(root,'second'),copy=path.join(root,'copy');
215
+ git(repo,'worktree','add','-b','second',second);
216
+ fs.cpSync(worktree,copy,{recursive:true});
217
+ assert.equal(git(copy,'rev-parse','--is-inside-work-tree'),'true');
218
+ assert.throws(()=>checkParallelWrite({repo:copy,assignment:[`T-001=${second}`,`T-batch-main=${copy}`]}),/T-batch-main path is not a registered worktree/);
219
+ assert.throws(()=>checkSoloWrite({repo:copy,assignment:`T-001=${second}`}),/main checkout is not a registered worktree/);
220
+ assert.equal(checkSoloWrite({repo:worktree,assignment:`T-001=${second}`}).outcome,'isolated','the registered original is fine');
221
+ }));
222
+
186
223
  test('Windows lock serializes two task completions without losing either checkbox',{skip:process.platform!=='win32'},()=>fixture(async root=>{
187
224
  const reviews=path.join(root,'.reviews');fs.mkdirSync(reviews);
188
225
  const tasks=path.join(root,'tasks.md');fs.writeFileSync(tasks,'- [ ] T-001: first\r\n- [ ] T-002: second\r\n');
@@ -202,6 +239,41 @@ test('Windows lock serializes two task completions without losing either checkbo
202
239
  }));
203
240
 
204
241
 
242
+ test('approved body must open with an unindented zero-blocking conclusion line; older evidence keeps the legacy reading',()=>fixture(root=>{
243
+ const handoff=path.join(root,'handoff.json'),review=path.join(root,'review.md');
244
+ writeHandoff(handoff);writeReview(review,{handoff});
245
+ const legacy=fs.readFileSync(review,'utf8'),selected={task:'T-001',attempt:1,handoff,changedFiles:['src/example.ts']};
246
+ const strict=legacy.replace('at: 2026-09-06T07:00:00-07:00','at: 2026-10-21T08:00:00Z');
247
+ const accepts=(base,body)=>{fs.writeFileSync(review,base.replace('Zero findings.',body));return validateReview(review,selected).verdict==='approved';};
248
+ const rejects=(base,body)=>{fs.writeFileSync(review,base.replace('Zero findings.',body));
249
+ assert.throws(()=>validateReview(review,selected),error=>error instanceof GateError&&/explicitly state zero blocking findings/.test(error.message),body);};
250
+ for(const phrase of ['零发现','零阻塞发现','零阻断发现','无阻塞发现','无阻断发现','未发现阻塞','未发现阻断','Zero findings','no findings','No blocking findings'])
251
+ assert.ok(accepts(strict,`结论:${phrase}。\n\n审查了全部范围。`),phrase);
252
+ for(const body of ['Zero findings.','No blocking findings.','- **结论:** 零阻断发现。','**结论:零阻塞发现。**','**结论**:零阻塞发现。',
253
+ 'Conclusion: no blocking findings','结论:零阻塞发现。\r\n\r\n说明。'])
254
+ assert.ok(accepts(strict,body),body);
255
+ for(const body of ['未发现阻断问题以外的问题。','零阻断发现?','零阻断发现 ?','不能说零阻塞发现。','零阻断发现,并不成立。仍有一个阻断问题。',
256
+ '不能宣称 e.g. no blocking findings,因为仍有阻断问题。','结论:approved,零 findings。No blocking findings. 已核对 handoff。',
257
+ '> 其他审查:零阻断发现\n\n本次仍存在一个阻断问题。','> 结论:零阻塞发现。\n\n本次仍存在一个阻断问题。','{"conclusion":"> Zero findings."}','```\nZero findings.\n```','~~~\n~~~javascript\nZero findings.',
258
+ '{"conclusion":"> 旧结果。No blocking findings."}','{"conclusion":"~~~\\n说明。Zero findings.\\n~~~"}','["e.g. No blocking findings."]',
259
+ '{"summary":"x"}\n','blocker、major、minor 都是 0。',
260
+ '- ~~~\n Zero findings.\n ~~~\n\n本次仍有阻断。','- a\n - ````\n 零阻塞发现。\n ````','1. ```\nZero findings.\n```',
261
+ '<!--\nZero findings.\n-->','<!-- 草稿 -->\n Zero findings.','说明。\n 结论:零阻塞发现。','- 第一项\n 零阻塞发现。',
262
+ '说明。\n\n结论:零阻塞发现。','- ~~~\n 示例\n ~~~\n\n结论:零阻塞发现。','~~~markdown\n> ~~~\nZero findings.\n~~~\n本轮仍有 major。',
263
+ '<!-- old --> <!-- example\nZero findings.\n-->','\n Zero findings.\n\n本轮仍有 major。','\tZero findings.','```示例```\n\nZero findings.',
264
+ ...['\\u2028','\\u2029','\\u000b','\\u000c','\\u0085','\\r'].map(separator=>`{"conclusion":"结论:${separator}Zero findings."}`),'结论:\u2028Zero findings.'])
265
+ rejects(strict,body);
266
+ // 启用前的凭证按原判定:原有说法出现在任意位置即可,新增说法不回溯放宽。
267
+ assert.ok(accepts(legacy,'结论:approved,零 findings。No blocking findings. 已核对 handoff。'));
268
+ rejects(legacy,'结论:零阻断发现。');
269
+ fs.writeFileSync(review,strict.replace('Zero findings.','blocker、major、minor 都是 0。'));
270
+ assert.throws(()=>validateReview(review,selected),error=>error instanceof GateError
271
+ &&/as its first line, unindented/.test(error.message)&&/零阻塞发现/.test(error.message)&&/regenerate/.test(error.message));
272
+ fs.writeFileSync(review,strict.replace('reviewer: codex-subagent','reviewer: codex-cli (gpt-6.1-sol, reasoning high, read-only)'));
273
+ assert.throws(()=>validateReview(review,selected),error=>error instanceof GateError
274
+ &&/unsupported reviewer source declaration/.test(error.message)&&/codex-subagent, codex-cli, claude-cli, self-degraded/.test(error.message));
275
+ }));
276
+
205
277
  test('reviewer and independent fields validate declaration format and consistency',()=>fixture(root=>{
206
278
  const handoff=path.join(root,'handoff.json'),review=path.join(root,'review.md');
207
279
  writeHandoff(handoff);writeReview(review,{handoff});
@@ -0,0 +1,66 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import fs from 'node:fs';
4
+ import os from 'node:os';
5
+ import path from 'node:path';
6
+ import {spawnSync} from 'node:child_process';
7
+ import {fileURLToPath} from 'node:url';
8
+ import {isTaskId,taskDeclarations,LEGACY_TASK_GRAMMAR} from '../runtime/js/spec-task-line.mjs';
9
+ import {parseFeatureTaskText,validDependencies} from '../runtime/js/cm-ai/cm-ai-admission.mjs';
10
+ import {checkPrdDraftMechanics} from '../runtime/js/cm-prd/self-check.mjs';
11
+ import {inspectPrdDraft} from '../runtime/js/cm-prd/draft.mjs';
12
+ import {inspectPrdChangeProposal} from '../runtime/js/cm-prd/change.mjs';
13
+ import {validateTestCases} from './validate-test-cases.mjs';
14
+
15
+ const cases={schemaVersion:'1.0',feature:'sample',cases:[{id:'TC-001',origin:'user',kind:'logic',blocking:true,
16
+ acIds:['AC-001'],taskIds:['T-004a','T-004b','T-004c'],title:'Existing acceptance',preconditions:[],
17
+ steps:['Check the existing implementation'],expected:['Original assertions hold'],cleanup:[]}]};
18
+ const completed=['T-001','T-002','T-003'].map(id=>`- [x] ${id}: Completed`);
19
+ const children=['a','b','c'].map(suffix=>`- [ ] T-004${suffix}: [NEW v3] Review existing implementation`);
20
+ const pending=Array.from({length:9},(_,i)=>`- [ ] T-${String(i+5).padStart(3,'0')}: Existing task`);
21
+ const historical='- [ ] T-004: Original task [DROPPED v3: retain history]';
22
+ const tasks=[...completed,historical,...children,...pending,
23
+ '- T-004a 依赖 T-001, T-002, T-003','- T-004b 依赖 T-004a','- T-004c 依赖 T-004a'].join('\n');
24
+ function rawDraft(source=tasks,contract=cases){
25
+ return {status:'draft',summary:'Review-only split proposal',features:[{name:'sample',testCasesReason:null,documents:[
26
+ {path:'requirements.md',content:'- [ ] [AC-001] Original acceptance'},
27
+ {path:'design.md',content:'# Existing design'},
28
+ {path:'tasks.md',content:source},{path:'test-cases.json',content:JSON.stringify(contract)}]}]};
29
+ }
30
+ function draft(source=tasks,contract=cases){return inspectPrdDraft(rawDraft(source,contract),{nextIndex:1,generateCases:true,userCasesProvided:true});}
31
+
32
+ test('split contract: one ID grammar accepts suffixes and existing named IDs, rejects malformed references',()=>{
33
+ for(const id of ['T-001','T-004a','T-004b','T-004c','T-FIX-api','T-api.v1_beta-2']){
34
+ assert.equal(isTaskId(id),true,id);
35
+ assert.equal(taskDeclarations(`- [ ] ${id}: Item`)[0].id,id);
36
+ const contract=structuredClone(cases);contract.cases[0].taskIds=[id];assert.deepEqual(validateTestCases(contract),[]);
37
+ }
38
+ for(const id of ['T-','T-004/a','T-004a!',' T-004a','T-004a\n','T-004a\r',null]){
39
+ assert.equal(isTaskId(id),false,String(id));
40
+ if(typeof id==='string'){
41
+ const contract=structuredClone(cases);contract.cases[0].taskIds=[id];
42
+ assert(validateTestCases(contract).some(reason=>reason.includes('taskIds has invalid id')));
43
+ }
44
+ }
45
+ });
46
+
47
+ test('split contract: validator CLI accepts suffixed references and rejects invalid IDs with explicit diagnostics',t=>{
48
+ const root=fs.mkdtempSync(path.join(os.tmpdir(),'cm-split-case-contract-'));
49
+ t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
50
+ const file=path.join(root,'test-cases.json'),entry=fileURLToPath(new URL('./validate-test-cases.mjs',import.meta.url));
51
+ fs.writeFileSync(file,JSON.stringify(cases));
52
+ const accepted=spawnSync(process.execPath,[entry,file],{encoding:'utf8'});
53
+ assert.equal(accepted.status,0,accepted.stderr);assert.match(accepted.stdout,/test-cases validation: PASSED/);
54
+ const bad=structuredClone(cases);bad.cases[0].taskIds=['T-004/a'];fs.writeFileSync(file,JSON.stringify(bad));
55
+ const rejected=spawnSync(process.execPath,[entry,file],{encoding:'utf8'});
56
+ assert.equal(rejected.status,1);assert.match(rejected.stderr,/taskIds has invalid id: 'T-004\/a'/);
57
+ assert.match(rejected.stderr,/test-cases validation: FAILED/);assert.equal(rejected.stdout,'');
58
+ });
59
+
60
+ test('task grammar versions are separate branches: 3 and 2 share declarations, 1 keeps the old parse',()=>{
61
+ const text='- [ ] T-001: a\n- [ ] T-002:b\n```\n- [ ] T-003: example\n```\n';
62
+ const ids=grammar=>taskDeclarations(text,{grammar}).map(item=>item.id);
63
+ assert.deepEqual(ids(3),['T-001','T-002']);assert.deepEqual(ids(2),['T-001','T-002']);
64
+ assert.deepEqual(ids(LEGACY_TASK_GRAMMAR),['T-001','T-003']);
65
+ assert.throws(()=>taskDeclarations(text,{grammar:4}),{code:'task_grammar_invalid'});
66
+ });