zhangzheng25/dsh-token-monitor 预览 preview

zhangzheng25/dsh-token-monitor

DeepSeek Harness 插件:Token 用量与对话统计设置页 - 今日 / 7日 / 30日总计,GitHub 风格 90 天贡献图,会话日志回填 | DeepSeek Harness 插件:Token 用量与对话统计设置页

Project Overview项目介绍

This is a native DeepSeek Harness (DSH) plugin built exclusively for DSH that adds a persistent "Today's Usage" card to the bottom of the DSH sidebar, right next to the settings icon. The card displays a live running total of daily token usage, updating automatically every 30 seconds, and it collapses to just show the numeric value when the sidebar is folded to save space. Clicking the card opens a full-featured modal statistics window that shows aggregated usage data across multiple time ranges, including daily, 7-day, and 30-day totals, plus 30-day stacked usage charts broken out by model.

This plugin is designed for DSH users who want to easily track their token usage and understand how much they are using each model over time. The plugin automatically pulls usage data directly from DSH session logs, which is the only data source it uses, and it does an idempotent re-scan of all existing sessions on launch, on manual trigger, and every 30 seconds during auto-refresh. This means that even usage from before you installed the plugin will be counted correctly, with no duplicate counts even if you run the backfill process multiple times. It also separates top-level sessions from internal sub-agent conversations for accurate session count statistics.

To install the plugin, you can run the DSH plugin command directly from this GitHub repository, or install it from a local directory if you cloned it to your machine. After running the install command, you will need to restart DSH for the plugin to load, and the usage card will automatically appear in the sidebar once DSH restarts. All usage data is stored persistently in a JSON file under the DSH home directory, and it retains 181 days of data sorted into daily buckets by model. The plugin follows DSH's native styling conventions, uses DSH theme variables to automatically match light and dark mode, and is released under the open source MIT license.

这是一款专为 DeepSeek Harness (DSH) 开发的原生插件,会在 DSH 侧边栏底部(设置图标旁)添加一张「今日用量」卡片,实时显示当日累计使用的 token 总量。点击卡片即可弹出完整统计窗口,提供今日、近7天、近30天的总量统计、近30天按模型分类的堆叠用量图、30天窗口的模型使用排行,以及会话数统计。

这款插件面向需要追踪 DSH token 使用量、掌握不同模型调用频率的开发者,每30秒自动轮询刷新数据,也支持手动刷新和历史用量回填功能,安装插件之前产生的历史用量也可以完整统计。日常使用中,用户无需进入设置页面即可一键查看用量情况,侧边栏折叠时仅显示数值,不占用多余界面空间。

数据默认存储在 $DSH_HOME/plugins/token-monitor/data.json,支持持久化保存,重启应用不会丢失,按天分桶保留181天的数据。插件遵循原生 DSH 主题风格,自动跟随亮色/深色主题切换,采用 MIT 许可开源,安装后只需要重启 DSH 即可使用。

Pre-install check安装前体检Compatibility · Security兼容性 · 安全性 1 warning1 项注意
  • Only 6 stars - very few users, little community feedback星标只有 6,几乎没人在用,遇到问题缺少社区反馈
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 --profile web add github:zhangzheng25/dsh-token-monitor

把 zhangzheng25/dsh-token-monitor 加入你的 DSH 配置(web profile)即可启用。

READMEREADME

dsh-token-monitor

简体中文 | English

🤖 AI 生成声明:本项目由 AI 辅助生成,仅供学习与技术交流使用,不构成任何形式的商业保证或支持承诺。

一个 DeepSeek Harness 插件:在侧边栏底部(设置图标旁)放一张 「今日用量」卡片,实时显示今日 token 总量(形如"今日用量:8888万");点击卡片即弹出完整统计窗口——今日 / 近 7 天 / 近 30 天总量、近 30 天按模型的堆叠用量图、按模型的使用排行(固定 30 天窗口)、以及会话数统计。不再占用设置页面,一键直达。

今日用量卡片

功能特性

  • 🚀 一键直达 — 侧边栏「今日用量」卡片实时显示今日 token 总量(单行"今日用量:8888万",每 30 秒自刷新,折叠成窄栏时只显示数值);点击弹出统计窗口(支持 Esc / ✕ / 点遮罩关闭,背景滚动锁定)。
  • 📊 近 30 天模型使用情况 — 30 天堆叠柱状图:每根柱子按模型分色堆叠(当天用量最高的模型在柱底,颜色按 30 天排名固定);图表区域铺满灰色点阵网格背景(每一天恰好两列点、垂直每 13px 一行,参考 temp/model-usage.png),有调用的柱子叠在点阵之上;横轴只显示每周一的基准日期;悬浮/点击某天弹出明细卡片(日期 / 总计 / 各模型色块行,样式参考 temp/tooltip.png),无任何高亮/变灰/柱上标签效果。
  • 🏆 模型使用排行 — 固定 30 天窗口:前 4 名 2×2 卡片(序号一行 / 模型名 + token 总数 / 提供商 + 占比右对齐,无增长与单位标签),悬停轻微放大。
  • 💬 会话统计 — 今日 / 近 7 天 / 近 30 天开启的顶层对话数(不含子代理内部会话),副文字显示对应时段的模型请求次数。
  • 🔄 自动刷新 — 页面每 30 秒轮询(带幂等重扫,数字自动修正),另有手动「刷新」与「回填历史」按钮。
  • 💾 持久化 — 数据写入 $DSH_HOME/plugins/token-monitor/data.json,重启不丢(按天桶保留 181 天;每个桶内按模型细分)。
  • 🕘 历史回填 — 会话日志是唯一数据源:启动 / 点击「回填历史」/ 30 秒轮询都会把窗口内全部会话用量幂等重扫进新桶(原子替换),把插件安装之前的用量也统计进来;重复运行不会重复计数,旧桶脏数据自动自愈,30 天堆叠图与模型排行立即可用。
  • 🎨 DSH 原生风格 — 亮色主题、1px 细边框卡片、8–10px 圆角、无阴影;颜色走 --dsw-alias-* 主题变量,跟随 DSH 深色主题。

安装

从本仓库安装:

dsh plugin --profile web add github:zhangzheng25/dsh-token-monitor

或从本地目录安装:

dsh plugin --profile web add E:\path\to\dsh-token-monitor

dsh plugin 会在 profile 目录中转发给 pnpm 安装,并自动调和 dsh.profile.bundles;包内 dsh.bundle.patch(cordis.patch.yml)把插件行插入宿主组合,dsh.client.platform: "web" 让 web 外壳加载 client/bundle.js。

安装后重启 DSH,侧边栏底部(设置图标旁)会出现「今日用量」卡片,点击即弹出统计窗口。

架构

┌────────────────────────── Host(Node.js)──────────────────────────┐
│ src/index.js                                                       │
│  • backfill()               ← 会话日志为唯一数据源(幂等全量重建:   │
│      sessionQuery 为 live-preferred,内存活跃会话 + 落盘日志都算,   │
│      每次把窗口内全部 assistant/message 的 usage 折叠进新桶并原子    │
│      替换,重复运行不重复计数;启动 / 点「回填历史」/ 30 秒轮询都跑) │
│      (输入 / 输出 / 缓存命中 / 缓存未命中 / 推理,按天按模型分桶,   │
│       模型归属取 message.source,覆盖 181 天窗口)                   │
│  • buildSessionStats()      ← 顶层对话统计(delegationDepth === 0)│
│      (20 秒缓存)                                                 │
│  • persist()                ← 防抖写入(schema v3:按天按模型分桶, │
│      保留 181 天)                                                │
│      $DSH_HOME/plugins/token-monitor/data.json                      │
│  • webServer.register('/token-monitor/today') ← 轻量今日读数(不触发│
│      重建,供侧边栏卡片轮询)                                        │
│  • webServer.register('/token-monitor/snapshot') ← 供 Client 读取   │
│      (静态 bundle 模式,含 modelRank 三档聚合 + modelDaily30)       │
└─────────────────────────────────────────────────────────────────────┘
                          │ fetch('/token-monitor/snapshot')
                          ▼
┌────────────────────────── Client(浏览器)─────────────────────────┐
│ client/bundle.js — 手工构建的 web bundle,符合 client-modules 协议  │
│  (window.__ModuleLoader__.load)                                  │
│  • slots.inject('sidebar.footer.action') → 侧边栏「今日用量」卡片     │
│      (点击弹出 fixed 模态,内容 = 完整统计面板;无 settings.section)│
│  • 指标卡 + 会话卡 + 30 天模型堆叠图 + 模型使用排行                  │
│  • 卡片每 30 秒轮询 /token-monitor/today;弹窗打开时拉取快照并       │
│    每 30 秒刷新,另有刷新 / 回填历史按钮                            │
└─────────────────────────────────────────────────────────────────────┘

Showing the opening section of the README — the full document lives in the repository以上为 README 开头摘要,完整文档在仓库内 · View the full README on GitHub →在 GitHub 查看完整 README →

← 上一个 Prev deepseek-harness-GUI 下一个 Next dsh-lan →