Skip to content

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

fix(cli): Windows .cmd shim 统一 CRLF 行尾,修复内置插件安装失败 (#581)

hairyfba0c66f46d9b
diff --git a/docs/AGENTS.desktop.md b/docs/AGENTS.desktop.md
index d5822f3d..ceb5e144 100644
--- a/docs/AGENTS.desktop.md
+++ b/docs/AGENTS.desktop.md
@@ -192,5 +192,6 @@ function ConfirmDialog(props: ConfirmDialogProps) {
* **YAML 补丁层错误 (Issue #525)**:损坏的 `cordis.patch.yml` 会被隔离为 `<Name>.broken-<Timestamp>`。若隔离/重命名失败,程序将直接中止并返回 `PATCH_LAYER_QUARANTINE_FAILED`,要求用户手动处理。
* **pnpm Workspace 多文档修复 (Issue #526)**:若 `pnpm-workspace.yaml` 被意外包含 `---` 多文档,解析器会自动尝试解析并合并为单文档落盘自愈(日志标记 `PROFILE_WORKSPACE_MULTI_DOCUMENT`)。
* **旧版 WebKit 缺失 Iterator 补丁 (Issue #539)**:在非 Windows 平台的 WebView 初始化时注入 `compat_iterator.js.inc` 垫片,补齐 ES2025 Iterator Helpers(在 `Object.getPrototypeOf(...)` 上挂载),防止旧 macOS WebKit 崩溃。
+* **Windows `.cmd` shim 行尾 (Issue #581)**:`.gitattributes` 把 `.rs` 固定为 LF,生成的 `dsh.cmd`/`pnpm.cmd` 必须在返回前统一转 CRLF(`normalize_cmd_line_endings`),LF-only 会让部分环境下 cmd.exe 解析错位、内置插件安装全部失败。
* **macOS 媒体权限配置 (Issue #214)**:必须同时在 `Info.plist` (声明 Usage Description) 与 `Entitlements.plist` (声明 `com.apple.security.device.*`) 中配置,相对路径基于 tauri bundle 运行时的 CWD 目录。
* **Linux 托盘点击适配 (Issue #386/#438)**:Linux 环境下通过 `linux_tray.rs` 基于 `tray-icon 0.25 (ksni)` 单独构建托盘,避免 muda 依赖版本冲突,通过 `Box::leak` 保活并在独立线程中处理事件。
\ No newline at end of file
diff --git a/src-tauri/src/service/cli/shim/build.rs b/src-tauri/src/service/cli/shim/build.rs
index c32df6ac..2299c1b1 100644
--- a/src-tauri/src/service/cli/shim/build.rs
+++ b/src-tauri/src/service/cli/shim/build.rs
@@ -14,6 +14,17 @@ use super::templates::{
SH_NODE_RESOLVE,
};
+/// Windows `.cmd` 统一为 CRLF 行尾。
+///
+/// 批处理由 `cmd.exe` 按行解析,本文件被 `.gitattributes` 固定为 LF(`*.rs
+/// text eol=lf`),Rust 多行字符串里的 LF 会原样落盘。LF-only 的 `.cmd` 在部分
+/// Windows 环境下会让批处理 label/括号块的解析错位,命令以退出码 1 结束
+/// (issue #581:`dsh plugin install` 因此全部失败)。所有 `.cmd` 内容在返回前
+/// 转换,落盘即与手写的 Windows 批处理一致。
+fn normalize_cmd_line_endings(content: String) -> String {
+ content.replace("\r\n", "\n").replace('\n', "\r\n")
+}
+
// ---------------------------------------------------------------------------
// dsh shim
// ---------------------------------------------------------------------------
@@ -25,7 +36,7 @@ use super::templates::{
pub fn build_cmd_shim(app_dir: &Path, dsh_home: &Path) -> String {
let dsh_bin = app_dir.join("dependencies/dsh/node_modules/@deepseek-ai/dsh/lib/bin.js");
- format!(
+ normalize_cmd_line_endings(format!(
r#"@echo off
rem DeepSeek Harness Desktop - dsh command shim (generated)
rem Do not edit: regenerated by the desktop app on install/startup.
@@ -58,7 +69,7 @@ exit /b 1
dsh_home = escape_path_cmd(&dsh_home),
user_dsh = CMD_USER_DSH_PRECEDENCE,
node_resolve = CMD_NODE_RESOLVE,
- )
+ ))
}
/// Windows `dsh.ps1` 内容
@@ -153,7 +164,7 @@ exec "$NODE" "$DSH_BIN" "$@"
pub fn build_pnpm_cmd_shim(app_dir: &Path) -> String {
let pnpm_bin = app_dir.join("dependencies/pnpm/bin/pnpm.cjs");
- format!(
+ normalize_cmd_line_endings(format!(
r#"@echo off
rem DeepSeek Harness Desktop - pnpm command shim (generated)
rem Do not edit: regenerated by the desktop app on install/startup.
@@ -224,7 +235,7 @@ exit /b 1
app_dir = escape_path_cmd(app_dir),
pnpm_bin = escape_path_cmd(&pnpm_bin),
node_resolve = CMD_NODE_RESOLVE,
- )
+ ))
}
/// Windows `pnpm.ps1` 内容:优先转发用户 pnpm(`Get-Command pnpm -All`,
@@ -368,6 +379,48 @@ mod tests {
assert!(!content.contains(r#"set "APP_DIR=C:\Users\100%test""#));
}
+ /// issue #581:Windows `.cmd` 必须全 CRLF。Rust 源码被 `.gitattributes`
+ /// 固定为 LF,多行字符串里的裸 LF 会让部分环境下的 cmd.exe 解析
+ /// label/括号块错位,`dsh plugin install` 因此整体失败。
+ #[test]
+ fn cmd_shims_use_crlf_line_endings() {
+ for (name, content) in [
+ (
+ "dsh.cmd",
+ build_cmd_shim(&sample_app_dir(), &sample_dsh_home()),
+ ),
+ ("pnpm.cmd", build_pnpm_cmd_shim(&sample_app_dir())),
+ ] {
+ assert!(content.contains("@echo off"), "{name}: missing header");
+ let bytes = content.as_bytes();
+ for (index, byte) in bytes.iter().enumerate() {
+ if *byte == b'\n' {
+ assert!(
+ index > 0 && bytes[index - 1] == b'\r',
+ "{name}: unpaired LF at byte {index}"
+ );
+ }
+ if *byte == b'\r' {
+ assert_eq!(
+ bytes.get(index + 1),
+ Some(&b'\n'),
+ "{name}: unpaired CR at byte {index}"
+ );
+ }
+ }
+ }
+ }
+
+ #[test]
+ fn normalize_cmd_line_endings_converts_lone_lf_and_is_idempotent() {
+ assert_eq!(normalize_cmd_line_endings("a\nb".into()), "a\r\nb");
+ assert_eq!(normalize_cmd_line_endings("a\r\nb".into()), "a\r\nb");
+ assert_eq!(
+ normalize_cmd_line_endings("a\r\nb\nc".into()),
+ "a\r\nb\r\nc"
+ );
+ }
+
#[cfg(windows)]
#[test]
fn windows_shims_configure_bundled_git_without_shadowing_system_git() {
diff --git a/src-tauri/src/service/cli/shim/write.rs b/src-tauri/src/service/cli/shim/write.rs
index ea48cdba..d698120f 100644
--- a/src-tauri/src/service/cli/shim/write.rs
+++ b/src-tauri/src/service/cli/shim/write.rs
@@ -328,4 +328,30 @@ mod tests {
);
let _ = std::fs::remove_dir_all(&dir);
}
+
+ /// issue #581:旧版本落盘的 LF-only `.cmd` 仍带生成标记(可被覆盖),
+ /// 下一次 `ensure_shims` 必须把它升级为 CRLF 版本。
+ #[test]
+ fn write_shim_file_migrates_legacy_lf_only_cmd_shim() {
+ let dir = temp_dir("legacy-lf-cmd");
+ let target = dir.join("pnpm.cmd");
+ let current = build_pnpm_cmd_shim(&dir.join("app"));
+ assert!(current.contains("\r\n"));
+ std::fs::write(&target, current.replace("\r\n", "\n")).unwrap();
+ assert!(
+ !is_foreign_file(&target),
+ "legacy generated shim must stay overwritable"
+ );
+
+ write_shim_file(&target, &current).unwrap();
+
+ let content = std::fs::read_to_string(&target).unwrap();
+ assert_eq!(content, current);
+ assert_eq!(
+ content.matches('\n').count(),
+ content.matches("\r\n").count(),
+ "migrated shim must not keep unpaired LF"
+ );
+ let _ = std::fs::remove_dir_all(&dir);
+ }
}