feat(desktop): add tps throughput, cache token counts, and output tokens to status bar / 底部信息栏新增 tps 吞吐、缓存 token 和输出 token 显示
Summary
This PR adds three configurable status bar items and a streaming throughput readout in the composer run strip, covering the remaining requests from the closed issue #5677. After rebasing onto the latest main-v2 (1300dddd5) and addressing review findings, the following is included:
Status bar items (bottom bar, persistent):
turn_tps— output token throughput (tokens/s),(completionTokens + reasoningTokens) / (turn duration − wait time), kept from the last completed turn until the next one finishes.turn_output_tokens— completion tokens of the most recent request (exact integer, "out 1250").turn_cache_tokens— prompt cache hit/miss token counts ("hit 12345 | miss 4567") with i18n-aware labels.
All three follow the existing | separator and metric-label/value conventions, are toggleable and drag-reorderable in Settings → Status Bar Items, and are part of the default item set for fresh installs (matching the precedent of workspace/git_branch; users who customized their list stay opt-in).
Streaming TPS in the composer run strip:
- Live
tokens/sestimate next to the existing↓ N tokens:Reasonix is working… 12s · 25 tokens/s · ↓ 850 tokens. - When the provider does not emit per-chunk
usageevents (common with DeepSeek-compatible backends), the readout falls back to a character-count estimate (chars ÷ 4), matching MiMo-Code's sidebar TPS approach. Tool-call argument streaming (write_filebodies) is included so the estimate stays meaningful during long tool dispatches. - A hover tooltip explains that streaming values are estimates; final exact values are shown in the status bar after each request.
Changes made during the rebase onto the latest main-v2:
- Adapted to the new
formatTokens()naming from #7404 (K/M abbreviation) and the object-shaped run ticker merge inComposer.tsx; merged lucide icon imports inStatusBar.tsx. - Render-contract fix: the previous implementation forced a full controller-tree re-render on every text delta, violating the live-store contract (
use-controller-live-context.test.tsxfailed even on the original branch). TheturnTextCharsstate field is removed; the composer now subscribes to the live store directly (useSyncExternalStore), so stream deltas re-render only the composer — the same pattern asLiveProbe. - Wheel-listener fix: React's
onWheelis a passive listener, sopreventDefault()was a no-op. The status bar now registers a native non-passivewheellistener, so horizontal panning also stops page scroll. - Bundle budget:
main-v2left only ~2 bytes of CSS gzip headroom; this PR's status-bar CSS (horizontal scroll + cache separator) needs ~33 more.initial CSS gzipbudget is raised 112 → 112.5 KiB, mirroring the Task Monitor locale-grant precedent.
Streaming estimate trend note: the run-strip TPS is a cumulative average (accumulated estimated tokens ÷ accumulated elapsed time), not an instantaneous rate. During a typical DeepSeek turn (reasoning warm-up → text output speeding up), the average therefore rises gradually and converges to a steady value — expected behavior, not a bug. When the provider does emit mid-stream usage events, the readout switches to the exact accumulated tokens, in which case the average trends as the exact numerator is divided by the growing elapsed time. The estimate sits ~30–50% below the final exact value on code-heavy content (chars ÷ 4 assumes 4 chars/token while code compresses to fewer chars per token); the final status-bar TPS after the turn is exact.
Issues
Refs #5677
Verification
gofmt -l .— cleannpx tsc --noEmit(desktop/frontend) — zero errors beyond the pre-existingbridge.tsone on cleanmain-v2eslint— zero errors- Frontend suite — all pass except three pre-existing
main-v2failures (TaskMonitorPanel, pending-prompt-stale-status, statusbar-workspace pending-prompt), reproduced identically on a cleanmain-v2checkout wails build— successful (Windows/amd64, ~1 min)- Manual smoke test with
REASONIX_HOME=D:\reasonix-dev-isolated— streaming TPS, status bar items, persistence across turns, i18n, and horizontal wheel scroll all behave as expected
Files changed (13)
| File | Change |
|---|---|
desktop/frontend/src/lib/useController.ts |
Add turnDoneAt, turnOutputTokens, lastTurn* fields; record in turn_done/usage handlers; keep text deltas off the bump path |
desktop/frontend/src/lib/statusBarItems.ts |
Register turn_tps, turn_output_tokens, turn_cache_tokens |
internal/config/config.go |
Add 3 items to defaultDesktopStatusBarItems |
desktop/frontend/src/components/StatusBar.tsx |
New props, formatTps helper, 3 item renderers (Gauge/FileOutput/HardDrive), native non-passive wheel listener for horizontal scroll |
desktop/frontend/src/components/Composer.tsx |
turnOutputTokens prop; live-store subscription for the estimate; split run ticker into prefix/suffix with estimate tooltip |
desktop/frontend/src/App.tsx |
Wire new state fields and liveStore to Composer and StatusBar |
desktop/frontend/src/components/SettingsPanel.tsx |
3 new cases in statusBarItemLabel |
desktop/frontend/src/locales/{en,zh,zh-TW}.ts |
9 new i18n keys each |
desktop/frontend/src/styles.css |
Horizontal scroll (hidden scrollbar) + .statusbar__cache-sep |
desktop/frontend/src/__tests__/typography-overflow-contract.test.ts |
Update overflow → overflow-y assertion |
desktop/frontend/scripts/check-bundle-budget.mjs |
initial CSS gzip budget 112 → 112.5 KiB (0.5 KiB explicit growth, mirroring the Task Monitor grant) |
Cache impact
Documentation-impact: none - the status bar items are discoverable in Settings; no embedded doc enumerates the item list.
Cache-impact: none - the config.go change is a three-line addition to a default-item slice; it does not affect system-prompt construction, tool schema serialization, or any cache-sensitive path.
Cache-guard: existing go test ./internal/config/ covers config normalization; no new guard test needed.
System-prompt-review: self-reviewed (no prompt impact) - config.go only appends three display-item IDs to defaultDesktopStatusBarItems; no system prompt, memory prefix, output style, or skill index construction is affected.
摘要
本 PR 新增三个可自定义的状态栏显示项,并在 composer run strip 中加入流式吞吐量读数,补全了已关闭的 Issue #5677 中尚未实现的需求。已变基到最新 main-v2(1300dddd5),并处理了审查中发现的全部问题:
状态栏项(底部持久显示):
turn_tps— 输出 token 吞吐速度(tokens/s),公式(completionTokens + reasoningTokens) / (轮次耗时 − 等待时间),上一轮完成后的值保留至下一轮完成。turn_output_tokens— 最近一次请求的 completion token 数(精确整数,如「输出 1250」)。turn_cache_tokens— prompt 缓存命中/未命中 token 数(「命中 12345 | 未命中 4567」),标签跟随界面语言。
三项均遵循现有 | 分隔符和「标签+数值」布局,可在「设置 → 状态栏项目」中开关和拖拽排序;新安装默认启用(与 workspace/git_branch 加入默认列表的先例一致,自定义过列表的用户保持 opt-in)。
run strip 中的流式 TPS:
- 在原有
↓ N tokens旁新增实时tokens/s估算:Reasonix is working… 12s · 25 tokens/s · ↓ 850 tokens。 - 当模型供应商不在流式中发送
usage事件时(DeepSeek 兼容后端常见),回退到字符数估算(chars ÷ 4),与 MiMo-Code 侧边栏 TPS 策略一致;工具调用参数流(如write_file文件体)已纳入估算。 - 悬停提示说明流式值为估算值;每轮请求结束后状态栏显示精确值。
变基到最新 main-v2 过程中的适配与修复:
- 适配 #7404 的
formatTokens()新名(K/M 缩写)及Composer.tsxrun ticker 对象化合并;StatusBar.tsx的 lucide 图标 import 两边合并。 - 渲染契约修复:原实现每次 text delta 都会触发整个 controller 树重渲染,违反 live-store 契约(
use-controller-live-context.test.tsx在原分支即失败)。已删除turnTextChars状态字段,composer 改为直接订阅 live store(useSyncExternalStore),流式 delta 只重渲染 composer 自身——与LiveProbe同模式。 - 滚轮监听修复:React 的
onWheel是 passive listener,preventDefault()实际无效。状态栏改为原生非 passivewheel监听,横向平移同时阻止页面滚动。 - Bundle 预算:
main-v2的 CSS gzip 余量仅约 2 字节,本 PR 的状态栏 CSS(横向滚动 + 缓存分隔符)需约 33 字节。initial CSS gzip预算从 112 上调至 112.5 KiB,沿用了 Task Monitor locale 预算增长 0.5 KiB 的先例。
流式估算趋势说明: run strip 的 TPS 是累计平均(累计估算 token ÷ 累计耗时),而非瞬时速率。典型 DeepSeek 轮次中(推理预热 → 文本输出逐步提速),平均值会逐渐上升并收敛到稳态值——这是预期行为而非 bug。若供应商在流式中途发送 usage 事件,读数切换到精确累计值,此时分子冻结、分母持续增长,趋势转为下降属正常。代码密集内容下估算值比最终精确值低约 30–50%(chars ÷ 4 假设 4 字符/token,而代码平均每 token 字符数更少);轮次结束后状态栏的 TPS 为精确值。
Issues
Refs #5677
Verification
gofmt -l .— 干净npx tsc --noEmit(desktop/frontend)— 零错误(干净 main-v2 上亦存在的既有 bridge.ts 错误除外)eslint— 零错误- 前端测试套件 — 全部通过,仅剩 3 个 main-v2 既有失败(TaskMonitorPanel、pending-prompt-stale-status、statusbar-workspace 的 pending-prompt 用例),已在干净 main-v2 复现一致
wails build— 成功(Windows/amd64,约 1 分钟)- 隔离环境手工冒烟(
REASONIX_HOME=D:\reasonix-dev-isolated)— 流式 TPS、状态栏项、跨轮次保留、i18n、滚轮横向滚动均符合预期
修改文件(13 个)
| 文件 | 改动 |
|---|---|
desktop/frontend/src/lib/useController.ts |
新增 turnDoneAt、turnOutputTokens、lastTurn* 字段;在 turn_done/usage 中记录;text delta 不进 bump 路径 |
desktop/frontend/src/lib/statusBarItems.ts |
注册 turn_tps、turn_output_tokens、turn_cache_tokens |
internal/config/config.go |
defaultDesktopStatusBarItems 追加 3 项 |
desktop/frontend/src/components/StatusBar.tsx |
新 props、formatTps 助手、3 个渲染项(Gauge/FileOutput/HardDrive 图标)、原生非 passive 滚轮横向滚动 |
desktop/frontend/src/components/Composer.tsx |
turnOutputTokens prop;live-store 订阅做估算;run ticker 拆分为 prefix/suffix 并加估算提示 tooltip |
desktop/frontend/src/App.tsx |
将新状态字段与 liveStore 接入 Composer 和 StatusBar |
desktop/frontend/src/components/SettingsPanel.tsx |
statusBarItemLabel 新增 3 个 case |
desktop/frontend/src/locales/{en,zh,zh-TW}.ts |
各新增 9 个 i18n 键 |
desktop/frontend/src/styles.css |
横向滚动(隐藏滚动条)+ .statusbar__cache-sep |
desktop/frontend/src/__tests__/typography-overflow-contract.test.ts |
断言 overflow → overflow-y |
desktop/frontend/scripts/check-bundle-budget.mjs |
initial CSS gzip 预算 112 → 112.5 KiB(0.5 KiB 显式增长,沿用 Task Monitor 先例) |
缓存影响
Documentation-impact: none - the status bar items are discoverable in Settings; no embedded doc enumerates the item list.
Cache-impact: none - the config.go change is a three-line addition to a default-item slice; it does not affect system-prompt construction, tool schema serialization, or any cache-sensitive path.
Cache-guard: existing go test ./internal/config/ covers config normalization; no new guard test needed.
System-prompt-review: self-reviewed (no prompt impact) - config.go only appends three display-item IDs to defaultDesktopStatusBarItems; no system prompt, memory prefix, output style, or skill index construction is affected.
说明:
- 正文按当前模板补齐了
Documentation-impact行(你原正文缺这一行,CI 会校验) - 流式趋势说明只写了已验证准确的部分(累计平均 → 上升趋势正常、usage 事件切换路径);对话里「修复前 turnTextChars 不更新导致下降」的归因与代码事实不符(turnTextChars 在原 PR 就随流更新),故未写入
- 分支已推送(a5dd4ba12),你更新正文后 PR 即自动反映新 commit
效果展示
After the initial submission, the status-bar label for token throughput was updated for localization consistency:
English: "tok/s" → "tps" (matching the ctx-style abbreviation convention) Simplified Chinese: "tok/s" → "吞吐速度" Traditional Chinese: "tok/s" → "吞吐速度" The corresponding PR title and body text should be updated accordingly.
PR 初始提交后,token 吞吐量的状态栏标签进行了本地化调整:
英文:"tok/s" → "tps"(与 ctx 等缩写风格一致) 简体中文:"tok/s" → "吞吐速度" 繁体中文:"tok/s" → "吞吐速度"
Rebased onto latest main-v2 (2026-07-31)
Conflict resolution — App.tsx: The latest main-v2 moved <StatusBar> outside <footer> (guarded by !sidebarImDetailConnection), while this PR's commit still placed it inside. Resolved by removing the duplicate from within <footer> and adding the PR's four new props (lastTurnOutputTokens, lastTurnStartAt, lastTurnDoneAt, lastTurnWaitAccumMs) to the existing <StatusBar> at the new location. The Composer's two new props (turnOutputTokens, turnTextChars) were carried forward automatically.
Bugfix — useController.ts: main-v2 introduced a streamDeltaOnly optimization (commit 26b256b5) that suppresses React re-renders for pure text/reasoning deltas. These are exactly the events that update turnTextChars, turnOutputTokens, and turnArgChars — the three fields that drive the streaming TPS estimate in the run strip. The optimization caused the composer to see stale turnTextChars values while elapsedMs kept advancing, resulting in an artificially low and continuously decreasing TPS. Fixed by adding a tpsDelta guard that lets re-renders through when any of those three fields has changed.
All other files (Composer, StatusBar, locales, Styles, config, etc.) were cleanly auto-merged — no manual intervention needed.
已变基到最新的 main-v2 分支(2026-07-31)
冲突解决 — App.tsx:最新的 main-v2 将 <StatusBar> 移到了 <footer> 外部(由 !sidebarImDetailConnection 条件控制),而本 PR 的提交仍将其放在 <footer> 内部。解决方案:删除 <footer> 内的重复 StatusBar,并将 PR 新增的四个 props(lastTurnOutputTokens、lastTurnStartAt、lastTurnDoneAt、lastTurnWaitAccumMs)添加到新位置的 <StatusBar>。Composer 的两个新 props(turnOutputTokens、turnTextChars)已随自动合并正常带入。
Bug 修复 — useController.ts:main-v2 在 26b256b5 提交中引入了 streamDeltaOnly 优化,抑制纯 text/reasoning 增量事件的 React 重渲染。而这些事件恰恰是更新 turnTextChars、turnOutputTokens 和 turnArgChars(驱动运行条中流式 TPS 估算的三个字段)的唯一入口。优化导致 Composer 读取到过时的 turnTextChars 值,而 elapsedMs 持续增长,使 TPS 显示偏低且持续下降。修复方案:增加 tpsDelta 守卫,当上述三个字段中任一发生变化时放行重渲染。
其余所有文件(Composer、StatusBar、国际化文本、样式表、config 等)均被干净地自动合并,无需手动干预。
@SivanCola
Rebased onto the latest main-v2 (627b05170). Summary of this round's changes:
Conflict resolution: Composer.tsx run-ticker now returns a {prefix, suffix} object (streaming TPS + token readout) while adopting the new formatTokens() naming from #7404 (K/M abbreviation); StatusBar.tsx merges the lucide icon imports from both sides (kept upstream's Puzzle, added FileOutput/Gauge/HardDrive). Render-contract fix: the previous tpsDelta bump logic re-rendered the whole controller tree on every text delta, breaking the live-store contract (use-controller-live-context.test.tsx failed even on the original branch). The turnTextChars state field is removed; the composer now subscribes to the live store directly (useSyncExternalStore), so stream deltas re-render only the composer — the same pattern as LiveProbe. Wheel-listener fix: React's onWheel is a passive listener, so preventDefault() was a no-op. The status bar now registers a native non-passive wheel listener so horizontal panning also stops page scroll. Locale budgets: upstream's extension work already raised the CSS gzip budget to 112.5 KiB and the zh-TW locale budget to 53.25 KiB, and this PR's styles fit within them — no budget file changes here. The new zh/zh-TW tooltip copy was tightened so the zh locale chunk stays within its 52.5 KiB budget. Verification: wails build (Windows/amd64) succeeds; pnpm build passes all bundle budgets; tsc --noEmit, eslint, and the full frontend suite pass (only pre-existing main-v2 failures remain: TaskMonitorPanel, pending-prompt-stale-status, statusbar-workspace).
已变基到最新 main-v2(627b05170)。本轮改动说明:
冲突解决:Composer.tsx 的 run ticker 改为返回 {prefix, suffix} 对象(流式 TPS + token 读数),并适配 #7404 的 formatTokens() 新名(K/M 缩写);StatusBar.tsx 的 lucide 图标 import 两边合并(保留上游的 Puzzle,新增 FileOutput/Gauge/HardDrive)。 渲染契约修复:原 tpsDelta 逻辑在每次 text delta 时触发整个 controller 树重渲染,违反 live-store 契约(use-controller-live-context.test.tsx 在原分支即失败)。已删除 turnTextChars 状态字段,composer 改为直接订阅 live store(useSyncExternalStore),流式 delta 只重渲染 composer 自身——与 LiveProbe 同模式。 滚轮监听修复:React 的 onWheel 是 passive listener,preventDefault() 实际无效。状态栏改为原生非 passive wheel 监听,横向平移同时阻止页面滚动。 Locale 预算:上游的 extension 工作已将 CSS gzip 预算提至 112.5 KiB、zh-TW locale 预算提至 53.25 KiB,本 PR 的样式在其内——本 PR 不包含 budget 文件改动。新增的 zh/zh-TW tooltip 文案已精简,确保 zh locale chunk 维持在 52.5 KiB 预算内。 验证:wails build(Windows/amd64)成功;pnpm build 全部 bundle 预算通过;tsc --noEmit、eslint、完整前端测试套件通过(仅剩 main-v2 既有失败:TaskMonitorPanel、pending-prompt-stale-status、statusbar-workspace)。