隔离小壹生产代理的技能来源

This commit is contained in:
WuYongJie 2026-11-27 22:42:09 +08:00
parent a4e272e6b5
commit 4c8ed7fe7e
3 changed files with 29 additions and 3 deletions

View File

@ -44,7 +44,8 @@ export async function createPhotoCraftExtensions(host, existing = [], {
noExtensions: true, noThemes: true, noContextFiles: true,
additionalExtensionPaths: includeGoal ? [path.join(goalPackage, '.pi', 'extensions', 'pi-goal', 'index.ts')] : [],
additionalSkillPaths: includeGoal ? [path.join(goalPackage, 'skills'), productionSkills] : [],
noSkills: !includeProjectResources, noPromptTemplates: !includeProjectResources,
noSkills: includeGoal || !includeProjectResources,
noPromptTemplates: !includeProjectResources,
systemPromptOverride: () => systemPrompt,
appendSystemPrompt: [],
extensionsOverride: result => ({...result, extensions:[...existing, ...result.extensions]}),

View File

@ -1227,7 +1227,7 @@ test('reading a fresh production goal never starts the strategy, image workers,
assert.equal((await host.productionOperations).active,0);
});
test('production loads the project’s native skill and prompt template', async t => {
test('production loads project prompt templates without discovering project skills', async t => {
const dir = await fs.mkdtemp(path.join(os.tmpdir(), 'pi-recovery-project-resources-'));
t.after(() => cleanup(dir));
const cwd = path.join(dir, 'workspace');
@ -1240,7 +1240,7 @@ test('production loads the project’s native skill and prompt template', async
await fs.writeFile(path.join(promptDir, 'fixture-copy.md'),
'---\ndescription: Write a fixture headline.\n---\nDescribe the work surface.');
const {resourceLoader} = await createPhotoCraftExtensions({workingDirectory: cwd, store: {dir}}, [], {includeGoal: true});
assert.ok(resourceLoader.getSkills().skills.some(skill => skill.name === 'desk-copy'));
assert.ok(!resourceLoader.getSkills().skills.some(skill => skill.name === 'desk-copy'));
assert.equal(resourceLoader.getPrompts().prompts.find(prompt => prompt.name === 'fixture-copy')?.content,
'Describe the work surface.');
});

View File

@ -96,12 +96,15 @@ test('Pi production and its worker read the same locked Skill and its relative r
productEvidence:{accountScope:id.scope,project:id.project,documentId,brief:{brandName:'试验品牌',categoryName:'灯具'}}})};
let main=0,worker=0,serial=0;
const reads=new Map();
const skillLists=new Map();
const transport={info:info(id.scope),stream(_model,context){
const system=getCurrentSystemPrompt(context.messages);
assert.match(system,/<name>lighting<\/name>/);
assert.doesNotMatch(system,/PINNED_FINISH|Use the \[fixture notes\]/);
const location=system.match(/<name>lighting<\/name>[\s\S]*?<location>([^<]*SKILL\.md)<\/location>/u)[1];
const child=system.includes('完成主代理委托的图位');
const skillList=system.match(/<available_skills>[\s\S]*?<\/available_skills>/u)[0];
skillLists.set(child?'worker':'main',[...skillList.matchAll(/<name>([^<]+)<\/name>/gu)].map(match=>match[1]).sort());
const steps=child?[
['read',{path:location}],
['read',{path:path.join(path.dirname(location),'references','finish.md')}],
@ -120,6 +123,24 @@ test('Pi production and its worker read the same locked Skill and its relative r
return step?stream([{type:'toolCall',name:step[0],id:'skill-'+(++serial),arguments:step[1]}]):
stream([{type:'text',text:'本轮结束。'}]);
}};
const home=path.join(dir,'home');
for(const [base,name] of [
[path.join(home,'.agents','skills'),'personal-skill'],
[path.join(store.dir,'skills'),'global-skill'],
[path.join(store.dir,'workspace','.pi','skills'),'workspace-skill'],
]){
const skillDir=path.join(base,name);
await fs.mkdir(skillDir,{recursive:true});
await fs.writeFile(path.join(skillDir,'SKILL.md'),`---\nname: ${name}\ndescription: An unbound test skill.\n---\nFixture only.`);
}
for(const key of ['HOME','USERPROFILE']){
const previous=process.env[key];
process.env[key]=home;
t.after(()=>{
if(previous===undefined) delete process.env[key];
else process.env[key]=previous;
});
}
const host=await DetailPiAgent.open({store,canvas,transport,documentId,productionGoal:{outputId:'detail',variantId,workspaceId:randomUUID(),requestedOutputs:[{outputId:'detail',variantId}],skillRunDeadline:runDeadline}});
let loads=0;
const documents=[];
@ -133,6 +154,10 @@ test('Pi production and its worker read the same locked Skill and its relative r
host.enterpriseContext.load=async()=>{loads++;return knowledge;};
try {
assert.equal((await host.prompt('制作详情页')).production.complete,true);
await t.test('production prompts only list bound and bundled skills',()=>{
const expected=['lighting','pi-goal-writer','product-image-sources'];
assert.deepEqual(Object.fromEntries(skillLists),{main:expected,worker:expected});
});
const context=await host.modelContext({}, {loadKnowledge:true});
assert.deepEqual(context.enterpriseKnowledge.sources.map(row=>row.revision),['r4','r7']);
assert.equal(loads,1,'read-only context uses the original locked selection');