diff --git a/packages/app/e2e/regression/review.spec.ts b/packages/app/e2e/regression/review.spec.ts index f236e7eda11..cebbe996919 100644 --- a/packages/app/e2e/regression/review.spec.ts +++ b/packages/app/e2e/regression/review.spec.ts @@ -459,7 +459,7 @@ test("context closes the side region only when its button opened it", async ({ p await expect(panel.locator("#session-side-panel-review-tab")).toHaveAttribute("aria-selected", "true") }) -test("context hides free-model cost but keeps paid-model zero cost", async ({ page }) => { +test("context hides zero cost for Go and free models but keeps paid-model cost", async ({ page }) => { const cases = [ { id: "ses_context_free", title: "Free model", model: "free", cost: 0, usage: false, text: "0" }, { id: "ses_context_paid", title: "Paid model", model: "paid", cost: 0, usage: false, text: "0·$0.00" }, @@ -468,24 +468,48 @@ test("context hides free-model cost but keeps paid-model zero cost", async ({ pa { id: "ses_context_mixed", title: "Previously paid", model: "free", cost: 1.25, usage: true, text: "2k·$1.25" }, { id: "ses_context_unknown", title: "Unknown pricing", model: "missing", cost: 0, usage: false, text: "0·$0.00" }, { id: "ses_context_output", title: "Output pricing", model: "output", cost: 0, usage: false, text: "0·$0.00" }, + { + id: "ses_context_go", + title: "Covered by Go", + providerID: "opencode-go", + model: "paid", + cost: 0, + usage: true, + text: "2k", + }, + { + id: "ses_context_go_spend", + title: "Go with charges", + providerID: "opencode-go", + model: "paid", + cost: 0.38, + usage: true, + text: "2k·$0.38", + }, // The root's model is free, but its subagent spent on a paid model: the family total shows. { id: "ses_context_family", title: "Paid subagent", model: "free", cost: 0, usage: true, text: "2k·$1.25" }, // A completed compaction resets the context until the next reply reports usage, as in the TUI. { id: "ses_context_compacted", title: "Compacted", model: "paid", cost: 1.25, usage: true, text: "0·$1.25" }, ] + const catalog = provider( + { id: "free", name: "Free", cost: { input: 0, output: 0 } }, + { id: "paid", name: "Paid", cost: { input: 1, output: 3 } }, + { id: "output", name: "Output", cost: { input: 0, output: 1 } }, + ) + await openSession(page, { name: "ContextPricing", - provider: provider( - { id: "free", name: "Free", cost: { input: 0, output: 0 } }, - { id: "paid", name: "Paid", cost: { input: 1, output: 3 } }, - { id: "output", name: "Output", cost: { input: 0, output: 1 } }, - ), + provider: { + ...catalog, + all: [...catalog.all, { ...catalog.all[0], id: "opencode-go", name: "OpenCode Go" }], + connected: [...catalog.connected, "opencode-go"], + }, sessions: [ ...cases.map((item) => ({ id: item.id, title: item.title, - model: { id: item.model, providerID: "opencode" }, + model: { id: item.model, providerID: item.providerID ?? "opencode" }, cost: item.cost, })), { @@ -504,7 +528,7 @@ test("context hides free-model cost but keeps paid-model zero cost", async ({ pa id: `msg_${item.id}`, type: "assistant", agent: "build", - model: { id: item.model, providerID: "opencode" }, + model: { id: item.model, providerID: item.providerID ?? "opencode" }, tokens: { input: 1500, output: 500, reasoning: 0, cache: { read: 0, write: 0 } }, content: [{ type: "text", text: "Done." }], time: { created: 1, completed: 2 }, @@ -533,6 +557,15 @@ test("context hides free-model cost but keeps paid-model zero cost", async ({ pa await page.locator("[data-titlebar-tab-slot]", { hasText: item.title }).click() await expectSessionTitle(page, item.title) await expect(button).toHaveText(item.text) + + if (item.providerID === "opencode-go") { + await button.click() + const panel = page.locator('[data-slot="session-usage-content"]') + + await expect(panel.getByText("OpenCode Go", { exact: true })).toBeVisible() + await expect(panel.getByText("Total Cost", { exact: true })).toBeVisible({ visible: item.cost > 0 }) + await button.click() + } } }) diff --git a/packages/gui-plugins/src/context/indicator.tsx b/packages/gui-plugins/src/context/indicator.tsx index 5760d32a357..ff3b1bb71cb 100644 --- a/packages/gui-plugins/src/context/indicator.tsx +++ b/packages/gui-plugins/src/context/indicator.tsx @@ -75,10 +75,11 @@ export function SessionContextUsage(props: { const cost = createMemo(() => usd().format(spent())) - // Spend anywhere in the family keeps the cost visible, even when this session's model is free. const showCost = createMemo(() => { if (spent() > 0) return true const ref = info()?.model ?? messages().findLast((item) => item.type === "assistant")?.model + + if (ref?.providerID === "opencode-go") return false const model = ref ? catalogModel(props.session, ref)?.model : undefined if (!model) return true diff --git a/packages/gui-plugins/src/context/tab.tsx b/packages/gui-plugins/src/context/tab.tsx index de49dc7821d..ca0d4f01fa3 100644 --- a/packages/gui-plugins/src/context/tab.tsx +++ b/packages/gui-plugins/src/context/tab.tsx @@ -143,8 +143,18 @@ export default function SessionContextTab(props: { session: MountedSession }) { const formatter = createMemo(() => createSessionContextFormatter(i18n.locale())) - // A root session's cost includes its subagent sessions, as in the TUI. - const cost = createMemo(() => usd().format(props.session.id ? data().session.cost(props.session.id) : 0)) + const cost = createMemo(() => { + if (!props.session.id) return + const spent = data().session.cost(props.session.id) + + if (spent === 0) { + const ref = info()?.model ?? messages().findLast((item) => item.type === "assistant")?.model + + if (ref?.providerID === "opencode-go") return + } + + return usd().format(spent) + }) const counts = createMemo(() => { const all = messages() @@ -396,7 +406,9 @@ export default function SessionContextTab(props: { session: MountedSession }) { >