import type { ExtensionAPI } from "@earendil-works/pi-coding-agent"; import { runCli } from "../cli.ts"; import { TOOLS } from "../schemas.ts"; /** * Register the passthrough tools: one native `cbm_*` tool per binary * subcommand. `index_repository`, `search_graph`, `get_code_snippet`, * `search_code`, and `list_projects` are handled separately (bespoke renderers) * and are skipped here. */ const BESPOKE = new Set([ "index_repository", "search_graph", "get_code_snippet", "search_code", "list_projects", ]); export function registerGenericTools(pi: ExtensionAPI) { for (const { tool, description, parameters } of TOOLS) { if (BESPOKE.has(tool)) continue; pi.registerTool({ name: `cbm_${tool}`, label: `cbm:${tool}`, description, parameters, async execute(_toolCallId, params, signal) { if (signal?.aborted) { return { content: [{ type: "text", text: "Cancelled" }], details: {} }; } const out = await runCli(tool, params, signal ?? undefined); return { content: [{ type: "text", text: out || "{}" }], details: {}, }; }, }); } }