@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,233 @@
1
+ import test,{after} from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import fs from 'node:fs';
4
+ import os from 'node:os';
5
+ import path from 'node:path';
6
+ import {openExecutionStore,appendFits} from '../runtime/js/cm-ai/execution-store.mjs';
7
+ import {readExecutionSnapshot} from '../runtime/js/cm-ai/execution-snapshot.mjs';
8
+ import {openFixExecution} from '../runtime/js/cm-fix/execution.mjs';
9
+ import {captureReviewBaseline,createReviewPackage,readReviewPackage} from '../runtime/js/cm-ai/review-package.mjs';
10
+ import * as presentation from '../runtime/js/cm-ai/review-presentation.mjs';
11
+ import {digest,requestFor} from '../runtime/js/cm-ai/effect-contract.mjs';
12
+
13
+ const MiB=1024*1024,STATE_LIMIT=16*MiB,workflow='cm-fix-stages-v1';
14
+ const copy=value=>JSON.parse(JSON.stringify(value));
15
+ const bytes=value=>Buffer.byteLength(JSON.stringify(value));
16
+ const isolated=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-review-storage-home-')));
17
+ const saved={CM_WORKFLOW_HOME:process.env.CM_WORKFLOW_HOME,CM_WORKFLOW_LOG_HOME:process.env.CM_WORKFLOW_LOG_HOME};
18
+ process.env.CM_WORKFLOW_HOME=path.join(isolated,'home');process.env.CM_WORKFLOW_LOG_HOME=path.join(isolated,'logs');
19
+ after(()=>{for(const [key,value] of Object.entries(saved)){if(value===undefined)delete process.env[key];else process.env[key]=value;}fs.rmSync(isolated,{recursive:true,force:true});});
20
+
21
+ function fixture(t,{mode=workflow}={}){
22
+ const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-fix-review-storage-')));
23
+ const cwd=path.join(root,'code'),specsRoot=path.join(root,'specs');fs.mkdirSync(cwd);fs.mkdirSync(specsRoot);
24
+ fs.writeFileSync(path.join(cwd,'repro.mjs'),"console.error('synthetic fixture');process.exit(1);\n");
25
+ const identity={repositoryId:'synthetic',runId:'review-storage',taskId:'T-FIX-storage',attempt:1};
26
+ let store;
27
+ t.after(()=>{store?.close();fs.rmSync(root,{recursive:true,force:true});});
28
+ let fingerprints;
29
+ if(mode===workflow){
30
+ // Obtain a genuine, validated first configuration record; never advance it.
31
+ const configuration={hostContextId:'storage-fixture-host',defect:'Synthetic storage regression only',
32
+ reproduction:{cwd,command:[process.execPath,'repro.mjs'],expectedFailure:{exitCode:1,outputIncludes:'synthetic fixture'},timeoutMs:2000}};
33
+ const owner=openFixExecution({specsRoot,identity,configuration,create:true},{});owner.close();
34
+ fingerprints=readExecutionSnapshot({specsRoot,identity:{repositoryId:identity.repositoryId,runId:identity.runId}}).fingerprints;
35
+ }else{
36
+ fingerprints={workflow:digest(mode),config:digest('synthetic configuration'),inputs:digest(identity)};
37
+ const initial=openExecutionStore({specsRoot,identity:{repositoryId:identity.repositoryId,runId:identity.runId},fingerprints,create:true});
38
+ initial.append({id:mode==='wrong-fingerprint'?'fix-configuration':'configuration',kind:'intent',
39
+ payload:{workflow:mode==='wrong-fingerprint'?workflow:mode,identity,configuration:{}},expectedRevision:initial.snapshot().revision});initial.close();
40
+ }
41
+ const shortIdentity={repositoryId:identity.repositoryId,runId:identity.runId},options={specsRoot,identity:shortIdentity,fingerprints,create:false};
42
+ store=openExecutionStore(options);
43
+ const stateFile=path.join(specsRoot,'.reviews/.execution',identity.runId,'state.json');
44
+ return {root,cwd,specsRoot,identity,shortIdentity,options,stateFile,store:()=>store,
45
+ close(){store.close();},reopen(){store.close();store=openExecutionStore(options);return store;},
46
+ readonly:()=>readExecutionSnapshot({specsRoot,identity:shortIdentity})};
47
+ }
48
+ function material(f,size=360*1024,format='utf8'){
49
+ const prefix='export const value=1;\n//';
50
+ const before=Buffer.from(prefix+'x'.repeat(size-Buffer.byteLength(prefix)-1)+'\n');
51
+ if(format==='bom')Buffer.from([0xef,0xbb,0xbf]).copy(before);
52
+ if(format==='binary')before.fill(0xff);
53
+ const after=Buffer.from(before);after[format==='binary'?0:prefix.indexOf('1')]=format==='binary'?0xfe:0x32;
54
+ fs.writeFileSync(path.join(f.cwd,'sample.mjs'),before);
55
+ const baseline=captureReviewBaseline({root:f.cwd,identity:f.identity,scope:['sample.mjs'],requirements:['sample.mjs']});
56
+ fs.writeFileSync(path.join(f.cwd,'sample.mjs'),after);
57
+ const reviewPackage=createReviewPackage({root:f.cwd,baseline,checks:[{id:'synthetic',command:['synthetic-check'],outcome:'passed',exitCode:0,evidence:'Synthetic fixture, not a provider observation'}]});
58
+ assert.deepEqual(readReviewPackage(reviewPackage),reviewPackage);
59
+ assert.equal(reviewPackage.changes[0].before.size,size);assert.equal(reviewPackage.changes[0].after.size,size);
60
+ assert.equal(reviewPackage.requirements[0].contentBase64,reviewPackage.changes[0].after.contentBase64);
61
+ return {baseline,reviewPackage};
62
+ }
63
+ // Synthetic storage envelopes match the durable owner shape. These fixture
64
+ // grants are data only; no reviewer is invoked and no approval is claimed.
65
+ function registration(reviewPackage,priorReview=null){
66
+ const request=requestFor({invocationId:'fix-final.synthetic-storage',identity:reviewPackage.identity,role:'reviewer',provider:'codex',
67
+ requestedModel:'synthetic',contextId:'synthetic-storage-context',payload:{reviewPackage,priorReview}});
68
+ return {request,authorizationAt:1000,registeredAt:1000,grant:{synthetic:true}};
69
+ }
70
+ function writeback(reviewPackage){return {writeback:{identity:reviewPackage.identity,learningDigest:digest('synthetic learning'),
71
+ retrospectiveDigest:digest('synthetic retrospective'),packageDigest:reviewPackage.packageDigest,outcome:'written',changed:true,
72
+ agentsFile:{scope:'project',path:'AGENTS.md',sha256:digest('synthetic instructions')},reason:null,completionEligible:false},reviewPackage};}
73
+ const entry=(f,id,payload,kind='intent')=>({id,kind,payload,expectedRevision:f.store().snapshot().revision});
74
+ function assertChain(snapshot){
75
+ let previous=null;
76
+ snapshot.records.forEach((record,index)=>{const {digest:checksum,...body}=record;assert.equal(record.seq,index+1);assert.equal(record.previousDigest,previous);assert.equal(digest(body),checksum);previous=checksum;});
77
+ const {revision,...body}=snapshot;assert.equal(digest(body),revision);
78
+ }
79
+ function rejectAppend(f,id,payload){
80
+ const input=entry(f,id,payload),before=fs.readFileSync(f.stateFile);
81
+ const fits=appendFits(f.store().snapshot(),input);
82
+ assert.throws(()=>f.store().append(input));assert.equal(fits,false);assert.deepEqual(fs.readFileSync(f.stateFile),before);
83
+ }
84
+ function codec(){
85
+ assert.equal(typeof presentation.packFixJournalPayload,'function','CM_FIX_REVIEW_STORAGE: the bounded CM-fix storage codec must exist');
86
+ assert.equal(typeof presentation.unpackFixJournalPayload,'function','CM_FIX_REVIEW_STORAGE: stored CM-fix evidence must have a real decoder');
87
+ return {pack:presentation.packFixJournalPayload,unpack:presentation.unpackFixJournalPayload};
88
+ }
89
+
90
+ test('a real CM-fix journal stores a repeated canonical review larger than one MiB and preserves exact evidence on reopen',t=>{
91
+ const f=fixture(t),{reviewPackage}=material(f),old=copy(f.store().snapshot());
92
+ assert.equal(old.records[0].id,'fix-configuration');assert.equal(old.records[0].kind,'intent');assert.equal(old.records[0].payload.workflow,workflow);
93
+ const oldPhysical=JSON.parse(fs.readFileSync(f.stateFile,'utf8')),rootPayload=reviewPackage;
94
+ assert(bytes(rootPayload)>MiB);let next;
95
+ const first=entry(f,'fix-retrospective-intent',rootPayload);
96
+ assert.doesNotThrow(()=>{next=f.store().append(first);},'CM_FIX_REVIEW_STORAGE: a real append must admit losslessly deduplicated canonical review evidence above one MiB');
97
+ assert.equal(appendFits(old,first),true);assert.deepEqual(next.records.at(-1).payload,rootPayload);assertChain(next);
98
+ const physical=JSON.parse(fs.readFileSync(f.stateFile,'utf8'));
99
+ assert.deepEqual(physical.records[0],oldPhysical.records[0]);assert(bytes(physical.records[1].payload)<=MiB);
100
+ assert.notDeepEqual(physical.records[1].payload,rootPayload);
101
+ for(const [id,payload] of [
102
+ ['fix-final-review-registered',registration(reviewPackage)],
103
+ ['fix-revision-prepared',{synthetic:'small revision metadata',priorPackageDigest:reviewPackage.packageDigest,nextIdentity:{...f.identity,attempt:2}}],
104
+ ['fix-revision-retrospective-intent',reviewPackage],
105
+ ['fix-revision-final-review-registered',registration(reviewPackage)],
106
+ ['fix-learning-writeback-result',writeback(reviewPackage)],
107
+ ]){
108
+ const input=entry(f,id,payload);assert.equal(appendFits(f.store().snapshot(),input),true);
109
+ next=f.store().append(input);assert.deepEqual(next.records.at(-1).payload,payload);assertChain(next);
110
+ }
111
+ const logical=copy(next),disk=fs.readFileSync(f.stateFile);
112
+ assert.deepEqual(f.readonly(),logical);assert.deepEqual(fs.readFileSync(f.stateFile),disk);
113
+ assert.deepEqual(f.reopen().snapshot(),logical);
114
+ assert.deepEqual(f.store().append(first),logical);assert.deepEqual(fs.readFileSync(f.stateFile),disk);
115
+ const oldRows=JSON.parse(fs.readFileSync(f.stateFile,'utf8')).records;
116
+ const small=entry(f,'small-after-packed',{ok:true},'result');next=f.store().append(small);assertChain(next);
117
+ assert.equal(JSON.stringify(JSON.parse(fs.readFileSync(f.stateFile,'utf8')).records.slice(0,-1)),JSON.stringify(oldRows));
118
+ assert.deepEqual(f.readonly(),next);assert.deepEqual(JSON.parse(fs.readFileSync(f.stateFile,'utf8')).records.at(-1),next.records.at(-1));
119
+ const prepared=next.records.find(row=>row.id==='fix-revision-prepared');
120
+ assert.deepEqual(JSON.parse(fs.readFileSync(f.stateFile,'utf8')).records[prepared.seq-1],prepared);
121
+ });
122
+
123
+ test('ordinary large data, non-fix workflows and false workflow fingerprints retain the one MiB limit',t=>{
124
+ const f=fixture(t);rejectAppend(f,'large-ordinary',{ordinary:'x'.repeat(MiB)});
125
+ const {reviewPackage}=material(f,64);rejectAppend(f,'small-package-large-ordinary',{reviewPackage,ordinary:'x'.repeat(MiB)});
126
+ rejectAppend(f,'arbitrary-nested-review',{arbitrary:{reviewPackage:material(f).reviewPackage}});
127
+ for(const mode of ['cm-ai-stages-v1','cm-ai-batch-v1','wrong-fingerprint']){
128
+ const other=fixture(t,{mode}),large=material(other).reviewPackage;
129
+ rejectAppend(other,'large-review',{reviewPackage:large});
130
+ }
131
+ });
132
+
133
+ test('a package that still exceeds the encoded limit or the expanded payload budget cannot be appended',t=>{
134
+ const f=fixture(t),{reviewPackage}=material(f,600*1024);
135
+ rejectAppend(f,'encoded-too-large',reviewPackage);
136
+ const smaller=material(f).reviewPackage;
137
+ const oversized=copy(registration(smaller));oversized.request.payload.priorReview={ordinary:'x'.repeat(10*MiB)};
138
+ const {requestDigest,...requestBody}=oversized.request;oversized.request.requestDigest=digest(requestBody);
139
+ rejectAppend(f,'logical-too-large',oversized);
140
+ });
141
+
142
+ test('a small valid review cannot authorize deduplication of repeated ordinary base64 or string metadata',t=>{
143
+ const f=fixture(t),{reviewPackage}=material(f,64),ordinary=Buffer.from('z'.repeat(600*1024)).toString('base64');
144
+ rejectAppend(f,'ordinary-base64-smuggling',registration(reviewPackage,{synthetic:'not valid final feedback; storage boundary only',ordinary:[{contentBase64:ordinary},{contentBase64:ordinary}]}));
145
+ rejectAppend(f,'ordinary-string-smuggling',registration(reviewPackage,{synthetic:'not valid final feedback; storage boundary only',ordinary:[ordinary,ordinary]}));
146
+ });
147
+
148
+ test('the codec preserves small marker-looking data and rejects invalid canonical review evidence',t=>{
149
+ const f=fixture(t),{pack,unpack}=codec(),{reviewPackage}=material(f);
150
+ const collision={version:1,kind:'cm-fix-journal-review-payload',logicalBytes:1,logicalDigest:'a'.repeat(64),data:'ordinary old scalar'};
151
+ assert.deepEqual(pack(collision,{workflow}),collision);
152
+ f.store().append(entry(f,'old-wrapper-lookalike',collision));assert.deepEqual(f.reopen().snapshot().records.at(-1).payload,collision);
153
+ for(const mutate of [p=>{p.extra=true;},p=>{p.packageDigest='0'.repeat(64);},p=>{p.changes[0].after.sha256='0'.repeat(64);},p=>{p.requirements[0].contentBase64+='!';}]){
154
+ const bad=copy(reviewPackage);mutate(bad);rejectAppend(f,'bad-canonical-review',bad);
155
+ }
156
+ const logical=reviewPackage;f.store().append(entry(f,'large-after-old-collision',logical));
157
+ assert.deepEqual(f.reopen().snapshot().records.find(row=>row.id==='old-wrapper-lookalike').payload,collision);
158
+ const encoded=pack(logical,{workflow});
159
+ assert(bytes(encoded)<=MiB);assert.deepEqual(unpack(encoded,{workflow}),logical);
160
+ assert.equal(digest(unpack(encoded,{workflow})),digest(logical));
161
+ for(const format of ['bom','binary']){const pkg=material(f,360*1024,format).reviewPackage;
162
+ f.store().append(entry(f,'lossless-'+format,pkg));assert.deepEqual(f.reopen().snapshot().records.at(-1).payload,pkg);
163
+ }
164
+ });
165
+
166
+ test('read-only and writer replay reject malformed physical wrappers, references and expansion without changing state',t=>{
167
+ const f=fixture(t),{reviewPackage}=material(f);codec();
168
+ f.store().append(entry(f,'large-review',registration(reviewPackage)));
169
+ const logical=copy(f.store().snapshot()),valid=fs.readFileSync(f.stateFile),physical=JSON.parse(valid);
170
+ assert.deepEqual(physical.storageEncoding.records,[2]);f.close();
171
+ const wrapper=s=>s.records[1].payload;
172
+ const firstRef=s=>Object.keys(wrapper(s).data.contents)[0];
173
+ const content=s=>wrapper(s).data.contents[firstRef(s)];
174
+ const edits=[
175
+ ['unmarked oversized legacy payload',s=>{delete s.storageEncoding;s.records[1].payload=copy(logical.records[1].payload);}],
176
+ ['extra wrapper field',s=>{wrapper(s).extra=true;}],
177
+ ['extra presentation field',s=>{wrapper(s).data.presentation.extra=true;}],
178
+ ['extra content field',s=>{content(s).extra=true;}],
179
+ ['bad declared digest',s=>{wrapper(s).logicalDigest='0'.repeat(64);}],
180
+ ['bad content hash',s=>{content(s).sha256='0'.repeat(64);}],
181
+ ['foreign package binding',s=>{wrapper(s).data.presentation.packageDigest='f'.repeat(64);}],
182
+ ['foreign reference',s=>{wrapper(s).data.payload.request.payload.reviewPackage.changes[0].after.contentRef='foreign';}],
183
+ ['orphan reference table entry',s=>{wrapper(s).data.contents.orphan=copy(content(s));}],
184
+ ['unknown content encoding',s=>{content(s).encoding='future-encoding';}],
185
+ ['metadata reference',s=>{wrapper(s).data.payload.request.payload.priorReview={contentRef:firstRef(s)};}],
186
+ ['expanded byte bomb',s=>{const p=wrapper(s).data.payload;p.request.payload.priorReview=Array.from({length:40},()=>copy(p.request.payload.reviewPackage));}],
187
+ ['declared expanded overflow',s=>{wrapper(s).logicalBytes=10*MiB+1;}],
188
+ ['scalar marked wrapper',s=>{s.records[1].payload='ordinary scalar cannot be an encoded row';}],
189
+ ['unknown wrapper kind',s=>{wrapper(s).kind='cm-fix-journal-review-payload-v999';}],
190
+ ['unknown state encoding',s=>{s.storageEncoding.kind='cm-fix-review-payloads-v999';}],
191
+ ['duplicate marked sequence',s=>{s.storageEncoding.records=[2,2];}],
192
+ ['ordinary configuration marked as encoded',s=>{s.storageEncoding.records=[1,2];}],
193
+ ];
194
+ for(const [label,mutate] of edits){
195
+ const bad=copy(physical);mutate(bad);fs.writeFileSync(f.stateFile,JSON.stringify(bad)+'\n');
196
+ const before=fs.readFileSync(f.stateFile),names=fs.readdirSync(path.dirname(f.stateFile));
197
+ assert.throws(()=>f.readonly(),undefined,label);assert.deepEqual(fs.readFileSync(f.stateFile),before,label);
198
+ assert.throws(()=>{let opened;try{opened=openExecutionStore(f.options);}finally{opened?.close();}},undefined,label);
199
+ assert.deepEqual(fs.readFileSync(f.stateFile),before,label);assert.deepEqual(fs.readdirSync(path.dirname(f.stateFile)),names,label);
200
+ }
201
+ fs.writeFileSync(f.stateFile,valid);assert.deepEqual(f.reopen().snapshot(),logical);
202
+ });
203
+
204
+ test('the whole-state limit applies to expanded logical evidence even when the physical journal is smaller',t=>{
205
+ const f=fixture(t),{reviewPackage}=material(f);codec();
206
+ f.store().append(entry(f,'large-review',registration(reviewPackage)));
207
+ let logical=copy(f.store().snapshot());const physical=JSON.parse(fs.readFileSync(f.stateFile));f.close();
208
+ const add=payload=>{
209
+ const body={version:1,seq:logical.records.length+1,id:'filler-'+logical.records.length,kind:'result',payload,
210
+ previousDigest:logical.records.at(-1).digest};
211
+ const record={...body,digest:digest(body)};logical.records.push(record);physical.records.push(copy(record));
212
+ };
213
+ // Seed one bounded historical image directly instead of cumulatively writing
214
+ // hundreds of MiB through repeated near-limit appends.
215
+ while(bytes(logical)+900*1024<STATE_LIMIT-4096)add({ordinary:'f'.repeat(900*1024)});
216
+ add({ordinary:''});const finalIndex=logical.records.length-1;
217
+ logical.records[finalIndex].payload.ordinary='f'.repeat(STATE_LIMIT-512-bytes(logical));
218
+ const {digest:ignored,...last}=logical.records[finalIndex];logical.records[finalIndex].digest=digest(last);
219
+ physical.records[finalIndex]=copy(logical.records[finalIndex]);
220
+ const seal=()=>{const {revision,...body}=logical;logical.revision=digest(body);physical.revision=logical.revision;};seal();
221
+ assert.equal(bytes(logical),STATE_LIMIT-512);assert(bytes(physical)<bytes(logical));
222
+ fs.writeFileSync(f.stateFile,JSON.stringify(physical)+'\n');
223
+ assert.deepEqual(f.reopen().snapshot(),logical);assert.deepEqual(f.readonly(),logical);assertChain(logical);
224
+ const tooLarge=entry(f,'overflow-next',{ordinary:'x'.repeat(1024)},'result'),before=fs.readFileSync(f.stateFile);
225
+ assert.equal(appendFits(logical,tooLarge),false);assert.throws(()=>f.store().append(tooLarge));assert.deepEqual(fs.readFileSync(f.stateFile),before);
226
+ // A forged but logically self-consistent over-budget image must also fail
227
+ // public read-only discovery and writer reopen before any rewrite occurs.
228
+ f.close();add(tooLarge.payload);seal();assert(bytes(logical)>STATE_LIMIT);assert(bytes(physical)<STATE_LIMIT);
229
+ fs.writeFileSync(f.stateFile,JSON.stringify(physical)+'\n');const overflowBytes=fs.readFileSync(f.stateFile);
230
+ assert.throws(()=>f.readonly());assert.deepEqual(fs.readFileSync(f.stateFile),overflowBytes);
231
+ assert.throws(()=>{let opened;try{opened=openExecutionStore(f.options);}finally{opened?.close();}});
232
+ assert.deepEqual(fs.readFileSync(f.stateFile),overflowBytes);
233
+ });
@@ -0,0 +1,242 @@
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 http from 'node:http';
7
+ import {spawn,spawnSync} from 'node:child_process';
8
+ import {runVerificationCommand,writeInsideCopy} from '../runtime/js/cm-fix/review-verification-command.mjs';
9
+ import {verificationFailureCode,verificationFailure} from '../runtime/js/cm-fix/review-verification-diagnostic.mjs';
10
+
11
+ const supported=process.platform==='darwin';
12
+ function fixture(t){
13
+ const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-review-command-')));
14
+ t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
15
+ const cwd=path.join(root,'copy');fs.mkdirSync(cwd);
16
+ return {root,cwd};
17
+ }
18
+ function run(cwd,source,extra={}){
19
+ return runVerificationCommand({cwd,command:[process.execPath,'-e',source],timeoutMs:5000,
20
+ signal:new AbortController().signal,...extra});
21
+ }
22
+ test('verification command refuses a symlink working directory',async t=>{
23
+ const {root,cwd}=fixture(t),link=path.join(root,'alias');fs.symlinkSync(cwd,link);
24
+ const result=await run(link,'process.exit(0)');
25
+ assert.equal(result.outcome,'unavailable');assert.equal(result.code,'verification_path_invalid');
26
+ });
27
+ test('verification command rejects system and home roots before cancellation',async()=>{
28
+ const controller=new AbortController();controller.abort();
29
+ for(const directory of ['/', '/usr', '/usr/local', '/private', os.homedir(),path.dirname(os.homedir())]){
30
+ if(!fs.existsSync(directory))continue;
31
+ const cwd=fs.realpathSync(directory),result=await run(cwd,'process.exit(8)',{signal:controller.signal});
32
+ assert.equal(result.code,'verification_path_invalid',directory);
33
+ }
34
+ });
35
+ test('verification sandbox does not read the local administrator prefix',{skip:!supported||!fs.existsSync('/usr/local')},async t=>{
36
+ const {cwd}=fixture(t);
37
+ const result=await run(cwd,`try{require('node:fs').readdirSync('/usr/local');process.exit(8)}
38
+ catch(error){process.exit(error.code==='EPERM'||error.code==='EACCES'?0:9)}`);
39
+ assert.equal(result.outcome,'passed',result.output);
40
+ });
41
+ test('verification sandbox rejects the data volume alias of an external fixture',{skip:!supported},async t=>{
42
+ const {root,cwd}=fixture(t),secret=path.join(root,'synthetic-secret');fs.writeFileSync(secret,'synthetic-private-value');
43
+ const alias='/System/Volumes/Data'+secret;
44
+ assert.equal(fs.readFileSync(alias,'utf8'),'synthetic-private-value');
45
+ const result=await run(cwd,`const fs=require('node:fs');let denied=0;
46
+ for(const target of ${JSON.stringify([alias,fs.realpathSync(alias)])}){
47
+ try{fs.readFileSync(target)}catch(error){if(['EPERM','EACCES'].includes(error.code))denied++;}
48
+ }process.exit(denied===2?0:8);`);
49
+ assert.equal(result.outcome,'passed',result.output);
50
+ });
51
+ test('verification sandbox denies credential and other Mach service lookups without contacting services',{skip:!supported},async t=>{
52
+ const {cwd}=fixture(t),source=path.join(cwd,'probe.c'),binary=path.join(cwd,'probe');
53
+ // sandbox_check only examines the current policy. It neither connects to a
54
+ // service nor asks Keychain for credentials. GLOBAL_NAME is filter value 2.
55
+ fs.writeFileSync(source,`#include <unistd.h>\n#include <stdio.h>\n
56
+ extern int sandbox_check(pid_t,const char *,int,...);
57
+ int main(void){const char *names[]={"com.apple.securityd","com.apple.securityd.xpc","cm.synthetic.nonexistent"};
58
+ for(int i=0;i<3;i++)if(sandbox_check(getpid(),"mach-lookup",2,names[i])!=1)return 8;
59
+ puts("lookup-denied");return 0;}`);
60
+ const compiled=spawnSync('/usr/bin/clang',[source,'-o',binary,'-lsandbox'],{encoding:'utf8',timeout:10000});
61
+ assert.equal(compiled.status,0,compiled.stderr);
62
+ const result=await run(cwd,'',{command:[binary]});
63
+ assert.equal(result.outcome,'passed',result.output);assert.match(result.output,/lookup-denied/);
64
+ });
65
+ test('verification command preserves exit status and uses a private environment',{skip:!supported},async t=>{
66
+ const {cwd}=fixture(t);
67
+ const result=await run(cwd,`const fs=require('node:fs');
68
+ if(process.env.ANTHROPIC_API_KEY||process.env.CODEX_HOME||process.env.NODE_OPTIONS)process.exit(8);
69
+ if(!process.env.HOME.startsWith(process.cwd()+'/'))process.exit(9);
70
+ fs.writeFileSync('artifact','ok');console.log('verification-output');`);
71
+ assert.equal(result.outcome,'passed');assert.equal(result.exitCode,0);assert.equal(result.code,null);
72
+ assert.match(result.output,/verification-output/);assert.equal(fs.readFileSync(path.join(cwd,'artifact'),'utf8'),'ok');
73
+ assert.deepEqual(fs.readdirSync(cwd),['artifact']);
74
+ const failed=await run(cwd,'process.exit(7)');
75
+ assert.equal(failed.outcome,'failed');assert.equal(failed.exitCode,7);
76
+ });
77
+ test('verification runs a real script entry without granting ancestor file contents',{skip:!supported},async t=>{
78
+ const {cwd,root}=fixture(t),entry=path.join(cwd,'entry.mjs'),secret=path.join(root,'secret');
79
+ fs.writeFileSync(secret,'private-fixture');
80
+ fs.writeFileSync(entry,`import fs from 'node:fs';console.log('real-entry');
81
+ try{fs.readFileSync(${JSON.stringify(secret)});process.exit(8)}catch{}`);
82
+ const result=await run(cwd,'',{command:[process.execPath,entry]});
83
+ assert.equal(result.outcome,'passed',result.output);assert.match(result.output,/real-entry/);
84
+ });
85
+ test('verification runs a real Node test file without Mach service access',{skip:!supported},async t=>{
86
+ const {cwd}=fixture(t),entry=path.join(cwd,'sample.test.mjs');
87
+ fs.writeFileSync(entry,"import test from 'node:test';import assert from 'node:assert/strict';test('isolated',()=>assert.equal(2+2,4));");
88
+ const result=await run(cwd,'',{command:[process.execPath,'--test',entry]});
89
+ assert.equal(result.outcome,'passed',result.output);assert.match(result.output,/pass 1/);
90
+ });
91
+ test('verification sandbox rejects external reads, source writes and symlink escapes',{skip:!supported},async t=>{
92
+ const {root,cwd}=fixture(t),secret=path.join(root,'secret'),source=path.join(root,'original');
93
+ fs.writeFileSync(secret,'private-fixture');fs.writeFileSync(source,'original');
94
+ fs.symlinkSync(root,path.join(cwd,'escape'));
95
+ const result=await run(cwd,`const fs=require('node:fs');let refused=0;
96
+ for(const p of [${JSON.stringify(secret)},'escape/secret'])try{fs.readFileSync(p)}catch{refused++}
97
+ for(const p of [${JSON.stringify(source)},'escape/original'])try{fs.writeFileSync(p,'bad')}catch{refused++}
98
+ console.log(refused);process.exit(refused===4?0:5);`);
99
+ assert.equal(result.outcome,'passed',result.output);assert.equal(result.output.trim(),'4');
100
+ assert.equal(fs.readFileSync(source,'utf8'),'original');
101
+ });
102
+ const PROCARGS_PROBE=`#include <stdio.h>
103
+ #include <stdlib.h>
104
+ #include <string.h>
105
+ #include <sys/sysctl.h>
106
+ int main(int argc,char**argv){int mib[3]={CTL_KERN,KERN_PROCARGS2,atoi(argv[1])};size_t size=0;
107
+ if(sysctl(mib,3,NULL,&size,NULL,0)!=0){perror("sysctl");return 2;}char*b=malloc(size);
108
+ if(sysctl(mib,3,b,&size,NULL,0)!=0){perror("sysctl");return 3;}size_t n=strlen(argv[2]);
109
+ for(size_t i=0;i+n<=size;i++)if(!memcmp(b+i,argv[2],n)){puts("FOUND");return 0;}puts("NOTFOUND");return 0;}`;
110
+ // CI sets CM_REQUIRE_NATIVE_PROBE=1 so a missing or broken compiler fails instead of skipping.
111
+ const requireProbe=process.env.CM_REQUIRE_NATIVE_PROBE==='1';
112
+ test('verification sandbox cannot read another process environment through a native helper',{skip:!supported||(!requireProbe&&!fs.existsSync('/usr/bin/clang'))},async t=>{
113
+ const {root,cwd}=fixture(t),source=path.join(root,'probe.c'),probe=path.join(cwd,'probe');
114
+ fs.writeFileSync(source,PROCARGS_PROBE);
115
+ const built=spawnSync('/usr/bin/clang',['-o',probe,source],{encoding:'utf8'});
116
+ if(built.status!==0){
117
+ assert.equal(requireProbe,false,`the native probe must build in CI: ${built.stderr}`);
118
+ t.skip('clang cannot build the probe here');return;
119
+ }
120
+ const secret=`cm-probe-${process.pid}-${Date.now()}`;
121
+ const holder=spawn(process.execPath,['-e','setInterval(()=>{},1000)'],{env:{...process.env,CM_PROBE_SECRET:secret},stdio:'ignore'});
122
+ t.after(()=>holder.kill('SIGKILL'));
123
+ // The fixture is valid only if the same probe does find the secret outside the sandbox.
124
+ const outside=spawnSync(probe,[String(holder.pid),secret],{encoding:'utf8'});
125
+ assert.equal(outside.stdout.trim(),'FOUND');
126
+ const inside=await runVerificationCommand({cwd,command:[probe,String(holder.pid),secret],timeoutMs:20000,signal:new AbortController().signal});
127
+ assert.equal(inside.outcome,'failed');
128
+ assert.doesNotMatch(inside.output,/FOUND/);
129
+ assert.match(inside.output,/Operation not permitted/);
130
+ // The same rules still let ordinary Node code inspect its own machine and spawn children.
131
+ const node=await run(cwd,"const os=require('os');const r=require('child_process').spawnSync(process.execPath,['-e','process.exit(0)']);process.exit(os.cpus().length>0&&r.status===0?0:9)");
132
+ assert.equal(node.outcome,'passed');
133
+ });
134
+ test('verification sandbox rejects loopback network access',{skip:!supported},async t=>{
135
+ const {cwd}=fixture(t);let requests=0;
136
+ const server=http.createServer((_req,res)=>{requests++;res.end('unexpected');});
137
+ await new Promise(resolve=>server.listen(0,'127.0.0.1',resolve));
138
+ try{
139
+ const port=server.address().port;
140
+ const result=await run(cwd,`const http=require('node:http');
141
+ const req=http.get('http://127.0.0.1:${port}',()=>process.exit(8));
142
+ req.once('error',()=>process.exit(0));req.setTimeout(1000,()=>process.exit(9));`);
143
+ assert.equal(result.outcome,'passed',result.output);assert.equal(requests,0);
144
+ }finally{server.closeAllConnections();await new Promise(resolve=>server.close(resolve));}
145
+ });
146
+ test('verification command timeout and cancellation are unavailable, never passed',{skip:!supported},async t=>{
147
+ const {cwd}=fixture(t),controller=new AbortController();
148
+ const timed=await run(cwd,'setInterval(()=>{},1000)',{timeoutMs:250});
149
+ assert.equal(timed.outcome,'unavailable');assert.equal(timed.code,'verification_timeout');
150
+ const pending=run(cwd,'setInterval(()=>{},1000)',{signal:controller.signal});
151
+ const timer=setTimeout(()=>controller.abort(),250);
152
+ const cancelled=await pending;clearTimeout(timer);
153
+ assert.equal(cancelled.outcome,'unavailable');assert.equal(cancelled.code,'verification_cancelled');
154
+ assert.deepEqual(fs.readdirSync(cwd),[]);
155
+ });
156
+ test('verification command bounds retained output and rejects output floods',{skip:!supported},async t=>{
157
+ const {cwd}=fixture(t);
158
+ const bounded=await run(cwd,"process.stdout.write('x'.repeat(20000))");
159
+ assert.equal(bounded.outcome,'passed');assert.equal(bounded.output.length,8192);
160
+ const flood=await run(cwd,"process.stdout.write('x'.repeat(5*1024*1024));setInterval(()=>{},1000)");
161
+ assert.equal(flood.outcome,'unavailable');assert.equal(flood.code,'verification_output_limit');
162
+ assert.equal(flood.output.length,8192);
163
+ });
164
+ test('verification timeout cleans its owned child process group',{skip:!supported},async t=>{
165
+ const {cwd}=fixture(t);
166
+ const result=await run(cwd,`const cp=require('node:child_process');
167
+ const child=cp.spawn(process.execPath,['-e','setInterval(()=>{},1000)'],{stdio:'ignore'});
168
+ console.log(child.pid);setInterval(()=>{},1000);`,{timeoutMs:300});
169
+ assert.equal(result.outcome,'unavailable');assert.equal(result.code,'verification_timeout');
170
+ const pid=Number(result.output.trim());assert(Number.isInteger(pid)&&pid>0);
171
+ assert.throws(()=>process.kill(pid,0),{code:'ESRCH'});
172
+ });
173
+ test('verification sandbox cannot signal its outer host',{skip:!supported},async t=>{
174
+ const {cwd}=fixture(t);
175
+ const result=await run(cwd,`try{process.kill(${process.pid},0);process.exit(8)}
176
+ catch(error){process.exit(error.code==='EPERM'?0:9)}`);
177
+ assert.equal(result.outcome,'passed',result.output);
178
+ });
179
+ test('verification setup failures and pre-cancellation never become failing test evidence',{skip:!supported},async t=>{
180
+ const {cwd}=fixture(t),controller=new AbortController();controller.abort();
181
+ const cancelled=await run(cwd,'process.exit(8)',{signal:controller.signal});
182
+ assert.equal(cancelled.code,'verification_cancelled');assert.deepEqual(fs.readdirSync(cwd),[]);
183
+ const missing=await run(cwd,'',{command:['/nonexistent-cm-verification-command']});
184
+ assert.equal(missing.outcome,'unavailable');assert.equal(missing.code,'verification_isolation_failed');
185
+ const invalid=await run(cwd,'',{timeoutMs:0});
186
+ assert.equal(invalid.outcome,'unavailable');assert.equal(invalid.code,'verification_command_invalid');
187
+ });
188
+ test('verification reports process ownership and cleans up when its observer rejects',{skip:!supported},async t=>{
189
+ const {cwd}=fixture(t),events=[];
190
+ const result=await run(cwd,'process.exit(0)',{onSpawn:pid=>{events.push(['spawn',pid]);},onClose:pid=>{events.push(['close',pid]);}});
191
+ assert.equal(result.outcome,'passed');assert.equal(events.length,2);assert.equal(events[0][1],events[1][1]);
192
+ assert.equal(events[0][0],'spawn');assert.equal(events[1][0],'close');
193
+ let pid,closed;
194
+ const failed=await run(cwd,'setInterval(()=>{},1000)',{onSpawn:value=>{pid=value;throw Error('synthetic observer error');},
195
+ onClose:value=>{closed=value;}});
196
+ assert.equal(failed.outcome,'unavailable');assert.equal(failed.code,'verification_observer_failed');
197
+ assert.equal(closed,pid);assert.throws(()=>process.kill(pid,0),{code:'ESRCH'});
198
+ });
199
+ test('verification does not claim cleanup when a detached descendant holds its output open',{skip:!supported},async t=>{
200
+ const {cwd}=fixture(t);let closed=false,pid;
201
+ try{
202
+ const result=await run(cwd,`const cp=require('node:child_process');
203
+ const child=cp.spawn(process.execPath,['-e','setInterval(()=>{},1000)'],{detached:true,stdio:['ignore',1,2]});
204
+ console.log(child.pid);child.unref();`,{onClose:()=>{closed=true;}});
205
+ pid=Number(result.output.trim());
206
+ assert.equal(result.outcome,'unavailable');assert.equal(result.code,'verification_cleanup_unknown');
207
+ assert.equal(closed,false);assert(Number.isInteger(pid)&&pid>0);
208
+ }finally{if(Number.isInteger(pid)&&pid>0)try{process.kill(-pid,'SIGKILL');}catch(error){if(error.code!=='ESRCH')throw error;}}
209
+ });
210
+ test('copy writes run inside the sandbox and cannot follow a link out of the copy',{skip:!supported},async t=>{
211
+ const {root,cwd}=fixture(t),outside=path.join(root,'outside.txt');
212
+ fs.writeFileSync(outside,'keep');
213
+ fs.writeFileSync(path.join(cwd,'a.txt'),'old',{mode:0o644});
214
+ writeInsideCopy({cwd,file:'a.txt',data:Buffer.from('new'),mode:0o600});
215
+ assert.equal(fs.readFileSync(path.join(cwd,'a.txt'),'utf8'),'new');
216
+ assert.equal(fs.statSync(path.join(cwd,'a.txt')).mode&0o7777,0o600);
217
+ writeInsideCopy({cwd,file:'a.txt',data:Buffer.from('kept mode'),mode:null});
218
+ assert.equal(fs.statSync(path.join(cwd,'a.txt')).mode&0o7777,0o600);
219
+ fs.symlinkSync(outside,path.join(cwd,'link.txt'));
220
+ assert.throws(()=>writeInsideCopy({cwd,file:'link.txt',data:Buffer.from('escaped'),mode:null}),{code:'review_verification_copy_drift'});
221
+ fs.mkdirSync(path.join(root,'outdir'));fs.writeFileSync(path.join(root,'outdir','b.txt'),'keep');
222
+ fs.symlinkSync(path.join(root,'outdir'),path.join(cwd,'dir'));
223
+ assert.throws(()=>writeInsideCopy({cwd,file:'dir/b.txt',data:Buffer.from('escaped'),mode:null}),{code:'review_verification_copy_drift'});
224
+ assert.equal(fs.readFileSync(outside,'utf8'),'keep');
225
+ assert.equal(fs.readFileSync(path.join(root,'outdir','b.txt'),'utf8'),'keep');
226
+ for(const file of ['../outside.txt','/etc/hosts','a/../../x','','a\\b','a\0b'])
227
+ assert.throws(()=>writeInsideCopy({cwd,file,data:Buffer.from('x'),mode:null}),{code:'verification_write_invalid'});
228
+ });
229
+ test('copy write failures keep their exact code through the persisted diagnostic',()=>{
230
+ // Argument validation runs before any platform check, so this holds on every platform.
231
+ let thrown;
232
+ try{writeInsideCopy({cwd:'/nonexistent',file:'../x',data:Buffer.from('x'),mode:null});}catch(error){thrown=error;}
233
+ assert.equal(thrown?.code,'verification_write_invalid');
234
+ for(const code of ['verification_write_invalid','verification_isolation_unsupported','review_verification_copy_drift']){
235
+ assert.equal(verificationFailureCode(Object.assign(Error(code),{code})),code);
236
+ assert.equal(verificationFailure({phase:'mutation',code}).code,code);
237
+ }
238
+ });
239
+ test('verification command rejects unsupported isolation without executing',{skip:supported},async t=>{
240
+ const {cwd}=fixture(t),result=await run(cwd,'process.exit(0)');
241
+ assert.equal(result.outcome,'unavailable');assert.equal(result.code,'verification_isolation_unsupported');
242
+ });