import type { ExtensionAPI } from "@earendil-works/pi-coding-agent"; import { closeDebug, dbg } from "./src/debug.ts"; import { KeysmashEditor } from "./src/editor.ts"; // Marks editor factories installed by this extension, across reloads. const OWNED = Symbol.for("@bugabinga/pi-ext-keysmash/editor"); export default function keysmash(pi: ExtensionAPI): void { pi.on("session_start", (_event, ctx) => { dbg?.("session.start"); if (!ctx.hasUI) return; const current = ctx.ui.getEditorComponent(); if (current && !(OWNED in current)) { dbg?.("edit.skip", { reason: "foreign-editor" }); ctx.ui.notify( "keysmash: another extension owns the prompt editor; leaving it alone", "warning", ); return; } const factory = Object.assign( (...args: ConstructorParameters) => new KeysmashEditor(...args), { [OWNED]: true }, ); ctx.ui.setEditorComponent(factory); }); pi.on("session_shutdown", () => { dbg?.("session.shutdown"); closeDebug(); }); }