Skip to content

feat(native): usage page, pooled limits, and composer context window meter - #47

Merged
rynfar merged 3 commits into
nativefrom
nw/w12-usage
Nov 2, 2026
Merged

rynfar merged 3 commits into
nativefrom
nw/w12-usage

Conversation

@rynfar

@rynfar rynfar commented Nov 2, 2026

Copy link
Copy Markdown
Owner

The native app had no Usage page and no composer context meter (ledger AP-USAGE, CO-METERS). This ports both from the web against the unmodified server.

What's in it

Core (crates/core/src/usage.rs, usage/), pure and tested (30 tests, cases ported from the web suites):

  • Wire types for server.getUsageSummary / server.refreshUsageRates (contracts/src/usage.ts). Forward-compatible arrays drop buckets and sources from providers this build doesn't know.
  • mergeUsage (usageMerge.ts): shared transcript directories count once, newer partial scans add only new cells, contract mismatches are excluded.
  • Number and window formatting (usageFormat.ts), matching Intl and toFixed, including how each rounds a tie.
  • Pooled limits (usageLimits.ts): account merging across native logins and limit sources, pool windows, pace, weekly-blocked sessions, Cursor and Antigravity ordering, notices, external usage links, and the /usage-limits report.
  • Chart geometry (monotone cubic, nice ticks), context window snapshot (contextWindow.ts), access, progress and saved preferences.
  • Server config now opts into usageLimitSources and decodes the full usage limits, auth email and workspace, and usageModelFilter.

App (crates/app/src/usage/): a route modal like Settings.

  • Cost, Tokens and Limits (keys C, T, L) and the period (cmd-shift-1..4). Shortcut titles come from the keymap.
  • Header: environment filter with status and coverage notes, provider filter, compact menus on narrow windows.
  • Overview: headline, per-provider rows, the provider chart drawn with GPUI paths (12% areas, 2px lines, hover tooltip), totals, cost and token share bars, and the model or period breakdown.
  • Model breakdown dialog. Pooled limits with pace ticks, refill, segment details, and reset credits behind a confirm.
  • Summaries load and decode on the network runtime, are cached per window for 60 seconds, and keep the last answer dimmed while a new window loads. Nothing repaints on its own.
  • Entry points: cmd-u (usage.open), the command palette ("Open usage"), and the sidebar footer. The footer is now one row (Settings, Pull requests, Usage), as on the web, and the existing Pull requests item moves into it.
  • Composer: the context window meter (ContextWindowMeter.tsx), mounted beside Send with one line, plus its legacy Labs toggle "Context window indicator (legacy)".
  • Provider hues and share-bar inks come from gen-theme.ts, which reads usageProviders.ts and usageBreakdown.ts. Five Lucide icons are vendored.
  • Snapshot tool: --usage cost|tokens|limits, --usage-period, --usage-model, --context-meter. Limits skips the provider refresh, so runs stay read-only.

Not ported yet (tracked in #43)

  • The Model prices dialog (UsagePriceOverrides). The "Model prices" menu item and the dialog's "Set price" button are left out.
  • The /usage-limits composer banner. Its logic is ported, but intercepting the command belongs to the composer's slash commands, so usageLimitsCommand is not advertised.
  • The meter's "Compact context", prompt length validation, and a fork's inherited context before its first turn.
  • Refresh shows a static, disabled icon instead of spinning.

Evidence

Headless decode (cargo run -p t3-client --example usage_probe). Real-data server (14700, read-only):

Past 24h contract=6 buckets=52/52 sources=11 models=6  providers=[Codex, Claude] periods=24/24 cost=$1,184.00 tokens=4.39B sessions=266
7 days   contract=6 buckets=32/32 sources=11 models=10 providers=[Codex, Claude, Opencode, Pi] periods=7/7 cost=$3,253.50 tokens=11.8B sessions=637
30 days  contract=6 buckets=99/99 sources=11 models=23 providers=[Codex, Claude, Opencode, Antigravity, Pi] periods=30/30 cost=$9,099.08 tokens=39.8B sessions=2738
90 days  contract=6 buckets=223/223 sources=11 models=36 providers=[...] periods=78/90 cost=$25,771.56 tokens=67B sessions=4572
limits  10 providers, 0 sources, 2 pools, notices=[]
        codex: Weekly 92% left pace=Some(Under) accounts=1
        claudeAgent: Weekly 87% left pace=Some(On); Weekly · Fable 99% left pace=Some(Under); Monthly spend 100% left pace=None
  • Smoke server (14658) with --refresh-rates: status: fresh, 4889 known models, all four periods decode.
  • Parity check: the same dumped replies merged by the web's mergeUsage give identical totals (30 days $9,101.79 / 39.8B / 2738 sessions / 23 models; 90 days $25,773.74 / 67B / 4572 / 36).
  • Meter: usage_probe --thread <id> reads "Context window 27% used".

Screenshots (offscreen snapshot tool, real-data server):

  • /private/tmp/claude-501/-Volumes-DevSSD-t3code/7a9093f7-05bd-4183-ab15-c4265aa48126/scratchpad/w12-shots/limits-light.png
  • /private/tmp/claude-501/-Volumes-DevSSD-t3code/7a9093f7-05bd-4183-ab15-c4265aa48126/scratchpad/w12-shots/cost-30d-light.png
  • /private/tmp/claude-501/-Volumes-DevSSD-t3code/7a9093f7-05bd-4183-ab15-c4265aa48126/scratchpad/w12-shots/tokens-24h-dark.png
  • /private/tmp/claude-501/-Volumes-DevSSD-t3code/7a9093f7-05bd-4183-ab15-c4265aa48126/scratchpad/w12-shots/model-dialog-light.png
  • /private/tmp/claude-501/-Volumes-DevSSD-t3code/7a9093f7-05bd-4183-ab15-c4265aa48126/scratchpad/w12-shots/meter-light.png (meter beside Send, sidebar footer row)

Gates: cargo test --workspace, cargo clippy --workspace --all-targets -- -D warnings (also with --features snapshot), gen-theme --check, parity/sync.test.ts, conformance --check, vendor-icons --check.

Ledger: AP-USAGE and CO-METERS are now partial, with follow-ups in #43.

Model: Opus 5.5, Claude Code (native-worker W12).

@rynfar

rynfar commented Nov 2, 2026

Copy link
Copy Markdown
Owner Author

Rebased onto native (a5513f9, after #37 and #46). Conflicts resolved so both sides keep their behavior:

Checks all pass: cargo test --workspace, clippy (workspace and --features snapshot), gen-theme --check, parity/sync.test.ts, conformance --check (no regeneration needed), and vp fmt (it reformatted the ledger). A read-only --usage cost snapshot against real data rendered without a panic. Not merged.

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.

1 participant