@aibyzero/cm-workflow 0.16.9 → 0.17.1
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.
- package/.codex-plugin/plugin.json +1 -1
- package/AGENTS.md +4 -0
- package/CHANGELOG.md +18 -1
- package/CONTRIBUTING.md +47 -0
- package/README.md +16 -1
- package/VERSION +1 -1
- package/docs/architecture.md +29 -13
- package/docs/cm-control-policy-v2.md +331 -0
- package/docs/execution-optimizations.md +1 -1
- package/docs/external-models.md +3 -3
- package/docs/fixes/20261013-claude-preinit-ui-invalidate.md +48 -0
- package/docs/human-correction.md +5 -5
- package/docs/installation.md +1 -1
- package/docs/js-workflow-control.md +104 -85
- package/docs/next-steps.md +11 -0
- package/docs/untested-branches.md +2 -3
- package/docs/user-guide.md +3 -3
- package/package.json +1 -1
- package/runtime/js/cm-ai/claude-review-stream.mjs +12 -8
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +13 -69
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +10 -5
- package/runtime/js/cm-ai/control-policy.mjs +112 -0
- package/runtime/js/cm-ai/drive-bootstrap.mjs +11 -8
- package/runtime/js/cm-ai/drive-core.mjs +124 -25
- package/runtime/js/cm-ai/durable-runner-state.mjs +32 -126
- package/runtime/js/cm-ai/gate-bridge.mjs +4 -4
- package/runtime/js/cm-ai/host-check.mjs +3 -1
- package/runtime/js/cm-ai/host-conversation-execution.mjs +22 -20
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +11 -2
- package/runtime/js/cm-ai/host-qa-policy.mjs +63 -21
- package/runtime/js/cm-ai/host-review-authority.mjs +2 -2
- package/runtime/js/cm-ai/host-review-file.mjs +1 -1
- package/runtime/js/cm-ai/host-session.mjs +41 -8
- package/runtime/js/cm-ai/host-stage-observer.mjs +26 -0
- package/runtime/js/cm-ai/host-tool-bridge.mjs +25 -9
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +21 -10
- package/runtime/js/cm-ai/host.mjs +1 -2
- package/runtime/js/cm-ai/operator-guidance.mjs +57 -54
- package/runtime/js/cm-ai/review-package.mjs +16 -4
- package/runtime/js/cm-ai/reviewed-deliveries.mjs +1 -1
- package/runtime/js/cm-ai/task-runner.mjs +41 -101
- package/runtime/js/cm-init/review-evidence.mjs +3 -1
- package/runtime/js/cm-prd/review-host.mjs +1 -1
- package/runtime/js/cm-prd/review-publication.mjs +5 -3
- package/runtime/js/cm-prd/summary.mjs +27 -12
- package/runtime/js/cm-refactor/workflow.mjs +1 -1
- package/runtime/js/notify-send.mjs +15 -14
- package/runtime/js/notify.mjs +27 -4
- package/runtime/js/policy-binding-compat.mjs +2 -1
- package/runtime/review.md +61 -7
- package/runtime/task-gates.md +107 -9
- package/scripts/cm-ai-abandon-effect-position.test.mjs +1 -8
- package/scripts/cm-ai-answer-gap-driver.test.mjs +12 -12
- package/scripts/cm-ai-answer-gap-fixture.mjs +1 -8
- package/scripts/cm-ai-batch-drive.mjs +50 -31
- package/scripts/cm-ai-batch-drive.test.mjs +62 -19
- package/scripts/cm-ai-batch-host.mjs +39 -20
- package/scripts/cm-ai-batch-host.test.mjs +83 -47
- package/scripts/cm-ai-batch-run-fixture.mjs +6 -53
- package/scripts/cm-ai-batch-run-member-stops.test.mjs +0 -12
- package/scripts/cm-ai-batch-run.mjs +46 -14
- package/scripts/cm-ai-bootstrap-flow.test.mjs +1 -7
- package/scripts/cm-ai-bootstrap.test.mjs +2 -3
- package/scripts/cm-ai-control-launch.test.mjs +219 -0
- package/scripts/cm-ai-control-policy.test.mjs +192 -0
- package/scripts/cm-ai-control-v2-drive.test.mjs +270 -0
- package/scripts/cm-ai-develop-answer-invalid.test.mjs +1 -8
- package/scripts/cm-ai-develop-call-timeout.test.mjs +1 -8
- package/scripts/cm-ai-develop-driver-gaps.test.mjs +33 -20
- package/scripts/cm-ai-direct-review.test.mjs +348 -0
- package/scripts/cm-ai-documentation-sync-gap.test.mjs +3 -3
- package/scripts/cm-ai-drive-bootstrap-rules.test.mjs +57 -27
- package/scripts/cm-ai-drive.mjs +96 -54
- package/scripts/cm-ai-drive.test.mjs +46 -87
- package/scripts/cm-ai-fix-integration.test.mjs +3 -5
- package/scripts/cm-ai-fix-later-delivery.test.mjs +3 -6
- package/scripts/cm-ai-fix-run-delivery.test.mjs +3 -6
- package/scripts/cm-ai-host-cli-workflow.test.mjs +6 -10
- package/scripts/cm-ai-host-fixture.mjs +47 -16
- package/scripts/cm-ai-host-protected.test.mjs +35 -33
- package/scripts/cm-ai-host.mjs +103 -93
- package/scripts/cm-ai-host.test.mjs +34 -18
- package/scripts/cm-ai-launch-diagnostics.test.mjs +5 -3
- package/scripts/cm-ai-legacy-history.test.mjs +53 -0
- package/scripts/cm-ai-light-modules.test.mjs +4 -7
- package/scripts/cm-ai-multi-root.test.mjs +4 -4
- package/scripts/cm-ai-nested-execution.test.mjs +16 -19
- package/scripts/cm-ai-operator-guidance.test.mjs +56 -0
- package/scripts/cm-ai-progress.test.mjs +10 -8
- package/scripts/cm-ai-project-qa-gate.test.mjs +37 -10
- package/scripts/cm-ai-protected-scope.test.mjs +1 -2
- package/scripts/cm-ai-qa-config-revision.test.mjs +1 -9
- package/scripts/cm-ai-qa-fingerprint-config.test.mjs +12 -9
- package/scripts/cm-ai-qa-fix-cross-session.test.mjs +18 -3
- package/scripts/cm-ai-qa-fixed-log.test.mjs +41 -0
- package/scripts/cm-ai-qa-recovery-args.test.mjs +7 -0
- package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +3 -4
- package/scripts/cm-ai-review-drift-precedence.test.mjs +1 -1
- package/scripts/cm-ai-review-failure.test.mjs +13 -19
- package/scripts/cm-ai-review-timeout-config.test.mjs +3 -1
- package/scripts/cm-ai-review-timeout.test.mjs +35 -128
- package/scripts/cm-ai-run.mjs +78 -24
- package/scripts/cm-ai-run.test.mjs +11 -38
- package/scripts/cm-ai-selection-guard.test.mjs +2 -2
- package/scripts/cm-ai-session-chain.test.mjs +18 -15
- package/scripts/cm-ai-spec-rebind.test.mjs +14 -18
- package/scripts/cm-ai-supersede.test.mjs +3 -10
- package/scripts/cm-blocked-reason.test.mjs +2 -3
- package/scripts/cm-capability-gate.test.mjs +33 -1
- package/scripts/cm-check-drive-files.mjs +1 -1
- package/scripts/cm-check-host.test.mjs +1 -1
- package/scripts/cm-check-runtime.sh +1 -1
- package/scripts/cm-claude-probe.test.mjs +26 -0
- package/scripts/cm-claude-review-stream.test.mjs +36 -0
- package/scripts/cm-claude-worker.test.mjs +21 -3
- package/scripts/cm-controlled-correction.test.mjs +469 -0
- package/scripts/cm-drive-liveness.test.mjs +83 -0
- package/scripts/cm-external-batch-host.test.mjs +38 -17
- package/scripts/cm-external-model-host.test.mjs +1 -1
- package/scripts/cm-external-model-recovery.test.mjs +3 -9
- package/scripts/cm-external-qa-fix.test.mjs +1 -1
- package/scripts/cm-external-review-reconciliation.test.mjs +6 -24
- package/scripts/cm-fix-review-recovery.test.mjs +1 -1
- package/scripts/cm-host-diagnostic.test.mjs +33 -0
- package/scripts/cm-host-liveness.test.mjs +150 -0
- package/scripts/cm-host-qa-executor.test.mjs +1 -2
- package/scripts/cm-host-qa-policy.test.mjs +43 -16
- package/scripts/cm-host-review-authority.test.mjs +0 -31
- package/scripts/cm-host-stage-observer.test.mjs +41 -0
- package/scripts/cm-knowledge-closeout.test.mjs +3 -3
- package/scripts/cm-notify-command.test.mjs +54 -18
- package/scripts/cm-notify-read-drift.test.mjs +69 -4
- package/scripts/cm-notify.mjs +16 -4
- package/scripts/cm-notify.test.mjs +135 -29
- package/scripts/cm-patrol.test.mjs +3 -2
- package/scripts/cm-prd-drive.test.mjs +1 -1
- package/scripts/cm-prd-self-check-revision.test.mjs +15 -0
- package/scripts/cm-prd-session-recovery.test.mjs +5 -3
- package/scripts/cm-prd-summary.test.mjs +31 -0
- package/scripts/cm-release-smoke.sh +2 -14
- package/scripts/cm-task-gate-correction.test.mjs +69 -16
- package/scripts/cm-task-gate.mjs +368 -34
- package/scripts/cm-task-gate.py +2 -0
- package/scripts/cm-task-gate.test.mjs +252 -4
- package/scripts/cm-test-suite.mjs +109 -0
- package/scripts/cm-test-suite.test.mjs +162 -0
- package/scripts/fixtures/bootstrap-review-runner.mjs +1 -7
- package/scripts/fixtures/host-diagnostic.mjs +33 -0
- package/scripts/fixtures/native-gate-fixture.mjs +18 -0
- package/scripts/policy-binding-compat.test.mjs +4 -0
- package/skills/cm-ai/SKILL.md +8 -6
- package/skills/cm-ai/references/N3-execute-task.md +17 -2
- package/skills/cm-ai/references/N4-review.md +11 -21
- package/skills/cm-ai/references/N5-mark-done.md +1 -1
- package/skills/cm-ai/references/N6-qa-eval.md +49 -21
- package/skills/cm-ai/references/js-host-modes.md +35 -14
- package/skills/cm-ai/references/js-host-qa-recovery.md +60 -12
- package/skills/cm-ai/references/js-host-recovery.md +95 -47
- package/skills/cm-ai/references/js-host.md +98 -29
- package/skills/cm-fix/SKILL.md +12 -0
- package/skills/cm-init/references/js-host.md +1 -1
- package/skills/cm-prd/references/js-host.md +1 -1
- package/skills/cm-refactor/SKILL.md +12 -0
- package/runtime/js/cm-ai/review-dispatch-limits.mjs +0 -18
- package/scripts/cm-ai-review-dispatch-exit.test.mjs +0 -475
|
@@ -17,8 +17,9 @@ import {serveCmAiHost,parseHostInputLimit,inputLimitReason} from '../runtime/js/
|
|
|
17
17
|
import {validateHostWorkflowConfiguration,featureHasBrowserCases,readBrowserCapability} from '../runtime/js/cm-ai/host-workflow-capabilities.mjs';
|
|
18
18
|
import {digest,json,need,shape} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
19
19
|
import {identifyApprovedBootstrapFeature} from '../runtime/js/cm-ai/bootstrap-feature.mjs';
|
|
20
|
+
import {readControlPolicyFile} from '../runtime/js/cm-ai/control-policy.mjs';
|
|
20
21
|
|
|
21
|
-
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-
|
|
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]...';
|
|
22
23
|
const safeCode=error=>typeof error?.code==='string'&&/^[a-z][a-z0-9_]{0,63}$/.test(error.code)?error.code:'batch_host_failed';
|
|
23
24
|
// Operator-facing reasons the batch owner writes itself (R4); others stay redacted.
|
|
24
25
|
const REASONED=new Set(['batch_resources_open','legacy_preflight_cache_invalid']);
|
|
@@ -155,13 +156,24 @@ async function memberReviewConfiguration(batch,definition,review,runtime,pair=nu
|
|
|
155
156
|
}
|
|
156
157
|
|
|
157
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');
|
|
158
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');
|
|
159
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');
|
|
160
|
-
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
|
|
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;}
|
|
161
163
|
let bridge;
|
|
162
164
|
try{
|
|
163
|
-
|
|
164
|
-
|
|
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];
|
|
165
177
|
const stat=fs.lstatSync(argv[2]);need(stat.isFile()&&!stat.isSymbolicLink()&&stat.size<=64*1024,'invalid_batch_config');
|
|
166
178
|
const bundle=json(JSON.parse(fs.readFileSync(argv[2],'utf8')));shape(bundle,['batch','workflows',...(Object.hasOwn(bundle,'bootstraps')?['bootstraps']:[])]);
|
|
167
179
|
const {batch,workflows,bootstraps=null}=bundle;need(Array.isArray(batch.tasks),'invalid_batch_config');
|
|
@@ -176,10 +188,10 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
176
188
|
need(keys.length===Object.keys(workflows).length&&keys.every(key=>Object.hasOwn(workflows,key)),'workflow_task_mismatch');
|
|
177
189
|
for(const key of keys)if(workflows[key]!==null)validateHostWorkflowConfiguration(workflows[key]);
|
|
178
190
|
let review=null,allowQa=false,allowBootstrap=false,runtime=null,protection=null,providerConfig=null,browserQaFlag,inputLimitRaw;
|
|
179
|
-
let rerunUnknownQa=false,rerunBlockedQa=false,verificationPrecheck=false,qaEnvironmentFailure=null;const
|
|
191
|
+
let rerunUnknownQa=false,rerunBlockedQa=false,verificationPrecheck=false,qaEnvironmentFailure=null;const developments=new Map(),holds=new Set();
|
|
180
192
|
const memberActions=Object.fromEntries(Object.keys(BATCH_MEMBER_ACTIONS).map(name=>[name,[]]));
|
|
181
193
|
let externalEnabled=false,externalFile,executionPolicyEnabled=false;
|
|
182
|
-
for(let index=6;index<argv.length;index++){
|
|
194
|
+
for(let index=controlPolicy?controlOffset+2:6;index<argv.length;index++){
|
|
183
195
|
const name=argv[index];
|
|
184
196
|
if(name==='--execution-optimizations'){need(!executionPolicyEnabled,'invalid_arguments');executionPolicyEnabled=true;}
|
|
185
197
|
else if(name==='--allow-qa'){need(!allowQa,'invalid_arguments');allowQa=true;}
|
|
@@ -231,11 +243,15 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
231
243
|
else if(name==='--hold-revision'){
|
|
232
244
|
const held=argv[++index];need(typeof held==='string'&&keys.includes(held)&&!holds.has(held),'invalid_arguments');holds.add(held);
|
|
233
245
|
}
|
|
234
|
-
else
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
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');
|
|
239
255
|
}
|
|
240
256
|
const started=keys.some(key=>fs.existsSync(path.join(batch.specsDir,'.reviews','.execution',batchTaskRunId(batch.batchId,key),'state.json')));
|
|
241
257
|
// Same read-only create gate as the batch owner, before any model or policy configuration is read or frozen.
|
|
@@ -256,16 +272,15 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
256
272
|
need(!developments.size||providerConfig!==null,'protected_configuration_required');
|
|
257
273
|
// Same launch-time assertion as the single-task host, evaluated across every
|
|
258
274
|
// task whose approved contract can select a browser case.
|
|
259
|
-
readBrowserCapability(browserQaFlag,keys.flatMap(key=>workflows[key]?.qa!=null
|
|
275
|
+
readBrowserCapability(browserQaFlag,keys.flatMap(key=>(!controlPolicy||allowQa)&&workflows[key]?.qa!=null
|
|
260
276
|
&&featureHasBrowserCases(batch.specsDir,key.slice(0,key.lastIndexOf('/')),batch.codeProject)
|
|
261
277
|
?[workflows[key].qa.environment?.carrier??'browser']:[]));
|
|
262
|
-
need(!approvals.size||review!==null,'review_configuration_required');
|
|
263
278
|
// Same two guards as the single-task host. A batch has no --mode, so the
|
|
264
279
|
// per-task resume check lives in createCmAiBatch rather than here.
|
|
265
280
|
need(!(rerunUnknownQa&&rerunBlockedQa),'qa_recovery_authorization_required');
|
|
266
281
|
need(!(rerunUnknownQa||rerunBlockedQa)||allowQa,'qa_recovery_authorization_required');
|
|
267
282
|
need(qaEnvironmentFailure===null||rerunUnknownQa||rerunBlockedQa,'qa_recovery_authorization_required');
|
|
268
|
-
need(allowQa||!Object.values(workflows).some(item=>item?.qa!=null),'qa_authorization_required');
|
|
283
|
+
need(controlPolicy||allowQa||!Object.values(workflows).some(item=>item?.qa!=null),'qa_authorization_required');
|
|
269
284
|
// Same rule as single-task create: the reviewer binding is part of every
|
|
270
285
|
// member's durable fingerprint and cannot be added on resume. A batch none
|
|
271
286
|
// of whose member runs exist yet is being created. Batches that already
|
|
@@ -274,7 +289,7 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
274
289
|
batchTaskRunId(batch.batchId,key),'state.json')));
|
|
275
290
|
if(!created&&review===null)throw Object.assign(new Error('review_configuration_required'),{code:'review_configuration_required',
|
|
276
291
|
reason:'新批次必须带 --review-config:审查配置写进每个任务运行的指纹,恢复时不能再补。先用 cm-ai-host.mjs preflight 生成 review.json;'
|
|
277
|
-
+'
|
|
292
|
+
+'普通 advance 按已有审查配置派发第 1、2 轮;来源声明不证明人工批准'});
|
|
278
293
|
// Tool replies travel on the same input lines, so they share the one limit.
|
|
279
294
|
bridge=createHostToolBridge({responseLimit:parseHostInputLimit(inputLimitRaw),answerTimeoutMs:HOST_ANSWER_BACKSTOP_MS});
|
|
280
295
|
// The current conversation transport accepts one outstanding host call.
|
|
@@ -285,17 +300,16 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
285
300
|
hostCallTail=pending.then(()=>{},()=>{});return pending;
|
|
286
301
|
}};
|
|
287
302
|
let reconciling=false;
|
|
288
|
-
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'),
|
|
289
304
|
runtime:runtime??'codex',checkCommands:(providerConfig??protection)?.checkCommands??null,checkTimeoutMs:(providerConfig??protection)?.timeoutMs??60000,
|
|
290
305
|
rerunUnknownQa,rerunBlockedQa,qaEnvironmentFailure,memberActions,holdRevisions:[...holds],bootstrapKeys:Object.keys(bootstraps??{}),
|
|
291
306
|
executionFor:async(definition,{parallelMember=false}={})=>{
|
|
292
307
|
await freezeBatchExecutionPolicy(batch,executionPolicy);
|
|
293
308
|
freezeBatchExternalModels(batch,externalModels);
|
|
294
309
|
const key=`${definition.feature}/${definition.identity.taskId}`;
|
|
295
|
-
const attempts=[1,2].filter(attempt=>approvals.has(`${key}:${attempt}`));
|
|
296
310
|
const memberReview=parallelMember?await memberReviewConfiguration(batch,definition,review,externalModels?routes.reviewerRuntime:runtime??'codex',externalModels?.providers[routes.reviewerRuntime]??null,!reconciling,Boolean(executionPolicy)):review;
|
|
297
|
-
const execution=createConversationExecution(definition,
|
|
298
|
-
{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'),
|
|
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'),
|
|
299
313
|
// A protected CLI config also protects unauthorized tasks: they stay on the
|
|
300
314
|
// current-session transport but with the same sandbox checks (protected-text edits).
|
|
301
315
|
...(protection?{protection}:providerConfig?{protection:{checkCommands:providerConfig.checkCommands,timeoutMs:providerConfig.timeoutMs}}:{}),
|
|
@@ -308,7 +322,12 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
308
322
|
return execution;
|
|
309
323
|
}});
|
|
310
324
|
const host={async handle(request){
|
|
311
|
-
try{
|
|
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
|
+
}
|
|
312
331
|
catch(cause){const reason=boundedReason(cause);return {outcome:'blocked',code:safeCode(cause),...(reason?{reason}:{})};}
|
|
313
332
|
}};
|
|
314
333
|
const rawMode=input.isTTY&&typeof input.setRawMode==='function';if(rawMode)input.setRawMode(true);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {hostDiagnostic} from './fixtures/host-diagnostic.mjs';
|
|
1
2
|
import test from 'node:test';
|
|
2
3
|
import assert from 'node:assert/strict';
|
|
3
4
|
import fs from 'node:fs';
|
|
@@ -66,35 +67,57 @@ function fixture(runtime='codex'){
|
|
|
66
67
|
// operations are sent one after another (each after the previous reply); the
|
|
67
68
|
// session closes after the last. failDevelop: task ids whose next develop
|
|
68
69
|
// answer is a bare failure after the session wrote (develop_answer_missing).
|
|
69
|
-
|
|
70
|
+
// Use an actual first-round review finding for a launch-only revision pause.
|
|
71
|
+
// The synthetic native process still emits its normal bound review observation.
|
|
72
|
+
function requestFirstRevision(f,taskIds,nativeFile=path.join(f.root,'bin',f.runtime)){
|
|
73
|
+
const fake=nativeFile;
|
|
74
|
+
const first=`${JSON.stringify(taskIds)}.includes(data.reviewPackage.identity.taskId)&&data.reviewPackage.identity.attempt===1`;
|
|
75
|
+
const source=fs.readFileSync(fake,'utf8');
|
|
76
|
+
assert(source.includes("verdict:'approved'")&&source.includes('findings:[]'),'native review fixture must retain its known response fields');
|
|
77
|
+
fs.writeFileSync(fake,source
|
|
78
|
+
.replace("verdict:'approved'",`verdict:(${first})?'changes_requested':'approved'`)
|
|
79
|
+
.replace('findings:[]',`findings:(${first})?[{id:'F1',severity:'P2',path:'task'+Number(data.reviewPackage.identity.taskId.slice(-1))+'.mjs',message:'Recheck the export in a revision',evidence:'Synthetic first-round review finding'}]:[]`));
|
|
80
|
+
return taskIds.flatMap(taskId=>['--hold-revision',`1.work/${taskId}`]);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function execute(f,{cancel=false,args=[],operations=[{operation:'advance',requestId:'advance'}],failDevelop=new Set()}={}){
|
|
70
84
|
return new Promise((resolve,reject)=>{
|
|
71
|
-
const child=spawn(process.execPath,[cli,...f.args,...args
|
|
85
|
+
const child=spawn(process.execPath,[cli,...f.args,...args],
|
|
72
86
|
{env:f.env,stdio:['pipe','pipe','pipe']});
|
|
73
|
-
let buffer='',stderr='',sessionId;const calls=[],rows=[];
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
87
|
+
let buffer='',stderr='',sessionId;const calls=[],rows=[],pendingControls=new Set();
|
|
88
|
+
let finalOperationReceived=false,closeRequested=false;
|
|
89
|
+
// Cancellation can finish the original advance before its status/cancel
|
|
90
|
+
// handlers return. Await those replies before requesting an idle close.
|
|
91
|
+
const closeWhenIdle=()=>{
|
|
92
|
+
if(finalOperationReceived&&pendingControls.size===0&&!closeRequested){
|
|
93
|
+
closeRequested=true;send({type:'host_close',sessionId});
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
const timeoutMs=Number(process.env.CM_TEST_FIXTURE_TIMEOUT_MS??60000),trace=hostDiagnostic(child,{timeoutMs});
|
|
97
|
+
const timer=setTimeout(()=>{child.kill('SIGTERM');reject(trace.attach(Error('batch host timeout')));},timeoutMs);
|
|
98
|
+
child.stderr.on('data',part=>{stderr+=part;});child.once('error',error=>reject(trace.attach(error)));
|
|
99
|
+
const send=value=>{trace.send(value);child.stdin.write(JSON.stringify(value)+'\n');};
|
|
77
100
|
const respond=(row,result)=>send({type:'host_result',sessionId:row.sessionId,callId:row.callId,requestDigest:row.requestDigest,result});
|
|
78
101
|
child.stdout.on('data',part=>{
|
|
79
102
|
buffer+=part;let newline;
|
|
80
103
|
while((newline=buffer.indexOf('\n'))!==-1){
|
|
81
104
|
const line=buffer.slice(0,newline);buffer=buffer.slice(newline+1);if(!line)continue;
|
|
82
105
|
try{
|
|
83
|
-
const row=JSON.parse(line);rows.push(row);
|
|
106
|
+
const row=JSON.parse(line);rows.push(row);trace.receive(row);
|
|
84
107
|
if(row.type==='host_ready')sessionId=row.sessionId;
|
|
85
108
|
if(row.type==='host_request'){
|
|
86
109
|
const payload=row.payload,identity=payload.identity??payload.request.identity;
|
|
87
110
|
const cwd=f.parallel&&identity.taskId!=='T-003'
|
|
88
111
|
?path.join(f.root,'.cm-worktrees',f.batch.batchId.slice(0,8),identity.taskId):f.codeProject;
|
|
89
112
|
calls.push(`${identity.taskId}:${row.kind}`);
|
|
90
|
-
if(cancel){send({operation:'status',requestId:'status'});send({operation:'cancel',requestId:'cancel'});continue;}
|
|
113
|
+
if(cancel){pendingControls.add('status');pendingControls.add('cancel');send({operation:'status',requestId:'status'});send({operation:'cancel',requestId:'cancel'});continue;}
|
|
91
114
|
if(row.kind==='develop'){
|
|
92
115
|
assert.equal(payload.request.provider,f.runtime);
|
|
93
116
|
const n=Number(identity.taskId.slice(-1));
|
|
94
117
|
assert.deepEqual(payload.request.payload.scope,f.batch.tasks[n-1].scope);
|
|
95
118
|
assert.equal(payload.request.payload.specification.task.id,identity.taskId);
|
|
96
119
|
assert.deepEqual(payload.request.payload.specification.sources,buildManifest(f.specsDir));
|
|
97
|
-
const content=`export const value = ${40+n};\n`;
|
|
120
|
+
const content=`export const value = ${40+n};\n${identity.attempt===2?"// Revised after the independent review finding.\n":""}`;
|
|
98
121
|
if(!f.protected)fs.writeFileSync(path.join(cwd,`task${n}.mjs`),content);
|
|
99
122
|
if(failDevelop.delete(identity.taskId)){respond(row,{status:'failed',code:'session_error'});continue;}
|
|
100
123
|
respond(row,{status:'succeeded',value:{outcome:'implemented',application:{status:'no_relevant_lesson',note:null},
|
|
@@ -107,8 +130,7 @@ function execute(f,approvals,{cancel=false,args=[],operations=[{operation:'advan
|
|
|
107
130
|
const result=spawnSync(command[0],command.slice(1));assert.equal(result.status,0);
|
|
108
131
|
return {id:'syntax',command,outcome:'passed',exitCode:0,evidence:'Actual Node syntax check exited 0'};
|
|
109
132
|
});respond(row,checks);
|
|
110
|
-
}else if(row.kind==='qa_assess')respond(row,{
|
|
111
|
-
changes:{api:false,migration:false,authentication:false,authorization:false,payment:false}});
|
|
133
|
+
}else if(row.kind==='qa_assess')respond(row,{confirmed:true});
|
|
112
134
|
else if(row.kind==='documentation_sync'){
|
|
113
135
|
assert.equal(identity.taskId,'T-002');assert.deepEqual(payload.paths,['README.md']);
|
|
114
136
|
fs.writeFileSync(path.join(f.codeProject,'README.md'),'# Exports 41 and 42\n');respond(row,{status:'completed'});
|
|
@@ -121,12 +143,14 @@ function execute(f,approvals,{cancel=false,args=[],operations=[{operation:'advan
|
|
|
121
143
|
}
|
|
122
144
|
const index=operations.findIndex(item=>item.requestId===row.requestId);
|
|
123
145
|
if(index>=0&&(row.result||row.error)){
|
|
124
|
-
if(index+1<operations.length)send(operations[index+1]);else
|
|
146
|
+
if(index+1<operations.length)send(operations[index+1]);else finalOperationReceived=true;
|
|
125
147
|
}
|
|
126
|
-
|
|
148
|
+
if(row.result||row.error)pendingControls.delete(row.requestId);
|
|
149
|
+
closeWhenIdle();
|
|
150
|
+
}catch(error){clearTimeout(timer);child.kill('SIGTERM');reject(trace.attach(error));}
|
|
127
151
|
}
|
|
128
152
|
});
|
|
129
|
-
child.once('close',code=>{clearTimeout(timer);resolve({code,stderr,calls,rows,
|
|
153
|
+
child.once('close',code=>{clearTimeout(timer);resolve({code,stderr,calls,rows,diagnostic:trace.snapshot(),
|
|
130
154
|
results:Object.fromEntries(operations.map(item=>[item.requestId,rows.find(row=>row.requestId===item.requestId)?.result])),
|
|
131
155
|
result:rows.find(row=>row.requestId===operations.at(-1).requestId)?.result});});
|
|
132
156
|
send(operations[0]);
|
|
@@ -147,55 +171,65 @@ test('protected Claude batch uses actual sandbox edits/checks and original two-t
|
|
|
147
171
|
fs.writeFileSync(protection,JSON.stringify({timeoutMs:5000,checkCommands:[{id:'syntax',command:[process.execPath,'-e',
|
|
148
172
|
"const fs=require('node:fs'),a=require('node:assert/strict');a.throws(()=>fs.writeFileSync('specs/1.work/tasks.md','bad'));a.throws(()=>fs.writeFileSync('AGENTS.md','bad'));for(const p of fs.readdirSync('.').filter(p=>/^task.*mjs$/.test(p)))a.match(fs.readFileSync(p,'utf8'),/export const value = 4[12];/);"]}]}));
|
|
149
173
|
f.args.push('--protected-conversation-config',protection);
|
|
150
|
-
const result=await execute(f
|
|
174
|
+
const result=await execute(f);
|
|
151
175
|
assert.equal(result.code,0,result.stderr);assert.equal(result.result.state,'run_done',JSON.stringify(result.result));
|
|
152
176
|
assert.deepEqual(result.calls,['T-001:develop','T-001:qa_assess','T-002:develop','T-002:qa_assess','T-002:documentation_inspect']);
|
|
153
177
|
assert.equal(fs.readFileSync(path.join(nested,'1.work/tasks.md'),'utf8').match(/\[x\]/g).length,2);
|
|
154
|
-
const resume=await execute(f
|
|
178
|
+
const resume=await execute(f);assert.equal(resume.result.state,'run_done');assert.deepEqual(resume.calls,['T-002:documentation_inspect']);
|
|
155
179
|
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
156
180
|
});
|
|
157
181
|
|
|
158
|
-
for(const runtime of ['codex','claude'])test(`${runtime} batch CLI preserves
|
|
182
|
+
for(const runtime of ['codex','claude'])test(`${runtime} batch CLI preserves held review revisions and reaches one original run_done without duplicate completion`,async()=>{
|
|
159
183
|
const f=fixture(runtime);
|
|
160
184
|
try{
|
|
161
|
-
const
|
|
162
|
-
|
|
185
|
+
const bundle=JSON.parse(fs.readFileSync(f.config,'utf8'));
|
|
186
|
+
bundle.workflows['1.work/T-001'].qa.criticalPaths={payment:['task1.mjs']};
|
|
187
|
+
fs.writeFileSync(f.config,JSON.stringify(bundle));
|
|
188
|
+
const held=requestFirstRevision(f,['T-002']);
|
|
189
|
+
const first=await execute(f,{args:held});assert.equal(first.code,0,first.stderr);
|
|
190
|
+
assert.equal(first.result.identity.taskId,'T-002');assert.equal(first.result.state,'changes_requested');
|
|
191
|
+
assert.equal(first.result.identity.attempt,2);assert.equal(first.result.code,'revision_answer_required');
|
|
163
192
|
assert(fs.readFileSync(path.join(f.specsDir,'1.work','tasks.md'),'utf8').includes('[ ] T-002'));
|
|
164
193
|
assert.deepEqual(first.calls,['T-001:develop','T-001:check','T-001:check','T-001:qa_assess',
|
|
165
194
|
'T-002:develop','T-002:documentation_sync','T-002:check']);
|
|
166
195
|
const original=fs.readFileSync(f.config,'utf8'),changed=JSON.parse(original);
|
|
167
196
|
changed.workflows['1.work/T-002'].documentationPaths=[];
|
|
168
197
|
fs.writeFileSync(f.config,JSON.stringify(changed));
|
|
169
|
-
const drift=await execute(f
|
|
198
|
+
const drift=await execute(f);
|
|
170
199
|
assert.equal(drift.result.outcome,'blocked');assert.deepEqual(drift.calls,[]);
|
|
171
200
|
fs.writeFileSync(f.config,original);
|
|
172
201
|
if(runtime==='claude'){
|
|
173
202
|
const saved=[...f.args];f.args[f.args.length-1]='codex';
|
|
174
|
-
const wrongRuntime=await execute(f
|
|
203
|
+
const wrongRuntime=await execute(f);assert.equal(wrongRuntime.result.outcome,'blocked');
|
|
175
204
|
assert.deepEqual(wrongRuntime.calls,[]);f.args=saved;
|
|
176
205
|
}
|
|
177
|
-
const second=await execute(f
|
|
206
|
+
const second=await execute(f);assert.equal(second.code,0,second.stderr);
|
|
178
207
|
assert.equal(second.result.state,'run_done',JSON.stringify(second.result));
|
|
179
|
-
assert.deepEqual(second.calls,['T-002:
|
|
180
|
-
|
|
208
|
+
assert.deepEqual(second.calls,['T-002:develop','T-002:documentation_sync','T-002:check','T-002:check',
|
|
209
|
+
'T-002:qa_assess','T-002:documentation_inspect']);
|
|
210
|
+
const reopened=await execute(f);assert.equal(reopened.code,0,reopened.stderr);
|
|
181
211
|
assert.equal(reopened.result.state,'run_done',JSON.stringify(reopened.result));
|
|
182
212
|
assert.deepEqual(reopened.calls,['T-002:documentation_inspect']);
|
|
183
213
|
const rows=fs.readFileSync(path.join(f.specsDir,'运行日志.jsonl'),'utf8').trim().split('\n').map(JSON.parse);
|
|
184
214
|
assert.equal(rows.filter(row=>row.event==='run_done').length,1);
|
|
185
215
|
assert.equal(rows.filter(row=>row.event==='decision'&&row.phase==='batch_handoff').length,1);
|
|
186
216
|
assert.equal(rows.filter(row=>row.event==='test_run'&&row.phase==='start').length,2);
|
|
217
|
+
const taskQa=rows.filter(row=>row.event==='qa'&&row.task==='T-001');
|
|
218
|
+
assert.equal(taskQa.length,1);
|
|
219
|
+
assert.equal(taskQa[0].status,'triggered');
|
|
220
|
+
assert(taskQa[0].reason.split(',').includes('payment'));
|
|
221
|
+
assert.equal(taskQa[0].score,null);
|
|
222
|
+
assert.equal(taskQa[0].changed_files_source,'review_package');
|
|
187
223
|
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
188
224
|
});
|
|
189
225
|
|
|
190
|
-
for(const runtime of ['codex','claude'])test(`${runtime} batch CLI cancellation remains durable
|
|
226
|
+
for(const runtime of ['codex','claude'])test(`${runtime} batch CLI cancellation remains durable`,async()=>{
|
|
191
227
|
const f=fixture(runtime);
|
|
192
228
|
try{
|
|
193
|
-
const
|
|
194
|
-
assert.equal(bad.status,1);assert(bad.stderr.includes('review_task_mismatch'));assert(!fs.existsSync(path.join(f.specsDir,'.reviews')));
|
|
195
|
-
const stopped=await execute(f,[],{cancel:true});assert.equal(stopped.code,0,stopped.stderr);
|
|
229
|
+
const stopped=await execute(f,{cancel:true});assert.equal(stopped.code,0,stopped.stderr);
|
|
196
230
|
assert.equal(stopped.result.code,'cancelled');assert.equal(stopped.calls.length,1);
|
|
197
231
|
assert(stopped.rows.some(row=>row.requestId==='status'));
|
|
198
|
-
const reopened=await execute(f
|
|
232
|
+
const reopened=await execute(f);assert.equal(reopened.result.code,'cancelled');assert.deepEqual(reopened.calls,[]);
|
|
199
233
|
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
200
234
|
});
|
|
201
235
|
|
|
@@ -214,11 +248,12 @@ test('parallel member loopback preflights bind worktree cwd, stop before start a
|
|
|
214
248
|
git(['add','-A']);git(['commit','--allow-empty','-m','synthetic baseline']);
|
|
215
249
|
const log=path.join(f.root,'probe-cwds.jsonl'),fail=path.join(f.root,'fail-probe');
|
|
216
250
|
fs.writeFileSync(fail,'fail second member');
|
|
217
|
-
const processFixture=
|
|
251
|
+
const processFixture=path.join(f.root,'native-review-process.mjs');
|
|
252
|
+
fs.copyFileSync(fileURLToPath(new URL('./fixtures/codex-review-process.mjs',import.meta.url)),processFixture);
|
|
218
253
|
fs.writeFileSync(path.join(f.root,'bin','codex'),`#!${process.execPath}
|
|
219
254
|
const fs=require('node:fs'),cp=require('node:child_process');
|
|
220
255
|
const args=process.argv.slice(2),cwd=args[args.indexOf('--cd')+1];
|
|
221
|
-
fs.appendFileSync(${JSON.stringify(log)},JSON.stringify(cwd)+'\\n');
|
|
256
|
+
if(args.includes('model_provider="cm_local_tool_preview"'))fs.appendFileSync(${JSON.stringify(log)},JSON.stringify(cwd)+'\\n');
|
|
222
257
|
if(cwd.endsWith('T-002')&&fs.existsSync(${JSON.stringify(fail)}))process.exit(1);
|
|
223
258
|
let input='';process.stdin.on('data',part=>input+=part);process.stdin.on('end',()=>{
|
|
224
259
|
const result=cp.spawnSync(process.execPath,[${JSON.stringify(processFixture)},...args],{input,encoding:'utf8'});
|
|
@@ -226,12 +261,13 @@ let input='';process.stdin.on('data',part=>input+=part);process.stdin.on('end',(
|
|
|
226
261
|
});
|
|
227
262
|
`,{mode:0o700});
|
|
228
263
|
const probes=()=>fs.readFileSync(log,'utf8').trim().split('\n').map(JSON.parse);
|
|
229
|
-
const failed=await execute(f
|
|
264
|
+
const failed=await execute(f);
|
|
230
265
|
assert.equal(failed.result.code,'review_preflight_failed',JSON.stringify(failed));
|
|
231
266
|
assert.equal(failed.result.currentTask,'1.work/T-002');assert.deepEqual(failed.calls,[]);
|
|
232
267
|
assert.equal(probes().length,2);
|
|
233
268
|
fs.unlinkSync(fail);
|
|
234
|
-
const
|
|
269
|
+
const held=requestFirstRevision(f,['T-001','T-002'],processFixture);
|
|
270
|
+
const first=await execute(f,{args:held});assert.equal(first.result.code,'revision_answer_required',JSON.stringify(first));
|
|
235
271
|
assert.equal(first.calls.filter(call=>call.endsWith(':develop')).length,2,JSON.stringify(first));
|
|
236
272
|
const directory=path.join(f.specsDir,'.reviews','.execution',f.batch.batchId);
|
|
237
273
|
const receipts=[1,2].map(n=>fs.readFileSync(path.join(directory,`preflight-T-00${n}.json`),'utf8'));
|
|
@@ -243,12 +279,12 @@ let input='';process.stdin.on('data',part=>input+=part);process.stdin.on('end',(
|
|
|
243
279
|
assert(probes().includes(cwd));
|
|
244
280
|
}
|
|
245
281
|
assert.equal(probes().length,3);
|
|
246
|
-
const resumed=await execute(f,
|
|
282
|
+
const resumed=await execute(f,{args:held});assert.equal(resumed.result.code,'revision_answer_required');assert.deepEqual(resumed.calls,[]);
|
|
247
283
|
assert.equal(probes().length,3);
|
|
248
284
|
assert.deepEqual([1,2].map(n=>fs.readFileSync(path.join(directory,`preflight-T-00${n}.json`),'utf8')),receipts);
|
|
249
285
|
const stale=JSON.parse(receipts[1]);stale.preflight.config_fingerprint='0'.repeat(64);
|
|
250
286
|
fs.writeFileSync(path.join(directory,'preflight-T-002.json'),JSON.stringify(stale));
|
|
251
|
-
const refreshed=await execute(f,
|
|
287
|
+
const refreshed=await execute(f,{args:held});assert.equal(refreshed.result.code,'revision_answer_required');assert.deepEqual(refreshed.calls,[]);
|
|
252
288
|
assert.equal(probes().length,4);
|
|
253
289
|
assert.equal(fs.readFileSync(path.join(directory,'preflight-T-002.json'),'utf8'),receipts[1]);
|
|
254
290
|
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
@@ -283,11 +319,12 @@ test('execution-policy batch moves an exact old-layout member preflight cache ou
|
|
|
283
319
|
try{
|
|
284
320
|
const log=path.join(f.root,'probe-cwds.jsonl'),fail=path.join(f.root,'fail-probe');
|
|
285
321
|
fs.writeFileSync(fail,'fail second member');
|
|
286
|
-
const processFixture=
|
|
322
|
+
const processFixture=path.join(f.root,'native-review-process.mjs');
|
|
323
|
+
fs.copyFileSync(fileURLToPath(new URL('./fixtures/codex-review-process.mjs',import.meta.url)),processFixture);
|
|
287
324
|
fs.writeFileSync(path.join(f.root,'bin','codex'),`#!${process.execPath}
|
|
288
325
|
const fs=require('node:fs'),cp=require('node:child_process');
|
|
289
326
|
const args=process.argv.slice(2),cwd=args[args.indexOf('--cd')+1];
|
|
290
|
-
fs.appendFileSync(${JSON.stringify(log)},JSON.stringify(cwd)+'\\n');
|
|
327
|
+
if(args.includes('model_provider="cm_local_tool_preview"'))fs.appendFileSync(${JSON.stringify(log)},JSON.stringify(cwd)+'\\n');
|
|
291
328
|
if(cwd.endsWith('T-002')&&fs.existsSync(${JSON.stringify(fail)}))process.exit(1);
|
|
292
329
|
let input='';process.stdin.on('data',part=>input+=part);process.stdin.on('end',()=>{
|
|
293
330
|
const result=cp.spawnSync(process.execPath,[${JSON.stringify(processFixture)},...args],{input,encoding:'utf8'});
|
|
@@ -297,7 +334,7 @@ let input='';process.stdin.on('data',part=>input+=part);process.stdin.on('end',(
|
|
|
297
334
|
const probes=()=>fs.readFileSync(log,'utf8').trim().split('\n').length;
|
|
298
335
|
const policy=['--execution-optimizations'];
|
|
299
336
|
// Stop before any member run exists (T-002's loopback fails): T-001 gets a real receipt.
|
|
300
|
-
const failed=await execute(f,
|
|
337
|
+
const failed=await execute(f,{args:policy});
|
|
301
338
|
assert.equal(failed.result.code,'review_preflight_failed',JSON.stringify(failed));
|
|
302
339
|
fs.unlinkSync(fail);
|
|
303
340
|
const real=fs.readFileSync(path.join(f.current,'preflight-T-001.json'),'utf8');
|
|
@@ -306,10 +343,10 @@ let input='';process.stdin.on('data',part=>input+=part);process.stdin.on('end',(
|
|
|
306
343
|
const receipts={'preflight-T-001.json':real,'preflight-T-002.json':JSON.stringify(second)+'\n'};
|
|
307
344
|
assert.deepEqual(Object.keys(JSON.parse(receipts['preflight-T-002.json'])),Object.keys(JSON.parse(real)));
|
|
308
345
|
fs.rmSync(path.dirname(f.current),{recursive:true});writeLegacy(f,receipts);
|
|
309
|
-
const before=probes();
|
|
310
|
-
const resumed=await execute(f,
|
|
346
|
+
const before=probes(),held=requestFirstRevision(f,['T-001','T-002'],processFixture);
|
|
347
|
+
const resumed=await execute(f,{args:[...policy,...held]});
|
|
311
348
|
assert.equal(resumed.code,0,resumed.stderr);
|
|
312
|
-
assert.equal(resumed.result.code,'
|
|
349
|
+
assert.equal(resumed.result.code,'revision_answer_required',JSON.stringify(resumed.result));
|
|
313
350
|
assert.equal(resumed.calls.filter(call=>call.endsWith(':develop')).length,2,JSON.stringify(resumed.calls));
|
|
314
351
|
assert.equal(probes(),before,'migrated receipts are reused without a new loopback');
|
|
315
352
|
assert(!fs.existsSync(f.legacy));
|
|
@@ -516,14 +553,13 @@ export async function serveCmAiHost({host}){await host.handle({});}
|
|
|
516
553
|
test('Q24 batch host recovers a serial member stopped at develop_redo and continues the batch',async()=>{
|
|
517
554
|
const f=fixture();
|
|
518
555
|
try{
|
|
519
|
-
const
|
|
520
|
-
const first=await execute(f,approvals,{failDevelop:new Set(['T-001'])});
|
|
556
|
+
const first=await execute(f,{failDevelop:new Set(['T-001'])});
|
|
521
557
|
assert.equal(first.code,0,first.stderr);
|
|
522
558
|
assert.deepEqual([first.result.state,first.result.code,first.result.pendingAction],['blocked','develop_answer_missing','develop_redo'],JSON.stringify(first.result));
|
|
523
559
|
assert.match(first.result.guidance.nextStep,/--allow-develop-redo 1\.work\/T-001/);assert.deepEqual(first.calls,['T-001:develop']);
|
|
524
560
|
const redo={operation:'develop_redo',requestId:'redo',taskKey:'1.work/T-001',reason:'会话已停止修改代码'};
|
|
525
561
|
// advance alone never redispatches; the operation needs its per-member grant.
|
|
526
|
-
const refused=await execute(f,
|
|
562
|
+
const refused=await execute(f,{operations:[{operation:'advance',requestId:'advance'},redo]});
|
|
527
563
|
assert.equal(refused.results.advance.pendingAction,'develop_redo');
|
|
528
564
|
assert.deepEqual([refused.result.outcome,refused.result.code],['rejected','batch_member_action_authorization_required']);
|
|
529
565
|
assert.match(refused.result.reason,/--allow-develop-redo 1\.work\/T-001/);assert.deepEqual(refused.calls,[]);
|
|
@@ -533,7 +569,7 @@ test('Q24 batch host recovers a serial member stopped at develop_redo and contin
|
|
|
533
569
|
const unsupported=spawnSync(process.execPath,[cli,...f.args,flag,'x'],{env:f.env,encoding:'utf8',timeout:5000});
|
|
534
570
|
assert.equal(unsupported.status,1);assert.match(unsupported.stderr,new RegExp(code));assert.match(unsupported.stderr,/出口/);
|
|
535
571
|
}
|
|
536
|
-
const recovered=await execute(f,
|
|
572
|
+
const recovered=await execute(f,{args:['--allow-develop-redo','1.work/T-001'],
|
|
537
573
|
operations:[redo,{operation:'advance',requestId:'advance'}]});
|
|
538
574
|
assert.equal(recovered.code,0,recovered.stderr);
|
|
539
575
|
assert.deepEqual([recovered.results.redo.outcome,recovered.results.redo.pendingAction,recovered.results.redo.taskKey],
|
|
@@ -548,8 +584,8 @@ test('Q24 batch host recovers a serial member stopped at develop_redo and contin
|
|
|
548
584
|
// After cancel the batch stays stopped; a forwarded operation cannot reopen it.
|
|
549
585
|
const g=fixture();
|
|
550
586
|
try{
|
|
551
|
-
const stopped=await execute(g,
|
|
552
|
-
const after=await execute(g,
|
|
587
|
+
const stopped=await execute(g,{cancel:true});assert.equal(stopped.result.code,'cancelled');
|
|
588
|
+
const after=await execute(g,{args:['--allow-develop-redo','1.work/T-001'],operations:[redo]});
|
|
553
589
|
assert.deepEqual([after.result.outcome,after.result.code],['blocked','cancelled']);
|
|
554
590
|
}finally{fs.rmSync(g.root,{recursive:true,force:true});}
|
|
555
591
|
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
@@ -23,11 +23,6 @@ export async function batchFixture(mode,options={}){
|
|
|
23
23
|
const parallel=mode.startsWith('parallel');
|
|
24
24
|
const recovery=mode==='parallel-recovery',blockedIds=options.blockedIds??['T-002'];
|
|
25
25
|
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-batch-')));
|
|
26
|
-
// parallel-grant-expired: right after T-002's first grant, registration reads the
|
|
27
|
-
// authorization instant and the dispatch clock reads past the 1 ms grant.
|
|
28
|
-
const realNow=Date.now;let expiry=null,expiredOnce=false,reviewDispatches=0;
|
|
29
|
-
if(mode==='parallel-grant-expired')Date.now=()=>{const now=realNow.call(Date);
|
|
30
|
-
if(expiry===null)return now;return expiry.reads++===0?expiry.at:Math.max(now,expiry.at+2);};
|
|
31
26
|
try{
|
|
32
27
|
const specsDir=path.join(root,'specs'),codeProject=path.join(root,'code'),feature='1.work';
|
|
33
28
|
fs.mkdirSync(path.join(specsDir,feature),{recursive:true});fs.mkdirSync(codeProject);
|
|
@@ -47,7 +42,7 @@ export async function batchFixture(mode,options={}){
|
|
|
47
42
|
let conflictHead=null,interrupted=false,reviewFailed=false,redoThrown=false;
|
|
48
43
|
const developerModel=mode==='parallel-redo'?'current-session':'fixture';
|
|
49
44
|
const executionFor=async(definition,{parallelMember=false}={})=>({configuration:{kind:'batch-fixture-v1',...(parallelMember?{parallelMember:true}:{})},timeoutMs:3000,
|
|
50
|
-
excludedContexts:['host'],
|
|
45
|
+
excludedContexts:['host'],applicableAgentFiles:[],
|
|
51
46
|
developer:{provider:'codex',requestedModel:developerModel,contextId:'author',run:createCodexDeveloperRun({requestedModel:developerModel,
|
|
52
47
|
worker:async({prompt},{signal})=>{
|
|
53
48
|
const data=JSON.parse(prompt.split('<cm-developer-data-json>\n')[1]),material=data.specification;
|
|
@@ -107,7 +102,6 @@ export async function batchFixture(mode,options={}){
|
|
|
107
102
|
},
|
|
108
103
|
reviewers:[{id:'reviewer',adapterId:'codex-review-adapter',provider:'codex',requestedModel:'fixture',allowed:true,available:true,
|
|
109
104
|
contexts:['review-1','review-2'],run:(request,{onEvent})=>{
|
|
110
|
-
if(request.identity.taskId==='T-002')reviewDispatches++;
|
|
111
105
|
assert.equal(request.payload.reviewPackage.specification.task.id,definition.identity.taskId);
|
|
112
106
|
assert.deepEqual(request.payload.reviewPackage.specification.sources,buildManifest(specsDir));
|
|
113
107
|
if(mode==='learning'&&request.identity.taskId==='T-001')
|
|
@@ -129,25 +123,15 @@ export async function batchFixture(mode,options={}){
|
|
|
129
123
|
return {status:'succeeded',value:{verdict:retry?'changes_requested':'approved',packageDigest:request.payload.reviewPackage.packageDigest,
|
|
130
124
|
examinedPaths:reviewPaths(request.payload.reviewPackage),findings:retry?[{id:'F1',severity:'P2',path:'file0.js',message:'Synthetic repair',evidence:'First implementation'}]:[],summary:'Synthetic independent review'}};
|
|
131
125
|
}}],
|
|
132
|
-
reviewInvocation:{developerThreadId:'author',excludedThreadIds:['host'],
|
|
133
|
-
|
|
134
|
-
invocationId:request.invocationId,requestDigest:request.requestDigest,identity:request.identity,reviewerId:'reviewer',
|
|
135
|
-
logicalContextId:request.contextId,packageDigest:request.payload.reviewPackage.packageDigest,hostContextId:'host',
|
|
136
|
-
decisionId:'decision',decision:'approved',issuedAt:authorizationAt,expiresAt:authorizationAt+60000};
|
|
137
|
-
if(mode==='parallel-denied'&&request.identity.taskId==='T-002')return {status:'denied',code:'permission_denied'};
|
|
138
|
-
if(mode==='parallel-grant-expired'&&request.identity.taskId==='T-002'&&!expiredOnce){
|
|
139
|
-
expiredOnce=true;body.expiresAt=authorizationAt+1;expiry={at:authorizationAt,reads:0};}
|
|
140
|
-
return {...body,grantDigest:digest(body)};
|
|
141
|
-
}},
|
|
142
|
-
qaDecisionProvider:parallelMember?createParallelMemberQaDecisionProvider():mode==='policy'?createHostQaDecisionProvider({timeoutMs:1000,assess:async binding=>{
|
|
126
|
+
reviewInvocation:{developerThreadId:'author',excludedThreadIds:['host']},
|
|
127
|
+
qaDecisionProvider:parallelMember?createParallelMemberQaDecisionProvider():mode==='policy'?createHostQaDecisionProvider({timeoutMs:1000,criticalPaths:{api:['file0.js']},assess:async binding=>{
|
|
143
128
|
assessments.push(binding.identity.taskId);
|
|
144
|
-
return {
|
|
145
|
-
changes:{api:binding.identity.taskId==='T-001',migration:false,authentication:false,authorization:false,payment:false}};
|
|
129
|
+
return {confirmed:true};
|
|
146
130
|
}}):{timeoutMs:1000,decide:async binding=>{
|
|
147
131
|
if(!qaReady)throw Object.assign(new Error('await QA decision'),{code:'qa_decision_required'});
|
|
148
132
|
const skip=binding.identity.taskId==='T-001'&&mode!=='failed-qa';
|
|
149
133
|
return {decisionId:`qa-${binding.identity.taskId}`,identity:binding.identity,packageDigest:binding.packageDigest,
|
|
150
|
-
status:skip?'skipped':'triggered',reason:'
|
|
134
|
+
status:skip?'skipped':'triggered',reason:skip?'no_fixed_trigger':'feature_complete',score:null,at:'2026-09-08T01:00:00Z'};
|
|
151
135
|
}},
|
|
152
136
|
qaExecutor:mode==='executor'?(()=>{
|
|
153
137
|
const executor=createHostQaExecutor({specsDir,codeProject,feature,runtime:'codex',requirements:definition.requirements,
|
|
@@ -259,37 +243,6 @@ export async function batchFixture(mode,options={}){
|
|
|
259
243
|
acquireExternalRunGuard({specsDir,codeProject:worktree,identity,feature},{strictOnly:true}).close();
|
|
260
244
|
return;
|
|
261
245
|
}
|
|
262
|
-
if(mode==='parallel-denied'){
|
|
263
|
-
// A refused review authorization is a decision, never retried by the batch itself: the member
|
|
264
|
-
// stays in its own run and names the operator's confirmation (abandon_review), which the batch
|
|
265
|
-
// forwards only under --allow-abandon-review for that member.
|
|
266
|
-
assert.equal(result.code,'batch_parallel_member_recovery_required',JSON.stringify(result));
|
|
267
|
-
assert.deepEqual([result.currentTask,result.memberState,result.memberCode,result.pendingAction],
|
|
268
|
-
[`${feature}/T-002`,'pending_review','permission_denied','abandon_review'],JSON.stringify(result));
|
|
269
|
-
assert.match(result.reason,/--allow-abandon-review 1\.work\/T-002/);assert.equal(result.guidance.authorizationGranted,false);
|
|
270
|
-
assert(fs.existsSync(path.join(root,'.cm-worktrees',config.batchId.slice(0,8),'T-002')));
|
|
271
|
-
assert.equal(fs.readFileSync(path.join(specsDir,'运行日志.jsonl'),'utf8').includes('batch_member_blocked'),false);
|
|
272
|
-
const {classifyDriveResult}=await import('../runtime/js/notify.mjs');
|
|
273
|
-
assert.equal(classifyDriveResult('cm-ai-batch',{result}),'stuck');
|
|
274
|
-
return;
|
|
275
|
-
}
|
|
276
|
-
if(mode==='parallel-grant-expired'){
|
|
277
|
-
const logfile=path.join(specsDir,'运行日志.jsonl'),rows=()=>fs.readFileSync(logfile,'utf8').trim().split('\n').map(JSON.parse);
|
|
278
|
-
assert(expiredOnce);
|
|
279
|
-
assert.deepEqual([result.state,result.code,result.pendingAction,result.identity.taskId],['pending_review','grant_expired','resume','T-002'],JSON.stringify(result));
|
|
280
|
-
assert.equal(reviewDispatches,0);
|
|
281
|
-
// Kept in its run: no reschedule, worktree and delivery stay.
|
|
282
|
-
assert.equal(rows().filter(row=>row.phase==='batch_member_blocked').length,0);
|
|
283
|
-
assert.equal(fs.readFileSync(path.join(root,'.cm-worktrees',config.batchId.slice(0,8),'T-002','file1.js'),'utf8'),'implemented\n');
|
|
284
|
-
result=await open().handle({operation:'advance',requestId:'after-grant-expired'});
|
|
285
|
-
assert.equal(result.code,'run_done',JSON.stringify(result));
|
|
286
|
-
assert.equal(reviewDispatches,1);assert.deepEqual(calls,['T-001','T-002','T-003']);
|
|
287
|
-
assert.equal(rows().filter(row=>row.phase==='batch_member_blocked').length,0);
|
|
288
|
-
const runId=`task-${digest({batchId:config.batchId,task:`${feature}/T-002`}).slice(0,48)}`;
|
|
289
|
-
const records=JSON.parse(fs.readFileSync(path.join(specsDir,'.reviews','.execution',runId,'state.json'),'utf8')).records;
|
|
290
|
-
assert.deepEqual(records.filter(row=>row.payload.type==='review-invocation-result').map(row=>row.payload.outcome),['not_dispatched','observed']);
|
|
291
|
-
return;
|
|
292
|
-
}
|
|
293
246
|
if(mode==='parallel-redo'){
|
|
294
247
|
const logfile=path.join(specsDir,'运行日志.jsonl'),rows=()=>fs.readFileSync(logfile,'utf8').trim().split('\n').map(JSON.parse);
|
|
295
248
|
assert.equal(result.code,'batch_parallel_member_recovery_required',JSON.stringify(result));
|
|
@@ -495,5 +448,5 @@ export async function batchFixture(mode,options={}){
|
|
|
495
448
|
assert.equal(log.filter(row=>row.event==='decision'&&row.phase==='qa_merge'&&row.task==='T-001').length,1);
|
|
496
449
|
assert(log.some(row=>row.event==='qa'&&row.task==='T-002'&&row.reason==='feature_complete'));
|
|
497
450
|
}
|
|
498
|
-
}finally{
|
|
451
|
+
}finally{fs.rmSync(root,{recursive:true,force:true});}
|
|
499
452
|
}
|
|
@@ -16,18 +16,6 @@ test('an ordinary-batch parallel member left unknown stays in its original run a
|
|
|
16
16
|
test('Q24 an ordinary-batch parallel member stopped at develop_redo recovers through the batch entry and merges',async()=>{
|
|
17
17
|
await batchFixture('parallel-redo');
|
|
18
18
|
});
|
|
19
|
-
// Batch 4 review round 1: a member whose review was registered but never dispatched
|
|
20
|
-
// (pending_review/grant_expired, call not_dispatched) is not an unresolved stop with
|
|
21
|
-
// unusable exits: no reviewer ran, so the next advance redispatches it in its own run.
|
|
22
|
-
test('an ordinary-batch parallel member whose review grant expired before dispatch redispatches it in its original run',async()=>{
|
|
23
|
-
await batchFixture('parallel-grant-expired');
|
|
24
|
-
});
|
|
25
|
-
// A member whose review authorization was refused (raw pending_review/permission_denied) is not
|
|
26
|
-
// redispatched by the batch and not rescheduled: it names the confirmation (abandon_review) that
|
|
27
|
-
// lets its own run ask for a fresh authorization.
|
|
28
|
-
test('a parallel member whose review authorization was refused stays in its run and names abandon_review',async()=>{
|
|
29
|
-
await batchFixture('parallel-denied');
|
|
30
|
-
});
|
|
31
19
|
// Q26: the batch handoff check closes a cleanup_failed QA command resource whose
|
|
32
20
|
// process group the host proves gone; one it cannot prove stops the batch with
|
|
33
21
|
// batch_resources_open naming the resource and the exit (not a bare code).
|