@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,7 +8,7 @@ import os from 'node:os';
8
8
  import path from 'node:path';
9
9
  import {EventEmitter} from 'node:events';
10
10
  import {PassThrough} from 'node:stream';
11
- import {spawnSync} from 'node:child_process';
11
+ import {spawn,spawnSync} from 'node:child_process';
12
12
  import {fileURLToPath} from 'node:url';
13
13
  import {buildManifest} from './cm-spec-manifest.mjs';
14
14
  import {projectedRunnerStatus} from '../runtime/js/cm-ai/durable-runner-state.mjs';
@@ -22,6 +22,7 @@ import {inspectProviderReview,inspectProviderReviewFailure} from '../runtime/js/
22
22
  import {buildReviewPrompt,VERDICT_RULES} from '../runtime/js/cm-ai/codex-review-adapter.mjs';
23
23
  import {reviewPaths} from '../runtime/js/cm-ai/review-runner.mjs';
24
24
  import {isSupportedExecutionPlatform} from '../runtime/js/cm-ai/execution-platform.mjs';
25
+ import {rateLimitRetryEligible} from '../runtime/js/cm-ai/drive-rate-limit.mjs';
25
26
  import {guardFixtureSource,killFixtureProcesses} from './fixtures/process-cleanup.mjs';
26
27
 
27
28
  // Native V3 runner fixtures require Node 24.14+ on macOS/Linux. Preserve the
@@ -108,9 +109,9 @@ function fixture(t,{reviewTimeoutMs=null}={}){
108
109
  fs.writeFileSync(file,JSON.stringify({config:'run.json',mode:'create',hostContext:'review-host-a',runtime:'claude',
109
110
  permissions:['--review-config','review.json'],answers:'answers',
110
111
  checks:[{id:'syntax',command:[process.execPath,'--check','target.mjs']}],...extra}));return file;};
111
- const drive=(file,operation)=>{const run=spawnSync(process.execPath,[DRIVER,'--plan',file,operation],{encoding:'utf8',timeout:60000,
112
+ const drive=(file,operation,env={})=>{const run=spawnSync(process.execPath,[DRIVER,'--plan',file,operation],{encoding:'utf8',timeout:60000,
112
113
  env:{...process.env,PATH:bin+path.delimiter+process.env.PATH,CM_WORKFLOW_HOME:path.join(root,'home'),
113
- CM_WORKFLOW_LOG_HOME:path.join(root,'logs')}});
114
+ CM_WORKFLOW_LOG_HOME:path.join(root,'logs'),...env}});
114
115
  let result=null;try{result=JSON.parse(run.stdout).result;}catch{}
115
116
  return {status:run.status,stderr:run.stderr,result};};
116
117
  const store=path.join(specsDir,'.reviews','.execution',identity.runId,'state.json');
@@ -122,10 +123,30 @@ function fixture(t,{reviewTimeoutMs=null}={}){
122
123
  const first=drive(plan(),'start');assert.equal(first.status,0,first.stderr);
123
124
  assert.equal(first.result.state,'awaiting_review');return first.result.packageDigest;
124
125
  };
125
- const decide=(packageDigest,attempt=1)=>drive(plan({mode:'resume',permissions:review(attempt),packageDigest,answers:undefined,checks:undefined}),'decision');
126
+ const decide=(packageDigest,attempt=1,env={})=>drive(plan({mode:'resume',permissions:review(attempt),packageDigest,answers:undefined,checks:undefined}),'decision',env);
126
127
  const lastResult=()=>records().findLast(row=>row.payload.type==='review-invocation-result').payload;
127
128
  const intents=()=>records().filter(row=>row.payload.type==='effect-intent').map(row=>row.payload.effect.id);
128
- return {root,specsDir,codeProject,answers,write,behave,plan,drive,store,records,replay,calls,review,awaitingReview,decide,lastResult,intents};
129
+ // Optional notices: notify.json in the fixture's CM_WORKFLOW_HOME runs a
130
+ // recorder; sent() lists what reached it (the launcher is detached).
131
+ const notices=()=>{
132
+ const home=path.join(root,'home'),sent=path.join(root,'sent.jsonl'),script=path.join(root,'fake-notify.mjs');
133
+ fs.mkdirSync(home,{recursive:true});
134
+ fs.writeFileSync(script,`import fs from 'node:fs';let input='';process.stdin.on('data',c=>input+=c);
135
+ process.stdin.on('end',()=>{fs.appendFileSync(${JSON.stringify(sent)},JSON.stringify({body:process.env.CM_NOTIFY_BODY,stdin:JSON.parse(input)})+'\\n');});`);
136
+ fs.writeFileSync(path.join(home,'notify.json'),JSON.stringify({version:1,command:[process.execPath,script],layout:'compact'}));
137
+ const rows=()=>fs.existsSync(sent)?fs.readFileSync(sent,'utf8').split('\n').filter(Boolean).map(line=>JSON.parse(line)):[];
138
+ const pending=()=>{const dir=path.join(home,'notify-pending');return fs.existsSync(dir)?fs.readdirSync(dir).filter(name=>name.endsWith('.json')):[];};
139
+ return {rows,pending};
140
+ };
141
+ // The same driver started without waiting for it (a timed retry in the background).
142
+ const driveAsync=(file,operation,env={})=>{
143
+ const child=spawn(process.execPath,[DRIVER,'--plan',file,operation],{env:{...process.env,PATH:bin+path.delimiter+process.env.PATH,
144
+ CM_WORKFLOW_HOME:path.join(root,'home'),CM_WORKFLOW_LOG_HOME:path.join(root,'logs'),...env}});
145
+ let stdout='',stderr='';child.stdout.on('data',chunk=>stdout+=chunk);child.stderr.on('data',chunk=>stderr+=chunk);
146
+ return {child,stderr:()=>stderr,done:new Promise(resolve=>child.on('close',status=>{
147
+ let result=null;try{result=JSON.parse(stdout).result;}catch{}resolve({status,stdout,stderr,result});}))};
148
+ };
149
+ return {root,specsDir,codeProject,answers,write,behave,plan,drive,driveAsync,store,records,replay,calls,review,awaitingReview,decide,lastResult,intents,notices};
129
150
  }
130
151
 
131
152
  const apiErrors=[
@@ -190,6 +211,8 @@ test(`#8 ${error==='authentication_failed'?'real Claude CLI':'in-process Claude
190
211
  assert.equal(failed.status,0,failed.stderr);
191
212
  assert.equal(failed.result.state,'pending_review');assert.equal(failed.result.code,'review_provider_failed');
192
213
  assert.equal(failed.result.pendingAction,'resume');assert.match(failed.result.reason,new RegExp(`^${failure}: `));
214
+ // The class is also a structured field, so a driver never parses the reason text.
215
+ assert.equal(failed.result.reviewFailure,failure);
193
216
  const result=f.lastResult();
194
217
  assert.equal(result.outcome,'failed');assert.equal(result.reconciliationRequired,false);
195
218
  assert.equal(result.inspection.kind,'cm-provider-review-failure');assert.equal(result.inspection.category,'provider');
@@ -210,6 +233,128 @@ test(`#8 ${error==='authentication_failed'?'real Claude CLI':'in-process Claude
210
233
  assert.equal(f.replay().state.state,'approved');assert.equal(f.calls().length,2);
211
234
  });
212
235
 
236
+ // 2026-10-26: a provider rate limit stopped the run although the quota recovered
237
+ // minutes later. The driver waits and re-runs the same command in resume mode,
238
+ // which is the runner's own one automatic redispatch of this round: no review
239
+ // round, no abandon_review, no extra permission, and no notice while it waits.
240
+ const rateLimited={mode:'api_error',error:'rate_limit',status:429,text:'API Error: 429 rate limited'};
241
+ const until=async(check,ms=8000)=>{const end=Date.now()+ms;while(!check()&&Date.now()<end)await new Promise(r=>setTimeout(r,25));return check();};
242
+ test('#8 a rate-limited review is redispatched by the driver after a wait, in the same run, without a notice',async t=>{
243
+ const f=fixture(t),packageDigest=f.awaitingReview(),notices=f.notices();
244
+ f.behave(rateLimited,{mode:'ok'});
245
+ const run=f.decide(packageDigest,1,{CM_DRIVE_RATE_LIMIT_DELAYS_MS:'300,300,300'});
246
+ assert.equal(run.status,0,run.stderr);
247
+ // stdout holds only the re-run's result: the interim rate-limited one is not printed.
248
+ assert.equal(run.result.state,'approved',run.stderr);
249
+ assert.match(run.stderr,/审查被限流(reviewer_rate_limited),1 秒后在原运行自动重派审查(第 1\/3 次);等待期间不推送/);
250
+ assert.deepEqual(f.intents(),['develop-1','review-1','review-1-retry-1']);assert.equal(f.calls().length,2);
251
+ // The review rounds are untouched: one round, its automatic redispatch spent.
252
+ assert.equal(f.replay().state.attempt,1);
253
+ await new Promise(resolve=>setTimeout(resolve,700));
254
+ assert.deepEqual(notices.rows(),[],'nothing is sent while waiting or after the retry succeeded');
255
+ assert.deepEqual(notices.pending(),[],'the backstop notice was cancelled by the re-run');
256
+ });
257
+
258
+ // advance (not only decision) dispatches the pending review again: the retry
259
+ // must show a new review effect and a second reviewer call.
260
+ test('#8 advance on a rate-limited review is retried and the review is really redispatched',async t=>{
261
+ const f=fixture(t);f.awaitingReview();
262
+ f.behave(rateLimited,{mode:'ok'});
263
+ const run=f.drive(f.plan({mode:'resume'}),'advance',{CM_DRIVE_RATE_LIMIT_DELAYS_MS:'300,300,300'});
264
+ assert.match(run.stderr,/自动重派审查(第 1\/3 次)/);
265
+ assert.match(run.stderr,/按等待时那次限流重派这一次审查(第 1\/3 次)/);
266
+ // The retry is a bound decision: it redispatched that review and did not go on to complete.
267
+ assert.equal(run.result.operation,'decision');assert.equal(f.intents().some(id=>id.startsWith('complete-')),false);
268
+ assert.deepEqual(f.intents().slice(0,3),['develop-1','review-1','review-1-retry-1']);
269
+ assert.equal(f.calls().length,2);assert.notEqual(run.result?.state,'pending_review',run.stderr);
270
+ // resume only reports a pending_review state, so it is never retried; decision and advance are.
271
+ assert.deepEqual(['advance','decision','resume','status'].map(op=>rateLimitRetryEligible(op,{permissions:[]})),[true,true,false,false]);
272
+ });
273
+
274
+ // The timed re-run is bound to the stop it waited for: if another driver moved
275
+ // the run on, or the PLAN now names something else, nothing is dispatched.
276
+ // Codex round 2 reproduction: the waiting command is advance; while it waits,
277
+ // another driver's decision takes the review to approved. The timed retry is a
278
+ // decision carrying the frozen stop, checked by the host under the run's writer
279
+ // lock: it dispatches nothing (no complete, tasks.md untouched).
280
+ test('#8 a timed rate-limit retry does nothing when another driver moved the run on meanwhile',async t=>{
281
+ const f=fixture(t),packageDigest=f.awaitingReview();
282
+ f.behave(rateLimited,{mode:'ok'},{mode:'ok'});
283
+ const tasks=path.join(f.specsDir,'1.work','tasks.md'),before=fs.readFileSync(tasks);
284
+ const waiting=f.driveAsync(f.plan({mode:'resume'}),'advance',{CM_DRIVE_RATE_LIMIT_DELAYS_MS:'4000'});
285
+ assert(await until(()=>/秒后在原运行自动重派审查/.test(waiting.stderr()),20000),'the first driver is waiting');
286
+ const other=f.decide(packageDigest,1,{CM_DRIVE_RATE_LIMIT_DELAYS_MS:'1'});
287
+ assert.equal(other.result.state,'approved',other.stderr);assert.equal(f.calls().length,2);
288
+ const intents=f.intents();
289
+ const first=await waiting.done;
290
+ assert.match(first.stderr,/状态已变,未自动重试:宿主核对运行已不停在等待时那次审查限流,没有派发任何操作/);
291
+ assert.equal(first.result.staleRetry,true,first.stdout);assert.equal(first.result.outcome,'rejected');
292
+ assert.equal(first.result.state,'approved');
293
+ assert.deepEqual(f.intents(),intents,'no effect at all, complete-1 included');
294
+ assert.equal(f.intents().some(id=>id.startsWith('complete-')),false);
295
+ assert.deepEqual(fs.readFileSync(tasks),before,'tasks.md unchanged');
296
+ assert.equal(f.calls().length,2,'no third reviewer call');assert.equal(f.replay().state.state,'approved');
297
+ });
298
+
299
+ // The host's own check of the frozen stop: another failed invocation is refused
300
+ // without any effect; the exact frozen one is redispatched once.
301
+ test('#8 the host redispatches a bound rate-limit retry only for the exact frozen review invocation',async t=>{
302
+ const f=fixture(t),packageDigest=f.awaitingReview();
303
+ f.behave(rateLimited,{mode:'ok'});
304
+ const file=f.plan({mode:'resume',permissions:f.review(1),packageDigest,answers:undefined,checks:undefined});
305
+ const waiting=f.driveAsync(file,'decision',{CM_DRIVE_RATE_LIMIT_DELAYS_MS:'600000'});
306
+ t.after(()=>{try{waiting.child.kill('SIGKILL');}catch{}});
307
+ assert(await until(()=>/分钟后在原运行自动重派审查/.test(waiting.stderr()),20000),'the first driver is waiting');
308
+ waiting.child.kill('SIGKILL');await waiting.done;
309
+ const invocationId=f.lastResult().invocationId,identity={repositoryId:'review-failure',runId:'review-failure-run',taskId:'T-001',attempt:1};
310
+ assert.equal(typeof invocationId,'string');
311
+ const bound=id=>f.drive(file,'decision',{CM_DRIVE_RATE_LIMIT_RETRY:'1',CM_DRIVE_RATE_LIMIT_EXPECTED:JSON.stringify({identity,packageDigest,invocationId:id})});
312
+ const intents=f.intents();
313
+ const stale=bound('another-invocation');
314
+ assert.equal(stale.result?.staleRetry,true,`${stale.status} ${stale.stderr}`);assert.equal(stale.result.state,'pending_review');
315
+ assert.deepEqual(f.intents(),intents);assert.equal(f.calls().length,1);
316
+ const exact=bound(invocationId);
317
+ assert.equal(exact.result.state,'approved',exact.stderr);assert.equal(f.calls().length,2);
318
+ assert.deepEqual(f.intents(),[...intents,'review-1-retry-1']);
319
+ // A retry without its frozen stop never falls back to a plain command.
320
+ const missing=f.drive(file,'decision',{CM_DRIVE_RATE_LIMIT_RETRY:'1'});
321
+ assert.equal(missing.status,2);assert.match(missing.stderr,/缺少等待时冻结的审查限流前置条件/);
322
+ });
323
+
324
+ test('#8 a timed rate-limit retry does nothing when the PLAN was changed to name another run',async t=>{
325
+ const f=fixture(t),packageDigest=f.awaitingReview();
326
+ f.behave(rateLimited,{mode:'ok'});
327
+ const file=f.plan({mode:'resume',permissions:f.review(1),packageDigest,answers:undefined,checks:undefined});
328
+ const waiting=f.driveAsync(file,'decision',{CM_DRIVE_RATE_LIMIT_DELAYS_MS:'2000'});
329
+ assert(await until(()=>/秒后在原运行自动重派审查/.test(waiting.stderr()),20000),'the first driver is waiting');
330
+ const definition=JSON.parse(fs.readFileSync(path.join(f.root,'run.json'),'utf8'));
331
+ fs.writeFileSync(path.join(f.root,'run-other.json'),JSON.stringify({...definition,identity:{...definition.identity,runId:'review-failure-other'}}));
332
+ fs.writeFileSync(file,JSON.stringify({...JSON.parse(fs.readFileSync(file,'utf8')),config:'run-other.json'}));
333
+ const first=await waiting.done;
334
+ assert.match(first.stderr,/状态已变,未自动重试:PLAN 文件在等待期间被改过/);
335
+ assert.equal(first.result.state,'pending_review');assert.equal(f.calls().length,1,'nothing was dispatched');
336
+ assert.equal(fs.existsSync(path.join(f.specsDir,'.reviews','.execution','review-failure-other')),false);
337
+ });
338
+
339
+ test('#8 a review still rate limited after the automatic retry is returned and notified at once with what to do',async t=>{
340
+ const f=fixture(t),packageDigest=f.awaitingReview(),notices=f.notices();
341
+ f.behave(rateLimited,rateLimited,{mode:'ok'});
342
+ const run=f.decide(packageDigest,1,{CM_DRIVE_RATE_LIMIT_DELAYS_MS:'200,200,200'});
343
+ // The second rate limit of the round is the runner's blocked stop: no third dispatch, no abandon_review sent.
344
+ assert.equal(run.result.state,'blocked',run.stderr);assert.equal(run.result.code,'review_provider_failed');
345
+ assert.equal(run.result.reviewFailure,'reviewer_rate_limited');assert.equal(run.result.pendingAction,'abandon_review');
346
+ assert.equal(f.calls().length,2);assert.equal(f.records().filter(row=>row.payload.type==='review-redispatch').length,0);
347
+ assert.equal((run.stderr.match(/自动重派审查(第 /g)??[]).length,1);
348
+ assert(await until(()=>notices.rows().length===1),'notified at once');
349
+ const [sent]=notices.rows();
350
+ // The real exit is the round's stop confirmation, not "继续": the notice says so.
351
+ assert.equal(sent.body.split('\n')[1],'你要做:需要你确认旧审查进程已停后,回到会话「review-host-a」授权放弃这次审查再重派');
352
+ assert.equal(sent.stdin.code,'review_provider_failed');
353
+ // Without the automatic retry budget (no eligible operation), status never retries.
354
+ const status=f.drive(f.plan({mode:'resume',answers:undefined,checks:undefined}),'status',{CM_DRIVE_RATE_LIMIT_DELAYS_MS:'200'});
355
+ assert.equal(status.result.state,'blocked');assert.equal(f.calls().length,2);
356
+ });
357
+
213
358
  test('#8 a reviewer with no init line is redispatched twice per round; the third failure is a limit and abandon is refused',t=>{
214
359
  const f=fixture(t),packageDigest=f.awaitingReview();
215
360
  f.behave({mode:'no_init'});
@@ -1,3 +1,4 @@
1
+ import {withHostStageObserver} from '../runtime/js/cm-ai/host-stage-observer.mjs';
1
2
  import test from 'node:test';
2
3
  import assert from 'node:assert/strict';
3
4
  import fs from 'node:fs';
@@ -514,3 +515,22 @@ test('review-redispatch replay refuses forged, duplicate and over-limit records'
514
515
  assert.equal(projectedRunnerStatus(older,config).state,'blocked');assert.equal(projectedRunnerStatus(older,config).reviewRedispatchStopRequired,true);
515
516
  assert.equal(projectedRunnerStatus(readRunnerHistory(records,config,3),config).code,'review_redispatch_limit');
516
517
  },{timeoutMs:20,reviewRun:timeoutRun}));
518
+
519
+ // Transport telemetry must use the existing budgets without entering durable history.
520
+ test('native review telemetry reports its configured deadline and leaves original replay unchanged',()=>fixture(async f=>{
521
+ f.options.reviewInvocation.timeoutMs=2500;
522
+ const runner=f.make(),rows=[];
523
+ await withHostStageObserver(row=>rows.push(row),async()=>{
524
+ await runner.executeEffect(f.effect('develop'));
525
+ const result=await runner.executeEffect(f.effect('review'));
526
+ assert.equal(result.state,'approved');
527
+ });
528
+ const review=rows.find(row=>row?.kind==='review');assert.ok(review);
529
+ assert.equal(review.deadlineMs-Date.parse(review.startedAt),2500);
530
+ assert.ok(rows.some(row=>row?.kind==='develop'));
531
+ assert.ok(rows.some(row=>row?.kind==='check'));
532
+ const before=JSON.stringify(f.getStore().snapshot());
533
+ assert.doesNotMatch(before,/nativeStage|host_heartbeat|lastProgressAt|deadlineMs/);
534
+ const resumed=f.reopen();assert.equal(resumed.status().state,'approved');
535
+ assert.equal(JSON.stringify(f.getStore().snapshot()),before);
536
+ },{timeoutMs:5000}));
@@ -1,13 +1,15 @@
1
1
  #!/usr/bin/env node
2
2
  // Fixed, no-provider control entry. Executing adapters are a subsequent slice.
3
3
  import fs from 'node:fs';
4
+ import {assertDeclaredScope} from '../runtime/js/task-scope.mjs';
4
5
  import {spawn as spawnChild} from 'node:child_process';
5
6
  import path from 'node:path';
6
7
  import {fileURLToPath} from 'node:url';
7
8
  import {serveCmAiHost} from '../runtime/js/cm-ai/host-session.mjs';
8
9
  import {digest as sha} from '../runtime/js/cm-ai/contracts.mjs';
9
10
  import {resolveCodeProjects,codeProjectPaths,assertCodeProjectSelections} from '../runtime/js/cm-ai/code-projects.mjs';
10
- import {preQaConfigurations,readQaAttachment} from '../runtime/js/cm-ai/qa-attachment.mjs';
11
+ import {preQaConfigurations,preQaUpgradeConfigurations,readQaAttachment} from '../runtime/js/cm-ai/qa-attachment.mjs';
12
+ import {isImplicitQaDecision} from '../runtime/js/cm-ai/implicit-qa-decision.mjs';
11
13
  import {recordCmAiQaAttachment} from '../runtime/js/cm-ai/cm-ai-qa-log.mjs';
12
14
  import {writeCmAiQaStatus} from '../runtime/js/cm-ai/cm-ai-run-finalizer.mjs';
13
15
  import {isSupportedExecutionPlatform} from '../runtime/js/cm-ai/execution-platform.mjs';
@@ -22,7 +24,7 @@ import {recordReviewAbandonment} from '../runtime/js/cm-ai/review-abandon-log.mj
22
24
  import {recordEffectAbandonment} from '../runtime/js/cm-ai/effect-abandon-log.mjs';
23
25
  import {reviewConsumedHandoff,reviewedHandoffConflict} from '../runtime/js/cm-ai/host-handoff.mjs';
24
26
  import {RUN_ID_RULE,validRunId} from './cm-log-event.mjs';
25
- import {JOURNAL_PAYLOAD_LIMIT,boundedReason} from '../runtime/js/cm-ai/effect-contract.mjs';
27
+ import {JOURNAL_PAYLOAD_LIMIT,boundedReason,shape,hex} from '../runtime/js/cm-ai/effect-contract.mjs';
26
28
  import {protectedScopePaths} from '../runtime/js/cm-ai/developer-adapter.mjs';
27
29
  import {closeoutPolicyCandidates} from '../runtime/js/cm-ai/knowledge-closeout.mjs';
28
30
 
@@ -244,7 +246,11 @@ export function runConfigMaterial(definition,execution,{parallelSelection=null,b
244
246
  export function inspectRunHistory(definition){
245
247
  const snapshot=readExecutionSnapshot({specsRoot:definition.specsDir,
246
248
  identity:{repositoryId:definition.identity.repositoryId,runId:definition.identity.runId}});
247
- return {identity:snapshot.identity,revision:snapshot.revision,fingerprints:snapshot.fingerprints,
249
+ // The restart target is the same launch projection a v2 supersede compares;
250
+ // histories this runtime cannot project report null rather than a guess.
251
+ let supersedeTarget=null;
252
+ try{supersedeTarget=controlLaunchTarget(snapshot);}catch{supersedeTarget=null;}
253
+ return {identity:snapshot.identity,revision:snapshot.revision,fingerprints:snapshot.fingerprints,supersedeTarget,
248
254
  records:snapshot.records.map(record=>({seq:record.seq,id:record.id,kind:record.kind,type:record.payload.type??null,
249
255
  legacyReviewGrant:record.payload.type==='review-invocation-registered'
250
256
  &&(Object.hasOwn(record.payload,'grant')||Object.hasOwn(record.payload,'authorizationAt'))}))};
@@ -268,6 +274,8 @@ export async function openControlRun(definition,mode,execution=null,options={}){
268
274
  if(!isSupportedExecutionPlatform())fail('unsupported_runner_platform');
269
275
  if(!['create','resume'].includes(mode))fail('invalid_mode');
270
276
  let guard;
277
+ const holds=[];
278
+ const releaseHolds=()=>{for(const held of holds.splice(0)){try{held.close();}catch{}}};
271
279
  try{
272
280
  const acquire=async()=>{
273
281
  const {acquireExternalRunGuard,externalRunGuardExists}=await import('../runtime/js/cm-ai/external-run-guard.mjs');
@@ -275,12 +283,15 @@ export async function openControlRun(definition,mode,execution=null,options={}){
275
283
  // Switching this binary to a legacy launch must not bypass an existing strict attempt.
276
284
  if(strict||externalRunGuardExists(definition.specsDir,definition.codeProject))guard=acquireExternalRunGuard(definition,{strictOnly:!strict});
277
285
  };
278
- const result=await openControlRunOwned(definition,mode,execution,options,acquire);
286
+ // A v2 restart holds the predecessor's writer lock from the target check until
287
+ // the new run has journaled and archived the supersession (or failed).
288
+ const result=await openControlRunOwned(definition,mode,execution,{...options,supersedeHolds:holds},acquire);
289
+ releaseHolds();
279
290
  const close=result.close;
280
291
  return {...result,close:()=>{try{close();}finally{guard?.close();}}};
281
- }catch(error){guard?.close();throw error;}
292
+ }catch(error){releaseHolds();guard?.close();throw error;}
282
293
  }
283
- async function openControlRunOwned(definition,mode,execution=null,{rerunUnknownQa=false,rerunBlockedQa=false,qaEnvironmentFailure=null,parallelSelection=null,qaConfigRevision=null,supersedeReason=null,acceptSupersededCodeDrift=false,allowAbandonReview=false,allowAbandonEffect=false,allowBootstrapReviewRecovery=false,allowDevelopRedo=false,holdRevision=false,specRebindReason=null,expectedControl=null}={},acquireGuard=async()=>{}){
294
+ async function openControlRunOwned(definition,mode,execution=null,{supersedeHolds=null,supersedeTarget=null,rerunUnknownQa=false,rerunBlockedQa=false,qaEnvironmentFailure=null,parallelSelection=null,qaConfigRevision=null,supersedeReason=null,acceptSupersededCodeDrift=false,allowAbandonReview=false,allowAbandonEffect=false,allowBootstrapReviewRecovery=false,allowDevelopRedo=false,holdRevision=false,specRebindReason=null,expectedControl=null,scopeRevision=null,developmentReworkReason=null,reviewedIntegration=null}={},acquireGuard=async()=>{}){
284
295
  // Check before importing node:sqlite: legacy Node users get a useful error.
285
296
  if(!isSupportedExecutionPlatform())fail('unsupported_runner_platform');
286
297
  const {conversationProtection,externalConversationDefinition}=await import('../runtime/js/cm-ai/host-conversation-execution.mjs');
@@ -290,8 +301,9 @@ async function openControlRunOwned(definition,mode,execution=null,{rerunUnknownQ
290
301
  // run here, before any journal, intent or execution directory exists, so it
291
302
  // cannot strand its first develop effect. A bootstrap run's own instruction
292
303
  // paths are checked by createHostBootstrap against its business scope.
293
- if(mode==='create'&&!execution?.bootstrap)assertCreatableScope(definition?.scope);
304
+ if(mode==='create'&&!execution?.bootstrap){assertCreatableScope(definition?.scope);assertDeclaredScope(definition);}
294
305
  if(supersedeReason!==null&&mode!=='create')fail('supersede_unavailable');
306
+ if(supersedeTarget!==null&&!execution?.configuration?.controlPolicy)fail('invalid_arguments');
295
307
  if(allowAbandonEffect&&mode!=='resume')fail('effect_abandon_unavailable');
296
308
  if(allowBootstrapReviewRecovery&&mode!=='resume')fail('bootstrap_review_recovery_unavailable');
297
309
  if(allowDevelopRedo&&mode!=='resume')fail('develop_redo_unavailable');
@@ -307,18 +319,49 @@ async function openControlRunOwned(definition,mode,execution=null,{rerunUnknownQ
307
319
  ||(rerunUnknownQa||rerunBlockedQa)&&(mode!=='resume'||!execution?.qaExecutor))fail('qa_recovery_authorization_required');
308
320
  const {openTaskExecutionStore}=await import('../runtime/js/cm-ai/task-owner.mjs');
309
321
  const controlPolicy=execution?.configuration?.controlPolicy??null;
310
- const launchRecovery=qaConfigRevision!==null||rerunUnknownQa||rerunBlockedQa||specRebindReason!==null;
322
+ const elevatedRecovery=scopeRevision!==null||developmentReworkReason!==null;
323
+ const launchRecovery=qaConfigRevision!==null||rerunUnknownQa||rerunBlockedQa||specRebindReason!==null||elevatedRecovery||reviewedIntegration!==null;
324
+ if(elevatedRecovery){
325
+ if(!controlPolicy||mode!=='resume'||parallelSelection!==null||conversationProtection(execution)!==null
326
+ ||protectedExecutions.has(execution)||execution.configuration.providerDevelopment)fail('recovery_launch_unavailable');
327
+ if([scopeRevision!==null,developmentReworkReason!==null,qaConfigRevision!==null,rerunUnknownQa,rerunBlockedQa,specRebindReason!==null].filter(Boolean).length!==1)fail('invalid_input');
328
+ const reason=scopeRevision?.reason??developmentReworkReason;
329
+ if(typeof reason!=='string'||!reason.trim()||Buffer.byteLength(reason,'utf8')>500||/[\r\n\0]/.test(reason))fail('invalid_input');
330
+ }
331
+ if(reviewedIntegration!==null){
332
+ shape(reviewedIntegration,['evidenceFile','expectedDigest']);hex(reviewedIntegration.expectedDigest);
333
+ if(typeof reviewedIntegration.evidenceFile!=='string'||!path.isAbsolute(reviewedIntegration.evidenceFile)
334
+ ||reviewedIntegration.evidenceFile.includes('\0'))fail('invalid_input');
335
+ if(!controlPolicy||mode!=='resume'||parallelSelection!==null)fail('recovery_launch_unavailable');
336
+ // Integration adoption is its own launch: never together with another recovery.
337
+ if(qaConfigRevision!==null||rerunUnknownQa||rerunBlockedQa||qaEnvironmentFailure!==null
338
+ ||specRebindReason!==null||supersedeReason!==null||holdRevision||elevatedRecovery||supersedeTarget!==null)fail('invalid_input');
339
+ }
311
340
  if(controlPolicy){
312
- if(supersedeReason!==null)fail('supersede_unavailable');
341
+ // V2 restart: only create, only with the previewed predecessor launch target.
342
+ if(supersedeReason!==null){
343
+ if(mode!=='create')fail('supersede_unavailable');
344
+ if(supersedeTarget===null)fail('invalid_input');
345
+ supersedeTarget=readControlTarget(supersedeTarget);
346
+ }else if(supersedeTarget!==null)fail('invalid_input');
313
347
  if(launchRecovery){
314
348
  if(mode!=='resume')fail('supersede_unavailable');
315
349
  if(expectedControl===null)fail('invalid_input');
316
350
  expectedControl=readControlTarget(expectedControl);
317
351
  }else if(expectedControl!==null)fail('invalid_input');
318
352
  }
353
+ // savedPolicy: set only when a completed qa:"disabled" run is resumed with
354
+ // qa:"run" and a QA workflow (control-policy.mjs isControlQaUpgrade). The
355
+ // runner keeps the saved policy; only the host's QA wiring uses the new one.
356
+ let savedPolicy=null;
319
357
  if(mode==='resume'){
320
358
  const snapshot=assertSupportedResumeHistory(definition);
321
- if(snapshot?.records.length)assertControlEntry(snapshot,controlPolicy);
359
+ if(snapshot?.records.length){
360
+ savedPolicy=assertControlEntry(snapshot,controlPolicy,{allowQaUpgrade:Boolean(execution?.qaExecutor)});
361
+ // The first upgrade is its own launch; recoveries come after it, on the attached run.
362
+ if(savedPolicy&&!snapshot.records.some(row=>row.payload.type==='qa-attached')
363
+ &&(launchRecovery||supersedeTarget!==null||holdRevision))fail('invalid_input');
364
+ }
322
365
  }
323
366
  const {createCmAiHost}=await import('../runtime/js/cm-ai/host.mjs');
324
367
  const {inspectCmAiAdmission,matchesCmAiTaskSelection,explainCmAiTaskSelection,selectedFeature}=await import('../runtime/js/cm-ai/cm-ai-admission.mjs');
@@ -357,7 +400,7 @@ async function openControlRunOwned(definition,mode,execution=null,{rerunUnknownQ
357
400
  const reviewsDir=path.join(specsDir,'.reviews');
358
401
  const supersession=mode==='create'&&supersedeReason!==null
359
402
  ?prepareReviewedEvidenceSupersession({specsDir,codeProject,feature,identity,reason:supersedeReason,tasksPath,
360
- acceptSupersededCodeDrift}):null;
403
+ acceptSupersededCodeDrift,...(supersedeTarget?{expectedPredecessor:supersedeTarget,predecessorTarget:controlLaunchTarget,holds:supersedeHolds}:{})}):null;
361
404
  let bootstrapConfig=null;
362
405
  if(execution?.bootstrap){
363
406
  const {bootstrapConfiguration}=await import('../runtime/js/cm-ai/host-bootstrap.mjs');
@@ -436,7 +479,7 @@ async function openControlRunOwned(definition,mode,execution=null,{rerunUnknownQ
436
479
  store=openTaskExecutionStore({...storeOptions,fingerprints:{...fingerprints,config:snapshot.fingerprints.config}});
437
480
  }
438
481
  if(!store){
439
- for(const previous of preQaConfigurations(material)){
482
+ for(const previous of [...preQaConfigurations(material),...(savedPolicy?preQaUpgradeConfigurations(material):[])]){
440
483
  try{store=openTaskExecutionStore({...storeOptions,fingerprints:{...fingerprints,config:sha(previous)}});break;}
441
484
  catch(cause){if(cause.code!=='fingerprint_mismatch')throw cause;}
442
485
  }
@@ -457,6 +500,7 @@ async function openControlRunOwned(definition,mode,execution=null,{rerunUnknownQ
457
500
  throw Object.assign(new Error('fingerprint_mismatch'),{code:'fingerprint_mismatch',
458
501
  reason:'启动配置与事后附加 QA 时绑定的配置不同;请用附加 QA 时的 --workflow-config 与参数恢复'});
459
502
  if(attaching&&store.snapshot().records.length===0)fail('qa_attach_not_completed');
503
+ if(savedPolicy&&!attaching&&!attached)fail('fingerprint_mismatch');
460
504
  return {material,fingerprints,store,attaching,priorMaterial,chain,attached};
461
505
  }catch(error){store.close();throw error;}
462
506
  };
@@ -478,6 +522,16 @@ async function openControlRunOwned(definition,mode,execution=null,{rerunUnknownQ
478
522
  }
479
523
  }
480
524
  }
525
+ // 修复前创建、没有 workflow 配置的 v2 运行:指纹里没有隐式 QA 判定,按原样打开,行为不变。
526
+ // 只用去掉判定的副本算指纹;execution 本身不换,受保护会话等按对象身份登记的状态保持原样。
527
+ let implicitQaSuppressed=false;
528
+ if(!opened&&mode==='resume'&&isImplicitQaDecision(execution?.qaDecisionProvider)){
529
+ const {qaDecisionProvider,...original}=execution;
530
+ for(const knowledgeCloseout of closeoutPolicyCandidates(original,mode,snapshot)){
531
+ try{opened=openFor(runConfigMaterial(definition,original,{parallelSelection,bootstrapConfig,knowledgeCloseout}));implicitQaSuppressed=true;break;}
532
+ catch(error){if(error.code!=='fingerprint_mismatch')throw error;}
533
+ }
534
+ }
481
535
  if(!opened)throw lastMismatch;
482
536
  const {material:configMaterial,fingerprints,store,attaching,priorMaterial,chain,attached}=opened;
483
537
  const knowledgeCloseout=configMaterial.knowledgeCloseout??null;
@@ -491,6 +545,8 @@ async function openControlRunOwned(definition,mode,execution=null,{rerunUnknownQ
491
545
  throw error;
492
546
  }
493
547
  }
548
+ // Integration acceptance never attaches QA or repairs unrelated audit mirrors.
549
+ if(reviewedIntegration!==null&&attaching)fail('integration_launch_qa_attachment_unavailable');
494
550
  let runnerMode=mode;
495
551
  if(mode==='resume'&&store.snapshot().records.length===0){
496
552
  // Only the genuine, fingerprint-matching empty initializer can be finished.
@@ -506,7 +562,8 @@ async function openControlRunOwned(definition,mode,execution=null,{rerunUnknownQ
506
562
  ...(knowledgeCloseout===null?{}:{knowledgeCloseout}),
507
563
  ...(execution?.configuration.executionPolicy?{executionPolicy:execution.configuration.executionPolicy}:{}),
508
564
  ...(execution?.configuration.externalModels?{externalModels:execution.configuration.externalModels}:{}),excludedContexts:['control-host'],
509
- ...(controlPolicy?{controlPolicy}:{}),
565
+ ...(controlPolicy?{controlPolicy:savedPolicy??controlPolicy}:{}),
566
+ ...(parallelSelection===null?{}:{parallelSelection}),
510
567
  developer:{provider:'codex',requestedModel:'unconfigured',contextId:'control-developer',run:unavailable},
511
568
  reviewers:[],check:unavailable,taskCompletion:{reviewsDir,handoffs},taskLearning:{feature},
512
569
  persistence:{store,mode:runnerMode,version:execution===null?2:3},
@@ -522,9 +579,17 @@ async function openControlRunOwned(definition,mode,execution=null,{rerunUnknownQ
522
579
  entry:{specsDir,codeProject,feature,identity,rerunUnknownQa,rerunBlockedQa,
523
580
  ...(definition.featureSelection?{featureSelection:definition.featureSelection.feature}:{}),
524
581
  ...(knowledgeCloseout===null?{}:{knowledgeCloseout,...(definition.codeProjects?{codeProjects:definition.codeProjects}:{})}),
525
- ...(qaEnvironmentFailure===null?{}:{qaEnvironmentFailure}),allowAbandonReview,allowAbandonEffect,allowBootstrapReviewRecovery,allowDevelopRedo,...(holdRevision?{holdRevision}:{}),...(selection===null?{}:{parallelSelection:selection}),...(execution===null?{}:{
526
- ...Object.fromEntries(['developmentAttempt','qaDecisionProvider','qaLogHome','qaExecutor','applicableAgentFiles','documentationProvider','documentationResult'].filter(key=>Object.hasOwn(execution,key)).map(key=>[key,execution[key]]))})},
582
+ ...(qaEnvironmentFailure===null?{}:{qaEnvironmentFailure}),allowAbandonReview,allowAbandonEffect,allowBootstrapReviewRecovery,allowDevelopRedo,allowCompletionRework:Boolean(controlPolicy)&&mode==='resume'&&parallelSelection===null&&conversationProtection(execution)===null
583
+ &&!protectedExecutions.has(execution)&&!execution.configuration.providerDevelopment,...(holdRevision?{holdRevision}:{}),...(selection===null?{}:{parallelSelection:selection}),...(execution===null?{}:{
584
+ ...Object.fromEntries(['developmentAttempt','qaDecisionProvider','qaLogHome','qaExecutor','applicableAgentFiles','documentationProvider','documentationResult'].filter(key=>Object.hasOwn(execution,key)
585
+ &&!(implicitQaSuppressed&&key==='qaDecisionProvider')).map(key=>[key,execution[key]]))})},
527
586
  });
587
+ if(elevatedRecovery||reviewedIntegration!==null){
588
+ const result=reviewedIntegration!==null?host.acceptReviewedIntegration({allowed:true,...reviewedIntegration})
589
+ :scopeRevision!==null?host.reviseScope({allowed:true,...scopeRevision})
590
+ :host.reworkDevelopment({allowed:true,reason:developmentReworkReason});
591
+ if(result.outcome==='rejected')fail(result.code);
592
+ }
528
593
  const logAbandonments=()=>{
529
594
  for(const record of store.snapshot().records.filter(row=>row.payload.type==='review-invocation-abandoned'))
530
595
  recordReviewAbandonment({specsDir,codeProject,feature,identity,record,
@@ -535,15 +600,15 @@ async function openControlRunOwned(definition,mode,execution=null,{rerunUnknownQ
535
600
  runtime:execution?.developer?.provider??'codex',
536
601
  ...(execution?.qaLogHome?{logHome:execution.qaLogHome}:{})});
537
602
  };
538
- if(mode==='resume')logAbandonments();
603
+ if(mode==='resume'&&reviewedIntegration===null)logAbandonments();
539
604
  const recorded=store.snapshot().records.find(row=>row.payload.type==='evidence-superseded')?.payload.record??null;
540
- if(supersession!==null||recorded!==null){
605
+ if(reviewedIntegration===null&&(supersession!==null||recorded!==null)){
541
606
  const record=host.supersedeEvidence(supersession??recorded);
542
607
  archiveReviewedEvidence(reviewsDir,record);
543
608
  recordEvidenceSupersession({specsDir,codeProject,identity,record,
544
609
  ...(execution?.qaLogHome?{logHome:execution.qaLogHome}:{})});
545
610
  }
546
- if(attaching||attached){
611
+ if(reviewedIntegration===null&&(attaching||attached)){
547
612
  const record=host.attachQa(attached??{version:1,qaFingerprint:fingerprints.config,
548
613
  attachedAt:new Date().toISOString().replace(/\.\d{3}Z$/,'Z'),hostContextId:execution.configuration.hostContextId});
549
614
  // Repeating this deterministic log write also repairs a crash after the
@@ -554,7 +619,7 @@ async function openControlRunOwned(definition,mode,execution=null,{rerunUnknownQ
554
619
  const qaBinding={specsDir,codeProject,feature,identity,
555
620
  ...(execution?.qaLogHome?{logHome:execution.qaLogHome}:{})};
556
621
  // Repair a crash after the journal append, before the log supersession.
557
- for(const record of chain.revisions)recordCmAiQaConfigurationRevision({...qaBinding,identity:{...identity,attempt:record.taskAttempt},packageDigest:record.packageDigest},record);
622
+ for(const record of reviewedIntegration===null?chain.revisions:[])recordCmAiQaConfigurationRevision({...qaBinding,identity:{...identity,attempt:record.taskAttempt},packageDigest:record.packageDigest},record);
558
623
  if(specRebindReason!==null){
559
624
  // Consumed once on this launch; the journal record is the audit trail.
560
625
  host.rebindSpecification({version:1,reason:specRebindReason,at:new Date().toISOString()});
@@ -578,7 +643,9 @@ async function openControlRunOwned(definition,mode,execution=null,{rerunUnknownQ
578
643
  // Replaying or repairing its audit mirror above is not new execution.
579
644
  if(!beforeQa)writeCmAiQaStatus({specsDir,feature,identity:current.identity,phase:'configuration_revised'});
580
645
  }
581
- const legacyHost={async handle(request){
646
+ const legacyHost={acceptReviewedIntegration:host.acceptReviewedIntegration,async handle(request){
647
+ if(reviewedIntegration!==null&&request.operation!=='status')
648
+ return {outcome:'rejected',code:'integration_launch_status_only'};
582
649
  if(execution===null&&!['status','cancel'].includes(request.operation)){
583
650
  // Do not imply an unavailable execution adapter was dispatched.
584
651
  return {outcome:'blocked',code:'execution_adapter_required',providerCalls:0};
@@ -588,7 +655,7 @@ async function openControlRunOwned(definition,mode,execution=null,{rerunUnknownQ
588
655
  return result;
589
656
  }};
590
657
  const controlHost=controlPolicy?withControlPolicyHost(legacyHost,{identity,snapshot:()=>store.snapshot(),launchTarget:controlLaunchTarget}):null;
591
- return {host:legacyHost,...(controlHost?{controlHost}:{}),inspectFixAssociation:host.inspectFixAssociation,acceptCompletedFix:host.acceptCompletedFix,
658
+ return {host:legacyHost,...(controlHost?{controlHost}:{}),inspectFixAssociation:host.inspectFixAssociation,acceptCompletedFix:host.acceptCompletedFix,acceptReviewedIntegration:host.acceptReviewedIntegration,
592
659
  checkpoint:()=>store.snapshot().revision,close:()=>store.close()};
593
660
  }catch(error){store.close();throw error;}
594
661
  }