@aibyzero/cm-workflow 0.21.1 → 0.21.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.codex-plugin/plugin.json +1 -1
- package/CHANGELOG.md +19 -0
- package/README.md +13 -1
- package/VERSION +1 -1
- package/docs/installation.md +1 -1
- package/docs/js-workflow-control.md +6 -1
- package/package.json +1 -1
- package/runtime/js/cm-ai/call-timeout.mjs +21 -0
- package/runtime/js/cm-ai/checkpoint-package-material.mjs +3 -2
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +5 -1
- package/runtime/js/cm-ai/codex-config.mjs +6 -1
- package/runtime/js/cm-ai/durable-runner-state.mjs +19 -4
- package/runtime/js/cm-ai/fix-code-association.mjs +5 -5
- package/runtime/js/cm-ai/host-conversation-execution.mjs +22 -15
- package/runtime/js/cm-ai/host-documentation.mjs +4 -3
- package/runtime/js/cm-ai/host-handoff.mjs +3 -2
- package/runtime/js/cm-ai/host-project-execution.mjs +11 -9
- package/runtime/js/cm-ai/host-qa-executor.mjs +3 -2
- package/runtime/js/cm-ai/host-replay.mjs +28 -8
- package/runtime/js/cm-ai/review-package.mjs +101 -33
- package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +1 -1
- package/runtime/js/cm-ai/reviewed-integration.mjs +1 -1
- package/runtime/js/cm-ai/spec-amendment.mjs +20 -0
- package/runtime/js/cm-ai/symlink-material.mjs +153 -0
- package/runtime/js/cm-ai/task-commit.mjs +6 -3
- package/runtime/js/cm-ai/task-runner.mjs +14 -6
- package/runtime/js/cm-ai/worker-claude-developer.mjs +19 -7
- package/runtime/js/cm-ai/worker-codex-developer.mjs +3 -1
- package/runtime/js/cm-fix/protected-edits.mjs +57 -36
- package/runtime/js/cm-prd/change.mjs +4 -1
- package/runtime/js/cm-prd/review-findings.mjs +3 -2
- package/runtime/js/cm-prd/review-publication.mjs +3 -2
- package/runtime/js/cm-prd/split-design.mjs +4 -4
- package/scripts/ci-test-weights.json +1 -0
- package/scripts/cm-ai-admission.test.mjs +5 -5
- package/scripts/cm-ai-batch-drive.mjs +9 -5
- package/scripts/cm-ai-call-timeout.test.mjs +85 -0
- package/scripts/cm-ai-control-launch.test.mjs +18 -0
- package/scripts/cm-ai-drive.mjs +142 -43
- package/scripts/cm-ai-host.mjs +15 -3
- package/scripts/cm-ai-host.test.mjs +3 -1
- package/scripts/cm-ai-launch-diagnostics.test.mjs +23 -0
- package/scripts/cm-ai-review-failure.test.mjs +3 -0
- package/scripts/cm-ai-run.mjs +2 -1
- package/scripts/cm-ai-scope-revision.test.mjs +35 -3
- package/scripts/cm-ai-supersede.test.mjs +51 -3
- package/scripts/cm-ai-symlink.test.mjs +481 -0
- package/scripts/cm-codex-developer-worker.test.mjs +13 -1
- package/scripts/cm-notify-command.test.mjs +3 -0
- package/scripts/cm-notify.test.mjs +3 -0
- package/scripts/cm-patrol.test.mjs +3 -0
- package/scripts/cm-prd-design-phase.test.mjs +31 -0
- package/scripts/cm-prd-review-gate.mjs +28 -3
- package/scripts/cm-prd-summary.test.mjs +5 -5
- package/scripts/cm-skill-hints.mjs +40 -16
- package/scripts/cm-skill-hints.test.mjs +91 -0
- package/scripts/cm-spec-amend.test.mjs +107 -1
- package/scripts/cm-specs-status.test.mjs +5 -5
- package/scripts/cm-start-check.mjs +53 -15
- package/scripts/cm-start-check.test.mjs +41 -2
- package/scripts/cm-task-gate.mjs +42 -13
- package/scripts/cm-task-gate.test.mjs +33 -0
- package/scripts/cm-tool-preview-context.test.mjs +20 -1
- package/scripts/cm-upgrade-compat.test.mjs +7 -0
- package/skills/cm-ai/references/js-host.md +1 -0
- package/skills/cm-prd/SKILL.md +14 -27
- package/skills/cm-prd/references/change-mode.md +2 -0
- package/skills/cm-prd/references/cm-optout.md +11 -0
- package/skills/cm-prd/references/context-scope.md +2 -1
- package/skills/cm-prd/references/js-host.md +2 -2
- package/skills/cm-prd/references/requirement-grilling.md +116 -0
- package/skills/cm-product-manager/SKILL.md +13 -1
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
// Link material binds the directory entry itself. It never opens the referent.
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import {createHash} from 'node:crypto';
|
|
5
|
+
import {need,shape,hex} from './effect-contract.mjs';
|
|
6
|
+
|
|
7
|
+
export const SYMLINK_BASELINE_VERSION=3;
|
|
8
|
+
export const reviewPackageVersion=baseline=>baseline.version===SYMLINK_BASELINE_VERSION?2:1;
|
|
9
|
+
const utf8=new TextDecoder('utf8',{fatal:true,ignoreBOM:true});
|
|
10
|
+
const inside=(root,file)=>file===root||file.startsWith(root+path.sep);
|
|
11
|
+
const validTargetText=target=>typeof target==='string'&&target.length>0&&!target.includes('\0')
|
|
12
|
+
&&utf8.decode(Buffer.from(target))===target;
|
|
13
|
+
|
|
14
|
+
export function symlinkRecord(file,target){
|
|
15
|
+
need(validTargetText(target),'unsupported_file');
|
|
16
|
+
return {path:file,type:'symlink',target,size:Buffer.byteLength(target),
|
|
17
|
+
sha256:createHash('sha256').update('symlink\0').update(target).digest('hex')};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function readSymlinkRecord(root,file){
|
|
21
|
+
const absolute=path.join(root,file);
|
|
22
|
+
const stat=()=>fs.lstatSync(absolute,{bigint:true});
|
|
23
|
+
const key=s=>[s.dev,s.ino,s.mode,s.size,s.ctimeNs,s.mtimeNs].join(':');
|
|
24
|
+
const before=stat();
|
|
25
|
+
need(before.isSymbolicLink(),'snapshot_changed');
|
|
26
|
+
const bytes=fs.readlinkSync(absolute,{encoding:'buffer'});
|
|
27
|
+
need(key(before)===key(stat())&&BigInt(bytes.length)===before.size,'snapshot_changed');
|
|
28
|
+
let target;
|
|
29
|
+
try{target=utf8.decode(bytes);}catch{need(false,'unsupported_file');}
|
|
30
|
+
return symlinkRecord(file,target);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function validateSymlinkRecord(file){
|
|
34
|
+
shape(file,['path','type','target','size','sha256']);
|
|
35
|
+
const expected=symlinkRecord(file.path,file.target);
|
|
36
|
+
need(file.type===expected.type&&file.size===expected.size&&file.sha256===expected.sha256);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function lstatOrMissing(file){
|
|
40
|
+
try{return fs.lstatSync(file);}catch(error){if(error.code==='ENOENT')return null;throw error;}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Root-to-leaf checks also see dangling links and stop before probing their children.
|
|
44
|
+
export function assertRealParents(root,file,stat=relative=>lstatOrMissing(path.join(root,relative))){
|
|
45
|
+
const parts=file.split('/');
|
|
46
|
+
need(parts.every(part=>part&&part!=='.'&&part!=='..'&&!/[\\\0]/.test(part)),'unsupported_path');
|
|
47
|
+
let cursor='';
|
|
48
|
+
for(const part of parts.slice(0,-1)){
|
|
49
|
+
cursor=cursor?cursor+'/'+part:part;
|
|
50
|
+
const info=stat(cursor);
|
|
51
|
+
if(info===null)return;
|
|
52
|
+
need(info.isDirectory(),'unsupported_path');
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const projectedFile=Object.freeze({isFile:()=>true,isDirectory:()=>false});
|
|
57
|
+
const projectedDirectory=Object.freeze({isFile:()=>false,isDirectory:()=>true});
|
|
58
|
+
const projectedLink=Object.freeze({isFile:()=>false,isDirectory:()=>false});
|
|
59
|
+
|
|
60
|
+
// Overlay known file states on the disk. A write also creates missing parents.
|
|
61
|
+
export function projectedPathStat(root,paths){
|
|
62
|
+
const parents=new Set();
|
|
63
|
+
for(const [file,type] of paths){
|
|
64
|
+
if(type===null)continue;
|
|
65
|
+
const parts=file.split('/');
|
|
66
|
+
while(parts.length>1){parts.pop();parents.add(parts.join('/'));}
|
|
67
|
+
}
|
|
68
|
+
return file=>{
|
|
69
|
+
if(paths.has(file)){
|
|
70
|
+
const type=paths.get(file);
|
|
71
|
+
return type===null?null:type==='symlink'?projectedLink:projectedFile;
|
|
72
|
+
}
|
|
73
|
+
return lstatOrMissing(path.join(root,file))??(parents.has(file)?projectedDirectory:null);
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Two proposed file entries cannot also make one of them the other's parent.
|
|
78
|
+
export function assertDisjointEditPaths(files){
|
|
79
|
+
const names=new Set(files.map(file=>file.toLowerCase()));
|
|
80
|
+
for(const file of names){
|
|
81
|
+
const parts=file.split('/');
|
|
82
|
+
while(parts.length>1){
|
|
83
|
+
parts.pop();
|
|
84
|
+
need(!names.has(parts.join('/')),'unsupported_path');
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function validateSymlinkTargetText(target){
|
|
90
|
+
need(validTargetText(target)&&Buffer.byteLength(target)<=1024&&!target.includes('\\')
|
|
91
|
+
&&!path.posix.isAbsolute(target)&&!path.win32.isAbsolute(target)&&!/^[a-z]:/i.test(target),'invalid_symlink_target');
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Resolve POSIX link text one component at a time. Checking components before
|
|
95
|
+
// applying ".." prevents normalization from hiding a link or protected directory.
|
|
96
|
+
export function resolveSymlinkTarget(root,file,target,{specsRoot=null,stat=null}={}){
|
|
97
|
+
const validateTarget=stat!==null;
|
|
98
|
+
if(validateTarget)validateSymlinkTargetText(target);
|
|
99
|
+
else need(validTargetText(target)&&!path.posix.isAbsolute(target)&&!path.win32.isAbsolute(target)
|
|
100
|
+
&&!/^[a-z]:/i.test(target),'symlink_outside_root');
|
|
101
|
+
const parts=file.split('/').slice(0,-1);
|
|
102
|
+
const protectedSpecs=specsRoot?.toLowerCase();
|
|
103
|
+
const checkLocation=relative=>{
|
|
104
|
+
const absolute=path.join(root,relative);
|
|
105
|
+
need(!parts.some(name=>['.git','.reviews'].includes(name.toLowerCase()))
|
|
106
|
+
&&!(protectedSpecs&&inside(protectedSpecs,absolute.toLowerCase()))
|
|
107
|
+
&&relative.toLowerCase()!==file.toLowerCase(),'invalid_symlink_target');
|
|
108
|
+
};
|
|
109
|
+
const segments=target.split('/');
|
|
110
|
+
for(const [index,part] of segments.entries()){
|
|
111
|
+
if(part==='..'){
|
|
112
|
+
need(parts.length>0,validateTarget?'invalid_symlink_target':'symlink_outside_root');
|
|
113
|
+
parts.pop();
|
|
114
|
+
}else if(part&&part!=='.'){
|
|
115
|
+
parts.push(part);
|
|
116
|
+
if(validateTarget){
|
|
117
|
+
const relative=parts.join('/');
|
|
118
|
+
checkLocation(relative);
|
|
119
|
+
const info=stat(relative);
|
|
120
|
+
need(info&&(info.isDirectory()||info.isFile()),'invalid_symlink_target');
|
|
121
|
+
if(!info.isDirectory())need(index===segments.length-1,'invalid_symlink_target');
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
const relative=parts.join('/');
|
|
126
|
+
if(validateTarget){
|
|
127
|
+
checkLocation(relative);
|
|
128
|
+
const info=relative===''?fs.lstatSync(root):stat(relative);
|
|
129
|
+
need(info&&(info.isDirectory()||info.isFile()),'invalid_symlink_target');
|
|
130
|
+
}
|
|
131
|
+
return path.join(root,relative);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
export function validateProtectedEdit(edit,allowSymlinks=false){
|
|
136
|
+
if(Object.hasOwn(edit,'symlink')){
|
|
137
|
+
need(allowSymlinks,'protected_edit_invalid');
|
|
138
|
+
shape(edit,['path','beforeSha256','symlink']);
|
|
139
|
+
validateSymlinkTargetText(edit.symlink);
|
|
140
|
+
}else{
|
|
141
|
+
shape(edit,['path','beforeSha256','content',...(Object.hasOwn(edit,'mode')?['mode']:[])]);
|
|
142
|
+
need(!Object.hasOwn(edit,'mode')||edit.content!==null&&['0644','0755'].includes(edit.mode),'protected_edit_invalid');
|
|
143
|
+
need(edit.content===null||typeof edit.content==='string','protected_edit_invalid');
|
|
144
|
+
need(edit.content===null||Buffer.byteLength(edit.content)<=1024*1024,'limit_exceeded');
|
|
145
|
+
need(edit.content!==null||edit.beforeSha256!==null,'protected_edit_invalid');
|
|
146
|
+
}
|
|
147
|
+
if(edit.beforeSha256!==null)hex(edit.beforeSha256);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export function protectedEditDigest(edit){
|
|
151
|
+
if(Object.hasOwn(edit,'symlink'))return symlinkRecord(edit.path,edit.symlink).sha256;
|
|
152
|
+
return edit.content===null?null:createHash('sha256').update(edit.content).digest('hex');
|
|
153
|
+
}
|
|
@@ -4,6 +4,7 @@ import path from 'node:path';
|
|
|
4
4
|
import { createHash,randomUUID } from 'node:crypto';
|
|
5
5
|
import { types } from 'node:util';
|
|
6
6
|
import {createRequire} from 'node:module';
|
|
7
|
+
import {SYMLINK_BASELINE_VERSION} from './symlink-material.mjs';
|
|
7
8
|
import { verifyCompletionReviewPackage,reviewSpecsPath } from './review-package.mjs';
|
|
8
9
|
import { checkCompletion } from './gate-bridge.mjs';
|
|
9
10
|
import { need,shape,json,digest,validIdentity,JOURNAL_PAYLOAD_LIMIT } from './effect-contract.mjs';
|
|
@@ -62,7 +63,9 @@ function readFile(p) {
|
|
|
62
63
|
}finally{if(fd!==undefined)fs.closeSync(fd);}
|
|
63
64
|
}
|
|
64
65
|
function nativeRevision(p,f) {return digest({path:p,stat:statFields(f.stat),sha256:sha(f.bytes)});}
|
|
65
|
-
function completionSelectors(selectors,identity,projectRoot){
|
|
66
|
+
function completionSelectors(selectors,identity,projectRoot,baseline){
|
|
67
|
+
return {...selectors,task:identity.taskId,projectRoot,allowSymlinks:baseline.version===SYMLINK_BASELINE_VERSION};
|
|
68
|
+
}
|
|
66
69
|
function verifyProof(v) {
|
|
67
70
|
verifyCompletionReviewPackage({root:v.root,baseline:v.baseline,checks:v.checks,reviewPackage:v.reviewPackage,expectedDigest:v.reviewPackage.packageDigest,
|
|
68
71
|
...(Object.hasOwn(v.reviewPackage,'handoff')?{handoffPath:v.selectors.handoff}:{})});
|
|
@@ -127,7 +130,7 @@ function commitCore(input,signal,owner,initial,guard,appendIntent,appendResult)
|
|
|
127
130
|
need((v.baseline.specsPath??null)===reviewSpecsPath(v.root,owner.specsRoot),'overlapping_roots');
|
|
128
131
|
const parent=parentRevision(path.dirname(owner.tasksPath));
|
|
129
132
|
let plan;
|
|
130
|
-
try{plan=json(prepareMarkDone(completionSelectors(selectors,v.identity,v.root)),MiB);}
|
|
133
|
+
try{plan=json(prepareMarkDone(completionSelectors(selectors,v.identity,v.root,v.baseline)),MiB);}
|
|
131
134
|
catch{need(false,'preparation_failed');}
|
|
132
135
|
const {after}=planBytes(plan);
|
|
133
136
|
need(plan.tasksPath===owner.tasksPath && plan.feature===owner.feature && plan.taskId===v.identity.taskId
|
|
@@ -149,7 +152,7 @@ function commitCore(input,signal,owner,initial,guard,appendIntent,appendResult)
|
|
|
149
152
|
const synced=checkTemp();need(sameStat(synced.stat,fs.fstatSync(fd,{bigint:true})),'temporary_changed');
|
|
150
153
|
fs.closeSync(fd);fd=undefined;
|
|
151
154
|
let verified;
|
|
152
|
-
try{verified=verifyMarkDonePlan(completionSelectors(selectors,v.identity,v.root),plan.planDigest);}
|
|
155
|
+
try{verified=verifyMarkDonePlan(completionSelectors(selectors,v.identity,v.root,v.baseline),plan.planDigest);}
|
|
153
156
|
catch{need(false,'preparation_failed');}
|
|
154
157
|
shape(verified,['outcome','planDigest']);need(verified.outcome==='matched' && verified.planDigest===plan.planDigest,'invalid_plan');
|
|
155
158
|
verifyProof(v);guard();
|
|
@@ -17,6 +17,7 @@ import path from 'node:path';
|
|
|
17
17
|
import {createRequire} from 'node:module';
|
|
18
18
|
import {verifySpecificationMaterial,boundSpecificationMaterial,inspectSpecificationDrift,describeSpecificationDrift,
|
|
19
19
|
readSpecificationRebind} from './specification-material.mjs';
|
|
20
|
+
import {SYMLINK_BASELINE_VERSION} from './symlink-material.mjs';
|
|
20
21
|
import { captureReviewBaseline, captureScopeRevisionSources, captureReviewInventory, compareReviewBaseline, createReviewPackage, verifyReviewPackage, verifyCompletionReviewPackage, validChecks, readReviewSourceFiles } from './review-package.mjs';
|
|
21
22
|
import { digest,need,shape,id,text,json,freeze,arrayItems,validIdentity,validTaskLearningInput,validCallTimeout,requestFor,terminalFor,failureCode,
|
|
22
23
|
JOURNAL_PAYLOAD_LIMIT,JOURNAL_REASON_LIMIT,developCheckpointReserve,taskReviewScope,boundedReason } from './effect-contract.mjs';
|
|
@@ -290,7 +291,7 @@ export function createTaskRunner(options) {
|
|
|
290
291
|
let scopeRevisionPaths=restored?.original.scopeRevisionPaths??null;
|
|
291
292
|
const effectiveMetadata=()=>({...metadata,scope:effectiveScope,...(scopeRevisionPaths?{scopeRevisionPaths}: {})});
|
|
292
293
|
const baselineOptions=()=>({...configToBaseline(effectiveMetadata()),
|
|
293
|
-
...(specificationSelection===null?{}:{specification:specificationSelection})});
|
|
294
|
+
...(specificationSelection===null?{}:{specification:specificationSelection,version:SYMLINK_BASELINE_VERSION})});
|
|
294
295
|
let original=restored?.original??captureReviewBaseline(baselineOptions());
|
|
295
296
|
let controller=new AbortController();
|
|
296
297
|
const calls=[],cache=new Map(),session=restored?.session??randomUUID(),registered=new Map(),receipts=[];
|
|
@@ -816,7 +817,8 @@ export function createTaskRunner(options) {
|
|
|
816
817
|
need(liveToken===token&&state==='committing'&&busy&&completeEffect,'commit_capability_invalid');
|
|
817
818
|
if(action==='guard'){storeOperation(currentStore);return ack();}
|
|
818
819
|
need(action==='append-intent'?phase==='prepared':phase==='intent','commit_phase_invalid');
|
|
819
|
-
|
|
820
|
+
// Same bound as readCommitIntent: a commit record the reader accepts must also be writable.
|
|
821
|
+
const fields={effectId:completeEffect.effect.id,completeIntentDigest:completeEffect.digest,commit:json(payload,JOURNAL_PAYLOAD_LIMIT)};
|
|
820
822
|
const type=action==='append-intent'?'task-commit-intent':'task-commit-result';
|
|
821
823
|
// Invalid caller data is rejected before invoking the appender. The actual
|
|
822
824
|
// append repeats preflight against its protected current cursor.
|
|
@@ -1166,10 +1168,11 @@ export function createTaskRunner(options) {
|
|
|
1166
1168
|
for(const file of effectiveScope){
|
|
1167
1169
|
const record=base.files.find(item=>item.path===file);
|
|
1168
1170
|
if(!record){files.set(file,null);continue;}
|
|
1171
|
+
if(record.type==='symlink'){files.set(file,{symlink:record.target});continue;}
|
|
1169
1172
|
if(record.type!=='file'||typeof record.contentBase64!=='string')return {unavailable:'baseline_without_content'};
|
|
1170
1173
|
files.set(file,{bytes:Buffer.from(record.contentBase64,'base64'),mode:record.mode});
|
|
1171
1174
|
}
|
|
1172
|
-
return {files};
|
|
1175
|
+
return {files,...(base.version===SYMLINK_BASELINE_VERSION?{allowSymlinks:true}:{})};
|
|
1173
1176
|
}
|
|
1174
1177
|
async function verificationSatisfied(checks) {
|
|
1175
1178
|
requirementEvidence=null;hostReplayEvidence=null;acceptanceEvidence=null;verificationReason=null;
|
|
@@ -1306,7 +1309,8 @@ export function createTaskRunner(options) {
|
|
|
1306
1309
|
state='awaiting_review';
|
|
1307
1310
|
}
|
|
1308
1311
|
function developControl(effectId,documentationRedo){
|
|
1309
|
-
const control={...(
|
|
1312
|
+
const control={...(original.version===SYMLINK_BASELINE_VERSION?{allowSymlinks:true}:{}),
|
|
1313
|
+
...(workerJournaling()?{onWorker:event=>journalWorker(effectId,event)}:{}),
|
|
1310
1314
|
...(documentationJournaling()?{onDocumentationSync:event=>journalDocumentationSync(effectId,event),
|
|
1311
1315
|
documentationSnapshot:paths=>documentationSnapshot(json(paths))}:{}),
|
|
1312
1316
|
...(documentationRedo?{documentationRedo}:{})};
|
|
@@ -2162,7 +2166,7 @@ export function createTaskRunner(options) {
|
|
|
2162
2166
|
const handoff=loadHandoff(handoffPath,{task:config.identity.taskId,attempt});
|
|
2163
2167
|
const paths=pkg.changes.map(item=>item.path);
|
|
2164
2168
|
need(digest([...handoff.changed_files].sort())===digest([...paths].sort())
|
|
2165
|
-
&&handoff.implementation_sha256===implementationSha256(config.root,handoff.changed_files),
|
|
2169
|
+
&&handoff.implementation_sha256===implementationSha256(config.root,handoff.changed_files,{allowSymlinks:base.version===SYMLINK_BASELINE_VERSION}),
|
|
2166
2170
|
'bootstrap_review_recovery_mismatch');
|
|
2167
2171
|
verifyReviewPackage({root:config.root,baseline:base,checks:currentChecks,
|
|
2168
2172
|
reviewPackage:pkg,expectedDigest:pkg.packageDigest,handoffPath});
|
|
@@ -2185,13 +2189,17 @@ export function createTaskRunner(options) {
|
|
|
2185
2189
|
// Read-only: the reviewed package's task checks, only while the code root
|
|
2186
2190
|
// still matches that package, so a QA command may reuse an identical passed
|
|
2187
2191
|
// check instead of running it again (host-qa-executor reuseCheck).
|
|
2192
|
+
const qaAllowsSymlinks=packageDigest=>{
|
|
2193
|
+
need(state==='fixture_completed'&&reviewPackage?.packageDigest===packageDigest,'stale_qa');
|
|
2194
|
+
return original.version===SYMLINK_BASELINE_VERSION;
|
|
2195
|
+
};
|
|
2188
2196
|
const qaCompletionChecks=packageDigest=>{
|
|
2189
2197
|
need(state==='fixture_completed'&&reviewPackage?.packageDigest===packageDigest,'stale_qa');
|
|
2190
2198
|
verifyReviewPackage({root:config.root,baseline:attemptBaseline(original,reviewPackage.identity.attempt),
|
|
2191
2199
|
checks:reviewPackage.checks,reviewPackage,expectedDigest:reviewPackage.packageDigest,...handoffBinding()});
|
|
2192
2200
|
return freeze(structuredClone(reviewPackage.checks));
|
|
2193
2201
|
};
|
|
2194
|
-
const api={qaChangedFiles,qaCompletionChecks,reviseQa,supersedeEvidence,rebindSpecification,abandonReview,reconcileReview,abandonEffect,recoverBootstrapReview,reworkCompletion,reworkDevelopment,reviseScope,executeEffect,status,cancel,run,inspectFixAssociation,acceptCompletedFix,acceptReviewedIntegration,attachQa,verificationBlocks,completionBlocks,reviewEffectIds,recheckLearningInput,redoDevelop,recoverCommit,interruptions};
|
|
2202
|
+
const api={qaChangedFiles,qaCompletionChecks,qaAllowsSymlinks,reviseQa,supersedeEvidence,rebindSpecification,abandonReview,reconcileReview,abandonEffect,recoverBootstrapReview,reworkCompletion,reworkDevelopment,reviseScope,executeEffect,status,cancel,run,inspectFixAssociation,acceptCompletedFix,acceptReviewedIntegration,attachQa,verificationBlocks,completionBlocks,reviewEffectIds,recheckLearningInput,redoDevelop,recoverCommit,interruptions};
|
|
2195
2203
|
if(bootstrap!==null)api.inspectBootstrapAdmission=()=>bootstrap.inspectAdmission(original);
|
|
2196
2204
|
if(taskLearning!==null)api.attachLearningEvidence=attachLearningEvidence;
|
|
2197
2205
|
// A terminal reviewer observation is durable even if the host died before
|
|
@@ -5,17 +5,24 @@ import {spawn} from 'node:child_process';
|
|
|
5
5
|
import {readFileSync} from 'node:fs';
|
|
6
6
|
import {claudeBaseArgs,claudeEnvironment} from './worker-claude.mjs';
|
|
7
7
|
import {reportClaudeDevIntentNotice,reportClaudeRateLimitNotice} from './claude-review-stream.mjs';
|
|
8
|
+
import {validateProtectedEdit} from './symlink-material.mjs';
|
|
8
9
|
import {need,text,validCallTimeout,json,shape} from './effect-contract.mjs';
|
|
9
10
|
|
|
10
|
-
export function claudeDeveloperArgs(model,effort){
|
|
11
|
+
export function claudeDeveloperArgs(model,effort,{allowSymlinks=false}={}){
|
|
11
12
|
const args=claudeBaseArgs(model,effort),index=args.indexOf('--tools');
|
|
12
13
|
args[index+1]='Read,Grep,Glob';
|
|
13
14
|
const schema=JSON.parse(readFileSync(new URL('./claude-developer-proposal.schema.json',import.meta.url),'utf8'));
|
|
14
15
|
delete schema.$schema;delete schema.$id;
|
|
16
|
+
if(allowSymlinks){
|
|
17
|
+
const regular=schema.properties.edits.items;
|
|
18
|
+
const {path,beforeSha256}=regular.properties;
|
|
19
|
+
schema.properties.edits.items={anyOf:[regular,{type:'object',additionalProperties:false,
|
|
20
|
+
required:['path','beforeSha256','symlink'],properties:{path,beforeSha256,symlink:{type:'string',minLength:1,maxLength:1024}}}]};
|
|
21
|
+
}
|
|
15
22
|
return [...args,'--allowedTools','Read,Grep,Glob','--json-schema',JSON.stringify(schema)];
|
|
16
23
|
}
|
|
17
24
|
|
|
18
|
-
export function validateClaudeProposal(raw){
|
|
25
|
+
export function validateClaudeProposal(raw,{allowSymlinks=false}={}){
|
|
19
26
|
const result=json(raw,64*1024); // Existing 64 KiB transport contract.
|
|
20
27
|
need(result&&['succeeded','failed'].includes(result.status),'invalid_result');
|
|
21
28
|
if(result.status==='failed'){
|
|
@@ -47,6 +54,11 @@ export function validateClaudeProposal(raw){
|
|
|
47
54
|
}
|
|
48
55
|
need(Array.isArray(result.edits)&&result.edits.length<=64,'protected_edit_invalid');
|
|
49
56
|
for(const edit of result.edits){
|
|
57
|
+
if(allowSymlinks&&Object.hasOwn(edit,'symlink')){
|
|
58
|
+
validateProtectedEdit(edit,true);
|
|
59
|
+
need(typeof edit.path==='string'&&edit.path.length>0,'protected_edit_invalid');
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
50
62
|
shape(edit,['path','beforeSha256','content']);
|
|
51
63
|
need(typeof edit.path==='string'&&edit.path.length>0
|
|
52
64
|
&&(edit.beforeSha256===null||(typeof edit.beforeSha256==='string'&&/^[a-f0-9]{64}$/.test(edit.beforeSha256))),'protected_edit_invalid');
|
|
@@ -69,7 +81,7 @@ function startupNotice(subtype,onNotice){
|
|
|
69
81
|
if(typeof onNotice!=='function')return;
|
|
70
82
|
try{onNotice({kind:'claude_system_notice',subtype});}catch{}
|
|
71
83
|
}
|
|
72
|
-
function createClaudeDeveloperStream(onNotice=null,onUsageTerminal=null){
|
|
84
|
+
function createClaudeDeveloperStream(onNotice=null,onUsageTerminal=null,allowSymlinks=false){
|
|
73
85
|
let session=null,initialized=false,done=false,value,assistant=false,noticeCount=0,thinkingCount=0;
|
|
74
86
|
const tools=new Set();
|
|
75
87
|
return {
|
|
@@ -143,15 +155,15 @@ function createClaudeDeveloperStream(onNotice=null,onUsageTerminal=null){
|
|
|
143
155
|
if(!Object.hasOwn(event,'structured_output')){
|
|
144
156
|
try{proposal=JSON.parse(event.result);}catch{need(false,'invalid_output_json');}
|
|
145
157
|
}
|
|
146
|
-
value=validateClaudeProposal(proposal);done=true;
|
|
158
|
+
value=validateClaudeProposal(proposal,{allowSymlinks});done=true;
|
|
147
159
|
},
|
|
148
160
|
finish(){need(done,'incomplete_result');return {...value,providerThread:session};},
|
|
149
161
|
};
|
|
150
162
|
}
|
|
151
163
|
|
|
152
|
-
export function claudeDeveloperWorker({cwd,model,effort,cli='claude',timeoutMs=1800000,spawnProcess=spawn,onNotice=null,onUsage=null,onUsageClaim=null}) {
|
|
164
|
+
export function claudeDeveloperWorker({cwd,model,effort,cli='claude',timeoutMs=1800000,spawnProcess=spawn,onNotice=null,onUsage=null,onUsageClaim=null,allowSymlinks=false}) {
|
|
153
165
|
validCallTimeout(timeoutMs);
|
|
154
|
-
const args=claudeDeveloperArgs(model,effort);
|
|
166
|
+
const args=claudeDeveloperArgs(model,effort,{allowSymlinks});
|
|
155
167
|
let used=false;
|
|
156
168
|
return async (request,{signal})=>{
|
|
157
169
|
text(request.prompt);need(Buffer.byteLength(request.prompt)<=11*1024*1024,'limit_exceeded');
|
|
@@ -167,7 +179,7 @@ export function claudeDeveloperWorker({cwd,model,effort,cli='claude',timeoutMs=1
|
|
|
167
179
|
try{child=spawnProcess(cli,args,{cwd,env:claudeEnvironment(),stdio:['pipe','pipe','pipe'],shell:false,detached:true});}
|
|
168
180
|
catch{usage.complete();resolve({status:'unavailable',code:'spawn_failed'});return;}
|
|
169
181
|
let buffer='',bytes=0;
|
|
170
|
-
const stream=createClaudeDeveloperStream(onNotice,value=>usage.terminal(value));
|
|
182
|
+
const stream=createClaudeDeveloperStream(onNotice,value=>usage.terminal(value),allowSymlinks);
|
|
171
183
|
let failure=null,closed=false,timer,cleanup;
|
|
172
184
|
// signalOwnedGroup (process-group-exit.mjs): an exited, not yet reaped leader
|
|
173
185
|
// (EPERM on macOS) is a stop only once its exit is observed and a re-probe
|
|
@@ -4,7 +4,7 @@ import {createProviderUsageCapture} from './provider-usage.mjs';
|
|
|
4
4
|
import {signalOwnedGroup} from './process-group-exit.mjs';
|
|
5
5
|
import {spawn} from 'node:child_process';
|
|
6
6
|
import {fileURLToPath} from 'node:url';
|
|
7
|
-
import {commonArgs,cleanEnvironment,specsPermissionArgs} from './codex-config.mjs';
|
|
7
|
+
import {commonArgs,cleanEnvironment,specsPermissionArgs,NO_USER_INPUT_TOOL} from './codex-config.mjs';
|
|
8
8
|
import {need,text,validCallTimeout,json} from './effect-contract.mjs';
|
|
9
9
|
import {CODEX_RECONNECT_NOTICE_LIMIT,isCodexReconnectNotice} from './codex-reconnect-notice.mjs';
|
|
10
10
|
import {codexRateLimited,CODEX_FAILURE_GRACE_MS} from './worker-codex.mjs';
|
|
@@ -20,6 +20,8 @@ export function developerArgs({cwd,model,effort,schemaPath,disabledSkills=[],spe
|
|
|
20
20
|
// Codex 0.153.4 uses code_mode_host for tool execution; keep its default
|
|
21
21
|
// on the coding path without enabling the separate code_mode feature.
|
|
22
22
|
if(args[i]==='--disable'&&(coding.has(args[i+1])||args[i+1]==='code_mode_host')){i++;continue;}
|
|
23
|
+
// The review-only removals for Codex 0.167 leave the coding tool surface as it was.
|
|
24
|
+
if(args[i]==='--disable'&&args[i+1]==='view_image'||args[i]==='-c'&&args[i+1]===NO_USER_INPUT_TOOL){i++;continue;}
|
|
23
25
|
result.push(args[i]==='read-only'&&args[i-1]==='--sandbox'?'workspace-write':args[i]);
|
|
24
26
|
}
|
|
25
27
|
return [...result,...[...coding].flatMap(name=>['--enable',name]),
|
|
@@ -3,75 +3,96 @@ import fs from 'node:fs';
|
|
|
3
3
|
import os from 'node:os';
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import {fileURLToPath} from 'node:url';
|
|
6
|
-
import {createHash} from 'node:crypto';
|
|
6
|
+
import {createHash,randomUUID} from 'node:crypto';
|
|
7
7
|
import {createHostCheck} from '../cm-ai/host-check.mjs';
|
|
8
8
|
import {validateDeveloperScope} from '../cm-ai/developer-adapter.mjs';
|
|
9
9
|
import {json,need,shape} from '../cm-ai/effect-contract.mjs';
|
|
10
|
+
import {assertDisjointEditPaths,assertRealParents,lstatOrMissing,readSymlinkRecord,resolveSymlinkTarget,validateProtectedEdit} from '../cm-ai/symlink-material.mjs';
|
|
10
11
|
|
|
11
|
-
function snapshot(cwd,file){
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
function snapshot(cwd,file,allowSymlinks){
|
|
13
|
+
assertRealParents(cwd,file);
|
|
14
|
+
const target=path.join(cwd,file),stat=lstatOrMissing(target);
|
|
15
|
+
if(stat===null)return null;
|
|
16
|
+
if(stat.isSymbolicLink()){
|
|
17
|
+
need(allowSymlinks,'unsupported_path');
|
|
18
|
+
return readSymlinkRecord(cwd,file);
|
|
17
19
|
}
|
|
18
|
-
|
|
20
|
+
need(stat.isFile()&&stat.nlink===1&&stat.size<=1024*1024,'protected_edit_invalid');
|
|
21
|
+
const fd=fs.openSync(target,fs.constants.O_RDONLY|fs.constants.O_NOFOLLOW);
|
|
19
22
|
try{
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
const opened=fs.fstatSync(fd);
|
|
24
|
+
need(stat.dev===opened.dev&&stat.ino===opened.ino&&opened.nlink===1,'protected_edit_stale');
|
|
25
|
+
return {type:'file',sha256:createHash('sha256').update(fs.readFileSync(fd)).digest('hex')};
|
|
26
|
+
}finally{fs.closeSync(fd);}
|
|
23
27
|
}
|
|
24
28
|
|
|
25
29
|
// Optional mode sets the permission bits of a written file (never of a deletion).
|
|
26
30
|
const EDIT_MODES=new Map([['0644',0o644],['0755',0o755]]);
|
|
27
|
-
export function
|
|
31
|
+
export function checkProtectedEdits({cwd,scope,edits,allowSymlinks=false,specsRoot=null}){
|
|
28
32
|
validateDeveloperScope(scope);need(fs.realpathSync(cwd)===cwd,'unsupported_path');
|
|
29
33
|
need(Array.isArray(edits)&&edits.length>0&&edits.length<=scope.length,'protected_edit_invalid');
|
|
30
|
-
const seen=new Set();
|
|
34
|
+
const seen=new Set(),removed=new Set(edits.filter(edit=>edit.content===null||Object.hasOwn(edit,'symlink')).map(edit=>edit.path));
|
|
35
|
+
const check=edit=>{
|
|
36
|
+
const before=snapshot(cwd,edit.path,allowSymlinks),link=Object.hasOwn(edit,'symlink');
|
|
37
|
+
need(before?.type!=='symlink'||link||edit.content===null,'unsupported_path');
|
|
38
|
+
need(edit.beforeSha256===(before?.sha256??null),'protected_edit_stale');
|
|
39
|
+
if(link)resolveSymlinkTarget(cwd,edit.path,edit.symlink,{specsRoot,
|
|
40
|
+
stat:file=>removed.has(file)?null:lstatOrMissing(path.join(cwd,file))});
|
|
41
|
+
};
|
|
31
42
|
for(const edit of edits){
|
|
32
|
-
|
|
33
|
-
need(!Object.hasOwn(edit,'mode')||edit.content!==null&&EDIT_MODES.has(edit.mode),'protected_edit_invalid');
|
|
43
|
+
validateProtectedEdit(edit,allowSymlinks);
|
|
34
44
|
need(scope.includes(edit.path)&&!seen.has(edit.path),'out_of_scope');seen.add(edit.path);
|
|
35
|
-
|
|
36
|
-
need(edit.content===null||Buffer.byteLength(edit.content)<=1024*1024,'limit_exceeded');
|
|
37
|
-
need(edit.beforeSha256===snapshot(cwd,edit.path),'protected_edit_stale');
|
|
38
|
-
need(edit.content!==null||edit.beforeSha256!==null,'protected_edit_invalid');
|
|
45
|
+
check(edit);
|
|
39
46
|
}
|
|
47
|
+
if(allowSymlinks)assertDisjointEditPaths([...seen]);
|
|
48
|
+
return check;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function applyProtectedEdits(options){
|
|
52
|
+
const {cwd,edits}=options,check=checkProtectedEdits(options);
|
|
40
53
|
for(const edit of edits){
|
|
41
|
-
|
|
54
|
+
check(edit);
|
|
42
55
|
const target=path.join(cwd,edit.path);
|
|
43
|
-
if(edit.content===null)fs.unlinkSync(target);
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
try{
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
fs.fsyncSync(fd);
|
|
54
|
-
}finally{fs.closeSync(fd);}
|
|
56
|
+
if(edit.content===null){fs.unlinkSync(target);continue;}
|
|
57
|
+
fs.mkdirSync(path.dirname(target),{recursive:true});
|
|
58
|
+
check(edit);
|
|
59
|
+
if(Object.hasOwn(edit,'symlink')){
|
|
60
|
+
if(edit.beforeSha256===null){fs.symlinkSync(edit.symlink,target);continue;}
|
|
61
|
+
const temporary=path.join(path.dirname(target),'.cm-link-'+randomUUID());
|
|
62
|
+
fs.symlinkSync(edit.symlink,temporary);
|
|
63
|
+
try{check(edit);fs.renameSync(temporary,target);}
|
|
64
|
+
finally{if(lstatOrMissing(temporary))fs.unlinkSync(temporary);}
|
|
65
|
+
continue;
|
|
55
66
|
}
|
|
67
|
+
const created=edit.beforeSha256===null;
|
|
68
|
+
const flags=fs.constants.O_WRONLY|fs.constants.O_NOFOLLOW
|
|
69
|
+
|(created?fs.constants.O_CREAT|fs.constants.O_EXCL:fs.constants.O_TRUNC);
|
|
70
|
+
const fd=fs.openSync(target,flags,0o644);
|
|
71
|
+
try{
|
|
72
|
+
fs.writeFileSync(fd,edit.content);
|
|
73
|
+
if(created||Object.hasOwn(edit,'mode'))fs.fchmodSync(fd,EDIT_MODES.get(edit.mode)??0o644);
|
|
74
|
+
fs.fsyncSync(fd);
|
|
75
|
+
}finally{fs.closeSync(fd);}
|
|
56
76
|
}
|
|
57
77
|
}
|
|
58
78
|
|
|
59
|
-
export function captureProtectedEdits(cwd,scope){
|
|
79
|
+
export function captureProtectedEdits(cwd,scope,{allowSymlinks=false}={}){
|
|
60
80
|
validateDeveloperScope(scope);
|
|
61
|
-
return Object.fromEntries(scope.map(file=>[file,snapshot(cwd,file)]));
|
|
81
|
+
return Object.fromEntries(scope.map(file=>[file,snapshot(cwd,file,allowSymlinks)?.sha256??null]));
|
|
62
82
|
}
|
|
63
83
|
|
|
64
84
|
// onApply (cm-ai protected development) journals the applying subprocess:
|
|
65
85
|
// apply_spawning before the spawn, apply_started with its pid right after. A
|
|
66
86
|
// journal failure kills the new group and fails the apply.
|
|
67
|
-
export async function commitProtectedEdits({cwd,specsRoot,scope,edits,expected,identity,timeoutMs,signal,onApply=null}){
|
|
87
|
+
export async function commitProtectedEdits({cwd,specsRoot,scope,edits,expected,identity,timeoutMs,signal,onApply=null,allowSymlinks=false}){
|
|
68
88
|
need(Array.isArray(edits),'protected_edit_invalid');
|
|
69
89
|
for(const edit of edits)need(Object.hasOwn(expected,edit.path)&&edit.beforeSha256===expected[edit.path],'protected_edit_stale');
|
|
70
90
|
need(!signal.aborted,'cancelled');
|
|
71
91
|
if(edits.length===0)return;
|
|
92
|
+
if(allowSymlinks)checkProtectedEdits({cwd,scope,edits,allowSymlinks,specsRoot});
|
|
72
93
|
const dir=fs.mkdtempSync(path.join(os.tmpdir(),'cm-fix-edits-')),file=path.join(dir,'edits.json');
|
|
73
94
|
try{
|
|
74
|
-
fs.writeFileSync(file,JSON.stringify({cwd,scope,edits}),{mode:0o600,flag:'wx'});
|
|
95
|
+
fs.writeFileSync(file,JSON.stringify({cwd,scope,edits,allowSymlinks,specsRoot}),{mode:0o600,flag:'wx'});
|
|
75
96
|
let journalFailed=false;
|
|
76
97
|
onApply?.({phase:'apply_spawning'});
|
|
77
98
|
const check=createHostCheck({cwd,specsRoot,timeoutMs,commands:[{id:'protected-edits',
|
|
@@ -10,6 +10,7 @@ import {loadConfig,resolveRole} from '../../../scripts/cm-workflow-config.mjs';
|
|
|
10
10
|
import {buildManifest} from '../../../scripts/cm-spec-manifest.mjs';
|
|
11
11
|
import {specLines,taskDeclarations,TASK_GRAMMAR,LEGACY_TASK_GRAMMAR,recordedTaskGrammar} from '../spec-task-line.mjs';
|
|
12
12
|
import {inspectPrdReview} from '../../../scripts/cm-prd-review-gate.mjs';
|
|
13
|
+
import {approvedSpecBaseline} from '../cm-ai/spec-amendment.mjs';
|
|
13
14
|
import {readCmInitSource} from '../cm-init/draft-inspection.mjs';
|
|
14
15
|
import {prdTreeFileDigest} from './tree-digest.mjs';
|
|
15
16
|
import {writeImmutableWorkflowFile} from '../cm-ai/review-evidence-file.mjs';
|
|
@@ -290,6 +291,8 @@ export function assertPrdReviewsSettled(specs,selected,{requireSplit=false}={}){
|
|
|
290
291
|
const archive=read(specs,`.reviews/prd-change-${status.revisionDigest}.json`);
|
|
291
292
|
if(archive!==null){const value=JSON.parse(archive);need(value.proposal.proposalDigest===status.revisionDigest,'prd_revision_archive_invalid');historical=value.before.reviews;}
|
|
292
293
|
}
|
|
294
|
+
// Receipts predate later human approvals and applied amendments; those bound bytes count too.
|
|
295
|
+
const approvedBaseline=approvedSpecBaseline(specs);
|
|
293
296
|
for(const directory of selected)for(const stage of ['design','split']){
|
|
294
297
|
const feature=directory.replace(/^\d+\./,''),prefix=`prd-${feature}-${stage}`;
|
|
295
298
|
for(const suffix of ['-dispatch.json','-r1.md','-r2.md','-disposition.json'])readCmInitSource(specs,`.reviews/${prefix}${suffix}`);
|
|
@@ -299,7 +302,7 @@ export function assertPrdReviewsSettled(specs,selected,{requireSplit=false}={}){
|
|
|
299
302
|
need(sha(readCmInitSource(specs,file))===hash,'prd_change_review_changed');
|
|
300
303
|
continue;
|
|
301
304
|
}
|
|
302
|
-
const gate=inspectPrdReview({stage,feature,evidence:path.join(reviews,`${prefix}-r1.md`),receipt:path.join(reviews,`${prefix}-disposition.json`)});
|
|
305
|
+
const gate=inspectPrdReview({stage,feature,evidence:path.join(reviews,`${prefix}-r1.md`),receipt:path.join(reviews,`${prefix}-disposition.json`),approvedBaseline});
|
|
303
306
|
need(['dispatch_once','completed'].includes(gate.outcome),'prd_revision_prior_review_unresolved');
|
|
304
307
|
if(requireSplit&&stage==='split')need(gate.outcome==='completed','prd_revision_original_split_required');
|
|
305
308
|
}
|
|
@@ -5,7 +5,8 @@ import {readCmInitSource} from '../cm-init/draft-inspection.mjs';
|
|
|
5
5
|
import {publishPrdReview} from './review-publication.mjs';
|
|
6
6
|
import {need,shape,json,digest} from '../cm-ai/effect-contract.mjs';
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
// approvedBaseline: change-mode only, see assertPrdReviewsSettled.
|
|
9
|
+
export function inspectPrdFindings({specs,stage,feature,pendingSplit=null,approvedBaseline=null}){
|
|
9
10
|
need(typeof specs==='string'&&fs.realpathSync(specs)===specs,'prd_review_root_invalid');
|
|
10
11
|
need(['design','split'].includes(stage),'prd_review_stage_invalid');
|
|
11
12
|
const match=typeof feature==='string'&&feature.match(/^([1-9]\d*)\.([a-z0-9]+(?:-[a-z0-9]+)*)$/);
|
|
@@ -23,7 +24,7 @@ export function inspectPrdFindings({specs,stage,feature,pendingSplit=null}){
|
|
|
23
24
|
const packageDigest=digest(archive.reviewPackage);
|
|
24
25
|
// Reuse the publisher's complete validation and exact-byte projection, but
|
|
25
26
|
// inspect only: never repair, recreate, overwrite or dispatch from this read.
|
|
26
|
-
const verified=publishPrdReview({specs,...archive,packageDigest,inspectOnly:true,pendingSplit});
|
|
27
|
+
const verified=publishPrdReview({specs,...archive,packageDigest,inspectOnly:true,pendingSplit,approvedBaseline});
|
|
27
28
|
const result=archive.response.result;
|
|
28
29
|
return json({status:'review_findings_ready',stage,feature,packageDigest,
|
|
29
30
|
draftDigest:archive.reviewPackage.draftDigest,evidence:relative,gate:verified.gate,
|
|
@@ -36,7 +36,8 @@ export function inspectPrdReviewResponse({reviewPackage,packageDigest,authorCont
|
|
|
36
36
|
return {response,result,examinedPaths,degraded};
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
export function publishPrdReview({specs,reviewPackage,packageDigest,authorContextId,response,inspectOnly=false,pendingSplit=null}){
|
|
39
|
+
export function publishPrdReview({specs,reviewPackage,packageDigest,authorContextId,response,inspectOnly=false,pendingSplit=null,approvedBaseline=null}){
|
|
40
|
+
need(approvedBaseline===null||inspectOnly,'prd_review_approved_baseline_inspect_only');
|
|
40
41
|
inspectPrdReviewResponse({reviewPackage,packageDigest,authorContextId,response});
|
|
41
42
|
if(!inspectOnly)assertPrdBatchActive(specs,[reviewPackage.feature]);
|
|
42
43
|
reviewPackage=json(reviewPackage,256*1024);response=json(response,64*1024);id(authorContextId);
|
|
@@ -48,7 +49,7 @@ export function publishPrdReview({specs,reviewPackage,packageDigest,authorContex
|
|
|
48
49
|
const reviews=path.join(specs,'.reviews');
|
|
49
50
|
need(fs.realpathSync(reviews)===reviews&&fs.lstatSync(reviews).isDirectory(),'prd_review_path_invalid');
|
|
50
51
|
const stage=reviewPackage.stage,feature=match[2],prefix=`prd-${feature}-${stage}`;
|
|
51
|
-
const args={stage,feature,pendingSplit,evidence:path.join(reviews,`${prefix}-r1.md`),receipt:path.join(reviews,`${prefix}-disposition.json`)};
|
|
52
|
+
const args={stage,feature,pendingSplit,approvedBaseline,evidence:path.join(reviews,`${prefix}-r1.md`),receipt:path.join(reviews,`${prefix}-disposition.json`)};
|
|
52
53
|
const gate=inspectPrdReview(args);
|
|
53
54
|
need(gate.package_sha256===packageDigest&&['dispatch_unknown','resume_disposition','completed'].includes(gate.outcome),
|
|
54
55
|
'prd_review_unclaimed');
|
|
@@ -8,13 +8,13 @@ import {inspectPrdDispositionPlan} from './disposition-plan.mjs';
|
|
|
8
8
|
import {need,digest} from '../cm-ai/effect-contract.mjs';
|
|
9
9
|
const sha=bytes=>createHash('sha256').update(bytes).digest('hex');
|
|
10
10
|
|
|
11
|
-
export function inspectPrdSplitDesign({specs,feature,originalSha,requirementsSha,draftDigest,pendingSplit=null,document='design.md'}){
|
|
11
|
+
export function inspectPrdSplitDesign({specs,feature,originalSha,requirementsSha,draftDigest,pendingSplit=null,document='design.md',approvedBaseline=null}){
|
|
12
12
|
need(['requirements.md','design.md'].includes(document),'prd_split_document_invalid');
|
|
13
13
|
const targetPath=`${feature}/${document}`;
|
|
14
14
|
const changedError=document==='requirements.md'?'prd_design_requirements_changed':'prd_design_receipt_changed';
|
|
15
15
|
const prefix=`.reviews/prd-${feature.replace(/^\d+\./,'')}-split`;
|
|
16
16
|
if(readCmInitSource(specs,prefix+'-r1.md')===null)return null;
|
|
17
|
-
const review=inspectPrdFindings({specs,stage:'split',feature});
|
|
17
|
+
const review=inspectPrdFindings({specs,stage:'split',feature,approvedBaseline});
|
|
18
18
|
const designPath=`${feature}/design.md`,requirementsPath=`${feature}/requirements.md`;
|
|
19
19
|
const baseline=prdSelfCheckRevisionBaseline(specs,feature,{originalSha,requirementsSha,draftDigest});
|
|
20
20
|
need(draftDigest===undefined||draftDigest===baseline.draftDigest,'prd_split_design_binding_changed');
|
|
@@ -45,7 +45,7 @@ export function inspectPrdSplitDesign({specs,feature,originalSha,requirementsSha
|
|
|
45
45
|
|
|
46
46
|
// Used by the shared receipt gate, including summary, publication and revision.
|
|
47
47
|
// Legacy receipts without a host archive retain their original strict behavior.
|
|
48
|
-
export function acceptsPrdSplitDesign({specs,evidence,receipt,item,currentSha,pendingSplit=null}){
|
|
48
|
+
export function acceptsPrdSplitDesign({specs,evidence,receipt,item,currentSha,pendingSplit=null,approvedBaseline=null}){
|
|
49
49
|
if(receipt.stage!=='design'||!item.path.endsWith('/design.md'))return null;
|
|
50
50
|
const bytes=readCmInitSource(specs,evidence);
|
|
51
51
|
const line=bytes?.toString('utf8').match(/\n```json\n([^\n]+)\n```\n$/);
|
|
@@ -61,7 +61,7 @@ export function acceptsPrdSplitDesign({specs,evidence,receipt,item,currentSha,pe
|
|
|
61
61
|
// accepted requirements/design bytes; pending plans require exact saved hashes.
|
|
62
62
|
const baseline=prdSelfCheckRevisionBaseline(specs,pkg.feature,{designDraftDigest:pkg.draftDigest,originalSha:item.sha256,requirementsSha});
|
|
63
63
|
const splitSha=inspectPrdSplitDesign({specs,feature:pkg.feature,originalSha:item.sha256,requirementsSha,
|
|
64
|
-
pendingSplit:currentSha===baseline.originalSha?null:pendingSplit});
|
|
64
|
+
pendingSplit:currentSha===baseline.originalSha?null:pendingSplit,approvedBaseline});
|
|
65
65
|
const completed=readCmInitSource(specs,`.reviews/prd-${receipt.feature}-split-disposition.json`)!==null;
|
|
66
66
|
return (completed||splitSha!==null?splitSha:baseline.originalSha)===currentSha;
|
|
67
67
|
}
|
|
@@ -9,11 +9,11 @@ import {parseFeatureTaskText,validDependencies,identifyApprovedBootstrapFeature,
|
|
|
9
9
|
import {validateRunDefinition} from './cm-ai-run.mjs';
|
|
10
10
|
import {buildManifest} from './cm-spec-manifest.mjs';
|
|
11
11
|
// Spec approvals write a round ledger under CM_WORKFLOW_HOME; keep it off the real home.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
12
|
+
// Always, not only when unset: an exported CM_WORKFLOW_HOME may be the tester's real home
|
|
13
|
+
// (review 2026-11-17: these suites left 11 approval records in an externally named home).
|
|
14
|
+
const isolatedHome=fs.mkdtempSync(path.join(os.tmpdir(),'cm-approval-home-'));
|
|
15
|
+
process.env.CM_WORKFLOW_HOME=isolatedHome;
|
|
16
|
+
process.on('exit',()=>fs.rmSync(isolatedHome,{recursive:true,force:true}));
|
|
17
17
|
|
|
18
18
|
const entry=fileURLToPath(new URL('./cm-ai-admission.mjs',import.meta.url));
|
|
19
19
|
function fixture(run){
|