ygc-dsh-plugin-autoupdate 0.9.1 → 0.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -45,18 +45,63 @@
45
45
  `ctx.get('desktopActions')`),插件直接调它。桌面 shell 自己 `app.relaunch()` 并无确认退出,
46
46
  把这次退出当作**预期内**的退出,因此**不会弹「启动失败」恢复框、不写 crash report**。
47
47
 
48
- ### 通道二:进程树之外的助手(兜底)
48
+ ### 通道二:进程树之外的助手(实际生效的那条)
49
49
 
50
50
  拿不到官方通道时才走这条。插件不自杀——它把重启助手**送到调用树之外**,由助手负责:
51
51
 
52
52
  1. 等 `restartDelaySeconds`(默认 0 秒)
53
- 2. **等旧 Electron main 自己退出**(默认最多 15 秒,`exitWaitMs` 可调)——它自己退了就一步强制动作都不做
54
- 3. 仍没退出,先 `taskkill /PID <main>`(**不带 `/F`**,等于发 WM_CLOSE,走 `app.quit()` 正常收尾);
55
- 仍不领情才 `/T /F`
53
+ 2. **按可执行文件路径**枚举所有同程序进程(main / host / renderer / gpu 都在内),排除助手自己
54
+ 3. 给 250ms 让正在写盘的日志收尾,然后 **`taskkill /PID <n…> /F` 一次性批量结束**
56
55
  4. 用 `process.execPath` 重新拉起,Windows 上带 `--updated`(窗口会自己置前台)
57
56
  5. 删掉跨进程锁,下一次重启才能正常排期
58
57
 
59
- 全程写 `~/.dsh/storages/plugin-autoupdate/restart.log`。
58
+ 全程写 `~/.dsh/storages/plugin-autoupdate/restart.log`。**端到端实测 ≤ 5 秒**
59
+ (`test/restart-speed.e2e.mjs`,三份同程序进程一次清掉)。
60
+
61
+ ### 0.9.2 修的「点重启完全没反应」(最直接的那条)
62
+
63
+ 用户原话:**「purge 是弹出来重启客户端,我点一下就立刻重启了;你这边我点了完全没反应。」**
64
+
65
+ 对照 dsh-purge 的实现找到了两个原因:
66
+
67
+ **原因一:助手顶着应用的名字,被别人的映像名清场打死。**
68
+
69
+ `process.execPath` 在宿主里是 `C:\DeepSeekHarness\DeepSeek Harness.exe`,
70
+ 所以 0.9.x 的助手**也叫 `DeepSeek Harness.exe`**。dsh-purge 的 helper 正是按
71
+ `DeepSeek Harness.exe` 枚举后逐个结束的(只排除它自己)——我的助手在那张名单里。
72
+ 12:03 那次重启的现场就是证据:
73
+
74
+ ```
75
+ 我的日志: [helper] start; ... self=21860
76
+ ← 之后再无任何一行(没有「等待期内未退出」,没有 relaunched)
77
+ purge 日志: relaunched via execPath ← 34 秒后,DSH 是 purge 拉回来的
78
+ ```
79
+
80
+ 现在助手由安装包自带的
81
+ `resources\runtime\primary-runtime\dependencies\node\bin\node.exe` 跑,
82
+ 映像是 `node.exe`:任何按 `DeepSeek Harness.exe` 的清场都碰不到它,
83
+ 也不再需要 `ELECTRON_RUN_AS_NODE` 那个开关(只在拿不到 node.exe 的退路上用)。
84
+
85
+ **原因二:流程里有最长 31 秒的沉默,其中一步还会弹模态框。**
86
+
87
+ | 步骤 | 旧行为 | 为什么致命 |
88
+ |---|---|---|
89
+ | 等旧 main 退出 | 15 秒 | 用户点完什么都看不到 |
90
+ | 「礼貌退出」 | 8 秒 | `taskkill` 不带 `/F` = 发 WM_CLOSE → 桌面 `before-quit` 会 `preventDefault()` 并弹原生「退出 DeepSeek Harness?当前正在运行的任务将会中断」,**不点就永远不退** |
91
+ | 强杀 | 8 秒 | 到这一步用户早已认定「没反应」 |
92
+
93
+ purge 的助手是直接 terminate,所以「点一下立刻重启」。0.9.2 对齐它:
94
+ 不做 WM_CLOSE、批量 `/F`、固定等待合计 ≤ 500ms。
95
+
96
+ **顺带修的两个隐患:**
97
+
98
+ - **按路径枚举必须加闸门。** 纯 node 环境里 `process.execPath` 是 `node.exe`,
99
+ 若照旧按路径扫会把机器上所有 node 进程杀光(实测一次带走 4 个,包括测试进程和
100
+ bash 作业运行器)。`canEnumerateByPath()` 只允许「应用自己的 exe」走路径模式,
101
+ node 一律退回显式 pid 名单。
102
+ - **新实例的 stderr 必须落盘。** 原来 `stdio: 'ignore'` 让 `Cannot find module …`
103
+ 这类错误彻底消失 —— 日志里只有 `relaunched`,实际上新实例根本没起来。
104
+ 现在写到同目录的 `relaunch-stderr.log`。
60
105
 
61
106
  ### 0.9.0 修的两条「重启之后 DSH 就没了」(实测复现 + 回归测试)
62
107
 
@@ -67,12 +112,12 @@
67
112
  日志停在「兜底结束旧宿主 pid=…」,`relaunched` 永远不出现。
68
113
  实测确认:`taskkill /T` 连 detached 子进程一起杀。
69
114
 
70
- 现在两条路把助手送走:
115
+ 现在把助手送走:
71
116
 
72
117
  | 通道 | 父进程 | 说明 |
73
118
  |---|---|---|
74
119
  | **WMI** `Win32_Process.Create`(首选) | `WmiPrvSE.exe` | 压根不在调用树里,`/T` 走不到 |
75
- | **两跳孤儿**(WMI 不可用时) | 已退出的第一跳 | 第一跳拉起第二跳后立刻 `exit(0)`,`/T` 顺树找不到它 |
120
+ | **detached spawn**(WMI 不可用时) | 调用方 | 兜底;助手映像是 `node.exe`,不会与 `DeepSeek Harness.exe` 混淆 |
76
121
 
77
122
  **故障二:结束的是宿主(Host),不是 Electron main。**
78
123
 
@@ -115,10 +160,13 @@ Electron 的 main / gpu-process / renderer / utility,以及以 `ELECTRON_RUN_A
115
160
  - 把自己的 renderer 一起打死 → `Desktop renderer exited: launch-failed` 崩溃日志
116
161
  - 用户看到的是 **DSH 无预警消失、随后自动重开**,完全不像「更新完成后的正常重启」
117
162
 
118
- 0.8.0 起助手只认两个明确的 pid:**自己**(`process.pid`,永不动)与
119
- **调用方登记的旧宿主**(`mainPid`)。这条边界由 `test/restart-safety.test.mjs`
163
+ 0.8.0 起到现在,助手从不按映像名做事:它按**可执行文件路径**枚举、
164
+ 排除自己、一次批量 `/F`。这条边界由 `test/restart-safety.test.mjs`
120
165
  以源码契约钉死(`tasklist` 不得出现 `IMAGENAME`、`taskkill` 必须带 `/PID` 且不得带 `/IM`)。
121
166
 
167
+ 0.9.2 额外把「按路径枚举」本身也加了闸门:只有目标是**应用自己的 exe** 时才允许,
168
+ `node.exe` 一律退回显式 pid 名单 —— 否则在纯 node 环境里会把机器上所有 node 进程扫掉。
169
+
122
170
  「只在没有会话正在跑的时候重启」默认开着:判定依据是最近 90 秒内有没有会话事件。
123
171
  有会话时重启会被推迟,等空闲了再执行。**手动卸载与手动重启不受这条约束。**
124
172
 
@@ -345,7 +393,7 @@ $node = "C:\DeepSeekHarness\resources\runtime\primary-runtime\dependencies\node\
345
393
  & $node "C:\DSH-Work\plugin-autoupdate\pkg\test\all.mjs"
346
394
  ```
347
395
 
348
- 十六个套件:
396
+ 二十二个套件(含 6 个 e2e):
349
397
 
350
398
  | 套件 | 覆盖 |
351
399
  |---|---|
@@ -358,12 +406,16 @@ $node = "C:\DeepSeekHarness\resources\runtime\primary-runtime\dependencies\node\
358
406
  | `machine.test.mjs` | 本机标识:继承会话同步的 machineId、固定后不漂移、改名不换特征值、卸载会话同步后旧值仍有效、写边界(别人的格 / `../` 逃逸 / 前缀相近) |
359
407
  | `share.test.mjs` | 特征文件夹:清单分类(registry 只写名 / 本地打副本 / 宿主自带不写)、tgz 结构、同步幂等与副本复用、他人清单合并去重、安装路径选择、特征名防上跳 |
360
408
  | `schedule.test.mjs` | 定时排期:更新与共享同步各自独立开关 |
361
- | `restart-safety.test.mjs` | **重启安全契约**(源码级):不得按映像名杀进程、必须排除自身、必须先等再兜底、助手须由 WMI/两跳送出进程树、须先礼后兵、须有冷却与锁、launcher 须设 `ELECTRON_RUN_AS_NODE` |
409
+ | `system-plugins.test.mjs` | **系统插件显示契约**(源码级):宿主清单是版本第二来源、版本回落顺序、宿主多出的名字也补进来、`installation` 不进检查、面板单独成组且不给策略/更新/刷新 |
410
+ | `system-plugins.behavior.test.mjs` | **系统插件显示行为**(真执行 + 假宿主):版本真的从宿主补出来、缺失 `pluginManager` / 抛错 / 脏数据三种降级都不让 `/state` 失败 |
411
+ | `restart-safety.test.mjs` | **重启安全契约**(源码级):不得按映像名杀、必须排除自身、枚举→批量结束→拉起的顺序固定、助手须由 WMI 送出进程树、直接 `/F` 不做 WM_CLOSE、有冷却与锁、助手解释器须优先用自带 node.exe |
412
+ | `restart-interpreter.test.mjs` | **助手解释器与安全闸门**:`canEnumerateByPath()` 拒绝 node.exe/node、payload 带闸门结果与显式 pid、固定等待 ≤ 1 秒、不再每轮重新枚举、批量 taskkill |
362
413
  | `pidtree.test.mjs` | **进程树解析**(合成进程表):Host 爬到 main、renderer 爬到同一个 main、起点缺失/父进程缺失/链过深时的边界、只在 Electron 里才爬 |
363
- | `restart-helper-behavior.test.mjs` | **助手行为**(真子进程):旧 main 自退时零强制动作、不退出时先请求正常退出再强杀、只针对登记的那个 pid、payload 读后即删 |
414
+ | `restart-helper-behavior.test.mjs` | **助手行为**(真子进程):by-pid 只结束登记的那个、空名单零动作且 <4 秒、by-path 一次收掉多份同程序进程、源码无软退出 |
364
415
  | `restart-relaunch.e2e.mjs` | **重启链路**(真进程树):助手父进程不是调用方、整树 `taskkill /T /F` 之后助手仍活着并完成 `relaunched` |
416
+ | `restart-speed.e2e.mjs` | **即时重启**(独立 exe 副本):三份同程序进程一次清掉 → 拉起新实例 → 全流程 ≤ 12 秒(实测约 4~5 秒),并断言助手不在自己的击杀名单里 |
365
417
  | `restart-env.e2e.mjs` | **环境传递**:`DSH_PROFILE` / `DSH_HOME` / `PATH` 传到新实例、白名单外的变量不落盘、新实例不带 `ELECTRON_RUN_AS_NODE` |
366
- | `restart-electron-env.e2e.mjs` | **Electron 助手模式**(真 Electron exe):launcher 能真的让 Electron 以 Node 模式跑脚本 |
418
+ | `restart-electron-env.e2e.mjs` | **退路通道**(真 Electron exe):拿不到 node.exe 时,Electron + `ELECTRON_RUN_AS_NODE` 仍能跑助手 |
367
419
  | `restart-electron-env.negative.mjs` | **负向对照**:故意不带 `ELECTRON_RUN_AS_NODE` 时脚本不执行,证明上一条断言不是空的 |
368
420
  | `uninstall.test.mjs` | **卸载契约**:未确认不出手、`installation`/不可移除的拒绝、拒绝卸自己与管理器、走 `removeBundle`、失败写 `uninstall-failed`、成功后请求重启;外加前端按钮 / 二次确认 / `canUninstall` 契约 |
369
421
  | `client-smoke.test.mjs` | 在 Node 里用假 `document` / React 求值 `client.js`,验证插槽注册、locale 注册、面板首渲染 |
@@ -376,10 +428,77 @@ $env:ELECTRON_RUN_AS_NODE = '1'
376
428
  & "C:\DeepSeekHarness\DeepSeek Harness.exe" "C:\DSH-Work\plugin-autoupdate\pkg\test\_live-pidtree.mjs"
377
429
  ```
378
430
 
431
+ ## 系统插件(随 DSH 安装提供的那些)
432
+
433
+ 面板里的「随 DSH 安装提供(N)」那一组,包括 `@deepseek-ai/dsh-base`、`dsh-web-app`、
434
+ `dsh-experimental-*` 等。它们的包在**安装目录**(`resources/app/dsh/node_modules`),
435
+ `profile/node_modules` 里没有 —— 所以:
436
+
437
+ | 数据 | 从哪来 |
438
+ |---|---|
439
+ | 名字 | profile 的 `dsh.profile.bundles`(`profileBundleNames()`) |
440
+ | **版本** | **宿主** `pluginManager.listBundles()` 的 `version` |
441
+ | 归属 | 同一接口的 `availability === 'installation'` |
442
+ | 可卸载性 | 同一接口的 `removable`(这些恒为 false) |
443
+
444
+ > **0.9.3 修的「Dsh 系统插件不在自动更新插件里显示」**:它们其实**一直**在列表里,
445
+ > 只是 `version` 读成了 `null`(只查 profile 的 node_modules),面板渲染成「未装」,
446
+ > 看着就像没列出来。现在 `listPlugins(host)` 把宿主清单当第二来源合并,
447
+ > 版本回落顺序是「profile 里实际装的 → 宿主报的 → null」。
448
+ >
449
+ > 顺带对齐了这些插件的语义:状态写「随安装」而不是「已是最新」(没联网比过就别说这话);
450
+ > 不给策略下拉、不给「立即更新」、不给「刷新」—— 它们的版本跟桌面端走,
451
+ > 查 registry 只会白打网络。检查阶段也显式跳过 `availability=installation`。
452
+
453
+ 宿主清单按 **10 秒 TTL** 缓存在 `hostBundlesCache`,由 `GET /state` 等入口惰性刷新。
454
+ 不在 `apply` 阶段拉:那时别的插件可能还没注册完,`pluginManager` 未必在。
455
+ `pluginManager` 缺失、`listBundles()` 抛错、或返回脏数据(`null` / 数字 name)都只降级,
456
+ 不会让 `/state` 失败 —— 这条由 `system-plugins.behavior.test.mjs` 逐个场景验证。
457
+
458
+ ### 五种来源,各自怎么显示(0.9.4 明确了分类)
459
+
460
+ 宿主清单的 `availability` 决定分组,`spec` 决定来源类型。两者**都**要看,
461
+ 只按其中一个分就会混组:
462
+
463
+ | 来源 | 判据 | 面板位置 | 状态文案 | 能自动更新 | 能卸载 |
464
+ |---|---|---|---|---|---|
465
+ | 随 DSH 安装 | `availability=installation` | 「随 DSH 安装提供(N)」 | 随安装 | 否 | 否 |
466
+ | **宿主知道但没装** | `availability=missing` | 「可选、本机未安装(N)」 | **未安装** | 否 | 否(无需) |
467
+ | npm registry | `kind=registry` | 「已装插件(N)」 | 可更新 / 已是最新 | 是 | 宿主说 removable 才行 |
468
+ | git 来源 | `kind=git` | 同上 | 比 commit | 是 | 同上 |
469
+ | **直链 tar 包** | `kind=local` + `spec` 是 `https://` | 「本地路径 / 直链来源」 | **直链·手动更新** | 否 | 同上 |
470
+
471
+ > **0.9.4 修的两处归类错误**(用户报「有两个插件应该是 dsh 系统插件,没有正确归类」):
472
+ > `@deepseek-ai/dsh-subagent-claude-code` 与 `-codex` 在宿主清单里是
473
+ > `availability: 'missing'`(宿主提供入口、包不在磁盘上),但旧代码
474
+ > `managed = availability !== 'installation'` 把它们划进了「已装」组,
475
+ > 同时 `kind` 又被算成 `installation`,于是显示成「随安装 + 未装」的矛盾行。
476
+ > 现在 `missing` 单列一组,状态写「未安装」,并且 `installed: false` 一并透出。
477
+ >
478
+ > 顺带把 `dsh-purge-community` 这类**直链 release tar** 标成「直链·手动更新」:
479
+ > 它的 `spec` 是 `https://github.com/.../releases/latest/download/xxx.tgz`,
480
+ > 没有版本号可比、也没有 ref 可追,说「已是最新」是假的。
481
+
482
+ ### 可卸载性:不要再自己算一遍
483
+
484
+ `listPlugins()` 直接把宿主的 `removable` / `readOnlyReason` 带在每行上
485
+ (`canUninstall` / `uninstallReadOnlyReason`),`snapshot()` 只做归一,不另起炉灶。
486
+
487
+ > **0.9.4 修的连带缺陷**:`snapshot()` 原来读 `deps._removableCache`,
488
+ > 而那个字段**从来没有被赋值**(全仓库只有一处读、零处写),
489
+ > 于是每个插件都显示「宿主未提供插件清单,无法卸载」——
490
+ > 连宿主明说 `removable: true` 的 `dsh-purge-community` 都点不动卸载。
491
+ > 另外 `refreshHostBundles()` 里字段名写成了 `removability`,与宿主的 `removable`
492
+ > 对不上,等于又丢了一层。两处一起修,`system-plugins.behavior.test.mjs`
493
+ > 用「宿主 removable=true 必须 canUninstall=true」把它钉死。
494
+
495
+
379
496
  ## 边界
380
497
 
381
498
  - 只**更新**已装插件,不安装新插件;**卸载仅限 profile 自装且宿主判定 removable 的包**(见「卸载插件」)
382
499
  - 只在 `registry` 来源上工作;`local` / `git` / `installation` 来源只显示、不处理
500
+ - **系统插件(`availability=installation`)只显示、不检查、不更新、不卸载**:
501
+ 版本跟桌面端走,`registry` 上的同名包与它无关
383
502
  - 更新失败只记历史,不自动回滚(避免把用户自己手改的清单吞掉);要回滚用 `/restore`
384
503
  - DSH 关闭期间不检查(进程内定时器的固有限制);重开后会立刻按上游发布时间重新判定
385
504
  - 共享只**同步清单与副本**,不自动安装别人的插件;安装必须人工点选
package/client.js CHANGED
@@ -180,10 +180,17 @@ function makePanel(React) {
180
180
  }
181
181
 
182
182
  const plugins = Array.isArray(snap.plugins) ? snap.plugins : [];
183
- const registryPlugins = plugins.filter((p) => p.kind === 'registry');
183
+ // 三类要分清,不能混:
184
+ // 1. 随 DSH 安装提供(availability=installation)—— 版本跟桌面端走
185
+ // 2. 知道但没装(availability=missing)—— 宿主清单里有条目,包并不在机器上
186
+ // 3. 本 profile 装的 —— 真正参与自动更新的那一批
187
+ const systemPlugins = plugins.filter((p) => p.availability === 'installation');
188
+ const missingPlugins = plugins.filter((p) => p.availability === 'missing');
189
+ const managed = plugins.filter((p) => p.availability !== 'installation' && p.availability !== 'missing');
190
+ const registryPlugins = managed.filter((p) => p.kind === 'registry');
184
191
  // git 与 registry 一样参与自动更新,只是比的是 commit 而不是版本号
185
- const gitPlugins = plugins.filter((p) => p.kind === 'git');
186
- const otherPlugins = plugins.filter((p) => p.kind !== 'registry' && p.kind !== 'git');
192
+ const gitPlugins = managed.filter((p) => p.kind === 'git');
193
+ const otherPlugins = managed.filter((p) => p.kind !== 'registry' && p.kind !== 'git');
187
194
  const available = plugins.filter((p) => p.updateAvailable);
188
195
  const ready = available.filter((p) => !p.waitMs);
189
196
 
@@ -326,18 +333,31 @@ function makePanel(React) {
326
333
 
327
334
  const pluginRow = (plugin) => {
328
335
  const isGit = plugin.kind === 'git';
336
+ // 三种特殊行,各自的状态文案必须诚实:
337
+ // system —— 随 DSH 安装,版本跟桌面端走
338
+ // missing —— 宿主知道但没装,不是「已是最新」
339
+ // link —— 直链 tar 包(如 GitHub release),没有版本号可比
340
+ const isSystem = plugin.availability === 'installation';
341
+ const isMissing = plugin.availability === 'missing';
342
+ const isLink = plugin.kind === 'local' && typeof plugin.spec === 'string' && /^https?:\/\//i.test(plugin.spec);
329
343
  const tone = plugin.updateAvailable
330
344
  ? plugin.waitMs
331
345
  ? 'pau-tag-warn'
332
346
  : 'pau-tag-ok'
333
347
  : 'pau-tag';
334
- const stateText = plugin.updateAvailable
335
- ? plugin.waitMs
336
- ? `待等 ${plugin.waitText}`
337
- : '可更新'
338
- : plugin.latestError
339
- ? '查询失败'
340
- : '已是最新';
348
+ const stateText = isMissing
349
+ ? '未安装'
350
+ : isSystem
351
+ ? '随安装'
352
+ : isLink
353
+ ? '直链·手动更新'
354
+ : plugin.updateAvailable
355
+ ? plugin.waitMs
356
+ ? `待等 ${plugin.waitText}`
357
+ : '可更新'
358
+ : plugin.latestError
359
+ ? '查询失败'
360
+ : '已是最新';
341
361
  // git 来源没有版本号可比:当前版本只认 commit,「最新」也只写短 sha
342
362
  const currentCommit = plugin.git && plugin.git.commit ? String(plugin.git.commit).slice(0, 10) : '';
343
363
  const showLatest = isGit
@@ -379,22 +399,31 @@ function makePanel(React) {
379
399
  ? h('div', { className: 'pau-row-d' }, plugin.description.slice(0, 160))
380
400
  : null,
381
401
  ),
382
- h(
383
- 'select',
384
- {
385
- className: 'pau-select',
386
- value: plugin.hasOverride ? plugin.policy : 'inherit',
387
- onChange: (e) => {
388
- const value = e.target.value;
389
- if (value === 'inherit') setPolicy(plugin.name, 'inherit');
390
- else setPolicy(plugin.name, value, plugin.delayHours);
391
- },
392
- },
393
- h('option', { value: 'inherit' }, '跟随默认'),
394
- h('option', { value: 'immediate' }, '立即更新'),
395
- h('option', { value: 'delayed' }, '延迟更新'),
396
- ),
397
- plugin.policy === 'delayed'
402
+ // 系统插件 / 未安装 / 直链来源的策略与「立即更新」都是假的:
403
+ // 一个版本跟桌面端走,一个根本没装,一个没有版本号可比。
404
+ // 与其让用户点了报错,不如把控件换成一句实话。
405
+ isMissing
406
+ ? h('span', { className: 'pau-row-d' }, '宿主清单里有、但本机没装')
407
+ : isSystem
408
+ ? h('span', { className: 'pau-row-d' }, '随桌面端更新')
409
+ : isLink
410
+ ? h('span', { className: 'pau-row-d' }, '直链包,无法按版本号自动更新')
411
+ : h(
412
+ 'select',
413
+ {
414
+ className: 'pau-select',
415
+ value: plugin.hasOverride ? plugin.policy : 'inherit',
416
+ onChange: (e) => {
417
+ const value = e.target.value;
418
+ if (value === 'inherit') setPolicy(plugin.name, 'inherit');
419
+ else setPolicy(plugin.name, value, plugin.delayHours);
420
+ },
421
+ },
422
+ h('option', { value: 'inherit' }, '跟随默认'),
423
+ h('option', { value: 'immediate' }, '立即更新'),
424
+ h('option', { value: 'delayed' }, '延迟更新'),
425
+ ),
426
+ !isSystem && !isMissing && !isLink && plugin.policy === 'delayed'
398
427
  ? h('input', {
399
428
  className: 'pau-input pau-input-num',
400
429
  type: 'number',
@@ -406,27 +435,29 @@ function makePanel(React) {
406
435
  setPolicy(plugin.name, 'delayed', Number(e.target.value)),
407
436
  })
408
437
  : null,
409
- plugin.policy === 'delayed' ? h('span', { className: 'pau-row-d' }, '小时') : null,
410
- h(
411
- 'button',
412
- {
413
- className: 'pau-btn pau-btn-sm',
414
- disabled: !!busy || !plugin.updateAvailable,
415
- title: isGit ? '安装远端最新提交' : '安装最新版本',
416
- onClick: () =>
417
- run(`update:${plugin.name}`, async () => {
418
- const body = isGit
419
- ? { name: plugin.name, commit: plugin.latestCommit || '' }
420
- : { name: plugin.name, version: plugin.latest };
421
- const next = await call('/update', body);
422
- if (next.restart) setNote(next.restart.message || '已安排重启');
423
- else if (next.result && next.result.ok === false) setNote(next.result.message || '未执行');
424
- else setNote(`${plugin.name} 已更新`);
425
- return next;
426
- }),
427
- },
428
- busy === `update:${plugin.name}` ? '更新中…' : '立即更新',
429
- ),
438
+ !isSystem && !isMissing && !isLink && plugin.policy === 'delayed' ? h('span', { className: 'pau-row-d' }, '小时') : null,
439
+ isSystem || isMissing || isLink
440
+ ? null
441
+ : h(
442
+ 'button',
443
+ {
444
+ className: 'pau-btn pau-btn-sm',
445
+ disabled: !!busy || !plugin.updateAvailable,
446
+ title: isGit ? '安装远端最新提交' : '安装最新版本',
447
+ onClick: () =>
448
+ run(`update:${plugin.name}`, async () => {
449
+ const body = isGit
450
+ ? { name: plugin.name, commit: plugin.latestCommit || '' }
451
+ : { name: plugin.name, version: plugin.latest };
452
+ const next = await call('/update', body);
453
+ if (next.restart) setNote(next.restart.message || '已安排重启');
454
+ else if (next.result && next.result.ok === false) setNote(next.result.message || '未执行');
455
+ else setNote(`${plugin.name} 已更新`);
456
+ return next;
457
+ }),
458
+ },
459
+ busy === `update:${plugin.name}` ? '更新中…' : '立即更新',
460
+ ),
430
461
  canMigrate
431
462
  ? h(
432
463
  'button',
@@ -448,16 +479,18 @@ function makePanel(React) {
448
479
  busy === `migrate:${plugin.name}` ? '切换中…' : '切换到 npm',
449
480
  )
450
481
  : null,
451
- h(
452
- 'button',
453
- {
454
- className: 'pau-btn pau-btn-sm',
455
- disabled: !!busy,
456
- title: '只查这一个插件',
457
- onClick: () =>
458
- run(`query:${plugin.name}`, async () => {
459
- const one = await call('/query', { name: plugin.name });
460
- setNote(
482
+ isSystem || isMissing || isLink
483
+ ? null
484
+ : h(
485
+ 'button',
486
+ {
487
+ className: 'pau-btn pau-btn-sm',
488
+ disabled: !!busy,
489
+ title: '只查这一个插件',
490
+ onClick: () =>
491
+ run(`query:${plugin.name}`, async () => {
492
+ const one = await call('/query', { name: plugin.name });
493
+ setNote(
461
494
  one.error
462
495
  ? `查询失败:${one.error}`
463
496
  : one.updateAvailable
@@ -468,7 +501,7 @@ function makePanel(React) {
468
501
  }),
469
502
  },
470
503
  '刷新',
471
- ),
504
+ ),
472
505
  h(
473
506
  'button',
474
507
  {
@@ -517,7 +550,13 @@ function makePanel(React) {
517
550
  h(
518
551
  'div',
519
552
  { className: 'pau-card-h' },
520
- h('h3', { className: 'pau-card-t' }, `已装插件(${registryPlugins.length + gitPlugins.length})`),
553
+ h(
554
+ 'h3',
555
+ { className: 'pau-card-t' },
556
+ // 只数「真正参与自动更新」的(registry + git)。local / 直链 / 系统 / 未装
557
+ // 各自单列,混进这个数字会让「已装插件(N)」与实际能自动更新的数量不符。
558
+ `已装插件(${registryPlugins.length + gitPlugins.length})`,
559
+ ),
521
560
  h('span', { className: 'pau-row-d' }, available.length ? `${available.length} 个可更新` : '全部最新'),
522
561
  ),
523
562
  registryPlugins.length + gitPlugins.length
@@ -527,12 +566,40 @@ function makePanel(React) {
527
566
  ? h(
528
567
  'div',
529
568
  { style: { marginTop: 12 } },
530
- h('div', { className: 'pau-row-d' }, '本地路径 / 随安装提供(不参与版本检查)'),
569
+ h('div', { className: 'pau-row-d' }, '本地路径 / 直链来源(不参与版本检查)'),
531
570
  otherPlugins.map((plugin) =>
532
571
  pluginRow(plugin),
533
572
  ),
534
573
  )
535
574
  : null,
575
+ // 系统插件:必须列出来(用户要能看到自己装了哪些),但要明确标注
576
+ // 「随 DSH 安装」——它们的版本跟桌面端走,查 registry 没有意义。
577
+ systemPlugins.length
578
+ ? h(
579
+ 'div',
580
+ { style: { marginTop: 12 } },
581
+ h(
582
+ 'div',
583
+ { className: 'pau-row-d' },
584
+ `随 DSH 安装提供(${systemPlugins.length})· 版本跟随桌面端,不参与联网检查与卸载`,
585
+ ),
586
+ systemPlugins.map(pluginRow),
587
+ )
588
+ : null,
589
+ // 「宿主清单里有、本机没装」:既不是系统插件也不是已装插件。
590
+ // 混进任何一组都会显示成矛盾状态(随安装 + 未装),所以单列。
591
+ missingPlugins.length
592
+ ? h(
593
+ 'div',
594
+ { style: { marginTop: 12 } },
595
+ h(
596
+ 'div',
597
+ { className: 'pau-row-d' },
598
+ `可选、本机未安装(${missingPlugins.length})· 宿主提供了入口但包不在磁盘上`,
599
+ ),
600
+ missingPlugins.map(pluginRow),
601
+ )
602
+ : null,
536
603
  );
537
604
 
538
605
  const restartCard = h(
package/index.js CHANGED
@@ -88,10 +88,89 @@ export function apply(ctx, config = {}) {
88
88
 
89
89
  const isBusy = () => Date.now() - lastActivityAt < ACTIVITY_WINDOW_MS;
90
90
 
91
- /** 当前 profile 里可被本插件管理的插件列表(含本地/非 registry 来源的说明)。 */
92
- const listPlugins = () => {
91
+ /**
92
+ * 宿主 `pluginManager.listBundles()` 的同步缓存。
93
+ *
94
+ * 为什么要缓存:`listPlugins()` 被 API 快照、检查、git 查询等多处同步调用,
95
+ * 而宿主接口是 async。缓存在这里统一刷新,调用方拿到的是同一份一致视图。
96
+ *
97
+ * 为什么必须要有:随 DSH 安装提供的插件装在**安装目录**,
98
+ * `profile/node_modules` 里没有它们 —— 只有宿主知道它们的版本。
99
+ */
100
+ let hostBundlesCache = Object.freeze({ bundles: [], at: 0, error: '' });
101
+ const HOST_BUNDLES_TTL = 10 * 1000;
102
+
103
+ const readHostManager = () => {
104
+ try {
105
+ return ctx.get('pluginManager');
106
+ } catch {
107
+ return undefined;
108
+ }
109
+ };
110
+
111
+ const hostBundles = () => hostBundlesCache;
112
+
113
+ /** 拉一次宿主清单(节流 10 秒),返回同一份缓存。 */
114
+ const refreshHostBundles = async (force = false) => {
115
+ if (!force && Date.now() - hostBundlesCache.at < HOST_BUNDLES_TTL && hostBundlesCache.at > 0) {
116
+ return hostBundlesCache;
117
+ }
118
+ const manager = readHostManager();
119
+ if (!manager || typeof manager.listBundles !== 'function') {
120
+ hostBundlesCache = Object.freeze({
121
+ bundles: hostBundlesCache.bundles || [],
122
+ at: Date.now(),
123
+ error: '宿主未提供 pluginManager',
124
+ });
125
+ return hostBundlesCache;
126
+ }
127
+ try {
128
+ const raw = await manager.listBundles();
129
+ hostBundlesCache = Object.freeze({
130
+ bundles: (Array.isArray(raw) ? raw : []).map((item) => ({
131
+ name: item && typeof item.name === 'string' ? item.name : '',
132
+ version: item && typeof item.version === 'string' ? item.version : null,
133
+ // availability: installation(随 DSH 装)/ profile(本 profile 装的)/ missing(宿主知道但没装)
134
+ availability: item && typeof item.availability === 'string' ? item.availability : null,
135
+ enabled: item ? item.enabled === true : undefined,
136
+ // 字段名跟着宿主:removable。之前这里写成 removability,
137
+ // 面板读 removable 时永远是 undefined → 所有插件都显示「宿主未提供插件清单」。
138
+ removable: item ? item.removable === true : false,
139
+ readOnlyReason: item && item.readOnlyReason ? String(item.readOnlyReason) : null,
140
+ })),
141
+ at: Date.now(),
142
+ error: '',
143
+ });
144
+ } catch (error) {
145
+ hostBundlesCache = Object.freeze({
146
+ bundles: hostBundlesCache.bundles || [],
147
+ at: Date.now(),
148
+ error: String((error && error.message) || error),
149
+ });
150
+ }
151
+ return hostBundlesCache;
152
+ };
153
+
154
+ // 开机**不**主动拉:apply 阶段别的插件可能还没注册完,`pluginManager` 未必在。
155
+ // 由 API 入口(每次 /state、/check)按 TTL 惰性刷新,那时宿主已经就绪。
156
+
157
+ /**
158
+ * 当前 profile 里可被本插件管理的插件列表(含本地/非 registry 来源的说明)。
159
+ *
160
+ * @param {{bundles?: Array<{name:string, version?:string|null, availability?:string|null}>}} [host]
161
+ * 宿主 `pluginManager.listBundles()` 的结果。**必须有这个第二来源**:
162
+ * 随 DSH 安装提供的插件(`@deepseek-ai/dsh-base` 等)装在**安装目录**里,
163
+ * `profile/node_modules` 里根本没有它们,只看 profile 就会把版本读成 null、
164
+ * 面板显示成「未装」。宿主自己知道它们的版本与 availability,直接合并。
165
+ */
166
+ const listPlugins = (host) => {
93
167
  const names = profileBundleNames();
94
168
  const specs = profileDependencySpecs();
169
+ // 宿主清单:name -> { version, availability, enabled }
170
+ const hostMap = new Map();
171
+ for (const item of Array.isArray(host && host.bundles) ? host.bundles : []) {
172
+ if (item && typeof item.name === 'string') hostMap.set(item.name, item);
173
+ }
95
174
  // 「已发布」名单存在 state 里,跟着面板配置走
96
175
  const publishedNames = loadState().publishedNames || [];
97
176
  // lockfile 只读一次:git 来源的「当前 commit」只能从这里拿
@@ -101,7 +180,10 @@ export function apply(ctx, config = {}) {
101
180
  } catch {
102
181
  /* 没有 lock 文件就退化成只有 gitHead */
103
182
  }
104
- return names
183
+ // 宿主里有、profile bundles 里没有的(例如其他 app 入口),也补进来:
184
+ // 用户要的是「我装了什么」,不是「profile 声明了什么」。
185
+ const allNames = [...new Set([...names, ...hostMap.keys()])];
186
+ return allNames
105
187
  .map((name) => {
106
188
  const meta = installedMeta(name);
107
189
  const spec = typeof specs[name] === 'string' ? specs[name] : null;
@@ -109,15 +191,26 @@ export function apply(ctx, config = {}) {
109
191
  const parsed = kind === 'git' ? parseGitSpec(spec) : undefined;
110
192
  const lockCommit = kind === 'git' ? parseLockGitCommit(lockText, name) : undefined;
111
193
  const gitHead = kind === 'git' ? installedGitHead(name) : undefined;
194
+ const hostRow = hostMap.get(name);
112
195
  return {
113
196
  name,
114
- version: installedVersion(name) || null,
197
+ // 版本:优先 profile 里实际装的;读不到就用宿主报的(系统插件只能从这里拿)
198
+ version: installedVersion(name) || (hostRow && hostRow.version) || null,
115
199
  spec,
116
200
  // 自己这个包也要能被管理,否则「自动更新器本身」永远停在旧版
117
201
  kind,
202
+ // 宿主视角的归属:installation(随 DSH 安装)/ profile(本 profile 装的)/ missing(没装)
203
+ availability: (hostRow && hostRow.availability) || null,
204
+ // 宿主明说「知道但没装」:这类既不是系统插件也不是已装插件,
205
+ // 单列成「可选未安装」,否则会被当成系统插件显示一个「随安装 + 未装」的矛盾行。
206
+ installed: !(hostRow && hostRow.availability === 'missing'),
207
+ enabled: hostRow ? hostRow.enabled === true : undefined,
208
+ // 可卸载性跟着宿主:宿主没给这一行时是 false(宁可置灰)
209
+ canUninstall: Boolean(hostRow && hostRow.removable === true),
210
+ uninstallReadOnlyReason: (hostRow && hostRow.readOnlyReason) || null,
118
211
  // git 来源额外带:仓库、钉住的 ref、当前 commit —— 面板据此显示「落后几个提交」
119
212
  git: kind === 'git' ? { owner: parsed?.owner, repo: parsed?.repo, ref: parsed?.ref, commit: lockCommit || gitHead } : undefined,
120
- description: meta.description || '',
213
+ description: meta.description || (hostRow && typeof hostRow.description === 'string' ? hostRow.description : ''),
121
214
  homepage: meta.homepage || meta.repository || '',
122
215
  };
123
216
  });
@@ -283,7 +376,11 @@ export function apply(ctx, config = {}) {
283
376
  const now = Date.now();
284
377
  const compare = (a, b) => (isNewerVersion(b, a) ? 1 : a === b ? 0 : -1);
285
378
  // registry 走版本号;git 走 commit sha。两者都要查。
286
- const plugins = listPlugins().filter((p) => isUpdatableKind(p.kind) && p.version);
379
+ // 随 DSH 安装提供的(availability=installation)不查:它们的版本跟着桌面端走,
380
+ // 查 registry 只会得到无关结论,还白白打网络。
381
+ const plugins = listPlugins(hostBundles()).filter(
382
+ (p) => isUpdatableKind(p.kind) && p.version && p.availability !== 'installation',
383
+ );
287
384
  const { registry, fallbackRegistries } = registries();
288
385
 
289
386
  const results = [];
@@ -745,6 +842,10 @@ export function apply(ctx, config = {}) {
745
842
 
746
843
  const api = createApi({
747
844
  listPlugins,
845
+ // 快照/查询用:先按 TTL 刷一次宿主清单,再交给 listPlugins 合并
846
+ ensureHostBundles: () => refreshHostBundles(false),
847
+ // 同步读取当前缓存(快照是同步函数)
848
+ hostBundles,
748
849
  runCheck: checkAndRecord,
749
850
  applyUpdate,
750
851
  migrateToNpm,