@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.
Files changed (165) hide show
  1. package/.codex-plugin/plugin.json +1 -1
  2. package/AGENTS.md +4 -0
  3. package/CHANGELOG.md +18 -1
  4. package/CONTRIBUTING.md +47 -0
  5. package/README.md +16 -1
  6. package/VERSION +1 -1
  7. package/docs/architecture.md +29 -13
  8. package/docs/cm-control-policy-v2.md +331 -0
  9. package/docs/execution-optimizations.md +1 -1
  10. package/docs/external-models.md +3 -3
  11. package/docs/fixes/20261013-claude-preinit-ui-invalidate.md +48 -0
  12. package/docs/human-correction.md +5 -5
  13. package/docs/installation.md +1 -1
  14. package/docs/js-workflow-control.md +104 -85
  15. package/docs/next-steps.md +11 -0
  16. package/docs/untested-branches.md +2 -3
  17. package/docs/user-guide.md +3 -3
  18. package/package.json +1 -1
  19. package/runtime/js/cm-ai/claude-review-stream.mjs +12 -8
  20. package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +13 -69
  21. package/runtime/js/cm-ai/cm-ai-qa-log.mjs +10 -5
  22. package/runtime/js/cm-ai/control-policy.mjs +112 -0
  23. package/runtime/js/cm-ai/drive-bootstrap.mjs +11 -8
  24. package/runtime/js/cm-ai/drive-core.mjs +124 -25
  25. package/runtime/js/cm-ai/durable-runner-state.mjs +32 -126
  26. package/runtime/js/cm-ai/gate-bridge.mjs +4 -4
  27. package/runtime/js/cm-ai/host-check.mjs +3 -1
  28. package/runtime/js/cm-ai/host-conversation-execution.mjs +22 -20
  29. package/runtime/js/cm-ai/host-qa-fix-owner.mjs +11 -2
  30. package/runtime/js/cm-ai/host-qa-policy.mjs +63 -21
  31. package/runtime/js/cm-ai/host-review-authority.mjs +2 -2
  32. package/runtime/js/cm-ai/host-review-file.mjs +1 -1
  33. package/runtime/js/cm-ai/host-session.mjs +41 -8
  34. package/runtime/js/cm-ai/host-stage-observer.mjs +26 -0
  35. package/runtime/js/cm-ai/host-tool-bridge.mjs +25 -9
  36. package/runtime/js/cm-ai/host-workflow-capabilities.mjs +21 -10
  37. package/runtime/js/cm-ai/host.mjs +1 -2
  38. package/runtime/js/cm-ai/operator-guidance.mjs +57 -54
  39. package/runtime/js/cm-ai/review-package.mjs +16 -4
  40. package/runtime/js/cm-ai/reviewed-deliveries.mjs +1 -1
  41. package/runtime/js/cm-ai/task-runner.mjs +41 -101
  42. package/runtime/js/cm-init/review-evidence.mjs +3 -1
  43. package/runtime/js/cm-prd/review-host.mjs +1 -1
  44. package/runtime/js/cm-prd/review-publication.mjs +5 -3
  45. package/runtime/js/cm-prd/summary.mjs +27 -12
  46. package/runtime/js/cm-refactor/workflow.mjs +1 -1
  47. package/runtime/js/notify-send.mjs +15 -14
  48. package/runtime/js/notify.mjs +27 -4
  49. package/runtime/js/policy-binding-compat.mjs +2 -1
  50. package/runtime/review.md +61 -7
  51. package/runtime/task-gates.md +107 -9
  52. package/scripts/cm-ai-abandon-effect-position.test.mjs +1 -8
  53. package/scripts/cm-ai-answer-gap-driver.test.mjs +12 -12
  54. package/scripts/cm-ai-answer-gap-fixture.mjs +1 -8
  55. package/scripts/cm-ai-batch-drive.mjs +50 -31
  56. package/scripts/cm-ai-batch-drive.test.mjs +62 -19
  57. package/scripts/cm-ai-batch-host.mjs +39 -20
  58. package/scripts/cm-ai-batch-host.test.mjs +83 -47
  59. package/scripts/cm-ai-batch-run-fixture.mjs +6 -53
  60. package/scripts/cm-ai-batch-run-member-stops.test.mjs +0 -12
  61. package/scripts/cm-ai-batch-run.mjs +46 -14
  62. package/scripts/cm-ai-bootstrap-flow.test.mjs +1 -7
  63. package/scripts/cm-ai-bootstrap.test.mjs +2 -3
  64. package/scripts/cm-ai-control-launch.test.mjs +219 -0
  65. package/scripts/cm-ai-control-policy.test.mjs +192 -0
  66. package/scripts/cm-ai-control-v2-drive.test.mjs +270 -0
  67. package/scripts/cm-ai-develop-answer-invalid.test.mjs +1 -8
  68. package/scripts/cm-ai-develop-call-timeout.test.mjs +1 -8
  69. package/scripts/cm-ai-develop-driver-gaps.test.mjs +33 -20
  70. package/scripts/cm-ai-direct-review.test.mjs +348 -0
  71. package/scripts/cm-ai-documentation-sync-gap.test.mjs +3 -3
  72. package/scripts/cm-ai-drive-bootstrap-rules.test.mjs +57 -27
  73. package/scripts/cm-ai-drive.mjs +96 -54
  74. package/scripts/cm-ai-drive.test.mjs +46 -87
  75. package/scripts/cm-ai-fix-integration.test.mjs +3 -5
  76. package/scripts/cm-ai-fix-later-delivery.test.mjs +3 -6
  77. package/scripts/cm-ai-fix-run-delivery.test.mjs +3 -6
  78. package/scripts/cm-ai-host-cli-workflow.test.mjs +6 -10
  79. package/scripts/cm-ai-host-fixture.mjs +47 -16
  80. package/scripts/cm-ai-host-protected.test.mjs +35 -33
  81. package/scripts/cm-ai-host.mjs +103 -93
  82. package/scripts/cm-ai-host.test.mjs +34 -18
  83. package/scripts/cm-ai-launch-diagnostics.test.mjs +5 -3
  84. package/scripts/cm-ai-legacy-history.test.mjs +53 -0
  85. package/scripts/cm-ai-light-modules.test.mjs +4 -7
  86. package/scripts/cm-ai-multi-root.test.mjs +4 -4
  87. package/scripts/cm-ai-nested-execution.test.mjs +16 -19
  88. package/scripts/cm-ai-operator-guidance.test.mjs +56 -0
  89. package/scripts/cm-ai-progress.test.mjs +10 -8
  90. package/scripts/cm-ai-project-qa-gate.test.mjs +37 -10
  91. package/scripts/cm-ai-protected-scope.test.mjs +1 -2
  92. package/scripts/cm-ai-qa-config-revision.test.mjs +1 -9
  93. package/scripts/cm-ai-qa-fingerprint-config.test.mjs +12 -9
  94. package/scripts/cm-ai-qa-fix-cross-session.test.mjs +18 -3
  95. package/scripts/cm-ai-qa-fixed-log.test.mjs +41 -0
  96. package/scripts/cm-ai-qa-recovery-args.test.mjs +7 -0
  97. package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +3 -4
  98. package/scripts/cm-ai-review-drift-precedence.test.mjs +1 -1
  99. package/scripts/cm-ai-review-failure.test.mjs +13 -19
  100. package/scripts/cm-ai-review-timeout-config.test.mjs +3 -1
  101. package/scripts/cm-ai-review-timeout.test.mjs +35 -128
  102. package/scripts/cm-ai-run.mjs +78 -24
  103. package/scripts/cm-ai-run.test.mjs +11 -38
  104. package/scripts/cm-ai-selection-guard.test.mjs +2 -2
  105. package/scripts/cm-ai-session-chain.test.mjs +18 -15
  106. package/scripts/cm-ai-spec-rebind.test.mjs +14 -18
  107. package/scripts/cm-ai-supersede.test.mjs +3 -10
  108. package/scripts/cm-blocked-reason.test.mjs +2 -3
  109. package/scripts/cm-capability-gate.test.mjs +33 -1
  110. package/scripts/cm-check-drive-files.mjs +1 -1
  111. package/scripts/cm-check-host.test.mjs +1 -1
  112. package/scripts/cm-check-runtime.sh +1 -1
  113. package/scripts/cm-claude-probe.test.mjs +26 -0
  114. package/scripts/cm-claude-review-stream.test.mjs +36 -0
  115. package/scripts/cm-claude-worker.test.mjs +21 -3
  116. package/scripts/cm-controlled-correction.test.mjs +469 -0
  117. package/scripts/cm-drive-liveness.test.mjs +83 -0
  118. package/scripts/cm-external-batch-host.test.mjs +38 -17
  119. package/scripts/cm-external-model-host.test.mjs +1 -1
  120. package/scripts/cm-external-model-recovery.test.mjs +3 -9
  121. package/scripts/cm-external-qa-fix.test.mjs +1 -1
  122. package/scripts/cm-external-review-reconciliation.test.mjs +6 -24
  123. package/scripts/cm-fix-review-recovery.test.mjs +1 -1
  124. package/scripts/cm-host-diagnostic.test.mjs +33 -0
  125. package/scripts/cm-host-liveness.test.mjs +150 -0
  126. package/scripts/cm-host-qa-executor.test.mjs +1 -2
  127. package/scripts/cm-host-qa-policy.test.mjs +43 -16
  128. package/scripts/cm-host-review-authority.test.mjs +0 -31
  129. package/scripts/cm-host-stage-observer.test.mjs +41 -0
  130. package/scripts/cm-knowledge-closeout.test.mjs +3 -3
  131. package/scripts/cm-notify-command.test.mjs +54 -18
  132. package/scripts/cm-notify-read-drift.test.mjs +69 -4
  133. package/scripts/cm-notify.mjs +16 -4
  134. package/scripts/cm-notify.test.mjs +135 -29
  135. package/scripts/cm-patrol.test.mjs +3 -2
  136. package/scripts/cm-prd-drive.test.mjs +1 -1
  137. package/scripts/cm-prd-self-check-revision.test.mjs +15 -0
  138. package/scripts/cm-prd-session-recovery.test.mjs +5 -3
  139. package/scripts/cm-prd-summary.test.mjs +31 -0
  140. package/scripts/cm-release-smoke.sh +2 -14
  141. package/scripts/cm-task-gate-correction.test.mjs +69 -16
  142. package/scripts/cm-task-gate.mjs +368 -34
  143. package/scripts/cm-task-gate.py +2 -0
  144. package/scripts/cm-task-gate.test.mjs +252 -4
  145. package/scripts/cm-test-suite.mjs +109 -0
  146. package/scripts/cm-test-suite.test.mjs +162 -0
  147. package/scripts/fixtures/bootstrap-review-runner.mjs +1 -7
  148. package/scripts/fixtures/host-diagnostic.mjs +33 -0
  149. package/scripts/fixtures/native-gate-fixture.mjs +18 -0
  150. package/scripts/policy-binding-compat.test.mjs +4 -0
  151. package/skills/cm-ai/SKILL.md +8 -6
  152. package/skills/cm-ai/references/N3-execute-task.md +17 -2
  153. package/skills/cm-ai/references/N4-review.md +11 -21
  154. package/skills/cm-ai/references/N5-mark-done.md +1 -1
  155. package/skills/cm-ai/references/N6-qa-eval.md +49 -21
  156. package/skills/cm-ai/references/js-host-modes.md +35 -14
  157. package/skills/cm-ai/references/js-host-qa-recovery.md +60 -12
  158. package/skills/cm-ai/references/js-host-recovery.md +95 -47
  159. package/skills/cm-ai/references/js-host.md +98 -29
  160. package/skills/cm-fix/SKILL.md +12 -0
  161. package/skills/cm-init/references/js-host.md +1 -1
  162. package/skills/cm-prd/references/js-host.md +1 -1
  163. package/skills/cm-refactor/SKILL.md +12 -0
  164. package/runtime/js/cm-ai/review-dispatch-limits.mjs +0 -18
  165. package/scripts/cm-ai-review-dispatch-exit.test.mjs +0 -475
@@ -0,0 +1,270 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import fs from 'node:fs';
4
+ import os from 'node:os';
5
+ import path from 'node:path';
6
+ import {spawnSync} from 'node:child_process';
7
+ import {fileURLToPath} from 'node:url';
8
+ import {buildManifest} from './cm-spec-manifest.mjs';
9
+ import {configFingerprint} from '../runtime/js/cm-ai/codex-config.mjs';
10
+ import {readDriverControl,controlDevelopAttempts,buildCmAiDriveHostArgs,buildCmAiDriveRequest} from './cm-ai-drive.mjs';
11
+ import {batchDevelopAttempts,buildCmAiBatchDriveHostArgs,buildCmAiBatchDriveRequest} from './cm-ai-batch-drive.mjs';
12
+ import {inspectDriverBootstrap} from '../runtime/js/cm-ai/drive-bootstrap.mjs';
13
+ import {createHostWorkflowCapabilities} from '../runtime/js/cm-ai/host-workflow-capabilities.mjs';
14
+
15
+ const SINGLE=fileURLToPath(new URL('./cm-ai-drive.mjs',import.meta.url));
16
+ const BATCH=fileURLToPath(new URL('./cm-ai-batch-drive.mjs',import.meta.url));
17
+ const REVIEW=fileURLToPath(new URL('./fixtures/codex-review-process.mjs',import.meta.url));
18
+ const policy={version:2,development:'conversation',bootstrap:'disabled',qa:'disabled',qaFix:'disabled'};
19
+ const identity={repositoryId:'v2-drive-fixture',runId:'v2-drive-run',taskId:'T-001',attempt:1};
20
+ const key='1.work/T-001';
21
+ const answer={status:'succeeded',value:{outcome:'implemented',application:{status:'no_relevant_lesson',note:null},
22
+ retrospective:{status:'no_new_lesson',candidates:[],reason:null}},edits:{'target.mjs':'target.txt'}};
23
+ function fixture(t,batch=false,qaRun=false){
24
+ const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-v2-drive-')));
25
+ t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
26
+ const specsDir=path.join(root,'specs5'),codeProject=path.join(root,'app'),bin=path.join(root,'bin');
27
+ fs.mkdirSync(path.join(specsDir,'1.work'),{recursive:true});fs.mkdirSync(codeProject);fs.mkdirSync(bin);
28
+ for(const name of ['requirements.md','design.md'])fs.writeFileSync(path.join(specsDir,'1.work',name),'# Fixture\n');
29
+ fs.writeFileSync(path.join(specsDir,'1.work/tasks.md'),'- [ ] T-001: fixture\n');
30
+ fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:['1.work'],specFiles:buildManifest(specsDir)}));
31
+ fs.writeFileSync(path.join(codeProject,'requirements.md'),'# Fixture\n');
32
+ if(batch)for(const args of [['init','-b','main'],['config','user.name','Fixture'],['config','user.email','fixture@example.invalid'],['add','-A'],['commit','-m','baseline']]){
33
+ const r=spawnSync('git',['-C',codeProject,...args],{encoding:'utf8'});assert.equal(r.status,0,r.stderr);
34
+ }
35
+ const definition={version:1,specsDir,codeProject,feature:'1.work',identity,scope:['target.mjs'],requirements:['requirements.md']};
36
+ const config=batch?{batch:{version:1,repositoryId:identity.repositoryId,batchId:'v2-batch-drive-run',specsDir,codeProject,
37
+ tasks:[{feature:'1.work',taskId:'T-001',scope:['target.mjs'],requirements:['requirements.md']}]},
38
+ workflows:{[key]:{qa:qaRun?{commands:[{id:'value',caseIds:[],command:[process.execPath,'-e',
39
+ "import('./target.mjs').then(m=>{if(m.value!==43)process.exit(1)})"]}],
40
+ environment:{kind:'web',carrier:'browser',target:'fixture-target',scope:'local'}}:null,
41
+ documentationPaths:[],applicableAgentFiles:[]}}}:definition;
42
+ fs.writeFileSync(path.join(root,'run.json'),JSON.stringify(config));
43
+ fs.writeFileSync(path.join(root,'control.json'),JSON.stringify({...policy,...(qaRun?{qa:'run'}:{})}));
44
+ fs.writeFileSync(path.join(root,'review.json'),JSON.stringify({model:'fixture',preflight:{passed:true,cli_model:'fixture',
45
+ prompt_transport:'stdin',config_fingerprint:configFingerprint({cwd:codeProject,model:'fixture'})}}));
46
+ const answers=path.join(root,'answers',...(batch?['1.work','T-001']:[]));fs.mkdirSync(answers,{recursive:true});
47
+ fs.writeFileSync(path.join(answers,'develop.json'),JSON.stringify(answer));
48
+ fs.writeFileSync(path.join(answers,'target.txt'),'export const value = 42;\n');
49
+ fs.writeFileSync(path.join(answers,'documentation-inspect.json'),JSON.stringify({status:'completed',reason:'Fixture inspected'}));
50
+ fs.writeFileSync(path.join(answers,'qa-assess.json'),JSON.stringify({confirmed:true}));
51
+ const review=verdict=>{
52
+ let source=fs.readFileSync(REVIEW,'utf8');
53
+ if(verdict==='changes_requested')source=source.replace("verdict:'approved'","verdict:'changes_requested'")
54
+ .replace('findings:[]',"findings:[{id:'F1',severity:'P2',path:'target.mjs',message:'Revise value',evidence:'Fixture finding'}]");
55
+ fs.writeFileSync(path.join(bin,'codex'),source,{mode:0o700});
56
+ };review('changes_requested');
57
+ const plan=extra=>{
58
+ const file=path.join(root,`plan-${Math.random().toString(36).slice(2)}.json`);
59
+ fs.writeFileSync(file,JSON.stringify({config:'run.json',mode:'create',hostContext:'v2-fixture-host',controlConfig:'control.json',
60
+ permissions:['--review-config','review.json'],answers:'answers',
61
+ checks:batch?{[key]:[{id:'syntax',command:[process.execPath,'--check','target.mjs']}]}:[{id:'syntax',command:[process.execPath,'--check','target.mjs']}],...extra}));
62
+ return file;
63
+ };
64
+ const drive=(file,operation='advance')=>spawnSync(process.execPath,[batch?BATCH:SINGLE,'--plan',file,operation],{encoding:'utf8',timeout:60000,
65
+ env:{...process.env,PATH:bin+path.delimiter+process.env.PATH,CM_WORKFLOW_HOME:path.join(root,'home'),CM_WORKFLOW_LOG_HOME:path.join(root,'logs')}});
66
+ return {root,codeProject,specsDir,answers,plan,drive,review};
67
+ }
68
+
69
+ test('v2 launch arguments replace the development grant and leave legacy launch intact',()=>{
70
+ const plan={mode:'create',hostContext:'host',controlConfig:'policy.json'};
71
+ assert.deepEqual(buildCmAiDriveHostArgs(plan,[],'run.json','/fixture/policy.json').slice(0,9),
72
+ ['serve','--config','run.json','--mode','create','--host-context','host','--control-config','/fixture/policy.json']);
73
+ assert.deepEqual(buildCmAiBatchDriveHostArgs(plan,[],'batch.json','/fixture/policy.json').slice(0,9),
74
+ ['serve','--config','batch.json','--mode','create','--host-context','host','--control-config','/fixture/policy.json']);
75
+ assert.ok(buildCmAiDriveHostArgs({mode:'create',hostContext:'host'},[],'run.json').includes('--allow-development'));
76
+ assert.deepEqual(buildCmAiBatchDriveHostArgs({mode:'create',hostContext:'host'},[],'run.json'),
77
+ ['serve','--config','run.json','--host-context','host','--allow-development']);
78
+ });
79
+ test('v2 batch accepts direct policy launch with or without mode',t=>{
80
+ const host=fileURLToPath(new URL('./cm-ai-batch-host.mjs',import.meta.url));
81
+ for(const mode of [null,'create','resume']){
82
+ const f=fixture(t,true),context='direct-v2-'+(mode??'no-mode');
83
+ const args=['serve','--config',path.join(f.root,'run.json'),
84
+ ...(mode?['--mode',mode]:[]),'--host-context',context,'--control-config',path.join(f.root,'control.json'),
85
+ '--review-config',path.join(f.root,'review.json')];
86
+ const request={version:2,operation:'status',requestId:'direct-status'};
87
+ const result=spawnSync(process.execPath,[host,...args],{encoding:'utf8',timeout:20000,
88
+ input:JSON.stringify(request)+'\n',env:{...process.env,CM_WORKFLOW_HOME:path.join(f.root,'home'),
89
+ CM_WORKFLOW_LOG_HOME:path.join(f.root,'logs')}});
90
+ assert.equal(result.status,0,result.stderr);
91
+ const rows=result.stdout.trim().split('\n').map(JSON.parse);
92
+ assert.equal(rows[0].type,'host_ready');
93
+ const response=rows.find(row=>row.requestId==='direct-status');assert.ok(response,result.stdout);
94
+ assert.notEqual(response.result.outcome,'rejected',result.stdout);
95
+ assert.ok(response.result.state,result.stdout);
96
+ }
97
+ });
98
+
99
+ test('v2 policy determines both rounds independently of legacy grant flags',()=>{
100
+ assert.deepEqual(controlDevelopAttempts({state:'ready',attempt:1},'advance').attempts,[1,2]);
101
+ assert.deepEqual(controlDevelopAttempts({state:'awaiting_review',attempt:1},'advance').attempts,[2]);
102
+ assert.deepEqual(controlDevelopAttempts({state:'changes_requested',attempt:2},'advance').attempts,[2]);
103
+ assert.deepEqual(batchDevelopAttempts({state:'ready',attempt:1},key,[],policy),[1,2]);
104
+ assert.deepEqual(batchDevelopAttempts({state:'ready',attempt:1},key,[],{...policy,development:'provider'}),[]);
105
+ assert.match(inspectDriverBootstrap({advance:true,definition:{},permissions:['--bootstrap-config','unused.json'],controlPolicy:policy}).gap,
106
+ /invalid_arguments.*bootstrap disabled/,'disabled bootstrap refuses its configured writer without reading it');
107
+ });
108
+ test('v2 recovery preserves the caller target while ordinary advance needs no target',t=>{
109
+ const f=fixture(t),base={controlConfig:'control.json',mode:'resume',permissions:[]};
110
+ assert.deepEqual(readDriverControl(base,f.root,'advance').policy,policy);
111
+ assert.throws(()=>readDriverControl(base,f.root,'develop_redo'),/expectedControl/);
112
+ const target={version:2,identity,state:'unknown',revision:'preview-bound'};
113
+ const p={...base,expectedControl:target};
114
+ assert.equal(buildCmAiDriveRequest('develop_redo',p,{identity}).expectedControl,target);
115
+ assert.equal(buildCmAiDriveRequest('advance',p,{identity}).expectedControl,undefined);
116
+ assert.equal(buildCmAiDriveRequest('advance',p,{identity}).version,2);
117
+ assert.equal(buildCmAiDriveRequest('advance',{},{identity}).version,1);
118
+ const attempt2={...p,expectedControl:{...target,identity:{...identity,attempt:2}}};
119
+ assert.equal(buildCmAiDriveRequest('develop_redo',attempt2,{identity},identity).identity.attempt,2,
120
+ 'recovery uses the preview identity rather than the definition or a new journal read');
121
+ const batchTarget={version:2,batchId:'batch',taskKey:key,member:target,batchDigest:'preview'};
122
+ assert.equal(buildCmAiBatchDriveRequest('develop_redo',{...p,taskKey:key,expectedControl:batchTarget}).expectedControl,batchTarget);
123
+ assert.throws(()=>readDriverControl({...p,mode:'create'},f.root,'advance'),/create 禁止/);
124
+ });
125
+ test('v2 always separates QA disposition from execution while qa:null keeps legacy behavior',()=>{
126
+ const options={definition:{specsDir:'/fixture/specs',codeProject:'/fixture/code',feature:'1.work',requirements:[]},
127
+ configuration:{qa:null,documentationPaths:[],applicableAgentFiles:[]},bridge:{call:async()=>{}},allowQa:false};
128
+ const old=createHostWorkflowCapabilities(options);
129
+ assert.equal(old.qaDecisionProvider,undefined);assert.equal(old.qaExecutor,undefined);
130
+ const v2=createHostWorkflowCapabilities({...options,controlPolicy:policy});
131
+ assert.equal(typeof v2.qaDecisionProvider.decide,'function');assert.equal(v2.qaExecutor,undefined);
132
+ const configured={...options,configuration:{...options.configuration,qa:{commands:[{id:'local',caseIds:[],command:[process.execPath,'-e','0']}],
133
+ environment:{kind:'web',carrier:'browser',target:'fixture-target',scope:'local'}}}};
134
+ assert.equal(createHostWorkflowCapabilities({...configured,controlPolicy:policy}).qaExecutor,undefined,
135
+ 'a stored execution recipe does not enable a disabled executor');
136
+ assert.throws(()=>createHostWorkflowCapabilities(configured),{code:'qa_authorization_required'},
137
+ 'legacy configured QA still requires its original authorization');
138
+ });
139
+ test('v2 rejects every allow flag as a migration error before opening a run',t=>{
140
+ const f=fixture(t);
141
+ for(const flag of ['--allow-development','--allow-review-attempt','--allow-unrecognized']){
142
+ const r=f.drive(f.plan({permissions:[flag,'1']}));assert.equal(r.status,2,r.stderr);
143
+ assert.match(r.stderr,/迁移错误.*--allow-\*/);
144
+ assert.equal(fs.existsSync(path.join(f.specsDir,'.reviews/.execution')),false);
145
+ }
146
+ });
147
+ test('disabled bootstrap and QA Fix refuse configured capabilities before reading their files',t=>{
148
+ const f=fixture(t);
149
+ for(const flag of ['--bootstrap-config','--qa-fix-owner-config','--qa-fix-template-config','--protected-config']){
150
+ const r=f.drive(f.plan({permissions:[flag,'missing.json']}));
151
+ assert.equal(r.status,2,r.stderr);assert.match(r.stderr,/invalid_arguments/);
152
+ assert.doesNotMatch(r.stderr,/文件不存在|ENOENT/);
153
+ assert.equal(fs.existsSync(path.join(f.specsDir,'.reviews/.execution')),false);
154
+ }
155
+ });
156
+ for(const batch of [false,true])test(`v2 ${batch?'batch':'single'} explicit recovery refuses missing preview before host launch`,t=>{
157
+ const f=fixture(t,batch);
158
+ const r=f.drive(f.plan({mode:'resume',originalHostContext:'v2-fixture-host',taskKey:key,reason:'Fixture stopped'}),'develop_redo');
159
+ assert.equal(r.status,2,r.stderr);assert.match(r.stderr,/expectedControl/);
160
+ assert.equal(fs.existsSync(path.join(f.specsDir,'.reviews/.execution')),false);
161
+ });
162
+ for(const batch of [false,true])test(`v2 ${batch?'batch':'single'} real host holds absent a2 and resumes with its own second-round answer`,t=>{
163
+ const f=fixture(t,batch,batch),first=f.drive(f.plan());
164
+ assert.equal(first.status,0,first.stderr);
165
+ const result=JSON.parse(first.stdout).result;
166
+ assert.equal(result.code,'revision_answer_required',first.stdout);
167
+ assert.match(first.stderr,/应答 develop/);assert.match(first.stderr,/develop-a2\.json/);
168
+ assert.equal(fs.readFileSync(path.join(f.codeProject,'target.mjs'),'utf8'),'export const value = 42;\n');
169
+ fs.writeFileSync(path.join(f.answers,'develop-a2.json'),JSON.stringify({...answer,edits:{'target.mjs':'second.txt'}}));
170
+ fs.writeFileSync(path.join(f.answers,'second.txt'),'export const value = 43;\n');f.review('approved');
171
+ const second=f.drive(f.plan({mode:'resume',originalHostContext:'v2-fixture-host'}));
172
+ assert.equal(second.status,0,second.stderr);
173
+ assert.equal(fs.readFileSync(path.join(f.codeProject,'target.mjs'),'utf8'),'export const value = 43;\n');
174
+ let result2=JSON.parse(second.stdout).result;
175
+ if(batch)for(let n=0;n<4&&result2.state!=='run_done';n++){
176
+ const next=f.drive(f.plan({mode:'resume',originalHostContext:'v2-fixture-host'}));
177
+ assert.equal(next.status,0,next.stderr);result2=JSON.parse(next.stdout).result;
178
+ }
179
+ assert.equal(result2.state,batch?'run_done':'fixture_completed',second.stdout);
180
+ if(batch){
181
+ assert.match(second.stderr,/应答 qa_assess/);
182
+ assert.match(second.stderr,/检查结束.*value.*passed/,'actual QA command supplies the passed result');
183
+ const rows=fs.readFileSync(path.join(f.specsDir,'运行日志.jsonl'),'utf8').trim().split('\n').map(JSON.parse);
184
+ assert.ok(rows.some(row=>row.node==='N6'&&row.event==='test_run'&&row.phase==='complete'&&row.result==='PASS'));
185
+ }
186
+ });
187
+
188
+ test('v2 protected provider real host dispatches two fresh independent reviews after a rejected first round',t=>{
189
+ const f=fixture(t),bin=path.join(f.root,'bin'),witness=path.join(f.root,'protected-dispatch.jsonl');
190
+ fs.writeFileSync(path.join(f.root,'control.json'),JSON.stringify({...policy,development:'provider'}));
191
+ fs.writeFileSync(path.join(f.codeProject,'.cm-workflow.json'),JSON.stringify({version:1,runtimes:{available:'codex'},
192
+ roles:{coder:{adapter:'codex-cli'},reviewer:{adapter:'codex-cli'}}}));
193
+ fs.writeFileSync(path.join(f.root,'protected.json'),JSON.stringify({model:'fixture',timeoutMs:5000,
194
+ checkCommands:[{id:'syntax',command:[process.execPath,'--check','target.mjs']}]}));
195
+ // Only fixture Node processes run. The sandbox shim verifies the formal
196
+ // profile/command arguments; this witness does not test native OS isolation.
197
+ fs.writeFileSync(path.join(bin,'codex'),`#!${process.execPath}
198
+ const fs=require('node:fs'),cp=require('node:child_process'),assert=require('node:assert/strict');
199
+ const args=process.argv.slice(2),witness=${JSON.stringify(witness)};
200
+ const record=row=>fs.appendFileSync(witness,JSON.stringify(row)+'\\n');
201
+ if(args[0]==='sandbox'){
202
+ assert.equal(args[args.indexOf('-P')+1],'cm-specs');assert(args.includes('--include-managed-config'));
203
+ const settings=args.filter((_,index)=>args[index-1]==='-c');
204
+ assert(settings.includes('default_permissions="cm-specs"'));
205
+ assert(settings.some(value=>value.startsWith('permissions.cm-specs=')&&value.includes('network={enabled=false}')));
206
+ const command=args.slice(args.indexOf('--')+1);assert.deepEqual(command,[${JSON.stringify(process.execPath)},'--check','target.mjs']);
207
+ record({type:'check'});const checked=cp.spawnSync(command[0],command.slice(1),{cwd:process.cwd(),encoding:'utf8'});
208
+ process.stdout.write(checked.stdout??'');process.stderr.write(checked.stderr??'');process.exit(checked.status??1);
209
+ }
210
+ let prompt='';process.stdin.on('data',part=>prompt+=part);process.stdin.on('end',()=>{
211
+ let value,thread;
212
+ if(prompt.includes('<cm-developer-data-json>')){
213
+ const data=JSON.parse(prompt.split('<cm-developer-data-json>\\n')[1].split('\\n')[0]),attempt=data.identity.attempt;
214
+ assert.deepEqual(data.scope,['target.mjs']);assert.equal(data.specification.task.id,'T-001');
215
+ const settings=args.filter((_,index)=>args[index-1]==='-c');assert(settings.includes('default_permissions="cm-specs"'));
216
+ assert(args.includes('--output-schema'));record({type:'develop',attempt});
217
+ fs.writeFileSync('target.mjs','export const value = '+(41+attempt)+';\\n');
218
+ value={outcome:'implemented',application:{status:'no_relevant_lesson',note:null},
219
+ retrospective:{status:'no_new_lesson',candidates:[],reason:null}};thread='fixture-protected-author-'+attempt;
220
+ }else{
221
+ const data=JSON.parse(prompt.split('<cm-review-data-json>\\n')[1]),attempt=data.reviewPackage.identity.attempt;
222
+ assert.equal(args[args.indexOf('--sandbox')+1],'read-only');
223
+ if(attempt===2)assert.equal(data.priorReview.verdict,'changes_requested');
224
+ thread='fixture-protected-independent-review-'+attempt;
225
+ value={verdict:attempt===1?'changes_requested':'approved',packageDigest:data.reviewPackage.packageDigest,
226
+ examinedPaths:data.examinedPaths,findings:attempt===1?[{id:'F1',severity:'P2',path:'target.mjs',
227
+ message:'Use the revised constant',evidence:'First synthetic review rejects 42'}]:[],summary:'Synthetic independent review'};
228
+ record({type:'review',attempt,thread,verdict:value.verdict,packageDigest:value.packageDigest});
229
+ }
230
+ for(const event of [{type:'thread.started',thread_id:thread},{type:'turn.started'},
231
+ {type:'item.completed',item:{type:'agent_message',text:JSON.stringify(value)}},{type:'turn.completed'}])
232
+ process.stdout.write(JSON.stringify(event)+'\\n');
233
+ });
234
+ `,{mode:0o700});
235
+ const result=f.drive(f.plan({permissions:['--review-config','review.json','--protected-config','protected.json']}));
236
+ assert.equal(result.status,0,result.stderr);assert.equal(JSON.parse(result.stdout).result.state,'fixture_completed',result.stdout);
237
+ const dispatched=fs.readFileSync(witness,'utf8').trim().split('\n').map(JSON.parse),reviews=dispatched.filter(row=>row.type==='review');
238
+ assert.deepEqual(dispatched.filter(row=>row.type==='develop').map(row=>row.attempt),[1,2]);
239
+ assert.deepEqual(reviews.map(row=>[row.attempt,row.verdict]),[[1,'changes_requested'],[2,'approved']]);
240
+ assert.equal(new Set(reviews.map(row=>row.thread)).size,2);assert.notEqual(reviews[0].packageDigest,reviews[1].packageDigest);
241
+ assert.ok(dispatched.filter(row=>row.type==='check').length>=3,'both rounds and completion run the real syntax command');
242
+ assert.equal(fs.readFileSync(path.join(f.codeProject,'target.mjs'),'utf8'),'export const value = 43;\n');
243
+ assert.match(fs.readFileSync(path.join(f.specsDir,'1.work/tasks.md'),'utf8'),/\[x\] T-001/);
244
+ const state=JSON.parse(fs.readFileSync(path.join(f.specsDir,'.reviews','.execution',identity.runId,'state.json')));
245
+ const registrations=state.records.filter(row=>row.payload.type==='review-invocation-registered');
246
+ assert.deepEqual(registrations.map(row=>row.payload.binding.identity.attempt),[1,2]);
247
+ assert.equal(new Set(registrations.map(row=>row.payload.binding.invocationId)).size,2);
248
+ for(const row of registrations){assert.equal(Object.hasOwn(row.payload,'grant'),false);assert.equal(Object.hasOwn(row.payload,'authorizationAt'),false);}
249
+ assert.equal(state.records[0].payload.config.controlPolicy.development,'provider','v2 is bound in the actual durable run');
250
+ });
251
+ test('v2 disabled QA still assesses mandatory feature completion and cannot report run_done or passed',t=>{
252
+ const f=fixture(t,true);f.review('approved');
253
+ let r=f.drive(f.plan());assert.equal(r.status,0,r.stderr);
254
+ let result=JSON.parse(r.stdout).result,combined=r.stderr;
255
+ for(let n=0;n<3&&result.code!=='qa_triggered';n++){
256
+ r=f.drive(f.plan({mode:'resume',originalHostContext:'v2-fixture-host'}));assert.equal(r.status,0,r.stderr);
257
+ result=JSON.parse(r.stdout).result;combined+=r.stderr;
258
+ }
259
+ assert.match(combined,/应答 qa_assess/);
260
+ assert.equal(result.code,'qa_triggered',JSON.stringify(result));assert.equal(result.pendingAction,'qa_execution');
261
+ assert.notEqual(result.state,'run_done');
262
+ const rows=fs.readFileSync(path.join(f.specsDir,'运行日志.jsonl'),'utf8').trim().split('\n').map(JSON.parse);
263
+ assert.ok(rows.some(row=>row.event==='qa'&&row.status==='triggered'&&row.reason==='feature_complete'));
264
+ assert.equal(rows.some(row=>row.node==='N6'&&row.event==='test_run'&&row.phase==='complete'&&row.result==='PASS'),false);
265
+ });
266
+ test('batch refuses unavailable QA Fix mode before starting the host',t=>{
267
+ const f=fixture(t,true);fs.writeFileSync(path.join(f.root,'control.json'),JSON.stringify({...policy,qa:'run',qaFix:'auto'}));
268
+ const r=f.drive(f.plan());assert.equal(r.status,2,r.stderr);assert.match(r.stderr,/invalid_arguments/);
269
+ assert.equal(fs.existsSync(path.join(f.specsDir,'.reviews/.execution')),false);
270
+ });
@@ -50,14 +50,7 @@ function execution(f,answers){
50
50
  const worker=queue.shift();
51
51
  if(typeof worker==='object'){fs.writeFileSync(path.join(f.codeProject,'a.mjs'),worker.write);return {status:'succeeded',value:worker.value};}
52
52
  fs.writeFileSync(path.join(f.codeProject,'a.mjs'),worker);return {status:'succeeded',value:learning};}})},
53
- reviewers:[reviewer],reviewInvocation:{developerThreadId:'author-thread',excludedThreadIds:['control'],
54
- authorize:(value,{authorizationAt})=>{const body={version:1,kind:'cm-review-dispatch-grant',
55
- grantId:'grant',adapterId:'codex-review-adapter',invocationId:value.invocationId,
56
- requestDigest:value.requestDigest,identity:value.identity,reviewerId:'reviewer',
57
- logicalContextId:value.contextId,packageDigest:value.payload.reviewPackage.packageDigest,
58
- hostContextId:'control',decisionId:'approved',decision:'approved',issuedAt:authorizationAt,
59
- expiresAt:authorizationAt+60000};return {...body,grantDigest:digest(body)};}},
60
- hostDecision:{status:'approved'},check:createHostCheck({cwd:f.codeProject,
53
+ reviewers:[reviewer],reviewInvocation:{developerThreadId:'author-thread',excludedThreadIds:['control']},check:createHostCheck({cwd:f.codeProject,
61
54
  commands:[{id:'syntax',command:[process.execPath,'-e','0']}]})};
62
55
  }
63
56
  async function session(f,mode,answers,operations){
@@ -50,14 +50,7 @@ function execution(f,answers){
50
50
  const worker=queue.shift();
51
51
  if(worker==='hang')return new Promise(()=>{});
52
52
  fs.writeFileSync(path.join(f.codeProject,'a.mjs'),worker);return {status:'succeeded',value:learning};}})},
53
- reviewers:[reviewer],reviewInvocation:{developerThreadId:'author-thread',excludedThreadIds:['control'],
54
- authorize:(value,{authorizationAt})=>{const body={version:1,kind:'cm-review-dispatch-grant',
55
- grantId:'grant',adapterId:'codex-review-adapter',invocationId:value.invocationId,
56
- requestDigest:value.requestDigest,identity:value.identity,reviewerId:'reviewer',
57
- logicalContextId:value.contextId,packageDigest:value.payload.reviewPackage.packageDigest,
58
- hostContextId:'control',decisionId:'approved',decision:'approved',issuedAt:authorizationAt,
59
- expiresAt:authorizationAt+60000};return {...body,grantDigest:digest(body)};}},
60
- hostDecision:{status:'approved'},check:createHostCheck({cwd:f.codeProject,
53
+ reviewers:[reviewer],reviewInvocation:{developerThreadId:'author-thread',excludedThreadIds:['control']},check:createHostCheck({cwd:f.codeProject,
61
54
  commands:[{id:'syntax',command:[process.execPath,'-e','0']}]})};
62
55
  }
63
56
  async function session(f,mode,answers,operations){
@@ -12,6 +12,7 @@ import {PassThrough,Writable} from 'node:stream';
12
12
  import {fileURLToPath} from 'node:url';
13
13
  import {buildManifest} from './cm-spec-manifest.mjs';
14
14
  import {configFingerprint} from '../runtime/js/cm-ai/codex-config.mjs';
15
+ import {readRunnerHistory,runnerStatus} from '../runtime/js/cm-ai/durable-runner-state.mjs';
15
16
  import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
16
17
  import {applyProtectedEdits,protectedFixBridge} from '../runtime/js/cm-fix/protected-edits.mjs';
17
18
  import {createHostToolBridge} from '../runtime/js/cm-ai/host-tool-bridge.mjs';
@@ -75,12 +76,13 @@ function fixture(t,{scope=['target.mjs'],runId='drive-gaps-run',files={}}={}){
75
76
  const store=path.join(specsDir,'.reviews','.execution',runId,'state.json');
76
77
  const reviewer=verdict=>{
77
78
  let fake=fs.readFileSync(REVIEWER,'utf8');
78
- if(verdict==='changes_requested')fake=fake.replace("verdict:'approved'","verdict:'changes_requested'")
79
- .replace('findings:[]',"findings:[{id:'F1',severity:'P2',path:'"+scope[0]+"',message:'Revise',evidence:'Fixture finding'}]");
79
+ if(verdict==='changes_requested')fake=fake.replace("verdict:'approved'","verdict:data.reviewPackage.identity.attempt===1?'changes_requested':'approved'")
80
+ .replace('findings:[]',"findings:data.reviewPackage.identity.attempt===1?[{id:'F1',severity:'P2',path:'"+scope[0]+"',message:'Revise',evidence:'Fixture finding'}]:[]");
80
81
  fs.writeFileSync(path.join(bin,'codex'),fake,{mode:0o700});
81
82
  fs.writeFileSync(path.join(root,'review.json'),JSON.stringify({model:'fixture',preflight:{passed:true,
82
83
  cli_model:'fixture',prompt_transport:'stdin',config_fingerprint:configFingerprint({cwd:codeProject,model:'fixture'})}}));
83
84
  };
85
+ reviewer('approved');
84
86
  return {root,specsDir,codeProject,config,answers,bin,env,identity,write,content,develop,plan,drive,store,reviewer};
85
87
  }
86
88
  const result=run=>JSON.parse(run.stdout).result;
@@ -96,9 +98,9 @@ test('single advance reaches live logic and browser QA only after independent fi
96
98
  fs.writeFileSync(path.join(f.root,'workflow.json'),JSON.stringify({documentationPaths:[],applicableAgentFiles:[],qa:{
97
99
  commands:[{id:'fixture-check',caseIds:['TC-001'],command:[process.execPath,'-e','0']}],
98
100
  environment:{kind:'web',carrier:'browser',target:'fixture',scope:'local'}}}));
99
- f.write('qa-assess.json',{scores:{scope:2,risk:2,accumulation:2,boundary:2},changes:{api:false,migration:false,authentication:false,authorization:false,payment:false}});
101
+ f.write('qa-assess.json',{confirmed:true});
100
102
  f.write('documentation-inspect.json',{status:'completed',reason:'Fixture inspected'});
101
- const plan=f.plan({permissions:['--allow-review-attempt','1','--workflow-config','workflow.json','--allow-qa','--browser-qa','available'],
103
+ const plan=f.plan({permissions:['--workflow-config','workflow.json','--allow-qa','--browser-qa','available'],
102
104
  liveEvidence:{directory:'exchange',kinds:['qa_logic','qa_browser'],timeoutMs:1000}});
103
105
  const out=await runLiveDriver(DRIVER,plan,'advance',row=>row.kind==='qa_logic'
104
106
  ?{verdict:'SUPPORTED',evidence:['Fixture target.mjs exports 42']}
@@ -149,16 +151,16 @@ test('#29 the single driver binds the current attempt for decision and complete
149
151
  const review=['--review-config','review.json'];
150
152
  f.content('a1.mjs','export const value = 42;\n');f.develop({'target.mjs':'a1.mjs'});
151
153
  const first=f.drive(f.plan({permissions:review}),'advance');assert.equal(first.status,0,first.stderr);
152
- assert.equal(result(first).state,'awaiting_review');
153
- const decided=f.drive(f.plan({mode:'resume',permissions:[...review,'--allow-review-attempt','1'],
154
+ assert.equal(result(first).state,'changes_requested');assert.equal(result(first).code,'revision_answer_required');
155
+ const decided=f.drive(f.plan({mode:'resume',permissions:[...review],
154
156
  packageDigest:result(first).packageDigest,answers:undefined,checks:undefined}),'decision');
155
157
  assert.equal(decided.status,0,decided.stderr);
156
158
  assert.equal(result(decided).state,'changes_requested');assert.equal(result(decided).identity.attempt,2);
157
159
  f.content('a2.mjs','export const value = 43;\n');f.develop({'target.mjs':'a2.mjs'},'develop-a2.json');f.reviewer('approved');
158
- const second=f.drive(f.plan({mode:'resume',permissions:review}),'advance');assert.equal(second.status,0,second.stderr);
160
+ const second=f.drive(f.plan({mode:'resume',permissions:review}),'start');assert.equal(second.status,0,second.stderr);
159
161
  assert.equal(result(second).state,'awaiting_review');assert.equal(result(second).identity.attempt,2);
160
162
  const packageDigest=result(second).packageDigest;
161
- const approved=f.drive(f.plan({mode:'resume',permissions:[...review,'--allow-review-attempt','2'],packageDigest,
163
+ const approved=f.drive(f.plan({mode:'resume',permissions:[...review],packageDigest,
162
164
  answers:undefined,checks:undefined}),'decision');
163
165
  assert.equal(approved.status,0,approved.stderr);
164
166
  assert.equal(result(approved).outcome,'advanced',approved.stdout);
@@ -179,7 +181,7 @@ test('#11 a develop answer deletes, sets the executable bit and renames, and the
179
181
  f.develop({'scripts/test.sh':{mode:'0755'},'old/Legacy.swift':{delete:true},'new/Legacy.swift':'legacy.swift'});
180
182
  // The task's own check runs the script directly, so it only passes with the executable bit.
181
183
  // A private umask must not leak into new source files: they are created 0644.
182
- const run=f.drive(f.plan({checks:[{id:'test',command:['./scripts/test.sh']}]}),'advance',60000,'077');
184
+ const run=f.drive(f.plan({checks:[{id:'test',command:['./scripts/test.sh']}]}),'start',60000,'077');
183
185
  assert.equal(run.status,0,run.stderr);assert.equal(result(run).state,'awaiting_review',run.stdout);
184
186
  assert.equal(fs.statSync(path.join(f.codeProject,'scripts/test.sh')).mode&0o777,0o755);
185
187
  assert.equal(fs.existsSync(path.join(f.codeProject,'old/Legacy.swift')),false);
@@ -206,7 +208,7 @@ for(const [name,edits,pattern] of [
206
208
  ['unknown field',{'scripts/test.sh':{file:'legacy.swift',owner:'root'}},/develop\.json\.edits/],
207
209
  ])test(`#11 invalid develop edit entry is refused before launch: ${name}`,t=>{
208
210
  const f=fixture(t,{scope:renameScope,files:renameFiles});f.content('legacy.swift','// legacy\n');f.develop(edits);
209
- const run=f.drive(f.plan(),'advance');
211
+ const run=f.drive(f.plan(),'start');
210
212
  assert.equal(run.status,2,run.stderr);assert.match(run.stderr,/develop\.json\.edits/);assert.match(run.stderr,pattern);
211
213
  noRun(f);
212
214
  });
@@ -253,7 +255,7 @@ test('#19 a lesson-only delivery is not refused as empty: its Learning writeback
253
255
  f.write('develop.json',{status:'succeeded',value:{...developValue,retrospective:{status:'lesson_candidate',reason:null,
254
256
  candidates:[{classification:'structured',trigger:'Fixture values need an explicit check',
255
257
  action:'Run the syntax check before delivering',evidence:['target.mjs']}]}},edits:{}});
256
- const run=f.drive(f.plan(),'advance');
258
+ const run=f.drive(f.plan(),'start');
257
259
  assert.equal(run.status,0,run.stderr);assert.equal(result(run).state,'awaiting_review',run.stdout);
258
260
  assert(lastCheckpoint(f).reviewPackage.changes.some(change=>change.path==='AGENTS.md'));
259
261
  });
@@ -271,7 +273,7 @@ test('#11 the protected host refuses an invalid mode before any sandbox write',t
271
273
  fs.writeFileSync(wrapper,`import {driveHost} from ${JSON.stringify(DRIVE_CORE)};
272
274
  driveHost({host:${JSON.stringify(HOST)},args:['serve','--config',${JSON.stringify(f.config)},'--mode',${JSON.stringify(fs.existsSync(f.store)?'resume':'create')},
273
275
  '--host-context','drive-host-a','--allow-development','--review-config',${JSON.stringify(path.join(f.root,'review.json'))},'--protected-conversation-config',${JSON.stringify(protection)}],
274
- cwd:${JSON.stringify(f.codeProject)},operation:'advance',answers:{},request:{version:1,identity:${JSON.stringify(f.identity)}},
276
+ cwd:${JSON.stringify(f.codeProject)},operation:'advance',answers:{},request:{version:1,identity:${JSON.stringify(fs.existsSync(f.store)?{...f.identity,attempt:runnerStatus(readRunnerHistory(records(f),records(f)[0].payload.config,3).state,records(f)[0].payload.config).identity.attempt}:f.identity)}},
275
277
  answerFor:async row=>row.kind==='develop'?{status:'succeeded',value:${JSON.stringify(developValue)},
276
278
  edits:[{path:'target.mjs',beforeSha256:row.payload.expected['target.mjs'],...${JSON.stringify(edit)}}]}:null});`);
277
279
  const run=spawnSync(process.execPath,[wrapper],{encoding:'utf8',timeout:60000,env:f.env});
@@ -295,8 +297,8 @@ import {driveHost} from ${JSON.stringify(DRIVE_CORE)};
295
297
  import {createHostCheck} from ${JSON.stringify(HOST_CHECK)};
296
298
  const cwd=${JSON.stringify(f.codeProject)};
297
299
  driveHost({host:${JSON.stringify(HOST)},args:['serve','--config',${JSON.stringify(f.config)},'--mode',${JSON.stringify(mode)},
298
- '--host-context','drive-host-a','--allow-development',...${JSON.stringify(args.includes('--review-config')?args:['--review-config',path.join(f.root,'review.json'),...args])}],cwd,operation:'advance',answers:{},
299
- request:{version:1,identity:${JSON.stringify(f.identity)}},
300
+ '--host-context','drive-host-a','--allow-development',...${JSON.stringify(args.includes('--review-config')?args:['--review-config',path.join(f.root,'review.json'),...args])}],cwd,operation:'start',answers:{},
301
+ request:{version:1,identity:${JSON.stringify(fs.existsSync(f.store)?{...f.identity,attempt:runnerStatus(readRunnerHistory(records(f),records(f)[0].payload.config,3).state,records(f)[0].payload.config).identity.attempt}:f.identity)}},
300
302
  answerFor:async row=>{
301
303
  if(row.kind==='develop'){
302
304
  ${act}
@@ -423,24 +425,34 @@ function secondRound(f){
423
425
  const review=['--review-config','review.json'];
424
426
  f.content('a1.mjs','export const value = 42;\n');f.develop({'target.mjs':'a1.mjs'});
425
427
  const first=f.drive(f.plan({permissions:review}),'advance');assert.equal(first.status,0,first.stderr);
426
- const decided=f.drive(f.plan({mode:'resume',permissions:[...review,'--allow-review-attempt','1'],
428
+ const decided=f.drive(f.plan({mode:'resume',permissions:[...review],
427
429
  packageDigest:result(first).packageDigest,answers:undefined,checks:undefined}),'decision');
428
430
  assert.equal(decided.status,0,decided.stderr);assert.equal(result(decided).state,'changes_requested');
429
431
  return review;
430
432
  }
433
+ function approveSecondRound(f,review,packageDigest){
434
+ const approved=f.drive(f.plan({mode:'resume',permissions:review,packageDigest,answers:undefined,checks:undefined}),'decision');
435
+ assert.equal(approved.status,0,approved.stderr);assert.equal(result(approved).state,'approved',approved.stdout);
436
+ assert.equal(result(approved).identity.attempt,2);
437
+ const rows=records(f),registered=rows.filter(row=>row.payload.type==='review-invocation-registered');
438
+ assert.equal(registered.length,2);assert.notEqual(registered[0].payload.binding.invocationId,registered[1].payload.binding.invocationId);
439
+ const threads=rows.filter(row=>row.payload.type==='review-invocation-started').map(row=>row.payload.providerThreadId);
440
+ assert.equal(threads.length,2);assert.notEqual(threads[0],threads[1]);
441
+ }
431
442
  test('#19 a second-round develop whose checks fail retries in the same attempt after the fix',t=>{
432
443
  const f=fixture(t),review=secondRound(f);
433
444
  f.content('a2.mjs','export const value = 43;\n');f.develop({'target.mjs':'a2.mjs'},'develop-a2.json');
434
445
  const failing=f.drive(f.plan({mode:'resume',permissions:review,
435
- checks:[{id:'unit',command:[process.execPath,'-e','process.exit(3)']}]}),'advance');
446
+ checks:[{id:'unit',command:[process.execPath,'-e','process.exit(3)']}]}),'start');
436
447
  assert.equal(failing.status,0,failing.stderr);
437
448
  assert.equal(result(failing).state,'blocked',failing.stdout);assert.equal(result(failing).code,'develop_checks_not_passed');
438
449
  assert.equal(result(failing).identity.attempt,2);assert.equal(result(failing).pendingAction,'resume');
439
- const retried=f.drive(f.plan({mode:'resume',permissions:review}),'advance');
450
+ const retried=f.drive(f.plan({mode:'resume',permissions:review}),'start');
440
451
  assert.equal(retried.status,0,retried.stderr);
441
452
  assert.equal(result(retried).state,'awaiting_review',retried.stdout);assert.equal(result(retried).identity.attempt,2);
442
453
  const intents=records(f).filter(row=>row.payload.type==='effect-intent'&&row.payload.effect.kind==='develop').map(row=>row.payload.effect.id);
443
454
  assert.deepEqual(intents,['develop-1','develop-2','develop-2-retry-1']);
455
+ approveSecondRound(f,review,result(retried).packageDigest);
444
456
  });
445
457
  test('#19 a second-round delivery that deletes an in-scope requirement is recoverable at attempt 2',t=>{
446
458
  const f=fixture(t,{scope:['target.mjs','requirements.md']}),review=secondRound(f);
@@ -456,6 +468,7 @@ test('#19 a second-round delivery that deletes an in-scope requirement is recove
456
468
  assert.equal(result(restored).state,'awaiting_review',restored.stdout);assert.equal(result(restored).identity.attempt,2);
457
469
  const changes=lastCheckpoint(f).reviewPackage.changes.map(change=>change.path);
458
470
  assert.deepEqual(changes,['target.mjs']);
471
+ approveSecondRound(f,review,result(restored).packageDigest);
459
472
  });
460
473
  test('#19 review material counts every AGENTS.md the snapshot carries, not only ancestors',t=>{
461
474
  // Two unrelated instruction files plus scope growth: 300+300+1000+900 KiB > 2 MiB.
@@ -485,7 +498,7 @@ for(const kib of [700,800,1000])test(`#19 a ${kib} KiB delivery whose checkpoint
485
498
  test('#19 a 500 KiB delivery still fits the journal and reaches review',t=>{
486
499
  const f=fixture(t,{files:{'target.mjs':'export const value = 1;\n'}});
487
500
  f.content('big.mjs',line(500));f.develop({'target.mjs':'big.mjs'});
488
- const run=f.drive(f.plan(),'advance');
501
+ const run=f.drive(f.plan(),'start');
489
502
  assert.equal(run.status,0,run.stderr);assert.equal(result(run).state,'awaiting_review',run.stdout);
490
503
  });
491
504
  test('#19 a create baseline too large for its journal record is refused by the driver before launch',t=>{
@@ -568,7 +581,7 @@ test('#19 a package admitted at the budget edge survives a maximal review throug
568
581
  const developed=Buffer.byteLength(JSON.stringify(records(f).at(-1).payload));
569
582
  assert(developed<=budget&&developed>budget-8192,`${developed} vs ${budget}`);
570
583
  const review=['--review-config','review.json'];
571
- const decided=f.drive(f.plan({mode:'resume',permissions:[...review,'--allow-review-attempt','1'],
584
+ const decided=f.drive(f.plan({mode:'resume',permissions:[...review],
572
585
  packageDigest:result(admitted).packageDigest,answers:undefined,checks:undefined}),'decision');
573
586
  assert.equal(decided.status,0,decided.stderr);assert.equal(result(decided).state,'approved',decided.stdout);
574
587
  const completed=f.drive(f.plan({mode:'resume',permissions:review,packageDigest:result(admitted).packageDigest}),'complete');
@@ -618,7 +631,7 @@ function sweepEdge(t,{scope,files={},writeLayout,answerLayout,value=developValue
618
631
  for(let step=-4;step<=4;step++){
619
632
  const f=fixture(t,{scope,files});answerLayout(f,edge+step*4096);
620
633
  f.write('develop.json',{status:'succeeded',value,edits:f.edits});
621
- const run=f.drive(f.plan(),'advance');
634
+ const run=f.drive(f.plan(),'start');
622
635
  if(run.status===2){refused++;assert.match(run.stderr,/含 handoff/);noRun(f);continue;}
623
636
  admitted++;assert.equal(run.status,0,run.stderr);
624
637
  assert.equal(result(run).state,'awaiting_review',`${edge+step*4096}: ${run.stdout}`);