dsh-mask 0.2.20 → 0.2.23

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
@@ -22,6 +22,11 @@
22
22
 
23
23
  [English](README.md) · [简体中文](README-zh.md) · [Español](README-es.md) · [Português](README-pt.md) · [हिन्दी](README-hi.md)
24
24
 
25
+ ```sh
26
+ dsh plugin --profile <name> add dsh-mask
27
+ ```
28
+
29
+
25
30
  </div>
26
31
 
27
32
  ---
@@ -29,11 +34,20 @@
29
34
  **📖 Ecosystem knowledge base** — measured data, not marketing: [plugin development guide · plugin-selection data · maintenance criteria](https://perrylink.github.io/dsh-plugin-guide/).
30
35
 
31
36
  <!-- star-cta -->
37
+ ## Install & uninstall
38
+
39
+ - **git channel** (latest `main`): `dsh plugin --profile web add github:PerryLink/dsh-mask` (equivalent to installing from `git+https://github.com/PerryLink/dsh-mask.git`). No build step — `index.mjs` and `lib/` are the shipped artifacts.
40
+ - **npm channel** (published releases): `dsh plugin --profile web add dsh-mask`.
41
+ - **tarball channel**: `pnpm pack` in this repo, then `dsh plugin --profile web add ./dsh-mask-<version>.tgz`.
42
+ - **uninstall**: `dsh plugin --profile web remove dsh-mask` (or remove the row from the profile patch).
43
+
44
+ `dsh-mask` no longer bundles the storage stack. Profiles that already compose it (the `web` profile does, via `@deepseek-ai/dsh-web-app`) provide `storageDomain`, so persistence works out of the box. On a bare profile without storage the plugin still mounts and masks, but the restore table is memory-only (lost on restart) — compose the storage stack in your profile patch, or set `persistRestoreTable: false`.
45
+
32
46
  ## ⭐ 如果它帮到了你
33
47
 
34
- 这个插件是 [DSH 插件家族](https://github.com/PerryLink)的一员(40+ 个,全部 Apache-2.0)。如果你在用,**给个 star** —— 它不会解锁任何功能,但会让下一个人在搜索里更容易找到它。
48
+ 这个插件是 [DSH 插件家族](https://github.com/PerryLink)的一员(95 个,全部 Apache-2.0)。如果你在用,**给个 star** —— 它不会解锁任何功能,但会让下一个人在搜索里更容易找到它。
35
49
 
36
- *English:* part of a 40+ plugin family for DeepSeek Harness. If it is useful, **a star helps the next person find it** — nothing is gated behind it.
50
+ *English:* part of a 95 plugin family for DeepSeek Harness. If it is useful, **a star helps the next person find it** — nothing is gated behind it.
37
51
 
38
52
 
39
53
  ## What is dsh-mask?
@@ -42,11 +56,11 @@ PII masking middleware for DeepSeek Harness — anonymize personal data before i
42
56
 
43
57
  Phones, emails, ID cards, bank cards, keys, and more become placeholders at the model boundary; the plaintext never enters your session log.
44
58
 
45
- ![Terminal demo of dsh-mask: dsh-mask — PII becomes placeholders before the model sees it](https://raw.githubusercontent.com/PerryLink/dsh-mask/main/docs/assets/dsh-mask-demo.png)
59
+ ![Workflow diagram for dsh-mask: call → plugin → result.](docs/assets/dsh-mask-flow.svg)
60
+
61
+ *Workflow overview: call → plugin → result. The examples below use the real command surface.*
46
62
 
47
- ![Animated terminal demo of dsh-mask](https://raw.githubusercontent.com/PerryLink/dsh-mask/main/docs/assets/dsh-mask-demo.gif)
48
63
 
49
- *The same run, animated.*
50
64
 
51
65
  ## Comparison
52
66
 
@@ -70,13 +84,13 @@ Phones, emails, ID cards, bank cards, keys, and more become placeholders at the
70
84
  - **Request-time masking** — `agent/pre-step` messages are rewritten so phones, emails, ID cards, bank cards, and keys (on by default) and IPs (opt-in) become `<PHONE_1>`-style placeholders. The masked text is what gets logged and sent to the model.
71
85
  - **Restore table** — the `placeholder → original` map lives only in memory and a controlled storage domain (`dsh_mask`); the plaintext never enters the session log.
72
86
  - **Audit, not plaintext** — the `mask/applied` session event records only "replaced N values + type distribution", never the original text or the mapping.
73
- - **`/mask` command** — `status` (counts + distribution), `on`/`off` (runtime toggle), `restore <text>` (unmap placeholders), `help`.
87
+ - **`/mask` command** — `status` (counts + distribution), `on`/`off` (runtime toggle), `restore <text>` (unmap placeholders and deliver the plaintext as a file, never as logged text), `help`.
74
88
  - **`mask_test` tool** — run a snippet through the detector and see the placeholder result; it never reveals the original values.
75
89
 
76
90
  ```text
77
- user message ──agent/pre-step──▶ placeholders ──model──▶ placeholders ──restore──▶ display
78
- ▲ │
79
- └──────── restore table (memory + dsh_mask) ────────┘
91
+ user message ──agent/pre-step──▶ placeholders ──model──▶ placeholders ──restore──▶ controlled file
92
+ ▲ │
93
+ └──────── restore table (memory + dsh_mask) ───────────┘
80
94
  ```
81
95
 
82
96
  ## Quick start
@@ -109,16 +123,58 @@ Then tailor the entity list in your profile patch:
109
123
  ```
110
124
  > /mask status
111
125
  > /mask restore <PHONE_1>
126
+ mask: restored 1 placeholder(s): <PHONE_1>
127
+ file: /tmp/dsh-mask-restore/restore-1f0c….txt (mode 0600, one file per session)
112
128
  ```
113
129
 
114
- ## Install & uninstall
130
+ ### Examples
115
131
 
116
- - **git channel** (latest `main`): `dsh plugin --profile web add github:PerryLink/dsh-mask` (equivalent to installing from `git+https://github.com/PerryLink/dsh-mask.git`). No build step — `index.mjs` and `lib/` are the shipped artifacts.
117
- - **npm channel** (published releases): `dsh plugin --profile web add dsh-mask`.
118
- - **tarball channel**: `pnpm pack` in this repo, then `dsh plugin --profile web add ./dsh-mask-<version>.tgz`.
119
- - **uninstall**: `dsh plugin --profile web remove dsh-mask` (or remove the row from the profile patch).
132
+ These are the plugin's real entry points; install once, then call one.
120
133
 
121
- `dsh-mask` no longer bundles the storage stack. Profiles that already compose it (the `web` profile does, via `@deepseek-ai/dsh-web-app`) provide `storageDomain`, so persistence works out of the box. On a bare profile without storage the plugin still mounts and masks, but the restore table is memory-only (lost on restart) — compose the storage stack in your profile patch, or set `persistRestoreTable: false`.
134
+ #### Detailed example
135
+
136
+ **Command**
137
+
138
+ ~~~sh
139
+ mask_test
140
+ ~~~
141
+
142
+ **Input**
143
+
144
+ ~~~json
145
+ {"text":"电话 13812345678"}
146
+ ~~~
147
+
148
+ **Output**
149
+
150
+ ~~~text
151
+ mask_test: replaced 1 PII value(s) (PHONE=1)
152
+ masked:
153
+ 电话 <PHONE_1>
154
+ ~~~
155
+
156
+ *Observed from `plugins/dsh-mask/index.mjs:243-250; test/index.test.mjs:306-315`*
157
+
158
+ #### Failure branch
159
+
160
+ **Input**
161
+
162
+ ~~~text
163
+ /mask restore <PHONE_1> with restoreDir=/tmp/dsh-mask-probe-not-a-dir (a regular file)
164
+ ~~~
165
+
166
+ **Output**
167
+
168
+ ~~~text
169
+ mask: restore failed: EEXIST: file already exists, mkdir '/tmp/dsh-mask-probe-not-a-dir'
170
+ ~~~
171
+
172
+ *Observed from `plugins/dsh-mask/index.mjs:501-506; plugins/dsh-mask/lib/deliver.mjs:89-97; plugins/dsh-mask/test/index.test.mjs:278-290`*
173
+
174
+ #### Brief examples
175
+
176
+ - `mask_test`
177
+ - `/mask restore <text>`
122
178
 
123
179
  ## Configuration
124
180
 
@@ -136,6 +192,7 @@ All tunables are Schemastery `Config` fields (changeable from cordis.yml). An id
136
192
  | `maxRestoreEntriesPerSession` | `500` | Per-session restore entry cap (oldest evicted first) |
137
193
  | `maxSessions` | `1000` | In-memory session cap (least-recently-used evicted, mapping reloaded on demand) |
138
194
  | `maskClientEnabled` | `false` | Feature flag for the browser half "reveal" bubble (defensive; off by default until the live slot catalog verifies the target slot). The key is schema-declared and validated, but no runtime code reads it yet, so it changes nothing until the browser half ships |
195
+ | `restoreDir` | `''` | Where `/mask restore` delivers the restored plaintext. Empty = `os.tmpdir()/dsh-mask-restore`; a relative value resolves against the host process working directory. The directory is created `0700` and the file written `0600`, one file per session |
139
196
 
140
197
  Example override in your profile patch:
141
198
 
@@ -157,20 +214,20 @@ Example override in your profile patch:
157
214
  | `tools/post-execute` masking | never | Rewrites tool-result text blocks to placeholders before they are logged or fed back to the model (scope: `tools`) |
158
215
  | `/mask status` | never | Enabled state, total replaced, type distribution |
159
216
  | `/mask on` / `/mask off` | never | Runtime toggle (resets to `config.enabled` on restart) |
160
- | `/mask restore <text>` | yes (explicit) | Unmaps placeholders back to the values stored for this session |
217
+ | `/mask restore <text>` | yes (explicit) | Unmaps placeholders back to the values stored for this session and writes them to a controlled file (one per session, mode `0600`); the result text and the session log carry only that path and the placeholder names |
161
218
  | `mask_test` | never | Masks a snippet and reports the placeholder result + counts |
162
219
 
163
220
  ## Permissions & data
164
221
 
165
- - **Permissions**: `dsh-mask` performs no network requests and stores no credentials; it only reads the session at the `agent/pre-step` boundary and writes its own `dsh_mask` storage domain. The `dshWorkshop` manifest declares `network:none` and `credentials:none`.
166
- - **Data**: the `placeholder → original` restore table lives in memory and, when `persistRestoreTable: true`, in the controlled `dsh_mask` storage domain — this is the only place plaintext PII is stored, and it is never written to the session log.
222
+ - **Permissions**: `dsh-mask` performs no network requests and stores no credentials; it reads the session at the `agent/pre-step` boundary, writes its own `dsh_mask` storage domain, and writes the `/mask restore` delivery file (the manifest declares `filesystem:write` for exactly that). The `dshWorkshop` manifest also declares `network:none` and `credentials:none`.
223
+ - **Data**: the `placeholder → original` restore table lives in memory and, when `persistRestoreTable: true`, in the controlled `dsh_mask` storage domain — it is never written to the session log. The only other plaintext copy is the delivery file an explicit `/mask restore` writes under `restoreDir` (mode `0600`, one file per session, overwritten by the next restore); nothing writes plaintext to disk implicitly.
167
224
  - **Session log**: `mask/applied` is declared in `types.d.ts` and appended only when the host records the type (see Known limitations). Its payload is counts + type distribution only.
168
225
 
169
226
  ## Security boundaries
170
227
 
171
- - **Plaintext never enters the session log.** The masked (placeholder) form is what gets logged and sent to the model, so model-visible content is reconstructable from the log in placeholder form; the originals stay in the restore table.
172
- - **Sanitize before display/log.** `lib/sanitize.mjs` redacts PII, secrets, and URL credentials before any text reaches the model or the log; `mask_test` and `/mask status` never echo originals.
173
- - **Controlled restore.** `/mask restore` is the single explicit reveal surface, and it only reads the mapping for the active session.
228
+ - **Plaintext never enters the session log.** The masked (placeholder) form is what gets logged and sent to the model, so model-visible content is reconstructable from the log in placeholder form; the originals stay in the restore table. The same rule governs the reveal direction: a command's result text is logged **verbatim** by the host and rendered from that same event, so `/mask restore` writes the plaintext to a controlled file and returns only its path.
229
+ - **Sanitize before display/log.** `lib/sanitize.mjs` redacts PII, secrets, and URL credentials before any text reaches the model or the log; `mask_test`, `/mask status`, and every `/mask` error path never echo originals.
230
+ - **Controlled restore.** `/mask restore` is the single explicit reveal surface, and it only reads the mapping for the active session. Failure fails closed: if the delivery file cannot be written, the command reports an error and never falls back to echoing the plaintext.
174
231
  - **Fail closed.** Unimplemented `mode` (`regex+ner`), unknown `scope` values, NER-only entities, and out-of-bounds numbers all fail loudly at load.
175
232
  - **Registrations are effects.** The listener, command, tool, and storage-domain close are all Cordis effects — stop/hot-reload removes them.
176
233
 
@@ -178,7 +235,8 @@ Example override in your profile patch:
178
235
 
179
236
  - **Regex only.** Name (`person`) and address (`address`) recognition needs an external NER recognizer, which the pure-host zero-dependency form does not bundle; `mode: regex+ner` and those entities fail loudly at load. The PII types covered out of the box are phone, email, ID card, bank card, key, and (opt-in) IP.
180
237
  - **Region-specific patterns.** The `phone` and `id-card` detectors match mainland-China formats only: `phone` is `1[3-9]` followed by nine digits, and `id-card` is an 18-character Chinese resident ID (17 digits plus a digit or `X`). Phone numbers and national identifiers from other countries are not detected. `email`, `ip`, and `key` are region-agnostic; `bank-card` accepts any 16-19 digit run at a lower confidence score.
181
- - **Display-layer restore needs a client half.** Masking is fully host-side, but transparently un-masking the assistant bubbles in the client UI is a browser-half feature this pure-host form does not ship. The host side keeps the restore table and the exported `RestoreStore` seam (its methods take a session id), so a future client half would reach them through a host remote rather than directly; today the unmasking surface is the `/mask restore <text>` command, and the `maskClientEnabled` key is validated but read by no runtime code yet.
238
+ - **Display-layer restore needs a client half.** Masking is fully host-side, but transparently un-masking the assistant bubbles in the client UI is a browser-half feature this pure-host form does not ship. The host side keeps the restore table and the exported `RestoreStore` seam (its methods take a session id), so a future client half would reach them through a host remote rather than directly; today the unmasking surface is the `/mask restore <text>` command, which delivers the plaintext as a file because a command result is logged verbatim (see Security boundaries), and the `maskClientEnabled` key is validated but read by no runtime code yet.
239
+ - **No no-argument `/mask restore`.** Restoring *every* placeholder of the most recent assistant message is not offered, and the command says so when invoked without text. Two host facts block it: the restore table is a flat per-session `{placeholder: original}` map with no per-message index, so that message has to be located in the session event log; and the host deprecated `Session.snapshotEvents()` / `eventAt()` / `ownEvents()` with an explicit "new calls are prohibited", leaving an incremental projection as the only sanctioned route — which this plugin's declared host corridor (`>=0.1.2-rc.1`) cannot rely on. Placeholders keep working one at a time instead: `/mask restore <PHONE_1>`.
182
240
  - **Session events on `0.1.7-rc.2`.** The harness records 59 session event types and none of them is `mask/*`; its `Session.append` also cannot stamp the `ignorable` envelope, so the session-log audit appends are skipped and sessions keep loading. The gate is not silent about it: the first refusal per session logs one visible warning naming the skipped type and this documented limitation. The plugin enables the append automatically once a host records the type or supports the `ignorable` envelope.
183
241
 
184
242
  ## Development
@@ -228,59 +286,110 @@ Static evidence: `dsh-plugin-doctor` K10–K13 report `pass` for every check on
228
286
 
229
287
  ## PerryLink DSH Plugin Family
230
288
 
231
- This project is one of the **33 actively maintained** DeepSeek Harness plugins from [PerryLink](https://github.com/PerryLink) — the roster is **42**, of which **6** are frozen and **3** retired; every one keeps its row below, with the reason in the Status column. If this one helps you, the others likely will too:
289
+ This project is part of the DeepSeek Harness plugin family from [PerryLink](https://github.com/PerryLink). The roster stays collapsed below so every README keeps a short first screen; expand it to see every row and its status.
232
290
 
233
- | Plugin | One-liner | Status |
234
- |---|---|---|
235
- | **[dsh-auto-review](https://github.com/PerryLink/dsh-auto-review)** | Second-model auto-review on the approval chain, fail-closed by default | |
236
- | **[dsh-autotier](https://github.com/PerryLink/dsh-autotier)** | Automatic strong/cheap model-tier routing with deterministic risk guards and a `/tier` command | |
237
- | **[dsh-background-agents](https://github.com/PerryLink/dsh-background-agents)** | Durable background child agents with a Web UI sidebar, messaging and interrupt | 🚫 **RETIRED** — see the note above |
238
- | **[dsh-budget](https://github.com/PerryLink/dsh-budget)** | Cost governance for DeepSeek Harness: budgets, carbon, and latency in one panel. | 🧊 FROZEN — see the repo README |
239
- | **[dsh-catalog](https://github.com/PerryLink/dsh-catalog)** | DSH Desktop Market standard catalog source for the PerryLink family | |
240
- | **[dsh-cert-mcp](https://github.com/PerryLink/dsh-cert-mcp)** | Read-only MCP server exposing the certification registry: grades, snapshots and five-dimension evidence | |
241
- | **[dsh-checkpoint-rewind](https://github.com/PerryLink/dsh-checkpoint-rewind)** | Claude Code /rewind-equivalent: snapshots, session forks, one-shot restore | |
242
- | **[dsh-claude-move](https://github.com/PerryLink/dsh-claude-move)** | Migrate Claude Code sessions, memory, skills and CLAUDE.md into DSH | 🧊 FROZEN — see the repo README |
243
- | **[dsh-click](https://github.com/PerryLink/dsh-click)** | Cross-platform native desktop control for DeepSeek Harness — Windows first. | |
244
- | **[dsh-composer-history](https://github.com/PerryLink/dsh-composer-history)** | Terminal-style input history for the web composer: arrows, Ctrl+R search | |
245
- | **[dsh-data-quality](https://github.com/PerryLink/dsh-data-quality)** | Dataset quality checks and citation cross-checks (the optional numeric bridge consumed here) | |
246
- | **[dsh-defend](https://github.com/PerryLink/dsh-defend)** | Prompt-injection, jailbreak, and secret-leak defense for DeepSeek Harness. | 🧊 FROZEN — see the repo README |
247
- | **[dsh-doublecheck](https://github.com/PerryLink/dsh-doublecheck)** | Engineering-discipline guard: requirements grill, test gates, adversary review | |
248
- | **[dsh-draw](https://github.com/PerryLink/dsh-draw)** | Unified static-image generation routing for DeepSeek Harness. | 🧊 FROZEN — see the repo README |
249
- | **[dsh-fast](https://github.com/PerryLink/dsh-fast)** | Read-only performance diagnostics for DeepSeek Harness. | |
250
- | **[dsh-fund-research](https://github.com/PerryLink/dsh-fund-research)** | Deterministic research reports for Chinese public mutual funds | |
251
- | **[dsh-github](https://github.com/PerryLink/dsh-github)** | GitHub PR/issues integration for DSH, every write gated by approval | |
252
- | **[dsh-industry-research](https://github.com/PerryLink/dsh-industry-research)** | Industry research orchestration that seals its deliverables through this plugin's `ctx.researchReport.assemble` | |
253
- | **[dsh-laya](https://github.com/PerryLink/dsh-laya)** | Laya typed decisions (`noul`/`choice`/`score`) as a first-class Cordis service and model-visible tools | |
254
- | **[dsh-library](https://github.com/PerryLink/dsh-library)** | Local document knowledge base for DeepSeek Harness. | |
255
- | **[dsh-local-ai](https://github.com/PerryLink/dsh-local-ai)** | Local-model (Ollama) integration for DeepSeek Harness. | |
256
- | **[dsh-lsp-actions](https://github.com/PerryLink/dsh-lsp-actions)** | LSP diagnostics, formatting, completion, code actions and rename over language servers | |
257
- | **[dsh-mask](https://github.com/PerryLink/dsh-mask)** | PII masking middleware: anonymize at the model boundary, restore at the display layer | |
258
- | **[dsh-mcp-panel](https://github.com/PerryLink/dsh-mcp-panel)** | Read-only MCP runtime panel: /mcp command + Settings tab with status, tools and errors | |
259
- | **[dsh-memento](https://github.com/PerryLink/dsh-memento)** | Approval-gated cross-session memory: ctx.memory seam + SQLite + memory tool | 🧊 FROZEN — see the repo README |
260
- | **[dsh-observe](https://github.com/PerryLink/dsh-observe)** | OpenTelemetry and Langfuse observability exporter for DeepSeek Harness. | |
261
- | **[dsh-output-styles](https://github.com/PerryLink/dsh-output-styles)** | Claude Code outputStyles-equivalent runtime style switching | |
262
- | **[dsh-permission-rules](https://github.com/PerryLink/dsh-permission-rules)** | Claude Code-style declarative allow/deny/ask permission rules with audit | |
263
- | **[dsh-plugin-certification](https://github.com/PerryLink/dsh-plugin-certification)** | Community certification registry with repro-checkable grades and badges | |
264
- | **[dsh-plugin-doctor](https://github.com/PerryLink/dsh-plugin-doctor)** | Zero-dependency static + sandbox smoke detector for DSH plugins | |
265
- | **[dsh-plugin-guide](https://github.com/PerryLink/dsh-plugin-guide)** | Plugin-development knowledge base as an on-demand agent skill | |
266
- | **[dsh-plugin-kit](https://github.com/PerryLink/dsh-plugin-kit)** | Shared zero-runtime-dependency toolkit for the PerryLink DSH plugins | |
267
- | **[dsh-plugin-upgrade](https://github.com/PerryLink/dsh-plugin-upgrade)** | One-package, one-corridor-index plugin upgrade skill: routes a repository to the matching closed corridor card | |
268
- | **[dsh-plugin-upgrade-015](https://github.com/PerryLink/dsh-plugin-upgrade-015)** | Merged `0.1.3-alpha.1` → `0.1.5-rc.1` upgrade corridor card plus a zero-dependency seam scanner | 🚫 RETIRED — corridors carried by `dsh-plugin-upgrade` |
269
- | **[dsh-reach](https://github.com/PerryLink/dsh-reach)** | Multi-channel approval/question bridge: WeChat/Telegram/Feishu, session console | 🧊 FROZEN — see the repo README |
270
- | **[dsh-research-report](https://github.com/PerryLink/dsh-research-report)** | Verifiable research-report engine: content-addressed evidence ledger and sealed versions | |
271
- | **[dsh-score](https://github.com/PerryLink/dsh-score)** | Multi-dimensional quality scoring for DeepSeek Harness plugins. | |
272
- | **[dsh-session-pin](https://github.com/PerryLink/dsh-session-pin)** | Pin sessions in the Web sidebar with durable ordering | 🚫 **RETIRED** — see the note above |
273
- | **[dsh-session-sync](https://github.com/PerryLink/dsh-session-sync)** | Cross-device session sync for DeepSeek Harness — a dedicated git mirror of your session store. | |
274
- | **[dsh-skill-pack-security](https://github.com/PerryLink/dsh-skill-pack-security)** | Security-audit skill pack: secret scan, dependency and supply-chain review | |
275
- | **[dsh-talk](https://github.com/PerryLink/dsh-talk)** | Voice-first session loop for DeepSeek Harness: talk to it, hear it answer. | |
276
- | **[dsh-team-rooms](https://github.com/PerryLink/dsh-team-rooms)** | Cross-session team rooms: shared message bus, task board and timeline | 🚫 **RETIRED** — see the note above |
277
- | **[dsh-test-drive](https://github.com/PerryLink/dsh-test-drive)** | Isolated install-and-smoke test drives for DeepSeek Harness plugins. | |
278
- | **[dsh-ticktick](https://github.com/PerryLink/dsh-ticktick)** | TickTick/Dida365 task bridge: session-header panel + 11 tools | |
279
- | **[dsh-translate](https://github.com/PerryLink/dsh-translate)** | Vendor parameter translation and deterministic JSON repair for DeepSeek Harness. | |
280
-
281
- ### Install from the DSH Desktop Market
282
-
283
- All PerryLink plugins are browsable in the built-in DSH Desktop Market: **Market → Sources → add source → paste** `https://perrylink-dsh-catalog.perrylink.workers.dev/catalog-source.json` **→ select it**. Installation still goes through the Market's npm-identity verification and your confirmation.
291
+ <details>
292
+ <summary>Expand all plugins</summary>
293
+
294
+ | Plugin | Status |
295
+ |---|---|
296
+ | **[dsh-aqua-input-check](https://github.com/PerryLink/dsh-aqua-input-check)** | |
297
+ | **[dsh-archive-check](https://github.com/PerryLink/dsh-archive-check)** | |
298
+ | **[dsh-auto-review](https://github.com/PerryLink/dsh-auto-review)** | |
299
+ | **[dsh-autotier](https://github.com/PerryLink/dsh-autotier)** | |
300
+ | **[dsh-bid-ca-precheck](https://github.com/PerryLink/dsh-bid-ca-precheck)** | |
301
+ | **[dsh-bid-qual-check](https://github.com/PerryLink/dsh-bid-qual-check)** | |
302
+ | **[dsh-cert-mcp](https://github.com/PerryLink/dsh-cert-mcp)** | |
303
+ | **[dsh-checkpoint-rewind](https://github.com/PerryLink/dsh-checkpoint-rewind)** | |
304
+ | **[dsh-click](https://github.com/PerryLink/dsh-click)** | |
305
+ | **[dsh-composer-history](https://github.com/PerryLink/dsh-composer-history)** | |
306
+ | **[dsh-contract-stance](https://github.com/PerryLink/dsh-contract-stance)** | |
307
+ | **[dsh-customs-doc-check](https://github.com/PerryLink/dsh-customs-doc-check)** | |
308
+ | **[dsh-data-quality](https://github.com/PerryLink/dsh-data-quality)** | |
309
+ | **[dsh-demurrage-ledger](https://github.com/PerryLink/dsh-demurrage-ledger)** | |
310
+ | **[dsh-doublecheck](https://github.com/PerryLink/dsh-doublecheck)** | |
311
+ | **[dsh-drill-script-check](https://github.com/PerryLink/dsh-drill-script-check)** | |
312
+ | **[dsh-eia-guide-check](https://github.com/PerryLink/dsh-eia-guide-check)** | |
313
+ | **[dsh-emergency-plan](https://github.com/PerryLink/dsh-emergency-plan)** | |
314
+ | **[dsh-essay-rubric-check](https://github.com/PerryLink/dsh-essay-rubric-check)** | |
315
+ | **[dsh-evidence-check](https://github.com/PerryLink/dsh-evidence-check)** | |
316
+ | **[dsh-export-ctl-check](https://github.com/PerryLink/dsh-export-ctl-check)** | |
317
+ | **[dsh-fast](https://github.com/PerryLink/dsh-fast)** | |
318
+ | **[dsh-fmea-table-check](https://github.com/PerryLink/dsh-fmea-table-check)** | |
319
+ | **[dsh-forecast-penalty](https://github.com/PerryLink/dsh-forecast-penalty)** | |
320
+ | **[dsh-fund-research](https://github.com/PerryLink/dsh-fund-research)** | |
321
+ | **[dsh-github](https://github.com/PerryLink/dsh-github)** | |
322
+ | **[dsh-gongwen-flow-check](https://github.com/PerryLink/dsh-gongwen-flow-check)** | |
323
+ | **[dsh-gongwen-word-check](https://github.com/PerryLink/dsh-gongwen-word-check)** | |
324
+ | **[dsh-guard-plan-qc](https://github.com/PerryLink/dsh-guard-plan-qc)** | |
325
+ | **[dsh-hazchem-check](https://github.com/PerryLink/dsh-hazchem-check)** | |
326
+ | **[dsh-hazplan-check](https://github.com/PerryLink/dsh-hazplan-check)** | |
327
+ | **[dsh-hidden-risk-map](https://github.com/PerryLink/dsh-hidden-risk-map)** | |
328
+ | **[dsh-hs-classify](https://github.com/PerryLink/dsh-hs-classify)** | |
329
+ | **[dsh-icd-rule-check](https://github.com/PerryLink/dsh-icd-rule-check)** | |
330
+ | **[dsh-industry-research](https://github.com/PerryLink/dsh-industry-research)** | |
331
+ | **[dsh-lawcite-adapter](https://github.com/PerryLink/dsh-lawcite-adapter)** | |
332
+ | **[dsh-laya](https://github.com/PerryLink/dsh-laya)** | |
333
+ | **[dsh-lc-doc-check](https://github.com/PerryLink/dsh-lc-doc-check)** | |
334
+ | **[dsh-learning-gap-check](https://github.com/PerryLink/dsh-learning-gap-check)** | |
335
+ | **[dsh-library](https://github.com/PerryLink/dsh-library)** | |
336
+ | **[dsh-local-ai](https://github.com/PerryLink/dsh-local-ai)** | |
337
+ | **[dsh-lsp-actions](https://github.com/PerryLink/dsh-lsp-actions)** | |
338
+ | **[dsh-mask](https://github.com/PerryLink/dsh-mask)** | |
339
+ | **[dsh-mcp-panel](https://github.com/PerryLink/dsh-mcp-panel)** | |
340
+ | **[dsh-medrec-qc](https://github.com/PerryLink/dsh-medrec-qc)** | |
341
+ | **[dsh-memento](https://github.com/PerryLink/dsh-memento)** | |
342
+ | **[dsh-nsfc-form-check](https://github.com/PerryLink/dsh-nsfc-form-check)** | |
343
+ | **[dsh-nurse-record-check](https://github.com/PerryLink/dsh-nurse-record-check)** | |
344
+ | **[dsh-observe](https://github.com/PerryLink/dsh-observe)** | |
345
+ | **[dsh-origin-rvc-check](https://github.com/PerryLink/dsh-origin-rvc-check)** | |
346
+ | **[dsh-ota-review-check](https://github.com/PerryLink/dsh-ota-review-check)** | |
347
+ | **[dsh-output-styles](https://github.com/PerryLink/dsh-output-styles)** | |
348
+ | **[dsh-paper-doc-adapter](https://github.com/PerryLink/dsh-paper-doc-adapter)** | |
349
+ | **[dsh-permission-rules](https://github.com/PerryLink/dsh-permission-rules)** | |
350
+ | **[dsh-permit-report-check](https://github.com/PerryLink/dsh-permit-report-check)** | |
351
+ | **[dsh-pipeline-check](https://github.com/PerryLink/dsh-pipeline-check)** | |
352
+ | **[dsh-pleading-draft](https://github.com/PerryLink/dsh-pleading-draft)** | |
353
+ | **[dsh-plugin-doctor](https://github.com/PerryLink/dsh-plugin-doctor)** | |
354
+ | **[dsh-plugin-guide](https://github.com/PerryLink/dsh-plugin-guide)** | |
355
+ | **[dsh-plugin-kit](https://github.com/PerryLink/dsh-plugin-kit)** | |
356
+ | **[dsh-plugin-upgrade](https://github.com/PerryLink/dsh-plugin-upgrade)** | |
357
+ | **[dsh-policy-brief-draft](https://github.com/PerryLink/dsh-policy-brief-draft)** | |
358
+ | **[dsh-power-loss-split](https://github.com/PerryLink/dsh-power-loss-split)** | |
359
+ | **[dsh-power-ticket-check](https://github.com/PerryLink/dsh-power-ticket-check)** | |
360
+ | **[dsh-ppap-check](https://github.com/PerryLink/dsh-ppap-check)** | |
361
+ | **[dsh-protest-deadline](https://github.com/PerryLink/dsh-protest-deadline)** | |
362
+ | **[dsh-railway-window](https://github.com/PerryLink/dsh-railway-window)** | |
363
+ | **[dsh-repair-order-qc](https://github.com/PerryLink/dsh-repair-order-qc)** | |
364
+ | **[dsh-research-report](https://github.com/PerryLink/dsh-research-report)** | |
365
+ | **[dsh-review-reply-check](https://github.com/PerryLink/dsh-review-reply-check)** | |
366
+ | **[dsh-rulefile-check](https://github.com/PerryLink/dsh-rulefile-check)** | |
367
+ | **[dsh-safety-brief-check](https://github.com/PerryLink/dsh-safety-brief-check)** | |
368
+ | **[dsh-score](https://github.com/PerryLink/dsh-score)** | |
369
+ | **[dsh-session-sync](https://github.com/PerryLink/dsh-session-sync)** | |
370
+ | **[dsh-site-log-check](https://github.com/PerryLink/dsh-site-log-check)** | |
371
+ | **[dsh-skill-pack-security](https://github.com/PerryLink/dsh-skill-pack-security)** | |
372
+ | **[dsh-soe-decision-check](https://github.com/PerryLink/dsh-soe-decision-check)** | |
373
+ | **[dsh-soilwater-check](https://github.com/PerryLink/dsh-soilwater-check)** | |
374
+ | **[dsh-sop-sync-check](https://github.com/PerryLink/dsh-sop-sync-check)** | |
375
+ | **[dsh-spc-gbt-adapter](https://github.com/PerryLink/dsh-spc-gbt-adapter)** | |
376
+ | **[dsh-talk](https://github.com/PerryLink/dsh-talk)** | |
377
+ | **[dsh-tender-extract](https://github.com/PerryLink/dsh-tender-extract)** | |
378
+ | **[dsh-tender-matrix](https://github.com/PerryLink/dsh-tender-matrix)** | |
379
+ | **[dsh-test-drive](https://github.com/PerryLink/dsh-test-drive)** | |
380
+ | **[dsh-ticktick](https://github.com/PerryLink/dsh-ticktick)** | |
381
+ | **[dsh-translate](https://github.com/PerryLink/dsh-translate)** | |
382
+ | **[dsh-warranty-calc](https://github.com/PerryLink/dsh-warranty-calc)** | |
383
+ | **[dsh-budget](https://github.com/PerryLink/dsh-budget)** | 🧊 FROZEN — see the repo README |
384
+ | **[dsh-claude-move](https://github.com/PerryLink/dsh-claude-move)** | 🧊 FROZEN — see the repo README |
385
+ | **[dsh-defend](https://github.com/PerryLink/dsh-defend)** | 🧊 FROZEN — see the repo README |
386
+ | **[dsh-draw](https://github.com/PerryLink/dsh-draw)** | 🧊 FROZEN — see the repo README |
387
+ | **[dsh-reach](https://github.com/PerryLink/dsh-reach)** | 🧊 FROZEN — see the repo README |
388
+ | **[dsh-background-agents](https://github.com/PerryLink/dsh-background-agents)** | 🚫 RETIRED — see the repo README |
389
+ | **[dsh-session-pin](https://github.com/PerryLink/dsh-session-pin)** | 🚫 RETIRED — see the repo README |
390
+ | **[dsh-team-rooms](https://github.com/PerryLink/dsh-team-rooms)** | 🚫 RETIRED — see the repo README |
391
+
392
+ </details>
284
393
 
285
394
  ## License
286
395
 
package/cordis.patch.yml CHANGED
@@ -58,3 +58,10 @@
58
58
  # already backs it; the client slot ships separately and is off by
59
59
  # default until the live slot catalog verifies the target slot.
60
60
  maskClientEnabled: false
61
+ # Where /mask restore delivers the restored plaintext. The host writes a
62
+ # command's result (command/done.text) into the session log verbatim,
63
+ # and the client renders that same event, so the plaintext can never
64
+ # live in the result text: it goes to one controlled file per session
65
+ # (mode 0600, overwritten by the next restore) and the result carries
66
+ # the path plus the placeholder names only. Empty = os.tmpdir()/dsh-mask-restore.
67
+ restoreDir: ''
package/index.mjs CHANGED
@@ -7,6 +7,9 @@
7
7
  // 日志重建(占位符形式),原文绝不进会话日志。
8
8
  // - 恢复表:占位符→原文映射只存内存 + 受控 storageDomain(dsh_mask/restore),
9
9
  // 绝不进会话日志明文;/mask restore 与恢复 seam 按需回载。
10
+ // - 还原交付:宿主把命令结果(command/done.text)原样写进持久会话日志,且客户端
11
+ // 用户可见输出就是从同一条事件渲染的(同源,无法分离)⇒ /mask restore 绝不把
12
+ // 明文放进结果文本,而是写进受控文件(lib/deliver.mjs)并把路径回给用户。
10
13
  // - 审计:mask/applied 会话事件只记"替换了 N 处 + 类型分布"(log-only,自适应
11
14
  // 门),不记明文与映射。
12
15
  // - 表面:/mask 命令(status|on|off|restore|help)与 mask_test 工具(试跑一段
@@ -39,6 +42,8 @@ import { maskMessages, maskContentBlocks } from './lib/mask.mjs'
39
42
  import { makeEventGate, maybeAppendSessionEvent } from './lib/gate.mjs'
40
43
  import { RestoreStore } from './lib/store.mjs'
41
44
  import { dshMaskDomainSpec } from './lib/domain.mjs'
45
+ import { deliverPlaintext, resolveRestoreDir } from './lib/deliver.mjs'
46
+ import { redactText } from './lib/sanitize.mjs'
42
47
 
43
48
  export const name = PLUGIN_NAME
44
49
 
@@ -96,6 +101,7 @@ export const Config = Schema.object({
96
101
  maxRestoreEntriesPerSession: Schema.number().default(DEFAULTS.MAX_RESTORE_ENTRIES_PER_SESSION),
97
102
  maxSessions: Schema.number().default(DEFAULTS.MAX_SESSIONS),
98
103
  maskClientEnabled: Schema.boolean().default(DEFAULTS.MASK_CLIENT_ENABLED),
104
+ restoreDir: Schema.string().default(DEFAULTS.RESTORE_DIR),
99
105
  })
100
106
 
101
107
  /**
@@ -116,9 +122,13 @@ export function resolveConfig(config = {}) {
116
122
  maxRestoreEntriesPerSession: config.maxRestoreEntriesPerSession ?? DEFAULTS.MAX_RESTORE_ENTRIES_PER_SESSION,
117
123
  maxSessions: config.maxSessions ?? DEFAULTS.MAX_SESSIONS,
118
124
  maskClientEnabled: config.maskClientEnabled ?? DEFAULTS.MASK_CLIENT_ENABLED,
125
+ restoreDir: config.restoreDir ?? DEFAULTS.RESTORE_DIR,
119
126
  }
120
127
  if (resolved.enabled === false) return resolved
121
128
 
129
+ if (typeof resolved.restoreDir !== 'string') {
130
+ throw badConfig('restoreDir must be a string (empty = the OS temp directory)')
131
+ }
122
132
  if (resolved.mode === MODES.REGEX_NER) {
123
133
  throw nerModeUnsupported(resolved.mode)
124
134
  }
@@ -178,7 +188,37 @@ const HELP_TEXT = [
178
188
  ' status show masking state: enabled, total replaced, type distribution (default)',
179
189
  ' on enable masking at runtime (config.enabled is the persistent switch)',
180
190
  ' off disable masking at runtime',
181
- ' restore unmap placeholders in <text> back to the values stored for this session',
191
+ ' restore unmap placeholders in <text> back to the values stored for this session and',
192
+ ' deliver the plaintext as a file — never in this result text or the session log',
193
+ ].join('\n')
194
+
195
+ /**
196
+ * restore 结果的安全文案(纯函数):只含占位符与落点路径,绝不含还原出的明文。
197
+ * 路径由「配置目录 + 固定前缀 + 会话 id 的 sha256 前 16 位 + .txt」拼成,
198
+ * 不含会话 id、更不含原文,因此可以安全地进日志/转录(这也是它与明文的关键区别)。
199
+ * @param {{placeholders: string[], path: string}} delivery - 占位符与落点。
200
+ * @returns {string} 命令结果文本。
201
+ */
202
+ export function renderRestore(delivery) {
203
+ return [
204
+ `mask: restored ${delivery.placeholders.length} placeholder(s): ${delivery.placeholders.join(', ')}`,
205
+ ` file: ${delivery.path} (mode 0600, one file per session)`,
206
+ ' The plaintext is NOT in this text and NOT in the session log: the host records a',
207
+ ' command\'s result verbatim, so this command writes the restored text to the file above',
208
+ ' instead. Open it to read the plaintext; the next /mask restore overwrites it.',
209
+ ].join('\n')
210
+ }
211
+
212
+ /**
213
+ * restore 无参形态的说明(该形态未实现,见 README「Known limitations」):
214
+ * 定位「最近一条助手消息」需要同步读会话事件史,而宿主已把
215
+ * `Session.snapshotEvents()/eventAt()/ownEvents()` 标为 @deprecated 并禁止新调用方。
216
+ */
217
+ const RESTORE_NO_ARG_NOTE = [
218
+ ' (a no-argument form that would restore every placeholder of the last assistant message is',
219
+ ' not offered: the restore table is a flat per-session map with no per-message index, and',
220
+ ' locating that message needs a synchronous session-history read the host prohibits for new',
221
+ ' callers — see README Known limitations.)',
182
222
  ].join('\n')
183
223
 
184
224
  /**
@@ -383,6 +423,19 @@ export function apply(ctx, config = {}) {
383
423
  name: COMMAND_NAME,
384
424
  description: 'PII masking status and controls: status (replaced count + type distribution), on/off (runtime toggle), restore <text> (unmap placeholders to this session\'s values), help.',
385
425
  input: { hint: '[status | on | off | restore <text> | help]' },
426
+ // `recordInput: false` —— 输入侧的同类泄漏闸(2026-10-13,用户裁定)。
427
+ //
428
+ // 为什么必须关:宿主把 `parsed.rawInput`(逐字原文)写进 `command/run` 事件的 `args`
429
+ // 字段(dsh-commands `index.ts:376`),而该事件同样进持久会话转录。于是
430
+ // `/mask restore 13812345678`(用户直接粘贴明文)会把 PII 写进日志 —— 与
431
+ // 结果侧那条缺陷同一个洞,只是入口不同。关掉它后 `args` 字段整体缺席(宿主
432
+ // `index.ts:215` 只在显式设置时才带上该键)。
433
+ //
434
+ // 代价(如实记录,勿以为无损):`recordInput` 是**命令级、无子命令粒度**
435
+ // (宿主 `types.ts:75`),所以 `status` / `on` / `off` 的 args 也一并退出转录。
436
+ // 这三条都是无参数或单关键词调用,信息量本来就为零;而恢复映射本身另有
437
+ // 交付文件与 `mask/applied` 审计事件承载,不依赖 args。因此这是净收益。
438
+ recordInput: false,
386
439
  async handler(invocation) {
387
440
  return handleMaskCommand(invocation)
388
441
  },
@@ -422,14 +475,33 @@ export function apply(ctx, config = {}) {
422
475
  return { kind: 'error', text: 'mask: restore requires an active session' }
423
476
  }
424
477
  if (snippet === '') {
425
- return { kind: 'error', text: 'mask: restore needs text, e.g. /mask restore <PHONE_1>' }
478
+ return { kind: 'error', text: `mask: restore needs text, e.g. /mask restore <PHONE_1>\n${RESTORE_NO_ARG_NOTE}` }
479
+ }
480
+ const { text: restored, placeholders } = await store.restoreDetailed(sessionId, snippet)
481
+ if (placeholders.length === 0) {
482
+ return {
483
+ kind: 'success',
484
+ text: [
485
+ 'mask: restore found no placeholder this session knows — nothing was revealed or written.',
486
+ ' Pass a placeholder exactly as the model saw it, e.g. /mask restore <PHONE_1>',
487
+ ].join('\n'),
488
+ }
426
489
  }
427
- const restored = await store.restore(sessionId, snippet)
428
- return { kind: 'success', text: `mask: restored\n${restored}` }
490
+ // 安全缺陷修复点:宿主把 result.text 原样写进持久会话日志(command/done),
491
+ // 客户端又从同一条事件渲染用户可见输出 ⇒ 结果文本既是转录也是日志。
492
+ // 因此明文绝不进结果文本,只进受控文件,结果里只回路径 + 占位符名。
493
+ const delivery = await deliverPlaintext({
494
+ dir: resolveRestoreDir(resolved.restoreDir),
495
+ sessionId,
496
+ text: restored,
497
+ })
498
+ return { kind: 'success', text: renderRestore({ placeholders, path: delivery.path }) }
429
499
  }
430
500
  return { kind: 'success', text: HELP_TEXT }
431
501
  } catch (error) {
432
- const message = `mask: ${actionKey} failed: ${messageOf(error)}`
502
+ // 失败关闭:交付失败也绝不回退到「把明文放进结果文本」。错误消息同样过
503
+ // redactText(ARCHITECTURE「Sanitize before display/log」),因为它同样会进日志。
504
+ const message = redactText(`mask: ${actionKey} failed: ${messageOf(error)}`)
433
505
  logger.error(message)
434
506
  return { kind: 'error', text: message }
435
507
  }
package/lib/constants.mjs CHANGED
@@ -80,6 +80,8 @@ export const DEFAULTS = Object.freeze({
80
80
  MAX_RESTORE_ENTRIES_PER_SESSION: 500,
81
81
  MAX_SESSIONS: 1000,
82
82
  MASK_CLIENT_ENABLED: false,
83
+ // 还原结果交付目录;空串 = os.tmpdir()/dsh-mask-restore(见 lib/deliver.mjs)。
84
+ RESTORE_DIR: '',
83
85
  })
84
86
 
85
87
  // 配置字段合法性边界(加载期校验,越界响亮失败)。