dsh-drydock 1.0.2 → 1.1.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.en.md CHANGED
@@ -82,7 +82,7 @@ Verified on **DSH 0.1.7-rc.2**: the engine boots cleanly, the sidebar shows "Plu
82
82
  - **Rescue decoupled from the engine** (v0.7+): with the engine down, the **3081 launcher (with a built-in rescue page) and the 3082 rescue service** still self-check, repair and start it.
83
83
  - **Browser as launcher**: set your home page to `http://127.0.0.1:3081/` (`http://localhost:3081/` works the same way) — opening the browser runs self-check → repair → start → jumps to the main UI.
84
84
  - **Local write endpoints are guarded** (v0.9.1): same-origin `Origin` (same-host, same-port allowlist: `127.0.0.1` / `localhost` / `[::1]`) + one-time token + single-flight, so a third-party page cannot start/stop anything; `--status` also appends a `health.log` line (7 days / 1000 lines).
85
- - **Multi-source update aggregation**: npm registry / dshfind / GitHub / custom mirrors queried in parallel, with rate-limit circuit breaking and the highest version winning.
85
+ - **Multi-source update aggregation**: npm registry / GitHub / custom mirrors queried in parallel, with rate-limit circuit breaking and the highest version winning.
86
86
 
87
87
  ---
88
88
 
@@ -96,7 +96,7 @@ Five sections, switching keeps your scroll position:
96
96
  |---|---|
97
97
  | **Official built-ins (optional)** | Engine-provided bundles that are disabled by default (one-click enable/disable) + official plugins with their own config page + version exemptions |
98
98
  | **All plugins** | Plugin list: search, collapsible groups, origin filter, enable/disable, inline config, inline uninstall, version & origin, manual origin override |
99
- | **Market** | dshfind curated catalog (browse by category / search / sort), one-click install; falls back to GitHub search when offline |
99
+ | **Market** | ADP curated catalog (browse by category / search / sort), one-click install |
100
100
  | **Operations & scenarios** | Transactional uninstall with impact preview, **pre-uninstall health check**, operation history undo, scenarios |
101
101
  | **Maintenance** | Update sources, pre-boot self-check, rescue center entries, downloads folder |
102
102
 
@@ -218,7 +218,7 @@ node "$DSH_HOME/profiles/web/node_modules/dsh-drydock/bin/open-boot.mjs" --statu
218
218
  | `~/.dsh/profiles/<name>/vendor/downloads/*.tgz` | archive staging for browser downloads; archives still referenced by dependencies are never deleted | No |
219
219
  | `$DSH_HOME/downloads/*` | "auto-install from the downloads folder" scans archives and writes `.installed` / `.failed` stamps | No |
220
220
  | Local npm global root (Windows `%APPDATA%\npm`, macOS/Linux `npm root -g` and common paths) | **read-only**: locate the engine-provided `@deepseek-ai/*` packages and extract plugin summaries | No |
221
- | Update sources: npm registry (`registry.npmjs.org` by default), dshfind, GitHub, mirrors you add (e.g. `registry.npmmirror.com`) | query versions and download archives | **Queries only** (GET metadata / archives) — no local data is uploaded |
221
+ | Update sources: npm registry (`registry.npmjs.org` by default), GitHub, mirrors you add (e.g. `registry.npmmirror.com`) | query versions and download archives | **Queries only** (GET metadata / archives) — no local data is uploaded |
222
222
  | GitHub API: `api.github.com`, `raw.githubusercontent.com`, `codeload.github.com` | read releases and repository `package.json`, download tgz | same |
223
223
  | Catalog `awesome-dsh-plugin.com/plugins.json` | market catalog (10-minute host cache) | same |
224
224
  | Loopback ports `3080` / `3081` / `3082` (+ lock `4081 = 3081+1000`) | main UI / launcher + rescue page / backup rescue service / single-instance lock — bound to `127.0.0.1` only | No (never leaves the machine) |
package/README.md CHANGED
@@ -18,7 +18,7 @@
18
18
 
19
19
  | 场景 | 谁来管 |
20
20
  | --- | --- |
21
- | 找插件、逛市场、一键装 | 官方插件页 / 插件市场(dshmarket 等)——这条赛道已封顶;本工具**不自建目录**,市场页签只是借 dshfind 目录的顺手入口 |
21
+ | 找插件、逛市场、一键装 | 官方插件页 / 插件市场(dshmarket 等)——这条赛道已封顶;本工具**不自建目录**,市场页签只是借 ADP 目录的顺手入口 |
22
22
  | 装坏了怎么办 | **本工具**:事务化卸载(影响预览 → 体检 → 备份 → 删除 → 验证 → 失败自动回滚)+ 一键撤销(最近 20 次操作留痕) |
23
23
  | 装多了怎么管 | **本工具**:来源三分区 + 场景方案(启停组合一键切换)+ 操作历史 |
24
24
  | 引擎起不来怎么办 | **本工具**:独立进程 3081 的 `verify / fix / start / stop / status`,不依赖 Cordis 运行时;带明确退出码,可被脚本/外部调用 |
@@ -42,6 +42,7 @@
42
42
  | 启动页(3081) | `http://127.0.0.1:3081/` | 打开即自检并启动引擎(浏览器主页设为它 = "打开即启动") |
43
43
  | 救援球 🛟 | 3080 右下角浮动按钮 | 可拖动换位(位置持久记忆),单击打开救援页 |
44
44
  | 救援页 | `http://127.0.0.1:3081/rescue` | verify / fix / start / stop / status 全套修复能力 |
45
+ | **离线诊断(CLI)** | `npx dsh-drydock-doctor` | v1.1.0:**只读**收集环境 / profile / 桌面锁 / 崩溃报告 / 操作记录 / 端口事实,产出可粘贴的中文报告;不写盘、不启停进程 |
45
46
 
46
47
  ## ✨ 亮点
47
48
 
@@ -51,7 +52,7 @@
51
52
  - **事务化卸载**(v1.0 加固):卸载前**影响预览与体检** → 备份 → `pnpm remove` → 清理补丁条目 → 逐项验证 → **失败自动回滚**;卸载后可**一键撤销**
52
53
  - **操作历史 + 场景方案**:最近 20 次操作留痕可撤销;插件组合保存为命名场景,一键切换(应用前展示变更预览)
53
54
  - **兜底页独立于引擎**(v1.0):引擎挂了,`http://127.0.0.1:3081/plugins` 依然能启停 / 更新 / 卸载 / 体检 / 重启引擎
54
- - **多源更新聚合**:npm registry / 插件超市 dshfind / GitHub / 自定义镜像并行查询,限流熔断,公平取最高版本
55
+ - **多源更新聚合**:npm registry / GitHub / 自定义镜像并行查询,限流熔断,公平取最高版本
55
56
  - **浏览器即启动器**:主页设为 `http://127.0.0.1:3081/`,打开浏览器 = 自动自检 → 修复 → 启动 → 跳转主界面
56
57
  - **本地写接口有防护**(v0.9.1):`Origin`(同机同端口白名单)+ 一次性令牌 + 单飞闸门,第三方网页无法触发启动/停止
57
58
 
@@ -80,7 +81,7 @@
80
81
 
81
82
  - **官方内置(可选)**:引擎自带、默认未启用的组合包一键启用/停用 + 版本豁免
82
83
  - **全部插件**:插件清单(见上文分区模型)
83
- - **插件市场**:dshfind 精选目录,一键安装(见下文)
84
+ - **插件市场**:ADP 精选目录,一键安装(见下文)
84
85
  - **操作与场景**:事务化卸载与影响预览、**卸载前体检**、操作历史一键撤销、场景方案
85
86
  - **维护**:更新源与刷新、启动前自检、救援中心入口、下载目录
86
87
 
@@ -112,7 +113,7 @@
112
113
 
113
114
  ### 🛒 插件市场
114
115
 
115
- - **dshfind 精选目录**:带本地化描述 / 星标 / 收录日期与分类;条目数随上游变化,host 端 10 分钟缓存。在线不可用自动兜底 GitHub `topic:dsh-plugin` 搜索
116
+ - **ADP 精选目录**:数据来自 awesome-dsh-plugin 收录池,带本地化描述 / 星标 / 收录日期与分类;条目数随上游变化,host 端 10 分钟缓存
116
117
  - **零往返过滤**:目录一次拉全量,搜索 / 分类 chips / 排序 / 分页全部客户端本地完成
117
118
  - **一键安装**:带 npm 名的条目优先 **npm registry 直装**;GitHub 仓库走内置下载器;两步确认防误触;已装 ✓ 徽标
118
119
  - **装后防砖校验**:自动验证 `dsh.bundle` / `dsh.client` 清单,缺失自动卸载;pnpm hoist 漂移 / `minimumReleaseAge` 陷阱自动恢复
@@ -166,6 +167,104 @@
166
167
  >
167
168
  > ⚠️ **实现注意**:自启包装脚本一律「wscript → node」,不用隐藏 PowerShell(会被部分杀软误判删除);守护拉起引擎时刻意不加 `windowsHide`。
168
169
 
170
+ ## 🖥️ 桌面版(DSH Desktop)支持(v1.1.0 新增)
171
+
172
+ > **一句话定位**:桌面版不是"加个 target",而是把 drydock 的**控制面**降级成「编排层 + 只读诊断 + 离线修复」。
173
+ > 网页版保持"我全权负责",桌面版承认"**应用负责执行,我负责判断、记录、修下一次启动**"。
174
+
175
+ ### 为什么只做灾备,不做接管
176
+
177
+ 桌面版官方已经把安装、启停、更新、卸载、内置运行时、单实例锁、后台任务、崩溃恢复、操作日志、更新协调**全部吃进 app 了**。你在桌面版做管理台,是去跟官方抢同一个正面位置,而且会撞上一条硬约束:
178
+
179
+ 官方 `@deepseek-ai/dsh-official-bundles` 导出的 `PROTECTED_PLUGINS`(17 项)里明确包含 **`@deepseek-ai/dsh-client-ui-plugin-manager`**,注释原文是 *"Plugin packages the plugin manager refuses to disable or remove, because management itself needs them"*。drydock 在网页版接管插件页的核心动作,正是**停用这个包**。网页版靠 patch 层能跑,桌面版一旦失效就是**静默空白**(官方 issue #2403 已证明这类失效不报错)。
180
+
181
+ 而桌面版真正剩下的缺口是:**Electron 起不来 / 插件把引擎拖死时,用户没有任何出路**——他们不会开终端、不知道 `DSH_HOME` 在哪、看不懂 `cordis.patch.yml`、连日志在哪都不知道。官方的 `fatal-recovery` 再完善也在 Electron 进程里;**进程起不来它就不在**。
182
+
183
+ 所以 drydock 在桌面版只做三件官方覆盖不到的事:**离线只读诊断、恢复后自愈、官方通道重建救援 profile**。
184
+
185
+ ### 能力边界(不默默缺失)
186
+
187
+ | 能力 | 网页版 | 桌面版 | 桌面版为什么这样 |
188
+ |---|:--:|:--:|---|
189
+ | 接管官方插件页 | ✅ | ❌ | 撞 `PROTECTED_PLUGINS`;失效形态是静默空白 |
190
+ | 现跑 pnpm 增删 | ✅ | ⛔ 门控 | Electron 持 `profiles/desktop/lock` 时**一律拒绝**;需完全退出后重开 |
191
+ | 启停/配置热切换 | ✅ | 🟡 分级授权 | 允许 `cordis.patch.yml` 级可逆写(有备份、只动带归属标记的行),**不做** pnpm 级增删 |
192
+ | 开机自启 / 浏览器即启动器 | ✅ | ❌ | 官方托盘 + 后台任务 + 更新协调已覆盖;叠加 = 双份自启抢 `HKCU\Run` |
193
+ | 内置插件市场 | ✅ | ❌ | 交给官方 `dsh-experimental-plugin-market-bundle` + dshmarket |
194
+ | 拉起 / 停止 / 重启引擎 | ✅ | ❌ | 单实例 + 特权 IPC 是应用的;抢了就变成"装了 drydock 桌面版起不来" |
195
+ | **离线只读诊断报告** | ✅ | ✅ **主战场** | 官方没有;普通用户最缺 |
196
+ | **恢复后自愈** | — | ✅ **主战场** | 官方恢复会埋掉运维层(见下) |
197
+ | **官方通道重建救援 profile** | ✅ | ✅ **主战场** | 走 `dsh rescue --from-default-profile web` |
198
+
199
+ > UI 上被关掉的每一项都能点开看**一句话理由**("灰着但告诉你为什么")。"能点但失败"是最差形态。
200
+
201
+ ### 三个桌面版专用入口
202
+
203
+ ```sh
204
+ # ① 离线只读诊断:不写盘、不碰锁、不启停进程;产出可直接粘贴给插件作者/官方的中文报告
205
+ npx dsh-drydock-doctor # 人读报告
206
+ npx dsh-drydock-doctor --json # 机器可读
207
+ npx dsh-drydock-doctor --profile desktop --include-logs
208
+ npx dsh-drydock-doctor --out 诊断.txt # 显式落盘(默认不落盘)
209
+
210
+ # ② 官方恢复后自愈:官方恢复把 cordis.patch.yml 改名 .bak-<时间戳> 并建空 patch,
211
+ # 你的归属行/开关行/隔离行全丢 —— 从侧车 plugin-manager.json 与 .rescue-bak-* 重建
212
+ npx dsh-drydock-boot --heal-recovery # 默认 dry-run:只打印计划,不动盘
213
+ npx dsh-drydock-boot --heal-recovery --apply --confirm web # 真写(要双确认)
214
+
215
+ # ③ 走官方通道重建救援 profile(不碰 desktop profile、不需要绕官方门禁)
216
+ npx dsh-drydock-boot --rescue-profile
217
+ ```
218
+
219
+ **自愈的安全边界**:桌面版持锁时**整个目录一个字节都不改**,并明确告诉你"请从系统托盘**完全退出**(不是关窗口)后重开";只动带归属标记的行;写前 `.rescue-bak-*` 备份、原子写、写完重读复检、失败自动回滚;**不写 `package.json`、不碰 `node_modules`、不写 `state.json`**。
220
+
221
+ ### 官方恢复到底干了什么(这是自愈的存在理由)
222
+
223
+ 官方桌面版的致命故障恢复对话框("禁用第三方插件、备份 profile patch 并重启")在官方文档里写得很清楚:
224
+
225
+ > 原生恢复操作在 profile 事务锁内调用共享 app-boot 恢复函数。它**禁用第三方 bundle**,并将 profile 的 `cordis.patch.yml` **重命名为 `cordis.patch.yml.bak-<timestamp>`**,无需解析;下次启动创建**空 patch**。已安装包和已有备份保留。
226
+
227
+ → 官方**救活了引擎**,代价是把 drydock 的运维层一起埋了。
228
+ → drydock 的差异就在这里:**"它修这次启动,我们修下一次为什么还会坏。"**
229
+
230
+ ### 双端安装(同一份包,各自独立 profile)
231
+
232
+ ```sh
233
+ # 网页版(不变)
234
+ dsh plugin --profile web add dsh-drydock
235
+
236
+ # 桌面版:官方桌面应用内「插件」页安装(推荐),或
237
+ # 1) 先启动一次桌面版以初始化 profiles/desktop
238
+ # 2) 从系统托盘完全退出桌面版
239
+ # 3) 用桌面版自带的 CLI(不是 npm 的 dsh)执行:
240
+ dsh plugin --profile desktop add dsh-drydock
241
+ # 4) 重开桌面版;在设置里显式确认插件已启用
242
+ ```
243
+
244
+ > ⚠️ **npm 安装的 `dsh` 无法修改桌面版 profile**:官方 CLI 对 `profile "desktop"` 显式报错
245
+ > `profile "desktop" is managed exclusively by the Electron application`,且桌面版独占 `$DSH_HOME/profiles/desktop`、
246
+ > 单实例锁与包管理器状态。drydock 对 desktop profile **只做纯 Node 文件读写**(且要求 Electron 已退出)。
247
+
248
+ ### 兼容性(v1.1.0 实测范围)
249
+
250
+ | 项 | 状态 |
251
+ |---|---|
252
+ | 已装官方桌面版 | **0.2.2-rc.5 win-x64**(官方 CDN 固定下载,SHA-512 与官方 feed 一致) |
253
+ | 桌面壳与 dsh 版本 | **同一精确版本**(官方规则:升级 dsh 必须发新桌面版) |
254
+ | 静态核对 | 已解包 `resources/app.asar` 逐项核对:来源判定值 `dsh-app://app`、`profiles/desktop` + `lock` 路径、`desktop-runtime.json` 字段、`ELECTRON_RUN_AS_NODE` 启动方式 |
255
+ | 真机验证 | ⏳ **待做**(本机未安装桌面版;全部桌面能力以 fixture + 注入式探测单测覆盖,见 `npm run test:desktop`) |
256
+
257
+ ### 给开发者:能力门控表在哪
258
+
259
+ 运行时探测 → 一张表 → UI 按表渲染,**不散落 `if (isDesktop)`**:
260
+
261
+ - `lib/envprobe.mjs`:`probeEnv()`(判定 `web`/`desktop`/`unknown` + home 候选 + 桌面锁 + 宿主版本 + 端口候选)
262
+ - `lib/capabilities.mjs`:`CAPABILITIES`(**web 全 true → 网页版零回归**)、`capabilityReason()`、`assertCapability()`
263
+ - `lib/bundles-official.mjs`:直接 import 官方 `PROTECTED_PLUGINS` / `HIDDEN_BUNDLES` / `PROFILE_TEMPLATES`,带静态回落副本
264
+
265
+ > 设计契约全文:[docs/桌面版移植-1.1.0设计.md](docs/桌面版移植-1.1.0设计.md);
266
+ > 官方一手事实核查(含真包静态分析证据链):`桌面移植/官方事实核查-2026-11-26.md`(工作区文档,不在包内)。
267
+
169
268
  ## 环境要求
170
269
 
171
270
  - Windows 10/11 · macOS · Linux(`/rescue` 与三个 bin 工具全平台可用;**开机自启管理目前为 Windows**)
@@ -176,11 +275,17 @@
176
275
 
177
276
  | 你的 DSH 引擎 | 本管理器版本 | 说明 |
178
277
  |---|---|---|
179
- | **≥ 0.1.7-rc.2**(含 0.2.x,`<0.3.0-0`) | **1.0.0**(推荐)/ 0.9.1 | 独立插件页 + 兜底页 + 救援工具链全套;1.0.0 实测于 0.2.x 引擎(三分区 / 统一口径 / 事务卸载,隔离环境 + 主环境双验证) |
278
+ | **≥ 0.1.7-rc.2**(含 0.2.x,`<0.3.0-0`) | **1.1.0**(推荐)/ 1.0.1 / 0.9.1 | 独立插件页 + 兜底页 + 救援工具链全套;**1.1.0 新增桌面版支持**(能力门控 / 离线诊断 / 恢复后自愈 / 官方 rescue profile 通道),网页版行为与 1.0.x 一致 |
180
279
  | 0.1.6 及以后 | 0.9.1 | 官方 0.1.6 起内置插件管理页,本包接管(停用 `ui-plugin-manager` + 自己的行 id) |
181
280
  | **0.1.0-rc.6 ~ 0.1.5**(老引擎) | **0.8.2** | 旧「设置 → 插件」tab 路线;0.8.x 在 0.1.7 上不成立(typert strict codec / runtime 依赖移除) |
182
281
 
183
- > **一句话**:引擎越新越要 1.0.0;引擎很老(0.1.6 之前)才需要 0.8.2。回退:`dsh plugin --profile web add dsh-plugin-manager-pro@0.8.2`。
282
+ | 运行形态 | 支持情况 | 说明 |
283
+ |---|---|---|
284
+ | 网页版(`dsh web`,默认 3080) | ✅ 全功能 | 本文档上半部分的全部能力 |
285
+ | **官方桌面版(DSH Desktop)** | ✅ **灾备子集** | v1.1.0 起:离线诊断、恢复后自愈、官方通道重建救援 profile、`cordis.patch.yml` 级可逆启停(需 Electron 已退出)。**不接管插件页 / 不自启 / 不抢引擎生命周期**(见 [桌面版支持](#️-桌面版dsh-desktop支持v110-新增)) |
286
+ | 社区壳(Tauri / Wails 等) | ⚠️ 未验证 | 走同一套能力探测;识别不出形态时**退回网页版全能力**并给出中文原因 |
287
+
288
+ > **一句话**:引擎越新越要 1.1.0;引擎很老(0.1.6 之前)才需要 0.8.2。回退:`dsh plugin --profile web add dsh-plugin-manager-pro@0.8.2`。
184
289
 
185
290
  ## 🔐 权限与数据范围
186
291
 
@@ -194,7 +299,7 @@
194
299
  | `~/.dsh/profiles/<名字>/node_modules/**` | 读依赖反向图与包简介;卸载/隔离时经 `pnpm` 删除 | 否(装卸时由 pnpm 访问 registry) |
195
300
  | `$DSH_HOME/downloads/*` | 「下载目录自动安装」扫描归档;写 `.installed` / `.failed` 标记 | 否 |
196
301
  | 本机 npm 全局根 | **只读**:定位引擎自带的 `@deepseek-ai/*`、提取简介 | 否 |
197
- | 更新源(npm registry / dshfind / GitHub / 你加的镜像) | 查询最新版本、下载归档 | **只查询**,不上传本地数据 |
302
+ | 更新源(npm registry / GitHub / 你加的镜像) | 查询最新版本、下载归档 | **只查询**,不上传本地数据 |
198
303
  | 本机回环端口 3080 / 3081 / 3082 / 4081 | 主界面 / 启动器 / 备份救援 / 守护锁;全部只绑 `127.0.0.1` | 否(不出本机) |
199
304
  | Windows 注册表 `HKCU\...\Run\DSHWebFront` | **仅在显式执行 `--install-autostart` 时写入**;`--uninstall-autostart` 可清理 | 否 |
200
305
  | profile 内 `.rescue-daemon.pid`、`.open-boot.pid`、`health.log` 等 | 守护/启动器的 PID、日志与自检留痕(7 天 / 1000 行) | 否 |
@@ -0,0 +1,239 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * drydock-doctor.mjs — 离线只读诊断报告 CLI(1.1.0 桌面版支持 M4)。
4
+ *
5
+ * 设计目标(用户视角):Electron 起不来的时候,普通用户不会开终端、不知道 DSH_HOME
6
+ * 在哪、看不懂 cordis.patch.yml、连日志在哪也不知道。这条命令要能一条命令产出
7
+ * **一份用户能直接粘贴给插件作者/官方**的诊断文本,且**零风险**:
8
+ * - 默认只把中文报告打到 stdout,**不落盘**;
9
+ * - 不写 profile、不启停进程、不解析日志取 token(详见 lib/diagnostics.mjs 的只读承诺)。
10
+ *
11
+ * 用法(对齐 bin/dsh-boot.mjs 的风格:--help / isDirectRun() 保护 / 退出码语义):
12
+ * node bin/drydock-doctor.mjs 人读中文报告(stdout)
13
+ * node bin/drydock-doctor.mjs --json 机器可读 JSON(stdout)
14
+ * node bin/drydock-doctor.mjs --out <file> 同时落盘(默认不落盘;落盘路径打印到 stderr)
15
+ * node bin/drydock-doctor.mjs --profile web 聚焦某个 profile(名称或目录)
16
+ * node bin/drydock-doctor.mjs --home D:\x 覆盖 DSH_HOME
17
+ * node bin/drydock-doctor.mjs --include-logs / --no-logs 是否包含日志尾部(默认不含)
18
+ *
19
+ * 退出码:
20
+ * 0 = 收集完成(**即使有 unavailable 段**也算成功:缺数据不等于失败)
21
+ * 1 = 完全无法定位 DSH_HOME(或 --out 报告落盘失败)
22
+ * 2 = 参数错误(未知参数 / 选项缺取值 / --include-logs 与 --no-logs 互斥)
23
+ *
24
+ * 注意:本文件**不注册进 package.json 的 bin**(那是共享文件,由 lead 统一改);
25
+ * 建议的 bin 行见交付说明。
26
+ */
27
+ import { realpathSync, writeFileSync } from "node:fs";
28
+ import { resolve, sep } from "node:path";
29
+ import { fileURLToPath } from "node:url";
30
+ import { collectDiagnostics, defaultResourcesDirs, renderReport, SCHEMA } from "../lib/diagnostics.mjs";
31
+
32
+ const SELF = fileURLToPath(import.meta.url);
33
+
34
+ const HELP_TEXT = `dsh-drydock 离线只读诊断报告(drydock-doctor)
35
+
36
+ 用法:
37
+ node bin/drydock-doctor.mjs [选项]
38
+
39
+ 选项:
40
+ --json 输出机器可读 JSON(默认输出人读中文报告)
41
+ --out <file> 同时把报告写入文件(默认不落盘;落盘绝对路径打印到 stderr)
42
+ --profile <name|dir>
43
+ 只聚焦某个 profile(名称如 web / desktop,或直接给目录)
44
+ --home <dir> 覆盖 DSH_HOME(默认按 $DSH_HOME > ~/.dsh 解析)
45
+ --include-logs 包含引擎日志尾部(每 profile 最多 64 KiB,官方 stderr 口径)
46
+ --no-logs 不包含引擎日志尾部(默认行为;与 --include-logs 互斥)
47
+ --help, -h 显示本帮助
48
+
49
+ 报告内容(数据源按官方桌面版诊断文档 + 真包静态分析):
50
+ · 环境 / DSH_HOME 与全部候选(解析优先级:--home > $DSH_HOME > ~/.dsh)
51
+ · profile 清单:package.json、cordis.patch.yml(大小/BOM/是否空 patch/条目数)、
52
+ lock、.open-boot.pid、drydock 侧车 plugin-manager.json、.dsh-market/state.json
53
+ · 桌面 profile 状态:是否初始化、lock 内容(截断 200 字符)、dsh.profile.bundles
54
+ · 桌面宿主:安装目录 resources/app.asar/dsh/desktop-runtime.json 的 release
55
+ (version / hostProtocolVersion / nodeVersion / pnpmVersion,只读前部、不整读 4.7 MB)、
56
+ resources/runtime/versions.json、桌面自带 CLI(不是 npm 的 dsh)
57
+ · 官方恢复痕迹检测(空 patch + cordis.patch.yml.bak-<时间戳> → 建议"恢复后自愈")
58
+ · 崩溃报告 <userData>/logs/crash-<UTC>-<source>.log(最新 3 份,每份只读前 4 KiB)
59
+ · 插件操作记录 <userData>/plugin-operations(最多 100 条 / 64 KiB)
60
+ · 端口事实:候选端口清单 + 每个端口是否有监听(**不**据此断言引擎健康)
61
+
62
+ 退出码:
63
+ 0 = 收集完成(即使有"不可用"段)
64
+ 1 = 完全无法定位 DSH_HOME(或报告落盘失败)
65
+ 2 = 参数错误(含 --out 指向桌面安装目录:那里只读,拒绝写入)
66
+
67
+ 示例:
68
+ node bin/drydock-doctor.mjs --profile desktop --json --out .\\doctor.json
69
+ node bin/drydock-doctor.mjs --home "D:\\dsh-home" --include-logs
70
+ DSH_DESKTOP_RESOURCES_DIR="C:\\...\\resources" node bin/drydock-doctor.mjs # 已解包的安装目录
71
+
72
+ 说明:报告已脱敏(令牌/密钥/邮箱/绝对路径里的用户名);含"不可用"段属正常,
73
+ 表示那一项在你这台机器上不存在(例如没装桌面版就没有崩溃报告)。
74
+ 桌面安装目录里的 app.asar / desktop-runtime.json 只读,不会写;--out 默认不落盘,
75
+ 显式落盘时写到用户指定路径(落在桌面安装目录会被拒绝)。
76
+ `;
77
+
78
+ /**
79
+ * 解析 argv。错误进 `errors`(由 main 转成退出码 2),不在解析阶段直接退出。
80
+ */
81
+ function parseArgs(argv) {
82
+ const args = {
83
+ help: false,
84
+ json: false,
85
+ out: null,
86
+ profile: null,
87
+ home: null,
88
+ includeLogs: false,
89
+ errors: []
90
+ };
91
+ const wantValue = (option, index) => {
92
+ const value = argv[index + 1];
93
+ if (value === undefined || value === "" || (value.startsWith("-") && value !== "-")) {
94
+ args.errors.push(`选项 ${option} 缺少取值`);
95
+ return null;
96
+ }
97
+ return value;
98
+ };
99
+ let sawInclude = false;
100
+ let sawNoLogs = false;
101
+ for (let index = 0; index < argv.length; index += 1) {
102
+ const argument = argv[index];
103
+ switch (argument) {
104
+ case "--help":
105
+ case "-h":
106
+ args.help = true;
107
+ break;
108
+ case "--json":
109
+ args.json = true;
110
+ break;
111
+ case "--include-logs":
112
+ sawInclude = true;
113
+ break;
114
+ case "--no-logs":
115
+ sawNoLogs = true;
116
+ break;
117
+ case "--out": {
118
+ const value = wantValue(argument, index);
119
+ if (value !== null) {
120
+ args.out = value;
121
+ index += 1;
122
+ }
123
+ break;
124
+ }
125
+ case "--profile": {
126
+ const value = wantValue(argument, index);
127
+ if (value !== null) {
128
+ args.profile = value;
129
+ index += 1;
130
+ }
131
+ break;
132
+ }
133
+ case "--home": {
134
+ const value = wantValue(argument, index);
135
+ if (value !== null) {
136
+ args.home = value;
137
+ index += 1;
138
+ }
139
+ break;
140
+ }
141
+ default:
142
+ if (argument.startsWith("-")) args.errors.push(`无法识别的参数 ${argument}`);
143
+ else args.errors.push(`多余的位置参数 ${argument}`);
144
+ break;
145
+ }
146
+ }
147
+ if (sawInclude && sawNoLogs) args.errors.push("--include-logs 与 --no-logs 互斥,只能选一个");
148
+ args.includeLogs = sawInclude;
149
+ return args;
150
+ }
151
+
152
+ /**
153
+ * 桌面安装目录只读:`--out` 落在 `<安装目录>/resources` 里一律拒绝(app.asar / desktop-runtime.json
154
+ * 只读)。返回"包含该目标的安装目录"或 null。
155
+ */
156
+ function installDirContaining(target) {
157
+ const normalized = target.replace(/\//g, "\\").toLowerCase();
158
+ for (const dir of defaultResourcesDirs({})) {
159
+ const base = dir.replace(/\//g, "\\").replace(/\\+$/, "").toLowerCase();
160
+ if (normalized === base || normalized.startsWith(`${base}\\`)) return dir;
161
+ }
162
+ return null;
163
+ }
164
+
165
+ async function main() {
166
+ const args = parseArgs(process.argv.slice(2));
167
+ if (args.help) {
168
+ process.stdout.write(HELP_TEXT);
169
+ return 0;
170
+ }
171
+ if (args.errors.length > 0) {
172
+ console.error(`[drydock-doctor] 参数错误:${args.errors.join(";")}`);
173
+ console.error("[drydock-doctor] 用 --help 查看用法。");
174
+ return 2;
175
+ }
176
+ const outTarget = args.out ? resolve(args.out) : null;
177
+ if (outTarget) {
178
+ const blocked = installDirContaining(outTarget);
179
+ if (blocked) {
180
+ console.error(`[drydock-doctor] 拒绝把报告写进桌面安装目录:${outTarget}`);
181
+ console.error(`[drydock-doctor] 安装目录(${blocked})里的 app.asar / desktop-runtime.json 只读;请换一个输出路径。退出码 2`);
182
+ return 2;
183
+ }
184
+ }
185
+
186
+ const diagnostics = await collectDiagnostics({
187
+ dshHome: args.home,
188
+ profile: args.profile,
189
+ includeLogs: args.includeLogs
190
+ });
191
+ const text = args.json ? JSON.stringify(diagnostics, null, 2) : renderReport(diagnostics);
192
+ process.stdout.write(text.endsWith("\n") ? text : `${text}\n`);
193
+
194
+ if (args.out) {
195
+ const target = outTarget ?? resolve(args.out);
196
+ try {
197
+ writeFileSync(target, text.endsWith("\n") ? text : `${text}\n`, "utf8");
198
+ } catch (error) {
199
+ // 落盘失败不影响已经打到 stdout 的报告;但明确报错 + 非 0 退出,绝不静默
200
+ console.error(`[drydock-doctor] 报告落盘失败:${target}(${error.code ?? error.message});上面的报告仍已输出到 stdout。`);
201
+ return 1;
202
+ }
203
+ console.error(`[drydock-doctor] 报告已写入:${target}(未使用 --out 时默认不落盘)`);
204
+ }
205
+
206
+ if (!diagnostics.home.resolved) {
207
+ console.error(`[drydock-doctor] 无法定位 DSH_HOME(见报告「DSH_HOME」段):可用 --home <dir> 指定。退出码 1`);
208
+ return 1;
209
+ }
210
+ return 0;
211
+ }
212
+
213
+ /**
214
+ * 只在"直接运行本文件"时执行入口(被 import 时不执行,便于测试)。
215
+ * 语义与 bin/dsh-boot.mjs:151-162 完全对齐(同一判定,不另写一套)。
216
+ */
217
+ function isDirectRun() {
218
+ if (process.env.DSH_LAUNCHER_IMPORT_ONLY === "1") return false;
219
+ const entry = process.argv[1];
220
+ if (!entry) return false;
221
+ const norm = (path) => {
222
+ try {
223
+ return realpathSync(path).replace(/\\/g, "/").toLowerCase();
224
+ } catch {
225
+ try {
226
+ return resolve(path).replace(/\\/g, "/").toLowerCase();
227
+ } catch {
228
+ return path;
229
+ }
230
+ }
231
+ };
232
+ return norm(entry) === norm(SELF);
233
+ }
234
+
235
+ if (isDirectRun()) {
236
+ process.exit(await main());
237
+ }
238
+
239
+ export { HELP_TEXT, SCHEMA, main, parseArgs };
package/bin/dsh-boot.cmd CHANGED
@@ -36,6 +36,10 @@ if "%EXITCODE%"=="0" (
36
36
  ) else if "%EXITCODE%"=="2" (
37
37
  echo [dsh-boot] REPAIR INCOMPLETE - run: dsh-boot.cmd --repair-only
38
38
  echo and fix the listed issues manually.
39
+ ) else if "%EXITCODE%"=="3" (
40
+ echo [dsh-boot] REFUSED BY SAFETY GATE - nothing was changed.
41
+ echo locked desktop profile / missing --confirm / missing --allow-desktop / desktop spawn refused.
42
+ echo Details: dsh-boot.cmd --help (exit code 3 is documented there)
39
43
  ) else (
40
44
  echo [dsh-boot] UNKNOWN - exit code %EXITCODE%
41
45
  )