erya2000/dsh-session-budget-guard ↗★ 0
dsh-session-budget-guard
提供单会话树的Token消费额度与速率熔断器 适合需要严格限制单个会话或代理调用预算、防止模型无限循环跑飞扣费的用户。
安裝
$
npx -p @deepseek-ai/dsh dsh plugin --profile web add github:erya2000/dsh-session-budget-guard說明文件
閱讀完整 README ↗Configuration
Every key is optional; the defaults live in lib/rules.js. Unknown keys are
logged and ignored rather than silently dropped.
| Key | Default | Meaning |
|---|---|---|
mode | notify | notify = log + notify only. enforce = also refuse the next step, deny over-quota delegations/searches and stop the tree. |
enabled | true | Master switch. |
treeWarnCny | 20 | Warn once per tree at this cumulative spend. |
treeStopCny | 50 | Stop the tree at this cumulative spend. |
rateWarnPerMin | 4 | Warn when the tree grows faster than ¥4/min. |
rateStopPerMin | 8 | Stop the tree when it grows faster than ¥8/min. |
windowsSeconds | [60, 180] | Sliding windows used for the rate, in seconds. |
maxDelegationDepth | null (off) | Deepest allowed subagent depth. 1 means subagents may not spawn subagents. |
maxTreeNodes | null (off) | Most subagents allowed in one tree. |
maxSearchesPerSession | null (off) | Most web_search/web_fetch calls allowed per session. |
dailyWarnCny / dailyStopCny | 100 / 300 | Reported in warnings for the whole day across trees. |
stopStreak | 2 | Consecutive over-limit checks before acting. |
notifyCooldownSeconds | 300 | Minimum gap between notifications for the same tree. |
notify | auto | auto (macOS: osascript), none, or a shell command template containing {text}. |
exchangeRate | 7.2 | Used to convert the cost-meter ledger (USD) into CNY. |
statePath / logPath | $DSH_HOME/state/... | Where persistent state and the log live. |
A configuration tuned for enforcement (this is what the incident above led to):
config:
mode: enforce
treeWarnCny: 5
treeStopCny: 10
rateWarnPerMin: 1.5
rateStopPerMin: 3
maxDelegationDepth: 1
maxTreeNodes: 6
maxSearchesPerSession: 40