feat(ui): add cache hit rate to context sidebar last-message token breakdown (#1524)

* feat(ui): add cache hit rate to context sidebar with verified formula

Add a Cache Hit row to the last-assistant-message token breakdown in
the context sidebar. The percentage is computed by the new
computeCacheHitRate utility:

  cache.read / (input + cache.read + cache.write) x 100

The formula was verified against the SDK source
(packages/opencode/src/session/session.ts:getUsage), which reports
input as the non-cached portion only
(totalInputTokens - cacheReadInputTokens - cacheWriteInputTokens).

Also export sumTokenBreakdown from tokenUtils for reuse, and fix the
event-reducer test type errors (setDelta/getText helpers, toBeCloseTo
replacement).

Closes: #

* fix: wire i18n key for Cache Hit label, fix formatNumber type, drop unintended event-reducer changes

* chore: remove unused cacheHitRate and cacheHitRateTooltip i18n keys from en.ts

* fix: correct cache hit token display

* fix: add French cache hit label

---------

Co-authored-by: Bohdan Triapitsyn <artmore@protonmail.com>
This commit is contained in:
raz123
2026-06-11 21:43:41 +03:00
committed by GitHub
co-authored by Bohdan Triapitsyn
parent 284d72bef2
commit e20cfa2dbc
12 changed files with 179 additions and 9 deletions
+1
View File
@@ -1031,6 +1031,7 @@ export const dict = {
'contextSidebar.tokens.reasoning': 'Raisonnement',
'contextSidebar.tokens.cacheRead': 'Lecture du cache',
'contextSidebar.tokens.cacheWrite': 'Écriture du cache',
'contextSidebar.tokens.cacheHit': 'Succès du cache',
'contextSidebar.actions.copyJson': 'Copier JSON',
'contextSidebar.actions.copy': 'Copie',
'contextSidebar.actions.copied': 'Copié',