/** * The footer surface: the two-line status bar and the session lifecycle that * installs and restores it. * * The footer is installed only in interactive (`tui`) sessions, and the price * configuration is read once per install, so starting a new session or changing * the session tree is how an edited `bytefly.json` is picked up. Nothing watches * the file. The surface is always on; `pi config` is the way to turn bytefly's * chrome off. */ import { homedir } from "node:os"; import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent"; import { createSnapshotReader } from "./collect/snapshot.ts"; import { loadByteflyConfig } from "./price/config.ts"; import { createFooter } from "./render/footer.ts"; /** Register the footer install/restore lifecycle. */ export function registerFooter(pi: ExtensionAPI): void { const install = (ctx: ExtensionContext): void => { if (ctx.mode !== "tui") return; const config = loadByteflyConfig(ctx.cwd); const read = createSnapshotReader(config); ctx.ui.setFooter((tui, _theme, footerData) => createFooter( tui, footerData, () => read(ctx, footerData), () => ctx.ui.theme, homedir(), ), ); }; pi.on("session_start", (_event, ctx) => install(ctx)); pi.on("session_tree", (_event, ctx) => install(ctx)); pi.on("session_shutdown", (_event, ctx) => { if (ctx.mode !== "tui") return; ctx.ui.setFooter(undefined); }); }