From 00d3e41fcc9e323853833d01d35ad0f1d142dd51 Mon Sep 17 00:00:00 2001 From: lzt404 <2596933790@qq.com> Date: Fri, 21 Aug 2026 16:58:32 +0800 Subject: [PATCH] fix(agents): prevent Claude Desktop from launching during macOS detection --- src-tauri/src/agents/discovery.rs | 36 +++++++++++++++++----- src-tauri/src/tests/agent_configuration.rs | 16 ++++++++++ 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/src-tauri/src/agents/discovery.rs b/src-tauri/src/agents/discovery.rs index 0d75290..0ba7a0c 100644 --- a/src-tauri/src/agents/discovery.rs +++ b/src-tauri/src/agents/discovery.rs @@ -830,16 +830,18 @@ pub(crate) fn inspect_agent_config( Err(error) => (false, None, false, false, Some(error)), }; let executable = find_agent_executable(client, home); - // ZCode's desktop executable is an Electron app, not a CLI. Invoking it - // with --version can start the GUI and block discovery, so only probe a - // separately installed command-line entry point here. + // Desktop application executables are not CLIs. Invoking them with + // --version can start their GUI and block discovery, so never probe them + // directly. ZCode may still expose a separate command-line entry point. let cli_version = if client == AgentClient::ZCode { find_named_agent_executable(home, &["zcode"]) .filter(|path| executable.as_ref() != Some(path)) .as_deref() .and_then(read_agent_version) - } else { + } else if should_probe_primary_agent_executable_version(client) { executable.as_deref().and_then(read_agent_version) + } else { + None }; let codex_app_installation = (client == AgentClient::Codex) .then(|| find_codex_app_installation(home)) @@ -855,7 +857,8 @@ pub(crate) fn inspect_agent_config( }; let version = cli_version.clone().or_else(|| app_version.clone()); let installed = version.is_some() - || (client == AgentClient::ZCode && executable.is_some()) + || (matches!(client, AgentClient::ClaudeDesktop | AgentClient::ZCode) + && executable.is_some()) || codex_app_installation.is_some(); let launch_targets = agent_launch_targets( client, @@ -907,6 +910,10 @@ pub(crate) fn inspect_agent_config( } } +pub(crate) fn should_probe_primary_agent_executable_version(client: AgentClient) -> bool { + !matches!(client, AgentClient::ClaudeDesktop | AgentClient::ZCode) +} + pub(crate) fn agent_launch_targets( client: AgentClient, executable: Option<&Path>, @@ -1333,11 +1340,24 @@ pub(crate) fn read_claude_desktop_version(home: &Path) -> Option { #[cfg(target_os = "windows")] { read_windows_claude_desktop_store_version().or_else(|| { - find_claude_desktop_executable(home).and_then(|path| read_agent_version(&path)) + find_claude_desktop_executable(home) + .and_then(|path| read_windows_executable_version(&path)) }) } - #[cfg(not(target_os = "windows"))] - find_claude_desktop_executable(home).and_then(|path| read_agent_version(&path)) + #[cfg(target_os = "macos")] + { + find_claude_desktop_executable(home).and_then(|path| { + let application = path.ancestors().find(|candidate| { + candidate.extension().and_then(|value| value.to_str()) == Some("app") + })?; + read_macos_app_version(application) + }) + } + #[cfg(not(any(target_os = "windows", target_os = "macos")))] + { + let _ = home; + None + } } pub(crate) fn read_codex_app_installation_version(installation: &CodexAppTarget) -> Option { diff --git a/src-tauri/src/tests/agent_configuration.rs b/src-tauri/src/tests/agent_configuration.rs index 85cfe58..fac09a6 100644 --- a/src-tauri/src/tests/agent_configuration.rs +++ b/src-tauri/src/tests/agent_configuration.rs @@ -1148,6 +1148,22 @@ fn kimi_grok_and_zcode_use_cpa_runtime_context_windows() { } } +#[test] +fn desktop_application_binaries_are_not_used_for_cli_version_probes() { + assert!(!should_probe_primary_agent_executable_version( + AgentClient::ClaudeDesktop + )); + assert!(!should_probe_primary_agent_executable_version( + AgentClient::ZCode + )); + assert!(should_probe_primary_agent_executable_version( + AgentClient::ClaudeCode + )); + assert!(should_probe_primary_agent_executable_version( + AgentClient::Codex + )); +} + #[test] fn claude_model_lists_mark_yaml_aliases_when_api_returns_only_model_ids() { let mut models = test_agent_models(&[