diff --git a/README.md b/README.md index 0ebe50f..09ce1aa 100644 --- a/README.md +++ b/README.md @@ -252,9 +252,10 @@ prompt-inject.md 有内容? ──是──> 注入 systemPrompt section 按优先级自动定位: 1. `DSH_BASE` 环境变量 → 插件根 -2. `npm prefix -g` / `npm config get prefix` → npm 全局目录 -3. 从全局目录反推 `node_modules/@deepseek-ai/dsh/node_modules/@deepseek-ai` -4. 递归搜索兜底 +2. DSH Desktop → `process.resourcesPath/app.asar.unpacked/node_modules/@deepseek-ai` +3. `npm prefix -g` / `npm config get prefix` → npm 全局目录 +4. 从全局目录反推 `node_modules/@deepseek-ai/dsh/node_modules/@deepseek-ai` +5. 递归搜索兜底 当前 Desktop Harness 的 monorepo 安装结构还会从 `dsh-base` 的真实路径 反推出版本根,并兼容 `packages/interaction/user-approval` 与 diff --git a/README.zh-CN.md b/README.zh-CN.md index 9baa1c9..77dce83 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -249,9 +249,10 @@ prompt-inject.md 有内容? ──是──> 注入 systemPrompt section 按优先级自动定位: 1. `DSH_BASE` 环境变量 → 插件根 -2. `npm prefix -g` / `npm config get prefix` → npm 全局目录 -3. 从全局目录反推 `node_modules/@deepseek-ai/dsh/node_modules/@deepseek-ai` -4. 递归搜索兜底 +2. DSH Desktop → `process.resourcesPath/app.asar.unpacked/node_modules/@deepseek-ai` +3. `npm prefix -g` / `npm config get prefix` → npm 全局目录 +4. 从全局目录反推 `node_modules/@deepseek-ai/dsh/node_modules/@deepseek-ai` +5. 递归搜索兜底 当前 Desktop Harness 的 monorepo 安装结构还会从 `dsh-base` 的真实路径 反推出版本根,并兼容 `packages/interaction/user-approval` 与 diff --git a/lib/core.js b/lib/core.js index a0b8ceb..08c8875 100644 --- a/lib/core.js +++ b/lib/core.js @@ -64,6 +64,28 @@ export function findShimDir() { return null; } +/** + * 定位 DSH Desktop 解包后的 @deepseek-ai 依赖目录。 + * Electron 将 app.asar 中标记为 unpacked 的文件放在相邻目录,补丁应写入该真实路径。 + */ +function findDesktopAiBase() { + const candidates = []; + if (typeof process.resourcesPath === "string" && process.resourcesPath.trim()) { + candidates.push(path.join(process.resourcesPath, "app.asar.unpacked", "node_modules", "@deepseek-ai")); + } + + // ELECTRON_RUN_AS_NODE 模式没有稳定的 resourcesPath,按可执行文件位置回推 Contents/Resources。 + const contentsDir = path.dirname(path.dirname(process.execPath)); + candidates.push(path.join(contentsDir, "Resources", "app.asar.unpacked", "node_modules", "@deepseek-ai")); + + for (const candidate of candidates) { + if (fs.existsSync(path.join(candidate, "dsh-agent-instructions", "lib"))) { + return path.normalize(candidate); + } + } + return null; +} + export function findAiBase() { const env = process.env.DSH_BASE; if (env && env.trim()) { @@ -71,6 +93,9 @@ export function findAiBase() { if (fs.existsSync(path.join(p, "dsh-agent-instructions", "lib"))) return p; } + const desktopBase = findDesktopAiBase(); + if (desktopBase) return desktopBase; + const rel = path.join("node_modules", "@deepseek-ai", "dsh", "node_modules", "@deepseek-ai"); const prefix = findNpmPrefix();