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.

feat(install): uninstall.sh and uninstall.ps1 for Cua Spaces and the cua CLI (CUA-1876) (#5432)

Francesco Bonacciccb726e53e68
diff --git a/.github/workflows/cd-cua-sdk.yml b/.github/workflows/cd-cua-sdk.yml
index 27c0a15b57..560da977d8 100644
--- a/.github/workflows/cd-cua-sdk.yml
+++ b/.github/workflows/cd-cua-sdk.yml
@@ -584,7 +584,8 @@ jobs:
# Sigstore identity they verify).
python3 scripts/install/stamp_installers.py --repo "$GITHUB_REPOSITORY" --out stamped
gh release upload cua-install-latest release-artifacts.json \
- stamped/install.sh stamped/install.ps1 --clobber --repo "$GITHUB_REPOSITORY"
+ stamped/install.sh stamped/install.ps1 stamped/uninstall.sh stamped/uninstall.ps1 \
+ --clobber --repo "$GITHUB_REPOSITORY"
# The Swift package's CuaSDKFFI.xcframework.zip joins the already-published
# release when its build finishes; checksums.txt is rewritten to include it.
diff --git a/.github/workflows/cd-cua-spaces.yml b/.github/workflows/cd-cua-spaces.yml
index 13da497cf6..1fb34bbd9a 100644
--- a/.github/workflows/cd-cua-spaces.yml
+++ b/.github/workflows/cd-cua-spaces.yml
@@ -1979,4 +1979,5 @@ jobs:
}
fi
gh release upload cua-install-latest assets/release-artifacts.json \
- stamped/install.sh stamped/install.ps1 --clobber --repo "$GITHUB_REPOSITORY"
+ stamped/install.sh stamped/install.ps1 stamped/uninstall.sh stamped/uninstall.ps1 \
+ --clobber --repo "$GITHUB_REPOSITORY"
diff --git a/.github/workflows/ci-installers.yml b/.github/workflows/ci-installers.yml
index 188a69d6f5..4e3a51fd54 100644
--- a/.github/workflows/ci-installers.yml
+++ b/.github/workflows/ci-installers.yml
@@ -1,6 +1,7 @@
name: "CI: Installers"
-# install.sh / install.ps1 (scripts/install), the release manifest generator
+# install.sh / install.ps1 and uninstall.sh / uninstall.ps1 (scripts/install),
+# the release manifest generator
# and the macOS .pkg, exercised against a locally served fake release. Nothing
# here installs onto the runner outside temp dirs, except the Linux container
# smoke, which installs into a throwaway container.
@@ -37,13 +38,13 @@ jobs:
- name: shellcheck
run: |
docker run --rm -v "$PWD:/w:ro" koalaman/shellcheck:stable -s sh \
- /w/scripts/install/install.sh /w/scripts/install/tests/run.sh /w/scripts/install/tests/docker-pester.sh \
+ /w/scripts/install/install.sh /w/scripts/install/uninstall.sh /w/scripts/install/tests/run.sh /w/scripts/install/tests/docker-pester.sh \
/w/apps/cua-spaces/scripts/build-pkg.sh /w/apps/cua-spaces/scripts/prepare-cli-sidecar.sh \
/w/apps/cua-spaces/src-tauri/installer/macos-pkg/postinstall /w/apps/cua-spaces/tests/installer/pkg.test.sh
- name: shfmt
run: |
docker run --rm -v "$PWD:/w:ro" mvdan/shfmt:v3 -d \
- /w/scripts/install/install.sh /w/scripts/install/tests/run.sh \
+ /w/scripts/install/install.sh /w/scripts/install/uninstall.sh /w/scripts/install/tests/run.sh \
/w/apps/cua-spaces/scripts/build-pkg.sh /w/apps/cua-spaces/scripts/prepare-cli-sidecar.sh \
/w/apps/cua-spaces/src-tauri/installer/macos-pkg/postinstall /w/apps/cua-spaces/tests/installer/pkg.test.sh
- name: release_manifest.py unit tests
@@ -100,6 +101,8 @@ jobs:
- uses: actions/checkout@v4
- name: install.sh test suite (includes the .dmg mount into --prefix)
run: sh scripts/install/tests/run.sh
+ - name: uninstall.sh tests under macOS's /bin/sh (a throwaway HOME, no real Keychain or services)
+ run: python3 -m unittest discover -s scripts/install/tests -p 'test_uninstall.py' -v
- name: .pkg build + expand + postinstall against a temp volume
run: sh apps/cua-spaces/tests/installer/pkg.test.sh
@@ -129,3 +132,9 @@ jobs:
./scripts/install/install.ps1 -DryRun -Yes -Mode host
./scripts/install/install.ps1 -CliOnly -Yes -NoOnboarding -Prefix (Join-Path $env:RUNNER_TEMP 'prefix')
if (-not (Test-Path (Join-Path $env:RUNNER_TEMP 'prefix/bin/cua.exe'))) { throw 'cua.exe was not installed' }
+ - name: uninstall.ps1 -DryRun changes nothing
+ shell: pwsh
+ run: |
+ $prefix = Join-Path $env:RUNNER_TEMP 'prefix'
+ ./scripts/install/uninstall.ps1 -DryRun -Prefix $prefix
+ if (-not (Test-Path (Join-Path $prefix 'bin/cua.exe'))) { throw 'the dry run removed cua.exe' }
diff --git a/.github/workflows/release-installers-feed.yml b/.github/workflows/release-installers-feed.yml
index 86f676bcb3..9f6010436f 100644
--- a/.github/workflows/release-installers-feed.yml
+++ b/.github/workflows/release-installers-feed.yml
@@ -1,11 +1,11 @@
name: "Release: installer scripts feed"
-# cua.ai/install.sh and install.ps1 redirect to the copies on the rolling
-# cua-install-latest release. cd-cua-sdk.yml and cd-cua-spaces.yml refresh
+# cua.ai/install.sh, install.ps1, uninstall.sh and uninstall.ps1 redirect to the
+# copies on the rolling cua-install-latest release. cd-cua-sdk.yml and cd-cua-spaces.yml refresh
# those copies only when a CLI or app release publishes, so an installer fix
# merged between releases would not reach users (CUA-1771: the --pair guard
# stayed unpublished while the manifest still pointed at CLI 0.4.2).
-# This workflow republishes the two scripts when they change on main. It
+# This workflow republishes the scripts when they change on main. It
# touches only the scripts, never release-artifacts.json.
on:
@@ -14,6 +14,8 @@ on:
paths:
- "scripts/install/install.sh"
- "scripts/install/install.ps1"
+ - "scripts/install/uninstall.sh"
+ - "scripts/install/uninstall.ps1"
- "scripts/install/stamp_installers.py"
workflow_dispatch:
@@ -26,12 +28,14 @@ concurrency:
jobs:
publish:
- name: Publish install.sh / install.ps1 to cua-install-latest
+ name: Publish the installer and uninstaller scripts to cua-install-latest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check the scripts
- run: sh -n scripts/install/install.sh
+ run: |
+ sh -n scripts/install/install.sh
+ sh -n scripts/install/uninstall.sh
- name: Stamp and upload
env:
GH_TOKEN: ${{ github.token }}
@@ -43,5 +47,5 @@ jobs:
fi
python3 scripts/install/stamp_installers.py --repo "$GITHUB_REPOSITORY" --out stamped
gh release upload cua-install-latest stamped/install.sh stamped/install.ps1 \
- --clobber --repo "$GITHUB_REPOSITORY"
- echo "Published install.sh and install.ps1 from $GITHUB_SHA" >> "$GITHUB_STEP_SUMMARY"
+ stamped/uninstall.sh stamped/uninstall.ps1 --clobber --repo "$GITHUB_REPOSITORY"
+ echo "Published install.sh, install.ps1, uninstall.sh and uninstall.ps1 from $GITHUB_SHA" >> "$GITHUB_STEP_SUMMARY"
diff --git a/docs/content/docs/spaces/guides/uninstall.mdx b/docs/content/docs/spaces/guides/uninstall.mdx
new file mode 100644
index 0000000000..bbc64d1cf5
--- /dev/null
+++ b/docs/content/docs/spaces/guides/uninstall.mdx
@@ -0,0 +1,109 @@
+---
+title: Uninstall Cua Spaces
+description: 'Remove Cua Spaces, the cua CLI and everything they set up with one command. Your Spaces and their data stay unless you ask for them to go.'
+---
+
+import { Callout } from 'fumadocs-ui/components/callout';
+import { Tab, Tabs } from 'fumadocs-ui/components/tabs';
+
+One command removes Cua Spaces, the `cua` CLI and what they set up on this
+computer. It lists what it found and asks before it removes anything. Run it
+again any time: a computer that has nothing left, or only part of Cua, is fine.
+
+<Tabs items={['macOS and Linux', 'Windows']}>
+ <Tab value="macOS and Linux">
+ ```bash skip="destructive"
+ curl -fsSL https://cua.ai/uninstall.sh | sh
+ ```
+ </Tab>
+ <Tab value="Windows">
+ ```powershell skip="destructive"
+ irm https://cua.ai/uninstall.ps1 | iex
+ ```
+ </Tab>
+</Tabs>
+
+To see what it would do first, add `--dry-run` (`-DryRun` on Windows). It prints
+every step and changes nothing:
+
+```bash skip="destructive"
+curl -fsSL https://cua.ai/uninstall.sh | sh -s -- --dry-run
+```
+
+## What it removes
+
+- The Cua Spaces app.
+- The `cua` CLI, and the line the installer added to your shell profile (the user
+ PATH on Windows).
+- The host service, after `cua host remove`, so this computer no longer shows up
+ as a machine in your account.
+- The Cua skills and MCP entries in your AI agents, the way `cua agents remove`
+ does. Entries from other tools stay.
+- Launch at login.
+- Your sign-in and the device key: macOS Keychain items (including the old
+ `run.cua.ai` one), Windows Credential Manager entries.
+- Cua's settings, caches and logs.
+
+## What it keeps
+
+Your Spaces and their data. That is the Space disks under `~/.cua`, the local
+Cua Volume files and the Keyvault. Running Spaces are listed and stopped first,
+and their disks stay.
+
+Pass `--keep-data` (`-KeepData`) to also keep `~/.cua` (settings, caches, the
+device key) and the app's settings, for a later reinstall. Programs, services,
+agent entries and your sign-in are still removed.
+
+## Delete Spaces and their data too
+
+<Callout type="warn">
+`--delete-spaces` deletes the Spaces on this computer, the local Cua Volume files
+and the Keyvault. It cannot be undone.
+</Callout>
+
+```bash skip="destructive"
+curl -fsSL https://cua.ai/uninstall.sh | sh -s -- --delete-spaces
+```
+
+It lists the Spaces, stops the running ones, and asks you to type `delete`.
+`--yes` skips that question, so use it only in scripts you trust.
+
+## Options
+
+| macOS and Linux | Windows | Effect |
+|-----------------|---------|--------|
+| `--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. |
+| `--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. |
+| `--yes` | `-Yes` | Accept every question. Without a terminal, nothing is removed unless you pass it. |
+
+## 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:
+
+```bash skip="destructive"
+/bin/bash -c "$(curl -fsSL https://cua.ai/driver/uninstall.sh)"
+/bin/bash -c "$(curl -fsSL https://cua.ai/lume/uninstall.sh)"
+```
+
+## If a step needs your attention
+
+The command says what to run for anything it could not remove, and exits with a
+non-zero status.
+
+- **An app or `cua` owned by root** (installed from the `.pkg`, or with
+ `sudo`): run the `sudo rm` line it prints, or run the whole uninstaller with
+ `sudo`.
+- **The Cua Spaces login item on macOS.** The app registers itself, so a script
+ cannot unregister it. With the app gone it has nothing to start. If a row is
+ left in System Settings, Login Items, switch it off there.
+- **A `cua` from pip, npm or Homebrew** is not touched. Remove it with the tool
+ that installed it.
+- **The `.deb` on Linux** needs root: `sudo apt-get remove cua-spaces`.
+
+To install again: `curl -fsSL https://cua.ai/install.sh | sh`. See
+[Install](/spaces/guides/install).
diff --git a/scripts/install/README.md b/scripts/install/README.md
index 5cbfdef3ba..465a24dd0c 100644
--- a/scripts/install/README.md
+++ b/scripts/install/README.md
@@ -1,6 +1,6 @@
# Cua installers
-Two scripts install the `cua` CLI, the Cua Spaces app and agent extras, then sign in and set up your AI coding agents with `cua auth login`.
+Two scripts install the `cua` CLI, the Cua Spaces app and agent extras, then sign in and set up your AI coding agents with `cua auth login`. Two more remove them again: [`uninstall.sh` and `uninstall.ps1`](#uninstall).
```sh
curl -fsSL https://cua.ai/install.sh | sh
@@ -78,6 +78,46 @@ On Linux and macOS, when the bin dir is not on PATH, install.sh in a terminal as
MDM on macOS: `apps/cua-spaces/scripts/build-pkg.sh` builds a `.pkg` (signed with `--sign`, install mode baked with `--mode`) that installs the app and links `/usr/local/bin/cua` to the CLI bundled inside it. The macOS app is the SwiftUI app (`apps/cua-spaces-macos`, `scripts/build-release.sh`), which carries the CLI as `Contents/MacOS/cua`; the Linux and Windows Electron app (`apps/cua-spaces-desktop`) bundles it itself, and the Tauri bundles (disabled) carry it as a sidecar (`apps/cua-spaces/scripts/prepare-cli-sidecar.sh` + `src-tauri/tauri.sidecar.conf.json`).
+## Uninstall
+
+```sh
+curl -fsSL https://cua.ai/uninstall.sh | sh
+```
+
+```powershell
+irm https://cua.ai/uninstall.ps1 | iex
+```
+
+It lists what it found, asks once (`--yes` skips the question; without a terminal it refuses to remove anything unless you pass `--yes`), and can be run again at any time: a computer with nothing left, or only part of Cua, is fine. It only touches Cua's own paths and never a file outside them.
+
+| 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 |
+| `--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 |
+| `--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 |
+| `--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.
+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.
+7. The CLI: `~/.local/bin/cua`, `/usr/local/bin/cua` (and `DIR/bin/cua`), only when it is the Cua CLI (`cua --version` says `cua X.Y.Z`, or a link into the app). A `cua` from pip, npm or Homebrew is left alone and named. On Windows, `%LOCALAPPDATA%\Programs\cua\bin\cua.exe` and its user PATH entry.
+8. The `# Added by the cua installer` PATH line in your shell profile (kept while `cua-driver` or `lume` still lives in the same folder).
+9. Credentials: the macOS Keychain items of service `run.cua.ai` and `staging.run.cua.ai` (account `cua-cli` for the session; the device key and agent keys too unless `--keep-data`; this includes the legacy `run.cua.ai` label), and the Windows Credential Manager entries `cua-cli.*.run.cua.ai`. With `--delete-spaces` also the Keyvault master key (`Cua Keyvault`).
+10. Settings and caches: in `~/.cua` the config, caches, telemetry, runtimes, skills, the host folder and the Cua Volume cache (`volume/cache`); on macOS the app's Application Support, Preferences, Caches, saved state and WebKit folders; on Linux and Windows the app's own settings folder. Everything else in `~/.cua` (sandboxes, vmm, images, `volume/data`, the Keyvault, trajectories, the Spaces registry) stays until you pass `--delete-spaces`.
+
+The scripts are published next to the installers on the rolling `cua-install-latest` release (`release-installers-feed.yml`, and the CLI and app release workflows through `stamp_installers.py`), and cua.ai redirects `/uninstall.sh` and `/uninstall.ps1` to them the way it does `/install.sh`.
+
+Tests: `python3 -m unittest discover -s scripts/install/tests -p 'test_uninstall.py'` (a throwaway HOME, recording fakes for `cua`, `launchctl`, `systemctl`, `security`, and an `rm` that refuses anything outside the sandbox) and the Pester file `tests/uninstall.Tests.ps1` (every step that touches the machine is mocked).
+
## Release manifest
Both scripts read `release-artifacts.json`:
diff --git a/scripts/install/stamp_installers.py b/scripts/install/stamp_installers.py
index 3037bb8c20..0818c128ee 100755
--- a/scripts/install/stamp_installers.py
+++ b/scripts/install/stamp_installers.py
@@ -1,5 +1,7 @@
#!/usr/bin/env python3
"""Copy install.sh / install.ps1 with the release repository as their default.
+The uninstallers (uninstall.sh / uninstall.ps1) download nothing from a release,
+so they are copied as they are, to publish next to the installers.
The installers default to trycua/cua: their download base and the Sigstore
identity they verify (the release workflow at its tag) both derive from it.
@@ -9,7 +11,8 @@ then installs, and verifies, its own releases):
python3 scripts/install/stamp_installers.py --repo "$GITHUB_REPOSITORY" --out stamped
-writes stamped/install.sh and stamped/install.ps1. CUA_INSTALL_REPO still
+writes stamped/install.sh, stamped/install.ps1, stamped/uninstall.sh and
+stamped/uninstall.ps1. CUA_INSTALL_REPO still
overrides the default at install time. Fails if a default is not found, so a
changed installer cannot silently keep pointing somewhere else.
"""
@@ -18,6 +21,7 @@ from __future__ import annotations
import argparse
import re
+import shutil
import sys
from pathlib import Path
@@ -33,6 +37,9 @@ DEFAULTS = {
),
}
+# Published unchanged next to the installers (cua.ai/uninstall.sh and .ps1).
+UNCHANGED = ("uninstall.sh", "uninstall.ps1")
+
def stamp(text: str, name: str, repo: str) -> str:
old, template = DEFAULTS[name]
@@ -45,7 +52,7 @@ def main(argv: list[str] | None = None) -> int:
parser = argparse.ArgumentParser(description=__doc__.split("\n\n")[0])
parser.add_argument("--repo", required=True, help="owner/name, e.g. $GITHUB_REPOSITORY")
parser.add_argument("--out", required=True, type=Path, help="directory for the stamped copies")
- parser.add_argument("--src", type=Path, default=HERE, help="directory holding install.sh / install.ps1")
+ parser.add_argument("--src", type=Path, default=HERE, help="directory holding the installer and uninstaller scripts")
args = parser.parse_args(argv)
if not REPO_RE.match(args.repo):
print(f"invalid repository {args.repo!r} (want owner/name)", file=sys.stderr)
@@ -64,6 +71,11 @@ def main(argv: list[str] | None = None) -> int:
fh.write(stamped)
dest.chmod((args.src / name).stat().st_mode)
print(f"{dest}: default repository {args.repo}")
+ for name in UNCHANGED:
+ dest = args.out / name
+ shutil.copyfile(args.src / name, dest)
+ dest.chmod((args.src / name).stat().st_mode)
+ print(f"{dest}: copied as is")
return 0
diff --git a/scripts/install/tests/test_stamp_installers.py b/scripts/install/tests/test_stamp_installers.py
index e2064874bb..d99e949032 100644
--- a/scripts/install/tests/test_stamp_installers.py
+++ b/scripts/install/tests/test_stamp_installers.py
@@ -40,6 +40,15 @@ class StampInstallersTest(unittest.TestCase):
for name in ("install.sh", "install.ps1"):
self.assertEqual((self.out / name).read_bytes(), (HERE / name).read_bytes(), name)
+ def test_the_uninstallers_are_copied_as_they_are_for_every_repository(self):
+ for repo in ("trycua/cua", "trycua/cua-staging"):
+ out = self.out / repo.split("/")[1]
+ result = run("--repo", repo, "--out", str(out))
+ self.assertEqual(result.returncode, 0, result.stderr)
+ for name in ("uninstall.sh", "uninstall.ps1"):
+ self.assertEqual((out / name).read_bytes(), (HERE / name).read_bytes(), name)
+ self.assertEqual((out / "uninstall.sh").stat().st_mode, (HERE / "uninstall.sh").stat().st_mode)
+
def test_rejects_a_bad_repository(self):
for bad in ("", "trycua", "a/b/c", "trycua/cua; rm -rf /", "trycua/cua'"):
self.assertNotEqual(run("--repo", bad, "--out", str(self.out)).returncode, 0, bad)
@@ -49,6 +58,8 @@ class StampInstallersTest(unittest.TestCase):
src.mkdir()
(src / "install.sh").write_text('REPO="${SOMETHING_ELSE:-trycua/cua}"\n')
(src / "install.ps1").write_text((HERE / "install.ps1").read_text())
+ for name in ("uninstall.sh", "uninstall.ps1"):
+ (src / name).write_text((HERE / name).read_text())
result = run("--repo", "trycua/cua-staging", "--out", str(self.out / "o"), "--src", str(src))
self.assertEqual(result.returncode, 1)
self.assertIn("install.sh", result.stderr)
diff --git a/scripts/install/tests/test_uninstall.py b/scripts/install/tests/test_uninstall.py
new file mode 100644
index 0000000000..247a949277
--- /dev/null
+++ b/scripts/install/tests/test_uninstall.py
@@ -0,0 +1,579 @@
+"""Tests for uninstall.sh (python3 -m unittest discover scripts/install/tests).
+
+Hermetic, in the style of libs/cua-driver/scripts/tests/test_uninstall_*.py: a
+throwaway HOME, a PATH that holds only symlinks to a few real utilities plus
+recording fakes (cua, launchctl, systemctl, security, ...), and an `rm` that
+refuses anything outside the sandbox. Nothing here touches the real home
+folder, /Applications, the real Keychain or a real service.
+"""
+
+import http.server
+import os
+import shlex
+import shutil
+import subprocess
+import sys
+import tempfile
+import threading
+import unittest
+from pathlib import Path
+
+HERE = Path(__file__).resolve().parent.parent
+SCRIPT = HERE / "uninstall.sh"
+
+# Real utilities the script needs; everything else is a fake or absent.
+REAL_TOOLS = (
+ "awk", "cat", "cmp", "curl", "cut", "dirname", "env", "grep", "head", "kill", "ls", "mkdir",
+ "mktemp", "printf", "readlink", "rmdir", "sed", "sort", "tr", "wc", "bash",
+)
+
+FAKE_CUA = """#!/bin/sh
+printf 'cua[%s]: %s\\n' "${CUA_HOME:-}" "$*" >>"$FAKE_CALLS"
+case "$*" in
+"--version") echo "cua 1.2.3 (test)" ;;
+"sandbox ls --local --no-size")
+ 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" ;;
+esac
+exit 0
+"""
+
+
+def write_executable(path, body):
+ path.parent.mkdir(parents=True, exist_ok=True)
+ path.write_text(body, encoding="utf-8")
+ path.chmod(0o755)
+
+
+class Sandbox:
+ """A fake computer: HOME, a recording PATH and an rm that stays inside."""
+
+ def __init__(self, root, os_name="Darwin", shell="/bin/sh"):
+ self.root = Path(root).resolve()
+ self.home = self.root / "home"
+ self.bin = self.root / "bin"
+ self.calls = self.root / "calls.log"
+ self.spaces = self.root / "spaces.txt"
+ self.shell = shell
+ self.os_name = os_name
+ self.home.mkdir()
+ (self.root / "tmp").mkdir()
+ self.calls.write_text("")
+ for tool in REAL_TOOLS:
+ real = shutil.which(tool)
+ if real:
+ (self.bin / tool).parent.mkdir(parents=True, exist_ok=True)
+ (self.bin / tool).symlink_to(real)
+ # rm keeps real semantics but may only act inside the sandbox.
+ guard = self.root / "safe_rm.py"
+ guard.write_text(
+ "import os, pathlib, sys\n"
+ f"root = pathlib.Path({str(self.root)!r})\n"
+ "for arg in sys.argv[1:]:\n"
+ " if arg.startswith('-'): continue\n"
+ " parent = pathlib.Path(os.path.abspath(arg)).parent\n"
+ " assert root == parent or root in parent.parents, 'rm outside the sandbox: ' + arg\n"
+ "os.execv('/bin/rm', ['/bin/rm', *sys.argv[1:]])\n"
+ )
+ write_executable(self.bin / "rm", f"#!/bin/sh\nexec {shlex.quote(sys.executable)} {shlex.quote(str(guard))} \"$@\"\n")
+ # Records every sleep: the timeout watchdog must never park a long one.
+ write_executable(self.bin / "sleep", "#!/bin/sh\nprintf 'sleep: %s\\n' \"$*\" >>\"$FAKE_CALLS\"\nexec " + shlex.quote(shutil.which("sleep")) + " \"$@\"\n")
+ write_executable(self.bin / "id", '#!/bin/sh\nif [ "${1:-}" = -u ]; then echo "${FAKE_UID:-1000}"; fi\n')
+ write_executable(self.bin / "pgrep", "#!/bin/sh\nexit 1\n")
+ for name in (
+ "pkill", "launchctl", "systemctl", "security", "osascript", "defaults", "umount",
+ "diskutil", "pkgutil", "apt-get", "sudo", "secret-tool", "fusermount",
+ ):
+ self.fake_recording(name)
+ write_executable(self.bin / "mount", "#!/bin/sh\ncat \"${FAKE_MOUNTS:-/dev/null}\"\n")
+ self.fake_security()
+ write_executable(self.bin / "cua", FAKE_CUA)
+ self.env = {
+ "HOME": str(self.home),
+ "PATH": str(self.bin),
+ "TMPDIR": str(self.root / "tmp"),
+ # The macOS system python writes bytecode caches under $HOME.
+ "PYTHONDONTWRITEBYTECODE": "1",
+ "FAKE_CALLS": str(self.calls),
+ "FAKE_SPACES": str(self.spaces),
+ "CUA_UNINSTALL_OS": os_name,
+ "CUA_UNINSTALL_NONINTERACTIVE": "1",
+ # /Applications, /usr/local/bin, /opt and /etc live in here.
+ "CUA_UNINSTALL_ROOT": str(self.root / "sys"),
+ }
+ self.sys = self.root / "sys"
+
+ def fake_recording(self, name):
+ write_executable(self.bin / name, f"#!/bin/sh\nprintf '{name}: %s\\n' \"$*\" >>\"$FAKE_CALLS\"\nexit 0\n")
+
+ def fake_security(self):
+ """A Keychain with items listed in keychain.txt as `service|account` lines."""
+ store = self.root / "keychain.txt"
+ store.write_text("")
+ write_executable(
+ self.bin / "security",
+ f"""#!/bin/sh
+store={shlex.quote(str(store))}
+printf 'security: %s\\n' "$*" >>"$FAKE_CALLS"
+verb="$1"; shift
+service=""; account=""
+while [ $# -gt 0 ]; do
+ case "$1" in
+ -s) service="$2"; shift ;;
+ -a) account="$2"; shift ;;
+ esac
+ shift
+done
+match() {{ awk -F'|' -v s="$service" -v a="$account" '$1 == s && (a == "" || $2 == a) {{ print; exit }}' "$store"; }}
+case "$verb" in
+find-generic-password) [ -n "$(match)" ] ;;
+delete-generic-password)
+ line="$(match)"
+ [ -n "$line" ] || exit 44
+ grep -vxF "$line" "$store" >"$store.new" || true
+ cat "$store.new" >"$store"
+ ;;
+esac
+""",
+ )
+ self.keychain = store
+
+ # -- fixtures -------------------------------------------------------------
+ def put(self, relative, text="x\n", mode=None):
+ path = self.home / relative
+ path.parent.mkdir(parents=True, exist_ok=True)
+ path.write_text(text)
+ if mode is not None:
+ path.chmod(mode)
+ return path
+
+ def put_sys(self, relative, text="x\n", mode=None):
+ path = self.sys / relative
+ path.parent.mkdir(parents=True, exist_ok=True)
+ path.write_text(text)
+ if mode is not None:
+ path.chmod(mode)
+ return path
+
+ def cli(self, relative=".local/bin/cua"):
+ path = self.home / relative
+ path.parent.mkdir(parents=True, exist_ok=True)
+ shutil.copy(self.bin / "cua", path)
+ return path
+
+ def keychain_add(self, *items):
+ with open(self.keychain, "a") as fh:
+ for item in items:
+ fh.write(item + "\n")
+
+ def keychain_items(self):
+ return [line for line in self.keychain.read_text().splitlines() if line]
+
+ def run(self, *args, env=None, shell=None):
+ e = dict(self.env)
+ e.update(env or {})
+ return subprocess.run(
+ [shell or self.shell, str(SCRIPT), *args],
+ env=e, text=True, capture_output=True, cwd=str(self.root), check=False,
+ )
+
+ def call_log(self):
+ return self.calls.read_text().splitlines()
+
+ def index(self, fragment):
+ for i, line in enumerate(self.call_log()):
+ if fragment in line:
+ return i
+ return -1
+
+ def exists(self, relative):
+ path = self.home / relative
+ return path.exists() or path.is_symlink()
+
+
+def shells():
+ found = ["/bin/sh"]
+ dash = shutil.which("dash")
+ if dash and Path(dash).resolve() != Path("/bin/sh").resolve():
+ found.append(dash)
+ return found
+
+
+PATH_BLOCK = '\n# Added by the cua installer\nexport PATH="{home}/.local/bin:$PATH"\n'
+
+
+def installed_mac(box):
+ """Everything install.sh and the Cua Spaces app leave on a Mac (sandboxed)."""
+ box.put("Applications/Cua Spaces.app/Contents/MacOS/CuaSpacesMac", "app\n", 0o755)
+ box.cli()
+ box.put(".zshrc", "alias a=b\n" + PATH_BLOCK.format(home=box.home) + "export KEEP=1\n")
+ box.put("Library/LaunchAgents/com.trycua.spacesd.host.plist", "plist\n")
+ box.put(".cua/host/config.json", "{}\n")
+ box.put(".cua/host/bin/cua-spacesd", "bin\n")
+ box.put(".cua/config.toml", "default.on = 'local'\n")
+ box.put(".cua/credentials.json", "{}\n")
+ box.put(".cua/cache/blob", "blob\n")
+ box.put(".cua/telemetry/install_channel", "install_script\n")
+ box.put(".cua/volume/cache/block", "cached\n")
+ box.put(".cua/volume/data/notes.txt", "my notes\n")
+ box.put(".cua/sandboxes/studio/disk.img", "disk\n")
+ box.put(".cua/vmm/state", "vm\n")
+ box.put("Library/Application Support/com.trycua.spaces.macos/settings.json", "{}\n")
+ box.put("Library/Caches/com.trycua.spaces.macos/c", "cache\n")
+ box.put("Library/Preferences/com.trycua.spaces.macos.plist", "prefs\n")
+ box.keychain_add("run.cua.ai|cua-cli", "run.cua.ai|cua-cli.device-key", "run.cua.ai|cua-cli.agent-keys",
+ "Cua Keyvault|vault-1", "Cua Keyvault Generation|vault-1", "Other App|me")
+
+
+class UninstallMacTest(unittest.TestCase):
+ def setUp(self):
+ self.tmp = tempfile.TemporaryDirectory()
+ self.addCleanup(self.tmp.cleanup)
+
+ def box(self, **kw):
+ return Sandbox(self.tmp.name, "Darwin", **kw)
+
+ def test_dry_run_prints_the_plan_and_changes_nothing(self):
+ for shell in shells():
+ with self.subTest(shell=shell):
+ box = Sandbox(tempfile.mkdtemp(dir=self.tmp.name), "Darwin", shell=shell)
+ installed_mac(box)
+ before = sorted(str(p) for p in box.home.rglob("*"))
+ zshrc = (box.home / ".zshrc").read_text()
+ result = box.run("--dry-run", "--all", "--delete-spaces")
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ 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)
+ 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"):
+ self.assertNotIn(destructive, log)
+
+ def test_default_removes_programs_and_settings_and_keeps_spaces_data(self):
+ for shell in shells():
+ with self.subTest(shell=shell):
+ box = Sandbox(tempfile.mkdtemp(dir=self.tmp.name), "Darwin", shell=shell)
+ installed_mac(box)
+ result = box.run("--yes", "--prefix", str(box.home))
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ # The app, the CLI, the host service, settings and caches are gone.
+ for gone in (
+ "Applications/Cua Spaces.app", ".local/bin/cua",
+ "Library/LaunchAgents/com.trycua.spacesd.host.plist", ".cua/host", ".cua/config.toml",
+ ".cua/credentials.json", ".cua/cache", ".cua/telemetry", ".cua/volume/cache",
+ "Library/Application Support/com.trycua.spaces.macos", "Library/Caches/com.trycua.spaces.macos",
+ "Library/Preferences/com.trycua.spaces.macos.plist",
+ ):
+ self.assertFalse(box.exists(gone), gone)
+ # Spaces, their disks and the local Cua Volume files stay.
+ self.assertEqual((box.home / ".cua/volume/data/notes.txt").read_text(), "my notes\n")
+ self.assertTrue(box.exists(".cua/sandboxes/studio/disk.img"))
+ self.assertTrue(box.exists(".cua/vmm/state"))
+ self.assertIn("kept in", result.stdout)
+ # The PATH block goes; the rest of the profile is untouched.
+ self.assertEqual((box.home / ".zshrc").read_text(), "alias a=b\nexport KEEP=1\n")
+ # Sign-in and device key leave the Keychain; Keyvault and other apps stay.
+ self.assertEqual(box.keychain_items(), ["Cua Keyvault|vault-1", "Cua Keyvault Generation|vault-1", "Other App|me"])
+ # The right steps, in a safe order: the app, hosting, agents, daemon, sign-out.
+ steps = [
+ "host remove --force --uninstalling", "agents remove --agents all --yes",
+ "daemon stop", "auth logout",
+ ]
+ indexes = [box.index(step) for step in steps]
+ self.assertTrue(all(i >= 0 for i in indexes), box.call_log())
+ self.assertEqual(indexes, sorted(indexes))
+ self.assertGreaterEqual(box.index("launchctl: bootout"), 0)
+
+ def test_keep_data_keeps_the_cua_home_but_still_signs_out(self):
+ box = self.box()
+ installed_mac(box)
+ result = box.run("--yes", "--keep-data", "--prefix", str(box.home))
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ for kept in (".cua/config.toml", ".cua/cache/blob", ".cua/volume/cache/block", ".cua/sandboxes/studio/disk.img",
+ "Library/Application Support/com.trycua.spaces.macos/settings.json"):
+ self.assertTrue(box.exists(kept), kept)
+ for gone in ("Applications/Cua Spaces.app", ".local/bin/cua", ".cua/credentials.json",
+ "Library/LaunchAgents/com.trycua.spacesd.host.plist"):
+ self.assertFalse(box.exists(gone), gone)
+ # Only the session item goes; the device key and agent keys stay.
+ self.assertIn("run.cua.ai|cua-cli.device-key", box.keychain_items())
+ self.assertNotIn("run.cua.ai|cua-cli", box.keychain_items())
+ self.assertGreaterEqual(box.index("auth logout"), 0)
+
+ def test_running_spaces_are_listed_and_stopped_but_not_deleted(self):
+ box = self.box()
+ installed_mac(box)
+ box.spaces.write_text("ID STATUS LOCATION KIND RUNTIME EXPIRES\n"
+ "local:studio ready local container gvisor -\n"
+ "local:old stopped local vm qemu -\n")
+ result = box.run("--yes", "--prefix", str(box.home))
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ self.assertIn("local:studio", result.stdout)
+ self.assertGreaterEqual(box.index("spaces stop local:studio"), 0)
+ self.assertEqual(box.index("spaces stop local:old"), -1)
+ self.assertEqual(box.index("sandbox rm"), -1)
+ self.assertLess(box.index("spaces stop local:studio"), box.index("daemon stop"))
+ self.assertTrue(box.exists(".cua/sandboxes/studio/disk.img"))
+
+ def test_delete_spaces_stops_then_deletes_everything_including_the_keyvault(self):
+ box = self.box()
+ installed_mac(box)
+ box.spaces.write_text("ID STATUS LOCATION KIND RUNTIME EXPIRES\n"
+ "local:studio ready local container gvisor -\n"
+ "local:old stopped local vm qemu -\n")
+ result = box.run("--yes", "--delete-spaces", "--prefix", str(box.home))
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ self.assertIn("DELETES the Spaces", result.stdout)
+ self.assertLess(box.index("spaces stop local:studio"), box.index("sandbox rm local:studio --force"))
+ self.assertGreaterEqual(box.index("sandbox rm local:old --force"), 0)
+ self.assertFalse(box.exists(".cua"))
+ self.assertEqual(box.keychain_items(), ["Other App|me"])
+
+ def test_a_running_app_is_asked_to_quit_before_anything_else(self):
+ box = self.box()
+ installed_mac(box)
+ running = box.root / "app-running"
+ running.write_text("")
+ write_executable(box.bin / "pgrep", f'#!/bin/sh\n[ -f {shlex.quote(str(running))} ]\n')
+ write_executable(box.bin / "osascript", f'#!/bin/sh\nprintf "osascript: %s\\n" "$*" >>"$FAKE_CALLS"\nrm -f {shlex.quote(str(running))}\n')
+ result = box.run("--yes", "--prefix", str(box.home))
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ quit_at = box.index('osascript: -e tell application id "com.trycua.spaces.macos" to quit')
+ self.assertGreaterEqual(quit_at, 0, box.call_log())
+ self.assertLess(quit_at, box.index("daemon stop"))
+ self.assertEqual(box.index("pkill"), -1)
+
+ def test_nothing_is_deleted_without_asking_when_there_is_no_terminal(self):
+ box = self.box()
+ installed_mac(box)
+ before = sorted(str(p) for p in box.home.rglob("*"))
+ result = box.run("--prefix", str(box.home))
+ self.assertEqual(result.returncode, 1)
+ self.assertIn("rerun with --yes", result.stderr)
+ self.assertEqual(before, sorted(str(p) for p in box.home.rglob("*")))
+
+ def test_idempotent_and_safe_when_nothing_or_only_a_part_is_installed(self):
+ box = self.box()
+ result = box.run("--yes")
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ self.assertIn("nothing to remove", result.stdout)
+ # Only the CLI is there.
+ box.cli()
+ result = box.run("--yes")
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ self.assertFalse(box.exists(".local/bin/cua"))
+ again = box.run("--yes")
+ self.assertEqual(again.returncode, 0)
+ self.assertIn("nothing to remove", again.stdout)
+
+ def test_a_cua_that_is_not_the_cua_cli_is_left_alone(self):
+ box = self.box()
+ box.put(".local/bin/cua", "#!/usr/bin/env python3\nprint('cua 0.9')\n", 0o755)
+ box.put(".cua/config.toml", "x\n")
+ result = box.run("--yes")
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ self.assertTrue(box.exists(".local/bin/cua"))
+ self.assertFalse(box.exists(".cua/config.toml"))
+
+ def test_the_path_line_stays_while_cua_driver_lives_in_the_same_folder(self):
+ box = self.box()
+ box.cli()
+ box.put(".local/bin/cua-driver", "driver\n", 0o755)
+ box.put(".zshrc", PATH_BLOCK.format(home=box.home))
+ result = box.run("--yes")
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ self.assertIn("# Added by the cua installer", (box.home / ".zshrc").read_text())
+ self.assertIn("Cua Driver is separate", result.stdout)
+
+ def test_no_modify_path_never_edits_the_profile(self):
+ box = self.box()
+ box.cli()
+ box.put(".zshrc", PATH_BLOCK.format(home=box.home))
+ before = (box.home / ".zshrc").read_text()
+ result = box.run("--yes", "--no-modify-path")
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ self.assertEqual((box.home / ".zshrc").read_text(), before)
+
+ def test_a_volume_that_cannot_be_unmounted_keeps_every_file(self):
+ box = self.box()
+ installed_mac(box)
+ mounts = box.root / "mounts.txt"
+ mounts.write_text(f"localhost:/ on {box.home}/Cua Volume (nfs, nodev, nosuid)\n")
+ result = box.run("--yes", "--delete-spaces", "--prefix", str(box.home), env={"FAKE_MOUNTS": str(mounts)})
+ self.assertEqual(result.returncode, 1, result.stdout + result.stderr)
+ self.assertIn("still mounted", result.stderr)
+ self.assertTrue(box.exists(".cua/volume/data/notes.txt"))
+ self.assertTrue(box.exists(".cua/sandboxes/studio/disk.img"))
+
+ def test_a_machine_wide_install_is_removed_too(self):
+ box = self.box()
+ box.put_sys("Applications/Cua Spaces.app/Contents/MacOS/CuaSpacesMac", "app\n", 0o755)
+ link = box.sys / "usr/local/bin/cua"
+ link.parent.mkdir(parents=True)
+ link.symlink_to("/Applications/Cua Spaces.app/Contents/MacOS/cua")
+ box.put_sys("usr/local/bin/other", "keep\n", 0o755)
+ result = box.run("--yes")
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ self.assertFalse((box.sys / "Applications/Cua Spaces.app").exists())
+ self.assertFalse(link.is_symlink())
+ self.assertTrue((box.sys / "usr/local/bin/other").exists())
+
+ def test_an_app_with_another_bundle_id_is_left_alone(self):
+ box = self.box()
+ app = box.put_sys("Applications/Cua Spaces.app/Contents/Info.plist", "plist\n").parent.parent
+ write_executable(box.bin / "defaults", "#!/bin/sh\necho com.example.other\n")
+ result = box.run("--yes")
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ self.assertTrue(app.exists())
+
+ def test_the_contradicting_flags_are_refused(self):
+ result = self.box().run("--keep-data", "--delete-spaces", "--yes")
+ self.assertEqual(result.returncode, 1)
+ self.assertIn("contradict", result.stderr)
+
+ def test_unknown_options_and_help(self):
+ box = self.box()
+ self.assertEqual(box.run("--nope").returncode, 1)
+ helped = box.run("--help")
+ self.assertEqual(helped.returncode, 0)
+ for flag in ("--keep-data", "--delete-spaces", "--all", "--dry-run", "--yes", "--prefix"):
+ self.assertIn(flag, helped.stdout)
+
+ def test_a_home_that_is_the_users_home_is_never_deleted(self):
+ box = self.box()
+ box.put("Documents/keep.txt", "mine\n")
+ box.put("sandboxes/a/disk", "disk\n")
+ result = box.run("--yes", "--delete-spaces", env={"CUA_HOME": str(box.home)})
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ self.assertTrue(box.exists("Documents/keep.txt"))
+ self.assertIn("not touching", result.stderr)
+
+ def test_a_custom_cua_home_without_cua_files_is_left_alone(self):
+ box = self.box()
+ box.put("elsewhere/notes.txt", "mine\n")
+ box.put(".cua/config.toml", "x\n")
+ result = box.run("--yes", "--delete-spaces", env={"CUA_HOME": str(box.home / "elsewhere")})
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ self.assertTrue(box.exists("elsewhere/notes.txt"))
+ self.assertIn("no Cua files", result.stderr)
+
+
+class OtherToolsTest(unittest.TestCase):
+ """--all runs the Cua Driver and Lume uninstallers (served here, not cua.ai)."""
+
+ def setUp(self):
+ self.tmp = tempfile.TemporaryDirectory()
+ self.addCleanup(self.tmp.cleanup)
+ served = Path(self.tmp.name) / "served"
+ (served / "driver").mkdir(parents=True)
+ (served / "lume").mkdir(parents=True)
+ self.log = Path(self.tmp.name) / "tools.log"
+ for name in ("driver", "lume"):
+ (served / name / "uninstall.sh").write_text(f'#!/bin/bash\necho "{name} $*" >>{shlex.quote(str(self.log))}\n')
+
+ class Handler(http.server.SimpleHTTPRequestHandler):
+ def __init__(self, *a, **k):
+ super().__init__(*a, directory=str(served), **k)
+
+ def log_message(self, *a):
+ pass
+
+ self.server = http.server.ThreadingHTTPServer(("127.0.0.1", 0), Handler)
+ threading.Thread(target=self.server.serve_forever, daemon=True).start()
+ self.addCleanup(self.server.shutdown)
+ self.base = f"http://127.0.0.1:{self.server.server_address[1]}"
+
+ def env(self):
+ return {
+ "CUA_UNINSTALL_DRIVER_URL": f"{self.base}/driver/uninstall.sh",
+ "CUA_UNINSTALL_LUME_URL": f"{self.base}/lume/uninstall.sh",
+ }
+
+ def test_all_runs_both_uninstallers_and_keeps_lume_vms_by_default(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.assertEqual(self.log.read_text().splitlines(), ["driver ", "lume --force"])
+
+ def test_all_with_delete_spaces_purges_lume(self):
+ box = Sandbox(tempfile.mkdtemp(dir=self.tmp.name), "Darwin")
+ box.cli()
+ result = box.run("--yes", "--all", "--delete-spaces", env=self.env())
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ self.assertEqual(self.log.read_text().splitlines(), ["driver ", "lume --force --purge"])
+
+ def test_on_linux_lume_is_skipped_and_the_driver_runs_even_with_nothing_else_installed(self):
+ box = Sandbox(tempfile.mkdtemp(dir=self.tmp.name), "Linux")
+ result = box.run("--yes", "--all", env=self.env())
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ self.assertEqual(self.log.read_text().splitlines(), ["driver "])
+
+ def test_a_plain_http_uninstaller_url_is_refused(self):
+ box = Sandbox(tempfile.mkdtemp(dir=self.tmp.name), "Linux")
+ result = box.run("--yes", "--all", env={"CUA_UNINSTALL_DRIVER_URL": "http://example.com/uninstall.sh"})
+ self.assertNotEqual(result.returncode, 0)
+ self.assertIn("non-HTTPS", result.stderr)
+ self.assertFalse(self.log.exists())
+
+
+class UninstallLinuxTest(unittest.TestCase):
+ def setUp(self):
+ self.tmp = tempfile.TemporaryDirectory()
+ self.addCleanup(self.tmp.cleanup)
+
+ def installed(self, box):
+ box.cli()
+ box.put(".local/bin/cua-spaces", "appimage\n", 0o755)
+ box.put(".local/share/applications/cua-spaces.desktop", "[Desktop Entry]\nName=Cua Spaces\nExec=cua-spaces\n")
+ box.put(".config/autostart/cua-spaces.desktop", "[Desktop Entry]\nName=Cua Spaces\nExec=cua-spaces --hidden\n")
+ box.put(".config/autostart/other.desktop", "[Desktop Entry]\nName=Other\nExec=other\n")
+ box.put(".config/systemd/user/cua-spacesd-host.service", "[Unit]\n")
+ box.put(".config/Cua Spaces/settings.json", "{}\n")
+ box.put(".local/share/cua-spaces/daemon/1/cua", "daemon\n", 0o755)
+ box.put(".bashrc", PATH_BLOCK.format(home=box.home))
+ box.put(".cua/host/config.json", "{}\n")
+ box.put(".cua/credentials.json", "{}\n")
+ box.put(".cua/sandboxes/a/disk", "disk\n")
+
+ def test_removes_the_appimage_autostart_service_and_state(self):
+ for shell in shells():
+ with self.subTest(shell=shell):
+ box = Sandbox(tempfile.mkdtemp(dir=self.tmp.name), "Linux", shell=shell)
+ self.installed(box)
+ result = box.run("--yes", "--prefix", str(box.home / "nowhere"))
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ for gone in (".local/bin/cua", ".local/bin/cua-spaces", ".local/share/applications/cua-spaces.desktop",
+ ".config/autostart/cua-spaces.desktop", ".config/systemd/user/cua-spacesd-host.service",
+ ".config/Cua Spaces", ".local/share/cua-spaces", ".cua/host", ".cua/credentials.json"):
+ self.assertFalse(box.exists(gone), gone)
+ self.assertTrue(box.exists(".config/autostart/other.desktop"))
+ self.assertTrue(box.exists(".cua/sandboxes/a/disk"))
+ self.assertEqual((box.home / ".bashrc").read_text(), "")
+ self.assertGreaterEqual(box.index("systemctl: --user disable --now cua-spacesd-host"), 0)
+ self.assertGreaterEqual(box.index("host remove --force --uninstalling"), 0)
+
+ def test_the_deb_is_removed_with_apt_as_root(self):
+ box = Sandbox(self.tmp.name, "Linux")
+ write_executable(box.bin / "dpkg-query", "#!/bin/sh\nprintf 'install ok installed'\n")
+ result = box.run("--yes", env={"FAKE_UID": "0"})
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ self.assertGreaterEqual(box.index("apt-get: remove -y cua-spaces"), 0)
+
+ def test_the_deb_without_privileges_says_what_to_run(self):
+ box = Sandbox(self.tmp.name, "Linux")
+ write_executable(box.bin / "dpkg-query", "#!/bin/sh\nprintf 'install ok installed'\n")
+ write_executable(box.bin / "sudo", "#!/bin/sh\nexit 1\n")
+ result = box.run("--yes")
+ self.assertEqual(result.returncode, 1)
+ self.assertIn("sudo apt-get remove cua-spaces", result.stderr)
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/scripts/install/tests/uninstall.Tests.ps1 b/scripts/install/tests/uninstall.Tests.ps1
new file mode 100644
index 0000000000..a5464ef9d1
--- /dev/null
+++ b/scripts/install/tests/uninstall.Tests.ps1
@@ -0,0 +1,226 @@
+# Pester 5 tests for uninstall.ps1. Hermetic: temp folders for LOCALAPPDATA,
+# APPDATA and CUA_HOME, and every step that would touch the machine (the app's
+# uninstaller, scheduled tasks, Run keys, the user PATH, Credential Manager,
+# running programs, the cua CLI) is replaced by a mock that records its call.
+# pwsh -c "Invoke-Pester scripts/install/tests -Output Detailed"
+
+BeforeAll {
+ $script:Uninstaller = Join-Path $PSScriptRoot '..' 'uninstall.ps1'
+ $env:CUA_UNINSTALL_NO_RUN = '1'
+ . $script:Uninstaller
+ $env:CUA_UNINSTALL_NO_RUN = $null
+ $script:Saved = @{}
+ foreach ($name in 'LOCALAPPDATA', 'APPDATA', 'CUA_HOME', 'CUA_UNINSTALL_NONINTERACTIVE') {
+ $script:Saved[$name] = [Environment]::GetEnvironmentVariable($name)
+ }
+}
+
+AfterAll {
+ foreach ($name in $script:Saved.Keys) { [Environment]::SetEnvironmentVariable($name, $script:Saved[$name]) }
+}
+
+Describe 'helpers' {
+ BeforeEach {
+ $script:Root = Join-Path ([IO.Path]::GetTempPath()) ("cua-ps-uninstall-" + [Guid]::NewGuid().ToString('N'))
+ New-Item -ItemType Directory -Force -Path $script:Root | Out-Null
+ $env:LOCALAPPDATA = Join-Path $script:Root 'local'
+ $env:APPDATA = Join-Path $script:Root 'roaming'
+ $KeepData = [switch]$false
+ $DeleteSpaces = [switch]$false
+ }
+ AfterEach { Remove-Item -Recurse -Force -LiteralPath $script:Root -ErrorAction SilentlyContinue }
+
+ It 'keeps the sign-in entries, the device key and the Keyvault apart' {
+ $targets = @('cua-cli.run.cua.ai', 'cua-cli.device-key.run.cua.ai', 'cua-cli.agent-keys.run.cua.ai', 'cua-cli.staging.run.cua.ai',
+ 'vault-1.Cua Keyvault', 'vault-1.Cua Keyvault Generation', 'MicrosoftAccount:[email protected]', 'git:https://github.com', 'cua-cli.run.example.com')
+ $picked = @(Select-CuaCredentialTargets $targets)
+ $picked | Should -Be @('cua-cli.run.cua.ai', 'cua-cli.device-key.run.cua.ai', 'cua-cli.agent-keys.run.cua.ai', 'cua-cli.staging.run.cua.ai')
+ $KeepData = [switch]$true
+ @(Select-CuaCredentialTargets $targets) | Should -Be @('cua-cli.run.cua.ai', 'cua-cli.staging.run.cua.ai')
+ $KeepData = [switch]$false
+ $DeleteSpaces = [switch]$true
+ @(Select-CuaCredentialTargets $targets) | Should -Contain 'vault-1.Cua Keyvault'
+ @(Select-CuaCredentialTargets $targets) | Should -Contain 'vault-1.Cua Keyvault Generation'
+ }
+
+ It 'never deletes a drive root, the profile or the app data folders' {
+ Test-SafePath $env:LOCALAPPDATA | Should -BeFalse
+ Test-SafePath $env:APPDATA | Should -BeFalse
+ Test-SafePath $HOME | Should -BeFalse
+ Test-SafePath '' | Should -BeFalse
+ Test-SafePath 'relative\path' | Should -BeFalse
+ Test-SafePath (Join-Path $env:LOCALAPPDATA 'x\..\..') | Should -BeFalse
+ Test-SafePath (Join-Path $env:LOCALAPPDATA 'Programs\Cua Spaces') | Should -BeTrue
+ }
+}
+
+Describe 'Invoke-CuaUninstall' {
+ BeforeEach {
+ $script:Root = Join-Path ([IO.Path]::GetTempPath()) ("cua-ps-uninstall-" + [Guid]::NewGuid().ToString('N'))
+ $script:Local = Join-Path $script:Root 'local'
+ $script:Roaming = Join-Path $script:Root 'roaming'
+ $script:CuaHome = Join-Path $script:Root 'cuahome'
+ New-Item -ItemType Directory -Force -Path $script:Local, $script:Roaming, $script:CuaHome | Out-Null
+ $env:LOCALAPPDATA = $script:Local
+ $env:APPDATA = $script:Roaming
+ $env:CUA_HOME = $script:CuaHome
+ $env:CUA_UNINSTALL_NONINTERACTIVE = '1'
+ $KeepData = [switch]$false; $DeleteSpaces = [switch]$false; $All = [switch]$false
+ $NoModifyPath = [switch]$false; $DryRun = [switch]$false; $Yes = [switch]$false; $Prefix = ''
+ $script:Calls = New-Object System.Collections.Generic.List[string]
+ $script:SpacesText = ''
+ $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"
+
+ # What install.ps1 and the app leave behind.
+ $script:Bin = Join-Path $script:Local 'Programs\cua\bin'
+ New-Item -ItemType Directory -Force -Path $script:Bin | Out-Null
+ Set-Content -LiteralPath (Join-Path $script:Bin 'cua.exe') -Value 'fake cua'
+ foreach ($rel in 'host\config.json', 'config.toml', 'credentials.json', 'cache\blob', 'telemetry\install_channel',
+ 'volume\cache\block', 'volume\data\notes.txt', 'sandboxes\studio\disk.img', 'vmm\state') {
+ $path = Join-Path $script:CuaHome $rel
+ New-Item -ItemType Directory -Force -Path (Split-Path -Parent $path) | Out-Null
+ Set-Content -LiteralPath $path -Value 'x'
+ }
+ New-Item -ItemType Directory -Force -Path (Join-Path $script:Roaming 'Cua Spaces') | Out-Null
+ Set-Content -LiteralPath (Join-Path $script:Roaming 'Cua Spaces\settings.json') -Value '{}'
+ $script:Entry = [pscustomobject]@{ Key = 'k'; InstallLocation = (Join-Path $script:Local 'Programs\Cua Spaces'); UninstallString = 'x'; QuietUninstallString = 'x'; WindowsInstaller = $false }
+
+ Mock Stop-CuaSpacesApp { $script:Calls.Add('stop-app') }
+ Mock Get-AppUninstallEntry { $script:Entry }
+ Mock Invoke-AppUninstaller { $script:Calls.Add('app-uninstaller'); 0 }
+ Mock Remove-AppRegistryKey { $script:Calls.Add('registry-key') }
+ Mock Remove-HostTask { $script:Calls.Add('host-task') }
+ Mock Remove-RunValue { param($Name) $script:Calls.Add("run-value $Name") }
+ Mock Get-UserPath { $script:UserPath }
+ Mock Set-UserPath { param($Value) $script:Calls.Add("user-path $Value"); $script:UserPath = $Value }
+ Mock Get-CredentialTargets { $script:Credentials }
+ Mock Remove-CredentialTarget { param($Target) $script:Calls.Add("credential $Target"); $true }
+ # The cua CLI: a file that says "fake cua" is the Cua CLI; anything else is not.
+ Mock Invoke-Bounded {
+ param($File, $Arguments, $Seconds)
+ $args1 = @($Arguments) -join ' '
+ if ($args1 -eq '--version') {
+ if ((Test-Path -LiteralPath $File) -and ((Get-Content -Raw -LiteralPath $File) -match 'fake cua')) {
+ return [pscustomobject]@{ ExitCode = 0; Output = "cua 1.2.3 (test)`n" }
+ }
+ return [pscustomobject]@{ ExitCode = 0; Output = "something else 9.9`n" }
+ }
+ $script:Calls.Add("cua[$env:CUA_HOME] $args1")
+ 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 = '' }
+ }
+ }
+ AfterEach {
+ $env:CUA_UNINSTALL_NONINTERACTIVE = $null
+ Remove-Item -Recurse -Force -LiteralPath $script:Root -ErrorAction SilentlyContinue
+ }
+
+ It 'prints the plan with -DryRun and changes nothing' {
+ $DryRun = [switch]$true; $All = [switch]$true; $DeleteSpaces = [switch]$true
+ $env:CUA_UNINSTALL_DRIVER_URL = 'https://example.invalid/driver/uninstall.ps1'
+ $out = Invoke-CuaUninstall *>&1 | Out-String
+ $env:CUA_UNINSTALL_DRIVER_URL = $null
+ $out | Should -Match 'Found on this PC'
+ $out | Should -Match '\[dry-run\] remove'
+ $out | Should -Match '\[dry-run\] cua host remove --force --uninstalling'
+ 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
+ }
+
+ It 'removes programs and settings by default and keeps Spaces data' {
+ $Yes = [switch]$true
+ $script:SpacesText = "ID STATUS LOCATION KIND RUNTIME EXPIRES`nlocal:studio ready local container gvisor -`nlocal:old stopped local vm qemu -"
+ Invoke-CuaUninstall *>&1 | Out-Null
+ Test-Path (Join-Path $script:Bin 'cua.exe') | Should -BeFalse
+ foreach ($gone in 'host', 'config.toml', 'credentials.json', 'cache', 'telemetry', 'volume\cache') {
+ Test-Path (Join-Path $script:CuaHome $gone) | Should -BeFalse -Because $gone
+ }
+ Get-Content -Raw (Join-Path $script:CuaHome 'volume\data\notes.txt') | Should -Match 'x'
+ Test-Path (Join-Path $script:CuaHome 'sandboxes\studio\disk.img') | Should -BeTrue
+ Test-Path (Join-Path $script:CuaHome 'vmm\state') | Should -BeTrue
+ Test-Path (Join-Path $script:Roaming 'Cua Spaces') | Should -BeFalse
+ $script:UserPath | Should -Be 'C:\Windows;C:\Tools'
+ $script:Calls | Should -Contain 'credential cua-cli.run.cua.ai'
+ $script:Calls | Should -Contain 'credential cua-cli.device-key.run.cua.ai'
+ $script:Calls | Should -Not -Contain 'credential vault-1.Cua Keyvault'
+ $script:Calls | Should -Not -Contain 'credential git:https://github.com'
+ $script:Calls | Should -Contain 'app-uninstaller'
+ $script:Calls | Should -Contain 'host-task'
+ # Running Spaces are stopped (their disks stay); nothing is deleted.
+ $script:Calls | Should -Contain "cua[$script:CuaHome] spaces stop local:studio"
+ @($script:Calls | Where-Object { $_ -like '*spaces stop local:old*' -or $_ -like '*sandbox rm*' }) | Should -BeNullOrEmpty
+ # In a safe order: Spaces, hosting, agents, daemon, sign-out.
+ $steps = @('spaces stop local:studio', 'host remove --force --uninstalling', 'agents remove --agents all --yes', 'daemon stop', 'auth logout')
+ $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 ',')
+ }
+
+ It 'keeps the cua home and the device key with -KeepData but still signs out' {
+ $Yes = [switch]$true; $KeepData = [switch]$true
+ Invoke-CuaUninstall *>&1 | Out-Null
+ foreach ($kept in 'config.toml', 'cache\blob', 'volume\cache\block', 'sandboxes\studio\disk.img') {
+ Test-Path (Join-Path $script:CuaHome $kept) | Should -BeTrue -Because $kept
+ }
+ Test-Path (Join-Path $script:CuaHome 'credentials.json') | Should -BeFalse
+ Test-Path (Join-Path $script:Roaming 'Cua Spaces\settings.json') | Should -BeTrue
+ Test-Path (Join-Path $script:Bin 'cua.exe') | Should -BeFalse
+ $script:Calls | Should -Contain 'credential cua-cli.run.cua.ai'
+ $script:Calls | Should -Not -Contain 'credential cua-cli.device-key.run.cua.ai'
+ @($script:Calls | Where-Object { $_ -like '*auth logout*' }) | Should -Not -BeNullOrEmpty
+ }
+
+ It 'stops, then deletes the Spaces, the home and the Keyvault with -DeleteSpaces -Yes' {
+ $Yes = [switch]$true; $DeleteSpaces = [switch]$true
+ $script:SpacesText = "ID STATUS LOCATION KIND RUNTIME EXPIRES`nlocal:studio ready local container gvisor -"
+ $out = Invoke-CuaUninstall *>&1 | Out-String
+ $out | Should -Match 'DELETES the Spaces'
+ $stop = $script:Calls.FindIndex([Predicate[string]] { param($c) $c -like '*spaces stop local:studio*' })
+ $rm = $script:Calls.FindIndex([Predicate[string]] { param($c) $c -like '*sandbox rm local:studio --force*' })
+ $stop | Should -BeGreaterThan -1
+ $rm | Should -BeGreaterThan $stop
+ Test-Path $script:CuaHome | Should -BeFalse
+ $script:Calls | Should -Contain 'credential vault-1.Cua Keyvault'
+ }
+
+ It 'refuses to remove anything without -Yes when there is no terminal' {
+ { Invoke-CuaUninstall *>&1 | Out-Null } | Should -Throw '*rerun with -Yes*'
+ Test-Path (Join-Path $script:Bin 'cua.exe') | Should -BeTrue
+ Test-Path (Join-Path $script:CuaHome 'config.toml') | Should -BeTrue
+ }
+
+ It 'leaves a cua.exe that is not the Cua CLI alone' {
+ $Yes = [switch]$true
+ Set-Content -LiteralPath (Join-Path $script:Bin 'cua.exe') -Value 'some other program'
+ Invoke-CuaUninstall *>&1 | Out-Null
+ Test-Path (Join-Path $script:Bin 'cua.exe') | Should -BeTrue
+ $script:UserPath | Should -Match 'Programs'
+ }
+
+ It 'never deletes a CUA_HOME that holds no Cua files' {
+ $Yes = [switch]$true; $DeleteSpaces = [switch]$true
+ $other = Join-Path $script:Root 'elsewhere'
+ New-Item -ItemType Directory -Force -Path $other | Out-Null
+ Set-Content -LiteralPath (Join-Path $other 'notes.txt') -Value 'mine'
+ $env:CUA_HOME = $other
+ Invoke-CuaUninstall *>&1 | Out-Null
+ Test-Path (Join-Path $other 'notes.txt') | Should -BeTrue
+ }
+
+ It 'says so and succeeds when nothing is installed' {
+ $Yes = [switch]$true
+ Remove-Item -Recurse -Force -LiteralPath $script:Bin, $script:CuaHome, (Join-Path $script:Roaming 'Cua Spaces')
+ $script:Entry = $null
+ $script:Credentials = @()
+ Mock Get-AppUninstallEntry { $null }
+ $out = Invoke-CuaUninstall *>&1 | Out-String
+ $out | Should -Match 'nothing to remove'
+ $script:Calls.Count | Should -Be 0
+ }
+}
diff --git a/scripts/install/uninstall.ps1 b/scripts/install/uninstall.ps1
new file mode 100644
index 0000000000..4c07216f0d
--- /dev/null
+++ b/scripts/install/uninstall.ps1
@@ -0,0 +1,556 @@
+<#
+.SYNOPSIS
+Cua uninstaller for Windows: removes what install.ps1 and the Cua Spaces app put on this PC.
+
+.DESCRIPTION
+ irm https://cua.ai/uninstall.ps1 | iex
+ & ([scriptblock]::Create((irm https://cua.ai/uninstall.ps1))) -DryRun
+ & ([scriptblock]::Create((irm https://cua.ai/uninstall.ps1))) -Yes -KeepData
+
+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.
+
+.PARAMETER KeepData
+Keep %USERPROFILE%\.cua (settings, the Spaces registry, caches, the Cua Volume
+cache, device key). Programs, services, integrations and your sign-in are still removed.
+.PARAMETER DeleteSpaces
+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.
+.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.
+.PARAMETER Yes
+Accept every prompt (non-interactive).
+#>
+[CmdletBinding()]
+param(
+ [switch]$KeepData,
+ [switch]$DeleteSpaces,
+ [switch]$All,
+ [string]$Prefix = '',
+ [switch]$NoModifyPath,
+ [switch]$DryRun,
+ [switch]$Yes
+)
+
+# Windows PowerShell 5.1 started from PowerShell 7 inherits pwsh's module path
+# and cannot load its own utility modules; see install.ps1.
+if ($PSVersionTable.PSEdition -eq 'Desktop') {
+ $desktopModules = Join-Path $PSHOME 'Modules'
+ $modulePaths = @($desktopModules) + @(($env:PSModulePath -split ';') | Where-Object {
+ $_ -and ($_ -notmatch '\\PowerShell\\') -and ($_.TrimEnd('\') -ne $desktopModules.TrimEnd('\'))
+ })
+ $env:PSModulePath = $modulePaths -join ';'
+}
+
+$DriverUrl = if ($env:CUA_UNINSTALL_DRIVER_URL) { $env:CUA_UNINSTALL_DRIVER_URL } else { 'https://cua.ai/driver/uninstall.ps1' }
+# Settings and local state inside the cua home, removed unless -KeepData.
+# Spaces and their data (sandboxes, vmm, images, volume\data, the Keyvault,
+# trajectories, spaces.json) are not on this list: only -DeleteSpaces removes them.
+$DisposableNames = @('cache', 'cache.json', 'daemon.json', 'daemon.starting', 'fleet-gc.lock', 'config', 'config.toml',
+ 'env-tokens.json', 'do_target.json', 'host_consented', 'host', 'spacesd', 'telemetry', 'skills', 'bin', 'runtimes',
+ 'spaces-install-mode', 'volume\cache')
+# The sign-in goes with the uninstall even with -KeepData.
+$SessionFiles = @('credentials.json', 'spaces-session.json', 'spaces-credentials.json')
+$script:Failed = $false
+
+function Write-Info([string]$Message) { Write-Host "cua-uninstall: $Message" }
+function Write-Warn([string]$Message) { Write-Warning "cua-uninstall: $Message" }
+function Stop-Uninstall([string]$Message) { throw "cua-uninstall: error: $Message" }
+
+function Test-Interactive {
+ if ($env:CUA_UNINSTALL_NONINTERACTIVE -eq '1') { return $false }
+ try { return [Environment]::UserInteractive -and -not [Console]::IsInputRedirected } catch { return $false }
+}
+
+# Asks a yes/no question; the default is no. -Yes accepts.
+function Confirm-Step([string]$Question) {
+ if ($Yes) { return $true }
+ if (-not (Test-Interactive)) { return $false }
+ $answer = Read-Host "$Question [y/N]"
+ return ($answer -match '^(y|yes)$')
+}
+
+function Get-CuaHome {
+ if ($env:CUA_HOME) { return $env:CUA_HOME }
+ return (Join-Path $HOME '.cua')
+}
+
+function Get-LocalAppData {
+ if ($env:LOCALAPPDATA) { return $env:LOCALAPPDATA }
+ return (Join-Path $HOME 'AppData\Local')
+}
+
+function Get-RoamingAppData {
+ if ($env:APPDATA) { return $env:APPDATA }
+ return (Join-Path $HOME 'AppData\Roaming')
+}
+
+# A path this script may delete: not a drive root, the profile or a system or
+# program folder.
+function Test-SafePath([string]$Path) {
+ if (-not $Path -or -not [IO.Path]::IsPathRooted($Path)) { return $false }
+ if ($Path -match '(^|[\\/])\.\.([\\/]|$)') { return $false }
+ $full = [IO.Path]::GetFullPath($Path).TrimEnd('\', '/')
+ $guards = @($HOME, $env:USERPROFILE, (Get-LocalAppData), (Get-RoamingAppData), $env:ProgramFiles, ${env:ProgramFiles(x86)},
+ $env:SystemRoot, $env:SystemDrive, (Join-Path (Get-LocalAppData) 'Programs')) | Where-Object { $_ }
+ foreach ($guard in $guards) {
+ if ($full -ieq ([IO.Path]::GetFullPath($guard).TrimEnd('\', '/'))) { return $false }
+ }
+ return ($full.Length -gt 3 -and -not ($full -match '^[A-Za-z]:$'))
+}
+
+# Removes a file or folder when it exists; says so when it cannot.
+function Remove-CuaPath([string]$Path) {
+ if (-not (Test-Path -LiteralPath $Path)) { return }
+ if (-not (Test-SafePath $Path)) { Write-Warn "not touching $Path"; return }
+ if ($DryRun) { Write-Host "[dry-run] remove $Path"; return }
+ Remove-Item -LiteralPath $Path -Recurse -Force -ErrorAction SilentlyContinue
+ if (Test-Path -LiteralPath $Path) {
+ Write-Warn "could not remove $Path (is a program using it? close it and run this again)"
+ $script:Failed = $true
+ } else {
+ Write-Info "removed $Path"
+ }
+}
+
+# Removes a folder only when it is empty.
+function Remove-EmptyDirectory([string]$Path) {
+ if ($DryRun -or -not (Test-Path -LiteralPath $Path -PathType Container) -or -not (Test-SafePath $Path)) { return }
+ if (-not (Get-ChildItem -LiteralPath $Path -Force -ErrorAction SilentlyContinue)) {
+ Remove-Item -LiteralPath $Path -Force -ErrorAction SilentlyContinue
+ }
+}
+
+# Runs a program with no input and kills it after Seconds. Returns ExitCode and Output.
+function Invoke-Bounded([string]$File, [string[]]$Arguments, [int]$Seconds) {
+ $out = Join-Path ([IO.Path]::GetTempPath()) ('cua-uninstall-' + [Guid]::NewGuid().ToString('N') + '.out')
+ $err = "$out.err"
+ try {
+ $params = @{ FilePath = $File; PassThru = $true; NoNewWindow = $true; RedirectStandardOutput = $out; RedirectStandardError = $err }
+ if ($Arguments -and $Arguments.Count -gt 0) {
+ $params.ArgumentList = @($Arguments | ForEach-Object { if ($_ -match '\s') { '"' + $_ + '"' } else { $_ } })
+ }
+ $process = Start-Process @params
+ $null = $process.Handle
+ if (-not $process.WaitForExit($Seconds * 1000)) {
+ Stop-Process -Id $process.Id -Force -ErrorAction SilentlyContinue
+ return [pscustomobject]@{ ExitCode = 124; Output = '' }
+ }
+ $text = if (Test-Path -LiteralPath $out) { Get-Content -Raw -LiteralPath $out } else { '' }
+ return [pscustomobject]@{ ExitCode = $process.ExitCode; Output = "$text" }
+ } catch {
+ return [pscustomobject]@{ ExitCode = 127; Output = '' }
+ } finally {
+ Remove-Item -LiteralPath $out, $err -Force -ErrorAction SilentlyContinue
+ }
+}
+
+# A cua.exe that Cua put there: `cua --version` says `cua X.Y.Z`.
+function Test-CuaCli([string]$Path) {
+ if (-not (Test-Path -LiteralPath $Path -PathType Leaf)) { return $false }
+ $result = Invoke-Bounded $Path @('--version') 10
+ return ($result.ExitCode -eq 0 -and $result.Output -match '^cua \d+\.\d+\.\d+')
+}
+
+function Get-CuaCliCandidates {
+ $list = @()
+ if ($Prefix) { $list += (Join-Path $Prefix 'bin\cua.exe') }
+ $list += (Join-Path (Get-LocalAppData) 'Programs\cua\bin\cua.exe')
+ return @($list | Select-Object -Unique)
+}
+
+function Find-Cua {
+ $candidates = @()
+ $candidates += Get-CuaCliCandidates
+ $onPath = Get-Command cua -CommandType Application -ErrorAction SilentlyContinue | Select-Object -First 1
+ if ($onPath) { $candidates += $onPath.Source }
+ $candidates += (Join-Path (Get-LocalAppData) 'Programs\Cua Spaces\resources\native\cua.exe')
+ if ($env:ProgramFiles) { $candidates += (Join-Path $env:ProgramFiles 'Cua Spaces\resources\native\cua.exe') }
+ foreach ($candidate in $candidates) {
+ if (Test-CuaCli $candidate) { return $candidate }
+ }
+ return $null
+}
+
+# Runs the cua CLI for a removal step (bounded, no usage telemetry).
+function Invoke-Cua([string]$Label, [int]$Seconds, [string[]]$Arguments, [hashtable]$Environment = @{}) {
+ if ($DryRun) { Write-Host "[dry-run] cua $($Arguments -join ' ')"; return }
+ Write-Info $Label
+ $saved = @{}
+ $vars = @{ CUA_TELEMETRY = '0'; DO_NOT_TRACK = '1' }
+ foreach ($k in $Environment.Keys) { $vars[$k] = $Environment[$k] }
+ foreach ($k in $vars.Keys) { $saved[$k] = [Environment]::GetEnvironmentVariable($k); [Environment]::SetEnvironmentVariable($k, $vars[$k]) }
+ try {
+ $result = Invoke-Bounded $script:Cua $Arguments $Seconds
+ if ($result.ExitCode -ne 0) { Write-Warn "'cua $($Arguments -join ' ')' did not finish; continuing" }
+ return $result
+ } finally {
+ foreach ($k in $saved.Keys) { [Environment]::SetEnvironmentVariable($k, $saved[$k]) }
+ }
+}
+
+# The cua homes: the main one and one per environment (~/.cua/envs/staging).
+function Get-CuaHomes {
+ $home1 = Get-CuaHome
+ if (-not (Test-Path -LiteralPath $home1 -PathType Container)) { return @() }
+ $list = @($home1)
+ $envs = Join-Path $home1 'envs'
+ if (Test-Path -LiteralPath $envs -PathType Container) {
+ $list += @(Get-ChildItem -LiteralPath $envs -Directory -ErrorAction SilentlyContinue | ForEach-Object { $_.FullName })
+ }
+ return $list
+}
+
+# "ID STATUS" rows for each local Space, from `cua sandbox ls --local`.
+function Get-LocalSpaces {
+ if (-not $script:Cua) { return @() }
+ $result = Invoke-Bounded $script:Cua @('sandbox', 'ls', '--local', '--no-size') 30
+ if ($result.ExitCode -ne 0) { return @() }
+ $rows = @()
+ $lines = @($result.Output -split "`r?`n" | Where-Object { $_.Trim() })
+ for ($i = 1; $i -lt $lines.Count; $i++) {
+ $cells = @($lines[$i].Trim() -split '\s+')
+ if ($cells.Count -ge 2 -and $cells[0] -ne 'No') { $rows += [pscustomobject]@{ Id = $cells[0]; Status = $cells[1] } }
+ }
+ return $rows
+}
+
+# --- the Windows-specific steps (small, so tests can replace them) ---------------
+
+function Stop-CuaSpacesApp {
+ $running = @(Get-Process -Name 'Cua Spaces' -ErrorAction SilentlyContinue)
+ if ($running.Count -eq 0) { return }
+ if ($DryRun) { Write-Host '[dry-run] quit Cua Spaces'; return }
+ Write-Info 'quitting Cua Spaces'
+ foreach ($p in $running) { $null = $p.CloseMainWindow() }
+ $deadline = (Get-Date).AddSeconds(10)
+ while ((Get-Process -Name 'Cua Spaces' -ErrorAction SilentlyContinue) -and (Get-Date) -lt $deadline) { Start-Sleep -Milliseconds 500 }
+ Get-Process -Name 'Cua Spaces' -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue
+}
+
+# The Cua Spaces app's entry in Add or remove programs (per user, or per machine).
+function Get-AppUninstallEntry {
+ $roots = @('HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall', 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall',
+ 'HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall')
+ foreach ($root in $roots) {
+ if (-not (Test-Path $root)) { continue }
+ foreach ($key in Get-ChildItem $root -ErrorAction SilentlyContinue) {
+ $props = Get-ItemProperty $key.PSPath -ErrorAction SilentlyContinue
+ if ($props.DisplayName -eq 'Cua Spaces') {
+ return [pscustomobject]@{
+ Key = $key.PSChildName
+ InstallLocation = $props.InstallLocation
+ UninstallString = $props.UninstallString
+ QuietUninstallString = $props.QuietUninstallString
+ WindowsInstaller = ($props.WindowsInstaller -eq 1)
+ }
+ }
+ }
+ }
+ return $null
+}
+
+# Runs the app's own uninstaller silently: it also stops the host service and
+# removes launch at login and the CLI the app put on PATH.
+function Invoke-AppUninstaller($Entry) {
+ if ($Entry.WindowsInstaller) {
+ $proc = Start-Process -FilePath 'msiexec.exe' -ArgumentList @('/x', $Entry.Key, '/qn', '/norestart') -Wait -PassThru
+ return $proc.ExitCode
+ }
+ $command = if ($Entry.QuietUninstallString) { $Entry.QuietUninstallString } else { "$($Entry.UninstallString) /S" }
+ if ($command -notmatch '^\s*"?([^"]+?\.exe)"?\s*(.*)$') { return 1 }
+ $start = @{ FilePath = $Matches[1]; Wait = $true; PassThru = $true }
+ if ($Matches[2]) { $start.ArgumentList = $Matches[2] }
+ $proc = Start-Process @start
+ # The NSIS uninstaller hands over to a copy of itself: wait for the folder to go.
+ $deadline = (Get-Date).AddSeconds(90)
+ while ($Entry.InstallLocation -and (Test-Path -LiteralPath $Entry.InstallLocation) -and (Get-Date) -lt $deadline) {
+ Start-Sleep -Milliseconds 500
+ }
+ return $proc.ExitCode
+}
+
+function Remove-AppRegistryKey {
+ Remove-Item -Path 'HKCU:\Software\ai.cua.spaces.desktop' -Recurse -Force -ErrorAction SilentlyContinue
+}
+
+function Remove-HostTask {
+ foreach ($task in @('Cua\SpacesdHost', 'Cua\EnvDriverHost')) {
+ $null = & schtasks.exe /End /TN $task 2>&1
+ $null = & schtasks.exe /Delete /TN $task /F 2>&1
+ }
+}
+
+function Remove-RunValue([string]$Name) {
+ foreach ($key in @('HKCU:\Software\Microsoft\Windows\CurrentVersion\Run', 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\StartupApproved\Run')) {
+ if (Get-ItemProperty -Path $key -Name $Name -ErrorAction SilentlyContinue) {
+ Remove-ItemProperty -Path $key -Name $Name -ErrorAction SilentlyContinue
+ }
+ }
+}
+
+function Get-UserPath { return [Environment]::GetEnvironmentVariable('Path', 'User') }
+function Set-UserPath([string]$Value) { [Environment]::SetEnvironmentVariable('Path', $Value, 'User') }
+
+# The targets Windows Credential Manager holds, `cmdkey /list` style.
+function Get-CredentialTargets {
+ $targets = @()
+ if (-not (Get-Command cmdkey.exe -ErrorAction SilentlyContinue)) { return $targets }
+ foreach ($line in @(& cmdkey.exe /list 2>$null)) {
+ if ($line -match 'Target:\s*(?:LegacyGeneric:target=|Domain:target=)?(.+?)\s*$') { $targets += $Matches[1] }
+ }
+ return $targets
+}
+
+function Remove-CredentialTarget([string]$Target) {
+ $null = & cmdkey.exe "/delete:$Target" 2>&1
+ return ($LASTEXITCODE -eq 0)
+}
+
+# --- the removal steps --------------------------------------------------------
+
+# Credential Manager: the session and device key are `cua-cli[.name].run.cua.ai`
+# (`.staging.run.cua.ai` for staging); the Keyvault master key is `<id>.Cua Keyvault`.
+function Select-CuaCredentialTargets([string[]]$Targets) {
+ $picked = @()
+ foreach ($target in $Targets) {
+ $isSession = $target -match '^cua-cli\.(staging\.)?run\.cua\.ai$'
+ $isOther = $target -match '^cua-cli\..+\.(staging\.)?run\.cua\.ai$'
+ $isKeyvault = $target -match '\.Cua Keyvault( Generation)?$'
+ if ($isSession) { $picked += $target }
+ elseif ($isOther -and -not $KeepData) { $picked += $target }
+ elseif ($isKeyvault -and $DeleteSpaces) { $picked += $target }
+ }
+ return $picked
+}
+
+function Remove-CuaCredentials {
+ $targets = @(Select-CuaCredentialTargets @(Get-CredentialTargets))
+ foreach ($target in $targets) {
+ if ($DryRun) { Write-Host "[dry-run] remove the Credential Manager entry $target"; continue }
+ if (Remove-CredentialTarget $target) { Write-Info "removed the Credential Manager entry $target" }
+ else { Write-Warn "could not remove the Credential Manager entry $target; delete it in Control Panel, Credential Manager"; $script:Failed = $true }
+ }
+}
+
+function Remove-CuaCli {
+ foreach ($exe in Get-CuaCliCandidates) {
+ if (-not (Test-Path -LiteralPath $exe)) { continue }
+ if (Test-CuaCli $exe) {
+ Remove-CuaPath $exe
+ $bin = Split-Path -Parent $exe
+ Remove-EmptyDirectory $bin
+ Remove-EmptyDirectory (Split-Path -Parent $bin)
+ if (-not $NoModifyPath) { Remove-FromUserPath $bin }
+ } else {
+ Write-Info "leaving $exe (not the Cua CLI)"
+ }
+ }
+}
+
+# Takes a folder off the user PATH once it holds no cua.exe any more.
+function Remove-FromUserPath([string]$Dir) {
+ if (Test-Path -LiteralPath (Join-Path $Dir 'cua.exe')) { return }
+ $current = Get-UserPath
+ if (-not $current) { return }
+ $parts = @($current -split ';' | Where-Object { $_ })
+ $kept = @($parts | Where-Object { $_.TrimEnd('\') -ine $Dir.TrimEnd('\') })
+ if ($kept.Count -eq $parts.Count) { return }
+ if ($DryRun) { Write-Host "[dry-run] remove $Dir from the user PATH"; return }
+ Set-UserPath ($kept -join ';')
+ Write-Info "removed $Dir from your user PATH (new terminals pick it up)"
+}
+
+function Remove-CuaState {
+ $cuaHome = Get-CuaHome
+ if (-not (Test-Path -LiteralPath $cuaHome -PathType Container)) { return }
+ if ($DeleteSpaces) {
+ if (($env:CUA_HOME) -and -not $script:HomeRecognised) {
+ Write-Warn "CUA_HOME=$cuaHome has no Cua files in it; leaving it alone"
+ return
+ }
+ Remove-CuaPath $cuaHome
+ return
+ }
+ foreach ($h in Get-CuaHomes) {
+ foreach ($name in $SessionFiles) { Remove-CuaPath (Join-Path $h $name) }
+ if (-not $KeepData) {
+ foreach ($name in $DisposableNames) { Remove-CuaPath (Join-Path $h $name) }
+ }
+ Remove-EmptyDirectory (Join-Path $h 'volume')
+ }
+ if ($KeepData) { Write-Info "kept $cuaHome"; return }
+ if ($DryRun) { Write-Host "[dry-run] keep the Spaces and their data in $cuaHome (-DeleteSpaces removes them)"; return }
+ $envs = Join-Path $cuaHome 'envs'
+ if (Test-Path -LiteralPath $envs) {
+ Get-ChildItem -LiteralPath $envs -Directory -ErrorAction SilentlyContinue | ForEach-Object { Remove-EmptyDirectory $_.FullName }
+ Remove-EmptyDirectory $envs
+ }
+ Remove-EmptyDirectory $cuaHome
+ if (Test-Path -LiteralPath $cuaHome) {
+ $left = (Get-ChildItem -LiteralPath $cuaHome -Force | ForEach-Object { $_.Name }) -join ' '
+ Write-Info "kept in ${cuaHome}: $left (Spaces and their data; -DeleteSpaces removes them)"
+ }
+}
+
+# A CUA_HOME that was set by hand is only deleted when Cua files are in it,
+# checked before any step removes some of them.
+$script:HomeRecognised = $true
+function Test-HomeRecognised {
+ if (-not $env:CUA_HOME) { return }
+ $script:HomeRecognised = $false
+ foreach ($name in @('host', 'sandboxes', 'vmm', 'daemon.json', 'config.toml', 'credentials.json', 'spaces.json', 'volume')) {
+ if (Test-Path -LiteralPath (Join-Path $env:CUA_HOME $name)) { $script:HomeRecognised = $true }
+ }
+}
+
+function Remove-CuaApp($Entry) {
+ if ($DryRun) {
+ if ($Entry) { Write-Host "[dry-run] run the Cua Spaces uninstaller ($($Entry.InstallLocation))" }
+ Write-Host '[dry-run] remove the host scheduled task and launch at login'
+ } else {
+ if ($Entry) {
+ Write-Info 'removing Cua Spaces (its own uninstaller, silent)'
+ $code = Invoke-AppUninstaller $Entry
+ if ($code -ne 0 -and $code -ne 3010) { Write-Warn "the Cua Spaces uninstaller exited with $code"; $script:Failed = $true }
+ if ($Entry.InstallLocation) { Remove-CuaPath $Entry.InstallLocation }
+ }
+ Remove-HostTask
+ Remove-RunValue 'ai.cua.spaces.desktop'
+ Remove-RunValue 'CuaSpacesdHost'
+ Remove-AppRegistryKey
+ }
+ if (-not $KeepData) { Remove-CuaPath (Join-Path (Get-RoamingAppData) 'Cua Spaces') }
+}
+
+function Invoke-OtherUninstaller([string]$Name, [string]$Url) {
+ if ($DryRun) { Write-Host "[dry-run] download $Url"; Write-Host "[dry-run] run the $Name uninstaller"; return }
+ if ($Url -notmatch '^https://' -and $Url -notmatch '^http://(127\.0\.0\.1|localhost)[:/]') {
+ Stop-Uninstall "refusing a non-HTTPS download: $Url"
+ }
+ $script = Join-Path ([IO.Path]::GetTempPath()) ("cua-$Name-uninstall-" + [Guid]::NewGuid().ToString('N') + '.ps1')
+ try {
+ Invoke-WebRequest -UseBasicParsing -Uri $Url -OutFile $script
+ Write-Info "running the $Name uninstaller"
+ $shell = (Get-Process -Id $PID).Path
+ if (-not $shell) { $shell = 'powershell.exe' }
+ & $shell -NoProfile -ExecutionPolicy Bypass -File $script
+ if ($LASTEXITCODE -ne 0) { Write-Warn "the $Name uninstaller did not finish"; $script:Failed = $true }
+ } catch {
+ Write-Warn "${Name}: $($_.Exception.Message)"
+ $script:Failed = $true
+ } finally {
+ Remove-Item -LiteralPath $script -Force -ErrorAction SilentlyContinue
+ }
+}
+
+function Invoke-CuaUninstall {
+ $script:Cua = Find-Cua
+ $entry = Get-AppUninstallEntry
+ $cuaHome = Get-CuaHome
+ $found = @()
+ if ($entry) { $found += "Cua Spaces app: $($entry.InstallLocation)" }
+ foreach ($exe in Get-CuaCliCandidates) { if ((Test-Path -LiteralPath $exe) -and (Test-CuaCli $exe)) { $found += "cua CLI: $exe" } }
+ if (Test-Path -LiteralPath $cuaHome) { $found += "cua state: $cuaHome" }
+ if (@(Select-CuaCredentialTargets @(Get-CredentialTargets)).Count -gt 0) { $found += 'Credential Manager entries: cua-cli' }
+ $appData = Join-Path (Get-RoamingAppData) 'Cua Spaces'
+ if (Test-Path -LiteralPath $appData) { $found += "app settings: $appData" }
+ if ($found.Count -eq 0 -and -not $All) {
+ Write-Info 'Cua does not look installed here; nothing to remove'
+ return
+ }
+ if ($found.Count -gt 0) {
+ Write-Host 'Found on this PC:'
+ $found | ForEach-Object { Write-Host " $_" }
+ if ($script:Cua) { Write-Host " (the removal steps run the cua at $($script:Cua))" }
+ }
+ if ($DryRun) { Write-Info 'dry run: nothing will be changed' }
+ Test-HomeRecognised
+ $spaces = @(Get-LocalSpaces)
+
+ 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.'
+ 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 (-not $Yes -and -not (Test-Interactive)) {
+ Stop-Uninstall 'no terminal to ask on; rerun with -Yes (or -DryRun to see what would be removed)'
+ }
+ if (-not (Confirm-Step 'Continue?')) { Write-Host 'Cancelled; nothing was removed.'; return }
+ if ($DeleteSpaces) {
+ Write-Host ''
+ Write-Host '-DeleteSpaces DELETES the Spaces on this PC and their data:'
+ $spaces | ForEach-Object { Write-Host " $($_.Id) $($_.Status)" }
+ Write-Host " ${cuaHome}: Space disks, the local Cua Volume files, the Keyvault. This cannot be undone."
+ if (-not $Yes) {
+ $answer = Read-Host 'Type "delete" to delete them, or anything else to cancel'
+ if ($answer -ne 'delete') { Write-Host 'Cancelled; nothing was removed.'; return }
+ }
+ }
+ }
+
+ Stop-CuaSpacesApp
+ if ($script:Cua) {
+ if ($spaces.Count -gt 0) {
+ Write-Host ''
+ Write-Host 'Spaces on this PC:'
+ $spaces | ForEach-Object { Write-Host " $($_.Id) $($_.Status)" }
+ }
+ foreach ($space in $spaces) {
+ if ($space.Status -in @('stopped', 'missing')) { continue }
+ if ($DryRun) { Write-Host "[dry-run] cua spaces stop $($space.Id)" }
+ else { Write-Info "stopping $($space.Id) (its disk is kept)"; $null = Invoke-Bounded $script:Cua @('spaces', 'stop', $space.Id) 90 }
+ }
+ if ($DeleteSpaces) {
+ foreach ($space in $spaces) {
+ if ($DryRun) { Write-Host "[dry-run] cua sandbox rm $($space.Id) --force" }
+ else { Write-Info "deleting Space $($space.Id)"; $null = Invoke-Bounded $script:Cua @('sandbox', 'rm', $space.Id, '--force') 120 }
+ }
+ }
+ foreach ($h in Get-CuaHomes) {
+ if (Test-Path -LiteralPath (Join-Path $h 'host\config.json')) {
+ $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')
+ 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')) {
+ $null = Invoke-Cua 'signing out of staging' 60 @('auth', 'logout') @{ CUA_ENV = 'staging' }
+ }
+ }
+ foreach ($h in Get-CuaHomes) {
+ foreach ($name in $SessionFiles) { Remove-CuaPath (Join-Path $h $name) }
+ }
+ Remove-CuaApp $entry
+ Remove-CuaCli
+ if ($All) { Invoke-OtherUninstaller 'cua-driver' $DriverUrl }
+ Remove-CuaCredentials
+ Remove-CuaState
+
+ if ($DryRun) { Write-Info 'dry run finished; nothing was changed'; return }
+ if (-not $All -and (Get-Command cua-driver -ErrorAction SilentlyContinue)) {
+ Write-Info 'Cua Driver is separate and was kept; run this with -All to remove it too'
+ }
+ if ($script:Failed) { Write-Info 'finished, but some steps need your attention (see the warnings above)'; $global:LASTEXITCODE = 1; return }
+ Write-Info 'done. To install again: irm https://cua.ai/install.ps1 | iex'
+}
+
+# Dot-sourcing with CUA_UNINSTALL_NO_RUN=1 loads the functions for tests.
+if ($env:CUA_UNINSTALL_NO_RUN -ne '1') {
+ if ($KeepData -and $DeleteSpaces) { Stop-Uninstall '-KeepData and -DeleteSpaces contradict each other' }
+ Invoke-CuaUninstall
+}
diff --git a/scripts/install/uninstall.sh b/scripts/install/uninstall.sh
new file mode 100755
index 0000000000..03c9caea2a
--- /dev/null
+++ b/scripts/install/uninstall.sh
@@ -0,0 +1,1153 @@
+#!/bin/sh
+# Cua uninstaller for macOS and Linux (Windows: uninstall.ps1). It removes what
+# install.sh and the Cua Spaces app put on this computer.
+#
+# curl -fsSL https://cua.ai/uninstall.sh | sh
+# curl -fsSL https://cua.ai/uninstall.sh | sh -s -- --dry-run
+# curl -fsSL https://cua.ai/uninstall.sh | sh -s -- --yes --keep-data
+# 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.
+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.
+
+Options:
+ --keep-data keep ~/.cua (settings, the Spaces registry, caches, the
+ Cua Volume cache, device key); programs, services,
+ integrations and your sign-in are still removed
+ --delete-spaces ALSO delete the Spaces on this computer and their data
+ (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
+ (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
+ -y, --yes accept every prompt (non-interactive)
+ -h, --help show this help
+
+Environment:
+ CUA_UNINSTALL_NONINTERACTIVE=1 never prompt (needs --yes to remove anything)
+ CUA_HOME cua state dir (default ~/.cua)
+EOF
+}
+
+# Test hooks: CUA_UNINSTALL_OS, CUA_UNINSTALL_DRIVER_URL, CUA_UNINSTALL_LUME_URL,
+# CUA_UNINSTALL_ROOT (a folder standing in for / when looking at /Applications,
+# /usr/local/bin, /opt and /etc).
+DRIVER_URL="${CUA_UNINSTALL_DRIVER_URL:-https://cua.ai/driver/uninstall.sh}"
+LUME_URL="${CUA_UNINSTALL_LUME_URL:-https://cua.ai/lume/uninstall.sh}"
+# Written above a PATH edit by install.sh and by the Cua Spaces app.
+MARKER="# Added by the cua installer"
+# Settings and local state inside the cua home, removed unless --keep-data.
+# Spaces and their data (sandboxes, vmm, images, volume/data, the Keyvault,
+# trajectories, spaces.json) are not on this list: only --delete-spaces removes them.
+DISPOSABLE="cache cache.json cua.sock keyvault.sock x.sock daemon.json daemon.starting fleet-gc.lock config config.toml env-tokens.json do_target.json host_consented host spacesd telemetry skills bin runtimes spaces-install-mode volume/cache"
+# The sign-in goes with the uninstall even with --keep-data.
+SESSION_FILES="credentials.json spaces-session.json spaces-credentials.json"
+
+keep_data=0
+delete_spaces=0
+all_tools=0
+prefix=""
+no_modify_path=0
+dry_run=0
+assume_yes=0
+tmp=""
+failed=0
+cua_bin=""
+
+say() { printf '%s\n' "$*"; }
+info() { printf 'cua-uninstall: %s\n' "$*"; }
+warn() { printf 'cua-uninstall: warning: %s\n' "$*" >&2; }
+die() {
+ printf 'cua-uninstall: error: %s\n' "$*" >&2
+ exit 1
+}
+
+cleanup() {
+ if [ -n "$tmp" ] && [ -d "$tmp" ]; then
+ rm -rf "$tmp"
+ fi
+}
+trap cleanup EXIT
+trap 'exit 130' INT TERM
+
+# ---------------------------------------------------------------- arguments
+
+parse_args() {
+ while [ $# -gt 0 ]; do
+ case "$1" in
+ --keep-data) keep_data=1 ;;
+ --delete-spaces) delete_spaces=1 ;;
+ --all) all_tools=1 ;;
+ --prefix)
+ [ $# -ge 2 ] || die "--prefix needs a directory"
+ prefix="$2"
+ shift
+ ;;
+ --prefix=*) prefix="${1#--prefix=}" ;;
+ --no-modify-path) no_modify_path=1 ;;
+ --dry-run) dry_run=1 ;;
+ -y | --yes) assume_yes=1 ;;
+ -h | --help)
+ usage
+ exit 0
+ ;;
+ *) die "unknown option: $1 (see --help)" ;;
+ esac
+ shift
+ done
+ if [ "$keep_data" = 1 ] && [ "$delete_spaces" = 1 ]; then
+ die "--keep-data and --delete-spaces contradict each other"
+ fi
+ case "$prefix" in
+ "" | /*) ;;
+ *) prefix="$(pwd)/$prefix" ;;
+ esac
+ prefix="${prefix%/}"
+}
+
+# ---------------------------------------------------------------- helpers
+
+has() { command -v "$1" >/dev/null 2>&1; }
+
+# Whether a human can answer prompts (curl | sh keeps /dev/tty usable).
+tty_ok() {
+ [ "${CUA_UNINSTALL_NONINTERACTIVE:-}" != 1 ] || return 1
+ [ -t 1 ] || [ -t 2 ] || return 1
+ (: </dev/tty) 2>/dev/null
+}
+
+# confirm "question": 0 for yes. Default is no.
+confirm() {
+ [ "$assume_yes" = 1 ] && return 0
+ tty_ok || return 1
+ printf '%s [y/N] ' "$1" >/dev/tty
+ answer=""
+ read -r answer </dev/tty || answer=""
+ case "$answer" in
+ [yY] | [yY][eE][sS]) return 0 ;;
+ *) return 1 ;;
+ esac
+}
+
+# bounded SECONDS COMMAND...: runs the command with no input and kills it
+# after SECONDS (macOS has no timeout(1)). Returns the command's status.
+bounded() {
+ secs="$1"
+ shift
+ "$@" </dev/null &
+ pid=$!
+ (
+ elapsed=0
+ while [ "$elapsed" -lt "$secs" ] && kill -0 "$pid" 2>/dev/null; do
+ sleep 1
+ elapsed=$((elapsed + 1))
+ done
+ if [ "$elapsed" -ge "$secs" ]; then kill "$pid" 2>/dev/null; fi
+ ) >/dev/null 2>&1 &
+ watchdog=$!
+ status=0
+ wait "$pid" || status=$?
+ kill "$watchdog" 2>/dev/null || true
+ wait "$watchdog" 2>/dev/null || true
+ return "$status"
+}
+
+# A path this script may delete: absolute, not a system or home directory.
+safe_path() {
+ case "$1" in
+ "" | / | //*) return 1 ;;
+ /*) ;;
+ *) return 1 ;;
+ esac
+ case "$1" in
+ */../* | */.. | */./* | */.) return 1 ;;
+ esac
+ candidate="${1%/}"
+ for guard in "$HOME" "$sysroot/Applications" "$sysroot/Library" "$sysroot/Users" "$sysroot/home" "$sysroot/usr" \
+ "$sysroot/usr/local" "$sysroot/usr/local/bin" "$sysroot/usr/bin" "$sysroot/opt" "$sysroot/etc" "$sysroot/var" /tmp \
+ "$HOME/Applications" "$HOME/Library" "$HOME/.local" "$HOME/.local/bin" "$HOME/.local/share" "$HOME/.config" "$HOME/.cache"; do
+ [ "$candidate" = "${guard%/}" ] && return 1
+ done
+ return 0
+}
+
+# rm_path PATH: remove a file, link or folder when it exists. Says so when it
+# cannot (a root-owned app) instead of stopping.
+rm_path() {
+ [ -e "$1" ] || [ -L "$1" ] || return 0
+ if ! safe_path "$1"; then
+ warn "not touching $1"
+ return 0
+ fi
+ if [ "$dry_run" = 1 ]; then
+ say "[dry-run] remove $1"
+ return 0
+ fi
+ if [ -d "$1" ] && [ ! -L "$1" ]; then
+ rm -rf -- "$1" 2>/dev/null || true
+ else
+ rm -f -- "$1" 2>/dev/null || true
+ fi
+ if [ -e "$1" ] || [ -L "$1" ]; then
+ warn "could not remove $1 (try: sudo rm -rf \"$1\")"
+ failed=1
+ else
+ info "removed $1"
+ fi
+}
+
+# rmdir_quiet DIR: remove DIR only when it is empty.
+rmdir_quiet() {
+ [ "$dry_run" = 1 ] && return 0
+ [ -d "$1" ] && [ ! -L "$1" ] || return 0
+ rmdir "$1" 2>/dev/null || true
+}
+
+# run COMMAND...: runs it, or only prints it with --dry-run.
+run() {
+ if [ "$dry_run" = 1 ]; then
+ say "[dry-run] $*"
+ else
+ "$@"
+ fi
+}
+
+# run_cua LABEL SECONDS ARGS...: the cua CLI, bounded, without usage telemetry.
+run_cua() {
+ label="$1"
+ secs="$2"
+ shift 2
+ if [ "$dry_run" = 1 ]; then
+ say "[dry-run] cua $*"
+ return 0
+ fi
+ info "$label"
+ if ! bounded "$secs" env CUA_TELEMETRY=0 DO_NOT_TRACK=1 "$cua_bin" "$@"; then
+ warn "'cua $*' did not finish; continuing"
+ fi
+}
+
+detect_platform() {
+ os="${CUA_UNINSTALL_OS:-$(uname -s)}"
+ case "$os" in
+ Darwin | darwin | macos) os=darwin ;;
+ Linux | linux) os=linux ;;
+ MINGW* | MSYS* | CYGWIN* | Windows_NT | windows)
+ die "on Windows, run: irm https://cua.ai/uninstall.ps1 | iex"
+ ;;
+ *) die "unsupported OS: $os" ;;
+ esac
+ [ -n "${HOME:-}" ] && [ -d "$HOME" ] || die "HOME is not set to a folder"
+ sysroot="${CUA_UNINSTALL_ROOT:-}"
+ sysroot="${sysroot%/}"
+ cua_home="${CUA_HOME:-$HOME/.cua}"
+ data_home="${XDG_DATA_HOME:-$HOME/.local/share}"
+ config_home="${XDG_CONFIG_HOME:-$HOME/.config}"
+}
+
+# ---------------------------------------------------------------- what is here
+
+# is_cua_cli FILE: the file is a cua CLI that Cua put there: a link into the
+# Cua Spaces app, or a program whose `--version` says `cua X.Y.Z`. A script
+# with the same name (a pip install) is left alone.
+is_cua_cli() {
+ if [ -L "$1" ]; then
+ case "$(readlink "$1" 2>/dev/null || true)" in
+ *"Cua Spaces.app"* | *"/Cua Spaces/"*) return 0 ;;
+ esac
+ fi
+ [ -f "$1" ] && [ -x "$1" ] || return 1
+ version="$(bounded 10 "$1" --version 2>/dev/null | head -n 1 || true)"
+ case "$version" in
+ "cua "[0-9]*.[0-9]*.[0-9]*) return 0 ;;
+ *) return 1 ;;
+ esac
+}
+
+# is_cua_app APP: an app folder named Cua Spaces.app that is Cua's (a bundle
+# with another identifier is somebody else's).
+is_cua_app() {
+ id=""
+ if has defaults && [ -f "$1/Contents/Info.plist" ]; then
+ id="$(defaults read "$1/Contents/Info" CFBundleIdentifier 2>/dev/null || true)"
+ fi
+ case "$id" in
+ "" | com.trycua.* | ai.cua.*) return 0 ;;
+ *) return 1 ;;
+ esac
+}
+
+cli_candidates() {
+ {
+ [ -z "$prefix" ] || printf '%s\n' "$prefix/bin/cua"
+ printf '%s\n' "$HOME/.local/bin/cua" "$sysroot/usr/local/bin/cua"
+ } | awk '!seen[$0]++'
+}
+
+app_candidates() {
+ case "$os" in
+ darwin)
+ {
+ [ -z "$prefix" ] || printf '%s\n' "$prefix/Applications/Cua Spaces.app"
+ printf '%s\n' "$sysroot/Applications/Cua Spaces.app" "$HOME/Applications/Cua Spaces.app"
+ } | awk '!seen[$0]++'
+ ;;
+ linux)
+ {
+ [ -z "$prefix" ] || printf '%s\n' "$prefix/bin/cua-spaces"
+ printf '%s\n' "$HOME/.local/bin/cua-spaces" "$sysroot/usr/local/bin/cua-spaces"
+ } | awk '!seen[$0]++'
+ ;;
+ esac
+}
+
+deb_installed() {
+ [ "$os" = linux ] && has dpkg-query &&
+ dpkg-query -W -f='${Status}' cua-spaces 2>/dev/null | grep -q 'install ok installed'
+}
+
+# find_cua: the cua CLI to run the removal steps with.
+find_cua() {
+ cua_bin=""
+ for candidate in "$(command -v cua 2>/dev/null || true)" "$HOME/.local/bin/cua" "$sysroot/usr/local/bin/cua" \
+ "$sysroot/Applications/Cua Spaces.app/Contents/MacOS/cua" "$HOME/Applications/Cua Spaces.app/Contents/MacOS/cua" \
+ "$sysroot/opt/Cua Spaces/resources/native/cua" "${prefix:+$prefix/bin/cua}" "${prefix:+$prefix/Applications/Cua Spaces.app/Contents/MacOS/cua}"; do
+ [ -n "$candidate" ] && [ -x "$candidate" ] || continue
+ version="$(bounded 10 "$candidate" --version 2>/dev/null | head -n 1 || true)"
+ case "$version" in
+ "cua "[0-9]*.[0-9]*.[0-9]*)
+ cua_bin="$candidate"
+ return 0
+ ;;
+ esac
+ done
+ return 0
+}
+
+host_service_files() {
+ case "$os" in
+ darwin)
+ printf '%s\n' "$HOME/Library/LaunchAgents/com.trycua.spacesd.host.plist" \
+ "$HOME/Library/LaunchAgents/com.trycua.env-driver.host.plist"
+ ;;
+ linux)
+ printf '%s\n' "$config_home/systemd/user/cua-spacesd-host.service" \
+ "$config_home/systemd/user/cua-env-driver-host.service" \
+ "$sysroot/etc/systemd/system/cua-spacesd-host.service" "$sysroot/etc/systemd/system/cua-env-driver-host.service"
+ ;;
+ esac
+}
+
+# cua homes: the main one and one per environment (~/.cua/envs/staging).
+cua_homes() {
+ [ -d "$cua_home" ] || return 0
+ printf '%s\n' "$cua_home"
+ for env_home in "$cua_home"/envs/*; do
+ [ -d "$env_home" ] && printf '%s\n' "$env_home"
+ done
+ return 0
+}
+
+library_dirs_removed_always() {
+ [ "$os" = darwin ] || return 0
+ printf '%s\n' "$HOME/Library/Caches/com.trycua.spaces.macos" \
+ "$HOME/Library/Caches/com.trycua.cua-spaces" \
+ "$HOME/Library/Saved Application State/com.trycua.spaces.macos.savedState" \
+ "$HOME/Library/HTTPStorages/com.trycua.spaces.macos" \
+ "$HOME/Library/HTTPStorages/com.trycua.spaces.macos.binarycookies" \
+ "$HOME/Library/WebKit/com.trycua.spaces.macos"
+}
+
+library_dirs_removed_unless_keep() {
+ case "$os" in
+ darwin)
+ printf '%s\n' "$HOME/Library/Application Support/com.trycua.spaces.macos" \
+ "$HOME/Library/Preferences/com.trycua.spaces.macos.plist"
+ ;;
+ linux)
+ printf '%s\n' "$config_home/Cua Spaces"
+ ;;
+ esac
+}
+
+kc_has() {
+ has security && bounded 20 security find-generic-password -s "$1" >/dev/null 2>&1
+}
+
+# ---------------------------------------------------------------- survey
+
+found=0
+found_lines=""
+add_found() {
+ found=1
+ found_lines="$found_lines $1
+"
+}
+
+survey() {
+ while IFS= read -r app; do
+ [ -n "$app" ] || continue
+ if { [ -e "$app" ] || [ -L "$app" ]; } && { [ "$os" != darwin ] || is_cua_app "$app"; }; then
+ add_found "Cua Spaces app: $app"
+ fi
+ done <<EOF
+$(app_candidates)
+EOF
+ if deb_installed; then
+ add_found "Cua Spaces package: cua-spaces (.deb)"
+ fi
+ while IFS= read -r cli; do
+ [ -n "$cli" ] || continue
+ if { [ -e "$cli" ] || [ -L "$cli" ]; } && is_cua_cli "$cli"; then
+ add_found "cua CLI: $cli"
+ fi
+ done <<EOF
+$(cli_candidates)
+EOF
+ while IFS= read -r svc; do
+ [ -n "$svc" ] || continue
+ if [ -e "$svc" ]; then
+ add_found "host service: $svc"
+ fi
+ done <<EOF
+$(host_service_files)
+EOF
+ if [ -d "$cua_home" ]; then
+ add_found "cua state: $cua_home"
+ fi
+ if [ "$os" = darwin ] && { kc_has run.cua.ai || kc_has staging.run.cua.ai; }; then
+ add_found "macOS Keychain items: run.cua.ai (sign-in, device key)"
+ fi
+ while IFS= read -r lib; do
+ [ -n "$lib" ] || continue
+ if [ -e "$lib" ]; then
+ add_found "app settings and caches: $lib"
+ fi
+ done <<EOF
+$(library_dirs_removed_always)
+$(library_dirs_removed_unless_keep)
+EOF
+ if [ "$found" = 1 ]; then
+ say "Found on this computer:"
+ printf '%s' "$found_lines"
+ if [ -n "$cua_bin" ]; then
+ say " (the removal steps run the cua at $cua_bin)"
+ fi
+ fi
+}
+
+# ---------------------------------------------------------------- Spaces
+
+# local_spaces: "ID STATUS" for each local Space.
+local_spaces() {
+ [ -n "$cua_bin" ] || return 0
+ bounded 30 env CUA_TELEMETRY=0 DO_NOT_TRACK=1 "$cua_bin" sandbox ls --local --no-size 2>/dev/null |
+ awk 'NR > 1 && $1 != "" && $1 != "No" && $1 != "ID" { print $1, $2 }' || true
+}
+
+# stop_spaces: lists the Spaces and stops the running ones (their disks stay).
+stop_spaces() {
+ [ -n "$spaces" ] || return 0
+ say ""
+ say "Spaces on this computer:"
+ printf '%s\n' "$spaces" | sed 's/^/ /'
+ while IFS= read -r row; do
+ [ -n "$row" ] || continue
+ id="${row%% *}"
+ state="${row#* }"
+ case "$state" in
+ stopped | missing) continue ;;
+ esac
+ if [ "$dry_run" = 1 ]; then
+ say "[dry-run] cua spaces stop $id"
+ else
+ info "stopping $id (its disk is kept)"
+ bounded 90 env CUA_TELEMETRY=0 DO_NOT_TRACK=1 "$cua_bin" spaces stop "$id" >/dev/null 2>&1 ||
+ warn "could not stop $id; it may still be running"
+ fi
+ done <<EOF
+$spaces
+EOF
+}
+
+delete_spaces_now() {
+ [ "$delete_spaces" = 1 ] || return 0
+ [ -n "$spaces" ] || return 0
+ while IFS= read -r row; do
+ [ -n "$row" ] || continue
+ id="${row%% *}"
+ if [ "$dry_run" = 1 ]; then
+ say "[dry-run] cua sandbox rm $id --force"
+ else
+ info "deleting Space $id"
+ bounded 120 env CUA_TELEMETRY=0 DO_NOT_TRACK=1 "$cua_bin" sandbox rm "$id" --force >/dev/null 2>&1 ||
+ warn "could not delete $id"
+ fi
+ done <<EOF
+$spaces
+EOF
+}
+
+# ---------------------------------------------------------------- the removal steps
+
+# The app's own executable only: the daemon it started is stopped, with the
+# Spaces, by the steps after it.
+app_patterns() {
+ case "$os" in
+ darwin) printf '%s\n' 'Cua Spaces\.app/Contents/MacOS/(CuaSpacesMac|Cua Spaces)( |$)' ;;
+ linux)
+ printf '%s\n' "^$sysroot/opt/Cua Spaces/cua-spaces( |\$)"
+ printf '%s\n' '^/tmp/\.mount_[^/]*/cua-spaces( |$)'
+ ;;
+ esac
+}
+
+app_running() {
+ while IFS= read -r pattern; do
+ [ -n "$pattern" ] || continue
+ if pgrep -f "$pattern" >/dev/null 2>&1; then return 0; fi
+ done <<EOF
+$(app_patterns)
+EOF
+ return 1
+}
+
+quit_app() {
+ has pgrep || return 0
+ app_running || return 0
+ if [ "$dry_run" = 1 ]; then
+ say "[dry-run] quit Cua Spaces"
+ return 0
+ fi
+ info "quitting Cua Spaces"
+ if [ "$os" = darwin ] && has osascript; then
+ bounded 15 osascript -e 'tell application id "com.trycua.spaces.macos" to quit' >/dev/null 2>&1 || true
+ fi
+ waited=0
+ while app_running && [ "$waited" -lt 10 ]; do
+ sleep 1
+ waited=$((waited + 1))
+ done
+ if app_running; then
+ while IFS= read -r pattern; do
+ [ -n "$pattern" ] || continue
+ pkill -TERM -f "$pattern" >/dev/null 2>&1 || true
+ done <<EOF
+$(app_patterns)
+EOF
+ sleep 2
+ while IFS= read -r pattern; do
+ [ -n "$pattern" ] || continue
+ pkill -KILL -f "$pattern" >/dev/null 2>&1 || true
+ done <<EOF
+$(app_patterns)
+EOF
+ fi
+}
+
+# The host service: `cua host remove` unregisters this computer from the relay
+# and removes the service; the unit or plist is removed directly when cua is
+# not there to do it.
+remove_host_service() {
+ while IFS= read -r h; do
+ [ -n "$h" ] || continue
+ if [ -f "$h/host/config.json" ] && [ -n "$cua_bin" ]; then
+ if [ "$dry_run" = 1 ]; then
+ say "[dry-run] CUA_HOME=$h cua host remove --force --uninstalling"
+ else
+ info "turning off hosting ($h)"
+ bounded 150 env CUA_HOME="$h" CUA_TELEMETRY=0 DO_NOT_TRACK=1 "$cua_bin" host remove --force --uninstalling ||
+ warn "could not tell the relay this computer is gone; remove it from Machines in Cua Spaces"
+ fi
+ fi
+ done <<EOF
+$(cua_homes)
+EOF
+ case "$os" in
+ darwin)
+ for label in com.trycua.spacesd.host com.trycua.env-driver.host; do
+ plist="$HOME/Library/LaunchAgents/$label.plist"
+ [ -f "$plist" ] || continue
+ if [ "$dry_run" = 1 ]; then
+ say "[dry-run] launchctl bootout gui/$(id -u)/$label"
+ else
+ launchctl bootout "gui/$(id -u)/$label" >/dev/null 2>&1 || launchctl unload "$plist" >/dev/null 2>&1 || true
+ fi
+ rm_path "$plist"
+ done
+ ;;
+ linux)
+ for unit in cua-spacesd-host cua-env-driver-host; do
+ user_unit="$config_home/systemd/user/$unit.service"
+ system_unit="$sysroot/etc/systemd/system/$unit.service"
+ if [ -f "$user_unit" ]; then
+ if [ "$dry_run" = 1 ]; then
+ say "[dry-run] systemctl --user disable --now $unit"
+ elif has systemctl; then
+ bounded 30 systemctl --user disable --now "$unit" >/dev/null 2>&1 || true
+ fi
+ rm_path "$user_unit"
+ [ "$dry_run" = 1 ] || { has systemctl && bounded 20 systemctl --user daemon-reload >/dev/null 2>&1 || true; }
+ fi
+ if [ -f "$system_unit" ] && [ "$(id -u)" = 0 ]; then
+ if [ "$dry_run" = 1 ]; then
+ say "[dry-run] systemctl disable --now $unit"
+ elif has systemctl; then
+ bounded 30 systemctl disable --now "$unit" >/dev/null 2>&1 || true
+ fi
+ rm_path "$system_unit"
+ [ "$dry_run" = 1 ] || { has systemctl && bounded 20 systemctl daemon-reload >/dev/null 2>&1 || true; }
+ elif [ -f "$system_unit" ]; then
+ warn "the system service $system_unit needs root: sudo systemctl disable --now $unit && sudo rm $system_unit"
+ failed=1
+ fi
+ done
+ ;;
+ esac
+ # A host driver copy still running from the cua home.
+ if [ -d "$cua_home/host/bin" ] && [ "$dry_run" = 0 ] && has pkill; then
+ pkill -f "$cua_home/host/bin/" >/dev/null 2>&1 || true
+ fi
+}
+
+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
+}
+
+stop_daemon() {
+ [ -n "$cua_bin" ] || return 0
+ while IFS= read -r h; do
+ [ -n "$h" ] || continue
+ if [ "$dry_run" = 1 ]; then
+ say "[dry-run] CUA_HOME=$h cua daemon stop"
+ else
+ bounded 30 env CUA_HOME="$h" CUA_TELEMETRY=0 DO_NOT_TRACK=1 "$cua_bin" daemon stop >/dev/null 2>&1 || true
+ fi
+ done <<EOF
+$(cua_homes)
+EOF
+}
+
+# Cua Volume is a mount (~/Cua Volume on macOS, ~/cua-volume on Linux): the
+# daemon unmounts it when it stops. Make sure, and never delete files while it
+# is mounted.
+volume_mounted=0
+app_removed=0
+unmount_volume() {
+ case "$os" in
+ darwin) mount_point="$HOME/Cua Volume" ;;
+ linux) mount_point="$HOME/cua-volume" ;;
+ esac
+ is_mounted "$mount_point" || return 0
+ if [ "$dry_run" = 1 ]; then
+ say "[dry-run] unmount $mount_point"
+ return 0
+ fi
+ info "unmounting $mount_point"
+ case "$os" in
+ darwin) bounded 30 umount "$mount_point" >/dev/null 2>&1 || bounded 30 diskutil unmount force "$mount_point" >/dev/null 2>&1 || true ;;
+ linux) bounded 30 fusermount -u "$mount_point" >/dev/null 2>&1 || bounded 30 umount "$mount_point" >/dev/null 2>&1 || true ;;
+ esac
+ if is_mounted "$mount_point"; then
+ warn "$mount_point is still mounted; leaving it and the Cua Volume files alone"
+ volume_mounted=1
+ failed=1
+ else
+ rmdir_quiet "$mount_point"
+ fi
+}
+
+is_mounted() {
+ has mount || return 1
+ mount 2>/dev/null | grep -F " on $1 " >/dev/null 2>&1
+}
+
+# Sign out: revokes the session and removes the stored credentials.
+sign_out() {
+ if [ -n "$cua_bin" ]; then
+ run_cua "signing out (cua auth logout)" 60 auth logout
+ if [ -d "$cua_home/envs/staging" ]; then
+ if [ "$dry_run" = 1 ]; then
+ say "[dry-run] CUA_ENV=staging cua auth logout"
+ else
+ bounded 60 env CUA_ENV=staging CUA_TELEMETRY=0 DO_NOT_TRACK=1 "$cua_bin" auth logout >/dev/null 2>&1 || true
+ fi
+ fi
+ fi
+ while IFS= read -r h; do
+ [ -n "$h" ] || continue
+ for name in $SESSION_FILES; do
+ rm_path "$h/$name"
+ done
+ done <<EOF
+$(cua_homes)
+EOF
+}
+
+# remove_app: the Cua Spaces app and what it put outside its own folder.
+remove_app() {
+ case "$os" in
+ darwin)
+ while IFS= read -r app; do
+ [ -n "$app" ] || continue
+ if is_cua_app "$app"; then
+ rm_path "$app"
+ if [ "$dry_run" = 0 ] && [ ! -e "$app" ]; then app_removed=1; fi
+ else
+ info "leaving $app (not the Cua Spaces app)"
+ fi
+ done <<EOF
+$(app_candidates)
+EOF
+ if [ "$(id -u)" = 0 ] && has pkgutil && pkgutil --pkg-info com.trycua.spaces.app >/dev/null 2>&1; then
+ run pkgutil --forget com.trycua.spaces.app >/dev/null 2>&1 || true
+ fi
+ ;;
+ linux)
+ if deb_installed; then
+ if [ "$dry_run" = 1 ]; then
+ say "[dry-run] apt-get remove -y cua-spaces"
+ elif [ "$(id -u)" = 0 ]; then
+ info "removing the cua-spaces package"
+ apt-get remove -y cua-spaces </dev/null >/dev/null 2>&1 || {
+ warn "could not remove the cua-spaces package: apt-get remove cua-spaces"
+ failed=1
+ }
+ elif has sudo && sudo -n true 2>/dev/null; then
+ info "removing the cua-spaces package"
+ sudo -n apt-get remove -y cua-spaces </dev/null >/dev/null 2>&1 || {
+ warn "could not remove the cua-spaces package: sudo apt-get remove cua-spaces"
+ failed=1
+ }
+ else
+ warn "the cua-spaces package needs root: sudo apt-get remove cua-spaces"
+ failed=1
+ fi
+ fi
+ while IFS= read -r app; do
+ [ -n "$app" ] || continue
+ rm_path "$app"
+ done <<EOF
+$(app_candidates)
+EOF
+ for entry in "${prefix:+$prefix/share/applications/cua-spaces.desktop}" "$data_home/applications/cua-spaces.desktop" "$config_home/autostart/cua-spaces.desktop"; do
+ [ -n "$entry" ] || continue
+ if [ -f "$entry" ] && grep -q 'cua-spaces\|Cua Spaces' "$entry" 2>/dev/null; then
+ rm_path "$entry"
+ fi
+ done
+ rm_path "$data_home/cua-spaces"
+ ;;
+ esac
+ while IFS= read -r lib; do
+ [ -n "$lib" ] || continue
+ rm_path "$lib"
+ done <<EOF
+$(library_dirs_removed_always)
+EOF
+ if [ "$keep_data" = 0 ]; then
+ if [ "$os" = darwin ] && has defaults && [ "$dry_run" = 0 ]; then
+ bounded 10 defaults delete com.trycua.spaces.macos >/dev/null 2>&1 || true
+ fi
+ while IFS= read -r lib; do
+ [ -n "$lib" ] || continue
+ rm_path "$lib"
+ done <<EOF
+$(library_dirs_removed_unless_keep)
+EOF
+ fi
+}
+
+remove_cli() {
+ while IFS= read -r cli; do
+ [ -n "$cli" ] || continue
+ [ -e "$cli" ] || [ -L "$cli" ] || continue
+ if is_cua_cli "$cli"; then
+ rm_path "$cli"
+ else
+ info "leaving $cli (not the Cua CLI)"
+ fi
+ done <<EOF
+$(cli_candidates)
+EOF
+}
+
+# The PATH line that install.sh and the app wrote under $MARKER. Kept when
+# cua-driver or lume still live in the same folder.
+shared_bin_dirs() {
+ for dir in "$HOME/.local/bin" "${prefix:+$prefix/bin}" /usr/local/bin; do
+ [ -n "$dir" ] || continue
+ if [ "$all_tools" = 0 ] && { [ -e "$dir/cua-driver" ] || [ -e "$dir/lume" ]; }; then
+ printf '%s\n' "$dir"
+ fi
+ done
+}
+
+clean_profiles() {
+ [ "$no_modify_path" = 0 ] || return 0
+ shared="$(shared_bin_dirs | tr '\n' ' ')"
+ seen_profiles=" "
+ for profile in "${ZDOTDIR:-$HOME}/.zshrc" "$HOME/.zshrc" "$HOME/.bash_profile" "$HOME/.bashrc" "$HOME/.profile" "$config_home/fish/config.fish"; do
+ [ -f "$profile" ] || continue
+ case "$seen_profiles" in
+ *" $profile "*) continue ;;
+ esac
+ seen_profiles="$seen_profiles$profile "
+ grep -qF "$MARKER" "$profile" 2>/dev/null || continue
+ if [ "$dry_run" = 1 ]; then
+ say "[dry-run] remove the PATH line the cua installer added to $profile"
+ continue
+ fi
+ edited="$tmp/profile.edited"
+ awk -v marker="$MARKER" -v shared="$shared" '
+ function dir_of(line, d) {
+ d = line
+ if (sub(/^export PATH="/, "", d)) { sub(/:\$PATH"$/, "", d); return d }
+ if (sub(/^fish_add_path "/, "", d)) { sub(/"$/, "", d); return d }
+ return ""
+ }
+ function is_path_line(line) {
+ return line ~ /^export PATH="[^"]*:\$PATH"$/ || line ~ /^fish_add_path "[^"]*"$/
+ }
+ { lines[NR] = $0 }
+ END {
+ n = split(shared, kept, " ")
+ for (k = 1; k <= n; k++) keep[kept[k]] = 1
+ i = 1
+ while (i <= NR) {
+ if (lines[i] == marker && i < NR && is_path_line(lines[i + 1]) && !(dir_of(lines[i + 1]) in keep)) {
+ if (out_n > 0 && out[out_n] == "") out_n--
+ i += 2
+ continue
+ }
+ out[++out_n] = lines[i]
+ i++
+ }
+ for (j = 1; j <= out_n; j++) print out[j]
+ }' "$profile" >"$edited"
+ if cmp -s "$edited" "$profile"; then
+ info "kept the PATH line in $profile (cua-driver or lume still lives in that folder)"
+ else
+ if cat "$edited" >"$profile" 2>/dev/null; then
+ info "removed the PATH line from $profile (open a new terminal to pick it up)"
+ else
+ warn "could not edit $profile; remove the '$MARKER' line and the one after it by hand"
+ failed=1
+ fi
+ fi
+ done
+}
+
+# clean_state: the cua home. Settings and local state go unless --keep-data;
+# Spaces and their data only with --delete-spaces.
+clean_state() {
+ [ -d "$cua_home" ] || return 0
+ if [ "$delete_spaces" = 1 ]; then
+ if [ "$volume_mounted" = 1 ]; then
+ warn "not deleting $cua_home while Cua Volume is mounted"
+ return 0
+ fi
+ delete_home
+ return 0
+ fi
+ while IFS= read -r h; do
+ [ -n "$h" ] || continue
+ for name in $SESSION_FILES; do
+ rm_path "$h/$name"
+ done
+ if [ "$keep_data" = 0 ]; then
+ for name in $DISPOSABLE; do
+ rm_path "$h/$name"
+ done
+ fi
+ rmdir_quiet "$h/volume"
+ done <<EOF
+$(cua_homes)
+EOF
+ if [ "$keep_data" = 1 ]; then
+ info "kept $cua_home"
+ elif [ "$dry_run" = 1 ]; then
+ say "[dry-run] keep the Spaces and their data in $cua_home (--delete-spaces removes them)"
+ elif [ -d "$cua_home" ]; then
+ for env_home in "$cua_home"/envs/*; do
+ rmdir_quiet "$env_home"
+ done
+ rmdir_quiet "$cua_home/envs"
+ rmdir_quiet "$cua_home"
+ if [ -d "$cua_home" ]; then
+ kept=""
+ for entry in "$cua_home"/* "$cua_home"/.[!.]*; do
+ [ -e "$entry" ] && kept="$kept${entry##*/} "
+ done
+ info "kept in $cua_home: $kept(Spaces and their data; --delete-spaces removes them)"
+ fi
+ fi
+}
+
+# delete_home: the whole cua home, for --delete-spaces. A CUA_HOME that Cua did
+# not create (no Cua files inside) is left alone.
+delete_home() {
+ if [ -n "${CUA_HOME:-}" ] && [ "$home_recognised" = 0 ]; then
+ warn "CUA_HOME=$cua_home has no Cua files in it; leaving it alone"
+ return 0
+ fi
+ rm_path "$cua_home"
+}
+
+# A CUA_HOME that was set by hand is only deleted when Cua files are in it,
+# checked before any step removes some of them.
+home_recognised=1
+recognise_home() {
+ [ -n "${CUA_HOME:-}" ] || return 0
+ home_recognised=0
+ for name in host sandboxes vmm daemon.json config.toml credentials.json spaces.json volume keyvault.sock; do
+ if [ -e "$cua_home/$name" ]; then home_recognised=1; fi
+ done
+}
+
+# macOS Keychain: the session and device key live under service run.cua.ai
+# (staging.run.cua.ai for staging); the Keyvault master key under "Cua Keyvault".
+kc_delete_all() { # service
+ kc_has "$1" || return 0
+ if [ "$dry_run" = 1 ]; then
+ say "[dry-run] remove the Keychain items of service $1"
+ return 0
+ fi
+ n=0
+ while [ "$n" -lt 20 ] && bounded 20 security delete-generic-password -s "$1" >/dev/null 2>&1; do
+ n=$((n + 1))
+ done
+ if kc_has "$1"; then
+ warn "could not remove every Keychain item of '$1'; delete them in Keychain Access (search for $1)"
+ failed=1
+ else
+ info "removed $n Keychain item(s) of '$1'"
+ fi
+}
+
+kc_delete_account() { # service account
+ bounded 20 security find-generic-password -s "$1" -a "$2" >/dev/null 2>&1 || return 0
+ if [ "$dry_run" = 1 ]; then
+ say "[dry-run] remove the Keychain item $1 / $2"
+ return 0
+ fi
+ if bounded 20 security delete-generic-password -s "$1" -a "$2" >/dev/null 2>&1; then
+ info "removed the Keychain item $1 / $2"
+ else
+ warn "could not remove the Keychain item $1 / $2; delete it in Keychain Access"
+ failed=1
+ fi
+}
+
+remove_secrets() {
+ case "$os" in
+ darwin)
+ has security || return 0
+ for service in run.cua.ai staging.run.cua.ai; do
+ if [ "$keep_data" = 1 ]; then
+ kc_delete_account "$service" cua-cli
+ else
+ kc_delete_all "$service"
+ fi
+ done
+ if [ "$delete_spaces" = 1 ]; then
+ kc_delete_all "Cua Keyvault"
+ kc_delete_all "Cua Keyvault Generation"
+ fi
+ ;;
+ linux)
+ # Only used when the Secret Service holds Cua items (forced keychain store, Keyvault).
+ has secret-tool || return 0
+ if [ "$dry_run" = 1 ]; then
+ say "[dry-run] secret-tool clear service run.cua.ai"
+ return 0
+ fi
+ if [ "$keep_data" = 0 ]; then
+ bounded 20 secret-tool clear service run.cua.ai >/dev/null 2>&1 || true
+ bounded 20 secret-tool clear service staging.run.cua.ai >/dev/null 2>&1 || true
+ fi
+ if [ "$delete_spaces" = 1 ]; then
+ bounded 20 secret-tool clear service "Cua Keyvault" >/dev/null 2>&1 || true
+ bounded 20 secret-tool clear service "Cua Keyvault Generation" >/dev/null 2>&1 || true
+ fi
+ ;;
+ esac
+}
+
+# ---------------------------------------------------------------- other Cua tools
+
+check_url() {
+ case "$1" in
+ *[[:space:]]* | http://*@*) die "refusing a malformed URL: $1" ;;
+ https://*) ;;
+ http://127.0.0.1[:/]* | http://localhost[:/]* | http://\[::1\][:/]*) ;;
+ *) die "refusing a non-HTTPS download: $1" ;;
+ esac
+}
+
+fetch() { # URL DEST
+ check_url "$1"
+ if has curl; then
+ case "$1" in
+ https://*) proto='=https' ;;
+ *) proto='=https,http' ;;
+ esac
+ curl --proto "$proto" --proto-redir "$proto" --tlsv1.2 -fsSL --retry 3 -o "$2" "$1"
+ elif has wget; then
+ wget -q -O "$2" "$1"
+ else
+ return 1
+ fi
+}
+
+# run_other_uninstaller NAME URL ARGS...: Cua Driver's and Lume's own
+# uninstallers (bash scripts), the same ones cua.ai serves.
+run_other_uninstaller() {
+ name="$1"
+ url="$2"
+ shift 2
+ if [ "$dry_run" = 1 ]; then
+ say "[dry-run] download $url"
+ say "[dry-run] bash $name-uninstall.sh${*:+ $*}"
+ return 0
+ fi
+ has bash || {
+ warn "$name: its uninstaller needs bash; run it by hand: /bin/bash -c \"\$(curl -fsSL $url)\""
+ failed=1
+ return 0
+ }
+ script="$tmp/$name-uninstall.sh"
+ if ! fetch "$url" "$script"; then
+ warn "$name: could not download $url"
+ failed=1
+ return 0
+ fi
+ info "running the $name uninstaller"
+ bash "$script" "$@" </dev/null || {
+ warn "the $name uninstaller did not finish"
+ failed=1
+ }
+}
+
+remove_other_tools() {
+ [ "$all_tools" = 1 ] || return 0
+ run_other_uninstaller cua-driver "$DRIVER_URL"
+ if [ "$os" = darwin ]; then
+ if [ "$delete_spaces" = 1 ]; then
+ run_other_uninstaller lume "$LUME_URL" --force --purge
+ else
+ run_other_uninstaller lume "$LUME_URL" --force
+ fi
+ fi
+}
+
+# ---------------------------------------------------------------- main
+
+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."
+ if [ "$keep_data" = 1 ]; then
+ say "It keeps $cua_home and the Cua Volume cache (--keep-data)."
+ elif [ "$delete_spaces" = 1 ]; then
+ say "It also deletes Cua's settings and caches."
+ else
+ 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)."
+ 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)"
+ fi
+ confirm "Continue?" || {
+ say "Cancelled; nothing was removed."
+ exit 0
+ }
+ if [ "$delete_spaces" = 1 ]; then
+ say ""
+ say "--delete-spaces DELETES the Spaces on this computer and their data:"
+ if [ -n "${spaces:-}" ]; then
+ printf '%s\n' "$spaces" | sed 's/^/ /'
+ fi
+ say " $cua_home: Space disks, the local Cua Volume files, the Keyvault. This cannot be undone."
+ if [ "$assume_yes" = 0 ]; then
+ printf 'Type "delete" to delete them, or anything else to cancel: ' >/dev/tty
+ answer=""
+ read -r answer </dev/tty || answer=""
+ [ "$answer" = delete ] || {
+ say "Cancelled; nothing was removed."
+ exit 0
+ }
+ fi
+ fi
+}
+
+main() {
+ parse_args "$@"
+ detect_platform
+ tmp="$(mktemp -d "${TMPDIR:-/tmp}/cua-uninstall.XXXXXX" 2>/dev/null || mktemp -d -t cua-uninstall)"
+ find_cua
+ survey
+ if [ "$found" = 0 ] && [ "$all_tools" = 0 ]; then
+ info "Cua does not look installed here; nothing to remove"
+ exit 0
+ fi
+ if [ "$dry_run" = 1 ]; then
+ info "dry run: nothing will be changed"
+ fi
+ recognise_home
+ spaces="$(local_spaces)"
+ confirm_plan
+ quit_app
+ stop_spaces
+ delete_spaces_now
+ remove_host_service
+ remove_agent_integrations
+ stop_daemon
+ unmount_volume
+ sign_out
+ remove_app
+ remove_cli
+ remove_other_tools
+ clean_profiles
+ clean_state
+ remove_secrets
+ if [ "$dry_run" = 1 ]; then
+ info "dry run finished; nothing was changed"
+ exit 0
+ fi
+ if has cua && [ "$all_tools" = 0 ]; then
+ info "another cua is still on your PATH at $(command -v cua); it was not installed by Cua's installer (pip, npm or Homebrew?), so remove it with the tool that installed it"
+ fi
+ if [ "$all_tools" = 0 ] && { has cua-driver || [ -e "$HOME/.local/bin/cua-driver" ]; }; then
+ info "Cua Driver is separate and was kept; run this with --all to remove it too"
+ fi
+ if [ "$app_removed" = 1 ]; then
+ info "the app registered itself as a login item, which a script cannot unregister; if Cua Spaces still shows in System Settings, Login Items, switch it off there"
+ fi
+ if [ "$failed" = 1 ]; then
+ info "finished, but some steps need your attention (see the warnings above)"
+ exit 1
+ fi
+ info "done. To install again: curl -fsSL https://cua.ai/install.sh | sh"
+}
+
+main "$@"