dsh-mcp-manager-plus 0.4.3 → 0.4.5
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 +54 -0
- package/README.en.md +7 -3
- package/README.md +6 -3
- package/lib/client.js +121 -20
- package/lib/index.js +22 -42
- package/lib/yaml.js +503 -0
- package/package.json +4 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,59 @@
|
|
|
5
5
|
|
|
6
6
|
0.3.1 之前的开发发生在公开仓库建立之前,历史没有保留。
|
|
7
7
|
|
|
8
|
+
## [0.4.5] - 2026-11-08
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- **DSH 0.2.2-rc.1 的设置侧边栏里,本行并排出现两个图标(左边链条例、右边齿轮)**:
|
|
13
|
+
新版 shell 把导航行图标改成了 `settings.section.icon` 槽位,并把自己画的默认
|
|
14
|
+
齿轮包进 `<span class="navIcon">`。于是旧的样式兜底
|
|
15
|
+
(`button[data-mcpmp-nav]>svg:first-child` 隐藏 + `::before` 遮罩)既隐藏不掉
|
|
16
|
+
齿轮,又照常画出自己的链条,两枚图标并排 —— 用户截图里的正是这一现象。
|
|
17
|
+
现在**优先把图标注册进这个槽位**(注册 id 必须等于 section 的 id `mcp`,shell
|
|
18
|
+
按行的 id 取用,取不到才回落到默认齿轮);槽位存在时旧的「标记行 + 遮罩」整条
|
|
19
|
+
链路直接关掉,行里只剩插件自己的链条图标。
|
|
20
|
+
- 没有该槽位的老版本(0.1.6-alpha.1 … 0.2.1)行为不变:页面照常注册,
|
|
21
|
+
旧兜底仍接管这一行。
|
|
22
|
+
|
|
23
|
+
### Added
|
|
24
|
+
|
|
25
|
+
- 回归用例:槽位可用时图标注册进去(id 与 section 一致、尺寸跟随槽位、颜色走
|
|
26
|
+
`currentColor`);槽位可用时不再启动行标记(否则就是这次的双图标);
|
|
27
|
+
槽位缺失时页面仍注册、兜底仍在观察(测试总数 127 → 131)。
|
|
28
|
+
|
|
29
|
+
## [0.4.4] - 2026-10-15
|
|
30
|
+
|
|
31
|
+
### Fixed
|
|
32
|
+
|
|
33
|
+
- **profile 顶层被提升到 `js-yaml` v5 时整页「加载失败:yaml.Type is not a constructor」**:
|
|
34
|
+
`loadYaml()` 用 v3/v4 的自定义类型 API(`new yaml.Type(...)` + `schema.extend(...)`)
|
|
35
|
+
承载 `!!js` 标签,而 `js-yaml` 一直是按 profile 锚点解析的——任何别的插件
|
|
36
|
+
(如声明 `js-yaml@^5` 的插件)把 v5 提升到 profile 顶层后,`new yaml.Type(...)`
|
|
37
|
+
就抛错,所有路由 500、面板完全不可用(感谢 @asfre 的报告与定位)。
|
|
38
|
+
现在不再「谁先解析到就用谁」,而是在新增的 `lib/yaml.js` 里**探测能力**:
|
|
39
|
+
一个副本构造不出 `!!js` 类型就跳过、继续沿锚点往下找,于是插件在
|
|
40
|
+
`dependencies` 中钉住的 `js-yaml@^4.1.0` 会接管,而不是被顶层提升的 v5 拖垮
|
|
41
|
+
- **所有副本都不兼容时仍有兜底**:若插件目录与 profile 里没有任何能构造自定义类型的
|
|
42
|
+
副本,也不再抛错,而是改用兼容解析——解析前把 `!!js` 标签替换成占位符、解析后再
|
|
43
|
+
还原为表达式节点(扫描会跳过引号与注释内的文本,`args: ["echo !!js x"]`、
|
|
44
|
+
`PLAIN: "!!js not a tag"` 这类值不会被误判成表达式)。面板因此照常加载与管理,
|
|
45
|
+
且 `!!js` 语义不被改写:降级解析与快路径读出的值完全相同,回写的字节也完全一致
|
|
46
|
+
- 降级时在页面「配置提示」里写明实际解析到的 `js-yaml` 与降级状态,不再静默降级
|
|
47
|
+
|
|
48
|
+
### Added
|
|
49
|
+
|
|
50
|
+
- `dependencies` 新增 `js-yaml: ^4.1.0`:插件自带确定的副本,不再依赖 profile 顶层
|
|
51
|
+
提升结果;解析顺序仍是 profile 锚点优先(与载入器 include 插件一致),只是不再
|
|
52
|
+
接受一个无法承载 `!!js` 的副本
|
|
53
|
+
- 回归用例 `test/yaml.test.mjs`(11 项):能力探测(`Type` 抛错、缺 `extend`、
|
|
54
|
+
非对象等形态)、注入加载器验证「profile 锚点的不兼容副本让位于插件的可用副本」、
|
|
55
|
+
完全没有可解析副本时报出明确错误,以及降级解析下 `!!js` 的行内 / 块 / 流式三种
|
|
56
|
+
写法、「与快路径逐字节一致」、「回写后仍能通过校验并往返」
|
|
57
|
+
- 回归用例 `test/host.test.mjs`:在临时 profile 里放一个「v5 形状」(可解析、无自定义
|
|
58
|
+
类型)的 `js-yaml`,`GET /servers` 必须仍返回 200 并列出种子行,而不是整页不可用
|
|
59
|
+
(测试总数 115 → 127)
|
|
60
|
+
|
|
8
61
|
## [0.4.3] - 2026-10-09
|
|
9
62
|
|
|
10
63
|
### Fixed
|
|
@@ -121,6 +174,7 @@
|
|
|
121
174
|
JSON 编辑、宿主路由、bundle 加载、profile 组合与真实 profile 只读验证;
|
|
122
175
|
另附 e2e 导入、往返校验、图标预览等辅助脚本
|
|
123
176
|
|
|
177
|
+
[0.4.4]: https://github.com/appthin/dsh-mcp-manager-plus/compare/v0.4.3...v0.4.4
|
|
124
178
|
[0.4.3]: https://github.com/appthin/dsh-mcp-manager-plus/compare/v0.4.2...v0.4.3
|
|
125
179
|
[0.4.2]: https://github.com/appthin/dsh-mcp-manager-plus/compare/v0.4.1...v0.4.2
|
|
126
180
|
[0.4.1]: https://github.com/appthin/dsh-mcp-manager-plus/compare/v0.4.0...v0.4.1
|
package/README.en.md
CHANGED
|
@@ -42,7 +42,7 @@ paste a whole replacement block, and renaming is just changing the name.
|
|
|
42
42
|
|
|
43
43
|
## Installation
|
|
44
44
|
|
|
45
|
-
**Requirements:** DSH >= 0.1.6-alpha.1 and < 0.3.0 (tested on 0.1.6-alpha.1 and 0.2.
|
|
45
|
+
**Requirements:** DSH >= 0.1.6-alpha.1 and < 0.3.0 (tested on 0.1.6-alpha.1, 0.2.0-rc.2 and 0.2.2-rc.1).
|
|
46
46
|
DSH itself needs Node.js >= 24.2.0 and Git >= 2.31.0.
|
|
47
47
|
|
|
48
48
|
### Option 1: one-click install from the plugin market
|
|
@@ -227,12 +227,13 @@ converged state.
|
|
|
227
227
|
## Development
|
|
228
228
|
|
|
229
229
|
```sh
|
|
230
|
-
node test/run.mjs # all
|
|
230
|
+
node test/run.mjs # all eight suites (127 assertions)
|
|
231
231
|
```
|
|
232
232
|
|
|
233
233
|
| Suite | Coverage |
|
|
234
234
|
| --- | --- |
|
|
235
235
|
| `test/patch.test.mjs` | patch-layer segmentation, parsing, validation, generation and byte-exact round-trips |
|
|
236
|
+
| `test/yaml.test.mjs` | the `js-yaml` compatibility layer: capability probing, skipping an incompatible copy, and `!!js` fidelity under the degraded parser |
|
|
236
237
|
| `test/import.test.mjs` | config formats of 14 tools, the TOML subset, JSON comments and trailing commas |
|
|
237
238
|
| `test/editjson.test.mjs` | JSON-mode editing: in-place updates, renames keeping id and overrides, multi-server rejection |
|
|
238
239
|
| `test/host.test.mjs` | every host-side HTTP route, driving the real `apply()` through a fake Cordis context |
|
|
@@ -241,7 +242,8 @@ node test/run.mjs # all seven suites (106 assertions)
|
|
|
241
242
|
| `test/live.test.mjs` | read-only run against the real profile, confirming live configs read correctly with secrets masked |
|
|
242
243
|
|
|
243
244
|
The tests use no test framework — just Node's built-in `node:test` — and reuse
|
|
244
|
-
the `js-yaml` from the profile (the same parse path as the runtime
|
|
245
|
+
the `js-yaml` from the profile (the same parse path as the runtime, compatibility
|
|
246
|
+
layer in `lib/yaml.js` included).
|
|
245
247
|
|
|
246
248
|
### Layout
|
|
247
249
|
|
|
@@ -250,6 +252,7 @@ the `js-yaml` from the profile (the same parse path as the runtime).
|
|
|
250
252
|
| `lib/index.js` | host side: HTTP API, inventory projection, write operations |
|
|
251
253
|
| `lib/import.js` | import parsing: each tool's config format → this plugin's server shape |
|
|
252
254
|
| `lib/patch.js` | patch-layer read/write: segmentation, parsing, validation, generation |
|
|
255
|
+
| `lib/yaml.js` | `js-yaml` compatibility: capability probing, skipping an incompatible copy, and a degraded parser when no copy can carry the custom type |
|
|
253
256
|
| `lib/client.js` | browser side: the settings page UI (hand-written lazy-CJS bundle, no build step) |
|
|
254
257
|
| `cordis.patch.yml` | the bundle patch inserting this plugin into the profile's layer stack |
|
|
255
258
|
|
|
@@ -265,6 +268,7 @@ the `js-yaml` from the profile (the same parse path as the runtime).
|
|
|
265
268
|
| `node tools/check-nav-icon.mjs` | checks that the nav icon's mask payload is a drawable 16×16 template |
|
|
266
269
|
| `node tools/gen-icon-preview.cjs` | extracts icons from the dsh web bundle into the `icon-options.html` comparison page |
|
|
267
270
|
| `node tools/dump-icon.cjs <IconName>` | prints an icon's SVG path for hand-written overrides |
|
|
271
|
+
| `node tools/verify-release.mjs [version]` | post-publish verification: the registry serves the version, a fresh install pulled its own `js-yaml`, and both halves of the "profile hoists a v5" scenario; `--sync-mirror` also waits for the npmmirror mirror |
|
|
268
272
|
|
|
269
273
|
## License
|
|
270
274
|
|
package/README.md
CHANGED
|
@@ -35,7 +35,7 @@ MCP 服务器管理插件:在 DeepSeek Harness 设置界面的左侧边栏新
|
|
|
35
35
|
|
|
36
36
|
## 安装说明
|
|
37
37
|
|
|
38
|
-
**版本要求:** DSH >= 0.1.6-alpha.1 且 < 0.3.0(已在 0.1.6-alpha.1 与 0.2.
|
|
38
|
+
**版本要求:** DSH >= 0.1.6-alpha.1 且 < 0.3.0(已在 0.1.6-alpha.1、0.2.0-rc.2 与 0.2.2-rc.1 上测试)。DSH 自身依赖 Node.js >= 24.2.0 与 Git >= 2.31.0。
|
|
39
39
|
|
|
40
40
|
### 方式一:插件市场一键安装
|
|
41
41
|
|
|
@@ -191,12 +191,13 @@ $DSH_HOME/profiles/<profile>/cordis.patch.yml
|
|
|
191
191
|
## 开发
|
|
192
192
|
|
|
193
193
|
```sh
|
|
194
|
-
node test/run.mjs #
|
|
194
|
+
node test/run.mjs # 全部八个测试套件(共 127 项)
|
|
195
195
|
```
|
|
196
196
|
|
|
197
197
|
| 套件 | 覆盖范围 |
|
|
198
198
|
| --- | --- |
|
|
199
199
|
| `test/patch.test.mjs` | 补丁层分段、解析、校验、生成与逐字节往返 |
|
|
200
|
+
| `test/yaml.test.mjs` | `js-yaml` 兼容层:能力探测、跳过硬编码不兼容的副本、降级解析下 `!!js` 的语义保真 |
|
|
200
201
|
| `test/import.test.mjs` | 14 种工具的配置格式、TOML 子集、JSON 注释与尾逗号 |
|
|
201
202
|
| `test/editjson.test.mjs` | JSON 模式编辑:原地更新、重命名保留 id 与覆盖、多条拒绝 |
|
|
202
203
|
| `test/host.test.mjs` | 宿主端全部 HTTP 路由,用假的 Cordis 上下文驱动真实 `apply()` |
|
|
@@ -205,7 +206,7 @@ node test/run.mjs # 全部七个测试套件(共 106 项)
|
|
|
205
206
|
| `test/live.test.mjs` | 只读地跑真实 profile,确认线上配置能被正确读出且凭据已掩码 |
|
|
206
207
|
|
|
207
208
|
测试不依赖任何测试框架,只用 Node 内置的 `node:test`,并复用 profile 中已有的
|
|
208
|
-
`js-yaml
|
|
209
|
+
`js-yaml`(与运行时同一条解析路径,含 `lib/yaml.js` 的兼容层)。
|
|
209
210
|
|
|
210
211
|
### 结构
|
|
211
212
|
|
|
@@ -214,6 +215,7 @@ node test/run.mjs # 全部七个测试套件(共 106 项)
|
|
|
214
215
|
| `lib/index.js` | 宿主端:HTTP API、清单投影、写操作 |
|
|
215
216
|
| `lib/import.js` | 导入解析:各工具配置格式 → 本插件的服务器形状 |
|
|
216
217
|
| `lib/patch.js` | 补丁层读写:分段、解析、校验、生成 |
|
|
218
|
+
| `lib/yaml.js` | `js-yaml` 兼容层:副本能力探测、跳过硬编码不兼容的副本、无自定义类型时的降级解析 |
|
|
217
219
|
| `lib/client.js` | 浏览器端:设置页面 UI(手写 lazy-CJS bundle,无构建步骤) |
|
|
218
220
|
| `cordis.patch.yml` | bundle 补丁,把本插件插入 profile 的层栈 |
|
|
219
221
|
|
|
@@ -229,6 +231,7 @@ node test/run.mjs # 全部七个测试套件(共 106 项)
|
|
|
229
231
|
| `node tools/check-nav-icon.mjs` | 校验导航图标的 mask 载荷是合法可绘制的 16×16 模板 |
|
|
230
232
|
| `node tools/gen-icon-preview.cjs` | 从 dsh 前端 bundle 提取图标,生成 `icon-options.html` 对照页 |
|
|
231
233
|
| `node tools/dump-icon.cjs <IconName>` | 打印某个内置图标的 SVG 路径,便于手写覆盖 |
|
|
234
|
+
| `node tools/verify-release.mjs [版本]` | 发布后验证:registry 是否有该版本、全新安装是否带上了自己的 `js-yaml`、以及「profile 顶层被换成 v5」的两种情形;`--sync-mirror` 顺带等 npmmirror 同步 |
|
|
232
235
|
|
|
233
236
|
## License
|
|
234
237
|
|
package/lib/client.js
CHANGED
|
@@ -33,9 +33,27 @@ window.__ModuleLoader__.load({
|
|
|
33
33
|
|
|
34
34
|
var NS = 'dsh-mcp-manager-plus';
|
|
35
35
|
|
|
36
|
-
/**
|
|
36
|
+
/**
|
|
37
|
+
* Attribute the LEGACY nav-row fallback stamps on this plugin's row.
|
|
38
|
+
*
|
|
39
|
+
* Only shells that predate `settings.section.icon` need it: they draw a
|
|
40
|
+
* generic gear for any section id they do not know, and CSS can hide that
|
|
41
|
+
* gear only if it can find the row, so the row is tagged. On a current
|
|
42
|
+
* shell the icon seat owns the row and no flag is ever written (apply()
|
|
43
|
+
* switches the tagger off as soon as the seat is live).
|
|
44
|
+
*/
|
|
37
45
|
var NAV_ROW_FLAG = 'data-mcpmp-nav';
|
|
38
46
|
|
|
47
|
+
/**
|
|
48
|
+
* Whether the shell declared `settings.section.icon`.
|
|
49
|
+
*
|
|
50
|
+
* When it did, the registration in `apply()` puts our glyph inside the
|
|
51
|
+
* shell's own icon seat: the shell then owns the row and its markup, so
|
|
52
|
+
* the flag-and-mask fallback must keep quiet, or the row would carry two
|
|
53
|
+
* glyphs (the one it paints and the one we painted beside the gear).
|
|
54
|
+
*/
|
|
55
|
+
var iconSlotLive = false;
|
|
56
|
+
|
|
39
57
|
/** The dictionary, keyed for the two locales the harness ships. */
|
|
40
58
|
var DICT = {
|
|
41
59
|
zh: {
|
|
@@ -198,12 +216,14 @@ window.__ModuleLoader__.load({
|
|
|
198
216
|
};
|
|
199
217
|
}
|
|
200
218
|
|
|
201
|
-
// The
|
|
202
|
-
//
|
|
203
|
-
//
|
|
204
|
-
//
|
|
205
|
-
//
|
|
206
|
-
//
|
|
219
|
+
// The chain-link glyph for this plugin's settings nav row.
|
|
220
|
+
//
|
|
221
|
+
// This is the shell's own `IconLinkOutline16` geometry, copied verbatim so
|
|
222
|
+
// the row matches the rest of the sidebar's visual language. The shapes are
|
|
223
|
+
// filled (not stroked) because that is how the shipped icon draws. Two
|
|
224
|
+
// consumers share these paths: `NavIcon` renders them into the shell's
|
|
225
|
+
// `settings.section.icon` seat on a current shell, and the legacy mask in
|
|
226
|
+
// `CSS` paints them on shells that have no such seat.
|
|
207
227
|
var NAV_ICON_PATHS = [
|
|
208
228
|
'M9.94133 6.50173C11.3218 7.99603 11.3218 10.3011 9.94128 11.7954C9.88691 11.8542 9.82125 11.9196 9.72099 12.0198L7.75707 13.9838C7.65709 14.0838 7.592 14.1491 7.53334 14.2034C6.03906 15.5843 3.7327 15.5854 2.23827 14.2048C2.17933 14.1503 2.11374 14.0844 2.01315 13.9838C1.91318 13.8839 1.84922 13.8188 1.79495 13.7601C0.413857 12.2657 0.413909 9.95948 1.795 8.46503C1.84923 8.4064 1.91335 8.34115 2.01321 8.24129L3.79275 6.46313C3.71814 7.08101 3.75236 7.71445 3.90115 8.33518L3.00344 9.23151C2.89398 9.34097 2.8535 9.38307 2.82251 9.41658C1.93771 10.3744 1.93704 11.8514 2.82179 12.8092C2.85279 12.8427 2.89383 12.884 3.0034 12.9936C3.11272 13.1029 3.15429 13.1442 3.18777 13.1752C4.14561 14.0603 5.62381 14.0608 6.58178 13.1758C6.61532 13.1448 6.65722 13.1032 6.76685 12.9935L8.73077 11.0296C8.83999 10.9204 8.88142 10.8787 8.91238 10.8452C9.79744 9.88728 9.7969 8.40911 8.91173 7.45124C8.88074 7.41775 8.83944 7.3762 8.73011 7.26687C8.62082 7.15757 8.58061 7.11623 8.54712 7.08526C8.37347 6.92477 8.18243 6.79361 7.98088 6.69165L9.00289 5.66964C9.17506 5.78373 9.34035 5.91265 9.49663 6.05703C9.55538 6.11135 9.62026 6.17652 9.72036 6.27662C9.82094 6.3772 9.88686 6.4428 9.94133 6.50173Z',
|
|
209
229
|
'M6.06816 9.49196C4.68626 7.99724 4.68667 5.68942 6.06885 4.19487C6.12268 4.13671 6.18789 4.07306 6.28706 3.9739L8.24541 2.01416C8.34478 1.91479 8.41018 1.85055 8.46845 1.79665C9.96301 0.414902 12.2689 0.414922 13.7635 1.79665C13.8217 1.85051 13.8866 1.91559 13.9858 2.01486C14.0849 2.11394 14.1502 2.17769 14.204 2.23583C15.5861 3.7304 15.5866 6.03823 14.2047 7.53291C14.1508 7.59125 14.0854 7.65638 13.9858 7.75595L12.1994 9.54098C12.2614 8.92982 12.2185 8.30587 12.0634 7.69657L12.9956 6.76573C13.1044 6.65692 13.1458 6.61529 13.1765 6.58205C14.0621 5.62404 14.0621 4.1454 13.1765 3.18738C13.1458 3.15419 13.104 3.1135 12.9956 3.00508C12.8877 2.89716 12.8471 2.85551 12.814 2.82485C11.8559 1.9389 10.376 1.93886 9.41794 2.82485C9.38479 2.85554 9.34381 2.89622 9.23564 3.00439L7.27728 4.96413C7.16875 5.07265 7.12708 5.11322 7.09636 5.14643C6.21074 6.10441 6.21153 7.58236 7.09705 8.5404C7.12775 8.57357 7.16826 8.61575 7.27659 8.72408C7.38456 8.83205 7.42647 8.87227 7.45958 8.90293C7.62849 9.0591 7.81309 9.1881 8.00856 9.28894L6.98795 10.3095C6.82111 10.1978 6.66052 10.0715 6.50872 9.93114C6.45057 9.87733 6.38547 9.81341 6.28637 9.71431C6.1871 9.61504 6.12202 9.55018 6.06816 9.49196Z',
|
|
@@ -296,13 +316,15 @@ window.__ModuleLoader__.load({
|
|
|
296
316
|
'.mcpmp-textarea{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;line-height:1.55;resize:vertical}',
|
|
297
317
|
'.mcpmp-input:focus,.mcpmp-select:focus,.mcpmp-textarea:focus{outline:none;border-color:var(--dsw-alias-brand-primary)}',
|
|
298
318
|
'@media (max-width:640px){.mcpmp-tool{grid-template-columns:1fr;gap:2px}}',
|
|
299
|
-
// ── settings nav row icon
|
|
300
|
-
//
|
|
301
|
-
//
|
|
302
|
-
//
|
|
303
|
-
//
|
|
304
|
-
//
|
|
305
|
-
//
|
|
319
|
+
// ── legacy settings nav row icon (shells without the icon seat) ───────
|
|
320
|
+
// Before `settings.section.icon` existed, the shell drew a generic gear
|
|
321
|
+
// for any section id it did not know and offered no way to supply a
|
|
322
|
+
// different one. This is that workaround, kept only for those shells: a
|
|
323
|
+
// row tagged with NAV_ROW_FLAG hides the gear and paints the chain-link
|
|
324
|
+
// glyph in its place. The glyph rides a mask so it inherits
|
|
325
|
+
// `currentColor` exactly like every other nav icon, in both themes.
|
|
326
|
+
// `apply()` stops tagging rows as soon as the icon seat is live, so on a
|
|
327
|
+
// current shell no row ever matches these rules.
|
|
306
328
|
'button[' + NAV_ROW_FLAG + ']>svg:first-child{display:none}',
|
|
307
329
|
'button[' + NAV_ROW_FLAG + ']::before{content:"";flex:none;width:16px;height:16px;background-color:currentColor;'
|
|
308
330
|
+ '-webkit-mask-repeat:no-repeat;mask-repeat:no-repeat;-webkit-mask-position:center;mask-position:center;'
|
|
@@ -479,6 +501,32 @@ window.__ModuleLoader__.load({
|
|
|
479
501
|
code: h('path', { d: 'M6 4L2.5 8 6 12M10 4l3.5 4L10 12' }),
|
|
480
502
|
};
|
|
481
503
|
|
|
504
|
+
/**
|
|
505
|
+
* The settings nav-row glyph, for the shell's `settings.section.icon` seat.
|
|
506
|
+
*
|
|
507
|
+
* The seat hands a square size (the same 16 the shell's own nav icons use)
|
|
508
|
+
* and expects back the same shape they are: one inline SVG painted in
|
|
509
|
+
* `currentColor`, so the row's own active/hover colour applies without this
|
|
510
|
+
* component knowing either theme. It is deliberately not tied to the page's
|
|
511
|
+
* own header icon set — the row is part of the shell's sidebar.
|
|
512
|
+
*/
|
|
513
|
+
function NavIcon(props) {
|
|
514
|
+
var size = props !== null && typeof props.size === 'number' ? props.size : 16;
|
|
515
|
+
return h(
|
|
516
|
+
'svg',
|
|
517
|
+
{
|
|
518
|
+
width: size,
|
|
519
|
+
height: size,
|
|
520
|
+
viewBox: '0 0 16 16',
|
|
521
|
+
fill: 'none',
|
|
522
|
+
'aria-hidden': 'true',
|
|
523
|
+
},
|
|
524
|
+
NAV_ICON_PATHS.map(function (d, index) {
|
|
525
|
+
return h('path', { key: index, d: d, fill: 'currentColor' });
|
|
526
|
+
}),
|
|
527
|
+
);
|
|
528
|
+
}
|
|
529
|
+
|
|
482
530
|
/**
|
|
483
531
|
* Mark this plugin's own nav row so the stylesheet can swap its icon.
|
|
484
532
|
*
|
|
@@ -490,10 +538,14 @@ window.__ModuleLoader__.load({
|
|
|
490
538
|
* `:nth-child` guess) keeps working when another plugin inserts a section
|
|
491
539
|
* at a neighbouring order, and it never touches a row that is not ours.
|
|
492
540
|
*
|
|
541
|
+
* Only the legacy path calls this: with the icon seat live the shell draws
|
|
542
|
+
* our glyph itself and tagging the row would add a second one.
|
|
543
|
+
*
|
|
493
544
|
* @param root - the mounted page element.
|
|
494
545
|
* @returns a disposer that removes the marker.
|
|
495
546
|
*/
|
|
496
547
|
function markNavRow(root) {
|
|
548
|
+
if (iconSlotLive) return function () {};
|
|
497
549
|
if (root === null || typeof root.closest !== 'function') return function () {};
|
|
498
550
|
var label = makeT(localeRef.current)('nav');
|
|
499
551
|
// The page is mounted inside the settings panel, so the panel is the
|
|
@@ -527,15 +579,22 @@ window.__ModuleLoader__.load({
|
|
|
527
579
|
* for environments without MutationObserver; here a missing flag is only
|
|
528
580
|
* ever set, never removed, so mutations cannot ping-pong.
|
|
529
581
|
*
|
|
582
|
+
* LEGACY path only: the whole tagger switches off the moment
|
|
583
|
+
* `settings.section.icon` is live. The shell then draws our glyph inside
|
|
584
|
+
* its own icon seat, so a flagged row would show that glyph plus the
|
|
585
|
+
* mask, i.e. a second icon — exactly the bug this guard exists to prevent.
|
|
586
|
+
*
|
|
530
587
|
* @returns a disposer that disconnects the observer.
|
|
531
588
|
*/
|
|
532
589
|
function watchNavRow() {
|
|
590
|
+
if (iconSlotLive) return function () {};
|
|
533
591
|
if (typeof MutationObserver === 'undefined' || typeof document === 'undefined') {
|
|
534
592
|
return function () {};
|
|
535
593
|
}
|
|
536
594
|
var scheduled = false;
|
|
537
595
|
function scan() {
|
|
538
596
|
scheduled = false;
|
|
597
|
+
if (iconSlotLive) return;
|
|
539
598
|
var label = makeT(localeRef.current)('nav');
|
|
540
599
|
var cells = document.querySelectorAll('button[class*="navCell"]');
|
|
541
600
|
for (var i = 0; i < cells.length; i += 1) {
|
|
@@ -558,6 +617,20 @@ window.__ModuleLoader__.load({
|
|
|
558
617
|
};
|
|
559
618
|
}
|
|
560
619
|
|
|
620
|
+
/**
|
|
621
|
+
* Drop every legacy row flag.
|
|
622
|
+
*
|
|
623
|
+
* Called when the icon seat turns out to be live. The shell usually
|
|
624
|
+
* declares it before this plugin applies, but nothing guarantees that: if
|
|
625
|
+
* it declares the seat later, rows the fallback already tagged have to
|
|
626
|
+
* stop painting a glyph of their own, or the row ends up with two.
|
|
627
|
+
*/
|
|
628
|
+
function clearNavRowFlags() {
|
|
629
|
+
if (typeof document === 'undefined' || typeof document.querySelectorAll !== 'function') return;
|
|
630
|
+
var rows = document.querySelectorAll('button[' + NAV_ROW_FLAG + ']');
|
|
631
|
+
for (var i = 0; i < rows.length; i += 1) rows[i].removeAttribute(NAV_ROW_FLAG);
|
|
632
|
+
}
|
|
633
|
+
|
|
561
634
|
/** The row switch, styled as the pill toggle the rest of the UI uses. */
|
|
562
635
|
function Switch(props) {
|
|
563
636
|
return h(
|
|
@@ -1231,9 +1304,11 @@ window.__ModuleLoader__.load({
|
|
|
1231
1304
|
var settleTimer = useRef(null);
|
|
1232
1305
|
var pageRef = useRef(null);
|
|
1233
1306
|
|
|
1234
|
-
//
|
|
1235
|
-
//
|
|
1236
|
-
//
|
|
1307
|
+
// Legacy paths only — with `settings.section.icon` live the glyph is
|
|
1308
|
+
// registered at apply() time and the row needs no tagging. watchNavRow
|
|
1309
|
+
// already keeps the row flagged from registration time, so this is a
|
|
1310
|
+
// fallback for environments where the observer is unavailable; both are
|
|
1311
|
+
// no-ops once the icon seat is live.
|
|
1237
1312
|
useEffect(function () {
|
|
1238
1313
|
return markNavRow(pageRef.current);
|
|
1239
1314
|
}, []);
|
|
@@ -1595,9 +1670,35 @@ window.__ModuleLoader__.load({
|
|
|
1595
1670
|
});
|
|
1596
1671
|
}, 'dsh-mcp-manager-plus: settings section');
|
|
1597
1672
|
|
|
1598
|
-
//
|
|
1599
|
-
//
|
|
1600
|
-
|
|
1673
|
+
// Preferred path: the shell's own icon seat for a settings section.
|
|
1674
|
+
// `id` must equal the section id registered above — the shell draws the
|
|
1675
|
+
// entry whose id matches the row it is rendering and falls back to its
|
|
1676
|
+
// generic gear when none does. This seat only exists on shells that
|
|
1677
|
+
// declare it, hence the stylesheet fallback below.
|
|
1678
|
+
try {
|
|
1679
|
+
ctx.effect(function () {
|
|
1680
|
+
return slots.inject('settings.section.icon', function () {
|
|
1681
|
+
iconSlotLive = true;
|
|
1682
|
+
// The seat took over the row: retire anything the legacy fallback
|
|
1683
|
+
// already tagged before its first render.
|
|
1684
|
+
clearNavRowFlags();
|
|
1685
|
+
return slots.register({ name: 'settings.section.icon', id: 'mcp' }, NavIcon);
|
|
1686
|
+
});
|
|
1687
|
+
}, 'dsh-mcp-manager-plus: settings nav icon');
|
|
1688
|
+
} catch (error) {
|
|
1689
|
+
// A shell without the seat parks the injection; one that rejects the
|
|
1690
|
+
// unknown key lands here. Either way the page must still register, so
|
|
1691
|
+
// the failure is reported and the fallback below takes the row.
|
|
1692
|
+
console.warn(
|
|
1693
|
+
'[dsh-mcp-manager-plus] settings.section.icon is unavailable, using the stylesheet glyph:',
|
|
1694
|
+
error,
|
|
1695
|
+
);
|
|
1696
|
+
}
|
|
1697
|
+
|
|
1698
|
+
// Legacy path, for shells that predate the icon seat: flag the row from
|
|
1699
|
+
// the moment the shell first renders it, so the link glyph shows before
|
|
1700
|
+
// the page is ever opened. No-op once `iconSlotLive` is set.
|
|
1701
|
+
ctx.effect(watchNavRow, 'dsh-mcp-manager-plus: legacy nav row icon');
|
|
1601
1702
|
};
|
|
1602
1703
|
|
|
1603
1704
|
return module.exports;
|
package/lib/index.js
CHANGED
|
@@ -25,9 +25,8 @@
|
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
27
|
import { accessSync, constants, existsSync, mkdirSync, renameSync, writeFileSync } from 'node:fs';
|
|
28
|
-
import { createRequire } from 'node:module';
|
|
29
28
|
import { dirname, join } from 'node:path';
|
|
30
|
-
import {
|
|
29
|
+
import { fileURLToPath } from 'node:url';
|
|
31
30
|
import { homedir } from 'node:os';
|
|
32
31
|
import {
|
|
33
32
|
MCP_CLIENT_PACKAGE,
|
|
@@ -46,6 +45,7 @@ import {
|
|
|
46
45
|
validateDocument,
|
|
47
46
|
} from './patch.js';
|
|
48
47
|
import { parseMcpConfig } from './import.js';
|
|
48
|
+
import { resolveEntryYaml, yamlResolutionAnchors } from './yaml.js';
|
|
49
49
|
|
|
50
50
|
/** Route prefix for this plugin's API. */
|
|
51
51
|
const API_PREFIX = '/mcp-manager-plus';
|
|
@@ -117,6 +117,8 @@ const MSGS = {
|
|
|
117
117
|
noServerEntries: '未在配置中找到任何 MCP 服务器条目',
|
|
118
118
|
importEditUpdated: '已识别 {source} 配置;更新 {name}',
|
|
119
119
|
renamedFrom: '(由 {name} 重命名)',
|
|
120
|
+
yamlDegraded:
|
|
121
|
+
'解析到的 js-yaml({source})不支持 !!js 自定义类型,已改用兼容解析;面板功能不受影响',
|
|
120
122
|
},
|
|
121
123
|
en: {
|
|
122
124
|
loopbackOnly: 'Only local (loopback) requests are allowed',
|
|
@@ -149,6 +151,8 @@ const MSGS = {
|
|
|
149
151
|
noServerEntries: 'No MCP server entries found in the configuration',
|
|
150
152
|
importEditUpdated: 'Recognized {source} configuration; updated {name}',
|
|
151
153
|
renamedFrom: ' (renamed from {name})',
|
|
154
|
+
yamlDegraded:
|
|
155
|
+
'The js-yaml in use ({source}) does not support the !!js custom type; a compatible parser is active and the panel stays fully usable',
|
|
152
156
|
},
|
|
153
157
|
};
|
|
154
158
|
|
|
@@ -191,48 +195,20 @@ function joinList(lang, names) {
|
|
|
191
195
|
* tried first — that is where the loader's own include plugin resolves it from
|
|
192
196
|
* — with a normal import as the fallback.
|
|
193
197
|
*
|
|
198
|
+
* A copy that cannot register the `!!js` type no longer takes the page down
|
|
199
|
+
* with it: it is skipped in favour of the plugin's own pinned copy, and when
|
|
200
|
+
* no copy at all can carry the tag the module is adapted instead of rejected.
|
|
201
|
+
* See `./yaml.js` for both defences.
|
|
202
|
+
*
|
|
194
203
|
* @param ctx - host context, used to anchor resolution at the profile directory.
|
|
195
|
-
* @returns
|
|
204
|
+
* @returns `{ yaml, schema, degraded, source, raw }` — the module plus a
|
|
205
|
+
* schema able to round-trip `!!js` scalars.
|
|
196
206
|
*/
|
|
197
207
|
async function loadYaml(ctx) {
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
construct: (data) => ({ __jsExpr: data }),
|
|
203
|
-
predicate: (value) =>
|
|
204
|
-
value !== null && typeof value === 'object' && typeof value.__jsExpr === 'string',
|
|
205
|
-
represent: (value) => value.__jsExpr,
|
|
206
|
-
});
|
|
207
|
-
return { yaml, schema: yaml.JSON_SCHEMA.extend(jsExpr) };
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
/** Resolve the `js-yaml` module, preferring the profile's own copy. */
|
|
211
|
-
async function resolveYaml(anchorDir) {
|
|
212
|
-
const candidates = [];
|
|
213
|
-
if (typeof anchorDir === 'string' && anchorDir !== '') candidates.push(anchorDir);
|
|
214
|
-
// The plugin's own package directory: an installed copy sits inside the
|
|
215
|
-
// profile's node_modules, so this reaches the same hoisted `js-yaml` even
|
|
216
|
-
// when the profile directory could not be resolved from the loader.
|
|
217
|
-
candidates.push(dirname(fileURLToPath(import.meta.url)));
|
|
218
|
-
candidates.push(process.cwd());
|
|
219
|
-
const home = dshHome();
|
|
220
|
-
candidates.push(join(home, 'profiles', argvProfile() ?? 'web'));
|
|
221
|
-
candidates.push(join(home, 'profiles'));
|
|
222
|
-
|
|
223
|
-
for (const anchor of candidates) {
|
|
224
|
-
try {
|
|
225
|
-
const require = createRequire(join(anchor, 'package.json'));
|
|
226
|
-
const loaded = await import(pathToFileURL(require.resolve('js-yaml')).href);
|
|
227
|
-
return loaded.default ?? loaded;
|
|
228
|
-
} catch {
|
|
229
|
-
// Try the next anchor.
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
// Last resort: an ordinary bare import, which succeeds when this package was
|
|
233
|
-
// installed with `js-yaml` as a real dependency.
|
|
234
|
-
const loaded = await import('js-yaml');
|
|
235
|
-
return loaded.default ?? loaded;
|
|
208
|
+
const { profileDir } = resolvePatchPath(ctx);
|
|
209
|
+
return resolveEntryYaml(
|
|
210
|
+
yamlResolutionAnchors(profileDir, { home: dshHome(), profile: argvProfile() ?? 'web' }),
|
|
211
|
+
);
|
|
236
212
|
}
|
|
237
213
|
|
|
238
214
|
/** The harness home, honouring a `DSH_HOME` override. */
|
|
@@ -1015,9 +991,13 @@ export function apply(ctx) {
|
|
|
1015
991
|
if (cache !== null && now - cache.at < CACHE_TTL_MS && cache.patchPath === patchPath) {
|
|
1016
992
|
return cache.value;
|
|
1017
993
|
}
|
|
1018
|
-
const { yaml, schema } = await loadYaml(ctx);
|
|
994
|
+
const { yaml, schema, degraded, source } = await loadYaml(ctx);
|
|
1019
995
|
const document = readDocument(readPatchText(patchPath), yaml, schema);
|
|
1020
996
|
const inventory = buildInventory(ctx, document, lang);
|
|
997
|
+
// Say so rather than silently parsing with a weaker engine: the user's
|
|
998
|
+
// patch file is still fully managed, but a report that mentions it saves a
|
|
999
|
+
// round trip.
|
|
1000
|
+
if (degraded) inventory.issues.push(tr(lang, 'yamlDegraded', { source }));
|
|
1021
1001
|
// Report writability before an edit rather than after one fails. Probing
|
|
1022
1002
|
// the directory covers a patch file that does not exist yet; probing the
|
|
1023
1003
|
// file covers one that a previous tool left read-only.
|
package/lib/yaml.js
ADDED
|
@@ -0,0 +1,503 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-mcp-manager-plus — `js-yaml` compatibility layer.
|
|
3
|
+
*
|
|
4
|
+
* The plugin needs exactly one thing from `js-yaml`: a custom scalar type for
|
|
5
|
+
* the entry-list dialect's `!!js` tag. That is a v3/v4 API — `new yaml.Type(…)`
|
|
6
|
+
* plus `schema.extend(…)` — and the module is resolved through the *profile*
|
|
7
|
+
* root, where every plugin's dependencies are hoisted by pnpm. So an unrelated
|
|
8
|
+
* plugin declaring `js-yaml@^5` can hoist a v5 to the top of the profile, and a
|
|
9
|
+
* v5 no longer exports `Type`: the constructor call threw inside `loadYaml()`
|
|
10
|
+
* and the whole panel became `加载失败:yaml.Type is not a constructor`. The
|
|
11
|
+
* plugin never pinned its own copy, so nothing kept that from happening.
|
|
12
|
+
*
|
|
13
|
+
* Two independent defences, applied in this order:
|
|
14
|
+
*
|
|
15
|
+
* 1. **Pick a copy that can do the job.** Resolution walks the same anchors as
|
|
16
|
+
* before, but a candidate that cannot build the `!!js` tag is *skipped*
|
|
17
|
+
* rather than used, so the plugin's own pinned `js-yaml` (a real
|
|
18
|
+
* `dependencies` entry, reached through the plugin's own directory) wins
|
|
19
|
+
* over a hoisted v5.
|
|
20
|
+
* 2. **Never lose the page.** If every candidate is incompatible the module is
|
|
21
|
+
* *adapted* instead of rejected: the `!!js` tag is neutralized textually
|
|
22
|
+
* before parsing and the parsed scalar is re-tagged afterwards. The panel
|
|
23
|
+
* keeps loading, and — because this module's contract is that a `!!js`
|
|
24
|
+
* expression must never be silently rewritten into a literal string — the
|
|
25
|
+
* value still round-trips as an expression node rather than as plain text.
|
|
26
|
+
*
|
|
27
|
+
* The adaptation is deliberately equivalent to the fast path, not merely
|
|
28
|
+
* "good enough": a `!!js` scalar decodes to the same expression string a v4
|
|
29
|
+
* `construct()` would have produced, so emission through {@link
|
|
30
|
+
* module:dsh-mcp-manager-plus/patch.scalar} is unchanged.
|
|
31
|
+
*
|
|
32
|
+
* @module dsh-mcp-manager-plus/yaml
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
import { createRequire } from 'node:module';
|
|
36
|
+
import { dirname, join } from 'node:path';
|
|
37
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
38
|
+
|
|
39
|
+
/** The tag the loader's include plugin uses for an expression scalar. */
|
|
40
|
+
export const JS_EXPR_TAG = 'tag:yaml.org,2002:js';
|
|
41
|
+
|
|
42
|
+
/** Prefix of the placeholder that stands in for a neutralized `!!js` scalar. */
|
|
43
|
+
const PLACEHOLDER_PREFIX = '__mcpmp_js_expr_';
|
|
44
|
+
|
|
45
|
+
/** This file's own directory: the anchor that reaches the plugin's own deps. */
|
|
46
|
+
const PLUGIN_DIR = dirname(fileURLToPath(import.meta.url));
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Build the entry-list schema — a JSON schema plus the `!!js` scalar type — or
|
|
50
|
+
* `null` when this module cannot express the tag.
|
|
51
|
+
*
|
|
52
|
+
* The probe is deliberately narrow: it asks for the two things the dialect
|
|
53
|
+
* needs (`Type` constructible, base schema extensible) instead of sniffing a
|
|
54
|
+
* version number, because a fork or a v5 that keeps half the API should fall
|
|
55
|
+
* through to the adapted parser rather than throw halfway through a parse.
|
|
56
|
+
*
|
|
57
|
+
* @param mod - a `js-yaml` module (namespace or CJS exports object).
|
|
58
|
+
* @returns the schema, or `null` when the module cannot carry `!!js`.
|
|
59
|
+
*/
|
|
60
|
+
export function buildEntrySchema(mod) {
|
|
61
|
+
try {
|
|
62
|
+
if (mod === null || typeof mod !== 'object') return null;
|
|
63
|
+
if (typeof mod.Type !== 'function') return null;
|
|
64
|
+
const base = mod.JSON_SCHEMA ?? mod.DEFAULT_SCHEMA;
|
|
65
|
+
if (base === null || typeof base !== 'object') return null;
|
|
66
|
+
if (typeof base.extend !== 'function') return null;
|
|
67
|
+
const jsExpr = new mod.Type(JS_EXPR_TAG, {
|
|
68
|
+
kind: 'scalar',
|
|
69
|
+
resolve: (data) => typeof data === 'string',
|
|
70
|
+
construct: (data) => ({ __jsExpr: data }),
|
|
71
|
+
predicate: (value) =>
|
|
72
|
+
value !== null && typeof value === 'object' && typeof value.__jsExpr === 'string',
|
|
73
|
+
represent: (value) => value.__jsExpr,
|
|
74
|
+
});
|
|
75
|
+
return base.extend(jsExpr);
|
|
76
|
+
} catch {
|
|
77
|
+
// A module that advertises the API but throws while building it (a v5 that
|
|
78
|
+
// keeps a `Type` binding for compatibility, say) degrades like any other.
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Adapt a resolved `js-yaml` module for the entry-list dialect.
|
|
85
|
+
*
|
|
86
|
+
* @param mod - the module to adapt.
|
|
87
|
+
* @param source - where it came from, for diagnostics and the UI warning.
|
|
88
|
+
* @returns `{ yaml, schema, degraded, source, raw }`. `yaml` is the module
|
|
89
|
+
* itself on the fast path and a `load`-compatible wrapper otherwise;
|
|
90
|
+
* `schema` is `undefined` when degraded, because the wrapper ignores it.
|
|
91
|
+
*/
|
|
92
|
+
export function adaptYamlModule(mod, source = 'js-yaml') {
|
|
93
|
+
const schema = buildEntrySchema(mod);
|
|
94
|
+
if (schema !== null) return { yaml: mod, schema, degraded: false, source, raw: mod };
|
|
95
|
+
return { yaml: degradeModule(mod), schema: undefined, degraded: true, source, raw: mod };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* The anchors `js-yaml` is resolved through, in order.
|
|
100
|
+
*
|
|
101
|
+
* Order is unchanged from the original implementation — the profile directory
|
|
102
|
+
* first, so the dialect matches what the loader's own include plugin uses — but
|
|
103
|
+
* that no longer means "first copy wins": {@link resolveEntryYaml} skips an
|
|
104
|
+
* anchor whose copy cannot build the `!!js` tag, which is what lets the
|
|
105
|
+
* plugin's own pinned copy take over from a hoisted v5.
|
|
106
|
+
*
|
|
107
|
+
* @param profileDir - the profile directory, when the loader knows it.
|
|
108
|
+
* @param options - `{ home, profile, pluginDir, cwd }`; all optional.
|
|
109
|
+
* @returns candidate directories, most specific first.
|
|
110
|
+
*/
|
|
111
|
+
export function yamlResolutionAnchors(profileDir, options = {}) {
|
|
112
|
+
const {
|
|
113
|
+
home,
|
|
114
|
+
profile = 'web',
|
|
115
|
+
pluginDir = PLUGIN_DIR,
|
|
116
|
+
cwd = process.cwd(),
|
|
117
|
+
} = options;
|
|
118
|
+
const anchors = [];
|
|
119
|
+
if (typeof profileDir === 'string' && profileDir !== '') anchors.push(profileDir);
|
|
120
|
+
// The plugin's own package directory: an installed copy sits inside the
|
|
121
|
+
// profile's node_modules, so this reaches the same hoisted `js-yaml` even
|
|
122
|
+
// when the profile directory could not be resolved from the loader.
|
|
123
|
+
anchors.push(pluginDir);
|
|
124
|
+
anchors.push(cwd);
|
|
125
|
+
if (typeof home === 'string' && home !== '') {
|
|
126
|
+
anchors.push(join(home, 'profiles', profile));
|
|
127
|
+
anchors.push(join(home, 'profiles'));
|
|
128
|
+
}
|
|
129
|
+
return anchors;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Resolve `js-yaml` and adapt it, preferring a copy that can express `!!js`.
|
|
134
|
+
*
|
|
135
|
+
* Every anchor is tried; the first *compatible* copy wins. If none is
|
|
136
|
+
* compatible the first resolvable one is returned adapted (degraded), and only
|
|
137
|
+
* when nothing resolves at all does this throw — a thrown error here is the
|
|
138
|
+
* one case the page cannot survive, so it is left as the last resort rather
|
|
139
|
+
* than the first.
|
|
140
|
+
*
|
|
141
|
+
* @param anchors - directories to resolve from, in order.
|
|
142
|
+
* @param options - `{ load }`, injectable for tests.
|
|
143
|
+
* @returns `{ yaml, schema, degraded, source, raw }`.
|
|
144
|
+
*/
|
|
145
|
+
export async function resolveEntryYaml(anchors, options = {}) {
|
|
146
|
+
const load = options.load ?? loadFromAnchor;
|
|
147
|
+
let degraded = null;
|
|
148
|
+
for (const anchor of anchors) {
|
|
149
|
+
if (typeof anchor !== 'string' || anchor === '') continue;
|
|
150
|
+
let loaded;
|
|
151
|
+
try {
|
|
152
|
+
loaded = await load(anchor);
|
|
153
|
+
} catch {
|
|
154
|
+
continue; // No copy here; try the next anchor.
|
|
155
|
+
}
|
|
156
|
+
if (loaded === null || loaded === undefined) continue;
|
|
157
|
+
const adapted = adaptLoaded(loaded, anchor);
|
|
158
|
+
if (!adapted.degraded) return adapted;
|
|
159
|
+
if (degraded === null) degraded = adapted;
|
|
160
|
+
}
|
|
161
|
+
// Last resort: an ordinary bare import, which succeeds when this package was
|
|
162
|
+
// installed with `js-yaml` as a real dependency.
|
|
163
|
+
try {
|
|
164
|
+
const loaded = await load(null);
|
|
165
|
+
if (loaded !== null && loaded !== undefined) {
|
|
166
|
+
const adapted = adaptLoaded(loaded, 'js-yaml');
|
|
167
|
+
if (!adapted.degraded) return adapted;
|
|
168
|
+
if (degraded === null) degraded = adapted;
|
|
169
|
+
}
|
|
170
|
+
} catch {
|
|
171
|
+
// Nothing resolvable; handled below.
|
|
172
|
+
}
|
|
173
|
+
if (degraded !== null) return degraded;
|
|
174
|
+
throw new Error('未能解析到 js-yaml:插件目录与 profile 中都没有可用副本');
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Import a `js-yaml` copy through one anchor.
|
|
179
|
+
* @param anchor - a directory, or `null` for a bare import.
|
|
180
|
+
* @returns `{ module, source }`.
|
|
181
|
+
*/
|
|
182
|
+
async function loadFromAnchor(anchor) {
|
|
183
|
+
if (anchor === null) {
|
|
184
|
+
const loaded = await import('js-yaml');
|
|
185
|
+
return { module: unwrapModule(loaded), source: 'js-yaml' };
|
|
186
|
+
}
|
|
187
|
+
const require = createRequire(join(anchor, 'package.json'));
|
|
188
|
+
const resolved = require.resolve('js-yaml');
|
|
189
|
+
const loaded = await import(pathToFileURL(resolved).href);
|
|
190
|
+
return { module: unwrapModule(loaded), source: resolved };
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** A CJS module reached through `import()` carries its exports under `.default`. */
|
|
194
|
+
function unwrapModule(loaded) {
|
|
195
|
+
return loaded?.default ?? loaded;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Adapt whatever a loader returned, accepting a bare module for convenience.
|
|
200
|
+
* @param loaded - `{ module, source }` or a module.
|
|
201
|
+
* @param fallbackSource - source label when the loader did not supply one.
|
|
202
|
+
* @returns the adapter result.
|
|
203
|
+
*/
|
|
204
|
+
function adaptLoaded(loaded, fallbackSource) {
|
|
205
|
+
const mod = loaded.module !== undefined ? loaded.module : loaded;
|
|
206
|
+
return adaptYamlModule(mod, loaded.source ?? fallbackSource);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// ── degraded parsing ────────────────────────────────────────────────────────
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Wrap a module that cannot register `!!js` so it still parses documents that
|
|
213
|
+
* carry the tag.
|
|
214
|
+
*
|
|
215
|
+
* Only `load` is provided: the plugin never dumps YAML through the module (it
|
|
216
|
+
* emits patch text itself), so a `dump` here would be dead code pretending to
|
|
217
|
+
* be a fallback.
|
|
218
|
+
*
|
|
219
|
+
* @param mod - the incompatible module.
|
|
220
|
+
* @returns `{ load, __mcpmpDegraded }`.
|
|
221
|
+
*/
|
|
222
|
+
function degradeModule(mod) {
|
|
223
|
+
return {
|
|
224
|
+
load(text) {
|
|
225
|
+
if (typeof text !== 'string' || !text.includes('!!js')) return parseDocument(mod, text);
|
|
226
|
+
const { text: neutralized, expressions } = neutralizeJsTags(mod, text);
|
|
227
|
+
if (expressions.size === 0) return parseDocument(mod, text);
|
|
228
|
+
return retagExpressions(parseDocument(mod, neutralized), expressions);
|
|
229
|
+
},
|
|
230
|
+
__mcpmpDegraded: true,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Parse with the closest schema the module offers. The fast path extends
|
|
236
|
+
* `JSON_SCHEMA`, so degrading to it keeps value typing identical — falling back
|
|
237
|
+
* to the default schema would quietly turn a date-shaped string into a `Date`
|
|
238
|
+
* and rewrite it on the next save.
|
|
239
|
+
* @param mod - the `js-yaml` module.
|
|
240
|
+
* @param text - document text.
|
|
241
|
+
* @returns the parsed value.
|
|
242
|
+
*/
|
|
243
|
+
function parseDocument(mod, text) {
|
|
244
|
+
const base = mod.JSON_SCHEMA ?? mod.DEFAULT_SCHEMA;
|
|
245
|
+
return base === undefined ? mod.load(text) : mod.load(text, { schema: base });
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Replace every `!!js` tag and its scalar with a unique placeholder string.
|
|
250
|
+
*
|
|
251
|
+
* The scan is quote- and comment-aware on purpose: a config value such as
|
|
252
|
+
* `args: ["echo !!js x"]` or a header comment mentioning `!!js` must survive
|
|
253
|
+
* untouched, and a placeholder that leaked into such a value would be re-tagged
|
|
254
|
+
* as an expression and change what the row configures.
|
|
255
|
+
*
|
|
256
|
+
* @param mod - the `js-yaml` module (used to decode each scalar).
|
|
257
|
+
* @param text - the document.
|
|
258
|
+
* @returns `{ text, expressions }`, expressions mapping placeholder → value.
|
|
259
|
+
*/
|
|
260
|
+
function neutralizeJsTags(mod, text) {
|
|
261
|
+
const nonce = `${PLACEHOLDER_PREFIX}${Math.random().toString(36).slice(2)}_`;
|
|
262
|
+
const expressions = new Map();
|
|
263
|
+
let out = '';
|
|
264
|
+
let index = 0;
|
|
265
|
+
let inSingle = false;
|
|
266
|
+
let inDouble = false;
|
|
267
|
+
let inComment = false;
|
|
268
|
+
let lineStart = true;
|
|
269
|
+
let flowDepth = 0;
|
|
270
|
+
|
|
271
|
+
while (index < text.length) {
|
|
272
|
+
const char = text[index];
|
|
273
|
+
|
|
274
|
+
if (char === '\n') {
|
|
275
|
+
out += char;
|
|
276
|
+
index += 1;
|
|
277
|
+
inComment = false;
|
|
278
|
+
lineStart = true;
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
if (inComment) {
|
|
282
|
+
out += char;
|
|
283
|
+
index += 1;
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
if (inSingle) {
|
|
287
|
+
out += char;
|
|
288
|
+
index += 1;
|
|
289
|
+
// YAML escapes a quote inside a single-quoted scalar by doubling it.
|
|
290
|
+
if (char === "'") {
|
|
291
|
+
if (text[index] === "'") {
|
|
292
|
+
out += text[index];
|
|
293
|
+
index += 1;
|
|
294
|
+
} else {
|
|
295
|
+
inSingle = false;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
continue;
|
|
299
|
+
}
|
|
300
|
+
if (inDouble) {
|
|
301
|
+
out += char;
|
|
302
|
+
index += 1;
|
|
303
|
+
if (char === '\\') {
|
|
304
|
+
out += text[index] ?? '';
|
|
305
|
+
index += 1;
|
|
306
|
+
} else if (char === '"') {
|
|
307
|
+
inDouble = false;
|
|
308
|
+
}
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
if (char === '#' && (lineStart || /[ \t]/u.test(text[index - 1] ?? '\n'))) {
|
|
312
|
+
inComment = true;
|
|
313
|
+
out += char;
|
|
314
|
+
index += 1;
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
if (char === "'" || char === '"') {
|
|
318
|
+
inSingle = char === "'";
|
|
319
|
+
inDouble = char === '"';
|
|
320
|
+
lineStart = false;
|
|
321
|
+
out += char;
|
|
322
|
+
index += 1;
|
|
323
|
+
continue;
|
|
324
|
+
}
|
|
325
|
+
if (char === '[' || char === '{') {
|
|
326
|
+
flowDepth += 1;
|
|
327
|
+
lineStart = false;
|
|
328
|
+
out += char;
|
|
329
|
+
index += 1;
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
332
|
+
if (char === ']' || char === '}') {
|
|
333
|
+
flowDepth = Math.max(0, flowDepth - 1);
|
|
334
|
+
lineStart = false;
|
|
335
|
+
out += char;
|
|
336
|
+
index += 1;
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
if (char === '!' && text.startsWith('!!js', index) && isTagBoundary(text[index + 4])) {
|
|
340
|
+
const node = captureNode(text, index, index + 4, flowDepth);
|
|
341
|
+
const placeholder = `${nonce}${expressions.size}`;
|
|
342
|
+
expressions.set(placeholder, decodeExpression(mod, node.raw));
|
|
343
|
+
out += placeholder;
|
|
344
|
+
index = node.end;
|
|
345
|
+
lineStart = false;
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
if (char !== ' ' && char !== '\t') lineStart = false;
|
|
349
|
+
out += char;
|
|
350
|
+
index += 1;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
return { text: out, expressions };
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/** A tag ends at end-of-input or at the whitespace before its node. */
|
|
357
|
+
function isTagBoundary(char) {
|
|
358
|
+
return char === undefined || char === ' ' || char === '\t' || char === '\n';
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Find the scalar a `!!js` tag applies to.
|
|
363
|
+
*
|
|
364
|
+
* The tag is followed by either an inline scalar (a plain, single- or
|
|
365
|
+
* double-quoted scalar, ended by the line, an unquoted comment, or a flow
|
|
366
|
+
* indicator) or a block scalar header (`|`/`>`) whose indented lines belong to
|
|
367
|
+
* it. Neither form is decoded here — the raw source text is returned so the
|
|
368
|
+
* decode can go through `js-yaml` itself, which is the only correct parser for
|
|
369
|
+
* quoting and block folding.
|
|
370
|
+
*
|
|
371
|
+
* @param text - the document.
|
|
372
|
+
* @param tagStart - index of the `!` that opens the tag.
|
|
373
|
+
* @param from - index just past the tag.
|
|
374
|
+
* @param flowDepth - current flow-collection depth (0 outside `[]`/`{}`).
|
|
375
|
+
* @returns `{ raw, end }`; `end` is where the placeholder replaces to.
|
|
376
|
+
*/
|
|
377
|
+
function captureNode(text, tagStart, from, flowDepth) {
|
|
378
|
+
let cursor = from;
|
|
379
|
+
while (text[cursor] === ' ' || text[cursor] === '\t') cursor += 1;
|
|
380
|
+
if (text[cursor] === '|' || text[cursor] === '>') return captureBlock(text, tagStart, cursor);
|
|
381
|
+
|
|
382
|
+
let end = cursor;
|
|
383
|
+
let single = false;
|
|
384
|
+
let double = false;
|
|
385
|
+
while (end < text.length) {
|
|
386
|
+
const char = text[end];
|
|
387
|
+
if (char === '\n') break;
|
|
388
|
+
if (single) {
|
|
389
|
+
if (char === "'") {
|
|
390
|
+
if (text[end + 1] === "'") {
|
|
391
|
+
end += 2;
|
|
392
|
+
continue;
|
|
393
|
+
}
|
|
394
|
+
single = false;
|
|
395
|
+
}
|
|
396
|
+
end += 1;
|
|
397
|
+
continue;
|
|
398
|
+
}
|
|
399
|
+
if (double) {
|
|
400
|
+
if (char === '\\') {
|
|
401
|
+
end += 2;
|
|
402
|
+
continue;
|
|
403
|
+
}
|
|
404
|
+
if (char === '"') double = false;
|
|
405
|
+
end += 1;
|
|
406
|
+
continue;
|
|
407
|
+
}
|
|
408
|
+
if (char === "'") {
|
|
409
|
+
single = true;
|
|
410
|
+
end += 1;
|
|
411
|
+
continue;
|
|
412
|
+
}
|
|
413
|
+
if (char === '"') {
|
|
414
|
+
double = true;
|
|
415
|
+
end += 1;
|
|
416
|
+
continue;
|
|
417
|
+
}
|
|
418
|
+
if (char === '#' && (text[end - 1] === ' ' || text[end - 1] === '\t')) break;
|
|
419
|
+
if (flowDepth > 0 && (char === ',' || char === '}' || char === ']')) break;
|
|
420
|
+
end += 1;
|
|
421
|
+
}
|
|
422
|
+
let rawEnd = end;
|
|
423
|
+
while (rawEnd > cursor && (text[rawEnd - 1] === ' ' || text[rawEnd - 1] === '\t')) rawEnd -= 1;
|
|
424
|
+
return { raw: text.slice(cursor, rawEnd), end };
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* Capture a block scalar (`!!js |-`) including its indented body.
|
|
429
|
+
* @param text - the document.
|
|
430
|
+
* @param tagStart - index of the `!` that opens the tag.
|
|
431
|
+
* @param indicatorStart - index of the `|`/`>` indicator.
|
|
432
|
+
* @returns `{ raw, end }`.
|
|
433
|
+
*/
|
|
434
|
+
function captureBlock(text, tagStart, indicatorStart) {
|
|
435
|
+
const lineStart = text.lastIndexOf('\n', tagStart - 1) + 1;
|
|
436
|
+
const firstBreak = text.indexOf('\n', indicatorStart);
|
|
437
|
+
const headerEnd = firstBreak === -1 ? text.length : firstBreak;
|
|
438
|
+
const tagIndent = (text.slice(lineStart, headerEnd).match(/^[ \t]*/u)?.[0] ?? '').length;
|
|
439
|
+
|
|
440
|
+
let cursor = firstBreak === -1 ? text.length : firstBreak + 1;
|
|
441
|
+
let lastContent = headerEnd;
|
|
442
|
+
while (cursor < text.length) {
|
|
443
|
+
const nextBreak = text.indexOf('\n', cursor);
|
|
444
|
+
const lineStop = nextBreak === -1 ? text.length : nextBreak;
|
|
445
|
+
const line = text.slice(cursor, lineStop).replace(/\r$/u, '');
|
|
446
|
+
if (line.trim() !== '') {
|
|
447
|
+
const indent = (line.match(/^[ \t]*/u)?.[0] ?? '').length;
|
|
448
|
+
if (indent <= tagIndent) break;
|
|
449
|
+
lastContent = lineStop;
|
|
450
|
+
}
|
|
451
|
+
if (nextBreak === -1) break;
|
|
452
|
+
cursor = nextBreak + 1;
|
|
453
|
+
}
|
|
454
|
+
return { raw: text.slice(indicatorStart, lastContent), end: lastContent };
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* Decode one captured scalar through `js-yaml`, so the expression string is
|
|
459
|
+
* exactly what a v4 `construct()` would have received. A scalar the module
|
|
460
|
+
* refuses (or one that resolves to a non-string) keeps its raw source text,
|
|
461
|
+
* which still emits as a valid `!!js` scalar.
|
|
462
|
+
* @param mod - the `js-yaml` module.
|
|
463
|
+
* @param raw - the captured scalar source text.
|
|
464
|
+
* @returns the expression string.
|
|
465
|
+
*/
|
|
466
|
+
function decodeExpression(mod, raw) {
|
|
467
|
+
if (raw === '') return raw;
|
|
468
|
+
try {
|
|
469
|
+
const parsed = parseDocument(mod, `x: ${raw}`);
|
|
470
|
+
const value = parsed?.x;
|
|
471
|
+
if (typeof value === 'string') return value;
|
|
472
|
+
} catch {
|
|
473
|
+
// Fall through to the raw source.
|
|
474
|
+
}
|
|
475
|
+
return raw;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* Walk a parsed document and turn every placeholder back into an expression
|
|
480
|
+
* node. Only strings are considered (a placeholder is always parsed as one),
|
|
481
|
+
* and only plain objects/arrays are recursed into, so schema-built values such
|
|
482
|
+
* as `Date` are returned untouched.
|
|
483
|
+
* @param value - the parsed value.
|
|
484
|
+
* @param expressions - placeholder → expression string.
|
|
485
|
+
* @returns the document with expression nodes restored.
|
|
486
|
+
*/
|
|
487
|
+
function retagExpressions(value, expressions) {
|
|
488
|
+
if (typeof value === 'string') {
|
|
489
|
+
const expr = expressions.get(value);
|
|
490
|
+
return expr === undefined ? value : { __jsExpr: expr };
|
|
491
|
+
}
|
|
492
|
+
if (Array.isArray(value)) return value.map((entry) => retagExpressions(entry, expressions));
|
|
493
|
+
if (value !== null && typeof value === 'object') {
|
|
494
|
+
const proto = Object.getPrototypeOf(value);
|
|
495
|
+
if (proto !== Object.prototype && proto !== null) return value;
|
|
496
|
+
const out = {};
|
|
497
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
498
|
+
out[key] = retagExpressions(entry, expressions);
|
|
499
|
+
}
|
|
500
|
+
return out;
|
|
501
|
+
}
|
|
502
|
+
return value;
|
|
503
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-mcp-manager-plus",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.5",
|
|
4
4
|
"description": "MCP manager settings page for DeepSeek Harness: list, enable, configure and add MCP servers from the browser, written durably to the profile's user patch layer.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"icon": "./icon.svg",
|
|
@@ -32,6 +32,9 @@
|
|
|
32
32
|
"scripts": {
|
|
33
33
|
"test": "node test/run.mjs"
|
|
34
34
|
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"js-yaml": "^4.1.0"
|
|
37
|
+
},
|
|
35
38
|
"keywords": [
|
|
36
39
|
"deepseek",
|
|
37
40
|
"harness",
|