@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
@@ -19,6 +19,7 @@
19
19
  // "hostContext": "<当前真实会话 ID>",
20
20
  // "originalHostContext": "<旧会话 ID>", 只在换会话恢复时填
21
21
  // "runtime": "codex" | "claude", 缺省 codex
22
+ // "reviewRuntime": "codex" | "claude", 可选;省略沿用 runtime,恢复不能改
22
23
  // "reviewConfig": "review.json", 可选
23
24
  // "permissions": ["--allow-red-test", ...], 原样传给宿主,不另造一套词
24
25
  // "answers": "answers", 答案目录;abandon_step / abandon_review 可省略
@@ -34,13 +35,23 @@
34
35
  // retrospective.json {status, candidates, reason}
35
36
  // test-edits.json {"仓库内路径": "本目录下的内容文件"};修订轮用 test-edits-a2.json
36
37
  // repair-edits.json 同上;修订轮用 repair-edits-a2.json
38
+ //
39
+ // 受控 Jest 启动更正:先用 cm-fix-command-correction.mjs --config FIX_CONFIG
40
+ // --jest-config mobile/package.json 只读预览;再用原 PLAN 执行 prepare_command_correction。
41
+ // PLAN 须 mode:resume、完整 expected、commandCorrection:{kind:'jest-config-path',path}、
42
+ // previousInvocationStopped:true、reason 和 permissions:['--allow-command-correction']。
43
+ // 只追加 --config,保留原配置/历史,每 run 一次;准备不跑测试或 provider。
44
+ // 详见 skills/cm-fix/references/command-correction.md。新 run 会预检 Jest 配置发现。
37
45
  import fs from 'node:fs';
46
+ import {assertJestConfigurationDiscovery} from '../runtime/js/cm-fix/jest-command-correction.mjs';
38
47
  import path from 'node:path';
39
48
  import {fileURLToPath} from 'node:url';
40
49
  import {fixEvidenceNames} from '../runtime/js/cm-fix/layout.mjs';
41
50
  import {inspectFixDiagnosis,describeFixDiagnosisError} from '../runtime/js/cm-fix/diagnosis.mjs';
42
51
  import {readExecutionSnapshot} from '../runtime/js/cm-ai/execution-snapshot.mjs';
43
52
  import {stderr,stop,readJson,loadPlanFile,requireFields,preflightAnswers,driveHost} from '../runtime/js/cm-ai/drive-core.mjs';
53
+ import {cmFixSessionBoundary} from '../runtime/js/session-boundary.mjs';
54
+ import {printHandoff} from '../runtime/js/session-handoff.mjs';
44
55
 
45
56
  const here=path.dirname(fileURLToPath(import.meta.url));
46
57
  const HOST=path.join(here,'cm-fix-host.mjs');
@@ -60,13 +71,15 @@ const ASKS={
60
71
  const READ_ONLY=new Set(['status','final_review_package','completion_evidence','cause_review_package']);
61
72
  const KNOWN=new Set([...Object.keys(ASKS),...READ_ONLY,'cancel','handoff','publish_review','check_n5',
62
73
  'publish_dossier','learning_writeback','walkthrough','finish','final_review','cause_review',
63
- 'reconcile_review','recover_final_review','abandon_step','abandon_review','rerun_blocked_step','resume','revision_test_check']);
74
+ 'prepare_test_type_correction','prepare_command_correction','prepare_diagnosis_module_correction','prepare_verification_recovery','reconcile_review','recover_final_review','abandon_step','abandon_review','rerun_blocked_step','resume','revision_test_check']);
64
75
 
65
76
  function loadPlan(){
66
77
  const {operation,plan,base}=loadPlanFile({name:'cm-fix-drive.mjs',known:KNOWN});
67
78
  const abandoning=['abandon_step','abandon_review','rerun_blocked_step'].includes(operation);
68
- requireFields(plan,['config','cwd','mode','hostContext','permissions',...(abandoning||operation==='reconcile_review'?[]:['answers'])]);
79
+ requireFields(plan,['config','cwd','mode','hostContext','permissions',...(abandoning||['reconcile_review','prepare_test_type_correction','prepare_command_correction','prepare_diagnosis_module_correction','prepare_verification_recovery','recover_final_review'].includes(operation)?[]:['answers'])]);
69
80
  if(!['create','resume'].includes(plan.mode))stop(2,'mode 只能是 create 或 resume');
81
+ for(const key of ['runtime','reviewRuntime'])
82
+ if(Object.hasOwn(plan,key)&&!['codex','claude'].includes(plan[key]))stop(2,`${key} 只能是 codex 或 claude`);
70
83
  if(!Array.isArray(plan.permissions))stop(2,'permissions must be an array');
71
84
  for(let i=0;i<plan.permissions.length;i++){
72
85
  const flag=plan.permissions[i];
@@ -75,6 +88,12 @@ function loadPlan(){
75
88
  plan.permissions[++i]=path.resolve(base,plan.permissions[i]);
76
89
  }else if(!['--execution-optimizations','--external-models'].includes(flag)&&!/^--allow-[a-z-]+$/.test(flag))stop(2,'invalid permissions');
77
90
  }
91
+ if(operation==='prepare_test_type_correction'&&(plan.mode!=='resume'||!plan.permissions.includes('--allow-test-type-correction')||!plan.expected||!plan.testTypeCorrection||plan.previousInvocationStopped!==true||typeof plan.reason!=='string'||!plan.reason.trim()))stop(2,'prepare_test_type_correction requires resume, expected, testTypeCorrection, stopped confirmation, reason and --allow-test-type-correction');
92
+ if(operation==='prepare_command_correction'&&(plan.mode!=='resume'||!plan.permissions.includes('--allow-command-correction')||!plan.expected||!plan.commandCorrection||plan.previousInvocationStopped!==true||typeof plan.reason!=='string'||!plan.reason.trim()))stop(2,'prepare_command_correction requires resume, expected, commandCorrection, stopped confirmation, reason and --allow-command-correction');
93
+ if(operation==='prepare_diagnosis_module_correction'&&(plan.mode!=='resume'||!plan.permissions.includes('--allow-diagnosis-module-correction')||!plan.expected||plan.previousInvocationStopped!==true||typeof plan.reason!=='string'||!plan.reason.trim()||Buffer.byteLength(plan.reason,'utf8')>1000||/[\r\n\0\u0085\u2028\u2029]/.test(plan.reason)))stop(2,'prepare_diagnosis_module_correction requires resume, complete expected, stopped confirmation, single-line reason and --allow-diagnosis-module-correction');
94
+ if(operation==='prepare_verification_recovery'&&(plan.mode!=='resume'||!plan.permissions.includes('--allow-verification-recovery')||!plan.expected||plan.previousInvocationStopped!==true||typeof plan.reason!=='string'||!plan.reason.trim()))stop(2,'prepare_verification_recovery 需要 resume、expected、previousInvocationStopped:true、reason 和 --allow-verification-recovery');
95
+ if(Object.hasOwn(plan,'sourceCorrection')&&(operation!=='prepare_verification_recovery'||plan.mode!=='resume'||!plan.permissions.includes('--allow-source-correction')))stop(2,'sourceCorrection 仅用于 resume 的 prepare_verification_recovery,并须 --allow-source-correction');
96
+ if(Object.hasOwn(plan,'verificationRecoveryAuthorization')&&!/^[a-f0-9]{64}$/.test(plan.verificationRecoveryAuthorization))stop(2,'verificationRecoveryAuthorization 必须是准备记录的摘要');
78
97
  if(operation==='reconcile_review'&&(plan.mode!=='resume'||typeof plan.invocationId!=='string'||!plan.invocationId))stop(2,'reconcile_review requires resume and original invocationId');
79
98
  const abandonFlag=operation==='abandon_review'?'--allow-abandon-review':operation==='rerun_blocked_step'?'--allow-rerun-blocked-step':'--allow-abandon';
80
99
  if(abandoning&&(!plan.permissions.includes(abandonFlag)||typeof plan.reason!=='string'
@@ -157,6 +176,7 @@ export function preflight({operation,plan,paths}){
157
176
  return map;
158
177
  });
159
178
  if(plan.mode==='create'){
179
+ try{assertJestConfigurationDiscovery(config);}catch(e){stop(2,`${e.code}: Jest needs an explicit --config path before this run is frozen; --rootDir is not config discovery.`);}
160
180
  // 建运行前的体检:宿主也会查,但这里把「是哪个文件」提前说清。
161
181
  const cwd=path.resolve(plan.cwd);
162
182
  for(const file of [...(config.testAuthor?.requirements??[]),...(config.repair?.requirements??[]),
@@ -183,7 +203,10 @@ function hostArgs({plan,paths}){
183
203
  return [HOST,'serve','--config',paths.config,'--mode',plan.mode,'--host-context',plan.hostContext,'--allow-reproduction',
184
204
  ...(plan.originalHostContext?['--original-host-context',plan.originalHostContext]:[]),
185
205
  '--runtime',plan.runtime??'codex',
206
+ ...(Object.hasOwn(plan,'reviewRuntime')?['--review-runtime',plan.reviewRuntime]:[]),
186
207
  ...(Object.hasOwn(plan,'inputLimit')?['--input-limit',String(plan.inputLimit)]:[]),
208
+ ...(plan.verificationRecoveryAuthorization?['--verification-recovery-authorization',plan.verificationRecoveryAuthorization]:[]),
209
+ ...(plan.finalReviewRecoveryInvocation?['--final-review-recovery-invocation',plan.finalReviewRecoveryInvocation]:[]),
187
210
  ...(paths.review?['--review-config',paths.review]:[]),
188
211
  ...plan.permissions];
189
212
  }
@@ -230,12 +253,17 @@ export function answerFor(row,answers,paths){
230
253
 
231
254
  function main(){
232
255
  const loaded=loadPlan();
233
- const {answers,round}=preflight(loaded);
256
+ const {config,answers,round}=preflight(loaded);
234
257
  const {operation,plan,paths}=loaded;
258
+ const archive=config.specsRoot??path.join(path.resolve(plan.cwd),'docs','fixes');
259
+ if(plan.mode==='create')printHandoff(archive);
235
260
  driveHost({host:HOST,args:hostArgs(loaded).slice(1),cwd:path.resolve(plan.cwd),operation,
236
- request:{...(operation==='reconcile_review'?{invocationId:plan.invocationId}:{}),...(['abandon_step','abandon_review','rediagnose','rerun_blocked_step'].includes(operation)?{reason:plan.reason}:{}),
261
+ request:{...(operation==='prepare_diagnosis_module_correction'?{expected:plan.expected,previousInvocationStopped:plan.previousInvocationStopped,reason:plan.reason}:{}),...(operation==='prepare_test_type_correction'?{expected:plan.expected,testTypeCorrection:plan.testTypeCorrection,previousInvocationStopped:plan.previousInvocationStopped,reason:plan.reason}:{}),...(operation==='prepare_command_correction'?{expected:plan.expected,commandCorrection:plan.commandCorrection,previousInvocationStopped:plan.previousInvocationStopped,reason:plan.reason}:{}),...(operation==='prepare_verification_recovery'?{expected:plan.expected,...(Object.hasOwn(plan,'sourceCorrection')?{sourceCorrection:plan.sourceCorrection}:{}),previousInvocationStopped:plan.previousInvocationStopped,reason:plan.reason}:{}),
262
+ ...(operation==='recover_final_review'?{invocationId:plan.invocationId,packageDigest:plan.packageDigest,previousInvocationStopped:plan.previousInvocationStopped,reason:plan.reason}:{}),
263
+ ...(operation==='reconcile_review'?{invocationId:plan.invocationId}:{}),...(['abandon_step','abandon_review','rediagnose','rerun_blocked_step'].includes(operation)?{reason:plan.reason}:{}),
237
264
  ...(operation==='prepare_revision'&&Object.hasOwn(plan,'revisionTests')?{tests:plan.revisionTests}:{})},
238
- answers,paths:{...paths,round},answerFor});
265
+ answers,paths:{...paths,round},answerFor,
266
+ sessionBoundary:(result,op)=>cmFixSessionBoundary(result,op,{archive,runId:config.identity?.runId})});
239
267
  }
240
268
 
241
269
  if(process.argv[1]&&path.resolve(process.argv[1])===fileURLToPath(import.meta.url))main();
@@ -8,6 +8,8 @@ import {fileURLToPath} from 'node:url';
8
8
  import {isSupportedExecutionPlatform} from '../runtime/js/cm-ai/execution-platform.mjs';
9
9
  import {openFixExecution} from '../runtime/js/cm-fix/execution.mjs';
10
10
  import {openExecutionStore} from '../runtime/js/cm-ai/execution-store.mjs';
11
+ import {configFingerprint} from '../runtime/js/cm-ai/codex-config.mjs';
12
+ import {claudeReviewFingerprint} from '../runtime/js/cm-ai/worker-claude.mjs';
11
13
  import {startFixRun} from '../runtime/js/cm-fix/start.mjs';
12
14
 
13
15
  // Never write the real ~/.cm-workflow home or its global log from this suite.
@@ -150,3 +152,50 @@ test('revision repair requires its own answer before launching the host',{skip},
150
152
  assert.equal(run.status,2,run.stderr);assert.match(run.stderr,/repair-edits-a2\.json/);
151
153
  assert.deepEqual(fs.readFileSync(statePath),before);
152
154
  });
155
+
156
+ for(const [runtime,reviewRuntime] of [['codex','claude'],['claude','codex']])
157
+ test(`${runtime}/${reviewRuntime} driver preserves reviewer configuration on resume and refuses drift`,{skip},t=>{
158
+ const f=fixture(t),model='synthetic';
159
+ fs.writeFileSync(path.join(f.cwd,'.cm-workflow.json'),JSON.stringify({version:1,policies:{delivery:'diff'},
160
+ roles:{coder:{adapter:`${runtime}-cli`},reviewer:{adapter:`${reviewRuntime}-cli`}},runtimes:{available:'both'}}));
161
+ const review={model,disabledSkills:[],preflight:reviewRuntime==='claude'
162
+ ?{passed:true,provider:'claude',prompt_transport:'stdin',config_fingerprint:claudeReviewFingerprint({cwd:f.cwd,model})}
163
+ :{passed:true,cli_model:model,prompt_transport:'stdin',config_fingerprint:configFingerprint({cwd:f.cwd,model,disabledSkills:[],promptTransport:'stdin'})}};
164
+ fs.writeFileSync(path.join(f.root,'review.json'),JSON.stringify(review));
165
+ const selected={runtime,reviewRuntime,reviewConfig:'review.json'};
166
+ const created=drive(f.plan(selected),'status');assert.equal(created.status,0,created.stderr);
167
+ const statePath=path.join(f.archive,'.reviews','.execution','drive-demo','state.json');
168
+ const before=fs.readFileSync(statePath),saved=JSON.parse(before).records[0].payload;
169
+ assert.equal(saved.configuration.runtime??'codex',runtime);
170
+ assert.equal(saved.configuration.reviewRuntime,reviewRuntime);
171
+ assert.equal(saved.configuration.causeReview.provider,reviewRuntime);
172
+ const resumed=drive(f.plan({...selected,mode:'resume'}),'status');assert.equal(resumed.status,0,resumed.stderr);
173
+ assert.deepEqual(fs.readFileSync(statePath),before,'status resume must not dispatch or rewrite history');
174
+ const omitted=drive(f.plan({...selected,reviewRuntime:undefined,mode:'resume'}),'status');
175
+ assert.notEqual(omitted.status,0);assert.deepEqual(fs.readFileSync(statePath),before);
176
+ const switched=drive(f.plan({...selected,reviewRuntime:runtime,mode:'resume'}),'status');
177
+ assert.notEqual(switched.status,0);assert.deepEqual(fs.readFileSync(statePath),before);
178
+ review.model='different';fs.writeFileSync(path.join(f.root,'review.json'),JSON.stringify(review));
179
+ const stale=drive(f.plan({...selected,mode:'resume'}),'status');
180
+ assert.notEqual(stale.status,0);assert.match(stale.stderr,/tool_preflight_missing/);
181
+ assert.deepEqual(fs.readFileSync(statePath),before);
182
+ if(reviewRuntime==='codex')review.preflight.cli_model=review.model;
183
+ review.preflight.config_fingerprint=(reviewRuntime==='claude'?claudeReviewFingerprint:configFingerprint)({cwd:f.cwd,model:review.model,disabledSkills:[],promptTransport:'stdin'});
184
+ fs.writeFileSync(path.join(f.root,'review.json'),JSON.stringify(review));
185
+ const changed=drive(f.plan({...selected,mode:'resume'}),'status');
186
+ assert.notEqual(changed.status,0);assert.match(changed.stderr,/fingerprint_mismatch/);
187
+ assert.deepEqual(fs.readFileSync(statePath),before);
188
+ });
189
+
190
+ test('driver refuses retrofitting an explicit reviewer onto a legacy same-tool run',{skip},t=>{
191
+ const f=fixture(t),model='synthetic';
192
+ fs.writeFileSync(path.join(f.cwd,'.cm-workflow.json'),JSON.stringify({version:1,runtimes:{available:'codex'}}));
193
+ fs.writeFileSync(path.join(f.root,'review.json'),JSON.stringify({model,disabledSkills:[],preflight:{passed:true,
194
+ cli_model:model,prompt_transport:'stdin',config_fingerprint:configFingerprint({cwd:f.cwd,model,disabledSkills:[],promptTransport:'stdin'})}}));
195
+ const created=drive(f.plan({reviewConfig:'review.json'}),'status');assert.equal(created.status,0,created.stderr);
196
+ const statePath=path.join(f.archive,'.reviews','.execution','drive-demo','state.json'),before=fs.readFileSync(statePath);
197
+ const attempted=drive(f.plan({mode:'resume',reviewRuntime:'codex',reviewConfig:'review.json'}),'status');
198
+ assert.notEqual(attempted.status,0);assert.match(attempted.stderr,/fingerprint_mismatch/);
199
+ assert.deepEqual(fs.readFileSync(statePath),before);
200
+ assert.equal(drive(f.plan({mode:'resume',reviewConfig:'review.json'}),'status').status,0);
201
+ });
@@ -1,4 +1,4 @@
1
- import test from 'node:test';
1
+ import test,{after} from 'node:test';
2
2
  import assert from 'node:assert/strict';
3
3
  import os from 'node:os';
4
4
  import fs from 'node:fs';
@@ -6,6 +6,16 @@ import path from 'node:path';
6
6
  import {createFixReviewHost} from '../runtime/js/cm-fix/host-review.mjs';
7
7
  import {configFingerprint} from '../runtime/js/cm-ai/codex-config.mjs';
8
8
  import {claudeReviewFingerprint} from '../runtime/js/cm-ai/worker-claude.mjs';
9
+ import {openFixExecution} from '../runtime/js/cm-fix/execution.mjs';
10
+ import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
11
+ import {createFixCausePackage} from '../runtime/js/cm-fix/cause-package.mjs';
12
+ import {validateReviewDispatchGrant} from '../runtime/js/cm-ai/durable-runner-state.mjs';
13
+
14
+ const isolatedHome=fs.mkdtempSync(path.join(os.tmpdir(),'fix-review-assembly-home-'));
15
+ const previousHome=process.env.CM_WORKFLOW_HOME;
16
+ process.env.CM_WORKFLOW_HOME=isolatedHome;
17
+ after(()=>{if(previousHome===undefined)delete process.env.CM_WORKFLOW_HOME;else process.env.CM_WORKFLOW_HOME=previousHome;
18
+ fs.rmSync(isolatedHome,{recursive:true,force:true});});
9
19
 
10
20
  for(const runtime of ['codex','claude'])test(`${runtime} fix assembly keeps child review permissions separate and lazy`,async()=>{
11
21
  const codeProject=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'fix-review-assembly-')));
@@ -32,3 +42,189 @@ for(const runtime of ['codex','claude'])test(`${runtime} fix assembly keeps chil
32
42
  assert.equal(workers,0);
33
43
  }finally{fs.rmSync(codeProject,{recursive:true,force:true});}
34
44
  });
45
+
46
+
47
+ function reviewConfig(codeProject,provider,{model='synthetic',effort}={}){
48
+ const options={cwd:codeProject,model,disabledSkills:[],promptTransport:'stdin',...(effort===undefined?{}:{effort})};
49
+ return {model,disabledSkills:[],...(effort===undefined?{}:{effort}),preflight:provider==='codex'
50
+ ?{passed:true,cli_model:model,prompt_transport:'stdin',config_fingerprint:configFingerprint(options)}
51
+ :{passed:true,provider:'claude',prompt_transport:'stdin',config_fingerprint:claudeReviewFingerprint(options)}};
52
+ }
53
+ function writeRoles(codeProject,runtime,reviewRuntime){
54
+ fs.writeFileSync(path.join(codeProject,'.cm-workflow.json'),JSON.stringify({version:1,policies:{delivery:'diff'},
55
+ roles:{coder:{adapter:`${runtime}-cli`},reviewer:{adapter:`${reviewRuntime}-cli`}},runtimes:{available:'both'}}));
56
+ }
57
+ function causeRequest(codeProject,provider){
58
+ fs.writeFileSync(path.join(codeProject,'value.mjs'),'export const value=1;');
59
+ const identity={repositoryId:'fixture',runId:'cross-assembly',taskId:'T-FIX-cross',attempt:1};
60
+ const pkg=createFixCausePackage({codeProject,defect:'Fixture value mismatch',status:{identity,stage:'cause_review_required',learning:null,
61
+ reproduction:{status:'reproduced',next:'diagnose',observation:{id:'reproduce',command:['fixture'],outcome:'failed',exitCode:1,evidence:'fixture failure',signatureMatched:true}},
62
+ diagnosis:{status:'diagnosed',rootCause:'Cross-layer constant',plan:'Correct source after red test',affectedPaths:['value.mjs'],affectedModules:['value'],crossLayer:true}}});
63
+ const body={version:1,invocationId:'cross-cause-call',identity,role:'reviewer',provider,requestedModel:'synthetic',contextId:'fresh-review',payload:{reviewPackage:pkg,priorReview:null}};
64
+ return {...body,requestDigest:digest(body)};
65
+ }
66
+
67
+ for(const [runtime,reviewRuntime] of [['codex','claude'],['claude','codex']]){
68
+ test(`${runtime}/${reviewRuntime} fix assembly binds reviewer diagnostics, adapters and immutable worker options`,async()=>{
69
+ const codeProject=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'fix-cross-assembly-')));
70
+ try{
71
+ writeRoles(codeProject,runtime,reviewRuntime);
72
+ const review=reviewConfig(codeProject,reviewRuntime),captured=[];
73
+ let dispatches=0;
74
+ const base={codeProject,hostContextId:'author-host',runtime,reviewRuntime,review,permissions:['--allow-cause-review','--allow-final-review'],
75
+ workerFactory:options=>{captured.push(options);return async()=>{dispatches++;return {status:'failed',code:'reviewer_auth_failed'};};}};
76
+ const host=createFixReviewHost(base),request=causeRequest(codeProject,reviewRuntime);
77
+ assert.equal(host.reviewer.provider,reviewRuntime);
78
+ assert.equal(host.reviewer.adapterId,`${reviewRuntime}-cause-review-adapter`);
79
+ assert.equal(host.reviewer.requestedModel,review.model);
80
+ assert.equal(host.reviewer.workerConfigurationDigest,digest({cwd:codeProject,model:review.model,disabledSkills:[],promptTransport:'stdin',...(reviewRuntime==='claude'?{runtime:reviewRuntime}:{})}));
81
+ assert.equal(captured.length,0,'construction is not provider dispatch');
82
+ // Caller mutation cannot change a prepared review's provider/model/receipt.
83
+ review.model='caller-mutated';review.preflight.passed=false;
84
+ const control={signal:new AbortController().signal,onEvent:()=>true};
85
+ assert.deepEqual(await host.execution.causeReview.run(request,control),{status:'failed',code:'reviewer_auth_failed'});
86
+ assert.equal(dispatches,1,'provider failure is preserved, never an approved review');
87
+ assert.equal(captured[0].model,'synthetic');assert.equal(captured[0].preflight.passed,true);
88
+ assert.equal(captured[0].cwd,codeProject);assert.equal(captured[0].promptTransport,'stdin');
89
+ const wrongBody={...request,provider:runtime};delete wrongBody.requestDigest;
90
+ const wrongRequest={...wrongBody,requestDigest:digest(wrongBody)};
91
+ for(const phase of ['causeReview','finalReview'])assert.throws(()=>host.execution[phase].run(wrongRequest,control),{code:'review_request_invalid'});
92
+ assert.equal(dispatches,1,'wrong provider cannot reach the native worker');
93
+ assert.throws(()=>createFixReviewHost({...base,review:reviewConfig(codeProject,runtime)}),{code:'tool_preflight_missing'});
94
+ assert.throws(()=>createFixReviewHost({...base,review:null}),{code:'review_configuration_required'});
95
+ for(const mutate of [r=>{r.preflight.passed=false;},r=>{r.model='different-model';},r=>{r.preflight.prompt_transport='argument';},r=>{r.preflight.config_fingerprint='0'.repeat(64); }]){
96
+ const bad=reviewConfig(codeProject,reviewRuntime);mutate(bad);
97
+ assert.throws(()=>createFixReviewHost({...base,review:bad}),{code:'tool_preflight_missing'});
98
+ }
99
+ const elsewhere=fs.mkdtempSync(path.join(codeProject,'different-root-'));
100
+ assert.throws(()=>createFixReviewHost({...base,review:reviewConfig(elsewhere,reviewRuntime)}),{code:'tool_preflight_missing'});
101
+ }finally{fs.rmSync(codeProject,{recursive:true,force:true});}
102
+ });
103
+
104
+ test(`${runtime}/${reviewRuntime} fix assembly rejects live role drift before readiness and both dispatch phases`,()=>{
105
+ const codeProject=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'fix-cross-drift-')));
106
+ try{
107
+ writeRoles(codeProject,runtime,reviewRuntime);let workers=0;
108
+ const base={codeProject,hostContextId:'author-host',runtime,reviewRuntime,review:reviewConfig(codeProject,reviewRuntime),permissions:[],
109
+ workerFactory:()=>{workers++;throw Error('must not create worker after role drift');}};
110
+ assert.throws(()=>createFixReviewHost({...base,reviewRuntime:null}),{code:'invalid_runtime'});
111
+ const host=createFixReviewHost(base);host.execution.assertReviewReady();
112
+ writeRoles(codeProject,reviewRuntime,runtime);
113
+ assert.throws(()=>createFixReviewHost(base),{code:'fix_review_runtime_mismatch'});
114
+ assert.throws(()=>host.execution.assertReviewReady(),{code:'fix_review_runtime_mismatch'});
115
+ for(const phase of ['causeReview','finalReview'])assert.throws(()=>host.execution[phase].run({},{}),{code:'fix_review_runtime_mismatch'});
116
+ assert.equal(workers,0);
117
+ fs.writeFileSync(path.join(codeProject,'.cm-workflow.json'),'invalid json');
118
+ assert.throws(()=>createFixReviewHost(base),{code:'invalid_workflow_config'});
119
+ writeRoles(codeProject,reviewRuntime,runtime);
120
+ // A run without the new field retains the prior same-tool contract even
121
+ // when the project's current role declarations describe another route.
122
+ const legacy=createFixReviewHost({...base,reviewRuntime:undefined,review:reviewConfig(codeProject,runtime)});
123
+ assert.equal(legacy.reviewer.provider,runtime);legacy.execution.assertReviewReady();
124
+ assert.equal(workers,0);
125
+ }finally{fs.rmSync(codeProject,{recursive:true,force:true});}
126
+ });
127
+
128
+ test(`${runtime}/${reviewRuntime} fix assembly selects only reviewer external model and effort`,()=>{
129
+ const codeProject=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'fix-cross-model-')));
130
+ try{
131
+ writeRoles(codeProject,runtime,reviewRuntime);
132
+ const externalModels={schemaVersion:1,providers:{codex:{model:'codex-model',effort:'high'},claude:{model:'claude-model',effort:'max'}}};
133
+ const pair=externalModels.providers[reviewRuntime],review=reviewConfig(codeProject,reviewRuntime,pair);
134
+ const base={codeProject,hostContextId:'author-host',runtime,reviewRuntime,review,externalModels};
135
+ const host=createFixReviewHost(base);
136
+ assert.equal(host.reviewer.requestedModel,pair.model);
137
+ assert.equal(host.reviewer.workerConfigurationDigest,digest({cwd:codeProject,model:pair.model,effort:pair.effort,disabledSkills:[],promptTransport:'stdin',...(reviewRuntime==='claude'?{runtime:reviewRuntime}:{})}));
138
+ assert.throws(()=>createFixReviewHost({...base,review:{...review,model:externalModels.providers[runtime].model}}),{code:'external_model_pair_conflict'});
139
+ assert.throws(()=>createFixReviewHost({...base,review:{...review,effort:'low'}}),{code:'external_model_pair_conflict'});
140
+ assert.throws(()=>createFixReviewHost({...base,externalModels:{schemaVersion:1,providers:{[runtime]:externalModels.providers[runtime]}}}),{code:'external_model_setup_required'});
141
+ const stale=reviewConfig(codeProject,reviewRuntime,{...pair,effort:'low'});stale.effort=pair.effort;
142
+ assert.throws(()=>createFixReviewHost({...base,review:stale}),{code:'tool_preflight_missing'});
143
+ }finally{fs.rmSync(codeProject,{recursive:true,force:true});}
144
+ });
145
+
146
+ test(`${runtime}/${reviewRuntime} cause and final grants bind reviewer while expired or reused grants stay rejected`,async()=>{
147
+ const codeProject=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'fix-cross-grant-')));
148
+ try{
149
+ writeRoles(codeProject,runtime,reviewRuntime);
150
+ const host=createFixReviewHost({codeProject,hostContextId:'author-host',runtime,reviewRuntime,review:reviewConfig(codeProject,reviewRuntime),permissions:['--allow-cause-review','--allow-final-review']});
151
+ const request=causeRequest(codeProject,reviewRuntime),packageDigest=request.payload.reviewPackage.packageDigest;
152
+ for(const [authority,reviewerId,adapterId] of [[host.authority,'fix-cause-reviewer',`${reviewRuntime}-cause-review-adapter`],[host.finalAuthority,'fix-final-reviewer',`${reviewRuntime}-review-adapter`]]){
153
+ const signal=new AbortController().signal;
154
+ await authority.hostDecisionProvider.decide({identity:request.identity,packageDigest},signal);
155
+ const authorizationAt=Date.now(),grant=authority.authorize(request,{authorizationAt});
156
+ const expected={request,reviewerId,adapterId,packageDigest,hostContextIds:['author-host'],authorizationAt,registeredAt:authorizationAt};
157
+ assert.deepEqual(validateReviewDispatchGrant(grant,expected),grant);
158
+ assert.equal(grant.hostContextId,'author-host');assert.equal(grant.adapterId,adapterId);
159
+ assert.throws(()=>validateReviewDispatchGrant(grant,{...expected,registeredAt:grant.expiresAt}),{code:'runner_grant'});
160
+ assert.throws(()=>validateReviewDispatchGrant(grant,{...expected,adapterId:`${runtime}-review-adapter`}),{code:'runner_grant'});
161
+ assert.throws(()=>validateReviewDispatchGrant(grant,{...expected,packageDigest:'0'.repeat(64)}),{code:'runner_grant'});
162
+ assert.deepEqual(authority.authorize(request,{authorizationAt}),{status:'denied',code:'permission_denied'});
163
+ await authority.hostDecisionProvider.decide({identity:request.identity,packageDigest},signal);
164
+ assert.deepEqual(authority.authorize(request,{authorizationAt:Date.now()+60000}),{status:'denied',code:'permission_denied'});
165
+ }
166
+ }finally{fs.rmSync(codeProject,{recursive:true,force:true});}
167
+ });
168
+ }
169
+
170
+ for(const [runtime,reviewRuntime] of [['codex','claude'],['claude','codex']]){
171
+ test(`${runtime}/${reviewRuntime} owner rejects route drift before cause registration without consuming review history`,async()=>{
172
+ const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'fix-cross-owner-drift-')));
173
+ const codeProject=path.join(root,'code'),specsRoot=path.join(root,'specs');fs.mkdirSync(codeProject);fs.mkdirSync(specsRoot);
174
+ let owner,workers=0;
175
+ try{
176
+ writeRoles(codeProject,runtime,reviewRuntime);fs.writeFileSync(path.join(codeProject,'value.mjs'),'export const value=1;');
177
+ const host=createFixReviewHost({codeProject,hostContextId:'author-host',runtime,reviewRuntime,review:reviewConfig(codeProject,reviewRuntime),permissions:['--allow-cause-review'],
178
+ workerFactory:()=>{workers++;throw Error('must not dispatch after route drift');}});
179
+ const identity={repositoryId:'fixture',runId:'cross-owner',taskId:'T-FIX-cross',attempt:1};
180
+ owner=openFixExecution({specsRoot,identity,create:true,configuration:{hostContextId:'author-host',defect:'Wrong value',
181
+ ...(runtime==='claude'?{runtime}:{}),reviewRuntime,causeReview:host.reviewer,
182
+ reproduction:{cwd:codeProject,command:[process.execPath,'-e',"console.error('BUG');process.exit(1)"],expectedFailure:{exitCode:1,outputIncludes:'BUG'},timeoutMs:2000}}},
183
+ {...host.execution,bridge:{async call(){return {status:'diagnosed',rootCause:'Cross-layer value',plan:'Set value to 2',affectedPaths:['value.mjs'],affectedModules:['value'],crossLayer:true};}}});
184
+ await owner.advance({authorized:true});assert.equal(owner.status().stage,'cause_review_required');
185
+ const pkg=owner.causeReviewPackage();await host.authority.hostDecisionProvider.decide({identity,packageDigest:pkg.packageDigest},new AbortController().signal);
186
+ const statePath=path.join(specsRoot,'.reviews','.execution',identity.runId,'state.json'),before=fs.readFileSync(statePath);
187
+ writeRoles(codeProject,reviewRuntime,runtime);
188
+ await assert.rejects(owner.reviewCause(),{code:'fix_review_runtime_mismatch'});
189
+ assert.equal(owner.status().stage,'cause_review_required');assert.equal(workers,0);
190
+ assert.deepEqual(fs.readFileSync(statePath),before,'local rejection must not consume a review slot or append a grant');
191
+ }finally{owner?.close();fs.rmSync(root,{recursive:true,force:true});}
192
+ });
193
+
194
+ test(`${runtime}/${reviewRuntime} default worker launches the selected CLI protocol fixture`,async()=>{
195
+ const codeProject=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'fix-cross-native-'))),previousPath=process.env.PATH;
196
+ try{
197
+ writeRoles(codeProject,runtime,reviewRuntime);
198
+ const bin=path.join(codeProject,'bin');fs.mkdirSync(bin);
199
+ for(const provider of ['codex','claude']){
200
+ const fixture=new URL(`./fixtures/${provider}-review-process.mjs`,import.meta.url);
201
+ const original=fs.readFileSync(fixture,'utf8'),end=original.indexOf('\n');
202
+ const marker=path.join(codeProject,`${provider}.called`);
203
+ fs.writeFileSync(path.join(bin,provider),original.slice(0,end+1)+
204
+ `import {writeFileSync as markCalled} from 'node:fs';markCalled(${JSON.stringify(marker)},'called');\n`+original.slice(end+1),{mode:0o700});
205
+ }
206
+ process.env.PATH=bin+path.delimiter+previousPath;
207
+ const host=createFixReviewHost({codeProject,hostContextId:'author-host',runtime,reviewRuntime,review:{...reviewConfig(codeProject,reviewRuntime),timeoutMs:5000},permissions:['--allow-cause-review']});
208
+ const result=await host.execution.causeReview.run(causeRequest(codeProject,reviewRuntime),{signal:new AbortController().signal,onEvent:()=>true});
209
+ assert.equal(result.status,'succeeded',JSON.stringify(result));assert.equal(result.value.verdict,'approved');
210
+ assert.equal(fs.existsSync(path.join(codeProject,`${reviewRuntime}.called`)),true);
211
+ assert.equal(fs.existsSync(path.join(codeProject,`${runtime}.called`)),false);
212
+ }finally{if(previousPath===undefined)delete process.env.PATH;else process.env.PATH=previousPath;fs.rmSync(codeProject,{recursive:true,force:true});}
213
+ });
214
+ }
215
+
216
+ test('isolated verification changes only reviewer fingerprint and refuses legacy diagnostics or Codex reviewer',{skip:process.platform!=='darwin'},()=>{
217
+ const codeProject=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'fix-review-tools-')));
218
+ try{
219
+ writeRoles(codeProject,'codex','claude');
220
+ const verification={files:['value.mjs'],checks:[{id:'unit',command:['node','--test']}],mutationPaths:['value.mjs'],timeoutMs:1000};
221
+ const review=reviewConfig(codeProject,'claude');
222
+ const args={codeProject,hostContextId:'author-host',runtime:'codex',reviewRuntime:'claude',review,permissions:['--allow-cause-review'],verification};
223
+ assert.throws(()=>createFixReviewHost(args),{code:'tool_preflight_missing'});
224
+ review.preflight.config_fingerprint=claudeReviewFingerprint({cwd:codeProject,model:review.model,verification});
225
+ const host=createFixReviewHost(args);assert.equal(host.reviewer.provider,'claude');host.execution.assertReviewReady();
226
+ assert.notEqual(host.reviewer.workerConfigurationDigest,createFixReviewHost({...args,verification:null,review:reviewConfig(codeProject,'claude')}).reviewer.workerConfigurationDigest);
227
+ assert.throws(()=>createFixReviewHost({...args,reviewRuntime:'codex'}),{code:'review_verification_provider'});
228
+ assert.throws(()=>createFixReviewHost({...args,verification:{...verification,timeoutMs:2000}}),{code:'tool_preflight_missing'});
229
+ }finally{fs.rmSync(codeProject,{recursive:true,force:true});}
230
+ });
@@ -19,8 +19,10 @@ process.env.CM_WORKFLOW_HOME=path.join(isolatedWorkflowHome,'user');
19
19
  process.env.CM_WORKFLOW_LOG_HOME=path.join(isolatedWorkflowHome,'logs');
20
20
  after(()=>fs.rmSync(isolatedWorkflowHome,{recursive:true,force:true}));
21
21
 
22
- for(const runtime of ['codex','claude']){
23
- test(`${runtime} CLI cause review requires opt-in and matching diagnostic, then resumes without dispatch`,async()=>{
22
+ for(const [runtime,reviewRuntime] of [['codex',null],['claude',null],['codex','claude'],['claude','codex']]){
23
+ const selectedReview=reviewRuntime??runtime;
24
+ const workflow={version:1,policies:{delivery:'diff'},...(reviewRuntime?{roles:{coder:{adapter:`${runtime}-cli`},reviewer:{adapter:`${reviewRuntime}-cli`}},runtimes:{available:'both'}}:{})};
25
+ test(`${runtime}/${selectedReview} CLI cause review requires opt-in and matching diagnostic, then resumes without dispatch`,async()=>{
24
26
  const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'fix-host-review-')));
25
27
  const cwd=path.join(root,'code'),specsRoot=path.join(root,'specs');fs.mkdirSync(cwd);fs.mkdirSync(specsRoot);
26
28
  fs.writeFileSync(path.join(cwd,'value.mjs'),'export const value=1;');
@@ -30,10 +32,11 @@ test(`${runtime} CLI cause review requires opt-in and matching diagnostic, then
30
32
  expectedFailure:{exitCode:3,outputIncludes:'BUG'},timeoutMs:1000}}));
31
33
  const review={model:'synthetic-model',disabledSkills:[],preflight:{passed:true,cli_model:'synthetic-model',prompt_transport:'stdin',
32
34
  config_fingerprint:configFingerprint({cwd,model:'synthetic-model',disabledSkills:[],promptTransport:'stdin'})}};
33
- if(runtime==='claude')review.preflight={passed:true,provider:'claude',prompt_transport:'stdin',config_fingerprint:claudeReviewFingerprint({cwd,model:review.model})};
35
+ if(selectedReview==='claude')review.preflight={passed:true,provider:'claude',prompt_transport:'stdin',config_fingerprint:claudeReviewFingerprint({cwd,model:review.model})};
34
36
  fs.writeFileSync(reviewConfig,JSON.stringify({...review,preflight:{...review.preflight,passed:false}}));
35
37
  const args=['serve','--config',config,'--mode','create','--host-context','fixture-host','--allow-reproduction','--review-config',reviewConfig];
36
38
  if(runtime==='claude')args.push('--runtime','claude');
39
+ if(reviewRuntime){args.push('--review-runtime',reviewRuntime);fs.writeFileSync(path.join(cwd,'.cm-workflow.json'),JSON.stringify(workflow));}
37
40
  let calls=0;
38
41
  const reviewWorkerFactory=()=>async({prompt},{onEvent})=>{
39
42
  calls++;const data=JSON.parse(prompt.split('<cm-review-data-json>\n')[1]);
@@ -47,7 +50,7 @@ test(`${runtime} CLI cause review requires opt-in and matching diagnostic, then
47
50
  const discard=new Writable({write(c,e,cb){cb();}});
48
51
  assert.equal(await main([...args,'--allow-cause-review'],{error:discard,reviewWorkerFactory}),1);
49
52
  assert.equal(fs.existsSync(path.join(specsRoot,'.reviews')),false);assert.equal(calls,0);
50
- if(runtime==='claude'){
53
+ if(selectedReview==='claude'){
51
54
  const wrong={passed:true,cli_model:review.model,prompt_transport:'stdin',
52
55
  config_fingerprint:configFingerprint({cwd,model:review.model,disabledSkills:[],promptTransport:'stdin'})};
53
56
  fs.writeFileSync(reviewConfig,JSON.stringify({...review,preflight:wrong}));
@@ -88,13 +91,13 @@ test(`${runtime} CLI cause review requires opt-in and matching diagnostic, then
88
91
  }finally{fs.rmSync(root,{recursive:true,force:true});}
89
92
  });
90
93
 
91
- test(`${runtime} CLI stages independently authorize writes and synthetic final review, then resume without redispatch`,{timeout:FIXTURE_TIMEOUT_MS},async()=>{
94
+ test(`${runtime}/${selectedReview} CLI stages independently authorize writes and synthetic final review, then resume without redispatch`,{timeout:FIXTURE_TIMEOUT_MS},async()=>{
92
95
  const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'fix-host-author-')));
93
96
  const cwd=path.join(root,'code'),specsRoot=path.join(root,'specs');fs.mkdirSync(cwd);fs.mkdirSync(specsRoot);
94
97
  fs.writeFileSync(path.join(cwd,'value.mjs'),'export const value=1;');
95
98
  const config=path.join(root,'config.json'),reviewConfig=path.join(root,'review.json');
96
99
  fs.writeFileSync(path.join(cwd,'existing.mjs'),"import {value} from './value.mjs';if(typeof value!=='number')process.exit(1)");
97
- fs.writeFileSync(path.join(cwd,'.cm-workflow.json'),JSON.stringify({version:1,policies:{delivery:'diff'}}));
100
+ fs.writeFileSync(path.join(cwd,'.cm-workflow.json'),JSON.stringify(workflow));
98
101
  fs.writeFileSync(config,JSON.stringify({specsRoot,identity:{repositoryId:'fixture',runId:'fix-author-cli',taskId:'T-FIX-author',attempt:1},
99
102
  defect:'Synthetic',reproduction:{cwd,command:[process.execPath,'-e',"console.error('BUG');process.exit(1)"],expectedFailure:{exitCode:1,outputIncludes:'BUG'},timeoutMs:2000},
100
103
  redTest:{cwd,testFiles:['regression.mjs'],command:[process.execPath,'regression.mjs'],expectedFailure:{exitCode:1,outputIncludes:'BUG'},timeoutMs:2000},
@@ -103,9 +106,10 @@ test(`${runtime} CLI stages independently authorize writes and synthetic final r
103
106
  baseline:{cwd,testFiles:['existing.mjs'],commands:[{id:'existing',command:[process.execPath,'existing.mjs']}],timeoutMs:2000}}));
104
107
  const review={model:'synthetic-model',disabledSkills:[],preflight:{passed:true,cli_model:'synthetic-model',prompt_transport:'stdin',
105
108
  config_fingerprint:configFingerprint({cwd,model:'synthetic-model',disabledSkills:[],promptTransport:'stdin'})}};
106
- if(runtime==='claude')review.preflight={passed:true,provider:'claude',prompt_transport:'stdin',config_fingerprint:claudeReviewFingerprint({cwd,model:review.model})};
109
+ if(selectedReview==='claude')review.preflight={passed:true,provider:'claude',prompt_transport:'stdin',config_fingerprint:claudeReviewFingerprint({cwd,model:review.model})};
107
110
  const args=['serve','--config',config,'--mode','create','--host-context','fixture-host','--allow-reproduction','--review-config',reviewConfig];
108
111
  if(runtime==='claude')args.push('--runtime','claude');
112
+ if(reviewRuntime){args.push('--review-runtime',reviewRuntime);fs.writeFileSync(path.join(cwd,'.cm-workflow.json'),JSON.stringify(workflow));}
109
113
  let providerCalls=0,writes=0,repairs=0,retrospectives=0;const reviewWorkerFactory=()=>async({prompt},{onEvent})=>{
110
114
  providerCalls++;
111
115
  const data=JSON.parse(prompt.split('<cm-review-data-json>\n')[1]);assert(data.reviewPackage.handoff);
@@ -191,6 +195,9 @@ test(`${runtime} CLI stages independently authorize writes and synthetic final r
191
195
  assert.doesNotThrow(()=>checkN4(gateOptions));
192
196
  const bytes=fs.readFileSync(reviewPath),state=JSON.parse(fs.readFileSync(path.join(reviewsDir,'.execution','fix-author-cli','state.json')));
193
197
  const saved=state.records[0].payload;
198
+ assert.equal(saved.configuration.runtime??'codex',runtime);
199
+ assert.equal(saved.configuration.causeReview.provider,selectedReview);
200
+ assert.equal(saved.configuration.reviewRuntime,reviewRuntime??undefined);
194
201
  let owner=openFixExecution({specsRoot,identity:saved.identity,configuration:saved.configuration,create:false});
195
202
  try{
196
203
  const closed=owner.status();assert.equal(closed.stage,'closeout_required');assert.equal(closed.n5.gate.outcome,'approved');
@@ -229,10 +236,15 @@ test(`${runtime} CLI stages independently authorize writes and synthetic final r
229
236
  const expected=resolveRole(loadConfig({projectRoot:cwd}),row.role,runtime);
230
237
  assert.equal(row.adapter,expected.adapter);assert.equal(row.route_state,expected.route_state);
231
238
  }
239
+ if(reviewRuntime){
240
+ assert.equal(routes.find(row=>row.role==='reviewer').review_runtime,reviewRuntime);
241
+ assert.equal(routes.find(row=>row.role==='reviewer').outcome,'selected_not_dispatched');
242
+ assert(!logs.some(row=>row.event==='degrade'&&row.role==='reviewer'));
243
+ }
232
244
  const reviews=logs.filter(row=>row.event==='review');assert.equal(reviews.length,1);
233
245
  assert.equal(reviews[0].node,'FIX');assert.equal(reviews[0].result,'approved');assert.equal(reviews[0].package_digest,walked.n5.packageDigest);
234
- assert.equal(reviews[0].provider,runtime);
235
- assert(bytes.toString().includes(`reviewer: ${runtime}-cli`));
246
+ assert.equal(reviews[0].provider,selectedReview);
247
+ assert(bytes.toString().includes(`reviewer: ${selectedReview}-cli`));
236
248
  assert.equal(logs.filter(row=>row.event==='task_start').length,1);
237
249
  assert(!logs.some(row=>['task_done','run_done'].includes(row.event)));
238
250
  fs.appendFileSync(reviewPath,'conflicting bytes');assert.equal(owner.status().stage,'final_review_evidence_required');
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ import {assertJestConfigurationDiscovery} from '../runtime/js/cm-fix/jest-command-correction.mjs';
2
3
  // Opt-in fix stages; cause review dispatch needs explicit launch authority and matching diagnostics.
3
4
  import {readFixExecutionPolicy} from '../runtime/js/cm-ai/execution-policy.mjs';
4
5
  import {readFixExternalModels} from '../runtime/js/cm-ai/external-group-models.mjs';
@@ -13,9 +14,13 @@ import {id,json,need,shape,digest} from '../runtime/js/cm-ai/effect-contract.mjs
13
14
  import {readConversationReviewConfiguration} from './cm-ai-host.mjs';
14
15
  import {createFixReviewHost} from '../runtime/js/cm-fix/host-review.mjs';
15
16
 
16
- const usage='cm-fix-host.mjs serve --config PATH --mode create|resume --host-context ID --allow-reproduction [--original-host-context ID] [--execution-optimizations] [--external-models [--external-models-config PATH]] [--runtime codex|claude] [--input-limit BYTES] [--review-config PATH] [--allow-cause-review] [--allow-rediagnosis] [--allow-final-review] [--allow-test-author] [--allow-red-test] [--allow-baseline] [--allow-repair] [--allow-regression] [--allow-learning-writeback]\nCodex or Claude current-host operations: rediagnose, prepare_revision, revision_test_check, advance, cause_review_package, cause_review, author_tests, red_test, baseline, repair, regression, retrospective, learning_writeback, handoff, final_review_package, final_review, publish_review, check_n5, post_review_regression, status, cancel. Runtime defaults to codex; claude uses its own matching diagnostic receipt and cannot reuse Codex preflight or disabledSkills settings. Runtime selection is bound to recovery; switching providers requires a separate run. This selects existing adapters, not permission to call them. Each write/check needs its respective launch flag and configuration. Test authoring, repair, cause and final review dispatch require matching existing stdin diagnostics; diagnostic alone is not authorization. Passing regression stops at handoff_required. The read-only retrospective operation yields handoff_ready or learning_writeback_required. learning_writeback requires its own flag, preserves project instructions and includes AGENTS.md in the review scope; it does not authorize provider calls. handoff publishes the fixed specs-local handoff with Learning evidence and moves to final_review_required; no provider is called and no task is completed. final_review_package is read-only and returns the final content-bound review package. final_review requires its own flag and matching diagnostics; observations do not complete the task. publish_review projects the registered result into the existing review file; it does not dispatch or complete tasks. check_n5 runs the original Learning-aware gate; post_review_regression requires --allow-regression and reaches closeout_required, not completion.';
17
+ const usage='cm-fix-host.mjs serve --config PATH --mode create|resume --host-context ID --allow-reproduction [--original-host-context ID] [--execution-optimizations] [--external-models [--external-models-config PATH]] [--runtime codex|claude] [--review-runtime codex|claude] [--input-limit BYTES] [--review-config PATH] [--allow-cause-review] [--allow-rediagnosis] [--allow-final-review] [--allow-test-author] [--allow-red-test] [--allow-baseline] [--allow-repair] [--allow-regression] [--allow-learning-writeback]\nCodex or Claude current-host operations: rediagnose, prepare_revision, revision_test_check, advance, cause_review_package, cause_review, author_tests, red_test, baseline, repair, regression, retrospective, learning_writeback, handoff, final_review_package, final_review, publish_review, check_n5, post_review_regression, status, cancel. Runtime is the actual execution host and defaults to codex. Optional --review-runtime selects the independent reviewer using the declared coder/reviewer roles; omission preserves legacy same-tool routing. Review configuration and diagnostics must match the selected reviewer; Claude cannot reuse Codex preflight or disabledSkills settings. Explicit review runtime is bound to recovery; adding, removing or switching it on an existing run is refused. This selects existing adapters, not permission to call them. Each write/check needs its respective launch flag and configuration. Test authoring, repair, cause and final review dispatch require matching existing stdin diagnostics; diagnostic alone is not authorization. Passing regression stops at handoff_required. The read-only retrospective operation yields handoff_ready or learning_writeback_required. learning_writeback requires its own flag, preserves project instructions and includes AGENTS.md in the review scope; it does not authorize provider calls. handoff publishes the fixed specs-local handoff with Learning evidence and moves to final_review_required; no provider is called and no task is completed. final_review_package is read-only and returns the final content-bound review package. final_review requires its own flag and matching diagnostics; observations do not complete the task. publish_review projects the registered result into the existing review file; it does not dispatch or complete tasks. check_n5 runs the original Learning-aware gate; post_review_regression requires --allow-regression and reaches closeout_required, not completion.';
17
18
 
18
19
  export async function main(argv=process.argv.slice(2),{input=process.stdin,output=process.stdout,error=process.stderr,reviewWorkerFactory=null}={}){
20
+ if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('prepare_test_type_correction requires resume and --allow-test-type-correction with the latest complete expected target, testTypeCorrection declaration, stopped confirmation and reason. It inserts one runtime-equivalent callback parameter type into an owner-authored test; see test-type-correction.md. It preserves the original red/baseline and leaves regression_blocked for the separately authorized rerun_blocked_step and regression.\n');
21
+ if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('Bounded isolated verification recovery: inspect with cm-fix-verification-recovery.mjs (no writer/provider); prepare_verification_recovery requires --allow-verification-recovery, expected target, stopped confirmation and reason. It runs frozen checks in isolation and prepares at most one continuation per run. Later cause_review/final_review requires --verification-recovery-authorization DIGEST plus its original review permission. Optional type-import-split sourceCorrection additionally requires --allow-source-correction in resume mode; preview uses --source-correction JSON_PATH on the read-only inspector. The same one-run recovery budget and original dispatch permissions apply. See skills/cm-fix/references/verification-recovery.md.\n');
22
+ if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('One module-only diagnosis correction: inspectFixDiagnosisModuleCorrection({specsRoot,identity}) is read-only. prepare_diagnosis_module_correction requires resume, --allow-diagnosis-module-correction, the complete expected target, previousInvocationStopped:true and reason. It only aligns the just-diagnosed module set to the exact frozen walkthrough union; original diagnosis/config/history and action budgets remain. Preparation dispatches no provider/check; any later activity refuses this operation.\n');
23
+ if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('Bounded Jest command correction: inspect read-only with cm-fix-command-correction.mjs --config PATH --jest-config PROJECT_PACKAGE_JSON. prepare_command_correction requires --mode resume --allow-command-correction, the latest complete expected, commandCorrection:{kind:"jest-config-path",path}, previousInvocationStopped:true and reason. It appends only --config to eligible original Jest argv and one history record per run; original configuration, fingerprint and failure records remain unchanged. Preparation executes no check or provider. Red test, baseline, regression, post-review regression and command walkthrough then use the recorded overlay under their original permissions and review gates. Drift stops continuation. New runs precheck Jest configuration discovery. See skills/cm-fix/references/command-correction.md.\n');
19
24
  if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('Optional --execution-optimizations freezes policy v1 for new runs only; recovery retains the original policy and legacy runs reject retrofit. See docs/execution-optimizations.md.\n');
20
25
  if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('Design-change escalation: approved cause_review reaches design_change_required when redTest is configured (test_author_required first if needed); author_tests/red_test keep their original flags and evidence checks. Confirmed red reaches escalation_required, never baseline/repair/regression. Non-visual runs without redTest reach escalation_required directly after approval and record why no failing test exists. Visual runs require a matching visual redTest with testFiles:[] and must complete the visual red step before escalation; opening without it fails with fix_visual_configuration_required. publish_dossier saves an 升级立项 dossier; finish requires --allow-finish, records run_done phase escalation/result escalated and closes the owner with escalationRunEnded:true. Retained tests become acceptance checks for the suggested $cm-prd --change. Resume the same run after a crash; conflicting exits fail with fix_escalation_exit_conflict. Terminal escalated is not completed: no task_done, metrics, repair or parent QA completion.\n');
21
26
  if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('Omit specsRoot or use null for a bare project: the same owner stores archives in docs/fixes and reviews in docs/fixes/.reviews, uses the original no-specs log mode, and skips METRICS. No specs skeleton is created. Visual-only reproduction/redTest may use kind:visual with cwd, timeoutMs, before:{path,sha256,kind:screenshot|video,description}, reason explaining why automated red cannot be written, environment, steps and expected; redTest also has testFiles:[]. No testAuthor or fake red/green command. Repair/regression/review/finish permissions remain mandatory. qa_browser returns actual after carrier metadata; missing evidence blocks.\n');
@@ -37,7 +42,7 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
37
42
  need(['create','resume'].includes(argv[4]),'invalid_arguments');id(argv[6]);
38
43
  const extra=new Map();
39
44
  for(let index=8;index<argv.length;index++){
40
- const flag=argv[index];need(!extra.has(flag)&&['--execution-optimizations','--external-models','--external-models-config','--runtime','--input-limit','--review-config','--original-host-context','--final-review-recovery-invocation','--allow-qa-fix','--allow-rediagnosis','--allow-cause-review','--allow-final-review','--allow-final-review-recovery','--allow-abandon','--allow-abandon-review','--allow-rerun-blocked-step','--allow-red-test','--allow-baseline','--allow-test-author','--allow-repair','--allow-regression','--allow-learning-writeback','--allow-walkthrough','--allow-finish'].includes(flag),'invalid_arguments');
45
+ const flag=argv[index];need(!extra.has(flag)&&['--execution-optimizations','--external-models','--external-models-config','--runtime','--review-runtime','--input-limit','--review-config','--original-host-context','--final-review-recovery-invocation','--verification-recovery-authorization','--allow-verification-recovery','--allow-source-correction','--allow-command-correction','--allow-diagnosis-module-correction','--allow-test-type-correction','--allow-qa-fix','--allow-rediagnosis','--allow-cause-review','--allow-final-review','--allow-final-review-recovery','--allow-abandon','--allow-abandon-review','--allow-rerun-blocked-step','--allow-red-test','--allow-baseline','--allow-test-author','--allow-repair','--allow-regression','--allow-learning-writeback','--allow-walkthrough','--allow-finish'].includes(flag),'invalid_arguments');
41
46
  if(flag.startsWith('--allow-')||flag==='--external-models'||flag==='--execution-optimizations')extra.set(flag,true);
42
47
  else{need(typeof argv[index+1]==='string'&&!argv[index+1].startsWith('--'),'invalid_arguments');extra.set(flag,argv[++index]);}
43
48
  }
@@ -46,9 +51,18 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
46
51
  // while --host-context stays the real current session for every live decision.
47
52
  const originalHostContext=extra.get('--original-host-context')??null;
48
53
  if(originalHostContext!==null){id(originalHostContext);need(argv[4]==='resume','fix_original_host_context_unavailable');}
54
+ const verificationRecoveryAuthorization=extra.get('--verification-recovery-authorization')??null;
55
+ if(verificationRecoveryAuthorization!==null)need(argv[4]==='resume'&&/^[a-f0-9]{64}$/.test(verificationRecoveryAuthorization),'fix_verification_recovery_authorization_required');
56
+ if(extra.has('--allow-test-type-correction'))need(argv[4]==='resume','fix_test_type_correction_unavailable');
57
+ if(extra.has('--allow-command-correction'))need(argv[4]==='resume','fix_command_correction_unavailable');
58
+ if(extra.has('--allow-diagnosis-module-correction'))need(argv[4]==='resume','fix_diagnosis_module_correction_unavailable');
59
+ if(extra.has('--allow-verification-recovery'))need(argv[4]==='resume','fix_verification_recovery_unavailable');
60
+ if(extra.has('--allow-source-correction'))need(argv[4]==='resume'&&extra.has('--allow-verification-recovery'),'fix_source_correction_authorization_required');
49
61
  const recoveryInvocationId=extra.get('--final-review-recovery-invocation')??null;
50
62
  if(recoveryInvocationId!==null){id(recoveryInvocationId);need(extra.has('--allow-final-review-recovery'),'fix_review_recovery_authorization_required');}
51
63
  const runtime=extra.get('--runtime')??'codex';need(['codex','claude'].includes(runtime),'invalid_runtime');
64
+ const reviewRuntime=extra.get('--review-runtime'),selectedReviewRuntime=reviewRuntime??runtime;
65
+ need(['codex','claude'].includes(selectedReviewRuntime),'invalid_runtime');
52
66
  // Transport only, like the cm-ai hosts: lines and tool replies share one limit.
53
67
  const inputLimit=parseHostInputLimit(extra.get('--input-limit'));
54
68
  let review;
@@ -56,14 +70,16 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
56
70
  need(stat.isFile()&&!stat.isSymbolicLink()&&stat.size<=64*1024,'invalid_fix_config');
57
71
  const config=json(JSON.parse(fs.readFileSync(argv[2],'utf8')),64*1024);
58
72
  shape(config,['identity','defect','reproduction',...(Object.hasOwn(config,'specsRoot')?['specsRoot']:[]),...(Object.hasOwn(config,'applicableAgentFiles')?['applicableAgentFiles']:[]),
73
+ ...(Object.hasOwn(config,'reviewVerification')?['reviewVerification']:[]),
59
74
  ...(Object.hasOwn(config,'protectSpecs')?['protectSpecs']:[]),
60
75
  ...(Object.hasOwn(config,'qaSource')?['qaSource']:[]),
61
76
  ...(Object.hasOwn(config,'redTest')?['redTest']:[]),...(Object.hasOwn(config,'baseline')?['baseline']:[]),
62
77
  ...(Object.hasOwn(config,'testAuthor')?['testAuthor']:[]),...(Object.hasOwn(config,'repair')?['repair']:[]),...(Object.hasOwn(config,'walkthrough')?['walkthrough']:[])]);
78
+ if(argv[4]==='create')assertJestConfigurationDiscovery(config);
63
79
  const executionPolicy=readFixExecutionPolicy({config,mode:argv[4],enabled:extra.has('--execution-optimizations')});
64
- const externalModels=readFixExternalModels({config,mode:argv[4],enabled:extra.has('--external-models'),inputFile:extra.get('--external-models-config'),runtime});
65
- review=extra.has('--review-config')?readConversationReviewConfiguration(extra.get('--review-config'),externalModels?.providers[runtime]??null):null;
66
- need(runtime!=='claude'||!review||review.disabledSkills.length===0,'invalid_review_config');
80
+ const externalModels=readFixExternalModels({config,mode:argv[4],enabled:extra.has('--external-models'),inputFile:extra.get('--external-models-config'),runtime:selectedReviewRuntime});
81
+ review=extra.has('--review-config')?readConversationReviewConfiguration(extra.get('--review-config'),externalModels?.providers[selectedReviewRuntime]??null):null;
82
+ need(selectedReviewRuntime!=='claude'||!review||review.disabledSkills.length===0,'invalid_review_config');
67
83
  need(!extra.has('--allow-cause-review')||review!==null,'review_configuration_required');
68
84
  need(!extra.has('--allow-final-review')||review!==null,'review_configuration_required');
69
85
  need(!extra.has('--allow-walkthrough')||config.walkthrough,'walkthrough_configuration_required');
@@ -75,7 +91,7 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
75
91
  need(!extra.has('--allow-repair')||(config.repair&&review),'repair_configuration_required');
76
92
  need(!extra.has('--allow-regression')||(config.repair&&config.redTest&&config.baseline),'regression_configuration_required');
77
93
  const {reviewer,authority,finalAuthority,execution:reviewExecution}=createFixReviewHost({
78
- codeProject:config.reproduction.cwd,hostContextId:argv[6],runtime,review,
94
+ codeProject:config.reproduction.cwd,hostContextId:argv[6],runtime,reviewRuntime,review,verification:config.reviewVerification??null,
79
95
  permissions:[...extra.keys()],workerFactory:reviewWorkerFactory,externalModels,executionPolicy,specsDir:config.specsRoot??null});
80
96
  bridge=createHostToolBridge({responseLimit:inputLimit,answerTimeoutMs:HOST_ANSWER_BACKSTOP_MS});
81
97
  owner=openFixExecution({specsRoot:config.specsRoot??null,identity:config.identity,create:argv[4]==='create',
@@ -84,6 +100,8 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
84
100
  ...(Object.hasOwn(config,'protectSpecs')?{protectSpecs:config.protectSpecs}:{}),
85
101
  ...(Object.hasOwn(config,'qaSource')?{qaSource:config.qaSource}:{}),
86
102
  ...(runtime==='claude'?{runtime}:{}),
103
+ ...(reviewRuntime!==undefined?{reviewRuntime}:{}),
104
+ ...(Object.hasOwn(config,'reviewVerification')?{reviewVerification:config.reviewVerification}:{}),
87
105
  ...(reviewer?{causeReview:reviewer}:{}),
88
106
  ...(Object.hasOwn(config,'redTest')?{redTest:config.redTest}:{}),
89
107
  ...(Object.hasOwn(config,'baseline')?{baseline:config.baseline}:{}),
@@ -94,7 +112,7 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
94
112
  ...reviewExecution,
95
113
  prepare:createFixLearningPreparation({bridge,codeProject:config.reproduction.cwd,
96
114
  applicableAgentFiles:config.applicableAgentFiles??[]})});
97
- const host=createFixHost({owner,config,runtime,permissions:[...extra.keys(),'--allow-reproduction'],authority,finalAuthority,recoveryInvocationId});
115
+ const host=createFixHost({owner,config,runtime,reviewRuntime,permissions:[...extra.keys(),'--allow-reproduction'],authority,finalAuthority,recoveryInvocationId,verificationRecoveryAuthorization});
98
116
  const rawMode=input.isTTY&&typeof input.setRawMode==='function';
99
117
  if(rawMode)input.setRawMode(true);
100
118
  try{await serveCmAiHost({host,input,output,toolBridge:bridge,inputLimit});}
@@ -102,7 +120,7 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
102
120
  return 0;
103
121
  }catch(cause){
104
122
  const code=typeof cause?.code==='string'&&/^[a-z][a-z0-9_]{0,63}$/.test(cause.code)?cause.code:'fix_host_failed';
105
- error.write(JSON.stringify({error:{code,...(code==='request_too_large'?{reason:inputLimitReason(cause.limit)}:{})}})+'\n');return 1;
123
+ error.write(JSON.stringify({error:{code,...(code==='request_too_large'?{reason:inputLimitReason(cause.limit)}:code==='fix_review_runtime_mismatch'?{reason:'执行宿主与审查工具须匹配项目 coder/reviewer 角色;恢复时保留原审查配置。'}:code==='invalid_workflow_config'?{reason:'请检查项目 .cm-workflow 配置及继承的用户默认配置,确认 coder/reviewer 与 runtimes 声明一致。'}:code==='tool_preflight_missing'?{reason:'请为选定审查工具在相同项目、模型与配置下重新运行 preflight;另一工具的诊断不能复用。'}:{})}})+'\n');return 1;
106
124
  }finally{bridge?.close();owner?.close();}
107
125
  }
108
126
  if(process.argv[1]&&fs.realpathSync(process.argv[1])===fileURLToPath(import.meta.url))process.exitCode=await main();