@aibyzero/cm-workflow 0.16.0 → 0.16.1
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 +20 -0
- package/README.md +2 -2
- package/VERSION +1 -1
- package/docs/installation.md +1 -1
- package/docs/js-workflow-control.md +8 -2
- package/package.json +1 -1
- package/runtime/js/cm-ai/checklist-coverage.mjs +70 -0
- package/runtime/js/cm-ai/effect-contract.mjs +3 -1
- package/runtime/js/cm-ai/host-conversation-execution.mjs +37 -1
- package/runtime/js/cm-ai/review-package.mjs +29 -3
- package/runtime/js/cm-ai/task-runner.mjs +10 -4
- package/runtime/js/cm-fix/cause-invocation.mjs +17 -4
- package/runtime/js/cm-fix/execution.mjs +30 -22
- package/runtime/js/cm-fix/final-review.mjs +18 -11
- package/runtime/js/cm-fix/finish.mjs +14 -1
- package/runtime/js/cm-security/scan.mjs +7 -1
- package/scripts/cm-ai-checklist-coverage.test.mjs +116 -0
- package/scripts/cm-ai-verification-gate.test.mjs +18 -0
- package/scripts/cm-fix-cross-session-host.test.mjs +100 -0
- package/scripts/cm-fix-execution.test.mjs +33 -0
- package/scripts/cm-fix-host.mjs +11 -5
- package/scripts/cm-fix-repair-owner.test.mjs +22 -18
- package/scripts/cm-review-dependency-snapshot.test.mjs +85 -0
- package/scripts/cm-review-inventory.test.mjs +42 -0
- package/scripts/cm-security.test.mjs +24 -0
- package/skills/cm-fix/references/js-host.md +18 -1
- package/templates/auto-update/cm-update.sh +51 -0
|
@@ -19,13 +19,17 @@ import {startFixRun} from '../runtime/js/cm-fix/start.mjs';
|
|
|
19
19
|
import {readProjectInstructionContext} from '../runtime/js/cm-ai/cm-ai-context-refresh.mjs';
|
|
20
20
|
|
|
21
21
|
test('durable repair registers before write, preserves cause approval history and never redispatches lost results',async()=>{
|
|
22
|
-
for(const mode of ['revision','revision-approved','revision-lost','normal','lost','cause','cause-map','unfixed','regression-intent','lesson','retrospective-lost','lesson-intent','lesson-pending','handoff-forged','handoff-legacy','handoff-large']){
|
|
22
|
+
for(const mode of ['revision','revision-approved','revision-draft-mr','revision-lost','normal','lost','cause','cause-map','unfixed','regression-intent','lesson','retrospective-lost','lesson-intent','lesson-pending','handoff-forged','handoff-legacy','handoff-large']){
|
|
23
23
|
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'fix-repair-owner-')));
|
|
24
24
|
const cwd=path.join(root,'code'),specsRoot=path.join(root,'specs');fs.mkdirSync(cwd);fs.mkdirSync(specsRoot);
|
|
25
25
|
fs.writeFileSync(path.join(cwd,'value.mjs'),'export const value=1;');
|
|
26
26
|
fs.writeFileSync(path.join(cwd,'red.mjs'),"import {value} from './value.mjs';if(value!==2){console.error('BUG');process.exit(1)}");
|
|
27
27
|
fs.writeFileSync(path.join(cwd,'existing.mjs'),"import {value} from './value.mjs';if(typeof value!=='number')process.exit(1)");
|
|
28
|
-
|
|
28
|
+
// 收尾只关心「交付模式没在中途变过」,不关心它是哪一种:Git 是单独的 delivery
|
|
29
|
+
// 事件,不是 task_done 的前提。draft-mr 是 cm-init 给带 remote 的仓库生成的默认值。
|
|
30
|
+
const approvedRevision=['revision-approved','revision-draft-mr'].includes(mode);
|
|
31
|
+
if(approvedRevision)fs.writeFileSync(path.join(cwd,'.cm-workflow.json'),
|
|
32
|
+
JSON.stringify({version:1,policies:{delivery:mode==='revision-draft-mr'?'draft-mr':'diff'}}));
|
|
29
33
|
const identity={repositoryId:'fixture',runId:'repair-owner',taskId:'T-FIX-owner',attempt:1};
|
|
30
34
|
const mapPaths=mode==='cause-map'?['docs/codebase-context/00-index.md','docs/codebase-context/07-business-logic.md','docs/codebase-context/09-changelog.md']:[];
|
|
31
35
|
const mapPlan='Create partial value map; cover value.mjs only; other modules unverified.';
|
|
@@ -37,7 +41,7 @@ test('durable repair registers before write, preserves cause approval history an
|
|
|
37
41
|
repair:{scope:['value.mjs',...mapPaths],requirements:['value.mjs']},...(mode.startsWith('cause')||mode.startsWith('revision')?{causeReview:reviewer}:{})}};
|
|
38
42
|
if(mode==='handoff-large')options.configuration.redTest.command=[process.execPath,'-e',
|
|
39
43
|
"import('./value.mjs').then(({value})=>{if(value!==2){process.stderr.write('BUG'+'x'.repeat(128*1024-3));process.exitCode=1;}});//"+'x'.repeat(31*1024)];
|
|
40
|
-
if(
|
|
44
|
+
if(approvedRevision)options.configuration.walkthrough={timeoutMs:2000,flows:[{id:'value-flow',modules:['one'],steps:['Read corrected value'],expected:['Value is 2'],kind:'commands',command:[process.execPath,'red.mjs']}]};
|
|
41
45
|
const authority=createHostReviewAuthority({hostContextId:'fixture-host',reviewerId:reviewer.reviewerId,adapterId:reviewer.adapterId,decide:async()=>({status:'approved'})});
|
|
42
46
|
const causeReview={authorize:authority.authorize,run:createCauseReviewRun(async({prompt},{onEvent})=>{
|
|
43
47
|
const data=JSON.parse(prompt.split('<cm-review-data-json>\n')[1]);
|
|
@@ -47,7 +51,7 @@ test('durable repair registers before write, preserves cause approval history an
|
|
|
47
51
|
},'codex')};
|
|
48
52
|
const learning={contextDigest:digest([]),files:[],application:{contextDigest:digest([]),status:'no_relevant_lesson',summary:'No project instructions in synthetic fixture'}};
|
|
49
53
|
const prepare=async()=>{
|
|
50
|
-
if(
|
|
54
|
+
if(!approvedRevision||!fs.existsSync(path.join(cwd,'AGENTS.md')))return learning;
|
|
51
55
|
const files=readProjectInstructionContext(cwd,[]).map(({content,...metadata})=>metadata);
|
|
52
56
|
return {files,contextDigest:digest(files),application:{contextDigest:digest(files),status:'applied',summary:'Preserve reviewed first-round lessons'}};
|
|
53
57
|
};
|
|
@@ -55,14 +59,14 @@ test('durable repair registers before write, preserves cause approval history an
|
|
|
55
59
|
bridge.attach(row=>{
|
|
56
60
|
if(row.type!=='host_request')return;
|
|
57
61
|
let result={status:'diagnosed',rootCause:'Wrong constant',affectedPaths:['value.mjs'],affectedModules:['one'],crossLayer:mode.startsWith('cause'),plan:mode==='cause-map'?mapPlan:'Correct constant'};
|
|
58
|
-
if(
|
|
62
|
+
if(approvedRevision)result.investigation={discardedAlternatives:[],boundaryAnalysis:null};
|
|
59
63
|
if(row.kind==='fix_retrospective'){
|
|
60
64
|
const state=JSON.parse(fs.readFileSync(path.join(specsRoot,'.reviews','.execution',identity.runId,'state.json')));
|
|
61
65
|
assert.equal(state.records.at(-1).id,row.payload.identity.attempt===2?'fix-revision-retrospective-intent':'fix-retrospective-intent');retrospectives++;
|
|
62
66
|
if(mode==='retrospective-lost'){bridge.close();return;}
|
|
63
67
|
result=mode.startsWith('lesson')?{status:mode==='lesson-pending'?'writeback_pending':'lesson_candidate',candidates:[{classification:'structured',trigger:'Wrong constant',action:'Keep regression check',evidence:['red.mjs']}],reason:mode==='lesson-pending'?'Human assessment required':null}
|
|
64
68
|
:{status:'no_new_lesson',candidates:[],reason:null};
|
|
65
|
-
if(
|
|
69
|
+
if(approvedRevision)result={status:'lesson_candidate',candidates:[{classification:'structured',trigger:row.payload.identity.attempt===2?'Second repair boundary':'First repair boundary',action:'Keep value regression',evidence:['red.mjs']}],reason:null};
|
|
66
70
|
}
|
|
67
71
|
if(row.kind==='fix_repair'){
|
|
68
72
|
const state=JSON.parse(fs.readFileSync(path.join(specsRoot,'.reviews','.execution',identity.runId,'state.json')));
|
|
@@ -86,7 +90,7 @@ test('durable repair registers before write, preserves cause approval history an
|
|
|
86
90
|
// Compare settled state with reopened state when checking durable recovery.
|
|
87
91
|
const settled=async pending=>{await pending;return owner.status();};
|
|
88
92
|
try{
|
|
89
|
-
if(
|
|
93
|
+
if(approvedRevision)startFixRun({specsRoot,identity,configuration:options.configuration});
|
|
90
94
|
await owner.advance({authorized:true});
|
|
91
95
|
if(mode.startsWith('cause')){
|
|
92
96
|
if(mode==='cause-map')assert(!fs.existsSync(path.join(cwd,'docs')));
|
|
@@ -140,7 +144,7 @@ test('durable repair registers before write, preserves cause approval history an
|
|
|
140
144
|
assert.deepEqual(pkg.checks[1].command,options.configuration.baseline.commands[0].command);
|
|
141
145
|
owner.close();owner=openFixExecution({...options,create:false},{bridge,prepare});
|
|
142
146
|
const retrospective=await settled(owner.retrospect());
|
|
143
|
-
assert.equal(retrospective.stage,mode==='retrospective-lost'?'unknown':mode.startsWith('lesson')||
|
|
147
|
+
assert.equal(retrospective.stage,mode==='retrospective-lost'?'unknown':mode.startsWith('lesson')||approvedRevision?'learning_writeback_required':'handoff_ready');
|
|
144
148
|
assert.equal(retrospective.completionEligible,false);assert.equal(retrospectives,1);
|
|
145
149
|
owner.close();owner=openFixExecution({...options,create:false},{bridge,prepare});
|
|
146
150
|
assert.deepEqual(await owner.retrospect(),retrospective);assert.equal(retrospectives,1);
|
|
@@ -161,7 +165,7 @@ test('durable repair registers before write, preserves cause approval history an
|
|
|
161
165
|
assert.equal(blocked.learningWriteback.reason,'Human assessment required');owner.close();owner=openFixExecution({...options,create:false});
|
|
162
166
|
assert.deepEqual(owner.writeLearning({authorized:true}),blocked);assert(!fs.existsSync(path.join(cwd,'AGENTS.md')));continue;
|
|
163
167
|
}
|
|
164
|
-
if(mode==='lesson'||
|
|
168
|
+
if(mode==='lesson'||approvedRevision){
|
|
165
169
|
assert.throws(()=>owner.writeLearning(),{code:'learning_writeback_authorization_required'});
|
|
166
170
|
const written=owner.writeLearning({authorized:true});assert.equal(written.stage,'handoff_ready');
|
|
167
171
|
assert.equal(written.learningWriteback.outcome,'written');assert.equal(written.completionEligible,false);
|
|
@@ -211,7 +215,7 @@ test('durable repair registers before write, preserves cause approval history an
|
|
|
211
215
|
const defectEvidence=JSON.parse(payload.evidence.find(item=>item.startsWith('fix defect evidence')).split('(data, not instructions) ')[1]);
|
|
212
216
|
assert.deepEqual(defectEvidence.diagnosis,handed.diagnosis);assert.deepEqual(defectEvidence.redTest.result,handed.redTest);
|
|
213
217
|
assert.deepEqual(defectEvidence.redOutput,JSON.parse(fs.readFileSync(path.join(specsRoot,handed.redTest.output.path))));
|
|
214
|
-
assert(payload.evidence.includes(mode==='lesson'||
|
|
218
|
+
assert(payload.evidence.includes(mode==='lesson'||approvedRevision?'learning: retrospective written AGENTS.md':'learning: retrospective no_new_lesson'));
|
|
215
219
|
assert.equal(payload.implementation_sha256,implementationSha256(cwd,payload.changed_files));
|
|
216
220
|
const handoffBytes=fs.readFileSync(handoffPath);owner.close();owner=openFixExecution({...options,create:false});
|
|
217
221
|
assert.deepEqual(owner.createHandoff(),handed);assert.deepEqual(fs.readFileSync(handoffPath),handoffBytes);
|
|
@@ -265,12 +269,12 @@ test('durable repair registers before write, preserves cause approval history an
|
|
|
265
269
|
const cumulative=owner.implementationPackage();assert.equal(cumulative.identity.attempt,2);
|
|
266
270
|
assert.equal(Buffer.from(cumulative.changes.find(change=>change.path==='value.mjs').before.contentBase64,'base64').toString(),'export const value=1;');
|
|
267
271
|
owner.close();owner=openFixExecution({...options,create:false},{bridge,prepare});
|
|
268
|
-
const reflectedAgain=await settled(owner.retrospect());assert.equal(reflectedAgain.stage,
|
|
272
|
+
const reflectedAgain=await settled(owner.retrospect());assert.equal(reflectedAgain.stage,approvedRevision?'revision_learning_writeback_required':'revision_handoff_ready');
|
|
269
273
|
assert.equal(reflectedAgain.revisionRetrospective.identity.attempt,2);assert.equal(retrospectives,2);
|
|
270
274
|
assert.equal(reflectedAgain.revisionRetrospective.packageDigest,cumulative.packageDigest);assert.equal(reflectedAgain.completionEligible,false);
|
|
271
275
|
owner.close();owner=openFixExecution({...options,create:false});assert.deepEqual(owner.status(),reflectedAgain);
|
|
272
276
|
assert.deepEqual(await owner.retrospect(),reflectedAgain);assert.equal(retrospectives,2);
|
|
273
|
-
if(
|
|
277
|
+
if(approvedRevision){
|
|
274
278
|
assert.throws(()=>owner.writeLearning(),{code:'learning_writeback_authorization_required'});
|
|
275
279
|
assert.equal(owner.createHandoff().stage,'revision_learning_writeback_required');
|
|
276
280
|
const written=owner.writeLearning({authorized:true});assert.equal(written.stage,'revision_handoff_ready');
|
|
@@ -286,7 +290,7 @@ test('durable repair registers before write, preserves cause approval history an
|
|
|
286
290
|
const secondPath=path.join(specsRoot,'.reviews','fix-owner-T-FIX-owner-a2-handoff.json');
|
|
287
291
|
const secondBytes=fs.readFileSync(secondPath),secondHandoff=loadHandoff(secondPath,{task:identity.taskId,attempt:2});
|
|
288
292
|
assert(secondHandoff.evidence.some(item=>item.startsWith('fix prior review')&&item.includes('F1')));
|
|
289
|
-
if(
|
|
293
|
+
if(approvedRevision){assert(secondHandoff.evidence.includes('learning: retrospective written AGENTS.md'));assert(secondHandoff.changed_files.includes('AGENTS.md'));}
|
|
290
294
|
assert.deepEqual(fs.readFileSync(handoffPath),handoffBytes);assert.equal(handedAgain.completionEligible,false);
|
|
291
295
|
const reviewAgain=owner.finalReviewPackage();assert.equal(reviewAgain.identity.attempt,2);assert.equal(reviewAgain.handoff.sha256,handedAgain.revisionHandoff.handoffSha256);
|
|
292
296
|
assert.equal(Buffer.from(reviewAgain.changes.find(change=>change.path==='value.mjs').before.contentBase64,'base64').toString(),'export const value=1;');
|
|
@@ -300,15 +304,15 @@ test('durable repair registers before write, preserves cause approval history an
|
|
|
300
304
|
for(const event of [{event:'thread.started',provider_thread:'second-revision-reviewer'},{event:'turn.started',item_type:null},
|
|
301
305
|
{event:'item.completed',item_type:'agent_message'},{event:'turn.completed',item_type:null},{event:'process_closed',exit_code:0,signal:null,timed_out:false}])assert.equal(onEvent(event),true);
|
|
302
306
|
return {status:'succeeded',value:{...request.payload.priorReview,packageDigest:reviewAgain.packageDigest,examinedPaths:reviewPaths(reviewAgain),
|
|
303
|
-
...(
|
|
307
|
+
...(approvedRevision?{verdict:'approved',findings:[]}: {})}};
|
|
304
308
|
}}});
|
|
305
309
|
assert.equal((await owner.reviewFinal()).stage,'revision_final_review_evidence_required');
|
|
306
|
-
const reviewedAgain=owner.publishReview();assert.equal(reviewedAgain.stage,
|
|
310
|
+
const reviewedAgain=owner.publishReview();assert.equal(reviewedAgain.stage,approvedRevision?'revision_completion_gate_required':'revision_review_limit_reached');
|
|
307
311
|
assert.equal(reviewedAgain.completionEligible,false);assert.equal(calls,2);
|
|
308
312
|
owner.close();owner=openFixExecution({...options,create:false});assert.deepEqual(owner.status(),reviewedAgain);
|
|
309
313
|
assert.deepEqual(await owner.reviewFinal(),reviewedAgain);assert.equal(calls,2);
|
|
310
314
|
await assert.rejects(owner.prepareRevision({authorized:true}),{code:'fix_revision_unavailable'});
|
|
311
|
-
if(
|
|
315
|
+
if(approvedRevision){
|
|
312
316
|
const gated=owner.checkCompletionGate();assert.equal(gated.stage,'revision_post_review_regression_required');
|
|
313
317
|
assert.equal(gated.revisionN5.gate.attempt,2);assert.equal(gated.completionEligible,false);
|
|
314
318
|
const reviewPath=path.join(specsRoot,'.reviews','fix-owner-T-FIX-owner-r2.md'),reviewBytes=fs.readFileSync(reviewPath);
|
|
@@ -355,8 +359,8 @@ test('durable repair registers before write, preserves cause approval history an
|
|
|
355
359
|
assert(archive.includes('先前轮次(历史记录,不替代当前审查)'));assert(archive.includes('changes_requested'));
|
|
356
360
|
assert(fs.readFileSync(path.join(specsRoot,'METRICS.md'),'utf8').includes('| 2 | 1 |'));
|
|
357
361
|
}
|
|
358
|
-
fs.appendFileSync(path.join(cwd,'value.mjs'),' ');assert.equal(owner.status().stage,
|
|
359
|
-
if(
|
|
362
|
+
fs.appendFileSync(path.join(cwd,'value.mjs'),' ');assert.equal(owner.status().stage,approvedRevision?'revision_learning_writeback_evidence_required':'revision_repair_evidence_required');
|
|
363
|
+
if(approvedRevision){assert.equal(owner.status().completionEligible,false);assert.equal(owner.status().completionHistory.runDoneEventIds.length,1);}
|
|
360
364
|
assert.deepEqual(owner.status().revision,revised.revision);continue;
|
|
361
365
|
}
|
|
362
366
|
if(mode==='cause'){
|
|
@@ -75,3 +75,88 @@ test('legacy baselines retain already-recorded dependency files and their drift
|
|
|
75
75
|
fs.unlinkSync(path.join(root,'.venv','recorded.txt'));
|
|
76
76
|
assert.throws(()=>createReviewPackage({root,baseline,checks}),{code:'out_of_scope'});
|
|
77
77
|
});
|
|
78
|
+
|
|
79
|
+
function installCocoaPods(root,prefix){
|
|
80
|
+
const pods=path.join(root,prefix);
|
|
81
|
+
fs.mkdirSync(path.join(pods,'Headers/Private/DoubleConversion/double-conversion'),{recursive:true});
|
|
82
|
+
fs.mkdirSync(path.join(pods,'Pods.xcodeproj'));
|
|
83
|
+
fs.writeFileSync(path.join(pods,'Manifest.lock'),'PODFILE CHECKSUM: synthetic');
|
|
84
|
+
fs.writeFileSync(path.join(path.dirname(pods),'Podfile.lock'),'PODFILE CHECKSUM: synthetic');
|
|
85
|
+
fs.writeFileSync(path.join(pods,'DoubleConversion.h'),'generated pod header');
|
|
86
|
+
fs.symlinkSync('../../../../DoubleConversion.h',path.join(pods,'Headers/Private/DoubleConversion/double-conversion/bignum-dtoa.h'));
|
|
87
|
+
return pods;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
test('generated CocoaPods trees stay out of the snapshot instead of blocking it',t=>{
|
|
91
|
+
const {root,options}=fixture(t);
|
|
92
|
+
installCocoaPods(root,'mobile/ios/Pods');
|
|
93
|
+
const baseline=captureReviewBaseline(options);
|
|
94
|
+
// Podfile.lock is authored and checked in; only the generated tree disappears.
|
|
95
|
+
assert.deepEqual(baseline.files.map(f=>f.path),
|
|
96
|
+
['mobile/ios/Podfile.lock','requirements.md','src/main.py']);
|
|
97
|
+
fs.writeFileSync(path.join(root,'src/main.py'),'after');
|
|
98
|
+
const pkg=createReviewPackage({root,baseline,checks});
|
|
99
|
+
assert.equal(verifyReviewPackage({root,baseline,checks,reviewPackage:pkg,expectedDigest:pkg.packageDigest}).outcome,'matched');
|
|
100
|
+
for(const field of ['scope','requirements'])
|
|
101
|
+
assert.throws(()=>captureReviewBaseline({...options,[field]:['mobile/ios/Pods/DoubleConversion.h']}),{code:'excluded_snapshot_path'});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test('an authored pods directory is still snapshotted and its symlinks still fail closed',t=>{
|
|
105
|
+
const {root,options}=fixture(t);
|
|
106
|
+
fs.mkdirSync(path.join(root,'src/pods'),{recursive:true});
|
|
107
|
+
fs.writeFileSync(path.join(root,'src/pods/scheduler.py'),'business code');
|
|
108
|
+
assert.deepEqual(captureReviewBaseline(options).files.map(f=>f.path),
|
|
109
|
+
['requirements.md','src/main.py','src/pods/scheduler.py']);
|
|
110
|
+
fs.symlinkSync('../../requirements.md',path.join(root,'src/pods/linked.py'));
|
|
111
|
+
assert.throws(()=>captureReviewBaseline(options),{code:'unsupported_file'});
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test('a Pods directory missing any one CocoaPods artefact keeps the symlink guard',t=>{
|
|
115
|
+
for(const missing of ['Pods/Manifest.lock','Pods/Pods.xcodeproj','Podfile.lock']){
|
|
116
|
+
const {root,options}=fixture(t);
|
|
117
|
+
installCocoaPods(root,'mobile/ios/Pods');
|
|
118
|
+
fs.rmSync(path.join(root,'mobile/ios',missing),{recursive:true,force:true});
|
|
119
|
+
assert.throws(()=>captureReviewBaseline(options),{code:'unsupported_file'},missing);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// The traversal and the scope guard must ask one predicate, not two that agree
|
|
124
|
+
// by coincidence. They once did not: the traversal probed every directory for
|
|
125
|
+
// the generated entries while the guard additionally required the name "pods".
|
|
126
|
+
// A directory called src/ holding an empty Manifest.lock and an empty
|
|
127
|
+
// Pods.xcodeproj/ was then skipped whole — taking a file explicitly declared in
|
|
128
|
+
// scope out of the review with no error raised anywhere.
|
|
129
|
+
test('a directory that is not named pods is never treated as a generated tree',t=>{
|
|
130
|
+
const {root,options}=fixture(t);
|
|
131
|
+
fs.writeFileSync(path.join(root,'src/Manifest.lock'),'');
|
|
132
|
+
fs.mkdirSync(path.join(root,'src/Pods.xcodeproj'));
|
|
133
|
+
fs.writeFileSync(path.join(root,'Podfile.lock'),'');
|
|
134
|
+
const baseline=captureReviewBaseline(options);
|
|
135
|
+
assert.ok(baseline.files.some(f=>f.path==='src/main.py'),
|
|
136
|
+
'a declared scope file was silently dropped from the snapshot');
|
|
137
|
+
// A file added inside the disguise must stay visible: out_of_scope is the
|
|
138
|
+
// snapshot seeing it and refusing it, which is the opposite of vanishing.
|
|
139
|
+
fs.writeFileSync(path.join(root,'src/added.py'),'new');
|
|
140
|
+
fs.writeFileSync(path.join(root,'src/main.py'),'after');
|
|
141
|
+
assert.throws(()=>createReviewPackage({root,baseline,checks}),{code:'out_of_scope'},
|
|
142
|
+
'a file added after the baseline stayed invisible to the review package');
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
// Whatever the predicate accepts leaves the review silently, so the two callers
|
|
146
|
+
// must never diverge again. Assert they are the same predicate, not two rules.
|
|
147
|
+
test('the scope guard rejects exactly what the traversal skips',t=>{
|
|
148
|
+
const {root,options}=fixture(t);
|
|
149
|
+
installCocoaPods(root,'mobile/ios/Pods');
|
|
150
|
+
assert.deepEqual(captureReviewBaseline(options).files.map(f=>f.path),
|
|
151
|
+
['mobile/ios/Podfile.lock','requirements.md','src/main.py']);
|
|
152
|
+
for(const field of ['scope','requirements'])
|
|
153
|
+
assert.throws(()=>captureReviewBaseline({...options,[field]:['mobile/ios/Pods/DoubleConversion.h']}),
|
|
154
|
+
{code:'excluded_snapshot_path'},field);
|
|
155
|
+
// Remove one artefact: the tree comes back into the snapshot, and the guard
|
|
156
|
+
// must stop rejecting it in the same step.
|
|
157
|
+
fs.rmSync(path.join(root,'mobile/ios/Podfile.lock'));
|
|
158
|
+
fs.rmSync(path.join(root,'mobile/ios/Pods/Headers'),{recursive:true,force:true});
|
|
159
|
+
assert.ok(captureReviewBaseline(options).files.some(f=>f.path==='mobile/ios/Pods/DoubleConversion.h'));
|
|
160
|
+
assert.deepEqual(captureReviewBaseline({...options,scope:['mobile/ios/Pods/DoubleConversion.h']})
|
|
161
|
+
.files.some(f=>f.path==='mobile/ios/Pods/DoubleConversion.h'),true);
|
|
162
|
+
});
|
|
@@ -296,3 +296,45 @@ test('new specification and legacy packages both retain receipt completion eligi
|
|
|
296
296
|
assert.equal(verifyReviewPackage({root:f.code,baseline:pkg===current?baseline:legacyBaseline,checks,reviewPackage:pkg,expectedDigest:pkg.packageDigest}).outcome,'matched');
|
|
297
297
|
}
|
|
298
298
|
});
|
|
299
|
+
|
|
300
|
+
// A repository that merely contains mobile/.env.example used to be impossible
|
|
301
|
+
// to review: walk() validates every discovered path, so the placeholder aborted
|
|
302
|
+
// the whole baseline capture rather than being skipped. Committed placeholders
|
|
303
|
+
// are ordinary source; the real secret files must still be refused.
|
|
304
|
+
test('committed environment placeholders are inventoried while real secret files stay refused',()=>fixture(root=>{
|
|
305
|
+
fs.mkdirSync(path.join(root,'mobile'));
|
|
306
|
+
write(root,'mobile/.env.example','API_URL=https://example.invalid\n');
|
|
307
|
+
write(root,'.env.sample','TOKEN=replace-me\n');
|
|
308
|
+
const baseline=capture(root);
|
|
309
|
+
const inventoried=baseline.files.map(f=>f.path);
|
|
310
|
+
assert.ok(inventoried.includes('mobile/.env.example'),'placeholder missing from the inventory');
|
|
311
|
+
assert.ok(inventoried.includes('.env.sample'),'placeholder missing from the inventory');
|
|
312
|
+
// Inventoried means hashed, not disclosed: only selected scope carries a body.
|
|
313
|
+
const placeholder=baseline.files.find(f=>f.path==='mobile/.env.example');
|
|
314
|
+
assert.equal(placeholder.contentBase64,undefined);
|
|
315
|
+
assert.equal(typeof placeholder.sha256,'string');
|
|
316
|
+
|
|
317
|
+
// Selecting a placeholder as ordinary source is allowed too.
|
|
318
|
+
const selected=captureReviewBaseline({root,identity,scope:['mobile/.env.example'],
|
|
319
|
+
requirements:['requirements.md']}).files.find(f=>f.path==='mobile/.env.example');
|
|
320
|
+
assert.equal(Buffer.from(selected.contentBase64,'base64').toString(),
|
|
321
|
+
'API_URL=https://example.invalid\n');
|
|
322
|
+
|
|
323
|
+
for(const secret of ['.env','.env.local','.env.production','.env.example.bak']){
|
|
324
|
+
write(root,secret,'SECRET=1\n');
|
|
325
|
+
assert.throws(()=>capture(root),{code:'unsupported_path'},`${secret} was not refused`);
|
|
326
|
+
assert.throws(()=>captureReviewBaseline({root,identity,scope:[secret],
|
|
327
|
+
requirements:['requirements.md']}),{code:'unsupported_path'},`${secret} was selectable`);
|
|
328
|
+
fs.rmSync(path.join(root,secret));
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// The placeholder name must not become a way to smuggle a real secret in.
|
|
332
|
+
fs.writeFileSync(path.join(root,'.env'),'SECRET=real\n');
|
|
333
|
+
fs.symlinkSync('.env',path.join(root,'.env.disguise'));
|
|
334
|
+
fs.renameSync(path.join(root,'.env.disguise'),path.join(root,'.env.template'));
|
|
335
|
+
assert.throws(()=>capture(root),{code:'unsupported_path'},'the .env sibling was not refused');
|
|
336
|
+
fs.rmSync(path.join(root,'.env'));
|
|
337
|
+
assert.throws(()=>capture(root),/unsupported_file|unsupported_path|read_failed/,
|
|
338
|
+
'a symlink wearing a placeholder name was captured');
|
|
339
|
+
fs.rmSync(path.join(root,'.env.template'));
|
|
340
|
+
}));
|
|
@@ -58,6 +58,30 @@ test('no change is distinct from partial and missing tools do not pass',t=>{
|
|
|
58
58
|
assert.ok(r.tools.every(v=>v.reason==='tool_missing'));assert.equal(r.aiReview,'pending');
|
|
59
59
|
});
|
|
60
60
|
|
|
61
|
+
// .env.example and friends are committed placeholder files meant to be copied.
|
|
62
|
+
// Treating them as real secret files hid exactly the case worth scanning: a real
|
|
63
|
+
// key pasted into the example. Only these four explicit suffixes are readable.
|
|
64
|
+
test('committed env examples are scanned while real env files stay protected',t=>{
|
|
65
|
+
const f=fixture(t);
|
|
66
|
+
for(const name of ['.env.example','.env.sample','.env.template','.env.dist'])f.put(name,'API_KEY=replace-me\n');
|
|
67
|
+
f.put('nested/.env.example','TOKEN=replace-me\n');
|
|
68
|
+
for(const name of ['.env','.env.local','.env.production','.env.example.bak'])f.put(name,'API_KEY=real\n');
|
|
69
|
+
f.git('add','.');
|
|
70
|
+
const r=inventory(f.project,{all:true});
|
|
71
|
+
const gap=name=>r.gaps.some(v=>v.path===name&&v.reason==='protected_path_not_read');
|
|
72
|
+
const read=name=>r.files.some(v=>v.path===name);
|
|
73
|
+
for(const name of ['.env.example','.env.sample','.env.template','.env.dist','nested/.env.example']){
|
|
74
|
+
assert.equal(read(name),true,`${name} 应当被扫描`);
|
|
75
|
+
assert.equal(gap(name),false,`${name} 不应记为受保护跳过`);
|
|
76
|
+
}
|
|
77
|
+
// Real secret files keep their existing protection, including a suffix that
|
|
78
|
+
// merely contains "example" rather than ending with it.
|
|
79
|
+
for(const name of ['.env','.env.local','.env.production','.env.example.bak']){
|
|
80
|
+
assert.equal(gap(name),true,`${name} 应当仍被保护`);
|
|
81
|
+
assert.equal(read(name),false,`${name} 不应被读取`);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
|
|
61
85
|
test('symlink ancestor, protected files and scanner controls are visible gaps',t=>{
|
|
62
86
|
const f=fixture(t);f.put('dir/file.py','ok');f.put('.env','private fixture');f.put('.gitleaks.toml','malicious rule');f.git('add','.');
|
|
63
87
|
fs.renameSync(path.join(f.project,'dir'),path.join(f.base,'outside'));
|
|
@@ -11,6 +11,10 @@
|
|
|
11
11
|
纯视觉替代、裸项目走下文原owner分支,不能伪造命令或specs跨过。
|
|
12
12
|
2. 从当前真实宿主确定 `--runtime codex|claude`,不能让模型选择另一端规避失败。
|
|
13
13
|
用真实会话身份作为 `--host-context`;恢复必须保留原身份、配置与 runtime,不冒用旧会话。
|
|
14
|
+
换会话恢复时,`--host-context` 填当前真实会话,另加 `--original-host-context` 填创建这次运行的旧会话 ID
|
|
15
|
+
(取自 `specs/.reviews/.execution/<runId>/state.json` 首条 `fix-configuration` 记录的
|
|
16
|
+
`configuration.hostContextId`)。durable 配置与指纹保持原样、旧记录一字不改;填错只会 `fingerprint_mismatch`
|
|
17
|
+
失败退出。两个会话身份都算宿主:授权凭据两者皆可,reviewer 必须同时独立于两者。同会话重开不带此参数。
|
|
14
18
|
3. 配置是数据文件,不是脚本模块。读取 `../../../scripts/cm-fix-host.mjs` 的配置解析与
|
|
15
19
|
`--help`,按已批准范围填写 `specsRoot`、`identity`、`defect`、`reproduction`;后者为
|
|
16
20
|
`{cwd, command, expectedFailure:{exitCode,outputIncludes}, timeoutMs}`,命令使用 argv 数组。
|
|
@@ -46,6 +50,17 @@ node "{CM_WORKFLOW_ROOT}/scripts/cm-fix-host.mjs" serve \
|
|
|
46
50
|
复现/红测/存量基线/修后及审后回归/命令走查使用同一原生specs只读沙箱;日志、证据和Learning仍由原owner负责。
|
|
47
51
|
固定命令执行器使用本机Codex sandbox,不调用模型;Claude宿主的推理和Review仍属Claude,不借用Codex身份或诊断。
|
|
48
52
|
|
|
53
|
+
沙箱里 `network={enabled=false}`,而这个开关同时管着 unix domain socket 的 listen。于是**凡是要开本地
|
|
54
|
+
IPC socket 的命令都会失败**,典型的是 `tsx` CLI(启动时在 TMPDIR 建 `<pid>.pipe`,报
|
|
55
|
+
`Error: listen EPERM`),`vitest` 等同理;写 TMPDIR 文件本身不受影响。这不是配置能绕开的:放开它就等于
|
|
56
|
+
给测试命令放开整个外网。配 `baseline.commands` / `redTest` / `walkthrough` 时请避开这类命令,例如把
|
|
57
|
+
`npm test`(内部串联 12 个 `tsx xxx.test.ts`)换成逐文件的
|
|
58
|
+
`node --import ./node_modules/tsx/dist/loader.mjs <file>`,覆盖面不变而沙箱能跑。
|
|
59
|
+
|
|
60
|
+
沙箱内失败只会留下 `outcome:"failed"` 和 `host check exited N`——原始输出**有意**不进证据(可能含密钥、
|
|
61
|
+
且不稳定)。要看真实原因,手工重放 `specsPermissionArgs` 拼出的那条 `codex sandbox ... -- <命令>`。
|
|
62
|
+
配置里留了跑不了的命令,代价是修复前后都失败、回归判 `unresolved_failure`,整轮卡在 `regression_blocked`。
|
|
63
|
+
|
|
49
64
|
`fix_test_author`/`fix_repair`请求若有`editMode:"protected-text-v1"`,当前会话只读取和生成提案,**不直接修改文件**。
|
|
50
65
|
按请求scope和expected返回`{outcome,edits:[{path,beforeSha256,content}]}`,content为完整UTF-8正文,null删除已有文件,
|
|
51
66
|
beforeSha256严格复制expected中该路径的摘要(原不存在则null);不能改路径范围或先自行落盘。blocked须edits为空数组。
|
|
@@ -132,7 +147,9 @@ handoff → 最终独立 Review/发布 → 原 N5 → 审后回归/走查 →
|
|
|
132
147
|
第二次修复仍需 fresh 独立 Review;不得重置 ≤2 轮上限。unknown 不重派。
|
|
133
148
|
|
|
134
149
|
修复完成仅认原 `finish` 的当前结果与证据;待授权、失败、漂移、缺证据如实报告,
|
|
135
|
-
|
|
150
|
+
不手工补成功。finish 接受 `policies.delivery` 的任一取值,只要求它在收尾写记录期间不变;
|
|
151
|
+
它写档案/METRICS/task_done,**不执行 Git**——branch/draft-mr 的提交、推送、开 MR 仍由执行者按
|
|
152
|
+
SKILL 第 7 步单独完成并记 `delivery` 事件。Git/发布/安装都不在这些开关的权限内。
|
|
136
153
|
退出通道用 `host_close` 或 EOF;只有用户明确取消才发 `cancel`。
|
|
137
154
|
|
|
138
155
|
本接线是源 Skill 指令,不证明安装副本已加载或真实双宿主验收。保持原输出格式,
|
|
@@ -12,6 +12,7 @@ MANIFEST="$ROOT/manifest.txt"
|
|
|
12
12
|
LOG="$ROOT/update.log"
|
|
13
13
|
STAMP="$ROOT/.last-check"
|
|
14
14
|
LOCK="$ROOT/.lock"
|
|
15
|
+
DISCARDED="$ROOT/discarded" # reset 前抢救出来的本地改动补丁
|
|
15
16
|
ANNOUNCE="$ROOT/pending-announce" # 下次 Claude Code 启动时播报,由 cm-announce.sh 消费
|
|
16
17
|
REMOTE="${CM_UPDATE_REMOTE:-git@github.com:kingxiaozhe/cm-workflow.git}" # 团队 fork 用环境变量覆盖,别改文件(会被自愈还原)
|
|
17
18
|
BRANCH="${CM_UPDATE_BRANCH:-main}"
|
|
@@ -23,6 +24,35 @@ export GIT_SSH_COMMAND="ssh -o BatchMode=yes -o StrictHostKeyChecking=accept-new
|
|
|
23
24
|
|
|
24
25
|
mkdir -p "$ROOT"
|
|
25
26
|
|
|
27
|
+
# repo/ 是更新器的缓存,不是给人开发的克隆:每次更新都会 reset --hard + clean -fd。
|
|
28
|
+
# 说明文件放在缓存目录之外,否则会被 clean 掉。
|
|
29
|
+
if [ ! -f "$ROOT/README.md" ]; then
|
|
30
|
+
cat >"$ROOT/README.md" <<'CMREADME'
|
|
31
|
+
# ~/.cm-workflow 是 CM Workflow 的私有工作目录
|
|
32
|
+
|
|
33
|
+
## repo/ 是缓存,不要在里面改代码
|
|
34
|
+
|
|
35
|
+
`repo/` 由自动更新器管理。每次更新都会执行:
|
|
36
|
+
|
|
37
|
+
git reset --hard origin/<分支>
|
|
38
|
+
git clean -qfd
|
|
39
|
+
|
|
40
|
+
**它里面任何未提交的改动和未跟踪的新文件都会被丢弃,不另行询问。**
|
|
41
|
+
它看起来是个正常的 git 克隆(remote 指向真仓库、`git log` 正常),
|
|
42
|
+
但不要拿它当开发目录——请另外 `git clone` 一份。
|
|
43
|
+
|
|
44
|
+
更新器在丢弃前会做两件事:把改动存成补丁放到 `discarded/`,并在
|
|
45
|
+
`update.log` 里记一行、同时发一条系统通知。补丁可以用
|
|
46
|
+
`git apply` 打回你自己的克隆。
|
|
47
|
+
|
|
48
|
+
## 其他内容
|
|
49
|
+
|
|
50
|
+
- `update.log`:更新日志
|
|
51
|
+
- `logs/`:各工作流的运行日志(本机私有,不外发)
|
|
52
|
+
- `discarded/`:被更新器丢弃的本地改动补丁
|
|
53
|
+
CMREADME
|
|
54
|
+
fi
|
|
55
|
+
|
|
26
56
|
log() { printf '%s %s\n' "$(date '+%F %T')" "$*" >>"$LOG"; }
|
|
27
57
|
notify() { osascript -e "display notification \"$2\" with title \"$1\"" >/dev/null 2>&1 || true; }
|
|
28
58
|
die() { log "✗ $*"; exit 1; }
|
|
@@ -199,6 +229,27 @@ if [ "$local_sha" = "$remote_sha" ] && [ -f "$MANIFEST" ] && [ "$FORCE" = 0 ]; t
|
|
|
199
229
|
fi
|
|
200
230
|
|
|
201
231
|
new_commits="$(git log --oneline "HEAD..origin/$BRANCH" 2>/dev/null | head -5)"
|
|
232
|
+
|
|
233
|
+
# 缓存目录里不该有人工改动,但确实发生过。丢弃之前先存一份补丁并明确告警,
|
|
234
|
+
# 不要让它无声消失。抢救失败不阻塞更新——缓存与远端一致才是这里的第一要务。
|
|
235
|
+
dirty="$(git status --porcelain 2>/dev/null)"
|
|
236
|
+
if [ -n "$dirty" ]; then
|
|
237
|
+
dirty_n="$(printf '%s\n' "$dirty" | wc -l | tr -d ' ')"
|
|
238
|
+
mkdir -p "$DISCARDED"
|
|
239
|
+
patch="$DISCARDED/$(date '+%Y%m%dT%H%M%S').patch"
|
|
240
|
+
{
|
|
241
|
+
printf '# 更新器在 %s 丢弃的本地改动(%s 个条目)\n' "$(date '+%F %T')" "$dirty_n"
|
|
242
|
+
printf '# 已跟踪文件的改动可用 git apply 打回自己的克隆;未跟踪文件只列出路径。\n\n'
|
|
243
|
+
git diff HEAD 2>/dev/null
|
|
244
|
+
printf '\n# 未跟踪文件(内容未保存):\n'
|
|
245
|
+
git ls-files --others --exclude-standard 2>/dev/null | sed 's|^|# |'
|
|
246
|
+
} >"$patch" 2>/dev/null || patch=""
|
|
247
|
+
log "⚠ repo/ 有 $dirty_n 处本地改动,将被更新丢弃:"
|
|
248
|
+
log "$(printf '%s\n' "$dirty" | head -20 | sed 's|^| |')"
|
|
249
|
+
[ -n "$patch" ] && log " 已存补丁:$patch"
|
|
250
|
+
notify "CM Workflow 更新" "repo/ 的 $dirty_n 处本地改动已被丢弃,补丁见 discarded/"
|
|
251
|
+
fi
|
|
252
|
+
|
|
202
253
|
git reset --hard --quiet "origin/$BRANCH" || die "reset 到 origin/$BRANCH 失败"
|
|
203
254
|
git clean -qfd
|
|
204
255
|
VERSION="$(cat "$REPO/VERSION" 2>/dev/null || echo 未知)"
|