Skip to content

feat(tui): show session cost in tray status line - #919

Open
Xsidz wants to merge 3 commits into
PrimeIntellect-ai:mainfrom
Xsidz:fix/tui-session-cost
Open

feat(tui): show session cost in tray status line#919
Xsidz wants to merge 3 commits into
PrimeIntellect-ai:mainfrom
Xsidz:fix/tui-session-cost

Conversation

@Xsidz

@Xsidz Xsidz commented Aug 8, 2026

Copy link
Copy Markdown

Summary

Shows accumulated session spend in the TUI tray/status line next to the existing token/context readout:

main · 128.4k (61%) · $1.32
  • Added sessionCost?: number to AgentConnectionState in types.ts
  • Populated from session.getSessionStats().cost in createAgentConnectionState (snapshot.ts) so cost is available immediately on attach
  • Persisted each turn via refreshConnectionContextUsage alongside the existing contextUsage patch (no extra RPC call — getSessionStats was already called here and the result discarded)
  • Rendered in getTrayContextLabel with sub-cent precision: 4 decimal places for cost < $0.01 (e.g. $0.0042), 2 decimal places otherwise

All the plumbing already existed; this is a display-only change.

Test plan

  • npm run check passes (biome, tsgo, installer render, browser smoke)
  • $0.00 shown when cost is 0 (before first assistant turn)
  • Sub-cent cost shows 4 decimal places (e.g. $0.0042)
  • Normal cost shows 2 decimal places (e.g. $1.32)
  • Cost only appears when sessionCost is populated (no undefined rendered)

Fixes #894

Note

Show session cost in TUI tray/status line alongside token/context readout

  • Adds an optional sessionCost field to AgentConnectionState in types.ts, populated from session.getSessionStats() in snapshot.ts.
  • Extends getTrayContextLabel in interactive-mode.ts to append a formatted cost string (e.g. $1.32) next to the context usage label, updated after each completed turn.
  • Adds formatSessionCost helper: shows $0.00 for zero, 4 decimal places below $0.01, otherwise 2 decimal places.

Macroscope summarized 23d7315.

Copilot AI lite review requested due to automatic review settings August 8, 2026 09:23

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds persistent session cost visibility to the interactive TUI tray/status line by plumbing SessionStats.cost into the connection snapshot/state and rendering it next to the existing token/context usage readout.

Changes:

  • Extended AgentConnectionState with optional sessionCost?: number.
  • Populated and refreshed sessionCost from getSessionStats().cost (on attach via snapshot, and after each completed turn via the existing context-usage refresh).
  • Rendered a cost label in the tray with sub-cent precision rules and documented the change in the coding-agent changelog.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
packages/coding-agent/src/modes/interactive/interactive-mode.ts Persists sessionCost during usage refresh and appends a formatted cost label to the tray context string.
packages/coding-agent/src/modes/agent-connection/types.ts Adds sessionCost?: number to the connection state shape.
packages/coding-agent/src/modes/agent-connection/snapshot.ts Populates sessionCost from session.getSessionStats() so it’s available immediately on attach.
packages/coding-agent/CHANGELOG.md Adds an Unreleased entry documenting the new tray cost display.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/coding-agent/src/modes/agent-connection/snapshot.ts

@Xsidz Xsidz left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good catch — fixed in a82fb3ca. Replaced session.getContextUsage() with sessionStats.contextUsage since getSessionStats() already calls getContextUsage() internally.

@Xsidz
Xsidz force-pushed the fix/tui-session-cost branch 2 times, most recently from 40af471 to bf1066b Compare August 11, 2026 17:35
Siddhesh Kabra added 3 commits August 11, 2026 23:32
Populates session spend from getSessionStats().cost in the
connection state snapshot so the TUI can render it in the tray.

Part of fixes PrimeIntellect-ai#894
Renders accumulated session spend next to token/context usage,
e.g. '128.4k (61%) · $1.32'. Sub-cent costs use 4 decimal places
to avoid showing $0.00 for non-zero spend.

fixes PrimeIntellect-ai#894
…ntextUsage() again

getSessionStats() already calls getContextUsage() internally; reusing
the result avoids the duplicate scan of session state.
@Xsidz
Xsidz force-pushed the fix/tui-session-cost branch from bf1066b to 23d7315 Compare August 11, 2026 18:05
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.

Show session token cost in the TUI tray/status line (not just /context)

2 participants