Skip to content

Client: dev-only context-window segment breakdown in usage card#12646

Draft
harryalbert wants to merge 2 commits into
masterfrom
harry/context-window-segments-client
Draft

Client: dev-only context-window segment breakdown in usage card#12646
harryalbert wants to merge 2 commits into
masterfrom
harry/context-window-segments-client

Conversation

@harryalbert

Copy link
Copy Markdown
Contributor

Description

Client (§3) of the dev-only context-window-usage segment breakdown plan.

Ingests the new context_window_segments field on the multi-agent
StreamFinished.ConversationUsageMetadata proto and renders an
expandable per-segment breakdown beside the "Context window used" row in
the conversation usage card. The breakdown lists segments such as system
prompt, tool definitions, conversation history, and latest input.

Because the per-segment values are estimated/derived (scaled to the
exact displayed total), the breakdown is introduced by an
"ESTIMATED BREAKDOWN" header and each percentage is prefixed with ~.

Changes

  • crates/persistence/src/model.rs: new ContextWindowSegment struct + #[serde(default)] context_window_segments field on ConversationUsageMetadata, with proto From conversions (both directions).
  • app/src/ai/agent/conversation.rs: copies segments from the proto in update_cost_and_usage_for_request; adds context_window_segments() accessor.
  • app/src/ai/blocklist/usage/conversation_usage_view.rs: ConversationUsageInfo.context_window_segments; ToggleContextWindowExpanded action + context_window_expanded state + mouse state; render_context_window_toggle / append_context_window_segment_rows helpers; handle_action wiring.
  • app/src/terminal/view.rs: populates the segment vec when building the usage footer.
  • Forward-fills segments on the shared-session and replay proto builders; defaults to empty on the historical GraphQL paths (out of scope).
  • Feature flag ContextWindowUsageBreakdown (sibling of ContextWindowUsageV2) in warp_features, app/src/features.rs, app/Cargo.toml. Dev-only: intentionally not added to default; enable via --features context_window_usage_breakdown.

Temporary cross-repo wiring (revert before merge)

  • Cargo.toml: path patch pointing warp_multi_agent_api at the local warp-proto-apis checkout (with a TODO to revert and bump the git rev once the proto change merges).

Verification

  • cargo check -p warp
  • cargo check -p warp --features context_window_usage_breakdown
  • cargo fmt --check
  • Per repo conventions, did not run nextest/presubmit.

Conversation: https://staging.warp.dev/conversation/95bb9b48-02cf-4f8d-a157-bc4653694e6f
Run: https://oz.staging.warp.dev/runs/019ecbbe-4836-75e3-987f-656c693aa297

This PR was generated with Oz.

Ingests the new `context_window_segments` field from the multi-agent
StreamFinished proto and renders an expandable per-segment breakdown
(system prompt, tool definitions, conversation history, etc.) beside the
"Context window used" row in the conversation usage card. Values are
estimated/derived, so the breakdown is labeled "ESTIMATED BREAKDOWN" and
percentages are prefixed with `~`.

Gated behind the dev-only `ContextWindowUsageBreakdown` feature flag
(not in app/Cargo.toml `default`; enable via
`--features context_window_usage_breakdown`).

Temporary cross-repo wiring: points `warp_multi_agent_api` at the local
warp-proto-apis checkout via a Cargo path patch (see revert TODO).

Co-Authored-By: Oz <oz-agent@warp.dev>
@cla-bot cla-bot Bot added the cla-signed label Jun 15, 2026
Extends the breakdown beyond the live stream: adds the
`contextWindowSegments` field + `ContextWindowSegment` type to the
bundled GraphQL schema, wires matching cynic fragments in the
conversation-usage and AI-conversation queries, and maps the GraphQL
segments into the persistence model. Removes the empty-default
workarounds on the historical paths.

Co-Authored-By: Oz <oz-agent@warp.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant