dsh-plugin-showcase 0.1.0 → 0.2.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 +221 -126
- package/README.zh.md +180 -92
- package/lib/client.js +121 -7
- package/lib/index.js +337 -7
- package/market/index.json +53 -0
- package/package.json +4 -3
package/README.zh.md
CHANGED
|
@@ -1,35 +1,56 @@
|
|
|
1
1
|
# dsh-plugin-showcase
|
|
2
2
|
|
|
3
|
-
一个 **DeepSeek Harness(DSH)**
|
|
4
|
-
|
|
5
|
-
读完。
|
|
3
|
+
一个 **DeepSeek Harness(DSH)** 的新人首装搭档:用一句话说明它所在的这台 DSH 主机
|
|
4
|
+
是什么状况,同时把八个插件能力面一次性用满,因此整块接口面可以在一个小包里读完。
|
|
6
5
|
|
|
7
|
-
|
|
6
|
+
版本 **0.2.0**。v1 的能力面一个都没退化(`showcase_inspect`、`/showcase on|off`、
|
|
7
|
+
拦截门、三处 slot、locale、icon、patch 全部保持),v2 增加了体检、两个命令分支、
|
|
8
|
+
面板里的三步引导,以及随包分发的自托管市场索引。
|
|
9
|
+
|
|
10
|
+
| 能力面 | 位置(v0.2.0) |
|
|
8
11
|
| --- | --- |
|
|
9
|
-
| 工具 `showcase_inspect` | `lib/index.js:
|
|
10
|
-
|
|
|
11
|
-
|
|
|
12
|
-
|
|
|
13
|
-
|
|
|
14
|
-
|
|
|
15
|
-
|
|
|
12
|
+
| 工具 `showcase_inspect` | `lib/index.js:600`,注册在 `:638` |
|
|
13
|
+
| 工具 `showcase_doctor` | `lib/index.js:619`,注册在 `:639` |
|
|
14
|
+
| 钩子 `tools/pre-execute` | `lib/index.js:641`(拦截门),模式表 `:21`–`:38` |
|
|
15
|
+
| 斜杠命令 `/showcase` | `lib/index.js:652` |
|
|
16
|
+
| 设置卡片 | `lib/client.js:531`(`settings.section`,id `showcase`) |
|
|
17
|
+
| 右侧栏面板 | 面板体 `lib/client.js:551`,tab 类型 `:539` |
|
|
18
|
+
| 国际化 | `lib/client.js:13`(19 键)、`locale/en.json`、`locale/zh.json` |
|
|
19
|
+
| 市场索引 | `market/index.json`(在 `files` 白名单里随包发布) |
|
|
16
20
|
| 测试 | `tests/host.test.mjs`、`tests/client.test.mjs` |
|
|
17
21
|
|
|
18
|
-
|
|
19
|
-
`@deepseek-ai` import。
|
|
22
|
+
行号对应 v0.2.0。全程零构建:只有原生 ESM JavaScript,没有第三方运行时依赖,也没有
|
|
23
|
+
任何 `@deepseek-ai` import。
|
|
20
24
|
|
|
21
25
|
## 安装与卸载
|
|
22
26
|
|
|
23
27
|
本机使用的 profile:`C:\Users\baba\.dsh\profiles\web`。
|
|
24
28
|
|
|
25
|
-
###
|
|
29
|
+
### 方式一:从市场安装(正常路径)
|
|
30
|
+
|
|
31
|
+
1. 把 0.2.0 发布到 npm(流程见 `PUBLISH.md`),包内索引就能在
|
|
32
|
+
`https://cdn.jsdelivr.net/npm/dsh-plugin-showcase@latest/market/index.json` 取到。
|
|
33
|
+
2. 打开 DSH → 设置 → 市场/发现页,把这个 URL 添加为索引源。宿主服务
|
|
34
|
+
`pluginMarket` 维护这份 `indexes` 列表,它的初始值是空数组:发现页**不搜索
|
|
35
|
+
npm**,所以没配索引之前什么都不会出现。
|
|
36
|
+
3. 搜索 `dsh-plugin-showcase` → 安装。包会装进 profile,并把它在 `dsh.bundle` 里
|
|
37
|
+
对应的条目追加进 `dsh.profile.bundles`,层随即生效。
|
|
38
|
+
|
|
39
|
+
索引随包分发,所以从 **0.2.0** 起才有:0.1.0 发布时包里没有 `market/`,它没有索引。
|
|
40
|
+
0.2.0 及以后的版本,上面那条 CDN 地址直接就能取到索引——不需要本机服务,也没有任何
|
|
41
|
+
进程要你养着。
|
|
42
|
+
|
|
43
|
+
不想等索引,也可以直接按 registry 名安装:
|
|
26
44
|
|
|
27
45
|
```sh
|
|
28
|
-
dsh plugin --profile web add
|
|
46
|
+
dsh plugin --profile web add dsh-plugin-showcase
|
|
29
47
|
```
|
|
30
48
|
|
|
31
|
-
|
|
32
|
-
|
|
49
|
+
### 方式二:从 checkout 安装(官方命令)
|
|
50
|
+
|
|
51
|
+
```sh
|
|
52
|
+
dsh plugin --profile web add <本目录路径>
|
|
53
|
+
```
|
|
33
54
|
|
|
34
55
|
本机 `PATH` 上没有全局 `dsh`,所以同一个命令改从检出调用:
|
|
35
56
|
|
|
@@ -37,27 +58,25 @@ dsh plugin --profile web add <本目录路径>
|
|
|
37
58
|
node "C:\Users\baba\Desktop\deepseek-harness\apps\cli\lib\bin.js" plugin --profile web add "C:\Users\baba\Desktop\DSH工作区\plugins\dsh-plugin-showcase"
|
|
38
59
|
```
|
|
39
60
|
|
|
40
|
-
卸载:`... plugin --profile web remove dsh-plugin-showcase
|
|
61
|
+
卸载:`... plugin --profile web remove dsh-plugin-showcase`。
|
|
41
62
|
|
|
42
|
-
###
|
|
63
|
+
### 方式三:本机实际使用的手动等价物
|
|
43
64
|
|
|
44
65
|
三处改动,不跑安装:
|
|
45
66
|
|
|
46
67
|
1. `C:\Users\baba\.dsh\profiles\web\package.json` 的 `dependencies` 加一行
|
|
47
68
|
`"dsh-plugin-showcase": "link:C:/Users/baba/Desktop/DSH工作区/plugins/dsh-plugin-showcase"`;
|
|
48
|
-
2. 同一个文件的 `dsh.profile.bundles` 末尾追加 `"dsh-plugin-showcase"
|
|
49
|
-
(目前它就是最后一项);
|
|
69
|
+
2. 同一个文件的 `dsh.profile.bundles` 末尾追加 `"dsh-plugin-showcase"`;
|
|
50
70
|
3. 建一个目录 junction,让 Node 能解析这个包名:
|
|
51
71
|
`C:\Users\baba\.dsh\profiles\web\node_modules\dsh-plugin-showcase`
|
|
52
72
|
→ `C:\Users\baba\Desktop\DSH工作区\plugins\dsh-plugin-showcase`
|
|
53
|
-
(本机实测为 `<JUNCTION>`
|
|
54
|
-
`cmd /c mklink /J <链接> <目标>`)。
|
|
73
|
+
(本机实测为 `<JUNCTION>` 重解析点;重建命令 `cmd /c mklink /J <链接> <目标>`)。
|
|
55
74
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
`dsh-
|
|
59
|
-
|
|
60
|
-
|
|
75
|
+
**为什么本机不用安装命令。** 它会在 profile 内跑一次安装,而这次安装会重新解析整棵树。
|
|
76
|
+
这个 profile 里已经装着十一个第三方插件(`dsh-cost-meter`、`dsh-better-sidebar`、
|
|
77
|
+
`dsh-chat-import`、`dsh-context`、`dsh-memgas`、`dsh-wallpaper-bg`、`@linxin666/*`、
|
|
78
|
+
`@liustack/*`、`@tt-a1i/archify-dsh`)。上面三处改动正是链接安装后的最终状态,但没有那次
|
|
79
|
+
可能改写这十一个插件版本的解析过程。
|
|
61
80
|
|
|
62
81
|
不启动、只验证层(以下为实测输出):
|
|
63
82
|
|
|
@@ -73,14 +92,58 @@ DSH 的 HMR 监视 profile 的 `package.json`(只看 `bundles` 数组)与 pr
|
|
|
73
92
|
文件,因此追加条目会在不重启宿主进程的情况下重新组合;浏览器那一半需要刷新一次页面。
|
|
74
93
|
撤销同样只是把这三处改回去。
|
|
75
94
|
|
|
76
|
-
##
|
|
95
|
+
## 体检(0.2.0 新增)
|
|
96
|
+
|
|
97
|
+
`showcase_doctor` 无参数,返回一份 **HealthReport**:
|
|
98
|
+
|
|
99
|
+
```
|
|
100
|
+
{
|
|
101
|
+
generatedAt: "ISO", pluginVersion: "0.2.0",
|
|
102
|
+
dshVersion: "0.2.1-rc.2", // string | null
|
|
103
|
+
summary: { ok, warn, fail, unknown }, // 整数,与下面 checks 的统计恒等
|
|
104
|
+
checks: [{ id, title, status, detail, hint }] // hint: string | null
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
两种问法:
|
|
109
|
+
|
|
110
|
+
- 工具:跑一次 `showcase_doctor`(`showcase_inspect` 仍然返回 v1 那份巡检快照)
|
|
111
|
+
- 命令:`/showcase doctor` —— 同一段文本直接回在对话里
|
|
112
|
+
|
|
113
|
+
渲染文本首行是 `DSH 体检报告 <generatedAt>`,随后每条 check 一行
|
|
114
|
+
`[OK|WARN|FAIL|?] <title> — <detail>`,有下一步时再缩进一行 ` ↳ <hint>`,末行是
|
|
115
|
+
`合计: ok N / warn N / fail N / unknown N`。
|
|
116
|
+
|
|
117
|
+
六项 check(按顺序):
|
|
77
118
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
119
|
+
| id | 看什么 | ok / warn / fail / unknown |
|
|
120
|
+
| --- | --- | --- |
|
|
121
|
+
| `engine.dsh` | 运行中的 DSH 版本(读 `<profile>/node_modules/@deepseek-ai/dsh-app-boot/package.json`)与 `engines.dsh` 比对 | ok = 满足范围,fail = 不满足(hint 提示升级),warn = 未声明 `engines.dsh`,unknown = 版本读不到或范围无法离线解析 |
|
|
122
|
+
| `workspace.cwd` | `workingDirectory` | ok = 有目录,warn = 取不到 |
|
|
123
|
+
| `model.default` | `agentDefaultModel` | ok = `provider/model`,unknown = 无该服务 |
|
|
124
|
+
| `plugin.gate` | 本插件的拦截门 | ok = 开启,warn = 关闭(hint: `/showcase on`) |
|
|
125
|
+
| `plugin.locale` | `settings.describe()` 里的界面语言偏好 | ok = 有值,unknown = 读不到 |
|
|
126
|
+
| `market.index` | `pluginMarket.listIndexes()` 的索引列表 | ok = 每个源都可用,warn = 一条都没配或部分不可用,unknown = 没有市场服务 |
|
|
81
127
|
|
|
82
|
-
|
|
83
|
-
|
|
128
|
+
**任何一条 check 内部抛错都不会让整次体检失败。** 只有它自己那行退化成 `unknown`,
|
|
129
|
+
`detail` 写成 `检查异常: <message>` 并带 hint,其余五项判决保持不变,合计仍然是六项。
|
|
130
|
+
|
|
131
|
+
## 命令
|
|
132
|
+
|
|
133
|
+
| 输入 | 回答 |
|
|
134
|
+
| --- | --- |
|
|
135
|
+
| `/showcase` | v1 那份巡检报告文本 |
|
|
136
|
+
| `/showcase on` / `off` | `showcase 拦截门: 已开启` / `已关闭` |
|
|
137
|
+
| `/showcase doctor` | 体检报告文本(与工具同一份渲染) |
|
|
138
|
+
| `/showcase about` | 一行:版本、两个工具、命令分支、拦截门状态、DSH 版本 |
|
|
139
|
+
| 其它 | `/showcase [on|off|doctor|about]` |
|
|
140
|
+
|
|
141
|
+
输入先 trim 再转小写,所以 ` ON ` 有效,`Dr. Who` 得到用法那一行。
|
|
142
|
+
|
|
143
|
+
## 拦截门
|
|
144
|
+
|
|
145
|
+
默认开启。当一次工具调用的 `command`、`cmd`、`script` 或 `code` 参数(不区分大小写)
|
|
146
|
+
命中下列任一模式时拒绝执行:
|
|
84
147
|
|
|
85
148
|
- `rm -rf /`、`rm -rf ~`
|
|
86
149
|
- fork 炸弹:`:(){:|:&;}`、`:(){ :|:& };:`、`.(){ :|:& };:`、`bomb(){ bomb|bomb& };bomb`
|
|
@@ -88,66 +151,91 @@ DSH 的 HMR 监视 profile 的 `package.json`(只看 `bundles` 数组)与 pr
|
|
|
88
151
|
- 处在命令位置上的 `shutdown` / `shutdown.exe` 词(前面可以带 `sudo`、`doas` 或
|
|
89
152
|
`pkexec`),例如 `shutdown /s /t 0`、`sudo shutdown -h now`
|
|
90
153
|
|
|
91
|
-
|
|
92
|
-
`showcase: 拒绝执行破坏性命令`;其余一律调用 `next()`
|
|
93
|
-
|
|
154
|
+
把空格抹掉的写法(例如 `rm -rf /tmp`),或把空格换成制表符,同样拦得住。拒绝理由固定为
|
|
155
|
+
`showcase: 拒绝执行破坏性命令`;其余一律调用 `next()` 放行。这四个参数键之外的文本不
|
|
156
|
+
参与匹配;钩子内部出故障也照样 `next()` —— 插件 bug 绝不能阻塞工具调用。
|
|
94
157
|
|
|
95
|
-
|
|
96
|
-
`/showcase off` 切换拦截门(`showcase 拦截门: 已开启` / `已关闭`);其它输入回
|
|
97
|
-
`/showcase [on|off]`。状态属于插件实例,重新 apply 会回到开启。
|
|
158
|
+
## 设置卡与面板
|
|
98
159
|
|
|
99
|
-
|
|
100
|
-
|
|
160
|
+
**设置卡片** —— 设置里的导航行 **功能展示 / Showcase**(id `showcase`,order 90):
|
|
161
|
+
标题与说明、体检提示、一行可复制的 `/showcase doctor`、刷新与"打开巡检面板"按钮、带
|
|
162
|
+
`v0.2.0` 与拦截门状态的页脚、三条能力行,最后是快照或降级文案。
|
|
101
163
|
|
|
102
|
-
|
|
164
|
+
**右侧栏面板** —— tab 类型 id `showcase-panel`、kind `showcase`、标题
|
|
103
165
|
**巡检面板 / Showcase panel**,面板体挂在同一个 key 上。打开它有两个入口:左侧栏底部
|
|
104
|
-
Settings 旁边的 ◎
|
|
105
|
-
`sidebarRight.openTab('showcase')`。这个 tab 类型没有声明 `guide`
|
|
106
|
-
|
|
166
|
+
Settings 旁边的 ◎ 按钮,以及设置卡上的按钮,两者最终都走
|
|
167
|
+
`sidebarRight.openTab('showcase')`。这个 tab 类型没有声明 `guide` 条目,所以它不会出现
|
|
168
|
+
在右侧栏的引导页里。
|
|
169
|
+
|
|
170
|
+
面板一打开就是三步引导:1)跑一次体检 —— 把 `/showcase doctor` 作为可复制文本交给你;
|
|
171
|
+
2)打开设置卡;3)了解拦截门 —— 给出 `/showcase on|off` 的可复制文本。每一步都有自己
|
|
172
|
+
的复制按钮,按下后标签变成 **已复制 / Copied**,约 1.6 秒后回退。页脚显示 `v0.2.0`,
|
|
173
|
+
取不到快照时再加上降级那一行。
|
|
174
|
+
|
|
175
|
+
## 国际化
|
|
176
|
+
|
|
177
|
+
19 个运行期键,`en` 与 `zh` 各一份,都是真翻译而不是照抄:
|
|
178
|
+
|
|
179
|
+
v1 的八个 `title` `subtitle` `panelTitle` `panelEmpty` `gateOn` `gateOff`
|
|
180
|
+
`openPanel` `refresh`,加 v2 的 `welcome` `stepDoctorTitle` `stepDoctorBody`
|
|
181
|
+
`stepSettingsTitle` `stepSettingsBody` `stepGateTitle` `stepGateBody` `copyHint`
|
|
182
|
+
`copied` `doctorHint` `aboutBody`。
|
|
183
|
+
|
|
184
|
+
语言解析顺序是 `ctx.locale` → `navigator.language` → `en`;没有 locale 服务的宿主照样
|
|
185
|
+
渲染真实文案。
|
|
186
|
+
|
|
187
|
+
## 市场索引(随包自托管)
|
|
188
|
+
|
|
189
|
+
v0.2.0 起索引跟包一起走:`market/index.json`(format 1,收录本插件),并在
|
|
190
|
+
`package.json` 的 `files` 白名单里,所以它在发布出去的 tarball 里。对外地址:
|
|
191
|
+
|
|
192
|
+
```
|
|
193
|
+
https://cdn.jsdelivr.net/npm/dsh-plugin-showcase@latest/market/index.json
|
|
194
|
+
```
|
|
107
195
|
|
|
108
|
-
|
|
109
|
-
`gateOn`、`gateOff`、`openPanel`、`refresh`——`en` 与 `zh` 各一份。语言解析顺序是
|
|
110
|
-
`ctx.locale` → `navigator.language` → `en`;没有 locale 服务的宿主照样渲染真实文案。
|
|
111
|
-
市场元数据来自 `locale/en.json`(锚点)与 `locale/zh.json`。
|
|
196
|
+
在发现页把它添加为索引源,就不用任何本地服务器也能装。
|
|
112
197
|
|
|
113
|
-
|
|
114
|
-
|
|
198
|
+
开发期本机用过的那套临时服务仍在 `http://127.0.0.1:8791` 上监听(它的索引在
|
|
199
|
+
`/index.json` 回答 200)。**它已经不再需要**:把发现页的索引源换成上面那条 CDN 地址
|
|
200
|
+
即可,之后那套本地服务可以停掉。
|
|
115
201
|
|
|
116
|
-
|
|
202
|
+
市场元数据仍然来自 `locale/en.json`(锚点)与 `locale/zh.json`,所以插件页会显示本地化
|
|
203
|
+
标题与描述,配上 `icon.svg`。
|
|
117
204
|
|
|
118
205
|
## 诚实的限制清单
|
|
119
206
|
|
|
120
|
-
1. **client
|
|
207
|
+
1. **client 侧仍然拿不到宿主实时数据,零构建约束下也拿不到。** 官方 remote API 路线需要
|
|
121
208
|
typert 装饰器、代码生成步骤和第三方依赖——这三条与"原生 ESM、不构建、不加依赖"逐条
|
|
122
|
-
冲突。`lib/client.js`
|
|
123
|
-
|
|
124
|
-
|
|
209
|
+
冲突。`lib/client.js` 会去探测几种可能的形状(`remote.showcase`、`ctx.showcase`),
|
|
210
|
+
失败即降级为 `null`。所以设置卡与面板显示的是静态能力行加降级文案,不是实时快照;
|
|
211
|
+
也正因如此,首启引导只能把 `/showcase doctor` 文本交给你,而不是替你去调用宿主。
|
|
125
212
|
2. **`sidebar.footer.action` 座位不投影 `label`。** 侧栏外壳只以 `{ wide }` 渲染这个
|
|
126
213
|
座位,可见文本由组件自己画(`◎`,标签通过 `aria-label` 承载)。那个 `label` thunk
|
|
127
214
|
是合法的 `SlotLabel` 也没写错,只是这个座位没有壳去读它。
|
|
128
|
-
3.
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
色值;截图与脚本在 `_visual/`,没有做逐像素基线比对。
|
|
215
|
+
3. **390px 左右的表现由宿主决定,不由插件决定。** 实测容器宽度低于 320px 时座位才改为
|
|
216
|
+
堆叠,且每个盒子都是 `min-width: 0` 加 `overflow-x: hidden`,被压窄时只会让行变短、
|
|
217
|
+
不会撑出横向滚动条。但右列宽度是 DSH 自己钳制的:插件既不能把面板做得比宿主允许的
|
|
218
|
+
更窄,也不能更宽,而 390px 以下的情况只是通过容器实测走到的,没有在真实窄视口里验证。
|
|
219
|
+
4. **没有真实浏览器的视觉回归 —— 测试覆盖事实,不覆盖像素。** client 侧证据来自 Node 桩
|
|
220
|
+
测试:`react` 被换成最小的 `createElement`/`useState`/`useEffect`/`useRef` 替身,
|
|
221
|
+
所以断言的是元素树与文本(19 键双语、三条引导标题、点击后的"已复制"、降级文案)。
|
|
222
|
+
既没有截图基线,也没有像素比对。
|
|
137
223
|
|
|
138
224
|
## 二次开发指引
|
|
139
225
|
|
|
140
|
-
- **加一个工具。** 照抄 `inspectTool`(`lib/index.js:
|
|
141
|
-
`ToolDefinition` 形状,用
|
|
142
|
-
`ctx.effect(() => ctx.tools.register(<tool>), 'showcase: <name>')`
|
|
143
|
-
`output` 必须带 `{ schema, render }
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
`
|
|
149
|
-
|
|
150
|
-
|
|
226
|
+
- **加一个工具。** 照抄 `inspectTool`(`lib/index.js:600`)或 `doctorTool`(`:619`)
|
|
227
|
+
那种原始 JSON-Schema `ToolDefinition` 形状,用
|
|
228
|
+
`ctx.effect(() => ctx.tools.register(<tool>), 'showcase: <name>')` 注册
|
|
229
|
+
(`:638` / `:639`)。`output` 必须带 `{ schema, render }`。
|
|
230
|
+
- **加一项 check。** 在 `buildHealthReport`(`lib/index.js:511`)的数组里加一行
|
|
231
|
+
`runCheck('<id>', '<标题>', () => …)`,保持这层包裹(抛错才会退化成 `unknown`);
|
|
232
|
+
只有形状真的变了才动 `buildHealthSchema`。
|
|
233
|
+
- **加一个新 slot。** 在 `apply()`(`lib/client.js:525`)里照抄
|
|
234
|
+
`slots.inject(<slot>, () => slots.register({ name, … }, 组件))` 这个形状:
|
|
235
|
+
`settings.section` 在 `:531`、`sidebar.right.pane.tab` 在 `:551`、
|
|
236
|
+
`sidebar.footer.action` 在 `:559`。右侧栏 tab 必须两半都注册——面板体的 key 要等于
|
|
237
|
+
通过 `sidebarRightTabs` 注册的类型 id。
|
|
238
|
+
- **加一条运行期文案。** 同时加进 `dict.en` 与 `dict.zh`(`lib/client.js:13`),并把
|
|
151
239
|
`tests/helpers/client-harness.mjs` 里的 `DICT_KEYS` 一起扩展,双语用例才会继续守住它。
|
|
152
240
|
|
|
153
241
|
## 测试
|
|
@@ -157,18 +245,18 @@ npm install # 只做一次,需要访问 registry(devDependency: vitest)
|
|
|
157
245
|
npm test # 之后完全离线,一条命令跑完整个套件
|
|
158
246
|
```
|
|
159
247
|
|
|
160
|
-
两个文件共
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
- `tests/host.test.mjs`(
|
|
164
|
-
`output`
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
248
|
+
两个文件共 98 个用例,不写死任何机器路径——所有路径都由 `import.meta.url` 推导,夹具
|
|
249
|
+
(一个工作区、一个双版本 DSH profile)是每次运行现建的临时目录。
|
|
250
|
+
|
|
251
|
+
- `tests/host.test.mjs`(66 个):模块形状、四处注册的 `ctx.effect` 生命周期、两个工具
|
|
252
|
+
的参数与 `output` 契约(返回值用各自声明的 schema 反向校验)、快照形状与 `""`/`null`
|
|
253
|
+
降级、git 分支发现、八条破坏性模式外加抹空格写法与参数键范围、关机类命令的词边界、
|
|
254
|
+
钩子内部抛错仍放行、拦截门开关、HealthReport 形状与"不出现 `undefined`"、summary 与
|
|
255
|
+
checks 恒等、六项 check 各自的 ok/warn/unknown/fail 分支、单条 check 抛错只降级自己、
|
|
256
|
+
报告渲染版式,以及命令的五种输入。
|
|
257
|
+
- `tests/client.test.mjs`(32 个):lazy-CJS 登记、factory 导出(含 `VERSION`)、恰好三个
|
|
258
|
+
座位、tab 类型与面板体 key 一致且服务晚到也能补注册、侧栏按钮的打开路径、19 个双语键、
|
|
259
|
+
三条引导标题、语言解析(含没有 locale 服务的宿主)、`fetchSnapshot` 的各级降级、
|
|
260
|
+
有数据与无数据两种渲染、首启引导、点击复制后变"已复制"、刷新点击。
|
|
261
|
+
|
|
262
|
+
运行器:**vitest 3**(已声明的 devDependency)。
|
package/lib/client.js
CHANGED
|
@@ -6,6 +6,7 @@ window.__ModuleLoader__.load({
|
|
|
6
6
|
const React = require('react')
|
|
7
7
|
const h = React.createElement
|
|
8
8
|
|
|
9
|
+
const VERSION = '0.2.0'
|
|
9
10
|
const TAB_ID = 'showcase-panel'
|
|
10
11
|
const TAB_KIND = 'showcase'
|
|
11
12
|
|
|
@@ -19,6 +20,17 @@ window.__ModuleLoader__.load({
|
|
|
19
20
|
gateOff: 'Guard gate: off',
|
|
20
21
|
openPanel: 'Open showcase panel',
|
|
21
22
|
refresh: 'Refresh',
|
|
23
|
+
welcome: 'Welcome to Showcase',
|
|
24
|
+
stepDoctorTitle: '1 · Run a health check',
|
|
25
|
+
stepDoctorBody: 'Send this command in the conversation box; the host answers with a full DSH health report.',
|
|
26
|
+
stepSettingsTitle: '2 · Open the settings card',
|
|
27
|
+
stepSettingsBody: 'Settings → Showcase shows the same snapshot, the guard-gate state and this plugin version.',
|
|
28
|
+
stepGateTitle: '3 · Understand the guard gate',
|
|
29
|
+
stepGateBody: 'The gate refuses destructive shell commands before they run. This command turns it on or off.',
|
|
30
|
+
copyHint: 'Copy',
|
|
31
|
+
copied: 'Copied',
|
|
32
|
+
doctorHint: 'The client half cannot call the host directly, so the command is handed to you as selectable text.',
|
|
33
|
+
aboutBody: 'Tools, hooks, commands, settings and a sidebar panel in one small package — a reference implementation you can copy.',
|
|
22
34
|
},
|
|
23
35
|
zh: {
|
|
24
36
|
title: '功能展示',
|
|
@@ -29,6 +41,17 @@ window.__ModuleLoader__.load({
|
|
|
29
41
|
gateOff: '拦截门:已关闭',
|
|
30
42
|
openPanel: '打开巡检面板',
|
|
31
43
|
refresh: '刷新',
|
|
44
|
+
welcome: '欢迎使用功能展示',
|
|
45
|
+
stepDoctorTitle: '1 · 跑一次体检',
|
|
46
|
+
stepDoctorBody: '把这条命令发到对话输入框,宿主会回一份完整的 DSH 体检报告。',
|
|
47
|
+
stepSettingsTitle: '2 · 打开设置卡',
|
|
48
|
+
stepSettingsBody: '在「设置 → 功能展示」里能看到同一份巡检快照、拦截门状态与本插件版本。',
|
|
49
|
+
stepGateTitle: '3 · 了解拦截门',
|
|
50
|
+
stepGateBody: '拦截门会在破坏性 shell 命令执行前拦下它,用这条命令开启或关闭。',
|
|
51
|
+
copyHint: '复制',
|
|
52
|
+
copied: '已复制',
|
|
53
|
+
doctorHint: '客户端无法直接调用宿主,所以这里把命令作为可选中文本交给你。',
|
|
54
|
+
aboutBody: '工具、钩子、命令、设置卡与侧栏面板都装在这一个小包里——可直接抄走的参考实现。',
|
|
32
55
|
},
|
|
33
56
|
}
|
|
34
57
|
|
|
@@ -131,10 +154,20 @@ window.__ModuleLoader__.load({
|
|
|
131
154
|
head: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 8 },
|
|
132
155
|
title: { margin: 0, fontSize: 14, fontWeight: 600 },
|
|
133
156
|
subtitle: { margin: 0, fontSize: 12, lineHeight: 1.55, opacity: 0.72 },
|
|
157
|
+
welcome: { margin: 0, fontSize: 13, fontWeight: 600 },
|
|
158
|
+
about: { margin: 0, fontSize: 12, lineHeight: 1.55, opacity: 0.72 },
|
|
134
159
|
toolbar: { display: 'flex', flexWrap: 'wrap', gap: 8 },
|
|
135
160
|
button: { font: 'inherit', fontSize: 12, padding: '3px 10px', borderRadius: 6, border: '1px solid rgba(128,128,128,.45)', background: 'transparent', color: 'inherit', cursor: 'pointer' },
|
|
136
161
|
footerAction: { display: 'inline-flex', alignItems: 'center', justifyContent: 'center', width: 26, height: 26, borderRadius: 6, border: 0, background: 'transparent', color: 'inherit', cursor: 'pointer', fontSize: 14 },
|
|
137
162
|
note: { margin: 0, fontSize: 12, lineHeight: 1.55, opacity: 0.7 },
|
|
163
|
+
steps: { display: 'flex', flexDirection: 'column', gap: 8, minWidth: 0 },
|
|
164
|
+
step: { display: 'flex', flexDirection: 'column', gap: 4, padding: '8px 10px', borderRadius: 8, border: '1px solid rgba(128,128,128,.25)', minWidth: 0 },
|
|
165
|
+
stepTitle: { margin: 0, fontSize: 13, fontWeight: 600 },
|
|
166
|
+
stepBody: { margin: 0, fontSize: 12, lineHeight: 1.5, opacity: 0.72, overflowWrap: 'anywhere' },
|
|
167
|
+
copyRow: { display: 'flex', gap: 6, alignItems: 'center', minWidth: 0 },
|
|
168
|
+
copyRowNarrow: { display: 'flex', flexDirection: 'column', gap: 4, alignItems: 'stretch', minWidth: 0 },
|
|
169
|
+
code: { flex: '1 1 auto', minWidth: 0, padding: '3px 8px', borderRadius: 6, background: 'rgba(128,128,128,.14)', fontFamily: MONO, fontSize: 12, whiteSpace: 'pre-wrap', overflowWrap: 'anywhere', wordBreak: 'break-word' },
|
|
170
|
+
foot: { display: 'flex', flexWrap: 'wrap', gap: 8, alignItems: 'baseline', fontSize: 11, opacity: 0.62, minWidth: 0 },
|
|
138
171
|
group: { display: 'flex', flexDirection: 'column', gap: 3 },
|
|
139
172
|
groupTitle: { margin: '4px 0 0', fontSize: 12, fontWeight: 600, opacity: 0.85 },
|
|
140
173
|
row: { display: 'flex', gap: 8, alignItems: 'baseline', minWidth: 0 },
|
|
@@ -148,6 +181,7 @@ window.__ModuleLoader__.load({
|
|
|
148
181
|
// Below this the label column alone eats the line, so pairs stack instead of
|
|
149
182
|
// squeezing one character per line.
|
|
150
183
|
const NARROW_MAX = 320
|
|
184
|
+
const COPIED_MS = 1600
|
|
151
185
|
|
|
152
186
|
function row(key, label, value, narrow) {
|
|
153
187
|
const shown = value === null || value === undefined || value === '' ? '—' : String(value)
|
|
@@ -182,20 +216,66 @@ window.__ModuleLoader__.load({
|
|
|
182
216
|
row('item-' + index + '-' + itemIndex, String((item && item.label) || ''), item && item.value, narrow)))))
|
|
183
217
|
}
|
|
184
218
|
|
|
185
|
-
// Contract §7 fallback:
|
|
186
|
-
//
|
|
219
|
+
// Contract v1 §7 fallback, kept: with no client-reachable remote the seats still
|
|
220
|
+
// say what this plugin offers instead of rendering nothing.
|
|
187
221
|
const CAPABILITIES = [
|
|
188
222
|
['tool', 'showcase_inspect'],
|
|
189
223
|
['command', '/showcase'],
|
|
190
224
|
['plugin', 'dsh-plugin-showcase'],
|
|
191
225
|
]
|
|
192
226
|
|
|
193
|
-
function
|
|
227
|
+
function capabilityBlock(t, narrow) {
|
|
194
228
|
return h('div', { style: S.group },
|
|
195
|
-
withNote ? h('p', { style: S.note }, t.panelEmpty) : null,
|
|
196
229
|
CAPABILITIES.map(([label, value], index) => row('cap-' + index, label, value, narrow)))
|
|
197
230
|
}
|
|
198
231
|
|
|
232
|
+
function copyText(value) {
|
|
233
|
+
try {
|
|
234
|
+
const clipboard = typeof navigator === 'undefined' ? null : navigator.clipboard
|
|
235
|
+
if (clipboard === null || clipboard === undefined || typeof clipboard.writeText !== 'function') return false
|
|
236
|
+
const pending = clipboard.writeText(value)
|
|
237
|
+
if (pending !== null && typeof pending === 'object' && typeof pending.catch === 'function') pending.catch(() => {})
|
|
238
|
+
return true
|
|
239
|
+
} catch (error) {
|
|
240
|
+
return false
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// The command stays on screen as selectable text, so a blocked clipboard still
|
|
245
|
+
// leaves the reader something to copy by hand.
|
|
246
|
+
function copyRow(id, value, t, narrow, copiedId, onCopy) {
|
|
247
|
+
const copied = copiedId === id
|
|
248
|
+
return h('div', { key: 'copy-' + id, style: narrow === true ? S.copyRowNarrow : S.copyRow },
|
|
249
|
+
h('code', { style: S.code }, value),
|
|
250
|
+
h('button', {
|
|
251
|
+
type: 'button',
|
|
252
|
+
style: S.button,
|
|
253
|
+
onClick: () => onCopy(id, value),
|
|
254
|
+
'aria-label': t.copyHint,
|
|
255
|
+
title: t.copyHint,
|
|
256
|
+
}, copied ? t.copied : t.copyHint))
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function guideSteps(t, narrow, copiedId, onCopy) {
|
|
260
|
+
const steps = [
|
|
261
|
+
{ id: 'doctor', title: t.stepDoctorTitle, body: t.stepDoctorBody, value: '/showcase doctor' },
|
|
262
|
+
{ id: 'settings', title: t.stepSettingsTitle, body: t.stepSettingsBody, value: t.title },
|
|
263
|
+
{ id: 'gate', title: t.stepGateTitle, body: t.stepGateBody, value: '/showcase on|off' },
|
|
264
|
+
]
|
|
265
|
+
return steps.map(step => h('div', { key: 'step-' + step.id, style: S.step },
|
|
266
|
+
h('h4', { style: S.stepTitle }, step.title),
|
|
267
|
+
h('p', { style: S.stepBody }, step.body),
|
|
268
|
+
copyRow(step.id, step.value, t, narrow, copiedId, onCopy)))
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function gateLabel(t, snapshot) {
|
|
272
|
+
if (snapshot === null || snapshot === undefined) return '—'
|
|
273
|
+
const plugin = snapshot.plugin || {}
|
|
274
|
+
return plugin.gateEnabled === true ? t.gateOn : t.gateOff
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// ---- hooks ---------------------------------------------------------------
|
|
278
|
+
|
|
199
279
|
// Re-renders on a language switch so the visible copy follows the label thunks.
|
|
200
280
|
function useLangTick(ctx) {
|
|
201
281
|
if (typeof React.useState !== 'function' || typeof React.useEffect !== 'function') return
|
|
@@ -230,6 +310,23 @@ window.__ModuleLoader__.load({
|
|
|
230
310
|
return [state, refresh]
|
|
231
311
|
}
|
|
232
312
|
|
|
313
|
+
function useCopyState() {
|
|
314
|
+
const [copiedId, setCopiedId] = React.useState(null)
|
|
315
|
+
const timer = useRefOf()
|
|
316
|
+
const copy = (id, value) => {
|
|
317
|
+
copyText(value)
|
|
318
|
+
setCopiedId(id)
|
|
319
|
+
try {
|
|
320
|
+
if (typeof setTimeout !== 'function') return
|
|
321
|
+
if (timer.current !== null && timer.current !== undefined) clearTimeout(timer.current)
|
|
322
|
+
timer.current = setTimeout(() => setCopiedId(null), COPIED_MS)
|
|
323
|
+
} catch (error) {
|
|
324
|
+
// the badge stays until the next render
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
return [copiedId, copy]
|
|
328
|
+
}
|
|
329
|
+
|
|
233
330
|
// The host forces a very narrow content column on small screens; stacking is
|
|
234
331
|
// driven by the measured box, not the viewport, because only the box knows.
|
|
235
332
|
function useNarrow(ref) {
|
|
@@ -306,15 +403,23 @@ window.__ModuleLoader__.load({
|
|
|
306
403
|
const t = text(ctx)
|
|
307
404
|
useLangTick(ctx)
|
|
308
405
|
const [state, refresh] = useSnapshot(ctx)
|
|
406
|
+
const [copiedId, copy] = useCopyState()
|
|
309
407
|
const ref = useRefOf()
|
|
310
408
|
const narrow = useNarrow(ref)
|
|
409
|
+
const degraded = state.data === null
|
|
311
410
|
return h('section', { ref, style: narrow ? { ...S.card, ...S.cardNarrow } : S.card },
|
|
312
411
|
h('h3', { style: S.title }, t.title),
|
|
313
412
|
h('p', { style: S.subtitle }, t.subtitle),
|
|
413
|
+
h('p', { style: S.note }, t.doctorHint),
|
|
414
|
+
copyRow('card-doctor', '/showcase doctor', t, narrow, copiedId, copy),
|
|
314
415
|
h('div', { style: S.toolbar },
|
|
315
416
|
h('button', { type: 'button', style: S.button, onClick: refresh }, t.refresh),
|
|
316
417
|
h('button', { type: 'button', style: S.button, onClick: () => openPanel(ctx) }, t.openPanel)),
|
|
317
|
-
|
|
418
|
+
h('div', { style: S.foot },
|
|
419
|
+
h('span', null, 'v' + VERSION),
|
|
420
|
+
h('span', null, gateLabel(t, state.data))),
|
|
421
|
+
capabilityBlock(t, narrow),
|
|
422
|
+
degraded ? h('p', { style: S.note }, t.panelEmpty) : snapshotBody(state.data, t, narrow))
|
|
318
423
|
}
|
|
319
424
|
|
|
320
425
|
function ShowcasePanel() {
|
|
@@ -322,13 +427,22 @@ window.__ModuleLoader__.load({
|
|
|
322
427
|
const t = text(ctx)
|
|
323
428
|
useLangTick(ctx)
|
|
324
429
|
const [state, refresh] = useSnapshot(ctx)
|
|
430
|
+
const [copiedId, copy] = useCopyState()
|
|
325
431
|
const ref = useRefOf()
|
|
326
432
|
const narrow = useNarrow(ref)
|
|
433
|
+
const degraded = state.data === null
|
|
327
434
|
return h('div', { ref, style: narrow ? { ...S.pane, ...S.paneNarrow } : S.pane },
|
|
328
435
|
h('div', { style: S.head },
|
|
329
436
|
h('h3', { style: S.title }, t.panelTitle),
|
|
330
437
|
h('button', { type: 'button', style: S.button, onClick: refresh }, t.refresh)),
|
|
331
|
-
|
|
438
|
+
h('h4', { style: S.welcome }, t.welcome),
|
|
439
|
+
h('p', { style: S.about }, t.aboutBody),
|
|
440
|
+
h('div', { style: S.steps }, guideSteps(t, narrow, copiedId, copy)),
|
|
441
|
+
h('p', { style: S.note }, t.doctorHint),
|
|
442
|
+
degraded ? capabilityBlock(t, narrow) : snapshotBody(state.data, t, narrow),
|
|
443
|
+
h('div', { style: S.foot },
|
|
444
|
+
h('span', null, 'v' + VERSION),
|
|
445
|
+
degraded ? h('span', null, t.panelEmpty) : null))
|
|
332
446
|
}
|
|
333
447
|
|
|
334
448
|
function FooterAction(props) {
|
|
@@ -451,6 +565,6 @@ window.__ModuleLoader__.load({
|
|
|
451
565
|
}, FooterAction)), 'showcase: sidebar footer action')
|
|
452
566
|
}
|
|
453
567
|
|
|
454
|
-
return { apply, inject: ['slots'], fetchSnapshot, lang, dict, TAB_ID, TAB_KIND }
|
|
568
|
+
return { apply, inject: ['slots'], fetchSnapshot, lang, dict, VERSION, TAB_ID, TAB_KIND }
|
|
455
569
|
},
|
|
456
570
|
})
|