@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
@@ -8,7 +8,7 @@ const sqlite=()=>process.getBuiltinModule('node:sqlite');
8
8
  import { need,shape,id,hex,json,digest,freeze,JOURNAL_PAYLOAD_LIMIT } from './effect-contract.mjs';
9
9
  import { isSupportedExecutionPlatform } from './execution-platform.mjs';
10
10
  import { MiB,STATE_LIMIT,PHYSICAL_LIMIT } from './execution-store-limits.mjs';
11
- import {fixJournalWorkflow,packFixJournalPayload,packFixJournalState,unpackFixJournalState} from './review-presentation.mjs';
11
+ import {fixJournalWorkflow,journalPhysicalLimit,packFixJournalPayload,packFixJournalState,unpackFixJournalState} from './review-presentation.mjs';
12
12
 
13
13
  const APP_ID=0x434d5831;
14
14
  const PROTOCOL_SQL='CREATE TABLE protocol(version INTEGER NOT NULL CHECK(version=1))';
@@ -59,7 +59,7 @@ function validateState(raw,options) {
59
59
  shape(r,['version','seq','id','kind','payload','previousDigest','digest']);
60
60
  need(r.version===1,'store_version');need(r.seq===index+1 && r.previousDigest===previous,'store_corrupt');
61
61
  id(r.id);need(!ids.has(r.id) && kinds.has(r.kind),'store_corrupt');ids.add(r.id);
62
- need(Buffer.byteLength(JSON.stringify(packFixJournalPayload(r.payload,{workflow:fixJournalWorkflow(v)})))<=JOURNAL_PAYLOAD_LIMIT,'limit_exceeded');
62
+ need(Buffer.byteLength(JSON.stringify(packFixJournalPayload(r.payload,{workflow:fixJournalWorkflow(v)})))<=journalPhysicalLimit(v),'limit_exceeded');
63
63
  const {digest:checksum,...data}=r;hex(checksum);need(digest(data)===checksum,'store_corrupt');previous=checksum;
64
64
  }
65
65
  const {revision,...data}=v;hex(revision);need(digest(data)===revision,'store_corrupt');return v;
@@ -252,7 +252,7 @@ export function openExecutionStore(input) {
252
252
  const v=json(input,10*MiB);shape(v,['id','kind','payload','expectedRevision']);
253
253
  id(v.id);hex(v.expectedRevision);need(kinds.has(v.kind));
254
254
  const current=snapshot(),physicalPayload=packFixJournalPayload(v.payload,{workflow:fixJournalWorkflow(current)});
255
- need(Buffer.byteLength(JSON.stringify({...v,payload:physicalPayload}))<=MiB+1024,'limit_exceeded');
255
+ need(Buffer.byteLength(JSON.stringify({...v,payload:physicalPayload}))<=journalPhysicalLimit(current)+1024,'limit_exceeded');
256
256
  const existing=current.records.find(r=>r.id===v.id);
257
257
  if(existing){need(existing.kind===v.kind && digest(existing.payload)===digest(v.payload),'record_conflict');return current;}
258
258
  need(v.expectedRevision===current.revision,'revision_mismatch');
@@ -263,7 +263,10 @@ export function openExecutionStore(input) {
263
263
  const next=validateState(seal({...data,records:[...current.records,{...record,digest:digest(record)}]}),options);
264
264
  const {storageEncoding,...physicalData}=physicalState;
265
265
  const encodedSequences=[...(storageEncoding?.records??[]),
266
- ...(Buffer.byteLength(JSON.stringify(v.payload))>JOURNAL_PAYLOAD_LIMIT?[record.seq]:[])];
266
+ // cm-fix 的物理压缩门槛固定 1 MiB(review-presentation PAYLOAD_LIMIT),与记录上限无关:
267
+ // 记录上限放大后仍按 1 MiB 打标记,否则压缩过的记录读回时不会解码
268
+ // 只有 cm-fix 运行的载荷会被压缩;普通运行的大记录原样存,打了标记读回时会被当成损坏
269
+ ...(fixJournalWorkflow(current)&&Buffer.byteLength(JSON.stringify(v.payload))>MiB?[record.seq]:[])];
267
270
  const physicalNext={...physicalData,records:[...physicalState.records,{...record,payload:physicalPayload,digest:digest(record)}],
268
271
  revision:next.revision,...(encodedSequences.length?{storageEncoding:{version:1,kind:'cm-fix-review-payloads-v1',records:encodedSequences}}:{})};
269
272
  try{
@@ -4,6 +4,7 @@ import {verifySpecificationMaterial} from './specification-material.mjs';
4
4
  import {CONFIG_FILENAMES} from '../../../scripts/cm-workflow-config.mjs';
5
5
  import {digest,hex,id,json,need,shape} from './effect-contract.mjs';
6
6
  import {assertSnapshotBoundaries} from './integration-snapshots.mjs';
7
+ import {USER_MAINTAINED_FILE,readUserMaintainedPaths,userMaintainedInvalid} from './user-maintained-paths.mjs';
7
8
 
8
9
  const inventoryFile=({contentBase64,...metadata})=>metadata;
9
10
  const sameFile=(a,b)=>digest(a===null?null:inventoryFile(a))===digest(b===null?null:inventoryFile(b));
@@ -46,13 +47,19 @@ export function firstReviewAt(records,identity){
46
47
  &&bound?.repositoryId===identity.repositoryId&&bound.runId===identity.runId&&bound.taskId===identity.taskId
47
48
  &&Number.isInteger(bound.attempt)&&bound.attempt>=1?row.registeredAt:null;
48
49
  }
50
+ // Features number their tasks independently (each has a T-001), so a task is its
51
+ // feature's tasks.md and task id. A side without a recorded tasks.md keeps the
52
+ // historical, conservative task-id-only match.
53
+ const known=tasksPath=>typeof tasksPath==='string';
54
+ export const sameDeliveryTask=(a,b)=>a.taskId===b.taskId
55
+ &&(!known(a.tasksPath)||!known(b.tasksPath)||a.tasksPath===b.tasksPath);
49
56
  const key=file=>file===null||file===undefined?null:`${file.sha256}:${file.mode}`;
50
57
  const applyMeta=(state,pkg)=>{for(const change of pkg.changes){
51
58
  if(change.after===null)state.delete(change.path);else state.set(change.path,inventoryFile(change.after));}};
52
59
  // Every qualifying later package, in durable review order (ties: run id, then
53
60
  // package position). Nothing is chosen or dropped by content.
54
61
  function laterSequence(deliveries,after,rootDigest){
55
- return deliveries.flatMap(delivery=>delivery.packages.map((item,index)=>({runId:delivery.runId,index,reviewedAt:item.reviewedAt,raw:item.pkg})))
62
+ return deliveries.flatMap(delivery=>delivery.packages.map((item,index)=>({runId:delivery.runId,tasksPath:delivery.tasksPath??null,index,reviewedAt:item.reviewedAt,raw:item.pkg})))
56
63
  .filter(entry=>deliveredAfter(entry,after)).map(entry=>({...entry,pkg:readReviewPackage(entry.raw)}))
57
64
  .filter(entry=>entry.pkg.rootDigest===rootDigest)
58
65
  .sort((a,b)=>a.reviewedAt-b.reviewedAt||(a.runId<b.runId?-1:a.runId>b.runId?1:0)||a.index-b.index);
@@ -64,6 +71,15 @@ function unexplainedError(paths){
64
71
  // The root CM workflow config outside the run's scope is user-editable policy,
65
72
  // not delivered code, and is the one tolerated unreviewed difference.
66
73
  const toleratedConfig=ownScope=>{const scope=new Set(ownScope);return p=>CONFIG_FILENAMES.includes(p)&&!scope.has(p);};
74
+ // The plain completed-run chain also tolerates the files the code root declares
75
+ // as user-maintained, and that declaration, outside the run's own scope (compared
76
+ // case-insensitively). compareCurrent binds the declaration bytes it was read
77
+ // from to the inventory it compares.
78
+ const toleratedUserMaintained=(ownScope,root)=>{
79
+ const config=toleratedConfig(ownScope),scope=new Set(ownScope.map(p=>p.toLowerCase()));
80
+ const {paths,sha256}=readUserMaintainedPaths(root),declared=new Set(paths);
81
+ return Object.assign(p=>config(p)||!scope.has(p.toLowerCase())&&(p===USER_MAINTAINED_FILE||declared.has(p)),{declaration:sha256});
82
+ };
67
83
  // Apply one later delivery strictly: its reviewed before-state must be the
68
84
  // running composition on every path it touches (tolerated config aside). None
69
85
  // is ever skipped; a mismatch names the paths.
@@ -77,10 +93,14 @@ const strict=()=>false;
77
93
  // The composition must be the current tree exactly, content and mode.
78
94
  function compareCurrent({root,base,state,tolerated}){
79
95
  const original=new Map(base.files.map(file=>[file.path,inventoryFile(file)]));
80
- const actual=new Map(compareReviewInventoryToBaseline(root,base,{withMode:true})
81
- .map(row=>[row.path,row.sha256===null?null:`${row.sha256}:${row.mode}`]));
96
+ const declared=Object.hasOwn(tolerated,'declaration');
97
+ const rows=compareReviewInventoryToBaseline(root,base,{withMode:true,...(declared?{probe:USER_MAINTAINED_FILE}:{})});
98
+ const actual=new Map(rows.filter(row=>!row.probe).map(row=>[row.path,row.sha256===null?null:`${row.sha256}:${row.mode}`]));
82
99
  const wanted=new Map([...new Set([...original.keys(),...state.keys()])]
83
100
  .filter(p=>key(original.get(p))!==key(state.get(p))).map(p=>[p,key(state.get(p))]));
101
+ // The tolerance stands only on the declaration this very scan contains.
102
+ if(declared&&(rows.find(row=>row.probe).sha256??null)!==tolerated.declaration)
103
+ throw userMaintainedInvalid('核对期间声明已变化,或声明被忽略规则排除');
84
104
  const unexplained=[...new Set([...wanted.keys(),...actual.keys()])]
85
105
  .filter(p=>!tolerated(p)&&wanted.get(p)!==actual.get(p)).sort();
86
106
  if(unexplained.length)throw unexplainedError(unexplained);
@@ -135,13 +155,13 @@ export function composeFixCode({baseline,parentPackage,fixPackages,steps=[]}){
135
155
  // order and strictly; the result must be the current tree exactly.
136
156
  export function explainReviewedDrift({root,baseline,composed,ownScope,deliveries,after}){
137
157
  const base=readReviewBaseline(baseline);
138
- const state=new Map(composed.map(file=>[file.path,inventoryFile(file)])),tolerated=toleratedConfig(ownScope);
158
+ const state=new Map(composed.map(file=>[file.path,inventoryFile(file)])),tolerated=toleratedUserMaintained(ownScope,root);
139
159
  for(const entry of laterSequence(deliveries,after,base.rootDigest))applyDelivery(state,entry.pkg,tolerated);
140
160
  compareCurrent({root,base,state,tolerated});
141
161
  }
142
162
 
143
163
  // Completed run without accepted fixes: its own reviewed composition, then drift.
144
- export function explainCompletedDelivery({root,baseline,parentPackage,deliveries,after,since=null}){
164
+ export function explainCompletedDelivery({root,baseline,parentPackage,deliveries,after,since=null,tasksPath=null}){
145
165
  const base=readReviewBaseline(baseline),parent=readReviewPackage(parentPackage);
146
166
  need(parent.baseIdentity===base.baselineDigest&&parent.rootDigest===base.rootDigest
147
167
  &&digest(parent.identity)===digest(base.identity),'fix_parent_binding_mismatch');
@@ -165,7 +185,8 @@ export function explainCompletedDelivery({root,baseline,parentPackage,deliveries
165
185
  const interval=new Map(base.files.map(file=>[file.path,inventoryFile(file)]));
166
186
  for(const entry of earlier){
167
187
  need(entry.pkg.identity.repositoryId===parent.identity.repositoryId&&entry.pkg.identity.runId===entry.runId
168
- &&entry.runId!==parent.identity.runId&&entry.pkg.identity.taskId!==parent.identity.taskId,'fix_association_unverified');
188
+ &&entry.runId!==parent.identity.runId
189
+ &&!sameDeliveryTask({taskId:entry.pkg.identity.taskId,tasksPath:entry.tasksPath},{taskId:parent.identity.taskId,tasksPath}),'fix_association_unverified');
169
190
  applyDelivery(interval,entry.pkg,strict);
170
191
  }
171
192
  // The parent's own reviewed scope remains authoritative, including paths
@@ -57,6 +57,11 @@ function trustedGit(root){
57
57
  }
58
58
  return null;
59
59
  }
60
+ // Listing ignored AGENTS.md walks every ignored directory. A large local build
61
+ // tree (Wue specs8: 67 GB under an ignored .artifacts/) took about 11 s; at the
62
+ // old 10 s limit the query timed out, the Git rules were dropped and the whole
63
+ // ignored tree entered the inventory until the 1 GiB limit refused the run.
64
+ export const GIT_IGNORE_TIMEOUT_MS=120000;
60
65
  function gitIgnore(root,legacy=false){
61
66
  const bin=trustedGit(root);if(!bin)return null;
62
67
  const safePath=(process.env.PATH??'').split(path.delimiter).filter(dir=>{
@@ -67,7 +72,7 @@ function gitIgnore(root,legacy=false){
67
72
  LANG:'C.UTF-8',LC_ALL:'C.UTF-8',GIT_NO_REPLACE_OBJECTS:'1',GIT_NO_LAZY_FETCH:'1',GIT_TERMINAL_PROMPT:'0',
68
73
  GIT_CONFIG_NOSYSTEM:'1',GIT_CONFIG_GLOBAL:os.devNull};
69
74
  const run=args=>spawnSync(bin,['--no-optional-locks','-c','core.fsmonitor=false','-C',root,...args],
70
- {env,timeout:10000,maxBuffer:16*1024*1024});
75
+ {env,timeout:GIT_IGNORE_TIMEOUT_MS,maxBuffer:16*1024*1024});
71
76
  const ruleBytes=file=>{
72
77
  let fd;
73
78
  try{
@@ -88,9 +93,15 @@ function gitIgnore(root,legacy=false){
88
93
  if(!inside(worktree,root))return null;
89
94
  const result=run(['ls-files','--others','--ignored','--exclude-standard','--directory','-z']);
90
95
  const agents=run(['ls-files','--cached','--others','--exclude-standard','-z','--','AGENTS.md','**/AGENTS.md']);
91
- const ignoredAgents=run(['ls-files','--others','--ignored','--exclude-standard','-z','--','AGENTS.md','**/AGENTS.md']);
96
+ // One walk of the ignored tree for both names: each such query visits every
97
+ // ignored file, and two of them made a single capture take about 22 s on a
98
+ // 67 GB ignored build tree (Wue specs8), long enough to miss host heartbeats.
99
+ const ignoredNamed=run(['ls-files','--others','--ignored','--exclude-standard','-z','--','AGENTS.md','**/AGENTS.md','.gitignore','**/.gitignore']);
100
+ const ignoredAs=name=>({error:ignoredNamed.error,status:ignoredNamed.status,
101
+ stdout:Buffer.from((ignoredNamed.stdout??Buffer.alloc(0)).toString('utf8').split('\0').filter(p=>p&&path.posix.basename(p)===name).map(p=>p+'\0').join(''),'utf8')});
102
+ const ignoredAgents=ignoredAs('AGENTS.md');
92
103
  const rules=run(['ls-files','--cached','--others','--exclude-standard','-z','--','.gitignore','**/.gitignore']);
93
- const ignoredRules=run(['ls-files','--others','--ignored','--exclude-standard','-z','--','.gitignore','**/.gitignore']);
104
+ const ignoredRules=ignoredAs('.gitignore');
94
105
  const config=run(['config','--local','--list','--null']);
95
106
  const excludesFile=run(['config',...(legacy?['--local']:[]),'--path','--get','core.excludesfile']);
96
107
  if([result,agents,ignoredAgents,rules,ignoredRules,config].some(row=>row.error||row.status!==0)
@@ -426,7 +437,9 @@ export function captureReviewInventory(root,baseline,{withMode=false}={}){
426
437
  }
427
438
  // withMode also reports permission-only changes; the mode is part of a reviewed
428
439
  // file record. The default keeps the historical content-only comparison.
429
- export function compareReviewInventoryToBaseline(root,baseline,{withMode=false}={}){
440
+ // probe: one path also reported from this same scan, changed or not, flagged
441
+ // probe:true (sha256 null when the current inventory does not contain it).
442
+ export function compareReviewInventoryToBaseline(root,baseline,{withMode=false,probe=null}={}){
430
443
  validBaseline(baseline);
431
444
  const stable=baseline.ignorePolicy?.version===2;
432
445
  const policy=stable?stableSnapshotPolicy(root,baseline.ignorePolicy)
@@ -438,8 +451,9 @@ export function compareReviewInventoryToBaseline(root,baseline,{withMode=false}=
438
451
  const previous=new Map(before.map(file=>[file.path,key(file)]));
439
452
  const current=new Map(after.map(file=>[file.path,key(file)]));
440
453
  const records=new Map(after.map(file=>[file.path,file]));
441
- return [...new Set([...previous.keys(),...current.keys()])].filter(p=>previous.get(p)!==current.get(p))
442
- .map(p=>({path:p,sha256:records.get(p)?.sha256??null,...(withMode?{mode:records.get(p)?.mode??null}:{})}));
454
+ const row=p=>({path:p,sha256:records.get(p)?.sha256??null,...(withMode?{mode:records.get(p)?.mode??null}:{})});
455
+ const rows=[...new Set([...previous.keys(),...current.keys()])].filter(p=>previous.get(p)!==current.get(p)).map(row);
456
+ return probe===null?rows:[...rows,{...row(probe),probe:true}];
443
457
  }
444
458
  export function compareReviewBaseline(current,expected){
445
459
  if(digest(current)===digest(expected))return true;
@@ -1,6 +1,6 @@
1
1
  // Lossless presentation inside the same no-tools prompt. Canonical evidence stays unchanged.
2
2
  import {createHash} from 'node:crypto';
3
- import {json,need,shape,hex,digest,validIdentity} from './effect-contract.mjs';
3
+ import {json,need,shape,hex,digest,validIdentity,JOURNAL_PAYLOAD_LIMIT} from './effect-contract.mjs';
4
4
  import {readReviewPackage} from './review-package.mjs';
5
5
  export function compactReviewData(raw){
6
6
  const input=json(raw,10*1024*1024);
@@ -58,6 +58,8 @@ const storageCode='review_storage_invalid';
58
58
  const sizeOf=value=>Buffer.byteLength(JSON.stringify(value));
59
59
  const sameBytes=(a,b)=>JSON.stringify(a)===JSON.stringify(b);
60
60
  const object=value=>value!==null&&typeof value==='object'&&!Array.isArray(value);
61
+ /** 单条物理载荷上限:修复流程固定 1 MiB(超出须压缩),其他流程为记录上限 */
62
+ export const journalPhysicalLimit=state=>fixJournalWorkflow(state)===FIX_WORKFLOW?PAYLOAD_LIMIT:JOURNAL_PAYLOAD_LIMIT;
61
63
  export function fixJournalWorkflow(state){
62
64
  const first=state.records?.[0];
63
65
  return first?.id==='fix-configuration'&&first.kind==='intent'&&first.payload?.workflow===FIX_WORKFLOW
@@ -102,8 +104,9 @@ function packageLocations(value,{validate=true}={}){
102
104
  }
103
105
  export function packFixJournalPayload(raw,{workflow}={}){
104
106
  const value=json(raw,INPUT_LIMIT),logicalBytes=sizeOf(value);
105
- if(logicalBytes<=PAYLOAD_LIMIT)return value;
106
- need(workflow===FIX_WORKFLOW,'limit_exceeded');
107
+ // 只有 cm-fix 的审查载荷在超过 1 MiB 时压缩;其他运行原样存,大小由存储层的记录上限
108
+ // (JOURNAL_PAYLOAD_LIMIT)把关——这里再按 1 MiB 拒绝,会让放大后的记录上限形同虚设
109
+ if(logicalBytes<=PAYLOAD_LIMIT||workflow!==FIX_WORKFLOW){need(logicalBytes<=JOURNAL_PAYLOAD_LIMIT,'limit_exceeded');return value;}
107
110
  const {paths,packages}=packageLocations(value);
108
111
  // No duplicated anchor package in the temporary input: the canonical package
109
112
  // already inside payload supplies the presentation digest to the same visitor.
@@ -178,7 +181,8 @@ export function packFixJournalState(raw){
178
181
  const workflow=fixJournalWorkflow(state),sequences=[];
179
182
  const records=state.records.map(record=>{
180
183
  const payload=packFixJournalPayload(record.payload,{workflow});
181
- if(sizeOf(record.payload)>PAYLOAD_LIMIT)sequences.push(record.seq);
184
+ // 只标真正被压缩的 cm-fix 记录;普通运行的大记录原样存(与 execution-store 追加时的标记一致)
185
+ if(workflow===FIX_WORKFLOW&&sizeOf(record.payload)>PAYLOAD_LIMIT)sequences.push(record.seq);
182
186
  return {...record,payload};
183
187
  });
184
188
  return json({...state,records,...(sequences.length?{storageEncoding:{version:1,kind:STORAGE_KIND,records:sequences}}:{})},STATE_LIMIT);
@@ -187,7 +191,10 @@ export function unpackFixJournalState(raw){
187
191
  const physical=json(raw,STATE_LIMIT);
188
192
  if(!Object.hasOwn(physical,'storageEncoding')){
189
193
  need(Array.isArray(physical.records),storageCode);
190
- physical.records.forEach(record=>json(record.payload,PAYLOAD_LIMIT));
194
+ // 修复流程的未编码载荷照旧以 1 MiB 为限(超过就必须压缩并打标记);普通流程用记录上限。
195
+ // 两者混用会让同一条未标记的修复记录在后来追加压缩记录后变得不可读
196
+ const limit=fixJournalWorkflow(physical)===FIX_WORKFLOW?PAYLOAD_LIMIT:JOURNAL_PAYLOAD_LIMIT;
197
+ physical.records.forEach(record=>json(record.payload,limit));
191
198
  return physical;
192
199
  }
193
200
  shape(physical,['version','identity','fingerprints','records','revision','storageEncoding']);
@@ -11,11 +11,12 @@ import path from 'node:path';
11
11
  import {readExecutionSnapshot} from './execution-snapshot.mjs';
12
12
  import {readRunnerHistory} from './durable-runner-state.mjs';
13
13
  import {inspectFixCompletionHistory} from '../cm-fix/execution.mjs';
14
- import {deliveredAfter,deliveryStep} from './fix-code-association.mjs';
14
+ import {deliveredAfter,deliveryStep,sameDeliveryTask} from './fix-code-association.mjs';
15
15
  import {digest,need} from './effect-contract.mjs';
16
16
 
17
17
  const RUN_ID=/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
18
18
  const cache=new Map();
19
+ export {sameDeliveryTask};
19
20
 
20
21
  function readDelivery(specsRoot,identity,read={}){
21
22
  try{
@@ -30,6 +31,7 @@ function readDelivery(specsRoot,identity,read={}){
30
31
  // Each package carries its own review time: the run's approving review, or
31
32
  // for an accepted QA fix the fix's final review registration it cites.
32
33
  return Object.freeze({runId:identity.runId,root:init.config.root,taskId:init.config.identity.taskId,
34
+ tasksPath:init.config.completion?.owner?.tasksPath??null,
33
35
  packages:Object.freeze([{pkg:state.reviewPackage,reviewedAt:approvedReviewAt(state)},
34
36
  ...history.acceptedFixes.map(item=>({pkg:item.evidence.reviewPackage,reviewedAt:fixReviewedAt(specsRoot,item.evidence)}))])});
35
37
  }catch{return null;}
@@ -43,7 +45,7 @@ function readDelivery(specsRoot,identity,read={}){
43
45
  function readFixDelivery(specsRoot,identity,configuration){
44
46
  if(Object.hasOwn(configuration??{},'qaSource')||configuration?.archiveMode!==undefined)return null;
45
47
  const {identity:fixIdentity,evidence}=inspectFixCompletionHistory({specsRoot,identity});
46
- return Object.freeze({runId:identity.runId,root:fs.realpathSync(configuration.reproduction.cwd),taskId:fixIdentity.taskId,
48
+ return Object.freeze({runId:identity.runId,root:fs.realpathSync(configuration.reproduction.cwd),taskId:fixIdentity.taskId,tasksPath:null,
47
49
  packages:Object.freeze([{pkg:evidence.reviewPackage,reviewedAt:fixReviewedAt(specsRoot,evidence)}])});
48
50
  }
49
51
  // A QA fix package's durable review time: the final review registration its
@@ -84,7 +86,7 @@ function cachedDelivery(specsRoot,repositoryId,runId,stat){
84
86
  // Resolve recorded steps to the real, completed, later reviewed packages of the
85
87
  // named runs. allowAbsent is only for journal replay: a missing store cannot be
86
88
  // re-proved there (returns null), and every live use refuses it.
87
- export function resolveDeliverySteps({specsRoot,root,identity,after,steps,allowAbsent=false}){
89
+ export function resolveDeliverySteps({specsRoot,root,identity,tasksPath=null,after,steps,allowAbsent=false}){
88
90
  const resolved=[];
89
91
  for(const step of steps){
90
92
  need(RUN_ID.test(step.runId)&&step.runId!==identity.runId,'fix_association_unverified');
@@ -92,7 +94,7 @@ export function resolveDeliverySteps({specsRoot,root,identity,after,steps,allowA
92
94
  try{stat=fs.lstatSync(path.join(specsRoot,'.reviews','.execution',step.runId,'state.json'));}
93
95
  catch(error){if(error.code==='ENOENT'){need(allowAbsent,'fix_association_unverified');return null;}throw error;}
94
96
  const delivery=cachedDelivery(specsRoot,identity.repositoryId,step.runId,stat);
95
- need(delivery&&delivery.root===root&&delivery.taskId!==identity.taskId,'fix_association_unverified');
97
+ need(delivery&&delivery.root===root&&!sameDeliveryTask(delivery,{taskId:identity.taskId,tasksPath}),'fix_association_unverified');
96
98
  const found=delivery.packages.find(item=>item.pkg.packageDigest===step.packageDigest);
97
99
  need(found&&deliveredAfter(found,after)&&digest(deliveryStep(step.runId,found.pkg,step.beforeFix))===digest(step),'fix_association_unverified');
98
100
  resolved.push({...step,pkg:found.pkg});
@@ -102,8 +104,9 @@ export function resolveDeliverySteps({specsRoot,root,identity,after,steps,allowA
102
104
 
103
105
  // Deliveries for the same code root and repository, excluding the caller's own
104
106
  // run and any other run of the same task: a superseding rerun of a task is not
105
- // a later change that its superseded run may adopt.
106
- export function completedReviewedDeliveries({specsRoot,root,identity}){
107
+ // a later change that its superseded run may adopt. tasksPath: the caller's
108
+ // feature tasks.md (sameDeliveryTask); null keeps the task-id-only exclusion.
109
+ export function completedReviewedDeliveries({specsRoot,root,identity,tasksPath=null}){
107
110
  const execution=path.join(specsRoot,'.reviews','.execution');
108
111
  let entries;
109
112
  try{entries=fs.readdirSync(execution,{withFileTypes:true});}catch{return [];}
@@ -114,7 +117,7 @@ export function completedReviewedDeliveries({specsRoot,root,identity}){
114
117
  try{stat=fs.lstatSync(path.join(execution,entry.name,'state.json'));}catch{continue;}
115
118
  // Replay once per journal version; a changed state.json is read again.
116
119
  const delivery=cachedDelivery(specsRoot,identity.repositoryId,entry.name,stat);
117
- if(delivery&&delivery.root===root&&delivery.taskId!==identity.taskId)deliveries.push(delivery);
120
+ if(delivery&&delivery.root===root&&!sameDeliveryTask(delivery,{taskId:identity.taskId,tasksPath}))deliveries.push(delivery);
118
121
  }
119
122
  return deliveries;
120
123
  }
@@ -223,7 +223,7 @@ export function verifyReviewedIntegration({root,specsRoot,baseline,parentPackage
223
223
  equal(history.state.reviewPackage,pkg);
224
224
  const after=approvedReviewAt(history.state),since=firstReviewAt(records,pkg.identity);
225
225
  need(Number.isSafeInteger(after)&&Number.isSafeInteger(since),'integration_order_unverified');
226
- const deliveries=completedReviewedDeliveries({specsRoot,root,identity:pkg.identity});
226
+ const deliveries=completedReviewedDeliveries({specsRoot,root,identity:pkg.identity,tasksPath:init.config.completion?.owner?.tasksPath??null});
227
227
  const sources=resolveSources(plan,{root,specsRoot,deliveries,after});
228
228
  if(plan.snapshots){
229
229
  const instructions=[...learningPaths(records),...sources.flatMap(row=>row.learningPaths)];