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.

fix(cua-cli): Cua Spaces uninstall leaves Cua Driver's agent entries alone (CUA-2223) (#5891)

cua-agents[bot]d68aaf216d2d
diff --git a/docs/content/docs/cua-cli/guides/mcp-server.mdx b/docs/content/docs/cua-cli/guides/mcp-server.mdx
index 19df6e4c0f..4e89773d67 100644
--- a/docs/content/docs/cua-cli/guides/mcp-server.mdx
+++ b/docs/content/docs/cua-cli/guides/mcp-server.mdx
@@ -25,7 +25,10 @@ can pass its own `sandbox`. Every tool is listed in
`cua agents setup --agents <id>` installs the cua skills and adds the `cua`
server to these user-level configs. It keeps your other servers and comments,
-and `cua agents remove` takes out only what cua added.
+and `cua agents remove` takes out only what cua added for Cua Spaces: the `cua`
+server and the Cua Spaces skills. Cua Driver's `cua-driver` server and skill stay
+(`--include-cua-driver` removes them too), and `cua agents remove --dry-run` lists
+exactly what it would remove.
| Agent | id | Skills | MCP config |
|-------|----|--------|------------|
diff --git a/docs/content/docs/cua-cli/reference/cli/agents.mdx b/docs/content/docs/cua-cli/reference/cli/agents.mdx
index 40d4d17b8e..68a065e777 100644
--- a/docs/content/docs/cua-cli/reference/cli/agents.mdx
+++ b/docs/content/docs/cua-cli/reference/cli/agents.mdx
@@ -49,7 +49,7 @@ description: "Run coding agents in a sandbox, set up your AI agents, the stdio M
| [`cua agents detect`](#cua-agents-detect) | List supported AI coding agents and which are installed (read-only). |
| [`cua agents setup`](#cua-agents-setup) | Install the default cua skills and configure the cua MCP server. |
| [`cua agents status`](#cua-agents-status) | What cua configured for each agent. |
-| [`cua agents remove`](#cua-agents-remove) | Remove the skills and MCP entries cua added (nothing else). |
+| [`cua agents remove`](#cua-agents-remove) | Remove the Cua Spaces skills and MCP entries cua added (nothing else). |
| [`cua agents update`](#cua-agents-update) | Refresh installed cua skills and managed MCP entries to this version. |
| [`cua mcp`](#cua-mcp) | Stdio MCP server exposing sandboxes, computer control and skills. |
| [`cua skills`](#cua-skills) | Recorded demonstrations (skills) for agents. |
@@ -816,7 +816,7 @@ cua agents status
### `cua agents remove`
-Remove the skills and MCP entries cua added (nothing else).
+Remove the Cua Spaces skills and MCP entries cua added (nothing else).
```text output
cua agents remove [OPTIONS]
@@ -828,12 +828,19 @@ cua agents remove [OPTIONS]
| <span id="cua-agents-remove--skills-only"></span>`--skills-only` | | boolean | `false` | Only remove skills. |
| <span id="cua-agents-remove--mcp-only"></span>`--mcp-only` | | boolean | `false` | Only remove the MCP entry. |
| <span id="cua-agents-remove--yes"></span>`--yes` | `-y` | boolean | `false` | Do not ask for confirmation. |
+| <span id="cua-agents-remove--include-cua-driver"></span>`--include-cua-driver` | | boolean | `false` | Also remove Cua Driver's skill and MCP server (`cua-driver`). Without it only Cua Spaces' own entries go: the `cua` server (`cua-local` for Local) and the Cua Spaces skills. |
+| <span id="cua-agents-remove--dry-run"></span>`--dry-run` | | boolean | `false` | List exactly what would be removed and change nothing. |
**Examples**
```bash test="cli-shape" id="ref-cua-agents-remove"
+# See what would be removed, change nothing
+cua agents remove --dry-run
cua agents remove
cua agents remove --agents codex --skills-only -y
+
+# Cua Driver's skill and MCP server too (they stay otherwise)
+cua agents remove --include-cua-driver
```
### `cua agents update`
diff --git a/docs/content/docs/spaces/guides/connect-your-agent.mdx b/docs/content/docs/spaces/guides/connect-your-agent.mdx
index f1781358e0..062d467a7f 100644
--- a/docs/content/docs/spaces/guides/connect-your-agent.mdx
+++ b/docs/content/docs/spaces/guides/connect-your-agent.mdx
@@ -62,10 +62,11 @@ To connect an agent later, or to remove one, open **Settings, AI agents**:
server to each agent you name.
```bash test="cli-shape" id="cua-agents-detect"
-cua agents detect # read-only: which supported agents are installed
+cua agents detect # read-only: which supported agents are installed
cua agents setup --agents claude,codex --yes
-cua agents status # what Cua configured for each agent
-cua agents remove # removes only what Cua added
+cua agents status # what Cua configured for each agent
+cua agents remove --dry-run # lists what it would remove
+cua agents remove # removes only what Cua Spaces added (Cua Driver's entries stay)
```
The [supported agents](/cua-cli/guides/mcp-server#supported-agents) include
diff --git a/docs/content/docs/spaces/guides/uninstall.mdx b/docs/content/docs/spaces/guides/uninstall.mdx
index bfd189b12f..23c831001b 100644
--- a/docs/content/docs/spaces/guides/uninstall.mdx
+++ b/docs/content/docs/spaces/guides/uninstall.mdx
@@ -24,7 +24,8 @@ again any time: a computer that has nothing left, or only part of Cua, is fine.
</Tabs>
To see what it would do first, add `--dry-run` (`-DryRun` on Windows). It prints
-every step and changes nothing:
+every step, lists the skills and MCP entries it would take out of each of your AI
+agents, and changes nothing:
```bash skip="destructive"
curl -fsSL https://cua.ai/uninstall.sh | sh -s -- --dry-run
@@ -37,8 +38,9 @@ curl -fsSL https://cua.ai/uninstall.sh | sh -s -- --dry-run
PATH on Windows).
- The host service, after `cua host remove`, so this computer no longer shows up
as a computer in your account.
-- The Cua skills and MCP entries in your AI agents, the way `cua agents remove`
- does. Entries from other tools stay.
+- The Cua Spaces skills and the `cua` MCP server in your AI agents, the way
+ `cua agents remove` does. Entries from other tools stay, and so do Cua Driver's
+ `cua-driver` skill and MCP server (see [Other Cua tools](#other-cua-tools)).
- Launch at login.
- Your sign-in and the device key: macOS Keychain items (including the old
`run.cua.ai` one), Windows Credential Manager entries.
@@ -74,7 +76,7 @@ It lists the Spaces, stops the running ones, and asks you to type `delete`.
|-----------------|---------|--------|
| `--keep-data` | `-KeepData` | Keep `~/.cua` and the app's settings. |
| `--delete-spaces` | `-DeleteSpaces` | Also delete Spaces and their data (not together with `--keep-data`). |
-| `--all` | `-All` | Also run the Cua Driver uninstaller and, on macOS, the Lume one. Lume keeps your VMs unless `--delete-spaces` is given too. |
+| `--all` | `-All` | Also run the Cua Driver uninstaller (and take its skill and MCP server out of your agents) and, on macOS, the Lume uninstaller. Lume keeps your VMs unless `--delete-spaces` is given too. |
| `--prefix DIR` | `-Prefix DIR` | Also remove what `install.sh --prefix DIR` installed. |
| `--no-modify-path` | `-NoModifyPath` | Never edit your shell profile or user PATH. |
| `--dry-run` | `-DryRun` | Print what would be removed, change nothing. |
@@ -83,7 +85,9 @@ It lists the Spaces, stops the running ones, and asks you to type `delete`.
## Other Cua tools
Cua Driver and Lume are separate products. The command above leaves them alone
-and says so. Add `--all` to remove them too, or run their own uninstallers:
+and says so, and that includes the `cua-driver` skill and MCP server in your AI
+agents: Claude Code, Codex, Cursor and the others keep using Cua Driver. Add
+`--all` to remove them too, or run their own uninstallers:
```bash skip="destructive"
/bin/bash -c "$(curl -fsSL https://cua.ai/driver/uninstall.sh)"
@@ -94,6 +98,18 @@ The Cua Driver uninstaller keeps its macOS permissions (Accessibility and Screen
Recording), so installing it again needs no new approval. To revoke them as
well, add `--reset-permissions` to its command.
+To remove the same entries without the uninstaller, run
+`cua agents remove --dry-run` to see them, then `cua agents remove`. Add
+`--include-cua-driver` to take Cua Driver's skill and MCP server out as well.
+
+With an older `cua`, one that has no `--dry-run` or `--include-cua-driver` on
+`cua agents remove`, the uninstaller skips that one step, because the older
+command also took out Cua Driver's skill and MCP server. It removes everything
+else as usual, finishes normally, and tells you that the `cua` MCP server and the
+Cua Spaces skills are still in your agents. To take them out, install the latest
+`cua` (`curl -fsSL https://cua.ai/install.sh | sh -s -- --cli-only --yes`) and run
+`cua agents remove`.
+
## If a step needs your attention
The command says what to run for anything it could not remove, and exits with a
diff --git a/libs/cua/crates/cua-agent-setup/README.md b/libs/cua/crates/cua-agent-setup/README.md
index 8afb0ec30d..11003684e7 100644
--- a/libs/cua/crates/cua-agent-setup/README.md
+++ b/libs/cua/crates/cua-agent-setup/README.md
@@ -27,8 +27,12 @@ server (`cua mcp`) in their MCP configs. Used by `cua agents ...`,
- **State**: `~/.cua/agent-setup.json` (or `$CUA_HOME`) records each entry and
skill folder cua wrote. `remove` deletes only entries that still hold the
value cua wrote (restoring a pre-existing non-cua entry of the same name)
- and only skill folders nobody edited. `update` refreshes skill folders cua
- owns and re-points managed MCP entries.
+ and only skill folders nobody edited. It removes Cua Spaces' entries only
+ (the `cua` server, `cua-local` for Local, and the Cua Spaces skills): Cua
+ Driver's `cua-driver` server and skill (`cua-driver-local` for Local) stay
+ unless `remove_with` is given `include_cua_driver`, and `dry_run` returns
+ the rows a real run would produce without writing. `update` refreshes skill
+ folders cua owns and re-points managed MCP entries.
- **Host safety**: everything resolves from a `HostEnv` (HOME, XDG and agent
override variables, PATH, app folders). `HostEnv::isolated(home)` is fully
hermetic; all tests use it with a temporary home.
diff --git a/libs/cua/crates/cua-agent-setup/src/lib.rs b/libs/cua/crates/cua-agent-setup/src/lib.rs
index 95261ddd50..bd058f8f33 100644
--- a/libs/cua/crates/cua-agent-setup/src/lib.rs
+++ b/libs/cua/crates/cua-agent-setup/src/lib.rs
@@ -339,6 +339,17 @@ pub const DRIVER_MCP_SERVER_NAME: &str = "cua-driver";
/// The bundled skill that teaches agents cua-driver.
pub const DRIVER_SKILL: &str = "cua-driver";
+/// Whether `name` (an MCP server or a skill folder) belongs to Cua Driver,
+/// not to Cua Spaces: `cua-driver`, and its siblings `cua-driver-local` (the
+/// Local channel's skill copy and driver) and `cua-driver-rs` (the old skill
+/// pack name). `cua agents remove` leaves them in place unless asked
+/// ([`RemoveOptions::include_cua_driver`]): Cua Driver is a separate product
+/// with its own uninstaller, and uninstalling Cua Spaces must not break the
+/// user's agents' computer-use.
+pub fn is_cua_driver_name(name: &str) -> bool {
+ name == DRIVER_MCP_SERVER_NAME || name.starts_with("cua-driver-")
+}
+
/// The name the retired Spaces Python MCP server (`spaces_mcp.py`, replaced
/// by `cua daemon mcp`) was registered under by older Spaces app builds.
pub const LEGACY_SPACES_MCP_NAME: &str = "cua-spaces";
@@ -538,6 +549,20 @@ impl Parts {
};
}
+/// The `Skipped` detail of a Cua Driver entry `remove` leaves in place.
+pub const KEPT_CUA_DRIVER: &str = "Cua Driver's; --include-cua-driver removes it";
+
+/// How [`AgentSetup::remove_with`] runs.
+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
+pub struct RemoveOptions {
+ /// Also remove Cua Driver's entries (the `cua-driver` MCP server and
+ /// skill, [`is_cua_driver_name`]). Off by default: they are not Cua
+ /// Spaces', and they stay.
+ pub include_cua_driver: bool,
+ /// Change nothing: return the outcomes a real run would produce.
+ pub dry_run: bool,
+}
+
/// The onboarding engine.
#[derive(Clone, Debug)]
pub struct AgentSetup {
@@ -1146,11 +1171,27 @@ impl AgentSetup {
Ok(())
}
- /// Undoes what cua wrote for `agents`: MCP entries that still hold the
- /// exact value cua wrote (the entry that was there before, if any, is
- /// restored), and skill folders cua installed and nobody edited (a
- /// folder shared with an agent not being removed stays).
+ /// Undoes what cua wrote for `agents`, for Cua Spaces only: MCP entries
+ /// that still hold the exact value cua wrote (the entry that was there
+ /// before, if any, is restored), and skill folders cua installed and
+ /// nobody edited (a folder shared with an agent not being removed stays).
+ /// Cua Driver's entries (`cua-driver`) stay; see
+ /// [`AgentSetup::remove_with`] to remove them too.
pub fn remove(&self, agents: &[String], parts: Parts) -> Result<Vec<Outcome>> {
+ self.remove_with(agents, parts, RemoveOptions::default())
+ }
+
+ /// [`AgentSetup::remove`] with options: `include_cua_driver` removes the
+ /// `cua-driver` server and skill too (otherwise each gets a `Skipped` row
+ /// that says it was kept), and `dry_run` writes nothing and returns the
+ /// rows a real run would produce, so a preview lists exactly what the
+ /// run removes.
+ pub fn remove_with(
+ &self,
+ agents: &[String],
+ parts: Parts,
+ opts: RemoveOptions,
+ ) -> Result<Vec<Outcome>> {
let specs = self.specs(agents)?;
let mut state = State::load(&self.state_path)?;
let mut out = Vec::new();
@@ -1183,7 +1224,12 @@ impl AgentSetup {
detail: String::new(),
backup: None,
};
- if let Err(e) = self.remove_mcp(&mut state, a, m, &file, &name, &mut o) {
+ if is_cua_driver_name(&name) && !opts.include_cua_driver {
+ o.detail = KEPT_CUA_DRIVER.into();
+ out.push(o);
+ continue;
+ }
+ if let Err(e) = self.remove_mcp(&mut state, a, m, &name, opts.dry_run, &mut o) {
o.change = Change::Failed;
o.detail = e.to_string();
}
@@ -1211,7 +1257,6 @@ impl AgentSetup {
if removing.is_empty() {
continue;
}
- r.agents.retain(|x| !ids.contains(x));
let mut o = Outcome {
agents: removing,
target: Target::Skill,
@@ -1221,6 +1266,12 @@ impl AgentSetup {
detail: String::new(),
backup: None,
};
+ if is_cua_driver_name(&r.skill) && !opts.include_cua_driver {
+ o.detail = KEPT_CUA_DRIVER.into();
+ out.push(o);
+ continue;
+ }
+ r.agents.retain(|x| !ids.contains(x));
if !r.agents.is_empty() {
o.detail = format!(
"kept for {}",
@@ -1234,16 +1285,23 @@ impl AgentSetup {
o.detail = "already gone".into();
state.skills.remove(&dest);
}
- Some(h) if h == r.hash => match std::fs::remove_dir_all(&dest) {
- Ok(()) => {
- o.change = Change::Removed;
- state.skills.remove(&dest);
- }
- Err(e) => {
- o.change = Change::Failed;
- o.detail = e.to_string();
+ Some(h) if h == r.hash => {
+ let gone = if opts.dry_run {
+ Ok(())
+ } else {
+ std::fs::remove_dir_all(&dest)
+ };
+ match gone {
+ Ok(()) => {
+ o.change = Change::Removed;
+ state.skills.remove(&dest);
+ }
+ Err(e) => {
+ o.change = Change::Failed;
+ o.detail = e.to_string();
+ }
}
- },
+ }
Some(_) => {
o.detail = "edited since cua installed it; left in place".into();
state.skills.remove(&dest);
@@ -1253,7 +1311,9 @@ impl AgentSetup {
out.push(o);
}
}
- state.save(&self.state_path)?;
+ if !opts.dry_run {
+ state.save(&self.state_path)?;
+ }
Ok(out)
}
@@ -1262,10 +1322,12 @@ impl AgentSetup {
state: &mut State,
a: &AgentSpec,
m: &McpSpec,
- file: &Path,
name: &str,
+ dry_run: bool,
o: &mut Outcome,
) -> Result<()> {
+ let file = self.mcp_file(m);
+ let file = file.as_path();
// `cua`'s record may carry another name (older states).
let key = if state.mcp.get(file).is_some_and(|r| r.name == name) {
MCP_SERVER_NAME
@@ -1293,8 +1355,12 @@ impl AgentSetup {
.filter(|_| self.env.run_agent_clis)
.and_then(|c| self.env.which(c.bin()).map(|bin| (c, bin)));
if let (Some((cli, bin)), None) = (via_cli, &r.previous) {
- run_cli(&bin, &cli.remove_args(&r.name))?;
+ if !dry_run {
+ run_cli(&bin, &cli.remove_args(&r.name))?;
+ }
} else {
+ // The edit is worked out on a dry run too: one the format cannot
+ // make without losing comments fails here, as it does for real.
let new = match &r.previous {
Some(prev) => {
let fields: edit::Fields = prev
@@ -1307,7 +1373,7 @@ impl AgentSetup {
}
None => edit::remove(m.format, file, &text, m.key_path, &r.name)?,
};
- if let Some(new) = new {
+ if let (Some(new), false) = (new, dry_run) {
fsutil::atomic_write(file, new.as_bytes())?;
}
}
diff --git a/libs/cua/crates/cua-agent-setup/tests/agents.rs b/libs/cua/crates/cua-agent-setup/tests/agents.rs
index 8e49c304a7..c4513c3c6d 100644
--- a/libs/cua/crates/cua-agent-setup/tests/agents.rs
+++ b/libs/cua/crates/cua-agent-setup/tests/agents.rs
@@ -630,17 +630,20 @@ fn skills_install_once_per_shared_dir_and_remove_only_when_unused() {
let out = s.remove(&ids(&["codex"]), Parts::ALL).unwrap();
assert!(
out.iter()
- .filter(|o| o.target == Target::Skill)
+ .filter(|o| o.target == Target::Skill && o.item != "cua-driver")
.all(|o| o.change == Change::Skipped && o.detail.starts_with("kept for"))
);
- assert!(shared.join("cua-driver").is_dir());
+ assert!(shared.join("cua-volume").is_dir());
// A user edit survives removal.
std::fs::write(shared.join("cua-spaces/NOTES.md"), "mine").unwrap();
s.remove(&ids(&["gemini-cli", "pi"]), Parts::ALL).unwrap();
- assert!(!shared.join("cua-driver").exists());
+ assert!(!shared.join("cua-volume").exists());
assert!(shared.join("cua-spaces/NOTES.md").is_file());
- // Claude's copies are untouched by removing other agents.
+ // Cua Driver's skill is not Cua Spaces': removing Spaces' entries leaves
+ // it, here and in Claude's copies (untouched by removing other agents).
+ assert!(shared.join("cua-driver").is_dir());
+ assert!(t.home.join(".claude/skills/cua-volume").is_dir());
assert!(t.home.join(".claude/skills/cua-driver").is_dir());
}
@@ -680,9 +683,10 @@ fn agents_that_also_read_claude_skills_are_served_from_there() {
// Removing Claude Code keeps the copies Cursor and OpenCode use.
s.remove(&ids(&["claude-code"]), Parts::ALL).unwrap();
- assert!(claude.join("cua-driver").is_dir());
+ assert!(claude.join("cua-volume").is_dir());
s.remove(&ids(&["cursor", "opencode"]), Parts::ALL).unwrap();
- assert!(!claude.join("cua-driver").exists());
+ assert!(!claude.join("cua-volume").exists());
+ assert!(claude.join("cua-driver").is_dir(), "Cua Driver's stays");
}
#[test]
@@ -912,7 +916,8 @@ fn cua_driver_setup_adds_its_skill_and_server_beside_cua_and_removes_both() {
"/opt/drv/bin/cua-driver"
);
- // Remove undoes both entries and the skill; the unrelated server stays.
+ // Plain remove undoes Cua Spaces' entry only: Cua Driver's server and
+ // skill stay, with a row each that says so.
let removed = s
.remove(&ids(&["claude-code", "codex"]), Parts::ALL)
.unwrap();
@@ -923,11 +928,47 @@ fn cua_driver_setup_adds_its_skill_and_server_beside_cua_and_removes_both() {
.collect();
assert_eq!(
names,
- [("cua", Change::Removed), ("cua-driver", Change::Removed)]
+ [("cua", Change::Removed), ("cua-driver", Change::Skipped)]
+ );
+ assert!(
+ removed
+ .iter()
+ .filter(|o| o.item == "cua-driver")
+ .all(|o| o.change == Change::Skipped && o.detail == cua_agent_setup::KEPT_CUA_DRIVER),
+ "{removed:#?}"
+ );
+ let left = t.read(&file);
+ assert!(cua_agent_setup_get(m.format, &file, &left, m.key_path, "cua").is_none());
+ assert!(cua_agent_setup_get(m.format, &file, &left, m.key_path, "cua-driver").is_some());
+ assert!(cua_agent_setup_get(m.format, &file, &left, m.key_path, "other").is_some());
+ assert!(t.home.join(".claude/skills/cua-driver/SKILL.md").is_file());
+ let state: Value = serde_json::from_str(&t.read(s.state_path())).unwrap();
+ assert!(state["servers"]["cua-driver"][&key].is_object(), "{state}");
+
+ // Asked for, remove undoes Cua Driver's entries and skill as well.
+ let removed = s
+ .remove_with(
+ &ids(&["claude-code", "codex"]),
+ Parts::ALL,
+ cua_agent_setup::RemoveOptions {
+ include_cua_driver: true,
+ dry_run: false,
+ },
+ )
+ .unwrap();
+ // (Codex's shared skills folder is also Pi's, who is not being removed.)
+ assert!(
+ removed
+ .iter()
+ .filter(|o| o.item == "cua-driver"
+ && (o.target == Target::Mcp || o.agents == ["claude-code"]))
+ .all(|o| o.change == Change::Removed),
+ "{removed:#?}"
);
let left = t.read(&file);
assert!(cua_agent_setup_get(m.format, &file, &left, m.key_path, "cua-driver").is_none());
assert!(cua_agent_setup_get(m.format, &file, &left, m.key_path, "other").is_some());
+ assert!(!t.home.join(".claude/skills/cua-driver").exists());
let state: Value = serde_json::from_str(&t.read(s.state_path())).unwrap();
assert!(state.get("servers").is_none(), "{state}");
@@ -1171,10 +1212,11 @@ fn hermes_gets_its_own_skill_copies() {
let out = s.remove(&ids(&["hermes"]), Parts::ALL).unwrap();
assert!(
out.iter()
- .filter(|o| o.target == Target::Skill)
+ .filter(|o| o.target == Target::Skill && o.item != "cua-driver")
.all(|o| o.change == Change::Removed)
);
assert!(!dir.join("cua-spaces").exists());
+ assert!(dir.join("cua-driver").is_dir(), "Cua Driver's stays");
assert!(t.home.join(".agents/skills/cua-spaces/SKILL.md").is_file());
}
diff --git a/libs/cua/crates/cua-agent-setup/tests/remove_keeps_cua_driver.rs b/libs/cua/crates/cua-agent-setup/tests/remove_keeps_cua_driver.rs
new file mode 100644
index 0000000000..6c03af5d0c
--- /dev/null
+++ b/libs/cua/crates/cua-agent-setup/tests/remove_keeps_cua_driver.rs
@@ -0,0 +1,528 @@
+//! Removing Cua Spaces' agent entries never takes Cua Driver's with them.
+//!
+//! `cua agents remove` (and the uninstaller that runs it) removes the `cua`
+//! MCP server (`cua-local` for Local) and the Cua Spaces skills. The
+//! `cua-driver` server and the `cua-driver` skill are Cua Driver's: they stay,
+//! as does everything of other tools, unless `include_cua_driver` asks. A
+//! dry run returns exactly the rows a real run produces and writes nothing.
+//! Configs in the formats of Claude Code (JSON), Codex (TOML) and Cursor
+//! (JSON), in a temporary HOME, never the real one.
+
+use cua_agent_setup::{
+ AgentSetup, Change, CuaChannel, HostEnv, KEPT_CUA_DRIVER, McpServer, Outcome, Parts,
+ RemoveOptions, Target, hash_dir, is_cua_driver_name,
+};
+use std::path::{Path, PathBuf};
+
+const AGENTS: [&str; 3] = ["claude-code", "codex", "cursor"];
+
+/// The Cua Spaces skills `cua agents setup` installs next to Cua Driver's.
+const SPACES_SKILLS: [&str; 4] = [
+ "cua-sandboxes",
+ "cua-spaces",
+ "cua-volume",
+ "gui-automation",
+];
+
+struct Home {
+ _dir: tempfile::TempDir,
+ path: PathBuf,
+}
+
+impl Home {
+ /// A home whose agent configs hold one server of the user's own each.
+ fn new() -> Self {
+ let dir = tempfile::tempdir().unwrap();
+ let path = dir.path().join("home");
+ std::fs::create_dir_all(&path).unwrap();
+ let h = Home { _dir: dir, path };
+ h.write(
+ ".claude.json",
+ "{\n \"numStartups\": 12,\n \"mcpServers\": {\n \"other\": {\"type\": \"stdio\", \"command\": \"other-mcp\", \"args\": []}\n }\n}\n",
+ );
+ h.write(
+ ".codex/config.toml",
+ "# my codex config\n[mcp_servers.other]\ncommand = \"other-mcp\"\nargs = []\n",
+ );
+ h.write(
+ ".cursor/mcp.json",
+ "{\n \"mcpServers\": {\n \"other\": {\"command\": \"other-mcp\"}\n }\n}\n",
+ );
+ h
+ }
+
+ fn write(&self, rel: &str, text: &str) {
+ let p = self.path.join(rel);
+ std::fs::create_dir_all(p.parent().unwrap()).unwrap();
+ std::fs::write(p, text).unwrap();
+ }
+
+ fn read(&self, rel: &str) -> String {
+ std::fs::read_to_string(self.path.join(rel)).unwrap()
+ }
+
+ fn setup(&self, channel: CuaChannel) -> AgentSetup {
+ AgentSetup::new(HostEnv::isolated(&self.path).with_channel(channel))
+ }
+
+ /// Everything a remove could touch: the three configs, the state files
+ /// and every skill folder (as tree hashes).
+ fn snapshot(&self) -> Vec<(String, String)> {
+ let mut out = Vec::new();
+ for rel in [
+ ".claude.json",
+ ".codex/config.toml",
+ ".cursor/mcp.json",
+ ".cua/agent-setup.json",
+ ".cua-local/agent-setup.json",
+ ] {
+ let text = std::fs::read_to_string(self.path.join(rel)).unwrap_or_default();
+ out.push((rel.to_string(), text));
+ }
+ for dir in [".claude/skills", ".agents/skills"] {
+ let Ok(entries) = std::fs::read_dir(self.path.join(dir)) else {
+ continue;
+ };
+ for e in entries.flatten() {
+ out.push((
+ format!("{dir}/{}", e.file_name().to_string_lossy()),
+ hash_dir(&e.path()).unwrap_or_default(),
+ ));
+ }
+ }
+ out.sort();
+ out
+ }
+
+ fn skill_dir(&self, agent_dir: &str, name: &str) -> PathBuf {
+ self.path.join(agent_dir).join(name)
+ }
+}
+
+fn ids(v: &[&str]) -> Vec<String> {
+ v.iter().map(|s| s.to_string()).collect()
+}
+
+fn driver() -> McpServer {
+ McpServer::driver("/opt/drv/bin/cua-driver")
+}
+
+/// Cua Spaces' setup (default skills + the `cua` server) and Cua Driver's
+/// (its skill + the `cua-driver` server) on all three agents.
+fn set_up_both(h: &Home, channel: CuaChannel) -> AgentSetup {
+ let s = h.setup(channel);
+ s.install_skills(&ids(&AGENTS), &[], false).unwrap();
+ let server = McpServer::for_channel(channel, "/opt/cua/bin/cua");
+ s.configure_mcp(&ids(&AGENTS), &server).unwrap();
+ s.setup_cua_driver(&ids(&AGENTS), &driver(), Parts::ALL, false)
+ .unwrap();
+ s
+}
+
+fn mcp_text(h: &Home, agent: &str) -> String {
+ match agent {
+ "claude-code" => h.read(".claude.json"),
+ "codex" => h.read(".codex/config.toml"),
+ "cursor" => h.read(".cursor/mcp.json"),
+ other => panic!("{other}"),
+ }
+}
+
+/// Whether the config of `agent` has an MCP server called `name`.
+fn has_server(h: &Home, agent: &str, name: &str) -> bool {
+ let text = mcp_text(h, agent);
+ match agent {
+ "codex" => text.contains(&format!("[mcp_servers.{name}]")),
+ _ => {
+ let v: serde_json::Value = serde_json::from_str(&text).unwrap();
+ !v["mcpServers"][name].is_null()
+ }
+ }
+}
+
+fn rows(out: &[Outcome]) -> Vec<(Target, String, Change, PathBuf, Vec<String>)> {
+ out.iter()
+ .map(|o| {
+ (
+ o.target,
+ o.item.clone(),
+ o.change,
+ o.path.clone(),
+ o.agents.clone(),
+ )
+ })
+ .collect()
+}
+
+fn items(out: &[Outcome], target: Target, change: Change) -> Vec<String> {
+ let mut v: Vec<String> = out
+ .iter()
+ .filter(|o| o.target == target && o.change == change)
+ .map(|o| o.item.clone())
+ .collect();
+ v.sort();
+ v.dedup();
+ v
+}
+
+#[test]
+fn the_names_that_are_cua_drivers() {
+ for n in ["cua-driver", "cua-driver-local", "cua-driver-rs"] {
+ assert!(is_cua_driver_name(n), "{n}");
+ }
+ for n in [
+ "cua",
+ "cua-local",
+ "cua-spaces",
+ "cua-spaces-local",
+ "cua-volume",
+ "cua-drivers",
+ "cua-driver2",
+ "other",
+ "",
+ ] {
+ assert!(!is_cua_driver_name(n), "{n}");
+ }
+}
+
+#[test]
+fn remove_takes_cua_spaces_entries_and_leaves_cua_driver_in_every_agent() {
+ let h = Home::new();
+ let s = set_up_both(&h, CuaChannel::Stable);
+ for a in AGENTS {
+ assert!(has_server(&h, a, "cua"), "{a}");
+ assert!(has_server(&h, a, "cua-driver"), "{a}");
+ }
+ let driver_entry_before: Vec<String> = AGENTS.iter().map(|a| mcp_text(&h, a)).collect();
+
+ let out = s.remove(&ids(&AGENTS), Parts::ALL).unwrap();
+
+ for a in AGENTS {
+ assert!(!has_server(&h, a, "cua"), "{a}: the cua server goes");
+ assert!(has_server(&h, a, "cua-driver"), "{a}: cua-driver stays");
+ assert!(has_server(&h, a, "other"), "{a}: the user's own stays");
+ }
+ // Only the `cua` entry left each config: nothing else changed in it.
+ for (a, before) in AGENTS.iter().zip(&driver_entry_before) {
+ let after = mcp_text(&h, a);
+ assert!(after.len() < before.len(), "{a}");
+ assert!(after.contains("/opt/drv/bin/cua-driver"), "{a}: {after}");
+ }
+ for dir in [".claude/skills", ".agents/skills"] {
+ for name in SPACES_SKILLS {
+ assert!(!h.skill_dir(dir, name).exists(), "{dir}/{name} stays");
+ }
+ assert!(
+ h.skill_dir(dir, "cua-driver").join("SKILL.md").is_file(),
+ "{dir}/cua-driver was removed"
+ );
+ }
+ // What was removed is exactly the cua server and the Spaces skills.
+ assert_eq!(items(&out, Target::Mcp, Change::Removed), ["cua"]);
+ assert_eq!(
+ items(&out, Target::Skill, Change::Removed),
+ SPACES_SKILLS.map(String::from)
+ );
+ // And what stayed says so, per agent and skill folder.
+ assert_eq!(items(&out, Target::Mcp, Change::Skipped), ["cua-driver"]);
+ assert_eq!(items(&out, Target::Skill, Change::Skipped), ["cua-driver"]);
+ assert!(
+ out.iter()
+ .filter(|o| o.item == "cua-driver")
+ .all(|o| o.change == Change::Skipped && o.detail == KEPT_CUA_DRIVER),
+ "{out:#?}"
+ );
+ assert!(out.iter().all(|o| !o.failed()), "{out:#?}");
+
+ // Cua Driver's records survive in the state, so a later explicit remove
+ // still finds them.
+ let state = h.read(".cua/agent-setup.json");
+ assert!(state.contains("\"servers\""), "{state}");
+ assert!(state.contains("cua-driver"), "{state}");
+}
+
+#[test]
+fn a_dry_run_lists_exactly_what_a_real_run_removes_and_changes_nothing() {
+ for include_cua_driver in [false, true] {
+ let h = Home::new();
+ let s = set_up_both(&h, CuaChannel::Stable);
+ let before = h.snapshot();
+
+ let plan = s
+ .remove_with(
+ &ids(&AGENTS),
+ Parts::ALL,
+ RemoveOptions {
+ include_cua_driver,
+ dry_run: true,
+ },
+ )
+ .unwrap();
+ assert_eq!(h.snapshot(), before, "a dry run wrote something");
+ assert!(
+ plan.iter().any(|o| o.change == Change::Removed),
+ "{plan:#?}"
+ );
+
+ let done = s
+ .remove_with(
+ &ids(&AGENTS),
+ Parts::ALL,
+ RemoveOptions {
+ include_cua_driver,
+ dry_run: false,
+ },
+ )
+ .unwrap();
+ assert_ne!(h.snapshot(), before, "a real run removed nothing");
+ assert_eq!(rows(&plan), rows(&done), "include={include_cua_driver}");
+ assert_eq!(
+ plan.iter()
+ .filter(|o| o.change == Change::Removed)
+ .any(|o| o.item == "cua-driver"),
+ include_cua_driver
+ );
+ }
+}
+
+#[test]
+fn asking_for_cua_driver_removes_its_server_and_skill_too() {
+ let h = Home::new();
+ let s = set_up_both(&h, CuaChannel::Stable);
+ let out = s
+ .remove_with(
+ &ids(&AGENTS),
+ Parts::ALL,
+ RemoveOptions {
+ include_cua_driver: true,
+ dry_run: false,
+ },
+ )
+ .unwrap();
+ for a in AGENTS {
+ assert!(!has_server(&h, a, "cua"), "{a}");
+ assert!(!has_server(&h, a, "cua-driver"), "{a}");
+ assert!(has_server(&h, a, "other"), "{a}");
+ }
+ for dir in [".claude/skills", ".agents/skills"] {
+ assert!(!h.skill_dir(dir, "cua-driver").exists(), "{dir}");
+ }
+ assert_eq!(
+ items(&out, Target::Mcp, Change::Removed),
+ ["cua", "cua-driver"]
+ );
+ assert!(
+ out.iter()
+ .all(|o| o.change != Change::Skipped || o.detail != KEPT_CUA_DRIVER)
+ );
+ // Codex's config is back to what the user had.
+ assert_eq!(
+ h.read(".codex/config.toml"),
+ "# my codex config\n[mcp_servers.other]\ncommand = \"other-mcp\"\nargs = []\n"
+ );
+}
+
+#[test]
+fn the_mcp_only_and_skills_only_parts_keep_cua_driver_too() {
+ let h = Home::new();
+ let s = set_up_both(&h, CuaChannel::Stable);
+ s.remove(
+ &ids(&AGENTS),
+ Parts {
+ skills: false,
+ mcp: true,
+ },
+ )
+ .unwrap();
+ for a in AGENTS {
+ assert!(!has_server(&h, a, "cua"), "{a}");
+ assert!(has_server(&h, a, "cua-driver"), "{a}");
+ }
+ assert!(h.skill_dir(".claude/skills", "cua-spaces").is_dir());
+
+ s.remove(
+ &ids(&AGENTS),
+ Parts {
+ skills: true,
+ mcp: false,
+ },
+ )
+ .unwrap();
+ assert!(!h.skill_dir(".claude/skills", "cua-spaces").exists());
+ assert!(h.skill_dir(".claude/skills", "cua-driver").is_dir());
+ for a in AGENTS {
+ assert!(has_server(&h, a, "cua-driver"), "{a}");
+ }
+}
+
+#[test]
+fn cua_driver_entries_cua_never_wrote_are_never_touched() {
+ let h = Home::new();
+ // Added by the driver's own installer, not by cua: no state record.
+ h.write(
+ ".claude.json",
+ "{\n \"mcpServers\": {\n \"cua-driver\": {\"type\": \"stdio\", \"command\": \"/Applications/CuaDriver.app/Contents/MacOS/cua-driver\", \"args\": [\"mcp\"]},\n \"cua-driver-local\": {\"type\": \"stdio\", \"command\": \"cua-driver-local\", \"args\": [\"mcp\"]}\n }\n}\n",
+ );
+ let s = h.setup(CuaChannel::Stable);
+ s.configure_mcp(&ids(&["claude-code"]), &McpServer::new("/opt/cua/bin/cua"))
+ .unwrap();
+ for include_cua_driver in [false, true] {
+ let out = s
+ .remove_with(
+ &ids(&["claude-code"]),
+ Parts::ALL,
+ RemoveOptions {
+ include_cua_driver,
+ dry_run: false,
+ },
+ )
+ .unwrap();
+ assert!(
+ out.iter()
+ .all(|o| !is_cua_driver_name(&o.item) || o.change != Change::Removed),
+ "{out:#?}"
+ );
+ assert!(has_server(&h, "claude-code", "cua-driver"));
+ assert!(has_server(&h, "claude-code", "cua-driver-local"));
+ }
+ assert!(!has_server(&h, "claude-code", "cua"));
+}
+
+#[test]
+fn local_removes_cua_local_and_leaves_cua_driver_and_cua_driver_local() {
+ let h = Home::new();
+ let local = h.setup(CuaChannel::Local);
+ local.install_skills(&ids(&AGENTS), &[], false).unwrap();
+ local
+ .configure_mcp(
+ &ids(&AGENTS),
+ &McpServer::for_channel(CuaChannel::Local, "/opt/cua/bin/cua-local"),
+ )
+ .unwrap();
+ local
+ .setup_cua_driver(&ids(&AGENTS), &driver(), Parts::ALL, false)
+ .unwrap();
+ for a in AGENTS {
+ assert!(has_server(&h, a, "cua-local"), "{a}");
+ assert!(has_server(&h, a, "cua-driver"), "{a}");
+ }
+ assert!(h.skill_dir(".claude/skills", "cua-driver-local").is_dir());
+
+ let plan = local
+ .remove_with(
+ &ids(&AGENTS),
+ Parts::ALL,
+ RemoveOptions {
+ include_cua_driver: false,
+ dry_run: true,
+ },
+ )
+ .unwrap();
+ assert_eq!(items(&plan, Target::Mcp, Change::Removed), ["cua-local"]);
+ assert!(
+ !items(&plan, Target::Skill, Change::Removed).contains(&"cua-driver-local".to_string()),
+ "{plan:#?}"
+ );
+
+ let out = local.remove(&ids(&AGENTS), Parts::ALL).unwrap();
+ assert_eq!(rows(&plan), rows(&out));
+ for a in AGENTS {
+ assert!(!has_server(&h, a, "cua-local"), "{a}");
+ assert!(has_server(&h, a, "cua-driver"), "{a}");
+ assert!(has_server(&h, a, "other"), "{a}");
+ }
+ assert!(!h.skill_dir(".claude/skills", "cua-spaces-local").exists());
+ assert!(
+ h.skill_dir(".claude/skills", "cua-driver-local")
+ .join("SKILL.md")
+ .is_file(),
+ "Cua Driver's Local skill was removed"
+ );
+ // The Local skill is Cua Driver's: it goes only when asked.
+ let out = local
+ .remove_with(
+ &ids(&AGENTS),
+ Parts::ALL,
+ RemoveOptions {
+ include_cua_driver: true,
+ dry_run: false,
+ },
+ )
+ .unwrap();
+ assert!(
+ items(&out, Target::Skill, Change::Removed).contains(&"cua-driver-local".to_string()),
+ "{out:#?}"
+ );
+ assert!(!h.skill_dir(".claude/skills", "cua-driver-local").exists());
+}
+
+#[test]
+fn a_dry_run_on_a_clean_home_has_nothing_to_remove() {
+ let h = Home::new();
+ let before = h.snapshot();
+ let out = h
+ .setup(CuaChannel::Stable)
+ .remove_with(
+ &ids(&AGENTS),
+ Parts::ALL,
+ RemoveOptions {
+ include_cua_driver: true,
+ dry_run: true,
+ },
+ )
+ .unwrap();
+ assert!(out.iter().all(|o| o.change == Change::Skipped), "{out:#?}");
+ assert_eq!(h.snapshot(), before);
+ assert!(!Path::new(&h.path.join(".cua/agent-setup.json")).exists());
+}
+
+/// A dry run works the edit out as a real run does: a managed entry the format
+/// cannot be edited around without losing the user's comments (a flow-style
+/// YAML mapping beside comments) fails in both, and the file is not touched.
+#[test]
+fn a_dry_run_reports_the_same_failure_as_the_real_run_for_an_edit_the_format_refuses() {
+ let h = Home::new();
+ let config = ".hermes/config.yaml";
+ h.write(
+ config,
+ "# my hermes config\nmcp_servers:\n other:\n command: other-mcp # mine\n args: []\n",
+ );
+ let s = h.setup(CuaChannel::Stable);
+ s.configure_mcp(&ids(&["hermes"]), &McpServer::new("/opt/cua/bin/cua"))
+ .unwrap();
+ // The user tidies the whole mapping into one flow-style line, keeping the
+ // entry's value and the comment.
+ let written = h.read(config);
+ assert!(
+ written.contains(" cua:\n command: /opt/cua/bin/cua\n args:\n - mcp\n"),
+ "{written}"
+ );
+ let reflowed = "# my hermes config\nmcp_servers: {other: {command: other-mcp, args: []}, cua: {command: /opt/cua/bin/cua, args: [mcp]}}\n".to_string();
+ h.write(config, &reflowed);
+ let state = h.read(".cua/agent-setup.json");
+
+ let plan = s
+ .remove_with(
+ &ids(&["hermes"]),
+ Parts::ALL,
+ RemoveOptions {
+ include_cua_driver: false,
+ dry_run: true,
+ },
+ )
+ .unwrap();
+ assert_eq!(h.read(config), reflowed);
+ assert_eq!(h.read(".cua/agent-setup.json"), state);
+ let real = s.remove(&ids(&["hermes"]), Parts::ALL).unwrap();
+ assert_eq!(h.read(config), reflowed, "the real run left the file alone");
+ assert_eq!(rows(&plan), rows(&real));
+ let cua = |out: &[Outcome]| {
+ out.iter()
+ .find(|o| o.target == Target::Mcp && o.item == "cua")
+ .cloned()
+ .unwrap()
+ };
+ assert_eq!(cua(&real).change, Change::Failed, "{real:#?}");
+ assert_eq!(cua(&plan).change, Change::Failed, "{plan:#?}");
+ assert_eq!(cua(&plan).detail, cua(&real).detail);
+}
diff --git a/libs/cua/crates/cua-cli/src/agents.rs b/libs/cua/crates/cua-cli/src/agents.rs
index 0df602e7f5..0f787c78c9 100644
--- a/libs/cua/crates/cua-cli/src/agents.rs
+++ b/libs/cua/crates/cua-cli/src/agents.rs
@@ -3,7 +3,9 @@
use crate::util::{self, internal, line};
use clap::{Args, Subcommand};
-use cua_agent_setup::{AgentSetup, AgentStatus, Change, McpServer, Outcome, Parts, Target};
+use cua_agent_setup::{
+ AgentSetup, AgentStatus, Change, McpServer, Outcome, Parts, RemoveOptions, Target,
+};
use cua_sdk::CuaError;
use std::{
collections::BTreeSet,
@@ -34,10 +36,14 @@ pub enum AgentsCmd {
#[command(after_help = "Examples:
cua agents status")]
Status,
- /// Remove the skills and MCP entries cua added (nothing else).
+ /// Remove the Cua Spaces skills and MCP entries cua added (nothing else).
#[command(after_help = "Examples:
+ # See what would be removed, change nothing
+ cua agents remove --dry-run
cua agents remove
- cua agents remove --agents codex --skills-only -y")]
+ cua agents remove --agents codex --skills-only -y
+ # Cua Driver's skill and MCP server too (they stay otherwise)
+ cua agents remove --include-cua-driver")]
Remove(RemoveArgs),
/// Refresh installed cua skills and managed MCP entries to this version.
#[command(after_help = "Examples:
@@ -96,6 +102,14 @@ pub struct RemoveArgs {
/// Do not ask for confirmation.
#[arg(long, short = 'y')]
pub yes: bool,
+ /// Also remove Cua Driver's skill and MCP server (`cua-driver`). Without
+ /// it only Cua Spaces' own entries go: the `cua` server (`cua-local` for
+ /// Local) and the Cua Spaces skills.
+ #[arg(long)]
+ pub include_cua_driver: bool,
+ /// List exactly what would be removed and change nothing.
+ #[arg(long)]
+ pub dry_run: bool,
}
fn err(e: cua_agent_setup::Error) -> CuaError {
@@ -741,27 +755,40 @@ pub fn cmd_remove(args: &RemoveArgs, json: bool, out: &mut dyn Write) -> Result<
skills: !args.mcp_only,
mcp: !args.skills_only,
};
- let prompt = Prompt::new(args.yes || json);
- if !prompt.confirm(
- out,
- "Remove the cua skills and MCP entries that cua added?",
- false,
- ) {
- if !stdin_is_tty() && !args.yes {
- line(out, "Pass --yes to remove without a prompt.");
+ let opts = RemoveOptions {
+ include_cua_driver: args.include_cua_driver,
+ dry_run: args.dry_run,
+ };
+ if !args.dry_run {
+ let prompt = Prompt::new(args.yes || json);
+ let question = if args.include_cua_driver {
+ "Remove the Cua Spaces and Cua Driver skills and MCP entries that cua added?"
+ } else {
+ "Remove the Cua Spaces skills and MCP entries that cua added?"
+ };
+ if !prompt.confirm(out, question, false) {
+ if !stdin_is_tty() && !args.yes {
+ line(out, "Pass --yes to remove without a prompt.");
+ }
+ return Ok(1);
}
- return Ok(1);
}
- let res = setup.remove(&ids, parts).map_err(err)?;
+ let res = setup.remove_with(&ids, parts, opts).map_err(err)?;
let failed = res.iter().any(Outcome::failed);
if json {
- util::json_line(out, &serde_json::json!({"outcomes": res}));
+ util::json_line(
+ out,
+ &serde_json::json!({"dry_run": args.dry_run, "outcomes": res}),
+ );
return Ok(fail_line(&res.iter().collect::<Vec<_>>()));
}
let touched: Vec<&Outcome> = res
.iter()
.filter(|o| !(o.change == Change::Skipped && o.detail == "not configured by cua"))
.collect();
+ if args.dry_run {
+ line(out, "Dry run: nothing is changed.");
+ }
if touched.is_empty() {
line(out, "Nothing to remove.");
}
@@ -770,6 +797,24 @@ pub fn cmd_remove(args: &RemoveArgs, json: bool, out: &mut dyn Write) -> Result<
Target::Skill => format!("skill {}", o.item),
Target::Mcp => format!("MCP server {}", o.item),
};
+ let place = tilde(&setup, &o.path);
+ if o.change == Change::Skipped && o.detail == cua_agent_setup::KEPT_CUA_DRIVER {
+ line(out, format!(" - {what}: {place} kept ({})", o.detail));
+ continue;
+ }
+ if args.dry_run && o.change == Change::Removed {
+ if o.detail == "already gone" {
+ line(out, format!(" - {what}: {place} already gone"));
+ } else if o.detail == "restored the previous entry" {
+ line(
+ out,
+ format!(" would restore the previous entry of {what}: {place}"),
+ );
+ } else {
+ line(out, format!(" would remove {what}: {place}"));
+ }
+ continue;
+ }
let detail = if o.detail.is_empty() || o.detail == "removed" {
String::new()
} else {
@@ -777,12 +822,7 @@ pub fn cmd_remove(args: &RemoveArgs, json: bool, out: &mut dyn Write) -> Result<
};
line(
out,
- format!(
- " {} {what}: {} {}{detail}",
- mark(o),
- tilde(&setup, &o.path),
- change_word(o)
- ),
+ format!(" {} {what}: {place} {}{detail}", mark(o), change_word(o)),
);
}
Ok(i32::from(failed))
diff --git a/libs/cua/crates/cua-cli/tests/agents_login.rs b/libs/cua/crates/cua-cli/tests/agents_login.rs
index da7667f7ea..f8cc9bd1e3 100644
--- a/libs/cua/crates/cua-cli/tests/agents_login.rs
+++ b/libs/cua/crates/cua-cli/tests/agents_login.rs
@@ -376,7 +376,10 @@ async fn agents_commands_round_trip_and_protect_malformed_files() {
o.ok();
let codex = std::fs::read_to_string(h.dir.path().join(".codex/config.toml")).unwrap();
assert_eq!(codex, "# mine\n[mcp_servers.other]\ncommand = \"o\"\n");
- assert!(!h.dir.path().join(".agents/skills/cua-driver").exists());
+ // The default skills include Cua Driver's: it is not Cua Spaces', so it
+ // stays; the Spaces skills go.
+ assert!(!h.dir.path().join(".agents/skills/cua-spaces").exists());
+ assert!(h.dir.path().join(".agents/skills/cua-driver").is_dir());
// Unknown agents are a usage error.
let o = h
@@ -765,14 +768,193 @@ async fn agents_setup_cua_driver_adds_the_driver_skill_and_server() {
};
assert!(o.stdout.contains(hint), "{o:?}");
- // `cua agents remove` undoes it.
+ // Plain `cua agents remove` leaves it: it removes Cua Spaces' entries
+ // only. `--include-cua-driver` undoes it.
let o = h.run(&["agents", "remove", "--yes"]).await;
o.ok();
let codex = std::fs::read_to_string(h.dir.path().join(".codex/config.toml")).unwrap();
+ assert!(codex.contains("[mcp_servers.cua-driver]"), "{codex}");
+ assert!(h.dir.path().join(".claude/skills/cua-driver").is_dir());
+ let o = h
+ .run(&["agents", "remove", "--include-cua-driver", "--yes"])
+ .await;
+ o.ok();
+ let codex = std::fs::read_to_string(h.dir.path().join(".codex/config.toml")).unwrap();
assert_eq!(codex, "[mcp_servers.other]\ncommand = \"o\"\n");
assert!(!h.dir.path().join(".claude/skills/cua-driver").exists());
}
+/// `cua agents remove` (what the uninstaller runs) takes Cua Spaces' `cua`
+/// server and skills and leaves Cua Driver's `cua-driver` server and skill,
+/// in the configs of Claude Code, Codex and Cursor; `--dry-run` lists exactly
+/// that and changes nothing; `--include-cua-driver` takes Cua Driver's too.
+#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
+async fn agents_remove_keeps_cua_driver_and_dry_run_lists_what_it_removes() {
+ let h = home();
+ mkdirs(&h, &[".claude", ".codex", ".cursor"]);
+ let at = |rel: &str| h.dir.path().join(rel);
+ std::fs::write(
+ at(".claude.json"),
+ "{\"mcpServers\": {\"other\": {\"command\": \"o\"}}}",
+ )
+ .unwrap();
+ std::fs::write(
+ at(".codex/config.toml"),
+ "[mcp_servers.other]\ncommand = \"o\"\n",
+ )
+ .unwrap();
+ std::fs::write(
+ at(".cursor/mcp.json"),
+ "{\"mcpServers\": {\"other\": {\"command\": \"o\"}}}",
+ )
+ .unwrap();
+ let agents = "claude,codex,cursor";
+ h.run(&[
+ "agents",
+ "setup",
+ "--agents",
+ agents,
+ "--yes",
+ "--mcp-command",
+ "/opt/cua/bin/cua",
+ ])
+ .await
+ .ok();
+ h.run(&[
+ "agents",
+ "setup",
+ "--cua-driver",
+ "--agents",
+ agents,
+ "--yes",
+ "--mcp-command",
+ "/opt/drv/cua-driver",
+ ])
+ .await
+ .ok();
+ let configs = [".claude.json", ".codex/config.toml", ".cursor/mcp.json"];
+ let read = |rel: &str| std::fs::read_to_string(at(rel)).unwrap();
+ for c in configs {
+ let text = read(c);
+ assert!(text.contains("/opt/cua/bin/cua"), "{c}: {text}");
+ assert!(text.contains("/opt/drv/cua-driver"), "{c}: {text}");
+ }
+ let state = at(".cua/agent-setup.json");
+ let snapshot = || -> Vec<String> {
+ configs
+ .iter()
+ .map(|c| read(c))
+ .chain([std::fs::read_to_string(&state).unwrap()])
+ .chain(["cua-spaces", "cua-volume", "cua-driver"].map(|s| {
+ std::fs::read_to_string(at(&format!(".claude/skills/{s}/SKILL.md"))).unwrap()
+ }))
+ .collect()
+ };
+ let before = snapshot();
+
+ // The preview needs no --yes, lists each entry and skill it would
+ // remove, names what it keeps, and writes nothing.
+ let o = h.run(&["agents", "remove", "--dry-run"]).await;
+ o.ok();
+ assert_eq!(snapshot(), before, "{o:?}");
+ let out = &o.stdout;
+ assert!(out.contains("Dry run: nothing is changed."), "{o:?}");
+ for (cfg, shown) in [
+ (".claude.json", "~/.claude.json"),
+ (".codex/config.toml", "~/.codex/config.toml"),
+ (".cursor/mcp.json", "~/.cursor/mcp.json"),
+ ] {
+ let _ = cfg;
+ assert!(
+ out.contains(&format!("would remove MCP server cua: {shown}")),
+ "{o:?}"
+ );
+ assert!(
+ out.contains(&format!("MCP server cua-driver: {shown} kept")),
+ "{o:?}"
+ );
+ }
+ for skill in [
+ "cua-spaces",
+ "cua-volume",
+ "cua-sandboxes",
+ "gui-automation",
+ ] {
+ assert!(
+ out.contains(&format!(
+ "would remove skill {skill}: ~/.claude/skills/{skill}"
+ )),
+ "{o:?}"
+ );
+ }
+ assert!(
+ out.contains("skill cua-driver: ~/.claude/skills/cua-driver kept"),
+ "{o:?}"
+ );
+ assert!(!out.contains("would remove MCP server cua-driver"), "{o:?}");
+ assert!(!out.contains("would remove skill cua-driver"), "{o:?}");
+
+ // The JSON preview carries the same rows.
+ let o = h.run(&["--json", "agents", "remove", "--dry-run"]).await;
+ o.ok();
+ let v = o.json();
+ assert_eq!(v["dry_run"], true, "{v}");
+ let removed: Vec<&str> = v["outcomes"]
+ .as_array()
+ .unwrap()
+ .iter()
+ .filter(|x| x["change"] == "removed")
+ .map(|x| x["item"].as_str().unwrap())
+ .collect();
+ assert!(removed.contains(&"cua"), "{v}");
+ assert!(!removed.contains(&"cua-driver"), "{v}");
+ assert_eq!(snapshot(), before);
+
+ // The real run removes what the preview listed, and only that.
+ let o = h.run(&["agents", "remove", "--yes"]).await;
+ o.ok();
+ assert!(
+ !o.stdout.contains("cua-driver: ~/.claude.json removed"),
+ "{o:?}"
+ );
+ for c in configs {
+ let text = read(c);
+ assert!(!text.contains("/opt/cua/bin/cua"), "{c}: {text}");
+ assert!(text.contains("/opt/drv/cua-driver"), "{c}: {text}");
+ assert!(text.contains("other"), "{c}: {text}");
+ }
+ assert!(!at(".claude/skills/cua-spaces").exists());
+ assert!(at(".claude/skills/cua-driver/SKILL.md").is_file());
+ let o = h.run(&["agents", "remove", "--dry-run"]).await;
+ o.ok();
+ assert!(!o.stdout.contains("would remove"), "{o:?}");
+
+ // Asked for, Cua Driver's go too; the previews say so first.
+ let o = h
+ .run(&["agents", "remove", "--include-cua-driver", "--dry-run"])
+ .await;
+ o.ok();
+ assert!(
+ o.stdout
+ .contains("would remove MCP server cua-driver: ~/.codex/config.toml"),
+ "{o:?}"
+ );
+ assert!(
+ o.stdout
+ .contains("would remove skill cua-driver: ~/.claude/skills/cua-driver"),
+ "{o:?}"
+ );
+ h.run(&["agents", "remove", "--include-cua-driver", "--yes"])
+ .await
+ .ok();
+ for c in configs {
+ let text = read(c);
+ assert!(!text.contains("cua-driver"), "{c}: {text}");
+ assert!(text.contains("other"), "{c}: {text}");
+ }
+ assert!(!at(".claude/skills/cua-driver").exists());
+}
+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn agents_setup_cua_driver_says_where_the_skill_went_and_no_skills_skips_it() {
let h = home();
diff --git a/libs/cua/crates/cua-sdk/src/native/agent_setup.rs b/libs/cua/crates/cua-sdk/src/native/agent_setup.rs
index 98cd06dc7e..7a008012c6 100644
--- a/libs/cua/crates/cua-sdk/src/native/agent_setup.rs
+++ b/libs/cua/crates/cua-sdk/src/native/agent_setup.rs
@@ -403,9 +403,19 @@ mod tests {
assert!(st.cua_configured && st.cua_managed);
let out = s.update(Some(server)).await.unwrap();
assert!(out.iter().all(|o| o.change == AgentSetupChange::Unchanged));
+ // Cua Spaces' entries go; the cua-driver skill (one of the bundled
+ // ones) is Cua Driver's and stays.
let out = s.remove(vec!["codex".into()], true, true).await.unwrap();
assert!(
- out.iter().all(|o| o.change == AgentSetupChange::Removed),
+ out.iter()
+ .filter(|o| o.item != "cua-driver")
+ .all(|o| o.change == AgentSetupChange::Removed),
+ "{out:?}"
+ );
+ assert!(
+ out.iter()
+ .filter(|o| o.item == "cua-driver")
+ .all(|o| o.change == AgentSetupChange::Skipped),
"{out:?}"
);
assert!(
diff --git a/scripts/docs-generators/cli-specs/cua.json b/scripts/docs-generators/cli-specs/cua.json
index 6b8a8ba724..11f7512711 100644
--- a/scripts/docs-generators/cli-specs/cua.json
+++ b/scripts/docs-generators/cli-specs/cua.json
@@ -508,8 +508,8 @@
"usage": "cua agents status [OPTIONS]"
},
{
- "abstract": "Remove the skills and MCP entries cua added (nothing else)",
- "after_help": "Examples:\n cua agents remove\n cua agents remove --agents codex --skills-only -y",
+ "abstract": "Remove the Cua Spaces skills and MCP entries cua added (nothing else)",
+ "after_help": "Examples:\n # See what would be removed, change nothing\n cua agents remove --dry-run\n cua agents remove\n cua agents remove --agents codex --skills-only -y\n # Cua Driver's skill and MCP server too (they stay otherwise)\n cua agents remove --include-cua-driver",
"aliases": [],
"arguments": [],
"flags": [
@@ -545,6 +545,28 @@
"repeatable": false,
"short_name": "y",
"takes_value": false
+ },
+ {
+ "aliases": [],
+ "default_value": false,
+ "env": null,
+ "help": "Also remove Cua Driver's skill and MCP server (`cua-driver`). Without it only Cua Spaces' own entries go: the `cua` server (`cua-local` for Local) and the Cua Spaces skills",
+ "hidden": false,
+ "name": "include-cua-driver",
+ "repeatable": false,
+ "short_name": null,
+ "takes_value": false
+ },
+ {
+ "aliases": [],
+ "default_value": false,
+ "env": null,
+ "help": "List exactly what would be removed and change nothing",
+ "hidden": false,
+ "name": "dry-run",
+ "repeatable": false,
+ "short_name": null,
+ "takes_value": false
}
],
"hidden": false,
diff --git a/scripts/install/README.md b/scripts/install/README.md
index 15394e1401..6d026c28e9 100644
--- a/scripts/install/README.md
+++ b/scripts/install/README.md
@@ -100,20 +100,20 @@ It lists what it found, asks once (`--yes` skips the question; without a termina
| install.sh | install.ps1 | Effect |
|---|---|---|
-| (default) | (default) | Removes the app, the CLI, the host service, the agent integrations, launch at login, your sign-in and Cua's settings and caches. Keeps Spaces and their data |
+| (default) | (default) | Removes the app, the CLI, the host service, Cua Spaces' agent skills and MCP entry, launch at login, your sign-in and Cua's settings and caches. Keeps Spaces and their data, and Cua Driver's and other tools' entries in your agents |
| `--keep-data` | `-KeepData` | Keeps `~/.cua` (settings, the Spaces registry, the Cua Volume cache, the device key) and the app's settings. Still removes programs, services, integrations and the sign-in |
| `--delete-spaces` | `-DeleteSpaces` | Also deletes the Spaces on this computer and their data: Space disks, the local Cua Volume files, the Keyvault. Running Spaces are listed and stopped first; asks you to type `delete` (not with `--yes`). Cannot be combined with `--keep-data` |
-| `--all` | `-All` | Also runs the Cua Driver uninstaller (`cua.ai/driver/uninstall.sh` / `.ps1`) and, on macOS, Lume's (`cua.ai/lume/uninstall.sh`). Lume keeps your VMs unless `--delete-spaces` is given too |
+| `--all` | `-All` | Also runs the Cua Driver uninstaller (`cua.ai/driver/uninstall.sh` / `.ps1`), takes Cua Driver's skill and MCP server out of your agents (`cua agents remove --include-cua-driver`) and, on macOS, runs Lume's uninstaller (`cua.ai/lume/uninstall.sh`). Lume keeps your VMs unless `--delete-spaces` is given too |
| `--prefix DIR` | `-Prefix DIR` | Also removes what `install.sh --prefix DIR` put under `DIR/bin` and `DIR/Applications` |
| `--no-modify-path` | `-NoModifyPath` | Never edits your shell profile (user PATH on Windows) |
-| `--dry-run` | `-DryRun` | Prints what would be removed, changes nothing |
+| `--dry-run` | `-DryRun` | Prints what would be removed, changes nothing. It runs `cua agents remove --dry-run` to list the agent skills and MCP entries one by one |
| `--yes` | `-Yes` | Accepts every prompt |
What it removes, in this order (each step is best effort and bounded, so one failure never stops the rest):
1. Quits the Cua Spaces app, lists the Spaces on this computer and stops the running ones (their disks stay).
2. `cua host remove --force --uninstalling`: unregisters this computer from the relay and removes the host service. When `cua` is not there to do it, it removes the service itself (launchd `com.trycua.spacesd.host` on macOS, the systemd unit `cua-spacesd-host` on Linux, the `Cua\SpacesdHost` scheduled task on Windows, and the names used before the rename).
-3. `cua agents remove --agents all --yes`: the Cua skills and MCP entries (including the cua-driver ones Cua added) in your agents.
+3. `cua agents remove --agents all --yes`: the Cua Spaces skills and the `cua` MCP server (`cua-local` for Local) in your agents. The `cua-driver` skill and MCP server (`cua-driver-local` for Local) and every other tool's entries stay, unless `--all` adds `--include-cua-driver`. A `cua` older than the version with `--include-cua-driver` and `--dry-run` would also strip Cua Driver's entries, so the script skips this step, says what stays in the agents and how to remove it (install the latest `cua`, run `cua agents remove`), removes the rest and still exits 0; a dry run says so too. The record `cua agents remove` works from (`~/.cua/agent-setup.json`) stays unless `--delete-spaces`.
4. `cua daemon stop`, and the Cua Volume mount (`~/Cua Volume` on macOS, `~/cua-volume` on Linux) is unmounted before any file is deleted.
5. Signs out (`cua auth logout`, which revokes the session) and removes a leftover `credentials.json`.
6. The app: `Cua Spaces.app` in `/Applications` and `~/Applications` (macOS, only when its bundle id is Cua's); the `cua-spaces` package with apt (Linux .deb), the AppImage, its desktop entry and autostart entry; on Windows the app's own uninstaller (silent), which also removes launch at login. On macOS the app registered itself as a login item, which a script cannot unregister: with the app gone it has nothing to start, and System Settings, Login Items shows how to remove a leftover row.
diff --git a/scripts/install/tests/test_uninstall.py b/scripts/install/tests/test_uninstall.py
index ce2cb12eb9..d58f343f94 100644
--- a/scripts/install/tests/test_uninstall.py
+++ b/scripts/install/tests/test_uninstall.py
@@ -35,6 +35,26 @@ case "$*" in
if [ -f "$FAKE_SPACES" ]; then cat "$FAKE_SPACES"; else echo "No sandboxes found."; fi
;;
"host remove --force --uninstalling") rm -rf "${CUA_HOME:-$HOME/.cua}/host" ;;
+"agents remove --help")
+ # A cua before the agents fix has neither --include-cua-driver nor --dry-run.
+ echo "Usage: cua agents remove [OPTIONS]"
+ echo " --agents <AGENTS> --skills-only --mcp-only -y, --yes"
+ if [ -z "${FAKE_CUA_OLD_AGENTS:-}" ]; then
+ echo " --include-cua-driver Also remove Cua Driver's skill and MCP server"
+ echo " --dry-run List exactly what would be removed"
+ fi
+ ;;
+"agents remove --agents all --dry-run" | "agents remove --agents all --include-cua-driver --dry-run")
+ echo "Dry run: nothing is changed."
+ echo " would remove MCP server cua: ~/.claude.json"
+ echo " would remove skill cua-spaces: ~/.claude/skills/cua-spaces"
+ echo " - MCP server cua-driver: ~/.claude.json kept (Cua Driver's; --include-cua-driver removes it)"
+ if [ -n "${FAKE_CUA_PLAN_FAILS:-}" ]; then
+ # One agent's config is unreadable: the others are still listed, and the exit status is 1.
+ echo " FAILED MCP server cua: ~/.codex/config.toml (left unchanged)"
+ exit 1
+ fi
+ ;;
esac
exit 0
"""
@@ -246,14 +266,23 @@ class UninstallMacTest(unittest.TestCase):
self.assertIn("[dry-run] remove", result.stdout)
self.assertIn("cua host remove --force --uninstalling", result.stdout)
self.assertIn("[dry-run] bash lume-uninstall.sh --force --purge", result.stdout)
+ # The agent entries are listed one by one, by the command the real run uses with --dry-run.
+ self.assertIn("[dry-run] cua agents remove --agents all --include-cua-driver --dry-run:", result.stdout)
+ self.assertIn("[dry-run] would remove MCP server cua: ~/.claude.json", result.stdout)
+ self.assertIn("[dry-run] would remove skill cua-spaces: ~/.claude/skills/cua-spaces", result.stdout)
self.assertEqual(before, sorted(str(p) for p in box.home.rglob("*")))
self.assertEqual(zshrc, (box.home / ".zshrc").read_text())
self.assertEqual(len(box.keychain_items()), 6)
log = "\n".join(box.call_log())
# The timeout watchdog polls with one-second sleeps, so nothing is left parked.
self.assertEqual(sorted({l for l in log.splitlines() if l.startswith("sleep:")} - {"sleep: 1"}), [])
- for destructive in ("delete-generic-password", "bootout", "agents remove", "daemon stop", "host remove"):
+ for destructive in ("delete-generic-password", "bootout", "daemon stop", "host remove"):
self.assertNotIn(destructive, log)
+ # `agents remove` runs only to read its help and to preview with --dry-run.
+ agent_calls = [l for l in log.splitlines() if "agents remove" in l]
+ self.assertTrue(agent_calls)
+ for call in agent_calls:
+ self.assertTrue(call.endswith("--help") or call.endswith("--dry-run"), call)
def test_default_removes_programs_and_settings_and_keeps_spaces_data(self):
for shell in shells():
@@ -289,6 +318,60 @@ class UninstallMacTest(unittest.TestCase):
self.assertTrue(all(i >= 0 for i in indexes), box.call_log())
self.assertEqual(indexes, sorted(indexes))
self.assertGreaterEqual(box.index("launchctl: bootout"), 0)
+ # Without --all, Cua Driver's skill and MCP entries stay, and the plan says so.
+ self.assertFalse([c for c in box.call_log() if "--include-cua-driver" in c])
+ self.assertIn("Cua Driver's skill and MCP server in your agents", result.stdout)
+
+ def test_a_dry_run_still_lists_the_rows_when_one_agents_config_cannot_be_read(self):
+ box = self.box()
+ installed_mac(box)
+ result = box.run("--dry-run", env={"FAKE_CUA_PLAN_FAILS": "1"})
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ self.assertIn("[dry-run] would remove MCP server cua: ~/.claude.json", result.stdout)
+ self.assertIn("[dry-run] would remove skill cua-spaces: ~/.claude/skills/cua-spaces", result.stdout)
+ self.assertIn("[dry-run] FAILED MCP server cua: ~/.codex/config.toml", result.stdout)
+ self.assertIn("reported a problem (see above), so the list may be incomplete", result.stderr)
+
+ def test_a_cua_too_old_to_leave_cua_driver_alone_skips_the_agent_step_and_still_succeeds(self):
+ """An older `cua agents remove` also strips the `cua-driver` skill and MCP server and
+ has no --dry-run: the uninstaller does not run it, says what stays in the agents and how
+ to remove it, removes everything else and exits 0. The script is published on merge,
+ before the cua release that adds the flag, so this must not look like a failure."""
+ box = self.box()
+ installed_mac(box)
+ box.put(".cua/agent-setup.json", "{}\n")
+ result = box.run("--yes", env={"FAKE_CUA_OLD_AGENTS": "1"})
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ self.assertTrue(box.exists(".cua/agent-setup.json"))
+ self.assertIn("older than the version that removes only Cua Spaces' entries", result.stdout)
+ self.assertIn("agent step is skipped", result.stdout)
+ self.assertIn("install.sh | sh -s -- --cli-only --yes", result.stdout)
+ self.assertIn("run: cua agents remove", result.stdout)
+ # A note, not a warning, and the run says it is done.
+ self.assertNotIn("older than the version", result.stderr)
+ self.assertNotIn("need your attention", result.stdout + result.stderr)
+ self.assertIn("cua-uninstall: done", result.stdout)
+ log = box.call_log()
+ self.assertEqual([c for c in log if "agents remove" in c and not c.endswith("--help")], [])
+ # Everything else goes: hosting, sign-out, the CLI and the app; the record of what cua
+ # added to the agents stays for a later `cua agents remove` (it is not in the disposable list).
+ self.assertGreaterEqual(box.index("host remove --force --uninstalling"), 0)
+ self.assertGreaterEqual(box.index("auth logout"), 0)
+ self.assertFalse(box.exists(".local/bin/cua"))
+ self.assertFalse(box.exists("Applications/Cua Spaces.app"))
+ # --delete-spaces deletes that record too: the note says to remove the entries by hand.
+ box = Sandbox(tempfile.mkdtemp(dir=self.tmp.name), "Darwin")
+ installed_mac(box)
+ result = box.run("--yes", "--delete-spaces", env={"FAKE_CUA_OLD_AGENTS": "1"})
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ self.assertIn("remove them by hand", result.stdout)
+ # A dry run says so and lists the rest of the plan.
+ box = Sandbox(tempfile.mkdtemp(dir=self.tmp.name), "Darwin")
+ installed_mac(box)
+ result = box.run("--dry-run", env={"FAKE_CUA_OLD_AGENTS": "1"})
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ self.assertIn("[dry-run] cua agents remove --agents all: skipped, this cua is older than", result.stdout)
+ self.assertIn("cua host remove --force --uninstalling", result.stdout)
def test_the_app_helper_goes_but_its_permissions_stay(self):
box = self.box()
@@ -527,6 +610,19 @@ class OtherToolsTest(unittest.TestCase):
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
self.assertEqual(self.log.read_text().splitlines(), ["driver ", "lume --force"])
+ def test_all_also_removes_cua_drivers_agent_entries_and_without_all_they_stay(self):
+ box = Sandbox(tempfile.mkdtemp(dir=self.tmp.name), "Darwin")
+ box.cli()
+ result = box.run("--yes", "--all", env=self.env())
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ self.assertGreaterEqual(box.index("agents remove --agents all --include-cua-driver --yes"), 0, box.call_log())
+ box = Sandbox(tempfile.mkdtemp(dir=self.tmp.name), "Darwin")
+ box.cli()
+ result = box.run("--yes", env=self.env())
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ self.assertGreaterEqual(box.index("agents remove --agents all --yes"), 0, box.call_log())
+ self.assertEqual([c for c in box.call_log() if "--include-cua-driver" in c], [])
+
def test_all_with_delete_spaces_purges_lume(self):
box = Sandbox(tempfile.mkdtemp(dir=self.tmp.name), "Darwin")
box.cli()
diff --git a/scripts/install/tests/uninstall.Tests.ps1 b/scripts/install/tests/uninstall.Tests.ps1
index a5464ef9d1..250724ae48 100644
--- a/scripts/install/tests/uninstall.Tests.ps1
+++ b/scripts/install/tests/uninstall.Tests.ps1
@@ -69,6 +69,8 @@ Describe 'Invoke-CuaUninstall' {
$NoModifyPath = [switch]$false; $DryRun = [switch]$false; $Yes = [switch]$false; $Prefix = ''
$script:Calls = New-Object System.Collections.Generic.List[string]
$script:SpacesText = ''
+ $script:OldCua = $false
+ $script:PlanFails = $false
$script:Credentials = @('cua-cli.run.cua.ai', 'cua-cli.device-key.run.cua.ai', 'vault-1.Cua Keyvault', 'git:https://github.com')
$script:UserPath = "C:\Windows;$(Join-Path $script:Local 'Programs\cua\bin');C:\Tools"
@@ -107,6 +109,16 @@ Describe 'Invoke-CuaUninstall' {
return [pscustomobject]@{ ExitCode = 0; Output = "something else 9.9`n" }
}
$script:Calls.Add("cua[$env:CUA_HOME] $args1")
+ # A cua before the agents fix has neither --include-cua-driver nor --dry-run.
+ if ($args1 -eq 'agents remove --help') {
+ $flags = if ($script:OldCua) { '--agents --skills-only --mcp-only --yes' } else { '--agents --skills-only --mcp-only --yes --include-cua-driver --dry-run' }
+ return [pscustomobject]@{ ExitCode = 0; Output = "Usage: cua agents remove [OPTIONS]`n$flags`n" }
+ }
+ if ($args1 -like 'agents remove * --dry-run') {
+ # One agent's config unreadable: the other rows are still listed, and the exit status is 1.
+ $failed = if ($script:PlanFails) { " FAILED MCP server cua: ~/.codex/config.toml (left unchanged)`n" } else { '' }
+ return [pscustomobject]@{ ExitCode = [int][bool]$script:PlanFails; Output = "Dry run: nothing is changed.`n would remove MCP server cua: ~/.claude.json`n MCP server cua-driver: ~/.claude.json kept (Cua Driver's; --include-cua-driver removes it)`n$failed" }
+ }
if ($args1 -eq 'sandbox ls --local --no-size') { return [pscustomobject]@{ ExitCode = 0; Output = $script:SpacesText } }
if ($args1 -eq 'host remove --force --uninstalling') { Remove-Item -Recurse -Force -LiteralPath (Join-Path $env:CUA_HOME 'host') }
return [pscustomobject]@{ ExitCode = 0; Output = '' }
@@ -125,12 +137,19 @@ Describe 'Invoke-CuaUninstall' {
$out | Should -Match 'Found on this PC'
$out | Should -Match '\[dry-run\] remove'
$out | Should -Match '\[dry-run\] cua host remove --force --uninstalling'
+ # The agent entries are listed by the same command a real run uses, with --dry-run.
+ $out | Should -Match '\[dry-run\] cua agents remove --agents all --include-cua-driver --dry-run:'
+ $out | Should -Match '\[dry-run\] would remove MCP server cua: ~/.claude.json'
+ $out | Should -Match 'MCP server cua-driver: ~/.claude.json kept'
Test-Path (Join-Path $script:Bin 'cua.exe') | Should -BeTrue
Test-Path (Join-Path $script:CuaHome 'config.toml') | Should -BeTrue
Test-Path (Join-Path $script:Roaming 'Cua Spaces\settings.json') | Should -BeTrue
$script:Calls | Should -Not -Contain 'app-uninstaller'
- # Only the read-only listing of Spaces runs.
- @($script:Calls | Where-Object { $_ -like 'credential *' -or $_ -like 'user-path *' -or ($_ -like 'cua*' -and $_ -notlike '*sandbox ls --local*') }) | Should -BeNullOrEmpty
+ # Only read-only commands run: the listing of Spaces, and the help and the preview of `agents remove`.
+ @($script:Calls | Where-Object {
+ $_ -like 'credential *' -or $_ -like 'user-path *' -or
+ ($_ -like 'cua*' -and $_ -notlike '*sandbox ls --local*' -and $_ -notlike '*agents remove --help' -and $_ -notlike '*agents remove * --dry-run')
+ }) | Should -BeNullOrEmpty
}
It 'removes programs and settings by default and keeps Spaces data' {
@@ -160,6 +179,51 @@ Describe 'Invoke-CuaUninstall' {
$indexes = $steps | ForEach-Object { $s = $_; [array]::FindIndex($script:Calls.ToArray(), [Predicate[string]] { param($c) $c -like "*$s*" }) }
$indexes | Should -Not -Contain -1
($indexes -join ',') | Should -Be (($indexes | Sort-Object) -join ',')
+ # Cua Driver's skill and MCP entries stay: its flag is only passed with -All.
+ @($script:Calls | Where-Object { $_ -like '*--include-cua-driver*' }) | Should -BeNullOrEmpty
+ }
+
+ It 'removes Cua Driver''s agent entries too only with -All' {
+ $Yes = [switch]$true; $All = [switch]$true
+ Mock Invoke-OtherUninstaller { param($Name) $script:Calls.Add("other-uninstaller $Name") }
+ Invoke-CuaUninstall *>&1 | Out-Null
+ $script:Calls | Should -Contain "cua[$script:CuaHome] agents remove --agents all --include-cua-driver --yes"
+ $script:Calls | Should -Contain 'other-uninstaller cua-driver'
+ }
+
+ It 'skips the agent step, says what stays and still succeeds when cua is too old to leave Cua Driver''s entries alone' {
+ $Yes = [switch]$true
+ $script:OldCua = $true
+ $global:LASTEXITCODE = 0
+ $out = Invoke-CuaUninstall *>&1 | Out-String
+ $out | Should -Match 'older than the version that removes only Cua Spaces'
+ $out | Should -Match 'agent step is skipped'
+ $out | Should -Match 'run: cua agents remove'
+ # A note, not a failure: the run says it is done.
+ $out | Should -Not -Match 'need your attention'
+ $out | Should -Match 'cua-uninstall: done'
+ $global:LASTEXITCODE | Should -Not -Be 1
+ @($script:Calls | Where-Object { $_ -like '*agents remove --agents all*' -and $_ -notlike '*--help' }) | Should -BeNullOrEmpty
+ # Everything else still goes.
+ $script:Calls | Should -Contain 'app-uninstaller'
+ Test-Path (Join-Path $script:Bin 'cua.exe') | Should -BeFalse
+ }
+
+ It 'still lists the rows in a dry run when one agent''s config cannot be read' {
+ $DryRun = [switch]$true
+ $script:PlanFails = $true
+ $out = Invoke-CuaUninstall *>&1 | Out-String
+ $out | Should -Match '\[dry-run\] would remove MCP server cua: ~/.claude.json'
+ $out | Should -Match '\[dry-run\] FAILED MCP server cua: ~/.codex/config.toml'
+ $out | Should -Match 'reported a problem \(see above\), so the list may be incomplete'
+ }
+
+ It 'says so in a dry run when cua is too old to list the agent entries' {
+ $DryRun = [switch]$true
+ $script:OldCua = $true
+ $out = Invoke-CuaUninstall *>&1 | Out-String
+ $out | Should -Match '\[dry-run\] cua agents remove --agents all: skipped, this cua is older than'
+ $out | Should -Match '\[dry-run\] cua host remove --force --uninstalling'
}
It 'keeps the cua home and the device key with -KeepData but still signs out' {
diff --git a/scripts/install/uninstall.ps1 b/scripts/install/uninstall.ps1
index 4c07216f0d..9ba7237397 100644
--- a/scripts/install/uninstall.ps1
+++ b/scripts/install/uninstall.ps1
@@ -9,9 +9,11 @@ Cua uninstaller for Windows: removes what install.ps1 and the Cua Spaces app put
By default it removes the Cua Spaces app (through its own uninstaller), the cua
CLI and its user PATH entry, the host service (`cua host remove --uninstalling`),
-your agents' Cua skills and MCP entries (`cua agents remove`), launch at login,
-your sign-in and device key (Windows Credential Manager), and Cua's settings and
-caches. It never deletes a Space or its data: that needs -DeleteSpaces.
+your agents' Cua Spaces skills and MCP entries (`cua agents remove`: the `cua`
+server and the Cua Spaces skills; Cua Driver's `cua-driver` entries and other
+tools' stay), launch at login, your sign-in and device key (Windows Credential
+Manager), and Cua's settings and caches. It never deletes a Space or its data:
+that needs -DeleteSpaces.
.PARAMETER KeepData
Keep %USERPROFILE%\.cua (settings, the Spaces registry, caches, the Cua Volume
@@ -21,13 +23,15 @@ Also delete the Spaces on this PC and their data (Space disks, the local Cua
Volume files, the Keyvault). Running Spaces are listed and stopped first. This
cannot be undone; you are asked to type "delete" unless -Yes is given.
.PARAMETER All
-Also run the Cua Driver uninstaller.
+Also run the Cua Driver uninstaller, and remove Cua Driver's skill and MCP
+server from your agents.
.PARAMETER Prefix
Also remove what install.ps1 -Prefix put there (Prefix\bin).
.PARAMETER NoModifyPath
Do not edit the user PATH.
.PARAMETER DryRun
-Print what would be removed; change nothing.
+Print what would be removed; change nothing. It lists the agent skills and MCP
+entries one by one.
.PARAMETER Yes
Accept every prompt (non-interactive).
#>
@@ -199,6 +203,54 @@ function Invoke-Cua([string]$Label, [int]$Seconds, [string[]]$Arguments, [hashta
}
}
+# Whether this cua removes only Cua Spaces' entries from agents (`cua agents
+# remove`: its own `cua` server and skills) and can preview that (--dry-run).
+# Older builds removed every entry cua ever wrote, Cua Driver's `cua-driver`
+# server and skill included, and had neither flag. The new flag in its help is
+# the test.
+function Test-CuaScopesAgentsRemove {
+ if (-not $script:Cua) { return $false }
+ $result = Invoke-Bounded $script:Cua @('agents', 'remove', '--help') 20
+ return ($result.ExitCode -eq 0 -and "$($result.Output)" -match '--include-cua-driver')
+}
+
+# What a cua that is too old to leave Cua Driver's entries alone costs: its
+# `agents remove` would strip them, so the step is skipped. That is a note, not a
+# failure: the uninstall finishes normally (the scripts are published before the
+# cua release that adds the flag).
+$OldCuaAgents = 'this cua is older than the version that removes only Cua Spaces'' entries from your agents: its ''cua agents remove'' would also take Cua Driver''s skill and MCP server out of Claude Code, Codex, Cursor and your other agents. So the agent step is skipped, and Cua Spaces'' ''cua'' MCP server and skills (cua-spaces, cua-volume, cua-sandboxes, gui-automation) stay in your agents. To remove them later, install the latest cua (& ([scriptblock]::Create((irm https://cua.ai/install.ps1))) -CliOnly -Yes) and run: cua agents remove'
+
+# Removes the Cua Spaces skills and MCP entries (the `cua` server, `cua-local`
+# for Local) from the agents. Cua Driver's `cua-driver` skill and server, and
+# every other tool's entries, stay, unless -All asked for Cua Driver to go.
+# With -DryRun it runs the same command with --dry-run, so the list is what the
+# real run removes.
+function Remove-AgentIntegrations {
+ $agentArgs = @('agents', 'remove', '--agents', 'all')
+ if ($All) { $agentArgs += '--include-cua-driver' }
+ if (-not (Test-CuaScopesAgentsRemove)) {
+ if ($DryRun) {
+ Write-Host "[dry-run] cua $($agentArgs -join ' '): skipped, $OldCuaAgents"
+ } else {
+ Write-Info $OldCuaAgents
+ if ($DeleteSpaces) { Write-Info '-DeleteSpaces also deletes the record cua keeps of them (agent-setup.json), so remove them by hand' }
+ }
+ return
+ }
+ if ($DryRun) {
+ Write-Host "[dry-run] cua $($agentArgs -join ' ') --dry-run:"
+ $plan = Invoke-Bounded $script:Cua ($agentArgs + '--dry-run') 60
+ # Whatever it listed, even when one agent's config could not be read:
+ # a real run removes the rows that did not fail.
+ foreach ($row in @("$($plan.Output)" -split "`r?`n" | Where-Object { $_.Trim() -and $_ -notlike 'Dry run:*' })) { Write-Host "[dry-run] $row" }
+ if ($plan.ExitCode -ne 0) {
+ Write-Warn "'cua $($agentArgs -join ' ') --dry-run' reported a problem (see above), so the list may be incomplete"
+ }
+ return
+ }
+ $null = Invoke-Cua 'removing the Cua Spaces skills and MCP entries from your agents' 60 ($agentArgs + '--yes')
+}
+
# The cua homes: the main one and one per environment (~/.cua/envs/staging).
function Get-CuaHomes {
$home1 = Get-CuaHome
@@ -480,12 +532,13 @@ function Invoke-CuaUninstall {
if (-not $DryRun) {
Write-Host ''
- Write-Host 'This removes Cua Spaces, the cua CLI, the host service, your agents'' Cua skills and MCP entries,'
- Write-Host 'launch at login and your sign-in.'
+ Write-Host 'This removes Cua Spaces, the cua CLI, the host service, Cua Spaces'' skills and MCP entry in your'
+ Write-Host 'agents, launch at login and your sign-in.'
+ if (-not $All) { Write-Host 'Cua Driver''s skill and MCP server in your agents, and other tools'' entries, stay.' }
if ($KeepData) { Write-Host "It keeps $cuaHome and the Cua Volume cache (-KeepData)." }
elseif ($DeleteSpaces) { Write-Host 'It also deletes Cua''s settings and caches.' }
else { Write-Host 'It also deletes Cua''s settings and caches, but keeps your Spaces and their data.' }
- if ($All) { Write-Host 'It also runs the Cua Driver uninstaller (-All).' }
+ if ($All) { Write-Host 'It also runs the Cua Driver uninstaller, and removes Cua Driver''s skill and MCP server from your agents (-All).' }
if (-not $Yes -and -not (Test-Interactive)) {
Stop-Uninstall 'no terminal to ask on; rerun with -Yes (or -DryRun to see what would be removed)'
}
@@ -525,7 +578,7 @@ function Invoke-CuaUninstall {
$null = Invoke-Cua "turning off hosting ($h)" 150 @('host', 'remove', '--force', '--uninstalling') @{ CUA_HOME = $h }
}
}
- $null = Invoke-Cua 'removing the Cua skills and MCP entries from your agents' 60 @('agents', 'remove', '--agents', 'all', '--yes')
+ Remove-AgentIntegrations
foreach ($h in Get-CuaHomes) { $null = Invoke-Cua 'stopping the cua daemon' 30 @('daemon', 'stop') @{ CUA_HOME = $h } }
$null = Invoke-Cua 'signing out (cua auth logout)' 60 @('auth', 'logout')
if (Test-Path -LiteralPath (Join-Path $cuaHome 'envs\staging')) {
diff --git a/scripts/install/uninstall.sh b/scripts/install/uninstall.sh
index 7fa1eab208..69ed659acf 100755
--- a/scripts/install/uninstall.sh
+++ b/scripts/install/uninstall.sh
@@ -8,18 +8,22 @@
# curl -fsSL https://cua.ai/uninstall.sh | sh -s -- --all
#
# By default it removes the Cua Spaces app, the cua CLI and its PATH line, the
-# host service (`cua host remove --uninstalling`), your agents' Cua skills and
-# MCP entries (`cua agents remove`), launch at login, your sign-in and device
-# key (macOS Keychain, including the old run.cua.ai item), and Cua's settings,
-# caches and logs. It never deletes a Space or its data: that needs
-# --delete-spaces. Run `uninstall.sh --help` for the options.
+# host service (`cua host remove --uninstalling`), your agents' Cua Spaces
+# skills and MCP entries (`cua agents remove`: the `cua` server and the Cua
+# Spaces skills; Cua Driver's `cua-driver` entries and other tools' stay),
+# launch at login, your sign-in and device key (macOS Keychain, including the
+# old run.cua.ai item), and Cua's settings, caches and logs. It never deletes a
+# Space or its data: that needs --delete-spaces. Run `uninstall.sh --help` for
+# the options.
set -eu
usage() {
cat <<'EOF'
Cua uninstaller: removes the Cua Spaces app, the cua CLI, the host service,
-agent integrations, sign-in and Cua's settings. Spaces and their data stay
-unless you ask for them to go.
+Cua Spaces' agent skills and MCP entries, sign-in and Cua's settings. Spaces
+and their data stay unless you ask for them to go. Cua Driver's skill and MCP
+server in your agents, and other tools' entries, stay too (--all removes Cua
+Driver's).
Options:
--keep-data keep ~/.cua (settings, the Spaces registry, caches, the
@@ -29,12 +33,14 @@ Options:
(Space disks, the local Cua Volume files, the Keyvault).
Running Spaces are listed and stopped first. Cannot be
undone; asks you to type "delete" unless --yes is given
- --all also run the Cua Driver and Lume uninstallers
+ --all also run the Cua Driver and Lume uninstallers, and remove
+ Cua Driver's skill and MCP server from your agents
(Lume keeps your VMs unless --delete-spaces is given too)
--prefix DIR also remove what install.sh --prefix DIR put there
(DIR/bin, DIR/Applications)
--no-modify-path never edit your shell profile
- --dry-run print what would be removed, change nothing
+ --dry-run print what would be removed, change nothing (it lists
+ the agent skills and MCP entries one by one)
-y, --yes accept every prompt (non-interactive)
-h, --help show this help
@@ -654,9 +660,59 @@ EOF
fi
}
+# Whether this cua removes only Cua Spaces' entries from agents (`cua agents
+# remove`: its own `cua` server and skills) and can preview that
+# (`--dry-run`). Older builds removed every entry cua ever wrote, Cua Driver's
+# `cua-driver` server and skill included, and had neither flag. The new flag
+# in its help is the test.
+cua_scopes_agents_remove() {
+ [ -n "$cua_bin" ] || return 1
+ bounded 20 env CUA_TELEMETRY=0 DO_NOT_TRACK=1 "$cua_bin" agents remove --help >"$tmp/agents-remove-help" 2>/dev/null || return 1
+ grep -e '--include-cua-driver' "$tmp/agents-remove-help" >/dev/null 2>&1
+}
+
+# What a cua that is too old to leave Cua Driver's entries alone costs: its
+# `agents remove` would strip them, so the step is skipped. That is a note, not a
+# failure: the uninstall finishes normally (the scripts are published before the
+# cua release that adds the flag). ~/.cua/agent-setup.json, the record
+# `cua agents remove` works from, stays unless --delete-spaces.
+OLD_CUA_AGENTS="this cua is older than the version that removes only Cua Spaces' entries from your agents: its 'cua agents remove' would also take Cua Driver's skill and MCP server out of Claude Code, Codex, Cursor and your other agents. So the agent step is skipped, and Cua Spaces' 'cua' MCP server and skills (cua-spaces, cua-volume, cua-sandboxes, gui-automation) stay in your agents. To remove them later, install the latest cua (curl -fsSL https://cua.ai/install.sh | sh -s -- --cli-only --yes) and run: cua agents remove"
+
+# Removes the Cua Spaces skills and MCP entries (the `cua` server, `cua-local`
+# for Local) from the agents. Cua Driver's `cua-driver` skill and server, and
+# every other tool's entries, stay, unless --all asked for Cua Driver to go.
+# With --dry-run it runs the same command with --dry-run, so the list is what
+# the real run removes.
remove_agent_integrations() {
[ -n "$cua_bin" ] || return 0
- run_cua "removing the Cua skills and MCP entries from your agents" 60 agents remove --agents all --yes
+ set -- agents remove --agents all
+ if [ "$all_tools" = 1 ]; then
+ set -- "$@" --include-cua-driver
+ fi
+ if ! cua_scopes_agents_remove; then
+ if [ "$dry_run" = 1 ]; then
+ say "[dry-run] cua $*: skipped, $OLD_CUA_AGENTS"
+ else
+ info "$OLD_CUA_AGENTS"
+ if [ "$delete_spaces" = 1 ]; then
+ info "--delete-spaces also deletes the record cua keeps of them (agent-setup.json), so remove them by hand"
+ fi
+ fi
+ return 0
+ fi
+ if [ "$dry_run" = 1 ]; then
+ say "[dry-run] cua $* --dry-run:"
+ planned=0
+ bounded 60 env CUA_TELEMETRY=0 DO_NOT_TRACK=1 "$cua_bin" "$@" --dry-run >"$tmp/agents-plan" 2>&1 || planned=$?
+ # Whatever it listed, even when one agent's config could not be read:
+ # a real run removes the rows that did not fail.
+ sed -e '/^Dry run:/d' -e 's/^/[dry-run] /' "$tmp/agents-plan"
+ if [ "$planned" != 0 ]; then
+ warn "'cua $* --dry-run' reported a problem (see above), so the list may be incomplete"
+ fi
+ return 0
+ fi
+ run_cua "removing the Cua Spaces skills and MCP entries from your agents" 60 "$@" --yes
}
stop_daemon() {
@@ -1091,8 +1147,11 @@ remove_other_tools() {
confirm_plan() {
[ "$dry_run" = 0 ] || return 0
say ""
- say "This removes Cua Spaces, the cua CLI, the host service, your agents' Cua skills and MCP"
- say "entries, launch at login and your sign-in."
+ say "This removes Cua Spaces, the cua CLI, the host service, Cua Spaces' skills and MCP"
+ say "entry in your agents, launch at login and your sign-in."
+ if [ "$all_tools" = 0 ]; then
+ say "Cua Driver's skill and MCP server in your agents, and other tools' entries, stay."
+ fi
if [ "$keep_data" = 1 ]; then
say "It keeps $cua_home and the Cua Volume cache (--keep-data)."
elif [ "$delete_spaces" = 1 ]; then
@@ -1101,7 +1160,8 @@ confirm_plan() {
say "It also deletes Cua's settings and caches, but keeps your Spaces and their data."
fi
if [ "$all_tools" = 1 ]; then
- say "It also runs the Cua Driver and Lume uninstallers (--all)."
+ say "It also runs the Cua Driver and Lume uninstallers, and removes Cua Driver's skill and"
+ say "MCP server from your agents (--all)."
fi
if [ "$assume_yes" = 0 ] && ! tty_ok; then
die "no terminal to ask on; rerun with --yes (or --dry-run to see what would be removed)"