DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
feat(env-isolation): implement isolation between development and production construction to avoid mutual pollution
hairyf8e30c2c4e505
diff --git a/AGENTS.md b/AGENTS.mdindex c87d4b8a..0695e65c 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -3,6 +3,7 @@DeepSeek Harness desktop (Tauri 2 + React 18), embeds the Harness UI served at `http://127.0.0.1:3080`.- **端口隔离**:release 默认 `3080`,debug(`pnpm tauri dev` / `cargo build`)默认 `3081`,由 `config::setting::default_port()` 用 `cfg!(debug_assertions)` 区分,避免开发时与已运行的桌面端争用端口。+- **数据隔离(核心共用、数据不共用)**:node/`dependencies/dsh`/`dependencies/pnpm` 为共用核心(AppData);debug 构建的 `$DSH_HOME` 默认为 `~/.dsh.dev`(`config::runtime::get_dsh_data_path` 用 `cfg!(debug_assertions)` 区分)且 store 用独立文件 `.store.dev.dat`(`config::setting::store_dat_file_name`),避免开发版与生产版会话/档案/端口状态互相污染,也防止 dev 版热重启把 release 的服务进程杀掉(`service/workflow::terminate_stale_harness_processes` 在 debug 下为 no-op,改由 `.dsh.dev/.harness.pid` 精确回收)。debug 构建不迁移旧数据(`service/migrate`)、不注册/注销 PATH、不写烘焙 DSH_HOME 的 `dsh` shim(`service/cli`)。- **Windows 极简模式**:预装插件流程(`service/plugin`)对 Windows 用户列出「修复」项(`dsh-win-terminal-inspector`,黄色 chip 默认勾选),确认后 `dsh plugin add github:clearkurt/dsh-win-terminal-inspector` 从 GitHub 安装(桌面端**不内置**插件源码);随后 `service/workflow/win_inspector.rs`(仅 Windows,幂等)写入 profile `cordis.patch.yml` 挂载行并创作 `$DSH_HOME/.agent-presets/minimal-win/` 用户 preset(Git Bash + danger-full-access,因为 agent preset 组成不受 profile patch 管辖)。- Prioritize using customized components from src/components, hero-ui.@@ -253,7 +254,7 @@ export function FooComponent(props: FooProps) {## Pitfalls- `dsh` CLI is a Node script (`dependencies/dsh/node_modules/@deepseek-ai/dsh/lib/bin.js`); CLI integration is **shim + PATH**. pnpm is also JS (`dependencies/pnpm/bin/pnpm.cjs`, npm tarball).-- AppData layout: `runtime/node.exe`, `dependencies/dsh/`, `dependencies/pnpm/`, `data/dsh` (DSH_HOME), `logs/dsh-web.log`.+- AppData layout(核心共用):`runtime/node.exe`、`dependencies/dsh/`、`dependencies/pnpm/`、`.store.dat` / `.store.dev.dat`(后者为 debug);服务日志 `logs/dsh-web.log`(debug 为 `logs/dsh-web.dev.log`);`$DSH_HOME` 在用户主目录(release `~/.dsh`,debug `~/.dsh.dev`)。- Service args: `node bin.js --profile web --host 127.0.0.1 --port <setting.port>`; `cli::ensure` runs after install.## Summarydiff --git a/src-tauri/src/bridge/cmd.rs b/src-tauri/src/bridge/cmd.rsindex 6a33dd8e..c3b5c6c4 100644--- a/src-tauri/src/bridge/cmd.rs+++ b/src-tauri/src/bridge/cmd.rs@@ -576,7 +576,8 @@ pub async fn clear_service_logs(app_handle: AppHandle) -> Result<(), String> {/// 读取运行日志(DSH 服务日志 + 桌面端 Rust 运行日志),格式化为便于/// 反馈/报障复制的纯文本块:`### 环境信息`、`### 服务日志` 与 `### 运行日志` 三段。///-/// 服务日志来自 `logs/dsh-web.log`,运行日志来自 `logs/desktop.log`+/// 服务日志来自 `logs/dsh-web.log`(debug 构建为 `logs/dsh-web.dev.log`),+/// 运行日志来自 `logs/desktop.log`/// (桌面端自身 `logger::init` 每次启动落盘,见 logger/mod.rs)。/// 每段取末尾最多 `MAX_LINES` 行,避免粘贴内容超出 GitHub issue 长度上限。#[tauri::command]diff --git a/src-tauri/src/config/constants.rs b/src-tauri/src/config/constants.rsindex 0f9aa894..cc82f63e 100644--- a/src-tauri/src/config/constants.rs+++ b/src-tauri/src/config/constants.rs@@ -40,6 +40,15 @@ pub const DSH_PORT: u16 = 3080;/// 争用同一个 3080 端口冲突。pub const DSH_DEV_PORT: u16 = 3081;+/// 官方 Harness 用户数据目录名:release 构建的 `$DSH_HOME` 默认目录(`~/.dsh`,+/// 与官方 node 安装保持一致)。+pub const DSH_HOME_DIR_NAME: &str = ".dsh";+/// 开发(debug)构建的用户数据目录名(`~/.dsh.dev`):与生产数据目录隔离。+/// 核心(node/`dependencies/dsh`/`dependencies/pnpm`)仍共用同一份安装,但+/// 会话、档案、插件与主题等数据各自独立——`pnpm tauri dev` 与已安装桌面端+/// 同时运行时互不干扰,也不会互相污染对方的会话数据。+pub const DSH_HOME_DEV_DIR_NAME: &str = ".dsh.dev";+/// 安装目录与 CLI 入口(相对安装目录)pub const DSH_CORE_DIR: &str = "dsh";pub const DSH_ENTRY_RELATIVE: &str = "node_modules/@deepseek-ai/dsh/lib/bin.js";@@ -55,6 +64,10 @@ pub const DSH_DATA_DIR_NAME: &str = "dsh";/// 简单 Store 持久化pub const STORE_DAT_FILE: &str = ".store.dat";+/// 开发(debug)构建的 Store 持久化文件名:与生产隔离,避免端口、installed、+/// active_core 等设置跨版本互写(生产默认 3080、开发默认 3081,共用一份+/// store 会让两边端口一路漂移并相互污染状态)。+pub const STORE_DAT_DEV_FILE: &str = ".store.dev.dat";pub const STORE_SETTING_KEY: &str = "setting";/// 健康检查超时diff --git a/src-tauri/src/config/runtime.rs b/src-tauri/src/config/runtime.rsindex 8df6c73b..972b74b0 100644--- a/src-tauri/src/config/runtime.rs+++ b/src-tauri/src/config/runtime.rs@@ -271,24 +271,39 @@ fn user_home_dir() -> Option<PathBuf> {/// Harness 用户数据目录($DSH_HOME)。////// 与官方 dsh(`${DSH_HOME:-$HOME/.dsh}`)保持一致:-/// - 环境变量 `DSH_HOME` 非空时优先使用;-/// - 否则默认 `~/.dsh`(Windows `%USERPROFILE%\.dsh`,Unix `$HOME/.dsh`)。-///-/// 桌面版与官方 node 安装共用同一份数据:两边数据互通、无需切换。+/// - 环境变量 `DSH_HOME` 非空时优先使用(用户显式指定优先于构建差异);+/// - 否则 release 构建默认 `~/.dsh`(Windows `%USERPROFILE%\.dsh`,Unix+/// `$HOME/.dsh`,与官方 node 安装共用同一份数据);+/// - debug 构建默认 `~/.dsh.dev`:开发版与生产版同时运行时,会话、档案、+/// 插件与主题等数据互不干扰,也不会互相污染对方的会话(核心目录+/// `dependencies/` 仍共用同一份安装)。pub fn get_dsh_data_path<R: Runtime>(_app_handle: &AppHandle<R>) -> PathBuf {if let Some(home) = std::env::var_os("DSH_HOME") {if !home.is_empty() {return PathBuf::from(home);}}+ let dir_name = if cfg!(debug_assertions) {+ DSH_HOME_DEV_DIR_NAME+ } else {+ DSH_HOME_DIR_NAME+ };user_home_dir()- .map(|home| home.join(".dsh"))- .unwrap_or_else(|| PathBuf::from(".dsh"))+ .map(|home| home.join(dir_name))+ .unwrap_or_else(|| PathBuf::from(dir_name))}/// dsh 服务日志文件路径-pub fn get_service_log_path(app_handle: &tauri::AppHandle) -> PathBuf {- get_base_dir(app_handle).join("logs").join("dsh-web.log")+///+/// debug 构建写入独立的 `dsh-web.dev.log`:开发版每次启动都会轮转日志,若与+/// 生产共用同一个文件,会把正在运行的生产版日志记录轮转覆盖掉。+pub fn get_service_log_path<R: Runtime>(app_handle: &AppHandle<R>) -> PathBuf {+ let name = if cfg!(debug_assertions) {+ "dsh-web.dev.log"+ } else {+ "dsh-web.log"+ };+ get_base_dir(app_handle).join("logs").join(name)}/// 捆绑的 Node.js 版本号@@ -371,24 +386,15 @@ pub struct RuntimeInfo {}pub fn runtime_info<R: Runtime>(app: &AppHandle<R>, port: u16) -> RuntimeInfo {- let app_data_dir = app- .path()- .app_data_dir()- .map(|p| p.to_string_lossy().into_owned())- .unwrap_or_default();-RuntimeInfo {app_version: app.package_info().version.to_string(),dsh_version: get_dsh_version(app),node_version: get_active_node_version(),service_url: get_dsh_service_url(port),- // 用户数据所在目录 = 官方 $DSH_HOME(~/.dsh),不再是 AppData+ // 用户数据所在目录 = $DSH_HOME(release 为官方 ~/.dsh,debug 为独立+ // ~/.dsh.dev,见 get_dsh_data_path),不再是 AppDatadata_dir: get_dsh_data_path(app).to_string_lossy().into_owned(),- log_path: PathBuf::from(&app_data_dir)- .join("logs")- .join("dsh-web.log")- .to_string_lossy()- .into_owned(),+ log_path: get_service_log_path(app).to_string_lossy().into_owned(),platform: env::consts::OS.to_string(),arch: env::consts::ARCH.to_string(),}diff --git a/src-tauri/src/config/setting.rs b/src-tauri/src/config/setting.rsindex 6b74ed95..97917003 100644--- a/src-tauri/src/config/setting.rs+++ b/src-tauri/src/config/setting.rs@@ -79,9 +79,23 @@ impl Default for Setting {}}+/// Store 持久化文件名:debug 构建与生产隔离(各自独立文件)。+///+/// store(端口、installed、active_core 等)属于「应用数据」而非共用核心——+/// 生产默认 3080、开发默认 3081,共用一份 store 会让两边端口一路漂移+/// (release 读到开发写入的 3081 后把 3080 让出,开发下次又从 3081 漂走)+/// 并相互污染安装/核心等状态。+fn store_dat_file_name() -> &'static str {+ if cfg!(debug_assertions) {+ STORE_DAT_DEV_FILE+ } else {+ STORE_DAT_FILE+ }+}+pub fn set_store_dat_setting(app_handle: &AppHandle, setting: Setting) {let store = app_handle- .store(STORE_DAT_FILE)+ .store(store_dat_file_name()).expect("Failed to load store");store.set(STORE_SETTING_KEY, serde_json::to_value(&setting).unwrap());store.save().expect("Failed to save store");@@ -92,7 +106,7 @@ pub fn set_store_dat_setting(app_handle: &AppHandle, setting: Setting) {pub fn get_store_dat_setting(app_handle: &AppHandle) -> Setting {let store = app_handle- .store(STORE_DAT_FILE)+ .store(store_dat_file_name()).expect("Failed to load store");let raw = store.get(STORE_SETTING_KEY);let value = raw.as_ref().and_then(|v| {diff --git a/src-tauri/src/service/cli/core.rs b/src-tauri/src/service/cli/core.rsindex 1c3ae425..7da18c3b 100644--- a/src-tauri/src/service/cli/core.rs+++ b/src-tauri/src/service/cli/core.rs@@ -52,6 +52,16 @@ pub fn ensure(app_handle: &AppHandle) -> Result<CliLinkStatus, String> {let bin_dir = get_bin_dir(app_handle);write_shims(app_handle, &bin_dir)?;+ // 开发(debug)构建不注册用户 PATH:bin 目录与 PATH 是共享的用户级状态,+ // 由生产版维护;开发版只写 shim(debug 下仅 pnpm shim,见 write_shims),+ // 既不增删 PATH 条目、也不覆盖生产的 dsh shim,避免干扰生产命令行集成。+ if cfg!(debug_assertions) {+ log::info!(+ "dsh/pnpm CLI shims ensured at {} (debug build: PATH registration skipped)",+ bin_dir.display()+ );+ return Ok(get_status(app_handle));+ }register_path(app_handle)?;log::info!("dsh/pnpm CLI links ensured at {}", bin_dir.display());@@ -71,6 +81,12 @@ pub fn ensure_shims(app_handle: &AppHandle) -> Result<(), String> {/// 禁用并清理命令行集成(删除 shim + 移除 PATH 注册)pub fn remove(app_handle: &AppHandle) -> Result<CliLinkStatus, String> {+ // 开发(debug)构建不删除 shim、不注销 PATH:这些是共享的用户级状态,+ // 由生产版维护——开发版执行清理会让正在运行的生产版命令行集成失效。+ if cfg!(debug_assertions) {+ log::info!("cli link removal skipped in debug build (shared user state kept)");+ return Ok(get_status(app_handle));+ }let bin_dir = get_bin_dir(app_handle);#[cfg(windows)]diff --git a/src-tauri/src/service/cli/shim.rs b/src-tauri/src/service/cli/shim.rsindex 4377b4bd..05182312 100644--- a/src-tauri/src/service/cli/shim.rs+++ b/src-tauri/src/service/cli/shim.rs@@ -112,9 +112,9 @@ fi// shim 目录)的用户 dsh,转发时不注入本应用的 DSH_HOME,保留用户环境;// 仅找不到用户 dsh 时才回退到捆绑 dsh。// 变量约定:cmd 用 %SELF_PREFIX%/%USER_DSH%,ps1 用 $selfDir/$userDsh,-// sh 用 $SELF_DIR。-// ----------------------------------------------------------------------------+// sh 用 $SELF_DIR。dsh shim 仅 release 构建写入(debug 构建不覆盖共享的+// dsh shim,见 write_shims),debug 下这些常量/函数未使用,允许 dead_code。+#[cfg_attr(debug_assertions, allow(dead_code))]const CMD_USER_DSH_PRECEDENCE: &str = r#"rem Prefer a user-installed dsh on PATH (skip our own shim dir), fall back to bundled.rem This preserves your own dsh binary and its $DSH_HOME config; nothing is overwritten.@@ -142,6 +142,7 @@ if defined USER_DSH ()"#;+#[cfg_attr(debug_assertions, allow(dead_code))]const PS1_USER_DSH_PRECEDENCE: &str = r#"# Prefer a user-installed dsh on PATH (skip our own shim dir), fall back to bundled.# This preserves your own dsh binary and its $env:DSH_HOME config; nothing is overwritten.@@ -156,6 +157,7 @@ if ($userDsh) {"#;#[cfg_attr(windows, allow(dead_code))] // 仅 Unix shim 使用+#[cfg_attr(debug_assertions, allow(dead_code))]const SH_USER_DSH_PRECEDENCE: &str = r#"# Prefer a user-installed dsh on PATH (skip our own shim dir), fall back to bundled.# This preserves your own dsh binary and its $DSH_HOME config; nothing is overwritten.@@ -199,7 +201,9 @@ pub fn escape_path_sh(path: &Path) -> String {// ---------------------------------------------------------------------------/// Windows `dsh.cmd` 内容。`app_dir` 为应用数据目录(绝对路径,生成时写死),-/// `dsh_home` 为官方 `$DSH_HOME`(`~/.dsh`,生成时写死,与桌面端/官方一致)。+/// `dsh_home` 为官方 `$DSH_HOME`(release 为 `~/.dsh`,生成时写死,与桌面端/+/// 官方一致)。+#[cfg_attr(debug_assertions, allow(dead_code))] // 仅 release 构建写入 dsh shimpub fn build_cmd_shim(app_dir: &Path, dsh_home: &Path) -> String {let dsh_bin = app_dir.join("dependencies/dsh/node_modules/@deepseek-ai/dsh/lib/bin.js");@@ -236,6 +240,7 @@ exit /b 1}/// Windows `dsh.ps1` 内容+#[cfg_attr(debug_assertions, allow(dead_code))] // 仅 release 构建写入 dsh shimpub fn build_ps1_shim(app_dir: &Path, dsh_home: &Path) -> String {let dsh_bin = app_dir.join("dependencies/dsh/node_modules/@deepseek-ai/dsh/lib/bin.js");@@ -267,6 +272,7 @@ exit $LASTEXITCODE/// Unix `dsh` shell 脚本内容(POSIX sh)#[cfg(not(windows))]+#[cfg_attr(debug_assertions, allow(dead_code))] // 仅 release 构建写入 dsh shimpub fn build_sh_shim(app_dir: &Path, dsh_home: &Path) -> String {let dsh_bin = app_dir.join("dependencies/dsh/node_modules/@deepseek-ai/dsh/lib/bin.js");@@ -500,7 +506,6 @@ pub fn user_dsh_preserved(bin_dir: &Path) -> bool {/// 同名 `dsh`/`pnpm` 一律保留不动,避免覆盖用户自己的安装与配置。pub fn write_shims(app_handle: &AppHandle, bin_dir: &Path) -> Result<(), String> {let app_dir = config::get_base_dir(app_handle);- let dsh_home = config::get_dsh_data_path(app_handle);fs::create_dir_all(bin_dir).map_err(|e| format!("create bin dir failed: {e}"))?;// 写入单个 shim:若目标已存在且非本应用生成,则跳过不覆盖(保留用户文件)。@@ -520,19 +525,43 @@ pub fn write_shims(app_handle: &AppHandle, bin_dir: &Path) -> Result<(), String>}};}+ // dsh shim 会在内容里烘焙 $DSH_HOME(生产为 ~/.dsh、开发为 ~/.dsh.dev)。+ // 开发构建禁止改写用户共享的 dsh shim——改写会让终端 `dsh` 指向开发数据+ // 目录,并覆盖生产的命令行集成;生产版生成的 dsh shim 原样保留。+ #[cfg(not(debug_assertions))]+ {+ let dsh_home = config::get_dsh_data_path(app_handle);+ #[cfg(windows)]+ {+ write_if_ours!(SHIM_CMD_NAME, build_cmd_shim(&app_dir, &dsh_home));+ write_if_ours!(SHIM_PS1_NAME, build_ps1_shim(&app_dir, &dsh_home));+ }+ #[cfg(not(windows))]+ {+ write_if_ours!(SHIM_SH_NAME, build_sh_shim(&app_dir, &dsh_home));+ }+ }+ #[cfg(debug_assertions)]+ log::debug!("debug build: skip dsh shim write (shared user state kept for release)");++ // pnpm shim 不烘焙 $DSH_HOME(仅绑定 bundle 目录与“用户 pnpm 优先”逻辑),+ // 内容与生产完全一致,开发构建也可写入——dsh plugin 子进程经 PATH 解析+ // pnpm 依赖它,写它不污染任何共享数据。#[cfg(windows)]{- write_if_ours!(SHIM_CMD_NAME, build_cmd_shim(&app_dir, &dsh_home));- write_if_ours!(SHIM_PS1_NAME, build_ps1_shim(&app_dir, &dsh_home));write_if_ours!(PNPM_SHIM_CMD_NAME, build_pnpm_cmd_shim(&app_dir));write_if_ours!(PNPM_SHIM_PS1_NAME, build_pnpm_ps1_shim(&app_dir));}#[cfg(not(windows))]{- write_if_ours!(SHIM_SH_NAME, build_sh_shim(&app_dir, &dsh_home));write_if_ours!(PNPM_SHIM_SH_NAME, build_pnpm_sh_shim(&app_dir));// 仅对本应用生成/覆盖过的 shim 设置可执行位;保留的用户文件不动- for name in [SHIM_SH_NAME, PNPM_SHIM_SH_NAME] {+ let chmod_names: &[&str] = if cfg!(debug_assertions) {+ &[PNPM_SHIM_SH_NAME]+ } else {+ &[SHIM_SH_NAME, PNPM_SHIM_SH_NAME]+ };+ for name in chmod_names {let path = bin_dir.join(name);if path.is_file() && !is_foreign_file(&path) {use std::os::unix::fs::PermissionsExt;diff --git a/src-tauri/src/service/migrate.rs b/src-tauri/src/service/migrate.rsindex 5b8dfbef..ebf1d69e 100644--- a/src-tauri/src/service/migrate.rs+++ b/src-tauri/src/service/migrate.rs@@ -30,6 +30,14 @@ fn legacy_dsh_home(app_handle: &AppHandle) -> PathBuf {/// 幂等:成功后会删除旧目录并置位 `.store.dat` 标记,重复调用为 no-op。/// 失败返回 Err(不删除旧数据),由调用方决定是否阻断——本应用选择仅告警。pub fn migrate(app_handle: &AppHandle) -> Result<(), String> {+ // 开发(debug)构建不执行旧数据迁移:旧版 AppData `data/dsh` 是生产的+ // 数据(release 尚未完成迁移时会把它整目录搬进开发版的 `.dsh.dev`,+ // 导致 release 丢失数据)。开发构建的数据目录从一开始就是独立的 `.dsh.dev`。+ if cfg!(debug_assertions) {+ log::debug!("skipping legacy data migration in debug build (data belongs to release)");+ return Ok(());+ }+let setting = config::get_store_dat_setting(app_handle);if setting.dsh_home_migrated {log::debug!("dsh home migration already done, skipping");diff --git a/src-tauri/src/service/workflow/mod.rs b/src-tauri/src/service/workflow/mod.rsindex b9771406..33a2451e 100644--- a/src-tauri/src/service/workflow/mod.rs+++ b/src-tauri/src/service/workflow/mod.rs@@ -159,6 +159,15 @@ pub fn has_owned_process() -> bool {/// 的 node 进程可判定为本应用的服务实例——路径精确匹配不会误杀用户其它 node/// 程序,因此可安全地全部结束(taskkill /T /F)。pub fn terminate_stale_harness_processes(app_handle: &tauri::AppHandle) {+ // 开发(debug)构建不做按路径清扫:生产与开发共用同一个 `dependencies/dsh`+ // 安装目录(核心共用),按命令行路径匹配会把同时运行的 release 服务进程+ // 一并结束——`pnpm tauri dev` 每次后端重编译都会重启应用并触发清扫,导致+ // "release 版 DSH 被 dev 版热更新杀掉"。开发构建自身的崩溃残留仍由+ // `.harness.pid` 标记(位于独立数据目录 `.dsh.dev`,PID+端口双重确认)+ // 精确回收。+ if cfg!(debug_assertions) {+ return;+ }#[cfg(windows)]{use std::os::windows::process::CommandExt;