dsh-token-optima: Token Attribution and Cache ROI Diagnosis in DSH

Preface

When running multi-turn conversations or agents with tools in DeepSeek Harness (DSH), the API returns usage data, but it is difficult to answer more granular questions: how many tokens a specific segment in the context consumes, whether prefix caching hits according to 64-token blocks, whether a specific tool result or assistant reply broke the cache, and how much the round actually cost (including peak/off-peak rates) and how much was saved by caching according to official rates. The community plugin dsh-token-optima (maintainer Boris-boomer), built on the Cordis plugin framework, addresses these diagnostic needs; it is neither a billing system nor a prompt compressor.

What is this

dsh-token-optima is a deep token monitoring plugin for DSH. Utilizing a 64-token block-level cache model and 14 attribution categories, it visualizes token allocation, cache hit status, and costs vs. cache ROI based on official DeepSeek rates for every request round. It is categorized under “Model Inference” capabilities; the repository is available on GitHub, and the community directory page is on SkillHub. The current package version is 0.5.0, licensed under MIT, requiring Node >= 22.0.0.

Key privacy points from the README: The plugin does not actively make external network requests and has no telemetry; it does not persist original prompts, reasoning, or tool results, using in-memory hashing for comparison only; the global debug object window.__tokenOptimaDebug is disabled by default; it only writes interface health diagnostic files to ~/.dsh/token-optima/, and failures do not block the main workflow.

Core Features

The capabilities listed below follow the README; data quality is categorized into three levels: Measured (API ground truth), Inferred, and Estimated.

14 Token Attribution Categories

Based on the coordinate model (source, cache_status, direction, is_reasoning), it breaks down tokens in a request round by dimensions such as source and cache status, facilitating composition review via the dashboard.

Real Costs & Cache ROI (Peak/Off-Peak Pricing)

Integrates official DeepSeek rates to calculate the total cost and cache savings for each conversation round. It identifies peak (weekdays 9–12, 14–18) and off-peak hours based on Beijing Time and supports historical cumulative statistics.

64-Token Block-Level Cache Modeling

Segments prefixes according to official 64-token storage units, tracking hits and misses; it can identify prefix breaks, context compression, and mid-surface replacements.

Intelligent Invalidation Attribution

When the cache is disrupted, it attempts to locate the source of the disruption (e.g., tool_result, assistant_msg), helping to troubleshoot “who broke the cache.”

Multi-Session & History Analysis

Users can switch sessions within the panel to view historical round details (cost per round, savings, hit rates, etc.).

UI & Charts

Provides dark/light themes, along with interactive donut composition charts and trend graphs.

Installation & Activation

The plugin is integrated into the DSH profile via a local link method. Installation steps are derived from the repository README.

  1. Add the dependency and bundle to the DSH profile’s package.json:
"dependencies": {
  "dsh-token-optima": "link:<plugin absolute path>"
},
"dsh": {
  "profile": {
    "bundles": [
      ...,
      "dsh-token-optima"
    ]
  }
}
  1. Run the installation in the profile directory:
cd <profile directory>
pnpm install
  1. Completely exit DSH (including the system tray) before restarting; otherwise, the new bundle may not take effect.

Please review the source code and the MIT license before installation; the plugin runs with the permissions of the current DSH process, same as other local plugins within DSH.

Enabling Exact Tokenizer (Optional)

By default, it uses a character-weighted algorithm to estimate tokens (the README claims ~80–90% accuracy). To mark attribution as exact (100% precise), the DeepSeek vocabulary must be loaded manually.

Step 1: Download Vocabulary Files

Download the following files (totaling approximately 7.8 MB) from HuggingFace to ~/.dsh/:

  • https://huggingface.co/deepseek-ai/DeepSeek-V3/resolve/main/tokenizer.json
  • https://huggingface.co/deepseek-ai/DeepSeek-V3/resolve/main/tokenizer_config.json

Step 2: Set Environment Variables

Windows (PowerShell); if launching DSH via the tray or shortcuts, write to user environment variables and completely restart DSH:

[Environment]::SetEnvironmentVariable('DSH_TOKENIZER_JSON', "$env:USERPROFILE\.dsh\tokenizer.json", 'User')
[Environment]::SetEnvironmentVariable('DSH_TOKENIZER_CONFIG', "$env:USERPROFILE\.dsh\tokenizer_config.json", 'User')

macOS / Linux: Add to ~/.bashrc or ~/.zshrc:

export DSH_TOKENIZER_JSON="$HOME/.dsh/tokenizer.json"
export DSH_TOKENIZER_CONFIG="$HOME/.dsh/tokenizer_config.json"

Step 3: Verification

Restart DSH and open the plugin panel; if the bottom status bar displays tokenizer: hf:... (exact), it indicates successful loading.

Typical Usage

Daily usage centers on the DSH embedded panel: after initiating a conversation, view the current round’s token composition, cache hits, and cost/savings; in multi-turn or tool-enabled scenarios, combine invalidation attribution to determine which message type caused the prefix cache break. To switch contexts, change sessions within the panel and browse the history round list and trend charts.

The repository’s examples/demo.ts can be run via pnpm demo (a dev-dependency command, see package.json scripts); general users should rely on the UI after enabling the profile bundle.

Use Cases & Notes

Suitable for developers already using the DeepSeek API on DSH who wish to optimize long contexts and caching strategies: needing to see where tokens are spent, whether cache ROI is reasonable, and whether invalidation points lie in tool or assistant outputs.

Notes:

  • Costs and ROI are based on the plugin’s built-in official rates and peak/off-peak rules, intended for diagnostics, not as a substitute for billing.
  • The optional dependency @huggingface/tokenizers is default; without configured vocabulary, attribution accuracy is on the estimation level.
  • The community directory SkillHub is an independent site and has no official affiliation with DeepSeek/High-Flyer; the DSH ecosystem philosophy is “everything is a plugin,” select as needed and review source code.

Summary

dsh-token-optima breaks down “where the tokens were spent this round and how much money the cache saved” to the block level with 14 attribution categories, completing statistics locally. Directory: SkillHub Plugin Page; Source code and full documentation: GitHub README.

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

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

Xiaoye