Skip to content

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

feat(bundle): 随包内核在核心面板置顶标记「本地」,切换仍走 AppData 槽位

hairyf9bc56aa59eba
diff --git a/scripts/bundle-metadata.mjs b/scripts/bundle-metadata.mjs
index 16a82e35..6b0ac934 100644
--- a/scripts/bundle-metadata.mjs
+++ b/scripts/bundle-metadata.mjs
@@ -265,11 +265,15 @@ export function toAssetTable(assets) {
}
/**
- * 把清单里的依赖托管根改写成 `$Resources/<dir>` 并关闭运行期覆盖。
+ * 把清单里的依赖托管根改写成 `$Resources/<dir>`。
*
- * 离线包把运行时随安装包分发,`managedRoot` 必须指向安装包资源目录;同时把
- * `overridable` 置为 false,让本机既有的 `dependencies.json` 记录(旧的非离线
- * 安装留下的 AppData 路径,可能已被删除)不能盖过随包资源。
+ * 离线包把运行时随安装包分发,`managedRoot` 必须指向安装包资源目录。
+ *
+ * `overridable` 按依赖区分:
+ * - Node / pnpm(以及可选的 MinGit)置 false:它们固定随包,本机既有的
+ * `dependencies.json` 记录(旧的非离线安装留下、可能已被删除)不该盖过随包资源;
+ * - 内核保持 true:随包内核是核心面板里置顶的「本地」项,用户要能下载并切换到
+ * AppData 里的其它版本,也能切回来——切换正是通过依赖映射表实现的。
*
* 改写结果直接写回 `src-tauri/resources/manifest.jsonc`(构建产物,不提交),
* 因此注释与缩进按 JSON 重新序列化。未随包的依赖(默认的 MinGit)保持清单原值,
@@ -290,8 +294,8 @@ export function applyBundleManifest({ repo = process.cwd(), platform, withGit =
throw bundleError(`manifest.jsonc is missing dependencies.${key}`)
const managedRoot = `${RESOURCES_TOKEN}/${BUNDLED_DIRS[key]}`
spec.managedRoot = managedRoot
- spec.overridable = false
- applied.push(`${key} -> ${managedRoot}`)
+ spec.overridable = key === 'dsh'
+ applied.push(`${key} -> ${managedRoot} (overridable: ${spec.overridable})`)
}
const file = manifestPath(repo)
diff --git a/src-tauri/resources/README.md b/src-tauri/resources/README.md
index 77a3ff70..119aece3 100644
--- a/src-tauri/resources/README.md
+++ b/src-tauri/resources/README.md
@@ -122,7 +122,7 @@ second set of installers that need no network on first launch. Its
Only what running `dsh` itself needs is bundled. Git is deliberately left out: it is not
required to start the harness, only git-backed features (worktree, `github:` plugins) are,
and an air-gapped machine can never provision it later. A bundled build therefore stops
-treating Git as a startup prerequisite (see `config::dependencies::is_bundled_install`),
+treating Git as a startup prerequisite (see `config::dependencies::bundled_core_dir`),
so the install screen is never entered for a download that cannot succeed.
Every asset is SHA-256 verified before unpacking (Node against the official
@@ -137,21 +137,38 @@ installer's own resources:
```jsonc
{
"dependencies": {
- "dsh": { "entry": "node_modules/@deepseek-ai/dsh/lib/bin.js", "managedRoot": "$Resources/dsh", "overridable": false }
+ "node": { "entry": { "windows": "node.exe", "default": "bin/node" }, "managedRoot": "$Resources/node", "overridable": false },
+ "dsh": { "entry": "node_modules/@deepseek-ai/dsh/lib/bin.js", "managedRoot": "$Resources/dsh", "overridable": true }
}
}
```
The rewrite only ever touches the build output — the committed manifest keeps its
-`$AppData/...` defaults. `overridable: false` is what stops a stale
-`<app-data>/dependencies.json` (written by an earlier, non-bundled install and possibly
-pointing at deleted directories) from winning over the bundled copy.
-
-No Rust code is involved: node/pnpm are only ever read, and the core is used in place,
-so the install directory must stay writable for the desktop's startup patches and plugin
-entry links — true for the per-user NSIS install, not for `/usr/lib/**` in the Linux deb
-(documented limitation). Community/preset plugins are still installed from the network;
-the offline bundle only removes the *first-launch* dependency downloads.
+`$AppData/...` defaults. `overridable` is per dependency:
+
+* `node` / `pnpm` (and MinGit, when bundled) are pinned (`false`): they ship with the
+ installer, and a stale `<app-data>/dependencies.json` (written by an earlier,
+ non-bundled install and possibly pointing at deleted directories) must not win over
+ them. `config::dependencies::active_root` additionally ignores a recorded root whose
+ path no longer exists.
+* `dsh` stays overridable (`true`): the bundled core is the core panel's pinned **本地**
+ entry, and switching cores works by pointing the `dsh` dependency root elsewhere —
+ either at a downloaded slot in `<app-data>/dependencies/<tag>` or back at
+ `$Resources/dsh`. Downloaded cores therefore keep landing in app data; the install
+ directory is never written to and never loses its bundled core (unlike a directory
+ swap, which would move `resources/dsh` into app data on every switch).
+
+`resource_root()` strips the Windows `\\?\` verbatim prefix that Tauri's
+`resource_dir()` carries (it canonicalizes the exe path). Without that, `$Resources/dsh`
+resolves to a verbatim path, which is handed to node as its main module — and node's
+`resolveMainPath` fails on it with `EISDIR: illegal operation on a directory, lstat 'C:'`,
+so the bundled core could never start.
+
+The bundled core is used in place, so the install directory must stay writable for the
+desktop's startup patches and plugin entry links — true for the per-user NSIS install, not
+for `/usr/lib/**` in the Linux deb (documented limitation). Community/preset plugins are
+still installed from the network; the offline bundle only removes the *first-launch*
+dependency downloads.
### Preset plugins — `plugins.preset`
diff --git a/src-tauri/src/config/dependencies.rs b/src-tauri/src/config/dependencies.rs
index c01a7ddf..e1251f7f 100644
--- a/src-tauri/src/config/dependencies.rs
+++ b/src-tauri/src/config/dependencies.rs
@@ -183,29 +183,37 @@ pub fn managed_root<R: Runtime>(app: &AppHandle<R>, key: &str) -> PathBuf {
///
/// 清单把 `dependencies.<key>.overridable` 声明为 false 时,映射表记录的位置一律
/// 被忽略(本地捆绑版内核固定随包,不允许被运行时改写)。
+///
+/// 记录的位置**已不存在**时同样按「未记录」处理:离线包(随包资源)升级、用户手工
+/// 删除下载的核心目录都会留下悬空记录,继续采信会让就绪判定把可用资源判成缺失,
+/// 进而转去联网下载。此时回落到清单托管根——普通安装的托管根与记录值本就同路,
+/// 悬空回落不影响既有行为。
pub fn active_root<R: Runtime>(app: &AppHandle<R>, key: &str) -> PathBuf {
let overridable = manifest::dependency_spec(app, key).is_none_or(|spec| spec.overridable);
if overridable {
if let Some(Some(recorded)) = mapped(app, key) {
- return manifest::resolve_location(app, &recorded.to_string_lossy());
+ let resolved = manifest::resolve_location(app, &recorded.to_string_lossy());
+ if resolved.exists() {
+ return resolved;
+ }
}
}
managed_root(app, key)
}
-/// 本次安装是否为「随包资源」构建:清单把核心托管根指向安装包资源目录
-/// (`$Resources/...`,离线包构建 `.github/actions/prepare-bundle-resources` 的改写产物)。
+/// 随包资源构建的随包核心根(`$Resources/dsh`);非随包构建为 None。
///
-/// 这类安装的运行时全部随安装包分发,运行期下载在离线机器上必然失败。启动就绪判定
-/// 据此放宽「补不上的依赖」——它们不是启动 dsh 的前置条件。
-#[cfg_attr(not(windows), allow(dead_code))] // 仅 Windows 的 Git 就绪判定使用
-pub fn is_bundled_install<R: Runtime>(app: &AppHandle<R>) -> bool {
- let Some(root) = manifest::resource_root(app) else {
- return false;
- };
+/// 这类安装的运行时全部随安装包分发(见 `.github/actions/prepare-bundle-resources`),
+/// 运行期下载在离线机器上必然失败:启动就绪判定据此放宽「补不上的依赖」,核心面板据此
+/// 把随包内核作为「本地」项置顶。
+///
+/// 判定按**清单托管根**而不是当前生效根:随包核心始终是安装目录里那一份,与该依赖
+/// 当前是否被映射到别处的槽位无关。
+pub fn bundled_core_dir<R: Runtime>(app: &AppHandle<R>) -> Option<PathBuf> {
+ let root = manifest::resource_root(app)?;
let managed = managed_root(app, DEP_DSH);
- // 资源根自身不算:只有把某个依赖托管到 `$Resources/<name>` 才是随包构建。
- managed != root && managed.starts_with(&root)
+ // 资源根自身不算:只有把核心托管到 `$Resources/<name>` 才是随包构建。
+ (managed != root && managed.starts_with(&root)).then_some(managed)
}
/// 入口相对路径(相对依赖根):清单 `dependencies.<key>.entry`,未声明时用内置默认
diff --git a/src-tauri/src/config/runtime.rs b/src-tauri/src/config/runtime.rs
index 77af2373..3f0bc501 100644
--- a/src-tauri/src/config/runtime.rs
+++ b/src-tauri/src/config/runtime.rs
@@ -446,13 +446,13 @@ pub fn get_git_cmd_dir<R: Runtime>(_app_handle: &AppHandle<R>) -> Option<PathBuf
///
/// 随包资源构建(离线安装包)只随包运行 dsh 必需的 Node / pnpm / 内核,不随包 MinGit:
/// 启动 dsh 本身不需要 Git,而内网补装必然失败,把 Git 当成启动前置条件只会把应用卡在
-/// 安装界面(见 [`dependencies::is_bundled_install`])。git 托管的能力(worktree、
+/// 安装界面(见 [`dependencies::bundled_core_dir`])。git 托管的能力(worktree、
/// `github:` 插件)在真正使用时给出明确失败。
#[cfg(windows)]
pub fn git_runtime_ready<R: Runtime>(app_handle: &AppHandle<R>) -> bool {
find_system_git_binary().is_some()
|| git_binary_works(&get_mingit_binary_path(app_handle))
- || dependencies::is_bundled_install(app_handle)
+ || dependencies::bundled_core_dir(app_handle).is_some()
}
/// 非 Windows 平台不属于本次空白 Windows 环境的自动配置范围。
diff --git a/src-tauri/src/service/core/source.rs b/src-tauri/src/service/core/source.rs
index b66798b2..5901f1cd 100644
--- a/src-tauri/src/service/core/source.rs
+++ b/src-tauri/src/service/core/source.rs
@@ -67,6 +67,9 @@ pub struct HarnessCore {
pub above_recommended: bool,
/// 本地存在但远程 pkg 仓库已不再提供的历史槽位。
pub orphaned: bool,
+ /// 是否随安装包分发(离线包把内核托管到 `$Resources/dsh`):核心面板把它置顶并
+ /// 标记「本地」,且不提供卸载——它是内网/离线环境唯一的兜底内核。
+ pub bundled: bool,
/// 资源清单中的推荐版本,用于切换前风险提示。
pub recommended_version: Option<String>,
pub error: Option<String>,
diff --git a/src-tauri/src/service/core/version.rs b/src-tauri/src/service/core/version.rs
index 7b4bdc14..79e39004 100644
--- a/src-tauri/src/service/core/version.rs
+++ b/src-tauri/src/service/core/version.rs
@@ -3,6 +3,10 @@
//! 磁盘布局:激活版本固定为 `dependencies/dsh`(既有代码全部依赖该路径),
//! 历史版本存放在 `dependencies/<tag>` 槽位,切换/卸载依赖既有版本行。本地
//! 核心的探测见 [`super::local`],来源判定与活动入口见 [`super::source`]。
+//!
+//! 随包资源构建(离线包)不适用上面的目录互换:随包内核必须留在安装目录里
+//! (`$Resources/dsh`,见 [`config::dependencies::bundled_core_dir`]),它在面板里
+//! 作为固定置顶的「本地」行存在,切换只是把 `dsh` 依赖根指向目标槽位或指回随包内核。
use crate::config;
use crate::service::{download, fs_guard, workflow};
@@ -13,16 +17,16 @@ use tauri::{AppHandle, Manager};
use super::local::{find_user_dsh_bin, local_core};
use super::source::{active_source, core_supports_bundled_plugins, CoreSource, HarnessCore};
-/// `dependencies` 目录(激活 `dsh` 与历史 `dsh-<tag>` 槽位的共同父级)。
+/// 随包内核的行 id:面板据此置顶并标记「本地」,[`set_active`] 据此切回随包内核。
+const BUNDLED_CORE_ID: &str = "app-bundled";
+
+/// `dependencies` 目录(下载的核心槽位与普通安装的 `dsh` 激活目录的共同父级)。
///
-/// 槽位是桌面端自己下载的产物,恒落在**托管根**之下:即使映射把激活核心指向
-/// `resources/dsh` 或其它任意位置,历史版本仍收在 AppData 里,不会污染安装目录。
+/// 恒落在应用数据目录之下:槽位是桌面端自己下载的产物,即使清单把激活核心托管到安装
+/// 包资源(离线包 `$Resources/dsh`)也不能让下载产物写进安装目录——那里在 macOS `.app`
+/// 上是签名的只读内容、在 Linux deb 里属于 root,且会随应用升级被覆盖。
fn dependencies_dir(app_handle: &AppHandle) -> PathBuf {
- let managed = config::dependencies::managed_root(app_handle, config::dependencies::DEP_DSH);
- managed
- .parent()
- .map(Path::to_path_buf)
- .unwrap_or_else(|| PathBuf::from("."))
+ config::get_base_dir(app_handle).join("dependencies")
}
/// 历史版本槽位:`dependencies/<tag>`。release tag 本身以 `dsh-` 开头
@@ -95,10 +99,41 @@ pub async fn list(app_handle: &AppHandle) -> Vec<HarnessCore> {
.as_ref()
.is_some_and(|c| config::is_dsh_version_above_recommended(app_handle, &c.version)),
orphaned: false,
+ bundled: false,
recommended_version: config::recommended_dsh_version(app_handle),
error: None,
}];
+ // 随包资源构建(离线包):随包内核独立成一行并置顶(`app-bundled`),用户仍可下载
+ // 其它版本(槽位在 AppData)并切换,也可以切回它。
+ let bundled_dir = config::dependencies::bundled_core_dir(app_handle);
+ let bundled_active = bundled_dir.as_ref().is_some_and(|dir| {
+ source == CoreSource::App && config::dependencies::active_root(app_handle, config::dependencies::DEP_DSH) == *dir
+ });
+ if let Some(dir) = &bundled_dir {
+ let version = read_manifest_dsh_version(dir).unwrap_or_default();
+ let dir_str = dir.to_string_lossy().into_owned();
+ rows.insert(
+ 0,
+ HarnessCore {
+ id: BUNDLED_CORE_ID.to_string(),
+ source: CoreSource::App,
+ above_recommended: config::is_dsh_version_above_recommended(app_handle, &version),
+ version,
+ tag: String::new(),
+ path: dir_str.clone(),
+ dir: dir_str,
+ present: dir.join(config::dependencies::entry_relative(app_handle, config::dependencies::DEP_DSH)).is_file(),
+ active: bundled_active,
+ preview: false,
+ orphaned: false,
+ bundled: true,
+ recommended_version: config::recommended_dsh_version(app_handle),
+ error: None,
+ },
+ );
+ }
+
// 激活的预打包信息:tag(可空,旧安装无记录)+ 安装目录状态
let active_tag = config::get_dsh_pkg_tag(app_handle);
let active_dir = config::get_dsh_install_path(app_handle);
@@ -106,7 +141,8 @@ pub async fn list(app_handle: &AppHandle) -> Vec<HarnessCore> {
// 激活核心按「版本」而非 tag 匹配版本行:pkg 仓库会对同一版本重打包/打
// 测试 tag,版本行去重后保留的 tag 未必等于本机安装时的记录 tag。按 tag
// 精确匹配会让激活版本行误标「未下载」并在列表底部多出一条重复激活行。
- let active_version = if source == CoreSource::App {
+ // 随包内核激活时(`app-bundled` 行已经代表它)不再让版本行认领同一份目录。
+ let active_version = if source == CoreSource::App && !bundled_active {
active_app_version(&active_tag, config::get_dsh_version(app_handle))
} else {
None
@@ -114,11 +150,15 @@ pub async fn list(app_handle: &AppHandle) -> Vec<HarnessCore> {
// 已安装的预打包版本号(无论当前以哪种来源运行都存在):用于保证预打包行
// 始终如实呈现为"已安装",即便本次以本地核心运行,也不会把它标成"未下载"。
// 旧记录可能没有版本号,稍后从激活目录 package.json 兜底读取。
- let installed_version = config::get_dsh_version(app_handle).or_else(|| {
- (source == CoreSource::App && active_present)
- .then(|| read_manifest_dsh_version(&active_dir))
- .flatten()
- });
+ let installed_version = if bundled_active {
+ None
+ } else {
+ config::get_dsh_version(app_handle).or_else(|| {
+ (source == CoreSource::App && active_present)
+ .then(|| read_manifest_dsh_version(&active_dir))
+ .flatten()
+ })
+ };
// 版本行:GitHub releases(最新在前,含 Pre-release label)→ 按版本去重,
// 同版本只保留最后一个 tag。releases 拉取失败(离线/限流)时回退 git tags,
@@ -210,6 +250,7 @@ pub async fn list(app_handle: &AppHandle) -> Vec<HarnessCore> {
preview: *preview,
above_recommended: config::is_dsh_version_above_recommended(app_handle, version),
orphaned: false,
+ bundled: false,
recommended_version: config::recommended_dsh_version(app_handle),
error: None,
});
@@ -218,7 +259,9 @@ pub async fn list(app_handle: &AppHandle) -> Vec<HarnessCore> {
// 已安装的预打包版本未出现在版本列表(离线/限流/tag 被移除/旧版无 tag 记录):
// 纳入版本行之后,保持列表不置顶;无论当前是否以本地核心运行都要列出,
// 避免"本地核心出现后预打包消失"。
- if !active_rendered && active_present {
+ // 随包内核已独立成行时不再兜底:`active_dir` 就是随包目录,再补一行会把下载版本
+ // 的旧 tag 指向随包目录,出现重复且错误的「当前使用中」。
+ if !active_rendered && active_present && !bundled_active {
rows.push(HarnessCore {
id: active_tag
.as_ref()
@@ -232,6 +275,7 @@ pub async fn list(app_handle: &AppHandle) -> Vec<HarnessCore> {
present: true,
active: source == CoreSource::App,
orphaned: false,
+ bundled: false,
// 无远程元数据(离线/限流):预览标记按 tag 命名兜底
preview: active_tag.as_deref().is_some_and(download::is_preview_tag),
above_recommended: installed_version
@@ -292,6 +336,7 @@ pub async fn list(app_handle: &AppHandle) -> Vec<HarnessCore> {
preview: download::is_preview_tag(&tag),
above_recommended: config::is_dsh_version_above_recommended(app_handle, &version),
orphaned,
+ bundled: false,
recommended_version: config::recommended_dsh_version(app_handle),
error: None,
});
@@ -338,9 +383,9 @@ async fn stop_harness_for_core_switch(app_handle: &AppHandle) -> Result<(), Stri
/// 切换活动核心(持久化 + 预打包版本目录互换;服务重启由前端负责)。
///
-/// `id` 取值:`local` | `app`(无 tag 记录的旧激活行)| `app-<tag>`。
+/// `id` 取值:`local` | `app`(无 tag 记录的旧激活行)| `app-bundled`(随包内核)| `app-<tag>`。
pub async fn set_active(app_handle: &AppHandle, id: &str) -> Result<HarnessCore, String> {
- let transition_guard = if id == "app" || id == "local" {
+ let transition_guard = if id == "app" || id == BUNDLED_CORE_ID || id == "local" {
Some(workflow::acquire_core_transition().await?)
} else {
None
@@ -364,6 +409,24 @@ pub async fn set_active(app_handle: &AppHandle, id: &str) -> Result<HarnessCore,
config::set_store_dat_setting(app_handle, setting);
// 映射表记录「该依赖由系统环境满足」(`null`),与清单的 `Path | null` 语义一致。
config::dependencies::record(app_handle, config::dependencies::DEP_DSH, None);
+ } else if id == BUNDLED_CORE_ID {
+ // 切回随包内核:它始终在安装目录里,只需把 dsh 依赖根指回去。
+ let Some(bundled) = config::dependencies::bundled_core_dir(app_handle) else {
+ return Err("CORE_BUNDLED_NOT_FOUND: this install ships no bundled core".to_string());
+ };
+ let entry = config::dependencies::entry_relative(app_handle, config::dependencies::DEP_DSH);
+ if !bundled.join(entry).is_file() {
+ return Err("CORE_BUNDLED_NOT_FOUND: bundled core files are missing".to_string());
+ }
+ stop_harness_for_core_switch(app_handle).await?;
+ let mut setting = config::get_store_dat_setting(app_handle);
+ setting.active_core = Some(CoreSource::App.as_str().to_string());
+ // 随包内核没有 pkg tag/commit:必须清掉下载版本留下的记录,否则版本展示与
+ // 「当前激活」判定仍指着那份已下载的核心。
+ setting.dsh_pkg_tag = None;
+ setting.dsh_pkg_commit = None;
+ config::set_store_dat_setting(app_handle, setting);
+ config::dependencies::record(app_handle, config::dependencies::DEP_DSH, Some(bundled));
} else if id == "app" {
if !config::get_dsh_binary_path(app_handle).exists() {
return Err("CORE_APP_NOT_FOUND: bundled core is not installed".to_string());
@@ -403,7 +466,8 @@ async fn switch_app_version(app_handle: &AppHandle, tag: &str) -> Result<(), Str
// 重叠,也避免 launch 在状态检查后插入并从旧的 dependencies/dsh 加载 DLL。
let _transition_guard = workflow::acquire_core_transition().await?;
let deps = dependencies_dir(app_handle);
- // 槽位互换只在托管根内进行(映射可能把激活核心指向安装目录的捆绑副本)。
+ // 槽位互换只在托管根内进行(映射可能把激活核心指向安装目录的捆绑副本);
+ // 随包资源构建不互换,见下方分支。
let active_dir = config::dependencies::managed_root(app_handle, config::dependencies::DEP_DSH);
fs_guard::validate_id(tag)?;
let cur_tag = config::get_dsh_pkg_tag(app_handle);
@@ -419,6 +483,30 @@ async fn switch_app_version(app_handle: &AppHandle, tag: &str) -> Result<(), Str
let target_dir = existing_slot_dir(app_handle, tag)
.ok_or_else(|| format!("CORE_VERSION_NOT_DOWNLOADED: {tag}"))?;
+ // 随包资源构建:随包内核必须留在安装目录(`$Resources/dsh`),不能像普通安装那样
+ // 把「激活目录 ↔ 槽位目录」互换——那会把安装包资源搬进 AppData,也会让应用升级
+ // 覆盖掉用户选中的版本。改为把 `dsh` 依赖根指向槽位本身:槽位本就在 AppData 里,
+ // 切回随包内核只是把根指回去(见 `set_active` 的 `app-bundled` 分支)。
+ if config::dependencies::bundled_core_dir(app_handle).is_some() {
+ stop_harness_for_core_switch(app_handle).await?;
+ let commit = match download::fetch_dsh_pkg_tags().await {
+ Ok(tags) => tags.into_iter().find(|(t, _)| t == tag).map(|(_, c)| c),
+ Err(e) => {
+ log::warn!("failed to resolve commit for tag {tag}: {e}");
+ None
+ }
+ };
+ let mut setting = config::get_store_dat_setting(app_handle);
+ setting.active_core = Some(CoreSource::App.as_str().to_string());
+ setting.dsh_pkg_tag = Some(tag.to_string());
+ if let Some(commit) = commit {
+ setting.dsh_pkg_commit = Some(commit);
+ }
+ config::set_store_dat_setting(app_handle, setting);
+ config::dependencies::record(app_handle, config::dependencies::DEP_DSH, Some(target_dir));
+ return Ok(());
+ }
+
// 切换前停止运行中的服务,避免目录被进程句柄锁定
if workflow::has_owned_process() {
workflow::stop(app_handle.clone()).await.map_err(|e| {
@@ -598,6 +686,13 @@ pub async fn download_version(app_handle: &AppHandle, tag: &str) -> Result<Harne
/// 卸载,正在跑的核心全挂了」)。只有直接删除因句柄锁定失败时(例如删到上一份激活
/// 副本、残留进程仍加载着它),才走「停服务 → 重试」的慢路径。
pub async fn remove_version(app_handle: &AppHandle, id: &str) -> Result<(), String> {
+ // 随包内核随安装包分发,是内网/离线环境唯一的兜底内核:删掉就只能重装应用才能恢复。
+ if id == BUNDLED_CORE_ID {
+ return Err(
+ "CORE_BUNDLED_PROTECTED: the bundled core ships with the app and cannot be removed"
+ .to_string(),
+ );
+ }
let Some(tag) = id.strip_prefix("app-") else {
return Err(format!("CORE_INVALID_ID: {id}"));
};
@@ -670,6 +765,7 @@ fn row_for_tag(app_handle: &AppHandle, tag: &str, dir: &Path) -> HarnessCore {
above_recommended: download::parse_version_from_tag(tag)
.is_some_and(|version| config::is_dsh_version_above_recommended(app_handle, &version)),
orphaned: false,
+ bundled: false,
recommended_version: config::recommended_dsh_version(app_handle),
error: None,
}
diff --git a/src-tauri/src/service/download/installable.rs b/src-tauri/src/service/download/installable.rs
index 31519d52..9754469e 100644
--- a/src-tauri/src/service/download/installable.rs
+++ b/src-tauri/src/service/download/installable.rs
@@ -126,9 +126,11 @@ impl Installable for Dsh {
config::get_dsh_binary_path(app).exists()
}
fn record_mapping(&self, app: &AppHandle) {
- let managed = config::dependencies::managed_root(app, config::dependencies::DEP_DSH);
+ // 记录**当前生效的根**而不是清单托管根:随包资源构建(离线包)里用户可以把内核
+ // 切到 AppData 的槽位,写回托管根会把这次切换悄悄改回随包内核。
+ let active = config::dependencies::active_root(app, config::dependencies::DEP_DSH);
if config::get_dsh_binary_path(app).is_file() {
- config::dependencies::record(app, InstallKind::Dsh.dependency_key(), Some(managed));
+ config::dependencies::record(app, InstallKind::Dsh.dependency_key(), Some(active));
} else if crate::service::core::active_version(app).is_some() {
// 只有系统(本地)核心可用:该依赖由系统环境满足。
config::dependencies::record(app, InstallKind::Dsh.dependency_key(), None);
diff --git a/src/types/core.ts b/src/types/core.ts
index 45480533..e82755aa 100644
--- a/src/types/core.ts
+++ b/src/types/core.ts
@@ -24,6 +24,8 @@ export interface HarnessCore {
aboveRecommended: boolean
/** 本地存在但 pkg 仓库已不再提供的历史槽位 */
orphaned: boolean
+ /** 随安装包分发的内核(离线包 `$Resources/dsh`):面板置顶并标记「本地」,不可卸载 */
+ bundled: boolean
recommendedVersion: string | null
error?: string | null
}
diff --git a/src/ui/config/core.tsx b/src/ui/config/core.tsx
index 37f34912..a0477593 100644
--- a/src/ui/config/core.tsx
+++ b/src/ui/config/core.tsx
@@ -90,10 +90,12 @@ export function ConfigCore() {
// 本地核心未检测到时不渲染 local 行(保留 local_missing_hint 提示)
// 后端列表在部分缓存/旧版本返回路径中可能仍保持远程顺序,前端统一按版本从高到低排序。
- // 本地核心固定放在版本列表前,预打包核心按 SemVer 排序。
+ // 随包内核(离线包)固定置顶并标记「本地」,其后是本地核心与预打包核心。
const rows = cores
.filter(core => !(core.source === 'local' && !core.present))
.sort((a, b) => {
+ if (a.bundled !== b.bundled)
+ return a.bundled ? -1 : 1
if (a.source !== b.source)
return a.source === 'local' ? -1 : 1
if (a.source === 'local')
@@ -355,7 +357,8 @@ export function ConfigCore() {
<Label className="min-w-0 truncate font-mono text-sm font-medium text-ink">
{displayVersion(core)}
</Label>
- <If cond={core.source === 'local'}>
+ {/* 随包内核(离线包)与用户 CLI 安装的本地核心都标记「本地」 */}
+ <If cond={core.source === 'local' || core.bundled}>
<Chip size="sm" variant="soft" color="accent" className="shrink-0 font-medium">
{t('core.local')}
</Chip>
@@ -434,8 +437,8 @@ export function ConfigCore() {
{t('core.download')}
</Button>
</If>
- {/* 已下载且非激活(app 版本):卸载入口 */}
- <If cond={core.present && !core.active && core.source === 'app'}>
+ {/* 已下载且非激活(app 版本):卸载入口。随包内核不可卸载(随应用分发) */}
+ <If cond={core.present && !core.active && core.source === 'app' && !core.bundled}>
<Button
size="sm"
variant="tertiary"
diff --git a/test/bundle-metadata.test.ts b/test/bundle-metadata.test.ts
index 59583085..3f58624a 100644
--- a/test/bundle-metadata.test.ts
+++ b/test/bundle-metadata.test.ts
@@ -188,16 +188,17 @@ describe('bundle manifest rewrite', () => {
try {
const result = bundleMetadata.applyBundleManifest({ repo, platform: 'windows' })
expect(result.applied).toEqual([
- 'node -> $Resources/node',
- 'pnpm -> $Resources/pnpm',
- 'dsh -> $Resources/dsh',
+ 'node -> $Resources/node (overridable: false)',
+ 'pnpm -> $Resources/pnpm (overridable: false)',
+ 'dsh -> $Resources/dsh (overridable: true)',
])
const manifest = JSON.parse(readFileSync(result.file, 'utf8'))
const shipped = JSON.parse(bundleMetadata.stripJsonc(SHIPPED))
for (const [key, dir] of [['node', 'node'], ['pnpm', 'pnpm'], ['dsh', 'dsh']]) {
expect(manifest.dependencies[key].managedRoot).toBe(`$Resources/${dir}`)
- expect(manifest.dependencies[key].overridable).toBe(false)
+ // 内核保持可覆盖:核心面板要能把 dsh 根切到 AppData 里的其它版本再切回来。
+ expect(manifest.dependencies[key].overridable).toBe(key === 'dsh')
// 入口形状由清单声明,改写托管根不得动它。
expect(manifest.dependencies[key].entry).toEqual(shipped.dependencies[key].entry)
}
@@ -216,10 +217,10 @@ describe('bundle manifest rewrite', () => {
try {
const { file, applied } = bundleMetadata.applyBundleManifest({ repo, platform: 'windows', withGit: true })
expect(applied).toEqual([
- 'node -> $Resources/node',
- 'pnpm -> $Resources/pnpm',
- 'dsh -> $Resources/dsh',
- 'git -> $Resources/git',
+ 'node -> $Resources/node (overridable: false)',
+ 'pnpm -> $Resources/pnpm (overridable: false)',
+ 'dsh -> $Resources/dsh (overridable: true)',
+ 'git -> $Resources/git (overridable: false)',
])
const manifest = JSON.parse(readFileSync(file, 'utf8'))
expect(manifest.dependencies.git.managedRoot).toBe('$Resources/git')
@@ -234,7 +235,11 @@ describe('bundle manifest rewrite', () => {
const repo = tempRepo()
try {
const { file, applied } = bundleMetadata.applyBundleManifest({ repo, platform: 'macos' })
- expect(applied).not.toContain('git -> $Resources/git')
+ expect(applied).toEqual([
+ 'node -> $Resources/node (overridable: false)',
+ 'pnpm -> $Resources/pnpm (overridable: false)',
+ 'dsh -> $Resources/dsh (overridable: true)',
+ ])
const manifest = JSON.parse(readFileSync(file, 'utf8'))
expect(manifest.dependencies.git.managedRoot).toBe('$AppData/dependencies/git')
expect(manifest.dependencies.git.overridable).toBe(true)
@@ -250,9 +255,9 @@ describe('bundle manifest rewrite', () => {
bundleMetadata.applyBundleManifest({ repo, platform: 'linux' })
const second = bundleMetadata.applyBundleManifest({ repo, platform: 'linux' })
expect(second.applied).toEqual([
- 'node -> $Resources/node',
- 'pnpm -> $Resources/pnpm',
- 'dsh -> $Resources/dsh',
+ 'node -> $Resources/node (overridable: false)',
+ 'pnpm -> $Resources/pnpm (overridable: false)',
+ 'dsh -> $Resources/dsh (overridable: true)',
])
expect(() => bundleMetadata.applyBundleManifest({ repo, platform: 'freebsd' as BundlePlatform }))
.toThrow(/^BUNDLE_METADATA:/)