READMESource: main@0f911c99
dsh-token-counter
A global DSH plugin that shows a realtime token counter right after the blue "深度思考 / 深度求索" (deep-thinking) indicator, plus per-operation token usage after each completed step. It is global: once enabled, every conversation gets it.
Features
- Live in / out token counter — after the deep-thinking indicator, a
"华光划过" (shimmer sweep) badge shows the streaming token count, painted with
the platform's own shimmer so it reads as part of the same sentence.
in N token= input tokens,out N token= output tokens.- Unit scaling (auto by default) — numbers render as
K(1e3),M(1e6),G(1e9) orT(1e12) by magnitude (1866 → 1.9K,2 500 000 → 2.5M); below 1000 the raw number shows. A rounding that would print1000Kpromotes to1Minstead. Each site (in / out / use) can instead LOCK one unit in its gear menu and then always scales by it. - The input count is the number the harness itself prices the prompt with
(its
contextPressureprojection), so it is live during the input phase and does not wait for the provider'susage. When the provider does reportinputTokens, that authoritative figure takes precedence; when neither is available yet, the last known input is reused. - The streaming output count is a client-side estimate (CJK glyph ≈ 1 token, latin ≈ 4 chars/token), then snaps to the authoritative value when the stream settles.
- Display mode (configurable) —
merged(default) orsplit.merged: the label swaps rather than stacking — onlyin …during the input phase, onlyout …while generating (the phase flips as soon as the first output token streams).split: always showsin … · out …together, for the whole turn.
- In / out visibility (configurable) — independent switches to show/hide the input and output counters (both on by default). Each of the three switches carries a gear button: clicking it drops open a per-site editor with font size (0/empty = follow the interface text), color (a native picker plus a "follow theme" reset) and unit (auto / K / M / G / T). Settings are staged in the same form and saved together with everything else.
- Per-operation "use N token" (configurable) — after each completed
operation ("已完成思考", "已完成命令", …) a
use N tokenlabel appears, styled to match that row, showing the tokens that operation's own step consumed (input + output, or the provider'stotalTokenswhen it reports one) — never the whole reply's total. One switch toggles it; its own gear menu styles it. - All options are configurable from four places: 设置 → Token 计数器 (Settings → Token Counter), the same tab under 设置 → 内置插件, the configuration section on this bundle's page in the 插件 / Plugins panel, and the card in that panel's 官方 / Official group.
- Visual settings UI — a light white/grey, adaptive two-pane layout: merged
and split each get a preview card that recreates the real transcript scene
(a "Command finished · use N token" row and the deep-thinking badge with the
shimmer sweep, all with fake data). Hovering a card animates the numbers
(in climbs to its cap, pauses, then out climbs); clicking it switches the
display mode; and the in / out / use toggles update both cards live — turn
inoff and both cards drop the in segment immediately. The gear menus' unit/font/color choices are reflected in the preview cards before saving.
Install
# 1. pack the plugin
cd packages/dsh-token-counter
pnpm pack
# 2. install into the desktop profile
dsh plugin --profile desktop add ./dsh-token-counter-<version>.tgz
# (or manually: add the tarball to the profile's package.json dependencies and
# append "dsh-token-counter" to dsh.profile.bundles, then `pnpm install`)
# 3. restart DSH
Usage
- Open any conversation and send a message.
- While the model is thinking/streaming, the counter appears after the "深度思考" indicator and counts up in real time.
- When the answer completes, each "已完成…" operation row shows
use N tokenfor that operation's own step. - Open 设置 → Token 计数器: hover a preview card to watch the numbers
animate, click it to switch merged/split, and use the in / output / per-op
toggles — the cards update in lockstep. Save when you are done. The same
form is also reachable as a tab under 设置 → 内置插件, as the
configuration section on this bundle's page in the 插件 / Plugins panel
("dsh-token-counter" → 配置), and as the "Token 计数器" card in that panel's
"官方 / Official" group.
If the settings form reports "This plugin is not loaded, so it cannot be
configured right now", the host half is not mounted — run
dsh --profile desktop --dump-config(or check the profile'scordis.patch.yml) before filing an issue.
How it works
- The browser half subscribes to the DSH client
sessionsservice and the active (main-view) session'sbinding.eventSource. - It counts
text-delta/reasoning-deltastream chunks as they arrive, reads the live input count from the harness'scontextPressureprojection, and records authoritativeusageper step from theusagechunk /assistant/messageevent (keyed by turn + step). - It injects a DOM badge into the running indicator (there is no slot around it). Each completed operation row is one step, so rows walked in document order claim the next settled step of their turn and show that step's own tokens.
Package layout
lib/index.js— host half: schemasteryConfig(the configurable options) +apply.lib/client.js— browser half viawindow.__ModuleLoader__.load.cordis.patch.yml— registers the plugin profile entry.package.json—dsh.client = { platform: "web", inject: [...] }.
Develop / test
node test/run-tests.mjs # mocked-browser unit tests (all features)
No comments yet. Be the first to write one.