@aibyzero/cm-workflow 0.17.0 → 0.17.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.codex-plugin/plugin.json +1 -1
- package/AGENTS.md +4 -0
- package/CHANGELOG.md +6 -1
- package/CONTRIBUTING.md +47 -0
- package/README.md +8 -1
- package/VERSION +1 -1
- package/docs/architecture.md +29 -13
- package/docs/fixes/20261013-claude-preinit-ui-invalidate.md +48 -0
- package/docs/installation.md +1 -1
- package/docs/js-workflow-control.md +3 -1
- package/package.json +1 -1
- package/runtime/js/cm-ai/claude-review-stream.mjs +12 -8
- package/runtime/js/cm-ai/control-policy.mjs +3 -2
- package/runtime/js/cm-ai/drive-core.mjs +124 -25
- package/runtime/js/cm-ai/host-check.mjs +3 -1
- package/runtime/js/cm-ai/host-session.mjs +41 -8
- package/runtime/js/cm-ai/host-stage-observer.mjs +26 -0
- package/runtime/js/cm-ai/host-tool-bridge.mjs +22 -9
- package/runtime/js/cm-ai/operator-guidance.mjs +56 -30
- package/runtime/js/cm-ai/task-runner.mjs +5 -2
- package/runtime/js/cm-prd/summary.mjs +27 -12
- package/runtime/review.md +9 -0
- package/scripts/cm-ai-batch-host.test.mjs +21 -9
- package/scripts/cm-ai-batch-run.mjs +12 -6
- package/scripts/cm-ai-control-policy.test.mjs +68 -0
- package/scripts/cm-ai-drive-bootstrap-rules.test.mjs +3 -2
- package/scripts/cm-ai-drive.test.mjs +3 -3
- package/scripts/cm-ai-host-fixture.mjs +9 -6
- package/scripts/cm-ai-host-protected.test.mjs +1 -1
- package/scripts/cm-ai-host.test.mjs +15 -0
- package/scripts/cm-ai-operator-guidance.test.mjs +56 -0
- package/scripts/cm-ai-review-timeout.test.mjs +20 -0
- package/scripts/cm-check-drive-files.mjs +1 -1
- package/scripts/cm-check-host.test.mjs +1 -1
- package/scripts/cm-claude-probe.test.mjs +26 -0
- package/scripts/cm-claude-review-stream.test.mjs +36 -0
- package/scripts/cm-claude-worker.test.mjs +16 -0
- package/scripts/cm-drive-liveness.test.mjs +83 -0
- package/scripts/cm-external-batch-host.test.mjs +8 -6
- package/scripts/cm-host-diagnostic.test.mjs +33 -0
- package/scripts/cm-host-liveness.test.mjs +150 -0
- package/scripts/cm-host-stage-observer.test.mjs +41 -0
- package/scripts/cm-notify.test.mjs +50 -16
- package/scripts/cm-prd-drive.test.mjs +1 -1
- package/scripts/cm-prd-self-check-revision.test.mjs +15 -0
- package/scripts/cm-prd-session-recovery.test.mjs +5 -3
- package/scripts/cm-prd-summary.test.mjs +31 -0
- package/scripts/cm-release-smoke.sh +2 -14
- package/scripts/cm-test-suite.mjs +109 -0
- package/scripts/cm-test-suite.test.mjs +162 -0
- package/scripts/fixtures/host-diagnostic.mjs +33 -0
- package/skills/cm-ai/references/js-host.md +33 -1
|
@@ -3,6 +3,7 @@ import {randomUUID} from 'node:crypto';
|
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import {executionDiagnostic,need} from './effect-contract.mjs';
|
|
5
5
|
import {diagnosticReason} from './diagnostic-reason.mjs';
|
|
6
|
+
import {withHostStageObserver} from './host-stage-observer.mjs';
|
|
6
7
|
|
|
7
8
|
const LIMIT=64*1024;
|
|
8
9
|
// One wording for every host that stops on an over-limit line.
|
|
@@ -53,11 +54,18 @@ function idleNotice(sessionKey,seq,row,since){
|
|
|
53
54
|
// A line above the transport limit ends the session. Carry a code and the
|
|
54
55
|
// limit so every host can name it instead of a generic launch failure.
|
|
55
56
|
const tooLarge=limit=>Object.assign(new Error('request_too_large'),{code:'request_too_large',limit});
|
|
56
|
-
export async function serveCmAiHost({host,input,output,toolBridge=null,inputLimit=LIMIT,errorOutput=process.stderr}){
|
|
57
|
+
export async function serveCmAiHost({host,input,output,toolBridge=null,inputLimit=LIMIT,errorOutput=process.stderr,heartbeat=process.env.CM_HOST_HEARTBEAT==='1'}){
|
|
57
58
|
if(!Number.isSafeInteger(inputLimit)||inputLimit<LIMIT||inputLimit>4*1024*1024)throw Error('input_limit_invalid');
|
|
58
59
|
let pending=null,buffer=Buffer.alloc(0),failure=null,closeRequested=false;
|
|
59
60
|
let writing=Promise.resolve();
|
|
60
|
-
const controls=new Set();let queuedWrites=0;
|
|
61
|
+
const controls=new Set(),activeControls=new Map();let queuedWrites=0,activeOperation=null;
|
|
62
|
+
let progressAt=Date.now(),heartbeatTimer=null,heartbeatWriting=false;
|
|
63
|
+
const inFlight=()=>{
|
|
64
|
+
const operation=activeOperation??activeControls.values().next().value??null;
|
|
65
|
+
const call=toolBridge?.inFlight?.()??null;
|
|
66
|
+
return operation?{...operation,stage:call?.kind??operation.nativeStage?.kind??operation.operation,call}:
|
|
67
|
+
call?{requestId:null,operation:null,startedAt:call.startedAt,stage:call.kind,call}:null;
|
|
68
|
+
};
|
|
61
69
|
const sessionKey=randomUUID(),startedAt=Date.now();let idle=null,seq=0,ended=false,lastRow=undefined,idleSince=0;
|
|
62
70
|
// Host registry (runtime/js/notify.mjs): serialised so a session that ends at
|
|
63
71
|
// once still removes its own entry. Each step is best-effort and synchronous.
|
|
@@ -93,7 +101,21 @@ export async function serveCmAiHost({host,input,output,toolBridge=null,inputLimi
|
|
|
93
101
|
writing.catch(error=>{failure=error;});
|
|
94
102
|
return writing;
|
|
95
103
|
};
|
|
96
|
-
toolBridge?.attach(reply);
|
|
104
|
+
toolBridge?.attach(reply,{heartbeat});
|
|
105
|
+
// Opt-in transport telemetry: no runner reads, journal writes or fingerprint changes.
|
|
106
|
+
// Keep at most one heartbeat queued so a slow peer cannot accumulate timer output.
|
|
107
|
+
if(heartbeat&&toolBridge){
|
|
108
|
+
const beat=()=>{
|
|
109
|
+
if(ended||failure||closeRequested||heartbeatWriting||queuedWrites>0)return;
|
|
110
|
+
heartbeatWriting=true;
|
|
111
|
+
reply({type:'host_heartbeat',sessionId:toolBridge.sessionId,pid:process.pid,at:new Date().toISOString(),
|
|
112
|
+
lastProgressAt:new Date(Math.max(progressAt,toolBridge.lastProgressAt?.()??0)).toISOString(),inFlight:inFlight()})
|
|
113
|
+
.catch(error=>{failure=error;}).finally(()=>{heartbeatWriting=false;});
|
|
114
|
+
};
|
|
115
|
+
// ready is already queued; send the first beat immediately after that write.
|
|
116
|
+
writing.then(beat).catch(()=>{});
|
|
117
|
+
heartbeatTimer=setInterval(beat,5000);heartbeatTimer.unref?.();
|
|
118
|
+
}
|
|
97
119
|
async function dispatch(bytes){
|
|
98
120
|
if(failure)throw failure;
|
|
99
121
|
let request;
|
|
@@ -101,7 +123,7 @@ export async function serveCmAiHost({host,input,output,toolBridge=null,inputLimi
|
|
|
101
123
|
request=JSON.parse(bytes.toString('utf8'));
|
|
102
124
|
if(POLLS.has(request?.operation))clearIdle();else nextStep();
|
|
103
125
|
if(toolBridge!==null&&['host_result','host_close'].includes(request?.type)){
|
|
104
|
-
const accepted=toolBridge.accept(request);closeRequested=accepted.closing===true;
|
|
126
|
+
const accepted=toolBridge.accept(request,{inFlight:inFlight()});closeRequested=accepted.closing===true;
|
|
105
127
|
reply({type:'host_response',...accepted}).catch(error=>{failure=error;});return;
|
|
106
128
|
}
|
|
107
129
|
if(!request||typeof request!=='object'||Array.isArray(request)
|
|
@@ -110,11 +132,20 @@ export async function serveCmAiHost({host,input,output,toolBridge=null,inputLimi
|
|
|
110
132
|
}catch{nextStep();reply({requestId:null,error:{code:'invalid_request'}}).catch(error=>{failure=error;});return;}
|
|
111
133
|
const requestId=request.requestId;
|
|
112
134
|
let row=null;
|
|
135
|
+
let operationActive=false,metadata=null;
|
|
136
|
+
const release=()=>{if(!operationActive)return;operationActive=false;
|
|
137
|
+
if(activeOperation===metadata)activeOperation=null;
|
|
138
|
+
activeControls.delete(request);if(!POLLS.has(request.operation))progressAt=Date.now();};
|
|
139
|
+
const begin=control=>{operationActive=true;const at=Date.now();if(!POLLS.has(request.operation))progressAt=at;
|
|
140
|
+
metadata={requestId,operation:request.operation,startedAt:new Date(at).toISOString(),nativeStage:null};
|
|
141
|
+
if(control)activeControls.set(request,metadata);else activeOperation=metadata;};
|
|
113
142
|
const invoke=async()=>{
|
|
114
|
-
try{const result=await
|
|
143
|
+
try{const result=await withHostStageObserver(stage=>{
|
|
144
|
+
if(operationActive){metadata.nativeStage=stage;if(!POLLS.has(request.operation))progressAt=Date.now();}
|
|
145
|
+
},()=>host.handle(request));row={result};release();await reply({requestId,result});}
|
|
115
146
|
catch(error){
|
|
116
147
|
reportRequestFailure(errorOutput,request.operation,error);
|
|
117
|
-
row={error:{code:'host_request_failed'}};
|
|
148
|
+
row={error:{code:'host_request_failed'}};release();
|
|
118
149
|
await reply({requestId,...row});
|
|
119
150
|
}
|
|
120
151
|
finally{if(!POLLS.has(request.operation))register(row,request.operation);}
|
|
@@ -123,10 +154,12 @@ export async function serveCmAiHost({host,input,output,toolBridge=null,inputLimi
|
|
|
123
154
|
if(request.operation==='status'||request.operation==='cancel'){
|
|
124
155
|
// The input reader must not wait for a slow response consumer before it
|
|
125
156
|
// can deliver the next control request (especially cancellation).
|
|
157
|
+
begin(true);
|
|
126
158
|
const control=invoke().finally(()=>{controls.delete(control);finished(row,request.operation);});
|
|
127
159
|
controls.add(control);control.catch(error=>{failure=error;});return;
|
|
128
160
|
}
|
|
129
|
-
if(pending){reply({requestId,error:{code:'host_busy'}}).catch(error=>{failure=error;});return;}
|
|
161
|
+
if(pending){reply({requestId,error:{code:'host_busy',inFlight:inFlight(),message:'上一步仍在执行,请继续等待该请求的结果。'}}).catch(error=>{failure=error;});return;}
|
|
162
|
+
begin(false);
|
|
130
163
|
pending=invoke().finally(()=>{pending=null;finished(row,request.operation);});
|
|
131
164
|
pending.catch(error=>{failure=error;});
|
|
132
165
|
}
|
|
@@ -150,7 +183,7 @@ export async function serveCmAiHost({host,input,output,toolBridge=null,inputLimi
|
|
|
150
183
|
}finally{
|
|
151
184
|
// With a duplex conversation, EOF means no more tool replies can arrive.
|
|
152
185
|
// Reject that wait as disconnected, not as an explicit user cancellation.
|
|
153
|
-
toolBridge?.close();ended=true;clearIdle();
|
|
186
|
+
toolBridge?.close();ended=true;clearInterval(heartbeatTimer);clearIdle();
|
|
154
187
|
// EOF is not a user cancellation. Finish the in-flight result before close.
|
|
155
188
|
try{await Promise.allSettled([...(pending?[pending]:[]),...controls,writing]);}
|
|
156
189
|
finally{
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Process-local transport telemetry only. No durable state, authority or timers.
|
|
2
|
+
import {AsyncLocalStorage} from 'node:async_hooks';
|
|
3
|
+
import {randomUUID} from 'node:crypto';
|
|
4
|
+
|
|
5
|
+
const operations=new AsyncLocalStorage();
|
|
6
|
+
const emit=context=>{
|
|
7
|
+
if(context.closed)return;
|
|
8
|
+
const stages=[...context.stages.values()],latest=stages.at(-1);
|
|
9
|
+
const snapshot=latest?Object.freeze({...latest,deadlineMs:Math.min(...stages.map(stage=>stage.deadlineMs))}):null;
|
|
10
|
+
try{context.observer(snapshot);}catch{/* diagnostic observers cannot change execution */}
|
|
11
|
+
};
|
|
12
|
+
export async function withHostStageObserver(observer,run){
|
|
13
|
+
const context={observer,stages:new Map(),closed:false};
|
|
14
|
+
return operations.run(context,async()=>{
|
|
15
|
+
try{return await run();}
|
|
16
|
+
finally{context.stages.clear();emit(context);context.closed=true;}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
export function beginHostStage(kind,timeoutMs){
|
|
20
|
+
const context=operations.getStore();
|
|
21
|
+
if(!context||context.closed||!Number.isSafeInteger(timeoutMs)||timeoutMs<1)return ()=>{};
|
|
22
|
+
const now=Date.now(),id=randomUUID();
|
|
23
|
+
context.stages.set(id,{id,kind,startedAt:new Date(now).toISOString(),deadlineMs:now+timeoutMs});emit(context);
|
|
24
|
+
let ended=false;
|
|
25
|
+
return ()=>{if(ended||context.closed)return;ended=true;context.stages.delete(id);emit(context);};
|
|
26
|
+
}
|
|
@@ -48,19 +48,25 @@ const lateDiagnostic=fields=>{try{process.stderr.write(JSON.stringify({diagnosti
|
|
|
48
48
|
export function createHostToolBridge({responseLimit=64*1024,answerTimeoutMs=hostAnswerTimeoutMs()}={}){
|
|
49
49
|
need(Number.isSafeInteger(responseLimit)&&responseLimit>=64*1024&&responseLimit<=4*1024*1024,'host_response_limit_invalid');
|
|
50
50
|
need(Number.isSafeInteger(answerTimeoutMs)&&answerTimeoutMs>=1000&&answerTimeoutMs<=HOST_ANSWER_BACKSTOP_MS,'host_answer_timeout_invalid');
|
|
51
|
-
const sessionId=randomUUID();let send=null,pending=null,closed=false;
|
|
51
|
+
const sessionId=randomUUID();let send=null,pending=null,closed=false,lastProgressAt=Date.now();
|
|
52
|
+
// Metadata only: never expose the request payload or answer through liveness.
|
|
53
|
+
const inFlight=()=>pending?{callId:pending.request.callId,kind:pending.request.kind,
|
|
54
|
+
startedAt:new Date(pending.startedAt).toISOString(),deadlineMs:pending.deadlineMs}:null;
|
|
52
55
|
const stopped=new Map();
|
|
53
56
|
const stop=(code,call=pending)=>{
|
|
54
|
-
if(!call||pending!==call)return;pending=null;clearTimeout(call.timer);call.notice?.();
|
|
57
|
+
if(!call||pending!==call)return;pending=null;lastProgressAt=Date.now();clearTimeout(call.timer);call.notice?.();
|
|
55
58
|
call.signal.removeEventListener('abort',call.abort);
|
|
56
59
|
if(code!=='host_disconnected'){stopped.set(call.request.callId,{kind:call.request.kind,stoppedBy:code});
|
|
57
60
|
if(stopped.size>LATE_CALLS)stopped.delete(stopped.keys().next().value);}
|
|
58
61
|
call.reject(Object.assign(new Error(code),{code}));
|
|
59
62
|
};
|
|
60
63
|
return Object.freeze({
|
|
61
|
-
|
|
64
|
+
sessionId,
|
|
65
|
+
inFlight,
|
|
66
|
+
lastProgressAt:()=>lastProgressAt,
|
|
67
|
+
attach(sender,{heartbeat=false}={}){
|
|
62
68
|
need(send===null&&typeof sender==='function'&&!closed,'host_bridge_unavailable');send=sender;
|
|
63
|
-
Promise.resolve(send({type:'host_ready',sessionId})).catch(()=>{closed=true;stop('host_disconnected');});
|
|
69
|
+
Promise.resolve(send({type:'host_ready',sessionId,...(heartbeat?{heartbeat:{intervalMs:5000,timeoutMs:30000}}:{})})).catch(()=>{closed=true;stop('host_disconnected');});
|
|
64
70
|
},
|
|
65
71
|
call(kind,payload,signal,{timeoutMs=null}={}){
|
|
66
72
|
need(send!==null&&!closed,'host_bridge_unavailable');need(pending===null,'host_bridge_busy');
|
|
@@ -73,7 +79,9 @@ export function createHostToolBridge({responseLimit=64*1024,answerTimeoutMs=host
|
|
|
73
79
|
stop('cancelled',call);
|
|
74
80
|
Promise.resolve(send({type:'host_call_cancelled',sessionId,callId:request.callId})).catch(()=>{});
|
|
75
81
|
};
|
|
76
|
-
const
|
|
82
|
+
const startedAt=Date.now(),duration=timeoutMs??(COMMAND_KINDS.has(kind)?Math.max(answerTimeoutMs,HOST_ANSWER_TIMEOUT_MAX_MS):answerTimeoutMs);
|
|
83
|
+
const call={request,signal,abort,resolve,reject,startedAt,deadlineMs:startedAt+duration,timer:null,notice:waitNotice(kind,request.callId)};
|
|
84
|
+
pending=call;lastProgressAt=startedAt;
|
|
77
85
|
if(timeoutMs!==null)call.timer=setTimeout(()=>stop('host_request_timeout',call),timeoutMs);
|
|
78
86
|
// The default deadline never keeps an otherwise finished process alive.
|
|
79
87
|
else {call.timer=setTimeout(()=>stop('host_request_timeout',call),
|
|
@@ -85,12 +93,17 @@ export function createHostToolBridge({responseLimit=64*1024,answerTimeoutMs=host
|
|
|
85
93
|
}).catch(()=>stop('host_disconnected',call));
|
|
86
94
|
});
|
|
87
95
|
},
|
|
88
|
-
accept(raw){
|
|
96
|
+
accept(raw,{inFlight:operation=null}={}){
|
|
89
97
|
let reply;
|
|
90
98
|
try{
|
|
91
99
|
if(raw?.type==='host_close'){
|
|
92
|
-
shape(raw,['type','sessionId']);need(raw.sessionId===sessionId&&!closed,'host_response_mismatch');
|
|
93
|
-
|
|
100
|
+
shape(raw,['type','sessionId',...(Object.hasOwn(raw,'force')?['force']:[])]);need(raw.sessionId===sessionId&&!closed,'host_response_mismatch');
|
|
101
|
+
need(raw.force===undefined||typeof raw.force==='boolean','host_response_mismatch');
|
|
102
|
+
const active=operation??(pending?{requestId:null,operation:null,startedAt:inFlight().startedAt,stage:pending.request.kind,call:inFlight()}:null);
|
|
103
|
+
if(active&&raw.force!==true)return {accepted:false,code:'host_close_busy',inFlight:active,
|
|
104
|
+
message:'上一步仍在执行,请继续等待其结果;只有明确放弃本次在途工作时才传 force:true。'};
|
|
105
|
+
closed=true;stop('host_disconnected');return {accepted:true,closing:true,...(active?{
|
|
106
|
+
warning:'已强制关闭在途工作,原运行可能进入 unknown;请核对原运行状态后恢复。',inFlight:active}:{})};
|
|
94
107
|
}
|
|
95
108
|
reply=json(raw,responseLimit);shape(reply,['type','sessionId','callId','requestDigest','result']);
|
|
96
109
|
const late=reply.type==='host_result'&&reply.sessionId===sessionId&&pending?.request.callId!==reply.callId
|
|
@@ -100,7 +113,7 @@ export function createHostToolBridge({responseLimit=64*1024,answerTimeoutMs=host
|
|
|
100
113
|
need(reply.type==='host_result'&&pending!==null&&!closed,'host_response_mismatch');
|
|
101
114
|
for(const key of ['sessionId','callId','requestDigest'])need(reply[key]===pending.request[key],'host_response_mismatch');
|
|
102
115
|
}catch(error){return {accepted:false,code:error?.code==='limit_exceeded'?'host_response_too_large':'host_response_mismatch'};}
|
|
103
|
-
const call=pending;pending=null;clearTimeout(call.timer);call.notice?.();call.signal.removeEventListener('abort',call.abort);
|
|
116
|
+
const call=pending;pending=null;lastProgressAt=Date.now();clearTimeout(call.timer);call.notice?.();call.signal.removeEventListener('abort',call.abort);
|
|
104
117
|
call.resolve(reply.result);return {accepted:true,callId:reply.callId};
|
|
105
118
|
},
|
|
106
119
|
close(){closed=true;stop('host_disconnected');},
|
|
@@ -26,18 +26,40 @@ const documentationMessages={
|
|
|
26
26
|
const explain=(summary,nextStep,operation=null,prerequisites=[])=>Object.freeze({
|
|
27
27
|
summary,nextStep,recoveryOperation:operation,prerequisites:Object.freeze(prerequisites),authorizationGranted:false,
|
|
28
28
|
});
|
|
29
|
-
|
|
29
|
+
// Rendering context is private and ephemeral; it never enters results or journals.
|
|
30
|
+
const guidanceContext=new WeakMap();
|
|
31
|
+
export function operatorGuidance(result,options={}){
|
|
32
|
+
const guidance=renderOperatorGuidance(result,options);
|
|
33
|
+
if(guidance)guidanceContext.set(guidance,{executionActive:options.executionActive===true,protocol:options.protocol??'legacy'});
|
|
34
|
+
return guidance;
|
|
35
|
+
}
|
|
36
|
+
export function projectOperatorGuidance(result,options={}){
|
|
37
|
+
if(!result?.guidance)return result;
|
|
38
|
+
const context=guidanceContext.get(result.guidance);
|
|
39
|
+
if(!context)return result;
|
|
40
|
+
const guidance=operatorGuidance(result,{...context,...options});
|
|
41
|
+
return guidance?{...result,guidance}:result;
|
|
42
|
+
}
|
|
43
|
+
const fixedTarget='先只读 status,展示并核对 controlTarget 与恢复动作,按当前对话的具体决定完整固定为 expectedControl;发送 version:2 和单行 reason;snapshot_changed 时停止,不自动刷新目标重试';
|
|
44
|
+
function renderOperatorGuidance(result,{executionActive=false,protocol='legacy',surface='single'}={}){
|
|
45
|
+
const v2=protocol==='v2',batch=surface==='batch';
|
|
46
|
+
const resume=batch?'从原批次入口发送 advance':'恢复原运行并发送 advance';
|
|
47
|
+
const permission=flag=>v2?fixedTarget:`显式 ${flag},并提供单行 reason`;
|
|
48
|
+
const supersede=v2?'当前 v2 没有作废旧证据并新建运行的出口;保留原运行、文件与证据,核对 reason 后交由维护者处理,不改走旧入口。'
|
|
49
|
+
:'修好后按 reason 用 --supersede-reviewed-evidence 新建运行重做。';
|
|
50
|
+
const supersedePrerequisites=v2?['原运行记录与现有文件保留,不改写','不改变协议、身份或恢复预算']
|
|
51
|
+
:['原运行记录保留,不改写','本运行留在盘上的改动需还原,或加 --accept-superseded-code-drift'];
|
|
30
52
|
if(result?.workflow!=='cm-ai'||!result.state||!result.identity)return null;
|
|
31
53
|
const {state,code,pendingAction:action,outcome}=result;
|
|
32
54
|
if(outcome==='rejected'||outcome==='denied')return explain('本次操作被拒绝,运行状态没有因此获得新的执行权限。',
|
|
33
55
|
'先核对 code 与 reason,修正请求或取得所需授权;不要据此重复开发或审查。');
|
|
34
56
|
if(executionActive)return explain('原运行仍有操作在执行。','等待原操作结果;可读取状态,不重复派发。');
|
|
35
57
|
if(code==='spec_drift')return explain('已批准规格发生变化,后续执行被阻止。',
|
|
36
|
-
action==='spec_rebind'?'先核对重新批准的规格;符合原任务内容未变的条件时,在原运行显式换绑规格。'
|
|
58
|
+
action==='spec_rebind'?(v2?'先核对重新批准的规格;符合原条件时,只读 status 并展示 launchControlTarget,将完整固定副本写入文件,以原策略和配置带 --expected-control FILE、--rebind-spec-material 与单行 --spec-rebind-reason 恢复;snapshot_changed 时停止,不自动刷新。':'先核对重新批准的规格;符合原任务内容未变的条件时,在原运行显式换绑规格。')
|
|
37
59
|
:'先核对规格变更与原任务绑定;当前没有可直接继续的恢复动作。',null,['保留原运行身份与历史','不得绕过规格审批']);
|
|
38
60
|
if(action==='bootstrap_review_recover')return explain('项目规则交付已记录,但规则审查包尚未恢复。',
|
|
39
61
|
'核对当前规则文件、handoff 和原证据;恢复原运行后发送 bootstrap_review_recover。此路径不重新派发开发。',
|
|
40
|
-
'bootstrap_review_recover',['使用原配置与 runId,以 --mode resume 启动','
|
|
62
|
+
'bootstrap_review_recover',['使用原配置与 runId,以 --mode resume 启动',permission('--allow-bootstrap-review-recovery'),'由原宿主重新核对恢复条件']);
|
|
41
63
|
if(state==='unknown'){
|
|
42
64
|
if(action==='abandon_effect'||action==='abandon_review'){
|
|
43
65
|
const review=action==='abandon_review';
|
|
@@ -47,46 +69,46 @@ export function operatorGuidance(result,{executionActive=false}={}){
|
|
|
47
69
|
?'先确认旧宿主及相关子进程已退出、会话已停止修改文档(宿主按存档核对文档路径以外的文件与此刻的文档);再发送 abandon_effect 登记中断,运行转为 documentation_sync_interrupted,之后只重发文档同步、不重新开发,计入文档同步重发的 2 次上限。盘上改动保留并经检查与独立审查;登记中断不代表成功。'
|
|
48
70
|
:'先确认旧宿主及相关子进程已退出、会话已停止写入(provider 开发由宿主按存档记下的进程身份核对);再发送 abandon_effect 登记中断,运行从这一步的可重试阻断继续:开发重发本轮、未登记的审查重新派发、未写提交意图的完成重新复查。盘上改动保留并经检查与独立审查;登记中断不代表成功。',
|
|
49
71
|
action,['保留原配置、runId 和失败历史,以 --mode resume 启动',
|
|
50
|
-
review?'
|
|
72
|
+
review?permission('--allow-abandon-review'):permission('--allow-abandon-effect'),
|
|
51
73
|
'由原宿主核对可放弃条件;不得直接重跑或改写完成记录']);
|
|
52
74
|
}
|
|
53
75
|
// V5 (A33/A36): a no-verdict review end the host cannot prove safe to redispatch.
|
|
54
76
|
if(['review_process_unverified','review_observation_invalid','review_boundary_unverified','review_abandon_budget_exhausted'].includes(result.reviewAbandonRefusal))
|
|
55
77
|
return explain('独立审查没有结论,且宿主不能证明再派一次是安全的(reason 写明原因)。',
|
|
56
|
-
|
|
57
|
-
null,
|
|
78
|
+
`按 reason 手工核对旧审查进程与原审查证据;本运行不再重派审查。${supersede}`,
|
|
79
|
+
null,supersedePrerequisites);
|
|
58
80
|
return explain('执行结果尚未确认,不能判断这一步成功或失败。',
|
|
59
81
|
'只读核对原运行记录、进程及实际文件;当前没有已确认的直接重试入口,不新建运行绕过历史。');
|
|
60
82
|
}
|
|
61
83
|
if(state==='blocked'&&action==='abandon_review')return explain('本轮独立审查第二次没有结论,本轮还剩 1 次无结论重派,但宿主不能证明原审查进程已停止。',
|
|
62
84
|
'先确认原审查进程(含子进程)已退出;再恢复原运行并发送 abandon_review 登记确认,之后 advance 重派。不算审查轮次。',
|
|
63
|
-
'abandon_review',['保留原配置、runId 与历史,以 --mode resume 启动','
|
|
85
|
+
'abandon_review',['保留原配置、runId 与历史,以 --mode resume 启动',permission('--allow-abandon-review'),'用满 2 次后为 review_redispatch_limit']);
|
|
64
86
|
// Q16/Q17: the final task's documentation_sync failed after develop answered.
|
|
65
87
|
// R3: whatever the failure, the host cannot see whether the session still writes.
|
|
66
88
|
if(action==='develop_redo'&&Object.hasOwn(documentationMessages,code))return explain(`${documentationMessages[code][0]}宿主无法证明会话已停止修改文档。`,
|
|
67
89
|
`先确认会话已停止修改文档,${documentationMessages[code][1]}再恢复原运行并发送 develop_redo 写入确认,之后 advance 只重发文档同步。盘上的开发与文档改动保留,经检查和独立审查。`,
|
|
68
|
-
'develop_redo',['保留原配置、runId 与历史,以 --mode resume 启动','
|
|
90
|
+
'develop_redo',['保留原配置、runId 与历史,以 --mode resume 启动',permission('--allow-develop-redo'),'只重发文档同步,不重发开发;每运行最多 2 次']);
|
|
69
91
|
if(state==='blocked'&&action==='resume'&&Object.hasOwn(documentationMessages,code)){
|
|
70
92
|
const [summary,repair]=documentationMessages[code];
|
|
71
|
-
return explain(summary,`${repair}
|
|
93
|
+
return explain(summary,`${repair}然后${resume},只重发文档同步,复用已记录的开发应答,不重新开发。`,
|
|
72
94
|
'advance',['保留原配置、runId 与历史,以 --mode resume 启动','文档路径以外的文件须与文档同步开始时一致、文档须与确认停写时一致,否则拒绝','不占调用与 effect 名额;每运行最多 2 次,用满为 documentation_sync_retry_limit']);
|
|
73
95
|
}
|
|
74
96
|
if(code==='documentation_sync_retry_limit')return explain('文档同步重发已在本运行用满 2 次,不再重发。',
|
|
75
|
-
|
|
76
|
-
null,
|
|
97
|
+
`先查清会话为何一直不应答、答复 blocked 或越界写文件;${supersede}`,
|
|
98
|
+
null,supersedePrerequisites);
|
|
77
99
|
if(action==='develop_redo')return explain('开发应答没有拿到(超时后代码已改动、会话断开或只回了 failed),会话可能仍在写文件。',
|
|
78
100
|
'先确认会话已停止修改代码;再恢复原运行并发送 develop_redo 写入确认,之后 advance 重发本轮开发。盘上改动保留,经检查和独立审查。',
|
|
79
|
-
'develop_redo',['保留原配置、runId 与历史,以 --mode resume 启动','
|
|
101
|
+
'develop_redo',['保留原配置、runId 与历史,以 --mode resume 启动',permission('--allow-develop-redo'),'不占调用与 effect 名额;每运行最多 2 次']);
|
|
80
102
|
if(state==='blocked'&&action==='resume'&&code==='develop_answer_missing')return explain('已确认会话停写,本轮开发等待重发。',
|
|
81
|
-
|
|
103
|
+
`${resume},用新 effect id 重发本轮开发;盘上改动保留,经检查和独立审查。`,
|
|
82
104
|
'advance',['保留原配置、runId 与历史,以 --mode resume 启动','确认原宿主已关闭,且本轮开发有原合同要求的授权']);
|
|
83
105
|
if(state==='blocked'&&action==='resume'&&code==='develop_out_of_scope')return explain('开发交付已落盘,但改动超出了任务 scope(reason 列出路径),尚未进入审查。',
|
|
84
|
-
|
|
106
|
+
`核对这些路径:会话越界写的就还原,你自己的改动就移出代码根,确需改动先走规格变更扩大 scope;然后${resume},只重跑检查、验证预检与审查包,不重新开发。`,
|
|
85
107
|
'advance',['保留原配置、runId 与历史,以 --mode resume 启动','不占开发调用与 effect 名额;每运行最多 2 次','不擅自删除用户改动']);
|
|
86
108
|
if(state==='blocked'&&action==='resume'&&['check_answer_missing','check_answer_invalid'].includes(code))
|
|
87
109
|
return explain(code==='check_answer_invalid'?'开发交付已落盘,但之后的检查或验证预检答复格式不合格。'
|
|
88
110
|
:'开发交付已落盘,但之后的检查或验证预检没有拿到应答(超时、断开或迟到)。',
|
|
89
|
-
|
|
111
|
+
`先确认上一次检查命令已停止;然后${resume},只重跑检查、验证预检与审查包,不重新开发。`,
|
|
90
112
|
'advance',['保留原配置、runId 与历史,以 --mode resume 启动','不占开发调用与 effect 名额;每运行最多 2 次','不会自动完成任务或消耗新的独立审查轮次']);
|
|
91
113
|
if(state==='blocked'&&action==='complete'&&code==='complete_commit_interrupted')return explain('宿主在写入任务完成提交意图后退出,tasks.md 可能已勾选也可能未勾选。',
|
|
92
114
|
'恢复原运行并发送 complete;宿主只按存档里的提交计划核对并收尾,不重新复查、不重新开发。tasks.md 或证据被改动时会拒绝并保留现场。',
|
|
@@ -96,25 +118,26 @@ export function operatorGuidance(result,{executionActive=false}={}){
|
|
|
96
118
|
'complete',['原 run 与已审交接、范围和包绑定不变','task-commit-intent 尚未写入;每运行最多 2 次']);
|
|
97
119
|
if(state==='blocked'&&action==='resume'&&Object.hasOwn(deliveryMessages,code)){
|
|
98
120
|
const [summary,repair]=deliveryMessages[code];
|
|
99
|
-
return explain(summary,`${repair}
|
|
121
|
+
return explain(summary,`${repair};然后${resume},重做本轮交付和检查。`,
|
|
100
122
|
'advance',['保留原配置、runId 与历史,以 --mode resume 启动','确认原宿主已关闭,且本轮开发有原合同要求的授权','不会自动完成任务或消耗新的独立审查轮次']);
|
|
101
123
|
}
|
|
102
124
|
if(state==='pending_review'&&action==='resume')return explain('本轮独立审查未取得可接受的结论。',
|
|
103
|
-
|
|
125
|
+
`核对 code 与原审查证据;取得本轮绑定的独立审查授权,再${resume}。`,
|
|
104
126
|
'advance',['原 run、配置和审查包绑定不变','原宿主仍须核对重派次数、进程和独立审查权限']);
|
|
105
127
|
if(state==='blocked'&&action==='complete')return explain('完成前复核受阻,已有审查结论不能直接当作任务完成。',
|
|
106
128
|
'核对 reason 中的检查或文件变化;满足原完成条件后,在原运行发送 complete,不重新开发。',
|
|
107
129
|
'complete',['原 run 与已审交接、范围和包绑定不变','使用当前 packageDigest;由宿主重新核对完成条件']);
|
|
108
130
|
if(code==='review_redispatch_limit')return explain('本轮独立审查已无结论重派 2 次,不再重派;这不计为审查轮次。',
|
|
109
|
-
|
|
110
|
-
null,
|
|
131
|
+
`先查清审查进程为何一直没有结论(登录、额度、网络或审查答复格式);${supersede}`,
|
|
132
|
+
null,supersedePrerequisites);
|
|
111
133
|
if(['check_answer_retry_limit','complete_recheck_limit','develop_redo_limit'].includes(code))
|
|
112
134
|
return explain('这一步的自动恢复已在本运行用满 2 次,不再重做。',
|
|
113
|
-
|
|
114
|
-
null,
|
|
135
|
+
`先查清会话为何一直不应答或答复不合格(或宿主环境为何失败);${supersede}`,
|
|
136
|
+
null,supersedePrerequisites);
|
|
115
137
|
// Q06/Q07/Q11: a QA call that stopped as a whole.
|
|
116
138
|
if(state==='fixture_completed'&&code==='qa_execution_unknown')return explain('本轮 QA 没有正常结束(整轮超时、宿主中途退出、答复格式不合格,或浏览器请求超时后设备可能仍被会话占用)。',
|
|
117
|
-
'
|
|
139
|
+
v2?(batch?'先确认上一轮会话与设备已空闲;批次 v2 没有启动型 QA 重跑出口,保留批次与 QA 证据并核对 reason,不新建运行绕过。':'先确认上一轮的会话、浏览器或模拟器已停止、设备已空闲;只读 status,展示并核对 launchControlTarget 后完整固定到文件。以原策略与配置 --mode resume、--expected-control FILE 和 --rerun-unknown-qa 启动;snapshot_changed 时停止,不自动刷新目标。宿主拒绝时保留原运行与 QA 证据,不改走旧入口。')
|
|
140
|
+
:'先确认上一轮的会话、浏览器或模拟器已停止、设备已空闲;再用原配置 --mode resume 加 --rerun-unknown-qa 重跑本轮。宿主拒绝时按拒绝码处理:含原始 FAIL、未解决的 [需确认] 或无法归因的旧记录的轮次不能替代,改用 --supersede-reviewed-evidence 新建运行。',
|
|
118
141
|
null,['保留原运行与 QA 日志,只追加不改写','因宿主或应答原因替代的轮次不占三轮预算']);
|
|
119
142
|
// Q15: the read-only documentation check answered blocked.
|
|
120
143
|
if(state==='fixture_completed'&&code==='documentation_sync_blocked')return explain('文档核对判定文档尚未同步(reason 写明缺什么)。',
|
|
@@ -151,20 +174,23 @@ const BATCH_RECOVERY={
|
|
|
151
174
|
};
|
|
152
175
|
// A member result is not a batch control surface. Keep unsupported single-run
|
|
153
176
|
// recovery operations out of batch instructions without changing pendingAction.
|
|
154
|
-
export function batchOperatorGuidance(result,{taskKey=null}={}){
|
|
155
|
-
const
|
|
177
|
+
export function batchOperatorGuidance(result,{taskKey=null,protocol='legacy'}={}){
|
|
178
|
+
const context=guidanceContext.get(result?.guidance);
|
|
179
|
+
const g=context?operatorGuidance(result,{...context,protocol,surface:'batch'}):result?.guidance;
|
|
180
|
+
if(!g)return null;
|
|
156
181
|
if(Object.hasOwn(BATCH_RECOVERY,g.recoveryOperation)){
|
|
157
|
-
const [flag,
|
|
182
|
+
const [flag,defaultConfirm]=BATCH_RECOVERY[g.recoveryOperation],target=taskKey??'FEATURE/TASK';
|
|
183
|
+
const confirm=g.recoveryOperation==='develop_redo'&&Object.hasOwn(documentationMessages,result.code)
|
|
184
|
+
?'先确认会话已停止修改文档':defaultConfirm;
|
|
185
|
+
if(protocol==='v2')return explain(g.summary,
|
|
186
|
+
`${confirm};用原策略与配置从批次入口只读 status,展示并核对完整批次 controlTarget(batchId、taskKey、member、batchDigest),按当前对话的具体决定固定为 expectedControl;发送 version:2 的批次操作 ${g.recoveryOperation}(taskKey ${target}、单行 reason),之后 advance 继续本批次。`,
|
|
187
|
+
g.recoveryOperation,['保留原批次、成员身份与历史;不跨成员','snapshot_changed 时停止,不自动刷新目标重试;批次 cancel 后不能再恢复']);
|
|
158
188
|
return explain(g.summary,`${confirm};关闭批次宿主,带 ${flag} ${target} 用同一批次配置重新启动,发送批次操作 ${g.recoveryOperation}(taskKey ${target}、单行 reason),之后 advance 继续本批次。`,
|
|
159
189
|
g.recoveryOperation,['保持原批次配置;批次只用这一项权限打开该成员运行,不跨成员','授权用一次即失效;批次 cancel 后不能再恢复']);
|
|
160
190
|
}
|
|
161
191
|
if(result.code==='spec_drift')return explain(g.summary,
|
|
162
192
|
'批次成员不能换绑规格;先按 reason 核对原批次可用出口,不直接重派。');
|
|
163
|
-
if(g.recoveryOperation==='advance')return explain(g.summary,
|
|
164
|
-
g.nextStep.replace('然后恢复原运行并发送 advance,重做本轮交付和检查。','然后从原批次入口发送 advance,重做本轮交付和检查。')
|
|
165
|
-
.replace('然后恢复原运行并发送 advance,只重跑','然后从原批次入口发送 advance,只重跑')
|
|
166
|
-
.replace('恢复原运行并发送 advance,用新 effect id','从原批次入口发送 advance,用新 effect id')
|
|
167
|
-
.replace('恢复原运行后,取得本轮绑定的独立审查授权,再发送 advance。','沿原批次续接,取得本轮绑定的独立审查授权,再发送 advance。'),
|
|
193
|
+
if(g.recoveryOperation==='advance')return explain(g.summary,g.nextStep,
|
|
168
194
|
'advance',['保持原批次配置、身份和 PLAN;成员运行由批次宿主选择恢复','先确认原批次宿主已关闭;开发与审查仍需原合同授权']);
|
|
169
195
|
if(g.recoveryOperation==='complete')return explain(g.summary,
|
|
170
196
|
'核对 reason 中的检查或文件变化;满足原完成条件后,从原批次入口发送 advance,由成员宿主继续完成复核。',
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {beginHostStage} from './host-stage-observer.mjs';
|
|
1
2
|
import {readExecutionPolicy} from './execution-policy.mjs';
|
|
2
3
|
import {readExternalModels} from './external-models.mjs';
|
|
3
4
|
import {beforeFirstQaRound,readQaConfigRevision} from './qa-config-revision.mjs';
|
|
@@ -840,6 +841,7 @@ export function createTaskRunner(options) {
|
|
|
840
841
|
function active(){need(!poisoned,'store_failure');need(state!=='cancelled','cancelled');}
|
|
841
842
|
async function bounded(fn,request,extraControl=null) {
|
|
842
843
|
active();let timer,abort;
|
|
844
|
+
const endStage=beginHostStage(request?.role==='developer'?'develop':request?.role==='reviewer'?'review':'check',config.timeoutMs);
|
|
843
845
|
try {
|
|
844
846
|
const boxed=await Promise.race([
|
|
845
847
|
new Promise((resolve,reject)=>{
|
|
@@ -865,7 +867,7 @@ export function createTaskRunner(options) {
|
|
|
865
867
|
})
|
|
866
868
|
]);
|
|
867
869
|
return boxed.value;
|
|
868
|
-
} finally {clearTimeout(timer);controller.signal.removeEventListener('abort',abort);}
|
|
870
|
+
} finally {endStage();clearTimeout(timer);controller.signal.removeEventListener('abort',abort);}
|
|
869
871
|
}
|
|
870
872
|
async function invoke(adapter,role,contextId,payload,extraControl=null) {
|
|
871
873
|
const request=requestFor({invocationId:`${session}.${++sequence}`,identity:{...config.identity,attempt},
|
|
@@ -981,6 +983,7 @@ export function createTaskRunner(options) {
|
|
|
981
983
|
}
|
|
982
984
|
};
|
|
983
985
|
let timer,timedOut=false,cancelReject;
|
|
986
|
+
const endReviewStage=beginHostStage('review',reviewTimeoutMs??config.timeoutMs);
|
|
984
987
|
try{
|
|
985
988
|
let raw;
|
|
986
989
|
try{
|
|
@@ -1090,7 +1093,7 @@ export function createTaskRunner(options) {
|
|
|
1090
1093
|
else if(retry)halt(retry.state,retry.code);
|
|
1091
1094
|
else halt('unknown',inspection.code??'reconciliation_required');
|
|
1092
1095
|
}finally{
|
|
1093
|
-
captureOpen=false;
|
|
1096
|
+
endReviewStage();captureOpen=false;
|
|
1094
1097
|
if((metadata.externalModels||metadata.executionPolicy)&&(state==='unknown'||state==='pending_review'&&code==='review_transport_timeout')
|
|
1095
1098
|
&&started!==null&&!invalid&&!receiptConflict&&capturedReceipt)
|
|
1096
1099
|
pendingReconciliation={effectId,invocationId:request.invocationId,receipt:capturedReceipt};
|
|
@@ -46,9 +46,14 @@ export function inspectPrdSummaryEvidence(specs,{currentFeatures}={}){
|
|
|
46
46
|
if(bytes!==null)evidenceFiles.push({path:file,sha256:sha(bytes)});
|
|
47
47
|
}
|
|
48
48
|
const args={stage,feature:slug,evidence:path.join(specs,prefix+'-r1.md'),receipt:path.join(specs,prefix+'-disposition.json')};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
try{
|
|
49
|
+
let findings=null,archiveIssue={},correctionSelfCheck=null,gate;
|
|
50
|
+
// A historical receipt may bind bytes that a later approved revision changed: register it, never block.
|
|
51
|
+
try{gate=inspectPrdReview(args);}
|
|
52
|
+
catch(error){
|
|
53
|
+
if(!historical)throw error;
|
|
54
|
+
gate={stage,feature:slug,outcome:'unavailable'};archiveIssue={archive:'unavailable',reason:error.code??error.message};
|
|
55
|
+
}
|
|
56
|
+
if(gate.outcome!=='unavailable')try{
|
|
52
57
|
if(['resume_disposition','completed'].includes(gate.outcome))findings=inspectPrdFindings({specs,stage,feature:directory});
|
|
53
58
|
if(gate.outcome==='completed'){
|
|
54
59
|
const receipt=JSON.parse(readCmInitSource(specs,prefix+'-disposition.json').toString('utf8'));
|
|
@@ -67,7 +72,7 @@ export function inspectPrdSummaryEvidence(specs,{currentFeatures}={}){
|
|
|
67
72
|
archiveIssue={archive:original!==null&&!/\n```json\n[^\n]+\n```\n$/.test(original.toString('utf8'))?'legacy_format':'unavailable',
|
|
68
73
|
reason:error.message};
|
|
69
74
|
}
|
|
70
|
-
if(historical
|
|
75
|
+
if(historical&&!['completed','unavailable'].includes(gate.outcome)&&(stage==='split'||gate.outcome!=='dispatch_once'))
|
|
71
76
|
archiveIssue={archive:archiveIssue.archive??'receipt_missing',
|
|
72
77
|
reason:[archiveIssue.reason,'prd_summary_receipt_missing'].filter(Boolean).join('; ')};
|
|
73
78
|
reviews[stage]={gate,independent:findings?.independent??null,verdict:findings?.verdict??null,
|
|
@@ -86,14 +91,24 @@ export function inspectPrdSummaryEvidence(specs,{currentFeatures}={}){
|
|
|
86
91
|
cases={total:null,user:null,generated:null,status:'invalid',reason:'test_cases_invalid'};
|
|
87
92
|
}
|
|
88
93
|
}
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
94
|
+
const revisionPath=prdSelfCheckRevisionPath(directory);let revision=null;
|
|
95
|
+
try{
|
|
96
|
+
revision=readPrdSelfCheckRevision(specs,directory);
|
|
97
|
+
if(revision!==null){
|
|
98
|
+
const target=revision.features.find(f=>f.directory===directory);
|
|
99
|
+
evidenceFiles.push({path:revisionPath,sha256:sha(readCmInitSource(specs,revisionPath))});
|
|
100
|
+
// The note is about exactly the revision reviewed by this split, including low-risk designs.
|
|
101
|
+
inspectPrdSplitDesign({specs,feature:directory,draftDigest:revision.draftDigest,
|
|
102
|
+
originalSha:target.documents.find(d=>d.path==='design.md').beforeSha256,
|
|
103
|
+
requirementsSha:target.documents.find(d=>d.path==='requirements.md').beforeSha256});
|
|
104
|
+
}
|
|
105
|
+
}catch(error){
|
|
106
|
+
// Same boundary as the review gate above: a historical revision check registers, never blocks.
|
|
107
|
+
if(!historical)throw error;
|
|
108
|
+
const bytes=readCmInitSource(specs,revisionPath);
|
|
109
|
+
if(bytes!==null&&!evidenceFiles.some(item=>item.path===revisionPath))evidenceFiles.push({path:revisionPath,sha256:sha(bytes)});
|
|
110
|
+
reviews.split={...reviews.split,archive:reviews.split.archive??'unavailable',
|
|
111
|
+
reason:[reviews.split.reason,`self_check_revision:${error.code??error.message}`].filter(Boolean).join('; ')};
|
|
97
112
|
}
|
|
98
113
|
features.push({directory,reviews,cases,...(revision?{selfCheckRevision:{reason:revision.reason,round:revision.round,
|
|
99
114
|
changedFiles:revision.features.find(f=>f.directory===directory).changedFiles}}:{}),...(currentFeatures===undefined?{}:{historical})});
|
package/runtime/review.md
CHANGED
|
@@ -83,6 +83,15 @@ directory for CLAUDE_CODE_TMPDIR and stops after the first valid message request
|
|
|
83
83
|
termination is not user cancellation or a successful review; real model review remains unverified.
|
|
84
84
|
Do not handcraft a passing diagnostic or approval to bypass readiness evidence.
|
|
85
85
|
Claude review streams accept `system/api_retry`, `hook_started`, `hook_response` and `commands_changed` only as `onNotice` summaries, sharing a 32-notice limit with `rate_limit_event`; they never enter observation or advance the verdict stage, and unknown system subtypes still fail closed (2026-09-17 dogfood: a transient API retry was misclassified as `unexpected_event`).
|
|
86
|
+
`system/ui_invalidate` is a fixed, body-free notice before or after `init`, as is
|
|
87
|
+
the existing `dev_intent` startup notice. Both bind the session and share the
|
|
88
|
+
same 32 slots; neither initializes a turn nor supplies a verdict. Missing init,
|
|
89
|
+
cross-session messages, unknown subtypes and post-terminal messages still fail.
|
|
90
|
+
The local probe still requires a compliant `/v1/messages` request; startup
|
|
91
|
+
health checks alone cannot pass (Claude Code 2.1.289 startup regression).
|
|
92
|
+
Claude probe model IDs are matched exactly against the outgoing request. Use
|
|
93
|
+
the full model ID when a CLI alias resolves to a different ID; a health response
|
|
94
|
+
or a mismatched model must not be converted into a passing diagnostic.
|
|
86
95
|
`system/thinking_tokens` has a separate 4096-event budget and remains subject to the worker's total 1,000,000-byte output cap; it emits no observation or notice and never advances the verdict stage (2026-09-17 dogfood: an 88-heartbeat review exceeded the former 64-event cap). The 4097th heartbeat fails with `unexpected_event`; output overflow retains `output_limit`.
|
|
87
96
|
|
|
88
97
|
## Review scope
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {hostDiagnostic} from './fixtures/host-diagnostic.mjs';
|
|
1
2
|
import test from 'node:test';
|
|
2
3
|
import assert from 'node:assert/strict';
|
|
3
4
|
import fs from 'node:fs';
|
|
@@ -83,24 +84,33 @@ function execute(f,{cancel=false,args=[],operations=[{operation:'advance',reques
|
|
|
83
84
|
return new Promise((resolve,reject)=>{
|
|
84
85
|
const child=spawn(process.execPath,[cli,...f.args,...args],
|
|
85
86
|
{env:f.env,stdio:['pipe','pipe','pipe']});
|
|
86
|
-
let buffer='',stderr='',sessionId;const calls=[],rows=[];
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
let buffer='',stderr='',sessionId;const calls=[],rows=[],pendingControls=new Set();
|
|
88
|
+
let finalOperationReceived=false,closeRequested=false;
|
|
89
|
+
// Cancellation can finish the original advance before its status/cancel
|
|
90
|
+
// handlers return. Await those replies before requesting an idle close.
|
|
91
|
+
const closeWhenIdle=()=>{
|
|
92
|
+
if(finalOperationReceived&&pendingControls.size===0&&!closeRequested){
|
|
93
|
+
closeRequested=true;send({type:'host_close',sessionId});
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
const timeoutMs=Number(process.env.CM_TEST_FIXTURE_TIMEOUT_MS??60000),trace=hostDiagnostic(child,{timeoutMs});
|
|
97
|
+
const timer=setTimeout(()=>{child.kill('SIGTERM');reject(trace.attach(Error('batch host timeout')));},timeoutMs);
|
|
98
|
+
child.stderr.on('data',part=>{stderr+=part;});child.once('error',error=>reject(trace.attach(error)));
|
|
99
|
+
const send=value=>{trace.send(value);child.stdin.write(JSON.stringify(value)+'\n');};
|
|
90
100
|
const respond=(row,result)=>send({type:'host_result',sessionId:row.sessionId,callId:row.callId,requestDigest:row.requestDigest,result});
|
|
91
101
|
child.stdout.on('data',part=>{
|
|
92
102
|
buffer+=part;let newline;
|
|
93
103
|
while((newline=buffer.indexOf('\n'))!==-1){
|
|
94
104
|
const line=buffer.slice(0,newline);buffer=buffer.slice(newline+1);if(!line)continue;
|
|
95
105
|
try{
|
|
96
|
-
const row=JSON.parse(line);rows.push(row);
|
|
106
|
+
const row=JSON.parse(line);rows.push(row);trace.receive(row);
|
|
97
107
|
if(row.type==='host_ready')sessionId=row.sessionId;
|
|
98
108
|
if(row.type==='host_request'){
|
|
99
109
|
const payload=row.payload,identity=payload.identity??payload.request.identity;
|
|
100
110
|
const cwd=f.parallel&&identity.taskId!=='T-003'
|
|
101
111
|
?path.join(f.root,'.cm-worktrees',f.batch.batchId.slice(0,8),identity.taskId):f.codeProject;
|
|
102
112
|
calls.push(`${identity.taskId}:${row.kind}`);
|
|
103
|
-
if(cancel){send({operation:'status',requestId:'status'});send({operation:'cancel',requestId:'cancel'});continue;}
|
|
113
|
+
if(cancel){pendingControls.add('status');pendingControls.add('cancel');send({operation:'status',requestId:'status'});send({operation:'cancel',requestId:'cancel'});continue;}
|
|
104
114
|
if(row.kind==='develop'){
|
|
105
115
|
assert.equal(payload.request.provider,f.runtime);
|
|
106
116
|
const n=Number(identity.taskId.slice(-1));
|
|
@@ -133,12 +143,14 @@ function execute(f,{cancel=false,args=[],operations=[{operation:'advance',reques
|
|
|
133
143
|
}
|
|
134
144
|
const index=operations.findIndex(item=>item.requestId===row.requestId);
|
|
135
145
|
if(index>=0&&(row.result||row.error)){
|
|
136
|
-
if(index+1<operations.length)send(operations[index+1]);else
|
|
146
|
+
if(index+1<operations.length)send(operations[index+1]);else finalOperationReceived=true;
|
|
137
147
|
}
|
|
138
|
-
|
|
148
|
+
if(row.result||row.error)pendingControls.delete(row.requestId);
|
|
149
|
+
closeWhenIdle();
|
|
150
|
+
}catch(error){clearTimeout(timer);child.kill('SIGTERM');reject(trace.attach(error));}
|
|
139
151
|
}
|
|
140
152
|
});
|
|
141
|
-
child.once('close',code=>{clearTimeout(timer);resolve({code,stderr,calls,rows,
|
|
153
|
+
child.once('close',code=>{clearTimeout(timer);resolve({code,stderr,calls,rows,diagnostic:trace.snapshot(),
|
|
142
154
|
results:Object.fromEntries(operations.map(item=>[item.requestId,rows.find(row=>row.requestId===item.requestId)?.result])),
|
|
143
155
|
result:rows.find(row=>row.requestId===operations.at(-1).requestId)?.result});});
|
|
144
156
|
send(operations[0]);
|