feat(tui): collapsible sidebar with compact usage overview#93
Open
Zireael wants to merge 2 commits into
Open
Conversation
Add toggle collapse for the Magic Context sidebar panel, persisted via KV store so the state survives session restarts and window reloads. Collapsed view shows a compact three-line summary: - Usage header: toggle indicator + percentage/token counts - Color-coded bar with inline token-count labels on segments ≥3 chars wide - Historian status line (running/idle + compartment/fact counts) The compact bar includes a dim "Free" segment proportional to remaining context capacity, with adaptive labels: "64K Free" when wide enough, "64K" at minimum width, or dim fill when too narrow. Expanded view is unchanged — full sidebar with legend, historian, memory, status, and dreamer sections. Utilities moved to sidebar-utils.ts with full test coverage (20 tests).
ace52c3 to
c4e9af8
Compare
…o collapsed sidebar
Adds three user-configurable settings under tui.compact_bar in
magic-context.jsonc to control collapsed sidebar bar segment labels:
- label_threshold (0.10): min share to show short token-count label
- free_label_threshold (0.25): min share to show full "XXK Free" label
- show_free_label (true): toggle the "Free" suffix on the free segment
Layout:
sidebar-utils.ts — CompactBarOptions interface + DEFAULT_COMPACT_BAR_OPTIONS
sidebar-content.tsx — reads magic-context.jsonc via shared utilities,
threads compactBarOptions → SidebarContent → TokenBreakdown, replaces
hardcoded 0.08/0.12 thresholds with config-driven barOpts()
magic-context.schema.json — tui.* schema sections with defaults
Also adds the missing showFreeShort render tier so the free-segment number
label appears between label_threshold and free_label_threshold, and applies
overflow="hidden" to all label segments to prevent text bleed.
Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
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
The Magic Context sidebar in OpenCode's TUI can now be collapsed into a compact 3-line view by clicking the header. This frees up sidebar space while keeping the most essential context information visible at a glance.
Suggestion 1 (I didn't implement this, but it could be a good idea): consider sorting the context categories by their size in context window. Currently the categories are displayed in static order (System ->Compartments ->Memories -> Conversation ->Tool Calls ->Tool Defs), which is also okay when you don't want to see categories jumping up and down because of re-sorting. But having an option to see a list of 'heaviest' categories taking space in context window would be preferable to some people.
Suggestion 2: Is there a separate category for 'Skills Defs', or are they bundled together with 'Tool Defs'? Skill definitions can bloat the context window as much as tool/MCP definitions, when you have too many packed in the .agents/ folders.
What changed
api.kv, so it survives session restarts and window reloads.flexGrow-based segments, filling the full sidebar width. Includes a "Free" segment (dim gray░) for unused context, with token-count labels overlaid on wide-enough segments.<box marginTop={1}>wrapper that created a blank line between the collapsed header and the status bar is removed.Under the hood, the bar rendering changed from fixed-character fill (
"█".repeat(w)) toflexGrow-proportional segment boxes withbackgroundColor, so the bar naturally stretches to the full row width regardless of the sidebar's rendered size.Summary by cubic
Make the Magic Context sidebar collapsible with a compact 3‑line overview that frees space while keeping usage visible. Compact bar labels are now configurable via
tui.compact_barinmagic-context.jsonc; collapse state persists across restarts.New Features
tui.compact_bar(label_threshold,free_label_threshold,show_free_label).tui.sidebar.collapse_defaultandtui.compact_bardefaults to the schema; manual toggles still persist via KV and override defaults.Refactors
sidebar-utils.ts(compactTokens,collapsedStatusLine,collapsedUsageLine) with tests insidebar-utils.test.ts; reads config and threads options into the compact bar.Written for commit af386db. Summary will update on new commits. Review in cubic