Skip to content

DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.

fix(desktop): 本地核心下插件子进程改用其包目录作为 cwd (#1003)

Mao Mrc36c2a85dc2b
diff --git a/src-tauri/src/service/core/mod.rs b/src-tauri/src/service/core/mod.rs
index 8c6ae95b..1a65b771 100644
--- a/src-tauri/src/service/core/mod.rs
+++ b/src-tauri/src/service/core/mod.rs
@@ -29,7 +29,9 @@ mod version;
pub use local::{local_core_package_dir, update_local_core};
// 以下重导出为对外公开 API(部分项当前链路未直接引用,属有意保留,见模块头)。
#[allow(unused_imports)]
-pub use source::{active_dsh_binary, active_source, active_version, CoreSource, HarnessCore};
+pub use source::{
+ active_core_dir, active_dsh_binary, active_source, active_version, CoreSource, HarnessCore,
+};
pub use version::{download_version, has_installed_version, list, remove_version, set_active};
pub(crate) use runtime::prepare_active_runtime;
// 目录链接实现(Windows 符号链接 → 无特权时的 junction 回退)供插件模块复用:
diff --git a/src-tauri/src/service/core/source.rs b/src-tauri/src/service/core/source.rs
index db1d8cc2..3c1dc727 100644
--- a/src-tauri/src/service/core/source.rs
+++ b/src-tauri/src/service/core/source.rs
@@ -1,8 +1,8 @@
//! 核心来源判定与「当前活动核心」入口选择。
//!
//! 承载 [`CoreSource`] / [`HarnessCore`] 两个公开类型,以及
-//! [`active_source`] / [`active_dsh_binary`] / [`active_version`] 三个供服务启动
-//! 与插件操作统一取用的入口。本地核心探测见 [`super::local`]。
+//! [`active_source`] / [`active_dsh_binary`] / [`active_core_dir`] / [`active_version`]
+//! 四个供服务启动与插件操作统一取用的入口。本地核心探测见 [`super::local`]。
use crate::config;
use serde::Serialize;
@@ -10,7 +10,7 @@ use std::path::PathBuf;
use std::sync::OnceLock;
use tauri::AppHandle;
-use super::local::local_core;
+use super::local::{local_core, local_core_package_dir};
use crate::service::download::parse_version_from_tag;
/// 核心来源
@@ -165,6 +165,22 @@ pub fn active_dsh_binary(app_handle: &AppHandle) -> PathBuf {
}
}
+/// 当前活动核心的安装目录:本地核心用其包目录(全局安装路径),预打包用桌面端目录。
+///
+/// 该目录同时是核心与 `dsh plugin` 子进程的 cwd(`CreateProcessW` 的 lpCurrentDirectory
+/// 必须真实存在),也是本地 spec 绝对化的基准。本地核心生效时桌面端依赖根不会被创建
+/// (`runtime::prepare_active_runtime` 跳过),误用依赖根会让核心启动卡在插件安装阶段:
+/// `PREINSTALL_SPAWN: 目录名称无效。 (os error 267)`。
+///
+/// 与 [`active_dsh_binary`] 的取舍一致——本地核心解析在调用瞬间失效时回退预打包目录。
+pub fn active_core_dir(app_handle: &AppHandle) -> PathBuf {
+ match active_source(app_handle) {
+ CoreSource::Local => local_core_package_dir(app_handle)
+ .unwrap_or_else(|| config::get_dsh_install_path(app_handle)),
+ CoreSource::App => config::get_dsh_install_path(app_handle),
+ }
+}
+
/// 当前生效的核心是否就是随安装包分发的那份(离线包把内核托管到 `$Resources/dsh`)。
///
/// 判定「来源是 App **且** 生效根就是随包内核目录」:切到本地核心时映射被记为系统环境、
diff --git a/src-tauri/src/service/plugin/install/inspect.rs b/src-tauri/src/service/plugin/install/inspect.rs
index 00133379..dd7b0501 100644
--- a/src-tauri/src/service/plugin/install/inspect.rs
+++ b/src-tauri/src/service/plugin/install/inspect.rs
@@ -36,7 +36,7 @@ pub async fn inspect_specs(
.map_err(|e| format!("INSPECT_CLIENT: {e}"))?;
// 与安装同源:本地 spec 的相对路径按 `dsh plugin add` 子进程的 cwd 解析。
- let base = crate::config::get_dsh_install_path(app_handle);
+ let base = crate::service::core::active_core_dir(app_handle);
let mut results = Vec::with_capacity(specs.len());
for raw in specs {
results.push(inspect_one(&client, raw, &base, runtime.as_deref()).await);
diff --git a/src-tauri/src/service/plugin/install/mod.rs b/src-tauri/src/service/plugin/install/mod.rs
index 7fd2825f..afac776c 100644
--- a/src-tauri/src/service/plugin/install/mod.rs
+++ b/src-tauri/src/service/plugin/install/mod.rs
@@ -231,10 +231,10 @@ fn preset_targets(app_handle: &AppHandle, ids: &[String]) -> Result<Vec<InstallT
fn spec_targets(app_handle: &AppHandle, specs: &[String]) -> Result<Vec<InstallTarget>, String> {
let core_version = crate::service::core::active_version(app_handle);
let presets = load_presets(app_handle);
- // 相对路径的基准:`dsh plugin` 不切换 cwd,pnpm 在 `$AppData/dependencies/dsh`
- // 下执行(与 [`install_with_cancel`] 传入的 cwd 同源),故本地 spec 必须在这里
- // 先绝对化,用户输入的 `./plugins/x` 才不会被解析到应用安装目录里。
- let base = config::get_dsh_install_path(app_handle);
+ // 相对路径的基准:`dsh plugin` 不切换 cwd,pnpm 在活动核心目录下执行(与
+ // [`install_with_cancel`] 传入的 cwd 同源),故本地 spec 必须在这里先绝对化,
+ // 用户输入的 `./plugins/x` 才不会被解析到应用安装目录里。
+ let base = crate::service::core::active_core_dir(app_handle);
let mut targets = Vec::with_capacity(specs.len());
for spec in specs {
let spec = spec.trim();
@@ -424,7 +424,7 @@ async fn install_with_cancel(
];
args.extend(specs.iter().map(OsString::from));
- let cwd = config::get_dsh_install_path(app_handle);
+ let cwd = crate::service::core::active_core_dir(app_handle);
// 日志打印实际传给 dsh 的 spec(此前打印 id 会误导排查:安装用的是 spec)
log::info!("Running dsh plugin install for {specs:?}");
@@ -656,7 +656,7 @@ pub async fn allow_version_exemptions(
}
let envs = build_plugin_envs(app_handle, harness_prefer_bundled_pnpm(app_handle));
- let cwd = config::get_dsh_install_path(app_handle);
+ let cwd = crate::service::core::active_core_dir(app_handle);
let profile = active_profile(app_handle);
let owner = new_process_owner();
let mut failures: Vec<String> = Vec::new();
diff --git a/src-tauri/src/service/plugin/install/single.rs b/src-tauri/src/service/plugin/install/single.rs
index dc8bd8ea..3ac9d1e4 100644
--- a/src-tauri/src/service/plugin/install/single.rs
+++ b/src-tauri/src/service/plugin/install/single.rs
@@ -787,7 +787,7 @@ async fn run_plugin_command(
sub_args,
));
- let cwd = config::get_dsh_install_path(app_handle);
+ let cwd = crate::service::core::active_core_dir(app_handle);
log::info!("Running dsh plugin {action} for {ids:?}");
let (exit_code, output, last_attempt) = run_plugin_with_allow_build_retry(
app_handle, &node, &args, &cwd, &envs, &window, action, None, owner,
diff --git a/src-tauri/src/service/workflow/launch.rs b/src-tauri/src/service/workflow/launch.rs
index 04a8a021..988b651f 100644
--- a/src-tauri/src/service/workflow/launch.rs
+++ b/src-tauri/src/service/workflow/launch.rs
@@ -712,16 +712,7 @@ pub async fn launch(app_handle: tauri::AppHandle) -> Result<(), String> {
// node 会让 dsh 派生的子进程各自新建可见控制台窗口(频繁闪烁 cmd 黑窗),
// 因此 Windows 上改用“隐藏控制台”方式启动,见 win_spawn 模块。
let active_profile = crate::service::profile::active_profile(&app_handle);
- let app_core_dir = config::get_dsh_install_path(&app_handle);
- let core_dir = if dsh_binary_path == config::get_dsh_binary_path(&app_handle) {
- app_core_dir
- } else {
- dsh_binary_path
- .parent()
- .and_then(std::path::Path::parent)
- .map(std::path::Path::to_path_buf)
- .unwrap_or(app_core_dir)
- };
+ let core_dir = crate::service::core::active_core_dir(&app_handle);
mark_phase("pre_spawn_setup", &mut phase_started);
super::startup::note_spawn();
let spawn_result: SpawnResult = {
diff --git a/src-tauri/src/utils/mod.rs b/src-tauri/src/utils/mod.rs
index 14152989..9e6dfd99 100644
--- a/src-tauri/src/utils/mod.rs
+++ b/src-tauri/src/utils/mod.rs
@@ -3,7 +3,7 @@ use std::path::{Path, PathBuf};
use tauri::{AppHandle, Manager, Runtime, WebviewWindow};
use crate::config;
-use crate::service::core::{active_source, local_core_package_dir, CoreSource};
+use crate::service::core::active_core_dir;
/// 对某个 dsh 包文件的一次性幂等补丁判定结果。
#[derive(Debug, PartialEq, Eq)]
@@ -16,18 +16,6 @@ pub enum PatchOutcome {
Patched(String),
}
-/// 活动核心安装目录:本地核心用其包目录(全局安装路径),预打包用桌面端目录。
-///
-/// 与 [`crate::service::core::active_dsh_binary`] 的取舍一致——本地核心解析在调用
-/// 瞬间失效时回退预打包目录,绝不让补丁打到永不加载的预打包文件上。
-fn active_core_install_dir(app_handle: &tauri::AppHandle) -> PathBuf {
- match active_source(app_handle) {
- CoreSource::Local => local_core_package_dir(app_handle)
- .unwrap_or_else(|| config::get_dsh_install_path(app_handle)),
- CoreSource::App => config::get_dsh_install_path(app_handle),
- }
-}
-
/// 对活动核心安装目录下的某个 dsh 包文件应用一次性幂等补丁。
///
/// - `rel_path`:相对活动核心安装目录的包内路径,例如
@@ -37,13 +25,13 @@ fn active_core_install_dir(app_handle: &tauri::AppHandle) -> PathBuf {
///
/// 统一处理「定位文件 → 读取 → 打补丁 → 写回」与对应的日志。文件缺失、已打过、
/// 锚点变更均静默跳过并返回 Ok;只有真实读/写失败才返回 Err(不阻断启动的调用方
-/// 据此仅告警)。活动核心的判定与 [`active_core_install_dir`] 一致。
+/// 据此仅告警)。活动核心的判定与 [`active_core_dir`] 一致。
pub fn patch_dsh(
app_handle: &tauri::AppHandle,
rel_path: &str,
patch: impl FnOnce(&str) -> PatchOutcome,
) -> Result<(), String> {
- patch_core_file(&active_core_install_dir(app_handle), rel_path, patch)
+ patch_core_file(&active_core_dir(app_handle), rel_path, patch)
}
/// [`patch_dsh`] 的目录版本:对显式给定的核心安装目录施加同一个补丁。