dsh-token-ledger: Cross-Project Aggregation of DSH Billing Tokens

Introduction

When developing across multiple projects and sessions in DeepSeek Harness (DSH), each session generates a tokenUsage projection reported by the provider. However, these numbers are scattered across the session logs of various projects. Sub-agents and forked sessions also replicate parent session history. If you simply sum the “recorded values” of each session, the same billable call will be double-counted. This article introduces the community plugin dsh-token-ledger (maintainer u-fw, categorized under admin-security): it aggregates the real billing metrics per project across all session corpora within an installation and provides graphical panels in the settings page and sidebar.

What is this?

dsh-token-ledger is a DSH profile bundle, not a standalone program. Once installed into a profile, it reads the persisted session corpus of that profile to derive statistics on demand; it does not maintain a separate database. The host registers the HTTP route GET /token-ledger/summary, and the panel is a Web client. Therefore, the DSH Web service must be running to view the interface. The package declares Node >=22.15 (corpus testing relies on zstd decoding capabilities introduced in Node 22.15).

Core Features

Statistical Metrics

Each session’s tokenUsage contains four billing buckets (derived from usage reported by the provider per call, not heuristic estimates):

Field Meaning
uncachedInputTokens Input not hitting cache
cacheReadTokens Input read from cache
cacheWriteTokens Writes to cache
outputTokens Model output

The plugin groups data by session working directory (header.cwd) into “Projects,” then aggregates session counts, input/output, cache rates, etc.

Exact Mode vs. Fast Mode

The top of the panel allows switching between two modes:

  1. Exact (Default)
    For each session, it only counts events where seq >= inheritedEventCount, skipping the log prefix inherited from the parent session to avoid double-counting caused by forks or sub-agents. The first full scan takes about 3 seconds at the README’s example scale (approx. 120 sessions); subsequent runs perform incremental reads based on sessionPersistence.revision, typically taking around 100+ milliseconds. Clicking “Recompute” clears the cache and performs a full re-read.

  2. Fast
    Reads directly from ctx.sessionProjectionCache without reading logs, returning in about 60 milliseconds. It cannot deduplicate and lacks attribution by model routing; numbers are inflated, and the panel indicates this.

The README provides a comparison using the example corpus: direct summation results in approx. 3.0 billion tokens (inflated by ~70%), while deduplicated results are approx. 1.75 billion tokens.

Tables and Views

  • Project Table: Project, Sessions, Sub-agents, Inherited History, Input, Output, Tokens Consumed (labeled “Recorded Tokens” in Fast Mode), Cache Rate, Percentage; clicking the project name expands up to 50 session details.
  • By Model Route: Available only in Exact mode, attributing each call to the actual serving provider/model.
  • Time Filter: All Time / Last 30 Days / Last 7 Days (based on session creation time).
  • Export CSV: A session-level long table of the current view, with BOM, for easy opening in Excel.

The “Inherited History” column is based on the header’s isSeeded and differs in meaning from the “Sub-agents” column: manual forks are also counted as inherited history.

Entry Points

Entry Location
Sidebar Icon Global Panel Row (below Plugins), “Back to Conversation” in the top left
Settings Sidebar → Settings → “Token Statistics” (located after Models / Plugins / Agent Presets)

Both locations host the same component. The settings modal’s content area is narrower (approx. 564px); the plugin uses container queries to hide certain columns to avoid clipping. Full data remains available in hover tooltips and CSV exports.

Installation and Activation

Prerequisites: A working DSH installation on your machine (providing plugin_manager and dsh plugin) and a local checkout of this repository (see GitHub Repository).

There are two equivalent ways to install into a profile:

  1. Plugin Manager — Use plugin_manager’s install_bundle within DSH, pointing the target to the checkout directory; or perform the same action via the Web Settings → Plugins.
  2. Manual — Add the package directory as a profile dependency (set the package manager to link:) and list it in dsh.profile.bundles of the profile’s package.json.

Once installed, it appears in Settings → Plugins, where it can be disabled or uninstalled. The host side is registered via cordis.patch.yml; the client is loaded via declarations in the dsh.client field of package.json. You must restart DSH after modifying host code (due to ESM module caching).

The current package version is 0.1.0, License MIT.

Typical Usage

  1. Install and enable the bundle, ensuring the DSH Web service is running.
  2. Open Settings → Token Statistics, or click the Token Statistics icon in the sidebar.
  3. By default, use Exact mode to view deduplicated Input / Output / Tokens Consumed and Cache Rates per project; switch to Fast for a quick overview (note that numbers are not deduplicated).
  4. Use Last 7 Days / Last 30 Days to narrow the scope; click Recompute if you suspect cache inaccuracy (clicks within 5 seconds are throttled).
  5. In Exact mode, view the By Model Route table to compare cache rate differences across routes.
  6. Export CSV when offline analysis is needed.

Developers can run tests within the repository (local checkout required):

npm test              # node --test test/*.test.mjs
npm run verify:live   # Perform end-to-end acceptance testing against a running DSH

verify:live checks if the host has reloaded, if session folding matches the corpus, if incremental caching is effective, etc.; the address priority is --url, followed by the environment variable DSH_WEB_URL.

Use Cases and Caveats

Suitable for: Administrators or heavy users managing multiple working directories (projects) within the same DSH installation, needing to aggregate provider billable tokens per project, troubleshoot duplicate counting from forks/sub-agents, and compare model routing and cache hit rates.

Important Notes:

  • The plugin runs with the current DSH profile / process privileges and reads all persisted sessions of that installation. You should review the source code and the MIT license before installing to ensure trust.
  • Statistics are not a bill: They only reflect usage reported by the provider and do not include price calculations.
  • It only counts sessions whose logs are still on disk; sessions without a cwd are grouped into “(no project directory)”.
  • The route GET /token-ledger/summary is not protected by the DSH /api authentication gate (consistent with general behavior for DSH custom routes); the README notes that forced refreshes have a 5-second cooldown to limit misuse and loop requests.
  • Exact mode complexity is proportional to the total number of log bytes; the duration of a cold full read will increase linearly with very large session scales.

The DSH ecosystem emphasizes that “Everything is a plugin”; the SkillHub directory page is a community site and has no official affiliation with DeepSeek or High-Flyer.

Conclusion

dsh-token-ledger consolidates provider billable tokens scattered across multiple projects and sessions into a single panel. In Exact mode, it deduplicates inherited history to provide a clear view of real consumption and cache utilization. For further information and source code:

  • Directory Page: https://www.skillhub.cn/plugins/u-fw/dsh-token-ledger
  • GitHub: https://github.com/u-fw/dsh-token-ledger
羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye