@aibyzero/cm-workflow 0.21.4 → 0.21.5
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 +6 -0
- package/README.md +2 -2
- package/VERSION +1 -1
- package/docs/installation.md +1 -1
- package/docs/js-workflow-control.md +1 -0
- package/package.json +1 -1
- package/runtime/js/cm-ai/host-session.mjs +1 -1
- package/runtime/js/cm-prd/accepted-design.mjs +4 -0
- package/runtime/js/cm-prd/disposition-plan.mjs +4 -2
- package/runtime/js/cm-prd/narrow-review.mjs +210 -0
- package/runtime/js/cm-prd/review-correction.mjs +161 -8
- package/runtime/js/cm-prd/review-disposition.mjs +8 -1
- package/runtime/js/cm-prd/review-findings.mjs +8 -0
- package/runtime/js/notify.mjs +1 -0
- package/scripts/ci-test-weights.json +1 -0
- package/scripts/cm-prd-design-phase.test.mjs +36 -4
- package/scripts/cm-prd-drive.mjs +12 -6
- package/scripts/cm-prd-host.mjs +15 -5
- package/scripts/cm-prd-narrow-review.test.mjs +429 -0
- package/scripts/cm-prd-review-gate.mjs +3 -0
- package/skills/cm-prd/SKILL.md +1 -0
- package/skills/cm-prd/references/js-change-recovery.md +2 -0
- package/skills/cm-prd/references/js-host.md +17 -2
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import {createHash} from 'node:crypto';
|
|
7
|
+
import {preparePrdReview} from '../runtime/js/cm-prd/review-preparation.mjs';
|
|
8
|
+
import {publishPrdReview} from '../runtime/js/cm-prd/review-publication.mjs';
|
|
9
|
+
import {recordPrdHostDisposition} from '../runtime/js/cm-prd/review-disposition.mjs';
|
|
10
|
+
import {createPrdCorrectionOwner,inspectPrdNarrowReview,recordPrdNarrowReviewHost} from '../runtime/js/cm-prd/review-correction.mjs';
|
|
11
|
+
import {claimPrdReview,recordPrdReview} from './cm-prd-review-gate.mjs';
|
|
12
|
+
import {narrowCorrectionBytes} from '../runtime/js/cm-prd/narrow-review.mjs';
|
|
13
|
+
import {inspectPrdFindings} from '../runtime/js/cm-prd/review-findings.mjs';
|
|
14
|
+
|
|
15
|
+
const sha=content=>createHash('sha256').update(content).digest('hex');
|
|
16
|
+
const AUTHOR='author',FEATURE='1.guide',signal=()=>new AbortController().signal;
|
|
17
|
+
// Design-stage fixture: original r1 with finding R1, files saved with private permissions.
|
|
18
|
+
function fixture(t){
|
|
19
|
+
const specs=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-prd-narrow-')));
|
|
20
|
+
t.after(()=>fs.rmSync(specs,{recursive:true,force:true}));fs.mkdirSync(path.join(specs,'.reviews'));
|
|
21
|
+
const documents=[{path:'requirements.md',content:'## 功能需求\n1. [F-001] Guide\n- [ ] [AC-001] Document setup.'},
|
|
22
|
+
{path:'design.md',content:'## 方案摘要\nDocumentation V1'}];
|
|
23
|
+
const prepared=preparePrdReview({specs,stage:'design',feature:FEATURE,draft:{draftDigest:'a'.repeat(64),features:[{name:'guide',directory:FEATURE,documents}]}});
|
|
24
|
+
claimPrdReview({...prepared.paths,package_sha256:prepared.packageDigest});
|
|
25
|
+
publishPrdReview({specs,reviewPackage:prepared.reviewPackage,packageDigest:prepared.packageDigest,authorContextId:AUTHOR,
|
|
26
|
+
response:{reviewer:'codex-subagent',contextId:'reviewer',independent:true,at:'2026-11-24T00:00:00.000Z',
|
|
27
|
+
result:{verdict:'changes_requested',packageDigest:prepared.packageDigest,
|
|
28
|
+
examinedPaths:documents.map(item=>`${FEATURE}/${item.path}`).sort(),
|
|
29
|
+
findings:[{id:'R1',severity:'P2',path:`${FEATURE}/design.md`,message:'Clarify design',evidence:'Synthetic'}],summary:'Synthetic review'}}});
|
|
30
|
+
fs.mkdirSync(path.join(specs,FEATURE));
|
|
31
|
+
for(const item of documents)fs.writeFileSync(path.join(specs,FEATURE,item.path),item.content,{mode:0o600});
|
|
32
|
+
return {specs,packageDigest:prepared.packageDigest,documents,designFile:path.join(specs,FEATURE,'design.md')};
|
|
33
|
+
}
|
|
34
|
+
const designSha=ctx=>sha(fs.readFileSync(ctx.designFile));
|
|
35
|
+
const finding=(id,{blocking=true}={})=>({id,severity:blocking?'major':'minor',security:false,dataLoss:false,silentFailure:false,
|
|
36
|
+
violatesWrittenRule:false,scenario:blocking?'input X in state Y gives wrong Z':'',message:`Finding ${id}`});
|
|
37
|
+
// Original (single) correction: applies R1 to design.md, or escalates it with no change.
|
|
38
|
+
async function originalCorrection(ctx,{escalate=false}={}){
|
|
39
|
+
const owner=createPrdCorrectionOwner({correct:async({documents})=>({
|
|
40
|
+
documents:documents.map(doc=>({path:doc.path,content:doc.content+(!escalate&&doc.path.endsWith('design.md')?'\nV2':'')})),
|
|
41
|
+
decisions:[{id:'R1',status:escalate?'escalated':'applied',evidence:['original'],changedPaths:escalate?[]:[`${FEATURE}/design.md`]}]})});
|
|
42
|
+
const result=await owner({specs:ctx.specs,stage:'design',feature:FEATURE,writeEnabled:true},signal());
|
|
43
|
+
assert.equal(result.status,'correction_saved');return result;
|
|
44
|
+
}
|
|
45
|
+
function narrowReview(ctx,round,{verdict,findings,session='narrow-reviewer',reviewer='codex-gpt-6.2-sol',independent=true,design=designSha(ctx),
|
|
46
|
+
packageDigest=ctx.packageDigest,author=AUTHOR}){
|
|
47
|
+
return recordPrdNarrowReviewHost({specs:ctx.specs,feature:FEATURE,packageDigest,authorContextId:author,writeEnabled:true,
|
|
48
|
+
input:{round,designSha256:design,reviewer,sessionId:session,independent,at:'2026-11-24T01:00:00.000Z',verdict,summary:'Narrow review',findings}});
|
|
49
|
+
}
|
|
50
|
+
const changes=(ctx,round,ids=['N1'])=>narrowReview(ctx,round,{verdict:'changes_requested',findings:ids.map(id=>finding(id))});
|
|
51
|
+
const approved=(ctx,round)=>narrowReview(ctx,round,{verdict:'approved',findings:[finding('M1',{blocking:false})]});
|
|
52
|
+
let corrections=0;
|
|
53
|
+
// Narrow correction goes through the same owner/call path as the original one.
|
|
54
|
+
async function narrowCorrection(ctx,{ids=['N1'],suffix='V3'}={}){
|
|
55
|
+
const owner=createPrdCorrectionOwner({correct:async({documents,review})=>{
|
|
56
|
+
corrections++;assert.equal(review.narrowRound>=1,true);assert.deepEqual(review.findings.map(item=>item.id),ids);
|
|
57
|
+
return {documents:documents.map(doc=>({path:doc.path,content:doc.content+(doc.path.endsWith('design.md')?`\n${suffix}`:'')})),
|
|
58
|
+
decisions:ids.map(id=>({id,status:'applied',evidence:['narrow'],changedPaths:[`${FEATURE}/design.md`]}))};
|
|
59
|
+
}});
|
|
60
|
+
return owner({specs:ctx.specs,stage:'design',feature:FEATURE,writeEnabled:true},signal());
|
|
61
|
+
}
|
|
62
|
+
const disposition=(ctx,decisions=[{id:'R1',status:'applied',evidence:['original'],changedPaths:[`${FEATURE}/design.md`]}])=>recordPrdHostDisposition({
|
|
63
|
+
specs:ctx.specs,stage:'design',feature:FEATURE,packageDigest:ctx.packageDigest,decisions,writeEnabled:true,
|
|
64
|
+
artifacts:[{path:`${FEATURE}/requirements.md`,sha256:sha(fs.readFileSync(path.join(ctx.specs,FEATURE,'requirements.md')))},
|
|
65
|
+
{path:`${FEATURE}/design.md`,sha256:designSha(ctx)}]});
|
|
66
|
+
const state=ctx=>inspectPrdNarrowReview({specs:ctx.specs,feature:FEATURE});
|
|
67
|
+
|
|
68
|
+
test('one narrow round: reviewed findings drive a correction that enters CM',async t=>{
|
|
69
|
+
const ctx=fixture(t);await originalCorrection(ctx);
|
|
70
|
+
const first=changes(ctx,1);assert.equal(first.phase.status,'awaiting_correction');assert.equal(first.next,'correct_findings');
|
|
71
|
+
const saved=await narrowCorrection(ctx);
|
|
72
|
+
assert.equal(saved.status,'correction_saved');assert.equal(saved.narrow,true);assert.equal(saved.round,1);
|
|
73
|
+
assert.equal(saved.completionAuthorized,false);assert.equal(saved.phase.status,'awaiting_review');assert.equal(saved.phase.round,2);
|
|
74
|
+
assert.match(fs.readFileSync(ctx.designFile,'utf8'),/V3/);
|
|
75
|
+
const archive=fs.readFileSync(path.join(ctx.specs,saved.archive),'utf8');
|
|
76
|
+
assert.match(archive,/narrowReviewDigest/);assert.match(archive,/"decisions"/);
|
|
77
|
+
assert.equal(fs.lstatSync(path.join(ctx.specs,saved.archive)).mode&0o777,0o600);
|
|
78
|
+
// Not reviewed yet: the original disposition must not accept the design.
|
|
79
|
+
assert.throws(()=>disposition(ctx),/prd_narrow_review_pending/);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test('two rounds: N1 changes, correction, N2 approves, then the original disposition records',async t=>{
|
|
83
|
+
const ctx=fixture(t);await originalCorrection(ctx);
|
|
84
|
+
changes(ctx,1);await narrowCorrection(ctx);
|
|
85
|
+
const second=approved(ctx,2);
|
|
86
|
+
assert.equal(second.phase.status,'approved');assert.equal(second.verdict,'approved');
|
|
87
|
+
assert.deepEqual(second.backlog.map(item=>item.id),['M1']);
|
|
88
|
+
const recorded=disposition(ctx);assert.equal(recorded.status,'disposition_recorded');assert.equal(recorded.completionAuthorized,false);
|
|
89
|
+
assert.equal(state(ctx).rounds.length,2);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test('a first narrow review that approves needs no correction',async t=>{
|
|
93
|
+
const ctx=fixture(t);await originalCorrection(ctx);approved(ctx,1);
|
|
94
|
+
assert.equal(disposition(ctx).status,'disposition_recorded');
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test('third round is rejected: a correction after the second review, and a third review record',async t=>{
|
|
98
|
+
const ctx=fixture(t);await originalCorrection(ctx);
|
|
99
|
+
changes(ctx,1);await narrowCorrection(ctx);
|
|
100
|
+
assert.throws(()=>narrowReview(ctx,3,{verdict:'approved',findings:[]}),/prd_narrow_round_limit/);
|
|
101
|
+
changes(ctx,2,['N2']);
|
|
102
|
+
assert.throws(()=>narrowReview(ctx,3,{verdict:'approved',findings:[]}),/prd_narrow_round_limit/);
|
|
103
|
+
await assert.rejects(narrowCorrection(ctx,{ids:['N2']}),/prd_narrow_awaiting_user_decision/);
|
|
104
|
+
assert.throws(()=>narrowReview(ctx,2,{verdict:'approved',findings:[]}),/prd_narrow_awaiting_user_decision/);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test('blocking findings after the second round stop for the user and never release automatically',async t=>{
|
|
108
|
+
const ctx=fixture(t);await originalCorrection(ctx);
|
|
109
|
+
changes(ctx,1);await narrowCorrection(ctx);
|
|
110
|
+
const stopped=changes(ctx,2,['N2']);
|
|
111
|
+
assert.equal(stopped.phase.status,'awaiting_user_decision');assert.equal(stopped.userDecisionRequired,true);
|
|
112
|
+
assert.equal(stopped.autoReleaseAllowed,false);assert.equal(stopped.completionAuthorized,false);
|
|
113
|
+
assert.equal(state(ctx).userDecisionRequired,true);
|
|
114
|
+
assert.throws(()=>disposition(ctx),/prd_narrow_awaiting_user_decision/);
|
|
115
|
+
assert.equal(fs.existsSync(path.join(ctx.specs,'.reviews/prd-guide-design-disposition.json')),false);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test('a correction without its review record is rejected, also a second one after a correction',async t=>{
|
|
119
|
+
const ctx=fixture(t);await originalCorrection(ctx);
|
|
120
|
+
const before=fs.readFileSync(ctx.designFile,'utf8');
|
|
121
|
+
await assert.rejects(narrowCorrection(ctx),/prd_narrow_review_required/);
|
|
122
|
+
assert.equal(fs.readFileSync(ctx.designFile,'utf8'),before);
|
|
123
|
+
changes(ctx,1);await narrowCorrection(ctx);
|
|
124
|
+
const corrected=fs.readFileSync(ctx.designFile,'utf8');
|
|
125
|
+
// The corrected bytes have not been reviewed: asking again only replays the saved correction, never a new one.
|
|
126
|
+
const calls=corrections,again=await narrowCorrection(ctx,{suffix:'V4'});
|
|
127
|
+
assert.equal(again.status,'correction_saved');assert.equal(corrections,calls);
|
|
128
|
+
assert.equal(fs.readFileSync(ctx.designFile,'utf8'),corrected);
|
|
129
|
+
assert.equal(state(ctx).phase.status,'awaiting_review');
|
|
130
|
+
const approvedCtx=fixture(t);await originalCorrection(approvedCtx);approved(approvedCtx,1);
|
|
131
|
+
await assert.rejects(narrowCorrection(approvedCtx),/prd_narrow_already_approved/);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
test('review records need independence, grading, scenario and the exact reviewed bytes',async t=>{
|
|
135
|
+
const ctx=fixture(t);await originalCorrection(ctx);
|
|
136
|
+
const args={verdict:'changes_requested',findings:[finding('N1')]};
|
|
137
|
+
assert.throws(()=>narrowReview(ctx,1,{...args,session:AUTHOR}),/prd_narrow_reviewer_not_independent/);
|
|
138
|
+
assert.throws(()=>narrowReview(ctx,1,{...args,session:'resumed-host',author:'resumed-host'}),/prd_narrow_reviewer_not_independent/);
|
|
139
|
+
assert.throws(()=>narrowReview(ctx,1,{...args,reviewer:'self-degraded'}),/invalid_input|prd_narrow_reviewer_not_independent/);
|
|
140
|
+
assert.throws(()=>narrowReview(ctx,1,{...args,independent:false}),/prd_narrow_reviewer_not_independent/);
|
|
141
|
+
assert.throws(()=>narrowReview(ctx,1,{...args,design:'b'.repeat(64)}),/prd_narrow_design_changed/);
|
|
142
|
+
assert.throws(()=>narrowReview(ctx,1,{...args,packageDigest:'c'.repeat(64)}),/prd_narrow_package_changed/);
|
|
143
|
+
assert.throws(()=>narrowReview(ctx,1,{verdict:'changes_requested',findings:[{...finding('N1'),scenario:' '}]}),/prd_narrow_blocking_scenario_required/);
|
|
144
|
+
assert.throws(()=>narrowReview(ctx,1,{verdict:'approved',findings:[finding('N1')]}),/prd_narrow_verdict_findings_mismatch/);
|
|
145
|
+
assert.throws(()=>narrowReview(ctx,1,{verdict:'changes_requested',findings:[finding('N1',{blocking:false})]}),/prd_narrow_verdict_findings_mismatch/);
|
|
146
|
+
// Any yes on the four questions makes a minor finding blocking.
|
|
147
|
+
assert.equal(narrowReview(ctx,1,{verdict:'changes_requested',findings:[{...finding('N1',{blocking:false}),dataLoss:true,scenario:'delete runs twice'}]}).phase.status,'awaiting_correction');
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
test('rounds cannot be skipped or repeated, and design drift is detected',async t=>{
|
|
151
|
+
const ctx=fixture(t);await originalCorrection(ctx);
|
|
152
|
+
assert.throws(()=>changes(ctx,2),/prd_narrow_round_out_of_order/);
|
|
153
|
+
changes(ctx,1);
|
|
154
|
+
assert.throws(()=>changes(ctx,1),/prd_narrow_round_out_of_order/);
|
|
155
|
+
assert.throws(()=>changes(ctx,2),/prd_narrow_round_out_of_order/);
|
|
156
|
+
fs.appendFileSync(ctx.designFile,'\nUser edit');
|
|
157
|
+
assert.throws(()=>state(ctx),/prd_narrow_design_changed/);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
test('narrow review needs the saved original correction and the original package',async t=>{
|
|
161
|
+
const ctx=fixture(t);
|
|
162
|
+
assert.throws(()=>changes(ctx,1),/prd_narrow_requires_original_correction/);
|
|
163
|
+
assert.equal(state(ctx).status,'narrow_not_started');
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
test('interrupted correction resumes from its archive without asking again',async t=>{
|
|
167
|
+
const ctx=fixture(t);await originalCorrection(ctx);changes(ctx,1);
|
|
168
|
+
const saved=await narrowCorrection(ctx);const calls=corrections;
|
|
169
|
+
const archive=JSON.parse(fs.readFileSync(path.join(ctx.specs,saved.archive),'utf8').match(/\n```json\n([^\n]+)\n```/)[1]);
|
|
170
|
+
// Crash prefix: archive durable, design.md not yet replaced.
|
|
171
|
+
fs.writeFileSync(ctx.designFile,archive.before.find(item=>item.path.endsWith('design.md')).content);
|
|
172
|
+
assert.throws(()=>changes(ctx,2),/prd_narrow_round_out_of_order/);
|
|
173
|
+
assert.equal(state(ctx).phase.status,'correction_incomplete');
|
|
174
|
+
const resumed=await narrowCorrection(ctx);
|
|
175
|
+
assert.equal(resumed.status,'correction_saved');assert.equal(corrections,calls);
|
|
176
|
+
assert.match(fs.readFileSync(ctx.designFile,'utf8'),/V3/);
|
|
177
|
+
assert.equal(state(ctx).phase.status,'awaiting_review');
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
test('an original correction that changed nothing still accepts the reviewed narrow changes',async t=>{
|
|
181
|
+
const ctx=fixture(t);await originalCorrection(ctx,{escalate:true});
|
|
182
|
+
changes(ctx,1);await narrowCorrection(ctx);approved(ctx,2);
|
|
183
|
+
const recorded=disposition(ctx,[{id:'R1',status:'escalated',evidence:['original'],changedPaths:[]}]);
|
|
184
|
+
assert.equal(recorded.status,'disposition_recorded');
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
test('without any narrow round the original single-correction flow is unchanged',async t=>{
|
|
188
|
+
const ctx=fixture(t);await originalCorrection(ctx);
|
|
189
|
+
assert.equal(disposition(ctx).status,'disposition_recorded');
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
test('narrow writes need the review-write switch',async t=>{
|
|
193
|
+
const ctx=fixture(t);await originalCorrection(ctx);
|
|
194
|
+
assert.throws(()=>recordPrdNarrowReviewHost({specs:ctx.specs,feature:FEATURE,packageDigest:ctx.packageDigest,authorContextId:AUTHOR,
|
|
195
|
+
writeEnabled:false,input:{round:1,designSha256:designSha(ctx),reviewer:'r',sessionId:'s',independent:true,at:'2026-11-24T01:00:00.000Z',
|
|
196
|
+
verdict:'approved',summary:'x',findings:[]}}),/prd_narrow_not_enabled/);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
test('original decisions cannot be flipped by unrelated narrow changes',async t=>{
|
|
200
|
+
const ctx=fixture(t);await originalCorrection(ctx,{escalate:true});
|
|
201
|
+
changes(ctx,1);await narrowCorrection(ctx);approved(ctx,2);
|
|
202
|
+
assert.throws(()=>disposition(ctx,[{id:'R1',status:'applied',evidence:['claimed'],changedPaths:[`${FEATURE}/design.md`]}]),/prd_narrow_disposition_decisions_changed/);
|
|
203
|
+
});
|
|
204
|
+
test('the original author context cannot sign a narrow review, and oversized records are refused',async t=>{
|
|
205
|
+
const ctx=fixture(t);await originalCorrection(ctx);
|
|
206
|
+
assert.throws(()=>narrowReview(ctx,1,{verdict:'changes_requested',findings:[finding('N1')],session:AUTHOR,author:'other-host'}),/prd_narrow_reviewer_not_independent/);
|
|
207
|
+
const big=Array.from({length:40},(_,i)=>({...finding(`N${i}`),message:'m'.repeat(1900),scenario:'s'.repeat(1900)}));
|
|
208
|
+
assert.throws(()=>narrowReview(ctx,1,{verdict:'changes_requested',findings:big}),/prd_narrow_record_too_large/);
|
|
209
|
+
assert.equal(state(ctx).phase.status,'awaiting_review');
|
|
210
|
+
});
|
|
211
|
+
test('a run whose original archive predates narrow rounds keeps the legacy flow',async t=>{
|
|
212
|
+
const ctx=fixture(t);const saved=await originalCorrection(ctx);
|
|
213
|
+
const file=path.join(ctx.specs,saved.archive),text=fs.readFileSync(file,'utf8');
|
|
214
|
+
const legacy=text.replace(',"narrowReview":1}','}');assert.notEqual(legacy,text);
|
|
215
|
+
fs.chmodSync(file,0o600);fs.writeFileSync(file,legacy,{mode:0o600});
|
|
216
|
+
assert.throws(()=>changes(ctx,1),/prd_narrow_requires_original_correction/);
|
|
217
|
+
const owner=createPrdCorrectionOwner({correct:async()=>{throw new Error('must not ask');}});
|
|
218
|
+
assert.equal((await owner({specs:ctx.specs,stage:'design',feature:FEATURE,writeEnabled:true},signal())).status,'correction_recovery_required');
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
test('the legacy record entry cannot close a pending narrow round or rewrite the original decision counts',async t=>{
|
|
222
|
+
const ctx=fixture(t);await originalCorrection(ctx,{escalate:true});
|
|
223
|
+
const args=(count,unresolved)=>({stage:'design',feature:'guide',evidence:path.join(ctx.specs,'.reviews/prd-guide-design-r1.md'),
|
|
224
|
+
receipt:path.join(ctx.specs,'.reviews/prd-guide-design-disposition.json'),disposition:unresolved?'escalated':'applied',
|
|
225
|
+
finding_count:count,unresolved_count:unresolved,artifact:[path.join(ctx.specs,FEATURE,'design.md')]});
|
|
226
|
+
changes(ctx,1);
|
|
227
|
+
assert.throws(()=>recordPrdReview(args(1,1)),/prd_narrow_review_pending|narrow_review_pending/);
|
|
228
|
+
await narrowCorrection(ctx);approved(ctx,2);
|
|
229
|
+
assert.throws(()=>recordPrdReview(args(1,0)),/prd_narrow_disposition_decisions_changed|decisions_changed/);
|
|
230
|
+
assert.equal(fs.existsSync(args(1,1).receipt),false);
|
|
231
|
+
assert.equal(recordPrdReview(args(1,1)).outcome,'recorded');
|
|
232
|
+
});
|
|
233
|
+
test('review_findings keeps its exact result shape for older sessions',async t=>{
|
|
234
|
+
const ctx=fixture(t);assert.equal(Object.hasOwn(inspectPrdFindings({specs:ctx.specs,stage:'design',feature:FEATURE}),'authorContextId'),false);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
test('the legacy record entry fails closed on missing, corrupt or unreadable narrow files',async t=>{
|
|
238
|
+
const call=ctx=>recordPrdReview({stage:'design',feature:'guide',evidence:path.join(ctx.specs,'.reviews/prd-guide-design-r1.md'),
|
|
239
|
+
receipt:path.join(ctx.specs,'.reviews/prd-guide-design-disposition.json'),disposition:'applied',finding_count:1,unresolved_count:0,
|
|
240
|
+
artifact:[path.join(ctx.specs,FEATURE,'design.md')]});
|
|
241
|
+
const refused=error=>/^prd_narrow_/.test(error.code)&&!error.message.includes(os.tmpdir());
|
|
242
|
+
const reviews=ctx=>path.join(ctx.specs,'.reviews');
|
|
243
|
+
// Only r2 remains (r1 lost), saying changes_requested.
|
|
244
|
+
let ctx=fixture(t);await originalCorrection(ctx);changes(ctx,1);await narrowCorrection(ctx);changes(ctx,2,['N2']);
|
|
245
|
+
fs.unlinkSync(path.join(reviews(ctx),'prd-guide-design-narrow-review-r1.json'));
|
|
246
|
+
assert.throws(()=>call(ctx),error=>error.code==='prd_narrow_record_invalid');
|
|
247
|
+
// Correction archive saved but r1 lost and r2 not yet written.
|
|
248
|
+
ctx=fixture(t);await originalCorrection(ctx);changes(ctx,1);await narrowCorrection(ctx);
|
|
249
|
+
fs.unlinkSync(path.join(reviews(ctx),'prd-guide-design-narrow-review-r1.json'));
|
|
250
|
+
assert.throws(()=>call(ctx),error=>error.code==='prd_narrow_record_invalid');
|
|
251
|
+
// r1 corrupt while r2 is a bare approved stub.
|
|
252
|
+
ctx=fixture(t);await originalCorrection(ctx);
|
|
253
|
+
fs.writeFileSync(path.join(reviews(ctx),'prd-guide-design-narrow-review-r1.json'),'{broken',{mode:0o600});
|
|
254
|
+
fs.writeFileSync(path.join(reviews(ctx),'prd-guide-design-narrow-review-r2.json'),'{"verdict":"approved"}\n',{mode:0o600});
|
|
255
|
+
assert.throws(()=>call(ctx),refused);
|
|
256
|
+
// Valid r1 changes_requested, r2 only a bare approved stub.
|
|
257
|
+
ctx=fixture(t);await originalCorrection(ctx);changes(ctx,1);
|
|
258
|
+
fs.writeFileSync(path.join(reviews(ctx),'prd-guide-design-narrow-review-r2.json'),'{"verdict":"approved"}\n',{mode:0o600});
|
|
259
|
+
assert.throws(()=>call(ctx),refused);
|
|
260
|
+
// Corrupt original archive tail: fixed code, no raw SyntaxError or path.
|
|
261
|
+
ctx=fixture(t);const saved=await originalCorrection(ctx);approved(ctx,1);
|
|
262
|
+
const archive=path.join(ctx.specs,saved.archive);fs.writeFileSync(archive,fs.readFileSync(archive,'utf8').replace('"proposal":','"proposal":{'),{mode:0o600});
|
|
263
|
+
assert.throws(()=>call(ctx),refused);
|
|
264
|
+
// Unreadable record file.
|
|
265
|
+
ctx=fixture(t);await originalCorrection(ctx);changes(ctx,1);
|
|
266
|
+
fs.chmodSync(path.join(reviews(ctx),'prd-guide-design-narrow-review-r1.json'),0o000);
|
|
267
|
+
assert.throws(()=>call(ctx),refused);
|
|
268
|
+
fs.chmodSync(path.join(reviews(ctx),'prd-guide-design-narrow-review-r1.json'),0o600);
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
test('the chain validates archived narrow decisions and ignores nothing beyond its phase',async t=>{
|
|
272
|
+
const call=ctx=>recordPrdReview({stage:'design',feature:'guide',evidence:path.join(ctx.specs,'.reviews/prd-guide-design-r1.md'),
|
|
273
|
+
receipt:path.join(ctx.specs,'.reviews/prd-guide-design-disposition.json'),disposition:'applied',finding_count:1,unresolved_count:0,
|
|
274
|
+
artifact:[path.join(ctx.specs,FEATURE,'design.md')]});
|
|
275
|
+
// Tampered narrow correction decisions are caught by the host chain and the legacy entry alike.
|
|
276
|
+
let ctx=fixture(t);await originalCorrection(ctx);changes(ctx,1);const saved=await narrowCorrection(ctx);
|
|
277
|
+
const file=path.join(ctx.specs,saved.archive),value=JSON.parse(fs.readFileSync(file,'utf8').match(/\n```json\n([^\n]+)\n```/)[1]);
|
|
278
|
+
value.proposal.decisions=[null];fs.writeFileSync(file,narrowCorrectionBytes(value),{mode:0o600});
|
|
279
|
+
assert.throws(()=>approved(ctx,2),error=>error.code==='prd_narrow_record_invalid');
|
|
280
|
+
assert.throws(()=>state(ctx),error=>error.code==='prd_narrow_record_invalid');
|
|
281
|
+
assert.throws(()=>call(ctx),error=>error.code==='prd_narrow_record_invalid');
|
|
282
|
+
// A decision list that no longer covers the narrow finding ids is refused too.
|
|
283
|
+
ctx=fixture(t);await originalCorrection(ctx);changes(ctx,1);const second=await narrowCorrection(ctx);
|
|
284
|
+
const again=path.join(ctx.specs,second.archive),parsed=JSON.parse(fs.readFileSync(again,'utf8').match(/\n```json\n([^\n]+)\n```/)[1]);
|
|
285
|
+
parsed.proposal.decisions[0].id='N9';fs.writeFileSync(again,narrowCorrectionBytes(parsed),{mode:0o600});
|
|
286
|
+
assert.throws(()=>state(ctx),error=>error.code==='prd_narrow_record_invalid');
|
|
287
|
+
// r1 approved, r2 a dangling link: later rounds are never skipped.
|
|
288
|
+
ctx=fixture(t);await originalCorrection(ctx);approved(ctx,1);
|
|
289
|
+
fs.symlinkSync(path.join(ctx.specs,'missing'),path.join(ctx.specs,'.reviews/prd-guide-design-narrow-review-r2.json'));
|
|
290
|
+
assert.throws(()=>state(ctx),error=>error.code==='prd_narrow_record_invalid');
|
|
291
|
+
assert.throws(()=>call(ctx),error=>error.code==='prd_narrow_record_invalid');
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
test('archived originals must match what the chain reviewed; later round names and dangling links are never ignored',async t=>{
|
|
295
|
+
const reviews=ctx=>path.join(ctx.specs,'.reviews'),code=error=>error.code==='prd_narrow_record_invalid';
|
|
296
|
+
const rewrite=(ctx,saved,edit)=>{const file=path.join(ctx.specs,saved.archive);
|
|
297
|
+
const value=JSON.parse(fs.readFileSync(file,'utf8').match(/\n```json\n([^\n]+)\n```/)[1]);edit(value);
|
|
298
|
+
fs.writeFileSync(file,narrowCorrectionBytes(value),{mode:0o600});};
|
|
299
|
+
// before.design rewritten to the corrected bytes while the top-level hash still names the reviewed one.
|
|
300
|
+
let ctx=fixture(t);await originalCorrection(ctx);changes(ctx,1);let saved=await narrowCorrection(ctx);
|
|
301
|
+
rewrite(ctx,saved,value=>{const design=value.before.find(item=>item.path.endsWith('design.md')),after=value.proposal.documents.find(item=>item.path.endsWith('design.md'));
|
|
302
|
+
design.content=after.content;design.sha256=value.afterSha256;value.proposal.decisions=[{id:'N1',status:'escalated',evidence:['claimed'],changedPaths:[]}];});
|
|
303
|
+
assert.throws(()=>state(ctx),code);
|
|
304
|
+
// requirements text inside the proposal changed.
|
|
305
|
+
ctx=fixture(t);await originalCorrection(ctx);changes(ctx,1);saved=await narrowCorrection(ctx);
|
|
306
|
+
rewrite(ctx,saved,value=>{value.proposal.documents.find(item=>item.path.endsWith('requirements.md')).content+='\nExtra requirement';});
|
|
307
|
+
assert.throws(()=>state(ctx),code);
|
|
308
|
+
// A third-round name beyond the limit, and a dangling correction link after an approved first round.
|
|
309
|
+
ctx=fixture(t);await originalCorrection(ctx);approved(ctx,1);
|
|
310
|
+
fs.symlinkSync(path.join(ctx.specs,'missing'),path.join(reviews(ctx),'prd-guide-design-narrow-review-r3.json'));
|
|
311
|
+
assert.throws(()=>state(ctx),code);
|
|
312
|
+
fs.unlinkSync(path.join(reviews(ctx),'prd-guide-design-narrow-review-r3.json'));
|
|
313
|
+
fs.symlinkSync(path.join(ctx.specs,'missing'),path.join(reviews(ctx),'prd-guide-design-narrow-correction-r1.md'));
|
|
314
|
+
assert.throws(()=>state(ctx),code);
|
|
315
|
+
fs.unlinkSync(path.join(reviews(ctx),'prd-guide-design-narrow-correction-r1.md'));
|
|
316
|
+
ctx=fixture(t);await originalCorrection(ctx);changes(ctx,1);await narrowCorrection(ctx);approved(ctx,2);
|
|
317
|
+
fs.writeFileSync(path.join(reviews(ctx),'prd-guide-design-narrow-correction-r2.md'),'stray',{mode:0o600});
|
|
318
|
+
assert.throws(()=>state(ctx),code);
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
test('a user edit of requirements.md blocks the narrow correction before anything is saved, and undoing it recovers',async t=>{
|
|
322
|
+
const ctx=fixture(t);await originalCorrection(ctx);changes(ctx,1);
|
|
323
|
+
const requirements=path.join(ctx.specs,FEATURE,'requirements.md'),original=fs.readFileSync(requirements,'utf8'),calls=corrections;
|
|
324
|
+
fs.writeFileSync(requirements,original+'\nUser edit',{mode:0o600});
|
|
325
|
+
await assert.rejects(narrowCorrection(ctx),/prd_correction_inputs_changed/);
|
|
326
|
+
assert.equal(corrections,calls);
|
|
327
|
+
assert.equal(fs.existsSync(path.join(ctx.specs,'.reviews/prd-guide-design-narrow-correction-r1.md')),false);
|
|
328
|
+
fs.writeFileSync(requirements,original,{mode:0o600});
|
|
329
|
+
assert.equal((await narrowCorrection(ctx)).status,'correction_saved');
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
// Degraded round: the review model was unavailable and the author model reviewed. Evidence only, never releases.
|
|
333
|
+
const degradedReview=(ctx,round,{verdict,findings,reason='review model unavailable',session=AUTHOR,independent=false,design=designSha(ctx)})=>
|
|
334
|
+
recordPrdNarrowReviewHost({specs:ctx.specs,feature:FEATURE,packageDigest:ctx.packageDigest,authorContextId:AUTHOR,writeEnabled:true,
|
|
335
|
+
input:{round,designSha256:design,reviewer:'self-degraded',sessionId:session,independent,degradedReason:reason,at:'2026-11-24T03:00:00.000Z',
|
|
336
|
+
verdict,summary:'Degraded narrow review',findings}});
|
|
337
|
+
test('a degraded approval is recorded but cannot release: it stops for the user',async t=>{
|
|
338
|
+
const ctx=fixture(t);await originalCorrection(ctx);
|
|
339
|
+
const recorded=degradedReview(ctx,1,{verdict:'approved',findings:[]});
|
|
340
|
+
assert.equal(recorded.degradedReview,true);assert.equal(recorded.phase.status,'awaiting_user_decision');
|
|
341
|
+
assert.equal(recorded.phase.reason,'degraded_review_only');assert.equal(recorded.userDecisionRequired,true);
|
|
342
|
+
assert.equal(recorded.rounds[0].degraded,true);
|
|
343
|
+
assert.throws(()=>disposition(ctx),/prd_narrow_awaiting_user_decision/);
|
|
344
|
+
assert.throws(()=>recordPrdReview({stage:'design',feature:'guide',evidence:path.join(ctx.specs,'.reviews/prd-guide-design-r1.md'),
|
|
345
|
+
receipt:path.join(ctx.specs,'.reviews/prd-guide-design-disposition.json'),disposition:'applied',finding_count:1,unresolved_count:0,
|
|
346
|
+
artifact:[path.join(ctx.specs,FEATURE,'design.md')]}),/prd_narrow_review_pending/);
|
|
347
|
+
assert.equal(recorded.independentFollowUpAllowed,true);
|
|
348
|
+
await assert.rejects(narrowCorrection(ctx),/prd_narrow_awaiting_user_decision/);
|
|
349
|
+
});
|
|
350
|
+
test('a degraded round with findings still drives a correction, and an independent approval then releases',async t=>{
|
|
351
|
+
const ctx=fixture(t);await originalCorrection(ctx);
|
|
352
|
+
assert.equal(degradedReview(ctx,1,{verdict:'changes_requested',findings:[finding('N1')]}).phase.status,'awaiting_correction');
|
|
353
|
+
await narrowCorrection(ctx);
|
|
354
|
+
assert.equal(approved(ctx,2).phase.status,'approved');
|
|
355
|
+
assert.equal(disposition(ctx).status,'disposition_recorded');
|
|
356
|
+
assert.equal(state(ctx).rounds[0].degraded,true);assert.equal(state(ctx).rounds[1].degraded,false);
|
|
357
|
+
});
|
|
358
|
+
test('degraded rounds count toward the two-round limit and need a reason, the author context and no independence claim',async t=>{
|
|
359
|
+
const ctx=fixture(t);await originalCorrection(ctx);
|
|
360
|
+
assert.throws(()=>degradedReview(ctx,1,{verdict:'approved',findings:[],reason:' '}),/prd_narrow_reviewer_not_independent/);
|
|
361
|
+
assert.throws(()=>degradedReview(ctx,1,{verdict:'approved',findings:[],session:'someone-else'}),/prd_narrow_reviewer_not_independent/);
|
|
362
|
+
assert.throws(()=>degradedReview(ctx,1,{verdict:'approved',findings:[],independent:true}),/prd_narrow_reviewer_not_independent/);
|
|
363
|
+
// An independent claim cannot carry a degraded reason.
|
|
364
|
+
assert.throws(()=>recordPrdNarrowReviewHost({specs:ctx.specs,feature:FEATURE,packageDigest:ctx.packageDigest,authorContextId:AUTHOR,
|
|
365
|
+
writeEnabled:true,input:{round:1,designSha256:designSha(ctx),reviewer:'codex',sessionId:'r',independent:true,degradedReason:'x',
|
|
366
|
+
at:'2026-11-24T03:00:00.000Z',verdict:'approved',summary:'s',findings:[]}}));
|
|
367
|
+
degradedReview(ctx,1,{verdict:'changes_requested',findings:[finding('N1')]});await narrowCorrection(ctx);
|
|
368
|
+
assert.equal(degradedReview(ctx,2,{verdict:'changes_requested',findings:[finding('N2')]}).phase.status,'awaiting_user_decision');
|
|
369
|
+
assert.throws(()=>degradedReview(ctx,3,{verdict:'approved',findings:[]}),/prd_narrow_round_limit/);
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
test('a context that signed a degraded round cannot sign an independent one after a host change',async t=>{
|
|
373
|
+
const ctx=fixture(t);await originalCorrection(ctx);
|
|
374
|
+
// Another host (B) resumed and acted as the author for the degraded first round.
|
|
375
|
+
recordPrdNarrowReviewHost({specs:ctx.specs,feature:FEATURE,packageDigest:ctx.packageDigest,authorContextId:'host-b',writeEnabled:true,
|
|
376
|
+
input:{round:1,designSha256:designSha(ctx),reviewer:'self-degraded',sessionId:'host-b',independent:false,degradedReason:'review model unavailable',
|
|
377
|
+
at:'2026-11-24T03:00:00.000Z',verdict:'changes_requested',summary:'Degraded',findings:[finding('N1')]}});
|
|
378
|
+
await narrowCorrection(ctx);
|
|
379
|
+
assert.throws(()=>narrowReview(ctx,2,{verdict:'approved',findings:[],session:'host-b',author:'host-c'}),/prd_narrow_reviewer_not_independent/);
|
|
380
|
+
assert.equal(narrowReview(ctx,2,{verdict:'approved',findings:[],session:'real-reviewer',author:'host-c'}).phase.status,'approved');
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
test('after a degraded approval an independent follow-up on the same bytes can release',async t=>{
|
|
384
|
+
const ctx=fixture(t);await originalCorrection(ctx);
|
|
385
|
+
degradedReview(ctx,1,{verdict:'approved',findings:[]});
|
|
386
|
+
assert.equal(state(ctx).next,'record_independent_narrow_review_r2');
|
|
387
|
+
assert.throws(()=>degradedReview(ctx,2,{verdict:'approved',findings:[]}),/prd_narrow_reviewer_not_independent/);
|
|
388
|
+
assert.throws(()=>narrowReview(ctx,2,{verdict:'approved',findings:[],session:AUTHOR}),/prd_narrow_reviewer_not_independent/);
|
|
389
|
+
assert.throws(()=>narrowReview(ctx,3,{verdict:'approved',findings:[]}),/prd_narrow_round_limit/);
|
|
390
|
+
assert.throws(()=>narrowReview(ctx,1,{verdict:'approved',findings:[]}),/prd_narrow_round_out_of_order/);
|
|
391
|
+
assert.equal(narrowReview(ctx,2,{verdict:'approved',findings:[]}).phase.status,'approved');
|
|
392
|
+
assert.equal(disposition(ctx).status,'disposition_recorded');
|
|
393
|
+
assert.equal(state(ctx).rounds[0].degraded,true);assert.equal(state(ctx).rounds[1].degraded,false);
|
|
394
|
+
});
|
|
395
|
+
test('an independent follow-up with blocking findings stops for the user, and a late degraded approval has no follow-up slot',async t=>{
|
|
396
|
+
let ctx=fixture(t);await originalCorrection(ctx);
|
|
397
|
+
degradedReview(ctx,1,{verdict:'approved',findings:[]});
|
|
398
|
+
const stopped=narrowReview(ctx,2,{verdict:'changes_requested',findings:[finding('N2')]});
|
|
399
|
+
assert.equal(stopped.phase.status,'awaiting_user_decision');assert.equal(stopped.independentFollowUpAllowed,false);
|
|
400
|
+
assert.throws(()=>disposition(ctx),/prd_narrow_awaiting_user_decision/);
|
|
401
|
+
ctx=fixture(t);await originalCorrection(ctx);changes(ctx,1);await narrowCorrection(ctx);
|
|
402
|
+
const late=degradedReview(ctx,2,{verdict:'approved',findings:[]});
|
|
403
|
+
assert.equal(late.independentFollowUpAllowed,false);
|
|
404
|
+
assert.throws(()=>narrowReview(ctx,3,{verdict:'approved',findings:[]}),/prd_narrow_round_limit/);
|
|
405
|
+
assert.throws(()=>disposition(ctx),/prd_narrow_awaiting_user_decision/);
|
|
406
|
+
});
|
|
407
|
+
test('the independent follow-up is chained to the degraded record',async t=>{
|
|
408
|
+
const ctx=fixture(t);await originalCorrection(ctx);degradedReview(ctx,1,{verdict:'approved',findings:[]});narrowReview(ctx,2,{verdict:'approved',findings:[]});
|
|
409
|
+
const file=path.join(ctx.specs,'.reviews/prd-guide-design-narrow-review-r1.json'),value=JSON.parse(fs.readFileSync(file,'utf8'));
|
|
410
|
+
value.summary='Rewritten after the follow-up was signed';fs.writeFileSync(file,JSON.stringify(value)+'\n',{mode:0o600});
|
|
411
|
+
assert.throws(()=>state(ctx),error=>error.code==='prd_narrow_record_invalid');
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
test('read-back refuses an independent record that reuses a degraded or author context',async t=>{
|
|
415
|
+
const tamper=(ctx,round,session)=>{const file=path.join(ctx.specs,`.reviews/prd-guide-design-narrow-review-r${round}.json`),value=JSON.parse(fs.readFileSync(file,'utf8'));
|
|
416
|
+
value.sessionId=session;fs.writeFileSync(file,JSON.stringify(value)+'\n',{mode:0o600});};
|
|
417
|
+
let ctx=fixture(t);await originalCorrection(ctx);degradedReview(ctx,1,{verdict:'approved',findings:[]});narrowReview(ctx,2,{verdict:'approved',findings:[]});
|
|
418
|
+
tamper(ctx,2,AUTHOR);assert.throws(()=>state(ctx),error=>error.code==='prd_narrow_reviewer_not_independent');
|
|
419
|
+
assert.throws(()=>disposition(ctx));
|
|
420
|
+
ctx=fixture(t);await originalCorrection(ctx);
|
|
421
|
+
recordPrdNarrowReviewHost({specs:ctx.specs,feature:FEATURE,packageDigest:ctx.packageDigest,authorContextId:'host-b',writeEnabled:true,
|
|
422
|
+
input:{round:1,designSha256:designSha(ctx),reviewer:'self-degraded',sessionId:'host-b',independent:false,degradedReason:'review model unavailable',
|
|
423
|
+
at:'2026-11-24T03:00:00.000Z',verdict:'approved',summary:'Degraded',findings:[]}});
|
|
424
|
+
narrowReview(ctx,2,{verdict:'approved',findings:[],session:'real-reviewer',author:'host-c'});
|
|
425
|
+
tamper(ctx,2,'host-b');assert.throws(()=>state(ctx),error=>error.code==='prd_narrow_reviewer_not_independent');
|
|
426
|
+
// No degraded round at all: an independent record naming the original author is refused on read-back.
|
|
427
|
+
ctx=fixture(t);await originalCorrection(ctx);approved(ctx,1);
|
|
428
|
+
tamper(ctx,1,AUTHOR);assert.throws(()=>state(ctx),error=>error.code==='prd_narrow_reviewer_not_independent');
|
|
429
|
+
});
|
|
@@ -8,6 +8,7 @@ import {TextDecoder} from 'node:util';
|
|
|
8
8
|
import {fileURLToPath} from 'node:url';
|
|
9
9
|
import {acceptsPrdSplitDesign} from '../runtime/js/cm-prd/split-design.mjs';
|
|
10
10
|
import {inspectPrdFailedCorrection} from '../runtime/js/cm-prd/failed-correction.mjs';
|
|
11
|
+
import {assertNarrowReceiptAllowed} from '../runtime/js/cm-prd/review-correction.mjs';
|
|
11
12
|
import {normalizeRuntimeMarks,normalizeRuntimeMarkBytes} from './cm-spec-manifest.mjs';
|
|
12
13
|
import {APPROVED_SPEC_FILES} from '../runtime/js/cm-ai/spec-amendment.mjs';
|
|
13
14
|
import {tagDiagnosticReason} from '../runtime/js/cm-ai/diagnostic-reason.mjs';
|
|
@@ -307,6 +308,8 @@ export function recordPrdReview(args){
|
|
|
307
308
|
}
|
|
308
309
|
const {evidence,receipt}=paths(args),base={stage:args.stage,feature:args.feature};evidenceHeader(evidence);
|
|
309
310
|
if(stat(receipt)){loadReceipt(receipt,args,evidence);return {...base,outcome:'already_recorded'};}
|
|
311
|
+
if(args.stage==='design')assertNarrowReceiptAllowed({specs:resolve(path.dirname(path.dirname(receipt))),slug:args.feature,
|
|
312
|
+
findingCount:args.finding_count,unresolvedCount:args.unresolved_count});
|
|
310
313
|
const root=resolve(path.dirname(path.dirname(receipt))),seen=new Set();
|
|
311
314
|
need(Array.isArray(args.artifact)&&args.artifact.length>0,'artifact required','prd_review_artifact_required');
|
|
312
315
|
const artifacts=args.artifact.map(raw=>{
|
package/skills/cm-prd/SKILL.md
CHANGED
|
@@ -370,6 +370,7 @@ design.md 生成后,满足任一触发条件 → 按 `runtime/review.md` 交**
|
|
|
370
370
|
无法机械确认的项写入摘要卡「风险点」交人裁决。**禁止 review → 修正 → 再 review**,
|
|
371
371
|
也禁止换一个审查者变相开启第 2 轮;凭证只允许 `design-r1.md`,不得生成 `design-r2.md`。
|
|
372
372
|
任何审查尝试(包括 `self-degraded`)均消耗唯一一轮;通道恢复后不得补审。
|
|
373
|
+
例外(仅 JS 宿主新运行):原修正保存后的窄审轮次(最多两轮、每轮独立记录,不生成 `design-r2.md`、不重开 r1)见 `references/js-host.md`「设计阶段的窄审轮次」。
|
|
373
374
|
(实跑教训:公共 CLI 契约的 3 轮方案复审耗时 11m59s,后两轮应由自检与人审承担。)
|
|
374
375
|
未命中上述风险信号的低风险 feature 不触发,零额外负担。
|
|
375
376
|
**凭证落盘**:审查原文 tee 到 `{SPECS_DIR}/.reviews/prd-{feature}-design-r1.md`——摘要卡「方案对抗审查」行必须与凭证对得上,无凭证的数字是自报(凭证教义全框架一体,规格期不豁免)。
|
|
@@ -191,6 +191,8 @@ callId/requestDigest必须绑定active中的未知调用,evidence不能为空
|
|
|
191
191
|
|
|
192
192
|
prd_correct先写`.reviews/prd-<feature>-<stage>-correction.md`存档再替换规格。中断后`inspect_correction`按存档逐文件比对:matches_correction(已是修正稿)、needs_correction(仍是原文,`resume_correction`续写)、conflict(两者都不是)。有conflict时inspect返回`status:correction_recovery_conflict`,每个冲突文件带currentSha256/originalSha256/correctedSha256和中文guidance;`resume_correction`以`prd_correction_recovery_conflict`阻断(blocked可见),不覆盖、不把半写结果当新交付。
|
|
193
193
|
|
|
194
|
+
设计阶段原修正已保存后,`correct_findings` 不再返回 `correction_recovery_required`:改走窄审轮次(`narrow_review` / `narrow_status`,最多两轮,见 `js-host.md`「设计阶段的窄审轮次」);原修正写入未完成时仍走本节 `inspect_correction` / `resume_correction`。窄审修正中断则重调 `correct_findings` 从 `...-narrow-correction-rN.md` 续写,不改 split 恢复。
|
|
195
|
+
|
|
194
196
|
### 可见的会话阻断
|
|
195
197
|
|
|
196
198
|
宿主返回`{status:'blocked',reason:<code>,recovery:<当前recovery>,completionAuthorized:false}`,调用方先读reason与recovery,再选择原输出恢复、显式放弃或取消。
|
|
@@ -93,7 +93,7 @@ JS拥有日志、草稿保存、修订写入、自检轮次、审查记录、处
|
|
|
93
93
|
每会话只登记一次;登记不授权review或审批,已有design尝试不能改列低风险,不能重启会话重置。
|
|
94
94
|
再save_design保存整批需求和设计;仅signals任一为true的feature用final_review(stage:design)进入原9.5,
|
|
95
95
|
final_review_package只准备包,不授权调用。模式须预先选定,不在开始后改换。
|
|
96
|
-
review_findings读取结果;有发现用correct_findings,再将其packageDigest/decisions/artifacts交review_disposition
|
|
96
|
+
review_findings读取结果;有发现用correct_findings,再将其packageDigest/decisions/artifacts交review_disposition(修正后可选窄审,最多两轮,见下节「设计阶段的窄审轮次」;一旦记录窄审,须窄审通过才能处置,处置的decisions须与原修正档案一致);
|
|
97
97
|
无发现用原findings响应的packageDigest/reviewedArtifacts和空decisions写原处置回执。
|
|
98
98
|
全部需审feature处置后advance共同生成任务;低风险须无design尝试且保存正文未变,不补空审查回执。
|
|
99
99
|
保留当前整批设计与编号,再advance原自检,通过后save_draft,继续步骤3。
|
|
@@ -123,6 +123,21 @@ JS 在 checkpoint 的 `selfCheckRevision` 记录原失败及其摘要、轮次
|
|
|
123
123
|
摘要风险信息逐 feature 自动注明原因、文件、轮次及“拆分审查已审、未另做设计审查”,说明本身不阻断。
|
|
124
124
|
未使用此路径的运行不产生新字段或档案,旧 checkpoint 仍可恢复。
|
|
125
125
|
|
|
126
|
+
### 设计阶段的窄审轮次(修正后再审,最多两轮)
|
|
127
|
+
|
|
128
|
+
仅 design 阶段,仅新运行;在途运行、split 阶段不变。原 `correct_findings` 保存修正后,同一 packageDigest 下可记录窄审轮次:
|
|
129
|
+
`narrow_review {stage:"design",feature,packageDigest,round,designSha256,reviewer,sessionId,independent:true,at,verdict,summary,findings}`
|
|
130
|
+
(需 `--allow-review-write` 与 `--host-context`)。`narrow_status {stage,feature}` 只读状态。
|
|
131
|
+
|
|
132
|
+
- 轮次链:原修正档案 → 窄审1 → 修正1 → 窄审2;每轮记录是 `.reviews/prd-<feature>-design-narrow-review-rN.json`(私有、不可覆盖),修正档案是 `...-narrow-correction-rN.md`。
|
|
133
|
+
- 每条 finding 带 `severity`(blocker|major|minor) 和 security/dataLoss/silentFailure/violatesWrittenRule 四个是否题,阻断项必须写 `scenario`;任一四项为 true 或等级非 minor 即阻断。verdict 与阻断项必须一致(approved 不得含阻断,changes_requested 至少一条)。
|
|
134
|
+
- `designSha256` 必须等于磁盘上 design.md 当前字节;独立模式下 reviewer 不得是 self-degraded,sessionId 不得等于 `--host-context` 作者,也不得等于已登记过降级轮的会话;这些是来源声明,不证明真实独立。
|
|
135
|
+
- 审查模型不可用时的降级留痕:`narrow_review` 可带 `reviewer:"self-degraded"`、`independent:false`、`degradedReason`(非空)、`sessionId` 须等于 `--host-context`(作者自己复查)。降级轮占用轮次、记录里标 degraded;有阻断的降级轮照常驱动修正;**降级的 approved 不放行**,状态进入 `awaiting_user_decision`(`reason:degraded_review_only`),处置与旧入口 record 均拒绝,由用户决定。只有独立审查的 approved 才放行。审查模型恢复后,若还剩一轮(降级轮不是第 2 轮),可对同一份 design.md 字节再记一轮独立 `narrow_review`(`round`=降级轮+1,不得是降级、不得复用降级会话,记录链到降级记录):approved 放行,有阻断则停在待拍板;降级轮已是第 2 轮则无补审名额。状态里 `independentFollowUpAllowed` 指示是否可补审。
|
|
136
|
+
- 窄审有阻断 → 再调 `correct_findings`,宿主以该轮 findings 向 `prd_correct` 要提案(`review.narrowRound`),逐项 applied/escalated + 证据,只准改 design.md,存档后写入;没有对应审查记录的修正一律拒绝(`prd_narrow_review_required`),修正后须再记下一轮审查才能继续。
|
|
137
|
+
- 轮次上限 2:第 3 轮报 `prd_narrow_round_limit`。第 2 轮仍有阻断 → 状态 `awaiting_user_decision`(`narrow_review` 返回 `userDecisionRequired:true`),修正、再审、`review_disposition` 全部拒绝,宿主不提供自动放行入口,由用户决定后续。
|
|
138
|
+
- 窄审通过(approved,非阻断项进 `backlog` 随结果返回)后才能 `review_disposition`;一旦存在窄审记录,未通过时处置报 `prd_narrow_review_pending`。原一次独立审查、处置回执、自检与审批位不变;从未记录窄审时行为与旧版一致。
|
|
139
|
+
- 修正中断(档案已写、design.md 未替换)再调 `correct_findings` 即从档案续写,不重新生成。
|
|
140
|
+
|
|
126
141
|
## 恢复与退出
|
|
127
142
|
|
|
128
143
|
status只读查询;只有用户明确取消才cancel,断连不等于取消。结束发送`{type:"host_close",sessionId:"原值"}`并保留结果。
|
|
@@ -133,7 +148,7 @@ status只读查询;只有用户明确取消才cancel,断连不等于取消
|
|
|
133
148
|
|
|
134
149
|
### 拆分审查要求补正需求或设计
|
|
135
150
|
|
|
136
|
-
|
|
151
|
+
设计阶段回执不改写(设计阶段的窄审轮次见上文,split 不适用:它已有强制的原 10.5 自检,且改动含任务文件,本次未扩展)。拆分审查已经返回且尚未处置时,可在同一 feature 的原发现中列明 requirements.md 或 design.md 改动,
|
|
137
152
|
由 correct_findings 归档并保存;随后直接 review_disposition,内置原 10.5 自检。补正保存有中断仍用
|
|
138
153
|
inspect_correction / resume_correction,只认归档的原字节或提案字节,不接受第三种内容。
|
|
139
154
|
|