Skip to content

feat(tui): open /context or /cost from the sidebar token-usage reading#3813

Open
aheritier wants to merge 4 commits into
feat/context-compaction-limit-visibilityfrom
usage-click-split-context-cost
Open

feat(tui): open /context or /cost from the sidebar token-usage reading#3813
aheritier wants to merge 4 commits into
feat/context-compaction-limit-visibilityfrom
usage-click-split-context-cost

Conversation

@aheritier

Copy link
Copy Markdown
Contributor

What & why

Clicking the sidebar Token Usage reading used to open the /cost dialog no matter where you clicked. This splits the click by segment so each part opens the dialog it describes:

  • Token count · (NN%) · (compacting…)/context dialog
  • $… · ⚠ capped · sub-session count/cost dialog
  • The "Token Usage" title is no longer clickable
  • Budget lines keep opening /cost

Works in both the vertical sidebar and the collapsed top band.

How

  • New ClickUsageContext click result routed to a new TargetSidebarUsageContext, split from the existing cost path by the rendered X-width of the context segment (usageContextSegWidth, measured with lipgloss.Width so it's ANSI/terminal-cell aware).
  • The usage click zone is narrowed to the reading line (the title line is excluded); the collapsed band splits by flat offset, handling both the right-aligned shared-line and the wrapped own-line cases.

Commits

  1. feat(tui): make sidebar usage title non-clickable and track context-segment width
  2. feat(tui): add ClickUsageContext and segment-aware usage click detection
  3. feat(tui): route sidebar context clicks to the context dialog
  4. docs(tui): document the context/cost click split

Stacked on #3811

Depends on feat/context-compaction-limit-visibility (#3811) for the ⚠ capped / agentCompactionModel rendering the segment split keys off. This PR targets that branch and will retarget to main once #3811 merges.

Validation

  • go build ./... — clean
  • go test ./pkg/tui/components/sidebar/... ./pkg/tui/page/chat/... — green
  • task lint — 0 issues

Note

The onboarding tour's cost step (matches ShowCostDialogMsg) no longer completes via a context-segment click — behavior-neutral for cost-segment clicks.

Plan: usage-click-split-context-cost

…egment width

The Token Usage section's click zone used to span the whole tab,
including the "Token Usage" title line, so clicking the title opened
the cost dialog just like clicking the reading below it.

Replace the half-open usageZoneStart/usageZoneEnd range with
usageReadingLine (the exact reading-line index) and usageSectionEnd
(covering any budget lines below it), excluding the title line from
the click zone. Also record usageContextSegWidth, the rendered width
of the reading line's context segment (glyph, token count, and context
%/compacting marker) — unused for now, but needed by the next commit
to split the reading line's click target between the context and cost
dialogs.
Split the Token Usage reading line's click target: an offset within
usageContextSegWidth (the glyph, token count, and context %/compacting
marker) now reports the new ClickUsageContext, while the rest of the
line (cost figure, ⚠ capped marker, sub-session count) keeps
reporting ClickUsage. Budget lines below the reading stay ClickUsage.

Apply the same offset split in both the vertical branch and the
collapsed band's shared-line/own-line branches of HandleClickType.
Add TargetSidebarUsageContext to the hit-test enum, map
sidebar.ClickUsageContext to it, and open ShowContextDialogMsg on a
left click, mirroring the existing ClickUsage -> ShowCostDialogMsg
routing for the cost segment.
Update the sidebar usage-click description in the TUI feature doc and
add a changelog entry for the new /context click target.
@aheritier
aheritier requested a review from a team as a code owner July 23, 2026 21:57
@aheritier aheritier added area/docs Documentation changes area/tui For features/issues/fixes related to the TUI kind/feat PR adds a new feature (maps to feat:). Use on PRs only. labels Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/docs Documentation changes area/tui For features/issues/fixes related to the TUI kind/feat PR adds a new feature (maps to feat:). Use on PRs only.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant