dsh-sensitive-guard 0.5.0 → 0.5.2
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/CHANGELOG.md +17 -0
- package/README.en.md +239 -0
- package/README.md +68 -35
- package/assets/icon-180.png +0 -0
- package/client.js +33 -14
- package/index.js +7 -7
- package/package.json +46 -6
- package/screenshots.json +5 -0
- package/test.mjs +63 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# 变更记录
|
|
2
2
|
|
|
3
|
+
## 0.5.2
|
|
4
|
+
|
|
5
|
+
- 修掉对话内胶囊的 `aria-label` / `title` 硬编码中文:现在走宿主字典,英文宿主下是 `Show secret` / `Hide secret`;拿不到 locale 服务时仍回退到内置中文,不影响「没服务也要有锁」这条底线。
|
|
6
|
+
- 两个工具(`sensitive_guard_status`、`sensitive_guard_export`)的 `description` 与参数说明改成英文。tool schema 是给模型读的,英文描述对英文模型的工具选择更稳;返回的字段名与结构没动。
|
|
7
|
+
- 自测 137 → 139:新增「胶囊 aria-label 取字典(英文宿主)」与「无字典服务时胶囊回退中文标签」两项,覆盖上面这两条分支。
|
|
8
|
+
- 说明:`client.js` 里的 `密码` / `令牌` / `密钥` 是保管库存的 **kind 值**,`TONE_RULES` 里的中文是**检测规则**,两者都不是界面文案,保持中文不动。
|
|
9
|
+
|
|
10
|
+
## 0.5.1
|
|
11
|
+
|
|
12
|
+
无代码变更,只改文档与包元数据。
|
|
13
|
+
|
|
14
|
+
- README 首屏重排成 landing page:一句话钩子 → badges → 主截图 → 「不用它 / 用它」对比表 → 一行 `dsh plugin add` 安装命令。HMAC 原理与「往宿主注册了什么」下移到「工作原理」。
|
|
15
|
+
- 三张截图从 `raw.githubusercontent.com` 换到 jsdelivr CDN——raw 在国内经常裂图,而主要用户是中文用户。
|
|
16
|
+
- 新增英文版 `README.en.md`,README 顶部加中英切换。
|
|
17
|
+
- 新增 `screenshots.json`(3 张截图按顺序声明)与 `assets/icon-180.png`(180×180 位图)。插件市场的卡片图标只收位图,详情页截图优先读仓库里的 `screenshots.json` 而不是从 README 抽取。
|
|
18
|
+
- `package.json`:`description` 精简到 130 字符,`keywords` 7 → 18 项(补 `api-key` / `credential` / `secrets` / `password` / `token` / `gitleaks` 等),补 `icon` 字段。
|
|
19
|
+
|
|
3
20
|
## 0.5.0
|
|
4
21
|
|
|
5
22
|
- 接入 [gitleaks](https://github.com/gitleaks/gitleaks) 官方规则库:从 `config/gitleaks.toml`(222 条,MIT)转换成 **221 条** JS 可用正则,随包发布 `rules/gitleaks.json` 与 `NOTICE`;`pkcs12-file` 是按文件名判定的,跳过并在规则页标注「不适用」。
|
package/README.en.md
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
# dsh-sensitive-guard
|
|
2
|
+
|
|
3
|
+
**Keeps your keys out of the model context.** API keys you paste into chat, the `.env` your agent reads, passwords buried in a `config.json` tool result — all swapped for `<SG_1e62c5fe7944>` placeholders before they reach the model. Plaintext stays encrypted on your own machine (AES-256-GCM); clicking the lock reveals it. The model only ever sees the code.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/dsh-sensitive-guard)
|
|
6
|
+
[](https://www.npmjs.com/package/dsh-sensitive-guard)
|
|
7
|
+
[](https://github.com/wangxy496/dsh-sensitive-guard/stargazers)
|
|
8
|
+
[](./LICENSE)
|
|
9
|
+
[](https://github.com/deepseek-ai/deepseek-harness)
|
|
10
|
+
|
|
11
|
+
English · [中文](README.md)
|
|
12
|
+
|
|
13
|
+
<img src="https://cdn.jsdelivr.net/gh/wangxy496/dsh-sensitive-guard@main/docs/chat-masked.png" width="640" alt="A masked credential in the conversation: sk- followed by a lock pill">
|
|
14
|
+
|
|
15
|
+
*Paste `sk-proj-…` and you get this. Click the lock to reveal, it re-masks after 20 seconds.*
|
|
16
|
+
|
|
17
|
+
## Why
|
|
18
|
+
|
|
19
|
+
One pasted `.env`, one `cat config.json`, and the secret is permanently in **the session log, the model context, and every screenshot you share**.
|
|
20
|
+
|
|
21
|
+
| | Model context | Session log on disk | Your screen |
|
|
22
|
+
| --- | --- | --- | --- |
|
|
23
|
+
| Without it | `sk-proj-abcdef…` in full | in full | in full |
|
|
24
|
+
| With it | `<SG_1e62c5fe7944>` | `v1:iv:tag:ciphertext` (AES-256-GCM) | a lock, plaintext only on demand |
|
|
25
|
+
|
|
26
|
+
It does not rewrite outbound calls, does not sandbox anything, and is no substitute for rotating keys. It guarantees exactly one thing: **a secret never becomes readable text in the model context just because you copied it once.**
|
|
27
|
+
|
|
28
|
+
## Install
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
dsh plugin add dsh-sensitive-guard
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Requires dsh 0.2.0+ and Node 18+. Tested on Windows 11 and Ubuntu 22.04; not tested on macOS.
|
|
35
|
+
|
|
36
|
+
A **Sensitive guard** section appears in Settings. To verify, send this in a session:
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
my api key is sk-proj-abcdefghijklmnopqrstuvwx
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
It should render as `my api key is sk-` plus a lock pill. Click it to reveal, it re-masks after 20 seconds. Then check **Settings → Sensitive guard**: the `inline reveal:` line at the bottom reads `ok` when healthy — any other value, see [Troubleshooting](#troubleshooting).
|
|
43
|
+
|
|
44
|
+
<details>
|
|
45
|
+
<summary>Without the CLI: edit package.json by hand</summary>
|
|
46
|
+
|
|
47
|
+
Edit `~/.dsh/profiles/<profile>/package.json`:
|
|
48
|
+
|
|
49
|
+
```json
|
|
50
|
+
{
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"dsh-sensitive-guard": "0.5.0"
|
|
53
|
+
},
|
|
54
|
+
"dsh": {
|
|
55
|
+
"profile": {
|
|
56
|
+
"bundles": ["dsh-sensitive-guard"]
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Keep the existing entries in `bundles` and append this one, then run `pnpm install` in the same directory and restart dsh.
|
|
63
|
+
|
|
64
|
+
</details>
|
|
65
|
+
|
|
66
|
+
<details>
|
|
67
|
+
<summary>Local development: link mode</summary>
|
|
68
|
+
|
|
69
|
+
Replace the version with `"link:/absolute/path/to/sensitive-guard"`. Client changes apply immediately; host-side changes still need a process restart.
|
|
70
|
+
|
|
71
|
+
</details>
|
|
72
|
+
|
|
73
|
+
## Screenshots
|
|
74
|
+
|
|
75
|
+
Click the lock to reveal in place — it re-masks after 20 seconds:
|
|
76
|
+
|
|
77
|
+
<img src="https://cdn.jsdelivr.net/gh/wangxy496/dsh-sensitive-guard@main/docs/chat-revealed.png" width="640" alt="Revealed in place">
|
|
78
|
+
|
|
79
|
+
The Settings page lists every vault entry with the same lock, plus a **Copy plaintext** button that writes the value straight to your clipboard (local API call, audited, plaintext never enters the model context):
|
|
80
|
+
|
|
81
|
+
<img src="https://cdn.jsdelivr.net/gh/wangxy496/dsh-sensitive-guard@main/docs/settings.png" width="720" alt="Settings page">
|
|
82
|
+
|
|
83
|
+
## What it catches
|
|
84
|
+
|
|
85
|
+
**Vendor rules.** 221 rules from [gitleaks](https://github.com/gitleaks/gitleaks) (MIT, see `NOTICE`) — 1Password, Adobe, Adafruit, Age, AWS, GCP, Azure, Stripe, Slack and the rest. Each carries a keyword prefilter, a regex and an optional entropy threshold, so a 221-regex sweep never runs over your text. 207 high-confidence rules are on by default; 10 "approximate conversion" rules and 4 loose ones ship off and can be enabled per rule in the Rules tab. Upstream's `pkcs12-file` matches on file name (`.p12`/`.pfx`) and is marked "not applicable" for text redaction.
|
|
86
|
+
|
|
87
|
+
Vendor prefixes: `sk-`, `sk_`, `ghp_`, `glpat-`, `npm_`, `hf_`, `AKIA`, `ASIA`, `xox*-`, `AIza`, `whsec_`, `SG.`. PEM private key blocks, JWTs, `Bearer` tokens.
|
|
88
|
+
|
|
89
|
+
Assignments and env vars: `password=`, `secret:`, `api_key:`, `SECRET_KEY=`, `DB_PASSWORD=`.
|
|
90
|
+
|
|
91
|
+
**JSON and structured data.** A tool that runs `cat config.json` returns one blob of JSON, and `{"password": "Abc!23456"}` has no vendor prefix — the value alone is unrecognizable. Any field named `password`, `passwd`, `pwd`, `token`, `credential`, `api_key`, `db_pass`, `dsn`, `connection_string` (including snake_case, kebab-case and camelCase variants) gets its value replaced. Key names, nesting and sibling values are untouched. Already-parsed object results are handled the same way.
|
|
92
|
+
|
|
93
|
+
Examples and placeholders stay visible: `your_password_here`, `${DB_PASS}`, `<your-token>`, `changeme`, and field names that merely describe something (`password_policy`, `token_count`).
|
|
94
|
+
|
|
95
|
+
**Chinese phrasings** too: `数据库密码是…`, `我的 token 是…`. Chinese-language passwords are caught from 6 characters (6-digit numeric passwords are common there); English and `key=value` forms start at 8, so `the secret is hidden` does not eat `hidden`. Trailing particles (`吗`/`呢`/`吧`) and punctuation stay outside the placeholder.
|
|
96
|
+
|
|
97
|
+
**Connection strings:** `mysql://user:pass@host`, `postgresql://…`, `password=` inside JDBC params, `X-Api-Key:`.
|
|
98
|
+
|
|
99
|
+
**Command lines:** `mysql -uroot -pabc12345`, `redis-cli -a xxx`. Only these clients are recognized, so `docker run -p 8080:80` is not a false positive.
|
|
100
|
+
|
|
101
|
+
**Keys broken across lines** are re-joined: pasting from a webpage or screenshot often injects `\r`/`\n` into `sk-proj-…`. The two halves are stitched back into one vault entry, with the identical placeholder you would get unbroken.
|
|
102
|
+
|
|
103
|
+
## How the agent uses a credential
|
|
104
|
+
|
|
105
|
+
The model never gets plaintext. When it needs one — to connect to a database, to call an API — it exports:
|
|
106
|
+
|
|
107
|
+
```
|
|
108
|
+
sensitive_guard_export(<SG_xxx>) # writes plaintext to a 0600 file, returns the path
|
|
109
|
+
$(cat /that/path) # in a command: plaintext never enters context
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
There are only two tools. `sensitive_guard_status` reports status and entry metadata with no plaintext — not even an 8-character preview. `sensitive_guard_export` writes the file, which expires after 15 minutes.
|
|
113
|
+
|
|
114
|
+
The most common false bug report: the model reads `application.yml`, sees placeholders, and fails to connect. Either have it export first, or pause protection temporarily.
|
|
115
|
+
|
|
116
|
+
## Data model
|
|
117
|
+
|
|
118
|
+
Three places, kept separate:
|
|
119
|
+
|
|
120
|
+
| | Content |
|
|
121
|
+
| --- | --- |
|
|
122
|
+
| Model context | `<SG_1e62c5fe7944>`, an HMAC prefix — not reversible offline |
|
|
123
|
+
| Disk | `v1:iv:tag:ciphertext`, AES-256-GCM, key in `vault.key` |
|
|
124
|
+
| Screen | The code plus a lock; plaintext only fetched from localhost on click |
|
|
125
|
+
|
|
126
|
+
The 12 hex digits are the first bytes of `HMAC-SHA256(vault.key, plaintext)`. The key never leaves the machine, so the code cannot be brute-forced back to a short password, while the same plaintext still yields the same code every time. Releases up to 0.3.4 used a `sha256(plaintext)` prefix, which is offline-guessable for low-entropy secrets; old codes are preserved in `vault.json` under `aliases` so old sessions still unlock, and every new capture uses the new algorithm.
|
|
127
|
+
|
|
128
|
+
Two interception points: user input through `agent/pre-step`, tool results through `tools/post-execute`. `llm/stream` additionally scrubs outbound streaming text as a fallback — only `text-delta` and `reasoning-delta`, never `tool-call-delta`, or tool arguments would turn into placeholders. Field-name matching only applies at the first two entry points, so example JSON the model writes itself is left alone.
|
|
129
|
+
|
|
130
|
+
## Config
|
|
131
|
+
|
|
132
|
+
`<data dir>/rules.json`, applied within two seconds of saving, no restart. `%USERPROFILE%\.dsh\sensitive-guard\` on Windows, `~/.dsh/sensitive-guard/` on Linux.
|
|
133
|
+
|
|
134
|
+
```json
|
|
135
|
+
{
|
|
136
|
+
"extraRules": [
|
|
137
|
+
{ "id": "my-internal", "pattern": "X-WX-Token:\\s*([A-Za-z0-9]{20,})", "flags": "i", "group": 1 }
|
|
138
|
+
],
|
|
139
|
+
"disabled": ["jwt"],
|
|
140
|
+
"enabledRules": [],
|
|
141
|
+
"outboundScrub": true,
|
|
142
|
+
"entropy": false,
|
|
143
|
+
"entropyThreshold": 4.5,
|
|
144
|
+
"allowCidrs": ["192.168.0.0/16"]
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
`group` is the capture group to mask, 0 for the whole match. Your regex runs in a synchronous hook, so avoid `(a+)+` / `(.*)*` — a backtracking blowup stalls the host.
|
|
149
|
+
|
|
150
|
+
`disabled` turns off individual default-on rules by id; `enabledRules` turns on default-off ones. The Settings switches maintain both lists. `outboundScrub: false` disables the outbound fallback. `allowCidrs` is empty by default, meaning loopback only — see below.
|
|
151
|
+
|
|
152
|
+
### Reaching it from another machine
|
|
153
|
+
|
|
154
|
+
Desktop users can skip this. All HTTP routes accept loopback only, which a browser on the same machine always satisfies.
|
|
155
|
+
|
|
156
|
+
One case reaches this: dsh started with `--host 0.0.0.0` or `--host 192.168.x.x` and opened from another machine's browser. Two options — open `127.0.0.1:3080` on the host machine itself, or allow the subnet in `rules.json`:
|
|
157
|
+
|
|
158
|
+
```json
|
|
159
|
+
{ "allowCidrs": ["192.168.0.0/16"] }
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
The Settings page shows an orange banner when you arrive over the LAN. Unconfigured, the page degrades to read-only rather than blanking: entry counts, kinds, capture times and hit counts, no values and no 8-character preview, plus a card explaining the current address with a ready-to-copy config computed for your source address.
|
|
163
|
+
|
|
164
|
+
**Allowing a subnet means every device in it can read full plaintext, not just previews.** Use it on a trusted LAN only. There is no login because an auth layer would add two steps to every lock click; narrowing the subnet is the better trade.
|
|
165
|
+
|
|
166
|
+
## HTTP routes
|
|
167
|
+
|
|
168
|
+
Five routes, loopback only by default.
|
|
169
|
+
|
|
170
|
+
| Method | Path | Purpose |
|
|
171
|
+
| --- | --- | --- |
|
|
172
|
+
| GET | `/guard/vault` | Panel data with 8-char previews and the current `access` level; unauthorized sources get a `restricted: true` read-only view without previews or audit |
|
|
173
|
+
| POST | `/guard/reveal` | `{placeholder}` → `{plaintext, body, prefix}`; 403 when unauthorized |
|
|
174
|
+
| GET | `/guard/settings` | `{off, paused, untilRestart, until, remainingMs}`; `remainingMs` is `null` when persistently off |
|
|
175
|
+
| POST | `/guard/settings` | `{action:"pause", minutes:30}`, `{action:"pause", untilRestart:true}`, `{action:"resume"}` clears a timed pause; `{action:"disable"}` persists off (survives restart), `{action:"enable"}` re-enables; 403 when unauthorized |
|
|
176
|
+
| GET | `/guard/rules` | Rule list (name, source, detector tag, tier, current state), totals, skipped items |
|
|
177
|
+
| POST | `/guard/rules` | `{id, enabled}` toggles one rule, writing `disabled` / `enabledRules` |
|
|
178
|
+
| POST | `/guard/entries` | `{action:"add", name, plaintext, kind}` or `{action:"delete", placeholder}`; plaintext goes only into the encrypted vault |
|
|
179
|
+
|
|
180
|
+
## Known limits
|
|
181
|
+
|
|
182
|
+
1. In-conversation pills cover user messages only (see above for why).
|
|
183
|
+
2. No outbound rewriting. The platform's `tools/pre-execute` only exposes allow, deny, cancel and ask — there is no hook to modify arguments, so credentials must go through an export file.
|
|
184
|
+
3. The vault defends against accidental reads and plaintext on disk, not against someone who already has your account. Encryption is AES-256-GCM and the key file is tightened with `icacls` on Windows.
|
|
185
|
+
4. Historical sessions are unprotected. `pre-step` runs after the host has written the user text to the log, and `session/event` is a read-only observer, so the plugin has no chance to rewrite before disk. Plaintext in old sessions is still on disk; rotate those keys.
|
|
186
|
+
5. `exports/` is the only place plaintext lands, cleaned on the next export after 15 minutes.
|
|
187
|
+
6. The vault holds at most 500 entries, evicting by last hit.
|
|
188
|
+
7. A corrupted vault fails open so the conversation continues, but counts the event — visible as `failOpen` in `sensitive_guard_status`.
|
|
189
|
+
8. Each text is scanned up to 200,000 characters. The hook is synchronous, so this bounds custom-regex backtracking; the tail of very long text is unmasked.
|
|
190
|
+
9. `allowCidrs` assumes the subnet is trustworthy. It blocks CSRF and DNS rebinding, not an active attacker inside the subnet. `0.0.0.0/0` is rejected and logged to `rules.error`.
|
|
191
|
+
10. Unauthorized sources still read metadata (which entries exist, which rules, when captured, hit counts) so the Settings page can explain itself — the cost is that a LAN peer can infer "12 credentials, keys and passwords". Values stay hidden.
|
|
192
|
+
11. The host is fail-fast: an exception at the top level of a client entry stops the whole app from booting. `apply` is fully guarded; that top-level risk cannot be removed.
|
|
193
|
+
12. Codes issued by 0.3.4 and earlier use a `sha256(plaintext)` prefix and are offline-guessable for short passwords. New captures use HMAC. Old codes remain in `vault.json` under `aliases` so old sessions still unlock, but **codes already written into historical session logs cannot be changed** — rotate those.
|
|
194
|
+
13. Rules come from gitleaks: 10 rules using Go's `(?-i:…)` scoping flag become slightly looser after conversion to JS and are marked "approximate conversion", off by default. `pkcs12-file` matches on file name and is not wired up. Rule data ships under the MIT license, declared in `NOTICE`.
|
|
195
|
+
14. Manually added entries are pinned in the vault and never count against the 500-entry cap. Plaintext lives only in the encrypted `vault.json`, decrypted into memory for literal matching, and is **never written to `rules.json`** — but it still cannot stop someone with your local account.
|
|
196
|
+
|
|
197
|
+
## Troubleshooting
|
|
198
|
+
|
|
199
|
+
Normal uninstall: edit `~/.dsh/profiles/<profile>/package.json`, remove `"dsh-sensitive-guard"` from `dependencies` and from the `dsh.profile.bundles` array, reopen the app.
|
|
200
|
+
|
|
201
|
+
If the app will not start, the log shows `web boot: N entry did not activate` with `dsh-sensitive-guard: failed`. Kill the leftover process first:
|
|
202
|
+
|
|
203
|
+
```
|
|
204
|
+
taskkill /F /IM "DeepSeek Harness.exe"
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
then remove the dependency as above. Crash logs live in `%APPDATA%\@deepseek-ai\dsh-desktop\logs\crash-*-web-boot.log`.
|
|
208
|
+
|
|
209
|
+
Values of `inline reveal:` — `ok` is healthy, `waiting` is still waiting for the `uiConversation` service, `no-service` cannot reach it, `matcher-failed` means the rule registration was rejected, `renderer-failed` means the renderer registration was rejected.
|
|
210
|
+
|
|
211
|
+
The data directory is `$DSH_PROFILE_DIR/sensitive-guard/`, holding `vault.json`, `vault.key`, `pause.json` (`until` for a timed pause plus `off` for persistent disable), `rules.json` and `exports/`. It falls back to `$DSH_HOME` when the variable is unset.
|
|
212
|
+
|
|
213
|
+
## Development
|
|
214
|
+
|
|
215
|
+
```bash
|
|
216
|
+
node test.mjs # offline self-test
|
|
217
|
+
node scripts/build-gitleaks.mjs # regenerate rule data from upstream
|
|
218
|
+
node scripts/build-gitleaks.mjs ./gitleaks.toml
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
139 offline tests using a temporary directory, never touching the real vault: the 0.3.x code-upgrade drill, both Settings tabs and the add dialog (including custom categories), list rows and the copy button, render smoke tests for the disable-confirmation dialog, compilation and tiering of all 221 rules, per-rule entropy/switch/manual-entry regressions, and a fresh-process restart proving persistent disable really survives.
|
|
222
|
+
|
|
223
|
+
| File | Role |
|
|
224
|
+
| --- | --- |
|
|
225
|
+
| `index.js` | Host: three hooks, vault, two tools, five routes |
|
|
226
|
+
| `client.js` | Client: both Settings tabs, rules page (search/filter/paging/toggles), add dialog, in-conversation pills |
|
|
227
|
+
| `rules/gitleaks.json` | 221 rules converted from the gitleaks TOML (MIT, see `NOTICE`) |
|
|
228
|
+
| `scripts/build-gitleaks.mjs` | Rule converter, Go/RE2 → JS downgrades and tiering |
|
|
229
|
+
| `test.mjs` | Self-test |
|
|
230
|
+
| `CHANGELOG.md` | Change log |
|
|
231
|
+
| `locale/` | Market metadata for the plugin marketplace |
|
|
232
|
+
|
|
233
|
+
GitHub Actions runs Node 18, 20 and 22 on ubuntu and windows. MIT licensed.
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
If this ever kept a key out of a context it should not have entered, a star is the most direct way to help: [⭐ star](https://github.com/wangxy496/dsh-sensitive-guard/stargazers)
|
|
238
|
+
|
|
239
|
+
Found a credential format it misses? [Open an issue](https://github.com/wangxy496/dsh-sensitive-guard/issues) with a redacted sample — vendor rules can be added.
|
package/README.md
CHANGED
|
@@ -1,46 +1,50 @@
|
|
|
1
1
|
# dsh-sensitive-guard
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**把密钥挡在模型上下文之外。** 你贴进对话的 API Key、agent 读到的 `.env`、工具返回的 `config.json` 里的密码,在进入模型上下文之前就被换成 `<SG_1e62c5fe7944>` 这样的占位符。明文用 AES-256-GCM 加密留在本机,点一下小锁才看得见——模型拿到的永远只是代号。
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[](https://www.npmjs.com/package/dsh-sensitive-guard)
|
|
6
|
+
[](https://www.npmjs.com/package/dsh-sensitive-guard)
|
|
7
|
+
[](https://github.com/wangxy496/dsh-sensitive-guard/stargazers)
|
|
8
|
+
[](./LICENSE)
|
|
9
|
+
[](https://github.com/deepseek-ai/deepseek-harness)
|
|
6
10
|
|
|
7
|
-
|
|
11
|
+
中文 · [English](README.en.md)
|
|
8
12
|
|
|
9
|
-
|
|
13
|
+
<img src="https://cdn.jsdelivr.net/gh/wangxy496/dsh-sensitive-guard@main/docs/chat-masked.png" width="640" alt="对话里被遮住的凭证:sk- 后面跟一个锁形胶囊">
|
|
10
14
|
|
|
11
|
-
|
|
12
|
-
| --- | --- | --- |
|
|
13
|
-
| `agent/pre-step` | host 钩子 | 用户输入进上下文前脱敏 |
|
|
14
|
-
| `tools/post-execute` | host 钩子 | 工具结果进上下文前脱敏 |
|
|
15
|
-
| `llm/stream` | host 钩子 | 出网的流式文本兜底清洗 |
|
|
16
|
-
| `sensitive_guard_status`、`sensitive_guard_export` | host 工具 | 查状态;把明文导出成 0600 临时文件 |
|
|
17
|
-
| `/guard/vault`、`/guard/reveal`、`/guard/settings`、`/guard/rules`、`/guard/entries` | HTTP 路由 | 设置页取数、揭示明文、暂停/关闭保护、规则清单与开关、手动录入敏感数据 |
|
|
18
|
-
| `settings.section` | 客户端 slot | 设置页里的「敏感保护」 |
|
|
19
|
-
| `conversation.user.text.node` | 客户端 slot | 对话里的锁形胶囊 |
|
|
15
|
+
*输入 `sk-proj-…` 就变成这样;点开锁看明文,20 秒后自动遮回。*
|
|
20
16
|
|
|
21
|
-
|
|
17
|
+
## 为什么需要它
|
|
22
18
|
|
|
23
|
-
|
|
19
|
+
一段对话里只要贴过一次 `.env`、让 agent `cat config.json`,密钥就永久留在了**会话日志、模型上下文,以及你随手分享的截图**里。
|
|
24
20
|
|
|
25
|
-
|
|
21
|
+
| | 模型上下文 | 落盘的会话日志 | 你的屏幕 |
|
|
22
|
+
| --- | --- | --- | --- |
|
|
23
|
+
| 不用它 | `sk-proj-abcdef…` 完整明文 | 完整明文 | 完整明文 |
|
|
24
|
+
| 用它 | `<SG_1e62c5fe7944>` | `v1:iv:tag:密文`(AES-256-GCM) | 锁,点开才向本机要明文 |
|
|
26
25
|
|
|
27
|
-
|
|
26
|
+
它不做出口改写、不做沙箱、也不替代密钥轮换。它只保证一件事:**密钥不会因为你的一次复制粘贴,变成模型上下文里的一段可读文本。**
|
|
28
27
|
|
|
29
|
-
|
|
28
|
+
## 安装
|
|
30
29
|
|
|
31
|
-
|
|
30
|
+
```bash
|
|
31
|
+
dsh plugin add dsh-sensitive-guard
|
|
32
|
+
```
|
|
32
33
|
|
|
33
|
-
|
|
34
|
+
要求 dsh 0.2.0 以上、Node 18 以上。Windows 11 和 Ubuntu 22.04 实测过,macOS 没测。
|
|
34
35
|
|
|
35
|
-
|
|
36
|
+
装完在设置页会多出「敏感保护」一节。发一句:
|
|
36
37
|
|
|
37
|
-
|
|
38
|
+
```
|
|
39
|
+
我的 api key 是 sk-proj-abcdefghijklmnopqrstuvwx
|
|
40
|
+
```
|
|
38
41
|
|
|
39
|
-
|
|
42
|
+
应该显示成 `我的 api key 是 sk-` 加一个锁形胶囊。点开能看到明文,20 秒后自动遮回。再看「设置 → 敏感保护」,最下面一行 `inline reveal:` 显示 `ok` 就正常,显示别的就翻到文末「卸载和故障」。
|
|
40
43
|
|
|
41
|
-
|
|
44
|
+
<details>
|
|
45
|
+
<summary>不用 CLI:手改 package.json</summary>
|
|
42
46
|
|
|
43
|
-
|
|
47
|
+
编辑 `~/.dsh/profiles/<profile>/package.json`:
|
|
44
48
|
|
|
45
49
|
```json
|
|
46
50
|
{
|
|
@@ -57,21 +61,24 @@ DSH 插件分 host 端和客户端两半,这个插件两半都占:host 端
|
|
|
57
61
|
|
|
58
62
|
`bundles` 里保留原有条目,只追加这一项。然后在同目录跑 `pnpm install`,重启 dsh。
|
|
59
63
|
|
|
60
|
-
|
|
64
|
+
</details>
|
|
61
65
|
|
|
62
|
-
|
|
66
|
+
<details>
|
|
67
|
+
<summary>本地改代码:link 模式</summary>
|
|
63
68
|
|
|
64
|
-
|
|
69
|
+
把版本号换成 `"link:/absolute/path/to/sensitive-guard"`,源码改动立刻生效,但 host 端的改动还是要重启进程。
|
|
65
70
|
|
|
66
|
-
|
|
71
|
+
</details>
|
|
67
72
|
|
|
68
|
-
|
|
69
|
-
我的 api key 是 sk-proj-abcdefghijklmnopqrstuvwx
|
|
70
|
-
```
|
|
73
|
+
## 长什么样
|
|
71
74
|
|
|
72
|
-
|
|
75
|
+
点一下锁,就地显示明文,20 秒后自动遮回:
|
|
76
|
+
|
|
77
|
+
<img src="https://cdn.jsdelivr.net/gh/wangxy496/dsh-sensitive-guard@main/docs/chat-revealed.png" width="640" alt="点开后显示明文">
|
|
78
|
+
|
|
79
|
+
设置页列出保管库里全部条目,行尾的锁同样能揭示;旁边的「复制明文」直接把值写进剪贴板(走本机接口,明文不进模型上下文):
|
|
73
80
|
|
|
74
|
-
|
|
81
|
+
<img src="https://cdn.jsdelivr.net/gh/wangxy496/dsh-sensitive-guard@main/docs/settings.png" width="720" alt="设置页">
|
|
75
82
|
|
|
76
83
|
## 日常怎么用
|
|
77
84
|
|
|
@@ -96,6 +103,26 @@ sensitive_guard_export(<SG_xxx>) 明文写到 0600 文件,返回路径
|
|
|
96
103
|
|
|
97
104
|
常被当成 bug 的一点:模型读 `application.yml` 时看到的是占位符,拿它去连库必然失败。要么让它先导出,要么临时点个暂停。
|
|
98
105
|
|
|
106
|
+
## 工作原理
|
|
107
|
+
|
|
108
|
+
代号里那 12 位十六进制是 `HMAC-SHA256(vault.key, 明文)` 的前缀。密钥只在本机,所以拿到代号的人没法靠穷举短密码反推;同一个密钥每次仍然得到同一个代号。0.3.4 及更早用的是 `sha256(明文)` 前缀,短密码可以离线猜出来,升级后旧代号仍保留可解锁,新捕获一律换成新算法。
|
|
109
|
+
|
|
110
|
+
### 它往宿主里注册了什么
|
|
111
|
+
|
|
112
|
+
DSH 插件分 host 端和客户端两半,这个插件两半都占:host 端抓数据、管保管库、开接口;客户端加设置页和对话里的胶囊。
|
|
113
|
+
|
|
114
|
+
| 注册点 | 端 | 作用 |
|
|
115
|
+
| --- | --- | --- |
|
|
116
|
+
| `agent/pre-step` | host 钩子 | 用户输入进上下文前脱敏 |
|
|
117
|
+
| `tools/post-execute` | host 钩子 | 工具结果进上下文前脱敏 |
|
|
118
|
+
| `llm/stream` | host 钩子 | 出网的流式文本兜底清洗 |
|
|
119
|
+
| `sensitive_guard_status`、`sensitive_guard_export` | host 工具 | 查状态;把明文导出成 0600 临时文件 |
|
|
120
|
+
| `/guard/vault`、`/guard/reveal`、`/guard/settings`、`/guard/rules`、`/guard/entries` | HTTP 路由 | 设置页取数、揭示明文、暂停/关闭保护、规则清单与开关、手动录入敏感数据 |
|
|
121
|
+
| `settings.section` | 客户端 slot | 设置页里的「敏感保护」 |
|
|
122
|
+
| `conversation.user.text.node` | 客户端 slot | 对话里的锁形胶囊 |
|
|
123
|
+
|
|
124
|
+
前提只要 `tools` 一个。`webServer` 不存在时脱敏照常工作,只是设置页和揭示用不了。
|
|
125
|
+
|
|
99
126
|
## 数据在哪
|
|
100
127
|
|
|
101
128
|
三处是分开的。
|
|
@@ -233,7 +260,7 @@ node scripts/build-gitleaks.mjs # 从上游重新生成规则数
|
|
|
233
260
|
node scripts/build-gitleaks.mjs ./gitleaks.toml
|
|
234
261
|
```
|
|
235
262
|
|
|
236
|
-
|
|
263
|
+
139 项离线自测,用临时目录,不碰真实保管库。包含 0.3.x 旧代号升级演练、两个设置页标签与添加弹窗(含自定义分类)、列表行与复制按钮、关闭保护确认弹窗的渲染冒烟测试、221 条规则的编译与分级校验、逐条熵值/开关/手动录入回归,以及一次用新进程模拟重启验证持久关闭仍然生效。
|
|
237
264
|
|
|
238
265
|
| 文件 | 作用 |
|
|
239
266
|
| --- | --- |
|
|
@@ -246,3 +273,9 @@ node scripts/build-gitleaks.mjs ./gitleaks.toml
|
|
|
246
273
|
| `locale/` | 插件市场用的中英元数据 |
|
|
247
274
|
|
|
248
275
|
GitHub Actions 在 ubuntu 和 windows 上跑 node 18、20、22 三个版本。许可证 MIT。
|
|
276
|
+
|
|
277
|
+
---
|
|
278
|
+
|
|
279
|
+
如果它帮你挡掉过一次不该进上下文的密钥,给个 star 是最直接的帮助:[⭐ star](https://github.com/wangxy496/dsh-sensitive-guard/stargazers)
|
|
280
|
+
|
|
281
|
+
遇到不认的凭据格式,[提个 issue](https://github.com/wangxy496/dsh-sensitive-guard/issues),带上脱敏后的样例,规则可以按厂商补。
|
|
Binary file
|
package/client.js
CHANGED
|
@@ -1037,7 +1037,17 @@ window.__ModuleLoader__.load({
|
|
|
1037
1037
|
* re-masks on its own. The plaintext never enters model context: this is a
|
|
1038
1038
|
* browser fetch, not a tool result.
|
|
1039
1039
|
*/
|
|
1040
|
-
|
|
1040
|
+
/**
|
|
1041
|
+
* Chip labels come from the host dictionary when it is available. The built-in
|
|
1042
|
+
* Chinese stays as the fallback: a host without a locale service must not cost
|
|
1043
|
+
* users the in-conversation lock (see registerInlineReveal).
|
|
1044
|
+
*/
|
|
1045
|
+
const chipLabel = (t, revealed) =>
|
|
1046
|
+
typeof t === 'function'
|
|
1047
|
+
? t(revealed ? 'hide' : 'reveal')
|
|
1048
|
+
: revealed ? '隐藏明文' : '显示明文';
|
|
1049
|
+
|
|
1050
|
+
function RevealChip({ ph, interactive, t }) {
|
|
1041
1051
|
const [value, setValue] = useState(null);
|
|
1042
1052
|
const [busy, setBusy] = useState(false);
|
|
1043
1053
|
const [tone, setTone] = useState(() => {
|
|
@@ -1131,8 +1141,8 @@ window.__ModuleLoader__.load({
|
|
|
1131
1141
|
cursor: 'pointer',
|
|
1132
1142
|
},
|
|
1133
1143
|
'aria-pressed': value !== null,
|
|
1134
|
-
'aria-label': value !== null
|
|
1135
|
-
title: value !== null
|
|
1144
|
+
'aria-label': chipLabel(t, value !== null),
|
|
1145
|
+
title: chipLabel(t, value !== null),
|
|
1136
1146
|
disabled: busy,
|
|
1137
1147
|
onClick: toggle,
|
|
1138
1148
|
}, h(LockGlyph, { open: value !== null })));
|
|
@@ -1143,7 +1153,7 @@ window.__ModuleLoader__.load({
|
|
|
1143
1153
|
* best-effort: a missing service or a changed slot contract must degrade to
|
|
1144
1154
|
* "placeholder shown as plain text", never break the message list.
|
|
1145
1155
|
*/
|
|
1146
|
-
function registerInlineReveal(ctx, slots) {
|
|
1156
|
+
function registerInlineReveal(ctx, slots, t) {
|
|
1147
1157
|
const install = (conv) => {
|
|
1148
1158
|
if (!conv || !conv.userText || typeof conv.userText.register !== 'function') {
|
|
1149
1159
|
inlineState = 'no-service';
|
|
@@ -1186,6 +1196,7 @@ window.__ModuleLoader__.load({
|
|
|
1186
1196
|
}, (props) => h(RevealChip, {
|
|
1187
1197
|
ph: props && props.node && props.node.data ? props.node.data.ph : '',
|
|
1188
1198
|
interactive: props ? props.interactive : true,
|
|
1199
|
+
t,
|
|
1189
1200
|
}));
|
|
1190
1201
|
inlineState = 'ok';
|
|
1191
1202
|
} catch (error) {
|
|
@@ -1238,18 +1249,26 @@ window.__ModuleLoader__.load({
|
|
|
1238
1249
|
function applyEntry(ctx) {
|
|
1239
1250
|
const slots = ctx && ctx.slots;
|
|
1240
1251
|
if (!slots || typeof slots.inject !== 'function' || typeof slots.register !== 'function') return;
|
|
1241
|
-
//
|
|
1242
|
-
//
|
|
1243
|
-
|
|
1252
|
+
// The dictionary goes first because the lock chip takes its accessible label
|
|
1253
|
+
// from it. It stays optional: without a locale service the chip falls back to
|
|
1254
|
+
// the built-in Chinese labels and only the settings page is skipped, so a
|
|
1255
|
+
// missing service never costs users the in-conversation lock.
|
|
1244
1256
|
const locale = ctx && ctx.locale;
|
|
1245
|
-
|
|
1246
|
-
if (typeof locale.register
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1257
|
+
let t = null;
|
|
1258
|
+
if (locale && typeof locale.register === 'function' && typeof locale.bind === 'function') {
|
|
1259
|
+
try {
|
|
1260
|
+
ctx.effect(() => locale.register(NS, { zh, en }), 'sensitive-guard: dictionaries');
|
|
1261
|
+
} catch (error) {
|
|
1262
|
+
console.warn('[sensitive-guard] dictionary registration failed:', error && error.message);
|
|
1263
|
+
}
|
|
1264
|
+
try {
|
|
1265
|
+
t = locale.bind(NS);
|
|
1266
|
+
} catch (error) {
|
|
1267
|
+
console.warn('[sensitive-guard] dictionary bind failed:', error && error.message);
|
|
1268
|
+
}
|
|
1251
1269
|
}
|
|
1252
|
-
|
|
1270
|
+
registerInlineReveal(ctx, slots, t);
|
|
1271
|
+
if (typeof t !== 'function') return;
|
|
1253
1272
|
slots.inject('settings.section', () => {
|
|
1254
1273
|
try {
|
|
1255
1274
|
return slots.register({
|
package/index.js
CHANGED
|
@@ -996,9 +996,9 @@ const STATUS_OUTPUT = {
|
|
|
996
996
|
type: 'object',
|
|
997
997
|
additionalProperties: false,
|
|
998
998
|
properties: {
|
|
999
|
-
ph: { type: 'string', description: '
|
|
1000
|
-
rule: { type: 'string', description: '
|
|
1001
|
-
origin: { type: 'string', description: '
|
|
999
|
+
ph: { type: 'string', description: 'Context placeholder' },
|
|
1000
|
+
rule: { type: 'string', description: 'Rule id that matched' },
|
|
1001
|
+
origin: { type: 'string', description: 'Where it was first captured' },
|
|
1002
1002
|
createdAt: { type: 'string' },
|
|
1003
1003
|
lastHitAt: { type: 'string' },
|
|
1004
1004
|
hits: { type: 'number' },
|
|
@@ -1018,7 +1018,7 @@ const EXPORT_OUTPUT = {
|
|
|
1018
1018
|
type: 'object',
|
|
1019
1019
|
additionalProperties: false,
|
|
1020
1020
|
properties: {
|
|
1021
|
-
path: { type: 'string', description: '
|
|
1021
|
+
path: { type: 'string', description: 'Path of the plaintext file (0600)' },
|
|
1022
1022
|
note: { type: 'string' },
|
|
1023
1023
|
},
|
|
1024
1024
|
required: ['path', 'note'],
|
|
@@ -1067,7 +1067,7 @@ function snapshot(view) {
|
|
|
1067
1067
|
function registerTools(ctx) {
|
|
1068
1068
|
ctx.effect(() => ctx.tools.register({
|
|
1069
1069
|
name: 'sensitive_guard_status',
|
|
1070
|
-
description: '
|
|
1070
|
+
description: 'Show the runtime status of Sensitive guard: metadata for every vault entry (placeholder, rule that matched, capture origin, timestamps, hit count), counters and errors. The result contains no plaintext characters and no plaintext fragments.',
|
|
1071
1071
|
parameters: {},
|
|
1072
1072
|
output: {
|
|
1073
1073
|
schema: STATUS_OUTPUT,
|
|
@@ -1091,12 +1091,12 @@ function registerTools(ctx) {
|
|
|
1091
1091
|
|
|
1092
1092
|
ctx.effect(() => ctx.tools.register({
|
|
1093
1093
|
name: 'sensitive_guard_export',
|
|
1094
|
-
description: '
|
|
1094
|
+
description: 'Export one masked secret (an <SG_ placeholder) to a plaintext file with 0600 permissions on this machine, for use from a command (e.g. --password "$(cat <path>)", source <path>). The plaintext is written only to that file and never enters the session context. Call this only when a credential is genuinely needed to run something; every export is audited.',
|
|
1095
1095
|
parameters: {
|
|
1096
1096
|
type: 'object',
|
|
1097
1097
|
additionalProperties: false,
|
|
1098
1098
|
properties: {
|
|
1099
|
-
placeholder: { type: 'string', description: '
|
|
1099
|
+
placeholder: { type: 'string', description: 'Vault placeholder, such as <SG_012345abcdef>' },
|
|
1100
1100
|
},
|
|
1101
1101
|
required: ['placeholder'],
|
|
1102
1102
|
},
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-sensitive-guard",
|
|
3
|
-
"version": "0.5.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.5.2",
|
|
4
|
+
"description": "敏感信息脱敏 DSH 插件:密钥、令牌、密码、API Key 在进入模型上下文前替换为 <SG_> 占位符,内置 221 条 gitleaks 规则与 .env/JSON 字段识别;明文 AES-256-GCM 加密存本机保管库,点小锁看真值,可导出给命令用。",
|
|
5
5
|
"license": "MIT",
|
|
6
|
+
"icon": "icon.svg",
|
|
6
7
|
"author": "wangxinyu",
|
|
7
8
|
"repository": {
|
|
8
9
|
"type": "git",
|
|
@@ -12,7 +13,26 @@
|
|
|
12
13
|
"url": "https://github.com/wangxy496/dsh-sensitive-guard/issues"
|
|
13
14
|
},
|
|
14
15
|
"homepage": "https://github.com/wangxy496/dsh-sensitive-guard#readme",
|
|
15
|
-
"keywords": [
|
|
16
|
+
"keywords": [
|
|
17
|
+
"dsh",
|
|
18
|
+
"dsh-plugin",
|
|
19
|
+
"deepseek-harness",
|
|
20
|
+
"sensitive",
|
|
21
|
+
"secret",
|
|
22
|
+
"secrets",
|
|
23
|
+
"credential",
|
|
24
|
+
"api-key",
|
|
25
|
+
"password",
|
|
26
|
+
"token",
|
|
27
|
+
"redact",
|
|
28
|
+
"redaction",
|
|
29
|
+
"mask",
|
|
30
|
+
"vault",
|
|
31
|
+
"encrypt",
|
|
32
|
+
"security",
|
|
33
|
+
"privacy",
|
|
34
|
+
"gitleaks"
|
|
35
|
+
],
|
|
16
36
|
"private": false,
|
|
17
37
|
"type": "module",
|
|
18
38
|
"engines": {
|
|
@@ -25,16 +45,36 @@
|
|
|
25
45
|
"./locale/*.json": "./locale/*.json",
|
|
26
46
|
"./icon": "./icon.svg"
|
|
27
47
|
},
|
|
28
|
-
"files": [
|
|
48
|
+
"files": [
|
|
49
|
+
"index.js",
|
|
50
|
+
"client.js",
|
|
51
|
+
"cordis.patch.yml",
|
|
52
|
+
"locale/*.json",
|
|
53
|
+
"icon.svg",
|
|
54
|
+
"assets/*.png",
|
|
55
|
+
"screenshots.json",
|
|
56
|
+
"README.md",
|
|
57
|
+
"README.en.md",
|
|
58
|
+
"CHANGELOG.md",
|
|
59
|
+
"LICENSE",
|
|
60
|
+
"NOTICE",
|
|
61
|
+
"test.mjs",
|
|
62
|
+
"rules/*.json",
|
|
63
|
+
"scripts/build-gitleaks.mjs"
|
|
64
|
+
],
|
|
29
65
|
"scripts": {
|
|
30
66
|
"test": "node test.mjs"
|
|
31
67
|
},
|
|
32
68
|
"dsh": {
|
|
33
|
-
"bundle": {
|
|
69
|
+
"bundle": {
|
|
70
|
+
"patch": "./cordis.patch.yml"
|
|
71
|
+
},
|
|
34
72
|
"client": {
|
|
35
73
|
"platform": "web",
|
|
36
74
|
"immediately": true,
|
|
37
|
-
"inject": [
|
|
75
|
+
"inject": [
|
|
76
|
+
"@deepseek-ai/dsh-client-ui-sidebar"
|
|
77
|
+
]
|
|
38
78
|
}
|
|
39
79
|
}
|
|
40
80
|
}
|
package/screenshots.json
ADDED
package/test.mjs
CHANGED
|
@@ -279,6 +279,69 @@ const fullCtx = new Proxy({
|
|
|
279
279
|
api.apply(fullCtx);
|
|
280
280
|
check('inline renderer uses keyed registration', registered.some((r) => r.key === 'sensitive-guard'));
|
|
281
281
|
|
|
282
|
+
/**
|
|
283
|
+
* The in-conversation chip takes its accessible label from the host dictionary,
|
|
284
|
+
* with the built-in Chinese as fallback. Both branches are load-bearing: without
|
|
285
|
+
* the fallback a host that provides no locale service loses the label entirely,
|
|
286
|
+
* and without the dictionary an English host gets a Chinese tooltip and screen
|
|
287
|
+
* reader announcement.
|
|
288
|
+
*/
|
|
289
|
+
function renderInlineChip(translate, revealed) {
|
|
290
|
+
let stateIndex = 0;
|
|
291
|
+
const ReactStub = {
|
|
292
|
+
createElement: (type, props, ...children) => (
|
|
293
|
+
typeof type === 'function' ? type({ ...(props || {}), children }) : { type, props, children }
|
|
294
|
+
),
|
|
295
|
+
Fragment: 'Fragment',
|
|
296
|
+
useState: (initial) => {
|
|
297
|
+
stateIndex += 1;
|
|
298
|
+
if (stateIndex === 1) return [revealed ? 'plain-value' : null, () => {}];
|
|
299
|
+
return [typeof initial === 'function' ? initial() : initial, () => {}];
|
|
300
|
+
},
|
|
301
|
+
useEffect: () => {},
|
|
302
|
+
useRef: () => ({ current: 0 }),
|
|
303
|
+
useCallback: (fn) => fn,
|
|
304
|
+
};
|
|
305
|
+
let chipApi = null;
|
|
306
|
+
const win = { __ModuleLoader__: { load(def) { chipApi = def.factory((n) => (n === 'react' ? ReactStub : {})); } } };
|
|
307
|
+
const capturedChip = [];
|
|
308
|
+
const chipSlots = {
|
|
309
|
+
inject(_name, factory) {
|
|
310
|
+
const it = factory();
|
|
311
|
+
if (it && typeof it.next === 'function') { let s = it.next(); while (!s.done) s = it.next(); }
|
|
312
|
+
},
|
|
313
|
+
register(options, renderer) { capturedChip.push({ options, renderer }); return () => {}; },
|
|
314
|
+
};
|
|
315
|
+
const conv = { uiConversation: { userText: { register: () => {} } } };
|
|
316
|
+
const ctx = new Proxy({
|
|
317
|
+
slots: chipSlots,
|
|
318
|
+
effect: () => () => {},
|
|
319
|
+
locale: { register: () => () => {}, bind: () => translate },
|
|
320
|
+
get: (name) => conv[name],
|
|
321
|
+
inject: (_deps, cb) => cb(conv),
|
|
322
|
+
}, { get(t, p) { return p in t ? t[p] : undefined; } });
|
|
323
|
+
new Function('window', 'globalThis', clientSrc).call(globalThis, win, globalThis);
|
|
324
|
+
chipApi.apply(ctx);
|
|
325
|
+
const node = capturedChip.find((c) => c.options && c.options.name === 'conversation.user.text.node');
|
|
326
|
+
if (!node) return null;
|
|
327
|
+
const tree = node.renderer({ node: { data: { ph: '<SG_aaaaaaaaaaaa>' } }, interactive: true });
|
|
328
|
+
const findButton = (n) => {
|
|
329
|
+
if (!n || typeof n !== 'object') return null;
|
|
330
|
+
if (n.type === 'button') return n;
|
|
331
|
+
for (const kid of n.children || []) { const hit = findButton(kid); if (hit) return hit; }
|
|
332
|
+
return null;
|
|
333
|
+
};
|
|
334
|
+
return findButton(tree);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
const chipEn = renderInlineChip((k) => ({ reveal: 'Show secret', hide: 'Hide secret' }[k] || k), false);
|
|
338
|
+
check('胶囊 aria-label 取字典(英文宿主)',
|
|
339
|
+
chipEn && chipEn.props['aria-label'] === 'Show secret', chipEn && chipEn.props['aria-label']);
|
|
340
|
+
|
|
341
|
+
const chipZh = renderInlineChip(null, false);
|
|
342
|
+
check('无字典服务时胶囊回退中文标签',
|
|
343
|
+
chipZh && chipZh.props['aria-label'] === '显示明文', chipZh && chipZh.props['aria-label']);
|
|
344
|
+
|
|
282
345
|
/**
|
|
283
346
|
* Render both tabs through a React stub that actually calls function
|
|
284
347
|
* components. Catches runtime errors in the new settings UI (undefined.map,
|