@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
@@ -1,5 +1,6 @@
1
1
  import {createProviderUsageCapture} from './provider-usage.mjs';
2
2
  // Read-only Claude process: edits are text proposals consumed by the protected host.
3
+ import {signalOwnedGroup} from './process-group-exit.mjs';
3
4
  import {spawn} from 'node:child_process';
4
5
  import {readFileSync} from 'node:fs';
5
6
  import {claudeBaseArgs,claudeEnvironment} from './worker-claude.mjs';
@@ -23,8 +24,10 @@ export function validateClaudeProposal(raw){
23
24
  shape(result,['status','value','edits']);
24
25
  const value=result.value,nullable=v=>v===null||typeof v==='string';
25
26
  need(value&&typeof value==='object','invalid_result');
26
- shape(value,['outcome',...['application','retrospective','reason'].filter(key=>Object.hasOwn(value,key))]);
27
+ shape(value,['outcome',...['application','retrospective','reason','requirements'].filter(key=>Object.hasOwn(value,key))]);
27
28
  need(['implemented','blocked'].includes(value.outcome),'invalid_result');
29
+ // The per-requirement report is validated where the host splits it off (requirement-evidence.mjs).
30
+ if(Object.hasOwn(value,'requirements'))need(value.requirements===null||Array.isArray(value.requirements)&&value.requirements.length<=64,'invalid_result');
28
31
  if(Object.hasOwn(value,'reason'))need(nullable(value.reason),'invalid_result');
29
32
  if(Object.hasOwn(value,'application')){
30
33
  shape(value.application,['status','note']);
@@ -54,6 +57,18 @@ export function validateClaudeProposal(raw){
54
57
  return result;
55
58
  }
56
59
 
60
+ // Error classes of Claude CLI 2.1.x API failures (as the reviewer stream maps them,
61
+ // claude-review-stream.mjs). A provider developer that hits one ends with the class
62
+ // as its code; the provider text is never kept. The terminal status is unchanged.
63
+ const DEVELOPER_API_ERROR_CLASSES=Object.freeze({authentication_failed:'developer_auth_failed',
64
+ billing_error:'developer_billing_error',rate_limit:'developer_rate_limited',
65
+ server_error:'developer_server_error',model_not_found:'developer_model_not_found'});
66
+ const STARTUP_NOTICES=new Set(['dev_intent','ui_invalidate']);
67
+ function startupNotice(subtype,onNotice){
68
+ if(subtype==='dev_intent')return reportClaudeDevIntentNotice(onNotice);
69
+ if(typeof onNotice!=='function')return;
70
+ try{onNotice({kind:'claude_system_notice',subtype});}catch{}
71
+ }
57
72
  function createClaudeDeveloperStream(onNotice=null,onUsageTerminal=null){
58
73
  let session=null,initialized=false,done=false,value,assistant=false,noticeCount=0,thinkingCount=0;
59
74
  const tools=new Set();
@@ -63,9 +78,11 @@ function createClaudeDeveloperStream(onNotice=null,onUsageTerminal=null){
63
78
  need(typeof event.session_id==='string'&&event.session_id.trim()&&event.session_id.length<=128,'invalid_session');
64
79
  if(session!==null)need(event.session_id===session,'session_mismatch');
65
80
  if(!initialized){
66
- if(event.type==='system'&&event.subtype==='dev_intent'){
81
+ // CLI 2.1.289 emits ui_invalidate before init, as the review stream
82
+ // already accepts. A notice never initializes the turn.
83
+ if(event.type==='system'&&STARTUP_NOTICES.has(event.subtype)){
67
84
  need(noticeCount<32,'unexpected_event');noticeCount++;
68
- session=event.session_id;reportClaudeDevIntentNotice(onNotice);return;
85
+ session=event.session_id;startupNotice(event.subtype,onNotice);return;
69
86
  }
70
87
  need(event.type==='system'&&event.subtype==='init','missing_init');
71
88
  session=event.session_id;initialized=true;return;
@@ -75,13 +92,19 @@ function createClaudeDeveloperStream(onNotice=null,onUsageTerminal=null){
75
92
  reportClaudeRateLimitNotice(event.rate_limit_info,onNotice);return;
76
93
  }
77
94
  if(event.type==='system'){
78
- if(event.subtype==='dev_intent'){
95
+ if(STARTUP_NOTICES.has(event.subtype)){
79
96
  need(noticeCount<32,'unexpected_event');noticeCount++;
80
- reportClaudeDevIntentNotice(onNotice);return;
97
+ startupNotice(event.subtype,onNotice);return;
81
98
  }
82
- need(event.subtype==='thinking_tokens'&&thinkingCount<64,'unexpected_event');thinkingCount++;return;
99
+ // Long developer turns emit one usage heartbeat per thinking step; same cap as the
100
+ // reviewer stream (claude-review-stream.mjs), with the 4 MB output limit behind it.
101
+ need(event.subtype==='thinking_tokens'&&thinkingCount<4096,'unexpected_event');thinkingCount++;return;
83
102
  }
84
103
  if(event.type==='assistant'){
104
+ // CLI 2.1.x reports an API failure as a synthetic assistant message carrying the
105
+ // error class, before any tool call; the is_error result follows.
106
+ if(typeof event.error==='string'&&event.parent_tool_use_id===null&&event.message?.role==='assistant'&&tools.size===0)
107
+ need(false,Object.hasOwn(DEVELOPER_API_ERROR_CLASSES,event.error)?DEVELOPER_API_ERROR_CLASSES[event.error]:'developer_api_error');
85
108
  need(event.parent_tool_use_id===null&&event.error==null&&event.message?.role==='assistant','unexpected_assistant');
86
109
  need(Array.isArray(event.message.content)&&event.message.content.length>0,'invalid_event');
87
110
  let substantive=false;
@@ -146,18 +169,19 @@ export function claudeDeveloperWorker({cwd,model,effort,cli='claude',timeoutMs=1
146
169
  let buffer='',bytes=0;
147
170
  const stream=createClaudeDeveloperStream(onNotice,value=>usage.terminal(value));
148
171
  let failure=null,closed=false,timer,cleanup;
149
- const signalGroup=signalName=>{
172
+ // signalOwnedGroup (process-group-exit.mjs): an exited, not yet reaped leader
173
+ // (EPERM on macOS) is a stop only once its exit is observed and a re-probe
174
+ // answers ESRCH; anything unproven is a cleanup failure, as before.
175
+ const signalGroup=async signalName=>{
150
176
  if(!Number.isInteger(child.pid)||child.pid<=0)return false;
151
- try{process.kill(-child.pid,signalName);return true;}
152
- catch(error){if(error.code!=='ESRCH')failure??='process_cleanup_failed';return false;}
177
+ try{return await signalOwnedGroup(child,signalName)==='sent';}
178
+ catch{failure??='process_cleanup_failed';return false;}
153
179
  };
154
- const cleanGroup=()=>{
155
- if(cleanup)return cleanup;
156
- if(!signalGroup('SIGTERM'))return cleanup=Promise.resolve();
180
+ const cleanGroup=()=>cleanup??=(async()=>{
181
+ if(!await signalGroup('SIGTERM'))return;
157
182
  // Keep escalation alive even when the leader closes its own pipes first.
158
- cleanup=new Promise(done=>setTimeout(()=>{signalGroup('SIGKILL');done();},1000));
159
- return cleanup;
160
- };
183
+ await new Promise(done=>setTimeout(done,1000));await signalGroup('SIGKILL');
184
+ })();
161
185
  const stop=code=>{
162
186
  failure??=code;
163
187
  if(closed)return;
@@ -1,4 +1,5 @@
1
1
  import {createProviderUsageCapture} from './provider-usage.mjs';
2
+ import {VERIFICATION_TOOLS,readReviewVerification} from '../cm-fix/review-verification-contract.mjs';
2
3
  import {externalEffort} from './external-models.mjs';
3
4
  import {spawn} from 'node:child_process';
4
5
  import {createHash} from 'node:crypto';
@@ -15,21 +16,33 @@ export function claudeBaseArgs(model,effort=null) {
15
16
  '--permission-mode','dontAsk','--no-chrome','--no-session-persistence',
16
17
  '--prompt-suggestions','false'];
17
18
  }
18
- export function claudeReviewArgs(model,effort=null) {
19
+ export function claudeReviewArgs(model,effort=null,verification=null,transport=null) {
19
20
  const args=claudeBaseArgs(model,effort);
21
+ if(verification){
22
+ readReviewVerification(verification);
23
+ // safe-mode suppresses even explicitly configured MCP servers. Restricted
24
+ // mode keeps native tools disabled while allowing this fixed stdio server.
25
+ args[args.indexOf('--safe-mode')]='--restricted';
26
+ args.push('--settings',JSON.stringify({disableAllHooks:true,enabledPlugins:{},autoMemoryEnabled:false}));
27
+ args[args.indexOf('--mcp-config')+1]=transport?.mcpConfig??'CM_ISOLATED_REVIEW_TOOLS';
28
+ args.push('--allowedTools',...VERIFICATION_TOOLS);
29
+ }
20
30
  const schema=JSON.parse(readFileSync(new URL('./review-result.schema.json',import.meta.url),'utf8'));
21
31
  // Claude's schema engine does not accept the draft-2020-12 metadata.
22
32
  delete schema.$schema;delete schema.$id;
23
33
  return [...args,'--json-schema',JSON.stringify(schema)];
24
34
  }
25
- export function claudeReviewFingerprint({cwd,model,cli='claude',effort=null}) {
26
- return createHash('sha256').update(JSON.stringify({cwd,cli,args:claudeReviewArgs(model,effort),
35
+ export function claudeReviewFingerprint({cwd,model,cli='claude',effort=null,verification=null}) {
36
+ return createHash('sha256').update(JSON.stringify({cwd,cli,args:claudeReviewArgs(model,effort,verification),...(verification?{verification:readReviewVerification(verification)}:{}),
27
37
  environmentPolicy:1,promptTransport:'stdin'})).digest('hex');
28
38
  }
29
39
  export function claudeEnvironment() {
30
- const allowed=['PATH','HOME','USER','LOGNAME','TMPDIR','LANG','LC_ALL','ANTHROPIC_API_KEY'];
40
+ // CM_NOTIFY_OFF kept for the same reason as in cleanEnvironment (codex-config.mjs).
41
+ const allowed=['PATH','HOME','USER','LOGNAME','TMPDIR','LANG','LC_ALL','ANTHROPIC_API_KEY','CM_NOTIFY_OFF'];
31
42
  return {...Object.fromEntries(Object.entries(process.env).filter(([key])=>allowed.includes(key))),
32
- CLAUDE_CODE_MAX_RETRIES:'0',CLAUDE_CODE_RETRY_WATCHDOG:'0'};
43
+ CLAUDE_CODE_MAX_RETRIES:'0',CLAUDE_CODE_RETRY_WATCHDOG:'0',
44
+ // CM's own sessions are not a person typing: the skill-hints hook stays out of them.
45
+ CM_SKILL_HINTS:'off'};
33
46
  }
34
47
  export function claudePreflightMatches(receipt,options) {
35
48
  return receipt?.passed===true && receipt.provider==='claude'
@@ -39,16 +52,17 @@ export function claudePreflightMatches(receipt,options) {
39
52
  // Diagnostic receipt is NOT authorization. Only the original V3 owner may dispatch this worker.
40
53
  // A matching diagnostic receipt remains required separately from the V3 grant.
41
54
  export function claudeWorker({cwd,model,preflight,cli='claude',timeoutMs=60000,spawnProcess=spawn,effort=null,
42
- killProcess=(pid,signal)=>process.kill(pid,signal),onNotice=null,onUsage=null,onUsageClaim=null}) {
43
- const args=claudeReviewArgs(model,effort);
55
+ killProcess=(pid,signal)=>process.kill(pid,signal),onNotice=null,onDiagnostic=null,onUsage=null,onUsageClaim=null,verification=null,verificationTransport=null}) {
56
+ const args=claudeReviewArgs(model,effort,verification,verificationTransport);
44
57
  if (!Number.isSafeInteger(timeoutMs)||timeoutMs<1) throw new Error('invalid_timeout');
45
58
  let used=false;
46
59
  return async (request,{signal,onEvent,onTerminal})=>{
47
60
  if (process.platform==='win32') return {status:'blocked',code:'unsupported_process_cleanup'};
48
61
  if (used) return {status:'blocked',code:'worker_dispatch_limit'};
49
- if (!claudePreflightMatches(preflight,{cwd,model,cli,effort})) {
62
+ if (!claudePreflightMatches(preflight,{cwd,model,cli,effort,verification})) {
50
63
  return {status:'blocked',code:'tool_preflight_missing'};
51
64
  }
65
+ if (verification&&!verificationTransport?.mcpConfig) return {status:'blocked',code:'review_verification_transport_missing'};
52
66
  if (signal.aborted) return {status:'cancelled',code:'cancelled_before_dispatch'};
53
67
  if (typeof request?.prompt!=='string') return {status:'failed',code:'invalid_prompt'};
54
68
  used=true;
@@ -56,10 +70,17 @@ export function claudeWorker({cwd,model,preflight,cli='claude',timeoutMs=60000,s
56
70
  try{onUsageClaim?.();}catch{}
57
71
  return new Promise(resolve=>{
58
72
  let child;
59
- try { child=spawnProcess(cli,args,{cwd,env:claudeEnvironment(),stdio:['pipe','pipe','pipe'],detached:true}); }
73
+ try { child=spawnProcess(cli,args,{cwd:verificationTransport?.cwd??cwd,env:claudeEnvironment(),stdio:['pipe','pipe','pipe'],detached:true}); }
60
74
  catch { usage.complete();resolve({status:'failed',code:'spawn_failed'});return; }
61
75
  let buffer='', bytes=0, failure=null, settled=false, timedOut=false, killTimer, pendingClose;
62
- let providerThread=null,providerTerminal=false,failedTerminal=false,receiptInvalid=false,failureDetail=null;
76
+ let providerThread=null,providerTerminal=false,failedTerminal=false,receiptInvalid=false,failureDetail=null,diagnosticReported=false;
77
+ // Optional, body-free diagnostics are separate from the strict observation
78
+ // receipt. Neither a callback nor its failure can change provider outcome.
79
+ const reportDiagnostic=error=>{
80
+ if(diagnosticReported||failure!==null||!error?.failureDetail)return;
81
+ diagnosticReported=true;
82
+ try{if(typeof onDiagnostic==='function')onDiagnostic({code:error.code,failureDetail:error.failureDetail});}catch{}
83
+ };
63
84
  // The boundary code carries the stream's body-free summary so the record
64
85
  // shows what was rejected; stop() and callers keep matching the base code.
65
86
  const withDetail=code=>code==='unexpected_tool_or_content'&&failureDetail!==null
@@ -73,7 +94,7 @@ export function claudeWorker({cwd,model,preflight,cli='claude',timeoutMs=60000,s
73
94
  if(event.event==='thread.started')providerThread=event.provider_thread;
74
95
  if(event.event==='turn.completed')providerTerminal=true;
75
96
  onEvent(event);
76
- },onNotice);
97
+ },onNotice,verification?VERIFICATION_TOOLS:[]);
77
98
  const stop=code=>{
78
99
  if(!['cancelled','timeout','provider_failed','reviewer_auth_failed','reviewer_billing_error',
79
100
  'reviewer_rate_limited','reviewer_server_error','reviewer_model_not_found','reviewer_api_error'].includes(code))receiptInvalid=true;
@@ -115,6 +136,7 @@ export function claudeWorker({cwd,model,preflight,cli='claude',timeoutMs=60000,s
115
136
  stream.accept(message);
116
137
  }
117
138
  catch (error) {
139
+ reportDiagnostic(error);
118
140
  if(failure===null&&error?.code==='unexpected_tool_or_content'&&error.detail)failureDetail=error.detail;
119
141
  stop(error instanceof SyntaxError?'invalid_event':error.code??'invalid_event');
120
142
  }
@@ -139,7 +161,7 @@ export function claudeWorker({cwd,model,preflight,cli='claude',timeoutMs=60000,s
139
161
  if (buffer.trim()) accept(buffer);
140
162
  pendingClose=async()=>{
141
163
  settled=true;clean();
142
- if(typeof onTerminal==='function')try{await cleanupGroup();}catch{failure='process_cleanup_unknown';}
164
+ if(verification||typeof onTerminal==='function')try{await cleanupGroup();}catch{failure='process_cleanup_unknown';}
143
165
  usage.complete();
144
166
  onEvent({event:'process_closed',exit_code:code,signal:exitSignal,timed_out:timedOut});
145
167
  if(failure==='process_cleanup_unknown'){resolve({status:'failed',code:failure});return;}
@@ -152,7 +174,7 @@ export function claudeWorker({cwd,model,preflight,cli='claude',timeoutMs=60000,s
152
174
  resolve({status:'failed',code:withDetail(failure??'incomplete_result')});return;
153
175
  }
154
176
  try {resolve(stream.finish());}
155
- catch(error){resolve({status:'failed',code:error.code??'incomplete_result'});}
177
+ catch(error){reportDiagnostic(error);resolve({status:'failed',code:error.code??'incomplete_result'});}
156
178
  };
157
179
  // Leader close does not prove group cleanup: redirected descendant pipes may close early.
158
180
  if (!killTimer) pendingClose();
@@ -1,10 +1,15 @@
1
1
  import {createProviderUsageCapture} from './provider-usage.mjs';
2
2
  // Coding subprocess only. The host must authorize the task and select an isolated
3
3
  // code workspace; workspace-write is not a per-file scope enforcement mechanism.
4
+ import {signalOwnedGroup} from './process-group-exit.mjs';
4
5
  import {spawn} from 'node:child_process';
5
6
  import {fileURLToPath} from 'node:url';
6
7
  import {commonArgs,cleanEnvironment,specsPermissionArgs} from './codex-config.mjs';
7
8
  import {need,text,validCallTimeout,json} from './effect-contract.mjs';
9
+ import {CODEX_RECONNECT_NOTICE_LIMIT,isCodexReconnectNotice} from './codex-reconnect-notice.mjs';
10
+ import {codexRateLimited,CODEX_FAILURE_GRACE_MS} from './worker-codex.mjs';
11
+ // A provider terminal (failed turn) still lets the usage of a later turn.failed through.
12
+ const PROVIDER_ENDED=new Set(['provider_failed']);
8
13
 
9
14
  export function developerArgs({cwd,model,effort,schemaPath,disabledSkills=[],specsRoot=null}) {
10
15
  text(cwd);text(schemaPath);
@@ -49,19 +54,20 @@ export function codexDeveloperWorker({cwd,model,effort,learning=true,specsRoot=n
49
54
  try{child=spawnProcess(cli,args,{cwd,env:cleanEnvironment(),stdio:['pipe','pipe','pipe'],shell:false,detached:true});}
50
55
  catch{usage.complete();resolve({status:'unavailable',code:'spawn_failed'});return;}
51
56
  let buffer='',bytes=0,thread=null,turnStarted=false,completed=false,lastMessage=null;
52
- let failure=null,closed=false,timer,cleanup,noticeCount=0;
53
- const signalGroup=signalName=>{
57
+ let failure=null,providerFailed=false,closed=false,timer,failureGrace,cleanup,noticeCount=0,reconnectNoticeCount=0,rateLimited=false;
58
+ // signalOwnedGroup (process-group-exit.mjs): an exited, not yet reaped leader
59
+ // (EPERM on macOS) is a stop only once its exit is observed and a re-probe
60
+ // answers ESRCH; anything unproven is a cleanup failure, as before.
61
+ const signalGroup=async signalName=>{
54
62
  if(!Number.isInteger(child.pid)||child.pid<=0)return false;
55
- try{process.kill(-child.pid,signalName);return true;}
56
- catch(error){if(error.code!=='ESRCH')failure??='process_cleanup_failed';return false;}
63
+ try{return await signalOwnedGroup(child,signalName)==='sent';}
64
+ catch{failure??='process_cleanup_failed';return false;}
57
65
  };
58
- const cleanGroup=()=>{
59
- if(cleanup)return cleanup;
60
- if(!signalGroup('SIGTERM'))return cleanup=Promise.resolve();
66
+ const cleanGroup=()=>cleanup??=(async()=>{
67
+ if(!await signalGroup('SIGTERM'))return;
61
68
  // Keep escalation alive even when the leader closes its own pipes first.
62
- cleanup=new Promise(done=>setTimeout(()=>{signalGroup('SIGKILL');done();},1000));
63
- return cleanup;
64
- };
69
+ await new Promise(done=>setTimeout(done,1000));await signalGroup('SIGKILL');
70
+ })();
65
71
  const stop=code=>{
66
72
  failure??=code;
67
73
  if(closed)return;
@@ -72,12 +78,29 @@ export function codexDeveloperWorker({cwd,model,effort,learning=true,specsRoot=n
72
78
  timer=setTimeout(()=>stop('timeout'),timeoutMs);
73
79
  if(signal.aborted)abort();
74
80
  const accept=line=>{
75
- if(!line.trim()||failure&&failure!=='provider_failed')return;
81
+ if(!line.trim()||failure&&!PROVIDER_ENDED.has(failure))return;
76
82
  let event;try{event=JSON.parse(line);}catch{stop('invalid_event');return;}
77
83
  if(!event||Array.isArray(event)||typeof event.type!=='string'){stop('invalid_event');return;}
78
84
  if(event.type==='turn.failed'&&thread&&turnStarted&&!completed)usage.terminal(event.usage);
79
- if(failure==='provider_failed')return;
80
- if(event.type==='error'||event.type==='turn.failed'){stop('provider_failed');return;}
85
+ // Like the Codex reviewer (worker-codex.mjs): every failure event of the turn,
86
+ // the first or a later one, may name the rate limit; only the class is kept.
87
+ if((event.type==='error'&&!isCodexReconnectNotice(event)||event.type==='turn.failed')&&codexRateLimited(event))rateLimited=true;
88
+ // After a provider failure only further failure lines count: they stop at once.
89
+ if(providerFailed||PROVIDER_ENDED.has(failure)){
90
+ if(event.type==='turn.failed'||event.type==='error'&&!isCodexReconnectNotice(event))stop('provider_failed');
91
+ return;
92
+ }
93
+ // Reconnects may precede thread initialization, but never bypass a
94
+ // completed turn. Keep their budget separate from item notices.
95
+ if(!completed&&isCodexReconnectNotice(event)&&reconnectNoticeCount<CODEX_RECONNECT_NOTICE_LIMIT){
96
+ reconnectNoticeCount++;
97
+ try{if(typeof onNotice==='function')onNotice(event.message.slice(0,200));}catch{}
98
+ return;
99
+ }
100
+ // A lone error waits a short grace for the turn.failed that may name the class.
101
+ if(event.type==='turn.failed'){stop('provider_failed');return;}
102
+ // The fact is kept apart from failure, so a cancel or timeout in the grace keeps its code.
103
+ if(event.type==='error'){providerFailed=true;if(!closed)failureGrace=setTimeout(()=>stop('provider_failed'),CODEX_FAILURE_GRACE_MS);return;}
81
104
  if(completed){
82
105
  stop(event.type==='item.completed'&&event.item?.type==='error'?'invalid_event':'event_after_terminal');return;
83
106
  }
@@ -113,7 +136,7 @@ export function codexDeveloperWorker({cwd,model,effort,learning=true,specsRoot=n
113
136
  child.stderr.resume();
114
137
  child.stdout.setEncoding('utf8');
115
138
  child.stdout.on('data',chunk=>{
116
- if(failure&&failure!=='provider_failed'||closed)return;
139
+ if(failure&&!PROVIDER_ENDED.has(failure)||closed)return;
117
140
  bytes+=Buffer.byteLength(chunk);if(bytes>4*1024*1024){stop('output_limit');return;}
118
141
  buffer+=chunk;let index;
119
142
  while((index=buffer.indexOf('\n'))!==-1){accept(buffer.slice(0,index));buffer=buffer.slice(index+1);}
@@ -125,12 +148,15 @@ export function codexDeveloperWorker({cwd,model,effort,learning=true,specsRoot=n
125
148
  // Background commands must not outlive a normally exiting coding leader.
126
149
  child.once('exit',()=>{cleanGroup();});
127
150
  child.once('close',async(code,exitSignal)=>{
128
- closed=true;clearTimeout(timer);signal.removeEventListener('abort',abort);
151
+ closed=true;clearTimeout(timer);clearTimeout(failureGrace);signal.removeEventListener('abort',abort);
129
152
  await cleanGroup();
130
153
  if(buffer.trim())accept(buffer);
131
154
  usage.complete();
132
- if(failure||code!==0||exitSignal||!completed||lastMessage===null){
133
- resolve({status:failure==='spawn_failed'?'unavailable':'unknown',code:failure??'incomplete_result'});return;
155
+ const ended=failure??(providerFailed?'provider_failed':null);
156
+ if(ended||code!==0||exitSignal||!completed||lastMessage===null){
157
+ // provider_failed stays the internal terminal; the published code names a rate limit.
158
+ resolve({status:ended==='spawn_failed'?'unavailable':'unknown',
159
+ code:ended==='provider_failed'&&rateLimited?'developer_rate_limited':ended??'incomplete_result'});return;
134
160
  }
135
161
  try{resolve({status:'succeeded',value:json(JSON.parse(lastMessage)),providerThread:thread});}
136
162
  catch{resolve({status:'unknown',code:'invalid_output_json'});}
@@ -2,6 +2,7 @@ import {createProviderUsageCapture} from './provider-usage.mjs';
2
2
  import { spawn } from 'node:child_process';
3
3
  import { commonArgs, cleanEnvironment, configFingerprint } from './codex-config.mjs';
4
4
  import {ownedProcessCleanup} from './owned-process-cleanup.mjs';
5
+ import {CODEX_RECONNECT_NOTICE_LIMIT,isCodexReconnectNotice} from './codex-reconnect-notice.mjs';
5
6
 
6
7
  // A preflight receipt is diagnostic evidence, not a human approval token.
7
8
  export function preflightMatches(receipt, options) {
@@ -28,6 +29,18 @@ function validEventShape(message) {
28
29
  return true;
29
30
  }
30
31
 
32
+ // A failed turn whose provider text names HTTP 429 / Too Many Requests / a rate
33
+ // limit is the same class the Claude reviewer reports (reviewer_rate_limited).
34
+ // Only the class leaves this file; the provider text is never kept or published.
35
+ const RATE_LIMITED=/(?<![0-9])429(?![0-9])|too many requests|rate[ _-]?limit/i;
36
+ const failureText=message=>message.type==='error'?message.message:message.error?.message;
37
+ export const codexRateLimited=message=>{const text=failureText(message);
38
+ return typeof text==='string'&&RATE_LIMITED.test(text.slice(0,2000));};
39
+
40
+ // Codex can write the generic error line before the turn.failed naming the class
41
+ // (e.g. a 429). A lone error waits this long for it before the group is stopped.
42
+ export const CODEX_FAILURE_GRACE_MS=2000;
43
+
31
44
  export function codexWorker({ cwd, model, schemaPath, preflight, effort='high',
32
45
  disabledSkills = [], cli = 'codex', timeoutMs = 60000,
33
46
  promptTransport = 'argument', spawnProcess = spawn, onNotice = null,onUsage=null,onUsageClaim=null }) {
@@ -47,8 +60,10 @@ export function codexWorker({ cwd, model, schemaPath, preflight, effort='high',
47
60
  });
48
61
  const cleanupGroup=ownedProcessCleanup(child);
49
62
  let buffer = '', outputBytes = 0, value, completion = false, failure, settled = false;
50
- let failureTerminal = false, noticeCount = 0, receiptInvalid=false;
51
- let providerThread, turnStarted = false, usageContextInvalid=false, timedOut = false, closeTimer, closing=false, terminationRequested=false;
63
+ let failureTerminal = false, noticeCount = 0, reconnectNoticeCount = 0, receiptInvalid=false, rateLimited=false;
64
+ // provider_failed stays the internal code; the published one names the class.
65
+ const published=code=>code==='provider_failed'&&rateLimited?'reviewer_rate_limited':code;
66
+ let failureGrace, providerFailed = false, providerThread, turnStarted = false, usageContextInvalid=false, timedOut = false, closeTimer, closing=false, terminationRequested=false;
52
67
  const cleanup=()=>process.platform==='win32'&&!terminationRequested?Promise.resolve():
53
68
  cleanupGroup().catch(()=>{failure='process_cleanup_unknown';});
54
69
  const stop = code => {
@@ -73,6 +88,15 @@ export function codexWorker({ cwd, model, schemaPath, preflight, effort='high',
73
88
  let message;
74
89
  try { message = JSON.parse(line); } catch { stop('invalid_event'); return; }
75
90
  if (!validEventShape(message)) { stop('invalid_event'); return; }
91
+ // While a lone error waits for its turn.failed, only further failure lines count.
92
+ if (failureGrace !== undefined && message.type !== 'turn.failed' && message.type !== 'error') return;
93
+ // Codex emits reconnect notices as errors but may subsequently recover.
94
+ // Keep a separate bounded notice budget; overflow follows fatal handling.
95
+ if (isCodexReconnectNotice(message) && reconnectNoticeCount < CODEX_RECONNECT_NOTICE_LIMIT) {
96
+ reconnectNoticeCount++;
97
+ try { if (typeof onNotice === 'function') onNotice(message.message.slice(0, 200)); } catch {}
98
+ return;
99
+ }
76
100
  // Notices stay outside the observer protocol and result contract.
77
101
  if (message.type === 'item.completed' && message.item.type === 'error') {
78
102
  if (typeof message.item.message !== 'string' || !providerThread
@@ -93,6 +117,7 @@ export function codexWorker({ cwd, model, schemaPath, preflight, effort='high',
93
117
  }
94
118
  if (message.type === 'turn.started') {if(!providerThread)usageContextInvalid=true;turnStarted = true;}
95
119
  const isFailureTerminal = message.type === 'turn.failed' || message.type === 'error';
120
+ if (isFailureTerminal && codexRateLimited(message)) rateLimited = true;
96
121
  // The generic error notice can precede the official turn.failed event.
97
122
  // Preserve one normalized failure, while accounting only native terminals.
98
123
  if(message.type==='turn.failed'&&providerThread&&turnStarted&&!completion&&!usageContextInvalid)usage.terminal(message.usage);
@@ -113,7 +138,16 @@ export function codexWorker({ cwd, model, schemaPath, preflight, effort='high',
113
138
  try { value = JSON.parse(message.item.text); } catch { stop('invalid_output_json'); }
114
139
  }
115
140
  if (message.type === 'turn.completed') {completion = true;if(providerThread&&turnStarted&&!failureTerminal&&!usageContextInvalid)usage.terminal(message.usage);}
116
- if (isFailureTerminal) stop('provider_failed');
141
+ // A turn.failed (or a second failure line, above) stops at once; a lone error
142
+ // stops after the grace, so a turn.failed written right after it is still read.
143
+ if (isFailureTerminal) {
144
+ if (message.type === 'turn.failed') stop('provider_failed');
145
+ else {
146
+ // Kept apart from failure, so a cancel or timeout in the grace keeps its code.
147
+ providerFailed = true;
148
+ if (!closing) failureGrace ??= setTimeout(() => stop('provider_failed'), CODEX_FAILURE_GRACE_MS);
149
+ }
150
+ }
117
151
  }
118
152
  child.stdout.on('data', chunk => {
119
153
  if (settled) return;
@@ -126,7 +160,7 @@ export function codexWorker({ cwd, model, schemaPath, preflight, effort='high',
126
160
  }
127
161
  });
128
162
  const clean = () => {
129
- clearTimeout(timer); clearTimeout(closeTimer); signal.removeEventListener('abort', onAbort);
163
+ clearTimeout(timer); clearTimeout(closeTimer); clearTimeout(failureGrace); signal.removeEventListener('abort', onAbort);
130
164
  };
131
165
  child.once('error', async () => {
132
166
  if(settled)return;settled=true;closing=true;clean();await cleanup();
@@ -145,12 +179,12 @@ export function codexWorker({ cwd, model, schemaPath, preflight, effort='high',
145
179
  // Windows/direct-child exit and uncertain cleanup cannot issue this receipt.
146
180
  if(process.platform!=='win32'&&failure!=='process_cleanup_unknown'&&!receiptInvalid&&typeof onTerminal==='function'){
147
181
  if(completion&&providerThread&&value!==undefined)onTerminal({status:'succeeded',value});
148
- else if(failureTerminal&&providerThread)onTerminal({status:'failed',code:'provider_failed'});
182
+ else if(failureTerminal&&providerThread)onTerminal({status:'failed',code:published('provider_failed')});
149
183
  }
150
184
  if(failure==='process_cleanup_unknown')resolve({status:'failed',code:failure});
151
185
  else if (signal.aborted) resolve({ status: 'cancelled', code: 'cancelled' });
152
- else if (failure || code !== 0 || !completion || !providerThread || value === undefined) {
153
- resolve({ status: 'failed', code: failure ?? 'incomplete_result' });
186
+ else if (failure || providerFailed || code !== 0 || !completion || !providerThread || value === undefined) {
187
+ resolve({ status: 'failed', code: published(failure ?? (providerFailed ? 'provider_failed' : 'incomplete_result')) });
154
188
  } else resolve({ status: 'succeeded', value });
155
189
  });
156
190
  if(promptTransport==='stdin'){
@@ -1,3 +1,5 @@
1
+ import {inspectVerificationDiagnostic} from './review-verification-diagnostic.mjs';
2
+ import {readReviewVerification,inspectReviewVerificationEvidence} from './review-verification-contract.mjs';
1
3
  import {inspectFixReconciledResult} from './review-reconciliation.mjs';
2
4
  // Shared V3 grant and normalized observation contracts; no completion receipt issuer.
3
5
  import {validateReviewDispatchGrant} from '../cm-ai/durable-runner-state.mjs';
@@ -50,11 +52,23 @@ export function inspectCauseRegistration(raw,configuration){
50
52
  return value;
51
53
  }
52
54
  export function inspectCauseResult(raw,registration,configuration,started){
53
- const value=json(raw,1024*1024);shape(value,['dispatchAt','observation',...(Object.hasOwn(value,'reconciliationReceipt')?['reconciliationReceipt']:[])]);
55
+ const value=json(raw,1024*1024);shape(value,['dispatchAt','observation',...(Object.hasOwn(value,'reconciliationReceipt')?['reconciliationReceipt']:[]),...(Object.hasOwn(value,'verification')?['verification']:[]),...(Object.hasOwn(value,'verificationDiagnostic')?['verificationDiagnostic']:[])]);
54
56
  need(Number.isSafeInteger(value.dispatchAt)&&value.dispatchAt>=registration.registeredAt
55
57
  &&value.dispatchAt<registration.grant.expiresAt,'cause_registration_mismatch');
56
58
  need(!value.reconciliationReceipt||(configuration.externalModels||configuration.executionPolicy),'review_reconciliation_unavailable');
57
59
  const expected=causeExpectation(registration.request,configuration);
58
60
  const result=value.reconciliationReceipt?inspectFixReconciledResult(value,expected,true):inspectProviderCauseReview(JSON.stringify(value.observation),JSON.stringify(expected));
59
- need(result.providerThreadId===started,'cause_registration_mismatch');return result;
61
+ need(result.providerThreadId===started,'cause_registration_mismatch');
62
+ if(configuration.reviewVerification){
63
+ readReviewVerification(configuration.reviewVerification);
64
+ need(!value.reconciliationReceipt,'review_verification_invalid');
65
+ if(result.observationStatus==='completed'||Object.hasOwn(value,'verification'))
66
+ inspectReviewVerificationEvidence(value.verification,{request:registration.request,configuration:configuration.reviewVerification,providerThreadId:started});
67
+ }else need(!Object.hasOwn(value,'verification'),'review_verification_invalid');
68
+ if(Object.hasOwn(value,'verificationDiagnostic')){
69
+ need(configuration.reviewVerification&&result.observationStatus!=='completed','review_verification_invalid');
70
+ const diagnostic=inspectVerificationDiagnostic(value.verificationDiagnostic,{request:registration.request,configuration:configuration.reviewVerification,providerThreadId:started});
71
+ return {...result,verificationDiagnostic:diagnostic};
72
+ }
73
+ return result;
60
74
  }
@@ -7,6 +7,42 @@ import {inspectFixReproductionAttempts} from './reproduce.mjs';
7
7
  import {inspectFixTestAuthor} from './test-author.mjs';
8
8
  import {inventory} from './test-extension.mjs';
9
9
  import {inspectVisualCarrier} from './visual.mjs';
10
+ import {inspectFixDiagnosis} from './diagnosis.mjs';
11
+
12
+ // A module-only correction is separate evidence, never a rewritten diagnosis or
13
+ // permission to change the code scope. The owner binds the target to history;
14
+ // every cause package carries both the original answer and that exact binding.
15
+ export function readDiagnosisModuleCorrection(raw,{identity,diagnosis}={}){
16
+ const value=json(raw,128*1024);
17
+ shape(value,['originalDiagnosis','target','reason','previousInvocationStopped','correctionDigest']);
18
+ const original=inspectFixDiagnosis(value.originalDiagnosis),t=value.target;
19
+ shape(t,['identity','configurationDigest','historyDigest','diagnosisRecordDigest','diagnosisDigest',
20
+ 'reproductionDigest','walkthroughDigest','originalModules','modules','files','snapshotDigest']);
21
+ validIdentity(t.identity);
22
+ need(original.status==='diagnosed'&&value.previousInvocationStopped===true
23
+ &&typeof value.reason==='string'&&value.reason.trim().length>0&&Buffer.byteLength(value.reason)<=1000
24
+ &&!/[\r\n\0\u0085\u2028\u2029]/.test(value.reason),'fix_diagnosis_module_correction_binding');
25
+ need(['configurationDigest','historyDigest','diagnosisRecordDigest','diagnosisDigest','reproductionDigest','walkthroughDigest','snapshotDigest']
26
+ .every(key=>typeof t[key]==='string'&&/^[a-f0-9]{64}$/.test(t[key])),'fix_diagnosis_module_correction_binding');
27
+ const corrected=inspectFixDiagnosis({...original,affectedModules:t.modules});
28
+ need(digest(t.modules)===digest([...new Set(t.modules)].sort())
29
+ &&digest(t.originalModules)===digest(original.affectedModules)
30
+ &&t.originalModules.length<t.modules.length&&t.originalModules.every(module=>t.modules.includes(module))
31
+ &&t.diagnosisDigest===digest(original),'fix_diagnosis_module_correction_binding');
32
+ need(Array.isArray(t.files)&&t.files.length>0&&t.files.length<=32
33
+ &&digest(t.files.map(file=>file.path))===digest([...original.affectedPaths].sort()),'fix_diagnosis_module_correction_binding');
34
+ for(const file of t.files){
35
+ shape(file,['path','type','mode','size','sha256']);
36
+ need(file.type==='file'&&Number.isInteger(file.mode)&&file.mode>=0&&file.mode<=511
37
+ &&Number.isSafeInteger(file.size)&&file.size>=0&&file.size<=1024*1024
38
+ &&typeof file.sha256==='string'&&/^[a-f0-9]{64}$/.test(file.sha256),'fix_diagnosis_module_correction_binding');
39
+ }
40
+ need(t.snapshotDigest===digest(t.files)&&value.correctionDigest===digest({target:t,reason:value.reason,
41
+ previousInvocationStopped:value.previousInvocationStopped}),'fix_diagnosis_module_correction_binding');
42
+ if(identity!==undefined)need(digest(t.identity)===digest(identity),'fix_diagnosis_module_correction_binding');
43
+ if(diagnosis!==undefined)need(digest(corrected)===digest(diagnosis),'fix_diagnosis_module_correction_binding');
44
+ return value;
45
+ }
10
46
 
11
47
  export const rediagnosisPackage=value=>({historyDigest:value.historyDigest,priorPackageDigest:value.priorPackageDigest,
12
48
  priorObservationDigest:value.priorObservationDigest,reason:value.reason,reviewFeedback:value.reviewFeedback});
@@ -32,8 +68,10 @@ export function createFixCausePackage({codeProject,defect,status,context=true}){
32
68
  const contextFiles=context&&status.rediagnosis?readContextFiles(codeProject,status.rediagnosis.reviewFeedback,status.diagnosis.affectedPaths):[];
33
69
  const value=json({version:1,kind:'cm-fix-cause-review-package',identity:status.identity,defect,
34
70
  reproduction:status.reproduction,diagnosis:status.diagnosis,learning:status.learning,
71
+ ...(status.diagnosisModuleCorrection?{diagnosisModuleCorrection:readDiagnosisModuleCorrection(status.diagnosisModuleCorrection,{identity:status.identity,...(!status.rediagnosis?{diagnosis:status.diagnosis}:{})})}:{}),
35
72
  ...(status.rediagnosis?{rediagnosis:rediagnosisPackage(status.rediagnosis)}:{}),
36
73
  ...(status.causeReviewCorrection?{correction:status.causeReviewCorrection}:{}),
74
+ ...(status.sourceRevision?{sourceRevision:status.sourceRevision}:{}),
37
75
  files:readReviewSourceFiles(codeProject,status.diagnosis.affectedPaths),...(contextFiles.length?{contextFiles}:{})},4*1024*1024);
38
76
  return json({...value,packageDigest:digest(value)},4*1024*1024);
39
77
  }
@@ -42,7 +80,14 @@ export function readFixCausePackage(raw){
42
80
  const value=json(raw,4*1024*1024);
43
81
  shape(value,['version','kind','identity','defect','reproduction','diagnosis','learning','files','packageDigest',
44
82
  ...(Object.hasOwn(value,'correction')?['correction']:[]),...(Object.hasOwn(value,'rediagnosis')?['rediagnosis']:[]),
45
- ...(Object.hasOwn(value,'contextFiles')?['contextFiles']:[])]);
83
+ ...(Object.hasOwn(value,'contextFiles')?['contextFiles']:[]),...(Object.hasOwn(value,'sourceRevision')?['sourceRevision']:[]),
84
+ ...(Object.hasOwn(value,'diagnosisModuleCorrection')?['diagnosisModuleCorrection']:[])]);
85
+ if(Object.hasOwn(value,'diagnosisModuleCorrection'))readDiagnosisModuleCorrection(value.diagnosisModuleCorrection,{identity:value.identity,...(!value.rediagnosis?{diagnosis:value.diagnosis}:{})});
86
+ if(value.sourceRevision){
87
+ shape(value.sourceRevision,['previousPackageDigest','correctionDigest','path','beforeSha256','afterSha256']);
88
+ const r=value.sourceRevision;need([r.previousPackageDigest,r.correctionDigest,r.beforeSha256,r.afterSha256].every(v=>typeof v==='string'&&/^[a-f0-9]{64}$/.test(v))
89
+ &&r.beforeSha256!==r.afterSha256&&value.files.some(f=>f.path===r.path&&f.sha256===r.afterSha256),'invalid_package');
90
+ }
46
91
  if(value.rediagnosis){
47
92
  shape(value.rediagnosis,['historyDigest','priorPackageDigest','priorObservationDigest','reason','reviewFeedback']);
48
93
  need([value.rediagnosis.historyDigest,value.rediagnosis.priorPackageDigest,value.rediagnosis.priorObservationDigest].every(v=>typeof v==='string'&&/^[a-f0-9]{64}$/.test(v)), 'invalid_package');
@@ -0,0 +1,37 @@
1
+ // Read-only qualification and immutable record validation for one startup correction.
2
+ import {digest,json,need,shape} from '../cm-ai/effect-contract.mjs';
3
+ import {verifyFixRedEvidence} from './red-test.mjs';
4
+ import {COMMAND_CORRECTION,correctionRow,deriveJestCorrection,readCorrectionConfig,correctionFiles} from './jest-command-correction.mjs';
5
+ export {COMMAND_CORRECTION,correctionRow};
6
+ export function inspectCommandCorrection(payload,{configuration,records,red}){
7
+ const p=json(payload,256*1024);shape(p,['target','reason','previousInvocationStopped']);
8
+ const t=p.target;shape(t,['configurationDigest','historyDigest','redResultDigest','outputSha256','declaration','configFile','commands','files','snapshotDigest']);
9
+ need(p.previousInvocationStopped===true&&typeof p.reason==='string'&&p.reason.trim()&&Buffer.byteLength(p.reason)<=1000&&!/[\r\n\0]/.test(p.reason),'fix_command_correction_confirmation');
10
+ need(!correctionRow(records)&&t.configurationDigest===digest(configuration)&&t.historyDigest===digest(records)
11
+ &&red?.status==='not_red'&&t.redResultDigest===digest(records.at(-1))&&records.at(-1).id==='fix-red-test-result'
12
+ &&t.outputSha256===red.output.sha256,'fix_command_correction_binding');
13
+ need(digest(t.commands)===digest(deriveJestCorrection(configuration,t.declaration,t.configFile))
14
+ &&t.commands.some(c=>c.id==='red-test'),'fix_command_correction_binding');
15
+ need(Array.isArray(t.files)&&t.snapshotDigest===digest(t.files),'fix_command_correction_binding');
16
+ const file=t.files.find(f=>f.path===t.configFile.path);need(file&&file.sha256===t.configFile.sha256&&file.mode===t.configFile.mode,'fix_command_correction_binding');
17
+ return p;
18
+ }
19
+ export function inspectCommandCorrectionTarget({configuration,records,status,specsRoot,declaration}){
20
+ need(!correctionRow(records),'fix_command_correction_used');
21
+ need(status.stage==='red_test_not_confirmed'&&status.redTest?.status==='not_red'
22
+ &&!configuration.qaSource&&!configuration.externalModels&&!configuration.executionPolicy,'fix_command_correction_unavailable');
23
+ const raw=verifyFixRedEvidence(status.redTest,configuration.redTest,specsRoot);
24
+ const stderr=Buffer.from(raw.stderrBase64,'base64').toString('utf8');
25
+ const stdout=Buffer.from(raw.stdoutBase64,'base64').toString('utf8');
26
+ need(status.redTest.output.complete===true&&status.redTest.observation.outcome==='failed'
27
+ &&!/(?:^|[\r\n])\s*(?:Test Suites|Tests):/m.test(stdout+'\n'+stderr)
28
+ &&status.redTest.observation.exitCode===1&&status.redTest.observation.signatureMatched===false
29
+ &&stderr.startsWith('Error: Could not find a config file based on provided values:')
30
+ &&stderr.includes(`cwd: "${configuration.redTest.cwd}"`),'fix_command_correction_unavailable');
31
+ const mutable=[...(configuration.repair?.scope??[]),...(configuration.redTest?.testFiles??[]),...(configuration.baseline?.testFiles??[])];
32
+ need(!mutable.includes(declaration.path),'fix_command_correction_config');
33
+ const configFile=readCorrectionConfig(configuration,declaration),commands=deriveJestCorrection(configuration,declaration,configFile),files=correctionFiles(configuration,declaration);
34
+ need(commands.every(c=>!c.before.includes('--')&&!c.before.includes('-c')),'fix_command_correction_config');
35
+ return {configurationDigest:digest(configuration),historyDigest:digest(records),redResultDigest:digest(records.at(-1)),outputSha256:status.redTest.output.sha256,
36
+ declaration:json(declaration),configFile,commands,files,snapshotDigest:digest(files)};
37
+ }
@@ -0,0 +1,12 @@
1
+ // Same serial steps for direct callers and the event-loop driven host.
2
+ import {setImmediate as yieldHost} from 'node:timers/promises';
3
+ export function runStepsSync(steps){
4
+ let result;
5
+ try{do{result=steps.next();}while(!result.done);return result.value;}
6
+ finally{if(!result?.done)steps.return();}
7
+ }
8
+ export async function runStepsCooperatively(steps){
9
+ let result;
10
+ try{do{await yieldHost();result=steps.next();}while(!result.done);return result.value;}
11
+ finally{if(!result?.done)steps.return();}
12
+ }