Introduction¶
When running multi-session, long-chain agents in DSH (DeepSeek Harness), usage is scattered across various session logs and event streams. It is difficult to see at a glance “how many billed tokens were spent in total, how much was cache read/write, and roughly how much money that is based on your pricing.” Manually digging through logs or running separate statistics scripts is costly and hard to link with the daily interface.
@shallbay/dsh-token-stats is a community-maintained dual-surface plugin: the Host side aggregates usage across all sessions and provides a dashboard and API, while the Client side registers a “Token Usage” entry in the sidebar. Below is an introduction to its positioning, capabilities, and installation usage; for facts, please refer to the GitHub repository README.
What is this¶
- Package Name:
@shallbay/dsh-token-stats(npm release name; source development copy linked as@deepseek-ai/dsh-token-statswithin the profile) - Maintainer: ShallBay
- Category: Client (Includes both Host bundle and Web client injection)
- License: MIT
- Directory Page: skillhub.cn/plugins/ShallBay/dsh-token-stats
The plugin aggregates billed tokens within the Harness scope: uncached input, cache reads, cache writes, and output. It provides RMB cost estimates based on peak/off-peak pricing; the dashboard route is /token-stats, supporting scheduled and manual refreshes.
Dual-Surface Architecture¶
The README splits the plugin into two halves with different responsibilities, delivered within the same package:
Host Half
- Aggregates billed token usage for all sessions.
- Provides dashboard pages and real-time data interfaces (
/api/token-stats/refresh,/api/token-stats/data). - Shares the
session/eventevent stream (v3, event-driven) with dsh-token-meter as the data source; refreshes no longer require a full log scan.
Client Half
- Registers a “Token Usage” entry at the bottom of the sidebar (above Settings).
- Web: Clicking opens
/token-statsin a new tab. - Desktop: Opens the dashboard in an in-app popup (iframe overlay); Electron shells intercept
window.openand only hand http(s) to the system browser, so desktop must use the in-app popup.
Core Features¶
Usage and Cost Display¶
The dashboard displays metrics related to three billing dimensions by provider/model: Cache Hits, Cache Misses, Output; and distinguishes between peak and off-peak unit prices. By default, it uses built-in unit prices for estimation, which can be modified per model in the dashboard “Prices” and saved in browser localStorage (key dsh-token-stats/pricing/v1). Upgrading the plugin will not clear these custom prices.
The page automatically polls and refreshes every 60 seconds and retains a manual refresh button.
Data Synchronization (v3)¶
The main path consumes the same session/event stream as dsh-token-meter, performing incremental upserts by session:turn:step; it is compatible with the assistant/chunk (0.1.x) and assistant/message, assistant/attempt (0.2.x) event forms. Starting from 0.2.0, billing for LLM retries: retries in the same turn/step append a #n key (e.g., 1:1#2), merging idempotently with old rollups.
Cold historical sessions: Prioritizes restoration from $DSH_HOME/token-stats-rollup.<profile>.json; otherwise, performs a one-time log scan; afterwards, only performs incremental re-parsing on session files where mtime/size has changed. Session logs match session[.<version>].jsonl[.zstd] (including session.jsonl.zstd, session.v3.jsonl.zstd, session.v4.jsonl.zstd, etc.).
Page data fetching priority: /api/token-stats/refresh (this plugin) → /api/refresh (standalone exe) → local token-usage.json.
Routing¶
| Path | Description |
|---|---|
GET /token-stats |
Dashboard page, data injected into window.__DSH_DATA__; uses compact popup layout when ?embed=1 or inside an iframe |
GET /api/token-stats/refresh |
Incrementally syncs and re-parses changed files, returns JSON |
GET /api/token-stats/data |
Reads from memory store, cache hit within 1 second |
In embedded mode (?embed=1 or iframe), headers and padding are more compact, stat cards adapt their column count, and “Usage Overview” and “Usage Trends” can sit side-by-side on wide screens.
Installation and Activation¶
The plugin runs with the permissions of the current DSH process; it is recommended to read the repository source code and MIT license before installing. The community directory SkillHub has no official affiliation with DeepSeek/Hunyuan, and is a third-party package within the “everything is a plugin” ecosystem.
If there is no dsh command, you can enter @shallbay/dsh-token-stats in Plugins → Add Plugin on the Desktop, or call resources\runtime\cli\bin\dsh.cmd in the installation directory.
Desktop:
dsh plugin --profile desktop add @shallbay/dsh-token-stats
Web:
dsh plugin --profile web add @shallbay/dsh-token-stats
After installation, you must restart the corresponding surface (the bundle is only read when the profile loads):
- Desktop: Fully exit and reopen the App; or toggle
dsh-token-statsoff and on in the Plugins page for hot loading. - Web:
Restart-Service dshweb.
The client module can be hot-updated; if there is no entry in the sidebar, force refresh first (Ctrl+F5).
Example of installing a specific version (version numbers in the README, subject to actual registry release):
dsh plugin --profile desktop add @shallbay/dsh-token-stats@1.2.0
View installed version:
dsh plugin --profile desktop why @shallbay/dsh-token-stats
npm view @shallbay/dsh-token-stats version --registry=https://registry.npmjs.org/
Typical Usage¶
- Install the plugin for the desktop or web profile using the command above and restart the surface.
- Click “Token Usage” at the bottom of the sidebar (above Settings).
- Web: View
/token-statsin a new tab; Desktop: View in the in-app popup, press Esc to close. - If costs do not match billing, adjust the peak/off-peak unit prices per model in the dashboard price table and save (locally persisted).
- Click manual refresh when the latest summary is needed, or wait for the 60-second automatic polling.
Upgrade and Uninstall¶
The package manager will not automatically upgrade installed versions; you must first remove then add, and then restart the surface as well:
dsh plugin --profile desktop remove @shallbay/dsh-token-stats
dsh plugin --profile desktop add @shallbay/dsh-token-stats
Uninstall example:
dsh plugin --profile desktop remove @shallbay/dsh-token-stats
dsh plugin --profile web remove @shallbay/dsh-token-stats
After restarting, the sidebar entry and /token-stats route will disappear. The following data will not be automatically deleted and requires manual cleanup:
| Data | Location |
|---|---|
| Usage Summary (Host Disk Write) | $DSH_HOME/token-stats-rollup.json, $DSH_HOME/token-stats-rollup.<profile>.json |
| Dashboard Custom Prices | Browser localStorage dsh-token-stats/pricing/v1 |
Use Cases and Notes¶
Who is it for
- Long-term running of multi-session agents on DSH, requiring Harness-level billed token aggregation and trends, rather than visual statistics per session.
- Hope to use peak/off-peak unit prices for rough RMB calculations and be able to modify prices per model in the dashboard.
- Unified entry for both Web and Desktop: Web new tab, Desktop in-app popup.
Common Questions (from README)
- No entry in sidebar: Ctrl+F5; confirm the profile’s
dsh.profile.bundlescontains@shallbay/dsh-token-statsand has been restarted. /token-stats404: Plugin not loaded, check the bundle andtoken-statserrors in host logs.- Numbers are all 0: Requires at least one event with usage; the first load of old sessions may trigger a one-time log scan for seeding.
- Cost deviation: Modify model unit prices in the dashboard price table.
For development or offline use, you can run install.ps1 from the source code (see repository README); do not manually append insert lines to cordis.patch.yml, persist via dsh.profile.bundles instead.
Conclusion¶
@shallbay/dsh-token-stats centralizes billed tokens and cost estimates within the Harness scope into /token-stats, and connects to the daily operation path via the sidebar “Token Usage”; the data side is aligned with the token-meter event stream and supports profile-level rollups and incremental refreshes.
- Directory Page: https://www.skillhub.cn/plugins/ShallBay/dsh-token-stats
- Source Code and Documentation: https://github.com/ShallBay/dsh-token-stats