Preface¶
The core design philosophy of DeepSeek Harness (DSH) is “Everything is a Plugin.” When running long-duration agent tasks, budget runaway or sudden task interruptions without records are common pain points. ziostudio/dsh-budget-handoff is a Session budget brake plugin that calculates consumption in real-time based on the official price list, stops execution when the budget is exhausted, and leaves a recoverable handoff snapshot.
Installation and Activation¶
Installing this plugin requires specifying a profile. You need to restart DSH after installation is complete.
dsh plugin --profile <your_profile> add dsh-budget-handoff
If you see a missing peer warning during installation, this is structural noise and does not affect usage. If you need to pin a specific version, you can append the version number to the end of the command.
Core Functions¶
This plugin provides the following capabilities:
- Billing by Official Price List: Monitors every call and calculates costs against the official price list.
- Budget Exhaustion Interception: Immediately stops task execution when the session budget is used up.
- Handoff Snapshot: Generates a snapshot file containing context, file changes, and progress upon interception to facilitate subsequent recovery.
- Budget Management: Supports setting, querying, and temporarily increasing budgets.
- 80% Warning: Issues a reminder when consumption reaches 80% of the budget, but does not stop the task.
Usage¶
Basic Commands¶
Send the following commands in the DSH session (case and space insensitive):
/budget 5: Sets the current session budget to 5 CNY./budget: Queries the current remaining budget and the amount used./budget 20: Increases the budget cap (must be greater than the amount already spent).
If not set, the default budget for each session is 10 CNY.
Budget Management Details¶
- Format Validation:
/budget abcwill explicitly prompt a format error and provide usage instructions. - Lower Bound Limit:
/budget 0or/budget -1will be rejected; the lower limit is0.0001CNY. - Cross-Session Isolation: Budgets in different sessions do not affect each other.
Warning and Interception Mechanism¶
- 80% Warning: When the used amount reaches 80% of the budget, the plugin sends a reminder stating the remaining amount and the estimated interception point. The task continues to run, and this reminder is triggered only once per session.
- 100% Interception: When the budget is truly exhausted, task execution is stopped. In this case, the CLI exit code is 1.
Handling After Budget Exhaustion¶
1. Generate Handoff Snapshot¶
When the budget is exhausted, the plugin generates two files locally:
<your_working_directory>\BUDGET-STOPPED-handoff-snapshot.md<$DSH_HOME>\storages\dsh-budget-handoff\last-stop.md
The snapshot contains the following information:
- Generation time and Session ID.
- Trigger location (turn/step).
- Cumulative consumption vs. budget comparison.
- Task goal description.
- Current progress (working directory, number of replies, recent actions).
- Files modified.
- How to continue (recovery steps).
2. Resuming Tasks¶
To continue previous work, the following conditions must be met:
- Increase Budget: Use
/budget <new_amount>to increase the cap; the new amount must be greater than the amount already spent. - Input Command: Send the command
继续(Continue).
Since the handoff snapshot has been injected into the model context, the model can continue execution based on this breakpoint without starting from scratch.
Configuration¶
To modify the global default budget, add configuration to the profile’s cordis.patch.yml:
- insert:
- id: dsh-budget-handoff
name: dsh-budget-handoff
config:
budgetCNY: 20.0
Configuration options:
* budgetCNY: Budget per session, unit is CNY, default 10.0, lower limit 0.0001.
* verbose: Whether to output usage per entry to stdout, default false.
Billing Rules and Limitations¶
Billing Coverage¶
The plugin only covers specific models under the deepseek-official provider:
* deepseek-flash
* deepseek-v4-pro
* deepseek-v4-flash
* deepseek-v4-flash-vision-exp
If other providers or models are used, the plugin cannot calculate charges, and a budget protection failure prompt will appear.
Price List and Time Slots¶
Prices are based on src/pricing.json, with units in CNY / million tokens. Includes Cache Hit/Miss and Peak/Off-Peak price tiers.
- Peak Hours: Beijing Time (UTC+8) Monday to Friday
09:00–12:00,14:00–18:00. - Off-Peak Hours: Times outside of peak hours (including weekends).
- Holiday Handling: The plugin does not model public holidays. Holidays during the day will be billed at peak prices (2x), which may cause the budget to run out prematurely.
Known Limitations¶
- Single-step sessions will not trigger interception: The gate takes effect “before the next step starts.” If a session has only one step, it ends immediately after execution and will not trigger interception.
- No cross-process accumulation: Cumulative consumption and budget are memory values; they reset to zero after a process restart.
- Prices do not update automatically: Official price adjustments require manual modification of the configuration file and a rebuild.
Directory and Source Code¶
- SkillHub Directory: ziostudio/dsh-budget-handoff
- GitHub Repository: ZiOstudio/dsh-budget-handoff