Skip to content

feat(tui): estimate spend in the mini footer - #60659

Closed
augustovicente wants to merge 3 commits into
anomalyco:devfrom
augustovicente:mini-cost-estimate
Closed

augustovicente wants to merge 3 commits into
anomalyco:devfrom
augustovicente:mini-cost-estimate

Conversation

@augustovicente

@augustovicente augustovicente commented Oct 30, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #60653

Dependency: This PR is stacked on #59864 and must merge after it. Only the final commit is new; the rest are from #59864.

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Adds the experimental["cost-estimate"] estimate to the mini/run footer, which #59864 leaves out of scope. When a provider reports cost: 0, the status line shows the catalog-priced session spend (≈ $5.25, or ≈ <$0.01) instead of nothing; a positive recorded cost still wins.

The estimate reads session totals from session.get and live session.usage.updated events, and prices observed assistant steps at their per-call context tier. Earlier, title, and compaction usage stays at untiered rates, matching the main footer. It covers the current session only: the main footer's root-family total needs the client store, which mini does not have.

This branch is stacked on #59864 so it compiles before that PR lands — only the last commit is new. I'll rebase onto dev and drop the duplicate once #59864 merges.

How did you verify your code works?

From packages/tui:

bun test --timeout 30000 test/mini
bun run typecheck:tsc

430 mini tests pass (2 skipped), including new unit tests for sessionSpend, renderer assertions for ≈ $X, ≈ <$0.01, and recorded-cost precedence, plus a transport test for session.usage.updated. The full TUI run is 1623 pass, 2 skip, and 1 failure in component/go-upsell-art.test.tsx; that test also fails in isolation on this machine and is untouched here. bun run check passes from the repository root.

Visual

<svg xmlns="http://www.w3.org/2000/svg" width="240" height="72" viewBox="0 0 240 72">
  <style>
    .t { font: 9px ui-monospace, SFMono-Regular, Menlo, monospace; fill: currentColor; }
    .est { animation: in 3.4s ease infinite; }
    @keyframes in { 0% { opacity: 0; } 20%, 90% { opacity: 1; } 100% { opacity: 0; } }
  </style>
  <text class="t" x="12" y="34" opacity="0.85">Build · GPT-5 · 12.0K (8%) ·</text>
  <text class="t est" x="146" y="34">≈ $5.25</text>
  <text class="t" x="12" y="52" opacity="0.45">mini footer · cost estimate</text>
</svg>

Screenshots / recordings

No screenshot attached. The footer renders as:

Build · GPT-5 · 12.0K (8%) · ≈ $5.25

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Added by the opencode bot (AI-generated).

Related: #59861, #59923, #39740

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Oct 30, 2026
@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Oct 30, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@augustovicente
augustovicente marked this pull request as ready for review October 30, 2026 18:03

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks sound. The new mini tests, the util/session tests and the footer/sidebar tests pass, and tsc -b passes. I couldn't see it working live: the review harness can't start mini/run mode, and the simulated model has no usage or prices. Could you attach a screenshot of the mini footer showing ≈ $X with the experiment on, and one with it off?

Public API: this commit doesn't change it. The experimental["cost-estimate"] config key only shows up in this diff because the branch is stacked on #59864, so this can only land after that one.

Two things are noted inline: with the experiment on, a provider that reports a real cost now shows a different number in the footer, and the new pricing field is never read.

Related: #59861, #59923, #39740

Comment thread packages/tui/src/mini/catalog.shared.ts Resolved
@augustovicente

Copy link
Copy Markdown
Author

Both inline notes are addressed in 5f4e20e (replied in their threads).

On the screenshots: mini/run mode can't be started in the harness, but RunFooterView is the production component, so these are real renderer captures. This OpenTUI build only exposes character-frame capture, so there is no PNG to attach.

With the experiment on, provider reporting $0:

Build · gpt-5 · 159.6K (16%) · ≈ $4.23 · ctrl+p menu

With it off:

Build · gpt-5 · 159.6K (16%) · ctrl+p menu

After the fix above, a provider that reports a cost keeps showing that step's reported figure in both modes; ≈ only appears for zero-cost sessions.

@augustovicente

Copy link
Copy Markdown
Author

Review addressed in 5f4e20e — ready for another look.

  • sessionSpend now only produces an estimate, and only while the session's recorded cost is zero. A step's reported cost is kept as-is in both modes, and no estimate is computed when that step reported one.
  • The unused pricing field, its type, and the fixture line are gone.
  • Both footer states are captured from the real renderer in the comment above.

Checking GitHub directly, this account can't request reviewers (read-only access), so a maintainer needs to re-request or approve. check-compliance and check-standards are green on the new SHA, and I'll rebase off dev as soon as #59864 lands.

@opencodejr

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both earlier points are fixed. When a step reports a cost, the footer keeps showing that step's cost, and the estimate only appears when nothing was reported. The unused pricing field is gone. The mini and util/session tests and tsc -b pass on the new head. The public API is unchanged by these commits. I still couldn't run mini mode here, so a screenshot of the footer with the experiment on would help maintainers. Nothing new to flag.

@augustovicente

Copy link
Copy Markdown
Author

Screenshot of both states, from the real RunFooterView in the mini renderer tests (provider reporting cost: 0, experiment on top, off below). This OpenTUI build exposes only character-frame capture, so the captured frame is rasterized here rather than exported from the renderer.

mini footer cost estimate

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This push only rebases the branch onto the latest dev. Your commit has the same content as the one I reviewed last time, and the tests and tsc -b pass on the new head. The public API is unchanged by this push. Nothing new to flag. This still has to land after #59864, which is open, and a screenshot of the mini footer showing ≈ $X would still help maintainers.

@augustovicente

Copy link
Copy Markdown
Author

Rebased onto dev (2026-11-12). Still stacked on #59864, which is open and now conflicting, so the dependency commits remain in this branch.

Resolution notes:

  • packages/schema/src/model.ts keeps both main's FreeformFormat import and the new TokenUsage import.
  • packages/core/src/session/usage.ts now re-exports Model.calculateCost instead of keeping a second copy, matching the move of the pricing helper into @opencode/schema.
  • Re-ran the current gates: bun run typecheck:tsc (33/33 tasks), bun run lint, bun run lint:changed, bun test test/mini (430 pass, 2 skip), plus the util/session, prompt-footer and sidebar-context tests (26 pass). tsc -b in packages/tui is clean.

@simonsilie if #59864 is not going to land soon it may be worth folding it into this one, since the mini footer change cannot compile without it.

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This push only rebases the branch onto the latest dev. Your commit has the same content as the one I reviewed last time, and the mini, util/session and footer/sidebar tests and tsc -b in packages/tui pass on the new head. The public API is unchanged by this push. Nothing new to flag. This still has to land after #59864, which is open, and a screenshot of the mini footer showing ≈ $X would still help maintainers.

@simonsilie

Copy link
Copy Markdown

@augustovicente thanks for the hint. I have also rebase my PR and is now conflict free.

At this point, I'm no longer sure if the maintainers even want my PR. I also don't know right now whether we'd have a better chance of success with one big PR than with two small ones.

@augustovicente

Copy link
Copy Markdown
Author

@simonsilie I agree — with #59864 now rebased onto current dev and conflict-free, one big PR has the better chance than two small ones. Let's fold the mini-footer change into #59864 and retire this PR.

I don't have push access to your fork, so could you add the commit to catalog-cost-estimate? Either route works:

  • Fast-forward (easiest): your current head b227b3cf plus one commit is already prepared on augustovicente:fold/mini-into-59864 — git pull https://github.com/augustovicente/opencode.git fold/mini-into-59864 and push.
  • Or cherry-pick: 772e2c6 "feat(tui): estimate spend in the mini footer" from mini-cost-estimate.

Verified on top of b227b3cf: bun test test/mini (430 pass, 2 skip, 0 fail), the util/session tests, and tsc -b in packages/tui all pass.

One bookkeeping note: this PR carried Closes #60653, so please add that line to #59864's description so the issue still auto-closes.

Closing this PR now to keep the work to a single one — the branch and commit stay here if anything is needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tui: show the cost estimate in the mini/run footer

2 participants