feat(usage): add OpenCode to usage contract and provider presentation - #7623
feat(usage): add OpenCode to usage contract and provider presentation#7623Project516 wants to merge 2 commits into
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.
Adding a third usage provider leaves two web call sites still assuming two. Details in the inline comment.
Posted via Macroscope — UI Consistency
| opencode: { | ||
| label: "OpenCode", | ||
| color: "#8b5cf6", | ||
| mark: OpenCodeIcon, | ||
| }, |
There was a problem hiding this comment.
Registering a third provider here changes two downstream call sites that still assume two:
UsagePage.tsx:396— the time breakdown header renders 1 period column +PROVIDER_ORDER.lengthprovider columns +Total+Tokens(now 6), but the "No activity in this window." row is stillcolSpan={5}, so the empty state stops one column short and leaves a stray cell at the right edge. Suggest deriving it:colSpan={PROVIDER_ORDER.length + 3}.UsageProviderChart.test.ts:85—buildDayColumnsmaps overPROVIDER_ORDER, so each column now has a third band; the "keeps band values absolute rather than cumulative" assertion still lists onlycodexandclaudeand will fail. Add{ provider: "opencode", value: 0 }.
The rest of the presentation wiring (label, color, mark, chart/legend/tooltip/skeleton consumption) matches the existing providers.
Posted via Macroscope — UI Consistency
ApprovabilityVerdict: Approved at Macroscope's review found this PR approvable — This is a small, additive contract and UI registration for OpenCode using existing provider-rendering paths, with no server scanning, deployment, or sensitive-data changes. Backward compatibility remains explicitly supported, and current existing-provider behavior is preserved. You can add or adjust custom eligibility rules. Learn more. |
|
Fixed both call sites flagged by Macroscope:
|
|
Yes, PLEASE IMPLEMENT THIS |
Usage currently only reports claude and codex. Users who run opencode see empty or low totals on the Usage page, even though their SQLite store holds the same token and cost data. This bumps USAGE_CONTRACT_VERSION to 5, adds opencode to UsageProviderKind, and registers the label, color and icon in web and mobile. The page can now render the third provider once the server starts scanning opencode.db. The scan itself follows in a next change, as in pingdotgg#6040. Closes pingdotgg#7622
The opencode addition bumps PROVIDER_ORDER to three, but UsagePage still used colSpan 5 for the empty time breakdown. With the header now 1 + 3 + 2 columns, that left a stray cell. The chart test also listed only two bands, so it would fail once PROVIDER_ORDER includes the third provider. Derive the colspan from PROVIDER_ORDER and extend the band assertion to include opencode.
242359b to
fe3155c
Compare
Dismissing prior approval to re-evaluate fe3155c
|
Note 🤖 GPT-5.6 Sol responding on behalf of Theo We're closing this PR as we clean up the T3 Code backlog. Thank you for taking the time to put this together. We are keeping OPEN #8456 as the review path for OpenCode usage reporting. The focused provider-chart test here remains useful reference. If you believe we closed this in error, please reopen the PR and leave a comment explaining what we missed. |
What Changed
Adds OpenCode to the usage contract and to the provider presentation on web and mobile, on top of the Grok support that landed on
mainas v5 in #8358.packages/contracts/src/usage.tsgains"opencode"inUsageProviderKind(["claude", "codex", "grok", "opencode"]) and bumpsUSAGE_CONTRACT_VERSIONfrom 5 to 6.USAGE_MERGE_COMPATIBLE_SINCEstays at 4, so v4 Claude/Codex and v5 Grok buckets remain valid. Clients on an older version show partial coverage rather than failing the page.apps/web/src/components/usage/usageProviders.tsregisters OpenCode asOpenCode, violet#8b5cf6, withOpenCodeIconalongside the existinggrokentry. Keepscodexcolor asvar(--contrast-foreground)frommainand retains theprovidersWithUsagehelper. Order is nowcodex, claude, grok, opencode, so charts, legends, and tables pick it up automatically.apps/mobile/src/features/usage/usageProviders.tsadds the same order, label, and color for the React Native chart (grokstays as the neutral gray,opencodeis violet).apps/web/src/components/usage/UsageProviderChart.test.tsnow expects zero-valuedgrokandopencodebands together.This is the contract and UI half. The server scan that reads
~/.local/share/opencode/opencode.dbvianode:sqlitefollows next, as drafted in #6040. Keeping the two apart keeps the contract change reviewable and lets existing clients start handling the new provider.Rebased onto
mainatf6f2be32dto resolve conflicts with Grok usage (#8358) and subsequent usage-page refactors (provider filtering, skeleton updates, andactiveProviders).Why
The Usage page now knows
claude,codex, andgrok. Anyone who works through OpenCode still sees understated cost and token totals. I run OpenCode daily on a Pi and the page tells me I barely used anything. That is not true. Myopencode statssays otherwise.OpenCode already reports per-turn usage for the context meter. The Usage page should do the same rollup it does for the other providers, reading the provider's own store so sessions started outside T3 Code still count. That is the
ccusageapproach the existing providers use.Related: closed #5706 described the gap for Grok and OpenCode. Grok landed in #8358. Open PRs #6040, #6014, and #7221 propose the full OpenCode SQLite scan. None have landed on
mainyet. This starts with the contract so the UI does not need a second pass.UI Changes
No visual change until the server emits opencode buckets. When it does, the same chart and tables that render Codex, Claude, and Grok will include OpenCode without extra wiring.
UsagePagealready filters toactiveProvidersonmain, so the breakdown table only shows providers with activity and its empty-statecolSpanstays asactiveProviders.length + 3.Before: Claude Code, Codex, and Grok Build in the legend (when they have data).
After: legend, chart, and breakdown accept a fourth entry. With empty opencode data the page looks unchanged. With data it shows four bands, as in #6040 screenshots.
Checklist
Built with opencode + muse-spark-1.2-contributor on t3.
Closes #7622
Note
Medium Risk
Bumping the usage contract version and extending
UsageProviderKindaffects every client and server that serializes or merges usage summaries; the change is additive and merge-compatible, but mismatched versions could still show partial coverage.Overview
Extends usage reporting so OpenCode is a first-class provider alongside Claude, Codex, and Grok—contract and UI only; no server scan in this diff.
In
packages/contracts,UsageProviderKindgains theopencodeliteral andUSAGE_CONTRACT_VERSIONis bumped to 6 (with merge notes that v5 grok and v4 buckets still merge). WebusageProvidersregisters OpenCode presentation (label, violet#8b5cf6,OpenCodeIcon), and mobileusageProvidersadds the same label, color, and stack order. Chart tests now expect a zero-valued opencode band in day columns.Until backends emit
opencodebuckets, the Usage page looks the same; when data arrives, charts and tables pick it up via existing provider-order wiring.Reviewed by Cursor Bugbot for commit fe3155c. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Add
opencodeprovider to usage contract and provider presentationUsageProviderKindschema with the literal"opencode"and bumpsUSAGE_CONTRACT_VERSIONfrom 5 to 6 in usage.tsopencodetoPROVIDER_ORDER,PROVIDER_LABEL, anduseProviderColors(color#8b5cf6) in the mobile providers map usageProviders.tsPROVIDER_PRESENTATIONentry with label, color, andOpenCodeIconin the web providers map usageProviders.tsopencodeband with value 0 UsageProviderChart.test.tsopencodein usage summaries; bumpingUSAGE_CONTRACT_VERSIONto 6 means only version-6-aware consumers can parse the new provider kindMacroscope summarized fe3155c.