From d123b9b3be99725cc1b9b4cbce61002eda9b85c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phan=20Sainl=C3=A9ger?= Date: Wed, 18 Nov 2026 23:13:52 +0100 Subject: [PATCH] chg: [opencode-greenpt-usage] tighten the sidebar balance layout Put the balance on the section header line and keep the folded header to one row with today's spend. Remove the gap between the title and the metrics line, then indent model tokens below the full model name so they read as subordinate detail instead of wrapping mid-name. The stacked model rows avoid the narrow sidebar splitting a model id; costs stay right-aligned. Typecheck and the 49 unit tests pass. --- src/widget.tsx | 120 ++++++++++++++++++++++++++++++------------------- 1 file changed, 74 insertions(+), 46 deletions(-) diff --git a/src/widget.tsx b/src/widget.tsx index 16f3330..022730f 100644 --- a/src/widget.tsx +++ b/src/widget.tsx @@ -5,6 +5,23 @@ import { BALANCE_OPEN_KV, formatBalanceError, formatCredits, formatTokens, DEFAU import { dayTotals, monthTotals, type ModelTotal } from "./usage" import type { BalanceStore } from "./store" +/** Maximum characters before a model name is ellipsized in the table. */ +const MODEL_NAME_MAX = 28 + +/** Number of model rows shown before the "other models" summary. */ +const MODEL_ROWS_VISIBLE = 3 + +/** + * Shorten a model id for a narrow sidebar column. + * + * @param model Model id reported by OpenCode. + * @returns The id unchanged when short enough, otherwise an ellipsized form. + */ +function shortModel(model: string): string { + if (model.length <= MODEL_NAME_MAX) return model + return `${model.slice(0, MODEL_NAME_MAX - 1)}…` +} + /** * Sidebar section showing the remaining GreenPT credit balance and the * consumption of the API key: real credit spend per day/month plus a @@ -61,7 +78,7 @@ export function GreenptWidget(props: { const d = new Date(s.fetchedAt) const hh = String(d.getHours()).padStart(2, "0") const mm = String(d.getMinutes()).padStart(2, "0") - return `updated ${hh}:${mm}` + return `${hh}:${mm}` } const usage = () => props.store.usageDays() @@ -70,69 +87,80 @@ export function GreenptWidget(props: { const usageVisible = () => todayUsage().creditsSpent > 0 || monthUsage().cost > 0 const todayText = () => `${formatCredits(todayUsage().creditsSpent)} ${unit()}` const monthText = () => `${formatCredits(monthUsage().cost)} ${unit()}` - const foldedSuffix = () => (usageVisible() ? ` · today ${todayText()}` : "") - const modelRows = (): ModelTotal[] => monthUsage().byModel.slice(0, 5) + const modelRows = (): ModelTotal[] => monthUsage().byModel.slice(0, MODEL_ROWS_VISIBLE) + const otherModels = () => Math.max(0, monthUsage().byModel.length - MODEL_ROWS_VISIBLE) return ( }> - - - {open() ? "▼ " : "▶ "} - GreenPT - - {(text) => ( - - {" "} - {text()} - {foldedSuffix()} - - )} - - + + + + {open() ? "▼ " : "▶ "} + GreenPT + + + + {(text) => ( + + {text()} + + )} + + + · today {todayText()} + + + + - - Balance - - {balanceText()} - {updatedAt()} - + + + today {todayText()} · month {monthText()} · {updatedAt()} + - loading… + + loading… + - + + + - {formatBalanceError(error()!)} + + {formatBalanceError(error()!)} + + - - Spent - - today {todayText()} - month {monthText()} - - - - {(row) => ( - - {row.model} - - - {formatTokens(row.usage.tokens.input + row.usage.tokens.output)} tok - - - ~{formatCredits(row.usage.cost)} {unit()} - + + + {(row) => ( + + {shortModel(row.model)} + + + {formatTokens(row.usage.tokens.input + row.usage.tokens.output)} tok + + + ~{formatCredits(row.usage.cost)} {unit()} + + + )} + + 0}> + + + {otherModels()} more models - )} - + +