@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.
- package/.codex-plugin/plugin.json +1 -1
- package/AGENTS.md +8 -0
- package/CHANGELOG.md +38 -0
- package/README.md +15 -1
- package/VERSION +1 -1
- package/docs/architecture.md +3 -0
- package/docs/cm-acceptance-completion.md +185 -0
- package/docs/installation.md +1 -1
- package/docs/js-workflow-control.md +1 -1
- package/docs/proposals/spec-amendment-tiers.md +100 -0
- package/package.json +1 -1
- package/runtime/js/acceptance-language.mjs +32 -0
- package/runtime/js/autonomy.mjs +168 -3
- package/runtime/js/check-coverage.mjs +130 -0
- package/runtime/js/cm-ai/acceptance-contract.mjs +257 -0
- package/runtime/js/cm-ai/checkpoint-package-material.mjs +13 -3
- package/runtime/js/cm-ai/claude-developer-proposal.schema.json +18 -0
- package/runtime/js/cm-ai/cm-ai-admission.mjs +49 -8
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +10 -6
- package/runtime/js/cm-ai/cm-ai-run-finalizer.mjs +8 -3
- package/runtime/js/cm-ai/codex-developer-basic-output.schema.json +1 -1
- package/runtime/js/cm-ai/codex-developer-output.schema.json +1 -1
- package/runtime/js/cm-ai/codex-review-adapter.mjs +19 -3
- package/runtime/js/cm-ai/completion-summary.mjs +187 -0
- package/runtime/js/cm-ai/control-policy.mjs +3 -1
- package/runtime/js/cm-ai/delivery-evidence.mjs +173 -0
- package/runtime/js/cm-ai/developer-adapter.mjs +4 -0
- package/runtime/js/cm-ai/drive-core.mjs +15 -4
- package/runtime/js/cm-ai/durable-runner-state.mjs +10 -6
- package/runtime/js/cm-ai/effect-contract.mjs +8 -1
- package/runtime/js/cm-ai/execution-snapshot.mjs +4 -3
- package/runtime/js/cm-ai/execution-store-limits.mjs +3 -3
- package/runtime/js/cm-ai/execution-store.mjs +7 -4
- package/runtime/js/cm-ai/fix-code-association.mjs +27 -6
- package/runtime/js/cm-ai/gate-bridge.mjs +13 -1
- package/runtime/js/cm-ai/host-conversation-execution.mjs +26 -14
- package/runtime/js/cm-ai/host-progress.mjs +2 -1
- package/runtime/js/cm-ai/log-rows.mjs +3 -2
- package/runtime/js/cm-ai/operator-guidance.mjs +110 -4
- package/runtime/js/cm-ai/requirement-evidence.mjs +4 -2
- package/runtime/js/cm-ai/review-package.mjs +22 -8
- package/runtime/js/cm-ai/review-presentation.mjs +12 -5
- package/runtime/js/cm-ai/reviewed-deliveries.mjs +10 -7
- package/runtime/js/cm-ai/reviewed-integration.mjs +1 -1
- package/runtime/js/cm-ai/spec-amendment.mjs +535 -0
- package/runtime/js/cm-ai/specification-material.mjs +57 -12
- package/runtime/js/cm-ai/task-commit.mjs +4 -2
- package/runtime/js/cm-ai/task-runner.mjs +64 -22
- package/runtime/js/cm-ai/user-maintained-paths.mjs +68 -0
- package/runtime/js/cm-ai/verification-auto.mjs +6 -4
- package/runtime/js/cm-prd/acceptance-preview.mjs +203 -0
- package/runtime/js/cm-prd/change.mjs +52 -5
- package/runtime/js/cm-prd/self-check.mjs +36 -6
- package/runtime/js/cm-prd/session.mjs +8 -3
- package/runtime/js/cm-prd/summary.mjs +5 -0
- package/runtime/js/cm-prd/task-scope-record.mjs +13 -7
- package/runtime/js/node-test-selection.mjs +38 -0
- package/runtime/js/run-analysis.mjs +153 -0
- package/runtime/js/session-boundary.mjs +17 -5
- package/runtime/js/session-handoff.mjs +5 -2
- package/runtime/js/task-scope.mjs +4 -1
- package/runtime/test-contract.md +1 -0
- package/scripts/cm-acceptance-preview.mjs +26 -0
- package/scripts/cm-acceptance-preview.test.mjs +156 -0
- package/scripts/cm-ai-acceptance-contract.test.mjs +195 -0
- package/scripts/cm-ai-admission.mjs +8 -2
- package/scripts/cm-ai-admission.test.mjs +20 -4
- package/scripts/cm-ai-blockage.test.mjs +120 -0
- package/scripts/cm-ai-checklist-coverage.test.mjs +5 -2
- package/scripts/cm-ai-checkpoint-package-material.test.mjs +60 -6
- package/scripts/cm-ai-checkpoint-package-owner.test.mjs +1 -0
- package/scripts/cm-ai-completion-summary.test.mjs +154 -0
- package/scripts/cm-ai-conversation-entry-ops.test.mjs +8 -2
- package/scripts/cm-ai-develop-driver-gaps.test.mjs +1 -0
- package/scripts/cm-ai-drive.mjs +18 -11
- package/scripts/cm-ai-fix-later-delivery.test.mjs +2 -2
- package/scripts/cm-ai-later-delivery-feature.test.mjs +102 -0
- package/scripts/cm-ai-progress.test.mjs +7 -0
- package/scripts/cm-ai-project-qa-gate.test.mjs +55 -4
- package/scripts/cm-ai-review-input-limit.test.mjs +91 -0
- package/scripts/cm-ai-run.test.mjs +23 -1
- package/scripts/cm-ai-spec-rebind.test.mjs +51 -15
- package/scripts/cm-ai-user-maintained-paths.test.mjs +183 -0
- package/scripts/cm-ai-verification-auto.test.mjs +33 -8
- package/scripts/cm-ai-verification-gate.test.mjs +1 -1
- package/scripts/cm-autonomy-acceptance.test.mjs +212 -0
- package/scripts/cm-autonomy-review-r1.test.mjs +142 -0
- package/scripts/cm-autonomy.mjs +3 -1
- package/scripts/cm-autonomy.test.mjs +10 -9
- package/scripts/cm-check-runtime.sh +5 -2
- package/scripts/cm-delivery-evidence.mjs +59 -0
- package/scripts/cm-delivery-evidence.test.mjs +177 -0
- package/scripts/cm-drive-liveness.test.mjs +14 -0
- package/scripts/cm-driver-light-import.test.mjs +32 -0
- package/scripts/cm-fix-observation-task-id.test.mjs +49 -0
- package/scripts/cm-fix-review-storage.test.mjs +14 -4
- package/scripts/cm-journal-limit.test.mjs +69 -0
- package/scripts/cm-mandatory-check-coverage.test.mjs +82 -0
- package/scripts/cm-node-test-selection.test.mjs +108 -0
- package/scripts/cm-notify-read-drift.test.mjs +6 -3
- package/scripts/cm-prd-completion.test.mjs +49 -0
- package/scripts/cm-prd-drive.mjs +1 -1
- package/scripts/cm-prd-host.mjs +3 -1
- package/scripts/cm-prd-host.test.mjs +19 -2
- package/scripts/cm-prd-self-check-rules.test.mjs +23 -11
- package/scripts/cm-prd-self-check.test.mjs +24 -1
- package/scripts/cm-prd-summary.test.mjs +25 -4
- package/scripts/cm-review-inventory.test.mjs +25 -6
- package/scripts/cm-run-analysis.mjs +21 -0
- package/scripts/cm-run-analysis.test.mjs +120 -0
- package/scripts/cm-spec-amend.mjs +68 -0
- package/scripts/cm-spec-amend.test.mjs +510 -0
- package/scripts/cm-specs-status.test.mjs +6 -0
- package/scripts/cm-start-check.mjs +140 -53
- package/scripts/cm-start-check.test.mjs +139 -1
- package/scripts/cm-task-scope.test.mjs +3 -2
- package/scripts/cm-usage-report.py +8 -3
- package/scripts/cm019-r1-contract.test.mjs +137 -0
- package/scripts/cm019-review-gates.test.mjs +97 -0
- package/scripts/test-journal-limit-1mib.mjs +4 -0
- package/scripts/validate-public-repo.py +4 -0
- package/skills/cm-ai/references/N1-init.md +23 -1
- package/skills/cm-ai/references/js-host-qa-recovery.md +3 -2
- package/skills/cm-ai/references/js-host-recovery.md +2 -1
- package/skills/cm-ai/references/js-host.md +7 -2
- package/skills/cm-prd/references/js-change-recovery.md +2 -1
- package/skills/cm-prd/references/js-host.md +1 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
// Local declarations, not an authentication service or a deployment executor.
|
|
2
|
+
// Original execution/review evidence remains authoritative for task completion.
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import {createHash,randomUUID} from 'node:crypto';
|
|
6
|
+
import {digest,need,shape,hex,id,validIdentity,json,freeze} from './effect-contract.mjs';
|
|
7
|
+
import {readExecutionSnapshot} from './execution-snapshot.mjs';
|
|
8
|
+
import {readRunnerHistory,attemptBaseline} from './durable-runner-state.mjs';
|
|
9
|
+
import {readReviewSourceFiles,verifyReviewPackage} from './review-package.mjs';
|
|
10
|
+
import {verifyApprovedManifest} from '../../../scripts/cm-spec-manifest.mjs';
|
|
11
|
+
|
|
12
|
+
const directory='.reviews/.delivery',MAX_RECORDS=1000;
|
|
13
|
+
const environmentKey=value=>value.trim().toLowerCase();
|
|
14
|
+
const key=s=>[s.dev,s.ino,s.mode,s.nlink,s.size,s.mtimeNs,s.ctimeNs].join(':');
|
|
15
|
+
const line=value=>need(typeof value==='string'&&value.trim().length>0&&value.length<=240
|
|
16
|
+
&&!/[\x00-\x1f\x7f-\x9f\u202a-\u202e\u2066-\u2069]/.test(value),'delivery_invalid_text');
|
|
17
|
+
function rootDirectory(specsDir,create=false){
|
|
18
|
+
need(typeof specsDir==='string'&&path.isAbsolute(specsDir)&&fs.realpathSync(specsDir)===specsDir,'delivery_invalid_root');
|
|
19
|
+
let current=specsDir;
|
|
20
|
+
for(const part of directory.split('/')){
|
|
21
|
+
current=path.join(current,part);
|
|
22
|
+
if(create)try{fs.mkdirSync(current,{mode:0o700});}catch(error){if(error.code!=='EEXIST')throw error;}
|
|
23
|
+
try{const stat=fs.lstatSync(current);need(stat.isDirectory()&&!stat.isSymbolicLink(),'delivery_invalid_directory');}
|
|
24
|
+
catch(error){if(!create&&error.code==='ENOENT')return null;throw error;}
|
|
25
|
+
}
|
|
26
|
+
return current;
|
|
27
|
+
}
|
|
28
|
+
// Bounded streaming hash also supports build files larger than review text.
|
|
29
|
+
export function deliveryFile(file,{maxBytes=1024*1024*1024}={}){
|
|
30
|
+
need(typeof file==='string'&&path.isAbsolute(file)&&fs.realpathSync(file)===file,'delivery_invalid_file');
|
|
31
|
+
const before=fs.lstatSync(file,{bigint:true});
|
|
32
|
+
need(before.isFile()&&!before.isSymbolicLink()&&before.nlink===1n&&before.size>0n&&before.size<=1024n*1024n*1024n,'delivery_invalid_file');
|
|
33
|
+
need(before.size<=BigInt(maxBytes),'delivery_evidence_budget_exceeded');
|
|
34
|
+
const fd=fs.openSync(file,fs.constants.O_RDONLY|fs.constants.O_NOFOLLOW),hash=createHash('sha256');
|
|
35
|
+
let size=0;
|
|
36
|
+
try{
|
|
37
|
+
need(key(fs.fstatSync(fd,{bigint:true}))===key(before),'delivery_file_changed');
|
|
38
|
+
const buffer=Buffer.alloc(64*1024);
|
|
39
|
+
while(true){const n=fs.readSync(fd,buffer,0,buffer.length,null);if(!n)break;
|
|
40
|
+
size+=n;need(BigInt(size)<=before.size,'delivery_file_changed');hash.update(buffer.subarray(0,n));}
|
|
41
|
+
need(BigInt(size)===before.size&&key(fs.fstatSync(fd,{bigint:true}))===key(before)
|
|
42
|
+
&&key(fs.lstatSync(file,{bigint:true}))===key(before),'delivery_file_changed');
|
|
43
|
+
}finally{fs.closeSync(fd);}
|
|
44
|
+
return {path:file,sha256:hash.digest('hex'),size};
|
|
45
|
+
}
|
|
46
|
+
function validFile(file){shape(file,['path','sha256','size']);need(typeof file.path==='string'&&path.isAbsolute(file.path),'delivery_invalid_file');
|
|
47
|
+
hex(file.sha256);need(Number.isSafeInteger(file.size)&&file.size>0&&file.size<=1024*1024*1024,'delivery_invalid_file');}
|
|
48
|
+
function validCandidate(c){
|
|
49
|
+
shape(c,['version','feature','identity','packageDigest','specificationDigest','artifact','runnerRevision']);
|
|
50
|
+
need(c.version===1,'delivery_invalid_candidate');line(c.feature);need(!/[\\/]/.test(c.feature)&&!['.','..'].includes(c.feature),'delivery_invalid_candidate');
|
|
51
|
+
validIdentity(c.identity);[c.packageDigest,c.specificationDigest,c.runnerRevision].forEach(hex);validFile(c.artifact);
|
|
52
|
+
}
|
|
53
|
+
function validStatement(kind,s){
|
|
54
|
+
shape(s,kind==='acceptance'?['actor','environment','outcome','note']:['actor','environment','execution','verification','note']);
|
|
55
|
+
[s.actor,s.environment,s.note].forEach(line);
|
|
56
|
+
if(kind==='acceptance')need(['accepted','rejected','revoked'].includes(s.outcome),'delivery_invalid_statement');
|
|
57
|
+
else {need(['succeeded','failed'].includes(s.execution)&&['passed','failed','unknown'].includes(s.verification),'delivery_invalid_statement');
|
|
58
|
+
need(s.execution==='succeeded'||s.verification!=='passed','delivery_invalid_statement');}
|
|
59
|
+
}
|
|
60
|
+
function validRecord(record,sequence,previousDigest){
|
|
61
|
+
const r=json(record,32*1024);shape(r,['version','sequence','previousDigest','at','kind','candidate','statement','evidence','provenance','recordDigest']);
|
|
62
|
+
need(r.version===1&&r.sequence===sequence&&r.previousDigest===previousDigest&&['acceptance','deployment'].includes(r.kind),'delivery_record_invalid');
|
|
63
|
+
need(typeof r.at==='string'&&new Date(r.at).toISOString()===r.at&&r.provenance==='interactive-terminal-declaration','delivery_record_invalid');
|
|
64
|
+
validCandidate(r.candidate);validStatement(r.kind,r.statement);
|
|
65
|
+
shape(r.evidence,['report','verificationReport']);validFile(r.evidence.report);
|
|
66
|
+
if(r.evidence.verificationReport!==null)validFile(r.evidence.verificationReport);
|
|
67
|
+
need(r.kind==='deployment'&&r.statement.verification!=='unknown'?r.evidence.verificationReport!==null:r.evidence.verificationReport===null,'delivery_verification_report_required');
|
|
68
|
+
const {recordDigest,...body}=r;need(digest(body)===recordDigest,'delivery_record_invalid');return r;
|
|
69
|
+
}
|
|
70
|
+
export function readDeliveryRecords(specsDir){
|
|
71
|
+
const dir=rootDirectory(specsDir);if(dir===null)return freeze([]);
|
|
72
|
+
const before=fs.lstatSync(dir,{bigint:true}),entries=fs.readdirSync(dir);
|
|
73
|
+
need(entries.length<=MAX_RECORDS*2,'delivery_record_limit');
|
|
74
|
+
const names=entries.filter(name=>!name.startsWith('.pending-')&&name!=='.DS_Store').sort();
|
|
75
|
+
need(names.length<=MAX_RECORDS,'delivery_record_limit');const records=[],watched=[];
|
|
76
|
+
for(const [index,name] of names.entries()){
|
|
77
|
+
need(name===String(index+1).padStart(6,'0'),'delivery_record_invalid');
|
|
78
|
+
const entry=path.join(dir,name),entryStat=fs.lstatSync(entry,{bigint:true});
|
|
79
|
+
need(entryStat.isDirectory()&&!entryStat.isSymbolicLink()&&JSON.stringify(fs.readdirSync(entry))===JSON.stringify(['record.json']),'delivery_record_invalid');
|
|
80
|
+
const location=path.join(entry,'record.json'),stat=key(fs.lstatSync(location,{bigint:true}));
|
|
81
|
+
const file=readReviewSourceFiles(specsDir,[`${directory}/${name}/record.json`])[0];watched.push([entry,key(entryStat)],[location,stat]);
|
|
82
|
+
records.push(validRecord(JSON.parse(Buffer.from(file.contentBase64,'base64').toString('utf8')),index+1,records.at(-1)?.recordDigest??null));
|
|
83
|
+
}
|
|
84
|
+
need(key(before)===key(fs.lstatSync(dir,{bigint:true}))&&watched.every(([file,stat])=>key(fs.lstatSync(file,{bigint:true}))===stat),'delivery_snapshot_changed');return freeze(records);
|
|
85
|
+
}
|
|
86
|
+
function currentDeliveryOwner({specsDir,repositoryId,runId,feature}){
|
|
87
|
+
[repositoryId,runId].forEach(id);line(feature);
|
|
88
|
+
const snapshot=readExecutionSnapshot({specsRoot:specsDir,identity:{repositoryId,runId}}),init=snapshot.records[0]?.payload;
|
|
89
|
+
const history=readRunnerHistory(snapshot.records,init.config,init.version),state=history.state;
|
|
90
|
+
need(history.pending===null&&state.state==='fixture_completed'&&state.receipt?.result?.verdict==='approved','delivery_candidate_incomplete');
|
|
91
|
+
const pkg=state.reviewPackage,baseline=attemptBaseline(history.original,state.attempt);
|
|
92
|
+
need(baseline.specification?.feature===feature&&init.config.completion?.owner?.specsRoot===specsDir,'delivery_candidate_mismatch');
|
|
93
|
+
verifyReviewPackage({root:init.config.root,baseline,checks:pkg.checks,reviewPackage:pkg,expectedDigest:pkg.packageDigest,
|
|
94
|
+
...(pkg.handoff?{handoffPath:init.config.completion.handoffs[state.attempt-1]}:{})});
|
|
95
|
+
const manifest=verifyApprovedManifest(specsDir,path.join(specsDir,'.cm-specs-status'));
|
|
96
|
+
return {version:1,feature,identity:pkg.identity,packageDigest:pkg.packageDigest,specificationDigest:digest(manifest),runnerRevision:snapshot.revision};
|
|
97
|
+
}
|
|
98
|
+
export function deliveryCandidate(options){
|
|
99
|
+
const candidate={...currentDeliveryOwner(options),artifact:deliveryFile(options.artifact)};
|
|
100
|
+
validCandidate(candidate);return freeze(candidate);
|
|
101
|
+
}
|
|
102
|
+
export function previewDelivery({specsDir,repositoryId,runId,feature,artifact,kind,statement,report,verificationReport=null}){
|
|
103
|
+
need(['acceptance','deployment'].includes(kind),'delivery_invalid_kind');validStatement(kind,statement);
|
|
104
|
+
const candidate=deliveryCandidate({specsDir,repositoryId,runId,feature,artifact}),records=readDeliveryRecords(specsDir);
|
|
105
|
+
need(records.length<MAX_RECORDS,'delivery_record_limit');
|
|
106
|
+
const body={version:1,sequence:records.length+1,previousDigest:records.at(-1)?.recordDigest??null,
|
|
107
|
+
kind,candidate,statement:json({...statement,environment:environmentKey(statement.environment)}),evidence:{report:deliveryFile(report),verificationReport:verificationReport===null?null:deliveryFile(verificationReport)}};
|
|
108
|
+
// Same shape check as persisted records, before asking a human anything.
|
|
109
|
+
const probe={...body,at:new Date().toISOString(),provenance:'interactive-terminal-declaration'};
|
|
110
|
+
validRecord({...probe,recordDigest:digest(probe)},body.sequence,body.previousDigest);
|
|
111
|
+
return freeze({...body,previewDigest:digest(body)});
|
|
112
|
+
}
|
|
113
|
+
export function deliveryConfirmation(preview){return `RECORD ${preview.kind} ${preview.previewDigest}`;}
|
|
114
|
+
// Confirmation is provided by a trusted host callback, never by parsed model JSON.
|
|
115
|
+
// The bundled CLI supplies a real interactive terminal callback; no --yes exists.
|
|
116
|
+
export async function recordDelivery(options,{confirm}={}){
|
|
117
|
+
need(typeof confirm==='function','delivery_confirmation_required');
|
|
118
|
+
const preview=previewDelivery(options),answer=await confirm(preview,deliveryConfirmation(preview));
|
|
119
|
+
need(answer===deliveryConfirmation(preview),'delivery_confirmation_refused');
|
|
120
|
+
need(digest(previewDelivery(options))===digest(preview),'delivery_preview_changed');
|
|
121
|
+
const {previewDigest,...body}=preview,recordBody={...body,at:new Date().toISOString(),provenance:'interactive-terminal-declaration'};
|
|
122
|
+
const record=freeze({...recordBody,recordDigest:digest(recordBody)}),dir=rootDirectory(options.specsDir,true);
|
|
123
|
+
const temp=path.join(dir,`.pending-${randomUUID()}`),target=path.join(dir,String(record.sequence).padStart(6,'0'));
|
|
124
|
+
// Publish a nonempty directory by atomic rename. Unlike hard-link publication,
|
|
125
|
+
// a crash cannot leave the committed record with a second link. Existing valid
|
|
126
|
+
// nonempty directories cannot be replaced. Unpublished stages remain evidence.
|
|
127
|
+
fs.mkdirSync(temp,{mode:0o700});
|
|
128
|
+
const fd=fs.openSync(path.join(temp,'record.json'),'wx',0o600);
|
|
129
|
+
try{fs.writeFileSync(fd,JSON.stringify(record)+'\n');fs.fsyncSync(fd);}finally{fs.closeSync(fd);}
|
|
130
|
+
try{
|
|
131
|
+
try{fs.lstatSync(target);need(false,'delivery_concurrent_write');}catch(error){if(error.code!=='ENOENT')throw error;}
|
|
132
|
+
fs.renameSync(temp,target);
|
|
133
|
+
}catch(error){if(['EEXIST','ENOTEMPTY'].includes(error.code))need(false,'delivery_concurrent_write');throw error;}
|
|
134
|
+
return record;
|
|
135
|
+
}
|
|
136
|
+
const unknown=reason=>({status:'unknown',reason,evidence:[],environments:[]});
|
|
137
|
+
export function deliveryProjection({specsDir,feature,identity,packageDigest,specificationDigest,current=true,artifactSha256=null,maxEvidenceBytes=1024*1024*1024*3}){
|
|
138
|
+
const result={productAcceptance:unknown('external_owner_acceptance_not_recorded'),deployment:unknown('deployment_evidence_not_recorded')};
|
|
139
|
+
try{
|
|
140
|
+
const records=readDeliveryRecords(specsDir);let owner,remaining=maxEvidenceBytes;
|
|
141
|
+
need(Number.isSafeInteger(remaining)&&remaining>=0,'delivery_evidence_budget_exceeded');
|
|
142
|
+
const checkedFiles=new Map();
|
|
143
|
+
const checkFile=file=>{
|
|
144
|
+
const prior=checkedFiles.get(file.path);if(prior!==undefined){need(digest(prior)===digest(file),'delivery_evidence_changed');return;}
|
|
145
|
+
const checked=deliveryFile(file.path,{maxBytes:remaining});remaining-=checked.size;
|
|
146
|
+
need(digest(checked)===digest(file),'delivery_evidence_changed');checkedFiles.set(file.path,checked);
|
|
147
|
+
};
|
|
148
|
+
const ownerMatches=()=>{
|
|
149
|
+
if(owner===undefined)try{const inspected=currentDeliveryOwner({specsDir,repositoryId:identity.repositoryId,runId:identity.runId,feature});
|
|
150
|
+
owner=digest(inspected.identity)===digest(identity)&&inspected.packageDigest===packageDigest&&inspected.specificationDigest===specificationDigest;
|
|
151
|
+
}catch{owner=false;}
|
|
152
|
+
return owner;
|
|
153
|
+
};
|
|
154
|
+
for(const [kind,field] of [['acceptance','productAcceptance'],['deployment','deployment']]){
|
|
155
|
+
const selected=new Map();for(const record of records)if(record.kind===kind&&record.candidate.feature===feature)selected.set(environmentKey(record.statement.environment),record);
|
|
156
|
+
if(!selected.size)continue;
|
|
157
|
+
const environments=[...selected].map(([environment,r])=>{
|
|
158
|
+
let reason=null;
|
|
159
|
+
if(!current||(artifactSha256!==null&&artifactSha256!==r.candidate.artifact.sha256)||digest(r.candidate.identity)!==digest(identity)||r.candidate.packageDigest!==packageDigest||r.candidate.specificationDigest!==specificationDigest)reason='delivery_candidate_changed';
|
|
160
|
+
else if(!ownerMatches())reason='delivery_candidate_changed';
|
|
161
|
+
else try{for(const file of [r.candidate.artifact,r.evidence.report,r.evidence.verificationReport].filter(Boolean))
|
|
162
|
+
checkFile(file);}
|
|
163
|
+
catch(error){reason=error.code==='delivery_evidence_budget_exceeded'?error.code:'delivery_evidence_changed';}
|
|
164
|
+
return {environment,status:reason==='delivery_evidence_budget_exceeded'?'unknown':reason?'stale':'recorded',reason,statement:r.statement,artifactSha256:r.candidate.artifact.sha256,
|
|
165
|
+
at:r.at,provenance:r.provenance,evidence:[`${directory}/${String(r.sequence).padStart(6,'0')}/record.json#sha256=${r.recordDigest}`]};
|
|
166
|
+
});
|
|
167
|
+
result[field]={status:environments.some(e=>e.status==='unknown')?'unknown':environments.every(e=>e.status==='recorded')?'recorded':'stale',reason:null,environments,
|
|
168
|
+
evidence:environments.flatMap(e=>e.evidence)};
|
|
169
|
+
}
|
|
170
|
+
}catch{result.productAcceptance=unknown('delivery_records_unavailable');result.deployment=unknown('delivery_records_unavailable');}
|
|
171
|
+
return freeze(result);
|
|
172
|
+
}
|
|
173
|
+
export {deliveryLines} from './operator-guidance.mjs';
|
|
@@ -29,6 +29,10 @@ The top-level reason explains blocked outcomes; otherwise it must be null. Use n
|
|
|
29
29
|
Use outcome blocked when implementation is not possible. Do not claim implementation if no implementation was made.
|
|
30
30
|
Always also return requirements: one item {requirement, satisfied, evidence, run, result} for each requirement written in the
|
|
31
31
|
task's description and verification (specification), evidence naming where it is met (file, test name, expected command result).
|
|
32
|
+
When specification.acceptanceContract exists, its obligations are the mandatory set: return exactly one item per obligation,
|
|
33
|
+
copying id, requirement, evidenceType, environment and run verbatim, and adding satisfied, evidence and optional result.
|
|
34
|
+
Do not omit or combine obligations, reinterpret the required environment, or declare unresolved mappings satisfied.
|
|
35
|
+
Without an acceptanceContract, id, evidenceType and environment may be omitted or null for legacy reports.
|
|
32
36
|
Use null when the task states none. The host runs the task's checks itself before development (baseline) and with only the
|
|
33
37
|
task's test files delivered (red), and checks tagged items against those runs: set run "red" on an item stating that a new
|
|
34
38
|
test fails before the implementation; set run "baseline" on an item stating the result before development, with result
|
|
@@ -3,7 +3,7 @@ import fs from 'node:fs';
|
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import {spawn} from 'node:child_process';
|
|
5
5
|
import readline from 'node:readline';
|
|
6
|
-
import {guidanceText} from './operator-guidance.mjs';
|
|
6
|
+
import {guidanceText,completionLines} from './operator-guidance.mjs';
|
|
7
7
|
import {applyRateLimitResume,nextRateLimitRetry,rateLimitedReview,rateLimitRetriesDone,RATE_LIMIT_RETRY_ENV,RATE_LIMIT_EXPECTED_ENV,
|
|
8
8
|
RATE_LIMIT_PLAN_DIGEST_ENV,planFileFromArgv,planDigest,digestBytes,expectedReviewStop,readExpectedReviewStop} from './drive-rate-limit.mjs';
|
|
9
9
|
|
|
@@ -80,8 +80,15 @@ export function deliberatelyUnanswered(message){
|
|
|
80
80
|
}
|
|
81
81
|
// Transport-only budgets: no field is added to a run or its configuration hash.
|
|
82
82
|
// The long fallback covers hosts that cannot advertise individual phase budgets.
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
// heartbeatMs: the host beats from a timer, which cannot fire while it runs a
|
|
84
|
+
// synchronous tree capture. On a code root with a large ignored build tree one
|
|
85
|
+
// capture took 12-22 s and a develop step runs several, so 30 s killed a healthy
|
|
86
|
+
// host after it had applied the edits (Wue specs8 T-001). operationMs still
|
|
87
|
+
// bounds a host that never finishes. startupMs covers a create's baseline capture
|
|
88
|
+
// before host_ready, whose Git ignore query may take up to GIT_IGNORE_TIMEOUT_MS
|
|
89
|
+
// (120 s, review-package.mjs) plus the capture itself.
|
|
90
|
+
export const DRIVE_LIVENESS_DEFAULTS=Object.freeze({startupMs:180000,operationMs:21600000,
|
|
91
|
+
heartbeatMs:120000,graceMs:30000,closeMs:5000,killMs:1000,pollMs:250});
|
|
85
92
|
// rateLimitRetry (cm-ai drivers only, drive-rate-limit.mjs; 'batch' for the batch driver): a review the provider
|
|
86
93
|
// rate limited is redispatched by re-running this same driver command after a
|
|
87
94
|
// wait, without printing the interim result or notifying; the re-run's result is
|
|
@@ -137,7 +144,11 @@ export function driveHost({host,args,cwd,operation,request={},answers,paths,answ
|
|
|
137
144
|
if(typeof sessionBoundary==='function'&&!row.error){let block=null;try{block=sessionBoundary(row.result,operation);}catch{stderr('会话边界结论生成失败;请按技能输出模板手写三行结论(业务结果不受影响)');}
|
|
138
145
|
// stderr, not stdout: callers parse stdout as one JSON result.
|
|
139
146
|
if(typeof block==='string'&&block)process.stderr.write(block+'\n');}
|
|
140
|
-
const guidance=guidanceText(row.result);if(guidance)stderr(guidance);
|
|
147
|
+
try{const guidance=guidanceText(row.result);if(guidance)stderr(guidance);}
|
|
148
|
+
catch{stderr('恢复指引显示失败;业务结果不受影响');}
|
|
149
|
+
try{if(row.result?.state!=='run_done'||typeof sessionBoundary!=='function')
|
|
150
|
+
for(const line of completionLines(row.result?.completion))stderr(line);}
|
|
151
|
+
catch{stderr('完成摘要显示失败;业务结果不受影响');}
|
|
141
152
|
if(row.result?.stage)stderr(`stage = ${row.result.stage}`);
|
|
142
153
|
if(row.error)stderr(`宿主拒绝:${row.error.code}(真实原因和位置在上面 [host] 那行 diagnostic 里)`);
|
|
143
154
|
};
|
|
@@ -7,7 +7,7 @@ import {readExternalModels} from './external-models.mjs';
|
|
|
7
7
|
import {beforeFirstQaRound,qaRevisionFollows,readQaConfigRevision} from './qa-config-revision.mjs';
|
|
8
8
|
import {readCloseoutPolicy} from './knowledge-closeout.mjs';
|
|
9
9
|
// Host-only S3b2b journal grammar. Data validation grants no provider authority.
|
|
10
|
-
import {digest,need,shape,id,text,hex,json,validIdentity,validTaskLearningInput,validCallTimeout,validBlockedReason,validFailureCode,requestFor,JOURNAL_REASON_LIMIT,boundedReason} from './effect-contract.mjs';
|
|
10
|
+
import {digest,need,shape,id,text,hex,json,validIdentity,validTaskLearningInput,validCallTimeout,validBlockedReason,validFailureCode,requestFor,JOURNAL_REASON_LIMIT,boundedReason,JOURNAL_PAYLOAD_LIMIT} from './effect-contract.mjs';
|
|
11
11
|
import {readReviewBaseline,readReviewPackage,reviewSpecsPath,reviewMaterialLimitReason} from './review-package.mjs';
|
|
12
12
|
import {reviewResult,reviewReceipt} from './review-runner.mjs';
|
|
13
13
|
import {checkCompletion} from './gate-bridge.mjs';
|
|
@@ -725,12 +725,16 @@ export function bootstrapReviewRecoverable(s,pending=null,configuration=null) {
|
|
|
725
725
|
}
|
|
726
726
|
// limit only widens the builder's own copy check so a caller can measure an
|
|
727
727
|
// oversized record exactly; the store still refuses it (JOURNAL_PAYLOAD_LIMIT).
|
|
728
|
-
|
|
728
|
+
// The default is the store's own record limit: json()'s 1 MiB default made the
|
|
729
|
+
// runner refuse a record the store accepts, inside the store operation, which
|
|
730
|
+
// poisons the run as store_failure (Wue specs8 T-001 develop checkpoint).
|
|
731
|
+
export const runnerPayload=(type,fields,version=1,limit=JOURNAL_PAYLOAD_LIMIT)=>{need([1,2].includes(version),'runner_version');
|
|
729
732
|
return json(version===1?{version,protocol:'cm-task-runner',type,...fields}:{...fields,version,protocol:'cm-task-runner',type},limit);};
|
|
730
|
-
export const runnerPayloadV3=(type,fields,limit=
|
|
733
|
+
export const runnerPayloadV3=(type,fields,limit=JOURNAL_PAYLOAD_LIMIT)=>json({...fields,version:3,protocol:'cm-task-runner',type},limit);
|
|
731
734
|
export function boundRunnerRecord({id,kind,payload},seq) {
|
|
732
735
|
// Exact S3a envelope width. Digest contents do not affect encoded byte count.
|
|
733
|
-
|
|
736
|
+
// The envelope adds at most the 1 KiB the store allows above the payload.
|
|
737
|
+
json({version:1,seq,id,kind,payload,previousDigest:seq>1?'0'.repeat(64):null,digest:'0'.repeat(64)},JOURNAL_PAYLOAD_LIMIT+1024);
|
|
734
738
|
}
|
|
735
739
|
export function attemptBaseline(original,attempt) {
|
|
736
740
|
const {baselineDigest,...data}=original,next={...data,identity:{...original.identity,attempt}};
|
|
@@ -1150,7 +1154,7 @@ function checkpoint(before,raw,effect,config,original,session,controls,version=1
|
|
|
1150
1154
|
same(s.receipts,before.receipts);same(s.receipt,before.receipt);same(s.priorReview,before.priorReview);
|
|
1151
1155
|
if(s.state==='fixture_completed') {
|
|
1152
1156
|
checkCompletion({receipt:s.receipt,registered:before.receipt,execution:s.calls.find(c=>c.invocationId===s.receipt?.id),
|
|
1153
|
-
reviewPackage:s.reviewPackage,identity});expectedState='fixture_completed';
|
|
1157
|
+
reviewPackage:s.reviewPackage,identity,historical:true});expectedState='fixture_completed';
|
|
1154
1158
|
} else if(s.state==='blocked'){
|
|
1155
1159
|
expectedState='blocked';
|
|
1156
1160
|
if(['completion_checks_changed','completion_package_changed'].includes(s.code)){
|
|
@@ -1854,7 +1858,7 @@ export function readRunnerHistory(raw,config,version=1) {
|
|
|
1854
1858
|
const c=readCommitIntent(p.commit,{owner:completion.owner,identity:pending.identity,fingerprints:completion.fingerprints});
|
|
1855
1859
|
const base=attemptBaseline(original,pending.identity.attempt),s=beforeIntent;
|
|
1856
1860
|
checkCompletion({receipt:s.receipt,registered:s.receipts.find(x=>x.id===s.receipt?.id),
|
|
1857
|
-
execution:s.calls.find(x=>x.invocationId===s.receipt?.id),reviewPackage:s.reviewPackage,identity:pending.identity});
|
|
1861
|
+
execution:s.calls.find(x=>x.invocationId===s.receipt?.id),reviewPackage:s.reviewPackage,identity:pending.identity,historical:true});
|
|
1858
1862
|
same(c.proof,{root:config.root,baselineDigest:base.baselineDigest,packageDigest:s.reviewPackage.packageDigest,
|
|
1859
1863
|
receiptDigest:s.receipt.receiptDigest,checksDigest:s.reviewPackage.checksDigest});
|
|
1860
1864
|
need(c.plan.evidence.every(e=>path.dirname(e.path)===completion.reviewsDir)
|
|
@@ -6,7 +6,14 @@ export const need=(ok,code='invalid_input')=>{
|
|
|
6
6
|
};
|
|
7
7
|
// One journal record payload (execution-store). Anything a record must carry,
|
|
8
8
|
// such as a review package inside a checkpoint, has to fit this, not only its own limits.
|
|
9
|
-
|
|
9
|
+
// 4 MiB:审查材料允许 2 MiB,审查包又按 base64 存改动前后两份;1 MiB 时一个改 30 来个文件的任务
|
|
10
|
+
// (Wue specs8 T-001,审查包约 1.17 MB)连外置归档也装不下(2026-11-15)。
|
|
11
|
+
// CM_JOURNAL_PAYLOAD_LIMIT_TEST 只许调小(64 KiB 起、低于默认值):边界测试用它压回 1 MiB 复现原场景;
|
|
12
|
+
// 调大或非法值一律忽略,这个开关不能放宽任何检查。
|
|
13
|
+
const JOURNAL_PAYLOAD_DEFAULT=4*1024*1024;
|
|
14
|
+
const loweredJournalLimit=Number(globalThis.process?.env?.CM_JOURNAL_PAYLOAD_LIMIT_TEST);
|
|
15
|
+
export const JOURNAL_PAYLOAD_LIMIT=Number.isSafeInteger(loweredJournalLimit)&&loweredJournalLimit>=64*1024
|
|
16
|
+
&&loweredJournalLimit<JOURNAL_PAYLOAD_DEFAULT?loweredJournalLimit:JOURNAL_PAYLOAD_DEFAULT;
|
|
10
17
|
// A develop checkpoint must leave room for the later checkpoints of the same
|
|
11
18
|
// attempt, which carry the same package again. Their growth is bounded:
|
|
12
19
|
// - the reviewer result (verdict, digest, findings, summary; examinedPaths are
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
// reconstructed expected fingerprints and acquire its normal ownership lock.
|
|
3
3
|
import fs from 'node:fs';
|
|
4
4
|
import path from 'node:path';
|
|
5
|
-
import {digest,need,shape,id,hex,json} from './effect-contract.mjs';
|
|
6
|
-
import {fixJournalWorkflow,packFixJournalPayload,unpackFixJournalState} from './review-presentation.mjs';
|
|
5
|
+
import {digest,need,shape,id,hex,json,JOURNAL_PAYLOAD_LIMIT} from './effect-contract.mjs';
|
|
6
|
+
import {fixJournalWorkflow,journalPhysicalLimit,packFixJournalPayload,unpackFixJournalState} from './review-presentation.mjs';
|
|
7
7
|
export function readExecutionSnapshot({specsRoot,identity}){
|
|
8
8
|
shape(identity,['repositoryId','runId']);Object.values(identity).forEach(id);
|
|
9
9
|
need(path.isAbsolute(specsRoot)&&fs.realpathSync(specsRoot)===specsRoot,'unsupported_path');
|
|
@@ -32,7 +32,8 @@ export function readExecutionSnapshot({specsRoot,identity}){
|
|
|
32
32
|
let previous=null;const ids=new Set();
|
|
33
33
|
for(const [index,r] of v.records.entries()){
|
|
34
34
|
shape(r,['version','seq','id','kind','payload','previousDigest','digest']);id(r.id);hex(r.digest);
|
|
35
|
-
|
|
35
|
+
// Same per-record bound as the store that wrote it (execution-store.mjs).
|
|
36
|
+
need(Buffer.byteLength(JSON.stringify(packFixJournalPayload(r.payload,{workflow:fixJournalWorkflow(v)})))<=journalPhysicalLimit(v),'limit_exceeded');
|
|
36
37
|
const {digest:checksum,...body}=r;
|
|
37
38
|
need(r.version===1&&r.seq===index+1&&r.previousDigest===previous&&!ids.has(r.id)
|
|
38
39
|
&&['intent','result','cancel','commit-intent','commit-result','finalized'].includes(r.kind)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Size and count limits of the local durable record store, without the store
|
|
2
2
|
// itself (no node:sqlite import), so owners can check an append before making it.
|
|
3
|
-
import { digest,json } from './effect-contract.mjs';
|
|
4
|
-
import {fixJournalWorkflow,packFixJournalPayload,packFixJournalState} from './review-presentation.mjs';
|
|
3
|
+
import { digest,json,JOURNAL_PAYLOAD_LIMIT } from './effect-contract.mjs';
|
|
4
|
+
import {fixJournalWorkflow,journalPhysicalLimit,packFixJournalPayload,packFixJournalState} from './review-presentation.mjs';
|
|
5
5
|
|
|
6
6
|
export const MiB=1024*1024,STATE_LIMIT=16*MiB,PHYSICAL_LIMIT=32*MiB,RECORD_LIMIT=1024;
|
|
7
7
|
|
|
@@ -13,7 +13,7 @@ export function appendFits(current,input){
|
|
|
13
13
|
try{
|
|
14
14
|
const bytes=value=>Buffer.byteLength(JSON.stringify(value));
|
|
15
15
|
const entry=json(input,10*MiB),physicalPayload=packFixJournalPayload(entry.payload,{workflow:fixJournalWorkflow(current)});
|
|
16
|
-
if(bytes({...entry,payload:physicalPayload})>
|
|
16
|
+
if(bytes({...entry,payload:physicalPayload})>journalPhysicalLimit(current)+1024||current.records.length>=RECORD_LIMIT)return false;
|
|
17
17
|
const record={version:1,seq:current.records.length+1,id:entry.id,kind:entry.kind,payload:entry.payload,
|
|
18
18
|
previousDigest:current.records.at(-1)?.digest??null};
|
|
19
19
|
const {revision,...data}=current,next={...data,records:[...current.records,{...record,digest:digest(record)}]};
|
|
@@ -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)})))<=
|
|
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}))<=
|
|
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
|
-
|
|
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
|
|
81
|
-
|
|
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=
|
|
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
|
|
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
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// Pure S2b comparison only. This is not the Python gate and cannot write tasks.
|
|
2
2
|
import { digest,need,shape,id,json,validIdentity } from './effect-contract.mjs';
|
|
3
3
|
import { reviewResult } from './review-runner.mjs';
|
|
4
|
-
|
|
4
|
+
import {verifyAcceptanceEvidence,acceptanceCoverage} from './acceptance-contract.mjs';
|
|
5
|
+
export function checkCompletion({receipt,registered,execution,reviewPackage,identity,historical=false}) {
|
|
5
6
|
const r=json(receipt);validIdentity(identity);
|
|
6
7
|
shape(r,['version','kind','id','identity','packageDigest','baseIdentity','artifactDigest',
|
|
7
8
|
'requirementsDigest','checksDigest','execution','route','result','receiptDigest']);
|
|
@@ -21,5 +22,16 @@ export function checkCompletion({receipt,registered,execution,reviewPackage,iden
|
|
|
21
22
|
const result=reviewResult(r.result,reviewPackage);
|
|
22
23
|
need(r.execution.resultDigest===digest(result) && result.verdict==='approved','review_not_approved');
|
|
23
24
|
need(reviewPackage.checks.length>0 && reviewPackage.checks.every(c=>c.outcome==='passed' && c.exitCode===0),'checks_not_passed');
|
|
25
|
+
if(reviewPackage.specification?.acceptanceContract){
|
|
26
|
+
const contract=reviewPackage.specification.acceptanceContract;
|
|
27
|
+
// Replay verifies the registered host evidence below. Reinterpreting its
|
|
28
|
+
// already accepted selection with today's Node path/parser would change
|
|
29
|
+
// historical completion after a runtime upgrade. Live completion stays strict.
|
|
30
|
+
if(!historical)need(acceptanceCoverage(contract,reviewPackage.checks).satisfied,'verification_precheck_failed');
|
|
31
|
+
let handoff;
|
|
32
|
+
try{handoff=JSON.parse(Buffer.from(reviewPackage.handoff.contentBase64,'base64').toString('utf8'));}
|
|
33
|
+
catch{need(false,'verification_precheck_failed');}
|
|
34
|
+
verifyAcceptanceEvidence({contract,identity,evidence:handoff.evidence});
|
|
35
|
+
}
|
|
24
36
|
return json({outcome:'eligible',receiptDigest});
|
|
25
37
|
}
|
|
@@ -24,6 +24,7 @@ import {checklistGaps} from './checklist-coverage.mjs';
|
|
|
24
24
|
import {readRequirementItems,splitRequirementReport} from './requirement-evidence.mjs';
|
|
25
25
|
import {replayDelivery,notReplayed} from './host-replay.mjs';
|
|
26
26
|
import {autoVerificationVerdict} from './verification-auto.mjs';
|
|
27
|
+
import {acceptanceProblems,acceptanceCoverage,describeAcceptanceProblems} from './acceptance-contract.mjs';
|
|
27
28
|
import {declaredTaskScope} from '../task-scope.mjs';
|
|
28
29
|
import {specsPermissionArgs} from './codex-config.mjs';
|
|
29
30
|
import {createProjectExecution} from './host-project-execution.mjs';
|
|
@@ -34,7 +35,7 @@ import {verifySpecificationMaterial} from './specification-material.mjs';
|
|
|
34
35
|
import {isFinalCmAiTask} from './cm-ai-admission.mjs';
|
|
35
36
|
import {createHostBootstrap} from './host-bootstrap.mjs';
|
|
36
37
|
import {withHostProgress} from './host-progress.mjs';
|
|
37
|
-
import {digest,id,hex,json,need,shape,freeze,arrayItems} from './effect-contract.mjs';
|
|
38
|
+
import {digest,id,hex,json,need,shape,freeze,arrayItems,boundedReason} from './effect-contract.mjs';
|
|
38
39
|
export const protectedTextInstructions='\nProtected current-host mode: do not write files or run commands. Return {status,value,edits} on success; '
|
|
39
40
|
+'value retains the original implementation/Learning contract. edits is [{path,beforeSha256,content[,mode]}], complete UTF-8 text or null for deletion; '
|
|
40
41
|
+'optional mode "0755" or "0644" sets the permission bits of a written file. '
|
|
@@ -52,11 +53,9 @@ export const externalConversationDefinition=execution=>externalConversations.get
|
|
|
52
53
|
// passing it is not an approval, produces no receipt and consumes no review
|
|
53
54
|
// round. A satisfied gate still leaves the full independent review ahead.
|
|
54
55
|
//
|
|
55
|
-
//
|
|
56
|
-
//
|
|
57
|
-
//
|
|
58
|
-
// nonempty evidence location, and that the gate passes only when every returned
|
|
59
|
-
// requirement is satisfied. Mechanical shape is not semantic coverage.
|
|
56
|
+
// This parser validates reports, not coverage. The caller and runner separately
|
|
57
|
+
// compare new reports with their approved acceptanceContract. Legacy reports
|
|
58
|
+
// keep their original shape. Nonempty evidence is still not semantic proof.
|
|
60
59
|
export function readVerificationPrecheck(raw){
|
|
61
60
|
const value=json(raw,256*1024);shape(value,['items']);
|
|
62
61
|
const items=readRequirementItems(arrayItems(value.items));
|
|
@@ -226,23 +225,35 @@ export function createConversationExecution(definition,hostContextId,bridge,revi
|
|
|
226
225
|
snapshot:control.baselineSnapshot??null,scope:request.scope??definition.scope,
|
|
227
226
|
tests:declaredTests(request.identity.taskId),checkCommands:protection.checkCommands,timeoutMs:protection.timeoutMs,
|
|
228
227
|
identity:request.identity,greenChecks:request.checks,signal:control.signal}):null;
|
|
229
|
-
// The
|
|
230
|
-
//
|
|
231
|
-
//
|
|
232
|
-
//
|
|
228
|
+
// The optional legacy gate retains its original policy. A new frozen contract
|
|
229
|
+
// always runs, including when the optional precheck/auto setting is disabled.
|
|
230
|
+
// A failed gate carries a bounded diagnostic through the existing checkpoint
|
|
231
|
+
// reason. It survives restart without becoming approval or recovery authority.
|
|
233
232
|
// A v2 policy may enable the gate durably (it is part of the run fingerprint);
|
|
234
233
|
// the legacy launch flag keeps working for runs created without it.
|
|
235
234
|
// auto: the host answers from the developer's report and its own runs
|
|
236
235
|
// (verification-auto.mjs); precheck: the session answers, seeing the host runs.
|
|
237
236
|
const gateMode=controlPolicy?.verification==='auto'?'auto'
|
|
238
237
|
:options.verificationPrecheck===true||controlPolicy?.verification==='precheck'?'precheck':null;
|
|
239
|
-
const verificationGate=
|
|
238
|
+
const verificationGate=async(request,control)=>{
|
|
239
|
+
const contract=request.acceptanceContract??null;
|
|
240
|
+
if(!gateMode&&!contract)return {satisfied:true}; // original, unprotected run
|
|
240
241
|
const facts=await hostRuns(request,control);
|
|
241
|
-
const
|
|
242
|
+
const report=requirementReports.get(reportKey(request.identity))??null;
|
|
243
|
+
const verdict=gateMode!=='precheck'?autoVerificationVerdict({report,contract,
|
|
242
244
|
facts:facts??notReplayed(definition.codeProjects?'multi_root':'no_host_checks',request.checks)})
|
|
243
245
|
:readVerificationPrecheck(await bridge.call('verification_precheck',
|
|
244
246
|
{...request,codeProject:definition.codeProject,feature:definition.feature,
|
|
245
247
|
scope:request.scope??definition.scope,...(facts?{hostRuns:facts}:{})},control.signal));
|
|
248
|
+
const coverage=contract?acceptanceCoverage(contract,request.checks):null;
|
|
249
|
+
const problems=contract?acceptanceProblems(contract,gateMode==='precheck'?verdict.items:report,facts):[];
|
|
250
|
+
if(coverage&&!coverage.satisfied)problems.push('mandatory checks missing or unverifiable: '+JSON.stringify(coverage));
|
|
251
|
+
if(problems.length){
|
|
252
|
+
try{process.stderr.write(JSON.stringify({diagnostic:'acceptance_contract_failed',task:request.identity.taskId,problems})+'\n');}
|
|
253
|
+
catch{/* presentation never changes the blocking verdict */}
|
|
254
|
+
return {satisfied:false,reason:boundedReason('verification_precheck_failed: ',
|
|
255
|
+
describeAcceptanceProblems(contract,[...new Set([...problems,...(verdict.unsatisfied??[])])]))};
|
|
256
|
+
}
|
|
246
257
|
if(!verdict.satisfied)try{
|
|
247
258
|
process.stderr.write(JSON.stringify({diagnostic:'verification_precheck_failed',
|
|
248
259
|
task:request.identity.taskId,attempt:request.identity.attempt,mode:gateMode,
|
|
@@ -264,8 +275,9 @@ export function createConversationExecution(definition,hostContextId,bridge,revi
|
|
|
264
275
|
// The answered items travel to the runner, which binds them into the host
|
|
265
276
|
// handoff the reviewer reads; a failed gate halts before any handoff exists.
|
|
266
277
|
// The host record travels as its own handoff entry (host-replay.mjs), never inside the items.
|
|
267
|
-
return verdict.satisfied?{satisfied:true,items:verdict.items,...(facts?{hostRecord:facts}:{})}:{
|
|
268
|
-
|
|
278
|
+
return verdict.satisfied?{satisfied:true,items:verdict.items,...(facts?{hostRecord:facts}:{}),...(coverage?{coverage}:{})}
|
|
279
|
+
:{satisfied:false,reason:boundedReason('verification_precheck_failed: ',verdict.unsatisfied??['门禁未记录具体缺项'])};
|
|
280
|
+
};
|
|
269
281
|
const outerTimeoutMs=provider?protection.timeoutMs:1800000;
|
|
270
282
|
const progress=(request,control,stage,run,selectedRuntime=runtime)=>withHostProgress({definition,
|
|
271
283
|
identity:request.identity,runtime:selectedRuntime,stage,signal:control.signal},run);
|
|
@@ -5,6 +5,7 @@ import {randomUUID} from 'node:crypto';
|
|
|
5
5
|
import {fileURLToPath} from 'node:url';
|
|
6
6
|
import {need} from './effect-contract.mjs';
|
|
7
7
|
import {readStatusProjection,writeStatusProjection} from './status-projection.mjs';
|
|
8
|
+
import {completionLines} from './completion-summary.mjs';
|
|
8
9
|
|
|
9
10
|
const writer=fileURLToPath(new URL('../../../scripts/cm-log-event.py',import.meta.url));
|
|
10
11
|
const phases={developing:['N3','正在开发'],checking:['N3','正在执行检查'],
|
|
@@ -73,7 +74,7 @@ export function projectHostResult({specsDir,feature,result,readCurrent}){
|
|
|
73
74
|
if(['N6','N7','N8'].includes(previous.node))return;
|
|
74
75
|
const node=['blocked','unknown','cancelled'].includes(result.state)?previous.node:selected[0];
|
|
75
76
|
writeStatusProjection({specsDir,feature,identity:result.identity,node,state:result.state,
|
|
76
|
-
detail:(result.guidance?.summary??selected[1])+(result.code?`(${result.code})`:''),code:result.code,
|
|
77
|
+
detail:(result.guidance?.summary??(result.state==='fixture_completed'?completionLines(result.completion)[0]:null)??selected[1])+(result.code?`(${result.code})`:''),code:result.code,
|
|
77
78
|
...(result.state==='changes_requested'&&result.identity.attempt>1?{previousAttempt:result.identity.attempt-1}:{}),
|
|
78
79
|
expectedToken:previous.progress_id??null});
|
|
79
80
|
}catch{diagnostic();}
|