@aibyzero/cm-workflow 0.16.9 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.codex-plugin/plugin.json +1 -1
- package/CHANGELOG.md +12 -0
- package/README.md +9 -1
- package/VERSION +1 -1
- 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/human-correction.md +5 -5
- package/docs/installation.md +1 -1
- package/docs/js-workflow-control.md +101 -84
- 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/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 +111 -0
- package/runtime/js/cm-ai/drive-bootstrap.mjs +11 -8
- 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-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-tool-bridge.mjs +3 -0
- 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 +1 -24
- 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 +36 -99
- 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-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 +52 -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 +62 -38
- 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 +34 -8
- 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 +124 -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 +54 -25
- package/scripts/cm-ai-drive.mjs +96 -54
- package/scripts/cm-ai-drive.test.mjs +43 -84
- 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 +38 -10
- 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 +19 -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-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 +15 -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-runtime.sh +1 -1
- package/scripts/cm-claude-worker.test.mjs +5 -3
- package/scripts/cm-controlled-correction.test.mjs +469 -0
- package/scripts/cm-external-batch-host.test.mjs +30 -11
- 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-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-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 +91 -19
- package/scripts/cm-patrol.test.mjs +3 -2
- 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/fixtures/bootstrap-review-runner.mjs +1 -7
- 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 +65 -28
- 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
|
@@ -66,9 +66,22 @@ function fixture(runtime='codex'){
|
|
|
66
66
|
// operations are sent one after another (each after the previous reply); the
|
|
67
67
|
// session closes after the last. failDevelop: task ids whose next develop
|
|
68
68
|
// answer is a bare failure after the session wrote (develop_answer_missing).
|
|
69
|
-
|
|
69
|
+
// Use an actual first-round review finding for a launch-only revision pause.
|
|
70
|
+
// The synthetic native process still emits its normal bound review observation.
|
|
71
|
+
function requestFirstRevision(f,taskIds,nativeFile=path.join(f.root,'bin',f.runtime)){
|
|
72
|
+
const fake=nativeFile;
|
|
73
|
+
const first=`${JSON.stringify(taskIds)}.includes(data.reviewPackage.identity.taskId)&&data.reviewPackage.identity.attempt===1`;
|
|
74
|
+
const source=fs.readFileSync(fake,'utf8');
|
|
75
|
+
assert(source.includes("verdict:'approved'")&&source.includes('findings:[]'),'native review fixture must retain its known response fields');
|
|
76
|
+
fs.writeFileSync(fake,source
|
|
77
|
+
.replace("verdict:'approved'",`verdict:(${first})?'changes_requested':'approved'`)
|
|
78
|
+
.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'}]:[]`));
|
|
79
|
+
return taskIds.flatMap(taskId=>['--hold-revision',`1.work/${taskId}`]);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function execute(f,{cancel=false,args=[],operations=[{operation:'advance',requestId:'advance'}],failDevelop=new Set()}={}){
|
|
70
83
|
return new Promise((resolve,reject)=>{
|
|
71
|
-
const child=spawn(process.execPath,[cli,...f.args,...args
|
|
84
|
+
const child=spawn(process.execPath,[cli,...f.args,...args],
|
|
72
85
|
{env:f.env,stdio:['pipe','pipe','pipe']});
|
|
73
86
|
let buffer='',stderr='',sessionId;const calls=[],rows=[];
|
|
74
87
|
const timer=setTimeout(()=>{child.kill('SIGTERM');reject(Error('batch host timeout'));},Number(process.env.CM_TEST_FIXTURE_TIMEOUT_MS??60000));
|
|
@@ -94,7 +107,7 @@ function execute(f,approvals,{cancel=false,args=[],operations=[{operation:'advan
|
|
|
94
107
|
assert.deepEqual(payload.request.payload.scope,f.batch.tasks[n-1].scope);
|
|
95
108
|
assert.equal(payload.request.payload.specification.task.id,identity.taskId);
|
|
96
109
|
assert.deepEqual(payload.request.payload.specification.sources,buildManifest(f.specsDir));
|
|
97
|
-
const content=`export const value = ${40+n};\n`;
|
|
110
|
+
const content=`export const value = ${40+n};\n${identity.attempt===2?"// Revised after the independent review finding.\n":""}`;
|
|
98
111
|
if(!f.protected)fs.writeFileSync(path.join(cwd,`task${n}.mjs`),content);
|
|
99
112
|
if(failDevelop.delete(identity.taskId)){respond(row,{status:'failed',code:'session_error'});continue;}
|
|
100
113
|
respond(row,{status:'succeeded',value:{outcome:'implemented',application:{status:'no_relevant_lesson',note:null},
|
|
@@ -107,8 +120,7 @@ function execute(f,approvals,{cancel=false,args=[],operations=[{operation:'advan
|
|
|
107
120
|
const result=spawnSync(command[0],command.slice(1));assert.equal(result.status,0);
|
|
108
121
|
return {id:'syntax',command,outcome:'passed',exitCode:0,evidence:'Actual Node syntax check exited 0'};
|
|
109
122
|
});respond(row,checks);
|
|
110
|
-
}else if(row.kind==='qa_assess')respond(row,{
|
|
111
|
-
changes:{api:false,migration:false,authentication:false,authorization:false,payment:false}});
|
|
123
|
+
}else if(row.kind==='qa_assess')respond(row,{confirmed:true});
|
|
112
124
|
else if(row.kind==='documentation_sync'){
|
|
113
125
|
assert.equal(identity.taskId,'T-002');assert.deepEqual(payload.paths,['README.md']);
|
|
114
126
|
fs.writeFileSync(path.join(f.codeProject,'README.md'),'# Exports 41 and 42\n');respond(row,{status:'completed'});
|
|
@@ -147,55 +159,65 @@ test('protected Claude batch uses actual sandbox edits/checks and original two-t
|
|
|
147
159
|
fs.writeFileSync(protection,JSON.stringify({timeoutMs:5000,checkCommands:[{id:'syntax',command:[process.execPath,'-e',
|
|
148
160
|
"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
161
|
f.args.push('--protected-conversation-config',protection);
|
|
150
|
-
const result=await execute(f
|
|
162
|
+
const result=await execute(f);
|
|
151
163
|
assert.equal(result.code,0,result.stderr);assert.equal(result.result.state,'run_done',JSON.stringify(result.result));
|
|
152
164
|
assert.deepEqual(result.calls,['T-001:develop','T-001:qa_assess','T-002:develop','T-002:qa_assess','T-002:documentation_inspect']);
|
|
153
165
|
assert.equal(fs.readFileSync(path.join(nested,'1.work/tasks.md'),'utf8').match(/\[x\]/g).length,2);
|
|
154
|
-
const resume=await execute(f
|
|
166
|
+
const resume=await execute(f);assert.equal(resume.result.state,'run_done');assert.deepEqual(resume.calls,['T-002:documentation_inspect']);
|
|
155
167
|
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
156
168
|
});
|
|
157
169
|
|
|
158
|
-
for(const runtime of ['codex','claude'])test(`${runtime} batch CLI preserves
|
|
170
|
+
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
171
|
const f=fixture(runtime);
|
|
160
172
|
try{
|
|
161
|
-
const
|
|
162
|
-
|
|
173
|
+
const bundle=JSON.parse(fs.readFileSync(f.config,'utf8'));
|
|
174
|
+
bundle.workflows['1.work/T-001'].qa.criticalPaths={payment:['task1.mjs']};
|
|
175
|
+
fs.writeFileSync(f.config,JSON.stringify(bundle));
|
|
176
|
+
const held=requestFirstRevision(f,['T-002']);
|
|
177
|
+
const first=await execute(f,{args:held});assert.equal(first.code,0,first.stderr);
|
|
178
|
+
assert.equal(first.result.identity.taskId,'T-002');assert.equal(first.result.state,'changes_requested');
|
|
179
|
+
assert.equal(first.result.identity.attempt,2);assert.equal(first.result.code,'revision_answer_required');
|
|
163
180
|
assert(fs.readFileSync(path.join(f.specsDir,'1.work','tasks.md'),'utf8').includes('[ ] T-002'));
|
|
164
181
|
assert.deepEqual(first.calls,['T-001:develop','T-001:check','T-001:check','T-001:qa_assess',
|
|
165
182
|
'T-002:develop','T-002:documentation_sync','T-002:check']);
|
|
166
183
|
const original=fs.readFileSync(f.config,'utf8'),changed=JSON.parse(original);
|
|
167
184
|
changed.workflows['1.work/T-002'].documentationPaths=[];
|
|
168
185
|
fs.writeFileSync(f.config,JSON.stringify(changed));
|
|
169
|
-
const drift=await execute(f
|
|
186
|
+
const drift=await execute(f);
|
|
170
187
|
assert.equal(drift.result.outcome,'blocked');assert.deepEqual(drift.calls,[]);
|
|
171
188
|
fs.writeFileSync(f.config,original);
|
|
172
189
|
if(runtime==='claude'){
|
|
173
190
|
const saved=[...f.args];f.args[f.args.length-1]='codex';
|
|
174
|
-
const wrongRuntime=await execute(f
|
|
191
|
+
const wrongRuntime=await execute(f);assert.equal(wrongRuntime.result.outcome,'blocked');
|
|
175
192
|
assert.deepEqual(wrongRuntime.calls,[]);f.args=saved;
|
|
176
193
|
}
|
|
177
|
-
const second=await execute(f
|
|
194
|
+
const second=await execute(f);assert.equal(second.code,0,second.stderr);
|
|
178
195
|
assert.equal(second.result.state,'run_done',JSON.stringify(second.result));
|
|
179
|
-
assert.deepEqual(second.calls,['T-002:
|
|
180
|
-
|
|
196
|
+
assert.deepEqual(second.calls,['T-002:develop','T-002:documentation_sync','T-002:check','T-002:check',
|
|
197
|
+
'T-002:qa_assess','T-002:documentation_inspect']);
|
|
198
|
+
const reopened=await execute(f);assert.equal(reopened.code,0,reopened.stderr);
|
|
181
199
|
assert.equal(reopened.result.state,'run_done',JSON.stringify(reopened.result));
|
|
182
200
|
assert.deepEqual(reopened.calls,['T-002:documentation_inspect']);
|
|
183
201
|
const rows=fs.readFileSync(path.join(f.specsDir,'运行日志.jsonl'),'utf8').trim().split('\n').map(JSON.parse);
|
|
184
202
|
assert.equal(rows.filter(row=>row.event==='run_done').length,1);
|
|
185
203
|
assert.equal(rows.filter(row=>row.event==='decision'&&row.phase==='batch_handoff').length,1);
|
|
186
204
|
assert.equal(rows.filter(row=>row.event==='test_run'&&row.phase==='start').length,2);
|
|
205
|
+
const taskQa=rows.filter(row=>row.event==='qa'&&row.task==='T-001');
|
|
206
|
+
assert.equal(taskQa.length,1);
|
|
207
|
+
assert.equal(taskQa[0].status,'triggered');
|
|
208
|
+
assert(taskQa[0].reason.split(',').includes('payment'));
|
|
209
|
+
assert.equal(taskQa[0].score,null);
|
|
210
|
+
assert.equal(taskQa[0].changed_files_source,'review_package');
|
|
187
211
|
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
188
212
|
});
|
|
189
213
|
|
|
190
|
-
for(const runtime of ['codex','claude'])test(`${runtime} batch CLI cancellation remains durable
|
|
214
|
+
for(const runtime of ['codex','claude'])test(`${runtime} batch CLI cancellation remains durable`,async()=>{
|
|
191
215
|
const f=fixture(runtime);
|
|
192
216
|
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);
|
|
217
|
+
const stopped=await execute(f,{cancel:true});assert.equal(stopped.code,0,stopped.stderr);
|
|
196
218
|
assert.equal(stopped.result.code,'cancelled');assert.equal(stopped.calls.length,1);
|
|
197
219
|
assert(stopped.rows.some(row=>row.requestId==='status'));
|
|
198
|
-
const reopened=await execute(f
|
|
220
|
+
const reopened=await execute(f);assert.equal(reopened.result.code,'cancelled');assert.deepEqual(reopened.calls,[]);
|
|
199
221
|
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
200
222
|
});
|
|
201
223
|
|
|
@@ -214,11 +236,12 @@ test('parallel member loopback preflights bind worktree cwd, stop before start a
|
|
|
214
236
|
git(['add','-A']);git(['commit','--allow-empty','-m','synthetic baseline']);
|
|
215
237
|
const log=path.join(f.root,'probe-cwds.jsonl'),fail=path.join(f.root,'fail-probe');
|
|
216
238
|
fs.writeFileSync(fail,'fail second member');
|
|
217
|
-
const processFixture=
|
|
239
|
+
const processFixture=path.join(f.root,'native-review-process.mjs');
|
|
240
|
+
fs.copyFileSync(fileURLToPath(new URL('./fixtures/codex-review-process.mjs',import.meta.url)),processFixture);
|
|
218
241
|
fs.writeFileSync(path.join(f.root,'bin','codex'),`#!${process.execPath}
|
|
219
242
|
const fs=require('node:fs'),cp=require('node:child_process');
|
|
220
243
|
const args=process.argv.slice(2),cwd=args[args.indexOf('--cd')+1];
|
|
221
|
-
fs.appendFileSync(${JSON.stringify(log)},JSON.stringify(cwd)+'\\n');
|
|
244
|
+
if(args.includes('model_provider="cm_local_tool_preview"'))fs.appendFileSync(${JSON.stringify(log)},JSON.stringify(cwd)+'\\n');
|
|
222
245
|
if(cwd.endsWith('T-002')&&fs.existsSync(${JSON.stringify(fail)}))process.exit(1);
|
|
223
246
|
let input='';process.stdin.on('data',part=>input+=part);process.stdin.on('end',()=>{
|
|
224
247
|
const result=cp.spawnSync(process.execPath,[${JSON.stringify(processFixture)},...args],{input,encoding:'utf8'});
|
|
@@ -226,12 +249,13 @@ let input='';process.stdin.on('data',part=>input+=part);process.stdin.on('end',(
|
|
|
226
249
|
});
|
|
227
250
|
`,{mode:0o700});
|
|
228
251
|
const probes=()=>fs.readFileSync(log,'utf8').trim().split('\n').map(JSON.parse);
|
|
229
|
-
const failed=await execute(f
|
|
252
|
+
const failed=await execute(f);
|
|
230
253
|
assert.equal(failed.result.code,'review_preflight_failed',JSON.stringify(failed));
|
|
231
254
|
assert.equal(failed.result.currentTask,'1.work/T-002');assert.deepEqual(failed.calls,[]);
|
|
232
255
|
assert.equal(probes().length,2);
|
|
233
256
|
fs.unlinkSync(fail);
|
|
234
|
-
const
|
|
257
|
+
const held=requestFirstRevision(f,['T-001','T-002'],processFixture);
|
|
258
|
+
const first=await execute(f,{args:held});assert.equal(first.result.code,'revision_answer_required',JSON.stringify(first));
|
|
235
259
|
assert.equal(first.calls.filter(call=>call.endsWith(':develop')).length,2,JSON.stringify(first));
|
|
236
260
|
const directory=path.join(f.specsDir,'.reviews','.execution',f.batch.batchId);
|
|
237
261
|
const receipts=[1,2].map(n=>fs.readFileSync(path.join(directory,`preflight-T-00${n}.json`),'utf8'));
|
|
@@ -243,12 +267,12 @@ let input='';process.stdin.on('data',part=>input+=part);process.stdin.on('end',(
|
|
|
243
267
|
assert(probes().includes(cwd));
|
|
244
268
|
}
|
|
245
269
|
assert.equal(probes().length,3);
|
|
246
|
-
const resumed=await execute(f,
|
|
270
|
+
const resumed=await execute(f,{args:held});assert.equal(resumed.result.code,'revision_answer_required');assert.deepEqual(resumed.calls,[]);
|
|
247
271
|
assert.equal(probes().length,3);
|
|
248
272
|
assert.deepEqual([1,2].map(n=>fs.readFileSync(path.join(directory,`preflight-T-00${n}.json`),'utf8')),receipts);
|
|
249
273
|
const stale=JSON.parse(receipts[1]);stale.preflight.config_fingerprint='0'.repeat(64);
|
|
250
274
|
fs.writeFileSync(path.join(directory,'preflight-T-002.json'),JSON.stringify(stale));
|
|
251
|
-
const refreshed=await execute(f,
|
|
275
|
+
const refreshed=await execute(f,{args:held});assert.equal(refreshed.result.code,'revision_answer_required');assert.deepEqual(refreshed.calls,[]);
|
|
252
276
|
assert.equal(probes().length,4);
|
|
253
277
|
assert.equal(fs.readFileSync(path.join(directory,'preflight-T-002.json'),'utf8'),receipts[1]);
|
|
254
278
|
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
@@ -283,11 +307,12 @@ test('execution-policy batch moves an exact old-layout member preflight cache ou
|
|
|
283
307
|
try{
|
|
284
308
|
const log=path.join(f.root,'probe-cwds.jsonl'),fail=path.join(f.root,'fail-probe');
|
|
285
309
|
fs.writeFileSync(fail,'fail second member');
|
|
286
|
-
const processFixture=
|
|
310
|
+
const processFixture=path.join(f.root,'native-review-process.mjs');
|
|
311
|
+
fs.copyFileSync(fileURLToPath(new URL('./fixtures/codex-review-process.mjs',import.meta.url)),processFixture);
|
|
287
312
|
fs.writeFileSync(path.join(f.root,'bin','codex'),`#!${process.execPath}
|
|
288
313
|
const fs=require('node:fs'),cp=require('node:child_process');
|
|
289
314
|
const args=process.argv.slice(2),cwd=args[args.indexOf('--cd')+1];
|
|
290
|
-
fs.appendFileSync(${JSON.stringify(log)},JSON.stringify(cwd)+'\\n');
|
|
315
|
+
if(args.includes('model_provider="cm_local_tool_preview"'))fs.appendFileSync(${JSON.stringify(log)},JSON.stringify(cwd)+'\\n');
|
|
291
316
|
if(cwd.endsWith('T-002')&&fs.existsSync(${JSON.stringify(fail)}))process.exit(1);
|
|
292
317
|
let input='';process.stdin.on('data',part=>input+=part);process.stdin.on('end',()=>{
|
|
293
318
|
const result=cp.spawnSync(process.execPath,[${JSON.stringify(processFixture)},...args],{input,encoding:'utf8'});
|
|
@@ -297,7 +322,7 @@ let input='';process.stdin.on('data',part=>input+=part);process.stdin.on('end',(
|
|
|
297
322
|
const probes=()=>fs.readFileSync(log,'utf8').trim().split('\n').length;
|
|
298
323
|
const policy=['--execution-optimizations'];
|
|
299
324
|
// Stop before any member run exists (T-002's loopback fails): T-001 gets a real receipt.
|
|
300
|
-
const failed=await execute(f,
|
|
325
|
+
const failed=await execute(f,{args:policy});
|
|
301
326
|
assert.equal(failed.result.code,'review_preflight_failed',JSON.stringify(failed));
|
|
302
327
|
fs.unlinkSync(fail);
|
|
303
328
|
const real=fs.readFileSync(path.join(f.current,'preflight-T-001.json'),'utf8');
|
|
@@ -306,10 +331,10 @@ let input='';process.stdin.on('data',part=>input+=part);process.stdin.on('end',(
|
|
|
306
331
|
const receipts={'preflight-T-001.json':real,'preflight-T-002.json':JSON.stringify(second)+'\n'};
|
|
307
332
|
assert.deepEqual(Object.keys(JSON.parse(receipts['preflight-T-002.json'])),Object.keys(JSON.parse(real)));
|
|
308
333
|
fs.rmSync(path.dirname(f.current),{recursive:true});writeLegacy(f,receipts);
|
|
309
|
-
const before=probes();
|
|
310
|
-
const resumed=await execute(f,
|
|
334
|
+
const before=probes(),held=requestFirstRevision(f,['T-001','T-002'],processFixture);
|
|
335
|
+
const resumed=await execute(f,{args:[...policy,...held]});
|
|
311
336
|
assert.equal(resumed.code,0,resumed.stderr);
|
|
312
|
-
assert.equal(resumed.result.code,'
|
|
337
|
+
assert.equal(resumed.result.code,'revision_answer_required',JSON.stringify(resumed.result));
|
|
313
338
|
assert.equal(resumed.calls.filter(call=>call.endsWith(':develop')).length,2,JSON.stringify(resumed.calls));
|
|
314
339
|
assert.equal(probes(),before,'migrated receipts are reused without a new loopback');
|
|
315
340
|
assert(!fs.existsSync(f.legacy));
|
|
@@ -516,14 +541,13 @@ export async function serveCmAiHost({host}){await host.handle({});}
|
|
|
516
541
|
test('Q24 batch host recovers a serial member stopped at develop_redo and continues the batch',async()=>{
|
|
517
542
|
const f=fixture();
|
|
518
543
|
try{
|
|
519
|
-
const
|
|
520
|
-
const first=await execute(f,approvals,{failDevelop:new Set(['T-001'])});
|
|
544
|
+
const first=await execute(f,{failDevelop:new Set(['T-001'])});
|
|
521
545
|
assert.equal(first.code,0,first.stderr);
|
|
522
546
|
assert.deepEqual([first.result.state,first.result.code,first.result.pendingAction],['blocked','develop_answer_missing','develop_redo'],JSON.stringify(first.result));
|
|
523
547
|
assert.match(first.result.guidance.nextStep,/--allow-develop-redo 1\.work\/T-001/);assert.deepEqual(first.calls,['T-001:develop']);
|
|
524
548
|
const redo={operation:'develop_redo',requestId:'redo',taskKey:'1.work/T-001',reason:'会话已停止修改代码'};
|
|
525
549
|
// advance alone never redispatches; the operation needs its per-member grant.
|
|
526
|
-
const refused=await execute(f,
|
|
550
|
+
const refused=await execute(f,{operations:[{operation:'advance',requestId:'advance'},redo]});
|
|
527
551
|
assert.equal(refused.results.advance.pendingAction,'develop_redo');
|
|
528
552
|
assert.deepEqual([refused.result.outcome,refused.result.code],['rejected','batch_member_action_authorization_required']);
|
|
529
553
|
assert.match(refused.result.reason,/--allow-develop-redo 1\.work\/T-001/);assert.deepEqual(refused.calls,[]);
|
|
@@ -533,7 +557,7 @@ test('Q24 batch host recovers a serial member stopped at develop_redo and contin
|
|
|
533
557
|
const unsupported=spawnSync(process.execPath,[cli,...f.args,flag,'x'],{env:f.env,encoding:'utf8',timeout:5000});
|
|
534
558
|
assert.equal(unsupported.status,1);assert.match(unsupported.stderr,new RegExp(code));assert.match(unsupported.stderr,/出口/);
|
|
535
559
|
}
|
|
536
|
-
const recovered=await execute(f,
|
|
560
|
+
const recovered=await execute(f,{args:['--allow-develop-redo','1.work/T-001'],
|
|
537
561
|
operations:[redo,{operation:'advance',requestId:'advance'}]});
|
|
538
562
|
assert.equal(recovered.code,0,recovered.stderr);
|
|
539
563
|
assert.deepEqual([recovered.results.redo.outcome,recovered.results.redo.pendingAction,recovered.results.redo.taskKey],
|
|
@@ -548,8 +572,8 @@ test('Q24 batch host recovers a serial member stopped at develop_redo and contin
|
|
|
548
572
|
// After cancel the batch stays stopped; a forwarded operation cannot reopen it.
|
|
549
573
|
const g=fixture();
|
|
550
574
|
try{
|
|
551
|
-
const stopped=await execute(g,
|
|
552
|
-
const after=await execute(g,
|
|
575
|
+
const stopped=await execute(g,{cancel:true});assert.equal(stopped.result.code,'cancelled');
|
|
576
|
+
const after=await execute(g,{args:['--allow-develop-redo','1.work/T-001'],operations:[redo]});
|
|
553
577
|
assert.deepEqual([after.result.outcome,after.result.code],['blocked','cancelled']);
|
|
554
578
|
}finally{fs.rmSync(g.root,{recursive:true,force:true});}
|
|
555
579
|
}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).
|
|
@@ -18,7 +18,9 @@ import {approvedTaskGrammar} from '../runtime/js/spec-task-line.mjs';
|
|
|
18
18
|
import {createHostCheck} from '../runtime/js/cm-ai/host-check.mjs';
|
|
19
19
|
import {inspectRunClosure as inspectClosure} from './cm-log-event.mjs';
|
|
20
20
|
import {releaseVerifiedQaResources} from '../runtime/js/cm-ai/qa-resource-release.mjs';
|
|
21
|
-
import {readRunnerHistory} from '../runtime/js/cm-ai/durable-runner-state.mjs';
|
|
21
|
+
import {readRunnerHistory,projectedRunnerStatus} from '../runtime/js/cm-ai/durable-runner-state.mjs';
|
|
22
|
+
import {readExecutionSnapshot} from '../runtime/js/cm-ai/execution-snapshot.mjs';
|
|
23
|
+
import {readControlPolicy,controlTarget,readControlTarget} from '../runtime/js/cm-ai/control-policy.mjs';
|
|
22
24
|
import {strictPriorAttemptResolved,sameTaskPriorAttemptResolved} from '../runtime/js/cm-ai/external-run-guard.mjs';
|
|
23
25
|
|
|
24
26
|
const writer=fileURLToPath(new URL('./cm-log-event.py',import.meta.url));
|
|
@@ -89,7 +91,8 @@ export function memberSupersedeAdmitted(specsDir,runId,history){
|
|
|
89
91
|
export function createCmAiBatch({configuration,executionFor,logHome,runtime='codex',checkCommands=null,checkTimeoutMs=60000,
|
|
90
92
|
rerunUnknownQa=false,rerunBlockedQa=false,qaEnvironmentFailure=null,holdRevisions=[],bootstrapKeys=[],memberActions={}}){
|
|
91
93
|
const config=json(configuration);
|
|
92
|
-
shape(config,['version','repositoryId','batchId','specsDir','codeProject','tasks',...['externalModels','executionPolicy','codeProjects','parallel'].filter(name=>Object.hasOwn(config,name))]);
|
|
94
|
+
shape(config,['version','repositoryId','batchId','specsDir','codeProject','tasks',...['externalModels','executionPolicy','codeProjects','parallel','controlPolicy'].filter(name=>Object.hasOwn(config,name))]);
|
|
95
|
+
const controlPolicy=config.controlPolicy?readControlPolicy(config.controlPolicy):null;
|
|
93
96
|
need(config.version===1);id(config.repositoryId);id(config.batchId);need(config.batchId.length>=8);
|
|
94
97
|
need(typeof executionFor==='function'&&typeof logHome==='string'&&path.isAbsolute(logHome));
|
|
95
98
|
need(Array.isArray(config.tasks)&&config.tasks.length>0&&config.tasks.length<=256);
|
|
@@ -135,6 +138,16 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
135
138
|
const groups=validateGroups(config,plans),membership=new Map(groups.flatMap(group=>group.map(key=>[key,group])));
|
|
136
139
|
const originalMembership=new Map(membership),originalPlans=new Map(plans);
|
|
137
140
|
const first=plans.keys().next().value,planDigest=digest(config),log=path.join(config.specsDir,'运行日志.jsonl');
|
|
141
|
+
const batchControlTarget=async(taskKey,state=progress())=>{
|
|
142
|
+
const definition=plans.get(taskKey);need(definition,'batch_member_action_unavailable');
|
|
143
|
+
if(membership.has(taskKey))bindWorktree(taskKey);
|
|
144
|
+
const run=await open(taskKey);need(run.controlHost,'fingerprint_mismatch');
|
|
145
|
+
try{
|
|
146
|
+
const observed=await run.controlHost.handle({version:2,operation:'status',requestId:'control-preview',identity:definition.identity});
|
|
147
|
+
return {version:2,batchId:config.batchId,taskKey,member:observed.controlTarget,
|
|
148
|
+
batchDigest:digest({planDigest,rows:state.rows})};
|
|
149
|
+
}finally{run.close();}
|
|
150
|
+
};
|
|
138
151
|
// Q26: before any closure check, close cleanup_failed QA command resources whose
|
|
139
152
|
// journaled process group the host proves gone (qa-resource-release.mjs).
|
|
140
153
|
let stillOpen=[];
|
|
@@ -521,7 +534,7 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
521
534
|
?membership.get(state.current).filter(key=>membership.has(key)&&!state.ready?.has(key)&&!state.done?.has(key)):[state.current];
|
|
522
535
|
if(!stopped.includes(taskKey))return refuse('batch_member_action_not_current',
|
|
523
536
|
`批次当前停在 ${stopped.join('、')};恢复操作只转给当前停住的成员,不跨成员`);
|
|
524
|
-
if(!actionGrants.get(request.operation).has(taskKey))return refuse('batch_member_action_authorization_required',
|
|
537
|
+
if(!controlPolicy&&!actionGrants.get(request.operation).has(taskKey))return refuse('batch_member_action_authorization_required',
|
|
525
538
|
`${request.operation} 需要批次宿主启动参数 ${flag} ${taskKey};关闭批次宿主,带上该参数用同一批次配置重新启动后再发送`);
|
|
526
539
|
if(membership.has(taskKey))bindWorktree(taskKey);
|
|
527
540
|
const definition=plans.get(taskKey);
|
|
@@ -530,15 +543,19 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
530
543
|
const run=await open(taskKey,{[option]:true});
|
|
531
544
|
if(run.blocked)return {outcome:'blocked',code:run.blocked.reason,batchId:config.batchId};
|
|
532
545
|
try{
|
|
533
|
-
const result=await run.
|
|
534
|
-
identity:
|
|
546
|
+
const result=controlPolicy?await run.controlHost.handle({version:2,operation:request.operation,requestId:request.requestId,
|
|
547
|
+
identity:request.expectedControl.member.identity,reason:request.reason,expectedControl:request.expectedControl.member})
|
|
548
|
+
:await run.host.handle({version:1,operation:request.operation,requestId:request.requestId,
|
|
549
|
+
identity:definition.identity,reason:request.reason});
|
|
535
550
|
actionGrants.get(request.operation).delete(taskKey);
|
|
536
551
|
return {...result,batchId:config.batchId,taskKey};
|
|
537
552
|
}finally{run.close();}
|
|
538
553
|
}
|
|
539
|
-
return Object.freeze({async handle(raw){
|
|
554
|
+
return Object.freeze({controlTarget:()=>batchControlTarget(progress().current),async handle(raw){
|
|
540
555
|
const request=json(raw);shape(request,['operation','requestId',...(request.operation==='reconcile_review'?['taskKey','invocationId']:[]),
|
|
541
|
-
...(Object.hasOwn(BATCH_MEMBER_ACTIONS,request.operation??'')?['taskKey','reason']:[])
|
|
556
|
+
...(Object.hasOwn(BATCH_MEMBER_ACTIONS,request.operation??'')?['taskKey','reason']:[]),
|
|
557
|
+
...(controlPolicy?['version',...((IN_RUN_ACTIONS.has(request.operation??''))?['expectedControl']:[])]:[])]);id(request.requestId);
|
|
558
|
+
if(controlPolicy)need(request.version===2,'fingerprint_mismatch');
|
|
542
559
|
need(['advance','status','cancel','reconcile_review',...Object.keys(BATCH_MEMBER_ACTIONS)].includes(request.operation));
|
|
543
560
|
if(request.operation==='cancel'&&busy){
|
|
544
561
|
cancelled=true;
|
|
@@ -557,6 +574,13 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
557
574
|
try{
|
|
558
575
|
releaseLock=acquireBatchLock(config);
|
|
559
576
|
const initial=progress();liveKey=initial.current;
|
|
577
|
+
if(controlPolicy&&IN_RUN_ACTIONS.has(request.operation)){
|
|
578
|
+
const expected=json(request.expectedControl);shape(expected,['version','batchId','taskKey','member','batchDigest']);
|
|
579
|
+
readControlTarget(expected.member);hex(expected.batchDigest);
|
|
580
|
+
if(membership.has(request.taskKey))bindWorktree(request.taskKey);
|
|
581
|
+
need(expected.version===2&&expected.batchId===config.batchId&&expected.taskKey===request.taskKey
|
|
582
|
+
&&expected.batchDigest===digest({planDigest,rows:initial.rows}),'snapshot_changed');
|
|
583
|
+
}
|
|
560
584
|
const {externalModels:ignoredModels,executionPolicy:ignoredPolicy,...policyBatch}=config;
|
|
561
585
|
const policy=readBatchExecutionPolicy({batch:policyBatch,started:initial.rows.length>0,enabled:!!config.executionPolicy});
|
|
562
586
|
need(digest(policy)===digest(config.executionPolicy??null),'execution_policy_batch_binding');
|
|
@@ -569,7 +593,9 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
569
593
|
const definition=plans.get(request.taskKey);
|
|
570
594
|
need(fs.existsSync(path.join(config.specsDir,'.reviews','.execution',definition.identity.runId,'state.json')),'review_reconciliation_unavailable');
|
|
571
595
|
const run=await open(request.taskKey);
|
|
572
|
-
try{return await run.
|
|
596
|
+
try{return controlPolicy?await run.controlHost.handle({version:2,operation:'reconcile_review',requestId:request.requestId,
|
|
597
|
+
identity:request.expectedControl.member.identity,invocationId:request.invocationId,expectedControl:request.expectedControl.member})
|
|
598
|
+
:await run.host.handle({version:1,operation:'reconcile_review',requestId:request.requestId,identity:definition.identity,invocationId:request.invocationId});}
|
|
573
599
|
finally{run.close();}
|
|
574
600
|
}
|
|
575
601
|
if(initial.stopped)return {outcome:'blocked',code:initial.code??'cancelled',batchId:config.batchId};
|
|
@@ -85,13 +85,7 @@ function open(f,taskId,mode='create',overrides={}){
|
|
|
85
85
|
return {status:'succeeded',value:{verdict:revise?'changes_requested':'approved',packageDigest:request.payload.reviewPackage.packageDigest,
|
|
86
86
|
examinedPaths:reviewPaths(request.payload.reviewPackage),findings:revise?[{id:'F1',severity:'P2',path:'AGENTS.md',
|
|
87
87
|
message:'Reverify instruction applicability',evidence:'Synthetic revision fixture'}]:[],summary:'Synthetic independent review'}};}}],
|
|
88
|
-
reviewInvocation:{developerThreadId:'scaffold-author',excludedThreadIds:['main'],
|
|
89
|
-
const body={version:1,kind:'cm-review-dispatch-grant',grantId:'grant-'+request.identity.attempt,adapterId:'codex-review-adapter',
|
|
90
|
-
invocationId:request.invocationId,requestDigest:request.requestDigest,identity:request.identity,reviewerId:'reviewer',
|
|
91
|
-
logicalContextId:request.contextId,packageDigest:request.payload.reviewPackage.packageDigest,hostContextId:'main',
|
|
92
|
-
decisionId:'decision-'+request.identity.attempt,decision:'approved',issuedAt:authorizationAt,expiresAt:authorizationAt+60000};
|
|
93
|
-
return {...body,grantDigest:digest(body)};
|
|
94
|
-
}},
|
|
88
|
+
reviewInvocation:{developerThreadId:'scaffold-author',excludedThreadIds:['main']},
|
|
95
89
|
check:createHostCheck({cwd:f.codeProject,timeoutMs:1000,commands:[{id:'syntax',command:[process.execPath,'--check','app.mjs']}]}),
|
|
96
90
|
taskCompletion:{reviewsDir:path.join(f.specsDir,'.reviews'),handoffs:[1,2].map(a=>path.join(f.specsDir,'.reviews',`bootstrap-${taskId}-a${a}-handoff.json`))},
|
|
97
91
|
persistence:{store,mode,version:3}});
|
|
@@ -43,7 +43,7 @@ function prepareCli(f){
|
|
|
43
43
|
for(const [name,value] of Object.entries(files))fs.writeFileSync(path.join(f.root,name+'.json'),JSON.stringify(value));
|
|
44
44
|
return {cli,env,args:['serve','--config',config,'--mode','create','--host-context','bootstrap-current-host','--allow-development',
|
|
45
45
|
'--protected-conversation-config',path.join(f.root,'protection.json'),'--bootstrap-config',path.join(f.root,'bootstrap.json'),
|
|
46
|
-
'--allow-bootstrap-write','--review-config',path.join(f.root,'review.json'),
|
|
46
|
+
'--allow-bootstrap-write','--review-config',path.join(f.root,'review.json'),
|
|
47
47
|
'--workflow-config',path.join(f.root,'workflow.json'),'--allow-qa']};
|
|
48
48
|
}
|
|
49
49
|
|
|
@@ -67,8 +67,7 @@ function runCli(f,config,mode,operation){
|
|
|
67
67
|
if(['init_generate','init_verify'].includes(row.kind)){assert(mode==='create'||f.resumeInit);
|
|
68
68
|
response=reply(f,row.kind,row.payload);
|
|
69
69
|
if(row.kind==='init_verify'&&f.failVerify>0){f.failVerify--;response.checks.commands={status:'failed',evidence:'npm test exited 1'};}}
|
|
70
|
-
else if(row.kind==='qa_assess')response={
|
|
71
|
-
changes:{api:false,migration:false,authentication:false,authorization:false,payment:false}};
|
|
70
|
+
else if(row.kind==='qa_assess')response={confirmed:true};
|
|
72
71
|
else if(row.kind==='documentation_inspect'){
|
|
73
72
|
const {syncId,identity,packageDigest,contextDigest}=row.payload;
|
|
74
73
|
response={syncId,identity,packageDigest,contextDigest,status:'completed',reason:'Fixture instructions inspected; no documentation paths configured',
|