From 945b9624d65cd59ebac8b24d8aa417c5ece60a12 Mon Sep 17 00:00:00 2001 From: yexi Date: Wed, 14 Oct 2026 22:53:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=A1=8C=E9=9D=A2=E7=89=88?= =?UTF-8?q?=E4=BE=9D=E8=B5=96=E5=86=B2=E7=AA=81=E6=81=A2=E5=A4=8D=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E4=B8=8E=E5=AE=9E=E6=B5=8B=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/issue-7-recovery.md | 40 +++++++++++++ tools/repair-desktop-profile.ps1 | 100 +++++++++++++++++++++++++++++++ 2 files changed, 140 insertions(+) create mode 100644 docs/issue-7-recovery.md create mode 100644 tools/repair-desktop-profile.ps1 diff --git a/docs/issue-7-recovery.md b/docs/issue-7-recovery.md new file mode 100644 index 0000000..0832a59 --- /dev/null +++ b/docs/issue-7-recovery.md @@ -0,0 +1,40 @@ +# Desktop 0.2.0-rc.2 的预设加载失败恢复 + +适用于 [issue #7](https://github.com/yexi-by/dsh-unrestricted/issues/7):为处理插件导入错误,手工安装了 `@deepseek-ai/dsh-system-prompt`、`@deepseek-ai/dsh-scope`、`@deepseek-ai/cordis` 等宿主包,随后四个预设加载失败,并提示: + +```text +persona (@deepseek-ai/dsh-persona): prompt section "deployment:persona-prefix" is already registered (for a per-agent override, register through that agent's `agent.ctx` instead) +``` + +这些宿主包应由桌面版运行时提供。额外安装的副本可能让预设注册与提示词服务使用不同的作用域标记,即使版本号相同也会产生该错误。 + +报告者同时安装的 `dsh-openwrite@0.2.12` 依赖旧版 `@deepseek-ai/schemastery@3.18.2`。默认平铺布局会把该包放在其他插件的查找路径中,破限插件随后会出现 `.volatile is not a function`。恢复流程同时改用隔离布局,保留 OpenWrite 自己的旧依赖,让破限插件继续使用宿主提供的版本。 + +## 恢复步骤 + +1. 完全退出 DeepSeek Harness Desktop,包括托盘中的进程。 +2. 下载与本文一起提供的 `repair-desktop-profile.ps1`,在文件所在目录打开 PowerShell,运行: + + ```powershell + powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\repair-desktop-profile.ps1 + ``` + +3. 重新启动桌面版。在插件页面启用 `dsh-unrestricted`,再打开破限功能开关,确认四种模式通过校验并新建会话。 + +脚本先备份 profile 的配置、依赖清单和锁文件,再把包管理设置改为 `nodeLinker: isolated`、`hoist: false`、`autoInstallPeers: false`,将旧 `node_modules` 移入同一备份目录。随后使用桌面版自带 CLI 移除破限插件及直接声明的六个相关宿主包,重新安装官方 `v0.2.2` 和其余已有依赖。其他插件的依赖声明、会话和自定义预设保留;不会自动退出或启动桌面应用。备份位置会打印在命令输出中。 + +如果桌面版安装在其他目录,使用 `-DesktopCliPath '实际路径\resources\runtime\cli\bin\dsh.cmd'`。如果设置了不同的 DSH 数据目录,使用 `-DshHomePath '实际的 DSH_HOME 目录'`。脚本默认继承 `DSH_HOME`,未设置时使用用户目录下的 `.dsh`。 + +执行失败时保留完整输出并反馈。若再次出现 `ERR_MODULE_NOT_FOUND`,不要继续手工补装宿主包,应检查桌面版 CLI 路径及 profile 的安装布局。 + +## 实测范围 + +使用 Windows 上桌面版自带 `0.2.0-rc.2` 运行时及临时 profile 验证,未启动桌面界面,也未调用模型 API: + +- 全新安装官方 `v0.2.2` 后,standard、ptc、cordis、minimal 均可创建 Agent。 +- 开启破限后四种模式均完成注入,工具列表不变;关闭后提示词恢复。 +- 按报告补装五个宿主依赖后,复现同一条全局 persona 重复注册异常。 +- 保留报告中的自定义小说预设、`dsh-novel-craft@0.3.0` 和 `dsh-openwrite@0.2.12`,复现旧 schemastery 的导入冲突;隔离依赖后四种模式及小说预设重新可加载。 +- 最终恢复脚本在含以上插件和手工宿主依赖的 profile 上执行后,再次完成加载、开关与回滚验证;恢复过程保持 `cordis.patch.yml` 字节不变,并保留另外两个插件的依赖声明和 bundle。 + +该流程针对报告中的安装状态;尚未在报告者电脑上执行。 diff --git a/tools/repair-desktop-profile.ps1 b/tools/repair-desktop-profile.ps1 new file mode 100644 index 0000000..97fcc88 --- /dev/null +++ b/tools/repair-desktop-profile.ps1 @@ -0,0 +1,100 @@ +#requires -Version 5.1 +<# +.SYNOPSIS +修复 issue #7 中手工补装宿主依赖后,桌面版预设全部加载失败的问题。 +.DESCRIPTION +先备份 profile 配置和依赖清单,再通过桌面版自带 CLI 隔离第三方依赖, +移除手工宿主依赖,并重新安装已验证的官方插件 v0.2.2。 +运行前请完全退出 DSH Desktop;脚本不会退出或启动桌面应用。 +#> +[CmdletBinding()] +param( + [string]$DesktopCliPath = (Join-Path $env:LOCALAPPDATA 'Programs/DeepSeek Harness/resources/runtime/cli/bin/dsh.cmd'), + [string]$DshHomePath = $(if ([string]::IsNullOrWhiteSpace($env:DSH_HOME)) { Join-Path $env:USERPROFILE '.dsh' } else { $env:DSH_HOME }), + [string]$ProfileName = 'desktop' +) + +$ErrorActionPreference = 'Stop' +if (-not (Test-Path -LiteralPath $DesktopCliPath -PathType Leaf)) { + throw "找不到桌面版 CLI:$DesktopCliPath。请用 -DesktopCliPath 指定实际安装目录内的 dsh.cmd。" +} +if ($ProfileName -notmatch '^[a-zA-Z0-9][a-zA-Z0-9_-]*$') { + throw 'ProfileName 必须是 profile 名称,不能是路径。' +} +$DshHomePath = [System.IO.Path]::GetFullPath($DshHomePath) +$profileDirectory = Join-Path (Join-Path $DshHomePath 'profiles') $ProfileName +$manifestPath = Join-Path $profileDirectory 'package.json' +if (-not (Test-Path -LiteralPath $manifestPath -PathType Leaf)) { + throw "找不到现有 profile:$manifestPath。请确认 DSH_HOME 或用 -DshHomePath 指定实际目录。" +} +$manifest = Get-Content -LiteralPath $manifestPath -Raw -Encoding UTF8 | ConvertFrom-Json +$sharedPackageNames = @( + '@deepseek-ai/cordis', + '@deepseek-ai/schemastery', + '@deepseek-ai/dsh-system-prompt', + '@deepseek-ai/dsh-scope', + '@deepseek-ai/dsh-invariants', + '@deepseek-ai/dsh-llm' +) +$declaredNames = @( + foreach ($section in @('dependencies', 'devDependencies', 'optionalDependencies', 'peerDependencies')) { + $dependencies = $manifest.$section + if ($null -ne $dependencies) { $dependencies.PSObject.Properties.Name } + } +) +$removeNames = @( + @('dsh-unrestricted') + $sharedPackageNames | + Where-Object { $declaredNames -contains $_ } | + Select-Object -Unique +) +$backupDirectory = Join-Path $profileDirectory ('.plugin-manager/backups/unrestricted-issue7-' + (Get-Date -Format 'yyyyMMdd-HHmmss') + '-' + [guid]::NewGuid().ToString('N').Substring(0, 6)) +New-Item -ItemType Directory -Path $backupDirectory -Force | Out-Null +foreach ($filename in @('package.json', 'pnpm-lock.yaml', 'pnpm-workspace.yaml', 'cordis.yml', 'cordis.patch.yml')) { + $sourcePath = Join-Path $profileDirectory $filename + if (Test-Path -LiteralPath $sourcePath -PathType Leaf) { + Copy-Item -LiteralPath $sourcePath -Destination (Join-Path $backupDirectory $filename) + } +} +Write-Host "配置和依赖清单已备份到:$backupDirectory" + +function Invoke-DesktopDsh { + param([string[]]$DshArguments) + & $DesktopCliPath @DshArguments + if ($LASTEXITCODE -ne 0) { + throw "桌面版 CLI 执行失败(退出码 $LASTEXITCODE)。请保留上面的错误和备份目录;不要手工安装 @deepseek-ai 宿主包。" + } +} + +$previousDshHome = $env:DSH_HOME +try { + $env:DSH_HOME = $DshHomePath + Invoke-DesktopDsh -DshArguments @('--version') + # OpenWrite 的旧 schemastery 仅供它自身使用,不能提升到其他插件的查找路径。 + Invoke-DesktopDsh -DshArguments @('plugin', '--profile', $ProfileName, 'config', 'set', 'nodeLinker', 'isolated', '--location', 'project') + Invoke-DesktopDsh -DshArguments @('plugin', '--profile', $ProfileName, 'config', 'set', 'hoist', 'false', '--location', 'project') + Invoke-DesktopDsh -DshArguments @('plugin', '--profile', $ProfileName, 'config', 'set', 'autoInstallPeers', 'false', '--location', 'project') + + # 更换安装布局前保留旧目录;不删除插件源码、会话或 profile 配置。 + $moduleDirectory = [System.IO.Path]::GetFullPath((Join-Path $profileDirectory 'node_modules')) + $moduleBackup = [System.IO.Path]::GetFullPath((Join-Path $backupDirectory 'node_modules')) + $profilePrefix = [System.IO.Path]::GetFullPath($profileDirectory).TrimEnd('\', '/') + [System.IO.Path]::DirectorySeparatorChar + if (-not $moduleDirectory.StartsWith($profilePrefix, [System.StringComparison]::OrdinalIgnoreCase) -or + -not $moduleBackup.StartsWith($profilePrefix, [System.StringComparison]::OrdinalIgnoreCase)) { + throw '依赖目录或备份目录不在指定 profile 内,已停止。' + } + if (Test-Path -LiteralPath $moduleDirectory) { + Move-Item -LiteralPath $moduleDirectory -Destination $moduleBackup + } + if ($removeNames.Count -gt 0) { + Invoke-DesktopDsh -DshArguments (@('plugin', '--profile', $ProfileName, 'remove') + $removeNames) + } + Invoke-DesktopDsh -DshArguments @('plugin', '--profile', $ProfileName, 'add', 'github:yexi-by/dsh-unrestricted#v0.2.2') + $installedManifestPath = Join-Path $profileDirectory 'node_modules/dsh-unrestricted/package.json' + $installed = Get-Content -LiteralPath $installedManifestPath -Raw -Encoding UTF8 | ConvertFrom-Json + if ($installed.version -ne '0.2.2') { + throw "安装包版本应为 0.2.2,实际为 $($installed.version)。请保留命令输出。" + } + Write-Host '官方 dsh-unrestricted v0.2.2 已重新安装,第三方依赖已隔离。请启动 DSH Desktop,开启插件及破限功能开关,再新建会话验证。' +} finally { + $env:DSH_HOME = $previousDshHome +}