Introduction¶
In DeepSeek Harness (DSH) development or agent orchestration scenarios, models often cannot intuitively perceive the current session’s token consumption, remaining context window, or budget progress. This can lead to passive stop-loss only after the context is filled or the budget is exhausted. dsh-plugin-quota solves this problem by providing real-time meters and predictive algorithms, allowing the model to “see” its own resource consumption in every turn and support self-throttling.
Plugin Introduction¶
This is a client-side plugin designed to provide real-time token/cost meters for each turn and give estimates for the next step along with budget/context window consumption predictions. The model itself can see this information and thus autonomously control its output pacing. This plugin is maintained by 121212165 and is released under the MIT license.
Core Features¶
- Real-time Tracking: Monitors
session/event(assistant/message usage), accumulating the session’s input/output/cache-hit tokens in real-time after each model response. If a price table is configured, it also estimates costs (accumulated in micro-units). - System Prompt Injection: Provides the model with a one-line real-time meter each turn (e.g.,
Live: 13.8k tok / 50k ▰▰▰▱… · 5 steps · ≈0.0153 USD), so the model can directly see when the budget limit is exceeded. - /qm Panel: Enter
/qmto view the current session plus all today’s sessions combined, including budget progress bars (requiresbudgetTokensconfiguration) and over-budget warnings. - Next-Step Estimation: Provides token and cost ranges for the next turn based on historical data, as well as the number of steps required to fill the context or exhaust the budget.
- quota_meter Tool: The model can call this tool for self-checking, with results rendered as a generic card.
- Cross-Plugin Contract: Publishes budget and context status to other plugins in the family (e.g., task-forge) via
~/.dsh/quota/summary.json, without needing to understand session ID structure.
Installation and Activation¶
Install the plugin via the command line. After installation, restart dsh, and it works with default configuration (meter injection + /qm panel).
dsh plugin --profile <your_profile> add github:121212165/dsh-plugin-quota
After restarting dsh, enter /qm in the conversation to view the panel. If you need budget progress bars or cost estimation, you need to configure budgetTokens and prices.
Configuration¶
- Zero-config Ready: When no price and budget are configured, only token counts and step numbers are displayed.
- Price Configuration:
pricesmust be configured to estimate costs. - Budget Configuration:
budgetTokensmust be configured to display progress bars. - Context Window:
contextWindowmust be a positive finite number, otherwise an error will occur at startup.
Example configuration (place in the profile’s cordis.patch.yml):
budgetTokens: 0 # Per-session token budget, 0 = no progress bar
inject: true # Inject real-time meter into system prompt
prices: # Match by model id substring, estimate cost only on match
- match: space-bunny
currency: USD
perMillion: { input: 1, output: 2, cacheRead: 0.1 }
contextWindow: 128000 # Basis for full prediction; if omitted, this model only reports next-step estimates without calculating the fill point
Data Persistence and Contract¶
The plugin maintains three files under ~/.dsh/quota/ (or the directory where dataPath is located), all written atomically:
totals.json: The plugin’s internal ledger, formatted as{ <sessionId>: UsageTotals }.history.json: The most recent 64 steps ofStepUsage[]per session, used for predictions.summary.json: The family contract file, containing fields likebudgetTokens,contextWindow,stepsUntilFull,stepsUntilBudget. Other plugins can read this file to obtain session status.
Testing and Maintenance¶
This plugin includes 34 tests, covering pure functions (conversion, pricing, formatting, prediction models, contract fields) and assembly layer tests (real apply() with mock ctx, driven by real usage events). The codebase is released under the MIT license.
Use Cases¶
Suitable for DSH users or developers who need fine-grained control over costs and context windows. The plugin runs with the current dsh process permissions, so it is recommended to review the source code and license before installation.
Conclusion¶
By introducing dsh-plugin-quota, developers can achieve “model self-monitoring” in agent development, avoiding resource waste. For more details and source code, please refer to the GitHub repository.