qwen-code/docs/design/web-shell-context-tab.md
Shaojin Wen 96b14f2311
feat(web-shell): add a context usage tab to the right sidebar (#11177)
* feat(web-shell): add a context usage tab to the right sidebar

Surface current context-window composition beside the existing token
consumption tab. The new opt-in header action opens a session-owned
context_usage artifact tab that reuses the /context renderer in a compact
sidebar layout, with manual refresh and owner-bound restoration.

The data path already exists (getContextUsage with detail), so this adds no
endpoint or core change. Tabs deduplicate, persist, restore lazily against
their saved session, and close with their pane or session, mirroring the
token tab lifecycle. Transcript /context behavior is unchanged.

* fix(web-shell): address context tab review round 1

- Share one transient-read predicate between the two usage panels so both
  swallow disconnect, transport-close and fetch-failed identically.
- Keep the last good context reading during and after a failed refresh;
  only owner changes clear it.
- Dedupe the mount collection across StrictMode replays with an owner-keyed
  in-flight request instead of a closure-local flag.
- Reclaim pane-bound usage tabs at restore completion; the mount-time pane
  cleanup runs before restoration lands, so they survived reloads into a
  non-split view.
- Let the compact panel opt out of the 30-char detail-name cap, render the
  progress meter as proportional blocks, uncapped meta row and indented
  sub-rows, and align the zh-CN wording with the established term.
- Pin the gaps the review measured: transcript-insertion negatives, pane
  action owner binding, primary-session restore arm, standalone opt-in,
  no-actions render, and the compact/transcript truncation contract.

* fix(web-shell): address context tab review round 2

- Reclaim pane-bound usage tabs from an effect gated on a new
  splitViewSettled flag instead of at restore-commit time: mainView and
  splitSessionIds are still their useState initials when the restore
  continuation runs, so deciding there dropped legitimately pane-bound tabs
  and wrote the drop back to storage.
- Rethrow transient getContextUsage failures without a notice, mirroring
  getStats: the context panel re-collects on every activation, so the notice
  channel stacked identical errors while a session was down.
- Emit the compact meter segments in legend order (used, free, buffer) and
  pin widths and threshold colors in tests.
- Pin the alert-over-retained-reading precedence, the remaining reclaim
  filter quadrants, and the reachable pane-bound restore shape; type the
  pane context fixture and build the pane actions mock as an override of the
  main one so it satisfies the declared contract.

* fix(web-shell): address context tab review round 3

- Settle the split latch at every bootstrap exit, including superseded
  classifications and the non-workspace bail, and gate the non-split close
  twin on it so a live pane tab is never dropped mid-decision.
- Re-apply the pane-bound predicate at restore commit once the latch is
  already true, so a stale tab cannot be selected active and mount a foreign
  collection; defer to the settled sweep while the decision is pending, and
  re-run the sweep when the restored tab list lands.
- Make getContextUsage silence opt-in (silent) so the auto-recollecting panel
  stops stacking notices while user-initiated callers keep the attributed
  notice and suppressed duplicate toast.
- Pin the gaps the round measured: uncontrolled split bootstrap paths,
  superseded-classification settle, language-change survival, closed-panel
  restore, serialization of closeWithPane, binding replacement on re-open,
  render assertions for restored payloads, aria-busy during background
  refetch, clearing of unusable refresh results, transcript glyph math,
  meter-legend agreement, and the widened transient predicate at call sites.

* fix(web-shell): address context tab review round 4

- Re-arm the split latch when a classification actually starts, in both
  openSplitView and the controlled split effect, so a later decision re-opens
  the reclaim window instead of being licensed by an earlier settled one.
- Close the right panel when the restore-commit reclaim empties the tab list,
  mirroring closeArtifactPanelTabs, so an emptied panel is not persisted open.
- Dedupe silent hard context-usage failures through the existing
  silentHardFailureNoticeKeys pair, matching getTasks/getWorkflowTasks.
- Delete the non-split close twin subsumed by the settled sweep, which also
  removes its missing artifactPanelRestoring guard.
- Pin the re-arm, the do-not-settle branch under overlapping classifications,
  the emptied-panel close, the deep-link storage purge with a positive
  control, and the silent hard-failure notice semantics.

* fix(web-shell): address context tab review round 5

- Settle the split latch on a terminal capabilities error in the controlled
  split effect, so a capabilities blip cannot strand the latch unsettled
  while no classification can start; a merely pending load still defers.
- Route silent context-usage hard failures through noticeForSession and gate
  dedupe-key registration on the session still being live, so the registry
  stays session-scoped and a stale in-flight failure neither toasts for a
  session the user left nor suppresses the notice of the session on screen.
- Extract resetEmptyArtifactPanel and share it between closeArtifactPanelTabs
  and the reclaim-emptied commit path so the empty-panel reset cannot drift.
- Pin the owning-classification reclaim half of the overlapping-classification
  test, the capabilities-error settle, the registry teardown clear, and the
  per-call non-silent notice.

---------

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-09-08 01:22:42 +00:00

2.2 KiB

Web Shell context sidebar tab

Problem

Token consumption can be inspected in a right-sidebar tab, but current context composition is only displayed in transcript messages through /context.

Design

Add an independent opt-in contextUsage chat-header action, enabled in the standalone Web Shell, opening a session-owned context_usage artifact tab. Mirror token-tab deduplication, persistence, restoration and pane/session cleanup. Restored secondary-session tabs must bind getContextUsage to their saved session through the workspace client, rather than reading the current main session.

A small ContextUsagePanel loads getContextUsage({ detail: true }) on mount and manual refresh. Reuse ContextUsageMessage for the breakdown and detail lists, with scoped narrow-panel styling. Preserve estimated/no-provider wording. Render loading, unavailable and retry states, reject mismatched session payloads, and ignore stale asynchronous responses after ownership changes or unmount. Only active tabs fetch. No polling is introduced because collecting detailed context is more expensive than reading cumulative counters.

Affected files

Web Shell client App and tests, ArtifactPanel, new ContextUsagePanel and tests, ChatContextHeader, customization, standalone main, localization, and the context message renderer only if needed for a scoped compact layout.

Boundaries

No new endpoint, SDK/core changes, generic polling abstraction, raw prompt viewer, or changes to /context transcript behavior. Existing context metadata includes model/window usage, messages, system prompt, tools, memory and skills, not raw prompt contents. Token consumption remains independent.

Validation

Component and App regression tests cover loading, refresh, error recovery, stale responses, owner validation, independent tab deduplication, lazy restoration, secondary-session binding, opt-in actions and lifecycle cleanup. Browser checks cover the new entry, rendered details, refresh without transcript insertion, 320px layout and coexistence with token usage. Build, typecheck, focused tests, lint and self-audit precede completion.

Open questions

None for this scope. Automatic refresh can be considered separately if requested.