@aibyzero/cm-workflow 0.17.1 → 0.19.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 (357) hide show
  1. package/.codex-plugin/plugin.json +1 -1
  2. package/AGENTS.md +23 -0
  3. package/CHANGELOG.md +242 -0
  4. package/README.md +20 -3
  5. package/THIRD_PARTY_NOTICES.md +13 -0
  6. package/VERSION +1 -1
  7. package/compat/claude-commands/cm-challenge.md +3 -0
  8. package/docs/architecture.md +11 -0
  9. package/docs/cm-control-policy-v2.md +127 -9
  10. package/docs/installation.md +310 -4
  11. package/docs/js-workflow-control.md +150 -15
  12. package/docs/live-evidence-drivers.md +28 -4
  13. package/docs/out-of-scope/README.md +25 -0
  14. package/docs/out-of-scope/background-supervisor.md +32 -0
  15. package/docs/reviewed-integration.md +48 -0
  16. package/docs/user-guide.md +50 -21
  17. package/install-codex.sh +331 -18
  18. package/install.ps1 +28 -2
  19. package/install.sh +321 -17
  20. package/package.json +2 -1
  21. package/runtime/js/autonomy.mjs +152 -0
  22. package/runtime/js/cm-ai/batch-location.mjs +55 -0
  23. package/runtime/js/cm-ai/batch-plan.mjs +242 -0
  24. package/runtime/js/cm-ai/checkpoint-package-material.mjs +162 -0
  25. package/runtime/js/cm-ai/claude-developer-proposal.schema.json +55 -1
  26. package/runtime/js/cm-ai/claude-review-stream.mjs +83 -14
  27. package/runtime/js/cm-ai/claude-tool-preview.mjs +11 -9
  28. package/runtime/js/cm-ai/cm-ai-admission.mjs +56 -17
  29. package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +91 -6
  30. package/runtime/js/cm-ai/cm-ai-qa-log.mjs +5 -1
  31. package/runtime/js/cm-ai/codex-config.mjs +6 -2
  32. package/runtime/js/cm-ai/codex-developer-basic-output.schema.json +3 -2
  33. package/runtime/js/cm-ai/codex-developer-output.schema.json +2 -1
  34. package/runtime/js/cm-ai/codex-reconnect-notice.mjs +6 -0
  35. package/runtime/js/cm-ai/codex-review-adapter.mjs +27 -7
  36. package/runtime/js/cm-ai/control-policy.mjs +21 -4
  37. package/runtime/js/cm-ai/developer-adapter.mjs +19 -5
  38. package/runtime/js/cm-ai/drive-core.mjs +115 -11
  39. package/runtime/js/cm-ai/drive-rate-limit.mjs +105 -0
  40. package/runtime/js/cm-ai/durable-runner-state.mjs +234 -33
  41. package/runtime/js/cm-ai/effect-contract.mjs +11 -2
  42. package/runtime/js/cm-ai/execution-policy.mjs +3 -1
  43. package/runtime/js/cm-ai/execution-snapshot.mjs +4 -2
  44. package/runtime/js/cm-ai/execution-store-limits.mjs +14 -7
  45. package/runtime/js/cm-ai/execution-store.mjs +60 -17
  46. package/runtime/js/cm-ai/fix-code-association.mjs +73 -2
  47. package/runtime/js/cm-ai/host-check.mjs +11 -5
  48. package/runtime/js/cm-ai/host-conversation-execution.mjs +70 -28
  49. package/runtime/js/cm-ai/host-qa-executor.mjs +38 -5
  50. package/runtime/js/cm-ai/host-qa-fix-owner.mjs +2 -2
  51. package/runtime/js/cm-ai/host-qa-policy.mjs +19 -2
  52. package/runtime/js/cm-ai/host-replay.mjs +148 -0
  53. package/runtime/js/cm-ai/host-session.mjs +1 -1
  54. package/runtime/js/cm-ai/host-workflow-capabilities.mjs +19 -2
  55. package/runtime/js/cm-ai/host.mjs +1 -1
  56. package/runtime/js/cm-ai/implicit-qa-decision.mjs +5 -0
  57. package/runtime/js/cm-ai/integration-snapshots.mjs +50 -0
  58. package/runtime/js/cm-ai/live-evidence.mjs +28 -6
  59. package/runtime/js/cm-ai/operator-guidance.mjs +9 -2
  60. package/runtime/js/cm-ai/owned-process-cleanup.mjs +27 -9
  61. package/runtime/js/cm-ai/process-group-exit.mjs +46 -0
  62. package/runtime/js/cm-ai/provider-review-observation.mjs +3 -2
  63. package/runtime/js/cm-ai/qa-attachment.mjs +22 -0
  64. package/runtime/js/cm-ai/qa-config-revision.mjs +7 -2
  65. package/runtime/js/cm-ai/requirement-evidence.mjs +102 -0
  66. package/runtime/js/cm-ai/review-package.mjs +79 -7
  67. package/runtime/js/cm-ai/review-presentation-delta.mjs +166 -0
  68. package/runtime/js/cm-ai/review-presentation.mjs +177 -8
  69. package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +70 -2
  70. package/runtime/js/cm-ai/reviewed-integration.mjs +260 -0
  71. package/runtime/js/cm-ai/scope-revision.mjs +38 -0
  72. package/runtime/js/cm-ai/specification-material.mjs +2 -2
  73. package/runtime/js/cm-ai/task-runner.mjs +242 -39
  74. package/runtime/js/cm-ai/verification-auto.mjs +38 -0
  75. package/runtime/js/cm-ai/worker-claude-developer.mjs +39 -15
  76. package/runtime/js/cm-ai/worker-claude.mjs +35 -13
  77. package/runtime/js/cm-ai/worker-codex-developer.mjs +43 -17
  78. package/runtime/js/cm-ai/worker-codex.mjs +41 -7
  79. package/runtime/js/cm-fix/cause-invocation.mjs +16 -2
  80. package/runtime/js/cm-fix/cause-package.mjs +46 -1
  81. package/runtime/js/cm-fix/command-correction.mjs +37 -0
  82. package/runtime/js/cm-fix/cooperative.mjs +12 -0
  83. package/runtime/js/cm-fix/dossier.mjs +8 -2
  84. package/runtime/js/cm-fix/execution.mjs +578 -100
  85. package/runtime/js/cm-fix/final-review.mjs +39 -8
  86. package/runtime/js/cm-fix/finish.mjs +15 -11
  87. package/runtime/js/cm-fix/host-review.mjs +65 -10
  88. package/runtime/js/cm-fix/host.mjs +35 -12
  89. package/runtime/js/cm-fix/jest-command-correction.mjs +69 -0
  90. package/runtime/js/cm-fix/metrics.mjs +18 -5
  91. package/runtime/js/cm-fix/regression-evidence.mjs +3 -2
  92. package/runtime/js/cm-fix/regression.mjs +16 -7
  93. package/runtime/js/cm-fix/repair.mjs +29 -8
  94. package/runtime/js/cm-fix/review-verification-command.mjs +135 -0
  95. package/runtime/js/cm-fix/review-verification-contract.mjs +54 -0
  96. package/runtime/js/cm-fix/review-verification-diagnostic.mjs +75 -0
  97. package/runtime/js/cm-fix/review-verification-recovery.mjs +44 -0
  98. package/runtime/js/cm-fix/review-verification-server.mjs +38 -0
  99. package/runtime/js/cm-fix/review-verification.mjs +214 -0
  100. package/runtime/js/cm-fix/source-correction-recovery.mjs +65 -0
  101. package/runtime/js/cm-fix/start.mjs +6 -3
  102. package/runtime/js/cm-fix/test-type-correction.mjs +86 -0
  103. package/runtime/js/cm-fix/test-type-recovery.mjs +51 -0
  104. package/runtime/js/cm-fix/type-import-correction.mjs +89 -0
  105. package/runtime/js/cm-prd/accepted-design.mjs +8 -0
  106. package/runtime/js/cm-prd/analysis.mjs +13 -9
  107. package/runtime/js/cm-prd/change.mjs +37 -16
  108. package/runtime/js/cm-prd/draft-save.mjs +13 -6
  109. package/runtime/js/cm-prd/draft.mjs +31 -3
  110. package/runtime/js/cm-prd/failed-correction.mjs +19 -3
  111. package/runtime/js/cm-prd/inputs-replaced.mjs +3 -0
  112. package/runtime/js/cm-prd/review-correction.mjs +6 -4
  113. package/runtime/js/cm-prd/review-disposition.mjs +7 -1
  114. package/runtime/js/cm-prd/self-check-revision.mjs +2 -2
  115. package/runtime/js/cm-prd/self-check.mjs +125 -6
  116. package/runtime/js/cm-prd/session.mjs +30 -1
  117. package/runtime/js/cm-prd/summary.mjs +11 -5
  118. package/runtime/js/cm-prd/task-scope-record.mjs +97 -0
  119. package/runtime/js/cm-prd/tree-digest.mjs +34 -0
  120. package/runtime/js/cm-prd/validation-reason.mjs +8 -4
  121. package/runtime/js/cm-security/scan.mjs +1 -1
  122. package/runtime/js/commander/decision.mjs +44 -0
  123. package/runtime/js/commander/dispatch-registry.mjs +110 -0
  124. package/runtime/js/commander/ledger.mjs +265 -0
  125. package/runtime/js/commander/preflight.mjs +107 -0
  126. package/runtime/js/notify-later.mjs +13 -0
  127. package/runtime/js/notify-send.mjs +6 -2
  128. package/runtime/js/notify.mjs +581 -65
  129. package/runtime/js/review-findings.mjs +38 -0
  130. package/runtime/js/session-boundary.mjs +56 -0
  131. package/runtime/js/session-handoff.mjs +68 -0
  132. package/runtime/js/spec-task-line.mjs +27 -13
  133. package/runtime/js/specs-status.mjs +5 -4
  134. package/runtime/js/task-scope.mjs +197 -0
  135. package/runtime/logging.md +6 -1
  136. package/runtime/model-efficiency.md +69 -10
  137. package/runtime/orchestration.md +3 -1
  138. package/runtime/project-learning.md +2 -0
  139. package/runtime/review.md +3 -2
  140. package/runtime/test-contract.md +1 -0
  141. package/scripts/ci-test-weights.json +3 -0
  142. package/scripts/cm-ai-admission.mjs +21 -7
  143. package/scripts/cm-ai-admission.test.mjs +171 -3
  144. package/scripts/cm-ai-batch-drive.mjs +79 -18
  145. package/scripts/cm-ai-batch-drive.test.mjs +169 -3
  146. package/scripts/cm-ai-batch-host.mjs +38 -9
  147. package/scripts/cm-ai-batch-host.test.mjs +6 -5
  148. package/scripts/cm-ai-batch-learning-merge.test.mjs +36 -0
  149. package/scripts/cm-ai-batch-location.test.mjs +57 -0
  150. package/scripts/cm-ai-batch-plan.mjs +52 -0
  151. package/scripts/cm-ai-batch-plan.test.mjs +397 -0
  152. package/scripts/cm-ai-batch-run-fixture.mjs +446 -35
  153. package/scripts/cm-ai-batch-run-member-stops.test.mjs +16 -0
  154. package/scripts/cm-ai-batch-run-parallel.test.mjs +28 -1
  155. package/scripts/cm-ai-batch-run.mjs +471 -57
  156. package/scripts/cm-ai-batch-run.test.mjs +23 -4
  157. package/scripts/cm-ai-batch-session-e2e.test.mjs +235 -0
  158. package/scripts/cm-ai-batch-session-member.test.mjs +293 -0
  159. package/scripts/cm-ai-batch-session-recovery.test.mjs +423 -0
  160. package/scripts/cm-ai-check-recheck-cancellation.test.mjs +247 -0
  161. package/scripts/cm-ai-checklist-coverage.test.mjs +4 -2
  162. package/scripts/cm-ai-checkpoint-package-material.test.mjs +221 -0
  163. package/scripts/cm-ai-checkpoint-package-owner.test.mjs +193 -0
  164. package/scripts/cm-ai-control-launch.test.mjs +21 -0
  165. package/scripts/cm-ai-control-policy.test.mjs +14 -0
  166. package/scripts/cm-ai-control-v2-drive.test.mjs +398 -3
  167. package/scripts/cm-ai-control-v2-supersede-race.mjs +25 -0
  168. package/scripts/cm-ai-control-v2-supersede.test.mjs +318 -0
  169. package/scripts/cm-ai-develop-driver-gaps.test.mjs +163 -0
  170. package/scripts/cm-ai-development-rework.test.mjs +423 -0
  171. package/scripts/cm-ai-drive.mjs +73 -17
  172. package/scripts/cm-ai-drive.test.mjs +34 -2
  173. package/scripts/cm-ai-execution-store-legacy-probe.test.mjs +84 -0
  174. package/scripts/cm-ai-host.mjs +60 -19
  175. package/scripts/cm-ai-integration-adoption.test.mjs +223 -0
  176. package/scripts/cm-ai-integration-independence.test.mjs +23 -0
  177. package/scripts/cm-ai-integration-launch.test.mjs +240 -0
  178. package/scripts/cm-ai-integration-preview.mjs +41 -0
  179. package/scripts/cm-ai-integration-snapshots.test.mjs +197 -0
  180. package/scripts/cm-ai-nested-execution.test.mjs +29 -1
  181. package/scripts/cm-ai-operator-guidance.test.mjs +16 -1
  182. package/scripts/cm-ai-prefinal-delivery.test.mjs +278 -0
  183. package/scripts/cm-ai-project-qa-gate.test.mjs +56 -0
  184. package/scripts/cm-ai-qa-fingerprint-config.test.mjs +28 -0
  185. package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +36 -2
  186. package/scripts/cm-ai-requirement-evidence.test.mjs +65 -0
  187. package/scripts/cm-ai-review-failure.test.mjs +150 -5
  188. package/scripts/cm-ai-run.mjs +88 -21
  189. package/scripts/cm-ai-scope-revision.test.mjs +341 -0
  190. package/scripts/cm-ai-spec-rebind.test.mjs +13 -0
  191. package/scripts/cm-ai-supersede.test.mjs +28 -0
  192. package/scripts/cm-ai-verification-auto.test.mjs +99 -0
  193. package/scripts/cm-announce-hook.mjs +35 -8
  194. package/scripts/cm-announce-hook.test.mjs +25 -0
  195. package/scripts/cm-autonomy.mjs +94 -0
  196. package/scripts/cm-autonomy.test.mjs +162 -0
  197. package/scripts/cm-challenge.test.mjs +61 -0
  198. package/scripts/cm-check-drive-files.mjs +1 -1
  199. package/scripts/cm-check-runtime.sh +60 -1
  200. package/scripts/cm-claude-developer-worker.test.mjs +56 -7
  201. package/scripts/cm-claude-install-layout.test.mjs +1 -1
  202. package/scripts/cm-claude-review-diagnostics.test.mjs +235 -0
  203. package/scripts/cm-claude-review-stream.test.mjs +13 -0
  204. package/scripts/cm-codex-developer-reconnect-notice.test.mjs +98 -0
  205. package/scripts/cm-codex-developer-worker.test.mjs +120 -0
  206. package/scripts/cm-codex-install-local-edit-guard.test.mjs +436 -0
  207. package/scripts/cm-codex-prompt-input.test.mjs +153 -0
  208. package/scripts/cm-codex-reconnect-notice.test.mjs +167 -0
  209. package/scripts/cm-commander-ledger.test.mjs +260 -0
  210. package/scripts/cm-commander-p2.test.mjs +295 -0
  211. package/scripts/cm-commander-preflight.mjs +84 -0
  212. package/scripts/cm-commander.mjs +116 -0
  213. package/scripts/cm-config-lock.mjs +35 -0
  214. package/scripts/cm-controlled-correction.test.mjs +10 -1
  215. package/scripts/cm-developer-failure-code.test.mjs +62 -0
  216. package/scripts/cm-display-task-id.test.mjs +41 -0
  217. package/scripts/cm-efficiency-presentation-delta.test.mjs +218 -0
  218. package/scripts/cm-execution-snapshot-reuse.test.mjs +115 -0
  219. package/scripts/cm-external-batch-host.test.mjs +4 -3
  220. package/scripts/cm-external-process-cleanup.test.mjs +128 -0
  221. package/scripts/cm-external-qa-fix.test.mjs +89 -7
  222. package/scripts/cm-external-review-reconciliation.test.mjs +11 -0
  223. package/scripts/cm-failover.mjs +48 -10
  224. package/scripts/cm-failover.test.mjs +46 -0
  225. package/scripts/cm-fix-cause-invocation.test.mjs +19 -4
  226. package/scripts/cm-fix-command-correction.mjs +17 -0
  227. package/scripts/cm-fix-command-correction.test.mjs +211 -0
  228. package/scripts/cm-fix-cooperative-closeout.test.mjs +87 -0
  229. package/scripts/cm-fix-diagnosis-module-correction.test.mjs +217 -0
  230. package/scripts/cm-fix-drive.mjs +33 -5
  231. package/scripts/cm-fix-drive.test.mjs +49 -0
  232. package/scripts/cm-fix-host-review-assembly.test.mjs +197 -1
  233. package/scripts/cm-fix-host-review.test.mjs +21 -9
  234. package/scripts/cm-fix-host.mjs +26 -8
  235. package/scripts/cm-fix-monorepo-map.test.mjs +92 -0
  236. package/scripts/cm-fix-observation-task-id.test.mjs +122 -0
  237. package/scripts/cm-fix-regression-input-budget.test.mjs +111 -0
  238. package/scripts/cm-fix-repair-input-budget.test.mjs +119 -0
  239. package/scripts/cm-fix-review-file-paging.test.mjs +91 -0
  240. package/scripts/cm-fix-review-preflight.mjs +24 -0
  241. package/scripts/cm-fix-review-storage.test.mjs +233 -0
  242. package/scripts/cm-fix-review-verification-command.test.mjs +242 -0
  243. package/scripts/cm-fix-review-verification-evidence.test.mjs +218 -0
  244. package/scripts/cm-fix-review-verification-integration.test.mjs +81 -0
  245. package/scripts/cm-fix-review-verification-recovery.test.mjs +198 -0
  246. package/scripts/cm-fix-review-verification.test.mjs +146 -0
  247. package/scripts/cm-fix-revision-transport.test.mjs +81 -0
  248. package/scripts/cm-fix-source-correction.test.mjs +296 -0
  249. package/scripts/cm-fix-test-type-correction.mjs +18 -0
  250. package/scripts/cm-fix-test-type-correction.test.mjs +123 -0
  251. package/scripts/cm-fix-test-type-owner.test.mjs +208 -0
  252. package/scripts/cm-fix-test-type-verification-cost.test.mjs +66 -0
  253. package/scripts/cm-fix-type-import-correction.test.mjs +95 -0
  254. package/scripts/cm-fix-verification-diagnostic.test.mjs +200 -0
  255. package/scripts/cm-fix-verification-recovery.mjs +33 -0
  256. package/scripts/cm-host-qa-executor.test.mjs +77 -0
  257. package/scripts/cm-host-replay.test.mjs +176 -0
  258. package/scripts/cm-install-local-edit-guard.test.mjs +621 -0
  259. package/scripts/cm-install-manifest.sh +351 -0
  260. package/scripts/cm-live-evidence.test.mjs +59 -1
  261. package/scripts/cm-log-event.mjs +61 -10
  262. package/scripts/cm-log-event.test.mjs +121 -1
  263. package/scripts/cm-matt-skills.mjs +576 -0
  264. package/scripts/cm-matt-skills.test.mjs +550 -0
  265. package/scripts/cm-notify-command.test.mjs +42 -10
  266. package/scripts/cm-notify.mjs +14 -10
  267. package/scripts/cm-notify.test.mjs +581 -59
  268. package/scripts/cm-patrol.mjs +4 -1
  269. package/scripts/cm-patrol.test.mjs +23 -5
  270. package/scripts/cm-prd-answer-gaps.test.mjs +2 -2
  271. package/scripts/cm-prd-completion.test.mjs +56 -13
  272. package/scripts/cm-prd-design-phase.test.mjs +78 -8
  273. package/scripts/cm-prd-draft-save.test.mjs +12 -0
  274. package/scripts/cm-prd-draft.test.mjs +1 -1
  275. package/scripts/cm-prd-drive.mjs +13 -6
  276. package/scripts/cm-prd-drive.test.mjs +45 -1
  277. package/scripts/cm-prd-gate-diagnostic.test.mjs +2 -2
  278. package/scripts/cm-prd-host.mjs +10 -5
  279. package/scripts/cm-prd-host.test.mjs +4 -2
  280. package/scripts/cm-prd-inputs-replaced.test.mjs +1 -1
  281. package/scripts/cm-prd-review-disposition.test.mjs +124 -8
  282. package/scripts/cm-prd-revision.test.mjs +1 -1
  283. package/scripts/cm-prd-self-check-revision.test.mjs +1 -1
  284. package/scripts/cm-prd-self-check-rules.test.mjs +239 -0
  285. package/scripts/cm-prd-self-check.test.mjs +105 -5
  286. package/scripts/cm-prd-summary.test.mjs +24 -3
  287. package/scripts/cm-prd-task-grouping.test.mjs +6 -6
  288. package/scripts/cm-prd-tree-digest.test.mjs +74 -0
  289. package/scripts/cm-refactor-drive.mjs +2 -1
  290. package/scripts/cm-refactor-drive.test.mjs +9 -0
  291. package/scripts/cm-release-smoke.sh +1 -1
  292. package/scripts/cm-skill-hints-autowire.test.mjs +394 -0
  293. package/scripts/cm-skill-hints-exam.mjs +149 -0
  294. package/scripts/cm-skill-hints-install.test.mjs +168 -0
  295. package/scripts/cm-skill-hints.exam.json +706 -0
  296. package/scripts/cm-skill-hints.json +119 -0
  297. package/scripts/cm-skill-hints.mjs +669 -0
  298. package/scripts/cm-skill-hints.test.mjs +831 -0
  299. package/scripts/cm-skill-judge.mjs +181 -0
  300. package/scripts/cm-skill-judge.test.mjs +255 -0
  301. package/scripts/cm-specs-status.test.mjs +4 -2
  302. package/scripts/cm-start-check.mjs +323 -0
  303. package/scripts/cm-start-check.test.mjs +406 -0
  304. package/scripts/cm-task-gate.mjs +150 -29
  305. package/scripts/cm-task-gate.test.mjs +73 -1
  306. package/scripts/cm-task-id-grammar.test.mjs +66 -0
  307. package/scripts/cm-task-scope.test.mjs +308 -0
  308. package/scripts/cm-upgrade-compat-batch.test.mjs +172 -0
  309. package/scripts/cm-upgrade-compat.test.mjs +239 -0
  310. package/scripts/cm-workflow-config.mjs +12 -2
  311. package/scripts/fixtures/fix-verification-claude.mjs +44 -0
  312. package/scripts/fixtures/reviewed-integration.mjs +202 -0
  313. package/scripts/scan-public-safety.py +1 -0
  314. package/scripts/session-boundary.test.mjs +170 -0
  315. package/scripts/test-npm-install.py +14 -3
  316. package/scripts/test-shell-compat.sh +2 -0
  317. package/scripts/validate-public-repo.py +4 -0
  318. package/scripts/validate-test-cases.mjs +3 -2
  319. package/skills/cm-ai/SKILL.md +5 -2
  320. package/skills/cm-ai/references/N3-execute-task.md +1 -1
  321. package/skills/cm-ai/references/N4-review.md +2 -1
  322. package/skills/cm-ai/references/N6-qa-eval.md +3 -1
  323. package/skills/cm-ai/references/N8-finish.md +22 -0
  324. package/skills/cm-ai/references/js-host-qa-recovery.md +1 -1
  325. package/skills/cm-ai/references/js-host-recovery.md +79 -3
  326. package/skills/cm-ai/references/js-host.md +82 -16
  327. package/skills/cm-challenge/SKILL.md +65 -0
  328. package/skills/cm-challenge/evals/README.md +18 -0
  329. package/skills/cm-challenge/evals/trigger-cases.json +20 -0
  330. package/skills/cm-challenge/evals/trigger-config.json +28 -0
  331. package/skills/cm-challenge/references/examples.md +15 -0
  332. package/skills/cm-check/SKILL.md +5 -0
  333. package/skills/cm-check/references/js-host.md +2 -0
  334. package/skills/cm-fix/SKILL.md +12 -3
  335. package/skills/cm-fix/references/command-correction.md +67 -0
  336. package/skills/cm-fix/references/isolated-review.md +54 -0
  337. package/skills/cm-fix/references/js-host.md +62 -2
  338. package/skills/cm-fix/references/test-type-correction.md +72 -0
  339. package/skills/cm-fix/references/verification-recovery.md +114 -0
  340. package/skills/cm-idea/SKILL.md +2 -0
  341. package/skills/cm-idea/references/js-host.md +2 -0
  342. package/skills/cm-notify/SKILL.md +2 -0
  343. package/skills/cm-prd/SKILL.md +14 -9
  344. package/skills/cm-prd/references/brownfield.md +8 -1
  345. package/skills/cm-prd/references/change-mode.md +8 -1
  346. package/skills/cm-prd/references/greenfield.md +4 -0
  347. package/skills/cm-prd/references/js-change-recovery.md +14 -0
  348. package/skills/cm-prd/references/js-host.md +4 -2
  349. package/skills/cm-prd/references/spec-self-check.md +5 -1
  350. package/skills/cm-refactor/SKILL.md +8 -0
  351. package/skills/cm-refactor/references/js-host.md +2 -0
  352. package/skills/cm-test/SKILL.md +4 -0
  353. package/templates/dashboard/dashboard.html +2 -2
  354. package/templates/pixel/cm-pixel.html +1 -1
  355. package/templates/pixel/cm-pixel.sh +1 -1
  356. package/templates/pixel/dev/template.html +1 -1
  357. package/templates/statusline/cm-statusline.sh +1 -1
@@ -0,0 +1,423 @@
1
+ // R2-01: the recovery table of design 3.4 driven through the real batch session
2
+ // entry (cm-ai-batch-drive.mjs -> cm-ai-batch-host.mjs -> member run). The test
3
+ // plays the current session on the live develop channel. Every scenario checks the
4
+ // number of live develop requests, the final state/code, the target bytes, the
5
+ // review count (fixture Codex witness) and the member's durable journal.
6
+ import test from 'node:test';
7
+ import assert from 'node:assert/strict';
8
+ import fs from 'node:fs';
9
+ import os from 'node:os';
10
+ import path from 'node:path';
11
+ import {createHash} from 'node:crypto';
12
+ import {spawn,spawnSync} from 'node:child_process';
13
+ import {fileURLToPath,pathToFileURL} from 'node:url';
14
+ import {buildManifest} from './cm-spec-manifest.mjs';
15
+ import {configFingerprint} from '../runtime/js/cm-ai/codex-config.mjs';
16
+
17
+ const BATCH=fileURLToPath(new URL('./cm-ai-batch-drive.mjs',import.meta.url));
18
+ const key='1.work/T-001',identity={repositoryId:'session-recovery-fixture'};
19
+ const ORIGINAL='export const value = 1;\n',PROPOSED='export const value = 42;\n';
20
+ const sha=text=>createHash('sha256').update(text).digest('hex');
21
+ const learning={application:{status:'no_relevant_lesson',note:null},retrospective:{status:'no_new_lesson',candidates:[],reason:null}};
22
+
23
+ // Same fixture as cm-ai-batch-session-e2e.test.mjs, with a tracked target.mjs so a
24
+ // stale proposal and a partially changed code root can be told apart.
25
+ function fixture(t){
26
+ const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-session-recovery-')));
27
+ t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
28
+ const specsDir=path.join(root,'specs'),codeProject=path.join(root,'app'),bin=path.join(root,'bin'),witness=path.join(root,'witness.jsonl');
29
+ fs.mkdirSync(path.join(specsDir,'1.work'),{recursive:true});fs.mkdirSync(codeProject);fs.mkdirSync(bin);
30
+ for(const name of ['requirements.md','design.md'])fs.writeFileSync(path.join(specsDir,'1.work',name),'# Fixture\n');
31
+ fs.writeFileSync(path.join(specsDir,'1.work/tasks.md'),'- [ ] T-001: walk the page\n - 范围: `target.mjs`\n - 开发: 会话\n');
32
+ fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:['1.work'],
33
+ specFiles:buildManifest(specsDir),taskGrammar:3}));
34
+ fs.writeFileSync(path.join(codeProject,'requirements.md'),'# Fixture\n');
35
+ fs.writeFileSync(path.join(codeProject,'target.mjs'),ORIGINAL);
36
+ fs.writeFileSync(path.join(codeProject,'.cm-workflow.json'),JSON.stringify({version:1,runtimes:{available:'codex'},
37
+ roles:{coder:{adapter:'codex-cli'},reviewer:{adapter:'codex-cli'}}}));
38
+ for(const args of [['init','-b','main'],['config','user.name','Fixture'],['config','user.email','fixture@example.invalid'],['add','-A'],['commit','-m','baseline']]){
39
+ const r=spawnSync('git',['-C',codeProject,...args],{encoding:'utf8'});assert.equal(r.status,0,r.stderr);
40
+ }
41
+ fs.writeFileSync(path.join(root,'run.json'),JSON.stringify({batch:{version:1,repositoryId:identity.repositoryId,batchId:'session-recovery-batch',
42
+ specsDir,codeProject,tasks:[{feature:'1.work',taskId:'T-001',scope:['target.mjs'],requirements:['requirements.md']}],
43
+ memberDevelopment:{[key]:'session'}},
44
+ workflows:{[key]:{qa:null,documentationPaths:[],applicableAgentFiles:[]}}}));
45
+ fs.writeFileSync(path.join(root,'control.json'),JSON.stringify({version:2,development:'provider',bootstrap:'disabled',qa:'disabled',qaFix:'disabled'}));
46
+ fs.writeFileSync(path.join(root,'review.json'),JSON.stringify({model:'fixture',preflight:{passed:true,cli_model:'fixture',
47
+ prompt_transport:'stdin',config_fingerprint:configFingerprint({cwd:codeProject,model:'fixture'})}}));
48
+ fs.writeFileSync(path.join(root,'protected.json'),JSON.stringify({model:'fixture',timeoutMs:5000,
49
+ checkCommands:[{id:'syntax',command:[process.execPath,'--check','target.mjs']}]}));
50
+ const answers=path.join(root,'answers','1.work','T-001');fs.mkdirSync(answers,{recursive:true});
51
+ fs.writeFileSync(path.join(answers,'documentation-inspect.json'),JSON.stringify({status:'completed',reason:'Fixture inspected'}));
52
+ fs.writeFileSync(path.join(bin,'codex'),`#!${process.execPath}
53
+ const fs=require('node:fs'),cp=require('node:child_process');
54
+ const args=process.argv.slice(2),record=row=>fs.appendFileSync(${JSON.stringify(witness)},JSON.stringify(row)+'\\n');
55
+ if(args[0]==='sandbox'){
56
+ const command=args.slice(args.indexOf('--')+1);
57
+ // A check whose answer never arrives: the first check after hang-check was
58
+ // armed outlives the runner's call limit (the marker is consumed).
59
+ const hang=${JSON.stringify(path.join(root,'hang-check'))};
60
+ if(command.includes('--check')&&fs.existsSync(hang)){fs.rmSync(hang);record({type:'check_hang'});setTimeout(()=>process.exit(0),20000);return;}
61
+ record({type:command.includes('--check')?'check':'sandbox'});
62
+ const checked=cp.spawnSync(command[0],command.slice(1),{cwd:process.cwd(),encoding:'utf8'});
63
+ process.stdout.write(checked.stdout??'');process.stderr.write(checked.stderr??'');process.exit(checked.status??1);
64
+ }
65
+ let prompt='';process.stdin.on('data',part=>prompt+=part);process.stdin.on('end',()=>{
66
+ if(prompt.includes('<cm-developer-data-json>')){record({type:'provider_develop'});process.exit(1);}
67
+ const data=JSON.parse(prompt.split('<cm-review-data-json>\\n')[1]);
68
+ const value={verdict:'approved',packageDigest:data.reviewPackage.packageDigest,examinedPaths:data.examinedPaths,findings:[],summary:'Synthetic independent review'};
69
+ record({type:'review',attempt:data.reviewPackage.identity.attempt});
70
+ for(const event of [{type:'thread.started',thread_id:'fixture-session-member-review'},{type:'turn.started'},
71
+ {type:'item.completed',item:{type:'agent_message',text:JSON.stringify(value)}},{type:'turn.completed'}])
72
+ process.stdout.write(JSON.stringify(event)+'\\n');
73
+ });
74
+ `,{mode:0o700});
75
+ const plan=path.join(root,'plan.json'),exchange=path.join(root,'exchange');
76
+ fs.writeFileSync(plan,JSON.stringify({config:'run.json',mode:'create',hostContext:'session-recovery-host',controlConfig:'control.json',
77
+ permissions:['--review-config','review.json','--protected-config','protected.json'],answers:'answers',
78
+ liveEvidence:{directory:'exchange',kinds:['develop'],timeoutMs:60000}}));
79
+ // The member run's host-call limit for a session member is fixed at 30 minutes
80
+ // (host-conversation-execution.mjs outerTimeoutMs) and journaled in the run
81
+ // config. This preload leaves the journaled value alone and only shortens the
82
+ // actual 30-minute timers armed while the shrink file holds a positive number.
83
+ const shrink=path.join(root,'shrink-ms'),preload=path.join(root,'shrink-timer.mjs');
84
+ fs.writeFileSync(preload,`import fs from 'node:fs';
85
+ const original=globalThis.setTimeout;
86
+ const patched=function(fn,delay,...rest){
87
+ if(delay===1800000){try{const value=Number(fs.readFileSync(${JSON.stringify(shrink)},'utf8'));if(value>0)delay=value;}catch{}}
88
+ return original.call(this,fn,delay,...rest);
89
+ };
90
+ for(const key of Reflect.ownKeys(original))if(!Reflect.has(patched,key)||typeof key==='symbol')try{patched[key]=original[key];}catch{}
91
+ globalThis.setTimeout=patched;
92
+ `);
93
+ return {root,specsDir,codeProject,plan,witness,exchange,shrink,target:path.join(codeProject,'target.mjs'),
94
+ env:{...process.env,PATH:bin+path.delimiter+process.env.PATH,CM_NOTIFY_OFF:'1',
95
+ NODE_OPTIONS:`${process.env.NODE_OPTIONS??''} --import=${pathToFileURL(preload).href}`.trim(),
96
+ CM_WORKFLOW_HOME:path.join(root,'home'),CM_WORKFLOW_LOG_HOME:path.join(root,'logs')}};
97
+ }
98
+ const writePlan=(f,patch)=>fs.writeFileSync(f.plan,JSON.stringify({...JSON.parse(fs.readFileSync(f.plan,'utf8')),...patch}));
99
+ const resumePlan=(f,patch={})=>writePlan(f,{mode:'resume',originalHostContext:'session-recovery-host',...patch});
100
+ // Every live develop request any driver wrote, oldest first.
101
+ function developRequests(f){
102
+ if(!fs.existsSync(f.exchange))return [];
103
+ const out=[];
104
+ for(const dir of fs.readdirSync(f.exchange)){
105
+ const sub=path.join(f.exchange,dir);if(!fs.statSync(sub).isDirectory())continue;
106
+ for(const name of fs.readdirSync(sub).filter(item=>item.endsWith('.request.json'))){
107
+ const file=path.join(sub,name),row=JSON.parse(fs.readFileSync(file,'utf8'));
108
+ if(row.kind==='develop')out.push({file,row,mtime:fs.statSync(file).mtimeMs});
109
+ }
110
+ }
111
+ return out.sort((a,b)=>a.mtime-b.mtime);
112
+ }
113
+ const witness=f=>fs.existsSync(f.witness)?fs.readFileSync(f.witness,'utf8').trim().split('\n').filter(Boolean).map(JSON.parse):[];
114
+ const reviews=f=>witness(f).filter(row=>row.type==='review').map(row=>row.attempt);
115
+ function journal(f){
116
+ const dir=path.join(f.specsDir,'.reviews','.execution');
117
+ const runs=fs.existsSync(dir)?fs.readdirSync(dir).filter(name=>fs.existsSync(path.join(dir,name,'state.json'))):[];
118
+ assert.equal(runs.length,1,`one member run: ${runs}`);
119
+ return JSON.parse(fs.readFileSync(path.join(dir,runs[0],'state.json'),'utf8')).records;
120
+ }
121
+ const types=f=>journal(f).map(row=>row.payload.type);
122
+ const effectIds=f=>journal(f).filter(row=>row.payload.type==='effect-intent').map(row=>row.payload.effect.id);
123
+ const lastCheckpoint=f=>journal(f).filter(row=>row.payload.type==='effect-checkpoint').at(-1)?.payload.checkpoint??null;
124
+ const dump=f=>JSON.stringify({types:types(f),effects:effectIds(f),cp:lastCheckpoint(f)&&{s:lastCheckpoint(f).state,c:lastCheckpoint(f).code,a:lastCheckpoint(f).attempt},dev:developRequests(f).length,rev:reviews(f),file:fs.readFileSync(f.target,'utf8')});
125
+ const proposal=(request,overrides={})=>({status:'succeeded',value:{outcome:'implemented',...learning},
126
+ edits:[{path:'target.mjs',beforeSha256:request.payload.expected['target.mjs'],content:PROPOSED}],...overrides});
127
+ function reply(file,request,result){
128
+ const target=file.replace(/\.request\.json$/,'.result.json'),tmp=target+'.tmp';
129
+ fs.writeFileSync(tmp,JSON.stringify({type:'host_result',sessionId:request.sessionId,callId:request.callId,
130
+ requestDigest:request.requestDigest,result}),{mode:0o600});fs.renameSync(tmp,target);
131
+ }
132
+ // One driver invocation. respond(request,index) returns a result to write, or
133
+ // undefined to leave the request unanswered. kill(request) may stop the whole
134
+ // driver process group (driver + batch host) with SIGKILL.
135
+ async function drive(f,{operation='advance',respond=request=>proposal(request),onRequest=null,env={},timeoutMs=90000}={}){
136
+ const seen=new Set(developRequests(f).map(item=>item.file));
137
+ const child=spawn(process.execPath,[BATCH,'--plan',f.plan,operation],{env:{...f.env,...env},stdio:['ignore','pipe','pipe'],detached:true});
138
+ let stdout='',stderr='',killed=false;child.stdout.on('data',part=>stdout+=part);child.stderr.on('data',part=>stderr+=part);
139
+ // The batch host runs in its own process group (drive-core.mjs): kill both groups.
140
+ const killGroup=()=>{killed=true;
141
+ const ps=spawnSync('ps',['-A','-o','pid=,ppid='],{encoding:'utf8'}).stdout.trim().split('\n').map(line=>line.trim().split(/\s+/).map(Number));
142
+ for(const [pid,ppid] of ps)if(ppid===child.pid)try{process.kill(-pid,'SIGKILL');}catch{try{process.kill(pid,'SIGKILL');}catch{}}
143
+ try{process.kill(-child.pid,'SIGKILL');}catch{}};
144
+ let index=0;
145
+ const timer=setInterval(()=>{try{
146
+ for(const {file,row} of developRequests(f)){
147
+ if(seen.has(file))continue;seen.add(file);
148
+ if(onRequest&&onRequest(row,{kill:killGroup,file})===false)continue;
149
+ const result=respond(row,index++);if(result!==undefined)reply(file,row,result);
150
+ }
151
+ }catch(error){stderr+=`\n[test] ${error.stack}`;}},50);
152
+ const code=await new Promise(resolve=>{const kill=setTimeout(killGroup,timeoutMs);child.on('exit',(value,signal)=>{clearTimeout(kill);resolve(value??signal);});});
153
+ clearInterval(timer);
154
+ if(killed){await new Promise(resolve=>setTimeout(resolve,300));return {code,stdout,stderr,killed,result:null};}
155
+ let result=null;try{result=JSON.parse(stdout.slice(stdout.indexOf('{'),stdout.lastIndexOf('}')+1)).result;}catch{}
156
+ return {code,stdout,stderr,killed,result};
157
+ }
158
+ const killOnRequest={respond:()=>undefined,onRequest:(row,{kill})=>{setTimeout(kill,300);return false;}};
159
+ function recoveryPlan(f,patch={}){
160
+ const plan=JSON.parse(fs.readFileSync(f.plan,'utf8'));
161
+ for(const field of ['taskKey','reason','expectedControl'])delete plan[field];
162
+ fs.writeFileSync(f.plan,JSON.stringify({...plan,...patch}));
163
+ }
164
+ const attempts=f=>developRequests(f).map(item=>item.row.payload.request.identity.attempt);
165
+ function assertSessionOnly(f){
166
+ assert.equal(witness(f).filter(row=>row.type==='provider_develop').length,0,'the session member never reaches the provider');
167
+ }
168
+ // The driver exits 1 when the member's state is unknown or needs reconciling
169
+ // (drive-core.mjs hostResponseFailed), else 0; either way it printed a result.
170
+ function settled(r){
171
+ assert.ok(r.result,`no result: ${r.stderr.slice(-2000)}`);
172
+ assert.equal(r.code,r.result.state==='unknown'||r.result.pendingAction==='reconcile'?1:0,r.stderr.slice(-2000));
173
+ }
174
+ const summary=r=>JSON.stringify(r.result??{code:r.code,stdout:r.stdout.slice(-1500),stderr:r.stderr.slice(-2500)}).slice(0,3000);
175
+
176
+ // Row 2: the host records unknown/call_timeout; the code root still equals the
177
+ // round start, so advance redoes the same round with a new effect id.
178
+ test('row 2: a timed-out session develop is redone in the same round by advance and completes with one review',async t=>{
179
+ const f=fixture(t);
180
+ fs.writeFileSync(f.shrink,'2500');
181
+ const first=await drive(f,{respond:()=>undefined});
182
+ settled(first);
183
+ assert.deepEqual([first.result.state,first.result.code,first.result.pendingAction,first.result.guidance.recoveryOperation],
184
+ ['blocked','develop_call_timeout','resume','advance'],summary(first));
185
+ assert.deepEqual([lastCheckpoint(f).state,lastCheckpoint(f).code],['unknown','call_timeout'],'the journal keeps the raw timeout');
186
+ assert.equal(fs.readFileSync(f.target,'utf8'),ORIGINAL);
187
+ fs.rmSync(f.shrink);resumePlan(f);
188
+ const second=await drive(f);
189
+ settled(second);
190
+ assert.deepEqual([second.result.state,second.result.code],['fixture_completed','qa_triggered'],summary(second));
191
+ assert.deepEqual(attempts(f),[1,1],'one new live request, same round');
192
+ assert.deepEqual(effectIds(f),['develop-1','develop-1-retry-1','review-1','complete-1']);
193
+ assert.equal(types(f).filter(type=>type==='develop-timeout-retry').length,1);
194
+ assert.deepEqual(reviews(f),[1],'the timeout spent no review round');
195
+ assert.equal(fs.readFileSync(f.target,'utf8'),PROPOSED);
196
+ assertSessionOnly(f);
197
+ });
198
+
199
+ // Rows 2/2b: at most 2 timeout redos per run; afterwards no exit re-sends the request.
200
+ test('row 2b: after two timeout redos the third timeout stays stopped and advance sends no new develop request',async t=>{
201
+ const f=fixture(t);
202
+ fs.writeFileSync(f.shrink,'2500');
203
+ const results=[];
204
+ for(let round=0;round<3;round++){
205
+ if(round)resumePlan(f);
206
+ const r=await drive(f,{respond:()=>undefined});settled(r);results.push(r.result);
207
+ }
208
+ assert.deepEqual(results.map(r=>r.code),['develop_call_timeout','develop_call_timeout','call_timeout']);
209
+ assert.deepEqual(effectIds(f),['develop-1','develop-1-retry-1','develop-1-retry-2']);
210
+ assert.equal(types(f).filter(type=>type==='develop-timeout-retry').length,2,'budget: two redos per run');
211
+ const before=journal(f);
212
+ const again=await drive(f);
213
+ settled(again);
214
+ assert.deepEqual([again.result.state,again.result.code,again.result.pendingAction,again.result.guidance.recoveryOperation],
215
+ ['unknown','call_timeout','reconcile',null],summary(again));
216
+ assert.deepEqual(journal(f),before,'nothing recorded');
217
+ assert.deepEqual(attempts(f),[1,1,1],'no fourth live request');
218
+ assert.deepEqual(reviews(f),[]);
219
+ assert.equal(fs.readFileSync(f.target,'utf8'),ORIGINAL);
220
+ assertSessionOnly(f);
221
+ });
222
+
223
+ // Row 3: an invalid proposal (an out-of-scope path) is a retryable block; advance asks
224
+ // the same round again and spends no review round.
225
+ test('row 3: an invalid session proposal blocks with developer_result_invalid and advance re-requests the same round',async t=>{
226
+ const f=fixture(t);
227
+ const first=await drive(f,{respond:request=>proposal(request,{edits:[{path:'other.mjs',beforeSha256:null,content:'x\n'}]})});
228
+ settled(first);
229
+ assert.deepEqual([first.result.state,first.result.code,first.result.pendingAction,first.result.guidance.recoveryOperation],
230
+ ['blocked','developer_result_invalid','resume','advance'],summary(first));
231
+ assert.equal(fs.readFileSync(f.target,'utf8'),ORIGINAL);
232
+ assert.ok(!fs.existsSync(path.join(f.codeProject,'other.mjs')),'nothing outside the scope was written');
233
+ assert.deepEqual(reviews(f),[]);
234
+ resumePlan(f);
235
+ const second=await drive(f);
236
+ settled(second);
237
+ assert.deepEqual([second.result.state,second.result.code],['fixture_completed','qa_triggered'],summary(second));
238
+ assert.deepEqual(attempts(f),[1,1]);
239
+ assert.deepEqual(effectIds(f),['develop-1','develop-1-retry-1','review-1','complete-1']);
240
+ assert.deepEqual(reviews(f),[1],'one review round in all');
241
+ assert.equal(fs.readFileSync(f.target,'utf8'),PROPOSED);
242
+ assertSessionOnly(f);
243
+ });
244
+
245
+ // Row 4: a stale proposal (beforeSha256 differs, disk is not the proposal) stays blocked.
246
+ test('row 4: a stale session proposal stays blocked on protected_edit_stale; advance sends nothing and keeps the file',async t=>{
247
+ const f=fixture(t);
248
+ const first=await drive(f,{respond:request=>proposal(request,{edits:[{path:'target.mjs',beforeSha256:sha('drifted\n'),content:PROPOSED}]})});
249
+ settled(first);
250
+ assert.deepEqual([first.result.state,first.result.code,first.result.pendingAction,first.result.guidance.recoveryOperation],
251
+ ['blocked','protected_edit_stale','none',null],summary(first));
252
+ const before=journal(f);
253
+ resumePlan(f);
254
+ const second=await drive(f);
255
+ settled(second);
256
+ assert.deepEqual([second.result.outcome,second.result.state,second.result.code],['reported','blocked','protected_edit_stale'],summary(second));
257
+ assert.deepEqual(journal(f),before,'nothing recorded');
258
+ assert.deepEqual(effectIds(f),['develop-1']);
259
+ assert.deepEqual(attempts(f),[1],'no new live request');
260
+ assert.deepEqual(reviews(f),[]);
261
+ assert.equal(fs.readFileSync(f.target,'utf8'),ORIGINAL,'the file is kept, never overwritten');
262
+ assertSessionOnly(f);
263
+ });
264
+
265
+ // Row 5: the develop succeeded and was applied; the check after it never answered.
266
+ // advance journals develop-recheck and re-runs only the checks, never the develop.
267
+ test('row 5: a check answer gap after a delivered session develop re-runs only the checks on advance',async t=>{
268
+ const f=fixture(t);
269
+ // The check's own sandbox limit must outlast the shortened runner call limit.
270
+ fs.writeFileSync(path.join(f.root,'protected.json'),JSON.stringify({model:'fixture',timeoutMs:60000,
271
+ checkCommands:[{id:'syntax',command:[process.execPath,'--check','target.mjs']}]}));
272
+ fs.writeFileSync(f.shrink,'6000');fs.writeFileSync(path.join(f.root,'hang-check'),'');
273
+ const first=await drive(f);
274
+ settled(first);
275
+ assert.deepEqual([first.result.state,first.result.code,first.result.pendingAction,first.result.guidance.recoveryOperation],
276
+ ['blocked','check_answer_missing','resume','advance'],summary(first));
277
+ assert.equal(witness(f).filter(row=>row.type==='check_hang').length,1);
278
+ assert.equal(fs.readFileSync(f.target,'utf8'),PROPOSED,'the delivery is on disk');
279
+ fs.rmSync(f.shrink);resumePlan(f);
280
+ const second=await drive(f);
281
+ settled(second);
282
+ assert.deepEqual([second.result.state,second.result.code],['fixture_completed','qa_triggered'],summary(second));
283
+ assert.deepEqual(attempts(f),[1],'the re-check never asks the session to develop again');
284
+ assert.equal(types(f).filter(type=>type==='develop-recheck').length,1);
285
+ assert.equal(types(f).filter(type=>type==='develop-worker').length,2,'one proposal apply in all');
286
+ assert.ok(witness(f).filter(row=>row.type==='check').length>=1,'the checks re-ran');
287
+ assert.deepEqual(reviews(f),[1]);
288
+ assert.equal(fs.readFileSync(f.target,'utf8'),PROPOSED);
289
+ assertSessionOnly(f);
290
+ });
291
+
292
+ // Row 6: the session legitimately cannot do the task.
293
+ test('row 6: a legitimate blocked outcome stops at blocked/failed with the reason and advance asks nothing more',async t=>{
294
+ const f=fixture(t),why='浏览器走查环境不可用';
295
+ const first=await drive(f,{respond:()=>({status:'succeeded',value:{outcome:'blocked',reason:why,...learning},edits:[]})});
296
+ settled(first);
297
+ assert.deepEqual([first.result.state,first.result.code,first.result.pendingAction,first.result.blockedReason],
298
+ ['blocked','failed','none',why],summary(first));
299
+ assert.equal(lastCheckpoint(f).calls.at(-1).blockedReason,why,'the reason is journaled');
300
+ const before=journal(f);
301
+ resumePlan(f);
302
+ const second=await drive(f);
303
+ settled(second);
304
+ assert.deepEqual([second.result.outcome,second.result.state,second.result.code,second.result.blockedReason],
305
+ ['reported','blocked','failed',why],summary(second));
306
+ assert.deepEqual(journal(f),before,'nothing recorded');
307
+ assert.deepEqual(attempts(f),[1]);
308
+ assert.deepEqual(reviews(f),[]);
309
+ assert.equal(fs.readFileSync(f.target,'utf8'),ORIGINAL);
310
+ assertSessionOnly(f);
311
+ });
312
+
313
+ async function statusTarget(f){
314
+ recoveryPlan(f);
315
+ const status=await drive(f,{operation:'status'});settled(status);
316
+ return status.result;
317
+ }
318
+ async function abandon(f,target,reason='Session host was killed before answering'){
319
+ recoveryPlan(f,{taskKey:key,reason,expectedControl:target.controlTarget});
320
+ const result=await drive(f,{operation:'abandon_effect'});recoveryPlan(f);return result;
321
+ }
322
+
323
+ // Rows 7/8: the driver and batch host are SIGKILLed while the live develop request is
324
+ // unanswered. Only an explicit v2 abandon_effect (status controlTarget as expectedControl)
325
+ // registers the interruption; the next advance sends a fresh request.
326
+ test('row 7: a killed pending session develop needs an explicit abandon_effect, then advance re-requests and completes',async t=>{
327
+ const f=fixture(t);
328
+ const killed=await drive(f,killOnRequest);
329
+ assert.ok(killed.killed);
330
+ assert.deepEqual(types(f),['init','effect-intent'],'the develop is left pending');
331
+ resumePlan(f);
332
+ const plain=await drive(f);
333
+ settled(plain);
334
+ assert.deepEqual([plain.result.state,plain.result.code,plain.result.pendingAction,plain.result.guidance.recoveryOperation],
335
+ ['unknown','reconciliation_required','abandon_effect','abandon_effect'],summary(plain));
336
+ assert.deepEqual(types(f),['init','effect-intent'],'advance without authorization records nothing');
337
+ assert.deepEqual(attempts(f),[1],'and sends no new request');
338
+ // v2 recovery: the v1 permission grant is refused by the driver, and so is a
339
+ // recovery operation without the status controlTarget.
340
+ const permissions=JSON.parse(fs.readFileSync(f.plan,'utf8')).permissions;
341
+ recoveryPlan(f,{taskKey:key,reason:'Session host was killed',permissions:[...permissions,'--allow-abandon-effect',key]});
342
+ const granted=await drive(f,{operation:'abandon_effect'});
343
+ assert.equal(granted.code,2);assert.match(granted.stderr,/禁止 --allow-\*/);
344
+ recoveryPlan(f,{taskKey:key,reason:'Session host was killed',permissions});
345
+ const blind=await drive(f,{operation:'abandon_effect'});
346
+ assert.equal(blind.code,2);assert.match(blind.stderr,/expectedControl/);
347
+ assert.deepEqual(types(f),['init','effect-intent']);
348
+ const target=await statusTarget(f);
349
+ assert.deepEqual([target.controlTarget.taskKey,target.controlTarget.member.effectId],[key,'develop-1']);
350
+ const registered=await abandon(f,target);
351
+ settled(registered);
352
+ assert.deepEqual([registered.result.outcome,registered.result.state,registered.result.code,registered.result.pendingAction],
353
+ ['recorded','blocked','develop_interrupted','resume'],summary(registered));
354
+ assert.deepEqual(types(f),['init','effect-intent','effect-interrupted']);
355
+ const resumed=await drive(f);
356
+ settled(resumed);
357
+ assert.deepEqual([resumed.result.state,resumed.result.code],['fixture_completed','qa_triggered'],summary(resumed));
358
+ assert.deepEqual(attempts(f),[1,1],'one fresh request after the registered interruption');
359
+ assert.deepEqual(effectIds(f),['develop-1','develop-1-resume-1','review-1','complete-1']);
360
+ assert.deepEqual(reviews(f),[1]);
361
+ assert.equal(fs.readFileSync(f.target,'utf8'),PROPOSED);
362
+ assertSessionOnly(f);
363
+ });
364
+
365
+ test('row 8: a code root changed since the round start refuses abandon_effect and stays blocked',async t=>{
366
+ const f=fixture(t),partial='export const value = 4;\n';
367
+ await drive(f,killOnRequest);
368
+ fs.writeFileSync(f.target,partial);
369
+ resumePlan(f);
370
+ const target=await statusTarget(f);
371
+ const refused=await abandon(f,target);
372
+ settled(refused);
373
+ assert.deepEqual([refused.result.outcome,refused.result.code],['rejected','effect_interrupt_root_changed'],summary(refused));
374
+ assert.match(refused.result.reason,/target\.mjs/);
375
+ assert.deepEqual(types(f),['init','effect-intent'],'the refusal records nothing');
376
+ const again=await drive(f);
377
+ settled(again);
378
+ assert.deepEqual([again.result.state,again.result.code,again.result.pendingAction],['unknown','reconciliation_required','abandon_effect'],summary(again));
379
+ assert.deepEqual(attempts(f),[1],'no new request');
380
+ assert.deepEqual(reviews(f),[]);
381
+ assert.equal(fs.readFileSync(f.target,'utf8'),partial,'the partial bytes are kept for a person to inspect');
382
+ assertSessionOnly(f);
383
+ });
384
+
385
+ // Three killed requests with two registered interruptions in between.
386
+ async function reachInterruptLimit(f){
387
+ await drive(f,killOnRequest);resumePlan(f);
388
+ for(let round=1;round<=2;round++){
389
+ const registered=await abandon(f,await statusTarget(f));
390
+ assert.equal(registered.result?.code,'develop_interrupted',summary(registered));
391
+ await drive(f,killOnRequest);
392
+ }
393
+ return statusTarget(f);
394
+ }
395
+ test('rows 7/8: the develop interruption budget is two in-run recoveries; the third only voids the run',async t=>{
396
+ const f=fixture(t);
397
+ const limited=await reachInterruptLimit(f);
398
+ assert.deepEqual(effectIds(f),['develop-1','develop-1-resume-1','develop-1-resume-2']);
399
+ assert.equal(types(f).filter(type=>type==='effect-interrupted').length,2);
400
+ assert.deepEqual([limited.state,limited.code,limited.pendingAction],['unknown','effect_interrupt_limit','abandon_effect'],JSON.stringify(limited));
401
+ const voided=await abandon(f,limited);
402
+ assert.deepEqual([voided.result.outcome,voided.result.state,voided.result.code],['abandoned','cancelled','effect_abandoned'],summary(voided));
403
+ assert.equal(types(f).at(-1),'effect-abandoned');
404
+ const after=await drive(f);
405
+ assert.deepEqual([after.result.outcome,after.result.state,after.result.code],['reported','cancelled','effect_abandoned'],summary(after));
406
+ assert.deepEqual(attempts(f),[1,1,1],'no fourth request');
407
+ assert.deepEqual(reviews(f),[]);
408
+ assert.equal(fs.readFileSync(f.target,'utf8'),ORIGINAL);
409
+ assertSessionOnly(f);
410
+ });
411
+
412
+ // Found by this suite (design 3.4 row 8: a batch member has no single-task supersede
413
+ // exit). At effect_interrupt_limit the batch guidance still says abandon_effect and
414
+ // then advance continues the batch, and the reason names --supersede-reviewed-evidence;
415
+ // in fact abandon_effect voids the member run (cancelled/effect_abandoned) and the
416
+ // batch cannot continue it. Left as todo: the guidance text is not changed here.
417
+ test('rows 7/8 guidance: at effect_interrupt_limit the batch guidance does not promise advance or a supersede exit',{todo:'guidance defect reported to the main session'},async t=>{
418
+ const f=fixture(t);
419
+ const limited=await reachInterruptLimit(f);
420
+ assert.equal(limited.code,'effect_interrupt_limit');
421
+ assert.doesNotMatch(limited.guidance.nextStep,/之后 advance 继续本批次/);
422
+ assert.doesNotMatch(limited.reason,/--supersede-reviewed-evidence/);
423
+ });