@aibyzero/cm-workflow 0.16.8 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.codex-plugin/plugin.json +1 -1
- package/CHANGELOG.md +31 -0
- package/README.md +22 -3
- package/VERSION +1 -1
- package/compat/claude-commands/cm-notify.md +3 -0
- package/docs/cm-control-policy-v2.md +331 -0
- package/docs/execution-optimizations.md +1 -1
- package/docs/external-models.md +3 -3
- package/docs/human-correction.md +5 -5
- package/docs/installation.md +1 -1
- package/docs/js-workflow-control.md +119 -78
- package/docs/next-steps.md +19 -2
- package/docs/untested-branches.md +2 -3
- package/docs/user-guide.md +105 -5
- package/package.json +2 -1
- package/runtime/js/cm-ai/claude-review-stream.mjs +49 -13
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +103 -68
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +79 -27
- package/runtime/js/cm-ai/code-projects.mjs +4 -1
- package/runtime/js/cm-ai/control-policy.mjs +111 -0
- package/runtime/js/cm-ai/developer-adapter.mjs +7 -0
- package/runtime/js/cm-ai/drive-bootstrap.mjs +11 -8
- package/runtime/js/cm-ai/drive-core.mjs +9 -0
- package/runtime/js/cm-ai/durable-runner-state.mjs +883 -69
- package/runtime/js/cm-ai/effect-abandon-log.mjs +5 -2
- package/runtime/js/cm-ai/effect-contract.mjs +6 -1
- package/runtime/js/cm-ai/external-run-guard.mjs +18 -7
- package/runtime/js/cm-ai/gate-bridge.mjs +4 -4
- package/runtime/js/cm-ai/host-check.mjs +4 -1
- package/runtime/js/cm-ai/host-conversation-execution.mjs +33 -24
- package/runtime/js/cm-ai/host-documentation.mjs +53 -12
- package/runtime/js/cm-ai/host-project-execution.mjs +2 -2
- package/runtime/js/cm-ai/host-qa-executor.mjs +49 -4
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +53 -9
- package/runtime/js/cm-ai/host-qa-policy.mjs +63 -21
- package/runtime/js/cm-ai/host-review-authority.mjs +2 -2
- package/runtime/js/cm-ai/host-review-file.mjs +1 -1
- package/runtime/js/cm-ai/host-session.mjs +1 -1
- package/runtime/js/cm-ai/host-tool-bridge.mjs +43 -3
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +21 -10
- package/runtime/js/cm-ai/host.mjs +1 -2
- package/runtime/js/cm-ai/operator-guidance.mjs +89 -3
- package/runtime/js/cm-ai/provider-review-observation.mjs +50 -0
- package/runtime/js/cm-ai/qa-resource-release.mjs +46 -0
- package/runtime/js/cm-ai/qa-round-budget.mjs +13 -0
- package/runtime/js/cm-ai/review-package.mjs +26 -5
- package/runtime/js/cm-ai/reviewed-deliveries.mjs +1 -1
- package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +1 -1
- package/runtime/js/cm-ai/task-commit.mjs +39 -0
- package/runtime/js/cm-ai/task-runner.mjs +629 -121
- package/runtime/js/cm-ai/worker-claude-developer.mjs +9 -0
- package/runtime/js/cm-ai/worker-claude.mjs +10 -3
- package/runtime/js/cm-ai/worker-process-identity.mjs +43 -0
- package/runtime/js/cm-fix/execution.mjs +176 -48
- package/runtime/js/cm-fix/host.mjs +2 -1
- package/runtime/js/cm-fix/pinned-baseline.mjs +24 -0
- package/runtime/js/cm-fix/progress.mjs +13 -3
- package/runtime/js/cm-fix/protected-edits.mjs +10 -3
- package/runtime/js/cm-fix/repair.mjs +11 -3
- package/runtime/js/cm-fix/test-author.mjs +10 -3
- package/runtime/js/cm-idea/session.mjs +67 -4
- package/runtime/js/cm-init/review-evidence.mjs +3 -1
- package/runtime/js/cm-prd/review-correction.mjs +10 -4
- package/runtime/js/cm-prd/review-host.mjs +1 -1
- package/runtime/js/cm-prd/review-publication.mjs +5 -3
- package/runtime/js/cm-prd/session.mjs +43 -0
- package/runtime/js/cm-refactor/records.mjs +98 -8
- package/runtime/js/cm-refactor/workflow.mjs +80 -10
- package/runtime/js/cm-test/host.mjs +10 -3
- package/runtime/js/cm-test/session.mjs +45 -6
- package/runtime/js/notify-safe-read.mjs +49 -0
- package/runtime/js/notify-send.mjs +313 -0
- package/runtime/js/notify.mjs +164 -37
- package/runtime/js/policy-binding-compat.mjs +55 -0
- package/runtime/review.md +52 -7
- package/runtime/task-gates.md +107 -9
- package/scripts/ci-test-shards.mjs +67 -0
- package/scripts/ci-test-shards.test.mjs +64 -0
- package/scripts/ci-test-weights.json +222 -0
- package/scripts/cm-ai-abandon-effect-position.test.mjs +71 -10
- package/scripts/cm-ai-answer-gap-dispatch.test.mjs +86 -0
- package/scripts/cm-ai-answer-gap-driver.test.mjs +51 -0
- package/scripts/cm-ai-answer-gap-fixture.mjs +89 -0
- package/scripts/cm-ai-answer-gap-recheck.test.mjs +70 -0
- package/scripts/cm-ai-answer-gap-redo.test.mjs +103 -0
- package/scripts/cm-ai-batch-drive.mjs +98 -34
- package/scripts/cm-ai-batch-drive.test.mjs +124 -16
- package/scripts/cm-ai-batch-host.mjs +167 -29
- package/scripts/cm-ai-batch-host.test.mjs +303 -31
- package/scripts/cm-ai-batch-run-fixture.mjs +452 -0
- package/scripts/cm-ai-batch-run-member-stops.test.mjs +26 -0
- package/scripts/cm-ai-batch-run-parallel.test.mjs +7 -0
- package/scripts/cm-ai-batch-run-reschedule.test.mjs +17 -0
- package/scripts/cm-ai-batch-run.mjs +213 -25
- package/scripts/cm-ai-batch-run.test.mjs +21 -341
- package/scripts/cm-ai-bootstrap-flow.test.mjs +1 -7
- package/scripts/cm-ai-bootstrap.test.mjs +2 -3
- package/scripts/cm-ai-control-launch.test.mjs +219 -0
- package/scripts/cm-ai-control-policy.test.mjs +124 -0
- package/scripts/cm-ai-control-v2-drive.test.mjs +270 -0
- package/scripts/cm-ai-develop-answer-invalid.test.mjs +97 -0
- package/scripts/cm-ai-develop-call-timeout.test.mjs +146 -0
- package/scripts/cm-ai-develop-driver-gaps.test.mjs +37 -23
- package/scripts/cm-ai-direct-review.test.mjs +348 -0
- package/scripts/cm-ai-documentation-sync-gap.test.mjs +424 -0
- package/scripts/cm-ai-drive-bootstrap-rules.test.mjs +54 -25
- package/scripts/cm-ai-drive.mjs +142 -58
- package/scripts/cm-ai-drive.test.mjs +70 -84
- package/scripts/cm-ai-fix-integration.test.mjs +3 -5
- package/scripts/cm-ai-fix-later-delivery.test.mjs +3 -6
- package/scripts/cm-ai-fix-run-delivery.test.mjs +3 -6
- package/scripts/cm-ai-host-cli-workflow.test.mjs +267 -0
- package/scripts/cm-ai-host-fixture.mjs +296 -0
- package/scripts/cm-ai-host-protected.test.mjs +253 -0
- package/scripts/cm-ai-host.mjs +122 -100
- package/scripts/cm-ai-host.test.mjs +35 -776
- package/scripts/cm-ai-launch-diagnostics.test.mjs +5 -3
- package/scripts/cm-ai-legacy-history.test.mjs +53 -0
- package/scripts/cm-ai-light-modules.test.mjs +54 -0
- package/scripts/cm-ai-multi-root.test.mjs +4 -4
- package/scripts/cm-ai-nested-execution.test.mjs +16 -19
- package/scripts/cm-ai-operator-guidance.test.mjs +30 -5
- package/scripts/cm-ai-progress.test.mjs +10 -8
- package/scripts/cm-ai-project-qa-gate.test.mjs +37 -10
- package/scripts/cm-ai-protected-scope.test.mjs +8 -5
- package/scripts/cm-ai-qa-answer-gaps.test.mjs +99 -0
- package/scripts/cm-ai-qa-config-revision.test.mjs +1 -9
- package/scripts/cm-ai-qa-fingerprint-config.test.mjs +12 -9
- package/scripts/cm-ai-qa-fix-cross-session.test.mjs +95 -13
- package/scripts/cm-ai-qa-fixed-log.test.mjs +41 -0
- package/scripts/cm-ai-qa-recovery-args.test.mjs +7 -0
- package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +59 -14
- package/scripts/cm-ai-review-drift-precedence.test.mjs +1 -1
- package/scripts/cm-ai-review-failure.test.mjs +137 -32
- package/scripts/cm-ai-review-timeout-config.test.mjs +3 -1
- package/scripts/cm-ai-review-timeout.test.mjs +132 -67
- package/scripts/cm-ai-run.mjs +91 -28
- package/scripts/cm-ai-run.test.mjs +11 -38
- package/scripts/cm-ai-selection-guard.test.mjs +2 -2
- package/scripts/cm-ai-session-chain.test.mjs +18 -15
- package/scripts/cm-ai-spec-rebind.test.mjs +14 -18
- package/scripts/cm-ai-supersede.test.mjs +489 -51
- package/scripts/cm-blocked-reason.test.mjs +2 -3
- package/scripts/cm-capability-gate.test.mjs +33 -1
- package/scripts/cm-check-drive-files.mjs +8 -0
- package/scripts/cm-check-drive.test.mjs +2 -5
- package/scripts/cm-check-runtime.sh +4 -2
- package/scripts/cm-claude-developer-worker.test.mjs +15 -0
- package/scripts/cm-claude-review-stream.test.mjs +21 -16
- package/scripts/cm-claude-review-synthetic.test.mjs +155 -0
- package/scripts/cm-claude-worker.test.mjs +23 -5
- package/scripts/cm-controlled-correction.test.mjs +469 -0
- package/scripts/cm-external-batch-host.test.mjs +30 -11
- package/scripts/cm-external-model-host.test.mjs +1 -1
- package/scripts/cm-external-model-recovery.test.mjs +32 -12
- package/scripts/cm-external-qa-fix.test.mjs +1 -1
- package/scripts/cm-external-review-reconciliation.test.mjs +6 -24
- package/scripts/cm-fix-abandon.test.mjs +163 -10
- package/scripts/cm-fix-drive-unprotected.test.mjs +37 -0
- package/scripts/cm-fix-drive.mjs +25 -7
- package/scripts/cm-fix-host.mjs +8 -7
- package/scripts/cm-fix-review-budget.test.mjs +13 -0
- package/scripts/cm-fix-review-recovery.test.mjs +36 -1
- package/scripts/cm-host-answer-timeout.test.mjs +65 -0
- package/scripts/cm-host-call-kinds.test.mjs +28 -0
- package/scripts/cm-host-documentation.test.mjs +49 -0
- package/scripts/cm-host-qa-executor.test.mjs +23 -12
- package/scripts/cm-host-qa-policy.test.mjs +43 -16
- package/scripts/cm-host-review-authority.test.mjs +0 -31
- package/scripts/cm-idea-answer-gaps.test.mjs +164 -0
- package/scripts/cm-idea-drive.mjs +49 -11
- package/scripts/cm-idea-drive.test.mjs +66 -0
- package/scripts/cm-idea-host.mjs +106 -16
- package/scripts/cm-init-answer-gaps.test.mjs +258 -0
- package/scripts/cm-init-drive.mjs +41 -7
- package/scripts/cm-init-host.mjs +61 -12
- package/scripts/cm-knowledge-closeout.test.mjs +3 -3
- package/scripts/cm-log-event.mjs +21 -10
- package/scripts/cm-notify-command.test.mjs +936 -0
- package/scripts/cm-notify-read-drift.test.mjs +270 -0
- package/scripts/cm-notify.mjs +481 -0
- package/scripts/cm-notify.test.mjs +312 -23
- package/scripts/cm-patrol.test.mjs +3 -2
- package/scripts/cm-prd-answer-gaps.test.mjs +216 -0
- package/scripts/cm-prd-drive.mjs +18 -5
- package/scripts/cm-prd-drive.test.mjs +15 -0
- package/scripts/cm-prd-host.mjs +37 -4
- package/scripts/cm-prd-review-disposition.test.mjs +6 -1
- package/scripts/cm-prd-review-gate.mjs +56 -0
- package/scripts/cm-refactor-answer-gaps.test.mjs +206 -0
- package/scripts/cm-refactor-drive.mjs +52 -8
- package/scripts/cm-refactor-drive.test.mjs +44 -0
- package/scripts/cm-refactor-host.test.mjs +10 -6
- package/scripts/cm-release-smoke.sh +2 -0
- package/scripts/cm-task-gate-correction.test.mjs +69 -16
- package/scripts/cm-task-gate.mjs +368 -34
- package/scripts/cm-task-gate.py +2 -0
- package/scripts/cm-task-gate.test.mjs +252 -4
- package/scripts/cm-test-answer-gaps.test.mjs +151 -0
- package/scripts/cm-test-drive.mjs +21 -5
- package/scripts/fixtures/bootstrap-review-runner.mjs +1 -7
- package/scripts/fixtures/claude-review-process.mjs +1 -1
- package/scripts/fixtures/native-gate-fixture.mjs +18 -0
- package/scripts/policy-binding-compat.test.mjs +103 -0
- package/scripts/scan-public-safety.py +4 -0
- package/scripts/validate-public-repo.py +4 -0
- package/skills/cm-ai/SKILL.md +8 -6
- package/skills/cm-ai/references/N3-execute-task.md +17 -2
- package/skills/cm-ai/references/N4-review.md +11 -21
- package/skills/cm-ai/references/N5-mark-done.md +1 -1
- package/skills/cm-ai/references/N6-qa-eval.md +49 -21
- package/skills/cm-ai/references/js-host-modes.md +35 -14
- package/skills/cm-ai/references/js-host-qa-recovery.md +85 -11
- package/skills/cm-ai/references/js-host-recovery.md +181 -21
- package/skills/cm-ai/references/js-host.md +76 -32
- package/skills/cm-check/SKILL.md +3 -3
- package/skills/cm-fix/SKILL.md +12 -0
- package/skills/cm-fix/references/js-host.md +44 -5
- package/skills/cm-idea/references/js-host.md +27 -2
- package/skills/cm-init/references/js-host.md +17 -4
- package/skills/cm-notify/SKILL.md +34 -0
- package/skills/cm-prd/references/js-change-recovery.md +35 -1
- package/skills/cm-prd/references/js-host.md +1 -1
- package/skills/cm-refactor/SKILL.md +12 -0
- package/skills/cm-refactor/references/js-host.md +17 -0
- package/skills/cm-test/references/js-host.md +14 -1
package/scripts/cm-ai-host.mjs
CHANGED
|
@@ -2,26 +2,39 @@
|
|
|
2
2
|
import {readLaunchExecutionPolicy} from '../runtime/js/cm-ai/execution-policy.mjs';
|
|
3
3
|
import {readLaunchExternalModels} from '../runtime/js/cm-ai/external-model-launch.mjs';
|
|
4
4
|
import {loadExternalModels,externalPair} from '../runtime/js/cm-ai/external-models.mjs';
|
|
5
|
-
//
|
|
6
|
-
//
|
|
5
|
+
// Current-conversation host. Legacy keeps explicit attempt choices; v2 uses
|
|
6
|
+
// its bound policy. Both retain V3 review binding; preflight is local diagnostics.
|
|
7
7
|
import {selectExternalModels} from '../runtime/js/cm-ai/external-models.mjs';
|
|
8
8
|
import fs from 'node:fs';
|
|
9
9
|
import path from 'node:path';
|
|
10
10
|
import {spawnSync} from 'node:child_process';
|
|
11
11
|
import {fileURLToPath} from 'node:url';
|
|
12
12
|
import {REVIEWED_HANDOFF_HINT} from '../runtime/js/cm-ai/host-handoff.mjs';
|
|
13
|
-
import {readRunDefinition,openControlRun,createCodexExecution,assertCreatableScope} from './cm-ai-run.mjs';
|
|
13
|
+
import {readRunDefinition,openControlRun,createCodexExecution,assertCreatableScope,controlLaunchTarget,assertSupportedResumeHistory} from './cm-ai-run.mjs';
|
|
14
14
|
import {createConversationExecution as executionFor} from '../runtime/js/cm-ai/host-conversation-execution.mjs';
|
|
15
|
-
import {createHostToolBridge} from '../runtime/js/cm-ai/host-tool-bridge.mjs';
|
|
15
|
+
import {createHostToolBridge,HOST_ANSWER_BACKSTOP_MS} from '../runtime/js/cm-ai/host-tool-bridge.mjs';
|
|
16
16
|
import {serveCmAiHost,parseHostInputLimit,inputLimitReason} from '../runtime/js/cm-ai/host-session.mjs';
|
|
17
17
|
import {createQaFixOwnerHost} from '../runtime/js/cm-ai/host-qa-fix-owner.mjs';
|
|
18
18
|
import {createFixLearningPreparation} from '../runtime/js/cm-fix/learning.mjs';
|
|
19
19
|
import {createFixReviewHost} from '../runtime/js/cm-fix/host-review.mjs';
|
|
20
|
-
import {createHostReviewAuthority} from '../runtime/js/cm-ai/host-review-authority.mjs';
|
|
21
20
|
import {loadConfig,declaredRuntimes,resolveProtectedRuntimes} from './cm-workflow-config.mjs';
|
|
22
21
|
import {readHostWorkflowConfiguration,featureHasBrowserCases,readBrowserCapability} from '../runtime/js/cm-ai/host-workflow-capabilities.mjs';
|
|
23
22
|
import {digest,json,need,shape,id} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
24
|
-
|
|
23
|
+
import {readControlPolicyFile,withControlPolicyHost,readControlTarget} from '../runtime/js/cm-ai/control-policy.mjs';
|
|
24
|
+
import {readExecutionSnapshot} from '../runtime/js/cm-ai/execution-snapshot.mjs';
|
|
25
|
+
import {parseModelJson} from '../runtime/js/cm-ai/model-configuration-file.mjs';
|
|
26
|
+
export {executionFor as createConversationExecution,reviewConfiguration as readConversationReviewConfiguration,reviewConfigurationValue as readConversationReviewConfigurationValue};
|
|
27
|
+
export function readLaunchControlFile(file){
|
|
28
|
+
const before=fs.lstatSync(file);
|
|
29
|
+
need(before.isFile()&&!before.isSymbolicLink()&&before.nlink===1&&before.size<=65536,'invalid_input');
|
|
30
|
+
const descriptor=fs.openSync(file,fs.constants.O_RDONLY|fs.constants.O_NOFOLLOW);
|
|
31
|
+
try{
|
|
32
|
+
const bytes=fs.readFileSync(descriptor),after=fs.fstatSync(descriptor),current=fs.lstatSync(file);
|
|
33
|
+
need([after,current].every(info=>['dev','ino','size','mtimeMs','ctimeMs'].every(key=>info[key]===before[key]))
|
|
34
|
+
&&bytes.length===before.size,'snapshot_changed');
|
|
35
|
+
return readControlTarget(parseModelJson(new TextDecoder('utf-8',{fatal:true}).decode(bytes)));
|
|
36
|
+
}finally{fs.closeSync(descriptor);}
|
|
37
|
+
}
|
|
25
38
|
export function withHandoffDiagnostic(host,error){
|
|
26
39
|
return {...host,async handle(request){
|
|
27
40
|
const result=await host.handle(request);
|
|
@@ -46,12 +59,12 @@ export function readBootstrapConfiguration(file){
|
|
|
46
59
|
const refuse=(ok,code,reason)=>{if(!ok)throw Object.assign(new Error(code),{code,reason});};
|
|
47
60
|
const REASONED_CODES=['supersede_unavailable','supersede_code_drift','handoff_exists','browser_capability_required',
|
|
48
61
|
'browser_capability_unavailable','invalid_arguments','fingerprint_mismatch','task_selection_mismatch','review_configuration_required',
|
|
49
|
-
'spec_rebind_refused','spec_rebind_unavailable','protected_scope'];
|
|
62
|
+
'spec_rebind_refused','spec_rebind_unavailable','protected_scope','invalid_input','snapshot_changed','runner_invocation'];
|
|
50
63
|
const fixLocalPermissions=new Map(['red-test','baseline','regression','learning-writeback','walkthrough','finish','abandon',
|
|
51
|
-
'abandon-review','test-author','repair','cause-review','final-review']
|
|
64
|
+
'abandon-review','test-author','repair','cause-review','final-review','rediagnosis','rerun-blocked-step','final-review-recovery']
|
|
52
65
|
.map(name=>[`--allow-qa-fix-${name}`,`--allow-${name}`]));
|
|
53
66
|
|
|
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
|
|
67
|
+
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-abandon-review] [--allow-abandon-effect] [--allow-bootstrap-review-recovery] [--allow-develop-redo] [--hold-revision] [--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)';
|
|
55
68
|
|
|
56
69
|
export function formatClaudeModelHint(config,version=null){
|
|
57
70
|
const marker=config?.preflight?.request_checks?.find(check=>check?.model_recognized===false);
|
|
@@ -74,7 +87,11 @@ export async function serveHostTransport(options,rawInputLimit,serve=serveCmAiHo
|
|
|
74
87
|
function reviewConfiguration(file,pair=null){
|
|
75
88
|
const info=fs.lstatSync(file);
|
|
76
89
|
need(info.isFile()&&!info.isSymbolicLink()&&info.size<=64*1024,'invalid_review_config');
|
|
77
|
-
|
|
90
|
+
return reviewConfigurationValue(JSON.parse(fs.readFileSync(file,'utf8')),pair);
|
|
91
|
+
}
|
|
92
|
+
// Same validation for bytes the caller already read (and pinned) itself.
|
|
93
|
+
function reviewConfigurationValue(raw,pair=null){
|
|
94
|
+
let config=json(raw);
|
|
78
95
|
if(pair){need(!Object.hasOwn(config,'model')||config.model===pair.model,'external_model_configuration_conflict');
|
|
79
96
|
need(!Object.hasOwn(config,'effort')||config.effort===pair.effort,'external_model_configuration_conflict');config={...config,...pair};}
|
|
80
97
|
shape(config,['model','preflight',...(pair?['effort']:[]),...(Object.hasOwn(config,'disabledSkills')?['disabledSkills']:[]),
|
|
@@ -108,12 +125,12 @@ export async function runReviewPreflight(definition,{model,effort,runtime='codex
|
|
|
108
125
|
real_model_requests:receipt.real_model_requests,listener_closed:receipt.listener_closed}};
|
|
109
126
|
}
|
|
110
127
|
|
|
111
|
-
async function protectedExecutionFor(definition,hostContextId,extra,review,mode,workflow,bridge,bootstrap=null,externalModels=null,executionPolicy=null){
|
|
128
|
+
async function protectedExecutionFor(definition,hostContextId,extra,review,mode,workflow,bridge,bootstrap=null,externalModels=null,executionPolicy=null,controlPolicy=null){
|
|
112
129
|
const runtime=extra.get('--runtime')??'codex';
|
|
113
130
|
const selected=resolveProtectedRuntimes(loadConfig({projectRoot:definition.codeProject}),runtime);
|
|
114
131
|
need(review!==null,'review_configuration_required');
|
|
115
|
-
|
|
116
|
-
|
|
132
|
+
const attempt=controlPolicy?1:Number(extra.get('--allow-provider-development-attempt'));
|
|
133
|
+
need([1,2].includes(attempt),'provider_development_authorization_required');
|
|
117
134
|
need(mode!=='create'||attempt===1,'invalid_development_attempt');
|
|
118
135
|
// Child fix configuration is checked before opening the parent store below.
|
|
119
136
|
const file=extra.get('--protected-config'),info=fs.lstatSync(file);
|
|
@@ -122,82 +139,51 @@ async function protectedExecutionFor(definition,hostContextId,extra,review,mode,
|
|
|
122
139
|
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
140
|
shape(config,['model','checkCommands','timeoutMs',...(externalModels?['effort']:[])]);
|
|
124
141
|
return executionFor(definition,hostContextId,bridge,review,
|
|
125
|
-
|
|
126
|
-
workflow,extra.has('--allow-qa'),runtime,{
|
|
142
|
+
null,
|
|
143
|
+
workflow,controlPolicy?controlPolicy.qa==='run':extra.has('--allow-qa'),runtime,{
|
|
127
144
|
...(extra.has('--original-host-context')?{originalHostContextId:extra.get('--original-host-context')}:{}),
|
|
128
145
|
protection:{checkCommands:config.checkCommands,timeoutMs:config.timeoutMs},
|
|
129
146
|
providerDevelopment:{model:config.model,attempt,...selected,...(externalModels?{effort:config.effort}:{})},
|
|
130
147
|
...(executionPolicy?{executionPolicy}:{}),
|
|
148
|
+
...(controlPolicy?{controlPolicy}:{}),
|
|
131
149
|
...(externalModels?{externalModels}:{}),
|
|
132
150
|
...(extra.has('--verification-precheck')?{verificationPrecheck:true}:{}),
|
|
133
|
-
...(bootstrap?{bootstrap:{...bootstrap,allowWrite:extra.has('--allow-bootstrap-write')}}:{}),
|
|
151
|
+
...(bootstrap?{bootstrap:{...bootstrap,allowWrite:controlPolicy?controlPolicy.bootstrap==='write':extra.has('--allow-bootstrap-write')}}:{}),
|
|
134
152
|
});
|
|
135
153
|
}
|
|
136
154
|
|
|
137
155
|
|
|
138
|
-
// Existing Codex-only runs retain their exact configuration/context identities.
|
|
139
|
-
// A successful original fingerprint check is the sole authority for this path;
|
|
140
|
-
// no migration, journal rewrite, or in-flight provider switch is permitted.
|
|
141
|
-
async function legacyProtectedExecutionFor(definition,hostContextId,extra,review,mode,workflow,bridge,bootstrap=null){
|
|
142
|
-
need((extra.get('--runtime')??'codex')==='codex','protected_runtime_unsupported');
|
|
143
|
-
need(!extra.has('--verification-precheck'),'verification_precheck_unavailable');
|
|
144
|
-
need(review!==null,'review_configuration_required');
|
|
145
|
-
need(['1','2'].includes(extra.get('--allow-provider-development-attempt')),'provider_development_authorization_required');
|
|
146
|
-
const attempt=Number(extra.get('--allow-provider-development-attempt'));
|
|
147
|
-
need(mode!=='create'||attempt===1,'invalid_development_attempt');
|
|
148
|
-
// Child fix configuration is checked before opening the parent store below.
|
|
149
|
-
const file=extra.get('--protected-config'),info=fs.lstatSync(file);
|
|
150
|
-
need(info.isFile()&&!info.isSymbolicLink()&&info.size<=64*1024,'invalid_protected_config');
|
|
151
|
-
const config=json(JSON.parse(fs.readFileSync(file,'utf8')));shape(config,['model','checkCommands','timeoutMs']);
|
|
152
|
-
const authority=createHostReviewAuthority({hostContextId,reviewerId:'reviewer',adapterId:'codex-review-adapter',
|
|
153
|
-
decide:async binding=>String(binding.identity.attempt)===extra.get('--allow-review-attempt')?{status:'approved'}:null});
|
|
154
|
-
return createCodexExecution({codeProject:definition.codeProject,specsRoot:definition.specsDir,
|
|
155
|
-
developerModel:config.model,checkCommands:config.checkCommands,timeoutMs:config.timeoutMs,
|
|
156
|
-
hostContextId,developerContextId:'cm-protected-author',reviewerModel:review.model,
|
|
157
|
-
reviewerPreflight:review.preflight,disabledSkills:review.disabledSkills,
|
|
158
|
-
...(workflow?{workflow:{definition,configuration:workflow}}:{}),
|
|
159
|
-
...(bootstrap?{bootstrap:{definition,selection:bootstrap.selection}}:{})},
|
|
160
|
-
{hostDecision:null,developmentAttempt:attempt,hostDecisionProvider:authority.hostDecisionProvider,authorizeReview:authority.authorize,
|
|
161
|
-
...(workflow?{workflow:{bridge,allowQa:extra.has('--allow-qa')}}:{}),
|
|
162
|
-
...(bootstrap?{bootstrap:{bridge,allowWrite:extra.has('--allow-bootstrap-write')}}:{}),
|
|
163
|
-
authorizeDevelopment:request=>({status:request.identity.attempt===attempt
|
|
164
|
-
&&digest({...request.identity,attempt:1})===digest(definition.identity)?'approved':'denied'})});
|
|
165
|
-
}
|
|
166
|
-
function canResumeLegacyProtected(definition,runtime){
|
|
167
|
-
if(runtime!=='codex')return false;
|
|
168
|
-
const config=loadConfig({projectRoot:definition.codeProject});
|
|
169
|
-
return ['unknown','codex'].includes(declaredRuntimes(config).available)
|
|
170
|
-
&&['coder','reviewer'].every(role=>['current-ai','codex-cli'].includes(config.roles[role].adapter));
|
|
171
|
-
}
|
|
172
|
-
|
|
173
156
|
export async function main(argv=process.argv.slice(2),{input=process.stdin,output=process.stdout,error=process.stderr}={}){
|
|
157
|
+
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('Control v2: serve --config RUN --mode create|resume --host-context ID --control-config POLICY --review-config REVIEW. No --allow-*; policy selects optional modes, not human authentication. Old launches remain legacy. See docs/cm-control-policy-v2.md.\n');
|
|
174
158
|
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');
|
|
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
|
|
159
|
+
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. Historical grant runs cannot resume; inspect them with cm-ai-run.mjs inspect-history --config RUN. The old protected assembly entrance is discontinued.\n');
|
|
176
160
|
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');
|
|
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
|
|
178
|
-
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
|
|
161
|
+
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 a fresh review context; 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, Review checks and QA capability choices 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');
|
|
162
|
+
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 dispatches directly with the configured reviewer. Diagnostics check capability. 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');
|
|
179
163
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--browser-qa is required when the approved contract for this feature contains blocking or policy-enabled interactive QA cases and QA is enabled. It covers the declared carrier (browser, ios-simulator, and others); the flag name is retained for compatibility. It is a declaration by the launching session, not a probe. The gate applies to create and resume, and is not persisted. unavailable refuses to start.\n');
|
|
180
164
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--revise-qa-config PREVIOUS_WORKFLOW.json --qa-config-revision-reason REASON: 仅 resume 且 --allow-qa;核对旧配置后追加 QA 修订,旧 QA 作废留史,下一轮仍受三轮上限约束。未知 QA 须先处理;不能修改开发配置或重开 N5。\n');
|
|
181
165
|
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');
|
|
182
166
|
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');
|
|
183
167
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('fix_run continuously executes normal stages of the fixed QA child using the same binding as fix_advance. Requires --allow-qa-fix-start and every original per-action permission/configuration. Stops on unknown, blocked, observation, revision-required or unchanged state; a design-change child closes as escalated and reports qa_fix_incomplete, never qa_fix_completed. It does not auto-switch child configuration or run parent QA.\n');
|
|
184
|
-
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('fix_action delegates to the shared original cm-fix dispatcher. Local flags: --allow-qa-fix-red-test, --allow-qa-fix-baseline, --allow-qa-fix-regression, --allow-qa-fix-learning-writeback, --allow-qa-fix-walkthrough, --allow-qa-fix-finish, --allow-qa-fix-abandon, --allow-qa-fix-abandon-review. abandon_step also requires a reason in the fix_action request and only applies to eligible local unknown steps; abandon_review requires --allow-qa-fix-abandon-review and a reason, and applies once to the child cause review and once to its second-round final review while that registered review has no review result. The parent run\'s own --allow-abandon-review does not reach the child. 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
|
|
168
|
+
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('fix_action delegates to the shared original cm-fix dispatcher. Local flags: --allow-qa-fix-red-test, --allow-qa-fix-baseline, --allow-qa-fix-regression, --allow-qa-fix-learning-writeback, --allow-qa-fix-walkthrough, --allow-qa-fix-finish, --allow-qa-fix-abandon, --allow-qa-fix-abandon-review, --allow-qa-fix-rediagnosis, --allow-qa-fix-rerun-blocked-step, --allow-qa-fix-final-review-recovery [--qa-fix-final-review-recovery-invocation ID]. Recovery fixOperations rediagnose, rerun_blocked_step (reason), revision_test_check (regression flag) and recover_final_review ({invocationId, reviewPackageDigest = the child final review package digest, previousInvocationStopped:true, reason}) go to the same cm-fix dispatcher with the same conditions as cm-fix-host; a missing flag returns qa_fix_action_authorization_required naming the parent flag, a cm-fix refusal returns its own code, and the parent reopens either way. abandon_step also requires a reason in the fix_action request and only applies to eligible local unknown steps; abandon_review requires --allow-qa-fix-abandon-review and a reason, and applies once to the child cause review and once to its second-round final review while that registered review has no review result. The parent run\'s own --allow-abandon-review does not reach the child. 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 does not configure child review.\n');
|
|
185
169
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--allow-qa-fix-start additionally permits fix_advance to create or resume the fixed QA child and run only its original Learning/reproduction/diagnosis stages. Child runtime must match this host. A new child hostContextId must be the live session or the parent durable creator; an existing child retains its fingerprint-verified configuration. Child opens and review grants use the live session. It does not authorize test authoring, repair, independent provider Review, finish, Git or re-QA. Active child status/cancel use the original child owner; repeated advance never resets an unknown or completed step.\n');
|
|
186
170
|
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');
|
|
187
171
|
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');
|
|
188
172
|
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');
|
|
189
|
-
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');
|
|
190
|
-
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. Exception: a call stopped as a whole (qa_execution_timeout) with no report and no FAIL, whose every case_blocked is a host request timeout (host_request_timeout: true; an older row without that field needs the full qa.timeoutMs elapsed since case_start plus an operator --qa-environment-failure REASON attesting no session answer, recorded verbatim as legacy_timeout_attestation, otherwise qa_environment_failure_required) and never session-declared, is superseded (reason host_request_timeout) and rerun at qaRound+1; --rerun-blocked-qa on it is refused as qa_rerun_unknown_qa_required.\n');
|
|
191
|
-
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--rerun-blocked-qa requires --mode resume, the original --workflow-config and fresh --allow-qa. Only the latest completed BLOCKED invocation with zero failures and exclusively host/environment evidence gaps can be superseded: browser evidenceProblem, failed cleanup, environment mismatch, host timeout or a host-declared BLOCKED answer; logic INSUFFICIENT_EVIDENCE or blocked only by a mapped command without exit code; QA commands that produced no exit code (timeout, killed, spawn/output failure). Missing/deferred command rows ([需确认], commands-unavailable, no-applicable-cases, no browser capability) and source drift are excluded. A new testRunId reruns every case at qaRound+1 (
|
|
173
|
+
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 ({confirmed:true}, inventory source only); fixed checkpoints and registered paths decide N6; no automatic decision or repeated development/Review. Dogfood: missing workflow at create previously stranded mandatory feature QA.\n');
|
|
174
|
+
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. Exception: a call stopped as a whole (qa_execution_timeout) with no report and no FAIL, whose every case_blocked is a host request timeout (host_request_timeout: true; an older row without that field needs the full qa.timeoutMs elapsed since case_start plus an operator --qa-environment-failure REASON attesting no session answer, recorded verbatim as legacy_timeout_attestation, otherwise qa_environment_failure_required) and never session-declared, is superseded (reason host_request_timeout) and rerun at qaRound+1; --rerun-blocked-qa on it is refused as qa_rerun_unknown_qa_required. The same applies to a call stopped as a whole (timeout, host death or a hard-invalid answer) whose other BLOCKED rows were session-declared or host-judged evidence/environment/cleanup gaps (blocked_reason): they are listed as host_blocked_cases. The whole-round deadline scales with the frozen plan (commands x command timeout, logic cases x request window, browser cases x two windows, plus one minute; at least 30 minutes, at most 24 hours). A cleanup_failed QA command resource whose recorded process group the host proves gone is released first (released_by host_verified).\n');
|
|
175
|
+
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--rerun-blocked-qa requires --mode resume, the original --workflow-config and fresh --allow-qa. Only the latest completed BLOCKED invocation with zero failures and exclusively host/environment evidence gaps can be superseded: browser evidenceProblem, failed cleanup, environment mismatch, host timeout or a host-declared BLOCKED answer; logic INSUFFICIENT_EVIDENCE or blocked only by a mapped command without exit code; QA commands that produced no exit code (timeout, killed, spawn/output failure). Missing/deferred command rows ([需确认], commands-unavailable, no-applicable-cases, no browser capability) and source drift are excluded. A new testRunId reruns every case at qaRound+1 (three rounds, plus at most two given back for rounds superseded for host or answer problems: host_request_timeout, host_evidence_problem); superseded and start link previous_test_run_id. The flag is consumed once, never persisted; no development/Review/task replay or new QA decision. Do not combine with --rerun-unknown-qa.\n');
|
|
192
176
|
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');
|
|
193
177
|
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');
|
|
194
|
-
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--allow-abandon-effect: resume 原 run 后发送 abandon_effect,request.reason 必须是单行且不超过 500 UTF-8
|
|
178
|
+
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--allow-abandon-effect: resume 原 run 后发送 abandon_effect,request.reason 必须是单行且不超过 500 UTF-8 字节。用于宿主在 develop/review(登记前)/complete(无 task-commit-intent)中途退出、只留下意图的运行:操作员先确认旧 host、会话写入和 effect 启动的检查/构建进程均已退出,宿主写 effect-interrupted,运行不作废,而从这一步的可重试阻断继续(develop_interrupted 后 advance 重发本轮;审查回到 awaiting_review;完成回到原状态)。provider 开发须存档记有 worker 进程身份且宿主核对进程组已退出;受保护当前会话开发须代码根仍等于本轮起点。已登记且本轮重派已用完的审查仍按旧规则作废运行(effect-abandoned),之后可 supersede。写了 task-commit-intent 的完成改发 complete 按提交计划收尾。\n');
|
|
179
|
+
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--hold-revision: 本次启动在第 1 轮审查要求修改后停在 changes_requested(revision_answer_required),不发起第 2 轮开发意图;只缩小本次启动,不写入配置,下次不带它即继续修订。\n');
|
|
180
|
+
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--allow-develop-redo: resume 原 run 后发送 develop_redo,request.reason 必须是单行且不超过 500 UTF-8 字节。当前会话开发(非受保护)的应答没拿到,或 provider 开发结果不明且存档记有 worker 进程身份(宿主先核对进程组已退出),pendingAction=develop_redo 时可用;操作员先确认会话已停止修改代码,宿主写入 develop-answer-redo 记录,之后 advance 重发本轮开发。旗标只消费一次,不写入配置。\n');
|
|
195
181
|
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--allow-bootstrap-review-recovery: resume 原 run 后发送 bootstrap_review_recover;只在 bootstrap develop 已完成且审查包构建失败时核对现有文件、handoff 与原始证据,并追加恢复记录,不重新派发开发。\n');
|
|
196
182
|
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');
|
|
197
183
|
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');
|
|
198
184
|
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
185
|
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');
|
|
200
|
-
if(argv.length===1&&['--help','-h'].includes(argv[0])){output.write(usage+'\n');return 0;}
|
|
186
|
+
if(argv.length===1&&['--help','-h'].includes(argv[0])){output.write(usage+'\nV2: replace --allow-development with --control-config FILE. Explicit resume QA reruns, QA configuration revisions and specification rebinds require --expected-control FILE containing the original status.launchControlTarget; ordinary host recovery uses status.controlTarget.\n');return 0;}
|
|
201
187
|
let run,bridge;
|
|
202
188
|
try{
|
|
203
189
|
if(argv[0]==='preflight'){
|
|
@@ -218,15 +204,46 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
218
204
|
}
|
|
219
205
|
return config.preflight.passed?0:1;
|
|
220
206
|
}
|
|
207
|
+
let controlPolicy=null;
|
|
208
|
+
if(argv[0]==='serve'&&argv[7]==='--control-config'){
|
|
209
|
+
refuse(!argv.some(value=>value.startsWith('--allow-')),'invalid_arguments',
|
|
210
|
+
'新版控制入口不接受 --allow-*;用 control-config 选择执行模式。旧运行请保留原入口与参数。');
|
|
211
|
+
controlPolicy=readControlPolicyFile(argv[8]);
|
|
212
|
+
// Keep the policy entry separate; never synthesize legacy argv or grants.
|
|
213
|
+
}
|
|
221
214
|
need(argv.length>=8&&argv[0]==='serve'&&argv[1]==='--config'&&argv[3]==='--mode'
|
|
222
|
-
&&argv[5]==='--host-context'&&argv[7]==='--allow-development','host_launch_authorization_required');
|
|
215
|
+
&&argv[5]==='--host-context'&&(controlPolicy!==null||argv[7]==='--allow-development'),'host_launch_authorization_required');
|
|
223
216
|
const extra=new Map();
|
|
224
|
-
for(let index=8;index<argv.length;index++){
|
|
217
|
+
for(let index=controlPolicy?9:8;index<argv.length;index++){
|
|
225
218
|
const name=argv[index];refuse(!extra.has(name),'invalid_arguments',`参数重复:${name}`);
|
|
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
|
|
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);
|
|
219
|
+
refuse(['--expected-control','--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-abandon-review','--allow-abandon-effect','--allow-bootstrap-review-recovery','--allow-develop-redo','--hold-revision','--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','--qa-fix-final-review-recovery-invocation','--allow-qa-fix-start','--auto-qa-fix',...fixLocalPermissions.keys()].includes(name),'invalid_arguments',`未知参数:${name}`);
|
|
220
|
+
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','--allow-develop-redo','--hold-revision','--rerun-unknown-qa','--rerun-blocked-qa','--failover','--allow-qa-fix-start','--auto-qa-fix',...fixLocalPermissions.keys()].includes(name))extra.set(name,true);
|
|
228
221
|
else{refuse(typeof argv[index+1]==='string'&&!argv[index+1].startsWith('--'),'invalid_arguments',`${name} 需要一个值`);extra.set(name,argv[++index]);}
|
|
229
222
|
}
|
|
223
|
+
if(controlPolicy){
|
|
224
|
+
// Policy choices go directly to execution contracts, not the legacy flag map.
|
|
225
|
+
refuse((controlPolicy.development==='provider')===extra.has('--protected-config'),'invalid_arguments',
|
|
226
|
+
'development:provider 需要 --protected-config;conversation 模式不启动 provider 开发。');
|
|
227
|
+
refuse((controlPolicy.bootstrap==='write')===extra.has('--bootstrap-config'),'invalid_arguments',
|
|
228
|
+
'bootstrap:write 需要 --bootstrap-config;加载规则配置必须明确选择 write 模式。');
|
|
229
|
+
refuse(controlPolicy.qaFix!=='disabled'||!['--qa-fix-owner-config','--qa-fix-template-config'].some(flag=>extra.has(flag)),
|
|
230
|
+
'invalid_arguments','加载 QA 修复配置必须选择 manual 或 auto 模式。');
|
|
231
|
+
refuse(!extra.has('--auto-qa-fix')||controlPolicy.qaFix==='auto','invalid_input','自动 QA 修复需要 qaFix:auto。');
|
|
232
|
+
refuse(!['--supersede-reviewed-evidence','--supersede-reason','--accept-superseded-code-drift']
|
|
233
|
+
.some(flag=>extra.has(flag)),'supersede_unavailable',
|
|
234
|
+
'新版启动入口暂不作废旧运行;保留现场,不自动更新目标后换运行。');
|
|
235
|
+
}
|
|
236
|
+
const qaEnabled=controlPolicy?controlPolicy.qa==='run':extra.has('--allow-qa');
|
|
237
|
+
const fixEnabled=controlPolicy?controlPolicy.qaFix!=='disabled':extra.has('--allow-qa-fix-start');
|
|
238
|
+
const autoFix=controlPolicy?controlPolicy.qaFix==='auto':extra.has('--auto-qa-fix');
|
|
239
|
+
const recoveryEnabled=flag=>controlPolicy?argv[4]==='resume':extra.has(flag);
|
|
240
|
+
const launchRecovery=['--revise-qa-config','--qa-config-revision-reason','--rerun-unknown-qa','--rerun-blocked-qa',
|
|
241
|
+
'--rebind-spec-material','--spec-rebind-reason'].some(flag=>extra.has(flag));
|
|
242
|
+
refuse(!extra.has('--expected-control')||(controlPolicy&&launchRecovery&&argv[4]==='resume'),'invalid_input',
|
|
243
|
+
'--expected-control 仅用于新版 --mode resume 的显式 QA 恢复、QA 配置修订或规格重绑。');
|
|
244
|
+
if(controlPolicy&&launchRecovery)refuse(argv[4]==='resume'&&extra.has('--expected-control'),'invalid_input',
|
|
245
|
+
'启动恢复需要 --mode resume 与 --expected-control FILE,文件须保存原 status 的 launchControlTarget;目标变化时先核对,不能自动替换。');
|
|
246
|
+
const expectedControl=extra.has('--expected-control')?readLaunchControlFile(extra.get('--expected-control')):null;
|
|
230
247
|
let inputLimit;
|
|
231
248
|
try{inputLimit=parseHostInputLimit(extra.get('--input-limit'));}
|
|
232
249
|
catch(error){refuse(error.code!=='invalid_arguments','invalid_arguments','--input-limit 须为 65536–4194304 的整数字节数');throw error;}
|
|
@@ -234,13 +251,14 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
234
251
|
need(!extra.has('--supersede-reviewed-evidence')&&!extra.has('--supersede-reason')&&!extra.has('--accept-superseded-code-drift')
|
|
235
252
|
||(argv[4]==='create'&&extra.has('--supersede-reviewed-evidence')&&extra.has('--supersede-reason')),
|
|
236
253
|
'supersede_unavailable');
|
|
237
|
-
need(!revisionRequested||(argv[4]==='resume'&&
|
|
254
|
+
need(!revisionRequested||(argv[4]==='resume'&&qaEnabled&&extra.has('--revise-qa-config')
|
|
238
255
|
&&extra.has('--qa-config-revision-reason')&&!extra.has('--rerun-unknown-qa')&&!extra.has('--rerun-blocked-qa')),'qa_revision_authorization_required');
|
|
239
256
|
need(!extra.has('--allow-abandon-review')||argv[4]==='resume','review_abandon_unavailable');
|
|
240
257
|
refuse(extra.has('--rebind-spec-material')===extra.has('--spec-rebind-reason')&&(!extra.has('--rebind-spec-material')||argv[4]==='resume'),
|
|
241
258
|
'spec_rebind_unavailable','--rebind-spec-material 只用于 --mode resume,并须同时提供单行 --spec-rebind-reason 原因');
|
|
242
259
|
need(!extra.has('--allow-abandon-effect')||argv[4]==='resume','effect_abandon_unavailable');
|
|
243
260
|
need(!extra.has('--allow-bootstrap-review-recovery')||argv[4]==='resume','bootstrap_review_recovery_unavailable');
|
|
261
|
+
need(!extra.has('--allow-develop-redo')||argv[4]==='resume','develop_redo_unavailable');
|
|
244
262
|
const qaConfigRevision=revisionRequested?{previousWorkflow:readHostWorkflowConfiguration(extra.get('--revise-qa-config')),
|
|
245
263
|
reason:extra.get('--qa-config-revision-reason')}:null;
|
|
246
264
|
const originalHostContextId=extra.get('--original-host-context')??null;
|
|
@@ -248,29 +266,34 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
248
266
|
if(originalHostContextId===argv[6])extra.delete('--original-host-context');
|
|
249
267
|
let review=null;
|
|
250
268
|
const workflow=extra.has('--workflow-config')?readHostWorkflowConfiguration(extra.get('--workflow-config')):null;
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
269
|
+
refuse(!qaEnabled||workflow?.qa!=null,'invalid_arguments',
|
|
270
|
+
controlPolicy
|
|
271
|
+
?(workflow===null?'QA 执行需要同时提供 --workflow-config':'QA 执行需要 --workflow-config 中的 qa 不为 null;没有 QA 时不要启用执行')
|
|
272
|
+
:(workflow===null?'--allow-qa 需要同时提供 --workflow-config':'--allow-qa 需要 --workflow-config 中的 qa 不为 null;本运行没有 QA 时去掉 --allow-qa'));
|
|
255
273
|
need(!(extra.has('--rerun-unknown-qa')&&extra.has('--rerun-blocked-qa')),'qa_recovery_authorization_required');
|
|
256
|
-
need(!(extra.has('--rerun-unknown-qa')||extra.has('--rerun-blocked-qa'))||(argv[4]==='resume'&&
|
|
274
|
+
need(!(extra.has('--rerun-unknown-qa')||extra.has('--rerun-blocked-qa'))||(argv[4]==='resume'&&qaEnabled),'qa_recovery_authorization_required');
|
|
257
275
|
need(!extra.has('--qa-environment-failure')||extra.has('--rerun-blocked-qa')||extra.has('--rerun-unknown-qa'),'qa_recovery_authorization_required');
|
|
258
276
|
const hasFix=extra.has('--qa-fix-owner-config')||extra.has('--qa-fix-template-config');
|
|
259
277
|
need(!(extra.has('--qa-fix-owner-config')&&extra.has('--qa-fix-template-config')),'invalid_fix_config');
|
|
260
|
-
need(!
|
|
278
|
+
need(!fixEnabled||hasFix,'qa_fix_source_required');
|
|
261
279
|
need(!extra.has('--qa-fix-review-config')||hasFix,'qa_fix_source_required');
|
|
262
|
-
need(!
|
|
263
|
-
need(![...fixLocalPermissions.keys()].some(flag=>extra.has(flag))||
|
|
280
|
+
need(!autoFix||(extra.has('--qa-fix-template-config')&&fixEnabled),'qa_fix_auto_authorization_required');
|
|
281
|
+
need(![...fixLocalPermissions.keys()].some(flag=>extra.has(flag))||fixEnabled,'qa_fix_start_authorization_required');
|
|
282
|
+
// Same binding as cm-fix-host --final-review-recovery-invocation, for the child.
|
|
283
|
+
refuse(!extra.has('--qa-fix-final-review-recovery-invocation')||(controlPolicy?fixEnabled:extra.has('--allow-qa-fix-final-review-recovery')),'invalid_arguments',
|
|
284
|
+
controlPolicy?'QA 修复回执恢复需要已启用 QA Fix 模式':'--qa-fix-final-review-recovery-invocation 需要同时提供 --allow-qa-fix-final-review-recovery');
|
|
285
|
+
if(extra.has('--qa-fix-final-review-recovery-invocation'))id(extra.get('--qa-fix-final-review-recovery-invocation'));
|
|
264
286
|
need(!extra.has('--allow-provider-development-attempt')||extra.has('--protected-config'),'protected_configuration_required');
|
|
265
287
|
refuse(!(extra.has('--review-runtime')&&(extra.has('--protected-config')||extra.has('--external-models'))),'invalid_arguments',
|
|
266
288
|
'--review-runtime 只用于普通当前会话宿主;--protected-config 与 --external-models 按 roles 自行选择审查端');
|
|
267
289
|
refuse(!(extra.has('--protected-config')&&extra.has('--protected-conversation-config')),'invalid_arguments','--protected-config 与 --protected-conversation-config 不能同时使用');
|
|
268
290
|
const protection=extra.has('--protected-conversation-config')?readConversationProtection(extra.get('--protected-conversation-config')):null;
|
|
269
291
|
const bootstrap=extra.has('--bootstrap-config')?readBootstrapConfiguration(extra.get('--bootstrap-config')):null;
|
|
270
|
-
need(!extra.has('--allow-bootstrap-write')||bootstrap!==null,'bootstrap_configuration_required');
|
|
292
|
+
need(!(controlPolicy?controlPolicy.bootstrap==='write':extra.has('--allow-bootstrap-write'))||bootstrap!==null,'bootstrap_configuration_required');
|
|
271
293
|
// Checked before the definition is read so the conflict is reported on its own.
|
|
272
294
|
need(!(extra.has('--failover')&&extra.has('--protected-config')),'failover_unsupported_in_protected_mode');
|
|
273
295
|
let definition=readRunDefinition(argv[2]);
|
|
296
|
+
if(argv[4]==='resume')assertSupportedResumeHistory(definition);
|
|
274
297
|
// --feature binds an explicit batch choice into the run definition, exactly
|
|
275
298
|
// as a printed featureSelection does; resume must repeat it (fingerprint).
|
|
276
299
|
if(extra.has('--feature')){
|
|
@@ -290,10 +313,10 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
290
313
|
// Launch-time capability assertion. See host-workflow-capabilities: this is a
|
|
291
314
|
// fresh declaration, not a probe the host performs.
|
|
292
315
|
readBrowserCapability(extra.get('--browser-qa'),
|
|
293
|
-
workflow?.qa!=null&&featureHasBrowserCases(definition.specsDir,definition.feature,definition.codeProject)
|
|
316
|
+
(!controlPolicy||qaEnabled)&&workflow?.qa!=null&&featureHasBrowserCases(definition.specsDir,definition.feature,definition.codeProject)
|
|
294
317
|
?[workflow.qa.environment?.carrier??'browser']:[]);
|
|
295
318
|
// Tool replies travel on the same input lines, so they share the one limit.
|
|
296
|
-
bridge=createHostToolBridge({responseLimit:inputLimit});
|
|
319
|
+
bridge=createHostToolBridge({responseLimit:inputLimit,answerTimeoutMs:HOST_ANSWER_BACKSTOP_MS});
|
|
297
320
|
// Startup-only role failover. The project's runtimes.available declaration is
|
|
298
321
|
// primary: it fixes which runtimes may be chosen and, via roles.coder, the
|
|
299
322
|
// requested start runtime. The CLI probe only confirms reachability. It never
|
|
@@ -320,29 +343,16 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
320
343
|
fix=json(JSON.parse(fs.readFileSync(file,'utf8')),64*1024);
|
|
321
344
|
if(extra.has('--protected-config')||protection)need(fix.configuration?.protectSpecs===true,'protected_fix_required');
|
|
322
345
|
}
|
|
323
|
-
// The reviewer
|
|
324
|
-
// it cannot be added on resume. Requiring it at create removes the trap of
|
|
325
|
-
// a run that can reach awaiting_review but never be reviewed. Authorizing a
|
|
326
|
-
// review attempt is still the separate --allow-review-attempt.
|
|
346
|
+
// The reviewer configuration remains bound into the durable fingerprint.
|
|
327
347
|
refuse(argv[4]!=='create'||review!==null,'review_configuration_required',
|
|
328
|
-
'create 必须带 --review-config:审查配置写进运行指纹,resume
|
|
348
|
+
'create 必须带 --review-config:审查配置写进运行指纹,resume 时不能再补。配置完成后自动派发 fresh Review。');
|
|
329
349
|
let execution;
|
|
330
|
-
if(argv[4]==='resume'&&!extra.has('--original-host-context')&&extra.has('--protected-config')&&!externalModels&&!executionPolicy&&canResumeLegacyProtected(definition,runtime)){
|
|
331
|
-
try{
|
|
332
|
-
execution=await legacyProtectedExecutionFor(definition,argv[6],extra,review,argv[4],workflow,bridge,bootstrap);
|
|
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});
|
|
334
|
-
error.write('cm-ai-host: resumed original Codex protected execution after exact fingerprint validation.\n');
|
|
335
|
-
}catch(cause){
|
|
336
|
-
if(!['fingerprint_mismatch','tool_preflight_missing'].includes(cause.code))throw cause;
|
|
337
|
-
execution=undefined;
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
350
|
if(!run){
|
|
341
351
|
execution=extra.has('--protected-config')
|
|
342
|
-
?await protectedExecutionFor(definition,argv[6],extra,review,argv[4],workflow,bridge,bootstrap,externalModels,executionPolicy)
|
|
343
|
-
:executionFor(definition,argv[6],bridge,review,
|
|
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:
|
|
352
|
+
?await protectedExecutionFor(definition,argv[6],extra,review,argv[4],workflow,bridge,bootstrap,externalModels,executionPolicy,controlPolicy)
|
|
353
|
+
:executionFor(definition,argv[6],bridge,review,null,workflow,qaEnabled,runtime,
|
|
354
|
+
{...(controlPolicy?{controlPolicy}:{}),...(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:(controlPolicy?controlPolicy.bootstrap==='write':extra.has('--allow-bootstrap-write'))}}:{})});
|
|
355
|
+
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:recoveryEnabled('--allow-abandon-review'),allowAbandonEffect:recoveryEnabled('--allow-abandon-effect'),allowBootstrapReviewRecovery:recoveryEnabled('--allow-bootstrap-review-recovery'),allowDevelopRedo:recoveryEnabled('--allow-develop-redo'),...(extra.has('--hold-revision')?{holdRevision:true}:{}),specRebindReason:extra.get('--spec-rebind-reason')??null,expectedControl});
|
|
346
356
|
}
|
|
347
357
|
if(run.blocked){output.write(JSON.stringify({outcome:'blocked',admission:run.blocked})+'\n');return 1;}
|
|
348
358
|
if(hasFix){
|
|
@@ -350,11 +360,17 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
350
360
|
&&fs.realpathSync(fix.configuration.reproduction.cwd)===fs.realpathSync(definition.codeProject)
|
|
351
361
|
&&(templated?fix.feature:fix.configuration.qaSource.feature)===definition.feature,'qa_fix_source_mismatch');
|
|
352
362
|
if(templated)need(digest(fix.identity)===digest(definition.identity),'qa_fix_source_mismatch');
|
|
353
|
-
if(
|
|
354
|
-
|
|
363
|
+
if(fixEnabled)need((fix.configuration.runtime??'codex')===runtime,'qa_fix_host_mismatch');
|
|
364
|
+
let fixPermissions=[...fixLocalPermissions].filter(([flag])=>controlPolicy
|
|
365
|
+
?!['test-author','repair','cause-review','final-review'].some(name=>flag.endsWith('-'+name))
|
|
366
|
+
:extra.has(flag)).map(([,permission])=>permission);
|
|
355
367
|
const fixRuntime=fix.configuration.runtime??'codex';
|
|
356
368
|
const fixModels=externalModels?selectExternalModels(externalModels,[fixRuntime]):null;
|
|
357
369
|
const fixReview=extra.has('--qa-fix-review-config')?reviewConfiguration(extra.get('--qa-fix-review-config'),fixModels?.providers[fixRuntime]??null):null;
|
|
370
|
+
if(controlPolicy&&fixReview)fixPermissions.push(...[...fixLocalPermissions]
|
|
371
|
+
.filter(([flag])=>flag.endsWith('-cause-review')||flag.endsWith('-final-review')
|
|
372
|
+
||fix.configuration.testAuthor&&flag.endsWith('-test-author')||fix.configuration.repair&&flag.endsWith('-repair'))
|
|
373
|
+
.map(([,permission])=>permission));
|
|
358
374
|
need(!fixPermissions.includes('--allow-test-author')||(fix.configuration.testAuthor&&fixReview),'test_author_configuration_required');
|
|
359
375
|
need(!fixPermissions.includes('--allow-repair')||(fix.configuration.repair&&fixReview),'repair_configuration_required');
|
|
360
376
|
const fixReviewHost=createFixReviewHost({codeProject:definition.codeProject,
|
|
@@ -369,8 +385,9 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
369
385
|
}
|
|
370
386
|
}else if(fixReview)need(digest(fix.configuration.causeReview??null)===digest(fixReviewHost.reviewer),'qa_fix_review_configuration_mismatch');
|
|
371
387
|
const host=createQaFixOwnerHost({parent:run,hostContextId:argv[6],parentHostContextId:execution.configuration.hostContextId,...(templated?{template:fix}:{fix}),reopenParent:()=>openControlRun(definition,'resume',execution),
|
|
372
|
-
externalModels:fixModels,executionPolicy,fixPermissions,fixAuthorities:{authority:fixReviewHost.authority,finalAuthority:fixReviewHost.finalAuthority},
|
|
373
|
-
allowStart:
|
|
388
|
+
externalModels:fixModels,executionPolicy,controlPolicy,fixPermissions,fixAuthorities:{authority:fixReviewHost.authority,finalAuthority:fixReviewHost.finalAuthority},
|
|
389
|
+
allowStart:fixEnabled,autoFix:autoFix,
|
|
390
|
+
recoveryInvocationId:extra.get('--qa-fix-final-review-recovery-invocation')??null,fixExecution:{bridge,...fixReviewHost.execution,
|
|
374
391
|
prepare:createFixLearningPreparation({bridge,codeProject:definition.codeProject,
|
|
375
392
|
applicableAgentFiles:fix.configuration.applicableAgentFiles??[]})}});
|
|
376
393
|
run={host,close:host.close};
|
|
@@ -378,7 +395,9 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
378
395
|
// PTY sessions are used by desktop tool hosts. Disable echo only on this
|
|
379
396
|
// process's own terminal so tool results are not mistaken for output frames.
|
|
380
397
|
const rawMode=input.isTTY&&typeof input.setRawMode==='function';if(rawMode)input.setRawMode(true);
|
|
381
|
-
const
|
|
398
|
+
const controlled=controlPolicy?withControlPolicyHost(run.host,{identity:definition.identity,
|
|
399
|
+
snapshot:()=>readExecutionSnapshot({specsRoot:definition.specsDir,identity:{repositoryId:definition.identity.repositoryId,runId:definition.identity.runId}}),launchTarget:controlLaunchTarget}):run.host;
|
|
400
|
+
const diagnosticHost=withHandoffDiagnostic(controlled,error);
|
|
382
401
|
try{await serveHostTransport({host:diagnosticHost,input,output,toolBridge:bridge,errorOutput:error},extra.get('--input-limit'));}
|
|
383
402
|
finally{if(rawMode)input.setRawMode(false);}
|
|
384
403
|
return 0;
|
|
@@ -391,6 +410,9 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
391
410
|
const snapshotReason=['out_of_scope','unsupported_file','limit_exceeded','package_mismatch'].includes(code)
|
|
392
411
|
&&typeof cause?.message==='string'&&cause.message.length<=8192&&!/[\r\n\0]/.test(cause.message)
|
|
393
412
|
?cause.message:null;
|
|
413
|
+
const protectedHistoryHint=code==='fingerprint_mismatch'&&argv[4]==='resume'&&argv.includes('--protected-config')
|
|
414
|
+
?' --protected-config 的配置指纹不匹配。旧 createCodexExecution 组装的 CLI 恢复入口已停用;无旧 grant 登记时不能仅凭指纹识别旧运行,不能自动转换。若属于这种旧运行,重复原参数无法恢复;保留现场,只读查看:node scripts/cm-ai-run.mjs inspect-history --config RUN_DEFINITION.json(使用原运行定义文件)。现代 provider 运行仍须核对原配置漂移。':null;
|
|
415
|
+
if(protectedHistoryHint)cause.reason=(typeof cause.reason==='string'?cause.reason:'')+protectedHistoryHint;
|
|
394
416
|
const reason=REASONED_CODES.includes(code)&&typeof cause?.reason==='string'&&cause.reason.length<=8192
|
|
395
417
|
&&!/[\r\n\0]/.test(cause.reason)?cause.reason:null;
|
|
396
418
|
if(code==='handoff_exists')error.write(`[host] ${REVIEWED_HANDOFF_HINT}\n`);
|