Skip to content

feat(opencode): add OpenCode Go quota tracking provider#109

Open
hiyukoim wants to merge 3 commits into
onllm-dev:mainfrom
hiyukoim:feat/opencode-provider-v2
Open

feat(opencode): add OpenCode Go quota tracking provider#109
hiyukoim wants to merge 3 commits into
onllm-dev:mainfrom
hiyukoim:feat/opencode-provider-v2

Conversation

@hiyukoim

Copy link
Copy Markdown

Summary

Replaces closed #102 since it got messy. Rebuilds OpenCode Go as a quota provider on current upstream/main (keeps Kimi / Moonshot / DeepSeek), following the existing provider pattern from CONTRIBUTING.md. Related: #100.

  • Agent + tracker + SQLite store for OpenCode Go snapshots (5-hour / weekly / monthly)
  • Dashboard tab, charts, deep insights, menubar card, settings UI
  • Config via OPENCODE_GO_WORKSPACE_ID + OPENCODE_GO_AUTH_COOKIE (see docs/OPENCODE_SETUP.md)
  • OPENCODE_ENABLED remains the separate Codex-via-OpenCode-auth path
  • Frontend contract: quota JSON uses limit (not limitValue); empty-state re-render guarded; dedicated history routing

Why a new PR

#102 was closed after an unrelated-histories merge onto the harden branch corrupted history / app.js. This branch starts clean from upstream/main and ports OpenCode-only changes.

Provider checklist

Per CONTRIBUTING "Adding a New Provider":

  1. internal/api/opencode*.go
  2. internal/store/opencode_store.go (+ schema in store.go)
  3. internal/tracker/opencode_tracker.go
  4. internal/agent/opencode_agent.go
  5. Endpoints in internal/web/handlers.go / opencode_handlers.go
  6. Dashboard tab + charts in internal/web/static/app.js

Test plan

  • Focused short tests: api, web, agent, store, tracker, config
  • go vet ./...
  • CI green on this PR
  • With OPENCODE_GO_WORKSPACE_ID + OPENCODE_GO_AUTH_COOKIE set: OpenCode tab appears, quotas poll, charts update
  • Without OpenCode env: other providers unchanged, no OpenCode tab noise
./app.sh --smoke
# optional full suite:
./app.sh --test

hiyukoim and others added 3 commits July 24, 2026 12:29
Rebuild PR work cleanly from upstream (keeps kimi/moonshot/deepseek).
Hardened scrape client, tracker wiring, typed errors, dashboard/UI,
limit-field contract test, and empty-state/history frontend fixes.

Co-authored-by: Cursor <cursoragent@cursor.com>
Prevent DetectCodexCredentials from reading the host OpenCode
auth.json when CODEX_HOME auth is empty.

Co-authored-by: Cursor <cursoragent@cursor.com>
Pin OPENCODE_HOME to a temp dir in tests so host auth.json
cannot leak on macOS. Add menubar/tab/historyBoth/settings
and document OPENCODE_GO_* in .env.example.
@prakersh

Copy link
Copy Markdown
Contributor

Thanks for the clean rebuild - this follows the provider pattern well and the limit-key regression test from #102 is appreciated. CI is green. A few things before merge:

  1. Auth vs parse errors: the client follows redirects, so an expired cookie likely hits a 302→login page→200 and surfaces as ErrOpenCodeParseFailed instead of ErrOpenCodeUnauthorized. Setting CheckRedirect to http.ErrUseLastResponse and mapping 3xx to unauthorized would fix this (also keeps the cookie out of redirect chains).
  2. False cycle resets in fallback mode: the data-slot parser has hour granularity, so recomputed ResetsAt can jump ~59 min between polls - past the 10-min threshold in the tracker, spuriously closing weekly/monthly cycles. Suggest a wider threshold (~90 min) or requiring a utilization drop.
  3. TestOpenCodeAgent_Poll_FetchErrorNoInsert hits the real opencode.ai - please use the stub client or an httptest server; tests here must be hermetic.
  4. Cookie heuristic: Contains(cookie, "=") misfires if the raw value contains = (base64 padding). Prefer an auth= prefix check.
  5. Late-appearing quotas never render: cards render once, then update by ID - if monthly shows up after the first render, it gets no card until reload. Re-render when the incoming quota set differs from the rendered cards.

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.

2 participants