@alexpeng/dsh-custom-plugin 0.7.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,313 +1,325 @@
1
- # dsh-custom-plugin
2
-
3
- [![npm version](https://img.shields.io/npm/v/%40alexpeng%2Fdsh-custom-plugin?style=flat-square)](https://www.npmjs.com/package/@alexpeng/dsh-custom-plugin)
4
- [![license](https://img.shields.io/badge/license-Apache--2.0-blue?style=flat-square)](LICENSE)
5
- [![Node](https://img.shields.io/badge/node-%3E%3D22-339933?style=flat-square)](#install)
6
- [![TypeScript](https://img.shields.io/badge/TypeScript-5.7-3178C6?style=flat-square&logo=typescript&logoColor=white)](https://www.typescriptlang.org)
7
- [![CI](https://github.com/AlexPeng07/dsh-custom-plugin/actions/workflows/ci.yml/badge.svg)](https://github.com/AlexPeng07/dsh-custom-plugin/actions/workflows/ci.yml)
8
- [![Awesome DSH Plugin](https://awesome-dsh-plugin.com/badge.svg)](https://awesome-dsh-plugin.com)
9
-
10
- English | [中文](README.zh.md)
11
-
12
- Custom convenience suite for the DeepSeek Harness (DSH) Web GUI: personalization, weather FX, glass effects, project folders, enhanced prompts, conversation export/search, Mermaid rendering, quote reply, 7/30/90-day usage analytics, budget and key-free local backups, plus a Ctrl/Cmd+K command palette.
13
-
14
- The plugin is dual-face: the host half (`src/`) owns the state document, registers the `/api/custom-plugin` routes and the `custom_plugin_status` agent tool; the browser half (`src/client/`) injects its UI through eight injections into seven official slots and talks to the host over same-origin fetch. Mounted through the official profile mechanism — no DSH source changes.
15
-
16
- <p align="center">
17
- <img src="https://github.com/AlexPeng07/dsh-custom-plugin/raw/main/docs/overview.png" alt="dsh-custom-plugin overview" width="100%">
18
- </p>
19
-
20
- ## Selected screenshots
21
-
22
- <table>
23
- <tr>
24
- <td width="50%" valign="top"><b>Settings → 个性化: the full-page appearance config</b><br><img src="https://github.com/AlexPeng07/dsh-custom-plugin/raw/main/docs/settings-appearance.png" alt="Settings → 个性化 full appearance page" width="100%"></td>
25
- <td width="50%" valign="top"><b>The same panel as a popover from the session header (light theme)</b><br><img src="https://github.com/AlexPeng07/dsh-custom-plugin/raw/main/docs/personalization-panel.png" alt="Personalization popover" width="100%"></td>
26
- </tr>
27
- <tr>
28
- <td width="50%" valign="top"><b>Liquid glass (displacement refraction on Custom surfaces)</b><br><img src="https://github.com/AlexPeng07/dsh-custom-plugin/raw/main/docs/liquid-glass.png" alt="Liquid glass" width="100%"></td>
29
- <td width="50%" valign="top"><b>Multi-level project folders</b><br><img src="https://github.com/AlexPeng07/dsh-custom-plugin/raw/main/docs/project-folders.png" alt="Project folders" width="100%"></td>
30
- </tr>
31
- <tr>
32
- <td width="50%" valign="top"><b>Mermaid mindmap rendered in place</b><br><img src="https://github.com/AlexPeng07/dsh-custom-plugin/raw/main/docs/mermaid-mindmap.png" alt="Mermaid mindmap" width="100%"></td>
33
- <td width="50%" valign="top" align="center"><b>Balance and today's per-model usage</b><br><img src="https://github.com/AlexPeng07/dsh-custom-plugin/raw/main/docs/balance-usage.png" alt="Balance and usage panel" width="100%"></td>
34
- </tr>
35
- <tr>
36
- <td width="50%" valign="top" align="center"><b>Rain (three depth layers)</b><br><img src="https://github.com/AlexPeng07/dsh-custom-plugin/raw/main/docs/weather-rain.gif" alt="Rain effect" width="100%"></td>
37
- <td width="50%" valign="top" align="center"><b>Sakura</b><br><img src="https://github.com/AlexPeng07/dsh-custom-plugin/raw/main/docs/weather-sakura.gif" alt="Sakura effect" width="100%"></td>
38
- </tr>
39
- <tr>
40
- <td width="50%" valign="top" align="center"><b>Snow</b><br><img src="https://github.com/AlexPeng07/dsh-custom-plugin/raw/main/docs/weather-snow.gif" alt="Snow effect" width="100%"></td>
41
- </tr>
42
- </table>
43
-
44
- Weather FX is shown in dark mode. Usage history, backup-import previews, session search, and the command palette are dynamic views of the same panel; open them inside DSH to inspect the live UI — no additional fixed screenshots are included.
45
-
46
- ## What it does
47
-
48
- ### Appearance
49
-
50
- - **Background colors**: 20 muted low-saturation palettes (each with a matching tab color, `天青灰` by default) plus "no color" (follows the GUI default theme). Every palette works in both themes; dark mode derives the same family's dark variant (hue and low saturation kept, lightness dropped onto the dark ramp), and the swatch preview shows what the current theme will actually paint.
51
- - **Weather FX**: canvas-rendered, pointer-transparent one-click overlays — falling snow, cinematic rain (three depth layers with splashes), and drifting sakura petals; turning it off clears the canvas.
52
- - **Glass**: frosted glass on every Custom surface, or liquid glass (edge displacement refraction chained with a slight blur + saturation so text over large panels stays readable; engines without SVG-referencing backdrop filters fall back to frosted). A global-glass option extends the same treatment to dialogs, menus, tooltips, listboxes and the system settings window — displaced as well in liquid mode.
53
-
54
- ### Project folders
55
-
56
- A multi-level folder tree persisted in the `$DSH_HOME` state file, shared across workspaces. Any workspace or session can be folded in; folders support drag-to-reorder (before / inside / after), rename, delete, and add-current-session shortcuts.
57
-
58
- ### Prompts
59
-
60
- A prompt library with add / edit / copy / delete, search, favorites, tags, drag sorting, recency and use counts. `{{variable}}` placeholders open a fill-in form before insertion. The library supports versioned JSON and heading-based Markdown import/export.
61
-
62
- ### Conversation export
63
-
64
- Export the current session in three formats (file names carry a date stamp):
65
-
66
- - **JSON**: standard `messages` structure (user / assistant / tool), with a meta block carrying the session title, creation time, working directory and export time — importable elsewhere;
67
- - **Markdown**: role-sectioned plain text;
68
- - **PDF**: an A4 print-layout HTML opened in the browser and saved as PDF; images embed as base64 (up to 30 images, 12 MB total, 4 MB each).
69
-
70
- Tool rows carry the tool name and an argument digest (resolved from the paired tool/call events).
71
-
72
- Plugin state can be exported as a versioned JSON backup containing appearance, folders, prompts, stars, usage, and budget settings. API keys and credential metadata are excluded. Imports show a conflict preview, support merge or non-secret replacement, and create a recovery copy first.
73
-
74
- ### Mermaid
75
-
76
- ```mermaid blocks anywhere in the chat — assistant replies included (mindmaps, flowcharts, sequence diagrams, …) — render in place automatically: a diagram/code toggle bar with a mermaid.live fallback link appears above the block, streaming blocks preview once their content is complete, diagrams re-render on GUI theme flips, and a failed render keeps the raw code. Detection keys off the fence language label; with a blank label (mid-stream) a content heuristic decides (keyword prefix + completeness checks, so blocks labeled with a real language are never touched). The engine loads from the mermaid 11 dependency installed with the plugin (works offline), falling back to jsdelivr / fastly / unpkg mirrors and caching in the host process; the render chips under user messages and the multi-diagram modal stay, and the mermaid.live link uses the DEFLATE-compressed `#pako:` format that restores the diagram on open.
77
-
78
- ### Efficiency tools
79
-
80
- - **Quote reply**: select text in the conversation and a "quote reply" button inserts it as a blockquote into the input box;
81
- - **Anti auto-scroll**: force `scroll-behavior: auto` so sends never yank the view to the bottom (off by default);
82
- - **Formula copy**: LaTeX / MathML copy chips under matching messages (MathML pastes into Word);
83
- - **Batch archive**: select sessions and archive them in bulk; running sessions are unavailable and completion reports separate success/failure counts. DSH exposes no restore API yet, so the plugin provides no restore entry point.
84
- - **Session search**: search current-session user, assistant, and tool content and jump to the containing turn; superseded requests are cancelled. DSH's event index is used when the deployment opens one, and otherwise the plugin scans the session log it already read (the panel says which path answered).
85
- - **Command palette**: press `Ctrl+K` / `Cmd+K` outside editors to search sessions, workspaces, prompts, and common actions; cross-session content search uses DSH's official API and reports its own unavailability.
86
- - **Reliable archive**: running sessions are unavailable by default and batch completion reports separate success and failure counts.
87
-
88
- ### Balance and usage
89
-
90
- A usage badge sits in the session header (clickable to pin): with an API key configured it shows the official balance; without one it shows the local cost estimate (e.g. `≈¥0.42`) and today's call count. The panel provides:
91
-
92
- - **Usage and cost (default section, key-free)**: today's and historical usage, budget and the cost estimate all come from local session records — no key required.
93
- - **Balance query (collapsible opt-in, needs an API key)**: the official `https://api.deepseek.com/user/balance` endpoint, CNY preferred, granted and topped-up balances listed separately, with the account availability flag; with no key configured the section stays collapsed and shows no error. The host's outbound call goes over the machine's direct connection (system proxy settings are not read); when a local proxy or security suite intermittently TLS-intercepts HTTPS, the query fails with a readable reason ("TLS certificate verification failed") and retries automatically (8s/30s/30s, with the 60s poll as the backstop) — hover the header pill to see the reason.
94
- - **Key resolution order**: the system credential store (when available) → the legacy plugin state-file key → environment variables `DEEPSEEK_API_KEY` / `DEEPSEEK_KEY` / `DEEPSEEK_TOKEN` (values must start with `sk-`) → the DSH credentials file `$DSH_HOME/.credentials.yaml` (reuses the DeepSeek key already configured in DSH — no duplicate setup). Account-login Desktop installs have no sk- key; that is a normal state.
95
- - **Today's usage**: per-model input / output / cache token counters and call counts, folded live from `session/event` records.
96
- - **Cost estimate**: DeepSeek's current official peak/off-peak table (checked 2026-09-30) — peak hours are Beijing Monday–Friday 09:00–12:00 / 14:00–18:00; all other hours, including weekends, are off-peak at half price: `deepseek-flash` (the retired names `deepseek-v4-flash` / `deepseek-v4-flash-vision-exp` still route at Flash pricing) peaks at ¥2 / ¥8, `deepseek-v4-pro` ¥9 / ¥27 (CNY per 1M tokens, peak in / out). Indicative only.
97
- - **Scan**: "scan today's session logs" replays every session and buckets usage events by their own timestamp (cross-midnight sessions keep contributing today's usage), reporting how many active sessions were scanned.
98
- - **History and budget**: inspect 7 / 30 / 90-day trends and per-model totals, export UTF-8 CSV, and set a local monthly CNY budget with an in-plugin warning threshold.
99
-
100
- ### Settings entry
101
-
102
- The Settings → 个性化 section provides the full appearance and tool-toggle page; the 个性化 buttons in the session header and the sidebar footer open the same panel as a popover.
103
-
104
- ### Agent integration
105
-
106
- The `custom_plugin_status` tool reports appearance config, today's per-model usage, balance, a timeline sample, Mermaid engine state, the state file path and client diagnostics. The plugin never injects system-prompt announcements.
107
-
108
- ## Compatibility
109
-
110
- | plugin release | dsh it was built and verified against | status |
111
- | --- | --- | --- |
112
- | 0.6.x | dsh 0.1.7-rc.2 and dsh 0.2.0-rc.2 (peer range names both; see Install) | this release |
113
- | 0.5.x | dsh 0.1.7-rc.2 (peer range `>=0.1.7-rc.2 <0.2.0-0`) | fine on 0.1.x; refused on any 0.2.x host, including dsh Desktop |
114
- | 0.4.2 | dsh 0.1.1-rc.1 … 0.1.6 era | superseded; do not expect it to work on 0.1.7+ |
115
-
116
- 0.1.7 changed the plugin-facing contracts this suite depends on (session
117
- navigation moved to `ctx.uiWorkspace`, the session list stopped publishing the
118
- viewed session, and the message model dropped the `tool-result` content block),
119
- so neither release substitutes for the other. dsh 0.1.7+ validates a bundle's
120
- `@deepseek-ai/dsh-*` peer ranges against its own version at install and startup
121
- and skips a bundle that does not match. Runtimes predating that gate load the
122
- bundle anyway and degrade instead: on 0.1.1-rc.2, 7 of 8 slot registrations
123
- succeed, the turn-tail entry is rejected (that slot became a list slot back in
124
- 0.1.6-alpha.2), and the open-session / branch / cross-session actions
125
- report their service as missing rather than throwing.
126
-
127
- ## Install
128
-
129
- Prerequisites: Node 22+, pnpm, and the `dsh` CLI (the official `@deepseek-ai/dsh` npm package; `npx @deepseek-ai/dsh` stands in for `dsh` when it is not installed globally). This release targets **dsh 0.1.7-rc.2 through the rest of 0.1.x, plus 0.2.0-rc.2** — dsh checks a bundle's `@deepseek-ai/dsh-*` peer ranges against its own version at install and startup, and skips a bundle that does not match, so `package.json` names only the releases this package was actually built and verified against. 0.7.0 keeps the build target 0.6.0 established (0.2.0-rc.2) and the same peer range; the 0.6.0 artifact ran the live host probes on both runtime lines (0.2.0-rc.2 boot graph of 66 module rows, 0.1.7-rc.2 of 65, 18 of 19 probes passing each, the skip needing a real session), and the 0.7.0 artifact additionally passed the desktop-shape live probe **on a real Desktop install** (see "On dsh Desktop" below). What stays unverified is what was always unverified: the per-turn chips (Mermaid render, LaTeX) need a real model reply, so a credential-free scratch home cannot reach them, and slot rendering still needs a browser pass. The range deliberately excludes 0.2.0-rc.1 (a superseded prerelease), 0.2.0-rc.3 and later prereleases nobody has looked at, and 0.2.0 stable until someone does. Range spelling matters here: `^0.1.7-rc.2` desugars to `>=0.1.7-rc.2 <0.2.0-0`, and every `0.2.0-rc.N` sorts *above* `0.2.0-0`, so a verified prerelease has to be named in its own clause — `pnpm smoke` checks that the build target actually satisfies the declared range and that `engines.dsh` admits the same versions. On an older dsh, install the matching older plugin release (`0.5.0` targets 0.1.7-rc.2) rather than granting a compatibility exemption.
130
-
131
- ### From npm
132
-
133
- ```sh
134
- dsh plugin --profile web add @alexpeng/dsh-custom-plugin
135
- # restart dsh web
136
- ```
137
-
138
- The registry tarball ships prebuilt output — no source build on the installing machine.
139
-
140
- ### On dsh Desktop
141
-
142
- dsh Desktop is an Electron shell around the same Web application, and it bundles
143
- **exactly dsh 0.2.0-rc.2** — the desktop release line pins the shell and the
144
- runtime together, so a Desktop install is always a 0.2.x runtime. 0.7.0 names
145
- that version in its peer range and installs there with no compatibility
146
- exemption; 0.5.0 did not, and was refused with the same message a 0.2.x Web
147
- profile prints.
148
-
149
- Measured against 0.2.0-rc.2: the boot graph carries our row and all five inject
150
- targets, the Mermaid engine loads locally, and the host probes score the same
151
- there as on 0.1.7-rc.2. The access fence shares the platform fence's trust
152
- semantics: a loopback socket naming a loopback Host, a non-`cross-site` marker,
153
- and an Origin that is absent or matches the Host authority. The shell forwards
154
- renderer requests to its own Host after deleting `host`, `origin`,
155
- `sec-fetch-site` and `cookie`, then attaches its own credential — that unmarked
156
- shape is accepted outright (through 0.6.0 the fence additionally required a
157
- same-origin marker and rejected exactly this shape with `forbidden`; fixed in
158
- 0.7.0 with fence-level unit tests). Foreign-origin and cross-site requests are
159
- still 403. **The 0.7.0 artifact has been probed route by route on a real
160
- Desktop install in the desktop forward shape** (upgraded to this build, Desktop
161
- restarted, `scripts/desktop-shape-probe.mjs` run): state / debug / backup /
162
- usage scan / the Mermaid engine preload and script routes all answer 200, and
163
- foreign-origin and cross-site probes still get 403; the timeline, the three
164
- export formats and search are re-checked by the same probe once the GUI has
165
- produced its first session. The visual pass inside the Desktop window (liquid
166
- glass look, panel layout, pattern removal) belongs to whoever installs it.
167
-
168
- Managing the desktop profile takes the `dsh` command that ships with Desktop, not
169
- the npm one — the public CLI refuses the reserved `desktop` profile:
170
-
171
- 1. Start Desktop once so the profile exists, then quit it fully (closing the
172
- window only hides it; on Windows use the tray).
173
- 2. `dsh plugin --profile desktop add @alexpeng/dsh-custom-plugin`
174
- 3. Reopen Desktop. The in-app Plugin Manager installs and updates against the
175
- same profile using Desktop's own bundled pnpm, if you would rather not open a
176
- terminal.
177
-
178
- Appearance, prompt library, project folders, stars and usage all live in
179
- `$DSH_HOME/custom-plugin-state.json`, which Desktop and Web share by design —
180
- each keeps its own `profiles/<name>` for code, never for that file — so
181
- switching between the two shows the same data. Both hosts can therefore write it
182
- at once, which is why the state replace names its temp file after the writing
183
- process.
184
-
185
- ### From GitHub (source install)
186
-
187
- ```sh
188
- dsh plugin --profile web add github:AlexPeng07/dsh-custom-plugin
189
- # restart dsh web
190
- ```
191
-
192
- Git installs pull sources; the `prepare` script builds `lib/` on the installing machine. pnpm ≥10 asks you to approve that build once — copy the exact package key it prints into the profile's `pnpm-workspace.yaml` under `allowBuilds`, then re-run the add. The npm route above skips the build-approval step.
193
-
194
- ### Local link (development)
195
-
196
- ```sh
197
- # build (run from this repo root)
198
- pnpm install
199
- pnpm build
200
- # add to the web profile. The link path must not contain spaces: on Windows,
201
- # create a space-free directory junction first and link to the junction path
202
- dsh plugin --profile web add link:F:/dsh-plugin-dev
203
- # restart dsh web
204
- ```
205
-
206
- The package declares its manifest per the official bundle protocol: `dsh.bundle.patch` in `package.json` points at the `cordis.patch.yml` config layer (row id `custom-plugin`) and `dsh.client` declares the browser half. `dsh plugin add` forwards to pnpm inside the profile directory; the installed package joins `dsh.profile.bundles` automatically because of that declaration, and the browser half loads via the official client module system from the same row.
207
-
208
- ## Config
209
-
210
- The plugin reads and writes one JSON document at `$DSH_HOME/custom-plugin-state.json` (`~/.dsh` by default, overridable via the `DSH_HOME` environment variable): appearance config, folders, prompts, stars, legacy compatibility data, and a 90-day per-day usage ledger. Writes are atomic (temp file + rename), so a crash never truncates the document.
211
-
212
- Appearance and feature toggles (the `cfg` field, all with defaults):
213
-
214
- | Key | Default | Meaning |
215
- |---|---|---|
216
- | `bg` | `天青灰` | `default` (no color) / one of the 20 palette names (both themes; a stored `aurora` migrates to `default`) |
217
- | `weather` | `none` | `none` / `snow` / `rain` / `sakura` |
218
- | `glass` | `true` | master glass toggle for Custom surfaces |
219
- | `glassMode` | `frost` | `frost` frosted / `liquid` displacement glass |
220
- | `globalGlass` | `true` | blur global overlays (dialogs/menus/tooltips) |
221
- | `quote` | `true` | selection quote reply |
222
- | `antiScroll` | `false` | anti auto-scroll |
223
- | `mermaid` | `true` | automatic in-place Mermaid rendering (plus render chips) |
224
- | `formula` | `true` | LaTeX / MathML copy chips |
225
- | `monthlyBudgetCny` | `0` | Monthly CNY budget; `0` disables warnings |
226
- | `budgetWarningPercent` | `80` | Monthly warning threshold (1–100) |
227
-
228
- ## Security model
229
-
230
- - The browser talks to the host only through loopback `/api/custom-plugin` routes; every route checks a loopback socket address, a loopback Host header, and browser same-origin markers (`sec-fetch-site` / `Origin`). `X-Forwarded-For` is never trusted.
231
- - The browser never receives the saved DeepSeek API key. New panel keys use the OS credential store through `keytar` when it is present; older plaintext state keys are migrated on startup when that store is available. `keytar` ships as no dependency of this plugin (a native module would trip pnpm 11's strict build gate and silently keep the whole bundle from activating); users who want the OS keyring can add it to the profile themselves: `dsh plugin --profile web add keytar`.
232
- - If the OS credential store is unavailable, the plugin keeps a compatibility fallback in `$DSH_HOME/custom-plugin-state.json`; protect `$DSH_HOME` accordingly. DSH's own `$DSH_HOME/.credentials.yaml` remains a supported plaintext fallback.
233
- - Conversation exports and timeline data stay on the local host.
234
-
235
- ## Known limitations
236
-
237
- - The Mermaid engine comes from the dependency installed with the plugin and works offline; only a missing dependency falls back to a CDN fetch (cached for the host process lifetime).
238
- - The usage ledger folds token counts from live `session/event` records, retains 90 Beijing calendar days, and a manual "scan" re-reads today's session logs with four concurrent reads when live events were missed.
239
- - The balance panel shows the peak/off-peak token and cost split plus a link to the official pricing page; legacy rows without peak counters are marked inexact and excluded from cost totals until rescanned.
240
- - OS credential storage detects a `keytar` module present in the profile's `node_modules` when the host starts; when it cannot be loaded, the compatibility state-file fallback is used.
241
- - Cost estimates use DeepSeek's official peak/off-peak list prices and are indicative only.
242
- - Palettes derive a same-family dark variant in dark mode (hue and low saturation kept).
243
- - DSH currently exposes no archive-restore API; the plugin does not bypass that boundary by editing the underlying registry.
244
- - The command palette owns `Ctrl+K` / `Cmd+K` (no Alt/Shift, ignored inside editors). dsh's own default on the **web** profile is `Ctrl+Alt+K` (the desktop default is plain `Ctrl+K`), so nothing collides out of the box — but dsh 0.1.7 lets you rebind host shortcuts, and if you assign a host command to plain `Ctrl+K`, both fire. Keep the palette key reserved, or pick another binding there.
245
- - dsh's shipped `web` profile composes its session-query index with `openAt: never`, so full-text search is off unless the deployment enables it. In-session search therefore answers from a direct log scan (ordered, capped at 100 hits) and the palette's cross-session search shows dsh's own refusal.
246
-
247
- ## Development
248
-
249
- ```sh
250
- pnpm typecheck # type check
251
- pnpm test # vitest unit tests
252
- pnpm build # build the node ESM library and the browser bundle into lib/
253
- pnpm check:readme # bilingual README hash consistency
254
- pnpm smoke # post-build contract checks: loader handshake, manifest
255
- # fields dsh reads, patch row, local Mermaid engine
256
- ```
257
-
258
- `scripts/live-dsh-check.sh` is a separate, manual probe against a **running**
259
- isolated dsh profile (`DSH_HOME=… DSH_PORT=… bash scripts/live-dsh-check.sh`):
260
- it exercises the host half on real session data — timeline, the three export
261
- formats, the search scan path, usage scan, backup, the Mermaid engine route, the
262
- client→host diagnostic ring, a UTF-8 state round trip that restores and then
263
- verifies your prompt library, and the three trust-fence shapes (an unmarked
264
- loopback request passes, a foreign Origin and a cross-site marker are
265
- rejected). It refuses to run against a
266
- real `~/.dsh` unless you set `ALLOW_REAL_DSH_HOME=1`, reports `PASS`/`FAIL` per
267
- probe, counts and names anything it `SKIP`s, and exits non-zero on any failure.
268
- CI has no harness to talk to, so run it whenever a dsh release lands; slot
269
- registration and rendering still need the browser pass described above.
270
-
271
- `scripts/desktop-shape-probe.mjs` is a third probe, aimed at a **running dsh
272
- Desktop** (its Host listens on `127.0.0.1:19387` by default, override with
273
- `DSH_PORT`): it probes state / debug / backup / usage scan / the Mermaid engine
274
- and script routes in the exact header shape the desktop shell forwards (loopback
275
- Host, no `origin`, no `sec-fetch-site`), then runs timeline, the three export
276
- formats and search against the first session the host has registered; the
277
- foreign-origin and cross-site probes must still come back 403. It is read-only
278
- against the real home; if the GUI has no session yet, send one message there and
279
- re-run.
280
-
281
- Checking a new dsh release takes four commands, and never touches your own
282
- harness home:
283
-
284
- ```bash
285
- mkdir -p /tmp/dshnext && cd /tmp/dshnext && npm init -y && npm i @deepseek-ai/dsh@<version>
286
- DSH_HOME=/tmp/dshnext-home node node_modules/@deepseek-ai/dsh/lib/bin.js plugin --profile web add <packed.tgz>
287
- DSH_HOME=/tmp/dshnext-home node node_modules/@deepseek-ai/dsh/lib/bin.js --profile web --no-open --port 13999 &
288
- DSH_HOME=/tmp/dshnext-home DSH_PORT=13999 COOKIE_JAR=/tmp/dshnext/jar.txt bash scripts/live-dsh-check.sh
289
- ```
290
-
291
- If the release falls outside the declared peer range, the second command refuses
292
- and rolls the profile back; `dsh plugin --profile web allow-version <pkg>@<ver>
293
- --dsh-version <version> --accept-risk` grants the exact-version exemption, so the
294
- probe can tell you *what* actually breaks instead of what the gate already
295
- refused.
296
-
297
- For a **dsh Desktop** release, start one step earlier, because the repository
298
- cannot tell you what an installer runs: Desktop pins its shell and
299
- `@deepseek-ai/dsh` to one exact version and ships the whole runtime inside
300
- `resources/app.asar`. Read it off the installed app instead — the command is
301
- read-only, and it prints that version together with whether the peer range
302
- declared here admits it:
303
-
304
- ```bash
305
- node scripts/desktop-runtime.mjs "D:/DSH" # the installation dir
306
- node scripts/desktop-runtime.mjs "D:/DSH/resources/app.asar" # or the archive itself
307
- ```
308
-
309
- Then run the four commands above against the version it names.
310
-
311
- ## License
312
-
313
- Apache-2.0. Portions of the code reference [Nagi-ovo/voyager](https://github.com/Nagi-ovo/voyager) and [unovue/inspira-ui](https://github.com/unovue/inspira-ui).
1
+ # dsh-custom-plugin
2
+
3
+ [![npm version](https://img.shields.io/npm/v/%40alexpeng%2Fdsh-custom-plugin?style=flat-square)](https://www.npmjs.com/package/@alexpeng/dsh-custom-plugin)
4
+ [![license](https://img.shields.io/badge/license-Apache--2.0-blue?style=flat-square)](LICENSE)
5
+ [![Node](https://img.shields.io/badge/node-%3E%3D22-339933?style=flat-square)](#install)
6
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.7-3178C6?style=flat-square&logo=typescript&logoColor=white)](https://www.typescriptlang.org)
7
+ [![CI](https://github.com/AlexPeng07/dsh-custom-plugin/actions/workflows/ci.yml/badge.svg)](https://github.com/AlexPeng07/dsh-custom-plugin/actions/workflows/ci.yml)
8
+ [![Awesome DSH Plugin](https://awesome-dsh-plugin.com/badge.svg)](https://awesome-dsh-plugin.com)
9
+
10
+ <p align="center">
11
+ <img src="https://www.npm.bet/svg?q=%40alexpeng%2Fdsh-custom-plugin&amp;timeRange=last-month&amp;grouping=day&amp;metric=downloads&amp;zeroMode=estimated" alt="npm downloads, last month" width="560">
12
+ </p>
13
+
14
+ English | [中文](README.zh.md)
15
+
16
+ Custom convenience suite for the DeepSeek Harness (DSH) Web GUI: personalization, weather FX, glass effects, project folders, enhanced prompts, conversation export/search, Mermaid rendering, quote reply, 7/30/90-day usage analytics, budget and key-free local backups, plus a Ctrl/Cmd+K command palette.
17
+
18
+ The plugin is dual-face: the host half (`src/`) owns the state document, registers the `/api/custom-plugin` routes and the `custom_plugin_status` agent tool; the browser half (`src/client/`) injects its UI through eight injections into seven official slots and talks to the host over same-origin fetch. Mounted through the official profile mechanism — no DSH source changes.
19
+
20
+ <p align="center">
21
+ <img src="https://github.com/AlexPeng07/dsh-custom-plugin/raw/main/docs/overview.png" alt="dsh-custom-plugin overview" width="100%">
22
+ </p>
23
+
24
+ ## Selected screenshots
25
+
26
+ <table>
27
+ <tr>
28
+ <td width="50%" valign="top"><b>Settings → 个性化: the full-page appearance config</b><br><img src="https://github.com/AlexPeng07/dsh-custom-plugin/raw/main/docs/settings-appearance.png" alt="Settings → 个性化 full appearance page" width="100%"></td>
29
+ <td width="50%" valign="top"><b>The same panel as a popover from the session header (light theme)</b><br><img src="https://github.com/AlexPeng07/dsh-custom-plugin/raw/main/docs/personalization-panel.png" alt="Personalization popover" width="100%"></td>
30
+ </tr>
31
+ <tr>
32
+ <td width="50%" valign="top"><b>Liquid glass (displacement refraction on Custom surfaces)</b><br><img src="https://github.com/AlexPeng07/dsh-custom-plugin/raw/main/docs/liquid-glass.png" alt="Liquid glass" width="100%"></td>
33
+ <td width="50%" valign="top"><b>Multi-level project folders</b><br><img src="https://github.com/AlexPeng07/dsh-custom-plugin/raw/main/docs/project-folders.png" alt="Project folders" width="100%"></td>
34
+ </tr>
35
+ <tr>
36
+ <td width="50%" valign="top"><b>Mermaid mindmap rendered in place</b><br><img src="https://github.com/AlexPeng07/dsh-custom-plugin/raw/main/docs/mermaid-mindmap.png" alt="Mermaid mindmap" width="100%"></td>
37
+ <td width="50%" valign="top" align="center"><b>Balance and today's per-model usage</b><br><img src="https://github.com/AlexPeng07/dsh-custom-plugin/raw/main/docs/balance-usage.png" alt="Balance and usage panel" width="100%"></td>
38
+ </tr>
39
+ <tr>
40
+ <td width="50%" valign="top" align="center"><b>Rain (three depth layers)</b><br><img src="https://github.com/AlexPeng07/dsh-custom-plugin/raw/main/docs/weather-rain.gif" alt="Rain effect" width="100%"></td>
41
+ <td width="50%" valign="top" align="center"><b>Sakura</b><br><img src="https://github.com/AlexPeng07/dsh-custom-plugin/raw/main/docs/weather-sakura.gif" alt="Sakura effect" width="100%"></td>
42
+ </tr>
43
+ <tr>
44
+ <td width="50%" valign="top" align="center"><b>Snow</b><br><img src="https://github.com/AlexPeng07/dsh-custom-plugin/raw/main/docs/weather-snow.gif" alt="Snow effect" width="100%"></td>
45
+ </tr>
46
+ </table>
47
+
48
+ Weather FX is shown in dark mode. Usage history, backup-import previews, session search, and the command palette are dynamic views of the same panel; open them inside DSH to inspect the live UI — no additional fixed screenshots are included.
49
+
50
+ ## What it does
51
+
52
+ ### Appearance
53
+
54
+ - **Background colors**: 20 muted low-saturation palettes (each with a matching tab color, `天青灰` by default) plus "no color" (follows the GUI default theme). Every palette works in both themes; dark mode derives the same family's dark variant (hue and low saturation kept, lightness dropped onto the dark ramp), and the swatch preview shows what the current theme will actually paint.
55
+ - **Weather FX**: canvas-rendered, pointer-transparent one-click overlays — falling snow, cinematic rain (three depth layers with splashes), and drifting sakura petals; turning it off clears the canvas.
56
+ - **Glass**: frosted glass on every Custom surface, or liquid glass (edge displacement refraction chained with a slight blur + saturation so text over large panels stays readable; engines without SVG-referencing backdrop filters fall back to frosted). A global-glass option extends the same treatment to dialogs, menus, tooltips, listboxes and the system settings window — displaced as well in liquid mode.
57
+
58
+ ### Project folders
59
+
60
+ A multi-level folder tree persisted in the `$DSH_HOME` state file, shared across workspaces. Any workspace or session can be folded in; folders support drag-to-reorder (before / inside / after), rename, delete, and add-current-session shortcuts.
61
+
62
+ ### Prompts
63
+
64
+ A prompt library with add / edit / copy / delete, search, favorites, tags, drag sorting, recency and use counts. `{{variable}}` placeholders open a fill-in form before insertion. The library supports versioned JSON and heading-based Markdown import/export.
65
+
66
+ ### Conversation export
67
+
68
+ Export the current session in three formats (file names carry a date stamp):
69
+
70
+ - **JSON**: standard `messages` structure (user / assistant / tool), with a meta block carrying the session title, creation time, working directory and export time — importable elsewhere;
71
+ - **Markdown**: role-sectioned plain text;
72
+ - **PDF**: an A4 print-layout HTML opened in the browser and saved as PDF; images embed as base64 (up to 30 images, 12 MB total, 4 MB each).
73
+
74
+ Tool rows carry the tool name and an argument digest (resolved from the paired tool/call events).
75
+
76
+ Plugin state can be exported as a versioned JSON backup containing appearance, folders, prompts, stars, usage, and budget settings. API keys and credential metadata are excluded. Imports show a conflict preview, support merge or non-secret replacement, and create a recovery copy first.
77
+
78
+ ### Mermaid
79
+
80
+ ```mermaid blocks anywhere in the chat — assistant replies included (mindmaps, flowcharts, sequence diagrams, …) — render in place automatically: a diagram/code toggle bar with a mermaid.live fallback link appears above the block, streaming blocks preview once their content is complete, diagrams re-render on GUI theme flips, and a failed render keeps the raw code. Detection keys off the fence language label; with a blank label (mid-stream) a content heuristic decides (keyword prefix + completeness checks, so blocks labeled with a real language are never touched). The engine loads from the mermaid 11 dependency installed with the plugin (works offline), falling back to jsdelivr / fastly / unpkg mirrors and caching in the host process; the render chips under user messages and the multi-diagram modal stay, and the mermaid.live link uses the DEFLATE-compressed `#pako:` format that restores the diagram on open.
81
+
82
+ ### Efficiency tools
83
+
84
+ - **Quote reply**: select text in the conversation and a "quote reply" button inserts it as a blockquote into the input box;
85
+ - **Anti auto-scroll**: force `scroll-behavior: auto` so sends never yank the view to the bottom (off by default);
86
+ - **Formula copy**: LaTeX / MathML copy chips under matching messages (MathML pastes into Word);
87
+ - **Batch archive**: select sessions and archive them in bulk; running sessions are unavailable and completion reports separate success/failure counts. DSH exposes no restore API yet, so the plugin provides no restore entry point.
88
+ - **Session search**: search current-session user, assistant, and tool content and jump to the containing turn; superseded requests are cancelled. DSH's event index is used when the deployment opens one, and otherwise the plugin scans the session log it already read (the panel says which path answered).
89
+ - **Command palette**: press `Ctrl+K` / `Cmd+K` outside editors to search sessions, workspaces, prompts, and common actions; cross-session content search uses DSH's official API and reports its own unavailability.
90
+ - **Reliable archive**: running sessions are unavailable by default and batch completion reports separate success and failure counts.
91
+
92
+ ### Balance and usage
93
+
94
+ A usage badge sits in the session header (clickable to pin): with an API key configured it shows the official balance; without one it shows the local cost estimate (e.g. `≈¥0.42`) and today's call count. The panel provides:
95
+
96
+ - **Usage and cost (default section, key-free)**: today's and historical usage, budget and the cost estimate all come from local session records — no key required.
97
+ - **Balance query (collapsible opt-in, needs an API key)**: the official `https://api.deepseek.com/user/balance` endpoint, CNY preferred, granted and topped-up balances listed separately, with the account availability flag; with no key configured the section stays collapsed and shows no error. The host's outbound call goes over the machine's direct connection (system proxy settings are not read); when a local proxy or security suite intermittently TLS-intercepts HTTPS, the query fails with a readable reason ("TLS certificate verification failed") and retries automatically (8s/30s/30s, with the 60s poll as the backstop) — hover the header pill to see the reason.
98
+ - **Key resolution order**: the system credential store (when available) → the legacy plugin state-file key → environment variables `DEEPSEEK_API_KEY` / `DEEPSEEK_KEY` / `DEEPSEEK_TOKEN` (values must start with `sk-`) → the DSH credentials file `$DSH_HOME/.credentials.yaml` (reuses the DeepSeek key already configured in DSH — no duplicate setup). Account-login Desktop installs have no sk- key; that is a normal state.
99
+ - **Today's usage**: per-model input / output / cache token counters and call counts, folded live from `session/event` records.
100
+ - **Cost estimate**: DeepSeek's current official peak/off-peak table (checked 2026-09-30) — peak hours are Beijing Monday–Friday 09:00–12:00 / 14:00–18:00; all other hours, including weekends, are off-peak at half price: `deepseek-flash` (the retired names `deepseek-v4-flash` / `deepseek-v4-flash-vision-exp` still route at Flash pricing) peaks at ¥2 / ¥8, `deepseek-v4-pro` ¥9 / ¥27 (CNY per 1M tokens, peak in / out). Indicative only.
101
+ - **Scan**: "scan today's session logs" replays every session and buckets usage events by their own timestamp (cross-midnight sessions keep contributing today's usage), reporting how many active sessions were scanned.
102
+ - **History and budget**: inspect 7 / 30 / 90-day trends and per-model totals, export UTF-8 CSV, and set a local monthly CNY budget with an in-plugin warning threshold.
103
+
104
+ ### Settings entry
105
+
106
+ The Settings → 个性化 section provides the full appearance and tool-toggle page; the 个性化 buttons in the session header and the sidebar footer open the same panel as a popover.
107
+
108
+ ### Agent integration
109
+
110
+ The `custom_plugin_status` tool reports appearance config, today's per-model usage, balance, a timeline sample, Mermaid engine state, the state file path and client diagnostics. The plugin never injects system-prompt announcements.
111
+
112
+ ## Compatibility
113
+
114
+ | plugin release | dsh it was built and verified against | status |
115
+ | --- | --- | --- |
116
+ | 0.8.x | dsh 0.1.7-rc.2, dsh 0.2.0-rc.2 and dsh 0.2.1-rc.2 (both gates name all three; see Install) | this release |
117
+ | 0.7.x | dsh 0.1.7-rc.2 and dsh 0.2.0-rc.2 | previous; refused on dsh 0.2.1-rc.2 |
118
+ | 0.6.x | dsh 0.1.7-rc.2 and dsh 0.2.0-rc.2 | previous; refused on dsh 0.2.1-rc.2 |
119
+ | 0.5.x | dsh 0.1.7-rc.2 (peer range `>=0.1.7-rc.2 <0.2.0-0`) | fine on 0.1.x; refused on any 0.2.x host, including dsh Desktop |
120
+ | 0.4.2 | dsh 0.1.1-rc.1 … 0.1.6 era | superseded; do not expect it to work on 0.1.7+ |
121
+
122
+ 0.1.7 changed the plugin-facing contracts this suite depends on (session
123
+ navigation moved to `ctx.uiWorkspace`, the session list stopped publishing the
124
+ viewed session, and the message model dropped the `tool-result` content block),
125
+ so neither release substitutes for the other. dsh 0.2.1-alpha.4 changed the
126
+ compatibility gate itself: it reads `engines.dsh` first and falls back to the
127
+ `@deepseek-ai/dsh-*` peer ranges only when `engines.dsh` is absent. This package
128
+ declares the same range in both places; older hosts read the peers, newer hosts
129
+ read `engines.dsh`, and `pnpm smoke` fails if the two ever disagree. A bundle
130
+ whose range does not match is skipped at install and startup. Runtimes
131
+ predating that gate load the bundle anyway and degrade instead: on 0.1.1-rc.2,
132
+ 7 of 8 slot registrations succeed, the turn-tail entry is rejected (that slot
133
+ became a list slot back in 0.1.6-alpha.2), and the open-session / branch /
134
+ cross-session actions report their service as missing rather than throwing.
135
+
136
+ ## Install
137
+
138
+ Prerequisites: Node 22+, pnpm, and the `dsh` CLI (the official `@deepseek-ai/dsh` npm package; `npx @deepseek-ai/dsh` stands in for `dsh` when it is not installed globally). This release targets **dsh 0.1.7-rc.2 through the rest of 0.1.x, plus 0.2.0-rc.2 and 0.2.1-rc.2** — dsh 0.2.1-alpha.4 and later check `engines.dsh` first and fall back to the `@deepseek-ai/dsh-*` peer ranges only when it is absent, while older hosts read the peers; this package declares the same range in both places and skips nothing it was not built for. 0.8.0 moves the build and test cohort to 0.2.1-rc.2. The artifact was installed with Desktop's own CLI into an isolated 0.2.1-rc.2 profile **with no compatibility exemption**, then booted for real: a 70-row boot graph, all five `dsh.client.inject` targets, the client bundle served at about 200 KB, the local Mermaid engine (3.57 MB), the state / usage / backup routes, a UTF-8 round trip and the desktop-forward trust shape all passed (16 live probes pass, 1 skip; the skip is timeline/export/search on a profile with no session, covered by unit tests and unchanged in 0.2.1 apart from an optional `formatStatus` field). The 0.6.0 artifact ran the live host probes on 0.2.0-rc.2 (66 rows) and 0.1.7-rc.2 (65 rows), 18 of 19 each, and 0.7.0 additionally passed the desktop-shape probe **on a real Desktop install** (see "On dsh Desktop" below). What stays unverified is what was always unverified: the per-turn chips (Mermaid render, LaTeX) need a real model reply, so a credential-free scratch home cannot reach them, and slot rendering still needs a browser pass. The range deliberately excludes 0.2.0-rc.1 (a superseded prerelease), 0.2.0-rc.3 and later prereleases nobody has looked at, and 0.2.0 stable; likewise 0.2.1-alpha.x, 0.2.1-rc.3 and later, and 0.2.1 stable. Range spelling matters here: `^0.1.7-rc.2` desugars to `>=0.1.7-rc.2 <0.2.0-0`, and every `0.2.0-rc.N` sorts *above* `0.2.0-0`, so a verified prerelease has to be named in its own clause — `pnpm smoke` checks that the build target actually satisfies the declared range and that `engines.dsh` admits exactly the same versions as the peer range. On an older dsh, install the matching older plugin release (`0.5.0` targets 0.1.7-rc.2) rather than granting a compatibility exemption.
139
+
140
+ ### From npm
141
+
142
+ ```sh
143
+ dsh plugin --profile web add @alexpeng/dsh-custom-plugin
144
+ # restart dsh web
145
+ ```
146
+
147
+ The registry tarball ships prebuilt output — no source build on the installing machine.
148
+
149
+ ### On dsh Desktop
150
+
151
+ dsh Desktop is an Electron shell around the same Web application, and it bundles
152
+ **exactly dsh 0.2.1-rc.2** as of 2026-10-17 — the desktop release line pins the
153
+ shell and the runtime together, so a Desktop install is always one exact 0.2.x
154
+ runtime. 0.8.0 names that version in `engines.dsh` and in the peer range and
155
+ installs there with no compatibility exemption; 0.7.1 and earlier are refused by
156
+ the 0.2.1 gate with the same message a 0.2.x Web profile prints.
157
+
158
+ Measured against 0.2.1-rc.2: the boot graph carries our row and all five inject
159
+ targets (70 module rows), our client bundle is served at about 200 KB, the
160
+ Mermaid engine loads locally, and the live host probes pass 16 / skip 1 (the
161
+ session-path skip needs a real session). The access fence shares the platform
162
+ fence's trust semantics: a loopback socket naming a loopback Host, a
163
+ non-`cross-site` marker, and an Origin that is absent or matches the Host
164
+ authority. The shell forwards renderer requests to its own Host after deleting
165
+ `host`, `origin`, `sec-fetch-site` and `cookie`, then attaches its own
166
+ credential — that unmarked shape is accepted outright (through 0.6.0 the fence
167
+ additionally required a same-origin marker and rejected exactly this shape with
168
+ `forbidden`; fixed in 0.7.0 with fence-level unit tests). Foreign-origin and
169
+ cross-site requests are still 403. **The 0.7.0 artifact was probed route by
170
+ route on a real Desktop install in the desktop forward shape** (state / debug /
171
+ backup / usage scan / the Mermaid engine preload and script routes all 200;
172
+ foreign-origin and cross-site probes still 403), and 0.8.0 repeats the same
173
+ shape against a booted 0.2.1-rc.2 host. The visual pass inside the Desktop
174
+ window (liquid glass look, panel layout, pattern removal) belongs to whoever
175
+ installs it.
176
+
177
+ Managing the desktop profile takes the `dsh` command that ships with Desktop, not
178
+ the npm one — the public CLI refuses the reserved `desktop` profile:
179
+
180
+ 1. Start Desktop once so the profile exists, then quit it fully (closing the
181
+ window only hides it; on Windows use the tray).
182
+ 2. `dsh plugin --profile desktop add @alexpeng/dsh-custom-plugin`
183
+ 3. Reopen Desktop. The in-app Plugin Manager installs and updates against the
184
+ same profile using Desktop's own bundled pnpm, if you would rather not open a
185
+ terminal.
186
+
187
+ Appearance, prompt library, project folders, stars and usage all live in
188
+ `$DSH_HOME/custom-plugin-state.json`, which Desktop and Web share by design —
189
+ each keeps its own `profiles/<name>` for code, never for that file — so
190
+ switching between the two shows the same data. Both hosts can therefore write it
191
+ at once, which is why the state replace names its temp file after the writing
192
+ process.
193
+
194
+ ### From GitHub (source install)
195
+
196
+ ```sh
197
+ dsh plugin --profile web add github:AlexPeng07/dsh-custom-plugin
198
+ # restart dsh web
199
+ ```
200
+
201
+ Git installs pull sources; the `prepare` script builds `lib/` on the installing machine. pnpm ≥10 asks you to approve that build once — copy the exact package key it prints into the profile's `pnpm-workspace.yaml` under `allowBuilds`, then re-run the add. The npm route above skips the build-approval step.
202
+
203
+ ### Local link (development)
204
+
205
+ ```sh
206
+ # build (run from this repo root)
207
+ pnpm install
208
+ pnpm build
209
+ # add to the web profile. The link path must not contain spaces: on Windows,
210
+ # create a space-free directory junction first and link to the junction path
211
+ dsh plugin --profile web add link:F:/dsh-plugin-dev
212
+ # restart dsh web
213
+ ```
214
+
215
+ The package declares its manifest per the official bundle protocol: `dsh.bundle.patch` in `package.json` points at the `cordis.patch.yml` config layer (row id `custom-plugin`) and `dsh.client` declares the browser half. `dsh plugin add` forwards to pnpm inside the profile directory; the installed package joins `dsh.profile.bundles` automatically because of that declaration, and the browser half loads via the official client module system from the same row.
216
+
217
+ ## Config
218
+
219
+ The plugin reads and writes one JSON document at `$DSH_HOME/custom-plugin-state.json` (`~/.dsh` by default, overridable via the `DSH_HOME` environment variable): appearance config, folders, prompts, stars, legacy compatibility data, and a 90-day per-day usage ledger. Writes are atomic (temp file + rename), so a crash never truncates the document.
220
+
221
+ Appearance and feature toggles (the `cfg` field, all with defaults):
222
+
223
+ | Key | Default | Meaning |
224
+ |---|---|---|
225
+ | `bg` | `天青灰` | `default` (no color) / one of the 20 palette names (both themes; a stored `aurora` migrates to `default`) |
226
+ | `weather` | `none` | `none` / `snow` / `rain` / `sakura` |
227
+ | `glass` | `true` | master glass toggle for Custom surfaces |
228
+ | `glassMode` | `frost` | `frost` frosted / `liquid` displacement glass |
229
+ | `globalGlass` | `true` | blur global overlays (dialogs/menus/tooltips) |
230
+ | `quote` | `true` | selection quote reply |
231
+ | `antiScroll` | `false` | anti auto-scroll |
232
+ | `mermaid` | `true` | automatic in-place Mermaid rendering (plus render chips) |
233
+ | `formula` | `true` | LaTeX / MathML copy chips |
234
+ | `monthlyBudgetCny` | `0` | Monthly CNY budget; `0` disables warnings |
235
+ | `budgetWarningPercent` | `80` | Monthly warning threshold (1–100) |
236
+
237
+ ## Security model
238
+
239
+ - The browser talks to the host only through loopback `/api/custom-plugin` routes; every route checks a loopback socket address, a loopback Host header, and browser same-origin markers (`sec-fetch-site` / `Origin`). `X-Forwarded-For` is never trusted.
240
+ - The browser never receives the saved DeepSeek API key. New panel keys use the OS credential store through `keytar` when it is present; older plaintext state keys are migrated on startup when that store is available. `keytar` ships as no dependency of this plugin (a native module would trip pnpm 11's strict build gate and silently keep the whole bundle from activating); users who want the OS keyring can add it to the profile themselves: `dsh plugin --profile web add keytar`.
241
+ - If the OS credential store is unavailable, the plugin keeps a compatibility fallback in `$DSH_HOME/custom-plugin-state.json`; protect `$DSH_HOME` accordingly. DSH's own `$DSH_HOME/.credentials.yaml` remains a supported plaintext fallback.
242
+ - Conversation exports and timeline data stay on the local host.
243
+
244
+ ## Known limitations
245
+
246
+ - The Mermaid engine comes from the dependency installed with the plugin and works offline; only a missing dependency falls back to a CDN fetch (cached for the host process lifetime).
247
+ - The usage ledger folds token counts from live `session/event` records, retains 90 Beijing calendar days, and a manual "scan" re-reads today's session logs with four concurrent reads when live events were missed.
248
+ - The balance panel shows the peak/off-peak token and cost split plus a link to the official pricing page; legacy rows without peak counters are marked inexact and excluded from cost totals until rescanned.
249
+ - OS credential storage detects a `keytar` module present in the profile's `node_modules` when the host starts; when it cannot be loaded, the compatibility state-file fallback is used.
250
+ - Cost estimates use DeepSeek's official peak/off-peak list prices and are indicative only.
251
+ - Palettes derive a same-family dark variant in dark mode (hue and low saturation kept).
252
+ - DSH currently exposes no archive-restore API; the plugin does not bypass that boundary by editing the underlying registry.
253
+ - The command palette owns `Ctrl+K` / `Cmd+K` (no Alt/Shift, ignored inside editors). dsh's own default on the **web** profile is `Ctrl+Alt+K` (the desktop default is plain `Ctrl+K`), so nothing collides out of the box — but dsh 0.1.7 lets you rebind host shortcuts, and if you assign a host command to plain `Ctrl+K`, both fire. Keep the palette key reserved, or pick another binding there.
254
+ - dsh's shipped `web` profile composes its session-query index with `openAt: never`, so full-text search is off unless the deployment enables it. In-session search therefore answers from a direct log scan (ordered, capped at 100 hits) and the palette's cross-session search shows dsh's own refusal.
255
+
256
+ ## Development
257
+
258
+ ```sh
259
+ pnpm typecheck # type check
260
+ pnpm test # vitest unit tests
261
+ pnpm build # build the node ESM library and the browser bundle into lib/
262
+ pnpm check:readme # bilingual README hash consistency
263
+ pnpm smoke # post-build contract checks: loader handshake, manifest
264
+ # fields dsh reads, patch row, local Mermaid engine
265
+ ```
266
+
267
+ `scripts/live-dsh-check.sh` is a separate, manual probe against a **running**
268
+ isolated dsh profile (`DSH_HOME=… DSH_PORT=… bash scripts/live-dsh-check.sh`):
269
+ it exercises the host half on real session data — timeline, the three export
270
+ formats, the search scan path, usage scan, backup, the Mermaid engine route, the
271
+ client→host diagnostic ring, a UTF-8 state round trip that restores and then
272
+ verifies your prompt library, and the three trust-fence shapes (an unmarked
273
+ loopback request passes, a foreign Origin and a cross-site marker are
274
+ rejected). It refuses to run against a
275
+ real `~/.dsh` unless you set `ALLOW_REAL_DSH_HOME=1`, reports `PASS`/`FAIL` per
276
+ probe, counts and names anything it `SKIP`s, and exits non-zero on any failure.
277
+ CI has no harness to talk to, so run it whenever a dsh release lands; slot
278
+ registration and rendering still need the browser pass described above.
279
+
280
+ `scripts/desktop-shape-probe.mjs` is a third probe, aimed at a **running dsh
281
+ Desktop**. Desktop 0.2.1+ asks the OS for its port, so pass the port it printed
282
+ (or is listening on) as `DSH_PORT` — older releases listened on 19387. It probes
283
+ state / debug / backup / usage scan / the Mermaid engine and script routes in the
284
+ exact header shape the desktop shell forwards (loopback Host, no `origin`, no
285
+ `sec-fetch-site`), then runs timeline, the three export formats and search
286
+ against the first session the host has registered; the foreign-origin and
287
+ cross-site probes must still come back 403. The usage-scan probe rewrites
288
+ today's usage ledger, so point `DSH_HOME` at a scratch home when that matters;
289
+ the other probes are read-only. If the GUI has no session yet, send one message
290
+ there and re-run.
291
+
292
+ Checking a new dsh release takes four commands, and never touches your own
293
+ harness home:
294
+
295
+ ```bash
296
+ mkdir -p /tmp/dshnext && cd /tmp/dshnext && npm init -y && npm i @deepseek-ai/dsh@<version>
297
+ DSH_HOME=/tmp/dshnext-home node node_modules/@deepseek-ai/dsh/lib/bin.js plugin --profile web add <packed.tgz>
298
+ DSH_HOME=/tmp/dshnext-home node node_modules/@deepseek-ai/dsh/lib/bin.js --profile web --no-open --port 13999 &
299
+ DSH_HOME=/tmp/dshnext-home DSH_PORT=13999 COOKIE_JAR=/tmp/dshnext/jar.txt bash scripts/live-dsh-check.sh
300
+ ```
301
+
302
+ If the release falls outside the declared range (`engines.dsh` on dsh
303
+ 0.2.1-alpha.4 and later, the `@deepseek-ai/dsh-*` peers otherwise), the second
304
+ command refuses and rolls the profile back; `dsh plugin --profile web
305
+ allow-version <pkg>@<ver> --dsh-version <version> --accept-risk` grants the
306
+ exact-version exemption, so the probe can tell you *what* actually breaks instead
307
+ of what the gate already refused.
308
+
309
+ For a **dsh Desktop** release, start one step earlier, because the repository
310
+ cannot tell you what an installer runs: Desktop pins its shell and
311
+ `@deepseek-ai/dsh` to one exact version and ships the whole runtime inside
312
+ `resources/app.asar`. Read it off the installed app instead — the command is
313
+ read-only, and it prints that version together with whether the declared
314
+ `engines.dsh` / peer range admits it (and which gate dsh will actually read):
315
+
316
+ ```bash
317
+ node scripts/desktop-runtime.mjs "D:/DSH" # the installation dir
318
+ node scripts/desktop-runtime.mjs "D:/DSH/resources/app.asar" # or the archive itself
319
+ ```
320
+
321
+ Then run the four commands above against the version it names.
322
+
323
+ ## License
324
+
325
+ Apache-2.0. Portions of the code reference [Nagi-ovo/voyager](https://github.com/Nagi-ovo/voyager) and [unovue/inspira-ui](https://github.com/unovue/inspira-ui).