@aibyzero/cm-workflow 0.15.5 → 0.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.codex-plugin/plugin.json +1 -1
- package/CHANGELOG.md +45 -0
- package/README.md +2 -2
- package/VERSION +1 -1
- package/docs/installation.md +1 -1
- package/docs/js-workflow-control.md +174 -3
- package/package.json +1 -1
- package/runtime/js/cm-ai/checklist-coverage.mjs +70 -0
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +12 -2
- package/runtime/js/cm-ai/durable-runner-state.mjs +12 -1
- package/runtime/js/cm-ai/effect-contract.mjs +31 -4
- package/runtime/js/cm-ai/host-conversation-execution.mjs +91 -3
- package/runtime/js/cm-ai/host-handoff.mjs +59 -1
- package/runtime/js/cm-ai/host-session.mjs +21 -2
- package/runtime/js/cm-ai/host-tool-bridge.mjs +1 -1
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +4 -1
- package/runtime/js/cm-ai/review-package.mjs +29 -3
- package/runtime/js/cm-ai/task-runner.mjs +44 -3
- package/runtime/js/cm-fix/cause-invocation.mjs +17 -4
- package/runtime/js/cm-fix/execution.mjs +30 -22
- package/runtime/js/cm-fix/final-review.mjs +18 -11
- package/runtime/js/cm-fix/finish.mjs +14 -1
- package/runtime/js/cm-security/scan.mjs +7 -1
- package/scripts/cm-ai-batch-host.mjs +18 -6
- package/scripts/cm-ai-batch-run.mjs +12 -4
- package/scripts/cm-ai-checklist-coverage.test.mjs +116 -0
- package/scripts/cm-ai-execution-diagnostic.test.mjs +68 -0
- package/scripts/cm-ai-host.mjs +7 -2
- package/scripts/cm-ai-qa-recovery-args.test.mjs +80 -0
- package/scripts/cm-ai-review-timeout-config.test.mjs +53 -0
- package/scripts/cm-ai-run.mjs +2 -1
- package/scripts/cm-ai-verification-gate.test.mjs +116 -0
- package/scripts/cm-fix-cross-session-host.test.mjs +100 -0
- package/scripts/cm-fix-execution.test.mjs +33 -0
- package/scripts/cm-fix-host.mjs +11 -5
- package/scripts/cm-fix-repair-owner.test.mjs +22 -18
- package/scripts/cm-host-handoff.test.mjs +116 -1
- package/scripts/cm-host-session-diagnostic.test.mjs +82 -0
- package/scripts/cm-review-dependency-snapshot.test.mjs +85 -0
- package/scripts/cm-review-inventory.test.mjs +42 -0
- package/scripts/cm-security.test.mjs +24 -0
- package/skills/cm-ai/references/N3-execute-task.md +10 -0
- package/skills/cm-fix/references/js-host.md +18 -1
- package/templates/auto-update/cm-update.sh +51 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import test from 'node:test';
|
|
3
|
+
|
|
4
|
+
import {executionDiagnostic,failureCode,reportExecutionCollapse} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
5
|
+
|
|
6
|
+
const collapse=error=>{let out='';reportExecutionCollapse(error,value=>{out+=value;});return out;};
|
|
7
|
+
const named=(message,fields)=>Object.assign(new Error(message),fields);
|
|
8
|
+
|
|
9
|
+
test('a filesystem collapse names the syscall and both paths', () => {
|
|
10
|
+
const line=collapse(named('EEXIST: file already exists, link a -> b',
|
|
11
|
+
{code:'EEXIST',syscall:'link',path:'/specs/.reviews/.cm-initial-handoff-1',dest:'/specs/.reviews/x-a1-handoff.json'}));
|
|
12
|
+
assert.equal(line.endsWith('\n'),true);
|
|
13
|
+
assert.deepEqual(JSON.parse(line),{diagnostic:'execution_error',code:'EEXIST',syscall:'link',
|
|
14
|
+
path:'/specs/.reviews/.cm-initial-handoff-1',dest:'/specs/.reviews/x-a1-handoff.json'});
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test('an internal contract collapse carries its code alone', () => {
|
|
18
|
+
assert.deepEqual(JSON.parse(collapse(named('store_missing',{code:'store_missing'}))),
|
|
19
|
+
{diagnostic:'execution_error',code:'store_missing'});
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test('the raw message is never emitted', () => {
|
|
23
|
+
const line=collapse(named('secret token sk-live-0123456789 leaked from provider output',{code:'EPERM'}));
|
|
24
|
+
assert.equal(line.includes('sk-live'),false);
|
|
25
|
+
assert.equal(line.includes('secret'),false);
|
|
26
|
+
assert.deepEqual(JSON.parse(line),{diagnostic:'execution_error',code:'EPERM'});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('fields that are absent, oversized or control-bearing are dropped', () => {
|
|
30
|
+
assert.equal(executionDiagnostic(named('x',{code:'EBADF',path:'a'.repeat(1025)})).path,undefined);
|
|
31
|
+
assert.equal(executionDiagnostic(named('x',{code:'EBADF',syscall:`open${String.fromCharCode(0)}rm`})).syscall,undefined);
|
|
32
|
+
assert.equal(executionDiagnostic(named('x',{code:'EBADF',dest:''})).dest,undefined);
|
|
33
|
+
assert.deepEqual(executionDiagnostic(named('x',{code:'EBADF'})),{code:'EBADF'});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('an error with no usable field still produces a line', () => {
|
|
37
|
+
assert.deepEqual(JSON.parse(collapse(new Error('no code at all'))),
|
|
38
|
+
{diagnostic:'execution_error',detail:'unavailable'});
|
|
39
|
+
assert.equal(executionDiagnostic(new Error('no code at all')),null);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('an allowlisted code returns unchanged and emits nothing', () => {
|
|
43
|
+
let emitted=false;
|
|
44
|
+
const original=process.stderr.write;
|
|
45
|
+
process.stderr.write=(...args)=>{emitted=true;return original.apply(process.stderr,args);};
|
|
46
|
+
try{assert.equal(failureCode(named('invalid_input',{code:'invalid_input'})),'invalid_input');}
|
|
47
|
+
finally{process.stderr.write=original;}
|
|
48
|
+
assert.equal(emitted,false);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test('an unlisted code collapses and emits exactly one line', () => {
|
|
52
|
+
const lines=[];
|
|
53
|
+
const original=process.stderr.write;
|
|
54
|
+
process.stderr.write=value=>{lines.push(String(value));return true;};
|
|
55
|
+
try{assert.equal(failureCode(named('EEXIST: x',{code:'EEXIST',syscall:'link'})),'execution_error');}
|
|
56
|
+
finally{process.stderr.write=original;}
|
|
57
|
+
assert.equal(lines.length,1);
|
|
58
|
+
assert.deepEqual(JSON.parse(lines[0]),{diagnostic:'execution_error',code:'EEXIST',syscall:'link'});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('an error whose code cannot be read still collapses without throwing', () => {
|
|
62
|
+
const hostile={};
|
|
63
|
+
Object.defineProperty(hostile,'code',{get(){throw new Error('trap');}});
|
|
64
|
+
const original=process.stderr.write;
|
|
65
|
+
process.stderr.write=()=>true;
|
|
66
|
+
try{assert.equal(failureCode(hostile),'execution_error');}
|
|
67
|
+
finally{process.stderr.write=original;}
|
|
68
|
+
});
|
package/scripts/cm-ai-host.mjs
CHANGED
|
@@ -29,17 +29,22 @@ const fixLocalPermissions=new Map(['red-test','baseline','regression','learning-
|
|
|
29
29
|
'test-author','repair','cause-review','final-review']
|
|
30
30
|
.map(name=>[`--allow-qa-fix-${name}`,`--allow-${name}`]));
|
|
31
31
|
|
|
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]\ncm-ai-host.mjs preflight --config RUN_DEFINITION.json --review-model MODEL [--runtime codex|claude] (synthetic loopback only)';
|
|
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)';
|
|
33
33
|
|
|
34
34
|
function reviewConfiguration(file){
|
|
35
35
|
const info=fs.lstatSync(file);
|
|
36
36
|
need(info.isFile()&&!info.isSymbolicLink()&&info.size<=64*1024,'invalid_review_config');
|
|
37
37
|
const config=json(JSON.parse(fs.readFileSync(file,'utf8')));
|
|
38
|
-
shape(config,['model','preflight',...(Object.hasOwn(config,'disabledSkills')?['disabledSkills']:[])
|
|
38
|
+
shape(config,['model','preflight',...(Object.hasOwn(config,'disabledSkills')?['disabledSkills']:[]),
|
|
39
|
+
...(Object.hasOwn(config,'timeoutMs')?['timeoutMs']:[])]);
|
|
39
40
|
need(typeof config.model==='string'&&/^[a-zA-Z0-9._-]+$/.test(config.model),'invalid_review_config');
|
|
40
41
|
const disabledSkills=config.disabledSkills??[];
|
|
41
42
|
need(Array.isArray(disabledSkills)&&disabledSkills.length<=4096
|
|
42
43
|
&&disabledSkills.every(item=>typeof item==='string'&&path.isAbsolute(item)&&!/[\n\r\0]/.test(item)),'invalid_review_config');
|
|
44
|
+
// Reviewer transport budget only. It is not part of the authorized configuration
|
|
45
|
+
// digest, so a resumed run may raise it after a transport timeout.
|
|
46
|
+
if(Object.hasOwn(config,'timeoutMs'))need(Number.isInteger(config.timeoutMs)
|
|
47
|
+
&&config.timeoutMs>=1&&config.timeoutMs<=3600000,'invalid_review_config');
|
|
43
48
|
return json({...config,disabledSkills});
|
|
44
49
|
}
|
|
45
50
|
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import test from 'node:test';
|
|
6
|
+
import {spawnSync} from 'node:child_process';
|
|
7
|
+
import {fileURLToPath} from 'node:url';
|
|
8
|
+
|
|
9
|
+
import {validateHostWorkflowConfiguration} from '../runtime/js/cm-ai/host-workflow-capabilities.mjs';
|
|
10
|
+
|
|
11
|
+
const cli=fileURLToPath(new URL('./cm-ai-batch-host.mjs',import.meta.url));
|
|
12
|
+
|
|
13
|
+
const qa=timeoutMs=>({commands:[{id:'unit',command:['npm','test'],caseIds:[]}],
|
|
14
|
+
environment:{kind:'web',carrier:'browser',target:'fixture-command-only',scope:'local'},
|
|
15
|
+
...(timeoutMs===undefined?{}:{timeoutMs})});
|
|
16
|
+
const workflow=timeoutMs=>({qa:qa(timeoutMs),documentationPaths:[],applicableAgentFiles:[]});
|
|
17
|
+
|
|
18
|
+
test('a QA budget beyond one minute is accepted up to the shared call-timeout range', () => {
|
|
19
|
+
// A real browser walkthrough of one blocking case runs for minutes; the old
|
|
20
|
+
// 60000 cap made every such case time out with no way to raise it.
|
|
21
|
+
for(const timeoutMs of [1,60000,900000,3600000]){
|
|
22
|
+
assert.equal(validateHostWorkflowConfiguration(workflow(timeoutMs)).qa.timeoutMs,timeoutMs);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('a QA budget outside that range is still rejected', () => {
|
|
27
|
+
for(const timeoutMs of [0,-1,3600001,1.5,'900000',null]){
|
|
28
|
+
assert.throws(()=>validateHostWorkflowConfiguration(workflow(timeoutMs)),
|
|
29
|
+
error=>error.code==='invalid_workflow_config',`expected rejection for ${String(timeoutMs)}`);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('omitting the budget stays valid and plants no key', () => {
|
|
34
|
+
const config=validateHostWorkflowConfiguration(workflow(undefined));
|
|
35
|
+
assert.equal(Object.hasOwn(config.qa,'timeoutMs'),false);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
function batchFixture(fn){
|
|
39
|
+
const temp=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-qa-recovery-')));
|
|
40
|
+
const specs=path.join(temp,'specs'),code=path.join(temp,'code');
|
|
41
|
+
fs.mkdirSync(path.join(specs,'.reviews'),{recursive:true});fs.mkdirSync(code,{recursive:true});
|
|
42
|
+
const config=path.join(temp,'batch.json');
|
|
43
|
+
fs.writeFileSync(config,JSON.stringify({batch:{version:1,repositoryId:'fixture',batchId:'recovery-fixture',
|
|
44
|
+
specsDir:specs,codeProject:code,tasks:[{feature:'9.demo',taskId:'T-001',scope:['a.mjs'],requirements:[]}]},
|
|
45
|
+
workflows:{'9.demo/T-001':workflow(900000)}}));
|
|
46
|
+
const run=args=>spawnSync(process.execPath,[cli,'serve','--config',config,'--host-context','author',
|
|
47
|
+
'--allow-development',...args],{encoding:'utf8',timeout:15000,input:''});
|
|
48
|
+
try{fn(run);}finally{fs.rmSync(temp,{recursive:true,force:true});}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
test('the two QA recovery flags are mutually exclusive', () => batchFixture(run => {
|
|
52
|
+
const result=run(['--allow-qa','--rerun-unknown-qa','--rerun-blocked-qa']);
|
|
53
|
+
assert.equal(result.status,1);
|
|
54
|
+
assert.match(result.stderr,/qa_recovery_authorization_required/);
|
|
55
|
+
}));
|
|
56
|
+
|
|
57
|
+
test('a QA recovery flag without --allow-qa is refused', () => batchFixture(run => {
|
|
58
|
+
const result=run(['--rerun-blocked-qa']);
|
|
59
|
+
assert.equal(result.status,1);
|
|
60
|
+
assert.match(result.stderr,/qa_recovery_authorization_required/);
|
|
61
|
+
}));
|
|
62
|
+
|
|
63
|
+
test('the same flag twice is refused', () => batchFixture(run => {
|
|
64
|
+
const result=run(['--allow-qa','--rerun-blocked-qa','--rerun-blocked-qa']);
|
|
65
|
+
assert.equal(result.status,1);
|
|
66
|
+
assert.match(result.stderr,/invalid_arguments/);
|
|
67
|
+
}));
|
|
68
|
+
|
|
69
|
+
test('a single recovery flag with --allow-qa passes the launch guards', () => batchFixture(run => {
|
|
70
|
+
// The batch has no --mode: whether the flag applies is decided per task at
|
|
71
|
+
// open time, so the launch guards must not reject it the way the single-task
|
|
72
|
+
// host does. The fixture batch is otherwise minimal and still fails later for
|
|
73
|
+
// unrelated reasons, so this asserts only that the recovery guard stayed quiet.
|
|
74
|
+
const line=result=>result.stderr.split('\n').find(item=>item.startsWith('{'))??'';
|
|
75
|
+
const withFlag=run(['--allow-qa','--rerun-blocked-qa']);
|
|
76
|
+
const without=run(['--allow-qa']);
|
|
77
|
+
assert.equal(/qa_recovery_authorization_required/.test(withFlag.stderr),false,withFlag.stderr);
|
|
78
|
+
assert.equal(line(withFlag),line(without));
|
|
79
|
+
assert.equal(withFlag.status,without.status);
|
|
80
|
+
}));
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import test from 'node:test';
|
|
6
|
+
|
|
7
|
+
import {readConversationReviewConfiguration} from './cm-ai-host.mjs';
|
|
8
|
+
import {resolveReviewTimeout} from '../runtime/js/cm-ai/host-conversation-execution.mjs';
|
|
9
|
+
|
|
10
|
+
const preflight={passed:true,provider:'claude',prompt_transport:'stdin',config_fingerprint:'x'};
|
|
11
|
+
|
|
12
|
+
function configFile(value){
|
|
13
|
+
const root=fs.mkdtempSync(path.join(os.tmpdir(),'cm-review-timeout-'));
|
|
14
|
+
const file=path.join(root,'review.json');
|
|
15
|
+
fs.writeFileSync(file,JSON.stringify(value));
|
|
16
|
+
return file;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
test('review config accepts an explicit reviewer transport budget', () => {
|
|
20
|
+
const config=readConversationReviewConfiguration(configFile({model:'fixture',preflight,timeoutMs:600000}));
|
|
21
|
+
assert.equal(config.timeoutMs,600000);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('review config stays valid without a budget', () => {
|
|
25
|
+
const config=readConversationReviewConfiguration(configFile({model:'fixture',preflight}));
|
|
26
|
+
assert.equal(Object.hasOwn(config,'timeoutMs'),false);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('review config rejects budgets outside the shared call-timeout range', () => {
|
|
30
|
+
for(const timeoutMs of [0,-1,3600001,1.5,'600000',null]){
|
|
31
|
+
assert.throws(()=>readConversationReviewConfiguration(configFile({model:'fixture',preflight,timeoutMs})),
|
|
32
|
+
error=>error.code==='invalid_review_config',`expected rejection for ${String(timeoutMs)}`);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('review config accepts both range boundaries', () => {
|
|
37
|
+
for(const timeoutMs of [1,3600000]){
|
|
38
|
+
assert.equal(readConversationReviewConfiguration(configFile({model:'fixture',preflight,timeoutMs})).timeoutMs,timeoutMs);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('an explicit reviewer budget wins over the protected-mode budget', () => {
|
|
43
|
+
assert.deepEqual(resolveReviewTimeout({timeoutMs:600000},{timeoutMs:90000}),{timeoutMs:600000});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('protected mode still supplies the budget when review config omits one', () => {
|
|
47
|
+
assert.deepEqual(resolveReviewTimeout({model:'fixture'},{timeoutMs:90000}),{timeoutMs:90000});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('no budget anywhere leaves the worker default untouched', () => {
|
|
51
|
+
assert.deepEqual(resolveReviewTimeout(null,null),{});
|
|
52
|
+
assert.deepEqual(resolveReviewTimeout({model:'fixture'},null),{});
|
|
53
|
+
});
|
package/scripts/cm-ai-run.mjs
CHANGED
|
@@ -181,7 +181,7 @@ export async function openControlRun(definition,mode,execution=null,{rerunUnknow
|
|
|
181
181
|
if(execution!==null){
|
|
182
182
|
const {shape,json,validCallTimeout}=await import('../runtime/js/cm-ai/effect-contract.mjs');
|
|
183
183
|
shape(execution,['configuration','developer','reviewers','reviewInvocation','check','hostDecision','excludedContexts','timeoutMs',
|
|
184
|
-
...['bootstrap','developmentAttempt','hostDecisionProvider','qaDecisionProvider','qaLogHome','qaExecutor','applicableAgentFiles','documentationProvider','documentationResult','documentationSync'].filter(key=>Object.hasOwn(execution,key))]);
|
|
184
|
+
...['bootstrap','developmentAttempt','hostDecisionProvider','qaDecisionProvider','qaLogHome','qaExecutor','applicableAgentFiles','documentationProvider','documentationResult','documentationSync','verificationGate'].filter(key=>Object.hasOwn(execution,key))]);
|
|
185
185
|
json(execution.configuration);validCallTimeout(execution.timeoutMs);
|
|
186
186
|
if(Object.hasOwn(execution.configuration,'codeProject'))
|
|
187
187
|
if(execution.configuration.codeProject!==definition.codeProject)fail('execution_root_mismatch');
|
|
@@ -287,6 +287,7 @@ export async function openControlRun(definition,mode,execution=null,{rerunUnknow
|
|
|
287
287
|
...(execution.bootstrap?{bootstrap:execution.bootstrap}:{}),
|
|
288
288
|
reviewInvocation:execution.reviewInvocation,check:execution.check,
|
|
289
289
|
excludedContexts:execution.excludedContexts,timeoutMs:execution.timeoutMs,
|
|
290
|
+
...(Object.hasOwn(execution,'verificationGate')?{verificationGate:execution.verificationGate}:{}),
|
|
290
291
|
taskLearning:{feature,hostHandoff:true}})},
|
|
291
292
|
entry:{specsDir,codeProject,feature,identity,rerunUnknownQa,rerunBlockedQa,...(parallelSelection===null?{}:{parallelSelection}),...(execution===null?{}:{hostDecision:execution.hostDecision,
|
|
292
293
|
...Object.fromEntries(['developmentAttempt','hostDecisionProvider','qaDecisionProvider','qaLogHome','qaExecutor','applicableAgentFiles','documentationProvider','documentationResult'].filter(key=>Object.hasOwn(execution,key)).map(key=>[key,execution[key]]))})},
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import test from 'node:test';
|
|
3
|
+
|
|
4
|
+
import {readVerificationPrecheck} from '../runtime/js/cm-ai/host-conversation-execution.mjs';
|
|
5
|
+
|
|
6
|
+
const item=(requirement,satisfied,evidence)=>({requirement,satisfied,evidence});
|
|
7
|
+
const rejects=value=>assert.throws(()=>readVerificationPrecheck(value),
|
|
8
|
+
error=>error.code==='verification_precheck_invalid'||error.code==='invalid_input',
|
|
9
|
+
`expected rejection for ${JSON.stringify(value)}`);
|
|
10
|
+
|
|
11
|
+
test('every requirement satisfied lets the delivery through to the real review', () => {
|
|
12
|
+
const verdict=readVerificationPrecheck({items:[
|
|
13
|
+
item('记录实现前基线',true,'npm test tests 42 / pass 42 / fail 0'),
|
|
14
|
+
item('观察 RED 并记录失败用例名',true,'4 个用例因占位体抛错失败'),
|
|
15
|
+
]});
|
|
16
|
+
assert.equal(verdict.satisfied,true);
|
|
17
|
+
assert.deepEqual(verdict.unsatisfied,[]);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test('one unsatisfied requirement blocks and is named back', () => {
|
|
21
|
+
const verdict=readVerificationPrecheck({items:[
|
|
22
|
+
item('记录实现前基线',true,'tests 42 / pass 42 / fail 0'),
|
|
23
|
+
item('既有用例数不减少',false,'交付里只有实现后计数,没有实现前基线'),
|
|
24
|
+
item('新增用例只写在指定文件',true,'git status 只列出该文件'),
|
|
25
|
+
]});
|
|
26
|
+
assert.equal(verdict.satisfied,false);
|
|
27
|
+
assert.deepEqual(verdict.unsatisfied,['既有用例数不减少']);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('a requirement claimed satisfied without citing evidence is rejected', () => {
|
|
31
|
+
// The whole point of the gate is the evidence location, not the verdict.
|
|
32
|
+
rejects({items:[item('记录实现前基线',true,'')]});
|
|
33
|
+
rejects({items:[item('记录实现前基线',true,' ')]});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('an empty or oversized answer set is rejected', () => {
|
|
37
|
+
rejects({items:[]});
|
|
38
|
+
rejects({items:Array.from({length:65},(_,index)=>item(`要求 ${index}`,true,'证据'))});
|
|
39
|
+
assert.equal(readVerificationPrecheck({items:Array.from({length:64},
|
|
40
|
+
(_,index)=>item(`要求 ${index}`,true,'证据'))}).satisfied,true);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('extra, missing or mistyped fields are rejected', () => {
|
|
44
|
+
rejects({items:[{requirement:'x',satisfied:true}]});
|
|
45
|
+
rejects({items:[{...item('x',true,'y'),note:'多给一个字段'}]});
|
|
46
|
+
rejects({items:[item('x','true','y')]});
|
|
47
|
+
rejects({items:[item('x',1,'y')]});
|
|
48
|
+
rejects({items:'not an array'});
|
|
49
|
+
rejects({});
|
|
50
|
+
rejects({items:[item('x',true,'y')],extra:1});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('control characters and oversized text are rejected', () => {
|
|
54
|
+
rejects({items:[item(`要求${String.fromCharCode(0)}注入`,true,'证据')]});
|
|
55
|
+
rejects({items:[item('要求',true,'a'.repeat(2001))]});
|
|
56
|
+
assert.equal(readVerificationPrecheck({items:[item('要求',true,'a'.repeat(2000))]}).satisfied,true);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test('the verdict is frozen so a caller cannot flip it after validation', () => {
|
|
60
|
+
const verdict=readVerificationPrecheck({items:[item('要求',false,'没对上')]});
|
|
61
|
+
assert.throws(()=>{verdict.satisfied=true;},TypeError);
|
|
62
|
+
assert.equal(verdict.satisfied,false);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// The gate is only useful if a blocked delivery can be redone. A gate that
|
|
66
|
+
// leaves the task unrecoverable would cost more than the rework it prevents.
|
|
67
|
+
test('a blocked delivery is reported as resumable, not as an unknown state', async () => {
|
|
68
|
+
const {default:fs}=await import('node:fs');
|
|
69
|
+
const {developmentRetryable}=await import('../runtime/js/cm-ai/cm-ai-conversation-entry.mjs');
|
|
70
|
+
assert.equal(developmentRetryable({state:'blocked',code:'verification_precheck_failed'}),true);
|
|
71
|
+
assert.equal(developmentRetryable({state:'unknown',code:'verification_precheck_failed'}),false);
|
|
72
|
+
// resume is the action that predicate maps to.
|
|
73
|
+
const source=fs.readFileSync(new URL('../runtime/js/cm-ai/cm-ai-conversation-entry.mjs',import.meta.url),'utf8');
|
|
74
|
+
assert.match(source,/retryDeveloper\(status\)\|\|retryReview\(status\)\?'resume'/);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('the failure code survives redaction instead of collapsing to execution_error', async () => {
|
|
78
|
+
const {failureCode}=await import('../runtime/js/cm-ai/effect-contract.mjs');
|
|
79
|
+
assert.equal(failureCode(Object.assign(new Error('x'),{code:'verification_precheck_failed'})),
|
|
80
|
+
'verification_precheck_failed');
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// The serial entry and the parallel batch driver must agree on what is
|
|
84
|
+
// retryable. They used to keep separate code lists; a gate code added to one
|
|
85
|
+
// and not the other would stall every parallel member that hits it.
|
|
86
|
+
test('the batch driver decides retryability from the shared predicate', async () => {
|
|
87
|
+
const {default:fs}=await import('node:fs');
|
|
88
|
+
const {developmentRetryable}=await import('../runtime/js/cm-ai/cm-ai-conversation-entry.mjs');
|
|
89
|
+
const source=fs.readFileSync(new URL('./cm-ai-batch-run.mjs',import.meta.url),'utf8');
|
|
90
|
+
assert.match(source,/import \{developmentRetryable\}/);
|
|
91
|
+
assert.match(source,/\|\|developmentRetryable\(status\)\)await call\('start'\)/);
|
|
92
|
+
assert.equal(/status\.code==='developer_result_invalid'/.test(source),false,
|
|
93
|
+
'batch driver still carries its own copy of the retryable code list');
|
|
94
|
+
for(const code of ['developer_result_invalid','verification_precheck_failed'])
|
|
95
|
+
assert.equal(developmentRetryable({state:'blocked',code}),true,code);
|
|
96
|
+
assert.equal(developmentRetryable({state:'blocked',code:'package_mismatch'}),false);
|
|
97
|
+
assert.equal(developmentRetryable({state:'unknown',code:'verification_precheck_failed'}),false);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
// The gate is fed by task-runner, and the previous version sent only the
|
|
101
|
+
// verification section. Unit tests on the validator alone could not see that,
|
|
102
|
+
// which is exactly how the description requirements slipped through to the
|
|
103
|
+
// independent review. Assert the payload the runner actually builds.
|
|
104
|
+
test('the gate receives both the task description and the verification section', async () => {
|
|
105
|
+
const {default:fs}=await import('node:fs');
|
|
106
|
+
const source=fs.readFileSync(new URL('../runtime/js/cm-ai/task-runner.mjs',import.meta.url),'utf8');
|
|
107
|
+
const body=/async function verificationSatisfied\(checks\) \{([\s\S]*?)\n \}/.exec(source);
|
|
108
|
+
assert.notEqual(body,null,'verificationSatisfied not found');
|
|
109
|
+
assert.match(body[1],/specification\?\.task\?\.description/);
|
|
110
|
+
assert.match(body[1],/specification\?\.task\?\.verification/);
|
|
111
|
+
// Both must reach the payload, each only when actually written.
|
|
112
|
+
assert.match(body[1],/written\(description\)\?\{description\}/);
|
|
113
|
+
assert.match(body[1],/written\(verification\)\?\{verification\}/);
|
|
114
|
+
// The gate steps aside only when neither exists.
|
|
115
|
+
assert.match(body[1],/if\(!written\(verification\)&&!written\(description\)\)return true;/);
|
|
116
|
+
});
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import {execFileSync} from 'node:child_process';
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import os from 'node:os';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
|
|
8
|
+
import {fixHostContexts, validateCauseReviewer} from '../runtime/js/cm-fix/cause-invocation.mjs';
|
|
9
|
+
import {validateReviewDispatchGrant} from '../runtime/js/cm-ai/durable-runner-state.mjs';
|
|
10
|
+
import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
11
|
+
|
|
12
|
+
const DURABLE = '01a0bfd9-e7c3-7fa2-9808-206649615754';
|
|
13
|
+
const LIVE = '01a0c2b5-c2e2-7af1-8831-d6702c9a0d16';
|
|
14
|
+
const reviewer = {reviewerId: 'fix-cause-reviewer', adapterId: 'codex-cause-review-adapter', provider: 'codex',
|
|
15
|
+
requestedModel: 'gpt-6-astra', contextId: 'fix-cause-review-context', excludedThreadIds: []};
|
|
16
|
+
|
|
17
|
+
test('the durable host always comes first and a second one is optional', () => {
|
|
18
|
+
assert.deepEqual(fixHostContexts({hostContextId: DURABLE}), [DURABLE]);
|
|
19
|
+
assert.deepEqual(fixHostContexts({hostContextId: DURABLE, hostContextIds: [DURABLE, LIVE]}), [DURABLE, LIVE]);
|
|
20
|
+
// The resumed session can never displace the session the run is bound to.
|
|
21
|
+
// A malformed id is refused by the shared id() validator, a malformed set by
|
|
22
|
+
// this function's own bound; both are refusals, so accept either code.
|
|
23
|
+
const refused = error => ['invalid_host_context', 'invalid_input'].includes(error.code);
|
|
24
|
+
for (const hosts of [[LIVE, DURABLE], [LIVE], [DURABLE, DURABLE], [DURABLE, LIVE, 'third'], [],
|
|
25
|
+
[DURABLE, ''], [DURABLE, null], 'not-an-array'])
|
|
26
|
+
assert.throws(() => fixHostContexts({hostContextId: DURABLE, hostContextIds: hosts}),
|
|
27
|
+
refused, JSON.stringify(hosts));
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('a resumed session is a host, so it cannot also be the reviewer', () => {
|
|
31
|
+
assert.deepEqual(validateCauseReviewer(reviewer, [DURABLE, LIVE]), reviewer);
|
|
32
|
+
for (const host of [DURABLE, LIVE])
|
|
33
|
+
assert.throws(() => validateCauseReviewer({...reviewer, contextId: host}, [DURABLE, LIVE]),
|
|
34
|
+
{code: 'invalid_cause_reviewer'}, host);
|
|
35
|
+
// Excluding a host does not launder it into an acceptable reviewer either.
|
|
36
|
+
assert.throws(() => validateCauseReviewer({...reviewer, contextId: LIVE, excludedThreadIds: [LIVE]},
|
|
37
|
+
[DURABLE, LIVE]), {code: 'invalid_cause_reviewer'});
|
|
38
|
+
assert.throws(() => validateCauseReviewer(reviewer, [DURABLE, LIVE, 'third']), {code: 'invalid_cause_reviewer'});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// This is the claim the whole change rests on: the live session signs new grants
|
|
42
|
+
// while the durable session's old grants still replay. Neither may be widened
|
|
43
|
+
// into accepting a host the run never had.
|
|
44
|
+
test('a grant signed by either host is accepted and a third host is not', () => {
|
|
45
|
+
const request = {identity: {repositoryId: 'wue', runId: 'r', taskId: 'T-001', attempt: 1},
|
|
46
|
+
invocationId: 'invocation-1', requestDigest: digest({request: 1}), contextId: reviewer.contextId};
|
|
47
|
+
const issuedAt = 1_700_000_000_000;
|
|
48
|
+
const grantFor = hostContextId => {
|
|
49
|
+
const body = {version: 1, kind: 'cm-review-dispatch-grant', grantId: 'grant-1',
|
|
50
|
+
adapterId: reviewer.adapterId, invocationId: request.invocationId, requestDigest: request.requestDigest,
|
|
51
|
+
identity: request.identity, reviewerId: reviewer.reviewerId, logicalContextId: request.contextId,
|
|
52
|
+
packageDigest: digest({pkg: 1}), hostContextId, decisionId: 'decision-1', decision: 'approved',
|
|
53
|
+
issuedAt, expiresAt: issuedAt + 60000};
|
|
54
|
+
return {...body, grantDigest: digest(body)};
|
|
55
|
+
};
|
|
56
|
+
const expected = {request, reviewerId: reviewer.reviewerId, adapterId: reviewer.adapterId,
|
|
57
|
+
packageDigest: digest({pkg: 1}), hostContextIds: [DURABLE, LIVE],
|
|
58
|
+
authorizationAt: issuedAt, registeredAt: issuedAt + 1};
|
|
59
|
+
for (const host of [DURABLE, LIVE])
|
|
60
|
+
assert.equal(validateReviewDispatchGrant(grantFor(host), expected).hostContextId, host);
|
|
61
|
+
assert.throws(() => validateReviewDispatchGrant(grantFor('01a0c2b5-0000-0000-0000-000000000000'), expected),
|
|
62
|
+
{code: 'runner_grant'});
|
|
63
|
+
// A single-host run keeps refusing the session that never owned it.
|
|
64
|
+
assert.throws(() => validateReviewDispatchGrant(grantFor(LIVE), {...expected, hostContextIds: [DURABLE]}),
|
|
65
|
+
{code: 'runner_grant'});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// The flag exists so a new session can declare the old one. It must not become a
|
|
69
|
+
// way to plant an arbitrary host onto a run being created.
|
|
70
|
+
test('--original-host-context is refused when creating a run', () => {
|
|
71
|
+
const root = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'cm-fix-cross-')));
|
|
72
|
+
try {
|
|
73
|
+
const cwd = path.join(root, 'code');
|
|
74
|
+
fs.mkdirSync(cwd);
|
|
75
|
+
fs.writeFileSync(path.join(cwd, 'value.mjs'), 'export const value=1;');
|
|
76
|
+
const config = path.join(root, 'controls.json');
|
|
77
|
+
fs.writeFileSync(config, JSON.stringify({specsRoot: null, identity: {repositoryId: 'fixture',
|
|
78
|
+
runId: 'cross-session', taskId: 'T-FIX-cross', attempt: 1}, defect: 'Synthetic defect for the flag check',
|
|
79
|
+
reproduction: {cwd, command: [process.execPath, '-e', "process.stderr.write('BUG');process.exit(3)"],
|
|
80
|
+
expectedFailure: {exitCode: 3, outputIncludes: 'BUG'}, timeoutMs: 1000}}));
|
|
81
|
+
const host = fileURLToPathname(new URL('./cm-fix-host.mjs', import.meta.url));
|
|
82
|
+
const run = extra => {
|
|
83
|
+
try {
|
|
84
|
+
return execFileSync(process.execPath, [host, 'serve', '--config', config, ...extra],
|
|
85
|
+
{input: '', encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe']});
|
|
86
|
+
} catch (error) { return `${error.stdout ?? ''}${error.stderr ?? ''}`; }
|
|
87
|
+
};
|
|
88
|
+
assert.match(run(['--mode', 'create', '--host-context', LIVE, '--allow-reproduction',
|
|
89
|
+
'--original-host-context', DURABLE]), /fix_original_host_context_unavailable/);
|
|
90
|
+
// Creating without it gets past that refusal, which is what proves the refusal is
|
|
91
|
+
// the flag and not the rest of the launch. How far past depends on the host: the
|
|
92
|
+
// durable store needs Node >= 24.14, and CI validates on 22, where the platform
|
|
93
|
+
// gate stops the launch later in openFixExecution. Either outcome clears the flag
|
|
94
|
+
// check above it; only fix_original_host_context_unavailable would not.
|
|
95
|
+
assert.match(run(['--mode', 'create', '--host-context', LIVE, '--allow-reproduction']),
|
|
96
|
+
/host_ready|unsupported_platform/);
|
|
97
|
+
} finally { fs.rmSync(root, {recursive: true, force: true}); }
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
function fileURLToPathname(url) { return decodeURIComponent(url.pathname); }
|
|
@@ -92,3 +92,36 @@ test('legacy observation without attempts can publish, finish and resume without
|
|
|
92
92
|
assert.equal(fs.readFileSync(path.join(cwd,'visits'),'utf8'),'1');
|
|
93
93
|
}finally{owner.close();}
|
|
94
94
|
}));
|
|
95
|
+
|
|
96
|
+
const reviewer={reviewerId:'fix-cause-reviewer',adapterId:'codex-cause-review-adapter',provider:'codex',
|
|
97
|
+
requestedModel:'gpt-6-astra',contextId:'fix-cause-review-context',excludedThreadIds:[]};
|
|
98
|
+
const statePath=options=>path.join(options.specsRoot,'.reviews','.execution',identity.runId,'state.json');
|
|
99
|
+
|
|
100
|
+
test('a later session resumes the original run without rewriting its records',()=>fixture(async(options,cwd)=>{
|
|
101
|
+
const bridge=createHostToolBridge();
|
|
102
|
+
bridge.attach(row=>{if(row.type==='host_request')bridge.accept({type:'host_result',sessionId:row.sessionId,
|
|
103
|
+
callId:row.callId,requestDigest:row.requestDigest,result:cause});});
|
|
104
|
+
let owner=openFixExecution(options,{bridge});
|
|
105
|
+
try{assert.equal((await owner.advance({authorized:true})).stage,'red_test_required');}finally{owner.close();}
|
|
106
|
+
const before=fs.readFileSync(statePath(options));
|
|
107
|
+
// The chat session that created the run is gone; the durable record keeps it.
|
|
108
|
+
owner=openFixExecution({...options,create:false,hostContextId:'actual-resumed-host'},{bridge});
|
|
109
|
+
try{
|
|
110
|
+
assert.equal((await owner.advance()).stage,'red_test_required');
|
|
111
|
+
assert.equal(fs.readFileSync(path.join(cwd,'visits'),'utf8'),'1');
|
|
112
|
+
}finally{owner.close();bridge.close();}
|
|
113
|
+
assert.deepEqual(fs.readFileSync(statePath(options)),before);
|
|
114
|
+
assert.equal(JSON.parse(before).records[0].payload.configuration.hostContextId,'actual-fixture-host');
|
|
115
|
+
}));
|
|
116
|
+
|
|
117
|
+
test('resuming never rewrites the durable host or accepts a reviewer-shaped session',()=>fixture(async(options)=>{
|
|
118
|
+
const configuration={...options.configuration,causeReview:reviewer};
|
|
119
|
+
openFixExecution({...options,configuration}).close();
|
|
120
|
+
// Moving the durable host is still a different run configuration.
|
|
121
|
+
assert.throws(()=>openFixExecution({...options,configuration,create:false,
|
|
122
|
+
configuration:{...configuration,hostContextId:'other-host'}}),{code:'fingerprint_mismatch'});
|
|
123
|
+
// A resumed session is still a host, so it cannot be the independent reviewer.
|
|
124
|
+
assert.throws(()=>openFixExecution({...options,configuration,create:false,
|
|
125
|
+
hostContextId:reviewer.contextId}),{code:'invalid_cause_reviewer'});
|
|
126
|
+
openFixExecution({...options,configuration,create:false,hostContextId:'actual-resumed-host'}).close();
|
|
127
|
+
}));
|
package/scripts/cm-fix-host.mjs
CHANGED
|
@@ -11,7 +11,7 @@ import {id,json,need,shape,digest} from '../runtime/js/cm-ai/effect-contract.mjs
|
|
|
11
11
|
import {readConversationReviewConfiguration} from './cm-ai-host.mjs';
|
|
12
12
|
import {createFixReviewHost} from '../runtime/js/cm-fix/host-review.mjs';
|
|
13
13
|
|
|
14
|
-
const usage='cm-fix-host.mjs serve --config PATH --mode create|resume --host-context ID --allow-reproduction [--runtime codex|claude] [--review-config PATH] [--allow-cause-review] [--allow-final-review] [--allow-test-author] [--allow-red-test] [--allow-baseline] [--allow-repair] [--allow-regression] [--allow-learning-writeback]\nCodex or Claude current-host operations: advance, cause_review_package, cause_review, author_tests, red_test, baseline, repair, regression, retrospective, learning_writeback, handoff, final_review_package, final_review, publish_review, check_n5, post_review_regression, status, cancel. Runtime defaults to codex; claude uses its own matching diagnostic receipt and cannot reuse Codex preflight or disabledSkills settings. Runtime selection is bound to recovery; switching providers requires a separate run. This selects existing adapters, not permission to call them. Each write/check needs its respective launch flag and configuration. Test authoring, repair, cause and final review dispatch require matching existing stdin diagnostics; diagnostic alone is not authorization. Passing regression stops at handoff_required. The read-only retrospective operation yields handoff_ready or learning_writeback_required. learning_writeback requires its own flag, preserves project instructions and includes AGENTS.md in the review scope; it does not authorize provider calls. handoff publishes the fixed specs-local handoff with Learning evidence and moves to final_review_required; no provider is called and no task is completed. final_review_package is read-only and returns the final content-bound review package. final_review requires its own flag and matching diagnostics; observations do not complete the task. publish_review projects the registered result into the existing review file; it does not dispatch or complete tasks. check_n5 runs the original Learning-aware gate; post_review_regression requires --allow-regression and reaches closeout_required, not completion.';
|
|
14
|
+
const usage='cm-fix-host.mjs serve --config PATH --mode create|resume --host-context ID --allow-reproduction [--original-host-context ID] [--runtime codex|claude] [--review-config PATH] [--allow-cause-review] [--allow-final-review] [--allow-test-author] [--allow-red-test] [--allow-baseline] [--allow-repair] [--allow-regression] [--allow-learning-writeback]\nCodex or Claude current-host operations: advance, cause_review_package, cause_review, author_tests, red_test, baseline, repair, regression, retrospective, learning_writeback, handoff, final_review_package, final_review, publish_review, check_n5, post_review_regression, status, cancel. Runtime defaults to codex; claude uses its own matching diagnostic receipt and cannot reuse Codex preflight or disabledSkills settings. Runtime selection is bound to recovery; switching providers requires a separate run. This selects existing adapters, not permission to call them. Each write/check needs its respective launch flag and configuration. Test authoring, repair, cause and final review dispatch require matching existing stdin diagnostics; diagnostic alone is not authorization. Passing regression stops at handoff_required. The read-only retrospective operation yields handoff_ready or learning_writeback_required. learning_writeback requires its own flag, preserves project instructions and includes AGENTS.md in the review scope; it does not authorize provider calls. handoff publishes the fixed specs-local handoff with Learning evidence and moves to final_review_required; no provider is called and no task is completed. final_review_package is read-only and returns the final content-bound review package. final_review requires its own flag and matching diagnostics; observations do not complete the task. publish_review projects the registered result into the existing review file; it does not dispatch or complete tasks. check_n5 runs the original Learning-aware gate; post_review_regression requires --allow-regression and reaches closeout_required, not completion.';
|
|
15
15
|
|
|
16
16
|
export async function main(argv=process.argv.slice(2),{input=process.stdin,output=process.stdout,error=process.stderr,reviewWorkerFactory=null}={}){
|
|
17
17
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('Omit specsRoot or use null for a bare project: the same owner stores archives in docs/fixes and reviews in docs/fixes/.reviews, uses the original no-specs log mode, and skips METRICS. No specs skeleton is created. Visual-only reproduction/redTest may use kind:visual with cwd, timeoutMs, before:{path,sha256,kind:screenshot|video,description}, reason explaining why automated red cannot be written, environment, steps and expected; redTest also has testFiles:[]. No testAuthor or fake red/green command. Repair/regression/review/finish permissions remain mandatory. qa_browser returns actual after carrier metadata; missing evidence blocks.\n');
|
|
@@ -20,8 +20,8 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
20
20
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('recover_final_review requires --allow-final-review-recovery and exact latest invocationId/packageDigest, previousInvocationStopped:true, and a nonempty reason. The legacy first continuation remains once-only. A further continuation additionally requires a fresh startup --final-review-recovery-invocation ID matching the latest unknown invocation, authorizing exactly one new call. Confirm the previous process stopped; this is a trusted host acknowledgment, not an automatic liveness check. Preparation dispatches nothing. Later final_review requires recovery permission and --allow-final-review; additional cycles require the same invocation binding after restart. Old records, task attempt, reviewed package and the original Review/N5/finish remain unchanged. No automatic retry, cancelled/complete-verdict recovery, missing-thread recovery, business-revision recovery or source-drift bypass. status adds a read-only progress projection, not authorization or current-source verification.\n');
|
|
21
21
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('N6 child configuration may include qaSource {feature, identity, packageDigest, testRunId, handoffDigest}; derive the separate fixed child identity with qaFixIdentity. It requires --allow-qa-fix in addition to existing action flags. Close the parent host first: the original specs-wide owner lock is shared. Creation/resume rechecks the current failed round, project, report and policy; the source is bound to the original fix configuration. This does not resume the parent or automatically rerun QA, and does not authorize provider calls, installation or Git.\n');
|
|
22
22
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('Second-round retrospective uses the cumulative original baseline, including previously authored tests and Learning scope. It persists the current round reflection and reaches revision_handoff_ready or revision_learning_writeback_required; neither state completes the task or publishes a new handoff. From revision_handoff_ready, handoff publishes a separate a2 handoff containing cumulative changes, current reflection, original red evidence and prior review/Learning history; final_review_package then reads that bound package. Pending Learning blocks publication. final_review requires --allow-final-review, uses fresh-thread exclusions and carries prior findings; publish_review writes the original r2 evidence and review log, and check_n5 runs the original Learning-aware gate. Approval reaches revision_post_review_regression_required, not completion.\n');
|
|
23
|
-
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('prepare_revision requires --allow-repair and either a published first-round changes_requested review or an approved first-round review followed by a package-bound walkthrough result of failed. The latter preserves the approved verdict and carries separate walkthrough failure evidence; passed, blocked, unknown, or drifted evidence cannot authorize this repair. An approved first-round review followed by package-bound post-review regression defect_remaining or regressed can also prepare the second repair when all baseline commands produced complete results. The regression commands must match the first reviewed handoff; passed, inconclusive, unavailable or partial evidence is refused. Regression and walkthrough failure feedback are mutually exclusive and neither replaces the next independent review. It rereads project Learning and persists the second-round preparation in the original store, preserving first-round evidence. repair then uses the original business scope and findings with separate second-round records. regression requires --allow-regression and reruns the original test commands against the second repair, preserving the original red evidence. Success reaches revision_handoff_required, not completion; handoff and final_review use the second-round package; review evidence publication and N5 are connected; post_review_regression requires --allow-regression and reaches revision_closeout_required after the original checks; walkthrough requires --allow-walkthrough and binds the second-round package and identity; finish reuses the original closeout with --allow-finish
|
|
24
|
-
if(argv.length===1&&['--help','-h'].includes(argv[0])){output.write(usage+'\nAdditional operation: publish_dossier writes a private immutable fixes/YYYYMMDD-slug.md closeout snapshot; missing evidence is explicit and the task remains incomplete. In observation it writes the recorded reproduction summary and expected evidence to the same fixes archive, preserving its date across restart and refusing user-content conflicts; it does not repair or complete the task. In observation, finish with --allow-finish records run_done as observing and releases the owner lock without task_done or metrics; end the existing transport with host_close or EOF. resume accepts evidenceFiles (1-3 explicit specs-local files) and binds them to the prior observing exit and dossier without resetting task attempt. It reaches observation_resume_prepared; evidence drift blocks continuation. advance from prepared rereads Learning and reruns the original reproduction command, then passes selected evidence references to the original diagnosis capability. Recovery uses separate records without resetting attempt; unknown outcomes are not redispatched. Unreproduced, blocked or still-insufficient evidence stays incomplete. Before resumed execution, the original resume log binds the observation exit and selected evidence digests, restoring the same run to running without a new task start. Recovered handoffs bind exact selected evidence bytes and pre-observation history under the original size and review gates; legacy recovered handoffs lacking that material remain readable but cannot claim current review coverage. Recovered closeout preserves the exact observation archive prefix and original filename, appends the recovery results, and uses the existing finish gate; user-modified continuations are refused. If recovery still cannot reproduce the defect or diagnosis still needs evidence, publish_dossier appends the latest observation and authorized finish records a second bound observing exit without task completion or metrics. After a recorded observing exit, resume can bind another explicit evidence selection to the latest exit and archive. Observation cycles retain prior records and archive bytes, do not reset task attempts or review rounds, and require separately authorized advance; unknown outcomes are not retried. Multi-cycle handoffs include the exact prior archive under the original size limit. walkthrough requires configured module-mapped flows and --allow-walkthrough; it runs declared commands or uses existing qa_browser/qa_logic host capabilities. Static support cannot pass a walkthrough. Browser execution remains limited to the authorized current-host environment; no install or provider authority is implied.\nRepair completion via finish requires --allow-finish,
|
|
23
|
+
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('prepare_revision requires --allow-repair and either a published first-round changes_requested review or an approved first-round review followed by a package-bound walkthrough result of failed. The latter preserves the approved verdict and carries separate walkthrough failure evidence; passed, blocked, unknown, or drifted evidence cannot authorize this repair. An approved first-round review followed by package-bound post-review regression defect_remaining or regressed can also prepare the second repair when all baseline commands produced complete results. The regression commands must match the first reviewed handoff; passed, inconclusive, unavailable or partial evidence is refused. Regression and walkthrough failure feedback are mutually exclusive and neither replaces the next independent review. It rereads project Learning and persists the second-round preparation in the original store, preserving first-round evidence. repair then uses the original business scope and findings with separate second-round records. regression requires --allow-regression and reruns the original test commands against the second repair, preserving the original red evidence. Success reaches revision_handoff_required, not completion; handoff and final_review use the second-round package; review evidence publication and N5 are connected; post_review_regression requires --allow-regression and reaches revision_closeout_required after the original checks; walkthrough requires --allow-walkthrough and binds the second-round package and identity; finish reuses the original closeout with --allow-finish, preserving first-round history and recording completion for attempt 2. Second-round learning_writeback requires --allow-learning-writeback, includes the resulting AGENTS.md in the cumulative review package and preserves prior Learning history; pending or unknown writeback cannot advance to handoff. A lost repair or regression result stays unknown and is not redispatched.\n');
|
|
24
|
+
if(argv.length===1&&['--help','-h'].includes(argv[0])){output.write(usage+'\nAdditional operation: publish_dossier writes a private immutable fixes/YYYYMMDD-slug.md closeout snapshot; missing evidence is explicit and the task remains incomplete. In observation it writes the recorded reproduction summary and expected evidence to the same fixes archive, preserving its date across restart and refusing user-content conflicts; it does not repair or complete the task. In observation, finish with --allow-finish records run_done as observing and releases the owner lock without task_done or metrics; end the existing transport with host_close or EOF. resume accepts evidenceFiles (1-3 explicit specs-local files) and binds them to the prior observing exit and dossier without resetting task attempt. It reaches observation_resume_prepared; evidence drift blocks continuation. advance from prepared rereads Learning and reruns the original reproduction command, then passes selected evidence references to the original diagnosis capability. Recovery uses separate records without resetting attempt; unknown outcomes are not redispatched. Unreproduced, blocked or still-insufficient evidence stays incomplete. Before resumed execution, the original resume log binds the observation exit and selected evidence digests, restoring the same run to running without a new task start. Recovered handoffs bind exact selected evidence bytes and pre-observation history under the original size and review gates; legacy recovered handoffs lacking that material remain readable but cannot claim current review coverage. Recovered closeout preserves the exact observation archive prefix and original filename, appends the recovery results, and uses the existing finish gate; user-modified continuations are refused. If recovery still cannot reproduce the defect or diagnosis still needs evidence, publish_dossier appends the latest observation and authorized finish records a second bound observing exit without task completion or metrics. After a recorded observing exit, resume can bind another explicit evidence selection to the latest exit and archive. Observation cycles retain prior records and archive bytes, do not reset task attempts or review rounds, and require separately authorized advance; unknown outcomes are not retried. Multi-cycle handoffs include the exact prior archive under the original size limit. walkthrough requires configured module-mapped flows and --allow-walkthrough; it runs declared commands or uses existing qa_browser/qa_logic host capabilities. Static support cannot pass a walkthrough. Browser execution remains limited to the authorized current-host environment; no install or provider authority is implied.\nRepair completion via finish requires --allow-finish, a reviewed diagnosis, a modern handoff and a passed walkthrough. It accepts any configured policies.delivery and only requires that the mode stay unchanged while completion records are written; Git delivery is a separate logged event, not a precondition. It rechecks the original N5 gate, finalizes the generated dossier, records reviewed lessons, task_done, metrics and run_done. It resumes partial closeout without redispatch and refuses user-modified dossier conflicts. Branch/MR delivery still requires separate authorization; this command does not execute Git.\n');return 0;}
|
|
25
25
|
let owner,bridge;
|
|
26
26
|
try{
|
|
27
27
|
need(argv.length>=8&&argv[0]==='serve'&&argv[1]==='--config'&&argv[3]==='--mode'
|
|
@@ -29,10 +29,15 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
29
29
|
need(['create','resume'].includes(argv[4]),'invalid_arguments');id(argv[6]);
|
|
30
30
|
const extra=new Map();
|
|
31
31
|
for(let index=8;index<argv.length;index++){
|
|
32
|
-
const flag=argv[index];need(!extra.has(flag)&&['--runtime','--review-config','--final-review-recovery-invocation','--allow-qa-fix','--allow-cause-review','--allow-final-review','--allow-final-review-recovery','--allow-red-test','--allow-baseline','--allow-test-author','--allow-repair','--allow-regression','--allow-learning-writeback','--allow-walkthrough','--allow-finish'].includes(flag),'invalid_arguments');
|
|
32
|
+
const flag=argv[index];need(!extra.has(flag)&&['--runtime','--review-config','--original-host-context','--final-review-recovery-invocation','--allow-qa-fix','--allow-cause-review','--allow-final-review','--allow-final-review-recovery','--allow-red-test','--allow-baseline','--allow-test-author','--allow-repair','--allow-regression','--allow-learning-writeback','--allow-walkthrough','--allow-finish'].includes(flag),'invalid_arguments');
|
|
33
33
|
if(flag.startsWith('--allow-'))extra.set(flag,true);
|
|
34
34
|
else{need(typeof argv[index+1]==='string'&&!argv[index+1].startsWith('--'),'invalid_arguments');extra.set(flag,argv[++index]);}
|
|
35
35
|
}
|
|
36
|
+
// A run created in an earlier session keeps that session in its durable record.
|
|
37
|
+
// Resume declares it here so the stored fingerprint and history still match,
|
|
38
|
+
// while --host-context stays the real current session for every live decision.
|
|
39
|
+
const originalHostContext=extra.get('--original-host-context')??null;
|
|
40
|
+
if(originalHostContext!==null){id(originalHostContext);need(argv[4]==='resume','fix_original_host_context_unavailable');}
|
|
36
41
|
const recoveryInvocationId=extra.get('--final-review-recovery-invocation')??null;
|
|
37
42
|
if(recoveryInvocationId!==null){id(recoveryInvocationId);need(extra.has('--allow-final-review-recovery'),'fix_review_recovery_authorization_required');}
|
|
38
43
|
const runtime=extra.get('--runtime')??'codex';need(['codex','claude'].includes(runtime),'invalid_runtime');
|
|
@@ -61,7 +66,8 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
61
66
|
permissions:[...extra.keys()],workerFactory:reviewWorkerFactory});
|
|
62
67
|
bridge=createHostToolBridge();
|
|
63
68
|
owner=openFixExecution({specsRoot:config.specsRoot??null,identity:config.identity,create:argv[4]==='create',
|
|
64
|
-
|
|
69
|
+
hostContextId:argv[6],
|
|
70
|
+
configuration:{hostContextId:originalHostContext??argv[6],defect:config.defect,reproduction:config.reproduction,
|
|
65
71
|
...(Object.hasOwn(config,'protectSpecs')?{protectSpecs:config.protectSpecs}:{}),
|
|
66
72
|
...(Object.hasOwn(config,'qaSource')?{qaSource:config.qaSource}:{}),
|
|
67
73
|
...(runtime==='claude'?{runtime}:{}),
|