支持跨多个模型、供应商、工作区与时间范围进行统一分析,并可在全部保留历史中自定义起止日期;实时呈现缓存命中率,并可分别查看模型和供应商的分类数据;单日趋势按小时、跨日趋势按日,提供 53 周 GitHub 风格热力图、连续使用、模型与工作区 Token 占比环图及 Token、成本、占比明细,以及可独立自由组合的筛选;支持查询 DeepSeek 账户余额、管理工作区别名及导出 CSV 数据;独立账本在会话删除前持久化用量,工作区被删除时同样保留并把用量汇总为一行「已删除」,增量重建只处理新增事件;重启时未变化会话不回读日志、直接复用账本(以每会话日志 revision 为变更信号);工作区注册表通过 DSH 的 domain/changed 事件自动探针同步——只对新增/删除的工作区增量重扫,未变化的已有工作区直接复用已计算账本、零全量重扫,统计严格限定已注册工作区(未登记目录一律忽略),扫描完成后通过轻量 revision 状态判断,只有 Host/统计状态变化才获取完整历史,并显示 revision 复用、实际读取、账本恢复和失败等非敏感同步健康信息;全 0 用量的重放不会覆盖已记录的真实用量,Token 口径显式声明(输入不含缓存命中,缓存读写与推理独立成桶)。中文使用本地时区,英文统一使用 UTC;API 仅限本机访问。
安装
# npm 包(预构建)
dsh plugin --profile web add dsh-all-usage
# Release 预构建包
dsh plugin --profile web add "https://github.com/ParticleLight/dsh-all-usage/releases/download/v1.1.13/dsh-all-usage-1.1.13.tgz"
# GitHub 源码(首次需按提示配置 allowBuilds 构建授权后重试)
dsh plugin --profile web add github:ParticleLight/dsh-all-usage
装任何插件都等于在你的机器上跑第三方代码,权限和你本人一样大——能读你的文件、用你的凭据、访问网络,工具审批管不到它。GitHub 来源的插件还会在安装时执行构建脚本——pnpm 默认拦截,所以安装可能停在 ERR_PNPM_GIT_DEP_PREPARE_NOT_ALLOWED 或 ERR_PNPM_IGNORED_BUILDS;dsh 会打印出需要添加的确切键名,把它加进该 profile 的 pnpm-workspace.yaml 的 allowBuilds 下,重跑一次即可装上。放行构建本身就是一次信任判断:请只安装可信来源,并尽量锁定 commit(github:owner/repo#sha)。
README
dsh-all-usage
中文
DeepSeek Harness 全量用量看板:按模型、供应商、工作区和时间范围分析 Token、缓存与账户余额。
功能
- 热力图:53 周使用热力图;按工作区筛选并查看每日回合与 Token 明细
- 模型统计:支持混合查看、按模型合并、按供应商汇总三种维度,展示调用次数、各类 Token 与缓存命中率;模型行与筛选下拉显示真实厂商品牌 SVG 图标(未知/混牌保持中性)
- 摘要与工作区:Token 用量、缓存命中、估算成本、账户余额、连续使用、工作区 Token 分布和明细
- 成本统计 / 价格表:从 models.dev 同步模型价格;按输入、输出、缓存读取和缓存写入四个桶计算,保存价格快照,明确区分已计价、免费模型和未计价调用。成本设置是一张可编辑的价格表:每行一个账本模型,价格框直接编辑即写入该模型的手工价,「官方模型」列选定映射后该行自动改用官方目录价,并可为每行配置上下文费率档位与分时段(UTC 峰谷)计费;配置里存在但账本暂无用量的行同样可见、可改、可删。峰谷规则可额外开启「中国法定节假日全天按谷时计价」,节假日日期以显式列表保存在该模型的峰谷计划里(按北京时间 UTC+8 日历日判定,支持 2026-10-01..2026-10-07 区间写法,也可一键「从公开日历载入」当年放假安排后冻结进策略)。内置 DeepSeek 峰谷表已自带 2026 年官方放假安排(随插件版本更新),官方直连或已映射到官方条目的行无需任何配置即按节假日谷价计价;非官方直连的中转行仍按静态价,映射后生效
- 导出:按当前时间范围和模型聚合方式导出 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 <25;CI 会在 Node 22 和 Node 24 上运行测试、语法检查和 npm 包内容检查。 - DSH 兼容:
package.json声明 DSH runtime>=0.1.1-rc.1 <0.1.5-0 || >=0.1.5-rc.1 <0.1.6-0 || >=0.1.7-rc.2 <0.1.8-0 || >=0.2.0-rc.2 <0.2.1-0,已使用0.2.0-rc.2、0.1.7-rc.2、0.1.5-rc.2、0.1.5-rc.1、0.1.1-rc.2和0.1.1-rc.1的真实 Cordis 服务链验证,且全部纳入 CI smoke 矩阵(Node 22/24 双档);0.1.2-rc.1已通过实际使用验证兼容,但未纳入 CI smoke 矩阵。声明按元组拆成四段而非写成单一区间,是因为 node-semver 只有在范围里存在与目标版本同major.minor.patch且自身带预发布标签的比较符时,才会放行该预发布版本 —— 例如必须写成>=0.2.0-rc.2才能让0.2.0-rc.2进入范围。 - 桌面客户端(Electron,Windows):本插件在 DSH 桌面客户端上实测运行正常(实测
@deepseek-ai/dsh-desktop0.1.7-rc.2)。桌面客户端会在窗口顶部为自身的最小化 / 最大化 / 关闭按钮保留一条 40px 顶栏,并在文档上标记data-windows-titlebar与--dsh-windows-titlebar-height;面板据此从该条下方开始绘制,所以桌面端自己的关闭按钮永远不会被面板盖住。浏览器端没有该标记,不留白。顶栏高度优先取宿主声明,其次取 Window Controls Overlay 矩形,最后退回 UA;需要微调时可在 DevTools 执行localStorage.setItem('dsh-all-usage:topInset', '48')后刷新(0表示不留白),无需重新构建。桌面客户端自带运行时,其运行时0.1.7-rc.2已纳入声明区间与 CI smoke 矩阵(见下表)。 - Web 服务依赖:Host 将
webServer声明为必需依赖,确保服务晚挂载时由 DSH 等待后再执行插件;该包面向 DSH Web profile,不提供无 WebServer 的 headless 路由。HTTP 守卫还会检查真实 socket peer,反向代理只有在连接本身来自 loopback 时才会被接受。写接口(价格保存、立即同步、节假日抓取、别名)以进程令牌为授权凭据,不强制要求Origin:DSH 桌面端把 UI 跑在自定义协议上、请求由 Electron 主进程转发,转发时会删掉Origin(连同Host/Cookie/Sec-Fetch-*),强制 Origin 会让桌面端所有写入 403;而Origin若存在仍必须是 loopback 或桌面端自身 scheme,Host仍必须是 loopback(防 DNS rebinding)。
| DSH runtime | Node.js 支持 | 真实 Cordis smoke | 结论 |
|---|---|---|---|
0.2.0-rc.2 |
>=22 <25,CI 覆盖 22/24 |
通过(真实 Cordis 服务链,CI 覆盖 Node 22/24) | 已声明、已验证(DSH 官方 next 线;本机 web profile 即运行于此版本) |
0.1.7-rc.2 |
>=22 <25,CI 覆盖 22/24 |
通过(真实 Cordis 服务链,CI 覆盖 Node 22/24) | 已声明、已验证(DSH 桌面客户端即运行于此版本) |
0.1.5-rc.2 |
>=22 <25,CI 覆盖 22/24 |
通过(真实 Cordis 服务链,CI 覆盖 Node 22/24) | 已声明、已验证 |
0.1.5-rc.1 |
>=22 <25,CI 覆盖 22/24 |
通过(真实 Cordis 服务链,CI 覆盖 Node 22/24) | 已声明、已验证 |
0.1.2-rc.1 |
>=22 <25 |
通过(实际使用验证,未纳入 CI) | 已实际验证兼容 |
0.1.1-rc.2 |
>=22 <25,CI 覆盖 22/24 |
通过(真实 Cordis 服务链,CI 覆盖 Node 22/24) | 已声明、已验证 |
0.1.1-rc.1 |
>=22 <25,CI 覆盖 22/24 |
通过(真实 Cordis 服务链,CI 覆盖 Node 22/24) | 已声明、已验证 |
| 其他版本 | >=22 <25 |
未测试 | 不在已验证矩阵内 |
未列出的 DSH 版本不代表一定不兼容;提交问题时请附 DSH、Node.js 和插件版本。
- 中断请求:上游请求被中断时可能只有
assistant/chunk的 usage,没有最终assistant/message;本插件会保留该 chunk 用量。同一turn / step后续出现最终 message 时,message 会替换 chunk。若上游完全没有 usage 事件,则无法从响应内容精确恢复 Token。 - 估算成本:成本是基于 models.dev 价格和 DSH usage 桶的估算,不是供应商账单;目录不可用或模型没有官方匹配时不会猜测价格,而是显示未计价。缓存读取、缓存写入和 reasoning 的口径取决于 DSH 上游事件。
- 分层价格:models.dev 的 tiered/context-dependent 价格按本次请求的输入上下文(fresh input + cache read + cache write)选择对应档位;阈值边界遵循目录定义,无法验证的异常 tier 仍显示为 unsupported。
- 工作区边界:只有 cwd 能映射到 DSH 已注册工作区的会话才进入统计;未注册 cwd(包括已存在但未在 registry 中登记的目录)会被忽略。工作区注册列表通过 DSH 的
domain/changed探针自动同步:注册表一有改动就重读并只对新增/删除的工作区做增量处理,未变化的已有工作区直接复用已计算账本,不会全量重扫。会话尚未成功 flush 前删除或损坏的日志无法由独立账本恢复。工作区被删除时历史用量不会丢失:它会被保留并汇总为一行「已删除」。
本地统计与官方账单
本插件展示的是 DSH 本地事件日志上的可重放统计,不是供应商账单的镜像:
- 本地统计读取 DSH 的
assistant/chunk、最终assistant/message和其他会话事件,按同一turn / step去重和替换;官方账单可能按供应商自己的请求、分词器、舍入、折扣、免费额度和结算周期计算。 - 失败请求只要留下 usage chunk,就会进入本地统计;供应商是否对该失败请求收费,应以官方账单为准。
- 价格来自 models.dev 的公开模型目录和本地显式覆盖;目录价格、供应商实际价格、区域费率和账单折扣可能不同。成本字段应理解为估算值。
- 本地统计只包含已注册工作区;未注册 cwd 的旧 ledger 不进入统计。已删除工作区的历史用量会保留并汇总为一行「已删除」,删除工作区不会让历史统计变小。统计仍可能因日志损坏、清理或上游没有发出 usage 而少于官方账单。
可复现事件示例
下面的事件是脱敏的最小示例;完整可运行数据见 fixtures/usage-events.json。
失败请求仍保留 usage chunk
[
{"type": "assistant/chunk", "data": {"turn": 1, "step": 1, "chunk": {"type": "usage", "usage": {"inputTokens": 100, "outputTokens": 20}}}},
{"type": "request/error", "data": {"code": "upstream-failed"}}
]
没有最终 assistant/message 时,chunk 仍计为一个本地调用;这不等于官方一定收费。
孤立 usage chunk
{"type": "assistant/chunk", "data": {"turn": 1, "step": 1, "chunk": {"type": "usage", "usage": {"inputTokens": 7, "cacheReadTokens": 8}}}}
缺少 request/context 或 request/header 时,Token 仍可统计,但模型身份显示为 Unknown;插件不会从 Provider 名称或展示字符串猜测模型。
缓存 Token 的四桶含义
{"inputTokens": 100, "outputTokens": 20, "cacheReadTokens": 40, "cacheWriteTokens": 5, "reasoningTokens": 3}
本地 processed total 为 100 + 20 + 40 + 5 + 3 = 168;成本只对 input、output、cacheRead、cacheWrite 四个桶定价,reasoning 不会再次加到 output。
使用仓库中的 fixture 复现:
node scripts/replay-fixture.mjs fixtures/usage-events.json
该命令会加载真实插件 Host、调用兼容 API、校验预期 Token/records,并输出不含敏感信息的摘要。
报告问题
最近更新
v1.1.17
- 修复:DSH 桌面端无法保存成本设置。 写接口(保存价格、立即同步、节假日抓取、别名)原先要求请求带
Origin且与 loopback Host 同源,而桌面端把 UI 跑在自定义协议dsh-app://app上、请求由 Electron 主进程转发时会删掉Origin(连同Host/Cookie/Sec-Fetch-*),于是桌面端的所有写入必然 403——保存价格报「没有权限」、models.dev 目录永远同步不下来、自动同步勾选后回滚。现在写入以进程令牌为授权凭据(跨域页面既读不到也塞不进表单 POST),Origin存在时仍必须是 loopback 或桌面端自身 scheme,Host仍必须是 loopback(防 DNS rebinding)。 - 健壮性修复:宿主未下发
usageBacked时不再断言「账本无用量」,改为「用量未知」三态(独立标记、行样式与页脚计数);/api/all-usage/status新增派生的capabilityId(令牌轮换时变化,令牌本身只在完整快照里下发)与pluginVersion,页面据此察觉宿主被重新加载、写入遇 403 时自动重取令牌并重试一次,宿主与页面版本不一致时直接提示「请重启 DSH」。
完整版本记录见 CHANGELOG.md。
截图 / Screenshots



安装
本插件是标准的 DSH 社区插件包(声明 dsh.bundle manifest 与 Web Client),数据来自持久化会话日志和独立用量账本,安装后自动回填历史。
官方插件命令(推荐)
dsh plugin --profile web add github:ParticleLight/dsh-all-usage
安装命令会装配 bundle;随后刷新浏览器页面以加载 Client,无需手动修改 profile。若当前 DSH 版本未动态装配新包,请按 DSH 的提示重载包或重启进程。
手动注册(本地包)
把本目录放入任意位置,并在 $DSH_HOME/profiles/node_modules/ 下创建指向本目录的符号链接(Windows 用 junction):
New-Item -ItemType Junction -Path (Join-Path $env:DSH_HOME 'profiles/node_modules/dsh-all-usage') -Target '<本目录绝对路径>'在 $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 与同步健康状态,并附带最近一次客户端环境报告(clientEnv)、运行中插件的版本号(pluginVersion)与写入令牌的派生 ID(capabilityId,令牌轮换时变化,用于让页面察觉宿主被重新加载;令牌本身只在完整快照里下发)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— 读取可编辑价格表所需的完整配置:逐模型的生效费率与状态、映射、手工价、峰谷计划(含内置表来源与完整规则)以及仅存在于配置中的行GET /api/all-usage/pricing/models?q=...— 检索官方模型 ID 与名称匹配结果(含预览费率、是否分层计费、是否有内置峰谷表)POST /api/all-usage/pricing— 保存同步、mapping、手工价,以及上下文费率档位与峰谷时段规则(请求形状不变)POST /api/all-usage/pricing/sync— 手动同步 models.dev 并回填未计价调用POST /api/all-usage/pricing/holidays— 按年份抓取中国法定节假日安排(holiday-cn 数据集,jsDelivr 主源、GitHub raw 兜底,主机侧缓存 24 小时),只返回放假日日期列表与来源;不写入任何配置,由客户端冻结进峰谷计划GET /api/all-usage/client-env— 客户端环境诊断上报(UA、窗口控件遮罩高度、预留顶栏值及其来源、视口、面板矩形);客户端在加载与打开面板时各上报一次,只在内存保留
- 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、扫描进度、同步计数与最近一次客户端环境报告(UA、视口、预留顶栏值及其来源、面板矩形——由本机客户端上报且只存内存),不公开会话 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 已含推理时重复计费
- 分时段计费以 UTC 周几与半开时间窗判定:命中规则的请求使用峰时四项费率,未命中时使用该行基础价(谷时=基础价);生效起点之前的用量没有可验证档位,会失败关闭为未计价而不会套用今天的费率;同一峰谷计划被所有使用该价格条目的行共享;开启节假日规则后,节假日当天不再命中任何峰时规则,成本快照会记下 pricingHoliday,明细里显示为「节假日谷时」而不是普通「谷时」
- 历史账本中带
tiered标志的旧 flat 成本会在加载升级时迁移为unsupported(tiered-pricing-not-modeled),不再继续显示为当前精确 priced;Token 统计不受影响。 - 价格同步默认关闭;models.dev 不可用时保留最近一次成功目录,未匹配模型不会套用默认价格;成本设置的价格框即手工价入口(同一官方模型的所有行共享该价格),每行可展开配置上下文档位与 UTC 峰谷规则(含可选的中国法定节假日全天谷价),内置 DeepSeek 峰谷表可一键复制后自定义、也可恢复;看板范围与明细视图保存在浏览器本地,6 小时自动同步开关会立即写入受保护的 pricing API
- Mapping 语义:带
identityKey的 mapping 只对精确路由身份生效;不带身份键的 mapping 才按模型做全局回退;旧配置中的usageIdentityKey会在加载时归一化。 - 节假日日历只在用户点击「从公开日历载入」时抓取:目标主机是
cdn.jsdelivr.net(失败时raw.githubusercontent.com),请求里只有年份,不发送任何用量、会话或凭据数据;返回的日期串在用户保存前不会生效,保存后连同来源说明一起冻结进该模型的峰谷计划(来源不参与政策哈希) - 余额查询走 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 要求输入目标
v<package.version>tag 和完整 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 / price table: sync model prices from models.dev, calculate four cost buckets, persist price snapshots, and distinguish priced, free, ambiguous, and unpriced calls. Cost Settings is one editable price table: each row is a ledger model, its price boxes write that model's manual price, the official-model column switches the row to the catalog price, and every row can carry context rate bands and time-of-day (UTC peak/off-peak) rules, including an optional "Chinese statutory holidays price as off-peak all day" switch whose explicit date list lives in that model's peak plan (China Standard Time calendar days, 2026-10-01..2026-10-07 ranges supported, and one click loads the year's arrangement from a public calendar before it is frozen into the policy); rows that exist only in the saved configuration stay visible, editable, and removable
- 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 <25is required. CI runs the test suite, syntax checks, and package-content checks on Node 22 and Node 24. - DSH compatibility:
package.jsondeclares DSH runtime>=0.1.1-rc.1 <0.1.5-0 || >=0.1.5-rc.1 <0.1.6-0 || >=0.1.7-rc.2 <0.1.8-0 || >=0.2.0-rc.2 <0.2.1-0; the real Cordis service chain is verified on0.2.0-rc.2,0.1.7-rc.2,0.1.5-rc.2,0.1.5-rc.1,0.1.1-rc.2and0.1.1-rc.1, all of them covered by the CI smoke matrix on Node 22 and 24.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 —0.2.0-rc.2is admitted only because the range says>=0.2.0-rc.2. - Desktop client (Electron, Windows): the plugin is verified running in the DSH desktop client (
@deepseek-ai/dsh-desktop0.1.7-rc.2as measured). The desktop client keeps a 40px caption strip across the top of its window for its own minimise / maximise / close buttons and marks the document withdata-windows-titlebarand--dsh-windows-titlebar-height; the panel draws from below that strip, so the client's own close button is never covered. Browsers carry no such marker and reserve nothing. The strip height comes from the host's declaration first, then the Window Controls Overlay rectangle, then the user agent; to tune it, runlocalStorage.setItem('dsh-all-usage:topInset', '48')in DevTools and reload (0reserves nothing) — no rebuild required. The desktop client ships its own runtime, and that runtime —0.1.7-rc.2— is now part of the declared range and of the CI smoke matrix below. - 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 Cordis smoke | Conclusion |
|---|---|---|---|
0.2.0-rc.2 |
>=22 <25, CI covers 22/24 |
Passed (real Cordis service chain, CI covers Node 22/24) | Declared and verified (the current DSH next line; this machine's web profile runs it) |
0.1.7-rc.2 |
>=22 <25, CI covers 22/24 |
Passed (real Cordis service chain, CI covers Node 22/24) | Declared and verified (the DSH desktop client runs this version) |
0.1.5-rc.2 |
>=22 <25, CI covers 22/24 |
Passed (real Cordis service chain, CI covers Node 22/24) | Declared and verified |
0.1.5-rc.1 |
>=22 <25, CI covers 22/24 |
Passed (real Cordis service chain, CI covers Node 22/24) | Declared and verified |
0.1.2-rc.1 |
>=22 <25 |
Passed through real-world use (not in CI) | Verified compatible in real-world use |
0.1.1-rc.2 |
>=22 <25, CI covers 22/24 |
Passed (real Cordis service chain, CI covers Node 22/24) | Declared and verified |
0.1.1-rc.1 |
>=22 <25, CI covers 22/24 |
Passed (real Cordis service chain, CI covers Node 22/24) | Declared and verified |
| Other versions | >=22 <25 |
Not tested | Outside the verified matrix |
An unlisted DSH version is not necessarily incompatible. Include the DSH, Node.js, and plugin versions when reporting an issue.
- Interrupted requests: an interrupted upstream request may emit only
assistant/chunkusage and never produce a finalassistant/message; that chunk is retained. A later final message for the same turn/step replaces it. If the upstream emits no usage event at all, exact token usage cannot be reconstructed from response text. - Estimated cost: cost is an estimate based on models.dev rates and DSH usage buckets, not a provider invoice. Unavailable catalogs and unmatched models remain unpriced instead of receiving guessed rates. Cache reads, cache writes, and reasoning follow the buckets reported by the upstream DSH event.
- Tiered prices: models.dev context-tiered entries select the applicable rate from the request input context (fresh input plus cache read/write tokens); malformed schedules remain unsupported.
- Workspace boundary: only sessions whose cwd maps to a DSH-registered workspace are included. Unregistered cwds, including existing directories absent from the registry, are ignored. The registry is kept fresh by a
domain/changedprobe: any durable workspace-domain write triggers a reread, and only added/removed workspaces are reprocessed incrementally — unchanged workspaces reuse their computed aggregates and ledger. Data deleted or corrupted before a successful session flush cannot be recovered from the separate ledger.
Local Statistics vs Official Billing
This plugin reports replayable statistics from local DSH event logs; it is not a mirror of a provider invoice:
- Local statistics read DSH
assistant/chunk, finalassistant/message, and related session events, then deduplicate and replace samples by logicalturn / step. Official billing may use a provider tokenizer, rounding rules, discounts, free quotas, and billing periods. - A failed request is included locally whenever it leaves a usage chunk; whether the provider charged for that failed request must be checked against the official bill.
- Prices come from the public models.dev catalog and local explicit overrides. Catalog prices can differ from provider prices, regional rates, and invoice discounts, so the cost field is an estimate. A price belongs to the model, so every row priced from the same official model shares one manual entry; price edits never rewrite existing positive costs, while a peak-plan change reconciles that model's history against the new policy.
- Local statistics include registered workspaces only; old ledger rows for unregistered cwds are excluded. Usage recorded for a deleted workspace is kept and summed into one "Deleted" row, so removing a workspace never shrinks historical totals. Totals can still be lower than the official bill when logs are damaged, cleaned up, or the upstream emits no usage event.
Reproducible Event Examples
The following are redacted minimal examples; the complete runnable data is in fixtures/usage-events.json.
Retaining a failed request chunk
[
{"type": "assistant/chunk", "data": {"turn": 1, "step": 1, "chunk": {"type": "usage", "usage": {"inputTokens": 100, "outputTokens": 20}}}},
{"type": "request/error", "data": {"code": "upstream-failed"}}
]
Without a final assistant/message, the chunk remains one local call; this does not mean the provider necessarily charged for it.
Orphan usage chunk
{"type": "assistant/chunk", "data": {"turn": 1, "step": 1, "chunk": {"type": "usage", "usage": {"inputTokens": 7, "cacheReadTokens": 8}}}}
Without request/context or request/header, tokens are still counted, but the model identity is shown as Unknown; the plugin does not guess a model from a provider name or display string.
Cache token buckets
{"inputTokens": 100, "outputTokens": 20, "cacheReadTokens": 40, "cacheWriteTokens": 5, "reasoningTokens": 3}
The local processed total is 100 + 20 + 40 + 5 + 3 = 168; cost uses the input, output, cacheRead, and cacheWrite buckets, and reasoning is not added to output again.
Replay the repository fixture:
node scripts/replay-fixture.mjs fixtures/usage-events.json
The command loads the real plugin Host, calls its compatible APIs, checks the documented token/record totals, and prints a non-sensitive summary.
Report An Issue
Latest Update
v1.1.17
- Fixed: the DSH desktop client could not save cost settings. The write routes (price save, immediate sync, holiday fetch, alias) required an
Originheader matching the loopback host, but the desktop shell serves the UI on its owndsh-app://appscheme and forwards page requests through Electron, which stripsOrigin(along withHost,CookieandSec-Fetch-*) — so every desktop write was rejected with 403: saving prices reported "no permission", the models.dev catalog could never be synced, and the auto-sync checkbox rolled back. Writes are now authorized by the process capability (which a cross-origin page can neither read nor attach to a form POST), a presentOriginmust still be loopback or the shell's own scheme, andHostmust still be loopback against DNS rebinding. - Robustness fixes: a host that omits
usageBackedno longer reads as "no ledger usage" (the panel now has a distinct "usage unknown" state, flag, row style and footer count);GET /api/all-usage/statusreports a derivedcapabilityId(changes when the capability rotates, while the capability itself is only ever sent in the full snapshot) and the runningpluginVersion, so the page notices a plugin reload, re-reads the capability and retries once when a write is rejected with 403, and says "restart DSH" when the host and the page disagree on the version.
See CHANGELOG.md for the complete version history.
Installation
This is a standard DSH community bundle. It declares a dsh.bundle manifest and a web client, and backfills its data from persisted session logs and the durable usage ledger after installation.
Official plugin command (recommended)
dsh plugin --profile web add github:ParticleLight/dsh-all-usage
The installation command assembles the bundle. Refresh the browser page to load the client; no manual profile edits are required. If your DSH version does not dynamically assemble newly installed packages, use its supported package reload or restart the process.
Manual local registration
Place this directory anywhere and create a symlink to it under $DSH_HOME/profiles/node_modules/ (use a junction on Windows):
New-Item -ItemType Junction -Path (Join-Path $env:DSH_HOME 'profiles/node_modules/dsh-all-usage') -Target '<absolute plugin path>'Add this entry to $DSH_HOME/profiles/web/cordis.patch.yml:
- insert: - id: all-usage name: dsh-all-usage
The profile patch layer hot-reloads; save the file and refresh the page.
Architecture
- Host (entry
lib/index.js, assembled bylib/plugin.js): split by responsibility acrossaggregation.js(aggregation/query),ledger.js(durable ledger),session-sync.js(history/live sync),pricing-runtime.js(runtime pricing),balance.js(balance), andhttp.js(protected routes); aggregatesturn/end,assistant/chunkusage, and finalassistant/message.usage, folds livesession/eventupdates, and exposes data routes throughwebServer:GET /api/all-usage— compatible usage snapshotGET /api/all-usage/status— lightweight revision and sync health, plus the last client environment report (clientEnv), the running plugin version (pluginVersion) and a derived id of the write capability (capabilityId, changes when the capability rotates so the page can notice a plugin reload; the capability itself is only ever sent in the full snapshot)GET /api/all-usage/query— scoped aggregate, daily/hourly trend, and heatmap data; single-day scopes populatehourly, while cross-day scopes return an emptyhourlyarrayGET /api/all-usage/records— paginated privacy-safe canonical usage rowsGET /api/all-usage/balance?force=1— account balance using the configuredllm-deepseekAPI keyPOST /api/all-usage/alias— update workspace aliasesGET /api/all-usage/pricing— read the full editable price table: per-row effective rates and status, mappings, manual prices, peak plans (with their built-in/explicit origin and full rules), and rows that exist only in the configurationGET /api/all-usage/pricing/models?q=...— search official model IDs and display names, including preview rates, tiered-pricing flags, and whether a built-in peak table existsPOST /api/all-usage/pricing— save sync, mappings, manual prices, context rate bands, and peak-window rules (request shape unchanged)POST /api/all-usage/pricing/sync— sync models.dev and backfill unpriced callsPOST /api/all-usage/pricing/holidays— fetch one year of the Chinese holiday arrangement (the holiday-cn dataset, jsDelivr first with a GitHub raw fallback, cached host-side for 24 hours) and return only the off-day list plus its source; nothing is written to the configuration — the client freezes the dates into a peak planGET /api/all-usage/client-env— client environment report (user agent, window-controls overlay height, the reserved strip and its source, viewport, panel rectangles); the client reports it at load and whenever the sheet opens, kept in memory only
- Client: readable source lives in
src/client.js;npm run build:clientuses the pinned Terser version to generate thewindow.__ModuleLoader__bundle atlib/client.js, which registers the “Usage statistics” sidebar entry through thesidebar.footer.actionslot. All API routes accept loopback requests and reject an explicit cross-origin Origin; balance reads and alias writes also require a process-scoped token generated when the plugin starts (the balance GET tolerates browsers omitting Origin). Writes are authorized by that token, not by an Origin: the DSH desktop shell runs the UI on its own scheme and forwards requests through Electron, which stripsOrigin(withHost/Cookie/Sec-Fetch-*), so requiring one made every desktop save fail with 403. A presentOriginmust still be loopback or the shell's own scheme, andHostmust still be loopback (DNS-rebinding guard).
Data semantics
- Calls and tokens come from DSH session logs;
session/flushrebuilds and queues the derived ledger only when related events are dirty, coalescing the latest pending record per session and draining on plugin disposal. Readable logs and ledger history are backfilled when the plugin activates, so successfully persisted data survives reloads or session deletion; deleting a workspace likewise keeps its history, summed into one "Deleted" row together with usage that had not reached the ledger yet - Day-level range data retains every readable historical session date with tracked usage; the heatmap is only a fixed latest-53-week view
- After a session is deleted, successfully flushed usage is restored from the separate ledger; disposal hints and periodic reconciliation trigger rebuilds without deleting ledger rows
- For each session and logical
turn / step, only the final usage contribution is kept; retries or replaced messages do not double-count - Input tokens are fresh (exclude cache hits/writes, which sit in their own buckets); all-zero usage replays do not overwrite recorded usage and pure cache-read requests still count
- The lightweight status endpoint exposes only the Host instance, stats revision, scan progress, sync counters, and the last client environment report (user agent, viewport, reserved strip and its source, panel rectangles — reported by a local client and kept in memory only). It does not expose session IDs, workspace paths, prompts, or reply bodies; full snapshots are fetched only after status changes or a manual refresh
- Scoped results keep turns, model calls, and distinct sessions as separate metrics; missing route identity is explicitly Unknown rather than inferred from a display label
- The records endpoint returns only a short hash, time, workspace ID, structured model identity, turn/step, token buckets, and current materialization source. It omits raw session IDs, paths, prompts, replies, and credentials
- Processed tokens = input + output + cache read/write + reasoning; a cache hit means reused context, not newly generated tokens or actual cost
- Cost follows the cc-switch four-bucket formula: input, output, cache-read, and cache-write tokens are priced independently, summed, then multiplied by the final multiplier; when input context is strictly greater than a context-tier threshold, all four rates switch for the whole request instead of progressive band splitting, and DSH reasoning is not added to output a second time
- Time-of-day pricing matches UTC weekdays against half-open windows: a matching request uses the rule's peak rates, anything else uses the row base rates (off-peak = base); usage before a plan's effective instant has no verifiable band and fails closed as unpriced instead of inheriting today's rates, and one plan is shared by every row priced from the same entry (for DeepSeek the built-in plan carries the official State Council holiday list, refreshed with plugin releases); with the holiday switch on, a statutory holiday never matches a peak window and the cost snapshot records pricingHoliday, so records show "Holiday off-peak" instead of a plain off-peak band. The built-in DeepSeek table already ships the 2026 arrangement (refreshed with plugin releases), so first-party or mapped DeepSeek rows price holidays as off-peak with no configuration; reseller routes stay static until they are mapped to the official entry
- Legacy ledger costs carrying
tieredare migrated tounsupported(tiered-pricing-not-modeled) on load instead of remaining falsely marked as current flat priced estimates; token statistics are unchanged. - Pricing sync is off by default; when models.dev is unavailable the last good catalog remains in use, and unmatched models never receive a guessed default price; the Cost Settings price boxes are the manual-price entry point (shared by every row priced from the same official model), each row expands into context bands and UTC peak rules (including optional all-day off-peak pricing on Chinese statutory holidays), and the built-in DeepSeek table can be copied for customisation or restored; dashboard range and detail-view preferences are stored in browser storage, while the 6-hour sync toggle is immediately saved through the protected pricing API
- Mapping semantics: a mapping with
identityKeyapplies only to that exact route identity; a mapping without an identity key is the model-wide fallback. LegacyusageIdentityKeyvalues are normalized when loaded. - The holiday calendar is fetched only when the user clicks "Load from public calendar": the request goes to
cdn.jsdelivr.net(falling back toraw.githubusercontent.com), carries nothing but the year, and never includes usage, session, or credential data; the returned dates stay inert until saved, and saving freezes them together with their source note into that model's peak plan (the source is excluded from the policy hash) - Balance data comes from DeepSeek’s official
/user/balanceendpoint; the card shows guidance when no API key is configured - English mode uses UTC for date buckets, range filters, streaks, heatmap dates, and export timestamps; Chinese mode uses local time
- The ledger assigns each session ID to one of 32 stable-hash JSON shards, so a flush rewrites only its shard; the old
all_usage_ledger.jsonis migrated on first load. An async write failure or an unflushed shutdown does not lose in-memory statistics; the next startup simply scans that session again - Only sessions that can be mapped to a registered workspace by their working directory are included
Development
- After editing
src/client.js, runnpm run build:client, reload the DSH client module, and refresh the page;lib/client.jsis generated and should not be edited directly. After editinglib/plugin.jsor another Host module, reload the package through DSH or restart the process - The plugin has no third-party runtime dependencies: the Host uses Cordis services and the Client uses the runtime-provided React module; pinned Terser is only a development dependency for generating the browser artifact
- Manual npm recovery publishes require a target
v<package.version>tag and full commit SHA; GitHub Actions checks both against the checked-out tag and package version. Release events perform the same commit check.
License / 许可证
MIT
链接
同类插件
bowenliang123/dsh-context★ 1791
DSH 上下文洞察面板:Context 仪表盘 + /context命令 + Context 浏览器,查看 Context的分类组成、内容详情、演进趋势、压缩/注入事件、统计等一站式 Context 全生命周期管理。
Han-1413141/dsh-cost-meter★ 361
会话与当日 API 费用统计、预算图框(已用%)、官方余额、历史看板,支持峰谷计价与官方价格一键同步。
wssfk12138/dsh-damage-pulse★ 237
在 DSH Web 界面追踪 DeepSeek Token 用量、单次与会话费用及账户余额,并显示缓存感知的扣费动画。
zh667/TokenLedger★ 202
侧边栏用量面板:把 Token 归属到实际服务该请求的中转站,站点从已有的 provider 配置中读出,无需额外配置;含今日/本月/累计三窗口、按站点与模型下钻、一年活跃度热力图,以及 New API / Sub2API / DeepSeek 余额。
Ychris12138/dsh-usage-stats★ 167
多供应商用量看板:按供应商/模型统计 Token 与日期下钻,统一展示账户余额,并追踪 OpenCode Go / Z.ai 订阅额度。
PolinniZhong/dsh-personal-center★ 118
DeepSeek Harness 个人中心:跨会话用量统计、按模型成本估算、全局自定义指令、外观全局字号、数据驱动的桌面宠物(位图/矢量皮肤)与会话状态概览,纯本地离线运行。
社区评论
评论公开保存在 GitHub Discussions。加载评论会连接 GitHub 和 Giscus;发表内容需要 GitHub 账号。