feat: add OpenCode usage statistics - #7221
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Comment |
There was a problem hiding this comment.
One finding: adding a third usage provider makes the hardcoded colSpan on the time-breakdown empty state in UsagePage.tsx under-span the table. Details inline.
Posted via Macroscope — UI Consistency
ApprovabilityVerdict: Not approved Macroscope's review found this PR not approvable — This adds OpenCode usage reporting through a new SQLite worker integration and propagates the provider through server, contract, web, and mobile layers. It also changes existing transcript failure handling and multi-environment merge ownership, creating broader runtime impact than a small isolated usage update. You can add or adjust custom eligibility rules. Learn more. |
c8ef112 to
222b55f
Compare
2ce7e4f to
557dbb7
Compare
- Read OpenCode SQLite transcripts and report token and cost usage - Display OpenCode usage across web and mobile clients
…rsion A failed OpenCode SQLite open/query was flattened to zero usage and reported as status ok; propagate the null so the source reports failed. Adding the opencode provider kind also changes the wire schema, so bump USAGE_CONTRACT_VERSION to 5 for older clients to detect.
…s it The resolver invented a macOS Application Support branch and an OPENCODE_DATA_HOME override; the CLI resolves its data home through xdg-basedir on every platform (XDG_DATA_HOME or ~/.local/share/opencode) and the only documented override is OPENCODE_DB, which can be absolute or name a database inside the data home. Mirror that, including the channel-suffixed database caveat for dev installs.
13d3eb0 to
a1cf597
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 42cdcfe. Configure here.

What changed
The Usage page previously only counted Claude Code and Codex. This adds OpenCode as a third scanned provider.
~/.local/share/opencode/opencode.db), so instead of the JSONL file walk the other providers use, its scan is a single read-only query against themessagetable vianode:sqlite. The window filter is pushed into SQL (time_updated), and only completed assistant messages with token usage and a known model are projected into usage records.costis trusted when positive (OpenCode prices its own curated/subscription models that LiteLLM doesn't know); zero-cost rows fall back to LiteLLM like Codex. The messageidis the dedupe key.UsageProviderKindgains"opencode".PROVIDER_PRESENTATION(violet#8b5cf6,OpenCodeIcon); the chart test expectation gains the zero-value opencode band thatPROVIDER_ORDERnow produces.Why
Anyone driving agents through OpenCode currently sees an empty or understated Usage page. Scanning the provider's own transcript store (rather than T3's orchestration projections) keeps usage complete even for sessions never driven through T3 Code — the same
ccusage-style approach the existing providers use.Before / after
Verification
usageTranscripts.test.tsgains focused coverage for the OpenCode message projection (88 new lines); all 26 usage tests pass.Built with kimi-k3 via OpenCode.
Note
Medium Risk
New SQLite/worker read path and changed merge dedupe behavior affect reported totals; scan cache v3 invalidates prior entries. Contract v6 adds a provider but remains merge-compatible with v4+.
Overview
Adds OpenCode as a fourth usage provider end-to-end: contract
UsageProviderKindand v6 contract version, mobile/web chart labels and violet styling, and docs.On the server, usage is read from OpenCode’s SQLite store (
~/.local/share/opencode/opencode.db, overridable viaOPENCODE_DB/XDG_DATA_HOME) instead of JSONL walks. A read-only worker query pulls completed assistant usage from legacymessageand currentsession_messagetables; rows map throughparseOpenCodeUsageRow(completion time, token/cost rules, message id dedupe). OpenCode skips the per-file scan cache (window-sensitive); scan cache bumps to v3 for the expanded provider set.Reliability: JSONL listing now surfaces
hadReadError; failed transcript reads returnnulland sources can bepartialorfailedinstead of silently counting zero. Multi-environment mergeclaimSourcesprefers healthier sources (okoverpartial; failed/missing don’t claim) so a bad duplicate scan doesn’t hide good data.Reviewed by Cursor Bugbot for commit 8e7316b. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Add OpenCode usage provider with SQLite worker reader and source-health merge ranking
opencodeas a new usage provider across server, web, mobile, and contracts; the server reads OpenCode usage from its SQLite database via a worker thread inreadOpenCodeRecords, honoringOPENCODE_DBand XDG defaults viaresolveOpenCodeDatabasePath.parseOpenCodeUsageRowto project scalar rows intoUsageRecord, capping reasoning tokens to output, dropping zero-token rows, and trusting positive reported costs.listTranscriptFilesnow returnshadReadErrorsoreadSummarycan mark JSONL sourcespartialwhen directory traversal or file reads fail, with a user-facing message.claimSourcesnow ranks sources (ok>partial>missing/failed) so a failed source no longer hides a healthy duplicate;ownedContributionexcludes failed/missing sources from session and bucket attribution.USAGE_SCAN_CACHE_VERSIONbumps 2→3 andUSAGE_CONTRACT_VERSIONbumps 5→6, causing a one-time cold rescan and requiring client/server contract renegotiation; OpenCode reads bypass the mtime/size cache and always fetch fresh, which may add overhead on large databases.Macroscope summarized 8e7316b.