@aibyzero/cm-workflow 0.16.8 → 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 +31 -0
- package/README.md +22 -3
- package/VERSION +1 -1
- package/compat/claude-commands/cm-notify.md +3 -0
- 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 +119 -78
- package/docs/next-steps.md +19 -2
- package/docs/untested-branches.md +2 -3
- package/docs/user-guide.md +105 -5
- package/package.json +2 -1
- package/runtime/js/cm-ai/claude-review-stream.mjs +49 -13
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +103 -68
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +79 -27
- package/runtime/js/cm-ai/code-projects.mjs +4 -1
- package/runtime/js/cm-ai/control-policy.mjs +111 -0
- package/runtime/js/cm-ai/developer-adapter.mjs +7 -0
- package/runtime/js/cm-ai/drive-bootstrap.mjs +11 -8
- package/runtime/js/cm-ai/drive-core.mjs +9 -0
- package/runtime/js/cm-ai/durable-runner-state.mjs +883 -69
- package/runtime/js/cm-ai/effect-abandon-log.mjs +5 -2
- package/runtime/js/cm-ai/effect-contract.mjs +6 -1
- package/runtime/js/cm-ai/external-run-guard.mjs +18 -7
- package/runtime/js/cm-ai/gate-bridge.mjs +4 -4
- package/runtime/js/cm-ai/host-check.mjs +4 -1
- package/runtime/js/cm-ai/host-conversation-execution.mjs +33 -24
- package/runtime/js/cm-ai/host-documentation.mjs +53 -12
- package/runtime/js/cm-ai/host-project-execution.mjs +2 -2
- package/runtime/js/cm-ai/host-qa-executor.mjs +49 -4
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +53 -9
- 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-session.mjs +1 -1
- package/runtime/js/cm-ai/host-tool-bridge.mjs +43 -3
- 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 +89 -3
- package/runtime/js/cm-ai/provider-review-observation.mjs +50 -0
- package/runtime/js/cm-ai/qa-resource-release.mjs +46 -0
- package/runtime/js/cm-ai/qa-round-budget.mjs +13 -0
- package/runtime/js/cm-ai/review-package.mjs +26 -5
- package/runtime/js/cm-ai/reviewed-deliveries.mjs +1 -1
- package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +1 -1
- package/runtime/js/cm-ai/task-commit.mjs +39 -0
- package/runtime/js/cm-ai/task-runner.mjs +629 -121
- package/runtime/js/cm-ai/worker-claude-developer.mjs +9 -0
- package/runtime/js/cm-ai/worker-claude.mjs +10 -3
- package/runtime/js/cm-ai/worker-process-identity.mjs +43 -0
- package/runtime/js/cm-fix/execution.mjs +176 -48
- package/runtime/js/cm-fix/host.mjs +2 -1
- package/runtime/js/cm-fix/pinned-baseline.mjs +24 -0
- package/runtime/js/cm-fix/progress.mjs +13 -3
- package/runtime/js/cm-fix/protected-edits.mjs +10 -3
- package/runtime/js/cm-fix/repair.mjs +11 -3
- package/runtime/js/cm-fix/test-author.mjs +10 -3
- package/runtime/js/cm-idea/session.mjs +67 -4
- package/runtime/js/cm-init/review-evidence.mjs +3 -1
- package/runtime/js/cm-prd/review-correction.mjs +10 -4
- package/runtime/js/cm-prd/review-host.mjs +1 -1
- package/runtime/js/cm-prd/review-publication.mjs +5 -3
- package/runtime/js/cm-prd/session.mjs +43 -0
- package/runtime/js/cm-refactor/records.mjs +98 -8
- package/runtime/js/cm-refactor/workflow.mjs +80 -10
- package/runtime/js/cm-test/host.mjs +10 -3
- package/runtime/js/cm-test/session.mjs +45 -6
- package/runtime/js/notify-safe-read.mjs +49 -0
- package/runtime/js/notify-send.mjs +313 -0
- package/runtime/js/notify.mjs +164 -37
- package/runtime/js/policy-binding-compat.mjs +55 -0
- package/runtime/review.md +52 -7
- package/runtime/task-gates.md +107 -9
- package/scripts/ci-test-shards.mjs +67 -0
- package/scripts/ci-test-shards.test.mjs +64 -0
- package/scripts/ci-test-weights.json +222 -0
- package/scripts/cm-ai-abandon-effect-position.test.mjs +71 -10
- package/scripts/cm-ai-answer-gap-dispatch.test.mjs +86 -0
- package/scripts/cm-ai-answer-gap-driver.test.mjs +51 -0
- package/scripts/cm-ai-answer-gap-fixture.mjs +89 -0
- package/scripts/cm-ai-answer-gap-recheck.test.mjs +70 -0
- package/scripts/cm-ai-answer-gap-redo.test.mjs +103 -0
- package/scripts/cm-ai-batch-drive.mjs +98 -34
- package/scripts/cm-ai-batch-drive.test.mjs +124 -16
- package/scripts/cm-ai-batch-host.mjs +167 -29
- package/scripts/cm-ai-batch-host.test.mjs +303 -31
- package/scripts/cm-ai-batch-run-fixture.mjs +452 -0
- package/scripts/cm-ai-batch-run-member-stops.test.mjs +26 -0
- package/scripts/cm-ai-batch-run-parallel.test.mjs +7 -0
- package/scripts/cm-ai-batch-run-reschedule.test.mjs +17 -0
- package/scripts/cm-ai-batch-run.mjs +213 -25
- package/scripts/cm-ai-batch-run.test.mjs +21 -341
- 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 +97 -0
- package/scripts/cm-ai-develop-call-timeout.test.mjs +146 -0
- package/scripts/cm-ai-develop-driver-gaps.test.mjs +37 -23
- package/scripts/cm-ai-direct-review.test.mjs +348 -0
- package/scripts/cm-ai-documentation-sync-gap.test.mjs +424 -0
- package/scripts/cm-ai-drive-bootstrap-rules.test.mjs +54 -25
- package/scripts/cm-ai-drive.mjs +142 -58
- package/scripts/cm-ai-drive.test.mjs +70 -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 +267 -0
- package/scripts/cm-ai-host-fixture.mjs +296 -0
- package/scripts/cm-ai-host-protected.test.mjs +253 -0
- package/scripts/cm-ai-host.mjs +122 -100
- package/scripts/cm-ai-host.test.mjs +35 -776
- 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 +54 -0
- package/scripts/cm-ai-multi-root.test.mjs +4 -4
- package/scripts/cm-ai-nested-execution.test.mjs +16 -19
- package/scripts/cm-ai-operator-guidance.test.mjs +30 -5
- 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 +8 -5
- package/scripts/cm-ai-qa-answer-gaps.test.mjs +99 -0
- 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 +95 -13
- 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 +59 -14
- package/scripts/cm-ai-review-drift-precedence.test.mjs +1 -1
- package/scripts/cm-ai-review-failure.test.mjs +137 -32
- package/scripts/cm-ai-review-timeout-config.test.mjs +3 -1
- package/scripts/cm-ai-review-timeout.test.mjs +132 -67
- package/scripts/cm-ai-run.mjs +91 -28
- 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 +489 -51
- 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 +8 -0
- package/scripts/cm-check-drive.test.mjs +2 -5
- package/scripts/cm-check-runtime.sh +4 -2
- package/scripts/cm-claude-developer-worker.test.mjs +15 -0
- package/scripts/cm-claude-review-stream.test.mjs +21 -16
- package/scripts/cm-claude-review-synthetic.test.mjs +155 -0
- package/scripts/cm-claude-worker.test.mjs +23 -5
- 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 +32 -12
- package/scripts/cm-external-qa-fix.test.mjs +1 -1
- package/scripts/cm-external-review-reconciliation.test.mjs +6 -24
- package/scripts/cm-fix-abandon.test.mjs +163 -10
- package/scripts/cm-fix-drive-unprotected.test.mjs +37 -0
- package/scripts/cm-fix-drive.mjs +25 -7
- package/scripts/cm-fix-host.mjs +8 -7
- package/scripts/cm-fix-review-budget.test.mjs +13 -0
- package/scripts/cm-fix-review-recovery.test.mjs +36 -1
- package/scripts/cm-host-answer-timeout.test.mjs +65 -0
- package/scripts/cm-host-call-kinds.test.mjs +28 -0
- package/scripts/cm-host-documentation.test.mjs +49 -0
- package/scripts/cm-host-qa-executor.test.mjs +23 -12
- package/scripts/cm-host-qa-policy.test.mjs +43 -16
- package/scripts/cm-host-review-authority.test.mjs +0 -31
- package/scripts/cm-idea-answer-gaps.test.mjs +164 -0
- package/scripts/cm-idea-drive.mjs +49 -11
- package/scripts/cm-idea-drive.test.mjs +66 -0
- package/scripts/cm-idea-host.mjs +106 -16
- package/scripts/cm-init-answer-gaps.test.mjs +258 -0
- package/scripts/cm-init-drive.mjs +41 -7
- package/scripts/cm-init-host.mjs +61 -12
- package/scripts/cm-knowledge-closeout.test.mjs +3 -3
- package/scripts/cm-log-event.mjs +21 -10
- package/scripts/cm-notify-command.test.mjs +936 -0
- package/scripts/cm-notify-read-drift.test.mjs +270 -0
- package/scripts/cm-notify.mjs +481 -0
- package/scripts/cm-notify.test.mjs +312 -23
- package/scripts/cm-patrol.test.mjs +3 -2
- package/scripts/cm-prd-answer-gaps.test.mjs +216 -0
- package/scripts/cm-prd-drive.mjs +18 -5
- package/scripts/cm-prd-drive.test.mjs +15 -0
- package/scripts/cm-prd-host.mjs +37 -4
- package/scripts/cm-prd-review-disposition.test.mjs +6 -1
- package/scripts/cm-prd-review-gate.mjs +56 -0
- package/scripts/cm-refactor-answer-gaps.test.mjs +206 -0
- package/scripts/cm-refactor-drive.mjs +52 -8
- package/scripts/cm-refactor-drive.test.mjs +44 -0
- package/scripts/cm-refactor-host.test.mjs +10 -6
- package/scripts/cm-release-smoke.sh +2 -0
- 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/cm-test-answer-gaps.test.mjs +151 -0
- package/scripts/cm-test-drive.mjs +21 -5
- package/scripts/fixtures/bootstrap-review-runner.mjs +1 -7
- package/scripts/fixtures/claude-review-process.mjs +1 -1
- package/scripts/fixtures/native-gate-fixture.mjs +18 -0
- package/scripts/policy-binding-compat.test.mjs +103 -0
- package/scripts/scan-public-safety.py +4 -0
- package/scripts/validate-public-repo.py +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 +85 -11
- package/skills/cm-ai/references/js-host-recovery.md +181 -21
- package/skills/cm-ai/references/js-host.md +76 -32
- package/skills/cm-check/SKILL.md +3 -3
- package/skills/cm-fix/SKILL.md +12 -0
- package/skills/cm-fix/references/js-host.md +44 -5
- package/skills/cm-idea/references/js-host.md +27 -2
- package/skills/cm-init/references/js-host.md +17 -4
- package/skills/cm-notify/SKILL.md +34 -0
- package/skills/cm-prd/references/js-change-recovery.md +35 -1
- package/skills/cm-prd/references/js-host.md +1 -1
- package/skills/cm-refactor/SKILL.md +12 -0
- package/skills/cm-refactor/references/js-host.md +17 -0
- package/skills/cm-test/references/js-host.md +14 -1
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
// P1-4 (O02, O05/O06): a recorded answer the host then refused can be discarded
|
|
2
|
+
// and asked again under the same pending operation (real prd-4b8e48aa shape:
|
|
3
|
+
// change-mode prd_generate); one interrupted or unpublishable prd_review attempt
|
|
4
|
+
// can be abandoned with an explicit flag and reason, releasing the gate claim
|
|
5
|
+
// for a fresh independent review (real prd-29b5f91e shape: a split review that
|
|
6
|
+
// came back self-degraded for an independent request). A recorded review that
|
|
7
|
+
// would publish is never abandoned.
|
|
8
|
+
import test,{after} from 'node:test';
|
|
9
|
+
import assert from 'node:assert/strict';
|
|
10
|
+
import fs from 'node:fs';
|
|
11
|
+
import path from 'node:path';
|
|
12
|
+
import os from 'node:os';
|
|
13
|
+
import {spawn} from 'node:child_process';
|
|
14
|
+
import {once} from 'node:events';
|
|
15
|
+
import {createInterface} from 'node:readline';
|
|
16
|
+
import {fileURLToPath} from 'node:url';
|
|
17
|
+
import {inspectPrdReview} from './cm-prd-review-gate.mjs';
|
|
18
|
+
import {openPrdSession} from '../runtime/js/cm-prd/session.mjs';
|
|
19
|
+
|
|
20
|
+
const isolatedWorkflowHome=fs.mkdtempSync(path.join(os.tmpdir(),'cm-prd-gaps-home-'));
|
|
21
|
+
process.env.CM_WORKFLOW_HOME=path.join(isolatedWorkflowHome,'user');
|
|
22
|
+
process.env.CM_WORKFLOW_LOG_HOME=path.join(isolatedWorkflowHome,'logs');
|
|
23
|
+
after(()=>fs.rmSync(isolatedWorkflowHome,{recursive:true,force:true}));
|
|
24
|
+
const root=path.resolve(path.dirname(fileURLToPath(import.meta.url)),'..');
|
|
25
|
+
const version='\n| 日期 | 版本 | 说明 |\n| --- | --- | --- |\n| 2026-09-08 | v1 | original |\n';
|
|
26
|
+
const docs=()=>[
|
|
27
|
+
{path:'requirements.md',content:'## 需求版本'+version+'\n## 功能需求\n1. [F-001] Guide\n- [ ] [AC-001] Read guide\n'},
|
|
28
|
+
{path:'design.md',content:'## 设计版本'+version+'\n## 方案摘要\nExisting guide\n'},
|
|
29
|
+
{path:'tasks.md',content:'## 任务版本'+version+'\n- [x] T-001: Existing guide\n- [ ] T-002: Draft appendix\n'}];
|
|
30
|
+
const revised=()=>docs().map(doc=>({path:doc.path,content:doc.content.replace('| 2026-09-08 | v1 | original |','| 2026-09-08 | v1 | original |\n| 2026-09-08 | v2 | change |')
|
|
31
|
+
+(doc.path==='tasks.md'?'\n- [ ] T-003: [NEW] Add example\n':'\nUpdated example\n')}));
|
|
32
|
+
function fixture(t){const dir=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-prd-gaps-')));
|
|
33
|
+
t.after(()=>fs.rmSync(dir,{recursive:true,force:true}));fs.mkdirSync(path.join(dir,'docs'));fs.mkdirSync(path.join(dir,'mirror'));
|
|
34
|
+
fs.writeFileSync(path.join(dir,'docs/input.md'),'Synthetic guide');fs.mkdirSync(path.join(dir,'1.guide'));
|
|
35
|
+
for(const doc of docs())fs.writeFileSync(path.join(dir,'1.guide',doc.path),doc.content,{mode:0o600});return dir;}
|
|
36
|
+
async function client(t,dir,respond,{session,change=true,review=false,abandon=false}={}){
|
|
37
|
+
const child=spawn(process.execPath,[path.join(root,'scripts/cm-prd-host.mjs'),'serve','--skill-dir',path.join(root,'skills/cm-prd'),
|
|
38
|
+
'--project',dir,'--specs',dir,'--runtime','codex','--allow-log-write','--allow-spec-write',
|
|
39
|
+
...(change?['--change','1.guide']:[]),...(session?['--session',session]:[]),
|
|
40
|
+
...(review?['--allow-review-write','--allow-disposition-write','--host-context','synthetic-author']:[]),
|
|
41
|
+
...(abandon?['--allow-review-abandon']:[])],
|
|
42
|
+
{env:{...process.env,CM_WORKFLOW_LOG_HOME:path.join(dir,'mirror')},stdio:['pipe','pipe','pipe']});
|
|
43
|
+
t.after(()=>{if(child.exitCode===null)child.kill();});let error='',sessionId,seq=0;
|
|
44
|
+
child.stderr.on('data',bytes=>error+=bytes);const pending=new Map();let readyResolve,readyReject;
|
|
45
|
+
const ready=new Promise((yes,no)=>{readyResolve=yes;readyReject=no;});
|
|
46
|
+
const send=value=>child.stdin.write(JSON.stringify(value)+'\n');
|
|
47
|
+
createInterface({input:child.stdout}).on('line',line=>{const message=JSON.parse(line);
|
|
48
|
+
if(message.type==='host_ready'){sessionId=message.sessionId;readyResolve();}
|
|
49
|
+
else if(message.type==='host_request')Promise.resolve().then(()=>respond(message,child)).then(result=>{
|
|
50
|
+
if(result!==undefined)send({type:'host_result',sessionId,callId:message.callId,requestDigest:message.requestDigest,result});
|
|
51
|
+
}).catch(readyReject);
|
|
52
|
+
else if(message.requestId&&pending.has(message.requestId)){pending.get(message.requestId)(message);pending.delete(message.requestId);}
|
|
53
|
+
});
|
|
54
|
+
child.on('close',code=>{if(!sessionId)readyReject(Error(error));for(const resolve of pending.values())resolve({closed:code,error});pending.clear();});
|
|
55
|
+
await ready;
|
|
56
|
+
return {stderr:()=>error,request:async(operation,fields={})=>{const requestId=`test-${++seq}`;return new Promise(resolve=>{
|
|
57
|
+
pending.set(requestId,resolve);send({requestId,operation,...fields});});},
|
|
58
|
+
close:async()=>{send({type:'host_close',sessionId});const [code]=await once(child,'close');assert.equal(code,0,error);}};
|
|
59
|
+
}
|
|
60
|
+
const stateOf=(dir,runId)=>JSON.parse(fs.readFileSync(path.join(dir,'.reviews/prd-sessions',runId,'state.json'),'utf8'));
|
|
61
|
+
const generate=payload=>{const all=revised(),full=payload.phase==='change_tasks';
|
|
62
|
+
return {status:full?'draft':'documents',summary:'Add example',features:[{directory:'1.guide',
|
|
63
|
+
documents:all.filter(doc=>full||doc.path==='requirements.md'||payload.phase==='change_design'&&doc.path==='design.md'),
|
|
64
|
+
...(full?{testCasesReason:'no_observable_behavior'}:{})}],removed:[]};};
|
|
65
|
+
|
|
66
|
+
test('O02: a recorded prd_generate answer the host refused is discarded and asked again',{timeout:30000},async t=>{
|
|
67
|
+
const dir=fixture(t);let bad=true,generated=0;
|
|
68
|
+
const respond=({kind,payload})=>{
|
|
69
|
+
if(kind==='prd_analyze')return {status:'analyzed',summary:'Add example',openQuestions:[]};
|
|
70
|
+
assert.equal(kind,'prd_generate');generated++;
|
|
71
|
+
// The refused shape: recorded first, validated after (features missing).
|
|
72
|
+
return bad?{status:'documents',summary:'Add example',removed:[]}:generate(payload);
|
|
73
|
+
};
|
|
74
|
+
let c=await client(t,dir,respond);
|
|
75
|
+
assert.equal((await c.request('start',{text:'Add example'})).result.stage,'change_requirements');
|
|
76
|
+
assert.ok((await c.request('advance',{text:'Requirements'})).error,'the refused answer fails the operation');
|
|
77
|
+
const {runId}=(await c.request('status')).result;await c.close();
|
|
78
|
+
let state=stateOf(dir,runId);const recorded=state.active.calls.at(-1);
|
|
79
|
+
assert.equal(recorded.kind,'prd_generate');assert.ok(Object.hasOwn(recorded,'result'));
|
|
80
|
+
c=await client(t,dir,respond,{session:runId});
|
|
81
|
+
// Before: a plain resume replays the same refused answer forever.
|
|
82
|
+
assert.ok((await c.request('resume',{resolution:null})).error);
|
|
83
|
+
assert.equal((await c.request('advance',{text:'again'})).result.reason,'prd_operation_recovery_required');
|
|
84
|
+
const resolution={callId:recorded.callId,requestDigest:recorded.requestDigest,discard:true,evidence:'会话答复缺 features,被宿主拒收'};
|
|
85
|
+
// prd_review / binding / evidence guards.
|
|
86
|
+
assert.equal((await c.request('resume',{resolution:{...resolution,requestDigest:'wrong'}})).result.reason,'prd_recovery_binding');
|
|
87
|
+
assert.equal((await c.request('resume',{resolution:{...resolution,evidence:' '}})).result.reason,'prd_recovery_evidence_required');
|
|
88
|
+
bad=false;
|
|
89
|
+
const reply=await c.request('resume',{resolution});
|
|
90
|
+
assert.equal(reply.result?.stage,'change_design',JSON.stringify(reply)+c.stderr());
|
|
91
|
+
assert.equal(generated,2,'asked again under the same pending operation');
|
|
92
|
+
state=stateOf(dir,runId);
|
|
93
|
+
assert.equal(state.active,null);assert.equal(state.discardedAnswers.length,1);
|
|
94
|
+
assert.deepEqual([state.discardedAnswers[0].kind,state.discardedAnswers[0].callId,state.discardedAnswers[0].operation],
|
|
95
|
+
['prd_generate',recorded.callId,'advance']);
|
|
96
|
+
await c.close();
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test('O05/O06: an unpublishable recorded split review is abandoned with --allow-review-abandon, then reviewed afresh',{timeout:40000},async t=>{
|
|
100
|
+
const dir=fixture(t);let reviews=0,degraded=true,conflict=false;
|
|
101
|
+
const respond=({kind,payload})=>{
|
|
102
|
+
if(kind==='prd_analyze')return {status:'analyzed',summary:'New documentation',sourcePaths:['docs/input.md'],openQuestions:[]};
|
|
103
|
+
if(kind==='prd_generate')return {status:'draft',summary:'New guide',features:[{name:'new-guide',documents:docs().map(doc=>({
|
|
104
|
+
...doc,content:doc.content.replace('[x]','[ ]')})),testCasesReason:'no_observable_behavior'}]};
|
|
105
|
+
if(kind==='prd_self_check')return {draftDigest:payload.draft.draftDigest,features:payload.draft.features.map(f=>({directory:f.directory,
|
|
106
|
+
checks:payload.draft.mechanicalSelfCheck.pending.map(id=>({id,status:'passed',evidence:['Synthetic original context check']}))}))};
|
|
107
|
+
assert.equal(kind,'prd_review');reviews++;
|
|
108
|
+
if(conflict)fs.mkdirSync(path.join(dir,'.reviews/prd-new-guide-split-r1.md'));
|
|
109
|
+
const result={verdict:'approved',packageDigest:payload.package.packageDigest,examinedPaths:payload.examinedPaths,findings:[],summary:'Synthetic no findings'};
|
|
110
|
+
// The prd-29b5f91e shape: an independent request answered self-degraded with a degradedReason.
|
|
111
|
+
return degraded?{reviewer:'self-degraded',contextId:'synthetic-author',independent:false,at:'2026-09-08T00:00:00.000Z',
|
|
112
|
+
result,degradedReason:'Synthetic reviewer unavailable'}
|
|
113
|
+
:{reviewer:'codex-subagent',contextId:'synthetic-independent',independent:true,at:'2026-09-08T00:00:00.000Z',result};
|
|
114
|
+
};
|
|
115
|
+
let c=await client(t,dir,respond,{change:false,review:true});
|
|
116
|
+
await c.request('start',{text:'New guide'});await c.request('advance',{text:'Draft'});await c.request('advance',{text:'Check'});
|
|
117
|
+
await c.request('save_draft');
|
|
118
|
+
const runId=(await c.request('status')).result.runId;
|
|
119
|
+
const initial=await c.request('final_review',{stage:'split',feature:'2.new-guide',mode:'independent'});
|
|
120
|
+
assert.equal(initial.result.reviewState.status,'review_unknown',JSON.stringify(initial));
|
|
121
|
+
await c.close();
|
|
122
|
+
const gateArgs={stage:'split',feature:'new-guide',evidence:path.join(dir,'.reviews/prd-new-guide-split-r1.md'),
|
|
123
|
+
receipt:path.join(dir,'.reviews/prd-new-guide-split-disposition.json')};
|
|
124
|
+
assert.equal(inspectPrdReview(gateArgs).outcome,'dispatch_unknown');
|
|
125
|
+
const call=stateOf(dir,runId).active.calls.find(item=>item.kind==='prd_review');
|
|
126
|
+
const resolution={callId:call.callId,requestDigest:call.requestDigest,abandonReview:true,evidence:'独立审查回成了 self-degraded,原结果不可发布'};
|
|
127
|
+
// Without the explicit flag the claim stays.
|
|
128
|
+
c=await client(t,dir,respond,{session:runId,change:false,review:true});
|
|
129
|
+
assert.equal((await c.request('resume',{resolution})).result.reason,'prd_review_abandon_not_enabled');await c.close();
|
|
130
|
+
c=await client(t,dir,respond,{session:runId,change:false,review:true,abandon:true});
|
|
131
|
+
const abandoned=await c.request('resume',{resolution});
|
|
132
|
+
assert.equal(abandoned.result?.recovery,null,JSON.stringify(abandoned)+c.stderr());
|
|
133
|
+
assert.equal(inspectPrdReview(gateArgs).outcome,'dispatch_once');
|
|
134
|
+
const record=JSON.parse(fs.readFileSync(path.join(dir,'.reviews/prd-new-guide-split-dispatch-abandoned-1.json'),'utf8'));
|
|
135
|
+
assert.deepEqual([record.status,record.call_id,record.reason],['abandoned',call.callId,resolution.evidence]);
|
|
136
|
+
assert.equal(stateOf(dir,runId).abandonedReviews.length,1);
|
|
137
|
+
// A fresh independent review is claimed, dispatched and published as the review evidence.
|
|
138
|
+
degraded=false;
|
|
139
|
+
const fresh=await c.request('final_review',{stage:'split',feature:'2.new-guide',mode:'independent'});
|
|
140
|
+
assert.equal(fresh.result.reviewState.status,'review_recorded',JSON.stringify(fresh));
|
|
141
|
+
assert.equal(reviews,2);assert.equal(fs.existsSync(path.join(dir,'.reviews/prd-new-guide-split-r2.md')),false);
|
|
142
|
+
assert.equal(inspectPrdReview(gateArgs).outcome,'resume_disposition');
|
|
143
|
+
await c.close();
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test('O05/O06: a recorded review that would publish is never abandoned',{timeout:40000},async t=>{
|
|
147
|
+
const dir=fixture(t);let conflicted=false;
|
|
148
|
+
const respond=({kind,payload})=>{
|
|
149
|
+
if(kind==='prd_analyze')return {status:'analyzed',summary:'New documentation',sourcePaths:['docs/input.md'],openQuestions:[]};
|
|
150
|
+
if(kind==='prd_generate')return {status:'draft',summary:'New guide',features:[{name:'new-guide',documents:docs().map(doc=>({
|
|
151
|
+
...doc,content:doc.content.replace('[x]','[ ]')})),testCasesReason:'no_observable_behavior'}]};
|
|
152
|
+
if(kind==='prd_self_check')return {draftDigest:payload.draft.draftDigest,features:payload.draft.features.map(f=>({directory:f.directory,
|
|
153
|
+
checks:payload.draft.mechanicalSelfCheck.pending.map(id=>({id,status:'passed',evidence:['Synthetic original context check']}))}))};
|
|
154
|
+
// A valid independent review whose publication fails (the evidence path is taken).
|
|
155
|
+
if(!conflicted){conflicted=true;fs.mkdirSync(path.join(dir,'.reviews/prd-new-guide-split-r1.md'));}
|
|
156
|
+
return {reviewer:'codex-subagent',contextId:'synthetic-independent',independent:true,at:'2026-09-08T00:00:00.000Z',
|
|
157
|
+
result:{verdict:'approved',packageDigest:payload.package.packageDigest,examinedPaths:payload.examinedPaths,findings:[],summary:'Synthetic no findings'}};
|
|
158
|
+
};
|
|
159
|
+
let c=await client(t,dir,respond,{change:false,review:true,abandon:true});
|
|
160
|
+
await c.request('start',{text:'New guide'});await c.request('advance',{text:'Draft'});await c.request('advance',{text:'Check'});
|
|
161
|
+
await c.request('save_draft');
|
|
162
|
+
const runId=(await c.request('status')).result.runId;
|
|
163
|
+
assert.equal((await c.request('final_review',{stage:'split',feature:'2.new-guide',mode:'independent'})).result.reviewState.status,'review_unknown');
|
|
164
|
+
const call=stateOf(dir,runId).active.calls.find(item=>item.kind==='prd_review');
|
|
165
|
+
const before=stateOf(dir,runId);
|
|
166
|
+
const refused=await c.request('resume',{resolution:{callId:call.callId,requestDigest:call.requestDigest,abandonReview:true,evidence:'想换一个审查'}});
|
|
167
|
+
assert.equal(refused.result.reason,'prd_review_result_publishable');
|
|
168
|
+
assert.deepEqual(stateOf(dir,runId),before);
|
|
169
|
+
assert.equal(fs.readdirSync(path.join(dir,'.reviews')).some(name=>name.includes('dispatch-abandoned')),false);
|
|
170
|
+
await c.close();
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
test('O02: at most two discards per call kind in a session; prd_review and prd_correct are never discarded',async t=>{
|
|
174
|
+
const dir=fixture(t),session=openPrdSession({specs:dir,sessionId:'prd-discard-cap',identity:{entry:{fixture:true},runtime:'codex'}});
|
|
175
|
+
try{
|
|
176
|
+
session.begin({requestId:'one',operation:'advance',text:'x'},null);
|
|
177
|
+
const discard=call=>session.discardAnswer({callId:call.callId,requestDigest:call.requestDigest,discard:true,evidence:'被宿主拒收'});
|
|
178
|
+
for(let index=0;index<2;index++){
|
|
179
|
+
await session.call('prd_generate',{n:index},new AbortController().signal,async()=>({bad:true}));
|
|
180
|
+
discard(session.state.active.calls.at(-1));
|
|
181
|
+
}
|
|
182
|
+
await session.call('prd_generate',{n:3},new AbortController().signal,async()=>({bad:true}));
|
|
183
|
+
assert.throws(()=>discard(session.state.active.calls.at(-1)),{code:'prd_answer_discard_limit'});
|
|
184
|
+
assert.equal(session.state.discardedAnswers.length,2);
|
|
185
|
+
}finally{session.close();}
|
|
186
|
+
const other=openPrdSession({specs:dir,sessionId:'prd-discard-review',identity:{entry:{fixture:true},runtime:'codex'}});
|
|
187
|
+
try{
|
|
188
|
+
other.begin({requestId:'two',operation:'final_review',stage:'split',feature:'1.guide',mode:'independent'},null);
|
|
189
|
+
await other.call('prd_review',{package:{packageDigest:'0'.repeat(64)}},new AbortController().signal,async()=>({reviewer:'x'}));
|
|
190
|
+
const call=other.state.active.calls[0];
|
|
191
|
+
assert.throws(()=>other.discardAnswer({callId:call.callId,requestDigest:call.requestDigest,discard:true,evidence:'x'}),{code:'prd_review_recovery_required'});
|
|
192
|
+
}finally{other.close();}
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
test('O05/O06: the gate finishes a release interrupted after the abandoned record, without a new record or slot',async t=>{
|
|
196
|
+
const {claimPrdReview,abandonPrdReviewAttempt}=await import('./cm-prd-review-gate.mjs');
|
|
197
|
+
const dir=fixture(t),reviews=path.join(dir,'.reviews');fs.mkdirSync(reviews,{mode:0o700});
|
|
198
|
+
const args={stage:'split',feature:'guide',evidence:path.join(reviews,'prd-guide-split-r1.md'),receipt:path.join(reviews,'prd-guide-split-disposition.json')};
|
|
199
|
+
const dispatch=path.join(reviews,'prd-guide-split-dispatch.json');
|
|
200
|
+
for(const [index,call] of ['call-1','call-2'].entries()){
|
|
201
|
+
claimPrdReview({...args,package_sha256:String(index+1).repeat(64)});
|
|
202
|
+
const claim=fs.readFileSync(dispatch);
|
|
203
|
+
assert.equal(abandonPrdReviewAttempt({...args,call_id:call,reason:'原审查不可用'}).outcome,'abandoned');
|
|
204
|
+
// Simulate the crash window: the record is durable, the claim is back.
|
|
205
|
+
fs.writeFileSync(dispatch,claim,{mode:0o600});
|
|
206
|
+
assert.equal(inspectPrdReview(args).outcome,'dispatch_unknown');
|
|
207
|
+
const resumed=abandonPrdReviewAttempt({...args,call_id:call,reason:'原审查不可用'});
|
|
208
|
+
assert.deepEqual([resumed.outcome,resumed.abandoned],['release_completed',index+1]);
|
|
209
|
+
assert.equal(inspectPrdReview(args).outcome,'dispatch_once');
|
|
210
|
+
}
|
|
211
|
+
assert.deepEqual(fs.readdirSync(reviews).filter(name=>name.includes('abandoned')).sort(),
|
|
212
|
+
['prd-guide-split-dispatch-abandoned-1.json','prd-guide-split-dispatch-abandoned-2.json']);
|
|
213
|
+
// A different call on a new claim still meets the cap.
|
|
214
|
+
claimPrdReview({...args,package_sha256:'3'.repeat(64)});
|
|
215
|
+
assert.throws(()=>abandonPrdReviewAttempt({...args,call_id:'call-3',reason:'x'}),{code:'prd_review_abandon_limit'});
|
|
216
|
+
});
|
package/scripts/cm-prd-drive.mjs
CHANGED
|
@@ -79,7 +79,7 @@ function load(){
|
|
|
79
79
|
catch(e){fail('准入或配置无效',e.code??e.message);}
|
|
80
80
|
if(admission.status!=='ready'&&!(plan.session&&admission.mode==='change'&&admission.reason==='feature_missing'))
|
|
81
81
|
fail('准入失败',admission.reason??admission.status);
|
|
82
|
-
if(!Array.isArray(plan.permissions??[])||!(plan.permissions??[]).every(p=>['--execution-optimizations','--allow-spec-write','--allow-review-write','--allow-disposition-write'].includes(p)))
|
|
82
|
+
if(!Array.isArray(plan.permissions??[])||!(plan.permissions??[]).every(p=>['--execution-optimizations','--allow-spec-write','--allow-review-write','--allow-disposition-write','--allow-review-abandon'].includes(p)))
|
|
83
83
|
stop(2,'permissions 只能包含宿主支持的写入开关');
|
|
84
84
|
if(new Set(plan.permissions??[]).size!==(plan.permissions??[]).length)stop(2,'permissions 不可重复');
|
|
85
85
|
if(plan.predecessor&&!fs.existsSync(resolve(plan.predecessor)))stop(2,`predecessor 文件不存在: ${resolve(plan.predecessor)}`);
|
|
@@ -137,14 +137,25 @@ function load(){
|
|
|
137
137
|
if(operation==='resume'){
|
|
138
138
|
if(!Object.hasOwn(request,'resolution'))stop(2,'resume 缺少 PLAN.request.resolution(null 或绑定的回执)');
|
|
139
139
|
if(request.resolution!==null){
|
|
140
|
-
const v=request.resolution;exact(v,['callId','requestDigest','result','evidence','abandon'],'resolution');
|
|
140
|
+
const v=request.resolution;exact(v,['callId','requestDigest','result','evidence','abandon','discard','abandonReview'],'resolution');
|
|
141
141
|
const pending=state.active.calls.find(c=>c.callId===v.callId);
|
|
142
|
-
|
|
142
|
+
// discard: re-ask the last recorded answer the host refused (its answer file is preflighted below).
|
|
143
|
+
if(v.discard===true){
|
|
144
|
+
if(!pending||pending.requestDigest!==v.requestDigest||!nonempty(v.evidence)||Object.hasOwn(v,'result')
|
|
145
|
+
||!Object.hasOwn(pending,'result')||state.active.calls.at(-1)!==pending||['prd_review','prd_correct'].includes(pending.kind))
|
|
146
|
+
stop(2,'discard 只能作废最后一个已记录且被拒的应答(不含 prd_review、prd_correct),需要 callId/requestDigest/evidence');
|
|
147
|
+
}else if(v.abandonReview===true){
|
|
148
|
+
if(!pending||pending.kind!=='prd_review'||pending.requestDigest!==v.requestDigest||!nonempty(v.evidence)||Object.hasOwn(v,'result')
|
|
149
|
+
||!plan.permissions?.includes('--allow-review-write')||!plan.permissions?.includes('--allow-review-abandon'))
|
|
150
|
+
stop(2,'abandonReview 需要 prd_review 的 callId/requestDigest/evidence,以及 --allow-review-write 与 --allow-review-abandon');
|
|
151
|
+
}else if(!pending||pending.requestDigest!==v.requestDigest||!nonempty(v.evidence)
|
|
143
152
|
||Object.hasOwn(pending,'result')||(v.abandon===true?Object.hasOwn(v,'result'):!Object.hasOwn(v,'result')))
|
|
144
153
|
stop(2,'resume 缺少有效 callId/requestDigest/result/evidence 绑定');
|
|
145
154
|
if(v.abandon===true&&state.active.calls.some(c=>c.kind==='prd_review'))stop(2,'prd_review 不可 abandon');
|
|
155
|
+
// O03: a late original result for execution evidence cannot be relayed from a static file;
|
|
156
|
+
// abandon the operation and send it again, so the evidence is produced afresh (live runner / contextChecks).
|
|
146
157
|
if(v.abandon!==true&&['prd_materials','prd_self_check'].includes(pending.kind))
|
|
147
|
-
stop(2,`resume 的 ${pending.kind} 是执行证据,不能从静态 resolution.result
|
|
158
|
+
stop(2,`resume 的 ${pending.kind} 是执行证据,不能从静态 resolution.result 应答;改用 resolution {callId,requestDigest,abandon:true,evidence} 放弃原操作,再重发同一操作(${pending.kind==='prd_materials'?'PLAN.liveEvidence 实时读取材料':'PLAN.contextChecks 重新执行检查'})`);
|
|
148
159
|
}
|
|
149
160
|
}
|
|
150
161
|
if(operation==='replace_inputs'){
|
|
@@ -170,12 +181,14 @@ function load(){
|
|
|
170
181
|
asks.push('prd_materials');asks.push('prd_analyze');}
|
|
171
182
|
}
|
|
172
183
|
if(operation==='final_review')asks.push('prd_review');
|
|
184
|
+
if(operation==='resume'&&request.resolution?.discard===true)
|
|
185
|
+
asks.push(state.active.calls.find(c=>c.callId===request.resolution.callId).kind);
|
|
173
186
|
if(operation==='correct_findings')asks.push('prd_correct');
|
|
174
187
|
if(operation==='prepare_summary')asks.push('prd_summary');
|
|
175
188
|
if(operation==='review_disposition'&&request.stage==='split'&&request.decisions.some(d=>d.status==='applied'))asks.push('prd_self_check');
|
|
176
189
|
if(operation==='resume'&&request.resolution===null){
|
|
177
190
|
const pending=state.active.calls.find(c=>!Object.hasOwn(c,'result'));
|
|
178
|
-
if(pending)stop(2,`resume 尚缺原调用结果:${pending.kind} ${pending.callId} ${pending.requestDigest}
|
|
191
|
+
if(pending)stop(2,`resume 尚缺原调用结果:${pending.kind} ${pending.callId} ${pending.requestDigest};找到原回执就填 resolution.result,找不到且不含 prd_review 时用 abandon:true 放弃后重发原操作`);
|
|
179
192
|
}
|
|
180
193
|
let live;
|
|
181
194
|
try{live=driverLiveEvidence(plan,{base,protectedRoots:[project,specs],allowedKinds:['prd_materials']});}
|
|
@@ -177,3 +177,18 @@ test('real host unknown call resumes with its original callId and requestDigest'
|
|
|
177
177
|
assert.equal(resumed.status,0,resumed.stderr);assert.equal(resumed.json.result.stage,'analysis_ready');
|
|
178
178
|
assert.equal(JSON.parse(fs.readFileSync(f.store(session))).active,null);
|
|
179
179
|
});
|
|
180
|
+
|
|
181
|
+
// O03: a late original result for execution evidence is never relayed from a static
|
|
182
|
+
// file; the driver names the exit (abandon, then send the operation again).
|
|
183
|
+
test('resume with a static result for pending self-check evidence points to abandon and a fresh run',t=>{
|
|
184
|
+
const f=fixture(t);f.write('analyze.json',analyzed);
|
|
185
|
+
const started=f.drive('start');assert.equal(started.status,0,started.stderr);
|
|
186
|
+
const runId=started.json.result.runId,store=f.store(runId),state=JSON.parse(fs.readFileSync(store,'utf8'));
|
|
187
|
+
state.active={request:{requestId:'drive',operation:'advance',text:'Check'},before:state.checkpoint,
|
|
188
|
+
calls:[{kind:'prd_self_check',callId:'call-1',requestDigest:'0'.repeat(64),payload:{}}]};
|
|
189
|
+
fs.writeFileSync(store,JSON.stringify(state),{mode:0o600});
|
|
190
|
+
const run=f.drive('resume',{session:runId,request:{resolution:{callId:'call-1',requestDigest:'0'.repeat(64),result:{},evidence:'late'}}});
|
|
191
|
+
assert.equal(run.status,2);assert.match(run.stderr,/abandon:true/);assert.match(run.stderr,/contextChecks/);
|
|
192
|
+
const missing=f.drive('resume',{session:runId,request:{resolution:null}});
|
|
193
|
+
assert.equal(missing.status,2);assert.match(missing.stderr,/abandon:true 放弃后重发原操作/);
|
|
194
|
+
});
|
package/scripts/cm-prd-host.mjs
CHANGED
|
@@ -21,14 +21,18 @@ import {serveCmAiHost} from '../runtime/js/cm-ai/host-session.mjs';
|
|
|
21
21
|
import {need,shape,json,id,digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
22
22
|
import {openPrdSession} from '../runtime/js/cm-prd/session.mjs';
|
|
23
23
|
import {createPrdChange,assertPrdReviewsSettled} from '../runtime/js/cm-prd/change.mjs';
|
|
24
|
-
import {publishPrdReview} from '../runtime/js/cm-prd/review-publication.mjs';
|
|
24
|
+
import {publishPrdReview,inspectPrdReviewResponse} from '../runtime/js/cm-prd/review-publication.mjs';
|
|
25
|
+
import {abandonPrdReviewAttempt} from './cm-prd-review-gate.mjs';
|
|
25
26
|
|
|
26
27
|
const sessionFailureCodes=new Set(['prd_operation_recovery_required','prd_host_result_unknown','prd_nothing_to_resume',
|
|
27
28
|
'prd_recovery_binding','prd_recovery_evidence_required','prd_replay_inputs_changed','cancelled','prd_turn_not_ready',
|
|
28
29
|
'prd_review_recovery_required','prd_batch_inputs_replaced','prd_inputs_changed','prd_replacement_authorization_required',
|
|
29
30
|
'prd_inputs_not_changed','prd_successor_not_fresh','prd_replacement_conflict','prd_replacement_not_ready',
|
|
30
31
|
'execution_policy_required','execution_policy_legacy_run','prd_response_already_canonical',
|
|
31
|
-
'prd_predecessor_binding','prd_successor_inputs_changed'
|
|
32
|
+
'prd_predecessor_binding','prd_successor_inputs_changed',
|
|
33
|
+
'prd_answer_discard_limit','prd_correction_recovery_required','prd_review_abandon_not_enabled','prd_review_result_publishable',
|
|
34
|
+
'prd_review_abandon_unavailable','prd_review_abandon_limit','prd_review_abandon_reason_required','prd_review_abandon_binding',
|
|
35
|
+
'prd_correction_recovery_conflict']);
|
|
32
36
|
|
|
33
37
|
export async function main(argv=process.argv.slice(2),{input=process.stdin,output=process.stdout,error=process.stderr}={}){
|
|
34
38
|
let bridge,analysis,session,change=null,started=false,closed=false,record;
|
|
@@ -37,6 +41,7 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
37
41
|
output.write('replace_inputs {requestId,operation,approved:true,reason,successorSpecs,successorSessionId} ends a changed-input batch with immutable history; read_batch/status remain available. Start the bound fresh specs root with --session SUCCESSOR_ID --predecessor ABSOLUTE_RECEIPT_PATH. No approvals transfer.\n');
|
|
38
42
|
output.write('New and --change SELECTOR share this host. --session prd-ID resumes a durable local conversation; obtain runId from status. resume {requestId,operation,resolution:null|{callId,requestDigest,result,evidence}} consumes only the original host result, never re-dispatches an unknown call. decision {requestId,operation,proposalDigest,approved,allowUserCaseChanges} confirms an exact change proposal; save_draft archives and writes awaiting_review. prepare_revision {requestId,operation,reason} revises the saved current batch with original review history retained; no review counters reset.\n');
|
|
39
43
|
output.write('resume also accepts resolution:{callId,requestDigest,abandon:true,evidence} with result absent: discard the entire pending operation and restore its before checkpoint, only if no call is prd_review. Explicit cancel is terminal: checkpoint cancelled and active cleared; resume cannot continue it. Session failures return {status:blocked,reason,recovery,completionAuthorized:false} (2026-09-17 dogfood: cancelled checkpoint retained active and hid recovery errors).\n');
|
|
44
|
+
output.write('resume resolution:{callId,requestDigest,discard:true,evidence} discards the last RECORDED answer the host then refused (not prd_review/prd_correct), keeps an append-only discardedAnswers record and asks that call again under the same pending operation; at most 2 per call kind in a session. resolution:{callId,requestDigest,abandonReview:true,evidence} needs --allow-review-write and --allow-review-abandon: only for a pending final_review whose prd_review result was lost or fails publication, it releases the gate claim into prd-<feature>-<stage>-dispatch-abandoned-N.json (at most 2 per feature and stage), records abandonedReviews and restores the before checkpoint; then send final_review again for a fresh independent review. A recorded result that would publish is never abandoned.\n');
|
|
40
45
|
output.write('promote_design {requestId,operation,draftDigest,reason} moves an unreviewed full draft to design while preserving draft and self-check rounds. Saved drafts require complete exact original bytes with private permissions; partial/conflicting saves, prior review and exhausted rounds are rejected. Saved task revisions archive both versions before replacement; no approval is implied.\n');
|
|
41
46
|
output.write('select_design_reviews {requestId,operation,draftDigest,risks:[{feature,signals,evidence}]} at design_ready freezes host-reported Step 9.5 risks for every feature. Only high-risk features may request design review; low-risk exact saved designs continue without it. Not approval; existing attempts cannot be downgraded.\n');
|
|
42
47
|
output.write('plan_design {requestId,operation,text} generates requirements/design only. design_ready permits save_design with --allow-spec-write and original design review. After original design disposition, advance generates tasks from the exact current design, then original self-check/save_draft. No approval is implied.\n');
|
|
@@ -48,11 +53,13 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
48
53
|
const reviewEnabled=argv.includes('--allow-review-write');
|
|
49
54
|
const dispositionEnabled=argv.includes('--allow-disposition-write');
|
|
50
55
|
const specWriteEnabled=argv.includes('--allow-spec-write');
|
|
56
|
+
const reviewAbandonEnabled=argv.includes('--allow-review-abandon');
|
|
57
|
+
need(argv.filter(x=>x==='--allow-review-abandon').length<=1&&(!reviewAbandonEnabled||reviewEnabled),'invalid_arguments');
|
|
51
58
|
need(argv.filter(x=>x==='--allow-spec-write').length<=1,'invalid_arguments');
|
|
52
59
|
need(argv.filter(x=>x==='--allow-disposition-write').length<=1,'invalid_arguments');
|
|
53
60
|
need(argv.filter(x=>x==='--allow-review-write').length<=1,'invalid_arguments');
|
|
54
61
|
need(argv.filter(x=>x==='--execution-optimizations').length<=1,'invalid_arguments');
|
|
55
|
-
const args=argv.slice(1).filter(x=>!['--execution-optimizations','--allow-log-write','--allow-review-write','--allow-disposition-write','--allow-spec-write'].includes(x)),options={};
|
|
62
|
+
const args=argv.slice(1).filter(x=>!['--execution-optimizations','--allow-log-write','--allow-review-write','--allow-disposition-write','--allow-spec-write','--allow-review-abandon'].includes(x)),options={};
|
|
56
63
|
for(let i=0;i<args.length;i+=2){
|
|
57
64
|
need(['--skill-dir','--project','--specs','--runtime','--cases','--host-context','--change','--session','--predecessor'].includes(args[i])
|
|
58
65
|
&&!Object.hasOwn(options,args[i])&&typeof args[i+1]==='string','invalid_arguments');
|
|
@@ -279,12 +286,38 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
279
286
|
shape(request,['requestId','operation','resolution']);
|
|
280
287
|
need(!reviewController.signal.aborted&&session.state.checkpoint?.analysis?.stage!=='cancelled'
|
|
281
288
|
&&session.state.checkpoint?.change?.stage!=='cancelled','cancelled');
|
|
289
|
+
if(request.resolution?.discard===true){
|
|
290
|
+
const {operation:discardedOperation,kind,callId,evidence}=session.discardAnswer(request.resolution);
|
|
291
|
+
record({event:'decision',phase:'recovery',data:{operation:discardedOperation,kind,callId,evidence,outcome:'answer_discarded'}});
|
|
292
|
+
}else if(request.resolution?.abandonReview===true){
|
|
293
|
+
need(reviewAbandonEnabled,'prd_review_abandon_not_enabled');
|
|
294
|
+
const active=session.state.active,call=active?.calls.find(item=>item.callId===request.resolution.callId);
|
|
295
|
+
need(active?.request.operation==='final_review'&&call?.kind==='prd_review'
|
|
296
|
+
&&call.requestDigest===request.resolution.requestDigest,'prd_recovery_binding');
|
|
297
|
+
// A recorded result that would publish must be published (plain resume), never re-reviewed.
|
|
298
|
+
if(Object.hasOwn(call,'result')){
|
|
299
|
+
let publishable=true;
|
|
300
|
+
try{const response=session.reviewResponse(call),{packageDigest,...reviewPackage}=call.payload.package;
|
|
301
|
+
validatePrdReviewMode(active.request.mode,response);
|
|
302
|
+
inspectPrdReviewResponse({reviewPackage,packageDigest,authorContextId:call.payload.authorContextId,response});}
|
|
303
|
+
catch{publishable=false;}
|
|
304
|
+
need(!publishable,'prd_review_result_publishable');
|
|
305
|
+
}
|
|
306
|
+
const slug=active.request.feature.replace(/^\d+\./,''),prefix=path.join(admission.specs,'.reviews',`prd-${slug}-${active.request.stage}`);
|
|
307
|
+
const gate=abandonPrdReviewAttempt({stage:active.request.stage,feature:slug,evidence:`${prefix}-r1.md`,
|
|
308
|
+
receipt:`${prefix}-disposition.json`,call_id:call.callId,reason:request.resolution.evidence});
|
|
309
|
+
const {kind,callId,evidence}=session.abandonReview(request.resolution);
|
|
310
|
+
restore(session.state.checkpoint);replaying=false;reviewState=null;
|
|
311
|
+
record({event:'decision',phase:'recovery',data:{operation:'final_review',kind,callId,evidence,
|
|
312
|
+
outcome:'review_attempt_abandoned',abandoned:gate.abandoned}});
|
|
313
|
+
session.commit(checkpoint());return status();
|
|
314
|
+
}
|
|
282
315
|
if(request.resolution?.abandon===true){
|
|
283
316
|
const decision=session.abandon(request.resolution);
|
|
284
317
|
restore(session.state.checkpoint);replaying=false;
|
|
285
318
|
record({event:'decision',phase:'recovery',data:decision});return status();
|
|
286
319
|
}
|
|
287
|
-
if(request.resolution!==null)session.resolve(request.resolution);
|
|
320
|
+
if(request.resolution!==null&&request.resolution.discard!==true)session.resolve(request.resolution);
|
|
288
321
|
const active=session.replay();
|
|
289
322
|
replayCallIndex=0;
|
|
290
323
|
need(active.calls.every(call=>Object.hasOwn(call,'result')),'prd_host_result_unknown');
|
|
@@ -167,7 +167,12 @@ for(const mode of ['saved','partial','drift','outside','completed-task','cancell
|
|
|
167
167
|
assert.equal(fresh.status,0,fresh.stderr);assert.equal(JSON.parse(fresh.stdout).status,'correction_saved');
|
|
168
168
|
assert.equal(calls,1);assert.match(fs.readFileSync(path.join(args.specs,design.path),'utf8'),/Clarified/);
|
|
169
169
|
fs.appendFileSync(path.join(args.specs,design.path),'\nUser edit');
|
|
170
|
-
|
|
170
|
+
// V6: inspection lists the conflicting file for a person; resuming refuses and writes nothing.
|
|
171
|
+
const conflict=inspectPrdCorrectionRecovery(input),row=conflict.states.find(item=>item.path===design.path);
|
|
172
|
+
assert.equal(conflict.status,'correction_recovery_conflict');assert.equal(row.status,'conflict');assert.ok(row.currentSha256&&row.correctedSha256);
|
|
173
|
+
const edited=fs.readFileSync(path.join(args.specs,design.path),'utf8');
|
|
174
|
+
assert.throws(()=>resumePrdCorrection({...input,writeEnabled:true},new AbortController().signal),/prd_correction_recovery_conflict/);
|
|
175
|
+
assert.equal(fs.readFileSync(path.join(args.specs,design.path),'utf8'),edited);
|
|
171
176
|
}
|
|
172
177
|
assert.equal(fs.existsSync(receipt),false);
|
|
173
178
|
});
|
|
@@ -206,6 +206,62 @@ export function claimPrdReview(args){
|
|
|
206
206
|
return {stage:args.stage,feature:args.feature,outcome:'dispatch_claimed',dispatch_record:file,
|
|
207
207
|
package_sha256:args.package_sha256,providerAuthorized:false,completionAuthorized:false};
|
|
208
208
|
}
|
|
209
|
+
// V5 (O05/O06): release one interrupted attempt so a fresh independent review
|
|
210
|
+
// can be claimed. Only while the claim has no r1 evidence (dispatch_unknown);
|
|
211
|
+
// the claim moves to an append-only abandoned record carrying the operator
|
|
212
|
+
// reason and the abandoned session call, and at most MAX_PRD_REVIEW_ABANDONS
|
|
213
|
+
// attempts per feature and stage are released. Repeating it for the same call
|
|
214
|
+
// after the claim already moved is a no-op, so a host that died between this
|
|
215
|
+
// and its session record can finish. JS host contract only; the CLI and its
|
|
216
|
+
// Python oracle keep their inspect/claim/record commands unchanged.
|
|
217
|
+
export const MAX_PRD_REVIEW_ABANDONS=2;
|
|
218
|
+
const abandonedFile=(evidence,index)=>evidence.replace(/-r1\.md$/,`-dispatch-abandoned-${index}.json`);
|
|
219
|
+
function releaseClaim(file,directory){
|
|
220
|
+
fs.unlinkSync(file);
|
|
221
|
+
if(process.platform!=='win32'){
|
|
222
|
+
const directoryFd=fs.openSync(directory,'r');try{fs.fsyncSync(directoryFd);}finally{fs.closeSync(directoryFd);}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
export function abandonPrdReviewAttempt(args){
|
|
226
|
+
const {evidence}=paths(args),directory=path.dirname(evidence),file=dispatchFile(evidence);
|
|
227
|
+
need(typeof args.call_id==='string'&&/^[A-Za-z0-9-]{1,128}$/.test(args.call_id),'invalid call id','prd_review_abandon_binding');
|
|
228
|
+
need(typeof args.reason==='string'&&strip(args.reason).length>0&&args.reason.length<=2000&&!/[\r\n\0]/.test(args.reason),
|
|
229
|
+
'abandon reason required','prd_review_abandon_reason_required');
|
|
230
|
+
const existing=[];
|
|
231
|
+
for(let index=1;index<=MAX_PRD_REVIEW_ABANDONS;index++){
|
|
232
|
+
const record=abandonedFile(evidence,index);if(!stat(record))break;
|
|
233
|
+
need(!link(record),'unsafe PRD abandon record','prd_review_dispatch_invalid',()=>({dispatch:reviewFile(record)}));
|
|
234
|
+
existing.push(parseJson(read(record,'prd_review_dispatch_invalid',{dispatch:reviewFile(record)}),'prd_review_dispatch_invalid',{dispatch:reviewFile(record)}));
|
|
235
|
+
}
|
|
236
|
+
const gate=inspectPrdReview(args);
|
|
237
|
+
if(gate.outcome==='dispatch_once'&&existing.some(item=>item.call_id===args.call_id))
|
|
238
|
+
return {stage:args.stage,feature:args.feature,outcome:'already_abandoned',abandoned:existing.length};
|
|
239
|
+
need(gate.outcome==='dispatch_unknown','only an unpublished claimed attempt can be abandoned','prd_review_abandon_unavailable',
|
|
240
|
+
()=>({dispatch:reviewFile(file)}));
|
|
241
|
+
const dispatch=loadDispatch(file,args);
|
|
242
|
+
// Crash window: the abandoned record is durable but the claim was not yet
|
|
243
|
+
// removed. The same call and the same claim finish that release; no new
|
|
244
|
+
// record is appended and no slot is spent.
|
|
245
|
+
const pending=existing.findIndex(item=>item.call_id===args.call_id&&item.package_sha256===dispatch.package_sha256
|
|
246
|
+
&&item.dispatch_at===dispatch.at&&item.stage===args.stage&&item.feature===args.feature&&item.status==='abandoned');
|
|
247
|
+
if(pending!==-1){
|
|
248
|
+
releaseClaim(file,directory);
|
|
249
|
+
need(inspectPrdReview(args).outcome==='dispatch_once','PRD review claim was not released','prd_review_abandon_unavailable');
|
|
250
|
+
return {stage:args.stage,feature:args.feature,outcome:'release_completed',abandoned:pending+1,record:abandonedFile(evidence,pending+1),
|
|
251
|
+
providerAuthorized:false,completionAuthorized:false};
|
|
252
|
+
}
|
|
253
|
+
need(existing.length<MAX_PRD_REVIEW_ABANDONS,'PRD review abandon limit reached','prd_review_abandon_limit',
|
|
254
|
+
()=>({dispatch:reviewFile(file)}));
|
|
255
|
+
const index=existing.length+1,record=abandonedFile(evidence,index);
|
|
256
|
+
const value={schema_version:1,stage:args.stage,feature:args.feature,package_sha256:dispatch.package_sha256,
|
|
257
|
+
dispatch_at:dispatch.at,status:'abandoned',call_id:args.call_id,reason:args.reason,at:new Date().toISOString()};
|
|
258
|
+
const fd=fs.openSync(record,'wx',0o600);
|
|
259
|
+
try{fs.writeFileSync(fd,JSON.stringify(value)+'\n');fs.fsyncSync(fd);}finally{fs.closeSync(fd);}
|
|
260
|
+
releaseClaim(file,directory);
|
|
261
|
+
need(inspectPrdReview(args).outcome==='dispatch_once','PRD review claim was not released','prd_review_abandon_unavailable');
|
|
262
|
+
return {stage:args.stage,feature:args.feature,outcome:'abandoned',abandoned:index,record,
|
|
263
|
+
providerAuthorized:false,completionAuthorized:false};
|
|
264
|
+
}
|
|
209
265
|
export function inspectPrdReview(args){
|
|
210
266
|
const {evidence,receipt}=paths(args);
|
|
211
267
|
const dispatch=loadDispatch(dispatchFile(evidence),args);
|