Skip to content

feat(usage): add OpenCode to usage contract and provider presentation - #7623

Closed
Project516 wants to merge 2 commits into
pingdotgg:mainfrom
Project516:feat/usage-opencode
Closed

feat(usage): add OpenCode to usage contract and provider presentation#7623
Project516 wants to merge 2 commits into
pingdotgg:mainfrom
Project516:feat/usage-opencode

Conversation

@Project516

@Project516 Project516 commented Aug 20, 2026

Copy link
Copy Markdown

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 main as v5 in #8358.

  • packages/contracts/src/usage.ts gains "opencode" in UsageProviderKind (["claude", "codex", "grok", "opencode"]) and bumps USAGE_CONTRACT_VERSION from 5 to 6. USAGE_MERGE_COMPATIBLE_SINCE stays 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.ts registers OpenCode as OpenCode, violet #8b5cf6, with OpenCodeIcon alongside the existing grok entry. Keeps codex color as var(--contrast-foreground) from main and retains the providersWithUsage helper. Order is now codex, claude, grok, opencode, so charts, legends, and tables pick it up automatically.
  • apps/mobile/src/features/usage/usageProviders.ts adds the same order, label, and color for the React Native chart (grok stays as the neutral gray, opencode is violet).
  • apps/web/src/components/usage/UsageProviderChart.test.ts now expects zero-valued grok and opencode bands together.

This is the contract and UI half. The server scan that reads ~/.local/share/opencode/opencode.db via node:sqlite follows 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 main at f6f2be32d to resolve conflicts with Grok usage (#8358) and subsequent usage-page refactors (provider filtering, skeleton updates, and activeProviders).

Why

The Usage page now knows claude, codex, and grok. 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. My opencode stats says 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 ccusage approach 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 main yet. 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. UsagePage already filters to activeProviders on main, so the breakdown table only shows providers with activity and its empty-state colSpan stays as activeProviders.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

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes (no change until server scan lands)
  • I included a video for animation/interaction changes (not applicable)

Built with opencode + muse-spark-1.2-contributor on t3.

Closes #7622


Note

Medium Risk
Bumping the usage contract version and extending UsageProviderKind affects 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, UsageProviderKind gains the opencode literal and USAGE_CONTRACT_VERSION is bumped to 6 (with merge notes that v5 grok and v4 buckets still merge). Web usageProviders registers OpenCode presentation (label, violet #8b5cf6, OpenCodeIcon), and mobile usageProviders adds the same label, color, and stack order. Chart tests now expect a zero-valued opencode band in day columns.

Until backends emit opencode buckets, 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 opencode provider to usage contract and provider presentation

  • Extends UsageProviderKind schema with the literal "opencode" and bumps USAGE_CONTRACT_VERSION from 5 to 6 in usage.ts
  • Adds opencode to PROVIDER_ORDER, PROVIDER_LABEL, and useProviderColors (color #8b5cf6) in the mobile providers map usageProviders.ts
  • Adds matching PROVIDER_PRESENTATION entry with label, color, and OpenCodeIcon in the web providers map usageProviders.ts
  • Updates the web chart test to expect an opencode band with value 0 UsageProviderChart.test.ts
  • Risk: clients on contract version 5 will not recognize opencode in usage summaries; bumping USAGE_CONTRACT_VERSION to 6 means only version-6-aware consumers can parse the new provider kind

Macroscope summarized fe3155c.

@coderabbitai

coderabbitai Bot commented Aug 20, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8b3520e0-3bb7-485a-b703-1e7cda038156

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:S 10-29 changed lines (additions + deletions). labels Aug 20, 2026

@macroscopeapp macroscopeapp Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a third usage provider leaves two web call sites still assuming two. Details in the inline comment.

Posted via Macroscope — UI Consistency

Comment on lines +27 to +31
opencode: {
label: "OpenCode",
color: "#8b5cf6",
mark: OpenCodeIcon,
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registering a third provider here changes two downstream call sites that still assume two:

  1. UsagePage.tsx:396 — the time breakdown header renders 1 period column + PROVIDER_ORDER.length provider columns + Total + Tokens (now 6), but the "No activity in this window." row is still colSpan={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}.
  2. UsageProviderChart.test.ts:85buildDayColumns maps over PROVIDER_ORDER, so each column now has a third band; the "keeps band values absolute rather than cumulative" assertion still lists only codex and claude and 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

@macroscopeapp

macroscopeapp Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at fe3155c

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.

@Project516

Copy link
Copy Markdown
Author

Fixed both call sites flagged by Macroscope:

  • UsagePage.tsx:396 now derives colSpan={PROVIDER_ORDER.length + 3} so the empty time breakdown spans 1 period + providers + Total + Tokens without a stray cell.
  • UsageProviderChart.test.ts:85 assertion now includes the third band { provider: "opencode", value: 0 } so it stays green with the new provider order.

Pushed as 242359b on top of cb2cc4b.

macroscopeapp[bot]
macroscopeapp Bot previously approved these changes Aug 20, 2026
@SpyC0der77

Copy link
Copy Markdown

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.
@Project516
Project516 force-pushed the feat/usage-opencode branch from 242359b to fe3155c Compare August 27, 2026 18:36
@macroscopeapp
macroscopeapp Bot dismissed their stale review August 27, 2026 18:37

Dismissing prior approval to re-evaluate fe3155c

@t3dotgg

t3dotgg commented Aug 28, 2026

Copy link
Copy Markdown
Member

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.

@t3dotgg t3dotgg closed this Aug 28, 2026
@Project516
Project516 deleted the feat/usage-opencode branch August 28, 2026 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S 10-29 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Usage page does not include OpenCode [Feature]: Report Grok and OpenCode activity on the Usage page

3 participants