@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
|
@@ -24,15 +24,7 @@ const boundStatus=(status,identity)=>{validIdentity(status?.identity);
|
|
|
24
24
|
// verdict and a verdict that broke the written contract share one redispatch
|
|
25
25
|
// per attempt. Exported for the batch driver, like developmentRetryable.
|
|
26
26
|
export const reviewRetryable=status=>status.state==='pending_review'
|
|
27
|
-
&&
|
|
28
|
-
// Registered but never dispatched (expired grant, clock ran backwards): no reviewer
|
|
29
|
-
// ran, so a fresh authorization redispatches it (REVIEW_NOT_DISPATCHED_CODES; the
|
|
30
|
-
// runner's not_dispatched halt is the only source of pending_review with these codes).
|
|
31
|
-
||['grant_expired','clock_invalid'].includes(status.code)
|
|
32
|
-
// A refused authorization the operator has since confirmed (abandon_review): the same
|
|
33
|
-
// round asks for a fresh authorization. Unconfirmed (reviewDispatchConfirmRequired) it
|
|
34
|
-
// is not retryable here, so neither advance nor the batch driver ever redispatches it.
|
|
35
|
-
||status.code==='permission_denied_confirmed');
|
|
27
|
+
&&['review_transport_timeout','review_abandoned','review_provider_failed','review_verdict_invalid'].includes(status.code);
|
|
36
28
|
const retryReview=reviewRetryable;
|
|
37
29
|
// Both mean the delivery itself must be redone: an invalid developer result, or
|
|
38
30
|
// one that does not satisfy the task's own written verification. Exported so the
|
|
@@ -56,8 +48,6 @@ const pendingAction=status=>status.state==='awaiting_spec_approval'?'spec_approv
|
|
|
56
48
|
status.developRedoRequired===true?'develop_redo':
|
|
57
49
|
// V5: the round's second no-result redispatch needs the operator's stop confirmation.
|
|
58
50
|
status.reviewRedispatchStopRequired===true?'abandon_review':
|
|
59
|
-
// A review that never started and needs the operator's confirmation (abandon_review).
|
|
60
|
-
status.reviewDispatchConfirmRequired===true?'abandon_review':
|
|
61
51
|
status.reviewReconciliation?.available?'reconcile_review':
|
|
62
52
|
status.state==='changes_requested'||retryDeveloper(status)||retryReview(status)?'resume':
|
|
63
53
|
status.state==='awaiting_review'?'decision':status.state==='unknown'
|
|
@@ -84,7 +74,6 @@ const summary=(operation,status,outcome)=>freeze({version:1,workflow:'cm-ai',ope
|
|
|
84
74
|
...(status.developRedoRequired===true?{developRedoRequired:true}:{}),
|
|
85
75
|
...(status.documentationSyncPending===true?{documentationSyncPending:true}:{}),
|
|
86
76
|
...(status.reviewRedispatchStopRequired===true?{reviewRedispatchStopRequired:true}:{}),
|
|
87
|
-
...(status.reviewDispatchConfirmRequired===true?{reviewDispatchConfirmRequired:true}:{}),
|
|
88
77
|
...(typeof status.reviewAbandonRefusal==='string'?{reviewAbandonRefusal:status.reviewAbandonRefusal}:{}),
|
|
89
78
|
...(typeof status.reason==='string'?{reason:status.reason}:{}),
|
|
90
79
|
...(status.code==='handoff_exists'?{reason:REVIEWED_HANDOFF_HINT}:{}),
|
|
@@ -146,13 +135,7 @@ const rejected=(identity,error)=>{
|
|
|
146
135
|
outcome:'rejected',state:null,code,packageDigest:null,pendingAction:'none'});
|
|
147
136
|
};
|
|
148
137
|
|
|
149
|
-
|
|
150
|
-
if(decision?.status==='denied'){
|
|
151
|
-
shape(decision,['status','code']);need(decision.code==='permission_denied','invalid_host_decision');return 'denied';
|
|
152
|
-
}
|
|
153
|
-
shape(decision,['status']);need(decision.status==='approved','invalid_host_decision');
|
|
154
|
-
need(status.packageDigest!==null,'stale_decision');return 'approved';
|
|
155
|
-
}
|
|
138
|
+
|
|
156
139
|
|
|
157
140
|
function effectSummary(operation,result,runner,identity) {
|
|
158
141
|
if(result?.outcome==='rejected'){
|
|
@@ -210,8 +193,6 @@ function validateDocumentationResult(result,status,refresh,policy=null) {
|
|
|
210
193
|
|
|
211
194
|
export function createCmAiConversationEntry(options) {
|
|
212
195
|
const optionKeys=['specsDir','codeProject','feature','identity','runner'];
|
|
213
|
-
if(options&&Object.hasOwn(options,'hostDecision'))optionKeys.push('hostDecision');
|
|
214
|
-
if(options&&Object.hasOwn(options,'hostDecisionProvider'))optionKeys.push('hostDecisionProvider');
|
|
215
196
|
if(options&&Object.hasOwn(options,'developmentAttempt'))optionKeys.push('developmentAttempt');
|
|
216
197
|
if(options&&Object.hasOwn(options,'qaDecision'))optionKeys.push('qaDecision');
|
|
217
198
|
if(options&&Object.hasOwn(options,'qaDecisionProvider'))optionKeys.push('qaDecisionProvider');
|
|
@@ -240,6 +221,7 @@ export function createCmAiConversationEntry(options) {
|
|
|
240
221
|
const ownerIdentity=json(options.identity);validIdentity(ownerIdentity);
|
|
241
222
|
const runner=options.runner;
|
|
242
223
|
const runnerKeys=['executeEffect','status','cancel','run'];
|
|
224
|
+
if(runner&&Object.hasOwn(runner,'qaChangedFiles'))runnerKeys.push('qaChangedFiles');
|
|
243
225
|
if(runner&&Object.hasOwn(runner,'verificationBlocks'))runnerKeys.push('verificationBlocks');
|
|
244
226
|
if(runner&&Object.hasOwn(runner,'completionBlocks'))runnerKeys.push('completionBlocks');
|
|
245
227
|
if(runner&&Object.hasOwn(runner,'reviewEffectIds'))runnerKeys.push('reviewEffectIds');
|
|
@@ -260,6 +242,7 @@ export function createCmAiConversationEntry(options) {
|
|
|
260
242
|
if(runner&&Object.hasOwn(runner,'interruptions'))runnerKeys.push('interruptions');
|
|
261
243
|
if(runner&&Object.hasOwn(runner,'inspectBootstrapAdmission'))runnerKeys.push('inspectBootstrapAdmission');
|
|
262
244
|
shape(runner,runnerKeys);
|
|
245
|
+
if(Object.hasOwn(runner,'qaChangedFiles'))need(typeof runner.qaChangedFiles==='function');
|
|
263
246
|
for(const name of ['executeEffect','status','cancel','run'])need(typeof runner[name]==='function');
|
|
264
247
|
if(Object.hasOwn(runner,'completionBlocks'))need(typeof runner.completionBlocks==='function');
|
|
265
248
|
if(Object.hasOwn(runner,'reviewEffectIds'))need(typeof runner.reviewEffectIds==='function');
|
|
@@ -286,14 +269,6 @@ export function createCmAiConversationEntry(options) {
|
|
|
286
269
|
need(options.allowDevelopRedo===undefined||typeof options.allowDevelopRedo==='boolean','invalid_input');
|
|
287
270
|
let developRedoPermission=options.allowDevelopRedo===true;
|
|
288
271
|
|
|
289
|
-
const hostDecision=Object.hasOwn(options,'hostDecision')?json(options.hostDecision):null;
|
|
290
|
-
let hostDecisionProvider=null,pendingReviewDecision=null;
|
|
291
|
-
if(Object.hasOwn(options,'hostDecisionProvider')){
|
|
292
|
-
shape(options.hostDecisionProvider,['decide','timeoutMs']);
|
|
293
|
-
const {decide,timeoutMs}=options.hostDecisionProvider;
|
|
294
|
-
need(typeof decide==='function'&&Number.isInteger(timeoutMs)&&timeoutMs>=1&&timeoutMs<=60000);
|
|
295
|
-
need(hostDecision===null);hostDecisionProvider={decide,timeoutMs};
|
|
296
|
-
}
|
|
297
272
|
const qaDecision=Object.hasOwn(options,'qaDecision')?json(options.qaDecision):null;
|
|
298
273
|
const qaProvider=options.qaDecisionProvider??null;
|
|
299
274
|
if(qaProvider!==null){
|
|
@@ -577,10 +552,9 @@ export function createCmAiConversationEntry(options) {
|
|
|
577
552
|
return summary(operation,status,'reported');
|
|
578
553
|
}
|
|
579
554
|
if(operation.operation==='cancel'){
|
|
580
|
-
const interrupted=inFlightHandles.size>0||
|
|
555
|
+
const interrupted=inFlightHandles.size>0||pendingQa!==null
|
|
581
556
|
||pendingExecution!==null||pendingDocumentation!==null;
|
|
582
557
|
cancellationEpoch++;
|
|
583
|
-
pendingReviewDecision?.abort();
|
|
584
558
|
pendingQa?.abort();
|
|
585
559
|
pendingExecution?.abort();
|
|
586
560
|
pendingDocumentation?.abort();
|
|
@@ -638,48 +612,17 @@ export function createCmAiConversationEntry(options) {
|
|
|
638
612
|
const status=boundStatus(runner.status(),identity);
|
|
639
613
|
need(status.packageDigest===operation.packageDigest,'stale_decision');
|
|
640
614
|
if(status.code==='review_package_changed')return summary(operation,status,'rejected');
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
if(!(status.state==='awaiting_review'&&status.code===null)&&!retryReview(status))return summary(operation,status,'reported');
|
|
646
|
-
need(pendingReviewDecision===null,'review_decision_pending');
|
|
647
|
-
need(!status.cancellationRequested&&!status.cancelAfterCommit,'cancelled');
|
|
648
|
-
const controller=new AbortController();pendingReviewDecision=controller;
|
|
649
|
-
let timer,timedOut=false;
|
|
650
|
-
try{
|
|
651
|
-
const interrupted=new Promise((_,reject)=>{
|
|
652
|
-
controller.signal.addEventListener('abort',()=>reject(Object.assign(new Error('Review decision interrupted'),
|
|
653
|
-
{code:timedOut?'review_decision_timeout':'cancelled'})),{once:true});
|
|
654
|
-
timer=setTimeout(()=>{timedOut=true;controller.abort();},hostDecisionProvider.timeoutMs);
|
|
655
|
-
});
|
|
656
|
-
const binding=freeze(json({specsDir:options.specsDir,codeProject:options.codeProject,feature:options.feature,
|
|
657
|
-
identity,packageDigest:operation.packageDigest}));
|
|
658
|
-
decision=json(await Promise.race([Promise.resolve().then(()=>{
|
|
659
|
-
need(!controller.signal.aborted,'cancelled');return hostDecisionProvider.decide(binding,controller.signal);
|
|
660
|
-
}),interrupted]));
|
|
661
|
-
need(!controller.signal.aborted,'cancelled');
|
|
662
|
-
const current=boundStatus(runner.status(),identity);
|
|
663
|
-
need(current.state===status.state&¤t.code===status.code
|
|
664
|
-
&¤t.packageDigest===operation.packageDigest,'stale_decision');
|
|
665
|
-
need(!current.cancellationRequested&&!current.cancelAfterCommit,'cancelled');
|
|
666
|
-
}finally{clearTimeout(timer);pendingReviewDecision=null;}
|
|
667
|
-
}
|
|
668
|
-
if(decision===null)return summary(operation,{...status,code:'decision_required'},'awaiting');
|
|
669
|
-
if(validateHostDecision(decision,status)==='denied')
|
|
670
|
-
return summary(operation,{...status,code:'permission_denied'},'denied');
|
|
671
|
-
// A redispatch takes the next free id: at least the number of review effects THIS round's cache
|
|
672
|
-
// holds (runner.reviewEffectIds) and at least the host-authorized calls that ended without a
|
|
673
|
-
// verdict (an abandoned intent has a call but no cache entry), then skips any id already
|
|
674
|
-
// cached. A refused authorization leaves no call and keeps the previous round's
|
|
675
|
-
// reviewInvocation, so the call count alone can repeat an id and the cache would answer.
|
|
615
|
+
// Dispatch only a review-ready package. Completed or outstanding invocations
|
|
616
|
+
// remain runner-owned and cannot be reopened by a decision message.
|
|
617
|
+
if(!(status.state==='awaiting_review'&&status.code===null)&&!retryReview(status))return summary(operation,status,'reported');
|
|
618
|
+
need(!status.cancellationRequested&&!status.cancelAfterCommit,'cancelled');
|
|
676
619
|
const resumed=runner.interruptions?.('review')??0,roundIds=runner.reviewEffectIds?.();
|
|
677
620
|
const idFor=n=>`review-${identity.attempt}${n?`-retry-${n}`:''}${resumed?`-resume-${resumed}`:''}`;
|
|
678
621
|
let retries=0;
|
|
679
622
|
if(retryReview(status)){
|
|
680
623
|
retries=Math.max(Array.isArray(roundIds)?roundIds.length:0,
|
|
681
|
-
status.calls.filter(call=>call.channel==='host-
|
|
682
|
-
&&call.contextId===status.reviewInvocation?.registration?.
|
|
624
|
+
status.calls.filter(call=>call.channel==='host-review'&&['failed','abandoned'].includes(call.terminal)
|
|
625
|
+
&&call.contextId===status.reviewInvocation?.registration?.binding.logicalContextId).length);
|
|
683
626
|
if(Array.isArray(roundIds))while(roundIds.includes(idFor(retries)))retries++;
|
|
684
627
|
}
|
|
685
628
|
const effectId=idFor(retries);
|
|
@@ -735,6 +678,7 @@ export function createCmAiConversationEntry(options) {
|
|
|
735
678
|
decision=json(await Promise.race([
|
|
736
679
|
Promise.resolve().then(()=>{need(!controller.signal.aborted,'cancelled');
|
|
737
680
|
return decideQa(freeze({...binding,codeProject:options.codeProject,
|
|
681
|
+
changedFiles:runner.qaChangedFiles?.(operation.packageDigest)??{paths:[],source:'unavailable'},
|
|
738
682
|
...(previousDecisionId===null?{}:{previousDecisionId})}),controller.signal);}),interrupted]));
|
|
739
683
|
need(!controller.signal.aborted,'cancelled');
|
|
740
684
|
const current=boundStatus(runner.status(),identity);
|
|
@@ -749,7 +693,7 @@ export function createCmAiConversationEntry(options) {
|
|
|
749
693
|
return summary(operation,{...status,code:admission.reason},'awaiting');
|
|
750
694
|
const feature=admission.features.find(item=>item.name===options.feature);
|
|
751
695
|
need(feature,'qa_policy_unavailable');
|
|
752
|
-
// N6 feature completion is a mandatory trigger, regardless of
|
|
696
|
+
// N6 feature completion is a mandatory trigger, regardless of registered paths.
|
|
753
697
|
// Ask for the proper bound decision; do not synthesize authorization.
|
|
754
698
|
if(feature.pending===0)return summary(operation,{...status,code:'qa_mandatory_required'},'awaiting');
|
|
755
699
|
}
|
|
@@ -30,7 +30,9 @@ export function recordCmAiQaAttachment({specsDir,codeProject,feature,identity,re
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
export function readDecision(raw,identity,packageDigest) {
|
|
33
|
-
const decision=json(raw);shape(decision,['decisionId','identity','packageDigest','status','reason','score','at'
|
|
33
|
+
const decision=json(raw);shape(decision,['decisionId','identity','packageDigest','status','reason','score','at',
|
|
34
|
+
...(Object.hasOwn(decision,'changedFilesSource')?['changedFilesSource']:[])]);
|
|
35
|
+
if(Object.hasOwn(decision,'changedFilesSource'))need(['review_package','handoff_only','unavailable'].includes(decision.changedFilesSource));
|
|
34
36
|
id(decision.decisionId);validIdentity(decision.identity);hex(decision.packageDigest);
|
|
35
37
|
need(sameIdentity(decision.identity,identity)&&decision.packageDigest===packageDigest,'qa_decision_mismatch');
|
|
36
38
|
need(['triggered','skipped','blocked'].includes(decision.status));
|
|
@@ -39,7 +41,7 @@ export function readDecision(raw,identity,packageDigest) {
|
|
|
39
41
|
&&/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:Z|[+-]\d{2}:\d{2})$/.test(decision.at)
|
|
40
42
|
&&Number.isFinite(Date.parse(decision.at)));
|
|
41
43
|
if(decision.score!==null)need(Number.isInteger(decision.score)&&decision.score>=4&&decision.score<=20);
|
|
42
|
-
if(decision.status==='skipped'
|
|
44
|
+
if(decision.status==='skipped'&&decision.score!==null)need(decision.score<=7);
|
|
43
45
|
if(decision.status==='triggered'&&decision.score!==null)need(decision.score>=8);
|
|
44
46
|
return json({...decision,at:decision.at.endsWith('Z')?`${decision.at.slice(0,-1)}+00:00`:decision.at});
|
|
45
47
|
}
|
|
@@ -70,7 +72,8 @@ function existingDecision(specsDir,feature,identity,packageDigest,decision,previ
|
|
|
70
72
|
const row=effectiveQaDecisionRow(matches,'qa_decision_conflict');
|
|
71
73
|
if(row.decision_id===decision.decisionId){
|
|
72
74
|
need(row.status===decision.status&&row.reason===decision.reason&&row.score===decision.score&&row.at===decision.at
|
|
73
|
-
&&(row.previous_decision_id??null)===previousDecisionId
|
|
75
|
+
&&(row.previous_decision_id??null)===previousDecisionId
|
|
76
|
+
&&(row.changed_files_source??null)===(decision.changedFilesSource??null),'qa_decision_conflict');
|
|
74
77
|
return true;
|
|
75
78
|
}
|
|
76
79
|
// Only the single recorded timeout decision can be superseded, and once.
|
|
@@ -105,11 +108,12 @@ export function recordCmAiQaDecision(input) {
|
|
|
105
108
|
const decision=readDecision(input.decision,input.identity,input.packageDigest);
|
|
106
109
|
if(existingDecision(input.specsDir,input.feature,input.identity,input.packageDigest,decision,previousDecisionId))return;
|
|
107
110
|
const detail=(decision.status==='triggered'?`触发:${decision.reason}`:
|
|
108
|
-
decision.status==='skipped'
|
|
111
|
+
decision.status==='skipped'?`跳过:${decision.reason}`:`阻塞:${decision.reason}`)
|
|
109
112
|
+(previousDecisionId===null?'':`(重新评估,替代 ${previousDecisionId})`);
|
|
110
113
|
const data={node:'N6',feature:input.feature,task:input.identity.taskId,attempt:input.identity.attempt,
|
|
111
114
|
repository_id:input.identity.repositoryId,package_digest:input.packageDigest,decision_id:decision.decisionId,
|
|
112
115
|
status:decision.status,reason:decision.reason,score:decision.score,
|
|
116
|
+
...(Object.hasOwn(decision,'changedFilesSource')?{changed_files_source:decision.changedFilesSource}:{}),
|
|
113
117
|
...(previousDecisionId===null?{}:{previous_decision_id:previousDecisionId})};
|
|
114
118
|
const args=[writer,'--workflow','cm-ai','--event','qa','--runtime','codex','--project-root',input.codeProject,
|
|
115
119
|
'--specs-dir',input.specsDir,'--run-id',input.identity.runId,'--at',decision.at,'--detail',detail,
|
|
@@ -155,7 +159,8 @@ function findDecisionRow(input) {
|
|
|
155
159
|
export function findCmAiQaDecision(input) {
|
|
156
160
|
const row=findDecisionRow(input);if(row===null)return null;
|
|
157
161
|
return readDecision({status:row.status,decisionId:row.decision_id,identity:input.identity,
|
|
158
|
-
packageDigest:input.packageDigest,reason:row.reason,score:row.score,at:row.at
|
|
162
|
+
packageDigest:input.packageDigest,reason:row.reason,score:row.score,at:row.at,
|
|
163
|
+
...(Object.hasOwn(row,'changed_files_source')?{changedFilesSource:row.changed_files_source}:{})},input.identity,input.packageDigest);
|
|
159
164
|
}
|
|
160
165
|
|
|
161
166
|
// True when the effective decision is the linked replacement of a timed-out
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// Execution choices and stale-command protection, not human authentication.
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import {digest,json,need,shape,validIdentity,hex,id} from './effect-contract.mjs';
|
|
4
|
+
import {parseModelJson} from './model-configuration-file.mjs';
|
|
5
|
+
|
|
6
|
+
export const CONTROL_RECOVERY_OPERATIONS=Object.freeze(['abandon_review','abandon_effect','develop_redo',
|
|
7
|
+
'bootstrap_review_recover','reconcile_review']);
|
|
8
|
+
export const CONTROL_FIX_RECOVERY_OPERATIONS=Object.freeze(['abandon_step','abandon_review','rediagnose',
|
|
9
|
+
'rerun_blocked_step','recover_final_review','reconcile_review']);
|
|
10
|
+
export function readControlPolicy(raw){
|
|
11
|
+
const value=json(raw);shape(value,['version','development','bootstrap','qa','qaFix']);
|
|
12
|
+
need(value.version===2&&['conversation','provider'].includes(value.development)
|
|
13
|
+
&&['disabled','write'].includes(value.bootstrap)&&['disabled','run'].includes(value.qa)
|
|
14
|
+
&&['disabled','manual','auto'].includes(value.qaFix),'invalid_input');
|
|
15
|
+
need(value.qaFix==='disabled'||value.qa==='run','invalid_input');
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
export function readControlPolicyFile(file){
|
|
19
|
+
const before=fs.lstatSync(file);
|
|
20
|
+
need(before.isFile()&&!before.isSymbolicLink()&&before.nlink===1&&before.size<=65536,'invalid_input');
|
|
21
|
+
const fd=fs.openSync(file,fs.constants.O_RDONLY|fs.constants.O_NOFOLLOW);
|
|
22
|
+
try{
|
|
23
|
+
const bytes=fs.readFileSync(fd),after=fs.fstatSync(fd),current=fs.lstatSync(file);
|
|
24
|
+
need([after,current].every(s=>['dev','ino','size','mtimeMs','ctimeMs'].every(k=>s[k]===before[k]))
|
|
25
|
+
&&bytes.length===before.size,'snapshot_changed');
|
|
26
|
+
const text=bytes.toString('utf8');need(Buffer.from(text).equals(bytes),'invalid_input');
|
|
27
|
+
return readControlPolicy(parseModelJson(text));
|
|
28
|
+
}finally{fs.closeSync(fd);}
|
|
29
|
+
}
|
|
30
|
+
export function controlPolicyFromSnapshot(snapshot){
|
|
31
|
+
return snapshot.records.find(row=>row.payload.type==='init')?.payload.config?.controlPolicy??null;
|
|
32
|
+
}
|
|
33
|
+
export function assertControlEntry(snapshot,policy){
|
|
34
|
+
const saved=controlPolicyFromSnapshot(snapshot);
|
|
35
|
+
need((saved===null)===(policy===null),'fingerprint_mismatch');
|
|
36
|
+
if(saved!==null)need(digest(readControlPolicy(saved))===digest(readControlPolicy(policy)),'fingerprint_mismatch');
|
|
37
|
+
}
|
|
38
|
+
export function readControlTarget(raw){
|
|
39
|
+
const v=json(raw);shape(v,['version','identity','state','code','packageDigest','effectId','invocationId','revision',
|
|
40
|
+
...(Object.hasOwn(v,'child')?['child']:[])]);
|
|
41
|
+
need(v.version===2&&typeof v.state==='string'&&(v.code===null||typeof v.code==='string'),'invalid_input');
|
|
42
|
+
validIdentity(v.identity);hex(v.revision);
|
|
43
|
+
if(v.packageDigest!==null)hex(v.packageDigest);
|
|
44
|
+
for(const key of ['effectId','invocationId'])if(v[key]!==null)id(v[key]);
|
|
45
|
+
if(Object.hasOwn(v,'child'))readFixControlTarget(v.child);
|
|
46
|
+
return v;
|
|
47
|
+
}
|
|
48
|
+
export function readFixControlTarget(raw){
|
|
49
|
+
const v=json(raw);shape(v,['runId','revision','stage']);id(v.runId);hex(v.revision);
|
|
50
|
+
need(typeof v.stage==='string'&&v.stage.length>0&&v.stage.length<=128,'invalid_input');return v;
|
|
51
|
+
}
|
|
52
|
+
export function controlTarget(status,snapshot){
|
|
53
|
+
const intent=snapshot.records.findLast(row=>row.payload.type==='effect-intent')?.payload.effect??null;
|
|
54
|
+
const registration=snapshot.records.findLast(row=>row.payload.type==='review-invocation-registered')?.payload;
|
|
55
|
+
return readControlTarget({version:2,identity:status.identity,state:status.state,code:status.code??null,
|
|
56
|
+
packageDigest:status.packageDigest??null,effectId:intent?.id??null,
|
|
57
|
+
invocationId:registration?.binding?.invocationId??null,revision:snapshot.revision});
|
|
58
|
+
}
|
|
59
|
+
export function isControlRecovery(request){
|
|
60
|
+
return CONTROL_RECOVERY_OPERATIONS.includes(request.operation)
|
|
61
|
+
||request.operation==='fix_action'&&CONTROL_FIX_RECOVERY_OPERATIONS.includes(request.fixOperation);
|
|
62
|
+
}
|
|
63
|
+
export function assertExpectedControl(expected,current){
|
|
64
|
+
need(expected!==undefined,'invalid_input');
|
|
65
|
+
need(digest(readControlTarget(expected))===digest(readControlTarget(current)),'snapshot_changed');
|
|
66
|
+
}
|
|
67
|
+
// The existing store owns the writer lock. This guard never queues a previewed
|
|
68
|
+
// command behind another mutation; validation and invocation share that owner.
|
|
69
|
+
export function withControlPolicyHost(host,{identity,snapshot,launchTarget=null}){
|
|
70
|
+
let busy=false;
|
|
71
|
+
return {...host,async handle(raw){
|
|
72
|
+
let ownsBusy=false,checking=true;
|
|
73
|
+
try{
|
|
74
|
+
const request=json(raw);need(request.version===2,'fingerprint_mismatch');
|
|
75
|
+
if(busy&&!['status','cancel','fix_status'].includes(request.operation))return {outcome:'rejected',code:'host_busy'};
|
|
76
|
+
const recovering=isControlRecovery(request);
|
|
77
|
+
need(recovering||!Object.hasOwn(request,'expectedControl'),'invalid_input');
|
|
78
|
+
const {expectedControl,...wire}=request;wire.version=1;
|
|
79
|
+
// A busy poll cannot publish a recovery target.
|
|
80
|
+
if(busy)return host.handle(wire);
|
|
81
|
+
busy=true;ownsBusy=true;
|
|
82
|
+
if(recovering){
|
|
83
|
+
checking=false;
|
|
84
|
+
const status=await host.handle({version:1,requestId:request.requestId,operation:'status',identity});
|
|
85
|
+
checking=true;
|
|
86
|
+
if(request.operation==='fix_action'){
|
|
87
|
+
need(expectedControl!==undefined,'invalid_input');readControlTarget(expectedControl);
|
|
88
|
+
need(Object.hasOwn(expectedControl,'child'),'invalid_input');
|
|
89
|
+
const {child,...parent}=expectedControl;assertExpectedControl(parent,controlTarget(status,snapshot()));
|
|
90
|
+
wire.expectedFixControl=readFixControlTarget(child);
|
|
91
|
+
}else assertExpectedControl(expectedControl,controlTarget(status,snapshot()));
|
|
92
|
+
need(digest(wire.identity)===digest(status.identity),'snapshot_changed');
|
|
93
|
+
}
|
|
94
|
+
checking=false;
|
|
95
|
+
const result=await host.handle(wire);
|
|
96
|
+
if(request.operation==='fix_status'&&result.childControlTarget){
|
|
97
|
+
const parent=await host.handle({version:1,requestId:request.requestId,operation:'status',identity});
|
|
98
|
+
return {...result,controlTarget:{...controlTarget(parent,snapshot()),child:readFixControlTarget(result.childControlTarget)}};
|
|
99
|
+
}
|
|
100
|
+
if(result.identity&&result.state&&request.operation==='status')
|
|
101
|
+
return {...result,controlTarget:controlTarget(result,snapshot()),
|
|
102
|
+
...(launchTarget?{launchControlTarget:launchTarget(snapshot())}: {})};
|
|
103
|
+
return result;
|
|
104
|
+
}catch(error){
|
|
105
|
+
if(checking&&['invalid_input','snapshot_changed','fingerprint_mismatch'].includes(error.code))
|
|
106
|
+
return {outcome:'rejected',code:error.code,reason:error.code==='snapshot_changed'
|
|
107
|
+
?'恢复目标已经变化;先核对当前状态和原操作,不自动更新旧目标后重试。':'恢复需要 status 返回的当前 controlTarget;旧运行使用原兼容入口。'};
|
|
108
|
+
throw error;
|
|
109
|
+
}finally{if(ownsBusy)busy=false;}
|
|
110
|
+
}};
|
|
111
|
+
}
|
|
@@ -50,7 +50,9 @@ export function attemptAnswerName(root,name,attempt){
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
// Returns {mode,gap}; gap is a refusal for a bootstrap case this driver does not support.
|
|
53
|
-
export function inspectDriverBootstrap({advance,definition,permissions}){
|
|
53
|
+
export function inspectDriverBootstrap({advance,definition,permissions,controlPolicy=null}){
|
|
54
|
+
if(controlPolicy?.bootstrap==='disabled'&&permissions.includes('--bootstrap-config'))
|
|
55
|
+
return {mode:null,gap:'invalid_arguments: bootstrap disabled 禁止 --bootstrap-config;驾驶员未读取配置、未启动宿主'};
|
|
54
56
|
if(!advance||!permissions.includes('--bootstrap-config'))return {mode:null,gap:null};
|
|
55
57
|
let task;
|
|
56
58
|
try{task=inspectCmAiBootstrapTask({specsDir:definition.specsDir,codeProject:definition.codeProject,
|
|
@@ -59,7 +61,8 @@ export function inspectDriverBootstrap({advance,definition,permissions}){
|
|
|
59
61
|
}
|
|
60
62
|
if(task.mode!=='instructions')return {mode:task.mode,gap:null};
|
|
61
63
|
const gap=line=>({mode:'instructions',gap:`${line};可由当前 AI 会话用 cm-ai-host.mjs serve 应答 init_generate/init_verify`});
|
|
62
|
-
if(permissions.includes('--protected-config'))
|
|
64
|
+
if(controlPolicy?controlPolicy.development==='provider':permissions.includes('--protected-config'))
|
|
65
|
+
return gap(controlPolicy?'规范任务不支持 provider 开发驾驶':'规范任务不支持 --protected-config(provider 开发)驾驶');
|
|
63
66
|
if(Object.hasOwn(definition,'codeProjects'))return gap('多代码根(codeProjects)规范任务驾驶员尚不支持');
|
|
64
67
|
let selection;
|
|
65
68
|
// The host's own reader: a regular, non-symlink file of at most 64 KiB with only selection.
|
|
@@ -186,9 +189,9 @@ function readVerify(root,name,{definition,plan,attempt}){
|
|
|
186
189
|
// only when the develop effect starts, and the task entry inside it
|
|
187
190
|
// (host-bootstrap.mjs run()), so both are required here; everything else the host
|
|
188
191
|
// checks at launch runs before host_ready, before any command.
|
|
189
|
-
function authorizeRulesLaunch({definition,plan,permissions}){
|
|
192
|
+
function authorizeRulesLaunch({definition,plan,permissions,controlPolicy=null}){
|
|
190
193
|
const refusal=';驾驶员不运行 init-verify 命令、不启动宿主';
|
|
191
|
-
refuse(permissions.includes('--allow-bootstrap-write'),
|
|
194
|
+
refuse(controlPolicy?controlPolicy.bootstrap==='write':permissions.includes('--allow-bootstrap-write'),
|
|
192
195
|
`规范任务需要 --allow-bootstrap-write:宿主写规范前要求这一授权(bootstrap_write_authorization_required)${refusal}`);
|
|
193
196
|
const protection=permissions.indexOf('--protected-conversation-config');
|
|
194
197
|
if(protection!==-1)try{readConversationProtection(permissions[protection+1]);}
|
|
@@ -209,14 +212,14 @@ function authorizeRulesLaunch({definition,plan,permissions}){
|
|
|
209
212
|
`${definition.identity.taskId} 不是当前可进入的 bootstrap 任务(nextTask ${entry?.id??'无'},宿主以 bootstrap_task_required 拒绝)${refusal}`);
|
|
210
213
|
}
|
|
211
214
|
|
|
212
|
-
export function readBootstrapRulesAnswers({answers,operation,definition,plan,permissions,bootstrap,reachable}){
|
|
215
|
+
export function readBootstrapRulesAnswers({answers,operation,definition,plan,permissions,bootstrap,reachable,controlPolicy=null}){
|
|
213
216
|
const result=new Map(),slug=`.reviews/${definition.feature.replace(/^\d+\./,'')}-${definition.identity.taskId}`;
|
|
214
217
|
const pair=attempt=>`answers/init-generate-a${attempt}.json 与 answers/init-verify-a${attempt}.json`;
|
|
215
218
|
if(reachable.reviewAfterDevelop)
|
|
216
|
-
stop(2
|
|
219
|
+
stop(2,`规范任务不能预先进入第 2 轮:修订答案须在读取首轮审查 findings 之后编写。首轮自动审查后停在 changes_requested;读取 ${slug}-r1.md 的 findings;若要求修改,写 ${pair(2)} 后 advance。`);
|
|
217
220
|
if(reachable.reviewFirst)
|
|
218
|
-
stop(2,`规范修订答案须在读取首轮审查 findings 之后编写:请先以 decision 和当前 packageDigest ${reachable.packageDigest} 单独运行审查,读取 ${slug}-r1.md 的 findings,写 ${pair(2)} 后再 advance
|
|
219
|
-
if(reachable.attempts.length)authorizeRulesLaunch({definition,plan,permissions});
|
|
221
|
+
stop(2,`规范修订答案须在读取首轮审查 findings 之后编写:请先以 decision 和当前 packageDigest ${reachable.packageDigest} 单独运行审查,读取 ${slug}-r1.md 的 findings,写 ${pair(2)} 后再 advance`);
|
|
222
|
+
if(reachable.attempts.length)authorizeRulesLaunch({definition,plan,permissions,controlPolicy});
|
|
220
223
|
for(const attempt of reachable.attempts){
|
|
221
224
|
const names=['init-generate','init-verify'].map(name=>attemptAnswerName(answers??'',name,attempt));
|
|
222
225
|
for(const name of names){
|