@aibyzero/cm-workflow 0.12.0 → 0.13.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.codex-plugin/plugin.json +1 -1
- package/AGENTS.md +1 -0
- package/CHANGELOG.md +60 -1
- package/README.md +36 -3
- package/VERSION +1 -1
- package/compat/claude-commands/cm-runtime.md +3 -0
- package/docs/installation.md +58 -1
- package/docs/js-workflow-control.md +63 -6
- package/docs/runtime-failover.md +97 -0
- package/docs/user-guide.md +50 -1
- package/install-codex.sh +5 -0
- package/install.ps1 +10 -2
- package/install.sh +5 -0
- package/package.json +2 -1
- package/runtime/js/cm-ai/claude-developer-proposal.schema.json +151 -0
- package/runtime/js/cm-ai/claude-review-stream.mjs +69 -8
- package/runtime/js/cm-ai/claude-tool-preview.mjs +6 -4
- package/runtime/js/cm-ai/cm-ai-admission.mjs +38 -16
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +44 -17
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +105 -12
- package/runtime/js/cm-ai/codex-config.mjs +6 -0
- package/runtime/js/cm-ai/codex-review-adapter.mjs +6 -2
- package/runtime/js/cm-ai/developer-adapter.mjs +41 -16
- package/runtime/js/cm-ai/durable-runner-state.mjs +72 -15
- package/runtime/js/cm-ai/effect-contract.mjs +10 -1
- package/runtime/js/cm-ai/fix-code-association.mjs +4 -1
- package/runtime/js/cm-ai/host-conversation-execution.mjs +112 -27
- package/runtime/js/cm-ai/host-documentation.mjs +4 -2
- package/runtime/js/cm-ai/host-qa-executor.mjs +17 -4
- package/runtime/js/cm-ai/host-qa-policy.mjs +6 -3
- package/runtime/js/cm-ai/host-role-routing.mjs +9 -5
- package/runtime/js/cm-ai/host-tool-bridge.mjs +10 -7
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +9 -4
- package/runtime/js/cm-ai/host.mjs +1 -1
- package/runtime/js/cm-ai/provider-review-observation.mjs +8 -4
- package/runtime/js/cm-ai/qa-attachment.mjs +30 -0
- package/runtime/js/cm-ai/review-package.mjs +76 -18
- package/runtime/js/cm-ai/review-runner.mjs +15 -3
- package/runtime/js/cm-ai/runtime-failover.mjs +75 -0
- package/runtime/js/cm-ai/specification-material.mjs +98 -0
- package/runtime/js/cm-ai/task-runner.mjs +57 -20
- package/runtime/js/cm-ai/worker-claude-developer.mjs +174 -0
- package/runtime/js/cm-ai/worker-claude.mjs +18 -5
- package/runtime/js/cm-ai/worker-codex-developer.mjs +15 -4
- package/runtime/js/cm-ai/worker-codex.mjs +8 -12
- package/runtime/js/cm-init/draft-generation.mjs +24 -4
- package/runtime/js/cm-init/draft-inspection.mjs +29 -1
- package/runtime/js/cm-prd/session.mjs +19 -2
- package/runtime/js/cm-prd/summary.mjs +46 -20
- package/runtime/review.md +11 -1
- package/runtime/workflow-config.md +39 -2
- package/runtime/workflow-routing.md +6 -1
- package/scripts/cm-ai-admission.test.mjs +99 -0
- package/scripts/cm-ai-batch-host.test.mjs +4 -1
- package/scripts/cm-ai-batch-run.test.mjs +7 -1
- package/scripts/cm-ai-bootstrap.test.mjs +9 -2
- package/scripts/cm-ai-fix-integration.test.mjs +2 -1
- package/scripts/cm-ai-host.mjs +81 -12
- package/scripts/cm-ai-host.test.mjs +527 -6
- package/scripts/cm-ai-multi-root.test.mjs +16 -4
- package/scripts/cm-ai-nested-execution.test.mjs +18 -5
- package/scripts/cm-ai-review-timeout.test.mjs +226 -0
- package/scripts/cm-ai-run.mjs +40 -13
- package/scripts/cm-ai-run.test.mjs +45 -9
- package/scripts/cm-check-host.test.mjs +8 -2
- package/scripts/cm-check-runtime.sh +51 -1
- package/scripts/cm-claude-developer-worker.test.mjs +236 -0
- package/scripts/cm-claude-probe.test.mjs +64 -1
- package/scripts/cm-claude-review-stream.test.mjs +236 -1
- package/scripts/cm-claude-worker.test.mjs +110 -1
- package/scripts/cm-codex-developer-adapter.test.mjs +50 -2
- package/scripts/cm-codex-developer-worker.test.mjs +84 -1
- package/scripts/cm-codex-review-progress.test.mjs +34 -6
- package/scripts/cm-failover.mjs +288 -0
- package/scripts/cm-failover.test.mjs +184 -0
- package/scripts/cm-fix-host-review.test.mjs +7 -1
- package/scripts/cm-host-qa-executor.test.mjs +277 -0
- package/scripts/cm-host-tool-bridge.test.mjs +31 -0
- package/scripts/cm-init-draft-generation.test.mjs +62 -0
- package/scripts/cm-init-draft-inspection.test.mjs +76 -0
- package/scripts/cm-init-host.mjs +4 -4
- package/scripts/cm-init-host.test.mjs +12 -7
- package/scripts/cm-init-session.test.mjs +50 -0
- package/scripts/cm-log-event.mjs +34 -5
- package/scripts/cm-prd-completion.test.mjs +9 -3
- package/scripts/cm-prd-host.mjs +39 -3
- package/scripts/cm-prd-host.test.mjs +52 -0
- package/scripts/cm-prd-review-gate.mjs +11 -2
- package/scripts/cm-prd-review-gate.test.mjs +62 -0
- package/scripts/cm-prd-session-recovery.test.mjs +167 -0
- package/scripts/cm-prd-summary.test.mjs +147 -0
- package/scripts/cm-review-dependency-snapshot.test.mjs +10 -0
- package/scripts/cm-review-inventory.test.mjs +189 -0
- package/scripts/cm-review-schema.test.mjs +35 -1
- package/scripts/cm-review-scope-recovery.test.mjs +63 -0
- package/scripts/cm-runtime-edit.mjs +104 -0
- package/scripts/cm-runtime-failover.test.mjs +130 -0
- package/scripts/cm-runtime-i18n.mjs +32 -0
- package/scripts/cm-runtime-install.mjs +68 -0
- package/scripts/cm-runtime.mjs +141 -0
- package/scripts/cm-runtime.test.mjs +218 -0
- package/scripts/cm-spec-manifest.mjs +24 -21
- package/scripts/cm-spec-manifest.test.mjs +19 -0
- package/scripts/cm-workflow-config.mjs +113 -5
- package/scripts/cm-workflow-config.test.mjs +124 -1
- package/scripts/fixtures/prd-review-gate-python-oracle.py +18 -2
- package/scripts/test-cm-prd-review-gate.py +30 -0
- package/scripts/test-shell-compat.sh +34 -0
- package/scripts/validate-public-repo.py +5 -0
- package/skills/cm-ai/references/N4-review.md +5 -4
- package/skills/cm-ai/references/js-host.md +36 -2
- package/skills/cm-check/SKILL.md +7 -3
- package/skills/cm-init/SKILL.md +4 -0
- package/skills/cm-init/references/js-host.md +2 -0
- package/skills/cm-init/references/runtime-declaration.md +26 -0
- package/skills/cm-prd/SKILL.md +3 -3
- package/skills/cm-prd/references/js-change-recovery.md +24 -3
- package/skills/cm-prd/references/summary-card.md +7 -0
- package/skills/cm-runtime/SKILL.md +53 -0
- package/templates/auto-update/cm-update.sh +1 -1
- package/templates/cm-workflow.yml +16 -0
package/scripts/cm-ai-host.mjs
CHANGED
|
@@ -12,6 +12,7 @@ import {createQaFixOwnerHost} from '../runtime/js/cm-ai/host-qa-fix-owner.mjs';
|
|
|
12
12
|
import {createFixLearningPreparation} from '../runtime/js/cm-fix/learning.mjs';
|
|
13
13
|
import {createFixReviewHost} from '../runtime/js/cm-fix/host-review.mjs';
|
|
14
14
|
import {createHostReviewAuthority} from '../runtime/js/cm-ai/host-review-authority.mjs';
|
|
15
|
+
import {loadConfig,declaredRuntimes,resolveProtectedRuntimes} from './cm-workflow-config.mjs';
|
|
15
16
|
import {readHostWorkflowConfiguration} from '../runtime/js/cm-ai/host-workflow-capabilities.mjs';
|
|
16
17
|
import {digest,json,need,shape} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
17
18
|
export {executionFor as createConversationExecution,reviewConfiguration as readConversationReviewConfiguration};
|
|
@@ -28,7 +29,7 @@ const fixLocalPermissions=new Map(['red-test','baseline','regression','learning-
|
|
|
28
29
|
'test-author','repair','cause-review','final-review']
|
|
29
30
|
.map(name=>[`--allow-qa-fix-${name}`,`--allow-${name}`]));
|
|
30
31
|
|
|
31
|
-
const usage='cm-ai-host.mjs serve --config PATH --mode create|resume --host-context ID --allow-development [--runtime codex|claude] [--review-config PATH] [--allow-review-attempt 1|2] [--workflow-config PATH] [--allow-qa]\ncm-ai-host.mjs preflight --config PATH --review-model MODEL [--runtime codex|claude] (synthetic loopback only)';
|
|
32
|
+
const usage='cm-ai-host.mjs serve --config PATH --mode create|resume --host-context ID --allow-development [--runtime codex|claude] [--failover] [--review-config PATH] [--allow-review-attempt 1|2] [--workflow-config PATH] [--allow-qa]\ncm-ai-host.mjs preflight --config PATH --review-model MODEL [--runtime codex|claude] (synthetic loopback only)';
|
|
32
33
|
|
|
33
34
|
function reviewConfiguration(file){
|
|
34
35
|
const info=fs.lstatSync(file);
|
|
@@ -43,6 +44,30 @@ function reviewConfiguration(file){
|
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
async function protectedExecutionFor(definition,hostContextId,extra,review,mode,workflow,bridge,bootstrap=null){
|
|
47
|
+
const runtime=extra.get('--runtime')??'codex';
|
|
48
|
+
const selected=resolveProtectedRuntimes(loadConfig({projectRoot:definition.codeProject}),runtime);
|
|
49
|
+
need(review!==null,'review_configuration_required');
|
|
50
|
+
need(['1','2'].includes(extra.get('--allow-provider-development-attempt')),'provider_development_authorization_required');
|
|
51
|
+
const attempt=Number(extra.get('--allow-provider-development-attempt'));
|
|
52
|
+
need(mode!=='create'||attempt===1,'invalid_development_attempt');
|
|
53
|
+
// Child fix configuration is checked before opening the parent store below.
|
|
54
|
+
const file=extra.get('--protected-config'),info=fs.lstatSync(file);
|
|
55
|
+
need(info.isFile()&&!info.isSymbolicLink()&&info.size<=64*1024,'invalid_protected_config');
|
|
56
|
+
const config=json(JSON.parse(fs.readFileSync(file,'utf8')));shape(config,['model','checkCommands','timeoutMs']);
|
|
57
|
+
return executionFor(definition,hostContextId,bridge,review,
|
|
58
|
+
extra.has('--allow-review-attempt')?Number(extra.get('--allow-review-attempt')):null,
|
|
59
|
+
workflow,extra.has('--allow-qa'),runtime,{
|
|
60
|
+
protection:{checkCommands:config.checkCommands,timeoutMs:config.timeoutMs},
|
|
61
|
+
providerDevelopment:{model:config.model,attempt,...selected},
|
|
62
|
+
...(bootstrap?{bootstrap:{...bootstrap,allowWrite:extra.has('--allow-bootstrap-write')}}:{}),
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
// Existing Codex-only runs retain their exact configuration/context identities.
|
|
68
|
+
// A successful original fingerprint check is the sole authority for this path;
|
|
69
|
+
// no migration, journal rewrite, or in-flight provider switch is permitted.
|
|
70
|
+
async function legacyProtectedExecutionFor(definition,hostContextId,extra,review,mode,workflow,bridge,bootstrap=null){
|
|
46
71
|
need((extra.get('--runtime')??'codex')==='codex','protected_runtime_unsupported');
|
|
47
72
|
need(review!==null,'review_configuration_required');
|
|
48
73
|
need(['1','2'].includes(extra.get('--allow-provider-development-attempt')),'provider_development_authorization_required');
|
|
@@ -66,18 +91,27 @@ async function protectedExecutionFor(definition,hostContextId,extra,review,mode,
|
|
|
66
91
|
authorizeDevelopment:request=>({status:request.identity.attempt===attempt
|
|
67
92
|
&&digest({...request.identity,attempt:1})===digest(definition.identity)?'approved':'denied'})});
|
|
68
93
|
}
|
|
69
|
-
|
|
94
|
+
function canResumeLegacyProtected(definition,runtime){
|
|
95
|
+
if(runtime!=='codex')return false;
|
|
96
|
+
const config=loadConfig({projectRoot:definition.codeProject});
|
|
97
|
+
return ['unknown','codex'].includes(declaredRuntimes(config).available)
|
|
98
|
+
&&['coder','reviewer'].every(role=>['current-ai','codex-cli'].includes(config.roles[role].adapter));
|
|
99
|
+
}
|
|
70
100
|
|
|
71
101
|
export async function main(argv=process.argv.slice(2),{input=process.stdin,output=process.stdout,error=process.stderr}={}){
|
|
72
102
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('Approved 0.bootstrap only: --bootstrap-config PATH {selection:null for scaffold, or original cm-init selection for rules} and --allow-bootstrap-write. Original scope must include fixed instruction targets; they are host-written inside the original task effect, checked/reviewed and reloaded. No Git/install/network grant. Optional codeProjects selects disjoint real roots below codeProject; prefix scope/requirements and use protected current-session checks with a declared codeProject per command.\n');
|
|
73
|
-
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}. No extra model call. The current host returns scoped UTF-8 edits; native Codex sandbox applies them and runs the declared checks. Original author runtime, per-attempt Review and QA permissions remain required. Do not combine with --protected-config. Same original 64KiB transport limit; unavailable/binary changes stop, never switch to direct writes.\n');
|
|
74
|
-
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('Protected single-task
|
|
103
|
+
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('Protected current-session mode (Codex or Claude; also batch): --protected-conversation-config PATH with {checkCommands,timeoutMs}; timeoutMs bounds both check commands and the reviewer process. A review transport timeout with no result can resume once per attempt with fresh review authorization; a result-bearing timeout still requires reconciliation. No extra model call. The current host returns scoped UTF-8 edits; native Codex sandbox applies them and runs the declared checks. Original author runtime, per-attempt Review and QA permissions remain required. Do not combine with --protected-config. Same original 64KiB transport limit; unavailable/binary changes stop, never switch to direct writes.\n');
|
|
104
|
+
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('Protected single-task CLI mode: add --protected-config PATH --allow-provider-development-attempt 1|2 and --review-config PATH. Protected config is {model,checkCommands,timeoutMs}; roots and host identity come from the original run definition and launch. This explicitly permits one task attempt of real developer execution and its declared native-sandbox checks; --allow-development alone does not. Review separately requires --allow-review-attempt 1|2. Diagnostics are required but are not review authorization. Optional original --workflow-config PATH and --allow-qa connect protected QA commands and documentation within the same developer invocation before Review; host semantic/browser/inspection requests retain their original contracts, not arbitrary writes. Default current-session mode is unchanged. Protected parent mode selects coder/reviewer CLIs from the project declaration; Claude returns protected-text-v1 proposals for host validation and sandbox application; original QA-fix options require child configuration.protectSpecs=true and all original child action permissions. Protected fix writes use text proposals, not direct host edits. The original QA/documentation/finalizer gates remain required. No installation or Git authority.\n');
|
|
75
105
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--auto-qa-fix optionally connects parent advance -> fix_run -> re-QA. Requires --qa-fix-template-config, --allow-qa-fix-start, original action permissions and project policies.auto_fix=auto. Explicit/never policies stop. Unknown, blocked or incomplete repair stops; status/cancel remain available and no fourth QA round is dispatched.\n');
|
|
76
106
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--qa-fix-template-config PATH is an alternative to --qa-fix-owner-config. Supply {specsRoot, feature, identity: parent identity, configuration: original fix configuration without qaSource}. Each fix request binds it to the latest completed QA failure; identity/digests are generated, commands/scope/permissions are not. Existing child configuration remains immutable.\n');
|
|
77
107
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('fix_run continuously executes normal stages of the fixed QA child using the same binding as fix_advance. Requires --allow-qa-fix-start and every original per-action permission/configuration. Stops on unknown, blocked, observation, revision-required or unchanged state. It does not auto-switch child configuration or run parent QA.\n');
|
|
78
108
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('fix_action delegates to the shared original cm-fix dispatcher. Local flags: --allow-qa-fix-red-test, --allow-qa-fix-baseline, --allow-qa-fix-regression, --allow-qa-fix-learning-writeback, --allow-qa-fix-walkthrough, --allow-qa-fix-finish. Adapter flags: --allow-qa-fix-test-author, --allow-qa-fix-repair, --allow-qa-fix-cause-review, --allow-qa-fix-final-review, with separate --qa-fix-review-config PATH and matching original child reviewer metadata. All require --allow-qa-fix-start and the original action configuration/gates. Parent --review-config/--allow-review-attempt do not grant child review permission.\n');
|
|
79
109
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--allow-qa-fix-start additionally permits fix_advance to create or resume the fixed QA child and run only its original Learning/reproduction/diagnosis stages. Child hostContextId and runtime must match this host. It does not authorize test authoring, repair, independent provider Review, finish, Git or re-QA. Active child status/cancel use the original child owner; repeated advance never resets an unknown or completed step.\n');
|
|
80
110
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--qa-fix-owner-config PATH enables read-only fix_status. The file contains the existing fix owner definition {specsRoot, identity, configuration}, including its exact original qaSource and immutable configuration, not provider grants. fix_status binds the parent identity/packageDigest/testRunId, serially closes the parent writer, opens only an existing child, reads its original completion evidence, closes it and resumes the same parent. It does not create/execute repairs, rerun QA or clear correction gates.\n');
|
|
111
|
+
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('Protected current-session invalid_result means local value/Learning validation failed before file writes. Fix the reply, keep the same configuration, host identity and runId, restart with --mode resume and advance: blocked/developer_result_invalid retries develop at the same attempt. no_new_lesson requires reason:null (dogfood incident: nonempty reason previously wrote files then stranded the run as unknown). Already-applied proposals must match expected disk hashes; conflicts block as protected_edit_stale. Worker exceptions/timeouts and old unknown history are not retryable.\n');
|
|
112
|
+
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('New cm-ai runs carry approved specification data in developer requests and review packages: task/verification, all AC lines, design (64 KiB UTF-8 maximum, truncated:true above it), task-related test cases and manifest hashes. Sources must match .cm-specs-status.specFiles or spec_drift blocks. requirements may be [] or additional code-project files; specs never become writable scope. Legacy runs/packages retain their original representation. Dogfood: separate specs/code roots previously left developers and reviewers without task/interface contracts.\n');
|
|
113
|
+
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('Completed fixture_completed runs originally without QA may explicitly attach N6 once on --mode resume with --workflow-config (non-null qa) and --allow-qa. Original definition, scope, requirements, identity and non-workflow configuration must match. The immutable qa-attached journal record binds the full resumed config fingerprint; later resumes require that same configuration and fresh --allow-qa. qa still requests qa_assess; no automatic decision or repeated development/Review. Dogfood: missing workflow at create previously stranded mandatory feature QA.\n');
|
|
114
|
+
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--rerun-unknown-qa requires --mode resume and fresh --allow-qa with the original workflow config. Only an unfinished QA invocation whose recorded case results are all PASS and which has no fixed execution report may be abandoned and rerun under a new testRunId at the same qaRound. The abandoned record lists partial_pass_cases; every case is rerun and old PASS evidence is history only. FAIL/BLOCKED results and unclosed resources remain blocked; no complete is fabricated.\n');
|
|
81
115
|
if(argv.length===1&&['--help','-h'].includes(argv[0])){output.write(usage+'\n');return 0;}
|
|
82
116
|
let run,bridge;
|
|
83
117
|
try{
|
|
@@ -105,8 +139,8 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
105
139
|
const extra=new Map();
|
|
106
140
|
for(let index=8;index<argv.length;index++){
|
|
107
141
|
const name=argv[index];need(!extra.has(name),'invalid_arguments');
|
|
108
|
-
need(['--bootstrap-config','--allow-bootstrap-write','--protected-conversation-config','--protected-config','--allow-provider-development-attempt','--review-config','--allow-review-attempt','--workflow-config','--allow-qa','--runtime','--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');
|
|
109
|
-
if(['--allow-bootstrap-write','--allow-qa','--allow-qa-fix-start','--auto-qa-fix',...fixLocalPermissions.keys()].includes(name))extra.set(name,true);
|
|
142
|
+
need(['--bootstrap-config','--allow-bootstrap-write','--protected-conversation-config','--protected-config','--allow-provider-development-attempt','--review-config','--allow-review-attempt','--workflow-config','--allow-qa','--rerun-unknown-qa','--runtime','--failover','--qa-fix-owner-config','--qa-fix-template-config','--qa-fix-review-config','--allow-qa-fix-start','--auto-qa-fix',...fixLocalPermissions.keys()].includes(name),'invalid_arguments');
|
|
143
|
+
if(['--allow-bootstrap-write','--allow-qa','--rerun-unknown-qa','--failover','--allow-qa-fix-start','--auto-qa-fix',...fixLocalPermissions.keys()].includes(name))extra.set(name,true);
|
|
110
144
|
else{need(typeof argv[index+1]==='string'&&!argv[index+1].startsWith('--'),'invalid_arguments');extra.set(name,argv[++index]);}
|
|
111
145
|
}
|
|
112
146
|
const review=extra.has('--review-config')?reviewConfiguration(extra.get('--review-config')):null;
|
|
@@ -114,6 +148,7 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
114
148
|
let allowedAttempt=null;
|
|
115
149
|
if(extra.has('--allow-review-attempt')){need(['1','2'].includes(extra.get('--allow-review-attempt')),'invalid_arguments');allowedAttempt=Number(extra.get('--allow-review-attempt'));}
|
|
116
150
|
need(!extra.has('--allow-qa')||workflow?.qa!=null,'invalid_arguments');
|
|
151
|
+
need(!extra.has('--rerun-unknown-qa')||(argv[4]==='resume'&&extra.has('--allow-qa')),'qa_recovery_authorization_required');
|
|
117
152
|
const hasFix=extra.has('--qa-fix-owner-config')||extra.has('--qa-fix-template-config');
|
|
118
153
|
need(!(extra.has('--qa-fix-owner-config')&&extra.has('--qa-fix-template-config')),'invalid_fix_config');
|
|
119
154
|
need(!extra.has('--allow-qa-fix-start')||hasFix,'qa_fix_source_required');
|
|
@@ -125,7 +160,28 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
125
160
|
const protection=extra.has('--protected-conversation-config')?readConversationProtection(extra.get('--protected-conversation-config')):null;
|
|
126
161
|
const bootstrap=extra.has('--bootstrap-config')?readBootstrapConfiguration(extra.get('--bootstrap-config')):null;
|
|
127
162
|
need(!extra.has('--allow-bootstrap-write')||bootstrap!==null,'bootstrap_configuration_required');
|
|
163
|
+
// Checked before the definition is read so the conflict is reported on its own.
|
|
164
|
+
need(!(extra.has('--failover')&&extra.has('--protected-config')),'failover_unsupported_in_protected_mode');
|
|
128
165
|
const definition=readRunDefinition(argv[2]);bridge=createHostToolBridge();
|
|
166
|
+
// Startup-only role failover. The project's runtimes.available declaration is
|
|
167
|
+
// primary: it fixes which runtimes may be chosen and, via roles.coder, the
|
|
168
|
+
// requested start runtime. The CLI probe only confirms reachability. It never
|
|
169
|
+
// switches an in-flight task; a switch is always announced, never silent.
|
|
170
|
+
// Protected mode binds both roles before dispatch; startup failover remains a separate path.
|
|
171
|
+
let runtime=extra.get('--runtime')??'codex';
|
|
172
|
+
if(extra.has('--failover')){
|
|
173
|
+
const {selectRuntime,describeSelection}=await import('../runtime/js/cm-ai/runtime-failover.mjs');
|
|
174
|
+
const {probeRuntimes}=await import('./cm-failover.mjs');
|
|
175
|
+
const {loadConfig,declaredRuntimes,runtimeForAdapter}=await import('./cm-workflow-config.mjs');
|
|
176
|
+
const config=loadConfig({projectRoot:definition.codeProject}),declared=declaredRuntimes(config);
|
|
177
|
+
const requested=extra.get('--runtime')??runtimeForAdapter(config.roles.coder.adapter);
|
|
178
|
+
const reach=new Map(probeRuntimes().map(result=>[result.runtime,result.available]));
|
|
179
|
+
const selection=selectRuntime({role:'developer',requested,allowed:[...declared.allowed],
|
|
180
|
+
probe:(candidate)=>reach.get(candidate)===true});
|
|
181
|
+
runtime=selection.runtime;
|
|
182
|
+
error.write(`cm-ai-host failover: 声明 runtimes.available=${declared.available}; ${describeSelection(selection)}\n`);
|
|
183
|
+
if(selection.switched)error.write('cm-ai-host failover: CLI 可解析不等于配额可用;本次切换只决定起跑运行时。\n');
|
|
184
|
+
}
|
|
129
185
|
const templated=extra.has('--qa-fix-template-config');let fix=null;
|
|
130
186
|
if(hasFix){
|
|
131
187
|
const file=extra.get(templated?'--qa-fix-template-config':'--qa-fix-owner-config'),info=fs.lstatSync(file);
|
|
@@ -133,11 +189,24 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
133
189
|
fix=json(JSON.parse(fs.readFileSync(file,'utf8')),64*1024);
|
|
134
190
|
if(extra.has('--protected-config')||protection)need(fix.configuration?.protectSpecs===true,'protected_fix_required');
|
|
135
191
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
192
|
+
let execution;
|
|
193
|
+
if(argv[4]==='resume'&&extra.has('--protected-config')&&canResumeLegacyProtected(definition,runtime)){
|
|
194
|
+
try{
|
|
195
|
+
execution=await legacyProtectedExecutionFor(definition,argv[6],extra,review,argv[4],workflow,bridge,bootstrap);
|
|
196
|
+
run=await openControlRun(definition,argv[4],execution,{rerunUnknownQa:extra.has('--rerun-unknown-qa')});
|
|
197
|
+
error.write('cm-ai-host: resumed original Codex protected execution after exact fingerprint validation.\n');
|
|
198
|
+
}catch(cause){
|
|
199
|
+
if(!['fingerprint_mismatch','tool_preflight_missing'].includes(cause.code))throw cause;
|
|
200
|
+
execution=undefined;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
if(!run){
|
|
204
|
+
execution=extra.has('--protected-config')
|
|
205
|
+
?await protectedExecutionFor(definition,argv[6],extra,review,argv[4],workflow,bridge,bootstrap)
|
|
206
|
+
:executionFor(definition,argv[6],bridge,review,allowedAttempt,workflow,extra.has('--allow-qa'),runtime,
|
|
207
|
+
{...(protection?{protection}:{}),...(bootstrap?{bootstrap:{...bootstrap,allowWrite:extra.has('--allow-bootstrap-write')}}:{})});
|
|
208
|
+
run=await openControlRun(definition,argv[4],execution,{rerunUnknownQa:extra.has('--rerun-unknown-qa')});
|
|
209
|
+
}
|
|
141
210
|
if(run.blocked){output.write(JSON.stringify({outcome:'blocked',admission:run.blocked})+'\n');return 1;}
|
|
142
211
|
if(hasFix){
|
|
143
212
|
need(fs.realpathSync(fix.specsRoot)===fs.realpathSync(definition.specsDir)
|
|
@@ -145,7 +214,7 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
145
214
|
&&(templated?fix.feature:fix.configuration.qaSource.feature)===definition.feature,'qa_fix_source_mismatch');
|
|
146
215
|
if(templated)need(digest(fix.identity)===digest(definition.identity),'qa_fix_source_mismatch');
|
|
147
216
|
if(extra.has('--allow-qa-fix-start'))need(fix.configuration.hostContextId===argv[6]
|
|
148
|
-
&&(fix.configuration.runtime??'codex')===
|
|
217
|
+
&&(fix.configuration.runtime??'codex')===runtime,'qa_fix_host_mismatch');
|
|
149
218
|
const fixPermissions=[...fixLocalPermissions].filter(([flag])=>extra.has(flag)).map(([,permission])=>permission);
|
|
150
219
|
const fixReview=extra.has('--qa-fix-review-config')?reviewConfiguration(extra.get('--qa-fix-review-config')):null;
|
|
151
220
|
need(!fixPermissions.includes('--allow-test-author')||(fix.configuration.testAuthor&&fixReview),'test_author_configuration_required');
|