DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
feat(desktop): managedRoot 与映射值支持 $AppData / $Resources 前缀令牌
hairyf5e312b502c9a
diff --git a/src-tauri/resources/README.md b/src-tauri/resources/README.mdindex 9b80b1b3..e8745de0 100644--- a/src-tauri/resources/README.md+++ b/src-tauri/resources/README.md@@ -54,7 +54,7 @@ mapping entry**."node": {"engine": ">=22.22.0","entry": { "windows": "node.exe", "default": "bin/node" },- "managedRoot": "runtime",+ "managedRoot": "$AppData/runtime","overridable": true}},@@ -63,6 +63,18 @@ mapping entry**.}```+`managedRoot` (and every recorded mapping value) accepts three forms:++| Form | Resolves to |+| ---- | ----------- |+| `$AppData/...` | the app data directory (its `dev` sibling in debug builds) |+| `$Resources/...` (legacy spelling: `resources/...`) | the installed app's resource root, falling back to app data when it cannot be probed |+| absolute path (`C:/anywhere/dsh`, `/opt/dsh`) | used verbatim — how a local bundle build points at a checkout |+| any other relative path | app data directory |++Prefixes are case-insensitive and require the `/` boundary (`$resourcesfoo` is a plain+relative path).+| Section | Purpose || ------- | ------- || `engines.dsh.recommend` | Recommended core version (update hints, "above recommended" marks) |@@ -83,15 +95,15 @@ Which root is actually used is recorded per machine in{ "node": "C:/Users/you/AppData/Roaming/dsh-tauri/runtime", "pnpm": null, "dsh": "C:/Users/you/AppData/Roaming/dsh-tauri/dependencies/dsh" }```-* a path → that root is used (any absolute location, or a `resources/...` token- resolved against the installed app's resource root);+* a path → that root is used (an absolute location anywhere on disk, or a+ `$AppData/...` / `$Resources/...` token as described above);* `null` → the system environment satisfies this dependency; a managed copy isstill downloaded into `managedRoot` if one is ever needed (and the mapping isrewritten then);* a missing key → fall back to the manifest's `managedRoot` (under app data).This is what makes a future "bundled core" build a manifest-only change:-point `managedRoot` (or the recorded root) at `resources/dsh` and no path logic+point `managedRoot` (or the recorded root) at `$Resources/dsh` and no path logicin `src-tauri` has to move.### Preset plugins — `plugins.preset`diff --git a/src-tauri/resources/manifest.jsonc b/src-tauri/resources/manifest.jsoncindex b99a0ea9..e801f312 100644--- a/src-tauri/resources/manifest.jsonc+++ b/src-tauri/resources/manifest.jsonc@@ -22,20 +22,23 @@"dependencies": {// 依赖映射规范:AppData 的 dependencies.json 只记录每个依赖的安装根// (null = 用系统环境);入口相对路径与默认托管根以本表为准。- // 位置可为绝对路径(任意位置)、resources/*(安装包资源)或相对 AppData 的相对路径。+ // managedRoot / 映射值支持三种形态:+ // $AppData/... AppData 数据目录(debug 构建为 <base>/dev 的同级)+ // $Resources/... 安装包资源目录(`resources/...` 为等价旧写法)+ // 绝对路径 任意位置(如加载本地捆绑版内核)"node": {"engine": ">=22.22.0","entry": {"windows": "node.exe","default": "bin/node"},- "managedRoot": "runtime",+ "managedRoot": "$AppData/runtime","overridable": true},"pnpm": {"engine": ">=11.7.0","entry": "bin/pnpm.cjs",- "managedRoot": "dependencies/pnpm",+ "managedRoot": "$AppData/dependencies/pnpm","overridable": true},"dsh": {@@ -44,7 +47,7 @@"minimum": "0.1.5-rc.1"},"entry": "node_modules/@deepseek-ai/dsh/lib/bin.js",- "managedRoot": "dependencies/dsh",+ "managedRoot": "$AppData/dependencies/dsh","overridable": true},"git": {@@ -53,7 +56,7 @@"windows": "cmd/git.exe","default": "bin/git"},- "managedRoot": "dependencies/git",+ "managedRoot": "$AppData/dependencies/git","overridable": true}},diff --git a/src-tauri/src/config/dependencies.rs b/src-tauri/src/config/dependencies.rsindex 4e462506..cc97b91e 100644--- a/src-tauri/src/config/dependencies.rs+++ b/src-tauri/src/config/dependencies.rs@@ -175,9 +175,14 @@ pub fn managed_root<R: Runtime>(app: &AppHandle<R>, key: &str) -> PathBuf {}/// 当前生效的依赖根:映射指定的根优先,否则回落清单默认托管根+///+/// 映射表里的值同样按 [`manifest::resolve_location`] 解析:绝对路径原样使用(任意+/// 位置),`resources/...` 指向安装包资源根,其余相对路径相对 AppData 基目录。因此+/// 本地捆绑 / 切换内核只需在映射表里写 `"dsh": "resources/dsh"` 或任意绝对路径,+/// 不必改动清单或重装。pub fn active_root<R: Runtime>(app: &AppHandle<R>, key: &str) -> PathBuf {match mapped(app, key) {- Some(Some(path)) => path,+ Some(Some(recorded)) => manifest::resolve_location(app, &recorded.to_string_lossy()),_ => managed_root(app, key),}}@@ -327,14 +332,22 @@ mod tests {.join("resources").join(manifest::MANIFEST_FILE);let manifest = manifest::read_at(&path).expect("manifest should parse");+ // 清单声明的托管根可以是 `$AppData/...` 令牌,因此比较**解析后**的位置+ let base = PathBuf::from("C:/app-data");+ let resources = PathBuf::from("C:/app-resources");for (key, root, entry) in [- (DEP_NODE, "runtime", default_entry(DEP_NODE)),- (DEP_PNPM, "dependencies/pnpm", default_entry(DEP_PNPM)),- (DEP_DSH, "dependencies/dsh", default_entry(DEP_DSH)),- (DEP_GIT, "dependencies/git", default_entry(DEP_GIT)),+ (DEP_NODE, default_managed_root(DEP_NODE), default_entry(DEP_NODE)),+ (DEP_PNPM, default_managed_root(DEP_PNPM), default_entry(DEP_PNPM)),+ (DEP_DSH, default_managed_root(DEP_DSH), default_entry(DEP_DSH)),+ (DEP_GIT, default_managed_root(DEP_GIT), default_entry(DEP_GIT)),] {let spec = manifest.dependencies.get(key).expect("spec should exist");- assert_eq!(spec.managed_root.as_deref(), Some(root), "{key}");+ let declared = spec.managed_root.as_deref().expect("managedRoot");+ assert_eq!(+ manifest::resolve_location_from(&base, Some(&resources), declared),+ base.join(root),+ "{key}"+ );assert_eq!(spec.entry.resolve(), Some(entry), "{key}");}}diff --git a/src-tauri/src/config/manifest.rs b/src-tauri/src/config/manifest.rsindex fcfd5501..0e70eab2 100644--- a/src-tauri/src/config/manifest.rs+++ b/src-tauri/src/config/manifest.rs@@ -453,25 +453,56 @@ pub fn resolve_location<R: Runtime>(app: &AppHandle<R>, raw: &str) -> PathBuf {)}-/// [`resolve_location`] 的纯函数版本(不依赖 AppHandle,便于单测)+/// 位置令牌解析(依赖可位于任意位置:AppData 托管、安装目录捆绑、或用户指定的其它盘符):+///+/// - 绝对路径(`C:/...`、`/opt/...`)原样返回;+/// - `$AppData/...`(大小写不敏感)= AppData 基础目录,debug 构建即 `<base>/dev` 的同级;+/// - `$Resources/...` = 安装包资源根(`resources/` 为等价旧写法),探测不到时回落 AppData;+/// - 其余相对路径 = 相对 AppData 基础目录。pub fn resolve_location_from(base: &Path, resource_root: Option<&Path>, raw: &str) -> PathBuf {let value = raw.trim();- let path = PathBuf::from(value);- if path.is_absolute() {- return path;+ if PathBuf::from(value).is_absolute() {+ return PathBuf::from(value);}let normalized = value.replace('\\', "/");if let Some(rest) = normalized.strip_prefix("./") {return resolve_location_from(base, resource_root, rest);}+ if let Some(rest) = strip_prefix_ci(&normalized, "$appdata") {+ return join_token(base, rest);+ }+ if let Some(rest) = strip_prefix_ci(&normalized, "$resources") {+ return join_token(resource_root.unwrap_or(base), rest);+ }if let Some(rest) = normalized.strip_prefix("resources/") {if let Some(root) = resource_root {- return root.join(rest.replace('/', std::path::MAIN_SEPARATOR_STR));+ return join_token(root, rest);}}base.join(value)}+/// 大小写不敏感前缀剥离:前缀后必须是结束或 `/`(避免 `$resourcesfoo` 被当成令牌)+fn strip_prefix_ci<'a>(value: &'a str, prefix: &str) -> Option<&'a str> {+ let head = value.get(..prefix.len())?;+ if !head.eq_ignore_ascii_case(prefix) {+ return None;+ }+ let rest = &value[prefix.len()..];+ if rest.is_empty() {+ return Some(rest);+ }+ rest.strip_prefix('/')+}++/// 令牌剩余片段拼到根上(空片段取根本身)+fn join_token(root: &Path, rest: &str) -> PathBuf {+ if rest.is_empty() || rest == "." {+ return root.to_path_buf();+ }+ root.join(rest.replace('/', std::path::MAIN_SEPARATOR_STR))+}+fn strip_jsonc(raw: &str) -> String {let chars: Vec<char> = raw.chars().collect();let mut out = String::with_capacity(raw.len());@@ -736,4 +767,47 @@ mod tests {PathBuf::from(absolute));}++ #[test]+ fn location_prefix_tokens_are_case_insensitive_and_typed() {+ let base = PathBuf::from("C:/app/data");+ let resources = PathBuf::from("C:/app/resources");++ for raw in [+ "$AppData/runtime",+ "$appdata/runtime",+ "$APPDATA\\runtime",+ "$AppData",+ ] {+ let expected = if raw.ends_with("runtime") {+ base.join("runtime")+ } else {+ base.clone()+ };+ assert_eq!(+ resolve_location_from(&base, Some(&resources), raw),+ expected,+ "{raw}"+ );+ }++ for raw in ["$Resources/dsh", "$resources/dsh", r"$RESOURCES\dsh"] {+ assert_eq!(+ resolve_location_from(&base, Some(&resources), raw),+ resources.join("dsh"),+ "{raw}"+ );+ }++ // 资源根探测不到时回落 AppData,而不是相对当前工作目录+ assert_eq!(+ resolve_location_from(&base, None, "$Resources/dsh"),+ base.join("dsh")+ );+ // 前缀不完整(不是令牌)时按普通相对路径处理+ assert_eq!(+ resolve_location_from(&base, Some(&resources), "$resourcesfoo/dsh"),+ base.join("$resourcesfoo/dsh")+ );+ }}