@aibyzero/cm-workflow 0.20.0 → 0.21.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.
Files changed (72) hide show
  1. package/.codex-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +30 -0
  3. package/README.md +8 -1
  4. package/VERSION +1 -1
  5. package/docs/installation.md +1 -1
  6. package/docs/js-workflow-control.md +1 -1
  7. package/docs/proposals/spec-amendment-tiers.md +100 -0
  8. package/package.json +1 -1
  9. package/runtime/js/acceptance-language.mjs +32 -0
  10. package/runtime/js/autonomy.mjs +15 -6
  11. package/runtime/js/cm-ai/acceptance-contract.mjs +8 -3
  12. package/runtime/js/cm-ai/checkpoint-package-material.mjs +13 -3
  13. package/runtime/js/cm-ai/cm-ai-admission.mjs +35 -2
  14. package/runtime/js/cm-ai/codex-review-adapter.mjs +19 -3
  15. package/runtime/js/cm-ai/drive-core.mjs +9 -2
  16. package/runtime/js/cm-ai/durable-runner-state.mjs +8 -4
  17. package/runtime/js/cm-ai/effect-contract.mjs +8 -1
  18. package/runtime/js/cm-ai/execution-snapshot.mjs +4 -3
  19. package/runtime/js/cm-ai/execution-store-limits.mjs +3 -3
  20. package/runtime/js/cm-ai/execution-store.mjs +7 -4
  21. package/runtime/js/cm-ai/fix-code-association.mjs +27 -6
  22. package/runtime/js/cm-ai/review-package.mjs +20 -6
  23. package/runtime/js/cm-ai/review-presentation.mjs +12 -5
  24. package/runtime/js/cm-ai/reviewed-deliveries.mjs +10 -7
  25. package/runtime/js/cm-ai/reviewed-integration.mjs +1 -1
  26. package/runtime/js/cm-ai/spec-amendment.mjs +535 -0
  27. package/runtime/js/cm-ai/task-commit.mjs +4 -2
  28. package/runtime/js/cm-ai/task-runner.mjs +26 -9
  29. package/runtime/js/cm-ai/user-maintained-paths.mjs +68 -0
  30. package/runtime/js/cm-prd/change.mjs +35 -4
  31. package/runtime/js/cm-prd/self-check.mjs +36 -6
  32. package/runtime/js/cm-prd/session.mjs +8 -3
  33. package/runtime/js/cm-prd/task-scope-record.mjs +13 -7
  34. package/runtime/js/task-scope.mjs +4 -1
  35. package/runtime/test-contract.md +1 -0
  36. package/scripts/cm-ai-acceptance-contract.test.mjs +10 -0
  37. package/scripts/cm-ai-admission.mjs +8 -2
  38. package/scripts/cm-ai-admission.test.mjs +15 -2
  39. package/scripts/cm-ai-checkpoint-package-material.test.mjs +60 -6
  40. package/scripts/cm-ai-checkpoint-package-owner.test.mjs +1 -0
  41. package/scripts/cm-ai-develop-driver-gaps.test.mjs +1 -0
  42. package/scripts/cm-ai-drive.mjs +18 -11
  43. package/scripts/cm-ai-fix-later-delivery.test.mjs +2 -2
  44. package/scripts/cm-ai-later-delivery-feature.test.mjs +102 -0
  45. package/scripts/cm-ai-review-input-limit.test.mjs +91 -0
  46. package/scripts/cm-ai-user-maintained-paths.test.mjs +183 -0
  47. package/scripts/cm-autonomy-review-r1.test.mjs +49 -0
  48. package/scripts/cm-check-runtime.sh +4 -1
  49. package/scripts/cm-drive-liveness.test.mjs +8 -0
  50. package/scripts/cm-fix-observation-task-id.test.mjs +49 -0
  51. package/scripts/cm-fix-review-storage.test.mjs +14 -4
  52. package/scripts/cm-journal-limit.test.mjs +69 -0
  53. package/scripts/cm-prd-completion.test.mjs +37 -0
  54. package/scripts/cm-prd-drive.mjs +1 -1
  55. package/scripts/cm-prd-host.test.mjs +1 -1
  56. package/scripts/cm-prd-self-check-rules.test.mjs +23 -11
  57. package/scripts/cm-prd-self-check.test.mjs +24 -1
  58. package/scripts/cm-prd-summary.test.mjs +6 -0
  59. package/scripts/cm-review-inventory.test.mjs +5 -1
  60. package/scripts/cm-spec-amend.mjs +68 -0
  61. package/scripts/cm-spec-amend.test.mjs +510 -0
  62. package/scripts/cm-specs-status.test.mjs +6 -0
  63. package/scripts/cm-start-check.mjs +82 -2
  64. package/scripts/cm-start-check.test.mjs +64 -1
  65. package/scripts/cm-task-scope.test.mjs +3 -2
  66. package/scripts/test-journal-limit-1mib.mjs +4 -0
  67. package/scripts/validate-public-repo.py +4 -0
  68. package/skills/cm-ai/references/N1-init.md +23 -1
  69. package/skills/cm-ai/references/js-host-qa-recovery.md +3 -2
  70. package/skills/cm-ai/references/js-host-recovery.md +2 -1
  71. package/skills/cm-ai/references/js-host.md +2 -1
  72. package/skills/cm-prd/references/js-change-recovery.md +1 -0
@@ -0,0 +1,535 @@
1
+ // Tiered re-approval for in-flight spec corrections (docs/proposals/spec-amendment-tiers.md).
2
+ // A human "开始" binds a snapshot of the approved spec bytes. A later edit that keeps
3
+ // requirements, design, existing test cases and finished tasks intact (tier 1) can be
4
+ // re-bound after an independent review instead of another "开始"; a change that only
5
+ // appends version-table rows to tasks.md (tier 0) needs no review. Everything else
6
+ // (tier 2) still waits for the user. The snapshot and the receipt are guidance-level
7
+ // evidence, like .cm-specs-status itself: they bind content, not who wrote them.
8
+ import fs from 'node:fs';
9
+ import path from 'node:path';
10
+ import os from 'node:os';
11
+ import {createHash,randomUUID} from 'node:crypto';
12
+ import {readSpecsStatus,writeSpecsStatus} from '../specs-status.mjs';
13
+ import {buildManifest,normalizeRuntimeMarkBytes} from '../../../scripts/cm-spec-manifest.mjs';
14
+ import {taskLines,recordedTaskGrammar,LEGACY_TASK_GRAMMAR} from '../spec-task-line.mjs';
15
+ import {taskNames,acceptanceLanguage,weakensLanguage,versionNote,plainVersionNote,testingLanguage} from '../acceptance-language.mjs';
16
+
17
+ export const SNAPSHOT_FILE='.cm-specs-approved.json';
18
+ export const LOCK_FILE='.cm-specs-approval.lock';
19
+ // The round ledger lives outside the specs tree (CM_WORKFLOW_HOME, default
20
+ // ~/.cm-workflow) and names the latest human approval round and its snapshot bytes,
21
+ // so restoring an older snapshot (or a backup / git checkout of the specs directory)
22
+ // cannot revive an earlier authorization or policy.
23
+ export function roundLedgerPath(specsDir){
24
+ const home=path.resolve(process.env.CM_WORKFLOW_HOME||path.join(os.homedir(),'.cm-workflow'));
25
+ return path.join(home,'spec-approvals',`${sha(fs.realpathSync(specsDir))}.json`);
26
+ }
27
+ export const AMEND_LIMIT=3;
28
+ export const REVIEW_MARKER='cmSpecAmendReview';
29
+ const FILES=['requirements.md','design.md','tasks.md','test-cases.json'];
30
+ const FEATURE=/^\d+\.[^/\\]+$/;
31
+ const ACCEPTANCE=/^\s*[-*]\s+(?:\[[ xX]\]\s+)?(?:\[(AC-\d{3,})\]|(AC-\d{3,}))(?=[:\s])/;
32
+ const AC_REF=/AC-\d{3,}/g;
33
+ const DEPENDENCY=/^\s*-\s*(T-[A-Za-z0-9][A-Za-z0-9._-]*)\s+依赖\s+(.+)$/;
34
+ const record=value=>value!==null&&typeof value==='object'&&!Array.isArray(value);
35
+ const iso=value=>typeof value==='string'&&/^\d{4}-\d\d-\d\dT/.test(value)&&Number.isFinite(Date.parse(value));
36
+ const sha=value=>createHash('sha256').update(value).digest('hex');
37
+ const compare=(a,b)=>Buffer.compare(Buffer.from(a),Buffer.from(b));
38
+ const fail=code=>{throw Object.assign(new Error(code),{code});};
39
+ const rowsDigest=rows=>sha(JSON.stringify(rows.map(row=>[row.path,row.sha256])));
40
+
41
+ // Stable JSON so test-case comparison ignores key order but nothing else.
42
+ function stable(value){
43
+ if(Array.isArray(value))return `[${value.map(stable).join(',')}]`;
44
+ if(record(value))return `{${Object.keys(value).sort().map(key=>`${JSON.stringify(key)}:${stable(value[key])}`).join(',')}}`;
45
+ return JSON.stringify(value);
46
+ }
47
+
48
+ function atomicWrite(dir,name,bytes){
49
+ const target=path.join(dir,name),temporary=path.join(dir,`${name}-${randomUUID()}`);let fd;
50
+ try{
51
+ fd=fs.openSync(temporary,'wx',0o600);fs.writeFileSync(fd,bytes);fs.fsyncSync(fd);fs.closeSync(fd);fd=undefined;
52
+ fs.renameSync(temporary,target);
53
+ }finally{
54
+ if(fd!==undefined)fs.closeSync(fd);
55
+ try{fs.unlinkSync(temporary);}catch(error){if(error.code!=='ENOENT')throw error;}
56
+ }
57
+ }
58
+
59
+ function captureFiles(specsDir,features){
60
+ const files=[];
61
+ for(const name of features)for(const file of FILES){
62
+ const target=path.join(specsDir,name,file);
63
+ let stat;
64
+ try{stat=fs.lstatSync(target);}catch(error){if(error.code==='ENOENT'&&file==='test-cases.json')continue;throw error;}
65
+ if(stat.isSymbolicLink()||!stat.isFile())fail('spec_amend_file_invalid');
66
+ const bytes=fs.readFileSync(target),content=bytes.toString('utf8');
67
+ // The snapshot stores text; bytes that do not round-trip cannot be compared later.
68
+ if(!Buffer.from(content,'utf8').equals(bytes))fail('spec_amend_file_not_utf8');
69
+ files.push({path:`${name}/${file}`,content});
70
+ }
71
+ return files;
72
+ }
73
+
74
+ function snapshotRows(files){
75
+ return files.map(item=>({path:item.path,
76
+ sha256:sha(normalizeRuntimeMarkBytes(Buffer.from(item.content,'utf8'),path.posix.basename(item.path)))}))
77
+ .sort((a,b)=>compare(a.path,b.path));
78
+ }
79
+
80
+ // Called by the explicit human approval. `policy: 'off'` keeps the old behaviour:
81
+ // every later spec change waits for "开始".
82
+ export function writeApprovalSnapshot(specsDir,{features,specFiles,approval,policy='reviewed'}){
83
+ if(!['reviewed','off'].includes(policy))fail('spec_amend_policy_invalid');
84
+ const files=captureFiles(specsDir,features);
85
+ // Bytes read after the manifest was built must be the bytes that manifest approved.
86
+ if(rowsDigest(snapshotRows(files))!==rowsDigest(specFiles))fail('spec_amend_snapshot_race');
87
+ const value={version:1,policy,features:[...features],approval:{response:approval.response,at:approval.at},
88
+ amendments:[],rowsDigest:rowsDigest(specFiles),files};
89
+ const bytes=Buffer.from(JSON.stringify(value)+'\n');
90
+ atomicWrite(specsDir,SNAPSHOT_FILE,bytes);
91
+ writeRound(specsDir,value.approval.at,bytes);
92
+ return {policy,files:files.length};
93
+ }
94
+
95
+ function writeRound(specsDir,approvalAt,snapshotBytes){
96
+ const target=roundLedgerPath(specsDir);
97
+ fs.mkdirSync(path.dirname(target),{recursive:true,mode:0o700});
98
+ atomicWrite(path.dirname(target),path.basename(target),
99
+ Buffer.from(JSON.stringify({version:1,specsDir:fs.realpathSync(specsDir),approvalAt,snapshotSha256:sha(snapshotBytes)})+'\n'));
100
+ }
101
+
102
+ function invalidateRound(specsDir){
103
+ try{fs.unlinkSync(roundLedgerPath(specsDir));}
104
+ catch(error){if(error.code!=='ENOENT')fail('spec_amend_round_unremovable');}
105
+ }
106
+
107
+ function readRound(specsDir){
108
+ try{return fs.readFileSync(roundLedgerPath(specsDir));}catch{return null;}
109
+ }
110
+
111
+ function roundProblem(roundBytes,snapshotBytes,approvalAt){
112
+ if(roundBytes===null)return 'snapshot_round_missing';
113
+ let value;try{value=JSON.parse(roundBytes.toString('utf8'));}catch{return 'snapshot_round_mismatch';}
114
+ return record(value)&&value.version===1&&value.approvalAt===approvalAt&&snapshotBytes!==null
115
+ &&value.snapshotSha256===sha(snapshotBytes)?null:'snapshot_round_mismatch';
116
+ }
117
+
118
+ // A new human approval first removes the previous round's snapshot, so a failed
119
+ // snapshot write can never leave an older round (or its policy) in force.
120
+ export function removeApprovalSnapshot(specsDir){
121
+ invalidateRound(specsDir);
122
+ try{fs.unlinkSync(path.join(specsDir,SNAPSHOT_FILE));}
123
+ catch(error){if(error.code!=='ENOENT')fail('spec_amend_snapshot_unremovable');}
124
+ }
125
+
126
+ function processAlive(pid){
127
+ try{process.kill(pid,0);return true;}catch(error){return error.code==='EPERM';}
128
+ }
129
+
130
+ // Creates `target` holding `bytes` only if it does not exist. The bytes are
131
+ // complete before the name appears (temp file + link), so a lock is never seen
132
+ // empty or without its owner's pid, even while its creator is paused.
133
+ function createComplete(target,bytes){
134
+ const temp=`${target}.${randomUUID()}.tmp`;
135
+ let linked=false;
136
+ try{
137
+ fs.writeFileSync(temp,bytes,{mode:0o600,flag:'wx'});
138
+ try{fs.linkSync(temp,target);linked=true;}
139
+ catch(error){if(error.code!=='EEXIST')throw error;}
140
+ }finally{
141
+ try{fs.unlinkSync(temp);}
142
+ catch(error){
143
+ if(error.code!=='ENOENT'){
144
+ // The caller never learns it holds `target`, so withdraw it before failing:
145
+ // it is this call's own fresh link, which no one else may remove.
146
+ if(linked)try{fs.unlinkSync(target);}catch{}
147
+ throw error;
148
+ }
149
+ }
150
+ }
151
+ return linked;
152
+ }
153
+
154
+ // Serializes human approval and amendment re-binding in one specs directory.
155
+ // cm-prd does not take this lock; apply also re-checks status bytes before rename.
156
+ export function withApprovalLock(specsDir,run){
157
+ const target=path.join(specsDir,LOCK_FILE),guard=`${target}.reclaim`;
158
+ // A nonce makes every acquisition's bytes unique, so a releaser can tell its
159
+ // own lock from any other one at the same path.
160
+ const owner=()=>Buffer.from(JSON.stringify({pid:process.pid,nonce:randomUUID(),at:new Date().toISOString()}));
161
+ const mine=owner();
162
+ for(let attempt=0;attempt<2;attempt++){
163
+ if(!createComplete(target,mine)){
164
+ if(attempt>0)fail('spec_approval_busy');
165
+ // Only the holder of the reclaim guard may delete another process's lock,
166
+ // and only when its recorded pid is gone. A live owner is never judged
167
+ // stale, a dead owner cannot release, and every lock carries its pid from
168
+ // the moment it exists, so the lock path is never emptied under a live
169
+ // holder. A lock without a readable pid, or a guard left by a crash, is
170
+ // never reclaimed automatically (see N1-init「执行中补正分级」).
171
+ if(!createComplete(guard,owner()))fail('spec_approval_busy');
172
+ try{
173
+ let seen;
174
+ try{seen=fs.readFileSync(target);}
175
+ catch(readError){if(readError.code==='ENOENT')continue;throw readError;}
176
+ let holder=null;
177
+ try{holder=JSON.parse(seen.toString('utf8'));}catch{}
178
+ if(!(Number.isInteger(holder?.pid)&&holder.pid>0&&!processAlive(holder.pid)))fail('spec_approval_busy');
179
+ // The holder may have released, and a new holder taken the lock, between
180
+ // the read and the pid check. Only the very bytes judged dead are removed:
181
+ // a dead holder cannot release any more, and other reclaimers wait on the guard.
182
+ let current=null;
183
+ try{current=fs.readFileSync(target);}catch(readError){if(readError.code!=='ENOENT')throw readError;}
184
+ if(current===null)continue;
185
+ if(!current.equals(seen))fail('spec_approval_busy');
186
+ fs.unlinkSync(target);
187
+ }finally{
188
+ try{fs.unlinkSync(guard);}catch{}
189
+ }
190
+ continue;
191
+ }
192
+ try{
193
+ return run();
194
+ }finally{
195
+ // Release only this acquisition's lock, never one that replaced it.
196
+ try{if(fs.readFileSync(target).equals(mine))fs.unlinkSync(target);}catch{}
197
+ }
198
+ }
199
+ fail('spec_approval_busy');
200
+ }
201
+
202
+ export function readApprovalSnapshot(specsDir){
203
+ const target=path.join(specsDir,SNAPSHOT_FILE);
204
+ let stat;
205
+ try{stat=fs.lstatSync(target);}catch(error){return {kind:error.code==='ENOENT'?'missing':'invalid'};}
206
+ try{
207
+ if(stat.isSymbolicLink()||!stat.isFile())fail('invalid');
208
+ const value=JSON.parse(fs.readFileSync(target,'utf8'));
209
+ const valid=record(value)&&value.version===1&&['reviewed','off'].includes(value.policy)
210
+ &&Array.isArray(value.features)&&value.features.length>0&&value.features.every(name=>typeof name==='string'&&FEATURE.test(name))
211
+ &&new Set(value.features).size===value.features.length
212
+ &&record(value.approval)&&typeof value.approval.response==='string'&&value.approval.response.trim()!==''&&iso(value.approval.at)
213
+ &&Array.isArray(value.amendments)&&value.amendments.every(item=>record(item)&&[0,1].includes(item.tier))
214
+ &&Array.isArray(value.files)&&value.files.every(item=>record(item)&&typeof item.path==='string'
215
+ &&typeof item.content==='string'&&value.features.includes(item.path.split('/')[0])
216
+ &&item.path.split('/').length===2&&FILES.includes(item.path.split('/')[1]))
217
+ &&new Set(value.files.map(item=>item.path)).size===value.files.length
218
+ // Self digest: a snapshot edited by hand (e.g. synced to current specs) is invalid.
219
+ &&value.rowsDigest===rowsDigest(snapshotRows(value.files));
220
+ return valid?{kind:'valid',value}:{kind:'invalid'};
221
+ }catch{return {kind:'invalid'};}
222
+ }
223
+
224
+ function acceptanceIds(text){
225
+ return new Set(text.split(/\r?\n/).map(line=>line.match(ACCEPTANCE)).filter(Boolean).map(match=>match[1]||match[2]));
226
+ }
227
+
228
+ // A task block runs from its declaration to the next declaration, heading,
229
+ // dependency line or non-indented text; blank lines and fenced lines inside stay
230
+ // in the block (a blank line must not split off a finished task's verification).
231
+ function taskStructure(text,grammar){
232
+ const tasks=new Map(),dependencies=new Map(),prose=[];let current=null;
233
+ for(const line of taskLines(text,{grammar})){
234
+ const body=line.body.replace(/\s+$/,'');
235
+ if(!line.fenced&&line.declaration){
236
+ current={id:line.declaration.id,completed:line.declaration.completed,
237
+ dropped:/\[DROPPED(?:\s[^\]]*)?\]/.test(line.declaration.rest),
238
+ lines:[body.replace(/^(\s*-\s*(?:~~)?)\[[xX]\]/,'$1[ ]')]};
239
+ if(tasks.has(current.id))fail('spec_amend_tasks_invalid');
240
+ tasks.set(current.id,current);continue;
241
+ }
242
+ const dependency=line.fenced?null:body.match(DEPENDENCY);
243
+ const ends=dependency||(!line.fenced&&(/^\s{0,3}#/.test(body)||/^\S/.test(body)));
244
+ if(current&&!ends){current.lines.push(body);continue;}
245
+ current=null;
246
+ if(dependency){dependencies.set(dependency[1],dependency[2].trim());continue;}
247
+ prose.push(body);
248
+ }
249
+ for(const task of tasks.values()){
250
+ while(task.lines.length>1&&task.lines.at(-1)==='')task.lines.pop();
251
+ task.text=task.lines.join('\n');task.acceptance=new Set(task.text.match(AC_REF)??[]);
252
+ }
253
+ return {tasks,dependencies,prose};
254
+ }
255
+
256
+ // Tier 0 allows only appended rows in a "版本"/"Version" table: every other line
257
+ // stays identical and every earlier version row is kept.
258
+ function splitVersionRows(lines){
259
+ const body=[],rows=[];let versionSection=false;
260
+ for(const line of lines){
261
+ const heading=/^\s{0,3}#{1,6}\s+(.*)$/.exec(line);
262
+ if(heading)versionSection=/版本|version/i.test(heading[1]);
263
+ if(versionSection&&/^\s*\|/.test(line)){rows.push(line);continue;}
264
+ if(line.trim()!=='')body.push(line);
265
+ }
266
+ return {body,rows};
267
+ }
268
+ // Returns the appended version rows, or null when anything else changed.
269
+ function appendedVersionRows(oldLines,newLines){
270
+ const old=splitVersionRows(oldLines),next=splitVersionRows(newLines);
271
+ if(JSON.stringify(old.body)!==JSON.stringify(next.body))return null;
272
+ if(JSON.stringify(next.rows.slice(0,old.rows.length))!==JSON.stringify(old.rows))return null;
273
+ return next.rows.slice(old.rows.length);
274
+ }
275
+
276
+ function compareTestCases(before,after,reasons,name){
277
+ if(before===undefined)return;
278
+ if(after===undefined){reasons.push(`test_cases_removed:${name}`);return;}
279
+ let old,next;
280
+ try{old=JSON.parse(before);next=JSON.parse(after);}catch{reasons.push(`test_cases_invalid:${name}`);return;}
281
+ if(!record(old)||!record(next)||!Array.isArray(old.cases)||!Array.isArray(next.cases)){reasons.push(`test_cases_invalid:${name}`);return;}
282
+ const {cases:oldCases,...oldRest}=old,{cases:newCases,...newRest}=next;
283
+ if(stable(oldRest)!==stable(newRest))reasons.push(`test_cases_changed:${name}`);
284
+ const byId=new Map(newCases.filter(record).map(item=>[item.id,item]));
285
+ for(const item of oldCases){
286
+ const match=record(item)?byId.get(item.id):undefined;
287
+ if(!match||stable(match)!==stable(item)){reasons.push(`test_case_changed:${name}/${record(item)?item.id:'?'}`);}
288
+ }
289
+ }
290
+
291
+ // Classifies the difference between the bound snapshot and the current spec files.
292
+ // tier null: nothing to re-bind; 0: version rows only; 1: reviewed correction; 2: human.
293
+ const rawBytes=target=>{try{return fs.readFileSync(target);}catch{return null;}};
294
+ const sameBytes=(a,b)=>a===null?b===null:b!==null&&a.equals(b);
295
+
296
+ export function inspectSpecAmendment(specsDir){
297
+ const reasons=[],statusPath=path.join(specsDir,'.cm-specs-status'),snapshotPath=path.join(specsDir,SNAPSHOT_FILE);
298
+ const statusBytes=rawBytes(statusPath),snapshotBytes=rawBytes(snapshotPath),roundBytes=readRound(specsDir);
299
+ const status=readSpecsStatus(specsDir),snapshot=readApprovalSnapshot(specsDir);
300
+ const human=(...why)=>({tier:2,reasons:why,changedFiles:[],changedTasks:[],newTasks:[],deltaDigest:null});
301
+ if(!sameBytes(statusBytes,rawBytes(statusPath))||!sameBytes(snapshotBytes,rawBytes(snapshotPath))
302
+ ||!sameBytes(roundBytes,readRound(specsDir)))return human('spec_status_changed_during_inspect');
303
+ if(status.kind!=='valid')return human(`spec_status_${status.kind}`);
304
+ if(snapshot.kind!=='valid')return human(snapshot.kind==='missing'?'snapshot_missing':'snapshot_invalid');
305
+ const bound=snapshot.value,baseRows=snapshotRows(bound.files);
306
+ const round=roundProblem(roundBytes,snapshotBytes,bound.approval.at);
307
+ if(round)return human(round);
308
+ // While approved, the snapshot must be this approval round's content. After a
309
+ // cm-prd reset to awaiting_review the round is no longer recorded in status;
310
+ // the snapshot's self digest is then the only anchor (guidance-level, see docs).
311
+ if(status.value.status==='approved'&&(rowsDigest(status.value.specFiles??[])!==rowsDigest(baseRows)
312
+ ||status.value.approval?.at!==bound.approval.at))return human('snapshot_status_mismatch');
313
+ let currentRows;
314
+ try{currentRows=buildManifest(specsDir);}catch{return human('spec_files_invalid');}
315
+ const baseByPath=new Map(baseRows.map(row=>[row.path,row.sha256]));
316
+ const currentByPath=new Map(currentRows.map(row=>[row.path,row.sha256]));
317
+ const changedFiles=[...new Set([...baseByPath.keys(),...currentByPath.keys()])]
318
+ .filter(file=>baseByPath.get(file)!==currentByPath.get(file)).sort(compare);
319
+ const deltaDigest=sha(JSON.stringify({base:rowsDigest(baseRows),current:rowsDigest(currentRows),amendments:bound.amendments.length}));
320
+ const features=[...new Set(currentRows.map(row=>row.path.split('/')[0]))].sort(compare);
321
+ const boundFeatures=[...bound.features].sort(compare);
322
+ if(JSON.stringify(features)!==JSON.stringify(boundFeatures))return {...human('feature_set_changed'),changedFiles};
323
+ // Every later step (packet, review digest, re-bind) uses these exact bytes.
324
+ let currentFiles;
325
+ try{currentFiles=captureFiles(specsDir,features);}catch(error){return human(error.code??'spec_files_invalid');}
326
+ if(rowsDigest(snapshotRows(currentFiles))!==rowsDigest(currentRows))return human('spec_changed_during_inspect');
327
+ // Parse and re-bind with the grammar this approval round bound (2 or 3), never
328
+ // the newest constant: a grammar-2 「开发: 会话」 line must stay prose.
329
+ const grammar=recordedTaskGrammar(status.value.taskGrammar);
330
+ if(grammar===LEGACY_TASK_GRAMMAR)return {...human('task_grammar_legacy'),changedFiles};
331
+ const outcome=(tier,extra={})=>({tier,reasons,changedFiles,changedTasks:[],newTasks:[],deltaDigest,
332
+ currentRows,currentFiles,baseRows,snapshot:bound,status:status.value,statusBytes,snapshotBytes,roundBytes,...extra});
333
+ if(!changedFiles.length)return outcome(status.value.status==='approved'?null:0);
334
+ const current=new Map(currentFiles.map(item=>[item.path,item.content]));
335
+ const before=new Map(bound.files.map(item=>[item.path,item.content]));
336
+ const changedTasks=[],newTasks=[];let tasksOnlyVersionRows=true;
337
+ for(const name of features){
338
+ for(const file of ['requirements.md','design.md'])
339
+ if(changedFiles.includes(`${name}/${file}`))reasons.push(`${file.replace('.md','')}_changed:${name}`);
340
+ if(changedFiles.includes(`${name}/test-cases.json`)){
341
+ tasksOnlyVersionRows=false;
342
+ compareTestCases(before.get(`${name}/test-cases.json`),current.get(`${name}/test-cases.json`),reasons,name);
343
+ }
344
+ if(!changedFiles.includes(`${name}/tasks.md`))continue;
345
+ const oldText=before.get(`${name}/tasks.md`),newText=current.get(`${name}/tasks.md`);
346
+ let old,next;
347
+ try{old=taskStructure(oldText,grammar);next=taskStructure(newText,grammar);}catch{reasons.push(`tasks_invalid:${name}`);continue;}
348
+ const resetLines=text=>text.split(/\r?\n/).map(line=>line.replace(/^(\s*-\s*(?:~~)?)\[[xX]\]/,'$1[ ]').replace(/\s+$/,''));
349
+ const appended=appendedVersionRows(resetLines(oldText),resetLines(newText));
350
+ if(appended===null)tasksOnlyVersionRows=false;
351
+ else for(const row of appended){
352
+ const note=versionNote(row);
353
+ const affected=taskNames(note).find(id=>old.tasks.has(id));
354
+ // Same rule as the standing authorization: a version note that states or
355
+ // weakens acceptance for an existing task is a requirement change (tier 2).
356
+ if(affected&&(acceptanceLanguage(note)||weakensLanguage(note)||testingLanguage(note))){
357
+ reasons.push(`version_row_changes_acceptance:${name}/${affected}`);continue;}
358
+ // Only a note made entirely of "unchanged" statements stays tier 0
359
+ // (plainVersionNote); every other note goes to review (tier 1).
360
+ if(affected||!plainVersionNote(note))tasksOnlyVersionRows=false;
361
+ }
362
+ const declared=acceptanceIds(current.get(`${name}/requirements.md`)??'');
363
+ for(const [id,task] of old.tasks){
364
+ const now=next.tasks.get(id);
365
+ if(!now){reasons.push(`task_removed:${name}/${id}`);continue;}
366
+ if(now.dropped!==task.dropped){reasons.push(`task_${now.dropped?'dropped':'restored'}:${name}/${id}`);continue;}
367
+ if(task.completed&&!now.completed){reasons.push(`task_reopened:${name}/${id}`);continue;}
368
+ const finished=task.completed||now.completed;
369
+ if(task.text!==now.text||old.dependencies.get(id)!==next.dependencies.get(id)){
370
+ if(finished){reasons.push(`completed_task_changed:${name}/${id}`);continue;}
371
+ const lost=[...task.acceptance].filter(ac=>!now.acceptance.has(ac));
372
+ if(lost.length)reasons.push(`task_acceptance_removed:${name}/${id}:${lost.join(',')}`);
373
+ changedTasks.push(`${name}/${id}`);
374
+ }
375
+ }
376
+ for(const [id,task] of next.tasks){
377
+ if(old.tasks.has(id))continue;
378
+ if(task.completed){reasons.push(`new_task_completed:${name}/${id}`);continue;}
379
+ if(!task.dropped){
380
+ if(!task.acceptance.size)reasons.push(`new_task_without_acceptance:${name}/${id}`);
381
+ const unknown=[...task.acceptance].filter(ac=>!declared.has(ac));
382
+ if(unknown.length)reasons.push(`new_task_unknown_acceptance:${name}/${id}:${unknown.join(',')}`);
383
+ }
384
+ newTasks.push(`${name}/${id}`);
385
+ }
386
+ }
387
+ if(reasons.length)return outcome(2,{changedTasks,newTasks});
388
+ if(bound.policy==='off')return {...outcome(2,{changedTasks,newTasks}),reasons:['amend_policy_off']};
389
+ const onlyTasks=changedFiles.every(file=>file.endsWith('/tasks.md'));
390
+ if(onlyTasks&&tasksOnlyVersionRows)return outcome(0,{changedTasks,newTasks});
391
+ if(bound.amendments.filter(item=>item.tier===1).length>=AMEND_LIMIT)
392
+ return {...outcome(2,{changedTasks,newTasks}),reasons:['amend_limit_reached']};
393
+ return outcome(1,{changedTasks,newTasks});
394
+ }
395
+
396
+ export function publicAmendment(result){
397
+ const {currentRows,currentFiles,baseRows,snapshot,status,statusBytes,snapshotBytes,roundBytes,...rest}=result;
398
+ return rest;
399
+ }
400
+
401
+ const PROMPT=`你是 CM 规格补正的独立审查者。你没有写这次补正,也不能改任何文件。
402
+
403
+ before/ 是用户上次回复「开始」时批准的规格,after/ 是现在的规格。先运行:
404
+ diff -ru before after
405
+
406
+ context/ 是涉及的 feature 里没有改动的规格文件(需求、设计等),内容与批准时相同(不计勾选状态),只供对照。
407
+ 判断下面第 1 条时,先读 context/ 里的需求和设计,再看补正是在落实它们,还是在改变它们。
408
+
409
+ 工具已用机器核对过以下条件,全部成立:
410
+ - requirements.md、design.md 未变;
411
+ - test-cases.json 只新增用例,原有用例逐字不变;
412
+ - 已完成任务逐字不变,没有删除或作废任务;
413
+ - 新增任务引用了 requirements.md 里已有的验收标准编号;
414
+ - 改过的未完成任务没有丢掉原来引用的验收标准编号。
415
+
416
+ 你只判断机器判断不了的两件事:
417
+ 1. 这次补正是不是「执行中的补漏」:补测试文件进范围、为已有验收标准补修复任务、拆分或重排未完成任务、修正写法。
418
+ 如果它引入了新的产品行为、改变了用户能看到的需求、或者改变了已批准的设计取舍,判 changes_requested。
419
+ 2. 有没有削弱验证:删减「验证」「测试文件」里的检查、放宽断言、缩小原有检查范围、把必须人工确认的事改成自动通过。
420
+ 有任何一处,判 changes_requested。
421
+
422
+ 拿不准时判 changes_requested,补正就会退回给用户本人批准,不会丢失。
423
+
424
+ 最后一行只输出一行 JSON,不要加代码块:
425
+ {"${REVIEW_MARKER}":1,"deltaDigest":"{DELTA}","verdict":"approved 或 changes_requested","findings":["每条一句中文"]}
426
+ `;
427
+
428
+ // Writes before/ and after/ copies, the unchanged files of the touched features
429
+ // (context/), and the review prompt into a fresh directory outside the specs tree,
430
+ // so the reviewer reads exactly the classified bytes. Dogfood (wue v4, 2026-11-04):
431
+ // the amendment aligned tasks.md with design.md, which a reviewer cannot judge
432
+ // without the unchanged design.
433
+ export function prepareSpecAmendment(specsDir,{outDir}={}){
434
+ const result=inspectSpecAmendment(specsDir);
435
+ const summary=publicAmendment(result);
436
+ if(result.tier!==1)return {...summary,packet:null};
437
+ if(typeof outDir!=='string'||!outDir)fail('spec_amend_out_required');
438
+ const root=path.resolve(outDir);
439
+ if(fs.existsSync(root)&&fs.readdirSync(root).length)fail('spec_amend_out_not_empty');
440
+ const specsRoot=fs.realpathSync(specsDir);
441
+ fs.mkdirSync(root,{recursive:true});
442
+ const realRoot=fs.realpathSync(root),relative=path.relative(specsRoot,realRoot);
443
+ if(relative===''||(relative!=='..'&&!relative.startsWith(`..${path.sep}`)&&!path.isAbsolute(relative))){fs.rmSync(root,{recursive:true,force:true});fail('spec_amend_out_inside_specs');}
444
+ const before=new Map(result.snapshot.files.map(item=>[item.path,item.content]));
445
+ const after=new Map(result.currentFiles.map(item=>[item.path,item.content]));
446
+ const write=(side,file,content)=>{
447
+ const target=path.join(realRoot,side,file);
448
+ fs.mkdirSync(path.dirname(target),{recursive:true});fs.writeFileSync(target,content);
449
+ // The reviewer must read exactly the bytes the digest was computed from.
450
+ if(fs.readFileSync(target,'utf8')!==content)fail('spec_amend_packet_mismatch');
451
+ };
452
+ fs.mkdirSync(path.join(realRoot,'before'),{recursive:true});fs.mkdirSync(path.join(realRoot,'after'),{recursive:true});
453
+ for(const file of result.changedFiles){
454
+ if(before.has(file))write('before',file,before.get(file));
455
+ if(after.has(file))write('after',file,after.get(file));
456
+ }
457
+ const changed=new Set(result.changedFiles),features=new Set(result.changedFiles.map(file=>file.split('/')[0]));
458
+ for(const [file,content] of after){
459
+ if(!changed.has(file)&&features.has(file.split('/')[0]))write('context',file,content);
460
+ }
461
+ const prompt=PROMPT.replace('{DELTA}',result.deltaDigest);
462
+ fs.writeFileSync(path.join(realRoot,'review-prompt.md'),prompt);
463
+ return {...summary,packet:{dir:realRoot,prompt:path.join(realRoot,'review-prompt.md')}};
464
+ }
465
+
466
+ export function readReviewVerdict(text,deltaDigest){
467
+ const lines=String(text).split(/\r?\n/).map(line=>line.trim()).filter(Boolean);
468
+ for(let index=lines.length-1;index>=0;index--){
469
+ if(!lines[index].includes(REVIEW_MARKER))continue;
470
+ let value;try{value=JSON.parse(lines[index]);}catch{return {ok:false,reason:'review_output_invalid'};}
471
+ if(!record(value)||value[REVIEW_MARKER]!==1)return {ok:false,reason:'review_output_invalid'};
472
+ if(value.deltaDigest!==deltaDigest)return {ok:false,reason:'review_delta_mismatch'};
473
+ if(value.verdict!=='approved')return {ok:false,reason:'review_not_approved',findings:Array.isArray(value.findings)?value.findings:[]};
474
+ return {ok:true,findings:Array.isArray(value.findings)?value.findings:[]};
475
+ }
476
+ return {ok:false,reason:'review_output_missing'};
477
+ }
478
+
479
+ // Re-binds the approval to the current spec files when the tier allows it. Status is
480
+ // written before the snapshot: if the snapshot write fails, the two disagree and the
481
+ // next inspection falls back to tier 2 (human approval) instead of trusting stale bytes.
482
+ export function applySpecAmendment(specsDir,options={}){
483
+ const {reason}=options;
484
+ if(typeof reason!=='string'||!reason.trim()||/[\r\n\0]/.test(reason))fail('spec_amend_reason_required');
485
+ return withApprovalLock(specsDir,()=>applyLocked(specsDir,options));
486
+ }
487
+
488
+ function applyLocked(specsDir,{reason,reviewOutput,reviewer}){
489
+ const result=inspectSpecAmendment(specsDir);
490
+ const summary=publicAmendment(result);
491
+ if(result.tier===null)return {...summary,applied:false,refused:'spec_amend_nothing_to_apply'};
492
+ if(result.tier===2)return {...summary,applied:false,refused:'spec_amend_needs_human'};
493
+ let findings=[];
494
+ if(result.tier===1){
495
+ if(typeof reviewOutput!=='string')return {...summary,applied:false,refused:'review_output_required'};
496
+ if(typeof reviewer!=='string'||!reviewer.trim()||/[\r\n\0]/.test(reviewer))return {...summary,applied:false,refused:'reviewer_required'};
497
+ const verdict=readReviewVerdict(reviewOutput,result.deltaDigest);
498
+ if(!verdict.ok)return {...summary,applied:false,refused:verdict.reason,...(verdict.findings?{findings:verdict.findings}:{})};
499
+ findings=verdict.findings;
500
+ }
501
+ const features=[...result.snapshot.features],files=result.currentFiles;
502
+ const at=new Date().toISOString(),status=result.status;
503
+ // Final ownership check right before the status rename: same status round, same
504
+ // snapshot, same spec bytes as classified (cm-prd does not share the lock).
505
+ const unchanged=()=>sameBytes(result.statusBytes,rawBytes(path.join(specsDir,'.cm-specs-status')))
506
+ &&sameBytes(result.snapshotBytes,rawBytes(path.join(specsDir,SNAPSHOT_FILE)))
507
+ &&sameBytes(result.roundBytes,readRound(specsDir))
508
+ &&rowsDigest(buildManifest(specsDir))===rowsDigest(result.currentRows)
509
+ &&rowsDigest(snapshotRows(captureFiles(specsDir,features)))===rowsDigest(result.currentRows);
510
+ try{
511
+ writeSpecsStatus(specsDir,{status:'approved',summaryDigest:status.summaryDigest??null,at,features,
512
+ specFiles:result.currentRows,testCases:result.currentRows.filter(item=>item.path.endsWith('/test-cases.json')),
513
+ approval:result.snapshot.approval,taskGrammar:recordedTaskGrammar(status.taskGrammar),
514
+ ...(Object.hasOwn(status,'revisionDigest')?{revisionDigest:status.revisionDigest}:{})},
515
+ {beforeRename:()=>{
516
+ if(!unchanged())fail('spec_changed_during_apply');
517
+ // Void the current round first: if anything below fails, no snapshot of this
518
+ // or an earlier round matches the ledger, so every later change is tier 2.
519
+ invalidateRound(specsDir);
520
+ }});
521
+ }catch(error){
522
+ if(error.code==='spec_changed_during_apply')return {...summary,applied:false,refused:'spec_changed_during_apply'};
523
+ throw error;
524
+ }
525
+ const amendment={at,tier:result.tier,reason:reason.trim(),deltaDigest:result.deltaDigest,files:result.changedFiles,
526
+ ...(result.tier===1?{reviewer:reviewer.trim(),findings}:{})};
527
+ const value={...result.snapshot,amendments:[...result.snapshot.amendments,amendment],
528
+ rowsDigest:rowsDigest(result.currentRows),files};
529
+ // Round voided, then status, snapshot, round: a failure in between leaves no
530
+ // ledger entry, which inspection treats as tier 2 even after a cm-prd reset.
531
+ const bytes=Buffer.from(JSON.stringify(value)+'\n');
532
+ atomicWrite(specsDir,SNAPSHOT_FILE,bytes);
533
+ writeRound(specsDir,value.approval.at,bytes);
534
+ return {...summary,applied:true,amendment};
535
+ }
@@ -6,7 +6,7 @@ import { types } from 'node:util';
6
6
  import {createRequire} from 'node:module';
7
7
  import { verifyCompletionReviewPackage,reviewSpecsPath } from './review-package.mjs';
8
8
  import { checkCompletion } from './gate-bridge.mjs';
9
- import { need,shape,json,digest,validIdentity } from './effect-contract.mjs';
9
+ import { need,shape,json,digest,validIdentity,JOURNAL_PAYLOAD_LIMIT } from './effect-contract.mjs';
10
10
  import {planBytes,readCommitIntent,readCommitResult} from './task-commit-codec.mjs';
11
11
  import {resolveFixtureCommit} from './task-runner.mjs';
12
12
  import {readRunnerHistory} from './durable-runner-state.mjs';
@@ -73,7 +73,9 @@ function ownerMatch(store,owner,initial,revision) {
73
73
  need(equal(s.identity,initial.identity) && equal(s.fingerprints,initial.fingerprints),'identity_mismatch');
74
74
  need(s.revision===revision,'commit_store_changed');return s;
75
75
  }
76
- function boundedRecord(record) {need(Buffer.byteLength(JSON.stringify(record))<=MiB,'limit_exceeded');}
76
+ // The store's own record bound (payload limit plus the 1 KiB envelope): a fixed 1 MiB
77
+ // refused every commit of a run whose develop checkpoint the store had accepted.
78
+ function boundedRecord(record) {need(Buffer.byteLength(JSON.stringify(record))<=JOURNAL_PAYLOAD_LIMIT+1024,'limit_exceeded');}
77
79
  function append(store,current,id,kind,payload) {
78
80
  const data={version:1,seq:current.records.length+1,id,kind,payload,previousDigest:current.records.at(-1)?.digest??null};
79
81
  const record={...data,digest:digest(data)};boundedRecord(record);
@@ -1,4 +1,5 @@
1
- import {packageMaterialEligible,checkpointStoragePlan,checkpointPackageBudget,packageMaterialReference} from './checkpoint-package-material.mjs';
1
+ import {packageMaterialEligible,checkpointStoragePlan,checkpointPackageBudget,packageMaterialReference,INLINE_PACKAGE_LIMIT} from './checkpoint-package-material.mjs';
2
+ import {reviewInputFit} from './codex-review-adapter.mjs';
2
3
  import {taskDeclarations,approvedTaskGrammar} from '../spec-task-line.mjs';
3
4
  import {readIntegrationEvidenceFile,validateIntegrationRecord,verifyReviewedIntegration} from './reviewed-integration.mjs';
4
5
  import {beginHostStage} from './host-stage-observer.mjs';
@@ -346,10 +347,11 @@ export function createTaskRunner(options) {
346
347
  // Other task runs' committed, reviewed deliveries in this specs root, only
347
348
  // those reviewed after this run's own approving review, and the live proof
348
349
  // that recorded interleaving steps are exactly such deliveries.
349
- const laterDeliveries=()=>completedReviewedDeliveries({specsRoot:completion.owner.specsRoot,root:config.root,identity:config.identity});
350
+ const laterDeliveries=()=>completedReviewedDeliveries({specsRoot:completion.owner.specsRoot,root:config.root,identity:config.identity,
351
+ tasksPath:completion.owner.tasksPath??null});
350
352
  const reviewedAt=()=>approvedReviewAt({reviewInvocation,reviewPackage});
351
353
  const resolveSteps=(steps,allowAbsent=false)=>resolveDeliverySteps({specsRoot:completion.owner.specsRoot,root:config.root,
352
- identity:config.identity,after:reviewedAt(),steps,allowAbsent});
354
+ identity:config.identity,tasksPath:completion.owner.tasksPath??null,after:reviewedAt(),steps,allowAbsent});
353
355
  // This run's own QA fixes take their place in the same order at the final
354
356
  // review time their completion evidence cites (evidence: a fix not yet accepted).
355
357
  const fixTime=(evidence=null)=>fix=>{
@@ -703,13 +705,15 @@ export function createTaskRunner(options) {
703
705
  need(digest(readReviewSourceFiles(path.dirname(handoff),[path.basename(handoff)])[0])===digest(reviewPackage.handoff),'package_mismatch');
704
706
  }
705
707
  explainCompletedDelivery({root:config.root,baseline:base,parentPackage:reviewPackage,deliveries:laterDeliveries(),after:reviewedAt(),
708
+ tasksPath:completion.owner.tasksPath??null,
706
709
  since:firstReviewAt(journal,config.identity)});
707
710
  }
708
711
  return current;
709
712
  } catch(error){
710
713
  return freeze({...current,code:'correction_review_required',...(error?.code==='fix_current_code_unexplained'
711
714
  ?{reason:`未经审查的改动:${error.paths.slice(0,20).join(', ')}${error.paths.length>20?` 等 ${error.paths.length} 个路径`:''}`}
712
- :error?.code==='fix_association_unverified'?{reason:'已登记 QA 修复所接续的后续交付无法按其运行存档核实(存档缺失、未完成或内容不符)'}:{})});
715
+ :error?.code==='fix_association_unverified'?{reason:'已登记 QA 修复所接续的后续交付无法按其运行存档核实(存档缺失、未完成或内容不符)'}
716
+ :error?.code==='user_maintained_invalid'?{reason:`代码根的用户维护文件声明 .cm-user-maintained.json 无效:${error.detail}`}:{})});
713
717
  }
714
718
  };
715
719
  const halt=(next,why,detail=null)=>{state=next;code=why;reason=detail;};
@@ -1624,15 +1628,28 @@ export function createTaskRunner(options) {
1624
1628
  const size=value=>Buffer.byteLength(JSON.stringify(value??null));
1625
1629
  const reserve=developCheckpointReserve({examinedPathsBytes:size(reviewPaths(reviewPackage)),
1626
1630
  receiptsBytes:size(receipts),callsBytes:size(calls),writebackBytes:size(learningResult?.writeback)});
1627
- const budget=JOURNAL_PAYLOAD_LIMIT-reserve;
1628
1631
  const enabled=packageMaterialEnabled();
1629
- const capacity=enabled?checkpointPackageBudget({inlineBytes:bytes,packageBytes:size(reviewPackage),reserve,enabled,
1630
- referenced:packageMaterialReference(journal,reviewPackage,{...config.identity,attempt})!==null}):{fits:bytes<=budget};
1631
- if(!capacity.fits){
1632
+ // One budget for both: without a material archive the package repeats in
1633
+ // every later checkpoint, so it keeps the original inline budget.
1634
+ const capacity=checkpointPackageBudget({inlineBytes:bytes,packageBytes:size(reviewPackage),reserve,enabled,
1635
+ referenced:enabled&&packageMaterialReference(journal,reviewPackage,{...config.identity,attempt})!==null});
1636
+ const budget=capacity.budget;
1637
+ const reviewer=reviewers.find(candidate=>candidate.allowed&&candidate.available);
1638
+ const input=capacity.fits&&reviewer?reviewInputFit({reviewPackage,payload:{priorReview,...supersededReviewPayload(carriedReview,attempt)},
1639
+ provider:reviewer.provider,executionPolicy:metadata.executionPolicy??null}):null;
1640
+ if(input&&!input.fits){
1641
+ const changed=reviewPackage.changes.filter(change=>change.after).map(change=>change.after);
1642
+ reviewPackage=packageBefore;
1643
+ halt('blocked','develop_package_too_large',boundedReason(`develop_package_too_large: the review input for ${reviewer.provider} would exceed its limit of ${input.limit} bytes, `
1644
+ +'so no review could take this delivery; largest changed files: ',largestFiles(changed),
1645
+ '; shrink them or move them out of scope, then resume to redo this attempt'));
1646
+ result=privateStatus();cache.set(v.id,{effect:v,digest:digest(v),result});
1647
+ }
1648
+ else if(!capacity.fits){
1632
1649
  const changed=reviewPackage.changes.filter(change=>change.after).map(change=>change.after);
1633
1650
  reviewPackage=packageBefore;
1634
1651
  halt('blocked','develop_package_too_large',boundedReason(`develop_package_too_large: the review checkpoint would be ${bytes} bytes, `
1635
- +`above ${budget} (journal record limit ${JOURNAL_PAYLOAD_LIMIT} minus ${reserve} kept for the bounded review `
1652
+ +`above ${budget} (${enabled?`journal record limit ${JOURNAL_PAYLOAD_LIMIT}`:`inline package limit ${Math.min(JOURNAL_PAYLOAD_LIMIT,INLINE_PACKAGE_LIMIT)} for a package without a material archive`} minus ${reserve} kept for the bounded review `
1636
1653
  +'and completion records); largest changed files: ',largestFiles(changed),
1637
1654
  '; shrink them or move them out of scope, then resume to redo this attempt'));
1638
1655
  result=privateStatus();cache.set(v.id,{effect:v,digest:digest(v),result});