Preface¶
When running long tasks, workflows, or fanning out subagents in DeepSeek Harness (DSH), costs can spike within a short period. The DSH core itself has no hard-coded switches like “cost caps” or “step limits”; cost-meter-style plugins commonly found in the market mostly provide display and color-coded alerts for budgets, without automatically stopping the current turn when overspending. Below we introduce the community plugin dsh-spend-guard (maintainer summmmerz), which uses a rolling time window + RMB threshold on the host side for alerts and circuit breaking, filling the gap of “can calculate money but cannot stop the bleeding.”
What Is This¶
dsh-spend-guard is a host-side plugin for DSH, categorized as admin-security. Current version 0.1.1 (MIT license, requires Node.js ≥ 20). It does not perform independent pricing; instead it polls the dsh-cost-meter ledger to calculate how much was spent in the “last N minutes” (default 10 minutes), and when thresholds are reached:
- Spending within the last 10 minutes reaches ¥1 → sends a Windows notification reminder;
- Reaches ¥2 → ends the current turn (same path as the GUI “Stop” button).
The plugin is listed in the SkillHub plugin directory; source code and documentation are at GitHub: summmmerz/dsh-spend-guard. SkillHub is a community-maintained plugin index site with no official affiliation to DeepSeek / High-Flyer.
How It Differs from Existing Approaches¶
The README compares the current ecosystem landscape; key points are as follows:
- DSH core: no cost/step limit switches whatsoever.
- dsh-cost-meter’s “budget”: displays by today/this month/cumulative/custom ranges; color changes at ≥80% warning and ≥100% overspend, but does not pause the task.
- Other budget plugins: for example,
dsh-budgetuses session/day/month + USD with a hardcoded peer range of<0.2.0;dsh-balance-trackeruses Yuan as the unit and cancels the current turn as its action, but its window is a calendar day, and it depends on a 0.1.x client package that was removed in dsh 0.2.0.
dsh-spend-guard’s combination is: rolling minute window + amount (Yuan) + stop the current turn, aimed at scenarios like “subagent/workflow short-time burnout.”
Core Feature: How “Spending in the Last 10 Minutes” Is Calculated¶
The plugin does not price on its own, but instead polls the differential of the cost-meter ledger (default path <DSH_HOME>/storages/cost-meter/ledger.json):
- Reads the ledger every
pollMs(default 10s); - Computes the delta of the daily aggregate value
days[<date>].costrelative to the previous poll; - Deltas are written into a ring window keyed by sampling time; the sum within the window is “spending in the last N minutes”;
- The currency follows the ledger:
pricingCurrency(default USD) × ledgerconfig.exchangeRate(default 7.2) = RMB Yuan, the same source as the numbers in the dsh-cost-meter UI.
field can be cost (including subscription conversion) or apiCost (pure API accounting).
Why Not Use Per-Session Details¶
In the ledger, days[date].sessions[] contains “per-session daily cumulative values”, which can be truncated on heavy-load days. The README records: a 2026-10-04 measurement showed that this array only retains 200 entries, covering only 42% of that day’s spending (33.95 / 81.17 Yuan); the missing 47.2 Yuan came from subagents — exactly the kind of consumption circuit breaking should most prevent. The daily aggregate is a complete measure under any load (including subagents), so the plugin only trusts aggregate deltas. test/window.test.mjs contains regression tests: when sessions is empty or entries are replaced/truncated, the window must still count correctly.
Detection latency: at most about pollMs + cost-meter write interval (default 10s each), usually acceptable for a 10-minute window circuit break.
Degradation: when the ledger cannot be read (cost-meter not installed, format changes, permission issues), it does not circuit break, only logs a warning every 5 minutes — when the cost cannot be calculated, it should not crash the harness.
Core Feature: How It Stops on Circuit Break¶
Stopping the current turn calls:
agent.cancel({ kind: 'user' }, { keepInbox: true })
Consistent with the GUI “Stop” button (the README points to the stop implementation in dsh-api-session-controller): it only ends the current turn, does not destroy the session, and queued inputs are preserved.
The default cancelScope: all ends all running agents (including subagents) — the goal of circuit breaking is to stop the bleeding immediately. If you only want to end the main session, set cancelScope: root.
Configuration¶
Default values can be overridden via the profile’s cordis.patch.yml (the plugin package ships its own cordis.patch.yml, see dsh.bundle.patch in package.json):
- id: dsh-spend-guard
config:
windowMs: 600000 # Rolling window (ms), default 10 minutes
warnYuan: 1 # Amount (Yuan) reached within window → reminder
stopYuan: 2 # Amount (Yuan) reached within window → end current turn
pollMs: 10000 # Ledger polling interval (ms)
field: cost # cost (including subscription conversion) | apiCost (pure API accounting)
exchangeRate: null # Exchange rate override; null = use the ledger's config.exchangeRate
warnCooldownMs: 60000 # Minimum interval (ms) between two reminders
stopCooldownMs: 60000 # Minimum interval (ms) between two circuit breaks; 0 = keep breaking while over limit
cancelScope: all # all=end all running agents (including subagents) | root=end only the main session
toast: true # Whether to send Windows notifications
debug: false # Print the window amount on every poll
ledgerPath: "" # Ledger path; leave empty = auto-locate
Disable the entire plugin:
- id: dsh-spend-guard
disabled: true
After enabling, a line like this will appear in the logs (path depends on the local machine):
[dsh-spend-guard] 已启用: 滚动 10 分钟, 提醒 ¥1.00 / 熔断 ¥2.00, 账本 <path>
Reminders and circuit breaks are prefixed with 提醒: / 熔断: respectively, for easy grep.
Installation and Enablement¶
The README does not provide a standalone dsh plugin add … installation command. The plugin package can be obtained per community convention from the SkillHub directory page or the GitHub repository, and installed into the profile following DSH’s Cordis plugin/bundle approach.
Prerequisites: dsh-cost-meter must be installed and running locally, with the ledger persisted continuously; otherwise the plugin only logs warnings and does not circuit break.
It is recommended to read the source code and the MIT license before installation: the plugin runs with the current DSH process permissions, reads the ledger, and calls agent.cancel when thresholds are exceeded.
Typical Usage and Self-Testing¶
No extra daily operation is needed: once the plugin is installed and cost-meter is running, it works with the defaults 10 minutes / ¥1 reminder / ¥2 circuit break. To change thresholds or only break the main session, just modify the cordis.patch.yml from the previous section.
The repository includes window logic tests:
node test/window.test.mjs
Or via the npm script:
npm test
Test coverage: baseline established on first poll, counting by daily aggregate deltas, ¥1 reminder / ¥2 circuit break, regressions when sessions[] is empty or truncated, no erroneous circuit break across days, no negative deltas from aggregate rollback, cancelScope semantics, and that circuit breaking must go through cancel({ kind: 'user' }, { keepInbox: true }).
Suitable Scenarios and Known Boundaries¶
Suitable for: developers who run DSH locally for extended periods, frequently trigger workflow/subagent fan-outs, and want a hard stop of the current turn on a “last few minutes” dimension.
Notes:
- Depends on dsh-cost-meter; when not enabled, it silently does nothing (only logs).
- Window precision is limited by the polling interval (default ~10–20s).
- Only counts spending within the DSH ledger; consumption from other terminals or web pages is not in the window.
- The default circuit break interrupts all running turns (including subagents); for parallel multi-session use where you don’t want collateral interruption, use
cancelScope: root.
Conclusion¶
dsh-spend-guard turns the existing cost-meter ledger into a guard that “can alert and can stop the turn” using a rolling window, defaulting to ¥1 notification / ¥2 circuit break, and deliberately uses daily aggregate deltas to avoid undercounting subagents when sessions[] is truncated. Directory page: https://www.skillhub.cn/plugins/summmmerz/dsh-spend-guard; source code: https://github.com/summmmerz/dsh-spend-guard.