ygc-dsh-plugin-autoupdate 0.0.0-stage → 0.2.1
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 +129 -2
- package/client.js +654 -0
- package/cordis.patch.yml +5 -0
- package/icon.svg +7 -0
- package/index.js +385 -0
- package/lib/api.js +326 -0
- package/lib/backup.js +66 -0
- package/lib/core.js +335 -0
- package/lib/registry.js +120 -0
- package/lib/restart-helper.js +146 -0
- package/lib/restart.js +110 -0
- package/lib/updater.js +253 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +50 -4
package/README.md
CHANGED
|
@@ -1,3 +1,130 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 插件自动更新(dsh-plugin-autoupdate)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
给 DSH 的已装插件做自动升级,规则按你的要求做:
|
|
4
|
+
|
|
5
|
+
- **定时检查**:间隔自己设(最短 5 分钟,默认 360 分钟)
|
|
6
|
+
- **逐个插件定策略**:某个插件可以「发布后立即更新」,也可以「发布后等 N 小时」(默认 2 小时)
|
|
7
|
+
- **更新完是否自动重启**:独立开关,可设「只在没有会话跑的时候重启」和「重启前等待秒数」
|
|
8
|
+
|
|
9
|
+
## 打开位置
|
|
10
|
+
|
|
11
|
+
侧栏图标「插件自动更新」→ 主面板。面板分五块:总开关与频率、默认策略、插件列表、重启设置、最近记录。
|
|
12
|
+
|
|
13
|
+
## 怎么判断「等够时间了」
|
|
14
|
+
|
|
15
|
+
**用上游的发布时间,不是本地发现时间。**
|
|
16
|
+
|
|
17
|
+
假如你把某插件设成「等 2 小时」,而它 3 小时前就发布了 —— 打开 DSH 立刻就会装,不会再压你 2 小时。
|
|
18
|
+
反过来,如果版本刚发布 10 分钟,就算 DSH 全程开着,也要等满 2 小时才装。
|
|
19
|
+
|
|
20
|
+
发布时间从 npm registry 的 packument `time[version]` 取;取不到才退回「本次检查时间」。
|
|
21
|
+
本地路径(`file:`)和 Git 来源的包不参与检查 —— 它们没有「发布」这个概念。
|
|
22
|
+
|
|
23
|
+
## 更新怎么执行
|
|
24
|
+
|
|
25
|
+
1. 先把 profile 的 `package.json` / `pnpm-lock.yaml` / `pnpm-workspace.yaml` 快照到
|
|
26
|
+
`~/.dsh/storages/plugin-autoupdate/backups/<时间戳>/`(保留最近 20 份)
|
|
27
|
+
2. 在 `pnpm-workspace.yaml` 的 `minimumReleaseAgeExclude` 里登记 `包名@版本`
|
|
28
|
+
—— 否则 pnpm 的「发布年龄」策略会把刚落地的版本挡回去
|
|
29
|
+
3. 走宿主自己的 `ctx.pluginManager.installBundle(spec, { saveExact: true })`
|
|
30
|
+
4. `installBundle` 不可用或没生效 → 退回用桌面宿主自带的 pnpm 执行 `add`
|
|
31
|
+
5. 装完记一条历史;如果是 `restart-required`,标记「需要重启」
|
|
32
|
+
|
|
33
|
+
**插件不自己改 `cordis.patch.yml`,不卸载任何插件,不碰 `~/.dsh/workbuddy-vault`。**
|
|
34
|
+
|
|
35
|
+
## 自动重启怎么做的
|
|
36
|
+
|
|
37
|
+
不自杀。插件调用时只是把重启助手以 detached 方式拉起来(`ELECTRON_RUN_AS_NODE=1`),
|
|
38
|
+
由助手负责:
|
|
39
|
+
|
|
40
|
+
1. 等 `restartDelaySeconds`(默认 10 秒)
|
|
41
|
+
2. 等旧宿主进程退出(最多 15 秒)
|
|
42
|
+
3. 清掉同名残留进程(排除自己)
|
|
43
|
+
4. 用 `process.execPath` 重新拉起,Windows 上带 `--updated`(窗口会自己置前台)
|
|
44
|
+
|
|
45
|
+
全程写 `~/.dsh/storages/plugin-autoupdate/restart.log`。
|
|
46
|
+
|
|
47
|
+
「只在没有会话正在跑的时候重启」默认开着:判定依据是最近 90 秒内有没有会话事件。
|
|
48
|
+
有会话时重启会被推迟,等空闲了再执行。
|
|
49
|
+
|
|
50
|
+
## 状态文件
|
|
51
|
+
|
|
52
|
+
`~/.dsh/storages/plugin-autoupdate.json`
|
|
53
|
+
|
|
54
|
+
```jsonc
|
|
55
|
+
{
|
|
56
|
+
"enabled": true, // 总开关
|
|
57
|
+
"intervalMinutes": 360, // 检查间隔
|
|
58
|
+
"defaultPolicy": "delayed", // immediate | delayed
|
|
59
|
+
"defaultDelayHours": 2,
|
|
60
|
+
"autoRestart": false,
|
|
61
|
+
"restartOnlyWhenIdle": true,
|
|
62
|
+
"restartDelaySeconds": 10,
|
|
63
|
+
"perPlugin": { // 单包覆盖
|
|
64
|
+
"dsh-connect-workbuddy": { "policy": "immediate", "delayHours": 2 }
|
|
65
|
+
},
|
|
66
|
+
"lastCheck": {}, // 上次检查的快照(面板「最新」列用它)
|
|
67
|
+
"pending": {}, // 待装的新版本(含上游发布时间)
|
|
68
|
+
"history": [] // 最近 100 条
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## 插件识别规则
|
|
73
|
+
|
|
74
|
+
`profile/package.json` 里 `dsh.profile.bundles` 列出的就是插件全集,再按 `dependencies` 的来源分三类:
|
|
75
|
+
|
|
76
|
+
| 来源写法 | 类别 | 是否参与更新 |
|
|
77
|
+
|---|---|---|
|
|
78
|
+
| `1.2.3` / `^1.2.3` | `registry` | 是 |
|
|
79
|
+
| `file:` / `link:` / `workspace:` | `local` | 否(没有「发布」概念) |
|
|
80
|
+
| `git+` / `github:` / `http(s)://` | `git` | 否 |
|
|
81
|
+
| 不在 `dependencies` 里(随 DSH 安装提供) | `installation` | 否(版本跟随宿主) |
|
|
82
|
+
|
|
83
|
+
## HTTP API
|
|
84
|
+
|
|
85
|
+
面板和外部脚本都走 `/api/local/plugin-autoupdate/`:
|
|
86
|
+
|
|
87
|
+
| 方法 | 路径 | 作用 |
|
|
88
|
+
|---|---|---|
|
|
89
|
+
| GET | `/state` | 面板快照 |
|
|
90
|
+
| POST | `/settings` | 改总开关 / 间隔 / 默认策略 / 重启设置 |
|
|
91
|
+
| POST | `/plugin-policy` | 改单个插件策略(`policy: 'inherit'` 恢复跟随默认) |
|
|
92
|
+
| POST | `/check` | 立即检查(只查不装) |
|
|
93
|
+
| POST | `/query` | 查单个包 |
|
|
94
|
+
| POST | `/update` | 立即更新指定包(忽略延迟) |
|
|
95
|
+
| POST | `/update-all` | 更新所有已到点的包 |
|
|
96
|
+
| POST | `/restart` | 立即重启 |
|
|
97
|
+
| GET | `/backups` | 列出清单备份 |
|
|
98
|
+
| POST | `/restore` | 用某份备份回滚清单 |
|
|
99
|
+
| GET | `/diagnose` | 看插件识别结果(排查「为什么某个包没被检查」) |
|
|
100
|
+
|
|
101
|
+
## 自检
|
|
102
|
+
|
|
103
|
+
```powershell
|
|
104
|
+
$node = "C:\DeepSeekHarness\resources\runtime\primary-runtime\dependencies\node\bin\node.exe"
|
|
105
|
+
& $node "C:\DSH-Work\plugin-autoupdate\pkg\test\all.mjs"
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
四个套件:
|
|
109
|
+
|
|
110
|
+
| 套件 | 覆盖 |
|
|
111
|
+
|---|---|
|
|
112
|
+
| `selftest.mjs` | 版本比较(含 prerelease)、状态规范化夹紧、延迟判定、registry packument 解析、本机 profile 识别 |
|
|
113
|
+
| `workspace-merge.test.mjs` | `pnpm-workspace.yaml` 的 `minimumReleaseAgeExclude` 合并(同名并成一行、不重复、CRLF 保持、段落连续) |
|
|
114
|
+
| `api-smoke.test.mjs` | 用假 ctx 真加载 Host 半,走完全部 API 路由;状态写在临时 HOME,不碰真实 profile |
|
|
115
|
+
| `client-smoke.test.mjs` | 在 Node 里用假 `document` / React 求值 `client.js`,验证插槽注册、locale 注册、面板首渲染 |
|
|
116
|
+
|
|
117
|
+
## 边界
|
|
118
|
+
|
|
119
|
+
- 只**更新**已装插件,不安装新插件、不卸载插件
|
|
120
|
+
- 只在 `registry` 来源上工作;`local` / `git` / `installation` 来源只显示、不处理
|
|
121
|
+
- 更新失败只记历史,不自动回滚(避免把用户自己手改的清单吞掉);要回滚用 `/restore`
|
|
122
|
+
- DSH 关闭期间不检查(进程内定时器的固有限制);重开后会立刻按上游发布时间重新判定
|
|
123
|
+
|
|
124
|
+
## 踩过的坑
|
|
125
|
+
|
|
126
|
+
**不要 `export const Config = {}`。** cordis 的 `resolveConfig` 对任何 truthy 的 `Config`
|
|
127
|
+
都会去读 `Config['~standard'].validate`,空对象直接抛
|
|
128
|
+
`TypeError: Cannot read properties of undefined (reading 'validate')`,
|
|
129
|
+
插件激活失败(`dsh: warning: 1 entry did not activate`)。
|
|
130
|
+
配置全走面板 + 状态文件,不需要 patch 里的 `config` 行,也就不需要 `Config` 导出。
|