Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.
Rust agentai-agentapplecomputer-usecomputer-use-agentcontainerizationcuadesktop-automationhacktoberfestlumemacosmanusoperatorswiftvirtualizationvirtualization-frameworkwindowswindows-sandbox
installer: --pair reuses an installed cua and app instead of downloading again (CUA-1772) (#5318)
Francesco Bonacci980ce016f23a
diff --git a/scripts/install/README.md b/scripts/install/README.mdindex 5de40a8a77..ad036d8f56 100644--- a/scripts/install/README.md+++ b/scripts/install/README.md@@ -63,6 +63,8 @@ cua-driver lands where its own installer puts it: `~/.local/bin/cua-driver` (orOn Linux and macOS, when the bin dir is not on PATH, install.sh in a terminal asks once ("Add ... to PATH in ~/.zshrc? [Y/n]", Enter = yes). Without a terminal, or with `--yes`, it prints the exact one-line command for your shell instead and never edits a profile unless you pass `--modify-path`; `--no-modify-path` never edits it. `--pair` runs the CLI by its absolute path, so it works before PATH changes. install.ps1 adds the user PATH by default (`-NoModifyPath` opts out). `--mode` writes `~/.cua/spaces-install-mode`, which the app reads on first launch.+`--pair` (`-Pair`) on a computer that already has Cua reuses what is there: a `cua` that knows `host setup --pair` (on PATH, in `~/.local/bin`, or inside the Cua Spaces app) and, on macOS and Linux, the installed app. It then downloads nothing and does not read the release manifest. `--prefix`, `--version` and `CUA_INSTALL_REINSTALL=1` install anyway; an older `cua` without `--pair` is replaced as before.+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`).## Release manifestdiff --git a/scripts/install/install.ps1 b/scripts/install/install.ps1index 3a345e909e..64349dc0e4 100644--- a/scripts/install/install.ps1+++ b/scripts/install/install.ps1@@ -38,7 +38,9 @@ Preselect the app's first-run choice: host or client (implies spaces)..PARAMETER PairAdd this machine to your account with a one-time code from the Cua Spaces app(Add a machine): installs the CLI and runs `cua host setup --pair <code>`, with-no sign-in and no checklist.+no sign-in and no checklist. A computer that already has a cua with+`host setup --pair` uses it instead of downloading again; -Prefix, -Version or+CUA_INSTALL_REINSTALL=1 install anyway..PARAMETER RelayRelay for -Pair (default https://relay.cua.ai)..PARAMETER Version@@ -498,6 +500,23 @@ function Invoke-HostSetup([string]$Cua) {if ($LASTEXITCODE -ne 0) { Write-Warning "host setup did not finish; run 'cua host setup' after 'cua auth login'" }}+# -Pair on a computer that already has Cua: the `cua` that is there (it must+# know `host setup --pair`), or $null. -Prefix, -Version and+# CUA_INSTALL_REINSTALL=1 install anyway.+function Find-ExistingCua {+ if (-not $Pair -or $Prefix -or $Version -or $env:CUA_INSTALL_REINSTALL -eq '1') { return $null }+ $candidates = @()+ $onPath = Get-Command cua -CommandType Application -ErrorAction SilentlyContinue | Select-Object -First 1+ if ($onPath) { $candidates += $onPath.Source }+ if ($env:LOCALAPPDATA) { $candidates += (Join-Path $env:LOCALAPPDATA 'Programs\cua\bin\cua.exe') }+ foreach ($candidate in $candidates) {+ if (-not (Test-Path -LiteralPath $candidate)) { continue }+ $help = (& $candidate host setup --help 2>&1 | Out-String)+ if ($help -match '--pair') { return $candidate }+ }+ return $null+}+function Invoke-CuaInstall {# Function scope: `irm | iex` runs in the caller's session, so keep these local.Set-StrictMode -Version 3@@ -516,13 +535,23 @@ function Invoke-CuaInstall {$tmp = Join-Path ([IO.Path]::GetTempPath()) ("cua-install-" + [Guid]::NewGuid().ToString('N'))New-Item -ItemType Directory -Force -Path $tmp | Out-Nulltry {- $manifestUrl = Get-ManifestUrl- $manifestFile = Join-Path $tmp 'release-artifacts.json'- Get-Remote $manifestUrl $manifestFile- $manifest = Get-Content -Raw -LiteralPath $manifestFile | ConvertFrom-Json- if ($manifest.schema -ne 1) { Stop-Install "unsupported release manifest at $manifestUrl" }- Write-Info "platform $platform, manifest $manifestUrl"$cua = $null+ $existing = Find-ExistingCua+ if ($existing) {+ Write-Info "cua is already installed at $existing; using it (CUA_INSTALL_REINSTALL=1 installs it again)"+ $sel.cli = $false+ $cua = $existing+ }+ $manifestUrl = $null+ # Nothing to download (-Pair on a computer that has Cua): no manifest to read.+ if ($sel.cli -or $sel.spaces -or $sel['cua-driver']) {+ $manifestUrl = Get-ManifestUrl+ $manifestFile = Join-Path $tmp 'release-artifacts.json'+ Get-Remote $manifestUrl $manifestFile+ $manifest = Get-Content -Raw -LiteralPath $manifestFile | ConvertFrom-Json+ if ($manifest.schema -ne 1) { Stop-Install "unsupported release manifest at $manifestUrl" }+ Write-Info "platform $platform, manifest $manifestUrl"+ }if ($sel.cli) { $cua = Install-Cli $manifest $manifestUrl $platform $tmp }if ($sel.spaces) {if ($Mode) {diff --git a/scripts/install/install.sh b/scripts/install/install.shindex 32b093f6c4..925ef4275d 100755--- a/scripts/install/install.sh+++ b/scripts/install/install.sh@@ -22,6 +22,9 @@# from the Cua Spaces app (Add a machine): installs and# runs `cua host setup --pair CODE`, no sign-in, no checklist# --relay URL relay for --pair (default https://relay.cua.ai)+# A computer that already has a cua with `host setup --pair`+# (and the app) uses them instead of downloading again;+# --version, --prefix or CUA_INSTALL_REINSTALL=1 install anyway# --version VERSION install this CLI release (default: latest)# --prefix DIR install under DIR (DIR/bin, DIR/Applications)# --modify-path add the bin dir to your shell profile without asking@@ -34,6 +37,7 @@## Environment (mostly for testing and mirrors):# CUA_INSTALL_NONINTERACTIVE=1 never prompt (defaults plus --select)+# CUA_INSTALL_REINSTALL=1 with --pair, install the CLI and app even if present# CUA_INSTALL_MANIFEST_URL release-artifacts.json to read# CUA_INSTALL_BASE_URL release download base (default GitHub releases)# CUA_INSTALL_DRIVER_URL cua-driver installer (default cua.ai/driver/install.sh)@@ -79,6 +83,7 @@ dry_run=0assume_yes=0tmp=""mounted=""+existing_cua=""say() { printf '%s\n' "$*"; }info() { printf 'cua-install: %s\n' "$*"; }@@ -330,6 +335,38 @@ spaces_supported() {[ "$os" = darwin ] || [ "$os" = linux ]}+# --pair on a computer that already has Cua: use the `cua` that is there+# (it must know `host setup --pair`) and keep the app that is there, instead+# of downloading both again. Anything else (--prefix, --version, an old cua,+# nothing installed) installs as before.+reuse_installed() {+ [ -n "$pair_code" ] || return 0+ [ -z "$prefix" ] && [ -z "$version" ] && [ "${CUA_INSTALL_REINSTALL:-0}" != 1 ] || return 0+ [ "$app_only" = 0 ] || return 0+ found=""+ for candidate in "$(command -v cua 2>/dev/null || true)" "$HOME/.local/bin/cua" /usr/local/bin/cua \+ "/Applications/Cua Spaces.app/Contents/MacOS/cua" "$HOME/Applications/Cua Spaces.app/Contents/MacOS/cua"; do+ [ -n "$candidate" ] && [ -x "$candidate" ] || continue+ if "$candidate" host setup --help 2>&1 </dev/null | grep -q -e '--pair'; then+ found="$candidate"+ break+ fi+ done+ [ -n "$found" ] || return 0+ info "cua is already installed at $found; using it (CUA_INSTALL_REINSTALL=1 installs it again)"+ existing_cua="$found"+ want_cli=0+ case "$os" in+ darwin)+ if [ -d "/Applications/Cua Spaces.app" ] || [ -d "$HOME/Applications/Cua Spaces.app" ]; then sel_spaces=0; fi+ ;;+ linux)+ if has cua-spaces || [ -x "$HOME/.local/bin/cua-spaces" ]; then sel_spaces=0; fi+ ;;+ esac+ if [ "$sel_spaces" = 0 ] && spaces_supported; then info "Cua Spaces is already installed; keeping it"; fi+}+# Show the checklist only when a human can answer it.wants_checklist() {[ -z "$pair_code" ] && [ "$assume_yes" = 0 ] && [ "$only_set" = 0 ] && [ "$cli_only" = 0 ] &&@@ -993,6 +1030,7 @@ main() {parse_args "$@"detect_platforminit_selection+ reuse_installedtmp="$(mktemp -d 2>/dev/null || mktemp -d -t cua-install)"if wants_checklist; thenchecklist@@ -1000,15 +1038,18 @@ main() {if [ "$dry_run" = 1 ]; theninfo "dry run: nothing will be changed"fi- load_manifest- info "platform $platform, manifest $manifest_url"+ # Nothing to download (--pair on a computer that has Cua): no manifest to read.+ if [ "$want_cli" = 1 ] || [ "$sel_spaces" = 1 ] || [ "$sel_driver" = 1 ]; then+ load_manifest+ info "platform $platform, manifest $manifest_url"+ fi# Fail before installing anything when cua-driver cannot be installed.driver_url="${CUA_INSTALL_DRIVER_URL:-https://cua.ai/driver/install.sh}"if [ "$sel_driver" = 1 ]; thencheck_url "$driver_url"[ "$dry_run" = 1 ] || has bash || die "cua-driver: its installer needs bash; install bash and rerun"fi- cua_bin="cua"+ cua_bin="${existing_cua:-cua}"app_path=""if [ "$want_cli" = 1 ]; theninstall_clidiff --git a/scripts/install/tests/install.Tests.ps1 b/scripts/install/tests/install.Tests.ps1index 435b1a0c0a..43925bd636 100644--- a/scripts/install/tests/install.Tests.ps1+++ b/scripts/install/tests/install.Tests.ps1@@ -219,13 +219,35 @@ Describe 'install.ps1' {}It 'dry run: -Pair installs the CLI and runs host setup with the code, no sign-in or checklist' {- $out = Invoke-Installer @{ DryRun = $true; Pair = 'K7QM-4XPB-2RHD'; Relay = 'https://relay.example.com' }+ $out = Invoke-Installer @{ DryRun = $true; Pair = 'K7QM-4XPB-2RHD'; Relay = 'https://relay.example.com' } @{ CUA_INSTALL_REINSTALL = '1' }$out | Should -Match 'cua-cli-1.2.3-windows-x64.zip'$out | Should -Match 'host setup --pair K7QM-4XPB-2RHD --relay https://relay.example.com'$out | Should -Not -Match 'auth login'$out | Should -Not -Match 'Choose what to install'}+ It '-Pair on a computer that already has cua: uses it and downloads nothing' {+ $dir = Join-Path $env:CUA_TEST_ROOT 'existing-cua'+ New-Item -ItemType Directory -Force -Path $dir | Out-Null+ $sep = [IO.Path]::PathSeparator+ if ($IsWindows) {+ Set-Content -LiteralPath (Join-Path $dir 'cua.cmd') -Value "@echo off`r`necho --pair ^<CODE^> add this machine with a code"+ } else {+ $fake = Join-Path $dir 'cua'+ Set-Content -LiteralPath $fake -Value "#!/bin/sh`necho ' --pair <CODE> add this machine with a code'"+ chmod +x $fake+ }+ $vars = @{ PATH = "$dir$sep$env:PATH"; CUA_INSTALL_REINSTALL = $null }+ $out = Invoke-Installer @{ DryRun = $true; Pair = 'K7QM-4XPB-2RHD' } $vars+ $out | Should -Match 'already installed at'+ $out | Should -Match 'host setup --pair K7QM-4XPB-2RHD'+ $out | Should -Not -Match 'cua-cli-1.2.3'+ $out | Should -Not -Match 'manifest'+ # -Version and CUA_INSTALL_REINSTALL install anyway.+ (Invoke-Installer @{ DryRun = $true; Pair = 'K7QM-4XPB-2RHD'; Version = '1.2.3' } $vars) | Should -Match 'cua-cli-1.2.3'+ (Invoke-Installer @{ DryRun = $true; Pair = 'K7QM-4XPB-2RHD' } @{ PATH = $vars.PATH; CUA_INSTALL_REINSTALL = '1' }) | Should -Match 'cua-cli-1.2.3'+ }+It '-Pair refuses codes and relays with shell characters' {{ Invoke-Installer @{ DryRun = $true; Pair = 'K7QM;calc' } } | Should -Throw '*not a pairing code*'{ Invoke-Installer @{ DryRun = $true; Pair = 'K7QM-4XPB-2RHD'; Relay = 'http://evil.example' } } | Should -Throw '*https*'diff --git a/scripts/install/tests/run.sh b/scripts/install/tests/run.shindex b4645446dc..66eda57e3f 100755--- a/scripts/install/tests/run.sh+++ b/scripts/install/tests/run.sh@@ -410,6 +410,34 @@ check "--no-modify-path wins over --modify-path" absent "$home/.profile"inst -- --pair K7QM-4XPB-2RHD --prefix "$work/pp4"check "--pair runs the CLI by absolute path even when it is not on PATH" sh -c "[ $status = 0 ] && grep -qx 'host setup --pair K7QM-4XPB-2RHD' '$home/cua.log' && grep -q 'This machine is added' '$work/out'"+# --pair on a computer that already has Cua: reuse the cua and the app that are+# there instead of downloading them again.+seed="$work/seed/bin"+make_cua "$seed" linux-x64+sed -i.bak "s/cua $version/cua 9.9.9/" "$seed/cua" && rm -f "$seed/cua.bak"+printf '#!/bin/sh\necho existing cua-spaces\n' >"$seed/cua-spaces"+chmod +x "$seed/cua-spaces"+inst PATH="$seed:$PATH" -- --pair K7QM-4XPB-2RHD+check "--pair with Cua installed: uses it, no download" sh -c "[ $status = 0 ] && grep -q 'already installed at $seed/cua' '$work/out' && grep -qx 'host setup --pair K7QM-4XPB-2RHD' '$home/cua.log' && ! grep -q 'manifest' '$work/out' && [ ! -e '$home/.local/bin/cua' ]"+check "--pair with the app installed: keeps it, no AppImage" sh -c "grep -q 'Cua Spaces is already installed' '$work/out' && [ ! -e '$home/.local/bin/cua-spaces' ]"+# Installing anyway writes the default bin dir (/usr/local/bin as root): only as a user.+if [ "$(id -u)" != 0 ]; then+ inst PATH="$seed:$PATH" CUA_INSTALL_REINSTALL=1 -- --pair K7QM-4XPB-2RHD+ check "--pair with CUA_INSTALL_REINSTALL=1: installs again" sh -c "[ $status = 0 ] && ! grep -q 'already installed' '$work/out' && [ -x '$home/.local/bin/cua' ] && '$home/.local/bin/cua' --version | grep -q $version"+ inst PATH="$seed:$PATH" -- --pair K7QM-4XPB-2RHD --version "$version"+ check "--pair --version: installs that release" sh -c "[ $status = 0 ] && ! grep -q 'already installed' '$work/out' && [ -x '$home/.local/bin/cua' ]"+ inst PATH="$seed:$PATH" -- --yes --cli-only --prefix "$work/rp1"+ check "without --pair an installed cua is not reused" sh -c "[ $status = 0 ] && ! grep -q 'already installed' '$work/out' && [ -x '$work/rp1/bin/cua' ]"+ # (A real cua at one of the fixed places would be reused: skip there.)+ if [ ! -x /usr/local/bin/cua ] && [ ! -x "/Applications/Cua Spaces.app/Contents/MacOS/cua" ] && [ ! -x "$HOME/Applications/Cua Spaces.app/Contents/MacOS/cua" ]; then+ old="$work/seed-old/bin"+ make_cua "$old" linux-x64+ sed -i.bak 's/--pair <CODE> add this machine with a code/--no-such-flag/' "$old/cua" && rm -f "$old/cua.bak"+ inst PATH="$old:$PATH" -- --pair K7QM-4XPB-2RHD+ check "--pair with an old cua (no --pair): installs the current one" sh -c "[ $status = 0 ] && ! grep -q 'already installed' '$work/out' && [ -x '$home/.local/bin/cua' ]"+ fi+fi+# One quiet info line when signatures cannot be checked (neither minisign nor cosign).sig2="$release/sig2"mkdir -p "$sig2"