feat(opencode): switch Go meters to the official usage API - #1097
Conversation
Local SQLite dollar-cap math only saw this Mac and drifted from the dashboard. The new /zen/go/v1/usage endpoint is account-wide percents. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default 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 5aae1f0. Configure here.
Wall-clock now-30d sat later the same day than start-of-day 30 days ago, so morning rows on the oldest day never left SQLite. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Confirming the production usage payload that this PR consumes.
Filed the remaining 0.7.8 user-facing bug (local SQLite |
…s#1097) * feat(opencode): read Go plan windows from the official usage API Local SQLite dollar-cap math only saw this Mac and drifted from the dashboard. The new /zen/go/v1/usage endpoint is account-wide percents. Co-authored-by: Cursor <cursoragent@cursor.com> * fix(opencode): align SQLite scan cutoff with the calendar tile window Wall-clock now-30d sat later the same day than start-of-day 30 days ago, so morning rows on the oldest day never left SQLite. Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: Cursor <cursoragent@cursor.com> (cherry picked from commit 064819b)
**TL;DR** — The OpenCode Session / Weekly / Monthly meters now come from OpenCode's official usage endpoint (`GET https://opencode.ai/zen/go/v1/usage`, authorized with the local `opencode-go` key) instead of being reconstructed from local SQLite logs with hardcoded dollar caps and window math. Port of upstream openusage robinebers#1097. **What was happening** - The Go plan meters were estimated locally: `OpenCodeGoWindows` reimplemented the rolling 5-hour session, ISO-week, and anchored-month windows over this machine's logs, bounded by hardcoded dollar caps. - That undercounted account usage from other machines, drifted from OpenCode's own accounting, and broke whenever OpenCode changed plan caps. **What this changes** - New `OpenCodeUsageClient` calls the official usage API; the mapper turns `{ usage: { rolling, weekly, monthly } }` into three percent meters with reset countdowns — the same numbers the OpenCode dashboard shows, account-wide. - The provider distinguishes a rejected key (401), a valid key with no Go subscription (403 `EntitlementError` → meters hidden, spend tiles stay), and transport errors. If the local database is unreadable but the API works, the meters still render and the failure is logged. - `OpenCodeGoWindows` (147 lines of window math) and its tests are deleted; the scanner now only feeds the spend tiles and trend from local logs. - Metric IDs (`opencode.session/weekly/monthly`) are unchanged, so layout customizations, pins, and defaults carry over; the widgets switch from bounded-dollar meters to percent meters. Docs updated (`docs/providers/opencode.md`, `docs/local-http-api.md`). **Heads-up** - Runway-specific adaptations from upstream: no telemetry `ErrorCategory` (Runway removed PostHog), and the scanner keeps Runway's `DayKeyCache` day-key memoization. - The local HTTP API's `session`/`weekly`/`monthly` units change from `usd` (estimated) to `percent` — anything scripted against those units will see the new unit field. **Tests** - `swift test` — full suite, 1772 tests, 0 failures (42 OpenCode tests, ported from upstream with the Runway adaptations above).

TL;DR
OpenCode Go Session / Weekly / Monthly now come from
GET https://opencode.ai/zen/go/v1/usage— the same account-wide percents as the OpenCode dashboard. Local SQLite dollar-cap math is gone. Spend tiles and the usage trend still come from this Mac's logs.What was happening
opencode-gomessage costs against hardcoded $12 / $30 / $60 caps.What this changes
OpenCodeUsageClientcalls/zen/go/v1/usagewith the localopencode-gokey asAuthorization: Bearer.{ usage: { rolling, weekly, monthly } }into.percentmeters (widget IDs and placement unchanged).EntitlementError→ no Go subscription (Zen spend tiles still work). Generic 403 / transport failures fail loudly.OpenCodeGoWindowsand the local window math. Scanner is tiles + trend only.docs/providers/opencode.md, local HTTP API unit ispercent).Heads-up
Tests
./script/build_and_run.sh verify— dev build launched; live Go key returned Session ~1% / Weekly 0% / Monthly ~1%.Made with Cursor