@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
|
@@ -7,7 +7,7 @@ import {spawnSync} from 'node:child_process';
|
|
|
7
7
|
import {createTaskRunner} from '../runtime/js/cm-ai/task-runner.mjs';
|
|
8
8
|
import {openTaskExecutionStore} from '../runtime/js/cm-ai/task-owner.mjs';
|
|
9
9
|
import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
10
|
-
import {readRunnerHistory,runnerStatus,completedEffectCount} from '../runtime/js/cm-ai/durable-runner-state.mjs';
|
|
10
|
+
import {readRunnerHistory,runnerStatus,completedEffectCount,projectedRunnerStatus} from '../runtime/js/cm-ai/durable-runner-state.mjs';
|
|
11
11
|
import {reviewPaths} from '../runtime/js/cm-ai/review-runner.mjs';
|
|
12
12
|
import {createCmAiConversationEntry} from '../runtime/js/cm-ai/cm-ai-conversation-entry.mjs';
|
|
13
13
|
import {abandonReviewPlanError,buildCmAiDriveRequest,buildCmAiDriveHostArgs} from './cm-ai-drive.mjs';
|
|
@@ -17,13 +17,6 @@ import {recordReviewAbandonment} from '../runtime/js/cm-ai/review-abandon-log.mj
|
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
const checks=[{id:'check',command:['synthetic'],outcome:'passed',exitCode:0,evidence:'fixture'}];
|
|
20
|
-
const grantFor=(request,authorizationAt,change=grant=>grant)=>{
|
|
21
|
-
const body={version:1,kind:'cm-review-dispatch-grant',grantId:`grant-${request.invocationId}`,adapterId:`${request.provider}-review-adapter`,
|
|
22
|
-
invocationId:request.invocationId,requestDigest:request.requestDigest,identity:request.identity,
|
|
23
|
-
reviewerId:'reviewer',logicalContextId:request.contextId,packageDigest:request.payload.reviewPackage.packageDigest,
|
|
24
|
-
hostContextId:'actual-main',decisionId:'decision-1',decision:'approved',issuedAt:authorizationAt,expiresAt:authorizationAt+60000};
|
|
25
|
-
change(body);return {...body,grantDigest:digest(body)};
|
|
26
|
-
};
|
|
27
20
|
const events=(onEvent,thread='actual-review')=>{
|
|
28
21
|
onEvent({event:'thread.started',provider_thread:thread});
|
|
29
22
|
onEvent({event:'turn.started',item_type:null});
|
|
@@ -32,7 +25,7 @@ const events=(onEvent,thread='actual-review')=>{
|
|
|
32
25
|
onEvent({event:'process_closed',exit_code:0,signal:null,timed_out:false});
|
|
33
26
|
};
|
|
34
27
|
|
|
35
|
-
async function fixture(fn,{reviewRun,
|
|
28
|
+
async function fixture(fn,{reviewRun,times,timeoutMs=1000,provider='codex'}={}) {
|
|
36
29
|
const temp=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-review-v3-')));
|
|
37
30
|
const root=path.join(temp,'code'),specsRoot=path.join(temp,'specs'),reviewsDir=path.join(specsRoot,'.reviews');
|
|
38
31
|
fs.mkdirSync(root);fs.mkdirSync(reviewsDir,{recursive:true});
|
|
@@ -56,8 +49,7 @@ async function fixture(fn,{reviewRun,authorize,times,timeoutMs=1000,provider='co
|
|
|
56
49
|
dispatches++;lateEvent=control.onEvent;return (reviewRun??defaultRun)(request,control);
|
|
57
50
|
}}],check:()=>checks,
|
|
58
51
|
taskCompletion:{reviewsDir,handoffs:[path.join(reviewsDir,'a1.json'),path.join(reviewsDir,'a2.json')]},
|
|
59
|
-
reviewInvocation:{developerThreadId:'actual-developer',excludedThreadIds:['actual-main']
|
|
60
|
-
authorize:authorize??((request,{authorizationAt})=>grantFor(request,authorizationAt))}};
|
|
52
|
+
reviewInvocation:{developerThreadId:'actual-developer',excludedThreadIds:['actual-main']}};
|
|
61
53
|
const make=mode=>{
|
|
62
54
|
const old=Date.now,values=times?[...times]:null;if(values)Date.now=()=>values.length>1?values.shift():values[0];
|
|
63
55
|
try{return createTaskRunner({...options,persistence:{store,mode,version:3}});}finally{Date.now=old;}
|
|
@@ -85,36 +77,6 @@ const timeoutRun=(request,{onEvent})=>{
|
|
|
85
77
|
};
|
|
86
78
|
const retryEffect=(f,attempt=1)=>({...f.effect('review',attempt),id:`review-${attempt}-retry-1`});
|
|
87
79
|
|
|
88
|
-
test('V3 expired dispatch grant is journaled as grant_expired without adapter dispatch',()=>fixture(async f=>{
|
|
89
|
-
const runner=f.make();await runner.executeEffect(f.effect('develop'));
|
|
90
|
-
const end=await runner.executeEffect(f.effect('review'));
|
|
91
|
-
assert.equal(end.state,'pending_review');assert.equal(end.code,'grant_expired');assert.equal(f.dispatches(),0);
|
|
92
|
-
assert.equal(end.reviewInvocation.result.outcome,'not_dispatched');
|
|
93
|
-
assert.equal(end.reviewInvocation.result.reason,'grant_expired');
|
|
94
|
-
assert.equal(end.reviewInvocation.result.dispatchAt,200);
|
|
95
|
-
assert.equal(end.reviewInvocation.registration.grant.expiresAt,150);
|
|
96
|
-
assert.equal(end.calls.at(-1).terminal,'not_dispatched');assert.equal(end.receipt,null);
|
|
97
|
-
const saved=f.getStore().snapshot();
|
|
98
|
-
assert.equal(readRunnerHistory(saved.records,saved.records[0].payload.config,3).state.code,'grant_expired');
|
|
99
|
-
assert.deepEqual(saved.records.slice(-3).map(record=>record.payload.type),
|
|
100
|
-
['review-invocation-registered','review-invocation-result','effect-checkpoint']);
|
|
101
|
-
assert.deepEqual(f.reopen().status(),end);
|
|
102
|
-
},{times:[100,101,200],authorize:(request,{authorizationAt})=>grantFor(request,authorizationAt,grant=>{grant.expiresAt=150;})}));
|
|
103
|
-
|
|
104
|
-
test('V3 non-monotonic dispatch clock is journaled as clock_invalid without adapter dispatch',()=>fixture(async f=>{
|
|
105
|
-
const runner=f.make();await runner.executeEffect(f.effect('develop'));
|
|
106
|
-
const end=await runner.executeEffect(f.effect('review'));
|
|
107
|
-
assert.equal(end.state,'pending_review');assert.equal(end.code,'clock_invalid');assert.equal(f.dispatches(),0);
|
|
108
|
-
assert.equal(end.reviewInvocation.result.outcome,'not_dispatched');
|
|
109
|
-
assert.equal(end.reviewInvocation.result.reason,'clock_invalid');
|
|
110
|
-
assert.equal(end.reviewInvocation.result.dispatchAt,99);
|
|
111
|
-
assert.equal(end.reviewInvocation.registration.registeredAt,101);
|
|
112
|
-
assert.equal(end.calls.at(-1).terminal,'not_dispatched');assert.equal(end.receipt,null);
|
|
113
|
-
const saved=f.getStore().snapshot();
|
|
114
|
-
assert.equal(readRunnerHistory(saved.records,saved.records[0].payload.config,3).state.code,'clock_invalid');
|
|
115
|
-
assert.deepEqual(f.reopen().status(),end);
|
|
116
|
-
},{times:[100,101,99]}));
|
|
117
|
-
|
|
118
80
|
test('runner timer without a result shares pending/blocked timeout transitions and replay',()=>fixture(async f=>{
|
|
119
81
|
const runner=f.make();await runner.executeEffect(f.effect('develop'));
|
|
120
82
|
const end=await runner.executeEffect(f.effect('review'));
|
|
@@ -126,15 +88,32 @@ test('runner timer without a result shares pending/blocked timeout transitions a
|
|
|
126
88
|
assert.deepEqual(f.getStore().snapshot(),before);
|
|
127
89
|
const resumed=f.reopen();assert.deepEqual(resumed.status(),end);
|
|
128
90
|
assert.deepEqual(await resumed.executeEffect(f.effect('review')),end);assert.equal(f.dispatches(),1);
|
|
91
|
+
// V5: the round keeps a second no-result redispatch, but the timer only
|
|
92
|
+
// aborted the reviewer: nothing is redispatched until the operator confirms
|
|
93
|
+
// the original reviewer stopped (abandon_review journals review-redispatch).
|
|
129
94
|
const blocked=await resumed.executeEffect(retryEffect(f));assert.equal(blocked.state,'blocked');
|
|
130
|
-
assert.equal(blocked.code,'review_transport_timeout');assert.
|
|
131
|
-
assert.
|
|
132
|
-
assert.
|
|
95
|
+
assert.equal(blocked.code,'review_transport_timeout');assert.equal(blocked.reviewRedispatchStopRequired,true);
|
|
96
|
+
assert.match(blocked.reason,/^review_redispatch_stop_required: /);
|
|
97
|
+
const second=f.reopen();assert.deepEqual(second.status(),blocked);
|
|
98
|
+
assert.equal((await second.executeEffect({...retryEffect(f),id:'review-1-retry-2'})).code,'stage_mismatch');assert.equal(f.dispatches(),2);
|
|
99
|
+
const unconfirmed=f.getStore().snapshot();
|
|
100
|
+
assert.equal(second.abandonReview({allowed:false,reason:'x'}).code,'review_abandon_authorization_required');
|
|
101
|
+
assert.equal(second.abandonReview({allowed:true,reason:' '}).code,'review_abandon_reason_required');
|
|
102
|
+
assert.deepEqual(f.getStore().snapshot(),unconfirmed);
|
|
103
|
+
const confirmed=second.abandonReview({allowed:true,reason:'Original reviewer process confirmed exited'});
|
|
104
|
+
assert.equal(confirmed.state,'pending_review');assert.equal(confirmed.code,'review_transport_timeout');
|
|
105
|
+
const third=await f.reopen().executeEffect({...retryEffect(f),id:'review-1-retry-2'});
|
|
106
|
+
assert.equal(third.state,'blocked');assert.equal(third.code,'review_redispatch_limit');
|
|
107
|
+
const spent=f.reopen().status();assert.deepEqual(spent,third);
|
|
108
|
+
assert.match(spent.reason,/无结论重派 2 次/);
|
|
109
|
+
assert.equal((await f.reopen().executeEffect({...retryEffect(f),id:'review-1-retry-3'})).code,'stage_mismatch');
|
|
110
|
+
assert.equal(f.dispatches(),3);
|
|
111
|
+
assert.equal(f.getStore().snapshot().records.filter(row=>row.payload.type==='review-redispatch').length,1);
|
|
133
112
|
},{timeoutMs:20,reviewRun:(request,{onEvent})=>{
|
|
134
113
|
onEvent({event:'thread.started',provider_thread:`thread-${request.invocationId}`});return new Promise(()=>{});
|
|
135
114
|
}}));
|
|
136
115
|
|
|
137
|
-
test('each attempt gets one retry without consuming the six-effect budget or reusing
|
|
116
|
+
test('each attempt gets one retry without consuming the six-effect budget or reusing bindings',()=>fixture(async f=>{
|
|
138
117
|
const attempts=new Map();
|
|
139
118
|
f.options.reviewers[0].run=(request,control)=>{
|
|
140
119
|
const attempt=request.identity.attempt,count=(attempts.get(attempt)??0)+1;attempts.set(attempt,count);
|
|
@@ -151,8 +130,8 @@ test('each attempt gets one retry without consuming the six-effect budget or reu
|
|
|
151
130
|
runner=f.reopen();assert.deepEqual(runner.status(),first);
|
|
152
131
|
const second=await runner.executeEffect(retryEffect(f,attempt));
|
|
153
132
|
assert.equal(second.state,attempt===1?'changes_requested':'approved');
|
|
154
|
-
assert.notEqual(first.reviewInvocation.registration.
|
|
155
|
-
assert.notEqual(first.reviewInvocation.registration.
|
|
133
|
+
assert.notEqual(first.reviewInvocation.registration.binding.invocationId,second.reviewInvocation.registration.binding.invocationId);
|
|
134
|
+
assert.notEqual(first.reviewInvocation.registration.binding.requestDigest,second.reviewInvocation.registration.binding.requestDigest);
|
|
156
135
|
runner=f.reopen();assert.deepEqual(runner.status(),second);
|
|
157
136
|
}
|
|
158
137
|
const records=f.getStore().snapshot().records,history=readRunnerHistory(records,records[0].payload.config,3);
|
|
@@ -184,10 +163,10 @@ test('interrupted V3 review needs explicit abandonment and replays the audited e
|
|
|
184
163
|
const next=f.reopen();
|
|
185
164
|
const result=await next.executeEffect(retryEffect(f));
|
|
186
165
|
assert.equal(result.state,'approved');
|
|
187
|
-
assert.notEqual(result.reviewInvocation.registration.
|
|
188
|
-
abandoned.reviewInvocation.registration.
|
|
189
|
-
assert.notEqual(result.reviewInvocation.registration.
|
|
190
|
-
abandoned.reviewInvocation.registration.
|
|
166
|
+
assert.notEqual(result.reviewInvocation.registration.binding.invocationId,
|
|
167
|
+
abandoned.reviewInvocation.registration.binding.invocationId);
|
|
168
|
+
assert.notEqual(result.reviewInvocation.registration.binding.requestDigest,
|
|
169
|
+
abandoned.reviewInvocation.registration.binding.requestDigest);
|
|
191
170
|
}));
|
|
192
171
|
|
|
193
172
|
test('registered review without a started record can also be abandoned',()=>fixture(async f=>{
|
|
@@ -231,15 +210,18 @@ test('abandonment is refused when a review result is already journaled',()=>fixt
|
|
|
231
210
|
assert.deepEqual(f.getStore().snapshot(),completed);
|
|
232
211
|
}));
|
|
233
212
|
|
|
234
|
-
test('abandonment and transport timeout share the
|
|
213
|
+
test('abandonment and transport timeout share the round\'s two no-result redispatches',()=>fixture(async f=>{
|
|
235
214
|
const runner=f.make();await runner.executeEffect(f.effect('develop'));await runner.executeEffect(f.effect('review'));
|
|
236
215
|
const interrupted=f.resumePrefix('review-invocation-started');
|
|
237
216
|
assert.equal(interrupted.abandonReview({allowed:true,reason:'exit'}).state,'pending_review');
|
|
238
217
|
f.options.reviewers[0].run=timeoutRun;
|
|
239
218
|
const retry=f.reopen();
|
|
240
219
|
const result=await retry.executeEffect(retryEffect(f));
|
|
241
|
-
assert.equal(result.state,'blocked');assert.equal(result.
|
|
242
|
-
assert.equal(
|
|
220
|
+
assert.equal(result.state,'blocked');assert.equal(result.reviewRedispatchStopRequired,true);
|
|
221
|
+
assert.equal(f.reopen().abandonReview({allowed:true,reason:'stopped'}).state,'pending_review');
|
|
222
|
+
const last=await f.reopen().executeEffect({...retryEffect(f),id:'review-1-retry-2'});
|
|
223
|
+
assert.equal(last.state,'blocked');assert.equal(last.code,'review_redispatch_limit');
|
|
224
|
+
assert.equal((await f.reopen().executeEffect({...retryEffect(f),id:'review-1-retry-3'})).code,'stage_mismatch');
|
|
243
225
|
}));
|
|
244
226
|
|
|
245
227
|
test('conversation reports unknown cancel truthfully, then consumes abandonment authority once',()=>fixture(async f=>{
|
|
@@ -252,7 +234,7 @@ test('conversation reports unknown cancel truthfully, then consumes abandonment
|
|
|
252
234
|
assert.equal((await noFlag.handle(request('abandon_review',{reason:'old process exited'}))).outcome,'rejected');
|
|
253
235
|
assert.deepEqual(f.getStore().snapshot(),before);
|
|
254
236
|
const entry=createCmAiConversationEntry({specsDir:path.dirname(f.tasksPath),codeProject:f.root,
|
|
255
|
-
feature:'feature',identity:f.options.identity,runner,allowAbandonReview:true
|
|
237
|
+
feature:'feature',identity:f.options.identity,runner,allowAbandonReview:true});
|
|
256
238
|
const cancelled=await entry.handle(request('cancel'));
|
|
257
239
|
assert.equal(cancelled.outcome,'reported');assert.equal(cancelled.state,'unknown');
|
|
258
240
|
assert.equal(cancelled.pendingAction,'abandon_review');
|
|
@@ -278,8 +260,8 @@ test('cancel after abandonment becomes durable cancelled',()=>fixture(async f=>{
|
|
|
278
260
|
}));
|
|
279
261
|
|
|
280
262
|
test('abandonment refuses an exhausted retry before appending a record',()=>fixture(async f=>{
|
|
281
|
-
let
|
|
282
|
-
if(
|
|
263
|
+
let failures=2;f.options.reviewers[0].run=(request,control)=>{
|
|
264
|
+
if(failures>0){failures--;return timeoutRun(request,control);}
|
|
283
265
|
events(control.onEvent,`thread-${request.invocationId}`);
|
|
284
266
|
return {status:'succeeded',value:{verdict:'approved',packageDigest:request.payload.reviewPackage.packageDigest,
|
|
285
267
|
examinedPaths:reviewPaths(request.payload.reviewPackage),findings:[],summary:'Synthetic'}};
|
|
@@ -287,8 +269,11 @@ test('abandonment refuses an exhausted retry before appending a record',()=>fixt
|
|
|
287
269
|
const runner=f.make();await runner.executeEffect(f.effect('develop'));
|
|
288
270
|
const firstResult=await runner.executeEffect(f.effect('review'));
|
|
289
271
|
assert.equal(firstResult.code,'review_transport_timeout');
|
|
290
|
-
|
|
272
|
+
assert.equal((await runner.executeEffect(retryEffect(f))).reviewRedispatchStopRequired,true);
|
|
273
|
+
assert.equal(f.reopen().abandonReview({allowed:true,reason:'stopped'}).state,'pending_review');
|
|
274
|
+
const secondResult=await f.reopen().executeEffect({...retryEffect(f),id:'review-1-retry-2'});
|
|
291
275
|
assert.equal(secondResult.state,'approved');
|
|
276
|
+
// Both redispatches of the round are spent (automatic + review-redispatch).
|
|
292
277
|
const interrupted=f.resumePrefix('review-invocation-started',true),before=f.getStore().snapshot();
|
|
293
278
|
const result=interrupted.abandonReview({allowed:true,reason:'exit'});
|
|
294
279
|
assert.equal(result.outcome,'rejected');assert.equal(result.code,'review_abandon_budget_exhausted');
|
|
@@ -409,7 +394,7 @@ test(`factory passes exact configured timeout to ${runtime} reviewer, provider m
|
|
|
409
394
|
const review={model:'fixture',disabledSkills:[],preflight:{passed:true,provider:runtime,cli_model:'fixture',
|
|
410
395
|
prompt_transport:'stdin',config_fingerprint:(runtime==='codex'?configFingerprint:claudeReviewFingerprint)(workerOptions)}};
|
|
411
396
|
const timeoutMs=providerMode?6789:5123;
|
|
412
|
-
const execution=createConversationExecution(definition,'host-test',{call:()=>assert.fail('unexpected host call')},review,
|
|
397
|
+
const execution=createConversationExecution(definition,'host-test',{call:()=>assert.fail('unexpected host call')},review,null,null,false,runtime,
|
|
413
398
|
{protection:{checkCommands:[{id:'syntax',command:[process.execPath,'--version']}],timeoutMs},
|
|
414
399
|
...(providerMode?{providerDevelopment:{model:'fixture',attempt:1,coderRuntime:runtime,reviewerRuntime:runtime}}:{})});
|
|
415
400
|
const timers=[],originalTimer=globalThis.setTimeout;
|
|
@@ -433,19 +418,99 @@ test(`factory passes exact configured timeout to ${runtime} reviewer, provider m
|
|
|
433
418
|
}finally{t.mock.restoreAll();syncBuiltinESMExports();}
|
|
434
419
|
}));
|
|
435
420
|
|
|
436
|
-
for(const boundary of ['
|
|
421
|
+
for(const boundary of ['package-drift','cancelled'])
|
|
437
422
|
test(`retry preserves original authorization/package/cancellation boundary: ${boundary}`,()=>fixture(async f=>{
|
|
438
|
-
if(boundary==='stale-grant'){
|
|
439
|
-
let firstGrant;
|
|
440
|
-
f.options.reviewInvocation.authorize=(request,{authorizationAt})=>firstGrant??=grantFor(request,authorizationAt);
|
|
441
|
-
}
|
|
442
423
|
let runner=f.make();await runner.executeEffect(f.effect('develop'));
|
|
443
424
|
const pending=await runner.executeEffect(f.effect('review'));assert.equal(pending.state,'pending_review');
|
|
444
425
|
if(boundary==='package-drift')fs.writeFileSync(path.join(f.root,'code.js'),'outside drift\n');
|
|
445
426
|
if(boundary==='cancelled')runner.cancel();
|
|
446
|
-
|
|
427
|
+
runner=f.reopen();
|
|
447
428
|
const result=await runner.executeEffect(retryEffect(f));
|
|
448
|
-
assert.equal(result.code,boundary==='
|
|
429
|
+
assert.equal(result.code,boundary==='package-drift'?'package_mismatch':'stage_mismatch');
|
|
449
430
|
assert.equal(f.dispatches(),1);
|
|
450
|
-
if(boundary==='stale-grant')assert.equal(f.reopen().status().state,'unknown');
|
|
451
431
|
},{reviewRun:timeoutRun}));
|
|
432
|
+
|
|
433
|
+
// V5 (A33): a reviewer whose worker proved its process gone without a final
|
|
434
|
+
// message may be abandoned and redispatched; an unverified cleanup or an invalid
|
|
435
|
+
// stream is refused with its own code and reason, before anything is appended.
|
|
436
|
+
const closedFailure=code=>(request,{onEvent})=>{
|
|
437
|
+
onEvent({event:'thread.started',provider_thread:`thread-${request.invocationId}`});
|
|
438
|
+
onEvent({event:'turn.started',item_type:null});
|
|
439
|
+
onEvent({event:'process_closed',exit_code:1,signal:null,timed_out:false});
|
|
440
|
+
return {status:'failed',code};
|
|
441
|
+
};
|
|
442
|
+
for(const [name,run] of [['spawn_failed',()=>({status:'failed',code:'spawn_failed'})],['output_limit',closedFailure('output_limit')],
|
|
443
|
+
['prompt_write_failed',closedFailure('prompt_write_failed')]])
|
|
444
|
+
test(`A33 ${name} with the reviewer process gone is abandonable and redispatched`,()=>fixture(async f=>{
|
|
445
|
+
const runner=f.make();await runner.executeEffect(f.effect('develop'));
|
|
446
|
+
const end=await runner.executeEffect(f.effect('review'));
|
|
447
|
+
assert.equal(end.state,'unknown');assert.equal(end.abandonableReviewResult,true,JSON.stringify(end));
|
|
448
|
+
const abandoned=f.reopen().abandonReview({allowed:true,reason:'worker reported the process gone'});
|
|
449
|
+
assert.equal(abandoned.state,'pending_review');assert.equal(abandoned.code,'review_abandoned');
|
|
450
|
+
f.options.reviewers[0].run=(request,{onEvent})=>{events(onEvent,`thread-${request.invocationId}`);
|
|
451
|
+
return {status:'succeeded',value:{verdict:'approved',packageDigest:request.payload.reviewPackage.packageDigest,
|
|
452
|
+
examinedPaths:reviewPaths(request.payload.reviewPackage),findings:[],summary:'Synthetic'}};};
|
|
453
|
+
assert.equal((await f.reopen().executeEffect(retryEffect(f))).state,'approved');
|
|
454
|
+
},{reviewRun:run}));
|
|
455
|
+
for(const [name,run,code] of [
|
|
456
|
+
['process_cleanup_unknown',closedFailure('process_cleanup_unknown'),'review_process_unverified'],
|
|
457
|
+
['a tool item boundary exit',closedFailure('unexpected_tool_or_item'),'review_boundary_unverified'],
|
|
458
|
+
['spawn_failed after events',(request,{onEvent})=>{onEvent({event:'thread.started',provider_thread:`thread-${request.invocationId}`});
|
|
459
|
+
return {status:'failed',code:'spawn_failed'};},'review_boundary_unverified'],
|
|
460
|
+
['an invalid stream',(request,{onEvent})=>{onEvent({event:'turn.completed',item_type:null});return new Promise(()=>{});},'review_observation_invalid']])
|
|
461
|
+
test(`A33 ${name} stays unknown and abandon_review is refused with ${code}`,()=>fixture(async f=>{
|
|
462
|
+
const runner=f.make();await runner.executeEffect(f.effect('develop'));
|
|
463
|
+
const end=await runner.executeEffect(f.effect('review'));
|
|
464
|
+
assert.equal(end.state,'unknown');assert.equal(end.abandonableReviewResult,undefined);
|
|
465
|
+
assert.equal(end.reviewAbandonRefusal,code);assert.match(end.reason,new RegExp(`^${code}: `));
|
|
466
|
+
const reopened=f.reopen(),before=f.getStore().snapshot();
|
|
467
|
+
const refused=reopened.abandonReview({allowed:true,reason:'try'});
|
|
468
|
+
assert.equal(refused.outcome,'rejected');assert.equal(refused.code,code);assert.match(refused.reason,/supersede-reviewed-evidence/);
|
|
469
|
+
assert.deepEqual(f.getStore().snapshot(),before);
|
|
470
|
+
},{reviewRun:run}));
|
|
471
|
+
|
|
472
|
+
// A38: the host died after the no-verdict result reached the journal but before
|
|
473
|
+
// its checkpoint: abandon_review binds that result record; replay re-derives it.
|
|
474
|
+
test('A38 a pending review with a journaled no-verdict result is abandoned and redispatched',()=>fixture(async f=>{
|
|
475
|
+
const runner=f.make();await runner.executeEffect(f.effect('develop'));
|
|
476
|
+
assert.equal((await runner.executeEffect(f.effect('review'))).state,'unknown');
|
|
477
|
+
const interrupted=f.resumePrefix('review-invocation-result',true);
|
|
478
|
+
const status=interrupted.status();
|
|
479
|
+
assert.equal(status.state,'unknown');assert.equal(status.pendingReviewInvocation,true);assert.equal(status.pendingEffectKind,undefined);
|
|
480
|
+
const abandoned=interrupted.abandonReview({allowed:true,reason:'old host and reviewer exited'});
|
|
481
|
+
assert.equal(abandoned.state,'pending_review',JSON.stringify(abandoned));assert.equal(abandoned.code,'review_abandoned');
|
|
482
|
+
const records=f.getStore().snapshot().records,last=records.at(-1).payload;
|
|
483
|
+
assert.equal(last.type,'review-invocation-abandoned');assert.equal(last.resultDigest,records.at(-2).digest);
|
|
484
|
+
assert.equal(records.at(-2).payload.type,'review-invocation-result');
|
|
485
|
+
f.options.reviewers[0].run=(request,{onEvent})=>{events(onEvent,`thread-${request.invocationId}`);
|
|
486
|
+
return {status:'succeeded',value:{verdict:'approved',packageDigest:request.payload.reviewPackage.packageDigest,
|
|
487
|
+
examinedPaths:reviewPaths(request.payload.reviewPackage),findings:[],summary:'Synthetic'}};};
|
|
488
|
+
assert.equal((await f.reopen().executeEffect(retryEffect(f))).state,'approved');
|
|
489
|
+
},{reviewRun:closedFailure('output_limit')}));
|
|
490
|
+
|
|
491
|
+
// V5 replay: review-redispatch is re-derived; forged, duplicate or over-cap records are refused.
|
|
492
|
+
test('review-redispatch replay refuses forged, duplicate and over-limit records',()=>fixture(async f=>{
|
|
493
|
+
const runner=f.make();await runner.executeEffect(f.effect('develop'));
|
|
494
|
+
await runner.executeEffect(f.effect('review'));await f.reopen().executeEffect(retryEffect(f));
|
|
495
|
+
f.reopen().abandonReview({allowed:true,reason:'stopped'});
|
|
496
|
+
await f.reopen().executeEffect({...retryEffect(f),id:'review-1-retry-2'});
|
|
497
|
+
const records=structuredClone(f.getStore().snapshot().records),config=records[0].payload.config;
|
|
498
|
+
assert.equal(readRunnerHistory(records,config,3).state.state,'blocked');
|
|
499
|
+
const at=records.findIndex(row=>row.payload.type==='review-redispatch');assert(at>0);
|
|
500
|
+
for(const change of [p=>{p.attempt=2;},p=>{p.code='review_abandoned';},p=>{p.effectId='review-1';},p=>{p.invocationId='other';},p=>{p.extra=true;},
|
|
501
|
+
p=>{delete p.reason;},p=>{p.reason='';},p=>{p.at='yesterday';}]){
|
|
502
|
+
const forged=structuredClone(records);change(forged[at].payload);
|
|
503
|
+
assert.throws(()=>readRunnerHistory(rechain(forged),config,3),{code:/^(runner_review_redispatch|invalid_input)$/});
|
|
504
|
+
}
|
|
505
|
+
// A duplicate right after the first, and a third redispatch after the second failure.
|
|
506
|
+
const duplicate=structuredClone(records.slice(0,at+1));duplicate.push(structuredClone(records[at]));
|
|
507
|
+
assert.throws(()=>readRunnerHistory(resequence(duplicate),config,3),{code:'runner_review_redispatch'});
|
|
508
|
+
const third=structuredClone(records);third.push({...structuredClone(records[at]),payload:{...records[at].payload,
|
|
509
|
+
effectId:'review-1-retry-2',invocationId:readRunnerHistory(records,config,3).state.reviewInvocation.registration.binding.invocationId}});
|
|
510
|
+
assert.throws(()=>readRunnerHistory(resequence(third),config,3),{code:'runner_review_redispatch'});
|
|
511
|
+
// A journal without the record (older version) replays the spent block unchanged;
|
|
512
|
+
// drivers read it through the same projection the host shows.
|
|
513
|
+
const older=readRunnerHistory(records.slice(0,at),config,3);assert.equal(older.state.state,'blocked');
|
|
514
|
+
assert.equal(projectedRunnerStatus(older,config).state,'blocked');assert.equal(projectedRunnerStatus(older,config).reviewRedispatchStopRequired,true);
|
|
515
|
+
assert.equal(projectedRunnerStatus(readRunnerHistory(records,config,3),config).code,'review_redispatch_limit');
|
|
516
|
+
},{timeoutMs:20,reviewRun:timeoutRun}));
|
package/scripts/cm-ai-run.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// Fixed, no-provider control entry. Executing adapters are a subsequent slice.
|
|
3
3
|
import fs from 'node:fs';
|
|
4
|
+
import {spawn as spawnChild} from 'node:child_process';
|
|
4
5
|
import path from 'node:path';
|
|
5
6
|
import {fileURLToPath} from 'node:url';
|
|
6
7
|
import {serveCmAiHost} from '../runtime/js/cm-ai/host-session.mjs';
|
|
@@ -11,6 +12,8 @@ import {recordCmAiQaAttachment} from '../runtime/js/cm-ai/cm-ai-qa-log.mjs';
|
|
|
11
12
|
import {writeCmAiQaStatus} from '../runtime/js/cm-ai/cm-ai-run-finalizer.mjs';
|
|
12
13
|
import {isSupportedExecutionPlatform} from '../runtime/js/cm-ai/execution-platform.mjs';
|
|
13
14
|
import {readExecutionSnapshot} from '../runtime/js/cm-ai/execution-snapshot.mjs';
|
|
15
|
+
import {assertControlEntry,withControlPolicyHost,controlTarget,assertExpectedControl,readControlTarget} from '../runtime/js/cm-ai/control-policy.mjs';
|
|
16
|
+
import {readRunnerHistory,projectedRunnerStatus} from '../runtime/js/cm-ai/durable-runner-state.mjs';
|
|
14
17
|
import {hasLegacyQaPlanFingerprint,previousQaMaterial,qaConfigurationSlice,qaExecutorMaterial,qaInvariantDigest,qaRevisionChain,verifyQaRevisionMaterial} from '../runtime/js/cm-ai/qa-config-revision.mjs';
|
|
15
18
|
import {hasCmAiQaRun,inspectCmAiQaRevisionTarget,recordCmAiQaConfigurationRevision} from '../runtime/js/cm-ai/cm-ai-qa-log.mjs';
|
|
16
19
|
import {prepareReviewedEvidenceSupersession,archiveReviewedEvidence,recordEvidenceSupersession,assertNoUnrecordedPriorCode} from '../runtime/js/cm-ai/reviewed-evidence-supersede.mjs';
|
|
@@ -23,11 +26,22 @@ import {JOURNAL_PAYLOAD_LIMIT,boundedReason} from '../runtime/js/cm-ai/effect-co
|
|
|
23
26
|
import {protectedScopePaths} from '../runtime/js/cm-ai/developer-adapter.mjs';
|
|
24
27
|
import {closeoutPolicyCandidates} from '../runtime/js/cm-ai/knowledge-closeout.mjs';
|
|
25
28
|
|
|
26
|
-
const usage='cm-ai-run.mjs serve --config RUN_DEFINITION.json --mode create|resume (no provider dispatch)\nNew runs bind approved specification material from specsDir; requirements may be [] or supplemental code-project files. Manifest drift blocks as spec_drift; legacy journals retain their original format.';
|
|
29
|
+
const usage='cm-ai-run.mjs inspect-history --config RUN_DEFINITION.json (validated read-only history; no owner lock or provider dispatch)\ncm-ai-run.mjs serve --config RUN_DEFINITION.json --mode create|resume (no provider dispatch)\nNew runs bind approved specification material from specsDir; requirements may be [] or supplemental code-project files. Manifest drift blocks as spec_drift; legacy journals retain their original format.';
|
|
27
30
|
const fail=code=>{throw Object.assign(new Error(code),{code});};
|
|
28
31
|
// In-process provenance only; a config flag cannot certify protected callbacks.
|
|
29
32
|
const protectedExecutions=new WeakMap();
|
|
30
33
|
|
|
34
|
+
// Launch recovery binds the durable runner projection, while controlTarget on
|
|
35
|
+
// ordinary status may additionally project current QA/specification evidence.
|
|
36
|
+
export function controlLaunchTarget(snapshot){
|
|
37
|
+
const initial=snapshot.records[0]?.payload;
|
|
38
|
+
if(initial?.type!=='init')fail('snapshot_changed');
|
|
39
|
+
const history=readRunnerHistory(snapshot.records,initial.config,initial.version);
|
|
40
|
+
const status=projectedRunnerStatus(history,initial.config);
|
|
41
|
+
return controlTarget({...status,identity:{...initial.config.identity,attempt:status.attempt},
|
|
42
|
+
packageDigest:status.reviewPackage?.packageDigest??null},snapshot);
|
|
43
|
+
}
|
|
44
|
+
|
|
31
45
|
// Fixed adapter assembly for a trusted host. The authority callbacks are never
|
|
32
46
|
// sourced from run.json or the JSONL channel. Construction performs no dispatch.
|
|
33
47
|
export async function createCodexExecution(configuration,authority){
|
|
@@ -41,16 +55,10 @@ export async function createCodexExecution(configuration,authority){
|
|
|
41
55
|
need(!['codex-independent-review-1','codex-independent-review-2'].some(value=>
|
|
42
56
|
value===config.hostContextId||value===config.developerContextId),'not_independent');
|
|
43
57
|
validCallTimeout(config.timeoutMs);
|
|
44
|
-
shape(authority,['authorizeDevelopment',
|
|
45
|
-
...['
|
|
46
|
-
need(typeof authority.authorizeDevelopment==='function'
|
|
58
|
+
shape(authority,['authorizeDevelopment',
|
|
59
|
+
...['developmentAttempt','workflow','bootstrap'].filter(key=>Object.hasOwn(authority,key))]);
|
|
60
|
+
need(typeof authority.authorizeDevelopment==='function');
|
|
47
61
|
if(Object.hasOwn(authority,'developmentAttempt'))need([1,2].includes(authority.developmentAttempt),'invalid_development_attempt');
|
|
48
|
-
if(Object.hasOwn(authority,'hostDecisionProvider')){
|
|
49
|
-
shape(authority.hostDecisionProvider,['decide','timeoutMs']);
|
|
50
|
-
need(typeof authority.hostDecisionProvider.decide==='function'
|
|
51
|
-
&&Number.isInteger(authority.hostDecisionProvider.timeoutMs)&&authority.hostDecisionProvider.timeoutMs>0
|
|
52
|
-
&&authority.hostDecisionProvider.timeoutMs<=60000,'invalid_input');
|
|
53
|
-
}
|
|
54
62
|
const disabledSkills=config.disabledSkills??[];
|
|
55
63
|
need(Array.isArray(disabledSkills)&&disabledSkills.length<=4096
|
|
56
64
|
&&disabledSkills.every(p=>typeof p==='string'&&path.isAbsolute(p)&&!/[\n\r\0]/.test(p)),'invalid_review_config');
|
|
@@ -99,18 +107,23 @@ export async function createCodexExecution(configuration,authority){
|
|
|
99
107
|
const execution={
|
|
100
108
|
configuration:config,timeoutMs:config.timeoutMs,excludedContexts:[config.hostContextId],check,
|
|
101
109
|
...(bootstrap?{bootstrap}:{}),
|
|
102
|
-
hostDecision:json(authority.hostDecision),
|
|
103
110
|
...workflowCapabilities,
|
|
104
111
|
...(Object.hasOwn(authority,'developmentAttempt')?{developmentAttempt:authority.developmentAttempt}:{}),
|
|
105
|
-
...(Object.hasOwn(authority,'hostDecisionProvider')?{hostDecisionProvider:authority.hostDecisionProvider}:{}),
|
|
106
112
|
developer:{provider:'codex',requestedModel:config.developerModel,contextId:config.developerContextId,
|
|
107
113
|
run:async(request,control)=>{
|
|
108
114
|
const bound=readCodexDeveloperRequest(request);
|
|
109
115
|
const decision=json(await authority.authorizeDevelopment(bound));
|
|
110
|
-
shape(decision,['status']);need(decision.status==='approved','
|
|
116
|
+
shape(decision,['status']);need(decision.status==='approved','invalid_development_attempt');
|
|
111
117
|
need(!control.signal.aborted,'cancelled');
|
|
112
118
|
need(!used.has(bound.invocationId),'duplicate_dispatch');used.add(bound.invocationId);
|
|
113
|
-
|
|
119
|
+
// The runner journals the worker identity around the spawn (develop-worker).
|
|
120
|
+
const onWorker=typeof control.onWorker==='function'?control.onWorker:null;
|
|
121
|
+
const worker=codexDeveloperWorker({cwd:config.codeProject,model:config.developerModel,timeoutMs:config.timeoutMs,specsRoot,
|
|
122
|
+
spawnProcess:(cli,args,options)=>{
|
|
123
|
+
onWorker?.({phase:'spawning'});const child=spawnChild(cli,args,options);
|
|
124
|
+
if(Number.isInteger(child.pid))try{onWorker?.({phase:'started',pid:child.pid});}
|
|
125
|
+
catch(error){child.on('error',()=>{});child.stdin?.on('error',()=>{});try{process.kill(-child.pid,'SIGKILL');}catch{}throw error;}
|
|
126
|
+
return child;}});
|
|
114
127
|
// Documentation stays inside the same authorized sandbox invocation and
|
|
115
128
|
// original checks/handoff/Review. The semantic bridge never writes it.
|
|
116
129
|
const {isFinalCmAiTask}=await import('../runtime/js/cm-ai/cm-ai-admission.mjs');
|
|
@@ -126,8 +139,7 @@ export async function createCodexExecution(configuration,authority){
|
|
|
126
139
|
reviewers:[{id:'reviewer',adapterId:'codex-review-adapter',provider:'codex',requestedModel:config.reviewerModel,
|
|
127
140
|
allowed:true,available:true,contexts:['codex-independent-review-1','codex-independent-review-2'],
|
|
128
141
|
run:(request,control)=>createCodexReviewRun(codexWorker(reviewOptions))(request,control)}],
|
|
129
|
-
reviewInvocation:{developerThreadId:config.developerContextId,excludedThreadIds:[config.hostContextId],
|
|
130
|
-
authorize:authority.authorizeReview},
|
|
142
|
+
reviewInvocation:{developerThreadId:config.developerContextId,excludedThreadIds:[config.hostContextId],hostContextId:config.hostContextId},
|
|
131
143
|
};
|
|
132
144
|
if(specsRoot!==null){
|
|
133
145
|
// Do not permit later replacement of the developer/check or addition of an
|
|
@@ -220,7 +232,6 @@ export function runConfigMaterial(definition,execution,{parallelSelection=null,b
|
|
|
220
232
|
...(knowledgeCloseout===null?{}:{knowledgeCloseout}),
|
|
221
233
|
...(bootstrapConfig?{bootstrap:bootstrapConfig}:{}),
|
|
222
234
|
...(Object.hasOwn(execution,'developmentAttempt')?{developmentAuthorization:'per-attempt-v1'}:{}),
|
|
223
|
-
...(execution.hostDecisionProvider?{hostDecisionProvider:{version:1,timeoutMs:execution.hostDecisionProvider.timeoutMs}}:{}),
|
|
224
235
|
...(execution.qaDecisionProvider?{qaDecisionProvider:'host-v1',qaTimeoutMs:execution.qaDecisionProvider.timeoutMs}:{}),
|
|
225
236
|
...(execution.qaExecutor?{qaExecutor:qaExecutorMaterial(execution.qaExecutor,legacyQa)}:{}),
|
|
226
237
|
...(execution.applicableAgentFiles?{applicableAgentFiles:execution.applicableAgentFiles}:{}),
|
|
@@ -228,6 +239,27 @@ export function runConfigMaterial(definition,execution,{parallelSelection=null,b
|
|
|
228
239
|
...(execution.documentationResult?{documentationResult:execution.documentationResult}:{}),
|
|
229
240
|
...(execution.documentationSync?{documentationSync:{version:1,paths:execution.documentationSync.paths}}:{})};
|
|
230
241
|
}
|
|
242
|
+
// Inspect only the validated store envelope. Do not replay old grants or open
|
|
243
|
+
// a writer merely to explain an unsupported historical execution.
|
|
244
|
+
export function inspectRunHistory(definition){
|
|
245
|
+
const snapshot=readExecutionSnapshot({specsRoot:definition.specsDir,
|
|
246
|
+
identity:{repositoryId:definition.identity.repositoryId,runId:definition.identity.runId}});
|
|
247
|
+
return {identity:snapshot.identity,revision:snapshot.revision,fingerprints:snapshot.fingerprints,
|
|
248
|
+
records:snapshot.records.map(record=>({seq:record.seq,id:record.id,kind:record.kind,type:record.payload.type??null,
|
|
249
|
+
legacyReviewGrant:record.payload.type==='review-invocation-registered'
|
|
250
|
+
&&(Object.hasOwn(record.payload,'grant')||Object.hasOwn(record.payload,'authorizationAt'))}))};
|
|
251
|
+
}
|
|
252
|
+
export function assertSupportedResumeHistory(definition){
|
|
253
|
+
let snapshot;
|
|
254
|
+
try{snapshot=readExecutionSnapshot({specsRoot:definition.specsDir,
|
|
255
|
+
identity:{repositoryId:definition.identity.repositoryId,runId:definition.identity.runId}});}
|
|
256
|
+
catch(error){if(error.code==='ENOENT')return null;throw error;}
|
|
257
|
+
if(snapshot.records.some(record=>record.payload.type==='review-invocation-registered'
|
|
258
|
+
&&(Object.hasOwn(record.payload,'grant')||Object.hasOwn(record.payload,'authorizationAt'))))
|
|
259
|
+
throw Object.assign(new Error('runner_invocation'),{code:'runner_invocation',
|
|
260
|
+
reason:'旧授权协议不支持恢复。原运行与审查历史已保留;重复原参数不会恢复。只读查看历史:node scripts/cm-ai-run.mjs inspect-history --config RUN_DEFINITION.json(使用原运行定义文件)。'});
|
|
261
|
+
return snapshot;
|
|
262
|
+
}
|
|
231
263
|
const LEGACY_QA_FINGERPRINT_REASON='运行指纹与当前配置不符。若此运行由之前的版本创建,它的指纹还含有当时生效的 CM 配置'
|
|
232
264
|
+'(项目 .cm-workflow.yml、~/.cm-workflow/runtimes.yml 与插件内置默认值):把这些配置恢复为创建时的内容即可恢复;'
|
|
233
265
|
+'现在新建的运行不再把这些可变配置写进指纹。否则请核对 run.json、--workflow-config、宿主身份及授权参数是否与创建时一致。';
|
|
@@ -248,7 +280,7 @@ export async function openControlRun(definition,mode,execution=null,options={}){
|
|
|
248
280
|
return {...result,close:()=>{try{close();}finally{guard?.close();}}};
|
|
249
281
|
}catch(error){guard?.close();throw error;}
|
|
250
282
|
}
|
|
251
|
-
async function openControlRunOwned(definition,mode,execution=null,{rerunUnknownQa=false,rerunBlockedQa=false,qaEnvironmentFailure=null,parallelSelection=null,qaConfigRevision=null,supersedeReason=null,acceptSupersededCodeDrift=false,allowAbandonReview=false,allowAbandonEffect=false,allowBootstrapReviewRecovery=false,holdRevision=false,specRebindReason=null}={},acquireGuard=async()=>{}){
|
|
283
|
+
async function openControlRunOwned(definition,mode,execution=null,{rerunUnknownQa=false,rerunBlockedQa=false,qaEnvironmentFailure=null,parallelSelection=null,qaConfigRevision=null,supersedeReason=null,acceptSupersededCodeDrift=false,allowAbandonReview=false,allowAbandonEffect=false,allowBootstrapReviewRecovery=false,allowDevelopRedo=false,holdRevision=false,specRebindReason=null,expectedControl=null}={},acquireGuard=async()=>{}){
|
|
252
284
|
// Check before importing node:sqlite: legacy Node users get a useful error.
|
|
253
285
|
if(!isSupportedExecutionPlatform())fail('unsupported_runner_platform');
|
|
254
286
|
const {conversationProtection,externalConversationDefinition}=await import('../runtime/js/cm-ai/host-conversation-execution.mjs');
|
|
@@ -262,6 +294,7 @@ async function openControlRunOwned(definition,mode,execution=null,{rerunUnknownQ
|
|
|
262
294
|
if(supersedeReason!==null&&mode!=='create')fail('supersede_unavailable');
|
|
263
295
|
if(allowAbandonEffect&&mode!=='resume')fail('effect_abandon_unavailable');
|
|
264
296
|
if(allowBootstrapReviewRecovery&&mode!=='resume')fail('bootstrap_review_recovery_unavailable');
|
|
297
|
+
if(allowDevelopRedo&&mode!=='resume')fail('develop_redo_unavailable');
|
|
265
298
|
if(typeof holdRevision!=='boolean')fail('invalid_input');
|
|
266
299
|
if(specRebindReason!==null&&(mode!=='resume'||execution===null||typeof specRebindReason!=='string'||!specRebindReason.trim()
|
|
267
300
|
||Buffer.byteLength(specRebindReason,'utf8')>500||/[\r\n\0]/.test(specRebindReason)))fail('spec_rebind_unavailable');
|
|
@@ -273,13 +306,27 @@ async function openControlRunOwned(definition,mode,execution=null,{rerunUnknownQ
|
|
|
273
306
|
if(typeof rerunUnknownQa!=='boolean'||typeof rerunBlockedQa!=='boolean'||rerunUnknownQa&&rerunBlockedQa
|
|
274
307
|
||(rerunUnknownQa||rerunBlockedQa)&&(mode!=='resume'||!execution?.qaExecutor))fail('qa_recovery_authorization_required');
|
|
275
308
|
const {openTaskExecutionStore}=await import('../runtime/js/cm-ai/task-owner.mjs');
|
|
309
|
+
const controlPolicy=execution?.configuration?.controlPolicy??null;
|
|
310
|
+
const launchRecovery=qaConfigRevision!==null||rerunUnknownQa||rerunBlockedQa||specRebindReason!==null;
|
|
311
|
+
if(controlPolicy){
|
|
312
|
+
if(supersedeReason!==null)fail('supersede_unavailable');
|
|
313
|
+
if(launchRecovery){
|
|
314
|
+
if(mode!=='resume')fail('supersede_unavailable');
|
|
315
|
+
if(expectedControl===null)fail('invalid_input');
|
|
316
|
+
expectedControl=readControlTarget(expectedControl);
|
|
317
|
+
}else if(expectedControl!==null)fail('invalid_input');
|
|
318
|
+
}
|
|
319
|
+
if(mode==='resume'){
|
|
320
|
+
const snapshot=assertSupportedResumeHistory(definition);
|
|
321
|
+
if(snapshot?.records.length)assertControlEntry(snapshot,controlPolicy);
|
|
322
|
+
}
|
|
276
323
|
const {createCmAiHost}=await import('../runtime/js/cm-ai/host.mjs');
|
|
277
324
|
const {inspectCmAiAdmission,matchesCmAiTaskSelection,explainCmAiTaskSelection,selectedFeature}=await import('../runtime/js/cm-ai/cm-ai-admission.mjs');
|
|
278
325
|
const {captureReviewBaseline}=await import('../runtime/js/cm-ai/review-package.mjs');
|
|
279
326
|
if(execution!==null){
|
|
280
327
|
const {shape,json,validCallTimeout}=await import('../runtime/js/cm-ai/effect-contract.mjs');
|
|
281
|
-
shape(execution,['configuration','developer','reviewers','reviewInvocation','check','
|
|
282
|
-
...['bootstrap','developmentAttempt','
|
|
328
|
+
shape(execution,['configuration','developer','reviewers','reviewInvocation','check','excludedContexts','timeoutMs',
|
|
329
|
+
...['bootstrap','developmentAttempt','qaDecisionProvider','qaLogHome','qaExecutor','applicableAgentFiles','documentationProvider','documentationResult','documentationSync','verificationGate'].filter(key=>Object.hasOwn(execution,key))]);
|
|
283
330
|
json(execution.configuration);validCallTimeout(execution.timeoutMs);
|
|
284
331
|
if(Object.hasOwn(execution.configuration,'codeProject'))
|
|
285
332
|
if(execution.configuration.codeProject!==definition.codeProject)fail('execution_root_mismatch');
|
|
@@ -435,6 +482,15 @@ async function openControlRunOwned(definition,mode,execution=null,{rerunUnknownQ
|
|
|
435
482
|
const {material:configMaterial,fingerprints,store,attaching,priorMaterial,chain,attached}=opened;
|
|
436
483
|
const knowledgeCloseout=configMaterial.knowledgeCloseout??null;
|
|
437
484
|
try{
|
|
485
|
+
// The store owns the actual writer lock. Check before constructing the
|
|
486
|
+
// runner (which may journal a session join), audit repair, or recovery.
|
|
487
|
+
if(controlPolicy&&launchRecovery){
|
|
488
|
+
try{assertExpectedControl(expectedControl,controlLaunchTarget(store.snapshot()));}
|
|
489
|
+
catch(error){
|
|
490
|
+
if(error.code==='snapshot_changed')error.reason='启动恢复目标已经变化;核对当前状态和原操作,不能自动替换原 launchControlTarget 后重试。';
|
|
491
|
+
throw error;
|
|
492
|
+
}
|
|
493
|
+
}
|
|
438
494
|
let runnerMode=mode;
|
|
439
495
|
if(mode==='resume'&&store.snapshot().records.length===0){
|
|
440
496
|
// Only the genuine, fingerprint-matching empty initializer can be finished.
|
|
@@ -450,11 +506,12 @@ async function openControlRunOwned(definition,mode,execution=null,{rerunUnknownQ
|
|
|
450
506
|
...(knowledgeCloseout===null?{}:{knowledgeCloseout}),
|
|
451
507
|
...(execution?.configuration.executionPolicy?{executionPolicy:execution.configuration.executionPolicy}:{}),
|
|
452
508
|
...(execution?.configuration.externalModels?{externalModels:execution.configuration.externalModels}:{}),excludedContexts:['control-host'],
|
|
509
|
+
...(controlPolicy?{controlPolicy}:{}),
|
|
453
510
|
developer:{provider:'codex',requestedModel:'unconfigured',contextId:'control-developer',run:unavailable},
|
|
454
511
|
reviewers:[],check:unavailable,taskCompletion:{reviewsDir,handoffs},taskLearning:{feature},
|
|
455
512
|
persistence:{store,mode:runnerMode,version:execution===null?2:3},
|
|
456
513
|
...(execution===null?{}:{providerDevelopment:protectedExecutions.has(execution)
|
|
457
|
-
||Boolean(execution.configuration.providerDevelopment)}),
|
|
514
|
+
||Boolean(execution.configuration.providerDevelopment),protectedDevelopment:conversationProtection(execution)!==null}),
|
|
458
515
|
...(execution===null?{}:{developer,reviewers:execution.reviewers,
|
|
459
516
|
...(execution.bootstrap?{bootstrap:execution.bootstrap}:{}),
|
|
460
517
|
reviewInvocation:execution.reviewInvocation,check:execution.check,
|
|
@@ -465,15 +522,15 @@ async function openControlRunOwned(definition,mode,execution=null,{rerunUnknownQ
|
|
|
465
522
|
entry:{specsDir,codeProject,feature,identity,rerunUnknownQa,rerunBlockedQa,
|
|
466
523
|
...(definition.featureSelection?{featureSelection:definition.featureSelection.feature}:{}),
|
|
467
524
|
...(knowledgeCloseout===null?{}:{knowledgeCloseout,...(definition.codeProjects?{codeProjects:definition.codeProjects}:{})}),
|
|
468
|
-
...(qaEnvironmentFailure===null?{}:{qaEnvironmentFailure}),allowAbandonReview,allowAbandonEffect,allowBootstrapReviewRecovery,...(holdRevision?{holdRevision}:{}),...(selection===null?{}:{parallelSelection:selection}),...(execution===null?{}:{
|
|
469
|
-
...Object.fromEntries(['developmentAttempt','
|
|
525
|
+
...(qaEnvironmentFailure===null?{}:{qaEnvironmentFailure}),allowAbandonReview,allowAbandonEffect,allowBootstrapReviewRecovery,allowDevelopRedo,...(holdRevision?{holdRevision}:{}),...(selection===null?{}:{parallelSelection:selection}),...(execution===null?{}:{
|
|
526
|
+
...Object.fromEntries(['developmentAttempt','qaDecisionProvider','qaLogHome','qaExecutor','applicableAgentFiles','documentationProvider','documentationResult'].filter(key=>Object.hasOwn(execution,key)).map(key=>[key,execution[key]]))})},
|
|
470
527
|
});
|
|
471
528
|
const logAbandonments=()=>{
|
|
472
529
|
for(const record of store.snapshot().records.filter(row=>row.payload.type==='review-invocation-abandoned'))
|
|
473
530
|
recordReviewAbandonment({specsDir,codeProject,feature,identity,record,
|
|
474
531
|
runtime:execution?.reviewers?.[0]?.provider??'codex',
|
|
475
532
|
...(execution?.qaLogHome?{logHome:execution.qaLogHome}:{})});
|
|
476
|
-
for(const record of store.snapshot().records.filter(row=>row.payload.type
|
|
533
|
+
for(const record of store.snapshot().records.filter(row=>['effect-abandoned','effect-interrupted'].includes(row.payload.type)))
|
|
477
534
|
recordEffectAbandonment({specsDir,codeProject,feature,identity,record,
|
|
478
535
|
runtime:execution?.developer?.provider??'codex',
|
|
479
536
|
...(execution?.qaLogHome?{logHome:execution.qaLogHome}:{})});
|
|
@@ -521,15 +578,17 @@ async function openControlRunOwned(definition,mode,execution=null,{rerunUnknownQ
|
|
|
521
578
|
// Replaying or repairing its audit mirror above is not new execution.
|
|
522
579
|
if(!beforeQa)writeCmAiQaStatus({specsDir,feature,identity:current.identity,phase:'configuration_revised'});
|
|
523
580
|
}
|
|
524
|
-
|
|
581
|
+
const legacyHost={async handle(request){
|
|
525
582
|
if(execution===null&&!['status','cancel'].includes(request.operation)){
|
|
526
583
|
// Do not imply an unavailable execution adapter was dispatched.
|
|
527
584
|
return {outcome:'blocked',code:'execution_adapter_required',providerCalls:0};
|
|
528
585
|
}
|
|
529
586
|
const result=await host.handle(request);
|
|
530
|
-
if(['abandon_review','abandon_effect'].includes(request.operation)&&result.outcome
|
|
587
|
+
if(['abandon_review','abandon_effect'].includes(request.operation)&&['abandoned','recorded'].includes(result.outcome))logAbandonments();
|
|
531
588
|
return result;
|
|
532
|
-
}}
|
|
589
|
+
}};
|
|
590
|
+
const controlHost=controlPolicy?withControlPolicyHost(legacyHost,{identity,snapshot:()=>store.snapshot(),launchTarget:controlLaunchTarget}):null;
|
|
591
|
+
return {host:legacyHost,...(controlHost?{controlHost}:{}),inspectFixAssociation:host.inspectFixAssociation,acceptCompletedFix:host.acceptCompletedFix,
|
|
533
592
|
checkpoint:()=>store.snapshot().revision,close:()=>store.close()};
|
|
534
593
|
}catch(error){store.close();throw error;}
|
|
535
594
|
}
|
|
@@ -540,6 +599,9 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
540
599
|
if(argv.length===1&&['--help','-h'].includes(argv[0])){output.write(usage+'\n');return 0;}
|
|
541
600
|
let run;
|
|
542
601
|
try{
|
|
602
|
+
if(argv.length===3&&argv[0]==='inspect-history'&&argv[1]==='--config'){
|
|
603
|
+
output.write(JSON.stringify(inspectRunHistory(readRunDefinition(argv[2])))+'\n');return 0;
|
|
604
|
+
}
|
|
543
605
|
if(argv.length!==5||argv[0]!=='serve'||argv[1]!=='--config'||argv[3]!=='--mode')fail('invalid_arguments');
|
|
544
606
|
run=await openControlRun(readRunDefinition(argv[2]),argv[4],execution);
|
|
545
607
|
if(run.blocked){output.write(JSON.stringify({outcome:'blocked',admission:run.blocked})+'\n');return 1;}
|
|
@@ -548,7 +610,8 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
548
610
|
// Config diagnostics contain field names/reasons, never field values or provider text.
|
|
549
611
|
const code=typeof cause.code==='string'&&(/^[a-z_]+$/.test(cause.code)
|
|
550
612
|
||cause.code.startsWith('invalid_config: '))?cause.code:'control_failed';
|
|
551
|
-
|
|
613
|
+
const reason=code==='runner_invocation'&&typeof cause.reason==='string'?cause.reason:null;
|
|
614
|
+
error.write(JSON.stringify({error:{code,...(reason?{reason}:{})}})+'\n');return 1;
|
|
552
615
|
}finally{run?.close();}
|
|
553
616
|
}
|
|
554
617
|
if(process.argv[1]&&path.resolve(process.argv[1])===fileURLToPath(import.meta.url))process.exitCode=await main();
|