bowenliang123/dsh-context
bowenliang123/dsh-contextDSH 上下文洞察面板:Context 仪表盘 + /context命令 + Context 浏览器,查看 Context的分类组成、内容详情、演进趋势、压缩/注入事件、统计等一站式 Context 全生命周期管理。
侧边栏底部的 DeepSeek 钱包余额:信用卡图标配余额数字,按剩余额度着色(≥ ¥2 绿色、¥0–2 黄色、≤ ¥0 红色),挂载时、每轮对话结束和点击时刷新;余额变动时带符号差额上飘淡出。
DeepSeek wallet balance at the sidebar foot — a DeepSeek Harness plugin.
DeepSeek-only: this plugin targets the DeepSeek platform exclusively — the official DeepSeek balance endpoint and
DEEPSEEK_API_KEY. No other platforms or providers are supported.
English | 中文
Shows your DeepSeek account balance as a card icon + amount in the sidebar footer (beside Settings), tinted by how much is left. Refreshes when a conversation turn ends, on click, and on mount — no polling. When the amount changes, a signed delta (+¥3.14 / -¥1.97) floats up and fades next to it — every spend (or top-up) is visible at a glance.

lowBalanceThreshold (default 2): greenrefresh event when any conversation turn ends — wallet spend settles with the turn.prefers-reduced-motion.Requires a DeepSeek Harness runtime that can load the plugin, plus a DeepSeek account credential. The package deliberately places no version restriction on DSH: there is no engines.dsh range and the optional @deepseek-ai/dsh peer is *, so the Harness plugin manager does not reject it on version grounds. Any Harness release that provides the plugin APIs it uses will run it; a future release that removes those APIs would fail at load time instead. The plugin resolves DEEPSEEK_API_KEY through the optional harness credential service (~/.dsh/.credentials.yaml) or the environment.
dsh plugin --profile <name> add dsh-balance-plugin
Download dsh-balance-plugin-<version>.tgz from the releases page, then:
dsh plugin --profile <name> add ./dsh-balance-plugin-<version>.tgz
Note: the plugin lives in the plugins/ subdirectory of the dsh-plugins monorepo, so dsh plugin add github:... cannot target it — use the tarball (or npm).
The Desktop app serves the same Web surface, so the plugin runs there unchanged — install it into the app's own desktop profile rather than web, either from the app's Plugins page or with dsh plugin --profile desktop add dsh-balance-plugin while the app is quit (Desktop owns that profile, so its CLI refuses to initialize it from scratch). Verified against Desktop 0.2.0-rc.2: the sidebar action registers and both /dsh-balance routes mount.
For npm installs, update the package in the same profile, confirm that its bundle layer remains active, then restart the Web server:
dsh plugin --profile <name> update dsh-balance-plugin
dsh --profile <name> --dump-config # expect a "# == dsh-balance-plugin" layer
# restart dsh web, then hard-refresh the browser
dsh plugin forwards pnpm commands and reconciles the installed package's dsh.bundle declaration after a successful update. For a Release tarball, run dsh plugin --profile <name> add ./dsh-balance-plugin-<version>.tgz with the newer archive, then perform the same verification and restart.
The plugin ships with sensible defaults; override via the bundle's plugin row:
# profile's cordis.patch.yml (or your home-level one)
- id: balance
name: dsh-balance-plugin
config:
apiKeyEnv: DEEPSEEK_API_KEY # credential reference, then the environment
baseURL: https://api.deepseek.com # provider base URL
timeoutMs: 12000 # per-request timeout; abort maps to balance-timeout
lowBalanceThreshold: 2 # amount at or above which the tint reads healthy
| Half | What it does |
|---|---|
| Host (Node) | Registers authenticated GET /dsh-balance (the wallet readout as JSON) and GET /dsh-balance/events (an SSE stream). Each route passes the Harness browser-auth and Origin fence before reading a credential. It listens on session/event and emits refresh per turn/end, resolving credentials per request through the optional service before falling back to the environment. |
| Client (browser) | Registers the sidebar.footer.action slot entry (the shell's reserved seat beside Settings; on the collapsed rail it stacks above the settings icon). Fetches the readout on mount, on refresh SSE events, and on click, with an in-flight guard. The card icon is self-contained (no dependency on the shell's icon library). |
Position and interaction follow the shell's own design: the sidebar.footer.action hole is the official extension point for "optional actions beside Settings".
The balance looks stale right after a conversation ends. Provider settlement lags the turn by tens of seconds. The turn-end refresh may briefly show the pre-settlement amount; clicking later shows the settled value. This matches the official DeepSeek client behavior — the readout is advisory.
Nothing renders. No credential resolves (unconfigured) or the fetch failed — by design. Check dsh --profile <name> --dump-config for the plugin row, and that DEEPSEEK_API_KEY resolves through the credential seam or the environment.
How do I remove it?
dsh plugin --profile <name> remove dsh-balance-plugin
This removes the dependency and the bundle layer together.
src/
balance-core.ts # pure query logic (credential resolution, HTTP, normalization)
index.ts # host plugin: routes + SSE + turn-end listener
client.tsx # browser plugin: the sidebar-foot action
scripts/build.mjs # esbuild: host ESM + browser __ModuleLoader__ bundle
tests/ # node:test unit tests for balance-core
pnpm install
pnpm run build # emits lib/index.js + lib/client.js
pnpm test # balance-core, float, and host-route unit tests
Local install check (official verification points):
dsh plugin --profile demo add ./
dsh --profile demo --dump-config # expect a "# == dsh-balance-plugin" layer
Before publishing a new version:
pnpm run build and pnpm test pass.dsh plugin --profile demo update dsh-balance-plugin both keep the --dump-config layer; the web profile renders the readout with a real credential.npm version patch/minor/major); git tag matches.pnpm pack — inspect the tarball: it must contain lib/, cordis.patch.yml, README.md (and nothing else heavy).npm publish — publishes prebuilt code, so users install with zero friction.