import type { ExtensionAPI } from "@earendil-works/pi-coding-agent"; import { loadGlobalEnv } from "./load"; export default function (pi: ExtensionAPI) { // Load eagerly at factory time. All extension factories run before // session_start, so consumers that read process.env during load (e.g. // API-key checks in the extension body) only see these values if we // apply them here. A factory error would drop the whole extension from // pi's load, so keep it alive and let session_start retry. try { loadGlobalEnv(); } catch (error) { const message = error instanceof Error ? error.message : String(error); console.error(`[pi-dotenv] failed to load .env at startup: ${message}`); } // Re-load on each session start: idempotent (defined keys are skipped) // and picks up .env edits across /new, /resume, and /fork. pi.on("session_start", async (_event, _ctx) => { loadGlobalEnv(); }); }