@aibyzero/cm-workflow 0.16.9 → 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 +12 -0
- package/README.md +9 -1
- package/VERSION +1 -1
- 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 +101 -84
- package/docs/next-steps.md +11 -0
- package/docs/untested-branches.md +2 -3
- package/docs/user-guide.md +3 -3
- package/package.json +1 -1
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +13 -69
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +10 -5
- package/runtime/js/cm-ai/control-policy.mjs +111 -0
- package/runtime/js/cm-ai/drive-bootstrap.mjs +11 -8
- package/runtime/js/cm-ai/durable-runner-state.mjs +32 -126
- package/runtime/js/cm-ai/gate-bridge.mjs +4 -4
- package/runtime/js/cm-ai/host-conversation-execution.mjs +22 -20
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +11 -2
- 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-tool-bridge.mjs +3 -0
- 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 +1 -24
- package/runtime/js/cm-ai/review-package.mjs +16 -4
- package/runtime/js/cm-ai/reviewed-deliveries.mjs +1 -1
- package/runtime/js/cm-ai/task-runner.mjs +36 -99
- package/runtime/js/cm-init/review-evidence.mjs +3 -1
- package/runtime/js/cm-prd/review-host.mjs +1 -1
- package/runtime/js/cm-prd/review-publication.mjs +5 -3
- package/runtime/js/cm-refactor/workflow.mjs +1 -1
- package/runtime/js/notify-send.mjs +15 -14
- package/runtime/js/notify.mjs +27 -4
- package/runtime/js/policy-binding-compat.mjs +2 -1
- package/runtime/review.md +52 -7
- package/runtime/task-gates.md +107 -9
- package/scripts/cm-ai-abandon-effect-position.test.mjs +1 -8
- package/scripts/cm-ai-answer-gap-driver.test.mjs +12 -12
- package/scripts/cm-ai-answer-gap-fixture.mjs +1 -8
- package/scripts/cm-ai-batch-drive.mjs +50 -31
- package/scripts/cm-ai-batch-drive.test.mjs +62 -19
- package/scripts/cm-ai-batch-host.mjs +39 -20
- package/scripts/cm-ai-batch-host.test.mjs +62 -38
- package/scripts/cm-ai-batch-run-fixture.mjs +6 -53
- package/scripts/cm-ai-batch-run-member-stops.test.mjs +0 -12
- package/scripts/cm-ai-batch-run.mjs +34 -8
- 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 +1 -8
- package/scripts/cm-ai-develop-call-timeout.test.mjs +1 -8
- package/scripts/cm-ai-develop-driver-gaps.test.mjs +33 -20
- package/scripts/cm-ai-direct-review.test.mjs +348 -0
- package/scripts/cm-ai-documentation-sync-gap.test.mjs +3 -3
- package/scripts/cm-ai-drive-bootstrap-rules.test.mjs +54 -25
- package/scripts/cm-ai-drive.mjs +96 -54
- package/scripts/cm-ai-drive.test.mjs +43 -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 +6 -10
- package/scripts/cm-ai-host-fixture.mjs +38 -10
- package/scripts/cm-ai-host-protected.test.mjs +35 -33
- package/scripts/cm-ai-host.mjs +103 -93
- package/scripts/cm-ai-host.test.mjs +19 -18
- 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 +4 -7
- package/scripts/cm-ai-multi-root.test.mjs +4 -4
- package/scripts/cm-ai-nested-execution.test.mjs +16 -19
- 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 +1 -2
- 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 +18 -3
- 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 +3 -4
- package/scripts/cm-ai-review-drift-precedence.test.mjs +1 -1
- package/scripts/cm-ai-review-failure.test.mjs +13 -19
- package/scripts/cm-ai-review-timeout-config.test.mjs +3 -1
- package/scripts/cm-ai-review-timeout.test.mjs +15 -128
- package/scripts/cm-ai-run.mjs +78 -24
- 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 +3 -10
- 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 +1 -1
- package/scripts/cm-check-runtime.sh +1 -1
- package/scripts/cm-claude-worker.test.mjs +5 -3
- 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 +3 -9
- package/scripts/cm-external-qa-fix.test.mjs +1 -1
- package/scripts/cm-external-review-reconciliation.test.mjs +6 -24
- package/scripts/cm-fix-review-recovery.test.mjs +1 -1
- package/scripts/cm-host-qa-executor.test.mjs +1 -2
- package/scripts/cm-host-qa-policy.test.mjs +43 -16
- package/scripts/cm-host-review-authority.test.mjs +0 -31
- package/scripts/cm-knowledge-closeout.test.mjs +3 -3
- package/scripts/cm-notify-command.test.mjs +54 -18
- package/scripts/cm-notify-read-drift.test.mjs +69 -4
- package/scripts/cm-notify.mjs +16 -4
- package/scripts/cm-notify.test.mjs +91 -19
- package/scripts/cm-patrol.test.mjs +3 -2
- 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/fixtures/bootstrap-review-runner.mjs +1 -7
- package/scripts/fixtures/native-gate-fixture.mjs +18 -0
- package/scripts/policy-binding-compat.test.mjs +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 +60 -12
- package/skills/cm-ai/references/js-host-recovery.md +95 -47
- package/skills/cm-ai/references/js-host.md +65 -28
- package/skills/cm-fix/SKILL.md +12 -0
- package/skills/cm-init/references/js-host.md +1 -1
- package/skills/cm-prd/references/js-host.md +1 -1
- package/skills/cm-refactor/SKILL.md +12 -0
- package/runtime/js/cm-ai/review-dispatch-limits.mjs +0 -18
- package/scripts/cm-ai-review-dispatch-exit.test.mjs +0 -475
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {readExecutionPolicy} from './execution-policy.mjs';
|
|
2
|
+
import {readControlPolicy} from './control-policy.mjs';
|
|
2
3
|
import {readExternalModels} from './external-models.mjs';
|
|
3
4
|
import {beforeFirstQaRound,qaRevisionFollows,readQaConfigRevision} from './qa-config-revision.mjs';
|
|
4
5
|
import {readCloseoutPolicy} from './knowledge-closeout.mjs';
|
|
@@ -21,10 +22,6 @@ import {identifyApprovedBootstrapFeature} from './bootstrap-feature.mjs';
|
|
|
21
22
|
import {readSpecificationRebind} from './specification-material.mjs';
|
|
22
23
|
import {protectedScopePaths} from './developer-adapter.mjs';
|
|
23
24
|
import {validWorkerPid,validStartTime} from './worker-process-identity.mjs';
|
|
24
|
-
import {MAX_REVIEW_NOT_DISPATCHED_RETRIES,MAX_REVIEW_NOT_DISPATCHED_EXTENSIONS,REVIEW_NOT_DISPATCHED_LIMIT_CODE,MAX_REVIEW_DENIAL_CONFIRMATIONS,
|
|
25
|
-
REVIEW_DENIAL_LIMIT_CODE,REVIEW_NEVER_STARTED_MANUAL_STEP} from './review-dispatch-limits.mjs';
|
|
26
|
-
export {MAX_REVIEW_NOT_DISPATCHED_RETRIES,MAX_REVIEW_NOT_DISPATCHED_EXTENSIONS,REVIEW_NOT_DISPATCHED_LIMIT_CODE,MAX_REVIEW_DENIAL_CONFIRMATIONS,
|
|
27
|
-
REVIEW_DENIAL_LIMIT_CODE,REVIEW_NEVER_STARTED_MANUAL_STEP};
|
|
28
25
|
|
|
29
26
|
const LIMIT=16*1024*1024;
|
|
30
27
|
// The developer adapter refuses a protected scope on every dispatch, before any
|
|
@@ -41,8 +38,7 @@ const uuid=s=>need(typeof s==='string' && /^[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}
|
|
|
41
38
|
const states=['ready','awaiting_review','approved','changes_requested','fixture_completed','blocked','unknown','cancelled','pending_review'];
|
|
42
39
|
export const stageAllowed=(kind,state,code=null,reviewVerdict=null)=>
|
|
43
40
|
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','develop_call_timeout','develop_answer_invalid',...RECHECK_CODES,DEVELOP_REDO_CODE,DISPATCH_RETRY_CODE,DEVELOP_INTERRUPTED_CODE,...DOCUMENTATION_SYNC_CODES].includes(code)
|
|
44
|
-
||kind==='review'&&state==='pending_review'&&
|
|
45
|
-
||code===REVIEW_DENIAL_CONFIRMED_CODE)
|
|
41
|
+
||kind==='review'&&state==='pending_review'&&REVIEW_RETRY_CODES.includes(code)
|
|
46
42
|
||kind==='complete'&&state==='blocked'&&(['completion_checks_changed','completion_package_changed',COMPLETE_RECHECK_CODE].includes(code)
|
|
47
43
|
||code==='review_package_changed'&&reviewVerdict==='approved')
|
|
48
44
|
||kind==='develop'&&state==='blocked'&&code==='review_package_changed'&&reviewVerdict==='changes_requested'
|
|
@@ -61,72 +57,6 @@ export const reviewerFailure=result=>result?.outcome==='failed'&&result.reconcil
|
|
|
61
57
|
export const reviewRetryCode=result=>reviewTransportTimeout(result)?'review_transport_timeout'
|
|
62
58
|
:reviewerFailure(result)?(result.inspection.category==='verdict'?'review_verdict_invalid':'review_provider_failed'):null;
|
|
63
59
|
export const REVIEW_RETRY_CODES=Object.freeze(['review_transport_timeout','review_abandoned','review_provider_failed','review_verdict_invalid']);
|
|
64
|
-
// A review registered but never handed to the reviewer: the dispatch grant had
|
|
65
|
-
// expired, or the dispatch clock ran backwards (task-runner, outcome not_dispatched,
|
|
66
|
-
// call started:false). No reviewer process ran and no verdict exists, so nothing has
|
|
67
|
-
// to be proven stopped: the round may dispatch again under a fresh grant (new effect
|
|
68
|
-
// id, same review round). Such an effect holds no call or effect slot. Only the
|
|
69
|
-
// runner's not_dispatched halt yields pending_review with these codes.
|
|
70
|
-
export const REVIEW_NOT_DISPATCHED_CODES=Object.freeze(['grant_expired','clock_invalid']);
|
|
71
|
-
const notDispatchedEffect=entry=>entry.effect.kind==='review'&&entry.result.state==='pending_review'
|
|
72
|
-
&&REVIEW_NOT_DISPATCHED_CODES.includes(entry.result.code)&&entry.result.reviewInvocation?.result?.outcome==='not_dispatched';
|
|
73
|
-
// Bounded on its own (it holds no call or effect slot): at most two such redispatches
|
|
74
|
-
// per review round, like the no-result ones. The count is the round's not-dispatched
|
|
75
|
-
// effects in the checkpointed cache, so live and replay read the same number; once the
|
|
76
|
-
// round's latest end is the third, no review effect is admitted (live and replay) and
|
|
77
|
-
// status shows the explicit limit block. The limit has one audited exit: the operator's
|
|
78
|
-
// confirmation (abandon_review + reason, journaled as review-dispatch-confirmed) grants
|
|
79
|
-
// MAX_REVIEW_NOT_DISPATCHED_RETRIES more, at most MAX_REVIEW_NOT_DISPATCHED_EXTENSIONS
|
|
80
|
-
// per round, so the retry cap (R2) is never defeated, only extended on the record.
|
|
81
|
-
export const reviewNotDispatchedCount=(cache,attempt)=>cache.filter(entry=>entry.effect.identity.attempt===attempt&¬DispatchedEffect(entry)).length;
|
|
82
|
-
export const reviewNotDispatchedExhausted=(s,extended=0)=>s.state==='pending_review'&&REVIEW_NOT_DISPATCHED_CODES.includes(s.code)
|
|
83
|
-
&&reviewNotDispatchedCount(s.cache,s.attempt)>MAX_REVIEW_NOT_DISPATCHED_RETRIES*(1+extended);
|
|
84
|
-
export const reviewNotDispatchedExtendable=(s,confirmed)=>reviewNotDispatchedExhausted(s,confirmed.extended)
|
|
85
|
-
&&confirmed.extended<MAX_REVIEW_NOT_DISPATCHED_EXTENSIONS
|
|
86
|
-
&&s.cache.at(-1)!==undefined&¬DispatchedEffect(s.cache.at(-1))&&s.cache.at(-1).effect.identity.attempt===s.attempt;
|
|
87
|
-
export const reviewNotDispatchedLimitReason=(code,extended=0)=>`${REVIEW_NOT_DISPATCHED_LIMIT_CODE}: 本轮独立审查已登记 ${MAX_REVIEW_NOT_DISPATCHED_RETRIES*(1+extended)+1} 次,每次都在派发前作废(最近一次 pending_review/${code}:授权过期或派发时钟倒退),审查进程从未启动、没有写入。`
|
|
88
|
-
+(extended<MAX_REVIEW_NOT_DISPATCHED_EXTENSIONS
|
|
89
|
-
?'本运行不再自动重派。先查清宿主从授权到派发为何超过授权有效期(60 秒内)或本机时钟为何倒退,并修好;'
|
|
90
|
-
+`然后用 --mode resume 加 --allow-abandon-review 启动并发送 abandon_review(单行 reason 写明修好了什么)登记确认,本轮再多重派 ${MAX_REVIEW_NOT_DISPATCHED_RETRIES} 次(每轮只能确认 ${MAX_REVIEW_NOT_DISPATCHED_EXTENSIONS} 次,用满后不再有这个出口)。`
|
|
91
|
-
:`已确认延长 ${extended} 次(用满),不再提供继续重派的操作。先查清宿主从授权到派发为何超过授权有效期(60 秒内)或本机时钟为何倒退。${REVIEW_NEVER_STARTED_MANUAL_STEP}`);
|
|
92
|
-
// A review whose authorization was refused before any registration (the runner's
|
|
93
|
-
// permission_denied halt): no call, no grant, no reviewer, so nothing can be writing.
|
|
94
|
-
// It is a decision, not a timing failure: only an explicit operator confirmation
|
|
95
|
-
// (abandon_review, journaled as review-dispatch-confirmed with its reason) lets the same
|
|
96
|
-
// round ask for a fresh authorization, once per denial, at most
|
|
97
|
-
// MAX_REVIEW_DENIAL_CONFIRMATIONS per round; a host or a standing approval never does.
|
|
98
|
-
export const REVIEW_DENIED_CODE='permission_denied';
|
|
99
|
-
export const REVIEW_DENIAL_CONFIRMED_CODE='permission_denied_confirmed';
|
|
100
|
-
export const REVIEW_DISPATCH_CONFIRM_REQUIRED_CODE='review_dispatch_confirmation_required';
|
|
101
|
-
const deniedEffect=entry=>entry.effect.kind==='review'&&entry.result.state==='pending_review'&&entry.result.code===REVIEW_DENIED_CODE;
|
|
102
|
-
export const reviewDenialUnconfirmed=s=>s.state==='pending_review'&&s.code===REVIEW_DENIED_CODE;
|
|
103
|
-
export const reviewDenialExhausted=(s,confirmed)=>reviewDenialUnconfirmed(s)&&confirmed.denied>=MAX_REVIEW_DENIAL_CONFIRMATIONS;
|
|
104
|
-
export const reviewDenialConfirmable=(s,confirmed)=>reviewDenialUnconfirmed(s)&&confirmed.denied<MAX_REVIEW_DENIAL_CONFIRMATIONS
|
|
105
|
-
&&deniedEffect(s.cache.at(-1)??{effect:{},result:{}})&&s.cache.at(-1).effect.identity.attempt===s.attempt;
|
|
106
|
-
// Confirmations of a review round, read the same way live (journal payloads) and in
|
|
107
|
-
// replay (the running tally in answerGaps.reviewDispatchConfirmed).
|
|
108
|
-
export const noReviewDispatchConfirmations=()=>({denied:0,extended:0});
|
|
109
|
-
export const countReviewDispatchConfirmations=(payloads,attempt)=>{
|
|
110
|
-
const count=noReviewDispatchConfirmations();
|
|
111
|
-
for(const p of payloads)if(p.type==='review-dispatch-confirmed'&&p.attempt===attempt)
|
|
112
|
-
count[p.code===REVIEW_DENIED_CODE?'denied':'extended']++;
|
|
113
|
-
return count;
|
|
114
|
-
};
|
|
115
|
-
export const reviewDenialConfirmReason=confirmed=>`${REVIEW_DENIED_CODE}: 本轮独立审查的授权没有取得(被拒绝,或授权已超过有效期),审查没有登记、没有派发、审查进程从未启动,不会有任何写入。`
|
|
116
|
-
+'宿主不会自动重试,也不会因为留着的审查授权而重派:先查清是谁拒绝、为什么,确认现在可以授权后,用 --mode resume 加 --allow-abandon-review 启动并发送 abandon_review(单行 reason 写明依据)登记确认,'
|
|
117
|
-
+`再按原方式重新取得本轮审查授权后 advance。每轮最多这样确认 ${MAX_REVIEW_DENIAL_CONFIRMATIONS} 次(本轮已确认 ${confirmed.denied} 次),之后为 ${REVIEW_DENIAL_LIMIT_CODE}。`;
|
|
118
|
-
export const reviewDenialLimitReason=()=>`${REVIEW_DENIAL_LIMIT_CODE}: 本轮独立审查的授权已被拒绝 ${MAX_REVIEW_DENIAL_CONFIRMATIONS+1} 次,已确认重新授权 ${MAX_REVIEW_DENIAL_CONFIRMATIONS} 次(用满),审查进程从未启动,也没有写入。`
|
|
119
|
-
+`本运行不再提供重新授权的操作。先查清授权为何一直被拒绝(宿主是否配了审查权限、授权是否在 60 秒内用完)。${REVIEW_NEVER_STARTED_MANUAL_STEP}`;
|
|
120
|
-
// Status-only overlay for a review round that ended without ever starting a reviewer,
|
|
121
|
-
// read by the live runner and by replay (projectedRunnerStatus) alike; never journaled.
|
|
122
|
-
export function reviewNeverStartedStatus(s,confirmed){
|
|
123
|
-
if(reviewDenialExhausted(s,confirmed))return {state:'blocked',code:REVIEW_DENIAL_LIMIT_CODE,reason:reviewDenialLimitReason()};
|
|
124
|
-
if(reviewDenialUnconfirmed(s))return {reviewDispatchConfirmRequired:true,reason:reviewDenialConfirmReason(confirmed)};
|
|
125
|
-
if(reviewNotDispatchedExhausted(s,confirmed.extended))
|
|
126
|
-
return {state:'blocked',code:REVIEW_NOT_DISPATCHED_LIMIT_CODE,reason:reviewNotDispatchedLimitReason(s.code,confirmed.extended),
|
|
127
|
-
...(confirmed.extended<MAX_REVIEW_NOT_DISPATCHED_EXTENSIONS?{reviewDispatchConfirmRequired:true}:{})};
|
|
128
|
-
return null;
|
|
129
|
-
}
|
|
130
60
|
const timeoutEffect=entry=>entry.effect.kind==='review'&&reviewRetryCode(entry.result.reviewInvocation?.result)!==null
|
|
131
61
|
&&entry.result.code===reviewRetryCode(entry.result.reviewInvocation.result);
|
|
132
62
|
export const reviewRetrySpent=(cache,calls,attempt,contextId)=>cache.some(entry=>entry.effect.identity.attempt===attempt&&timeoutEffect(entry))
|
|
@@ -152,8 +82,8 @@ const spentRetryBlock=s=>{
|
|
|
152
82
|
return s.state==='blocked'&&REVIEW_RETRY_CODES.includes(s.code)&&entry?.effect.kind==='review'
|
|
153
83
|
&&s.reviewInvocation?.result?.observation?.result?.code!=='process_cleanup_unknown'
|
|
154
84
|
&&entry.effect.identity.attempt===s.attempt&&timeoutEffect(entry)&&entry.result.state==='blocked'&&entry.result.code===s.code
|
|
155
|
-
&&s.reviewInvocation?.registration?.
|
|
156
|
-
&&entry.result.reviewInvocation?.registration?.
|
|
85
|
+
&&s.reviewInvocation?.registration?.binding?.invocationId!=null
|
|
86
|
+
&&entry.result.reviewInvocation?.registration?.binding?.invocationId===s.reviewInvocation.registration.binding.invocationId;
|
|
157
87
|
};
|
|
158
88
|
export const reviewRedispatchable=(s,contextId,records=0)=>spentRetryBlock(s)
|
|
159
89
|
&&reviewRedispatchCount(s.cache,s.calls,s.attempt,contextId,records)<MAX_REVIEW_REDISPATCHES;
|
|
@@ -165,7 +95,7 @@ export const reviewRedispatchLimitReason=code=>`${REVIEW_REDISPATCH_LIMIT_CODE}:
|
|
|
165
95
|
+'修好后用 --supersede-reviewed-evidence 新建运行重做;本运行记录保留不改写。';
|
|
166
96
|
export const reviewRedispatchStopReason=code=>`review_redispatch_stop_required: 本轮独立审查第二次没有结论(blocked/${code}),本轮还剩 1 次无结论重派。`
|
|
167
97
|
+'宿主只中止了原调用、没有等到审查进程退出,不能证明它已停止:先确认原审查进程(含子进程)已退出,'
|
|
168
|
-
+'再用 --allow-abandon-review 发送 abandon_review(单行 reason)登记确认,之后 advance
|
|
98
|
+
+'再用 --allow-abandon-review 发送 abandon_review(单行 reason)登记确认,之后 advance 重派;不算审查轮次。';
|
|
169
99
|
export const reviewTimeoutTransition=(result,cache,attempt,calls=[],contextId=null)=>{
|
|
170
100
|
const code=reviewRetryCode(result);
|
|
171
101
|
return code===null?null:{state:reviewRetrySpent(cache,calls,attempt,contextId)?'blocked':'pending_review',code};
|
|
@@ -532,12 +462,12 @@ const INTERRUPTIBLE_TRAILERS={develop:['control','develop-worker','documentation
|
|
|
532
462
|
export const developRedoSource=entry=>developAnswerMissingEffect(entry)||providerStuckCause(entry)!==null;
|
|
533
463
|
export const countedCalls=(calls,cache)=>calls.filter(call=>!invalidDeveloperCall(call)&&call.terminal!=='abandoned').length
|
|
534
464
|
-cache.filter(timeoutEffect).length-cache.filter(developTimeoutEffect).length-cache.filter(developAnswerInvalidEffect).length
|
|
535
|
-
-cache.filter(developRedoSource).length-cache.filter(developDispatchFailedEffect).length
|
|
465
|
+
-cache.filter(developRedoSource).length-cache.filter(developDispatchFailedEffect).length
|
|
536
466
|
-cache.filter(documentationSyncSource).length;
|
|
537
467
|
// A review effect whose journaled result the operator abandoned (below) no
|
|
538
468
|
// longer holds one of the six effect slots; its retry does.
|
|
539
469
|
const abandonedResult=(entry,calls)=>entry.effect.kind==='review'&&entry.result.state==='unknown'
|
|
540
|
-
&&calls.some(call=>call.terminal==='abandoned'&&call.invocationId===entry.result.reviewInvocation?.registration?.
|
|
470
|
+
&&calls.some(call=>call.terminal==='abandoned'&&call.invocationId===entry.result.reviewInvocation?.registration?.binding?.invocationId);
|
|
541
471
|
// Completion holds no effect slot. It makes no provider call, it is admitted
|
|
542
472
|
// only from an approved review (stageAllowed), and every outcome but a
|
|
543
473
|
// completion re-check block ends the run; those blocks have their own bound,
|
|
@@ -550,7 +480,7 @@ export const completionBlockCount=cache=>cache.filter(completionBlock).length;
|
|
|
550
480
|
export const completedEffectCount=(cache,calls=[])=>cache.filter(entry=>!(entry.effect.kind==='develop'
|
|
551
481
|
&&entry.result.state==='blocked'&&['developer_result_invalid','check_output_out_of_scope'].includes(entry.result.code))
|
|
552
482
|
&&!timeoutEffect(entry)&&!developTimeoutEffect(entry)&&!developAnswerInvalidEffect(entry)&&!developRecheckSource(entry)
|
|
553
|
-
&&!developRedoSource(entry)&&!developDispatchFailedEffect(entry)&&!
|
|
483
|
+
&&!developRedoSource(entry)&&!developDispatchFailedEffect(entry)&&!documentationSyncSource(entry)
|
|
554
484
|
&&!abandonedResult(entry,calls)&&entry.effect.kind!=='complete').length;
|
|
555
485
|
// The six-effect cap counts develop and review effects only; completion (above),
|
|
556
486
|
// QA, documentation and finalization hold no slot.
|
|
@@ -607,7 +537,7 @@ export function abandonableReviewResult(s,contextId,records=0){
|
|
|
607
537
|
const entry=s.cache.at(-1),result=s.reviewInvocation?.result;
|
|
608
538
|
return s.state==='unknown'&&entry?.effect.kind==='review'&&entry.effect.identity.attempt===s.attempt
|
|
609
539
|
&&entry.result.state==='unknown'&&abandonableReviewOutcome(result)
|
|
610
|
-
&&entry.result.reviewInvocation?.registration?.
|
|
540
|
+
&&entry.result.reviewInvocation?.registration?.binding?.invocationId===s.reviewInvocation.registration?.binding?.invocationId
|
|
611
541
|
&&reviewRedispatchCount(s.cache,s.calls,s.attempt,contextId,records)<MAX_REVIEW_REDISPATCHES;
|
|
612
542
|
}
|
|
613
543
|
// R4: why a no-verdict review end cannot be abandoned, with its real exit.
|
|
@@ -686,7 +616,7 @@ export function runnerStatus(s,config) {
|
|
|
686
616
|
export function controlledState(state,event,outstanding,version=1) {
|
|
687
617
|
const s=structuredClone(state);
|
|
688
618
|
const unresolvedReview=version===3&&s.reviewInvocation?.result?.reconciliationRequired===true
|
|
689
|
-
&&s.reviewInvocation.registration?.
|
|
619
|
+
&&s.reviewInvocation.registration?.binding?.identity?.attempt===s.attempt;
|
|
690
620
|
if(event==='workflow-error') {s.workflowError='workflow_error';if(!outstanding && s.state!=='fixture_completed'
|
|
691
621
|
&& !(s.state==='unknown'&&(version>=2&&s.taskCommit||unresolvedReview))){s.state='blocked';s.code='workflow_error';if(Object.hasOwn(s,'reason'))s.reason=null;}}
|
|
692
622
|
else if(event==='late-cancel'){s.cancelAfterCommit=true;s.cancellationRequested=true;}
|
|
@@ -775,15 +705,19 @@ export function validateReviewDispatchGrant(raw,expected) {
|
|
|
775
705
|
need(digest(grantBody(grant))===grant.grantDigest,'runner_grant');return grant;
|
|
776
706
|
}
|
|
777
707
|
function readRegistration(p,before,effect,config,session,carried=null) {
|
|
778
|
-
|
|
708
|
+
need(!Object.hasOwn(p,'grant')&&!Object.hasOwn(p,'authorizationAt'),'runner_invocation');
|
|
709
|
+
shape(p,['version','protocol','type','effectId','reviewerId','adapterId','requestDigest','registeredAt','binding']);
|
|
779
710
|
need(p.effectId===effect.id,'runner_invocation');
|
|
780
|
-
const request=reviewRequest(before,config,session,carried),reviewer=config.reviewers[0];
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
711
|
+
const request=reviewRequest(before,config,session,carried),reviewer=config.reviewers[0],binding=json(p.binding);
|
|
712
|
+
shape(binding,['adapterId','invocationId','requestDigest','identity','reviewerId','logicalContextId','packageDigest','hostContextId']);
|
|
713
|
+
id(binding.hostContextId);need(Number.isSafeInteger(p.registeredAt),'runner_invocation');
|
|
714
|
+
need([config.reviewInvocation.developerThreadId,...config.reviewInvocation.excludedThreadIds].includes(binding.hostContextId),'runner_invocation');
|
|
715
|
+
same(binding,{adapterId:reviewer.adapterId,invocationId:request.invocationId,requestDigest:request.requestDigest,
|
|
716
|
+
identity:request.identity,reviewerId:reviewer.id,logicalContextId:request.contextId,
|
|
717
|
+
packageDigest:before.reviewPackage.packageDigest,hostContextId:binding.hostContextId});
|
|
718
|
+
need(p.reviewerId===reviewer.id&&p.adapterId===reviewer.adapterId&&p.requestDigest===request.requestDigest,'runner_invocation');
|
|
785
719
|
return {request,record:json({reviewerId:p.reviewerId,adapterId:p.adapterId,requestDigest:p.requestDigest,
|
|
786
|
-
|
|
720
|
+
registeredAt:p.registeredAt,binding})};
|
|
787
721
|
}
|
|
788
722
|
function readStarted(p,registration,effect,config) {
|
|
789
723
|
shape(p,['version','protocol','type','effectId','invocationId','providerThreadId']);
|
|
@@ -796,9 +730,7 @@ function readInvocationResult(p,registration,started,effect,config) {
|
|
|
796
730
|
const common=['version','protocol','type','effectId','invocationId','dispatchAt','outcome','observation','inspection','reconciliationRequired'];
|
|
797
731
|
need(p.effectId===effect.id&&p.invocationId===registration.request.invocationId,'runner_invocation');
|
|
798
732
|
need(typeof p.reconciliationRequired==='boolean','runner_invocation');
|
|
799
|
-
|
|
800
|
-
else need(Number.isSafeInteger(p.dispatchAt)&®istration.record.registeredAt<=p.dispatchAt
|
|
801
|
-
&&p.dispatchAt<registration.record.grant.expiresAt,'runner_invocation');
|
|
733
|
+
need(Number.isSafeInteger(p.dispatchAt)&®istration.record.registeredAt===p.dispatchAt,'runner_invocation');
|
|
802
734
|
const expectation={request:registration.request,developerThreadId:config.reviewInvocation.developerThreadId,
|
|
803
735
|
excludedThreadIds:config.reviewInvocation.excludedThreadIds};
|
|
804
736
|
let inspected=null;
|
|
@@ -833,11 +765,6 @@ function readInvocationResult(p,registration,started,effect,config) {
|
|
|
833
765
|
const failure=inspectProviderReviewFailure(JSON.stringify(observation),JSON.stringify(expectation));
|
|
834
766
|
need(failure!==null,'runner_invocation');same(p.inspection,failure);
|
|
835
767
|
need(failure.providerThreadId===started,'runner_invocation');
|
|
836
|
-
} else if(p.outcome==='not_dispatched') {
|
|
837
|
-
shape(p,[...common,'reason']);need(['grant_expired','clock_invalid'].includes(p.reason)
|
|
838
|
-
&&p.observation===null&&p.inspection===null&&p.reconciliationRequired===true&&started===null,'runner_invocation');
|
|
839
|
-
need(p.reason==='grant_expired'?Number.isSafeInteger(p.dispatchAt)&&p.dispatchAt>=registration.record.grant.expiresAt:
|
|
840
|
-
p.dispatchAt===null||p.dispatchAt<registration.record.registeredAt,'runner_invocation');
|
|
841
768
|
} else need(false,'runner_invocation');
|
|
842
769
|
return json(Object.fromEntries(Object.entries(p).filter(([key])=>!['version','protocol','type','effectId','invocationId'].includes(key))),512*1024);
|
|
843
770
|
}
|
|
@@ -845,11 +772,11 @@ function invocationCall(call,registration,started,result,before) {
|
|
|
845
772
|
shape(call,['invocationId','contextId','provider','requestedModel','effectiveModel','channel','started','terminal','requestDigest','resultDigest','providerThreadId']);
|
|
846
773
|
const request=registration.request;need(call.invocationId===request.invocationId&&call.contextId===request.contextId
|
|
847
774
|
&&call.provider===request.provider&&call.requestedModel===request.requestedModel&&call.effectiveModel==='unknown'
|
|
848
|
-
&&call.channel==='host-
|
|
775
|
+
&&call.channel==='host-review'&&call.requestDigest===request.requestDigest
|
|
849
776
|
&&call.providerThreadId===started,'runner_call');
|
|
850
777
|
const expectedTerminal=result.outcome==='observed'?'succeeded':result.outcome==='cancelled'?'cancelled':
|
|
851
|
-
|
|
852
|
-
need(call.started===
|
|
778
|
+
reviewTransportTimeout(result)||reviewerFailure(result)?'failed':'unknown';
|
|
779
|
+
need(call.started===true&&call.terminal===expectedTerminal
|
|
853
780
|
&&call.resultDigest===digest(result.outcome==='observed'?result.inspection.review:result)
|
|
854
781
|
&&before.sequence+1===Number(request.invocationId.split('.').at(-1)),'runner_call');
|
|
855
782
|
}
|
|
@@ -1009,9 +936,8 @@ function checkpoint(before,raw,effect,config,original,session,controls,version=1
|
|
|
1009
936
|
need(!invocation?.result&&added.length===0&&s.sequence===before.sequence,'runner_invocation');
|
|
1010
937
|
same(s.reviewInvocation,before.reviewInvocation);same(s.receipt,before.receipt);same(s.receipts,before.receipts);same(s.priorReview,before.priorReview);
|
|
1011
938
|
if(controls.cancelled===true){expectedState='cancelled';expectedCode='cancelled';}
|
|
1012
|
-
else if(s.code==='permission_denied')expectedState='pending_review';
|
|
1013
939
|
else if(Object.hasOwn(original,'specification')&&s.code==='spec_drift')expectedState='blocked';
|
|
1014
|
-
else {need(
|
|
940
|
+
else {need(s.code==='clock_invalid','runner_invocation');expectedState='unknown';}
|
|
1015
941
|
expectedCode??=s.code;
|
|
1016
942
|
} else {
|
|
1017
943
|
need(invocation.result&&added.length===1,'runner_invocation');
|
|
@@ -1036,7 +962,6 @@ function checkpoint(before,raw,effect,config,original,session,controls,version=1
|
|
|
1036
962
|
}
|
|
1037
963
|
}
|
|
1038
964
|
else if(invocation.result.outcome==='cancelled'){need(controls.cancelled===true,'runner_control');expectedState='cancelled';expectedCode='cancelled';}
|
|
1039
|
-
else if(invocation.result.outcome==='not_dispatched'){expectedState='pending_review';expectedCode=invocation.result.reason;}
|
|
1040
965
|
else {const retry=reviewTimeoutTransition(invocation.result,before.cache,before.attempt,before.calls,
|
|
1041
966
|
config.reviewers[0].contexts[before.attempt-1]);
|
|
1042
967
|
expectedState=retry?.state??'unknown';expectedCode=retry?.code??invocation.result.reason??invocation.result.inspection?.code??'reconciliation_required';}
|
|
@@ -1160,7 +1085,8 @@ function checkpoint(before,raw,effect,config,original,session,controls,version=1
|
|
|
1160
1085
|
function completionConfig(config,version){
|
|
1161
1086
|
shape(config,['root','identity','scope','requirements','excludedContexts','timeoutMs','developer','reviewers','completion',
|
|
1162
1087
|
...(version===3?['reviewInvocation']:[]),...(Object.hasOwn(config,'taskLearning')?['taskLearning']:[]),
|
|
1163
|
-
...['bootstrap','codeProjectPaths','knowledgeCloseout','externalModels','executionPolicy'].filter(key=>Object.hasOwn(config,key))]);
|
|
1088
|
+
...['bootstrap','codeProjectPaths','knowledgeCloseout','externalModels','executionPolicy','controlPolicy'].filter(key=>Object.hasOwn(config,key))]);
|
|
1089
|
+
if(Object.hasOwn(config,'controlPolicy')){same(config.controlPolicy,readControlPolicy(config.controlPolicy));need(version===3,'runner_version');}
|
|
1164
1090
|
if(Object.hasOwn(config,'knowledgeCloseout'))readCloseoutPolicy(config.knowledgeCloseout);
|
|
1165
1091
|
if(Object.hasOwn(config,'executionPolicy')){same(config.executionPolicy,readExecutionPolicy(config.executionPolicy));need(version===3,'execution_policy_runner_version');}
|
|
1166
1092
|
if(Object.hasOwn(config,'externalModels')){same(config.externalModels,readExternalModels(config.externalModels));need(version===3,'external_model_runner_version');}
|
|
@@ -1252,8 +1178,7 @@ export function readRunnerHistory(raw,config,version=1) {
|
|
|
1252
1178
|
let original,session,state,pending=null,beforeIntent=null,controlCount=0,controls={},completeIntentDigest=null,transaction=null;
|
|
1253
1179
|
let invocation={registration:null,started:null,result:null};let registrationRecord=null,startedRecord=null,resultRecord=null,lastReview=null;
|
|
1254
1180
|
const acceptedFixes=[],joinedHosts=[],reviewerThreads=[];let qaAttachment=null,qaRevision=null,joinedForInvocation=false,supersession=null;
|
|
1255
|
-
const answerGaps={developRecheck:0,completeRecheck:0,developRedo:0,developDispatch:0,documentationSync:0,reviewRedispatch:{1:0,2:0}
|
|
1256
|
-
reviewDispatchConfirmed:{1:noReviewDispatchConfirmations(),2:noReviewDispatchConfirmations()}};
|
|
1181
|
+
const answerGaps={developRecheck:0,completeRecheck:0,developRedo:0,developDispatch:0,documentationSync:0,reviewRedispatch:{1:0,2:0}};
|
|
1257
1182
|
// Q16: documentation-sync-started records by digest, and the pending develop's.
|
|
1258
1183
|
const documentationRecords=new Map();let pendingDocumentation=null,documentationStop=null;
|
|
1259
1184
|
// V8/V9: interrupted intents (their ids are never reused) and the provider
|
|
@@ -1368,7 +1293,6 @@ export function readRunnerHistory(raw,config,version=1) {
|
|
|
1368
1293
|
if(Object.hasOwn(e,'learningInput')){need(e.kind==='develop'&&Object.hasOwn(config,'taskLearning'),'runner_learning');
|
|
1369
1294
|
validTaskLearningInput(e.learningInput,e.identity,config.taskLearning.feature);}
|
|
1370
1295
|
same(e.identity,{...config.identity,attempt:state.attempt});need(e.version===1 && stageAllowed(e.kind,state.state,state.code,state.priorReview?.verdict),'runner_stage');
|
|
1371
|
-
need(!(e.kind==='review'&&reviewNotDispatchedExhausted(state,answerGaps.reviewDispatchConfirmed[state.attempt].extended)),'runner_stage');
|
|
1372
1296
|
need(effectSlotFree(e.kind,state.cache,state.calls) && !state.cache.some(c=>c.effect.id===e.id),'runner_cache');
|
|
1373
1297
|
pending=e;beforeIntent=structuredClone(state);controls={};completeIntentDigest=e.kind==='complete'?r.digest:null;pendingDocumentation=null;documentationStop=null;
|
|
1374
1298
|
invocation={registration:null,started:null,result:null};registrationRecord=null;startedRecord=null;resultRecord=null;
|
|
@@ -1553,25 +1477,9 @@ export function readRunnerHistory(raw,config,version=1) {
|
|
|
1553
1477
|
need(r.kind==='result'&&pending===null&&p.attempt===state.attempt
|
|
1554
1478
|
&&reviewRedispatchable(state,contextId,answerGaps.reviewRedispatch[state.attempt])
|
|
1555
1479
|
&&p.code===state.code&&p.effectId===state.cache.at(-1).effect.id
|
|
1556
|
-
&&p.invocationId===state.reviewInvocation.registration.
|
|
1480
|
+
&&p.invocationId===state.reviewInvocation.registration.binding.invocationId,'runner_review_redispatch');
|
|
1557
1481
|
answerGaps.reviewRedispatch[state.attempt]++;
|
|
1558
1482
|
state.state='pending_review';lastReview=null;
|
|
1559
|
-
} else if(version===3&&p.type==='review-dispatch-confirmed') {
|
|
1560
|
-
// The operator's confirmation (abandon_review + reason) for a review that never
|
|
1561
|
-
// started: a refused authorization (once per denial) or the spent not-dispatched
|
|
1562
|
-
// redispatch bound (once per round). Nothing ran, so there is no process to prove
|
|
1563
|
-
// stopped (unlike review-redispatch). Re-derived from the journal.
|
|
1564
|
-
shape(p,[...common,'effectId','attempt','code','reason','at']);
|
|
1565
|
-
need(typeof p.reason==='string'&&p.reason.trim().length>0&&Buffer.byteLength(p.reason,'utf8')<=500
|
|
1566
|
-
&&!/[\r\n\0]/.test(p.reason),'runner_review_dispatch_confirm');
|
|
1567
|
-
need(typeof p.at==='string'&&Number.isFinite(Date.parse(p.at))&&new Date(p.at).toISOString()===p.at,'runner_review_dispatch_confirm');
|
|
1568
|
-
const confirmed=answerGaps.reviewDispatchConfirmed[state.attempt];
|
|
1569
|
-
need(r.kind==='result'&&pending===null&&p.attempt===state.attempt&&p.code===state.code
|
|
1570
|
-
&&p.effectId===state.cache.at(-1)?.effect.id
|
|
1571
|
-
&&(reviewDenialConfirmable(state,confirmed)||reviewNotDispatchedExtendable(state,confirmed)),'runner_review_dispatch_confirm');
|
|
1572
|
-
if(p.code===REVIEW_DENIED_CODE){confirmed.denied++;state.code=REVIEW_DENIAL_CONFIRMED_CODE;}
|
|
1573
|
-
else confirmed.extended++;
|
|
1574
|
-
lastReview=null;
|
|
1575
1483
|
} else if(version===3&&p.type==='completion-retry-limit') {
|
|
1576
1484
|
// Terminal: written instead of a complete intent once the re-check bound
|
|
1577
1485
|
// is spent. Every field is recomputed from the replayed state.
|
|
@@ -1592,7 +1500,7 @@ export function readRunnerHistory(raw,config,version=1) {
|
|
|
1592
1500
|
&&!/[\r\n\0]/.test(p.reason),'runner_abandon');
|
|
1593
1501
|
need(typeof p.at==='string'&&Number.isFinite(Date.parse(p.at))&&new Date(p.at).toISOString()===p.at,'runner_abandon');
|
|
1594
1502
|
const call=state.calls.find(item=>item.invocationId===p.invocationId);
|
|
1595
|
-
need(call?.terminal==='unknown'&&call.channel==='host-
|
|
1503
|
+
need(call?.terminal==='unknown'&&call.channel==='host-review','runner_abandon');
|
|
1596
1504
|
// The invocation keeps its slot and its result digest; only its terminal
|
|
1597
1505
|
// records the operator's exit, which also marks the attempt's retry spent.
|
|
1598
1506
|
call.terminal='abandoned';
|
|
@@ -1621,7 +1529,7 @@ export function readRunnerHistory(raw,config,version=1) {
|
|
|
1621
1529
|
need(roundRedispatches()<MAX_REVIEW_REDISPATCHES,'runner_abandon_budget');
|
|
1622
1530
|
const request=invocation.registration.request;
|
|
1623
1531
|
state.calls.push({invocationId:request.invocationId,contextId:request.contextId,provider:request.provider,
|
|
1624
|
-
requestedModel:request.requestedModel,effectiveModel:'unknown',channel:'host-
|
|
1532
|
+
requestedModel:request.requestedModel,effectiveModel:'unknown',channel:'host-review',
|
|
1625
1533
|
started:startedRecord!==null,terminal:'abandoned',requestDigest:request.requestDigest,
|
|
1626
1534
|
resultDigest:r.digest,providerThreadId:invocation.started});
|
|
1627
1535
|
state.sequence++;
|
|
@@ -1883,8 +1791,6 @@ export function projectedRunnerStatus(history,config){
|
|
|
1883
1791
|
if(reviewRedispatchable(s,contextId,records))return {...s,reviewRedispatchStopRequired:true,reason:reviewRedispatchStopReason(s.code)};
|
|
1884
1792
|
if(reviewRedispatchExhausted(s,contextId,records))return {...s,code:REVIEW_REDISPATCH_LIMIT_CODE,reason:reviewRedispatchLimitReason(s.code)};
|
|
1885
1793
|
}
|
|
1886
|
-
const never=reviewNeverStartedStatus(s,gaps.reviewDispatchConfirmed?.[s.attempt]??noReviewDispatchConfirmations());
|
|
1887
|
-
if(never!==null)return {...s,...never};
|
|
1888
1794
|
if(s.state!=='unknown')return s;
|
|
1889
1795
|
const recheck=developRecheckCode(s,config,gaps.developRecheck??0);
|
|
1890
1796
|
if(recheck!==null)return project(recheck);
|
|
@@ -12,10 +12,10 @@ export function checkCompletion({receipt,registered,execution,reviewPackage,iden
|
|
|
12
12
|
for(const field of ['packageDigest','baseIdentity','artifactDigest','requirementsDigest','checksDigest'])
|
|
13
13
|
need(r[field]===reviewPackage[field],'receipt_package_mismatch');
|
|
14
14
|
const executionKeys=['invocationId','contextId','provider','requestedModel','effectiveModel','channel','started','terminal','requestDigest','resultDigest'];
|
|
15
|
-
const
|
|
16
|
-
shape(r.execution,[...executionKeys,...(
|
|
17
|
-
need(['fixture','host-authorized'].includes(r.execution.channel),'execution_mismatch');
|
|
18
|
-
if(
|
|
15
|
+
const observedReview=['host-review','host-authorized'].includes(r.execution?.channel);
|
|
16
|
+
shape(r.execution,[...executionKeys,...(observedReview?['providerThreadId']:[])]);
|
|
17
|
+
need(['fixture','host-review','host-authorized'].includes(r.execution.channel),'execution_mismatch');
|
|
18
|
+
if(observedReview)id(r.execution.providerThreadId);
|
|
19
19
|
need(r.id===r.execution.invocationId && r.execution.started===true && r.execution.terminal==='succeeded'
|
|
20
20
|
&& digest(r.execution)===digest(json(execution)),'execution_mismatch');
|
|
21
21
|
const result=reviewResult(r.result,reviewPackage);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {createNativeUsageLog} from './native-usage-log.mjs';
|
|
2
2
|
import {readExecutionPolicy} from './execution-policy.mjs';
|
|
3
|
+
import {readControlPolicy} from './control-policy.mjs';
|
|
3
4
|
import {selectExternalModels} from './external-models.mjs';
|
|
4
5
|
// Fixed current-conversation factory, separate from CLI top-level execution.
|
|
5
6
|
import fs from 'node:fs';
|
|
@@ -17,7 +18,6 @@ import {createCodexReviewRun} from './codex-review-adapter.mjs';
|
|
|
17
18
|
import {createClaudeReviewRun} from './claude-review-adapter.mjs';
|
|
18
19
|
import {claudeWorker,claudePreflightMatches} from './worker-claude.mjs';
|
|
19
20
|
import {codexWorker,preflightMatches} from './worker-codex.mjs';
|
|
20
|
-
import {createHostReviewAuthority} from './host-review-authority.mjs';
|
|
21
21
|
import {createHostWorkflowCapabilities} from './host-workflow-capabilities.mjs';
|
|
22
22
|
import {resolveHostRole} from './host-role-routing.mjs';
|
|
23
23
|
import {checklistGaps} from './checklist-coverage.mjs';
|
|
@@ -105,13 +105,21 @@ export function resolveReviewTimeout(review,protection){
|
|
|
105
105
|
// after its own deadline; the margin leaves room for that and for close.
|
|
106
106
|
export const REVIEW_BOUND_MARGIN_MS=60000;
|
|
107
107
|
export const reviewRaceTimeout=(outerTimeoutMs,reviewTimeoutMs)=>Math.max(outerTimeoutMs,reviewTimeoutMs+REVIEW_BOUND_MARGIN_MS);
|
|
108
|
-
export function createConversationExecution(definition,hostContextId,bridge,review=null,
|
|
108
|
+
export function createConversationExecution(definition,hostContextId,bridge,review=null,reservedReviewAttempt=null,workflow=null,allowQa=false,runtime='codex',options={}){
|
|
109
109
|
definition=json(definition);workflow=workflow===null?null:json(workflow);options=json(options);
|
|
110
|
-
shape(options,[...['originalHostContextId','protection','batchWorkflowsDigest','qaLogHome','bootstrap','providerDevelopment','externalModels','reviewerRuntime','reviewRuntime','parallelMember','verificationPrecheck','executionPolicy'].filter(key=>Object.hasOwn(options,key))]);
|
|
110
|
+
shape(options,[...['originalHostContextId','protection','batchWorkflowsDigest','qaLogHome','bootstrap','providerDevelopment','externalModels','reviewerRuntime','reviewRuntime','parallelMember','verificationPrecheck','executionPolicy','controlPolicy'].filter(key=>Object.hasOwn(options,key))]);
|
|
111
|
+
const controlPolicy=options.controlPolicy?readControlPolicy(options.controlPolicy):null;
|
|
111
112
|
need(!Object.hasOwn(options,'verificationPrecheck')||typeof options.verificationPrecheck==='boolean','invalid_input');
|
|
112
113
|
const executionPolicy=options.executionPolicy?readExecutionPolicy(options.executionPolicy):null;
|
|
113
114
|
const parallelMember=options.parallelMember??false;need(typeof parallelMember==='boolean','invalid_input');
|
|
114
115
|
const provider=options.providerDevelopment??null;
|
|
116
|
+
if(controlPolicy){
|
|
117
|
+
need((controlPolicy.development==='provider')===Boolean(provider),'invalid_arguments');
|
|
118
|
+
need(controlPolicy.bootstrap!=='write'||Boolean(options.bootstrap),'invalid_arguments');
|
|
119
|
+
need(controlPolicy.qa!=='run'||workflow?.qa!=null,'invalid_arguments');
|
|
120
|
+
need(!options.bootstrap||controlPolicy.bootstrap==='write','invalid_arguments');
|
|
121
|
+
need(allowQa===(controlPolicy.qa==='run'),'invalid_input');
|
|
122
|
+
}
|
|
115
123
|
if(provider){
|
|
116
124
|
shape(provider,['model','attempt','coderRuntime','reviewerRuntime',...(Object.hasOwn(provider,'effort')?['effort']:[])]);
|
|
117
125
|
need(options.protection&&review!==null,'protected_configuration_required');
|
|
@@ -148,9 +156,7 @@ export function createConversationExecution(definition,hostContextId,bridge,revi
|
|
|
148
156
|
const check=projectExecution?.check??null;
|
|
149
157
|
const documentationPaths=workflow?validateDocumentationPaths(workflow.documentationPaths,definition.scope):[];
|
|
150
158
|
need(['codex','claude'].includes(runtime),'invalid_runtime');
|
|
151
|
-
|
|
152
|
-
need(allowedAttempts.length<=2&&new Set(allowedAttempts).size===allowedAttempts.length
|
|
153
|
-
&&allowedAttempts.every(value=>value===1||value===2),'invalid_review_attempt');
|
|
159
|
+
need(reservedReviewAttempt===null,'invalid_input');
|
|
154
160
|
const author='cm-conversation-author',reviewContexts=['cm-conversation-review-1','cm-conversation-review-2'];
|
|
155
161
|
const durableHostContextId=options.originalHostContextId??hostContextId;
|
|
156
162
|
for(const context of [hostContextId,durableHostContextId]){
|
|
@@ -160,6 +166,7 @@ export function createConversationExecution(definition,hostContextId,bridge,revi
|
|
|
160
166
|
// slice too. A transport is not physical protection of nested specs.
|
|
161
167
|
need(protection||!definition.specsDir.startsWith(definition.codeProject+path.sep),'nested_specs_protection_required');
|
|
162
168
|
const configuration={kind:'cm-current-conversation-v1',...(parallelMember?{parallelMember}:{}),definitionDigest:digest(definition),hostContextId:durableHostContextId,
|
|
169
|
+
...(controlPolicy?{controlPolicy}:{}),
|
|
163
170
|
...(runtime==='claude'?{runtime}:{}),
|
|
164
171
|
...(options.reviewRuntime===undefined?{}:{reviewRuntime:options.reviewRuntime}),
|
|
165
172
|
...(executionPolicy?{executionPolicy}:{}),
|
|
@@ -174,13 +181,10 @@ export function createConversationExecution(definition,hostContextId,bridge,revi
|
|
|
174
181
|
disabledSkills:review?.disabledSkills??[],
|
|
175
182
|
...resolveReviewTimeout(review,protection),
|
|
176
183
|
promptTransport:'stdin',schemaPath:fileURLToPath(new URL('./review-result.schema.json',import.meta.url))};
|
|
177
|
-
|
|
178
|
-
if(allowedAttempts.length||provider)need((reviewerRuntime==='codex'?preflightMatches:claudePreflightMatches)(reviewOptions.preflight,reviewOptions),'tool_preflight_missing');
|
|
184
|
+
if(review!==null||provider)need((reviewerRuntime==='codex'?preflightMatches:claudePreflightMatches)(reviewOptions.preflight,reviewOptions),'tool_preflight_missing');
|
|
179
185
|
need(reviewerRuntime!=='claude'||!review||review.disabledSkills.length===0,'invalid_review_config');
|
|
180
186
|
// Preserve P4a's unauthorizable placeholder bytes for existing unconfigured runs.
|
|
181
187
|
const reviewProvider=review?reviewerRuntime:'codex', adapterId=`${reviewProvider}-review-adapter`;
|
|
182
|
-
const authority=review?createHostReviewAuthority({hostContextId,reviewerId:'reviewer',adapterId,
|
|
183
|
-
decide:async binding=>allowedAttempts.includes(binding.identity.attempt)?{status:'approved'}:null}):null;
|
|
184
188
|
// Reread role declarations at each boundary; never switch a bound invocation.
|
|
185
189
|
// onWorker (provider development, task-runner.mjs) journals the worker's
|
|
186
190
|
// identity right before and right after the spawn; a journal failure kills
|
|
@@ -232,17 +236,17 @@ export function createConversationExecution(definition,hostContextId,bridge,revi
|
|
|
232
236
|
const outerTimeoutMs=provider?protection.timeoutMs:1800000;
|
|
233
237
|
const progress=(request,control,stage,run,selectedRuntime=runtime)=>withHostProgress({definition,
|
|
234
238
|
identity:request.identity,runtime:selectedRuntime,stage,signal:control.signal},run);
|
|
235
|
-
const execution={configuration,timeoutMs:outerTimeoutMs,excludedContexts:[durableHostContextId],
|
|
239
|
+
const execution={configuration,timeoutMs:outerTimeoutMs,excludedContexts:[durableHostContextId],applicableAgentFiles:[],
|
|
236
240
|
...(verificationGate?{verificationGate:(request,control)=>progress(request,control,'verifying',()=>verificationGate(request,control))}:{}),
|
|
237
241
|
...(bootstrap?{bootstrap}:{}),
|
|
238
|
-
...(provider?{developmentAttempt:provider.attempt}:{}),
|
|
239
|
-
...(workflow?createHostWorkflowCapabilities({definition,configuration:workflow,bridge,allowQa,runtime,protectedExecution:protection!==null,bootstrap,parallelMember}):{}),
|
|
242
|
+
...(provider&&!controlPolicy?{developmentAttempt:provider.attempt}:{}),
|
|
243
|
+
...(workflow?createHostWorkflowCapabilities({definition,configuration:workflow,bridge,allowQa,runtime,protectedExecution:protection!==null,bootstrap,parallelMember,controlPolicy}):{}),
|
|
240
244
|
...(options.qaLogHome?{qaLogHome:options.qaLogHome}:{}),
|
|
241
|
-
...(authority?{hostDecisionProvider:authority.hostDecisionProvider}:{}),
|
|
242
245
|
developer:{provider:coderRuntime,requestedModel:provider?.model??'current-session',contextId:author,run:async(request,control)=>{
|
|
243
246
|
const bound=(coderRuntime==='codex'?readCodexDeveloperRequest:readClaudeDeveloperRequest)(request);
|
|
244
247
|
if(provider){
|
|
245
|
-
need(bound.identity.attempt
|
|
248
|
+
need((controlPolicy?[1,2].includes(bound.identity.attempt):bound.identity.attempt===provider.attempt)
|
|
249
|
+
&&digest({...bound.identity,attempt:1})===digest(definition.identity),'invalid_development_attempt');
|
|
246
250
|
need(!used.has(bound.invocationId),'duplicate_dispatch');used.add(bound.invocationId);
|
|
247
251
|
}
|
|
248
252
|
const route=provider?null:resolveHostRole({definition,identity:bound.identity,role:'coder',signal:control.signal,runtime});
|
|
@@ -314,7 +318,7 @@ export function createConversationExecution(definition,hostContextId,bridge,revi
|
|
|
314
318
|
}
|
|
315
319
|
}
|
|
316
320
|
// CLI session identity comes from the observed process stream; current
|
|
317
|
-
// conversation responses retain the
|
|
321
|
+
// conversation responses retain the declared host context.
|
|
318
322
|
return {status:response.status,value:response.value,providerThread:provider?response.providerThread:hostContextId};
|
|
319
323
|
}
|
|
320
324
|
if(provider){const {providerThread,...failure}=response;shape(failure,['status','code']);return failure;}
|
|
@@ -329,8 +333,7 @@ export function createConversationExecution(definition,hostContextId,bridge,revi
|
|
|
329
333
|
return bridge.call('check',{...request,codeProject:definition.codeProject,
|
|
330
334
|
scope:definition.scope,requirements:definition.requirements,route},control.signal);
|
|
331
335
|
}),
|
|
332
|
-
// The
|
|
333
|
-
// Diagnostic preflight alone never grants review dispatch.
|
|
336
|
+
// The process adapter records observed reviewer events. Preflight checks capability.
|
|
334
337
|
reviewers:[{id:'reviewer',adapterId,provider:reviewProvider,requestedModel:reviewOptions.model,
|
|
335
338
|
allowed:true,available:true,contexts:reviewContexts,
|
|
336
339
|
run:(request,control)=>{
|
|
@@ -350,8 +353,7 @@ export function createConversationExecution(definition,hostContextId,bridge,revi
|
|
|
350
353
|
}}],
|
|
351
354
|
reviewInvocation:{developerThreadId:author,excludedThreadIds:[durableHostContextId],hostContextId,
|
|
352
355
|
// Not journaled (unlike timeoutMs above), so a resumed run may raise it.
|
|
353
|
-
timeoutMs:reviewRaceTimeout(outerTimeoutMs,reviewOptions.timeoutMs),
|
|
354
|
-
authorize:authority?.authorize??(()=>({status:'denied',code:'permission_denied'}))},
|
|
356
|
+
timeoutMs:reviewRaceTimeout(outerTimeoutMs,reviewOptions.timeoutMs)},
|
|
355
357
|
};
|
|
356
358
|
if(definition.codeProjects)execution.applicableAgentFiles=[...new Set([...execution.applicableAgentFiles,
|
|
357
359
|
...codeProjectInstructionPaths(codeProjectPaths(definition.codeProject,definition.codeProjects))
|
|
@@ -7,6 +7,8 @@ import {openFixExecution} from '../cm-fix/execution.mjs';
|
|
|
7
7
|
import {createFixHost} from '../cm-fix/host.mjs';
|
|
8
8
|
import {bindQaFixDefinition} from './qa-fix-definition.mjs';
|
|
9
9
|
import {digest,id,json,need,shape,validIdentity,hex} from './effect-contract.mjs';
|
|
10
|
+
import {readExecutionSnapshot} from './execution-snapshot.mjs';
|
|
11
|
+
import {readFixControlTarget,CONTROL_FIX_RECOVERY_OPERATIONS} from './control-policy.mjs';
|
|
10
12
|
|
|
11
13
|
// Q23: the child's recovery operations, each with the original cm-fix flag the
|
|
12
14
|
// shared dispatcher (cm-fix/host.mjs) checks and the parent flag that grants it.
|
|
@@ -23,7 +25,7 @@ const parentFlag=flag=>flag.replace(/^--allow-/,'--allow-qa-fix-');
|
|
|
23
25
|
const actionRefusal=(fixOperation,code,reason)=>Object.freeze({outcome:'rejected',code,fixOperation,reason,
|
|
24
26
|
guidance:Object.freeze({summary:'QA 修复子流程的这次操作被拒绝,子运行没有因此改变。',nextStep:reason,
|
|
25
27
|
recoveryOperation:null,prerequisites:Object.freeze([]),authorizationGranted:false})});
|
|
26
|
-
export function createQaFixOwnerHost({parent,reopenParent,hostContextId,parentHostContextId,fix=null,template=null,allowStart=false,autoFix=false,fixExecution={},fixPermissions=[],fixAuthorities={},externalModels=null,executionPolicy=null,recoveryInvocationId=null}){
|
|
28
|
+
export function createQaFixOwnerHost({parent,reopenParent,hostContextId,parentHostContextId,fix=null,template=null,allowStart=false,autoFix=false,fixExecution={},fixPermissions=[],fixAuthorities={},externalModels=null,executionPolicy=null,recoveryInvocationId=null,controlPolicy=null}){
|
|
27
29
|
id(hostContextId);id(parentHostContextId);
|
|
28
30
|
if(recoveryInvocationId!==null)id(recoveryInvocationId);
|
|
29
31
|
need((fix===null)!==(template===null),'invalid_fix_config');
|
|
@@ -81,7 +83,8 @@ export function createQaFixOwnerHost({parent,reopenParent,hostContextId,parentHo
|
|
|
81
83
|
...(request.operation==='fix_action'?['fixOperation',...(request.fixOperation==='reconcile_review'?['invocationId']:[]),
|
|
82
84
|
...(QA_FIX_REASONED.includes(request.fixOperation)&&Object.hasOwn(request,'reason')?['reason']:[]),
|
|
83
85
|
...(request.fixOperation==='prepare_revision'&&Object.hasOwn(request,'tests')?['tests']:[]),
|
|
84
|
-
...(request.fixOperation==='recover_final_review'?['invocationId','reviewPackageDigest','previousInvocationStopped','reason']:[])]:[])
|
|
86
|
+
...(request.fixOperation==='recover_final_review'?['invocationId','reviewPackageDigest','previousInvocationStopped','reason']:[])]:[]),
|
|
87
|
+
...(controlPolicy&&request.operation==='fix_action'&&CONTROL_FIX_RECOVERY_OPERATIONS.includes(request.fixOperation)?['expectedFixControl']:[])]);
|
|
85
88
|
need(value.version===1,'invalid_input');id(value.requestId);validIdentity(value.identity);hex(value.packageDigest);id(value.testRunId);
|
|
86
89
|
if(fixedTemplate)definition=bindQaFixDefinition({template:fixedTemplate,identity:value.identity,
|
|
87
90
|
packageDigest:value.packageDigest,testRunId:value.testRunId});
|
|
@@ -110,6 +113,11 @@ export function createQaFixOwnerHost({parent,reopenParent,hostContextId,parentHo
|
|
|
110
113
|
if(advancing&&!existing)need([hostContextId,parentHostContextId].includes(definition.configuration.hostContextId),'qa_fix_host_mismatch');
|
|
111
114
|
child=openFixExecution({...definition,hostContextId,create:advancing&&!existing},advancing||acting?fixExecution:{});
|
|
112
115
|
activeChild=child;
|
|
116
|
+
const childTarget=()=>readFixControlTarget({runId:definition.identity.runId,stage:child.status().stage,
|
|
117
|
+
revision:readExecutionSnapshot({specsRoot:definition.specsRoot,
|
|
118
|
+
identity:{repositoryId:definition.identity.repositoryId,runId:definition.identity.runId}}).revision});
|
|
119
|
+
if(controlPolicy&&acting&&CONTROL_FIX_RECOVERY_OPERATIONS.includes(value.fixOperation))
|
|
120
|
+
need(digest(readFixControlTarget(value.expectedFixControl))===digest(childTarget()),'snapshot_changed');
|
|
113
121
|
let actionResult;
|
|
114
122
|
if(advancing||acting){
|
|
115
123
|
const host=createFixHost({owner:child,config:{...definition.configuration,specsRoot:definition.specsRoot,identity:definition.identity},
|
|
@@ -138,6 +146,7 @@ export function createQaFixOwnerHost({parent,reopenParent,hostContextId,parentHo
|
|
|
138
146
|
?json({outcome:'verified',code:'qa_fix_completed',evidence:child.completionEvidence()},12*1024*1024)
|
|
139
147
|
:json({outcome:'blocked',code:'qa_fix_incomplete',fixStage:observed.stage,
|
|
140
148
|
...(acting?{actionResult}: {})},12*1024*1024);
|
|
149
|
+
if(controlPolicy&&value.operation==='fix_status')result={...result,childControlTarget:childTarget()};
|
|
141
150
|
}finally{
|
|
142
151
|
try{activeChild=null;child?.close();if(released)current=await reopenParent();}
|
|
143
152
|
finally{busy=false;switching=false;}
|