feat(opencode): collapsible TUI sidebar#58
Merged
Conversation
…nged The callback fires on any persisted fallback storage change (token refresh, quota update, or error recording), not only quota fetches. Rename per review feedback for an accurate API name.
There was a problem hiding this comment.
No issues found across 8 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Architecture diagram
sequenceDiagram
participant TUI as OpenCode TUI
participant Plugin as AnthropicAuthPlugin
participant FAM as FallbackAccountManager
participant QM as QuotaManager
participant Storage as Account Storage
participant Fetch as External APIs
Note over TUI,Fetch: NEW: Collapsible Sidebar + Active Account Fix
TUI->>TUI: onMouseDown on header
alt Has Data
TUI->>TUI: toggle collapsed() signal
end
TUI->>TUI: resolveActiveAccount(state)
Note over TUI: NEW: Pure helper from sidebar-state.ts
TUI->>TUI: Check activeId
alt activeId === 'main' or unmatched/disabled
TUI->>TUI: Return main account
else activeId matches enabled fallback
TUI->>TUI: Return fallback account
end
TUI->>TUI: Render collapsed view
Note over TUI: NEW: Show active account name + 5h % ● or em dash
Plugin->>FAM: new FallbackAccountManager({onFallbackQuotaFetched})
Note over Plugin: NEW: register callback for background quota updates
FAM->>FAM: refreshQuotaForDueAccounts()
FAM->>Storage: Save changed quotas
FAM-->>Plugin: onFallbackQuotaFetched()
Plugin->>Plugin: refreshSidebarQuota()
Note over Plugin: NEW: Re-write sidebar with last known routing
Plugin->>Storage: loadAccounts()
Plugin->>Storage: writeSidebarState(lastSidebarRouting)
Plugin-->>TUI: Updated sidebar state
Plugin->>Plugin: writeSidebarState()
Plugin->>Plugin: Store lastSidebarRouting
Note over Plugin: NEW: Remember last activeId/route
Plugin->>QM: refreshMain(access)
QM->>Fetch: GET /api/oauth/usage
Fetch-->>QM: Quota data
QM-->>Plugin: .then()
Plugin->>Plugin: refreshSidebarQuota()
Note over Plugin: CHANGED: Uses last routing instead of resetting to 'main'
Plugin-->>TUI: Sidebar updated without clobbering active account
alt Collapsed && Has Data
TUI->>TUI: Show active account + 5h quota
alt Fast Mode On
TUI->>TUI: Show "Mode fast" row
end
else !Collapsed || !Has Data
TUI->>TUI: Show expanded full sidebar
TUI->>TUI: Show quota sections, routing, cache, health
end
Note over TUI: CHANGED: Header shows ▼/▶ + version or LIMITED badge
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.
Summary
Adds a click-to-collapse toggle to the OpenCode quota sidebar, mirroring cortexkit's
aftplugin.onMouseDownon the header toggles it (resets to expanded on restart).▼/▶ CLAUDEglyph + plugin version (or theLIMITEDbadge when degraded).% ●(usage-toned), plus aMode fastrow when fast mode is on. Em dash when no 5h window.!collapsed() || !hasData()so it never goes blank.resolveActiveAccountpure helper (unit-tested) resolves the active account fromactiveId.Changes
packages/opencode/src/sidebar-state.ts—resolveActiveAccounthelper.packages/opencode/src/tui.tsx— collapse signal, header (glyph + version), collapsed render.README.md— sidebar docs.Tests
resolveActiveAccount. Full suite green (typecheck + test + build).Dependency
Stacked on #57 (stale fallback quota / clobbered active account). The collapsed view shows the active account, which relies on the BUG 2
activeIdfix in #57. Merge #57 first — until then this PR's diff includes #57's commits.Need help on this PR? Tag
/codesmithwith what you need. Autofix is disabled.Summary by cubic
Adds a click-to-collapse toggle to the OpenCode quota sidebar with a compact view and versioned header. Preserves the active fallback during async quota refreshes and live-updates after background fallback storage changes.
New Features
CLAUDEheader to collapse/expand; shows▼/▶andv{version}(read frompackage.json) orLIMITEDwhen degraded.Mode fastrow when enabled. Collapse state is per session.resolveActiveAccountselects the active account for the collapsed view (with a defensive enabled guard).Bug Fixes
refreshSidebarQuota.onFallbackStorageChanged, without a request.Written for commit 5959f45. Summary will update on new commits.
Greptile Summary
This PR adds a click-to-collapse toggle to the OpenCode quota sidebar and fixes a bug where async background quota refreshes would clobber the active fallback account in the sidebar state. The collapse state is session-local, the header gains a
▼/▶glyph plus plugin version (orLIMITEDbadge when degraded), and the collapsed view shows the active account's 5h usage.tui.tsx): AcollapsedSolid signal toggles ononMouseDownonly whenhasData()is true; collapsed and expanded views are gated with complementaryShowpredicates so the sidebar never goes blank when data clears while collapsed.index.ts):lastSidebarRoutingcaptures the last explicit routing decision;refreshSidebarQuota()replays it during async quota refreshes instead of unconditionally resettingactiveIdto'main'.resolveActiveAccount(sidebar-state.ts): New pure helper with 6 unit tests mappingactiveId→{id, name, quota}for the collapsed view;onFallbackStorageChangedcallback inaccounts.tstriggers a sidebar re-render after background storage saves.Confidence Score: 5/5
Safe to merge — changes are confined to TUI rendering and sidebar state plumbing, with no load-bearing auth or quota logic altered.
All new code paths are guarded (null checks on latestGetAuth, hasData() gate on collapse toggle, defensive enabled check in resolveActiveAccount), the clobber fix is straightforward and well-tested with a timing-sensitive integration test, and the reactive patterns in tui.tsx are idiomatic Solid.js. No data-loss or auth boundary concerns introduced.
No files require special attention.
Important Files Changed
Reviews (2): Last reviewed commit: "docs(opencode): clarify version path lay..." | Re-trigger Greptile