预载小壹锁定知识并复用同屏复核结论(R5-Z56)

This commit is contained in:
WuYongJie 2026-11-30 05:42:45 +08:00
parent bfcb7656d9
commit 0a86c73b3a
7 changed files with 131 additions and 5 deletions

View File

@ -0,0 +1,33 @@
# R5-Z56 小壹三件套复核尾段
数据来自两个工程的 `conversation-v1/events.jsonl`。run36 截至 2026-11-30 04:04:13,run37 截至 05:38:45,均为北京时间。run37 截面晚于原耗时报告。
| 样本 | 助手 | 作用域数 | 模型轮数(每作用域) | 含 read 的可归属轮数(每作用域) | read 调用 |
|---|---|---:|---:|---:|---:|
| run36 | 整屏复核 | 32 | 180(5.63) | 103(3.22) | 174 |
| run36 | 候选复核 | 60 | 161(2.68) | 81(1.35) | 140 |
| run36 | 图位制作 | 39 | 190(4.87) | 41(1.05) | 90 |
| run37 | 整屏复核 | 37 | 302(8.16) | 203(5.49) | 284 |
| run37 | 候选复核 | 35 | 110(3.14) | 43(1.23) | 99 |
| run37 | 图位制作 | 43 | 299(6.95) | 54(1.26) | 130 |
助手会话驻留内存。按成品类型和请求作用域去重,同一作用域的多次委派计入同一分组。模型轮数取 `usage`,将 `read` 开始事件归给同作用域最近的用量回执,一轮内并发读取只计一轮。这是可从日志归属的轮次,不能还原同作用域每次委派的独立会话。
成功读取路径取 `enterprise_skill_resource_read`。下表依次列整屏、候选和图位助手的次数。
| 清单登记文件 | run36 | run37 |
|---|---:|---:|
| 模板小壹/SKILL.md | 53 / 38 / 27 | 86 / 32 / 37 |
| 无人值守补充说明.md | 57 / 49 / 31 | 89 / 31 / 42 |
| 小壹共用/模板原图换商品.md | 57 / 50 / 31 | 94 / 32 / 43 |
| 03-模板输入与制作衔接.md | 7 / 3 / 1 | 15 / 4 / 3 |
现有锁定知识前缀只含模板入口。扩大到清单的模板入口、补充、登记的 SKILL 入口和覆盖声明引用的文件,逐份附全文。三类助手首轮都使用同一前缀,其他登记文件仍可按需读取。
现有复核账本按成品、花色和按屏内容指纹保存结论。候选验图已经可以复用采纳后匹配的合成屏结论。整屏助手保存的完整回执也按该账本复用。屏指纹包含画布文案,商品输入签名覆盖款式资料、实拍引用和已选卖点。相同输入返回完整结论、当前修订号和 `reused: true`,跳过合成屏渲染、实拍重读和整屏助手。文案要求也参与复用判断。复核和返工仍由小壹决定。
若入口读取轮全被省掉,按事件归属的量级是每套约 225–300 次模型调用。以每轮 6–8 秒估算,累计推理时间约 22.5–40 分钟。假设这些调用均摊在六个持续忙碌的助手上,约合 3.8–6.7 分钟,实际墙钟收益取决于关键路径、其他工具等待和并发。两次历史整屏提交分别为 57 和 91 次,对应每次提交约 3.16 和 3.32 条模型回执。预载入口后每次复用至少可省一次结论推理,若一套命中十屏,按相同轮次耗时约省 1–1.3 分钟串行推理。两个估算存在重叠,线上实际命中率和耗时需用后续运行验证。
## 离线验证
Node 全量测试 391 通过。锁定知识与整屏复核定向测试 37 通过。使用内存模型传输验证三类助手的首轮提示都带入口全文和一致的前缀,并保留 `read`。整屏测试验证同指纹时复用完整回执,指纹或商品资料变化后重新调用助手。

View File

@ -2,6 +2,7 @@ import { candidateReceipt, compactProgress, receiptPage, reviewSlotSummary } fro
import { compactTemplateFidelity } from './template-fidelity.mjs';
import { compareTemplateFields, visibleTemplateConflicts } from './field-requirements.mjs';
import { readFileSync } from 'node:fs';
import { isDeepStrictEqual } from 'node:util';
import path from 'node:path';
import { CanvasOperations } from './canvas-operations.mjs';
import { Type } from '@sinclair/typebox';
@ -1818,6 +1819,21 @@ export async function openProductionOperations(host,{target=host.productionGoal,
job.run=scheduleDelegate(activeSignal,async permit=>{
job.receipt={page,state:'checking'};
notice('正在按屏复核');
const saved=new Map(journal.screenReviews??[]).get(page-1);
if(saved?.receipt && saved.screenFingerprint){
const live=await current();
const inputs=productionInputs(live,variantId);
if(saved.copyInputs===inputs){
const snapshot=await onCanvas(activeSignal,()=>copySnapshot({screenFingerprintPage:page-1}),permit);
activeSignal.throwIfAborted();
const requirements=fieldRequirements(live).filter(row=>row.page===snapshot.pages?.[page-1]);
if(snapshot.screenFingerprint===saved.screenFingerprint &&
isDeepStrictEqual(requirements,saved.receipt.fieldRequirements??[])){
job.receipt={...saved.receipt,revision:snapshot.revision,reused:true};
return;
}
}
}
const screen=await onCanvas(activeSignal,()=>operations.read_output_screen({page:page-1,includeTemplateImage:true},activeSignal),permit);
const previous=new Map(journal.screenReviews??[]).get(page-1);
if(previous?.candidateReview && (!screen.details.templateFidelity || previous.candidateReview.templateEvidence) && !screen.details.screenChanged &&

View File

@ -267,13 +267,22 @@ export async function openXiaoyiSkills(store, templateId, signal, finishedGoal,
instruction:'按锁定的知识库根相对路径读取资料。共享章节有覆盖声明时,以对应补充章节为准,其余共享内容继续适用。',
};
const sources = [...documents.values()];
const workerEntries = new Set([
manifest.entrypoint, manifest.supplement,
...manifest.files.filter(item => path.posix.basename(item.path) === 'SKILL.md').map(item => item.path),
...(manifest.overrides ?? []).flatMap(({sharedPath,supplementPath}) => [sharedPath,supplementPath]),
]);
const packagedPaths = new Set(manifest.files.map(item => item.path));
const workerGuides = await Promise.all([...workerEntries]
.filter(relativePath => packagedPaths.has(relativePath))
.map(async relativePath => relativePath + '\n' + await fs.readFile(fileAt(root,relativePath),'utf8')));
return {
knowledgeVersion:manifest.knowledgeVersion, execution, productionProfiles, snapshot:{manifest,root},
productionBinding:{templateId, knowledgeVersion:manifest.knowledgeVersion, productionProfiles,
assets:manifest.assets.map(item => ({...item,localPath:fileAt(root,item.path)}))},
filesRoot:root, resource, documents, sources,
files:[...documents].map(([file, source]) => ({...source,path:file})),
workerGuidePrefix:JSON.stringify(execution) + '\n\n' + await fs.readFile(entry,'utf8') + '\n\n',
workerGuidePrefix:[JSON.stringify(execution),...workerGuides].join('\n\n') + '\n\n',
resolveFile:async file => documents.has(file),
shellFiles:async () => manifest.files.map(item => {
const file = fileAt(root,item.path);

View File

@ -521,6 +521,35 @@ test('references enter the actual Pi user message as image and quoted text parts
await cleanup(dir);
}
});
test('各类制作助手的首轮推理共用完整锁定入口前缀,并可按需读附录', async t => {
const dir=await root(), id=identity(), store=await ProjectStore.open(dir,id,binding('A'));
t.after(()=>cleanup(dir));
const requests=[];
const host=await openAgent({store,transport:{info:info(id.scope),stream(_model,context){
requests.push({system:getCurrentSystemPrompt(context.messages),tools:getCurrentTools(context.messages)});
return stream([{type:'text',text:'已收到制作任务'}]);
}}});
try {
const entrypoint='SKILL.md', supplement='补充.md';
const entry='---\nname: guide\ndescription: Demo guide.\n---\n完整模板内容';
const extra='补充说明第一行\n补充说明末行';
host.productionSkills=await openXiaoyiSkills(store,'demo',undefined,undefined,
xiaoyiFixture('demo','1',entrypoint,{[entrypoint]:entry,[supplement]:extra,'附录.md':'按需资料'},{supplement}));
const prefix=host.productionSkills.workerGuidePrefix;
for(const [slot,role] of [['screen-1','整屏复核'],['slot-1','候选复核'],['slot-2','图位制作']]){
await host.runDetailAgent(slot,role,'当前任务',[],[]);
const request=requests.at(-1);
assert.ok(request.system.startsWith(prefix+role));
assert.ok(request.system.includes(entry));
assert.ok(request.system.includes(extra));
assert.ok(request.tools.some(tool=>tool.name==='read'));
}
assert.equal(requests.length,3);
} finally {
await host.dispose();
}
});
test('actual Pi SDK retries an overloaded inference with the default budget', async () => {
const dir = await root(), id = identity(), store = await ProjectStore.open(dir, id, binding('A'));
let calls = 0;

View File

@ -37,10 +37,25 @@ test('子代理从同一锁定版本构建出字节一致的企业前缀', async
const dir = await fs.mkdtemp(path.join(tmpdir(),'xiaoyi-guide-'));
t.after(() => fs.rm(dir,{recursive:true,force:true}));
const entry = '规则/SKILL.md';
const fetch = xiaoyiFixture('demo','1',entry,{[entry]:'---\nname: guide\ndescription: Demo guide.\n---\n制作指引正文'});
const supplement = '规则/模板补充.md';
const supplementPath = '共用/小壹补充.md';
const sharedPath = '共用/规则.md';
const guides = {
[entry]:'---\nname: guide\ndescription: Demo guide.\n---\n制作指引正文',
[supplement]:'模板补充首段\n模板补充末段',
[supplementPath]:'小壹补充首段\n小壹补充末段',
[sharedPath]:'共用规则首段\n共用规则末段',
'共用/SKILL.md':'共用入口首段\n共用入口末段',
};
const fetch = xiaoyiFixture('demo','1',entry,{...guides,'附录.md':'按需读取的附录'},
{supplement,overrides:[{sharedPath,supplementPath}]});
const first = await openXiaoyiSkills({dir},'demo',undefined,undefined,fetch);
const second = await openXiaoyiSkills({dir},'demo',undefined,undefined,
()=>assert.fail('locked prefixes must not use network'));
assert.equal(first.workerGuidePrefix,second.workerGuidePrefix);
assert.match(first.workerGuidePrefix,/demo@1.*制作指引正文/s);
for (const [file,body] of Object.entries(guides)) {
assert.ok(first.workerGuidePrefix.includes(file+'\n'+body+'\n\n'),file);
}
assert.ok(!first.workerGuidePrefix.includes('按需读取的附录'));
assert.ok(await first.resolveFile(path.join(first.filesRoot,'附录.md')));
});

View File

@ -205,6 +205,30 @@ test('候选原图与整屏一起验,采纳匹配指纹后直接沿用错位
assert.equal(reviews,1);
});
test('同屏同商品资料复用整屏助手的完整回执,屏指纹或资料变化时重新复核', async t=>{
const {host,actions,state}=await fixture(t);
let reviews=0;
host.runDetailAgent=async(_id,_system,_prompt,[tool])=>{
reviews++;
await tool.execute('',pass);
};
const check=async()=> (await actions.check_output_screens({pages:[1]}))[0];
const first=await check();
assert.equal(first.verdict,'pass');
state.revision++;
assert.deepEqual(await check(),{...first,revision:state.revision,reused:true});
assert.equal(reviews,1);
assert.deepEqual(state.reads,[0]);
assert.equal(state.referenceReads,1);
state.fingerprints[0]='changed';
assert.equal((await check()).screenFingerprint,'changed');
assert.equal(reviews,2);
state.colorName='浅木色';
assert.equal((await check()).reused,undefined);
assert.equal(reviews,3);
await actions.close();
});
test('多图位屏齐备后在采纳与验图回执提示,当前画面复核后清除提示', async t=>{
const {host,actions,state,slots}=await fixture(t);
slots[1].documentId='P1';

View File

@ -1,7 +1,7 @@
import {createHash} from 'node:crypto';
import {zipSync} from 'fflate';
export function xiaoyiFixture(templateId, version, entrypoint, documents) {
export function xiaoyiFixture(templateId, version, entrypoint, documents, {supplement=entrypoint,overrides=[]}={}) {
const sha256 = bytes => createHash('sha256').update(bytes).digest('hex');
const describe = bytes => ({size:bytes.length,sha256:sha256(bytes)});
const productionConfig = '小壹/production.json';
@ -10,7 +10,7 @@ export function xiaoyiFixture(templateId, version, entrypoint, documents) {
const bundle = zipSync(entries);
const knowledgeVersion = templateId + '@' + version;
const manifest = Buffer.from(JSON.stringify({schemaVersion:1,templateId,version,knowledgeVersion,entrypoint,
productionConfig,supplement:entrypoint,overrides:[],assets:[],bundle:describe(bundle),
productionConfig,supplement,overrides,assets:[],bundle:describe(bundle),
files:Object.entries(entries).map(([path,bytes]) => ({
path,type:path===entrypoint?'skill':'attachment',...describe(bytes),
})),