DeepSeek Harness Plugin

V-dev-388/dsh-usage-meter

Stars ★ 0 Category UI Enhancements Added 2026-08-15

Settings-page usage dashboard: per-provider/model token summary across all sessions, with today/7-day/30-day CSS-bar trends and a cache-hit rate.

Install

# from GitHub (first run asks for allowBuilds approval — follow the hint, retry)

dsh plugin --profile web add github:V-dev-388/dsh-usage-meter

Any plugin you install runs third-party code with your own permissions — it can read your files, use your credentials, and reach the network, and tool approvals don’t sandbox it. GitHub-sourced plugins also run build scripts at install time. Only install sources you trust, and pin a commit (github:owner/repo#sha).

README

DSH(DeepSeek Harness)模型用量仪表盘插件。在设置页新增「用量」板块,按服务商/模型汇总全部会话的 token 用量,支持今日 / 近 7 天 / 近 30 天三档时间范围趋势图。

  • 零运行时依赖:Host 端只用 Cordis 上下文服务(sessions / shell / webServer),不 import 任何包
  • 图表纯 CSS 柱状条,不引第三方库
  • 数据落盘 $DSH_HOME/storages/usage-meter.json,原子写(tmp + rename)
  • 完全被动:只在本机监听会话事件,不联网、无遥测

功能

  • 汇总卡:请求数 / 总 Token / 缓存命中率 / 输入 / 输出 / 缓存读取
  • 时间范围:今日(24 根小时柱)/ 近 7 天 / 近 30 天(按天柱),本地时区切日
  • 服务商表、模型表:请求数、输入、输出、缓存读取、总 Token
  • 60s 自动轮询 + 手动刷新
  • 全部会话都计入(含子 agent 会话)

数据口径

  • 只统计 assistant/message 且带 usage 的事件(失败请求无 message,不计)
  • 归属取 data.message.source.provider / model
  • 缓存命中率 = cacheRead ÷ (input + cacheRead)
  • 不做费用估算,不做逐请求日志表

安装(dsh web profile)

方式一:dsh plugin add(推荐)

插件已发布到 npm,并声明 dsh.bundle manifest(dsh plugin add 安装后自动加入 profile 层栈):

dsh plugin --profile web add dsh-usage-meter

方式二:手动拷贝(照 khazix-skills 的静态插件安装范式)

# 1. 把包放进 profile 的 node_modules
mkdir -p ~/.dsh/profiles/web/node_modules/dsh-usage-meter
cp -R lib package.json dsh.plugin.json ~/.dsh/profiles/web/node_modules/dsh-usage-meter/

# 2. 在 ~/.dsh/profiles/web/cordis.patch.yml 末尾追加:
# - insert:
#     - id: dsh-usage-meter
#       name: dsh-usage-meter

安装后重启 dsh web(或刷新页面加载 client bundle),打开 设置 → 用量 即可查看。

HTTP 接口

接口 说明
GET /dsh-usage-meter/summary?range=today|7d|30d 汇总 + byProvider + byModel + series(今日按小时、其余按天),全部按 range 过滤
GET /dsh-usage-meter/sessions 每会话对账数据 [{sessionId, watermark, requests, totalTokens, provider, model}]

summary 返回字段:

{
  "updatedAt": "2026-08-15T01:06:33.031Z",
  "range": "today",
  "requests": 36, "inputTokens": 19049, "outputTokens": 42036,
  "cacheReadTokens": 4378368, "cacheWriteTokens": 0,
  "totalTokens": 4439453, "cacheHitRate": 0.995668,
  "byProvider": [{ "provider": "opencode-go", "requests": 36, /* ... */ }],
  "byModel": [{ "provider": "opencode-go", "model": "deepseek-v4-flash", "requests": 36, /* ... */ }],
  "series": [{ "label": "08:00", "requests": 28, "totalTokens": 3240870, "cacheReadTokens": 3199360 }]
}

数据存储与幂等

  • 启动回填:遍历 $DSH_HOME/sessions/*/*/session.jsonl.zstd(跳过活会话),unzstd 解压折 JSONL;活会话折内存 session.events 全量 + session/event 事件增量
  • 每会话存 watermark(已折最后 seq),重复回放不重复计数;会话日志变短(文件最后 seq < watermark)则清空该会话重折
  • 变更 debounce 2s 后原子写 usage-meter.json

开发

node test/verify.mjs   # 自包含合成测试:口径 / 幂等 / 文件变短 / summary 自洽

License

MIT

Content from the project README on GitHub ↗

Links

More in this category

View the whole category →