Skip to content

feat(usage): make the spend entry an icon and read it on open - #730

Merged
huichen merged 3 commits into
mainfrom
feat/usage-icon
Sep 20, 2026
Merged

huichen merged 3 commits into
mainfrom
feat/usage-icon

Conversation

@huichen

@huichen huichen commented Sep 20, 2026

Copy link
Copy Markdown
Collaborator

Three changes to the session-spend entry, from reviewing the panel on both platforms.

1. The entry is an icon, not an amount

Both headers showed the running total as text (¥1.0904). That puts a number that changes on every run in the most prominent slot of the header, and it competed with the thread title for width. It is now a ReceiptText (bill) icon button — desktop 32×32, mobile 44×44 (touch target) — with aria-label "Token 用量与金额" and aria-haspopup on desktop. The amount is unaffected; it is one click away, in the panel.

Chosen over Coins/CircleDollarSign/Wallet/PieChart/Gauge after rendering all six in the real UI: the first three read as "money/balance" (the desktop sidebar already uses a wallet for account credit), PieChart/Gauge read as "statistics/quota", and a bill matches what the panel actually shows — a session's itemised spend.

2. Opening the panel now reads the session instead of a cached snapshot

The number was stuck at whatever it was when the thread was opened: agent_end forwarded the event to the message list but never re-read usage, and the click handler only toggled visibility.

  • Desktop: clicking re-reads the session (revalidateAgentState), and a run ending re-reads too, so a panel already on screen updates in place. The cached value stays visible until the new one arrives (no blank flash).
  • Mobile: refreshSessionUsage() on open; a failed read keeps the last known figures rather than clearing the sheet, and no request is sent when no session is open.

3. Mobile: no rename in the conversation

The pencil sat in the top bar and again in the panel header, while every conversation in the list already has Rename in its row menu. Both were removed (and useRename.ts deleted — the sheet was its only other consumer), which frees the top-bar row for the title.

Verification

  • Desktop: npm run lint (eslint over src/shot + tsc), npm run stylelint, vitest run — 1184 passed.
  • Mobile: tsc --noEmit, eslint ., jest — 1706 passed.
  • Screenshot harness: the mocks answer the panel's read with a larger figure and the scenarios assert the refreshed value is what the panel shows (¥1.3904, previously the cached ¥1.0904), so a regression in the refresh fails the capture instead of only being visible to a human. Six icon-variant scenarios are included for the comparison above.
  • Unit tests for the staleness: desktop "re-reads on open" and "re-reads when a run ends"; mobile "applies the refreshed usage", "keeps the last figures when the read fails", "does not fetch without a session". The desktop pair fails against the previous behaviour.

Reviewed images (entry before/after, panel, unpriced model, icon candidates, both platforms) were rendered from the real UI against demo data.

…versation

Two comments on the first cut, both about where the control belongs:

- The entry showed the running amount as text. That is the conversation header,
  whose job is the conversation — a number that changes every turn competes with
  the title for the eye. A receipt icon opens the same dialog without carrying
  the figure; the amount lives inside, where it has the token split next to it.
  Receipt rather than coins/wallet/circle: those read as "money in general", and
  the activity rail already uses a wallet for the account balance, whereas a
  receipt is the bill for this conversation.
- Renaming lived in the conversation (a pencil in the top bar, later inside the
  usage sheet). The session list already owns it, so repeating it only lengthened
  the bar and put an editing action in an accounting view. Removed from both,
  along with `useRename` — nothing else used it.

The label font for composed sheets is not part of this change, but the review
images for it hit a real trap: PingFang.ttc no longer exists on current macOS, so
a short font list falls through to a Latin-only face and every Han glyph becomes
a tofu box. The sheets here go through the harness's own `load_font`, which
already orders CJK faces first.
…ched one

The amount came from the cached agent state, which is only as fresh as the last
read: opening the thread, an agent reconnect, or a compaction event. Nothing
re-read it when a run finished, so the panel kept showing the figure from
whenever the conversation was opened — the same numbers every time, which is how
it was reported.

- Desktop: opening the panel re-reads the session (`revalidateAgentState`), and
  `agent_end` now revalidates too — a run's spend is final at that point, and the
  panel may already be on screen when it lands. The cached values stay visible
  until the fresh read arrives; nothing blanks out.
- Mobile: the sheet's entry point re-reads through `refreshSessionUsage`, a new
  controller method. A failed read keeps the last known figures rather than
  emptying the sheet, and no request is made when no conversation is open.

Verification is end-to-end, not just "the call happens": both harness mocks now
answer a *later* read with a larger figure and the scenarios assert the panel
shows it — `thread-usage` requires ¥1.3904 in the dialog where the header's
cached value was ¥1.0904, and `usage-sheet` requires the same in the sheet and
then on the top bar after closing. Those steps fail the capture run if the
refresh stops reaching the UI.

Unit tests cover the pieces: the desktop re-read fires on open and on run end
(both fail against the previous code), and the mobile controller applies what a
refresh returns while surviving a failure.
@huichen
huichen enabled auto-merge (squash) September 20, 2026 01:09
@huichen
huichen merged commit fb88388 into main Sep 20, 2026
12 checks passed
@huichen
huichen deleted the feat/usage-icon branch September 20, 2026 01:12
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