Skip to content

Enhance tokenUsageSection in DiscoverView with time-scoped stats and richer breakdowns #604

Description

@haiphucnguyen

Context

tokenUsageSection in DiscoverView.kt currently renders a horizontal bar chart of
the top 5 models by all-time token usage, sourced directly from
TelemetryMetrics.llmTokensByInstance (a flat in-memory/file-backed map).

With Issue 1 landing (SQLite persistence + LlmUsageRepository), we can query
time-scoped data. This ticket covers enhancing the section to surface that richer data.

Current Behaviour

  • All-time total shown in section header (discover.tokens.total)
  • Top-5 bar chart with provider/model label, fill bar, abbreviated token count, and %
  • Empty state if totalTokensUsed == 0
  • "Open in new" icon navigates to System Diagnostics

Proposed Enhancements

1. Time-scope selector (This Month / This Week / All Time)

Add a compact segmented control or chip row below the section title to switch between:

  • This Month (default)
  • This Week
  • All Time
  1. Summary stat row above the bar chart
    Inside the Surface card, before the bar rows, add a compact 3-column stat strip:
    Tokens used. Calls made Avg tokens/call
    45.2K 38. 1.2K
    All values scoped to the active time period. Uses abbreviateTokens() (already exists) and LocalizationManager.formatNumber().

  2. tokenBarRow — add call count column
    Extend the existing tokenBarRow composable with an additional calls: Int column to the right of the % label, so each row shows:

[model/provider] [====bar====] [45.2K] [62%] [38 calls]

  1. Empty state - scope-aware copy
    Currently the empty state shows a single string (discover.tokens.empty). Update to show a scope-aware message, e.g.:
    "No token usage recorded this month"
    "No token usage recorded this week"
    "No token usage recorded yet"

Depends on #603

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions