DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
fix(plugin): uninstall orphaned internal plugins whose link dir vanished (#321)
Mao Mr3fa3e4284c1a
diff --git a/src-tauri/src/service/plugin/internal/manifest.rs b/src-tauri/src/service/plugin/internal/manifest.rsindex 53d929c7..2cc00c7e 100644--- a/src-tauri/src/service/plugin/internal/manifest.rs+++ b/src-tauri/src/service/plugin/internal/manifest.rs@@ -189,6 +189,17 @@ pub(super) fn remove_stale_plugin_entry(entry: &Path) -> std::io::Result<()> {std::fs::remove_file(entry)}+/// 判断某依赖值是否为「本地目录链接」形式(`link:` / `file:`)。+///+/// 内置插件统一以 `link:<捆绑目录绝对路径>` 安装;`file:` 是协议切换前的历史遗留+/// 同义形式。用于启动自愈:当捆绑目录已不存在(如 debug 下切换 git 分支、某内置+/// 插件源码目录消失)时,只有 `link:`/`file:` 依赖才意味着「这是我们装的本地链接」,+/// 可以把悬空引用卸载;registry/git 引用(如 `[email protected]`、`github:x/y`)是用户+/// 独立安装,绝不能误卸。路径值不做存在性判断,只判前缀。+pub(super) fn is_local_link_dep(spec: &str) -> bool {+ spec.starts_with("link:") || spec.starts_with("file:")+}+/// 判断 pnpm 写入 profile 的依赖值与期望的 `link:` 捆绑路径是否一致。////// 容忍:`link:`/`file:` 前缀缺失或两者混写(历史遗留 `file:` 安装值);Windows@@ -375,6 +386,18 @@ mod tests {let _ = std::fs::remove_dir_all(root);}+ #[test]+ fn local_link_dep_detects_only_directory_specs() {+ // link:/file: 前缀 → 本地目录链接(含历史遗留 file: 形式)+ assert!(is_local_link_dep("link:C:/Apps/dsh/resources/internal-plugins/dsh-tauri"));+ assert!(is_local_link_dep("file:/Applications/.../dsh-tauri-ui"));+ // 无前缀的裸路径、registry 版本、git 引用都不是本地链接,绝不能误卸+ assert!(!is_local_link_dep("[email protected]"));+ assert!(!is_local_link_dep("github:dsh-market/dshmarket"));+ assert!(!is_local_link_dep("workspace:*"));+ assert!(!is_local_link_dep(""));+ }+#[test]fn dep_spec_matches_itself() {let expected = "link:C:/Apps/dsh/resources/internal-plugins/dsh-tauri";diff --git a/src-tauri/src/service/plugin/internal/mod.rs b/src-tauri/src/service/plugin/internal/mod.rsindex 0fa315ee..79599e86 100644--- a/src-tauri/src/service/plugin/internal/mod.rs+++ b/src-tauri/src/service/plugin/internal/mod.rs@@ -26,7 +26,7 @@ use super::process::{new_process_owner, ProcessOwner};use crate::config;use manifest::{- dedupe_profile_bundles, dep_matches_spec, internal_plugin_entry_is_ready,+ dedupe_profile_bundles, dep_matches_spec, internal_plugin_entry_is_ready, is_local_link_dep,remove_duplicate_bundle_entries_from_patch, remove_internal_plugins_from_manifest,remove_stale_plugin_entry, write_profile_manifest,};@@ -528,15 +528,36 @@ async fn ensure_inner(}let mut need: Vec<(String, String, PathBuf)> = Vec::new();+ // 本分支要「直接卸载」的孤儿内置插件(安装包名):其捆绑目录已不存在且仍以+ // `link:`/`file:` 本地依赖形式安装在 profile 里。见下方 bundle 缺失分支的说明。+ let mut orphans: Vec<String> = Vec::new();for preset in internal {let Some(bundled) = bundled_plugin_dir(app_handle, &preset.id) else {// 未找到内置插件目录:release 说明构建期 build:plugins 未打包(发布// 缺陷,由 build:plugins 响亮失败);debug 自动发现 packages/* 中非私有// 且含 dsh 对象的包,未命中时跳过(「找不到则不装」)。- log::warn!(- "INTERNAL_PLUGIN_BUNDLE_MISSING: {}(release 需构建期 build:plugins;debug 无匹配的 packages/* 包)",- preset.id- );+ //+ // debug 下这是「切换 git 分支导致某内置插件源码消失」的典型场景:上一+ // 分支把它以 `link:<packages/<id>>` 装进 profile,当前分支不再有该目录,+ // 悬空链接指向不存在的源。此时重装无从谈起(无源),且残留悬空链接会让+ // loader 无法解析。因此只要它仍以本地链接(`link:`/`file:`)形式安装在+ // profile 里,就直接卸载该插件;registry/git 等非本地依赖(用户独立安装+ // 的同名包)绝不误卸。+ let name = installed_name(preset).to_string();+ let is_orphan = dependencies+ .get(&name)+ .is_some_and(|spec| is_local_link_dep(spec));+ if is_orphan {+ log::warn!(+ "INTERNAL_PLUGIN_BUNDLE_MISSING_UNINSTALLING: {name}(link 指向的捆绑目录已不存在,卸载悬空内置插件)"+ );+ orphans.push(name);+ } else {+ log::warn!(+ "INTERNAL_PLUGIN_BUNDLE_MISSING: {}(release 需构建期 build:plugins;debug 无匹配的 packages/* 包)",+ preset.id+ );+ }continue;};let name = installed_name(preset).to_string();@@ -560,6 +581,23 @@ async fn ensure_inner(need.push((preset.id.clone(), name, entry));}}+ // 卸载孤儿内置插件:best-effort、离线精准,不依赖 node/pnpm(其源目录已+ // 不存在,走 `dsh plugin remove` 也没有可安装的本地链接可删)。与弃用插件+ // 自动卸载同一模式:任何失败只记告警,绝不阻断本轮其余重装或整体启动。+ if !orphans.is_empty() {+ log::info!("Uninstalling orphaned internal preset plugins: {orphans:?}");+ for name in &orphans {+ if !super::recovery::is_actionable_plugin_ref(name) {+ log::warn!(+ "INTERNAL_PLUGIN_ORPHAN_SKIPPED: {name}(核心/官方包不执行孤儿卸载)"+ );+ continue;+ }+ if let Err(e) = super::uninstall_recovery(app_handle, name) {+ log::warn!("INTERNAL_PLUGIN_ORPHAN_UNINSTALL_FAILED: {name}: {e}");+ }+ }+ }if need.is_empty() {return Ok(());}