@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,167 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import {EventEmitter} from 'node:events';
4
+ import {PassThrough} from 'node:stream';
5
+ import {codexWorker} from '../runtime/js/cm-ai/worker-codex.mjs';
6
+ import {configFingerprint} from '../runtime/js/cm-ai/codex-config.mjs';
7
+
8
+ const reconnect = n => ({type:'error',message:`Reconnecting... ${n}/5 (stream disconnected before completion: synthetic)`});
9
+ const start = [{type:'thread.started',thread_id:'synthetic-reconnect'},{type:'turn.started'}];
10
+ const finish = [{type:'item.completed',item:{type:'agent_message',text:'{"ok":true}'}},{type:'turn.completed'}];
11
+
12
+ async function stream(rows,{throwNotice=false}={}) {
13
+ const options={cwd:'/fixture',model:'fixture',effort:'high'},events=[],notices=[],terminals=[],diagnostics=[];
14
+ let kills=0;
15
+ const run=codexWorker({...options,schemaPath:'/unused',timeoutMs:1000,
16
+ preflight:{passed:true,cli_model:options.model,config_fingerprint:configFingerprint(options)},
17
+ onNotice:notice=>{notices.push(notice);if(throwNotice)throw Error('synthetic notice sink failure');},
18
+ onDiagnostic:diagnostic=>diagnostics.push(diagnostic),
19
+ spawnProcess(){
20
+ const child=new EventEmitter();child.stdout=new PassThrough();child.stderr=new PassThrough();
21
+ let closed=false;
22
+ const close=()=>{if(closed)return;closed=true;child.stdout.end();child.stderr.end();child.emit('close',0,null);};
23
+ child.kill=()=>{kills++;queueMicrotask(close);return true;};
24
+ queueMicrotask(()=>{
25
+ for(const row of rows){if(kills)break;child.stdout.write(JSON.stringify(row)+'\n');}
26
+ close();
27
+ });
28
+ return child;
29
+ }});
30
+ const result=await run({prompt:'synthetic reconnect test'},{signal:new AbortController().signal,
31
+ onEvent:event=>events.push(event),onTerminal:terminal=>terminals.push(terminal)});
32
+ return {result,events,notices,terminals,diagnostics,kills};
33
+ }
34
+
35
+ test('Codex reconnect 2/5 through 5/5 followed by HTTPS fallback succeeds',async()=>{
36
+ const notices=[2,3,4,5].map(reconnect);
37
+ const fallback={type:'item.completed',item:{type:'error',message:'Falling back to HTTPS transport. synthetic'}};
38
+ const actual=await stream([...start,...notices,fallback,...finish]);
39
+ assert.deepEqual(actual.result,{status:'succeeded',value:{ok:true}});
40
+ assert.deepEqual(actual.notices,[...notices.map(row=>row.message),fallback.item.message]);
41
+ assert.deepEqual(actual.events.map(row=>row.event),['thread.started','turn.started','item.completed','turn.completed','process_closed']);
42
+ assert.deepEqual(actual.terminals,[{status:'succeeded',value:{ok:true}}]);
43
+ assert.deepEqual(actual.diagnostics,[]);
44
+ });
45
+
46
+ test('Codex reconnect notices cannot hide a later turn.failed',async()=>{
47
+ const actual=await stream([...start,reconnect(2),reconnect(3),{type:'turn.failed',error:{message:'request failed'}}]);
48
+ assert.deepEqual(actual.result,{status:'failed',code:'provider_failed'});
49
+ assert.equal(actual.notices.length,2);
50
+ assert.deepEqual(actual.events.filter(row=>['error','turn.failed'].includes(row.event)).map(row=>row.event),['turn.failed']);
51
+ assert.deepEqual(actual.terminals,[{status:'failed',code:'provider_failed'}]);
52
+ });
53
+
54
+ test('Codex non-reconnect top-level errors remain fatal',async()=>{
55
+ for(const message of ['request failed','prefix Reconnecting... 2/5','Reconnecting.. 2/5','Reconnecting... two/5',null]){
56
+ const actual=await stream([...start,{type:'error',message},...finish]);
57
+ assert.deepEqual(actual.result,{status:'failed',code:'provider_failed'});
58
+ assert.deepEqual(actual.notices,[]);
59
+ assert.equal(actual.events.find(row=>row.event==='error').event,'error');
60
+ }
61
+ });
62
+
63
+ test('Codex reconnect limit allows 32 notices independently of eight item notices',async()=>{
64
+ const reconnects=Array.from({length:32},(_,n)=>reconnect(n+1));
65
+ const items=Array.from({length:8},()=>({type:'item.completed',item:{type:'error',message:'synthetic startup notice'}}));
66
+ const actual=await stream([...start,...reconnects,...items,...finish]);
67
+ assert.deepEqual(actual.result,{status:'succeeded',value:{ok:true}});
68
+ assert.equal(actual.notices.length,40);
69
+ });
70
+
71
+ test('Codex reconnect notice 33 fails instead of allowing an endless stream',async()=>{
72
+ const actual=await stream([...start,...Array.from({length:33},(_,n)=>reconnect(n+1)),...finish]);
73
+ assert.deepEqual(actual.result,{status:'failed',code:'provider_failed'});
74
+ assert.equal(actual.notices.length,32);
75
+ assert.equal(actual.events.filter(row=>row.event==='error').length,1);
76
+ assert.deepEqual(actual.terminals,[{status:'failed',code:'provider_failed'}]);
77
+ });
78
+
79
+ test('Codex reconnect notices are bounded and notice sink failure does not fail a turn',async()=>{
80
+ const notice={...reconnect(1),message:reconnect(1).message+'x'.repeat(400)};
81
+ const actual=await stream([...start,notice,...finish],{throwNotice:true});
82
+ assert.deepEqual(actual.result,{status:'succeeded',value:{ok:true}});
83
+ assert.deepEqual(actual.notices,[notice.message.slice(0,200)]);
84
+ });
85
+
86
+ // 2026-10-26: a real Codex review ended with this pair after its own retries.
87
+ // The class is kept, never the provider text; other errors stay provider_failed.
88
+ const limited='exceeded retry limit, last status: 429 Too Many Requests';
89
+ test('Codex 429 / Too Many Requests / rate limit ends as reviewer_rate_limited (class only, no text)',async()=>{
90
+ for(const rows of [
91
+ [{type:'error',message:limited},{type:'turn.failed',error:{message:limited}}],
92
+ [{type:'turn.failed',error:{message:limited}}],
93
+ [{type:'error',message:'stream error: Too Many Requests'}],
94
+ [{type:'error',message:'Rate limit reached for requests'},{type:'turn.failed',error:{message:'request failed'}}],
95
+ ]){
96
+ const actual=await stream([...start,...rows]);
97
+ assert.deepEqual(actual.result,{status:'failed',code:'reviewer_rate_limited'},JSON.stringify(rows));
98
+ assert.deepEqual(actual.terminals,[{status:'failed',code:'reviewer_rate_limited'}]);
99
+ assert(!JSON.stringify(actual.events).includes('429'),'no provider text in published events');
100
+ }
101
+ });
102
+
103
+ test('Codex failure naming only the HTTP status 429 is a rate limit',async()=>{
104
+ for(const message of ['unexpected status HTTP 429','HTTP 429']){
105
+ const actual=await stream([...start,{type:'error',message},{type:'turn.failed',error:{message}}]);
106
+ assert.deepEqual(actual.result,{status:'failed',code:'reviewer_rate_limited'},message);
107
+ }
108
+ });
109
+
110
+ test('Codex non-rate-limit failures stay provider_failed; a 429 reconnect notice that recovers still succeeds',async()=>{
111
+ for(const message of ['request failed','status 500 Internal Server Error','error 4290 unrelated id']){
112
+ const actual=await stream([...start,{type:'error',message},{type:'turn.failed',error:{message}}]);
113
+ assert.deepEqual(actual.result,{status:'failed',code:'provider_failed'},message);
114
+ assert.deepEqual(actual.terminals,[{status:'failed',code:'provider_failed'}]);
115
+ }
116
+ const notice={type:'error',message:'Reconnecting... 1/5 (unexpected status 429 Too Many Requests)'};
117
+ const recovered=await stream([...start,notice,...finish]);
118
+ assert.deepEqual(recovered.result,{status:'succeeded',value:{ok:true}});
119
+ });
120
+
121
+ // Ticket 11: the reviewer must not stop on the generic error before the 429 turn.failed
122
+ // that Codex writes a moment later; a lone error still stops within the short grace.
123
+ async function delayedFailure(delayMs,{timeoutMs=60000,tail=false,closeAt=5000}={}){
124
+ const options={cwd:'/fixture',model:'fixture',effort:'high'},terminals=[];let kills=0;
125
+ const run=codexWorker({...options,schemaPath:'/unused',timeoutMs,
126
+ preflight:{passed:true,cli_model:options.model,config_fingerprint:configFingerprint(options)},
127
+ spawnProcess(){
128
+ const child=new EventEmitter();child.stdout=new PassThrough();child.stderr=new PassThrough();
129
+ let closed=false;
130
+ const close=()=>{if(closed)return;closed=true;child.stdout.end();child.stderr.end();child.emit('close',1,null);};
131
+ child.kill=()=>{kills++;queueMicrotask(close);return true;};
132
+ const write=row=>{if(!kills&&!closed)child.stdout.write(JSON.stringify(row)+'\n');};
133
+ queueMicrotask(()=>{
134
+ for(const row of start)write(row);
135
+ // tail: the error is the last line, with no trailing newline, written as the process closes.
136
+ if(tail){child.stdout.write(JSON.stringify({type:'error',message:'Request failed'}));close();return;}
137
+ write({type:'error',message:'Request failed'});
138
+ if(delayMs!==null)setTimeout(()=>write({type:'turn.failed',error:{message:'HTTP 429 Too Many Requests'}}),delayMs);
139
+ setTimeout(close,closeAt);
140
+ });
141
+ return child;
142
+ }});
143
+ const started=Date.now();
144
+ const result=await run({prompt:'synthetic delayed failure'},{signal:new AbortController().signal,onEvent(){},onTerminal:t=>terminals.push(t)});
145
+ return {result,terminals,elapsed:Date.now()-started,kills:()=>kills};
146
+ }
147
+ test('Codex reviewer keeps the 429 of a turn.failed written 400 ms after a generic error',async()=>{
148
+ const actual=await delayedFailure(400);
149
+ assert.deepEqual(actual.result,{status:'failed',code:'reviewer_rate_limited'});
150
+ assert.deepEqual(actual.terminals,[{status:'failed',code:'reviewer_rate_limited'}]);
151
+ });
152
+ test('Codex reviewer stops a lone generic error within the short grace, not the call timeout',async()=>{
153
+ const actual=await delayedFailure(null);
154
+ assert.deepEqual(actual.result,{status:'failed',code:'provider_failed'});
155
+ assert.ok(actual.elapsed<4500,`stopped after ${actual.elapsed} ms`);
156
+ });
157
+ test('Codex reviewer timeout during the error grace keeps timeout',async()=>{
158
+ const actual=await delayedFailure(null,{timeoutMs:300});
159
+ assert.deepEqual(actual.result,{status:'failed',code:'timeout'});
160
+ });
161
+ test('Codex reviewer starts no grace for an unterminated error read at close',async()=>{
162
+ const timers=()=>process.getActiveResourcesInfo().filter(name=>name==='Timeout').length;
163
+ const before=timers();
164
+ const actual=await delayedFailure(null,{tail:true});
165
+ assert.deepEqual(actual.result,{status:'failed',code:'provider_failed'});
166
+ assert.equal(timers(),before,'no grace timer left after the call settled');
167
+ });
@@ -0,0 +1,260 @@
1
+ // Commander phase 1: the read-only ledger. Pure rules use synthetic inputs with
2
+ // a fixed clock; one integration test drives a real run and replays it.
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 {spawnSync} from 'node:child_process';
9
+ import {fileURLToPath} from 'node:url';
10
+ import {composeLedger,readLogEvents,buildLedger,readRuns,rawHints,checkedSupersession,originBound,IDLE_MINUTES} from '../runtime/js/commander/ledger.mjs';
11
+ import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
12
+ import {buildManifest} from './cm-spec-manifest.mjs';
13
+ import {configFingerprint} from '../runtime/js/cm-ai/codex-config.mjs';
14
+ import {main,renderLedger} from './cm-commander.mjs';
15
+
16
+ const isolated=fs.mkdtempSync(path.join(os.tmpdir(),'cm-commander-home-'));
17
+ process.env.CM_WORKFLOW_HOME=path.join(isolated,'user');process.env.CM_WORKFLOW_LOG_HOME=path.join(isolated,'logs');
18
+ test.after(()=>fs.rmSync(isolated,{recursive:true,force:true}));
19
+
20
+ const NOW='2026-10-20T10:00:00.000Z';
21
+ const minutesAgo=n=>new Date(Date.parse(NOW)-n*60000).toISOString();
22
+ // The real admission result shape: state plus reason (not code).
23
+ const ready={state:'ready',reason:'task_selected',nextTask:{feature:'1.work',id:'T-002'}};
24
+ const features=[{name:'1.work',tasks:[
25
+ {id:'T-001',completed:true,dropped:false,dependsOn:[]},
26
+ {id:'T-002',completed:false,dropped:false,dependsOn:[]},
27
+ {id:'T-003',completed:false,dropped:false,dependsOn:['T-002']}]}];
28
+ const run=(runId,taskId,extra={})=>({runId,kind:'cm-ai',verified:true,feature:'1.work',taskId,state:'awaiting_review',
29
+ code:null,attempt:1,pending:null,committed:false,trustedPrevious:[],claimedPrevious:[],records:4,...extra});
30
+ const unverified=(runId,taskId,extra={})=>run(runId,taskId,{verified:false,chainVerified:true,state:null,attempt:null,...extra});
31
+ const log=(entries={})=>({present:true,invalid:0,runs:new Map(Object.entries(entries).map(([id,ago])=>[id,{at:minutesAgo(ago),event:'progress',detail:'x',runDone:false}]))});
32
+ const compose=(runs,logs,admission=ready,runsError=null)=>composeLedger({specsDir:'/s',admission,features,runs,runsError,log:logs,now:NOW});
33
+
34
+ test('with no run in flight the next step is admission’s task; its reason is carried through',()=>{
35
+ const l=compose([],log());
36
+ assert.equal(l.next.kind,'start_task');assert.equal(l.next.task,'T-002');
37
+ assert.deepEqual(l.features[0].tasks.map(t=>t.status),['done','todo','todo']);
38
+ assert.equal(compose([],log(),{state:'complete',reason:'all_tasks_terminal'}).next.kind,'finish');
39
+ const blocked=compose([],log(),{state:'blocked',reason:'spec_drift',detail:{feature:'1.work'},warnings:['w']});
40
+ assert.equal(blocked.next.kind,'admission_blocked');assert.equal(blocked.next.reason,'spec_drift');
41
+ assert.match(blocked.next.why,/blocked\/spec_drift/);assert.deepEqual(blocked.admission.detail,{feature:'1.work'});
42
+ assert.deepEqual(blocked.admission.warnings,['w']);
43
+ });
44
+
45
+ test('single-flight on an unchecked task: an active run is waited on; idle, silent or stopped runs come first',()=>{
46
+ const active=compose([run('r-active','T-002')],log({'r-active':5}));
47
+ assert.equal(active.next.kind,'wait_run','no new task while a run is active');
48
+ assert.equal(active.features[0].tasks[1].status,'in_run');
49
+ const idle=compose([run('r-idle','T-002')],log({'r-idle':IDLE_MINUTES}));
50
+ assert.equal(idle.next.kind,'attend_run');assert.match(idle.next.why,/45 分钟没有新日志/);
51
+ const silent=compose([run('r-silent','T-002')],log());
52
+ assert.equal(silent.next.kind,'attend_run');assert.match(silent.next.why,/没有日志活动/);
53
+ const both=compose([run('r-idle','T-002'),run('r-stop','T-003',{state:'blocked',code:'review_blocked'})],log({'r-idle':300,'r-stop':1}));
54
+ assert.equal(both.next.runId,'r-stop','a stopped run outranks a merely idle one');
55
+ assert.deepEqual(both.queue.map(a=>a.runId),['r-idle']);
56
+ });
57
+
58
+ test('a journaled but unfinished effect is executing, not stopped',()=>{
59
+ const busy=compose([run('r','T-002',{state:'unknown',code:'reconciliation_required',pending:'develop'})],log({r:0}));
60
+ assert.equal(busy.features[0].tasks[1].status,'in_run');assert.equal(busy.next.kind,'wait_run');
61
+ assert.match(busy.next.why,/正在执行 develop/);
62
+ const quiet=compose([run('r','T-002',{state:'unknown',code:'reconciliation_required',pending:'review'})],log({r:120}));
63
+ assert.equal(quiet.next.kind,'attend_run');assert.match(quiet.next.why,/未结的 review/);
64
+ });
65
+
66
+ test('two open runs of one task both stay in the queue; recent activity does not retire the other',()=>{
67
+ const l=compose([run('old','T-002',{state:'blocked',code:'review_blocked'}),run('new','T-002')],log({old:600,new:1}));
68
+ assert.equal(l.next.runId,'old','the stopped run is handled before waiting on the active one');
69
+ assert.deepEqual(l.features[0].tasks[1].runIds.sort(),['new','old']);
70
+ assert.ok(l.inconsistencies.some(i=>i.kind==='multiple_open_runs'));
71
+ });
72
+
73
+ test('a replayed supersession retires its predecessor; a claimed one does not, and asks for a check',()=>{
74
+ const trusted=compose([run('old','T-002',{state:'blocked',code:'review_blocked'}),run('new','T-002',{trustedPrevious:['old']})],log({old:600,new:3}));
75
+ assert.equal(trusted.next.kind,'wait_run');assert.equal(trusted.next.runId,'new');
76
+ assert.equal(trusted.runs.find(r=>r.runId==='old').supersededBy,'new');assert.deepEqual(trusted.inconsistencies,[]);
77
+ const claimed=compose([run('old','T-002',{state:'blocked',code:'review_blocked'}),unverified('new','T-002',{claimedPrevious:['old']})],log({old:600,new:3}));
78
+ assert.equal(claimed.runs.find(r=>r.runId==='old').supersededBy,null,'an unchecked claim never retires a run');
79
+ assert.equal(claimed.next.runId,'old');assert.ok(claimed.queue.some(q=>q.kind==='check_records'&&q.runId==='new'));
80
+ const crossTask=compose([run('old','T-002',{state:'blocked',code:'review_blocked'}),run('new','T-003',{trustedPrevious:['old']})],log({old:600,new:3}));
81
+ assert.equal(crossTask.runs.find(r=>r.runId==='old').supersededBy,null,'a supersession across tasks is refused');
82
+ assert.ok(crossTask.inconsistencies.some(i=>i.kind==='supersession_task_mismatch'));
83
+ });
84
+
85
+ test('an unverified run is never stopped, and its commit claim is not a commit',()=>{
86
+ const recent=compose([unverified('u','T-002',{state:'blocked'})],log({u:2}));
87
+ assert.equal(recent.features[0].tasks[1].status,'in_run');assert.equal(recent.next.kind,'wait_run');
88
+ assert.match(recent.next.why,/未校验/);
89
+ const quiet=compose([unverified('u','T-002')],log({u:90}));
90
+ assert.equal(quiet.next.kind,'attend_run');assert.match(quiet.next.why,/未校验/);
91
+ const claim=compose([unverified('u','T-002',{committedClaim:true})],log({u:90}));
92
+ assert.equal(claim.next.kind,'attend_run','a commit claim does not end the run');
93
+ assert.ok(!claim.inconsistencies.some(i=>i.kind==='commit_without_check'));
94
+ });
95
+
96
+ test('unreadable runs or an unreadable run directory never become “nothing in flight”',()=>{
97
+ const bad=compose([{runId:'x',kind:'unreadable',code:'store_corrupt'}],log());
98
+ assert.equal(bad.next.kind,'check_records');assert.match(bad.next.why,/store_corrupt/);
99
+ const dir=compose([],log(),ready,'EACCES');
100
+ assert.equal(dir.next.kind,'check_records');assert.match(dir.next.why,/EACCES/);
101
+ const fix=compose([{runId:'f',kind:'cm-fix',records:3},{runId:'e',kind:'empty'}],log());
102
+ assert.equal(fix.next.kind,'start_task','identified cm-fix history and empty residue directories do not block');
103
+ });
104
+
105
+ test('a checked task: a run is history only on evidence, never on the checkmark or log age alone',()=>{
106
+ const live=compose([run('d','T-001',{state:'developing'})],log({d:3}));
107
+ assert.equal(live.next.kind,'attend_run');assert.equal(live.next.runId,'d');assert.match(live.next.why,/任务已勾选/);
108
+ const old=compose([run('d','T-001',{state:'blocked',code:'failed'})],log({d:9000}));
109
+ assert.equal(old.next.kind,'start_task','a verified terminal attempt with nothing in flight is history');
110
+ assert.ok(old.inconsistencies.some(i=>i.kind==='checked_with_open_run'));
111
+ for(const logs of [log({p:60}),log()]){
112
+ const pending=compose([run('p','T-001',{state:'unknown',code:'reconciliation_required',pending:'develop'})],logs);
113
+ assert.equal(pending.next.kind,'attend_run','an unfinished effect is never history');assert.match(pending.next.why,/未结的 develop/);
114
+ }
115
+ const committed=compose([unverified('u','T-001',{committedClaim:true}),unverified('v','T-001',{committedClaim:true})],log({u:9000,v:9000}));
116
+ assert.equal(committed.next.kind,'start_task','an intact chain that journaled the commit is history');
117
+ assert.deepEqual(committed.inconsistencies,[]);
118
+ const unproven=compose([unverified('u','T-001')],log({u:9000}));
119
+ assert.equal(unproven.next.kind,'attend_run','an unverified run without a commit record is not proven over');
120
+ assert.match(unproven.next.why,/没有可核验的结束记录/);
121
+ const recent=compose([unverified('u','T-001',{committedClaim:true})],log({u:1}));
122
+ assert.equal(recent.next.kind,'attend_run','recent activity on a checked task is never history');
123
+ const brokenChain=compose([unverified('u','T-001',{committedClaim:true,chainVerified:false})],log({u:9000}));
124
+ assert.equal(brokenChain.next.kind,'attend_run','a commit claim in a broken chain proves nothing');
125
+ const commitNoCheck=compose([run('c','T-003',{committed:true})],log({c:3}));
126
+ assert.ok(commitNoCheck.inconsistencies.some(i=>i.kind==='commit_without_check'&&i.task==='T-003'));
127
+ assert.throws(()=>composeLedger({specsDir:'/s',admission:ready,features,runs:[],log:log(),now:'yesterday'}),{code:'invalid_now'});
128
+ });
129
+
130
+ test('the log reader keeps the latest event per run, sticky run_done, and counts bad lines',()=>{
131
+ const dir=fs.mkdtempSync(path.join(os.tmpdir(),'cm-commander-log-'));test.after(()=>fs.rmSync(dir,{recursive:true,force:true}));
132
+ const row=(run_id,at,event='progress')=>JSON.stringify({run_id,at,event,detail:event});
133
+ fs.writeFileSync(path.join(dir,'运行日志.jsonl'),[row('a',minutesAgo(10),'run_done'),row('a',minutesAgo(5)),row('a',minutesAgo(20)),
134
+ 'not json',JSON.stringify({run_id:'b',at:'bad'}),row('b',minutesAgo(1))].join('\n')+'\n');
135
+ const read=readLogEvents(dir);
136
+ assert.equal(read.invalid,2);assert.equal(read.runs.get('a').at,minutesAgo(5));assert.equal(read.runs.get('a').runDone,true);
137
+ assert.equal(readLogEvents(path.join(dir,'missing')).present,false);
138
+ });
139
+
140
+ // Integration: a real driven run in awaiting_review, then the same journal made
141
+ // unreplayable by a foreign record type, still mapped to its task.
142
+ const DRIVER=fileURLToPath(new URL('./cm-ai-drive.mjs',import.meta.url));
143
+ const REVIEW=fileURLToPath(new URL('./fixtures/codex-review-process.mjs',import.meta.url));
144
+ function project(t){
145
+ const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-commander-')));t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
146
+ const specsDir=path.join(root,'specs5'),codeProject=path.join(root,'app'),bin=path.join(root,'bin'),answers=path.join(root,'answers');
147
+ for(const dir of [path.join(specsDir,'1.work'),codeProject,bin,answers])fs.mkdirSync(dir,{recursive:true});
148
+ for(const name of ['requirements.md','design.md'])fs.writeFileSync(path.join(specsDir,'1.work',name),'# Fixture\n');
149
+ fs.writeFileSync(path.join(specsDir,'1.work/tasks.md'),'- [ ] T-001: fixture\n- [ ] T-002: next\n');
150
+ fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:['1.work'],specFiles:buildManifest(specsDir)}));
151
+ fs.writeFileSync(path.join(codeProject,'requirements.md'),'# Fixture\n');
152
+ const identity={repositoryId:'commander',runId:'commander-run',taskId:'T-001',attempt:1};
153
+ fs.writeFileSync(path.join(root,'run.json'),JSON.stringify({version:1,specsDir,codeProject,feature:'1.work',identity,scope:['target.mjs'],requirements:['requirements.md']}));
154
+ fs.writeFileSync(path.join(root,'control.json'),JSON.stringify({version:2,development:'conversation',bootstrap:'disabled',qa:'disabled',qaFix:'disabled'}));
155
+ fs.writeFileSync(path.join(root,'review.json'),JSON.stringify({model:'fixture',preflight:{passed:true,cli_model:'fixture',
156
+ prompt_transport:'stdin',config_fingerprint:configFingerprint({cwd:codeProject,model:'fixture'})}}));
157
+ fs.writeFileSync(path.join(bin,'codex'),fs.readFileSync(REVIEW,'utf8'),{mode:0o700});
158
+ fs.writeFileSync(path.join(answers,'develop.json'),JSON.stringify({status:'succeeded',value:{outcome:'implemented',
159
+ application:{status:'no_relevant_lesson',note:null},retrospective:{status:'no_new_lesson',candidates:[],reason:null}},edits:{'target.mjs':'target.txt'}}));
160
+ fs.writeFileSync(path.join(answers,'target.txt'),'export const value = 42;\n');
161
+ const plan=path.join(root,'plan.json');
162
+ fs.writeFileSync(plan,JSON.stringify({config:'run.json',mode:'create',hostContext:'commander-host',controlConfig:'control.json',
163
+ permissions:['--review-config','review.json'],answers:'answers',checks:[{id:'syntax',command:[process.execPath,'--check','target.mjs']}]}));
164
+ const env={...process.env,PATH:bin+path.delimiter+process.env.PATH,CM_WORKFLOW_HOME:path.join(root,'home'),CM_WORKFLOW_LOG_HOME:path.join(root,'logs')};
165
+ const started=spawnSync(process.execPath,[DRIVER,'--plan',plan,'start'],{encoding:'utf8',timeout:60000,env});
166
+ assert.equal(started.status,0,started.stderr);assert.equal(JSON.parse(started.stdout).result.state,'awaiting_review',started.stdout);
167
+ return {specsDir,codeProject,store:path.join(specsDir,'.reviews/.execution/commander-run/state.json')};
168
+ }
169
+
170
+ test('a real run replays into the ledger read-only, and an unreplayable copy keeps its task mapping',t=>{
171
+ const p=project(t),before=fs.readFileSync(p.store);
172
+ // Every file and directory under specs, with size and mtime, before and after.
173
+ const listing=dir=>fs.readdirSync(dir,{recursive:true}).sort().map(name=>{const s=fs.lstatSync(path.join(dir,name));
174
+ return `${name}|${s.isDirectory()?'d':s.size}|${s.mtimeMs}`;});
175
+ const tree=listing(p.specsDir);
176
+ const live=buildLedger({specsDir:p.specsDir,codeProject:p.codeProject});
177
+ const task=live.features[0].tasks[0];
178
+ assert.equal(task.status,'in_run');assert.equal(task.verified,true);assert.equal(task.runState,'awaiting_review');
179
+ assert.equal(live.next.kind,'wait_run','the run was just active');assert.equal(live.next.runId,'commander-run');
180
+ const later=buildLedger({specsDir:p.specsDir,codeProject:p.codeProject,now:new Date(Date.now()+2*3600000).toISOString()});
181
+ assert.equal(later.next.kind,'attend_run');assert.match(later.next.how,/cm-ai-drive\.mjs status/);
182
+ assert.deepEqual(listing(p.specsDir),tree,'reading the ledger adds, removes or modifies nothing under specs');
183
+ const text=main(['ledger','--specs',p.specsDir,'--code-project',p.codeProject]);
184
+ assert.equal(text.code,0);assert.match(text.text,/下一步:等 1\.work T-001/);
185
+ assert.equal(main(['ledger','--specs',p.specsDir]).code,2,'missing code project is a usage error');
186
+ // Append a record type this runtime does not know, keeping the hash chain valid.
187
+ const state=JSON.parse(before),last=state.records.at(-1);
188
+ const body={version:1,seq:last.seq+1,id:`runner.${String(last.seq+1).padStart(6,'0')}`,kind:'result',
189
+ payload:{version:3,protocol:'cm-task-runner',type:'foreign-branch-record'},previousDigest:last.digest};
190
+ state.records.push({...body,digest:digest(body)});const {revision,...rest}=state;
191
+ fs.writeFileSync(p.store,JSON.stringify({...rest,revision:digest(rest)})+'\n');
192
+ const foreign=buildLedger({specsDir:p.specsDir,codeProject:p.codeProject}).features[0].tasks[0];
193
+ assert.equal(foreign.status,'in_run');assert.equal(foreign.verified,false);assert.equal(foreign.runId,'commander-run');
194
+ assert.match(renderLedger(buildLedger({specsDir:p.specsDir,codeProject:p.codeProject})),/回放不了记录的运行 1 个/);
195
+ });
196
+
197
+ test('raw hints map an unreplayable run to its task, predecessors and commit record',()=>{
198
+ const records=[{payload:{protocol:'cm-task-runner',type:'init',config:{identity:{taskId:'T-007'},
199
+ completion:{owner:{tasksPath:'/s/7.skins/tasks.md'}}}}},
200
+ {payload:{type:'evidence-superseded',record:{previousRunIds:['old-1','old-2',3]}}},
201
+ {payload:{type:'task-commit-result'}}];
202
+ assert.deepEqual(rawHints(records),{feature:'7.skins',taskId:'T-007',previousRunIds:['old-1','old-2'],committed:true});
203
+ assert.deepEqual(rawHints([{payload:{config:{identity:{taskId:'T-1'},taskLearning:{feature:'1.a'}}}}]),
204
+ {feature:'1.a',taskId:'T-1',previousRunIds:[],committed:false});
205
+ });
206
+
207
+ test('a structural supersession check needs the record in place, valid, and naming this run and task',()=>{
208
+ const record={version:1,feature:'7.skins',taskId:'T-007',newRunId:'new',previousRunIds:['old'],reason:'r',files:[],
209
+ authorizedAt:'2026-10-20T09:00:00.000Z'};
210
+ const records=at=>[{kind:'result',payload:{type:'init'}},...(at===1?[]:[{kind:'result',payload:{type:'x'}}]),
211
+ {kind:'result',payload:{type:'evidence-superseded',record}}];
212
+ const hints={feature:'7.skins',taskId:'T-007'};
213
+ assert.deepEqual(checkedSupersession(records(1),'new',hints),['old']);
214
+ assert.deepEqual(checkedSupersession(records(2),'new',hints),[],'only the second record counts, as in replay');
215
+ assert.deepEqual(checkedSupersession(records(1),'other',hints),[],'it must name this run');
216
+ assert.deepEqual(checkedSupersession(records(1),'new',{...hints,taskId:'T-008'}),[],'and this task');
217
+ const forged=[records(1)[0],{kind:'result',payload:{type:'evidence-superseded',record:{...record,files:'x'}}}];
218
+ assert.deepEqual(checkedSupersession(forged,'new',hints),[],'and pass the shared record validator');
219
+ });
220
+
221
+ test('a supersession is believed only when the run’s start binds snapshot, init and feature together',()=>{
222
+ const init=(over={})=>({kind:'result',payload:{version:3,type:'init',protocol:'cm-task-runner',config:{
223
+ identity:{repositoryId:'repo',runId:'new',taskId:'T-007',...over.identity},
224
+ completion:{owner:{tasksPath:'/s/7.skins/tasks.md'}},taskLearning:{feature:over.feature??'7.skins'}}}});
225
+ const snapshot={identity:{repositoryId:'repo',runId:'new'}};
226
+ assert.equal(originBound([init()],snapshot,'new'),true);
227
+ assert.equal(originBound([init({identity:{runId:'different-run'}})],snapshot,'new'),false,'init must name this run');
228
+ assert.equal(originBound([init({feature:'8.other'})],snapshot,'new'),false,'task path and learning feature must agree');
229
+ assert.equal(originBound([init({identity:{repositoryId:'elsewhere'}})],snapshot,'new'),false,'and the snapshot repository');
230
+ assert.equal(originBound([init()],null,'new'),false,'without a validated snapshot nothing binds');
231
+ });
232
+
233
+ test('a state file that exists but cannot be read is unreadable, not an empty residue',t=>{
234
+ const specs=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-commander-eacces-')));
235
+ const runDir=path.join(specs,'.reviews','.execution','locked');fs.mkdirSync(runDir,{recursive:true});
236
+ fs.writeFileSync(path.join(runDir,'state.json'),'{}');fs.mkdirSync(path.join(specs,'.reviews','.execution','residue'));
237
+ fs.chmodSync(runDir,0o000);
238
+ t.after(()=>{fs.chmodSync(runDir,0o700);fs.rmSync(specs,{recursive:true,force:true});});
239
+ const {runs,error}=readRuns(specs);
240
+ assert.equal(error,null);
241
+ assert.deepEqual(runs.map(r=>[r.runId,r.kind,r.code??null]),[['locked','unreadable','EACCES'],['residue','empty',null]]);
242
+ });
243
+
244
+ test('reading a chain-valid journal whose init names another run trusts none of its supersession',t=>{
245
+ const specs=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-commander-forged-')));t.after(()=>fs.rmSync(specs,{recursive:true,force:true}));
246
+ const runDir=path.join(specs,'.reviews','.execution','new');fs.mkdirSync(runDir,{recursive:true,mode:0o700});
247
+ fs.chmodSync(path.join(specs,'.reviews','.execution'),0o700);fs.chmodSync(runDir,0o700);
248
+ const config={identity:{repositoryId:'repo',runId:'different-run',taskId:'T-007'},
249
+ completion:{owner:{tasksPath:path.join(specs,'7.skins','tasks.md')}},taskLearning:{feature:'7.skins'}};
250
+ const record={version:1,feature:'7.skins',taskId:'T-007',newRunId:'new',previousRunIds:['old'],reason:'r',files:[],
251
+ authorizedAt:'2026-10-20T09:00:00.000Z'};
252
+ const payloads=[{config,version:3,protocol:'cm-task-runner',type:'init'},{record,version:3,protocol:'cm-task-runner',type:'evidence-superseded'}];
253
+ let previous=null;const records=payloads.map((payload,i)=>{const body={version:1,seq:i+1,id:`runner.${String(i+1).padStart(6,'0')}`,
254
+ kind:'result',payload,previousDigest:previous};previous=digest(body);return {...body,digest:previous};});
255
+ const body={version:1,identity:{repositoryId:'repo',runId:'new'},fingerprints:{workflow:'a'.repeat(64),config:'b'.repeat(64),inputs:'c'.repeat(64)},records};
256
+ fs.writeFileSync(path.join(runDir,'state.json'),JSON.stringify({...body,revision:digest(body)})+'\n',{mode:0o600});
257
+ const [run]=readRuns(specs).runs;
258
+ assert.equal(run.kind,'cm-ai');assert.equal(run.verified,false);assert.equal(run.chainVerified,true,'the chain itself is intact');
259
+ assert.deepEqual(run.claimedPrevious,['old']);assert.deepEqual(run.trustedPrevious,[],'an unbound start proves no supersession');
260
+ });