@aibyzero/cm-workflow 0.16.5 → 0.16.7
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 +14 -0
- package/CHANGELOG.md +19 -1
- package/README.md +17 -4
- package/THIRD_PARTY_NOTICES.md +9 -0
- package/VERSION +1 -1
- package/docs/architecture.md +43 -0
- package/docs/execution-optimizations.md +33 -0
- package/docs/external-models.md +114 -0
- package/docs/fixes/.reviews/20260929-bootstrap-unchanged-review-r1.md +7 -0
- package/docs/fixes/.reviews/20260930-develop-package-limit-recovery-r4.md +9 -0
- package/docs/fixes/20260929-bootstrap-rule-refresh-conflict.md +22 -0
- package/docs/fixes/20260929-bootstrap-unchanged-review.md +26 -0
- package/docs/fixes/20260930-develop-package-limit-recovery.md +65 -0
- package/docs/human-correction.md +31 -0
- package/docs/installation.md +28 -7
- package/docs/js-workflow-control.md +96 -6
- package/docs/live-evidence-drivers.md +62 -0
- package/docs/next-steps.md +15 -10
- package/docs/untested-branches.md +27 -4
- package/docs/user-guide.md +23 -8
- package/install-codex.sh +28 -11
- package/package.json +1 -1
- package/runtime/js/cm-ai/claude-review-adapter.mjs +7 -4
- package/runtime/js/cm-ai/claude-tool-preview.mjs +4 -4
- package/runtime/js/cm-ai/cm-ai-admission.mjs +34 -10
- package/runtime/js/cm-ai/cm-ai-context-refresh.mjs +9 -5
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +111 -34
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +93 -31
- package/runtime/js/cm-ai/cm-ai-run-finalizer.mjs +13 -57
- package/runtime/js/cm-ai/codex-config.mjs +3 -2
- package/runtime/js/cm-ai/codex-review-adapter.mjs +34 -15
- package/runtime/js/cm-ai/committed-rule-basis.mjs +76 -0
- package/runtime/js/cm-ai/developer-adapter.mjs +8 -5
- package/runtime/js/cm-ai/drive-bootstrap.mjs +22 -12
- package/runtime/js/cm-ai/drive-core.mjs +9 -3
- package/runtime/js/cm-ai/durable-runner-state.mjs +146 -14
- package/runtime/js/cm-ai/effect-contract.mjs +1 -1
- package/runtime/js/cm-ai/execution-policy.mjs +58 -0
- package/runtime/js/cm-ai/external-group-models.mjs +53 -0
- package/runtime/js/cm-ai/external-model-launch.mjs +23 -0
- package/runtime/js/cm-ai/external-models.mjs +52 -0
- package/runtime/js/cm-ai/external-run-guard.mjs +96 -0
- package/runtime/js/cm-ai/host-bootstrap.mjs +70 -20
- package/runtime/js/cm-ai/host-check.mjs +30 -4
- package/runtime/js/cm-ai/host-conversation-execution.mjs +59 -17
- package/runtime/js/cm-ai/host-documentation.mjs +2 -2
- package/runtime/js/cm-ai/host-progress.mjs +80 -0
- package/runtime/js/cm-ai/host-project-execution.mjs +16 -11
- package/runtime/js/cm-ai/host-qa-executor.mjs +54 -8
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +22 -5
- package/runtime/js/cm-ai/host-session.mjs +1 -1
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +3 -1
- package/runtime/js/cm-ai/knowledge-closeout.mjs +56 -0
- package/runtime/js/cm-ai/legacy-model-run-preview.mjs +24 -0
- package/runtime/js/cm-ai/legacy-model-settings.mjs +59 -0
- package/runtime/js/cm-ai/live-evidence.mjs +96 -0
- package/runtime/js/cm-ai/log-rows.mjs +36 -0
- package/runtime/js/cm-ai/model-configuration-file.mjs +63 -0
- package/runtime/js/cm-ai/model_configuration_write.py +214 -0
- package/runtime/js/cm-ai/native-usage-log.mjs +26 -0
- package/runtime/js/cm-ai/operator-guidance.mjs +89 -0
- package/runtime/js/cm-ai/owned-process-cleanup.mjs +22 -0
- package/runtime/js/cm-ai/provider-review-observation.mjs +15 -0
- package/runtime/js/cm-ai/provider-usage.mjs +39 -0
- package/runtime/js/cm-ai/review-package.mjs +11 -0
- package/runtime/js/cm-ai/review-presentation.mjs +45 -0
- package/runtime/js/cm-ai/review-reconciliation.mjs +20 -0
- package/runtime/js/cm-ai/status-projection.mjs +93 -0
- package/runtime/js/cm-ai/task-runner.mjs +176 -25
- package/runtime/js/cm-ai/tool-preview.mjs +8 -4
- package/runtime/js/cm-ai/worker-claude-developer.mjs +16 -7
- package/runtime/js/cm-ai/worker-claude.mjs +63 -19
- package/runtime/js/cm-ai/worker-codex-developer.mjs +15 -9
- package/runtime/js/cm-ai/worker-codex.mjs +45 -19
- package/runtime/js/cm-fix/cause-evidence.mjs +5 -3
- package/runtime/js/cm-fix/cause-invocation.mjs +6 -3
- package/runtime/js/cm-fix/cause-package.mjs +10 -1
- package/runtime/js/cm-fix/execution.mjs +183 -40
- package/runtime/js/cm-fix/final-review.mjs +18 -10
- package/runtime/js/cm-fix/finish.mjs +2 -19
- package/runtime/js/cm-fix/host-review.mjs +25 -6
- package/runtime/js/cm-fix/host.mjs +4 -1
- package/runtime/js/cm-fix/layout.mjs +1 -1
- package/runtime/js/cm-fix/log-events.mjs +29 -0
- package/runtime/js/cm-fix/metrics.mjs +3 -2
- package/runtime/js/cm-fix/progress.mjs +4 -0
- package/runtime/js/cm-fix/review-reconciliation.mjs +64 -0
- package/runtime/js/cm-prd/analysis.mjs +5 -2
- package/runtime/js/cm-prd/response-recovery.mjs +23 -0
- package/runtime/js/cm-prd/review-host.mjs +2 -1
- package/runtime/js/cm-prd/review-publication.mjs +23 -13
- package/runtime/js/cm-prd/review-time.mjs +29 -0
- package/runtime/js/cm-prd/session.mjs +53 -6
- package/runtime/js/cm-security/finalize.mjs +32 -0
- package/runtime/js/cm-test/recovery.mjs +4 -4
- package/runtime/review.md +5 -0
- package/runtime/task-gates.md +6 -0
- package/runtime/workflow-config.md +10 -1
- package/scripts/cm-ai-admission.mjs +14 -3
- package/scripts/cm-ai-batch-drive.mjs +52 -23
- package/scripts/cm-ai-batch-drive.test.mjs +47 -2
- package/scripts/cm-ai-batch-host.mjs +44 -16
- package/scripts/cm-ai-batch-run.mjs +77 -29
- package/scripts/cm-ai-bootstrap-flow.test.mjs +3 -2
- package/scripts/cm-ai-bootstrap-merge.test.mjs +118 -1
- package/scripts/cm-ai-bootstrap.test.mjs +80 -87
- package/scripts/cm-ai-conversation-entry-ops.test.mjs +15 -0
- package/scripts/cm-ai-develop-driver-gaps.test.mjs +102 -0
- package/scripts/cm-ai-drive-bootstrap-rules.test.mjs +2 -2
- package/scripts/cm-ai-drive.mjs +73 -28
- package/scripts/cm-ai-drive.test.mjs +119 -1
- package/scripts/cm-ai-feature-selection.test.mjs +178 -0
- package/scripts/cm-ai-host.mjs +79 -27
- package/scripts/cm-ai-host.test.mjs +88 -0
- package/scripts/cm-ai-operator-guidance.test.mjs +94 -0
- package/scripts/cm-ai-progress.test.mjs +521 -0
- package/scripts/cm-ai-protected-scope.test.mjs +194 -0
- package/scripts/cm-ai-qa-config-revision.test.mjs +21 -0
- package/scripts/cm-ai-review-failure.test.mjs +71 -11
- package/scripts/cm-ai-run.mjs +94 -19
- package/scripts/cm-ai-run.test.mjs +2 -1
- package/scripts/cm-bootstrap-review-recovery.test.mjs +70 -0
- package/scripts/cm-check-drive.test.mjs +1 -0
- package/scripts/cm-check-runtime.sh +11 -0
- package/scripts/cm-claude-install-layout.test.mjs +26 -0
- package/scripts/cm-claude-probe.test.mjs +1 -1
- package/scripts/cm-codex-plugin-metadata.py +83 -0
- package/scripts/cm-codex-plugin-metadata.test.mjs +55 -0
- package/scripts/cm-efficiency-checks.test.mjs +37 -0
- package/scripts/cm-efficiency-diagnostics.test.mjs +74 -0
- package/scripts/cm-efficiency-offline.mjs +35 -0
- package/scripts/cm-efficiency-policy.test.mjs +48 -0
- package/scripts/cm-efficiency-presentation.test.mjs +35 -0
- package/scripts/cm-efficiency-response.test.mjs +117 -0
- package/scripts/cm-efficiency-usage.test.mjs +148 -0
- package/scripts/cm-external-batch-host.test.mjs +157 -0
- package/scripts/cm-external-fix-host.test.mjs +281 -0
- package/scripts/cm-external-fix-reconciliation.test.mjs +105 -0
- package/scripts/cm-external-group-models.test.mjs +60 -0
- package/scripts/cm-external-model-host.test.mjs +180 -0
- package/scripts/cm-external-model-recovery.test.mjs +108 -0
- package/scripts/cm-external-models.test.mjs +89 -0
- package/scripts/cm-external-process-cleanup.test.mjs +71 -0
- package/scripts/cm-external-qa-fix.test.mjs +170 -0
- package/scripts/cm-external-review-reconciliation.test.mjs +314 -0
- package/scripts/cm-fix-drive.mjs +28 -13
- package/scripts/cm-fix-final-review.test.mjs +11 -6
- package/scripts/cm-fix-host.mjs +17 -10
- package/scripts/cm-fix-large-log.test.mjs +113 -0
- package/scripts/cm-fix-protected-edits.test.mjs +12 -0
- package/scripts/cm-fix-rediagnosis.test.mjs +168 -0
- package/scripts/cm-fix-review-budget.test.mjs +7 -1
- package/scripts/cm-host-qa-executor.test.mjs +329 -3
- package/scripts/cm-knowledge-closeout.test.mjs +160 -0
- package/scripts/cm-live-evidence.test.mjs +64 -0
- package/scripts/cm-log-event.mjs +34 -7
- package/scripts/cm-log-event.py +15 -0
- package/scripts/cm-model-setup.mjs +79 -0
- package/scripts/cm-prd-drive.mjs +32 -11
- package/scripts/cm-prd-drive.test.mjs +15 -0
- package/scripts/cm-prd-host.mjs +26 -6
- package/scripts/cm-prd-host.test.mjs +4 -0
- package/scripts/cm-prd-review-host.test.mjs +17 -0
- package/scripts/cm-prd-session-recovery.test.mjs +44 -2
- package/scripts/cm-prd-task-grouping.test.mjs +206 -0
- package/scripts/cm-release-smoke.sh +5 -1
- package/scripts/cm-review-scope-recovery.test.mjs +5 -3
- package/scripts/cm-runtime-i18n.mjs +15 -4
- package/scripts/cm-runtime-install.mjs +8 -4
- package/scripts/cm-runtime.mjs +116 -23
- package/scripts/cm-runtime.test.mjs +121 -12
- package/scripts/cm-security.test.mjs +32 -0
- package/scripts/cm-task-gate-correction.test.mjs +117 -0
- package/scripts/cm-task-gate.mjs +146 -10
- package/scripts/cm-task-gate.py +1 -0
- package/scripts/cm-test-branch-impact.test.mjs +11 -0
- package/scripts/cm-test-drive.mjs +10 -4
- package/scripts/cm-test-drive.test.mjs +14 -1
- package/scripts/cm-tool-preview-context.test.mjs +12 -0
- package/scripts/cm-usage-report.py +22 -3
- package/scripts/cm-workflow-config.mjs +10 -1
- package/scripts/fixtures/bootstrap-review-runner.mjs +102 -0
- package/scripts/fixtures/live-evidence-driver.mjs +35 -0
- package/scripts/fixtures/process-cleanup.mjs +3 -1
- package/scripts/test-cm-native-usage.py +62 -0
- package/scripts/test-external-model-setup.py +91 -0
- package/scripts/test-model-configuration-write.py +201 -0
- package/scripts/test-npm-install.py +10 -1
- package/skills/cm-ai/SKILL.md +2 -2
- package/skills/cm-ai/references/N1-init.md +1 -1
- package/skills/cm-ai/references/N8-finish.md +5 -0
- package/skills/cm-ai/references/js-host.md +16 -7
- package/skills/cm-ai/references/knowledge-closeout.md +90 -0
- package/skills/cm-fix/SKILL.md +1 -1
- package/skills/cm-fix/references/js-host.md +30 -2
- package/skills/cm-prd/SKILL.md +5 -4
- package/skills/cm-prd/references/spec-self-check.md +3 -1
- package/skills/cm-runtime/SKILL.md +29 -6
- package/skills/cm-security/SKILL.md +4 -2
- package/skills/cm-security/references/scan-contract.md +1 -0
- package/templates/cm-workflow.yml +1 -1
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
// Explicit batch (feature) selection. An approved cross-feature order may run a
|
|
2
|
+
// later feature while an earlier one still has pending tasks: the 2026-10-06
|
|
3
|
+
// AI潮 6.api-native-reading batch before 5.author-column T-009/T-010. Without an
|
|
4
|
+
// explicit selection, admission still picks the lowest-numbered pending feature.
|
|
5
|
+
import nodeTest from 'node:test';
|
|
6
|
+
import assert from 'node:assert/strict';
|
|
7
|
+
import fs from 'node:fs';
|
|
8
|
+
import os from 'node:os';
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
import {spawnSync} from 'node:child_process';
|
|
11
|
+
import {fileURLToPath} from 'node:url';
|
|
12
|
+
import {buildManifest} from './cm-spec-manifest.mjs';
|
|
13
|
+
import {inspectCmAiAdmission,isFinalCmAiTask} from '../runtime/js/cm-ai/cm-ai-admission.mjs';
|
|
14
|
+
import {inspectCmAiContextRefresh} from '../runtime/js/cm-ai/cm-ai-context-refresh.mjs';
|
|
15
|
+
import {openControlRun,validateRunDefinition} from './cm-ai-run.mjs';
|
|
16
|
+
import {isSupportedExecutionPlatform} from '../runtime/js/cm-ai/execution-platform.mjs';
|
|
17
|
+
|
|
18
|
+
const platform=isSupportedExecutionPlatform();
|
|
19
|
+
const test=(name,fn)=>nodeTest(name,{skip:!platform},fn);
|
|
20
|
+
const admissionCli=fileURLToPath(new URL('./cm-ai-admission.mjs',import.meta.url));
|
|
21
|
+
const runCli=fileURLToPath(new URL('./cm-ai-run.mjs',import.meta.url));
|
|
22
|
+
const EARLY='5.author',LATER='6.reader';
|
|
23
|
+
|
|
24
|
+
function project(t,{later='- [ ] T-001: reader contract\n- [ ] T-002: mapping\n\n## 依赖\n\n- T-002 依赖 T-001\n'}={}){
|
|
25
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-feature-selection-')));
|
|
26
|
+
t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
27
|
+
const specsDir=path.join(root,'specs'),codeProject=path.join(root,'code');
|
|
28
|
+
fs.mkdirSync(codeProject);fs.writeFileSync(path.join(codeProject,'a.js'),'old\n');
|
|
29
|
+
for(const [feature,tasks] of [[EARLY,'- [x] T-008: done\n- [ ] T-009: after the reader batch\n'],[LATER,later]]){
|
|
30
|
+
fs.mkdirSync(path.join(specsDir,feature),{recursive:true});
|
|
31
|
+
for(const file of ['requirements.md','design.md'])fs.writeFileSync(path.join(specsDir,feature,file),`# ${feature}\n`);
|
|
32
|
+
fs.writeFileSync(path.join(specsDir,feature,'tasks.md'),tasks);
|
|
33
|
+
}
|
|
34
|
+
const approve=()=>fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',
|
|
35
|
+
features:[EARLY,LATER],specFiles:buildManifest(specsDir)}));
|
|
36
|
+
approve();
|
|
37
|
+
const admission=(...args)=>{
|
|
38
|
+
const out=spawnSync(process.execPath,[admissionCli,'--specs-dir',specsDir,'--code-project',codeProject,...args],{encoding:'utf8'});
|
|
39
|
+
return {...out,json:out.stdout.trim()?JSON.parse(out.stdout):null};
|
|
40
|
+
};
|
|
41
|
+
const definition=(taskId,extra={})=>({version:1,specsDir,codeProject,feature:LATER,
|
|
42
|
+
identity:{repositoryId:'fixture',runId:`reader-${taskId}-run`,taskId,attempt:1},scope:['a.js'],requirements:[],...extra});
|
|
43
|
+
const selected={featureSelection:{version:1,feature:LATER}};
|
|
44
|
+
return {root,specsDir,codeProject,approve,admission,definition,selected};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
test('without an explicit choice admission still selects the lowest-numbered pending feature',t=>{
|
|
48
|
+
const f=project(t);
|
|
49
|
+
const result=f.admission();
|
|
50
|
+
assert.equal(result.status,0,result.stderr);
|
|
51
|
+
assert.deepEqual(result.json.nextTask,{feature:EARLY,id:'T-009',description:'after the reader batch'});
|
|
52
|
+
assert.equal(Object.hasOwn(result.json,'requestedFeatureComplete'),false);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('an explicit later feature is selected with its own dependency rule and the earlier feature untouched',t=>{
|
|
56
|
+
const f=project(t);
|
|
57
|
+
const tasksBefore=fs.readFileSync(path.join(f.specsDir,EARLY,'tasks.md'));
|
|
58
|
+
const result=f.admission('--feature',LATER);
|
|
59
|
+
assert.equal(result.status,0,result.stderr);
|
|
60
|
+
assert.equal(result.json.state,'ready');
|
|
61
|
+
assert.deepEqual(result.json.nextTask,{feature:LATER,id:'T-001',description:'reader contract'});
|
|
62
|
+
// T-002 depends on T-001: only T-001 is eligible.
|
|
63
|
+
assert.deepEqual(result.json.eligibleTasks,[{feature:LATER,id:'T-001'}]);
|
|
64
|
+
assert.deepEqual(result.json.features.map(item=>[item.name,item.pending]),[[EARLY,1],[LATER,2]]);
|
|
65
|
+
assert.deepEqual(fs.readFileSync(path.join(f.specsDir,EARLY,'tasks.md')),tasksBefore);
|
|
66
|
+
const printed=f.admission('--feature',LATER,'--print-run-definition','--scope','a.js');
|
|
67
|
+
assert.equal(printed.status,0,printed.stderr);
|
|
68
|
+
assert.deepEqual(printed.json.featureSelection,{version:1,feature:LATER});
|
|
69
|
+
assert.equal(printed.json.feature,LATER);assert.equal(printed.json.identity.taskId,'T-001');
|
|
70
|
+
const blocked=f.admission('--feature',LATER,'--print-run-definition','--scope','a.js','--task','T-002');
|
|
71
|
+
assert.equal(blocked.status,1);assert.match(blocked.stderr,/task_selection_mismatch/);assert.match(blocked.stderr,/T-001 尚未完成/);
|
|
72
|
+
const missing=f.admission('--feature','7.missing');
|
|
73
|
+
assert.equal(missing.status,1);assert.equal(missing.json.reason,'feature_selection_invalid');
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test('an explicit choice keeps every approval gate: manifest drift and unapproved specs still block',t=>{
|
|
77
|
+
const f=project(t);
|
|
78
|
+
fs.appendFileSync(path.join(f.specsDir,EARLY,'requirements.md'),'drift\n');
|
|
79
|
+
const drift=f.admission('--feature',LATER);
|
|
80
|
+
assert.equal(drift.status,1);assert.equal(drift.json.reason,'spec_drift');
|
|
81
|
+
fs.writeFileSync(path.join(f.specsDir,'.cm-specs-status'),JSON.stringify({status:'awaiting_review',features:[EARLY,LATER]}));
|
|
82
|
+
const pending=f.admission('--feature',LATER);
|
|
83
|
+
assert.equal(pending.json.state,'awaiting_spec_approval');assert.equal(pending.json.nextTask,null);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test('a completed selected feature is reported and never yields another feature definition or run',async t=>{
|
|
87
|
+
const f=project(t,{later:'- [x] T-001: reader contract\n'});
|
|
88
|
+
const result=f.admission('--feature',LATER);
|
|
89
|
+
assert.equal(result.status,0,result.stderr);
|
|
90
|
+
assert.equal(result.json.requestedFeatureComplete,LATER);
|
|
91
|
+
assert.equal(result.json.nextTask.feature,EARLY);
|
|
92
|
+
assert.match(result.json.warnings.join(' '),new RegExp(`所选 feature ${LATER} 已无待办任务`));
|
|
93
|
+
const printed=f.admission('--feature',LATER,'--print-run-definition','--scope','a.js');
|
|
94
|
+
assert.equal(printed.status,1);assert.equal(printed.stdout,'');assert.match(printed.stderr,/feature_tasks_terminal/);
|
|
95
|
+
await assert.rejects(openControlRun(validateRunDefinition(f.definition('T-001',f.selected)),'create'),
|
|
96
|
+
error=>error.code==='task_selection_mismatch'&&/已无待办任务/.test(error.reason));
|
|
97
|
+
assert.equal(fs.existsSync(path.join(f.specsDir,'.reviews','.execution')),false);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test('a run creates for an explicit later feature, refuses without it, and refuses a task whose dependency is pending',async t=>{
|
|
101
|
+
const f=project(t);
|
|
102
|
+
// Unchanged 0.16.7 behaviour without an explicit choice.
|
|
103
|
+
await assert.rejects(openControlRun(validateRunDefinition(f.definition('T-001')),'create'),
|
|
104
|
+
error=>error.code==='task_selection_mismatch'&&error.reason.includes(`当前 feature ${EARLY}`)&&error.reason.includes('--feature'));
|
|
105
|
+
await assert.rejects(openControlRun(validateRunDefinition(f.definition('T-002',f.selected)),'create'),
|
|
106
|
+
error=>error.code==='task_selection_mismatch'&&error.reason.includes('T-001 尚未完成'));
|
|
107
|
+
assert.equal(fs.existsSync(path.join(f.specsDir,'.reviews','.execution')),false);
|
|
108
|
+
const config=path.join(f.root,'run.json');fs.writeFileSync(config,JSON.stringify(f.definition('T-001',f.selected)));
|
|
109
|
+
const invoke=mode=>{
|
|
110
|
+
const out=spawnSync(process.execPath,[runCli,'serve','--config',config,'--mode',mode],{encoding:'utf8',timeout:20000,
|
|
111
|
+
input:[{version:1,operation:'status',requestId:'status',identity:f.definition('T-001').identity}].map(JSON.stringify).join('\n')+'\n'});
|
|
112
|
+
return {...out,rows:out.stdout.trim().split('\n').filter(Boolean).map(JSON.parse)};
|
|
113
|
+
};
|
|
114
|
+
const created=invoke('create');
|
|
115
|
+
assert.equal(created.status,0,created.stderr);
|
|
116
|
+
assert.equal(created.rows.find(row=>row.requestId==='status').result.identity.taskId,'T-001');
|
|
117
|
+
const journal=path.join(f.specsDir,'.reviews','.execution','reader-T-001-run','state.json');
|
|
118
|
+
const before=fs.readFileSync(journal);
|
|
119
|
+
const resumed=invoke('resume');
|
|
120
|
+
assert.equal(resumed.status,0,resumed.stderr);
|
|
121
|
+
assert.equal(resumed.rows.find(row=>row.requestId==='status').result.identity.taskId,'T-001');
|
|
122
|
+
assert.deepEqual(fs.readFileSync(journal),before);
|
|
123
|
+
// The selection is part of the durable definition: dropping it changes the run.
|
|
124
|
+
fs.writeFileSync(config,JSON.stringify(f.definition('T-001')));
|
|
125
|
+
const dropped=invoke('resume');assert.equal(dropped.status,1);assert.match(dropped.stderr,/fingerprint_mismatch/);
|
|
126
|
+
assert.match(fs.readFileSync(path.join(f.specsDir,EARLY,'tasks.md'),'utf8'),/- \[ \] T-009/);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test('in-run admission for an explicit run reads the selected feature (context refresh and last-task check)',t=>{
|
|
130
|
+
const f=project(t,{later:'- [ ] T-001: reader contract\n'});
|
|
131
|
+
const input={specsDir:f.specsDir,codeProject:f.codeProject,feature:LATER,applicableAgentFiles:[]};
|
|
132
|
+
assert.throws(()=>inspectCmAiContextRefresh(input),{code:'context_invalid'});
|
|
133
|
+
const refresh=inspectCmAiContextRefresh({...input,featureSelection:LATER});
|
|
134
|
+
assert.deepEqual(refresh.nextTask,{feature:LATER,id:'T-001',description:'reader contract'});
|
|
135
|
+
assert.throws(()=>inspectCmAiContextRefresh({...input,featureSelection:EARLY}),{code:'context_invalid'});
|
|
136
|
+
assert.throws(()=>isFinalCmAiTask({specsDir:f.specsDir,codeProject:f.codeProject,feature:LATER,taskId:'T-001'}),
|
|
137
|
+
{code:'documentation_admission_required'});
|
|
138
|
+
// Two tasks are pending in the project (T-009 too): not the final task.
|
|
139
|
+
assert.equal(isFinalCmAiTask({specsDir:f.specsDir,codeProject:f.codeProject,feature:LATER,taskId:'T-001',featureSelection:LATER}),false);
|
|
140
|
+
assert.equal(inspectCmAiAdmission({specsDir:f.specsDir,codeProject:f.codeProject}).nextTask.feature,EARLY);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
test('run definitions accept featureSelection only for their own feature',t=>{
|
|
144
|
+
const f=project(t);
|
|
145
|
+
assert.deepEqual(validateRunDefinition(f.definition('T-001',f.selected)).featureSelection,{version:1,feature:LATER});
|
|
146
|
+
for(const bad of [{version:1,feature:EARLY},{version:2,feature:LATER},{version:1,feature:LATER,extra:true},null])
|
|
147
|
+
assert.throws(()=>validateRunDefinition(f.definition('T-001',{featureSelection:bad})),{code:'invalid_feature_selection'});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
test('the human approval phrase 可以,请开始开发 is an explicit start; looser phrasings are not',t=>{
|
|
151
|
+
const f=project(t);
|
|
152
|
+
fs.writeFileSync(path.join(f.specsDir,'.cm-specs-status'),JSON.stringify({status:'awaiting_review',features:[EARLY,LATER]}));
|
|
153
|
+
for(const reply of ['可以,请开始开发','可以,请开始开发。'])
|
|
154
|
+
assert.equal(f.admission('--approval-response',reply).json.approvalIntent,'explicit',reply);
|
|
155
|
+
for(const reply of ['开始开发','请开始开发','可以,请开始开发,但别现在做','可以'])
|
|
156
|
+
assert.equal(f.admission('--approval-response',reply).json.approvalIntent,'not_approval',reply);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
test('after its last task an explicit run still refreshes context; the next task is the project own one',t=>{
|
|
160
|
+
const f=project(t,{later:'- [x] T-001: reader contract\n'});
|
|
161
|
+
const refresh=inspectCmAiContextRefresh({specsDir:f.specsDir,codeProject:f.codeProject,feature:LATER,applicableAgentFiles:[],featureSelection:LATER});
|
|
162
|
+
assert.equal(refresh.state,'ready');assert.equal(refresh.nextTask.feature,EARLY);
|
|
163
|
+
assert(refresh.contextFiles.some(file=>file.path===`${LATER}/tasks.md`));
|
|
164
|
+
const admission=inspectCmAiAdmission({specsDir:f.specsDir,codeProject:f.codeProject,feature:LATER});
|
|
165
|
+
assert.deepEqual(admission.features.map(item=>item.name),[EARLY,LATER]);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
test('with every task done an explicit feature still refuses to print or create, not exit 0',async t=>{
|
|
169
|
+
const f=project(t,{later:'- [x] T-001: reader contract\n'});
|
|
170
|
+
fs.writeFileSync(path.join(f.specsDir,EARLY,'tasks.md'),'- [x] T-008: done\n- [x] T-009: done\n');f.approve();
|
|
171
|
+
const admission=f.admission('--feature',LATER);
|
|
172
|
+
assert.equal(admission.json.state,'complete');assert.equal(admission.json.requestedFeatureComplete,LATER);
|
|
173
|
+
const printed=f.admission('--feature',LATER,'--print-run-definition','--scope','a.js');
|
|
174
|
+
assert.equal(printed.status,1);assert.equal(printed.stdout,'');assert.match(printed.stderr,/feature_tasks_terminal/);
|
|
175
|
+
await assert.rejects(openControlRun(validateRunDefinition(f.definition('T-001',f.selected)),'create'),
|
|
176
|
+
error=>error.code==='task_selection_mismatch'&&/已无待办任务/.test(error.reason));
|
|
177
|
+
assert.equal(fs.existsSync(path.join(f.specsDir,'.reviews','.execution')),false);
|
|
178
|
+
});
|
package/scripts/cm-ai-host.mjs
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import {readLaunchExecutionPolicy} from '../runtime/js/cm-ai/execution-policy.mjs';
|
|
3
|
+
import {readLaunchExternalModels} from '../runtime/js/cm-ai/external-model-launch.mjs';
|
|
4
|
+
import {loadExternalModels,externalPair} from '../runtime/js/cm-ai/external-models.mjs';
|
|
2
5
|
// Opt-in current-conversation host. Review requires a separately authorized
|
|
3
6
|
// attempt and the registered V3 boundary; preflight is only local diagnostics.
|
|
7
|
+
import {selectExternalModels} from '../runtime/js/cm-ai/external-models.mjs';
|
|
4
8
|
import fs from 'node:fs';
|
|
5
9
|
import path from 'node:path';
|
|
6
10
|
import {spawnSync} from 'node:child_process';
|
|
7
11
|
import {fileURLToPath} from 'node:url';
|
|
8
12
|
import {REVIEWED_HANDOFF_HINT} from '../runtime/js/cm-ai/host-handoff.mjs';
|
|
9
|
-
import {readRunDefinition,openControlRun,createCodexExecution} from './cm-ai-run.mjs';
|
|
13
|
+
import {readRunDefinition,openControlRun,createCodexExecution,assertCreatableScope} from './cm-ai-run.mjs';
|
|
10
14
|
import {createConversationExecution as executionFor} from '../runtime/js/cm-ai/host-conversation-execution.mjs';
|
|
11
15
|
import {createHostToolBridge} from '../runtime/js/cm-ai/host-tool-bridge.mjs';
|
|
12
16
|
import {serveCmAiHost,parseHostInputLimit,inputLimitReason} from '../runtime/js/cm-ai/host-session.mjs';
|
|
@@ -42,12 +46,12 @@ export function readBootstrapConfiguration(file){
|
|
|
42
46
|
const refuse=(ok,code,reason)=>{if(!ok)throw Object.assign(new Error(code),{code,reason});};
|
|
43
47
|
const REASONED_CODES=['supersede_unavailable','supersede_code_drift','handoff_exists','browser_capability_required',
|
|
44
48
|
'browser_capability_unavailable','invalid_arguments','fingerprint_mismatch','task_selection_mismatch','review_configuration_required',
|
|
45
|
-
'spec_rebind_refused','spec_rebind_unavailable'];
|
|
49
|
+
'spec_rebind_refused','spec_rebind_unavailable','protected_scope'];
|
|
46
50
|
const fixLocalPermissions=new Map(['red-test','baseline','regression','learning-writeback','walkthrough','finish','abandon',
|
|
47
51
|
'abandon-review','test-author','repair','cause-review','final-review']
|
|
48
52
|
.map(name=>[`--allow-qa-fix-${name}`,`--allow-${name}`]));
|
|
49
53
|
|
|
50
|
-
const usage='cm-ai-host.mjs serve --config RUN_DEFINITION.json --mode create|resume --host-context ID --allow-development --review-config PATH (required at create; resume passes the same file) [--original-host-context ID] [--runtime codex|claude] [--input-limit BYTES] [--failover] [--allow-review-attempt 1|2] [--allow-abandon-review] [--allow-abandon-effect] [--workflow-config PATH] [--allow-qa] [--browser-qa available|unavailable]\nInput limit is transport-only: integer 65536-4194304 bytes, default 65536; it bounds every input line and every tool reply, and may change on resume. A longer line stops the session with request_too_large. Review config is {model,preflight[,disabledSkills][,timeoutMs]}; timeoutMs is the reviewer transport budget in milliseconds (integer 1-3600000, default 900000), independent of protected mode and outside the authorized configuration digest. --browser-qa declares interactive QA capability for applicable carriers including browser and ios-simulator.\ncm-ai-host.mjs preflight --config RUN_DEFINITION.json --review-model MODEL [--runtime codex|claude] (synthetic loopback only)';
|
|
54
|
+
const usage='cm-ai-host.mjs serve --config RUN_DEFINITION.json --mode create|resume --host-context ID --allow-development --review-config PATH (required at create; resume passes the same file) [--original-host-context ID] [--runtime codex|claude] [--review-runtime codex|claude] [--feature N.slug] [--input-limit BYTES] [--failover] [--allow-review-attempt 1|2] [--allow-abandon-review] [--allow-abandon-effect] [--allow-bootstrap-review-recovery] [--workflow-config PATH] [--allow-qa] [--browser-qa available|unavailable]\nInput limit is transport-only: integer 65536-4194304 bytes, default 65536; it bounds every input line and every tool reply, and may change on resume. A longer line stops the session with request_too_large. Review config is {model,preflight[,disabledSkills][,timeoutMs]}; timeoutMs is the reviewer transport budget in milliseconds (integer 1-3600000, default 900000), independent of protected mode and outside the authorized configuration digest. --browser-qa declares interactive QA capability for applicable carriers including browser and ios-simulator.\nNew runs: --external-models [--external-models-config FILE] freezes one pair per actual external provider; resume reads only its snapshot. preflight --config RUN_DEFINITION.json --external-provider codex|claude uses the saved pair.\ncm-ai-host.mjs preflight --config RUN_DEFINITION.json --review-model MODEL [--runtime codex|claude] (synthetic loopback only)';
|
|
51
55
|
|
|
52
56
|
export function formatClaudeModelHint(config,version=null){
|
|
53
57
|
const marker=config?.preflight?.request_checks?.find(check=>check?.model_recognized===false);
|
|
@@ -67,11 +71,13 @@ export async function serveHostTransport(options,rawInputLimit,serve=serveCmAiHo
|
|
|
67
71
|
return serve({...options,inputLimit:parseHostInputLimit(rawInputLimit)});
|
|
68
72
|
}
|
|
69
73
|
|
|
70
|
-
function reviewConfiguration(file){
|
|
74
|
+
function reviewConfiguration(file,pair=null){
|
|
71
75
|
const info=fs.lstatSync(file);
|
|
72
76
|
need(info.isFile()&&!info.isSymbolicLink()&&info.size<=64*1024,'invalid_review_config');
|
|
73
|
-
|
|
74
|
-
|
|
77
|
+
let config=json(JSON.parse(fs.readFileSync(file,'utf8')));
|
|
78
|
+
if(pair){need(!Object.hasOwn(config,'model')||config.model===pair.model,'external_model_configuration_conflict');
|
|
79
|
+
need(!Object.hasOwn(config,'effort')||config.effort===pair.effort,'external_model_configuration_conflict');config={...config,...pair};}
|
|
80
|
+
shape(config,['model','preflight',...(pair?['effort']:[]),...(Object.hasOwn(config,'disabledSkills')?['disabledSkills']:[]),
|
|
75
81
|
...(Object.hasOwn(config,'timeoutMs')?['timeoutMs']:[])]);
|
|
76
82
|
need(typeof config.model==='string'&&/^[a-zA-Z0-9._-]+$/.test(config.model),'invalid_review_config');
|
|
77
83
|
const disabledSkills=config.disabledSkills??[];
|
|
@@ -85,24 +91,24 @@ function reviewConfiguration(file){
|
|
|
85
91
|
}
|
|
86
92
|
|
|
87
93
|
// Shared synthetic loopback diagnostic; a receipt never grants Review permission.
|
|
88
|
-
export async function runReviewPreflight(definition,{model,runtime='codex',disabledSkills}={}){
|
|
94
|
+
export async function runReviewPreflight(definition,{model,effort,runtime='codex',disabledSkills}={}){
|
|
89
95
|
need(['codex','claude'].includes(runtime),'invalid_runtime');
|
|
90
96
|
if(runtime==='claude'){
|
|
91
97
|
const {previewClaudeTools}=await import('../runtime/js/cm-ai/claude-tool-preview.mjs');
|
|
92
|
-
const config=await previewClaudeTools({cwd:definition.codeProject,model});
|
|
98
|
+
const config=await previewClaudeTools({cwd:definition.codeProject,model,effort});
|
|
93
99
|
return config;
|
|
94
100
|
}
|
|
95
101
|
const {previewIsolated,previewTools}=await import('../runtime/js/cm-ai/tool-preview.mjs');
|
|
96
102
|
const preview=disabledSkills===undefined?previewIsolated:previewTools;
|
|
97
|
-
const receipt=await preview({cwd:definition.codeProject,model,allowCodeProject:true,promptTransport:'stdin',
|
|
103
|
+
const receipt=await preview({cwd:definition.codeProject,model,effort,allowCodeProject:true,promptTransport:'stdin',
|
|
98
104
|
...(disabledSkills===undefined?{}:{disabledSkills})});
|
|
99
105
|
// No raw startup diagnostics, headers, prompt or discovered content.
|
|
100
|
-
return {model,disabledSkills:receipt.disabledSkillFolders,preflight:{passed:receipt.passed,
|
|
106
|
+
return {model,...(effort===undefined?{}:{effort}),disabledSkills:receipt.disabledSkillFolders,preflight:{passed:receipt.passed,
|
|
101
107
|
cli_model:receipt.cli_model,config_fingerprint:receipt.config_fingerprint,prompt_transport:receipt.prompt_transport,
|
|
102
108
|
real_model_requests:receipt.real_model_requests,listener_closed:receipt.listener_closed}};
|
|
103
109
|
}
|
|
104
110
|
|
|
105
|
-
async function protectedExecutionFor(definition,hostContextId,extra,review,mode,workflow,bridge,bootstrap=null){
|
|
111
|
+
async function protectedExecutionFor(definition,hostContextId,extra,review,mode,workflow,bridge,bootstrap=null,externalModels=null,executionPolicy=null){
|
|
106
112
|
const runtime=extra.get('--runtime')??'codex';
|
|
107
113
|
const selected=resolveProtectedRuntimes(loadConfig({projectRoot:definition.codeProject}),runtime);
|
|
108
114
|
need(review!==null,'review_configuration_required');
|
|
@@ -112,13 +118,18 @@ async function protectedExecutionFor(definition,hostContextId,extra,review,mode,
|
|
|
112
118
|
// Child fix configuration is checked before opening the parent store below.
|
|
113
119
|
const file=extra.get('--protected-config'),info=fs.lstatSync(file);
|
|
114
120
|
need(info.isFile()&&!info.isSymbolicLink()&&info.size<=64*1024,'invalid_protected_config');
|
|
115
|
-
|
|
121
|
+
let config=json(JSON.parse(fs.readFileSync(file,'utf8')));
|
|
122
|
+
if(externalModels){const pair=externalModels.providers[selected.coderRuntime];need(!Object.hasOwn(config,'model')||config.model===pair.model,'external_model_configuration_conflict');need(!Object.hasOwn(config,'effort')||config.effort===pair.effort,'external_model_configuration_conflict');config={...config,...pair};}
|
|
123
|
+
shape(config,['model','checkCommands','timeoutMs',...(externalModels?['effort']:[])]);
|
|
116
124
|
return executionFor(definition,hostContextId,bridge,review,
|
|
117
125
|
extra.has('--allow-review-attempt')?Number(extra.get('--allow-review-attempt')):null,
|
|
118
126
|
workflow,extra.has('--allow-qa'),runtime,{
|
|
119
127
|
...(extra.has('--original-host-context')?{originalHostContextId:extra.get('--original-host-context')}:{}),
|
|
120
128
|
protection:{checkCommands:config.checkCommands,timeoutMs:config.timeoutMs},
|
|
121
|
-
providerDevelopment:{model:config.model,attempt,...selected},
|
|
129
|
+
providerDevelopment:{model:config.model,attempt,...selected,...(externalModels?{effort:config.effort}:{})},
|
|
130
|
+
...(executionPolicy?{executionPolicy}:{}),
|
|
131
|
+
...(externalModels?{externalModels}:{}),
|
|
132
|
+
...(extra.has('--verification-precheck')?{verificationPrecheck:true}:{}),
|
|
122
133
|
...(bootstrap?{bootstrap:{...bootstrap,allowWrite:extra.has('--allow-bootstrap-write')}}:{}),
|
|
123
134
|
});
|
|
124
135
|
}
|
|
@@ -129,6 +140,7 @@ async function protectedExecutionFor(definition,hostContextId,extra,review,mode,
|
|
|
129
140
|
// no migration, journal rewrite, or in-flight provider switch is permitted.
|
|
130
141
|
async function legacyProtectedExecutionFor(definition,hostContextId,extra,review,mode,workflow,bridge,bootstrap=null){
|
|
131
142
|
need((extra.get('--runtime')??'codex')==='codex','protected_runtime_unsupported');
|
|
143
|
+
need(!extra.has('--verification-precheck'),'verification_precheck_unavailable');
|
|
132
144
|
need(review!==null,'review_configuration_required');
|
|
133
145
|
need(['1','2'].includes(extra.get('--allow-provider-development-attempt')),'provider_development_authorization_required');
|
|
134
146
|
const attempt=Number(extra.get('--allow-provider-development-attempt'));
|
|
@@ -159,6 +171,7 @@ function canResumeLegacyProtected(definition,runtime){
|
|
|
159
171
|
}
|
|
160
172
|
|
|
161
173
|
export async function main(argv=process.argv.slice(2),{input=process.stdin,output=process.stdout,error=process.stderr}={}){
|
|
174
|
+
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('Optional --execution-optimizations freezes policy v1 for new runs only; recovery retains the original policy and legacy runs reject retrofit. See docs/execution-optimizations.md.\n');
|
|
162
175
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--original-host-context ID is resume-only: keep the creating session in durable configuration while --host-context remains the real live session. Omit it for same-session resume; a different session must declare the creating session. Equal IDs are equivalent to omission. Parent conversation runs only; legacy protected runs, batch and QA-fix children are unchanged.\n');
|
|
163
176
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('Approved bootstrap feature (0.bootstrap or a single numbered *.bootstrap): --bootstrap-config PATH {selection:null for scaffold, or original cm-init selection for rules} and --allow-bootstrap-write. Original scope must include fixed instruction targets; they are host-written inside the original task effect, checked/reviewed and reloaded. No Git/install/network grant. Optional codeProjects selects disjoint real roots below codeProject; prefix scope/requirements and use protected current-session checks with a declared codeProject per command.\n');
|
|
164
177
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('Protected current-session mode (Codex or Claude; also batch): --protected-conversation-config PATH with {checkCommands,timeoutMs}; timeoutMs bounds check commands and is the reviewer budget only when review-config has no timeoutMs. A review transport timeout with no result can resume once per attempt with fresh review authorization; a result-bearing timeout still requires reconciliation. No extra model call. The current host returns scoped UTF-8 edits (optional mode "0755"/"0644" on written files; new files are 0644); native Codex sandbox applies them and runs the declared checks. Original author runtime, per-attempt Review and QA permissions remain required. Do not combine with --protected-config. The input limit defaults to 64 KiB and may be raised with --input-limit; unavailable/binary changes stop, never switch to direct writes.\n');
|
|
@@ -179,13 +192,20 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
179
192
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('For a QA decision an older host recorded as blocked/host_request_timeout, --rerun-blocked-qa instead re-asks qa_assess once and appends a decision linked by previous_decision_id; history is kept (current hosts report a missed qa_assess window as retryable rejected/qa_decision_timeout and record nothing). --qa-environment-failure REASON (with --rerun-blocked-qa, single line, at most 500 UTF-8 bytes) declares that the non-zero QA command exits of the latest completed FAIL came from the environment: only command exits and logic cases failed solely by them qualify, never browser FAIL or CONTRADICTED; the superseded row records reason, failed_cases and blocked_cases. Every rerun reuses the three-round QA budget. Single-task host only.\n');
|
|
180
193
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--allow-abandon-review: resume 原 run 后发送 abandon_review,request.reason 必须是单行且不超过 500 UTF-8 字节。操作员先确认旧 host 与 review 进程已退出;旗标只消费一次,不写入配置。\n');
|
|
181
194
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--allow-abandon-effect: resume 原 run 后发送 abandon_effect,request.reason 必须是单行且不超过 500 UTF-8 字节。操作员须确认旧 host 和 effect 启动的检查/构建进程均已退出;仅当前会话 develop/complete 且无 task-commit-intent 时可用。\n');
|
|
195
|
+
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--allow-bootstrap-review-recovery: resume 原 run 后发送 bootstrap_review_recover;只在 bootstrap develop 已完成且审查包构建失败时核对现有文件、handoff 与原始证据,并追加恢复记录,不重新派发开发。\n');
|
|
182
196
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--supersede-reviewed-evidence --supersede-reason REASON:仅新建同任务运行;旧运行都已终止且 tasks.md 未勾选时,先在新 journal 记授权,再归档旧审查证据。若保留直接前驱运行留下的代码漂移,可额外使用 --accept-superseded-code-drift;漂移文件会作为新运行的已有代码并记录当前 SHA-256。\n');
|
|
183
197
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--rebind-spec-material --spec-rebind-reason REASON:仅 resume。规格经 cm-prd --change 重新批准后,若本任务的描述、验证要求、验收标准、设计摘录与测试用例都未变,只换绑批准哈希并写 specification-rebound 记录,已有开发与审查结论保留;内容有变则拒绝并列出变化。status 的 spec_drift 会说明是否可换绑。\n');
|
|
184
198
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('当前会话手动驱动请用 scripts/cm-ai-drive.mjs(批次 cm-ai-batch-drive.mjs;修复 cm-fix-drive.mjs;规格 cm-prd-drive.mjs);详情见 skills/cm-ai/references/js-host.md。\n');
|
|
199
|
+
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('External-model mode freezes one model/effort pair per provider. Unknown or invalid external results require reconciliation; automatic retries and abandonment are disabled. See docs/external-models.md.\n');
|
|
185
200
|
if(argv.length===1&&['--help','-h'].includes(argv[0])){output.write(usage+'\n');return 0;}
|
|
186
201
|
let run,bridge;
|
|
187
202
|
try{
|
|
188
203
|
if(argv[0]==='preflight'){
|
|
204
|
+
if([5,7].includes(argv.length)&&argv[1]==='--config'&&argv[3]==='--external-provider'){
|
|
205
|
+
need(argv.length===5||argv[5]==='--external-models-config','invalid_arguments');
|
|
206
|
+
const runtime=argv[4],pair=loadExternalModels(argv[6]).providers[runtime];need(pair,'external_model_setup_required');
|
|
207
|
+
const config=await runReviewPreflight(readRunDefinition(argv[2]),{...pair,runtime});output.write(JSON.stringify({...config,timeoutMs:900000})+'\n');return config.preflight.passed?0:1;
|
|
208
|
+
}
|
|
189
209
|
need((argv.length===5||argv.length===7)&&argv[1]==='--config'&&argv[3]==='--review-model','invalid_arguments');
|
|
190
210
|
const runtime=argv.length===5?'codex':argv[6];
|
|
191
211
|
need(argv.length===5||argv[5]==='--runtime','invalid_arguments');
|
|
@@ -203,8 +223,8 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
203
223
|
const extra=new Map();
|
|
204
224
|
for(let index=8;index<argv.length;index++){
|
|
205
225
|
const name=argv[index];refuse(!extra.has(name),'invalid_arguments',`参数重复:${name}`);
|
|
206
|
-
refuse(['--revise-qa-config','--qa-config-revision-reason','--qa-environment-failure','--supersede-reviewed-evidence','--supersede-reason','--accept-superseded-code-drift','--rebind-spec-material','--spec-rebind-reason','--original-host-context','--bootstrap-config','--allow-bootstrap-write','--protected-conversation-config','--protected-config','--allow-provider-development-attempt','--review-config','--allow-review-attempt','--allow-abandon-review','--allow-abandon-effect','--workflow-config','--allow-qa','--browser-qa','--rerun-unknown-qa','--rerun-blocked-qa','--runtime','--input-limit','--failover','--qa-fix-owner-config','--qa-fix-template-config','--qa-fix-review-config','--allow-qa-fix-start','--auto-qa-fix',...fixLocalPermissions.keys()].includes(name),'invalid_arguments',`未知参数:${name}`);
|
|
207
|
-
if(['--supersede-reviewed-evidence','--accept-superseded-code-drift','--rebind-spec-material','--allow-bootstrap-write','--allow-qa','--allow-abandon-review','--allow-abandon-effect','--rerun-unknown-qa','--rerun-blocked-qa','--failover','--allow-qa-fix-start','--auto-qa-fix',...fixLocalPermissions.keys()].includes(name))extra.set(name,true);
|
|
226
|
+
refuse(['--execution-optimizations','--external-models','--external-models-config','--verification-precheck','--revise-qa-config','--qa-config-revision-reason','--qa-environment-failure','--supersede-reviewed-evidence','--supersede-reason','--accept-superseded-code-drift','--rebind-spec-material','--spec-rebind-reason','--original-host-context','--bootstrap-config','--allow-bootstrap-write','--protected-conversation-config','--protected-config','--allow-provider-development-attempt','--review-config','--allow-review-attempt','--allow-abandon-review','--allow-abandon-effect','--allow-bootstrap-review-recovery','--workflow-config','--allow-qa','--browser-qa','--rerun-unknown-qa','--rerun-blocked-qa','--runtime','--review-runtime','--feature','--input-limit','--failover','--qa-fix-owner-config','--qa-fix-template-config','--qa-fix-review-config','--allow-qa-fix-start','--auto-qa-fix',...fixLocalPermissions.keys()].includes(name),'invalid_arguments',`未知参数:${name}`);
|
|
227
|
+
if(['--execution-optimizations','--external-models','--verification-precheck','--supersede-reviewed-evidence','--accept-superseded-code-drift','--rebind-spec-material','--allow-bootstrap-write','--allow-qa','--allow-abandon-review','--allow-abandon-effect','--allow-bootstrap-review-recovery','--rerun-unknown-qa','--rerun-blocked-qa','--failover','--allow-qa-fix-start','--auto-qa-fix',...fixLocalPermissions.keys()].includes(name))extra.set(name,true);
|
|
208
228
|
else{refuse(typeof argv[index+1]==='string'&&!argv[index+1].startsWith('--'),'invalid_arguments',`${name} 需要一个值`);extra.set(name,argv[++index]);}
|
|
209
229
|
}
|
|
210
230
|
let inputLimit;
|
|
@@ -220,12 +240,13 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
220
240
|
refuse(extra.has('--rebind-spec-material')===extra.has('--spec-rebind-reason')&&(!extra.has('--rebind-spec-material')||argv[4]==='resume'),
|
|
221
241
|
'spec_rebind_unavailable','--rebind-spec-material 只用于 --mode resume,并须同时提供单行 --spec-rebind-reason 原因');
|
|
222
242
|
need(!extra.has('--allow-abandon-effect')||argv[4]==='resume','effect_abandon_unavailable');
|
|
243
|
+
need(!extra.has('--allow-bootstrap-review-recovery')||argv[4]==='resume','bootstrap_review_recovery_unavailable');
|
|
223
244
|
const qaConfigRevision=revisionRequested?{previousWorkflow:readHostWorkflowConfiguration(extra.get('--revise-qa-config')),
|
|
224
245
|
reason:extra.get('--qa-config-revision-reason')}:null;
|
|
225
246
|
const originalHostContextId=extra.get('--original-host-context')??null;
|
|
226
247
|
if(originalHostContextId!==null){need(argv[4]==='resume','original_host_context_unavailable');id(originalHostContextId);}
|
|
227
248
|
if(originalHostContextId===argv[6])extra.delete('--original-host-context');
|
|
228
|
-
|
|
249
|
+
let review=null;
|
|
229
250
|
const workflow=extra.has('--workflow-config')?readHostWorkflowConfiguration(extra.get('--workflow-config')):null;
|
|
230
251
|
let allowedAttempt=null;
|
|
231
252
|
if(extra.has('--allow-review-attempt')){refuse(['1','2'].includes(extra.get('--allow-review-attempt')),'invalid_arguments','--allow-review-attempt 只接受 1 或 2');allowedAttempt=Number(extra.get('--allow-review-attempt'));}
|
|
@@ -241,13 +262,31 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
241
262
|
need(!extra.has('--auto-qa-fix')||(extra.has('--qa-fix-template-config')&&extra.has('--allow-qa-fix-start')),'qa_fix_auto_authorization_required');
|
|
242
263
|
need(![...fixLocalPermissions.keys()].some(flag=>extra.has(flag))||extra.has('--allow-qa-fix-start'),'qa_fix_start_authorization_required');
|
|
243
264
|
need(!extra.has('--allow-provider-development-attempt')||extra.has('--protected-config'),'protected_configuration_required');
|
|
265
|
+
refuse(!(extra.has('--review-runtime')&&(extra.has('--protected-config')||extra.has('--external-models'))),'invalid_arguments',
|
|
266
|
+
'--review-runtime 只用于普通当前会话宿主;--protected-config 与 --external-models 按 roles 自行选择审查端');
|
|
244
267
|
refuse(!(extra.has('--protected-config')&&extra.has('--protected-conversation-config')),'invalid_arguments','--protected-config 与 --protected-conversation-config 不能同时使用');
|
|
245
268
|
const protection=extra.has('--protected-conversation-config')?readConversationProtection(extra.get('--protected-conversation-config')):null;
|
|
246
269
|
const bootstrap=extra.has('--bootstrap-config')?readBootstrapConfiguration(extra.get('--bootstrap-config')):null;
|
|
247
270
|
need(!extra.has('--allow-bootstrap-write')||bootstrap!==null,'bootstrap_configuration_required');
|
|
248
271
|
// Checked before the definition is read so the conflict is reported on its own.
|
|
249
272
|
need(!(extra.has('--failover')&&extra.has('--protected-config')),'failover_unsupported_in_protected_mode');
|
|
250
|
-
|
|
273
|
+
let definition=readRunDefinition(argv[2]);
|
|
274
|
+
// --feature binds an explicit batch choice into the run definition, exactly
|
|
275
|
+
// as a printed featureSelection does; resume must repeat it (fingerprint).
|
|
276
|
+
if(extra.has('--feature')){
|
|
277
|
+
refuse(extra.get('--feature')===definition.feature&&(!definition.featureSelection
|
|
278
|
+
||definition.featureSelection.feature===definition.feature),'invalid_arguments',
|
|
279
|
+
`--feature ${extra.get('--feature')} 必须与运行定义的 feature ${definition.feature} 一致`);
|
|
280
|
+
definition={...definition,featureSelection:{version:1,feature:definition.feature}};
|
|
281
|
+
}
|
|
282
|
+
// Before any frozen model/policy configuration, execution or journal write.
|
|
283
|
+
if(argv[4]==='create'&&bootstrap===null)assertCreatableScope(definition.scope);
|
|
284
|
+
const boundRuntime=extra.get('--runtime')??'codex';
|
|
285
|
+
const routes=extra.has('--protected-config')?resolveProtectedRuntimes(loadConfig({projectRoot:definition.codeProject}),boundRuntime):{reviewerRuntime:boundRuntime};
|
|
286
|
+
const executionPolicy=readLaunchExecutionPolicy({definition,mode:argv[4],enabled:extra.has('--execution-optimizations')});
|
|
287
|
+
const externalModels=readLaunchExternalModels({definition,mode:argv[4],enabled:extra.has('--external-models'),inputFile:extra.get('--external-models-config'),providers:[routes.coderRuntime,routes.reviewerRuntime].filter(Boolean)});
|
|
288
|
+
need(!externalModels||!extra.has('--failover'),'external_model_failover_unsupported');
|
|
289
|
+
review=extra.has('--review-config')?reviewConfiguration(extra.get('--review-config'),externalModels?.providers[routes.reviewerRuntime]??null):null;
|
|
251
290
|
// Launch-time capability assertion. See host-workflow-capabilities: this is a
|
|
252
291
|
// fresh declaration, not a probe the host performs.
|
|
253
292
|
readBrowserCapability(extra.get('--browser-qa'),
|
|
@@ -288,10 +327,10 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
288
327
|
refuse(argv[4]!=='create'||review!==null,'review_configuration_required',
|
|
289
328
|
'create 必须带 --review-config:审查配置写进运行指纹,resume 时不能再补。先用 cm-ai-host.mjs preflight --config 运行定义 --review-model 模型 --runtime 端 生成 review.json;是否真正派发审查仍由 --allow-review-attempt 单独授权');
|
|
290
329
|
let execution;
|
|
291
|
-
if(argv[4]==='resume'&&!extra.has('--original-host-context')&&extra.has('--protected-config')&&canResumeLegacyProtected(definition,runtime)){
|
|
330
|
+
if(argv[4]==='resume'&&!extra.has('--original-host-context')&&extra.has('--protected-config')&&!externalModels&&!executionPolicy&&canResumeLegacyProtected(definition,runtime)){
|
|
292
331
|
try{
|
|
293
332
|
execution=await legacyProtectedExecutionFor(definition,argv[6],extra,review,argv[4],workflow,bridge,bootstrap);
|
|
294
|
-
run=await openControlRun(definition,argv[4],execution,{qaConfigRevision,rerunUnknownQa:extra.has('--rerun-unknown-qa'),rerunBlockedQa:extra.has('--rerun-blocked-qa'),qaEnvironmentFailure:extra.get('--qa-environment-failure')??null,supersedeReason:extra.get('--supersede-reason')??null,acceptSupersededCodeDrift:extra.has('--accept-superseded-code-drift'),allowAbandonReview:extra.has('--allow-abandon-review'),allowAbandonEffect:extra.has('--allow-abandon-effect'),specRebindReason:extra.get('--spec-rebind-reason')??null});
|
|
333
|
+
run=await openControlRun(definition,argv[4],execution,{qaConfigRevision,rerunUnknownQa:extra.has('--rerun-unknown-qa'),rerunBlockedQa:extra.has('--rerun-blocked-qa'),qaEnvironmentFailure:extra.get('--qa-environment-failure')??null,supersedeReason:extra.get('--supersede-reason')??null,acceptSupersededCodeDrift:extra.has('--accept-superseded-code-drift'),allowAbandonReview:extra.has('--allow-abandon-review'),allowAbandonEffect:extra.has('--allow-abandon-effect'),allowBootstrapReviewRecovery:extra.has('--allow-bootstrap-review-recovery'),specRebindReason:extra.get('--spec-rebind-reason')??null});
|
|
295
334
|
error.write('cm-ai-host: resumed original Codex protected execution after exact fingerprint validation.\n');
|
|
296
335
|
}catch(cause){
|
|
297
336
|
if(!['fingerprint_mismatch','tool_preflight_missing'].includes(cause.code))throw cause;
|
|
@@ -300,10 +339,10 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
300
339
|
}
|
|
301
340
|
if(!run){
|
|
302
341
|
execution=extra.has('--protected-config')
|
|
303
|
-
?await protectedExecutionFor(definition,argv[6],extra,review,argv[4],workflow,bridge,bootstrap)
|
|
342
|
+
?await protectedExecutionFor(definition,argv[6],extra,review,argv[4],workflow,bridge,bootstrap,externalModels,executionPolicy)
|
|
304
343
|
:executionFor(definition,argv[6],bridge,review,allowedAttempt,workflow,extra.has('--allow-qa'),runtime,
|
|
305
|
-
{...(extra.has('--original-host-context')?{originalHostContextId:extra.get('--original-host-context')}:{}),...(protection?{protection}:{}),...(bootstrap?{bootstrap:{...bootstrap,allowWrite:extra.has('--allow-bootstrap-write')}}:{})});
|
|
306
|
-
run=await openControlRun(definition,argv[4],execution,{qaConfigRevision,rerunUnknownQa:extra.has('--rerun-unknown-qa'),rerunBlockedQa:extra.has('--rerun-blocked-qa'),qaEnvironmentFailure:extra.get('--qa-environment-failure')??null,supersedeReason:extra.get('--supersede-reason')??null,acceptSupersededCodeDrift:extra.has('--accept-superseded-code-drift'),allowAbandonReview:extra.has('--allow-abandon-review'),allowAbandonEffect:extra.has('--allow-abandon-effect'),specRebindReason:extra.get('--spec-rebind-reason')??null});
|
|
344
|
+
{...(extra.has('--review-runtime')?{reviewRuntime:extra.get('--review-runtime')}:{}),...(executionPolicy?{executionPolicy}:{}),...(externalModels?{externalModels}:{}),...(extra.has('--verification-precheck')?{verificationPrecheck:true}:{}),...(extra.has('--original-host-context')?{originalHostContextId:extra.get('--original-host-context')}:{}),...(protection?{protection}:{}),...(bootstrap?{bootstrap:{...bootstrap,allowWrite:extra.has('--allow-bootstrap-write')}}:{})});
|
|
345
|
+
run=await openControlRun(definition,argv[4],execution,{qaConfigRevision,rerunUnknownQa:extra.has('--rerun-unknown-qa'),rerunBlockedQa:extra.has('--rerun-blocked-qa'),qaEnvironmentFailure:extra.get('--qa-environment-failure')??null,supersedeReason:extra.get('--supersede-reason')??null,acceptSupersededCodeDrift:extra.has('--accept-superseded-code-drift'),allowAbandonReview:extra.has('--allow-abandon-review'),allowAbandonEffect:extra.has('--allow-abandon-effect'),allowBootstrapReviewRecovery:extra.has('--allow-bootstrap-review-recovery'),specRebindReason:extra.get('--spec-rebind-reason')??null});
|
|
307
346
|
}
|
|
308
347
|
if(run.blocked){output.write(JSON.stringify({outcome:'blocked',admission:run.blocked})+'\n');return 1;}
|
|
309
348
|
if(hasFix){
|
|
@@ -313,15 +352,24 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
313
352
|
if(templated)need(digest(fix.identity)===digest(definition.identity),'qa_fix_source_mismatch');
|
|
314
353
|
if(extra.has('--allow-qa-fix-start'))need((fix.configuration.runtime??'codex')===runtime,'qa_fix_host_mismatch');
|
|
315
354
|
const fixPermissions=[...fixLocalPermissions].filter(([flag])=>extra.has(flag)).map(([,permission])=>permission);
|
|
316
|
-
const
|
|
355
|
+
const fixRuntime=fix.configuration.runtime??'codex';
|
|
356
|
+
const fixModels=externalModels?selectExternalModels(externalModels,[fixRuntime]):null;
|
|
357
|
+
const fixReview=extra.has('--qa-fix-review-config')?reviewConfiguration(extra.get('--qa-fix-review-config'),fixModels?.providers[fixRuntime]??null):null;
|
|
317
358
|
need(!fixPermissions.includes('--allow-test-author')||(fix.configuration.testAuthor&&fixReview),'test_author_configuration_required');
|
|
318
359
|
need(!fixPermissions.includes('--allow-repair')||(fix.configuration.repair&&fixReview),'repair_configuration_required');
|
|
319
360
|
const fixReviewHost=createFixReviewHost({codeProject:definition.codeProject,
|
|
320
361
|
hostContextId:argv[6],runtime:fix.configuration.runtime??'codex',
|
|
321
|
-
review:fixReview,permissions:fixPermissions});
|
|
322
|
-
if(
|
|
362
|
+
review:fixReview,permissions:fixPermissions,externalModels:fixModels,executionPolicy,specsDir:definition.specsDir});
|
|
363
|
+
if(fixModels||executionPolicy){
|
|
364
|
+
if(fixModels&&fix.configuration.causeReview)need(fix.configuration.causeReview.requestedModel===fixModels.providers[fixRuntime].model&&fix.configuration.causeReview.provider===fixRuntime,'external_model_pair_conflict');
|
|
365
|
+
if(fixReview){
|
|
366
|
+
// Preserve explicit reviewer contexts/exclusions; changing them changes the durable run.
|
|
367
|
+
need(!fix.configuration.causeReview||digest(fix.configuration.causeReview)===digest(fixReviewHost.reviewer),'qa_fix_review_configuration_mismatch');
|
|
368
|
+
fix={...fix,configuration:{...fix.configuration,causeReview:fixReviewHost.reviewer,...(fixModels?{externalModels:fixModels}:{})}};
|
|
369
|
+
}
|
|
370
|
+
}else if(fixReview)need(digest(fix.configuration.causeReview??null)===digest(fixReviewHost.reviewer),'qa_fix_review_configuration_mismatch');
|
|
323
371
|
const host=createQaFixOwnerHost({parent:run,hostContextId:argv[6],parentHostContextId:execution.configuration.hostContextId,...(templated?{template:fix}:{fix}),reopenParent:()=>openControlRun(definition,'resume',execution),
|
|
324
|
-
fixPermissions,fixAuthorities:{authority:fixReviewHost.authority,finalAuthority:fixReviewHost.finalAuthority},
|
|
372
|
+
externalModels:fixModels,executionPolicy,fixPermissions,fixAuthorities:{authority:fixReviewHost.authority,finalAuthority:fixReviewHost.finalAuthority},
|
|
325
373
|
allowStart:extra.has('--allow-qa-fix-start'),autoFix:extra.has('--auto-qa-fix'),fixExecution:{bridge,...fixReviewHost.execution,
|
|
326
374
|
prepare:createFixLearningPreparation({bridge,codeProject:definition.codeProject,
|
|
327
375
|
applicableAgentFiles:fix.configuration.applicableAgentFiles??[]})}});
|
|
@@ -335,6 +383,9 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
335
383
|
finally{if(rawMode)input.setRawMode(false);}
|
|
336
384
|
return 0;
|
|
337
385
|
}catch(cause){
|
|
386
|
+
const preflightDiagnostic=argv[0]==='preflight'&&['EPERM','EACCES'].includes(cause?.code)
|
|
387
|
+
&&cause?.syscall==='listen'&&cause?.address==='127.0.0.1'
|
|
388
|
+
?{operation:'listen',systemCode:cause.code,address:'loopback'}:null;
|
|
338
389
|
const code=typeof cause?.code==='string'&&(/^[a-z][a-z0-9_]{0,63}$/.test(cause.code)
|
|
339
390
|
||cause.code.startsWith('invalid_config: '))?cause.code:'host_launch_failed';
|
|
340
391
|
const snapshotReason=['out_of_scope','unsupported_file','limit_exceeded','package_mismatch'].includes(code)
|
|
@@ -347,7 +398,8 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
347
398
|
if(snapshotReason)error.write(`[host] ${snapshotReason}\n`);
|
|
348
399
|
const limitReason=code==='request_too_large'?inputLimitReason(cause.limit):null;
|
|
349
400
|
if(limitReason)error.write(`[host] request_too_large: ${limitReason}\n`);
|
|
350
|
-
error.write(JSON.stringify({error:{code,...(snapshotReason?{reason:snapshotReason}:{}),...(limitReason?{reason:limitReason}:{}),...(reason?{reason}:{})
|
|
401
|
+
error.write(JSON.stringify({error:{code,...(snapshotReason?{reason:snapshotReason}:{}),...(limitReason?{reason:limitReason}:{}),...(reason?{reason}:{}),
|
|
402
|
+
...(preflightDiagnostic?{diagnostic:preflightDiagnostic}:{})}})+'\n');return 1;
|
|
351
403
|
}finally{bridge?.close();run?.close();}
|
|
352
404
|
}
|
|
353
405
|
if(process.argv[1]&&fs.realpathSync(process.argv[1])===fileURLToPath(import.meta.url))process.exitCode=await main();
|
|
@@ -184,6 +184,23 @@ test('host create reports the offending unsupported file on stderr before transp
|
|
|
184
184
|
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
185
185
|
});
|
|
186
186
|
|
|
187
|
+
test('host create refuses a scope with AGENTS.md and lists the protected paths before any journal exists',async()=>{
|
|
188
|
+
const f=fixture(),lines=[],output=[];
|
|
189
|
+
try{
|
|
190
|
+
const definition=JSON.parse(fs.readFileSync(f.config,'utf8'));
|
|
191
|
+
fs.writeFileSync(f.config,JSON.stringify({...definition,scope:['target.mjs','AGENTS.md','.claude/rules/security.md']}));
|
|
192
|
+
fs.writeFileSync(path.join(f.codeProject,'AGENTS.md'),'# rules\n');
|
|
193
|
+
const exit=await hostMain(launchArgs(f),{input:{},output:{write(value){output.push(value);}},error:{write(value){lines.push(value);}}});
|
|
194
|
+
assert.equal(exit,1);assert.deepEqual(output,[]);
|
|
195
|
+
const error=JSON.parse(lines.join('').trim().split('\n').at(-1)).error;
|
|
196
|
+
assert.equal(error.code,'protected_scope');
|
|
197
|
+
assert.match(error.reason,/AGENTS\.md、\.claude\/rules\/security\.md/);
|
|
198
|
+
assert.doesNotMatch(error.reason,/target\.mjs/);
|
|
199
|
+
// No init, no intent, no execution directory, no review record of any kind.
|
|
200
|
+
assert.equal(fs.existsSync(path.join(f.specsDir,'.reviews')),false);
|
|
201
|
+
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
202
|
+
});
|
|
203
|
+
|
|
187
204
|
function runCli(f,mode,action='create'){
|
|
188
205
|
return new Promise((resolve,reject)=>{
|
|
189
206
|
const args=[...launchArgs(f)];args[4]=action;
|
|
@@ -1250,3 +1267,74 @@ test('#11 #31 protected driver deletes, sets the executable bit, creates new fil
|
|
|
1250
1267
|
assert.equal(changes.get('new/Legacy.swift').after.mode,0o644);
|
|
1251
1268
|
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
1252
1269
|
});
|
|
1270
|
+
|
|
1271
|
+
// Explicit batch choice (2026-10-06 AI潮 6.api-native-reading before 5.author-column).
|
|
1272
|
+
const withEarlierPendingFeature=f=>{
|
|
1273
|
+
const early=path.join(f.specsDir,'0.early');fs.mkdirSync(early);
|
|
1274
|
+
for(const name of ['requirements.md','design.md'])fs.writeFileSync(path.join(early,name),'# Early\n');
|
|
1275
|
+
fs.writeFileSync(path.join(early,'tasks.md'),'- [ ] T-001: earlier batch, after this one\n');
|
|
1276
|
+
fs.writeFileSync(path.join(f.specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:['0.early','1.work'],specFiles:buildManifest(f.specsDir)}));
|
|
1277
|
+
};
|
|
1278
|
+
const serveOnce=(f,extra,mode='create')=>{
|
|
1279
|
+
const args=[...launchArgs(f)];args[4]=mode;
|
|
1280
|
+
const out=spawnSync(process.execPath,[cli,...args,...extra],{encoding:'utf8',timeout:20000,
|
|
1281
|
+
input:[request('status')].map(JSON.stringify).join('\n')+'\n'});
|
|
1282
|
+
return {...out,rows:out.stdout.trim().split('\n').filter(Boolean).map(JSON.parse)};
|
|
1283
|
+
};
|
|
1284
|
+
test('host --feature creates a later approved feature run; without it the original task_selection_mismatch stays',()=>{
|
|
1285
|
+
const f=fixture();
|
|
1286
|
+
try{
|
|
1287
|
+
withEarlierPendingFeature(f);
|
|
1288
|
+
const refused=serveOnce(f,[]);
|
|
1289
|
+
assert.equal(refused.status,1);assert.match(refused.stderr,/task_selection_mismatch/);assert.match(refused.stderr,/--feature 1\.work/);
|
|
1290
|
+
const wrong=serveOnce(f,['--feature','0.early']);
|
|
1291
|
+
assert.equal(wrong.status,1);assert.match(wrong.stderr,/invalid_arguments/);
|
|
1292
|
+
assert.equal(fs.existsSync(path.join(f.specsDir,'.reviews','.execution',identity.runId)),false);
|
|
1293
|
+
const created=serveOnce(f,['--feature','1.work']);
|
|
1294
|
+
assert.equal(created.status,0,created.stderr);
|
|
1295
|
+
assert.equal(created.rows[0].type,'host_ready');
|
|
1296
|
+
assert.equal(created.rows.find(row=>row.requestId==='status').result.identity.taskId,'T-001');
|
|
1297
|
+
const resumed=serveOnce(f,['--feature','1.work'],'resume');
|
|
1298
|
+
assert.equal(resumed.status,0,resumed.stderr);assert.equal(resumed.rows[0].type,'host_ready');
|
|
1299
|
+
// The choice is bound into the run: resuming without it is a different run.
|
|
1300
|
+
const unbound=serveOnce(f,[],'resume');
|
|
1301
|
+
assert.equal(unbound.status,1);assert.match(unbound.stderr,/fingerprint_mismatch/);
|
|
1302
|
+
assert.match(fs.readFileSync(path.join(f.specsDir,'0.early','tasks.md'),'utf8'),/- \[ \] T-001/);
|
|
1303
|
+
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
1304
|
+
});
|
|
1305
|
+
|
|
1306
|
+
// Kept from the 0.16.6 project patch: runs T-001..T-003 of that batch were
|
|
1307
|
+
// created with --runtime codex --review-runtime claude and resume only with it.
|
|
1308
|
+
const crossToolRoles='version: 1\nruntimes: {available: both}\nroles:\n coder: {adapter: codex-cli, source: subscription}\n reviewer: {adapter: claude-cli, source: subscription}\n';
|
|
1309
|
+
test('--review-runtime binds the other tool as reviewer and must be repeated on resume',async()=>{
|
|
1310
|
+
const f=fixture(),bridge=createHostToolBridge();
|
|
1311
|
+
try{
|
|
1312
|
+
fs.writeFileSync(path.join(f.codeProject,'.cm-workflow.yml'),crossToolRoles);
|
|
1313
|
+
const definition=readRunDefinition(f.config);
|
|
1314
|
+
const {claudeReviewFingerprint}=await import('../runtime/js/cm-ai/worker-claude.mjs');
|
|
1315
|
+
const model='fixture';const review={model,disabledSkills:[],preflight:{passed:true,provider:'claude',
|
|
1316
|
+
config_fingerprint:claudeReviewFingerprint({cwd:f.codeProject,model}),prompt_transport:'stdin'}};
|
|
1317
|
+
const make=options=>createConversationExecution(definition,'native-host-fixture',bridge,review,null,null,false,'codex',options);
|
|
1318
|
+
const original=make({reviewRuntime:'claude'});
|
|
1319
|
+
assert.equal(original.developer.provider,'codex');assert.equal(original.reviewers[0].provider,'claude');
|
|
1320
|
+
assert.equal(original.configuration.reviewRuntime,'claude');
|
|
1321
|
+
const first=await openControlRun(definition,'create',original);first.close();
|
|
1322
|
+
const resumed=await openControlRun(definition,'resume',make({reviewRuntime:'claude'}));resumed.close();
|
|
1323
|
+
await assert.rejects(openControlRun(definition,'resume',make({})),{code:'fingerprint_mismatch'});
|
|
1324
|
+
assert.throws(()=>make({reviewRuntime:'codex'}),{code:'runtime_selection_mismatch'});
|
|
1325
|
+
assert.throws(()=>make({reviewRuntime:'other'}),{code:'invalid_runtime'});
|
|
1326
|
+
assert.throws(()=>createConversationExecution(definition,'native-host-fixture',bridge,{...review,preflight:{}},1,null,false,'codex',{reviewRuntime:'claude'}),{code:'tool_preflight_missing'});
|
|
1327
|
+
}finally{bridge.close();fs.rmSync(f.root,{recursive:true,force:true});}
|
|
1328
|
+
});
|
|
1329
|
+
test('ordinary CLI accepts --review-runtime claude under a Codex host and refuses an invalid runtime before any journal',()=>{
|
|
1330
|
+
for(const reviewRuntime of ['claude','other']){
|
|
1331
|
+
const f=fixture();
|
|
1332
|
+
try{
|
|
1333
|
+
fs.writeFileSync(path.join(f.codeProject,'.cm-workflow.yml'),crossToolRoles);
|
|
1334
|
+
const out=serveOnce(f,['--runtime','codex','--review-runtime',reviewRuntime]);
|
|
1335
|
+
if(reviewRuntime==='claude'){assert.equal(out.status,0,out.stderr);assert.equal(out.rows[0].type,'host_ready');}
|
|
1336
|
+
else{assert.equal(out.status,1);assert.match(out.stderr,/invalid_runtime/);
|
|
1337
|
+
assert.equal(fs.existsSync(path.join(f.specsDir,'.reviews','.execution',identity.runId)),false);}
|
|
1338
|
+
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
1339
|
+
}
|
|
1340
|
+
});
|