Add OpenCode Go usage support with dashboard credentials and local DB fallback#50
Open
jmtt89 wants to merge 1 commit into
Open
Add OpenCode Go usage support with dashboard credentials and local DB fallback#50jmtt89 wants to merge 1 commit into
jmtt89 wants to merge 1 commit into
Conversation
… fallback Adds an optional OpenCode Go model to the widget. The first gauge shows the rolling 5h window; the second gauge dynamically shows whichever of the 7-day and 30-day windows is currently more used. Two data sources are supported in priority order: - OpenCode dashboard (https://opencode.ai/workspace/<wrk_id>/go) using the user's auth cookie and workspace ID, with server-side reset times for the full subscription. - Local SQLite database (opencode.db) opened in read-only mode as a fallback that requires no extra configuration but only reflects this machine's session costs. The dashboard parsing approach is ported from opgginc/opencode-bar (Swift) and validated against its test fixtures. Localizations updated in all 10 languages. New dependency: regex 1.
jmtt89
marked this pull request as ready for review
July 3, 2026 18:35
|
Would be awesome to see this merged :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an optional OpenCode Go model to the widget, alongside the existing Claude Code, Codex, and Antigravity providers. The first gauge always shows the rolling 5h window; the second gauge shows whichever of the 7-day and 30-day windows is currently more used (with the window name prefixed in the value text so the user can tell which one is being displayed).
Two data sources are supported, in priority order:
OpenCode dashboard (recommended) — uses the user
authcookie and workspace ID to fetch real Go usage fromhttps://opencode.ai/workspace/<wrk_id>/go. The dashboard returnsusagePercentandresetInSecper window (rolling / weekly / monthly), so the widget shows the actual server-side reset countdowns and includes usage from other devices.Local SQLite database (fallback) — if no dashboard credentials are configured, the monitor falls back to the local
opencode.dbopened inSQLITE_OPEN_READ_ONLYmode. This reflects only this machine session costs and shows estimated 5h / 7d reset windows from the current poll time (the local DB has no server-side reset signal).How it works
#2EBD85) with a white "O" label.OPENCODE_GO_WORKSPACE_ID+OPENCODE_GO_AUTH_COOKIEenvironment variablesOPENCODE_GO_CONFIG_FILE(if set)$XDG_CONFIG_HOME/opencode-bar/opencode-go.json(oropencode-quota/)~/.config/opencode-bar/opencode-go.json(oropencode-quota/)%APPDATA%\opencode-go\config.json(Windows-friendly default)$OPENCODE_DB→~/.local/share/opencode/opencode.db→%APPDATA%\opencode.db$R[N]resource references are both supported).pick_opencode_second_window) comparesweekly.usage_percentagainstmonthly.usage_percentand uses the larger one for the second gauge. If only one window is present, that one is used; if both are missing, the gauge is empty.Setup for dashboard mode
https://opencode.ai/goin your browser.https://opencode.aiand copy the value ofauth./workspace/<wrk_id>/go).%APPDATA%\opencode-go\config.jsonwith:{ "workspaceId": "wrk_01...", "authCookie": "eyJhbGciOi..." }Setup for local DB fallback
Just install OpenCode, sign in to a Go subscription, run at least one session so the local database exists, and enable OpenCode from the Models menu. No additional configuration is required.
Notes
OPENCODE_DBenvironment variable.AI development disclosure
This feature was developed end-to-end with an AI coding agent (opencode-go running the MiniMax-M3 model). The development followed an iterative, user-driven workflow:
opencode.db) and computedcostaggregations against hardcoded $12 / $30 limits.%USERPROFILE%\.local\share\opencode\opencode.dbon Windows), not%APPDATA%\Roaming\opencode\opencode.db. The path discovery was extended to checkXDG_DATA_HOMEand the cross-platform default.time_updatedin the 7-day range). Both were rejected because the local DB only tracks this machine'"'"'s sessions, while the server-side reset depends on usage from all devices.OpenCodeGoProvider.swift, and ported the approach to Rust: env vars / config file credential discovery, theCookie: auth=<value>+ desktop Chrome User-Agent request, and the two regex patterns (window body capture + numeric field extraction) that handle both the Next.js escaped-JSON shape and the Solid$R[N]resource-reference shape. The 3 parser test fixtures from the Swift test suite were used to validate the Rust port.pick_opencode_second_windowhelper compares the two windows; the chosen window'"'"'s label is carried throughUsageData.weekly_labeland prepended to the value text at render time.All 18 changed files were reviewed and the final build (
cargo build --release) compiles cleanly with zero warnings.