@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,193 @@
1
+ // Real owner/driver and local checks; reviewer output is synthetic protocol
2
+ // evidence, never independent review of this implementation. No Codex sandbox.
3
+ import test from 'node:test';
4
+ import assert from 'node:assert/strict';
5
+ import fs from 'node:fs';
6
+ import os from 'node:os';
7
+ import path from 'node:path';
8
+ import {spawn,spawnSync} from 'node:child_process';
9
+ import {fileURLToPath} from 'node:url';
10
+ import {buildManifest} from './cm-spec-manifest.mjs';
11
+ import {configFingerprint} from '../runtime/js/cm-ai/codex-config.mjs';
12
+ import {digest,JOURNAL_PAYLOAD_LIMIT,developCheckpointReserve} from '../runtime/js/cm-ai/effect-contract.mjs';
13
+ import {readRunnerHistory} from '../runtime/js/cm-ai/durable-runner-state.mjs';
14
+ import {reviewPaths} from '../runtime/js/cm-ai/review-runner.mjs';
15
+ import {readRunJournal,developPreview} from './cm-ai-drive.mjs';
16
+ const DRIVER=fileURLToPath(new URL('./cm-ai-drive.mjs',import.meta.url));
17
+ const HOST=fileURLToPath(new URL('./cm-ai-host.mjs',import.meta.url));
18
+ const REVIEWER=fileURLToPath(new URL('./fixtures/codex-review-process.mjs',import.meta.url));
19
+ const developValue={outcome:'implemented',application:{status:'no_relevant_lesson',note:null},
20
+ retrospective:{status:'no_new_lesson',candidates:[],reason:null}};
21
+ const policy={version:2,development:'conversation',bootstrap:'disabled',qa:'disabled',qaFix:'disabled'};
22
+ const size=value=>Buffer.byteLength(JSON.stringify(value??null));
23
+ const CONTENT='//'+'x'.repeat(594000)+'\n';
24
+ function fixture(t,{scope=['target.mjs'],runId='drive-gaps-run',files={}}={}){
25
+ const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-drive-gaps-')));
26
+ t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
27
+ const specsDir=path.join(root,'specs5'),codeProject=path.join(root,'app'),feature='1.work';
28
+ const identity={repositoryId:'drive-gaps',runId,taskId:'T-001',attempt:1};
29
+ fs.mkdirSync(path.join(specsDir,feature),{recursive:true});fs.mkdirSync(codeProject);
30
+ for(const name of ['requirements.md','design.md'])fs.writeFileSync(path.join(specsDir,feature,name),'# Fixture\n');
31
+ fs.writeFileSync(path.join(specsDir,feature,'tasks.md'),'- [ ] T-001: fixture\n');
32
+ fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:[feature],specFiles:buildManifest(specsDir)}));
33
+ fs.writeFileSync(path.join(codeProject,'requirements.md'),'# Fixture\n');
34
+ for(const [file,content] of Object.entries(files)){
35
+ fs.mkdirSync(path.dirname(path.join(codeProject,file)),{recursive:true});
36
+ fs.writeFileSync(path.join(codeProject,file),content);fs.chmodSync(path.join(codeProject,file),0o644);
37
+ }
38
+ const config=path.join(root,'run.json');
39
+ fs.writeFileSync(config,JSON.stringify({version:1,specsDir,codeProject,feature,identity,scope,requirements:['requirements.md']}));
40
+ const answers=path.join(root,'answers');fs.mkdirSync(answers);
41
+ // create requires a bound review configuration; reviewer() replaces it with the
42
+ // same model and a real preflight, so the durable fingerprint is unchanged.
43
+ fs.writeFileSync(path.join(root,'review.json'),JSON.stringify({model:'fixture',preflight:{}}));
44
+ const bin=path.join(root,'bin');fs.mkdirSync(bin);
45
+ const env={...process.env,PATH:bin+path.delimiter+process.env.PATH,CM_WORKFLOW_HOME:path.join(root,'home'),
46
+ CM_WORKFLOW_LOG_HOME:path.join(root,'logs')};
47
+ const write=(name,value)=>fs.writeFileSync(path.join(answers,name),JSON.stringify(value));
48
+ const content=(name,bytes)=>fs.writeFileSync(path.join(answers,name),bytes);
49
+ const develop=(edits,name='develop.json')=>write(name,{status:'succeeded',value:developValue,edits});
50
+ const plan=(extra={})=>{const file=path.join(root,`plan-${Math.random().toString(36).slice(2)}.json`);
51
+ const value={config:'run.json',mode:'create',hostContext:'drive-host-a',
52
+ permissions:[],answers:'answers',checks:[{id:'noop',command:[process.execPath,'-e','0']}],...extra};
53
+ if(!value.permissions.includes('--review-config'))value.permissions=[...value.permissions,'--review-config','review.json'];
54
+ fs.writeFileSync(file,JSON.stringify(value));
55
+ return file;};
56
+ const drive=(file,operation,timeout=60000,umask=null)=>umask===null
57
+ ?spawnSync(process.execPath,[DRIVER,'--plan',file,operation],{encoding:'utf8',timeout,env})
58
+ :spawnSync('/bin/sh',['-c',`umask ${umask}; exec "$0" "$@"`,process.execPath,DRIVER,'--plan',file,operation],{encoding:'utf8',timeout,env});
59
+ const store=path.join(specsDir,'.reviews','.execution',runId,'state.json');
60
+ const reviewer=verdict=>{
61
+ let fake=fs.readFileSync(REVIEWER,'utf8');
62
+ if(verdict==='changes_requested')fake=fake.replace("verdict:'approved'","verdict:data.reviewPackage.identity.attempt===1?'changes_requested':'approved'")
63
+ .replace('findings:[]',"findings:data.reviewPackage.identity.attempt===1?[{id:'F1',severity:'P2',path:'"+scope[0]+"',message:'Revise',evidence:'Fixture finding'}]:[]");
64
+ fs.writeFileSync(path.join(bin,'codex'),fake,{mode:0o700});
65
+ fs.writeFileSync(path.join(root,'review.json'),JSON.stringify({model:'fixture',preflight:{passed:true,
66
+ cli_model:'fixture',prompt_transport:'stdin',config_fingerprint:configFingerprint({cwd:codeProject,model:'fixture'})}}));
67
+ };
68
+ reviewer('approved');
69
+ return {root,specsDir,codeProject,config,answers,bin,env,identity,write,content,develop,plan,drive,store,reviewer};
70
+ }
71
+ const result=run=>JSON.parse(run.stdout).result;
72
+ const records=f=>JSON.parse(fs.readFileSync(f.store,'utf8')).records;
73
+
74
+ function capacityFixture(t){
75
+ const f=fixture(t,{files:{'target.mjs':'export const value = 1;\n'}});
76
+ fs.writeFileSync(path.join(f.root,'control.json'),JSON.stringify(policy));
77
+ f.content('target.txt',CONTENT);f.develop({'target.mjs':'target.txt'});
78
+ return f;
79
+ }
80
+ // SIGKILL the actual owner after its persisted reply, before host_close. Resume
81
+ // must release the stale writer and replay the same records without redoing work.
82
+ function developAndKill(f,{enabled=true}={}){
83
+ return new Promise((resolve,reject)=>{
84
+ const args=['serve','--config',f.config,'--mode','create','--host-context','drive-host-a',
85
+ ...(enabled?['--control-config',path.join(f.root,'control.json')]:['--allow-development']),
86
+ '--review-config',path.join(f.root,'review.json')];
87
+ const child=spawn(process.execPath,[HOST,...args],{env:f.env,stdio:['pipe','pipe','pipe']});
88
+ let buffer='',stderr='',reply=null,failed=null;
89
+ const timer=setTimeout(()=>{failed=new Error('capacity owner timed out');child.kill('SIGKILL');},30000);
90
+ const send=row=>child.stdin.write(JSON.stringify(row)+'\n');
91
+ child.stderr.on('data',chunk=>{stderr+=chunk;});
92
+ child.on('error',error=>{clearTimeout(timer);reject(error);});
93
+ child.stdout.on('data',chunk=>{
94
+ buffer+=chunk;
95
+ try{let index;while((index=buffer.indexOf('\n'))>=0){
96
+ const line=buffer.slice(0,index);buffer=buffer.slice(index+1);if(!line)continue;const row=JSON.parse(line);
97
+ if(row.type==='host_ready')send({version:enabled?2:1,operation:'start',requestId:'capacity',identity:f.identity});
98
+ if(row.type==='host_request'){
99
+ let result;
100
+ if(row.kind==='develop'){fs.writeFileSync(path.join(f.codeProject,'target.mjs'),CONTENT);result={status:'succeeded',value:developValue};}
101
+ else{
102
+ assert.equal(row.kind,'check');
103
+ const command=[process.execPath,'--check',path.join(f.codeProject,'target.mjs')];
104
+ const checked=spawnSync(command[0],command.slice(1),{encoding:'utf8',timeout:3000});assert.equal(checked.status,0,checked.stderr);
105
+ result=[{id:'noop',command,outcome:'passed',exitCode:0,evidence:'Actual isolated syntax check passed'}];
106
+ }
107
+ send({type:'host_result',sessionId:row.sessionId,callId:row.callId,requestDigest:row.requestDigest,result});
108
+ }
109
+ if(row.requestId==='capacity'&&row.result){reply=row.result;child.kill('SIGKILL');}
110
+ }}catch(error){failed=error;child.kill('SIGKILL');}
111
+ });
112
+ child.on('close',(code,signal)=>{clearTimeout(timer);
113
+ if(failed)reject(failed);else if(!reply)reject(new Error('owner exited without reply: '+stderr));
114
+ else {assert.equal(signal,'SIGKILL');resolve(reply);}
115
+ });
116
+ });
117
+ }
118
+
119
+ test('review-capacity: eligible 800 KB-class delivery exceeds inline reserve, survives owner kill, review and completion',async t=>{
120
+ const f=capacityFixture(t),developed=await developAndKill(f);
121
+ t.diagnostic(JSON.stringify({state:developed.state,code:developed.code,reason:developed.reason}));
122
+ assert.equal(developed.state,'awaiting_review',JSON.stringify(developed));
123
+ const developedRows=records(f),material=developedRows.at(-1),checkpoint=material.payload.checkpoint;
124
+ assert.equal(material.payload.packageMaterial,true);
125
+ assert.equal(material.payload.type,'effect-checkpoint');
126
+ const pkg=checkpoint.reviewPackage,fullPackageBytes=JSON.stringify(pkg);
127
+ const reserve=developCheckpointReserve({examinedPathsBytes:size(reviewPaths(pkg)),receiptsBytes:size(checkpoint.receipts),
128
+ callsBytes:size(checkpoint.calls),writebackBytes:size(checkpoint.learningResult?.writeback)});
129
+ assert(size(material.payload)>JOURNAL_PAYLOAD_LIMIT-reserve);
130
+ assert(size(material.payload)<=JOURNAL_PAYLOAD_LIMIT);
131
+ assert.equal(Buffer.from(pkg.changes.find(c=>c.path==='target.mjs').after.contentBase64,'base64').toString(),CONTENT);
132
+ t.diagnostic(JSON.stringify({developBytes:size(material.payload),reserve,budget:JOURNAL_PAYLOAD_LIMIT-reserve}));
133
+ const resume={mode:'resume',controlConfig:'control.json',checks:undefined};
134
+ const status=f.drive(f.plan(resume),'status');assert.equal(status.status,0,status.stderr);
135
+ assert.equal(result(status).state,'awaiting_review');assert.deepEqual(records(f),developedRows);
136
+ const approved=f.drive(f.plan({...resume,packageDigest:developed.packageDigest}),'decision');
137
+ assert.equal(approved.status,0,approved.stderr);assert.equal(result(approved).state,'approved',approved.stdout);
138
+ const completed=f.drive(f.plan({...resume,packageDigest:developed.packageDigest,
139
+ checks:[{id:'noop',command:[process.execPath,'--check',path.join(f.codeProject,'target.mjs')]}]}),'complete');
140
+ assert.equal(completed.status,0,completed.stderr);assert.equal(result(completed).state,'fixture_completed',completed.stdout);
141
+ const completedRows=records(f),refs=completedRows.filter(row=>row.payload.packageRef);
142
+ assert(refs.length>=2);
143
+ for(const row of refs){assert.equal(row.payload.checkpoint.reviewPackage,null);
144
+ assert.deepEqual(row.payload.packageRef,{recordId:material.id,recordDigest:material.digest,packageDigest:pkg.packageDigest});}
145
+ for(const row of completedRows)assert(size(row.payload)<=JOURNAL_PAYLOAD_LIMIT);
146
+ assert.deepEqual(completedRows.slice(0,developedRows.length),developedRows);
147
+ const restored=readRunnerHistory(completedRows,completedRows[0].payload.config,3);
148
+ assert.equal(JSON.stringify(restored.state.reviewPackage),fullPackageBytes);
149
+ const final=f.drive(f.plan(resume),'status');assert.equal(final.status,0,final.stderr);
150
+ assert.equal(result(final).state,'fixture_completed');assert.deepEqual(records(f),completedRows);
151
+ t.diagnostic(JSON.stringify({maxPayloadBytes:Math.max(...completedRows.map(row=>size(row.payload))),referenceCount:refs.length}));
152
+ const damaged=structuredClone(completedRows),row=damaged.findLast(entry=>entry.payload.packageRef);
153
+ row.payload.packageRef.recordDigest='0'.repeat(64);
154
+ for(let i=0;i<damaged.length;i++){const {digest:discard,...body}=damaged[i];body.previousDigest=i?damaged[i-1].digest:null;damaged[i]={...body,digest:digest(body)};}
155
+ assert.throws(()=>readRunnerHistory(damaged,completedRows[0].payload.config,3),{code:'checkpoint_package_material_invalid'});
156
+ // Replay refuses the stored representation for a run that is not eligible. The
157
+ // prefix ends at the material checkpoint, so no later packageRef can fail first.
158
+ const forged=structuredClone(developedRows);forged[0].payload.config.controlPolicy.development='provider';
159
+ for(let i=0;i<forged.length;i++){const {digest:discard,...body}=forged[i];body.previousDigest=i?forged[i-1].digest:null;forged[i]={...body,digest:digest(body)};}
160
+ assert.throws(()=>readRunnerHistory(forged,forged[0].payload.config,3),{code:'checkpoint_package_material_invalid'});
161
+ });
162
+
163
+ test('review-capacity: ineligible legacy run with the identical delivery still blocks develop_package_too_large',async t=>{
164
+ const f=capacityFixture(t),blocked=await developAndKill(f,{enabled:false});
165
+ assert.equal(blocked.state,'blocked');assert.equal(blocked.code,'develop_package_too_large');
166
+ const [,bytes,budget]=/checkpoint would be (\d+) bytes, above (\d+)/.exec(blocked.reason).map(Number);
167
+ assert(bytes>budget&&bytes<=JOURNAL_PAYLOAD_LIMIT);
168
+ assert(records(f).every(row=>!Object.hasOwn(row.payload,'packageMaterial')&&!Object.hasOwn(row.payload,'packageRef')));
169
+ const restored=readRunnerHistory(records(f),records(f)[0].payload.config,3);
170
+ assert.equal(restored.state.code,'develop_package_too_large');
171
+ t.diagnostic(JSON.stringify({bytes,budget,code:blocked.code}));
172
+ });
173
+
174
+ test('review-capacity: resume driver and owner admit the same large eligible delivery',t=>{
175
+ const f=capacityFixture(t);
176
+ const created=f.drive(f.plan({controlConfig:'control.json'}),'status');assert.equal(created.status,0,created.stderr);
177
+ const started=f.drive(f.plan({mode:'resume',controlConfig:'control.json'}),'start');
178
+ assert.equal(started.status,0,started.stderr);assert.equal(result(started).state,'awaiting_review',started.stdout);
179
+ assert.equal(records(f).at(-1).payload.packageMaterial,true);
180
+ // The driver budgets an already archived package as a reference, so its digest
181
+ // must reach the preview from the real journal, not only exist in the store.
182
+ const definition=JSON.parse(fs.readFileSync(f.config,'utf8')),journal=readRunJournal(definition);
183
+ const archived=[records(f).at(-1).payload.checkpoint.reviewPackage.packageDigest];
184
+ assert.equal(journal.packageMaterialEnabled,true);assert.deepEqual(journal.archivedPackageDigests,archived);
185
+ assert.deepEqual(developPreview({definition,journal}).archivedPackageDigests,archived);
186
+ });
187
+
188
+
189
+ test('review-capacity: create driver and owner also admit the same eligible delivery without an existing journal',t=>{
190
+ const f=capacityFixture(t),started=f.drive(f.plan({controlConfig:'control.json'}),'start');
191
+ assert.equal(started.status,0,started.stderr);assert.equal(result(started).state,'awaiting_review',started.stdout);
192
+ assert.equal(records(f).at(-1).payload.packageMaterial,true);
193
+ });
@@ -12,6 +12,7 @@ import {createHostCheck} from '../runtime/js/cm-ai/host-check.mjs';
12
12
  import {createHostQaExecutor} from '../runtime/js/cm-ai/host-qa-executor.mjs';
13
13
  import {readExecutionSnapshot} from '../runtime/js/cm-ai/execution-snapshot.mjs';
14
14
  import {configFingerprint} from '../runtime/js/cm-ai/codex-config.mjs';
15
+ import {markImplicitQaDecision} from '../runtime/js/cm-ai/implicit-qa-decision.mjs';
15
16
 
16
17
  const policy={version:2,development:'conversation',bootstrap:'disabled',qa:'run',qaFix:'disabled'};
17
18
  const cli=fileURLToPath(new URL('./cm-ai-host.mjs',import.meta.url));
@@ -105,6 +106,26 @@ test('v1 recovery retains its original no-target and fingerprint behavior',async
105
106
  assert.equal(f.snapshot().records.find(row=>row.payload.type==='specification-rebound').payload.record.reason,'Legacy explicit reason.');
106
107
  });
107
108
 
109
+ test('regression: a v2 run created before the implicit QA decision still resumes in its original form',async t=>{
110
+ const f=fixture(t);
111
+ // 修复前没有 workflow 配置的 v2 运行:没有 workflow、执行器,也没有 QA 判定。
112
+ delete f.execution.configuration.workflow;delete f.execution.qaExecutor;delete f.execution.qaDecisionProvider;
113
+ const original={...f.execution};
114
+ const created=await openControlRun(f.definition,'create',original);created.close();
115
+ const provider={timeoutMs:1000,decide:()=>{throw new Error('must not assess');}};
116
+ const implicit={...original,qaDecisionProvider:markImplicitQaDecision(provider)};
117
+ const resumed=await openControlRun(f.definition,'resume',implicit);resumed.close();
118
+ // 没有隐式标记的判定不能借这条兼容路径改变指纹。
119
+ await assert.rejects(openControlRun(f.definition,'resume',{...original,qaDecisionProvider:{...provider}}),/fingerprint_mismatch/);
120
+ // 修复后新建的运行带着隐式判定的指纹,按新形式正常恢复。
121
+ const g=fixture(t);
122
+ delete g.execution.configuration.workflow;delete g.execution.qaExecutor;
123
+ g.execution.qaDecisionProvider=markImplicitQaDecision({timeoutMs:1000,decide:()=>{throw new Error('must not assess');}});
124
+ const fresh=await openControlRun(g.definition,'create',g.execution);fresh.close();
125
+ const again=await openControlRun(g.definition,'resume',g.execution);again.close();
126
+ await assert.rejects(openControlRun(g.definition,'resume',(({qaDecisionProvider,...rest})=>rest)(g.execution)),/fingerprint_mismatch/);
127
+ });
128
+
108
129
  test('target file rejects unknown fields, malformed targets, symlinks and hardlinks',async t=>{
109
130
  const f=fixture(t),target=await initialize(f),file=path.join(f.root,'target.json');
110
131
  fs.writeFileSync(file,JSON.stringify(target));assert.deepEqual(readLaunchControlFile(file),target);
@@ -1,6 +1,9 @@
1
1
  import test from 'node:test';
2
+ import {operatorGuidance,guidanceText} from '../runtime/js/cm-ai/operator-guidance.mjs';
2
3
  import assert from 'node:assert/strict';
3
4
  import fs from 'node:fs';
5
+ import {spawnSync} from 'node:child_process';
6
+ import {createCmAiBatch,batchTaskRunId} from './cm-ai-batch-run.mjs';
4
7
  import os from 'node:os';
5
8
  import path from 'node:path';
6
9
  import {buildManifest} from './cm-spec-manifest.mjs';
@@ -26,6 +29,20 @@ test('control choices are strict and cannot turn data presence into execution pe
26
29
  {...policy,qaFix:'auto'},{...policy,qa:'skip'},{...policy,bootstrap:'yes'}])assert.throws(()=>readControlPolicy(value));
27
30
  assert.deepEqual(readControlPolicy({...policy,qa:'run',qaFix:'manual'}).qaFix,'manual');
28
31
  });
32
+ test('verification is an optional policy choice that keeps older policies byte-identical',()=>{
33
+ // Absent is the policy every earlier run saved; its digest must not move.
34
+ assert.equal(digest(readControlPolicy(policy)),digest(policy));
35
+ assert.deepEqual(readControlPolicy({...policy,verification:'precheck'}),{...policy,verification:'precheck'});
36
+ assert.deepEqual(readControlPolicy({...policy,verification:'disabled'}),{...policy,verification:'disabled'});
37
+ assert.deepEqual(readControlPolicy({...policy,verification:'auto'}),{...policy,verification:'auto'});
38
+ for(const verification of ['on',true,null,'','PRECHECK','AUTO'])
39
+ assert.throws(()=>readControlPolicy({...policy,verification}),{code:'invalid_input'});
40
+ // The choice is part of the saved run: a launch cannot add or drop it.
41
+ assert.throws(()=>assertControlEntry(snapshot(),{...policy,verification:'precheck'}),{code:'fingerprint_mismatch'});
42
+ const saved={revision:digest('a'),records:[{payload:{type:'init',config:{controlPolicy:{...policy,verification:'precheck'}}}}]};
43
+ assert.throws(()=>assertControlEntry(saved,policy),{code:'fingerprint_mismatch'});
44
+ assertControlEntry(saved,{...policy,verification:'precheck'});
45
+ });
29
46
  test('policy file rejects duplicate keys, invalid UTF8 and symbolic links',t=>{
30
47
  const root=temp(t),file=path.join(root,'control.json');
31
48
  fs.writeFileSync(file,JSON.stringify(policy));assert.deepEqual(readControlPolicyFile(file),policy);
@@ -122,3 +139,68 @@ test('reused error codes do not swallow failures from the underlying host',async
122
139
  ?{expectedControl:controlTarget(status,snapshot())}:{})),error=>error===failure);
123
140
  }
124
141
  });
142
+
143
+
144
+ test('v2 wrapper re-renders recovery guidance without reads, mutations or journal changes',async()=>{
145
+ let reads=0;const current=snapshot(),before=JSON.stringify(current);
146
+ const native={workflow:'cm-ai',...status,pendingAction:'abandon_effect',outcome:'reported'};
147
+ native.guidance=operatorGuidance(native);const nativeBefore=JSON.stringify(native);
148
+ const requests=[];
149
+ const host=withControlPolicyHost({async handle(request){requests.push(request);return native;}},
150
+ {identity,snapshot:()=>{reads++;return current;}});
151
+ for(const operation of ['status','advance']){
152
+ const output=await host.handle(wire(operation));
153
+ assert.doesNotMatch(guidanceText(output),/--allow-/);assert.match(guidanceText(output),/expectedControl/);
154
+ const {guidance,controlTarget:target,...unchanged}=output;
155
+ const {guidance:original,...expected}=native;assert.deepEqual(unchanged,expected);
156
+ }
157
+ assert.equal(reads,1,'guidance does not read state');assert.equal(requests.length,2,'guidance does not dispatch');
158
+ assert.equal(JSON.stringify(current),before);assert.equal(JSON.stringify(native),nativeBefore);
159
+ });
160
+
161
+ test('v2 wrapper preserves an active-operation suppression',async()=>{
162
+ const native={workflow:'cm-ai',...status,pendingAction:'abandon_effect',outcome:'reported'};
163
+ native.guidance=operatorGuidance(native,{executionActive:true});
164
+ const host=withControlPolicyHost({async handle(){return native;}},{identity,snapshot});
165
+ const output=await host.handle(wire('status'));
166
+ assert.equal(output.guidance.recoveryOperation,null);assert.match(guidanceText(output),/不重复派发/);
167
+ });
168
+
169
+
170
+ test('real v2 batch status and recovery render the batch target and leave status history unchanged',async t=>{
171
+ const root=temp(t),codeProject=path.join(root,'code'),specsDir=path.join(root,'specs'),logHome=path.join(root,'logs');
172
+ const feature='1.work',taskKey=`${feature}/T-001`,batchId='guidance-batch';
173
+ fs.mkdirSync(codeProject);fs.mkdirSync(path.join(specsDir,feature),{recursive:true});
174
+ // A clean disposable Git root without a commit; explicit scope remains authoritative.
175
+ const initialized=spawnSync('git',['init','-q',codeProject],{encoding:'utf8'});assert.equal(initialized.status,0);
176
+ fs.writeFileSync(path.join(codeProject,'.git/info/exclude'),'*\n');
177
+ fs.writeFileSync(path.join(codeProject,'.cm-workflow.json'),JSON.stringify({version:1,policies:{delivery:'diff'}}));
178
+ for(const name of ['requirements.md','design.md'])fs.writeFileSync(path.join(specsDir,feature,name),'# Fixture\n');
179
+ fs.writeFileSync(path.join(specsDir,feature,'tasks.md'),'- [ ] T-001: fixture\n');
180
+ fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:[feature],specFiles:buildManifest(specsDir)}));
181
+ let calls=0;
182
+ const configuration={version:1,repositoryId:identity.repositoryId,batchId,specsDir,codeProject,controlPolicy:policy,
183
+ tasks:[{feature,taskId:'T-001',scope:['target.mjs'],requirements:[]}]};
184
+ const batch=createCmAiBatch({configuration,logHome,executionFor:async definition=>createConversationExecution(
185
+ definition,'control-fixture-host',{async call(operation){
186
+ calls++;assert.equal(operation,'develop');fs.writeFileSync(path.join(codeProject,'target.mjs'),'// preserved edit\n');
187
+ throw Object.assign(new Error('Synthetic disconnect'),{code:'host_disconnected'});
188
+ }},{model:'fixture',disabledSkills:[],preflight:{passed:true,cli_model:'fixture',prompt_transport:'stdin',
189
+ config_fingerprint:configFingerprint({cwd:codeProject,model:'fixture'})}},null,null,false,'codex',{controlPolicy:policy,qaLogHome:logHome})});
190
+ const advance=await batch.handle({version:2,operation:'advance',requestId:'batch-advance'});
191
+ assert.equal(advance.pendingAction,'develop_redo',JSON.stringify(advance));
192
+ assert.match(guidanceText(advance),/完整批次 controlTarget/);assert.doesNotMatch(guidanceText(advance),/--allow-/);
193
+ const journal=path.join(specsDir,'.reviews/.execution',batchTaskRunId(batchId,taskKey),'state.json');
194
+ const before=fs.readFileSync(journal),log=path.join(specsDir,'运行日志.jsonl'),beforeLog=fs.readFileSync(log);
195
+ const reported=await batch.handle({version:2,operation:'status',requestId:'batch-status'});
196
+ assert.match(guidanceText(reported),/batchId、taskKey、member、batchDigest/);
197
+ assert.deepEqual(fs.readFileSync(journal),before);assert.deepEqual(fs.readFileSync(log),beforeLog);assert.equal(calls,1);
198
+ const expectedControl=await batch.controlTarget();
199
+ assert.deepEqual(fs.readFileSync(journal),before);assert.deepEqual(fs.readFileSync(log),beforeLog);
200
+ const recovered=await batch.handle({version:2,operation:'develop_redo',requestId:'batch-redo',taskKey,
201
+ reason:'Synthetic stopped conversation',expectedControl});
202
+ assert.equal(recovered.code,'develop_answer_missing',JSON.stringify(recovered));
203
+ assert.match(guidanceText(recovered),/原批次入口/);assert.doesNotMatch(guidanceText(recovered),/--allow-|恢复原运行/);
204
+ assert.equal(calls,1,'recovery only records confirmation');
205
+ assert.equal(fs.readFileSync(path.join(codeProject,'target.mjs'),'utf8'),'// preserved edit\n');
206
+ });