Skip to content

feat(sessions): context breakdown popover#2353

Draft
k11kirky wants to merge 1 commit into
posthog-code/context-breakdown-datafrom
posthog-code/context-breakdown-popover
Draft

feat(sessions): context breakdown popover#2353
k11kirky wants to merge 1 commit into
posthog-code/context-breakdown-datafrom
posthog-code/context-breakdown-popover

Conversation

@k11kirky
Copy link
Copy Markdown
Contributor

@k11kirky k11kirky commented May 25, 2026

Problem

The context usage indicator previously showed only a tooltip with raw token counts. Users had no way to see how their context window was being consumed across different categories (system prompt, tools, rules, skills, MCP, subagents, conversation).

Changes

  • Replaced the tooltip on ContextUsageIndicator with a Radix Popover that opens a ContextBreakdownPopover panel when clicked.
  • ContextBreakdownPopover displays the aggregate token count, percentage full, a visual progress bar, and a per-category breakdown with color-coded segments when breakdown data is available. Before the first response, a placeholder message is shown instead.
  • The progress bar renders as a segmented, multi-color bar when breakdown data exists, or a single-color bar based on overall usage level otherwise.
  • Extracted shared utilities (getOverallUsageColor, formatTokensCompact, and CONTEXT_CATEGORIES) into contextColors.ts so they can be reused across both components.
  • The indicator text now also shows the percentage inline (e.g. 74K/200K · 37%).

How did you test this?

Added unit tests in ContextBreakdownPopover.test.tsx covering:

  • Header rendering with aggregate token counts and percentage.
  • Placeholder copy when breakdown data is null.
  • Only non-zero categories appearing in the breakdown list.

Publish to changelog?

no

Copy link
Copy Markdown
Contributor Author

k11kirky commented May 25, 2026

Replaces the simple tooltip on the inline context indicator with a
Radix popover that mirrors the design spec: an aggregate header
("~74K / 200K tokens", "37% full"), a multi-segment progress bar
colored by source, and a per-category token list (System prompt,
Tools, Rules, Skills, MCP, Subagents, Conversation) with zero-token
rows hidden. The inline label now reads "X/Y · Z%" so the percent
is glanceable without opening the popover.

The popover consumes the new `breakdown` field from `useContextUsage`
(plumbed in B3). When the breakdown is missing — e.g. before the
first response of a session — the popover falls back to a single
percent bar and surfaces a one-line placeholder explaining that
detail will arrive after the first response. Color choices and the
`formatTokensCompact` helper are lifted into a shared
`contextColors` module so both the indicator and popover read from
the same source.

Generated-By: PostHog Code
Task-Id: bac06178-1ab1-4000-9a56-1901215bd4af

Generated-By: PostHog Code
Task-Id: bac06178-1ab1-4000-9a56-1901215bd4af
@k11kirky k11kirky force-pushed the posthog-code/context-breakdown-popover branch from b68e4e4 to ebe1dbc Compare May 25, 2026 16:58
@k11kirky k11kirky force-pushed the posthog-code/context-breakdown-data branch from 78a3903 to 00f8802 Compare May 25, 2026 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant