feat(agent): capability registry, Pi AgentRuntimePort, fake model provider and redaction guard (W1-5)

- CapabilityRegistry: descriptor(id/version/schema/scope/risk/idempotent/preview/replay),
  invoke = scope limit -> input schema -> server-side authorize -> idempotency key -> handler
  -> output schema -> audit; capability id <-> tool name mapping (download.submit <-> download__submit)
- PiAgentRuntime (pi-agent-core AgentHarness 0.87.1): whitelist tools + before_tool re-check,
  redacted event stream, JSONL session at sessionDir/<runId>.jsonl, resume/abort/compact,
  tool-call/duration/token/cost budgets -> abort + run_failed(budget)
- AgentSettings -> pi-ai createProvider (anthropic / openai-compatible), compaction mapping
- FakeModelProvider + createFakeRuntime (scripted, transcript-derived, survives crash/resume)
- buildSystemPrompt, redactForModel; 27 tests incl. SIGKILL + resume

Co-Authored-By: Claude Fable 5.1 <[email protected]>
This commit is contained in:
rootandClaude Fable 5.1 committed 2026-09-27 17:55:28 +08:00
1 parent 1262340856
commit 9c881e737f
24 files changed
+2419 -8

No files matched your search

+26
View File
@@ -0,0 +1,26 @@
// 子进程:启动 run,download.submit 执行中挂起;父进程收到 SUBMIT_STARTED 后 SIGKILL 本进程。
import { createFakeRuntime } from "../../src";
import { makeFixture, settings } from "../helpers";
import { crashScript, RUN_ID } from "./crash-script";
const sessionDir = process.argv[2]!;
const fx = makeFixture({ slowMs: 60_000 });
fx.grants.set("user:1", new Set(["download.submit"]));
const { runtime } = createFakeRuntime({
registry: fx.registry,
scripts: [crashScript],
onEvent: (e) => {
if (e.type === "tool_call_start" && e.capabilityId === "download.submit") process.stdout.write("SUBMIT_STARTED\n");
},
});
const run = await runtime.createRun({
runId: RUN_ID,
goal: "把 Dune 1080p 收进来",
systemPrompt: "媒体库助手",
capabilities: ["inventory.query", "download.submit"],
settings: settings(),
sessionDir,
actor: { actorId: "user:1", taskId: "task:crash", scopeIds: [] },
});
await run.prompt();
process.stdout.write("UNEXPECTED_FINISH\n");
+18
View File
@@ -0,0 +1,18 @@
import type { FakeScript } from "../../src";
export const RUN_ID = "run-crash-1";
export const crashScript: FakeScript = {
match: "Dune",
steps: [
{ text: "先查库存。", toolCalls: [{ capability: "inventory.query", input: { title: "Dune" } }] },
{
text: "库里没有,提交下载。",
toolCalls: [{ capability: "download.submit", input: { title: "Dune", quality: "1080p" } }],
},
],
finalText: (results) => {
const last = results.at(-1);
return last?.isError ? `下载提交结果未知,需要核对:${last.text.slice(0, 40)}` : "已提交(未入库)";
},
};