前言¶
DeepSeek Harness 的 dsh-token-meter 提供實時 token 計量,但沒有跨會話的聚合報表。用戶需要了解“本月用了多少 token”或“哪個模型最費 token”時,通常需要手動翻閱日誌。dsh-token-stats 插件解決這一問題:監聽 session 事件,自動寫入日誌,並提供 token_report 工具進行聚合查詢。
功能¶
該插件提供以下核心能力:
- 自動記錄:監聽
session/event事件,在每次assistant/message帶 usage 字段時,自動寫入一條包含計數和會話 ID 的日誌。 - 聚合報表:支持按天、周、月或全量聚合,支持按模型和日期區間過濾。
- 工具支持:提供
dsh-token-report命令行工具,以及在 DSH 會話中由模型調用的token_report工具。 - 系統引導:通過系統提示段引導模型在用戶詢問 token 用量時調用
token_report。
安裝與啓用¶
系統要求¶
- 操作系統:Linux 或 macOS(Windows 未測試)。
- 環境:已安裝 DeepSeek Harness CLI (
dsh) 及其 profile。
安裝命令¶
使用官方插件安裝命令即可:
dsh plugin --profile headless add github:QEDQCD/dsh-token-stats
安裝後,插件會自動掛載 token_report 工具到對應的 profile。
使用示例¶
命令行查看¶
在終端直接運行 dsh-token-report 查看彙總數據:
dsh-token-report # 今日 + 本月 + 全部彙總
dsh-token-report --by day # 按天明細
dsh-token-report --model deepseek # 按模型過濾
模型側調用¶
在 DSH 會話中,模型可以主動調用工具:
token_report(period: "month")
token_report(period: "month", model: "deepseek-chat")
限制與隱私¶
隱私安全¶
日誌文件存儲在 ~/.dsh/token_usage.l,僅包含 token 計數和會話 ID,不包含提示詞內容或 API Key。
已知限制¶
- 存儲路徑:日誌文件路徑固定爲
~/.dsh/token_usage.l。 - 記錄內容:當前無法記錄模型名。
- 配置項:
maxRecords配置字段已聲明但未實現,目前不限制記錄數量。 - 兼容性:不支持 Codex。
- 操作系統:僅支持 Linux/macOS,Windows 未進行測試。