@linxin666/dsh-client-ui-plugin-manager 0.4.6 → 0.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.i18n.yaml +2 -2
- package/README.md +3 -3
- package/README.zh.md +3 -3
- package/lib/client.js +1 -1
- package/lib/index.js +415 -50
- package/lib/types/host/gateway.d.ts +161 -6
- package/lib/types/host/rows.d.ts +32 -0
- package/package.json +15 -15
package/README.i18n.yaml
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
|
3
3
|
# after editing either side, bring the other along and re-record with:
|
|
4
4
|
# node scripts/verify-docs.mjs --write <dir>
|
|
5
|
-
README.md:
|
|
6
|
-
README.zh.md:
|
|
5
|
+
README.md: dc8c77b9f1423ef1444777ee7a40313ff30a89bc
|
|
6
|
+
README.zh.md: 018d1b32436acdb60cca31062d98a0076f97f00a
|
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ English | [中文](README.zh.md)
|
|
|
5
5
|
<p align="center">
|
|
6
6
|
<img src="https://img.shields.io/npm/v/@linxin666/dsh-client-ui-plugin-manager?style=flat-square" alt="Version">
|
|
7
7
|
|
|
8
|
-
<img src="https://img.shields.io/badge/DSH-%3E%3D0.2.
|
|
8
|
+
<img src="https://img.shields.io/badge/DSH-%3E%3D0.2.1--rc.2-4c6ef5?style=flat-square&labelColor=454a54" alt="DSH">
|
|
9
9
|
|
|
10
10
|
<img src="https://img.shields.io/badge/license-Apache--2.0-blue?style=flat-square" alt="License">
|
|
11
11
|
</p>
|
|
@@ -68,7 +68,7 @@ The contract source of truth is `src/core/service.ts` (`PluginManagerService`).
|
|
|
68
68
|
|
|
69
69
|
- Loopback-only: on a LAN or remote browser the update block renders a local-only notice (the same boundary the official installer page enforces; the gateway refuses non-loopback requests with 403).
|
|
70
70
|
- On the npm-published web runtime, gateway writes go through the official CLI. The gateway resolves `dsh` from the host process PATH first, then from `node_modules/.bin` project roots above the running host entry, then from the running host package's own `lib/bin.js`, and finally from the packaged Desktop install's own CLI launcher under the Electron resource directory (`runtime/cli/bin/dsh.cmd` on Windows, `runtime/cli/bin/dsh` elsewhere) — the last one covers a packaged Desktop, where the host runs from inside `app.asar`, the private host package ships no `lib/bin.js`, every `.bin` shim directory is stripped from the installer, and the launcher puts only the bundled `node` on the host's PATH. A Node-script CLI (an npm or homebrew shim, a `.bin` symlink, a `lib/bin.js`) runs under an interpreter resolved without PATH: the `node` installed beside the CLI when the installation ships one, otherwise the host's own interpreter. The CLI's own directory goes first on the child PATH, so the `dsh plugin` run finds the pnpm installed beside it. If no source contains the CLI, CLI-backed writes remain unavailable — an application-owned profile writes through the official in-process manager and needs no binary, so its install, update and removal routes never demand one. CLI output is decoded as bytes in one pass, so a Windows console's code page (CP936/GBK) renders as readable text instead of replacement characters. Installs of git sources can take minutes and run as background jobs. Gateway updates apply only to npm registry sources, resolve the latest version on the host, and succeed only after the same installed package reports that exact version.
|
|
71
|
-
- An application-owned profile (the packaged Desktop client) runs installs, updates and removals through the official in-process plugin manager the host mounts, the same writer that profile's official Plugins page drives: the CLI refuses `--profile desktop` outright, and the launcher hands that manager its bundled package-manager invocation. The job, its status polling and its verification are identical to the CLI path — an install must add a dependency the profile did not carry, a removal must drop one, and an update must still report the version the route resolved — while the CLI-specific guards (duplicate-mount stripping, insert-row and boot preflight) stay with the CLI writer, because there the official manager validates and applies the bundle itself. The manager's own verdict is read before the profile is: it resolves a refused run with `application: 'failed'` instead of rejecting, so the job reports that run's real reason (the pnpm diagnostic, or the packages an incompatible-version refusal names) rather than a no-op after an unchanged profile. Every other runtime keeps the CLI as the single writer of installs, updates and removals.
|
|
71
|
+
- An application-owned profile (the packaged Desktop client) runs installs, updates and removals through the official in-process plugin manager the host mounts, the same writer that profile's official Plugins page drives: the CLI refuses `--profile desktop` outright, and the launcher hands that manager its bundled package-manager invocation. The job, its status polling and its verification are identical to the CLI path — an install must add a dependency the profile did not carry, a removal must drop one, and an update must still report the version the route resolved — while the CLI-specific guards (duplicate-mount stripping, insert-row and boot preflight) stay with the CLI writer, because there the official manager validates and applies the bundle itself. The manager's own verdict is read before the profile is: it resolves a refused run with `application: 'failed'` instead of rejecting, so the job reports that run's real reason (the pnpm diagnostic, or the packages an incompatible-version refusal names) rather than a no-op after an unchanged profile. Since 0.2.1-rc.2 that manager also refuses to install a dependency the profile already carries while the host mounts `hmr` — every profile host — so an update there runs as its two phases instead: remove the installed bundle, then install the target spec through the same manager, and a second phase that fails reinstalls the spec the profile carried before the run, so a failed update leaves a working plugin rather than an empty slot. The single call stays first, so an upstream in-place update would need no change here. Every other runtime keeps the CLI as the single writer of installs, updates and removals.
|
|
72
72
|
- Compatibility gating applies only when the target manifest declares a minimum DSH version; packages without `dsh.engines.dsh` update unchecked, and official-installer runtimes (DSHCode and the checkout web) are not gated here because their updates go through the official installer. The running DSH version is read from the installation's own `@deepseek-ai/dsh` manifest, which the launcher publishes as the profile's install anchor — no subprocess, no PATH, and therefore an answer on a packaged Desktop host — with `dsh --version` kept as the fallback for a runtime that publishes no anchor. A requirement the host cannot verify at all is reported as unverified rather than as a version below the minimum: both hold the update back, but only the second sends the user to upgrade DSH.
|
|
73
73
|
- Enablement on the npm runtime reports the effective next-start value: a profile override row wins where present, otherwise the installed bundle's own `disabled` rows decide (the aggregate's inactive-by-default families), and rows no layer mentions are enabled. Enabling a row the bundle disables writes an explicit `disabled: false` override, because deleting the user row would only restore the bundle default; the runtime's loader honors these rows at the next start, but this path is less exercised than the official desktop writer's.
|
|
74
74
|
- Restart is explicit, user-clicked and three-mode. The route is method-aware: `GET /api/plugin-manager/restart` reads the plan (no side effects, so a prefetch or a typed URL can never stop a host) and `POST` carries it out; every other method is refused with 405. The toolbar reads the plan first, so the confirmation names the same consequence the host will produce. On a terminal launch (`dsh web`) the host starts a detached helper that waits for the outgoing process to exit and then re-executes the same command line, so the port is free before the replacement binds it, and the replacement's output goes to `$DSH_HOME/logs/plugin-manager-restart.log`. Under the packaged Desktop app the plugin cannot relaunch anything — Electron owns the process tree, a detached respawn would fight the shell for the same port, and the shell's own recovery dialog is the only restart it offers — so that confirmation says what its dialog does before running it: confirming stops the host, the shell shows its error-titled dialog, and the dialog's Restart finishes `app.relaunch()` (a crash report is written with it); the manual way out, quitting DeepSeek Harness and opening it again, is named beside it. A launch with no terminal (a supervisor, an editor task) is left running and the toolbar says to restart manually. Without a restart, updated plugin code is loaded at the next start.
|
|
@@ -81,7 +81,7 @@ The contract source of truth is `src/core/service.ts` (`PluginManagerService`).
|
|
|
81
81
|
|
|
82
82
|
- Trust boundary is the loopback fence: every gateway route requires a loopback socket address, a loopback Host header, and a non-cross-site origin (socket + Host + Origin + `sec-fetch-site`), the same authority the official installer channels enforce. There is no browser-reachable path from a remote origin; rejected requests receive HTTP 403 with `{ ok: false, error: "forbidden: loopback-only" }`.
|
|
83
83
|
- Mutation routes (install / update / remove / set-enabled / restart) carry no token: the loopback authority *is* the local user, matching the official channels. The restart route is the one route whose effect is process-level: it never invents a command line (it re-executes this process's own `execPath` + argv, dropping inspector flags), it refuses to relaunch anything it cannot identify as a terminal launch, and under the packaged Desktop app it only stops this process so the shell decides what happens next. Any local process can therefore drive plugin installs and removals, and npm installs run package install scripts — treat the gateway as local code execution by design and never expose it beyond loopback.
|
|
84
|
-
- Install specs and package ids are rejected when they contain command-shell expansion characters or control characters. On Windows, npm shims are resolved to `node.exe` plus the package `bin.js`; packaged Desktop shims have no adjacent npm layout, so they run through `cmd.exe /d /s /c` with a pre-quoted, verbatim argument envelope. Desktop profile discovery reads the packaged launcher's profile environment value or persisted profile selection, and application-owned profile installs, updates and removals run in the host half through the mounted official `pluginManager` service — the same writer that profile's official Plugins page drives through its own RPC face — under the same loopback fence and user click.
|
|
84
|
+
- Install specs and package ids are rejected when they contain command-shell expansion characters or control characters. On Windows, npm shims are resolved to `node.exe` plus the package `bin.js`; packaged Desktop shims have no adjacent npm layout, so they run through `cmd.exe /d /s /c` with a pre-quoted, verbatim argument envelope. That command processor is addressed by absolute path (`ComSpec`, otherwise `%SystemRoot%\System32\cmd.exe`) instead of by bare name, so a host whose PATH omits the system directories still runs the shim; a spawn that still fails settles as a failed job carrying the reason instead of taking the dsh host process down. Desktop profile discovery reads the packaged launcher's profile environment value or persisted profile selection, and application-owned profile installs, updates and removals run in the host half through the mounted official `pluginManager` service — the same writer that profile's official Plugins page drives through its own RPC face — under the same loopback fence and user click.
|
|
85
85
|
- Mutations are serialized through one queue, so concurrent jobs never interleave their before/after profile captures. An install is only `done` when the new dependency actually landed in the profile (and a removal only when it is gone); a success exit code alone is never trusted.
|
|
86
86
|
- Enablement re-reads the current profile manifest under that mutation queue and rejects stale or unknown package ids with `404` before writing, so a panel row left behind by an uninstall cannot create an orphan `disabled` override.
|
|
87
87
|
- Conflict handling is owner-aware: a duplicate entry id or an insert row naming an unresolvable package rolls the *new* package back through the official remove path. The gateway never writes `disabled` rows for a shared id (such rows cannot stop the loader's duplicate check and would flag the existing owner).
|
package/README.zh.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<p align="center">
|
|
6
6
|
<img src="https://img.shields.io/npm/v/@linxin666/dsh-client-ui-plugin-manager?style=flat-square" alt="Version">
|
|
7
7
|
|
|
8
|
-
<img src="https://img.shields.io/badge/DSH-%3E%3D0.2.
|
|
8
|
+
<img src="https://img.shields.io/badge/DSH-%3E%3D0.2.1--rc.2-4c6ef5?style=flat-square&labelColor=454a54" alt="DSH">
|
|
9
9
|
|
|
10
10
|
<img src="https://img.shields.io/badge/license-Apache--2.0-blue?style=flat-square" alt="License">
|
|
11
11
|
</p>
|
|
@@ -68,7 +68,7 @@ dsh plugin --profile web add link:$(pwd)/packages/dsh-plugin-manager
|
|
|
68
68
|
|
|
69
69
|
- 仅限本机:LAN 或远程浏览器只显示「仅限本机操作」提示(与官方安装器页同一边界;网关对非 loopback 请求返回 403)。
|
|
70
70
|
- npm 发布的官方 web 上,网关写入经官方 CLI 执行。网关先从 host 进程 PATH 解析 `dsh`,再从运行中 host 入口上层各项目根的 `node_modules/.bin` 回退查找,然后回退到运行中 host 包自身的 `lib/bin.js`,最后回退到桌面安装包自带的 CLI 启动器(位于 Electron 资源目录下:Windows 为 `runtime/cli/bin/dsh.cmd`,其他平台为 `runtime/cli/bin/dsh`)——最后这条覆盖打包桌面端:host 从 `app.asar` 内运行、私有 host 包不带 `lib/bin.js`、安装包剥除所有 `.bin` shim 目录,且启动器只把自带的 `node` 放进 host 的 PATH;Node 脚本形式的 CLI(npm/homebrew shim、`.bin` 符号链接、`lib/bin.js`)由不依赖 PATH 的解释器执行——安装包里 CLI 旁有 `node` 时用它,否则用 host 自身的解释器;CLI 所在目录放在子进程 PATH 首位,使 `dsh plugin` 运行能找到同处安装的 pnpm。全部来源都没有 CLI 时,走 CLI 的写入才不可用——应用自有 profile 由官方进程内管理器写入,不需要任何二进制,其安装、更新与卸载路由也不要求它。CLI 输出按字节一次性解码,Windows 中文控制台(CP936/GBK)的报错文本可读而不再是替换字符。git 源安装可能耗时数分钟,以后台任务运行。网关更新只适用于 npm registry 源,由 host 解析最新版本,且仅当同一已装包报告该精确版本时才算成功。
|
|
71
|
-
- 应用自有 profile(打包桌面客户端)的安装、更新与卸载走宿主挂载的官方进程内插件管理器——即该 profile 官方插件页所用的同一个写入器:CLI 直接拒绝 `--profile desktop`,启动器则把自带的包管理器调用交给该管理器。任务、状态轮询与校验与 CLI 路径一致:安装必须新增一条此前没有的依赖、卸载必须删除一条依赖、更新必须报告路由解析出的版本;而 CLI 专属的守卫(重复挂载剥离、insert 行与启动预检)仍留在 CLI 写入器一侧,因为该路径下官方管理器会自行校验并应用 bundle。管理器返回的判定会先于 profile 被读取:被拒绝的运行以 `application: 'failed'` 解析而不是抛错,因此任务上报该运行的真实原因(pnpm 诊断文本,或 `incompatible-version` 拒绝点名的包),而不是在 profile
|
|
71
|
+
- 应用自有 profile(打包桌面客户端)的安装、更新与卸载走宿主挂载的官方进程内插件管理器——即该 profile 官方插件页所用的同一个写入器:CLI 直接拒绝 `--profile desktop`,启动器则把自带的包管理器调用交给该管理器。任务、状态轮询与校验与 CLI 路径一致:安装必须新增一条此前没有的依赖、卸载必须删除一条依赖、更新必须报告路由解析出的版本;而 CLI 专属的守卫(重复挂载剥离、insert 行与启动预检)仍留在 CLI 写入器一侧,因为该路径下官方管理器会自行校验并应用 bundle。管理器返回的判定会先于 profile 被读取:被拒绝的运行以 `application: 'failed'` 解析而不是抛错,因此任务上报该运行的真实原因(pnpm 诊断文本,或 `incompatible-version` 拒绝点名的包),而不是在 profile 未变之后给出一句空转文案。自 0.2.1-rc.2 起,该管理器在宿主挂载 `hmr` 时还会拒绝安装 profile 已携带的依赖——而那是每个 profile 宿主——因此那里的更新改为按两个阶段执行:先移除已安装的组合包,再用同一个管理器安装目标 spec;第二阶段失败时,装回运行前 profile 携带的 spec,使失败的更新留下可用的插件而不是空槽。单次调用仍排在最前,因此上游哪天接受原地更新,这里无需改动。其余运行时的安装、更新与卸载仍以 CLI 为唯一写入器。
|
|
72
72
|
- 兼容性门禁只在目标清单声明了最低 DSH 版本时生效;未声明 `dsh.engines.dsh` 的包更新不被检查,官方安装器运行时(DSHCode 与 checkout 版 web)不经过本门禁(其更新走官方安装器)。运行中的 DSH 版本读取安装自身的 `@deepseek-ai/dsh` 清单——启动器把它作为 profile 的 install anchor 发布——无需子进程、无需 PATH,因此打包桌面端也能作答;运行时不发布 anchor 时回退到 `dsh --version`。宿主完全无法核验的要求按「无法确认」呈现,而不是报成低于下限:两者都拦住更新,但只有后者会让用户去升级 DSH。
|
|
73
73
|
- npm 运行时上的启停显示下次启动的真实生效值:profile 覆盖行优先,其次由所装 bundle 自带的 `disabled` 行决定(聚合包的按需开启家族),两层都未提及的行视为启用。开启一个被 bundle 停用的行会写入显式 `disabled: false` 覆盖行——只删除用户行只会退回 bundle 默认值;该运行时 loader 在下次启动时认读这些行,但这条路径不如官方桌面写入器经过充分锻炼。
|
|
74
74
|
- 重启是显式、需用户点击且有三种模式的动作,路由按方法区分:`GET /api/plugin-manager/restart` 只读「重启方案」(无副作用,因此浏览器预取或直接输入 URL 都不会停掉宿主),`POST` 才执行;其他方法一律 405 拒绝。工具条先读方案,确认面板说的后果与实际执行的一致。终端启动(`dsh web`)时宿主启动一个 detached helper:等旧进程退出后按原命令行重新拉起,端口先释放再被替换进程绑定,替换进程的输出写入 `$DSH_HOME/logs/plugin-manager-restart.log`。打包桌面应用下本插件无法重启任何东西——进程树归 Electron,detached 重拉只会与桌面外壳抢同一端口,而外壳只提供它自己的恢复对话框这一条重启路径——因此那里的确认面板会先写明该对话框会做什么:确认后宿主退出,外壳弹出错误样式的「应用无法启动或已意外停止」对话框,在对话框里点「重启」即完成 `app.relaunch()`(同时写一份崩溃报告);旁边给出替代路径——退出 DeepSeek Harness 后重新打开。无终端的启动(受监督进程、编辑器任务)保持不动,工具条提示手动重启。不重启时,更新后的插件代码在下次启动生效。
|
|
@@ -81,7 +81,7 @@ dsh plugin --profile web add link:$(pwd)/packages/dsh-plugin-manager
|
|
|
81
81
|
|
|
82
82
|
- 信任边界是 loopback 门禁:每条网关路由都要求 loopback socket 地址、loopback Host 头与非跨站来源(socket + Host + Origin + `sec-fetch-site` 四重),与官方安装器通道同一权威。远程来源的浏览器没有可达路径;被拒请求返回 HTTP 403 与 `{ ok: false, error: "forbidden: loopback-only" }`。
|
|
83
83
|
- 变更类路由(install / update / remove / set-enabled / restart)不带 token:loopback 权威即本机用户,与官方通道同模型。重启路由是唯一作用在进程层面的路由:它绝不臆造命令行(只重放本进程自身的 `execPath` + argv,并剔除 inspector 开关),对无法确认为终端启动的宿主拒绝重拉,在打包桌面应用下只让本进程退出而把后续交给外壳。因此任何本机进程都能驱动插件安装与卸载,且 npm 安装会执行包的 install 脚本——请将本网关视为「设计上即本机代码执行」,绝不暴露到 loopback 之外。
|
|
84
|
-
- 安装 spec 与包 id 含命令行展开字符或控制字符时一律拒绝。Windows 下,npm shim 会解析为 `node.exe` 加包内 `bin.js`;DSH Desktop 打包 shim 附近没有 npm 布局,因此通过带完整预引用、逐字参数封套的 `cmd.exe /d /s /c`
|
|
84
|
+
- 安装 spec 与包 id 含命令行展开字符或控制字符时一律拒绝。Windows 下,npm shim 会解析为 `node.exe` 加包内 `bin.js`;DSH Desktop 打包 shim 附近没有 npm 布局,因此通过带完整预引用、逐字参数封套的 `cmd.exe /d /s /c` 执行;该命令解释器按绝对路径定位(`ComSpec`,其次 `%SystemRoot%\System32\cmd.exe`)而不再依赖裸名的 PATH 查找,因此 PATH 缺系统目录的宿主仍能执行 shim;若 spawn 仍失败,则该次作业以失败结算并带出原因,绝不带走 dsh 宿主进程。桌面 profile 从打包启动器环境值或持久化的 profile 选择中读取;应用自有 profile 的安装、更新与卸载由 host 半区直接调用宿主挂载的官方 `pluginManager` 服务(与官方插件页经自身 RPC 面驱动的是同一个写入器),其权威同样是 loopback 门禁加用户点击。
|
|
85
85
|
- 变更经同一队列串行,并发任务的 before/after profile 快照绝不交错。安装只有在依赖真实落入 profile 后才判 done(卸载以依赖消失为准),绝不轻信成功退出码。
|
|
86
86
|
- 启停操作会在该变更队列内重新读取最新 profile 清单,并在写入前以 `404` 拒绝过期或未知的包 id,因此卸载后遗留在面板里的旧行不会制造孤儿 `disabled` 覆盖。
|
|
87
87
|
- 冲突处置是 owner-aware 的:重复入口 id 或引用不可解析包的 insert 行会经官方 remove 路径回滚**新**包;网关绝不对共享 id 写 `disabled` 行(那既阻止不了 loader 的重复检查,又会误伤现有插件)。
|
package/lib/client.js
CHANGED
package/lib/index.js
CHANGED
|
@@ -431,6 +431,81 @@ function setRowEnabled(text, filename, id, name, enabled, baseEnabled = true) {
|
|
|
431
431
|
}));
|
|
432
432
|
return document.toString({ lineWidth: 0 }) + "\n";
|
|
433
433
|
}
|
|
434
|
+
/** The complete key set of an enablement override row this package writes. */
|
|
435
|
+
const OVERRIDE_ROW_KEYS = /* @__PURE__ */ new Set([
|
|
436
|
+
"id",
|
|
437
|
+
"name",
|
|
438
|
+
"disabled"
|
|
439
|
+
]);
|
|
440
|
+
/**
|
|
441
|
+
* The entry id of an enablement override row this package owns, when the item
|
|
442
|
+
* is one: a bare row carrying a string `id`, a boolean `disabled`, and no
|
|
443
|
+
* other key. Anything else is somebody else's row — a config row carrying
|
|
444
|
+
* options, a row with an unknown shape, an insert wrapper — and the manager
|
|
445
|
+
* never edits or removes it.
|
|
446
|
+
* @param item - one top-level patch item.
|
|
447
|
+
* @returns the override's entry id, or undefined when the item is not ours.
|
|
448
|
+
*/
|
|
449
|
+
function overrideRowId(item) {
|
|
450
|
+
if (!isBareRow(item)) return void 0;
|
|
451
|
+
const id = bareRowId(item);
|
|
452
|
+
if (id === void 0) return void 0;
|
|
453
|
+
const disabled = item.get("disabled", true);
|
|
454
|
+
if (!(isScalar(disabled) && typeof disabled.value === "boolean")) return void 0;
|
|
455
|
+
for (const pair of item.items) {
|
|
456
|
+
const key = pair.key;
|
|
457
|
+
if (!isScalar(key) || !OVERRIDE_ROW_KEYS.has(String(key.value))) return void 0;
|
|
458
|
+
}
|
|
459
|
+
return id;
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Drop this package's own enablement overrides whose entry id the composed
|
|
463
|
+
* profile no longer carries — a retired row leaves a stale override behind,
|
|
464
|
+
* which the loader reports on every boot as `patch: entry "<id>" not found`.
|
|
465
|
+
* The prunable set is decided by the caller from the composed entry ids: an
|
|
466
|
+
* id the composition does not carry has no row left to override. Only rows
|
|
467
|
+
* {@link overrideRowId} recognizes are removed, comments and every other row
|
|
468
|
+
* are kept, and an already-pruned file returns its input text unchanged so the
|
|
469
|
+
* caller can skip the write entirely.
|
|
470
|
+
* @param text - current patch file text.
|
|
471
|
+
* @param filename - absolute path (diagnostics only).
|
|
472
|
+
* @param composedIds - the entry ids the composed profile carries.
|
|
473
|
+
* @returns the rewritten text and the pruned ids.
|
|
474
|
+
*/
|
|
475
|
+
function pruneOrphanRowOverrides(text, filename, composedIds) {
|
|
476
|
+
const { document, root } = parsePatch(text, filename);
|
|
477
|
+
const pruned = [];
|
|
478
|
+
for (let index = root.items.length - 1; index >= 0; index -= 1) {
|
|
479
|
+
const item = root.items[index];
|
|
480
|
+
const id = overrideRowId(item);
|
|
481
|
+
if (id === void 0 || composedIds.has(id)) continue;
|
|
482
|
+
pruned.unshift(id);
|
|
483
|
+
const comment = isMap(item) ? item.commentBefore : void 0;
|
|
484
|
+
root.items.splice(index, 1);
|
|
485
|
+
if (comment === void 0 || comment === null || comment === "") continue;
|
|
486
|
+
const next = root.items[index];
|
|
487
|
+
if (isMap(next) || isSeq(next)) next.commentBefore = appendComment(comment, next.commentBefore);
|
|
488
|
+
else document.comment = appendComment(comment, document.comment);
|
|
489
|
+
}
|
|
490
|
+
if (pruned.length === 0) return {
|
|
491
|
+
text,
|
|
492
|
+
pruned
|
|
493
|
+
};
|
|
494
|
+
const serialized = document.toString({ lineWidth: 0 });
|
|
495
|
+
return {
|
|
496
|
+
text: `${serialized.endsWith("\n") ? serialized.slice(0, -1) : serialized}${text.endsWith("\n") ? "\n" : ""}`,
|
|
497
|
+
pruned
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* One node's comment block followed by another's.
|
|
502
|
+
* @param first - the comment block to keep first.
|
|
503
|
+
* @param second - the existing block, when there is one.
|
|
504
|
+
* @returns the combined block.
|
|
505
|
+
*/
|
|
506
|
+
function appendComment(first, second) {
|
|
507
|
+
return second === void 0 || second === null || second === "" ? first : `${first}\n${second}`;
|
|
508
|
+
}
|
|
434
509
|
//#endregion
|
|
435
510
|
//#region src/host/bundle-guard.ts
|
|
436
511
|
/**
|
|
@@ -1290,6 +1365,47 @@ function dshSpawnCommand(binary, platform = process.platform, localNodeExists =
|
|
|
1290
1365
|
argsPrefix: [binJs]
|
|
1291
1366
|
};
|
|
1292
1367
|
}
|
|
1368
|
+
/** The Windows directory used when the environment names no system root at all. */
|
|
1369
|
+
const WINDOWS_ROOT_FALLBACK = "C:\\Windows";
|
|
1370
|
+
/**
|
|
1371
|
+
* Read one environment variable by name, case-insensitively, ignoring blank
|
|
1372
|
+
* values. Windows spells the same variable `ComSpec` and `comspec` depending on
|
|
1373
|
+
* who wrote it (a launcher, a service, the user's own shell), and a plain
|
|
1374
|
+
* object seam carries whatever spelling the caller built.
|
|
1375
|
+
* @param env - the environment to read.
|
|
1376
|
+
* @param name - the variable name, matched without regard to case.
|
|
1377
|
+
* @returns the first non-blank value, or undefined.
|
|
1378
|
+
*/
|
|
1379
|
+
function envValue(env, name) {
|
|
1380
|
+
const wanted = name.toUpperCase();
|
|
1381
|
+
for (const [key, value] of Object.entries(env)) {
|
|
1382
|
+
if (typeof value !== "string" || value.trim() === "") continue;
|
|
1383
|
+
if (key.toUpperCase() === wanted) return value;
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
/**
|
|
1387
|
+
* Absolute path of the Windows command processor, resolved from an environment
|
|
1388
|
+
* rather than from PATH.
|
|
1389
|
+
*
|
|
1390
|
+
* Every `.cmd` shim still has to be executed through cmd.exe, and a bare
|
|
1391
|
+
* `cmd.exe` spawn resolves through the host PATH: a GUI-launched host whose PATH
|
|
1392
|
+
* carries no `%SystemRoot%\system32` (a packaged Desktop launch, a service, a
|
|
1393
|
+
* stripped environment) gets ENOENT for a name that is present on disk, and the
|
|
1394
|
+
* whole feature fails with it (issue #1857). ComSpec is the variable Windows
|
|
1395
|
+
* itself uses for this and names the real binary, so it is preferred; otherwise
|
|
1396
|
+
* the system root is read from `SystemRoot` or `windir`, with the conventional
|
|
1397
|
+
* `C:\Windows` as the last resort.
|
|
1398
|
+
*
|
|
1399
|
+
* Only the Windows branch needs it — a POSIX host spawns the CLI directly.
|
|
1400
|
+
* @param env - the environment to resolve from.
|
|
1401
|
+
* @returns the absolute cmd.exe path.
|
|
1402
|
+
*/
|
|
1403
|
+
function windowsCmdPath(env = process.env) {
|
|
1404
|
+
const comSpec = envValue(env, "ComSpec");
|
|
1405
|
+
if (comSpec !== void 0) return comSpec;
|
|
1406
|
+
const root = envValue(env, "SystemRoot") ?? envValue(env, "windir") ?? WINDOWS_ROOT_FALLBACK;
|
|
1407
|
+
return win32.join(root, "System32", "cmd.exe");
|
|
1408
|
+
}
|
|
1293
1409
|
/** Build the exact cmd.exe command line required to execute a trusted .cmd shim. */
|
|
1294
1410
|
function windowsCmdShimArgs(binary, args) {
|
|
1295
1411
|
const unsafe = /[&|<>"'`%!\n\r\0]/;
|
|
@@ -1320,6 +1436,105 @@ function withPrependedPath(env, dir, platform = process.platform) {
|
|
|
1320
1436
|
next.PATH = current === "" ? dir : `${dir}${separator}${current}`;
|
|
1321
1437
|
return next;
|
|
1322
1438
|
}
|
|
1439
|
+
/** The spawn failure recorded on a guarded child, read by {@link awaitChildExit}. */
|
|
1440
|
+
const SPAWN_FAILURE = /* @__PURE__ */ new WeakMap();
|
|
1441
|
+
/**
|
|
1442
|
+
* Whether an emitted error is a spawn failure rather than a later lifecycle
|
|
1443
|
+
* failure (a kill that did not land, a closed stdio pipe). Only a spawn failure
|
|
1444
|
+
* means the child will never close on its own.
|
|
1445
|
+
* @param error - the emitted error.
|
|
1446
|
+
* @returns true when no process was ever created.
|
|
1447
|
+
*/
|
|
1448
|
+
function isSpawnFailure(error) {
|
|
1449
|
+
if (typeof error !== "object" || error === null) return false;
|
|
1450
|
+
const syscall = error.syscall;
|
|
1451
|
+
return typeof syscall === "string" && syscall.startsWith("spawn");
|
|
1452
|
+
}
|
|
1453
|
+
/**
|
|
1454
|
+
* The operator-facing text of one spawn failure.
|
|
1455
|
+
* @param error - the emitted error.
|
|
1456
|
+
* @returns a readable one-line reason.
|
|
1457
|
+
*/
|
|
1458
|
+
function spawnFailureText(error) {
|
|
1459
|
+
return "plugin-manager: 无法启动子进程(" + (error instanceof Error ? error.message : String(error)) + ")";
|
|
1460
|
+
}
|
|
1461
|
+
/**
|
|
1462
|
+
* Attach the error fallback every spawn outlet needs.
|
|
1463
|
+
*
|
|
1464
|
+
* A ChildProcess without an `error` listener turns a spawn failure into an
|
|
1465
|
+
* unhandled `error` event, which is an uncaught exception: the failure of one
|
|
1466
|
+
* CLI call took the whole dsh host process down with it. This records the
|
|
1467
|
+
* reason and, when the child never closed, settles it as a failed exit so a
|
|
1468
|
+
* caller that only waits for `close` neither hangs nor crashes (issue #1857).
|
|
1469
|
+
* @param child - the spawned child.
|
|
1470
|
+
* @returns the same child, guarded.
|
|
1471
|
+
*/
|
|
1472
|
+
function guardSpawnFailure(child) {
|
|
1473
|
+
let closed = false;
|
|
1474
|
+
child.on("close", () => {
|
|
1475
|
+
closed = true;
|
|
1476
|
+
});
|
|
1477
|
+
child.on("error", (error) => {
|
|
1478
|
+
if (!isSpawnFailure(error)) return;
|
|
1479
|
+
SPAWN_FAILURE.set(child, spawnFailureText(error));
|
|
1480
|
+
if (closed) return;
|
|
1481
|
+
closed = true;
|
|
1482
|
+
child.emit("close", -1, null);
|
|
1483
|
+
});
|
|
1484
|
+
return child;
|
|
1485
|
+
}
|
|
1486
|
+
/**
|
|
1487
|
+
* Wait for a spawned child to close, settling on a spawn failure as well.
|
|
1488
|
+
*
|
|
1489
|
+
* The listener pair is attached to every child this package waits on, so the
|
|
1490
|
+
* wait is safe for a child that arrived through a seam ({@link guardSpawnFailure}
|
|
1491
|
+
* guards the real spawn outlets, an injected one may skip it).
|
|
1492
|
+
* @param child - the spawned child.
|
|
1493
|
+
* @returns the exit verdict.
|
|
1494
|
+
*/
|
|
1495
|
+
async function awaitChildExit(child) {
|
|
1496
|
+
return new Promise((resolve) => {
|
|
1497
|
+
let settled = false;
|
|
1498
|
+
const finish = (code) => {
|
|
1499
|
+
if (settled) return;
|
|
1500
|
+
settled = true;
|
|
1501
|
+
const spawnError = SPAWN_FAILURE.get(child);
|
|
1502
|
+
resolve(spawnError === void 0 ? { code } : {
|
|
1503
|
+
code,
|
|
1504
|
+
spawnError
|
|
1505
|
+
});
|
|
1506
|
+
};
|
|
1507
|
+
child.on("close", (code) => {
|
|
1508
|
+
finish(code);
|
|
1509
|
+
});
|
|
1510
|
+
child.on("error", () => {
|
|
1511
|
+
finish(-1);
|
|
1512
|
+
});
|
|
1513
|
+
});
|
|
1514
|
+
}
|
|
1515
|
+
/**
|
|
1516
|
+
* Wait for one spawned CLI child, folding a spawn failure into its output.
|
|
1517
|
+
*
|
|
1518
|
+
* Every caller already reports a non-zero exit through the captured output, so
|
|
1519
|
+
* a process that never started is reported the same readable way instead of as
|
|
1520
|
+
* a silent failure or a hang.
|
|
1521
|
+
* @param child - the spawned child.
|
|
1522
|
+
* @param output - the bounded capture the failure text is appended to.
|
|
1523
|
+
* @param timeoutMs - kill the child after this long; omitted for no deadline.
|
|
1524
|
+
* @returns the exit code, or null when a signal ended the child.
|
|
1525
|
+
*/
|
|
1526
|
+
async function awaitCliExit(child, output, timeoutMs) {
|
|
1527
|
+
const timer = timeoutMs === void 0 ? void 0 : setTimeout(() => {
|
|
1528
|
+
child.kill();
|
|
1529
|
+
}, timeoutMs);
|
|
1530
|
+
try {
|
|
1531
|
+
const exit = await awaitChildExit(child);
|
|
1532
|
+
if (exit.spawnError !== void 0) capture(Buffer.from(exit.spawnError + "\n"), output);
|
|
1533
|
+
return exit.code;
|
|
1534
|
+
} finally {
|
|
1535
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
1536
|
+
}
|
|
1537
|
+
}
|
|
1323
1538
|
/**
|
|
1324
1539
|
* Spawn the dsh CLI with piped stdio and no shell parsing (see
|
|
1325
1540
|
* {@link dshSpawnCommand}).
|
|
@@ -1330,6 +1545,9 @@ function withPrependedPath(env, dir, platform = process.platform) {
|
|
|
1330
1545
|
* `dsh plugin` to pnpm, so without this the update would start and then fail on
|
|
1331
1546
|
* a missing pnpm instead. This mirrors the packaged Desktop launcher, which
|
|
1332
1547
|
* prepends its bundled runtime bin to the host it spawns.
|
|
1548
|
+
*
|
|
1549
|
+
* Every child leaves here guarded ({@link guardSpawnFailure}), so a spawn that
|
|
1550
|
+
* fails settles as a non-zero exit instead of raising an unhandled error.
|
|
1333
1551
|
* @param binary - the resolved dsh CLI path.
|
|
1334
1552
|
* @param args - arguments after the interpreter/script prefix.
|
|
1335
1553
|
* @param env - the host environment.
|
|
@@ -1338,7 +1556,7 @@ function withPrependedPath(env, dir, platform = process.platform) {
|
|
|
1338
1556
|
function spawnDsh(binary, args, env) {
|
|
1339
1557
|
const { command, argsPrefix } = dshSpawnCommand(binary);
|
|
1340
1558
|
const childEnv = withPrependedPath(env, (process.platform === "win32" ? win32 : posix).dirname(binary));
|
|
1341
|
-
if (process.platform === "win32" && command.toLowerCase().endsWith(".cmd")) return spawn(
|
|
1559
|
+
if (process.platform === "win32" && command.toLowerCase().endsWith(".cmd")) return guardSpawnFailure(spawn(windowsCmdPath(env), windowsCmdShimArgs(command, args), {
|
|
1342
1560
|
env: childEnv,
|
|
1343
1561
|
windowsVerbatimArguments: true,
|
|
1344
1562
|
stdio: [
|
|
@@ -1346,8 +1564,8 @@ function spawnDsh(binary, args, env) {
|
|
|
1346
1564
|
"pipe",
|
|
1347
1565
|
"pipe"
|
|
1348
1566
|
]
|
|
1349
|
-
});
|
|
1350
|
-
return spawn(command, [...argsPrefix, ...args], {
|
|
1567
|
+
}));
|
|
1568
|
+
return guardSpawnFailure(spawn(command, [...argsPrefix, ...args], {
|
|
1351
1569
|
env: command === process.execPath ? {
|
|
1352
1570
|
...childEnv,
|
|
1353
1571
|
ELECTRON_RUN_AS_NODE: "1"
|
|
@@ -1357,7 +1575,7 @@ function spawnDsh(binary, args, env) {
|
|
|
1357
1575
|
"pipe",
|
|
1358
1576
|
"pipe"
|
|
1359
1577
|
]
|
|
1360
|
-
});
|
|
1578
|
+
}));
|
|
1361
1579
|
}
|
|
1362
1580
|
/**
|
|
1363
1581
|
* Entry-id line of the official installer channels in the boot dump. A plain
|
|
@@ -1366,6 +1584,28 @@ function spawnDsh(binary, args, env) {
|
|
|
1366
1584
|
*/
|
|
1367
1585
|
const OFFICIAL_INSTALLER_PATTERN = /^\s*-?\s*id:\s*['"]?plugin-(?:installer|control)['"]?\s*$/m;
|
|
1368
1586
|
/**
|
|
1587
|
+
* The entry ids of a composed profile dump (`dsh --profile <name>
|
|
1588
|
+
* --dump-config`). The dump prints one YAML block per patch layer under a
|
|
1589
|
+
* `# ==` header, with the composed entries as column-0 `- id:` items — an
|
|
1590
|
+
* entry a profile patch overrides appears once, carrying the override's keys,
|
|
1591
|
+
* so those lines are exactly the loader's own entry set. Nested config keeps
|
|
1592
|
+
* its own `id` keys indented and is never mistaken for an entry.
|
|
1593
|
+
* @param dump - the dump's captured text.
|
|
1594
|
+
* @returns the composed entry ids, or undefined when the dump carried none.
|
|
1595
|
+
*/
|
|
1596
|
+
function composedEntryIdsOf(dump) {
|
|
1597
|
+
const ids = /* @__PURE__ */ new Set();
|
|
1598
|
+
for (const rawLine of dump.split("\n")) {
|
|
1599
|
+
const line = rawLine.endsWith("\r") ? rawLine.slice(0, -1) : rawLine;
|
|
1600
|
+
const match = /^-[ \t]+id:[ \t]*(.+?)[ \t]*$/.exec(line);
|
|
1601
|
+
if (match === null) continue;
|
|
1602
|
+
const value = match[1];
|
|
1603
|
+
const unquoted = /^'(.*)'$/.exec(value)?.[1] ?? /^"(.*)"$/.exec(value)?.[1] ?? value;
|
|
1604
|
+
if (unquoted !== "") ids.add(unquoted);
|
|
1605
|
+
}
|
|
1606
|
+
return ids.size === 0 ? void 0 : ids;
|
|
1607
|
+
}
|
|
1608
|
+
/**
|
|
1369
1609
|
* Detect whether the official installer channels exist on this runtime by
|
|
1370
1610
|
* dumping the boot composition once: the npm-published web never contains
|
|
1371
1611
|
* `plugin-installer` entries, DSHCode and the checkout web do. The browser
|
|
@@ -1390,9 +1630,7 @@ async function detectOfficialChannels(binary, profileName, env = process.env, sp
|
|
|
1390
1630
|
child.stderr?.on("data", (chunk) => {
|
|
1391
1631
|
capture(chunk, output);
|
|
1392
1632
|
});
|
|
1393
|
-
if (await
|
|
1394
|
-
child.on("close", resolve);
|
|
1395
|
-
}) !== 0) return false;
|
|
1633
|
+
if (await awaitCliExit(child, output) !== 0) return false;
|
|
1396
1634
|
return OFFICIAL_INSTALLER_PATTERN.test(output.read());
|
|
1397
1635
|
}
|
|
1398
1636
|
/**
|
|
@@ -1416,6 +1654,22 @@ function nativeManagerFailure(outcome) {
|
|
|
1416
1654
|
const code = failure?.code;
|
|
1417
1655
|
return typeof code === "string" && code !== "" ? `官方插件管理器拒绝执行(${code})` : "官方插件管理器报告失败";
|
|
1418
1656
|
}
|
|
1657
|
+
/**
|
|
1658
|
+
* The official manager's own refusal code for one run, or undefined when its
|
|
1659
|
+
* verdict is not a failure. {@link nativeManagerFailure} renders the code for the
|
|
1660
|
+
* person; this is the same verdict read for a decision, which is how the update
|
|
1661
|
+
* path recognises the `already-installed` refusal it has to answer with a
|
|
1662
|
+
* two-phase replacement.
|
|
1663
|
+
* @param outcome - the resolved value of `installBundle` / `removeBundle`.
|
|
1664
|
+
* @returns the manager's failure code, or undefined for a run that did not fail.
|
|
1665
|
+
*/
|
|
1666
|
+
function nativeManagerRefusalCode(outcome) {
|
|
1667
|
+
if (typeof outcome !== "object" || outcome === null) return void 0;
|
|
1668
|
+
const verdict = outcome;
|
|
1669
|
+
if (verdict.application !== "failed") return void 0;
|
|
1670
|
+
const code = verdict.error?.code;
|
|
1671
|
+
return typeof code === "string" && code !== "" ? code : void 0;
|
|
1672
|
+
}
|
|
1419
1673
|
/** The gateway: serializes CLI operations through one job table and one mutation queue. */
|
|
1420
1674
|
var CliGateway = class {
|
|
1421
1675
|
facts;
|
|
@@ -1498,15 +1752,8 @@ var CliGateway = class {
|
|
|
1498
1752
|
child.stderr?.on("data", (chunk) => {
|
|
1499
1753
|
capture(chunk, output);
|
|
1500
1754
|
});
|
|
1501
|
-
const timer = setTimeout(() => {
|
|
1502
|
-
child.kill();
|
|
1503
|
-
}, timeoutMs);
|
|
1504
|
-
const code = await new Promise((resolve) => {
|
|
1505
|
-
child.on("close", resolve);
|
|
1506
|
-
});
|
|
1507
|
-
clearTimeout(timer);
|
|
1508
1755
|
return {
|
|
1509
|
-
code,
|
|
1756
|
+
code: await awaitCliExit(child, output, timeoutMs),
|
|
1510
1757
|
output: output.read().trim()
|
|
1511
1758
|
};
|
|
1512
1759
|
}
|
|
@@ -1607,6 +1854,7 @@ var CliGateway = class {
|
|
|
1607
1854
|
job.error = `plugin-manager: 迁移后的启动预检失败${verify.output === "" ? "" : `:\n${verify.output}`}`;
|
|
1608
1855
|
return;
|
|
1609
1856
|
}
|
|
1857
|
+
if (await this.pruneOrphanOverrides(job, verify.output) === void 0) return;
|
|
1610
1858
|
const manifest = await readProfileManifest(this.facts.packageJsonPath);
|
|
1611
1859
|
const updated = await buildPluginRow(this.facts, targetId, manifest.dependencies[targetId] ?? targetSpec, after.layer.rows);
|
|
1612
1860
|
if (!/^(?:link:|file:)/.test(targetSpec) && updated.version !== targetVersion) {
|
|
@@ -1817,6 +2065,13 @@ var CliGateway = class {
|
|
|
1817
2065
|
* run (pnpm exited non-zero, an incompatible version, a cancellation) resolves
|
|
1818
2066
|
* with `application: 'failed'`, and only that verdict carries the reason — the
|
|
1819
2067
|
* profile re-read can only show that the version did not move.
|
|
2068
|
+
*
|
|
2069
|
+
* An `already-installed` refusal is answered by {@link replaceInstalled}: the
|
|
2070
|
+
* manager refuses to install a dependency the profile already carries while the
|
|
2071
|
+
* host mounts `hmr` (0.2.1-rc.2, and dsh-base mounts that service on every
|
|
2072
|
+
* profile host), so an in-place update there is only expressible as its two
|
|
2073
|
+
* phases. The single call stays first so the day the manager accepts an
|
|
2074
|
+
* in-place update this path needs no change.
|
|
1820
2075
|
* @param job - the update job being settled.
|
|
1821
2076
|
* @param native - the official manager.
|
|
1822
2077
|
*/
|
|
@@ -1829,10 +2084,13 @@ var CliGateway = class {
|
|
|
1829
2084
|
return;
|
|
1830
2085
|
}
|
|
1831
2086
|
const before = await this.capture();
|
|
1832
|
-
const
|
|
2087
|
+
const carried = await readProfileManifest(this.facts.packageJsonPath);
|
|
2088
|
+
const first = await native.installBundle(job.spec, {
|
|
1833
2089
|
enabled: true,
|
|
1834
2090
|
requestId: job.id
|
|
1835
|
-
})
|
|
2091
|
+
});
|
|
2092
|
+
let refusal = nativeManagerFailure(first);
|
|
2093
|
+
if (refusal !== void 0 && nativeManagerRefusalCode(first) === "already-installed") refusal = await this.replaceInstalled(job, native, targetId, carried.dependencies[targetId]);
|
|
1836
2094
|
if (refusal !== void 0) {
|
|
1837
2095
|
job.phase = "error";
|
|
1838
2096
|
job.error = `plugin-manager: 官方插件管理器更新失败:${refusal}`;
|
|
@@ -1851,6 +2109,7 @@ var CliGateway = class {
|
|
|
1851
2109
|
job.error = `plugin-manager: 官方插件管理器报告成功,但 ${targetId} 仍为 ${updated.version},预期 ${targetVersion}(更新未生效)`;
|
|
1852
2110
|
return;
|
|
1853
2111
|
}
|
|
2112
|
+
if (await this.pruneOrphanOverrides(job) === void 0) return;
|
|
1854
2113
|
job.plugin = updated;
|
|
1855
2114
|
job.conflicts = significantChanges(diffLayer(before.layer, after.layer)).map((change) => ({
|
|
1856
2115
|
id: change.id,
|
|
@@ -1860,6 +2119,39 @@ var CliGateway = class {
|
|
|
1860
2119
|
}));
|
|
1861
2120
|
job.phase = "done";
|
|
1862
2121
|
}
|
|
2122
|
+
/**
|
|
2123
|
+
* Replace an installed bundle with the update job's target spec through the
|
|
2124
|
+
* official manager, the only writer an application-owned profile accepts.
|
|
2125
|
+
* Removing first is what makes the install possible: the manager's
|
|
2126
|
+
* `already-installed` guard reads the profile, so the same name is a fresh
|
|
2127
|
+
* dependency once the old one is gone.
|
|
2128
|
+
*
|
|
2129
|
+
* A failed second phase reinstalls the spec the profile carried before the run,
|
|
2130
|
+
* so an update that cannot land leaves a working plugin behind instead of an
|
|
2131
|
+
* empty slot; the report says which of the two happened.
|
|
2132
|
+
* @param job - the update job whose spec is installed.
|
|
2133
|
+
* @param native - the official manager.
|
|
2134
|
+
* @param targetId - the installed bundle being replaced.
|
|
2135
|
+
* @param previousSpec - the dependency spec the profile carried before the run.
|
|
2136
|
+
* @returns the failure to report, or undefined once the target spec landed.
|
|
2137
|
+
*/
|
|
2138
|
+
async replaceInstalled(job, native, targetId, previousSpec) {
|
|
2139
|
+
if (previousSpec === void 0) return `${targetId} 不在 profile 依赖中,无法替换已安装版本`;
|
|
2140
|
+
const removalFailure = nativeManagerFailure(await native.removeBundle(targetId));
|
|
2141
|
+
if (removalFailure !== void 0) return `已安装版本无法移除(${removalFailure}),本次更新未做改动`;
|
|
2142
|
+
const refusal = nativeManagerFailure(await native.installBundle(job.spec, {
|
|
2143
|
+
enabled: true,
|
|
2144
|
+
requestId: job.id
|
|
2145
|
+
}));
|
|
2146
|
+
if (refusal === void 0) return void 0;
|
|
2147
|
+
const restoreSpec = `${targetId}@${previousSpec}`;
|
|
2148
|
+
const restoreFailure = nativeManagerFailure(await native.installBundle(restoreSpec, {
|
|
2149
|
+
enabled: true,
|
|
2150
|
+
requestId: job.id
|
|
2151
|
+
}));
|
|
2152
|
+
if (restoreFailure === void 0) return `${refusal};已装回 ${restoreSpec}`;
|
|
2153
|
+
return `${refusal};装回 ${restoreSpec} 也失败:${restoreFailure},请手动重新安装`;
|
|
2154
|
+
}
|
|
1863
2155
|
/** Start a deterministic legacy aggregate migration. */
|
|
1864
2156
|
migrate(sourceId, targetId, targetVersion, targetSpec) {
|
|
1865
2157
|
const job = {
|
|
@@ -2058,13 +2350,7 @@ var CliGateway = class {
|
|
|
2058
2350
|
child.stderr?.on("data", (chunk) => {
|
|
2059
2351
|
capture(chunk, output);
|
|
2060
2352
|
});
|
|
2061
|
-
const
|
|
2062
|
-
child.kill();
|
|
2063
|
-
}, timeoutMs);
|
|
2064
|
-
const code = await new Promise((resolve) => {
|
|
2065
|
-
child.on("close", resolve);
|
|
2066
|
-
});
|
|
2067
|
-
clearTimeout(timer);
|
|
2353
|
+
const code = await awaitCliExit(child, output, timeoutMs);
|
|
2068
2354
|
if (code !== 0) {
|
|
2069
2355
|
job.phase = "error";
|
|
2070
2356
|
const tail = output.read().trim();
|
|
@@ -2119,8 +2405,9 @@ var CliGateway = class {
|
|
|
2119
2405
|
return;
|
|
2120
2406
|
}
|
|
2121
2407
|
job.plugin = updated;
|
|
2122
|
-
await this.verifyBoot(job, before, after, conflicts);
|
|
2408
|
+
const dump = await this.verifyBoot(job, before, after, conflicts);
|
|
2123
2409
|
if (job.phase === "error") return;
|
|
2410
|
+
if (await this.pruneOrphanOverrides(job, dump) === void 0) return;
|
|
2124
2411
|
} else if (before.dependencies.find((candidate) => !after.dependencies.includes(candidate)) === void 0) {
|
|
2125
2412
|
job.phase = "error";
|
|
2126
2413
|
job.error = "plugin-manager: dsh plugin remove 报告成功,但依赖仍在 profile 中(卸载未生效)";
|
|
@@ -2165,6 +2452,84 @@ var CliGateway = class {
|
|
|
2165
2452
|
}
|
|
2166
2453
|
}
|
|
2167
2454
|
/**
|
|
2455
|
+
* Compose the profile with the CLI's read-only `--dump-config` probe and
|
|
2456
|
+
* return the dump text. Composition writes nothing and binds no port, so it
|
|
2457
|
+
* is safe on every runtime — including an application-owned profile whose
|
|
2458
|
+
* *writes* the CLI refuses. A run that cannot compose (no CLI on this
|
|
2459
|
+
* runtime, a non-zero exit, a spawn failure) reports undefined, and the
|
|
2460
|
+
* caller must then leave the profile alone instead of guessing at the entry
|
|
2461
|
+
* set.
|
|
2462
|
+
* @returns the composed dump text, or undefined when it is unavailable.
|
|
2463
|
+
*/
|
|
2464
|
+
async compositionOf() {
|
|
2465
|
+
const binary = this.binary();
|
|
2466
|
+
if (binary === null) return void 0;
|
|
2467
|
+
try {
|
|
2468
|
+
const output = createOutputCapture(MAX_OUTPUT_BYTES);
|
|
2469
|
+
const child = this.spawnCli(binary, [
|
|
2470
|
+
"--profile",
|
|
2471
|
+
this.facts.profileName,
|
|
2472
|
+
"--dump-config"
|
|
2473
|
+
]);
|
|
2474
|
+
child.stdout?.on("data", (chunk) => {
|
|
2475
|
+
capture(chunk, output);
|
|
2476
|
+
});
|
|
2477
|
+
child.stderr?.on("data", (chunk) => {
|
|
2478
|
+
capture(chunk, output);
|
|
2479
|
+
});
|
|
2480
|
+
return await awaitCliExit(child, output, 9e4) === 0 ? output.read() : void 0;
|
|
2481
|
+
} catch {
|
|
2482
|
+
return;
|
|
2483
|
+
}
|
|
2484
|
+
}
|
|
2485
|
+
/**
|
|
2486
|
+
* Post-update orphan guard: drop this package's own enablement overrides
|
|
2487
|
+
* whose entry id the composed *target* profile no longer carries. The
|
|
2488
|
+
* authority is the loader's own composition after the update
|
|
2489
|
+
* ({@link composedEntryIdsOf}), not the profile patch and not the source
|
|
2490
|
+
* profile: an override is only orphaned once the target composition stops
|
|
2491
|
+
* declaring that id, and ids the official base or another bundle still
|
|
2492
|
+
* mounts stay valid. A retired row would otherwise leave a stale override
|
|
2493
|
+
* that the loader reports on every boot as `patch: entry "<id>" not found`.
|
|
2494
|
+
*
|
|
2495
|
+
* Nothing is written when nothing is orphaned — a second run over a pruned
|
|
2496
|
+
* profile returns the input text untouched, so no write and no second backup
|
|
2497
|
+
* happen — and an unobtainable composition leaves the file as it is instead
|
|
2498
|
+
* of emptying it. A write that does fail settles the job as an error the way
|
|
2499
|
+
* every other post-mutation patch write in this transaction does, with the
|
|
2500
|
+
* backup the write helper takes first left in place.
|
|
2501
|
+
* @param job - the settling job (error target on write failure).
|
|
2502
|
+
* @param dumpText - an already captured composition, when the caller has one.
|
|
2503
|
+
* @returns the pruned entry ids, or undefined when the job failed.
|
|
2504
|
+
*/
|
|
2505
|
+
async pruneOrphanOverrides(job, dumpText) {
|
|
2506
|
+
const dump = dumpText ?? await this.compositionOf();
|
|
2507
|
+
if (dump === void 0) return [];
|
|
2508
|
+
const composed = composedEntryIdsOf(dump);
|
|
2509
|
+
if (composed === void 0) return [];
|
|
2510
|
+
let text;
|
|
2511
|
+
try {
|
|
2512
|
+
text = await readFile(this.facts.patchPath, "utf8");
|
|
2513
|
+
} catch {
|
|
2514
|
+
return [];
|
|
2515
|
+
}
|
|
2516
|
+
let pruned;
|
|
2517
|
+
try {
|
|
2518
|
+
pruned = pruneOrphanRowOverrides(text, this.facts.patchPath, composed);
|
|
2519
|
+
} catch {
|
|
2520
|
+
return [];
|
|
2521
|
+
}
|
|
2522
|
+
if (pruned.pruned.length === 0) return [];
|
|
2523
|
+
try {
|
|
2524
|
+
await writePatchAtomic(this.facts.patchPath, pruned.text);
|
|
2525
|
+
return pruned.pruned;
|
|
2526
|
+
} catch (error) {
|
|
2527
|
+
job.phase = "error";
|
|
2528
|
+
job.error = `plugin-manager: 失效行覆盖清理写回失败:${error instanceof Error ? error.message : String(error)}(备份在 ${this.facts.patchPath}.bak-plugin-manager,下次启动前请手动检查 ${this.facts.patchPath})`;
|
|
2529
|
+
return;
|
|
2530
|
+
}
|
|
2531
|
+
}
|
|
2532
|
+
/**
|
|
2168
2533
|
* Roll back a freshly installed dependency through the official remove
|
|
2169
2534
|
* path (which also drops its bundle), then settle the job as an error.
|
|
2170
2535
|
* This is the owner-aware conflict resolution: the existing plugin keeps
|
|
@@ -2189,14 +2554,7 @@ var CliGateway = class {
|
|
|
2189
2554
|
child.stderr?.on("data", (chunk) => {
|
|
2190
2555
|
capture(chunk, output);
|
|
2191
2556
|
});
|
|
2192
|
-
|
|
2193
|
-
child.kill();
|
|
2194
|
-
}, REMOVE_TIMEOUT_MS);
|
|
2195
|
-
const code = await new Promise((resolve) => {
|
|
2196
|
-
child.on("close", resolve);
|
|
2197
|
-
});
|
|
2198
|
-
clearTimeout(timer);
|
|
2199
|
-
rolledBack = code === 0;
|
|
2557
|
+
rolledBack = await awaitCliExit(child, output, REMOVE_TIMEOUT_MS) === 0;
|
|
2200
2558
|
tail = output.read().trim();
|
|
2201
2559
|
}
|
|
2202
2560
|
job.phase = "error";
|
|
@@ -2266,14 +2624,19 @@ var CliGateway = class {
|
|
|
2266
2624
|
};
|
|
2267
2625
|
}
|
|
2268
2626
|
/**
|
|
2269
|
-
* Boot preflight after an install: compose the profile with the
|
|
2270
|
-
* `--dump-config` (resolves every entry without binding the port). A
|
|
2271
|
-
* that implicates the new plugin disables it so the next start
|
|
2272
|
-
* an unrelated failure is reported without touching anything.
|
|
2627
|
+
* Boot preflight after an install or update: compose the profile with the
|
|
2628
|
+
* CLI's `--dump-config` (resolves every entry without binding the port). A
|
|
2629
|
+
* failure that implicates the new plugin disables it so the next start
|
|
2630
|
+
* cannot fail; an unrelated failure is reported without touching anything.
|
|
2631
|
+
* The captured dump is returned on success so the update path can read the
|
|
2632
|
+
* composed entry set from the same probe (see {@link pruneOrphanOverrides}).
|
|
2633
|
+
* @returns the composed dump text, or undefined when the preflight did not
|
|
2634
|
+
* produce one (no CLI on this runtime, or a failure the caller must read
|
|
2635
|
+
* from `job`).
|
|
2273
2636
|
*/
|
|
2274
2637
|
async verifyBoot(job, before, after, conflicts) {
|
|
2275
2638
|
const binary = this.binary();
|
|
2276
|
-
if (binary === null) return;
|
|
2639
|
+
if (binary === null) return void 0;
|
|
2277
2640
|
const name = this.newDependency(before, after);
|
|
2278
2641
|
const verifyOutput = createOutputCapture(MAX_OUTPUT_BYTES);
|
|
2279
2642
|
const child = this.spawnCli(binary, [
|
|
@@ -2287,15 +2650,10 @@ var CliGateway = class {
|
|
|
2287
2650
|
child.stderr?.on("data", (chunk) => {
|
|
2288
2651
|
capture(chunk, verifyOutput);
|
|
2289
2652
|
});
|
|
2290
|
-
const
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
const
|
|
2294
|
-
child.on("close", resolve);
|
|
2295
|
-
});
|
|
2296
|
-
clearTimeout(timer);
|
|
2297
|
-
if (code === 0) return;
|
|
2298
|
-
const tail = verifyOutput.read().trim();
|
|
2653
|
+
const code = await awaitCliExit(child, verifyOutput, 9e4);
|
|
2654
|
+
const dump = verifyOutput.read();
|
|
2655
|
+
if (code === 0) return dump;
|
|
2656
|
+
const tail = dump.trim();
|
|
2299
2657
|
if (name === void 0) {
|
|
2300
2658
|
job.phase = "error";
|
|
2301
2659
|
job.error = tail === "" ? "plugin-manager: boot preflight failed" : tail;
|
|
@@ -2679,11 +3037,13 @@ const launch = (attempt) => {
|
|
|
2679
3037
|
const child = cp.spawn(job.execPath, job.argv, { cwd: job.cwd, env: process.env, detached: true, stdio: ['ignore', fd, fd] });
|
|
2680
3038
|
child.unref();
|
|
2681
3039
|
let code = null;
|
|
3040
|
+
let spawnError = null;
|
|
2682
3041
|
child.on('exit', (value) => { code = value; });
|
|
3042
|
+
child.on('error', (err) => { spawnError = err; log('relaunch spawn error: ' + err.message); });
|
|
2683
3043
|
setTimeout(() => {
|
|
2684
|
-
if (code === null) { log('relaunch started (pid ' + child.pid + ')'); fs.closeSync(fd); return; }
|
|
2685
|
-
if (attempt < 4) { log('relaunch
|
|
2686
|
-
log('relaunch gave up after exit ' + code);
|
|
3044
|
+
if (code === null && spawnError === null) { log('relaunch started (pid ' + child.pid + ')'); fs.closeSync(fd); return; }
|
|
3045
|
+
if (attempt < 4) { log('relaunch failed (' + (spawnError === null ? 'exit ' + code : spawnError.message) + '); retrying'); launch(attempt + 1); return; }
|
|
3046
|
+
log('relaunch gave up after ' + (spawnError === null ? 'exit ' + code : spawnError.message));
|
|
2687
3047
|
fs.closeSync(fd);
|
|
2688
3048
|
}, 3000);
|
|
2689
3049
|
};
|
|
@@ -2722,6 +3082,11 @@ function startRelaunchHelper(command, logPath = restartLogPath()) {
|
|
|
2722
3082
|
stdio: "ignore"
|
|
2723
3083
|
});
|
|
2724
3084
|
helper.unref();
|
|
3085
|
+
helper.on("error", (error) => {
|
|
3086
|
+
try {
|
|
3087
|
+
appendFileSync(logPath, (/* @__PURE__ */ new Date()).toISOString() + " helper spawn error: " + error.message + "\n");
|
|
3088
|
+
} catch {}
|
|
3089
|
+
});
|
|
2725
3090
|
return helper.pid !== void 0;
|
|
2726
3091
|
} catch (error) {
|
|
2727
3092
|
try {
|
|
@@ -13,9 +13,11 @@
|
|
|
13
13
|
* plugin manager instead (see {@link NativePluginManager}).
|
|
14
14
|
* @module @linxin666/dsh-client-ui-plugin-manager/host
|
|
15
15
|
*/
|
|
16
|
+
import { type ChildProcess } from 'node:child_process';
|
|
16
17
|
import type { InstalledPluginItem } from '../core/protocol.ts';
|
|
17
18
|
import type { ControlChange } from '../core/conflict.ts';
|
|
18
19
|
import { type ProfileFacts } from './profile.ts';
|
|
20
|
+
import { type OutputCapture } from './console-output.ts';
|
|
19
21
|
/**
|
|
20
22
|
* Validate an install spec or package id against shell metacharacters.
|
|
21
23
|
* @param spec - the user-supplied spec or id.
|
|
@@ -94,6 +96,24 @@ export declare function dshSpawnCommand(binary: string, platform?: string, local
|
|
|
94
96
|
command: string;
|
|
95
97
|
argsPrefix: string[];
|
|
96
98
|
};
|
|
99
|
+
/**
|
|
100
|
+
* Absolute path of the Windows command processor, resolved from an environment
|
|
101
|
+
* rather than from PATH.
|
|
102
|
+
*
|
|
103
|
+
* Every `.cmd` shim still has to be executed through cmd.exe, and a bare
|
|
104
|
+
* `cmd.exe` spawn resolves through the host PATH: a GUI-launched host whose PATH
|
|
105
|
+
* carries no `%SystemRoot%\system32` (a packaged Desktop launch, a service, a
|
|
106
|
+
* stripped environment) gets ENOENT for a name that is present on disk, and the
|
|
107
|
+
* whole feature fails with it (issue #1857). ComSpec is the variable Windows
|
|
108
|
+
* itself uses for this and names the real binary, so it is preferred; otherwise
|
|
109
|
+
* the system root is read from `SystemRoot` or `windir`, with the conventional
|
|
110
|
+
* `C:\Windows` as the last resort.
|
|
111
|
+
*
|
|
112
|
+
* Only the Windows branch needs it — a POSIX host spawns the CLI directly.
|
|
113
|
+
* @param env - the environment to resolve from.
|
|
114
|
+
* @returns the absolute cmd.exe path.
|
|
115
|
+
*/
|
|
116
|
+
export declare function windowsCmdPath(env?: NodeJS.ProcessEnv): string;
|
|
97
117
|
/** Build the exact cmd.exe command line required to execute a trusted .cmd shim. */
|
|
98
118
|
export declare function windowsCmdShimArgs(binary: string, args: readonly string[]): string[];
|
|
99
119
|
/**
|
|
@@ -108,6 +128,53 @@ export declare function windowsCmdShimArgs(binary: string, args: readonly string
|
|
|
108
128
|
* @returns a new environment with one normalized, prepended PATH.
|
|
109
129
|
*/
|
|
110
130
|
export declare function withPrependedPath(env: NodeJS.ProcessEnv, dir: string, platform?: string): NodeJS.ProcessEnv;
|
|
131
|
+
/**
|
|
132
|
+
* Exit code reported for a child that never became a process. Node delivers a
|
|
133
|
+
* failed spawn as an `error` event whose `close` may never follow, and every
|
|
134
|
+
* consumer of a spawned child waits for `close` alone.
|
|
135
|
+
*/
|
|
136
|
+
export declare const SPAWN_FAILURE_EXIT_CODE = -1;
|
|
137
|
+
/**
|
|
138
|
+
* Attach the error fallback every spawn outlet needs.
|
|
139
|
+
*
|
|
140
|
+
* A ChildProcess without an `error` listener turns a spawn failure into an
|
|
141
|
+
* unhandled `error` event, which is an uncaught exception: the failure of one
|
|
142
|
+
* CLI call took the whole dsh host process down with it. This records the
|
|
143
|
+
* reason and, when the child never closed, settles it as a failed exit so a
|
|
144
|
+
* caller that only waits for `close` neither hangs nor crashes (issue #1857).
|
|
145
|
+
* @param child - the spawned child.
|
|
146
|
+
* @returns the same child, guarded.
|
|
147
|
+
*/
|
|
148
|
+
export declare function guardSpawnFailure(child: ChildProcess): ChildProcess;
|
|
149
|
+
/** One spawned child's exit verdict. */
|
|
150
|
+
export interface ChildExit {
|
|
151
|
+
/** The process exit code, or {@link SPAWN_FAILURE_EXIT_CODE} when it never started. */
|
|
152
|
+
code: number | null;
|
|
153
|
+
/** The spawn failure reason, present only when no process was created. */
|
|
154
|
+
spawnError?: string;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Wait for a spawned child to close, settling on a spawn failure as well.
|
|
158
|
+
*
|
|
159
|
+
* The listener pair is attached to every child this package waits on, so the
|
|
160
|
+
* wait is safe for a child that arrived through a seam ({@link guardSpawnFailure}
|
|
161
|
+
* guards the real spawn outlets, an injected one may skip it).
|
|
162
|
+
* @param child - the spawned child.
|
|
163
|
+
* @returns the exit verdict.
|
|
164
|
+
*/
|
|
165
|
+
export declare function awaitChildExit(child: ChildProcess): Promise<ChildExit>;
|
|
166
|
+
/**
|
|
167
|
+
* Wait for one spawned CLI child, folding a spawn failure into its output.
|
|
168
|
+
*
|
|
169
|
+
* Every caller already reports a non-zero exit through the captured output, so
|
|
170
|
+
* a process that never started is reported the same readable way instead of as
|
|
171
|
+
* a silent failure or a hang.
|
|
172
|
+
* @param child - the spawned child.
|
|
173
|
+
* @param output - the bounded capture the failure text is appended to.
|
|
174
|
+
* @param timeoutMs - kill the child after this long; omitted for no deadline.
|
|
175
|
+
* @returns the exit code, or null when a signal ended the child.
|
|
176
|
+
*/
|
|
177
|
+
export declare function awaitCliExit(child: ChildProcess, output: OutputCapture, timeoutMs?: number): Promise<number | null>;
|
|
111
178
|
/**
|
|
112
179
|
* Spawn the dsh CLI with piped stdio and no shell parsing (see
|
|
113
180
|
* {@link dshSpawnCommand}).
|
|
@@ -118,12 +185,26 @@ export declare function withPrependedPath(env: NodeJS.ProcessEnv, dir: string, p
|
|
|
118
185
|
* `dsh plugin` to pnpm, so without this the update would start and then fail on
|
|
119
186
|
* a missing pnpm instead. This mirrors the packaged Desktop launcher, which
|
|
120
187
|
* prepends its bundled runtime bin to the host it spawns.
|
|
188
|
+
*
|
|
189
|
+
* Every child leaves here guarded ({@link guardSpawnFailure}), so a spawn that
|
|
190
|
+
* fails settles as a non-zero exit instead of raising an unhandled error.
|
|
121
191
|
* @param binary - the resolved dsh CLI path.
|
|
122
192
|
* @param args - arguments after the interpreter/script prefix.
|
|
123
193
|
* @param env - the host environment.
|
|
124
194
|
* @returns the spawned child process.
|
|
125
195
|
*/
|
|
126
|
-
export declare function spawnDsh(binary: string, args: string[], env: NodeJS.ProcessEnv):
|
|
196
|
+
export declare function spawnDsh(binary: string, args: string[], env: NodeJS.ProcessEnv): ChildProcess;
|
|
197
|
+
/**
|
|
198
|
+
* The entry ids of a composed profile dump (`dsh --profile <name>
|
|
199
|
+
* --dump-config`). The dump prints one YAML block per patch layer under a
|
|
200
|
+
* `# ==` header, with the composed entries as column-0 `- id:` items — an
|
|
201
|
+
* entry a profile patch overrides appears once, carrying the override's keys,
|
|
202
|
+
* so those lines are exactly the loader's own entry set. Nested config keeps
|
|
203
|
+
* its own `id` keys indented and is never mistaken for an entry.
|
|
204
|
+
* @param dump - the dump's captured text.
|
|
205
|
+
* @returns the composed entry ids, or undefined when the dump carried none.
|
|
206
|
+
*/
|
|
207
|
+
export declare function composedEntryIdsOf(dump: string): Set<string> | undefined;
|
|
127
208
|
/**
|
|
128
209
|
* Detect whether the official installer channels exist on this runtime by
|
|
129
210
|
* dumping the boot composition once: the npm-published web never contains
|
|
@@ -149,7 +230,10 @@ export declare function detectOfficialChannels(binary: string, profileName: stri
|
|
|
149
230
|
*/
|
|
150
231
|
export interface NativePluginManager {
|
|
151
232
|
/**
|
|
152
|
-
* Install
|
|
233
|
+
* Install one package spec through the official manager. Since 0.2.1-rc.2 it
|
|
234
|
+
* refuses a package the profile already carries while the host mounts the `hmr`
|
|
235
|
+
* service (`already-installed`), which is every profile host, so an in-place
|
|
236
|
+
* update cannot be one call there.
|
|
153
237
|
* @param spec - package spec (e.g. `@scope/pkg@1.2.3`).
|
|
154
238
|
* @param options - activation choice and the request id the run is tracked under.
|
|
155
239
|
* @returns the manager's own verdict ({@link NativeManagerOutcome}); the caller
|
|
@@ -205,6 +289,16 @@ export interface NativeManagerOutcome {
|
|
|
205
289
|
* @returns the failure text to report, or undefined for a run that did not fail.
|
|
206
290
|
*/
|
|
207
291
|
export declare function nativeManagerFailure(outcome: unknown): string | undefined;
|
|
292
|
+
/**
|
|
293
|
+
* The official manager's own refusal code for one run, or undefined when its
|
|
294
|
+
* verdict is not a failure. {@link nativeManagerFailure} renders the code for the
|
|
295
|
+
* person; this is the same verdict read for a decision, which is how the update
|
|
296
|
+
* path recognises the `already-installed` refusal it has to answer with a
|
|
297
|
+
* two-phase replacement.
|
|
298
|
+
* @param outcome - the resolved value of `installBundle` / `removeBundle`.
|
|
299
|
+
* @returns the manager's failure code, or undefined for a run that did not fail.
|
|
300
|
+
*/
|
|
301
|
+
export declare function nativeManagerRefusalCode(outcome: unknown): string | undefined;
|
|
208
302
|
/** The gateway: serializes CLI operations through one job table and one mutation queue. */
|
|
209
303
|
export declare class CliGateway {
|
|
210
304
|
private readonly facts;
|
|
@@ -319,10 +413,34 @@ export declare class CliGateway {
|
|
|
319
413
|
* run (pnpm exited non-zero, an incompatible version, a cancellation) resolves
|
|
320
414
|
* with `application: 'failed'`, and only that verdict carries the reason — the
|
|
321
415
|
* profile re-read can only show that the version did not move.
|
|
416
|
+
*
|
|
417
|
+
* An `already-installed` refusal is answered by {@link replaceInstalled}: the
|
|
418
|
+
* manager refuses to install a dependency the profile already carries while the
|
|
419
|
+
* host mounts `hmr` (0.2.1-rc.2, and dsh-base mounts that service on every
|
|
420
|
+
* profile host), so an in-place update there is only expressible as its two
|
|
421
|
+
* phases. The single call stays first so the day the manager accepts an
|
|
422
|
+
* in-place update this path needs no change.
|
|
322
423
|
* @param job - the update job being settled.
|
|
323
424
|
* @param native - the official manager.
|
|
324
425
|
*/
|
|
325
426
|
private runNativeUpdate;
|
|
427
|
+
/**
|
|
428
|
+
* Replace an installed bundle with the update job's target spec through the
|
|
429
|
+
* official manager, the only writer an application-owned profile accepts.
|
|
430
|
+
* Removing first is what makes the install possible: the manager's
|
|
431
|
+
* `already-installed` guard reads the profile, so the same name is a fresh
|
|
432
|
+
* dependency once the old one is gone.
|
|
433
|
+
*
|
|
434
|
+
* A failed second phase reinstalls the spec the profile carried before the run,
|
|
435
|
+
* so an update that cannot land leaves a working plugin behind instead of an
|
|
436
|
+
* empty slot; the report says which of the two happened.
|
|
437
|
+
* @param job - the update job whose spec is installed.
|
|
438
|
+
* @param native - the official manager.
|
|
439
|
+
* @param targetId - the installed bundle being replaced.
|
|
440
|
+
* @param previousSpec - the dependency spec the profile carried before the run.
|
|
441
|
+
* @returns the failure to report, or undefined once the target spec landed.
|
|
442
|
+
*/
|
|
443
|
+
private replaceInstalled;
|
|
326
444
|
/** Start a deterministic legacy aggregate migration. */
|
|
327
445
|
migrate(sourceId: string, targetId: string, targetVersion: string, targetSpec: string): {
|
|
328
446
|
jobId: string;
|
|
@@ -376,6 +494,38 @@ export declare class CliGateway {
|
|
|
376
494
|
* @returns the stripped entries, or undefined when the job failed.
|
|
377
495
|
*/
|
|
378
496
|
private stripDuplicateMounts;
|
|
497
|
+
/**
|
|
498
|
+
* Compose the profile with the CLI's read-only `--dump-config` probe and
|
|
499
|
+
* return the dump text. Composition writes nothing and binds no port, so it
|
|
500
|
+
* is safe on every runtime — including an application-owned profile whose
|
|
501
|
+
* *writes* the CLI refuses. A run that cannot compose (no CLI on this
|
|
502
|
+
* runtime, a non-zero exit, a spawn failure) reports undefined, and the
|
|
503
|
+
* caller must then leave the profile alone instead of guessing at the entry
|
|
504
|
+
* set.
|
|
505
|
+
* @returns the composed dump text, or undefined when it is unavailable.
|
|
506
|
+
*/
|
|
507
|
+
private compositionOf;
|
|
508
|
+
/**
|
|
509
|
+
* Post-update orphan guard: drop this package's own enablement overrides
|
|
510
|
+
* whose entry id the composed *target* profile no longer carries. The
|
|
511
|
+
* authority is the loader's own composition after the update
|
|
512
|
+
* ({@link composedEntryIdsOf}), not the profile patch and not the source
|
|
513
|
+
* profile: an override is only orphaned once the target composition stops
|
|
514
|
+
* declaring that id, and ids the official base or another bundle still
|
|
515
|
+
* mounts stay valid. A retired row would otherwise leave a stale override
|
|
516
|
+
* that the loader reports on every boot as `patch: entry "<id>" not found`.
|
|
517
|
+
*
|
|
518
|
+
* Nothing is written when nothing is orphaned — a second run over a pruned
|
|
519
|
+
* profile returns the input text untouched, so no write and no second backup
|
|
520
|
+
* happen — and an unobtainable composition leaves the file as it is instead
|
|
521
|
+
* of emptying it. A write that does fail settles the job as an error the way
|
|
522
|
+
* every other post-mutation patch write in this transaction does, with the
|
|
523
|
+
* backup the write helper takes first left in place.
|
|
524
|
+
* @param job - the settling job (error target on write failure).
|
|
525
|
+
* @param dumpText - an already captured composition, when the caller has one.
|
|
526
|
+
* @returns the pruned entry ids, or undefined when the job failed.
|
|
527
|
+
*/
|
|
528
|
+
private pruneOrphanOverrides;
|
|
379
529
|
/**
|
|
380
530
|
* Roll back a freshly installed dependency through the official remove
|
|
381
531
|
* path (which also drops its bundle), then settle the job as an error.
|
|
@@ -398,10 +548,15 @@ export declare class CliGateway {
|
|
|
398
548
|
/** Whether the new install claims an entry id another plugin already holds. */
|
|
399
549
|
private detectDuplicateClaims;
|
|
400
550
|
/**
|
|
401
|
-
* Boot preflight after an install: compose the profile with the
|
|
402
|
-
* `--dump-config` (resolves every entry without binding the port). A
|
|
403
|
-
* that implicates the new plugin disables it so the next start
|
|
404
|
-
* an unrelated failure is reported without touching anything.
|
|
551
|
+
* Boot preflight after an install or update: compose the profile with the
|
|
552
|
+
* CLI's `--dump-config` (resolves every entry without binding the port). A
|
|
553
|
+
* failure that implicates the new plugin disables it so the next start
|
|
554
|
+
* cannot fail; an unrelated failure is reported without touching anything.
|
|
555
|
+
* The captured dump is returned on success so the update path can read the
|
|
556
|
+
* composed entry set from the same probe (see {@link pruneOrphanOverrides}).
|
|
557
|
+
* @returns the composed dump text, or undefined when the preflight did not
|
|
558
|
+
* produce one (no CLI on this runtime, or a failure the caller must read
|
|
559
|
+
* from `job`).
|
|
405
560
|
*/
|
|
406
561
|
private verifyBoot;
|
|
407
562
|
}
|
package/lib/types/host/rows.d.ts
CHANGED
|
@@ -120,3 +120,35 @@ export declare function findInsertRow(root: YAMLSeq, id: string): YAMLMap | unde
|
|
|
120
120
|
* @returns the new file text.
|
|
121
121
|
*/
|
|
122
122
|
export declare function setRowEnabled(text: string, filename: string, id: string, name: string, enabled: boolean, baseEnabled?: boolean): string;
|
|
123
|
+
/**
|
|
124
|
+
* The entry id of an enablement override row this package owns, when the item
|
|
125
|
+
* is one: a bare row carrying a string `id`, a boolean `disabled`, and no
|
|
126
|
+
* other key. Anything else is somebody else's row — a config row carrying
|
|
127
|
+
* options, a row with an unknown shape, an insert wrapper — and the manager
|
|
128
|
+
* never edits or removes it.
|
|
129
|
+
* @param item - one top-level patch item.
|
|
130
|
+
* @returns the override's entry id, or undefined when the item is not ours.
|
|
131
|
+
*/
|
|
132
|
+
export declare function overrideRowId(item: unknown): string | undefined;
|
|
133
|
+
/** The rewritten patch text and the entry ids that were dropped. */
|
|
134
|
+
export interface PrunedOverrides {
|
|
135
|
+
/** The new file text; the original text when nothing was pruned. */
|
|
136
|
+
readonly text: string;
|
|
137
|
+
/** The pruned entry ids, in file order. */
|
|
138
|
+
readonly pruned: string[];
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Drop this package's own enablement overrides whose entry id the composed
|
|
142
|
+
* profile no longer carries — a retired row leaves a stale override behind,
|
|
143
|
+
* which the loader reports on every boot as `patch: entry "<id>" not found`.
|
|
144
|
+
* The prunable set is decided by the caller from the composed entry ids: an
|
|
145
|
+
* id the composition does not carry has no row left to override. Only rows
|
|
146
|
+
* {@link overrideRowId} recognizes are removed, comments and every other row
|
|
147
|
+
* are kept, and an already-pruned file returns its input text unchanged so the
|
|
148
|
+
* caller can skip the write entirely.
|
|
149
|
+
* @param text - current patch file text.
|
|
150
|
+
* @param filename - absolute path (diagnostics only).
|
|
151
|
+
* @param composedIds - the entry ids the composed profile carries.
|
|
152
|
+
* @returns the rewritten text and the pruned ids.
|
|
153
|
+
*/
|
|
154
|
+
export declare function pruneOrphanRowOverrides(text: string, filename: string, composedIds: ReadonlySet<string>): PrunedOverrides;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@linxin666/dsh-client-ui-plugin-manager",
|
|
3
3
|
"description": "Update checking for the dsh web GUI's official Plugins page: compares installed plugins against the version their registry source serves, gates the update on the DSH runtime minimum the release declares, and drives the update through the official installer channel or this package's loopback CLI gateway.",
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.7",
|
|
5
5
|
"icon": "icon.svg",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "lib/index.js",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dsh": {
|
|
22
22
|
"engines": {
|
|
23
|
-
"dsh": ">=0.2.
|
|
23
|
+
"dsh": ">=0.2.1-rc.2"
|
|
24
24
|
},
|
|
25
25
|
"bundle": {
|
|
26
26
|
"patch": "./cordis.patch.yml"
|
|
@@ -34,21 +34,21 @@
|
|
|
34
34
|
}
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@deepseek-ai/dsh": ">=0.2.
|
|
37
|
+
"@deepseek-ai/dsh": ">=0.2.1-rc.2",
|
|
38
38
|
"react": "^18.2.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@deepseek-ai/cordis": "^4.0.
|
|
42
|
-
"@deepseek-ai/dsh-api-session-controller": "^0.2.
|
|
43
|
-
"@deepseek-ai/dsh-api-workspace-controller": "^0.2.
|
|
44
|
-
"@deepseek-ai/dsh-client-connection": "^0.2.
|
|
45
|
-
"@deepseek-ai/dsh-client-locale": "^0.2.
|
|
46
|
-
"@deepseek-ai/dsh-client-ui-primitives": "^0.2.
|
|
47
|
-
"@deepseek-ai/dsh-client-ui-renderer": "^0.2.
|
|
48
|
-
"@deepseek-ai/dsh-client-ui-settings": "^0.2.
|
|
49
|
-
"@deepseek-ai/dsh-client-ui-slots": "^0.2.
|
|
50
|
-
"@deepseek-ai/dsh-client-ui-workspace": "^0.2.
|
|
51
|
-
"@deepseek-ai/dsh-host-webserver": "^0.2.
|
|
41
|
+
"@deepseek-ai/cordis": "^4.0.5",
|
|
42
|
+
"@deepseek-ai/dsh-api-session-controller": "^0.2.1-rc.2",
|
|
43
|
+
"@deepseek-ai/dsh-api-workspace-controller": "^0.2.1-rc.2",
|
|
44
|
+
"@deepseek-ai/dsh-client-connection": "^0.2.1-rc.2",
|
|
45
|
+
"@deepseek-ai/dsh-client-locale": "^0.2.1-rc.2",
|
|
46
|
+
"@deepseek-ai/dsh-client-ui-primitives": "^0.2.1-rc.2",
|
|
47
|
+
"@deepseek-ai/dsh-client-ui-renderer": "^0.2.1-rc.2",
|
|
48
|
+
"@deepseek-ai/dsh-client-ui-settings": "^0.2.1-rc.2",
|
|
49
|
+
"@deepseek-ai/dsh-client-ui-slots": "^0.2.1-rc.2",
|
|
50
|
+
"@deepseek-ai/dsh-client-ui-workspace": "^0.2.1-rc.2",
|
|
51
|
+
"@deepseek-ai/dsh-host-webserver": "^0.2.1-rc.2",
|
|
52
52
|
"@testing-library/react": "^16.1.0",
|
|
53
53
|
"@types/node": "^22.20.0",
|
|
54
54
|
"@types/react": "~18.3.1",
|
|
@@ -79,6 +79,6 @@
|
|
|
79
79
|
"build": "tsc -b tsconfig.build.json && tsdown",
|
|
80
80
|
"watch": "tsdown --watch",
|
|
81
81
|
"test": "vitest run",
|
|
82
|
-
"typecheck": "
|
|
82
|
+
"typecheck": "tsgo --noEmit"
|
|
83
83
|
}
|
|
84
84
|
}
|