refactor(background): require registry in status tool

This commit is contained in:
pi
2026-04-12 13:56:43 +01:00
parent af6824ef18
commit 0c18d021df
2 changed files with 12 additions and 10 deletions

View File

@@ -4,7 +4,13 @@ import { createBackgroundRegistry } from "./background-registry.ts";
test("recordLaunch and counts update correctly", () => { test("recordLaunch and counts update correctly", () => {
const reg = createBackgroundRegistry(); const reg = createBackgroundRegistry();
reg.recordLaunch({ runId: "r1", preset: "p1", task: "t1" }); reg.recordLaunch({
runId: "r1",
preset: "p1",
task: "t1",
paths: { resultPath: "/tmp/r1/result.json" },
meta: { source: "test" },
});
reg.recordLaunch({ runId: "r2", preset: "p2", task: "t2" }); reg.recordLaunch({ runId: "r2", preset: "p2", task: "t2" });
let counts = reg.getCounts(); let counts = reg.getCounts();
@@ -21,7 +27,10 @@ test("recordLaunch and counts update correctly", () => {
const r2 = reg.getRun("r2"); const r2 = reg.getRun("r2");
assert.ok(r1); assert.ok(r1);
assert.ok(r2); assert.ok(r2);
assert.deepEqual(r1?.paths, { resultPath: "/tmp/r1/result.json" });
assert.deepEqual(r1?.meta, { source: "test" });
assert.equal(r2?.finalText, "done"); assert.equal(r2?.finalText, "done");
assert.equal(reg.getRun("missing"), undefined);
}); });
test("replay seeds registry and counts", () => { test("replay seeds registry and counts", () => {

View File

@@ -1,8 +1,8 @@
import { BackgroundAgentStatusSchema } from "./background-schema.ts"; import { BackgroundAgentStatusSchema } from "./background-schema.ts";
import type { BackgroundRegistry } from "./background-registry.ts"; import type { BackgroundRegistry } from "./background-registry.ts";
export function createBackgroundStatusTool(deps: { registry: BackgroundRegistry } | { registry?: BackgroundRegistry } = {}) { export function createBackgroundStatusTool(deps: { registry: BackgroundRegistry }) {
const registry = (deps as any).registry; const { registry } = deps;
return { return {
name: "background_agent_status", name: "background_agent_status",
@@ -10,13 +10,6 @@ export function createBackgroundStatusTool(deps: { registry: BackgroundRegistry
description: "Query background agent runs and their status.", description: "Query background agent runs and their status.",
parameters: BackgroundAgentStatusSchema, parameters: BackgroundAgentStatusSchema,
async execute(_toolCallId: string, params: any = {}, _signal: AbortSignal | undefined, _onUpdate: any, _ctx: any) { async execute(_toolCallId: string, params: any = {}, _signal: AbortSignal | undefined, _onUpdate: any, _ctx: any) {
if (!registry) {
return {
content: [{ type: "text" as const, text: "Background registry not available" }],
details: { runs: [] },
isError: true,
};
}
const runId = typeof params.runId === "string" ? params.runId : undefined; const runId = typeof params.runId === "string" ? params.runId : undefined;
const includeCompleted = Boolean(params.includeCompleted); const includeCompleted = Boolean(params.includeCompleted);