docs(spikes): OpenWorkflow and Pi SDK compatibility spikes + ADR-002/003 (W0-B)

Co-Authored-By: Claude Fable 5.1 <[email protected]>
This commit is contained in:
rootandClaude Fable 5.1 committed 2026-09-27 17:39:35 +08:00
1 parent 8b90d396b2
commit ec023a8405
16 files changed
+2884

No files matched your search

+21
View File
@@ -0,0 +1,21 @@
// Manual + threshold compaction with the fake model (summary text is scripted).
import { createModels, fauxProvider, fauxAssistantMessage } from "@earendil-works/pi-ai";
import { AgentHarness, BACKGROUND_CONTEXT as ctx, MemorySessionRepo } from "@earendil-works/pi-agent-core";
const faux = fauxProvider({ provider: "umt-fake", models: [{ id: "tiny", contextWindow: 3000, maxTokens: 500 }] });
const models = createModels(); models.setProvider(faux.provider);
const session = await new MemorySessionRepo().create({}, ctx);
const { harness } = await AgentHarness.create({ session, models, model: faux.getModel(), systemPrompt: "助手",
compaction: { enabled: true, reserveTokens: 600, keepRecentTokens: 200 } }, ctx);
for (const t of ["compaction_start", "compaction_end", "run_end"] as const)
harness.events.on(t as any, (e: any) => console.log(`[${e.type}] reason=${e.reason ?? ""} status=${e.status ?? ""}`));
const lane = await harness.lane("main", ctx);
const long = "目标:收录 Dune 1080p。约束:只用已授权能力。".repeat(Number(process.env.REPEAT ?? 60));
faux.setResponses([fauxAssistantMessage("好的,已记录目标。" + "x".repeat(2000)), fauxAssistantMessage("## 摘要\n目标:收录 Dune 1080p;已完成:无"), fauxAssistantMessage("继续")]);
console.log("run1:", JSON.stringify((await lane.prompt(long, undefined, ctx)) as any).slice(0, 400));
console.log("run2:", JSON.stringify((await lane.prompt("继续", undefined, ctx)) as any).slice(0, 400));
faux.appendResponses([fauxAssistantMessage("## 手动摘要\n目标/约束/证据/已完成/剩余")]);
const c = await lane.compact({ customInstructions: "保留目标、约束、证据引用、已完成动作、剩余事项" }, ctx);
console.log("manual compact:", JSON.stringify(c).slice(0, 200));
const entries = await lane.findEntries(undefined, ctx);
console.log("entry types:", entries.map((e: any) => e.type).join(","), "fake calls:", faux.state.callCount);
await harness.close(ctx);