import { getAgentDir, type ExtensionAPI } from "@earendil-works/pi-coding-agent"; import { writeFile } from "node:fs/promises"; import { join } from "node:path"; const NOTICE_MARKER_FILENAME = ".pi-radius-mcp-migration-notice-v1"; /** Atomically claim the one-time notice across packages and running Pi processes. */ async function claimMigrationNotice(): Promise { try { await writeFile(join(getAgentDir(), NOTICE_MARKER_FILENAME), "shown\n", { encoding: "utf8", flag: "wx", mode: 0o600, }); return true; } catch (error) { if ((error as NodeJS.ErrnoException).code === "EEXIST") return false; // A read-only config directory should not suppress the migration guidance. return true; } } export default function (pi: ExtensionAPI): void { pi.on("session_start", async (_event, ctx) => { if (ctx.mode !== "tui" || !(await claimMigrationNotice())) return; ctx.ui.notify( [ "The Radius Pi extensions are deprecated in favor of the Radius MCP.", "pi mcp add radius --url https://radius.pi.dev/mcp", ].join("\n"), "warning", ); }); }