Repository navigation
Conversation
Adds native support for OpenCode Go subscriptions in the agents panel. Queries OpenCode's official /zen/go/v1/usage API for rolling (5h), weekly, and monthly limit usage with reset timers. Key design decisions: - Harness-agnostic: reads API key from Pi, OpenCode CLI, or env var - Uses curl instead of urllib to bypass Cloudflare TLS fingerprinting - Includes light/dark icon variants matching OpenCode brand colors - Adds test coverage for auth lookup, API parsing, and error handling
There was a problem hiding this comment.
Pull request overview
Adds OpenCode Go subscription usage to the agents panel through a new API collector, provider configuration, documentation, tests, and themed icons.
Changes:
- Collects rolling, weekly, and monthly limits.
- Discovers credentials from environment and harness auth files.
- Enables and documents the provider with light/dark assets.
Tip
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.
Reviewed changes
Copilot reviewed 3 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
bin/omarchy-agent-usage-opencode-go |
Implements credential discovery and usage collection. |
test/shell.d/agent-usage-opencode-go-scanner-test.sh |
Tests collector output and failures. |
shell/plugins/agents/manifest.json |
Enables OpenCode Go by default. |
shell/plugins/agents/README.md |
Documents provider behavior and setup. |
shell/plugins/agents/assets/opencode-go.svg |
Adds the dark-surface icon. |
shell/plugins/agents/assets/opencode-go-light.svg |
Adds the light-surface icon. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Adds native support for OpenCode Go subscriptions in the agents panel. Queries OpenCode's official /zen/go/v1/usage API for rolling (5h), weekly, and monthly limit usage with reset timers. Unique features compared to other PRs (omacom#7157, omacom#8065, omacom#6526, omacom#6779, omacom#6464): - Pi session scanning for local token stats - Harness-agnostic key discovery (Pi, OpenCode CLI, env var) - Account-scoped metadata (scope, hasPromptStats) Key design decisions: - Uses curl instead of urllib to bypass Cloudflare TLS fingerprinting - Includes light/dark icon variants matching OpenCode brand colors - Adds test coverage for auth lookup, API parsing, and error handling
Adds native support for OpenCode Go subscriptions in the agents panel. Queries OpenCode's official /zen/go/v1/usage API for rolling (5h), weekly, and monthly limit usage with reset timers. Features matching codex/claude collectors: - Limits caching with stale-window detection (limit_window_open) - Scan caching with file locking (fcntl.flock) - --force bypasses caches, --limits-only reuses scan cache - Pi session scanning for local token stats - OpenCode DB scanning with providerID LIKE narrowing - Harness-agnostic key discovery (Pi, OpenCode CLI, env var) - Account-scoped metadata (scope='account', hasPromptStats=false) - Manual/17-ai.md documentation Bug fixes from review: - Fix todayTokensByModel not populated from Pi sessions - Gate scan cache on DB scan completeness - Add json_extract guard for providerID in SQL - Move import hashlib to top Test coverage: 16 tests covering API parsing, provider detection, Pi session scanning, todayTokensByModel, and error handling.
|
Tried this collector on a live OpenCode Go subscription (Omarchy 4.0.2-1, agents plugin 1.0.0). The limits half works great — One bug though: local stats are dropped on any day the subscription hasn't been used yet. In local_stats = cached_local_stats(max_age)
if local_stats.get("todayTotalTokens", 0) > 0:
record.update(local_stats)Because the guard keys on today's tokens, a scan that found plenty of history still gets discarded whenever today's total is 0. The panel then renders limit meters above a permanently empty "Tokens by day" and "Tokens by model" — which is the common case first thing in the morning, or for anyone who uses the subscription a few days a week. ReproWith OpenCode Go usage on disk from previous days but none today: The scan itself is fine — the data is found and cached correctly, it just never reaches the record: And the on-disk scan cache holds the right values too: Suggested fixGate on whether the scan produced anything at all rather than on today specifically: if (local_stats.get("todayTotalTokens", 0) > 0
or local_stats.get("totalPrompts", 0) > 0
or local_stats.get("modelUsage")):
record.update(local_stats)That keeps the original intent — don't clobber the record with an empty scan — while letting prior-day history through. Running with this change, the same machine reports Happy to open a PR against your branch if that's easier. |
- Fix local_stats guard: accept prior-day history, not just today's tokens - Fix shebang to #!/usr/bin/python3 (match other collectors) - Add runtime_env/find_command for ripgrep PATH discovery (match codex) - Pass env=ENV to ripgrep subprocess for expanded PATH - Hide API key from /proc/cmdline via curl -H @file pattern - Merge totalSessions/todaySessions alongside other counters - Fix manual JSONL scan fallback when rg is not found - Fix scan_opencode_sessions return type annotation - README: accurately describe local data sources in provider table - Add compact-JSON test, merge logic test, cache test, auth file test
|
@averyrobbins thanks for the thorough review. The guard is now fixed to accept prior-day history. |
|
Automated duplication check: this pull request looks similar to #8065, which covers the same OpenCode usage collector. I keep that one open and close this one to consolidate review. If you feel this is the wrong decision, please open the PR again with a note on the difference. |
Add OpenCode Go collector for agents panel
Summary
Adds native support for OpenCode Go subscriptions in the agents panel. OpenCode Go is a $10/month subscription providing access to popular open coding models, used by Pi, OpenCode CLI, and other harnesses.
Changes
bin/omarchy-agent-usage-opencode-go— New collector that queries OpenCode's official/zen/go/v1/usageAPI for rolling (5h), weekly, and monthly limit usage with reset timersshell/plugins/agents/assets/opencode-go.svg— Dark mode iconshell/plugins/agents/assets/opencode-go-light.svg— Light mode iconshell/plugins/agents/manifest.json— Addopencode-goto default providersshell/plugins/agents/README.md— Document the new collector and its key discovery logicDesign decisions
Harness-agnostic key discovery
The OpenCode Go API key is the same regardless of which harness (Pi, OpenCode CLI, etc.) connects to the subscription. The collector searches multiple auth locations:
OPENCODE_GO_API_KEYenvironment variable~/.pi/agent/auth.json(Pi harness)~/.local/share/opencode/auth.json(OpenCode CLI)Adding a new harness requires only appending to
AUTH_PATHSin the script.curl instead of urllib
Other collectors use
urllib.requestdirectly, butopencode.aiis behind Cloudflare which blocks requests based on TLS fingerprinting (JA3/JA4). Python'ssslmodule produces a fingerprint Cloudflare flags as non-browser traffic, returning 403. Curl has a browser-like fingerprint and passes through. This deviation is documented in the script.No local stats
Unlike Claude/Codex collectors that parse local session files, this collector relies solely on the server-side API. OpenCode's local database doesn't reliably represent server-side accounting, especially when using multiple machines. The API provides accurate, real-time limits.
Testing
Verified working on a live OpenCode Go subscription:
omarchy-shell omarchy.agents refreshRelated