import type { ExtensionAPI } from "@earendil-works/pi-coding-agent"; import { DESKTOP_NOTIFY_EVENT, NOTIFY_FLAGS } from "./constants.ts"; import { resolveNotificationConfig } from "./config.ts"; import { sendNotification } from "./send.ts"; import { createNotifyTool } from "./notify-tool.ts"; import { registerAgentLoopHandlers } from "./triggers/agent-loop.ts"; /** pi extension entry point. The side-effect-free client lives at `./client`. */ export default function desktopNotifyExtension(pi: ExtensionAPI): void { pi.registerFlag(NOTIFY_FLAGS.completion, { type: "string", description: "Enable or disable final completion notifications (on|off).", }); pi.registerFlag(NOTIFY_FLAGS.error, { type: "string", description: "Enable or disable final error notifications (on|off).", }); pi.registerFlag(NOTIFY_FLAGS.tool, { type: "string", description: "Enable or disable the model-callable notify tool (on|off).", }); const config = resolveNotificationConfig(pi, process.env); registerAgentLoopHandlers(pi, { completion: config.completion, error: config.error, getSessionName: () => pi.getSessionName(), }); pi.events.on(DESKTOP_NOTIFY_EVENT, data => { try { sendNotification(data); } catch { // EventBus delivery is an optional best-effort integration. } }); if (config.tool === "on") pi.registerTool(createNotifyTool()); }