Repository navigation
Name the OpenCode plan only when one is known - #1
dadofsambonzuki wants to merge 1 commit into
Conversation
The Go gateway reports percents and reset times, not the plan they belong to: `/zen/go/v1/usage` names no plan, and neither does any endpoint an API key authenticates against, so `tierLabel` asserted the $10 Go plan for what may be a Go Plus account. Use a plan the payload reports as it stands — that is what lets a future tier appear without this collector changing — and otherwise leave the label blank, which the panel renders as "Subscription". A user whose plan the endpoint still hides can declare it in `~/.config/omarchy/agents/opencode.json`, the override file the Fireworks collector already uses for its account.
|
A design note that is worth recording here, since it is the same thread as the plan-label change. The collector currently has to reconstruct per-model usage from client stores (opencode's own database, pi/omp transcripts, and other harnesses that spent the same subscription). That is a workaround: those stores are per-machine and per-client, so they miss usage from other machines and from harnesses whose database you do not know about, and the account-level percentages in There are open feature requests for the endpoint that would replace all of it — If such an endpoint appears, this collector should prefer it and treat the local scans as a fallback for the cases where it is unavailable (no key, no entitlement, no network): one authoritative source, no per-client scans to keep in sync, and no double counting when two stores hold the same session. I have raised the requirement on #43983 with the panel's needs; no change needed here today, just worth agreeing on the direction before more local scanners get written. |
|
Thank you, Nathan. The plan-label idea is sound: do not name a plan the endpoint never reports, and let a user declare their own. This PR can not go in as it is, though. It targets Closing this one. If the Go Plus label still shows wrong on |
|
Re-cut on It targets the rewritten collector from omacom#14040 — nothing from this branch is carried over, since the functions it changed no longer exist — and keeps the same three-part idea: read the plan from the answer if it ever reports one, take a declaration in The endpoint is unchanged as of today: Thanks for the pointer to anomalyco/opencode#43983 — usage history is a separate gap and I have not touched it here. |
Follow-up to omacom#13548, on the same file. This branch is based on yours, so it can be merged into it or cherry-picked as-is.
The mechanism
GET https://opencode.ai/zen/go/v1/usageanswers with percents and reset times and nothing else:{"usage":{"rolling":{"status":"ok","percent":19,"resetsAt":"2026-09-30T11:20:47.701Z"}, "weekly":{"status":"ok","percent":22,"resetsAt":"2026-10-05T00:00:00.000Z"}, "monthly":{"status":"ok","percent":27,"resetsAt":"2026-10-21T07:45:46.000Z"}}}No plan field, and nothing else an API key authenticates against names one:
/zen/go/v1/{subscription,plan,account,me,limits,credits,balance},/zen/v1/usage|credits|balanceand/inference/go/v1/{subscription,account,plan,limits}all answer 404, and the console that does know the subscription is session-gated. SotierLabel = "Go"is an assertion rather than a reading — right for the $10 plan, wrong for a Go Plus ($40) subscriber, whose panel would name a plan they do not have.The change
plan_from_payload()reads the plan out of the payload when the endpoint reports one —plan,planType,plan_type,planName,plan_name,tier,planId,plan_id, at the top level or underusage/subscription/account. A tier the endpoint starts naming therefore appears in the panel with no change here, which is the part that matters for tiers that do not exist yet.plan_label()resolves the label: the user's own declaration in~/.config/omarchy/agents/opencode.json({"plan": "Go Plus"}— the same override file the Fireworks collector reads its funding from) → the payload's plan → blank.test/shell.d/agent-usage-opencode-limits-test.shnow sandboxesXDG_CONFIG_HOME, so no case can read the operator's own override file and pass by accident.The caveat
With neither source the label is blank and the panel renders that as "Subscription" (
Panel.qml'sheroMeta()falls back to it whentierLabelis empty). That is the honest reading of a percents-only payload, but it is a visible change for existing Go users — if a tier should always show, the source for it is the Console session, not this endpoint, and I am happy to wire that up instead.Tests
New cases in
test/shell.d/agent-usage-opencode-limits-test.sh:One existing assertion changes: the first case pinned
tierLabel == "Go"for a payload whose plan is unknown.How much each source changes the record (the same driver run against your head and this branch,
urllibstubbed, no fixtures for the numbers):"Go""Go Plus""Go""Go Plus""Go"""What I ran
bash test/shell.d/agent-usage-opencode-limits-test.sh→ 17 ok, exit 0bash test/shell.d/agent-usage-opencode-scanner-test.sh→ 5 ok, exit 0./test/shell→ 288 scripts run, 13 failing; all 13 are environment-dependent (anomarchy-pkgscheckout,omasnap, the machine's own Hermes install, a browser launcher) and each reproduces with byte-identical ok/not-ok counts on the unpatched head, so none is this change.hermes-cli-test.sh, for example: 6 ok / 1 not ok on both.~/.local/share/opencode, 732 prompts over 18 sessions): the record is identical apart from the label — limitsRolling (5h) 22%,Weekly (7-day) 23%,Monthly 28%,totalPrompts 732,totalSessions 18,activeDays 8.