From 4c1d4177d9f52b7a97c0355abdebdaec4bba2b40 Mon Sep 17 00:00:00 2001 From: Menghuan1918 Date: Wed, 4 Nov 2026 21:03:54 +0800 Subject: [PATCH] =?UTF-8?q?fix(install):=20=E8=A3=85=E5=AE=8C=E5=85=88?= =?UTF-8?q?=E6=9F=A5=20profile=20=E8=87=AA=E5=B8=A6=E7=9A=84=E5=AE=BF?= =?UTF-8?q?=E4=B8=BB=E5=8C=85=E6=98=AF=E5=90=A6=E6=B7=B7=E7=89=88=EF=BC=88?= =?UTF-8?q?#1107=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit profile 自带的 @deepseek-ai/dsh-* 会覆盖宿主安装的同一批包(DSH 的 profile 解析先取 profile 前缀内的副本),本插件静态 import 的 dsh-subagent 因此绑到 混搭版本;混版缺导出时宿主只报 DesktopHostFatalError / required plugins did not activate,看不到是哪个包缺了什么。 新增随包发布的 scripts/check-profile-host-tree.mjs:按 DSH 的 profile 解析 规则(只看 profile 前缀内的副本、上级 profiles/node_modules 不参与)判定 dsh-subagent 精确声明的 dsh-attachment peer。install.sh / install.ps1 装完 运行它,混版时打印两份版本号与修复命令并退出,不再提示重启。README 常见 问题、docs/host-contracts.md 与中英 CHANGELOG 同批记录;新增 tests/install-host-tree.spec.ts 真跑发布脚本钉住行为。 --- CHANGELOG.md | 2 + CHANGELOG_EN.md | 2 + README.md | 1 + README_ZH.md | 1 + docs/host-contracts.md | 1 + package.json | 1 + scripts/check-profile-host-tree.mjs | 112 ++++++++++++++++++++++++ scripts/install.ps1 | 26 +++++- scripts/install.sh | 25 +++++- tests/install-host-tree.spec.ts | 127 ++++++++++++++++++++++++++++ 10 files changed, 290 insertions(+), 8 deletions(-) create mode 100644 scripts/check-profile-host-tree.mjs create mode 100644 tests/install-host-tree.spec.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 16088bc7..cbcb7c2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ ### 未发布 +- 🧭 **安装脚本会先查 profile 自带的 `@deepseek-ai/dsh-*` 副本是否混版**([#1107](https://github.com/omdsh-dev/DSH-better-sidebar/issues/1107)):profile 里自己装的宿主包会抢在 DSH 安装之前被解析,本插件静态 import 的 `dsh-subagent` 因此绑到混搭版本;混版缺导出时整只宿主只报 `DesktopHostFatalError: required plugins did not activate`,看不到是哪个包缺了什么。`scripts/install.sh` / `scripts/install.ps1` 现在装完会运行随包发布的 `scripts/check-profile-host-tree.mjs`(按 DSH 自己的 profile 解析规则:只看 profile 内的副本、只判定 `dsh-subagent` 精确声明的 `dsh-attachment` peer)——混版就打印两份版本号与修复命令并退出,不再提示重启。README 常见问题补了同一条修复路径(从 profile 的 `package.json` / overrides 移除 `@deepseek-ai/dsh-*` 后 `pnpm install`,或把两份副本对齐到同一版本)。 + - 🧪 测试:新增 `tests/install-host-tree.spec.ts`(6 例,真跑发布脚本:混版退出码 1 并给出两份版本;配对一致 / 只有 subagent 副本 / profile 之外的旧副本被忽略 / 未装插件均放行;并钉住两个安装脚本都调用它、脚本随包发布)。 - 📐 **页面 CSS zoom 不再被误判成页面级 transform**([#1102](https://github.com/omdsh-dev/DSH-better-sidebar/issues/1102);贡献者 PR [#1110](https://github.com/omdsh-dev/DSH-better-sidebar/pull/1110) @HootRock):`body { zoom: 1.15 }` 下 panel host 的 `100vh` 按 zoom 放大(811px 视口 → 约 932.6px),几何自检因此判定「页面被 transform」→ 降级成 absolute、把文档撑高,聚焦 / 滚动会把整个外壳一起推走。现在预期高度按祖先链累积的 `zoom` 归一,宽度与位移仍按原阈值判定,真实 transform 不会被掩盖。 - 🧪 测试:`tests/e2e/panel-host-zoom.e2e.ts`(Chromium 实测 `body { zoom: 1.15 }` 下不再降级)。 - 🎛 **Changes 的「Git / 本轮文件」切换改用公开组件**([#1098](https://github.com/omdsh-dev/DSH-better-sidebar/issues/1098);贡献者 PR [#1101](https://github.com/omdsh-dev/DSH-better-sidebar/pull/1101) @wang-kaopu):此前自己画一套按钮、还依赖宿主私有 CSS Modules 的哈希类名,宿主一改样式就退化成浏览器原生按钮(方框 + 1px 黑边)。现在改用 `dsh-client-ui-primitives` 公开导出的 `SegmentedControl`,私有类名依赖一并删除。 diff --git a/CHANGELOG_EN.md b/CHANGELOG_EN.md index aae6bbad..4db6371a 100644 --- a/CHANGELOG_EN.md +++ b/CHANGELOG_EN.md @@ -6,6 +6,8 @@ ### Unreleased +- 🧭 **The installers now verify that a profile's own `@deepseek-ai/dsh-*` copies belong to one host version** ([#1107](https://github.com/omdsh-dev/DSH-better-sidebar/issues/1107)): profile-installed host packages resolve ahead of the DSH installation, so the `dsh-subagent` this plugin imports statically binds to a mixed set; a missing export then takes the whole host down with `DesktopHostFatalError: required plugins did not activate`, never naming the package. `scripts/install.sh` / `scripts/install.ps1` now run the shipped `scripts/check-profile-host-tree.mjs` after installing (mirroring DSH's own profile resolution: profile-local copies only, and only the exact `dsh-attachment` peer `dsh-subagent` declares) — a torn pair prints both versions plus the repair and stops instead of telling you to restart. The README FAQ documents the same repair (remove `@deepseek-ai/dsh-*` from the profile's `package.json` / overrides and `pnpm install`, or align both copies). + - 🧪 New `tests/install-host-tree.spec.ts` (6 cases, running the shipped script: a torn pair exits 1 with both versions; a matching pair, a subagent-only copy, a stale copy above the profile, and an absent plugin all pass; both installers are pinned to call it and the script is pinned into `files`). - 📐 **Page CSS zoom is no longer mistaken for a page-level transform** ([#1102](https://github.com/omdsh-dev/DSH-better-sidebar/issues/1102), PR [#1110](https://github.com/omdsh-dev/DSH-better-sidebar/pull/1110)): with `body { zoom: 1.15 }` the panel host's `100vh` resolved to ~932.6px in an 811px viewport, so the geometry self-check switched the host to absolute positioning and grew the document. The expected height now folds the ancestor `zoom` chain while width and offsets keep their thresholds, so a real page transform is still caught. - 🎛 **The Changes lens switcher uses the public `SegmentedControl`** ([#1098](https://github.com/omdsh-dev/DSH-better-sidebar/issues/1098), PR [#1101](https://github.com/omdsh-dev/DSH-better-sidebar/pull/1101)): it previously painted its own buttons on top of host-private CSS-module hash names and degraded to native browser buttons whenever the host restyled. The private-class dependency is gone. - 🗂 **A container workspace now shows and switches every child repository**: `git.status` has always reported every discovered root in `repositories`, but the Git panel only listed them in the "More actions → Repository" submenu — no name and no count at the top of the panel, and the body rendered `repositories[0]`, so a workspace holding three projects looked like it had one. When more than one root is discovered, a chip row (`data-scm-repos`, one `[data-scm-repo]` per root) now renders above the Changes section with the current checkout marked `[data-active="true"]`; clicking a chip goes through the existing `chooseRepo`, so reads, mutations and the commit graph stay pinned to the chosen root. A single-repository workspace renders no row, and the existing menu entry stays. diff --git a/README.md b/README.md index 7d3edd8d..9ab3812a 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,7 @@ If something fails, check the FAQ table in https://github.com/omdsh-dev/DSH-bett | `Ignored build scripts` error | pnpm 11 blocked a transitive dependency's build script. Run `pnpm approve-builds` in the profile directory (`~/.dsh/profiles/web`) — this plugin itself has no build-script dependencies. | | `minimum release age` / version younger than 24h | The release is less than 24 hours old. Wait 24h or re-run (pnpm auto-adds `minimumReleaseAgeExclude`). | | "Profile directory not found" | Run `dsh web` once to initialize `~/.dsh/profiles/web`. | +| Host dies on start: `DesktopHostFatalError: … required plugins did not activate / better-sidebar` | The profile carries its own `@deepseek-ai/dsh-*` copies (left by an older DSH, or listed in the profile's `package.json` / overrides) and they resolve ahead of the installation, so the `dsh-subagent` this plugin imports statically binds to a mixed set; when an export is missing the host only reports this fatal and never names the package. Confirm with the check shipped in the current plugin: `node ~/.dsh/profiles/web/node_modules/dsh-better-sidebar/scripts/check-profile-host-tree.mjs ~/.dsh/profiles/web`. Fix: remove `@deepseek-ai/dsh-*` from the profile's `package.json` / overrides and `pnpm install` there (the installation then supplies them), or align both copies to one version; then restart. The install scripts run this check for you. | | **Two sidebars** on the page | Double mounting. Remove the legacy manual mount line (`- insert: ... better-sidebar ...`) from `~/.dsh/profiles/web/cordis.patch.yml`; aggregate packages mounting this package under a different id are auto-yielded, no action needed. | | Settings values gone after upgrade | Since DSH 0.1.7, preferences live on this plugin's mount row in the profile (default entry id `better-sidebar`). The plugin migrates your old `settings.yaml` values once on first start and never overwrites newer values. | | Terminal unavailable | Terminals are provided by **DSH itself** (this plugin ships no PTY) — see DSH docs; "host provides no terminal capability" in the bottom terminal means this deployment has no terminal controller mounted. | diff --git a/README_ZH.md b/README_ZH.md index bd624f45..a6267f52 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -89,6 +89,7 @@ dsh plugin --profile web add dsh-better-sidebar@latest | 报 `Ignored build scripts` | pnpm 11 拦截了某个传递依赖的构建脚本。在 profile 目录(`~/.dsh/profiles/web`)跑 `pnpm approve-builds` 按提示放行——本插件自身已无构建脚本依赖。 | | 报 `minimum release age` / 版本不足 24h | 装的版本发布不足 24 小时。等 24h 或重跑一次(pnpm 会自动补 `minimumReleaseAgeExclude`)。 | | 报「找不到 profile 目录」 | 先跑一次 `dsh web`,让它初始化 `~/.dsh/profiles/web`。 | +| 宿主启动即崩:`DesktopHostFatalError: … required plugins did not activate / better-sidebar` | profile 里自带了 `@deepseek-ai/dsh-*` 副本(旧 DSH 版本留下的,或被写进 profile 的 `package.json` / overrides),它们会抢在宿主安装之前被解析,本插件静态 import 的 `dsh-subagent` 因此绑到混搭版本;混版缺导出时宿主只报这条 fatal,看不到是哪个包缺了什么。先确认(新版插件随包提供):`node ~/.dsh/profiles/web/node_modules/dsh-better-sidebar/scripts/check-profile-host-tree.mjs ~/.dsh/profiles/web`。修复:从 profile 的 `package.json` / overrides 移除 `@deepseek-ai/dsh-*` 后在该目录 `pnpm install`(让宿主安装提供),或把两份副本对齐到同一版本;然后重启。安装脚本会自动跑这条检查。 | | 页面出现**两个侧边栏** | 双挂载。删掉 `~/.dsh/profiles/web/cordis.patch.yml` 里旧的手动挂载行(`- insert: ... better-sidebar ...`);聚合包以不同 id 挂载本包时会自动退让,无需处理。 | | 升级后设置页的值去哪了 | DSH 0.1.7 起偏好写在 profile 里本插件的挂载行上(默认 entry id `better-sidebar`),插件首次启动会把旧 `settings.yaml` 里的配置一次性回迁,不会覆盖新设的值。 | | 终端无法使用 | 终端由 **DSH 自身**提供(本插件不自带 PTY),请查 DSH 侧文档;底部终端显示「宿主未提供终端能力」= 这个部署没挂终端控制器。 | diff --git a/docs/host-contracts.md b/docs/host-contracts.md index 84abe8a3..79bb1ec5 100644 --- a/docs/host-contracts.md +++ b/docs/host-contracts.md @@ -35,6 +35,7 @@ 6. **`@deepseek-ai/dsh-client-runtime` 包已消亡**(继任 seed 是裸名 `dsh-client-store`,无 `/client` 子路径):peerDependencies、devDependencies、`dsh.client.inject`、chunk externals 白名单(`src/client/chunk-loader.ts` / `tsdown.config.ts` 各有一处说明它已移除的注释)**无活引用**。 7. **e2e scratch profile 的 `minimumReleaseAgeExclude` 含 `'@deepseek-ai/*'`**(字面配置在 `scripts/e2e-common.sh` 的 `e2e_write_profile` heredoc,`e2e-mount.sh` / `e2e-aggregate-mount.sh` 都调它;与仓库根 `pnpm-workspace.yaml` 同策):alpha 版本常在发布后 24h 内跑 lane,pnpm 11 的 `minimumReleaseAge` 默认会拒装新鲜包。 8. **插件开发树的 dsh-* 传递 peer 需提升为 devDependencies**:npm 上的宿主包把姊妹包(`dsh-attachment` / `scope` / `session-projection` / `system-prompt` / `user-approval` / `util-time` 等)声明为 peerDependencies(由宿主 bundle 树统一提供,插件仓库没有),插件若只直接依赖其中一部分,其余 peer 在 pnpm 下会解析到树上残留的旧版——测试加载即崩。因此 devDependencies 需涵盖 dev 树实际触达的全部 peer,与直接依赖同款精确钉版;**一律以 `pnpm peers check` 的实际输出为准,不要预加**(`dsh-workspace` / `dsh-agent-preset-registry` 只是 `dsh-subagent` 的 optional peer 且从不被 import)。当前伴随依赖为 Cordis `4.0.5`、schemastery `~3.18.5`、group `1.0.5` 与 include `1.0.10`;不直接钉 loader、不设 override,Cordis peer 下限为 `^4.0.5`,dev 精确 `4.0.5`;与 RC 宿主及传递 loader 的范围一致;`cordis-plugin-group` / `-include` 是 `dsh-app-boot` / `dsh-config-editor` 的**传递 peer**,只改 `dependencies` 不够(pnpm 会继续沿用 lockfile 里的旧副本),要**显式钉进 devDependencies** 才收敛。例外已消除:`dsh-client-locale` 与 DSH 同 tuple,不再允许落后。 + **用户 profile 侧同理,而且优先级相反**:DSH 的 profile 解析(`dsh-app-boot` 的 `routeScoped`)先取 profile 内 `node_modules` 的副本,且只在 profile 前缀内查找(`layer.localPrefix`;`~/.dsh/profiles/node_modules` 这类上级目录永远不参与)。用户 profile 自带的 `@deepseek-ai/dsh-*` 因此会覆盖宿主安装的同一批包,插件静态 import 的宿主包(本插件是 `dsh-subagent`)会绑到混搭版本,混版缺导出时整只宿主只报 `DesktopHostFatalError: required plugins did not activate`,看不到是哪个包缺了什么(#1107)。判据用 `dsh-subagent` 精确声明的 `dsh-attachment` peer:`scripts/check-profile-host-tree.mjs` 随包发布,`scripts/install.sh` / `install.ps1` 装完自动运行,混版即打印两份版本号与修复命令并退出。 9. **右侧栏是 DSH 原生栏,插件只提供 tab 类型**(**编号提示**:旧文与代码注释里把它引用作 `§3.10` / `§3 第 10 条`——`tests/native-surface-cross-session.spec.ts` 的 `§3.10` 与指南 §10 表格里的「第 10 条」都指本条):聊天里一切文件打开(工具行 / 产物行 / 正文提及 / 行内代码路径)统一走 `ctx.sidebarRight.openResource(fileAddressFor(sessionId, cwd, path))`,其中文件地址语法为「一律 session 作用域、绝对路径保留前导 `/`」,`parseFileAddress` 前缀解析并去 `?`/`#`。插件的每个 `TabDescriptor` 注册成原生 tab 类型(`kind = descriptor.id`,`extension` 带)+ 原生 tab 体(`sidebar.right.pane.tab` keyed 槽,key = `dsh-better-sidebar:`);`editor` 类型同时认领 `dsh-resource://file/**`(**但按本文 A 节的清单让出一部分**),并接管内置 `files` 页面 kind(`openTab('files')` 打开插件文件树,注销即复位)。`ctx.sidebarRight.openTab/openResource/close` 只对**在屏会话**写入,跨会话用具体类上的 `openTabIn/openResourceIn/closeIn`;原生 tab 的插件侧状态在 `src/client/native/tab-adapter.tsx`。几条硬事实: - **注册必须等服务、不能等槽声明**:原生栏先声明 `sidebar.right.pane.tab` 再 `provide('sidebarRightTabs')`,真机 profile 上槽声明回调里 `ctx.get('sidebarRightTabs')` 仍是 undefined(实测 3 秒后才出现),按槽触发注册会静默什么都不注册且永不重试——用 `ctx.inject(['sidebarRightTabs'], cb)` 驱动类型注册(`tests/native-surface.spec.ts` 以「槽先触发、服务后到达」的顺序守护)。 - `SidebarRightGuideEntry.id` **必填且同 provider 内唯一**(缺它会静默清空整个承载面);同 provider 的 guide 条目是**追加**关系(`chain` 那种「替换宿主条目」的语义只存在于 `conversation.chat.turnTail` 且已被上游改成 `list`)。**指南只描述 ≤4 条条目**(`GuideBody.tsx` 的 `MAX_DESCRIBED_ENTRIES`):更长是整列丢弃而不是截断——插件默认贡献 4 个 guide 条目(文件 / Git / 任务管理 / 侧边对话),加上宿主终端条目后可能超限;插件**不恢复**旧的 `nativeGuideDesc` 通用兜底句。 diff --git a/package.json b/package.json index 7e22a766..c3aaf85a 100644 --- a/package.json +++ b/package.json @@ -64,6 +64,7 @@ "lib/client-terminal.js", "lib/types/**/*.d.ts", "src", + "scripts/check-profile-host-tree.mjs", "scripts/install.sh", "scripts/install.ps1", "cordis.patch.yml", diff --git a/scripts/check-profile-host-tree.mjs b/scripts/check-profile-host-tree.mjs new file mode 100644 index 00000000..76179ef4 --- /dev/null +++ b/scripts/check-profile-host-tree.mjs @@ -0,0 +1,112 @@ +/** + * Detect the torn host-package shadow pair that keeps this plugin from + * activating at all (issue #1107: `DesktopHostFatalError: required plugins did + * not activate / better-sidebar`). + * + * DSH resolves a profile plugin's bare imports through its own runtime + * interception (`dsh-app-boot`'s `routeScoped`): a copy the profile installs + * under `/node_modules` wins over the installation's own tuple, and + * that winning copy is itself the anchor for that copy's siblings' imports. + * So a profile carrying its own `@deepseek-ai/dsh-subagent` also binds + * `@deepseek-ai/dsh-attachment` from the profile tree. The plugin statically + * imports `dsh-subagent` (src/sidechat-routes.ts), whose module graph pulls + * the rest of the host packages — a mixed set can strip a symbol that graph + * imports, and the failure surfaces as a host fatal error ("required plugins + * did not activate") instead of one readable plugin error. + * + * The reliable signal for that mix is the sibling pin: `dsh-subagent` declares + * the exact host version of `dsh-attachment`, so a profile copy that disagrees + * with it came from a different host release. When the profile shadows only the + * subagent, the installation supplies the sibling and that pairing is out of + * reach here. + * + * The lookup below mirrors that resolution exactly: Node's node_modules order + * from the installed plugin, restricted to the profile directory — the prefix + * the interception stops at (`layer.localPrefix`), which is why copies above + * the profile (the shared `profiles/node_modules` tree) never win there and + * are ignored here. + * + * Only an exact pinned peer is judged (`dsh-subagent` pins the sibling host + * package by exact version, so the pairing is decidable); ranged peers are + * treated as clear rather than guessed at. + * + * Usage: node scripts/check-profile-host-tree.mjs + * Exit 0 — nothing torn (plugin not installed, no shadow copy, or a matching + * pair); exit 1 — torn pair, with the repair printed to stderr. + */ +import { existsSync, readFileSync, realpathSync } from 'node:fs' +import { createRequire } from 'node:module' +import { join, resolve, sep } from 'node:path' + +const PLUGIN = 'dsh-better-sidebar' +const SUBAGENT = '@deepseek-ai/dsh-subagent' +const ATTACHMENT = '@deepseek-ai/dsh-attachment' +const EXACT_VERSION = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/ + +function realOrUndefined(path) { + try { + return realpathSync(path) + } catch { + return undefined + } +} + +function manifestOf(dir) { + return JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8')) +} + +/** + * The copy Node would pick for `name` from `anchor`, limited to the profile + * tree. Returns undefined when the profile installs no such copy (the host + * installation then supplies it, consistently for every importer). + */ +function shadowOf(anchor, name, profileDir) { + const prefix = profileDir + sep + for (const searchPath of createRequire(anchor).resolve.paths(name) ?? []) { + if (!searchPath.startsWith(prefix)) continue + const dir = join(searchPath, name) + if (existsSync(join(dir, 'package.json'))) return dir + } + return undefined +} + +/** The broken pairing, or undefined when the profile cannot break this import. */ +function tornPair(profileDir) { + const profile = realOrUndefined(profileDir) + if (profile === undefined) return undefined + const pluginDir = realOrUndefined(join(profile, 'node_modules', PLUGIN)) + // A `link:` install resolves outside the profile tree and is not intercepted + // as a profile-layer importer, so the shadow rule does not apply to it. + if (pluginDir === undefined || !pluginDir.startsWith(profile + sep)) return undefined + const subagentDir = shadowOf(join(pluginDir, 'package.json'), SUBAGENT, profile) + if (subagentDir === undefined) return undefined + const expected = manifestOf(subagentDir).peerDependencies?.[ATTACHMENT] + if (typeof expected !== 'string' || !EXACT_VERSION.test(expected)) return undefined + const attachmentDir = shadowOf(join(subagentDir, 'package.json'), ATTACHMENT, profile) + if (attachmentDir === undefined) return undefined + const subagent = manifestOf(subagentDir).version + const attachment = manifestOf(attachmentDir).version + return attachment === expected ? undefined : { profile, subagent, expected, attachment } +} + +const profileArg = process.argv[2] +if (profileArg === undefined || profileArg === '') { + console.error('用法:node scripts/check-profile-host-tree.mjs ') + process.exit(2) +} + +const torn = tornPair(resolve(profileArg)) +if (torn === undefined) { + console.log('[host-tree] profile 未自带宿主包影子副本,或 @deepseek-ai/dsh-subagent ↔ dsh-attachment 配对一致') + process.exit(0) +} + +console.error(`[host-tree] profile 自带的宿主包配对不一致:${SUBAGENT} ${torn.subagent} 要求 ${ATTACHMENT} ${torn.expected},实际解析到 ${torn.attachment}`) +console.error(`[host-tree] profile:${torn.profile}`) +console.error('[host-tree] 它们会抢在 DSH 安装之前被解析,本插件静态 import 的 dsh-subagent 因此绑到混搭版本;混版缺导出时宿主启动只报') +console.error('[host-tree] DesktopHostFatalError / required plugins did not activate,看不到是哪个包缺了什么。') +console.error('[host-tree] 修复(任选其一,然后重启 DSH):') +console.error(`[host-tree] A. 让 DSH 安装提供宿主包:从 profile 的 package.json 与 overrides 移除 @deepseek-ai/dsh-*,再 cd ${torn.profile} && pnpm install`) +console.error(`[host-tree] (若副本由别的依赖带进来:cd ${torn.profile} && pnpm update @deepseek-ai/dsh-*` + ')') +console.error(`[host-tree] B. 把副本对齐到同一版本:cd ${torn.profile} && pnpm add ${SUBAGENT}@${torn.expected} ${ATTACHMENT}@${torn.expected}`) +process.exit(1) diff --git a/scripts/install.ps1 b/scripts/install.ps1 index 3e22e921..b9946335 100644 --- a/scripts/install.ps1 +++ b/scripts/install.ps1 @@ -161,8 +161,9 @@ if ($DryRun) { Say "[dry-run] 步骤 1:确保 $WS_YML 含 minimumReleaseAgeExclude($PKG)" Say "[dry-run] 步骤 2:执行 $CLI plugin --profile $Profile add $PKG@$SPEC(安装 + bundle 自动注册)" Say "[dry-run] 步骤 3:校验 dsh.profile.bundles 含 $PKG" - Say "[dry-run] 步骤 4:幂等移除 $PATCH_YML 里旧的 better-sidebar 手动挂载行(避免双挂载)" - if ($Restart) { Say '[dry-run] 步骤 5:pm2 restart dsh-web' } else { Say '[dry-run] 步骤 5:提示用户手动重启 DSH' } + Say "[dry-run] 步骤 4:校验 profile 自带的 @deepseek-ai 宿主包配对(混版会让宿主启动即崩)" + Say "[dry-run] 步骤 5:幂等移除 $PATCH_YML 里旧的 better-sidebar 手动挂载行(避免双挂载)" + if ($Restart) { Say '[dry-run] 步骤 6:pm2 restart dsh-web' } else { Say '[dry-run] 步骤 6:提示用户手动重启 DSH' } exit 0 } @@ -196,7 +197,24 @@ if ($bundles -notcontains $PKG) { } Say "bundle 已注册:dsh.profile.bundles 包含 $PKG(下次启动自动挂载)" -# 步骤 4:幂等移除旧的 manual 挂载行(避免与 bundle 双挂载) +# 步骤 4:校验 profile 自带的宿主包配对(#1107)。profile 里的 @deepseek-ai +# 副本会抢在宿主安装之前被加载(DSH 的 profile 解析把 profile 内副本排在 +# 安装副本之前),本插件静态 import 的 dsh-subagent 因此绑到混搭版本;混版 +# 缺导出时宿主只报 DesktopHostFatalError / required plugins did not activate, +# 看不到是哪个包缺了什么。判据用 dsh-subagent 精确声明的 dsh-attachment peer。 +# 检查脚本随包发布,用刚装好的那份运行。 +$hostTreeCheck = Join-Path $PROFILE_DIR "node_modules\$PKG\scripts\check-profile-host-tree.mjs" +if (Test-Path $hostTreeCheck) { + & node $hostTreeCheck $PROFILE_DIR + if ($LASTEXITCODE -ne 0) { + Warn 'profile 自带的 @deepseek-ai 宿主包混版:重启后本插件无法激活(宿主启动失败)。按上面的提示修好后重跑本脚本。' + exit 1 + } +} else { + Warn "未找到 $hostTreeCheck(该插件版本未携带宿主包配对检查),跳过。" +} + +# 步骤 5:幂等移除旧的 manual 挂载行(避免与 bundle 双挂载) $mountScript = @' const fs = require("fs"); const p = process.argv[2]; @@ -246,7 +264,7 @@ if ($mountResult -eq 'removed') { Say "安装完成:$PKG@$SPEC" -# 步骤 5:重启提示 +# 步骤 6:重启提示 if ($Restart) { if (Get-Command pm2 -ErrorAction SilentlyContinue) { Say '重启 dsh-web(pm2)...' diff --git a/scripts/install.sh b/scripts/install.sh index 7a9cb01a..d2c337aa 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -160,8 +160,9 @@ if [ "$DRY_RUN" = true ]; then say "[dry-run] 步骤 1:确保 $WS_YML 含 minimumReleaseAgeExclude(${PKG})" say "[dry-run] 步骤 2:执行 $CLI plugin --profile $PROFILE_NAME add $PKG@${SPEC}(安装 + bundle 自动注册)" say "[dry-run] 步骤 3:校验 dsh.profile.bundles 含 $PKG" - say "[dry-run] 步骤 4:幂等移除 $PATCH_YML 里旧的 better-sidebar 手动挂载行(避免双挂载)" - if [ "$RESTART" = true ]; then say "[dry-run] 步骤 5:pm2 restart dsh-web"; else say "[dry-run] 步骤 5:提示用户手动重启 DSH"; fi + say "[dry-run] 步骤 4:校验 profile 自带的 @deepseek-ai 宿主包配对(混版会让宿主启动即崩)" + say "[dry-run] 步骤 5:幂等移除 $PATCH_YML 里旧的 better-sidebar 手动挂载行(避免双挂载)" + if [ "$RESTART" = true ]; then say "[dry-run] 步骤 6:pm2 restart dsh-web"; else say "[dry-run] 步骤 6:提示用户手动重启 DSH"; fi exit 0 fi @@ -190,7 +191,23 @@ if ! node -e ' fi say "bundle 已注册:dsh.profile.bundles 包含 ${PKG}(下次启动自动挂载)" -# 步骤 3:幂等移除旧的 manual 挂载行(避免与 bundle 双挂载) +# 步骤 4:校验 profile 自带的宿主包配对(#1107)。profile 里的 @deepseek-ai +# 副本会抢在宿主安装之前被加载(DSH 的 profile 解析把 profile 内副本排在 +# 安装副本之前),本插件静态 import 的 dsh-subagent 因此绑到混搭版本;混版 +# 缺导出时宿主只报 DesktopHostFatalError / required plugins did not activate, +# 看不到是哪个包缺了什么。判据用 dsh-subagent 精确声明的 dsh-attachment peer。 +# 检查脚本随包发布,用刚装好的那份运行。 +HOST_TREE_CHECK="$PROFILE_DIR/node_modules/$PKG/scripts/check-profile-host-tree.mjs" +if [ -f "$HOST_TREE_CHECK" ]; then + if ! node "$HOST_TREE_CHECK" "$PROFILE_DIR"; then + warn "profile 自带的 @deepseek-ai 宿主包混版:重启后本插件无法激活(宿主启动失败)。按上面的提示修好后重跑本脚本。" + exit 1 + fi +else + warn "未找到 ${HOST_TREE_CHECK}(该插件版本未携带宿主包配对检查),跳过。" +fi + +# 步骤 5:幂等移除旧的 manual 挂载行(避免与 bundle 双挂载) MOUNT_RESULT="$(node -e ' const fs = require("fs"); const p = process.argv[1]; @@ -231,7 +248,7 @@ if (!removed) { say "安装完成:$PKG@$SPEC" -# 步骤 4:重启提示 +# 步骤 6:重启提示 if [ "$RESTART" = true ]; then if command -v pm2 >/dev/null 2>&1; then say "重启 dsh-web(pm2)..." diff --git a/tests/install-host-tree.spec.ts b/tests/install-host-tree.spec.ts new file mode 100644 index 00000000..ab6e2e0f --- /dev/null +++ b/tests/install-host-tree.spec.ts @@ -0,0 +1,127 @@ +/** + * Host-package shadow contract (#1107). + * + * DSH resolves a profile plugin's bare imports through its own profile + * interception, where a copy installed inside the profile beats the + * installation's tuple and becomes the anchor for that copy's own siblings. + * A profile carrying its own `@deepseek-ai/dsh-subagent` therefore also + * resolves `@deepseek-ai/dsh-attachment` from the profile tree; when the two + * copies disagree, loading this plugin dies in the ESM linker and the whole + * host refuses to boot ("required plugins did not activate") instead of + * disabling one row. + * + * `scripts/check-profile-host-tree.mjs` must predict exactly the resolution the + * host will perform: profile-local copies only (plus the pairing rule), silent + * pass otherwise. `tests/...` run the shipped script itself, so the assertions + * below fail if the detection is removed, not just if its output is reworded. + * Both standalone installers must run it after installing and before telling + * the user to restart, and the script must be published or that run silently + * skips. + */ +import { execFileSync } from 'node:child_process' +import { mkdirSync, mkdtempSync, readFileSync, realpathSync, writeFileSync } from 'node:fs' +import { tmpdir } from 'node:os' +import { join, resolve } from 'node:path' +import { fileURLToPath } from 'node:url' +import { afterEach, describe, expect, it } from 'vitest' +import { removeTree } from './temp-tree.ts' + +const ROOT = resolve(fileURLToPath(new URL('..', import.meta.url))) +const CHECK = resolve(ROOT, 'scripts/check-profile-host-tree.mjs') +const SUBAGENT = '@deepseek-ai/dsh-subagent' +const ATTACHMENT = '@deepseek-ai/dsh-attachment' +const tempDirs: string[] = [] + +function tempDir(): string { + const dir = mkdtempSync(join(tmpdir(), 'dshbs-host-tree-')) + tempDirs.push(dir) + return dir +} + +function writePackage(dir: string, manifest: Record): void { + mkdirSync(dir, { recursive: true }) + writeFileSync(join(dir, 'package.json'), JSON.stringify(manifest)) +} + +/** One profile with the plugin installed and the requested host-package copies. */ +function profileFixture(options: { plugin?: boolean; subagent?: string; attachment?: string; peer?: string }): string { + const profile = join(tempDir(), 'web') + if (options.plugin !== false) writePackage(join(profile, 'node_modules', 'dsh-better-sidebar'), { name: 'dsh-better-sidebar', version: '0.29.0' }) + if (options.subagent !== undefined) { + writePackage(join(profile, 'node_modules', SUBAGENT), { + name: SUBAGENT, + version: options.subagent, + peerDependencies: { [ATTACHMENT]: options.peer ?? options.subagent }, + }) + } + if (options.attachment !== undefined) writePackage(join(profile, 'node_modules', ATTACHMENT), { name: ATTACHMENT, version: options.attachment }) + return profile +} + +function runCheck(profile: string): { status: number; output: string } { + try { + const stdout = execFileSync(process.execPath, [CHECK, profile], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }) + return { status: 0, output: stdout } + } catch (error) { + const failed = error as { status?: number; stdout?: string; stderr?: string } + return { status: failed.status ?? -1, output: `${failed.stdout ?? ''}${failed.stderr ?? ''}` } + } +} + +afterEach(() => { + for (const dir of tempDirs.splice(0)) removeTree(dir) +}) + +describe('profile host-package shadow check', () => { + it('fails a torn subagent/attachment pair and names both versions', () => { + const profile = profileFixture({ subagent: '0.2.1-rc.5', attachment: '0.1.0-rc.8', peer: '0.2.1-rc.5' }) + const { status, output } = runCheck(profile) + + expect(status).toBe(1) + expect(output).toContain('0.2.1-rc.5') + expect(output).toContain('0.1.0-rc.8') + expect(output).toContain(realpathSync(profile)) + }) + + it('passes a profile copy pair that matches the subagent peer pin', () => { + const profile = profileFixture({ subagent: '0.2.1-rc.5', attachment: '0.2.1-rc.5' }) + + expect(runCheck(profile).status).toBe(0) + }) + + it('passes a shadowed subagent whose attachment the installation then supplies', () => { + const profile = profileFixture({ subagent: '0.2.1-rc.5' }) + + expect(runCheck(profile).status).toBe(0) + }) + + it('ignores a stale copy above the profile, where the host never looks', () => { + const root = tempDir() + const profile = join(root, 'web') + writePackage(join(profile, 'node_modules', 'dsh-better-sidebar'), { name: 'dsh-better-sidebar', version: '0.29.0' }) + writePackage(join(profile, 'node_modules', SUBAGENT), { name: SUBAGENT, version: '0.2.1-rc.5', peerDependencies: { [ATTACHMENT]: '0.2.1-rc.5' } }) + writePackage(join(root, 'node_modules', ATTACHMENT), { name: ATTACHMENT, version: '0.1.0-rc.8' }) + + expect(runCheck(profile).status).toBe(0) + }) + + it('passes a profile without the plugin or without any shadow copy', () => { + expect(runCheck(profileFixture({ plugin: false, subagent: '0.2.1-rc.5', attachment: '0.1.0-rc.8' })).status).toBe(0) + expect(runCheck(tempDir()).status).toBe(0) + }) + + it('is shipped in the published package and run by both standalone installers', () => { + const pkg = JSON.parse(readFileSync(join(ROOT, 'package.json'), 'utf8')) as { files?: string[] } + expect(pkg.files).toContain('scripts/check-profile-host-tree.mjs') + + const invocations = [ + ['scripts/install.sh', 'node_modules/$PKG/scripts/check-profile-host-tree.mjs', 'node "$HOST_TREE_CHECK" "$PROFILE_DIR"'], + ['scripts/install.ps1', 'node_modules\\$PKG\\scripts\\check-profile-host-tree.mjs', '& node $hostTreeCheck $PROFILE_DIR'], + ] as const + for (const [installer, scriptPath, command] of invocations) { + const source = readFileSync(join(ROOT, installer), 'utf8') + expect(source, installer).toContain(scriptPath) + expect(source, installer).toContain(command) + } + }) +})