Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

spaces: onboarding AI agents step only ticks agents that are really installed (CUA-1771) (#5312)

Francesco Bonacci1876e2771f51
diff --git a/libs/cua/crates/cua-agent-setup/src/lib.rs b/libs/cua/crates/cua-agent-setup/src/lib.rs
index b2d3353f4f..0ade4cf1e5 100644
--- a/libs/cua/crates/cua-agent-setup/src/lib.rs
+++ b/libs/cua/crates/cua-agent-setup/src/lib.rs
@@ -137,6 +137,19 @@ pub struct HostEnv {
pub run_agent_clis: bool,
}
+/// Where coding-agent CLIs usually install, searched after `$PATH`.
+fn well_known_bin_dirs(home: &Path) -> Vec<PathBuf> {
+ vec![
+ home.join(".local/bin"),
+ home.join(".claude/local"),
+ home.join(".npm-global/bin"),
+ home.join(".bun/bin"),
+ home.join(".cargo/bin"),
+ PathBuf::from("/opt/homebrew/bin"),
+ PathBuf::from("/usr/local/bin"),
+ ]
+}
+
const VARS: &[&str] = &[
"XDG_CONFIG_HOME",
"APPDATA",
@@ -166,10 +179,20 @@ impl HostEnv {
.iter()
.filter_map(|k| std::env::var(k).ok().map(|v| (k.to_string(), v)))
.collect();
- let path = std::env::var_os("PATH")
+ let os = Os::current();
+ let mut path: Vec<PathBuf> = std::env::var_os("PATH")
.map(|p| std::env::split_paths(&p).collect())
.unwrap_or_default();
- let os = Os::current();
+ // A GUI app (Cua Spaces from the Dock) runs without the user's
+ // shell PATH, so an agent installed under a user bin dir would look
+ // missing. Search the usual install dirs after the real PATH.
+ if os != Os::Windows {
+ for d in well_known_bin_dirs(&home) {
+ if !path.contains(&d) {
+ path.push(d);
+ }
+ }
+ }
// `CUA_AGENT_APP_DIRS` (a path list, empty for none) replaces the
// app folders, so hermetic runs do not see the host's apps.
let app_dirs = match std::env::var_os("CUA_AGENT_APP_DIRS") {
@@ -1323,7 +1346,7 @@ fn run_cli(bin: &Path, args: &[String]) -> Result<()> {
#[cfg(test)]
mod cmd_shim_tests {
- use super::cmd_shim_target;
+ use super::{HostEnv, Os, cmd_shim_target};
/// What `npm i -g @anthropic-ai/claude-code` writes (cmd-shim).
const NATIVE_SHIM: &str = "@ECHO off\r\nGOTO start\r\n:find_dp0\r\nSET dp0=%~dp0\r\nEXIT /b\r\n:start\r\nSETLOCAL\r\nCALL :find_dp0\r\n\"%dp0%\\node_modules\\@anthropic-ai\\claude-code\\bin\\claude.exe\" %*\r\n";
@@ -1341,6 +1364,19 @@ mod cmd_shim_tests {
d
}
+ #[test]
+ fn the_current_env_also_searches_the_usual_install_dirs() {
+ let env = HostEnv::current();
+ if env.os != Os::Windows {
+ let home = env.home.clone();
+ assert!(env.path.contains(&home.join(".local/bin")));
+ assert!(
+ env.path
+ .contains(&std::path::PathBuf::from("/opt/homebrew/bin"))
+ );
+ }
+ }
+
#[test]
fn an_npm_shim_resolves_to_the_native_claude() {
let d = npm_dir(NATIVE_SHIM, true);
diff --git a/libs/cua/crates/cua-spaces-ffi/src/app_core.rs b/libs/cua/crates/cua-spaces-ffi/src/app_core.rs
index dae058ab89..3c1cde8569 100644
--- a/libs/cua/crates/cua-spaces-ffi/src/app_core.rs
+++ b/libs/cua/crates/cua-spaces-ffi/src/app_core.rs
@@ -2258,10 +2258,11 @@ pub fn app_agent_setup_summary(
/// The SDK's agent detection as the app core reads it.
#[uniffi::export]
pub fn app_agent_setup_status(info: cua_sdk::AgentInfo) -> AppAgentSetupStatus {
+ let installed = agent_really_installed(&info);
AppAgentSetupStatus {
id: info.id,
name: info.name,
- installed: info.installed,
+ installed,
skills_dir: info.skills_dir,
mcp_config: info.mcp_config,
cua_configured: info.cua_configured,
@@ -2271,6 +2272,18 @@ pub fn app_agent_setup_status(info: cua_sdk::AgentInfo) -> AppAgentSetupStatus {
}
}
+/// Whether first-run onboarding should treat the agent as installed: its
+/// program (`bin:`) or app bundle (`app:`) was found. A leftover or
+/// cua-created config folder alone (`path:`) is not enough: the AI agents
+/// step ticks and sets up only agents the user actually has (CUA-1771).
+fn agent_really_installed(info: &cua_sdk::AgentInfo) -> bool {
+ info.installed
+ && info
+ .evidence
+ .iter()
+ .any(|e| e.starts_with("bin:") || e.starts_with("app:"))
+}
+
/// The SDK's setup outcome as the app core reads it.
#[uniffi::export]
pub fn app_agent_setup_outcome(outcome: cua_sdk::AgentSetupOutcome) -> AppAgentSetupOutcomeInput {
@@ -2936,3 +2949,46 @@ mod relay_usage_tests {
assert_eq!(plain.upgrade_url, None);
}
}
+
+#[cfg(test)]
+mod agent_detection_tests {
+ use super::*;
+
+ fn info(id: &str, installed: bool, evidence: &[&str]) -> cua_sdk::AgentInfo {
+ cua_sdk::AgentInfo {
+ id: id.into(),
+ name: id.into(),
+ installed,
+ evidence: evidence.iter().map(|e| e.to_string()).collect(),
+ skills_dir: None,
+ mcp_config: None,
+ mcp_format: None,
+ cua_configured: false,
+ cua_managed: false,
+ cua_driver_configured: false,
+ skills_installed: vec![],
+ skills_outdated: vec![],
+ error: None,
+ unverified: None,
+ }
+ }
+
+ /// Onboarding only ticks agents whose program or app is on the machine;
+ /// a leftover config folder is not an install (CUA-1771).
+ #[test]
+ fn onboarding_counts_a_program_or_an_app_not_a_config_folder() {
+ let s = |i| app_agent_setup_status(i).installed;
+ assert!(s(info(
+ "claude-code",
+ true,
+ &["bin:/usr/local/bin/claude", "path:/h/.claude"]
+ )));
+ assert!(s(info(
+ "vscode",
+ true,
+ &["app:/Applications/Visual Studio Code.app"]
+ )));
+ assert!(!s(info("copilot-cli", true, &["path:/h/.copilot"])));
+ assert!(!s(info("gemini-cli", false, &[])));
+ }
+}