@aibyzero/cm-workflow 0.21.6 → 0.25.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 (212) hide show
  1. package/.codex-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +58 -0
  3. package/README.md +18 -3
  4. package/VERSION +1 -1
  5. package/docs/architecture.md +9 -0
  6. package/docs/cm-acceptance-completion.md +3 -1
  7. package/docs/cm-control-policy-v2.md +35 -3
  8. package/docs/execution-optimizations.md +1 -1
  9. package/docs/external-models.md +1 -0
  10. package/docs/human-correction.md +1 -1
  11. package/docs/installation.md +42 -16
  12. package/docs/js-workflow-control.md +65 -30
  13. package/docs/next-steps.md +10 -0
  14. package/docs/runtime-failover.md +5 -3
  15. package/docs/user-guide.md +6 -6
  16. package/package.json +1 -1
  17. package/runtime/js/cm-ai/batch-location.mjs +14 -0
  18. package/runtime/js/cm-ai/batch-plan.mjs +6 -2
  19. package/runtime/js/cm-ai/checkpoint-package-material.mjs +9 -2
  20. package/runtime/js/cm-ai/cm-ai-admission.mjs +9 -3
  21. package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +51 -8
  22. package/runtime/js/cm-ai/cm-ai-qa-log.mjs +30 -4
  23. package/runtime/js/cm-ai/codex-review-adapter.mjs +2 -4
  24. package/runtime/js/cm-ai/delivery-evidence.mjs +3 -1
  25. package/runtime/js/cm-ai/developer-adapter.mjs +15 -1
  26. package/runtime/js/cm-ai/drive-core.mjs +50 -6
  27. package/runtime/js/cm-ai/drive-next-step.mjs +61 -0
  28. package/runtime/js/cm-ai/durable-runner-state.mjs +85 -23
  29. package/runtime/js/cm-ai/execution-snapshot.mjs +5 -2
  30. package/runtime/js/cm-ai/execution-store.mjs +21 -3
  31. package/runtime/js/cm-ai/external-run-guard.mjs +9 -1
  32. package/runtime/js/cm-ai/host-check.mjs +4 -2
  33. package/runtime/js/cm-ai/host-conversation-execution.mjs +23 -2
  34. package/runtime/js/cm-ai/host-handoff.mjs +7 -0
  35. package/runtime/js/cm-ai/host-progress.mjs +18 -0
  36. package/runtime/js/cm-ai/host-qa-executor.mjs +47 -15
  37. package/runtime/js/cm-ai/host-qa-fix-owner.mjs +11 -2
  38. package/runtime/js/cm-ai/host-qa-policy.mjs +24 -14
  39. package/runtime/js/cm-ai/host-session.mjs +1 -1
  40. package/runtime/js/cm-ai/host-workflow-capabilities.mjs +1 -1
  41. package/runtime/js/cm-ai/host.mjs +1 -1
  42. package/runtime/js/cm-ai/operator-guidance.mjs +126 -2
  43. package/runtime/js/cm-ai/project-qa-gate.mjs +13 -2
  44. package/runtime/js/cm-ai/provider-review-observation.mjs +7 -3
  45. package/runtime/js/cm-ai/qa-plan-notes.mjs +106 -0
  46. package/runtime/js/cm-ai/review-continuation.mjs +102 -0
  47. package/runtime/js/cm-ai/review-evidence-file.mjs +11 -0
  48. package/runtime/js/cm-ai/review-package.mjs +25 -4
  49. package/runtime/js/cm-ai/review-presentation.mjs +31 -14
  50. package/runtime/js/cm-ai/review-runner.mjs +5 -4
  51. package/runtime/js/cm-ai/review-verdict-rules.mjs +7 -0
  52. package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +30 -1
  53. package/runtime/js/cm-ai/task-commit-codec.mjs +11 -1
  54. package/runtime/js/cm-ai/task-commit.mjs +7 -4
  55. package/runtime/js/cm-ai/task-owner.mjs +5 -2
  56. package/runtime/js/cm-ai/task-runner.mjs +343 -52
  57. package/runtime/js/cm-ai/tool-preview.mjs +6 -0
  58. package/runtime/js/cm-fix/diagnosis.mjs +16 -3
  59. package/runtime/js/cm-fix/execution.mjs +47 -9
  60. package/runtime/js/cm-fix/finish.mjs +9 -1
  61. package/runtime/js/cm-fix/step-timing.mjs +222 -0
  62. package/runtime/js/cm-idea/session.mjs +22 -3
  63. package/runtime/js/cm-init/review-evidence.mjs +20 -7
  64. package/runtime/js/cm-prd/ai-draft.mjs +260 -0
  65. package/runtime/js/cm-prd/analysis.mjs +27 -9
  66. package/runtime/js/cm-prd/change.mjs +29 -8
  67. package/runtime/js/cm-prd/failed-correction.mjs +24 -4
  68. package/runtime/js/cm-prd/narrow-review.mjs +63 -3
  69. package/runtime/js/cm-prd/review-correction.mjs +65 -5
  70. package/runtime/js/cm-prd/review-disposition.mjs +10 -1
  71. package/runtime/js/cm-prd/self-check.mjs +121 -9
  72. package/runtime/js/cm-prd/session.mjs +55 -13
  73. package/runtime/js/cm-prd/summary.mjs +34 -6
  74. package/runtime/js/cm-prd/task-scope-record.mjs +40 -15
  75. package/runtime/js/cm-refactor/records.mjs +82 -11
  76. package/runtime/js/cm-refactor/workflow.mjs +3 -1
  77. package/runtime/js/executor-version.mjs +81 -0
  78. package/runtime/js/python-log-writer.mjs +15 -0
  79. package/runtime/js/run-analysis.mjs +136 -11
  80. package/runtime/logging.md +6 -0
  81. package/runtime/review.md +3 -1
  82. package/runtime/workflow-config.md +1 -1
  83. package/scripts/ci-test-weights.json +1 -0
  84. package/scripts/cm-ai-admission.mjs +27 -1
  85. package/scripts/cm-ai-admission.test.mjs +34 -2
  86. package/scripts/cm-ai-answer-gap-recheck.test.mjs +3 -2
  87. package/scripts/cm-ai-batch-drive.mjs +54 -17
  88. package/scripts/cm-ai-batch-drive.test.mjs +123 -6
  89. package/scripts/cm-ai-batch-host.mjs +55 -9
  90. package/scripts/cm-ai-batch-host.test.mjs +22 -3
  91. package/scripts/cm-ai-batch-location.test.mjs +22 -1
  92. package/scripts/cm-ai-batch-merge.mjs +102 -0
  93. package/scripts/cm-ai-batch-plan.mjs +55 -2
  94. package/scripts/cm-ai-batch-plan.test.mjs +228 -6
  95. package/scripts/cm-ai-batch-run-fixture.mjs +239 -15
  96. package/scripts/cm-ai-batch-run-parallel.test.mjs +23 -1
  97. package/scripts/cm-ai-batch-run.mjs +435 -33
  98. package/scripts/cm-ai-batch-session-member.test.mjs +85 -0
  99. package/scripts/cm-ai-check-recheck-cancellation.test.mjs +23 -2
  100. package/scripts/cm-ai-checkpoint-package-material.test.mjs +28 -0
  101. package/scripts/cm-ai-completion-summary.test.mjs +2 -1
  102. package/scripts/cm-ai-control-v2-drive.test.mjs +39 -9
  103. package/scripts/cm-ai-direct-review.test.mjs +1 -1
  104. package/scripts/cm-ai-disk-edits.test.mjs +229 -0
  105. package/scripts/cm-ai-drive-next-step.test.mjs +191 -0
  106. package/scripts/cm-ai-drive.mjs +66 -14
  107. package/scripts/cm-ai-drive.test.mjs +13 -3
  108. package/scripts/cm-ai-host-cli-workflow.test.mjs +4 -2
  109. package/scripts/cm-ai-host.mjs +16 -8
  110. package/scripts/cm-ai-host.test.mjs +12 -0
  111. package/scripts/cm-ai-operator-guidance.test.mjs +132 -1
  112. package/scripts/cm-ai-project-qa-gate.test.mjs +26 -0
  113. package/scripts/cm-ai-qa-fix-cross-session.test.mjs +18 -0
  114. package/scripts/cm-ai-review-continuation.test.mjs +335 -0
  115. package/scripts/cm-ai-review-failure.test.mjs +13 -10
  116. package/scripts/cm-ai-review-timeout.test.mjs +1 -1
  117. package/scripts/cm-ai-run.mjs +42 -11
  118. package/scripts/cm-ai-run.test.mjs +26 -0
  119. package/scripts/cm-ai-supersede.test.mjs +10 -2
  120. package/scripts/cm-capability-gate.test.mjs +1 -1
  121. package/scripts/cm-check-runtime.sh +9 -0
  122. package/scripts/cm-codex-clean-env.test.mjs +40 -0
  123. package/scripts/cm-codex-prompt-input.test.mjs +2 -1
  124. package/scripts/cm-developer-self-review.test.mjs +27 -0
  125. package/scripts/cm-efficiency-presentation-delta.test.mjs +4 -3
  126. package/scripts/cm-efficiency-response.test.mjs +2 -1
  127. package/scripts/cm-executor-version-draft.test.mjs +251 -0
  128. package/scripts/cm-executor-version-entries.test.mjs +93 -0
  129. package/scripts/cm-executor-version-prd.test.mjs +154 -0
  130. package/scripts/cm-executor-version-records.test.mjs +256 -0
  131. package/scripts/cm-executor-version.test.mjs +250 -0
  132. package/scripts/cm-external-model-host.test.mjs +6 -1
  133. package/scripts/cm-external-review-reconciliation.test.mjs +1 -1
  134. package/scripts/cm-fix-closeout-preflight.test.mjs +123 -0
  135. package/scripts/cm-fix-diagnosis-module-correction.test.mjs +5 -1
  136. package/scripts/cm-fix-drive.mjs +7 -2
  137. package/scripts/cm-fix-drive.test.mjs +45 -0
  138. package/scripts/cm-fix-entry.mjs +5 -2
  139. package/scripts/cm-fix-frozen-baseline.test.mjs +50 -0
  140. package/scripts/cm-fix-host.mjs +9 -2
  141. package/scripts/cm-fix-test-extension.test.mjs +30 -2
  142. package/scripts/cm-host-check.test.mjs +12 -0
  143. package/scripts/cm-host-qa-executor.test.mjs +172 -1
  144. package/scripts/cm-host-qa-policy.test.mjs +55 -1
  145. package/scripts/cm-idea-drive.mjs +5 -2
  146. package/scripts/cm-idea-entry.mjs +5 -2
  147. package/scripts/cm-idea-host.mjs +3 -1
  148. package/scripts/cm-init-drive.mjs +8 -5
  149. package/scripts/cm-init-entry.mjs +5 -2
  150. package/scripts/cm-init-host.mjs +6 -2
  151. package/scripts/cm-log-event.mjs +10 -2
  152. package/scripts/cm-log-event.test.mjs +29 -0
  153. package/scripts/cm-prd-ai-draft-fixture.mjs +18 -0
  154. package/scripts/cm-prd-ai-draft.test.mjs +505 -0
  155. package/scripts/cm-prd-answer-gaps.test.mjs +110 -5
  156. package/scripts/cm-prd-completion.test.mjs +67 -4
  157. package/scripts/cm-prd-design-phase.test.mjs +48 -13
  158. package/scripts/cm-prd-drive.mjs +89 -20
  159. package/scripts/cm-prd-drive.test.mjs +109 -4
  160. package/scripts/cm-prd-entry.mjs +5 -2
  161. package/scripts/cm-prd-host.mjs +89 -20
  162. package/scripts/cm-prd-host.test.mjs +17 -8
  163. package/scripts/cm-prd-narrow-review.test.mjs +49 -1
  164. package/scripts/cm-prd-review-disposition.test.mjs +94 -1
  165. package/scripts/cm-prd-review-gate.mjs +11 -4
  166. package/scripts/cm-prd-self-check-rules.test.mjs +175 -10
  167. package/scripts/cm-prd-self-check.test.mjs +1 -1
  168. package/scripts/cm-refactor-drive.mjs +10 -4
  169. package/scripts/cm-refactor-entry.mjs +5 -2
  170. package/scripts/cm-refactor-host.mjs +3 -1
  171. package/scripts/cm-run-analysis.test.mjs +373 -1
  172. package/scripts/cm-runtime-i18n.mjs +3 -3
  173. package/scripts/cm-runtime-install.mjs +19 -10
  174. package/scripts/cm-runtime.mjs +2 -4
  175. package/scripts/cm-runtime.test.mjs +55 -13
  176. package/scripts/cm-skill-hints-autowire.test.mjs +1 -1
  177. package/scripts/cm-skill-hints-exam.mjs +3 -1
  178. package/scripts/cm-skill-hints-install.test.mjs +1 -1
  179. package/scripts/cm-skill-hints.mjs +106 -10
  180. package/scripts/cm-skill-hints.test.mjs +162 -6
  181. package/scripts/cm-skill-judge.mjs +2 -1
  182. package/scripts/cm-statusline.test.mjs +54 -0
  183. package/scripts/cm-task-gate.mjs +88 -18
  184. package/scripts/cm-task-scope.test.mjs +1 -1
  185. package/scripts/cm-test-drive.mjs +13 -8
  186. package/scripts/cm-test-entry.mjs +5 -2
  187. package/scripts/cm-test-host.mjs +3 -1
  188. package/scripts/cm-upgrade-compat-batch.test.mjs +62 -9
  189. package/scripts/fixtures/fresh-completion-checks.mjs +8 -0
  190. package/scripts/fixtures/prd-review-gate-python-oracle.py +9 -0
  191. package/scripts/policy-binding-compat.test.mjs +3 -2
  192. package/scripts/test-cm-prd-review-gate.py +25 -0
  193. package/skills/cm-ai/SKILL.md +1 -1
  194. package/skills/cm-ai/references/N1-init.md +4 -3
  195. package/skills/cm-ai/references/N4-review.md +6 -3
  196. package/skills/cm-ai/references/N6-qa-eval.md +3 -1
  197. package/skills/cm-ai/references/js-host-recovery.md +4 -1
  198. package/skills/cm-ai/references/js-host.md +25 -5
  199. package/skills/cm-fix/references/js-host.md +20 -0
  200. package/skills/cm-fix/references/test-extension.md +1 -1
  201. package/skills/cm-prd/SKILL.md +8 -6
  202. package/skills/cm-prd/references/ai-draft.md +81 -0
  203. package/skills/cm-prd/references/change-mode.md +2 -0
  204. package/skills/cm-prd/references/greenfield.md +2 -0
  205. package/skills/cm-prd/references/js-change-recovery.md +2 -2
  206. package/skills/cm-prd/references/js-host.md +9 -6
  207. package/skills/cm-prd/references/light-mode.md +19 -0
  208. package/skills/cm-prd/references/requirement-grilling.md +2 -0
  209. package/skills/cm-prd/references/spec-self-check.md +1 -0
  210. package/skills/cm-prd/references/summary-card.md +1 -0
  211. package/skills/cm-runtime/SKILL.md +6 -6
  212. package/templates/statusline/cm-statusline.sh +63 -1
@@ -19,12 +19,13 @@ import {validateHostWorkflowConfiguration,featureHasBrowserCases,readBrowserCapa
19
19
  import {digest,json,need,shape} from '../runtime/js/cm-ai/effect-contract.mjs';
20
20
  import {identifyApprovedBootstrapFeature} from '../runtime/js/cm-ai/bootstrap-feature.mjs';
21
21
  import {readControlPolicyFile} from '../runtime/js/cm-ai/control-policy.mjs';
22
+ import {EXECUTOR_REASON_CODES} from '../runtime/js/executor-version.mjs';
22
23
 
23
- 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]...';
24
+ 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] [--review-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]...';
24
25
  const safeCode=error=>typeof error?.code==='string'&&/^[a-z][a-z0-9_]{0,63}$/.test(error.code)?error.code:'batch_host_failed';
25
26
  // Operator-facing reasons the batch owner writes itself (R4); others stay redacted.
26
- const REASONED=new Set(['batch_resources_open','legacy_preflight_cache_invalid']);
27
- 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 REASONED=new Set(['batch_resources_open','tool_preflight_missing','legacy_preflight_cache_invalid','batch_qa_cadence_changed','batch_member_store_unreadable',...EXECUTOR_REASON_CODES]);
28
+ const boundedReason=error=>REASONED.has(error?.code)&&typeof error.reason==='string'&&Buffer.byteLength(error.reason,'utf8')<=8192&&!/[\r\n\0]/.test(error.reason)?error.reason:null;
28
29
  const actionFlags=new Map(Object.entries(BATCH_MEMBER_ACTIONS).map(([name,{flag}])=>[flag,name]));
29
30
  // Single-task recovery inputs a batch cannot take: each member's fingerprint binds
30
31
  // the whole batch workflow map, and a member cannot be rebound alone.
@@ -33,6 +34,20 @@ const UNSUPPORTED={'--revise-qa-config':'batch_qa_revision_unavailable','--qa-co
33
34
  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 原因 新建运行重做该任务',
34
35
  batch_spec_rebind_unavailable:'批次成员不能换绑规格。出口:还原这些规格改动并重新批准后继续本批次;或取消本批次,还原该任务已改动的代码后,用单任务宿主 cm-ai-host.mjs 以 --supersede-reviewed-evidence --supersede-reason 原因 新建运行重做该任务'};
35
36
 
37
+ // Which launch input picked a batch member's reviewer, for a tool_preflight_missing reason.
38
+ // --review-runtime (#302) is refused with --protected-config and --external-models, so those
39
+ // batches are never told to add it (Codex round 4).
40
+ export function batchReviewerNote({runtime,reviewRuntime,protectedBatch,externalModels}){
41
+ const host=runtime??'codex,未传时的缺省值';
42
+ if(protectedBatch&&externalModels)return '。本批次带 --protected-config 且已冻结外部模型:所有成员的审查端都是项目 roles 声明的审查方'
43
+ +'(上面已写明本成员实际是哪一端),这类批次不能用 --review-runtime';
44
+ if(protectedBatch)return '。本批次带 --protected-config:provider 开发的成员与 v2 provider 批次里由会话开发的成员,审查端是项目 roles 声明的审查方;'
45
+ +`legacy 受保护批次里其余由会话开发的成员,审查端是宿主 --runtime(本次 ${host})。上面已写明本成员实际是哪一端;受保护批次不能用 --review-runtime`;
46
+ if(externalModels)return `。本批次已冻结外部模型:审查端是宿主 --runtime(本次 ${host}),这类批次不能用 --review-runtime`;
47
+ if(reviewRuntime!==null)return `。本批次用 --review-runtime ${reviewRuntime} 选审查端:当前会话开发的成员由 ${reviewRuntime} 审查`;
48
+ return `。本批次没传 --review-runtime:当前会话开发的成员,审查端就是宿主 --runtime(本次 ${host});`
49
+ +'要由另一端审查,只能在新批次启动时加 --review-runtime(须与项目 roles 一致,不能与 --protected-config、--external-models 同用,开跑后不能补加或改值)';
50
+ }
36
51
  export async function serveHostTransport(options,rawInputLimit,serve=serveCmAiHost){
37
52
  return serve({...options,inputLimit:parseHostInputLimit(rawInputLimit)});
38
53
  }
@@ -178,6 +193,10 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
178
193
  const stat=fs.lstatSync(argv[2]);need(stat.isFile()&&!stat.isSymbolicLink()&&stat.size<=64*1024,'invalid_batch_config');
179
194
  const bundle=json(JSON.parse(fs.readFileSync(argv[2],'utf8')));shape(bundle,['batch','workflows',...(Object.hasOwn(bundle,'bootstraps')?['bootstraps']:[])]);
180
195
  const {batch,workflows,bootstraps=null}=bundle;need(Array.isArray(batch.tasks),'invalid_batch_config');
196
+ // reviewRuntime is added by this host from --review-runtime only; a bundle that carries it
197
+ // would bind a reviewer into the plan digest that no member actually uses.
198
+ if(Object.hasOwn(batch,'reviewRuntime'))throw Object.assign(new Error('invalid_arguments'),{code:'invalid_arguments',
199
+ reason:'批次配置文件不能写 reviewRuntime;审查端只用启动参数 --review-runtime 选择'});
181
200
  need(workflows!==null&&typeof workflows==='object'&&!Array.isArray(workflows),'invalid_batch_config');
182
201
  const keys=batch.tasks.map(task=>`${task.feature}/${task.taskId}`);
183
202
  // Grammar 3 execution table (batch-plan.mjs; validated again by createCmAiBatch): the
@@ -191,7 +210,7 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
191
210
  }
192
211
  need(keys.length===Object.keys(workflows).length&&keys.every(key=>Object.hasOwn(workflows,key)),'workflow_task_mismatch');
193
212
  for(const key of keys)if(workflows[key]!==null)validateHostWorkflowConfiguration(workflows[key]);
194
- let review=null,allowQa=false,allowBootstrap=false,runtime=null,protection=null,providerConfig=null,browserQaFlag,inputLimitRaw;
213
+ let review=null,allowQa=false,allowBootstrap=false,runtime=null,reviewRuntime=null,protection=null,providerConfig=null,browserQaFlag,inputLimitRaw;
195
214
  let rerunUnknownQa=false,rerunBlockedQa=false,verificationPrecheck=false,qaEnvironmentFailure=null;const developments=new Map(),holds=new Set();
196
215
  const memberActions=Object.fromEntries(Object.keys(BATCH_MEMBER_ACTIONS).map(name=>[name,[]]));
197
216
  let externalEnabled=false,externalFile,executionPolicyEnabled=false;
@@ -239,6 +258,9 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
239
258
  else if(name==='--runtime'){
240
259
  need(runtime===null&&['codex','claude'].includes(argv[index+1]),'invalid_runtime');runtime=argv[++index];
241
260
  }
261
+ else if(name==='--review-runtime'){
262
+ need(reviewRuntime===null&&['codex','claude'].includes(argv[index+1]),'invalid_runtime');reviewRuntime=argv[++index];
263
+ }
242
264
  else if(name==='--input-limit'){
243
265
  need(inputLimitRaw===undefined&&typeof argv[index+1]==='string','invalid_arguments');
244
266
  inputLimitRaw=argv[++index];parseHostInputLimit(inputLimitRaw);
@@ -265,7 +287,13 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
265
287
  if(!Object.hasOwn(bootstraps??{},keys[index])&&!fs.existsSync(path.join(batch.specsDir,'.reviews','.execution',batchTaskRunId(batch.batchId,keys[index]),'state.json')))
266
288
  try{assertCreatableScope(task.scope);}catch(cause){cause.reason=`${keys[index]}: ${cause.reason}`;throw cause;}
267
289
  const executionPolicy=readBatchExecutionPolicy({batch,started,enabled:executionPolicyEnabled});
268
- const routes=providerConfig?resolveProtectedRuntimes(loadConfig({projectRoot:batch.codeProject}),runtime??'codex'):{reviewerRuntime:runtime??'codex'};
290
+ // --review-runtime (same as the single-task host): the current session develops and
291
+ // the other declared tool reviews. Only for session-developed members; the provider
292
+ // and external-model routes pick their reviewer from roles. It is bound into every
293
+ // member configuration and the batch plan digest, so a batch resumes only with it.
294
+ if(reviewRuntime!==null&&(providerConfig||externalEnabled))throw Object.assign(new Error('invalid_arguments'),{code:'invalid_arguments',
295
+ reason:'--review-runtime 只用于当前会话开发的批次;--protected-config 与 --external-models 按 roles 自行选择审查端'});
296
+ const routes=providerConfig?resolveProtectedRuntimes(loadConfig({projectRoot:batch.codeProject}),runtime??'codex'):{reviewerRuntime:reviewRuntime??runtime??'codex'};
269
297
  const externalModels=readBatchExternalModels({batch,started,enabled:externalEnabled,inputFile:externalFile,providers:[routes.coderRuntime,routes.reviewerRuntime].filter(Boolean)});
270
298
  if(providerConfig&&!externalModels)shape(providerConfig,['model','checkCommands','timeoutMs']);
271
299
  if(providerConfig&&externalModels){
@@ -275,6 +303,17 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
275
303
  providerConfig={...providerConfig,...pair};
276
304
  }
277
305
  need(!sessionMembers.size||!externalModels&&!executionPolicy,'session_member_unsupported_config');
306
+ if(reviewRuntime!==null){
307
+ if(reviewRuntime===(runtime??'codex'))throw Object.assign(new Error('invalid_arguments'),{code:'invalid_arguments',
308
+ reason:`--review-runtime 只用于让另一工具审查;它和写代码方都是 ${reviewRuntime}。由当前工具全新上下文审查时省略 --review-runtime`});
309
+ if(externalModels)throw Object.assign(new Error('invalid_arguments'),{code:'invalid_arguments',
310
+ reason:'本批次已冻结外部模型,审查端按 roles 选择,不能再传 --review-runtime'});
311
+ const declared=resolveProtectedRuntimes(loadConfig({projectRoot:batch.codeProject}),runtime??'codex');
312
+ if(digest(declared)!==digest({coderRuntime:runtime??'codex',reviewerRuntime:reviewRuntime}))
313
+ throw Object.assign(new Error('runtime_selection_mismatch'),{code:'runtime_selection_mismatch',
314
+ reason:`项目声明写代码方 ${declared.coderRuntime}、审查方 ${declared.reviewerRuntime};本次是 --runtime ${runtime??'codex(缺省)'}、`
315
+ +`--review-runtime ${reviewRuntime}。按声明改参数,或先用 cm-runtime 改声明`});
316
+ }
278
317
  // A v2 provider batch: a session member's coder is this host, so it must be the
279
318
  // declared coder; it is reviewed by the declared reviewer like the provider members
280
319
  // (reviewRuntime), never by the host itself.
@@ -315,7 +354,7 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
315
354
  hostCallTail=pending.then(()=>{},()=>{});return pending;
316
355
  }};
317
356
  let reconciling=false;
318
- const driver=createCmAiBatch({configuration:{...batch,...(controlPolicy?{controlPolicy}:{}),...(externalModels?{externalModels}:{}),...(executionPolicy?{executionPolicy}:{})},logHome:path.join(batch.specsDir,'.reviews','host-log-mirror'),
357
+ const driver=createCmAiBatch({configuration:{...batch,...(controlPolicy?{controlPolicy}:{}),...(reviewRuntime!==null?{reviewRuntime}:{}),...(externalModels?{externalModels}:{}),...(executionPolicy?{executionPolicy}:{})},logHome:path.join(batch.specsDir,'.reviews','host-log-mirror'),
319
358
  runtime:runtime??'codex',checkCommands:(providerConfig??protection)?.checkCommands??null,checkTimeoutMs:(providerConfig??protection)?.timeoutMs??60000,
320
359
  rerunUnknownQa,rerunBlockedQa,qaEnvironmentFailure,memberActions,holdRevisions:[...holds],bootstrapKeys:Object.keys(bootstraps??{}),workflows,
321
360
  executionFor:async(definition,{parallelMember=false,soloMember=false}={})=>{
@@ -326,7 +365,7 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
326
365
  // declared one for a provider-developed member (the host runtime may be the coder
327
366
  // there), else the one this member always had (host runtime, or the external route).
328
367
  const memberReviewer=developments.has(key)?resolveProtectedRuntimes(loadConfig({projectRoot:definition.codeProject}),runtime??'codex').reviewerRuntime
329
- :externalModels?routes.reviewerRuntime:runtime??'codex';
368
+ :externalModels?routes.reviewerRuntime:reviewRuntime??runtime??'codex';
330
369
  const memberReview=parallelMember?await memberReviewConfiguration(batch,definition,review,memberReviewer,externalModels?.providers[routes.reviewerRuntime]??null,!reconciling,Boolean(executionPolicy)):review;
331
370
  const execution=createConversationExecution(definition,hostContextId,parallelMember?memberBridge:bridge,memberReview,null,workflows[key],allowQa,runtime??'codex',
332
371
  {parallelMember,...(soloMember?{soloMember}:{}),...(controlPolicy?{controlPolicy}:{}),...(executionPolicy?{executionPolicy}:{}),...(externalModels?{externalModels,...(providerConfig?{reviewerRuntime:routes.reviewerRuntime}:{})}:{}),...(verificationPrecheck?{verificationPrecheck:true}:{}),
@@ -334,6 +373,7 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
334
373
  batchWorkflowsDigest:digest(executionPolicy?{workflows,bootstraps,externalModels,executionPolicy}:externalModels?{workflows,bootstraps,externalModels}
335
374
  :Object.hasOwn(batch,'memberDevelopment')?{workflows,bootstraps,memberDevelopment:batch.memberDevelopment}:bootstraps?{workflows,bootstraps}:workflows),qaLogHome:path.join(batch.specsDir,'.reviews','host-log-mirror'),
336
375
  ...(sessionMembers.has(key)?{memberDevelopment:'session',...(sessionReviewRuntime!==null?{reviewRuntime:sessionReviewRuntime}:{})}:{}),
376
+ ...(reviewRuntime!==null?{reviewRuntime}:{}),
337
377
  // A protected CLI config also protects unauthorized tasks: they stay on the
338
378
  // current-session transport but with the same sandbox checks (protected-text edits).
339
379
  ...(protection?{protection}:providerConfig?{protection:{checkCommands:providerConfig.checkCommands,timeoutMs:providerConfig.timeoutMs}}:{}),
@@ -357,13 +397,19 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
357
397
  }
358
398
  return result;
359
399
  }
360
- catch(cause){const reason=boundedReason(cause);return {outcome:'blocked',code:safeCode(cause),...(reason?{reason}:{})};}
400
+ catch(cause){
401
+ // Appended before the bound check, so the whole reason stays one line within 8192 bytes.
402
+ const note=cause?.code==='tool_preflight_missing'&&typeof cause.reason==='string'
403
+ ?batchReviewerNote({runtime,reviewRuntime,protectedBatch:Boolean(providerConfig),externalModels:Boolean(externalModels)}):'';
404
+ const reason=boundedReason(note?{code:cause.code,reason:cause.reason+note}:cause);
405
+ return {outcome:'blocked',code:safeCode(cause),...(reason?{reason}:{})};
406
+ }
361
407
  }};
362
408
  const rawMode=input.isTTY&&typeof input.setRawMode==='function';if(rawMode)input.setRawMode(true);
363
409
  try{await serveHostTransport({host,input,output,toolBridge:bridge},inputLimitRaw);}
364
410
  finally{if(rawMode)input.setRawMode(false);}
365
411
  return 0;
366
- }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','session_coder_runtime_mismatch',...Object.keys(UNSUPPORTED_REASON)].includes(code)
412
+ }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','session_coder_runtime_mismatch','runtime_selection_mismatch',...Object.keys(UNSUPPORTED_REASON),...EXECUTOR_REASON_CODES].includes(code)
367
413
  &&typeof cause.reason==='string'?{reason:cause.reason}:{}),...(code==='request_too_large'?{reason:inputLimitReason(cause.limit)}:{})}})+'\n');return 1;}
368
414
  finally{bridge?.close();}
369
415
  }
@@ -60,7 +60,9 @@ function fixture(runtime='codex'){
60
60
  ...(runtime==='claude'?{provider:runtime}:{}),prompt_transport:'stdin',
61
61
  config_fingerprint:(runtime==='claude'?claudeReviewFingerprint:configFingerprint)({cwd:codeProject,model:'fixture'})}}));
62
62
  const fake=path.join(bin,runtime);fs.copyFileSync(fileURLToPath(new URL(`./fixtures/${runtime}-review-process.mjs`,import.meta.url)),fake);fs.chmodSync(fake,0o700);
63
- return {runtime,root,specsDir,codeProject,config,review,batch,env:{...process.env,PATH:bin+path.delimiter+process.env.PATH},
63
+ // The fixed call sequences below assume completion check reuse; an outer off switch must not leak in.
64
+ const env={...process.env,PATH:bin+path.delimiter+process.env.PATH};delete env.CM_AI_COMPLETION_CHECK_REUSE;
65
+ return {runtime,root,specsDir,codeProject,config,review,batch,env,
64
66
  args:['serve','--config',config,'--host-context','current-batch-host','--allow-development','--review-config',review,'--allow-qa',
65
67
  ...(runtime==='claude'?['--runtime','claude']:[])]};
66
68
  }
@@ -191,7 +193,8 @@ for(const runtime of ['codex','claude'])test(`${runtime} batch CLI preserves hel
191
193
  assert.equal(first.result.identity.taskId,'T-002');assert.equal(first.result.state,'changes_requested');
192
194
  assert.equal(first.result.identity.attempt,2);assert.equal(first.result.code,'revision_answer_required');
193
195
  assert(fs.readFileSync(path.join(f.specsDir,'1.work','tasks.md'),'utf8').includes('[ ] T-002'));
194
- assert.deepEqual(first.calls,['T-001:develop','T-001:check','T-001:check','T-001:qa_assess',
196
+ // A new run completes T-001 on its reviewed checks (completion check reuse): one check call.
197
+ assert.deepEqual(first.calls,['T-001:develop','T-001:check','T-001:qa_assess',
195
198
  'T-002:develop','T-002:documentation_sync','T-002:check']);
196
199
  const original=fs.readFileSync(f.config,'utf8'),changed=JSON.parse(original);
197
200
  changed.workflows['1.work/T-002'].documentationPaths=[];
@@ -206,7 +209,7 @@ for(const runtime of ['codex','claude'])test(`${runtime} batch CLI preserves hel
206
209
  }
207
210
  const second=await execute(f);assert.equal(second.code,0,second.stderr);
208
211
  assert.equal(second.result.state,'run_done',JSON.stringify(second.result));
209
- assert.deepEqual(second.calls,['T-002:develop','T-002:documentation_sync','T-002:check','T-002:check',
212
+ assert.deepEqual(second.calls,['T-002:develop','T-002:documentation_sync','T-002:check',
210
213
  'T-002:qa_assess','T-002:documentation_inspect']);
211
214
  const reopened=await execute(f);assert.equal(reopened.code,0,reopened.stderr);
212
215
  assert.equal(reopened.result.state,'run_done',JSON.stringify(reopened.result));
@@ -591,3 +594,19 @@ test('Q24 batch host recovers a serial member stopped at develop_redo and contin
591
594
  }finally{fs.rmSync(g.root,{recursive:true,force:true});}
592
595
  }finally{fs.rmSync(f.root,{recursive:true,force:true});}
593
596
  });
597
+
598
+ // Codex 第四轮:受保护批次与外部模型批次不能用 --review-runtime,说明不能让人去加它。
599
+ test('the tool_preflight_missing batch note names the input that picked the reviewer',async()=>{
600
+ const {batchReviewerNote}=await import('./cm-ai-batch-host.mjs');
601
+ const roles=batchReviewerNote({runtime:'codex',reviewRuntime:null,protectedBatch:true,externalModels:false});
602
+ assert.match(roles,/--protected-config.*项目 roles 声明的审查方/);assert.doesNotMatch(roles,/加 --review-runtime|cm-runtime/);
603
+ // Codex 第五轮:legacy 受保护批次里其余会话成员由宿主 --runtime 审;外部模型恢复时可不带旗标。
604
+ assert.match(roles,/legacy.*其余.*宿主 --runtime(本次 codex)/);
605
+ const external=batchReviewerNote({runtime:'claude',reviewRuntime:null,protectedBatch:false,externalModels:true});
606
+ assert.match(external,/已冻结外部模型.*宿主 --runtime(本次 claude).*不能用 --review-runtime/);assert.doesNotMatch(external,/加 --review-runtime|带 --external-models/);
607
+ // Codex 第六轮:受保护且冻结外部模型时,所有成员都按 roles 审查,不再说 legacy 会话成员由宿主审。
608
+ const both=batchReviewerNote({runtime:'codex',reviewRuntime:null,protectedBatch:true,externalModels:true});
609
+ assert.match(both,/--protected-config.*已冻结外部模型.*所有成员.*项目 roles 声明的审查方/);assert.doesNotMatch(both,/宿主 --runtime(本次/);
610
+ assert.match(batchReviewerNote({runtime:'claude',reviewRuntime:'codex',protectedBatch:false,externalModels:false}),/--review-runtime codex.*由 codex 审查/);
611
+ assert.match(batchReviewerNote({runtime:null,reviewRuntime:null,protectedBatch:false,externalModels:false}),/没传 --review-runtime.*宿主 --runtime(本次 codex,未传时的缺省值).*新批次启动时加 --review-runtime/);
612
+ });
@@ -6,7 +6,8 @@ import assert from 'node:assert/strict';
6
6
  import fs from 'node:fs';
7
7
  import os from 'node:os';
8
8
  import path from 'node:path';
9
- import {BATCH_SEGMENT_FIELD,batchSegment,batchSegments,batchMemberWorktree,batchMemberBranch} from '../runtime/js/cm-ai/batch-location.mjs';
9
+ import {BATCH_SEGMENT_FIELD,batchSegment,batchSegments,batchMemberWorktree,batchMemberBranch,batchQaCadence} from '../runtime/js/cm-ai/batch-location.mjs';
10
+ import {soloQaBase} from '../runtime/js/cm-ai/batch-plan.mjs';
10
11
 
11
12
  function specs(t,rows=[]){
12
13
  const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-batch-location-')));
@@ -55,3 +56,23 @@ test('the segment is a safe single path component and ref component',()=>{
55
56
  for(const id of ['a','a.b.c.d.e.f.g.h','....----','batch_2026.10.23-x'])
56
57
  assert.match(batchSegment(id),/^[A-Za-z0-9_-]{1,8}-[a-f0-9]{12}$/,id);
57
58
  });
59
+
60
+ // Reviews q2/q3: one N6 count per batch. batch_start fixes it; before that, a member run an
61
+ // older host already initialized (e.g. by a status call) keeps the batch on the old count.
62
+ test('the batch QA cadence: batch_start first, then members already initialized',t=>{
63
+ const specsDir=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-batch-cadence-')));
64
+ t.after(()=>fs.rmSync(specsDir,{recursive:true,force:true}));
65
+ const log=path.join(specsDir,'运行日志.jsonl');
66
+ const snapshots={};const read=runId=>snapshots[runId]??null;
67
+ const cadence=()=>batchQaCadence({specsDir,batchId:'batch-cadence',runIds:['m1','m2'],readSnapshot:read});
68
+ assert.equal(cadence(),'feature-v1');
69
+ snapshots.m1={records:[]};assert.equal(cadence(),'feature-v1','an empty store froze nothing');
70
+ snapshots.m2={records:[{payload:{config:{qaCadence:'feature-v1'}}}]};assert.equal(cadence(),'feature-v1');
71
+ snapshots.m1={records:[{payload:{config:{}}}]};assert.equal(cadence(),'legacy');
72
+ const start={workflow:'cm-ai',event:'decision',phase:'batch_start',run_id:'batch-cadence'};
73
+ fs.writeFileSync(log,JSON.stringify({...start,qa_cadence:'feature-v1'})+'\n');
74
+ assert.equal(cadence(),'feature-v1','batch_start decides once written');
75
+ fs.writeFileSync(log,JSON.stringify(start)+'\n');delete snapshots.m1;
76
+ assert.equal(cadence(),'legacy');
77
+ assert.throws(()=>soloQaBase({specsDir,codeProject:specsDir,feature:'1.work',repositoryId:'r',qaCadence:'other'}),{code:'invalid_input'});
78
+ });
@@ -0,0 +1,102 @@
1
+ // Git evidence for merge-before-complete batches. The coordinator owns journaling
2
+ // and the N5 capability. This module only checks and prepares Git images.
3
+ import fs from 'node:fs';
4
+ import path from 'node:path';
5
+ import {randomUUID} from 'node:crypto';
6
+ import {spawnSync} from 'node:child_process';
7
+ import {need} from '../runtime/js/cm-ai/effect-contract.mjs';
8
+
9
+ export const gitOid=value=>typeof value==='string'&&/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/.test(value);
10
+ const sorted=items=>[...items].sort();
11
+ const gitEntry=(git,repo,tree,name)=>git(repo,['--literal-pathspecs','ls-tree','-z',tree,'--',name]);
12
+ const fileMode=mode=>mode&0o100?'100755':'100644';
13
+ function blobEntry(repo,name,mode,bytes,options,code){
14
+ const hash=spawnSync('git',['-C',repo,'hash-object','--stdin'],{...options,input:bytes});
15
+ need(hash.status===0&&gitOid(hash.stdout.trim()),code);
16
+ return `${mode} blob ${hash.stdout.trim()}\t${name}\0`;
17
+ }
18
+ const diffPaths=(git,repo,from,to)=>git(repo,['diff','--no-renames','--name-only','-z',from,to]).split('\0').filter(Boolean);
19
+
20
+ export function verifyStagedDelivery(git,repo,base,tree,changes,options){
21
+ need(JSON.stringify(sorted(diffPaths(git,repo,base,tree)))===JSON.stringify(sorted(changes.map(item=>item.path))),
22
+ 'batch_member_delivery_changed');
23
+ for(const {path:name,after} of changes){
24
+ if(after===null)continue;
25
+ const link=after.type==='symlink';
26
+ const mode=link?'120000':fileMode(after.mode);
27
+ const bytes=link?Buffer.from(after.target):Buffer.from(after.contentBase64,'base64');
28
+ const code='batch_member_delivery_changed';
29
+ need(gitEntry(git,repo,tree,name)===blobEntry(repo,name,mode,bytes,options,code),code);
30
+ }
31
+ }
32
+
33
+ export function verifyIntegratedTree(git,repo,intent,tree,{allowUnion=false}={}){
34
+ const changed=diffPaths(git,repo,intent.member_base,intent.member_commit);
35
+ const integrated=diffPaths(git,repo,intent.expected_old,tree);
36
+ need(integrated.every(name=>changed.includes(name)),'batch_merge_delivery_changed');
37
+ const entry=(ref,name)=>gitEntry(git,repo,ref,name);
38
+ for(const name of changed){
39
+ const merged=entry(tree,name),member=entry(intent.member_commit,name);
40
+ if(merged===member)continue;
41
+ // Git's configured union driver is allowed to combine the two reviewed
42
+ // instruction files. Freeze that index tree before letting Git commit it.
43
+ need(allowUnion&&name.split('/').at(-1)==='AGENTS.md'&&merged&&member
44
+ &&entry(intent.expected_old,name)!==entry(intent.member_base,name),'batch_merge_delivery_changed');
45
+ }
46
+ }
47
+
48
+ // Git status may hide paths with skip-worktree or assume-unchanged set.
49
+ export function verifyCheckoutDelivery(git,repo,base,tree,options,code,expectedTree=tree){
50
+ for(const name of diffPaths(git,repo,base,tree)){
51
+ const file=path.resolve(repo,name),parent=path.dirname(file);
52
+ need(file.startsWith(repo+path.sep),code);
53
+ const expected=gitEntry(git,repo,expectedTree,name);
54
+ let stat;
55
+ try{stat=fs.lstatSync(file);}catch(error){if(error.code!=='ENOENT')throw error;}
56
+ if(!stat){need(!expected,code);continue;}
57
+ need(fs.realpathSync(parent)===parent&&(stat.isFile()||stat.isSymbolicLink()),code);
58
+ const mode=stat.isSymbolicLink()?'120000':fileMode(stat.mode);
59
+ const bytes=stat.isSymbolicLink()?fs.readlinkSync(file,{encoding:'buffer'}):fs.readFileSync(file);
60
+ need(expected===blobEntry(repo,name,mode,bytes,options,code),code);
61
+ }
62
+ }
63
+
64
+ export function mergeHead(git,repo){
65
+ const file=git(repo,['rev-parse','--path-format=absolute','--git-path','MERGE_HEAD']);
66
+ return fs.existsSync(file)?fs.readFileSync(file,'utf8').trim():null;
67
+ }
68
+
69
+ const unionSuffix=Buffer.from('\nAGENTS.md merge=union\n');
70
+ const attributesPath=(git,repo)=>git(repo,['rev-parse','--path-format=absolute','--git-path','info/attributes']);
71
+ function attributeBytes(target){
72
+ let stat;
73
+ try{stat=fs.lstatSync(target);}catch(error){if(error.code==='ENOENT')return null;throw error;}
74
+ need(stat.isFile()&&!stat.isSymbolicLink()&&stat.nlink===1&&stat.size<=8192,'batch_attributes_invalid');
75
+ return fs.readFileSync(target);
76
+ }
77
+ export const readBatchAttributes=(git,repo)=>attributeBytes(attributesPath(git,repo))?.toString('base64')??null;
78
+ function replaceAttributes(target,bytes){
79
+ if(bytes===null){fs.unlinkSync(target);return;}
80
+ fs.mkdirSync(path.dirname(target),{recursive:true});
81
+ // The temporary is private and has no meaning to Git if the process dies.
82
+ const temporary=path.join(path.dirname(target),`cm-attributes-${randomUUID()}`);
83
+ try{
84
+ const mode=fs.existsSync(target)?fs.statSync(target).mode&0o777:0o644;
85
+ const fd=fs.openSync(temporary,'wx',mode);
86
+ try{fs.writeFileSync(fd,bytes);fs.fsyncSync(fd);}finally{fs.closeSync(fd);}
87
+ fs.renameSync(temporary,target);
88
+ }finally{if(fs.existsSync(temporary))fs.unlinkSync(temporary);}
89
+ }
90
+
91
+ export function batchUnionAttributes(git,repo,saved,{install=false}={}){
92
+ need(saved===null||typeof saved==='string'&&saved.length<=11000
93
+ &&Buffer.from(saved,'base64').toString('base64')===saved,'batch_history_invalid');
94
+ const target=attributesPath(git,repo),before=saved===null?null:Buffer.from(saved,'base64');
95
+ const after=Buffer.concat([before??Buffer.alloc(0),unionSuffix]),current=attributeBytes(target);
96
+ if(current?.equals(after)){
97
+ if(!install)replaceAttributes(target,before);
98
+ return;
99
+ }
100
+ need(current===null&&before===null||current?.equals(before??Buffer.alloc(0))&&before!==null,'batch_attributes_changed');
101
+ if(install)replaceAttributes(target,after);
102
+ }
@@ -27,6 +27,60 @@ function parse(argv){
27
27
  }
28
28
  return ['specsDir','codeProject','repositoryId','batchId'].every(key=>typeof input[key]==='string')?input:null;
29
29
  }
30
+ // A config error says what is wrong instead of a bare code (2026-12-01 probe). Parser messages
31
+ // interpolate key names, field paths, file paths and file text, so a message is shown only when
32
+ // it matches, whole, one of the parser's fixed templates below (Codex rounds 1-5: every
33
+ // cut-and-replace scheme leaked). Field paths in "must be …" templates come from validateRaw,
34
+ // which rejects unknown keys first; credential checks run earlier on raw keys, so their
35
+ // location is never shown. Anything else is named by category only.
36
+ const CONTROL=/[\x00-\x1f\x7f-\x9f\u061c\u200b-\u200f\u2028-\u202e\u2060-\u2069\ufeff]+/g;
37
+ const FIXED=new Set(['unclosed quote or inline collection','empty scalar is not allowed','unterminated quoted scalar',
38
+ 'mapping key cannot be empty','mapping keys must be strings','tabs are not allowed for indentation','configuration is empty',
39
+ 'root indentation must be zero','configuration nesting is too deep','expected an indented mapping or list','unexpected indentation',
40
+ 'mixed mapping and list','empty list item',"expected 'key: value'",'unexpected content','invalid JSON: unterminated string',
41
+ 'invalid JSON: object key must be a string',"invalid JSON: expected ':'","invalid JSON: expected ',' or '}'","invalid JSON: expected ',' or ']'",
42
+ 'configuration must be a regular file','file exceeds configuration size limit','secret-like value is forbidden',
43
+ 'configuration contains a secret-like value','user.runtimes.available conflicts with user.preset','configuration text must be a string',
44
+ 'roles.external_expert must use adapter external-browser and source browser','policies.tests includes browser but roles.browser_qa.adapter is not browser',
45
+ 'invalid_runtime','runtime_not_declared','cross_runtime_review_required']);
46
+ const FIELD='(?:config|user|project|roles|policies|parallel|runtimes|preset)(?:\\.[a-z_]{1,32}){0,4}';
47
+ const TEMPLATES=[/^invalid JSON near byte \d+$/,/^configuration(?: text)? exceeds \d+ bytes$/,
48
+ new RegExp(`^${FIELD} (?:must be a mapping|must be a non-empty string|contains unsupported characters|must be boolean|must equal integer 1|must be an integer from 1 to 4|must be a non-empty list(?: of logic/commands/browser)?|contains an unsupported test kind|must be one of: [A-Za-z0-9_.-]+(?:, [A-Za-z0-9_.-]+)*)$`),
49
+ /^multiple CM workflow configs found: \.cm-workflow\.(?:yml|yaml|json)(?:, \.cm-workflow\.(?:yml|yaml|json))+$/,
50
+ /^(?:config\.)?roles\.[a-z_]{1,32}\.(?:adapter cannot be external-browser; only external_expert may use (?:the external browser|it)|adapter browser is reserved for browser_qa|source browser is reserved for external_expert)$/,
51
+ /^roles\.[a-z_]{1,32}\.adapter [a-z-]{1,32} needs the [a-z]{1,16} runtime, but runtimes\.available declares [a-z]{1,16}$/,
52
+ /^roles\.coder and roles\.reviewer both resolve to [a-z]{1,16}; with runtimes\.available both, review must run on the other runtime$/];
53
+ // Fixed heads whose tail is file text: the head names the kind of error.
54
+ const HEADS=['invalid inline mapping item','invalid quoted scalar','unsupported YAML feature','invalid JSON'];
55
+ export function redactConfigMessage(raw){
56
+ let message=String(raw).replace(CONTROL,' ').trim(),head='';
57
+ for(let prefix;(prefix=/^(?:runtimes\.yml|user\.runtimes|line \d{1,7}): /.exec(message));){head+=prefix[0];message=message.slice(prefix[0].length);}
58
+ if(FIXED.has(message)||TEMPLATES.some(template=>template.test(message)))return head+message;
59
+ // Only two parser messages carry a path, each at a fixed place (Codex round 7: scanning every
60
+ // ": " let an unknown key dressed as "<path>: <safe sentence>" through). In the batch plan a
61
+ // message that starts with an absolute path is readConfigText on the user-level runtimes.yml.
62
+ const oversized=/^configuration file exceeds (\d+) bytes: /.exec(message);
63
+ if(oversized)return `${head}项目配置文件 configuration file exceeds ${oversized[1]} bytes(路径不回显)`;
64
+ if(/^(?:\/|[A-Za-z]:\\)(?:.*?[\/\\])?runtimes\.yml: /.test(message)){
65
+ const tail=/: (configuration must be a regular file|configuration exceeds \d+ bytes)$/.exec(message);
66
+ return tail?`${head}用户级 runtimes.yml: ${tail[1]}`:`${head}用户级 runtimes.yml 读取失败(路径与系统原文不回显)`;
67
+ }
68
+ // "user.runtimes: " wraps only the lstat failure of the user-level file (loadUserRuntimes).
69
+ if(head.endsWith('user.runtimes: '))return `${head}用户级 runtimes.yml 读取失败(路径与系统原文不回显)`;
70
+ const unknown=new RegExp(`^(${FIELD}) has unknown field\\(s\\): `).exec(message);
71
+ if(unknown)return `${head}${unknown[1]} has unknown field(s)(字段名不回显)`;
72
+ if(/: (?:credential fields|secret-like values) are forbidden$/.test(message))return '有凭证字段名或疑似密钥的值(位置不回显)';
73
+ if(/^duplicate (?:JSON object )?key "/.test(message))return `${head}有重复的键(键名不回显)`;
74
+ if(/^missing value for "/.test(message))return `${head}缺少值(键名不回显)`;
75
+ const kind=HEADS.find(name=>message.startsWith(`${name}: `));
76
+ return head+(kind?`${kind}(原文不回显)`:'配置格式或字段不合法(原文含用户写的内容,不回显)');
77
+ }
78
+ function planFailureReason(error){
79
+ if(typeof error?.reason==='string')return {reason:error.reason};
80
+ if(error instanceof SyntaxError)return {reason:'--workflow-config 文件不是合法 JSON;改正后重新运行 cm-ai-batch-plan'};
81
+ if(error?.name!=='ConfigError'||typeof error.message!=='string')return {};
82
+ return {reason:`项目工作流配置无效:${redactConfigMessage(error.message)}。检查代码根的 .cm-workflow.yml(或 .yaml/.json)与用户级 ~/.cm-workflow/runtimes.yml,改正后重新运行 cm-ai-batch-plan`};
83
+ }
30
84
  export function main(argv=process.argv.slice(2)){
31
85
  if(argv.length===1&&['--help','-h'].includes(argv[0])){process.stdout.write(usage+'\n');return 0;}
32
86
  const input=parse(argv);
@@ -41,8 +95,7 @@ export function main(argv=process.argv.slice(2)){
41
95
  const plan=planCmAiBatch({specsDir,codeProject,repositoryId:input.repositoryId,batchId:input.batchId,settings,workflow});
42
96
  process.stdout.write(JSON.stringify(plan)+'\n');return 0;
43
97
  }catch(error){
44
- process.stderr.write(JSON.stringify({error:{code:error.code??'batch_plan_failed',
45
- ...(typeof error.reason==='string'?{reason:error.reason}:{})}})+'\n');return 1;
98
+ process.stderr.write(JSON.stringify({error:{code:error.code??'batch_plan_failed',...planFailureReason(error)}})+'\n');return 1;
46
99
  }
47
100
  }
48
101
  function isMain(entry){