@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
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ import {packageMaterialEligible,checkpointPackageBudget} from '../runtime/js/cm-ai/checkpoint-package-material.mjs';
2
3
  // cm-ai host 的单步驾驶员。PLAN 路径相对 PLAN 文件;命令仅在 codeProject 内执行。
3
4
  // 请求表来自 host-session.mjs operationNames(传输允许集)、host-conversation-execution.mjs
4
5
  // developer/check/verificationGate、host-workflow-capabilities.mjs QA/文档接线、
@@ -59,13 +60,16 @@ import {readCloseoutReport} from '../runtime/js/cm-ai/knowledge-closeout.mjs';
59
60
  import {readRunnerHistory,attemptBaseline,projectedRunnerStatus,RECHECK_CODES,DOCUMENTATION_SYNC_CODES} from '../runtime/js/cm-ai/durable-runner-state.mjs';
60
61
  import {developmentRetryable} from '../runtime/js/cm-ai/cm-ai-conversation-entry.mjs';
61
62
  import {stderr,stop,readJson,loadPlanFile,requireFields,preflightAnswers,driveHost,planCheckTimeout} from '../runtime/js/cm-ai/drive-core.mjs';
63
+ import {rateLimitRetryEligible} from '../runtime/js/cm-ai/drive-rate-limit.mjs';
64
+ import {cmAiSessionBoundary} from '../runtime/js/session-boundary.mjs';
65
+ import {printHandoff} from '../runtime/js/session-handoff.mjs';
62
66
  import {attemptAnswerName,inspectDriverBootstrap,readBootstrapRulesAnswers,createBootstrapRulesResponder} from '../runtime/js/cm-ai/drive-bootstrap.mjs';
63
- import {driverLiveEvidence} from '../runtime/js/cm-ai/live-evidence.mjs';
67
+ import {driverLiveEvidence,qaAnswerWindowShortfall} from '../runtime/js/cm-ai/live-evidence.mjs';
64
68
  import {readControlPolicyFile,isControlRecovery as controlRecoveryRequest} from '../runtime/js/cm-ai/control-policy.mjs';
65
69
 
66
70
  // PLAN.liveEvidence: fresh current-session evidence; see docs/live-evidence-drivers.md.
67
71
  const HOST=fileURLToPath(new URL('./cm-ai-host.mjs',import.meta.url));
68
- const OPERATIONS=new Set(['advance','start','resume','status','cancel','reconcile_review','abandon_review','abandon_effect','bootstrap_review_recover','develop_redo','decision','complete','qa','qa_result',
72
+ const OPERATIONS=new Set(['advance','start','resume','status','cancel','reconcile_review','abandon_review','abandon_effect','bootstrap_review_recover','completion_rework','development_rework','revise_scope','develop_redo','decision','complete','qa','qa_result',
69
73
  'fix_status','fix_advance','fix_action','fix_run','run_finalize','context_refresh','finish']);
70
74
  const ADVANCE=new Set(['advance','start','resume']);
71
75
  const PACKAGE_OPERATIONS=new Set(['decision','complete','qa','qa_result','context_refresh','finish','run_finalize']);
@@ -87,13 +91,13 @@ const FIX_REASONED=['abandon_step','abandon_review','rediagnose','rerun_blocked_
87
91
  const FILES={develop:'develop.json',qa_assess:'qa-assess.json',documentation_inspect:'documentation-inspect.json',
88
92
  documentation_sync:'documentation-sync.json',fix_learning:'learning.json',fix_diagnose:'diagnosis.json',
89
93
  fix_test_author:'test-edits.json',fix_repair:'repair-edits.json',fix_retrospective:'retrospective.json'};
90
- const PAIR_FLAGS=new Set(['--external-models-config','--review-config','--workflow-config',
94
+ const PAIR_FLAGS=new Set(['--integration-evidence','--accept-integration-digest','--expected-control','--revise-scope','--scope-revision-reason','--development-rework-reason','--external-models-config','--review-config','--workflow-config',
91
95
  '--input-limit',
92
96
  '--protected-conversation-config','--protected-config','--revise-qa-config','--qa-config-revision-reason','--qa-environment-failure',
93
97
  '--qa-fix-owner-config','--qa-fix-template-config','--qa-fix-review-config','--browser-qa',
94
- '--bootstrap-config','--allow-provider-development-attempt','--supersede-reason','--spec-rebind-reason',
98
+ '--bootstrap-config','--allow-provider-development-attempt','--supersede-reason','--supersede-target','--spec-rebind-reason',
95
99
  '--review-runtime','--feature','--qa-fix-final-review-recovery-invocation']);
96
- const FLAG_FLAGS=new Set(['--execution-optimizations','--external-models','--allow-development','--allow-qa','--allow-qa-fix-start','--auto-qa-fix',
100
+ const FLAG_FLAGS=new Set(['--development-rework','--execution-optimizations','--external-models','--allow-development','--allow-qa','--allow-qa-fix-start','--auto-qa-fix',
97
101
  '--verification-precheck',
98
102
  '--allow-bootstrap-write','--allow-abandon-review','--allow-abandon-effect','--allow-bootstrap-review-recovery','--allow-develop-redo','--rerun-unknown-qa','--rerun-blocked-qa','--failover',
99
103
  '--supersede-reviewed-evidence','--accept-superseded-code-drift','--rebind-spec-material',
@@ -111,6 +115,8 @@ export function readDriverControl(plan,base,operation,recovery=null){
111
115
  throw Error('permissions 必须是宿主参数数组');
112
116
  if(plan.permissions.some(flag=>flag.startsWith('--allow-')))
113
117
  throw Error('control v2 迁移错误:permissions 禁止 --allow-*;请改用 controlConfig 的明确模式和 expectedControl');
118
+ if(['revise_scope','development_rework'].includes(operation))
119
+ throw Error('启动型恢复不发送 wire 操作;用 permissions 的专用启动参数、单行原因和 --expected-control FILE 保存原 launchControlTarget,再发送 status 或 advance');
114
120
  const recovering=recovery??isControlRecovery(operation,plan);
115
121
  if(plan.mode==='create'&&Object.hasOwn(plan,'expectedControl'))
116
122
  throw Error('control v2 create 禁止 expectedControl');
@@ -274,7 +280,7 @@ export function journalRestBytes(records){
274
280
  return {restBytes:size(last.payload)-size(frame.reviewPackage),resultBytes:size(frame.cache.at(-1)?.result),
275
281
  receiptsBytes:size(frame.receipts),callsBytes:size(frame.calls)};
276
282
  }
277
- export function developPreview({definition,codeProject=definition.codeProject,journal=null,parallelSelection=null,exact=true}){
283
+ export function developPreview({definition,codeProject=definition.codeProject,journal=null,parallelSelection=null,exact=true,controlPolicy=null}){
278
284
  let baseline=journal?.baseline??null;
279
285
  try{
280
286
  if(baseline===null){
@@ -291,6 +297,9 @@ export function developPreview({definition,codeProject=definition.codeProject,jo
291
297
  }
292
298
  }
293
299
  return {definition,baseline,material:reviewMaterialSizes({root:codeProject,baseline}),parallelSelection,
300
+ packageMaterialEnabled:journal?.packageMaterialEnabled===true||journal===null&&packageMaterialEligible({
301
+ ...definition,root:codeProject,controlPolicy,...(parallelSelection?{parallelSelection}:{})}),
302
+ archivedPackageDigests:journal?.archivedPackageDigests??[],
294
303
  exact:exact&&!definition.codeProjects,...(journal?.frame??journalRestBytes([]))};
295
304
  }catch(error){
296
305
  if(error.code==='limit_exceeded')stop(2,`交付前的审查材料已超出审查包上限:${error.message}`);
@@ -433,7 +442,10 @@ export function preflightDevelopDeliveries({deliveries,answersRoot,codeProject,s
433
442
  const reserve=developCheckpointReserve({examinedPathsBytes:size(reviewPaths(pkg)),receiptsBytes:preview.receiptsBytes,
434
443
  callsBytes:preview.callsBytes+1024,writebackBytes:1024});
435
444
  const budget=JOURNAL_PAYLOAD_LIMIT-reserve;
436
- if(bytes>budget){
445
+ const enabled=preview.packageMaterialEnabled===true;
446
+ const capacity=enabled?checkpointPackageBudget({inlineBytes:bytes,packageBytes,reserve,enabled,
447
+ referenced:preview.archivedPackageDigests.includes(pkg.packageDigest)}):{fits:bytes<=budget};
448
+ if(!capacity.fits){
437
449
  const largest=pkg.changes.filter(change=>change.after).map(change=>change.after).sort((a,b)=>b.size-a.size).slice(0,3)
438
450
  .map(file=>`${file.path} ${kib(file.size)}`).join(',');
439
451
  stop(2,`${label}: 交付后的开发检查点约 ${kib(bytes)}(其中审查包 ${kib(packageBytes)},含 handoff),超过运行存档单条记录上限 ${JOURNAL_PAYLOAD_LIMIT} `
@@ -467,7 +479,10 @@ export function readRunJournal(definition){
467
479
  const snapshot=readExecutionSnapshot({specsRoot:definition.specsDir,identity:{
468
480
  repositoryId:definition.identity.repositoryId,runId:definition.identity.runId}});
469
481
  const first=snapshot.records[0];
470
- return {history:readRunnerHistory(snapshot.records,first.payload.config,3),config:first.payload.config,baseline:first.payload.baseline,
482
+ const history=readRunnerHistory(snapshot.records,first.payload.config,3);
483
+ return {history,config:first.payload.config,baseline:history.original,
484
+ packageMaterialEnabled:packageMaterialEligible(first.payload.config,first.payload.version),
485
+ archivedPackageDigests:snapshot.records.filter(row=>row.payload.type==='effect-checkpoint'&&row.payload.packageMaterial===true).map(row=>row.payload.checkpoint.reviewPackage.packageDigest),
471
486
  frame:journalRestBytes(snapshot.records)};
472
487
  }
473
488
  function reachableDevelopAttempts({plan,operation,journal,permissions,controlPolicy=null}){
@@ -533,7 +548,10 @@ export function validateCmAiAnswer(kind,value,root){
533
548
  if(value.status==='succeeded'){
534
549
  exact(value,['status','value','edits'],'develop.json');
535
550
  requireShape(object(value.value)&&['implemented','blocked'].includes(value.value.outcome),'develop.json.value.outcome');
536
- exact(value.value,['outcome','application','retrospective','reason'],'develop.json.value');
551
+ exact(value.value,['outcome','application','retrospective','reason','requirements'],'develop.json.value');
552
+ // The per-requirement report the prompt asks for; the host validates and splits it off.
553
+ requireShape(!Object.hasOwn(value.value,'requirements')||value.value.requirements===null
554
+ ||Array.isArray(value.value.requirements)&&value.value.requirements.length<=64,'develop.json.value.requirements');
537
555
  if(value.value.outcome==='implemented')requireShape(object(value.value.application)
538
556
  &&['applied','no_relevant_lesson'].includes(value.value.application.status)
539
557
  &&(value.value.application.status==='applied'?nonempty(value.value.application.note):value.value.application.note===null)
@@ -596,6 +614,7 @@ function load(){
596
614
  requireFields(plan,['config','mode','hostContext','permissions']);
597
615
  let control;
598
616
  try{control=readDriverControl(plan,base,operation);}catch(error){stop(2,error.message);}
617
+ if(['revise_scope','development_rework'].includes(operation)&&!control)stop(2,`${operation} 只用于原 v2 单任务运行`);
599
618
  if(control?.policy.bootstrap==='write'&&!plan.permissions.includes('--bootstrap-config'))
600
619
  stop(2,'invalid_arguments: bootstrap write 需要 --bootstrap-config');
601
620
  if(control?.policy.qaFix==='disabled'&&['fix_advance','fix_run','fix_action'].includes(operation))
@@ -613,6 +632,19 @@ function load(){
613
632
  else if(PAIR_FLAGS.has(flag)&&nonempty(plan.permissions[i+1]))permissions.push(flag,plan.permissions[++i]);
614
633
  else stop(2,`permissions 无效或缺少参数: ${flag}`);
615
634
  }
635
+ const integrationEvidence=permissions.includes('--integration-evidence');
636
+ const integrationDigest=permissions.includes('--accept-integration-digest');
637
+ if(integrationEvidence||integrationDigest){
638
+ if(!integrationEvidence||!integrationDigest||!control||plan.mode!=='resume'||operation!=='status'
639
+ ||!permissions.includes('--expected-control')
640
+ ||!/^[a-f0-9]{64}$/.test(permissions[permissions.indexOf('--accept-integration-digest')+1]))
641
+ stop(2,'受控集成接纳只允许新版 resume 的 status;需要成对 --integration-evidence、--accept-integration-digest 和原 --expected-control 文件');
642
+ if(['--revise-scope','--scope-revision-reason','--development-rework','--development-rework-reason',
643
+ '--revise-qa-config','--qa-config-revision-reason','--rerun-unknown-qa','--rerun-blocked-qa','--qa-environment-failure',
644
+ '--rebind-spec-material','--spec-rebind-reason','--supersede-reviewed-evidence','--supersede-reason',
645
+ '--supersede-target','--accept-superseded-code-drift','--hold-revision'].some(flag=>permissions.includes(flag)))
646
+ stop(2,'受控集成接纳不得并用其他恢复或 QA 重跑');
647
+ }
616
648
  const supersedeFlag=permissions.includes('--supersede-reviewed-evidence');
617
649
  const supersedeReason=permissions.includes('--supersede-reason');
618
650
  if(supersedeFlag!==supersedeReason)
@@ -620,12 +652,16 @@ function load(){
620
652
  if(permissions.includes('--accept-superseded-code-drift')&&!supersedeFlag)
621
653
  stop(2,'--accept-superseded-code-drift 需要 --supersede-reviewed-evidence 与 --supersede-reason');
622
654
  if(supersedeFlag&&plan.mode!=='create')stop(2,'supersede 只允许 mode create');
655
+ if(permissions.includes('--supersede-target')&&(!supersedeFlag||!control))
656
+ stop(2,'--supersede-target 只用于新版 controlConfig 的 create 重开,并须同时提供 --supersede-reviewed-evidence 与 --supersede-reason');
657
+ if(control&&supersedeFlag&&!permissions.includes('--supersede-target'))
658
+ stop(2,'新版重开需要 --supersede-target 文件:保存旧运行 inspect-history 返回的 supersedeTarget,不自动生成或替换');
623
659
  if(permissions.includes('--rebind-spec-material')!==permissions.includes('--spec-rebind-reason')
624
660
  ||permissions.includes('--rebind-spec-material')&&plan.mode!=='resume')
625
661
  stop(2,'--rebind-spec-material 只用于 mode resume,并须同时提供 --spec-rebind-reason 原因');
626
662
  // V2 recovery operations are gated by the original expectedControl in the
627
663
  // host, while the driver still validates the explicit operation and reason.
628
- if(control&&['abandon_review','abandon_effect','bootstrap_review_recover','develop_redo'].includes(operation)
664
+ if(control&&['abandon_review','abandon_effect','bootstrap_review_recover','completion_rework','development_rework','revise_scope','develop_redo'].includes(operation)
629
665
  &&(plan.mode!=='resume'||!nonempty(plan.reason)||Buffer.byteLength(plan.reason,'utf8')>500||/[\r\n\0]/.test(plan.reason)))
630
666
  stop(2,`${operation} 需要 resume、expectedControl 与单行 reason(最多 500 UTF-8 字节)`);
631
667
  const abandonError=control?null:abandonReviewPlanError(operation,plan,permissions);
@@ -636,6 +672,9 @@ function load(){
636
672
  if(developRedoError)stop(2,developRedoError);
637
673
  const bootstrapRecoveryError=control?null:bootstrapReviewRecoveryPlanError(operation,plan,permissions);
638
674
  if(bootstrapRecoveryError)stop(2,bootstrapRecoveryError);
675
+ for(const flag of ['--expected-control','--revise-scope']){
676
+ const at=permissions.indexOf(flag);if(at!==-1)permissions[at+1]=path.resolve(base,permissions[at+1]);
677
+ }
639
678
  const config=path.resolve(base,plan.config),answers=plan.answers?path.resolve(base,plan.answers):null;
640
679
  if(!fs.existsSync(config))stop(2,`运行定义不存在: ${config}`);
641
680
  let definition;
@@ -655,6 +694,7 @@ function load(){
655
694
  if(plan.mode==='resume'&&!fs.existsSync(path.join(store,'state.json')))stop(2,`恢复存档不存在: ${store}`);
656
695
  let journal=null;
657
696
  if(plan.mode==='resume')try{journal=readRunJournal(definition);}catch(error){journal={error};}
697
+ if(journal?.history?.scopeRevisions)definition={...definition,scope:journal.history.effectiveScope};
658
698
  // The run definition always says attempt 1. Package-bound operations must name
659
699
  // the attempt the run is on now, so send that; an unreadable journal keeps the
660
700
  // original identity and the host decides, exactly as before.
@@ -667,8 +707,8 @@ function load(){
667
707
  }
668
708
  const permissionFiles=[];
669
709
  for(let i=0;i<permissions.length;i++)if(PAIR_FLAGS.has(permissions[i])
670
- &&permissions[i]!=='--browser-qa'
671
- &&permissions[i]!=='--qa-config-revision-reason'&&permissions[i]!=='--qa-environment-failure'&&permissions[i]!=='--allow-provider-development-attempt'
710
+ &&permissions[i]!=='--browser-qa'&&permissions[i]!=='--accept-integration-digest'
711
+ &&permissions[i]!=='--scope-revision-reason'&&permissions[i]!=='--development-rework-reason'&&permissions[i]!=='--qa-config-revision-reason'&&permissions[i]!=='--qa-environment-failure'&&permissions[i]!=='--allow-provider-development-attempt'
672
712
  &&permissions[i]!=='--supersede-reason'&&permissions[i]!=='--spec-rebind-reason'&&permissions[i]!=='--input-limit'
673
713
  &&permissions[i]!=='--review-runtime'&&permissions[i]!=='--feature'&&permissions[i]!=='--qa-fix-final-review-recovery-invocation'){
674
714
  const file=path.resolve(base,permissions[i+1]);if(!fs.existsSync(file))stop(2,`${permissions[i]} 文件不存在: ${file}`);
@@ -686,9 +726,14 @@ function load(){
686
726
  else if(!providerMode)asks.push('develop');
687
727
  if(!protectedMode)asks.push('check');
688
728
  }
689
- if((plan.verificationPrecheck===true||permissions.includes('--verification-precheck'))&&(ADVANCE.has(operation)||operation==='complete'))asks.push('verification_precheck');
729
+ // The gate runs only where a delivery is checked: complete re-runs the checks
730
+ // of an already reviewed package and never asks it.
731
+ if((plan.verificationPrecheck===true||permissions.includes('--verification-precheck')||control?.policy.verification==='precheck')
732
+ &&ADVANCE.has(operation))asks.push('verification_precheck');
690
733
  if(operation==='complete'&&!protectedMode)asks.push('check');
691
- if((operation==='advance'||operation==='qa')&&workflow&&(control||workflow.qa)){asks.push('qa_assess');
734
+ // v2 没有 workflow 配置时宿主也会隐式补上 QA 判定(implicit-qa-decision.mjs)。
735
+ // 策略 qa:"disabled" 时宿主自己确认,不再问(host-workflow-capabilities.mjs)。
736
+ if((operation==='advance'||operation==='qa')&&(control||workflow?.qa)&&control?.policy.qa!=='disabled'){asks.push('qa_assess');
692
737
  }
693
738
  if((operation==='advance'||operation==='qa')&&workflow?.qa&&(!control||control.policy.qa==='run')){
694
739
  try{asks.push(...predictedQaAsks(definition,workflow.qa));}
@@ -719,6 +764,9 @@ function load(){
719
764
  catch(error){stop(2,error.message);}
720
765
  const missing=asks.filter(kind=>['qa_logic','qa_browser','verification_precheck'].includes(kind)&&!live.has(kind));
721
766
  if(missing.length)stop(2,`缺少真实执行 runner: ${missing.join(', ')};不能从静态答案文件应答`);
767
+ const shortWindow=qaAnswerWindowShortfall(workflow?.qa,live,asks);
768
+ if(shortWindow&&(plan.mode??'create')==='create')stop(2,shortWindow);
769
+ if(shortWindow)process.stderr.write(`[drive] 警告: ${shortWindow}\n`);
722
770
  const executionPolicy=readLaunchExecutionPolicy({definition,mode:plan.mode??'create',enabled:permissions.includes('--execution-optimizations')});
723
771
  if(asks.includes('check')){
724
772
  if(!Array.isArray(plan.checks)||plan.checks.length===0)stop(2,'步骤会反问 check,但 PLAN.checks 缺少真实命令列表');
@@ -766,7 +814,7 @@ function load(){
766
814
  scope:definition.scope,requirements:definition.requirements,
767
815
  baseline:plan.mode==='create'?'disk':baselineScope(journal.baseline,definition.scope),
768
816
  protectedMode,inputLimit:inputLimitFrom(permissions),checks:plannedCheckResults(protectedMode?null:plan.checks),
769
- preview:developPreview({definition,journal:plan.mode==='create'?null:journal,
817
+ preview:developPreview({definition,journal:plan.mode==='create'?null:journal,controlPolicy:control?.policy??null,
770
818
  exact:!permissions.includes('--bootstrap-config')})});
771
819
  const unique=[...new Set(asks.filter(kind=>FILES[kind]&&kind!=='develop'))];
772
820
  const answer=preflightAnswers(unique,kind=>{
@@ -859,7 +907,8 @@ export function buildCmAiDriveRequest(operation,plan,definition,identity=definit
859
907
  return {version:Object.hasOwn(plan,'controlConfig')?2:1,identity,
860
908
  ...(Object.hasOwn(plan,'controlConfig')&&isControlRecovery(operation,plan)?{expectedControl:plan.expectedControl}:{}),
861
909
  ...(operation==='reconcile_review'?{invocationId:plan.invocationId}:{}),
862
- ...(['abandon_review','abandon_effect','bootstrap_review_recover','develop_redo'].includes(operation)?{reason:plan.reason}:{}),
910
+ ...(operation==='revise_scope'?{scope:plan.scope}:{}),
911
+ ...(['abandon_review','abandon_effect','bootstrap_review_recover','completion_rework','development_rework','revise_scope','develop_redo'].includes(operation)?{reason:plan.reason}:{}),
863
912
  ...(PACKAGE_OPERATIONS.has(operation)?{packageDigest:plan.packageDigest}:{}),
864
913
  ...(TEST_RUN_OPERATIONS.has(operation)?{testRunId:plan.testRunId}:{}),
865
914
  ...(['fix_status','fix_advance','fix_action','fix_run'].includes(operation)?{
@@ -885,14 +934,21 @@ async function main(){
885
934
  stop(2,`${operation} 需要 packageDigest(64 位十六进制)`);
886
935
  if(TEST_RUN_OPERATIONS.has(operation)&&!(operation==='qa_result'?nonempty(plan.testRunId)
887
936
  :plan.testRunId===null||nonempty(plan.testRunId)))stop(2,`${operation} 需要 testRunId(可为 null)`);
888
- const request=buildCmAiDriveRequest(operation,plan,definition,loaded.identity);
937
+ // A timed rate-limit retry (drive-core.mjs) is a decision bound to the frozen
938
+ // stop: the host redispatches that review only if the run is still exactly there.
939
+ const expected=loaded.expectedReviewStop??null;
940
+ const request=expected?{...buildCmAiDriveRequest('decision',plan,definition,expected.identity),
941
+ expectedReviewStop:{invocationId:expected.invocationId}}:buildCmAiDriveRequest(operation,plan,definition,loaded.identity);
889
942
  if(operation.startsWith('fix_')&&(!nonempty(plan.packageDigest)||!nonempty(plan.testRunId)))
890
943
  stop(2,`${operation} 需要 packageDigest 和 testRunId`);
891
944
  // Rules init_verify commands really run once the host has accepted the launch
892
945
  // (host_ready) and before the operation is sent: a failure never becomes an
893
946
  // unknown develop effect, and the host's own launch validation came first.
947
+ if(plan.mode==='create')printHandoff(definition.specsDir);
894
948
  driveHost({host:HOST,args:[...buildCmAiDriveHostArgs(plan,permissions,config,loaded.control?.file),...(loaded.holdRevision?['--hold-revision']:[])],cwd:definition.codeProject,operation,request,
895
949
  answers:answer,paths:{answers:loaded.answers},answerFor,
950
+ sessionBoundary:result=>cmAiSessionBoundary(result,{specsDir:definition.specsDir,feature:definition.feature,identity:definition.identity}),
951
+ rateLimitRetry:rateLimitRetryEligible(operation,plan),
896
952
  ...(loaded.bootstrapRules?{beforeRequest:()=>loaded.bootstrapRules.prepare(plan.mode)}:{})});
897
953
  }
898
954
  if(process.argv[1]&&fs.realpathSync(process.argv[1])===fileURLToPath(import.meta.url))
@@ -191,13 +191,25 @@ test(`closeout real driver completes the original workflow with ${mode}`,t=>{
191
191
  f.write('documentation-inspect.json',{status:'completed',reason:'Controlled required-document fixture',
192
192
  ...(mode==='report'?{closeout}:{})});
193
193
  plan.permissions=['--workflow-config','workflow.json','--allow-qa',...permissions];
194
- let result;
194
+ // A previous session's handoff is printed when this new run is created, never on resume.
195
+ const handoff=path.join(f.specsDir,'.reviews','session-handoff.md');
196
+ if(mode==='report'){fs.mkdirSync(path.dirname(handoff),{recursive:true});fs.writeFileSync(handoff,'# 交接摘要\n- previous-session-marker\n');}
197
+ let result,last;
195
198
  for(let n=0;n<4;n++){
196
199
  const out=f.drive(f.plan({...plan,...(n?{mode:'resume',originalHostContext:'drive-host-a'}:{})}),'advance');
197
- assert.equal(out.status,0,out.stderr);result=JSON.parse(out.stdout).result;
200
+ assert.equal(out.status,0,out.stderr);result=JSON.parse(out.stdout).result;last=out;
201
+ if(mode==='report')assert.equal(out.stderr.includes('previous-session-marker'),n===0,out.stderr);
198
202
  if(result.state==='run_done')break;
203
+ assert.doesNotMatch(out.stderr,/会话边界:换新会话。/,'no verdict before run_done');
199
204
  }
200
205
  assert.equal(result.state,'run_done',JSON.stringify(result));
206
+ // The real driver prints the session-boundary verdict itself at run_done.
207
+ assert.match(last.stderr,/会话边界:换新会话。\n新会话里运行:无,1\.work 的任务已全部完成/);
208
+ // run_done writes this run's handoff over the previous one and names it in the verdict.
209
+ assert.match(last.stderr,/交接摘要:\S*\/\.reviews\/session-handoff\.md(/);
210
+ const written=fs.readFileSync(handoff,'utf8');
211
+ assert.match(written,/工作流:cm-ai/);assert.match(written,/1\.work T-001:已到 run_done/);
212
+ assert.match(written,/## 待做\n- 无/);assert.doesNotMatch(written,/previous-session-marker/);
201
213
  assert.equal(result.knowledgeCloseout.status,mode==='report'?'reported':mode==='off'?'disabled':'not_completed');
202
214
  if(mode==='report')assert.deepEqual(result.knowledgeCloseout.items,closeout.items);
203
215
  const state=JSON.parse(fs.readFileSync(f.store)),before=fs.readFileSync(path.join(f.codeProject,'target.mjs'));
@@ -598,3 +610,23 @@ test('driver forwards --feature for a later approved feature and --review-runtim
598
610
  const unbound=f.drive(f.plan({...bare,mode:'resume'}),'status');
599
611
  assert.notEqual(unbound.status,0);assert.match(unbound.stdout+unbound.stderr,/fingerprint_mismatch/);
600
612
  });
613
+ test('a QA answer window shorter than the live wait stops a new run and only warns on resume',t=>{
614
+ const f=fixture(t);prepared(f);
615
+ const file=qaFixture(f,[{kind:'browser',expected:'Browser evidence'}]);
616
+ const withLive=extra=>{const plan={...JSON.parse(fs.readFileSync(file,'utf8')),
617
+ liveEvidence:{directory:'../exchange',kinds:['qa_browser'],timeoutMs:900000},...extra};
618
+ const target=path.join(f.root,`plan-${Math.random().toString(36).slice(2)}.json`);fs.writeFileSync(target,JSON.stringify(plan));return target;};
619
+ const refused=f.drive(withLive(),'advance');
620
+ assert.equal(refused.status,2,refused.stderr);
621
+ assert.match(refused.stderr,/qa\.timeoutMs 未填(默认 60000) 毫秒,短于 PLAN\.liveEvidence 对 qa_browser 的等待 900000 毫秒/);
622
+ assert.equal(fs.existsSync(f.store),false);
623
+ // A window that covers the wait launches as before (nobody answers: the case times out at once).
624
+ const workflow=JSON.parse(fs.readFileSync(path.join(f.root,'workflow.json'),'utf8'));
625
+ fs.writeFileSync(path.join(f.root,'workflow.json'),JSON.stringify({...workflow,qa:{...workflow.qa,timeoutMs:1000}}));
626
+ const created=f.drive(withLive({liveEvidence:{directory:'../exchange',kinds:['qa_browser'],timeoutMs:1000}}),'advance');
627
+ assert.doesNotMatch(created.stderr,/qa\.timeoutMs/);assert(fs.existsSync(f.store),created.stderr);
628
+ // The recorded run resumes with the shorter window; the driver only warns.
629
+ const resumed=f.drive(withLive({mode:'resume'}),'advance');
630
+ assert.match(resumed.stderr,/\[drive\] 警告: workflow 的 qa\.timeoutMs 为 1000 毫秒,短于 PLAN\.liveEvidence 对 qa_browser 的等待 900000 毫秒/);
631
+ assert.doesNotMatch(resumed.stderr,/^\[drive\] 停止|invalid_arguments/m);
632
+ });
@@ -0,0 +1,84 @@
1
+ // Every create probes the legacy shared writer (.reviews/.execution/writer.sqlite).
2
+ // Two creates started together in different processes used to fail one of them
3
+ // with store_busy. A briefly held legacy lock is now waited out; one that stays
4
+ // held still refuses, and that refused create leaves nothing behind.
5
+ import test from 'node:test';
6
+ import assert from 'node:assert/strict';
7
+ import fs from 'node:fs';
8
+ import os from 'node:os';
9
+ import path from 'node:path';
10
+ import {spawn} from 'node:child_process';
11
+ import {openExecutionStore,LEGACY_PROBE_ATTEMPTS,LEGACY_PROBE_DELAY_MS} from '../runtime/js/cm-ai/execution-store.mjs';
12
+
13
+ const hash=char=>char.repeat(64);
14
+ const fingerprints={workflow:hash('a'),config:hash('b'),inputs:hash('c')};
15
+
16
+ function legacyRoot(t){
17
+ const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-legacy-probe-')));
18
+ // One cleanup, in order: every lock holder has exited before the root is removed.
19
+ const holders=[];
20
+ t.after(async()=>{
21
+ for(const child of holders)if(child.exitCode===null&&child.signalCode===null){
22
+ const gone=new Promise(resolve=>child.once('exit',resolve));child.kill();await gone;
23
+ }
24
+ fs.rmSync(root,{recursive:true,force:true});
25
+ });
26
+ // A real store built by the current protocol, then placed where the legacy shared writer lives.
27
+ const seed=openExecutionStore({specsRoot:root,identity:{repositoryId:'probe',runId:'seed-run-0001'},fingerprints,create:true});
28
+ seed.close();
29
+ const execution=path.join(root,'.reviews','.execution'),seedDir=path.join(execution,'seed-run-0001');
30
+ for(const name of ['writer.sqlite','writer-ready.json'])fs.copyFileSync(path.join(seedDir,name),path.join(execution,name));
31
+ return {root,legacy:path.join(execution,'writer.sqlite'),execution,holders};
32
+ }
33
+
34
+ // Another process holds the legacy writer's write lock for holdMs, as a concurrent
35
+ // create's probe does; resolves once the lock is actually held.
36
+ function holdLegacy(f,holdMs){
37
+ const legacy=f.legacy;
38
+ const child=spawn(process.execPath,['--no-warnings','-e',`
39
+ const {DatabaseSync}=require('node:sqlite');
40
+ const db=new DatabaseSync(process.argv[1],{timeout:0});
41
+ db.exec('BEGIN IMMEDIATE');process.stdout.write('held\\n');
42
+ setTimeout(()=>{db.exec('ROLLBACK');db.close();process.stdout.write('released\\n');},Number(process.argv[2]));
43
+ `,legacy,String(holdMs)],{stdio:['ignore','pipe','inherit']});
44
+ f.holders.push(child);
45
+ let output='';
46
+ const held=new Promise((resolve,reject)=>{
47
+ child.stdout.on('data',chunk=>{output+=chunk;if(output.includes('held'))resolve();});
48
+ child.on('exit',code=>{if(!output.includes('held'))reject(new Error(`holder exited ${code}`));});
49
+ });
50
+ const exited=new Promise(resolve=>child.on('exit',()=>resolve(output)));
51
+ return {held,exited};
52
+ }
53
+
54
+ test('a create waits out a legacy writer lock that another process holds briefly',async t=>{
55
+ const f=legacyRoot(t);
56
+ const holdMs=Math.floor(LEGACY_PROBE_ATTEMPTS*LEGACY_PROBE_DELAY_MS/4);
57
+ const holder=holdLegacy(f,holdMs);await holder.held;
58
+ const store=openExecutionStore({specsRoot:f.root,identity:{repositoryId:'probe',runId:'new-run-0001'},fingerprints,create:true});
59
+ store.close();
60
+ assert(fs.existsSync(path.join(f.execution,'new-run-0001','writer.sqlite')));
61
+ assert.match(await holder.exited,/released/);
62
+ });
63
+
64
+ test('a legacy writer lock held past the retry budget still refuses with store_busy and creates nothing',async t=>{
65
+ const f=legacyRoot(t);
66
+ const holder=holdLegacy(f,LEGACY_PROBE_ATTEMPTS*LEGACY_PROBE_DELAY_MS*4);await holder.held;
67
+ const started=Date.now();
68
+ assert.throws(()=>openExecutionStore({specsRoot:f.root,identity:{repositoryId:'probe',runId:'new-run-0002'},fingerprints,create:true}),
69
+ error=>error.code==='store_busy');
70
+ // It retried for roughly its budget instead of failing on the first contention.
71
+ assert(Date.now()-started>=(LEGACY_PROBE_ATTEMPTS-1)*LEGACY_PROBE_DELAY_MS*0.8);
72
+ assert.equal(fs.existsSync(path.join(f.execution,'new-run-0002')),false);
73
+ });
74
+
75
+ test('an unreadable legacy writer is not retried and refuses at once',t=>{
76
+ const f=legacyRoot(t);
77
+ fs.writeFileSync(f.legacy,'not a sqlite database');
78
+ const started=Date.now();
79
+ assert.throws(()=>openExecutionStore({specsRoot:f.root,identity:{repositoryId:'probe',runId:'new-run-0003'},fingerprints,create:true}),
80
+ error=>error.code==='store_busy');
81
+ // Not retried: well under half of the full retry budget, with room for slow disks.
82
+ assert(Date.now()-started<LEGACY_PROBE_ATTEMPTS*LEGACY_PROBE_DELAY_MS/2);
83
+ assert.equal(fs.existsSync(path.join(f.execution,'new-run-0003')),false);
84
+ });
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import {readLaunchExecutionPolicy} from '../runtime/js/cm-ai/execution-policy.mjs';
3
+ import {assertDeclaredScope} from '../runtime/js/task-scope.mjs';
3
4
  import {readLaunchExternalModels} from '../runtime/js/cm-ai/external-model-launch.mjs';
4
5
  import {loadExternalModels,externalPair} from '../runtime/js/cm-ai/external-models.mjs';
5
6
  // Current-conversation host. Legacy keeps explicit attempt choices; v2 uses
@@ -24,6 +25,18 @@ import {readControlPolicyFile,withControlPolicyHost,readControlTarget} from '../
24
25
  import {readExecutionSnapshot} from '../runtime/js/cm-ai/execution-snapshot.mjs';
25
26
  import {parseModelJson} from '../runtime/js/cm-ai/model-configuration-file.mjs';
26
27
  export {executionFor as createConversationExecution,reviewConfiguration as readConversationReviewConfiguration,reviewConfigurationValue as readConversationReviewConfigurationValue};
28
+ export function readScopeRevisionFile(file){
29
+ const before=fs.lstatSync(file);
30
+ need(before.isFile()&&!before.isSymbolicLink()&&before.nlink===1&&before.size<=65536,'invalid_input');
31
+ const descriptor=fs.openSync(file,fs.constants.O_RDONLY|fs.constants.O_NOFOLLOW);
32
+ try{
33
+ const bytes=fs.readFileSync(descriptor),after=fs.fstatSync(descriptor),current=fs.lstatSync(file);
34
+ need([after,current].every(info=>['dev','ino','size','mtimeMs','ctimeMs'].every(key=>info[key]===before[key]))
35
+ &&bytes.length===before.size,'snapshot_changed');
36
+ return parseModelJson(new TextDecoder('utf-8',{fatal:true}).decode(bytes));
37
+ }finally{fs.closeSync(descriptor);}
38
+ }
39
+
27
40
  export function readLaunchControlFile(file){
28
41
  const before=fs.lstatSync(file);
29
42
  need(before.isFile()&&!before.isSymbolicLink()&&before.nlink===1&&before.size<=65536,'invalid_input');
@@ -32,7 +45,9 @@ export function readLaunchControlFile(file){
32
45
  const bytes=fs.readFileSync(descriptor),after=fs.fstatSync(descriptor),current=fs.lstatSync(file);
33
46
  need([after,current].every(info=>['dev','ino','size','mtimeMs','ctimeMs'].every(key=>info[key]===before[key]))
34
47
  &&bytes.length===before.size,'snapshot_changed');
35
- return readControlTarget(parseModelJson(new TextDecoder('utf-8',{fatal:true}).decode(bytes)));
48
+ const target=parseModelJson(new TextDecoder('utf-8',{fatal:true}).decode(bytes));
49
+ need(target!==null&&typeof target==='object'&&!Array.isArray(target),'invalid_input');
50
+ return readControlTarget(target);
36
51
  }finally{fs.closeSync(descriptor);}
37
52
  }
38
53
  export function withHandoffDiagnostic(host,error){
@@ -179,10 +194,11 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
179
194
  if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--hold-revision: 本次启动在第 1 轮审查要求修改后停在 changes_requested(revision_answer_required),不发起第 2 轮开发意图;只缩小本次启动,不写入配置,下次不带它即继续修订。\n');
180
195
  if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--allow-develop-redo: resume 原 run 后发送 develop_redo,request.reason 必须是单行且不超过 500 UTF-8 字节。当前会话开发(非受保护)的应答没拿到,或 provider 开发结果不明且存档记有 worker 进程身份(宿主先核对进程组已退出),pendingAction=develop_redo 时可用;操作员先确认会话已停止修改代码,宿主写入 develop-answer-redo 记录,之后 advance 重发本轮开发。旗标只消费一次,不写入配置。\n');
181
196
  if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--allow-bootstrap-review-recovery: resume 原 run 后发送 bootstrap_review_recover;只在 bootstrap develop 已完成且审查包构建失败时核对现有文件、handoff 与原始证据,并追加恢复记录,不重新派发开发。\n');
182
- if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--supersede-reviewed-evidence --supersede-reason REASON:仅新建同任务运行;旧运行都已终止且 tasks.md 未勾选时,先在新 journal 记授权,再归档旧审查证据。若保留直接前驱运行留下的代码漂移,可额外使用 --accept-superseded-code-drift;漂移文件会作为新运行的已有代码并记录当前 SHA-256。\n');
197
+ if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--supersede-reviewed-evidence --supersede-reason REASON:仅新建同任务运行;旧运行都已终止且 tasks.md 未勾选时,先在新 journal 记授权,再归档旧审查证据。若保留直接前驱运行留下的代码漂移,可额外使用 --accept-superseded-code-drift;漂移文件会作为新运行的已有代码并记录当前 SHA-256。新版 --control-config 运行另须 --supersede-target FILE:文件保存旧运行 cm-ai-run.mjs inspect-history 返回的 supersedeTarget;旧运行在预览后变化则拒绝为 snapshot_changed,不自动替换目标。\n');
183
198
  if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--rebind-spec-material --spec-rebind-reason REASON:仅 resume。规格经 cm-prd --change 重新批准后,若本任务的描述、验证要求、验收标准、设计摘录与测试用例都未变,只换绑批准哈希并写 specification-rebound 记录,已有开发与审查结论保留;内容有变则拒绝并列出变化。status 的 spec_drift 会说明是否可换绑。\n');
184
199
  if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('当前会话手动驱动请用 scripts/cm-ai-drive.mjs(批次 cm-ai-batch-drive.mjs;修复 cm-fix-drive.mjs;规格 cm-prd-drive.mjs);详情见 skills/cm-ai/references/js-host.md。\n');
185
200
  if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('External-model mode freezes one model/effort pair per provider. Unknown or invalid external results require reconciliation; automatic retries and abandonment are disabled. See docs/external-models.md.\n');
201
+ if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--integration-evidence FILE --accept-integration-digest HEX:新版 resume 启动时接纳已审集成计划;须提供原 --expected-control FILE。本连接仅允许 status,不执行开发、审查或 QA。\n');
186
202
  if(argv.length===1&&['--help','-h'].includes(argv[0])){output.write(usage+'\nV2: replace --allow-development with --control-config FILE. Explicit resume QA reruns, QA configuration revisions and specification rebinds require --expected-control FILE containing the original status.launchControlTarget; ordinary host recovery uses status.controlTarget.\n');return 0;}
187
203
  let run,bridge;
188
204
  try{
@@ -216,8 +232,8 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
216
232
  const extra=new Map();
217
233
  for(let index=controlPolicy?9:8;index<argv.length;index++){
218
234
  const name=argv[index];refuse(!extra.has(name),'invalid_arguments',`参数重复:${name}`);
219
- refuse(['--expected-control','--execution-optimizations','--external-models','--external-models-config','--verification-precheck','--revise-qa-config','--qa-config-revision-reason','--qa-environment-failure','--supersede-reviewed-evidence','--supersede-reason','--accept-superseded-code-drift','--rebind-spec-material','--spec-rebind-reason','--original-host-context','--bootstrap-config','--allow-bootstrap-write','--protected-conversation-config','--protected-config','--allow-provider-development-attempt','--review-config','--allow-abandon-review','--allow-abandon-effect','--allow-bootstrap-review-recovery','--allow-develop-redo','--hold-revision','--workflow-config','--allow-qa','--browser-qa','--rerun-unknown-qa','--rerun-blocked-qa','--runtime','--review-runtime','--feature','--input-limit','--failover','--qa-fix-owner-config','--qa-fix-template-config','--qa-fix-review-config','--qa-fix-final-review-recovery-invocation','--allow-qa-fix-start','--auto-qa-fix',...fixLocalPermissions.keys()].includes(name),'invalid_arguments',`未知参数:${name}`);
220
- if(['--execution-optimizations','--external-models','--verification-precheck','--supersede-reviewed-evidence','--accept-superseded-code-drift','--rebind-spec-material','--allow-bootstrap-write','--allow-qa','--allow-abandon-review','--allow-abandon-effect','--allow-bootstrap-review-recovery','--allow-develop-redo','--hold-revision','--rerun-unknown-qa','--rerun-blocked-qa','--failover','--allow-qa-fix-start','--auto-qa-fix',...fixLocalPermissions.keys()].includes(name))extra.set(name,true);
235
+ refuse(['--integration-evidence','--accept-integration-digest','--revise-scope','--scope-revision-reason','--development-rework','--development-rework-reason','--expected-control','--execution-optimizations','--external-models','--external-models-config','--verification-precheck','--revise-qa-config','--qa-config-revision-reason','--qa-environment-failure','--supersede-reviewed-evidence','--supersede-reason','--supersede-target','--accept-superseded-code-drift','--rebind-spec-material','--spec-rebind-reason','--original-host-context','--bootstrap-config','--allow-bootstrap-write','--protected-conversation-config','--protected-config','--allow-provider-development-attempt','--review-config','--allow-abandon-review','--allow-abandon-effect','--allow-bootstrap-review-recovery','--allow-develop-redo','--hold-revision','--workflow-config','--allow-qa','--browser-qa','--rerun-unknown-qa','--rerun-blocked-qa','--runtime','--review-runtime','--feature','--input-limit','--failover','--qa-fix-owner-config','--qa-fix-template-config','--qa-fix-review-config','--qa-fix-final-review-recovery-invocation','--allow-qa-fix-start','--auto-qa-fix',...fixLocalPermissions.keys()].includes(name),'invalid_arguments',`未知参数:${name}`);
236
+ if(['--development-rework','--execution-optimizations','--external-models','--verification-precheck','--supersede-reviewed-evidence','--accept-superseded-code-drift','--rebind-spec-material','--allow-bootstrap-write','--allow-qa','--allow-abandon-review','--allow-abandon-effect','--allow-bootstrap-review-recovery','--allow-develop-redo','--hold-revision','--rerun-unknown-qa','--rerun-blocked-qa','--failover','--allow-qa-fix-start','--auto-qa-fix',...fixLocalPermissions.keys()].includes(name))extra.set(name,true);
221
237
  else{refuse(typeof argv[index+1]==='string'&&!argv[index+1].startsWith('--'),'invalid_arguments',`${name} 需要一个值`);extra.set(name,argv[++index]);}
222
238
  }
223
239
  if(controlPolicy){
@@ -229,21 +245,42 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
229
245
  refuse(controlPolicy.qaFix!=='disabled'||!['--qa-fix-owner-config','--qa-fix-template-config'].some(flag=>extra.has(flag)),
230
246
  'invalid_arguments','加载 QA 修复配置必须选择 manual 或 auto 模式。');
231
247
  refuse(!extra.has('--auto-qa-fix')||controlPolicy.qaFix==='auto','invalid_input','自动 QA 修复需要 qaFix:auto。');
248
+ // V2 supersede binds the predecessor state the operator previewed; it never
249
+ // refreshes the target or archives a run whose state moved after approval.
232
250
  refuse(!['--supersede-reviewed-evidence','--supersede-reason','--accept-superseded-code-drift']
233
- .some(flag=>extra.has(flag)),'supersede_unavailable',
234
- '新版启动入口暂不作废旧运行;保留现场,不自动更新目标后换运行。');
235
- }
251
+ .some(flag=>extra.has(flag))||argv[4]==='create'&&extra.has('--supersede-target'),'supersede_unavailable',
252
+ '新版重开需要 --mode create 与 --supersede-target FILE(保存旧运行 inspect-history 返回的 supersedeTarget);目标变化时先核对,不自动替换。');
253
+ refuse(!extra.has('--supersede-target')||extra.has('--supersede-reviewed-evidence'),'invalid_input',
254
+ '--supersede-target 只与 --supersede-reviewed-evidence、--supersede-reason 一起用于新版 create 重开。');
255
+ }else refuse(!extra.has('--supersede-target'),'invalid_arguments','--supersede-target 只用于新版 --control-config 的 create 重开。');
236
256
  const qaEnabled=controlPolicy?controlPolicy.qa==='run':extra.has('--allow-qa');
237
257
  const fixEnabled=controlPolicy?controlPolicy.qaFix!=='disabled':extra.has('--allow-qa-fix-start');
238
258
  const autoFix=controlPolicy?controlPolicy.qaFix==='auto':extra.has('--auto-qa-fix');
239
259
  const recoveryEnabled=flag=>controlPolicy?argv[4]==='resume':extra.has(flag);
240
- const launchRecovery=['--revise-qa-config','--qa-config-revision-reason','--rerun-unknown-qa','--rerun-blocked-qa',
241
- '--rebind-spec-material','--spec-rebind-reason'].some(flag=>extra.has(flag));
260
+ const launchRecovery=['--integration-evidence','--accept-integration-digest','--revise-qa-config','--qa-config-revision-reason','--rerun-unknown-qa','--rerun-blocked-qa',
261
+ '--rebind-spec-material','--spec-rebind-reason','--revise-scope','--scope-revision-reason','--development-rework','--development-rework-reason'].some(flag=>extra.has(flag));
242
262
  refuse(!extra.has('--expected-control')||(controlPolicy&&launchRecovery&&argv[4]==='resume'),'invalid_input',
243
- '--expected-control 仅用于新版 --mode resume 的显式 QA 恢复、QA 配置修订或规格重绑。');
263
+ '--expected-control 仅用于新版 --mode resume 的显式启动恢复。');
244
264
  if(controlPolicy&&launchRecovery)refuse(argv[4]==='resume'&&extra.has('--expected-control'),'invalid_input',
245
265
  '启动恢复需要 --mode resume 与 --expected-control FILE,文件须保存原 status 的 launchControlTarget;目标变化时先核对,不能自动替换。');
246
266
  const expectedControl=extra.has('--expected-control')?readLaunchControlFile(extra.get('--expected-control')):null;
267
+ const scopeRequested=extra.has('--revise-scope')||extra.has('--scope-revision-reason');
268
+ const reworkRequested=extra.has('--development-rework')||extra.has('--development-rework-reason');
269
+ refuse(!scopeRequested&&!reworkRequested||controlPolicy&&argv[4]==='resume'
270
+ &&(!scopeRequested||extra.has('--revise-scope')&&extra.has('--scope-revision-reason'))
271
+ &&(!reworkRequested||extra.has('--development-rework')&&extra.has('--development-rework-reason')),'invalid_input');
272
+ const scopeRevision=scopeRequested?{scope:readScopeRevisionFile(extra.get('--revise-scope')),reason:extra.get('--scope-revision-reason')}:null;
273
+ const supersedeTarget=extra.has('--supersede-target')?readLaunchControlFile(extra.get('--supersede-target')):null;
274
+ const integrationRequested=extra.has('--integration-evidence')||extra.has('--accept-integration-digest');
275
+ refuse(!integrationRequested||controlPolicy&&argv[4]==='resume'&&extra.has('--integration-evidence')
276
+ &&extra.has('--accept-integration-digest')&&/^[a-f0-9]{64}$/.test(extra.get('--accept-integration-digest'))
277
+ &&!['--revise-scope','--scope-revision-reason','--development-rework','--development-rework-reason',
278
+ '--revise-qa-config','--qa-config-revision-reason','--rerun-unknown-qa','--rerun-blocked-qa','--qa-environment-failure',
279
+ '--rebind-spec-material','--spec-rebind-reason','--supersede-reviewed-evidence','--supersede-reason',
280
+ '--supersede-target','--accept-superseded-code-drift','--hold-revision'].some(flag=>extra.has(flag)),
281
+ 'invalid_input','受控集成接纳需要新版 resume、成对证据与批准摘要及原 launchControlTarget;不得并用其他恢复。');
282
+ const reviewedIntegration=integrationRequested?{evidenceFile:path.resolve(extra.get('--integration-evidence')),
283
+ expectedDigest:extra.get('--accept-integration-digest')}:null;
247
284
  let inputLimit;
248
285
  try{inputLimit=parseHostInputLimit(extra.get('--input-limit'));}
249
286
  catch(error){refuse(error.code!=='invalid_arguments','invalid_arguments','--input-limit 须为 65536–4194304 的整数字节数');throw error;}
@@ -303,7 +340,7 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
303
340
  definition={...definition,featureSelection:{version:1,feature:definition.feature}};
304
341
  }
305
342
  // Before any frozen model/policy configuration, execution or journal write.
306
- if(argv[4]==='create'&&bootstrap===null)assertCreatableScope(definition.scope);
343
+ if(argv[4]==='create'&&bootstrap===null){assertCreatableScope(definition.scope);assertDeclaredScope(definition);}
307
344
  const boundRuntime=extra.get('--runtime')??'codex';
308
345
  const routes=extra.has('--protected-config')?resolveProtectedRuntimes(loadConfig({projectRoot:definition.codeProject}),boundRuntime):{reviewerRuntime:boundRuntime};
309
346
  const executionPolicy=readLaunchExecutionPolicy({definition,mode:argv[4],enabled:extra.has('--execution-optimizations')});
@@ -352,10 +389,10 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
352
389
  ?await protectedExecutionFor(definition,argv[6],extra,review,argv[4],workflow,bridge,bootstrap,externalModels,executionPolicy,controlPolicy)
353
390
  :executionFor(definition,argv[6],bridge,review,null,workflow,qaEnabled,runtime,
354
391
  {...(controlPolicy?{controlPolicy}:{}),...(extra.has('--review-runtime')?{reviewRuntime:extra.get('--review-runtime')}:{}),...(executionPolicy?{executionPolicy}:{}),...(externalModels?{externalModels}:{}),...(extra.has('--verification-precheck')?{verificationPrecheck:true}:{}),...(extra.has('--original-host-context')?{originalHostContextId:extra.get('--original-host-context')}:{}),...(protection?{protection}:{}),...(bootstrap?{bootstrap:{...bootstrap,allowWrite:(controlPolicy?controlPolicy.bootstrap==='write':extra.has('--allow-bootstrap-write'))}}:{})});
355
- run=await openControlRun(definition,argv[4],execution,{qaConfigRevision,rerunUnknownQa:extra.has('--rerun-unknown-qa'),rerunBlockedQa:extra.has('--rerun-blocked-qa'),qaEnvironmentFailure:extra.get('--qa-environment-failure')??null,supersedeReason:extra.get('--supersede-reason')??null,acceptSupersededCodeDrift:extra.has('--accept-superseded-code-drift'),allowAbandonReview:recoveryEnabled('--allow-abandon-review'),allowAbandonEffect:recoveryEnabled('--allow-abandon-effect'),allowBootstrapReviewRecovery:recoveryEnabled('--allow-bootstrap-review-recovery'),allowDevelopRedo:recoveryEnabled('--allow-develop-redo'),...(extra.has('--hold-revision')?{holdRevision:true}:{}),specRebindReason:extra.get('--spec-rebind-reason')??null,expectedControl});
392
+ run=await openControlRun(definition,argv[4],execution,{reviewedIntegration,qaConfigRevision,rerunUnknownQa:extra.has('--rerun-unknown-qa'),rerunBlockedQa:extra.has('--rerun-blocked-qa'),qaEnvironmentFailure:extra.get('--qa-environment-failure')??null,supersedeReason:extra.get('--supersede-reason')??null,acceptSupersededCodeDrift:extra.has('--accept-superseded-code-drift'),allowAbandonReview:recoveryEnabled('--allow-abandon-review'),allowAbandonEffect:recoveryEnabled('--allow-abandon-effect'),allowBootstrapReviewRecovery:recoveryEnabled('--allow-bootstrap-review-recovery'),allowDevelopRedo:recoveryEnabled('--allow-develop-redo'),...(extra.has('--hold-revision')?{holdRevision:true}:{}),scopeRevision,developmentReworkReason:extra.get('--development-rework-reason')??null,specRebindReason:extra.get('--spec-rebind-reason')??null,expectedControl,supersedeTarget});
356
393
  }
357
394
  if(run.blocked){output.write(JSON.stringify({outcome:'blocked',admission:run.blocked})+'\n');return 1;}
358
- if(hasFix){
395
+ if(hasFix&&reviewedIntegration===null){
359
396
  need(fs.realpathSync(fix.specsRoot)===fs.realpathSync(definition.specsDir)
360
397
  &&fs.realpathSync(fix.configuration.reproduction.cwd)===fs.realpathSync(definition.codeProject)
361
398
  &&(templated?fix.feature:fix.configuration.qaSource.feature)===definition.feature,'qa_fix_source_mismatch');
@@ -364,9 +401,9 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
364
401
  let fixPermissions=[...fixLocalPermissions].filter(([flag])=>controlPolicy
365
402
  ?!['test-author','repair','cause-review','final-review'].some(name=>flag.endsWith('-'+name))
366
403
  :extra.has(flag)).map(([,permission])=>permission);
367
- const fixRuntime=fix.configuration.runtime??'codex';
368
- const fixModels=externalModels?selectExternalModels(externalModels,[fixRuntime]):null;
369
- const fixReview=extra.has('--qa-fix-review-config')?reviewConfiguration(extra.get('--qa-fix-review-config'),fixModels?.providers[fixRuntime]??null):null;
404
+ const fixRuntime=fix.configuration.runtime??'codex',fixReviewRuntime=fix.configuration.reviewRuntime??fixRuntime;
405
+ const fixModels=externalModels?selectExternalModels(externalModels,[fixReviewRuntime]):null;
406
+ const fixReview=extra.has('--qa-fix-review-config')?reviewConfiguration(extra.get('--qa-fix-review-config'),fixModels?.providers[fixReviewRuntime]??null):null;
370
407
  if(controlPolicy&&fixReview)fixPermissions.push(...[...fixLocalPermissions]
371
408
  .filter(([flag])=>flag.endsWith('-cause-review')||flag.endsWith('-final-review')
372
409
  ||fix.configuration.testAuthor&&flag.endsWith('-test-author')||fix.configuration.repair&&flag.endsWith('-repair'))
@@ -374,10 +411,10 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
374
411
  need(!fixPermissions.includes('--allow-test-author')||(fix.configuration.testAuthor&&fixReview),'test_author_configuration_required');
375
412
  need(!fixPermissions.includes('--allow-repair')||(fix.configuration.repair&&fixReview),'repair_configuration_required');
376
413
  const fixReviewHost=createFixReviewHost({codeProject:definition.codeProject,
377
- hostContextId:argv[6],runtime:fix.configuration.runtime??'codex',
414
+ hostContextId:argv[6],runtime:fixRuntime,reviewRuntime:fix.configuration.reviewRuntime,verification:fix.configuration.reviewVerification??null,
378
415
  review:fixReview,permissions:fixPermissions,externalModels:fixModels,executionPolicy,specsDir:definition.specsDir});
379
416
  if(fixModels||executionPolicy){
380
- if(fixModels&&fix.configuration.causeReview)need(fix.configuration.causeReview.requestedModel===fixModels.providers[fixRuntime].model&&fix.configuration.causeReview.provider===fixRuntime,'external_model_pair_conflict');
417
+ if(fixModels&&fix.configuration.causeReview)need(fix.configuration.causeReview.requestedModel===fixModels.providers[fixReviewRuntime].model&&fix.configuration.causeReview.provider===fixReviewRuntime,'external_model_pair_conflict');
381
418
  if(fixReview){
382
419
  // Preserve explicit reviewer contexts/exclusions; changing them changes the durable run.
383
420
  need(!fix.configuration.causeReview||digest(fix.configuration.causeReview)===digest(fixReviewHost.reviewer),'qa_fix_review_configuration_mismatch');
@@ -397,7 +434,11 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
397
434
  const rawMode=input.isTTY&&typeof input.setRawMode==='function';if(rawMode)input.setRawMode(true);
398
435
  const controlled=controlPolicy?withControlPolicyHost(run.host,{identity:definition.identity,
399
436
  snapshot:()=>readExecutionSnapshot({specsRoot:definition.specsDir,identity:{repositoryId:definition.identity.repositoryId,runId:definition.identity.runId}}),launchTarget:controlLaunchTarget}):run.host;
400
- const diagnosticHost=withHandoffDiagnostic(controlled,error);
437
+ const launchHost=reviewedIntegration===null?controlled:{...controlled,async handle(request){
438
+ if(request.operation!=='status')return {outcome:'rejected',code:'integration_launch_status_only'};
439
+ return controlled.handle(request);
440
+ }};
441
+ const diagnosticHost=withHandoffDiagnostic(launchHost,error);
401
442
  try{await serveHostTransport({host:diagnosticHost,input,output,toolBridge:bridge,errorOutput:error},extra.get('--input-limit'));}
402
443
  finally{if(rawMode)input.setRawMode(false);}
403
444
  return 0;