Skip to content

armgit / cua

Public Imported from GitHub
0

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

fix(install.ps1): put cua on PATH, offer the app, quiet -CliOnly (CUA-1704) (#5263)

Francesco Bonacciaf6139560141
diff --git a/scripts/install/install.ps1 b/scripts/install/install.ps1
index 6bfedd79c8..498cf389be 100644
--- a/scripts/install/install.ps1
+++ b/scripts/install/install.ps1
@@ -10,7 +10,7 @@ Cua installer for Windows: the `cua` CLI, the Cua Spaces app and agent extras.
At a console it first shows a numbered checklist of what to install. Items:
cli the cua CLI (always installed, except with -AppOnly)
- spaces the Cua Spaces app (the Electron app's setup.exe; off by default here, pick it or use -Select spaces)
+ spaces the Cua Spaces app (the Electron app's setup.exe; on by default)
cua-driver cua-driver MCP and skill for your agents (off by default)
host host this machine: `cua host setup` (off by default)
Set CUA_INSTALL_NONINTERACTIVE=1 to never prompt.
@@ -18,7 +18,9 @@ Set CUA_INSTALL_NONINTERACTIVE=1 to never prompt.
Reads release-artifacts.json (see scripts/install/README.md), downloads the
artifacts for this machine, verifies their sha256 (and a minisign or cosign
signature when available), installs `cua` to %LOCALAPPDATA%\Programs\cua\bin
-(or -Prefix\bin), then runs `cua auth login` when a user is at the console.
+(or -Prefix\bin) and adds that directory to your user PATH (-NoModifyPath
+skips it), then runs `cua auth login` when a user is at the console (not
+with -CliOnly, -Pair or -NoOnboarding).
-AppOnly, -Mode and the `spaces` item install the Cua Spaces app: its signed
setup.exe for this machine's architecture, run silently (/S) after the sha256
(and cosign, when available) check.
@@ -28,7 +30,7 @@ Preselect items (comma list: spaces, cua-driver, host); the checklist still show
.PARAMETER Only
Install exactly these items plus the CLI, without the checklist.
.PARAMETER CliOnly
-Install only the `cua` CLI (same as -Only cli).
+Install only the `cua` CLI (same as -Only cli), without prompts or sign-in.
.PARAMETER AppOnly
Install only the Cua Spaces app (no CLI).
.PARAMETER Mode
@@ -44,7 +46,9 @@ Install this CLI release (default: latest).
.PARAMETER Prefix
Install the CLI under Prefix\bin.
.PARAMETER ModifyPath
-Add the CLI directory to the user PATH.
+Kept for older commands: the CLI directory is added to the user PATH by default.
+.PARAMETER NoModifyPath
+Do not add the CLI directory to the user PATH.
.PARAMETER NoOnboarding
Do not run `cua auth login` afterwards.
.PARAMETER RequireSignature
@@ -68,6 +72,7 @@ param(
[string]$Version = '',
[string]$Prefix = '',
[switch]$ModifyPath,
+ [switch]$NoModifyPath,
[switch]$NoOnboarding,
[switch]$RequireSignature,
[ValidateSet('msi', 'nsis')][string]$Installer = 'nsis',
@@ -161,6 +166,9 @@ function Get-CuaSelection {
if ($App -and ($extra -contains 'cua-driver' -or $extra -contains 'host')) { Stop-Install '-AppOnly skips the CLI, which cua-driver and host need' }
$sel = [ordered]@{ cli = -not $App; spaces = $false; 'cua-driver' = $false; host = $false }
$list = if ($OnlyList -or $Cli) { $OnlyList } else { $SelectList }
+ # The app is a default, as on macOS and Linux (not with -Only, -CliOnly
+ # or a pairing code, which adds a host machine).
+ if (-not ($OnlyList -or $Cli -or $Pair)) { $sel.spaces = $true }
foreach ($item in @(ConvertTo-CuaItems $list)) { $sel[$item] = $true }
# A pairing code adds this machine: the CLI and host setup.
if ($Pair) {
@@ -177,11 +185,10 @@ function Test-WantsChecklist {
$env:CUA_INSTALL_NONINTERACTIVE -ne '1' -and (Test-Interactive))
}
-# Numbered checklist: toggle numbers, Enter to install. The CLI row is locked;
-# Spaces shows only when preselected (-Select spaces, -Mode).
+# Numbered checklist: toggle numbers, Enter to install. The CLI row is locked.
function Read-CuaSelection($Sel, [scriptblock]$Reader = { Read-Host 'Toggle numbers (e.g. 2 3), Enter to install' }) {
$rows = @('cli')
- if ($Sel.spaces) { $rows += 'spaces' }
+ if ($script:SpacesSupported) { $rows += 'spaces' }
$rows += 'cua-driver', 'host'
$labels = @{ cli = 'cua CLI (required)'; spaces = 'Cua Spaces app'; 'cua-driver' = 'cua-driver MCP and skill for your agents'; host = 'Host this machine' }
Write-Host ''
@@ -333,17 +340,19 @@ function Get-CliBinDir {
function Add-UserPath([string]$Dir) {
$current = [Environment]::GetEnvironmentVariable('Path', 'User')
$parts = @(if ($current) { $current -split ';' | Where-Object { $_ } })
- if ($parts -contains $Dir) { return }
if ($DryRun) { Write-Host "[dry-run] add $Dir to the user PATH"; return }
+ # This terminal too, so `cua` works right away.
+ if (@($env:Path -split ';') -notcontains $Dir) { $env:Path = "$env:Path;$Dir" }
+ if ($parts -contains $Dir) { return }
[Environment]::SetEnvironmentVariable('Path', (($parts + $Dir) -join ';'), 'User')
- $env:Path = "$env:Path;$Dir"
Write-Info "added $Dir to your user PATH (new terminals pick it up)"
}
function Install-Cli($Manifest, [string]$ManifestUrl, [string]$Platform, [string]$Tmp) {
$bin = Get-CliBinDir
$target = Join-Path $bin 'cua.exe'
- if (-not (Confirm-Step "Install the cua CLI to ${target}?")) { Stop-Install 'cancelled; rerun with -Prefix DIR to choose another location' }
+ # -CliOnly / -Only already said what to install.
+ if (-not ($CliOnly -or $Only) -and -not (Confirm-Step "Install the cua CLI to ${target}?")) { Stop-Install 'cancelled; rerun with -Prefix DIR to choose another location' }
$zip = Get-Artifact $Manifest $ManifestUrl 'cli' $Platform 'zip' $Tmp
if ($DryRun) {
Write-Host "[dry-run] install cua.exe -> $target"
@@ -358,12 +367,11 @@ function Install-Cli($Manifest, [string]$ManifestUrl, [string]$Platform, [string
}
$onPath = @($env:Path -split ';') -contains $bin
if (-not $onPath) {
- if ($ModifyPath) { Add-UserPath $bin }
+ if (-not $NoModifyPath) { Add-UserPath $bin }
else {
Write-Host ""
Write-Host "$bin is not on your PATH. Add it with:"
Write-Host " [Environment]::SetEnvironmentVariable('Path', `"`$([Environment]::GetEnvironmentVariable('Path','User'));$bin`", 'User')"
- Write-Host "(or rerun the installer with -ModifyPath)"
}
}
return $target
@@ -408,7 +416,7 @@ function Get-DriverBinDir {
function Get-DriverInstallArgs {
$a = @()
if ($RequireSignature) { $a += '-RequireSignature' }
- if (-not $ModifyPath) { $a += '-NoPathUpdate' }
+ if ($NoModifyPath) { $a += '-NoPathUpdate' }
return $a
}
@@ -531,7 +539,7 @@ function Invoke-CuaInstall {
$env:CUA_INSTALL_CHANNEL = 'install_script'
if ($sel['cua-driver']) { Install-CuaDriver $cua $tmp $manifestUrl }
Write-Info 'done'
- if ($cua -and -not $Pair -and -not $NoOnboarding -and -not $DryRun -and (Test-Interactive)) {
+ if ($cua -and -not $Pair -and -not $CliOnly -and -not $NoOnboarding -and -not $DryRun -and (Test-Interactive)) {
Write-Info 'signing in (cua auth login)'
& $cua auth login
if ($LASTEXITCODE -ne 0) { Write-Warning "sign-in did not finish; run 'cua auth login' later" }
diff --git a/scripts/install/tests/install.Tests.ps1 b/scripts/install/tests/install.Tests.ps1
index f1bed908cb..435b1a0c0a 100644
--- a/scripts/install/tests/install.Tests.ps1
+++ b/scripts/install/tests/install.Tests.ps1
@@ -87,7 +87,8 @@ Describe 'functions' {
It 'selects defaults, -Select, -Only and the legacy switches' {
$d = Get-CuaSelection -SelectList '' -OnlyList '' -Cli $false -App $false -InstallMode ''
- @($d.cli, $d.spaces, $d['cua-driver'], $d.host) | Should -Be @($true, $false, $false, $false)
+ @($d.cli, $d.spaces, $d['cua-driver'], $d.host) | Should -Be @($true, $true, $false, $false)
+ (Get-CuaSelection -SelectList '' -OnlyList '' -Cli $true -App $false -InstallMode '').spaces | Should -BeFalse
(Get-CuaSelection -SelectList 'cua-driver' -OnlyList '' -Cli $false -App $false -InstallMode '')['cua-driver'] | Should -BeTrue
$o = Get-CuaSelection -SelectList '' -OnlyList 'host' -Cli $false -App $false -InstallMode ''
@($o.cli, $o.spaces, $o.host) | Should -Be @($true, $false, $true)
@@ -106,15 +107,15 @@ Describe 'functions' {
}
It 'toggles items in the numbered checklist; the CLI row is locked' {
- $script:answers = [Collections.Generic.Queue[string]]::new([string[]]@('1 2', '3', ''))
+ $script:answers = [Collections.Generic.Queue[string]]::new([string[]]@('1 3', '4', ''))
$sel = Get-CuaSelection -SelectList '' -OnlyList '' -Cli $false -App $false -InstallMode ''
$sel = Read-CuaSelection $sel { $script:answers.Dequeue() } 6>$null
- @($sel.cli, $sel.spaces, $sel['cua-driver'], $sel.host) | Should -Be @($true, $false, $true, $true)
+ @($sel.cli, $sel.spaces, $sel['cua-driver'], $sel.host) | Should -Be @($true, $true, $true, $true)
$script:Picked | Should -BeTrue
$script:Picked = $false
}
- It 'shows Spaces in the checklist only when preselected' {
+ It 'shows Spaces in the checklist, where it can be unticked' {
$script:answers = [Collections.Generic.Queue[string]]::new([string[]]@('2', ''))
$sel = Get-CuaSelection -SelectList 'spaces' -OnlyList '' -Cli $false -App $false -InstallMode ''
$sel = Read-CuaSelection $sel { $script:answers.Dequeue() } 6>$null
@@ -123,9 +124,9 @@ Describe 'functions' {
}
It 'forwards -RequireSignature and -NoPathUpdate to the cua-driver installer' {
- $RequireSignature = $false; $ModifyPath = $false
+ $RequireSignature = $false; $NoModifyPath = $true
Get-DriverInstallArgs | Should -Be @('-NoPathUpdate')
- $RequireSignature = $true; $ModifyPath = $true
+ $RequireSignature = $true; $NoModifyPath = $false
Get-DriverInstallArgs | Should -Be @('-RequireSignature')
}
@@ -146,7 +147,7 @@ Set-Content (Join-Path `$env:CUA_DRIVER_RS_INSTALL_DIR 'cua-driver.exe') 'fake'
Set-Content -LiteralPath $fakeCua -Value "#!/bin/sh`necho `"`$*`" >>'$cuaLog'"
chmod +x $fakeCua
$env:CUA_INSTALL_DRIVER_URL = ConvertTo-FileUrl $fakeDriver
- $Prefix = $prefix; $DryRun = $false; $RequireSignature = $true; $ModifyPath = $false
+ $Prefix = $prefix; $DryRun = $false; $RequireSignature = $true; $NoModifyPath = $true
try {
Install-CuaDriver $fakeCua (New-Item -ItemType Directory -Force -Path (Join-Path $root 'tmp')).FullName 'file:///r.json' 6>$null
} finally { $env:CUA_INSTALL_DRIVER_URL = $null }
@@ -172,12 +173,22 @@ Set-Content (Join-Path `$env:CUA_DRIVER_RS_INSTALL_DIR 'cua-driver.exe') 'fake'
Describe 'install.ps1' {
It 'installs the CLI into -Prefix\bin and verifies the checksum' {
$prefix = Join-Path $env:CUA_TEST_ROOT 'p1'
- $out = Invoke-Installer @{ CliOnly = $true; Yes = $true; NoOnboarding = $true; Prefix = $prefix }
+ $out = Invoke-Installer @{ CliOnly = $true; Yes = $true; NoOnboarding = $true; NoModifyPath = $true; Prefix = $prefix }
Join-Path $prefix 'bin/cua.exe' | Should -Exist
$out | Should -Match 'Next steps'
$out | Should -Match 'is not on your PATH'
}
+ # CUA-1704: `cua` must work in the next terminal without a manual step.
+ It 'adds the CLI to the user PATH by default; -CliOnly neither asks nor signs in' {
+ $out = Invoke-Installer @{ DryRun = $true; CliOnly = $true; Prefix = (Join-Path $env:CUA_TEST_ROOT 'p11') }
+ $out | Should -Match '\[dry-run\] add .*p11.bin to the user PATH'
+ $out | Should -Not -Match 'is not on your PATH'
+ $out | Should -Not -Match 'Install the cua CLI to'
+ $out | Should -Not -Match 'signing in'
+ $out | Should -Not -Match 'setup.exe'
+ }
+
# Cua Spaces for Windows is the Electron app's NSIS setup.exe.
It 'dry run: -Mode plans the CLI and the silent setup.exe, and changes nothing' {
$prefix = Join-Path $env:CUA_TEST_ROOT 'p2'
@@ -260,9 +271,10 @@ Describe 'install.ps1' {
Get-Content $log | Should -Not -Match 'identity-regexp'
}
- It 'dry run: Spaces is off by default on Windows' {
+ It 'dry run: Spaces is on by default on Windows' {
$out = Invoke-Installer @{ DryRun = $true; Yes = $true }
$out | Should -Match 'cua-cli-1.2.3-windows-x64.zip'
+ $out | Should -Match 'cua-spaces-1.2.3-windows-x64-setup.exe /S'
$out | Should -Not -Match 'msiexec'
$out | Should -Not -Match 'cua-driver'
}
@@ -277,7 +289,8 @@ Describe 'install.ps1' {
It 'dry run: -Select cua-driver,host prints the driver, agents and host steps' {
$out = Invoke-Installer @{ DryRun = $true; Select = 'cua-driver,host'; Prefix = (Join-Path $env:CUA_TEST_ROOT 'p10') } @{ CUA_INSTALL_NONINTERACTIVE = '1'; CUA_INSTALL_DRIVER_URL = 'https://example.test/driver/install.ps1' }
$out | Should -Match '\[dry-run\] download https://example.test/driver/install.ps1'
- $out | Should -Match 'cua-driver-install.ps1 -NoPathUpdate'
+ $out | Should -Match 'cua-driver-install.ps1'
+ $out | Should -Not -Match 'NoPathUpdate'
$out | Should -Match 'agents setup --cua-driver --agents all --yes --mcp-command .*p10.bin.cua-driver.exe'
$out | Should -Match '\[dry-run\] .*cua.exe host setup'
$out | Should -Not -Match 'msiexec'