@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
@@ -3,8 +3,13 @@ import assert from 'node:assert/strict';
3
3
  import fs from 'node:fs';
4
4
  import os from 'node:os';
5
5
  import path from 'node:path';
6
- import {spawnSync} from 'node:child_process';
6
+ import {createHash} from 'node:crypto';
7
+ const digestForFile=file=>createHash('sha256').update(fs.readFileSync(file)).digest('hex');
8
+ import {spawn,spawnSync} from 'node:child_process';
7
9
  import {fileURLToPath} from 'node:url';
10
+ import {readRunnerHistory,completionReworkBinding,pendingDevelopStart,developTimeoutBasis} from '../runtime/js/cm-ai/durable-runner-state.mjs';
11
+ import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
12
+ import {checkN5,activeCompletionReworkOwner} from './cm-task-gate.mjs';
8
13
  import {buildManifest} from './cm-spec-manifest.mjs';
9
14
  import {configFingerprint} from '../runtime/js/cm-ai/codex-config.mjs';
10
15
  import {readDriverControl,controlDevelopAttempts,buildCmAiDriveHostArgs,buildCmAiDriveRequest} from './cm-ai-drive.mjs';
@@ -63,7 +68,8 @@ function fixture(t,batch=false,qaRun=false){
63
68
  };
64
69
  const drive=(file,operation='advance')=>spawnSync(process.execPath,[batch?BATCH:SINGLE,'--plan',file,operation],{encoding:'utf8',timeout:60000,
65
70
  env:{...process.env,PATH:bin+path.delimiter+process.env.PATH,CM_WORKFLOW_HOME:path.join(root,'home'),CM_WORKFLOW_LOG_HOME:path.join(root,'logs')}});
66
- return {root,codeProject,specsDir,answers,plan,drive,review};
71
+ return {root,codeProject,specsDir,answers,plan,drive,review,env:{...process.env,PATH:bin+path.delimiter+process.env.PATH,
72
+ CM_WORKFLOW_HOME:path.join(root,'home'),CM_WORKFLOW_LOG_HOME:path.join(root,'logs')}};
67
73
  }
68
74
 
69
75
  test('v2 launch arguments replace the development grant and leave legacy launch intact',()=>{
@@ -256,15 +262,404 @@ test('v2 disabled QA still assesses mandatory feature completion and cannot repo
256
262
  r=f.drive(f.plan({mode:'resume',originalHostContext:'v2-fixture-host'}));assert.equal(r.status,0,r.stderr);
257
263
  result=JSON.parse(r.stdout).result;combined+=r.stderr;
258
264
  }
259
- assert.match(combined,/应答 qa_assess/);
265
+ // qa:"disabled": the host confirms the read-only assessment itself; the decision is still made.
266
+ assert.doesNotMatch(combined,/应答 qa_assess/);
260
267
  assert.equal(result.code,'qa_triggered',JSON.stringify(result));assert.equal(result.pendingAction,'qa_execution');
261
268
  assert.notEqual(result.state,'run_done');
262
269
  const rows=fs.readFileSync(path.join(f.specsDir,'运行日志.jsonl'),'utf8').trim().split('\n').map(JSON.parse);
263
270
  assert.ok(rows.some(row=>row.event==='qa'&&row.status==='triggered'&&row.reason==='feature_complete'));
264
271
  assert.equal(rows.some(row=>row.node==='N6'&&row.event==='test_run'&&row.phase==='complete'&&row.result==='PASS'),false);
265
272
  });
273
+ test('regression: single-task v2 without --workflow-config still decides QA instead of stalling at qa_decision_required',t=>{
274
+ const f=fixture(t);f.review('approved');
275
+ let r=f.drive(f.plan());assert.equal(r.status,0,r.stderr);
276
+ let result=JSON.parse(r.stdout).result,combined=r.stderr;
277
+ for(let n=0;n<3&&!['qa_triggered','qa_decision_required'].includes(result.code);n++){
278
+ r=f.drive(f.plan({mode:'resume'}));assert.equal(r.status,0,r.stderr);
279
+ result=JSON.parse(r.stdout).result;combined+=r.stderr;
280
+ }
281
+ assert.notEqual(result.code,'qa_decision_required',JSON.stringify(result));
282
+ // qa:"disabled": the host confirms the read-only assessment itself; the decision is still made.
283
+ assert.doesNotMatch(combined,/应答 qa_assess/);
284
+ // 唯一任务完成即 feature 完成:必需 QA 被触发,但 disabled 没有执行器,停在 qa_execution,不能报 run_done。
285
+ assert.equal(result.code,'qa_triggered',JSON.stringify(result));assert.equal(result.pendingAction,'qa_execution');
286
+ });
287
+
288
+ test('regression: serial batch member with workflows[key]:null still gets the implicit QA decision',t=>{
289
+ const f=fixture(t,true);f.review('approved');
290
+ const run=path.join(f.root,'run.json'),config=JSON.parse(fs.readFileSync(run,'utf8'));
291
+ config.workflows[key]=null;fs.writeFileSync(run,JSON.stringify(config));
292
+ let r=f.drive(f.plan());assert.equal(r.status,0,r.stderr);
293
+ let result=JSON.parse(r.stdout).result,combined=r.stderr;
294
+ for(let n=0;n<3&&result.code!=='qa_triggered';n++){
295
+ r=f.drive(f.plan({mode:'resume',originalHostContext:'v2-fixture-host'}));assert.equal(r.status,0,r.stderr);
296
+ result=JSON.parse(r.stdout).result;combined+=r.stderr;
297
+ }
298
+ // qa:"disabled": the host confirms the read-only assessment itself; the decision is still made.
299
+ assert.doesNotMatch(combined,/应答 qa_assess/);
300
+ assert.equal(result.code,'qa_triggered',JSON.stringify(result));assert.equal(result.pendingAction,'qa_execution');
301
+ });
302
+
266
303
  test('batch refuses unavailable QA Fix mode before starting the host',t=>{
267
304
  const f=fixture(t,true);fs.writeFileSync(path.join(f.root,'control.json'),JSON.stringify({...policy,qa:'run',qaFix:'auto'}));
268
305
  const r=f.drive(f.plan());assert.equal(r.status,2,r.stderr);assert.match(r.stderr,/invalid_arguments/);
269
306
  assert.equal(fs.existsSync(path.join(f.specsDir,'.reviews/.execution')),false);
270
307
  });
308
+
309
+
310
+ test('completion_rework keeps the original run and failure, requires fresh a2 review (real CLI)',t=>{
311
+ const f=fixture(t);f.review('approved');
312
+ fs.writeFileSync(path.join(f.specsDir,'1.work/tasks.md'),' - [ ] T-001:fixture\n\n```md\n- [ ] T-001: example\n```\n');
313
+ fs.writeFileSync(path.join(f.specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',taskGrammar:2,
314
+ features:['1.work'],specFiles:buildManifest(f.specsDir)}));
315
+ const marker=path.join(f.root,'checks-pass');fs.writeFileSync(marker,'pass');
316
+ const checks=[{id:'gate',command:[process.execPath,'-e',`process.exit(require('node:fs').existsSync(${JSON.stringify(marker)})?0:1)`]}];
317
+ const run=(op,extra={})=>{const r=f.drive(f.plan({mode:'resume',originalHostContext:'v2-fixture-host',checks,...extra}),op);
318
+ assert.equal(r.status,0,r.stderr);return JSON.parse(r.stdout).result;};
319
+ const delivered=run('start',{mode:'create',originalHostContext:undefined});
320
+ const pkg=delivered.packageDigest;assert.equal(run('decision',{packageDigest:pkg}).state,'approved');
321
+ const reviewDir=path.join(f.specsDir,'.reviews'),r1=path.join(reviewDir,'work-T-001-r1.md');
322
+ const handoff=path.join(reviewDir,'work-T-001-a1-handoff.json');
323
+ const oldReview=fs.readFileSync(r1),oldHandoff=fs.readFileSync(handoff);
324
+ fs.rmSync(marker);assert.equal(run('complete',{packageDigest:pkg}).code,'completion_checks_changed');
325
+ const status=run('status'),target=status.controlTarget;
326
+ assert.equal(run('completion_rework',{reason:'Fix the failed test',expectedControl:{...target,revision:'0'.repeat(64)}}).code,'snapshot_changed');
327
+ const store=path.join(f.specsDir,'.reviews/.execution',identity.runId,'state.json');
328
+ const blockedBytes=fs.readFileSync(store);
329
+ const reject=(expected)=>{
330
+ const result=run('completion_rework',{reason:'Fix the failed test',expectedControl:target});
331
+ assert.equal(result.code,expected);assert.deepEqual(fs.readFileSync(store),blockedBytes);
332
+ };
333
+ const r2=path.join(reviewDir,'work-T-001-r2.md');fs.writeFileSync(r2,'occupied');
334
+ reject('completion_rework_evidence_exists');fs.rmSync(r2);
335
+ const source=path.join(f.codeProject,'target.mjs'),beforeSource=fs.readFileSync(source);
336
+ fs.appendFileSync(source,'// drift\n');
337
+ assert.equal(run('completion_rework',{reason:'Fix the failed test',expectedControl:target}).outcome,'rejected');
338
+ assert.deepEqual(fs.readFileSync(store),blockedBytes);fs.writeFileSync(source,beforeSource);
339
+ const rows=JSON.parse(blockedBytes).records,config=rows[0].payload.config;
340
+ const state=readRunnerHistory(rows,config,3).state;
341
+ for(const change of [{attempt:2},{state:'approved',code:null},{taskCommit:{}},{cancellationRequested:true},{workflowError:'workflow_error'},
342
+ {receipt:null},{code:'completion_package_changed'}])
343
+ assert.throws(()=>completionReworkBinding({...state,...change},config),{code:'completion_rework_unavailable'});
344
+ assert.throws(()=>completionReworkBinding(state,{...config,controlPolicy:{...config.controlPolicy,development:'provider'}}),
345
+ {code:'completion_rework_unavailable'},'this entry is limited to conversation-owned development');
346
+ assert.throws(()=>completionReworkBinding(state,{...config,parallelSelection:{version:1,group:['T-001','T-002']}}),
347
+ {code:'completion_rework_unavailable'},'batch completion rework is forbidden at the durable binding');
348
+ const rework=run('completion_rework',{reason:'Fix the failed test',expectedControl:target});
349
+ const reworkedRows=JSON.parse(fs.readFileSync(store)).records;
350
+ assert.equal(reworkedRows.at(-1).payload.type,'completion-rework-requested');
351
+ assert.equal(readRunnerHistory(reworkedRows,config,3).state.priorReview.verdict,'approved');
352
+ const reworkedState=readRunnerHistory(reworkedRows,config,3).state;
353
+ assert.equal(pendingDevelopStart(reworkedState),'reviewed_package');
354
+ const {receipts:ignoredReceipts,...slimReworked}=reworkedState;
355
+ assert.equal(pendingDevelopStart(slimReworked),'reviewed_package','compact live states match replay without a receipts array');
356
+ const oldOwner={snapshot:{identity:{runId:identity.runId},records:reworkedRows},history:{supersession:null}};
357
+ const successor={snapshot:{identity:{runId:'successor'},records:[]},history:{supersession:{previousRunIds:[identity.runId]}}};
358
+ assert.equal(activeCompletionReworkOwner([oldOwner,successor]),null,'retired evidence is retained but does not own successor gates');
359
+ const freshOwner={...successor,snapshot:{...successor.snapshot,records:reworkedRows}};
360
+ assert.equal(activeCompletionReworkOwner([oldOwner,freshOwner]).identity.runId,'successor');
361
+ for(const field of ['failedCheckpointDigest','packageDigest','receiptDigest','artifactDigest','handoffDigest']){
362
+ const forged=structuredClone(reworkedRows);forged.at(-1).payload[field]='0'.repeat(64);
363
+ let previous=null;for(const row of forged){row.previousDigest=previous;const {digest:old,...body}=row;row.digest=digest(body);previous=row.digest;}
364
+ assert.throws(()=>readRunnerHistory(forged,config,3),{code:'runner_history_mismatch'});
365
+ }
366
+
367
+ assert.equal(rework.state,'changes_requested');assert.equal(rework.identity.attempt,2);
368
+ assert.deepEqual(fs.readFileSync(r1),oldReview);assert.deepEqual(fs.readFileSync(handoff),oldHandoff);
369
+ assert.equal(run('completion_rework',{reason:'Duplicate',expectedControl:target}).code,'snapshot_changed');
370
+ const beforeMissing=fs.readFileSync(store);
371
+ const missing=f.drive(f.plan({mode:'resume',originalHostContext:'v2-fixture-host',checks}),'start');
372
+ assert.equal(missing.status,2);assert.match(missing.stderr,/develop-a2/);assert.deepEqual(fs.readFileSync(store),beforeMissing);
373
+ fs.writeFileSync(path.join(f.answers,'develop-a2.json'),JSON.stringify(answer));fs.writeFileSync(marker,'pass');
374
+ assert.equal(run('start').code,'develop_unchanged_after_review','unchanged approved artifact cannot spend r2');
375
+ fs.writeFileSync(path.join(f.answers,'target.txt'),'export const value = 43;\n');
376
+ const revised=run('start');assert.equal(revised.identity.attempt,2);assert.notEqual(revised.packageDigest,pkg);
377
+ assert.equal(run('complete',{identity:{...identity,attempt:2},packageDigest:pkg}).code,'stale_completion');
378
+ const revisedHandoff=path.join(reviewDir,'work-T-001-a2-handoff.json');
379
+ const handoffSha=digestForFile(revisedHandoff);
380
+ fs.writeFileSync(r2,oldReview.toString().replace('attempt: 1','attempt: 2').replace('round: 1','round: 2')
381
+ .replace('a1-handoff.json','a2-handoff.json').replace(/handoff_sha256: [a-f0-9]{64}/,'handoff_sha256: '+handoffSha));
382
+ assert.throws(()=>checkN5({handoff:revisedHandoff,reviewsDir:reviewDir,feature:'work',task:'T-001',projectRoot:f.codeProject}),/completion rework/,
383
+ 'a forged r2 cannot stand in for the real second review');
384
+ fs.writeFileSync(r1,oldReview.toString().replace('verdict: approved','verdict: changes_requested').replace('blocking_findings: 0','blocking_findings: 1'));
385
+ assert.throws(()=>checkN5({handoff:revisedHandoff,reviewsDir:reviewDir,feature:'work',task:'T-001',projectRoot:f.codeProject}),/completion rework/,
386
+ 'changing a textual r1 verdict cannot downgrade to legacy gates');
387
+ const originalA2=fs.readFileSync(revisedHandoff),withoutMarker=JSON.parse(originalA2);
388
+ withoutMarker.evidence=withoutMarker.evidence.filter(x=>!x.startsWith('cm-completion-rework-v1: '));
389
+ fs.writeFileSync(revisedHandoff,JSON.stringify(withoutMarker,null,2)+'\n');
390
+ fs.writeFileSync(r2,fs.readFileSync(r2,'utf8').replace(/handoff_sha256: [a-f0-9]{64}/,'handoff_sha256: '+digestForFile(revisedHandoff)));
391
+ assert.throws(()=>checkN5({handoff:revisedHandoff,reviewsDir:reviewDir,feature:'work',task:'T-001',projectRoot:f.codeProject}),/completion rework/,
392
+ 'removing the marker cannot downgrade the retained JS owner');
393
+ const alias=path.join(f.root,'app-alias');fs.symlinkSync(f.codeProject,alias,'dir');
394
+ for(const projectRoot of [f.codeProject+'/',f.codeProject+'/.',path.relative(process.cwd(),f.codeProject),alias])
395
+ assert.throws(()=>checkN5({handoff:revisedHandoff,reviewsDir:reviewDir,feature:'work',task:'T-001',projectRoot}),/completion rework/,
396
+ 'aliases of the same root must still find its owner');
397
+
398
+ delete withoutMarker.implementation_sha256;fs.writeFileSync(revisedHandoff,JSON.stringify(withoutMarker,null,2)+'\n');
399
+ fs.writeFileSync(r2,fs.readFileSync(r2,'utf8').replace(/handoff_sha256: [a-f0-9]{64}/,'handoff_sha256: '+digestForFile(revisedHandoff)));
400
+ assert.throws(()=>checkN5({handoff:revisedHandoff,reviewsDir:reviewDir,feature:'work',task:'T-001',allowLegacyUnbound:true}),/completion rework/,
401
+ 'omitting projectRoot and enabling legacy unbound cannot hide a retained owner');
402
+ fs.writeFileSync(revisedHandoff,originalA2);fs.writeFileSync(r1,oldReview);fs.rmSync(r2);
403
+
404
+ assert.equal(run('decision',{identity:{...identity,attempt:2},packageDigest:revised.packageDigest}).state,'approved');
405
+ checkN5({handoff:path.join(reviewDir,'work-T-001-a2-handoff.json'),reviewsDir:reviewDir,feature:'work',task:'T-001',projectRoot:f.codeProject});
406
+ checkN5({handoff:revisedHandoff,reviewsDir:path.relative(process.cwd(),reviewDir),feature:'work',task:'T-001',projectRoot:f.codeProject});
407
+ const registeredR2=fs.readFileSync(r2);
408
+ fs.writeFileSync(r2,registeredR2.toString().replace(/Registered receipt: [a-f0-9]{64}/,'Registered receipt: '+'0'.repeat(64)));
409
+ assert.throws(()=>checkN5({handoff:revisedHandoff,reviewsDir:reviewDir,feature:'work',task:'T-001',projectRoot:f.codeProject}),/completion rework/);
410
+ fs.writeFileSync(r2,registeredR2);
411
+
412
+ const completed=run('complete',{identity:{...identity,attempt:2},packageDigest:revised.packageDigest});
413
+ assert.equal(completed.state,'fixture_completed',JSON.stringify(completed));
414
+ assert.ok(fs.existsSync(path.join(reviewDir,'work-T-001-r2.md')));
415
+ const finalRows=JSON.parse(fs.readFileSync(store)).records;
416
+ for(let n=1;n<=finalRows.length;n++)readRunnerHistory(finalRows.slice(0,n),config,3);
417
+ assert.deepEqual(finalRows.slice(0,rows.length),rows,'all previous failure and review records unchanged');
418
+ assert.deepEqual(fs.readFileSync(r1),oldReview);assert.deepEqual(fs.readFileSync(handoff),oldHandoff);
419
+ });
420
+
421
+
422
+ // review-capacity: an approved a1 package too large to repeat inline is stored
423
+ // once and referenced by its review checkpoint; the N5 owner gate must still
424
+ // find that original approved review instead of reporting it missing.
425
+ test('review-capacity: completion rework gate resolves a referenced a1 review package',t=>{
426
+ const f=fixture(t);f.review('approved');
427
+ fs.writeFileSync(path.join(f.answers,'target.txt'),'export const value = 42;\n//'+'x'.repeat(600*1024)+'\n');
428
+ const marker=path.join(f.root,'checks-pass');fs.writeFileSync(marker,'pass');
429
+ const checks=[{id:'gate',command:[process.execPath,'-e',`process.exit(require('node:fs').existsSync(${JSON.stringify(marker)})?0:1)`]}];
430
+ const run=(op,extra={})=>{const r=f.drive(f.plan({mode:'resume',originalHostContext:'v2-fixture-host',checks,...extra}),op);
431
+ assert.equal(r.status,0,r.stderr);return JSON.parse(r.stdout).result;};
432
+ const delivered=run('start',{mode:'create',originalHostContext:undefined});
433
+ assert.equal(delivered.state,'awaiting_review',JSON.stringify(delivered));
434
+ const pkg=delivered.packageDigest;assert.equal(run('decision',{packageDigest:pkg}).state,'approved');
435
+ const store=path.join(f.specsDir,'.reviews/.execution',identity.runId,'state.json');
436
+ const records=()=>JSON.parse(fs.readFileSync(store)).records;
437
+ assert.ok(records().some(row=>row.payload.packageMaterial===true),'a1 package is archived once');
438
+ assert.ok(records().some(row=>row.payload.packageRef&&row.payload.checkpoint.receipt),'the approved review checkpoint references it');
439
+ fs.rmSync(marker);assert.equal(run('complete',{packageDigest:pkg}).code,'completion_checks_changed');
440
+ const target=run('status').controlTarget;
441
+ assert.equal(run('completion_rework',{reason:'Fix the failed test',expectedControl:target}).identity.attempt,2);
442
+ fs.writeFileSync(path.join(f.answers,'develop-a2.json'),JSON.stringify(answer));fs.writeFileSync(marker,'pass');
443
+ fs.writeFileSync(path.join(f.answers,'target.txt'),'export const value = 43;\n');
444
+ const revised=run('start');assert.equal(revised.identity.attempt,2,JSON.stringify(revised));
445
+ assert.equal(run('decision',{identity:{...identity,attempt:2},packageDigest:revised.packageDigest}).state,'approved');
446
+ const reviewDir=path.join(f.specsDir,'.reviews');
447
+ checkN5({handoff:path.join(reviewDir,'work-T-001-a2-handoff.json'),reviewsDir:reviewDir,feature:'work',task:'T-001',projectRoot:f.codeProject});
448
+ assert.equal(run('complete',{identity:{...identity,attempt:2},packageDigest:revised.packageDigest}).state,'fixture_completed');
449
+ });
450
+
451
+ test('completion_rework resumes a real interrupted a2 developer without changing r1',async t=>{
452
+ const f=fixture(t);f.review('approved');const marker=path.join(f.root,'gate');fs.writeFileSync(marker,'pass');
453
+ const checks=[{id:'gate',command:[process.execPath,'-e',`process.exit(require('node:fs').existsSync(${JSON.stringify(marker)})?0:1)`]}];
454
+ const run=(op,extra={})=>{const out=f.drive(f.plan({mode:'resume',originalHostContext:'v2-fixture-host',checks,...extra}),op);
455
+ assert.ok(out.status===0||op==='status'&&out.status===1,out.stderr);return JSON.parse(out.stdout).result;};
456
+ const pkg=run('start',{mode:'create',originalHostContext:undefined}).packageDigest;
457
+ assert.equal(run('decision',{packageDigest:pkg}).state,'approved');fs.rmSync(marker);
458
+ assert.equal(run('complete',{packageDigest:pkg}).code,'completion_checks_changed');
459
+ const expectedControl=run('status').controlTarget;
460
+ assert.equal(run('completion_rework',{reason:'Fix the failed check',expectedControl}).identity.attempt,2);
461
+ const host=fileURLToPath(new URL('./cm-ai-host.mjs',import.meta.url));
462
+ const child=spawn(process.execPath,[host,'serve','--config',path.join(f.root,'run.json'),'--mode','resume',
463
+ '--host-context','v2-fixture-host','--control-config',path.join(f.root,'control.json'),
464
+ '--original-host-context','v2-fixture-host','--runtime','codex','--review-config',path.join(f.root,'review.json')],
465
+ {cwd:f.codeProject,env:f.env,detached:true,stdio:['pipe','pipe','pipe']});
466
+ let buffer='',received=false,stderr='';child.stderr.on('data',part=>stderr+=part);
467
+ await new Promise((resolve,reject)=>{
468
+ const timer=setTimeout(()=>{child.kill('SIGKILL');reject(new Error('fixture host did not dispatch develop: '+stderr));},30000);
469
+ child.stdout.on('data',part=>{buffer+=part;let newline;
470
+ while((newline=buffer.indexOf('\n'))>=0){const line=buffer.slice(0,newline);buffer=buffer.slice(newline+1);let row;try{row=JSON.parse(line);}catch{continue;}
471
+ if(row.type==='host_ready')child.stdin.write(JSON.stringify({version:2,operation:'start',requestId:'interrupted-a2',identity:{...identity,attempt:2}})+'\n');
472
+ if(row.type==='host_request'&&row.kind==='develop'){received=true;child.kill('SIGKILL');}
473
+ }});
474
+ child.once('error',error=>{clearTimeout(timer);reject(error);});
475
+ child.once('exit',()=>{clearTimeout(timer);resolve();});
476
+ });
477
+ assert.ok(received,stderr);
478
+ const store=path.join(f.specsDir,'.reviews/.execution',identity.runId,'state.json');
479
+ const interruptedRows=JSON.parse(fs.readFileSync(store)).records,config=interruptedRows[0].payload.config;
480
+ const history=readRunnerHistory(interruptedRows,config,3);assert.equal(history.pending.kind,'develop');
481
+ assert.equal(pendingDevelopStart(history.state),'reviewed_package');
482
+ const status=run('status');
483
+ assert.equal(run('abandon_effect',{reason:'Fixture host exited before answering',expectedControl:status.controlTarget}).code,'develop_interrupted');
484
+ fs.writeFileSync(path.join(f.answers,'develop-a2.json'),JSON.stringify(answer));
485
+ fs.writeFileSync(path.join(f.answers,'target.txt'),'export const value = 43;\n');fs.writeFileSync(marker,'pass');
486
+ const revised=run('start');assert.equal(revised.state,'awaiting_review');assert.equal(revised.identity.attempt,2);
487
+ assert.equal(run('decision',{identity:{...identity,attempt:2},packageDigest:revised.packageDigest}).state,'approved');
488
+ assert.equal(run('complete',{identity:{...identity,attempt:2},packageDigest:revised.packageDigest}).state,'fixture_completed');
489
+ });
490
+
491
+
492
+ test('completion_rework accepts a reviewed mode-only repair (real CLI)',t=>{
493
+ const f=fixture(t);f.review('approved');const marker=path.join(f.root,'gate');fs.writeFileSync(marker,'pass');
494
+ const checks=[{id:'gate',command:[process.execPath,'-e',`process.exit(require('node:fs').existsSync(${JSON.stringify(marker)})?0:1)`]}];
495
+ const run=(op,extra={})=>{const out=f.drive(f.plan({mode:'resume',originalHostContext:'v2-fixture-host',checks,...extra}),op);
496
+ assert.equal(out.status,0,out.stderr);return JSON.parse(out.stdout).result;};
497
+ const pkg=run('start',{mode:'create',originalHostContext:undefined}).packageDigest;
498
+ assert.equal(run('decision',{packageDigest:pkg}).state,'approved');fs.rmSync(marker);
499
+ assert.equal(run('complete',{packageDigest:pkg}).code,'completion_checks_changed');
500
+ assert.equal(run('completion_rework',{reason:'Repair executable permissions',expectedControl:run('status').controlTarget}).identity.attempt,2);
501
+ fs.writeFileSync(path.join(f.answers,'develop-a2.json'),JSON.stringify({...answer,edits:{'target.mjs':{mode:'0755'}}}));
502
+ const before=fs.readFileSync(path.join(f.codeProject,'target.mjs'));fs.writeFileSync(marker,'pass');
503
+ const revised=run('start');assert.equal(revised.state,'awaiting_review');assert.deepEqual(fs.readFileSync(path.join(f.codeProject,'target.mjs')),before);
504
+ assert.equal(fs.statSync(path.join(f.codeProject,'target.mjs')).mode&0o777,0o755);
505
+ assert.equal(run('decision',{identity:{...identity,attempt:2},packageDigest:revised.packageDigest}).state,'approved');
506
+ assert.equal(run('complete',{identity:{...identity,attempt:2},packageDigest:revised.packageDigest}).state,'fixture_completed');
507
+ });
508
+
509
+ // Design 3.4: a session member of a v2 provider batch answers develop only live.
510
+ test('v2 provider batch with a session member refuses a plan without live develop before launch',t=>{
511
+ const f=fixture(t,true),run=path.join(f.root,'run.json'),config=JSON.parse(fs.readFileSync(run,'utf8'));
512
+ config.batch.memberDevelopment={[key]:'session'};fs.writeFileSync(run,JSON.stringify(config));
513
+ fs.writeFileSync(path.join(f.root,'control.json'),JSON.stringify({...policy,development:'provider'}));
514
+ const r=f.drive(f.plan({permissions:['--protected-config','protected.json','--review-config','review.json']}));
515
+ assert.equal(r.status,2,r.stderr);assert.match(r.stderr,/1\.work\/T-001.*liveEvidence\.kinds 需要声明 develop/);
516
+ assert.equal(fs.existsSync(path.join(f.specsDir,'.reviews/.execution')),false);
517
+ });
518
+ // Design 3.5: a new qa:"run" batch needs every member's QA workflow; an existing batch keeps its boundary.
519
+ test('new v2 qa:"run" batch with a member lacking its QA workflow is refused with batch_workflow_missing',t=>{
520
+ const f=fixture(t,true,true),run=path.join(f.root,'run.json'),config=JSON.parse(fs.readFileSync(run,'utf8'));
521
+ config.workflows[key]=null;fs.writeFileSync(run,JSON.stringify(config));
522
+ const r=f.drive(f.plan());
523
+ assert.equal(r.status,2,r.stderr);assert.match(r.stderr,/batch_workflow_missing: .*1\.work\/T-001.*cm-ai-batch-plan --workflow-config/);
524
+ assert.equal(fs.existsSync(path.join(f.specsDir,'.reviews/.execution')),false);
525
+ // An existing batch (its scheduler rows are in the project log) is not refused by this new check.
526
+ fs.writeFileSync(path.join(f.specsDir,'运行日志.jsonl'),JSON.stringify({workflow:'cm-ai',event:'decision',run_id:'v2-batch-drive-run',phase:'batch_start'})+'\n');
527
+ const resumed=f.drive(f.plan({mode:'resume',originalHostContext:'v2-fixture-host'}));
528
+ // The driver launches the host, which keeps judging the batch as before (here the fake log mismatches its plan).
529
+ assert.doesNotMatch(resumed.stderr,/batch_workflow_missing/);assert.equal(JSON.parse(resumed.stdout).requestId,'drive',resumed.stderr);
530
+ });
531
+
532
+ // AI潮 specs6 (2026-10-29): every run of the batch was created with qa:"disabled"; each feature's
533
+ // last task stopped at qa_triggered/qa_execution and the project could never reach run_done.
534
+ // Such a completed run may turn QA on once: same policy except qa:"run", with a QA workflow.
535
+ const repro=async t=>{
536
+ const f=fixture(t);f.review('approved');
537
+ let r=f.drive(f.plan());assert.equal(r.status,0,r.stderr);
538
+ let result=JSON.parse(r.stdout).result;
539
+ for(let n=0;n<3&&result.code!=='qa_triggered';n++){
540
+ r=f.drive(f.plan({mode:'resume'}));assert.equal(r.status,0,r.stderr);result=JSON.parse(r.stdout).result;
541
+ }
542
+ assert.equal(result.code,'qa_triggered',JSON.stringify(result));assert.equal(result.pendingAction,'qa_execution');
543
+ fs.writeFileSync(path.join(f.root,'control-run.json'),JSON.stringify({...policy,qa:'run'}));
544
+ fs.writeFileSync(path.join(f.root,'workflow.json'),JSON.stringify({documentationPaths:[],applicableAgentFiles:[],
545
+ qa:{commands:[{id:'syntax',command:[process.execPath,'--check','target.mjs'],caseIds:[],reuseCheck:'syntax'}],
546
+ environment:{kind:'web',carrier:'browser',target:'fixture-target',scope:'local'},timeoutMs:60000}}));
547
+ return f;
548
+ };
549
+ test('a completed v2 run created with qa:"disabled" turns QA on once and reaches run_done',async t=>{
550
+ const f=await repro(t);
551
+ const plan=extra=>f.plan({mode:'resume',controlConfig:'control-run.json',
552
+ permissions:['--review-config','review.json','--workflow-config','workflow.json'],...extra});
553
+ const r=f.drive(plan());
554
+ assert.equal(r.status,0,r.stderr);
555
+ const result=JSON.parse(r.stdout).result;
556
+ assert.equal(result.state,'run_done',JSON.stringify(result));
557
+ const rows=fs.readFileSync(path.join(f.specsDir,'运行日志.jsonl'),'utf8').trim().split('\n').map(JSON.parse);
558
+ assert.ok(rows.some(row=>row.event==='test_run'&&row.phase==='complete'&&row.result==='PASS'));
559
+ assert.equal(rows.filter(row=>row.event==='decision'&&row.phase==='qa_attach').length,1);
560
+ // The task check result was taken over, not rerun.
561
+ const start=rows.filter(row=>row.event==='test_run'&&row.phase==='start').at(-1);
562
+ const report=fs.readFileSync(path.join(f.specsDir,'.reviews',`${start.operation_id}-execution.md`),'utf8');
563
+ assert.match(report,/"reusedCheck": "syntax"/);
564
+ const stateFile=path.join(f.specsDir,'.reviews','.execution',identity.runId,'state.json');
565
+ const state=JSON.parse(fs.readFileSync(stateFile,'utf8'));
566
+ assert.equal(state.records.filter(row=>row.payload.type==='qa-attached').length,1);
567
+ assert.equal(state.records[0].payload.config.controlPolicy.qa,'disabled','the saved policy is never rewritten');
568
+ // The upgraded run resumes with the upgraded launch; nothing new is attached.
569
+ const again=f.drive(plan());assert.equal(again.status,0,again.stderr);
570
+ assert.equal(JSON.parse(again.stdout).result.state,'run_done');
571
+ assert.deepEqual(JSON.parse(fs.readFileSync(stateFile,'utf8')).records.filter(row=>row.payload.type==='qa-attached'),
572
+ state.records.filter(row=>row.payload.type==='qa-attached'));
573
+ // QA cannot be taken back off once it was attached.
574
+ const back=f.drive(f.plan({mode:'resume'}));
575
+ assert.notEqual(back.status,0);assert.match(back.stdout+back.stderr,/fingerprint_mismatch/);
576
+ });
577
+
578
+ test('turning QA on is refused before completion, with another policy change, or without a QA workflow',async t=>{
579
+ const f=fixture(t);f.review('approved');
580
+ fs.writeFileSync(path.join(f.root,'workflow.json'),JSON.stringify({documentationPaths:[],applicableAgentFiles:[],
581
+ qa:{commands:[{id:'syntax',command:[process.execPath,'--check','target.mjs'],caseIds:[]}],
582
+ environment:{kind:'web',carrier:'browser',target:'fixture-target',scope:'local'},timeoutMs:60000}}));
583
+ const upgrade=(control,extra={})=>{fs.writeFileSync(path.join(f.root,'control-up.json'),JSON.stringify(control));
584
+ return f.drive(f.plan({mode:'resume',controlConfig:'control-up.json',
585
+ permissions:['--review-config','review.json','--workflow-config','workflow.json'],...extra}),'status');};
586
+ // Created, but the task is not complete yet: review is still to come.
587
+ f.review('changes_requested');
588
+ let r=f.drive(f.plan());assert.equal(r.status,0,r.stderr);
589
+ const stateFile=path.join(f.specsDir,'.reviews','.execution',identity.runId,'state.json');
590
+ const before=fs.readFileSync(stateFile,'utf8');
591
+ r=upgrade({...policy,qa:'run'});
592
+ assert.notEqual(r.status,0);assert.match(r.stdout+r.stderr,/qa_attach_not_completed|fingerprint_mismatch/);
593
+ assert.equal(fs.readFileSync(stateFile,'utf8'),before);
594
+ // Another field changed together with qa: never an upgrade.
595
+ r=upgrade({...policy,qa:'run',verification:'auto'});
596
+ assert.notEqual(r.status,0);assert.match(r.stdout+r.stderr,/fingerprint_mismatch/);
597
+ assert.equal(fs.readFileSync(stateFile,'utf8'),before);
598
+ // qa:"run" with no QA workflow is not an upgrade either.
599
+ fs.writeFileSync(path.join(f.root,'control-up.json'),JSON.stringify({...policy,qa:'run'}));
600
+ r=f.drive(f.plan({mode:'resume',controlConfig:'control-up.json'}),'status');
601
+ assert.notEqual(r.status,0);assert.match(r.stdout+r.stderr,/fingerprint_mismatch|QA 执行需要同时提供 --workflow-config/);
602
+ assert.equal(fs.readFileSync(stateFile,'utf8'),before);
603
+ });
604
+
605
+ test('a QA upgrade is exactly saved qa:"disabled" to qa:"run", and only where the launch allows it',async()=>{
606
+ const {isControlQaUpgrade,assertControlEntry}=await import('../runtime/js/cm-ai/control-policy.mjs');
607
+ const snapshot=saved=>({records:[{payload:{type:'init',config:{controlPolicy:saved}}}]});
608
+ assert.equal(isControlQaUpgrade(policy,{...policy,qa:'run'}),true);
609
+ assert.equal(isControlQaUpgrade(policy,{...policy,qa:'run',verification:'auto'}),false);
610
+ assert.equal(isControlQaUpgrade({...policy,qa:'run'},policy),false);
611
+ assert.equal(isControlQaUpgrade(policy,policy),false);
612
+ assert.equal(isControlQaUpgrade(policy,{...policy,qa:'run',qaFix:'manual'}),false);
613
+ assert.equal(isControlQaUpgrade(null,{...policy,qa:'run'}),false);
614
+ assert.equal(assertControlEntry(snapshot(policy),policy),null);
615
+ assert.throws(()=>assertControlEntry(snapshot(policy),{...policy,qa:'run'}),{code:'fingerprint_mismatch'});
616
+ assert.deepEqual(assertControlEntry(snapshot(policy),{...policy,qa:'run'},{allowQaUpgrade:true}),policy);
617
+ assert.throws(()=>assertControlEntry(snapshot(policy),{...policy,qa:'run',verification:'auto'},{allowQaUpgrade:true}),{code:'fingerprint_mismatch'});
618
+ });
619
+
620
+ const qaWorkflow=command=>({documentationPaths:[],applicableAgentFiles:[],
621
+ qa:{commands:[{id:'syntax',command,caseIds:[]}],environment:{kind:'web',carrier:'browser',target:'fixture-target',scope:'local'},timeoutMs:60000}});
622
+ const toTriggered=(f,extra={})=>{
623
+ let r=f.drive(f.plan(extra));assert.equal(r.status,0,r.stderr);let result=JSON.parse(r.stdout).result;
624
+ for(let n=0;n<3&&result.code!=='qa_triggered';n++){
625
+ r=f.drive(f.plan({mode:'resume',...extra}));assert.equal(r.status,0,r.stderr);result=JSON.parse(r.stdout).result;
626
+ }
627
+ assert.equal(result.code,'qa_triggered',JSON.stringify(result));
628
+ };
629
+ for(const initial of ['qa-null','qa-config'])
630
+ test(`a completed qa:"disabled" run created with a ${initial} workflow turns QA on too`,t=>{
631
+ const f=fixture(t);f.review('approved');
632
+ const check=[process.execPath,'--check','target.mjs'];
633
+ fs.writeFileSync(path.join(f.root,'workflow-initial.json'),JSON.stringify(initial==='qa-null'?{...qaWorkflow(check),qa:null}:qaWorkflow(check)));
634
+ toTriggered(f,{permissions:['--review-config','review.json','--workflow-config','workflow-initial.json']});
635
+ fs.writeFileSync(path.join(f.root,'control-run.json'),JSON.stringify({...policy,qa:'run'}));
636
+ fs.writeFileSync(path.join(f.root,'workflow.json'),JSON.stringify(qaWorkflow(check)));
637
+ const r=f.drive(f.plan({mode:'resume',controlConfig:'control-run.json',
638
+ permissions:['--review-config','review.json','--workflow-config','workflow.json']}));
639
+ assert.equal(r.status,0,r.stderr);
640
+ assert.equal(JSON.parse(r.stdout).result.state,'run_done',r.stdout);
641
+ });
642
+
643
+ test('after turning QA on, a wrong QA configuration is revised on the same run and QA then passes',t=>{
644
+ const f=fixture(t);f.review('approved');toTriggered(f);
645
+ fs.writeFileSync(path.join(f.root,'control-run.json'),JSON.stringify({...policy,qa:'run'}));
646
+ fs.writeFileSync(path.join(f.root,'workflow-wrong.json'),JSON.stringify(qaWorkflow([path.join(f.root,'missing-command')])));
647
+ const upgraded=f.drive(f.plan({mode:'resume',controlConfig:'control-run.json',
648
+ permissions:['--review-config','review.json','--workflow-config','workflow-wrong.json']}));
649
+ assert.equal(upgraded.status,0,upgraded.stderr);
650
+ assert.equal(JSON.parse(upgraded.stdout).result.code,'qa_result_blocked',upgraded.stdout);
651
+ const status=f.drive(f.plan({mode:'resume',controlConfig:'control-run.json',
652
+ permissions:['--review-config','review.json','--workflow-config','workflow-wrong.json']}),'status');
653
+ assert.equal(status.status,0,status.stderr);
654
+ const target=JSON.parse(status.stdout).result.launchControlTarget;assert.ok(target,status.stdout);
655
+ fs.writeFileSync(path.join(f.root,'launch-target.json'),JSON.stringify(target));
656
+ fs.writeFileSync(path.join(f.root,'workflow.json'),JSON.stringify(qaWorkflow([process.execPath,'--check','target.mjs'])));
657
+ const revised=f.drive(f.plan({mode:'resume',controlConfig:'control-run.json',
658
+ permissions:['--review-config','review.json','--workflow-config','workflow.json','--revise-qa-config','workflow-wrong.json',
659
+ '--qa-config-revision-reason','QA 命令填错,改为语法检查','--expected-control','launch-target.json']}));
660
+ assert.equal(revised.status,0,revised.stderr);
661
+ assert.equal(JSON.parse(revised.stdout).result.state,'run_done',revised.stdout);
662
+ const again=f.drive(f.plan({mode:'resume',controlConfig:'control-run.json',
663
+ permissions:['--review-config','review.json','--workflow-config','workflow.json']}));
664
+ assert.equal(again.status,0,again.stderr);assert.equal(JSON.parse(again.stdout).result.state,'run_done');
665
+ });
@@ -0,0 +1,25 @@
1
+ // Child of the cross-process race test: scan, pause on a file barrier, then try to take the lock.
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import {controlLaunchTarget} from './cm-ai-run.mjs';
5
+ import {prepareReviewedEvidenceSupersession} from '../runtime/js/cm-ai/reviewed-evidence-supersede.mjs';
6
+
7
+ const input=JSON.parse(process.argv[2]);
8
+ const holds=[];
9
+ const pause=()=>{
10
+ fs.writeFileSync(path.join(input.barrier,'scanned'),'');
11
+ const cell=new Int32Array(new SharedArrayBuffer(4));
12
+ for(let i=0;i<400&&!fs.existsSync(path.join(input.barrier,'go'));i++)Atomics.wait(cell,0,0,50);
13
+ // A missing release signal must fail the scenario, not silently carry on out of order.
14
+ if(!fs.existsSync(path.join(input.barrier,'go')))throw Object.assign(new Error('barrier_timeout'),{code:'barrier_timeout'});
15
+ };
16
+ let result;
17
+ try{
18
+ prepareReviewedEvidenceSupersession({specsDir:input.specsDir,codeProject:input.codeProject,feature:input.feature,
19
+ identity:{repositoryId:input.repositoryId,runId:input.runId,taskId:input.taskId,attempt:1},reason:input.reason,
20
+ tasksPath:path.join(input.specsDir,input.feature,'tasks.md'),expectedPredecessor:input.target,
21
+ predecessorTarget:controlLaunchTarget,holds,afterDiscovery:pause});
22
+ result={ok:true};
23
+ }catch(error){result={ok:false,code:error.code??null,reason:String(error.reason??error.message??'').slice(0,300)};}
24
+ for(const held of holds)held.close();
25
+ process.stdout.write(JSON.stringify(result)+'\n');