@aibyzero/cm-workflow 0.16.2 → 0.16.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.codex-plugin/plugin.json +1 -1
- package/AGENTS.md +4 -0
- package/CHANGELOG.md +138 -0
- package/README.md +2 -2
- package/VERSION +1 -1
- package/docs/installation.md +1 -1
- package/docs/js-workflow-control.md +46 -7
- package/docs/next-steps.md +110 -0
- package/docs/untested-branches.md +24 -18
- package/package.json +1 -1
- package/runtime/js/cm-ai/claude-tool-preview.mjs +45 -6
- package/runtime/js/cm-ai/cm-ai-admission.mjs +5 -0
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +22 -12
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +70 -5
- package/runtime/js/cm-ai/cm-ai-run-finalizer.mjs +5 -5
- package/runtime/js/cm-ai/drive-core.mjs +68 -0
- package/runtime/js/cm-ai/durable-runner-state.mjs +42 -9
- package/runtime/js/cm-ai/effect-contract.mjs +4 -3
- package/runtime/js/cm-ai/execution-snapshot.mjs +40 -0
- package/runtime/js/cm-ai/host-conversation-execution.mjs +8 -5
- package/runtime/js/cm-ai/host-handoff.mjs +9 -14
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +12 -7
- package/runtime/js/cm-ai/host-session.mjs +2 -2
- package/runtime/js/cm-ai/host.mjs +1 -1
- package/runtime/js/cm-ai/qa-config-revision.mjs +85 -0
- package/runtime/js/cm-ai/review-evidence-file.mjs +18 -1
- package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +144 -0
- package/runtime/js/cm-ai/reviewed-evidence-supersession-record.mjs +34 -0
- package/runtime/js/cm-ai/task-runner.mjs +41 -8
- package/runtime/js/cm-fix/cause-invocation.mjs +9 -5
- package/runtime/js/cm-fix/cause-package.mjs +21 -0
- package/runtime/js/cm-fix/dossier.mjs +40 -1
- package/runtime/js/cm-fix/execution.mjs +360 -83
- package/runtime/js/cm-fix/host.mjs +7 -3
- package/runtime/js/cm-fix/layout.mjs +14 -6
- package/runtime/js/cm-fix/progress.mjs +14 -0
- package/runtime/js/cm-fix/protected-edits.mjs +1 -1
- package/runtime/js/cm-fix/red-test.mjs +7 -6
- package/runtime/js/cm-fix/regression-evidence.mjs +6 -3
- package/runtime/js/cm-fix/regression.mjs +16 -10
- package/runtime/js/cm-fix/repair.mjs +16 -13
- package/runtime/js/cm-fix/test-author.mjs +2 -1
- package/runtime/js/cm-fix/test-extension.mjs +45 -0
- package/runtime/js/cm-prd/accepted-design.mjs +28 -9
- package/runtime/js/cm-prd/analysis.mjs +68 -16
- package/runtime/js/cm-prd/change.mjs +21 -1
- package/runtime/js/cm-prd/draft-save.mjs +96 -2
- package/runtime/js/cm-prd/failed-correction.mjs +51 -0
- package/runtime/js/cm-prd/inputs-replaced.mjs +122 -0
- package/runtime/js/cm-prd/review-correction.mjs +3 -0
- package/runtime/js/cm-prd/review-disposition.mjs +33 -15
- package/runtime/js/cm-prd/review-findings.mjs +2 -2
- package/runtime/js/cm-prd/review-host.mjs +2 -0
- package/runtime/js/cm-prd/review-preparation.mjs +28 -1
- package/runtime/js/cm-prd/review-publication.mjs +4 -2
- package/runtime/js/cm-prd/self-check-revision.mjs +81 -0
- package/runtime/js/cm-prd/session.mjs +5 -5
- package/runtime/js/cm-prd/split-design.mjs +67 -0
- package/runtime/js/cm-prd/summary.mjs +53 -8
- package/runtime/js/cm-refactor/workflow.mjs +100 -19
- package/scripts/cm-ai-batch-drive.mjs +251 -0
- package/scripts/cm-ai-batch-drive.test.mjs +152 -0
- package/scripts/cm-ai-contracts.test.mjs +30 -0
- package/scripts/cm-ai-conversation-entry-ops.test.mjs +62 -0
- package/scripts/cm-ai-drive.mjs +334 -0
- package/scripts/cm-ai-drive.test.mjs +251 -0
- package/scripts/cm-ai-fix-integration.test.mjs +1 -1
- package/scripts/cm-ai-host.mjs +41 -18
- package/scripts/cm-ai-host.test.mjs +37 -0
- package/scripts/cm-ai-qa-config-revision.test.mjs +328 -0
- package/scripts/cm-ai-qa-fix-cross-session.test.mjs +255 -0
- package/scripts/cm-ai-qa-fix-policy.test.mjs +79 -0
- package/scripts/cm-ai-review-timeout.test.mjs +30 -0
- package/scripts/cm-ai-run.mjs +59 -11
- package/scripts/cm-ai-runner-error-code-regression.test.mjs +29 -0
- package/scripts/cm-ai-session-chain.test.mjs +261 -0
- package/scripts/cm-ai-supersede.test.mjs +320 -0
- package/scripts/cm-check-drive.mjs +93 -0
- package/scripts/cm-check-drive.test.mjs +62 -0
- package/scripts/cm-check-host.test.mjs +47 -0
- package/scripts/cm-claude-probe.test.mjs +117 -2
- package/scripts/cm-fix-abandon.test.mjs +383 -0
- package/scripts/cm-fix-cause-package.test.mjs +31 -1
- package/scripts/cm-fix-cross-session-host.test.mjs +17 -5
- package/scripts/cm-fix-drive.mjs +168 -0
- package/scripts/cm-fix-drive.test.mjs +117 -0
- package/scripts/cm-fix-escalation.test.mjs +214 -0
- package/scripts/cm-fix-execution.test.mjs +26 -0
- package/scripts/cm-fix-host.mjs +4 -2
- package/scripts/cm-fix-observation-dossier.test.mjs +34 -9
- package/scripts/cm-fix-qa-source.test.mjs +3 -3
- package/scripts/cm-fix-session-chain.test.mjs +244 -0
- package/scripts/cm-fix-test-extension.test.mjs +246 -0
- package/scripts/cm-fix-visual-carrier.test.mjs +66 -0
- package/scripts/cm-host-handoff.test.mjs +37 -0
- package/scripts/cm-idea-drive.mjs +99 -0
- package/scripts/cm-idea-drive.test.mjs +50 -0
- package/scripts/cm-init-drive.mjs +191 -0
- package/scripts/cm-init-drive.test.mjs +59 -0
- package/scripts/cm-log-event.mjs +9 -0
- package/scripts/cm-prd-design-phase.test.mjs +355 -15
- package/scripts/cm-prd-drive.mjs +308 -0
- package/scripts/cm-prd-drive.test.mjs +154 -0
- package/scripts/cm-prd-host.mjs +46 -17
- package/scripts/cm-prd-inputs-replaced.test.mjs +237 -0
- package/scripts/cm-prd-review-disposition.test.mjs +133 -7
- package/scripts/cm-prd-review-gate.mjs +23 -4
- package/scripts/cm-prd-self-check-revision.test.mjs +302 -0
- package/scripts/cm-prd-summary.test.mjs +48 -4
- package/scripts/cm-refactor-drive.mjs +237 -0
- package/scripts/cm-refactor-drive.test.mjs +77 -0
- package/scripts/cm-refactor-gaps.test.mjs +276 -0
- package/scripts/cm-refactor-host.test.mjs +1 -48
- package/scripts/cm-refactor-judge-revision.test.mjs +253 -0
- package/scripts/cm-test-drive.mjs +132 -0
- package/scripts/cm-test-drive.test.mjs +91 -0
- package/scripts/cm-test-session.test.mjs +117 -0
- package/scripts/correction-check.test.mjs +38 -0
- package/scripts/fixtures/claude-model-marker.mjs +6 -0
- package/scripts/fixtures/claude-review-process.mjs +7 -0
- package/scripts/fixtures/cm-refactor.mjs +56 -0
- package/skills/cm-ai/SKILL.md +1 -1
- package/skills/cm-ai/references/N4-review.md +2 -0
- package/skills/cm-ai/references/N8-finish.md +1 -0
- package/skills/cm-ai/references/js-host.md +80 -3
- package/skills/cm-check/references/js-host.md +2 -0
- package/skills/cm-fix/SKILL.md +11 -4
- package/skills/cm-fix/references/js-host.md +67 -2
- package/skills/cm-fix/references/test-extension.md +57 -0
- package/skills/cm-idea/references/js-host.md +2 -0
- package/skills/cm-init/references/js-host.md +2 -0
- package/skills/cm-prd/SKILL.md +8 -8
- package/skills/cm-prd/references/js-change-recovery.md +41 -0
- package/skills/cm-prd/references/js-host.md +64 -2
- package/skills/cm-prd/references/spec-self-check.md +14 -2
- package/skills/cm-refactor/SKILL.md +5 -0
- package/skills/cm-refactor/references/js-batch.md +3 -1
- package/skills/cm-refactor/references/js-host.md +49 -0
- package/skills/cm-test/references/js-host.md +5 -0
- package/skills/cm-test/references/unit-coverage.md +2 -2
|
@@ -0,0 +1,251 @@
|
|
|
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 {qaFixAnswerFor} from './cm-ai-drive.mjs';
|
|
10
|
+
|
|
11
|
+
const DRIVER=fileURLToPath(new URL('./cm-ai-drive.mjs',import.meta.url));
|
|
12
|
+
const identity={repositoryId:'drive-fixture',runId:'drive-run',taskId:'T-001',attempt:1};
|
|
13
|
+
test('help prints the plan command without launching a host',()=>{
|
|
14
|
+
const help=spawnSync(process.execPath,[DRIVER,'--help'],{encoding:'utf8'});
|
|
15
|
+
assert.equal(help.status,0);assert.match(help.stdout,/--plan PLAN\.json <operation>/);
|
|
16
|
+
});
|
|
17
|
+
function fixture(t){
|
|
18
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-ai-drive-')));
|
|
19
|
+
t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
20
|
+
const specsDir=path.join(root,'specs'),codeProject=path.join(root,'code'),feature='1.work';
|
|
21
|
+
fs.mkdirSync(path.join(specsDir,feature),{recursive:true});fs.mkdirSync(codeProject);
|
|
22
|
+
for(const name of ['requirements.md','design.md'])fs.writeFileSync(path.join(specsDir,feature,name),'# Fixture\n');
|
|
23
|
+
fs.writeFileSync(path.join(specsDir,feature,'tasks.md'),'- [ ] T-001: fixture\n');
|
|
24
|
+
fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:[feature],specFiles:buildManifest(specsDir)}));
|
|
25
|
+
fs.writeFileSync(path.join(codeProject,'requirements.md'),'# Fixture\n');
|
|
26
|
+
fs.writeFileSync(path.join(root,'run.json'),JSON.stringify({version:1,specsDir,codeProject,feature,identity,
|
|
27
|
+
scope:['target.mjs'],requirements:['requirements.md']}));
|
|
28
|
+
const answers=path.join(root,'answers');fs.mkdirSync(answers);
|
|
29
|
+
const write=(name,value)=>fs.writeFileSync(path.join(answers,name),JSON.stringify(value));
|
|
30
|
+
const plan=(extra={})=>{const file=path.join(root,`plan-${Math.random().toString(36).slice(2)}.json`);
|
|
31
|
+
fs.writeFileSync(file,JSON.stringify({config:'run.json',mode:'create',hostContext:'drive-host-a',
|
|
32
|
+
permissions:[],answers:'answers',checks:[{id:'syntax',command:[process.execPath,'--check','target.mjs']}],...extra}));
|
|
33
|
+
return file;};
|
|
34
|
+
const drive=(file,operation)=>spawnSync(process.execPath,[DRIVER,'--plan',file,operation],
|
|
35
|
+
{encoding:'utf8',timeout:30000,env:{...process.env,CM_WORKFLOW_HOME:path.join(root,'home'),
|
|
36
|
+
CM_WORKFLOW_LOG_HOME:path.join(root,'logs')}});
|
|
37
|
+
const store=path.join(specsDir,'.reviews','.execution',identity.runId,'state.json');
|
|
38
|
+
return {root,codeProject,specsDir,answers,write,plan,drive,store};
|
|
39
|
+
}
|
|
40
|
+
const develop={status:'succeeded',value:{outcome:'implemented',
|
|
41
|
+
application:{status:'no_relevant_lesson',note:null},
|
|
42
|
+
retrospective:{status:'no_new_lesson',candidates:[],reason:null}},
|
|
43
|
+
edits:{'target.mjs':'target-content.mjs'}};
|
|
44
|
+
function prepared(f){f.write('develop.json',develop);fs.writeFileSync(path.join(f.answers,'target-content.mjs'),'export const value = 42;\n');}
|
|
45
|
+
function qaFixture(f,kinds,caseIds=[]){
|
|
46
|
+
const featureRoot=path.join(f.specsDir,'1.work');
|
|
47
|
+
fs.writeFileSync(path.join(featureRoot,'requirements.md'),'- [AC-001]: fixture\n');
|
|
48
|
+
const cases=kinds.map(({kind,expected,taskIds=['T-001']},index)=>({id:`TC-${String(index+1).padStart(3,'0')}`,origin:'user',kind,
|
|
49
|
+
blocking:true,acIds:['AC-001'],taskIds,title:`${kind} fixture`,preconditions:[],
|
|
50
|
+
steps:['Observe fixture'],expected:[expected],cleanup:[]}));
|
|
51
|
+
fs.writeFileSync(path.join(featureRoot,'test-cases.json'),JSON.stringify({schemaVersion:'1.0',feature:'work',cases}));
|
|
52
|
+
fs.writeFileSync(path.join(f.specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:['1.work'],
|
|
53
|
+
specFiles:buildManifest(f.specsDir)}));
|
|
54
|
+
fs.writeFileSync(path.join(f.root,'workflow.json'),JSON.stringify({documentationPaths:[],applicableAgentFiles:[],
|
|
55
|
+
qa:{commands:[{id:'unit',command:[process.execPath,'--check','target.mjs'],caseIds}],
|
|
56
|
+
environment:{kind:'web',carrier:'browser',target:'fixture-local',scope:'local'}}}));
|
|
57
|
+
f.write('qa-assess.json',{scores:{scope:1,risk:1,accumulation:1,boundary:1},
|
|
58
|
+
changes:{api:false,migration:false,authentication:false,authorization:false,payment:false}});
|
|
59
|
+
f.write('documentation-inspect.json',{status:'blocked',reason:'Fixture stops before documentation review'});
|
|
60
|
+
return f.plan({permissions:['--workflow-config','workflow.json','--allow-qa',
|
|
61
|
+
...(kinds.some(item=>item.kind==='browser')?['--browser-qa','available']:[])]});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
test('create and advance run authored edits and actual check, then resume with original context',t=>{
|
|
65
|
+
const f=fixture(t);prepared(f);
|
|
66
|
+
const first=f.drive(f.plan(),'advance');assert.equal(first.status,0,first.stderr);
|
|
67
|
+
const result=JSON.parse(first.stdout).result;
|
|
68
|
+
assert.equal(result.state,'awaiting_review');assert.equal(result.code,'decision_required');
|
|
69
|
+
assert.match(first.stderr,/应答 develop/);assert.match(first.stderr,/应答 check/);
|
|
70
|
+
assert.equal(fs.readFileSync(path.join(f.codeProject,'target.mjs'),'utf8'),'export const value = 42;\n');
|
|
71
|
+
assert(fs.existsSync(f.store));
|
|
72
|
+
const resumed=f.drive(f.plan({mode:'resume',hostContext:'drive-host-b',originalHostContext:'drive-host-a'}),'advance');
|
|
73
|
+
assert.equal(resumed.status,0,resumed.stderr);assert.equal(JSON.parse(resumed.stdout).result.code,'decision_required');
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test('missing develop answer is refused before store creation',t=>{
|
|
77
|
+
const f=fixture(t);const run=f.drive(f.plan(),'advance');
|
|
78
|
+
assert.equal(run.status,2);assert.match(run.stderr,/develop\.json/);assert.equal(fs.existsSync(f.store),false);
|
|
79
|
+
});
|
|
80
|
+
test('out-of-scope develop edit is refused before host launch',t=>{
|
|
81
|
+
const f=fixture(t);prepared(f);
|
|
82
|
+
f.write('develop.json',{...develop,edits:{'outside.mjs':'target-content.mjs'}});
|
|
83
|
+
const run=f.drive(f.plan(),'advance');
|
|
84
|
+
assert.equal(run.status,2,run.stderr);
|
|
85
|
+
assert.match(run.stderr,/develop\.json\.edits 越过批准 scope: outside\.mjs/);
|
|
86
|
+
assert.equal(fs.existsSync(path.dirname(f.store)),false,'preflight must not create the run store');
|
|
87
|
+
});
|
|
88
|
+
test('unprotected advance without checks is refused before host launch',t=>{
|
|
89
|
+
const f=fixture(t);prepared(f);
|
|
90
|
+
const run=f.drive(f.plan({checks:undefined}),'advance');
|
|
91
|
+
assert.equal(run.status,2,run.stderr);
|
|
92
|
+
assert.match(run.stderr,/步骤会反问 check,但 PLAN\.checks 缺少真实命令列表/);
|
|
93
|
+
assert.equal(fs.existsSync(path.dirname(f.store)),false,'preflight must not create the run store');
|
|
94
|
+
});
|
|
95
|
+
test('missing checks cannot be replaced with static check.json',t=>{
|
|
96
|
+
const f=fixture(t);prepared(f);f.write('check.json',[{id:'syntax',outcome:'passed',exitCode:0}]);
|
|
97
|
+
const run=f.drive(f.plan({checks:undefined}),'advance');
|
|
98
|
+
assert.equal(run.status,2);assert.match(run.stderr,/PLAN\.checks/);assert.equal(fs.existsSync(f.store),false);
|
|
99
|
+
});
|
|
100
|
+
test('a static passed check cannot override a failed real command',t=>{
|
|
101
|
+
const f=fixture(t);prepared(f);f.write('check.json',[{id:'syntax',outcome:'passed',exitCode:0}]);
|
|
102
|
+
const run=f.drive(f.plan({checks:[{id:'actual',command:[process.execPath,'-e','process.exit(7)']}]}),'advance');
|
|
103
|
+
assert.equal(run.status,0,run.stderr);
|
|
104
|
+
const evidence=fs.readFileSync(f.store,'utf8');
|
|
105
|
+
assert.match(evidence,/host check exited 7/);
|
|
106
|
+
assert.doesNotMatch(evidence,/"outcome":"passed","exitCode":0/);
|
|
107
|
+
});
|
|
108
|
+
test('malformed develop answer is rejected before host launch',t=>{
|
|
109
|
+
const f=fixture(t);prepared(f);f.write('develop.json',{status:'succeeded',value:{outcome:'implemented'},
|
|
110
|
+
edits:{'target.mjs':'target-content.mjs'}});
|
|
111
|
+
const run=f.drive(f.plan(),'advance');assert.equal(run.status,2);assert.match(run.stderr,/答案格式错误/);
|
|
112
|
+
assert.equal(fs.existsSync(f.store),false);
|
|
113
|
+
});
|
|
114
|
+
test('verification_precheck static answer is refused without an execution runner',t=>{
|
|
115
|
+
const f=fixture(t);prepared(f);f.write('verification-precheck.json',{items:[{requirement:'synthetic',satisfied:true,evidence:'claim'}]});
|
|
116
|
+
const run=f.drive(f.plan({verificationPrecheck:true}),'advance');
|
|
117
|
+
assert.equal(run.status,2);assert.match(run.stderr,/verification_precheck/);assert.equal(fs.existsSync(f.store),false);
|
|
118
|
+
});
|
|
119
|
+
test('mapped logic case is still refused because executor asks qa_logic',t=>{
|
|
120
|
+
const f=fixture(t);prepared(f);
|
|
121
|
+
const plan=qaFixture(f,[{kind:'logic',expected:'Unit check passes'},
|
|
122
|
+
{kind:'browser',expected:'[需确认] Browser evidence'}],['TC-001']);
|
|
123
|
+
const run=f.drive(plan,'advance');
|
|
124
|
+
assert.equal(run.status,2,run.stderr);
|
|
125
|
+
assert.match(run.stderr,/缺少真实执行 runner: qa_logic/);
|
|
126
|
+
assert.doesNotMatch(run.stderr,/qa_browser/);
|
|
127
|
+
assert.equal(fs.existsSync(f.store),false);
|
|
128
|
+
});
|
|
129
|
+
test('marked browser case launches without qa_browser runner',t=>{
|
|
130
|
+
const f=fixture(t);prepared(f);
|
|
131
|
+
const run=f.drive(qaFixture(f,[{kind:'browser',expected:'[需确认] Browser evidence'}]),'advance');
|
|
132
|
+
assert.doesNotMatch(run.stderr,/缺少真实执行 runner/);
|
|
133
|
+
assert(fs.existsSync(f.store),run.stderr);
|
|
134
|
+
});
|
|
135
|
+
test('uncovered logic case is refused before launch without qa_logic runner',t=>{
|
|
136
|
+
const f=fixture(t);prepared(f);
|
|
137
|
+
const run=f.drive(qaFixture(f,[{kind:'logic',expected:'Unit check passes'}]),'advance');
|
|
138
|
+
assert.equal(run.status,2,run.stderr);assert.match(run.stderr,/缺少真实执行 runner: qa_logic/);
|
|
139
|
+
assert.equal(fs.existsSync(f.store),false);
|
|
140
|
+
});
|
|
141
|
+
test('unmarked browser case is refused before launch without qa_browser runner',t=>{
|
|
142
|
+
const f=fixture(t);prepared(f);
|
|
143
|
+
const run=f.drive(qaFixture(f,[{kind:'browser',expected:'Browser evidence'}]),'advance');
|
|
144
|
+
assert.equal(run.status,2,run.stderr);assert.match(run.stderr,/缺少真实执行 runner: qa_browser/);
|
|
145
|
+
assert.equal(fs.existsSync(f.store),false);
|
|
146
|
+
});
|
|
147
|
+
test('cases bound to another unfinished task do not require QA runners yet',t=>{
|
|
148
|
+
const f=fixture(t);prepared(f);
|
|
149
|
+
fs.writeFileSync(path.join(f.specsDir,'1.work','tasks.md'),'- [ ] T-001: current\n- [ ] T-002: future\n');
|
|
150
|
+
const run=f.drive(qaFixture(f,[{kind:'logic',expected:'Future logic',taskIds:['T-002']},
|
|
151
|
+
{kind:'browser',expected:'Future browser',taskIds:['T-002']}]),'advance');
|
|
152
|
+
assert.doesNotMatch(run.stderr,/缺少真实执行 runner/);
|
|
153
|
+
assert(fs.existsSync(f.store),run.stderr);
|
|
154
|
+
});
|
|
155
|
+
test('protected conversation still requires the authored develop answer',t=>{
|
|
156
|
+
const f=fixture(t);fs.writeFileSync(path.join(f.root,'protection.json'),JSON.stringify({checkCommands:[
|
|
157
|
+
{id:'syntax',command:[process.execPath,'--check','target.mjs']}],timeoutMs:60000}));
|
|
158
|
+
const run=f.drive(f.plan({checks:undefined,
|
|
159
|
+
permissions:['--protected-conversation-config','protection.json']}),'advance');
|
|
160
|
+
assert.equal(run.status,2);assert.match(run.stderr,/develop\.json/);assert.equal(fs.existsSync(f.store),false);
|
|
161
|
+
});
|
|
162
|
+
test('resume requires originalHostContext before host launch',t=>{
|
|
163
|
+
const f=fixture(t);prepared(f);
|
|
164
|
+
const run=f.drive(f.plan({mode:'resume'}),'advance');assert.equal(run.status,2);
|
|
165
|
+
assert.match(run.stderr,/originalHostContext/);assert.equal(fs.existsSync(f.store),false);
|
|
166
|
+
});
|
|
167
|
+
test('supersession flags reach create and incomplete or resume pairs stop before host launch',t=>{
|
|
168
|
+
const f=fixture(t);prepared(f);
|
|
169
|
+
const both=['--supersede-reviewed-evidence','--supersede-reason','operator restart'];
|
|
170
|
+
const create=f.drive(f.plan({permissions:both}),'advance');
|
|
171
|
+
assert.equal(create.status,1,create.stderr);
|
|
172
|
+
assert.match(create.stderr,/supersede_unavailable/);
|
|
173
|
+
for(const permissions of [['--supersede-reviewed-evidence'],['--supersede-reason','operator restart']]){
|
|
174
|
+
const refused=f.drive(f.plan({permissions}),'advance');
|
|
175
|
+
assert.equal(refused.status,2,refused.stderr);
|
|
176
|
+
assert.match(refused.stderr,/supersede-reviewed-evidence.*supersede-reason/);
|
|
177
|
+
}
|
|
178
|
+
const resumed=f.drive(f.plan({mode:'resume',originalHostContext:'drive-host-a',permissions:both}),'status');
|
|
179
|
+
assert.equal(resumed.status,2,resumed.stderr);
|
|
180
|
+
assert.match(resumed.stderr,/supersede.*create/);
|
|
181
|
+
});
|
|
182
|
+
test('status reads the existing run without answer files or checks',t=>{
|
|
183
|
+
const f=fixture(t);prepared(f);assert.equal(f.drive(f.plan(),'advance').status,0);
|
|
184
|
+
const before=fs.readFileSync(f.store);
|
|
185
|
+
const status=f.drive(f.plan({mode:'resume',originalHostContext:'drive-host-a',answers:undefined,checks:undefined}),'status');
|
|
186
|
+
assert.equal(status.status,0,status.stderr);assert.equal(JSON.parse(status.stdout).result.state,'awaiting_review');
|
|
187
|
+
assert.deepEqual(fs.readFileSync(f.store),before);
|
|
188
|
+
});
|
|
189
|
+
test('decision sends the package binding and needs no answer files',t=>{
|
|
190
|
+
const f=fixture(t);prepared(f);
|
|
191
|
+
const first=f.drive(f.plan(),'advance');assert.equal(first.status,0,first.stderr);
|
|
192
|
+
const packageDigest=JSON.parse(first.stdout).result.packageDigest;
|
|
193
|
+
const decision=f.drive(f.plan({mode:'resume',originalHostContext:'drive-host-a',
|
|
194
|
+
packageDigest,answers:undefined,checks:undefined}),'decision');
|
|
195
|
+
assert.equal(decision.status,0,decision.stderr);
|
|
196
|
+
assert.equal(JSON.parse(decision.stdout).result.code,'decision_required');
|
|
197
|
+
});
|
|
198
|
+
test('explicit allow-development permission reaches the host once',t=>{
|
|
199
|
+
const f=fixture(t);prepared(f);
|
|
200
|
+
const run=f.drive(f.plan({permissions:['--allow-development']}),'advance');
|
|
201
|
+
assert.equal(run.status,0,run.stderr);assert.equal(JSON.parse(run.stdout).result.code,'decision_required');
|
|
202
|
+
});
|
|
203
|
+
test('QA-fix child operation forwards its binding and returns parent gate result',t=>{
|
|
204
|
+
const f=fixture(t);prepared(f);assert.equal(f.drive(f.plan(),'advance').status,0);
|
|
205
|
+
const binding={feature:'1.work',identity,packageDigest:'a'.repeat(64),testRunId:'qa-child'};
|
|
206
|
+
fs.writeFileSync(path.join(f.root,'fix-owner.json'),JSON.stringify({specsRoot:f.specsDir,identity:{...identity,runId:'fix-run'},
|
|
207
|
+
configuration:{hostContextId:'drive-host-a',reproduction:{cwd:f.codeProject},qaSource:binding}}));
|
|
208
|
+
const attempt=f.drive(f.plan({mode:'resume',originalHostContext:'drive-host-a',
|
|
209
|
+
permissions:['--qa-fix-owner-config','fix-owner.json'],packageDigest:'a'.repeat(64),testRunId:'qa-child'}),'fix_status');
|
|
210
|
+
assert.equal(attempt.status,1,attempt.stderr);
|
|
211
|
+
assert.match(attempt.stderr,/qa_fix_parent_not_completed/);
|
|
212
|
+
});
|
|
213
|
+
test('QA-fix child action requires its own answer before any host request',t=>{
|
|
214
|
+
const f=fixture(t);prepared(f);assert.equal(f.drive(f.plan(),'advance').status,0);
|
|
215
|
+
const binding={feature:'1.work',identity,packageDigest:'a'.repeat(64),testRunId:'qa-child'};
|
|
216
|
+
fs.writeFileSync(path.join(f.root,'fix-owner.json'),JSON.stringify({specsRoot:f.specsDir,identity:{...identity,runId:'fix-run'},
|
|
217
|
+
configuration:{hostContextId:'drive-host-a',reproduction:{cwd:f.codeProject},qaSource:binding}}));
|
|
218
|
+
const options={mode:'resume',originalHostContext:'drive-host-a',packageDigest:'a'.repeat(64),
|
|
219
|
+
testRunId:'qa-child',fixOperation:'red_test',permissions:['--qa-fix-owner-config','fix-owner.json','--allow-qa-fix-start']};
|
|
220
|
+
const missing=f.drive(f.plan(options),'fix_action');assert.equal(missing.status,2);
|
|
221
|
+
assert.match(missing.stderr,/learning\.json/);
|
|
222
|
+
f.write('learning.json',{status:'no_relevant_lesson',summary:'No applicable project lesson'});
|
|
223
|
+
const sent=f.drive(f.plan(options),'fix_action');assert.equal(sent.status,1,sent.stderr);
|
|
224
|
+
assert.match(sent.stderr,/qa_fix_parent_not_completed/);
|
|
225
|
+
const learning={status:'no_relevant_lesson',summary:'No applicable project lesson'};
|
|
226
|
+
assert.deepEqual(qaFixAnswerFor({kind:'fix_learning',payload:{contextDigest:'binding'}},{fix_learning:learning},f.answers),
|
|
227
|
+
{contextDigest:'binding',...learning});
|
|
228
|
+
fs.writeFileSync(path.join(f.answers,'repair.txt'),'export const value = 43;\n');
|
|
229
|
+
assert.deepEqual(qaFixAnswerFor({kind:'fix_repair',payload:{expected:{'target.mjs':'old-hash'}}},
|
|
230
|
+
{fix_repair:{'target.mjs':'repair.txt'}},f.answers),
|
|
231
|
+
{outcome:'repaired',edits:[{path:'target.mjs',beforeSha256:'old-hash',content:'export const value = 43;\n'}]});
|
|
232
|
+
});
|
|
233
|
+
test('QA-fix answer travels through the shared JSONL core',t=>{
|
|
234
|
+
const f=fixture(t),host=path.join(f.root,'child-host.mjs'),wrapper=path.join(f.root,'child-drive.mjs');
|
|
235
|
+
fs.writeFileSync(host,`process.stdout.write(JSON.stringify({type:'host_ready',sessionId:'child'})+'\\n');
|
|
236
|
+
let text='';process.stdin.on('data',chunk=>{text+=chunk;let at;while((at=text.indexOf('\\n'))>=0){
|
|
237
|
+
const line=text.slice(0,at);text=text.slice(at+1);if(!line)continue;const row=JSON.parse(line);
|
|
238
|
+
if(row.operation==='fix_action')process.stdout.write(JSON.stringify({type:'host_request',sessionId:'child',
|
|
239
|
+
callId:'learning-call',requestDigest:'digest',kind:'fix_learning',payload:{contextDigest:'context'}})+'\\n');
|
|
240
|
+
if(row.type==='host_result')process.stdout.write(JSON.stringify({requestId:'drive',result:{stage:'child_answered',answer:row.result}})+'\\n');
|
|
241
|
+
}});`);
|
|
242
|
+
fs.writeFileSync(wrapper,`import {driveHost} from ${JSON.stringify(new URL('../runtime/js/cm-ai/drive-core.mjs',import.meta.url).href)};
|
|
243
|
+
import {qaFixAnswerFor} from ${JSON.stringify(new URL('./cm-ai-drive.mjs',import.meta.url).href)};
|
|
244
|
+
const answers={fix_learning:{status:'no_relevant_lesson',summary:'No applicable lesson'}};
|
|
245
|
+
driveHost({host:${JSON.stringify(host)},args:[],cwd:${JSON.stringify(f.root)},operation:'fix_action',answers,
|
|
246
|
+
answerFor:(row,value)=>qaFixAnswerFor(row,value,${JSON.stringify(f.answers)})});`);
|
|
247
|
+
const run=spawnSync(process.execPath,[wrapper],{encoding:'utf8',timeout:5000});
|
|
248
|
+
assert.equal(run.status,0,run.stderr);assert.match(run.stderr,/应答 fix_learning/);
|
|
249
|
+
assert.deepEqual(JSON.parse(run.stdout).result.answer,
|
|
250
|
+
{contextDigest:'context',status:'no_relevant_lesson',summary:'No applicable lesson'});
|
|
251
|
+
});
|
|
@@ -99,7 +99,7 @@ for(const mode of ['history','retest','unknown','failed-retest','double-pass','d
|
|
|
99
99
|
baseline:{cwd:codeProject,testFiles:['existing.mjs'],commands:[{id:'existing',command:[process.execPath,'existing.mjs']}],timeoutMs:2000},
|
|
100
100
|
repair:{scope:['value.mjs'],requirements:['requirements.md']},
|
|
101
101
|
walkthrough:{timeoutMs:2000,flows:[{id:'value',modules:['value'],steps:['Read value'],expected:['2'],kind:'commands',command:[process.execPath,'red.mjs']}]}};
|
|
102
|
-
const makeSerial=(parent,childIdentity,configuration,repairValue)=>createQaFixOwnerHost({parent,reopenParent:()=>openControlRun(definition,'resume',execution),
|
|
102
|
+
const makeSerial=(parent,childIdentity,configuration,repairValue)=>createQaFixOwnerHost({parent,hostContextId:'parent-host',parentHostContextId:'parent-host',reopenParent:()=>openControlRun(definition,'resume',execution),
|
|
103
103
|
...(double||automatic?{template:{specsRoot:specsDir,feature,identity,configuration:Object.fromEntries(Object.entries(configuration).filter(([key])=>key!=='qaSource'))}}
|
|
104
104
|
:{fix:{specsRoot:specsDir,identity:childIdentity,configuration}}),allowStart:true,autoFix:automatic,fixPermissions:permissions,
|
|
105
105
|
fixAuthorities:{authority:reviewHost.authority,finalAuthority:reviewHost.finalAuthority},fixExecution:{...reviewHost.execution,
|
package/scripts/cm-ai-host.mjs
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import fs from 'node:fs';
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
import {fileURLToPath} from 'node:url';
|
|
7
|
+
import {REVIEWED_HANDOFF_HINT} from '../runtime/js/cm-ai/host-handoff.mjs';
|
|
7
8
|
import {readRunDefinition,openControlRun,createCodexExecution} from './cm-ai-run.mjs';
|
|
8
9
|
import {createConversationExecution as executionFor} from '../runtime/js/cm-ai/host-conversation-execution.mjs';
|
|
9
10
|
import {createHostToolBridge} from '../runtime/js/cm-ai/host-tool-bridge.mjs';
|
|
@@ -14,8 +15,15 @@ import {createFixReviewHost} from '../runtime/js/cm-fix/host-review.mjs';
|
|
|
14
15
|
import {createHostReviewAuthority} from '../runtime/js/cm-ai/host-review-authority.mjs';
|
|
15
16
|
import {loadConfig,declaredRuntimes,resolveProtectedRuntimes} from './cm-workflow-config.mjs';
|
|
16
17
|
import {readHostWorkflowConfiguration,featureHasBrowserCases,readBrowserCapability} from '../runtime/js/cm-ai/host-workflow-capabilities.mjs';
|
|
17
|
-
import {digest,json,need,shape} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
18
|
+
import {digest,json,need,shape,id} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
18
19
|
export {executionFor as createConversationExecution,reviewConfiguration as readConversationReviewConfiguration};
|
|
20
|
+
export function withHandoffDiagnostic(host,error){
|
|
21
|
+
return {...host,async handle(request){
|
|
22
|
+
const result=await host.handle(request);
|
|
23
|
+
if(result?.code==='handoff_exists')error.write(`[host] ${REVIEWED_HANDOFF_HINT}\n`);
|
|
24
|
+
return result;
|
|
25
|
+
}};
|
|
26
|
+
}
|
|
19
27
|
export {conversationProtection} from '../runtime/js/cm-ai/host-conversation-execution.mjs';
|
|
20
28
|
export function readConversationProtection(file){
|
|
21
29
|
const stat=fs.lstatSync(file);need(stat.isFile()&&!stat.isSymbolicLink()&&stat.size<=64*1024,'invalid_protected_config');
|
|
@@ -25,11 +33,11 @@ export function readBootstrapConfiguration(file){
|
|
|
25
33
|
const stat=fs.lstatSync(file);need(stat.isFile()&&!stat.isSymbolicLink()&&stat.size<=64*1024,'invalid_bootstrap_config');
|
|
26
34
|
const config=json(JSON.parse(fs.readFileSync(file,'utf8')));shape(config,['selection']);return config;
|
|
27
35
|
}
|
|
28
|
-
const fixLocalPermissions=new Map(['red-test','baseline','regression','learning-writeback','walkthrough','finish',
|
|
36
|
+
const fixLocalPermissions=new Map(['red-test','baseline','regression','learning-writeback','walkthrough','finish','abandon',
|
|
29
37
|
'test-author','repair','cause-review','final-review']
|
|
30
38
|
.map(name=>[`--allow-qa-fix-${name}`,`--allow-${name}`]));
|
|
31
39
|
|
|
32
|
-
const usage='cm-ai-host.mjs serve --config RUN_DEFINITION.json --mode create|resume --host-context ID --allow-development [--runtime codex|claude] [--failover] [--review-config PATH] [--allow-review-attempt 1|2] [--workflow-config PATH] [--allow-qa] [--browser-qa available|unavailable]\nReview config is {model,preflight[,disabledSkills][,timeoutMs]}; timeoutMs is the reviewer transport budget in milliseconds (integer 1-3600000, default 60000), independent of protected mode and outside the authorized configuration digest.\ncm-ai-host.mjs preflight --config RUN_DEFINITION.json --review-model MODEL [--runtime codex|claude] (synthetic loopback only)';
|
|
40
|
+
const usage='cm-ai-host.mjs serve --config RUN_DEFINITION.json --mode create|resume --host-context ID --allow-development [--original-host-context ID] [--runtime codex|claude] [--failover] [--review-config PATH] [--allow-review-attempt 1|2] [--workflow-config PATH] [--allow-qa] [--browser-qa available|unavailable]\nReview config is {model,preflight[,disabledSkills][,timeoutMs]}; timeoutMs is the reviewer transport budget in milliseconds (integer 1-3600000, default 60000), independent of protected mode and outside the authorized configuration digest.\ncm-ai-host.mjs preflight --config RUN_DEFINITION.json --review-model MODEL [--runtime codex|claude] (synthetic loopback only)';
|
|
33
41
|
|
|
34
42
|
function reviewConfiguration(file){
|
|
35
43
|
const info=fs.lstatSync(file);
|
|
@@ -80,6 +88,7 @@ async function protectedExecutionFor(definition,hostContextId,extra,review,mode,
|
|
|
80
88
|
return executionFor(definition,hostContextId,bridge,review,
|
|
81
89
|
extra.has('--allow-review-attempt')?Number(extra.get('--allow-review-attempt')):null,
|
|
82
90
|
workflow,extra.has('--allow-qa'),runtime,{
|
|
91
|
+
...(extra.has('--original-host-context')?{originalHostContextId:extra.get('--original-host-context')}:{}),
|
|
83
92
|
protection:{checkCommands:config.checkCommands,timeoutMs:config.timeoutMs},
|
|
84
93
|
providerDevelopment:{model:config.model,attempt,...selected},
|
|
85
94
|
...(bootstrap?{bootstrap:{...bootstrap,allowWrite:extra.has('--allow-bootstrap-write')}}:{}),
|
|
@@ -122,21 +131,24 @@ function canResumeLegacyProtected(definition,runtime){
|
|
|
122
131
|
}
|
|
123
132
|
|
|
124
133
|
export async function main(argv=process.argv.slice(2),{input=process.stdin,output=process.stdout,error=process.stderr}={}){
|
|
134
|
+
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--original-host-context ID is resume-only: keep the creating session in durable configuration while --host-context remains the real live session. Equal IDs mean a same-session reopen. Parent conversation runs only; legacy protected runs, batch and QA-fix children are unchanged.\n');
|
|
125
135
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('Approved 0.bootstrap only: --bootstrap-config PATH {selection:null for scaffold, or original cm-init selection for rules} and --allow-bootstrap-write. Original scope must include fixed instruction targets; they are host-written inside the original task effect, checked/reviewed and reloaded. No Git/install/network grant. Optional codeProjects selects disjoint real roots below codeProject; prefix scope/requirements and use protected current-session checks with a declared codeProject per command.\n');
|
|
126
136
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('Protected current-session mode (Codex or Claude; also batch): --protected-conversation-config PATH with {checkCommands,timeoutMs}; timeoutMs bounds both check commands and the reviewer process. A review transport timeout with no result can resume once per attempt with fresh review authorization; a result-bearing timeout still requires reconciliation. No extra model call. The current host returns scoped UTF-8 edits; native Codex sandbox applies them and runs the declared checks. Original author runtime, per-attempt Review and QA permissions remain required. Do not combine with --protected-config. Same original 64KiB transport limit; unavailable/binary changes stop, never switch to direct writes.\n');
|
|
127
137
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('Protected single-task CLI mode: add --protected-config PATH --allow-provider-development-attempt 1|2 and --review-config PATH. Protected config is {model,checkCommands,timeoutMs}; roots and host identity come from the original run definition and launch. This explicitly permits one task attempt of real developer execution and its declared native-sandbox checks; --allow-development alone does not. Review separately requires --allow-review-attempt 1|2. Diagnostics are required but are not review authorization. Optional original --workflow-config PATH and --allow-qa connect protected QA commands and documentation within the same developer invocation before Review; host semantic/browser/inspection requests retain their original contracts, not arbitrary writes. Default current-session mode is unchanged. Protected parent mode selects coder/reviewer CLIs from the project declaration; Claude returns protected-text-v1 proposals for host validation and sandbox application; original QA-fix options require child configuration.protectSpecs=true and all original child action permissions. Protected fix writes use text proposals, not direct host edits. The original QA/documentation/finalizer gates remain required. No installation or Git authority.\n');
|
|
128
138
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--browser-qa is required when the approved contract for this feature contains blocking browser cases or policy-enabled browser cases and QA is enabled, and must not be given otherwise. It is a declaration by the launching session, not a probe: the host cannot verify that this session can drive a browser. The gate applies to create and resume alike, so every launch must assert it again; the assertion is not persisted, because a stored assertion would only repeat the claim made by whichever session wrote it. unavailable refuses to start; either launch from a browser-capable session or remove browser cases from the approved contract.\n');
|
|
139
|
+
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--revise-qa-config PREVIOUS_WORKFLOW.json --qa-config-revision-reason REASON: 仅 resume 且 --allow-qa;核对旧配置后追加 QA 修订,旧 QA 作废留史,下一轮仍受三轮上限约束。未知 QA 须先处理;不能修改开发配置或重开 N5。\n');
|
|
129
140
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--auto-qa-fix optionally connects parent advance -> fix_run -> re-QA. Requires --qa-fix-template-config, --allow-qa-fix-start, original action permissions and project policies.auto_fix=auto. Explicit/never policies stop. Unknown, blocked or incomplete repair stops; status/cancel remain available and no fourth QA round is dispatched.\n');
|
|
130
141
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--qa-fix-template-config PATH is an alternative to --qa-fix-owner-config. Supply {specsRoot, feature, identity: parent identity, configuration: original fix configuration without qaSource}. Each fix request binds it to the latest completed QA failure; identity/digests are generated, commands/scope/permissions are not. Existing child configuration remains immutable.\n');
|
|
131
|
-
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('fix_run continuously executes normal stages of the fixed QA child using the same binding as fix_advance. Requires --allow-qa-fix-start and every original per-action permission/configuration. Stops on unknown, blocked, observation, revision-required or unchanged state. It does not auto-switch child configuration or run parent QA.\n');
|
|
132
|
-
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('fix_action delegates to the shared original cm-fix dispatcher. Local flags: --allow-qa-fix-red-test, --allow-qa-fix-baseline, --allow-qa-fix-regression, --allow-qa-fix-learning-writeback, --allow-qa-fix-walkthrough, --allow-qa-fix-finish. Adapter flags: --allow-qa-fix-test-author, --allow-qa-fix-repair, --allow-qa-fix-cause-review, --allow-qa-fix-final-review, with separate --qa-fix-review-config PATH and matching original child reviewer metadata. All require --allow-qa-fix-start and the original action configuration/gates. Parent --review-config/--allow-review-attempt do not grant child review permission.\n');
|
|
133
|
-
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--allow-qa-fix-start additionally permits fix_advance to create or resume the fixed QA child and run only its original Learning/reproduction/diagnosis stages. Child
|
|
142
|
+
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('fix_run continuously executes normal stages of the fixed QA child using the same binding as fix_advance. Requires --allow-qa-fix-start and every original per-action permission/configuration. Stops on unknown, blocked, observation, revision-required or unchanged state; a design-change child closes as escalated and reports qa_fix_incomplete, never qa_fix_completed. It does not auto-switch child configuration or run parent QA.\n');
|
|
143
|
+
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('fix_action delegates to the shared original cm-fix dispatcher. Local flags: --allow-qa-fix-red-test, --allow-qa-fix-baseline, --allow-qa-fix-regression, --allow-qa-fix-learning-writeback, --allow-qa-fix-walkthrough, --allow-qa-fix-finish, --allow-qa-fix-abandon. abandon_step also requires a reason in the fix_action request and only applies to eligible local unknown steps. Adapter flags: --allow-qa-fix-test-author, --allow-qa-fix-repair, --allow-qa-fix-cause-review, --allow-qa-fix-final-review, with separate --qa-fix-review-config PATH and matching original child reviewer metadata. All require --allow-qa-fix-start and the original action configuration/gates. Parent --review-config/--allow-review-attempt do not grant child review permission.\n');
|
|
144
|
+
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--allow-qa-fix-start additionally permits fix_advance to create or resume the fixed QA child and run only its original Learning/reproduction/diagnosis stages. Child runtime must match this host. A new child hostContextId must be the live session or the parent durable creator; an existing child retains its fingerprint-verified configuration. Child opens and review grants use the live session. It does not authorize test authoring, repair, independent provider Review, finish, Git or re-QA. Active child status/cancel use the original child owner; repeated advance never resets an unknown or completed step.\n');
|
|
134
145
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--qa-fix-owner-config PATH enables read-only fix_status. The file contains the existing fix owner definition {specsRoot, identity, configuration}, including its exact original qaSource and immutable configuration, not provider grants. fix_status binds the parent identity/packageDigest/testRunId, serially closes the parent writer, opens only an existing child, reads its original completion evidence, closes it and resumes the same parent. It does not create/execute repairs, rerun QA or clear correction gates.\n');
|
|
135
146
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('Protected current-session invalid_result means local value/Learning validation failed before file writes. Fix the reply, keep the same configuration, host identity and runId, restart with --mode resume and advance: blocked/developer_result_invalid retries develop at the same attempt. no_new_lesson requires reason:null (dogfood incident: nonempty reason previously wrote files then stranded the run as unknown). Already-applied proposals must match expected disk hashes; conflicts block as protected_edit_stale. Worker exceptions/timeouts and old unknown history are not retryable.\n');
|
|
136
147
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('New cm-ai runs carry approved specification data in developer requests and review packages: task/verification, all AC lines, design (64 KiB UTF-8 maximum, truncated:true above it), task-related test cases and manifest hashes. Sources must match .cm-specs-status.specFiles or spec_drift blocks. requirements may be [] or additional code-project files; specs never become writable scope. Legacy runs/packages retain their original representation. Dogfood: separate specs/code roots previously left developers and reviewers without task/interface contracts.\n');
|
|
137
148
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('Completed fixture_completed runs originally without QA may explicitly attach N6 once on --mode resume with --workflow-config (non-null qa) and --allow-qa. Original definition, scope, requirements, identity and non-workflow configuration must match. The immutable qa-attached journal record binds the full resumed config fingerprint; later resumes require that same configuration and fresh --allow-qa. qa still requests qa_assess; no automatic decision or repeated development/Review. Dogfood: missing workflow at create previously stranded mandatory feature QA.\n');
|
|
138
149
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--rerun-unknown-qa requires --mode resume and fresh --allow-qa with the original workflow config. Only an unfinished QA invocation whose recorded case results are all PASS and which has no fixed execution report may be abandoned and rerun under a new testRunId at the same qaRound. The abandoned record lists partial_pass_cases; every case is rerun and old PASS evidence is history only. FAIL/BLOCKED results and unclosed resources remain blocked; no complete is fabricated.\n');
|
|
139
150
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--rerun-blocked-qa requires --mode resume, the original --workflow-config and fresh --allow-qa. Only the latest completed BLOCKED invocation with zero failures and exclusively host/environment evidence gaps can be superseded: browser evidenceProblem, failed cleanup, environment mismatch or host timeout; logic INSUFFICIENT_EVIDENCE. Commands BLOCKED and source drift are excluded. A new testRunId reruns every case at qaRound+1 (maximum 3); superseded and start link previous_test_run_id. The flag is consumed once, never persisted; no development/Review/task replay or new QA decision. Do not combine with --rerun-unknown-qa.\n');
|
|
151
|
+
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--supersede-reviewed-evidence --supersede-reason REASON:仅新建同任务运行;旧运行都已终止且 tasks.md 未勾选时,先在新 journal 记授权,再归档旧审查证据。\n');
|
|
140
152
|
if(argv.length===1&&['--help','-h'].includes(argv[0])){output.write(usage+'\n');return 0;}
|
|
141
153
|
let run,bridge;
|
|
142
154
|
try{
|
|
@@ -154,10 +166,21 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
154
166
|
const extra=new Map();
|
|
155
167
|
for(let index=8;index<argv.length;index++){
|
|
156
168
|
const name=argv[index];need(!extra.has(name),'invalid_arguments');
|
|
157
|
-
need(['--bootstrap-config','--allow-bootstrap-write','--protected-conversation-config','--protected-config','--allow-provider-development-attempt','--review-config','--allow-review-attempt','--workflow-config','--allow-qa','--browser-qa','--rerun-unknown-qa','--rerun-blocked-qa','--runtime','--failover','--qa-fix-owner-config','--qa-fix-template-config','--qa-fix-review-config','--allow-qa-fix-start','--auto-qa-fix',...fixLocalPermissions.keys()].includes(name),'invalid_arguments');
|
|
158
|
-
if(['--allow-bootstrap-write','--allow-qa','--rerun-unknown-qa','--rerun-blocked-qa','--failover','--allow-qa-fix-start','--auto-qa-fix',...fixLocalPermissions.keys()].includes(name))extra.set(name,true);
|
|
169
|
+
need(['--revise-qa-config','--qa-config-revision-reason','--supersede-reviewed-evidence','--supersede-reason','--original-host-context','--bootstrap-config','--allow-bootstrap-write','--protected-conversation-config','--protected-config','--allow-provider-development-attempt','--review-config','--allow-review-attempt','--workflow-config','--allow-qa','--browser-qa','--rerun-unknown-qa','--rerun-blocked-qa','--runtime','--failover','--qa-fix-owner-config','--qa-fix-template-config','--qa-fix-review-config','--allow-qa-fix-start','--auto-qa-fix',...fixLocalPermissions.keys()].includes(name),'invalid_arguments');
|
|
170
|
+
if(['--supersede-reviewed-evidence','--allow-bootstrap-write','--allow-qa','--rerun-unknown-qa','--rerun-blocked-qa','--failover','--allow-qa-fix-start','--auto-qa-fix',...fixLocalPermissions.keys()].includes(name))extra.set(name,true);
|
|
159
171
|
else{need(typeof argv[index+1]==='string'&&!argv[index+1].startsWith('--'),'invalid_arguments');extra.set(name,argv[++index]);}
|
|
160
172
|
}
|
|
173
|
+
const revisionRequested=extra.has('--revise-qa-config')||extra.has('--qa-config-revision-reason');
|
|
174
|
+
need(!extra.has('--supersede-reviewed-evidence')&&!extra.has('--supersede-reason')
|
|
175
|
+
||(argv[4]==='create'&&extra.has('--supersede-reviewed-evidence')&&extra.has('--supersede-reason')),
|
|
176
|
+
'supersede_unavailable');
|
|
177
|
+
need(!revisionRequested||(argv[4]==='resume'&&extra.has('--allow-qa')&&extra.has('--revise-qa-config')
|
|
178
|
+
&&extra.has('--qa-config-revision-reason')&&!extra.has('--rerun-unknown-qa')&&!extra.has('--rerun-blocked-qa')),'qa_revision_authorization_required');
|
|
179
|
+
const qaConfigRevision=revisionRequested?{previousWorkflow:readHostWorkflowConfiguration(extra.get('--revise-qa-config')),
|
|
180
|
+
reason:extra.get('--qa-config-revision-reason')}:null;
|
|
181
|
+
const originalHostContextId=extra.get('--original-host-context')??null;
|
|
182
|
+
if(originalHostContextId!==null){need(argv[4]==='resume','original_host_context_unavailable');id(originalHostContextId);}
|
|
183
|
+
if(originalHostContextId===argv[6])extra.delete('--original-host-context');
|
|
161
184
|
const review=extra.has('--review-config')?reviewConfiguration(extra.get('--review-config')):null;
|
|
162
185
|
const workflow=extra.has('--workflow-config')?readHostWorkflowConfiguration(extra.get('--workflow-config')):null;
|
|
163
186
|
let allowedAttempt=null;
|
|
@@ -211,10 +234,10 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
211
234
|
if(extra.has('--protected-config')||protection)need(fix.configuration?.protectSpecs===true,'protected_fix_required');
|
|
212
235
|
}
|
|
213
236
|
let execution;
|
|
214
|
-
if(argv[4]==='resume'&&extra.has('--protected-config')&&canResumeLegacyProtected(definition,runtime)){
|
|
237
|
+
if(argv[4]==='resume'&&!extra.has('--original-host-context')&&extra.has('--protected-config')&&canResumeLegacyProtected(definition,runtime)){
|
|
215
238
|
try{
|
|
216
239
|
execution=await legacyProtectedExecutionFor(definition,argv[6],extra,review,argv[4],workflow,bridge,bootstrap);
|
|
217
|
-
run=await openControlRun(definition,argv[4],execution,{rerunUnknownQa:extra.has('--rerun-unknown-qa'),rerunBlockedQa:extra.has('--rerun-blocked-qa')});
|
|
240
|
+
run=await openControlRun(definition,argv[4],execution,{qaConfigRevision,rerunUnknownQa:extra.has('--rerun-unknown-qa'),rerunBlockedQa:extra.has('--rerun-blocked-qa'),supersedeReason:extra.get('--supersede-reason')??null});
|
|
218
241
|
error.write('cm-ai-host: resumed original Codex protected execution after exact fingerprint validation.\n');
|
|
219
242
|
}catch(cause){
|
|
220
243
|
if(!['fingerprint_mismatch','tool_preflight_missing'].includes(cause.code))throw cause;
|
|
@@ -225,8 +248,8 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
225
248
|
execution=extra.has('--protected-config')
|
|
226
249
|
?await protectedExecutionFor(definition,argv[6],extra,review,argv[4],workflow,bridge,bootstrap)
|
|
227
250
|
:executionFor(definition,argv[6],bridge,review,allowedAttempt,workflow,extra.has('--allow-qa'),runtime,
|
|
228
|
-
{...(protection?{protection}:{}),...(bootstrap?{bootstrap:{...bootstrap,allowWrite:extra.has('--allow-bootstrap-write')}}:{})});
|
|
229
|
-
run=await openControlRun(definition,argv[4],execution,{rerunUnknownQa:extra.has('--rerun-unknown-qa'),rerunBlockedQa:extra.has('--rerun-blocked-qa')});
|
|
251
|
+
{...(extra.has('--original-host-context')?{originalHostContextId:extra.get('--original-host-context')}:{}),...(protection?{protection}:{}),...(bootstrap?{bootstrap:{...bootstrap,allowWrite:extra.has('--allow-bootstrap-write')}}:{})});
|
|
252
|
+
run=await openControlRun(definition,argv[4],execution,{qaConfigRevision,rerunUnknownQa:extra.has('--rerun-unknown-qa'),rerunBlockedQa:extra.has('--rerun-blocked-qa'),supersedeReason:extra.get('--supersede-reason')??null});
|
|
230
253
|
}
|
|
231
254
|
if(run.blocked){output.write(JSON.stringify({outcome:'blocked',admission:run.blocked})+'\n');return 1;}
|
|
232
255
|
if(hasFix){
|
|
@@ -234,17 +257,16 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
234
257
|
&&fs.realpathSync(fix.configuration.reproduction.cwd)===fs.realpathSync(definition.codeProject)
|
|
235
258
|
&&(templated?fix.feature:fix.configuration.qaSource.feature)===definition.feature,'qa_fix_source_mismatch');
|
|
236
259
|
if(templated)need(digest(fix.identity)===digest(definition.identity),'qa_fix_source_mismatch');
|
|
237
|
-
if(extra.has('--allow-qa-fix-start'))need(fix.configuration.
|
|
238
|
-
&&(fix.configuration.runtime??'codex')===runtime,'qa_fix_host_mismatch');
|
|
260
|
+
if(extra.has('--allow-qa-fix-start'))need((fix.configuration.runtime??'codex')===runtime,'qa_fix_host_mismatch');
|
|
239
261
|
const fixPermissions=[...fixLocalPermissions].filter(([flag])=>extra.has(flag)).map(([,permission])=>permission);
|
|
240
262
|
const fixReview=extra.has('--qa-fix-review-config')?reviewConfiguration(extra.get('--qa-fix-review-config')):null;
|
|
241
263
|
need(!fixPermissions.includes('--allow-test-author')||(fix.configuration.testAuthor&&fixReview),'test_author_configuration_required');
|
|
242
264
|
need(!fixPermissions.includes('--allow-repair')||(fix.configuration.repair&&fixReview),'repair_configuration_required');
|
|
243
265
|
const fixReviewHost=createFixReviewHost({codeProject:definition.codeProject,
|
|
244
|
-
hostContextId:
|
|
266
|
+
hostContextId:argv[6],runtime:fix.configuration.runtime??'codex',
|
|
245
267
|
review:fixReview,permissions:fixPermissions});
|
|
246
268
|
if(fixReview)need(digest(fix.configuration.causeReview??null)===digest(fixReviewHost.reviewer),'qa_fix_review_configuration_mismatch');
|
|
247
|
-
const host=createQaFixOwnerHost({parent:run,...(templated?{template:fix}:{fix}),reopenParent:()=>openControlRun(definition,'resume',execution),
|
|
269
|
+
const host=createQaFixOwnerHost({parent:run,hostContextId:argv[6],parentHostContextId:execution.configuration.hostContextId,...(templated?{template:fix}:{fix}),reopenParent:()=>openControlRun(definition,'resume',execution),
|
|
248
270
|
fixPermissions,fixAuthorities:{authority:fixReviewHost.authority,finalAuthority:fixReviewHost.finalAuthority},
|
|
249
271
|
allowStart:extra.has('--allow-qa-fix-start'),autoFix:extra.has('--auto-qa-fix'),fixExecution:{bridge,...fixReviewHost.execution,
|
|
250
272
|
prepare:createFixLearningPreparation({bridge,codeProject:definition.codeProject,
|
|
@@ -254,13 +276,14 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
254
276
|
// PTY sessions are used by desktop tool hosts. Disable echo only on this
|
|
255
277
|
// process's own terminal so tool results are not mistaken for output frames.
|
|
256
278
|
const rawMode=input.isTTY&&typeof input.setRawMode==='function';if(rawMode)input.setRawMode(true);
|
|
257
|
-
|
|
279
|
+
const diagnosticHost=withHandoffDiagnostic(run.host,error);
|
|
280
|
+
try{await serveCmAiHost({host:diagnosticHost,input,output,toolBridge:bridge,errorOutput:error});}
|
|
258
281
|
finally{if(rawMode)input.setRawMode(false);}
|
|
259
282
|
return 0;
|
|
260
283
|
}catch(cause){
|
|
261
284
|
const code=typeof cause?.code==='string'&&(/^[a-z][a-z0-9_]{0,63}$/.test(cause.code)
|
|
262
285
|
||cause.code.startsWith('invalid_config: '))?cause.code:'host_launch_failed';
|
|
263
|
-
error.write(JSON.stringify({error:{code}})+'\n');return 1;
|
|
286
|
+
error.write(JSON.stringify({error:{code,...(code==='supersede_unavailable'&&typeof cause.reason==='string'?{reason:cause.reason}:{})}})+'\n');return 1;
|
|
264
287
|
}finally{bridge?.close();run?.close();}
|
|
265
288
|
}
|
|
266
289
|
if(process.argv[1]&&fs.realpathSync(process.argv[1])===fileURLToPath(import.meta.url))process.exitCode=await main();
|
|
@@ -951,3 +951,40 @@ test('step31 CLI resumes completed evidence BLOCKED QA and reaches the original
|
|
|
951
951
|
}
|
|
952
952
|
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
953
953
|
});
|
|
954
|
+
|
|
955
|
+
test('F7 CLI explicitly revises missing QA commands after N5 and resumes the same run',async()=>{
|
|
956
|
+
const f=fixture();
|
|
957
|
+
try{
|
|
958
|
+
f.workflow=true;
|
|
959
|
+
const definition=JSON.parse(fs.readFileSync(f.config));definition.scope.push('README.md');
|
|
960
|
+
fs.writeFileSync(f.config,JSON.stringify(definition));
|
|
961
|
+
const bin=path.join(f.root,'bin');fs.mkdirSync(bin);
|
|
962
|
+
const fake=path.join(bin,'codex');fs.copyFileSync(fileURLToPath(new URL('./fixtures/codex-review-process.mjs',import.meta.url)),fake);
|
|
963
|
+
fs.chmodSync(fake,0o700);f.env={...process.env,PATH:bin+path.delimiter+process.env.PATH};
|
|
964
|
+
const preview=spawnSync(process.execPath,[cli,'preflight','--config',f.config,'--review-model','fixture'],
|
|
965
|
+
{encoding:'utf8',env:f.env,timeout:15000});assert.equal(preview.status,0,preview.stderr);
|
|
966
|
+
const review=path.join(f.root,'review.json');fs.writeFileSync(review,preview.stdout);
|
|
967
|
+
const oldWorkflow={documentationPaths:['README.md'],applicableAgentFiles:[],qa:{commands:[],
|
|
968
|
+
environment:{kind:'web',carrier:'browser',target:'fixture',scope:'local'}}};
|
|
969
|
+
const oldFile=path.join(f.root,'workflow-old.json'),file=path.join(f.root,'workflow.json');
|
|
970
|
+
fs.writeFileSync(oldFile,JSON.stringify(oldWorkflow));fs.writeFileSync(file,JSON.stringify(oldWorkflow));
|
|
971
|
+
f.args.push('--review-config',review,'--allow-review-attempt','1','--workflow-config',file,'--allow-qa');
|
|
972
|
+
const first=await runCli(f,'normal');assert.equal(first.code,0,first.stderr);
|
|
973
|
+
assert.equal(first.rows.find(row=>row.requestId==='advance').result.code,'qa_result_blocked');
|
|
974
|
+
const stateFile=path.join(f.specsDir,'.reviews','.execution',identity.runId,'state.json');
|
|
975
|
+
const before=JSON.parse(fs.readFileSync(stateFile));
|
|
976
|
+
fs.writeFileSync(file,JSON.stringify({...oldWorkflow,qa:{...oldWorkflow.qa,
|
|
977
|
+
commands:[{id:'syntax',command:[process.execPath,'--check','target.mjs'],caseIds:[]}]}}));
|
|
978
|
+
const denied=await runCli(f,'normal','resume');assert.equal(denied.code,1);assert.match(denied.stderr,/fingerprint_mismatch/);
|
|
979
|
+
f.args.push('--revise-qa-config',oldFile,'--qa-config-revision-reason','Correct missing QA command');
|
|
980
|
+
const resumed=await runCli(f,'authorized-review','resume');assert.equal(resumed.code,0,resumed.stderr);
|
|
981
|
+
assert.equal(resumed.rows.find(row=>row.requestId==='advance').result.code,'run_done');
|
|
982
|
+
assert.deepEqual(resumed.calls,['documentation_inspect']);
|
|
983
|
+
const after=JSON.parse(fs.readFileSync(stateFile));assert.deepEqual(after.records.slice(0,before.records.length),before.records);
|
|
984
|
+
assert.equal(after.records.filter(row=>row.payload.type==='qa-config-revised').length,1);
|
|
985
|
+
f.args.splice(-4);
|
|
986
|
+
const again=await runCli(f,'normal','resume');assert.equal(again.code,0,again.stderr);
|
|
987
|
+
assert.equal(again.rows.find(row=>row.requestId==='advance').result.code,'run_done');
|
|
988
|
+
assert.deepEqual(JSON.parse(fs.readFileSync(stateFile)),after);
|
|
989
|
+
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
990
|
+
});
|