Skip to content

feat(chat): show per-turn token usage capsule - #1818

Merged
Tioit-Wang merged 4 commits into
mainfrom
feat/turn-usage-capsule
Oct 23, 2026
Merged

Tioit-Wang merged 4 commits into
mainfrom
feat/turn-usage-capsule

Conversation

@Tioit-Wang

Copy link
Copy Markdown
Collaborator

What changed

Completed assistant turns now render one quiet usage capsule immediately to the right of the existing model badge:

  • Always visible: average generation speed and compact turn total.
  • Hover or keyboard focus: a portaled popover with the composition bar, exact cache-read / input / output counts (cache write only when non-zero), and the exact total.
  • The capsule stays open while the pointer is over it, closes after a short grace delay unless the trigger retains keyboard focus, and also closes on Escape or an outside pointer press.
  • The popover clamps to the conversation pane, repositions on scroll, resize, and pane geometry changes, and prefers the space below the answer (the composer inspector keeps its above-first behavior).

Semantics

  • Turn total = input + output + cacheRead + cacheWrite summed across the visual turn's parent assistant messages. Reasoning tokens are already inside output; subagent spend stays out.
  • Speed = summed output tokens over summed response duration, reusing calculateTokenRate; estimated interrupted-response output is prefixed with the existing approximately marker.
  • The composer context inspector remains the last-request occupancy authority. The two surfaces deliberately answer different questions and the specs now state that boundary.
  • No usage means no capsule; the legacy estimated-throughput chip remains for usage-less turns, and streaming turns still render no meta row.

Files

  • apps/desktop/src/features/chat/transcript/TurnUsageCapsule.tsx (new component)
  • apps/desktop/src/features/chat/transcript/{AssistantTurn,shared}.tsx
  • apps/desktop/src/lib/{context-usage,context-inspector-position}.ts
  • apps/desktop/src/styles/messages.css
  • packages/i18n/src/locales/* (9 shipped locales)
  • docs/spec/04-ux/{08-component-spec,10-workbuddy-benchmark-ux}.md + zh-CN mirrors
  • docs/spec/06-delivery/04-e2e-test-plan.md E2E-060d + zh-CN mirror
  • apps/desktop/test/{context-usage,context-inspector-position,turn-usage-capsule}.test.mjs

Validation

  • corepack pnpm --filter @pi-desktop/desktop typecheck — pass
  • corepack pnpm lint — pass (Biome + style-token gate)
  • node --test on the three touched test files — 38 pass, 0 fail
  • corepack pnpm build:js — pass
  • node docs/scripts/check-locales.mjs — 86 pairs verified
  • node docs/scripts/check-docs.mjs — 583 pages verified
  • corepack pnpm check:pr-base — origin/main is an ancestor of the head
  • Electron/verify:ui:* E2E was not run; this is a renderer-only surface and the user did not request UI E2E.

v_wyxgwang added 2 commits October 22, 2026 18:07
Completed assistant turns now show the model, average generation speed, and total tokens on one quiet row. Hovering or focusing the capsule reveals cache-read, input, and output counts without opening the composer inspector, while the composer remains the last-request occupancy authority.

The capsule aggregates every parent assistant message in the visual turn, so its total answers what the round consumed rather than what the newest request occupied. Subagent spend stays out of the per-message usage contract.
The session reference UI test transpiles the real shared transcript module and asserts every dependency is stubbed. Importing the new capsule broke that fixture graph, so the fixture now provides a capsule stub and the breakdown helper Mock.
@Tioit-Wang
Tioit-Wang merged commit 86944c0 into main Oct 23, 2026
7 checks passed
@Tioit-Wang
Tioit-Wang deleted the feat/turn-usage-capsule branch October 23, 2026 02:57

This branch was previously deployed

1 inactive deployment
Preview — 0221fc93 Deployed Oct 23, 2026 by vercel[bot]
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