dsh-usage-stats
A DeepSeek Harness (
dsh) Web plugin that adds a Usage stats button above the sidebar settings row, opening a full-page, zcode-style usage dashboard.
Track how you use the harness: tokens by day and by model, sessions, messages, active days, and an activity heatmap — all read from your own session logs, no third-party telemetry.
What you get
- Time-range switch — last 7 days / last 30 days
- Six metric cards — token usage, session count, message count, active days, current streak, most-used model (with share)
- Activity heatmap — 30 full weeks, bucketed into 5 levels by non-zero quantiles
- Daily token trend — per-model stacked bars (top 6 models + other) with legend
- Model usage — donut chart + breakdown list (share, tokens)
- Refresh button (bottom-right); close via Esc or the × (top-right)
Numbers are formatted the zcode way: 10.1亿 / 6178.2万.
How it works
| Half | File | Role |
|---|---|---|
| host | lib/index.js |
Hooks the sessionPersistence seam, scans session logs and folds them into daily/per-model summaries (in-memory index: full scan at boot + incremental every 60s); read-only loopback endpoint GET /api/usage-stats/usage?days=N |
| client | src/client.js → lib/client.js |
Registers a button in the sidebar.footer.action slot; react-dom portal full-page panel; hand-written SVG/DOM charts, no third-party deps |
Event-parsing semantics match TokenLedger (both usage chunks and assistant/message are received, same-(turn,step) samples replace each other, message counts ride on events), but no relay attribution — aggregation is per-model only.
Install (link, development)
npm install
npm run build # esbuild syntax-check src/client.js → lib/client.js
npm run link-profile # wire into ~/.dsh/profiles/web, then restart dsh web
link-profile does: add a link: dependency to the profile's dependencies, append to dsh.profile.bundles, and run pnpm install in the profile. Then restart dsh web (by convention, no auto-restart).
Verify
After restarting dsh web: a Usage stats row appears above Settings; DevTools console shows [usage-stats] bundle script executing / factory materializing. If the panel 404s or errors, check the host log for usage-stats: serving /api/usage-stats/usage.
Development
npm install
npm run build
npm test # node test/smoke.mjs — core contract smoke tests for both halves
npm run link-profile
License
MIT
No comments yet. Be the first to write one.