feat(tui): collapsible sidebar with compact usage overview#93
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 <[email protected]>
|
This is very good idea, was thinking something similar but couldn't decide which information to keep in condensed mode. Will look into your PR and test it out. |
Thanks! Fun fact, it is possible to display borders around boxes, but no one seems to fence off their plugin's real estate area 🤔 Tip 1: I think I have seen a way to make it so that people don't have to put your plugin two times in "exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js"
},
"./tui": {
"types": "./src/tui/index.tsx",
"import": "./src/tui/index.tsx"
}
},
"oc-plugin": [
"server",
"tui"
],Tip 2: I had an idea a while back but haven't tested it yet. Since you can click on TUI sidebar to collapse/expand a section, why not put there some buttons to execute actions done normally by slash commands? Or toggling some features on/off. |
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