Repository navigation
feat: prompt-cache tracking + consistent styled dropdowns - #118
Conversation
- Capture prompt-cache read/creation tokens across chat, agent, subagents, automations and one-shot AI calls; surface cache hits in the ContextRing (cache row + tooltip) and persist to the usage log. - Usage view: cached-input stat, per-row cached column with % of input, and an Estimates toggle to hide models.dev-estimated cost rows. - Cost estimates are cache-aware (models.dev cache_read/cache_write rates). - Model picker rows and triggers show name on one line with capabilities + cost underneath. - Replace all native <select> dropdowns with the shared styled Select (usage source, quick-settings provider, card column/blocker, automations, schedule builder, spawn-agent, llama console, service method, topbar).
|
Warning Review limit reached
Next review available in: 49 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (8)
📝 WalkthroughWalkthroughThe change adds prompt-cache token extraction, cache-aware pricing, database tracking, estimated-cost filtering, cache metrics in chat and agent context displays, and a shared styled ChangesPrompt-cache accounting
Shared controls
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant Provider
participant UsageRecorder
participant ChatAndAgentLoops
participant Database
participant UsageView
Provider->>UsageRecorder: Report cache usage
UsageRecorder->>ChatAndAgentLoops: Pass normalized cache tokens
ChatAndAgentLoops->>Database: Persist usage and estimated cost
Database-->>UsageView: Return totals and recent usage
UsageView->>UsageView: Display cached-token metrics and filters
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 7
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@electron/db/schema.ts`:
- Around line 1029-1032: Add a new versioned migration after the existing
migrations that adds cache_read_tokens and cache_creation_tokens to llm_usage
within the migration transaction, ensuring insertLlmUsage-required columns are
present before the schema version advances. Retain the existing ensure guards as
compatibility fallback, but do not rely on them as the primary schema update.
In `@electron/db/usage-queries.ts`:
- Around line 132-134: Update the excludeEstimated predicate in the usage query
to require both cost_estimated = 0 and cost_usd IS NOT NULL, preserving the UI
contract that excluding estimates shows only calls with provider-reported costs.
In `@electron/lib/coding-tools/subagent.ts`:
- Line 108: Update the onUsage callback in the subagent event forwarding to
accept arguments in the pi-agent-loop order: promptTokens, completionTokens,
reasoningTokens, breakdown, costUsd, cacheReadTokens, and cacheCreationTokens.
Forward each value to childToolCtx.send under the matching payload fields
without shifting or dropping values, and add a regression test using distinct
values for every usage argument.
In `@src/components/automations/schedule-builder.tsx`:
- Around line 241-246: Add accessible names to both schedule Select components:
set ariaLabel to “Interval unit” on the selector using intervalUnit and to “Day
of month” on the selector for the day-of-month value, preserving their existing
props and behavior.
In `@src/components/ui/select.tsx`:
- Around line 72-85: Restore a visible keyboard focus indicator on the Select
trigger button by updating its className focus styles around the button element,
replacing the unconditional focus outline removal with an appropriate
focus-visible outline or ring. Keep the existing hover, disabled, sizing, and
custom class behavior unchanged.
In `@src/components/usage/UsageView.tsx`:
- Around line 184-185: Replace the raw bg-white class on the toggle thumb span
in UsageView with a CSS custom-property background class such as
bg-[var(--surface)], while preserving the existing positioning and transition
classes.
- Around line 170-188: Add aria-pressed={excludeEstimated} to the
estimate-filter button in the UsageView toggle, preserving the existing state
and click behavior while exposing whether estimates are currently excluded.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 98386e1a-986e-4594-8131-6d54923bb049
📒 Files selected for processing (46)
changelogs/v2.6.7.mdelectron/db/schema.tselectron/db/usage-queries.test.tselectron/db/usage-queries.tselectron/ipc/chat.tselectron/ipc/pi-agent.tselectron/ipc/tool-builder.tselectron/ipc/usage-handlers.tselectron/lib/chat-loop.tselectron/lib/chat-subagent-loop.tselectron/lib/coding-tools/subagent.tselectron/lib/compaction.tselectron/lib/heartbeat-runner.tselectron/lib/llm-stream.tselectron/lib/llm.tselectron/lib/model-pricing.test.tselectron/lib/model-pricing.tselectron/lib/pi-agent-loop.tselectron/lib/usage-recorder.test.tselectron/lib/usage-recorder.tselectron/preload.tsshared/models/model-catalog.test.tsshared/models/model-catalog.tssrc/components/agent/AgentChatPane.tsxsrc/components/agent/AgentMessageBubble.tsxsrc/components/agent/ContextRing.tsxsrc/components/agent/SpawnAgentModal.tsxsrc/components/automations/automations-view.tsxsrc/components/automations/schedule-builder.tsxsrc/components/chat/chat-panel/ChatQuickSettings.tsxsrc/components/chat/chat-panel/ChatSubagentBlock.tsxsrc/components/chat/chat-panel/index.tsxsrc/components/kanban/card-detail-sidebar.tsxsrc/components/layout/topbar.tsxsrc/components/settings/LlamaServerConsole.tsxsrc/components/settings/tools/ServiceForm.tsxsrc/components/ui/model-picker.tsxsrc/components/ui/select.tsxsrc/components/usage/UsageView.tsxsrc/hooks/useChatStream.tssrc/hooks/useUsage.tssrc/lib/models-dev.tssrc/store/slices/chat.tssrc/store/slices/terminal-sessions.tssrc/types/index.tssrc/types/usage.ts
- schema: add versioned v39 migration for llm_usage cache columns (ensureColumns stays as fallback) - usage-queries: excludeEstimated now drops rows with no provider-reported cost too (cost_usd IS NOT NULL) - subagent: forward all onUsage args in pi-agent-loop order (was shifting reasoning/breakdown/cost); add regression test with distinct values - schedule-builder: ariaLabel on interval-unit and day-of-month selects - select: visible focus-visible ring on the trigger - UsageView: theme-var toggle thumb + aria-pressed on the estimates button
What does this PR do?
Two related chunks of work:
1. Prompt-cache visibility. Captures cache-read/creation tokens from provider usage (Anthropic
cache_read_input_tokens/ OpenAIcached_tokens) across chat, the Agent, subagents, automations, and one-shot AI calls. Surfaces them in the ContextRing (a Prompt cache row + tooltip), persists them to the usage log, and makes the Usage view show cached input as a stat and per-row column. Cost estimates from models.dev are now cache-aware (cached input priced atcache_read/cache_writerates instead of full input). The Usage view also gains an Estimates toggle to hide rows whose cost is a models.dev estimate.2. Consistent styled dropdowns. The model picker now puts the model name on one line with capabilities + cost underneath, in both the open menu and the closed trigger. All remaining native
<select>dropdowns were replaced with a shared styledSelectcomponent (Radix-based) so every dropdown has the same floating panel and theming: usage source filter, chat quick-settings provider, card column + blocker pickers, automation project scope + approval mode, schedule-builder units, spawn-agent binary, llama server context limit, service HTTP method, and the mobile topbar view selector.Type of change
Screenshots / recording
n/a (desktop UI — happy to add screenshots on request)
Checklist
npm run type-check:allpassesnpm run lintpassesnpm testpasses (runsnpm run compilefirst soelectron/bundle-guard.test.tsactually executes —npm run test:bundleto run just that)npm run test:e2epasses (run before merging UI changes or cutting a release)scripts/features.config.jsso it appears in the "What's New" modal (generated JSON — runnode scripts/generate-features.js)var(--accent),var(--text-primary), etc.)text-[Npx]pixel font classes — rem equivalents only (text-[0.714rem],text-xs, etc.)handle()and returnIpcResult<T>schema.ts— added columns via idempotentensureColumnsguards instead of a new migrationelectron/db/queries.ts— single source of truth (imported by both Electron main process and MCP server); never construct aDatabaseinstance outsidedb/client.ts(Electron) ormcp-server.ts(MCP runtime)dependenciesordevDependenciesadded toROLE_MAPinscripts/generate-licenses.jsandlicenses.jsonregeneratedelectron/mcp/tools/index.tsdispatch +electron/lib/tool-schemas.tsZod schema--external:<pkg>flag in thecompilescript: updated the appropriate allowlist group (RUNTIME_PROVIDED/OPTIONAL_TRANSITIVE/SUBPROCESS_ONLY/SHIPPED_NATIVE) inelectron/bundle-guard.test.tsand (ifSHIPPED_NATIVE) shipped the package viaelectron-builder.ymlNotes for reviewer
What's Newfeature entry was intentionally skipped — this is a refinement of existing surfaces (ContextRing + Usage view) rather than a new headline feature; it's recorded inchangelogs/v2.6.7.md.e2etests not run locally (need the app harness) — flagged in the checklist for the merge gate.coding-tools/subagent.tsforwards the thirdonUsagearg (reasoning tokens) into the subagentpi-agent:usageevent'sbreakdownfield. Out of scope here; cache fields map to the correct positional args regardless.Summary by CodeRabbit
New Features
Style
Documentation