Skip to content

A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.

Show a Bot's turns, speed, cache hits and context in the app's details

Fei2411777994eed2b8
diff --git a/app/ui/src/team.js b/app/ui/src/team.js
index cf78ebf3..34938396 100644
--- a/app/ui/src/team.js
+++ b/app/ui/src/team.js
@@ -168,6 +168,8 @@ export function createTeam() {
const reactions = reactionStore.update(saved => toggleReaction(saved, key, index, emoji), ui.getSnapshot().reactions)
ui.set(state => ({ ...state, reactions }))
},
+ // The window has no DSH status bar, so the Bot's details show its figures.
+ runStats: botId => call('run-stats', { botId }),
// Nothing else draws in the window: no shell panels, right sidebar, "@" menu or voice plugin.
hasRightSidebar: () => false,
canReferenceChat: () => false,
diff --git a/docs/plans/2026-10-16-desktop-app.md b/docs/plans/2026-10-16-desktop-app.md
index 72c01a3f..125bfc3d 100644
--- a/docs/plans/2026-10-16-desktop-app.md
+++ b/docs/plans/2026-10-16-desktop-app.md
@@ -77,7 +77,7 @@
## 已知限制
-- 窗口里还没有:群聊的历史消息、工具卡片和审批、Bot 详情里的轮数和用量、首次启动和导入、DeepSeek 账号登录、每个 Bot 的浏览器、更新和安装包。侧栏每一行的最新一句只显示打开窗口以后的新消息。插件版里打开 DSH 自己界面的入口(连接插件、管理模型、Harness 设置,「+」里的添加文件和引用对话)窗口里也没有。模型和密钥目前用环境变量,或数据位置里的 `.env`、`.credentials.yaml` 设置。
+- 窗口里还没有:群聊的历史消息、工具卡片和审批、首次启动和导入、DeepSeek 账号登录、每个 Bot 的浏览器、更新和安装包。侧栏每一行的最新一句只显示打开窗口以后的新消息。插件版里打开 DSH 自己界面的入口(连接插件、管理模型、Harness 设置,「+」里的添加文件和引用对话)窗口里也没有。模型和密钥目前用环境变量,或数据位置里的 `.env`、`.credentials.yaml` 设置。
- 不签名:Windows 第一次运行会弹出 SmartScreen 警告,macOS 要在系统设置里手动放行。
- 会话里记着工作文件夹的完整路径,不能改。所以导入和搬工作文件夹都要换段。
diff --git a/ds-bot/client.js b/ds-bot/client.js
index 9f9e2fdd..f741c477 100644
--- a/ds-bot/client.js
+++ b/ds-bot/client.js
@@ -448,6 +448,12 @@ var ZH = {
"Today {time}": "今天 {time}",
"Yesterday {time}": "昨天 {time}",
"{tokens} tok · Cache hit {hit}%": "{tokens} tok · 缓存命中 {hit}%",
+ "1 turn": "1 轮",
+ "{count} turns": "{count} 轮",
+ "{speed} tok/s": "{speed} tok/s",
+ "Cache hit {hit}%": "缓存命中 {hit}%",
+ "Context {percent}%": "上下文 {percent}%",
+ "{used} of {total} tokens of context in use": "上下文已用 {used} / {total} tokens",
// Transcript
Footnotes: "脚注",
"Remove reaction {emoji}": "移除表情 {emoji}",
@@ -1828,6 +1834,36 @@ function usageOf(list, ids) {
const hit = input > 0 ? Math.round(cacheRead / input * 100) : 0;
return t("{tokens} tok · Cache hit {hit}%", { tokens: formatTokens(input + output), hit });
}
+function percentText(part, whole) {
+ if (part >= whole) return "100";
+ for (let places = 0; places < 3; places += 1) {
+ const text = (part / whole * 100).toFixed(places);
+ if (Number(text) < 100) return text;
+ }
+ return "99.99";
+}
+function runStatsOf(values) {
+ const stats = values?.sessionStats;
+ const usage = values?.tokenUsage;
+ const pressure = values?.contextPressure;
+ const shown = [];
+ if (stats?.turns > 0) shown.push({ key: "turns", text: stats.turns === 1 ? t("1 turn") : t("{count} turns", { count: stats.turns }) });
+ if (stats?.decodeMs > 0 && stats.decodeTokens > 0) {
+ const speed = stats.decodeTokens / (stats.decodeMs / 1e3);
+ shown.push({ key: "speed", text: t("{speed} tok/s", { speed: speed >= 10 ? Math.round(speed) : Math.round(speed * 10) / 10 }) });
+ }
+ const prompt = (usage?.uncachedInputTokens ?? 0) + (usage?.cacheReadTokens ?? 0) + (usage?.cacheWriteTokens ?? 0);
+ if (prompt > 0) shown.push({ key: "cache", text: t("Cache hit {hit}%", { hit: percentText(usage.cacheReadTokens ?? 0, prompt) }) });
+ const used = pressure?.projectedTokens ?? pressure?.pressureTokens;
+ if (Number.isFinite(used) && pressure.contextWindow > 0) {
+ shown.push({
+ key: "context",
+ text: t("Context {percent}%", { percent: Math.min(100, Math.round(used / pressure.contextWindow * 100)) }),
+ title: t("{used} of {total} tokens of context in use", { used: formatTokens(used), total: formatTokens(pressure.contextWindow) })
+ });
+ }
+ return shown;
+}
// src/client/motion.js
var import_react = require("react");
@@ -2406,6 +2442,8 @@ button.bt-q-opt:active{background:var(--bt-active)}
.bt-actions{display:flex;gap:8px;flex-wrap:wrap;align-items:center}
.bt-kv{display:flex;justify-content:space-between;gap:8px;font-size:12px;line-height:20px;color:var(--bt-ink-2)}
.bt-kv span:last-child{color:var(--bt-ink);font-variant-numeric:tabular-nums}
+.bt-run-stats{display:flex;flex-wrap:wrap;justify-content:center;gap:0 6px;margin-top:-6px;font-size:12px;line-height:18px;color:var(--bt-ink-2);font-variant-numeric:tabular-nums}
+.bt-run-sep{color:var(--bt-ink-3)}
.bt-danger{color:var(--bt-danger)}
/* Bot settings: fields, the avatar editor popover, and the details-pane sub-view. */
@@ -11773,6 +11811,36 @@ function PermissionRow({ bot, roster, actions, run }) {
(0, import_react33.createElement)(PermissionPicker, { catalog, saved: bot.permission ?? catalog.defaultPreset, repick: bot.permission === void 0, onPick: (permission) => run(actions.updateBot(bot.id, { permission })) })
);
}
+function RunStats({ bot, part, running, actions }) {
+ const [values, setValues] = (0, import_react33.useState)(null);
+ (0, import_react33.useEffect)(() => {
+ if (!actions.runStats) return void 0;
+ let current = true;
+ actions.runStats(bot.id).then(
+ (next) => {
+ if (current) setValues(next);
+ },
+ // The line stays as it was until the next read works.
+ () => {
+ }
+ );
+ return () => {
+ current = false;
+ };
+ }, [bot.id, part, running]);
+ const shown = runStatsOf(values);
+ if (shown.length === 0) return null;
+ return (0, import_react33.createElement)(
+ "div",
+ { className: "bt-run-stats" },
+ shown.map((entry, index) => (0, import_react33.createElement)(
+ import_react33.Fragment,
+ { key: entry.key },
+ index > 0 ? (0, import_react33.createElement)("span", { className: "bt-run-sep", "aria-hidden": true }, "·") : null,
+ (0, import_react33.createElement)("span", { title: entry.title }, entry.text)
+ ))
+ );
+}
function BrowserCards({ bot, sessionId, roster, actions, useBrowserTabs, useBrowserPages }) {
const state = useBrowserTabs((map) => map[bot.id] ?? EMPTY_TABS);
const pages = useBrowserPages((map) => map);
@@ -12043,6 +12111,7 @@ function DetailsDrawer({ sessionId, startRenaming, startTab, hasStrip, roster, a
errorLine,
room2 && tab === "details" ? (0, import_react33.createElement)(GroupOverview, { room: room2, roster, actions, usage, useWork, openSettings: () => setView("settings") }) : null,
bot && tab === "details" ? [
+ (0, import_react33.createElement)(RunStats, { key: "stats", bot, part, running, actions }),
(0, import_react33.createElement)(
"div",
{ key: "model", className: "bt-drawer-model" },
diff --git a/ds-bot/src/client/details-drawer.js b/ds-bot/src/client/details-drawer.js
index b39ed011..39472e11 100644
--- a/ds-bot/src/client/details-drawer.js
+++ b/ds-bot/src/client/details-drawer.js
@@ -1,6 +1,6 @@
import { createElement as h, Fragment, useEffect, useRef, useState } from 'react'
import { isMainOf } from './sources.js'
-import { HEADER, currentPart, stripHeader, usageOf } from './text.js'
+import { HEADER, currentPart, runStatsOf, stripHeader, usageOf } from './text.js'
import { PlusIcon, ShareIcon, CloseIcon, ChevronLeftIcon, GearIcon } from './icons.js'
import { botState, BotMark, BotAvatar } from './mark.js'
import { GlobeIcon, Favicon } from './browser-pane.js'
@@ -44,6 +44,28 @@ function PermissionRow({ bot, roster, actions, run }) {
h(PermissionPicker, { catalog, saved: bot.permission ?? catalog.defaultPreset, repick: bot.permission === undefined, onPick: permission => run(actions.updateBot(bot.id, { permission })) }))
}
+// The current part's turns, speed, cache hits and context, for a window without DSH's
+// status bar (actions.runStats). It reads them again when a turn starts or ends.
+function RunStats({ bot, part, running, actions }) {
+ const [values, setValues] = useState(null)
+ useEffect(() => {
+ if (!actions.runStats) return undefined
+ let current = true
+ actions.runStats(bot.id).then(
+ (next) => { if (current) setValues(next) },
+ // The line stays as it was until the next read works.
+ () => {},
+ )
+ return () => { current = false }
+ }, [bot.id, part, running])
+ const shown = runStatsOf(values)
+ if (shown.length === 0) return null
+ return h('div', { className: 'bt-run-stats' },
+ shown.map((entry, index) => h(Fragment, { key: entry.key },
+ index > 0 ? h('span', { className: 'bt-run-sep', 'aria-hidden': true }, '·') : null,
+ h('span', { title: entry.title }, entry.text))))
+}
+
// The Bot's browser inside the details page: its tabs as small window cards on
// Desktop, a pointer there on web.
function BrowserCards({ bot, sessionId, roster, actions, useBrowserTabs, useBrowserPages }) {
@@ -238,6 +260,7 @@ export function DetailsDrawer({ sessionId, startRenaming, startTab, hasStrip, ro
errorLine,
room && tab === 'details' ? h(GroupOverview, { room, roster, actions, usage, useWork, openSettings: () => setView('settings') }) : null,
bot && tab === 'details' ? [
+ h(RunStats, { key: 'stats', bot, part, running, actions }),
h('div', { key: 'model', className: 'bt-drawer-model' },
h('div', { className: 'bt-section-title' }, t('Model')),
h(ModelMenu, { bot, roster, actions, run, wide: true }),
diff --git a/ds-bot/src/client/i18n.js b/ds-bot/src/client/i18n.js
index d56919b9..2cfa3f8c 100644
--- a/ds-bot/src/client/i18n.js
+++ b/ds-bot/src/client/i18n.js
@@ -391,6 +391,12 @@ const ZH = {
'Today {time}': '今天 {time}',
'Yesterday {time}': '昨天 {time}',
'{tokens} tok · Cache hit {hit}%': '{tokens} tok · 缓存命中 {hit}%',
+ '1 turn': '1 轮',
+ '{count} turns': '{count} 轮',
+ '{speed} tok/s': '{speed} tok/s',
+ 'Cache hit {hit}%': '缓存命中 {hit}%',
+ 'Context {percent}%': '上下文 {percent}%',
+ '{used} of {total} tokens of context in use': '上下文已用 {used} / {total} tokens',
// Transcript
Footnotes: '脚注',
diff --git a/ds-bot/src/client/styles.js b/ds-bot/src/client/styles.js
index e5824edd..f1207e26 100644
--- a/ds-bot/src/client/styles.js
+++ b/ds-bot/src/client/styles.js
@@ -384,6 +384,8 @@ button.bt-q-opt:active{background:var(--bt-active)}
.bt-actions{display:flex;gap:8px;flex-wrap:wrap;align-items:center}
.bt-kv{display:flex;justify-content:space-between;gap:8px;font-size:12px;line-height:20px;color:var(--bt-ink-2)}
.bt-kv span:last-child{color:var(--bt-ink);font-variant-numeric:tabular-nums}
+.bt-run-stats{display:flex;flex-wrap:wrap;justify-content:center;gap:0 6px;margin-top:-6px;font-size:12px;line-height:18px;color:var(--bt-ink-2);font-variant-numeric:tabular-nums}
+.bt-run-sep{color:var(--bt-ink-3)}
.bt-danger{color:var(--bt-danger)}
/* Bot settings: fields, the avatar editor popover, and the details-pane sub-view. */
diff --git a/ds-bot/src/client/text.js b/ds-bot/src/client/text.js
index d21f4034..c59f621d 100644
--- a/ds-bot/src/client/text.js
+++ b/ds-bot/src/client/text.js
@@ -230,3 +230,39 @@ export function usageOf(list, ids) {
const hit = input > 0 ? Math.round((cacheRead / input) * 100) : 0
return t('{tokens} tok · Cache hit {hit}%', { tokens: formatTokens(input + output), hit })
}
+
+// A share that is not whole never reads as 100%: it gets decimals until it does not.
+function percentText(part, whole) {
+ if (part >= whole) return '100'
+ for (let places = 0; places < 3; places += 1) {
+ const text = ((part / whole) * 100).toFixed(places)
+ if (Number(text) < 100) return text
+ }
+ return '99.99'
+}
+
+// One Session's figures from DSH's sessionStats, tokenUsage and contextPressure views, as
+// its status bar counts them: turns, output tokens over decode time, cache reads over
+// every prompt-side token, and the context in use. Figures with nothing to count yet are left out.
+export function runStatsOf(values) {
+ const stats = values?.sessionStats
+ const usage = values?.tokenUsage
+ const pressure = values?.contextPressure
+ const shown = []
+ if (stats?.turns > 0) shown.push({ key: 'turns', text: stats.turns === 1 ? t('1 turn') : t('{count} turns', { count: stats.turns }) })
+ if (stats?.decodeMs > 0 && stats.decodeTokens > 0) {
+ const speed = stats.decodeTokens / (stats.decodeMs / 1000)
+ shown.push({ key: 'speed', text: t('{speed} tok/s', { speed: speed >= 10 ? Math.round(speed) : Math.round(speed * 10) / 10 }) })
+ }
+ const prompt = (usage?.uncachedInputTokens ?? 0) + (usage?.cacheReadTokens ?? 0) + (usage?.cacheWriteTokens ?? 0)
+ if (prompt > 0) shown.push({ key: 'cache', text: t('Cache hit {hit}%', { hit: percentText(usage.cacheReadTokens ?? 0, prompt) }) })
+ const used = pressure?.projectedTokens ?? pressure?.pressureTokens
+ if (Number.isFinite(used) && pressure.contextWindow > 0) {
+ shown.push({
+ key: 'context',
+ text: t('Context {percent}%', { percent: Math.min(100, Math.round((used / pressure.contextWindow) * 100)) }),
+ title: t('{used} of {total} tokens of context in use', { used: formatTokens(used), total: formatTokens(pressure.contextWindow) }),
+ })
+ }
+ return shown
+}
diff --git a/ds-bot/test/run-stats.test.js b/ds-bot/test/run-stats.test.js
new file mode 100644
index 00000000..879c8251
--- /dev/null
+++ b/ds-bot/test/run-stats.test.js
@@ -0,0 +1,36 @@
+import assert from 'node:assert/strict'
+import { test } from 'node:test'
+import { runStatsOf } from '../src/client/text.js'
+
+const texts = values => runStatsOf(values).map(entry => entry.text)
+
+test('the figures read as DSH counts them', () => {
+ const values = {
+ sessionStats: { turns: 12, decodeMs: 4000, decodeTokens: 150 },
+ tokenUsage: { uncachedInputTokens: 50, cacheReadTokens: 900, cacheWriteTokens: 50, outputTokens: 400 },
+ contextPressure: { pressureTokens: 41_000, contextWindow: 100_000 },
+ }
+ assert.deepEqual(texts(values), ['12 turns', '38 tok/s', 'Cache hit 90%', 'Context 41%'])
+ assert.equal(runStatsOf(values).at(-1).title, '41.0K of 100.0K tokens of context in use')
+})
+
+test('a slow speed keeps a decimal, and a projected count wins over the last measure', () => {
+ const values = {
+ sessionStats: { turns: 1, decodeMs: 2000, decodeTokens: 9 },
+ contextPressure: { pressureTokens: 10, projectedTokens: 30, contextWindow: 100 },
+ }
+ assert.deepEqual(texts(values), ['1 turn', '4.5 tok/s', 'Context 30%'])
+})
+
+test('a cache hit short of whole never reads 100%', () => {
+ const hit = cacheReadTokens => texts({ tokenUsage: { uncachedInputTokens: 1000 - cacheReadTokens, cacheReadTokens } })
+ assert.deepEqual(hit(996), ['Cache hit 99.6%'])
+ assert.deepEqual(hit(1000), ['Cache hit 100%'])
+ assert.deepEqual(hit(0), ['Cache hit 0%'])
+})
+
+test('nothing to count leaves the line empty', () => {
+ assert.deepEqual(runStatsOf(null), [])
+ assert.deepEqual(runStatsOf({ sessionStats: { turns: 0, decodeMs: 0, decodeTokens: 0 }, tokenUsage: { uncachedInputTokens: 0, cacheReadTokens: 0, cacheWriteTokens: 0 } }), [])
+ assert.deepEqual(texts({ contextPressure: { contextWindow: 100 } }), [])
+})