dsh-token-ledger: DeepSeek Harness Token Consumption Monitoring

Preface

The projection cache in DeepSeek Harness is primarily for display purposes, and the data may be delayed or incomplete. For scenarios requiring precise cost accounting or usage monitoring, directly reading the session logs is a more reliable choice. dsh-token-ledger was developed based on this need; it does not rely on the projection cache but instead directly parses local session logs to provide daily Token consumption statistics based on local dates.

What is it

This is a plugin maintained by doremifaso12345 for monitoring the daily token consumption of DeepSeek Harness. It provides four entry points—a settings page card, an input box badge, chat commands, and model tools—to help users intuitively understand their Token usage.

Core Features

Dashboard and Data View

The dashboard displays four non-overlapping usage buckets, all based on actual values reported by the Provider:
* Uncached Input: Input that did not hit the prefix cache.
* Cache Read: Input that hit the cache.
* Cache Write: Input written to the cache.
* Output: Completion output (includes reasoning, not counted twice).

Additionally, the following metrics are provided:
* Total: The sum of the four buckets.
* Cache Hit Rate: Calculated as Cache Read / (Uncached Input + Cache Read + Cache Write).
* Cumulative Tokens: The sum of all four buckets in history.
* Peak Tokens: The highest value for a single day.
* Maximum Chat Duration: Defined as “continuous activity duration,” which is the accumulated time where adjacent events have an interval of no more than 30 minutes, rather than the difference between the first and last timestamps.
* Activity Heatmap: A GitHub-style contribution graph showing consumption over 52 weeks × 7 days.
* Tool Ranking: Sorted by call count and success rate.

Interaction Entries

  • Settings Card: Settings → Token Ledger. Supports selecting 7/14/30/90/180/365-day windows and one-click CSV export (with BOM).
  • Input Box Badge: Displays today’s total (e.g., 1.23M) and the cumulative total for the last 7 days. It refreshes every 60 seconds and shows details on hover.
  • Chat Command: Quickly view reports via the /tokens command.
  • Model Tool: The token_usage tool allows Agents to directly query usage data.

Installation

The plugin requires no build step and is installed directly via command. Please ensure you use the correct Profile name (default is web).

dsh plugin --profile web add github:doremifaso12345/dsh-token-ledger

Please restart dsh web after installation.

Typical Usage

Chat Commands

Use the following commands in the chat box:
* /tokens: View the daily report and overview for the last 7 days.
* /tokens 30: View data for the last 30 days.
* /tokens today: View only today’s data.
* /tokens csv [days]: Export CSV to the harness home.
* /tokens help: View help.

Model Tools

Call the token_usage tool, passing in the days and includeSessions parameters.

Environment and Dependencies

Runtime Environment

  • Node.js: Must satisfy ^22.15.0 || >=23.8.0. This version range includes the Node built-in zlib.zstdDecompressSync API, which is used to decompress multi-frame zstd session logs. If the version is too low (e.g., 23.0–23.7), the plugin will throw an error directly to avoid displaying incorrect 0 data.
  • DeepSeek Harness: Target version 0.1.5-rc.2.
  • Data Source: <DSH_HOME>/sessions/<workspace>/<session>/session.v3.jsonl.zstd. The plugin automatically handles multi-frame zstd containers and replicates the semantics of the official projection (e.g., collapsed billing in retry scenarios).

Configuration

Adjustable in cordis.patch.yml:

- insert:
    - id: dsh-token-ledger
      name: 'dsh-token-ledger'
      config:
        enabled: true       # Master switch
        cacheTtlMs: 5000    # Result cache duration (milliseconds)
        root: null          # Explicitly specify harness home

Notes

  • Zero Third-Party Dependencies: The plugin uses only Node built-in modules and does not depend on @deepseek-ai/* packages. This means that as long as contract dependencies are not broken during host version upgrades, the plugin will continue to work normally.
  • Data Integrity: If the sessions directory does not exist or log decompression fails, the dashboard will display empty data rather than silently erroring.
  • Contract Dependencies: Before installation, ensure that the host has mounted services such as commands, tools, and webServer, otherwise some entry points will be unavailable.

Summary

dsh-token-ledger provides a complete Token consumption monitoring solution, with targeted designs ranging from data sources (session logs) to display formats (dashboards, heatmaps, exports). It addresses the potential issues of missing or inaccurate data in the projection cache, making it suitable for developers who need fine-grained management and cost accounting.

羽毛球分组比赛记分
小程序二维码

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

Xiaoye