@aibyzero/cm-workflow 0.16.8 → 0.17.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 (226) hide show
  1. package/.codex-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +31 -0
  3. package/README.md +22 -3
  4. package/VERSION +1 -1
  5. package/compat/claude-commands/cm-notify.md +3 -0
  6. package/docs/cm-control-policy-v2.md +331 -0
  7. package/docs/execution-optimizations.md +1 -1
  8. package/docs/external-models.md +3 -3
  9. package/docs/human-correction.md +5 -5
  10. package/docs/installation.md +1 -1
  11. package/docs/js-workflow-control.md +119 -78
  12. package/docs/next-steps.md +19 -2
  13. package/docs/untested-branches.md +2 -3
  14. package/docs/user-guide.md +105 -5
  15. package/package.json +2 -1
  16. package/runtime/js/cm-ai/claude-review-stream.mjs +49 -13
  17. package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +103 -68
  18. package/runtime/js/cm-ai/cm-ai-qa-log.mjs +79 -27
  19. package/runtime/js/cm-ai/code-projects.mjs +4 -1
  20. package/runtime/js/cm-ai/control-policy.mjs +111 -0
  21. package/runtime/js/cm-ai/developer-adapter.mjs +7 -0
  22. package/runtime/js/cm-ai/drive-bootstrap.mjs +11 -8
  23. package/runtime/js/cm-ai/drive-core.mjs +9 -0
  24. package/runtime/js/cm-ai/durable-runner-state.mjs +883 -69
  25. package/runtime/js/cm-ai/effect-abandon-log.mjs +5 -2
  26. package/runtime/js/cm-ai/effect-contract.mjs +6 -1
  27. package/runtime/js/cm-ai/external-run-guard.mjs +18 -7
  28. package/runtime/js/cm-ai/gate-bridge.mjs +4 -4
  29. package/runtime/js/cm-ai/host-check.mjs +4 -1
  30. package/runtime/js/cm-ai/host-conversation-execution.mjs +33 -24
  31. package/runtime/js/cm-ai/host-documentation.mjs +53 -12
  32. package/runtime/js/cm-ai/host-project-execution.mjs +2 -2
  33. package/runtime/js/cm-ai/host-qa-executor.mjs +49 -4
  34. package/runtime/js/cm-ai/host-qa-fix-owner.mjs +53 -9
  35. package/runtime/js/cm-ai/host-qa-policy.mjs +63 -21
  36. package/runtime/js/cm-ai/host-review-authority.mjs +2 -2
  37. package/runtime/js/cm-ai/host-review-file.mjs +1 -1
  38. package/runtime/js/cm-ai/host-session.mjs +1 -1
  39. package/runtime/js/cm-ai/host-tool-bridge.mjs +43 -3
  40. package/runtime/js/cm-ai/host-workflow-capabilities.mjs +21 -10
  41. package/runtime/js/cm-ai/host.mjs +1 -2
  42. package/runtime/js/cm-ai/operator-guidance.mjs +89 -3
  43. package/runtime/js/cm-ai/provider-review-observation.mjs +50 -0
  44. package/runtime/js/cm-ai/qa-resource-release.mjs +46 -0
  45. package/runtime/js/cm-ai/qa-round-budget.mjs +13 -0
  46. package/runtime/js/cm-ai/review-package.mjs +26 -5
  47. package/runtime/js/cm-ai/reviewed-deliveries.mjs +1 -1
  48. package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +1 -1
  49. package/runtime/js/cm-ai/task-commit.mjs +39 -0
  50. package/runtime/js/cm-ai/task-runner.mjs +629 -121
  51. package/runtime/js/cm-ai/worker-claude-developer.mjs +9 -0
  52. package/runtime/js/cm-ai/worker-claude.mjs +10 -3
  53. package/runtime/js/cm-ai/worker-process-identity.mjs +43 -0
  54. package/runtime/js/cm-fix/execution.mjs +176 -48
  55. package/runtime/js/cm-fix/host.mjs +2 -1
  56. package/runtime/js/cm-fix/pinned-baseline.mjs +24 -0
  57. package/runtime/js/cm-fix/progress.mjs +13 -3
  58. package/runtime/js/cm-fix/protected-edits.mjs +10 -3
  59. package/runtime/js/cm-fix/repair.mjs +11 -3
  60. package/runtime/js/cm-fix/test-author.mjs +10 -3
  61. package/runtime/js/cm-idea/session.mjs +67 -4
  62. package/runtime/js/cm-init/review-evidence.mjs +3 -1
  63. package/runtime/js/cm-prd/review-correction.mjs +10 -4
  64. package/runtime/js/cm-prd/review-host.mjs +1 -1
  65. package/runtime/js/cm-prd/review-publication.mjs +5 -3
  66. package/runtime/js/cm-prd/session.mjs +43 -0
  67. package/runtime/js/cm-refactor/records.mjs +98 -8
  68. package/runtime/js/cm-refactor/workflow.mjs +80 -10
  69. package/runtime/js/cm-test/host.mjs +10 -3
  70. package/runtime/js/cm-test/session.mjs +45 -6
  71. package/runtime/js/notify-safe-read.mjs +49 -0
  72. package/runtime/js/notify-send.mjs +313 -0
  73. package/runtime/js/notify.mjs +164 -37
  74. package/runtime/js/policy-binding-compat.mjs +55 -0
  75. package/runtime/review.md +52 -7
  76. package/runtime/task-gates.md +107 -9
  77. package/scripts/ci-test-shards.mjs +67 -0
  78. package/scripts/ci-test-shards.test.mjs +64 -0
  79. package/scripts/ci-test-weights.json +222 -0
  80. package/scripts/cm-ai-abandon-effect-position.test.mjs +71 -10
  81. package/scripts/cm-ai-answer-gap-dispatch.test.mjs +86 -0
  82. package/scripts/cm-ai-answer-gap-driver.test.mjs +51 -0
  83. package/scripts/cm-ai-answer-gap-fixture.mjs +89 -0
  84. package/scripts/cm-ai-answer-gap-recheck.test.mjs +70 -0
  85. package/scripts/cm-ai-answer-gap-redo.test.mjs +103 -0
  86. package/scripts/cm-ai-batch-drive.mjs +98 -34
  87. package/scripts/cm-ai-batch-drive.test.mjs +124 -16
  88. package/scripts/cm-ai-batch-host.mjs +167 -29
  89. package/scripts/cm-ai-batch-host.test.mjs +303 -31
  90. package/scripts/cm-ai-batch-run-fixture.mjs +452 -0
  91. package/scripts/cm-ai-batch-run-member-stops.test.mjs +26 -0
  92. package/scripts/cm-ai-batch-run-parallel.test.mjs +7 -0
  93. package/scripts/cm-ai-batch-run-reschedule.test.mjs +17 -0
  94. package/scripts/cm-ai-batch-run.mjs +213 -25
  95. package/scripts/cm-ai-batch-run.test.mjs +21 -341
  96. package/scripts/cm-ai-bootstrap-flow.test.mjs +1 -7
  97. package/scripts/cm-ai-bootstrap.test.mjs +2 -3
  98. package/scripts/cm-ai-control-launch.test.mjs +219 -0
  99. package/scripts/cm-ai-control-policy.test.mjs +124 -0
  100. package/scripts/cm-ai-control-v2-drive.test.mjs +270 -0
  101. package/scripts/cm-ai-develop-answer-invalid.test.mjs +97 -0
  102. package/scripts/cm-ai-develop-call-timeout.test.mjs +146 -0
  103. package/scripts/cm-ai-develop-driver-gaps.test.mjs +37 -23
  104. package/scripts/cm-ai-direct-review.test.mjs +348 -0
  105. package/scripts/cm-ai-documentation-sync-gap.test.mjs +424 -0
  106. package/scripts/cm-ai-drive-bootstrap-rules.test.mjs +54 -25
  107. package/scripts/cm-ai-drive.mjs +142 -58
  108. package/scripts/cm-ai-drive.test.mjs +70 -84
  109. package/scripts/cm-ai-fix-integration.test.mjs +3 -5
  110. package/scripts/cm-ai-fix-later-delivery.test.mjs +3 -6
  111. package/scripts/cm-ai-fix-run-delivery.test.mjs +3 -6
  112. package/scripts/cm-ai-host-cli-workflow.test.mjs +267 -0
  113. package/scripts/cm-ai-host-fixture.mjs +296 -0
  114. package/scripts/cm-ai-host-protected.test.mjs +253 -0
  115. package/scripts/cm-ai-host.mjs +122 -100
  116. package/scripts/cm-ai-host.test.mjs +35 -776
  117. package/scripts/cm-ai-launch-diagnostics.test.mjs +5 -3
  118. package/scripts/cm-ai-legacy-history.test.mjs +53 -0
  119. package/scripts/cm-ai-light-modules.test.mjs +54 -0
  120. package/scripts/cm-ai-multi-root.test.mjs +4 -4
  121. package/scripts/cm-ai-nested-execution.test.mjs +16 -19
  122. package/scripts/cm-ai-operator-guidance.test.mjs +30 -5
  123. package/scripts/cm-ai-progress.test.mjs +10 -8
  124. package/scripts/cm-ai-project-qa-gate.test.mjs +37 -10
  125. package/scripts/cm-ai-protected-scope.test.mjs +8 -5
  126. package/scripts/cm-ai-qa-answer-gaps.test.mjs +99 -0
  127. package/scripts/cm-ai-qa-config-revision.test.mjs +1 -9
  128. package/scripts/cm-ai-qa-fingerprint-config.test.mjs +12 -9
  129. package/scripts/cm-ai-qa-fix-cross-session.test.mjs +95 -13
  130. package/scripts/cm-ai-qa-fixed-log.test.mjs +41 -0
  131. package/scripts/cm-ai-qa-recovery-args.test.mjs +7 -0
  132. package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +59 -14
  133. package/scripts/cm-ai-review-drift-precedence.test.mjs +1 -1
  134. package/scripts/cm-ai-review-failure.test.mjs +137 -32
  135. package/scripts/cm-ai-review-timeout-config.test.mjs +3 -1
  136. package/scripts/cm-ai-review-timeout.test.mjs +132 -67
  137. package/scripts/cm-ai-run.mjs +91 -28
  138. package/scripts/cm-ai-run.test.mjs +11 -38
  139. package/scripts/cm-ai-selection-guard.test.mjs +2 -2
  140. package/scripts/cm-ai-session-chain.test.mjs +18 -15
  141. package/scripts/cm-ai-spec-rebind.test.mjs +14 -18
  142. package/scripts/cm-ai-supersede.test.mjs +489 -51
  143. package/scripts/cm-blocked-reason.test.mjs +2 -3
  144. package/scripts/cm-capability-gate.test.mjs +33 -1
  145. package/scripts/cm-check-drive-files.mjs +8 -0
  146. package/scripts/cm-check-drive.test.mjs +2 -5
  147. package/scripts/cm-check-runtime.sh +4 -2
  148. package/scripts/cm-claude-developer-worker.test.mjs +15 -0
  149. package/scripts/cm-claude-review-stream.test.mjs +21 -16
  150. package/scripts/cm-claude-review-synthetic.test.mjs +155 -0
  151. package/scripts/cm-claude-worker.test.mjs +23 -5
  152. package/scripts/cm-controlled-correction.test.mjs +469 -0
  153. package/scripts/cm-external-batch-host.test.mjs +30 -11
  154. package/scripts/cm-external-model-host.test.mjs +1 -1
  155. package/scripts/cm-external-model-recovery.test.mjs +32 -12
  156. package/scripts/cm-external-qa-fix.test.mjs +1 -1
  157. package/scripts/cm-external-review-reconciliation.test.mjs +6 -24
  158. package/scripts/cm-fix-abandon.test.mjs +163 -10
  159. package/scripts/cm-fix-drive-unprotected.test.mjs +37 -0
  160. package/scripts/cm-fix-drive.mjs +25 -7
  161. package/scripts/cm-fix-host.mjs +8 -7
  162. package/scripts/cm-fix-review-budget.test.mjs +13 -0
  163. package/scripts/cm-fix-review-recovery.test.mjs +36 -1
  164. package/scripts/cm-host-answer-timeout.test.mjs +65 -0
  165. package/scripts/cm-host-call-kinds.test.mjs +28 -0
  166. package/scripts/cm-host-documentation.test.mjs +49 -0
  167. package/scripts/cm-host-qa-executor.test.mjs +23 -12
  168. package/scripts/cm-host-qa-policy.test.mjs +43 -16
  169. package/scripts/cm-host-review-authority.test.mjs +0 -31
  170. package/scripts/cm-idea-answer-gaps.test.mjs +164 -0
  171. package/scripts/cm-idea-drive.mjs +49 -11
  172. package/scripts/cm-idea-drive.test.mjs +66 -0
  173. package/scripts/cm-idea-host.mjs +106 -16
  174. package/scripts/cm-init-answer-gaps.test.mjs +258 -0
  175. package/scripts/cm-init-drive.mjs +41 -7
  176. package/scripts/cm-init-host.mjs +61 -12
  177. package/scripts/cm-knowledge-closeout.test.mjs +3 -3
  178. package/scripts/cm-log-event.mjs +21 -10
  179. package/scripts/cm-notify-command.test.mjs +936 -0
  180. package/scripts/cm-notify-read-drift.test.mjs +270 -0
  181. package/scripts/cm-notify.mjs +481 -0
  182. package/scripts/cm-notify.test.mjs +312 -23
  183. package/scripts/cm-patrol.test.mjs +3 -2
  184. package/scripts/cm-prd-answer-gaps.test.mjs +216 -0
  185. package/scripts/cm-prd-drive.mjs +18 -5
  186. package/scripts/cm-prd-drive.test.mjs +15 -0
  187. package/scripts/cm-prd-host.mjs +37 -4
  188. package/scripts/cm-prd-review-disposition.test.mjs +6 -1
  189. package/scripts/cm-prd-review-gate.mjs +56 -0
  190. package/scripts/cm-refactor-answer-gaps.test.mjs +206 -0
  191. package/scripts/cm-refactor-drive.mjs +52 -8
  192. package/scripts/cm-refactor-drive.test.mjs +44 -0
  193. package/scripts/cm-refactor-host.test.mjs +10 -6
  194. package/scripts/cm-release-smoke.sh +2 -0
  195. package/scripts/cm-task-gate-correction.test.mjs +69 -16
  196. package/scripts/cm-task-gate.mjs +368 -34
  197. package/scripts/cm-task-gate.py +2 -0
  198. package/scripts/cm-task-gate.test.mjs +252 -4
  199. package/scripts/cm-test-answer-gaps.test.mjs +151 -0
  200. package/scripts/cm-test-drive.mjs +21 -5
  201. package/scripts/fixtures/bootstrap-review-runner.mjs +1 -7
  202. package/scripts/fixtures/claude-review-process.mjs +1 -1
  203. package/scripts/fixtures/native-gate-fixture.mjs +18 -0
  204. package/scripts/policy-binding-compat.test.mjs +103 -0
  205. package/scripts/scan-public-safety.py +4 -0
  206. package/scripts/validate-public-repo.py +4 -0
  207. package/skills/cm-ai/SKILL.md +8 -6
  208. package/skills/cm-ai/references/N3-execute-task.md +17 -2
  209. package/skills/cm-ai/references/N4-review.md +11 -21
  210. package/skills/cm-ai/references/N5-mark-done.md +1 -1
  211. package/skills/cm-ai/references/N6-qa-eval.md +49 -21
  212. package/skills/cm-ai/references/js-host-modes.md +35 -14
  213. package/skills/cm-ai/references/js-host-qa-recovery.md +85 -11
  214. package/skills/cm-ai/references/js-host-recovery.md +181 -21
  215. package/skills/cm-ai/references/js-host.md +76 -32
  216. package/skills/cm-check/SKILL.md +3 -3
  217. package/skills/cm-fix/SKILL.md +12 -0
  218. package/skills/cm-fix/references/js-host.md +44 -5
  219. package/skills/cm-idea/references/js-host.md +27 -2
  220. package/skills/cm-init/references/js-host.md +17 -4
  221. package/skills/cm-notify/SKILL.md +34 -0
  222. package/skills/cm-prd/references/js-change-recovery.md +35 -1
  223. package/skills/cm-prd/references/js-host.md +1 -1
  224. package/skills/cm-refactor/SKILL.md +12 -0
  225. package/skills/cm-refactor/references/js-host.md +17 -0
  226. package/skills/cm-test/references/js-host.md +14 -1
@@ -5,32 +5,135 @@ import {readBatchExternalModels,freezeBatchExternalModels,batchModelsFile} from
5
5
  import fs from 'node:fs';
6
6
  import path from 'node:path';
7
7
  import {fileURLToPath} from 'node:url';
8
- import {createCmAiBatch,batchTaskRunId} from './cm-ai-batch-run.mjs';
8
+ import {createCmAiBatch,batchTaskRunId,BATCH_MEMBER_ACTIONS} from './cm-ai-batch-run.mjs';
9
+ import {validEnvironmentFailureReason} from '../runtime/js/cm-ai/cm-ai-qa-log.mjs';
9
10
  import {assertCreatableScope} from './cm-ai-run.mjs';
10
- import {createConversationExecution,readConversationReviewConfiguration,readConversationProtection,runReviewPreflight} from './cm-ai-host.mjs';
11
+ import {createConversationExecution,readConversationReviewConfiguration,readConversationReviewConfigurationValue,readConversationProtection,runReviewPreflight} from './cm-ai-host.mjs';
11
12
  import {loadConfig,resolveProtectedRuntimes} from './cm-workflow-config.mjs';
12
13
  import {preflightMatches} from '../runtime/js/cm-ai/worker-codex.mjs';
13
14
  import {claudePreflightMatches} from '../runtime/js/cm-ai/worker-claude.mjs';
14
- import {createHostToolBridge} from '../runtime/js/cm-ai/host-tool-bridge.mjs';
15
+ import {createHostToolBridge,HOST_ANSWER_BACKSTOP_MS} from '../runtime/js/cm-ai/host-tool-bridge.mjs';
15
16
  import {serveCmAiHost,parseHostInputLimit,inputLimitReason} from '../runtime/js/cm-ai/host-session.mjs';
16
17
  import {validateHostWorkflowConfiguration,featureHasBrowserCases,readBrowserCapability} from '../runtime/js/cm-ai/host-workflow-capabilities.mjs';
17
18
  import {digest,json,need,shape} from '../runtime/js/cm-ai/effect-contract.mjs';
18
19
  import {identifyApprovedBootstrapFeature} from '../runtime/js/cm-ai/bootstrap-feature.mjs';
20
+ import {readControlPolicyFile} from '../runtime/js/cm-ai/control-policy.mjs';
19
21
 
20
- const usage='cm-ai-batch-host.mjs serve --config PATH --host-context ID --allow-development --review-config PATH (required for a new batch; later launches pass the same file) [--execution-optimizations] [--external-models [--external-models-config PATH]] [--runtime codex|claude] [--input-limit BYTES] [--allow-review FEATURE/TASK:1|2]... [--allow-qa] [--rerun-unknown-qa | --rerun-blocked-qa] [--verification-precheck] [--browser-qa available|unavailable] [--protected-conversation-config PATH | --protected-config PATH] [--allow-provider-development FEATURE/TASK:1|2]... [--hold-revision FEATURE/TASK]...';
22
+ const usage='cm-ai-batch-host.mjs serve --config PATH --host-context ID --allow-development --review-config PATH (required for a new batch; later launches pass the same file) [--execution-optimizations] [--external-models [--external-models-config PATH]] [--runtime codex|claude] [--input-limit BYTES] [--allow-qa] [--rerun-unknown-qa | --rerun-blocked-qa [--qa-environment-failure REASON]] [--allow-develop-redo FEATURE/TASK]... [--allow-abandon-effect FEATURE/TASK]... [--allow-abandon-review FEATURE/TASK]... [--allow-bootstrap-review-recovery FEATURE/TASK]... [--verification-precheck] [--browser-qa available|unavailable] [--protected-conversation-config PATH | --protected-config PATH] [--allow-provider-development FEATURE/TASK:1|2]... [--hold-revision FEATURE/TASK]...';
21
23
  const safeCode=error=>typeof error?.code==='string'&&/^[a-z][a-z0-9_]{0,63}$/.test(error.code)?error.code:'batch_host_failed';
24
+ // Operator-facing reasons the batch owner writes itself (R4); others stay redacted.
25
+ const REASONED=new Set(['batch_resources_open','legacy_preflight_cache_invalid']);
26
+ const boundedReason=error=>REASONED.has(error?.code)&&typeof error.reason==='string'&&error.reason.length<=8192&&!/[\r\n\0]/.test(error.reason)?error.reason:null;
27
+ const actionFlags=new Map(Object.entries(BATCH_MEMBER_ACTIONS).map(([name,{flag}])=>[flag,name]));
28
+ // Single-task recovery inputs a batch cannot take: each member's fingerprint binds
29
+ // the whole batch workflow map, and a member cannot be rebound alone.
30
+ const UNSUPPORTED={'--revise-qa-config':'batch_qa_revision_unavailable','--qa-config-revision-reason':'batch_qa_revision_unavailable',
31
+ '--rebind-spec-material':'batch_spec_rebind_unavailable','--spec-rebind-reason':'batch_spec_rebind_unavailable'};
32
+ const UNSUPPORTED_REASON={batch_qa_revision_unavailable:'批次不能修订单个成员的 QA 配置:每个成员的运行指纹绑定整批 workflows,改一个成员会让其他成员都无法恢复,单任务宿主也打不开批次成员运行。出口:QA 环境问题用 --rerun-blocked-qa(必要时加 --qa-environment-failure 原因);确需改 QA 命令,取消本批次后用单任务宿主 cm-ai-host.mjs 以 --supersede-reviewed-evidence --supersede-reason 原因 新建运行重做该任务',
33
+ batch_spec_rebind_unavailable:'批次成员不能换绑规格。出口:还原这些规格改动并重新批准后继续本批次;或取消本批次,还原该任务已改动的代码后,用单任务宿主 cm-ai-host.mjs 以 --supersede-reviewed-evidence --supersede-reason 原因 新建运行重做该任务'};
22
34
 
23
35
  export async function serveHostTransport(options,rawInputLimit,serve=serveCmAiHost){
24
36
  return serve({...options,inputLimit:parseHostInputLimit(rawInputLimit)});
25
37
  }
26
38
 
27
- async function memberReviewConfiguration(batch,definition,review,runtime,pair=null,allowPreflight=true){
39
+ // Before 53c385e an execution-policy batch (without external models) cached its member
40
+ // loopback preflights in .reviews/.execution/<batchId>/preflight-<task>.json. The
41
+ // external run guard refuses that non-run directory, so such a batch could never open
42
+ // a member again. A directory that is exactly that old cache (only 0600 single-link
43
+ // preflight files of this batch's parallel members, each still bound to the launch
44
+ // review model, disabled skills and the member worktree cwd) moves file by file to
45
+ // the current location; an identical file already there drops the old copy. Anything
46
+ // else is refused with the directory named and nothing moved, so it is checked by hand.
47
+ export function migrateLegacyPreflightCache(batch,review,runtime){
48
+ const legacy=path.join(batch.specsDir,'.reviews','.execution',batch.batchId);
49
+ let stat;try{stat=fs.lstatSync(legacy);}catch(error){if(error.code==='ENOENT')return {moved:[],dropped:[]};throw error;}
50
+ const refuse=detail=>{throw Object.assign(new Error('legacy_preflight_cache_invalid'),{code:'legacy_preflight_cache_invalid',
51
+ reason:`运行目录下的 ${legacy} 不是可识别的旧版并行成员预检缓存(${detail})。外部运行守卫会把它当作无法核实的运行,批次成员打不开;宿主没有移动或删除其中任何文件。`
52
+ +`下一步:只读核对该目录;确认只是旧版 preflight 缓存且没有进程在写后,把它移出 .reviews/.execution(例如移到 .reviews/external-preflight-legacy/),再用同一批次配置重新启动批次宿主并 advance,成员会重新做一次本地 loopback 预检`});};
53
+ if(!stat.isDirectory()||stat.isSymbolicLink()||(stat.mode&0o077)!==0||fs.realpathSync(legacy)!==legacy)refuse('不是权限 0700 的普通目录');
54
+ if(review===null)refuse('本次启动没有 --review-config,无法核对缓存绑定的审查模型');
55
+ const members=new Map((batch.parallel??[]).flat().map(key=>[`preflight-${key.slice(key.lastIndexOf('/')+1)}.json`,key.slice(key.lastIndexOf('/')+1)]));
56
+ // The target and its parent are checked before anything is moved or deleted,
57
+ // whether or not a file will be moved; a missing one is created 0700 (one level at
58
+ // a time) and checked again only right before the first move.
59
+ const parent=path.join(batch.specsDir,'.reviews','external-preflight'),target=path.join(parent,batch.batchId);
60
+ const targetDirectories=create=>{
61
+ for(const directory of [parent,target]){
62
+ if(create)try{fs.mkdirSync(directory,{mode:0o700});}catch(error){if(error.code!=='EEXIST')throw error;}
63
+ let info;try{info=fs.lstatSync(directory);}catch(error){if(error.code==='ENOENT'&&!create)return;throw error;}
64
+ if(!info.isDirectory()||info.isSymbolicLink()||(info.mode&0o077)!==0||fs.realpathSync(directory)!==directory)
65
+ refuse(`新位置 ${directory} 不是权限 0700 的普通目录`);
66
+ }
67
+ };
68
+ targetDirectories(false);
69
+ // One read per file through a no-follow fd bound to the path's dev+ino; only these
70
+ // exact bytes are validated and compared. links: 2 only for an interrupted move,
71
+ // where the old and new names are the same inode.
72
+ const pinned=(file,links=1)=>{
73
+ let before;try{before=fs.lstatSync(file);}catch(error){if(error.code==='ENOENT')return null;throw error;}
74
+ if(!before.isFile()||before.isSymbolicLink()||before.nlink!==links||(before.mode&0o077)!==0||before.size>64*1024)
75
+ refuse(`${file} 不是权限 0600、${links} 个链接的普通文件`);
76
+ let fd;try{fd=fs.openSync(file,fs.constants.O_RDONLY|fs.constants.O_NOFOLLOW);}catch{refuse(`${file} 无法按不跟随链接的方式打开`);}
77
+ try{
78
+ const info=fs.fstatSync(fd);
79
+ if(info.dev!==before.dev||info.ino!==before.ino||!info.isFile()||info.nlink!==links)refuse(`${file} 在核对时被替换`);
80
+ return {bytes:fs.readFileSync(fd),dev:info.dev,ino:info.ino};
81
+ }finally{fs.closeSync(fd);}
82
+ };
83
+ const same=(left,right)=>left!==null&&right!==null&&left.dev===right.dev&&left.ino===right.ino&&left.bytes.equals(right.bytes);
84
+ const plan=[];
85
+ for(const entry of fs.readdirSync(legacy,{withFileTypes:true})){
86
+ const taskId=members.get(entry.name);if(!taskId)refuse(`含有不属于本批次并行成员预检缓存的条目 ${entry.name}`);
87
+ const file=path.join(legacy,entry.name),destination=path.join(target,entry.name);
88
+ let interrupted=false;
89
+ try{const a=fs.lstatSync(file),b=fs.lstatSync(destination);interrupted=a.dev===b.dev&&a.ino===b.ino;}catch(error){if(error.code!=='ENOENT')throw error;}
90
+ const source=pinned(file,interrupted?2:1);
91
+ if(source===null)refuse(`${entry.name} 在核对时消失`);
92
+ const cwd=path.resolve(batch.codeProject,'..','.cm-worktrees',batch.batchId.slice(0,8),taskId);
93
+ const options={cwd,model:review.model,disabledSkills:review.disabledSkills,promptTransport:'stdin'};
94
+ let cached;try{cached=readConversationReviewConfigurationValue(JSON.parse(source.bytes.toString('utf8')),null);}
95
+ catch{refuse(`${entry.name} 不是预检缓存格式`);}
96
+ if(Object.hasOwn(cached,'timeoutMs')||cached.model!==review.model||digest(cached.disabledSkills)!==digest(review.disabledSkills)
97
+ ||!(runtime==='claude'?claudePreflightMatches:preflightMatches)(cached.preflight,options))
98
+ refuse(`${entry.name} 绑定的审查模型、禁用技能或成员 worktree 指纹与本次启动不一致`);
99
+ if(interrupted){plan.push({file,destination,source,action:'finish'});continue;}
100
+ const existing=pinned(destination);
101
+ if(existing!==null&&!existing.bytes.equals(source.bytes))refuse(`新位置 ${destination} 已有不同内容`);
102
+ plan.push({file,destination,source,existing,action:existing===null?'move':'drop'});
103
+ }
104
+ // Commit without overwriting: link (fails on an existing name), re-read the linked
105
+ // inode, then remove the old name. A duplicate is removed only after both sides are
106
+ // re-read unchanged. A stop at any point leaves either the old file, or the same inode
107
+ // under both names, which the next launch finishes ('finish').
108
+ const moved=[],dropped=[];
109
+ if(plan.some(item=>item.action==='move'))targetDirectories(true);
110
+ for(const item of plan){
111
+ const name=path.basename(item.file);
112
+ if(item.action==='move'){
113
+ try{fs.linkSync(item.file,item.destination);}
114
+ catch(error){if(error.code==='EEXIST')refuse(`新位置 ${item.destination} 在迁移时出现`);throw error;}
115
+ const linked=pinned(item.destination,2);
116
+ if(!same(linked,item.source)){fs.unlinkSync(item.destination);refuse(`${name} 在迁移时被改动`);}
117
+ }else if(item.action==='drop'){
118
+ if(!same(pinned(item.file),item.source)||!same(pinned(item.destination),item.existing))refuse(`${name} 或新位置的副本在迁移时被改动`);
119
+ }else if(!same(pinned(item.destination,2),item.source))refuse(`${name} 在迁移时被改动`);
120
+ fs.unlinkSync(item.file);
121
+ (item.action==='drop'?dropped:moved).push(name);
122
+ }
123
+ try{fs.rmdirSync(legacy);}catch(error){if(['ENOTEMPTY','EEXIST'].includes(error.code))refuse('迁移时目录里出现了新条目');throw error;}
124
+ return {moved,dropped};
125
+ }
126
+ // strict: an execution-policy batch. Its member runs take the external run guard,
127
+ // which refuses any non-run directory under .reviews/.execution, so the loopback
128
+ // cache lives beside the external-model one instead.
129
+ async function memberReviewConfiguration(batch,definition,review,runtime,pair=null,allowPreflight=true,strict=false){
130
+ if(strict&&!pair)migrateLegacyPreflightCache(batch,review,runtime);
28
131
  try{
29
132
  need(review!==null,'review_configuration_required');
30
133
  const options={cwd:definition.codeProject,model:review.model,...(pair?{effort:pair.effort}:{}),disabledSkills:review.disabledSkills,promptTransport:'stdin'};
31
134
  const matches=config=>config.model===review.model&&digest(config.disabledSkills)===digest(review.disabledSkills)
32
135
  &&(runtime==='claude'?claudePreflightMatches:preflightMatches)(config.preflight,options);
33
- const directory=path.join(batch.specsDir,'.reviews',...(pair?['external-preflight']:['.execution']),batch.batchId);
136
+ const directory=path.join(batch.specsDir,'.reviews',...(pair||strict?['external-preflight']:['.execution']),batch.batchId);
34
137
  fs.mkdirSync(directory,{recursive:true,mode:0o700});
35
138
  need(fs.realpathSync(directory)===directory,'invalid_preflight_cache');
36
139
  const file=path.join(directory,`preflight-${definition.identity.taskId}.json`);
@@ -53,12 +156,24 @@ async function memberReviewConfiguration(batch,definition,review,runtime,pair=nu
53
156
  }
54
157
 
55
158
  export async function main(argv=process.argv.slice(2),{input=process.stdin,output=process.stdout,error=process.stderr}={}){
159
+ if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('Control v2: serve --config BUNDLE --host-context ID --control-config POLICY --review-config REVIEW; no --allow-*. Batch qaFix must be disabled. See docs/cm-control-policy-v2.md.\n');
56
160
  if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('Optional --execution-optimizations freezes policy v1 for new runs only; recovery retains the original policy and legacy runs reject retrofit. See docs/execution-optimizations.md.\n');
57
- if(argv.length===1&&['--help','-h'].includes(argv[0])){output.write(usage+'\nOptional --input-limit BYTES sets the host input transport limit to an integer from 65536 to 4194304 (default 65536); it may change on resume.\nOptional --protected-conversation-config PATH uses the shared current-host scoped text proposals and native sandbox checks; {checkCommands,timeoutMs}. No extra model call, same Codex/Claude runtime and per-task Review permissions. Optional --protected-config PATH {model,checkCommands,timeoutMs} enables CLI development only for per-task --allow-provider-development FEATURE/TASK:1|2 grants; mutually exclusive with --protected-conversation-config. Optional bundle.bootstraps maps approved bootstrap task keys to {selection}; --allow-bootstrap-write grants only those fixed instruction/scaffold steps. Optional batch.codeProjects uses prefixed paths and checks with codeProject per command; one task remains one completion gate.\n--review-config PATH is required when no member run of the batch exists yet (like single-task create): it is bound into every member fingerprint and cannot be added on resume. It is {model,preflight[,disabledSkills][,timeoutMs]}; timeoutMs is the reviewer transport budget in milliseconds (integer 1-3600000, default 900000). It is independent of --protected-conversation-config/--protected-config and wins over their timeoutMs for the reviewer. It is not part of the authorized configuration digest, so a resumed run may raise it after review_transport_timeout.\n--browser-qa available|unavailable declares interactive QA capability for applicable feature carriers including browser and ios-simulator; the flag name is retained for compatibility.\nOptional --rerun-unknown-qa / --rerun-blocked-qa carry the same single-task QA recovery into a batch and require --allow-qa; they are mutually exclusive. A batch has no --mode, so each task applies the flag only when it resumes an existing run and has a QA executor; a created run or a task without QA ignores it rather than failing the whole batch. Semantics, limits and the qaRound cap are the single-task ones, unchanged.\nOptional --verification-precheck sends the written verification of the task and the collected checks back as a verification_precheck request before any handoff or review package is built. It may only block: a requirement reported unsatisfied stops the task at blocked / verification_precheck_failed with pendingAction resume and spends no review round. Passing it is not an approval, writes no receipt and does not replace the independent review. A task with no written verification is unaffected.\nOptional --hold-revision FEATURE/TASK (repeatable, launch-only, never persisted) stops that task after a changes_requested review with code revision_answer_required, before any second-round develop intent; the next launch without it resumes the revision. It only narrows what this launch does.\nBatch entry requires a clean Git main checkout (including untracked files); batch_main_dirty lists dirty files before any task or worktree starts. Serial tasks are committed automatically before batch_handoff, with task_commit recording the SHA (null if unchanged). Terminal parallel members preserve WIP on their retained branches and fall back once to serial generation 2 after ready members merge.\n');return 0;}
161
+ if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('成员恢复(Q24):--allow-develop-redo / --allow-abandon-effect / --allow-abandon-review / --allow-bootstrap-review-recovery FEATURE/TASK 各授权一次同名批次操作 {operation, requestId, taskKey, reason},只转给批次当前停住的那个成员运行(同一 cm-ai 入口、只带这一项权限,不跨成员),之后 advance 继续本批次;缺授权返回 batch_member_action_authorization_required,非当前成员返回 batch_member_action_not_current。批次 cancel 后永久停止不变。--qa-environment-failure REASON 随 --rerun-blocked-qa / --rerun-unknown-qa 使用。--revise-qa-config 与 --rebind-spec-material 不支持(batch_qa_revision_unavailable / batch_spec_rebind_unavailable,原因里写明出口)。并行成员停在可在原运行内恢复的状态时返回 batch_parallel_member_recovery_required;结果未确认时返回 batch_parallel_member_unresolved 并留在原运行;只有原始存档为已 checkpoint 的 blocked 才改排串行第二代,且先停在 batch_member_rescheduled,下一次 advance 才开发第二代(普通批次与外部模型、执行策略批次相同)。\n');
162
+ if(argv.length===1&&['--help','-h'].includes(argv[0])){output.write(usage+'\nOptional --input-limit BYTES sets the host input transport limit to an integer from 65536 to 4194304 (default 65536); it may change on resume.\nOptional --protected-conversation-config PATH uses the shared current-host scoped text proposals and native sandbox checks; {checkCommands,timeoutMs}. No extra model call, same Codex/Claude runtime and configured per-task review execution. Optional --protected-config PATH {model,checkCommands,timeoutMs} enables CLI development only for per-task --allow-provider-development FEATURE/TASK:1|2 grants; mutually exclusive with --protected-conversation-config. Optional bundle.bootstraps maps approved bootstrap task keys to {selection}; --allow-bootstrap-write grants only those fixed instruction/scaffold steps. Optional batch.codeProjects uses prefixed paths and checks with codeProject per command; one task remains one completion gate.\n--review-config PATH is required when no member run of the batch exists yet (like single-task create): it is bound into every member fingerprint and cannot be added on resume. It is {model,preflight[,disabledSkills][,timeoutMs]}; timeoutMs is the reviewer transport budget in milliseconds (integer 1-3600000, default 900000). It is independent of --protected-conversation-config/--protected-config and wins over their timeoutMs for the reviewer. It is not part of the authorized configuration digest, so a resumed run may raise it after review_transport_timeout.\n--browser-qa available|unavailable declares interactive QA capability for applicable feature carriers including browser and ios-simulator; the flag name is retained for compatibility.\nOptional --rerun-unknown-qa / --rerun-blocked-qa carry the same single-task QA recovery into a batch and require --allow-qa; they are mutually exclusive. A batch has no --mode, so each task applies the flag only when it resumes an existing run and has a QA executor; a created run or a task without QA ignores it rather than failing the whole batch. Semantics, limits and the qaRound cap are the single-task ones, unchanged.\nOptional --verification-precheck sends the written verification of the task and the collected checks back as a verification_precheck request before any handoff or review package is built. It may only block: a requirement reported unsatisfied stops the task at blocked / verification_precheck_failed with pendingAction resume and spends no review round. Passing it is not an approval, writes no receipt and does not replace the independent review. A task with no written verification is unaffected.\nOptional --hold-revision FEATURE/TASK (repeatable, launch-only, never persisted) stops that task after a changes_requested review with code revision_answer_required, before any second-round develop intent; the next launch without it resumes the revision. It only narrows what this launch does.\nBatch entry requires a clean Git main checkout (including untracked files); batch_main_dirty lists dirty files before any task or worktree starts. Serial tasks are committed automatically before batch_handoff, with task_commit recording the SHA (null if unchanged). A parallel member whose raw journal is a checkpointed blocked terminal preserves WIP on its retained branch and falls back once to serial generation 2 after ready members merge; that advance stops at batch_member_rescheduled and the next one develops generation 2. Unconfirmed members stay in their original run.\n');return 0;}
58
163
  let bridge;
59
164
  try{
60
- need(argv.length>=6&&argv[0]==='serve'&&argv[1]==='--config'&&argv[3]==='--host-context'
61
- &&argv[5]==='--allow-development','host_launch_authorization_required');
165
+ let controlPolicy=null;
166
+ const withMode=argv[0]==='serve'&&argv[3]==='--mode'&&argv[5]==='--host-context'&&argv[7]==='--control-config';
167
+ if(withMode)need(['create','resume'].includes(argv[4]),'invalid_mode');
168
+ const contextOffset=withMode?5:3,controlOffset=withMode?7:5;
169
+ if(argv[0]==='serve'&&argv[controlOffset]==='--control-config'){
170
+ if(argv.some(value=>value.startsWith('--allow-')))throw Object.assign(new Error('invalid_arguments'),
171
+ {code:'invalid_arguments',reason:'新版批次不接受 --allow-*;旧批次请用原入口和参数。'});
172
+ controlPolicy=readControlPolicyFile(argv[controlOffset+1]);need(controlPolicy.qaFix==='disabled','invalid_arguments');
173
+ }
174
+ need(argv.length>=6&&argv[0]==='serve'&&argv[1]==='--config'&&argv[contextOffset]==='--host-context'
175
+ &&(controlPolicy!==null||argv[5]==='--allow-development'),'host_launch_authorization_required');
176
+ const hostContextId=argv[contextOffset+1];
62
177
  const stat=fs.lstatSync(argv[2]);need(stat.isFile()&&!stat.isSymbolicLink()&&stat.size<=64*1024,'invalid_batch_config');
63
178
  const bundle=json(JSON.parse(fs.readFileSync(argv[2],'utf8')));shape(bundle,['batch','workflows',...(Object.hasOwn(bundle,'bootstraps')?['bootstraps']:[])]);
64
179
  const {batch,workflows,bootstraps=null}=bundle;need(Array.isArray(batch.tasks),'invalid_batch_config');
@@ -73,15 +188,29 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
73
188
  need(keys.length===Object.keys(workflows).length&&keys.every(key=>Object.hasOwn(workflows,key)),'workflow_task_mismatch');
74
189
  for(const key of keys)if(workflows[key]!==null)validateHostWorkflowConfiguration(workflows[key]);
75
190
  let review=null,allowQa=false,allowBootstrap=false,runtime=null,protection=null,providerConfig=null,browserQaFlag,inputLimitRaw;
76
- let rerunUnknownQa=false,rerunBlockedQa=false,verificationPrecheck=false;const approvals=new Set(),developments=new Map(),holds=new Set();
191
+ let rerunUnknownQa=false,rerunBlockedQa=false,verificationPrecheck=false,qaEnvironmentFailure=null;const developments=new Map(),holds=new Set();
192
+ const memberActions=Object.fromEntries(Object.keys(BATCH_MEMBER_ACTIONS).map(name=>[name,[]]));
77
193
  let externalEnabled=false,externalFile,executionPolicyEnabled=false;
78
- for(let index=6;index<argv.length;index++){
194
+ for(let index=controlPolicy?controlOffset+2:6;index<argv.length;index++){
79
195
  const name=argv[index];
80
196
  if(name==='--execution-optimizations'){need(!executionPolicyEnabled,'invalid_arguments');executionPolicyEnabled=true;}
81
197
  else if(name==='--allow-qa'){need(!allowQa,'invalid_arguments');allowQa=true;}
82
198
  else if(name==='--rerun-unknown-qa'){need(!rerunUnknownQa,'invalid_arguments');rerunUnknownQa=true;}
83
199
  else if(name==='--rerun-blocked-qa'){need(!rerunBlockedQa,'invalid_arguments');rerunBlockedQa=true;}
84
200
  else if(name==='--verification-precheck'){need(!verificationPrecheck,'invalid_arguments');verificationPrecheck=true;}
201
+ else if(name==='--qa-environment-failure'){
202
+ need(qaEnvironmentFailure===null&&validEnvironmentFailureReason(argv[index+1]),'invalid_arguments');qaEnvironmentFailure=argv[++index];
203
+ }
204
+ else if(actionFlags.has(name)){
205
+ // A recovery grant names one member; it is consumed by that member's first forwarded operation.
206
+ const target=argv[++index],granted=memberActions[actionFlags.get(name)];
207
+ if(!(typeof target==='string'&&keys.includes(target)&&!granted.includes(target)))
208
+ throw Object.assign(new Error('invalid_arguments'),{code:'invalid_arguments',reason:`${name} 需要一个本批次的 FEATURE/TASK,且同一任务只给一次`});
209
+ granted.push(target);
210
+ }
211
+ else if(Object.hasOwn(UNSUPPORTED,name)){
212
+ const code=UNSUPPORTED[name];throw Object.assign(new Error(code),{code,reason:UNSUPPORTED_REASON[code]});
213
+ }
85
214
  else if(name==='--browser-qa'){
86
215
  need(browserQaFlag===undefined&&typeof argv[index+1]==='string','invalid_arguments');browserQaFlag=argv[++index];
87
216
  }
@@ -114,11 +243,15 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
114
243
  else if(name==='--hold-revision'){
115
244
  const held=argv[++index];need(typeof held==='string'&&keys.includes(held)&&!holds.has(held),'invalid_arguments');holds.add(held);
116
245
  }
117
- else if(name==='--allow-review'){
118
- const approval=argv[++index];need(typeof approval==='string'&&!approvals.has(approval),'invalid_arguments');
119
- const split=approval.lastIndexOf(':'),key=approval.slice(0,split),attempt=approval.slice(split+1);
120
- need(keys.includes(key)&&['1','2'].includes(attempt),'review_task_mismatch');approvals.add(approval);
121
- }else need(false,'invalid_arguments');
246
+ else need(false,'invalid_arguments');
247
+ }
248
+ if(controlPolicy){
249
+ allowQa=controlPolicy.qa==='run';allowBootstrap=controlPolicy.bootstrap==='write';
250
+ need((controlPolicy.development==='provider')===Boolean(providerConfig),'invalid_arguments');
251
+ need(controlPolicy.bootstrap!=='write'||bootstraps!==null,'invalid_arguments');
252
+ need(bootstraps===null||controlPolicy.bootstrap==='write','invalid_arguments');
253
+ if(providerConfig)for(const key of keys)developments.set(key,1);
254
+ need(!rerunUnknownQa&&!rerunBlockedQa,'supersede_unavailable');
122
255
  }
123
256
  const started=keys.some(key=>fs.existsSync(path.join(batch.specsDir,'.reviews','.execution',batchTaskRunId(batch.batchId,key),'state.json')));
124
257
  // Same read-only create gate as the batch owner, before any model or policy configuration is read or frozen.
@@ -139,15 +272,15 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
139
272
  need(!developments.size||providerConfig!==null,'protected_configuration_required');
140
273
  // Same launch-time assertion as the single-task host, evaluated across every
141
274
  // task whose approved contract can select a browser case.
142
- readBrowserCapability(browserQaFlag,keys.flatMap(key=>workflows[key]?.qa!=null
275
+ readBrowserCapability(browserQaFlag,keys.flatMap(key=>(!controlPolicy||allowQa)&&workflows[key]?.qa!=null
143
276
  &&featureHasBrowserCases(batch.specsDir,key.slice(0,key.lastIndexOf('/')),batch.codeProject)
144
277
  ?[workflows[key].qa.environment?.carrier??'browser']:[]));
145
- need(!approvals.size||review!==null,'review_configuration_required');
146
278
  // Same two guards as the single-task host. A batch has no --mode, so the
147
279
  // per-task resume check lives in createCmAiBatch rather than here.
148
280
  need(!(rerunUnknownQa&&rerunBlockedQa),'qa_recovery_authorization_required');
149
281
  need(!(rerunUnknownQa||rerunBlockedQa)||allowQa,'qa_recovery_authorization_required');
150
- need(allowQa||!Object.values(workflows).some(item=>item?.qa!=null),'qa_authorization_required');
282
+ need(qaEnvironmentFailure===null||rerunUnknownQa||rerunBlockedQa,'qa_recovery_authorization_required');
283
+ need(controlPolicy||allowQa||!Object.values(workflows).some(item=>item?.qa!=null),'qa_authorization_required');
151
284
  // Same rule as single-task create: the reviewer binding is part of every
152
285
  // member's durable fingerprint and cannot be added on resume. A batch none
153
286
  // of whose member runs exist yet is being created. Batches that already
@@ -156,9 +289,9 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
156
289
  batchTaskRunId(batch.batchId,key),'state.json')));
157
290
  if(!created&&review===null)throw Object.assign(new Error('review_configuration_required'),{code:'review_configuration_required',
158
291
  reason:'新批次必须带 --review-config:审查配置写进每个任务运行的指纹,恢复时不能再补。先用 cm-ai-host.mjs preflight 生成 review.json;'
159
- +'是否真正派发审查仍由 --allow-review 单独授权'});
292
+ +'普通 advance 按已有审查配置派发第 1、2 轮;来源声明不证明人工批准'});
160
293
  // Tool replies travel on the same input lines, so they share the one limit.
161
- bridge=createHostToolBridge({responseLimit:parseHostInputLimit(inputLimitRaw)});
294
+ bridge=createHostToolBridge({responseLimit:parseHostInputLimit(inputLimitRaw),answerTimeoutMs:HOST_ANSWER_BACKSTOP_MS});
162
295
  // The current conversation transport accepts one outstanding host call.
163
296
  // Queue those calls only; member runners and independent Review stay concurrent.
164
297
  let hostCallTail=Promise.resolve();
@@ -167,17 +300,16 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
167
300
  hostCallTail=pending.then(()=>{},()=>{});return pending;
168
301
  }};
169
302
  let reconciling=false;
170
- const driver=createCmAiBatch({configuration:{...batch,...(externalModels?{externalModels}:{}),...(executionPolicy?{executionPolicy}:{})},logHome:path.join(batch.specsDir,'.reviews','host-log-mirror'),
303
+ const driver=createCmAiBatch({configuration:{...batch,...(controlPolicy?{controlPolicy}:{}),...(externalModels?{externalModels}:{}),...(executionPolicy?{executionPolicy}:{})},logHome:path.join(batch.specsDir,'.reviews','host-log-mirror'),
171
304
  runtime:runtime??'codex',checkCommands:(providerConfig??protection)?.checkCommands??null,checkTimeoutMs:(providerConfig??protection)?.timeoutMs??60000,
172
- rerunUnknownQa,rerunBlockedQa,holdRevisions:[...holds],bootstrapKeys:Object.keys(bootstraps??{}),
305
+ rerunUnknownQa,rerunBlockedQa,qaEnvironmentFailure,memberActions,holdRevisions:[...holds],bootstrapKeys:Object.keys(bootstraps??{}),
173
306
  executionFor:async(definition,{parallelMember=false}={})=>{
174
307
  await freezeBatchExecutionPolicy(batch,executionPolicy);
175
308
  freezeBatchExternalModels(batch,externalModels);
176
309
  const key=`${definition.feature}/${definition.identity.taskId}`;
177
- const attempts=[1,2].filter(attempt=>approvals.has(`${key}:${attempt}`));
178
- const memberReview=parallelMember?await memberReviewConfiguration(batch,definition,review,externalModels?routes.reviewerRuntime:runtime??'codex',externalModels?.providers[routes.reviewerRuntime]??null,!reconciling):review;
179
- const execution=createConversationExecution(definition,argv[4],parallelMember?memberBridge:bridge,memberReview,attempts,workflows[key],allowQa,runtime??'codex',
180
- {parallelMember,...(executionPolicy?{executionPolicy}:{}),...(externalModels?{externalModels,...(providerConfig?{reviewerRuntime:routes.reviewerRuntime}:{})}:{}),...(verificationPrecheck?{verificationPrecheck:true}:{}),batchWorkflowsDigest:digest(executionPolicy?{workflows,bootstraps,externalModels,executionPolicy}:externalModels?{workflows,bootstraps,externalModels}:bootstraps?{workflows,bootstraps}:workflows),qaLogHome:path.join(batch.specsDir,'.reviews','host-log-mirror'),
310
+ const memberReview=parallelMember?await memberReviewConfiguration(batch,definition,review,externalModels?routes.reviewerRuntime:runtime??'codex',externalModels?.providers[routes.reviewerRuntime]??null,!reconciling,Boolean(executionPolicy)):review;
311
+ const execution=createConversationExecution(definition,hostContextId,parallelMember?memberBridge:bridge,memberReview,null,workflows[key],allowQa,runtime??'codex',
312
+ {parallelMember,...(controlPolicy?{controlPolicy}:{}),...(executionPolicy?{executionPolicy}:{}),...(externalModels?{externalModels,...(providerConfig?{reviewerRuntime:routes.reviewerRuntime}:{})}:{}),...(verificationPrecheck?{verificationPrecheck:true}:{}),batchWorkflowsDigest:digest(executionPolicy?{workflows,bootstraps,externalModels,executionPolicy}:externalModels?{workflows,bootstraps,externalModels}:bootstraps?{workflows,bootstraps}:workflows),qaLogHome:path.join(batch.specsDir,'.reviews','host-log-mirror'),
181
313
  // A protected CLI config also protects unauthorized tasks: they stay on the
182
314
  // current-session transport but with the same sandbox checks (protected-text edits).
183
315
  ...(protection?{protection}:providerConfig?{protection:{checkCommands:providerConfig.checkCommands,timeoutMs:providerConfig.timeoutMs}}:{}),
@@ -190,13 +322,19 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
190
322
  return execution;
191
323
  }});
192
324
  const host={async handle(request){
193
- try{reconciling=request.operation==='reconcile_review';return await driver.handle(request);}catch(cause){return {outcome:'blocked',code:safeCode(cause)};}
325
+ try{
326
+ reconciling=request.operation==='reconcile_review';const result=await driver.handle(request);
327
+ if(controlPolicy&&request.operation==='status'&&result.state!=='running')
328
+ return {...result,controlTarget:await driver.controlTarget()};
329
+ return result;
330
+ }
331
+ catch(cause){const reason=boundedReason(cause);return {outcome:'blocked',code:safeCode(cause),...(reason?{reason}:{})};}
194
332
  }};
195
333
  const rawMode=input.isTTY&&typeof input.setRawMode==='function';if(rawMode)input.setRawMode(true);
196
334
  try{await serveHostTransport({host,input,output,toolBridge:bridge},inputLimitRaw);}
197
335
  finally{if(rawMode)input.setRawMode(false);}
198
336
  return 0;
199
- }catch(cause){const code=safeCode(cause);error.write(JSON.stringify({error:{code,...(['browser_capability_required','browser_capability_unavailable','invalid_arguments','review_configuration_required','protected_scope'].includes(code)
337
+ }catch(cause){const code=safeCode(cause);error.write(JSON.stringify({error:{code,...(['browser_capability_required','browser_capability_unavailable','invalid_arguments','review_configuration_required','protected_scope',...Object.keys(UNSUPPORTED_REASON)].includes(code)
200
338
  &&typeof cause.reason==='string'?{reason:cause.reason}:{}),...(code==='request_too_large'?{reason:inputLimitReason(cause.limit)}:{})}})+'\n');return 1;}
201
339
  finally{bridge?.close();}
202
340
  }