feat(opencode): show quota usage toast after quota refresh#36
Open
iceteaSA wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
3 issues found across 6 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/opencode/src/index.ts">
<violation number="1" location="packages/opencode/src/index.ts:428">
P2: Fallback quota command output drops fresh per-account refresh errors by always passing an empty error map.</violation>
</file>
<file name="packages/core/src/quota-manager.ts">
<violation number="1" location="packages/core/src/quota-manager.ts:88">
P2: Persisted main quota cache uses interval-only staleness instead of policy-aware `getQuotaNextRefreshAt`, causing premature refreshes.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
4ad7d49 to
b20b6c0
Compare
2ec54d4 to
95a1614
Compare
Displays quota usage bar notifications via client.tui.showToast after quota data is refreshed. Shows main and fallback account usage with visual bars, percentage, and reset time. Toast variant reflects severity (info < 70%, warning >= 70%, error >= 90%).
95a1614 to
58f05a8
Compare
58f05a8 to
f4bee10
Compare
Align the quota refresh toast with the sidebar's visual language: - Replace the emoji status dots with status words (active/idle) - Use the shared bar width and a padded percentage via a quotaLine helper - Rename the seven-day label from 1w to 7d to match the sidebar - Keep severity-driven variant color (info/warning/error)
f4bee10 to
617634b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Displays quota-usage bar notifications via
client.tui.showToastafter quota data is refreshed.█░).formatResetInhandles sub-1-minute (<1m), "now", and invalid-date inputs.RangeErroron >100% utilization..then()of each periodic background refresh; never blocks the request.Single file change:
packages/opencode/src/index.ts.Summary by cubic
Shows a quota usage toast after quota refresh, matching the TUI sidebar. Uses the shared
QuotaManagerfrom@cortexkit/anthropic-auth-coreto keep requests non‑blocking and display a toast when refresh completes, including background every‑N refreshes.client.tui.showToast: shows main and enabled fallbacks with shared-width█░bars, padded percent, 5h/7d lines, reset-in time (<1m/now supported), active/idle labels; clamps >100%; info/warning/error variants.refreshMaincompletes and after periodic background refreshes; no request blocking.QuotaManagercache for main and fallback snapshots; picks the active account that passes policy (mirrors routing).Written for commit 617634b. Summary will update on new commits.
Greptile Summary
This PR wires quota usage toast notifications into the OpenCode plugin after each
QuotaManagermain-quota refresh. It adds four helper functions (quotaBar,quotaLine,formatResetIn,showQuotaToast) and an innershowQuotaToastFromCachethat reads the shared QuotaManager cache to build per-account bars, labels the active route, and firesclient.tui.showToastwith an info/warning/error variant.quotaBarclamps>100 %correctly andformatResetInnow returns\"resets <1m\"for sub-minute windows.showQuotaToastFromCacheis called both on the inline (blocking) refresh path and in the.then()callback of the background every-N refresh, keeping it non-blocking on the critical request path.variantis determined byglobalMaxUsedacross all displayed accounts; an idle fallback near exhaustion can drive theerrorvariant even when the active account has plenty of quota, which may mislead users.Confidence Score: 5/5
Safe to merge — the change is display-only (toast notifications) and does not touch routing logic, token handling, or quota policy decisions.
The toast helpers are all pure display functions that are fire-and-forget; any exception in the showToast call is silently swallowed by .catch(() => {}). The showQuotaToastFromCache function is correctly scoped and uses the same QuotaManager cache that drives the sidebar. None of the new code affects routing, token refresh, or quota enforcement paths.
packages/opencode/src/index.ts — specifically the variant-selection logic in showQuotaToast and the reset-time display in the account header lines.
Important Files Changed
Sequence Diagram
sequenceDiagram participant FH as Fetch Handler participant QM as QuotaManager participant TC as showQuotaToastFromCache participant TUI as client.tui.showToast FH->>QM: getMain(auth.access) alt cache miss (!routingQuota) FH->>QM: await refreshMain(auth.access) QM-->>FH: OAuthQuotaSnapshot FH->>TC: showQuotaToastFromCache() [sync] TC->>QM: getMain() [no token, display] TC->>QM: getFallback(id, access) per account TC->>TUI: "void showToast({ variant, message })" else needsRefresh (every-N or stale) FH->>QM: void refreshMain(auth.access) Note over FH: Non-blocking QM-->>FH: .then() resolves FH->>FH: writeSidebarState(...) FH->>TC: showQuotaToastFromCache() [in .then] TC->>QM: getMain() [no token, display] TC->>TUI: "void showToast({ variant, message })" endReviews (3): Last reviewed commit: "feat(opencode): restyle quota toast to m..." | Re-trigger Greptile