@aibyzero/cm-workflow 0.17.1 → 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 (352) hide show
  1. package/.codex-plugin/plugin.json +1 -1
  2. package/AGENTS.md +23 -0
  3. package/CHANGELOG.md +224 -0
  4. package/README.md +14 -3
  5. package/THIRD_PARTY_NOTICES.md +13 -0
  6. package/VERSION +1 -1
  7. package/compat/claude-commands/cm-challenge.md +3 -0
  8. package/docs/architecture.md +11 -0
  9. package/docs/cm-control-policy-v2.md +127 -9
  10. package/docs/installation.md +310 -4
  11. package/docs/js-workflow-control.md +150 -15
  12. package/docs/live-evidence-drivers.md +28 -4
  13. package/docs/out-of-scope/README.md +25 -0
  14. package/docs/out-of-scope/background-supervisor.md +32 -0
  15. package/docs/reviewed-integration.md +48 -0
  16. package/docs/user-guide.md +50 -21
  17. package/install-codex.sh +331 -18
  18. package/install.ps1 +28 -2
  19. package/install.sh +321 -17
  20. package/package.json +2 -1
  21. package/runtime/js/cm-ai/batch-location.mjs +55 -0
  22. package/runtime/js/cm-ai/batch-plan.mjs +242 -0
  23. package/runtime/js/cm-ai/checkpoint-package-material.mjs +162 -0
  24. package/runtime/js/cm-ai/claude-developer-proposal.schema.json +55 -1
  25. package/runtime/js/cm-ai/claude-review-stream.mjs +83 -14
  26. package/runtime/js/cm-ai/claude-tool-preview.mjs +11 -9
  27. package/runtime/js/cm-ai/cm-ai-admission.mjs +18 -12
  28. package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +91 -6
  29. package/runtime/js/cm-ai/cm-ai-qa-log.mjs +5 -1
  30. package/runtime/js/cm-ai/codex-config.mjs +6 -2
  31. package/runtime/js/cm-ai/codex-developer-basic-output.schema.json +3 -2
  32. package/runtime/js/cm-ai/codex-developer-output.schema.json +2 -1
  33. package/runtime/js/cm-ai/codex-reconnect-notice.mjs +6 -0
  34. package/runtime/js/cm-ai/codex-review-adapter.mjs +27 -7
  35. package/runtime/js/cm-ai/control-policy.mjs +21 -4
  36. package/runtime/js/cm-ai/developer-adapter.mjs +19 -5
  37. package/runtime/js/cm-ai/drive-core.mjs +114 -11
  38. package/runtime/js/cm-ai/drive-rate-limit.mjs +105 -0
  39. package/runtime/js/cm-ai/durable-runner-state.mjs +234 -33
  40. package/runtime/js/cm-ai/effect-contract.mjs +11 -2
  41. package/runtime/js/cm-ai/execution-policy.mjs +3 -1
  42. package/runtime/js/cm-ai/execution-snapshot.mjs +4 -2
  43. package/runtime/js/cm-ai/execution-store-limits.mjs +14 -7
  44. package/runtime/js/cm-ai/execution-store.mjs +60 -17
  45. package/runtime/js/cm-ai/fix-code-association.mjs +73 -2
  46. package/runtime/js/cm-ai/host-check.mjs +11 -5
  47. package/runtime/js/cm-ai/host-conversation-execution.mjs +70 -28
  48. package/runtime/js/cm-ai/host-qa-executor.mjs +38 -5
  49. package/runtime/js/cm-ai/host-qa-fix-owner.mjs +2 -2
  50. package/runtime/js/cm-ai/host-qa-policy.mjs +19 -2
  51. package/runtime/js/cm-ai/host-replay.mjs +148 -0
  52. package/runtime/js/cm-ai/host-session.mjs +1 -1
  53. package/runtime/js/cm-ai/host-workflow-capabilities.mjs +19 -2
  54. package/runtime/js/cm-ai/host.mjs +1 -1
  55. package/runtime/js/cm-ai/implicit-qa-decision.mjs +5 -0
  56. package/runtime/js/cm-ai/integration-snapshots.mjs +50 -0
  57. package/runtime/js/cm-ai/live-evidence.mjs +28 -6
  58. package/runtime/js/cm-ai/operator-guidance.mjs +9 -2
  59. package/runtime/js/cm-ai/owned-process-cleanup.mjs +27 -9
  60. package/runtime/js/cm-ai/process-group-exit.mjs +46 -0
  61. package/runtime/js/cm-ai/provider-review-observation.mjs +3 -2
  62. package/runtime/js/cm-ai/qa-attachment.mjs +22 -0
  63. package/runtime/js/cm-ai/qa-config-revision.mjs +7 -2
  64. package/runtime/js/cm-ai/requirement-evidence.mjs +102 -0
  65. package/runtime/js/cm-ai/review-package.mjs +79 -7
  66. package/runtime/js/cm-ai/review-presentation-delta.mjs +166 -0
  67. package/runtime/js/cm-ai/review-presentation.mjs +177 -8
  68. package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +70 -2
  69. package/runtime/js/cm-ai/reviewed-integration.mjs +260 -0
  70. package/runtime/js/cm-ai/scope-revision.mjs +38 -0
  71. package/runtime/js/cm-ai/specification-material.mjs +2 -2
  72. package/runtime/js/cm-ai/task-runner.mjs +242 -39
  73. package/runtime/js/cm-ai/verification-auto.mjs +38 -0
  74. package/runtime/js/cm-ai/worker-claude-developer.mjs +39 -15
  75. package/runtime/js/cm-ai/worker-claude.mjs +35 -13
  76. package/runtime/js/cm-ai/worker-codex-developer.mjs +43 -17
  77. package/runtime/js/cm-ai/worker-codex.mjs +41 -7
  78. package/runtime/js/cm-fix/cause-invocation.mjs +16 -2
  79. package/runtime/js/cm-fix/cause-package.mjs +46 -1
  80. package/runtime/js/cm-fix/command-correction.mjs +37 -0
  81. package/runtime/js/cm-fix/cooperative.mjs +12 -0
  82. package/runtime/js/cm-fix/dossier.mjs +8 -2
  83. package/runtime/js/cm-fix/execution.mjs +578 -100
  84. package/runtime/js/cm-fix/final-review.mjs +39 -8
  85. package/runtime/js/cm-fix/finish.mjs +15 -11
  86. package/runtime/js/cm-fix/host-review.mjs +65 -10
  87. package/runtime/js/cm-fix/host.mjs +35 -12
  88. package/runtime/js/cm-fix/jest-command-correction.mjs +69 -0
  89. package/runtime/js/cm-fix/metrics.mjs +18 -5
  90. package/runtime/js/cm-fix/regression-evidence.mjs +3 -2
  91. package/runtime/js/cm-fix/regression.mjs +16 -7
  92. package/runtime/js/cm-fix/repair.mjs +29 -8
  93. package/runtime/js/cm-fix/review-verification-command.mjs +135 -0
  94. package/runtime/js/cm-fix/review-verification-contract.mjs +54 -0
  95. package/runtime/js/cm-fix/review-verification-diagnostic.mjs +75 -0
  96. package/runtime/js/cm-fix/review-verification-recovery.mjs +44 -0
  97. package/runtime/js/cm-fix/review-verification-server.mjs +38 -0
  98. package/runtime/js/cm-fix/review-verification.mjs +214 -0
  99. package/runtime/js/cm-fix/source-correction-recovery.mjs +65 -0
  100. package/runtime/js/cm-fix/start.mjs +6 -3
  101. package/runtime/js/cm-fix/test-type-correction.mjs +86 -0
  102. package/runtime/js/cm-fix/test-type-recovery.mjs +51 -0
  103. package/runtime/js/cm-fix/type-import-correction.mjs +89 -0
  104. package/runtime/js/cm-prd/accepted-design.mjs +8 -0
  105. package/runtime/js/cm-prd/analysis.mjs +13 -9
  106. package/runtime/js/cm-prd/change.mjs +37 -16
  107. package/runtime/js/cm-prd/draft-save.mjs +13 -6
  108. package/runtime/js/cm-prd/draft.mjs +31 -3
  109. package/runtime/js/cm-prd/failed-correction.mjs +19 -3
  110. package/runtime/js/cm-prd/inputs-replaced.mjs +3 -0
  111. package/runtime/js/cm-prd/review-correction.mjs +6 -4
  112. package/runtime/js/cm-prd/review-disposition.mjs +7 -1
  113. package/runtime/js/cm-prd/self-check-revision.mjs +2 -2
  114. package/runtime/js/cm-prd/self-check.mjs +125 -6
  115. package/runtime/js/cm-prd/session.mjs +30 -1
  116. package/runtime/js/cm-prd/summary.mjs +11 -5
  117. package/runtime/js/cm-prd/task-scope-record.mjs +97 -0
  118. package/runtime/js/cm-prd/tree-digest.mjs +34 -0
  119. package/runtime/js/cm-prd/validation-reason.mjs +8 -4
  120. package/runtime/js/cm-security/scan.mjs +1 -1
  121. package/runtime/js/commander/decision.mjs +44 -0
  122. package/runtime/js/commander/dispatch-registry.mjs +110 -0
  123. package/runtime/js/commander/ledger.mjs +265 -0
  124. package/runtime/js/commander/preflight.mjs +107 -0
  125. package/runtime/js/notify-later.mjs +13 -0
  126. package/runtime/js/notify-send.mjs +6 -2
  127. package/runtime/js/notify.mjs +570 -63
  128. package/runtime/js/review-findings.mjs +38 -0
  129. package/runtime/js/session-boundary.mjs +56 -0
  130. package/runtime/js/session-handoff.mjs +68 -0
  131. package/runtime/js/spec-task-line.mjs +27 -13
  132. package/runtime/js/specs-status.mjs +1 -1
  133. package/runtime/js/task-scope.mjs +197 -0
  134. package/runtime/logging.md +6 -1
  135. package/runtime/model-efficiency.md +69 -10
  136. package/runtime/orchestration.md +3 -1
  137. package/runtime/project-learning.md +2 -0
  138. package/runtime/review.md +3 -2
  139. package/runtime/test-contract.md +1 -0
  140. package/scripts/ci-test-weights.json +3 -0
  141. package/scripts/cm-ai-admission.mjs +11 -5
  142. package/scripts/cm-ai-admission.test.mjs +23 -2
  143. package/scripts/cm-ai-batch-drive.mjs +79 -18
  144. package/scripts/cm-ai-batch-drive.test.mjs +169 -3
  145. package/scripts/cm-ai-batch-host.mjs +38 -9
  146. package/scripts/cm-ai-batch-host.test.mjs +6 -5
  147. package/scripts/cm-ai-batch-learning-merge.test.mjs +36 -0
  148. package/scripts/cm-ai-batch-location.test.mjs +57 -0
  149. package/scripts/cm-ai-batch-plan.mjs +52 -0
  150. package/scripts/cm-ai-batch-plan.test.mjs +397 -0
  151. package/scripts/cm-ai-batch-run-fixture.mjs +446 -35
  152. package/scripts/cm-ai-batch-run-member-stops.test.mjs +16 -0
  153. package/scripts/cm-ai-batch-run-parallel.test.mjs +28 -1
  154. package/scripts/cm-ai-batch-run.mjs +471 -57
  155. package/scripts/cm-ai-batch-run.test.mjs +23 -4
  156. package/scripts/cm-ai-batch-session-e2e.test.mjs +235 -0
  157. package/scripts/cm-ai-batch-session-member.test.mjs +293 -0
  158. package/scripts/cm-ai-batch-session-recovery.test.mjs +423 -0
  159. package/scripts/cm-ai-check-recheck-cancellation.test.mjs +247 -0
  160. package/scripts/cm-ai-checklist-coverage.test.mjs +4 -2
  161. package/scripts/cm-ai-checkpoint-package-material.test.mjs +221 -0
  162. package/scripts/cm-ai-checkpoint-package-owner.test.mjs +193 -0
  163. package/scripts/cm-ai-control-launch.test.mjs +21 -0
  164. package/scripts/cm-ai-control-policy.test.mjs +14 -0
  165. package/scripts/cm-ai-control-v2-drive.test.mjs +398 -3
  166. package/scripts/cm-ai-control-v2-supersede-race.mjs +25 -0
  167. package/scripts/cm-ai-control-v2-supersede.test.mjs +318 -0
  168. package/scripts/cm-ai-develop-driver-gaps.test.mjs +163 -0
  169. package/scripts/cm-ai-development-rework.test.mjs +423 -0
  170. package/scripts/cm-ai-drive.mjs +73 -17
  171. package/scripts/cm-ai-drive.test.mjs +34 -2
  172. package/scripts/cm-ai-execution-store-legacy-probe.test.mjs +84 -0
  173. package/scripts/cm-ai-host.mjs +60 -19
  174. package/scripts/cm-ai-integration-adoption.test.mjs +223 -0
  175. package/scripts/cm-ai-integration-independence.test.mjs +23 -0
  176. package/scripts/cm-ai-integration-launch.test.mjs +240 -0
  177. package/scripts/cm-ai-integration-preview.mjs +41 -0
  178. package/scripts/cm-ai-integration-snapshots.test.mjs +197 -0
  179. package/scripts/cm-ai-nested-execution.test.mjs +29 -1
  180. package/scripts/cm-ai-operator-guidance.test.mjs +16 -1
  181. package/scripts/cm-ai-prefinal-delivery.test.mjs +278 -0
  182. package/scripts/cm-ai-project-qa-gate.test.mjs +56 -0
  183. package/scripts/cm-ai-qa-fingerprint-config.test.mjs +28 -0
  184. package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +36 -2
  185. package/scripts/cm-ai-requirement-evidence.test.mjs +65 -0
  186. package/scripts/cm-ai-review-failure.test.mjs +150 -5
  187. package/scripts/cm-ai-run.mjs +88 -21
  188. package/scripts/cm-ai-scope-revision.test.mjs +341 -0
  189. package/scripts/cm-ai-spec-rebind.test.mjs +13 -0
  190. package/scripts/cm-ai-supersede.test.mjs +28 -0
  191. package/scripts/cm-ai-verification-auto.test.mjs +99 -0
  192. package/scripts/cm-announce-hook.mjs +35 -8
  193. package/scripts/cm-announce-hook.test.mjs +25 -0
  194. package/scripts/cm-challenge.test.mjs +61 -0
  195. package/scripts/cm-check-drive-files.mjs +1 -1
  196. package/scripts/cm-check-runtime.sh +58 -1
  197. package/scripts/cm-claude-developer-worker.test.mjs +56 -7
  198. package/scripts/cm-claude-install-layout.test.mjs +1 -1
  199. package/scripts/cm-claude-review-diagnostics.test.mjs +235 -0
  200. package/scripts/cm-claude-review-stream.test.mjs +13 -0
  201. package/scripts/cm-codex-developer-reconnect-notice.test.mjs +98 -0
  202. package/scripts/cm-codex-developer-worker.test.mjs +120 -0
  203. package/scripts/cm-codex-install-local-edit-guard.test.mjs +436 -0
  204. package/scripts/cm-codex-prompt-input.test.mjs +153 -0
  205. package/scripts/cm-codex-reconnect-notice.test.mjs +167 -0
  206. package/scripts/cm-commander-ledger.test.mjs +260 -0
  207. package/scripts/cm-commander-p2.test.mjs +295 -0
  208. package/scripts/cm-commander-preflight.mjs +84 -0
  209. package/scripts/cm-commander.mjs +116 -0
  210. package/scripts/cm-config-lock.mjs +35 -0
  211. package/scripts/cm-controlled-correction.test.mjs +10 -1
  212. package/scripts/cm-developer-failure-code.test.mjs +62 -0
  213. package/scripts/cm-display-task-id.test.mjs +41 -0
  214. package/scripts/cm-efficiency-presentation-delta.test.mjs +218 -0
  215. package/scripts/cm-execution-snapshot-reuse.test.mjs +115 -0
  216. package/scripts/cm-external-batch-host.test.mjs +4 -3
  217. package/scripts/cm-external-process-cleanup.test.mjs +128 -0
  218. package/scripts/cm-external-qa-fix.test.mjs +89 -7
  219. package/scripts/cm-external-review-reconciliation.test.mjs +11 -0
  220. package/scripts/cm-failover.mjs +48 -10
  221. package/scripts/cm-failover.test.mjs +46 -0
  222. package/scripts/cm-fix-cause-invocation.test.mjs +19 -4
  223. package/scripts/cm-fix-command-correction.mjs +17 -0
  224. package/scripts/cm-fix-command-correction.test.mjs +211 -0
  225. package/scripts/cm-fix-cooperative-closeout.test.mjs +87 -0
  226. package/scripts/cm-fix-diagnosis-module-correction.test.mjs +217 -0
  227. package/scripts/cm-fix-drive.mjs +33 -5
  228. package/scripts/cm-fix-drive.test.mjs +49 -0
  229. package/scripts/cm-fix-host-review-assembly.test.mjs +197 -1
  230. package/scripts/cm-fix-host-review.test.mjs +21 -9
  231. package/scripts/cm-fix-host.mjs +26 -8
  232. package/scripts/cm-fix-monorepo-map.test.mjs +92 -0
  233. package/scripts/cm-fix-observation-task-id.test.mjs +122 -0
  234. package/scripts/cm-fix-regression-input-budget.test.mjs +111 -0
  235. package/scripts/cm-fix-repair-input-budget.test.mjs +119 -0
  236. package/scripts/cm-fix-review-file-paging.test.mjs +91 -0
  237. package/scripts/cm-fix-review-preflight.mjs +24 -0
  238. package/scripts/cm-fix-review-storage.test.mjs +233 -0
  239. package/scripts/cm-fix-review-verification-command.test.mjs +242 -0
  240. package/scripts/cm-fix-review-verification-evidence.test.mjs +218 -0
  241. package/scripts/cm-fix-review-verification-integration.test.mjs +81 -0
  242. package/scripts/cm-fix-review-verification-recovery.test.mjs +198 -0
  243. package/scripts/cm-fix-review-verification.test.mjs +146 -0
  244. package/scripts/cm-fix-revision-transport.test.mjs +81 -0
  245. package/scripts/cm-fix-source-correction.test.mjs +296 -0
  246. package/scripts/cm-fix-test-type-correction.mjs +18 -0
  247. package/scripts/cm-fix-test-type-correction.test.mjs +123 -0
  248. package/scripts/cm-fix-test-type-owner.test.mjs +208 -0
  249. package/scripts/cm-fix-test-type-verification-cost.test.mjs +66 -0
  250. package/scripts/cm-fix-type-import-correction.test.mjs +95 -0
  251. package/scripts/cm-fix-verification-diagnostic.test.mjs +200 -0
  252. package/scripts/cm-fix-verification-recovery.mjs +33 -0
  253. package/scripts/cm-host-qa-executor.test.mjs +77 -0
  254. package/scripts/cm-host-replay.test.mjs +176 -0
  255. package/scripts/cm-install-local-edit-guard.test.mjs +621 -0
  256. package/scripts/cm-install-manifest.sh +351 -0
  257. package/scripts/cm-live-evidence.test.mjs +59 -1
  258. package/scripts/cm-log-event.mjs +61 -10
  259. package/scripts/cm-log-event.test.mjs +121 -1
  260. package/scripts/cm-matt-skills.mjs +576 -0
  261. package/scripts/cm-matt-skills.test.mjs +550 -0
  262. package/scripts/cm-notify-command.test.mjs +42 -10
  263. package/scripts/cm-notify.mjs +14 -10
  264. package/scripts/cm-notify.test.mjs +575 -59
  265. package/scripts/cm-patrol.mjs +4 -1
  266. package/scripts/cm-patrol.test.mjs +23 -5
  267. package/scripts/cm-prd-answer-gaps.test.mjs +2 -2
  268. package/scripts/cm-prd-completion.test.mjs +56 -13
  269. package/scripts/cm-prd-design-phase.test.mjs +78 -8
  270. package/scripts/cm-prd-draft-save.test.mjs +12 -0
  271. package/scripts/cm-prd-draft.test.mjs +1 -1
  272. package/scripts/cm-prd-drive.mjs +13 -6
  273. package/scripts/cm-prd-drive.test.mjs +45 -1
  274. package/scripts/cm-prd-gate-diagnostic.test.mjs +2 -2
  275. package/scripts/cm-prd-host.mjs +10 -5
  276. package/scripts/cm-prd-host.test.mjs +4 -2
  277. package/scripts/cm-prd-inputs-replaced.test.mjs +1 -1
  278. package/scripts/cm-prd-review-disposition.test.mjs +124 -8
  279. package/scripts/cm-prd-revision.test.mjs +1 -1
  280. package/scripts/cm-prd-self-check-revision.test.mjs +1 -1
  281. package/scripts/cm-prd-self-check-rules.test.mjs +239 -0
  282. package/scripts/cm-prd-self-check.test.mjs +105 -5
  283. package/scripts/cm-prd-summary.test.mjs +24 -3
  284. package/scripts/cm-prd-task-grouping.test.mjs +6 -6
  285. package/scripts/cm-prd-tree-digest.test.mjs +74 -0
  286. package/scripts/cm-refactor-drive.mjs +2 -1
  287. package/scripts/cm-refactor-drive.test.mjs +9 -0
  288. package/scripts/cm-release-smoke.sh +1 -1
  289. package/scripts/cm-skill-hints-autowire.test.mjs +394 -0
  290. package/scripts/cm-skill-hints-exam.mjs +149 -0
  291. package/scripts/cm-skill-hints-install.test.mjs +168 -0
  292. package/scripts/cm-skill-hints.exam.json +706 -0
  293. package/scripts/cm-skill-hints.json +119 -0
  294. package/scripts/cm-skill-hints.mjs +669 -0
  295. package/scripts/cm-skill-hints.test.mjs +831 -0
  296. package/scripts/cm-skill-judge.mjs +181 -0
  297. package/scripts/cm-skill-judge.test.mjs +255 -0
  298. package/scripts/cm-specs-status.test.mjs +4 -2
  299. package/scripts/cm-start-check.mjs +208 -0
  300. package/scripts/cm-start-check.test.mjs +321 -0
  301. package/scripts/cm-task-gate.mjs +150 -29
  302. package/scripts/cm-task-gate.test.mjs +73 -1
  303. package/scripts/cm-task-id-grammar.test.mjs +66 -0
  304. package/scripts/cm-task-scope.test.mjs +308 -0
  305. package/scripts/cm-upgrade-compat-batch.test.mjs +172 -0
  306. package/scripts/cm-upgrade-compat.test.mjs +239 -0
  307. package/scripts/cm-workflow-config.mjs +12 -2
  308. package/scripts/fixtures/fix-verification-claude.mjs +44 -0
  309. package/scripts/fixtures/reviewed-integration.mjs +202 -0
  310. package/scripts/scan-public-safety.py +1 -0
  311. package/scripts/session-boundary.test.mjs +170 -0
  312. package/scripts/test-npm-install.py +14 -3
  313. package/scripts/test-shell-compat.sh +2 -0
  314. package/scripts/validate-public-repo.py +1 -0
  315. package/scripts/validate-test-cases.mjs +3 -2
  316. package/skills/cm-ai/SKILL.md +5 -2
  317. package/skills/cm-ai/references/N4-review.md +2 -1
  318. package/skills/cm-ai/references/N6-qa-eval.md +3 -1
  319. package/skills/cm-ai/references/N8-finish.md +22 -0
  320. package/skills/cm-ai/references/js-host-qa-recovery.md +1 -1
  321. package/skills/cm-ai/references/js-host-recovery.md +79 -3
  322. package/skills/cm-ai/references/js-host.md +56 -16
  323. package/skills/cm-challenge/SKILL.md +65 -0
  324. package/skills/cm-challenge/evals/README.md +18 -0
  325. package/skills/cm-challenge/evals/trigger-cases.json +20 -0
  326. package/skills/cm-challenge/evals/trigger-config.json +28 -0
  327. package/skills/cm-challenge/references/examples.md +15 -0
  328. package/skills/cm-check/SKILL.md +5 -0
  329. package/skills/cm-check/references/js-host.md +2 -0
  330. package/skills/cm-fix/SKILL.md +12 -3
  331. package/skills/cm-fix/references/command-correction.md +67 -0
  332. package/skills/cm-fix/references/isolated-review.md +54 -0
  333. package/skills/cm-fix/references/js-host.md +62 -2
  334. package/skills/cm-fix/references/test-type-correction.md +72 -0
  335. package/skills/cm-fix/references/verification-recovery.md +114 -0
  336. package/skills/cm-idea/SKILL.md +2 -0
  337. package/skills/cm-idea/references/js-host.md +2 -0
  338. package/skills/cm-notify/SKILL.md +2 -0
  339. package/skills/cm-prd/SKILL.md +12 -8
  340. package/skills/cm-prd/references/brownfield.md +8 -1
  341. package/skills/cm-prd/references/change-mode.md +6 -0
  342. package/skills/cm-prd/references/greenfield.md +4 -0
  343. package/skills/cm-prd/references/js-host.md +4 -2
  344. package/skills/cm-prd/references/spec-self-check.md +5 -1
  345. package/skills/cm-refactor/SKILL.md +8 -0
  346. package/skills/cm-refactor/references/js-host.md +2 -0
  347. package/skills/cm-test/SKILL.md +4 -0
  348. package/templates/dashboard/dashboard.html +2 -2
  349. package/templates/pixel/cm-pixel.html +1 -1
  350. package/templates/pixel/cm-pixel.sh +1 -1
  351. package/templates/pixel/dev/template.html +1 -1
  352. package/templates/statusline/cm-statusline.sh +1 -1
@@ -0,0 +1,146 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import fs from 'node:fs';
4
+ import os from 'node:os';
5
+ import path from 'node:path';
6
+ import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
7
+ import {createReviewVerificationSession,createVerificationTools,verifyReviewVerificationBaseline} from '../runtime/js/cm-fix/review-verification.mjs';
8
+ import {readReviewVerification} from '../runtime/js/cm-fix/review-verification-contract.mjs';
9
+ function fixture(){
10
+ const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'fix-verification-')));
11
+ fs.writeFileSync(path.join(root,'value.mjs'),'export const value=1;\n');
12
+ fs.writeFileSync(path.join(root,'value.test.mjs'),"import {value} from './value.mjs'; if(value!==1)process.exit(1);\n");
13
+ const config={files:['value.mjs','value.test.mjs'],checks:[{id:'value',command:[process.execPath,'value.test.mjs']}],mutationPaths:['value.mjs'],timeoutMs:10000};
14
+ return {root,config,request:{requestDigest:'a'.repeat(64),provider:'claude',payload:{reviewPackage:{packageDigest:'b'.repeat(64),files:[]}}}};
15
+ }
16
+ test('verification profile rejects traversal, secrets, test mutations and arbitrary fields',()=>{
17
+ const f=fixture();try{assert.deepEqual(readReviewVerification(f.config),f.config);
18
+ for(const p of ['../x','.env','.git/config','a/../x'])assert.throws(()=>readReviewVerification({...f.config,files:[p]}));
19
+ assert.throws(()=>readReviewVerification({...f.config,mutationPaths:['value.test.mjs']}));
20
+ assert.throws(()=>readReviewVerification({...f.config,extra:true}));
21
+ }finally{fs.rmSync(f.root,{recursive:true,force:true});}
22
+ });
23
+ test('isolated session mechanically runs baseline, killed mutation and restoration without changing source', {skip:process.platform!=='darwin'},async()=>{
24
+ const f=fixture();let s;try{
25
+ s=createReviewVerificationSession({codeProject:f.root,configuration:f.config,request:f.request});
26
+ assert.notEqual(s.cwd,f.root);
27
+ assert.throws(()=>s.finish('fresh-review'),/review_verification/);
28
+ const check=await s.call('run_check',{id:'value'});assert.equal(check.exitCode,0);
29
+ const mutation=await s.call('mutate_check',{path:'value.mjs',find:'value=1',replace:'value=2',checkId:'value'});assert.equal(mutation.killed,true);
30
+ const e=s.finish('fresh-review');assert.equal(e.mutations.length,1);assert.equal(e.checks.length,1);
31
+ assert.equal(fs.readFileSync(path.join(f.root,'value.mjs'),'utf8'),'export const value=1;\n');
32
+ assert.equal(fs.readFileSync(path.join(s.cwd,'value.mjs'),'utf8'),'export const value=1;\n');
33
+ await assert.rejects(s.call('mutate_check',{path:'value.test.mjs',find:'1',replace:'2',checkId:'value'}));
34
+ fs.writeFileSync(path.join(f.root,'value.mjs'),'changed');assert.throws(()=>s.finish('fresh-review'),/drift/);
35
+ }finally{await s?.close();fs.rmSync(f.root,{recursive:true,force:true});}
36
+ });
37
+ test('snapshot rejects source links and package mismatch before tools start',{skip:process.platform!=='darwin'},()=>{
38
+ const f=fixture();try{
39
+ fs.symlinkSync('value.mjs',path.join(f.root,'link.mjs'));
40
+ assert.throws(()=>createReviewVerificationSession({codeProject:f.root,configuration:{...f.config,files:[...f.config.files,'link.mjs']},request:f.request}));
41
+ assert.throws(()=>createReviewVerificationSession({codeProject:f.root,configuration:f.config,request:{...f.request,payload:{reviewPackage:{...f.request.payload.reviewPackage,files:[{path:'value.mjs',sha256:'0'.repeat(64)}]}}}}),/binding/);
42
+ }finally{fs.rmSync(f.root,{recursive:true,force:true});}
43
+ });
44
+
45
+ test('package binding covers requirements, instructions and modes; absent future slots stay absent',{skip:process.platform!=='darwin'},async()=>{
46
+ const f=fixture();try{
47
+ const {createHash}=await import('node:crypto');const h=createHash('sha256').update(fs.readFileSync(path.join(f.root,'value.mjs'))).digest('hex');
48
+ for(const record of [{requirements:[{path:'value.mjs',sha256:'0'.repeat(64),mode:420}]},{instructions:[{path:'value.mjs',sha256:'0'.repeat(64),mode:420}]},{files:[{path:'value.mjs',sha256:h,mode:493}]}]){
49
+ assert.throws(()=>createReviewVerificationSession({codeProject:f.root,configuration:f.config,request:{...f.request,payload:{reviewPackage:{...f.request.payload.reviewPackage,...record}}}}),/binding/);
50
+ }
51
+ const s=createReviewVerificationSession({codeProject:f.root,configuration:{...f.config,files:[...f.config.files,'future.mjs']},request:f.request});
52
+ assert.equal(fs.existsSync(path.join(s.cwd,'future.mjs')),false);await s.close();
53
+ }finally{fs.rmSync(f.root,{recursive:true,force:true});}
54
+ });
55
+ test('a later failed mutation baseline invalidates earlier successful evidence',{skip:process.platform!=='darwin'},async()=>{
56
+ const f=fixture();let s;try{
57
+ s=createReviewVerificationSession({codeProject:f.root,configuration:f.config,request:f.request});
58
+ let laterFailure=false;
59
+ const tools=createVerificationTools({...JSON.parse(fs.readFileSync(s.configPath)),runCommand:async()=>{
60
+ const failed=laterFailure||fs.readFileSync(path.join(s.cwd,'value.mjs'),'utf8').includes('value=2');
61
+ return {outcome:failed?'failed':'passed',exitCode:failed?1:0,code:null,output:'synthetic'};
62
+ }});
63
+ await tools.call('run_check',{id:'value'});
64
+ assert.equal((await tools.call('mutate_check',{path:'value.mjs',find:'value=1',replace:'value=2',checkId:'value'})).killed,true);
65
+ s.finish('fresh-review');laterFailure=true;
66
+ await assert.rejects(tools.call('mutate_check',{path:'value.mjs',find:'value=1',replace:'value=3',checkId:'value'}),/baseline_failed/);
67
+ assert.throws(()=>s.finish('fresh-review'),/review_verification/);
68
+ }finally{await s?.close();fs.rmSync(f.root,{recursive:true,force:true});}
69
+ });
70
+ test('each command removes unregistered artifacts before reusing the snapshot',{skip:process.platform!=='darwin'},async()=>{
71
+ const f=fixture();let s;try{
72
+ fs.writeFileSync(path.join(f.root,'value.test.mjs'),`import fs from 'node:fs';import {value} from './value.mjs';if(fs.existsSync('.cache'))process.exit(3);fs.writeFileSync('.cache','residue');if(value!==1)process.exit(1);`);
73
+ s=createReviewVerificationSession({codeProject:f.root,configuration:f.config,request:f.request});
74
+ assert.equal((await s.call('run_check',{id:'value'})).exitCode,0);
75
+ assert.equal(fs.existsSync(path.join(s.cwd,'.cache')),false);
76
+ assert.equal((await s.call('run_check',{id:'value'})).exitCode,0);
77
+ assert.equal((await s.call('mutate_check',{path:'value.mjs',find:'value=1',replace:'value=2',checkId:'value'})).killed,true);
78
+ s.finish('fresh-review');
79
+ }finally{await s?.close();fs.rmSync(f.root,{recursive:true,force:true});}
80
+ });
81
+
82
+ test('host closes a registered command group after its MCP server is killed',{skip:process.platform!=='darwin'},async()=>{
83
+ const {spawn}=await import('node:child_process');
84
+ const f=fixture();let s,server,pid;
85
+ try{
86
+ fs.writeFileSync(path.join(f.root,'value.test.mjs'),"process.on('SIGTERM',()=>{});setInterval(()=>{},1000);");
87
+ s=createReviewVerificationSession({codeProject:f.root,configuration:f.config,request:f.request});
88
+ server=spawn(process.execPath,[new URL('../runtime/js/cm-fix/review-verification-server.mjs',import.meta.url).pathname,s.configPath],{stdio:['pipe','pipe','pipe'],detached:true});
89
+ server.stdout.resume();server.stderr.resume();
90
+ server.stdin.write(JSON.stringify({jsonrpc:'2.0',id:1,method:'tools/call',params:{name:'run_check',arguments:{id:'value'}}})+'\n');
91
+ const active=path.join(path.dirname(s.cwd),'active-command.json'),until=Date.now()+5000;
92
+ while(!fs.existsSync(active)&&Date.now()<until)await new Promise(r=>setTimeout(r,20));
93
+ assert(fs.existsSync(active),'command must be registered before termination');pid=JSON.parse(fs.readFileSync(active,'utf8')).pid;
94
+ const closed=new Promise(r=>server.once('close',r));process.kill(-server.pid,'SIGKILL');await closed;
95
+ await s.close();s=null;
96
+ assert.throws(()=>process.kill(pid,0),{code:'ESRCH'});
97
+ }finally{
98
+ if(server?.pid)try{process.kill(-server.pid,'SIGKILL');}catch{}
99
+ if(pid)try{process.kill(-pid,'SIGKILL');}catch{}
100
+ await s?.close();fs.rmSync(f.root,{recursive:true,force:true});
101
+ }
102
+ });
103
+
104
+ test('unknown cleanup retains the private directory and reports it without claiming success',{skip:process.platform!=='darwin'},async t=>{
105
+ const f=fixture();let s;
106
+ try{
107
+ s=createReviewVerificationSession({codeProject:f.root,configuration:f.config,request:f.request});
108
+ const active=path.join(path.dirname(s.cwd),'active-command.json');fs.writeFileSync(active,JSON.stringify({pid:2147483646}));
109
+ const messages=[];const kill=t.mock.method(process,'kill',()=>true),stderr=t.mock.method(process.stderr,'write',chunk=>{messages.push(String(chunk));return true;});
110
+ try{await assert.rejects(s.close(),{code:'process_cleanup_unknown'});assert(fs.existsSync(s.cwd));assert(messages.some(s=>s.includes('retainedDirectory')));}
111
+ finally{kill.mock.restore();stderr.mock.restore();fs.rmSync(active,{force:true});}
112
+ }finally{await s?.close();fs.rmSync(f.root,{recursive:true,force:true});}
113
+ });
114
+
115
+
116
+ test('unknown command cleanup prevents later tools and evidence from replacing the active group',{skip:process.platform!=='darwin'},async t=>{
117
+ const f=fixture();let s,active;
118
+ try{
119
+ s=createReviewVerificationSession({codeProject:f.root,configuration:f.config,request:f.request});
120
+ active=path.join(path.dirname(s.cwd),'active-command.json');let calls=0;
121
+ const tools=createVerificationTools({...JSON.parse(fs.readFileSync(s.configPath)),runCommand:async({onSpawn})=>{
122
+ calls++;onSpawn(2147483646);return {exitCode:null,outcome:'unavailable',code:'verification_cleanup_unknown',output:''};
123
+ }});
124
+ assert.equal((await tools.call('run_check',{id:'value'})).code,'verification_cleanup_unknown');
125
+ const saved=fs.readFileSync(active);
126
+ await assert.rejects(tools.call('run_check',{id:'value'}),{code:'review_verification_cleanup'});
127
+ await assert.rejects(tools.call('read_file',{path:'value.mjs'}),{code:'review_verification_cleanup'});
128
+ assert.equal(calls,1);assert.deepEqual(fs.readFileSync(active),saved);
129
+ assert.throws(()=>s.finish('fresh-review'),{code:'review_verification_cleanup'});
130
+ const kill=t.mock.method(process,'kill',()=>true),stderr=t.mock.method(process.stderr,'write',()=>true);
131
+ try{await assert.rejects(s.close(),{code:'process_cleanup_unknown'});assert(fs.existsSync(s.cwd));assert.deepEqual(fs.readFileSync(active),saved);}
132
+ finally{kill.mock.restore();stderr.mock.restore();}
133
+ }finally{if(active)fs.rmSync(active,{force:true});await s?.close();fs.rmSync(f.root,{recursive:true,force:true});}
134
+ });
135
+
136
+
137
+ test('fixed verification baseline observes cancellation instead of waiting for command timeout',{skip:process.platform!=='darwin'},async()=>{
138
+ const f=fixture(),controller=new AbortController();
139
+ f.config.checks=[{id:'long',command:[process.execPath,'-e','setTimeout(()=>{},10000)']}];f.config.timeoutMs=2000;
140
+ const timer=setTimeout(()=>controller.abort(),100);
141
+ try{
142
+ await assert.rejects(verifyReviewVerificationBaseline({codeProject:f.root,configuration:f.config,reviewPackage:f.request.payload.reviewPackage,signal:controller.signal}),error=>{
143
+ assert.equal(error.verificationDiagnostic.code,'verification_cancelled');return true;
144
+ });
145
+ }finally{clearTimeout(timer);fs.rmSync(f.root,{recursive:true,force:true});}
146
+ });
@@ -0,0 +1,81 @@
1
+ import test,{after} from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import fs from 'node:fs';
4
+ import os from 'node:os';
5
+ import path from 'node:path';
6
+ import {PassThrough,Writable} from 'node:stream';
7
+ import {serveCmAiHost} from '../runtime/js/cm-ai/host-session.mjs';
8
+ import {createHostToolBridge} from '../runtime/js/cm-ai/host-tool-bridge.mjs';
9
+ import {createFixHost} from '../runtime/js/cm-fix/host.mjs';
10
+
11
+ // The parser's optional registry must never touch the real user's CM home.
12
+ const isolated=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-revision-transport-')));
13
+ const previous={CM_WORKFLOW_HOME:process.env.CM_WORKFLOW_HOME,CM_WORKFLOW_LOG_HOME:process.env.CM_WORKFLOW_LOG_HOME};
14
+ process.env.CM_WORKFLOW_HOME=path.join(isolated,'home');process.env.CM_WORKFLOW_LOG_HOME=path.join(isolated,'logs');
15
+ after(()=>{for(const [key,value]of Object.entries(previous)){if(value===undefined)delete process.env[key];else process.env[key]=value;}fs.rmSync(isolated,{recursive:true,force:true});});
16
+
17
+ // One real ready/request/reply/EOF exchange. Only the owner is a routing spy:
18
+ // no run is opened, no commands execute, and no provider or Review is invoked.
19
+ async function exchange(operation,{permissions=[]}={}){
20
+ const calls=[],effects=[],handled=[],rows=[],diagnostics=[];
21
+ const request={requestId:'revision-check',operation};
22
+ const owner={
23
+ async runRevisionTests(options){
24
+ calls.push({method:'runRevisionTests',options});
25
+ if(options.authorized!==true)throw Object.assign(new Error('regression_authorization_required'),{code:'regression_authorization_required'});
26
+ effects.push('revision-test-check');return {stage:'revision_repair_required',fixture:'routing-only',completionEligible:false};
27
+ },
28
+ async runRegression(options){calls.push({method:'runRegression',options});return {stage:'handoff_required',fixture:'existing-routing-only'};},
29
+ };
30
+ const realHost=createFixHost({owner,config:{},permissions});
31
+ const host={handle(raw){handled.push(raw);return realHost.handle(raw);}};
32
+ const input=new PassThrough(),toolBridge=createHostToolBridge({answerTimeoutMs:1000});
33
+ const output=new Writable({write(chunk,encoding,done){
34
+ try{
35
+ const row=JSON.parse(chunk.toString());rows.push(row);
36
+ if(row.type==='host_ready')setImmediate(()=>input.write(JSON.stringify(request)+'\n'));
37
+ else if(Object.hasOwn(row,'requestId'))setImmediate(()=>input.end());
38
+ done();
39
+ }catch(error){done(error);}
40
+ }});
41
+ const errorOutput=new Writable({write(chunk,encoding,done){try{diagnostics.push(JSON.parse(chunk.toString()));done();}catch(error){done(error);}}});
42
+ const timer=setTimeout(()=>input.destroy(new Error('fixture_response_timeout')),3000);
43
+ try{await serveCmAiHost({host,input,output,errorOutput,toolBridge,heartbeat:false});}
44
+ finally{clearTimeout(timer);toolBridge.close();input.destroy();output.destroy();errorOutput.destroy();}
45
+ assert.equal(rows.filter(row=>row.type==='host_ready').length,1);
46
+ return {request,replies:rows.filter(row=>Object.hasOwn(row,'requestId')),calls,effects,handled,diagnostics};
47
+ }
48
+
49
+ test('revision test check crosses the real JSONL parser and exact permission-gated fix host route',async()=>{
50
+ const out=await exchange('revision_test_check',{permissions:['--allow-regression']});
51
+ assert.deepEqual(out.replies,[{requestId:'revision-check',result:{stage:'revision_repair_required',fixture:'routing-only',completionEligible:false}}],
52
+ 'CM_REVISION_TRANSPORT: an existing revision_test_check operation must reach the real host instead of invalid_request');
53
+ assert.deepEqual(out.handled,[out.request]);
54
+ assert.deepEqual(out.calls,[{method:'runRevisionTests',options:{authorized:true}}]);
55
+ assert.deepEqual(out.effects,['revision-test-check']);assert.deepEqual(out.diagnostics,[]);
56
+ });
57
+
58
+ test('revision test check without the existing regression permission cannot perform revision work',async()=>{
59
+ const out=await exchange('revision_test_check');
60
+ assert.deepEqual(out.replies,[{requestId:'revision-check',error:{code:'host_request_failed'}}]);
61
+ assert.deepEqual(out.handled,[out.request]);
62
+ assert.deepEqual(out.calls,[{method:'runRevisionTests',options:{authorized:false}}]);
63
+ assert.deepEqual(out.effects,[]);
64
+ assert.equal(out.diagnostics.length,1);assert.equal(out.diagnostics[0].operation,'revision_test_check');
65
+ assert.equal(out.diagnostics[0].code,'regression_authorization_required');
66
+ });
67
+
68
+ test('nearby invalid revision operation names are rejected by the parser before the host',async()=>{
69
+ for(const operation of ['revision_tests_check','revision_test_check_required','revision-test-check','revision_test_check ']){
70
+ const out=await exchange(operation,{permissions:['--allow-regression']});
71
+ assert.deepEqual(out.replies,[{requestId:null,error:{code:'invalid_request'}}],operation);
72
+ assert.deepEqual(out.handled,[]);assert.deepEqual(out.calls,[]);assert.deepEqual(out.effects,[]);assert.deepEqual(out.diagnostics,[]);
73
+ }
74
+ });
75
+
76
+ test('the existing regression operation keeps its JSONL route and permission argument',async()=>{
77
+ const out=await exchange('regression',{permissions:['--allow-regression']});
78
+ assert.deepEqual(out.replies,[{requestId:'revision-check',result:{stage:'handoff_required',fixture:'existing-routing-only'}}]);
79
+ assert.deepEqual(out.handled,[out.request]);
80
+ assert.deepEqual(out.calls,[{method:'runRegression',options:{authorized:true}}]);assert.deepEqual(out.effects,[]);assert.deepEqual(out.diagnostics,[]);
81
+ });
@@ -0,0 +1,296 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import fs from 'node:fs';
4
+ import os from 'node:os';
5
+ import path from 'node:path';
6
+ import {createHash} from 'node:crypto';
7
+ import {spawnSync} from 'node:child_process';
8
+ import {fileURLToPath} from 'node:url';
9
+ import {openFixExecution} from '../runtime/js/cm-fix/execution.mjs';
10
+ import {createFixReviewHost} from '../runtime/js/cm-fix/host-review.mjs';
11
+ import {fixFinalReviewConfiguration} from '../runtime/js/cm-fix/final-review.mjs';
12
+ import {startFixRun} from '../runtime/js/cm-fix/start.mjs';
13
+ import {createHostReviewAuthority} from '../runtime/js/cm-ai/host-review-authority.mjs';
14
+ import {claudeReviewFingerprint} from '../runtime/js/cm-ai/worker-claude.mjs';
15
+ import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
16
+
17
+ const sha=value=>createHash('sha256').update(value).digest('hex');
18
+ const supported=process.platform==='darwin'&&Number(process.versions.node.split('.')[0])>=24;
19
+ const DRIVER=fileURLToPath(new URL('./cm-fix-drive.mjs',import.meta.url));
20
+ const INSPECT=fileURLToPath(new URL('./cm-fix-verification-recovery.mjs',import.meta.url));
21
+ async function fixture(t,{reproductionClearsAfterCorrection=false,pauseReproductionAfterCorrection=false,fullCloseout=false,pauseBaseline=false}={}){
22
+ const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'fix-source-correction-'))),cwd=path.join(root,'code'),specsRoot=path.join(root,'specs');
23
+ fs.mkdirSync(cwd);fs.mkdirSync(specsRoot);
24
+ const source={
25
+ 'ios.ts':"export type AccentKey = 'blue';\nexport const palette = {blue:'#00f'};\n",
26
+ 'theme.ts':"import { AccentKey, palette } from './ios.ts';\nexport const accent: AccentKey = 'blue';\nexport const color = palette[accent];\n",
27
+ 'theme-check.mjs':"import {color} from './theme.ts';if(color!=='#00f')process.exit(1);\n",
28
+ 'button.mjs':'export const outline = true;\n',
29
+ 'button-check.mjs':"import {outline} from './button.mjs';if(outline){console.error('OUTLINE_BUG');process.exit(1);}\n"
30
+ };
31
+ if(reproductionClearsAfterCorrection)source['button-check.mjs']="import fs from 'node:fs';import {outline} from './button.mjs';if(outline&&!fs.readFileSync('theme.ts','utf8').startsWith('import type')){console.error('OUTLINE_BUG');process.exit(1); }\n";
32
+ if(pauseReproductionAfterCorrection)source['button-check.mjs']="import fs from 'node:fs';if(fs.readFileSync('theme.ts','utf8').startsWith('import type'))Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,1000);"+source['button-check.mjs'];
33
+ if(pauseBaseline)source['theme-check.mjs']+='Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,1000);\n';
34
+ for(const [name,value] of Object.entries(source))fs.writeFileSync(path.join(cwd,name),value);
35
+ fs.writeFileSync(path.join(cwd,'.cm-workflow.json'),JSON.stringify({version:1,runtimes:{available:'both'},roles:{coder:{adapter:'codex-cli'},reviewer:{adapter:'claude-cli'}}}));
36
+ const profile={files:Object.keys(source),checks:[{id:'theme',command:[process.execPath,'theme-check.mjs']}],mutationPaths:['theme.ts'],timeoutMs:3000};
37
+ const reviewConfig={model:'synthetic',disabledSkills:[],preflight:{passed:true,provider:'claude',prompt_transport:'stdin',config_fingerprint:claudeReviewFingerprint({cwd,model:'synthetic',verification:profile})}};
38
+ const reviewer=createFixReviewHost({codeProject:cwd,hostContextId:'author',runtime:'codex',reviewRuntime:'claude',verification:profile,review:reviewConfig}).reviewer;
39
+ const identity={repositoryId:'fixture',runId:'source-correction',taskId:'T-FIX-source-correction',attempt:1};
40
+ const configuration={hostContextId:'author',reviewRuntime:'claude',defect:'Pressed button has outline',causeReview:reviewer,reviewVerification:profile,
41
+ reproduction:{cwd,command:[process.execPath,'button-check.mjs'],expectedFailure:{exitCode:1,outputIncludes:'OUTLINE_BUG'},timeoutMs:3000},
42
+ redTest:{cwd,testFiles:['button-check.mjs'],command:[process.execPath,'button-check.mjs'],expectedFailure:{exitCode:1,outputIncludes:'OUTLINE_BUG'},timeoutMs:3000},
43
+ baseline:{cwd,testFiles:['theme-check.mjs'],commands:[{id:'theme',command:[process.execPath,'theme-check.mjs']}],timeoutMs:3000},repair:{scope:['button.mjs','theme.ts'],requirements:['button.mjs']}};
44
+ if(fullCloseout)configuration.walkthrough={timeoutMs:3000,flows:[{id:'button-flow',modules:['button'],steps:['Read the repaired button outline'],expected:['outline is false'],kind:'commands',command:[process.execPath,'button-check.mjs']},{id:'theme-flow',modules:['theme'],steps:['Load the corrected native TypeScript theme'],expected:['palette blue is preserved'],kind:'commands',command:[process.execPath,'theme-check.mjs']}]};
45
+ const authority=createHostReviewAuthority({hostContextId:'author',reviewerId:reviewer.reviewerId,adapterId:reviewer.adapterId,decide:async()=>({status:'approved'})});
46
+ const finalConfig=fixFinalReviewConfiguration(configuration),finalAuthority=createHostReviewAuthority({hostContextId:'author',reviewerId:finalConfig.reviewer.reviewerId,adapterId:finalConfig.reviewer.adapterId,decide:async()=>({status:'approved'})});
47
+ let owner,calls=0,approve=false,finalApprove=false;
48
+ const runtime={assertReviewReady(){},prepare:async()=>({contextDigest:digest([]),files:[],application:{contextDigest:digest([]),status:'no_relevant_lesson',summary:'No fixture instructions'}}),
49
+ bridge:{async call(kind){if(kind==='fix_diagnose'){
50
+ const diagnosis={status:'diagnosed',rootCause:'Pressed outline is enabled',plan:'Disable pressed outline',affectedPaths:['button.mjs','theme.ts'],affectedModules:['button','theme'],crossLayer:true};
51
+ if(fullCloseout){const button=spawnSync(process.execPath,['button-check.mjs'],{cwd,encoding:'utf8'}),theme=spawnSync(process.execPath,['theme-check.mjs'],{cwd,encoding:'utf8'});assert.equal(button.status,1);assert.match(button.stderr,/OUTLINE_BUG/);assert.equal(theme.status,1);assert.match(theme.stderr,/does not provide an export named 'AccentKey'/);
52
+ diagnosis.investigation={discardedAlternatives:[],boundaryAnalysis:{callChain:'button-check.mjs -> button.mjs; theme-check.mjs -> theme.ts -> ios.ts',edgeEvidence:'Native button check exits 1 with OUTLINE_BUG; native theme check exits 1 because AccentKey is not a runtime export',lastNormalEdge:'Both commands launched successfully with the frozen Node executable',firstFailingEdge:'button exports outline=true; theme uses a type-only symbol as a runtime import',hypotheses:[{hypothesis:'The button defect remains separate from the theme import transport failure',support:'The independent button command reports the original OUTLINE_BUG signature',counterTest:'Run theme-check.mjs separately with the same native Node executable',result:'The independent theme command fails with missing AccentKey runtime export'}]}};
53
+ }return diagnosis;
54
+ }
55
+ if(kind==='fix_repair'){fs.writeFileSync(path.join(cwd,'button.mjs'),'export const outline = false;\n');return {outcome:'repaired'};}
56
+ if(kind==='fix_retrospective')return {status:'no_new_lesson',candidates:[],reason:null};throw Error(kind);}},
57
+ causeReview:{authorize:authority.authorize,async run(request,{onEvent,onVerification}){
58
+ calls++;const thread='review-'+calls;for(const e of [{event:'thread.started',provider_thread:thread},{event:'turn.started',item_type:null},{event:'item.completed',item_type:'agent_message'},{event:'turn.completed',item_type:null},{event:'process_closed',exit_code:0,signal:null,timed_out:false}])onEvent(e);
59
+ if(!(request.payload.reviewPackage.kind==='cm-fix-cause-review-package'?approve:finalApprove))return {status:'failed',code:'review_verification_evidence'};
60
+ const files=profile.files.map(p=>({path:p,sha256:sha(fs.readFileSync(path.join(cwd,p))),mode:fs.statSync(path.join(cwd,p)).mode&511})),before=files.find(f=>f.path==='theme.ts').sha256;
61
+ onVerification({version:1,requestDigest:request.requestDigest,packageDigest:request.payload.reviewPackage.packageDigest,profileDigest:digest(profile),providerThreadId:thread,files,snapshotDigest:digest(files),checks:[{id:'theme',commandDigest:digest(profile.checks[0].command),exitCode:0,outputSha256:sha(''),startedAt:1,endedAt:2}],mutations:[{path:'theme.ts',beforeSha256:before,afterSha256:'c'.repeat(64),checkId:'theme',baselineExitCode:0,mutatedExitCode:1,restoredExitCode:0,restoredSha256:before,startedAt:3,endedAt:4}]});
62
+ return {status:'succeeded',value:{verdict:'approved',packageDigest:request.payload.reviewPackage.packageDigest,examinedPaths:['button.mjs','theme.ts'],findings:[],summary:'Synthetic routing proof only'}};
63
+ }}};
64
+ runtime.finalReview={authorize:finalAuthority.authorize,run:runtime.causeReview.run};
65
+ const options={specsRoot,identity,configuration};owner=openFixExecution({...options,create:true},runtime);
66
+ t.after(()=>{owner?.close();fs.rmSync(root,{recursive:true,force:true});});
67
+ const review=async token=>{const pkg=owner.causeReviewPackage();await authority.hostDecisionProvider.decide({identity:pkg.identity,packageDigest:pkg.packageDigest},new AbortController().signal);return owner.reviewCause({verificationRecoveryAuthorization:token});};
68
+ const finalReview=async()=>{const pkg=owner.finalReviewPackage();await finalAuthority.hostDecisionProvider.decide({identity:pkg.identity,packageDigest:pkg.packageDigest},new AbortController().signal);return owner.reviewFinal();};
69
+ if(fullCloseout)startFixRun({specsRoot,identity,configuration});
70
+ await owner.advance({authorized:true});await review();for(let i=0;i<2;i++){owner.abandonReview({authorized:true,reason:'Verification worker closed'});await review();}
71
+ const statePath=path.join(specsRoot,'.reviews','.execution',identity.runId,'state.json');
72
+ const correction={kind:'type-import-split',path:'theme.ts',beforeSha256:sha(source['theme.ts']),typeNames:['AccentKey']};
73
+ const config=path.join(root,'config.json'),reviewPath=path.join(root,'review.json'),correctionPath=path.join(root,'correction.json'),answers=path.join(root,'answers');
74
+ const {hostContextId,causeReview,reviewRuntime,...run}=configuration;
75
+ fs.writeFileSync(config,JSON.stringify({...run,identity,specsRoot}));fs.writeFileSync(reviewPath,JSON.stringify(reviewConfig));fs.writeFileSync(correctionPath,JSON.stringify(correction));fs.mkdirSync(answers);
76
+ return {root,cwd,specsRoot,statePath,source,correction,config,reviewPath,correctionPath,answers,configuration,review,finalReview,get owner(){return owner;},get calls(){return calls;},approve(){approve=true;},approveFinal(){finalApprove=true;},close(){owner.close();owner=null;},reopen(){owner?.close();owner=openFixExecution({...options,create:false},runtime);}};
77
+ }
78
+ function cli(f,args){return spawnSync(process.execPath,args,{encoding:'utf8',timeout:30000,env:{...process.env,CM_WORKFLOW_HOME:path.join(f.root,'home'),CM_WORKFLOW_LOG_HOME:path.join(f.root,'logs')}});}
79
+
80
+ test('type-import source correction previews in isolation then preserves original history and final diff',{skip:!supported},async t=>{
81
+ const f=await fixture(t),before=fs.readFileSync(f.statePath),old=JSON.parse(before),calls=f.calls;
82
+ const broken=spawnSync(process.execPath,['theme-check.mjs'],{cwd:f.cwd,encoding:'utf8'});assert.notEqual(broken.status,0);assert.match(broken.stderr,/does not provide an export named 'AccentKey'/);
83
+ const expected=await f.owner.inspectVerificationRecovery({sourceCorrection:f.correction});
84
+ assert.ok(expected.sourceCorrection);assert.deepEqual(fs.readFileSync(f.statePath),before);assert.equal(f.calls,calls);assert.equal(fs.readFileSync(path.join(f.cwd,'theme.ts'),'utf8'),f.source['theme.ts']);
85
+ const prepared=await f.owner.prepareVerificationRecovery({authorized:true,sourceCorrectionAuthorized:true,expected,sourceCorrection:f.correction,previousInvocationStopped:true,reason:'Explicit type-only import correction; preserve button defect'});
86
+ assert.match(prepared.authorizationDigest,/^[a-f0-9]{64}$/);assert.equal(f.calls,calls);
87
+ assert.match(fs.readFileSync(path.join(f.cwd,'theme.ts'),'utf8'),/import type/);assert.deepEqual(JSON.parse(fs.readFileSync(f.statePath)).records.slice(0,old.records.length),old.records);
88
+ assert.deepEqual(JSON.parse(fs.readFileSync(f.statePath)).fingerprints,old.fingerprints);
89
+ assert.deepEqual(await f.owner.prepareVerificationRecovery({authorized:true,sourceCorrectionAuthorized:true,expected,sourceCorrection:f.correction,previousInvocationStopped:true,reason:'Explicit type-only import correction; preserve button defect'}),prepared);
90
+ f.reopen();f.approve();await f.review(prepared.authorizationDigest);assert.equal(f.owner.status().stage,'red_test_required');
91
+ await f.owner.runRedTest({authorized:true});await f.owner.captureBaseline({authorized:true});await f.owner.repair({authorized:true});await f.owner.runRegression({authorized:true});await f.owner.retrospect();f.owner.createHandoff();
92
+ const pkg=f.owner.finalReviewPackage(),change=pkg.changes.find(c=>c.path==='theme.ts');
93
+ assert.ok(change,'Pre-review source correction must remain visible in final implementation diff');
94
+ assert.equal(Buffer.from(change.before.contentBase64,'base64').toString(),f.source['theme.ts']);assert.match(Buffer.from(change.after.contentBase64,'base64').toString(),/import type/);
95
+ assert.deepEqual(f.configuration.repair.scope,['button.mjs','theme.ts']);assert.equal(f.calls,calls+1);
96
+ });
97
+
98
+ test('real source-correction inspector and driver preserve previews and require separate startup authority',{skip:!supported},async t=>{
99
+ const f=await fixture(t),before=fs.readFileSync(f.statePath),calls=f.calls;
100
+ f.close();
101
+ const inspection=cli(f,[INSPECT,'--config',f.config,'--source-correction',f.correctionPath]);assert.equal(inspection.status,0,inspection.stdout+inspection.stderr);
102
+ const expected=JSON.parse(inspection.stdout).expected;assert.ok(expected.sourceCorrection);
103
+ assert.deepEqual(fs.readFileSync(f.statePath),before);assert.equal(fs.readFileSync(path.join(f.cwd,'theme.ts'),'utf8'),f.source['theme.ts']);
104
+ const plan=path.join(f.root,'plan.json'),base={config:f.config,cwd:f.cwd,mode:'resume',hostContext:'author',runtime:'codex',reviewRuntime:'claude',reviewConfig:f.reviewPath,expected,sourceCorrection:f.correction,previousInvocationStopped:true,reason:'Authorized type-only import correction'};
105
+ const drive=(permissions,operation='prepare_verification_recovery',extra={})=>{fs.writeFileSync(plan,JSON.stringify({...base,permissions,...extra}));return cli(f,[DRIVER,'--plan',plan,operation]);};
106
+ let run=drive(['--allow-verification-recovery']);assert.equal(run.status,2);assert.match(run.stderr,/--allow-source-correction/);assert.deepEqual(fs.readFileSync(f.statePath),before);
107
+ run=drive(['--allow-source-correction']);assert.equal(run.status,2);assert.match(run.stderr,/--allow-verification-recovery/);assert.deepEqual(fs.readFileSync(f.statePath),before);
108
+ run=drive(['--allow-verification-recovery','--allow-source-correction']);assert.equal(run.status,0,run.stdout+run.stderr);const prepared=JSON.parse(run.stdout).result;
109
+ assert.match(prepared.authorizationDigest,/^[a-f0-9]{64}$/);assert.match(fs.readFileSync(path.join(f.cwd,'theme.ts'),'utf8'),/import type/);
110
+ const preparedBytes=fs.readFileSync(f.statePath);run=drive(['--allow-verification-recovery','--allow-source-correction']);assert.equal(run.status,0,run.stdout+run.stderr);assert.deepEqual(fs.readFileSync(f.statePath),preparedBytes);
111
+ // A fresh review is still separately authorized; preparing source does not invoke it.
112
+ const {sourceCorrection,...continuation}=base;fs.writeFileSync(plan,JSON.stringify({...continuation,answers:f.answers,permissions:[],verificationRecoveryAuthorization:prepared.authorizationDigest}));
113
+ run=cli(f,[DRIVER,'--plan',plan,'cause_review']);assert.match(run.stdout+run.stderr,/permission_denied/);assert.deepEqual(fs.readFileSync(f.statePath),preparedBytes);assert.equal(f.calls,calls);
114
+ f.reopen();assert.equal(f.owner.status().stage,'cause_review_required');
115
+ });
116
+
117
+ test('source-correction startup flag refuses create and missing recovery permission before opening a run',{skip:!supported},async t=>{
118
+ const f=await fixture(t),before=fs.readFileSync(f.statePath),host=fileURLToPath(new URL('./cm-fix-host.mjs',import.meta.url));f.close();
119
+ for(const [mode,permissions] of [['create',['--allow-verification-recovery','--allow-source-correction']],['resume',['--allow-source-correction']]]){
120
+ const run=cli(f,[host,'serve','--config',f.config,'--mode',mode,'--host-context','author','--allow-reproduction',...permissions]);assert.notEqual(run.status,0);assert.match(run.stderr,/fix_(?:source_correction_authorization_required|verification_recovery_unavailable)/);assert.deepEqual(fs.readFileSync(f.statePath),before);
121
+ }
122
+ });
123
+
124
+ const prepareInput=(f,expected)=>({authorized:true,sourceCorrectionAuthorized:true,expected,sourceCorrection:f.correction,previousInvocationStopped:true,reason:'Explicit original-scope type import repair'});
125
+ test('source correction rejects missing authority, wrong expected and wrong declaration before writes',{skip:!supported},async t=>{
126
+ const f=await fixture(t),expected=await f.owner.inspectVerificationRecovery({sourceCorrection:f.correction}),input=prepareInput(f,expected),before=fs.readFileSync(f.statePath);
127
+ for(const [override,code] of [[{authorized:false},'fix_verification_recovery_authorization_required'],[{sourceCorrectionAuthorized:false},'fix_source_correction_authorization_required'],[{previousInvocationStopped:false},'fix_verification_recovery_confirmation'],[{expected:{...expected,invocationId:'wrong'}},'fix_verification_recovery_stale'],[{sourceCorrection:{...f.correction,typeNames:['MissingType']}},'type_import_correction_names']]){
128
+ await assert.rejects(f.owner.prepareVerificationRecovery({...input,...override}),{code});assert.deepEqual(fs.readFileSync(f.statePath),before);assert.equal(fs.readFileSync(path.join(f.cwd,'theme.ts'),'utf8'),f.source['theme.ts']);
129
+ }
130
+ assert.equal(f.calls,3);
131
+ });
132
+
133
+ test('source correction refuses a third source image and unapproved manual correction',{skip:!supported},async t=>{
134
+ const f=await fixture(t),expected=await f.owner.inspectVerificationRecovery({sourceCorrection:f.correction}),input=prepareInput(f,expected),before=fs.readFileSync(f.statePath);
135
+ const target=path.join(f.cwd,'theme.ts');fs.appendFileSync(target,'// unrelated manual source\n');
136
+ await assert.rejects(f.owner.prepareVerificationRecovery(input));assert.deepEqual(fs.readFileSync(f.statePath),before);
137
+ fs.writeFileSync(target,Buffer.from(expected.sourceCorrection.after.contentBase64,'base64'));
138
+ await assert.rejects(f.owner.prepareVerificationRecovery(input));assert.deepEqual(fs.readFileSync(f.statePath),before);assert.equal(f.calls,3);
139
+ });
140
+
141
+ test('source correction resumes the exact recorded intent after an injected post-rename interruption',{skip:!supported},async t=>{
142
+ const f=await fixture(t),expected=await f.owner.inspectVerificationRecovery({sourceCorrection:f.correction}),input=prepareInput(f,expected),before=JSON.parse(fs.readFileSync(f.statePath)).records;
143
+ const target=path.join(f.cwd,'theme.ts'),rename=fs.renameSync;let interrupted=false;
144
+ fs.renameSync=(from,to)=>{const result=rename(from,to);if(to===target&&!interrupted){interrupted=true;throw Object.assign(new Error('fixture interruption after atomic source rename'),{code:'fixture_interruption'});}return result;};
145
+ try{await assert.rejects(f.owner.prepareVerificationRecovery(input),{code:'fixture_interruption'});}finally{fs.renameSync=rename;}
146
+ assert.ok(interrupted);assert.match(fs.readFileSync(target,'utf8'),/import type/);
147
+ const interruptedRows=JSON.parse(fs.readFileSync(f.statePath)).records;assert.deepEqual(interruptedRows.slice(0,before.length),before);
148
+ assert.equal(interruptedRows.filter(r=>r.id==='fix-verification-recovery-source-intent').length,1);assert.equal(interruptedRows.some(r=>r.id==='fix-verification-recovery-prepared'),false);
149
+ f.reopen();const exactAfter=fs.readFileSync(target),interruptedState=fs.readFileSync(f.statePath);fs.appendFileSync(target,'// third content after interruption\n');
150
+ await assert.rejects(f.owner.prepareVerificationRecovery(input),{code:'type_import_correction_stale'});assert.deepEqual(fs.readFileSync(f.statePath),interruptedState);fs.writeFileSync(target,exactAfter);
151
+ const prepared=await f.owner.prepareVerificationRecovery(input);assert.match(prepared.authorizationDigest,/^[a-f0-9]{64}$/);
152
+ const rows=JSON.parse(fs.readFileSync(f.statePath)).records;assert.deepEqual(rows.slice(0,interruptedRows.length),interruptedRows);assert.equal(rows.filter(r=>r.id==='fix-verification-recovery-source-intent').length,1);assert.equal(f.calls,3);
153
+ assert.deepEqual(await f.owner.prepareVerificationRecovery(input),prepared);
154
+ });
155
+
156
+ test('source correction cannot replace a prepared declaration or claim a second recovery budget',{skip:!supported},async t=>{
157
+ const f=await fixture(t),expected=await f.owner.inspectVerificationRecovery({sourceCorrection:f.correction}),input=prepareInput(f,expected),prepared=await f.owner.prepareVerificationRecovery(input),before=fs.readFileSync(f.statePath);
158
+ await assert.rejects(f.owner.prepareVerificationRecovery({...input,sourceCorrection:{...f.correction,typeNames:['palette']}}));assert.deepEqual(fs.readFileSync(f.statePath),before);
159
+ for(const override of [{sourceCorrectionAuthorized:false},{sourceCorrection:undefined},{sourceCorrectionAuthorized:false,sourceCorrection:undefined}]){await assert.rejects(f.owner.prepareVerificationRecovery({...input,...override}),{code:'fix_source_correction_authorization_required'});assert.deepEqual(fs.readFileSync(f.statePath),before);}
160
+ await assert.rejects(f.owner.inspectVerificationRecovery(),{code:'fix_verification_recovery_used'});
161
+ assert.throws(()=>f.owner.abandonReview({authorized:true,reason:'No reset'}),{code:'fix_verification_recovery_used'});
162
+ await f.review(prepared.authorizationDigest);assert.equal(f.owner.status().stage,'unknown');assert.equal(f.calls,4);
163
+ await assert.rejects(f.owner.prepareVerificationRecovery(input),{code:'fix_verification_recovery_used'});assert.equal(f.calls,4);
164
+ });
165
+
166
+ test('source correction records failure and cannot dispatch when original reproduction no longer matches',{skip:!supported},async t=>{
167
+ const f=await fixture(t,{reproductionClearsAfterCorrection:true}),expected=await f.owner.inspectVerificationRecovery({sourceCorrection:f.correction}),input=prepareInput(f,expected),old=JSON.parse(fs.readFileSync(f.statePath)).records;
168
+ await assert.rejects(f.owner.prepareVerificationRecovery(input),{code:'fix_source_correction_reproduction_changed'});
169
+ const rows=JSON.parse(fs.readFileSync(f.statePath)).records;assert.deepEqual(rows.slice(0,old.length),old);assert.equal(rows.some(r=>r.id==='fix-verification-recovery-prepared'),false);
170
+ assert.equal(rows.find(r=>r.id==='fix-verification-recovery-source-failed').payload.code,'fix_source_correction_reproduction_changed');
171
+ assert.match(fs.readFileSync(path.join(f.cwd,'theme.ts'),'utf8'),/import type/);f.reopen();assert.equal(f.owner.status().stage,'unknown');
172
+ await assert.rejects(f.owner.prepareVerificationRecovery(input),{code:'fix_source_correction_failed'});assert.equal(f.calls,3);
173
+ });
174
+
175
+ test('interrupted source checks consume their bounded attempts without resetting review calls',{skip:!supported},async t=>{
176
+ const f=await fixture(t),expected=await f.owner.inspectVerificationRecovery({sourceCorrection:f.correction}),input=prepareInput(f,expected);
177
+ for(let attempt=1;attempt<=2;attempt++){
178
+ const rename=fs.renameSync;let interrupted=false;
179
+ fs.renameSync=(from,to)=>{const result=rename(from,to);if(to===f.statePath&&!interrupted&&JSON.parse(fs.readFileSync(to)).records.at(-1).id===`fix-verification-recovery-source-check-${attempt}-intent`){interrupted=true;throw Object.assign(new Error('fixture interruption after durable check intent'),{code:'fixture_interruption'});}return result;};
180
+ try{await assert.rejects(f.owner.prepareVerificationRecovery(input));}finally{fs.renameSync=rename;}
181
+ assert.ok(interrupted);f.reopen();assert.equal(f.owner.status().sourceCorrection.checksUsed,attempt);assert.equal(f.calls,3);
182
+ }
183
+ const before=fs.readFileSync(f.statePath);await assert.rejects(f.owner.prepareVerificationRecovery(input),{code:'fix_source_correction_check_budget'});assert.deepEqual(fs.readFileSync(f.statePath),before);
184
+ assert.equal(JSON.parse(before).records.some(r=>r.id==='fix-verification-recovery-prepared'),false);
185
+ });
186
+
187
+ test('source intent rejects non-target profile drift before applying the recorded patch',{skip:!supported},async t=>{
188
+ const f=await fixture(t),expected=await f.owner.inspectVerificationRecovery({sourceCorrection:f.correction}),input=prepareInput(f,expected),target=path.join(f.cwd,'theme.ts'),rename=fs.renameSync;let interrupted=false;
189
+ fs.renameSync=(from,to)=>{if(to===target&&!interrupted){interrupted=true;throw Object.assign(new Error('fixture interruption before atomic source rename'),{code:'fixture_interruption'});}return rename(from,to);};
190
+ try{await assert.rejects(f.owner.prepareVerificationRecovery(input),{code:'fixture_interruption'});}finally{fs.renameSync=rename;}
191
+ assert.ok(interrupted);f.reopen();const before=fs.readFileSync(f.statePath);fs.appendFileSync(path.join(f.cwd,'ios.ts'),'// changed dependency after intent\n');
192
+ await assert.rejects(f.owner.prepareVerificationRecovery(input),{code:'fix_source_correction_drift'});
193
+ assert.deepEqual(fs.readFileSync(f.statePath),before);assert.equal(fs.readFileSync(target,'utf8'),f.source['theme.ts']);assert.equal(f.calls,3);
194
+ });
195
+
196
+ test('source result cannot prepare after profile drift in the result-to-prepared interruption gap',{skip:!supported},async t=>{
197
+ const f=await fixture(t),expected=await f.owner.inspectVerificationRecovery({sourceCorrection:f.correction}),input=prepareInput(f,expected),rename=fs.renameSync;let interrupted=false;
198
+ fs.renameSync=(from,to)=>{if(to===f.statePath&&!interrupted&&JSON.parse(fs.readFileSync(from)).records.at(-1).id==='fix-verification-recovery-prepared'){interrupted=true;throw Object.assign(new Error('fixture interruption before prepared checkpoint'),{code:'fixture_interruption'});}return rename(from,to);};
199
+ try{await assert.rejects(f.owner.prepareVerificationRecovery(input),{code:'fixture_interruption'});}finally{fs.renameSync=rename;}
200
+ assert.ok(interrupted);f.reopen();const before=fs.readFileSync(f.statePath),rows=JSON.parse(before).records;
201
+ assert.ok(rows.some(r=>r.id==='fix-verification-recovery-source-result'));assert.equal(rows.some(r=>r.id==='fix-verification-recovery-prepared'),false);
202
+ fs.appendFileSync(path.join(f.cwd,'ios.ts'),'// changed after result\n');
203
+ await assert.rejects(f.owner.prepareVerificationRecovery(input),{code:'fix_source_correction_drift'});assert.deepEqual(fs.readFileSync(f.statePath),before);assert.equal(f.calls,3);
204
+ });
205
+
206
+ test('durable source result survives a post-rename store interruption without competing failure or repeated checks',{skip:!supported},async t=>{
207
+ const f=await fixture(t),expected=await f.owner.inspectVerificationRecovery({sourceCorrection:f.correction}),input=prepareInput(f,expected),rename=fs.renameSync;let interrupted=false;
208
+ fs.renameSync=(from,to)=>{const result=rename(from,to);if(to===f.statePath&&!interrupted&&JSON.parse(fs.readFileSync(to)).records.at(-1).id==='fix-verification-recovery-source-result'){interrupted=true;throw Object.assign(new Error('fixture interruption after durable source result'),{code:'fixture_interruption'});}return result;};
209
+ try{await assert.rejects(f.owner.prepareVerificationRecovery(input));}finally{fs.renameSync=rename;}
210
+ assert.ok(interrupted);const rows=JSON.parse(fs.readFileSync(f.statePath)).records;
211
+ assert.ok(rows.some(r=>r.id==='fix-verification-recovery-source-result'));assert.equal(rows.some(r=>r.id==='fix-verification-recovery-source-failed'),false);assert.equal(rows.some(r=>r.id==='fix-verification-recovery-prepared'),false);
212
+ f.reopen();const prepared=await f.owner.prepareVerificationRecovery(input);assert.match(prepared.authorizationDigest,/^[a-f0-9]{64}$/);
213
+ const after=JSON.parse(fs.readFileSync(f.statePath)).records;assert.deepEqual(after.slice(0,rows.length),rows);assert.equal(after.filter(r=>/^fix-verification-recovery-source-check-[12]-intent$/.test(r.id)).length,1);assert.equal(after.some(r=>r.id==='fix-verification-recovery-source-failed'),false);assert.equal(f.calls,3);
214
+ });
215
+
216
+ test('cancelling an active source reproduction cannot publish a prepared continuation',{skip:!supported},async t=>{
217
+ const f=await fixture(t,{pauseReproductionAfterCorrection:true}),expected=await f.owner.inspectVerificationRecovery({sourceCorrection:f.correction}),input=prepareInput(f,expected);
218
+ const running=f.owner.prepareVerificationRecovery(input).then(value=>({value}),error=>({error}));
219
+ const deadline=Date.now()+5000;let started=false;
220
+ while(Date.now()<deadline){if(JSON.parse(fs.readFileSync(f.statePath)).records.some(r=>r.id==='fix-verification-recovery-source-check-1-intent')){started=true;break;}await new Promise(resolve=>setTimeout(resolve,5));}
221
+ assert.ok(started,'The fixed source reproduction must actually have started');f.owner.cancel();const result=await running;assert.ok(result.error);
222
+ const rows=JSON.parse(fs.readFileSync(f.statePath)).records;assert.equal(rows.some(r=>r.id==='fix-verification-recovery-prepared'),false);assert.equal(rows.some(r=>r.id==='fix-verification-recovery-registered'),false);assert.equal(f.calls,3);
223
+ f.reopen();assert.equal(f.owner.status().stage,'cancelled');
224
+ });
225
+
226
+ async function correctedCause(f){
227
+ const expected=await f.owner.inspectVerificationRecovery({sourceCorrection:f.correction}),input=prepareInput(f,expected),prepared=await f.owner.prepareVerificationRecovery(input);
228
+ f.approve();await f.review(prepared.authorizationDigest);assert.equal(f.owner.status().stage,'red_test_required');return {input,prepared};
229
+ }
230
+ async function reachFinalReview(f){
231
+ await f.owner.runRedTest({authorized:true});await f.owner.captureBaseline({authorized:true});await f.owner.repair({authorized:true});await f.owner.runRegression({authorized:true});await f.owner.retrospect();f.owner.createHandoff();
232
+ }
233
+ test('successful source cause recovery retains original F24 final recovery and replays its fresh review',{skip:!supported},async t=>{
234
+ const f=await fixture(t),{input}=await correctedCause(f);await reachFinalReview(f);await f.finalReview();assert.equal(f.owner.status().stage,'unknown');
235
+ const before=JSON.parse(fs.readFileSync(f.statePath)).records,last=before.findLast(r=>r.id.endsWith('-registered')&&r.payload.request?.role==='reviewer').payload;
236
+ const recovered=f.owner.recoverFinalReview({authorized:true,invocationId:last.request.invocationId,packageDigest:last.request.payload.reviewPackage.packageDigest,previousInvocationStopped:true,reason:'Original F24 budget after a separate final transport failure'});
237
+ assert.equal(recovered.stage,'final_review_required');assert.equal(recovered.finalReviewRecoveryCount,1);
238
+ assert.deepEqual(JSON.parse(fs.readFileSync(f.statePath)).records.slice(0,before.length),before);
239
+ f.reopen();assert.equal(f.owner.status().stage,'final_review_required');f.approveFinal();await f.finalReview();assert.equal(f.owner.status().stage,'final_review_evidence_required');
240
+ f.owner.publishReview();f.reopen();assert.equal(f.owner.status().stage,'completion_gate_required');
241
+ const rows=JSON.parse(fs.readFileSync(f.statePath)).records,oldThread=rows.find(r=>r.id==='fix-final-started').payload.providerThreadId,newThread=rows.find(r=>r.id==='fix-final-recovery-started').payload.providerThreadId;
242
+ assert.notEqual(newThread,oldThread);assert.equal(rows.filter(r=>r.id==='fix-verification-recovery-registered').length,1);
243
+ await assert.rejects(f.owner.prepareVerificationRecovery(input),{code:'fix_verification_recovery_used'});
244
+ });
245
+
246
+ // Fixture-only corruption: reseal hashes so failures come from semantic replay,
247
+ // not the store's byte/hash checks. Never applied to a user's execution archive.
248
+ function resealFixture(statePath,mutate){
249
+ const state=JSON.parse(fs.readFileSync(statePath));mutate(state.records);let previous=null;
250
+ for(const row of state.records){row.previousDigest=previous;const {digest:old,...data}=row;row.digest=digest(data);previous=row.digest;}
251
+ const {revision,...data}=state;state.revision=digest(data);fs.writeFileSync(statePath,JSON.stringify(state)+'\n');
252
+ }
253
+ for(const field of ['package','reproduction','baseline','sourceResultDigest','sourceRevision'])test(`source correction replay rejects resealed ${field} tampering`,{skip:!supported},async t=>{
254
+ const f=await fixture(t),expected=await f.owner.inspectVerificationRecovery({sourceCorrection:f.correction}),prepared=await f.owner.prepareVerificationRecovery(prepareInput(f,expected));
255
+ if(field==='sourceRevision'){f.approve();await f.review(prepared.authorizationDigest);assert.equal(f.owner.status().stage,'red_test_required');}
256
+ f.close();const original=fs.readFileSync(f.statePath);
257
+ resealFixture(f.statePath,rows=>{
258
+ const result=rows.find(r=>r.id==='fix-verification-recovery-source-result').payload,ready=rows.find(r=>r.id==='fix-verification-recovery-prepared').payload;
259
+ if(field==='package'){result.package.defect+=' substituted';const {packageDigest,...body}=result.package;result.package.packageDigest=digest(body);}
260
+ if(field==='reproduction')result.reproduction.observation.signatureMatched=false;
261
+ if(field==='baseline')result.baseline.checks[0].commandDigest='a'.repeat(64);
262
+ if(['package','reproduction','baseline'].includes(field))rows.splice(rows.findIndex(r=>r.id==='fix-verification-recovery-source-result')+1);
263
+ if(field==='sourceResultDigest')ready.sourceResultDigest='a'.repeat(64);
264
+ if(field==='sourceRevision'){
265
+ const pkg=rows.find(r=>r.id==='fix-verification-recovery-registered').payload.request.payload.reviewPackage;
266
+ pkg.sourceRevision.correctionDigest='a'.repeat(64);const {packageDigest,...body}=pkg;pkg.packageDigest=digest(body);
267
+ }
268
+ });
269
+ try{assert.throws(()=>{f.reopen();f.owner.status();},error=>['fix_source_correction_binding','reproduction_mismatch','fix_verification_recovery_baseline','fix_verification_recovery_binding'].includes(error.code));}
270
+ finally{fs.writeFileSync(f.statePath,original);}
271
+ });
272
+
273
+ test('source correction completes the original JS gates with walkthrough frozen at creation',{skip:!supported},async t=>{
274
+ const f=await fixture(t,{fullCloseout:true}),initial=JSON.parse(fs.readFileSync(f.statePath)),{input}=await correctedCause(f);
275
+ await reachFinalReview(f);f.approveFinal();await f.finalReview();assert.equal(f.owner.status().stage,'final_review_evidence_required');
276
+ f.owner.publishReview();assert.equal(f.owner.checkCompletionGate().stage,'post_review_regression_required');
277
+ await f.owner.runRegression({authorized:true,postReview:true});assert.equal(f.owner.status().stage,'closeout_required');
278
+ await f.owner.runWalkthrough({authorized:true});assert.equal(f.owner.status().walkthrough.status,'passed');
279
+ const finished=f.owner.finish({authorized:true});assert.equal(finished.stage,'completed');assert.equal(finished.completionEligible,true);
280
+ f.reopen();assert.equal(f.owner.status().stage,'completed');const evidence=f.owner.completionEvidence();
281
+ assert.ok(evidence.reviewPackage.changes.some(c=>c.path==='theme.ts'));assert.equal(evidence.identity.attempt,1);
282
+ const final=JSON.parse(fs.readFileSync(f.statePath));assert.deepEqual(final.fingerprints,initial.fingerprints);assert.deepEqual(final.records.slice(0,initial.records.length),initial.records);
283
+ await assert.rejects(f.owner.prepareVerificationRecovery(input),{code:'fix_verification_recovery_used'});
284
+ });
285
+
286
+ test('cancelling formal source baseline interrupts its frozen check before completion',{skip:!supported},async t=>{
287
+ const f=await fixture(t,{pauseBaseline:true}),expected=await f.owner.inspectVerificationRecovery({sourceCorrection:f.correction}),input=prepareInput(f,expected),write=fs.writeFileSync;
288
+ let scheduled=false,cancelledAt=0,timer;
289
+ fs.writeFileSync=(file,...args)=>{const result=write(file,...args);if(!scheduled&&typeof file==='string'&&file.endsWith('/tools.json')&&JSON.parse(fs.readFileSync(f.statePath)).records.some(r=>r.id==='fix-verification-recovery-source-check-1-intent')){
290
+ scheduled=true;timer=setTimeout(()=>{cancelledAt=Date.now();f.owner.cancel();},50);
291
+ }return result;};
292
+ let failure;try{await f.owner.prepareVerificationRecovery(input);}catch(error){failure=error;}finally{fs.writeFileSync=write;clearTimeout(timer);}
293
+ assert.ok(scheduled);assert.ok(cancelledAt);assert.ok(failure);assert.equal(failure.verificationDiagnostic?.code,'verification_cancelled');
294
+ const rows=JSON.parse(fs.readFileSync(f.statePath)).records;assert.equal(rows.some(r=>r.id==='fix-verification-recovery-source-result'),false);assert.equal(rows.some(r=>r.id==='fix-verification-recovery-prepared'),false);assert.equal(f.calls,3);
295
+ f.reopen();assert.equal(f.owner.status().stage,'cancelled');
296
+ });
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env node
2
+ // Qualification only: no writer, source edits, command execution or provider.
3
+ import fs from 'node:fs';
4
+ import path from 'node:path';
5
+ import {fileURLToPath} from 'node:url';
6
+ import {inspectFixTestTypeCorrection} from '../runtime/js/cm-fix/execution.mjs';
7
+ import {need} from '../runtime/js/cm-ai/effect-contract.mjs';
8
+ export function main(argv=process.argv.slice(2),{output=process.stdout,error=process.stderr}={}){
9
+ try{
10
+ need(argv.length===4&&argv[0]==='--config'&&argv[2]==='--declaration','invalid_arguments');
11
+ const stat=fs.lstatSync(argv[1]);need(stat.isFile()&&!stat.isSymbolicLink()&&stat.size<=64*1024,'invalid_fix_config');
12
+ const declarationStat=fs.lstatSync(argv[3]);need(declarationStat.isFile()&&!declarationStat.isSymbolicLink()&&declarationStat.size<=4096,'invalid_type_declaration');
13
+ const c=JSON.parse(fs.readFileSync(argv[1],'utf8')),specsRoot=fs.realpathSync(c.specsRoot??path.join(c.reproduction.cwd,'docs/fixes'));
14
+ const expected=inspectFixTestTypeCorrection({specsRoot,identity:{repositoryId:c.identity.repositoryId,runId:c.identity.runId},declaration:JSON.parse(fs.readFileSync(argv[3],'utf8'))});
15
+ output.write(JSON.stringify({eligible:true,expected})+'\n');return 0;
16
+ }catch(e){const code=/^[a-z_]{1,64}$/.test(e?.code??'')?e.code:'fix_test_type_correction_unavailable';error.write(JSON.stringify({eligible:false,code})+'\n');return 1;}
17
+ }
18
+ if(process.argv[1]&&path.resolve(process.argv[1])===fileURLToPath(import.meta.url))process.exitCode=main();