@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
@@ -5,7 +5,9 @@ import path from 'node:path';
5
5
  import {randomUUID} from 'node:crypto';
6
6
  import {setTimeout as delay} from 'node:timers/promises';
7
7
 
8
- const KINDS=new Set(['qa_logic','qa_browser','verification_precheck','prd_materials']);
8
+ // develop is opt-in: only the batch driver allows it (session members' protected proposals).
9
+ const DEFAULT_KINDS=['qa_logic','qa_browser','verification_precheck','prd_materials'];
10
+ const KINDS=new Set([...DEFAULT_KINDS,'develop']);
9
11
  const fail=code=>{throw Error(code);};
10
12
  const inside=(root,file)=>file===root||file.startsWith(root+path.sep);
11
13
  function resolvedFutureRoot(file){
@@ -25,8 +27,10 @@ function ordinaryAncestors(file){
25
27
  }catch(error){if(error.code!=='ENOENT')throw error;}
26
28
  }
27
29
  }
28
- export function createLiveEvidence(config,{base,protectedRoots=[],notify=()=>{},maxBytes=65536,allowedKinds=[...KINDS]}={}){
29
- if(config===undefined)return {has:()=>false,answer:async()=>null};
30
+ // minimumTimeouts: per-kind floor over timeoutMs, for a kind whose host deadline
31
+ // must fire first (batch develop: the host records call_timeout, not the driver).
32
+ export function createLiveEvidence(config,{base,protectedRoots=[],notify=()=>{},maxBytes=65536,allowedKinds=DEFAULT_KINDS,minimumTimeouts={}}={}){
33
+ if(config===undefined)return {has:()=>false,timeoutFor:()=>null,answer:async()=>null};
30
34
  if(!config||typeof config!=='object'||Array.isArray(config)
31
35
  ||Object.keys(config).some(key=>!['directory','kinds','timeoutMs'].includes(key))
32
36
  ||typeof config.directory!=='string'||!config.directory.trim()
@@ -35,7 +39,9 @@ export function createLiveEvidence(config,{base,protectedRoots=[],notify=()=>{},
35
39
  ||!config.kinds.every(kind=>KINDS.has(kind)&&allowedKinds.includes(kind)))fail('live_evidence_invalid_config');
36
40
  const timeout=config.timeoutMs??900000;
37
41
  if(!Number.isSafeInteger(timeout)||timeout<1||timeout>3600000
38
- ||!Number.isSafeInteger(maxBytes)||maxBytes<1||maxBytes>4194304)fail('live_evidence_invalid_limit');
42
+ ||!Number.isSafeInteger(maxBytes)||maxBytes<1||maxBytes>4194304
43
+ ||Object.entries(minimumTimeouts).some(([kind,ms])=>!KINDS.has(kind)||!Number.isSafeInteger(ms)||ms<1))fail('live_evidence_invalid_limit');
44
+ const timeoutFor=kind=>Math.max(timeout,minimumTimeouts[kind]??0);
39
45
  const directory=path.resolve(base??process.cwd(),config.directory);
40
46
  const validateDirectory=()=>{
41
47
  ordinaryAncestors(directory);
@@ -51,7 +57,7 @@ export function createLiveEvidence(config,{base,protectedRoots=[],notify=()=>{},
51
57
  };
52
58
  validateDirectory();
53
59
  const kinds=new Set(config.kinds),seen=new Set();let exchange=null;
54
- return {has:kind=>kinds.has(kind),async answer(row,{signal}={}){
60
+ return {has:kind=>kinds.has(kind),timeoutFor:kind=>kinds.has(kind)?timeoutFor(kind):null,async answer(row,{signal}={}){
55
61
  if(!kinds.has(row.kind))return null;
56
62
  if(signal?.aborted)fail('live_evidence_cancelled');
57
63
  if(row.type!=='host_request'||!row.sessionId||!row.callId
@@ -66,7 +72,7 @@ export function createLiveEvidence(config,{base,protectedRoots=[],notify=()=>{},
66
72
  // File names never contain caller-controlled identifiers.
67
73
  const stem=path.join(exchange,randomUUID()),requestFile=stem+'.request.json',resultFile=stem+'.result.json';
68
74
  fs.writeFileSync(requestFile,JSON.stringify(row)+'\n',{flag:'wx',mode:0o600});
69
- notify(requestFile);const end=Date.now()+timeout;
75
+ notify(requestFile);const end=Date.now()+timeoutFor(row.kind);
70
76
  while(true){
71
77
  if(signal?.aborted)fail('live_evidence_cancelled');
72
78
  let fd;
@@ -90,6 +96,22 @@ export function createLiveEvidence(config,{base,protectedRoots=[],notify=()=>{},
90
96
  }};
91
97
  }
92
98
 
99
+ // The host gives a QA case qa.timeoutMs (60000 when omitted) to answer, while
100
+ // the live responder waits its own timeout. A host window shorter than that wait
101
+ // times the case out while the walkthrough is still running (an iOS UI pass
102
+ // takes minutes) and records it BLOCKED. Drivers refuse that on create and warn
103
+ // on resume, where the recorded configuration is kept.
104
+ export const QA_DEFAULT_ANSWER_WINDOW_MS=60000;
105
+ export function qaAnswerWindowShortfall(qa,live,kinds){
106
+ if(!qa||typeof qa!=='object')return null;
107
+ const window=qa.timeoutMs??QA_DEFAULT_ANSWER_WINDOW_MS;
108
+ const short=[...new Set(kinds)].filter(kind=>['qa_logic','qa_browser'].includes(kind)&&live.has(kind)&&live.timeoutFor(kind)>window);
109
+ if(!short.length)return null;
110
+ return `workflow 的 qa.timeoutMs ${Object.hasOwn(qa,'timeoutMs')?`为 ${window}`:`未填(默认 ${window})`} 毫秒,`
111
+ +`短于 PLAN.liveEvidence 对 ${short.join('、')} 的等待 ${Math.max(...short.map(kind=>live.timeoutFor(kind)))} 毫秒:`
112
+ +'宿主会先超时,把还在走查的用例判 BLOCKED。把 qa.timeoutMs 调到实际走查耗时(最多 3600000),或把 liveEvidence.timeoutMs 调到不超过它';
113
+ }
114
+
93
115
  export function driverLiveEvidence(plan,options){
94
116
  return createLiveEvidence(plan.liveEvidence,{...options,notify:file=>process.stderr.write(
95
117
  `[drive] live_evidence_request: ${file}\n[drive] Read the live request, execute its task, then atomically write the matching .result.json host_result.\n`)});
@@ -26,18 +26,47 @@ const documentationMessages={
26
26
  const explain=(summary,nextStep,operation=null,prerequisites=[])=>Object.freeze({
27
27
  summary,nextStep,recoveryOperation:operation,prerequisites:Object.freeze(prerequisites),authorizationGranted:false,
28
28
  });
29
- export function operatorGuidance(result,{executionActive=false}={}){
29
+ // Rendering context is private and ephemeral; it never enters results or journals.
30
+ const guidanceContext=new WeakMap();
31
+ export function operatorGuidance(result,options={}){
32
+ const guidance=renderOperatorGuidance(result,options);
33
+ if(guidance)guidanceContext.set(guidance,{executionActive:options.executionActive===true,protocol:options.protocol??'legacy'});
34
+ return guidance;
35
+ }
36
+ export function projectOperatorGuidance(result,options={}){
37
+ if(!result?.guidance)return result;
38
+ const context=guidanceContext.get(result.guidance);
39
+ if(!context)return result;
40
+ const guidance=operatorGuidance(result,{...context,...options});
41
+ return guidance?{...result,guidance}:result;
42
+ }
43
+ const fixedTarget='先只读 status,展示并核对 controlTarget 与恢复动作,按当前对话的具体决定完整固定为 expectedControl;发送 version:2 和单行 reason;snapshot_changed 时停止,不自动刷新目标重试';
44
+ function renderOperatorGuidance(result,{executionActive=false,protocol='legacy',surface='single'}={}){
45
+ const v2=protocol==='v2',batch=surface==='batch';
46
+ const resume=batch?'从原批次入口发送 advance':'恢复原运行并发送 advance';
47
+ const permission=flag=>v2?fixedTarget:`显式 ${flag},并提供单行 reason`;
48
+ // V2 does have a supersede exit (create with a fixed supersedeTarget); it is a
49
+ // new run the user approves, never a flag this guidance hands out.
50
+ const supersede=v2?`${batch?'批次成员先取消本批次,再按单任务处理;':''}`
51
+ +'原运行确无合法恢复出口时,用原配置只读 inspect-history 取得 supersedeTarget 并保存,向用户展示旧状态与重开原因;'
52
+ +'用户批准后按 v2 create 重开流程以新 runId 重开同一任务(docs/cm-control-policy-v2.md「卡死任务重开」)。目标与旧运行不符返回 snapshot_changed 时停止,不自动刷新。'
53
+ :'修好后按 reason 用 --supersede-reviewed-evidence 新建运行重做。';
54
+ const supersedePrerequisites=v2?['原运行记录与现有文件保留,不改写','重开须经用户批准且绑定已展示的 supersedeTarget','不改变原运行的协议、身份或恢复预算']
55
+ :['原运行记录保留,不改写','本运行留在盘上的改动需还原,或加 --accept-superseded-code-drift'];
30
56
  if(result?.workflow!=='cm-ai'||!result.state||!result.identity)return null;
31
57
  const {state,code,pendingAction:action,outcome}=result;
32
58
  if(outcome==='rejected'||outcome==='denied')return explain('本次操作被拒绝,运行状态没有因此获得新的执行权限。',
33
59
  '先核对 code 与 reason,修正请求或取得所需授权;不要据此重复开发或审查。');
34
60
  if(executionActive)return explain('原运行仍有操作在执行。','等待原操作结果;可读取状态,不重复派发。');
61
+ if(code==='checkpoint_package_material_invalid')return explain('检查点审查包引用或原始材料校验失败,后续执行已停止。',
62
+ '保留原运行与全部记录,核对被引用记录的摘要和任务身份;交由维护者处理,不改写历史或重新派发。',null,
63
+ ['不得替换被引用的原记录','不改变原运行身份与恢复预算']);
35
64
  if(code==='spec_drift')return explain('已批准规格发生变化,后续执行被阻止。',
36
- action==='spec_rebind'?'先核对重新批准的规格;符合原任务内容未变的条件时,在原运行显式换绑规格。'
65
+ action==='spec_rebind'?(v2?'先核对重新批准的规格;符合原条件时,只读 status 并展示 launchControlTarget,将完整固定副本写入文件,以原策略和配置带 --expected-control FILE、--rebind-spec-material 与单行 --spec-rebind-reason 恢复;snapshot_changed 时停止,不自动刷新。':'先核对重新批准的规格;符合原任务内容未变的条件时,在原运行显式换绑规格。')
37
66
  :'先核对规格变更与原任务绑定;当前没有可直接继续的恢复动作。',null,['保留原运行身份与历史','不得绕过规格审批']);
38
67
  if(action==='bootstrap_review_recover')return explain('项目规则交付已记录,但规则审查包尚未恢复。',
39
68
  '核对当前规则文件、handoff 和原证据;恢复原运行后发送 bootstrap_review_recover。此路径不重新派发开发。',
40
- 'bootstrap_review_recover',['使用原配置与 runId,以 --mode resume 启动','显式 --allow-bootstrap-review-recovery,并提供单行 reason','由原宿主重新核对恢复条件']);
69
+ 'bootstrap_review_recover',['使用原配置与 runId,以 --mode resume 启动',permission('--allow-bootstrap-review-recovery'),'由原宿主重新核对恢复条件']);
41
70
  if(state==='unknown'){
42
71
  if(action==='abandon_effect'||action==='abandon_review'){
43
72
  const review=action==='abandon_review';
@@ -47,46 +76,46 @@ export function operatorGuidance(result,{executionActive=false}={}){
47
76
  ?'先确认旧宿主及相关子进程已退出、会话已停止修改文档(宿主按存档核对文档路径以外的文件与此刻的文档);再发送 abandon_effect 登记中断,运行转为 documentation_sync_interrupted,之后只重发文档同步、不重新开发,计入文档同步重发的 2 次上限。盘上改动保留并经检查与独立审查;登记中断不代表成功。'
48
77
  :'先确认旧宿主及相关子进程已退出、会话已停止写入(provider 开发由宿主按存档记下的进程身份核对);再发送 abandon_effect 登记中断,运行从这一步的可重试阻断继续:开发重发本轮、未登记的审查重新派发、未写提交意图的完成重新复查。盘上改动保留并经检查与独立审查;登记中断不代表成功。',
49
78
  action,['保留原配置、runId 和失败历史,以 --mode resume 启动',
50
- review?'显式 --allow-abandon-review,并提供单行 reason':'显式 --allow-abandon-effect,并提供单行 reason',
79
+ review?permission('--allow-abandon-review'):permission('--allow-abandon-effect'),
51
80
  '由原宿主核对可放弃条件;不得直接重跑或改写完成记录']);
52
81
  }
53
82
  // V5 (A33/A36): a no-verdict review end the host cannot prove safe to redispatch.
54
83
  if(['review_process_unverified','review_observation_invalid','review_boundary_unverified','review_abandon_budget_exhausted'].includes(result.reviewAbandonRefusal))
55
84
  return explain('独立审查没有结论,且宿主不能证明再派一次是安全的(reason 写明原因)。',
56
- '按 reason 手工核对旧审查进程与原审查证据;本运行不再重派审查,确认后用 --supersede-reviewed-evidence 新建运行重做。',
57
- null,['原运行记录保留,不改写','本运行留在盘上的改动需还原,或加 --accept-superseded-code-drift']);
85
+ `按 reason 手工核对旧审查进程与原审查证据;本运行不再重派审查。${supersede}`,
86
+ null,supersedePrerequisites);
58
87
  return explain('执行结果尚未确认,不能判断这一步成功或失败。',
59
88
  '只读核对原运行记录、进程及实际文件;当前没有已确认的直接重试入口,不新建运行绕过历史。');
60
89
  }
61
90
  if(state==='blocked'&&action==='abandon_review')return explain('本轮独立审查第二次没有结论,本轮还剩 1 次无结论重派,但宿主不能证明原审查进程已停止。',
62
91
  '先确认原审查进程(含子进程)已退出;再恢复原运行并发送 abandon_review 登记确认,之后 advance 重派。不算审查轮次。',
63
- 'abandon_review',['保留原配置、runId 与历史,以 --mode resume 启动','显式 --allow-abandon-review,并提供单行 reason','用满 2 次后为 review_redispatch_limit']);
92
+ 'abandon_review',['保留原配置、runId 与历史,以 --mode resume 启动',permission('--allow-abandon-review'),'用满 2 次后为 review_redispatch_limit']);
64
93
  // Q16/Q17: the final task's documentation_sync failed after develop answered.
65
94
  // R3: whatever the failure, the host cannot see whether the session still writes.
66
95
  if(action==='develop_redo'&&Object.hasOwn(documentationMessages,code))return explain(`${documentationMessages[code][0]}宿主无法证明会话已停止修改文档。`,
67
96
  `先确认会话已停止修改文档,${documentationMessages[code][1]}再恢复原运行并发送 develop_redo 写入确认,之后 advance 只重发文档同步。盘上的开发与文档改动保留,经检查和独立审查。`,
68
- 'develop_redo',['保留原配置、runId 与历史,以 --mode resume 启动','显式 --allow-develop-redo,并提供单行 reason','只重发文档同步,不重发开发;每运行最多 2 次']);
97
+ 'develop_redo',['保留原配置、runId 与历史,以 --mode resume 启动',permission('--allow-develop-redo'),'只重发文档同步,不重发开发;每运行最多 2 次']);
69
98
  if(state==='blocked'&&action==='resume'&&Object.hasOwn(documentationMessages,code)){
70
99
  const [summary,repair]=documentationMessages[code];
71
- return explain(summary,`${repair}然后恢复原运行并发送 advance,只重发文档同步,复用已记录的开发应答,不重新开发。`,
100
+ return explain(summary,`${repair}然后${resume},只重发文档同步,复用已记录的开发应答,不重新开发。`,
72
101
  'advance',['保留原配置、runId 与历史,以 --mode resume 启动','文档路径以外的文件须与文档同步开始时一致、文档须与确认停写时一致,否则拒绝','不占调用与 effect 名额;每运行最多 2 次,用满为 documentation_sync_retry_limit']);
73
102
  }
74
103
  if(code==='documentation_sync_retry_limit')return explain('文档同步重发已在本运行用满 2 次,不再重发。',
75
- '先查清会话为何一直不应答、答复 blocked 或越界写文件;修好后按 reason 用 --supersede-reviewed-evidence 新建运行重做。',
76
- null,['原运行记录保留,不改写','本运行留在盘上的改动需还原,或加 --accept-superseded-code-drift']);
104
+ `先查清会话为何一直不应答、答复 blocked 或越界写文件;${supersede}`,
105
+ null,supersedePrerequisites);
77
106
  if(action==='develop_redo')return explain('开发应答没有拿到(超时后代码已改动、会话断开或只回了 failed),会话可能仍在写文件。',
78
107
  '先确认会话已停止修改代码;再恢复原运行并发送 develop_redo 写入确认,之后 advance 重发本轮开发。盘上改动保留,经检查和独立审查。',
79
- 'develop_redo',['保留原配置、runId 与历史,以 --mode resume 启动','显式 --allow-develop-redo,并提供单行 reason','不占调用与 effect 名额;每运行最多 2 次']);
108
+ 'develop_redo',['保留原配置、runId 与历史,以 --mode resume 启动',permission('--allow-develop-redo'),'不占调用与 effect 名额;每运行最多 2 次']);
80
109
  if(state==='blocked'&&action==='resume'&&code==='develop_answer_missing')return explain('已确认会话停写,本轮开发等待重发。',
81
- '恢复原运行并发送 advance,用新 effect id 重发本轮开发;盘上改动保留,经检查和独立审查。',
110
+ `${resume},用新 effect id 重发本轮开发;盘上改动保留,经检查和独立审查。`,
82
111
  'advance',['保留原配置、runId 与历史,以 --mode resume 启动','确认原宿主已关闭,且本轮开发有原合同要求的授权']);
83
112
  if(state==='blocked'&&action==='resume'&&code==='develop_out_of_scope')return explain('开发交付已落盘,但改动超出了任务 scope(reason 列出路径),尚未进入审查。',
84
- '核对这些路径:会话越界写的就还原,你自己的改动就移出代码根,确需改动先走规格变更扩大 scope;然后恢复原运行并发送 advance,只重跑检查、验证预检与审查包,不重新开发。',
113
+ `核对这些路径:会话越界写的就还原,你自己的改动就移出代码根,确需改动先走规格变更扩大 scope;然后${resume},只重跑检查、验证预检与审查包,不重新开发。`,
85
114
  'advance',['保留原配置、runId 与历史,以 --mode resume 启动','不占开发调用与 effect 名额;每运行最多 2 次','不擅自删除用户改动']);
86
115
  if(state==='blocked'&&action==='resume'&&['check_answer_missing','check_answer_invalid'].includes(code))
87
116
  return explain(code==='check_answer_invalid'?'开发交付已落盘,但之后的检查或验证预检答复格式不合格。'
88
117
  :'开发交付已落盘,但之后的检查或验证预检没有拿到应答(超时、断开或迟到)。',
89
- '先确认上一次检查命令已停止;然后恢复原运行并发送 advance,只重跑检查、验证预检与审查包,不重新开发。',
118
+ `先确认上一次检查命令已停止;然后${resume},只重跑检查、验证预检与审查包,不重新开发。`,
90
119
  'advance',['保留原配置、runId 与历史,以 --mode resume 启动','不占开发调用与 effect 名额;每运行最多 2 次','不会自动完成任务或消耗新的独立审查轮次']);
91
120
  if(state==='blocked'&&action==='complete'&&code==='complete_commit_interrupted')return explain('宿主在写入任务完成提交意图后退出,tasks.md 可能已勾选也可能未勾选。',
92
121
  '恢复原运行并发送 complete;宿主只按存档里的提交计划核对并收尾,不重新复查、不重新开发。tasks.md 或证据被改动时会拒绝并保留现场。',
@@ -96,25 +125,26 @@ export function operatorGuidance(result,{executionActive=false}={}){
96
125
  'complete',['原 run 与已审交接、范围和包绑定不变','task-commit-intent 尚未写入;每运行最多 2 次']);
97
126
  if(state==='blocked'&&action==='resume'&&Object.hasOwn(deliveryMessages,code)){
98
127
  const [summary,repair]=deliveryMessages[code];
99
- return explain(summary,`${repair};然后恢复原运行并发送 advance,重做本轮交付和检查。`,
128
+ return explain(summary,`${repair};然后${resume},重做本轮交付和检查。`,
100
129
  'advance',['保留原配置、runId 与历史,以 --mode resume 启动','确认原宿主已关闭,且本轮开发有原合同要求的授权','不会自动完成任务或消耗新的独立审查轮次']);
101
130
  }
102
131
  if(state==='pending_review'&&action==='resume')return explain('本轮独立审查未取得可接受的结论。',
103
- '核对 code 与原审查证据;恢复原运行后,取得本轮绑定的独立审查授权,再发送 advance。',
132
+ `核对 code 与原审查证据;取得本轮绑定的独立审查授权,再${resume}。`,
104
133
  'advance',['原 run、配置和审查包绑定不变','原宿主仍须核对重派次数、进程和独立审查权限']);
105
134
  if(state==='blocked'&&action==='complete')return explain('完成前复核受阻,已有审查结论不能直接当作任务完成。',
106
135
  '核对 reason 中的检查或文件变化;满足原完成条件后,在原运行发送 complete,不重新开发。',
107
136
  'complete',['原 run 与已审交接、范围和包绑定不变','使用当前 packageDigest;由宿主重新核对完成条件']);
108
137
  if(code==='review_redispatch_limit')return explain('本轮独立审查已无结论重派 2 次,不再重派;这不计为审查轮次。',
109
- '先查清审查进程为何一直没有结论(登录、额度、网络或审查答复格式);修好后按 reason 用 --supersede-reviewed-evidence 新建运行重做。',
110
- null,['原运行记录保留,不改写','本运行留在盘上的改动需还原,或加 --accept-superseded-code-drift']);
138
+ `先查清审查进程为何一直没有结论(登录、额度、网络或审查答复格式);${supersede}`,
139
+ null,supersedePrerequisites);
111
140
  if(['check_answer_retry_limit','complete_recheck_limit','develop_redo_limit'].includes(code))
112
141
  return explain('这一步的自动恢复已在本运行用满 2 次,不再重做。',
113
- '先查清会话为何一直不应答或答复不合格(或宿主环境为何失败);修好后按 reason 用 --supersede-reviewed-evidence 新建运行重做。',
114
- null,['原运行记录保留,不改写','本运行留在盘上的改动需还原,或加 --accept-superseded-code-drift']);
142
+ `先查清会话为何一直不应答或答复不合格(或宿主环境为何失败);${supersede}`,
143
+ null,supersedePrerequisites);
115
144
  // Q06/Q07/Q11: a QA call that stopped as a whole.
116
145
  if(state==='fixture_completed'&&code==='qa_execution_unknown')return explain('本轮 QA 没有正常结束(整轮超时、宿主中途退出、答复格式不合格,或浏览器请求超时后设备可能仍被会话占用)。',
117
- '先确认上一轮的会话、浏览器或模拟器已停止、设备已空闲;再用原配置 --mode resume 加 --rerun-unknown-qa 重跑本轮。宿主拒绝时按拒绝码处理:含原始 FAIL、未解决的 [需确认] 或无法归因的旧记录的轮次不能替代,改用 --supersede-reviewed-evidence 新建运行。',
146
+ v2?(batch?'先确认上一轮会话与设备已空闲;批次 v2 没有启动型 QA 重跑出口,保留批次与 QA 证据并核对 reason,不新建运行绕过。':'先确认上一轮的会话、浏览器或模拟器已停止、设备已空闲;只读 status,展示并核对 launchControlTarget 后完整固定到文件。以原策略与配置 --mode resume、--expected-control FILE 和 --rerun-unknown-qa 启动;snapshot_changed 时停止,不自动刷新目标。宿主拒绝时保留原运行与 QA 证据,不改走旧入口。')
147
+ :'先确认上一轮的会话、浏览器或模拟器已停止、设备已空闲;再用原配置 --mode resume 加 --rerun-unknown-qa 重跑本轮。宿主拒绝时按拒绝码处理:含原始 FAIL、未解决的 [需确认] 或无法归因的旧记录的轮次不能替代,改用 --supersede-reviewed-evidence 新建运行。',
118
148
  null,['保留原运行与 QA 日志,只追加不改写','因宿主或应答原因替代的轮次不占三轮预算']);
119
149
  // Q15: the read-only documentation check answered blocked.
120
150
  if(state==='fixture_completed'&&code==='documentation_sync_blocked')return explain('文档核对判定文档尚未同步(reason 写明缺什么)。',
@@ -151,20 +181,23 @@ const BATCH_RECOVERY={
151
181
  };
152
182
  // A member result is not a batch control surface. Keep unsupported single-run
153
183
  // recovery operations out of batch instructions without changing pendingAction.
154
- export function batchOperatorGuidance(result,{taskKey=null}={}){
155
- const g=result?.guidance;if(!g)return null;
184
+ export function batchOperatorGuidance(result,{taskKey=null,protocol='legacy'}={}){
185
+ const context=guidanceContext.get(result?.guidance);
186
+ const g=context?operatorGuidance(result,{...context,protocol,surface:'batch'}):result?.guidance;
187
+ if(!g)return null;
156
188
  if(Object.hasOwn(BATCH_RECOVERY,g.recoveryOperation)){
157
- const [flag,confirm]=BATCH_RECOVERY[g.recoveryOperation],target=taskKey??'FEATURE/TASK';
189
+ const [flag,defaultConfirm]=BATCH_RECOVERY[g.recoveryOperation],target=taskKey??'FEATURE/TASK';
190
+ const confirm=g.recoveryOperation==='develop_redo'&&Object.hasOwn(documentationMessages,result.code)
191
+ ?'先确认会话已停止修改文档':defaultConfirm;
192
+ if(protocol==='v2')return explain(g.summary,
193
+ `${confirm};用原策略与配置从批次入口只读 status,展示并核对完整批次 controlTarget(batchId、taskKey、member、batchDigest),按当前对话的具体决定固定为 expectedControl;发送 version:2 的批次操作 ${g.recoveryOperation}(taskKey ${target}、单行 reason),之后 advance 继续本批次。`,
194
+ g.recoveryOperation,['保留原批次、成员身份与历史;不跨成员','snapshot_changed 时停止,不自动刷新目标重试;批次 cancel 后不能再恢复']);
158
195
  return explain(g.summary,`${confirm};关闭批次宿主,带 ${flag} ${target} 用同一批次配置重新启动,发送批次操作 ${g.recoveryOperation}(taskKey ${target}、单行 reason),之后 advance 继续本批次。`,
159
196
  g.recoveryOperation,['保持原批次配置;批次只用这一项权限打开该成员运行,不跨成员','授权用一次即失效;批次 cancel 后不能再恢复']);
160
197
  }
161
198
  if(result.code==='spec_drift')return explain(g.summary,
162
199
  '批次成员不能换绑规格;先按 reason 核对原批次可用出口,不直接重派。');
163
- if(g.recoveryOperation==='advance')return explain(g.summary,
164
- g.nextStep.replace('然后恢复原运行并发送 advance,重做本轮交付和检查。','然后从原批次入口发送 advance,重做本轮交付和检查。')
165
- .replace('然后恢复原运行并发送 advance,只重跑','然后从原批次入口发送 advance,只重跑')
166
- .replace('恢复原运行并发送 advance,用新 effect id','从原批次入口发送 advance,用新 effect id')
167
- .replace('恢复原运行后,取得本轮绑定的独立审查授权,再发送 advance。','沿原批次续接,取得本轮绑定的独立审查授权,再发送 advance。'),
200
+ if(g.recoveryOperation==='advance')return explain(g.summary,g.nextStep,
168
201
  'advance',['保持原批次配置、身份和 PLAN;成员运行由批次宿主选择恢复','先确认原批次宿主已关闭;开发与审查仍需原合同授权']);
169
202
  if(g.recoveryOperation==='complete')return explain(g.summary,
170
203
  '核对 reason 中的检查或文件变化;满足原完成条件后,从原批次入口发送 advance,由成员宿主继续完成复核。',
@@ -1,22 +1,40 @@
1
1
  // POSIX children must be spawned detached. Own only that child's process group.
2
2
  // A leader closing its pipes does not cancel escalation for its descendants.
3
- export function ownedProcessCleanup(child,{graceMs=250,killWaitMs=750,killProcess=process.kill.bind(process)}={}) {
3
+ // Every group signal goes through signalOwnedGroup (process-group-exit.mjs), which
4
+ // tells an exited, not yet reaped child (EPERM on macOS) from a live member.
5
+ import {signalOwnedGroup} from './process-group-exit.mjs';
6
+ export function ownedProcessCleanup(child,{graceMs=250,killWaitMs=750,killProcess=process.kill.bind(process),
7
+ exitBudgetMs=1000}={}) {
4
8
  let cleanup;
5
9
  const error=()=>Object.assign(new Error('process_cleanup_unknown'),{code:'process_cleanup_unknown'});
6
- const signal=value=>{
7
- try{killProcess(-child.pid,value);return true;}
8
- catch(e){if(e.code==='ESRCH')return false;throw error();}
9
- };
10
+ // true: a member received it; false: the group is gone. An EPERM resolution never
11
+ // gets more than what is left of one overall deadline (review 2026-10-27): every
12
+ // signal used to get the full exitBudgetMs again, so the last probe could run past
13
+ // the cleanup's own limit.
14
+ let overall=null;
15
+ const left=()=>Math.max(0,overall-Date.now());
16
+ const signal=async(value,cap=exitBudgetMs)=>(await signalOwnedGroup(child,value,
17
+ {killProcess,budgetMs:Math.min(exitBudgetMs,cap,left())}))==='sent';
10
18
  const pause=ms=>new Promise(resolve=>setTimeout(resolve,ms));
11
19
  return ()=>cleanup??=(async()=>{
12
20
  // Preserve the legacy Windows leader termination, without claiming tree cleanup.
13
21
  if(process.platform==='win32'){child.kill('SIGTERM');throw error();}
14
22
  // A failed spawn has no PID; in-memory test transports also have none.
15
23
  if(!Number.isInteger(child.pid)||child.pid<=0){child.kill('SIGTERM');return;}
16
- if(!signal('SIGTERM'))return;
24
+ overall=Date.now()+exitBudgetMs+graceMs+killWaitMs;
25
+ if(!await signal('SIGTERM'))return;
17
26
  await pause(graceMs);
18
- if(!signal('SIGKILL'))return;
19
- const until=Date.now()+killWaitMs;
20
- while(signal(0)){if(Date.now()>=until)throw error();await pause(25);}
27
+ if(!await signal('SIGKILL'))return;
28
+ // Review 2026-10-27 round 3: an EPERM resolution before SIGKILL must not buy the
29
+ // poll a fresh killWaitMs, so the poll also ends at the overall deadline.
30
+ const until=Math.min(Date.now()+killWaitMs,overall);
31
+ // SIGKILL delivery is asynchronous. Give the group one polling turn to
32
+ // exit before probing; this wait consumes the existing deadline. An actual
33
+ // permission error still fails immediately, without another probe.
34
+ do {
35
+ await pause(Math.min(25,Math.max(0,until-Date.now())));
36
+ if(!await signal(0,Math.max(0,until-Date.now())))return;
37
+ } while(Date.now()<until);
38
+ throw error();
21
39
  })();
22
40
  }
@@ -0,0 +1,46 @@
1
+ // Whether a process group we spawned (detached, so its id is our direct child's pid)
2
+ // has really stopped: the writer-stopped proof behind every owned cleanup.
3
+ //
4
+ // Measured on macOS 26 (2026-10-27): a group whose only member is our own child that
5
+ // already exited but is not reaped yet (a zombie) answers kill(-pgid, 0|SIGTERM) with
6
+ // EPERM; once Node has reaped it (its 'exit' event) the same signal answers ESRCH, or
7
+ // is delivered when a live member is left. A grandchild zombie is reaped by launchd
8
+ // or init promptly. So EPERM is only resolved through our own child: wait (without
9
+ // blocking the event loop) until its exit is observed, then signal again within the
10
+ // same small budget. ESRCH is a stop, a delivered signal means a live member, and an
11
+ // EPERM that persists (a member we may not signal) stays unknown. No process table
12
+ // is read and no external program runs.
13
+ const unknown=()=>Object.assign(new Error('process_cleanup_unknown'),{code:'process_cleanup_unknown'});
14
+ const exited=child=>Number.isInteger(child?.exitCode)||typeof child?.signalCode==='string';
15
+ const pause=ms=>new Promise(resolve=>setTimeout(resolve,ms));
16
+ // Our direct child's exit, observed (Node emits 'exit' after reaping it) before the
17
+ // deadline. A child object without exit tracking can never prove it.
18
+ function childExit(child,deadline){
19
+ if(exited(child))return Promise.resolve(true);
20
+ if(typeof child?.once!=='function')return Promise.resolve(false);
21
+ return new Promise(resolve=>{
22
+ const done=()=>{clearTimeout(timer);resolve(true);};
23
+ const timer=setTimeout(()=>{child.off?.('exit',done);resolve(exited(child));},Math.max(0,deadline-Date.now()));
24
+ child.once('exit',done);
25
+ });
26
+ }
27
+
28
+ // Signal the group of our detached child: 'sent' (a live member received it) or
29
+ // 'gone' (the group no longer exists); throws process_cleanup_unknown otherwise.
30
+ // budgetMs bounds the EPERM resolution (child exit wait plus re-probes) in all.
31
+ export async function signalOwnedGroup(child,signal,{killProcess=process.kill.bind(process),budgetMs=1000,probeEveryMs=50}={}){
32
+ const send=()=>{
33
+ try{killProcess(-child.pid,signal);return 'sent';}
34
+ catch(error){return error?.code==='ESRCH'?'gone':error?.code==='EPERM'?'denied':'error';}
35
+ };
36
+ const first=send();
37
+ if(first==='sent'||first==='gone')return first;
38
+ const deadline=Date.now()+budgetMs;
39
+ if(first==='error'||!await childExit(child,deadline))throw unknown();
40
+ for(;;){
41
+ const again=send();
42
+ if(again==='sent'||again==='gone')return again;
43
+ if(again==='error'||Date.now()>=deadline)throw unknown();
44
+ await pause(Math.min(probeEveryMs,Math.max(0,deadline-Date.now())));
45
+ }
46
+ }
@@ -190,10 +190,11 @@ export function inspectProviderReviewReconciliation(observationText,expectationT
190
190
  const review=cause?reviewResultForPaths(r.value,expected.pkg,causeReviewPaths(expected.pkg)):reviewResult(r.value,expected.pkg);
191
191
  return json({...inspect(observationText,expectationText,cause),observationStatus:'completed',code:null,review});
192
192
  }
193
- need(['error','turn.failed'].includes(terminal)&&r.status==='failed'&&r.code==='provider_failed',
193
+ // A Codex rate limit (worker-codex.mjs) is the only other trusted failed terminal; it keeps its class.
194
+ need(['error','turn.failed'].includes(terminal)&&r.status==='failed'&&['provider_failed','reviewer_rate_limited'].includes(r.code),
194
195
  'review_reconciliation_evidence_required');
195
196
  return json({version:1,kind:'cm-provider-review-failure',requestDigest:expected.request.requestDigest,
196
197
  observationDigest:digest(observation),identity:expected.request.identity,logicalContextId:expected.request.contextId,
197
198
  provider:expected.request.provider,requestedModel:expected.request.requestedModel,providerThreadId:thread,
198
- category:'provider',failure:'reviewer_provider_failed',completionEligible:false});
199
+ category:'provider',failure:REVIEWER_PROVIDER_FAILURES[r.code],completionEligible:false});
199
200
  }
@@ -28,3 +28,25 @@ export function preQaConfigurations(material){
28
28
  else delete withoutWorkflow.applicableAgentFiles;
29
29
  return [withoutQa,withoutWorkflow];
30
30
  }
31
+
32
+ // The configurations a v2 run with qa:"disabled" was created with, derived from
33
+ // the qa:"run" launch that turns QA on: the policy's qa value, the executor and
34
+ // at most the QA part of the workflow differ. Under qa:"disabled" the host kept a
35
+ // given workflow (its qa as given, or null) and the QA decision; without any
36
+ // workflow it kept the implicit decision (implicit-qa-decision.mjs), and runs
37
+ // older than that had no decision at all. Each still has to equal the saved digest.
38
+ export function preQaUpgradeConfigurations(material){
39
+ if(material?.execution?.controlPolicy?.qa!=='run'||!material.qaExecutor||!material.qaDecisionProvider)return [];
40
+ const base=structuredClone(json(material));base.execution.controlPolicy.qa='disabled';
41
+ const kept=structuredClone(base);delete kept.qaExecutor;
42
+ const nullQa=structuredClone(kept);
43
+ const wrapped=Object.hasOwn(nullQa.execution.workflow??{},'configuration');
44
+ const workflow=wrapped?nullQa.execution.workflow.configuration:nullQa.execution.workflow;
45
+ if(!workflow?.qa)return [];
46
+ workflow.qa=null;
47
+ const candidates=preQaConfigurations(base);
48
+ const decided=structuredClone(candidates[1]);
49
+ decided.qaDecisionProvider=material.qaDecisionProvider;decided.qaTimeoutMs=material.qaTimeoutMs;
50
+ const plain=structuredClone(decided);delete plain.applicableAgentFiles;
51
+ return [kept,nullQa,...candidates,decided,plain];
52
+ }
@@ -2,7 +2,8 @@
2
2
  import {digest,json,shape,need,hex,id,text} from './effect-contract.mjs';
3
3
  import {createHostQaExecutor} from './host-qa-executor.mjs';
4
4
  import {validateHostWorkflowConfiguration} from './host-workflow-capabilities.mjs';
5
- import {preQaConfigurations,readQaAttachment} from './qa-attachment.mjs';
5
+ import {preQaConfigurations,preQaUpgradeConfigurations,readQaAttachment} from './qa-attachment.mjs';
6
+ import {controlPolicyFromSnapshot,isControlQaUpgrade} from './control-policy.mjs';
6
7
 
7
8
  const workflow=material=>material.execution?.workflow?.configuration??material.execution?.workflow;
8
9
  const BUILT_IN='cm-host-qa-executor-v1';
@@ -113,7 +114,11 @@ export function verifyQaRevisionMaterial(snapshot,material,prior=null){
113
114
  need(digest(qaConfigurationSlice(candidate))===revisions.at(-1).qaDigest,'fingerprint_mismatch');
114
115
  }else{
115
116
  const attached=snapshot.records.some(row=>row.payload.type==='qa-attached');
116
- need((attached?preQaConfigurations(candidate):[candidate]).some(p=>digest(p)===snapshot.fingerprints.config),'fingerprint_mismatch');
117
+ // A v2 run that turned QA on (control-policy.mjs isControlQaUpgrade) was
118
+ // attached from its qa:"disabled" configuration; check against that one.
119
+ const upgraded=attached&&isControlQaUpgrade(controlPolicyFromSnapshot(snapshot),candidate?.execution?.controlPolicy??null);
120
+ need((attached?[...preQaConfigurations(candidate),...(upgraded?preQaUpgradeConfigurations(candidate):[])]:[candidate])
121
+ .some(p=>digest(p)===snapshot.fingerprints.config),'fingerprint_mismatch');
117
122
  }
118
123
  return revisions;
119
124
  }
@@ -0,0 +1,102 @@
1
+ // Requirement evidence from the verification precheck, carried into the host
2
+ // handoff so the independent reviewer sees what the developer reported for each
3
+ // written requirement. It is the developer's own record, never host-verified fact.
4
+ import {need,shape,json,validIdentity,arrayItems} from './effect-contract.mjs';
5
+
6
+ export const REQUIREMENT_EVIDENCE_PREFIX='cm-requirement-evidence-v1: ';
7
+ export const REQUIREMENT_ITEM_LIMIT=64;
8
+ export const REQUIREMENT_TEXT_LIMIT=2000;
9
+ // The whole serialized item list. The handoff itself is capped at 256 KiB and
10
+ // also carries checks and Learning evidence, so the requirement record keeps a
11
+ // bound well below it instead of failing the package at publication time.
12
+ export const REQUIREMENT_EVIDENCE_LIMIT=64*1024;
13
+
14
+ const freeze=value=>Object.freeze(value);
15
+ const boundedText=(value,code)=>need(typeof value==='string'&&value.trim().length>0
16
+ &&Buffer.byteLength(value,'utf8')<=REQUIREMENT_TEXT_LIMIT&&!/[\x00-\x08\x0b-\x1f]/.test(value),code);
17
+
18
+ // Validates the precheck answer items: [{requirement,satisfied,evidence}], each
19
+ // optionally tagged with the host run it states (run "red": a test failed before
20
+ // the implementation; run "baseline" with result "passed"|"failed": the run before
21
+ // development). A null tag means none; the tag never reaches the handoff text.
22
+ // result means something only on a baseline item. Elsewhere it is dropped, not an
23
+ // error: the first real run wrote result "failed" on its red item, which is just
24
+ // what a red run is, and that one field must not void the whole report.
25
+ const RUNS=new Set(['red','baseline']),RESULTS=new Set(['passed','failed']);
26
+ export function readRequirementItems(raw,code='verification_precheck_invalid'){
27
+ need(Array.isArray(raw)&&raw.length>0&&raw.length<=REQUIREMENT_ITEM_LIMIT,code);
28
+ const items=raw.map(item=>{
29
+ need(item!==null&&typeof item==='object'&&!Array.isArray(item),code);
30
+ try{shape(item,['requirement','satisfied','evidence',...['run','result'].filter(key=>Object.hasOwn(item,key))]);}catch{need(false,code);}
31
+ need(typeof item.satisfied==='boolean',code);
32
+ boundedText(item.requirement,code);boundedText(item.evidence,code);
33
+ const run=item.run??null,result=item.result??null;
34
+ need(run===null||RUNS.has(run),code);need(result===null||RESULTS.has(result),code);
35
+ return freeze({requirement:item.requirement,satisfied:item.satisfied,evidence:item.evidence,
36
+ ...(run===null?{}:{run}),...(result===null||run!=='baseline'?{}:{result})});
37
+ });
38
+ need(Buffer.byteLength(JSON.stringify(items),'utf8')<=REQUIREMENT_EVIDENCE_LIMIT,code);
39
+ return freeze(items);
40
+ }
41
+
42
+ // One handoff evidence entry, bound to the task identity and attempt it answers.
43
+ export function encodeRequirementEvidence({identity,items}){
44
+ validIdentity(identity);
45
+ const checked=readRequirementItems(items,'invalid_result');
46
+ need(checked.every(item=>item.satisfied===true),'invalid_result');
47
+ return REQUIREMENT_EVIDENCE_PREFIX+JSON.stringify({version:1,identity:{repositoryId:identity.repositoryId,
48
+ runId:identity.runId,taskId:identity.taskId,attempt:identity.attempt},
49
+ items:checked.map(item=>({requirement:item.requirement,evidence:item.evidence}))});
50
+ }
51
+
52
+ export function readRequirementEvidence(entry){
53
+ need(typeof entry==='string'&&entry.startsWith(REQUIREMENT_EVIDENCE_PREFIX),'invalid_input');
54
+ const body=entry.slice(REQUIREMENT_EVIDENCE_PREFIX.length);
55
+ need(Buffer.byteLength(body,'utf8')<=REQUIREMENT_EVIDENCE_LIMIT+4096,'invalid_input');
56
+ let parsed;
57
+ try{parsed=JSON.parse(body);}catch{need(false,'invalid_input');}
58
+ const value=json(parsed);
59
+ shape(value,['version','identity','items']);need(value.version===1,'invalid_input');
60
+ validIdentity(value.identity);
61
+ const items=arrayItems(value.items).map(item=>{shape(item,['requirement','evidence']);return {...item,satisfied:true};});
62
+ readRequirementItems(items,'invalid_input');
63
+ return value;
64
+ }
65
+
66
+ // The first rule a report breaks, naming only positions, fixed field names and
67
+ // rules, never the reported text, so the operator can act on an invalid report.
68
+ export function requirementReportProblem(raw){
69
+ if(!Array.isArray(raw))return 'not a list';
70
+ if(raw.length>REQUIREMENT_ITEM_LIMIT)return `more than ${REQUIREMENT_ITEM_LIMIT} items`;
71
+ const known=['requirement','satisfied','evidence','run','result'];
72
+ for(const [index,item] of raw.entries()){
73
+ const at=`item ${index+1}`;
74
+ if(item===null||typeof item!=='object'||Array.isArray(item))return `${at}: not an object`;
75
+ const extra=Object.keys(item).filter(key=>!known.includes(key));
76
+ if(extra.length)return `${at}: ${extra.length} unknown field(s)`;
77
+ for(const key of ['requirement','satisfied','evidence'])if(!Object.hasOwn(item,key))return `${at}: missing ${key}`;
78
+ if(typeof item.satisfied!=='boolean')return `${at}: satisfied is not a boolean`;
79
+ for(const key of ['requirement','evidence']){
80
+ const text=item[key];
81
+ if(typeof text!=='string'||!text.trim())return `${at}: ${key} is empty or not text`;
82
+ if(Buffer.byteLength(text,'utf8')>REQUIREMENT_TEXT_LIMIT)return `${at}: ${key} over ${REQUIREMENT_TEXT_LIMIT} bytes`;
83
+ if(/[\x00-\x08\x0b-\x1f]/.test(text))return `${at}: ${key} has a control character`;
84
+ }
85
+ const run=item.run??null,result=item.result??null;
86
+ if(run!==null&&!RUNS.has(run))return `${at}: run is not red, baseline or null`;
87
+ if(result!==null&&!RESULTS.has(result))return `${at}: result is not passed, failed or null`;
88
+ }
89
+ return Buffer.byteLength(JSON.stringify(raw),'utf8')>REQUIREMENT_EVIDENCE_LIMIT?'report over the byte limit':'unknown';
90
+ }
91
+
92
+ // The developer's own per-requirement report travels beside, never inside, the
93
+ // journaled developer value, whose contract stays unchanged. {value, items}:
94
+ // items is the validated list, null when absent or empty, or 'invalid' (with the
95
+ // first broken rule as problem).
96
+ export function splitRequirementReport(value){
97
+ if(!value||typeof value!=='object'||Array.isArray(value)||!Object.hasOwn(value,'requirements'))return {value,items:null};
98
+ const {requirements,...rest}=value;
99
+ if(requirements===null||Array.isArray(requirements)&&requirements.length===0)return {value:rest,items:null};
100
+ try{return {value:rest,items:readRequirementItems(requirements,'invalid_result')};}
101
+ catch{return {value:rest,items:'invalid',problem:requirementReportProblem(requirements)};}
102
+ }