import type { ExtensionAPI } from "@earendil-works/pi-coding-agent"; import type { Decision } from "./parse"; import { parseDecision } from "./parse"; import { formatDetail, formatLine } from "./format"; /** * Pi extension entry point. After each routed provider response it updates a * footer status line with the Wayfinder routing decision, and registers a * `/wf` command that prints the full last decision. * * @param pi - The Pi extension API. */ export default function (pi: ExtensionAPI): void { let last: Decision | null = null; pi.on("after_provider_response", (event, ctx) => { const decision = parseDecision(event.headers); // A non-Wayfinder response yields null; leave the prior line untouched. if (!decision) return; last = decision; if (ctx.hasUI) ctx.ui.setStatus("wayfinder", formatLine(decision)); }); pi.on("session_start", (_event, ctx) => { last = null; if (ctx.hasUI) ctx.ui.setStatus("wayfinder", undefined); }); pi.registerCommand("wf", { description: "Show the last Wayfinder routing decision", handler: async (_args, ctx) => { const lines = last ? formatDetail(last) : ["wayfinder - no routed response yet"]; ctx.ui.notify(lines.join("\n"), "info"); }, }); }