dsh-mcp-manager-plus 0.4.2 → 0.4.4
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 +61 -0
- package/README.en.md +5 -2
- package/README.md +4 -2
- package/lib/client.js +5 -2
- package/lib/index.js +40 -44
- package/lib/yaml.js +503 -0
- package/package.json +4 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,65 @@
|
|
|
5
5
|
|
|
6
6
|
0.3.1 之前的开发发生在公开仓库建立之前,历史没有保留。
|
|
7
7
|
|
|
8
|
+
## [0.4.4] - 2026-10-15
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- **profile 顶层被提升到 `js-yaml` v5 时整页「加载失败:yaml.Type is not a constructor」**:
|
|
13
|
+
`loadYaml()` 用 v3/v4 的自定义类型 API(`new yaml.Type(...)` + `schema.extend(...)`)
|
|
14
|
+
承载 `!!js` 标签,而 `js-yaml` 一直是按 profile 锚点解析的——任何别的插件
|
|
15
|
+
(如声明 `js-yaml@^5` 的插件)把 v5 提升到 profile 顶层后,`new yaml.Type(...)`
|
|
16
|
+
就抛错,所有路由 500、面板完全不可用(感谢 @asfre 的报告与定位)。
|
|
17
|
+
现在不再「谁先解析到就用谁」,而是在新增的 `lib/yaml.js` 里**探测能力**:
|
|
18
|
+
一个副本构造不出 `!!js` 类型就跳过、继续沿锚点往下找,于是插件在
|
|
19
|
+
`dependencies` 中钉住的 `js-yaml@^4.1.0` 会接管,而不是被顶层提升的 v5 拖垮
|
|
20
|
+
- **所有副本都不兼容时仍有兜底**:若插件目录与 profile 里没有任何能构造自定义类型的
|
|
21
|
+
副本,也不再抛错,而是改用兼容解析——解析前把 `!!js` 标签替换成占位符、解析后再
|
|
22
|
+
还原为表达式节点(扫描会跳过引号与注释内的文本,`args: ["echo !!js x"]`、
|
|
23
|
+
`PLAIN: "!!js not a tag"` 这类值不会被误判成表达式)。面板因此照常加载与管理,
|
|
24
|
+
且 `!!js` 语义不被改写:降级解析与快路径读出的值完全相同,回写的字节也完全一致
|
|
25
|
+
- 降级时在页面「配置提示」里写明实际解析到的 `js-yaml` 与降级状态,不再静默降级
|
|
26
|
+
|
|
27
|
+
### Added
|
|
28
|
+
|
|
29
|
+
- `dependencies` 新增 `js-yaml: ^4.1.0`:插件自带确定的副本,不再依赖 profile 顶层
|
|
30
|
+
提升结果;解析顺序仍是 profile 锚点优先(与载入器 include 插件一致),只是不再
|
|
31
|
+
接受一个无法承载 `!!js` 的副本
|
|
32
|
+
- 回归用例 `test/yaml.test.mjs`(11 项):能力探测(`Type` 抛错、缺 `extend`、
|
|
33
|
+
非对象等形态)、注入加载器验证「profile 锚点的不兼容副本让位于插件的可用副本」、
|
|
34
|
+
完全没有可解析副本时报出明确错误,以及降级解析下 `!!js` 的行内 / 块 / 流式三种
|
|
35
|
+
写法、「与快路径逐字节一致」、「回写后仍能通过校验并往返」
|
|
36
|
+
- 回归用例 `test/host.test.mjs`:在临时 profile 里放一个「v5 形状」(可解析、无自定义
|
|
37
|
+
类型)的 `js-yaml`,`GET /servers` 必须仍返回 200 并列出种子行,而不是整页不可用
|
|
38
|
+
(测试总数 115 → 127)
|
|
39
|
+
|
|
40
|
+
## [0.4.3] - 2026-10-09
|
|
41
|
+
|
|
42
|
+
### Fixed
|
|
43
|
+
|
|
44
|
+
- **安装路径含空格时补丁文件被误判为「不可写」**(DSH Desktop / Windows):
|
|
45
|
+
`fromFileUrl()` 用 `new URL().pathname` 读取路径,会保留百分号编码——DSH Desktop
|
|
46
|
+
以 `file://` URL 传入 include 路径,`D:\DeepSeek Harness\` 因此变成
|
|
47
|
+
`DeepSeek%20Harness`,指向一个并不存在的文件,`W_OK` 探测失败后页面报
|
|
48
|
+
「配置文件不可写」并拒绝所有保存。现在改用 `fileURLToPath()`(解码 `%20`
|
|
49
|
+
等转义,并正确处理 Windows 盘符前导斜杠与 UNC 主机),手动解析仅作兜底
|
|
50
|
+
(感谢 @Lzh3070 的报告与定位)
|
|
51
|
+
- **暗色主题下主按钮白底白字、文字不可读**:`.mcpmp-btn-primary` 把前景硬编码成
|
|
52
|
+
`#fff`,而背景用的 `--dsw-alias-brand-primary` 会随主题翻转(亮色 `#0f1115`、
|
|
53
|
+
暗色 `#f9fafb`),暗色下于是成了白字配近白底。现在按 harness 自身主按钮的配对
|
|
54
|
+
改用 `--dsw-alias-button-primary-fill` + `--dsw-alias-label-primary-foreground`
|
|
55
|
+
(分别以 `brand-primary` / `label-primary-inverted` / `#fff` 兜底),hover 换成
|
|
56
|
+
官方的 `--dsw-alias-button-primary-hover`,取代在近白底上几乎无效的
|
|
57
|
+
`filter:brightness(1.08)`(感谢 @OTH-C3 的报告与定位)
|
|
58
|
+
|
|
59
|
+
### Added
|
|
60
|
+
|
|
61
|
+
- 回归用例:`file://` include 路径含 `%20` 时,`patchPath` 必须指向真实文件且
|
|
62
|
+
`writable` 必须为 `true`;把 `lib/index.js` 还原成旧实现可复现该用例失败
|
|
63
|
+
- 回归用例:任何把「会随主题翻转的填充色」(`brand-primary` /
|
|
64
|
+
`button-primary-fill`)与字面前景色写进同一条规则的样式都会被判失败
|
|
65
|
+
(测试总数 113 → 115)
|
|
66
|
+
|
|
8
67
|
## [0.4.2] - 2026-09-30
|
|
9
68
|
|
|
10
69
|
### Fixed
|
|
@@ -94,6 +153,8 @@
|
|
|
94
153
|
JSON 编辑、宿主路由、bundle 加载、profile 组合与真实 profile 只读验证;
|
|
95
154
|
另附 e2e 导入、往返校验、图标预览等辅助脚本
|
|
96
155
|
|
|
156
|
+
[0.4.4]: https://github.com/appthin/dsh-mcp-manager-plus/compare/v0.4.3...v0.4.4
|
|
157
|
+
[0.4.3]: https://github.com/appthin/dsh-mcp-manager-plus/compare/v0.4.2...v0.4.3
|
|
97
158
|
[0.4.2]: https://github.com/appthin/dsh-mcp-manager-plus/compare/v0.4.1...v0.4.2
|
|
98
159
|
[0.4.1]: https://github.com/appthin/dsh-mcp-manager-plus/compare/v0.4.0...v0.4.1
|
|
99
160
|
[0.4.0]: https://github.com/appthin/dsh-mcp-manager-plus/compare/v0.3.1...v0.4.0
|
package/README.en.md
CHANGED
|
@@ -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
|
|
package/README.md
CHANGED
|
@@ -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
|
|
package/lib/client.js
CHANGED
|
@@ -221,8 +221,11 @@ window.__ModuleLoader__.load({
|
|
|
221
221
|
'.mcpmp-btn{display:inline-flex;align-items:center;justify-content:center;gap:6px;height:30px;padding:0 12px;border-radius:8px;border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-primary);font-size:12px;cursor:pointer;white-space:nowrap}',
|
|
222
222
|
'.mcpmp-btn:hover:not(:disabled){background:var(--dsw-alias-bg-layer-2)}',
|
|
223
223
|
'.mcpmp-btn:disabled{opacity:.5;cursor:not-allowed}',
|
|
224
|
-
|
|
225
|
-
|
|
224
|
+
// The primary fill flips with the theme — dark in the light theme,
|
|
225
|
+
// near-white in the dark one — so its label must come from the matching
|
|
226
|
+
// token. A literal white was invisible on the dark theme's fill.
|
|
227
|
+
'.mcpmp-btn-primary{background:var(--dsw-alias-button-primary-fill,var(--dsw-alias-brand-primary));border-color:transparent;color:var(--dsw-alias-label-primary-foreground,var(--dsw-alias-label-primary-inverted,#fff))}',
|
|
228
|
+
'.mcpmp-btn-primary:hover:not(:disabled){background:var(--dsw-alias-button-primary-hover,var(--dsw-alias-button-primary-fill,var(--dsw-alias-brand-primary)))}',
|
|
226
229
|
'.mcpmp-btn-danger{color:var(--dsw-alias-state-error-primary)}',
|
|
227
230
|
'.mcpmp-btn-sm{height:26px;padding:0 9px;font-size:12px}',
|
|
228
231
|
'.mcpmp-icon{width:30px;padding:0}',
|
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. */
|
|
@@ -275,11 +251,27 @@ function resolvePatchPath(ctx) {
|
|
|
275
251
|
return { patchPath: join(profileDir, 'cordis.patch.yml'), profileDir };
|
|
276
252
|
}
|
|
277
253
|
|
|
278
|
-
/**
|
|
254
|
+
/**
|
|
255
|
+
* Resolve a `file://` URL to a native path; a plain path is returned untouched.
|
|
256
|
+
*
|
|
257
|
+
* `new URL(value).pathname` keeps percent-encoding, which is what broke DSH
|
|
258
|
+
* Desktop: it hands over the include path as a file URL, so an install
|
|
259
|
+
* directory containing a space arrived as `DeepSeek%20Harness`, named a file
|
|
260
|
+
* that does not exist, and the writability probe below then reported the patch
|
|
261
|
+
* file as read-only. `fileURLToPath` decodes `%20` (and every other escape)
|
|
262
|
+
* and normalizes the Windows drive-letter slash and UNC hosts.
|
|
263
|
+
* @param value - a `file://` URL or a native path.
|
|
264
|
+
* @returns the native path.
|
|
265
|
+
*/
|
|
279
266
|
function fromFileUrl(value) {
|
|
280
267
|
if (!value.startsWith('file://')) return value;
|
|
281
268
|
try {
|
|
282
|
-
|
|
269
|
+
return fileURLToPath(value);
|
|
270
|
+
} catch {
|
|
271
|
+
// A malformed URL falls through to the manual parse.
|
|
272
|
+
}
|
|
273
|
+
try {
|
|
274
|
+
const path = decodeURIComponent(new URL(value).pathname);
|
|
283
275
|
// Windows file URLs carry a leading slash before the drive letter.
|
|
284
276
|
return /^\/[A-Za-z]:/u.test(path) ? path.slice(1) : path;
|
|
285
277
|
} catch {
|
|
@@ -999,9 +991,13 @@ export function apply(ctx) {
|
|
|
999
991
|
if (cache !== null && now - cache.at < CACHE_TTL_MS && cache.patchPath === patchPath) {
|
|
1000
992
|
return cache.value;
|
|
1001
993
|
}
|
|
1002
|
-
const { yaml, schema } = await loadYaml(ctx);
|
|
994
|
+
const { yaml, schema, degraded, source } = await loadYaml(ctx);
|
|
1003
995
|
const document = readDocument(readPatchText(patchPath), yaml, schema);
|
|
1004
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 }));
|
|
1005
1001
|
// Report writability before an edit rather than after one fails. Probing
|
|
1006
1002
|
// the directory covers a patch file that does not exist yet; probing the
|
|
1007
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.4",
|
|
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",
|