@aibyzero/cm-workflow 0.16.3 → 0.16.5
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 +8 -0
- package/CHANGELOG.md +59 -0
- package/README.md +55 -3
- package/VERSION +1 -1
- package/docs/installation.md +21 -1
- package/docs/js-workflow-control.md +245 -33
- package/docs/next-steps.md +14 -24
- package/docs/runtime-failover.md +1 -1
- package/package.json +1 -1
- package/runtime/js/cm-ai/accepted-fix.mjs +23 -5
- package/runtime/js/cm-ai/bootstrap-feature.mjs +15 -0
- package/runtime/js/cm-ai/claude-review-stream.mjs +30 -0
- package/runtime/js/cm-ai/cm-ai-admission.mjs +116 -41
- package/runtime/js/cm-ai/cm-ai-context-refresh.mjs +3 -2
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +137 -22
- package/runtime/js/cm-ai/cm-ai-learning-handoff-writer.mjs +11 -9
- package/runtime/js/cm-ai/cm-ai-learning-writer.mjs +22 -5
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +180 -53
- package/runtime/js/cm-ai/cm-ai-run-finalizer.mjs +2 -1
- package/runtime/js/cm-ai/codex-review-adapter.mjs +24 -4
- package/runtime/js/cm-ai/developer-adapter.mjs +6 -2
- package/runtime/js/cm-ai/diagnostic-reason.mjs +10 -0
- package/runtime/js/cm-ai/drive-bootstrap.mjs +305 -0
- package/runtime/js/cm-ai/drive-core.mjs +39 -7
- package/runtime/js/cm-ai/durable-runner-state.mjs +307 -53
- package/runtime/js/cm-ai/effect-abandon-log.mjs +19 -0
- package/runtime/js/cm-ai/effect-contract.mjs +44 -2
- package/runtime/js/cm-ai/execution-store-limits.mjs +18 -0
- package/runtime/js/cm-ai/execution-store.mjs +6 -4
- package/runtime/js/cm-ai/fix-code-association.mjs +171 -18
- package/runtime/js/cm-ai/host-bootstrap.mjs +68 -21
- package/runtime/js/cm-ai/host-conversation-execution.mjs +16 -4
- package/runtime/js/cm-ai/host-handoff.mjs +13 -6
- package/runtime/js/cm-ai/host-qa-executor.mjs +21 -7
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +4 -4
- package/runtime/js/cm-ai/host-qa-policy.mjs +16 -7
- package/runtime/js/cm-ai/host-session.mjs +20 -5
- package/runtime/js/cm-ai/host-tool-bridge.mjs +1 -1
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +13 -4
- package/runtime/js/cm-ai/host.mjs +1 -1
- package/runtime/js/cm-ai/launch-mismatch.mjs +42 -0
- package/runtime/js/cm-ai/log-rows.mjs +21 -0
- package/runtime/js/cm-ai/project-qa-gate.mjs +84 -0
- package/runtime/js/cm-ai/provider-review-observation.mjs +53 -9
- package/runtime/js/cm-ai/qa-config-revision.mjs +44 -10
- package/runtime/js/cm-ai/review-abandon-log.mjs +21 -0
- package/runtime/js/cm-ai/review-package.mjs +427 -31
- package/runtime/js/cm-ai/review-runner.mjs +47 -1
- package/runtime/js/cm-ai/reviewed-deliveries.mjs +97 -0
- package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +104 -10
- package/runtime/js/cm-ai/reviewed-evidence-supersession-record.mjs +42 -3
- package/runtime/js/cm-ai/specification-material.mjs +154 -12
- package/runtime/js/cm-ai/task-commit.mjs +2 -2
- package/runtime/js/cm-ai/task-runner.mjs +502 -65
- package/runtime/js/cm-ai/worker-claude-developer.mjs +16 -7
- package/runtime/js/cm-fix/execution.mjs +109 -25
- package/runtime/js/cm-fix/host-review.mjs +7 -3
- package/runtime/js/cm-fix/host.mjs +3 -1
- package/runtime/js/cm-fix/progress.mjs +1 -0
- package/runtime/js/cm-fix/protected-edits.mjs +15 -4
- package/runtime/js/cm-fix/qa-source.mjs +6 -4
- package/runtime/js/cm-prd/analysis.mjs +2 -1
- package/runtime/js/cm-prd/change.mjs +28 -10
- package/runtime/js/cm-prd/draft.mjs +5 -2
- package/runtime/js/cm-prd/review-preparation.mjs +10 -3
- package/runtime/js/cm-prd/review-publication.mjs +4 -2
- package/runtime/js/cm-prd/self-check.mjs +6 -3
- package/runtime/js/cm-prd/summary.mjs +6 -2
- package/runtime/js/cm-prd/validation-reason.mjs +20 -0
- package/runtime/js/spec-task-line.mjs +117 -0
- package/runtime/js/specs-status.mjs +14 -3
- package/scripts/cm-ai-abandon-effect-position.test.mjs +201 -0
- package/scripts/cm-ai-admission.mjs +19 -10
- package/scripts/cm-ai-admission.test.mjs +65 -1
- package/scripts/cm-ai-batch-drive.mjs +93 -21
- package/scripts/cm-ai-batch-drive.test.mjs +171 -3
- package/scripts/cm-ai-batch-host.mjs +37 -13
- package/scripts/cm-ai-batch-host.test.mjs +26 -0
- package/scripts/cm-ai-batch-run.mjs +33 -10
- package/scripts/cm-ai-batch-run.test.mjs +56 -5
- package/scripts/cm-ai-bootstrap-driver-preflight.test.mjs +45 -0
- package/scripts/cm-ai-bootstrap-flow.test.mjs +158 -0
- package/scripts/cm-ai-bootstrap-merge.test.mjs +45 -0
- package/scripts/cm-ai-bootstrap.test.mjs +99 -7
- package/scripts/cm-ai-conversation-entry-ops.test.mjs +82 -2
- package/scripts/cm-ai-develop-driver-gaps.test.mjs +822 -0
- package/scripts/cm-ai-drive-bootstrap-rules.test.mjs +468 -0
- package/scripts/cm-ai-drive-timeout.test.mjs +17 -0
- package/scripts/cm-ai-drive.mjs +480 -47
- package/scripts/cm-ai-drive.test.mjs +247 -10
- package/scripts/cm-ai-fix-later-delivery.test.mjs +383 -0
- package/scripts/cm-ai-host.mjs +89 -25
- package/scripts/cm-ai-host.test.mjs +274 -12
- package/scripts/cm-ai-launch-diagnostics.test.mjs +142 -0
- package/scripts/cm-ai-multi-root.test.mjs +9 -3
- package/scripts/cm-ai-project-qa-gate.test.mjs +308 -0
- package/scripts/cm-ai-qa-config-revision.test.mjs +166 -15
- package/scripts/cm-ai-qa-fingerprint-config.test.mjs +157 -0
- package/scripts/cm-ai-qa-fix-cross-session.test.mjs +27 -2
- package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +400 -0
- package/scripts/cm-ai-review-drift-precedence.test.mjs +90 -0
- package/scripts/cm-ai-review-failure.test.mjs +917 -0
- package/scripts/cm-ai-review-timeout-config.test.mjs +29 -7
- package/scripts/cm-ai-review-timeout.test.mjs +199 -4
- package/scripts/cm-ai-run.mjs +160 -60
- package/scripts/cm-ai-run.test.mjs +4 -3
- package/scripts/cm-ai-runner-error-code-regression.test.mjs +219 -0
- package/scripts/cm-ai-selection-guard.test.mjs +100 -0
- package/scripts/cm-ai-session-chain.test.mjs +7 -3
- package/scripts/cm-ai-spec-rebind.test.mjs +481 -0
- package/scripts/cm-ai-supersede.test.mjs +571 -17
- package/scripts/cm-ai-verification-gate.test.mjs +2 -1
- package/scripts/cm-capability-gate.test.mjs +21 -2
- package/scripts/cm-check-drive.mjs +4 -3
- package/scripts/cm-check-drive.test.mjs +17 -1
- package/scripts/cm-check-entry.mjs +13 -2
- package/scripts/cm-check-host.mjs +2 -2
- package/scripts/cm-check-host.test.mjs +57 -1
- package/scripts/cm-check-runtime.sh +16 -7
- package/scripts/cm-claude-developer-worker.test.mjs +43 -2
- package/scripts/cm-claude-probe.test.mjs +9 -1
- package/scripts/cm-claude-review-stream.test.mjs +68 -0
- package/scripts/cm-claude-worker.test.mjs +11 -4
- package/scripts/cm-codex-developer-worker.test.mjs +4 -2
- package/scripts/cm-failover.mjs +8 -8
- package/scripts/cm-fix-abandon.test.mjs +123 -5
- package/scripts/cm-fix-cause-package.test.mjs +2 -0
- package/scripts/cm-fix-drive.mjs +45 -13
- package/scripts/cm-fix-drive.test.mjs +36 -1
- package/scripts/cm-fix-host.mjs +9 -6
- package/scripts/cm-fix-review-budget.test.mjs +141 -0
- package/scripts/cm-fixture-process-cleanup.test.mjs +95 -0
- package/scripts/cm-host-check.test.mjs +6 -3
- package/scripts/cm-host-qa-executor.test.mjs +192 -17
- package/scripts/cm-host-session-diagnostic.test.mjs +10 -0
- package/scripts/cm-interactive-qa-diagnostic.test.mjs +53 -0
- package/scripts/cm-log-event.mjs +17 -0
- package/scripts/cm-log-event.test.mjs +31 -0
- package/scripts/cm-prd-completion.test.mjs +105 -2
- package/scripts/cm-prd-draft.test.mjs +14 -0
- package/scripts/cm-prd-drive.mjs +13 -7
- package/scripts/cm-prd-drive.test.mjs +10 -0
- package/scripts/cm-prd-gate-diagnostic.test.mjs +100 -0
- package/scripts/cm-prd-review-gate.mjs +126 -81
- package/scripts/cm-prd-review-gate.test.mjs +105 -1
- package/scripts/cm-prd-review-preparation.test.mjs +15 -0
- package/scripts/cm-prd-review-publication.test.mjs +6 -0
- package/scripts/cm-prd-self-check.test.mjs +6 -0
- package/scripts/cm-prd-summary.test.mjs +40 -0
- package/scripts/cm-review-dependency-snapshot.test.mjs +15 -0
- package/scripts/cm-review-inventory.test.mjs +253 -1
- package/scripts/cm-spec-manifest.mjs +28 -10
- package/scripts/cm-spec-manifest.test.mjs +8 -4
- package/scripts/cm-spec-task-line.test.mjs +138 -0
- package/scripts/cm-specs-status.test.mjs +31 -1
- package/scripts/cm-task-gate.mjs +18 -10
- package/scripts/cm-task-gate.py +1 -1
- package/scripts/cm-test-branch-impact.test.mjs +6 -3
- package/scripts/fixtures/claude-review-process.mjs +1 -0
- package/scripts/fixtures/process-cleanup.mjs +99 -0
- package/scripts/test-cm-log-event.py +2 -0
- package/scripts/test-cm-prd-review-gate.py +2 -1
- package/scripts/test-npm-install.py +1 -1
- package/scripts/test-scan-public-safety.py +1 -1
- package/scripts/test-shell-compat.sh +67 -0
- package/scripts/test-spec-manifest.py +16 -8
- package/scripts/test-task-gate.py +2 -2
- package/scripts/test-workflow-config.py +1 -0
- package/scripts/validate-public-repo.py +1 -0
- package/skills/cm-ai/references/N1-init.md +1 -1
- package/skills/cm-ai/references/js-host.md +264 -40
- package/skills/cm-check/SKILL.md +6 -1
- package/skills/cm-check/references/js-host.md +3 -3
- package/skills/cm-fix/references/js-host.md +22 -1
- package/skills/cm-prd/references/js-change-recovery.md +30 -0
- package/skills/cm-prd/references/js-host.md +6 -0
|
@@ -87,7 +87,8 @@ test('the batch driver decides retryability from the shared predicate', async ()
|
|
|
87
87
|
const {default:fs}=await import('node:fs');
|
|
88
88
|
const {developmentRetryable}=await import('../runtime/js/cm-ai/cm-ai-conversation-entry.mjs');
|
|
89
89
|
const source=fs.readFileSync(new URL('./cm-ai-batch-run.mjs',import.meta.url),'utf8');
|
|
90
|
-
assert.match(source,/import \{
|
|
90
|
+
assert.match(source,/import \{[^}]*\bdevelopmentRetryable\b[^}]*\} from '\.\.\/runtime\/js\/cm-ai\/cm-ai-conversation-entry\.mjs'/);
|
|
91
|
+
assert.match(source,/import \{[^}]*\bcompletionRetryable\b[^}]*\} from '\.\.\/runtime\/js\/cm-ai\/cm-ai-conversation-entry\.mjs'/);
|
|
91
92
|
assert.match(source,/\|\|developmentRetryable\(status\)\)await call\('start'\)/);
|
|
92
93
|
assert.equal(/status\.code==='developer_result_invalid'/.test(source),false,
|
|
93
94
|
'batch driver still carries its own copy of the retryable code list');
|
|
@@ -41,15 +41,22 @@ function fixture(browserCase,{blocking=true,tests=['logic','commands','browser']
|
|
|
41
41
|
fs.writeFileSync(workflow,JSON.stringify({documentationPaths:[],applicableAgentFiles:[],
|
|
42
42
|
qa:{commands:[{id:'unit',command:[process.execPath,'--version'],caseIds:browserCase?[]:['TC-001']}],
|
|
43
43
|
environment:{kind:'web',carrier:'browser',target:'https://example.invalid/fixture',scope:'local'}}}));
|
|
44
|
+
// create requires a bound review configuration; this one grants no review attempt.
|
|
45
|
+
const review=path.join(root,'placeholder-review.json');fs.writeFileSync(review,JSON.stringify({model:'fixture',preflight:{}}));
|
|
44
46
|
return {root,specsDir,codeProject,config,workflow,
|
|
45
47
|
args:['serve','--config',config,'--mode','create','--host-context','gate-fixture','--allow-development',
|
|
46
|
-
'--workflow-config',workflow,'--allow-qa']};
|
|
48
|
+
'--workflow-config',workflow,'--allow-qa','--review-config',review]};
|
|
47
49
|
}
|
|
48
50
|
|
|
49
51
|
const launch=(f,...extra)=>spawnSync(process.execPath,[cli,...f.args,...extra],{encoding:'utf8',timeout:20000,env:{...process.env,NODE_NO_WARNINGS:'1'}});
|
|
50
52
|
function rejected(result,code){
|
|
51
53
|
assert.equal(result.error,undefined);assert.equal(result.status,1,result.stderr);
|
|
52
|
-
|
|
54
|
+
const parsed=JSON.parse(result.stderr);
|
|
55
|
+
assert.equal(parsed.error.code,code);
|
|
56
|
+
if(['browser_capability_required','browser_capability_unavailable'].includes(code))
|
|
57
|
+
assert.match(parsed.error.reason,/--browser-qa available\|unavailable.*interactive QA/);
|
|
58
|
+
else if(code==='invalid_arguments')assert.match(parsed.error.reason,/--browser-qa/);
|
|
59
|
+
else assert.deepEqual(parsed,{error:{code}});
|
|
53
60
|
}
|
|
54
61
|
function started(f,...extra){
|
|
55
62
|
const result=launch(f,...extra);
|
|
@@ -76,6 +83,18 @@ test('the browser gate fires exactly when the approved contract can select a bro
|
|
|
76
83
|
}finally{fs.rmSync(withoutBrowser.root,{recursive:true,force:true});}
|
|
77
84
|
});
|
|
78
85
|
|
|
86
|
+
test('iOS simulator carrier is named in the launch diagnostic',()=>{
|
|
87
|
+
const f=fixture(true);
|
|
88
|
+
try{
|
|
89
|
+
const workflow=JSON.parse(fs.readFileSync(f.workflow,'utf8'));
|
|
90
|
+
workflow.qa.environment={kind:'app',carrier:'ios-simulator',target:'fixture-app',scope:'local'};
|
|
91
|
+
fs.writeFileSync(f.workflow,JSON.stringify(workflow));
|
|
92
|
+
const result=launch(f);
|
|
93
|
+
rejected(result,'browser_capability_required');
|
|
94
|
+
assert.match(JSON.parse(result.stderr).error.reason,/ios-simulator/);
|
|
95
|
+
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
96
|
+
});
|
|
97
|
+
|
|
79
98
|
test('resume requires a fresh assertion and reopens the run created by available',()=>{
|
|
80
99
|
const f=fixture(true);
|
|
81
100
|
try{
|
|
@@ -50,15 +50,16 @@ function semantic(value,root){
|
|
|
50
50
|
}
|
|
51
51
|
function main(){
|
|
52
52
|
if(process.argv.length===3&&['--help','-h'].includes(process.argv[2])){
|
|
53
|
-
process.stdout.write('用法: cm-check-drive.mjs --plan PLAN.json <start|status|cancel>\nPLAN: skillDir, project, optional config/quick, checks:[{command:[checker,...args]}], answers。start 的机械证据由实际命令产生;check-semantic.json 只存人工判断。宿主没有跨进程恢复。\n');return;
|
|
53
|
+
process.stdout.write('用法: cm-check-drive.mjs --plan PLAN.json <start|status|cancel>\nPLAN: skillDir, project, optional config/runtime/quick, checks:[{command:[checker,...args]}], answers。start 的机械证据由实际命令产生;check-semantic.json 只存人工判断。宿主没有跨进程恢复。\n');return;
|
|
54
54
|
}
|
|
55
55
|
const {plan,operation,base}=loadPlanFile({name:'cm-check-drive.mjs',known:KNOWN});
|
|
56
56
|
requireFields(plan,['skillDir','project']);
|
|
57
57
|
if(plan.mode==='resume')stop(2,'cm-check 宿主没有持久会话,不能 resume');
|
|
58
58
|
const skillDir=path.resolve(base,plan.skillDir),project=path.resolve(base,plan.project);
|
|
59
59
|
const config=plan.config?path.resolve(base,plan.config):undefined;
|
|
60
|
+
const runtime=Object.hasOwn(plan,'runtime')?plan.runtime:undefined;
|
|
60
61
|
let invocation;
|
|
61
|
-
try{invocation=createCmCheckInvocation({skillDir,project,...(config?{config}:{})});}
|
|
62
|
+
try{invocation=createCmCheckInvocation({skillDir,project,...(config?{config}:{}),...(runtime===undefined?{}:{runtime})});}
|
|
62
63
|
catch(error){stop(2,`宿主输入无效: ${error.code??error.message}`);}
|
|
63
64
|
if(config)try{loadConfig({projectRoot:project,configPath:config});}
|
|
64
65
|
catch(error){stop(2,`PLAN.config 无效: ${config}: ${error.message}`);}
|
|
@@ -76,7 +77,7 @@ function main(){
|
|
|
76
77
|
if(value===undefined)stop(2,`步骤 start 会反问 ${kind},但答案文件不存在: ${file}`);
|
|
77
78
|
semantic(value,invocation.workflowRoot);return value;
|
|
78
79
|
});
|
|
79
|
-
driveHost({host:HOST,args:['serve','--skill-dir',skillDir,'--project',project,...(config?['--config',config]:[]),...(plan.quick?['--quick']:[])],
|
|
80
|
+
driveHost({host:HOST,args:['serve','--skill-dir',skillDir,'--project',project,...(config?['--config',config]:[]),...(runtime===undefined?[]:['--runtime',String(runtime)]),...(plan.quick?['--quick']:[])],
|
|
80
81
|
cwd:project,operation,answers:answer,answerFor:row=>{
|
|
81
82
|
if(row.kind==='check_semantic')return {sourceDigest:row.payload.sourceDigest,...answer.check_semantic};
|
|
82
83
|
if(row.kind!=='check_runtime')return null;
|
|
@@ -12,7 +12,7 @@ function fixture(t,exit=0){
|
|
|
12
12
|
t.after(()=>fs.rmSync(dir,{recursive:true,force:true}));
|
|
13
13
|
for(const file of ['scripts/cm-check-entry.mjs','scripts/cm-check-host.mjs','scripts/cm-check-drive.mjs',
|
|
14
14
|
'scripts/cm-workflow-config.mjs','runtime/js/cm-check/host.mjs','runtime/js/cm-ai/drive-core.mjs',
|
|
15
|
-
'runtime/js/cm-ai/host-tool-bridge.mjs','runtime/js/cm-ai/host-session.mjs','runtime/js/cm-ai/effect-contract.mjs',
|
|
15
|
+
'runtime/js/cm-ai/host-tool-bridge.mjs','runtime/js/cm-ai/host-session.mjs','runtime/js/cm-ai/diagnostic-reason.mjs','runtime/js/cm-ai/effect-contract.mjs',
|
|
16
16
|
'runtime/js/cm-ai/contracts.mjs','runtime/js/cm-init/draft-inspection.mjs','skills/cm-check/SKILL.md']){
|
|
17
17
|
fs.mkdirSync(path.dirname(path.join(dir,file)),{recursive:true});fs.copyFileSync(path.join(root,file),path.join(dir,file));
|
|
18
18
|
}
|
|
@@ -60,3 +60,19 @@ test('quick mode needs real runner and returns mechanical-only',t=>{
|
|
|
60
60
|
const run=f.drive(f.plan({quick:true}));assert.equal(run.status,0,run.stderr);
|
|
61
61
|
assert.equal(JSON.parse(run.stdout).result.result.overall,'MECHANICAL_ONLY');
|
|
62
62
|
});
|
|
63
|
+
|
|
64
|
+
test('a plan runtime reaches the checker command and a stale command is still refused',t=>{
|
|
65
|
+
const f=fixture(t),checker=path.join(f.dir,'scripts/cm-check-runtime.sh');
|
|
66
|
+
const withRuntime=f.plan({runtime:'claude',
|
|
67
|
+
checks:[{id:'check_runtime',command:[checker,'--project',f.project,'--runtime','claude','--print-effective']}]});
|
|
68
|
+
const run=f.drive(withRuntime);assert.equal(run.status,0,run.stderr);
|
|
69
|
+
assert.equal(JSON.parse(run.stdout).result.result.overall,'PASSED');
|
|
70
|
+
assert.equal(fs.readFileSync(f.marker,'utf8'),'x','the checker must run exactly once');
|
|
71
|
+
const mismatched=f.drive(f.plan({runtime:'claude'}));
|
|
72
|
+
assert.notEqual(mismatched.status,0,'a plan runtime absent from the command must not be accepted');
|
|
73
|
+
assert.equal(fs.readFileSync(f.marker,'utf8'),'x','a refused plan must not run the checker again');
|
|
74
|
+
const rejected=f.drive(f.plan({runtime:'pi',
|
|
75
|
+
checks:[{id:'check_runtime',command:[checker,'--project',f.project,'--runtime','pi','--print-effective']}]}));
|
|
76
|
+
assert.notEqual(rejected.status,0,'an unsupported runtime must not reach the checker');
|
|
77
|
+
assert.equal(fs.readFileSync(f.marker,'utf8'),'x');
|
|
78
|
+
});
|
|
@@ -51,9 +51,14 @@ function ownedFile(root,relative,code) {
|
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
// The checker labels each role against the runtime actually running it; an unnamed
|
|
55
|
+
// runtime stays unknown rather than being assumed.
|
|
56
|
+
const CHECK_RUNTIMES=new Set(['codex','claude']);
|
|
57
|
+
|
|
54
58
|
export function createCmCheckInvocation(input) {
|
|
55
59
|
const allowed=['skillDir','project'];
|
|
56
60
|
if(input&&Object.hasOwn(input,'config'))allowed.push('config');
|
|
61
|
+
if(input&&Object.hasOwn(input,'runtime'))allowed.push('runtime');
|
|
57
62
|
if(!input||typeof input!=='object'||Array.isArray(input)
|
|
58
63
|
||Object.keys(input).length!==allowed.length||!allowed.every(key=>Object.hasOwn(input,key)))reject('invalid_input');
|
|
59
64
|
const skillDir=realDirectory(input.skillDir,'skill_path_invalid');
|
|
@@ -68,8 +73,14 @@ export function createCmCheckInvocation(input) {
|
|
|
68
73
|
config=realFile(input.config,'config_path_invalid');
|
|
69
74
|
args.push('--config',config);
|
|
70
75
|
}
|
|
76
|
+
let runtime=null;
|
|
77
|
+
if(Object.hasOwn(input,'runtime')){
|
|
78
|
+
if(!CHECK_RUNTIMES.has(input.runtime))reject('runtime_invalid');
|
|
79
|
+
runtime=input.runtime;
|
|
80
|
+
args.push('--runtime',runtime);
|
|
81
|
+
}
|
|
71
82
|
args.push('--print-effective');
|
|
72
|
-
return Object.freeze({workflow:'cm-check',workflowRoot,skillDir,checker,project,config,args:Object.freeze(args)});
|
|
83
|
+
return Object.freeze({workflow:'cm-check',workflowRoot,skillDir,checker,project,config,runtime,args:Object.freeze(args)});
|
|
73
84
|
}
|
|
74
85
|
|
|
75
86
|
export function runCmCheck(input) {
|
|
@@ -99,7 +110,7 @@ function parseCli(argv) {
|
|
|
99
110
|
printEffective=true;
|
|
100
111
|
continue;
|
|
101
112
|
}
|
|
102
|
-
if(!['--skill-dir','--project','--config'].includes(flag)||index+1>=argv.length)reject('invalid_arguments');
|
|
113
|
+
if(!['--skill-dir','--project','--config','--runtime'].includes(flag)||index+1>=argv.length)reject('invalid_arguments');
|
|
103
114
|
const key=flag==='--skill-dir'?'skillDir':flag.slice(2);
|
|
104
115
|
if(Object.hasOwn(input,key))reject('invalid_arguments');
|
|
105
116
|
input[key]=argv[index+1];
|
|
@@ -11,12 +11,12 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
11
11
|
let bridge;
|
|
12
12
|
try{
|
|
13
13
|
if(argv.length===1&&argv[0]==='--help'){
|
|
14
|
-
output.write('cm-check-host.mjs serve --skill-dir ABS_PATH --project ABS_PATH [--config ABS_PATH] [--quick]\n--quick stops after the mechanical checker and reports MECHANICAL_ONLY; it never claims PASSED and never skips a failure.\nJSONL start/status/cancel. Current host executes check_runtime once using the existing platform checker; only exitCode 0 permits check_semantic. Eight original groups + optional degradation; complete coverage and local evidence required. No provider, install, repair, task completion or persistent state. Unknown/disconnected operations never retry.\n');return 0;
|
|
14
|
+
output.write('cm-check-host.mjs serve --skill-dir ABS_PATH --project ABS_PATH [--config ABS_PATH] [--runtime codex|claude] [--quick]\n--runtime names the runtime actually running this check so each role is labelled against it; omitted it stays unknown and no dispatch claim is made.\n--quick stops after the mechanical checker and reports MECHANICAL_ONLY; it never claims PASSED and never skips a failure.\nJSONL start/status/cancel. Current host executes check_runtime once using the existing platform checker; only exitCode 0 permits check_semantic. Eight original groups + optional degradation; complete coverage and local evidence required. No provider, install, repair, task completion or persistent state. Unknown/disconnected operations never retry.\n');return 0;
|
|
15
15
|
}
|
|
16
16
|
need(argv[0]==='serve','invalid_arguments');const request={};
|
|
17
17
|
for(let i=1;i<argv.length;){
|
|
18
18
|
if(argv[i]==='--quick'){need(!Object.hasOwn(request,'quick'),'invalid_arguments');request.quick=true;i+=1;continue;}
|
|
19
|
-
need(['--skill-dir','--project','--config'].includes(argv[i])&&argv[i+1],'invalid_arguments');
|
|
19
|
+
need(['--skill-dir','--project','--config','--runtime'].includes(argv[i])&&argv[i+1],'invalid_arguments');
|
|
20
20
|
const key=argv[i]==='--skill-dir'?'skillDir':argv[i].slice(2);need(!Object.hasOwn(request,key),'invalid_arguments');request[key]=argv[i+1];i+=2;
|
|
21
21
|
}
|
|
22
22
|
need(request.skillDir&&request.project,'invalid_arguments');
|
|
@@ -19,7 +19,7 @@ function fixture(t,exitCode=0){
|
|
|
19
19
|
const dir=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-check-host-'))),project=path.join(dir,'project');fs.mkdirSync(project);
|
|
20
20
|
t.after(()=>fs.rmSync(dir,{recursive:true,force:true}));
|
|
21
21
|
for(const file of ['scripts/cm-check-entry.mjs','scripts/cm-check-host.mjs','scripts/cm-workflow-config.mjs','runtime/js/cm-check/host.mjs',
|
|
22
|
-
'runtime/js/cm-ai/host-tool-bridge.mjs','runtime/js/cm-ai/host-session.mjs','runtime/js/cm-ai/effect-contract.mjs',
|
|
22
|
+
'runtime/js/cm-ai/host-tool-bridge.mjs','runtime/js/cm-ai/host-session.mjs','runtime/js/cm-ai/diagnostic-reason.mjs','runtime/js/cm-ai/effect-contract.mjs',
|
|
23
23
|
'runtime/js/cm-ai/contracts.mjs','runtime/js/cm-init/draft-inspection.mjs','skills/cm-check/SKILL.md']){
|
|
24
24
|
fs.mkdirSync(path.dirname(path.join(dir,file)),{recursive:true});fs.copyFileSync(path.join(root,file),path.join(dir,file));
|
|
25
25
|
}
|
|
@@ -211,3 +211,59 @@ test('quick mode still reports an actual mechanical failure',{timeout:5000},asyn
|
|
|
211
211
|
assert.equal(report.result.overall,'FAILED','quick mode must not swallow a failing checker');
|
|
212
212
|
assert.equal(report.result.semanticChecked,false);
|
|
213
213
|
});
|
|
214
|
+
|
|
215
|
+
test('an explicit runtime reaches the checker; omitting it never claims a dispatch verdict',{timeout:5000},async t=>{
|
|
216
|
+
const f=fixture(t),seen=[];
|
|
217
|
+
for(const runtime of ['codex','claude']){
|
|
218
|
+
const host=createCmCheckHost({...f.input,runtime,quick:true},{call:async(kind,payload)=>{
|
|
219
|
+
seen.push(payload.invocation.args);return mechanical(payload);
|
|
220
|
+
}});
|
|
221
|
+
const report=await host.handle({requestId:`r-${runtime}`,operation:'start'});
|
|
222
|
+
assert.equal(report.result.overall,'MECHANICAL_ONLY');
|
|
223
|
+
}
|
|
224
|
+
assert.deepEqual(seen,[
|
|
225
|
+
['--project',f.input.project,'--runtime','codex','--print-effective'],
|
|
226
|
+
['--project',f.input.project,'--runtime','claude','--print-effective']
|
|
227
|
+
],'the checker must be told which runtime is actually running it');
|
|
228
|
+
const plain=[];
|
|
229
|
+
const host=createCmCheckHost({...f.input,quick:true},{call:async(kind,payload)=>{
|
|
230
|
+
plain.push(payload.invocation.args);return mechanical(payload);
|
|
231
|
+
}});
|
|
232
|
+
await host.handle({requestId:'r-none',operation:'start'});
|
|
233
|
+
assert.deepEqual(plain,[['--project',f.input.project,'--print-effective']],'an unnamed runtime must not be substituted with a guess');
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
test('an unsupported runtime is rejected instead of silently defaulting',{timeout:5000},async t=>{
|
|
237
|
+
const f=fixture(t);
|
|
238
|
+
for(const runtime of ['pi','CODEX','unknown','',null]){
|
|
239
|
+
assert.throws(()=>createCmCheckHost({...f.input,runtime},{call:async()=>{throw Error('must not run');}}),
|
|
240
|
+
error=>error.code==='runtime_invalid',`runtime ${JSON.stringify(runtime)} must not reach the checker`);
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
test('the JSONL CLI accepts --runtime once and rejects a malformed one',{timeout:5000},async t=>{
|
|
245
|
+
const f=fixture(t),cli=path.join(f.dir,'scripts/cm-check-host.mjs');
|
|
246
|
+
const base=['serve','--skill-dir',f.input.skillDir,'--project',f.input.project];
|
|
247
|
+
for(const extra of [['--runtime'],['--runtime','claude','--runtime','codex']]){
|
|
248
|
+
const bad=spawnSync(process.execPath,[cli,...base,...extra],{encoding:'utf8',input:''});
|
|
249
|
+
assert.equal(bad.status,1,`${extra.join(' ')} must not start a session`);
|
|
250
|
+
assert.match(bad.stderr,/invalid_arguments/);
|
|
251
|
+
}
|
|
252
|
+
const help=spawnSync(process.execPath,[cli,'--help'],{encoding:'utf8'});
|
|
253
|
+
assert.match(help.stdout,/--runtime codex\|claude/,'the documented usage must name the option');
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
test('the standalone mechanical entry CLI takes the runtime flag and validates it',{timeout:5000},async t=>{
|
|
257
|
+
const f=fixture(t),cli=path.join(f.dir,'scripts/cm-check-entry.mjs');
|
|
258
|
+
const base=['--skill-dir',f.input.skillDir,'--project',f.input.project];
|
|
259
|
+
const ok=spawnSync(process.execPath,[cli,...base,'--runtime','claude','--print-effective'],{encoding:'utf8'});
|
|
260
|
+
assert.equal(ok.status,0,ok.stderr);
|
|
261
|
+
assert.match(ok.stdout,/original checker output/,'the real checker must still be the one that runs');
|
|
262
|
+
for(const extra of [['--runtime','pi'],['--runtime','unknown']]){
|
|
263
|
+
const bad=spawnSync(process.execPath,[cli,...base,...extra,'--print-effective'],{encoding:'utf8'});
|
|
264
|
+
assert.equal(bad.status,2,`${extra.join(' ')} must not run the checker`);
|
|
265
|
+
assert.match(bad.stderr,/runtime_invalid/);
|
|
266
|
+
}
|
|
267
|
+
const dup=spawnSync(process.execPath,[cli,...base,'--runtime','codex','--runtime','claude','--print-effective'],{encoding:'utf8'});
|
|
268
|
+
assert.equal(dup.status,2);assert.match(dup.stderr,/invalid_arguments/);
|
|
269
|
+
});
|
|
@@ -184,29 +184,38 @@ PROJECT_PATH="$PWD"
|
|
|
184
184
|
CONFIG_PATH=""
|
|
185
185
|
REQUESTED_MODE=""
|
|
186
186
|
PRINT_EFFECTIVE=0
|
|
187
|
+
CHECK_RUNTIME=""
|
|
187
188
|
while [ "$#" -gt 0 ]; do
|
|
188
189
|
case "$1" in
|
|
189
190
|
--project)
|
|
190
|
-
[ "$#" -ge 2 ] || { echo "Usage: $0 [--project PATH] [--config PATH] [--print-effective] [--routing-fixtures|--log-fixtures]" >&2; exit 2; }
|
|
191
|
+
[ "$#" -ge 2 ] || { echo "Usage: $0 [--project PATH] [--config PATH] [--runtime codex|claude] [--print-effective] [--routing-fixtures|--log-fixtures]" >&2; exit 2; }
|
|
191
192
|
PROJECT_PATH="$2"
|
|
192
193
|
shift 2
|
|
193
194
|
;;
|
|
194
195
|
--config)
|
|
195
|
-
[ "$#" -ge 2 ] || { echo "Usage: $0 [--project PATH] [--config PATH] [--print-effective] [--routing-fixtures|--log-fixtures]" >&2; exit 2; }
|
|
196
|
+
[ "$#" -ge 2 ] || { echo "Usage: $0 [--project PATH] [--config PATH] [--runtime codex|claude] [--print-effective] [--routing-fixtures|--log-fixtures]" >&2; exit 2; }
|
|
196
197
|
CONFIG_PATH="$2"
|
|
197
198
|
shift 2
|
|
198
199
|
;;
|
|
199
200
|
--routing-fixtures|--log-fixtures)
|
|
200
|
-
[ -z "$REQUESTED_MODE" ] || { echo "Usage: $0 [--project PATH] [--config PATH] [--print-effective] [--routing-fixtures|--log-fixtures]" >&2; exit 2; }
|
|
201
|
+
[ -z "$REQUESTED_MODE" ] || { echo "Usage: $0 [--project PATH] [--config PATH] [--runtime codex|claude] [--print-effective] [--routing-fixtures|--log-fixtures]" >&2; exit 2; }
|
|
201
202
|
REQUESTED_MODE="$1"
|
|
202
203
|
shift
|
|
203
204
|
;;
|
|
205
|
+
--runtime)
|
|
206
|
+
[ "$#" -ge 2 ] || { echo "Usage: $0 [--project PATH] [--config PATH] [--runtime codex|claude] [--print-effective] [--routing-fixtures|--log-fixtures]" >&2; exit 2; }
|
|
207
|
+
case "$2" in
|
|
208
|
+
codex|claude) CHECK_RUNTIME="$2" ;;
|
|
209
|
+
*) echo "Usage: $0 [--project PATH] [--config PATH] [--runtime codex|claude] [--print-effective] [--routing-fixtures|--log-fixtures]" >&2; exit 2 ;;
|
|
210
|
+
esac
|
|
211
|
+
shift 2
|
|
212
|
+
;;
|
|
204
213
|
--print-effective)
|
|
205
214
|
PRINT_EFFECTIVE=1
|
|
206
215
|
shift
|
|
207
216
|
;;
|
|
208
217
|
*)
|
|
209
|
-
echo "Usage: $0 [--project PATH] [--config PATH] [--print-effective] [--routing-fixtures|--log-fixtures]" >&2
|
|
218
|
+
echo "Usage: $0 [--project PATH] [--config PATH] [--runtime codex|claude] [--print-effective] [--routing-fixtures|--log-fixtures]" >&2
|
|
210
219
|
exit 2
|
|
211
220
|
;;
|
|
212
221
|
esac
|
|
@@ -273,7 +282,7 @@ for module in \
|
|
|
273
282
|
cm-ai-learning-handoff-writer.mjs cm-ai-learning-writer.mjs cm-ai-qa-log.mjs \
|
|
274
283
|
cm-ai-run-finalizer.mjs codex-config.mjs codex-review-adapter.mjs contracts.mjs \
|
|
275
284
|
durable-runner-state.mjs effect-contract.mjs execution-store.mjs gate-bridge.mjs \
|
|
276
|
-
host.mjs host-session.mjs index.mjs provider-review-observation.mjs review-package.mjs \
|
|
285
|
+
host.mjs host-session.mjs diagnostic-reason.mjs index.mjs provider-review-observation.mjs review-package.mjs \
|
|
277
286
|
review-result.schema.json review-runner.mjs task-commit-codec.mjs task-commit.mjs \
|
|
278
287
|
task-owner.mjs task-runner.mjs worker-codex.mjs; do
|
|
279
288
|
require_file "runtime/js/cm-ai/$module"
|
|
@@ -395,14 +404,14 @@ if [ -n "$NODE_BIN" ]; then
|
|
|
395
404
|
for rt in $missing; do
|
|
396
405
|
warn "runtimes.available 声明 ${declared},但本机 ${rt} CLI 不可解析(可解析≠配额可用)"
|
|
397
406
|
done
|
|
398
|
-
current_runtime="${CM_RUNTIME:-
|
|
407
|
+
current_runtime="${CHECK_RUNTIME:-${CM_RUNTIME:-unknown}}"
|
|
399
408
|
for role in coder reviewer; do
|
|
400
409
|
if [ -n "$CONFIG_PATH" ]; then
|
|
401
410
|
role_json=$("$NODE_BIN" "$ROOT/scripts/cm-workflow-config.mjs" --project "$PROJECT_PATH" --config "$CONFIG_PATH" --role "$role" --runtime "$current_runtime" --print-role 2>/dev/null || true)
|
|
402
411
|
else
|
|
403
412
|
role_json=$("$NODE_BIN" "$ROOT/scripts/cm-workflow-config.mjs" --project "$PROJECT_PATH" --role "$role" --runtime "$current_runtime" --print-role 2>/dev/null || true)
|
|
404
413
|
fi
|
|
405
|
-
role_line=$(printf '%s' "$role_json" | "$NODE_BIN" -e 'let d="";process.stdin.on("data",c=>d+=c).on("end",()=>{let j={};try{j=JSON.parse(d);}catch{}const tag=j.route_state==="declared-adapter"?"(已声明未派发)":"";process.stdout.write(`${j.role||"?"}: adapter=${j.adapter||"?"} route_state=${
|
|
414
|
+
role_line=$(printf '%s' "$role_json" | "$NODE_BIN" -e 'let d="";process.stdin.on("data",c=>d+=c).on("end",()=>{let j={};try{j=JSON.parse(d);}catch{}const unknown=process.argv[1]==="unknown";const state=unknown?"未判定":(j.route_state||"?");const tag=unknown?"(当前运行时未指定,用 --runtime 或 CM_RUNTIME 指定后才能判断)":(j.route_state==="declared-adapter"?"(已声明未派发)":"");process.stdout.write(`${j.role||"?"}: adapter=${j.adapter||"?"} route_state=${state}${tag}`);})' "$current_runtime" 2>/dev/null || true)
|
|
406
415
|
[ -n "$role_line" ] && echo "runtime declaration [${declared}] ${role_line}"
|
|
407
416
|
done
|
|
408
417
|
fi
|
|
@@ -9,6 +9,7 @@ import {createProjectExecution} from '../runtime/js/cm-ai/host-project-execution
|
|
|
9
9
|
import {buildClaudeDeveloperPrompt} from '../runtime/js/cm-ai/claude-developer-adapter.mjs';
|
|
10
10
|
import {protectedTextInstructions} from '../runtime/js/cm-ai/host-conversation-execution.mjs';
|
|
11
11
|
import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
12
|
+
import {ownerGuardSource} from './fixtures/process-cleanup.mjs';
|
|
12
13
|
|
|
13
14
|
const identity={repositoryId:'proposal-fixture',runId:'proposal-run',taskId:'T-001',attempt:1};
|
|
14
15
|
const proposal={status:'succeeded',value:{outcome:'implemented'},edits:[{path:'target.txt',beforeSha256:null,content:'safe text\n'}]};
|
|
@@ -25,7 +26,8 @@ function fixture(t){
|
|
|
25
26
|
function fakeWorker(cwd,{value=proposal,mode='normal',timeoutMs=3000,noticeEvents=[],noticeAt=1,onNotice,
|
|
26
27
|
resultFields={},toolName='Read',toolResultId='read-1',
|
|
27
28
|
assistantContent=[{type:'text',text:'proposal'}]}={}){
|
|
28
|
-
|
|
29
|
+
// The timeout mode hangs; the guard ends it if this test process dies first.
|
|
30
|
+
const source=`${ownerGuardSource()}let input='';process.stdin.on('data',s=>input+=s);process.stdin.on('end',()=>{
|
|
29
31
|
if(!input.includes('Return {status,value,edits}'))process.exit(9);
|
|
30
32
|
if(${JSON.stringify(mode)}==='timeout'){setInterval(()=>{},1000);return;}
|
|
31
33
|
const session_id='synthetic-claude-developer';
|
|
@@ -57,6 +59,45 @@ function fakeWorker(cwd,{value=proposal,mode='normal',timeoutMs=3000,noticeEvent
|
|
|
57
59
|
const rateLimit=(overrides={})=>({type:'rate_limit_event',session_id:'synthetic-claude-developer',
|
|
58
60
|
rate_limit_info:{status:'allowed',rateLimitType:'five_hour',resetsAt:123,active:true,reason:null,
|
|
59
61
|
nested:{raw:'private'},list:['private']},...overrides});
|
|
62
|
+
const devIntent=(sessionId='synthetic-claude-developer')=>JSON.parse(
|
|
63
|
+
`{"type":"system","subtype":"dev_intent","kind":"ios_app","trigger":"project_scan","uuid":"fixture-uuid","session_id":"${sessionId}"}`,
|
|
64
|
+
);
|
|
65
|
+
test('developer accepts dev_intent on either side of init with a sanitized notice',async t=>{
|
|
66
|
+
const root=fixture(t),control={signal:new AbortController().signal};
|
|
67
|
+
const baseline=await fakeWorker(root)({prompt:prompt()},control);
|
|
68
|
+
for(const noticeAt of [0,1,2]){
|
|
69
|
+
const notices=[],result=await fakeWorker(root,{noticeAt,noticeEvents:[devIntent()],onNotice:n=>notices.push(n)})
|
|
70
|
+
({prompt:prompt()},control);
|
|
71
|
+
assert.deepEqual(result,baseline);
|
|
72
|
+
assert.deepEqual(notices,[{kind:'claude_system_notice',subtype:'dev_intent'}]);
|
|
73
|
+
}
|
|
74
|
+
for(const onNotice of [undefined,()=>{throw Error('notice consumer');}]){
|
|
75
|
+
const result=await fakeWorker(root,{noticeAt:0,noticeEvents:[devIntent()],onNotice})({prompt:prompt()},control);
|
|
76
|
+
assert.deepEqual(result,baseline);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
test('developer dev_intent binds init session and shares a 32-notice budget',async t=>{
|
|
80
|
+
const root=fixture(t),control={signal:new AbortController().signal};
|
|
81
|
+
for(const [noticeEvents,noticeAt,code] of [
|
|
82
|
+
[[devIntent('other')],0,'session_mismatch'],
|
|
83
|
+
[[devIntent('other')],1,'session_mismatch'],
|
|
84
|
+
[[devIntent('')],0,'invalid_session'],
|
|
85
|
+
[[devIntent(' '.repeat(3))],0,'invalid_session'],
|
|
86
|
+
[[devIntent('x'.repeat(129))],0,'invalid_session'],
|
|
87
|
+
[[{...devIntent(),subtype:'api_retry'}],0,'missing_init'],
|
|
88
|
+
[[{...devIntent(),subtype:'future_notice'}],1,'unexpected_event'],
|
|
89
|
+
[Array.from({length:33},()=>devIntent()),0,'unexpected_event'],
|
|
90
|
+
]){
|
|
91
|
+
const result=await fakeWorker(root,{noticeEvents,noticeAt})({prompt:prompt()},control);
|
|
92
|
+
assert.deepEqual(result,{status:'unknown',code});
|
|
93
|
+
}
|
|
94
|
+
const notices=[],baseline=await fakeWorker(root)({prompt:prompt()},control);
|
|
95
|
+
const result=await fakeWorker(root,{noticeAt:1,
|
|
96
|
+
noticeEvents:[devIntent(),...Array.from({length:30},()=>devIntent()),rateLimit()],
|
|
97
|
+
onNotice:n=>notices.push(n)})({prompt:prompt()},control);
|
|
98
|
+
assert.deepEqual(result,baseline);
|
|
99
|
+
assert.equal(notices.length,32);
|
|
100
|
+
});
|
|
60
101
|
test('developer forwards scalar notices while preserving proposals and read-tool state',async t=>{
|
|
61
102
|
const root=fixture(t),events=[],control={signal:new AbortController().signal,onEvent:e=>events.push(e)};
|
|
62
103
|
const baseline=await fakeWorker(root)({prompt:prompt()},control);
|
|
@@ -110,7 +151,7 @@ test('developer rejects mismatched, excessive, unknown and terminal rate limit e
|
|
|
110
151
|
const root=fixture(t);
|
|
111
152
|
for(const [noticeEvents,noticeAt,code,count] of [
|
|
112
153
|
[[rateLimit({session_id:'other'})],1,'session_mismatch',0],
|
|
113
|
-
[Array.from({length:
|
|
154
|
+
[Array.from({length:33},()=>rateLimit()),1,'unexpected_event',32],
|
|
114
155
|
[[rateLimit({type:'foo_event'})],1,'unexpected_event',0],
|
|
115
156
|
[[rateLimit()],0,'missing_init',0],
|
|
116
157
|
[[rateLimit()],3,'invalid_event',0],
|
|
@@ -8,6 +8,7 @@ import * as zlib from 'node:zlib';
|
|
|
8
8
|
import {spawn,spawnSync} from 'node:child_process';
|
|
9
9
|
import {fileURLToPath} from 'node:url';
|
|
10
10
|
import {buildManifest} from './cm-spec-manifest.mjs';
|
|
11
|
+
import {ownerGuardSource} from './fixtures/process-cleanup.mjs';
|
|
11
12
|
import {previewClaudeTools,claudeProbeSandbox,createClaudeModelMarkerDetector} from '../runtime/js/cm-ai/claude-tool-preview.mjs';
|
|
12
13
|
import {previewPromptTransport,writePreviewPrompt} from '../runtime/js/cm-ai/tool-preview.mjs';
|
|
13
14
|
|
|
@@ -107,7 +108,7 @@ test('probe accepts at most two compliant requests and validates every request',
|
|
|
107
108
|
for(const [name,requests,passed] of cases)await t.test(name,async()=>{
|
|
108
109
|
// Keep the fixture alive after SIGTERM so the worker's real cleanup captures
|
|
109
110
|
// the entire sequence deterministically, without delaying the probe's abort.
|
|
110
|
-
const source
|
|
111
|
+
const source=`${ownerGuardSource()}process.on('SIGTERM',()=>{});setInterval(()=>{},1000);
|
|
111
112
|
let input='';process.stdin.on('data',s=>input+=s);process.stdin.on('end',async()=>{
|
|
112
113
|
for(const request of ${JSON.stringify(requests)}){
|
|
113
114
|
const response=await fetch(process.env.ANTHROPIC_BASE_URL+'/v1/messages',{method:'POST',
|
|
@@ -191,10 +192,17 @@ test('Claude preflight CLI exits 1 with model_recognized false and leaves normal
|
|
|
191
192
|
assert.ok(run.stdout.trim(),run.stderr);
|
|
192
193
|
const receipt=JSON.parse(run.stdout);
|
|
193
194
|
assert.equal(receipt.preflight.passed,expectedExit===0);
|
|
195
|
+
assert.equal(receipt.timeoutMs,900000);
|
|
194
196
|
assert.equal(receipt.preflight.request_checks.find(check=>Object.hasOwn(check,'model_matches'))?.model_matches,true);
|
|
195
197
|
if(expectedExit===1)assert.deepEqual(receipt.preflight.request_checks.at(-1),
|
|
196
198
|
{model_recognized:false,reported_model:model});
|
|
197
199
|
else assert.equal(receipt.preflight.request_checks.some(check=>Object.hasOwn(check,'model_recognized')),false);
|
|
200
|
+
if(expectedExit===1){
|
|
201
|
+
assert.match(run.stderr,/fixture-unrecognized-model/);
|
|
202
|
+
assert.match(run.stderr,/claude-opus-5/);
|
|
203
|
+
assert.match(run.stderr,/installed Claude CLI/);
|
|
204
|
+
assert.match(run.stderr,/2\.1\.274 \(Claude Code\)/);
|
|
205
|
+
}
|
|
198
206
|
assert.equal(run.stdout.includes('CM-PROBE-001'),false);
|
|
199
207
|
}
|
|
200
208
|
}finally{fs.rmSync(root,{recursive:true,force:true});}
|
|
@@ -170,12 +170,55 @@ test('rate limit session, count, whitelist and terminal boundaries fail closed',
|
|
|
170
170
|
});
|
|
171
171
|
|
|
172
172
|
const systemNotice = (subtype='api_retry',extra={}) => ({type:'system',subtype,session_id:'fresh-review',...extra});
|
|
173
|
+
const devIntent = (sessionId='fresh-review') => JSON.parse(
|
|
174
|
+
`{"type":"system","subtype":"dev_intent","kind":"ios_app","trigger":"project_scan","uuid":"fixture-uuid","session_id":"${sessionId}"}`,
|
|
175
|
+
);
|
|
173
176
|
function observe(messages,callback) {
|
|
174
177
|
const events=[],notices=[];
|
|
175
178
|
const stream=createClaudeReviewStream(e=>events.push(e),callback ?? (n=>notices.push(n)));
|
|
176
179
|
messages.forEach(m=>stream.accept(m));
|
|
177
180
|
return {result:stream.finish(),events,notices};
|
|
178
181
|
}
|
|
182
|
+
test('dev_intent before or after init preserves review result and emits only its subtype',()=>{
|
|
183
|
+
const [init,assistant,result]=transcript(),baseline=observe(transcript());
|
|
184
|
+
for(const messages of [
|
|
185
|
+
[devIntent(),init,assistant,result],
|
|
186
|
+
[init,devIntent(),assistant,result],
|
|
187
|
+
[init,assistant,devIntent(),result],
|
|
188
|
+
]){
|
|
189
|
+
const actual=observe(messages);
|
|
190
|
+
assert.deepEqual(actual.result,baseline.result);
|
|
191
|
+
assert.deepEqual(actual.events,baseline.events);
|
|
192
|
+
assert.deepEqual(actual.notices,[{kind:'claude_system_notice',subtype:'dev_intent'}]);
|
|
193
|
+
}
|
|
194
|
+
for(const callback of [undefined,()=>{throw Error('notice consumer');}]){
|
|
195
|
+
const stream=createClaudeReviewStream(()=>{},callback);
|
|
196
|
+
[devIntent(),init,assistant,result].forEach(message=>stream.accept(message));
|
|
197
|
+
assert.deepEqual(stream.finish(),baseline.result);
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
test('dev_intent binds session across init and shares the 32-notice budget',()=>{
|
|
201
|
+
const [init,assistant,result]=transcript();
|
|
202
|
+
for(const messages of [
|
|
203
|
+
[devIntent('other'),init],
|
|
204
|
+
[init,devIntent('other')],
|
|
205
|
+
])assert.throws(()=>decode(messages),{code:'session_mismatch'});
|
|
206
|
+
for(const sessionId of ['', ' '.repeat(3), 'x'.repeat(257)]){
|
|
207
|
+
const stream=createClaudeReviewStream(()=>{});
|
|
208
|
+
assert.throws(()=>stream.accept(devIntent(sessionId)),{code:'invalid_session'});
|
|
209
|
+
}
|
|
210
|
+
assert.throws(()=>decode([systemNotice('api_retry'),init]),{code:'missing_init'});
|
|
211
|
+
assert.throws(()=>decode([init,systemNotice('future_notice')]),{code:'unexpected_event'});
|
|
212
|
+
const notices=[],stream=createClaudeReviewStream(()=>{},notice=>notices.push(notice));
|
|
213
|
+
[devIntent(),...Array.from({length:30},()=>devIntent()),init,rateLimit(),assistant,result]
|
|
214
|
+
.forEach(message=>stream.accept(message));
|
|
215
|
+
assert.equal(stream.finish().status,'succeeded');
|
|
216
|
+
assert.equal(notices.length,32);
|
|
217
|
+
const overflow=createClaudeReviewStream(()=>{});
|
|
218
|
+
[devIntent(),init,...Array.from({length:31},()=>devIntent())]
|
|
219
|
+
.forEach(message=>overflow.accept(message));
|
|
220
|
+
assert.throws(()=>overflow.accept(devIntent()),{code:'unexpected_event'});
|
|
221
|
+
});
|
|
179
222
|
test('88-heartbeat dogfood event counts preserve structured findings and exact observation',()=>{
|
|
180
223
|
const [init,text,result]=transcript();
|
|
181
224
|
const value={verdict:'changes_requested',packageDigest:'a'.repeat(64),examinedPaths:['code.mjs'],
|
|
@@ -278,3 +321,28 @@ test('exhausted retries do not decide success or suppress provider failure',()=>
|
|
|
278
321
|
}
|
|
279
322
|
}
|
|
280
323
|
});
|
|
324
|
+
|
|
325
|
+
// Claude CLI 2.1.274 reports an API failure as a synthetic assistant message
|
|
326
|
+
// with a string error class. Before any tool call it names a retryable class;
|
|
327
|
+
// anything else keeps the fail-closed unexpected_assistant.
|
|
328
|
+
test('API error classes before any tool call name the reviewer failure',()=>{
|
|
329
|
+
const [init]=transcript();
|
|
330
|
+
const apiError=error=>({type:'assistant',session_id:'fresh-review',parent_tool_use_id:null,error,is_api_error_message:true,
|
|
331
|
+
message:{role:'assistant',content:[{type:'text',text:'API Error'}]}});
|
|
332
|
+
for(const [error,code] of [['authentication_failed','reviewer_auth_failed'],['billing_error','reviewer_billing_error'],
|
|
333
|
+
['rate_limit','reviewer_rate_limited'],['server_error','reviewer_server_error'],['model_not_found','reviewer_model_not_found'],
|
|
334
|
+
['invalid_request','reviewer_api_error'],['__proto__','reviewer_api_error']]){
|
|
335
|
+
const events=[],stream=createClaudeReviewStream(event=>events.push(event));stream.accept(init);
|
|
336
|
+
assert.throws(()=>stream.accept(apiError(error)),{code});
|
|
337
|
+
assert.deepEqual(events.map(event=>event.event),['thread.started','turn.started']);
|
|
338
|
+
assert.throws(()=>stream.finish(),{code:'incomplete_result'});
|
|
339
|
+
}
|
|
340
|
+
for(const messages of [
|
|
341
|
+
[assistant([tool('t1','Bash')]),toolResult('t1',true),apiError('rate_limit')],
|
|
342
|
+
[{...apiError('rate_limit'),parent_tool_use_id:'child'}],
|
|
343
|
+
[apiError({type:'rate_limit'})],
|
|
344
|
+
]){
|
|
345
|
+
const stream=createClaudeReviewStream(()=>{});stream.accept(init);
|
|
346
|
+
assert.throws(()=>messages.forEach(message=>stream.accept(message)),{code:'unexpected_assistant'});
|
|
347
|
+
}
|
|
348
|
+
});
|
|
@@ -6,6 +6,7 @@ import {spawn} from 'node:child_process';
|
|
|
6
6
|
import {createHash} from 'node:crypto';
|
|
7
7
|
import {readFileSync} from 'node:fs';
|
|
8
8
|
import {claudeWorker,claudeReviewArgs,claudeReviewFingerprint,claudePreflightMatches} from '../runtime/js/cm-ai/worker-claude.mjs';
|
|
9
|
+
import {killProcessGroup,ownerGuardSource} from './fixtures/process-cleanup.mjs';
|
|
9
10
|
|
|
10
11
|
const config={cwd:'/tmp',model:'claude-fixture',cli:'never-dispatch-real-cli'};
|
|
11
12
|
const receipt={passed:true,provider:'claude',prompt_transport:'stdin',config_fingerprint:claudeReviewFingerprint(config)};
|
|
@@ -164,14 +165,16 @@ test('failure, timeout, explicit cancellation and missing preflight remain disti
|
|
|
164
165
|
test('timeout kills inherited-pipe descendants, including TERM-ignoring children',
|
|
165
166
|
{skip:process.platform==='win32'},async()=>{
|
|
166
167
|
for (const descendantStdio of ['inherit','ignore']) {
|
|
167
|
-
let descendant;
|
|
168
|
+
let descendant,leader;
|
|
169
|
+
// Both guards watch this test process, never the leader, so a missed group kill still shows.
|
|
170
|
+
const hung=ownerGuardSource()+"process.on('SIGTERM',()=>{});setInterval(()=>{},1000)";
|
|
168
171
|
const worker=claudeWorker({...config,preflight:receipt,timeoutMs:300,
|
|
169
172
|
spawnProcess:(_cli,_args,options)=>{
|
|
170
173
|
const child=spawn(process.execPath,['-e',
|
|
171
|
-
|
|
172
|
-
|
|
174
|
+
`${ownerGuardSource()}const {spawn}=require('node:child_process');const c=spawn(process.execPath,['-e',
|
|
175
|
+
${JSON.stringify(hung)}],{stdio:['ignore','${descendantStdio}','${descendantStdio}']});
|
|
173
176
|
process.stderr.write(String(c.pid)+'\\n');setInterval(()=>{},1000);`],options);
|
|
174
|
-
child.stderr.on('data',chunk=>{descendant=Number(String(chunk).trim());});
|
|
177
|
+
leader=child.pid;child.stderr.on('data',chunk=>{descendant=Number(String(chunk).trim());});
|
|
175
178
|
return child;
|
|
176
179
|
}});
|
|
177
180
|
try {
|
|
@@ -180,7 +183,11 @@ test('timeout kills inherited-pipe descendants, including TERM-ignoring children
|
|
|
180
183
|
assert.equal(result.code,'timeout');assert.ok(Date.now()-started<4000);
|
|
181
184
|
assert.ok(Date.now()-started>=1200,'leader close must not cancel group escalation');
|
|
182
185
|
assert.ok(Number.isInteger(descendant));
|
|
186
|
+
const gone=()=>{try{process.kill(descendant,0);return false;}catch(error){return error.code==='ESRCH';}};
|
|
187
|
+
for(const deadline=Date.now()+3000;!gone()&&Date.now()<deadline;)await new Promise(resolve=>setTimeout(resolve,25));
|
|
188
|
+
assert.ok(gone(),'group SIGKILL must reach the TERM-ignoring descendant');
|
|
183
189
|
} finally {
|
|
190
|
+
killProcessGroup(leader);
|
|
184
191
|
if(Number.isInteger(descendant))try{process.kill(descendant,'SIGKILL');}catch{}
|
|
185
192
|
}
|
|
186
193
|
}
|
|
@@ -9,8 +9,10 @@ import {commonArgs} from '../runtime/js/cm-ai/codex-config.mjs';
|
|
|
9
9
|
import {createCodexDeveloperRun} from '../runtime/js/cm-ai/codex-developer-adapter.mjs';
|
|
10
10
|
import {requestFor} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
11
11
|
import {createTaskRunner} from '../runtime/js/cm-ai/task-runner.mjs';
|
|
12
|
+
import {ownerGuardSource} from './fixtures/process-cleanup.mjs';
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
// The hang mode never exits on its own; the guard ends it if this test process dies first.
|
|
15
|
+
const script=`${ownerGuardSource()}let input='';process.stdin.on('data',x=>input+=x);process.stdin.on('end',()=>{
|
|
14
16
|
const emit=x=>process.stdout.write(JSON.stringify(x)+'\\n');
|
|
15
17
|
emit({type:'thread.started',thread_id:'isolated-fixture'});emit({type:'turn.started'});
|
|
16
18
|
if(process.argv[1]==='hang'){setInterval(()=>{},1000);return;}
|
|
@@ -139,7 +141,7 @@ test('cancellation kills a TERM-resistant descendant inheriting output pipes',()
|
|
|
139
141
|
const descendant=`process.on('SIGTERM',()=>{});
|
|
140
142
|
process.stdout.write(JSON.stringify({type:'item.started',item:{type:'command_execution',id:'descendant-ready'}})+'\\n');
|
|
141
143
|
setTimeout(()=>{require('node:fs').writeFileSync('leaked.txt','still running');process.exit(0);},2500);`;
|
|
142
|
-
const parent
|
|
144
|
+
const parent=`${ownerGuardSource()}process.stdin.resume();
|
|
143
145
|
process.stdout.write(JSON.stringify({type:'thread.started',thread_id:'tree'})+'\\n');
|
|
144
146
|
process.stdout.write(JSON.stringify({type:'turn.started'})+'\\n');
|
|
145
147
|
require('node:child_process').spawn(process.execPath,['-e',${JSON.stringify(descendant)}],{stdio:['ignore','inherit','inherit']});
|
package/scripts/cm-failover.mjs
CHANGED
|
@@ -7,6 +7,7 @@ import path from 'node:path';
|
|
|
7
7
|
import childProcess from 'node:child_process';
|
|
8
8
|
// Single source of truth for role primary/standby; shared with the cm-ai host.
|
|
9
9
|
import {ROLE_ROUTING} from '../runtime/js/cm-ai/runtime-failover.mjs';
|
|
10
|
+
import {taskDeclarations,approvedTaskGrammar,TASK_GRAMMAR} from '../runtime/js/spec-task-line.mjs';
|
|
10
11
|
|
|
11
12
|
export {ROLE_ROUTING};
|
|
12
13
|
|
|
@@ -37,17 +38,16 @@ function readDirectory(dir,label){
|
|
|
37
38
|
return fs.readdirSync(dir,{withFileTypes:true});
|
|
38
39
|
}
|
|
39
40
|
|
|
40
|
-
//
|
|
41
|
-
|
|
41
|
+
// Task declarations use the shared tasks.md grammar (spec-task-line.mjs);
|
|
42
|
+
// anything else, including fenced examples, is prose.
|
|
43
|
+
export function parseTasks(text,grammar=TASK_GRAMMAR){
|
|
42
44
|
const tasks=[],seen=new Set();
|
|
43
|
-
for(const
|
|
44
|
-
const
|
|
45
|
-
if(!match)continue;
|
|
46
|
-
const id=match[2];
|
|
45
|
+
for(const declaration of taskDeclarations(text,{grammar})){
|
|
46
|
+
const id=declaration.id;
|
|
47
47
|
if(!TASK_RE.test(id))continue;
|
|
48
48
|
if(seen.has(id))throw new FailoverError(`tasks.md contains a duplicate task id: ${id}`);
|
|
49
49
|
seen.add(id);
|
|
50
|
-
tasks.push({id,done:
|
|
50
|
+
tasks.push({id,done:declaration.completed,title:declaration.rest.replace(/^[::\s]+/u,'').trim()});
|
|
51
51
|
}
|
|
52
52
|
if(tasks.length===0)throw new FailoverError('tasks.md declares no `- [ ] T-xxx:` task line');
|
|
53
53
|
return tasks;
|
|
@@ -136,7 +136,7 @@ export function classifyBreakpoint(task,attempts){
|
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
function inspectFeature(featureDir,feature){
|
|
139
|
-
const tasks=parseTasks(readTextFile(path.join(featureDir,'tasks.md'),'tasks.md'));
|
|
139
|
+
const tasks=parseTasks(readTextFile(path.join(featureDir,'tasks.md'),'tasks.md'),approvedTaskGrammar(path.dirname(featureDir)));
|
|
140
140
|
const reviewsDir=path.join(featureDir,'.reviews');
|
|
141
141
|
let entries=new Set();
|
|
142
142
|
if(fs.existsSync(reviewsDir))
|