@aibyzero/cm-workflow 0.17.0 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (372) hide show
  1. package/.codex-plugin/plugin.json +1 -1
  2. package/AGENTS.md +27 -0
  3. package/CHANGELOG.md +230 -1
  4. package/CONTRIBUTING.md +47 -0
  5. package/README.md +21 -3
  6. package/THIRD_PARTY_NOTICES.md +13 -0
  7. package/VERSION +1 -1
  8. package/compat/claude-commands/cm-challenge.md +3 -0
  9. package/docs/architecture.md +40 -13
  10. package/docs/cm-control-policy-v2.md +127 -9
  11. package/docs/fixes/20261013-claude-preinit-ui-invalidate.md +48 -0
  12. package/docs/installation.md +310 -4
  13. package/docs/js-workflow-control.md +153 -16
  14. package/docs/live-evidence-drivers.md +28 -4
  15. package/docs/out-of-scope/README.md +25 -0
  16. package/docs/out-of-scope/background-supervisor.md +32 -0
  17. package/docs/reviewed-integration.md +48 -0
  18. package/docs/user-guide.md +50 -21
  19. package/install-codex.sh +331 -18
  20. package/install.ps1 +28 -2
  21. package/install.sh +321 -17
  22. package/package.json +2 -1
  23. package/runtime/js/cm-ai/batch-location.mjs +55 -0
  24. package/runtime/js/cm-ai/batch-plan.mjs +242 -0
  25. package/runtime/js/cm-ai/checkpoint-package-material.mjs +162 -0
  26. package/runtime/js/cm-ai/claude-developer-proposal.schema.json +55 -1
  27. package/runtime/js/cm-ai/claude-review-stream.mjs +94 -21
  28. package/runtime/js/cm-ai/claude-tool-preview.mjs +11 -9
  29. package/runtime/js/cm-ai/cm-ai-admission.mjs +18 -12
  30. package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +91 -6
  31. package/runtime/js/cm-ai/cm-ai-qa-log.mjs +5 -1
  32. package/runtime/js/cm-ai/codex-config.mjs +6 -2
  33. package/runtime/js/cm-ai/codex-developer-basic-output.schema.json +3 -2
  34. package/runtime/js/cm-ai/codex-developer-output.schema.json +2 -1
  35. package/runtime/js/cm-ai/codex-reconnect-notice.mjs +6 -0
  36. package/runtime/js/cm-ai/codex-review-adapter.mjs +27 -7
  37. package/runtime/js/cm-ai/control-policy.mjs +24 -6
  38. package/runtime/js/cm-ai/developer-adapter.mjs +19 -5
  39. package/runtime/js/cm-ai/drive-core.mjs +236 -34
  40. package/runtime/js/cm-ai/drive-rate-limit.mjs +105 -0
  41. package/runtime/js/cm-ai/durable-runner-state.mjs +234 -33
  42. package/runtime/js/cm-ai/effect-contract.mjs +11 -2
  43. package/runtime/js/cm-ai/execution-policy.mjs +3 -1
  44. package/runtime/js/cm-ai/execution-snapshot.mjs +4 -2
  45. package/runtime/js/cm-ai/execution-store-limits.mjs +14 -7
  46. package/runtime/js/cm-ai/execution-store.mjs +60 -17
  47. package/runtime/js/cm-ai/fix-code-association.mjs +73 -2
  48. package/runtime/js/cm-ai/host-check.mjs +14 -6
  49. package/runtime/js/cm-ai/host-conversation-execution.mjs +70 -28
  50. package/runtime/js/cm-ai/host-qa-executor.mjs +38 -5
  51. package/runtime/js/cm-ai/host-qa-fix-owner.mjs +2 -2
  52. package/runtime/js/cm-ai/host-qa-policy.mjs +19 -2
  53. package/runtime/js/cm-ai/host-replay.mjs +148 -0
  54. package/runtime/js/cm-ai/host-session.mjs +42 -9
  55. package/runtime/js/cm-ai/host-stage-observer.mjs +26 -0
  56. package/runtime/js/cm-ai/host-tool-bridge.mjs +22 -9
  57. package/runtime/js/cm-ai/host-workflow-capabilities.mjs +19 -2
  58. package/runtime/js/cm-ai/host.mjs +1 -1
  59. package/runtime/js/cm-ai/implicit-qa-decision.mjs +5 -0
  60. package/runtime/js/cm-ai/integration-snapshots.mjs +50 -0
  61. package/runtime/js/cm-ai/live-evidence.mjs +28 -6
  62. package/runtime/js/cm-ai/operator-guidance.mjs +63 -30
  63. package/runtime/js/cm-ai/owned-process-cleanup.mjs +27 -9
  64. package/runtime/js/cm-ai/process-group-exit.mjs +46 -0
  65. package/runtime/js/cm-ai/provider-review-observation.mjs +3 -2
  66. package/runtime/js/cm-ai/qa-attachment.mjs +22 -0
  67. package/runtime/js/cm-ai/qa-config-revision.mjs +7 -2
  68. package/runtime/js/cm-ai/requirement-evidence.mjs +102 -0
  69. package/runtime/js/cm-ai/review-package.mjs +79 -7
  70. package/runtime/js/cm-ai/review-presentation-delta.mjs +166 -0
  71. package/runtime/js/cm-ai/review-presentation.mjs +177 -8
  72. package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +70 -2
  73. package/runtime/js/cm-ai/reviewed-integration.mjs +260 -0
  74. package/runtime/js/cm-ai/scope-revision.mjs +38 -0
  75. package/runtime/js/cm-ai/specification-material.mjs +2 -2
  76. package/runtime/js/cm-ai/task-runner.mjs +247 -41
  77. package/runtime/js/cm-ai/verification-auto.mjs +38 -0
  78. package/runtime/js/cm-ai/worker-claude-developer.mjs +39 -15
  79. package/runtime/js/cm-ai/worker-claude.mjs +35 -13
  80. package/runtime/js/cm-ai/worker-codex-developer.mjs +43 -17
  81. package/runtime/js/cm-ai/worker-codex.mjs +41 -7
  82. package/runtime/js/cm-fix/cause-invocation.mjs +16 -2
  83. package/runtime/js/cm-fix/cause-package.mjs +46 -1
  84. package/runtime/js/cm-fix/command-correction.mjs +37 -0
  85. package/runtime/js/cm-fix/cooperative.mjs +12 -0
  86. package/runtime/js/cm-fix/dossier.mjs +8 -2
  87. package/runtime/js/cm-fix/execution.mjs +578 -100
  88. package/runtime/js/cm-fix/final-review.mjs +39 -8
  89. package/runtime/js/cm-fix/finish.mjs +15 -11
  90. package/runtime/js/cm-fix/host-review.mjs +65 -10
  91. package/runtime/js/cm-fix/host.mjs +35 -12
  92. package/runtime/js/cm-fix/jest-command-correction.mjs +69 -0
  93. package/runtime/js/cm-fix/metrics.mjs +18 -5
  94. package/runtime/js/cm-fix/regression-evidence.mjs +3 -2
  95. package/runtime/js/cm-fix/regression.mjs +16 -7
  96. package/runtime/js/cm-fix/repair.mjs +29 -8
  97. package/runtime/js/cm-fix/review-verification-command.mjs +135 -0
  98. package/runtime/js/cm-fix/review-verification-contract.mjs +54 -0
  99. package/runtime/js/cm-fix/review-verification-diagnostic.mjs +75 -0
  100. package/runtime/js/cm-fix/review-verification-recovery.mjs +44 -0
  101. package/runtime/js/cm-fix/review-verification-server.mjs +38 -0
  102. package/runtime/js/cm-fix/review-verification.mjs +214 -0
  103. package/runtime/js/cm-fix/source-correction-recovery.mjs +65 -0
  104. package/runtime/js/cm-fix/start.mjs +6 -3
  105. package/runtime/js/cm-fix/test-type-correction.mjs +86 -0
  106. package/runtime/js/cm-fix/test-type-recovery.mjs +51 -0
  107. package/runtime/js/cm-fix/type-import-correction.mjs +89 -0
  108. package/runtime/js/cm-prd/accepted-design.mjs +8 -0
  109. package/runtime/js/cm-prd/analysis.mjs +13 -9
  110. package/runtime/js/cm-prd/change.mjs +37 -16
  111. package/runtime/js/cm-prd/draft-save.mjs +13 -6
  112. package/runtime/js/cm-prd/draft.mjs +31 -3
  113. package/runtime/js/cm-prd/failed-correction.mjs +19 -3
  114. package/runtime/js/cm-prd/inputs-replaced.mjs +3 -0
  115. package/runtime/js/cm-prd/review-correction.mjs +6 -4
  116. package/runtime/js/cm-prd/review-disposition.mjs +7 -1
  117. package/runtime/js/cm-prd/self-check-revision.mjs +2 -2
  118. package/runtime/js/cm-prd/self-check.mjs +125 -6
  119. package/runtime/js/cm-prd/session.mjs +30 -1
  120. package/runtime/js/cm-prd/summary.mjs +38 -17
  121. package/runtime/js/cm-prd/task-scope-record.mjs +97 -0
  122. package/runtime/js/cm-prd/tree-digest.mjs +34 -0
  123. package/runtime/js/cm-prd/validation-reason.mjs +8 -4
  124. package/runtime/js/cm-security/scan.mjs +1 -1
  125. package/runtime/js/commander/decision.mjs +44 -0
  126. package/runtime/js/commander/dispatch-registry.mjs +110 -0
  127. package/runtime/js/commander/ledger.mjs +265 -0
  128. package/runtime/js/commander/preflight.mjs +107 -0
  129. package/runtime/js/notify-later.mjs +13 -0
  130. package/runtime/js/notify-send.mjs +6 -2
  131. package/runtime/js/notify.mjs +570 -63
  132. package/runtime/js/review-findings.mjs +38 -0
  133. package/runtime/js/session-boundary.mjs +56 -0
  134. package/runtime/js/session-handoff.mjs +68 -0
  135. package/runtime/js/spec-task-line.mjs +27 -13
  136. package/runtime/js/specs-status.mjs +1 -1
  137. package/runtime/js/task-scope.mjs +197 -0
  138. package/runtime/logging.md +6 -1
  139. package/runtime/model-efficiency.md +69 -10
  140. package/runtime/orchestration.md +3 -1
  141. package/runtime/project-learning.md +2 -0
  142. package/runtime/review.md +12 -2
  143. package/runtime/test-contract.md +1 -0
  144. package/scripts/ci-test-weights.json +3 -0
  145. package/scripts/cm-ai-admission.mjs +11 -5
  146. package/scripts/cm-ai-admission.test.mjs +23 -2
  147. package/scripts/cm-ai-batch-drive.mjs +79 -18
  148. package/scripts/cm-ai-batch-drive.test.mjs +169 -3
  149. package/scripts/cm-ai-batch-host.mjs +38 -9
  150. package/scripts/cm-ai-batch-host.test.mjs +27 -14
  151. package/scripts/cm-ai-batch-learning-merge.test.mjs +36 -0
  152. package/scripts/cm-ai-batch-location.test.mjs +57 -0
  153. package/scripts/cm-ai-batch-plan.mjs +52 -0
  154. package/scripts/cm-ai-batch-plan.test.mjs +397 -0
  155. package/scripts/cm-ai-batch-run-fixture.mjs +446 -35
  156. package/scripts/cm-ai-batch-run-member-stops.test.mjs +16 -0
  157. package/scripts/cm-ai-batch-run-parallel.test.mjs +28 -1
  158. package/scripts/cm-ai-batch-run.mjs +483 -63
  159. package/scripts/cm-ai-batch-run.test.mjs +23 -4
  160. package/scripts/cm-ai-batch-session-e2e.test.mjs +235 -0
  161. package/scripts/cm-ai-batch-session-member.test.mjs +293 -0
  162. package/scripts/cm-ai-batch-session-recovery.test.mjs +423 -0
  163. package/scripts/cm-ai-check-recheck-cancellation.test.mjs +247 -0
  164. package/scripts/cm-ai-checklist-coverage.test.mjs +4 -2
  165. package/scripts/cm-ai-checkpoint-package-material.test.mjs +221 -0
  166. package/scripts/cm-ai-checkpoint-package-owner.test.mjs +193 -0
  167. package/scripts/cm-ai-control-launch.test.mjs +21 -0
  168. package/scripts/cm-ai-control-policy.test.mjs +82 -0
  169. package/scripts/cm-ai-control-v2-drive.test.mjs +398 -3
  170. package/scripts/cm-ai-control-v2-supersede-race.mjs +25 -0
  171. package/scripts/cm-ai-control-v2-supersede.test.mjs +318 -0
  172. package/scripts/cm-ai-develop-driver-gaps.test.mjs +163 -0
  173. package/scripts/cm-ai-development-rework.test.mjs +423 -0
  174. package/scripts/cm-ai-drive-bootstrap-rules.test.mjs +3 -2
  175. package/scripts/cm-ai-drive.mjs +73 -17
  176. package/scripts/cm-ai-drive.test.mjs +37 -5
  177. package/scripts/cm-ai-execution-store-legacy-probe.test.mjs +84 -0
  178. package/scripts/cm-ai-host-fixture.mjs +9 -6
  179. package/scripts/cm-ai-host-protected.test.mjs +1 -1
  180. package/scripts/cm-ai-host.mjs +60 -19
  181. package/scripts/cm-ai-host.test.mjs +15 -0
  182. package/scripts/cm-ai-integration-adoption.test.mjs +223 -0
  183. package/scripts/cm-ai-integration-independence.test.mjs +23 -0
  184. package/scripts/cm-ai-integration-launch.test.mjs +240 -0
  185. package/scripts/cm-ai-integration-preview.mjs +41 -0
  186. package/scripts/cm-ai-integration-snapshots.test.mjs +197 -0
  187. package/scripts/cm-ai-nested-execution.test.mjs +29 -1
  188. package/scripts/cm-ai-operator-guidance.test.mjs +71 -0
  189. package/scripts/cm-ai-prefinal-delivery.test.mjs +278 -0
  190. package/scripts/cm-ai-project-qa-gate.test.mjs +56 -0
  191. package/scripts/cm-ai-qa-fingerprint-config.test.mjs +28 -0
  192. package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +36 -2
  193. package/scripts/cm-ai-requirement-evidence.test.mjs +65 -0
  194. package/scripts/cm-ai-review-failure.test.mjs +150 -5
  195. package/scripts/cm-ai-review-timeout.test.mjs +20 -0
  196. package/scripts/cm-ai-run.mjs +88 -21
  197. package/scripts/cm-ai-scope-revision.test.mjs +341 -0
  198. package/scripts/cm-ai-spec-rebind.test.mjs +13 -0
  199. package/scripts/cm-ai-supersede.test.mjs +28 -0
  200. package/scripts/cm-ai-verification-auto.test.mjs +99 -0
  201. package/scripts/cm-announce-hook.mjs +35 -8
  202. package/scripts/cm-announce-hook.test.mjs +25 -0
  203. package/scripts/cm-challenge.test.mjs +61 -0
  204. package/scripts/cm-check-drive-files.mjs +2 -2
  205. package/scripts/cm-check-host.test.mjs +1 -1
  206. package/scripts/cm-check-runtime.sh +58 -1
  207. package/scripts/cm-claude-developer-worker.test.mjs +56 -7
  208. package/scripts/cm-claude-install-layout.test.mjs +1 -1
  209. package/scripts/cm-claude-probe.test.mjs +26 -0
  210. package/scripts/cm-claude-review-diagnostics.test.mjs +235 -0
  211. package/scripts/cm-claude-review-stream.test.mjs +49 -0
  212. package/scripts/cm-claude-worker.test.mjs +16 -0
  213. package/scripts/cm-codex-developer-reconnect-notice.test.mjs +98 -0
  214. package/scripts/cm-codex-developer-worker.test.mjs +120 -0
  215. package/scripts/cm-codex-install-local-edit-guard.test.mjs +436 -0
  216. package/scripts/cm-codex-prompt-input.test.mjs +153 -0
  217. package/scripts/cm-codex-reconnect-notice.test.mjs +167 -0
  218. package/scripts/cm-commander-ledger.test.mjs +260 -0
  219. package/scripts/cm-commander-p2.test.mjs +295 -0
  220. package/scripts/cm-commander-preflight.mjs +84 -0
  221. package/scripts/cm-commander.mjs +116 -0
  222. package/scripts/cm-config-lock.mjs +35 -0
  223. package/scripts/cm-controlled-correction.test.mjs +10 -1
  224. package/scripts/cm-developer-failure-code.test.mjs +62 -0
  225. package/scripts/cm-display-task-id.test.mjs +41 -0
  226. package/scripts/cm-drive-liveness.test.mjs +83 -0
  227. package/scripts/cm-efficiency-presentation-delta.test.mjs +218 -0
  228. package/scripts/cm-execution-snapshot-reuse.test.mjs +115 -0
  229. package/scripts/cm-external-batch-host.test.mjs +12 -9
  230. package/scripts/cm-external-process-cleanup.test.mjs +128 -0
  231. package/scripts/cm-external-qa-fix.test.mjs +89 -7
  232. package/scripts/cm-external-review-reconciliation.test.mjs +11 -0
  233. package/scripts/cm-failover.mjs +48 -10
  234. package/scripts/cm-failover.test.mjs +46 -0
  235. package/scripts/cm-fix-cause-invocation.test.mjs +19 -4
  236. package/scripts/cm-fix-command-correction.mjs +17 -0
  237. package/scripts/cm-fix-command-correction.test.mjs +211 -0
  238. package/scripts/cm-fix-cooperative-closeout.test.mjs +87 -0
  239. package/scripts/cm-fix-diagnosis-module-correction.test.mjs +217 -0
  240. package/scripts/cm-fix-drive.mjs +33 -5
  241. package/scripts/cm-fix-drive.test.mjs +49 -0
  242. package/scripts/cm-fix-host-review-assembly.test.mjs +197 -1
  243. package/scripts/cm-fix-host-review.test.mjs +21 -9
  244. package/scripts/cm-fix-host.mjs +26 -8
  245. package/scripts/cm-fix-monorepo-map.test.mjs +92 -0
  246. package/scripts/cm-fix-observation-task-id.test.mjs +122 -0
  247. package/scripts/cm-fix-regression-input-budget.test.mjs +111 -0
  248. package/scripts/cm-fix-repair-input-budget.test.mjs +119 -0
  249. package/scripts/cm-fix-review-file-paging.test.mjs +91 -0
  250. package/scripts/cm-fix-review-preflight.mjs +24 -0
  251. package/scripts/cm-fix-review-storage.test.mjs +233 -0
  252. package/scripts/cm-fix-review-verification-command.test.mjs +242 -0
  253. package/scripts/cm-fix-review-verification-evidence.test.mjs +218 -0
  254. package/scripts/cm-fix-review-verification-integration.test.mjs +81 -0
  255. package/scripts/cm-fix-review-verification-recovery.test.mjs +198 -0
  256. package/scripts/cm-fix-review-verification.test.mjs +146 -0
  257. package/scripts/cm-fix-revision-transport.test.mjs +81 -0
  258. package/scripts/cm-fix-source-correction.test.mjs +296 -0
  259. package/scripts/cm-fix-test-type-correction.mjs +18 -0
  260. package/scripts/cm-fix-test-type-correction.test.mjs +123 -0
  261. package/scripts/cm-fix-test-type-owner.test.mjs +208 -0
  262. package/scripts/cm-fix-test-type-verification-cost.test.mjs +66 -0
  263. package/scripts/cm-fix-type-import-correction.test.mjs +95 -0
  264. package/scripts/cm-fix-verification-diagnostic.test.mjs +200 -0
  265. package/scripts/cm-fix-verification-recovery.mjs +33 -0
  266. package/scripts/cm-host-diagnostic.test.mjs +33 -0
  267. package/scripts/cm-host-liveness.test.mjs +150 -0
  268. package/scripts/cm-host-qa-executor.test.mjs +77 -0
  269. package/scripts/cm-host-replay.test.mjs +176 -0
  270. package/scripts/cm-host-stage-observer.test.mjs +41 -0
  271. package/scripts/cm-install-local-edit-guard.test.mjs +621 -0
  272. package/scripts/cm-install-manifest.sh +351 -0
  273. package/scripts/cm-live-evidence.test.mjs +59 -1
  274. package/scripts/cm-log-event.mjs +61 -10
  275. package/scripts/cm-log-event.test.mjs +121 -1
  276. package/scripts/cm-matt-skills.mjs +576 -0
  277. package/scripts/cm-matt-skills.test.mjs +550 -0
  278. package/scripts/cm-notify-command.test.mjs +42 -10
  279. package/scripts/cm-notify.mjs +14 -10
  280. package/scripts/cm-notify.test.mjs +625 -75
  281. package/scripts/cm-patrol.mjs +4 -1
  282. package/scripts/cm-patrol.test.mjs +23 -5
  283. package/scripts/cm-prd-answer-gaps.test.mjs +2 -2
  284. package/scripts/cm-prd-completion.test.mjs +56 -13
  285. package/scripts/cm-prd-design-phase.test.mjs +78 -8
  286. package/scripts/cm-prd-draft-save.test.mjs +12 -0
  287. package/scripts/cm-prd-draft.test.mjs +1 -1
  288. package/scripts/cm-prd-drive.mjs +13 -6
  289. package/scripts/cm-prd-drive.test.mjs +46 -2
  290. package/scripts/cm-prd-gate-diagnostic.test.mjs +2 -2
  291. package/scripts/cm-prd-host.mjs +10 -5
  292. package/scripts/cm-prd-host.test.mjs +4 -2
  293. package/scripts/cm-prd-inputs-replaced.test.mjs +1 -1
  294. package/scripts/cm-prd-review-disposition.test.mjs +124 -8
  295. package/scripts/cm-prd-revision.test.mjs +1 -1
  296. package/scripts/cm-prd-self-check-revision.test.mjs +16 -1
  297. package/scripts/cm-prd-self-check-rules.test.mjs +239 -0
  298. package/scripts/cm-prd-self-check.test.mjs +105 -5
  299. package/scripts/cm-prd-session-recovery.test.mjs +5 -3
  300. package/scripts/cm-prd-summary.test.mjs +55 -3
  301. package/scripts/cm-prd-task-grouping.test.mjs +6 -6
  302. package/scripts/cm-prd-tree-digest.test.mjs +74 -0
  303. package/scripts/cm-refactor-drive.mjs +2 -1
  304. package/scripts/cm-refactor-drive.test.mjs +9 -0
  305. package/scripts/cm-release-smoke.sh +3 -15
  306. package/scripts/cm-skill-hints-autowire.test.mjs +394 -0
  307. package/scripts/cm-skill-hints-exam.mjs +149 -0
  308. package/scripts/cm-skill-hints-install.test.mjs +168 -0
  309. package/scripts/cm-skill-hints.exam.json +706 -0
  310. package/scripts/cm-skill-hints.json +119 -0
  311. package/scripts/cm-skill-hints.mjs +669 -0
  312. package/scripts/cm-skill-hints.test.mjs +831 -0
  313. package/scripts/cm-skill-judge.mjs +181 -0
  314. package/scripts/cm-skill-judge.test.mjs +255 -0
  315. package/scripts/cm-specs-status.test.mjs +4 -2
  316. package/scripts/cm-start-check.mjs +208 -0
  317. package/scripts/cm-start-check.test.mjs +321 -0
  318. package/scripts/cm-task-gate.mjs +150 -29
  319. package/scripts/cm-task-gate.test.mjs +73 -1
  320. package/scripts/cm-task-id-grammar.test.mjs +66 -0
  321. package/scripts/cm-task-scope.test.mjs +308 -0
  322. package/scripts/cm-test-suite.mjs +109 -0
  323. package/scripts/cm-test-suite.test.mjs +162 -0
  324. package/scripts/cm-upgrade-compat-batch.test.mjs +172 -0
  325. package/scripts/cm-upgrade-compat.test.mjs +239 -0
  326. package/scripts/cm-workflow-config.mjs +12 -2
  327. package/scripts/fixtures/fix-verification-claude.mjs +44 -0
  328. package/scripts/fixtures/host-diagnostic.mjs +33 -0
  329. package/scripts/fixtures/reviewed-integration.mjs +202 -0
  330. package/scripts/scan-public-safety.py +1 -0
  331. package/scripts/session-boundary.test.mjs +170 -0
  332. package/scripts/test-npm-install.py +14 -3
  333. package/scripts/test-shell-compat.sh +2 -0
  334. package/scripts/validate-public-repo.py +1 -0
  335. package/scripts/validate-test-cases.mjs +3 -2
  336. package/skills/cm-ai/SKILL.md +5 -2
  337. package/skills/cm-ai/references/N4-review.md +2 -1
  338. package/skills/cm-ai/references/N6-qa-eval.md +3 -1
  339. package/skills/cm-ai/references/N8-finish.md +22 -0
  340. package/skills/cm-ai/references/js-host-qa-recovery.md +1 -1
  341. package/skills/cm-ai/references/js-host-recovery.md +79 -3
  342. package/skills/cm-ai/references/js-host.md +89 -17
  343. package/skills/cm-challenge/SKILL.md +65 -0
  344. package/skills/cm-challenge/evals/README.md +18 -0
  345. package/skills/cm-challenge/evals/trigger-cases.json +20 -0
  346. package/skills/cm-challenge/evals/trigger-config.json +28 -0
  347. package/skills/cm-challenge/references/examples.md +15 -0
  348. package/skills/cm-check/SKILL.md +5 -0
  349. package/skills/cm-check/references/js-host.md +2 -0
  350. package/skills/cm-fix/SKILL.md +12 -3
  351. package/skills/cm-fix/references/command-correction.md +67 -0
  352. package/skills/cm-fix/references/isolated-review.md +54 -0
  353. package/skills/cm-fix/references/js-host.md +62 -2
  354. package/skills/cm-fix/references/test-type-correction.md +72 -0
  355. package/skills/cm-fix/references/verification-recovery.md +114 -0
  356. package/skills/cm-idea/SKILL.md +2 -0
  357. package/skills/cm-idea/references/js-host.md +2 -0
  358. package/skills/cm-notify/SKILL.md +2 -0
  359. package/skills/cm-prd/SKILL.md +12 -8
  360. package/skills/cm-prd/references/brownfield.md +8 -1
  361. package/skills/cm-prd/references/change-mode.md +6 -0
  362. package/skills/cm-prd/references/greenfield.md +4 -0
  363. package/skills/cm-prd/references/js-host.md +4 -2
  364. package/skills/cm-prd/references/spec-self-check.md +5 -1
  365. package/skills/cm-refactor/SKILL.md +8 -0
  366. package/skills/cm-refactor/references/js-host.md +2 -0
  367. package/skills/cm-test/SKILL.md +4 -0
  368. package/templates/dashboard/dashboard.html +2 -2
  369. package/templates/pixel/cm-pixel.html +1 -1
  370. package/templates/pixel/cm-pixel.sh +1 -1
  371. package/templates/pixel/dev/template.html +1 -1
  372. package/templates/statusline/cm-statusline.sh +1 -1
@@ -0,0 +1,200 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import fs from 'node:fs';
4
+ import os from 'node:os';
5
+ import path from 'node:path';
6
+ import {createHash} from 'node:crypto';
7
+ import * as verification from '../runtime/js/cm-fix/review-verification.mjs';
8
+ import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
9
+
10
+ const supported=process.platform==='darwin';
11
+ const nativeTypes=supported&&Number(process.versions.node.split('.')[0])>=24;
12
+ const sha=value=>createHash('sha256').update(value).digest('hex');
13
+ const diagnosticKeys=['version','requestDigest','packageDigest','profileDigest','providerThreadId','phase','code',
14
+ 'checkId','exitCode','outcome','outputSha256','runtimeFailure'].sort();
15
+ const privateMarker='SYNTHETIC_PRIVATE_OUTPUT_DO_NOT_PERSIST';
16
+ function fixture(t,{typeImport=false}={}){
17
+ const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-verification-diagnostic-')));
18
+ t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
19
+ const implementation=typeImport?'definitions.ts':'value.mjs',checkFile=typeImport?'consumer.ts':'value.test.mjs';
20
+ fs.writeFileSync(path.join(root,implementation),typeImport?'export type Marker=number;export const value=1;\n':'export const value=1;\n');
21
+ fs.writeFileSync(path.join(root,checkFile),typeImport?
22
+ "import {Marker,value} from './definitions.ts';const typed:Marker=value;export {typed};\n":
23
+ "import {value} from './value.mjs';if(value!==1)process.exit(1);\n");
24
+ const config={files:[implementation,checkFile],checks:[{id:'unit',command:[process.execPath,
25
+ ...(typeImport?['--experimental-strip-types']:[]),checkFile]}],mutationPaths:[implementation],timeoutMs:5000};
26
+ const files=config.files.map(p=>({path:p,sha256:sha(fs.readFileSync(path.join(root,p))),mode:fs.statSync(path.join(root,p)).mode&511}));
27
+ const reviewPackage={packageDigest:'b'.repeat(64),files};
28
+ const request={requestDigest:'a'.repeat(64),provider:'claude',payload:{reviewPackage}};
29
+ return {root,config,request,implementation,reviewPackage};
30
+ }
31
+ function open(f){return verification.createReviewVerificationSession({codeProject:f.root,configuration:f.config,request:f.request});}
32
+ function finishFailure(s){
33
+ let error;try{s.finish('fresh-review-thread');}catch(caught){error=caught;}
34
+ assert(error,'missing verification evidence must not become approval');
35
+ assert.equal(error.code,'review_verification_evidence','historical generic code stays compatible');
36
+ const diagnostic=s.diagnostic('fresh-review-thread',error,'finish');
37
+ assert.deepEqual(error.verificationDiagnostic,diagnostic);
38
+ return {error,diagnostic};
39
+ }
40
+ function assertBound(d,f){
41
+ assert.deepEqual(Object.keys(d).sort(),diagnosticKeys);
42
+ assert.equal(d.version,1);assert.equal(d.requestDigest,f.request.requestDigest);
43
+ assert.equal(d.packageDigest,f.reviewPackage.packageDigest);assert.equal(d.profileDigest,digest(f.config));
44
+ assert.equal(d.providerThreadId,'fresh-review-thread');
45
+ assert(!JSON.stringify(d).includes(f.root));assert(!JSON.stringify(d).includes(privateMarker));
46
+ }
47
+
48
+ test('Node type-only export failure keeps a bound check diagnostic after session cleanup',{skip:!nativeTypes},async t=>{
49
+ const f=fixture(t,{typeImport:true}),s=open(f);let saved;
50
+ try{
51
+ const check=await s.call('run_check',{id:'unit'});
52
+ assert.equal(check.outcome,'failed');assert.equal(check.exitCode,1);
53
+ assert.match(check.output,/does not provide an export named 'Marker'/);
54
+ const {diagnostic:d}=finishFailure(s);assertBound(d,f);
55
+ assert.equal(d.phase,'check');assert.equal(d.code,'review_verification_check_failed');
56
+ assert.equal(d.runtimeFailure,'module_export_missing');assert.equal(d.checkId,'unit');
57
+ assert.equal(d.exitCode,1);assert.equal(d.outcome,'failed');assert.equal(d.outputSha256,sha(check.output));
58
+ saved=JSON.stringify(d);
59
+ }finally{await s.close();}
60
+ assert.equal(fs.existsSync(s.cwd),false);
61
+ assert.equal(JSON.parse(saved).runtimeFailure,'module_export_missing');
62
+ });
63
+ test('successful checks without a mutation report the precise missing step',{skip:!supported},async t=>{
64
+ const f=fixture(t),s=open(f);try{
65
+ assert.equal((await s.call('run_check',{id:'unit'})).outcome,'passed');
66
+ const {diagnostic:d}=finishFailure(s);assertBound(d,f);
67
+ assert.equal(d.phase,'finish');assert.equal(d.code,'review_verification_mutation_missing');
68
+ assert.equal(d.runtimeFailure,null);
69
+ }finally{await s.close();}
70
+ });
71
+ for(const restoreFailed of [false,true]){
72
+ test(restoreFailed?'restoration check failure cannot be hidden as missing mutation':'surviving mutation reports its own failure with no private output',
73
+ {skip:!supported},async t=>{
74
+ const f=fixture(t),s=open(f);let calls=0;
75
+ try{
76
+ const tools=verification.createVerificationTools({...JSON.parse(fs.readFileSync(s.configPath,'utf8')),
77
+ runCommand:async()=>{
78
+ const i=calls++,failed=restoreFailed&&i>0;
79
+ return {exitCode:failed?1:0,outcome:failed?'failed':'passed',code:null,output:privateMarker};
80
+ }});
81
+ const result=await tools.call('mutate_check',{path:f.implementation,find:'value=1',replace:'value=2',checkId:'unit'});
82
+ assert.equal(result.killed,false);assert.equal(calls,3);
83
+ const {diagnostic:d}=finishFailure(s);assertBound(d,f);
84
+ assert.equal(d.code,restoreFailed?'review_verification_restore_failed':'review_verification_mutation_survived');
85
+ assert.equal(d.phase,restoreFailed?'restore':'mutation');assert.equal(d.checkId,'unit');
86
+ assert.equal(d.exitCode,restoreFailed?1:0);assert.equal(d.outputSha256,sha(privateMarker));
87
+ assert(!fs.readFileSync(path.join(path.dirname(s.cwd),'evidence.json'),'utf8').includes(privateMarker));
88
+ for(const name of fs.readdirSync(path.dirname(s.cwd)).filter(p=>p.includes('diagnostic')))
89
+ assert(!fs.readFileSync(path.join(path.dirname(s.cwd),name),'utf8').includes(privateMarker));
90
+ assert.equal(fs.readFileSync(path.join(f.root,f.implementation),'utf8'),'export const value=1;\n');
91
+ }finally{await s.close();}
92
+ });
93
+ }
94
+ test('baseline-only verification succeeds without requiring or inventing a mutation',{skip:!supported},async t=>{
95
+ const f=fixture(t),before=sha(fs.readFileSync(path.join(f.root,f.implementation)));
96
+ const result=await verification.verifyReviewVerificationBaseline({codeProject:f.root,configuration:f.config,reviewPackage:f.reviewPackage});
97
+ assert.equal(result.files.length,f.config.files.length);assert.equal(result.snapshotDigest,digest(result.files));
98
+ assert.equal(result.checks.length,1);assert.equal(result.checks[0].id,'unit');assert.equal(result.checks[0].exitCode,0);
99
+ assert.equal(sha(fs.readFileSync(path.join(f.root,f.implementation))),before);
100
+ });
101
+ test('baseline-only verification refuses an incompatible frozen check with safe diagnostics',{skip:!nativeTypes},async t=>{
102
+ const f=fixture(t,{typeImport:true});
103
+ await assert.rejects(verification.verifyReviewVerificationBaseline({codeProject:f.root,configuration:f.config,reviewPackage:f.reviewPackage}),error=>{
104
+ const d=error.verificationDiagnostic;
105
+ assert(d);assert.equal(d.phase,'check');assert.equal(d.code,'review_verification_check_failed');
106
+ assert.equal(d.runtimeFailure,'module_export_missing');assert.equal(d.providerThreadId,null);
107
+ assert.equal(d.packageDigest,f.reviewPackage.packageDigest);assert.equal(d.profileDigest,digest(f.config));
108
+ assert.equal(d.exitCode,1);assert.equal(d.outcome,'failed');assert.match(d.outputSha256,/^[a-f0-9]{64}$/);
109
+ assert(!JSON.stringify(d).includes(f.root));assert(!Object.hasOwn(d,'output'));return true;
110
+ });
111
+ });
112
+ for(const drift of [false,true]){
113
+ test(drift?'source drift outranks a recovered check failure':'a recovered check failure does not hide a missing mutation',
114
+ {skip:!supported},async t=>{
115
+ const f=fixture(t),s=open(f);let calls=0;
116
+ try{
117
+ const tools=verification.createVerificationTools({...JSON.parse(fs.readFileSync(s.configPath,'utf8')),
118
+ runCommand:async()=>{
119
+ const failed=calls++===0;
120
+ return {exitCode:failed?1:0,outcome:failed?'failed':'passed',code:null,output:failed?privateMarker:'passed'};
121
+ }});
122
+ assert.equal((await tools.call('run_check',{id:'unit'})).outcome,'failed');
123
+ assert.equal((await tools.call('run_check',{id:'unit'})).outcome,'passed');
124
+ if(drift)fs.writeFileSync(path.join(f.root,f.implementation),'export const value=2;\n');
125
+ let error;try{s.finish('fresh-review-thread');}catch(caught){error=caught;}
126
+ assert(error);assert.equal(error.code,drift?'review_verification_source_drift':'review_verification_evidence');
127
+ const d=s.diagnostic('fresh-review-thread',error,'finish');assertBound(d,f);
128
+ assert.deepEqual(error.verificationDiagnostic,d);
129
+ assert.equal(d.code,drift?'review_verification_source_drift':'review_verification_mutation_missing');
130
+ assert.equal(d.phase,'finish');assert.equal(d.exitCode,null);assert.equal(d.outputSha256,null);
131
+ }finally{await s.close();}
132
+ });
133
+ }
134
+ test('baseline package binding failure carries a safe snapshot diagnostic',{skip:!supported},async t=>{
135
+ const f=fixture(t),reviewPackage=structuredClone(f.reviewPackage);
136
+ reviewPackage.files[0].sha256='f'.repeat(64);
137
+ await assert.rejects(verification.verifyReviewVerificationBaseline({codeProject:f.root,configuration:f.config,reviewPackage}),error=>{
138
+ assert.equal(error.code,'review_verification_package_binding');
139
+ const d=error.verificationDiagnostic;assert(d);assert.deepEqual(Object.keys(d).sort(),diagnosticKeys);
140
+ assert.equal(d.code,'review_verification_package_binding');assert.equal(d.phase,'snapshot');
141
+ assert.equal(d.packageDigest,reviewPackage.packageDigest);assert.equal(d.profileDigest,digest(f.config));
142
+ assert.match(d.requestDigest,/^[a-f0-9]{64}$/);assert.equal(d.providerThreadId,null);
143
+ assert.equal(d.outputSha256,null);assert.equal(d.runtimeFailure,null);
144
+ assert(!JSON.stringify(d).includes(f.root));assert(!Object.hasOwn(d,'output'));return true;
145
+ });
146
+ });
147
+ test('unavailable check preserves its bounded timeout reason',{skip:!supported},async t=>{
148
+ const f=fixture(t),s=open(f);
149
+ try{
150
+ const tools=verification.createVerificationTools({...JSON.parse(fs.readFileSync(s.configPath,'utf8')),
151
+ runCommand:async()=>({exitCode:null,outcome:'unavailable',code:'verification_timeout',output:privateMarker})});
152
+ assert.equal((await tools.call('run_check',{id:'unit'})).outcome,'unavailable');
153
+ const {diagnostic:d}=finishFailure(s);assertBound(d,f);
154
+ assert.equal(d.phase,'check');assert.equal(d.code,'verification_timeout');assert.equal(d.checkId,'unit');
155
+ assert.equal(d.outcome,'unavailable');assert.equal(d.exitCode,null);assert.equal(d.outputSha256,sha(privateMarker));
156
+ }finally{await s.close();}
157
+ });
158
+ for(const prior of ['worker','mutation']){
159
+ test(`resolved ${prior} diagnostic does not hide a different missing check`,{skip:!supported},async t=>{
160
+ const f=fixture(t);
161
+ f.config.checks.push({id:'other',command:[process.execPath,'-e','process.exit(0)']});
162
+ if(prior==='mutation')f.config.checks.push({id:'missing',command:[process.execPath,'-e','process.exit(0)']});
163
+ const s=open(f);let calls=0;
164
+ try{
165
+ const tools=verification.createVerificationTools({...JSON.parse(fs.readFileSync(s.configPath,'utf8')),
166
+ runCommand:async()=>{
167
+ const exitCode=calls++===(prior==='worker'?2:4)?1:0;
168
+ return {exitCode,outcome:exitCode?'failed':'passed',code:null,output:'bounded output'};
169
+ }});
170
+ const mutation=checkId=>tools.call('mutate_check',{path:f.implementation,find:'value=1',replace:'value=2',checkId});
171
+ if(prior==='worker'){
172
+ await assert.rejects(tools.call('mutate_check',{path:f.implementation,find:'absent-token',replace:'replacement',checkId:'unit'}),{code:'review_verification_mutation'});
173
+ assert.equal((await tools.call('run_check',{id:'unit'})).outcome,'passed');
174
+ assert.equal((await mutation('unit')).killed,true);
175
+ }else{
176
+ assert.equal((await mutation('unit')).killed,false);
177
+ assert.equal((await mutation('other')).killed,true);
178
+ }
179
+ const {diagnostic:d}=finishFailure(s);assertBound(d,f);
180
+ assert.equal(d.code,'review_verification_check_missing');assert.equal(d.phase,'finish');
181
+ }finally{await s.close();}
182
+ });
183
+ }
184
+ for(const target of ['source','copy']){
185
+ test(`${target} drift outranks a still-unresolved failed check`,{skip:!supported},async t=>{
186
+ const f=fixture(t),s=open(f);
187
+ try{
188
+ const tools=verification.createVerificationTools({...JSON.parse(fs.readFileSync(s.configPath,'utf8')),
189
+ runCommand:async()=>({exitCode:1,outcome:'failed',code:null,output:privateMarker})});
190
+ assert.equal((await tools.call('run_check',{id:'unit'})).outcome,'failed');
191
+ fs.writeFileSync(path.join(target==='source'?f.root:s.cwd,f.implementation),'export const value=2;\n');
192
+ assert.throws(()=>s.finish('fresh-review-thread'),error=>{
193
+ assert.equal(error.code,`review_verification_${target}_drift`);
194
+ assertBound(error.verificationDiagnostic,f);
195
+ assert.equal(error.verificationDiagnostic.code,error.code);
196
+ assert.equal(error.verificationDiagnostic.phase,'finish');return true;
197
+ });
198
+ }finally{await s.close();}
199
+ });
200
+ }
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env node
2
+ // Read-only inspection: no writer, provider, installation, or source writes.
3
+ import fs from 'node:fs';
4
+ import path from 'node:path';
5
+ import {fileURLToPath} from 'node:url';
6
+ import {inspectFixVerificationRecovery} from '../runtime/js/cm-fix/execution.mjs';
7
+ import {inspectVerificationDiagnostic} from '../runtime/js/cm-fix/review-verification-diagnostic.mjs';
8
+ import {readExecutionSnapshot} from '../runtime/js/cm-ai/execution-snapshot.mjs';
9
+ import {digest,need} from '../runtime/js/cm-ai/effect-contract.mjs';
10
+ export async function main(argv=process.argv.slice(2),{output=process.stdout,error=process.stderr}={}){
11
+ let configuration,reviewPackage;
12
+ try{
13
+ need([2,4].includes(argv.length)&&argv[0]==='--config'&&(argv.length===2||argv[2]==='--source-correction'),'invalid_arguments');
14
+ let sourceCorrection;
15
+ if(argv.length===4){
16
+ const stat=fs.lstatSync(argv[3]);need(stat.isFile()&&!stat.isSymbolicLink()&&stat.size<=64*1024,'invalid_arguments');
17
+ sourceCorrection=JSON.parse(fs.readFileSync(argv[3],'utf8'));
18
+ }
19
+ const c=JSON.parse(fs.readFileSync(argv[1],'utf8'));
20
+ const specsRoot=fs.realpathSync(c.specsRoot??path.join(c.reproduction.cwd,'docs','fixes'));
21
+ const snapshot=readExecutionSnapshot({specsRoot,identity:{repositoryId:c.identity.repositoryId,runId:c.identity.runId}});
22
+ need(digest(c.identity)===digest(snapshot.records[0].payload.identity),'fix_verification_recovery_binding');
23
+ configuration=snapshot.records[0].payload.configuration.reviewVerification;reviewPackage=snapshot.records.findLast(r=>r.id.endsWith('-registered')&&r.payload.request?.role==='reviewer')?.payload.request.payload.reviewPackage;
24
+ const expected=await inspectFixVerificationRecovery({specsRoot,identity:{repositoryId:c.identity.repositoryId,runId:c.identity.runId},...(sourceCorrection===undefined?{}:{sourceCorrection})});
25
+ output.write(JSON.stringify({eligible:true,expected})+'\n');return 0;
26
+ }catch(e){
27
+ const code=/^[a-z_]{1,64}$/.test(e?.code??'')?e.code:'fix_verification_recovery_unavailable';
28
+ // Only contract-validated structured diagnostics, never raw errors/command output.
29
+ let diagnostic;try{if(e.verificationDiagnostic&&configuration&&reviewPackage)diagnostic=inspectVerificationDiagnostic(e.verificationDiagnostic,{configuration,providerThreadId:null,request:{provider:'claude',requestDigest:digest({packageDigest:reviewPackage.packageDigest,profile:configuration}),payload:{reviewPackage}}});}catch{}
30
+ error.write(JSON.stringify({eligible:false,code,...(diagnostic?{verificationDiagnostic:diagnostic}:{})})+'\n');return 1;
31
+ }
32
+ }
33
+ if(process.argv[1]&&path.resolve(process.argv[1])===fileURLToPath(import.meta.url))process.exitCode=await main();
@@ -0,0 +1,33 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import {EventEmitter} from 'node:events';
4
+ import {hostDiagnostic} from './fixtures/host-diagnostic.mjs';
5
+
6
+ function fixture(){
7
+ const child=new EventEmitter();child.pid=123;child.stdout=new EventEmitter();child.stderr=new EventEmitter();
8
+ let clock=10;const trace=hostDiagnostic(child,{timeoutMs:60000,now:()=>clock});
9
+ return {child,trace,tick:ms=>{clock+=ms;}};
10
+ }
11
+ test('fixture diagnostics retain last stage, time budget and child exit without changing the failure',()=>{
12
+ const {child,trace,tick}=fixture();trace.send({operation:'advance',requestId:'private-request'});tick(30);
13
+ trace.receive({type:'host_request',kind:'develop',payload:{private:'source'}});tick(50);
14
+ trace.receive({result:{state:'blocked',code:'develop_answer_missing'}});
15
+ child.stderr.emit('data',Buffer.from('private stderr'));child.emit('close',7,'SIGTERM');
16
+ const failure=new Error('fixture failure');assert.equal(trace.attach(failure),failure);
17
+ const data=failure.diagnostic;
18
+ assert.equal(data.timeoutMs,60000);assert.equal(data.elapsedMs,80);assert.equal(data.lastKind,'develop');
19
+ assert.equal(data.lastState,'blocked');assert.equal(data.lastCode,'develop_answer_missing');
20
+ assert.equal(data.exitCode,7);assert.equal(data.signal,'SIGTERM');assert.equal(data.closed,true);
21
+ assert.equal(data.stderrBytes,14);assert.equal(data.lastOperation,'advance');
22
+ assert(!JSON.stringify(data).includes('private'));
23
+ });
24
+ test('fixture diagnostics bound history and allowlist even hostile metadata',()=>{
25
+ const {child,trace}=fixture(),secret='private-synthetic-secret';
26
+ for(let i=0;i<80;i++)trace.receive({type:secret,kind:secret,requestId:secret,
27
+ result:{state:secret,code:secret},payload:{text:secret}});
28
+ child.stdout.emit('data',Buffer.from(secret));child.stderr.emit('data',Buffer.from(secret));child.emit('close',null,secret);
29
+ const data=trace.snapshot();assert.equal(data.events.length,32);assert.equal(data.eventCount,80);
30
+ assert.equal(data.lastKind,'other');assert.equal(data.lastCode,'other');assert.equal(data.signal,'other');
31
+ assert(!JSON.stringify(data).includes(secret));assert(JSON.stringify(data).length<6000);
32
+ data.events[0].kind=secret;assert(!JSON.stringify(trace.snapshot()).includes(secret));
33
+ });
@@ -0,0 +1,150 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import {PassThrough} from 'node:stream';
4
+ import {createHostToolBridge} from '../runtime/js/cm-ai/host-tool-bridge.mjs';
5
+ import {serveCmAiHost} from '../runtime/js/cm-ai/host-session.mjs';
6
+ import {beginHostStage} from '../runtime/js/cm-ai/host-stage-observer.mjs';
7
+
8
+ const tick=()=>new Promise(resolve=>setImmediate(resolve));
9
+ async function waitFor(rows,predicate,timeout=1500){
10
+ const end=Date.now()+timeout;
11
+ while(Date.now()<end){const found=rows.find(predicate);if(found)return found;await new Promise(resolve=>setTimeout(resolve,5));}
12
+ assert.fail(`missing row: ${JSON.stringify(rows)}`);
13
+ }
14
+ function session(handle,{heartbeat=false}={}){
15
+ const input=new PassThrough(),output=new PassThrough(),rows=[],bridge=createHostToolBridge();
16
+ output.on('data',chunk=>{for(const line of chunk.toString().trim().split('\n'))if(line)rows.push(JSON.parse(line));});
17
+ const serving=serveCmAiHost({host:{handle:(request)=>handle(request,bridge)},input,output,toolBridge:bridge,heartbeat});
18
+ return {rows,bridge,input,serving,send:row=>input.write(JSON.stringify(row)+'\n')};
19
+ }
20
+
21
+ test('host busy explains active request and close refuses a running operation without stopping it',async()=>{
22
+ let resolve;const done=new Promise(r=>{resolve=r;});
23
+ const s=session(async()=>{await done;return {outcome:'complete'};});
24
+ try{
25
+ const ready=await waitFor(s.rows,r=>r.type==='host_ready');
26
+ s.send({requestId:'first',operation:'advance'});await tick();
27
+ s.send({requestId:'second',operation:'advance'});
28
+ const busy=await waitFor(s.rows,r=>r.requestId==='second');
29
+ assert.equal(busy.error.code,'host_busy');assert.equal(busy.error.inFlight.requestId,'first');
30
+ assert.equal(busy.error.inFlight.operation,'advance');assert.equal(busy.error.inFlight.stage,'advance');
31
+ assert.ok(Number.isFinite(Date.parse(busy.error.inFlight.startedAt)));assert.match(busy.error.message,/继续等待/);
32
+ s.send({type:'host_close',sessionId:ready.sessionId});
33
+ const refused=await waitFor(s.rows,r=>r.type==='host_response');
34
+ assert.equal(refused.code,'host_close_busy');assert.equal(refused.accepted,false);
35
+ assert.equal(refused.inFlight.requestId,'first');
36
+ resolve();await waitFor(s.rows,r=>r.requestId==='first');
37
+ s.send({type:'host_close',sessionId:ready.sessionId});await s.serving;
38
+ assert.equal(s.rows.at(-1).closing,true);
39
+ }finally{resolve();s.input.end();await s.serving;}
40
+ });
41
+
42
+ test('bridge close validates session and force, exposes metadata only and preserves pending reply',async()=>{
43
+ const bridge=createHostToolBridge(),rows=[];bridge.attach(row=>{rows.push(row);});
44
+ const pending=bridge.call('develop',{secret:'never expose this'},new AbortController().signal,{timeoutMs:1000});
45
+ try{
46
+ await tick();const request=rows.find(r=>r.type==='host_request'),snapshot=bridge.inFlight();
47
+ assert.deepEqual(Object.keys(snapshot).sort(),['callId','deadlineMs','kind','startedAt']);
48
+ assert.equal(snapshot.kind,'develop');assert.equal(snapshot.deadlineMs-Date.parse(snapshot.startedAt),1000);
49
+ assert.equal(bridge.accept({type:'host_close',sessionId:'wrong',force:true}).code,'host_response_mismatch');
50
+ assert.equal(bridge.accept({type:'host_close',sessionId:request.sessionId,force:'true'}).code,'host_response_mismatch');
51
+ assert.equal(bridge.accept({type:'host_close',sessionId:request.sessionId}).code,'host_close_busy');
52
+ assert.equal(bridge.accept({...request,type:'host_result',kind:undefined,payload:undefined}).accepted,false);
53
+ const result={type:'host_result',sessionId:request.sessionId,callId:request.callId,requestDigest:request.requestDigest,result:{ok:true}};
54
+ assert.equal(bridge.accept(result).accepted,true);assert.deepEqual(await pending,{ok:true});
55
+ assert.equal(bridge.inFlight(),null);assert.equal(bridge.accept({type:'host_close',sessionId:request.sessionId}).closing,true);
56
+ }finally{bridge.close();await pending.catch(()=>{});}
57
+ });
58
+
59
+ test('forced close explicitly warns and interrupts a pending bridge call',{timeout:3000},async()=>{
60
+ const s=session(async(request,bridge)=>{try{await bridge.call('develop',{},new AbortController().signal);return {bad:true};}catch(error){return {code:error.code};}});
61
+ try{
62
+ const ready=await waitFor(s.rows,r=>r.type==='host_ready');s.send({requestId:'active',operation:'advance'});
63
+ await waitFor(s.rows,r=>r.type==='host_request');s.send({type:'host_close',sessionId:ready.sessionId,force:true});
64
+ const closed=await waitFor(s.rows,r=>r.type==='host_response');assert.equal(closed.closing,true);
65
+ await s.serving;assert.match(closed.warning,/unknown/);
66
+ assert.equal(s.rows.find(r=>r.requestId==='active').result.code,'host_disconnected');
67
+ }finally{s.input.end();await s.serving;}
68
+ });
69
+
70
+ test('heartbeat is opt-in, contains no payload, and idle ticks do not claim progress or poll runner',{timeout:14000},async()=>{
71
+ let calls=0;const s=session(async(request,bridge)=>{calls++;return bridge.call('check',{private:'payload'},new AbortController().signal,{timeoutMs:13000});},{heartbeat:true});
72
+ try{
73
+ const ready=await waitFor(s.rows,r=>r.type==='host_ready');assert.deepEqual(ready.heartbeat,{intervalMs:5000,timeoutMs:30000});
74
+ const first=await waitFor(s.rows,r=>r.type==='host_heartbeat');assert.equal(first.inFlight,null);
75
+ s.send({requestId:'check',operation:'advance'});const request=await waitFor(s.rows,r=>r.type==='host_request');
76
+ const beat=await waitFor(s.rows,r=>r.type==='host_heartbeat'&&r.inFlight?.call,6000);
77
+ assert.equal(beat.inFlight.stage,'check');assert.equal(beat.inFlight.call.kind,'check');assert.equal(beat.pid,process.pid);
78
+ assert.equal(beat.sessionId,ready.sessionId);assert.equal(calls,1);assert.equal(JSON.stringify(beat).includes('payload'),false);
79
+ assert.equal(beat.lastProgressAt,beat.inFlight.call.startedAt);
80
+ const second=await waitFor(s.rows,r=>r.type==='host_heartbeat'&&r.at!==beat.at&&r.inFlight?.call,6000);
81
+ assert.equal(second.lastProgressAt,beat.lastProgressAt);assert.deepEqual(second.inFlight,beat.inFlight);
82
+ s.send({type:'host_result',sessionId:ready.sessionId,callId:request.callId,requestDigest:request.requestDigest,result:{ok:true}});
83
+ await waitFor(s.rows,r=>r.requestId==='check');s.send({type:'host_close',sessionId:ready.sessionId});await s.serving;
84
+ const old=session(async()=>({ok:true}));const oldReady=await waitFor(old.rows,r=>r.type==='host_ready');
85
+ assert.equal(oldReady.heartbeat,undefined);assert.equal(old.rows.some(r=>r.type==='host_heartbeat'),false);
86
+ old.send({type:'host_close',sessionId:oldReady.sessionId});await old.serving;
87
+ }finally{s.input.end();await s.serving;}
88
+ });
89
+
90
+ for(const operation of ['status','cancel'])test(`close refuses in-flight ${operation} control`,async()=>{
91
+ let resolve;const done=new Promise(r=>{resolve=r;});const s=session(async()=>{await done;return {ok:true};});
92
+ try{
93
+ const ready=await waitFor(s.rows,r=>r.type==='host_ready');s.send({requestId:'control',operation});await tick();
94
+ s.send({type:'host_close',sessionId:ready.sessionId});
95
+ const refused=await waitFor(s.rows,r=>r.type==='host_response');
96
+ assert.equal(refused.code,'host_close_busy');assert.equal(refused.inFlight.operation,operation);
97
+ resolve();await waitFor(s.rows,r=>r.requestId==='control');s.send({type:'host_close',sessionId:ready.sessionId});await s.serving;
98
+ }finally{resolve();s.input.end();await s.serving;}
99
+ });
100
+
101
+ test('poll reusing requestId cannot release a different running operation',async()=>{
102
+ let resolve;const done=new Promise(r=>{resolve=r;});const s=session(async request=>{
103
+ if(request.operation==='advance')await done;return {operation:request.operation};
104
+ });
105
+ try{
106
+ const ready=await waitFor(s.rows,r=>r.type==='host_ready');s.send({requestId:'same',operation:'advance'});await tick();
107
+ s.send({requestId:'same',operation:'status'});await waitFor(s.rows,r=>r.result?.operation==='status');
108
+ s.send({type:'host_close',sessionId:ready.sessionId});
109
+ const refused=await waitFor(s.rows,r=>r.type==='host_response');assert.equal(refused.code,'host_close_busy');
110
+ assert.equal(refused.inFlight.operation,'advance');resolve();await waitFor(s.rows,r=>r.result?.operation==='advance');
111
+ s.send({type:'host_close',sessionId:ready.sessionId});await s.serving;
112
+ }finally{resolve();s.input.end();await s.serving;}
113
+ });
114
+
115
+ test('close sent synchronously when the result is written is allowed',async()=>{
116
+ const input=new PassThrough(),output=new PassThrough(),bridge=createHostToolBridge(),rows=[];let sessionId;
117
+ output.on('data',chunk=>{for(const line of chunk.toString().trim().split('\n'))if(line){
118
+ const row=JSON.parse(line);rows.push(row);
119
+ if(row.type==='host_ready'){sessionId=row.sessionId;input.write(JSON.stringify({requestId:'instant',operation:'advance'})+'\n');}
120
+ if(row.requestId==='instant')input.write(JSON.stringify({type:'host_close',sessionId})+'\n');
121
+ }});
122
+ const serving=serveCmAiHost({host:{handle:async()=>({ok:true})},input,output,toolBridge:bridge});
123
+ try{const closed=await waitFor(rows,r=>r.type==='host_response');assert.equal(closed.closing,true);await serving;assert.equal(rows.some(r=>r.code==='host_close_busy'),false);}
124
+ finally{input.end();await serving;}
125
+ });
126
+
127
+ test('CM_HOST_HEARTBEAT enables the wire contract without changing host operations',async()=>{
128
+ const previous=process.env.CM_HOST_HEARTBEAT;process.env.CM_HOST_HEARTBEAT='1';
129
+ const input=new PassThrough(),output=new PassThrough(),bridge=createHostToolBridge(),rows=[];
130
+ output.on('data',chunk=>{for(const line of chunk.toString().trim().split('\n'))if(line)rows.push(JSON.parse(line));});
131
+ const serving=serveCmAiHost({host:{handle:async()=>assert.fail('heartbeat must not invoke host')},input,output,toolBridge:bridge});
132
+ try{
133
+ const ready=await waitFor(rows,r=>r.type==='host_ready');assert.deepEqual(ready.heartbeat,{intervalMs:5000,timeoutMs:30000});
134
+ await waitFor(rows,r=>r.type==='host_heartbeat');input.write(JSON.stringify({type:'host_close',sessionId:ready.sessionId})+'\n');await serving;
135
+ }finally{input.end();await serving;if(previous===undefined)delete process.env.CM_HOST_HEARTBEAT;else process.env.CM_HOST_HEARTBEAT=previous;}
136
+ });
137
+
138
+ test('native stage exposes its real budget without requiring a bridge call',async()=>{
139
+ let resolve;const done=new Promise(r=>{resolve=r;});const s=session(async()=>{
140
+ const end=beginHostStage('check',5000);try{await done;return {ok:true};}finally{end();}
141
+ });
142
+ try{
143
+ const ready=await waitFor(s.rows,r=>r.type==='host_ready');s.send({requestId:'native',operation:'advance'});await tick();
144
+ s.send({requestId:'duplicate',operation:'advance'});const busy=await waitFor(s.rows,r=>r.requestId==='duplicate');
145
+ assert.equal(busy.error.inFlight.stage,'check');assert.equal(busy.error.inFlight.call,null);
146
+ const stage=busy.error.inFlight.nativeStage;assert.equal(stage.kind,'check');assert.equal(stage.deadlineMs-Date.parse(stage.startedAt),5000);
147
+ s.send({type:'host_close',sessionId:ready.sessionId});assert.equal((await waitFor(s.rows,r=>r.type==='host_response')).code,'host_close_busy');
148
+ resolve();await waitFor(s.rows,r=>r.requestId==='native');s.send({type:'host_close',sessionId:ready.sessionId});await s.serving;
149
+ }finally{resolve();s.input.end();await s.serving;}
150
+ });
@@ -1363,3 +1363,80 @@ test('a correction never changes anything but evidence: required cleanup not don
1363
1363
  }finally{f.cleanup();}
1364
1364
  }
1365
1365
  });
1366
+
1367
+ // AI潮: screenshots taken by the UI tests land outside the specs root; answers that named
1368
+ // them were BLOCKED. Each browser case is now told where its evidence is accepted from.
1369
+ test('each browser case request names an evidence directory inside .reviews, and files put there pass',async()=>{
1370
+ const f=fixture();
1371
+ try{
1372
+ f.configuration.commands[0].caseIds=[];const seen=[];
1373
+ const executor=createHostQaExecutor({...f.configuration,
1374
+ logic:async()=>({verdict:'INSUFFICIENT_EVIDENCE',evidence:['Synthetic static observation']}),
1375
+ browser:async request=>{seen.push(request);
1376
+ fs.mkdirSync(request.evidenceDirectory,{recursive:true});
1377
+ const file=path.join(request.evidenceDirectory,'walk.txt');fs.writeFileSync(file,'Synthetic observation');
1378
+ return {verdict:'PASS',evidence:[file],environment:request.environment,cleanup:'completed'};}});
1379
+ const binding=begin(f,executor),result=await executor.run(binding,new AbortController().signal);
1380
+ assert(seen.length>=1);
1381
+ for(const request of seen){
1382
+ assert.equal(request.evidenceDirectory,path.join(f.binding.specsDir,'.reviews','qa-evidence',f.binding.testRunId,request.case.id));
1383
+ }
1384
+ const rows=fs.readFileSync(result.report,'utf8').split(/^## /m).slice(1).map(part=>JSON.parse(part.slice(part.indexOf('\n')+1)))
1385
+ .filter(row=>row.kind==='browser');
1386
+ for(const row of rows){assert.equal(row.verdict,'PASS');assert.equal(row.answerCorrection,undefined);}
1387
+ }finally{f.cleanup();}
1388
+ });
1389
+
1390
+ test('the host only names the evidence directory: nothing is created, and a symlinked location still yields no PASS',async()=>{
1391
+ const f=fixture();
1392
+ try{
1393
+ f.configuration.commands[0].caseIds=[];const seen=[];
1394
+ const outside=path.join(f.root,'elsewhere');fs.mkdirSync(outside);
1395
+ fs.symlinkSync(outside,path.join(f.binding.specsDir,'.reviews','qa-evidence'));
1396
+ const executor=createHostQaExecutor({...f.configuration,
1397
+ logic:async()=>({verdict:'INSUFFICIENT_EVIDENCE',evidence:['Synthetic static observation']}),
1398
+ browser:async request=>{seen.push(request);
1399
+ if(request.correction)return {verdict:'BLOCKED',evidence:[],environment:request.environment,cleanup:'not_needed'};
1400
+ assert.deepEqual(fs.readdirSync(outside),[],'the host wrote nothing through the link');
1401
+ fs.mkdirSync(request.evidenceDirectory,{recursive:true});
1402
+ const file=path.join(request.evidenceDirectory,'walk.txt');fs.writeFileSync(file,'Synthetic observation');
1403
+ return {verdict:'PASS',evidence:[file],environment:request.environment,cleanup:'completed'};}});
1404
+ const binding=begin(f,executor),result=await executor.run(binding,new AbortController().signal);
1405
+ assert(seen.length>=1);
1406
+ const rows=fs.readFileSync(result.report,'utf8').split(/^## /m).slice(1).map(part=>JSON.parse(part.slice(part.indexOf('\n')+1)))
1407
+ .filter(row=>row.kind==='browser');
1408
+ for(const row of rows)assert.equal(row.verdict,'BLOCKED');
1409
+ }finally{f.cleanup();}
1410
+ });
1411
+
1412
+ test('reuseCheck takes only an identical passed task check; otherwise the command runs and the row says why',async()=>{
1413
+ for(const [name,checks,expected] of [
1414
+ ['passed',[{id:'tests',outcome:'passed',exitCode:0,evidence:'fixture'}],null],
1415
+ ['failed',[{id:'tests',outcome:'failed',exitCode:1,evidence:'fixture'}],'check_not_passed'],
1416
+ ['unavailable',[{id:'tests',outcome:'unavailable',exitCode:null,evidence:'host check: timeout'}],'check_not_passed'],
1417
+ ['not handed over',null,'no_verified_task_checks']]){
1418
+ const f=fixture();
1419
+ try{
1420
+ fs.unlinkSync(path.join(f.configuration.specsDir,f.configuration.feature,'test-cases.json'));
1421
+ const command=[process.execPath,'--test','check.test.mjs'];
1422
+ f.configuration.commands=[{id:'declared-test',command,caseIds:[],reuseCheck:'tests'}];
1423
+ const executor=createHostQaExecutor(f.configuration);
1424
+ const binding=begin(f,executor);
1425
+ const result=await executor.run(checks===null?binding:{...binding,completionChecks:checks.map(item=>({...item,command}))},
1426
+ new AbortController().signal);
1427
+ const row=fs.readFileSync(result.report,'utf8').split(/^## /m).slice(1).map(part=>JSON.parse(part.slice(part.indexOf('\n')+1)))
1428
+ .find(item=>item.id==='declared-test');
1429
+ assert.equal(row.verdict,'PASS',name);
1430
+ if(expected===null){assert.equal(row.reusedCheck,'tests');assert.match(row.evidence[0],/^reused task check tests /);}
1431
+ else{assert.equal(row.reuseUnavailable,expected,name);assert.equal(row.reusedCheck,undefined);}
1432
+ // A reused check holds no command resource; a run one is acquired and released.
1433
+ const resources=fs.readFileSync(path.join(f.binding.specsDir,'运行日志.jsonl'),'utf8').trim().split('\n').map(JSON.parse)
1434
+ .filter(item=>item.event==='resource');
1435
+ assert.equal(resources.length,expected===null?0:2,name);
1436
+ }finally{f.cleanup();}
1437
+ }
1438
+ const f=fixture();
1439
+ try{
1440
+ assert.throws(()=>createHostQaExecutor({...f.configuration,commands:[{...f.configuration.commands[0],reuseCheck:'bad id'}]}));
1441
+ }finally{f.cleanup();}
1442
+ });