前言¶
在 DeepSeek Harness(DSH)裏跑任務時,Token 消耗分散在會話日誌裏,想看清累計用量、單日峯值、模型佔比或連續使用天數,往往要自己翻文件或靠零散腳本。DSH Token Insight 是維護者 daniei-chen 發佈的客戶端類本地插件:數據只讀本機 ~/.dsh,在 DSH 的「設置 → 使用統計」裏提供完整面板,並附帶面向 AI 的安裝說明文檔;可選配套的 Android 殼應用見獨立倉庫 DeepSeek-Harness-APP,插件本身裝在運行 DSH 的 host 上即可。
下面介紹插件定位、能力、安裝與驗收方式。事實以 GitHub 倉庫 README 爲準;社區目錄頁:daniei-chen/dsh-token-insight。
這是什麼¶
DSH Token Insight(dsh-token-insight,當前版本 0.5.0,MIT 許可證)是裝在 DSH host 上的插件。host 側只讀解析會話與歷史彙總,client 側在設置頁渲染統計結果;不寫 sessions、不寫 storages,增量結果緩存在 ~/.dsh/dsh-usage-stats/session-cache.sqlite。
一句話:Local-first token usage dashboard for DeepSeek Harness——累計/峯值 Token、連續天數、52 周熱力圖、每日趨勢、模型用量、會話 Top 5、成本與導出,均來自本機數據,不聯網、不上傳、不需要賬號或 API key。
環境要求¶
| 項目 | 要求 |
|---|---|
| DSH | 0.2.1-rc.2 或更新 |
| Profile | desktop(默認) |
| DSH runtime Node | Node 24(插件使用內置 node:sqlite) |
DSH_HOME 默認爲 ~/.dsh;若自定義,安裝腳本與插件都會讀取該變量。
核心功能¶
README 中列出的面板模塊如下,均基於解析當前版本的 session.v4.jsonl.zstd(非估算),並標註數據覆蓋範圍,避免把「沒記錄」誤看成「沒使用」。
| 模塊 | 能力 |
|---|---|
| 總覽指標 | 累計 Token、峯值 Token、最長聊天時長、當前連續天數、最長連續天數 |
| 52 周熱力圖 | 每日 / 每週 / 累計;懸停顯示日期、token、輪消息;手機端可橫向滑動 |
| 每日趨勢 | 近 7 日 / 近 30 日 / 全部;按模型分色 |
| 模型用量 | 環形圖 + 明細列表;圖例與環形圖可篩選 |
| 數據覆蓋 | 實際起止日期;今日、本週、緩存命中率 |
| 會話 Top 5 | 標題、Token、時長 |
| 導出 | CSV / JSON / PNG |
| 日預算 | 本機 localStorage;超預算提示,不影響統計 |
| 歷史計費 | 從舊 web-billing / cost-meter 按天補全部分費用,並標註「部分」 |
| 主題 | 跟隨 DSH 深色/淺色 |
數據流要點:當前會話來自 ~/.dsh/sessions/**/session.v4.jsonl.zstd;舊版日彙總 ~/.dsh/storages/web-billing.json;cost-meter ~/.dsh/storages/cost-meter/ledger.json。同一自然日若多處有記錄,按 max() 合併,避免重複累加。
安裝與啓用¶
插件以當前 DSH 進程權限運行本機文件;安裝前請自行查看倉庫源碼與 MIT 許可證。以下命令與路徑來自官方 README,不要憑插件名拼接 dsh plugin add github:owner/repo。
方式一:Release 包(無需克隆倉庫)¶
從 Release v0.5.0 下載 dsh-token-insight-0.5.0.tgz,在 DSH 插件管理器中選擇該 tgz,或解壓到:
~/.dsh/profiles/desktop/node_modules/dsh-token-insight
方式二:手動寫入 profile¶
在 ~/.dsh/profiles/desktop/package.json 中增加依賴,並把包名加入 dsh.profile.bundles:
{
"dependencies": {
"dsh-token-insight": "file:/absolute/path/to/dsh-token-insight"
},
"dsh": {
"profile": {
"bundles": ["...", "dsh-token-insight"]
}
}
}
在 profile 的 node_modules 下建立指向插件目錄的 junction 或符號鏈接。Windows 示例:
New-Item -ItemType Junction `
-Path "$HOME/.dsh/profiles/desktop/node_modules/dsh-token-insight" `
-Target "<absolute-path-to-dsh-token-insight>"
macOS / Linux:
ln -s "<absolute-path-to-dsh-token-insight>" \
"$HOME/.dsh/profiles/desktop/node_modules/dsh-token-insight"
若本地已有插件目錄副本¶
在插件目錄內執行安裝腳本,會把依賴寫入 profile 並建立 node_modules 鏈接:
node scripts/install.mjs --profile desktop
無論採用哪種方式,都需要完整重啓 DSH(關閉應用再打開),然後在 設置 → 使用統計 打開面板。
面向 AI / 自動化安裝時,可先讀倉庫內 docs/INSTALL_FOR_AGENTS.md,內含逐步命令、驗收與排錯。
驗證安裝¶
在 host 上可按 README 做三項檢查(將 <port> 換成 DSH Web GUI 端口):
cd "$HOME/.dsh/profiles/desktop"
node -e "console.log(require.resolve('dsh-token-insight/client'))"
curl "http://127.0.0.1:<port>/usage-stats/api?days=30"
curl "http://127.0.0.1:<port>/usage-stats/api?days=all"
期望響應中 "ok": true,並包含 totalTokens、peakTokens、longestChat、models、cacheHitRate、todayTokens、weekTokens、sessionsTop、coverage 等字段。
典型用法¶
在界面中查看¶
安裝並重啓後,自上而下依次爲:總覽卡、數據覆蓋、今日/本週/緩存命中/歷史計費、日預算、52 周熱力圖、時間範圍切換、每日趨勢、模型用量、會話 Top 5、導出與刷新。
HTTP API¶
其他本機工具可只讀消費統計結果:
GET /usage-stats/api?days=7|30|all
常見返回字段包括:coverage(firstDay、lastDay、sources)、totalTokens / peakTokens、longestChat、currentStreak / longestStreak、cacheHitRate、todayTokens / weekTokens、cost、dayList、dayModels、models、sessionsTop、heatList 等。詳見 README「API」一節。
與手機 App 的關係¶
DeepSeek-Harness-APP 是獨立 Android 項目;插件不需要裝到手機。App 通過 WebView 顯示 DSH Web UI,host 裝好插件後,手機端同樣進入「設置 → 使用統計」即可看到同一份本機數據。
適用場景與注意¶
適合需要在 DSH 內長期跟蹤 Token 用量、模型分佈與會話成本的開發者:數據留在本機,適合對隱私和離線統計有要求的場景。
常見問題(摘自 README):若設置裏同時出現舊包「DSH 使用統計」與新「使用統計」,需確認 profile 只保留 dsh-token-insight 並完整重啓;/usage-stats/api 返回 404 時檢查插件是否加載、profile 與端口;Cannot find module 'node:sqlite' 表示 DSH 內置 Node 過低,需 Node 24 的 DSH;無數據時確認 ~/.dsh/sessions 下存在 .zstd 並在 DSH 中實際產生會話。
卸載時從 package.json 的 dependencies 與 dsh.profile.bundles 移除 dsh-token-insight,刪除對應 node_modules 條目並重啓;可選刪除 ~/.dsh/dsh-usage-stats/session-cache.sqlite,不會刪除原始會話。
結尾¶
DSH Token Insight 把本機會話與歷史彙總整理成可讀面板與 /usage-stats/api,適合作爲 DSH 生態裏「客戶端 / 使用統計」類插件的參考實現。目錄頁:https://www.skillhub.cn/plugins/daniei-chen/dsh-token-insight;源碼與文檔:https://github.com/daniei-chen/dsh-token-insight。