@aibyzero/cm-workflow 0.16.5 → 0.16.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.codex-plugin/plugin.json +1 -1
- package/AGENTS.md +14 -0
- package/CHANGELOG.md +19 -1
- package/README.md +17 -4
- package/THIRD_PARTY_NOTICES.md +9 -0
- package/VERSION +1 -1
- package/docs/architecture.md +43 -0
- package/docs/execution-optimizations.md +33 -0
- package/docs/external-models.md +114 -0
- package/docs/fixes/.reviews/20260929-bootstrap-unchanged-review-r1.md +7 -0
- package/docs/fixes/.reviews/20260930-develop-package-limit-recovery-r4.md +9 -0
- package/docs/fixes/20260929-bootstrap-rule-refresh-conflict.md +22 -0
- package/docs/fixes/20260929-bootstrap-unchanged-review.md +26 -0
- package/docs/fixes/20260930-develop-package-limit-recovery.md +65 -0
- package/docs/human-correction.md +31 -0
- package/docs/installation.md +28 -7
- package/docs/js-workflow-control.md +96 -6
- package/docs/live-evidence-drivers.md +62 -0
- package/docs/next-steps.md +15 -10
- package/docs/untested-branches.md +27 -4
- package/docs/user-guide.md +23 -8
- package/install-codex.sh +28 -11
- package/package.json +1 -1
- package/runtime/js/cm-ai/claude-review-adapter.mjs +7 -4
- package/runtime/js/cm-ai/claude-tool-preview.mjs +4 -4
- package/runtime/js/cm-ai/cm-ai-admission.mjs +34 -10
- package/runtime/js/cm-ai/cm-ai-context-refresh.mjs +9 -5
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +111 -34
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +93 -31
- package/runtime/js/cm-ai/cm-ai-run-finalizer.mjs +13 -57
- package/runtime/js/cm-ai/codex-config.mjs +3 -2
- package/runtime/js/cm-ai/codex-review-adapter.mjs +34 -15
- package/runtime/js/cm-ai/committed-rule-basis.mjs +76 -0
- package/runtime/js/cm-ai/developer-adapter.mjs +8 -5
- package/runtime/js/cm-ai/drive-bootstrap.mjs +22 -12
- package/runtime/js/cm-ai/drive-core.mjs +9 -3
- package/runtime/js/cm-ai/durable-runner-state.mjs +146 -14
- package/runtime/js/cm-ai/effect-contract.mjs +1 -1
- package/runtime/js/cm-ai/execution-policy.mjs +58 -0
- package/runtime/js/cm-ai/external-group-models.mjs +53 -0
- package/runtime/js/cm-ai/external-model-launch.mjs +23 -0
- package/runtime/js/cm-ai/external-models.mjs +52 -0
- package/runtime/js/cm-ai/external-run-guard.mjs +96 -0
- package/runtime/js/cm-ai/host-bootstrap.mjs +70 -20
- package/runtime/js/cm-ai/host-check.mjs +30 -4
- package/runtime/js/cm-ai/host-conversation-execution.mjs +59 -17
- package/runtime/js/cm-ai/host-documentation.mjs +2 -2
- package/runtime/js/cm-ai/host-progress.mjs +80 -0
- package/runtime/js/cm-ai/host-project-execution.mjs +16 -11
- package/runtime/js/cm-ai/host-qa-executor.mjs +54 -8
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +22 -5
- package/runtime/js/cm-ai/host-session.mjs +1 -1
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +3 -1
- package/runtime/js/cm-ai/knowledge-closeout.mjs +56 -0
- package/runtime/js/cm-ai/legacy-model-run-preview.mjs +24 -0
- package/runtime/js/cm-ai/legacy-model-settings.mjs +59 -0
- package/runtime/js/cm-ai/live-evidence.mjs +96 -0
- package/runtime/js/cm-ai/log-rows.mjs +36 -0
- package/runtime/js/cm-ai/model-configuration-file.mjs +63 -0
- package/runtime/js/cm-ai/model_configuration_write.py +214 -0
- package/runtime/js/cm-ai/native-usage-log.mjs +26 -0
- package/runtime/js/cm-ai/operator-guidance.mjs +89 -0
- package/runtime/js/cm-ai/owned-process-cleanup.mjs +22 -0
- package/runtime/js/cm-ai/provider-review-observation.mjs +15 -0
- package/runtime/js/cm-ai/provider-usage.mjs +39 -0
- package/runtime/js/cm-ai/review-package.mjs +11 -0
- package/runtime/js/cm-ai/review-presentation.mjs +45 -0
- package/runtime/js/cm-ai/review-reconciliation.mjs +20 -0
- package/runtime/js/cm-ai/status-projection.mjs +93 -0
- package/runtime/js/cm-ai/task-runner.mjs +176 -25
- package/runtime/js/cm-ai/tool-preview.mjs +8 -4
- package/runtime/js/cm-ai/worker-claude-developer.mjs +16 -7
- package/runtime/js/cm-ai/worker-claude.mjs +63 -19
- package/runtime/js/cm-ai/worker-codex-developer.mjs +15 -9
- package/runtime/js/cm-ai/worker-codex.mjs +45 -19
- package/runtime/js/cm-fix/cause-evidence.mjs +5 -3
- package/runtime/js/cm-fix/cause-invocation.mjs +6 -3
- package/runtime/js/cm-fix/cause-package.mjs +10 -1
- package/runtime/js/cm-fix/execution.mjs +183 -40
- package/runtime/js/cm-fix/final-review.mjs +18 -10
- package/runtime/js/cm-fix/finish.mjs +2 -19
- package/runtime/js/cm-fix/host-review.mjs +25 -6
- package/runtime/js/cm-fix/host.mjs +4 -1
- package/runtime/js/cm-fix/layout.mjs +1 -1
- package/runtime/js/cm-fix/log-events.mjs +29 -0
- package/runtime/js/cm-fix/metrics.mjs +3 -2
- package/runtime/js/cm-fix/progress.mjs +4 -0
- package/runtime/js/cm-fix/review-reconciliation.mjs +64 -0
- package/runtime/js/cm-prd/analysis.mjs +5 -2
- package/runtime/js/cm-prd/response-recovery.mjs +23 -0
- package/runtime/js/cm-prd/review-host.mjs +2 -1
- package/runtime/js/cm-prd/review-publication.mjs +23 -13
- package/runtime/js/cm-prd/review-time.mjs +29 -0
- package/runtime/js/cm-prd/session.mjs +53 -6
- package/runtime/js/cm-security/finalize.mjs +32 -0
- package/runtime/js/cm-test/recovery.mjs +4 -4
- package/runtime/review.md +5 -0
- package/runtime/task-gates.md +6 -0
- package/runtime/workflow-config.md +10 -1
- package/scripts/cm-ai-admission.mjs +14 -3
- package/scripts/cm-ai-batch-drive.mjs +52 -23
- package/scripts/cm-ai-batch-drive.test.mjs +47 -2
- package/scripts/cm-ai-batch-host.mjs +44 -16
- package/scripts/cm-ai-batch-run.mjs +77 -29
- package/scripts/cm-ai-bootstrap-flow.test.mjs +3 -2
- package/scripts/cm-ai-bootstrap-merge.test.mjs +118 -1
- package/scripts/cm-ai-bootstrap.test.mjs +80 -87
- package/scripts/cm-ai-conversation-entry-ops.test.mjs +15 -0
- package/scripts/cm-ai-develop-driver-gaps.test.mjs +102 -0
- package/scripts/cm-ai-drive-bootstrap-rules.test.mjs +2 -2
- package/scripts/cm-ai-drive.mjs +73 -28
- package/scripts/cm-ai-drive.test.mjs +119 -1
- package/scripts/cm-ai-feature-selection.test.mjs +178 -0
- package/scripts/cm-ai-host.mjs +79 -27
- package/scripts/cm-ai-host.test.mjs +88 -0
- package/scripts/cm-ai-operator-guidance.test.mjs +94 -0
- package/scripts/cm-ai-progress.test.mjs +521 -0
- package/scripts/cm-ai-protected-scope.test.mjs +194 -0
- package/scripts/cm-ai-qa-config-revision.test.mjs +21 -0
- package/scripts/cm-ai-review-failure.test.mjs +71 -11
- package/scripts/cm-ai-run.mjs +94 -19
- package/scripts/cm-ai-run.test.mjs +2 -1
- package/scripts/cm-bootstrap-review-recovery.test.mjs +70 -0
- package/scripts/cm-check-drive.test.mjs +1 -0
- package/scripts/cm-check-runtime.sh +11 -0
- package/scripts/cm-claude-install-layout.test.mjs +26 -0
- package/scripts/cm-claude-probe.test.mjs +1 -1
- package/scripts/cm-codex-plugin-metadata.py +83 -0
- package/scripts/cm-codex-plugin-metadata.test.mjs +55 -0
- package/scripts/cm-efficiency-checks.test.mjs +37 -0
- package/scripts/cm-efficiency-diagnostics.test.mjs +74 -0
- package/scripts/cm-efficiency-offline.mjs +35 -0
- package/scripts/cm-efficiency-policy.test.mjs +48 -0
- package/scripts/cm-efficiency-presentation.test.mjs +35 -0
- package/scripts/cm-efficiency-response.test.mjs +117 -0
- package/scripts/cm-efficiency-usage.test.mjs +148 -0
- package/scripts/cm-external-batch-host.test.mjs +157 -0
- package/scripts/cm-external-fix-host.test.mjs +281 -0
- package/scripts/cm-external-fix-reconciliation.test.mjs +105 -0
- package/scripts/cm-external-group-models.test.mjs +60 -0
- package/scripts/cm-external-model-host.test.mjs +180 -0
- package/scripts/cm-external-model-recovery.test.mjs +108 -0
- package/scripts/cm-external-models.test.mjs +89 -0
- package/scripts/cm-external-process-cleanup.test.mjs +71 -0
- package/scripts/cm-external-qa-fix.test.mjs +170 -0
- package/scripts/cm-external-review-reconciliation.test.mjs +314 -0
- package/scripts/cm-fix-drive.mjs +28 -13
- package/scripts/cm-fix-final-review.test.mjs +11 -6
- package/scripts/cm-fix-host.mjs +17 -10
- package/scripts/cm-fix-large-log.test.mjs +113 -0
- package/scripts/cm-fix-protected-edits.test.mjs +12 -0
- package/scripts/cm-fix-rediagnosis.test.mjs +168 -0
- package/scripts/cm-fix-review-budget.test.mjs +7 -1
- package/scripts/cm-host-qa-executor.test.mjs +329 -3
- package/scripts/cm-knowledge-closeout.test.mjs +160 -0
- package/scripts/cm-live-evidence.test.mjs +64 -0
- package/scripts/cm-log-event.mjs +34 -7
- package/scripts/cm-log-event.py +15 -0
- package/scripts/cm-model-setup.mjs +79 -0
- package/scripts/cm-prd-drive.mjs +32 -11
- package/scripts/cm-prd-drive.test.mjs +15 -0
- package/scripts/cm-prd-host.mjs +26 -6
- package/scripts/cm-prd-host.test.mjs +4 -0
- package/scripts/cm-prd-review-host.test.mjs +17 -0
- package/scripts/cm-prd-session-recovery.test.mjs +44 -2
- package/scripts/cm-prd-task-grouping.test.mjs +206 -0
- package/scripts/cm-release-smoke.sh +5 -1
- package/scripts/cm-review-scope-recovery.test.mjs +5 -3
- package/scripts/cm-runtime-i18n.mjs +15 -4
- package/scripts/cm-runtime-install.mjs +8 -4
- package/scripts/cm-runtime.mjs +116 -23
- package/scripts/cm-runtime.test.mjs +121 -12
- package/scripts/cm-security.test.mjs +32 -0
- package/scripts/cm-task-gate-correction.test.mjs +117 -0
- package/scripts/cm-task-gate.mjs +146 -10
- package/scripts/cm-task-gate.py +1 -0
- package/scripts/cm-test-branch-impact.test.mjs +11 -0
- package/scripts/cm-test-drive.mjs +10 -4
- package/scripts/cm-test-drive.test.mjs +14 -1
- package/scripts/cm-tool-preview-context.test.mjs +12 -0
- package/scripts/cm-usage-report.py +22 -3
- package/scripts/cm-workflow-config.mjs +10 -1
- package/scripts/fixtures/bootstrap-review-runner.mjs +102 -0
- package/scripts/fixtures/live-evidence-driver.mjs +35 -0
- package/scripts/fixtures/process-cleanup.mjs +3 -1
- package/scripts/test-cm-native-usage.py +62 -0
- package/scripts/test-external-model-setup.py +91 -0
- package/scripts/test-model-configuration-write.py +201 -0
- package/scripts/test-npm-install.py +10 -1
- package/skills/cm-ai/SKILL.md +2 -2
- package/skills/cm-ai/references/N1-init.md +1 -1
- package/skills/cm-ai/references/N8-finish.md +5 -0
- package/skills/cm-ai/references/js-host.md +16 -7
- package/skills/cm-ai/references/knowledge-closeout.md +90 -0
- package/skills/cm-fix/SKILL.md +1 -1
- package/skills/cm-fix/references/js-host.md +30 -2
- package/skills/cm-prd/SKILL.md +5 -4
- package/skills/cm-prd/references/spec-self-check.md +3 -1
- package/skills/cm-runtime/SKILL.md +29 -6
- package/skills/cm-security/SKILL.md +4 -2
- package/skills/cm-security/references/scan-contract.md +1 -0
- package/templates/cm-workflow.yml +1 -1
|
@@ -3,6 +3,7 @@ import fs from 'node:fs';
|
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import {spawn} from 'node:child_process';
|
|
5
5
|
import readline from 'node:readline';
|
|
6
|
+
import {guidanceText} from './operator-guidance.mjs';
|
|
6
7
|
|
|
7
8
|
export const stderr=line=>process.stderr.write(`[drive] ${line}\n`);
|
|
8
9
|
export const stop=(code,line)=>{stderr(line);process.exit(code);};
|
|
@@ -53,6 +54,7 @@ const rejectedReplyHint=code=>code==='host_response_too_large'
|
|
|
53
54
|
// A returned refusal closes the session without any operation and exits 2.
|
|
54
55
|
export function driveHost({host,args,cwd,operation,request={},answers,paths,answerFor,beforeRequest=null}){
|
|
55
56
|
const child=spawn(process.execPath,[host,...args],{cwd,stdio:['pipe','pipe','pipe']});
|
|
57
|
+
const control=new AbortController();
|
|
56
58
|
child.stderr.on('data',chunk=>process.stderr.write(chunk));
|
|
57
59
|
// After a rejected reply the session is ended; later rows get no answer.
|
|
58
60
|
const send=value=>{if(!child.stdin.writableEnded)child.stdin.write(JSON.stringify(value)+'\n');};
|
|
@@ -69,7 +71,8 @@ export function driveHost({host,args,cwd,operation,request={},answers,paths,answ
|
|
|
69
71
|
}
|
|
70
72
|
if(row.type==='host_request'){
|
|
71
73
|
let result;
|
|
72
|
-
try{result=await answerFor(row,answers,paths);}catch(error){stderr(`应答 ${row.kind} 失败:${error.message}`);result=null;}
|
|
74
|
+
try{result=await answerFor(row,answers,paths,{signal:control.signal});}catch(error){stderr(`应答 ${row.kind} 失败:${error.message}`);result=null;}
|
|
75
|
+
if(control.signal.aborted)return;
|
|
73
76
|
if(result===null){
|
|
74
77
|
stderr(`宿主问了预检没覆盖的问题 ${row.kind},无法应答;这一步会留在 unknown`);
|
|
75
78
|
send({type:'host_close',sessionId:row.sessionId});return;
|
|
@@ -81,6 +84,7 @@ export function driveHost({host,args,cwd,operation,request={},answers,paths,answ
|
|
|
81
84
|
if(row.type==='host_response'){
|
|
82
85
|
if(row.accepted===false&&rejected===null){
|
|
83
86
|
rejected=typeof row.code==='string'?row.code:'host_response_rejected';
|
|
87
|
+
control.abort();
|
|
84
88
|
stderr(`宿主拒收了应答:${rejected};${rejectedReplyHint(rejected)}。驾驶员不再等待,已结束会话;宿主会把这一步记为 unknown`);
|
|
85
89
|
child.stdin.end();
|
|
86
90
|
}
|
|
@@ -88,13 +92,15 @@ export function driveHost({host,args,cwd,operation,request={},answers,paths,answ
|
|
|
88
92
|
}
|
|
89
93
|
if(row.requestId==='drive'){
|
|
90
94
|
done=true;
|
|
95
|
+
control.abort();
|
|
91
96
|
process.stdout.write(JSON.stringify(row,null,2)+'\n');
|
|
97
|
+
const guidance=guidanceText(row.result);if(guidance)stderr(guidance);
|
|
92
98
|
if(row.result?.stage)stderr(`stage = ${row.result.stage}`);
|
|
93
99
|
if(row.error)stderr(`宿主拒绝:${row.error.code}(真实原因和位置在上面 [host] 那行 diagnostic 里)`);
|
|
94
100
|
process.exitCode=hostResponseFailed(row)||rejected!==null?1:0;
|
|
95
101
|
child.stdin.end();
|
|
96
102
|
}
|
|
97
103
|
});
|
|
98
|
-
child.on('error',error=>{stderr(`宿主启动失败:${error.message}`);process.exitCode=1;});
|
|
99
|
-
child.on('exit',code=>{if(!done&&!refused){stderr(`宿主在给出结果前退出了,exit ${code}`);process.exitCode=1;}});
|
|
104
|
+
child.on('error',error=>{control.abort();stderr(`宿主启动失败:${error.message}`);process.exitCode=1;});
|
|
105
|
+
child.on('exit',code=>{control.abort();if(!done&&!refused){stderr(`宿主在给出结果前退出了,exit ${code}`);process.exitCode=1;}});
|
|
100
106
|
}
|
|
@@ -1,12 +1,16 @@
|
|
|
1
|
+
import {readExecutionPolicy} from './execution-policy.mjs';
|
|
2
|
+
import {readExternalModels} from './external-models.mjs';
|
|
1
3
|
import {beforeFirstQaRound,qaRevisionFollows,readQaConfigRevision} from './qa-config-revision.mjs';
|
|
4
|
+
import {readCloseoutPolicy} from './knowledge-closeout.mjs';
|
|
2
5
|
// Host-only S3b2b journal grammar. Data validation grants no provider authority.
|
|
3
|
-
import {digest,need,shape,id,text,hex,json,validIdentity,validTaskLearningInput,validCallTimeout,validBlockedReason,requestFor,JOURNAL_REASON_LIMIT} from './effect-contract.mjs';
|
|
4
|
-
import {readReviewBaseline,readReviewPackage,reviewSpecsPath} from './review-package.mjs';
|
|
6
|
+
import {digest,need,shape,id,text,hex,json,validIdentity,validTaskLearningInput,validCallTimeout,validBlockedReason,requestFor,JOURNAL_REASON_LIMIT,boundedReason} from './effect-contract.mjs';
|
|
7
|
+
import {readReviewBaseline,readReviewPackage,reviewSpecsPath,reviewMaterialLimitReason} from './review-package.mjs';
|
|
5
8
|
import {reviewResult,reviewReceipt} from './review-runner.mjs';
|
|
6
9
|
import {checkCompletion} from './gate-bridge.mjs';
|
|
7
10
|
import path from 'node:path';
|
|
8
11
|
import {readCommitIntent,readCommitResult} from './task-commit-codec.mjs';
|
|
9
|
-
import {inspectProviderReview,hasProviderReviewResult,inspectProviderReviewFailure,REVIEWER_PROVIDER_FAILURES} from './provider-review-observation.mjs';
|
|
12
|
+
import {inspectProviderReview,hasProviderReviewResult,inspectProviderReviewFailure,inspectProviderReviewReconciliation,REVIEWER_PROVIDER_FAILURES} from './provider-review-observation.mjs';
|
|
13
|
+
import {readReconciliationReceipt} from './review-reconciliation.mjs';
|
|
10
14
|
import {readCmAiProjectLearningWriteback} from './cm-ai-learning-writer.mjs';
|
|
11
15
|
import {readCmAiTaskLearningApplication} from './cm-ai-context-refresh.mjs';
|
|
12
16
|
import {reviewExclusions} from './effect-contract.mjs';
|
|
@@ -15,15 +19,23 @@ import {readBootstrapEvidence,validateBootstrapReviewPackage} from './host-boots
|
|
|
15
19
|
import {validateCodeProjectPaths,assertCodeProjectSelections} from './code-projects.mjs';
|
|
16
20
|
import {identifyApprovedBootstrapFeature} from './bootstrap-feature.mjs';
|
|
17
21
|
import {readSpecificationRebind} from './specification-material.mjs';
|
|
22
|
+
import {protectedScopePaths} from './developer-adapter.mjs';
|
|
18
23
|
|
|
19
24
|
const LIMIT=16*1024*1024;
|
|
25
|
+
// The developer adapter refuses a protected scope on every dispatch, before any
|
|
26
|
+
// provider runs. A run with such a scope can never develop: it is a definite
|
|
27
|
+
// block, not an unknown outcome. Bootstrap runs scope their own rule paths.
|
|
28
|
+
export const protectedDevelopScope=config=>config.bootstrap?[]:protectedScopePaths(config.scope);
|
|
29
|
+
export const protectedScopeBlockReason=paths=>boundedReason('protected_scope: 任务 scope 含受保护路径:',paths,
|
|
30
|
+
'。开发适配器在派发前拒绝,未派发开发、未写入文件;本运行不能继续。从 scope 移除这些路径后按原门禁新建运行,'
|
|
31
|
+
+'规则文件走 docs/js-workflow-control.md「项目规则文件的修改通道」。');
|
|
20
32
|
export const MAX_AI_JOINED_HOSTS=16;
|
|
21
33
|
const same=(a,b)=>need(digest(a)===digest(b),'runner_history_mismatch');
|
|
22
34
|
const prefix=(a,b)=>{need(b.length>=a.length,'runner_history_mismatch');same(a,b.slice(0,a.length));};
|
|
23
35
|
const uuid=s=>need(typeof s==='string' && /^[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$/.test(s),'runner_session');
|
|
24
36
|
const states=['ready','awaiting_review','approved','changes_requested','fixture_completed','blocked','unknown','cancelled','pending_review'];
|
|
25
37
|
export const stageAllowed=(kind,state,code=null,reviewVerdict=null)=>
|
|
26
|
-
kind==='develop'&&state==='blocked'&&['developer_result_invalid','verification_precheck_failed','check_output_out_of_scope','develop_checks_not_passed','develop_unchanged_after_review','develop_empty_changes','develop_requirement_missing','develop_package_too_large','bootstrap_verification_failed'].includes(code)
|
|
38
|
+
kind==='develop'&&state==='blocked'&&['developer_result_invalid','verification_precheck_failed','check_output_out_of_scope','develop_checks_not_passed','develop_unchanged_after_review','develop_empty_changes','develop_requirement_missing','develop_package_too_large','bootstrap_verification_failed','bootstrap_instruction_conflict'].includes(code)
|
|
27
39
|
||kind==='review'&&state==='pending_review'&&REVIEW_RETRY_CODES.includes(code)
|
|
28
40
|
||kind==='complete'&&state==='blocked'&&(['completion_checks_changed','completion_package_changed'].includes(code)
|
|
29
41
|
||code==='review_package_changed'&&reviewVerdict==='approved')
|
|
@@ -136,6 +148,22 @@ export function validateTaskLearningReviewPackage(rawPackage,writeback,learningI
|
|
|
136
148
|
&&(agents===null||agents.after?.sha256===writeback.agentsFile.sha256),'runner_learning');
|
|
137
149
|
return true;
|
|
138
150
|
}
|
|
151
|
+
// Only a completed bootstrap development whose package construction failed can
|
|
152
|
+
// be reconciled locally. Its developer call, checks and Learning writeback are
|
|
153
|
+
// already durable; a second develop would lose the original review baseline.
|
|
154
|
+
export function bootstrapReviewRecoverable(s,pending=null,configuration=null) {
|
|
155
|
+
const last=s.cache.at(-1),call=s.calls.at(-1);
|
|
156
|
+
return configuration?.mode==='instructions'&&pending===null&&s.attempt===1
|
|
157
|
+
&&(s.state==='unknown'&&s.code==='execution_error'
|
|
158
|
+
||s.state==='blocked'&&s.code==='bootstrap_review_mismatch')
|
|
159
|
+
&&s.reviewPackage===null&&s.receipt===null&&s.reviewInvocation===null
|
|
160
|
+
&&last?.effect.kind==='develop'&&last.effect.identity.attempt===s.attempt
|
|
161
|
+
&&last.result.state===s.state&&last.result.code===s.code
|
|
162
|
+
&&call?.terminal==='succeeded'&&s.learningResult?.bootstrap!=null
|
|
163
|
+
&&s.learningResult.writeback?.outcome!=='writeback_pending'
|
|
164
|
+
&&Array.isArray(s.currentChecks)&&s.currentChecks.length>0
|
|
165
|
+
&&s.currentChecks.every(item=>item.outcome==='passed'&&(item.kind==='visual'||item.exitCode===0));
|
|
166
|
+
}
|
|
139
167
|
// limit only widens the builder's own copy check so a caller can measure an
|
|
140
168
|
// oversized record exactly; the store still refuses it (JOURNAL_PAYLOAD_LIMIT).
|
|
141
169
|
export const runnerPayload=(type,fields,version=1,limit=undefined)=>{need([1,2].includes(version),'runner_version');
|
|
@@ -299,12 +327,12 @@ function readInvocationResult(p,registration,started,effect,config) {
|
|
|
299
327
|
if(p.inspection===null)need(p.reconciliationRequired===true,'runner_invocation'); // legacy result
|
|
300
328
|
else {
|
|
301
329
|
same(p.inspection,check);need(p.outcome==='timed_out','runner_invocation');
|
|
302
|
-
need(p.reconciliationRequired===hasProviderReviewResult(observation.events),'runner_invocation');
|
|
330
|
+
need(p.reconciliationRequired===(Boolean(config.externalModels||config.executionPolicy)||hasProviderReviewResult(observation.events)),'runner_invocation');
|
|
303
331
|
}
|
|
304
332
|
need(check.providerThreadId===started,'runner_invocation');
|
|
305
333
|
need(p.outcome==='cancelled'?check.observationStatus==='cancelled':check.code==='transport_timeout','runner_invocation');
|
|
306
334
|
} else if(p.outcome==='failed') {
|
|
307
|
-
shape(p,common);need(p.reconciliationRequired===
|
|
335
|
+
shape(p,common);need(p.reconciliationRequired===Boolean(config.externalModels||config.executionPolicy),'runner_invocation');
|
|
308
336
|
const observation=json(p.observation,512*1024);
|
|
309
337
|
const failure=inspectProviderReviewFailure(JSON.stringify(observation),JSON.stringify(expectation));
|
|
310
338
|
need(failure!==null,'runner_invocation');same(p.inspection,failure);
|
|
@@ -387,10 +415,12 @@ function checkpoint(before,raw,effect,config,original,session,controls,version=1
|
|
|
387
415
|
need(evidence.invocationId===added[0]?.invocationId,'runner_learning');
|
|
388
416
|
for(const file of evidence.files){
|
|
389
417
|
const previous=before.learningResult?.bootstrap?.files.find(item=>item.path===file.path);
|
|
418
|
+
const initial=config.bootstrap?.committedBasis
|
|
419
|
+
?config.bootstrap.committedBasis.files.find(item=>item.path===file.path)?.sha256??null
|
|
420
|
+
:file.path==='AGENTS.md'?effect.learningInput.learningFiles.find(item=>item.scope==='project'
|
|
421
|
+
&&item.path==='AGENTS.md')?.sha256??null:null;
|
|
390
422
|
const expected=file.path==='AGENTS.md'&&previous&&before.learningResult.writeback.outcome==='written'
|
|
391
|
-
?before.learningResult.writeback.agentsFile.sha256:previous?.afterSha256
|
|
392
|
-
??(file.path==='AGENTS.md'?effect.learningInput.learningFiles.find(item=>item.scope==='project'
|
|
393
|
-
&&item.path==='AGENTS.md')?.sha256??null:null);
|
|
423
|
+
?before.learningResult.writeback.agentsFile.sha256:previous?.afterSha256??initial;
|
|
394
424
|
need(file.beforeSha256===expected,'runner_learning');
|
|
395
425
|
}
|
|
396
426
|
}
|
|
@@ -411,7 +441,8 @@ function checkpoint(before,raw,effect,config,original,session,controls,version=1
|
|
|
411
441
|
||Object.hasOwn(original,'specification')&&s.state==='blocked'&&s.code==='spec_drift'
|
|
412
442
|
// The host gate rejected the delivery after Learning was already written
|
|
413
443
|
// back: the writeback stands, only the review package was not built.
|
|
414
|
-
||s.state==='blocked'&&['verification_precheck_failed','check_output_out_of_scope','develop_checks_not_passed'].includes(s.code)
|
|
444
|
+
||s.state==='blocked'&&['verification_precheck_failed','check_output_out_of_scope','develop_checks_not_passed','bootstrap_instruction_conflict'].includes(s.code)
|
|
445
|
+
||added.length===0&&s.state==='blocked'&&s.code==='protected_scope'
|
|
415
446
|
||added[0]&&['failed','unavailable','auth_required','permission_denied'].includes(added[0].terminal),'runner_learning');
|
|
416
447
|
}
|
|
417
448
|
if(digest(s.reviewPackage)!==digest(before.reviewPackage)) {
|
|
@@ -440,6 +471,21 @@ function checkpoint(before,raw,effect,config,original,session,controls,version=1
|
|
|
440
471
|
need(before.attempt===2&&before.priorReview?.verdict==='changes_requested','runner_develop');
|
|
441
472
|
expectedState='blocked';expectedCode=s.code;
|
|
442
473
|
}
|
|
474
|
+
if(added[0]?.terminal==='succeeded'&&s.code==='bootstrap_review_mismatch'){
|
|
475
|
+
need(config.bootstrap?.mode==='instructions'&&s.reviewPackage===null&&s.learningResult?.bootstrap!=null,
|
|
476
|
+
'runner_develop');
|
|
477
|
+
expectedState='blocked';expectedCode=s.code;
|
|
478
|
+
}
|
|
479
|
+
if(added.length===0&&s.code==='bootstrap_instruction_conflict'){
|
|
480
|
+
need(config.bootstrap?.mode==='instructions','runner_develop');
|
|
481
|
+
same(s.learningResult,before.learningResult);
|
|
482
|
+
expectedState='blocked';expectedCode=s.code;
|
|
483
|
+
}
|
|
484
|
+
if(added.length===0&&s.code==='protected_scope'){
|
|
485
|
+
need(protectedDevelopScope(config).length>0&&digest(s.reviewPackage)===digest(before.reviewPackage),'runner_develop');
|
|
486
|
+
if(Object.hasOwn(config,'taskLearning'))same(s.learningResult,before.learningResult);
|
|
487
|
+
expectedState='blocked';expectedCode=s.code;
|
|
488
|
+
}
|
|
443
489
|
if(added[0] && ['failed','unavailable','auth_required','permission_denied'].includes(added[0].terminal)) {
|
|
444
490
|
expectedState='blocked';expectedCode=invalidDeveloperCall(added[0])
|
|
445
491
|
?'developer_result_invalid':['protected_edit_stale','bootstrap_verification_failed'].includes(added[0].failureResult?.code)
|
|
@@ -545,13 +591,50 @@ function checkpoint(before,raw,effect,config,original,session,controls,version=1
|
|
|
545
591
|
need(s.cancelAfterCommit===(controls.cancelAfterCommit||before.cancelAfterCommit),'runner_control');
|
|
546
592
|
need(s.cancellationRequested===(!!controls.cancelled||!!controls.cancelAfterCommit||before.cancellationRequested),'runner_control');
|
|
547
593
|
if(controls.cancelled)need(s.state==='cancelled','runner_control');
|
|
594
|
+
// Runners before the retryable package-limit transition journaled this exact
|
|
595
|
+
// host gate as unknown/limit_exceeded. Reproject only the unambiguous case:
|
|
596
|
+
// development succeeded, every check passed, and no review package exists.
|
|
597
|
+
// The original record remains byte-for-byte in the journal; a resumed frame
|
|
598
|
+
// carries the corrected projection forward.
|
|
599
|
+
if(effect.kind==='develop'&&before.attempt===1&&config.bootstrap?.mode!=='instructions'
|
|
600
|
+
&&s.state==='unknown'&&s.code==='limit_exceeded'
|
|
601
|
+
&&added[0]?.terminal==='succeeded'&&digest(s.reviewPackage)===digest(before.reviewPackage)
|
|
602
|
+
&&s.receipt===null&&Array.isArray(s.currentChecks)&&s.currentChecks.length>0
|
|
603
|
+
&&s.currentChecks.every(item=>item.outcome==='passed'&&(item.kind==='visual'||item.exitCode===0))
|
|
604
|
+
&&reviewMaterialLimitReason(s.reason)){
|
|
605
|
+
const recovered=structuredClone(s);
|
|
606
|
+
const detail=(s.reason??'review material exceeded its bounded size').replace(/^limit_exceeded:\s*/, '');
|
|
607
|
+
recovered.state='blocked';recovered.code='develop_package_too_large';
|
|
608
|
+
recovered.reason=boundedReason('develop_package_too_large: ',[detail],
|
|
609
|
+
'; shrink the changed files or move generated artifacts out of scope, then resume to redo this attempt');
|
|
610
|
+
recovered.cache.at(-1).result=runnerStatus(recovered,config);
|
|
611
|
+
return recovered;
|
|
612
|
+
}
|
|
613
|
+
// Runners before the create-time scope gate dispatched a protected scope and
|
|
614
|
+
// journaled the adapter's pre-dispatch refusal as unknown/execution_error,
|
|
615
|
+
// with no exit. Reproject only that exact shape: one developer call that never
|
|
616
|
+
// returned a result, nothing built, no Learning. The record stays unchanged.
|
|
617
|
+
if(effect.kind==='develop'&&s.state==='unknown'&&s.code==='execution_error'
|
|
618
|
+
&&protectedDevelopScope(config).length>0&&added.length===1&&added[0].terminal==='unknown'
|
|
619
|
+
&&added[0].resultDigest===null&&digest(s.reviewPackage)===digest(before.reviewPackage)
|
|
620
|
+
&&s.receipt===null&&s.receipts.length===before.receipts.length
|
|
621
|
+
&&(!Object.hasOwn(config,'taskLearning')||s.learningResult===null)){
|
|
622
|
+
const recovered=structuredClone(s);
|
|
623
|
+
recovered.state='blocked';recovered.code='protected_scope';
|
|
624
|
+
recovered.reason=protectedScopeBlockReason(protectedDevelopScope(config));
|
|
625
|
+
recovered.cache.at(-1).result=runnerStatus(recovered,config);
|
|
626
|
+
return recovered;
|
|
627
|
+
}
|
|
548
628
|
return structuredClone(s);
|
|
549
629
|
}
|
|
550
630
|
|
|
551
631
|
function completionConfig(config,version){
|
|
552
632
|
shape(config,['root','identity','scope','requirements','excludedContexts','timeoutMs','developer','reviewers','completion',
|
|
553
633
|
...(version===3?['reviewInvocation']:[]),...(Object.hasOwn(config,'taskLearning')?['taskLearning']:[]),
|
|
554
|
-
...['bootstrap','codeProjectPaths'].filter(key=>Object.hasOwn(config,key))]);
|
|
634
|
+
...['bootstrap','codeProjectPaths','knowledgeCloseout','externalModels','executionPolicy'].filter(key=>Object.hasOwn(config,key))]);
|
|
635
|
+
if(Object.hasOwn(config,'knowledgeCloseout'))readCloseoutPolicy(config.knowledgeCloseout);
|
|
636
|
+
if(Object.hasOwn(config,'executionPolicy')){same(config.executionPolicy,readExecutionPolicy(config.executionPolicy));need(version===3,'execution_policy_runner_version');}
|
|
637
|
+
if(Object.hasOwn(config,'externalModels')){same(config.externalModels,readExternalModels(config.externalModels));need(version===3,'external_model_runner_version');}
|
|
555
638
|
if(Object.hasOwn(config,'codeProjectPaths')){
|
|
556
639
|
same(config.codeProjectPaths,validateCodeProjectPaths(config.codeProjectPaths));
|
|
557
640
|
assertCodeProjectSelections(config.codeProjectPaths,[...config.scope,...config.requirements]);
|
|
@@ -620,6 +703,9 @@ export function readRunnerHistory(raw,config,version=1) {
|
|
|
620
703
|
const reviewConfig=(calls=[])=>({...config,reviewInvocation:{...config.reviewInvocation,
|
|
621
704
|
excludedThreadIds:reviewExclusions({excludedThreadIds:[...config.reviewInvocation.excludedThreadIds,...joinedHosts]},
|
|
622
705
|
calls,config.developer.contextId)}});
|
|
706
|
+
const reconciliationBinding=()=>({effectId:lastReview.effect.id,invocationId:lastReview.request.invocationId,
|
|
707
|
+
registeredDigest:lastReview.registrationRecord.digest,startedDigest:lastReview.startedRecord?.digest??null,
|
|
708
|
+
resultDigest:lastReview.resultRecord.digest});
|
|
623
709
|
for(const [index,r] of records.entries()) {
|
|
624
710
|
if(index>0)need(records[index-1].payload.type!=='effect-abandoned','runner_abandon');
|
|
625
711
|
boundRunnerRecord(r,index+1);
|
|
@@ -656,6 +742,19 @@ export function readRunnerHistory(raw,config,version=1) {
|
|
|
656
742
|
need(r.kind==='result'&&index===1&&pending===null&&state.state==='ready'&&supersession===null,'supersede_record_invalid');
|
|
657
743
|
supersession=readEvidenceSupersession(p.record,{feature:config.taskLearning.feature,
|
|
658
744
|
taskId:config.identity.taskId,newRunId:config.identity.runId});
|
|
745
|
+
} else if(version===3&&p.type==='bootstrap-review-recovered') {
|
|
746
|
+
shape(p,[...common,'fromDigest','reviewPackage','reason','at']);
|
|
747
|
+
need(r.kind==='result'&&p.fromDigest===records[index-1].digest
|
|
748
|
+
&&bootstrapReviewRecoverable(state,pending,config.bootstrap),'bootstrap_review_recovery_unavailable');
|
|
749
|
+
need(typeof p.reason==='string'&&p.reason.trim().length>0&&Buffer.byteLength(p.reason,'utf8')<=500
|
|
750
|
+
&&!/[\r\n\0]/.test(p.reason),'bootstrap_review_recovery_unavailable');
|
|
751
|
+
need(typeof p.at==='string'&&Number.isFinite(Date.parse(p.at))&&new Date(p.at).toISOString()===p.at,
|
|
752
|
+
'bootstrap_review_recovery_unavailable');
|
|
753
|
+
packageLink(p.reviewPackage,original,state.attempt,state.currentChecks);
|
|
754
|
+
validateTaskLearningReviewPackage(p.reviewPackage,state.learningResult.writeback,
|
|
755
|
+
state.cache.at(-1).effect.learningInput,state.learningResult.bootstrap,config.bootstrap);
|
|
756
|
+
state.reviewPackage=readReviewPackage(p.reviewPackage);
|
|
757
|
+
state.state='awaiting_review';state.code=null;state.reason=null;
|
|
659
758
|
} else if(p.type==='effect-intent') {
|
|
660
759
|
shape(p,[...common,'effect']);need(r.kind==='intent' && pending===null,'runner_intent');
|
|
661
760
|
const e=p.effect;shape(e,['version','id','identity','kind',...(Object.hasOwn(e,'learningInput')?['learningInput']:[])]);
|
|
@@ -694,6 +793,34 @@ export function readRunnerHistory(raw,config,version=1) {
|
|
|
694
793
|
invocation.result=readInvocationResult(p,invocation.registration,invocation.started,pending,reviewConfig(beforeIntent.calls));
|
|
695
794
|
if(invocation.result.outcome==='cancelled')need(controls.cancelled===true,'runner_control');
|
|
696
795
|
resultRecord=r;
|
|
796
|
+
} else if(version===3&&['review-invocation-receipt','review-invocation-reconciled'].includes(p.type)) {
|
|
797
|
+
const bindingKeys=['effectId','invocationId','registeredDigest','startedDigest','resultDigest'];
|
|
798
|
+
shape(p,[...common,...bindingKeys,...(p.type==='review-invocation-receipt'?['receipt']:['receiptDigest','checkpoint'])]);
|
|
799
|
+
need((config.externalModels||config.executionPolicy)&&r.kind==='result'&&pending===null&&lastReview!==null
|
|
800
|
+
&&(state.state==='unknown'&&lastReview.invocation.result.reconciliationRequired===true
|
|
801
|
+
||state.state==='pending_review'&&reviewTransportTimeout(lastReview.invocation.result))
|
|
802
|
+
&&lastReview.invocation.result.inspection!==null&&lastReview.invocation.started!==null,
|
|
803
|
+
'review_reconciliation_unavailable');
|
|
804
|
+
same(Object.fromEntries(bindingKeys.map(key=>[key,p[key]])),reconciliationBinding());
|
|
805
|
+
if(p.type==='review-invocation-receipt'){
|
|
806
|
+
need(!lastReview.reconciliation,'review_reconciliation_duplicate');
|
|
807
|
+
const receipt=readReconciliationReceipt(p.receipt);
|
|
808
|
+
prefix(lastReview.invocation.result.observation.events,receipt.events);
|
|
809
|
+
const observation={version:1,kind:'cm-provider-review-observation',requestDigest:lastReview.request.requestDigest,
|
|
810
|
+
events:receipt.events,result:receipt.result};
|
|
811
|
+
const inspection=inspectProviderReviewReconciliation(JSON.stringify(observation),JSON.stringify({request:lastReview.request,
|
|
812
|
+
developerThreadId:config.reviewInvocation.developerThreadId,
|
|
813
|
+
excludedThreadIds:reviewConfig(lastReview.before.calls).reviewInvocation.excludedThreadIds}));
|
|
814
|
+
need(inspection.providerThreadId===lastReview.invocation.started,'review_reconciliation_binding');
|
|
815
|
+
const result={dispatchAt:lastReview.invocation.result.dispatchAt,
|
|
816
|
+
outcome:inspection.observationStatus==='completed'?'observed':'failed',observation,inspection,reconciliationRequired:false};
|
|
817
|
+
lastReview.reconciliation={receiptDigest:r.digest,result};
|
|
818
|
+
}else{
|
|
819
|
+
need(lastReview.reconciliation?.receiptDigest===p.receiptDigest,'review_reconciliation_evidence_required');
|
|
820
|
+
state=checkpoint(lastReview.before,p.checkpoint,lastReview.effect,config,original,session,lastReview.controls,version,
|
|
821
|
+
state.taskCommit??null,{...lastReview.invocation,result:lastReview.reconciliation.result},supersession?.carriedReview??null);
|
|
822
|
+
lastReview=null;
|
|
823
|
+
}
|
|
697
824
|
} else if(version===3&&p.type==='develop-retry-limit') {
|
|
698
825
|
// Terminal: written instead of a develop intent when no delivery can still
|
|
699
826
|
// be reviewed. Every field is recomputed from the replayed state.
|
|
@@ -711,6 +838,7 @@ export function readRunnerHistory(raw,config,version=1) {
|
|
|
711
838
|
&&p.completionBlocks===completionBlockCount(state.cache),'runner_retry_limit');
|
|
712
839
|
state.state='blocked';state.code='completion_retry_limit';state.reason=completionRetryLimitReason(p);lastReview=null;
|
|
713
840
|
} else if(version===3&&p.type==='review-invocation-abandoned'&&Object.hasOwn(p,'resultDigest')) {
|
|
841
|
+
need(!(config.externalModels||config.executionPolicy),'external_review_reconciliation_required');
|
|
714
842
|
// Abandoning a checkpointed review whose journaled result was never accepted.
|
|
715
843
|
shape(p,[...common,'effectId','invocationId','registeredDigest','startedDigest','resultDigest','reason','at']);
|
|
716
844
|
need(r.kind==='result'&&pending===null&&lastReview!==null
|
|
@@ -731,6 +859,7 @@ export function readRunnerHistory(raw,config,version=1) {
|
|
|
731
859
|
result:{outcome:'abandoned',reason:p.reason,at:p.at,recordDigest:r.digest}};
|
|
732
860
|
lastReview=null;
|
|
733
861
|
} else if(version===3&&p.type==='review-invocation-abandoned') {
|
|
862
|
+
need(!(config.externalModels||config.executionPolicy),'external_review_reconciliation_required');
|
|
734
863
|
shape(p,[...common,'effectId','invocationId','registeredDigest','startedDigest','reason','at']);
|
|
735
864
|
need(r.kind==='result'&&pending?.kind==='review'&&invocation.registration&&!invocation.result
|
|
736
865
|
&&!controls.cancelled&&!controls.workflowError&&state.state==='awaiting_review','runner_abandon');
|
|
@@ -754,6 +883,7 @@ export function readRunnerHistory(raw,config,version=1) {
|
|
|
754
883
|
result:{outcome:'abandoned',reason:p.reason,at:p.at,recordDigest:r.digest}};
|
|
755
884
|
pending=null;beforeIntent=null;invocation={registration:null,started:null,result:null};
|
|
756
885
|
} else if(version===3&&p.type==='effect-abandoned') {
|
|
886
|
+
need(!(config.externalModels||config.executionPolicy),'external_review_reconciliation_required');
|
|
757
887
|
shape(p,[...common,'effectId','effectKind','intentDigest','reason','at',
|
|
758
888
|
...(Object.hasOwn(p,'lastRecordDigest')?['lastRecordDigest']:[])]);
|
|
759
889
|
let intentIndex=index-1;
|
|
@@ -777,7 +907,7 @@ export function readRunnerHistory(raw,config,version=1) {
|
|
|
777
907
|
state=checkpoint(beforeIntent,p.checkpoint,pending,config,original,session,controls,version,state.taskCommit??null,invocation,
|
|
778
908
|
supersession?.carriedReview??null);
|
|
779
909
|
lastReview=version===3&&pending.kind==='review'&&invocation.result?{effect:pending,request:invocation.registration.request,
|
|
780
|
-
registrationRecord,startedRecord,resultRecord}:null;
|
|
910
|
+
registrationRecord,startedRecord,resultRecord,before:beforeIntent,controls,invocation}:null;
|
|
781
911
|
pending=null;beforeIntent=null;invocation={registration:null,started:null,result:null};
|
|
782
912
|
} else if(version>=2 && ['task-commit-intent','task-commit-result'].includes(p.type)){
|
|
783
913
|
shape(p,[...common,'effectId','completeIntentDigest','commit']);
|
|
@@ -838,19 +968,21 @@ export function readRunnerHistory(raw,config,version=1) {
|
|
|
838
968
|
if(pending){state.state='unknown';state.code='reconciliation_required';
|
|
839
969
|
if(version===3&&invocation.registration)state.reviewInvocation={registration:invocation.registration.record,
|
|
840
970
|
started:invocation.started,result:invocation.result};}
|
|
841
|
-
const pendingAbandonable
|
|
971
|
+
const pendingAbandonable=!(config.externalModels||config.executionPolicy)&&version===3&&pending!==null
|
|
842
972
|
&&['develop','complete','review'].includes(pending.kind)
|
|
843
973
|
&&!transaction&&state.taskCommit?.intentDigest==null
|
|
844
974
|
&&(pending.kind!=='review'||!invocation.registration&&!joinedForInvocation)
|
|
845
975
|
&&records.slice(records.findLastIndex(row=>row.payload.type==='effect-intent')+1)
|
|
846
976
|
.every(row=>row.payload.type==='control');
|
|
847
|
-
const reviewResultAbandon
|
|
977
|
+
const reviewResultAbandon=!(config.externalModels||config.executionPolicy)&&version===3&&pending===null&&lastReview!==null
|
|
848
978
|
&&abandonableReviewResult(state,config.reviewers[0].contexts[state.attempt-1])
|
|
849
979
|
?{effectId:lastReview.effect.id,invocationId:lastReview.request.invocationId,
|
|
850
980
|
registeredDigest:lastReview.registrationRecord.digest,startedDigest:lastReview.startedRecord?.digest??null,
|
|
851
981
|
resultDigest:lastReview.resultRecord.digest}:null;
|
|
852
982
|
return {original,session,state,pending,acceptedFixes,qaAttachment,
|
|
853
983
|
...(version===3?{joinedHosts,reviewerThreads,supersession,pendingAbandonable,reviewResultAbandon,
|
|
984
|
+
reviewReconciliation:lastReview?.reconciliation&&['unknown','pending_review'].includes(state.state)?{...reconciliationBinding(),
|
|
985
|
+
...lastReview.reconciliation,request:lastReview.request,effect:lastReview.effect,before:lastReview.before}:null,
|
|
854
986
|
pendingObservedReview:pending?.kind==='review'&&invocation.result?.outcome==='observed'
|
|
855
987
|
?{request:invocation.registration.request,registration:invocation.registration.record,
|
|
856
988
|
started:invocation.started,result:invocation.result}:null}:{}),
|
|
@@ -51,7 +51,7 @@ const failureCodes=new Set(['invalid_input','limit_exceeded','call_timeout','can
|
|
|
51
51
|
'unregistered_receipt','invalid_receipt','receipt_identity','receipt_package_mismatch','review_not_approved',
|
|
52
52
|
'checks_not_passed','async_commit','commit_unknown','unsupported_path','unsupported_file','read_failed',
|
|
53
53
|
'snapshot_changed','spec_drift','invalid_baseline','out_of_scope','empty_changes','invalid_package','package_mismatch',
|
|
54
|
-
'handoff_exists','verification_precheck_failed','completion_checks_changed']);
|
|
54
|
+
'handoff_exists','verification_precheck_failed','completion_checks_changed','bootstrap_review_mismatch']);
|
|
55
55
|
// An unlisted code becomes execution_error, which on its own is not actionable.
|
|
56
56
|
// The EEXIST that blocked every retry of a task in #81 stayed invisible in the
|
|
57
57
|
// log, the state and stderr until a temporary print was added by hand. Emit one
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// Explicit, versioned policy for NEW executions. No defaults, migration or budgets.
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import {digest,json,need,id,shape} from './effect-contract.mjs';
|
|
5
|
+
import {isSupportedExecutionPlatform} from './execution-platform.mjs';
|
|
6
|
+
import {fixArchiveRoot} from '../cm-fix/layout.mjs';
|
|
7
|
+
import {readExecutionSnapshot} from './execution-snapshot.mjs';
|
|
8
|
+
import {scanRows} from './log-rows.mjs';
|
|
9
|
+
export const EXECUTION_POLICY_V1=Object.freeze({version:1,responseRecovery:'mechanical-v1',
|
|
10
|
+
checkReuse:'declared-adjacent-v1',reviewPresentation:'utf8-v1',usage:'provider-terminal-v1'});
|
|
11
|
+
export function readExecutionPolicy(raw){
|
|
12
|
+
const value=json(raw);need(digest(value)===digest(EXECUTION_POLICY_V1),'execution_policy_invalid');return value;
|
|
13
|
+
}
|
|
14
|
+
export function readLaunchExecutionPolicy({definition,mode,enabled=false}){
|
|
15
|
+
need(['create','resume'].includes(mode),'invalid_mode');
|
|
16
|
+
if(mode==='create')return enabled?readExecutionPolicy(EXECUTION_POLICY_V1):null;
|
|
17
|
+
let snapshot;
|
|
18
|
+
try{snapshot=readExecutionSnapshot({specsRoot:definition.specsDir,identity:{repositoryId:definition.identity.repositoryId,runId:definition.identity.runId}});}
|
|
19
|
+
catch(error){if(error.code!=='ENOENT')throw error;need(!enabled,'execution_policy_legacy_run');return null;}
|
|
20
|
+
const saved=snapshot.records.find(row=>row.payload.type==='init')?.payload.config.executionPolicy??null;
|
|
21
|
+
need(!enabled||saved!==null,'execution_policy_legacy_run');return saved===null?null:readExecutionPolicy(saved);
|
|
22
|
+
}
|
|
23
|
+
const batchRoot=batch=>path.join(batch.specsDir,'.cm-execution-policy-v1');
|
|
24
|
+
const batchIdentity=batch=>{id(batch.batchId);return {repositoryId:batch.repositoryId,runId:'batch-policy-'+digest(batch.batchId).slice(0,32)};};
|
|
25
|
+
export function readBatchExecutionPolicy({batch,started,enabled=false}){
|
|
26
|
+
const identity=batchIdentity(batch),root=batchRoot(batch),file=path.join(root,'.reviews','.execution',identity.runId,'state.json');
|
|
27
|
+
if(fs.existsSync(file)){
|
|
28
|
+
const snapshot=readExecutionSnapshot({specsRoot:root,identity});
|
|
29
|
+
need(snapshot.records.length===1&&snapshot.records[0].id==='batch-policy'&&snapshot.records[0].kind==='result','execution_policy_batch_binding');
|
|
30
|
+
const record=snapshot.records[0].payload;shape(record,['kind','batchId','planDigest','executionPolicy']);
|
|
31
|
+
need(record.kind==='cm-execution-policy-v1'&&record.batchId===batch.batchId&&record.planDigest===digest(batch),'execution_policy_batch_binding');
|
|
32
|
+
return readExecutionPolicy(record.executionPolicy);
|
|
33
|
+
}
|
|
34
|
+
const log=path.join(batch.specsDir,'运行日志.jsonl');
|
|
35
|
+
if(fs.existsSync(log))scanRows(log,row=>{if(row.workflow==='cm-ai'&&row.run_id===batch.batchId&&row.event==='decision'&&row.phase==='batch_start')started=true;});
|
|
36
|
+
need(!started||!enabled,'execution_policy_legacy_run');return enabled&&!started?readExecutionPolicy(EXECUTION_POLICY_V1):null;
|
|
37
|
+
}
|
|
38
|
+
export async function freezeBatchExecutionPolicy(batch,executionPolicy){
|
|
39
|
+
if(executionPolicy===null)return;
|
|
40
|
+
const root=batchRoot(batch),identity=batchIdentity(batch);
|
|
41
|
+
if(fs.existsSync(path.join(root,'.reviews','.execution',identity.runId,'state.json'))){
|
|
42
|
+
need(digest(readBatchExecutionPolicy({batch,started:true}))===digest(executionPolicy),'execution_policy_batch_binding');return;
|
|
43
|
+
}
|
|
44
|
+
need(isSupportedExecutionPlatform(),'unsupported_platform');
|
|
45
|
+
const {openExecutionStore}=await import('./execution-store.mjs');
|
|
46
|
+
try{fs.mkdirSync(root,{mode:0o700});}catch(error){if(error.code!=='EEXIST')throw error;}
|
|
47
|
+
need(fs.realpathSync(root)===root,'execution_policy_batch_binding');
|
|
48
|
+
const payload={kind:'cm-execution-policy-v1',batchId:batch.batchId,planDigest:digest(batch),executionPolicy:readExecutionPolicy(executionPolicy)};
|
|
49
|
+
const store=openExecutionStore({specsRoot:root,identity,create:true,fingerprints:{workflow:digest(payload.kind),config:digest(batch),inputs:digest(payload)}});
|
|
50
|
+
try{store.append({id:'batch-policy',kind:'result',payload,expectedRevision:store.snapshot().revision});}finally{store.close();}
|
|
51
|
+
}
|
|
52
|
+
export function readFixExecutionPolicy({config,mode,enabled=false}){
|
|
53
|
+
if(mode==='create')return enabled?readExecutionPolicy(EXECUTION_POLICY_V1):null;
|
|
54
|
+
need(mode==='resume','invalid_mode');
|
|
55
|
+
const snapshot=readExecutionSnapshot({specsRoot:fixArchiveRoot(config.specsRoot,config.reproduction.cwd),identity:{repositoryId:config.identity.repositoryId,runId:config.identity.runId}});
|
|
56
|
+
const saved=snapshot.records[0]?.payload.configuration?.executionPolicy??null;
|
|
57
|
+
need(!enabled||saved!==null,'execution_policy_legacy_run');return saved===null?null:readExecutionPolicy(saved);
|
|
58
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// Existing batch/fix owners keep the same provider parser and immutable selection.
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import {digest,need,id,shape} from './effect-contract.mjs';
|
|
5
|
+
import {loadExternalModels,readExternalModels,selectExternalModels} from './external-models.mjs';
|
|
6
|
+
import {openExecutionStore} from './execution-store.mjs';
|
|
7
|
+
import {readExecutionSnapshot} from './execution-snapshot.mjs';
|
|
8
|
+
import {fixArchiveRoot} from '../cm-fix/layout.mjs';
|
|
9
|
+
|
|
10
|
+
export function batchModelsFile(batch){
|
|
11
|
+
id(batch.batchId);return path.join(batch.specsDir,'.cm-external-models-v1','.reviews','.execution','batch-models-'+digest(batch.batchId).slice(0,32),'state.json');
|
|
12
|
+
}
|
|
13
|
+
export function readBatchExternalModels({batch,started,enabled=false,inputFile,providers}){
|
|
14
|
+
const file=batchModelsFile(batch);
|
|
15
|
+
if(fs.existsSync(file)){
|
|
16
|
+
need(inputFile===undefined,'external_model_resume_selection_forbidden');
|
|
17
|
+
const snapshot=readExecutionSnapshot({specsRoot:path.join(batch.specsDir,'.cm-external-models-v1'),identity:{repositoryId:batch.repositoryId,runId:path.basename(path.dirname(file))}});
|
|
18
|
+
need(snapshot.records.length===1&&snapshot.records[0].id==='batch-models'&&snapshot.records[0].kind==='result','external_model_batch_binding');
|
|
19
|
+
const record=snapshot.records[0].payload;
|
|
20
|
+
shape(record,['kind','batchId','planDigest','externalModels']);
|
|
21
|
+
need(record.kind==='cm-external-batch-models-v1'&&record.batchId===batch.batchId
|
|
22
|
+
&&record.planDigest===digest(batch),'external_model_batch_binding');
|
|
23
|
+
return readExternalModels(record.externalModels);
|
|
24
|
+
}
|
|
25
|
+
need(!started||!enabled,'external_model_resume_selection_forbidden');
|
|
26
|
+
need(inputFile===undefined||enabled&&!started,'external_model_feature_required');
|
|
27
|
+
return enabled&&!started?selectExternalModels(loadExternalModels(inputFile),providers):null;
|
|
28
|
+
}
|
|
29
|
+
export function freezeBatchExternalModels(batch,externalModels){
|
|
30
|
+
if(!externalModels)return;
|
|
31
|
+
const value={kind:'cm-external-batch-models-v1',batchId:batch.batchId,planDigest:digest(batch),externalModels:readExternalModels(externalModels)};
|
|
32
|
+
const file=batchModelsFile(batch);
|
|
33
|
+
if(fs.existsSync(file)){need(digest(readBatchExternalModels({batch,started:true,providers:Object.keys(externalModels.providers)}))===digest(externalModels),'external_model_batch_binding');return;}
|
|
34
|
+
const specsRoot=path.join(batch.specsDir,'.cm-external-models-v1');
|
|
35
|
+
try{fs.mkdirSync(specsRoot,{mode:0o700});}catch(error){if(error.code!=='EEXIST')throw error;}
|
|
36
|
+
need(fs.realpathSync(specsRoot)===specsRoot,'external_model_batch_binding');
|
|
37
|
+
const fingerprint=digest('cm-external-batch-models-v1');
|
|
38
|
+
const store=openExecutionStore({specsRoot,identity:{repositoryId:batch.repositoryId,runId:path.basename(path.dirname(file))},create:true,
|
|
39
|
+
fingerprints:{workflow:fingerprint,config:digest(batch),inputs:digest(value)}});
|
|
40
|
+
try{store.append({id:'batch-models',kind:'result',payload:value,expectedRevision:store.snapshot().revision});}finally{store.close();}
|
|
41
|
+
}
|
|
42
|
+
export function readFixExternalModels({config,mode,enabled=false,inputFile,runtime='codex'}){
|
|
43
|
+
if(mode==='resume'){
|
|
44
|
+
need(inputFile===undefined,'external_model_resume_selection_forbidden');
|
|
45
|
+
const specsRoot=fixArchiveRoot(config.specsRoot,config.reproduction.cwd);
|
|
46
|
+
const saved=readExecutionSnapshot({specsRoot,identity:{repositoryId:config.identity.repositoryId,runId:config.identity.runId}})
|
|
47
|
+
.records[0]?.payload.configuration?.externalModels??null;
|
|
48
|
+
need(!enabled||saved!==null,'external_model_resume_selection_forbidden');
|
|
49
|
+
return saved===null?null:readExternalModels(saved);
|
|
50
|
+
}
|
|
51
|
+
need(inputFile===undefined||enabled,'external_model_feature_required');
|
|
52
|
+
return enabled?selectExternalModels(loadExternalModels(inputFile),[runtime]):null;
|
|
53
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {readExecutionSnapshot} from './execution-snapshot.mjs';
|
|
2
|
+
import {loadExternalModels,readExternalModels,selectExternalModels} from './external-models.mjs';
|
|
3
|
+
import {need} from './effect-contract.mjs';
|
|
4
|
+
export function readLaunchExternalModels({definition,mode,enabled=false,inputFile,providers}){
|
|
5
|
+
need(['create','resume'].includes(mode),'invalid_mode');
|
|
6
|
+
if(mode==='resume'){
|
|
7
|
+
need(inputFile===undefined,'external_model_resume_selection_forbidden');
|
|
8
|
+
let snapshot;
|
|
9
|
+
try{snapshot=readExecutionSnapshot({specsRoot:definition.specsDir,
|
|
10
|
+
identity:{repositoryId:definition.identity.repositoryId,runId:definition.identity.runId}});}
|
|
11
|
+
catch(error){
|
|
12
|
+
if(error.code!=='ENOENT')throw error;
|
|
13
|
+
need(!enabled,'external_model_resume_selection_forbidden');
|
|
14
|
+
// Let the original owner report store_missing, without changing legacy resume diagnostics.
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
const saved=snapshot.records.find(row=>row.payload.type==='init')?.payload.config.externalModels??null;
|
|
18
|
+
need(!enabled||saved!==null,'external_model_resume_selection_forbidden');
|
|
19
|
+
return saved===null?null:readExternalModels(saved);
|
|
20
|
+
}
|
|
21
|
+
need(inputFile===undefined||enabled,'external_model_feature_required');
|
|
22
|
+
return enabled?selectExternalModels(loadExternalModels(inputFile),providers):null;
|
|
23
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// One explicit request per external provider; the host session is client-owned.
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import {json,need,shape} from './effect-contract.mjs';
|
|
5
|
+
import {readModelJsonRecord,writeModelJson} from './model-configuration-file.mjs';
|
|
6
|
+
|
|
7
|
+
export const EXTERNAL_MODEL_SCHEMA=1;
|
|
8
|
+
export const EXTERNAL_EFFORTS=Object.freeze({
|
|
9
|
+
codex:Object.freeze(['none','minimal','low','medium','high','xhigh']),
|
|
10
|
+
claude:Object.freeze(['low','medium','high','xhigh','max']),
|
|
11
|
+
});
|
|
12
|
+
export function externalEffort(provider,effort=undefined){
|
|
13
|
+
need(Object.hasOwn(EXTERNAL_EFFORTS,provider),'invalid_external_provider');
|
|
14
|
+
const value=effort===undefined?(provider==='codex'?'high':null):effort;
|
|
15
|
+
need(provider==='claude'&&value===null||EXTERNAL_EFFORTS[provider].includes(value),'unsupported_external_effort');
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
export function externalPair(provider,raw){
|
|
19
|
+
const value=json(raw);shape(value,['model',...(Object.hasOwn(value,'effort')?['effort']:[])]);
|
|
20
|
+
need(typeof value.model==='string'&&value.model.length<=128&&/^[a-zA-Z0-9._-]+$/.test(value.model)
|
|
21
|
+
&&value.model!=='current-session','external_model_required');
|
|
22
|
+
return {model:value.model,effort:externalEffort(provider,value.effort)};
|
|
23
|
+
}
|
|
24
|
+
export function readExternalModels(raw){
|
|
25
|
+
const value=json(raw,64*1024);shape(value,['schemaVersion','providers']);
|
|
26
|
+
need(value.schemaVersion===EXTERNAL_MODEL_SCHEMA,'external_schema_unsupported');
|
|
27
|
+
shape(value.providers,Object.keys(value.providers));
|
|
28
|
+
return {schemaVersion:EXTERNAL_MODEL_SCHEMA,providers:Object.fromEntries(Object.entries(value.providers)
|
|
29
|
+
.map(([provider,pair])=>[provider,externalPair(provider,pair)]))};
|
|
30
|
+
}
|
|
31
|
+
export const externalModelsPath=()=>path.join(path.resolve(process.env.CM_WORKFLOW_HOME||path.join(os.homedir(),'.cm-workflow')),'external-models-v1.json');
|
|
32
|
+
export function loadExternalModels(file=externalModelsPath()){
|
|
33
|
+
try{return readExternalModels(readModelJsonRecord(file).value);}
|
|
34
|
+
catch(error){if(error.code==='ENOENT')throw Object.assign(new Error('external_model_setup_required'),{code:'external_model_setup_required'});throw error;}
|
|
35
|
+
}
|
|
36
|
+
export function selectExternalModels(raw,providers){
|
|
37
|
+
const value=readExternalModels(raw);
|
|
38
|
+
return {schemaVersion:EXTERNAL_MODEL_SCHEMA,providers:Object.fromEntries([...new Set(providers)].map(provider=>{
|
|
39
|
+
need(Object.hasOwn(value.providers,provider),'external_model_setup_required');return [provider,value.providers[provider]];
|
|
40
|
+
}))};
|
|
41
|
+
}
|
|
42
|
+
export function externalSettingsRecord(file=externalModelsPath()){
|
|
43
|
+
try{return readModelJsonRecord(file);}catch(error){if(error.code==='ENOENT')return null;throw error;}
|
|
44
|
+
}
|
|
45
|
+
export function saveExternalModels(value,{file=externalModelsPath(),expectedSha256,sourceGuard=null}={}){
|
|
46
|
+
writeModelJson(file,readExternalModels(value),{expectedSha256,sourceGuard,createParents:true});
|
|
47
|
+
}
|
|
48
|
+
// This is a requested tuple and adapter capability, never provider confirmation.
|
|
49
|
+
export function describeExternalModels(raw){
|
|
50
|
+
return {host:'current-session (controlled by client)',external:readExternalModels(raw),
|
|
51
|
+
capabilityEvidence:'adapter argument contract',effectiveModel:'unknown',providerConfirmed:false};
|
|
52
|
+
}
|