@aibyzero/cm-workflow 0.19.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 (127) hide show
  1. package/.codex-plugin/plugin.json +1 -1
  2. package/AGENTS.md +8 -0
  3. package/CHANGELOG.md +38 -0
  4. package/README.md +15 -1
  5. package/VERSION +1 -1
  6. package/docs/architecture.md +3 -0
  7. package/docs/cm-acceptance-completion.md +185 -0
  8. package/docs/installation.md +1 -1
  9. package/docs/js-workflow-control.md +1 -1
  10. package/docs/proposals/spec-amendment-tiers.md +100 -0
  11. package/package.json +1 -1
  12. package/runtime/js/acceptance-language.mjs +32 -0
  13. package/runtime/js/autonomy.mjs +168 -3
  14. package/runtime/js/check-coverage.mjs +130 -0
  15. package/runtime/js/cm-ai/acceptance-contract.mjs +257 -0
  16. package/runtime/js/cm-ai/checkpoint-package-material.mjs +13 -3
  17. package/runtime/js/cm-ai/claude-developer-proposal.schema.json +18 -0
  18. package/runtime/js/cm-ai/cm-ai-admission.mjs +49 -8
  19. package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +10 -6
  20. package/runtime/js/cm-ai/cm-ai-run-finalizer.mjs +8 -3
  21. package/runtime/js/cm-ai/codex-developer-basic-output.schema.json +1 -1
  22. package/runtime/js/cm-ai/codex-developer-output.schema.json +1 -1
  23. package/runtime/js/cm-ai/codex-review-adapter.mjs +19 -3
  24. package/runtime/js/cm-ai/completion-summary.mjs +187 -0
  25. package/runtime/js/cm-ai/control-policy.mjs +3 -1
  26. package/runtime/js/cm-ai/delivery-evidence.mjs +173 -0
  27. package/runtime/js/cm-ai/developer-adapter.mjs +4 -0
  28. package/runtime/js/cm-ai/drive-core.mjs +15 -4
  29. package/runtime/js/cm-ai/durable-runner-state.mjs +10 -6
  30. package/runtime/js/cm-ai/effect-contract.mjs +8 -1
  31. package/runtime/js/cm-ai/execution-snapshot.mjs +4 -3
  32. package/runtime/js/cm-ai/execution-store-limits.mjs +3 -3
  33. package/runtime/js/cm-ai/execution-store.mjs +7 -4
  34. package/runtime/js/cm-ai/fix-code-association.mjs +27 -6
  35. package/runtime/js/cm-ai/gate-bridge.mjs +13 -1
  36. package/runtime/js/cm-ai/host-conversation-execution.mjs +26 -14
  37. package/runtime/js/cm-ai/host-progress.mjs +2 -1
  38. package/runtime/js/cm-ai/log-rows.mjs +3 -2
  39. package/runtime/js/cm-ai/operator-guidance.mjs +110 -4
  40. package/runtime/js/cm-ai/requirement-evidence.mjs +4 -2
  41. package/runtime/js/cm-ai/review-package.mjs +22 -8
  42. package/runtime/js/cm-ai/review-presentation.mjs +12 -5
  43. package/runtime/js/cm-ai/reviewed-deliveries.mjs +10 -7
  44. package/runtime/js/cm-ai/reviewed-integration.mjs +1 -1
  45. package/runtime/js/cm-ai/spec-amendment.mjs +535 -0
  46. package/runtime/js/cm-ai/specification-material.mjs +57 -12
  47. package/runtime/js/cm-ai/task-commit.mjs +4 -2
  48. package/runtime/js/cm-ai/task-runner.mjs +64 -22
  49. package/runtime/js/cm-ai/user-maintained-paths.mjs +68 -0
  50. package/runtime/js/cm-ai/verification-auto.mjs +6 -4
  51. package/runtime/js/cm-prd/acceptance-preview.mjs +203 -0
  52. package/runtime/js/cm-prd/change.mjs +52 -5
  53. package/runtime/js/cm-prd/self-check.mjs +36 -6
  54. package/runtime/js/cm-prd/session.mjs +8 -3
  55. package/runtime/js/cm-prd/summary.mjs +5 -0
  56. package/runtime/js/cm-prd/task-scope-record.mjs +13 -7
  57. package/runtime/js/node-test-selection.mjs +38 -0
  58. package/runtime/js/run-analysis.mjs +153 -0
  59. package/runtime/js/session-boundary.mjs +17 -5
  60. package/runtime/js/session-handoff.mjs +5 -2
  61. package/runtime/js/task-scope.mjs +4 -1
  62. package/runtime/test-contract.md +1 -0
  63. package/scripts/cm-acceptance-preview.mjs +26 -0
  64. package/scripts/cm-acceptance-preview.test.mjs +156 -0
  65. package/scripts/cm-ai-acceptance-contract.test.mjs +195 -0
  66. package/scripts/cm-ai-admission.mjs +8 -2
  67. package/scripts/cm-ai-admission.test.mjs +20 -4
  68. package/scripts/cm-ai-blockage.test.mjs +120 -0
  69. package/scripts/cm-ai-checklist-coverage.test.mjs +5 -2
  70. package/scripts/cm-ai-checkpoint-package-material.test.mjs +60 -6
  71. package/scripts/cm-ai-checkpoint-package-owner.test.mjs +1 -0
  72. package/scripts/cm-ai-completion-summary.test.mjs +154 -0
  73. package/scripts/cm-ai-conversation-entry-ops.test.mjs +8 -2
  74. package/scripts/cm-ai-develop-driver-gaps.test.mjs +1 -0
  75. package/scripts/cm-ai-drive.mjs +18 -11
  76. package/scripts/cm-ai-fix-later-delivery.test.mjs +2 -2
  77. package/scripts/cm-ai-later-delivery-feature.test.mjs +102 -0
  78. package/scripts/cm-ai-progress.test.mjs +7 -0
  79. package/scripts/cm-ai-project-qa-gate.test.mjs +55 -4
  80. package/scripts/cm-ai-review-input-limit.test.mjs +91 -0
  81. package/scripts/cm-ai-run.test.mjs +23 -1
  82. package/scripts/cm-ai-spec-rebind.test.mjs +51 -15
  83. package/scripts/cm-ai-user-maintained-paths.test.mjs +183 -0
  84. package/scripts/cm-ai-verification-auto.test.mjs +33 -8
  85. package/scripts/cm-ai-verification-gate.test.mjs +1 -1
  86. package/scripts/cm-autonomy-acceptance.test.mjs +212 -0
  87. package/scripts/cm-autonomy-review-r1.test.mjs +142 -0
  88. package/scripts/cm-autonomy.mjs +3 -1
  89. package/scripts/cm-autonomy.test.mjs +10 -9
  90. package/scripts/cm-check-runtime.sh +5 -2
  91. package/scripts/cm-delivery-evidence.mjs +59 -0
  92. package/scripts/cm-delivery-evidence.test.mjs +177 -0
  93. package/scripts/cm-drive-liveness.test.mjs +14 -0
  94. package/scripts/cm-driver-light-import.test.mjs +32 -0
  95. package/scripts/cm-fix-observation-task-id.test.mjs +49 -0
  96. package/scripts/cm-fix-review-storage.test.mjs +14 -4
  97. package/scripts/cm-journal-limit.test.mjs +69 -0
  98. package/scripts/cm-mandatory-check-coverage.test.mjs +82 -0
  99. package/scripts/cm-node-test-selection.test.mjs +108 -0
  100. package/scripts/cm-notify-read-drift.test.mjs +6 -3
  101. package/scripts/cm-prd-completion.test.mjs +49 -0
  102. package/scripts/cm-prd-drive.mjs +1 -1
  103. package/scripts/cm-prd-host.mjs +3 -1
  104. package/scripts/cm-prd-host.test.mjs +19 -2
  105. package/scripts/cm-prd-self-check-rules.test.mjs +23 -11
  106. package/scripts/cm-prd-self-check.test.mjs +24 -1
  107. package/scripts/cm-prd-summary.test.mjs +25 -4
  108. package/scripts/cm-review-inventory.test.mjs +25 -6
  109. package/scripts/cm-run-analysis.mjs +21 -0
  110. package/scripts/cm-run-analysis.test.mjs +120 -0
  111. package/scripts/cm-spec-amend.mjs +68 -0
  112. package/scripts/cm-spec-amend.test.mjs +510 -0
  113. package/scripts/cm-specs-status.test.mjs +6 -0
  114. package/scripts/cm-start-check.mjs +140 -53
  115. package/scripts/cm-start-check.test.mjs +139 -1
  116. package/scripts/cm-task-scope.test.mjs +3 -2
  117. package/scripts/cm-usage-report.py +8 -3
  118. package/scripts/cm019-r1-contract.test.mjs +137 -0
  119. package/scripts/cm019-review-gates.test.mjs +97 -0
  120. package/scripts/test-journal-limit-1mib.mjs +4 -0
  121. package/scripts/validate-public-repo.py +4 -0
  122. package/skills/cm-ai/references/N1-init.md +23 -1
  123. package/skills/cm-ai/references/js-host-qa-recovery.md +3 -2
  124. package/skills/cm-ai/references/js-host-recovery.md +2 -1
  125. package/skills/cm-ai/references/js-host.md +7 -2
  126. package/skills/cm-prd/references/js-change-recovery.md +2 -1
  127. package/skills/cm-prd/references/js-host.md +1 -0
@@ -26,11 +26,12 @@ export function scanRows(log,visit) {
26
26
  // read to its recorded size. Lines are parsed with plain JSON.parse, as the
27
27
  // historical log readers did; only selected rows are kept, in log order.
28
28
  const stableKey=s=>[s.dev,s.ino,s.mode,s.nlink,s.size,s.mtimeNs,s.ctimeNs].join(':');
29
- export function readStableLogRows(file,select,code){
29
+ export function readStableLogRows(file,select,code,{maxBytes=Infinity}={}){
30
30
  let descriptor;
31
31
  try{
32
32
  const before=fs.lstatSync(file,{bigint:true});
33
- need(before.isFile()&&!before.isSymbolicLink()&&before.nlink===1n,code);
33
+ need(before.isFile()&&!before.isSymbolicLink()&&before.nlink===1n
34
+ &&(maxBytes===Infinity||before.size<=BigInt(maxBytes)),code);
34
35
  descriptor=fs.openSync(file,fs.constants.O_RDONLY|fs.constants.O_NOFOLLOW);
35
36
  need(stableKey(fs.fstatSync(descriptor,{bigint:true}))===stableKey(before),code);
36
37
  const rows=[],chunk=Buffer.alloc(64*1024),decoder=new TextDecoder('utf-8',{fatal:true,ignoreBOM:true});
@@ -26,10 +26,73 @@ const documentationMessages={
26
26
  const explain=(summary,nextStep,operation=null,prerequisites=[])=>Object.freeze({
27
27
  summary,nextStep,recoveryOperation:operation,prerequisites:Object.freeze(prerequisites),authorizationGranted:false,
28
28
  });
29
+ const phases={verification_precheck_failed:['verification','验收要求核对'],
30
+ develop_checks_not_passed:['checks','开发检查'],checks_not_passed:['checks','旧完成检查'],
31
+ completion_checks_changed:['completion','完成前复查'],completion_package_changed:['completion','完成前复查'],
32
+ complete_recheck_failed:['completion','完成前复查'],complete_commit_interrupted:['completion','完成写入恢复'],
33
+ spec_drift:['specification','规格绑定核对']};
34
+ const reviewStops=new Set(['review_transport_timeout','review_provider_failed','review_verdict_invalid',
35
+ 'review_abandoned','review_redispatch_limit','review_blocked','review_limit']);
36
+ const safeLine=value=>typeof value==='string'&&!/[\x00-\x1f\x7f-\x9f\u202a-\u202e\u2066-\u2069]/.test(value);
37
+ const clipDiagnostic=value=>{
38
+ let text='';for(const char of value){if(Buffer.byteLength(text+char)>1600)break;text+=char;}
39
+ const truncated=text.length!==value.length;
40
+ return {status:'recorded',source:'current_result.reason',text:text+(truncated?'…(完整原因见 result.reason)':''),truncated};
41
+ };
42
+ // Reasons are explanatory evidence, never a recovery permission. Display only
43
+ // host-formatted diagnostics for this code; arbitrary provider reasons stay out
44
+ // of the driver's human channel. Older checkpoints legitimately have no detail.
45
+ function diagnosticFor(result){
46
+ const {reason,code}=result;
47
+ if(safeLine(reason)&&reason.length<=8192){
48
+ if(['verification_precheck_failed','develop_checks_not_passed','checks_not_passed','completion_checks_changed'].includes(code)
49
+ &&reason.startsWith(code+':')&&reason.slice(code.length+1).trim())return clipDiagnostic(reason);
50
+ if(code==='spec_drift'&&/^(规格当前未处于|规格已重新批准,变更文件:|规格已变更:)/.test(reason))
51
+ return clipDiagnostic(reason.split(';')[0]); // Do not copy legacy launch flags into v2/batch guidance.
52
+ }
53
+ return {status:'unknown',source:null,text:'当前结果未记录可展示的具体缺项;请核对原运行证据,不推断其他检查已通过。',truncated:false};
54
+ }
55
+ const identityMatches=(a,b)=>a&&b&&['repositoryId','runId','taskId','attempt'].every(key=>a[key]===b[key]);
56
+ function validEvidenceFor(result){
57
+ const c=result.completion,items=[];
58
+ // A receipt's presence or a successful historical run is insufficient. Only
59
+ // the already validated, current snapshot projection can supply these claims.
60
+ if(/^[a-f0-9]{64}$/.test(c?.snapshotDigest??'')&&c?.binding?.runnerRevision
61
+ &&identityMatches(c.binding.identity,result.identity)&&c.binding.packageDigest===result.packageDigest
62
+ &&c.task?.status==='completed'&&!['spec_drift','correction_review_required'].includes(result.code)){
63
+ if(c.task.review?.status==='passed')for(const reference of c.task.review.evidence??[])
64
+ if(/^receipt:[a-f0-9]{64}$/.test(reference))items.push({kind:'task_review',reference});
65
+ if(c.feature?.status==='passed'&&c.feature.qa?.status==='passed')items.push({kind:'feature_qa',reference:'completion.feature.qa'});
66
+ }
67
+ return {status:items.length?'confirmed':'unknown',items:Object.freeze(items.map(Object.freeze)),
68
+ message:items.length?'仅列当前完成摘要已核对的证据;恢复动作仍须再次核对原条件。'
69
+ :'当前结果不足以确认哪些旧证据仍可复用;保留原记录,不将历史通过当作当前通过。'};
70
+ }
71
+ function blockageFor(result,guidance,{executionActive=false}={}){
72
+ const action=guidance.recoveryOperation;
73
+ const phase=executionActive?['in_flight','原操作执行中']:Object.hasOwn(phases,result.code)?phases[result.code]
74
+ :result.state==='pending_review'||reviewStops.has(result.code)||['abandon_review','reconcile_review'].includes(result.pendingAction)
75
+ ?['review','独立审查']:['unknown','阶段未确认'];
76
+ let checks='unknown',reviewCalls='unknown';
77
+ if(['abandon_effect','abandon_review','develop_redo'].includes(action)){checks='not_dispatched';reviewCalls='not_dispatched';}
78
+ else if(action==='complete'){checks=result.code==='complete_commit_interrupted'?'not_dispatched':'rerun';reviewCalls='not_dispatched';}
79
+ // advance may cross review -> completion/QA, or review -> next development
80
+ // attempt. Describe the whole operation, not only the phase where it starts.
81
+ else if(action==='advance'){checks='may_run';reviewCalls='may_dispatch';}
82
+ const decision=executionActive?'wait':action&&['abandon_effect','abandon_review','develop_redo','bootstrap_review_recover'].includes(action)
83
+ ||result.code==='spec_drift'&&result.pendingAction==='spec_rebind'?'required':action?'existing_conditions'
84
+ :['blocked','unknown'].includes(result.state)?'not_available':'unknown';
85
+ return Object.freeze({version:1,phase:Object.freeze({code:phase[0],label:phase[1]}),
86
+ detail:Object.freeze(diagnosticFor(result)),validEvidence:Object.freeze(validEvidenceFor(result)),
87
+ recovery:Object.freeze({operation:action,decision,checks,reviewCalls,
88
+ budget:'original_limits_apply',authorizationGranted:false}),
89
+ inspection:Object.freeze({readOnly:true,dispatchedCalls:0})});
90
+ }
91
+ const withBlockage=(result,guidance,options={})=>guidance?Object.freeze({...guidance,blockage:blockageFor(result,guidance,options)}):null;
29
92
  // Rendering context is private and ephemeral; it never enters results or journals.
30
93
  const guidanceContext=new WeakMap();
31
94
  export function operatorGuidance(result,options={}){
32
- const guidance=renderOperatorGuidance(result,options);
95
+ const guidance=withBlockage(result,renderOperatorGuidance(result,options),options);
33
96
  if(guidance)guidanceContext.set(guidance,{executionActive:options.executionActive===true,protocol:options.protocol??'legacy'});
34
97
  return guidance;
35
98
  }
@@ -161,14 +224,33 @@ function renderOperatorGuidance(result,{executionActive=false,protocol='legacy',
161
224
  '核对 code、reason 和原运行证据;保留已有文件与历史,不把通用阻塞当作重试许可。');
162
225
  return null;
163
226
  }
164
- // Only bounded static guidance is rendered, never raw provider output.
227
+ // Static instructions plus bounded host-formatted diagnostics; never raw
228
+ // provider output. The structured explanation does not authorize an operation.
165
229
  export function guidanceText(result){
166
230
  if(result?.workflow!=='cm-ai')return null;
167
231
  const guidance=result?.guidance;
168
- const bounded=value=>typeof value==='string'&&Buffer.byteLength(value,'utf8')<=2000&&!/[\r\n\0]/.test(value);
232
+ const bounded=value=>safeLine(value)&&Buffer.byteLength(value,'utf8')<=2000;
169
233
  if(!guidance||guidance.authorizationGranted!==false||!bounded(guidance.summary)||!bounded(guidance.nextStep)
170
234
  ||!Array.isArray(guidance.prerequisites)||guidance.prerequisites.length>8||!guidance.prerequisites.every(bounded))return null;
171
- return `${guidance.summary} ${guidance.nextStep} ${guidance.prerequisites.join(';')}`.trim();
235
+ const text=`${guidance.summary} ${guidance.nextStep} ${guidance.prerequisites.join(';')}`.trim();
236
+ const b=guidance.blockage;
237
+ if(!b||b.version!==1||!bounded(b.phase?.label)||!bounded(b.detail?.text)
238
+ ||!bounded(b.validEvidence?.message)||!Array.isArray(b.validEvidence?.items)||b.validEvidence.items.length>8
239
+ ||!b.validEvidence.items.every(item=>item&&['task_review','feature_qa'].includes(item.kind))
240
+ ||b.recovery?.authorizationGranted!==false)return text;
241
+ const checks={unknown:'检查是否重跑待核对',not_dispatched:'该恢复动作不直接运行检查',rerun:'将重新运行检查',
242
+ may_run:'推进可能跨阶段并运行检查或 QA'};
243
+ const review={unknown:'审查调用待核对',not_dispatched:'该恢复动作不直接派发审查',may_dispatch:'后续可能派发审查,仍受原授权与预算约束'};
244
+ const decisions={wait:'等待原操作,不重复派发',required:'需要用户按原入口确认具体恢复动作',
245
+ existing_conditions:'按原运行已有授权与前置条件核对',not_available:'当前没有已确认可直接发送的恢复操作',
246
+ unknown:'是否需要新决定,须核对上述原入口条件'};
247
+ if(!Object.hasOwn(checks,b.recovery.checks)||!Object.hasOwn(review,b.recovery.reviewCalls)
248
+ ||!Object.hasOwn(decisions,b.recovery.decision))return text;
249
+ const evidence=b.validEvidence.status==='confirmed'
250
+ ?`当前已核对证据:${b.validEvidence.items.map(item=>item.kind==='task_review'?'任务独立审查':item.kind==='feature_qa'?'功能 QA':'未知').join('、')}`
251
+ :'当前可复用证据:UNKNOWN';
252
+ return `${text}\n阶段:${b.phase.label}。门禁记录的缺项/原因:${b.detail.text}\n${evidence}。${b.validEvidence.message}`
253
+ +`\n恢复条件:${decisions[b.recovery.decision]};${checks[b.recovery.checks]};${review[b.recovery.reviewCalls]}。查询本身不派发调用,也不重置原预算。`;
172
254
  }
173
255
 
174
256
  // Q24: in-run recovery operations the batch entry forwards to the stopped member
@@ -182,6 +264,9 @@ const BATCH_RECOVERY={
182
264
  // A member result is not a batch control surface. Keep unsupported single-run
183
265
  // recovery operations out of batch instructions without changing pendingAction.
184
266
  export function batchOperatorGuidance(result,{taskKey=null,protocol='legacy'}={}){
267
+ return withBlockage(result,renderBatchOperatorGuidance(result,{taskKey,protocol}),guidanceContext.get(result?.guidance));
268
+ }
269
+ function renderBatchOperatorGuidance(result,{taskKey=null,protocol='legacy'}={}){
185
270
  const context=guidanceContext.get(result?.guidance);
186
271
  const g=context?operatorGuidance(result,{...context,protocol,surface:'batch'}):result?.guidance;
187
272
  if(!g)return null;
@@ -206,3 +291,24 @@ export function batchOperatorGuidance(result,{taskKey=null,protocol='legacy'}={}
206
291
  '批次入口不支持此成员恢复操作;先核对原成员运行与 reason,不通过 advance 重派或新建运行绕过。');
207
292
  return g;
208
293
  }
294
+
295
+ // Pure formatting shared by all drivers, including partial check-only runtimes.
296
+ export function deliveryLines(value){
297
+ return [['productAcceptance','产品人工验收'],['deployment','发布/部署']].map(([field,label])=>{
298
+ const section=value[field];if(!section?.environments?.length)return `${label}:UNKNOWN`;
299
+ return `${label}:`+section.environments.map(e=>`${e.environment} [${e.artifactSha256.slice(0,12)}] ${e.status==='recorded'?'声明已记录':e.status==='unknown'?'UNKNOWN':'STALE'}(${
300
+ field==='productAcceptance'?e.statement.outcome:`执行 ${e.statement.execution};部署后验证 ${e.statement.verification}`})`).join(';');
301
+ });
302
+ }
303
+
304
+ const label={completed:'已完成',passed:'PASS',failed:'FAIL',blocked:'BLOCKED',unknown:'UNKNOWN',pending:'未完成',
305
+ skipped:'SKIPPED',finalized:'已收尾',ready_to_finalize:'具备收尾条件,尚未收尾'};
306
+ export function completionLines(summary){
307
+ if(!summary||summary.version!==1)return [];
308
+ const feature=summary.feature,project=summary.project;
309
+ const protection={contract_v1:'冻结合同 v1',legacy_unprotected:'旧运行,未受新合同保护',unknown:'验收保护 UNKNOWN'}[summary.task.acceptanceProtection];
310
+ return [`完成范围:task ${summary.binding.identity?.taskId??'未知'} ${label[summary.task.status]??'UNKNOWN'}(独立审查 ${label[summary.task.review?.status]??'UNKNOWN'})${protection?`;${protection}`:''}`,
311
+ `功能 ${summary.binding.feature??'未知'}:任务 ${feature.tasks?`${feature.tasks.completed}/${feature.tasks.total}`:'UNKNOWN'};QA ${label[feature.qa?.status]??'UNKNOWN'};当前资格 ${label[feature.status]??'UNKNOWN'}`,
312
+ `项目批准范围:${project.totalFeatures===undefined?'UNKNOWN':`${project.completedFeatures}/${project.totalFeatures} 个功能通过,${project.pendingTasks} 个待办`};${label[project.status]??'UNKNOWN'}`,
313
+ `本运行收尾:${label[summary.run.status]??'UNKNOWN'};${deliveryLines(summary).join(';')}`];
314
+ }
@@ -27,12 +27,14 @@ export function readRequirementItems(raw,code='verification_precheck_invalid'){
27
27
  need(Array.isArray(raw)&&raw.length>0&&raw.length<=REQUIREMENT_ITEM_LIMIT,code);
28
28
  const items=raw.map(item=>{
29
29
  need(item!==null&&typeof item==='object'&&!Array.isArray(item),code);
30
- try{shape(item,['requirement','satisfied','evidence',...['run','result'].filter(key=>Object.hasOwn(item,key))]);}catch{need(false,code);}
30
+ try{shape(item,['requirement','satisfied','evidence',...['run','result','id','evidenceType','environment'].filter(key=>Object.hasOwn(item,key))]);}catch{need(false,code);}
31
31
  need(typeof item.satisfied==='boolean',code);
32
32
  boundedText(item.requirement,code);boundedText(item.evidence,code);
33
33
  const run=item.run??null,result=item.result??null;
34
34
  need(run===null||RUNS.has(run),code);need(result===null||RESULTS.has(result),code);
35
+ for(const key of ['id','evidenceType','environment'])if(item[key]!==undefined&&item[key]!==null)boundedText(item[key],code);
35
36
  return freeze({requirement:item.requirement,satisfied:item.satisfied,evidence:item.evidence,
37
+ ...Object.fromEntries(['id','evidenceType','environment'].filter(key=>item[key]!=null).map(key=>[key,item[key]])),
36
38
  ...(run===null?{}:{run}),...(result===null||run!=='baseline'?{}:{result})});
37
39
  });
38
40
  need(Buffer.byteLength(JSON.stringify(items),'utf8')<=REQUIREMENT_EVIDENCE_LIMIT,code);
@@ -68,7 +70,7 @@ export function readRequirementEvidence(entry){
68
70
  export function requirementReportProblem(raw){
69
71
  if(!Array.isArray(raw))return 'not a list';
70
72
  if(raw.length>REQUIREMENT_ITEM_LIMIT)return `more than ${REQUIREMENT_ITEM_LIMIT} items`;
71
- const known=['requirement','satisfied','evidence','run','result'];
73
+ const known=['requirement','satisfied','evidence','run','result','id','evidenceType','environment'];
72
74
  for(const [index,item] of raw.entries()){
73
75
  const at=`item ${index+1}`;
74
76
  if(item===null||typeof item!=='object'||Array.isArray(item))return `${at}: not an object`;
@@ -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;
@@ -466,7 +480,7 @@ const sealed = (data,key) => {
466
480
  need(Buffer.byteLength(JSON.stringify(result))<=8*1024*1024,'limit_exceeded');
467
481
  return freeze(result);
468
482
  };
469
- export function captureReviewBaseline(options,legacy=false,policyVersion=2,baselinePolicy=null) {
483
+ export function captureReviewBaseline(options,legacy=false,policyVersion=2,baselinePolicy=null,acceptance=true) {
470
484
  const v=plain(options); keys(v,['root','identity','scope','requirements',
471
485
  ...['specsRoot','codeProjectPaths','bootstrapRequirements','specification','version','scopeRevisionPaths'].filter(key=>Object.hasOwn(v,key))]); identityCheck(v.identity);
472
486
  const version=v.version??2;need([1,2].includes(version));
@@ -480,7 +494,7 @@ export function captureReviewBaseline(options,legacy=false,policyVersion=2,basel
480
494
  if(Object.hasOwn(v,'specification')){
481
495
  keys(v.specification,['specsRoot','feature']);
482
496
  need(v.specification.specsRoot===v.specsRoot,'spec_drift');
483
- specification=captureSpecificationMaterial({...v.specification,taskId:v.identity.taskId});
497
+ specification=captureSpecificationMaterial({...v.specification,taskId:v.identity.taskId,acceptance});
484
498
  }
485
499
  const scope=paths(v.scope), requirements=requirementPaths(v.requirements,bootstrap!==null||specification!==null),root=rootPath(v.root);
486
500
  need(![...scope,...requirements].some(p=>inDependencyDirectory(p)||inCocoaPodsTree(root,p)),'excluded_snapshot_path');
@@ -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)];