Skip to content

Add OpenCode Go usage collector with rate limits to the agents plugin - #7082

Closed
tharinfernando wants to merge 4 commits into
omacom:quattrofrom
tharinfernando:feat/agents-opencode-go
Closed

tharinfernando wants to merge 4 commits into
omacom:quattrofrom
tharinfernando:feat/agents-opencode-go

Conversation

@tharinfernando

Copy link
Copy Markdown

Adds OpenCode Go (opencode-go) as a fourth subscription in the Agents panel,
alongside Claude Code, Codex, and Fireworks. The agents panel is display-only
and discovers any record in ~/.local/state/omarchy/agents/usage/, so this is
a new collector plus its mark, docs, and tests — no plugin changes needed.

Changes

  • bin/omarchy-agent-usage-opencode — new collector that:
    • Reads local token stats from opencode's own database
      (~/.local/share/opencode/opencode.db), filtered to messages that ran on
      the opencode-go provider (same schema handling, scan cache, and
      --force / --limits-only flags as the other collectors).
    • Fetches rate limits from the OpenCode Go usage endpoint
      (https://opencode.ai/zen/go/v1/usage) using the opencode-go API key from
      opencode's auth store — the rolling 5-hour, weekly, and monthly dollar
      windows render as the panel's LIMITS meters.
    • Degrades gracefully when the endpoint is unreachable or no key is set:
      empty limits + a status note, with local token usage still shown.
  • shell/plugins/agents/assets/opencode-go.svg — opencode mark for the tab.
  • shell/plugins/agents/manifest.json — enables opencode-go by default.
  • shell/plugins/agents/README.md — documents the collector and its limits.
  • test/shell.d/agent-usage-opencode-scanner-test.sh — 10 assertions:
    provider filtering, token/model aggregation, session counting, limit window
    mapping (endpoint mocked via OPENCODE_GO_USAGE_URL), and the offline
    fallback. Existing agent usage/panel tests still pass.

Notes

  • OpenCode Go is a subscription, not prepaid credits, so it reports rate
    limits but has no balance — no balance field.
  • OPENCODE_GO_USAGE_URL is honored so the limits probe can be pointed at a
    mock endpoint in tests.

Copilot AI balanced review requested due to automatic review settings August 16, 2026 07:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds OpenCode Go support to the agents usage panel by introducing a new local collector, wiring it into the plugin config/docs, and validating behavior via a dedicated shell test.

Changes:

  • Add omarchy-agent-usage-opencode collector to emit OpenCode Go usage + limits as a panel-ready JSON record.
  • Enable opencode-go in the agents plugin manifest and document the new provider.
  • Add an end-to-end shell test and a new SVG asset for the provider.

Reviewed changes

Copilot reviewed 3 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
test/shell.d/agent-usage-opencode-scanner-test.sh New shell test validating OpenCode Go scanning, limits mapping, offline behavior, and caching behavior.
shell/plugins/agents/manifest.json Adds opencode-go provider toggle and updates plugin description to include OpenCode Go.
shell/plugins/agents/assets/opencode-go.svg Adds the OpenCode Go icon asset.
shell/plugins/agents/README.md Documents the opencode-go provider and clarifies where stats/limits come from.
bin/omarchy-agent-usage-opencode New Python collector that scans opencode DB for local stats and fetches limits from OpenCode Go usage endpoint.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +8 to +9
TEST_HOME=$(mktemp -d)
trap 'rm -rf "$TEST_HOME"' EXIT
Comment on lines +89 to +90
OFFLINE_HOME=$(mktemp -d)
trap 'rm -rf "$TEST_HOME" "$OFFLINE_HOME"' EXIT
Comment on lines +103 to +104
FRESH_HOME=$(mktemp -d)
trap 'rm -rf "$TEST_HOME" "$FRESH_HOME"' EXIT
Comment on lines +153 to +154
every transcript still on disk, and OpenCode Go's cover every opencode
message still in the database.
Copilot AI review requested due to automatic review settings August 19, 2026 19:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 9 changed files in this pull request and generated no new comments.

Suppressed comments (4)

test/shell.d/agent-usage-opencode-scanner-test.sh:104

  • This final trap replaces the preceding cleanup and drops OFFLINE_HOME, so every successful test run leaks that temporary directory.
trap 'rm -rf "$TEST_HOME" "$FRESH_HOME"' EXIT

test/shell.d/agent-usage-opencode-scanner-test.sh:91

  • This “unreachable endpoint” case has no auth store, so auth_key() returns early and the file:///nonexistent URL is never opened. Seed OFFLINE_HOME with the test key before invoking the collector so the endpoint-failure path is actually covered.
mkdir -p "$OFFLINE_HOME/bin"

offline=$(HOME="$OFFLINE_HOME" XDG_DATA_HOME="$OFFLINE_HOME/.local/share" \
  OPENCODE_GO_USAGE_URL="file:///nonexistent" \
  "$ROOT/bin/omarchy-agent-usage-opencode" --force)

shell/plugins/agents/README.md:68

  • The local database scan does not require an API key; only the usage endpoint does. Saying both require the key contradicts the collector's offline/no-key behavior and may lead users to think local token stats are unavailable without authentication.
signed in there. OpenCode Go reads opencode's own database (honoring
`XDG_DATA_HOME`) and its usage endpoint (honoring `OPENCODE_GO_USAGE_URL`
for tests); both need the opencode-go key in the same auth store.

shell/plugins/agents/Agent.qml:23

  • FileView.atomicWrites controls how writes performed by that FileView are committed; it does not make a read-only watcher follow an inode replaced by the updater's mv. Since updateProcess.onExited only rescans filenames and preserves existing Agent objects, a refresh can still leave their records stale until the panel is reopened. Explicitly reload existing records after the updater exits (and adjust this assertion/comment) rather than relying on this property.
    // The update command rebuilds each record with an atomic rename, which
    // swaps out the watched inode. Watch for those replacements so the panel
    // picks up new numbers without being told to reload.
    atomicWrites: true

@bjarneo

bjarneo commented Sep 20, 2026

Copy link
Copy Markdown
Member

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.

@bjarneo bjarneo closed this Sep 20, 2026
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.

3 participants