Skip to content

feat: add OpenCode Zen Go official usage quota provider - #1

Open
abduznik wants to merge 2 commits into
aschwehm:mainfrom
abduznik:feat/opencode-zen-go-usage
Open

feat: add OpenCode Zen Go official usage quota provider#1
abduznik wants to merge 2 commits into
aschwehm:mainfrom
abduznik:feat/opencode-zen-go-usage

Conversation

@abduznik

Copy link
Copy Markdown

What

Adds an OpenCode Zen Go quota panel to the usage tab — the official cloud usage feed (GET https://opencode.ai/zen/go/v1/usage, same data as the web panel) showing rolling (5-hour), weekly and monthly utilisation percentages with their reset times, alongside the existing Claude/Codex limits cards.

This covers OpenCode usage that isn't visible in local logs — the OpenCode provider already tracks the local opencode.db, but token burns through Zen Go API providers (e.g. Hermes Agent pointed at opencode.ai/zen/go/v1) are only visible on the cloud-side quota feed.

How it works

  • New providers::opencode_go module:
    • fetch_zen_go_usage(key) — one ureq GET, Authorization: Bearer, browser User-Agent (the endpoint 403s the default ureq UA), 5 s timeout, 60 s result cache (same cadence as claude_limits).
    • resolve_api_key()OPENCODE_GO_API_KEY env var first, falling back to ${HERMES_HOME}/.env (the Hermes portable convention) so the quota lights up automatically under that setup without any extra config.
    • Pure parse_zen_go_usage(Value) parser with unit tests against the real response shape (usage.rolling/weekly/monthly with status/percent/resetsAt).
  • app.rsStateInner and UsageView carry ZenGoUsage; refresh() fetches it lock-free alongside the Claude limits; missing key → None → panel hidden.
  • +page.svelteZenGoLimits types and a quota card mirroring the Claude limits card (labels, percent, track fill). Rendered only when at least one bucket is present.
  • README + version bump 0.4.1 → 0.4.2.

Testing

  • 351 tests pass, 0 fail.
  • Includes a live-fetch test that runs against the real endpoint when a key is configured and self-skips otherwise (safe for CI): providers::opencode_go::tests::test_live_fetch_zen_go_usage — verified green against the live API.
  • npm run check (svelte-check / tsc): 0 errors.

Notes

  • Only /usage exists on the Zen Go API — no raw token counts or other endpoints, so the quota is percent + reset time, matching the web panel.
  • Which is exactly why it's a limits-style card, not a tokens row.

Fetches the official OpenCode Zen Go usage API (GET opencode.ai/zen/go/v1/usage)
and shows rolling (5-hour), weekly and monthly utilisation with reset times in
a quota panel on the usage tab.

- New providers::opencode_go module: URL const, browser UA (the API 403s the
  default ureq UA), 60s result cache, key resolution (OPENCODE_GO_API_KEY env
  var, falling back to ${HERMES_HOME}/.env for Hermes portable), pure JSON
  parser.
- app.rs: StateInner and UsageView carry the ZenGoUsage; refresh() fetches it
  in the background alongside the Claude limits, lock-free.
- +page.svelte: ZenGoLimits types + quota panel mirroring the Claude limits
  card (utilization bars and reset times).
- README: document the quota panel and key sources.
- Version bump 0.4.1 -> 0.4.2 (package.json, package-lock, Cargo.toml,
  tauri.conf.json, Cargo.lock).

351 tests pass, including a live fetch against the real endpoint (skips when
no key is configured).
The only audit finding is cookie <0.7.0 (3 low), pulled transitively by
@sveltejs/kit@2.70.2. npm audit fix --force would downgrade to a breaking
pre-release (@sveltejs/kit@0.0.30), so pin via overrides instead:
cookie 0.6.0 -> 0.7.2. npm audit now reports 0 vulnerabilities.

Verified: npm run check (0 errors), npm run build, cargo test (351 passed).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant