feat(usage): add OpenCode usage reporting - #8456
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2c7485e2e2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
ApprovabilityVerdict: Not approved Macroscope's review found this PR not approvable — This PR adds a substantial OpenCode usage capability across SQLite scanning, configuration discovery, cross-environment deduplication, contract versioning, and client presentation. Because it changes production usage collection and reported totals across multiple layers, the scope warrants human review. You can add or adjust custom eligibility rules. Learn more. |
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.
Reviewed by Cursor Bugbot for commit daf4731. Configure here.
|
This would be sooooo nice to have |

What Changed
messagetable and currentsession_messagetable.OPENCODE_DBoverrides, and channel-specific databases while reporting missing, failed, or partial source health.Why
Closes #7622. OpenCode persists its usage in SQLite, so the existing Claude Code, Codex, and Grok JSONL scan could never include it. This keeps sessions run outside T3 Code visible while ensuring prompt, response, and tool content never leave the local database.
This overlaps #7623 and #7221. #7623 covers the contract and presentation but not collection; #7221 is based on an older main and mixes in broader scan behavior. This PR keeps the complete path focused on OpenCode usage against current main.
UI Changes
Validation
git diff --check.t3runtime and the live OpenCode schemaChecklist
Built with GPT-5 Codex in T3 Code.
Note
Medium Risk
Touches usage contract v6, cross-environment merge rules, and read-only SQLite against user-local OpenCode DBs; behavior is heavily tested but affects reported totals and mixed-version clients.
Overview
Adds OpenCode as a first-class usage provider by reading completed assistant usage from local SQLite stores (read-only), alongside the existing Claude/Codex/Grok JSONL scans.
A new
usageOpenCodeadapter discovers databases from XDG data paths,OPENCODE_DB/ channel DB naming, and per–OpenCode-instance env overrides; it projects only token/cost metadata fromsession_messageand legacymessagetables, normalizes reasoning vs output tokens, dedupes migrated rows, and surfaces missing/failed/partial source health.UsageService.readSummaryfolds those records in with optionalsourcePathon buckets so multiple DBs stay distinct.The usage contract bumps to v6 (
opencode+ optionalsourcePath); aggregation and multi-environment merge respectsourcePathwhen deduplicating shared databases. Web and mobile gain OpenCode label, color, and icon; user docs describe SQLite-backed totals and pricing fallbacks when cost is zero.Reviewed by Cursor Bugbot for commit 84d43e4. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Add OpenCode usage reporting across server, contracts, and UI
usageOpenCode.tsto read OpenCode assistant usage from SQLite databases (current and legacy tables) with cross-runtime Bun/Node support, honoringOPENCODE_DBoverrides and channel database discoveryUsageService.maketo collect OpenCode environments from the host andopencodeprovider instances, resolve database paths, and aggregate records withsourcePathprovenanceUsageAggregatorandusageMergeto bucket and deduplicate bysourcePathso multiple stores under the same provider stay distinct and shared stores are owned correctlyUSAGE_CONTRACT_VERSIONto 6, adds'opencode'toUsageProviderKind, and adds optionalsourcePathtoUsageBucketUSAGE_CONTRACT_VERSIONmoves from 5 to 6; older clients that only negotiate version 5 will not receive OpenCode summaries.readFileRecordsandreadTranscriptRecordsnow exclude'opencode'from their provider type parameter, so any caller passing'opencode'to these JSONL readers will get a type errorMacroscope summarized 84d43e4.