DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
fix(plugin): uninstall dangling local link dependencies on startup
hairyfefe748876906
diff --git a/src-tauri/src/service/plugin/internal/manifest.rs b/src-tauri/src/service/plugin/internal/manifest.rsindex 2cc00c7e..ee1bfe40 100644--- a/src-tauri/src/service/plugin/internal/manifest.rs+++ b/src-tauri/src/service/plugin/internal/manifest.rs@@ -200,6 +200,62 @@ pub(super) fn is_local_link_dep(spec: &str) -> bool {spec.starts_with("link:") || spec.starts_with("file:")}+/// 收集「本地链接目标已不存在、且不再是当前内置预设」的依赖名(排序后返回)。+///+/// 已删除的内置包不会出现在 `load_presets` 的预设清单里,孤儿分支永远碰不到它,+/// 其 `link:` 悬空依赖与 `dsh.profile.bundles` 引用会永久留在 profile,令 dsh 每次+/// 启动都报 `cannot resolve profile bundle <name>`。`keep`(当前预设的包名)必须+/// 排除:预设的链接目标可能因应用升级/切分支而移动,那条路径要重装而不是卸载。+/// 只认 `link:`/`file:` 本地链接;registry/git 引用缺产物属安装问题,绝不在此清理。+pub(super) fn collect_dangling_local_link_deps(+ manifest: &serde_json::Value,+ keep: &HashSet<&str>,+ profile: &Path,+) -> Vec<String> {+ let Some(dependencies) = manifest+ .get("dependencies")+ .and_then(serde_json::Value::as_object)+ else {+ return Vec::new();+ };+ let mut dangling: Vec<String> = dependencies+ .iter()+ .filter(|(name, spec)| {+ !keep.contains(name.as_str())+ && spec.as_str().is_some_and(|spec| {+ is_local_link_dep(spec) && !local_link_target_exists(spec, profile)+ })+ })+ .map(|(name, _)| name.clone())+ .collect();+ dangling.sort();+ dangling+}++/// 本地链接依赖的目标目录是否存在(相对值按 profile 目录解析,容忍 verbatim 前缀)。+fn local_link_target_exists(spec: &str, profile: &Path) -> bool {+ let Some(raw) = spec+ .strip_prefix("link:")+ .or_else(|| spec.strip_prefix("file:"))+ else {+ return true;+ };+ let trimmed = raw.trim_end_matches(['/', '\\']);+ if trimmed.is_empty() {+ return false;+ }+ // pnpm 在 Windows 上可能写入 `\\?\` / `//?/` verbatim 前缀,先经 dunce 归一化,+ // 否则对同一目录的判存会因前缀不同而假阴性。+ let normalized = trimmed.replace('/', std::path::MAIN_SEPARATOR_STR);+ let path = dunce::simplified(Path::new(&normalized)).to_path_buf();+ let resolved = if path.is_absolute() {+ path+ } else {+ profile.join(path)+ };+ resolved.is_dir()+}+/// 判断 pnpm 写入 profile 的依赖值与期望的 `link:` 捆绑路径是否一致。////// 容忍:`link:`/`file:` 前缀缺失或两者混写(历史遗留 `file:` 安装值);Windows@@ -398,6 +454,48 @@ mod tests {assert!(!is_local_link_dep(""));}+ #[test]+ fn dangling_local_link_deps_exclude_presets_and_registry_specs() {+ let root = std::env::temp_dir().join(format!(+ "dsh-dangling-link-deps-{}",+ std::process::id()+ ));+ let _ = std::fs::remove_dir_all(&root);+ let profile = root.join("profile");+ let alive = root.join("packages/dsh-tauri-ui");+ std::fs::create_dir_all(&profile).unwrap();+ std::fs::create_dir_all(&alive).unwrap();+ let alive_spec = format!("link:{}", alive.to_string_lossy());++ let manifest = serde_json::json!({+ "dependencies": {+ "dsh-tauri-panel": "link:D:/gone/packages/dsh-tauri-panel",+ "dsh-tauri-ui": alive_spec,+ "dsh-tauri": "link:D:/gone/packages/dsh-tauri",+ "dshmarket": "github:dsh-market/dshmarket",+ "dsh-better-sidebar": "1.0.0",+ "dsh-tauri-pet": "link:missing-sibling-package"+ }+ });+ let keep = HashSet::from(["dsh-tauri"]);++ let dangling = collect_dangling_local_link_deps(&manifest, &keep, &profile);++ assert_eq!(+ dangling,+ vec!["dsh-tauri-panel".to_string(), "dsh-tauri-pet".to_string()]+ );+ let _ = std::fs::remove_dir_all(root);+ }++ #[test]+ fn dangling_local_link_deps_ignore_manifests_without_dependencies() {+ let profile = std::env::temp_dir();+ let manifest = serde_json::json!({ "name": "dsh-profile-web", "private": true });++ assert!(collect_dangling_local_link_deps(&manifest, &HashSet::new(), &profile).is_empty());+ }+#[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 3536c812..44002298 100644--- a/src-tauri/src/service/plugin/internal/mod.rs+++ b/src-tauri/src/service/plugin/internal/mod.rs@@ -26,9 +26,9 @@ use super::process::{new_process_owner, ProcessOwner};use crate::config;use manifest::{- 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,+ collect_dangling_local_link_deps, 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,};mod manifest;@@ -238,6 +238,7 @@ pub(crate) fn repair_loader_state(app_handle: &AppHandle) -> Result<(), String>pub(crate) async fn ensure(app_handle: &AppHandle) -> Result<(), String> {let presets = load_presets(app_handle);let internal: Vec<_> = presets.into_iter().filter(|p| p.internal).collect();+ prune_dangling_link_deps(app_handle, &internal);if internal.is_empty() {return Ok(());}@@ -260,6 +261,41 @@ pub(crate) async fn ensure(app_handle: &AppHandle) -> Result<(), String> {receive_current_or_next_flight(|| subscribe_or_start(app_handle, &internal)).await}+/// 卸载「本地链接目标已不存在」的失效依赖(含已被删除的内置包),在服务启动前调用。+///+/// 已删除的包不再出现在预设清单里,孤儿分支(bundled 目录缺失)永远碰不到它,其+/// `link:` 悬空依赖与 `dsh.profile.bundles` 引用会永久留档,令 dsh 每次启动都报+/// `cannot resolve profile bundle <name>`。与孤儿卸载同一模式:best-effort、离线+/// 精准(改写清单 + 删入口 + 剥 patch 层),任何失败只记告警,绝不阻断启动。+fn prune_dangling_link_deps(app_handle: &AppHandle, internal: &[PreinstallPluginInfo]) {+ let profile = profile_dir(app_handle);+ let manifest_path = profile.join("package.json");+ let Ok(raw) = std::fs::read_to_string(&manifest_path) else {+ return;+ };+ let Ok(manifest) = serde_json::from_str::<serde_json::Value>(&raw) else {+ log::warn!("INTERNAL_PLUGIN_MANIFEST_PARSE_FAILED: 跳过失效链接依赖清理");+ return;+ };+ let mut keep: HashSet<&str> = HashSet::new();+ for preset in internal {+ keep.insert(preset.id.as_str());+ keep.insert(installed_name(preset));+ }+ for name in collect_dangling_local_link_deps(&manifest, &keep, &profile) {+ if !super::recovery::is_actionable_plugin_ref(&name) {+ log::warn!("INTERNAL_PLUGIN_DANGLING_LINK_SKIPPED: {name}(核心/官方包不执行卸载)");+ continue;+ }+ log::warn!(+ "INTERNAL_PLUGIN_DANGLING_LINK_UNINSTALLING: {name}(本地链接目标已不存在,卸载失效依赖)"+ );+ if let Err(e) = super::uninstall_recovery(app_handle, &name) {+ log::warn!("INTERNAL_PLUGIN_DANGLING_LINK_UNINSTALL_FAILED: {name}: {e}");+ }+ }+}+async fn subscribe_or_start(app_handle: &AppHandle,internal: &[PreinstallPluginInfo],