Skip to content

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

refactor(patch): 删除已失效的 client-HMR 降级补丁

hairyf7c091d6cee77
diff --git a/src-tauri/src/service/patch/client_hmr.rs b/src-tauri/src/service/patch/client_hmr.rs
deleted file mode 100644
index 12c836f2..00000000
--- a/src-tauri/src/service/patch/client_hmr.rs
+++ /dev/null
@@ -1,104 +0,0 @@
-//! Debug 客户端插件重载兼容补丁。
-//!
-//! 当前内置 DSH `0.1.1-rc.2` 的 client-HMR 在收到 `rebuilt` 后会卸载旧插件,
-//! 但第三方插件的 Loader 条目不会重新挂载,表现为构建后插件消失、手动刷新才恢复。
-//! debug 桌面端本来就直接联接本地插件源码,因此将该坏 hot-swap 降级为页面自动刷新:
-//! 仍由 `/plugins/events` 精确触发,不轮询页面,也不会影响 release。
-
-use std::path::Path;
-
-use crate::utils::{patch_core_file, patch_dsh, PatchOutcome};
-
-// HARDCODE:以下锚点绑定内置 DSH 0.1.1-rc.2 的 client-HMR bundle;仅 debug 生效。
-const PATCH_MARKER: &str = "dsh-tauri-desktop: debug client plugin reload fallback";
-const ORIGINAL: &str = r#"case "rebuilt":
- queue = queue.then(() => reload(frame.id)).catch((error) => {
- ctx.logger.error(`client-hmr: reload of "${frame.id}" failed`);
- ctx.logger.error(error);
- });
- break;"#;
-const PATCHED: &str = r#"case "rebuilt":
- /* dsh-tauri-desktop: debug client plugin reload fallback */
- window.location.reload();
- break;"#;
-// 上游已恢复完整的 invalidate → refresh 流程时,无需桌面端降级补丁。
-// alpha 的压缩/格式化可能改变缩进,因此下面两个语句分别作为稳定锚点。
-const UPSTREAM_INVALIDATE: &str = "modLoader.invalidate(id, rev);";
-const UPSTREAM_PREFETCH: &str = "await modLoader.prefetch(id);";
-
-/// 相对活动核心安装目录的 client-hmr `lib/client.js` 包内路径。
-const CLIENT_HMR_CLIENT_JS: &str = "node_modules/@deepseek-ai/dsh-client-hmr/lib/client.js";
-
-fn patch_source(source: &str) -> PatchOutcome {
- if source.contains(PATCH_MARKER) {
- return PatchOutcome::AlreadyPatched;
- }
- if source.contains(UPSTREAM_INVALIDATE) && source.contains(UPSTREAM_PREFETCH) {
- return PatchOutcome::AlreadyPatched;
- }
- if !source.contains(ORIGINAL) {
- return PatchOutcome::AnchorMissing;
- }
- PatchOutcome::Patched(source.replacen(ORIGINAL, PATCHED, 1))
-}
-
-/// debug 启动前把损坏的插件 hot-swap 降级为自动页面刷新。
-#[cfg(debug_assertions)]
-pub fn apply(app_handle: &tauri::AppHandle) -> Result<(), String> {
- patch_dsh(app_handle, CLIENT_HMR_CLIENT_JS, patch_source)
-}
-
-/// release 不修改客户端重载行为。
-#[cfg(not(debug_assertions))]
-pub fn apply(_app_handle: &tauri::AppHandle) -> Result<(), String> {
- Ok(())
-}
-
-/// 对显式给定的核心安装目录施加本补丁(E2E 编排复用,无需运行中的桌面端)。
-#[cfg(debug_assertions)]
-pub fn apply_at(core_dir: &Path) -> Result<(), String> {
- patch_core_file(core_dir, CLIENT_HMR_CLIENT_JS, patch_source)
-}
-
-/// release 不修改客户端重载行为。
-#[cfg(not(debug_assertions))]
-pub fn apply_at(_core_dir: &Path) -> Result<(), String> {
- Ok(())
-}
-
-#[cfg(test)]
-mod tests {
- use super::*;
-
- #[test]
- fn replaces_broken_hot_swap_with_page_reload() {
- let PatchOutcome::Patched(patched) = patch_source(ORIGINAL) else {
- panic!("expected patched source");
- };
- assert!(patched.contains(PATCH_MARKER));
- assert!(patched.contains("window.location.reload();"));
- assert!(!patched.contains("queue = queue.then"));
- }
-
- #[test]
- fn patch_is_idempotent() {
- let PatchOutcome::Patched(patched) = patch_source(ORIGINAL) else {
- panic!("expected patched source");
- };
- assert_eq!(patch_source(&patched), PatchOutcome::AlreadyPatched);
- }
-
- #[test]
- fn skips_unknown_upstream_layout() {
- assert_eq!(
- patch_source("case \"rebuilt\": break;"),
- PatchOutcome::AnchorMissing
- );
- }
-
- #[test]
- fn accepts_upstream_fixed_reload_flow() {
- let source = format!("{UPSTREAM_INVALIDATE} {UPSTREAM_PREFETCH}");
- assert_eq!(patch_source(&source), PatchOutcome::AlreadyPatched);
- }
-}
diff --git a/src-tauri/src/service/patch/mod.rs b/src-tauri/src/service/patch/mod.rs
index 8769b061..0fc09949 100644
--- a/src-tauri/src/service/patch/mod.rs
+++ b/src-tauri/src/service/patch/mod.rs
@@ -6,9 +6,8 @@
//! 统一处理,避免每个补丁重复这份样板。
//!
//! 命名约定:子模块名不带 `_patch` 后缀(`renderer` / `session` / `workspace` /
-//! `client_hmr`),挂点统一为 `service::workflow::launch`,均为最佳努力、失败仅告警。
+//! `workspace_view`),挂点统一为 `service::workflow::launch`,均为最佳努力、失败仅告警。
-pub(crate) mod client_hmr;
pub(crate) mod composer;
pub(crate) mod llm_session;
pub(crate) mod model_selection;
@@ -28,7 +27,7 @@ use std::path::Path;
/// 单个补丁失败不阻断其余:与启动路径一样是「最佳努力」,但这里把错误汇总返回,
/// 让编排层能看见哪一条出了问题。
pub(crate) fn apply_all_at(core_dir: &Path) -> Result<(), String> {
- let patches: [(&str, fn(&Path) -> Result<(), String>); 8] = [
+ let patches: [(&str, fn(&Path) -> Result<(), String>); 7] = [
("renderer", renderer::apply_at),
("composer", composer::apply_at),
("session", session::apply_at),
@@ -36,7 +35,6 @@ pub(crate) fn apply_all_at(core_dir: &Path) -> Result<(), String> {
("model_selection", model_selection::apply_at),
("workspace", workspace::apply_at),
("workspace_view", workspace_view::apply_at),
- ("client_hmr", client_hmr::apply_at),
];
let mut failures = Vec::new();
for (name, apply) in patches {
diff --git a/src-tauri/src/service/workflow/launch.rs b/src-tauri/src/service/workflow/launch.rs
index 5ef20c76..39e3c458 100644
--- a/src-tauri/src/service/workflow/launch.rs
+++ b/src-tauri/src/service/workflow/launch.rs
@@ -456,11 +456,6 @@ pub async fn launch(app_handle: tauri::AppHandle) -> Result<(), String> {
if let Err(e) = crate::service::patch::workspace_view::apply(&app_handle) {
log::warn!("workspace view state patch failed: {e}");
}
- // 当前 DSH client-HMR 会卸载第三方插件却不重新挂载。debug 直接联接本地
- // 插件源码,故将 rebuilt 降级为自动刷新页面;release 保持上游行为。
- if let Err(e) = crate::service::patch::client_hmr::apply(&app_handle) {
- log::warn!("debug client plugin reload fallback patch failed: {e}");
- }
// 预防性处理:pnpm 在无 TTY 环境(dsh-market 等子进程)下重装/更新插件时,
// 清理/重建 node_modules 会触发交互确认并因无 TTY 直接中止
// (ERR_PNPM_ABORTED_REMOVE_MODULES_DIR_NO_TTY),表现为插件更新失败。