@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,61 @@
1
+ // Source/distribution checks only; model behavior is exercised separately.
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 {fileURLToPath} from 'node:url';
7
+ import test from 'node:test';
8
+
9
+ const root = fileURLToPath(new URL('..', import.meta.url));
10
+ const read = file => fs.readFileSync(path.join(root, file), 'utf8');
11
+ const entry = 'skills/cm-challenge/SKILL.md';
12
+
13
+ test('cm-challenge is discoverable through Pi, Codex and the thin Claude alias', () => {
14
+ const pkg = JSON.parse(read('package.json'));
15
+ assert.equal(pkg.pi.skills.filter(p => p === './skills/cm-challenge').length, 1);
16
+ assert.ok(pkg.files.includes('skills') && pkg.files.includes('runtime') && pkg.files.includes('compat'));
17
+ const plugin = JSON.parse(read('.codex-plugin/plugin.json'));
18
+ assert.equal(plugin.skills, './skills/');
19
+ const skill = read(entry);
20
+ assert.match(skill, /^---\nname: cm-challenge\ndescription: [^\n]+\n---\n/);
21
+ const alias = read('compat/claude-commands/cm-challenge.md');
22
+ assert.ok(alias.trim().split('\n').length <= 8);
23
+ assert.ok(alias.includes('skills/cm-challenge/SKILL.md'));
24
+ assert.ok(alias.includes('$ARGUMENTS'));
25
+ });
26
+
27
+ test('cm-challenge references resolve from a relocated package without personal Skills', t => {
28
+ const temp = fs.mkdtempSync(path.join(os.tmpdir(), 'cm-challenge-source-'));
29
+ t.after(() => fs.rmSync(temp, {recursive: true, force: true}));
30
+ for (const file of [entry, 'skills/cm-challenge/references/examples.md', 'runtime/steelman-review.md']) {
31
+ const target = path.join(temp, file);
32
+ fs.mkdirSync(path.dirname(target), {recursive: true});
33
+ fs.copyFileSync(path.join(root, file), target);
34
+ }
35
+ const skill = fs.readFileSync(path.join(temp, entry), 'utf8');
36
+ const refs = [...skill.matchAll(/`(\.\.\/[^`]+\.md)`|\]\((references\/[^)]+\.md)\)/g)]
37
+ .map(match => match[1] ?? match[2]);
38
+ assert.ok(refs.includes('../../runtime/steelman-review.md'), 'must reuse the shared reasoning contract');
39
+ assert.ok(refs.includes('references/examples.md'));
40
+ for (const ref of refs) {
41
+ const resolved = path.resolve(temp, path.dirname(entry), ref);
42
+ assert.ok(resolved.startsWith(`${temp}${path.sep}`));
43
+ assert.ok(fs.statSync(resolved).isFile(), ref);
44
+ }
45
+ assert.equal(fs.existsSync(path.join(temp, 'runtime/js')), false);
46
+ });
47
+
48
+ test('registered entry sets and documented count stay aligned', () => {
49
+ const pkg = JSON.parse(read('package.json'));
50
+ const entries = pkg.pi.skills.map(p => p.split('/').at(-1));
51
+ const validator = read('scripts/validate-public-repo.py').match(/CORE_SKILLS = \(([\s\S]*?)\n\)/)[1];
52
+ const registered = [...validator.matchAll(/"(cm-[a-z-]+)"/g)].map(m => m[1]);
53
+ assert.deepEqual([...registered].sort(), [...entries].sort());
54
+ const checker = read('scripts/cm-check-runtime.sh').match(/for name in (cm-[^;]+); do/)[1].split(' ');
55
+ assert.deepEqual([...checker].sort(), [...entries].sort());
56
+ assert.ok(read('README.md').includes(`入口目录与计数:${entries.length} 个核心入口`));
57
+ for (const name of entries) {
58
+ assert.ok(fs.existsSync(path.join(root, `skills/${name}/SKILL.md`)));
59
+ assert.ok(fs.existsSync(path.join(root, `compat/claude-commands/${name}.md`)));
60
+ }
61
+ });
@@ -2,7 +2,7 @@
2
2
  // guard (cm-ai-light-modules.test.mjs) imports operator-guidance.mjs from exactly this copy.
3
3
  export const CHECK_DRIVE_COPIED_FILES=Object.freeze([
4
4
  'scripts/cm-check-entry.mjs','scripts/cm-check-host.mjs','scripts/cm-check-drive.mjs',
5
- 'scripts/cm-workflow-config.mjs','runtime/js/cm-check/host.mjs','runtime/js/cm-ai/drive-core.mjs',
5
+ 'scripts/cm-workflow-config.mjs','runtime/js/cm-check/host.mjs','runtime/js/cm-ai/drive-core.mjs','runtime/js/cm-ai/drive-rate-limit.mjs',
6
6
  'runtime/js/cm-ai/operator-guidance.mjs','runtime/js/cm-ai/host-stage-observer.mjs',
7
7
  'runtime/js/cm-ai/host-tool-bridge.mjs','runtime/js/cm-ai/host-session.mjs','runtime/js/cm-ai/diagnostic-reason.mjs','runtime/js/cm-ai/effect-contract.mjs',
8
8
  'runtime/js/cm-ai/contracts.mjs','runtime/js/cm-init/draft-inspection.mjs','skills/cm-check/SKILL.md']);
@@ -287,6 +287,36 @@ for module in \
287
287
  task-owner.mjs task-runner.mjs worker-codex.mjs operator-guidance.mjs; do
288
288
  require_file "runtime/js/cm-ai/$module"
289
289
  done
290
+ # completion_rework is a paired producer/consumer contract, including transport.
291
+ CONTROL_POLICY_DOC="docs/cm-control-policy-v2.md"
292
+ if [ "$MODE" != "plugin" ]; then
293
+ CONTROL_POLICY_DOC="cm-workflow/docs/cm-control-policy-v2.md"
294
+ fi
295
+ for consumer in runtime/js/cm-ai/control-policy.mjs runtime/js/cm-ai/host-session.mjs \
296
+ runtime/js/cm-ai/cm-ai-conversation-entry.mjs scripts/cm-ai-drive.mjs "$CONTROL_POLICY_DOC"; do
297
+ grep -q 'completion_rework' "$ROOT/$consumer" || fail "missing completion_rework consumer: $consumer"
298
+ done
299
+ for consumer in runtime/js/cm-ai/task-runner.mjs runtime/js/cm-ai/durable-runner-state.mjs scripts/cm-ai-control-v2-drive.test.mjs; do
300
+ grep -q 'completion-rework-requested' "$ROOT/$consumer" || fail "missing completion rework journal pairing: $consumer"
301
+ done
302
+ grep -q 'cm-completion-rework-v1:' "$ROOT/scripts/cm-task-gate.mjs" || fail "missing native completion rework verifier"
303
+ require_file "scripts/cm-ai-development-rework.test.mjs"
304
+ for consumer in runtime/js/cm-ai/control-policy.mjs runtime/js/cm-ai/host-session.mjs \
305
+ runtime/js/cm-ai/cm-ai-conversation-entry.mjs scripts/cm-ai-drive.mjs "$CONTROL_POLICY_DOC"; do
306
+ grep -q 'development_rework' "$ROOT/$consumer" || fail "missing development rework consumer: $consumer"
307
+ done
308
+ for consumer in runtime/js/cm-ai/task-runner.mjs runtime/js/cm-ai/durable-runner-state.mjs scripts/cm-ai-development-rework.test.mjs; do
309
+ grep -q 'development-rework-authorized' "$ROOT/$consumer" || fail "missing development rework journal pairing: $consumer"
310
+ done
311
+ require_file "runtime/js/cm-ai/scope-revision.mjs"
312
+ require_file "scripts/cm-ai-scope-revision.test.mjs"
313
+ for consumer in runtime/js/cm-ai/control-policy.mjs runtime/js/cm-ai/host-session.mjs \
314
+ runtime/js/cm-ai/cm-ai-conversation-entry.mjs scripts/cm-ai-drive.mjs "$CONTROL_POLICY_DOC"; do
315
+ grep -q 'revise_scope' "$ROOT/$consumer" || fail "missing scope revision consumer: $consumer"
316
+ done
317
+ for consumer in runtime/js/cm-ai/task-runner.mjs runtime/js/cm-ai/durable-runner-state.mjs scripts/cm-ai-scope-revision.test.mjs; do
318
+ grep -q 'scope-revised' "$ROOT/$consumer" || fail "missing scope revision journal pairing: $consumer"
319
+ done
290
320
  require_file "scripts/cm-check-runtime.ps1"
291
321
  require_file "scripts/cm-security.mjs"
292
322
  require_file "scripts/cm-security.test.mjs"
@@ -430,6 +460,17 @@ if [ -n "$NODE_BIN" ]; then
430
460
  fi
431
461
  fi
432
462
  fi
463
+ # Optional Matt Pocock companion skills: a /cm-check report only, never a failure.
464
+ # Installers run this check without --print-effective and print their own hint.
465
+ if [ "$PRINT_EFFECTIVE" -eq 1 ] && [ -f "$ROOT/scripts/cm-matt-skills.mjs" ]; then
466
+ "$NODE_BIN" "$ROOT/scripts/cm-matt-skills.mjs" status ||
467
+ warn "recommended skills status unavailable"
468
+ fi
469
+ # Optional skill-hints hook: wiring, switch and table counts; a report only, never a failure.
470
+ if [ "$PRINT_EFFECTIVE" -eq 1 ] && [ -f "$ROOT/scripts/cm-skill-hints.mjs" ]; then
471
+ "$NODE_BIN" "$ROOT/scripts/cm-skill-hints.mjs" status ||
472
+ warn "skill hints status unavailable"
473
+ fi
433
474
  else
434
475
  fail "Node.js 18+ is required for CM workflow config validation"
435
476
  fi
@@ -652,7 +693,7 @@ for consumer in \
652
693
  fail "external-expert AUTO routing is not wired into $consumer"
653
694
  done
654
695
 
655
- for name in cm-idea cm-init cm-prd cm-ai cm-test cm-security cm-fix cm-refactor cm-check cm-runtime cm-notify; do
696
+ for name in cm-challenge cm-idea cm-init cm-prd cm-ai cm-test cm-security cm-fix cm-refactor cm-check cm-runtime cm-notify; do
656
697
  require_file "skills/$name/SKILL.md"
657
698
  require_file "compat/claude-commands/$name.md"
658
699
  wrapper="$ROOT/compat/claude-commands/$name.md"
@@ -903,6 +944,22 @@ elif grep -Fq 'ls {SPECS_DIR}/.reviews/fix-{slug}-r*.md' "$ROOT/skills/cm-fix/SK
903
944
  else
904
945
  fail "cm-fix is missing the mechanical post-fix review evidence gate"
905
946
  fi
947
+ # Fixed recovery producers, transport consumers and documentation stay paired.
948
+ for correction in command-correction test-type-correction; do
949
+ operation="prepare_${correction//-/_}"
950
+ permission="--allow-${correction}"
951
+ require_file "runtime/js/cm-fix/${correction}.mjs"
952
+ require_file "scripts/cm-fix-${correction}.mjs"
953
+ require_file "skills/cm-fix/references/${correction}.md"
954
+ for surface in runtime/js/cm-ai/host-session.mjs runtime/js/cm-fix/host.mjs scripts/cm-fix-drive.mjs; do
955
+ grep -Fq "'${operation}'" "$ROOT/$surface" || fail "${surface} does not route ${operation}"
956
+ done
957
+ for surface in scripts/cm-fix-host.mjs scripts/cm-fix-drive.mjs; do
958
+ grep -Fq -e "$permission" "$ROOT/$surface" || fail "${surface} does not bind ${permission}"
959
+ done
960
+ grep -Fq "${correction}.md" "$ROOT/skills/cm-fix/references/js-host.md" ||
961
+ fail "cm-fix host manual does not link ${correction}"
962
+ done
906
963
  require_file "skills/cm-fix/references/cross-boundary-debugging.md"
907
964
  grep -q "references/cross-boundary-debugging.md" "$ROOT/skills/cm-fix/SKILL.md" ||
908
965
  fail "cm-fix does not load its cross-boundary debugging reference"
@@ -23,7 +23,7 @@ function fixture(t){
23
23
  t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
24
24
  return root;
25
25
  }
26
- function fakeWorker(cwd,{value=proposal,mode='normal',timeoutMs=3000,noticeEvents=[],noticeAt=1,onNotice,
26
+ function fakeWorker(cwd,{value=proposal,mode='normal',timeoutMs=3000,noticeEvents=[],noticeAt=1,heartbeats=0,onNotice,
27
27
  resultFields={},toolName='Read',toolResultId='read-1',
28
28
  assistantContent=[{type:'text',text:'proposal'}]}={}){
29
29
  // The timeout mode hangs; the guard ends it if this test process dies first.
@@ -40,7 +40,9 @@ function fakeWorker(cwd,{value=proposal,mode='normal',timeoutMs=3000,noticeEvent
40
40
  ${JSON.stringify(mode)}==='write'?[{type:'tool_use',id:'bad',name:'Write',input:{}}]:${JSON.stringify(assistantContent)}}},
41
41
  {type:'result',session_id,subtype:${JSON.stringify(mode)}==='failed'?'error_during_execution':'success',
42
42
  is_error:${JSON.stringify(mode)}==='failed',num_turns:1,result:JSON.stringify(value),...${JSON.stringify(resultFields)}});
43
- events.splice(${JSON.stringify(noticeAt)},0,...${JSON.stringify(noticeEvents)});
43
+ // Heartbeats are generated here: thousands of them inlined would exceed the per-argument limit.
44
+ const heartbeats=Array.from({length:${JSON.stringify(heartbeats)}},()=>({type:'system',subtype:'thinking_tokens',session_id,estimated_tokens:10}));
45
+ events.splice(${JSON.stringify(noticeAt)},0,...heartbeats,...${JSON.stringify(noticeEvents)});
44
46
  for(const event of events)process.stdout.write(JSON.stringify(event)+'\\n');
45
47
  });`;
46
48
  return claudeDeveloperWorker({cwd,model:'fixture',timeoutMs,onNotice,spawnProcess:(cli,args,options)=>{
@@ -76,6 +78,23 @@ test('developer accepts dev_intent on either side of init with a sanitized notic
76
78
  assert.deepEqual(result,baseline);
77
79
  }
78
80
  });
81
+ // Regression: CLI 2.1.289 emits ui_invalidate before init. The review stream
82
+ // already accepts it (docs/fixes/20261013-claude-preinit-ui-invalidate.md); the
83
+ // developer stream rejected it as missing_init and killed its own process group.
84
+ test('developer accepts ui_invalidate on either side of init with a sanitized notice',async t=>{
85
+ const root=fixture(t),control={signal:new AbortController().signal};
86
+ const baseline=await fakeWorker(root)({prompt:prompt()},control);
87
+ const uiInvalidate={type:'system',subtype:'ui_invalidate',session_id:'synthetic-claude-developer',payload:{private:'x'}};
88
+ for(const noticeAt of [0,1,2]){
89
+ const notices=[],result=await fakeWorker(root,{noticeAt,noticeEvents:[uiInvalidate],onNotice:n=>notices.push(n)})
90
+ ({prompt:prompt()},control);
91
+ assert.deepEqual(result,baseline);
92
+ assert.deepEqual(notices,[{kind:'claude_system_notice',subtype:'ui_invalidate'}]);
93
+ }
94
+ // It never initializes a turn: alone it still fails as missing init, and it binds the session.
95
+ assert.deepEqual(await fakeWorker(root,{noticeAt:0,noticeEvents:[{...uiInvalidate,session_id:'other'}]})({prompt:prompt()},control),
96
+ {status:'unknown',code:'session_mismatch'});
97
+ });
79
98
  test('developer dev_intent binds init session and shares a 32-notice budget',async t=>{
80
99
  const root=fixture(t),control={signal:new AbortController().signal};
81
100
  for(const [noticeEvents,noticeAt,code] of [
@@ -120,9 +139,10 @@ const thoughts={type:'assistant',session_id:'synthetic-claude-developer',parent_
120
139
  test('developer thinking events preserve proposal and read tool pairing with developer schema',async t=>{
121
140
  const root=fixture(t),control={signal:new AbortController().signal};
122
141
  const baseline=await fakeWorker(root)({prompt:prompt()},control);
123
- for(const [mode,noticeAt,count] of [['normal',1,2],['normal',2,64],['read',2,2]]){
142
+ // 回归:长开发会话的思考心跳曾在第 65 条被拒(aihot T-001);上限与审查端同为 4096。
143
+ for(const [mode,noticeAt,count] of [['normal',1,2],['normal',2,64],['normal',2,65],['normal',2,4096],['read',2,2]]){
124
144
  const result=await fakeWorker(root,{mode,noticeAt,
125
- noticeEvents:[rateLimit(),...Array.from({length:count},thinkingTokens),thoughts],
145
+ heartbeats:count,noticeEvents:[rateLimit(),thoughts],
126
146
  assistantContent:[...thoughts.message.content,{type:'text',text:'proposal'}]})({prompt:prompt()},control);
127
147
  assert.deepEqual(result,baseline);
128
148
  }
@@ -133,15 +153,15 @@ test('developer thinking events preserve proposal and read tool pairing with dev
133
153
  });
134
154
  test('developer thinking preserves initial, terminal, count and unknown-system rejection',async t=>{
135
155
  const root=fixture(t),control={signal:new AbortController().signal};
136
- for(const [noticeEvents,noticeAt,code] of [
137
- [Array.from({length:65},thinkingTokens),1,'unexpected_event'],
156
+ for(const [noticeEvents,noticeAt,code,heartbeats=0] of [
157
+ [[],1,'unexpected_event',4097],
138
158
  [[{...thinkingTokens(),subtype:'unknown'}],1,'unexpected_event'],
139
159
  [[{...thinkingTokens(),subtype:'init'}],1,'unexpected_event'],
140
160
  [[{...thinkingTokens(),session_id:'other'}],1,'session_mismatch'],
141
161
  [[thinkingTokens()],0,'missing_init'],
142
162
  [[thinkingTokens()],3,'invalid_event'],
143
163
  ]){
144
- const result=await fakeWorker(root,{noticeEvents,noticeAt})({prompt:prompt()},control);
164
+ const result=await fakeWorker(root,{noticeEvents,noticeAt,heartbeats})({prompt:prompt()},control);
145
165
  assert.deepEqual(result,{status:'unknown',code});
146
166
  }
147
167
  const result=await fakeWorker(root,{assistantContent:thoughts.message.content})({prompt:prompt()},control);
@@ -290,3 +310,32 @@ test('developer stream treats a synthetic CLI reminder as a notice, except betwe
290
310
  assert.equal(pending.code,'unexpected_tool_or_content');
291
311
  assert.deepEqual(fs.readdirSync(root),[]);
292
312
  });
313
+
314
+ // 2026-10-26: a provider developer hitting the API rate limit is recognised by class.
315
+ // The stream shape is the one Claude CLI 2.1.274 prints for an API failure (see
316
+ // cm-ai-review-failure.test.mjs): a synthetic assistant message carrying the error
317
+ // class, then an is_error result with api_error_status. Only the class is kept.
318
+ function apiErrorWorker(cwd,{error,status,text}){
319
+ const source=`${ownerGuardSource()}let input='';process.stdin.on('data',s=>input+=s);process.stdin.on('end',()=>{
320
+ const session_id='synthetic-claude-developer',out=e=>process.stdout.write(JSON.stringify(e)+'\\n');
321
+ out({type:'system',subtype:'init',session_id});
322
+ out({type:'assistant',session_id,parent_tool_use_id:null,error:${JSON.stringify(error)},is_api_error_message:true,
323
+ message:{role:'assistant',content:[{type:'text',text:${JSON.stringify(text)}}]}});
324
+ out({type:'result',session_id,subtype:'success',is_error:true,num_turns:1,result:${JSON.stringify(text)},
325
+ terminal_reason:'api_error',api_error_status:${JSON.stringify(status)}});
326
+ process.exit(1);
327
+ });`;
328
+ return claudeDeveloperWorker({cwd,model:'fixture',timeoutMs:5000,spawnProcess:(cli,args,options)=>spawn(process.execPath,['-e',source],options)});
329
+ }
330
+ for(const [error,status,text,code] of [
331
+ ['rate_limit',429,'API Error: 429 rate limited','developer_rate_limited'],
332
+ ['server_error',529,'API Error: 529 Overloaded','developer_server_error'],
333
+ ['authentication_failed',401,'Invalid API key','developer_auth_failed'],
334
+ ['billing_error',402,'Credit balance too low','developer_billing_error'],
335
+ ['model_not_found',404,'model not found','developer_model_not_found'],
336
+ ['invalid_request',400,'API Error: 400 bad request','developer_api_error'],
337
+ ])test(`Claude developer API error ${error} ends as ${code} (class only, status unchanged)`,async t=>{
338
+ const root=fixture(t),result=await apiErrorWorker(root,{error,status,text})({prompt:prompt()},{signal:new AbortController().signal});
339
+ // Same terminal status as before (unknown): only the code names the class, never the text.
340
+ assert.deepEqual(result,{status:'unknown',code});assert.deepEqual(fs.readdirSync(root),[]);
341
+ });
@@ -11,7 +11,7 @@ test('real isolated Claude install checks correction docs at its installed layou
11
11
  const home=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-claude-install-layout-')));
12
12
  t.after(()=>fs.rmSync(home,{recursive:true,force:true}));
13
13
  const target=path.join(home,'.claude'),env={...process.env,HOME:home,CLAUDE_HOME:target,
14
- CM_WORKFLOW_HOME:path.join(home,'user'),CM_WORKFLOW_LOG_HOME:path.join(home,'logs')};
14
+ CM_WORKFLOW_HOME:path.join(home,'user'),CM_WORKFLOW_LOG_HOME:path.join(home,'logs'),CM_MATT_SKILLS_INSTALL:'off'};
15
15
  const installed=spawnSync('/bin/bash',[path.join(source,'install.sh'),'--yes'],{cwd:source,env,encoding:'utf8',timeout:120000,maxBuffer:4*1024*1024});
16
16
  assert.equal(installed.status,0,installed.stdout+installed.stderr);
17
17
  assert.match(installed.stdout,/cm runtime check: PASSED \(claude-compat v/);
@@ -0,0 +1,235 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import {EventEmitter} from 'node:events';
4
+ import {PassThrough} from 'node:stream';
5
+ import fs from 'node:fs';
6
+ import os from 'node:os';
7
+ import path from 'node:path';
8
+ import {spawn} from 'node:child_process';
9
+ import {createInterface} from 'node:readline';
10
+ import {createClaudeReviewStream} from '../runtime/js/cm-ai/claude-review-stream.mjs';
11
+ import {claudeWorker,claudeReviewFingerprint} from '../runtime/js/cm-ai/worker-claude.mjs';
12
+ import {createReviewVerificationSession} from '../runtime/js/cm-fix/review-verification.mjs';
13
+
14
+ const session_id='diagnostic-fixture';
15
+ const init={type:'system',subtype:'init',session_id};
16
+ const assistant={type:'assistant',session_id,parent_tool_use_id:null,
17
+ message:{role:'assistant',content:[{type:'text',text:'synthetic review'}]}};
18
+ const success={type:'result',subtype:'success',session_id,is_error:false,num_turns:1,structured_output:{verdict:'approved'}};
19
+ const api=(error='invalid_request',text='API Error',extra={})=>({...assistant,error,
20
+ message:{role:'assistant',content:[{type:'text',text}]},...extra});
21
+ function failure(message,prefix=[init],allowedTools=[]){
22
+ const events=[],stream=createClaudeReviewStream(event=>events.push(event),null,allowedTools);
23
+ prefix.forEach(value=>stream.accept(value));
24
+ let caught;try{stream.accept(message);}catch(error){caught=error;}
25
+ assert.ok(caught);assert.throws(()=>stream.finish(),{code:'incomplete_result'});
26
+ return {error:caught,events};
27
+ }
28
+ const privateText='PRIVATE-BODY-SENTINEL sk-private-credential https://private.invalid/secret /private/secret';
29
+ test('API diagnostics preserve failure classes and expose only fixed categories, status and bounded token limits',()=>{
30
+ for(const [kind,code] of [['authentication_failed','reviewer_auth_failed'],['billing_error','reviewer_billing_error'],
31
+ ['rate_limit','reviewer_rate_limited'],['server_error','reviewer_server_error'],['model_not_found','reviewer_model_not_found'],
32
+ ...['invalid_request','invalid_request_error','api_error','overloaded_error','context_window_exceeded','unknown'].map(kind=>[kind,'reviewer_api_error'])]){
33
+ const text='API Error: 400 '+JSON.stringify({type:'error',error:{type:'invalid_request_error',
34
+ message:'prompt is too long: 210123 tokens > 200000 maximum '+privateText},request_id:privateText});
35
+ const {error,events}=failure(api(kind,text));
36
+ assert.equal(error.code,code);
37
+ assert.deepEqual(error.failureDetail,{version:1,check:'api_error',stage:'assistant',eventType:'assistant',eventTypeLength:9,
38
+ eventSubtype:'absent',eventSubtypeLength:0,noticeCount:0,thinkingCount:0,progressCount:0,apiErrorClass:kind,apiErrorClassLength:kind.length,
39
+ providerErrorClass:'invalid_request_error',httpStatus:400,errorFlags:['prompt_too_long'],tokenBudget:{inputTokens:210123,maximumTokens:200000}});
40
+ assert.deepEqual(events.map(value=>value.event),['thread.started','turn.started']);
41
+ assert(!JSON.stringify(error.failureDetail).includes('PRIVATE'));
42
+ assert(Buffer.byteLength(JSON.stringify(error.failureDetail))<1024);
43
+ }
44
+ });
45
+ test('unknown or malformed provider fields and oversized API bodies never enter diagnostics',()=>{
46
+ for(const text of [privateText,'API Error: 400 '+JSON.stringify({error:{type:privateText,message:privateText}}),
47
+ 'API Error: 400 '+privateText.repeat(200),
48
+ 'API Error: 400 '+JSON.stringify({error:{type:'api_error',message:'prompt is too long: 1234567890 tokens > 200000 maximum'}})]){
49
+ const {error}=failure(api(privateText,text,{subtype:privateText,status_code:'401',error_status:999,api_error_status:99}));
50
+ assert.equal(error.code,'reviewer_api_error');assert.equal(error.failureDetail.apiErrorClass,'other');
51
+ assert.equal(error.failureDetail.eventSubtype,'other');assert.equal(error.failureDetail.tokenBudget,null);
52
+ assert.equal(error.failureDetail.httpStatus,text.startsWith('API Error: 400 ')?400:null);
53
+ assert(!JSON.stringify(error.failureDetail).includes('PRIVATE'));
54
+ assert(!JSON.stringify(error.failureDetail).includes('https:'));
55
+ assert(!JSON.stringify(error.failureDetail).includes('/private/'));
56
+ }
57
+ const explicit=failure(api('unknown','context_length_exceeded '+privateText,{api_error_status:413})).error.failureDetail;
58
+ assert.equal(explicit.httpStatus,413);assert.deepEqual(explicit.errorFlags,['context_length_exceeded']);
59
+ const huge=failure({type:privateText.repeat(15000),subtype:privateText.repeat(15000),session_id}).error.failureDetail;
60
+ assert.equal(huge.eventType,'other');assert.equal(huge.eventSubtype,'other');
61
+ assert.equal(huge.eventTypeLength,1_000_001);assert.equal(huge.eventSubtypeLength,1_000_001);
62
+ assert(Buffer.byteLength(JSON.stringify(huge))<1024);
63
+ });
64
+ test('locally known but unsupported protocol enums are diagnosed without accepting them',()=>{
65
+ for(const subtype of ['compact_boundary','status','task_started','task_progress','task_notification',
66
+ 'files_persisted','hook_progress','local_command_output']){
67
+ const {error}=failure({type:'system',subtype,session_id,body:privateText});
68
+ assert.equal(error.code,'unexpected_event');assert.equal(error.failureDetail.check,'unknown_system_subtype');
69
+ assert.equal(error.failureDetail.eventType,'system');assert.equal(error.failureDetail.eventSubtype,subtype);
70
+ }
71
+ for(const type of ['auth_status','keep_alive','stream_event','tool_use_summary']){
72
+ const {error}=failure({type,session_id,body:privateText});
73
+ assert.equal(error.code,'unexpected_event');assert.equal(error.failureDetail.check,'unknown_message_type');
74
+ assert.equal(error.failureDetail.eventType,type);
75
+ }
76
+ });
77
+ test('unexpected_event distinguishes exact existing notice, thinking and terminal boundaries',()=>{
78
+ const notice={type:'system',subtype:'api_retry',session_id};
79
+ const heartbeat={type:'system',subtype:'thinking_tokens',session_id};
80
+ for(const [message,prefix,check,count] of [
81
+ [notice,[init,...Array(32).fill(notice)],'notice_limit',32],
82
+ [heartbeat,[init,...Array(4096).fill(heartbeat)],'thinking_limit',4096],
83
+ [notice,[init,assistant,success],'terminal_stage',0],
84
+ ]){
85
+ const {error}=failure(message,prefix);assert.equal(error.code,'unexpected_event');assert.equal(error.failureDetail.check,check);
86
+ if(check==='notice_limit')assert.equal(error.failureDetail.noticeCount,count);
87
+ if(check==='thinking_limit')assert.equal(error.failureDetail.thinkingCount,count);
88
+ if(check==='terminal_stage')assert.equal(error.failureDetail.stage,'done');
89
+ }
90
+ });
91
+
92
+ async function run(wire,onDiagnostic){
93
+ const config={cwd:'/tmp',model:'diagnostic-fixture',cli:'never-execute-provider'};
94
+ const events=[],kills=[],terminals=[];
95
+ const worker=claudeWorker({...config,onDiagnostic,timeoutMs:5000,
96
+ preflight:{passed:true,provider:'claude',prompt_transport:'stdin',config_fingerprint:claudeReviewFingerprint(config)},
97
+ killProcess:(pid,signal)=>kills.push({pid,signal}),
98
+ spawnProcess:()=>{
99
+ const child=new EventEmitter();
100
+ // No PID: owned-process cleanup cannot reach a real process.
101
+ child.kill=()=>true;
102
+ child.stdin=new PassThrough();child.stdout=new PassThrough();child.stderr=new PassThrough();
103
+ child.stdin.resume();
104
+ child.stdin.once('finish',()=>queueMicrotask(()=>{
105
+ child.stderr.end(privateText);
106
+ child.stdout.end(wire.map(JSON.stringify).join('\n')+'\n');
107
+ child.emit('close',wire.at(-1)===success?0:null,wire.at(-1)===success?null:'SIGKILL');
108
+ }));return child;
109
+ }});
110
+ const result=await worker({prompt:'synthetic-only'},{signal:new AbortController().signal,onEvent:event=>events.push(event),onTerminal:value=>terminals.push(value)});
111
+ return {result,events,kills:kills.map(value=>value.signal),terminals};
112
+ }
113
+ test('worker diagnostic sidecar preserves strict receipts, cleanup signals and first failure',async()=>{
114
+ const wire=[init,api('invalid_request','API Error: 400 '+JSON.stringify({error:{type:'invalid_request_error',message:'prompt_too_long '+privateText}})),
115
+ {type:'system',subtype:'status',session_id}];
116
+ const rows=[];
117
+ const [baseline,withDiagnostic,throwing]=await Promise.all([run(wire),run(wire,row=>rows.push(row)),
118
+ run(wire,()=>{throw Error(privateText);})]);
119
+ assert.deepEqual(withDiagnostic,baseline);assert.deepEqual(throwing,baseline);
120
+ assert.deepEqual(baseline.result,{status:'failed',code:'reviewer_api_error'});
121
+ assert.deepEqual(baseline.events.map(value=>value.event),['thread.started','turn.started','process_closed']);
122
+ assert.equal(baseline.events.at(-1).signal,'SIGKILL');assert.equal(baseline.events.at(-1).timed_out,false);
123
+ assert.deepEqual(baseline.kills,['SIGTERM','SIGKILL']);assert.deepEqual(baseline.terminals,[]);
124
+ assert.equal(rows.length,1);assert.equal(rows[0].code,'reviewer_api_error');
125
+ assert.equal(rows[0].failureDetail.providerErrorClass,'invalid_request_error');
126
+ assert(!JSON.stringify(rows).includes('PRIVATE'));assert.deepEqual(Object.keys(baseline.result),['status','code']);
127
+ });
128
+ test('worker exposes unsupported subtype, reports no success diagnostic and cannot accept a diagnostic verdict',async()=>{
129
+ const rows=[];
130
+ const actual=await run([init,{type:'system',subtype:'status',session_id}],row=>{rows.push(row);return {status:'succeeded',value:{verdict:'approved'}};});
131
+ assert.deepEqual(actual.result,{status:'failed',code:'unexpected_event'});
132
+ assert.equal(rows.length,1);assert.equal(rows[0].failureDetail.eventSubtype,'status');assert.deepEqual(actual.terminals,[]);
133
+ const successRows=[],passed=await run([init,assistant,success],row=>successRows.push(row));
134
+ assert.deepEqual(passed.result,{status:'succeeded',value:{verdict:'approved'}});assert.deepEqual(successRows,[]);
135
+ assert.deepEqual(passed.kills,[]);
136
+ });
137
+
138
+ const reviewTools=['mcp__cm_review__read_file','mcp__cm_review__run_check','mcp__cm_review__mutate_check'];
139
+ const toolCall=(name=reviewTools[1],id='pending-tool')=>({...assistant,
140
+ message:{role:'assistant',content:[{type:'tool_use',id,name,input:{id:'long'}}]}});
141
+ const toolResult=(id='pending-tool')=>({type:'user',session_id,
142
+ message:{role:'user',content:[{type:'tool_result',tool_use_id:id,is_error:false,content:'synthetic result'}]}});
143
+ const progress=(extra={})=>({type:'tool_progress',session_id,tool_use_id:'pending-tool',
144
+ tool_name:reviewTools[1],parent_tool_use_id:null,elapsed_time_seconds:1,...extra});
145
+ test('progress is bound to an allowed pending tool and never emits review events or clears its result',()=>{
146
+ for(const name of [...reviewTools,'StructuredOutput']){
147
+ const events=[],notices=[],stream=createClaudeReviewStream(event=>events.push(event),value=>notices.push(value),reviewTools);
148
+ stream.accept(init);stream.accept(toolCall(name));
149
+ for(const elapsed of [0,1,10])stream.accept(progress({tool_name:name,elapsed_time_seconds:elapsed,payload:privateText}));
150
+ assert.deepEqual(events.map(value=>value.event),['thread.started','turn.started']);assert.deepEqual(notices,[]);
151
+ stream.accept(toolResult());stream.accept(success);assert.deepEqual(stream.finish(),{status:'succeeded',value:{verdict:'approved'}});
152
+ }
153
+ const {error}=failure(success,[init,toolCall(),progress()],reviewTools);
154
+ assert.equal(error.code,'unexpected_result');assert.equal(error.failureDetail.progressCount,1);
155
+ const stream=createClaudeReviewStream(()=>{},null,reviewTools);
156
+ [init,toolCall(),progress()].forEach(value=>stream.accept(value));assert.throws(()=>stream.finish(),{code:'incomplete_result'});
157
+ });
158
+ test('progress rejects wrong sessions, missing calls, mismatched names, unapproved tools and invalid elapsed time',()=>{
159
+ for(const [message,prefix,code,check] of [
160
+ [progress({session_id:'different'}),[init,toolCall()],'session_mismatch','session_mismatch'],
161
+ [progress({session_id:''}),[init,toolCall()],'invalid_session','invalid_session'],
162
+ [progress(),[],'missing_init','missing_init'],
163
+ [progress(),[init],'unexpected_event','tool_progress_stage'],
164
+ [progress({tool_use_id:'unregistered'}),[init,toolCall()],'unexpected_event','tool_progress_identity'],
165
+ [progress({tool_use_id:null}),[init,toolCall()],'unexpected_event','tool_progress_identity'],
166
+ [progress({tool_name:reviewTools[0]}),[init,toolCall()],'unexpected_event','tool_progress_tool'],
167
+ [progress({tool_name:'Bash'}),[init,toolCall('Bash')],'unexpected_event','tool_progress_tool'],
168
+ [progress({parent_tool_use_id:'child'}),[init,toolCall()],'unexpected_event','tool_progress_parent'],
169
+ [progress({parent_tool_use_id:undefined}),[init,toolCall()],'unexpected_event','tool_progress_parent'],
170
+ [progress(),[init,toolCall(),toolResult()],'unexpected_event','tool_progress_identity'],
171
+ [progress(),[init,toolCall(),toolResult(),success],'unexpected_event','terminal_stage'],
172
+ ...[-1,0.5,Infinity,NaN,'1',null,Number.MAX_SAFE_INTEGER+1].map(elapsed_time_seconds=>[
173
+ progress({elapsed_time_seconds}),[init,toolCall()],'unexpected_event','tool_progress_elapsed']),
174
+ ]){
175
+ const {error}=failure(message,prefix,reviewTools);assert.equal(error.code,code);assert.equal(error.failureDetail.check,check);
176
+ }
177
+ assert.equal(failure(progress(),[init,toolCall()]).error.failureDetail.check,'tool_progress_tool');
178
+ });
179
+ test('progress has a separate bounded budget while notices, thinking and pending tool rules stay intact',()=>{
180
+ const prefix=[init,toolCall(),...Array(32).fill({type:'system',subtype:'api_retry',session_id}),
181
+ ...Array(4096).fill({type:'system',subtype:'thinking_tokens',session_id}),...Array(4096).fill(progress())];
182
+ const stream=createClaudeReviewStream(()=>{},null,reviewTools);prefix.forEach(value=>stream.accept(value));
183
+ stream.accept(toolResult());stream.accept(success);assert.equal(stream.finish().status,'succeeded');
184
+ const {error}=failure(progress(),prefix,reviewTools);assert.equal(error.code,'unexpected_event');
185
+ assert.equal(error.failureDetail.check,'tool_progress_limit');assert.equal(error.failureDetail.progressCount,4096);
186
+ assert.equal(error.failureDetail.noticeCount,32);assert.equal(error.failureDetail.thinkingCount,4096);
187
+ });
188
+ test('a real isolated MCP check remains pending across progress and finishes through its original tool result',
189
+ {skip:process.platform!=='darwin',timeout:15000},async()=>{
190
+ const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'claude-progress-')));
191
+ const source="import {value} from './value.mjs'; await new Promise(resolve=>setTimeout(resolve,300)); if(value!==1)process.exit(1);\n";
192
+ fs.writeFileSync(path.join(root,'long.test.mjs'),source);
193
+ fs.writeFileSync(path.join(root,'value.mjs'),'export const value=1;\n');
194
+ const verification={files:['value.mjs','long.test.mjs'],checks:[{id:'long',command:[process.execPath,'long.test.mjs']}],mutationPaths:['value.mjs'],timeoutMs:5000};
195
+ let session,server,closed,pendingReply;
196
+ try{
197
+ session=createReviewVerificationSession({codeProject:root,configuration:verification,
198
+ request:{requestDigest:'a'.repeat(64),provider:'claude',payload:{reviewPackage:{packageDigest:'b'.repeat(64),files:[]}}}});
199
+ const transport=JSON.parse(session.transport.mcpConfig).mcpServers.cm_review;
200
+ server=spawn(transport.command,transport.args,{stdio:['pipe','pipe','pipe']});server.stderr.resume();
201
+ closed=new Promise(resolve=>server.once('close',resolve));
202
+ const reply=new Promise((resolve,reject)=>{pendingReply={resolve,reject};});
203
+ createInterface({input:server.stdout}).on('line',line=>{
204
+ try{const value=JSON.parse(line);if(value.id===1)pendingReply.resolve(value.result);}catch(error){pendingReply.reject(error);}
205
+ });
206
+ server.once('error',error=>pendingReply.reject(error));
207
+ const events=[],diagnostics=[],config={cwd:root,model:'diagnostic-fixture',cli:'never-execute-provider',verification};
208
+ let transportError=null;
209
+ const worker=claudeWorker({...config,verificationTransport:session.transport,timeoutMs:10000,
210
+ preflight:{passed:true,provider:'claude',prompt_transport:'stdin',config_fingerprint:claudeReviewFingerprint(config)},
211
+ onDiagnostic:value=>diagnostics.push(value),killProcess:()=>{throw Error('unexpected fixture stop');},
212
+ spawnProcess:()=>{
213
+ const child=new EventEmitter();child.kill=()=>true;
214
+ child.stdin=new PassThrough();child.stdout=new PassThrough();child.stderr=new PassThrough();child.stdin.resume();
215
+ child.stdin.once('finish',()=>{void(async()=>{
216
+ const emit=value=>child.stdout.write(JSON.stringify(value)+'\n');
217
+ try{
218
+ emit(init);emit(toolCall());
219
+ server.stdin.write(JSON.stringify({jsonrpc:'2.0',id:1,method:'tools/call',params:{name:'run_check',arguments:{id:'long'}}})+'\n');
220
+ let finished=false;void reply.then(()=>{finished=true;});
221
+ for(let i=0;i<3;i++){await new Promise(resolve=>setTimeout(resolve,25));assert.equal(finished,false);emit(progress({elapsed_time_seconds:0}));}
222
+ const value=await reply;assert.equal(value.isError,undefined);assert.equal(JSON.parse(value.content[0].text).exitCode,0);
223
+ emit(toolResult());emit(success);child.stdout.end();child.emit('close',0,null);
224
+ }catch(error){transportError=error;child.emit('close',1,null);}
225
+ })();});return child;
226
+ }});
227
+ const result=await worker({prompt:'synthetic-only'},{signal:new AbortController().signal,onEvent:value=>events.push(value)});
228
+ assert.equal(transportError,null);assert.deepEqual(result,{status:'succeeded',value:{verdict:'approved'}});
229
+ assert.deepEqual(diagnostics,[]);assert.deepEqual(events.map(value=>value.event),['thread.started','turn.started','item.completed','turn.completed','process_closed']);
230
+ assert.equal(fs.readFileSync(path.join(root,'long.test.mjs'),'utf8'),source);
231
+ }finally{
232
+ if(server){server.stdin.end();await closed;}
233
+ await session?.close();fs.rmSync(root,{recursive:true,force:true});
234
+ }
235
+ });
@@ -387,3 +387,16 @@ test('API error classes before any tool call name the reviewer failure',()=>{
387
387
  assert.throws(()=>messages.forEach(message=>stream.accept(message)),{code:'unexpected_assistant'});
388
388
  }
389
389
  });
390
+
391
+ test('opt-in verification permits only the fixed MCP tools; default remains no-tools',()=>{
392
+ const names=['mcp__cm_review__read_file','mcp__cm_review__run_check','mcp__cm_review__mutate_check'];
393
+ for(const name of names){
394
+ const messages=[transcript()[0],assistant([tool('verify',name)]),toolResult('verify'),transcript()[2]];
395
+ assert.throws(()=>decode(messages),{code:'unexpected_tool_or_content'});
396
+ const stream=createClaudeReviewStream(()=>{},null,names);messages.forEach(m=>stream.accept(m));assert.equal(stream.finish().status,'succeeded');
397
+ }
398
+ for(const name of ['Bash','Read','mcp__other__run_check']){
399
+ const stream=createClaudeReviewStream(()=>{},null,names);stream.accept(transcript()[0]);stream.accept(assistant([tool('bad',name)]));
400
+ assert.throws(()=>stream.accept(toolResult('bad')),{code:'unexpected_tool_or_content'});
401
+ }
402
+ });
@@ -0,0 +1,98 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import {EventEmitter} from 'node:events';
4
+ import {PassThrough} from 'node:stream';
5
+ import {codexDeveloperWorker} from '../runtime/js/cm-ai/worker-codex-developer.mjs';
6
+
7
+ const reconnect=n=>({type:'error',message:`Reconnecting... ${n}/5 (stream disconnected before completion: synthetic)`});
8
+ const start=[{type:'thread.started',thread_id:'synthetic-developer-reconnect'},{type:'turn.started'}];
9
+ const finish=[{type:'item.completed',item:{type:'agent_message',text:'{"outcome":"implemented"}'}},{type:'turn.completed'}];
10
+ const succeeded={status:'succeeded',value:{outcome:'implemented'},providerThread:'synthetic-developer-reconnect'};
11
+
12
+ async function stream(rows,{throwNotice=false}={}){
13
+ const notices=[];
14
+ const run=codexDeveloperWorker({cwd:'/fixture',model:'gpt-6.1-sol',effort:'high',learning:false,timeoutMs:1000,
15
+ onNotice:notice=>{notices.push(notice);if(throwNotice)throw Error('synthetic notice sink failure');},
16
+ spawnProcess(){
17
+ const child=new EventEmitter();
18
+ child.stdin=new PassThrough();child.stdout=new PassThrough();child.stderr=new PassThrough();
19
+ queueMicrotask(()=>{
20
+ for(const row of rows)child.stdout.write(JSON.stringify(row)+'\n');
21
+ child.stdout.end();child.stderr.end();child.emit('close',0,null);
22
+ });
23
+ return child;
24
+ }});
25
+ const result=await run({prompt:'synthetic developer reconnect test'},{signal:new AbortController().signal});
26
+ return {result,notices};
27
+ }
28
+
29
+ test('developer reconnect 2/5 through 5/5 followed by HTTPS fallback succeeds',async()=>{
30
+ const reconnects=[2,3,4,5].map(reconnect);
31
+ const fallback={type:'item.completed',item:{type:'error',message:'Falling back to HTTPS transport. synthetic'}};
32
+ const actual=await stream([...start,...reconnects,fallback,...finish]);
33
+ assert.deepEqual(actual.result,succeeded);
34
+ assert.deepEqual(actual.notices,[...reconnects.map(row=>row.message),fallback.item.message]);
35
+ });
36
+
37
+ test('developer reconnect notices cannot hide a later turn.failed',async()=>{
38
+ const actual=await stream([...start,reconnect(2),reconnect(3),{type:'turn.failed',error:{message:'Reconnecting... 4/5'}}]);
39
+ assert.deepEqual(actual.result,{status:'unknown',code:'provider_failed'});
40
+ assert.deepEqual(actual.notices,[reconnect(2).message,reconnect(3).message]);
41
+ });
42
+
43
+ test('developer non-reconnect top-level errors remain fatal',async()=>{
44
+ for(const message of ['request failed','prefix Reconnecting... 2/5','Reconnecting.. 2/5','Reconnecting... two/5',null]){
45
+ const actual=await stream([...start,{type:'error',message},...finish]);
46
+ assert.deepEqual(actual.result,{status:'unknown',code:'provider_failed'});
47
+ assert.deepEqual(actual.notices,[]);
48
+ }
49
+ });
50
+
51
+ test('developer reconnect limit allows 32 notices independently of eight item notices',async()=>{
52
+ const reconnects=Array.from({length:32},(_,n)=>reconnect(n+1));
53
+ const items=Array.from({length:8},()=>({type:'item.completed',item:{type:'error',message:'synthetic startup notice'}}));
54
+ const actual=await stream([...start,...reconnects,...items,...finish]);
55
+ assert.deepEqual(actual.result,succeeded);
56
+ assert.deepEqual(actual.notices,[...reconnects.map(row=>row.message),...items.map(row=>row.item.message)]);
57
+ });
58
+
59
+ test('developer reconnect notice 33 fails instead of allowing an endless stream',async()=>{
60
+ const actual=await stream([...start,...Array.from({length:33},(_,n)=>reconnect(n+1)),...finish]);
61
+ assert.deepEqual(actual.result,{status:'unknown',code:'provider_failed'});
62
+ assert.deepEqual(actual.notices,Array.from({length:32},(_,n)=>reconnect(n+1).message));
63
+ });
64
+
65
+ test('developer reconnect notices are bounded and notice sink failure does not fail a turn',async()=>{
66
+ const notice={...reconnect(1),message:reconnect(1).message+'x'.repeat(400)};
67
+ const actual=await stream([...start,notice,...finish],{throwNotice:true});
68
+ assert.deepEqual(actual.result,succeeded);
69
+ assert.deepEqual(actual.notices,[notice.message.slice(0,200)]);
70
+ });
71
+
72
+ test('developer reconnect before thread may recover but cannot replace thread initialization',async()=>{
73
+ const recovered=await stream([reconnect(1),...start,...finish]);
74
+ assert.deepEqual(recovered.result,succeeded);
75
+ assert.deepEqual(recovered.notices,[reconnect(1).message]);
76
+ const missing=await stream([reconnect(1),{type:'turn.started'},...finish]);
77
+ assert.deepEqual(missing.result,{status:'unknown',code:'thread_missing'});
78
+ assert.deepEqual(missing.notices,[reconnect(1).message]);
79
+ });
80
+
81
+ test('developer reconnect after completion remains fatal without emitting a notice',async()=>{
82
+ const actual=await stream([...start,...finish,reconnect(1)]);
83
+ assert.deepEqual(actual.result,{status:'unknown',code:'provider_failed'});
84
+ assert.deepEqual(actual.notices,[]);
85
+ });
86
+
87
+ test('developer reconnect does not reset or bypass existing item and turn guards',async()=>{
88
+ const item={type:'item.completed',item:{type:'error',message:'synthetic startup notice'}};
89
+ for(const [rows,code] of [
90
+ [[...start,...Array(8).fill(item),reconnect(1),item,...finish],'invalid_event'],
91
+ [[start[0],reconnect(1),...finish],'turn_missing'],
92
+ [[...start,reconnect(1),start[0],...finish],'thread_mismatch'],
93
+ [[...start,reconnect(1),start[1],...finish],'duplicate_turn'],
94
+ ]){
95
+ const actual=await stream(rows);
96
+ assert.deepEqual(actual.result,{status:'unknown',code});
97
+ }
98
+ });