Introduction¶
DeepSeek Harness (DSH) adopts a plugin-based architecture. During development or long-term usage, developers often need to track token consumption and costs across sessions. This plugin adds a “Token Statistics” section to the DSH settings page and provides a resident floating window. It does not rely on external services; instead, it aggregates data by reading local session logs, achieving usage monitoring with zero model consumption.
Core Features¶
Resident Floating Window¶
A floating window is docked at the bottom right by default, allowing you to check today’s usage at any time.
-
Four States
- Adsorbed: A slim bar attached to the edge, showing only the running status dot and vertically stacked “Today” numbers.
- Collapsed: A small horizontal bar showing the name, gear icon, status dot, and today’s numbers.
- Floating: A full card containing the collapsed state content, a heatmap, and a legend.
- Full History Panel: An independent overlay displaying the annual heatmap and summary metrics.
-
Interaction Methods
- Hover: In the Adsorbed state, hovering allows for a preview; in the Collapsed/Floating states, hovering over a block shows the input/output/cache details for that day.
- Double Click: Expands from the Adsorbed state to the Floating state; double-clicking in the Floating state returns to the Collapsed state.
- Drag & Resize: Drag anywhere on the card to move it; drag the bottom-right handle to resize.
- Annual History: Hovering over the title bar for approximately 160ms expands the full history panel.
- Click Block: After selecting a date, the main numbers switch to that day’s values, labels update, and a “Back to Today” button appears.
-
Runtime Status
- When a session is running, the card’s border presents a blue breathing effect; if the system “Reduce Motion” setting is enabled, this degrades to a steady blue border.
- The window automatically docks: it minimizes to the Adsorbed state when the window is not maximized, and restores to the full card when maximized.
Settings Section¶
The “Token Statistics” section in the settings page provides comprehensive usage analysis.
-
Top Metric Cards
- Consecutive Days: Current consecutive usage days / Max consecutive days.
- Total Tokens: Follows the value of the selected tab period (Daily / Weekly / Monthly / Cumulative).
- Peak Tokens, Longest Single Turn Duration: Linked with the tab and section.
-
Token Activity Heatmap
- Supports four time tabs: Daily, Weekly, Monthly, and Cumulative.
- Unused periods display as hollow squares; used periods are filled with colors adapted to actual usage quartiles.
- Hovering over a square displays a bubble with details for that period.
-
Model Usage Distribution
- Displays model rows and a donut chart.
- Shows cache hit rate (consistent with OpenAI’s metric).
- Hovering over a model row displays input/output/cache details.
-
Performance Timeline
- Displays duration, tool call count and duration, Time to First Token (TTFT), and output speed.
Cost Estimation¶
Click “Cost Pricing Configuration” to set model prices.
-
Base Pricing
- Each model can be configured with four price types: Input, Output, Cache Read, and Cache Write (Unit: Currency/Million tokens).
- Supports specifying currencies; totals are calculated separately for each currency.
-
Time-based Pricing (Peak & Valley)
- Multiple price tiers can be added; each tier includes the four prices and a bound time slot.
- Supports time slots crossing midnight (e.g., 22:00–06:00).
- Supports specifying the effective range by day of the week.
-
Historical Pricing
- Records historical price versions; calculates costs for specific days based on the effective start date.
-
Shared Pricing
- A single pricing entry can be applied to multiple model keys.
Plan Quota & Budget Alerts¶
-
Plan Quota
- Supports setting scope (All Models / Provider Prefix / Specific Model) and unit (Calls / Tokens / Cost).
- Subdivides quotas by model; the summary row shows the total usage rate.
-
Budget Alerts
- Supports setting daily budgets (based on both Cost or Tokens).
- On days exceeding the limit, heatmap blocks are marked with a red circle, and an alert bar appears at the top.
Session Drill-down¶
After clicking a heatmap block, it displays the top 10 sessions with the highest consumption in that time block.
- Main / Sub-agent View
- Comprehensive: Only lists main sessions; sub-agents are collapsed.
- All: Main and sub-agents are mixed together.
- Main Conversation: Only lists main sessions.
- Sub-conversation: Only lists sub-agent sessions.
- Session Details
- Displays the session name (workspace/UUID or title).
- Hovering displays the full directory name and input/output/cache details.
- Provides buttons to copy the session name and ID with one click.
Export¶
- Export CSV: Daily series as one row per day, with UTF-8 BOM.
- Export JSON: Contains
totals,days,models; supports dual-currency costs.
Installation & Prerequisites¶
-
Environment Requirements
- DSH version must be
>=0.1.7-alpha.1 - Node.js version must be
>=22.15
- DSH version must be
-
Data Dependencies
- The plugin depends on local session logs:
$DSH_HOME/sessions/**/session.l.zstd(old format) andsession.v3.jsonl.zstd(new format). - The configuration file is located at:
$DSH_HOME/token-stats.cfg.json.
- The plugin depends on local session logs:
-
Installation Method
- Place the plugin code into the DSH plugins directory (specific path depends on DSH configuration, usually
~/.dsh/plugins/or similar structure).
- Place the plugin code into the DSH plugins directory (specific path depends on DSH configuration, usually
Typical Usage¶
- View Today’s Usage: Hover over the floating window at the bottom right to check today’s numbers.
- Switch Dates: Double-click the floating window to expand it, then click a block in the heatmap to view usage for a specific date.
- Configure Pricing: Click the gear icon on the floating window title bar, or go to the “Token Statistics” section in the settings page to configure model input, output, and cache prices.
- View Model Distribution: Check the usage proportion and cache hit rate of each model in the settings page.
- Export Data: Click the “Export CSV” or “Export JSON” buttons in the settings page to save statistical data.
Notes¶
- Zero Model Consumption: The plugin does not register any tools or initiate LLM calls during runtime; all data is read from local logs.
- Real-time Performance: Data updates are near real-time (second-level); affected by log flushing latency, there may be a delay of a few seconds.
- First-time Parsing: Opening the section on first installation or when there is no cache requires a full parsing of historical logs, taking approximately half a minute.
- Configuration File: Cost configurations (pricing, plans, colors) are ultimately written to
$DSH_HOME/token-stats.cfg.json. You can edit this file directly and refresh the page to apply changes.