import type { ExtensionAPI } from "@oh-my-pi/pi-coding-agent"; import { inspect, query, summary, type Seed } from "./catalog"; interface CatalogDetails { scope: "fictional-fixture"; seeds: readonly Seed[]; } export default async function seedCatalog(pi: ExtensionAPI) { const description = await Bun.file(new URL("./tool.txt", import.meta.url)).text(); const z = pi.zod; const parameters = z.object({ op: z.enum(["query", "inspect"]), id: z.string().optional(), family: z.string().optional(), }); pi.registerTool({ name: "seed_catalog", label: "Seed catalog", description, parameters, approval: "read", loadMode: "essential", async execute(_id, params, signal) { signal?.throwIfAborted(); const seeds = params.op === "inspect" ? [inspect(params.id ?? "")] : query(params.family); return { content: [{ type: "text", text: summary(seeds) }], details: { scope: "fictional-fixture", seeds }, }; }, }); pi.registerCommand("seeds", { description: "Browse fictional seeds: query [family] | inspect ", async handler(args, ctx) { const [verb = "query", value, extra] = args.trim().split(/\s+/).filter(Boolean); let text: string; let failed = false; try { if (extra || !["query", "inspect"].includes(verb)) throw new Error("Use /seeds query [family] or /seeds inspect ."); text = summary(verb === "inspect" ? [inspect(value ?? "")] : query(value)); } catch (error) { failed = true; text = error instanceof Error ? error.message : "Catalog unavailable. Nothing changed."; } if (ctx.hasUI) ctx.ui.notify(text, failed ? "warning" : "info"); else pi.sendMessage({ customType: "seed-desk", content: text, display: true }, { triggerTurn: false }); }, }); }