From 4d47ce69dc77e3c88beabdd0783e6c7dc6fa5251 Mon Sep 17 00:00:00 2001 From: wangqiupei <154594742@qq.com> Date: Tue, 25 Aug 2026 09:43:23 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=94=AF=E6=8C=81=20DSH=20Desktop=20?= =?UTF-8?q?=E8=A7=A3=E5=8C=85=E4=BE=9D=E8=B5=96=E8=B7=AF=E5=BE=84=E6=8E=A2?= =?UTF-8?q?=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 7 ++++--- README.zh-CN.md | 7 ++++--- lib/core.js | 25 +++++++++++++++++++++++++ package.json | 3 +++ 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 906eca2..7147b32 100644 --- a/README.md +++ b/README.md @@ -211,9 +211,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. 递归搜索兜底 探测失败提示设置 `DSH_BASE`,不清除、不误伤。 diff --git a/README.zh-CN.md b/README.zh-CN.md index 77c04a1..f272ce7 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -206,9 +206,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. 递归搜索兜底 探测失败提示设置 `DSH_BASE`,不清除、不误伤。 diff --git a/lib/core.js b/lib/core.js index 91fbb51..80da83d 100644 --- a/lib/core.js +++ b/lib/core.js @@ -61,6 +61,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()) { @@ -68,6 +90,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(); diff --git a/package.json b/package.json index 7edaaef..d4da83b 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,9 @@ "bin": { "dsh-purge": "bin/dsh-purge.js" }, + "scripts": { + "test": "node --test" + }, "files": [ "lib", "bin",