@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
|
@@ -161,31 +161,54 @@ export const stripCode=text=>text.replace(/```[\s\S]*?(?:```|$)/g,' ');
|
|
|
161
161
|
// Real misfire: "不要换个会话,继续当前任务" told the model to start handoff.
|
|
162
162
|
// Quoted or inline-code words are being talked about, not asked for. ASCII ' is left
|
|
163
163
|
// alone because English contractions use it.
|
|
164
|
-
|
|
164
|
+
// Quotes never span lines, so an unclosed “ cannot swallow the rest of a message (todo from PR #265).
|
|
165
|
+
// A quote never opens twice, so a stray “ pairs with nothing; ’ inside an English word (don’t) is an
|
|
166
|
+
// apostrophe, not the closing quote (review r1).
|
|
167
|
+
const QUOTED=[/`[^`\n\r\u2028\u2029]*`/g,/“[^“”\n\r\u2028\u2029]*”/g,/「[^「」\n\r\u2028\u2029]*」/g,/『[^『』\n\r\u2028\u2029]*』/g,/"[^"\n\r\u2028\u2029]*"/g,
|
|
168
|
+
// Single quotes go last and never reach into another quote, so ‘ and ’ from two different quotes
|
|
169
|
+
// cannot pair up (review r2).
|
|
170
|
+
/‘(?:[^‘’“”「」『』\n\r\u2028\u2029]|’(?=[a-zA-Z]))*’(?![a-zA-Z])/g];
|
|
165
171
|
export const stripQuoted=text=>QUOTED.reduce((out,re)=>out.replace(re,' '),text);
|
|
166
172
|
// A negation masks only the few characters (Chinese) or words (English) right after it,
|
|
167
173
|
// within its own clause: "不要继续当前任务,换个会话交接" still asks for a handoff.
|
|
168
174
|
// "别忘了/不要忘了/别忘记" mean "do", so a negation followed by 忘 is not one.
|
|
169
175
|
export const NEGATION_WINDOW={zh:4,en:3};
|
|
170
|
-
const CLAUSE_END=/[,,。.!!??;;::\n]/;
|
|
176
|
+
const CLAUSE_END=/[,,。.!!??;;::\n\r\u2028\u2029]/;
|
|
177
|
+
// After a condition word in the same clause, 就 starts the consequence: "如果不需要测试就换个会话交接"
|
|
178
|
+
// (review r1). Without one, 就 is just "right away": "不要现在就换个会话交接" stays negated (review r2).
|
|
179
|
+
// 就 right after a time word (现在就/马上就) means "right away" and stays inside the negation (review r4b).
|
|
180
|
+
// A lone 这 is left out: 这就 (right away) and 放这就 (put it here, then) cannot be told apart here (review r5).
|
|
181
|
+
const RIGHT_AWAY=/(?:现在|马上|立刻|立即|立马|今天)$/;
|
|
182
|
+
// A lone 若 counts only right before the negation (若不用…); elsewhere it may be a name like 若琳 (review r4).
|
|
183
|
+
const ZH_CONDITION=/(?:如果|要是|假如|假设|万一|倘若|若是|(?<![宛仿犹恍])若$)(?![^就]*就)/;
|
|
171
184
|
// A lone 别 inside a word (别人、特别、分别、区别、告别、别名…) is not a negation (review r1),
|
|
172
|
-
// nor are A-not-A questions (
|
|
173
|
-
|
|
174
|
-
const
|
|
185
|
+
// nor are A-not-A questions (要不要、用不用、想不想、需(要)不需要、有没有必要), "why not" (review r2)
|
|
186
|
+
// or questions like "won't you/we …".
|
|
187
|
+
const ZH_NEGATION=/(?:先别|(?<!需)(?<!需要)不需要|(?<!有)没有必要|没必要|(?<!(?<!只)要)不要|(?<!用)不用|(?<!想)不想|无需|不必|(?<![特分区识级类个告差辨鉴性派道送判甄离])别(?![人处的致墅名扭样具]))(?!忘)/g;
|
|
188
|
+
const EN_NEGATION=/\b(?:(?<!why\s+)don['’]?t|(?<!why\s+)won['’]?t(?!\s+(?:you|we|they|i)\b)|do not|no need to|(?<!why\s+)not)\b/g;
|
|
175
189
|
const EN_WORD=/^[ \t]+[^\s,,。.!!??;;::]+/;
|
|
190
|
+
function zhWindowEnd(text,negationIndex,start){
|
|
191
|
+
let clauseStart=negationIndex;
|
|
192
|
+
while(clauseStart>0&&!CLAUSE_END.test(text[clauseStart-1]))clauseStart--;
|
|
193
|
+
const conditional=ZH_CONDITION.test(text.slice(clauseStart,negationIndex));
|
|
194
|
+
let end=start;
|
|
195
|
+
while(end<text.length&&end-start<NEGATION_WINDOW.zh&&!CLAUSE_END.test(text[end])&&!(conditional&&text[end]==='就'&&!RIGHT_AWAY.test(text.slice(Math.max(0,end-2),end))))end++;
|
|
196
|
+
return end;
|
|
197
|
+
}
|
|
176
198
|
export function maskNegated(text){
|
|
177
199
|
let out=text;
|
|
178
200
|
const blank=(from,to)=>{out=out.slice(0,from)+' '.repeat(to-from)+out.slice(to);};
|
|
179
201
|
for(const match of text.matchAll(ZH_NEGATION)){
|
|
180
202
|
const start=match.index+match[0].length;
|
|
181
|
-
|
|
182
|
-
while(end<text.length&&end-start<NEGATION_WINDOW.zh&&!CLAUSE_END.test(text[end]))end++;
|
|
183
|
-
blank(start,end);
|
|
203
|
+
blank(start,zhWindowEnd(text,match.index,start));
|
|
184
204
|
}
|
|
185
205
|
for(const match of text.matchAll(EN_NEGATION)){
|
|
186
206
|
const start=match.index+match[0].length;
|
|
187
207
|
let end=start;
|
|
188
|
-
|
|
208
|
+
// Chinese right after the English negation ("don't换个会话") is masked like a Chinese negation,
|
|
209
|
+
// condition rule included (todo from PR #265, review r1).
|
|
210
|
+
if(/^[\u3400-\u9fff]/.test(text.slice(start)))end=zhWindowEnd(text,match.index,start);
|
|
211
|
+
else for(let words=0;words<NEGATION_WINDOW.en;words++){
|
|
189
212
|
const next=EN_WORD.exec(text.slice(end));
|
|
190
213
|
if(!next)break;
|
|
191
214
|
end+=next[0].length;
|
|
@@ -316,6 +339,12 @@ export async function pickInvoke({prompt,rules,host,env,authorCheck,judgeModule,
|
|
|
316
339
|
const plain=splitHits(candidates,stripCode(prompt.toLowerCase()));
|
|
317
340
|
const raw=plain.map(hit=>hit.keyword||hit.pattern);
|
|
318
341
|
const index=guarded.findIndex((hit,at)=>raw[at]&&(hit.keyword||hit.pattern));
|
|
342
|
+
// What the guards held back, for the log (rule and reason only, never the text); every such rule,
|
|
343
|
+
// also when another rule goes ahead (todo from PR #265, review r1).
|
|
344
|
+
const unguarded=splitHits(candidates,unquoted);
|
|
345
|
+
const suppressed=candidates.flatMap((rule,at)=>raw[at]&&!(guarded[at].keyword||guarded[at].pattern)
|
|
346
|
+
?[{rule:rule.id,skill:rule.skill,reason:unguarded[at].keyword||unguarded[at].pattern?'negated':'quoted'}]:[]);
|
|
347
|
+
if(suppressed.length)fallback.suppressed=suppressed;
|
|
319
348
|
if(index>=0){
|
|
320
349
|
const rule=candidates[index];
|
|
321
350
|
// A rule with patterns keeps its mode only when a pattern matched both before and after
|
|
@@ -323,12 +352,7 @@ export async function pickInvoke({prompt,rules,host,env,authorCheck,judgeModule,
|
|
|
323
352
|
const strong=guarded[index].pattern&&plain[index].pattern;
|
|
324
353
|
return {...fallback,rule,mode:rule.patterns.length&&!strong?'ask':rule.invoke.mode};
|
|
325
354
|
}
|
|
326
|
-
|
|
327
|
-
const first=raw.findIndex(Boolean);
|
|
328
|
-
if(first<0)return {...fallback,rule:null};
|
|
329
|
-
const unguarded=splitHits([candidates[first]],unquoted)[0];
|
|
330
|
-
return {...fallback,rule:null,suppressed:{rule:candidates[first].id,skill:candidates[first].skill,
|
|
331
|
-
reason:unguarded.keyword||unguarded.pattern?'negated':'quoted'}};
|
|
355
|
+
return {...fallback,rule:null};
|
|
332
356
|
}
|
|
333
357
|
function splitHits(rules,text){
|
|
334
358
|
const byPattern=patternMatches(rules,text);
|
|
@@ -373,7 +397,7 @@ export async function hook(input,{env=process.env,host='claude',rulesFile=defaul
|
|
|
373
397
|
// A missing key is the normal state for most users, not worth a line per message.
|
|
374
398
|
if(invoked.error&&!['no-key','off'].includes(invoked.error))appendLog(env,{t:time,event:'judge-error',host,error:invoked.error});
|
|
375
399
|
if(start)appendLog(env,{t:time,event:'invoke',host,rule:invoked.rule.id,skill:start.skill,mode:start.mode,via:invoked.via});
|
|
376
|
-
|
|
400
|
+
for(const item of invoked.suppressed??[])appendLog(env,{t:time,event:'suppressed',host,...item});
|
|
377
401
|
for(const hint of hints)appendLog(env,{t:time,event:'hint',host,rule:hint.rule,skill:hint.skill});
|
|
378
402
|
}catch{/* 统计丢一条 */}
|
|
379
403
|
// Session state is never removed (decided 2026-10-24): a session resumed months
|
|
@@ -909,6 +909,56 @@ test('guards: window edges, case, everyday words with 别, and guards never add
|
|
|
909
909
|
assert.deepEqual(got,cases);
|
|
910
910
|
});
|
|
911
911
|
|
|
912
|
+
test('guards: 不需要, 没必要 and won\'t also negate; A-not-A and why-won\'t stay questions (todo from PR #265)',async t=>{
|
|
913
|
+
const f=guarded(t);
|
|
914
|
+
const cases=[
|
|
915
|
+
['不需要换个会话,继续',null],
|
|
916
|
+
['没必要换个会话交接',null],
|
|
917
|
+
["won't start a new session",null],
|
|
918
|
+
['won’t start a new session',null],
|
|
919
|
+
['需要换个会话交接','direct:handoff'],
|
|
920
|
+
['需不需要换个会话交接','direct:handoff'],
|
|
921
|
+
['有没有必要换个会话交接','direct:handoff'],
|
|
922
|
+
['不需要的先放着,换个会话交接','direct:handoff'],
|
|
923
|
+
["why won't we start a new session",'ask:handoff'],
|
|
924
|
+
["we won't need it, start a new session",'ask:handoff'],
|
|
925
|
+
// review r1: full A-not-A form, won't-questions, a condition ending in 就, and 没有必要.
|
|
926
|
+
['需要不需要换个会话交接','direct:handoff'],
|
|
927
|
+
['Won’t you start a new session?','ask:handoff'],
|
|
928
|
+
["Why exactly won't we start a new session?",'ask:handoff'],
|
|
929
|
+
['如果不需要测试就换个会话交接','direct:handoff'],
|
|
930
|
+
['如果不用测试就换个会话交接','direct:handoff'],
|
|
931
|
+
['没有必要换个会话交接,继续当前任务',null],
|
|
932
|
+
['有没有必要换个会话交接','direct:handoff'],
|
|
933
|
+
// review r2: 就 ends the negation only after a condition word (如果/要是/假如…) in the same clause.
|
|
934
|
+
['不要现在就换个会话交接,先把测试跑完',null],
|
|
935
|
+
['要是不用测试就换个会话交接','direct:handoff'],
|
|
936
|
+
['如果没问题,不要现在就换个会话交接',null],
|
|
937
|
+
// review r3 todo: single-character 若 is a condition word too; 若干/宛若 are not.
|
|
938
|
+
['若不用测试就换个会话交接','direct:handoff'],
|
|
939
|
+
['倘若不需要测试就换个会话交接','direct:handoff'],
|
|
940
|
+
['前面若干步不要就换个会话交接',null],
|
|
941
|
+
['宛若无事不要就换个会话交接',null],
|
|
942
|
+
// review r4: a condition already closed by its own 就 does not reach a later 就; a name like 若琳 is no condition.
|
|
943
|
+
['若测试还没跑完就不要现在就换个会话交接,先继续测试',null],
|
|
944
|
+
['如果测试没跑完就不要现在就换个会话交接',null],
|
|
945
|
+
['若琳说不要现在就换个会话交接,先把测试跑完',null],
|
|
946
|
+
['你若不想测试就换个会话交接','direct:handoff'],
|
|
947
|
+
// review r4b: 就 after a time word (现在就/马上就/立刻就) is "right away", not the consequence.
|
|
948
|
+
['若不想现在就换个会话交接,那就先继续测试',null],
|
|
949
|
+
['如果不想马上就换个会话交接,那就先继续测试',null],
|
|
950
|
+
['要是不用立刻就换个会话交接,就先继续测试',null],
|
|
951
|
+
// review r5: single 这/早 end other words (来这/起早), so they are not time words here.
|
|
952
|
+
['如果不用来这就换个会话交接,剩下的我远程做','direct:handoff'],
|
|
953
|
+
['如果不用起早就换个会话交接,下午再继续','direct:handoff'],
|
|
954
|
+
['若不想今天就换个会话交接,那就先继续测试',null],
|
|
955
|
+
['如果日志不用放这就换个会话交接,日志我移到归档目录','direct:handoff'],
|
|
956
|
+
];
|
|
957
|
+
const got=[];
|
|
958
|
+
for(const [prompt] of cases)got.push([prompt,await f.run(prompt)]);
|
|
959
|
+
assert.deepEqual(got,cases);
|
|
960
|
+
});
|
|
961
|
+
|
|
912
962
|
test('guards: what they hold back is logged with rule and reason only, never the text',async t=>{
|
|
913
963
|
const f=guarded(t);
|
|
914
964
|
await f.run('不要换个会话,继续当前任务');
|
|
@@ -919,6 +969,47 @@ test('guards: what they hold back is logged with rule and reason only, never the
|
|
|
919
969
|
assert.doesNotMatch(fs.readFileSync(logFile(f.env),'utf8'),/换个会话|继续当前任务/);
|
|
920
970
|
});
|
|
921
971
|
|
|
972
|
+
test('guards: Chinese single quotes, quotes never span lines, English negation right before Chinese (todo from PR #265)',async t=>{
|
|
973
|
+
const f=guarded(t);
|
|
974
|
+
const cases=[
|
|
975
|
+
['我们讨论 ‘换个会话’ 这个关键词',null],
|
|
976
|
+
['他说“先看看\n换个会话交接吧\n后面才是”结尾','direct:handoff'],
|
|
977
|
+
['「先看看\n换个会话交接吧\n」','direct:handoff'],
|
|
978
|
+
["don't换个会话,继续当前任务",null],
|
|
979
|
+
["don’t 换个会话,继续当前任务",null],
|
|
980
|
+
['Won’t you start a new session?','ask:handoff'],
|
|
981
|
+
// review r1: ’ inside an English word is an apostrophe; any line break ends a quote; a quote never
|
|
982
|
+
// opens twice; English negation glued to Chinese keeps the condition rule.
|
|
983
|
+
['我们讨论 ‘don’t hand off to a new session’ 这句英文',null],
|
|
984
|
+
['他说“先看看\r换个会话交接吧\r后面才是”结尾','direct:handoff'],
|
|
985
|
+
['他说“先看看\u2028换个会话交接吧\u2028后面才是”结尾','direct:handoff'],
|
|
986
|
+
['这里先留个左引号“,换个会话交接吧,标题用“进度”','direct:handoff'],
|
|
987
|
+
["如果don't测就换个会话交接",'direct:handoff'],
|
|
988
|
+
// review r2: ‘ and ’ never pair across two other quotes; \r and U+2028/U+2029 end a clause too.
|
|
989
|
+
['对比『‘ 是左单引号』和「’ 是右单引号,换个会话交接是测试短语」这两段文字',null],
|
|
990
|
+
['don’t测\u2028换个会话交接','direct:handoff'],
|
|
991
|
+
['不要测\r换个会话交接','direct:handoff'],
|
|
992
|
+
['不要测\u2029换个会话交接','direct:handoff'],
|
|
993
|
+
];
|
|
994
|
+
const got=[];
|
|
995
|
+
for(const [prompt] of cases)got.push([prompt,await f.run(prompt)]);
|
|
996
|
+
assert.deepEqual(got,cases);
|
|
997
|
+
});
|
|
998
|
+
|
|
999
|
+
test('guards: every rule the guards hold back in one message is logged, not just the first (todo from PR #265)',async t=>{
|
|
1000
|
+
const f=guarded(t,{version:1,rules:[
|
|
1001
|
+
{id:'long-session',skill:'handoff',author:true,keywords:['换个会话'],reason:'写交接',invoke:{mode:'direct',when:'写交接'}},
|
|
1002
|
+
{id:'split',skill:'wayfinder',author:true,keywords:['拆会话'],reason:'拆任务',invoke:{mode:'direct',when:'拆任务'}}]});
|
|
1003
|
+
assert.equal(await f.run('不要换个会话,也“拆会话”'),null);
|
|
1004
|
+
assert.deepEqual(f.log().filter(entry=>entry.event==='suppressed').map(({rule,skill,reason})=>({rule,skill,reason})),[
|
|
1005
|
+
{rule:'long-session',skill:'handoff',reason:'negated'},
|
|
1006
|
+
{rule:'split',skill:'wayfinder',reason:'quoted'}]);
|
|
1007
|
+
// review r1: a rule held back is logged even when another rule in the same message goes ahead.
|
|
1008
|
+
assert.equal(await f.run('换个会话交接吧,“拆会话”是另一个选项'),'direct:handoff');
|
|
1009
|
+
assert.deepEqual(f.log().filter(entry=>entry.event==='suppressed').slice(2).map(({rule,reason})=>({rule,reason})),[
|
|
1010
|
+
{rule:'split',reason:'quoted'}]);
|
|
1011
|
+
});
|
|
1012
|
+
|
|
922
1013
|
test('guards: masking a pattern\'s exclusion words never upgrades ask to direct (review r2)',async t=>{
|
|
923
1014
|
const f=guarded(t,{version:1,rules:[{id:'long-session',skill:'handoff',author:true,keywords:['换个会话'],
|
|
924
1015
|
patterns:['^(?![\\s\\S]*只是问问)[\\s\\S]*会话'],reason:'写交接',invoke:{mode:'direct',when:'写交接'}}]});
|
|
@@ -12,14 +12,16 @@ import {isXcodebuild, isTestAction, advisoryRunsTest as runsTest, mandatoryCheck
|
|
|
12
12
|
import {git as safeGit} from '../runtime/js/cm-security/scan.mjs';
|
|
13
13
|
import {captureSpecificationMaterial} from '../runtime/js/cm-ai/specification-material.mjs';
|
|
14
14
|
import {readReviewBaseline,captureReviewBaseline} from '../runtime/js/cm-ai/review-package.mjs';
|
|
15
|
+
import {SYMLINK_BASELINE_VERSION} from '../runtime/js/cm-ai/symlink-material.mjs';
|
|
15
16
|
import {taskReviewScope} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
17
|
+
import {callTimeoutFrom} from '../runtime/js/cm-ai/call-timeout.mjs';
|
|
16
18
|
import {codeProjectPaths,resolveCodeProjects} from '../runtime/js/cm-ai/code-projects.mjs';
|
|
17
19
|
import {readExecutionSnapshot} from '../runtime/js/cm-ai/execution-snapshot.mjs';
|
|
18
20
|
import {acceptanceCoverage} from '../runtime/js/cm-ai/acceptance-contract.mjs';
|
|
19
21
|
import {featureHasBrowserCases,readBrowserCapability} from '../runtime/js/cm-ai/host-workflow-capabilities.mjs';
|
|
20
22
|
|
|
21
23
|
// The whole check step of a current-session run is one host call with this deadline
|
|
22
|
-
// (runtime/js/cm-ai/host-conversation-execution.mjs, outerTimeoutMs). The test
|
|
24
|
+
// (runtime/js/cm-ai/host-conversation-execution.mjs, outerTimeoutMs; default unless --call-timeout-minutes). The test
|
|
23
25
|
// file guards that the literal is still there.
|
|
24
26
|
export const CHECK_CALL_LIMIT_MS = 1800000;
|
|
25
27
|
const MAX_LISTED = 20;
|
|
@@ -97,8 +99,32 @@ const optionValue = (tokens, name) => {
|
|
|
97
99
|
return at === -1 ? '' : tokens[at + 1] ?? '';
|
|
98
100
|
};
|
|
99
101
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
+
// 运行可用 --call-timeout-minutes(30–60)放宽整步期限;值非法或重复时宿主会拒绝启动,这里不论有无 checks 都提前报出
|
|
103
|
+
export function callLimit(plan, saved = null) {
|
|
104
|
+
try {
|
|
105
|
+
const value = callTimeoutFrom(plan.permissions), flags = Array.isArray(plan.permissions) ? plan.permissions : [];
|
|
106
|
+
const effective = value ?? CHECK_CALL_LIMIT_MS, bad = message => ({limitMs: CHECK_CALL_LIMIT_MS, findings: [{level: 'error', code: 'call_timeout_invalid', message}]});
|
|
107
|
+
if (saved?.external && effective !== saved.timeoutMs)
|
|
108
|
+
return bad(`外部模型运行恢复时期限须与创建时一致(${saved.timeoutMs / 60000} 分钟)`);
|
|
109
|
+
if (saved && !saved.external && effective < saved.timeoutMs)
|
|
110
|
+
return bad(`--call-timeout-minutes:此运行已用 ${saved.timeoutMs / 60000} 分钟,本次为 ${effective / 60000} 分钟;恢复时不得低于创建时的值`);
|
|
111
|
+
if (value !== null && (flags.includes('--protected-conversation-config') || flags.includes('--protected-config')))
|
|
112
|
+
return {limitMs: CHECK_CALL_LIMIT_MS, findings: [{level: 'error', code: 'call_timeout_invalid', message: '--call-timeout-minutes 不用于受保护运行'}]};
|
|
113
|
+
if (value !== null && flags.includes('--external-models') && plan.mode !== 'resume')
|
|
114
|
+
return {limitMs: CHECK_CALL_LIMIT_MS, findings: [{level: 'error', code: 'call_timeout_invalid', message: '外部模型运行创建时不接受 --call-timeout-minutes'}]};
|
|
115
|
+
return {limitMs: value ?? CHECK_CALL_LIMIT_MS, findings: []};
|
|
116
|
+
}
|
|
117
|
+
catch (error) { return {limitMs: CHECK_CALL_LIMIT_MS, findings: [{level: 'error', code: 'call_timeout_invalid', message: error.message}]}; }
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// 与宿主同一规则:受保护运行不接受;外部模型运行只在恢复时可带原值
|
|
121
|
+
const canWiden = (plan, saved = null) => {
|
|
122
|
+
const flags = Array.isArray(plan.permissions) ? plan.permissions : [];
|
|
123
|
+
return !saved?.external && !flags.includes('--protected-config') && !flags.includes('--protected-conversation-config') && !flags.includes('--external-models');
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
function checkChecks(plan, saved = null) {
|
|
127
|
+
const {limitMs, findings} = callLimit(plan, saved);
|
|
102
128
|
if (!Array.isArray(plan.checks)) return findings;
|
|
103
129
|
const items = plan.checks.filter(item => item !== null && typeof item === 'object' && !Array.isArray(item));
|
|
104
130
|
let timeouts;
|
|
@@ -131,10 +157,11 @@ function checkChecks(plan) {
|
|
|
131
157
|
message: `检查 ${group.map(entry => entry.item.id).join('、')} 都是同一 scheme/目的地、没有 -only-testing 的 xcodebuild test,很可能各自跑了一遍全量。保留一个,或用 -only-testing 分开`});
|
|
132
158
|
}
|
|
133
159
|
const totalMs = own.reduce((sum, entry) => sum + entry.timeoutMs, 0);
|
|
134
|
-
if (totalMs >
|
|
135
|
-
findings.push({level: 'warn', code: 'check_budget_over_call_limit', totalMs, limitMs
|
|
136
|
-
message: `各检查超时之和 ${Math.round(totalMs / 60000)} 分钟,超过检查整步的 ${
|
|
137
|
-
+ '
|
|
160
|
+
if (totalMs > limitMs)
|
|
161
|
+
findings.push({level: 'warn', code: 'check_budget_over_call_limit', totalMs, limitMs,
|
|
162
|
+
message: `各检查超时之和 ${Math.round(totalMs / 60000)} 分钟,超过检查整步的 ${limitMs / 60000} 分钟期限;这是最坏情况,实际可能更短。`
|
|
163
|
+
+ '按分层缩减(单元测试全跑,界面测试只跑本任务新写的和牵连的,其余留到功能末尾回归任务),或拆成多次运行;'
|
|
164
|
+
+ (canWiden(plan, saved) ? '设备检查确需更久时,在 PLAN.permissions 加 "--call-timeout-minutes","<30–60>"' : '此运行模式不能用 --call-timeout-minutes 延长期限(外部模型运行恢复时只可传创建时的原值)')});
|
|
138
165
|
return findings;
|
|
139
166
|
}
|
|
140
167
|
|
|
@@ -253,12 +280,12 @@ function checkDirtyScope(definition) {
|
|
|
253
280
|
// The runner captures this baseline when the run is created and again before
|
|
254
281
|
// each review package; a tree it refuses there stops the run after the develop
|
|
255
282
|
// answer was already written. Capture it here the same way, read-only.
|
|
256
|
-
export function checkReviewInventory(definition){
|
|
283
|
+
export function checkReviewInventory(definition,version=SYMLINK_BASELINE_VERSION){
|
|
257
284
|
if(!fs.existsSync(definition.codeProject)||typeof definition.specsDir!=='string'||!definition.identity
|
|
258
285
|
||!Array.isArray(definition.requirements))return [];
|
|
259
286
|
try{
|
|
260
287
|
const codeProject=definition.codeProject;
|
|
261
|
-
captureReviewBaseline({root:codeProject,specsRoot:definition.specsDir,identity:definition.identity,
|
|
288
|
+
captureReviewBaseline({root:codeProject,specsRoot:definition.specsDir,identity:definition.identity,version,
|
|
262
289
|
scope:taskReviewScope(definition.scope),requirements:definition.requirements,
|
|
263
290
|
...(typeof definition.feature==='string'?{specification:{specsRoot:definition.specsDir,feature:definition.feature}}:{}),
|
|
264
291
|
...(definition.codeProjects?{codeProjectPaths:codeProjectPaths(codeProject,resolveCodeProjects(codeProject,definition.codeProjects))}:{})});
|
|
@@ -335,6 +362,16 @@ export function checkMandatoryTests(plan, requiredTests) {
|
|
|
335
362
|
+ '补充明确执行这些测试的命令。包装脚本须先经原规格流程确认可机械核对的测试映射,不能仅在参数中出现测试名就认定覆盖'}];
|
|
336
363
|
}
|
|
337
364
|
|
|
365
|
+
// 恢复时读原运行首条记录里的期限与外部模型标记(只读、尽力而为;读不到时按计划自身判断,宿主仍会核对)
|
|
366
|
+
function savedRunConfig(plan, definition) {
|
|
367
|
+
if (plan.mode !== 'resume') return null;
|
|
368
|
+
try {
|
|
369
|
+
const config = readExecutionSnapshot({specsRoot: definition.specsDir,
|
|
370
|
+
identity: {repositoryId: definition.identity.repositoryId, runId: definition.identity.runId}}).records[0]?.payload?.config;
|
|
371
|
+
return config && Number.isInteger(config.timeoutMs) ? {timeoutMs: config.timeoutMs, external: Object.hasOwn(config, 'externalModels')} : null;
|
|
372
|
+
} catch { return null; }
|
|
373
|
+
}
|
|
374
|
+
|
|
338
375
|
function approvedStartContract(plan,definition){
|
|
339
376
|
// Old scope-only advisory inputs have no task identity and make no claim
|
|
340
377
|
// about a runnable CM specification. Real run definitions are checked below.
|
|
@@ -346,7 +383,7 @@ function approvedStartContract(plan,definition){
|
|
|
346
383
|
const baseline=readReviewBaseline(snapshot.records[0]?.payload?.baseline);
|
|
347
384
|
if(baseline.specificationRoot!==definition.specsDir||baseline.identity.taskId!==definition.identity.taskId)
|
|
348
385
|
throw new Error('owner mismatch');
|
|
349
|
-
return baseline.specification?.acceptanceContract??null;
|
|
386
|
+
return {contract:baseline.specification?.acceptanceContract??null,baselineVersion:baseline.version};
|
|
350
387
|
}
|
|
351
388
|
// A create-plan may be inspected before any specification has been written.
|
|
352
389
|
// Preserve its old scope/budget diagnostics; this read-only check grants no
|
|
@@ -360,14 +397,14 @@ function approvedStartContract(plan,definition){
|
|
|
360
397
|
const absent=file=>{try{fs.lstatSync(file);return false;}catch(error){if(error.code==='ENOENT')return true;throw error;}};
|
|
361
398
|
if(absent(path.join(root,'.cm-specs-status'))&&absent(path.join(root,definition.feature)))return null;
|
|
362
399
|
}
|
|
363
|
-
return captureSpecificationMaterial({specsRoot:definition.specsDir,feature:definition.feature,
|
|
364
|
-
taskId:definition.identity.taskId}).acceptanceContract;
|
|
400
|
+
return {contract:captureSpecificationMaterial({specsRoot:definition.specsDir,feature:definition.feature,
|
|
401
|
+
taskId:definition.identity.taskId}).acceptanceContract};
|
|
365
402
|
}catch{throw new InputError('必验合同无法从已批准规格或原运行读取;先核对规格批准与原运行身份,不能由 PLAN 自报或省略必验范围');}
|
|
366
403
|
}
|
|
367
404
|
|
|
368
405
|
export function startCheck(planFile, {requiredTests = []} = {}) {
|
|
369
406
|
const {plan, definition} = loadStartInputs(planFile);
|
|
370
|
-
const contract=approvedStartContract(plan,definition),mandatory=[];
|
|
407
|
+
const {contract,baselineVersion}=approvedStartContract(plan,definition)??{},mandatory=[];
|
|
371
408
|
if(contract){
|
|
372
409
|
if(contract.unresolved.length)mandatory.push({level:'error',code:'acceptance_mapping_required',
|
|
373
410
|
message:`已批准材料的必验映射尚不明确:${contract.unresolved.join(';')}`});
|
|
@@ -377,8 +414,9 @@ export function startCheck(planFile, {requiredTests = []} = {}) {
|
|
|
377
414
|
tests:coverage.missing,unverifiable:coverage.unverifiable,commands:coverage.missingCommands,
|
|
378
415
|
message:'当前计划未完整包含冻结的必验检查;补齐检查,不能缩减批准的验收范围'});
|
|
379
416
|
}
|
|
380
|
-
return [...checkProtectedScope(definition.scope), ...checkChecks(plan), ...checkAffectedTests(plan, definition),
|
|
381
|
-
...checkMandatoryTests(plan, requiredTests), ...mandatory, ...checkDirtyScope(definition), ...checkReviewInventory(definition),
|
|
417
|
+
return [...checkProtectedScope(definition.scope), ...checkChecks(plan, savedRunConfig(plan, definition)), ...checkAffectedTests(plan, definition),
|
|
418
|
+
...checkMandatoryTests(plan, requiredTests), ...mandatory, ...checkDirtyScope(definition), ...checkReviewInventory(definition,baselineVersion),
|
|
419
|
+
...checkLaunchInputs(plan, planFile, definition)];
|
|
382
420
|
}
|
|
383
421
|
|
|
384
422
|
export function main(argv = process.argv.slice(2), out = process.stdout, err = process.stderr) {
|
|
@@ -6,7 +6,7 @@ import path from 'node:path';
|
|
|
6
6
|
import test from 'node:test';
|
|
7
7
|
import {fileURLToPath} from 'node:url';
|
|
8
8
|
import {spawnSync} from 'node:child_process';
|
|
9
|
-
import {CHECK_CALL_LIMIT_MS, MAX_SCOPE_PATHS, startCheck, checkMandatoryTests, checkReviewInventory, checkLaunchInputs} from './cm-start-check.mjs';
|
|
9
|
+
import {CHECK_CALL_LIMIT_MS, MAX_SCOPE_PATHS, startCheck, checkMandatoryTests, checkReviewInventory, checkLaunchInputs, callLimit} from './cm-start-check.mjs';
|
|
10
10
|
import {buildManifest} from './cm-spec-manifest.mjs';
|
|
11
11
|
|
|
12
12
|
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
@@ -247,9 +247,28 @@ test('the summed check timeouts warn only above the 30 minute call limit', t =>
|
|
|
247
247
|
assert.deepEqual(codes(check(tight).report), ['check_budget_over_call_limit']);
|
|
248
248
|
});
|
|
249
249
|
|
|
250
|
+
test('--call-timeout-minutes 放宽整步期限:45 分钟的检查在 60 分钟期限下不报,非法值报 error', t => {
|
|
251
|
+
const checks = [cmd('a', ['a'], 1500000), cmd('b', ['b'], 1200000)];
|
|
252
|
+
assert.deepEqual(codes(check(project(t, {checks})).report), ['check_budget_over_call_limit']);
|
|
253
|
+
const widened = project(t, {checks, plan: {permissions: ['--allow-development', '--call-timeout-minutes', '60']}});
|
|
254
|
+
assert.deepEqual(check(widened).report.findings, []);
|
|
255
|
+
const short = project(t, {checks, plan: {permissions: ['--allow-development', '--call-timeout-minutes', '40']}});
|
|
256
|
+
const r = check(short);
|
|
257
|
+
assert.deepEqual(r.report.findings.map(item => [item.code, item.limitMs]), [['check_budget_over_call_limit', 2400000]]);
|
|
258
|
+
const bad = project(t, {checks: [cmd('a', ['a'])], plan: {permissions: ['--allow-development', '--call-timeout-minutes', '90']}});
|
|
259
|
+
assert.deepEqual(check(bad).report.findings.map(item => [item.level, item.code]), [['error', 'call_timeout_invalid']]);
|
|
260
|
+
// 计划不写 checks、或参数重复时也要提前报出(宿主同样会拒绝)
|
|
261
|
+
const noChecks = project(t, {plan: {permissions: ['--allow-development', '--call-timeout-minutes', '90']}});
|
|
262
|
+
assert.deepEqual(check(noChecks).report.findings.map(item => [item.level, item.code]), [['error', 'call_timeout_invalid']]);
|
|
263
|
+
const twice = project(t, {checks: [cmd('a', ['a'])], plan: {permissions: ['--call-timeout-minutes', '60', '--call-timeout-minutes', '90']}});
|
|
264
|
+
assert.deepEqual(check(twice).report.findings.map(item => [item.level, item.code]), [['error', 'call_timeout_invalid']]);
|
|
265
|
+
});
|
|
266
|
+
|
|
250
267
|
test('the call limit constant still matches the host source', () => {
|
|
251
268
|
const source = fs.readFileSync(path.join(here, '..', 'runtime/js/cm-ai/host-conversation-execution.mjs'), 'utf8');
|
|
252
|
-
assert.match(source, /const outerTimeoutMs=provider\?protection\.timeoutMs
|
|
269
|
+
assert.match(source, /const outerTimeoutMs=provider\?protection\.timeoutMs:\(options\.callTimeoutMs\?\?DEFAULT_CALL_TIMEOUT_MS\);/);
|
|
270
|
+
const limits = fs.readFileSync(path.join(here, '..', 'runtime/js/cm-ai/call-timeout.mjs'), 'utf8');
|
|
271
|
+
assert.match(limits, /export const DEFAULT_CALL_TIMEOUT_MS=1800000;/);
|
|
253
272
|
});
|
|
254
273
|
|
|
255
274
|
test('dirty scope files warn (tracked change and new file), files outside scope do not, --strict turns warns into exit 1', t => {
|
|
@@ -502,6 +521,16 @@ test('a code tree over the review inventory limit is an error before the run sta
|
|
|
502
521
|
assert.match(findings[0].message, /build\.bin/);
|
|
503
522
|
});
|
|
504
523
|
|
|
524
|
+
test('new-run inventory accepts a scoped directory symlink and does not scan its referent', t => {
|
|
525
|
+
const p=project(t,{scope:['alias'],repo:false});
|
|
526
|
+
const specsDir=path.join(p.dir,'specs');
|
|
527
|
+
fs.mkdirSync(specsDir);
|
|
528
|
+
fs.symlinkSync('src',path.join(p.root,'alias'));
|
|
529
|
+
const definition={codeProject:p.root,specsDir,scope:['alias'],requirements:['src/a.js'],
|
|
530
|
+
identity:{repositoryId:'r',runId:'run-1',taskId:'T-001',attempt:1}};
|
|
531
|
+
assert.deepEqual(checkReviewInventory(definition),[]);
|
|
532
|
+
});
|
|
533
|
+
|
|
505
534
|
// Wue specs8 T-001: each of these stopped one advance after the start check had passed.
|
|
506
535
|
test('answers the advance will ask and an invalid interactive QA declaration are errors before launch', t => {
|
|
507
536
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'cm-start-launch-'));
|
|
@@ -542,3 +571,13 @@ test('answers the advance will ask and an invalid interactive QA declaration are
|
|
|
542
571
|
const resumed = checkLaunchInputs({...plan([]), mode: 'resume'}, planFile, definition).filter(item => item.code === 'answers_conflict');
|
|
543
572
|
assert.deepEqual(resumed.map(item => item.level), ['warn']);
|
|
544
573
|
});
|
|
574
|
+
|
|
575
|
+
test('恢复时体检按原运行判断期限:普通运行不得低于创建值,外部模型运行须一致(与宿主同一规则)', () => {
|
|
576
|
+
const codes = r => r.findings.map(item => item.code);
|
|
577
|
+
const plain = {timeoutMs: 3600000, external: false}, external = {timeoutMs: 1800000, external: true};
|
|
578
|
+
assert.deepEqual(codes(callLimit({mode: 'resume', permissions: ['--call-timeout-minutes', '60']}, plain)), []);
|
|
579
|
+
assert.deepEqual(codes(callLimit({mode: 'resume', permissions: []}, plain)), ['call_timeout_invalid']);
|
|
580
|
+
assert.equal(callLimit({mode: 'resume', permissions: ['--call-timeout-minutes', '60']}, {timeoutMs: 1800000, external: false}).limitMs, 3600000);
|
|
581
|
+
assert.deepEqual(codes(callLimit({mode: 'resume', permissions: []}, external)), []);
|
|
582
|
+
assert.deepEqual(codes(callLimit({mode: 'resume', permissions: ['--call-timeout-minutes', '60']}, external)), ['call_timeout_invalid']);
|
|
583
|
+
});
|
package/scripts/cm-task-gate.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// JavaScript authority for CM handoff, review, and read-only completion-plan gates.
|
|
3
|
+
import {assertRealParents,readSymlinkRecord,resolveSymlinkTarget} from '../runtime/js/cm-ai/symlink-material.mjs';
|
|
3
4
|
import fs from 'node:fs';
|
|
4
5
|
import os from 'node:os';
|
|
5
6
|
import path from 'node:path';
|
|
@@ -179,7 +180,25 @@ function resolveStrictFalse(target){
|
|
|
179
180
|
}
|
|
180
181
|
}
|
|
181
182
|
|
|
182
|
-
|
|
183
|
+
const implementationDigest=()=>createHash('sha256').update('cm-implementation-v1\0');
|
|
184
|
+
const pathBytesOrder=(left,right)=>Buffer.compare(Buffer.from(left),Buffer.from(right));
|
|
185
|
+
function bindImplementationEntry(digest,file,type,content){
|
|
186
|
+
digest.update(file).update('\0').update(type).update('\0');
|
|
187
|
+
if(type!=='missing')digest.update(String(content.length)).update('\0').update(content).update('\0');
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// The already validated package contains the same bytes the gate hashes on disk.
|
|
191
|
+
export function projectedImplementationSha256(changes){
|
|
192
|
+
const digest=implementationDigest();
|
|
193
|
+
for(const {path:file,after} of [...changes].sort((a,b)=>pathBytesOrder(a.path,b.path))){
|
|
194
|
+
const type=after?.type??'missing';
|
|
195
|
+
const content=after===null?null:after.type==='symlink'?Buffer.from(after.target):Buffer.from(after.contentBase64,'base64');
|
|
196
|
+
bindImplementationEntry(digest,file,type,content);
|
|
197
|
+
}
|
|
198
|
+
return digest.digest('hex');
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export function implementationSha256(projectRoot,changedFiles,{allowSymlinks=false}={}){
|
|
183
202
|
requireString(projectRoot,'project root');
|
|
184
203
|
const expanded=projectRoot==='~'?os.homedir()
|
|
185
204
|
:projectRoot.startsWith(`~${path.sep}`)?path.join(os.homedir(),projectRoot.slice(2)):projectRoot;
|
|
@@ -191,11 +210,22 @@ export function implementationSha256(projectRoot,changedFiles){
|
|
|
191
210
|
if(error instanceof GateError)throw error;
|
|
192
211
|
throw new GateError(`project root is not an existing directory: ${path.resolve(expanded)}`);
|
|
193
212
|
}
|
|
194
|
-
const digest=
|
|
195
|
-
const files=[...requireRelativeFiles(changedFiles)].sort(
|
|
213
|
+
const digest=implementationDigest();
|
|
214
|
+
const files=[...requireRelativeFiles(changedFiles)].sort(pathBytesOrder);
|
|
196
215
|
for(const relative of files){
|
|
197
216
|
const unresolved=path.join(root,...relative.split('/'));
|
|
198
|
-
|
|
217
|
+
if(allowSymlinks){
|
|
218
|
+
try{assertRealParents(root,relative);}catch{throw new GateError(`changed file has an unsupported parent: ${relative}`);}
|
|
219
|
+
}
|
|
220
|
+
try{
|
|
221
|
+
if(fs.lstatSync(unresolved).isSymbolicLink()){
|
|
222
|
+
if(!allowSymlinks)throw new GateError(`changed file must not be a symlink: ${relative}`);
|
|
223
|
+
const file=readSymlinkRecord(root,relative);
|
|
224
|
+
try{resolveSymlinkTarget(root,relative,file.target);}
|
|
225
|
+
catch{throw new GateError(`changed file resolves outside project root: ${relative}`);}
|
|
226
|
+
bindImplementationEntry(digest,relative,'symlink',Buffer.from(file.target));continue;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
199
229
|
catch(error){if(error?.code!=='ENOENT')throw error;}
|
|
200
230
|
let candidate;
|
|
201
231
|
try{candidate=resolveStrictFalse(unresolved);}
|
|
@@ -203,28 +233,27 @@ export function implementationSha256(projectRoot,changedFiles){
|
|
|
203
233
|
const fromRoot=path.relative(root,candidate);
|
|
204
234
|
if(fromRoot===''||fromRoot==='..'||fromRoot.startsWith(`..${path.sep}`)||path.isAbsolute(fromRoot))
|
|
205
235
|
throw new GateError(`changed file resolves outside project root: ${relative}`);
|
|
206
|
-
digest.update(relative);digest.update('\0');
|
|
207
236
|
let info;
|
|
208
237
|
try{info=fs.statSync(candidate);}catch(error){
|
|
209
|
-
if(error?.code==='ENOENT'){digest
|
|
238
|
+
if(error?.code==='ENOENT'){bindImplementationEntry(digest,relative,'missing',null);continue;}
|
|
210
239
|
throw new GateError(`cannot read changed file ${relative}: ${error.message}`);
|
|
211
240
|
}
|
|
212
241
|
if(!info.isFile())throw new GateError(`changed file must be a regular file or deletion: ${relative}`);
|
|
213
242
|
let content;
|
|
214
243
|
try{content=fs.readFileSync(candidate);}catch(error){throw new GateError(`cannot read changed file ${relative}: ${error.message}`);}
|
|
215
|
-
digest
|
|
244
|
+
bindImplementationEntry(digest,relative,'file',content);
|
|
216
245
|
}
|
|
217
246
|
return digest.digest('hex');
|
|
218
247
|
}
|
|
219
248
|
|
|
220
|
-
function verifyImplementationBinding(payload,{projectRoot=null,allowLegacyUnbound=false}={}){
|
|
249
|
+
function verifyImplementationBinding(payload,{projectRoot=null,allowLegacyUnbound=false,allowSymlinks=false}={}){
|
|
221
250
|
const expected=payload.implementation_sha256;
|
|
222
251
|
if(expected===undefined){
|
|
223
252
|
if(allowLegacyUnbound)return false;
|
|
224
253
|
throw new GateError('handoff is not content-bound; legacy recovery requires --allow-legacy-unbound');
|
|
225
254
|
}
|
|
226
255
|
if(projectRoot===null||projectRoot===undefined)throw new GateError('content-bound handoff requires --project-root');
|
|
227
|
-
if(implementationSha256(projectRoot,payload.changed_files)!==expected)
|
|
256
|
+
if(implementationSha256(projectRoot,payload.changed_files,{allowSymlinks})!==expected)
|
|
228
257
|
throw new GateError('implementation content changed after handoff');
|
|
229
258
|
return true;
|
|
230
259
|
}
|
|
@@ -1019,7 +1048,7 @@ function checkCorrection(selectors,stage){
|
|
|
1019
1048
|
|
|
1020
1049
|
// Only compatibility CLI entries opt into inventory validation. Library callers
|
|
1021
1050
|
// retain the original content-binding contract and exact result shape.
|
|
1022
|
-
export function checkN4({handoff,reviewsDir,feature,task,projectRoot=null,allowLegacyUnbound=false,requireLearning=false,correction=null,inventory=null}){
|
|
1051
|
+
export function checkN4({handoff,reviewsDir,feature,task,projectRoot=null,allowLegacyUnbound=false,requireLearning=false,correction=null,inventory=null,allowSymlinks=false}){
|
|
1023
1052
|
if(correction!==null)return checkCorrection({handoff,reviewsDir,feature,task,projectRoot,correction,allowLegacyUnbound,inventory},'n4');
|
|
1024
1053
|
requireTaskId(task,'task');
|
|
1025
1054
|
const payload=loadHandoff(handoff,{task});
|
|
@@ -1028,12 +1057,12 @@ export function checkN4({handoff,reviewsDir,feature,task,projectRoot=null,allowL
|
|
|
1028
1057
|
const attempt=payload.attempt;
|
|
1029
1058
|
requireExpectedHandoff(handoff,{reviewsDir,feature,task,attempt});
|
|
1030
1059
|
validateAttemptChain(reviewsDir,feature,task,attempt,payload,projectRoot);
|
|
1031
|
-
const contentBound=verifyImplementationBinding(payload,{projectRoot,allowLegacyUnbound});
|
|
1060
|
+
const contentBound=verifyImplementationBinding(payload,{projectRoot,allowLegacyUnbound,allowSymlinks});
|
|
1032
1061
|
const inventoryResult=inventory==='required'?verifyInventory(payload,{projectRoot,reviewsDir,feature,task,allowLegacyUnbound}):{};
|
|
1033
1062
|
return {gate:'n4',task,attempt,outcome:'ready_for_review',handoff_sha256:sha256(handoff),content_bound:contentBound,...inventoryResult};
|
|
1034
1063
|
}
|
|
1035
1064
|
|
|
1036
|
-
export function checkN5({handoff,reviewsDir,feature,task,projectRoot=null,allowLegacyUnbound=false,requireLearning=false,correction=null,inventory=null}){
|
|
1065
|
+
export function checkN5({handoff,reviewsDir,feature,task,projectRoot=null,allowLegacyUnbound=false,requireLearning=false,correction=null,inventory=null,allowSymlinks=false}){
|
|
1037
1066
|
if(correction!==null)return checkCorrection({handoff,reviewsDir,feature,task,projectRoot,correction,allowLegacyUnbound,inventory},'n5');
|
|
1038
1067
|
requireTaskId(task,'task');
|
|
1039
1068
|
const payload=loadHandoff(handoff,{task});
|
|
@@ -1042,7 +1071,7 @@ export function checkN5({handoff,reviewsDir,feature,task,projectRoot=null,allowL
|
|
|
1042
1071
|
const attempt=payload.attempt;
|
|
1043
1072
|
requireExpectedHandoff(handoff,{reviewsDir,feature,task,attempt});
|
|
1044
1073
|
validateAttemptChain(reviewsDir,feature,task,attempt,payload,projectRoot,'n5');
|
|
1045
|
-
const contentBound=verifyImplementationBinding(payload,{projectRoot,allowLegacyUnbound});
|
|
1074
|
+
const contentBound=verifyImplementationBinding(payload,{projectRoot,allowLegacyUnbound,allowSymlinks});
|
|
1046
1075
|
const inventoryResult=inventory==='required'?verifyInventory(payload,{projectRoot,reviewsDir,feature,task,allowLegacyUnbound}):{};
|
|
1047
1076
|
const review=reviewPath(reviewsDir,feature,task,attempt);
|
|
1048
1077
|
const result=validateReview(review,{task,attempt,handoff,changedFiles:payload.changed_files});
|
|
@@ -60,6 +60,39 @@ ${body}
|
|
|
60
60
|
`);
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
test('legacy task gate rejects link leaves and preserves an in-root linked parent',()=>fixture(root=>{
|
|
64
|
+
const reviews=path.join(root,'.reviews');fs.mkdirSync(reviews);
|
|
65
|
+
fs.mkdirSync(path.join(root,'src'));fs.writeFileSync(path.join(root,'src/example.ts'),'fixture');
|
|
66
|
+
fs.symlinkSync('src',path.join(root,'alias'));
|
|
67
|
+
fs.symlinkSync('src/example.ts',path.join(root,'link.ts'));
|
|
68
|
+
const handoff=path.join(reviews,'login-T-001-a1-handoff.json'),review=path.join(reviews,'login-T-001-r1.md');
|
|
69
|
+
const options={handoff,reviewsDir:reviews,feature:'login',task:'T-001',projectRoot:root};
|
|
70
|
+
const bind=(file,implementation)=>{
|
|
71
|
+
writeHandoff(handoff,{implementation});
|
|
72
|
+
const payload=JSON.parse(fs.readFileSync(handoff,'utf8'));payload.changed_files=[file];
|
|
73
|
+
fs.writeFileSync(handoff,JSON.stringify(payload));writeReview(review,{handoff});
|
|
74
|
+
fs.writeFileSync(review,fs.readFileSync(review,'utf8').replace('src/example.ts',file));
|
|
75
|
+
};
|
|
76
|
+
const parentHash=createHash('sha256')
|
|
77
|
+
.update(['cm-implementation-v1','alias/example.ts','file','7','fixture',''].join('\0')).digest('hex');
|
|
78
|
+
const linkHash=implementationSha256(root,['link.ts'],{allowSymlinks:true});
|
|
79
|
+
bind('link.ts',linkHash);
|
|
80
|
+
assert.throws(()=>checkN4(options),/changed file must not be a symlink: link\.ts/);
|
|
81
|
+
assert.throws(()=>checkN5(options),/changed file must not be a symlink: link\.ts/);
|
|
82
|
+
bind('alias/example.ts',parentHash);
|
|
83
|
+
assert.equal(checkN4(options).outcome,'ready_for_review');
|
|
84
|
+
assert.equal(checkN5(options).outcome,'approved');
|
|
85
|
+
}));
|
|
86
|
+
|
|
87
|
+
test('legacy implementation digest omits link support unless explicitly selected',()=>fixture(root=>{
|
|
88
|
+
fs.mkdirSync(path.join(root,'src'));fs.writeFileSync(path.join(root,'src/a.js'),'fixture');
|
|
89
|
+
fs.symlinkSync('src',path.join(root,'alias'));
|
|
90
|
+
fs.symlinkSync('src/a.js',path.join(root,'link.js'));
|
|
91
|
+
assert.throws(()=>implementationSha256(root,['link.js']),/changed file must not be a symlink: link\.js/);
|
|
92
|
+
assert.equal(implementationSha256(root,['alias/a.js']),
|
|
93
|
+
implementationSha256(root,['alias/a.js'],{allowSymlinks:false}));
|
|
94
|
+
}));
|
|
95
|
+
|
|
63
96
|
test('Skill Learning gate rejects missing or pending records and binds reviewed writeback',()=>fixture(root=>{
|
|
64
97
|
const reviews=path.join(root,'.reviews');fs.mkdirSync(reviews);
|
|
65
98
|
fs.mkdirSync(path.join(root,'src'));fs.writeFileSync(path.join(root,'src/example.ts'),'fixture');
|
|
@@ -179,6 +179,7 @@ cm-fix 的 `learning.json`、`diagnosis.json`、`test-edits.json`、`repair-edit
|
|
|
179
179
|
缺答案、结构错误、路径或存档无效会在启动宿主前退出 2。
|
|
180
180
|
|
|
181
181
|
`develop` 回答可能超默认 64 KiB 时,首次启动即在 `PLAN.permissions` 传 `["--input-limit","1048576"]`(上限 4194304);详见 R「开发交付阻断与存档限额」。
|
|
182
|
+
检查整步(含设备流程)可能超默认 30 分钟时,在 `PLAN.permissions` 加 `["--call-timeout-minutes","60"]`(30–60,仅当前会话运行);它不进运行指纹,已因超时停下的运行可在 resume 时补上;恢复时不得低于创建时的值,每次启动在 stderr 报出实际期限。
|
|
182
183
|
|
|
183
184
|
`check` 只运行计划里的真实命令;原始输出打印到驾驶员 stderr,宿主只保存实际退出码和精简证据;静态 `check.json` 不会被读取。单任务和批次 PLAN 可设 `checkTimeoutMs` 作为检查默认超时,每个 `checks` 条目可设 `timeoutMs` 覆盖;均为 1..3600000 的整数毫秒,省略时驱动默认 900000(15 分钟),启动前校验。宿主 `host-check` 对其他调用方的默认值仍是 60000。
|
|
184
185
|
驾驶员收到 `state: "unknown"` 或 `pendingAction: "reconcile"` 的宿主结果时退出 1,并保留原输出供原 run 恢复;不能把有结果的 JSON 当成成功。
|