前言¶
在 DeepSeek Harness(DSH)裏用 Composer 寫代碼時,界面通常會顯示上下文用量(context meter)。若你同時訂閱了 OpenCode Go,額度還分 5 小時滾動、周、月等窗口;這些數字在官方控制台裏,和當前對話界面是分開的。來回切換容易在額度快用盡時才發現。
下面介紹社區插件 dsh-opencode-go-usage(維護者 lccc233):它把 OpenCode Go 三個額度窗口做成 Composer 停靠區裏、緊挨 context meter 右側的三個小圓環,懸停可展開明細。插件歸類爲「工作流」,面向已在 DSH Web GUI 中日常對話、又需要盯 OpenCode Go 用量的開發者。
這是什麼¶
dsh-opencode-go-usage 是 DSH 的 Web GUI 插件:在聊天輸入框(composer dock)旁展示 OpenCode Go plan 的額度佔用,不註冊工具、不注入 system prompt、不訂閱 session 事件,因此不增加面向模型的 token,也不影響 KV cache。
數據來源是 OpenCode 官方接口 GET https://opencode.ai/zen/go/v1/usage(Authorization: Bearer <key>)。Host 端通過 ctx.credentials 解析 API Key 並代請求上游,瀏覽器只輪詢本機 loopback 上的快照路由,密鑰不會進入瀏覽器。
界面與數據含義¶
緊湊模式下始終可見三個 14px 圓環(2px 描邊),分別對應 5h rolling / weekly / monthly,環上無文字;填充比例表示該窗口的已用百分比(percent),剩餘爲 100 − percent。
顏色閾值(資料原文):
- 已用
<60%:綠色 - 已用
≥60%:琥珀色 - 已用
≥85%:紅色 - 無數據:灰色環
- 上游失敗:三環均爲紅色
懸停、聚焦或點擊可展開詳情:每個窗口一條 6px 進度條,並顯示剩餘比例、重置倒計時、採樣時間與手動刷新。環與行的 title、aria-label 中會帶上可讀摘要(例如 5h rolling · 3% used (97 left · resets in 3h25m))。
上游 JSON 結構示例(字段以官方爲準):
{ "usage": {
"rolling": { "status": "ok", "percent": 3, "resetsAt": "2026-10-02T16:18:57.800Z" },
"weekly": { "status": "ok", "percent": 1, "resetsAt": "2026-10-05T00:00:00.000Z" },
"monthly": { "status": "ok", "percent": 59, "resetsAt": "2026-10-11T12:22:02.000Z" } } }
環境與依賴¶
安裝前請確認:
- DSH 0.2.0-rc.2(插件開發與驗證針對的版本),啓用 Web GUI profile(
@deepseek-ai/dsh-web-app),且具備conversation.composer.dock插槽(隨@deepseek-ai/dsh-client-ui-conversation提供)。 - 有效的 OpenCode Go 訂閱及 API Key。默認憑據引用爲
OPENCODE_GO_API_KEY(與llm-pi-aiprovider 相同)。可在 Settings → Models 配置,或寫入~/.dsh/.credentials.yaml,或導出同名環境變量。 - Windows、macOS 或 Linux。開發校驗需要 Node 22+。
安裝與啓用¶
DSH 主目錄默認爲 ~/.dsh(Windows 爲 %USERPROFILE%\.dsh)。Profile 位於 ~/.dsh/profiles/<name>/;桌面版 Electron 使用 desktop profile,下文示例以 desktop 爲準。
無論哪種路徑,啓用插件都需要三件事:
- Profile 能解析到包:
~/.dsh/profiles/<name>/node_modules/dsh-opencode-go-usage存在(實體目錄、junction 或 symlink)。 ~/.dsh/profiles/<name>/package.json的dependencies中記錄該包。~/.dsh/profiles/<name>/cordis.patch.yml中有對應的 Loaderinsert行。
修改 package.json 與 patch 時請使用無 BOM 的 UTF-8;Windows PowerShell 的 Set-Content -Encoding UTF8 可能寫入 BOM,導致 DSH 無法解析 JSON。
完成上述步驟後 重啓 DSH。全新包不會在配置熱重載時進入 Loader 圖,需啓動時加載。
路徑 A:克隆到插件目錄並鏈入 profile(desktop 推薦)¶
先把倉庫放到 profile 可解析的位置,再鏈入 node_modules:
git clone https://github.com/lccc233/dsh-opencode-go-usage.git ~/.dsh/plugins/dsh-opencode-go-usage
Windows(junction):
cmd /c mklink /J "%USERPROFILE%\.dsh\profiles\desktop\node_modules\dsh-opencode-go-usage" "%USERPROFILE%\.dsh\plugins\dsh-opencode-go-usage"
POSIX(symlink):
ln -s ~/.dsh/plugins/dsh-opencode-go-usage ~/.dsh/profiles/desktop/node_modules/dsh-opencode-go-usage
在 ~/.dsh/profiles/desktop/package.json 中登記依賴(路徑相對 profile 目錄):
{
"name": "dsh-profile-desktop",
"private": true,
"dependencies": {
"dsh-opencode-go-usage": "file:../../plugins/dsh-opencode-go-usage"
}
}
在 ~/.dsh/profiles/desktop/cordis.patch.yml 增加 Loader 行:
- insert:
- id: opencode-go-usage
name: "dsh-opencode-go-usage"
config:
apiKeyEnv: OPENCODE_GO_API_KEY
endpoint: https://opencode.ai/zen/go/v1/usage
refreshMs: 60000
timeoutMs: 10000
route: /opencode-go-usage/snapshot
路徑 B:profile 自帶的插件管理器¶
若環境已部署 @deepseek-ai/dsh-plugin-manager 且有 dsh CLI,可對非 desktop profile 執行:
dsh plugin --profile <name> add dsh-opencode-go-usage
該命令會完成依賴安裝、bundle 記錄與 patch 行。注意:desktop profile 不能這樣管理(dsh plugin --profile desktop 會被拒絕);desktop 請用路徑 A。本倉庫在 package.json 中聲明 dsh.bundle.patch,作爲 bundle 安裝時會寫入相同 insert。
路徑 C:作爲 profile bundle¶
在 profile 的 package.json → dsh.profile.bundles 中加入包名,由倉庫自帶的 cordis.patch.yml 插入 Loader 行:
{
"dsh": { "profile": { "bundles": ["@deepseek-ai/dsh-base", "@deepseek-ai/dsh-web-app", "dsh-opencode-go-usage"] } }
}
profile 層手寫行與 bundle 層使用相同 id: opencode-go-usage,profile 層 config 可覆蓋 bundle 層。
配置項¶
| 字段 | 默認值 | 含義 |
|---|---|---|
apiKeyEnv |
OPENCODE_GO_API_KEY |
每次刷新經 ctx.credentials 解析;可回退同名環境變量 |
apiKey |
— | 明文 Key(不推薦,會出現在 patch 中) |
endpoint |
https://opencode.ai/zen/go/v1/usage |
額度接口 |
refreshMs |
60000 |
緩存時長;瀏覽器按同週期輪詢 |
timeoutMs |
10000 |
單次上游請求超時 |
route |
/opencode-go-usage/snapshot |
本機 Web 服務快照路徑 |
驗證與日常使用¶
啓動 DSH 後,端口見啓動日誌中的 dsh web: URL。先用 curl 確認 Host 半部已加載:
curl http://127.0.0.1:<port>/opencode-go-usage/snapshot/probe
probe 返回插件名、版本(當前包版本 0.1.0)、路由與採樣時間等;404 表示未加載(路徑錯誤、缺少 insert 或 import 失敗)。
拉取快照:
curl http://127.0.0.1:<port>/opencode-go-usage/snapshot
返回各窗口的 percent、resetsAt 及 stale、error 等字段。隨後在 Web GUI 打開對話頁,Composer dock 中 context meter 右側應出現三個額度圓環;需要明細時懸停即可。
卸載時從 cordis.patch.yml 移除對應 insert、從 package.json 去掉依賴並刪除 node_modules 中的包,再重啓 DSH(完整步驟見倉庫 README)。
適用場景與注意¶
適合:已在 DSH Web GUI(含 desktop profile)中使用 Composer,且持有 OpenCode Go 訂閱、希望在與上下文用量同一行觀察三檔額度窗口的開發者。
請注意:
- 插件在 當前 DSH 進程權限 下運行,會代你調用 OpenCode 額度 API;安裝前應閱讀 GitHub 源碼 與 MIT 許可證,確認行爲符合你的安全策略。
- 社區目錄 SkillHub 插件頁 與 DeepSeek / 幻方無官方從屬關係;DSH 生態強調「一切皆插件」,目錄站是獨立社區索引。
- 版本與 DSH 的匹配以 README 爲準(開發驗證版本 0.2.0-rc.2);升級 DSH 或 OpenCode 接口後若異常,可對照 probe/snapshot 的
lastError與倉庫 Issue。
鏈接¶
- 社區目錄:https://www.skillhub.cn/plugins/lccc233/dsh-opencode-go-usage
- 源碼與完整部署說明:https://github.com/lccc233/dsh-opencode-go-usage
經過上面的步驟,你可以在不動對話 prompt 的前提下,把 OpenCode Go 的 rolling / weekly / monthly 額度貼在 Composer 旁,用顏色閾值和懸停明細避免額度用盡才發現的問題。