From a93ff9846104706fcb754712adc18bd35f327ea8 Mon Sep 17 00:00:00 2001 From: Doloro1978 Date: Mon, 3 Aug 2026 11:19:58 +0100 Subject: [PATCH] meow 2 --- config/modules/ai/model-cost.ts | 61 +++++++++++++++++++++++++++++++++ config/modules/ai/pi.nix | 7 +++- 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 config/modules/ai/model-cost.ts diff --git a/config/modules/ai/model-cost.ts b/config/modules/ai/model-cost.ts new file mode 100644 index 0000000..e2a988f --- /dev/null +++ b/config/modules/ai/model-cost.ts @@ -0,0 +1,61 @@ +/** + * Model cost display extension - shows cost info in status bar. + * + * Format: "$X.XX (Y.YY) in" where Y.YY is cache write cost if present. + * + * Usage: pi -e ./model-cost.ts + */ + +import type { + ExtensionAPI, + ModelSelectEvent, + UIContext, +} from "@earendil-works/pi-coding-agent"; + +export default function (pi: ExtensionAPI) { + const modelSelectHandler = async ( + event: ModelSelectEvent, + ctx: UIContext, + ) => { + const { model } = event; + + // Get cost data from model config + const cost = getModelCost(model); + + if (cost) { + ctx.ui.setStatus("model", cost); + } else { + ctx.ui.setStatus("model", ""); + } + }; + + pi.on("model_select", modelSelectHandler); +} + +function getModelCost(model: any): string { + if (!model?.cost) return ""; + + const { input, output, cacheRead, cacheWrite } = model.cost; + + // Only show if there's actual cost data + const hasCost = + input !== 0 || output !== 0 || cacheRead !== 0 || cacheWrite !== 0; + if (!hasCost) return ""; + + // Format: "$X.XX (Y.YY) in" + const parts: string[] = []; + + if (input !== 0) { + const cachePrefix = cacheRead > 0 ? ` (↙${cacheRead}) ` : ""; + parts.push(`$${input}${cachePrefix}in`); + } + + if (output !== 0) { + const cachePrefix = cacheWrite > 0 ? ` (↗${cacheWrite}) ` : ""; + parts.push(`$${output}${cachePrefix}out`); + } + + if (parts.length === 0) return ""; + + return parts.join(" / "); +} diff --git a/config/modules/ai/pi.nix b/config/modules/ai/pi.nix index 75fb5c5..650fbf0 100644 --- a/config/modules/ai/pi.nix +++ b/config/modules/ai/pi.nix @@ -188,7 +188,12 @@ home.file.".pi/agent/extensions/model-filter.ts" = { source = ./model-filter.ts; }; - + + # Show model cost in status bar + home.file.".pi/agent/extensions/model-cost.ts" = { + source = ./model-cost.ts; + }; + # Model filter config: per-provider filters applied by model-filter.ts home.file.".pi/agent/model-filters.json" = { text = builtins.toJSON {