fix(computer-use): reconcile existing cua-driver installs

This commit is contained in:
Francesco Bonacci
2026-08-16 06:56:48 -05:00
committed by Teknium
parent a403fe6f92
commit 81af2ef013
11 changed files with 574 additions and 33 deletions
+58 -3
View File
@@ -3552,6 +3552,57 @@ function Install-BrowserUseCli {
}
}
function Test-CuaDriverRuntimeContract {
param([Parameter(Mandatory = $true)][string]$DriverPath)
try {
$versionOutput = (& $DriverPath --version 2>$null | Out-String).Trim()
if ($LASTEXITCODE -ne 0) {
return $false
}
$versionMatch = [regex]::Match($versionOutput, '(\d+\.\d+\.\d+)')
if (-not $versionMatch.Success) {
return $false
}
if ([version]($versionMatch.Groups[1].Value) -lt [version]'0.20.0') {
return $false
}
$manifestOutput = (& $DriverPath manifest 2>$null | Out-String).Trim()
if ($LASTEXITCODE -ne 0 -or -not $manifestOutput) {
return $false
}
$manifest = $manifestOutput | ConvertFrom-Json
if (-not $manifest.mcp_invocation.args) {
return $false
}
$required = @{
mcp = @('--socket', '--grant')
serve = @(
'--socket', '--permission-mode', '--capability-manifest',
'--approve-capability-manifest', '--embedded'
)
stop = @('--socket')
}
foreach ($commandName in $required.Keys) {
$command = $manifest.subcommands | Where-Object { $_.name -eq $commandName }
if (-not $command) {
return $false
}
$argNames = @($command.args | ForEach-Object { $_.name })
foreach ($requiredArg in $required[$commandName]) {
if ($requiredArg -notin $argNames) {
return $false
}
}
}
return $true
} catch {
return $false
}
}
# cua-driver powers the computer_use toolset (background desktop control).
# Provision it at install time so enabling the tool later -- via `hermes
# tools`, the dashboard, or the desktop app -- is a config flip, not a
@@ -3563,9 +3614,13 @@ function Install-CuaDriver {
Write-Info "Skipping Computer Use (cua-driver) install (-SkipComputerUse)"
return
}
if (Get-Command cua-driver -ErrorAction SilentlyContinue) {
Write-Success "Computer Use driver (cua-driver) already installed"
return
$existingCuaDriver = Get-Command cua-driver -ErrorAction SilentlyContinue
if ($existingCuaDriver) {
if (Test-CuaDriverRuntimeContract -DriverPath $existingCuaDriver.Source) {
Write-Success "Computer Use driver (cua-driver) already installed and compatible"
return
}
Write-Warn "Existing cua-driver is old or incomplete; repairing it"
}
Write-Info "Installing Computer Use driver (cua-driver)..."
+36 -2
View File
@@ -2501,6 +2501,37 @@ install_browser_use_cli() {
fi
}
cua_driver_runtime_compatible() {
local driver_path version_output manifest_output
local major minor
driver_path="$(command -v cua-driver 2>/dev/null)" || return 1
version_output="$("$driver_path" --version 2>/dev/null)" || return 1
if [[ ! "$version_output" =~ ([0-9]+)\.([0-9]+)\.([0-9]+) ]]; then
return 1
fi
major="${BASH_REMATCH[1]}"
minor="${BASH_REMATCH[2]}"
if (( major == 0 && minor < 20 )); then
return 1
fi
manifest_output="$("$driver_path" manifest 2>/dev/null)" || return 1
local required
for required in \
'"mcp_invocation"' \
'"--socket"' \
'"--grant"' \
'"--permission-mode"' \
'"--capability-manifest"' \
'"--approve-capability-manifest"' \
'"--embedded"'; do
case "$manifest_output" in
*"$required"*) ;;
*) return 1 ;;
esac
done
return 0
}
install_computer_use_driver() {
# cua-driver powers the computer_use toolset (background desktop control).
# Provision it at install time so enabling the tool later — via
@@ -2519,8 +2550,11 @@ install_computer_use_driver() {
;;
esac
if command -v cua-driver >/dev/null 2>&1; then
log_success "Computer Use driver (cua-driver) already installed"
return 0
if cua_driver_runtime_compatible; then
log_success "Computer Use driver (cua-driver) already installed and compatible"
return 0
fi
log_warn "Existing cua-driver is old or incomplete; repairing it"
fi
# Non-admin macOS accounts can't receive the CuaDriver.app bundle in
# /Applications; skip cleanly instead of failing loudly (#47865 class).