beijingwahw/dsh-usage-ledger
dsh-usage-ledger(Token 费用统计)— 自动记下每笔对话花了多少 Token、多少钱(按对话、按天、累计都能查),价格自动跟着官方最新价走、支持多家国产厂商,低谷时段自动按便宜价算,预算超了自动提醒还能拦下调用,带可视化仪表盘。
Project Overview项目介绍
dsh-usage-ledger is a token usage and cost ledger plugin for DeepSeek Harness. It aggregates input, output, and cache read/write tokens from assistant/message events per session, per Beijing-time day, and per lifetime, pricing them in CNY via dynamic scraped official rates (DeepSeek peak/off-peak included). It adds daily/total/per-session budget warnings and optional call blocking, multi-vendor catalog auto-update, customPrices overrides, a web dashboard at /usage-ledger, and a usage_report tool. Use it to visualize usage and cap LLM spend. Caveat: with enforceBudget on, over-budget calls are blocked, and initial startup needs network access to fetch pricing.
dsh-usage-ledger 是 DeepSeek Harness 的 Token 用量与费用记账插件。它按会话、北京日、生命周期聚合 assistant/message 的 input/output/缓存读写 Token,按官方定价(支持峰谷分时)折算 CNY,并提供日/总/会话三级预算告警与拦截、动态抓取多家国产模型定价、customPrices 用户覆盖、Web 仪表盘 /usage-ledger 路由及 usage_report 工具。适合需要可视化用量、控制 LLM 成本的 Harness 部署。需注意:启用 enforceBudget 后超限会直接拦截模型调用,首次启动需网络以抓取定价页。
请帮我安装这个 DSH 插件。安装前先完成【兼容性检查 + 安全性检查】,检查通过再动手。
插件:dsh-usage-ledger(beijingwahw/dsh-usage-ledger)
仓库:https://github.com/beijingwahw/dsh-usage-ledger
本站详情页:https://www.yhbd.top/plugins/beijingwahw-dsh-usage-ledger/
本站登记:类型 plugin · 归类 原生 DSH 插件 · 许可证 MIT · ⭐ 3 · 最近提交 2026-08-31 · 主语言 TypeScript
按下面顺序执行,每步先把结论告诉我,再进入下一步:
【1 兼容性检查】
① 我这边:DSH 版本、Node 版本、操作系统、当前 profile(web / desktop)。
② 读它的 README、package.json、插件 manifest,列出它要求的 DSH 版本 / Node 版本 / 操作系统 / 外部依赖 / 需要另外先装的运行时。
③ 逐条比对,结论只写「满足 / 不满足 / 未知」三种;不满足的给出可行替代方案。
④ 检查是否和我已装的插件冲突:命令名重复、skill / tool 重名、端口占用、重复注册的 MCP server。
【2 安全性检查】
① 仓库可信度:和上面「本站登记」是否一致;star / fork 数、创建时间、最近提交,是否归档或长期停更。
② 安装脚本:逐行看 package.json 的 preinstall / install / postinstall,以及 install.sh、setup.ps1 之类脚本。出现 curl|bash、下载后直接执行、混淆代码、访问与插件功能无关的域名,立刻停下来告诉我,不要继续装。
③ 依赖:列出新增依赖,标出无人维护、或与知名包拼写近似的可疑包(typosquatting)。
④ 权限与副作用:它会读写哪些目录、访问哪些域名、需要哪些 DSH 权限(filesystem / network / shell / clipboard 等),以及怎么卸载和回滚。
⑤ 如果它要求 sudo / 管理员权限,或权限明显超出功能所需,先停下来问我。
【3 安装】
上面两步没有「不满足」和「高危项」时才执行;用官方推荐方式安装,不要自行提权。
【4 汇报】
用表格输出:检查项 / 结论 / 依据 / 是否需要我决策。拿不准的一律写「未知」并说明要我怎么确认——不要猜,也不要替我决定。
Send this message to DSH in your current session: it verifies compatibility and security first (answering met / not met / unknown item by item) and only installs once everything checks out — it will stop and ask you if it finds a high-risk item. The box scrolls; the copy is the full prompt. CLI install commands may not be accurate across systems, so DSH is the safer route.把上面这条消息直接发给当前会话里的 DSH:它会先核对兼容性与安全性(逐条给「满足 / 不满足 / 未知」),确认没问题再安装,有高危项会停下来问你。框内可滚动,复制到的是完整提示词;安装命令不一定准确,发给 DSH 更稳。
- Only 3 stars - very few users, little community feedback星标只有 3,几乎没人在用,遇到问题缺少社区反馈
DSH walks through these 9 checksDSH 会逐条核对这 9 项
Compatibility兼容性
- DSH, Node, OS and profile requirementsDSH 版本 / Node 版本 / 操作系统 / profile 是否满足要求
- External dependencies and runtimes (Electron / Python / Docker, ...)外部依赖与运行时(Electron / Python / Docker 等)是否齐备
- Conflicts with installed plugins: command names, skill / tool names, ports, duplicate MCP registration与已装插件是否冲突:命令名、skill / tool 重名、端口占用、重复 MCP 注册
Security安全性
- Repo matches the facts registered here; archived or abandoned?仓库是否与页面登记一致,是否归档或长期停更
- Safety of preinstall / install / postinstall and install.sh / setup.ps1preinstall / install / postinstall 与 install.sh、setup.ps1 是否安全
- curl|bash, download-then-execute, obfuscation, unrelated domains → stop immediatelycurl|bash、下载即执行、混淆代码、无关域名 → 立刻停止
- Typosquatting or unmaintained packages among the new dependencies新增依赖里有没有 typosquatting 或无人维护的包
- Requested permissions vs. what the feature actually needs申请了哪些权限、是否超出功能所需(filesystem / network / shell / clipboard)
- Any sudo / admin requirement, plus uninstall and rollback是否要求 sudo / 管理员权限,以及卸载与回滚方式
Anything uncertain must be marked unknown with a note on how to confirm it. This site's signal screen is a static snapshot, not a security audit.拿不准的必须标「未知」并说明要我怎么确认。本站的信号筛查是静态快照,不能替代安全审计。
Or use CLI install (for developers)或使用命令行安装(适合开发者)
CLI Install命令行安装
dsh plugin add beijingwahw/dsh-usage-ledger --profile web
把 beijingwahw/dsh-usage-ledger 加入你的 DSH 配置(web profile)即可启用。
READMEREADME
dsh-usage-ledger ( Token费用统计 )
中文 | English
DeepSeek Harness 的 Token / 用量统计与成本控制插件:按对话聚合消耗、动态跟随官方定价、支持预算拦截,并内置 Web 仪表盘。
功能特性
- 按会话统计:监听
session/event,把每次assistant/message的usage(输入 / 输出 / 缓存读写 Token)折算为费用,按会话、按北京日、按生命周期三个维度聚合,并持久化到账本文件。 - 动态官方定价:定期抓取官方定价页,自动解析并热更新价格,官方调价 / 上新模型时无需改代码即可生效。
- DeepSeek 峰谷分时:识别官方「高峰 / 空闲」时段表与生效日期,按调用发生的北京时间实时取价。
- 多厂商价格目录:覆盖 DeepSeek、智谱 GLM、月之暗面 Kimi、阿里通义、字节豆包、MiniMax、百度文心等主流国产模型,新模型上线官方定价页后自动导入。
- 预算控制:支持日 / 总 / 单会话三级预算,达到阈值进入告警,超限可通过
llm/stream钩子直接拦截模型调用。 - Web 仪表盘:通过
dsh-host-webserver注册/usage-ledger路由,提供用量可视化与 JSON API。 - 用户覆盖价:
customPrices设置可为任意模型(含自定义模型)覆盖或补充价格,优先级最高。
安装
一键安装
dsh plugin add beijingwahw/dsh-usage-ledger --profile web
常用进阶命令:升级
dsh plugin upgrade dsh-usage-ledger --profile web;卸载dsh plugin remove dsh-usage-ledger --profile web;本地路径安装dsh plugin add ./dsh-usage-ledger --profile web。
Harness 通过 dsh.plugin.json 与 cordis.patch.yml 自动加载插件,lib/ 随仓库分发,无需本地构建。
配置
在 Harness 的 cordis.yml 中挂载并配置:
- name: dsh-usage-ledger
config:
ledgerPath: '' # 留空则使用 $DSH_HOME/usage-ledger.json
saveIntervalMs: 5000 # 账本落盘防抖
pricingTimeoutMs: 10000 # 单次定价抓取超时
usage-ledger 命名空间的用户设置(可在运行时热更新):
| 设置 | 默认 | 说明 |
|---|---|---|
dailyBudget |
0 |
日预算(元),0 关闭 |
totalBudget |
0 |
总预算(元),0 关闭 |
sessionBudget |
0 |
单会话预算(元),0 关闭 |
warnRatio |
0.8 |
进入告警的预算占比 |
enforceBudget |
true |
超预算时拦截模型调用 |
pricingUrl |
DeepSeek 官方页 | 定价刷新来源 |
refreshIntervalMin |
60 |
定价刷新间隔(分钟) |
customPrices |
{} |
按模型 id 覆盖价格(最长前缀匹配) |
customPrices 示例:
{
"glm-4.6": { "inputCacheHit": 1, "inputMiss": 5, "output": 5 }
}
价格单位为 元 / 百万 tokens。
价格解析优先级
用户覆盖 > DeepSeek 实时表 > 各厂商实时抓取表 > 内置目录精确匹配 > 最长前缀匹配
各厂商抓取方式(fetchKind):
| 厂商 | 通道 |
|---|---|
| DeepSeek | 官方定价页 HTML(含峰谷表) |
| 智谱 GLM | SPA app.*.js 内嵌价格 + 公开运营位接口 |
| Kimi | Next.js RSC flight payload 子页 |
| 通义千问 | 官方定价页表格 |
| 豆包 | 火山文档中心服务端 Markdown |
| MiniMax | 官方定价页表格 |
| 文心 | 百度 CDN Gatsby page-data |
Showing the opening section of the README — the full document lives in the repository以上为 README 开头摘要,完整文档在仓库内 · View the full README on GitHub →在 GitHub 查看完整 README →
MeteorNOX/DeepSeek-Balance-Whale-Widget
wssfk12138/dsh-damage-pulse
Ychris12138/dsh-usage-stats
wink-run/tokenbank
JingbiaoMei/Tokdash
yxxbc/dsh-balance-plugin
Lxiayu/DshCockpit
feiyang-dev/dsh-usage-plugin