fix(install): 装完先查 profile 自带的宿主包是否混版(#1107)

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 真跑发布脚本钉住行为。
This commit is contained in:
Menghuan1918 committed 2026-11-04 21:03:54 +08:00
1 parent 4f6b763d1e
commit 4c1d4177d9
10 files changed
+290 -8

No files matched your search

+112
View File
@@ -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 `<profile>/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 <profile dir>
* 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 <profile 目录>')
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)
+22 -4
View File
@@ -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)...'
+21 -4
View File
@@ -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)..."