@aibyzero/cm-workflow 0.21.2 → 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 +7 -0
- package/README.md +7 -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/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/symlink-material.mjs +153 -0
- package/runtime/js/cm-ai/task-commit.mjs +6 -3
- package/runtime/js/cm-ai/task-runner.mjs +12 -5
- package/runtime/js/cm-ai/worker-claude-developer.mjs +19 -7
- package/runtime/js/cm-fix/protected-edits.mjs +57 -36
- package/scripts/ci-test-weights.json +1 -0
- 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 +141 -42
- 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-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-skill-hints.mjs +40 -16
- package/scripts/cm-skill-hints.test.mjs +91 -0
- 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/skills/cm-ai/references/js-host.md +1 -0
|
@@ -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=[];
|
|
@@ -1167,10 +1168,11 @@ export function createTaskRunner(options) {
|
|
|
1167
1168
|
for(const file of effectiveScope){
|
|
1168
1169
|
const record=base.files.find(item=>item.path===file);
|
|
1169
1170
|
if(!record){files.set(file,null);continue;}
|
|
1171
|
+
if(record.type==='symlink'){files.set(file,{symlink:record.target});continue;}
|
|
1170
1172
|
if(record.type!=='file'||typeof record.contentBase64!=='string')return {unavailable:'baseline_without_content'};
|
|
1171
1173
|
files.set(file,{bytes:Buffer.from(record.contentBase64,'base64'),mode:record.mode});
|
|
1172
1174
|
}
|
|
1173
|
-
return {files};
|
|
1175
|
+
return {files,...(base.version===SYMLINK_BASELINE_VERSION?{allowSymlinks:true}:{})};
|
|
1174
1176
|
}
|
|
1175
1177
|
async function verificationSatisfied(checks) {
|
|
1176
1178
|
requirementEvidence=null;hostReplayEvidence=null;acceptanceEvidence=null;verificationReason=null;
|
|
@@ -1307,7 +1309,8 @@ export function createTaskRunner(options) {
|
|
|
1307
1309
|
state='awaiting_review';
|
|
1308
1310
|
}
|
|
1309
1311
|
function developControl(effectId,documentationRedo){
|
|
1310
|
-
const control={...(
|
|
1312
|
+
const control={...(original.version===SYMLINK_BASELINE_VERSION?{allowSymlinks:true}:{}),
|
|
1313
|
+
...(workerJournaling()?{onWorker:event=>journalWorker(effectId,event)}:{}),
|
|
1311
1314
|
...(documentationJournaling()?{onDocumentationSync:event=>journalDocumentationSync(effectId,event),
|
|
1312
1315
|
documentationSnapshot:paths=>documentationSnapshot(json(paths))}:{}),
|
|
1313
1316
|
...(documentationRedo?{documentationRedo}:{})};
|
|
@@ -2163,7 +2166,7 @@ export function createTaskRunner(options) {
|
|
|
2163
2166
|
const handoff=loadHandoff(handoffPath,{task:config.identity.taskId,attempt});
|
|
2164
2167
|
const paths=pkg.changes.map(item=>item.path);
|
|
2165
2168
|
need(digest([...handoff.changed_files].sort())===digest([...paths].sort())
|
|
2166
|
-
&&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}),
|
|
2167
2170
|
'bootstrap_review_recovery_mismatch');
|
|
2168
2171
|
verifyReviewPackage({root:config.root,baseline:base,checks:currentChecks,
|
|
2169
2172
|
reviewPackage:pkg,expectedDigest:pkg.packageDigest,handoffPath});
|
|
@@ -2186,13 +2189,17 @@ export function createTaskRunner(options) {
|
|
|
2186
2189
|
// Read-only: the reviewed package's task checks, only while the code root
|
|
2187
2190
|
// still matches that package, so a QA command may reuse an identical passed
|
|
2188
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
|
+
};
|
|
2189
2196
|
const qaCompletionChecks=packageDigest=>{
|
|
2190
2197
|
need(state==='fixture_completed'&&reviewPackage?.packageDigest===packageDigest,'stale_qa');
|
|
2191
2198
|
verifyReviewPackage({root:config.root,baseline:attemptBaseline(original,reviewPackage.identity.attempt),
|
|
2192
2199
|
checks:reviewPackage.checks,reviewPackage,expectedDigest:reviewPackage.packageDigest,...handoffBinding()});
|
|
2193
2200
|
return freeze(structuredClone(reviewPackage.checks));
|
|
2194
2201
|
};
|
|
2195
|
-
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};
|
|
2196
2203
|
if(bootstrap!==null)api.inspectBootstrapAdmission=()=>bootstrap.inspectAdmission(original);
|
|
2197
2204
|
if(taskLearning!==null)api.attachLearningEvidence=attachLearningEvidence;
|
|
2198
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
|
|
@@ -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',
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
// to child/single-task hosts and are not batch operations.
|
|
17
17
|
// develop_redo/abandon_effect/abandon_review/bootstrap_review_recover -> none:
|
|
18
18
|
// batch-run.mjs memberAction forwards one to the stopped member's cm-ai entry (Q24).
|
|
19
|
+
import {SYMLINK_BASELINE_VERSION} from '../runtime/js/cm-ai/symlink-material.mjs';
|
|
19
20
|
import {readBatchExecutionPolicy} from '../runtime/js/cm-ai/execution-policy.mjs';
|
|
20
21
|
import {batchSegments,batchMemberWorktree} from '../runtime/js/cm-ai/batch-location.mjs';
|
|
21
22
|
import {readBatchExternalModels,batchModelsFile} from '../runtime/js/cm-ai/external-group-models.mjs';
|
|
@@ -139,7 +140,7 @@ function preflight(){
|
|
|
139
140
|
process.stdout.write('用法: cm-ai-batch-drive.mjs --plan PLAN.json <operation>\n'
|
|
140
141
|
+'operation: advance, status, cancel, reconcile_review(taskKey、invocationId), develop_redo / abandon_effect / abandon_review / bootstrap_review_recover(resume、PLAN.taskKey、单行 PLAN.reason,permissions 带对应 --allow-… 任务)。PLAN: config, mode, hostContext, permissions, answers, checks, checkTimeoutMs。\n'
|
|
141
142
|
+'checks 每项为 {id,command,timeoutMs?};超时为 1..3600000 整数,默认 900000 ms(15 分钟)。\n'
|
|
142
|
-
+'develop.json.edits 与单任务驾驶员相同:内容文件、{file,mode}、{mode}、{delete:true}
|
|
143
|
+
+'develop.json.edits 与单任务驾驶员相同:内容文件、{file,mode}、{mode}、{delete:true} 和新运行的 {symlink}。启动前同样拒绝超限、空交付与受保护模式下的非 UTF-8 内容(尚未开跑的后续任务不看代码树,只做答案本身就能判定的检查:单文件 1 MiB、答案写入的 scope 文件合计 2 MiB,等等;运行存档单条记录上限要看该任务开跑时的代码树,驾驶员事先算不出,超限交付写入后由宿主拦下,停在可重试的 blocked/develop_package_too_large)。\n'
|
|
143
144
|
+'按已有配置自动审查,还没有 develop-a2.json 时照常启动:审查若要求修改,该任务停在 changes_requested(revision_answer_required),读 .reviews/<feature>-<task>-r1.md 的 findings 写好 develop-a2.json 后再 advance。\n');
|
|
144
145
|
process.exit(0);
|
|
145
146
|
}
|
|
@@ -364,8 +365,10 @@ function preflight(){
|
|
|
364
365
|
const known=journal!==null||plan.mode==='create'&&firstGroup.includes(key);
|
|
365
366
|
const cwd=journal?actualCwd(bundle,key,journal.generation):batch.codeProject;
|
|
366
367
|
const codeProject=fs.existsSync(cwd)?cwd:batch.codeProject;
|
|
367
|
-
|
|
368
|
-
|
|
368
|
+
const codeProjects=definition.codeProjects?.map(root=>path.join(codeProject,path.relative(definition.codeProject,root)));
|
|
369
|
+
preflightDevelopDeliveries({deliveries,answersRoot:taskRoot,codeProject,codeProjects,
|
|
370
|
+
allowSymlinks:journal===null||journal.baseline.version===SYMLINK_BASELINE_VERSION,
|
|
371
|
+
scope:definition.scope,requirements:definition.requirements,diskChecks:known,specsRoot:definition.specsDir,
|
|
369
372
|
baseline:journal?baselineScope(journal.baseline,definition.scope):'disk',protectedMode,inputLimit,
|
|
370
373
|
checks:plannedCheckResults(protectedMode?null:plan.checks?.[key]),
|
|
371
374
|
preview:known?developPreview({definition,codeProject,journal,
|
|
@@ -432,9 +435,10 @@ async function answerFor(row,answers,paths,control){
|
|
|
432
435
|
if(!value)throw Error(`任务 ${key} develop attempt ${identity?.attempt} 未预检,拒绝复用旧答案`);
|
|
433
436
|
if(row.payload.codeProject!==cwd)return null;
|
|
434
437
|
if(value.status!=='succeeded')return {status:'failed',code:value.code};
|
|
438
|
+
const editOptions={allowSymlinks:row.payload.allowSymlinks===true,specsRoot:loaded.bundle.batch.specsDir,codeProjects:row.payload.codeProjects};
|
|
435
439
|
if(row.payload.editMode==='protected-text-v1')return {status:'succeeded',value:value.value,
|
|
436
|
-
edits:protectedDevelopEdits(value.edits,root,cwd,row.payload.expected)};
|
|
437
|
-
applyDevelopEdits(value.edits,root,cwd,row.payload.request.payload.scope);
|
|
440
|
+
edits:protectedDevelopEdits(value.edits,root,cwd,row.payload.expected,editOptions)};
|
|
441
|
+
applyDevelopEdits(value.edits,root,cwd,row.payload.request.payload.scope,editOptions);
|
|
438
442
|
return {status:'succeeded',value:value.value};
|
|
439
443
|
}
|
|
440
444
|
if(row.kind==='documentation_sync'){
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import test from 'node:test';
|
|
5
|
+
import {fileURLToPath} from 'node:url';
|
|
6
|
+
import {parseCallTimeoutMinutes,callTimeoutFrom,DEFAULT_CALL_TIMEOUT_MS} from '../runtime/js/cm-ai/call-timeout.mjs';
|
|
7
|
+
import {createConversationExecution} from '../runtime/js/cm-ai/host-conversation-execution.mjs';
|
|
8
|
+
import {sameRunnerConfig} from '../runtime/js/cm-ai/durable-runner-state.mjs';
|
|
9
|
+
|
|
10
|
+
const here=path.dirname(fileURLToPath(import.meta.url));
|
|
11
|
+
|
|
12
|
+
test('--call-timeout-minutes 只收 30–60 的整数分钟;缺省为 null(沿用 30 分钟)', () => {
|
|
13
|
+
assert.equal(parseCallTimeoutMinutes(undefined), null);
|
|
14
|
+
assert.equal(parseCallTimeoutMinutes('30'), 1800000);
|
|
15
|
+
assert.equal(parseCallTimeoutMinutes('60'), 3600000);
|
|
16
|
+
for (const bad of ['29', '61', '45.5', '045', '', 'x', '600'])
|
|
17
|
+
assert.throws(() => parseCallTimeoutMinutes(bad), {code: 'invalid_arguments'}, bad);
|
|
18
|
+
assert.equal(callTimeoutFrom(['--feature', 'f', '--call-timeout-minutes', '55']), 3300000);
|
|
19
|
+
assert.equal(callTimeoutFrom(['--feature', 'f']), null);
|
|
20
|
+
assert.throws(() => callTimeoutFrom(['--call-timeout-minutes']), {code: 'invalid_arguments'});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test('当前会话运行的调用期限:默认 30 分钟,传入 callTimeoutMs 时用它;范围外拒绝', () => {
|
|
24
|
+
const definition = {codeProject: here, specsDir: here, feature: '1.f', identity: {repositoryId: 'r', runId: 'x', taskId: 'T-001', attempt: 1},
|
|
25
|
+
scope: ['a.js'], requirements: []};
|
|
26
|
+
const bridge = {call: () => assert.fail('unexpected host call')};
|
|
27
|
+
assert.equal(createConversationExecution(definition, 'h', bridge).timeoutMs, DEFAULT_CALL_TIMEOUT_MS);
|
|
28
|
+
assert.equal(createConversationExecution(definition, 'h', bridge, null, null, null, false, 'codex', {callTimeoutMs: 3600000}).timeoutMs, 3600000);
|
|
29
|
+
for (const bad of [1799999, 3600001, 2000000.5])
|
|
30
|
+
assert.throws(() => createConversationExecution(definition, 'h', bridge, null, null, null, false, 'codex', {callTimeoutMs: bad}), undefined, String(bad));
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('宿主与驱动都接上了这个参数(静态核对,防止只改一处)', () => {
|
|
34
|
+
const host = fs.readFileSync(path.join(here, 'cm-ai-host.mjs'), 'utf8');
|
|
35
|
+
assert.match(host, /'--call-timeout-minutes'/);
|
|
36
|
+
assert.match(host, /callTimeoutMs/);
|
|
37
|
+
const drive = fs.readFileSync(path.join(here, 'cm-ai-drive.mjs'), 'utf8');
|
|
38
|
+
assert.match(drive, /'--call-timeout-minutes'/);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('落盘回放只对当前会话运行放宽期限比对;其余字段与受保护/外部模型运行仍逐字节比对', () => {
|
|
42
|
+
const base = {root: '/r', timeoutMs: 1800000, developer: {provider: 'claude', requestedModel: 'current-session', contextId: 'c'}};
|
|
43
|
+
assert.doesNotThrow(() => sameRunnerConfig(base, {...base, timeoutMs: 3600000}));
|
|
44
|
+
assert.throws(() => sameRunnerConfig({...base, timeoutMs: 3600000}, base), {code: 'invalid_arguments'});
|
|
45
|
+
assert.throws(() => sameRunnerConfig(base, {...base, root: '/other', timeoutMs: 3600000}), {code: 'runner_history_mismatch'});
|
|
46
|
+
assert.throws(() => sameRunnerConfig(base, {...base, timeoutMs: 3600001}), {code: 'runner_history_mismatch'});
|
|
47
|
+
const provider = {...base, developer: {...base.developer, requestedModel: 'gpt-x'}};
|
|
48
|
+
assert.throws(() => sameRunnerConfig(provider, {...provider, timeoutMs: 3600000}), {code: 'runner_history_mismatch'});
|
|
49
|
+
assert.throws(() => sameRunnerConfig(base, {...provider, timeoutMs: 1800000}), {code: 'runner_history_mismatch'});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('期限不进执行配置:同一运行定义下 30 与 60 分钟的配置字节相同', () => {
|
|
53
|
+
const definition = {codeProject: here, specsDir: here, feature: '1.f', identity: {repositoryId: 'r', runId: 'x', taskId: 'T-001', attempt: 1},
|
|
54
|
+
scope: ['a.js'], requirements: []};
|
|
55
|
+
const bridge = {call: () => assert.fail('unexpected host call')};
|
|
56
|
+
const a = createConversationExecution(definition, 'h', bridge), b = createConversationExecution(definition, 'h', bridge, null, null, null, false, 'codex', {callTimeoutMs: 3600000});
|
|
57
|
+
assert.deepEqual(b.configuration, a.configuration);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test('受保护会话与外部模型运行不接受期限放宽:构造入口拒绝,回放不忽略外部模型运行的期限差异;重复参数非法', () => {
|
|
61
|
+
const definition = {codeProject: here, specsDir: here, feature: '1.f', identity: {repositoryId: 'r', runId: 'x', taskId: 'T-001', attempt: 1},
|
|
62
|
+
scope: ['a.js'], requirements: []};
|
|
63
|
+
const bridge = {call: () => assert.fail('unexpected host call')};
|
|
64
|
+
assert.throws(() => createConversationExecution(definition, 'h', bridge, null, null, null, false, 'codex', {callTimeoutMs: 3600000, protection: {checkCommands: [], timeoutMs: 600000}}),
|
|
65
|
+
{code: 'invalid_input'});
|
|
66
|
+
const external = {root: '/r', timeoutMs: 1800000, externalModels: {version: 1},
|
|
67
|
+
developer: {provider: 'claude', requestedModel: 'current-session', contextId: 'c'}};
|
|
68
|
+
assert.throws(() => sameRunnerConfig(external, {...external, timeoutMs: 3600000}), {code: 'runner_history_mismatch'});
|
|
69
|
+
assert.throws(() => callTimeoutFrom(['--call-timeout-minutes', '60', '--call-timeout-minutes', '90']), {code: 'invalid_arguments'});
|
|
70
|
+
assert.throws(() => callTimeoutFrom(['--call-timeout-minutes', '60', '--call-timeout-minutes', '60']), {code: 'invalid_arguments'});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('宿主在加载外部模型快照与受保护会话配置之后拒绝期限放宽(静态核对顺序)', () => {
|
|
74
|
+
const host = fs.readFileSync(path.join(here, 'cm-ai-host.mjs'), 'utf8');
|
|
75
|
+
const load = host.indexOf('const externalModels=readLaunchExternalModels('), guard = host.indexOf("refuse(callTimeoutMs===null||!externalModels||argv[4]==='resume'");
|
|
76
|
+
assert.ok(load > 0 && guard > load);
|
|
77
|
+
assert.match(host, /refuse\(callTimeoutMs===null\|\|!protection,/);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test('恢复时期限不得低于创建时的值:缩短(含漏传)按参数名拒绝', () => {
|
|
81
|
+
const base = {root: '/r', timeoutMs: 3600000, developer: {provider: 'claude', requestedModel: 'current-session', contextId: 'c'}};
|
|
82
|
+
assert.doesNotThrow(() => sameRunnerConfig(base, base));
|
|
83
|
+
assert.throws(() => sameRunnerConfig(base, {...base, timeoutMs: 1800000}),
|
|
84
|
+
error => error.code === 'invalid_arguments' && /此运行已用 60 分钟,本次为 30 分钟/.test(error.reason));
|
|
85
|
+
});
|
|
@@ -171,6 +171,24 @@ test('real v2 CLI publishes a launch target, refuses a stale target and rebinds
|
|
|
171
171
|
assert.equal(f.snapshot().records.find(row=>row.payload.type==='specification-rebound').payload.record.reason,reason);
|
|
172
172
|
});
|
|
173
173
|
|
|
174
|
+
test('v2 run created without --call-timeout-minutes resumes with 60 (device checks that hit the 30 minute call limit)',t=>{
|
|
175
|
+
const f=fixture(t),config=path.join(f.root,'run.json'),control=path.join(f.root,'control.json'),
|
|
176
|
+
review=path.join(f.root,'review.json'),workflow=path.join(f.root,'workflow.json');
|
|
177
|
+
fs.writeFileSync(config,JSON.stringify(f.definition));fs.writeFileSync(control,JSON.stringify(policy));
|
|
178
|
+
fs.writeFileSync(workflow,JSON.stringify(f.execution.configuration.workflow));
|
|
179
|
+
fs.writeFileSync(review,JSON.stringify({model:'fixture',preflight:{passed:true,cli_model:'fixture',prompt_transport:'stdin',
|
|
180
|
+
config_fingerprint:configFingerprint({cwd:f.codeProject,model:'fixture'})}}));
|
|
181
|
+
const serve=(mode,extra=[])=>spawnSync(process.execPath,[cli,'serve','--config',config,'--mode',mode,'--host-context','main',
|
|
182
|
+
'--control-config',control,'--review-config',review,'--workflow-config',workflow,...extra],
|
|
183
|
+
{encoding:'utf8',timeout:20000,input:JSON.stringify({version:2,requestId:'status',operation:'status',identity:f.identity})+'\n',
|
|
184
|
+
env:{...process.env,CM_WORKFLOW_HOME:path.join(f.root,'home'),CM_WORKFLOW_LOG_HOME:path.join(f.root,'logs')}});
|
|
185
|
+
const created=serve('create');assert.equal(created.status,0,created.stderr);
|
|
186
|
+
const before=f.snapshot().fingerprints;
|
|
187
|
+
const resumed=serve('resume',['--call-timeout-minutes','60']);assert.equal(resumed.status,0,resumed.stderr);
|
|
188
|
+
assert.deepEqual(f.snapshot().fingerprints,before,'the call timeout never enters the run fingerprint');
|
|
189
|
+
const refused=serve('resume',['--call-timeout-minutes','61']);assert.equal(refused.status,1);assert.match(refused.stderr,/invalid_arguments/);
|
|
190
|
+
});
|
|
191
|
+
|
|
174
192
|
test('v2 argv requires target for startup recovery and refuses external allow flags or create supersession',t=>{
|
|
175
193
|
const f=fixture(t),config=path.join(f.root,'run.json'),control=path.join(f.root,'control.json');
|
|
176
194
|
fs.writeFileSync(config,JSON.stringify(f.definition));fs.writeFileSync(control,JSON.stringify(policy));
|