@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
|
@@ -17,10 +17,9 @@ import { digest,need,shape,id,text,json,freeze,arrayItems,validIdentity,validTas
|
|
|
17
17
|
import { reviewResult,reviewReceipt,boundReviewText,reviewPaths } from './review-runner.mjs';
|
|
18
18
|
import { checkCompletion } from './gate-bridge.mjs';
|
|
19
19
|
import { runnerPayload,runnerPayloadV3,readRunnerHistory,attemptBaseline,boundRunnerRecord,
|
|
20
|
-
MAX_AI_JOINED_HOSTS,controlledState,stageAllowed,effectSlotFree,reviewTimeoutTransition,
|
|
20
|
+
MAX_AI_JOINED_HOSTS,controlledState,stageAllowed,effectSlotFree,reviewTimeoutTransition,validateTaskLearningReviewPackage,
|
|
21
21
|
reviewRetrySpent,abandonableReviewResult,developBudget,developBudgetExhausted,
|
|
22
|
-
MAX_REVIEW_REDISPATCHES,REVIEW_RETRY_CODES,
|
|
23
|
-
REVIEW_DENIAL_LIMIT_CODE,REVIEW_DISPATCH_CONFIRM_REQUIRED_CODE,countReviewDispatchConfirmations,reviewRedispatchCount,reviewRedispatchable,reviewRedispatchExhausted,REVIEW_REDISPATCH_LIMIT_CODE,reviewRedispatchLimitReason,reviewRedispatchStopReason,reviewAbandonRefusal,
|
|
22
|
+
MAX_REVIEW_REDISPATCHES,REVIEW_RETRY_CODES,reviewRedispatchCount,reviewRedispatchable,reviewRedispatchExhausted,REVIEW_REDISPATCH_LIMIT_CODE,reviewRedispatchLimitReason,reviewRedispatchStopReason,reviewAbandonRefusal,
|
|
24
23
|
completionBlockCount,completionRetriesExhausted,supersededReviewPayload,bootstrapReviewRecoverable,protectedDevelopScope,protectedScopeBlockReason,
|
|
25
24
|
developTimeoutBasis,developTimeoutEffect,developTimeoutState,DEVELOP_CALL_TIMEOUT_REASON,
|
|
26
25
|
developAnswerInvalidEffect,developAnswerRetryable,developAnswerInvalidReason,
|
|
@@ -31,6 +30,7 @@ import { runnerPayload,runnerPayloadV3,readRunnerHistory,attemptBaseline,boundRu
|
|
|
31
30
|
pendingDevelopStart,redoDevelopStart,workerGoneBinding,EFFECT_INTERRUPT_LIMIT_CODE,effectInterruptLimitReason,developRedoSource,COMMIT_INTERRUPTED_CODE,COMMIT_INTERRUPTED_REASON,
|
|
32
31
|
DOCUMENTATION_SYNC_CODES,documentationSyncSource,documentationSyncRetryCode,documentationSyncStopReason } from './durable-runner-state.mjs';
|
|
33
32
|
import {splitDocumentationState} from './host-documentation.mjs';
|
|
33
|
+
import {readControlPolicy} from './control-policy.mjs';
|
|
34
34
|
import {readProcessStartTime,inspectWorkerGroup} from './worker-process-identity.mjs';
|
|
35
35
|
import {recoverRunnerCommitImage} from './task-commit.mjs';
|
|
36
36
|
import {commitRunnerFixture} from './task-commit.mjs';
|
|
@@ -156,6 +156,7 @@ export function createTaskRunner(options) {
|
|
|
156
156
|
if(options && Object.hasOwn(options,'knowledgeCloseout'))optionKeys.push('knowledgeCloseout');
|
|
157
157
|
if(options && Object.hasOwn(options,'executionPolicy'))optionKeys.push('executionPolicy');
|
|
158
158
|
if(options && Object.hasOwn(options,'externalModels'))optionKeys.push('externalModels');
|
|
159
|
+
if(options && Object.hasOwn(options,'controlPolicy'))optionKeys.push('controlPolicy');
|
|
159
160
|
if(invocationMode)optionKeys.push('reviewInvocation');
|
|
160
161
|
shape(options,optionKeys);
|
|
161
162
|
need(options.providerDevelopment===undefined||typeof options.providerDevelopment==='boolean','invalid_input');
|
|
@@ -192,10 +193,10 @@ export function createTaskRunner(options) {
|
|
|
192
193
|
if(invocationMode)id(r.adapterId);
|
|
193
194
|
return {...v,...(invocationMode?{adapterId:r.adapterId}:{}),run};
|
|
194
195
|
});
|
|
195
|
-
let invocationConfig=null,
|
|
196
|
+
let invocationConfig=null,liveHostContextId=null,reviewTimeoutMs=null;
|
|
196
197
|
if(invocationMode){
|
|
197
198
|
need(reviewers.length===1&&['codex','claude'].includes(reviewers[0].provider)&&reviewers[0].allowed&&reviewers[0].available,'runner_invocation');
|
|
198
|
-
shape(options.reviewInvocation,['developerThreadId','excludedThreadIds',
|
|
199
|
+
shape(options.reviewInvocation,['developerThreadId','excludedThreadIds',
|
|
199
200
|
...['hostContextId','timeoutMs'].filter(key=>Object.hasOwn(options.reviewInvocation,key))]);
|
|
200
201
|
liveHostContextId=options.reviewInvocation.hostContextId??null;
|
|
201
202
|
// Transient like hostContextId, never journaled: the host sizes the review
|
|
@@ -206,7 +207,6 @@ export function createTaskRunner(options) {
|
|
|
206
207
|
}
|
|
207
208
|
if(liveHostContextId!==null){id(liveHostContextId);
|
|
208
209
|
need(![developer.contextId,...reviewers.flatMap(r=>r.contexts)].includes(liveHostContextId),'not_independent');}
|
|
209
|
-
authorize=options.reviewInvocation.authorize;need(typeof authorize==='function','runner_invocation');
|
|
210
210
|
invocationConfig=json({developerThreadId:options.reviewInvocation.developerThreadId,
|
|
211
211
|
excludedThreadIds:options.reviewInvocation.excludedThreadIds});
|
|
212
212
|
id(invocationConfig.developerThreadId);need(Array.isArray(invocationConfig.excludedThreadIds)
|
|
@@ -219,7 +219,8 @@ export function createTaskRunner(options) {
|
|
|
219
219
|
...(Object.hasOwn(options,'taskLearning')?{taskLearning:json(options.taskLearning)}:{}),
|
|
220
220
|
...(Object.hasOwn(options,'knowledgeCloseout')?{knowledgeCloseout:readCloseoutPolicy(options.knowledgeCloseout)}:{}),
|
|
221
221
|
...(Object.hasOwn(options,'executionPolicy')?{executionPolicy:readExecutionPolicy(options.executionPolicy)}:{}),
|
|
222
|
-
...(Object.hasOwn(options,'externalModels')?{externalModels:readExternalModels(options.externalModels)}:{})
|
|
222
|
+
...(Object.hasOwn(options,'externalModels')?{externalModels:readExternalModels(options.externalModels)}:{}),
|
|
223
|
+
...(Object.hasOwn(options,'controlPolicy')?{controlPolicy:readControlPolicy(options.controlPolicy)}:{})});
|
|
223
224
|
const taskLearning=metadata.taskLearning??null;
|
|
224
225
|
if(taskLearning!==null){need(taskMode,'runner_learning');
|
|
225
226
|
shape(taskLearning,['feature',...(Object.hasOwn(taskLearning,'hostHandoff')?['hostHandoff']:[])]);
|
|
@@ -353,13 +354,10 @@ export function createTaskRunner(options) {
|
|
|
353
354
|
function reviewRedispatchRecords(){
|
|
354
355
|
return journal?.filter(row=>row.payload.type==='review-redispatch'&&row.payload.attempt===attempt).length??0;
|
|
355
356
|
}
|
|
356
|
-
// The
|
|
357
|
-
//
|
|
358
|
-
// value), so an id can never repeat one the cache holds.
|
|
357
|
+
// The entry derives each redispatch id from the current round's durable effects,
|
|
358
|
+
// so an id cannot repeat one the cache already holds.
|
|
359
359
|
const reviewEffectIds=()=>[...cache.values()].filter(entry=>entry.effect.kind==='review'
|
|
360
360
|
&&entry.effect.identity.attempt===attempt).map(entry=>entry.effect.id);
|
|
361
|
-
// Confirmations of this round (abandon_review on a review that never started).
|
|
362
|
-
const reviewDispatchConfirmations=()=>countReviewDispatchConfirmations((journal??[]).map(row=>row.payload),attempt);
|
|
363
361
|
// A spent retryable review block this round may still redispatch (advance).
|
|
364
362
|
const reviewRedispatchLive=()=>Boolean(!(metadata.externalModels||metadata.executionPolicy)&&invocationMode&&store&&!busy&&!poisoned
|
|
365
363
|
&&!restored?.pending&&reviewRedispatchable({state,code,attempt,cache:[...cache.values()],calls,reviewInvocation},
|
|
@@ -615,12 +613,6 @@ export function createTaskRunner(options) {
|
|
|
615
613
|
current=freeze({...current,reviewRedispatchStopRequired:true,reason:reviewRedispatchStopReason(current.code)});
|
|
616
614
|
else if(current.state==='blocked'&&reviewRedispatchSpent())
|
|
617
615
|
current=freeze({...current,code:REVIEW_REDISPATCH_LIMIT_CODE,reason:reviewRedispatchLimitReason(current.code)});
|
|
618
|
-
// A round whose review never started: a refused authorization (explicit confirmation
|
|
619
|
-
// needed) or registrations voided before dispatch three times. Shared with replay.
|
|
620
|
-
if(!busy&¤t.state==='pending_review'){
|
|
621
|
-
const never=reviewNeverStartedStatus({state,code,attempt,cache:[...cache.values()]},reviewDispatchConfirmations());
|
|
622
|
-
if(never!==null)current=freeze({...current,...never});
|
|
623
|
-
}
|
|
624
616
|
// Status only; never part of a cached result or checkpoint.
|
|
625
617
|
if(current.state==='unknown'&&reviewResultAbandonable())current=freeze({...current,abandonableReviewResult:true});
|
|
626
618
|
else if(current.state==='unknown'&&!(metadata.externalModels||metadata.executionPolicy)&&invocationMode&&store&&!busy&&!poisoned&&!restored?.pending){
|
|
@@ -631,8 +623,8 @@ export function createTaskRunner(options) {
|
|
|
631
623
|
&&readRunnerHistory(journal,metadata,3).reviewReconciliation!==null;
|
|
632
624
|
if((metadata.externalModels||metadata.executionPolicy)&&!busy&&!poisoned&&invocationMode&&store&&reviewInvocation?.registration
|
|
633
625
|
&&(available||current.state==='unknown'&&reviewInvocation.result?.reconciliationRequired!==false)){
|
|
634
|
-
const
|
|
635
|
-
current=freeze({...current,reviewReconciliation:{invocationId:
|
|
626
|
+
const binding=reviewInvocation.registration.binding;
|
|
627
|
+
current=freeze({...current,reviewReconciliation:{invocationId:binding.invocationId,requestDigest:binding.requestDigest,
|
|
636
628
|
provider:reviewers[0].provider,providerThreadId:reviewInvocation.started,available},
|
|
637
629
|
reason:available?'原调用的终态与本地清理收据已保存;使用 reconcile_review 接纳证据,此操作不派发模型。'
|
|
638
630
|
:'缺少原调用的可信终态或本地清理证据。保留本 run、attempt、journal 和快照;按 invocationId / providerThreadId 向原宿主或 provider 核对结果及终止状态,并确认本地后代已退出。当前适配器没有远端状态查询入口,人工说明、PID 消失或重启均不能解锁;不要删 journal、换 runId 或重派。'});
|
|
@@ -919,60 +911,26 @@ export function createTaskRunner(options) {
|
|
|
919
911
|
const nextSequence=sequence+1,request=requestFor({invocationId:`${session}.${nextSequence}`,
|
|
920
912
|
identity:{...config.identity,attempt},role:'reviewer',provider:adapter.provider,
|
|
921
913
|
requestedModel:adapter.requestedModel,contextId,payload});
|
|
922
|
-
let authorizationAt;
|
|
923
|
-
try{authorizationAt=safeTime();}catch{halt('unknown','clock_invalid');return;}
|
|
924
|
-
let grant;
|
|
925
|
-
try{
|
|
926
|
-
const returned=authorize(request,Object.freeze({authorizationAt}));
|
|
927
|
-
if(types.isPromise(returned)){
|
|
928
|
-
observePromise(returned,ignorePromiseResult,ignorePromiseResult);
|
|
929
|
-
if(state==='cancelled'||controller.signal.aborted)return;
|
|
930
|
-
need(false,'authorization_invalid');
|
|
931
|
-
}
|
|
932
|
-
if(state==='cancelled'||controller.signal.aborted)return;
|
|
933
|
-
grant=json(returned);
|
|
934
|
-
if(digest(grant)===digest({status:'denied',code:'permission_denied'})){
|
|
935
|
-
halt('pending_review','permission_denied');return;
|
|
936
|
-
}
|
|
937
|
-
}catch(error){
|
|
938
|
-
if(state==='cancelled'||controller.signal.aborted)return;
|
|
939
|
-
halt('unknown',failureCode(error)==='clock_invalid'?'clock_invalid':'authorization_invalid');return;
|
|
940
|
-
}
|
|
941
|
-
if(state==='cancelled'||controller.signal.aborted)return;
|
|
942
914
|
let registeredAt;
|
|
943
915
|
try{registeredAt=safeTime();}catch{halt('unknown','clock_invalid');return;}
|
|
944
|
-
if(
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
authorizationAt,registeredAt,grant};
|
|
951
|
-
// Validate first, then journal the signer immediately before registration.
|
|
952
|
-
// Durable host lists and prior joiners already have replayable authority.
|
|
953
|
-
if(![invocationConfig.developerThreadId,...invocationConfig.excludedThreadIds,...joinedHosts].includes(grant.hostContextId)){
|
|
916
|
+
if(state==='cancelled'||controller.signal.aborted)return;
|
|
917
|
+
const hostContextId=liveHostContextId??invocationConfig.developerThreadId;
|
|
918
|
+
const binding=json({adapterId:adapter.adapterId,invocationId:request.invocationId,requestDigest:request.requestDigest,
|
|
919
|
+
identity:request.identity,reviewerId:adapter.id,logicalContextId:request.contextId,
|
|
920
|
+
packageDigest:reviewPackage.packageDigest,hostContextId});
|
|
921
|
+
if(![invocationConfig.developerThreadId,...invocationConfig.excludedThreadIds,...joinedHosts].includes(hostContextId)){
|
|
954
922
|
need(joinedHosts.length<MAX_AI_JOINED_HOSTS,'host_limit');
|
|
955
|
-
persist('host-joined',{hostContextId
|
|
923
|
+
persist('host-joined',{hostContextId});joinedHosts.push(hostContextId);
|
|
956
924
|
}
|
|
957
|
-
persist('review-invocation-registered',registrationFields);
|
|
958
|
-
sequence=nextSequence;
|
|
959
925
|
const registration=json({reviewerId:adapter.id,adapterId:adapter.adapterId,requestDigest:request.requestDigest,
|
|
960
|
-
|
|
926
|
+
registeredAt,binding});
|
|
927
|
+
persist('review-invocation-registered',{effectId,...registration});
|
|
928
|
+
sequence=nextSequence;
|
|
961
929
|
const call={invocationId:request.invocationId,contextId,provider:request.provider,requestedModel:adapter.requestedModel,
|
|
962
|
-
effectiveModel:'unknown',channel:'host-
|
|
930
|
+
effectiveModel:'unknown',channel:'host-review',started:false,terminal:'running',requestDigest:request.requestDigest,
|
|
963
931
|
resultDigest:null,providerThreadId:null};
|
|
964
932
|
calls.push(call);
|
|
965
|
-
|
|
966
|
-
try{dispatchAt=safeTime();if(dispatchAt<registeredAt)notDispatched='clock_invalid';
|
|
967
|
-
else if(dispatchAt>=grant.expiresAt)notDispatched='grant_expired';}
|
|
968
|
-
catch{notDispatched='clock_invalid';}
|
|
969
|
-
if(notDispatched){
|
|
970
|
-
const fields={effectId,invocationId:request.invocationId,dispatchAt,outcome:'not_dispatched',observation:null,inspection:null,
|
|
971
|
-
reconciliationRequired:true,reason:notDispatched};
|
|
972
|
-
persist('review-invocation-result',fields);const result=resultView(fields);
|
|
973
|
-
Object.assign(call,{terminal:'not_dispatched',resultDigest:digest(result)});
|
|
974
|
-
reviewInvocation=json({registration,started:null,result});halt('pending_review',notDispatched);return;
|
|
975
|
-
}
|
|
933
|
+
const dispatchAt=registeredAt;
|
|
976
934
|
call.started=true;
|
|
977
935
|
const expectation={request,developerThreadId:invocationConfig.developerThreadId,
|
|
978
936
|
excludedThreadIds:reviewExclusions(liveInvocation(),calls,developer.contextId)};
|
|
@@ -1481,14 +1439,9 @@ export function createTaskRunner(options) {
|
|
|
1481
1439
|
timeoutBasis=developTimeoutRetryBasis();need(timeoutBasis!==null,'develop_timeout_root_changed');
|
|
1482
1440
|
if(state==='blocked')timeoutBasis=null;
|
|
1483
1441
|
}
|
|
1484
|
-
// A refused authorization is a decision: a review is admitted again only after the
|
|
1485
|
-
// operator's journaled confirmation (abandon_review), bounded per round.
|
|
1486
|
-
if(v.kind==='review'&&reviewDenialUnconfirmed({state,code}))
|
|
1487
|
-
need(false,reviewDenialExhausted({state,code},reviewDispatchConfirmations())?REVIEW_DENIAL_LIMIT_CODE:REVIEW_DISPATCH_CONFIRM_REQUIRED_CODE);
|
|
1488
1442
|
answerRetry=v.kind==='develop'&&state==='blocked'&&code==='failed'&&answerRetryable();
|
|
1489
1443
|
need(timeoutBasis!==null||answerRetry||recheck!==null||completeSource!==null||dispatchBasis!==null
|
|
1490
1444
|
||stageAllowed(v.kind,state,code,priorReview?.verdict),'stage_mismatch');need(effectSlotFree(v.kind,[...cache.values()],calls),'limit_exceeded');
|
|
1491
|
-
need(!(v.kind==='review'&&reviewNotDispatchedExhausted({state,code,attempt,cache:[...cache.values()]},reviewDispatchConfirmations().extended)),REVIEW_NOT_DISPATCHED_LIMIT_CODE);
|
|
1492
1445
|
if(Object.hasOwn(original,'specification'))verifySpecificationMaterial(original);
|
|
1493
1446
|
if(v.kind==='develop'&&bootstrap!==null)bootstrap.assertWriteAuthorized();
|
|
1494
1447
|
} catch(error){return Promise.resolve(freeze({outcome:'rejected',code:error.code??'invalid_input',
|
|
@@ -1730,29 +1683,6 @@ export function createTaskRunner(options) {
|
|
|
1730
1683
|
};
|
|
1731
1684
|
const abandonReview=raw=>{
|
|
1732
1685
|
try{
|
|
1733
|
-
// A review that never started (a refused authorization, or the spent not-dispatched
|
|
1734
|
-
// redispatch bound): nothing ran, so no process needs proving stopped, even for
|
|
1735
|
-
// external-model runs. Only this explicit, audited confirmation leaves those ends.
|
|
1736
|
-
if(invocationMode&&store&&!busy&&!poisoned&&!restored?.pending&&state==='pending_review'){
|
|
1737
|
-
const confirmed=reviewDispatchConfirmations(),ended={state,code,attempt,cache:[...cache.values()]};
|
|
1738
|
-
const denied=reviewDenialUnconfirmed(ended),voided=reviewNotDispatchedExhausted(ended,confirmed.extended);
|
|
1739
|
-
if(denied||voided){
|
|
1740
|
-
if(denied&&reviewDenialExhausted(ended,confirmed))
|
|
1741
|
-
throw Object.assign(new Error(REVIEW_DENIAL_LIMIT_CODE),{code:REVIEW_DENIAL_LIMIT_CODE,reason:reviewDenialLimitReason()});
|
|
1742
|
-
if(voided&&!reviewNotDispatchedExtendable(ended,confirmed))
|
|
1743
|
-
throw Object.assign(new Error(REVIEW_NOT_DISPATCHED_LIMIT_CODE),
|
|
1744
|
-
{code:REVIEW_NOT_DISPATCHED_LIMIT_CODE,reason:reviewNotDispatchedLimitReason(code,confirmed.extended)});
|
|
1745
|
-
need(denied?reviewDenialConfirmable(ended,confirmed):true,'review_abandon_unavailable');
|
|
1746
|
-
const value=json(raw);shape(value,['allowed','reason']);
|
|
1747
|
-
need(value.allowed===true,'review_abandon_authorization_required');
|
|
1748
|
-
need(typeof value.reason==='string'&&value.reason.trim().length>0&&Buffer.byteLength(value.reason,'utf8')<=500
|
|
1749
|
-
&&!/[\r\n\0]/.test(value.reason),'review_abandon_reason_required');
|
|
1750
|
-
persist('review-dispatch-confirmed',{effectId:[...cache.values()].at(-1).effect.id,attempt,code,reason:value.reason,
|
|
1751
|
-
at:new Date().toISOString()});
|
|
1752
|
-
const recovered=readRunnerHistory(journal,metadata,3).state;
|
|
1753
|
-
({state,code}=recovered);reason=recovered.reason??null;publication=privateStatus();return status();
|
|
1754
|
-
}
|
|
1755
|
-
}
|
|
1756
1686
|
need(!(metadata.externalModels||metadata.executionPolicy),'external_review_reconciliation_required');
|
|
1757
1687
|
// V5 (A34): the operator confirms the spent block's reviewer stopped; this
|
|
1758
1688
|
// journals the round's second no-result redispatch (no dispatch here).
|
|
@@ -1762,7 +1692,7 @@ export function createTaskRunner(options) {
|
|
|
1762
1692
|
need(typeof value.reason==='string'&&value.reason.trim().length>0&&Buffer.byteLength(value.reason,'utf8')<=500
|
|
1763
1693
|
&&!/[\r\n\0]/.test(value.reason),'review_abandon_reason_required');
|
|
1764
1694
|
persist('review-redispatch',{effectId:[...cache.values()].at(-1).effect.id,
|
|
1765
|
-
invocationId:reviewInvocation.registration.
|
|
1695
|
+
invocationId:reviewInvocation.registration.binding.invocationId,attempt,code,reason:value.reason,at:new Date().toISOString()});
|
|
1766
1696
|
state='pending_review';publication=privateStatus();return status();
|
|
1767
1697
|
}
|
|
1768
1698
|
if(state==='blocked'&&reviewRedispatchSpent())throw Object.assign(new Error('review_abandon_budget_exhausted'),{code:'review_abandon_budget_exhausted'});
|
|
@@ -1804,7 +1734,7 @@ export function createTaskRunner(options) {
|
|
|
1804
1734
|
need(reviewRedispatchCount(history.state.cache,history.state.calls,attempt,contextId,reviewRedispatchRecords())<MAX_REVIEW_REDISPATCHES,
|
|
1805
1735
|
'review_abandon_budget_exhausted');
|
|
1806
1736
|
const fields={effectId:history.pending.id,
|
|
1807
|
-
invocationId:history.state.reviewInvocation.registration.
|
|
1737
|
+
invocationId:history.state.reviewInvocation.registration.binding.invocationId,
|
|
1808
1738
|
registeredDigest:registration.digest,startedDigest:started?.digest??null,
|
|
1809
1739
|
...(withResult?{resultDigest:last.digest}:{}),
|
|
1810
1740
|
reason:value.reason,at:new Date().toISOString()};
|
|
@@ -1828,7 +1758,7 @@ export function createTaskRunner(options) {
|
|
|
1828
1758
|
const {request,effect,before,result,...binding}=proof;
|
|
1829
1759
|
const call=calls.find(item=>item.invocationId===value.invocationId);
|
|
1830
1760
|
need(['unknown','failed'].includes(call?.terminal),'review_reconciliation_unavailable');
|
|
1831
|
-
// Same call, same
|
|
1761
|
+
// Same call, same binding and same effect. The journal retains the original
|
|
1832
1762
|
// unknown and receipt; one atomic record contains the validated transition.
|
|
1833
1763
|
Object.assign(call,{terminal:result.outcome==='observed'?'succeeded':'failed',
|
|
1834
1764
|
resultDigest:digest(result.outcome==='observed'?result.inspection.review:result)});
|
|
@@ -2007,7 +1937,14 @@ export function createTaskRunner(options) {
|
|
|
2007
1937
|
};
|
|
2008
1938
|
// Interrupted intents keep their ids; the entry derives fresh ones from this count.
|
|
2009
1939
|
const interruptions=kind=>parsedHistory?.interrupted?.filter(item=>item.kind===kind).length??0;
|
|
2010
|
-
|
|
1940
|
+
// Read-only projection of the baseline-derived reviewed change inventory.
|
|
1941
|
+
// Entry checks current status before/after the call; do not rebuild a baseline
|
|
1942
|
+
// from the author's handoff or change any completion/correction authority.
|
|
1943
|
+
const qaChangedFiles=packageDigest=>{
|
|
1944
|
+
need(state==='fixture_completed'&&reviewPackage?.packageDigest===packageDigest,'stale_qa');
|
|
1945
|
+
return freeze({paths:reviewPackage.changes.map(change=>change.path),source:'review_package'});
|
|
1946
|
+
};
|
|
1947
|
+
const api={qaChangedFiles,reviseQa,supersedeEvidence,rebindSpecification,abandonReview,reconcileReview,abandonEffect,recoverBootstrapReview,executeEffect,status,cancel,run,inspectFixAssociation,acceptCompletedFix,attachQa,verificationBlocks,completionBlocks,reviewEffectIds,recheckLearningInput,redoDevelop,recoverCommit,interruptions};
|
|
2011
1948
|
if(bootstrap!==null)api.inspectBootstrapAdmission=()=>bootstrap.inspectAdmission(original);
|
|
2012
1949
|
if(taskLearning!==null)api.attachLearningEvidence=attachLearningEvidence;
|
|
2013
1950
|
// A terminal reviewer observation is durable even if the host died before
|
|
@@ -2015,7 +1952,7 @@ export function createTaskRunner(options) {
|
|
|
2015
1952
|
if(restored?.pendingObservedReview){
|
|
2016
1953
|
const observed=restored.pendingObservedReview,request=observed.request,result=observed.result;
|
|
2017
1954
|
const call={invocationId:request.invocationId,contextId:request.contextId,provider:request.provider,
|
|
2018
|
-
requestedModel:request.requestedModel,effectiveModel:'unknown',channel:'host-
|
|
1955
|
+
requestedModel:request.requestedModel,effectiveModel:'unknown',channel:'host-review',
|
|
2019
1956
|
started:true,terminal:'succeeded',requestDigest:request.requestDigest,
|
|
2020
1957
|
resultDigest:digest(result.inspection.review),providerThreadId:observed.started};
|
|
2021
1958
|
sequence++;calls.push(call);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Immutable archive of
|
|
1
|
+
// Immutable archive of review source declarations, not proof of reviewer identity or execution.
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import {createHash} from 'node:crypto';
|
|
@@ -10,6 +10,7 @@ import {writeReviewEvidence} from '../cm-ai/review-evidence-file.mjs';
|
|
|
10
10
|
function archiveBytes({project,reviewPackage,review}){
|
|
11
11
|
const {packageDigest,...body}=reviewPackage;
|
|
12
12
|
need(packageDigest===digest(body)&&body.project===project,'review_package_mismatch');
|
|
13
|
+
// Legacy source/channel/independent labels are checked as declarations only.
|
|
13
14
|
need(review.source==='current_host_review_attestation'&&review.packageDigest===packageDigest
|
|
14
15
|
&&review.independent===true&&['codex-subagent','codex-cli','claude-cli'].includes(review.reviewer),
|
|
15
16
|
'init_review_evidence_invalid');
|
|
@@ -18,6 +19,7 @@ function archiveBytes({project,reviewPackage,review}){
|
|
|
18
19
|
const checked=reviewResultForPaths(review.result,reviewPackage,body.examinedPaths);
|
|
19
20
|
need(checked.verdict==='approved','init_review_not_approved');
|
|
20
21
|
need(path.isAbsolute(project)&&fs.realpathSync(project)===project,'unsupported_path');
|
|
22
|
+
// Retain legacy rendered labels to preserve existing archive bytes and recovery.
|
|
21
23
|
const bytes=Buffer.from(['---','workflow: cm-init',`at: ${review.at}`,`reviewer: ${review.reviewer}`,
|
|
22
24
|
'independent: true','verdict: approved',`package_sha256: ${packageDigest}`,'scope:',
|
|
23
25
|
...body.examinedPaths.map(file=>` - ${file}`),'---','',
|
|
@@ -36,7 +36,7 @@ export async function runPrdHostReview({specs,prepared,authorContextId,writeEnab
|
|
|
36
36
|
const paths=(pkg.stage==='design'?['requirements.md','design.md']:['requirements.md','design.md','tasks.md'])
|
|
37
37
|
.map(file=>`${pkg.feature}/${file}`).sort();
|
|
38
38
|
const response=json(await review({package:{...pkg,packageDigest:prepared.packageDigest},examinedPaths:paths,authorContextId,mode,
|
|
39
|
-
instructions:'Use only the
|
|
39
|
+
instructions:'Use only the configured current-host review channel. For independent review, use an actual fresh reviewer context without author history, per runtime/review.md; self-degraded uses the author context and explains why the independent channel is unavailable. Treat reviewer, independent and contextId as source declarations, not proof of reviewer identity or independent execution. Require declaration format and consistency: independent declares true with a contextId different from the declared author; self-degraded declares false with the declared author contextId and a degradedReason. Forward the original result unchanged. No provider/CLI invocation, installation, external transmission, Git or project writes without separate authority. Return {reviewer,contextId,independent,at,result}, plus degradedReason only for self-degraded. Result follows verdict/packageDigest/examinedPaths/findings/summary. Do not retry or switch mode after this attempt; unavailable/interrupted remains unknown.'
|
|
40
40
|
+(pkg.stage==='split'?' In this existing split attempt, assess submitted task boundaries: combined work must share one independently verifiable and reversible objective with every AC, original test and verification prerequisite retained. Check requirement/design/context evidence for high or unknown risk, explicit user independence and unrelated objectives; retain those boundaries and legitimate contract-first dependencies. Do not infer risk from keywords, add a classifier/review call, enforce a merge ratio or repartition already generated tasks for fewer reviews. Do not apply this new grouping guidance retroactively to older drafts, revisions, change plans or in-flight tasks. Report only existing requirement/design failures with concrete consequences; mechanical reference checks alone do not establish semantic risk or user intent. Configured roles and per-task N4 remain unchanged.':'')},signal),64*1024);
|
|
41
41
|
need(!signal.aborted,'cancelled');current();
|
|
42
42
|
validatePrdReviewMode(mode,response);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Publish
|
|
1
|
+
// Publish unchanged r1 source declarations. They do not prove reviewer identity or execution.
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import {assertPrdBatchActive} from './inputs-replaced.mjs';
|
|
4
4
|
import path from 'node:path';
|
|
@@ -15,8 +15,8 @@ export function inspectPrdReviewResponse({reviewPackage,packageDigest,authorCont
|
|
|
15
15
|
need(typeof reviewPackage.feature==='string'&&/^[1-9]\d*\.[a-z0-9]+(?:-[a-z0-9]+)*$/.test(reviewPackage.feature),'prd_review_feature_invalid');
|
|
16
16
|
const degraded=response.reviewer==='self-degraded';
|
|
17
17
|
shape(response,['reviewer','contextId','independent','at','result',...(degraded?['degradedReason']:[])]);
|
|
18
|
-
//
|
|
19
|
-
//
|
|
18
|
+
// Declared subagent context IDs use canonical spelling, not filesystem paths.
|
|
19
|
+
// Validate declaration format and consistency only, not the actual reviewer identity.
|
|
20
20
|
const context=response.contextId;
|
|
21
21
|
need(typeof context==='string'&&context.length<=128&&!/\s/.test(context));
|
|
22
22
|
if(response.reviewer==='codex-subagent'&&context.startsWith('/')){
|
|
@@ -53,6 +53,8 @@ export function publishPrdReview({specs,reviewPackage,packageDigest,authorContex
|
|
|
53
53
|
need(gate.package_sha256===packageDigest&&['dispatch_unknown','resume_disposition','completed'].includes(gate.outcome),
|
|
54
54
|
'prd_review_unclaimed');
|
|
55
55
|
const {result,examinedPaths,degraded}=inspectPrdReviewResponse({reviewPackage,packageDigest,authorContextId,response});
|
|
56
|
+
// Preserve legacy rendered labels for exact archive-byte compatibility.
|
|
57
|
+
// Their attestation wording does not prove reviewer identity or execution.
|
|
56
58
|
const bytes=Buffer.from(['---',`at: ${response.at}`,`reviewer: ${response.reviewer}`,`independent: ${response.independent}`,
|
|
57
59
|
...(degraded?[`degraded_reason: ${JSON.stringify(response.degradedReason)}`]:[]),`package_sha256: ${packageDigest}`,
|
|
58
60
|
`verdict: ${result.verdict}`,'scope:',...examinedPaths.map(file=>` - ${file}`),'---','',
|
|
@@ -511,7 +511,7 @@ export function createCmRefactorHost(raw,{call}){
|
|
|
511
511
|
files:changed.map(name=>({path:name,before:context.original[name],after:files[name]})),analysis,retrospective,rulebook,judgeBefore,reports,
|
|
512
512
|
lessons:{path:lessons,before:context.lessons,after:files.__lessons??context.lessons},project,baselineCommands:config.baselineCommands,judgeCommand:config.judgeCommand,
|
|
513
513
|
preTaskDirty:context.baseline.gitState,route:routes.reviewer,
|
|
514
|
-
instructions:'
|
|
514
|
+
instructions:'Use an actual fresh reviewer context without author history per runtime/review.md. Treat reviewer channel and independent as source declarations; validate their format and consistency without treating them as proof of identity or execution. Review ALL diff including tests/Learning/rules/docs/LESSONS and judge coverage. Return {markdown} with original N4 header binding exact handoff SHA, attempt=round, scope, findings. No writes or unapproved provider. Missing channel is blocked, never invent approval.'});
|
|
515
515
|
// The review is validated in full before it becomes immutable evidence, so a
|
|
516
516
|
// reply that fails (missing header, wrong handoff digest, short scope) stays
|
|
517
517
|
// discardable. An already published review is checked as before (old journals).
|
|
@@ -7,13 +7,14 @@
|
|
|
7
7
|
// supported yet: every path exits 2 there (owner/ACL checks of the secret
|
|
8
8
|
// files are not verified on a real Windows machine). Total deadline: 12 s from
|
|
9
9
|
// the moment this script starts executing. A hard timer armed first at entry
|
|
10
|
-
// exits with
|
|
10
|
+
// exits with 5; file reads are asynchronous so that timer can always fire, and the
|
|
11
11
|
// remaining budget is checked before every read, before the request and
|
|
12
12
|
// before every exit 0. This stays inside the plugin's 15 s kill. Secret files are parsed as data
|
|
13
13
|
// (never executed or exported) and their values are never printed or logged.
|
|
14
14
|
// No retry: a timed-out request may already have been delivered.
|
|
15
|
-
// Exit codes: 0 sent; 2 config or secret problem; 3 network failure
|
|
16
|
-
//
|
|
15
|
+
// Exit codes: 0 sent; 2 config or secret problem; 3 network failure;
|
|
16
|
+
// 4 server rejected or odd response; 5 deadline passed; 6 unexpected error.
|
|
17
|
+
// Kept apart so the launcher's notify.log line (exit code only) tells them apart.
|
|
17
18
|
// CM_NOTIFY_DRY_RUN=1: opens no secret file, no network, prints a redacted request.
|
|
18
19
|
// --check: only verifies that the active channel's files parse; sends nothing.
|
|
19
20
|
import fs from 'node:fs';
|
|
@@ -31,7 +32,7 @@ import {fileURLToPath} from 'node:url';
|
|
|
31
32
|
// doing nothing. When run directly the
|
|
32
33
|
// 12 s hard timer is armed next, and on Windows the very next action is the
|
|
33
34
|
// refusal (exit 2), before anything reads a file. The timer is not unref'd:
|
|
34
|
-
// the process ends with
|
|
35
|
+
// the process ends with 5 at the deadline even if some work never settles.
|
|
35
36
|
export const WINDOWS_UNSUPPORTED='/cm:notify 暂不支持 Windows:密钥文件权限核对尚未在 Windows 实机验证';
|
|
36
37
|
export const NODE_UNSUPPORTED='cm-notify: 当前 Node 没有 import.meta.main,不受支持(插件要求 Node 24.14 或更高版本),没有发送';
|
|
37
38
|
export function entryDecision(main,platform){
|
|
@@ -42,13 +43,13 @@ export function entryDecision(main,platform){
|
|
|
42
43
|
const ENTRY_STARTED_AT=performance.now();
|
|
43
44
|
const ENTRY=entryDecision(import.meta.main,process.platform);
|
|
44
45
|
const armHardTimer=(deadlineMs,startedAt)=>setTimeout(()=>{
|
|
45
|
-
try{process.stderr.write(`cm-notify: 整次调用超过 ${Math.ceil(deadlineMs/1000)} 秒,已放弃\n`);}catch{}process.exit(
|
|
46
|
+
try{process.stderr.write(`cm-notify: 整次调用超过 ${Math.ceil(deadlineMs/1000)} 秒,已放弃\n`);}catch{}process.exit(5);
|
|
46
47
|
},Math.max(0,deadlineMs-(performance.now()-startedAt)));
|
|
47
48
|
if(ENTRY==='unsupported_node'){try{process.stderr.write(`${NODE_UNSUPPORTED}\n`);}catch{}process.exit(3);}
|
|
48
49
|
const ENTRY_HARD_TIMER=ENTRY==='run'||ENTRY==='windows'?armHardTimer(12000,ENTRY_STARTED_AT):null;
|
|
49
50
|
if(ENTRY==='windows'){try{process.stderr.write(`cm-notify: ${WINDOWS_UNSUPPORTED}\n`);}catch{}process.exit(2);}
|
|
50
51
|
|
|
51
|
-
export const SEND_EXIT=Object.freeze({ok:0,config:2,network:3,rejected:4});
|
|
52
|
+
export const SEND_EXIT=Object.freeze({ok:0,config:2,network:3,rejected:4,deadline:5,unexpected:6});
|
|
52
53
|
export const DEADLINE_MS=12000;
|
|
53
54
|
const MAX_FILE=64*1024,MAX_RESPONSE=64*1024,MAX_STDIN=64*1024;
|
|
54
55
|
// Largest file the safe read boundary accepts; /cm:notify never writes a bigger notify.json.
|
|
@@ -214,9 +215,9 @@ export function postJson(url,data,{request=https.request,agent,signal}={}){
|
|
|
214
215
|
parts.push(chunk);
|
|
215
216
|
});
|
|
216
217
|
response.on('end',()=>resolve({status:response.statusCode,raw:Buffer.concat(parts)}));
|
|
217
|
-
response.on('error',()=>reject(new SendError(SEND_EXIT.network,'
|
|
218
|
+
response.on('error',()=>reject(new SendError(SEND_EXIT.network,'网络请求失败')));
|
|
218
219
|
});
|
|
219
|
-
req.on('error',()=>reject(new SendError(SEND_EXIT.network,'
|
|
220
|
+
req.on('error',()=>reject(new SendError(SEND_EXIT.network,'网络请求失败')));
|
|
220
221
|
req.end(data);
|
|
221
222
|
});
|
|
222
223
|
}
|
|
@@ -259,7 +260,7 @@ export async function runSender({argv=[],env=process.env,stdin=process.stdin,std
|
|
|
259
260
|
const started=startedAt??clock(),seconds=Math.ceil(deadlineMs/1000);
|
|
260
261
|
const budget=()=>{
|
|
261
262
|
const left=deadlineMs-(clock()-started);
|
|
262
|
-
if(left<=0)throw new SendError(SEND_EXIT.
|
|
263
|
+
if(left<=0)throw new SendError(SEND_EXIT.deadline,`整次调用超过 ${seconds} 秒,已放弃(未发送)`,{deadline:true});
|
|
263
264
|
return left;
|
|
264
265
|
};
|
|
265
266
|
let timer;
|
|
@@ -281,21 +282,21 @@ export async function runSender({argv=[],env=process.env,stdin=process.stdin,std
|
|
|
281
282
|
const code=responseCodeType(raw);
|
|
282
283
|
if(status!==200||!code.ok)throw new SendError(SEND_EXIT.rejected,`推送返回 http=${Number.isSafeInteger(status)?status:'?'} code类型=${code.type}`);
|
|
283
284
|
// Accepted, but too late: report the deadline (it may have been delivered).
|
|
284
|
-
if(deadlineMs-(clock()-started)<=0)throw new SendError(SEND_EXIT.
|
|
285
|
+
if(deadlineMs-(clock()-started)<=0)throw new SendError(SEND_EXIT.deadline,`整次调用超过 ${seconds} 秒,已放弃(可能已送达)`,{deadline:true});
|
|
285
286
|
return SEND_EXIT.ok;
|
|
286
287
|
})();
|
|
287
288
|
try{
|
|
288
289
|
const result=await Promise.race([work.then(code=>({code}),error=>({error})),deadline]);
|
|
289
|
-
if(result==='deadline'){work.catch(()=>{});say(stderr,`cm-notify: 整次调用超过 ${seconds} 秒,已放弃`);return SEND_EXIT.
|
|
290
|
+
if(result==='deadline'){work.catch(()=>{});say(stderr,`cm-notify: 整次调用超过 ${seconds} 秒,已放弃`);return SEND_EXIT.deadline;}
|
|
290
291
|
if(result.error){
|
|
291
292
|
const error=result.error;
|
|
292
293
|
if(error instanceof SendError){
|
|
293
294
|
const prefix=error.exit===SEND_EXIT.config||error.detail.deadline?'':`${channel} `;
|
|
294
295
|
say(stderr,`cm-notify: ${prefix}${error.message}`);return error.exit;
|
|
295
296
|
}
|
|
296
|
-
say(stderr,'cm-notify: 意外错误(详情已隐藏,避免带出密钥)');return SEND_EXIT.
|
|
297
|
+
say(stderr,'cm-notify: 意外错误(详情已隐藏,避免带出密钥)');return SEND_EXIT.unexpected;
|
|
297
298
|
}
|
|
298
|
-
if(result.code===SEND_EXIT.ok&&deadlineMs-(clock()-started)<=0){say(stderr,`cm-notify: 整次调用超过 ${seconds} 秒,已放弃`);return SEND_EXIT.
|
|
299
|
+
if(result.code===SEND_EXIT.ok&&deadlineMs-(clock()-started)<=0){say(stderr,`cm-notify: 整次调用超过 ${seconds} 秒,已放弃`);return SEND_EXIT.deadline;}
|
|
299
300
|
return result.code;
|
|
300
301
|
}finally{clearTimeout(timer);}
|
|
301
302
|
}
|
|
@@ -304,7 +305,7 @@ export async function runSender({argv=[],env=process.env,stdin=process.stdin,std
|
|
|
304
305
|
// entry block above; tests call it with their own start and deadline.
|
|
305
306
|
export function runCli({argv=process.argv.slice(2),deadlineMs=DEADLINE_MS,softDeadlineMs=deadlineMs,startedAt=performance.now(),
|
|
306
307
|
hardTimer=armHardTimer(deadlineMs,startedAt),senderOptions={}}={}){
|
|
307
|
-
const hard=()=>{try{process.stderr.write('cm-notify: 意外错误(详情已隐藏,避免带出密钥)\n');}catch{}process.exit(SEND_EXIT.
|
|
308
|
+
const hard=()=>{try{process.stderr.write('cm-notify: 意外错误(详情已隐藏,避免带出密钥)\n');}catch{}process.exit(SEND_EXIT.unexpected);};
|
|
308
309
|
process.on('uncaughtException',hard);process.on('unhandledRejection',hard);
|
|
309
310
|
return runSender({argv,deadlineMs:softDeadlineMs,startedAt,...senderOptions})
|
|
310
311
|
.then(code=>{clearTimeout(hardTimer);process.exit(code);},hard);
|
package/runtime/js/notify.mjs
CHANGED
|
@@ -17,6 +17,8 @@ export const NOTIFY_LIMITS=Object.freeze({sameKeyMs:6*3600*1000,perMinute:4,perD
|
|
|
17
17
|
commandTimeoutMs:15000,titleChars:60,bodyChars:500,defaultWaitMinutes:10,defaultCheckWaitMinutes:45,
|
|
18
18
|
defaultIdleMinutes:45});
|
|
19
19
|
const LOCK_STALE_MS=30000,LOG_LIMIT=256*1024;
|
|
20
|
+
// Lock and dedup state are tiny JSON files; perDay sends bound the state size.
|
|
21
|
+
const CONTROL_FILE_LIMIT=256*1024;
|
|
20
22
|
const RUNNER=fileURLToPath(new URL('./notify-run.mjs',import.meta.url));
|
|
21
23
|
|
|
22
24
|
export function notifyHome(env=process.env){
|
|
@@ -196,7 +198,28 @@ const keyHash=key=>createHash('sha256').update(key).digest('hex').slice(0,16);
|
|
|
196
198
|
// older than 30 s; the critical section takes milliseconds) is reclaimed only
|
|
197
199
|
// by renaming it to a unique name and confirming it is byte-identical to the
|
|
198
200
|
// stale lock that was judged; anything else is put back and the notice skipped.
|
|
199
|
-
|
|
201
|
+
// Bounded read of a control file we may not own. lstat first: a symlink (even a
|
|
202
|
+
// dangling one, and even where O_NOFOLLOW is 0 as on Windows), a non-regular
|
|
203
|
+
// file or an oversized file never counts as readable. The descriptor is opened
|
|
204
|
+
// without following links and without blocking (a FIFO cannot stall the host),
|
|
205
|
+
// and must be the same inode lstat saw. Returns {missing:true} only for ENOENT;
|
|
206
|
+
// every other trouble returns null, which skips the notice.
|
|
207
|
+
function readBounded(file,limit){
|
|
208
|
+
let before;
|
|
209
|
+
try{before=fs.lstatSync(file);}catch(error){return error.code==='ENOENT'?{missing:true}:null;}
|
|
210
|
+
if(before.isSymbolicLink()||!before.isFile()||before.size>limit)return null;
|
|
211
|
+
let descriptor=null;
|
|
212
|
+
try{
|
|
213
|
+
descriptor=fs.openSync(file,fs.constants.O_RDONLY|fs.constants.O_NOFOLLOW|fs.constants.O_NONBLOCK);
|
|
214
|
+
const info=fs.fstatSync(descriptor);
|
|
215
|
+
if(!info.isFile()||info.size>limit||info.dev!==before.dev||info.ino!==before.ino)return null;
|
|
216
|
+
const buffer=Buffer.alloc(info.size);
|
|
217
|
+
let offset=0;while(offset<info.size){const n=fs.readSync(descriptor,buffer,offset,info.size-offset,offset);if(n===0)break;offset+=n;}
|
|
218
|
+
return {text:buffer.subarray(0,offset).toString('utf8')};
|
|
219
|
+
}catch{return null;}
|
|
220
|
+
finally{if(descriptor!==null)try{fs.closeSync(descriptor);}catch{}}
|
|
221
|
+
}
|
|
222
|
+
function readLock(file){const read=readBounded(file,CONTROL_FILE_LIMIT);return read===null||read.missing?null:read.text;}
|
|
200
223
|
function stale(raw){
|
|
201
224
|
let value;try{value=JSON.parse(raw);}catch{return false;}
|
|
202
225
|
if(!Number.isSafeInteger(value?.pid)||!Number.isFinite(value?.at))return false;
|
|
@@ -230,8 +253,8 @@ function reserve(home,hash,now){
|
|
|
230
253
|
const lock=takeLock(lockFile);if(lock===null)return 'state_busy';
|
|
231
254
|
try{
|
|
232
255
|
let state={version:1,keys:{},sends:[]};
|
|
233
|
-
|
|
234
|
-
|
|
256
|
+
const read=readBounded(stateFile,CONTROL_FILE_LIMIT);if(read===null)return 'state_invalid';
|
|
257
|
+
if(!read.missing){try{state=JSON.parse(read.text);}catch{return 'state_invalid';}}
|
|
235
258
|
if(!state||state.version!==1||!state.keys||typeof state.keys!=='object'||Array.isArray(state.keys)
|
|
236
259
|
||!Array.isArray(state.sends)||!state.sends.every(Number.isFinite)
|
|
237
260
|
||!Object.values(state.keys).every(Number.isFinite))return 'state_invalid';
|
|
@@ -381,7 +404,7 @@ const AI_PROGRESS_CODES=new Set(['context_refreshed','context_complete','qa_skip
|
|
|
381
404
|
const AI_STUCK_STATES=new Set(['blocked','unknown','pending_review','cancelled','awaiting_spec_approval']);
|
|
382
405
|
const AI_STUCK_ACTIONS=new Set(['reconcile','abandon_effect','abandon_review','reconcile_review','bootstrap_review_recover',
|
|
383
406
|
'review_evidence','spec_rebind','fix_authorization','fix_dispatch','qa_execution']);
|
|
384
|
-
const AI_STUCK_CODES=new Set(['
|
|
407
|
+
const AI_STUCK_CODES=new Set(['permission_denied','provider_development_authorization_required',
|
|
385
408
|
'qa_decision_required','qa_mandatory_required','qa_triggered','qa_blocked','qa_failed','qa_result_blocked',
|
|
386
409
|
'qa_execution_unknown','correction_review_required','project_qa_not_passed','documentation_sync_blocked',
|
|
387
410
|
'handoff_exists','spec_drift','qa_fix_code_unmatched',
|
|
@@ -34,7 +34,8 @@ export const LEGACY_TEST_POLICIES=Object.freeze([Object.freeze({since:'0b3040e',
|
|
|
34
34
|
// Known versions of the changed documents that may continue a legacy binding.
|
|
35
35
|
export const POLICY_DOC_SUCCESSORS=Object.freeze({
|
|
36
36
|
'skills/cm-init/references/js-host.md':Object.freeze(['d3d6ad0b02ee7d3863302c49a9434b1a9f423e8ab4ff332cd9ad077a0b270fb1',
|
|
37
|
-
'223dd3a4a4172591480bff818bc81216d5554ea1c7c7785619ccab33ee3fd833'
|
|
37
|
+
'223dd3a4a4172591480bff818bc81216d5554ea1c7c7785619ccab33ee3fd833',
|
|
38
|
+
'b218527db47bfa2c995173a0d80e3927e1bb8946c397a2945c3c09e73639af59']),
|
|
38
39
|
'skills/cm-test/references/js-host.md':Object.freeze(['0a6023c9036693a93a17650872b634b33d68eecc2fbece188519e94e31452e8c']),
|
|
39
40
|
});
|
|
40
41
|
// cm-init: files is the current [[relativePath, content|null], ...] policy list.
|
package/runtime/review.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Every implementation task requires an independent review before it can be marked complete. The reviewer must not inherit the author's reasoning narrative.
|
|
4
4
|
|
|
5
|
+
CM 门禁检查来源声明的格式、任务与轮次、材料摘要、当前文件和执行记录的一致性,用于防手滑与过期证据。来源声明不验证审查者身份或实际人工交互;门禁不承诺抵抗拥有完整文件写权限和 shell 能力的会话造假。fresh 上下文、审查结果、检查通过和完成复查仍是正常工作流路径的完成条件。发布、部署、资金及其他范围外动作继续遵守其单独确认要求。
|
|
6
|
+
|
|
5
7
|
N4 accepts only a `ready_for_review` implementation handoff validated through
|
|
6
8
|
`runtime/task-gates.md`. The handoff is author evidence, never an approval. The
|
|
7
9
|
review file owns the disposition that controls whether N3 retries or N5 may mark
|
|
@@ -62,10 +64,18 @@ to erase a valid blocking finding.
|
|
|
62
64
|
|
|
63
65
|
The shared-JS target supports a fresh reviewer on whichever provider is available.
|
|
64
66
|
The shared V3 runner now also accepts Claude-bound normalized review invocations,
|
|
65
|
-
using the same
|
|
67
|
+
using the same request/package binding, registration, reviewer source declarations, replay and completion checks.
|
|
68
|
+
cm-ai uses the `host-review` source channel; cm-fix retains its existing
|
|
69
|
+
`host-authorized` contract. A cm-ai journal with old grant-channel invocations is
|
|
70
|
+
rejected as `runner_invocation`; preserve it and use the original version's
|
|
71
|
+
read-only tools to inspect history. This entry does not replay or migrate those
|
|
72
|
+
invocations.
|
|
66
73
|
Its registered result is published as `claude-cli`, never relabeled as Codex.
|
|
67
74
|
The single-task host connects the Claude worker only with a matching diagnostic and
|
|
68
|
-
|
|
75
|
+
the active control contract: cm-ai advances ordinary review rounds directly within
|
|
76
|
+
the confirmed scope, for both existing and new runs. Requests and receipts bind
|
|
77
|
+
the actual invocation, package and execution records to detect stale or mismatched
|
|
78
|
+
materials. Claude preflight uses a macOS loopback-only sandbox,
|
|
69
79
|
synthetic credentials and a rejecting local sink; it does not obtain a model review.
|
|
70
80
|
The producer permits one empty startup health probe and rejects model requests locally.
|
|
71
81
|
Installed CLI has passed this local request-surface probe. It uses the same bounded temporary
|
|
@@ -105,10 +115,46 @@ PRD artifact 回执先比对原始字节,仅 Markdown 中 `tasks.md` 的任务
|
|
|
105
115
|
proceed only when the reviewer records `approved` and the disagreement is
|
|
106
116
|
preserved in `LESSONS.md`.
|
|
107
117
|
|
|
108
|
-
A concrete
|
|
118
|
+
A concrete local correction after the user confirms its scope may use the
|
|
109
119
|
one-shot task-gate entrance in `docs/human-correction.md`. It preserves the original
|
|
110
|
-
reports,
|
|
111
|
-
|
|
120
|
+
reports, records the correction reason and bound source declaration, seals a fresh
|
|
121
|
+
independent correction review, and does not reopen a host journal or reset ordinary
|
|
122
|
+
attempts. The record reports the supplied decision source; it does not create approval.
|
|
123
|
+
|
|
124
|
+
A separate version-two taskgate protocol, `cm-controlled-correction`, is one-shot
|
|
125
|
+
(`version:2`, `continuation:1`), described in `docs/cm-control-policy-v2.md`.
|
|
126
|
+
It supports only compatibility taskgate tasks without JS ownership. A retained
|
|
127
|
+
JS journal, JS run or unknown ownership evidence blocks the compatibility writer
|
|
128
|
+
and must be rejected before correction preparation. Do not delete that evidence
|
|
129
|
+
or hand-edit ownership to enter this protocol. It
|
|
130
|
+
records the concrete correction decision as provenance-only `operator` or `model`,
|
|
131
|
+
without claiming human authentication or approval. It keeps the original blocked
|
|
132
|
+
round-two report and every blocking finding, including P2, as immutable history.
|
|
133
|
+
Finalize the actual in-scope revision, relevant checks and Learning/handoff first;
|
|
134
|
+
then review the complete revised package through a fresh independent channel.
|
|
135
|
+
Only approved, zero-blocking evidence bound to the correction record, final
|
|
136
|
+
handoff and current implementation can enter the existing N4/N5 completion gate.
|
|
137
|
+
Its v2 correction review body is strict raw JSON with exactly `conclusion`,
|
|
138
|
+
`findings`, and `resolved_findings`. Each finding has exactly `id`, `priority`
|
|
139
|
+
(P0-P3), and nonempty `evidence`; ids are unique across both arrays. Active
|
|
140
|
+
`findings.length` equals the header's `blocking_findings`. Approved requires
|
|
141
|
+
`conclusion: "Zero findings."` and an empty active findings array; other verdicts
|
|
142
|
+
require `"Blocking findings."`. Fixed historical P2 belongs only in
|
|
143
|
+
`resolved_findings`. A zero-findings phrase cannot hide a remaining P2, extra prose
|
|
144
|
+
or a mismatched count. This structured-body rule does not change legacy human
|
|
145
|
+
correction review bodies.
|
|
146
|
+
This slice connects only owner-free compatibility taskgate correction evidence
|
|
147
|
+
and the exact task checkbox. cm-ai v2 single-task and batch round-two runs remain
|
|
148
|
+
formally blocked; no runner-owned correction completion entrance exists. Even
|
|
149
|
+
prepared/published taskgate evidence cannot complete a JS-owned run. No original
|
|
150
|
+
batch restoration, N6/N7/N8 advance or `run_done` follows this compatibility
|
|
151
|
+
protocol. Do not hand-edit journal or batch state to claim workflow completion.
|
|
152
|
+
It is not attempt 3, does not reset a host journal, and cannot coexist with the
|
|
153
|
+
legacy human continuation. Source labels, model output and V3 grants do not expand
|
|
154
|
+
real conversation authorization, code scope, external sends, Git/push, publication,
|
|
155
|
+
deployment or financial permissions. Safety/data-correctness disputes that need
|
|
156
|
+
a human decision still require that decision; unavailable review capacity remains
|
|
157
|
+
pending, never self-approved.
|
|
112
158
|
|
|
113
159
|
At any stage, changing reviewed code, tests, or execution instructions invalidates
|
|
114
160
|
approval for the changed content. N5 may record improvement suggestions, not make
|
|
@@ -145,8 +191,7 @@ verdict 至少为 1。`self-degraded` 必须写 `independent: false` 并增加
|
|
|
145
191
|
`--project-root` 复算;否则文件内容在审查后变化时无法进入 N5。历史恢复显式使用
|
|
146
192
|
`--allow-legacy-unbound` 时不属于内容绑定审查,必须在证据中披露。
|
|
147
193
|
历史 `self-degraded` 可读取和审计,但不得据此授权新完成或补造独立审查。
|
|
148
|
-
|
|
149
|
-
核对真实通道、任务增量及验证证据,不把当前声明门禁当成完整执行凭据机制。
|
|
194
|
+
`reviewer` 与 `independent` 是审查来源声明;`decision_source` 若由相应入口记录,也仅表示决定来源。字段和摘要用于核对本轮材料与执行记录的一致性。主执行者仍按正常工作流取得 fresh 审查、核对任务增量及验证证据。
|
|
150
195
|
|
|
151
196
|
No matching evidence file means review did not happen. File existence alone is
|
|
152
197
|
not approval: the completion node must run the `cm-task-gate.py mark-done` lock
|