@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
package/scripts/cm-ai-drive.mjs
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import {SYMLINK_BASELINE_VERSION,assertDisjointEditPaths,assertRealParents,lstatOrMissing,readSymlinkRecord,resolveSymlinkTarget,
|
|
3
|
+
projectedPathStat,symlinkRecord,validateSymlinkTargetText} from '../runtime/js/cm-ai/symlink-material.mjs';
|
|
2
4
|
import {packageMaterialEligible,checkpointPackageBudget,INLINE_PACKAGE_LIMIT} from '../runtime/js/cm-ai/checkpoint-package-material.mjs';
|
|
3
5
|
// cm-ai host 的单步驾驶员。PLAN 路径相对 PLAN 文件;命令仅在 codeProject 内执行。
|
|
4
6
|
// 请求表来自 host-session.mjs operationNames(传输允许集)、host-conversation-execution.mjs
|
|
@@ -36,7 +38,7 @@ import {packageMaterialEligible,checkpointPackageBudget,INLINE_PACKAGE_LIMIT} fr
|
|
|
36
38
|
import fs from 'node:fs';
|
|
37
39
|
import {readLaunchExecutionPolicy} from '../runtime/js/cm-ai/execution-policy.mjs';
|
|
38
40
|
import path from 'node:path';
|
|
39
|
-
import {createHash} from 'node:crypto';
|
|
41
|
+
import {createHash,randomUUID} from 'node:crypto';
|
|
40
42
|
import {fileURLToPath} from 'node:url';
|
|
41
43
|
import {createHostCheck,reportHostCheckProgress} from '../runtime/js/cm-ai/host-check.mjs';
|
|
42
44
|
import {readQaAssessment} from '../runtime/js/cm-ai/host-qa-policy.mjs';
|
|
@@ -49,6 +51,7 @@ import {REVIEW_MATERIAL_LIMITS,captureReviewBaseline,reviewMaterialSizes,project
|
|
|
49
51
|
import {JOURNAL_PAYLOAD_LIMIT,developCheckpointReserve,taskReviewScope} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
50
52
|
import {reviewPaths} from '../runtime/js/cm-ai/review-runner.mjs';
|
|
51
53
|
import {hostHandoffDocument} from '../runtime/js/cm-ai/host-handoff.mjs';
|
|
54
|
+
import {projectedImplementationSha256} from './cm-task-gate.mjs';
|
|
52
55
|
import {taskLearningHandoffBytes} from '../runtime/js/cm-ai/cm-ai-learning-handoff-writer.mjs';
|
|
53
56
|
import {projectLearningWriteback} from '../runtime/js/cm-ai/cm-ai-learning-writer.mjs';
|
|
54
57
|
import {inspectCmAiTaskLearningInput,createCmAiTaskLearningApplication,
|
|
@@ -92,7 +95,7 @@ const FILES={develop:'develop.json',qa_assess:'qa-assess.json',documentation_ins
|
|
|
92
95
|
documentation_sync:'documentation-sync.json',fix_learning:'learning.json',fix_diagnose:'diagnosis.json',
|
|
93
96
|
fix_test_author:'test-edits.json',fix_repair:'repair-edits.json',fix_retrospective:'retrospective.json'};
|
|
94
97
|
const PAIR_FLAGS=new Set(['--integration-evidence','--accept-integration-digest','--expected-control','--revise-scope','--scope-revision-reason','--development-rework-reason','--external-models-config','--review-config','--workflow-config',
|
|
95
|
-
'--input-limit',
|
|
98
|
+
'--input-limit','--call-timeout-minutes',
|
|
96
99
|
'--protected-conversation-config','--protected-config','--revise-qa-config','--qa-config-revision-reason','--qa-environment-failure',
|
|
97
100
|
'--qa-fix-owner-config','--qa-fix-template-config','--qa-fix-review-config','--browser-qa',
|
|
98
101
|
'--bootstrap-config','--allow-provider-development-attempt','--supersede-reason','--supersede-target','--spec-rebind-reason',
|
|
@@ -179,10 +182,11 @@ export const developFilename=(root,attempt)=>attemptAnswerName(root,'develop',at
|
|
|
179
182
|
// "content-file" write these bytes (existing mode kept, new file 0644)
|
|
180
183
|
// {file:"content-file",mode} write, then set mode
|
|
181
184
|
// {mode:"0755"|"0644"} only change the permission bits of an existing file
|
|
182
|
-
// {delete:true} delete an existing file
|
|
185
|
+
// {delete:true} delete an existing file or link
|
|
186
|
+
// {symlink:"relative-target"} create or retarget a link in a new run
|
|
183
187
|
// A rename is a delete of the old path plus a write of the new one, both in scope.
|
|
184
188
|
const DEVELOP_MODES=new Map([['0644',0o644],['0755',0o755]]);
|
|
185
|
-
const answerError=message=>Object.assign(new Error(message),{answerShape:true});
|
|
189
|
+
const answerError=(message,code)=>Object.assign(new Error(message),{answerShape:true,...(code?{code}:{})});
|
|
186
190
|
function safeContentFile(local,root,label){
|
|
187
191
|
if(!(typeof local==='string'&&local.length>0&&!path.isAbsolute(local)&&!local.split(/[\\/]/).includes('..')))
|
|
188
192
|
throw answerError(`${label} 路径无效`);
|
|
@@ -195,14 +199,19 @@ export function readDevelopEntry(target,entry,root,label='develop.json.edits'){
|
|
|
195
199
|
if(!nonempty(target))throw answerError(`${label} 路径无效`);
|
|
196
200
|
if(typeof entry==='string')return {kind:'write',local:safeContentFile(entry,root,label)};
|
|
197
201
|
const at=`${label}.${target}`;
|
|
198
|
-
if(!object(entry))throw answerError(`${at} 应为内容文件名,或 {file,mode} / {mode} / {delete:true}`);
|
|
202
|
+
if(!object(entry))throw answerError(`${at} 应为内容文件名,或 {file,mode} / {mode} / {delete:true} / {symlink}`);
|
|
199
203
|
const keys=Object.keys(entry).sort().join(',');
|
|
200
204
|
if(Object.hasOwn(entry,'delete')){
|
|
201
205
|
if(keys!=='delete')throw answerError(`${at}: delete 不能与 file、mode 同时出现`);
|
|
202
206
|
if(entry.delete!==true)throw answerError(`${at}.delete 只能是 true`);
|
|
203
207
|
return {kind:'delete'};
|
|
204
208
|
}
|
|
205
|
-
if(
|
|
209
|
+
if(keys==='symlink'){
|
|
210
|
+
try{validateSymlinkTargetText(entry.symlink);}
|
|
211
|
+
catch(error){throw answerError(`${at}.symlink 须为有效的相对目标,且最多 1024 字节(${error.code})`,error.code);}
|
|
212
|
+
return {kind:'symlink',target:entry.symlink};
|
|
213
|
+
}
|
|
214
|
+
if(!['file','file,mode','mode'].includes(keys))throw answerError(`${at} 只允许单独的 symlink、delete、mode,或 file 与可选的 mode`);
|
|
206
215
|
if(Object.hasOwn(entry,'mode')&&!DEVELOP_MODES.has(entry.mode))throw answerError(`${at}.mode 只能是字符串 "0644" 或 "0755"`);
|
|
207
216
|
return Object.hasOwn(entry,'file')?{kind:'write',local:safeContentFile(entry.file,root,label),
|
|
208
217
|
...(Object.hasOwn(entry,'mode')?{mode:entry.mode}:{})}:{kind:'mode',mode:entry.mode};
|
|
@@ -219,42 +228,98 @@ function protectedText(bytes,target){
|
|
|
219
228
|
try{return strictUtf8.decode(bytes);}
|
|
220
229
|
catch{throw answerError(`${target} 不是合法 UTF-8 文本;受保护模式只能提交 UTF-8 文本,二进制文件(图片、证书等)请移出 scope 或改用非受保护模式`);}
|
|
221
230
|
}
|
|
222
|
-
export function protectedDevelopEdits(map,answersRoot,codeProject,expected){
|
|
223
|
-
|
|
231
|
+
export function protectedDevelopEdits(map,answersRoot,codeProject,expected,options={}){
|
|
232
|
+
const entries=developEntries(map,answersRoot,'develop.json.edits');
|
|
233
|
+
const before=checkDevelopEntries(entries,codeProject,options);
|
|
234
|
+
return entries.map(([target,entry])=>{
|
|
235
|
+
|
|
224
236
|
const beforeSha256=expected?.[target]??null;
|
|
225
237
|
if(entry.kind==='delete')return {path:target,beforeSha256,content:null};
|
|
238
|
+
if(entry.kind==='symlink')return {path:target,beforeSha256,symlink:entry.target};
|
|
239
|
+
if(entry.kind==='mode'&&before.get(target)===null)throw answerError(`${target} 不存在,无法改权限`);
|
|
226
240
|
const source=entry.kind==='mode'?path.join(codeProject,target):answerPath(answersRoot,entry.local);
|
|
227
241
|
return {path:target,beforeSha256,content:protectedText(fs.readFileSync(source),target),
|
|
228
242
|
...(entry.mode?{mode:entry.mode}:{})};
|
|
229
243
|
});
|
|
230
244
|
}
|
|
231
|
-
|
|
232
|
-
|
|
245
|
+
function checkDevelopEntries(entries,codeProject,options){
|
|
246
|
+
if(options.allowSymlinks)assertDisjointEditPaths(entries.map(([file])=>file));
|
|
247
|
+
const before=new Map();
|
|
248
|
+
const removed=new Set(entries.filter(([,entry])=>['delete','symlink'].includes(entry.kind)).map(([file])=>file));
|
|
233
249
|
for(const [target,entry] of entries){
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
if(!file.startsWith(codeProject+path.sep))throw Error('编辑路径越界');
|
|
237
|
-
for(let parent=path.dirname(file);parent!==codeProject;parent=path.dirname(parent))
|
|
238
|
-
if(fs.existsSync(parent)&&fs.lstatSync(parent).isSymbolicLink())throw Error('编辑路径经过符号链接');
|
|
239
|
-
if(fs.existsSync(file)&&fs.lstatSync(file).isSymbolicLink())throw Error('编辑路径是符号链接');
|
|
240
|
-
if(entry.kind!=='write'&&!(fs.existsSync(file)&&fs.lstatSync(file).isFile()))throw Error(`${target} 不存在,无法删除或改权限`);
|
|
250
|
+
const prior=diskScopeEntry(codeProject,target);before.set(target,prior);
|
|
251
|
+
checkDevelopEntry(codeProject,target,entry,prior,{...options,removed});
|
|
241
252
|
}
|
|
253
|
+
return before;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function checkDevelopEntry(codeProject,file,entry,before,{allowSymlinks=false,specsRoot=null,codeProjects=null,removed,
|
|
257
|
+
stat=relative=>lstatOrMissing(path.join(codeProject,relative))}){
|
|
258
|
+
assertRealParents(codeProject,file,stat);
|
|
259
|
+
if(before?.type==='symlink'&&(!allowSymlinks||!['delete','symlink'].includes(entry.kind)))
|
|
260
|
+
throw Object.assign(new Error('编辑路径是符号链接'),{code:'unsupported_path'});
|
|
261
|
+
if(allowSymlinks&&before?.unsupported)throw answerError(`${file}: 只能替换普通文件或软链`);
|
|
262
|
+
if(entry.kind==='symlink'){
|
|
263
|
+
if(!allowSymlinks)throw answerError(`${file}: 当前运行的基线版本不支持新建或改指软链`);
|
|
264
|
+
const cwd=codeProjects?.find(root=>path.join(codeProject,file).startsWith(root+path.sep))??codeProject;
|
|
265
|
+
const prefix=cwd===codeProject?'':path.relative(codeProject,cwd).split(path.sep).join('/')+'/';
|
|
266
|
+
resolveSymlinkTarget(cwd,file.slice(prefix.length),entry.target,{specsRoot,
|
|
267
|
+
stat:relative=>removed.has(prefix+relative)?null:stat(prefix+relative)});
|
|
268
|
+
}else if(entry.kind!=='write'&&(before===null||before?.unsupported))
|
|
269
|
+
throw answerError(`${file} 不存在或类型不受支持,无法删除或改权限`);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
export function applyDevelopEdits(map,answersRoot,codeProject,allowed,options={}){
|
|
273
|
+
const entries=developEntries(map,answersRoot,'develop.json.edits');
|
|
274
|
+
for(const [target] of entries)if(!allowed.includes(target))throw Error(`${target} 不在宿主允许的范围`);
|
|
275
|
+
const before=checkDevelopEntries(entries,codeProject,options);
|
|
276
|
+
const removed=new Set(entries.filter(([,entry])=>['delete','symlink'].includes(entry.kind)).map(([file])=>file));
|
|
242
277
|
for(const [target,entry] of entries){
|
|
243
|
-
const
|
|
278
|
+
const prior=before.get(target),current=diskScopeEntry(codeProject,target);
|
|
279
|
+
if(JSON.stringify(prior)!==JSON.stringify(current))throw Error(`${target} 已变化,拒绝覆盖`);
|
|
280
|
+
checkDevelopEntry(codeProject,target,entry,current,{...options,removed});
|
|
281
|
+
const file=path.join(codeProject,target),directory=path.dirname(file);
|
|
244
282
|
if(entry.kind==='delete'){fs.unlinkSync(file);continue;}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
283
|
+
fs.mkdirSync(directory,{recursive:true});
|
|
284
|
+
assertRealParents(codeProject,target);
|
|
285
|
+
if(options.allowSymlinks&&JSON.stringify(diskScopeEntry(codeProject,target))!==JSON.stringify(prior))
|
|
286
|
+
throw Error(`${target} 已变化,拒绝覆盖`);
|
|
287
|
+
if(entry.kind==='symlink'){
|
|
288
|
+
if(prior===null){fs.symlinkSync(entry.target,file);continue;}
|
|
289
|
+
const temporary=path.join(directory,'.cm-link-'+randomUUID());
|
|
290
|
+
fs.symlinkSync(entry.target,temporary);
|
|
291
|
+
try{
|
|
292
|
+
if(JSON.stringify(diskScopeEntry(codeProject,target))!==JSON.stringify(prior))throw Error(`${target} 已变化,拒绝覆盖`);
|
|
293
|
+
fs.renameSync(temporary,file);
|
|
294
|
+
}finally{if(lstatOrMissing(temporary))fs.unlinkSync(temporary);}
|
|
295
|
+
continue;
|
|
296
|
+
}
|
|
297
|
+
const flags=entry.kind==='mode'?fs.constants.O_RDONLY:fs.constants.O_WRONLY
|
|
298
|
+
|(prior===null?fs.constants.O_CREAT|fs.constants.O_EXCL:fs.constants.O_TRUNC);
|
|
299
|
+
const fd=fs.openSync(file,flags|fs.constants.O_NOFOLLOW,0o644);
|
|
300
|
+
try{
|
|
301
|
+
if(entry.kind==='write')fs.writeFileSync(fd,fs.readFileSync(answerPath(answersRoot,entry.local)));
|
|
302
|
+
if(entry.mode||prior===null)fs.fchmodSync(fd,entry.mode?DEVELOP_MODES.get(entry.mode):0o644);
|
|
303
|
+
}finally{fs.closeSync(fd);}
|
|
249
304
|
}
|
|
250
305
|
}
|
|
251
306
|
const sha256=bytes=>createHash('sha256').update(bytes).digest('hex');
|
|
252
307
|
function diskScopeEntry(codeProject,target){
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
if(
|
|
256
|
-
return
|
|
257
|
-
|
|
308
|
+
assertRealParents(codeProject,target);
|
|
309
|
+
const file=path.join(codeProject,target),stat=lstatOrMissing(file);
|
|
310
|
+
if(stat===null)return null;
|
|
311
|
+
if(stat.isSymbolicLink())return readSymlinkRecord(codeProject,target);
|
|
312
|
+
if(!stat.isFile()||stat.nlink!==1)return {unsupported:true};
|
|
313
|
+
let hash=null;
|
|
314
|
+
if(stat.size<=REVIEW_MATERIAL_LIMITS.file){
|
|
315
|
+
const fd=fs.openSync(file,fs.constants.O_RDONLY|fs.constants.O_NOFOLLOW);
|
|
316
|
+
try{
|
|
317
|
+
const opened=fs.fstatSync(fd);
|
|
318
|
+
if(opened.dev!==stat.dev||opened.ino!==stat.ino||opened.nlink!==1)throw Error(`${target} 已变化,无法读取预期指纹`);
|
|
319
|
+
hash=sha256(fs.readFileSync(fd));
|
|
320
|
+
}finally{fs.closeSync(fd);}
|
|
321
|
+
}
|
|
322
|
+
return {size:stat.size,mode:stat.mode&0o7777,source:file,sha256:hash};
|
|
258
323
|
}
|
|
259
324
|
const kib=bytes=>`${bytes} 字节`;
|
|
260
325
|
// Most of what the runner would refuse only after the answer is written and the
|
|
@@ -287,7 +352,7 @@ export function developPreview({definition,codeProject=definition.codeProject,jo
|
|
|
287
352
|
if(baseline===null){
|
|
288
353
|
// The same baseline the runner captures (taskReviewScope, specsRoot, specification).
|
|
289
354
|
baseline=captureReviewBaseline({root:codeProject,specsRoot:definition.specsDir,identity:definition.identity,
|
|
290
|
-
scope:taskReviewScope(definition.scope),requirements:definition.requirements,specification:{specsRoot:definition.specsDir,feature:definition.feature},
|
|
355
|
+
scope:taskReviewScope(definition.scope),requirements:definition.requirements,version:SYMLINK_BASELINE_VERSION,specification:{specsRoot:definition.specsDir,feature:definition.feature},
|
|
291
356
|
...(definition.codeProjects?{codeProjectPaths:codeProjectPaths(codeProject,resolveCodeProjects(codeProject,definition.codeProjects))}:{})});
|
|
292
357
|
// The new run journals this baseline as one record, next to its own metadata.
|
|
293
358
|
const bytes=Buffer.byteLength(JSON.stringify(baseline));
|
|
@@ -309,9 +374,8 @@ export function developPreview({definition,codeProject=definition.codeProject,jo
|
|
|
309
374
|
}
|
|
310
375
|
// The package the runner will build for this delivery, byte for byte: the same
|
|
311
376
|
// Learning records, AGENTS.md writeback, handoff and package assembly, applied to
|
|
312
|
-
// the projected scope files.
|
|
313
|
-
//
|
|
314
|
-
// build a package from it at all (blocked outcome, pending writeback, no change).
|
|
377
|
+
// the projected scope files. V3 binds the projected implementation bytes.
|
|
378
|
+
// Returns null for outcomes that would not produce a review package.
|
|
315
379
|
export function projectDevelopCheckpoint({preview,codeProject,attempt,value,projected,checks}){
|
|
316
380
|
const {definition}=preview,identity={...definition.identity,attempt};
|
|
317
381
|
if(value.value?.outcome!=='implemented')return null;
|
|
@@ -336,7 +400,9 @@ export function projectDevelopCheckpoint({preview,codeProject,attempt,value,proj
|
|
|
336
400
|
let initial;
|
|
337
401
|
try{initial=projectedReviewPackage({root:codeProject,baseline,checks,scopeFiles});}
|
|
338
402
|
catch(error){if(['empty_changes','out_of_scope','read_failed'].includes(error.code))return null;throw error;}
|
|
339
|
-
const
|
|
403
|
+
const implementationSha256=baseline.version===SYMLINK_BASELINE_VERSION
|
|
404
|
+
?projectedImplementationSha256(initial.changes):'0'.repeat(64);
|
|
405
|
+
const {payload}=hostHandoffDocument({baseline,checks,reviewPackage:initial,implementationSha256});
|
|
340
406
|
const handoff=taskLearningHandoffBytes({handoff:payload,feature:definition.feature,identity,learningInput,
|
|
341
407
|
application,retrospective,includeAgents});
|
|
342
408
|
const pkg=projectedReviewPackage({root:codeProject,baseline,checks,scopeFiles,handoff:{
|
|
@@ -349,11 +415,20 @@ export function projectDevelopCheckpoint({preview,codeProject,attempt,value,proj
|
|
|
349
415
|
export const plannedCheckResults=commands=>(Array.isArray(commands)&&commands.length?commands:[{id:'check',command:['check']}])
|
|
350
416
|
.map(({id,command})=>({id,command,outcome:'passed',exitCode:0,evidence:'host check exited 0'}));
|
|
351
417
|
export function preflightDevelopDeliveries({deliveries,answersRoot,codeProject,scope,requirements,
|
|
352
|
-
baseline='disk',diskChecks=true,protectedMode=false,inputLimit=65536,preview=null,checks=plannedCheckResults(null)
|
|
418
|
+
baseline='disk',diskChecks=true,protectedMode=false,inputLimit=65536,preview=null,checks=plannedCheckResults(null),
|
|
419
|
+
specsRoot=preview?.definition?.specsDir??null,codeProjects=preview?.definition?.codeProjects??null,
|
|
420
|
+
allowSymlinks=preview?.baseline?.version===SYMLINK_BASELINE_VERSION}){
|
|
353
421
|
const {file:FILE,total:TOTAL,count:COUNT}=REVIEW_MATERIAL_LIMITS;
|
|
354
422
|
let material=diskChecks&&preview?new Map(preview.material.map(item=>[item.path,item.size])):null;
|
|
355
423
|
const projected=new Map();
|
|
356
|
-
let previous=diskChecks?new Map(scope.map(target=>
|
|
424
|
+
let previous=diskChecks?new Map(scope.map(target=>{
|
|
425
|
+
try{return [target,diskScopeEntry(codeProject,target)];}
|
|
426
|
+
catch(error){
|
|
427
|
+
const reason={unsupported_path:'路径无效或父级经过软链或非目录',
|
|
428
|
+
unsupported_file:'软链目标不是有效的 UTF-8'}[error.code];
|
|
429
|
+
stop(2,`无法读取任务范围 ${target}:${reason?`${reason}(${error.code})`:error.code??error.message}`);
|
|
430
|
+
}
|
|
431
|
+
})):null;
|
|
357
432
|
const base=!diskChecks?null:baseline==='disk'?previous:baseline;
|
|
358
433
|
// Without the tree (a later batch task), the scope files the answers write are
|
|
359
434
|
// still known to exist in the review material with exactly these sizes; the
|
|
@@ -367,14 +442,32 @@ export function preflightDevelopDeliveries({deliveries,answersRoot,codeProject,s
|
|
|
367
442
|
for(const {file,value,attempt=1} of deliveries){
|
|
368
443
|
if(value.status!=='succeeded')continue;
|
|
369
444
|
const label=path.basename(file);let entries;
|
|
370
|
-
try{
|
|
445
|
+
try{
|
|
446
|
+
entries=developEntries(value.edits,answersRoot,`${label}.edits`);
|
|
447
|
+
if(allowSymlinks)assertDisjointEditPaths(entries.map(([file])=>file));
|
|
448
|
+
}catch(error){stop(2,`答案格式错误:${error.message}`);}
|
|
371
449
|
const next=previous&&new Map(previous);
|
|
450
|
+
const removed=new Set(entries.filter(([,entry])=>['delete','symlink'].includes(entry.kind)).map(([file])=>file));
|
|
451
|
+
// Earlier deliveries are already applied when this round runs. The
|
|
452
|
+
// current delivery still needs its targets to exist before it writes.
|
|
453
|
+
const stat=previous&&allowSymlinks?projectedPathStat(codeProject,new Map([...previous]
|
|
454
|
+
.filter(([,state])=>!state?.unsupported).map(([file,state])=>[file,state===null?null:state.type??'file']))):undefined;
|
|
372
455
|
for(const [target,entry] of entries){
|
|
373
456
|
const before=previous?.get(target)??null;
|
|
374
457
|
// Scope and requirements may overlap; every review package must still carry
|
|
375
458
|
// each requirement file, so a delivery cannot delete one.
|
|
376
|
-
if(entry.kind
|
|
459
|
+
if(['delete','symlink'].includes(entry.kind)&&requirements.includes(target))
|
|
377
460
|
stop(2,`${label}.edits.${target}: 该路径同时列在运行定义的 requirements 中,审查包要求它存在,不能删除;可改写其内容,或先在新运行定义里把它移出 requirements`);
|
|
461
|
+
if(diskChecks){
|
|
462
|
+
try{checkDevelopEntry(codeProject,target,entry,before,{allowSymlinks,specsRoot,codeProjects,removed,stat});}
|
|
463
|
+
catch(error){stop(2,`${label}.edits.${target}: ${error.message}`);}
|
|
464
|
+
}
|
|
465
|
+
if(entry.kind==='symlink'){
|
|
466
|
+
if(!allowSymlinks)stop(2,`${label}.edits.${target}: 当前运行的基线版本不支持软链`);
|
|
467
|
+
const row=symlinkRecord(target,entry.target);
|
|
468
|
+
next?.set(target,row);delivered?.set(target,row.size);
|
|
469
|
+
continue;
|
|
470
|
+
}
|
|
378
471
|
if(entry.kind!=='write'){
|
|
379
472
|
if(entry.kind==='delete')delivered?.delete(target);
|
|
380
473
|
if(previous&&(before===null||before.unsupported))
|
|
@@ -392,8 +485,10 @@ export function preflightDevelopDeliveries({deliveries,answersRoot,codeProject,s
|
|
|
392
485
|
const edits=[];
|
|
393
486
|
try{
|
|
394
487
|
for(const [target,entry] of entries){
|
|
488
|
+
if(entry.kind==='symlink'){edits.push({path:target,beforeSha256:'0'.repeat(64),symlink:entry.target});continue;}
|
|
395
489
|
if(entry.kind==='delete'){edits.push({path:target,beforeSha256:'0'.repeat(64),content:null});continue;}
|
|
396
490
|
const source=entry.kind==='write'?answerPath(answersRoot,entry.local):previous?.get(target)?.source??path.join(codeProject,target);
|
|
491
|
+
if(!diskChecks&&allowSymlinks&&entry.kind==='mode')continue;
|
|
397
492
|
if(!fs.existsSync(source))continue;
|
|
398
493
|
edits.push({path:target,beforeSha256:'0'.repeat(64),content:protectedText(fs.readFileSync(source),target),
|
|
399
494
|
...(entry.mode?{mode:entry.mode}:{})});
|
|
@@ -433,6 +528,7 @@ export function preflightDevelopDeliveries({deliveries,answersRoot,codeProject,s
|
|
|
433
528
|
for(const [target] of entries){
|
|
434
529
|
const after=next.get(target);
|
|
435
530
|
projected.set(target,after===null?{path:target,contentBase64:null,mode:null}
|
|
531
|
+
:after.type==='symlink'?{path:target,symlink:after.target}
|
|
436
532
|
:{path:target,contentBase64:fs.readFileSync(after.source).toString('base64'),mode:after.mode});
|
|
437
533
|
}
|
|
438
534
|
const projection=preview.exact?projectDevelopCheckpoint({preview,codeProject,attempt,value,projected,checks}):null;
|
|
@@ -469,7 +565,7 @@ export function preflightDevelopDeliveries({deliveries,answersRoot,codeProject,s
|
|
|
469
565
|
export function baselineScope(baseline,scope){
|
|
470
566
|
const files=new Map((baseline?.files??[]).map(file=>[file.path,file]));
|
|
471
567
|
return new Map(scope.map(target=>{const file=files.get(target);
|
|
472
|
-
return [target,file?{size:file.size,mode:file.mode,sha256:file.sha256}:null];}));
|
|
568
|
+
return [target,file?{size:file.size,mode:file.mode,sha256:file.sha256,...(file.type==='symlink'?{type:file.type,target:file.target}:{})}:null];}));
|
|
473
569
|
}
|
|
474
570
|
export const inputLimitFrom=permissions=>{
|
|
475
571
|
const at=permissions.indexOf('--input-limit');
|
|
@@ -606,7 +702,7 @@ function load(){
|
|
|
606
702
|
if(process.argv.length===3&&['--help','-h'].includes(process.argv[2])){
|
|
607
703
|
process.stdout.write('新版 PLAN.controlConfig 为相对 PLAN 的 v2 控制配置路径;development、bootstrap、qa、qaFix 使用明确模式,permissions 禁止所有 --allow-*。普通 advance 自动独立审查;缺少 develop-a2.json 时保持 revision_answer_required。显式恢复需要 resume 与此前 status 返回的 PLAN.expectedControl,驾驶员不会读取新目标覆盖它。\n');
|
|
608
704
|
process.stdout.write('用法: cm-ai-drive.mjs --plan PLAN.json <operation>\nPLAN: config, mode, hostContext, originalHostContext (换会话 resume 必填), runtime, permissions, answers, checks, checkTimeoutMs。\nchecks 每项为 {id,command,timeoutMs?};checkTimeoutMs 与每项 timeoutMs 为 1..3600000 整数,默认 900000 ms(15 分钟)。\nabandon_review 需要 mode:resume、permissions:["--allow-abandon-review"] 与 PLAN.reason;abandon_effect 需要 mode:resume、permissions:["--allow-abandon-effect"] 与 PLAN.reason(均为单行、最多 500 UTF-8 字节)。develop_redo 需要 mode:resume、permissions:["--allow-develop-redo"] 与 PLAN.reason,先确认会话已停止修改代码。 bootstrap_review_recover 需要 mode:resume、permissions:["--allow-bootstrap-review-recovery"] 与 PLAN.reason;只核对原运行的已写规则与 handoff,不需要答案文件。\n人工答案放 answers/;check 只运行 PLAN.checks,不读取静态执行证据。bootstrap T-001 骨架可用;T-002 规范任务(纯规范 scope、单代码根、非 --protected-config)读 answers/init-generate.json({status:"generated",documents:[{path,contentFile}]},覆盖全部 targets)与 answers/init-verify.json(commands 为驾驶员实跑的草稿命令 {id,command,timeoutMs?},可选 commandsNotRun;checks 只含 globs/file_references/constraint_preservation/rule_applicability;constraintChanges:[];application/retrospective 沿原 Learning);第 1 轮也可用 *-a1.json,第 2 轮只读 init-generate-a2.json 与 init-verify-a2.json,审查自动派发;缺少第2轮草稿时先停在 changes_requested,读取首轮 findings 后再写草稿。commands 在宿主接受启动后、发送操作前由驾驶员实跑(须先带 --allow-bootstrap-write 等宿主授权;受保护模式在 specs 沙箱内),失败或改动了预检核对的文件即退出 2 且不发送操作(create 时改用 resume 重跑);结果只来自实跑,答案文件不能提供。\n'
|
|
609
|
-
+'develop.json.edits 每项是 scope 路径到下列之一:"内容文件"(写入;已有文件保留权限,新文件 0644)、{"file":"内容文件","mode":"0755"|"0644"}、{"mode":"0755"|"0644"}(只改已有文件权限)、{"delete":true}
|
|
705
|
+
+'develop.json.edits 每项是 scope 路径到下列之一:"内容文件"(写入;已有文件保留权限,新文件 0644)、{"file":"内容文件","mode":"0755"|"0644"}、{"mode":"0755"|"0644"}(只改已有文件权限)、{"delete":true}(删除已有文件或软链)、{"symlink":"相对目标"}(仅新运行可新建或改指软链)。改名的旧路径和新路径都要在 scope 内。requirements 路径须保留普通文件。\n'
|
|
610
706
|
+'启动前拒绝:单个 scope 文件超过 1 MiB、审查材料(按审查包快照:scope、requirements 与树中全部 AGENTS.md 正文)合计超过 2 MiB 或超过 256 个文件、交付后与任务基线完全相同(edits 为空或内容和权限都没变)、开发检查点(含 handoff 与 AGENTS.md 回写,按宿主同一套构建代码计)超出存档上限(开发检查点的内联预算为单条记录上限(默认 4 MiB)与 1 MiB 取较小值后减去为有界审查与完成记录推出的预留,最低为 0 字节;不支持材料归档的运行(批量、并行、bootstrap 等)按含 base64 审查包的完整检查点核算此预算;支持归档的运行若同一审查包已有归档则直接引用,并要求完整检查点减去审查包大小再加 512 字节后不超过单条记录上限减去预留;若尚未归档且完整检查点装得进内联预算则内联;否则仅在完整检查点加 1 KiB 仍不超过单条记录上限、且引用后的估算大小也符合上述引用预算时首次归档),或任务基线装不进一条记录。受保护模式(--protected-conversation-config)只收合法 UTF-8 文本,应答大于 --input-limit(默认 65536)时提示应加的值。\n'
|
|
611
707
|
+'runId 需 8–128 个字符(运行日志要求),create 前检查。resume 时按存档里的当前轮次发送 identity,第 2 轮的 decision/complete/qa 等无需手改。\n');
|
|
612
708
|
process.exit(0);
|
|
@@ -711,7 +807,7 @@ function load(){
|
|
|
711
807
|
for(let i=0;i<permissions.length;i++)if(PAIR_FLAGS.has(permissions[i])
|
|
712
808
|
&&permissions[i]!=='--browser-qa'&&permissions[i]!=='--accept-integration-digest'
|
|
713
809
|
&&permissions[i]!=='--scope-revision-reason'&&permissions[i]!=='--development-rework-reason'&&permissions[i]!=='--qa-config-revision-reason'&&permissions[i]!=='--qa-environment-failure'&&permissions[i]!=='--allow-provider-development-attempt'
|
|
714
|
-
&&permissions[i]!=='--supersede-reason'&&permissions[i]!=='--spec-rebind-reason'&&permissions[i]!=='--input-limit'
|
|
810
|
+
&&permissions[i]!=='--supersede-reason'&&permissions[i]!=='--spec-rebind-reason'&&permissions[i]!=='--input-limit'&&permissions[i]!=='--call-timeout-minutes'
|
|
715
811
|
&&permissions[i]!=='--review-runtime'&&permissions[i]!=='--feature'&&permissions[i]!=='--qa-fix-final-review-recovery-invocation'){
|
|
716
812
|
const file=path.resolve(base,permissions[i+1]);if(!fs.existsSync(file))stop(2,`${permissions[i]} 文件不存在: ${file}`);
|
|
717
813
|
permissions[i+1]=file;permissionFiles.push(file);i++;
|
|
@@ -815,7 +911,8 @@ function load(){
|
|
|
815
911
|
if(deliveries.length)preflightDevelopDeliveries({deliveries,answersRoot:answers,codeProject:definition.codeProject,
|
|
816
912
|
scope:definition.scope,requirements:definition.requirements,
|
|
817
913
|
baseline:plan.mode==='create'?'disk':baselineScope(journal.baseline,definition.scope),
|
|
818
|
-
|
|
914
|
+
allowSymlinks:plan.mode==='create'||journal.baseline.version===SYMLINK_BASELINE_VERSION,
|
|
915
|
+
specsRoot:definition.specsDir,codeProjects:definition.codeProjects,protectedMode,inputLimit:inputLimitFrom(permissions),checks:plannedCheckResults(protectedMode?null:plan.checks),
|
|
819
916
|
preview:developPreview({definition,journal:plan.mode==='create'?null:journal,controlPolicy:control?.policy??null,
|
|
820
917
|
exact:!permissions.includes('--bootstrap-config')})});
|
|
821
918
|
const unique=[...new Set(asks.filter(kind=>FILES[kind]&&kind!=='develop'))];
|
|
@@ -893,9 +990,11 @@ async function answerFor(row,answer,paths,control){
|
|
|
893
990
|
if(kind==='develop'){
|
|
894
991
|
if(!value)throw Error(`develop attempt ${row.payload.request?.identity?.attempt??row.payload.identity?.attempt} 未预检,拒绝复用旧答案`);
|
|
895
992
|
if(value.status!=='succeeded')return {status:'failed',code:value.code};
|
|
993
|
+
const editOptions={allowSymlinks:row.payload.allowSymlinks===true,specsRoot:loaded.definition.specsDir,
|
|
994
|
+
codeProjects:row.payload.codeProjects};
|
|
896
995
|
if(row.payload.editMode==='protected-text-v1')return {status:'succeeded',value:value.value,
|
|
897
|
-
edits:protectedDevelopEdits(value.edits,loaded.answers,loaded.definition.codeProject,row.payload.expected)};
|
|
898
|
-
applyDevelopEdits(value.edits,loaded.answers,loaded.definition.codeProject,row.payload.request.payload.scope);
|
|
996
|
+
edits:protectedDevelopEdits(value.edits,loaded.answers,loaded.definition.codeProject,row.payload.expected,editOptions)};
|
|
997
|
+
applyDevelopEdits(value.edits,loaded.answers,loaded.definition.codeProject,row.payload.request.payload.scope,editOptions);
|
|
899
998
|
return {status:'succeeded',value:value.value};
|
|
900
999
|
}
|
|
901
1000
|
if(kind==='documentation_sync'){
|
package/scripts/cm-ai-host.mjs
CHANGED
|
@@ -15,6 +15,7 @@ import {readRunDefinition,openControlRun,createCodexExecution,assertCreatableSco
|
|
|
15
15
|
import {createConversationExecution as executionFor} from '../runtime/js/cm-ai/host-conversation-execution.mjs';
|
|
16
16
|
import {createHostToolBridge,HOST_ANSWER_BACKSTOP_MS} from '../runtime/js/cm-ai/host-tool-bridge.mjs';
|
|
17
17
|
import {serveCmAiHost,parseHostInputLimit,inputLimitReason} from '../runtime/js/cm-ai/host-session.mjs';
|
|
18
|
+
import {parseCallTimeoutMinutes} from '../runtime/js/cm-ai/call-timeout.mjs';
|
|
18
19
|
import {createQaFixOwnerHost} from '../runtime/js/cm-ai/host-qa-fix-owner.mjs';
|
|
19
20
|
import {createFixLearningPreparation} from '../runtime/js/cm-fix/learning.mjs';
|
|
20
21
|
import {createFixReviewHost} from '../runtime/js/cm-fix/host-review.mjs';
|
|
@@ -79,7 +80,7 @@ const fixLocalPermissions=new Map(['red-test','baseline','regression','learning-
|
|
|
79
80
|
'abandon-review','test-author','repair','cause-review','final-review','rediagnosis','rerun-blocked-step','final-review-recovery']
|
|
80
81
|
.map(name=>[`--allow-qa-fix-${name}`,`--allow-${name}`]));
|
|
81
82
|
|
|
82
|
-
const usage='cm-ai-host.mjs serve --config RUN_DEFINITION.json --mode create|resume --host-context ID --allow-development --review-config PATH (required at create; resume passes the same file) [--original-host-context ID] [--runtime codex|claude] [--review-runtime codex|claude] [--feature N.slug] [--input-limit BYTES] [--failover] [--allow-abandon-review] [--allow-abandon-effect] [--allow-bootstrap-review-recovery] [--allow-develop-redo] [--hold-revision] [--workflow-config PATH] [--allow-qa] [--browser-qa available|unavailable]\nInput limit is transport-only: integer 65536-4194304 bytes, default 65536; it bounds every input line and every tool reply, and may change on resume. A longer line stops the session with request_too_large. Review config is {model,preflight[,disabledSkills][,timeoutMs]}; timeoutMs is the reviewer transport budget in milliseconds (integer 1-3600000, default 900000), independent of protected mode and outside the authorized configuration digest. --browser-qa declares interactive QA capability for applicable carriers including browser and ios-simulator.\nNew runs: --external-models [--external-models-config FILE] freezes one pair per actual external provider; resume reads only its snapshot. preflight --config RUN_DEFINITION.json --external-provider codex|claude uses the saved pair.\ncm-ai-host.mjs preflight --config RUN_DEFINITION.json --review-model MODEL [--runtime codex|claude] (synthetic loopback only)';
|
|
83
|
+
const usage='cm-ai-host.mjs serve --config RUN_DEFINITION.json --mode create|resume --host-context ID --allow-development --review-config PATH (required at create; resume passes the same file) [--original-host-context ID] [--runtime codex|claude] [--review-runtime codex|claude] [--feature N.slug] [--input-limit BYTES] [--call-timeout-minutes 30-60] [--failover] [--allow-abandon-review] [--allow-abandon-effect] [--allow-bootstrap-review-recovery] [--allow-develop-redo] [--hold-revision] [--workflow-config PATH] [--allow-qa] [--browser-qa available|unavailable]\nInput limit is transport-only: integer 65536-4194304 bytes, default 65536; it bounds every input line and every tool reply, and may change on resume. A longer line stops the session with request_too_large. Review config is {model,preflight[,disabledSkills][,timeoutMs]}; timeoutMs is the reviewer transport budget in milliseconds (integer 1-3600000, default 900000), independent of protected mode and outside the authorized configuration digest. --browser-qa declares interactive QA capability for applicable carriers including browser and ios-simulator.\nNew runs: --external-models [--external-models-config FILE] freezes one pair per actual external provider; resume reads only its snapshot. preflight --config RUN_DEFINITION.json --external-provider codex|claude uses the saved pair.\ncm-ai-host.mjs preflight --config RUN_DEFINITION.json --review-model MODEL [--runtime codex|claude] (synthetic loopback only)';
|
|
83
84
|
|
|
84
85
|
export function formatClaudeModelHint(config,version=null){
|
|
85
86
|
const marker=config?.preflight?.request_checks?.find(check=>check?.model_recognized===false);
|
|
@@ -232,7 +233,7 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
232
233
|
const extra=new Map();
|
|
233
234
|
for(let index=controlPolicy?9:8;index<argv.length;index++){
|
|
234
235
|
const name=argv[index];refuse(!extra.has(name),'invalid_arguments',`参数重复:${name}`);
|
|
235
|
-
refuse(['--integration-evidence','--accept-integration-digest','--revise-scope','--scope-revision-reason','--development-rework','--development-rework-reason','--expected-control','--execution-optimizations','--external-models','--external-models-config','--verification-precheck','--revise-qa-config','--qa-config-revision-reason','--qa-environment-failure','--supersede-reviewed-evidence','--supersede-reason','--supersede-target','--accept-superseded-code-drift','--rebind-spec-material','--spec-rebind-reason','--original-host-context','--bootstrap-config','--allow-bootstrap-write','--protected-conversation-config','--protected-config','--allow-provider-development-attempt','--review-config','--allow-abandon-review','--allow-abandon-effect','--allow-bootstrap-review-recovery','--allow-develop-redo','--hold-revision','--workflow-config','--allow-qa','--browser-qa','--rerun-unknown-qa','--rerun-blocked-qa','--runtime','--review-runtime','--feature','--input-limit','--failover','--qa-fix-owner-config','--qa-fix-template-config','--qa-fix-review-config','--qa-fix-final-review-recovery-invocation','--allow-qa-fix-start','--auto-qa-fix',...fixLocalPermissions.keys()].includes(name),'invalid_arguments',`未知参数:${name}`);
|
|
236
|
+
refuse(['--integration-evidence','--accept-integration-digest','--revise-scope','--scope-revision-reason','--development-rework','--development-rework-reason','--expected-control','--execution-optimizations','--external-models','--external-models-config','--verification-precheck','--revise-qa-config','--qa-config-revision-reason','--qa-environment-failure','--supersede-reviewed-evidence','--supersede-reason','--supersede-target','--accept-superseded-code-drift','--rebind-spec-material','--spec-rebind-reason','--original-host-context','--bootstrap-config','--allow-bootstrap-write','--protected-conversation-config','--protected-config','--allow-provider-development-attempt','--review-config','--allow-abandon-review','--allow-abandon-effect','--allow-bootstrap-review-recovery','--allow-develop-redo','--hold-revision','--workflow-config','--allow-qa','--browser-qa','--rerun-unknown-qa','--rerun-blocked-qa','--runtime','--review-runtime','--feature','--input-limit','--call-timeout-minutes','--failover','--qa-fix-owner-config','--qa-fix-template-config','--qa-fix-review-config','--qa-fix-final-review-recovery-invocation','--allow-qa-fix-start','--auto-qa-fix',...fixLocalPermissions.keys()].includes(name),'invalid_arguments',`未知参数:${name}`);
|
|
236
237
|
if(['--development-rework','--execution-optimizations','--external-models','--verification-precheck','--supersede-reviewed-evidence','--accept-superseded-code-drift','--rebind-spec-material','--allow-bootstrap-write','--allow-qa','--allow-abandon-review','--allow-abandon-effect','--allow-bootstrap-review-recovery','--allow-develop-redo','--hold-revision','--rerun-unknown-qa','--rerun-blocked-qa','--failover','--allow-qa-fix-start','--auto-qa-fix',...fixLocalPermissions.keys()].includes(name))extra.set(name,true);
|
|
237
238
|
else{refuse(typeof argv[index+1]==='string'&&!argv[index+1].startsWith('--'),'invalid_arguments',`${name} 需要一个值`);extra.set(name,argv[++index]);}
|
|
238
239
|
}
|
|
@@ -282,6 +283,10 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
282
283
|
const reviewedIntegration=integrationRequested?{evidenceFile:path.resolve(extra.get('--integration-evidence')),
|
|
283
284
|
expectedDigest:extra.get('--accept-integration-digest')}:null;
|
|
284
285
|
let inputLimit;
|
|
286
|
+
let callTimeoutMs;
|
|
287
|
+
try{callTimeoutMs=parseCallTimeoutMinutes(extra.get('--call-timeout-minutes'));}
|
|
288
|
+
catch(error){refuse(false,'invalid_arguments',error.message);throw error;}
|
|
289
|
+
refuse(callTimeoutMs===null||!extra.has('--protected-config'),'invalid_arguments','--call-timeout-minutes 只用于当前会话运行;--protected-config 的期限由其配置的 timeoutMs 决定');
|
|
285
290
|
try{inputLimit=parseHostInputLimit(extra.get('--input-limit'));}
|
|
286
291
|
catch(error){refuse(error.code!=='invalid_arguments','invalid_arguments','--input-limit 须为 65536–4194304 的整数字节数');throw error;}
|
|
287
292
|
const revisionRequested=extra.has('--revise-qa-config')||extra.has('--qa-config-revision-reason');
|
|
@@ -345,6 +350,10 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
345
350
|
const routes=extra.has('--protected-config')?resolveProtectedRuntimes(loadConfig({projectRoot:definition.codeProject}),boundRuntime):{reviewerRuntime:boundRuntime};
|
|
346
351
|
const executionPolicy=readLaunchExecutionPolicy({definition,mode:argv[4],enabled:extra.has('--execution-optimizations')});
|
|
347
352
|
const externalModels=readLaunchExternalModels({definition,mode:argv[4],enabled:extra.has('--external-models'),inputFile:extra.get('--external-models-config'),providers:[routes.coderRuntime,routes.reviewerRuntime].filter(Boolean)});
|
|
353
|
+
// 期限放宽只给普通当前会话运行:受保护会话与外部模型运行的期限由其已授权配置决定(恢复时自动加载的外部模型快照同样适用)
|
|
354
|
+
refuse(callTimeoutMs===null||!protection,'invalid_arguments','--call-timeout-minutes 不用于 --protected-conversation-config 运行,期限由其已授权配置决定');
|
|
355
|
+
// 外部模型运行(含恢复时自动加载的快照)不可新开放宽;恢复时可带创建时的同一值,落盘回放逐字节核对
|
|
356
|
+
refuse(callTimeoutMs===null||!externalModels||argv[4]==='resume','invalid_arguments','外部模型运行创建时不接受 --call-timeout-minutes');
|
|
348
357
|
need(!externalModels||!extra.has('--failover'),'external_model_failover_unsupported');
|
|
349
358
|
review=extra.has('--review-config')?reviewConfiguration(extra.get('--review-config'),externalModels?.providers[routes.reviewerRuntime]??null):null;
|
|
350
359
|
// Launch-time capability assertion. See host-workflow-capabilities: this is a
|
|
@@ -388,10 +397,13 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
388
397
|
execution=extra.has('--protected-config')
|
|
389
398
|
?await protectedExecutionFor(definition,argv[6],extra,review,argv[4],workflow,bridge,bootstrap,externalModels,executionPolicy,controlPolicy)
|
|
390
399
|
:executionFor(definition,argv[6],bridge,review,null,workflow,qaEnabled,runtime,
|
|
391
|
-
{...(controlPolicy?{controlPolicy}:{}),...(extra.has('--review-runtime')?{reviewRuntime:extra.get('--review-runtime')}:{}),...(executionPolicy?{executionPolicy}:{}),...(externalModels?{externalModels}:{}),...(extra.has('--verification-precheck')?{verificationPrecheck:true}:{}),...(extra.has('--original-host-context')?{originalHostContextId:extra.get('--original-host-context')}:{}),...(protection?{protection}:{}),...(bootstrap?{bootstrap:{...bootstrap,allowWrite:(controlPolicy?controlPolicy.bootstrap==='write':extra.has('--allow-bootstrap-write'))}}:{})});
|
|
400
|
+
{...(callTimeoutMs!==null?{callTimeoutMs}:{}),...(controlPolicy?{controlPolicy}:{}),...(extra.has('--review-runtime')?{reviewRuntime:extra.get('--review-runtime')}:{}),...(executionPolicy?{executionPolicy}:{}),...(externalModels?{externalModels}:{}),...(extra.has('--verification-precheck')?{verificationPrecheck:true}:{}),...(extra.has('--original-host-context')?{originalHostContextId:extra.get('--original-host-context')}:{}),...(protection?{protection}:{}),...(bootstrap?{bootstrap:{...bootstrap,allowWrite:(controlPolicy?controlPolicy.bootstrap==='write':extra.has('--allow-bootstrap-write'))}}:{})});
|
|
392
401
|
run=await openControlRun(definition,argv[4],execution,{reviewedIntegration,qaConfigRevision,rerunUnknownQa:extra.has('--rerun-unknown-qa'),rerunBlockedQa:extra.has('--rerun-blocked-qa'),qaEnvironmentFailure:extra.get('--qa-environment-failure')??null,supersedeReason:extra.get('--supersede-reason')??null,acceptSupersededCodeDrift:extra.has('--accept-superseded-code-drift'),allowAbandonReview:recoveryEnabled('--allow-abandon-review'),allowAbandonEffect:recoveryEnabled('--allow-abandon-effect'),allowBootstrapReviewRecovery:recoveryEnabled('--allow-bootstrap-review-recovery'),allowDevelopRedo:recoveryEnabled('--allow-develop-redo'),...(extra.has('--hold-revision')?{holdRevision:true}:{}),scopeRevision,developmentReworkReason:extra.get('--development-rework-reason')??null,specRebindReason:extra.get('--spec-rebind-reason')??null,expectedControl,supersedeTarget});
|
|
393
402
|
}
|
|
394
403
|
if(run.blocked){output.write(JSON.stringify({outcome:'blocked',admission:run.blocked})+'\n');return 1;}
|
|
404
|
+
// 期限按每次启动传入值生效(只校验不低于创建时的值),所以每次都明确报出,不悄悄变化
|
|
405
|
+
if(!extra.has('--protected-config')&&!protection)
|
|
406
|
+
error.write(`[cm-ai] 本次单次宿主调用期限 ${execution.timeoutMs/60000} 分钟(--call-timeout-minutes,${externalModels?'外部模型运行须与创建时一致':'不得低于创建时的值,最多 60'})\n`);
|
|
395
407
|
if(hasFix&&reviewedIntegration===null){
|
|
396
408
|
need(fs.realpathSync(fix.specsRoot)===fs.realpathSync(definition.specsDir)
|
|
397
409
|
&&fs.realpathSync(fix.configuration.reproduction.cwd)===fs.realpathSync(definition.codeProject)
|
|
@@ -143,7 +143,9 @@ test('split-root SwiftUI Claude control run creates a baseline beside Git-ignore
|
|
|
143
143
|
test('host create reports the offending unsupported file on stderr before transport starts',async()=>{
|
|
144
144
|
const f=fixture(),lines=[];
|
|
145
145
|
try{
|
|
146
|
-
|
|
146
|
+
// A hard link stays unsupported; a symlink is recorded since symlink baselines (v3).
|
|
147
|
+
fs.writeFileSync(path.join(f.codeProject,'zeta.swift'),'');
|
|
148
|
+
fs.linkSync(path.join(f.codeProject,'zeta.swift'),path.join(f.codeProject,'alien.swift'));
|
|
147
149
|
const exit=await hostMain(launchArgs(f),{input:{},output:{write(){}},error:{write(value){lines.push(value);}}});
|
|
148
150
|
assert.equal(exit,1);
|
|
149
151
|
assert.match(lines.join(''),/\[host\] unsupported_file: alien\.swift/);
|
|
@@ -76,6 +76,29 @@ test('fingerprint_mismatch names the launch input that differs',t=>{
|
|
|
76
76
|
'--runtime','claude','--review-config',f.review]}).status,0);
|
|
77
77
|
});
|
|
78
78
|
|
|
79
|
+
test('--call-timeout-minutes 恢复时可放宽:现行 main 建的运行恢复时加 60 能重开;缩短(含漏传)按名字拒绝',t=>{
|
|
80
|
+
const f=fixture(t),base=['--runtime','claude','--review-config',f.review];
|
|
81
|
+
assert.equal(f.host('create',{extra:base}).status,0);
|
|
82
|
+
for(const [label,extra] of [['explicit 30',[...base,'--call-timeout-minutes','30']],['raised to 45',[...base,'--call-timeout-minutes','45']],
|
|
83
|
+
['raised to 60',[...base,'--call-timeout-minutes','60']]]){
|
|
84
|
+
const result=f.host('resume',{extra});
|
|
85
|
+
assert.equal(result.status,0,`${label}: ${JSON.stringify(result.error??null)}`);
|
|
86
|
+
assert.match(result.stderr,new RegExp(`本次单次宿主调用期限 ${extra.at(-1)} 分钟`),label);
|
|
87
|
+
}
|
|
88
|
+
// 恢复时放宽不入落盘记录:再次恢复按当次值生效,并在 stderr 明确报出(不悄悄变化)
|
|
89
|
+
const again=f.host('resume',{extra:base});assert.equal(again.status,0);assert.match(again.stderr,/本次单次宿主调用期限 30 分钟/);
|
|
90
|
+
const g=fixture(t),gbase=['--runtime','claude','--review-config',g.review];
|
|
91
|
+
assert.equal(g.host('create',{extra:[...gbase,'--call-timeout-minutes','60']}).status,0);
|
|
92
|
+
assert.equal(g.host('resume',{extra:[...gbase,'--call-timeout-minutes','60']}).status,0,'created at 60, resumed at 60');
|
|
93
|
+
const lowered=g.host('resume',{extra:gbase});
|
|
94
|
+
assert.equal(lowered.status,1,'omitting the flag would shorten the window');assert.equal(lowered.error.code,'invalid_arguments');
|
|
95
|
+
assert.match(lowered.error.reason,/此运行已用 60 分钟,本次为 30 分钟/);
|
|
96
|
+
for(const bad of ['29','61','x']){
|
|
97
|
+
const result=g.host('resume',{extra:[...gbase,'--call-timeout-minutes',bad]});
|
|
98
|
+
assert.equal(result.status,1,bad);assert.equal(result.error.code,'invalid_arguments',bad);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
|
|
79
102
|
test('a legacy run created without review config explains why the config cannot be added on resume',async t=>{
|
|
80
103
|
const f=fixture(t),bridge=createHostToolBridge();
|
|
81
104
|
try{
|
package/scripts/cm-ai-run.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// Fixed, no-provider control entry. Executing adapters are a subsequent slice.
|
|
3
3
|
import fs from 'node:fs';
|
|
4
|
+
import {SYMLINK_BASELINE_VERSION} from '../runtime/js/cm-ai/symlink-material.mjs';
|
|
4
5
|
import {assertDeclaredScope} from '../runtime/js/task-scope.mjs';
|
|
5
6
|
import {spawn as spawnChild} from 'node:child_process';
|
|
6
7
|
import path from 'node:path';
|
|
@@ -442,7 +443,7 @@ async function openControlRunOwned(definition,mode,execution=null,{supersedeHold
|
|
|
442
443
|
// Reuse the runner's real validator before creating durable state. A failed
|
|
443
444
|
// baseline must not strand an otherwise unused run ID.
|
|
444
445
|
const specification={specsRoot:specsDir,feature};
|
|
445
|
-
const baselineOptions={root:codeProject,specsRoot:specsDir,identity,scope,requirements,specification,
|
|
446
|
+
const baselineOptions={root:codeProject,specsRoot:specsDir,identity,scope,requirements,specification,version:SYMLINK_BASELINE_VERSION,
|
|
446
447
|
...(bootstrapConfig?{bootstrapRequirements:bootstrapConfig.bootstrapRequirements}:{}),
|
|
447
448
|
...(selectedRoots?{codeProjectPaths:selectedRoots}:{})};
|
|
448
449
|
if(mode==='create'){
|
|
@@ -74,8 +74,18 @@ function fixture(t,{qa=false,protectedMode=false,selected=false}={}){
|
|
|
74
74
|
const rows=()=>JSON.parse(fs.readFileSync(stateFile)).records;
|
|
75
75
|
return {root,app,specs,answers,identity,scope,added,drive,deliver,stateFile,rows};
|
|
76
76
|
}
|
|
77
|
-
function blocked(t,options){
|
|
78
|
-
const f=fixture(t,options)
|
|
77
|
+
function blocked(t,{baselineVersion=3,...options}={}){
|
|
78
|
+
const f=fixture(t,options);
|
|
79
|
+
if(baselineVersion===2){
|
|
80
|
+
assert.equal(f.drive('status',{mode:'create'}).value.state,'ready');
|
|
81
|
+
const {revision,...snapshot}=JSON.parse(fs.readFileSync(f.stateFile,'utf8'));
|
|
82
|
+
assert.deepEqual(snapshot.records.map(row=>row.payload.type),['init']);
|
|
83
|
+
snapshot.records[0].payload.baseline=captureReviewBaseline({root:f.app,specsRoot:f.specs,identity:f.identity,
|
|
84
|
+
scope:[...f.scope,'AGENTS.md'],requirements:['requirements.md'],specification:{specsRoot:f.specs,feature:'1.work'},version:2});
|
|
85
|
+
reseal(snapshot.records);
|
|
86
|
+
fs.writeFileSync(f.stateFile,JSON.stringify({...snapshot,revision:digest(snapshot)})+'\n');
|
|
87
|
+
}
|
|
88
|
+
const r=f.drive('start',{mode:baselineVersion===2?'resume':'create'});
|
|
79
89
|
assert.equal(r.status,0,r.stderr);assert.equal(r.value.code,'develop_checks_not_passed',JSON.stringify(r.value));
|
|
80
90
|
f.target=f.drive().value.launchControlTarget;return f;
|
|
81
91
|
}
|
|
@@ -145,7 +155,8 @@ test('newly scoped unchanged files retain complete bytes and modes in review mat
|
|
|
145
155
|
handoffPath:path.join(f.specs,'.reviews','work-T-001-a1-handoff.json')}));
|
|
146
156
|
});
|
|
147
157
|
test('scope refusal leaves source records intact for stale, shrinking, protected and changed additions',t=>{
|
|
148
|
-
const f=blocked(t),before=fs.readFileSync(f.stateFile);
|
|
158
|
+
const f=blocked(t,{baselineVersion:2}),before=fs.readFileSync(f.stateFile);
|
|
159
|
+
assert.equal(f.rows()[0].payload.baseline.version,2);
|
|
149
160
|
const refused=(extra,code)=>{
|
|
150
161
|
const r=revise(f,extra);assert.equal(r.status,71,r.stderr);assert.equal(r.value.code,code,JSON.stringify(r.value));
|
|
151
162
|
assert.ok(fs.readFileSync(f.stateFile).equals(before),'rejection must not append a record');
|
|
@@ -173,6 +184,27 @@ test('scope refusal leaves source records intact for stale, shrinking, protected
|
|
|
173
184
|
assert.equal(revise(f).value.code,'snapshot_changed');
|
|
174
185
|
f.target=f.drive().value.launchControlTarget;assert.equal(revise(f,{scope:[...f.scope,f.added,'another.mjs']}).value.code,'scope_revision_unavailable');
|
|
175
186
|
});
|
|
187
|
+
test('v3 scope revision rejects a file swapped for an external symlink without reading its target',t=>{
|
|
188
|
+
const f=blocked(t),before=fs.readFileSync(f.stateFile),outside=path.join(f.root,'private.txt');
|
|
189
|
+
assert.equal(f.rows()[0].payload.baseline.version,3);
|
|
190
|
+
// Identical file bytes would defeat a check that followed the link and compared only the content.
|
|
191
|
+
fs.copyFileSync(path.join(f.app,f.added),outside);
|
|
192
|
+
const file=path.join(f.app,f.added);
|
|
193
|
+
fs.unlinkSync(file);fs.symlinkSync(outside,file);
|
|
194
|
+
const open=fs.openSync,guard=t.mock.method(fs,'openSync',(candidate,...args)=>{
|
|
195
|
+
assert.ok(![file,outside].includes(candidate),'neither the link nor its referent may be opened');
|
|
196
|
+
return open(candidate,...args);
|
|
197
|
+
});
|
|
198
|
+
assert.throws(()=>captureScopeRevisionSources(f.app,f.rows()[0].payload.baseline,[...f.scope,f.added]),
|
|
199
|
+
{code:'scope_revision_source_changed'});
|
|
200
|
+
guard.mock.restore();
|
|
201
|
+
const result=revise(f);
|
|
202
|
+
assert.equal(result.status,71,result.stderr);
|
|
203
|
+
assert.equal(result.value.code,'scope_revision_source_changed',JSON.stringify(result.value));
|
|
204
|
+
assert.deepEqual(fs.readFileSync(f.stateFile),before);
|
|
205
|
+
assert.equal(fs.readlinkSync(path.join(f.app,f.added)),outside);
|
|
206
|
+
assert.equal(fs.readFileSync(outside,'utf8'),'export const value = 0;\n');
|
|
207
|
+
});
|
|
176
208
|
test('replay validates the revision source and handles prefixes before and after append without filesystem reads',t=>{
|
|
177
209
|
const f=blocked(t);assert.equal(revise(f).value.outcome,'recorded');
|
|
178
210
|
const rows=f.rows(),config=rows[0].payload.config,last=rows.at(-1);
|