@twinsearth/timemachine-dsh-plugin 0.2.5 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.6 — 2026-12-04
4
+
5
+ ### 修复还原后 DSH profile 无法启动
6
+
7
+ - 还原后不再原样写回归档 `package.json`:只保留本机 `node_modules` 能解析的第三方依赖与 `dsh.profile.bundles`;安装失败、DSH 不兼容或未安装的条目自动移除,并写入 `plugin_warnings` 黄色提示。
8
+ - `cordis.patch.yml` 同步过滤:移除 `name` 指向未安装第三方插件的顶层行,避免 DSH 启动时继续报 `cannot resolve profile bundle`。
9
+ - 修复“只还原配置、不安装插件”路径:`installPlugins:false` 时也不会把归档中的第三方插件依赖写进当前 profile,只保留本机已安装插件。
10
+ - 覆盖 bug:还原到没有目标插件的机器后,`package.json` 残留 `@twinsearth/ai-prison-dsh-plugin`、`billion-context`、`dshmarket`、`dsh-ops`、`dsh-context` 等条目,导致 DSH 无法解析 profile bundle、插件管理器无法卸载。
11
+ - Windows 标题栏纯插件入口标签由「DSH一键还原点」改为「还原点」,按钮仍常驻。
12
+
13
+ ### 验证
14
+
15
+ - `npm test` 34/34;`npm run check` 30/30。
16
+ - 新增 `sanitizeProfilePackage`、`filterProfilePatch` 单测,以及失败安装/配置-only 还原后 `package.json` 不含未安装插件的断言。
17
+ - GitHub 与 npm 双通道发布 `0.2.6`(2026-12-04)。
18
+
3
19
  ## 0.2.5 — 2026-12-03
4
20
 
5
21
  ### 还原不中断
package/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  DSH 一键还原点(Time Machine)。它把 DSH 客户端的会话、工作区、配置与插件清单打包成一个可迁移的还原点,并在需要时把整台机器上的 DSH 恢复成还原点里的样子。
8
8
 
9
- - 版本:`0.2.5`
9
+ - 版本:`0.2.6`
10
10
  - 宿主:DeepSeek Harness(DSH)桌面客户端 `0.2.x`
11
11
  - 平台:Windows / macOS / Linux(Windows 默认目录,macOS/Linux 由用户选择目录)
12
12
  - 许可:MIT
@@ -74,7 +74,7 @@ DSH 一键还原点:
74
74
 
75
75
  完整面板右上角固定显示两枚胶囊:
76
76
 
77
- - `Time Machine v0.2.5`:版本号来自服务端 `status.version`,不是客户端硬编码;插件更新后随包变化。
77
+ - `Time Machine v0.2.6`:版本号来自服务端 `status.version`,不是客户端硬编码;插件更新后随包变化。
78
78
  - `在线 X · 7日 Y · 安装 Z`:通过本地 `GET /api/twinsearth/timemachine/stats` 代理独立统计服务。
79
79
 
80
80
  统计口径:
@@ -188,7 +188,7 @@ sessions/<project-key>/<encoded-session-id>/
188
188
 
189
189
  1. **DSH 通用设置**:`设置 -> 通用` 里新增「DSH 一键还原点」一行,可直接「立即备份」「一键还原」或「打开完整面板」。「一键还原」先打开还原计划确认弹窗,确认后还原最近一份手动/自动还原点,并自动打开还原后的会话。
190
190
  2. **左上角侧栏**:`sidebar.panellist` 顶部新增入口,位置在品牌行下方、会话列表上方。macOS 显示「时间机器」,Windows 显示「一键还原点」,点击打开完整面板。该入口在插件启动 **10 秒后自动隐藏**,让出导航位;之后仍可从通用设置行点「打开完整面板」。
191
- 3. **Windows 标题栏(纯插件备用入口)**:插件运行时在左上角「应用 / 编辑」右侧追加「DSH一键还原点」按钮,点击直接打开完整面板。该按钮**常驻,不再自动隐藏**;标题栏重绘后会补挂。它不需要改 `app.asar`;只在 DSH 桌面客户端存在 `[data-windows-menu]` 时生效,用浏览器打开 Web UI 不会显示。
191
+ 3. **Windows 标题栏(纯插件备用入口)**:插件运行时在左上角「应用 / 编辑」右侧追加「还原点」按钮,点击直接打开完整面板。该按钮**常驻,不再自动隐藏**;标题栏重绘后会补挂。它不需要改 `app.asar`;只在 DSH 桌面客户端存在 `[data-windows-menu]` 时生效,用浏览器打开 Web UI 不会显示。
192
192
  4. **原生应用菜单(需求 4.2 的精确入口)**:包内提供 `scripts/host-menu-patch.mjs`,在 DSH 的 `app.asar` 的「应用 -> 开发者工具」后插入显式 `visible: true` 的「DSH一键还原点」,点击后调用插件暴露的 `window.__DSH_TIMEMACHINE_OPEN__()` 打开面板。
193
193
 
194
194
  原生菜单必须由宿主补丁实现,因为 DSH 桌面端的「应用」菜单由主进程硬编码(关于/检查更新/管理 dsh 命令/开发者工具/重启应用/退出),插件 API 没有“向应用菜单追加菜单项”的能力,`windowsMenu` IPC 也只接受 `application`/`edit` 两个菜单名。标题栏第三个按钮是纯插件的降级入口;如果要求严格出现在「应用 -> 开发者工具」下面,执行下面的补丁。本机真实客户端已执行;换一台机器部署时仍需执行一次。
@@ -269,7 +269,7 @@ npm run check # 静态交付检查
269
269
  npm run pack-check
270
270
  ```
271
271
 
272
- 测试覆盖:手动/自动创建、范围选择、保留份数、计划与还原、插件安装失败不中断、DSH 版本兼容性跳过、导入、设置持久化、损坏归档拒绝、缺失盘符检测、HTTP 路由挂载、客户端 bundle 槽位注册、侧栏入口 10 秒自动隐藏与标题栏入口常驻、标题随系统自适应、locale 五项详情、文件夹结构树与单分支展开、会话引导修复、运行中 `workspaceRegistry` 实时注册。真实客户端验收记录见 `docs/TESTPLAN.md`。
272
+ 测试覆盖:手动/自动创建、范围选择、保留份数、计划与还原、插件安装失败不中断、未安装插件条目清理、DSH 版本兼容性跳过、导入、设置持久化、损坏归档拒绝、缺失盘符检测、HTTP 路由挂载、客户端 bundle 槽位注册、侧栏入口 10 秒自动隐藏与标题栏入口常驻、标题随系统自适应、locale 五项详情、文件夹结构树与单分支展开、会话引导修复、运行中 `workspaceRegistry` 实时注册。真实客户端验收记录见 `docs/TESTPLAN.md`。
273
273
 
274
274
  ## 数据与安全
275
275
 
@@ -287,10 +287,11 @@ npm run pack-check
287
287
  | 创建失败 `ROOT_REQUIRED` | macOS/Linux 先选择保存文件夹 |
288
288
  | 还原后看不到工作区 | 看提示:实时注册成功会自动打开会话;提示重启时完全退出 DSH 再启动 |
289
289
  | 提示同名 Session ID 冲突 | 目标 DSH 已有同一个 Session ID 的会话;还原点用于新机器/新工作区时不会出现。可先归档或移走旧会话再还原 |
290
- | 标题栏没有「DSH一键还原点」 | 该按钮只存在于 DSH 桌面客户端;用浏览器访问 Web UI 时没有 `[data-windows-menu]`。桌面端仍不出现时,改用侧栏入口或执行下面的原生菜单补丁 |
290
+ | 标题栏没有「还原点」 | 该按钮只存在于 DSH 桌面客户端;用浏览器访问 Web UI 时没有 `[data-windows-menu]`。桌面端仍不出现时,改用侧栏入口或执行下面的原生菜单补丁 |
291
291
  | 原生菜单项不出现 | 目标机必须完全退出 DSH 后,对 `D:\DSH\resources\app.asar` 执行 `host-menu-patch.mjs` 并重启;只装插件不会自动改宿主菜单。本机真实 asar 已补丁,可用 `--check` 复核 |
292
292
  | 还原/导入提示「本机没有该存储盘」 | 还原点来自另一台机器,工作区路径在 `D:` / `E:` 等本机不存在的盘。按红字提示修改工作区文件夹后再确认;不要强行使用不存在的盘符 |
293
- | 第三方插件安装失败 | 现在只显示黄色提示「安装失败,请自行手动安装!」,不会中断会话/配置还原;按提示手动安装该插件,或改用「同时备份插件安装包」离线还原 |
293
+ | 第三方插件安装失败 | 现在只显示黄色提示「安装失败,请自行手动安装!」,不会中断会话/配置还原;失败插件不会再写入还原后的 `package.json` / `dsh.profile.bundles`,按提示手动安装后再启用 |
294
+ | 还原后 DSH 报 `cannot resolve profile bundle` | 0.2.6 起会从 `package.json` 与 `cordis.patch.yml` 移除本机未安装的第三方插件条目,并在黄色提示中列出;若现有 profile 已被旧版本写坏,用还原前的 `.timemachine-backups` 回滚,或按缺失包逐个安装 |
294
295
  | 插件因 DSH 版本不兼容被跳过 | 插件声明了 `engines.dsh`(或 DSH peer 依赖),当前客户端版本不满足。升级 DSH 或换兼容版本插件后重试;该插件不会阻塞其余还原 |
295
296
  | 还原点过大 | 改用「活跃会话」范围,或关闭附件备份 |
296
297
 
@@ -103,7 +103,9 @@ service.plan -> restore.planRestore
103
103
  service.restore -> restore.restorePoint
104
104
  可选:备份当前 package.json / cordis.patch.yml
105
105
  可选:reinstallPlugins(仅当用户在还原计划弹窗勾选「安装并还原第三方插件」;pnpm add name@latest / npm fallback)
106
- 可选:用归档 package.json 覆盖,但保留刚安装版本
106
+ 可选:清洗归档 package.json / cordis.patch.yml
107
+ 只保留本机 node_modules 可解析的第三方依赖与 bundles
108
+ 移除未安装插件的 patch 行;失败/跳过条目写入 plugin_warnings
107
109
  applyRestore
108
110
  写 session / attachment / config
109
111
  写前把已存在文件复制到 .timemachine-backups/<timestamp>/
@@ -193,6 +195,7 @@ service.restore -> restore.restorePoint
193
195
  - 还原写入前生成预还原副本;校验失败回滚新增文件、删除新建空目录。
194
196
  - 第三方插件逐个安装;单个安装失败只记入 `plugins.failed` 并产生黄色提示「安装失败,请自行手动安装!」,会话、附件、配置和工作区继续应用。只有 profile 不存在或离线包结构不可读等致命错误才返回 `stage: plugin-install` 并恢复 `package.json` / `cordis.patch.yml`;`node_modules` 可能处于部分更新状态,这是已知权衡。
195
197
  - 安装前 `src/plugin-compat.mjs` 读取插件 `engines.dsh` 或 DSH peer 依赖,与 `resources/runtime/primary-runtime/runtime.json` 的 `desktopVersion` 比对;不满足时标记 `PLUGIN_DSH_INCOMPATIBLE` 并跳过,避免安装后才被 DSH 启动拒绝。
198
+ - 写回 `package.json` / `cordis.patch.yml` 前再次按目标 profile 的 `node_modules` 清洗:第三方包不存在时从 `bundles`、`dependencies` 和 patch 行中移除,并写入 `plugin_warnings`。DSH 会因单个无法解析的 bundle 拒绝启动整个 profile,这一步保证“安装失败不中断”不会演变成“客户端无法加载、插件无法卸载”。
196
199
  - Windows 下 `planRestore` 对每个目标工作区检查盘符是否存在;缺失时返回 `path_issues` 并让计划弹窗红字提示、禁用确认。`restorePoint` 和 `applyRestore` 均二次拒绝,防止绕过 UI 写不存在的盘。
197
200
 
198
201
  ## 8. 原生菜单补丁
@@ -219,7 +222,7 @@ click: 取 focused/first BrowserWindow -> show/focus -> executeJavaScript("windo
219
222
  ```
220
223
  document.querySelector('[data-windows-menu]')
221
224
  -> host.shadowRoot.querySelector('[role="menubar"]')
222
- -> append <button role="menuitem" data-timemachine-caption>DSH一键还原点</button>
225
+ -> append <button role="menuitem" data-timemachine-caption>还原点</button>
223
226
  click -> window.__DSH_TIMEMACHINE_OPEN__()
224
227
  ```
225
228
 
@@ -36,7 +36,7 @@ DSH 桌面端原生菜单由主进程 `D:\DSH\resources\app.asar` 内的 `applic
36
36
 
37
37
  因此提供两条路径:
38
38
 
39
- 1. **纯插件备用按钮(无需改宿主)**:`lib/client.js#installCaptionEntry` 在 Windows 桌面客户端的 `[data-windows-menu]` open shadowRoot 里追加「DSH一键还原点」按钮。它位于「应用 / 编辑」右侧,不在「应用」下拉菜单内;浏览器 Web UI 没有该宿主节点,不会显示。
39
+ 1. **纯插件备用按钮(无需改宿主)**:`lib/client.js#installCaptionEntry` 在 Windows 桌面客户端的 `[data-windows-menu]` open shadowRoot 里追加「还原点」按钮。它位于「应用 / 编辑」右侧,不在「应用」下拉菜单内;浏览器 Web UI 没有该宿主节点,不会显示。
40
40
  2. **原生菜单补丁(精确入口)**:`scripts/host-menu-patch.mjs` 修改 `app.asar`,在「应用 -> 开发者工具」后插入「DSH一键还原点」。
41
41
 
42
42
  本包的 `scripts/host-menu-patch.mjs` 用宿主补丁实现精确入口:
@@ -109,4 +109,12 @@ node scripts/host-menu-patch.mjs --app-asar "D:\DSH\resources\app.asar" --restor
109
109
  - [x] 导入/还原检测本机缺失的 Windows 存储盘,红字提示修改工作区文件夹
110
110
  - [x] Windows「应用」菜单补丁项 `visible: true`;纯插件标题栏入口常驻、标题栏重绘后补挂
111
111
  - [ ] 真实 DSH 客户端中「应用」菜单项与常驻标题栏按钮的点击验收
112
- - [ ] GitHub 与 npm 双通道发布 `0.2.5`(发布完成后勾选)
112
+ - [x] GitHub 与 npm 双通道发布 `0.2.5`(2026-12-03)
113
+
114
+ ### 0.2.6 还原配置兼容性修复
115
+
116
+ - [x] 还原后的 `package.json` / `dsh.profile.bundles` 只保留本机可解析的第三方插件,未安装条目移除并黄色提示
117
+ - [x] `cordis.patch.yml` 移除指向未安装第三方插件的顶层行
118
+ - [x] `installPlugins:false` 的配置-only 还原不再写入归档中的未安装插件依赖
119
+ - [ ] 在已被旧版本写坏的 profile 上验证回滚/修复后的真实 DSH 启动与卸载
120
+ - [x] GitHub 与 npm 发布 `0.2.6`(2026-12-04):[GitHub Release](https://github.com/TwinsEarth/TimeMachine-dsh-plugin/releases/tag/v0.2.6) / [npm](https://www.npmjs.com/package/@twinsearth/timemachine-dsh-plugin/v/0.2.6)
package/docs/TESTPLAN.md CHANGED
@@ -32,7 +32,7 @@ npm run pack-check
32
32
  | 11 | HTTP 路由 | 假 Connection registry 挂载、status/create/confirm 校验/settings |
33
33
  | 12 | 客户端 bundle | 三个槽位注册、卸载、包名裸 specifier、`slots,layout` 注入 |
34
34
  | 13 | 客户端包名 | bundle id 不含子路径 |
35
- | 14 | 标题栏备用入口 | bundle 含 `data-windows-menu`、`DSH一键还原点`、`data-timemachine-caption` |
35
+ | 14 | 标题栏备用入口 | bundle 含 `data-windows-menu`、`还原点`、`data-timemachine-caption` |
36
36
  | 15 | 第三方插件手动开关 | bundle 含「安装并还原第三方插件」、`installPlugins`、`useSavedPackages` |
37
37
  | 16 | 通用设置快捷入口 / 侧栏自适应 | bundle 含「立即备份」「一键还原」「打开完整面板」「时间机器」、`order: -100` |
38
38
  | 17 | 文件夹结构树 | 创建返回 `tree`;根目录、顶层文件、`sessions/`、中文说明与精确大小;`/inspect` 返回同一棵树 |
@@ -193,6 +193,15 @@ npm run pack-check
193
193
  - 标题栏用例:客户端 bundle 断言 `CAPTION_AUTO_HIDE_MS` 已移除、`CAPTION_DISCOVERY_MS=30_000`,标题栏按钮不再定时移除;原生菜单补丁静态断言 `visible: true`。
194
194
  - 真实 DSH 客户端「应用」菜单点击、常驻标题栏按钮出现/点击和缺失盘现场仍未做人工点击验收。
195
195
 
196
+ ### 3.15 0.2.6 还原配置清理(自动化通过)
197
+
198
+ - `npm test` 34/34、`npm run check` 30/30。
199
+ - `sanitizeProfilePackage`:归档 `package.json` 中同时存在官方包、已安装第三方包、未安装第三方包;断言 `bundles` 与 `dependencies` 只保留官方和本机 `node_modules` 可解析项,未安装项进入 `dropped_*`。
200
+ - `filterProfilePatch`:`cordis.patch.yml` 中官方行、已安装第三方行保留,未安装第三方行整块移除。
201
+ - 配置-only 还原:`installPlugins:false` 时,归档中的 `dshmarket` 不再出现在目标 `package.json` 的 `bundles` / `dependencies`。
202
+ - 失败安装还原:runner 返回失败时,还原仍完成,`plugin_warnings` 含「安装失败,请自行手动安装!」,目标 `package.json` 不含失败的 `dshmarket`。
203
+ - 真实 DSH 的旧坏 profile 回滚/修复仍需人工执行并重启验收。
204
+
196
205
  ## 4. 待人工验收
197
206
 
198
207
  - 安装 tarball 到真实 DSH profile `desktop` 后:
@@ -208,7 +217,7 @@ npm run pack-check
208
217
  - 创建卡片下方显示绿色「一键修复会话引导」;点击后返回检查/修复/无需修改/失败数量
209
218
  - 插件管理器详情显示五项能力,不再回退到包名
210
219
  - 真实 DSH 桌面客户端左上角标题栏:
211
- - 「应用 / 编辑」右侧出现「DSH一键还原点」
220
+ - 「应用 / 编辑」右侧出现「还原点」
212
221
  - 启动 30 秒后按钮仍存在,标题栏重绘后也不会消失
213
222
  - 点击打开插件面板;关闭/卸载插件后按钮消失
214
223
  - 浏览器 Web UI 不显示该按钮(无 `[data-windows-menu]`),属预期
@@ -229,7 +238,7 @@ npm run pack-check
229
238
 
230
239
  ## 5. 回归门槛
231
240
 
232
- - `npm test` 32/32 通过
241
+ - `npm test` 34/34 通过
233
242
  - `npm run check` 30/30 通过
234
- - `npm run pack-check` tarball 内容符合 `files`(34 个文件,390.3 KiB)
243
+ - `npm run pack-check` tarball 内容符合 `files`(34 个文件,398.8 KiB)
235
244
  - 任何失败先定位到具体断言,不通过放宽断言“修复”
package/lib/client.js CHANGED
@@ -1182,10 +1182,10 @@ window.__ModuleLoader__.load({
1182
1182
  const element = document.createElement('button');
1183
1183
  element.type = 'button';
1184
1184
  element.setAttribute('role', 'menuitem');
1185
- element.setAttribute('aria-label', 'DSH 一键还原点');
1185
+ element.setAttribute('aria-label', '还原点');
1186
1186
  element.setAttribute(ATTR, '');
1187
1187
  element.tabIndex = -1;
1188
- element.textContent = 'DSH一键还原点';
1188
+ element.textContent = '还原点';
1189
1189
  element.addEventListener('pointerdown', (event) => event.preventDefault());
1190
1190
  element.addEventListener('click', (event) => {
1191
1191
  event.preventDefault();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twinsearth/timemachine-dsh-plugin",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
4
4
  "description": "DSH 一键还原点:手动/自动双还原点、会话与工作区完整备份、第三方插件 latest 重装、配置迁移与一键还原、一键修复会话引导。",
5
5
  "type": "module",
6
6
  "icon": "./icon.png",
package/plugin.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "id": "timemachine",
3
3
  "name": "DeepSeekHarness:一键还原点",
4
- "version": "0.2.5",
4
+ "version": "0.2.6",
5
5
  "description": "DSH 一键还原点:手动/自动双还原点、会话与工作区完整备份、第三方插件 latest 重装、配置迁移与一键还原、一键修复会话引导。",
6
6
  "entry": "lib/index.js",
7
7
  "client": "lib/client.js",
package/src/plugins.mjs CHANGED
@@ -144,6 +144,93 @@ export function readProfilePlugins(input) {
144
144
  };
145
145
  }
146
146
 
147
+ /**
148
+ * Whether a profile can resolve a package without asking the DSH installation.
149
+ * Official DSH bundles live in the app and third-party packages live under the
150
+ * profile's node_modules. We deliberately do not trust package.json alone: a
151
+ * restore may have written an archived dependency that was never installed.
152
+ */
153
+ export function isProfilePackageAvailable(profileDir, name) {
154
+ if (!isSafePackageName(name)) return false;
155
+ if (name === SELF_PLUGIN || name.startsWith(OFFICIAL_SCOPE)) return true;
156
+ const segments = name.split('/');
157
+ return fs.existsSync(path.join(profileDir, 'node_modules', ...segments, 'package.json'));
158
+ }
159
+
160
+ /**
161
+ * Remove bundle/dependency entries that the target profile cannot resolve.
162
+ * This keeps a restore from writing another machine's plugin manifest into a
163
+ * profile where the plugin download failed or was skipped. The caller should
164
+ * surface `dropped_*` as a yellow restore warning.
165
+ */
166
+ export function sanitizeProfilePackage(input) {
167
+ const profileDir = input?.profileDir;
168
+ const source = input?.pkg;
169
+ const installed = new Set(Array.isArray(input?.installed) ? input.installed : []);
170
+ const pkg = JSON.parse(JSON.stringify(source ?? {}));
171
+ const droppedBundles = [];
172
+ const droppedDependencies = [];
173
+ const available = (name) => isProfilePackageAvailable(profileDir, name) || installed.has(name);
174
+
175
+ if (Array.isArray(pkg?.dsh?.profile?.bundles)) {
176
+ pkg.dsh.profile.bundles = pkg.dsh.profile.bundles.filter((name) => {
177
+ if (available(name)) return true;
178
+ droppedBundles.push(name);
179
+ return false;
180
+ });
181
+ }
182
+ if (pkg.dependencies !== null && typeof pkg.dependencies === 'object' && !Array.isArray(pkg.dependencies)) {
183
+ for (const name of Object.keys(pkg.dependencies)) {
184
+ if (available(name)) continue;
185
+ droppedDependencies.push(name);
186
+ delete pkg.dependencies[name];
187
+ }
188
+ }
189
+ return { pkg, dropped_bundles: droppedBundles, dropped_dependencies: droppedDependencies };
190
+ }
191
+
192
+ /**
193
+ * Drop top-level cordis.patch.yml rows whose `name` is a third-party package
194
+ * that is not installed in the target profile. Rows without a name (pure
195
+ * config overrides) are preserved.
196
+ */
197
+ export function filterProfilePatch(input) {
198
+ const profileDir = input?.profileDir;
199
+ const lines = String(input?.text ?? '').split(/\r?\n/u);
200
+ const output = [];
201
+ const dropped = [];
202
+ let block = [];
203
+ let blockName = null;
204
+ const flush = () => {
205
+ if (block.length === 0) return;
206
+ if (blockName !== null && isThirdParty(blockName) && !isProfilePackageAvailable(profileDir, blockName)) {
207
+ dropped.push(blockName);
208
+ } else {
209
+ output.push(...block);
210
+ }
211
+ block = [];
212
+ blockName = null;
213
+ };
214
+ for (const line of lines) {
215
+ if (/^-\s/u.test(line)) {
216
+ flush();
217
+ block = [line];
218
+ continue;
219
+ }
220
+ if (block.length > 0) {
221
+ block.push(line);
222
+ if (blockName === null) {
223
+ const match = /^\s{2}name:\s*['"]?([^'"\s]+)['"]?/u.exec(line);
224
+ if (match !== null) blockName = match[1];
225
+ }
226
+ } else {
227
+ output.push(line);
228
+ }
229
+ }
230
+ flush();
231
+ return { text: output.join('\n'), dropped };
232
+ }
233
+
147
234
  /** A filesystem-safe stem for a plugin tarball name. */
148
235
  export function packageFileStem(name) {
149
236
  return String(name).replace(/^@/u, '').replace(/[\\/]/gu, '-').replace(/[^a-z0-9._-]/giu, '_');
package/src/restore.mjs CHANGED
@@ -16,7 +16,7 @@ import { readArchive, readRestorePoint } from './point.mjs';
16
16
  import { mergeRegistry, registryDocument, registrySummary } from './registry.mjs';
17
17
  import { inspectSessionBuffer, isV4Header, remapSessionCwd } from './session-log.mjs';
18
18
  import { normalizeRegistry } from './scan.mjs';
19
- import { reinstallPlugins, SELF_PLUGIN } from './plugins.mjs';
19
+ import { filterProfilePatch, reinstallPlugins, sanitizeProfilePackage, SELF_PLUGIN } from './plugins.mjs';
20
20
  import { atomicWriteFile, atomicWriteJson, copyFileDurable, ensureDir, isInside, readJson, safeSegment, sha256, stamp } from './util/fs.mjs';
21
21
  import { encodeSegment, missingDriveForPath, projectKey, profileDir, resolveDshHome, sessionDir } from './util/paths.mjs';
22
22
 
@@ -301,7 +301,7 @@ export function planRestore(input) {
301
301
  if (!archive.map.has(rel)) return { ok: false, reason_code: RESTORE_CODES.PLUGIN_PACKAGE_INVALID, detail: `${name}: ${rel} is missing` };
302
302
  }
303
303
  if (includeConfig && !includePlugins && plugins.length === 0 && (point.plugins ?? []).length > 0) {
304
- warnings.push('本还原点包含第三方插件清单,但本次未勾选“安装第三方插件”;配置里仍会写入插件条目,DSH 可能提示插件缺失。');
304
+ warnings.push('本还原点包含第三方插件清单,但本次未勾选“安装第三方插件”;配置中只保留本机已安装的插件条目。');
305
305
  }
306
306
  const overwrites = sessions.filter((session) => session.action === 'overwrite').length;
307
307
  if (overwrites > 0) warnings.push(`${overwrites} 个同名会话已存在,会被本还原点覆盖;覆盖前会写入 .timemachine-backups。`);
@@ -760,30 +760,63 @@ export async function restorePoint(input) {
760
760
  };
761
761
  }
762
762
 
763
- // pnpm writes the installed versions into package.json. Re-apply the
764
- // archived package metadata, but keep the versions that were just installed.
765
- const archived = plan.config_buffers?.find((row) => row.target_rel === `profiles/${profile}/package.json`);
766
- if (archived !== undefined) {
767
- try {
768
- const current = JSON.parse(fs.readFileSync(packageFile, 'utf8'));
769
- const next = JSON.parse(archived.buffer.toString('utf8'));
770
- next.dependencies = isObject(next.dependencies) ? next.dependencies : {};
771
- if (isObject(current.dependencies)) {
772
- for (const row of install.installed ?? []) {
773
- if (typeof current.dependencies[row.name] === 'string') next.dependencies[row.name] = current.dependencies[row.name];
763
+ }
764
+
765
+ // The archive may come from a machine with a larger plugin set. Never write
766
+ // a package.json / cordis.patch.yml entry that the target profile cannot
767
+ // resolve: DSH refuses the whole profile at boot and the plugin manager
768
+ // becomes unusable. This runs even when the user chose "config only"
769
+ // (installPlugins=false), which previously copied the archived dependency
770
+ // list without installing any of it.
771
+ const profileWarnings = [];
772
+ const archivedPackage = plan.config_buffers?.find((row) => row.target_rel === `profiles/${profile}/package.json`);
773
+ if (archivedPackage !== undefined) {
774
+ try {
775
+ const currentPackage = JSON.parse(fs.readFileSync(path.join(profilePath, 'package.json'), 'utf8'));
776
+ const installedNames = Array.isArray(install?.installed) ? install.installed.map((row) => row.name) : [];
777
+ const sanitized = sanitizeProfilePackage({
778
+ profileDir: profilePath,
779
+ pkg: JSON.parse(archivedPackage.buffer.toString('utf8')),
780
+ installed: installedNames,
781
+ });
782
+ if (currentPackage?.dependencies !== null && typeof currentPackage?.dependencies === 'object') {
783
+ for (const name of Object.keys(sanitized.pkg.dependencies ?? {})) {
784
+ if (typeof currentPackage.dependencies[name] === 'string') {
785
+ sanitized.pkg.dependencies[name] = currentPackage.dependencies[name];
774
786
  }
775
787
  }
776
- plan.configOverrides = { [`profiles/${profile}/package.json`]: Buffer.from(`${JSON.stringify(next, null, 2)}\n`, 'utf8') };
777
- } catch { /* keep the archived package.json */ }
778
- }
788
+ }
789
+ plan.configOverrides = plan.configOverrides ?? {};
790
+ plan.configOverrides[`profiles/${profile}/package.json`] = Buffer.from(`${JSON.stringify(sanitized.pkg, null, 2)}\n`, 'utf8');
791
+ const dropped = [...new Set([...sanitized.dropped_bundles, ...sanitized.dropped_dependencies])];
792
+ if (dropped.length > 0) {
793
+ profileWarnings.push(`以下第三方插件未安装,已从还原后的 package.json 移除:${dropped.join('、')}。`);
794
+ }
795
+ } catch { /* keep the archived package.json if it cannot be sanitized */ }
796
+ }
797
+
798
+ const archivedPatch = plan.config_buffers?.find((row) => row.target_rel === `profiles/${profile}/cordis.patch.yml`);
799
+ if (archivedPatch !== undefined) {
800
+ try {
801
+ const original = archivedPatch.buffer.toString('utf8');
802
+ const filtered = filterProfilePatch({ profileDir: profilePath, text: original });
803
+ if (filtered.text !== original) {
804
+ plan.configOverrides = plan.configOverrides ?? {};
805
+ plan.configOverrides[`profiles/${profile}/cordis.patch.yml`] = Buffer.from(filtered.text, 'utf8');
806
+ }
807
+ if (filtered.dropped.length > 0) {
808
+ profileWarnings.push(`以下插件未安装,已从还原后的 cordis.patch.yml 移除配置:${[...new Set(filtered.dropped)].join('、')}。`);
809
+ }
810
+ } catch { /* keep the archived patch if it cannot be filtered */ }
779
811
  }
812
+ const restoreWarnings = [...(Array.isArray(install?.warnings) ? install.warnings : []), ...profileWarnings];
780
813
  const liveRegistry = input.workspaceRegistry ?? null;
781
814
  const applied = applyRestore(plan, {
782
815
  configOverrides: plan.configOverrides,
783
816
  backupDir,
784
817
  skipRegistry: liveRegistry !== null,
785
818
  });
786
- if (!applied.ok) return { ...applied, stage: 'file-restore', plugins: install, plugin_warnings: Array.isArray(install?.warnings) ? install.warnings : [] };
819
+ if (!applied.ok) return { ...applied, stage: 'file-restore', plugins: install, plugin_warnings: restoreWarnings };
787
820
 
788
821
  let live = null;
789
822
  if (liveRegistry !== null) {
@@ -795,7 +828,7 @@ export async function restorePoint(input) {
795
828
  point: plan.point,
796
829
  stage: 'restored',
797
830
  plugins: install,
798
- plugin_warnings: Array.isArray(install?.warnings) ? install.warnings : [],
831
+ plugin_warnings: restoreWarnings,
799
832
  restore: applied,
800
833
  workspaces: live?.workspaces ?? applied.workspaces,
801
834
  display: live?.display ?? null,
package/src/version.mjs CHANGED
@@ -1,2 +1,2 @@
1
1
  /** Single source for the version shown in the panel header and health routes. */
2
- export const PLUGIN_VERSION = '0.2.5';
2
+ export const PLUGIN_VERSION = '0.2.6';