dsh-turn-cost: Displaying Cost and Context Usage Per Turn in the DSH Web Interface

Preface

DeepSeek Harness (DSH) runs locally, with conversations billed by token. In the default Web interface, you typically only discover the total cost after the billing cycle ends, making it difficult to correlate which “turn” or “long conversation segment” consumed the most money. As the context grows, there’s also no per-turn occupancy indicator tied to each response. The community plugin dsh-turn-cost (maintainer: xinshang777, category: client) extends the timestamp next to each assistant reply to show “context percentage · estimated cost for this turn · original timestamp”, and performs local estimation based on DeepSeek’s official peak/off-peak price list. Below is what it does, how to install, how to use, and its scope of applicability.

What is this

In one sentence: it turns “how much this turn cost” into a concrete number next to the reply timestamp (e.g., ¥0.0123), and displays the context occupancy at the end of that turn before the amount (e.g., 28%). Clicking the percentage triggers /compact via DSH’s official command.

The plugin only displays, does not intercept spending; values are estimates from token × price list, not reconciled with official bills. Data and ledger are stored locally; the plugin itself does not make external requests.

Core Features

Per-turn cost

Subscribes to usage events produced by the DSH runtime, uses lib/pricing.mjs to determine peak/off-peak by event time, writes to the local ledger ~/.dsh/dsh-turn-cost/turns.json, and the frontend assets/client.js mounts on the same node as the native timestamp. By default, only prices DeepSeek-family models (provider or model name contains deepseek); other models show as ¥0.0000 unless priceUnknownProviders is enabled in configuration.

Context occupancy and compression

Displays the context occupancy percentage at the end of each turn before the amount (showContext defaults to true). Clicking the percentage number triggers /compact through the official command path, equivalent to manually typing that command; default timeout is 120 seconds (compactTimeoutMs).

Historical session backfill

When backfill is enabled (default true), it uses DSH’s sessionPersistence to backfill historical sessions. When switching back to an old session, previous turns also display amounts. Peak/off-peak is still calculated by the event time of each turn.

Visibility rules (aligned with DSH)

The amount shares the same visibility rules as the native timestamp: the last turn in the timeline is always visible; other turns only show when the mouse hovers over that turn. This is intentionally aligned with DSH’s upstream interaction, not a defect.

Installation and Activation

Prerequisites

  1. Node.js ≥ 18
  2. pnpm (the remaining parameters of dsh plugin are forwarded to pnpm as-is; if missing, first npm i -g pnpm)
  3. DSH installed and dsh web available
  4. If primarily using DeepSeek-family models, non-zero amounts will be visible by default

Run in the terminal:

dsh plugin --profile web add github:xinshang777/dsh-turn-cost

After successful installation, the plugin will be registered in the profile’s dsh.profile.bundles; no manual bundle configuration changes are needed. A full restart of dsh web is required after new installation or uninstallation. If amounts are not visible in the browser, try a hard refresh (Ctrl + F5).

30-second verification

Open dsh web, ask any question. If ¥0.xxxx appears next to the timestamp below the reply, it’s working (the last turn is always visible, other turns are visible on hover).

If still no amount, check in order: whether ~/.dsh/profiles/web/package.json’s dsh.profile.bundles contains dsh-turn-cost; whether dsh web was fully restarted; whether that turn used a DeepSeek-family model.

For local development, Download ZIP, etc., see the repository README; after changing profile configuration, restart dsh web; if only changing assets/client.js, a hard refresh is sufficient.

Typical Usage

  1. Check costs: After installation and restart, refresh the page and chat normally; the last turn’s amount is always visible, historical turns are visible on hover.
  2. Compress context: Click the percentage (e.g., 28%), wait for /compact to complete (default up to 120 seconds). If ineffective, first verify whether manually typing /compact works in that session.
  3. (Optional) Adjust display and ledger: Edit ~/.dsh/profiles/web/cordis.patch.yml, adjust under dsh-turn-cost’s config:. Note that the profile-level config is a full replacement; if you only write some fields, others fall back to plugin defaults. After changes, restart dsh web.

Common configuration example (for field meanings, see the configuration table in the repository README):

# ~/.dsh/profiles/web/cordis.patch.yml fragment illustration
dsh-turn-cost:
  config:
    showContext: true
    priceUnknownProviders: false
    backfill: true
    ttlDays: 30

If you want all turn amounts to always be visible, you can inject CSS yourself (the cost is that all action buttons for that turn will also always be visible, which differs from DSH’s default):

[data-actions-reveal=hover]:has([data-dsh-turn-cost]) .xzv4MW_actions { opacity: 1 }

Use Cases and Considerations

Who it’s for

  • Pay-per-use or monthly billing, want to see which turn or which conversation segment burned the most money
  • Long conversations, need per-turn context occupancy hints
  • Care about whether questions fall in peak or off-peak periods (estimated by official peak/off-peak prices)
  • Often forget to manually /compact, want to click the percentage to compress

Who it’s not for

  • Flat monthly subscription and completely unconcerned about per-turn costs
  • Primarily use non-DeepSeek models and don’t want to enable priceUnknownProviders (not priced by default)
  • Need budget caps, interception, or precise reconciliation with official bills — should use service provider backend reports; this plugin is only for trend and anomaly reference

Security and permissions

DSH plugins run with the current dsh process permissions. Before installation, it’s recommended to read the GitHub repository source code and MIT license to confirm behavior matches your environment policy. The ledger and configuration are under ~/.dsh/. To uninstall:

dsh plugin --profile web remove dsh-turn-cost

Optionally delete the data directory ~/.dsh/dsh-turn-cost/.

Known limitations

The price list is a static copy (README explains it’s copied from dsh-whale-widget@0.3.15); after official price changes, lib/pricing.mjs needs manual updating; holiday off-peak price lists need annual maintenance. When co-enabled with dsh-per-turn-isolation, changes in percentage semantics after compression are normal.

Conclusion

dsh-turn-cost brings the estimated cost and context occupancy of each conversation turn in DSH Web next to the timestamp, and supports clicking the percentage to trigger /compact, making it suitable for granular observation of token costs on local DSH. The community plugin directory is independent of DeepSeek / Huanhuan and is not an official app store.

  • Directory page: https://www.skillhub.cn/plugins/xinshang777/dsh-turn-cost
  • GitHub: https://github.com/xinshang777/dsh-turn-cost
羽毛球分组比赛记分
小程序二维码

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

Xiaoye