ParticleLight/dsh-all-usage ↗★ 5
dsh-all-usage
DeepSeek Harness usage dashboard with model, provider, workspace, cache, balance, and CSV insights
安装
$
npx -p @deepseek-ai/dsh dsh plugin --profile web add github:ParticleLight/dsh-all-usage说明文档
阅读完整 README ↗dsh-all-usage
中文
DeepSeek Harness 全量用量看板:按模型、供应商、工作区和时间范围分析 Token、缓存与账户余额。
功能
- 热力图:53 周使用热力图;按工作区筛选并查看每日回合与 Token 明细
- 模型统计:支持混合查看、按模型合并、按供应商汇总三种维度,展示调用次数、各类 Token 与缓存命中率;模型行与筛选下拉显示真实厂商品牌 SVG 图标(未知/混牌保持中性)
- 摘要与工作区:Token 用量、缓存命中、估算成本、账户余额、连续使用、工作区 Token 分布和明细
- 成本统计:从 models.dev 同步模型价格;按输入、输出、缓存读取和缓存写入四个桶计算,保存价格快照,明确区分已计价、免费模型和未计价调用
- 导出:按当前时间范围和模型聚合方式导出 CSV
- 时间范围:今日、近 30 天、近 90 天、全部,或在全部可扫描历史日数据中自定义起止日期;热力图始终展示最近 53 周
- 工作区别名:在侧栏入口打开看板后管理,持久化保存到 $DSH_HOME/storages 的 KV 单元
all_usage_aliases - 界面语言:在看板顶部切换中文与 English;选择会保存到浏览器本地
- 完整历史与增量重建:基线扫描全部可读历史会话;独立用量账本同时作为每会话游标——未变化的会话直接复用账本,新增事件只增量回填,长历史重启不再全量重建
- 重启免读:用持久化日志的 revision 作为每会话的变更信号(只读头部行 + stat,不读全量)——日志未变的会话重启时连事件都不读,直接从账本复用;仅日志变化(新增/修改)的会话才做增量读取
- 数据健康与按需刷新:扫描完成后浏览器只检查轻量状态版本,只有用量、别名或同步状态变化时才拉完整历史;显示本次数据更新时间、历史扫描健康、revision 免读、实际读取、账本恢复和失败,网络异常保留上次成功数据并可重试
- 工作区注册同步:监听 DSH 的
domain/changed事件自动跟随工作区注册表——注册表一有改动(创建/删除/重命名/重排/归档/成员变化)就重读workspaceRegistry.list();只对新增/删除的工作区做增量处理,未变化的已有工作区直接复用已计算账本(零重扫)。统计严格限定已注册工作区:未注册 cwd(含存在但未登记目录)一律忽略 - 性能优化:Host 在 ingest 时维护 local/UTC 的日期、工作区、模型身份日级 cube 与单日小时桶;scope 查询按 bucket 合并,成本使用精确 BigInt 小数累加,53 周热力图只生成实际需要的字段,并继续使用 revision-scoped snapshot/records 缓存和可回收的实时事件队列;Client 将热力图、tooltip、趋势、环形图、请求日志和定价对话框隔离为 memoized 边界,指针坐标通过 ref + requestAnimationFrame 更新,不再触发整页重渲染;浏览器入口在打包前确定性压缩
- 趋势折线图:按当前范围、时区、工作区、供应商和模型显示输入、缓存读写、输出、推理及总处理量;单日范围按小时聚合并显示小时轴,跨日范围按日聚合;使用平滑单调曲线与入场动画,悬停查看精确值,图例可切换曲线,点击点位进入当日明细
- 统一筛选与审计:工作区、供应商、模型和日期筛选贯穿摘要、热力图、趋势、表格与 CSV;工作区、供应商、模型三个筛选维度可独立自由组合,工作区、供应商和模型选项只展示当前日期范围内实际使用过的值;切换范围后失效筛选会自动清除;请求日志以紧凑分页表常驻显示,选择单条后查看分组 Token 详情
- Token 口径:输入按「未含缓存命中」计,缓存命中 / 写入与推理独立成桶;全 0 用量的重放事件不会覆盖已记录的真实用量,仅缓存命中的请求也会计入
- 成本口径:模型价格来自 models.dev 的 USD / 1M Token 目录;成本快照按 DSH 已归一化的 fresh input 和四类价格桶计算,倍率只作用于最终总价,已有正成本历史不会因价格更新重算;只按模型选择官方厂商条目,未找到官方价格时显示为未计价
兼容性与已知限制
- 运行环境:需要 Node.js `>=22 =0.1.1-rc.1 =0.1.5-rc.1 =22 =22 =22 =22 =22 '
-
在 $DSH_HOME/profiles/web/cordis.patch.yml 添加一行:
- insert: - id: all-usage name: dsh-all-usage
用户 patch 层会被热重载:保存后刷新页面即可。
架构
- Host 端(入口
lib/index.js,组装lib/plugin.js):按职责拆分为aggregation.js(聚合与查询)、ledger.js(持久账本)、session-sync.js(历史/实时同步)、pricing-runtime.js(运行时定价)、balance.js(余额)、http.js(安全路由);扫描turn/end、assistant/chunkusage 和最终assistant/message.usage,监听session/event实时折叠,并通过webServer服务注册数据路由:GET /api/all-usage— 兼容统计快照GET /api/all-usage/status— 轻量 revision 与同步健康状态GET /api/all-usage/query— 按 scope 返回聚合、daily/hourly 趋势和 heatmap 数据;单日 scope 填充hourly,跨日 scope 的hourly为空GET /api/all-usage/records— 按 scope 分页返回脱敏 canonical usage rowsGET /api/all-usage/balance?force=1— 账户余额(复用llm-deepseek的 API Key 配置)POST /api/all-usage/alias— 设置工作区别名GET /api/all-usage/pricing— 查看 models.dev 同步状态、已用模型匹配和显式覆盖GET /api/all-usage/pricing/models?q=...— 检索官方模型 ID 与名称匹配结果POST /api/all-usage/pricing— 保存同步、mapping 和显式价格覆盖(含 context tier 档位)POST /api/all-usage/pricing/sync— 手动同步 models.dev 并回填未计价调用
- Client 端:可读源码位于
src/client.js,npm run build:client使用固定版本 Terser 生成window.__ModuleLoader__工厂格式的lib/client.js浏览器 bundle,并注册侧边栏「用量统计」入口(sidebar.footer.action槽位)。所有 API 仅接受本机 loopback 请求并拒绝显式跨域请求;余额读取与别名写入还要求插件启动时生成、仅在当前进程有效的令牌(余额 GET 兼容浏览器省略 Origin)。英文模式的日期分桶、范围筛选、连续使用、热力图和导出时间统一按 UTC;中文模式按本地时区。
数据说明
- 使用次数与 Token 来自 DSH 会话日志;
session/flush只在存在新的相关事件时重建并将派生账本写入异步队列,同一 session 的 pending record 会合并,插件退出时 drain;插件激活时会回填日志与账本历史,插件卸载/重启后已成功持久化的数据不丢 - 按日范围统计会保留全部可读取历史会话的有使用记录日期;热力图仅作为最近 53 周的固定视图窗口
- 会话删除后,已成功 flush 的用量仍从独立账本恢复;工作区删除同样不会丢数据——其历史用量汇总为一行「已删除」(含未落账的实时用量)。会话销毁提示和周期对账只负责触发重建,不会删除账本记录
- 同一会话的同一
turn / step只保留一份最终 usage;重试或替换消息会替换旧贡献,不重复累计 - 输入 Token 按「未含缓存命中」计(缓存命中 / 写入独立成桶);全 0 用量的重放事件不会覆盖已记录的真实用量,纯缓存命中的请求仍会计入
- 轻量状态接口只公开 Host 实例、统计 revision、扫描进度与同步计数,不公开会话 ID、工作区路径、提示词或回复正文;完整快照仅在状态变化或手动刷新时获取
- scope query 将回合(turns)、模型调用(calls)和去重会话(sessions)分开统计;Provider/模型筛选缺少路由信息时明确归为 Unknown,不从展示字符串猜测
- records 接口只返回短 hash、时间、工作区 ID、结构化模型身份、turn/step、Token buckets 和当前物化来源,不返回原始 session ID、路径、提示词、回复或凭据
- 看板中的总处理量 = 输入 + 输出 + 缓存读写 + 推理;缓存命中表示复用的上下文 Token,不等于新生成 Token 或实际费用
- 成本计算沿用 cc-switch 的四桶公式:输入、输出、缓存读取和缓存写入分别乘每百万价格,四项相加后再乘倍率;context tier 在输入上下文严格大于阈值时为整次请求切换四项费率,不做渐进分段;DSH 的 reasoning 字段不再次加到 output,避免底层 completion/thoughts 已含推理时重复计费
- 历史账本中带
tiered标志的旧 flat 成本会在加载升级时迁移为unsupported(tiered-pricing-not-modeled),不再继续显示为当前精确 priced;Token 统计不受影响。 - 价格同步默认关闭;models.dev 不可用时保留最近一次成功目录,未匹配模型不会套用默认价格;成本设置可展开查看官方档位,并为显式 override 增删 context tier;看板范围与明细视图保存在浏览器本地,6 小时自动同步开关会立即写入受保护的 pricing API
- Mapping 语义:带
identityKey的 mapping 只对精确路由身份生效;不带身份键的 mapping 才按模型做全局回退;旧配置中的usageIdentityKey会在加载时归一化。 - 余额查询走 DeepSeek 官方
/user/balance接口;未配置 API Key 时卡片显示引导文案 - 账本按 session ID 稳定 hash 到 32 个 JSON shard,单次 flush 只重写对应 shard;旧的
all_usage_ledger.json会在首次加载时迁移,异步写失败或退出前未落盘不会丢失内存统计,只会让下次启动重新扫描 - 仅统计能归属到已注册工作区(按会话 cwd 匹配)的会话
开发
- 修改
src/client.js后先运行npm run build:client,再让 DSH 重载客户端模块并刷新页面;lib/client.js是生成产物,不直接编辑。修改lib/plugin.js或其他 Host 模块后,需由 DSH 重载该包或重启进程 - 插件无第三方运行时依赖:Host 端只使用 Cordis 服务,Client 端只使用 runtime 提供的 React 模块;Terser 仅作为固定版本开发依赖生成浏览器产物
- 手动恢复 npm 发布时,GitHub Actions 要求输入目标
vtag 和完整 commit SHA,并在 checkout 后校验 tag、SHA 与包版本一致;Release 事件同样执行 commit 校验。
English
A full usage dashboard for DeepSeek Harness. Analyze tokens, cache behavior, estimated cost, account balance, and activity by model, provider, workspace, and time range.
Features
- Heatmap: a 53-week activity heatmap with workspace filters and daily turn/token details
- Model analytics: mixed view, model-merged view, and provider summary with calls, token categories, and cache hit rate; model rows and the model filter dropdown render vendor brand SVG icons (neutral for unknown or mixed brands)
- Summary and workspaces: processed tokens, cache hits, estimated cost, account balance, usage streaks, workspace distribution, and details
- Cost statistics: sync model prices from models.dev, calculate four cost buckets, persist price snapshots, and distinguish priced, free, ambiguous, and unpriced calls
- CSV export: export data using the selected time range and aggregation mode
- Time ranges: today, last 30 days, last 90 days, all time, or a custom start/end date across all available historical daily data; the heatmap always shows the latest 53 weeks
- Workspace aliases: manage aliases from the sidebar dashboard; values persist in the $DSH_HOME/storages KV cell
all_usage_aliases - Interface language: switch between Chinese and English from the dashboard header; your choice persists locally in the browser
- Full history & incremental rebuild: the baseline scans every readable historical session; the durable usage ledger doubles as a per-session cursor, so unchanged sessions are reused straight from the ledger and only newly appended events are folded — long histories restart without a full rebuild
- Restart with no re-read: the persisted log revision (a header-line + stat via
sessionPersistence.listSnapshots()) acts as a per-session change signal — sessions whose log is unchanged are applied from the ledger on restart without reading their events at all; only changed/new sessions are read incrementally - Workspace registry sync: follows DSH's
domain/changedevent so the workspace registry stays fresh automatically — any durable registry write (create/delete/rename/reorder/archive/membership) triggers a reread ofworkspaceRegistry.list(), with only added/removed workspaces reprocessed incrementally while unchanged workspaces reuse their computed aggregates and ledger (zero rescan). Usage is strictly limited to registered workspaces: unregistered cwds, including existing directories absent from the registry, are ignored. - Data health and on-demand refresh: after a scan completes, the browser polls only a lightweight status revision and fetches full history only after usage, alias, or sync state changes; it shows the latest full-data update, historical scan health, revision skips, rereads, ledger recovery, and failures while preserving last-good data on network errors
- Performance: Host maintains ingest-time local/UTC day, workspace, model-identity cubes and single-day hour buckets; scope queries merge buckets, exact costs use BigInt decimal accumulators, and the 53-week heatmap emits only the fields it consumes, while revision-scoped snapshot/records caches and recyclable live-event queues remain in place. Client isolates the heatmap, tooltip, trend, donuts, request records, and pricing dialog behind memoized boundaries; pointer coordinates update through refs plus requestAnimationFrame instead of rerendering the page, and the browser entry is deterministically minified before packing
- Trend line chart: show input, cache read/write, output, reasoning, and total processed tokens for the active range, timezone, workspace, provider, and model scope; use hourly buckets for a single-day scope and daily buckets for cross-day scopes, with smooth monotone curves, staged entrance animation, hover for exact values, and click a point to inspect that day
- Unified filters and audit: workspace, provider, model, and date filters apply to the summary, heatmap, trend, tables, and CSV; workspace, provider, and model filters remain independent and can be combined freely, while workspace, provider, and model options are limited to values used in the selected date range and stale selections clear automatically; request logs stay visible as a compact paginated table with grouped Token details for the selected row
- Token accounting semantics: input tokens are fresh (exclude cache hits/writes, which sit in separate buckets along with reasoning); all-zero usage replays never overwrite recorded usage, while cache-only requests still count
- Cost semantics: prices come from the models.dev USD per 1M token catalog; DSH-normalized fresh input and the four cost buckets are snapshotted at calculation time, the multiplier applies only to final total, and existing positive historical costs are not recalculated; matching uses the model's official vendor entry and ignores the DSH provider, while missing official prices stay unpriced
Compatibility and Known Limitations
- Runtime: Node.js
>=22 =0.1.1-rc.1 =0.1.5-rc.1 <0.1.6-0; the real Cordis service chain is verified on0.1.5-rc.1,0.1.1-rc.2and0.1.1-rc.1.0.1.2-rc.1has also been verified compatible through real-world use, but is not covered by the CI smoke matrix. The declaration is split per tuple rather than written as one interval because node-semver only admits a prerelease version when some comparator shares its exactmajor.minor.patchtuple and itself carries a prerelease tag. - Web service dependency: the Host declares
webServeras a required dependency, so DSH waits for a late-mounted service before applying the plugin; this package targets the DSH Web profile and does not expose routes without WebServer. The HTTP guard also checks the actual socket peer, so a reverse proxy is accepted only when the connection itself is loopback.
| DSH runtime | Node.js support | Real