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
feat(install): Phase 2 — single canonical install.sh, Rust logic colocated (#1557)
Francesco Bonacci7f46cdca7788
diff --git a/.github/workflows/cd-rust-cua-driver.yml b/.github/workflows/cd-rust-cua-driver.ymlindex 4062f56a7d..5a8b00694e 100644--- a/.github/workflows/cd-rust-cua-driver.yml+++ b/.github/workflows/cd-rust-cua-driver.yml@@ -386,11 +386,15 @@ jobs:run: |# GNU sed (ubuntu-latest). The Swift CD workflow runs on# macos-15 and uses the BSD form (`sed -i ''`).+ # The Rust install logic now lives at+ # libs/cua-driver/scripts/_install-rust.sh (a private helper+ # invoked by libs/cua-driver/scripts/install.sh on+ # --backend=rust / non-macOS auto-detect).sed -i \"s/^CUA_DRIVER_RS_BAKED_VERSION=.*/CUA_DRIVER_RS_BAKED_VERSION=\"${VERSION}\"/" \- libs/cua-driver-rs/scripts/install.sh+ libs/cua-driver/scripts/_install-rust.sh- # install.ps1 now lives at the canonical Swift install dir;+ # install.ps1 lives at the canonical Swift install dir;# PowerShell line starts with `$Script:` — escape the `$` for# sed's BRE so it matches the literal dollar sign.sed -i \@@ -398,7 +402,7 @@ jobs:libs/cua-driver/scripts/install.ps1echo "Baked version ${VERSION} into working-tree install scripts:"- grep -E '^CUA_DRIVER_RS_BAKED_VERSION=' libs/cua-driver-rs/scripts/install.sh+ grep -E '^CUA_DRIVER_RS_BAKED_VERSION=' libs/cua-driver/scripts/_install-rust.shgrep -E '^\$Script:CuaDriverRsBakedVersion = ' libs/cua-driver/scripts/install.ps1- name: Stage release files@@ -417,14 +421,17 @@ jobs:# The freshly-baked scripts (rewritten in the prior step) are# what gets copied here, so the per-tag release assets carry the# current version's baked default — not the previous version's.- # Note: install.ps1 now lives at libs/cua-driver/scripts/install.ps1- # (canonical location for both Swift + Rust user-facing installers).- # install.sh stays under libs/cua-driver-rs/scripts/ for now —- # libs/cua-driver/scripts/install.sh is the Swift driver's installer- # that auto-delegates to this one when uname != Darwin or- # --experimental-rust is passed.- cp libs/cua-driver-rs/scripts/install.sh release-upload/install.sh- cp libs/cua-driver/scripts/install.ps1 release-upload/install.ps1+ # Both user-facing installers live under libs/cua-driver/scripts/:+ # install.sh is the Swift driver's installer that+ # auto-delegates to the Rust _install-rust.sh helper on+ # --experimental-rust / non-macOS hosts. install.ps1 is the+ # canonical Windows installer (Rust port; Swift has no+ # Windows build). The Rust install logic itself lives at+ # _install-rust.sh — published as a release asset alongside+ # the installers so curl|bash flows can fetch it.+ cp libs/cua-driver/scripts/install.sh release-upload/install.sh+ cp libs/cua-driver/scripts/install.ps1 release-upload/install.ps1+ cp libs/cua-driver/scripts/_install-rust.sh release-upload/_install-rust.sh# Skill pack — single platform-agnostic tarball fetched by# `cua-driver skills install`. The .md files are identical across@@ -513,18 +520,23 @@ jobs:### Install (Linux / macOS)```bash- /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/trycua/cua/main/libs/cua-driver-rs/scripts/install.sh)"+ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/trycua/cua/main/libs/cua-driver/scripts/install.sh)"```+ On macOS the installer defaults to the Swift driver; pass+ `--experimental-rust` to get the cua-driver-rs Rust port.+ On Linux it auto-detects the non-macOS host and installs+ the Rust port directly.+### Install (Windows)```powershellirm https://raw.githubusercontent.com/trycua/cua/main/libs/cua-driver/scripts/install.ps1 | iex```- > Note: the canonical Windows installer moved from- > `libs/cua-driver-rs/scripts/install.ps1` to- > `libs/cua-driver/scripts/install.ps1`. The old URL still works via a+ > Note: both canonical installer URLs now live under+ > `libs/cua-driver/scripts/`. Old URLs at+ > `libs/cua-driver-rs/scripts/install.{sh,ps1}` still work via a> deprecation shim that fetches the canonical script.The installer auto-detects host architecture (x86_64 / arm64) and uses@@ -601,11 +613,14 @@ jobs:# syntax (`sed -i` with no empty-string arg) — the Swift CD# workflow's bake step runs on macos-15 and uses the BSD form# (`sed -i ''`).+ # Rust install logic lives at libs/cua-driver/scripts/_install-rust.sh+ # (private helper invoked by the canonical libs/cua-driver/scripts/install.sh+ # on --backend=rust / non-macOS auto-detect).sed -i \"s/^CUA_DRIVER_RS_BAKED_VERSION=.*/CUA_DRIVER_RS_BAKED_VERSION=\"${VERSION}\"/" \- libs/cua-driver-rs/scripts/install.sh+ libs/cua-driver/scripts/_install-rust.sh- # install.ps1 now lives at libs/cua-driver/scripts/install.ps1+ # install.ps1 lives at libs/cua-driver/scripts/install.ps1# (canonical Windows entry point). The PowerShell line starts# with `$Script:` — escape the `$` for sed's BRE so it matches# the literal dollar sign.@@ -615,6 +630,6 @@ jobs:git config user.name "trycua-release[bot]"git config user.email "trycua-release[bot]@users.noreply.github.com"- git add libs/cua-driver-rs/scripts/install.sh libs/cua-driver/scripts/install.ps1+ git add libs/cua-driver/scripts/_install-rust.sh libs/cua-driver/scripts/install.ps1git commit -m "chore(cua-driver-rs): bake version ${VERSION} into install scripts [skip ci]"git push origin bake-version:maindiff --git a/docs/content/docs/cua-driver/guide/getting-started/installation.mdx b/docs/content/docs/cua-driver/guide/getting-started/installation.mdxindex 3b2aad2398..bc9c802ddc 100644--- a/docs/content/docs/cua-driver/guide/getting-started/installation.mdx+++ b/docs/content/docs/cua-driver/guide/getting-started/installation.mdx@@ -39,7 +39,7 @@ The install runs **without sudo**: `/Applications` is user-writable on personal(Equivalent long form: `--backend=rust`.)-The flag delegates to [`libs/cua-driver-rs/scripts/install.sh`](https://github.com/trycua/cua/blob/main/libs/cua-driver-rs/scripts/install.sh), which:+The flag delegates to [`libs/cua-driver/scripts/_install-rust.sh`](https://github.com/trycua/cua/blob/main/libs/cua-driver/scripts/_install-rust.sh) (a private helper colocated with the canonical `install.sh`), which:- Installs `CuaDriverRs.app` to `/Applications/` — separate bundle id (`com.trycua.cuadriverrs`) from the Swift driver's `com.trycua.driver`. Both can coexist on the same machine with independent TCC grants and independent telemetry IDs.- Points `~/.local/bin/cua-driver` at the Rust binary. The Swift `CuaDriver.app` (if previously installed) is left untouched and still launchable via its bundle path (`/Applications/CuaDriver.app/Contents/MacOS/cua-driver`).@@ -57,20 +57,22 @@ The second command rewires the `~/.local/bin/cua-driver` symlink back to the Swi### Install `cua-driver-rs` directly (Linux / Windows / macOS)-The cross-platform Rust port ships its own one-liners. Pick the one for your shell — no `--experimental-rust` plumbing through the Swift installer needed.+Both canonical installers live under `libs/cua-driver/scripts/`. On macOS the `.sh` installer defaults to the Swift driver; pass `--experimental-rust` to get the Rust port. On Linux it auto-detects the non-macOS host and installs the Rust port directly.-**Linux / macOS**+**Linux**```bash-/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/trycua/cua/main/libs/cua-driver-rs/scripts/install.sh)"+/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/trycua/cua/main/libs/cua-driver/scripts/install.sh)"```**Windows (PowerShell)**```powershell-irm https://raw.githubusercontent.com/trycua/cua/main/libs/cua-driver-rs/scripts/install.ps1 | iex+irm https://raw.githubusercontent.com/trycua/cua/main/libs/cua-driver/scripts/install.ps1 | iex```+The legacy `libs/cua-driver-rs/scripts/install.{sh,ps1}` URLs continue to work via backward-compat shims that redirect to the canonical installers — Hermes and any other integration that hardcodes the old URLs keep working unchanged.+The Windows installer auto-detects host architecture (x64 / arm64) via `[System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture` and downloads the matching `cua-driver-rs-<v>-windows-{x86_64,arm64}.zip` from GitHub Releases.It runs **without admin** and **without Developer Mode**.diff --git a/libs/cua-driver-rs/Skills/cua-driver-rs/README.md b/libs/cua-driver-rs/Skills/cua-driver-rs/README.mdindex a8dc7d4915..9fe8f8f077 100644--- a/libs/cua-driver-rs/Skills/cua-driver-rs/README.md+++ b/libs/cua-driver-rs/Skills/cua-driver-rs/README.md@@ -90,9 +90,12 @@ forbidden-list / launch / click details.works today. Install:```bash-/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/trycua/cua/main/libs/cua-driver-rs/scripts/install.sh)"+/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/trycua/cua/main/libs/cua-driver/scripts/install.sh)"```+(On Linux the canonical installer auto-detects the non-macOS host and+installs the Rust port — no flag needed.)+## InstallThe skill is a drop-in directory. Same shape on every platform.diff --git a/libs/cua-driver-rs/crates/cua-driver/src/cli.rs b/libs/cua-driver-rs/crates/cua-driver/src/cli.rsindex e7b4f8ed08..31a54b4f78 100644--- a/libs/cua-driver-rs/crates/cua-driver/src/cli.rs+++ b/libs/cua-driver-rs/crates/cua-driver/src/cli.rs@@ -896,14 +896,14 @@ pub fn run_update_cmd(apply: bool) {println!(" cua-driver update --apply");println!();println!("Or reinstall directly:");- println!(" curl -fsSL https://raw.githubusercontent.com/trycua/cua/main/libs/cua-driver-rs/scripts/install.sh | bash");+ println!(" curl -fsSL https://raw.githubusercontent.com/trycua/cua/main/libs/cua-driver/scripts/install.sh | bash");return;}println!("Downloading and installing cua-driver {v}…");let status = std::process::Command::new("bash").arg("-c")- .arg("curl -fsSL https://raw.githubusercontent.com/trycua/cua/main/libs/cua-driver-rs/scripts/install.sh | bash")+ .arg("curl -fsSL https://raw.githubusercontent.com/trycua/cua/main/libs/cua-driver/scripts/install.sh | bash").status();match status {Ok(s) if s.success() => {}diff --git a/libs/cua-driver-rs/scripts/install.sh b/libs/cua-driver-rs/scripts/install.shindex ae09a29372..1c79c26ca7 100644--- a/libs/cua-driver-rs/scripts/install.sh+++ b/libs/cua-driver-rs/scripts/install.sh@@ -1,638 +1,44 @@#!/usr/bin/env bash-# cua-driver-rs installer — download the latest cua-driver-rs release tarball-# from GitHub Releases and drop the binary into ~/.local/bin (or a path given-# via --bin-dir / CUA_DRIVER_RS_INSTALL_DIR). Sudo-free.#-# This is the Rust port of cua-driver — cross-platform (macOS / Linux / Windows-# via WSL or git-bash) computer-use automation. The Swift cua-driver (macOS-# only) ships separately under tag prefix `cua-driver-v*` and is installed-# via `libs/cua-driver/scripts/install.sh`; this script is hard-pinned to-# `cua-driver-rs-v*` and will never pick up the Swift binary.+# cua-driver-rs/scripts/install.sh — backward-compat redirect.#-# Usage:-# /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/trycua/cua/main/libs/cua-driver-rs/scripts/install.sh)"-#-# Flags:-# --bin-dir <path> install the visible binary/symlink to <path>-# instead of ~/.local/bin-# --no-modify-path skip auto-appending an `export PATH=...` line-#-# Env overrides:-# CUA_DRIVER_RS_VERSION=0.1.2 pin a specific release tag-# CUA_DRIVER_RS_INSTALL_DIR=PATH same as --bin-dir; sets the visible-# binary location-# CUA_DRIVER_RS_BIN_DIR=PATH legacy alias for INSTALL_DIR-# CUA_DRIVER_RS_HOME=PATH package home for versioned installs-# (default ~/.cua-driver-rs). Holds-# packages/releases/<v>-<target>/ and-# packages/current/ on Linux/Windows.-# CUA_DRIVER_RS_NO_MODIFY_PATH=1 same as --no-modify-path-# CUA_DRIVER_RS_KEEP_VERSIONS=N keep the N most recent per-version-# release dirs after install; older-# ones are deleted (default 5; set 0-# to disable GC entirely). Per-target-# — multi-arch dirs are pruned-# independently of each other.-#-# On-disk layout (Linux; macOS keeps its .app-in-/Applications layout, see-# below):-# $CUA_DRIVER_RS_HOME/-# packages/-# releases/-# 0.1.3-x86_64-unknown-linux-gnu/cua-driver (per-version binary)-# 0.1.4-x86_64-unknown-linux-gnu/cua-driver-# current/cua-driver -> ../releases/<active>/cua-driver (active version)-# $CUA_DRIVER_RS_INSTALL_DIR/cua-driver -> $HOME/packages/current/cua-driver-#-# Atomic upgrade: a new install drops the binary into a fresh per-version-# dir, then rename(2)-swaps the `current` symlink to point at it. A-# running daemon keeps its already-mmap'd binary open across the swap-# (open file handles survive). Rollback: re-point `current` at any older-# entry under `releases/`.-#-# Post-install GC trims the per-target release dirs so disk usage stays-# bounded (each release dir is ~15 MB, so an indefinite series of-# upgrades grows without bound). The N most-recent dirs are kept (default-# 5, override via CUA_DRIVER_RS_KEEP_VERSIONS); the dir that `current`-# resolves to is always preserved even if its mtime would otherwise drop-# it off the list. GC runs after the atomic swap so the about-to-be-active-# version is never a deletion candidate.-#-# ⚠️ This is a BETA release. The Rust port is feature-complete on Windows-# and Linux; macOS parity with the Swift cua-driver is in progress. For-# production macOS automation prefer `libs/cua-driver/scripts/install.sh`.-set -euo pipefail--REPO="trycua/cua"-BINARY_NAME="cua-driver"-TAG_PREFIX="cua-driver-rs-v"-# CUA_DRIVER_RS_INSTALL_DIR is the documented name; CUA_DRIVER_RS_BIN_DIR is-# the legacy alias kept for users with the old env in their shell rc.-BIN_DIR="${CUA_DRIVER_RS_INSTALL_DIR:-${CUA_DRIVER_RS_BIN_DIR:-$HOME/.local/bin}}"-HOME_DIR="${CUA_DRIVER_RS_HOME:-$HOME/.cua-driver-rs}"-NO_MODIFY_PATH="${CUA_DRIVER_RS_NO_MODIFY_PATH:-0}"-# Post-install GC: how many per-version release dirs to retain. Validated-# below as a non-negative integer; 0 means "never GC". The dir that-# `current` resolves to is always preserved regardless of cutoff.-KEEP_VERSIONS_DEFAULT=5-KEEP_VERSIONS="${CUA_DRIVER_RS_KEEP_VERSIONS:-$KEEP_VERSIONS_DEFAULT}"--# macOS-only: name and install location of the .app bundle that wraps-# the bare binary so the TCC auto-relaunch path in `cua-driver-rs mcp`-# has a stable bundle id (com.trycua.cuadriverrs) to attribute the-# daemon to. See libs/cua-driver-rs/scripts/CuaDriverRs.app/Contents/-# Info.plist and the matching docs on `cua-driver-rs mcp`'s auto--# relaunch behavior. Distinct from the Swift driver's CuaDriver.app-# (com.trycua.driver) so the two installs coexist on the same machine.-APP_NAME="CuaDriverRs.app"-APP_DEST="/Applications/$APP_NAME"--while [[ $# -gt 0 ]]; do- case "$1" in- --bin-dir) BIN_DIR="$2"; shift 2 ;;- --bin-dir=*) BIN_DIR="${1#*=}"; shift ;;- --no-modify-path) NO_MODIFY_PATH=1; shift ;;- *) shift ;;- esac-done--# Validate KEEP_VERSIONS up front so a typo (e.g. "five") falls back to-# the default instead of silently disabling GC. Accepts any non-negative-# integer; 0 is the documented "never GC" sentinel.-if ! [[ "$KEEP_VERSIONS" =~ ^[0-9]+$ ]]; then- printf 'warning: CUA_DRIVER_RS_KEEP_VERSIONS=%s is not a non-negative integer; falling back to %d\n' \- "$KEEP_VERSIONS" "$KEEP_VERSIONS_DEFAULT" >&2- KEEP_VERSIONS="$KEEP_VERSIONS_DEFAULT"-fi--BIN_LINK="$BIN_DIR/$BINARY_NAME"-TMP_DIR=$(mktemp -d)--log() { printf '==> %s\n' "$*"; }-err() { printf 'error: %s\n' "$*" >&2; }--# --- Concurrent-install lockfile ----------------------------------------#-# A second install kicked off while a first is still running can race-# on the atomic `current` symlink swap and produce a half-installed-# state (e.g. the symlink points at a dir whose binary the first install-# hasn't finished copying). Serialize installs per $HOME_DIR with a-# process-level mutex.-#-# Primitive: mkdir on POSIX is atomic. The first install to create-# $LOCK_DIR holds the lock; concurrent attempts get EEXIST and poll.-# Released via trap on every exit path (success, error, signal) so-# a half-finished install always frees the lock for the next one.-#-# Stale-lock recovery: if the holder dies without releasing (kill -9,-# OOM, host reboot mid-install), the lock dir sits around forever and-# every subsequent install hangs. After $LOCK_STALE_AFTER_SECONDS of-# waiting we probe the holder's liveness via `kill -0 <pid>` (the pid-# is stamped into $LOCK_INFO right after acquisition) — if the holder-# is alive we keep waiting (slow download / wedged network is not the-# same as a crashed install and we must not yank the lock out from-# under a live process), if it's dead we force-release with a loud log-# and proceed. The alternative (hang forever) leaves users in a-# permanently wedged state with no clear recovery path beyond `rm -rf`-# on an internal-looking dir.-LOCK_PACKAGES_DIR="$HOME_DIR/packages"-LOCK_DIR="$LOCK_PACKAGES_DIR/.install.lock.d"-LOCK_INFO="$LOCK_DIR/info"-LOCK_POLL_INTERVAL_SECONDS=1-LOCK_STALE_AFTER_SECONDS=600--LOCK_HELD=0-release_install_lock() {- if (( LOCK_HELD == 1 )); then- rm -rf "$LOCK_DIR" 2>/dev/null || true- LOCK_HELD=0- fi-}--# Combine TMP_DIR cleanup with lock release in a single trap so neither-# clobbers the other. INT/TERM also re-raise via $? so the user-visible-# exit code reflects the signal.-cleanup_on_exit() {- rm -rf "$TMP_DIR" 2>/dev/null || true- release_install_lock-}-trap cleanup_on_exit EXIT-trap 'cleanup_on_exit; trap - INT; kill -INT $$' INT-trap 'cleanup_on_exit; trap - TERM; kill -TERM $$' TERM--acquire_install_lock() {- mkdir -p "$LOCK_PACKAGES_DIR"- local waited=0- while ! mkdir "$LOCK_DIR" 2>/dev/null; do- if (( waited == 0 )); then- log "another cua-driver-rs install is already in progress (lock at $LOCK_DIR); waiting..."- fi- sleep "$LOCK_POLL_INTERVAL_SECONDS"- waited=$((waited + LOCK_POLL_INTERVAL_SECONDS))- if (( waited >= LOCK_STALE_AFTER_SECONDS )); then- # Don't yank the lock from a live install. Parse pid= from- # the info file (written by the holder right after mkdir);- # if that pid is still alive per kill -0, the holder is just- # slow (big download, wedged network) — keep waiting. Only- # reclaim when there's no live holder.- #- # Missing/unreadable info file → holder didn't get far enough- # to stamp pid, so assume dead and reclaim. Unparseable pid- # line → same. Either way we err on the side of progress- # rather than hanging forever once the 600s window elapses.- local holder_pid=""- if [[ -r "$LOCK_INFO" ]]; then- holder_pid=$(grep -E '^pid=' "$LOCK_INFO" 2>/dev/null | head -1 | cut -d= -f2)- fi- if [[ -n "$holder_pid" ]] && kill -0 "$holder_pid" 2>/dev/null; then- log "lock at $LOCK_DIR still held by live pid $holder_pid; continuing to wait"- # Reset waited so we re-check after another full window- # rather than spamming this branch every poll interval.- waited=0- continue- fi- log "lock at $LOCK_DIR appears stale (>${LOCK_STALE_AFTER_SECONDS}s, no live holder); forcing release"- rm -rf "$LOCK_DIR" 2>/dev/null || true- waited=0- fi- done- LOCK_HELD=1- # Drop pid + ISO timestamp + invocation args into the lock dir so a- # user investigating a stuck install can see who holds it (`cat- # $HOME_DIR/packages/.install.lock.d/info`).- {- printf 'pid=%s\n' "$$"- printf 'started=%s\n' "$(date -u +'%Y-%m-%dT%H:%M:%SZ' 2>/dev/null || date)"- printf 'argv=%s\n' "$0 $*"- } > "$LOCK_INFO" 2>/dev/null || true-}--acquire_install_lock "$@"--# Prune per-version release dirs under $RELEASES_DIR for the current-# $TARGET, keeping the N most recent (by mtime). The dir that the-# `current` symlink resolves to is always preserved — even if it's-# older than the cutoff — so we never delete the active install.-#-# Filtering is by target-triple suffix so a multi-arch dev with both-# (e.g.) aarch64-apple-darwin and x86_64-unknown-linux-gnu under the-# same $HOME_DIR keeps each target's history independently. Other-arch-# dirs are invisible to this prune pass.-#-# Args: $1 = releases dir, $2 = current symlink path, $3 = target triple,-# $4 = keep count (non-negative integer; 0 = skip).-prune_old_releases() {- local releases_dir="$1" current_link="$2" target="$3" keep="$4"-- if [[ "$keep" == "0" ]]; then- log "version GC disabled (CUA_DRIVER_RS_KEEP_VERSIONS=0)"- return 0- fi- if [[ ! -d "$releases_dir" ]]; then- return 0- fi-- # Resolve the dir `current` points at so we can exempt it from the- # prune candidates. `readlink -f` would canonicalize, but BSD readlink- # (macOS — which doesn't reach here in production but is tested from- # a dev shell) lacks -f, so use the more portable two-step.- local current_target=""- if [[ -L "$current_link" ]]; then- local link_value- link_value=$(readlink "$current_link" 2>/dev/null || true)- if [[ -n "$link_value" ]]; then- case "$link_value" in- /*) current_target="$link_value" ;;- *) current_target="$(dirname "$current_link")/$link_value" ;;- esac- fi- fi-- # `ls -dt` sorts dirs by mtime, newest-first. The trailing slash on- # the glob filters to dirs only. Skip if no matching dirs (the glob- # would otherwise pass through literally under shopt -s nullglob being- # off — guard with 2>/dev/null and an `|| true`).- local candidates=()- while IFS= read -r dir; do- [[ -n "$dir" ]] || continue- # Strip trailing slash for consistent comparison with $current_target.- dir="${dir%/}"- # Only consider dirs whose name ends in the current target triple.- local base="${dir##*/}"- case "$base" in- *-"$target") candidates+=("$dir") ;;- *) ;;- esac- done < <(ls -dt "$releases_dir"/*/ 2>/dev/null || true)-- if [[ ${#candidates[@]} -le "$keep" ]]; then- return 0- fi-- # Walk candidates newest-first. The first $keep are retained by mtime- # (active install counts toward the budget in the common case where- # the install just happened — it's the newest by mtime). The active- # install is *additionally* preserved even if it would otherwise fall- # outside the keep window (e.g. user rolled back to an old version),- # so the worst-case post-GC count is $keep + 1, common case is exactly- # $keep.- local to_prune=()- local kept=0- local i- for ((i=0; i<${#candidates[@]}; i++)); do- local cand="${candidates[$i]}"- local is_current=0- if [[ -n "$current_target" && "${cand%/}" == "${current_target%/}" ]]; then- is_current=1- fi- if (( kept < keep )); then- kept=$((kept + 1))- continue- fi- if (( is_current == 1 )); then- # Active install fell outside the keep window — preserve- # anyway (never delete the dir that's about to serve the- # next `cua-driver` invocation).- continue- fi- to_prune+=("$cand")- done-- if [[ ${#to_prune[@]} -eq 0 ]]; then- return 0- fi-- log "pruning ${#to_prune[@]} old release dir(s) (keeping $keep most recent for $target):"- local p- for p in "${to_prune[@]}"; do- log " - ${p##*/}"- done- printf '%s\0' "${to_prune[@]}" | xargs -0 rm -rf-}--# --- Resolve OS/arch ------------------------------------------------------OS=$(uname -s)-ARCH_RAW=$(uname -m)--# Rosetta translation correction.+# The canonical user-facing installer now lives at+# libs/cua-driver/scripts/install.sh (Swift driver's installer that+# auto-delegates to the Rust port on non-macOS hosts or when+# `--experimental-rust` is passed). This shim exists so the legacy+# one-liner against this path keeps working forever:#-# `uname -m` reflects the architecture of the *running process*, not the-# physical CPU. When an Apple Silicon Mac is driving an x86_64-translated-# shell (Rosetta — e.g. `arch -x86_64 bash`, or a Homebrew install pinned-# to /usr/local/), uname reports x86_64 even though the native arch is-# arm64. We'd then download the x86_64 binary and run it under Rosetta —-# slower, and an unnecessary translation when a native arm64 binary-# exists on the release page.+# /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/trycua/cua/main/libs/cua-driver-rs/scripts/install.sh)"#-# `sysctl.proc_translated` returns 1 when the current process is running-# under Rosetta translation; absent/0 means native. Only meaningful on-# macOS — the sysctl key is missing on Linux, so the redirect-to-null-# keeps the check a silent no-op there.-if [[ "$OS" == "Darwin" && "$ARCH_RAW" == "x86_64" ]]; then- if [[ "$(sysctl -n sysctl.proc_translated 2>/dev/null || echo 0)" == "1" ]]; then- log "detected Rosetta-translated shell on Apple Silicon — switching to darwin-arm64"- ARCH_RAW="arm64"- fi-fi+# The actual Rust install logic lives at+# libs/cua-driver/scripts/_install-rust.sh — invoked by the canonical+# script when `--backend=rust` (or auto-detected on Linux). This shim+# just forwards there with `--backend=rust` to skip the auto-detect+# message on Linux and the macOS-Swift-default behavior.-# LABEL = the release-asset tarball label (matches what cd-rust-cua-driver.yml-# publishes; user-facing).-# TARGET = the Rust target triple, used in the on-disk per-version dir name so-# a multi-arch dev can keep e.g. aarch64-apple-darwin and-# x86_64-unknown-linux-gnu side by side under $HOME_DIR/packages/-# releases/ without collision.-case "$OS-$ARCH_RAW" in- Darwin-arm64|Darwin-aarch64) LABEL="darwin-arm64" ; TARGET="aarch64-apple-darwin" ;;- Darwin-x86_64) LABEL="darwin-x86_64" ; TARGET="x86_64-apple-darwin" ;;- Linux-x86_64|Linux-amd64) LABEL="linux-x86_64" ; TARGET="x86_64-unknown-linux-gnu" ;;- *)- err "unsupported platform: $OS / $ARCH_RAW"- err " cua-driver-rs ships prebuilts for: darwin-arm64, darwin-x86_64, linux-x86_64."- err " Windows users: install via install.ps1 (irm https://raw.githubusercontent.com/trycua/cua/main/libs/cua-driver-rs/scripts/install.ps1 | iex)."- exit 1- ;;-esac+set -euo pipefail-for cmd in curl tar; do- if ! command -v "$cmd" >/dev/null 2>&1; then- err "$cmd not found on PATH"- exit 1- fi-done+CANONICAL_URL="https://raw.githubusercontent.com/trycua/cua/main/libs/cua-driver/scripts/install.sh"-# --- Resolve release tag -------------------------------------------------#-# Version is resolved in priority order:-# 1. CUA_DRIVER_RS_VERSION env var (explicit pin)-# 2. CUA_DRIVER_RS_BAKED_VERSION below (set automatically by CD after-# each release — no API call needed)-# 3. GitHub Releases API (fallback for dev / un-baked checkouts;-# unauthenticated = 60 req/hr per IP)-#-# The baked value is the common-case default: `curl ... | bash` against-# `main` resolves the version locally with zero API calls, so an API-# outage / rate limit / network blip can't break a default install. The-# API fallback only fires when this script is run from a branch where-# the baked line hasn't been updated yet (dev / pre-release checkouts).-#-# ~~~ BAKED_VERSION: auto-updated by CD workflow after each release — do not edit ~~~-CUA_DRIVER_RS_BAKED_VERSION="0.2.3"-# ~~~ END_BAKED_VERSION ~~~+printf 'note: cua-driver-rs/scripts/install.sh is deprecated; fetching the\n' >&2+printf ' canonical installer from cua-driver/scripts/install.sh\n' >&2+printf ' The Rust port is still what gets installed — only the URL moved.\n' >&2+printf '\n' >&2-if [[ -n "${CUA_DRIVER_RS_VERSION:-}" ]]; then- TAG="${TAG_PREFIX}${CUA_DRIVER_RS_VERSION#v}"- log "using version from CUA_DRIVER_RS_VERSION: $TAG"-elif [[ -n "${CUA_DRIVER_RS_BAKED_VERSION:-}" ]]; then- TAG="${TAG_PREFIX}${CUA_DRIVER_RS_BAKED_VERSION#v}"- log "using baked release: $TAG"-else- log "resolving latest $TAG_PREFIX* release via GitHub API"- # Pinned to the exact `cua-driver-rs-v*` prefix so this script can never- # accidentally pick up a Swift `cua-driver-v*` release.- TAG=$(curl -fsSL "https://api.github.com/repos/$REPO/releases?per_page=40" \- | grep -Eo '"tag_name":[[:space:]]*"'"${TAG_PREFIX}"'[^"]+"' \- | sed -E 's/.*"'"${TAG_PREFIX}"'([0-9]+[.][0-9]+[.][0-9]+)"/\1/' \- | sort -t. -k1,1nr -k2,2nr -k3,3nr \- | head -n 1 \- | sed -E 's/^/'"${TAG_PREFIX}"'/')- if [[ -z "$TAG" ]]; then- err "no release matching ${TAG_PREFIX}* found on $REPO"- err " (cua-driver-rs is a BETA-stage cross-platform port; releases may not be published yet.)"- exit 1- fi- log "latest release: $TAG"+# Try on-disk first when invoked from a checked-out tree (dev / CI).+SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]:-$0}")" && pwd 2>/dev/null || true)"+ON_DISK="$SCRIPT_DIR/../../cua-driver/scripts/install.sh"+if [[ -n "$SCRIPT_DIR" && -f "$ON_DISK" ]]; then+ exec /bin/bash "$ON_DISK" --backend=rust "$@"fi-VERSION="${TAG#${TAG_PREFIX}}"--# --- Download bare-binary tarball -----------------------------------------# Tarball selection:-#-# macOS — fetch the directory tarball (cua-driver-rs-vN-darwin-universal.tar.gz).-# The directory layout includes `CuaDriverRs.app/` alongside the bare-# binary, which we need to install into /Applications so the TCC-# auto-relaunch path in `cua-driver-rs mcp` can resolve-# `com.trycua.cuadriverrs` via `open -n -g -a CuaDriverRs`. The-# directory variant carries the same universal binary as the-# bare-binary tarball, so users on both Apple Silicon and Intel-# get a working install from one download.-#-# Linux / Windows-via-WSL — use the bare-binary tarball. No bundle on-# these platforms, no TCC, no need to unpack a directory.-case "$LABEL" in- darwin-*) TARBALL="cua-driver-rs-${VERSION}-darwin-universal.tar.gz" ;;- *) TARBALL="cua-driver-rs-${VERSION}-${LABEL}-binary.tar.gz" ;;-esac-URL="https://github.com/$REPO/releases/download/$TAG/$TARBALL"--log "downloading $URL"-if ! curl -fsSL -o "$TMP_DIR/$TARBALL" "$URL"; then- err "download failed; try CUA_DRIVER_RS_VERSION=<version> to pin a specific release"+if ! command -v curl >/dev/null 2>&1; then+ printf 'error: curl not found on PATH; cannot fetch %s\n' "$CANONICAL_URL" >&2exit 1fi-log "extracting"-tar -xzf "$TMP_DIR/$TARBALL" -C "$TMP_DIR"--# Layout detection:-# macOS dir tarball expands to:-# cua-driver-rs-${VERSION}-darwin-universal/-# ├── cua-driver (bare universal binary)-# ├── CuaDriverRs.app/ (minimal bundle; copy of the same binary-# │ lives at Contents/MacOS/cua-driver)-# └── LICENSE-# Linux bare-binary tarball expands to:-# cua-driver (single file at the archive root)-case "$LABEL" in- darwin-*)- STAGE="cua-driver-rs-${VERSION}-darwin-universal"- SRC="$TMP_DIR/$STAGE/$BINARY_NAME"- SRC_APP="$TMP_DIR/$STAGE/$APP_NAME"- ;;- *)- SRC="$TMP_DIR/$BINARY_NAME"- SRC_APP=""- ;;-esac-if [[ ! -f "$SRC" ]]; then- err "expected $BINARY_NAME in tarball but didn't find it"- ls -la "$TMP_DIR"+CANONICAL_SCRIPT="$(curl -fsSL "$CANONICAL_URL")" || {+ printf 'error: failed to download canonical installer from %s\n' "$CANONICAL_URL" >&2exit 1-fi--# --- Install --------------------------------------------------------------mkdir -p "$BIN_DIR"--# macOS: install the .app to /Applications first, then symlink the-# bin into the bundle so `~/.local/bin/cua-driver` resolves into-# `/Applications/CuaDriverRs.app/Contents/MacOS/cua-driver`. The-# `realpath` walk in `is_executable_inside_cuadriverrs_app()` keys on-# that resolved path to know whether the auto-relaunch heuristic-# should fire. Same shape as the Swift `cua-driver` install path —-# different bundle id (com.trycua.cuadriverrs) so the two coexist.-#-# The macOS path intentionally does NOT use the-# $HOME_DIR/packages/releases/<v>/ + current symlink layout used on-# Linux. Reason: /Applications/CuaDriverRs.app placement is the-# anchor for both TCC attribution (cdhash + bundle id) and-# LaunchServices' `open -a CuaDriverRs` discovery — symlinking the-# .app from /Applications to a versioned dir under $HOME_DIR breaks-# both. The asymmetry is deliberate; rollback on macOS = reinstall-# an older release tag.-#-# Linux: drop the binary into the per-version dir under-# $HOME_DIR/packages/releases/<version>-<target>/ and swap the-# `current` symlink atomically. The visible $BIN_DIR/cua-driver-# symlinks into `current` so PATH consumers (and MCP client configs)-# never need to change when the active version moves.-#-# Fail fast on Darwin if the .app is missing — falling through to the-# bare-binary install would silently produce a CLI that can never-# auto-relaunch into a TCC-correct daemon. CodeRabbit #3.-if [[ "$OS" == "Darwin" ]]; then- if [[ -z "${SRC_APP:-}" || ! -d "$SRC_APP" ]]; then- err "macOS install requires the .app bundle (SRC_APP not found at ${SRC_APP:-<unset>})"- err " This usually means the downloaded tarball is missing CuaDriverRs.app — re-run the installer or"- err " pin a known-good release via CUA_DRIVER_RS_VERSION=<version>."- exit 1- fi-fi-if [[ "$OS" == "Darwin" && -n "$SRC_APP" && -d "$SRC_APP" ]]; then- if [[ ! -w "/Applications" ]]; then- err "/Applications is not writable. Re-run this installer in a shell where it is, or grant write access."- err " Without the .app bundle, \`cua-driver-rs mcp\` from an IDE terminal will not auto-relaunch into a TCC-correct daemon."- exit 1- fi- if [[ -e "$APP_DEST" ]]; then- log "removing existing $APP_DEST"- rm -rf "$APP_DEST"- fi- log "installing $APP_DEST"- # `ditto` preserves the bundle's metadata + nested symlinks the way- # Apple's installer would. `cp -R` works but doesn't preserve as- # much, and ditto is always present on macOS.- ditto "$SRC_APP" "$APP_DEST"- APP_BINARY="$APP_DEST/Contents/MacOS/$BINARY_NAME"- if [[ ! -x "$APP_BINARY" ]]; then- err "binary missing at $APP_BINARY (refusing to create broken symlink)"- exit 1- fi- ln -sf "$APP_BINARY" "$BIN_LINK"- log "symlinked $BIN_LINK -> $APP_BINARY"-else- # Linux: versioned-dirs + atomic `current` symlink swap.- #- # Layout under $HOME_DIR/packages/:- # releases/<version>-<target>/cua-driver (this install)- # releases/<older>-<target>/cua-driver (kept for rollback)- # current/cua-driver -> ../releases/<active>-<target>/cua-driver- #- # Swap mechanics: write the new symlink to `current.tmp`, then- # `mv -Tf current.tmp current` so the rename is a single- # filesystem call. A daemon that already mmap'd the previous- # `current/cua-driver` keeps using the open file handle — Unix- # only invalidates path-based lookups, not held fds.- PACKAGES_DIR="$HOME_DIR/packages"- RELEASES_DIR="$PACKAGES_DIR/releases"- CURRENT_LINK="$PACKAGES_DIR/current"- VERSIONED_DIR="$RELEASES_DIR/${VERSION}-${TARGET}"-- mkdir -p "$VERSIONED_DIR"- install -m 0755 "$SRC" "$VERSIONED_DIR/$BINARY_NAME"- log "installed $VERSIONED_DIR/$BINARY_NAME (version $VERSION, target $TARGET)"-- # `ln -sfn` would replace an existing dir-symlink in place but is- # not atomic on Linux (it unlinks then symlinks). Use a tmp symlink- # + atomic rename instead so a concurrent `cua-driver` lookup- # always sees either the old or new target, never an absent path.- TMP_LINK="$PACKAGES_DIR/.current.$$"- rm -rf "$TMP_LINK"- # Relative target so the link is portable if $HOME_DIR is moved.- ln -s "releases/${VERSION}-${TARGET}" "$TMP_LINK"- # `mv -Tf` is the atomic-rename form on GNU coreutils (Linux). On- # BSD mv (macOS — which doesn't take this branch in production, but- # we still want this script to be runnable from a macOS dev shell- # for testing) `-T` is unknown; fall back to a non-atomic rm+mv.- if ! mv -Tf "$TMP_LINK" "$CURRENT_LINK" 2>/dev/null; then- rm -rf "$CURRENT_LINK"- mv "$TMP_LINK" "$CURRENT_LINK"- fi- log "current -> releases/${VERSION}-${TARGET}"-- # Visible PATH entry: replace whatever was at $BIN_LINK (could be- # an old plain binary from a pre-versioned-dirs install) with a- # symlink into `current`.- rm -f "$BIN_LINK"- ln -s "$CURRENT_LINK/$BINARY_NAME" "$BIN_LINK"- log "symlinked $BIN_LINK -> $CURRENT_LINK/$BINARY_NAME"-- # Post-install GC of old per-version release dirs. Runs AFTER the- # atomic `current` swap above so the about-to-be-active version is- # never a deletion candidate (it's both the newest by mtime and- # exempted via the current-symlink check inside prune_old_releases).- prune_old_releases "$RELEASES_DIR" "$CURRENT_LINK" "$TARGET" "$KEEP_VERSIONS"-fi--# Agent skill pack: NOT auto-linked. The install script never touches-# ~/.claude/skills/, ~/.agents/skills/, etc. Run `cua-driver skills-# install` after install to fetch + symlink the skill pack from the-# matching GitHub release. The post-install hint below points at the-# verb.--# --- Fire the one-shot install telemetry ping ----------------------------#-# Anonymous adoption signal — sends `cua_driver_install` to PostHog-# exactly once per install (guarded by ~/.cua-driver-rs/.installation_recorded-# on the binary side). The Rust port keeps its install signal independent-# of the Swift `cua-driver` install (separate marker dir + separate env var)-# so users can opt out of one without affecting the other.-#-# Bypasses the CUA_DRIVER_RS_TELEMETRY_ENABLED check by design — see-# `telemetry::capture_install()` for the rationale (count adoption even-# when users opt out immediately after install). Every subsequent event-# from the binary respects the opt-out normally.-#-# Background + redirect so a slow / failed POST never blocks the install.-"$BIN_LINK" telemetry install-event >/dev/null 2>&1 &-disown 2>/dev/null || true--# Auto-extend PATH for users whose shell doesn't already include BIN_DIR.-if [[ "$NO_MODIFY_PATH" != "1" ]] && [[ ":$PATH:" != *":$BIN_DIR:"* ]]; then- SHELL_RC=""- case "${SHELL:-}" in- */zsh) SHELL_RC="$HOME/.zshrc" ;;- */bash) SHELL_RC="$HOME/.bashrc" ;;- esac- if [[ -n "$SHELL_RC" ]]; then- {- printf '\n# Added by cua-driver-rs installer — see https://github.com/trycua/cua\n'- printf 'export PATH="%s:$PATH"\n' "$BIN_DIR"- } >> "$SHELL_RC"- log "appended PATH update to $SHELL_RC — open a new shell or run \`source $SHELL_RC\`"- else- log "WARNING: $BIN_DIR is not on PATH; add it manually."- fi-fi--echo ""-echo "cua-driver-rs $VERSION installed."-echo ""-echo "Try it:"-echo " $BIN_LINK list-tools"-echo " $BIN_LINK list_apps"-echo ""-echo "Agent skill pack (optional):"-echo " $BIN_LINK skills install # fetch + link the cua-driver-rs skill pack"-echo " # into Claude Code / Codex / OpenClaw / OpenCode."-echo " # The install never touches your agent dirs."-echo ""-echo "Docs: https://github.com/trycua/cua/tree/main/libs/cua-driver-rs"-echo ""-echo "⚠️ BETA: cua-driver-rs is a cross-platform Rust port of the Swift"-echo " cua-driver. Windows and Linux support is feature-complete; macOS"-echo " parity with the Swift binary is in progress. For production macOS"-echo " use, prefer the original install:"-echo " /bin/bash -c \"\$(curl -fsSL https://raw.githubusercontent.com/trycua/cua/main/libs/cua-driver/scripts/install.sh)\""+}+exec /bin/bash -c "$CANONICAL_SCRIPT" install --backend=rust "$@"diff --git a/libs/cua-driver/scripts/_install-rust.sh b/libs/cua-driver/scripts/_install-rust.shnew file mode 100644index 0000000000..33e78e2bb2--- /dev/null+++ b/libs/cua-driver/scripts/_install-rust.sh@@ -0,0 +1,649 @@+#!/usr/bin/env bash+# _install-rust.sh — private helper invoked by libs/cua-driver/scripts/install.sh+# (the canonical user-facing installer) when --backend=rust is selected or+# the script auto-detects a non-macOS host. Not intended for direct+# invocation; user-facing one-liners always go through the parent+# install.sh, which forwards args + sets up the lockfile.+#+# Downloads the latest cua-driver-rs release tarball from GitHub Releases+# and drops the binary into ~/.local/bin (or a path given via --bin-dir /+# CUA_DRIVER_RS_INSTALL_DIR). Sudo-free.+#+# This is the Rust port of cua-driver — cross-platform (macOS / Linux /+# Windows via WSL or git-bash) computer-use automation. The Swift+# cua-driver (macOS only) ships separately under tag prefix `cua-driver-v*`+# and is installed via the same `libs/cua-driver/scripts/install.sh` (no+# flag); this helper is hard-pinned to `cua-driver-rs-v*` and will never+# pick up the Swift binary.+#+# Canonical user-facing invocation (forwards here on Linux / --backend=rust):+# /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/trycua/cua/main/libs/cua-driver/scripts/install.sh)"+#+# Legacy URL (backward-compat shim at libs/cua-driver-rs/scripts/install.sh+# redirects here):+# /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/trycua/cua/main/libs/cua-driver-rs/scripts/install.sh)"+#+# Flags:+# --bin-dir <path> install the visible binary/symlink to <path>+# instead of ~/.local/bin+# --no-modify-path skip auto-appending an `export PATH=...` line+#+# Env overrides:+# CUA_DRIVER_RS_VERSION=0.1.2 pin a specific release tag+# CUA_DRIVER_RS_INSTALL_DIR=PATH same as --bin-dir; sets the visible+# binary location+# CUA_DRIVER_RS_BIN_DIR=PATH legacy alias for INSTALL_DIR+# CUA_DRIVER_RS_HOME=PATH package home for versioned installs+# (default ~/.cua-driver-rs). Holds+# packages/releases/<v>-<target>/ and+# packages/current/ on Linux/Windows.+# CUA_DRIVER_RS_NO_MODIFY_PATH=1 same as --no-modify-path+# CUA_DRIVER_RS_KEEP_VERSIONS=N keep the N most recent per-version+# release dirs after install; older+# ones are deleted (default 5; set 0+# to disable GC entirely). Per-target+# — multi-arch dirs are pruned+# independently of each other.+#+# On-disk layout (Linux; macOS keeps its .app-in-/Applications layout, see+# below):+# $CUA_DRIVER_RS_HOME/+# packages/+# releases/+# 0.1.3-x86_64-unknown-linux-gnu/cua-driver (per-version binary)+# 0.1.4-x86_64-unknown-linux-gnu/cua-driver+# current/cua-driver -> ../releases/<active>/cua-driver (active version)+# $CUA_DRIVER_RS_INSTALL_DIR/cua-driver -> $HOME/packages/current/cua-driver+#+# Atomic upgrade: a new install drops the binary into a fresh per-version+# dir, then rename(2)-swaps the `current` symlink to point at it. A+# running daemon keeps its already-mmap'd binary open across the swap+# (open file handles survive). Rollback: re-point `current` at any older+# entry under `releases/`.+#+# Post-install GC trims the per-target release dirs so disk usage stays+# bounded (each release dir is ~15 MB, so an indefinite series of+# upgrades grows without bound). The N most-recent dirs are kept (default+# 5, override via CUA_DRIVER_RS_KEEP_VERSIONS); the dir that `current`+# resolves to is always preserved even if its mtime would otherwise drop+# it off the list. GC runs after the atomic swap so the about-to-be-active+# version is never a deletion candidate.+#+# ⚠️ This is a BETA release. The Rust port is feature-complete on Windows+# and Linux; macOS parity with the Swift cua-driver is in progress. For+# production macOS automation prefer `libs/cua-driver/scripts/install.sh`.+set -euo pipefail++REPO="trycua/cua"+BINARY_NAME="cua-driver"+TAG_PREFIX="cua-driver-rs-v"+# CUA_DRIVER_RS_INSTALL_DIR is the documented name; CUA_DRIVER_RS_BIN_DIR is+# the legacy alias kept for users with the old env in their shell rc.+BIN_DIR="${CUA_DRIVER_RS_INSTALL_DIR:-${CUA_DRIVER_RS_BIN_DIR:-$HOME/.local/bin}}"+HOME_DIR="${CUA_DRIVER_RS_HOME:-$HOME/.cua-driver-rs}"+NO_MODIFY_PATH="${CUA_DRIVER_RS_NO_MODIFY_PATH:-0}"+# Post-install GC: how many per-version release dirs to retain. Validated+# below as a non-negative integer; 0 means "never GC". The dir that+# `current` resolves to is always preserved regardless of cutoff.+KEEP_VERSIONS_DEFAULT=5+KEEP_VERSIONS="${CUA_DRIVER_RS_KEEP_VERSIONS:-$KEEP_VERSIONS_DEFAULT}"++# macOS-only: name and install location of the .app bundle that wraps+# the bare binary so the TCC auto-relaunch path in `cua-driver-rs mcp`+# has a stable bundle id (com.trycua.cuadriverrs) to attribute the+# daemon to. See libs/cua-driver-rs/scripts/CuaDriverRs.app/Contents/+# Info.plist and the matching docs on `cua-driver-rs mcp`'s auto-+# relaunch behavior. Distinct from the Swift driver's CuaDriver.app+# (com.trycua.driver) so the two installs coexist on the same machine.+APP_NAME="CuaDriverRs.app"+APP_DEST="/Applications/$APP_NAME"++while [[ $# -gt 0 ]]; do+ case "$1" in+ --bin-dir) BIN_DIR="$2"; shift 2 ;;+ --bin-dir=*) BIN_DIR="${1#*=}"; shift ;;+ --no-modify-path) NO_MODIFY_PATH=1; shift ;;+ *) shift ;;+ esac+done++# Validate KEEP_VERSIONS up front so a typo (e.g. "five") falls back to+# the default instead of silently disabling GC. Accepts any non-negative+# integer; 0 is the documented "never GC" sentinel.+if ! [[ "$KEEP_VERSIONS" =~ ^[0-9]+$ ]]; then+ printf 'warning: CUA_DRIVER_RS_KEEP_VERSIONS=%s is not a non-negative integer; falling back to %d\n' \+ "$KEEP_VERSIONS" "$KEEP_VERSIONS_DEFAULT" >&2+ KEEP_VERSIONS="$KEEP_VERSIONS_DEFAULT"+fi++BIN_LINK="$BIN_DIR/$BINARY_NAME"+TMP_DIR=$(mktemp -d)++log() { printf '==> %s\n' "$*"; }+err() { printf 'error: %s\n' "$*" >&2; }++# --- Concurrent-install lockfile ---------------------------------------+#+# A second install kicked off while a first is still running can race+# on the atomic `current` symlink swap and produce a half-installed+# state (e.g. the symlink points at a dir whose binary the first install+# hasn't finished copying). Serialize installs per $HOME_DIR with a+# process-level mutex.+#+# Primitive: mkdir on POSIX is atomic. The first install to create+# $LOCK_DIR holds the lock; concurrent attempts get EEXIST and poll.+# Released via trap on every exit path (success, error, signal) so+# a half-finished install always frees the lock for the next one.+#+# Stale-lock recovery: if the holder dies without releasing (kill -9,+# OOM, host reboot mid-install), the lock dir sits around forever and+# every subsequent install hangs. After $LOCK_STALE_AFTER_SECONDS of+# waiting we probe the holder's liveness via `kill -0 <pid>` (the pid+# is stamped into $LOCK_INFO right after acquisition) — if the holder+# is alive we keep waiting (slow download / wedged network is not the+# same as a crashed install and we must not yank the lock out from+# under a live process), if it's dead we force-release with a loud log+# and proceed. The alternative (hang forever) leaves users in a+# permanently wedged state with no clear recovery path beyond `rm -rf`+# on an internal-looking dir.+LOCK_PACKAGES_DIR="$HOME_DIR/packages"+LOCK_DIR="$LOCK_PACKAGES_DIR/.install.lock.d"+LOCK_INFO="$LOCK_DIR/info"+LOCK_POLL_INTERVAL_SECONDS=1+LOCK_STALE_AFTER_SECONDS=600++LOCK_HELD=0+release_install_lock() {+ if (( LOCK_HELD == 1 )); then+ rm -rf "$LOCK_DIR" 2>/dev/null || true+ LOCK_HELD=0+ fi+}++# Combine TMP_DIR cleanup with lock release in a single trap so neither+# clobbers the other. INT/TERM also re-raise via $? so the user-visible+# exit code reflects the signal.+cleanup_on_exit() {+ rm -rf "$TMP_DIR" 2>/dev/null || true+ release_install_lock+}+trap cleanup_on_exit EXIT+trap 'cleanup_on_exit; trap - INT; kill -INT $$' INT+trap 'cleanup_on_exit; trap - TERM; kill -TERM $$' TERM++acquire_install_lock() {+ mkdir -p "$LOCK_PACKAGES_DIR"+ local waited=0+ while ! mkdir "$LOCK_DIR" 2>/dev/null; do+ if (( waited == 0 )); then+ log "another cua-driver-rs install is already in progress (lock at $LOCK_DIR); waiting..."+ fi+ sleep "$LOCK_POLL_INTERVAL_SECONDS"+ waited=$((waited + LOCK_POLL_INTERVAL_SECONDS))+ if (( waited >= LOCK_STALE_AFTER_SECONDS )); then+ # Don't yank the lock from a live install. Parse pid= from+ # the info file (written by the holder right after mkdir);+ # if that pid is still alive per kill -0, the holder is just+ # slow (big download, wedged network) — keep waiting. Only+ # reclaim when there's no live holder.+ #+ # Missing/unreadable info file → holder didn't get far enough+ # to stamp pid, so assume dead and reclaim. Unparseable pid+ # line → same. Either way we err on the side of progress+ # rather than hanging forever once the 600s window elapses.+ local holder_pid=""+ if [[ -r "$LOCK_INFO" ]]; then+ holder_pid=$(grep -E '^pid=' "$LOCK_INFO" 2>/dev/null | head -1 | cut -d= -f2)+ fi+ if [[ -n "$holder_pid" ]] && kill -0 "$holder_pid" 2>/dev/null; then+ log "lock at $LOCK_DIR still held by live pid $holder_pid; continuing to wait"+ # Reset waited so we re-check after another full window+ # rather than spamming this branch every poll interval.+ waited=0+ continue+ fi+ log "lock at $LOCK_DIR appears stale (>${LOCK_STALE_AFTER_SECONDS}s, no live holder); forcing release"+ rm -rf "$LOCK_DIR" 2>/dev/null || true+ waited=0+ fi+ done+ LOCK_HELD=1+ # Drop pid + ISO timestamp + invocation args into the lock dir so a+ # user investigating a stuck install can see who holds it (`cat+ # $HOME_DIR/packages/.install.lock.d/info`).+ {+ printf 'pid=%s\n' "$$"+ printf 'started=%s\n' "$(date -u +'%Y-%m-%dT%H:%M:%SZ' 2>/dev/null || date)"+ printf 'argv=%s\n' "$0 $*"+ } > "$LOCK_INFO" 2>/dev/null || true+}++acquire_install_lock "$@"++# Prune per-version release dirs under $RELEASES_DIR for the current+# $TARGET, keeping the N most recent (by mtime). The dir that the+# `current` symlink resolves to is always preserved — even if it's+# older than the cutoff — so we never delete the active install.+#+# Filtering is by target-triple suffix so a multi-arch dev with both+# (e.g.) aarch64-apple-darwin and x86_64-unknown-linux-gnu under the+# same $HOME_DIR keeps each target's history independently. Other-arch+# dirs are invisible to this prune pass.+#+# Args: $1 = releases dir, $2 = current symlink path, $3 = target triple,+# $4 = keep count (non-negative integer; 0 = skip).+prune_old_releases() {+ local releases_dir="$1" current_link="$2" target="$3" keep="$4"++ if [[ "$keep" == "0" ]]; then+ log "version GC disabled (CUA_DRIVER_RS_KEEP_VERSIONS=0)"+ return 0+ fi+ if [[ ! -d "$releases_dir" ]]; then+ return 0+ fi++ # Resolve the dir `current` points at so we can exempt it from the+ # prune candidates. `readlink -f` would canonicalize, but BSD readlink+ # (macOS — which doesn't reach here in production but is tested from+ # a dev shell) lacks -f, so use the more portable two-step.+ local current_target=""+ if [[ -L "$current_link" ]]; then+ local link_value+ link_value=$(readlink "$current_link" 2>/dev/null || true)+ if [[ -n "$link_value" ]]; then+ case "$link_value" in+ /*) current_target="$link_value" ;;+ *) current_target="$(dirname "$current_link")/$link_value" ;;+ esac+ fi+ fi++ # `ls -dt` sorts dirs by mtime, newest-first. The trailing slash on+ # the glob filters to dirs only. Skip if no matching dirs (the glob+ # would otherwise pass through literally under shopt -s nullglob being+ # off — guard with 2>/dev/null and an `|| true`).+ local candidates=()+ while IFS= read -r dir; do+ [[ -n "$dir" ]] || continue+ # Strip trailing slash for consistent comparison with $current_target.+ dir="${dir%/}"+ # Only consider dirs whose name ends in the current target triple.+ local base="${dir##*/}"+ case "$base" in+ *-"$target") candidates+=("$dir") ;;+ *) ;;+ esac+ done < <(ls -dt "$releases_dir"/*/ 2>/dev/null || true)++ if [[ ${#candidates[@]} -le "$keep" ]]; then+ return 0+ fi++ # Walk candidates newest-first. The first $keep are retained by mtime+ # (active install counts toward the budget in the common case where+ # the install just happened — it's the newest by mtime). The active+ # install is *additionally* preserved even if it would otherwise fall+ # outside the keep window (e.g. user rolled back to an old version),+ # so the worst-case post-GC count is $keep + 1, common case is exactly+ # $keep.+ local to_prune=()+ local kept=0+ local i+ for ((i=0; i<${#candidates[@]}; i++)); do+ local cand="${candidates[$i]}"+ local is_current=0+ if [[ -n "$current_target" && "${cand%/}" == "${current_target%/}" ]]; then+ is_current=1+ fi+ if (( kept < keep )); then+ kept=$((kept + 1))+ continue+ fi+ if (( is_current == 1 )); then+ # Active install fell outside the keep window — preserve+ # anyway (never delete the dir that's about to serve the+ # next `cua-driver` invocation).+ continue+ fi+ to_prune+=("$cand")+ done++ if [[ ${#to_prune[@]} -eq 0 ]]; then+ return 0+ fi++ log "pruning ${#to_prune[@]} old release dir(s) (keeping $keep most recent for $target):"+ local p+ for p in "${to_prune[@]}"; do+ log " - ${p##*/}"+ done+ printf '%s\0' "${to_prune[@]}" | xargs -0 rm -rf+}++# --- Resolve OS/arch ----------------------------------------------------++OS=$(uname -s)+ARCH_RAW=$(uname -m)++# Rosetta translation correction.+#+# `uname -m` reflects the architecture of the *running process*, not the+# physical CPU. When an Apple Silicon Mac is driving an x86_64-translated+# shell (Rosetta — e.g. `arch -x86_64 bash`, or a Homebrew install pinned+# to /usr/local/), uname reports x86_64 even though the native arch is+# arm64. We'd then download the x86_64 binary and run it under Rosetta —+# slower, and an unnecessary translation when a native arm64 binary+# exists on the release page.+#+# `sysctl.proc_translated` returns 1 when the current process is running+# under Rosetta translation; absent/0 means native. Only meaningful on+# macOS — the sysctl key is missing on Linux, so the redirect-to-null+# keeps the check a silent no-op there.+if [[ "$OS" == "Darwin" && "$ARCH_RAW" == "x86_64" ]]; then+ if [[ "$(sysctl -n sysctl.proc_translated 2>/dev/null || echo 0)" == "1" ]]; then+ log "detected Rosetta-translated shell on Apple Silicon — switching to darwin-arm64"+ ARCH_RAW="arm64"+ fi+fi++# LABEL = the release-asset tarball label (matches what cd-rust-cua-driver.yml+# publishes; user-facing).+# TARGET = the Rust target triple, used in the on-disk per-version dir name so+# a multi-arch dev can keep e.g. aarch64-apple-darwin and+# x86_64-unknown-linux-gnu side by side under $HOME_DIR/packages/+# releases/ without collision.+case "$OS-$ARCH_RAW" in+ Darwin-arm64|Darwin-aarch64) LABEL="darwin-arm64" ; TARGET="aarch64-apple-darwin" ;;+ Darwin-x86_64) LABEL="darwin-x86_64" ; TARGET="x86_64-apple-darwin" ;;+ Linux-x86_64|Linux-amd64) LABEL="linux-x86_64" ; TARGET="x86_64-unknown-linux-gnu" ;;+ *)+ err "unsupported platform: $OS / $ARCH_RAW"+ err " cua-driver-rs ships prebuilts for: darwin-arm64, darwin-x86_64, linux-x86_64."+ err " Windows users: install via install.ps1 (irm https://raw.githubusercontent.com/trycua/cua/main/libs/cua-driver-rs/scripts/install.ps1 | iex)."+ exit 1+ ;;+esac++for cmd in curl tar; do+ if ! command -v "$cmd" >/dev/null 2>&1; then+ err "$cmd not found on PATH"+ exit 1+ fi+done++# --- Resolve release tag ------------------------------------------------+#+# Version is resolved in priority order:+# 1. CUA_DRIVER_RS_VERSION env var (explicit pin)+# 2. CUA_DRIVER_RS_BAKED_VERSION below (set automatically by CD after+# each release — no API call needed)+# 3. GitHub Releases API (fallback for dev / un-baked checkouts;+# unauthenticated = 60 req/hr per IP)+#+# The baked value is the common-case default: `curl ... | bash` against+# `main` resolves the version locally with zero API calls, so an API+# outage / rate limit / network blip can't break a default install. The+# API fallback only fires when this script is run from a branch where+# the baked line hasn't been updated yet (dev / pre-release checkouts).+#+# ~~~ BAKED_VERSION: auto-updated by CD workflow after each release — do not edit ~~~+CUA_DRIVER_RS_BAKED_VERSION="0.2.3"+# ~~~ END_BAKED_VERSION ~~~++if [[ -n "${CUA_DRIVER_RS_VERSION:-}" ]]; then+ TAG="${TAG_PREFIX}${CUA_DRIVER_RS_VERSION#v}"+ log "using version from CUA_DRIVER_RS_VERSION: $TAG"+elif [[ -n "${CUA_DRIVER_RS_BAKED_VERSION:-}" ]]; then+ TAG="${TAG_PREFIX}${CUA_DRIVER_RS_BAKED_VERSION#v}"+ log "using baked release: $TAG"+else+ log "resolving latest $TAG_PREFIX* release via GitHub API"+ # Pinned to the exact `cua-driver-rs-v*` prefix so this script can never+ # accidentally pick up a Swift `cua-driver-v*` release.+ TAG=$(curl -fsSL "https://api.github.com/repos/$REPO/releases?per_page=40" \+ | grep -Eo '"tag_name":[[:space:]]*"'"${TAG_PREFIX}"'[^"]+"' \+ | sed -E 's/.*"'"${TAG_PREFIX}"'([0-9]+[.][0-9]+[.][0-9]+)"/\1/' \+ | sort -t. -k1,1nr -k2,2nr -k3,3nr \+ | head -n 1 \+ | sed -E 's/^/'"${TAG_PREFIX}"'/')+ if [[ -z "$TAG" ]]; then+ err "no release matching ${TAG_PREFIX}* found on $REPO"+ err " (cua-driver-rs is a BETA-stage cross-platform port; releases may not be published yet.)"+ exit 1+ fi+ log "latest release: $TAG"+fi++VERSION="${TAG#${TAG_PREFIX}}"++# --- Download bare-binary tarball ---------------------------------------++# Tarball selection:+#+# macOS — fetch the directory tarball (cua-driver-rs-vN-darwin-universal.tar.gz).+# The directory layout includes `CuaDriverRs.app/` alongside the bare+# binary, which we need to install into /Applications so the TCC+# auto-relaunch path in `cua-driver-rs mcp` can resolve+# `com.trycua.cuadriverrs` via `open -n -g -a CuaDriverRs`. The+# directory variant carries the same universal binary as the+# bare-binary tarball, so users on both Apple Silicon and Intel+# get a working install from one download.+#+# Linux / Windows-via-WSL — use the bare-binary tarball. No bundle on+# these platforms, no TCC, no need to unpack a directory.+case "$LABEL" in+ darwin-*) TARBALL="cua-driver-rs-${VERSION}-darwin-universal.tar.gz" ;;+ *) TARBALL="cua-driver-rs-${VERSION}-${LABEL}-binary.tar.gz" ;;+esac+URL="https://github.com/$REPO/releases/download/$TAG/$TARBALL"++log "downloading $URL"+if ! curl -fsSL -o "$TMP_DIR/$TARBALL" "$URL"; then+ err "download failed; try CUA_DRIVER_RS_VERSION=<version> to pin a specific release"+ exit 1+fi++log "extracting"+tar -xzf "$TMP_DIR/$TARBALL" -C "$TMP_DIR"++# Layout detection:+# macOS dir tarball expands to:+# cua-driver-rs-${VERSION}-darwin-universal/+# ├── cua-driver (bare universal binary)+# ├── CuaDriverRs.app/ (minimal bundle; copy of the same binary+# │ lives at Contents/MacOS/cua-driver)+# └── LICENSE+# Linux bare-binary tarball expands to:+# cua-driver (single file at the archive root)+case "$LABEL" in+ darwin-*)+ STAGE="cua-driver-rs-${VERSION}-darwin-universal"+ SRC="$TMP_DIR/$STAGE/$BINARY_NAME"+ SRC_APP="$TMP_DIR/$STAGE/$APP_NAME"+ ;;+ *)+ SRC="$TMP_DIR/$BINARY_NAME"+ SRC_APP=""+ ;;+esac+if [[ ! -f "$SRC" ]]; then+ err "expected $BINARY_NAME in tarball but didn't find it"+ ls -la "$TMP_DIR"+ exit 1+fi++# --- Install ------------------------------------------------------------++mkdir -p "$BIN_DIR"++# macOS: install the .app to /Applications first, then symlink the+# bin into the bundle so `~/.local/bin/cua-driver` resolves into+# `/Applications/CuaDriverRs.app/Contents/MacOS/cua-driver`. The+# `realpath` walk in `is_executable_inside_cuadriverrs_app()` keys on+# that resolved path to know whether the auto-relaunch heuristic+# should fire. Same shape as the Swift `cua-driver` install path —+# different bundle id (com.trycua.cuadriverrs) so the two coexist.+#+# The macOS path intentionally does NOT use the+# $HOME_DIR/packages/releases/<v>/ + current symlink layout used on+# Linux. Reason: /Applications/CuaDriverRs.app placement is the+# anchor for both TCC attribution (cdhash + bundle id) and+# LaunchServices' `open -a CuaDriverRs` discovery — symlinking the+# .app from /Applications to a versioned dir under $HOME_DIR breaks+# both. The asymmetry is deliberate; rollback on macOS = reinstall+# an older release tag.+#+# Linux: drop the binary into the per-version dir under+# $HOME_DIR/packages/releases/<version>-<target>/ and swap the+# `current` symlink atomically. The visible $BIN_DIR/cua-driver+# symlinks into `current` so PATH consumers (and MCP client configs)+# never need to change when the active version moves.+#+# Fail fast on Darwin if the .app is missing — falling through to the+# bare-binary install would silently produce a CLI that can never+# auto-relaunch into a TCC-correct daemon. CodeRabbit #3.+if [[ "$OS" == "Darwin" ]]; then+ if [[ -z "${SRC_APP:-}" || ! -d "$SRC_APP" ]]; then+ err "macOS install requires the .app bundle (SRC_APP not found at ${SRC_APP:-<unset>})"+ err " This usually means the downloaded tarball is missing CuaDriverRs.app — re-run the installer or"+ err " pin a known-good release via CUA_DRIVER_RS_VERSION=<version>."+ exit 1+ fi+fi+if [[ "$OS" == "Darwin" && -n "$SRC_APP" && -d "$SRC_APP" ]]; then+ if [[ ! -w "/Applications" ]]; then+ err "/Applications is not writable. Re-run this installer in a shell where it is, or grant write access."+ err " Without the .app bundle, \`cua-driver-rs mcp\` from an IDE terminal will not auto-relaunch into a TCC-correct daemon."+ exit 1+ fi+ if [[ -e "$APP_DEST" ]]; then+ log "removing existing $APP_DEST"+ rm -rf "$APP_DEST"+ fi+ log "installing $APP_DEST"+ # `ditto` preserves the bundle's metadata + nested symlinks the way+ # Apple's installer would. `cp -R` works but doesn't preserve as+ # much, and ditto is always present on macOS.+ ditto "$SRC_APP" "$APP_DEST"+ APP_BINARY="$APP_DEST/Contents/MacOS/$BINARY_NAME"+ if [[ ! -x "$APP_BINARY" ]]; then+ err "binary missing at $APP_BINARY (refusing to create broken symlink)"+ exit 1+ fi+ ln -sf "$APP_BINARY" "$BIN_LINK"+ log "symlinked $BIN_LINK -> $APP_BINARY"+else+ # Linux: versioned-dirs + atomic `current` symlink swap.+ #+ # Layout under $HOME_DIR/packages/:+ # releases/<version>-<target>/cua-driver (this install)+ # releases/<older>-<target>/cua-driver (kept for rollback)+ # current/cua-driver -> ../releases/<active>-<target>/cua-driver+ #+ # Swap mechanics: write the new symlink to `current.tmp`, then+ # `mv -Tf current.tmp current` so the rename is a single+ # filesystem call. A daemon that already mmap'd the previous+ # `current/cua-driver` keeps using the open file handle — Unix+ # only invalidates path-based lookups, not held fds.+ PACKAGES_DIR="$HOME_DIR/packages"+ RELEASES_DIR="$PACKAGES_DIR/releases"+ CURRENT_LINK="$PACKAGES_DIR/current"+ VERSIONED_DIR="$RELEASES_DIR/${VERSION}-${TARGET}"++ mkdir -p "$VERSIONED_DIR"+ install -m 0755 "$SRC" "$VERSIONED_DIR/$BINARY_NAME"+ log "installed $VERSIONED_DIR/$BINARY_NAME (version $VERSION, target $TARGET)"++ # `ln -sfn` would replace an existing dir-symlink in place but is+ # not atomic on Linux (it unlinks then symlinks). Use a tmp symlink+ # + atomic rename instead so a concurrent `cua-driver` lookup+ # always sees either the old or new target, never an absent path.+ TMP_LINK="$PACKAGES_DIR/.current.$$"+ rm -rf "$TMP_LINK"+ # Relative target so the link is portable if $HOME_DIR is moved.+ ln -s "releases/${VERSION}-${TARGET}" "$TMP_LINK"+ # `mv -Tf` is the atomic-rename form on GNU coreutils (Linux). On+ # BSD mv (macOS — which doesn't take this branch in production, but+ # we still want this script to be runnable from a macOS dev shell+ # for testing) `-T` is unknown; fall back to a non-atomic rm+mv.+ if ! mv -Tf "$TMP_LINK" "$CURRENT_LINK" 2>/dev/null; then+ rm -rf "$CURRENT_LINK"+ mv "$TMP_LINK" "$CURRENT_LINK"+ fi+ log "current -> releases/${VERSION}-${TARGET}"++ # Visible PATH entry: replace whatever was at $BIN_LINK (could be+ # an old plain binary from a pre-versioned-dirs install) with a+ # symlink into `current`.+ rm -f "$BIN_LINK"+ ln -s "$CURRENT_LINK/$BINARY_NAME" "$BIN_LINK"+ log "symlinked $BIN_LINK -> $CURRENT_LINK/$BINARY_NAME"++ # Post-install GC of old per-version release dirs. Runs AFTER the+ # atomic `current` swap above so the about-to-be-active version is+ # never a deletion candidate (it's both the newest by mtime and+ # exempted via the current-symlink check inside prune_old_releases).+ prune_old_releases "$RELEASES_DIR" "$CURRENT_LINK" "$TARGET" "$KEEP_VERSIONS"+fi++# Agent skill pack: NOT auto-linked. The install script never touches+# ~/.claude/skills/, ~/.agents/skills/, etc. Run `cua-driver skills+# install` after install to fetch + symlink the skill pack from the+# matching GitHub release. The post-install hint below points at the+# verb.++# --- Fire the one-shot install telemetry ping ---------------------------+#+# Anonymous adoption signal — sends `cua_driver_install` to PostHog+# exactly once per install (guarded by ~/.cua-driver-rs/.installation_recorded+# on the binary side). The Rust port keeps its install signal independent+# of the Swift `cua-driver` install (separate marker dir + separate env var)+# so users can opt out of one without affecting the other.+#+# Bypasses the CUA_DRIVER_RS_TELEMETRY_ENABLED check by design — see+# `telemetry::capture_install()` for the rationale (count adoption even+# when users opt out immediately after install). Every subsequent event+# from the binary respects the opt-out normally.+#+# Background + redirect so a slow / failed POST never blocks the install.+"$BIN_LINK" telemetry install-event >/dev/null 2>&1 &+disown 2>/dev/null || true++# Auto-extend PATH for users whose shell doesn't already include BIN_DIR.+if [[ "$NO_MODIFY_PATH" != "1" ]] && [[ ":$PATH:" != *":$BIN_DIR:"* ]]; then+ SHELL_RC=""+ case "${SHELL:-}" in+ */zsh) SHELL_RC="$HOME/.zshrc" ;;+ */bash) SHELL_RC="$HOME/.bashrc" ;;+ esac+ if [[ -n "$SHELL_RC" ]]; then+ {+ printf '\n# Added by cua-driver-rs installer — see https://github.com/trycua/cua\n'+ printf 'export PATH="%s:$PATH"\n' "$BIN_DIR"+ } >> "$SHELL_RC"+ log "appended PATH update to $SHELL_RC — open a new shell or run \`source $SHELL_RC\`"+ else+ log "WARNING: $BIN_DIR is not on PATH; add it manually."+ fi+fi++echo ""+echo "cua-driver-rs $VERSION installed."+echo ""+echo "Try it:"+echo " $BIN_LINK list-tools"+echo " $BIN_LINK list_apps"+echo ""+echo "Agent skill pack (optional):"+echo " $BIN_LINK skills install # fetch + link the cua-driver-rs skill pack"+echo " # into Claude Code / Codex / OpenClaw / OpenCode."+echo " # The install never touches your agent dirs."+echo ""+echo "Docs: https://github.com/trycua/cua/tree/main/libs/cua-driver-rs"+echo ""+echo "⚠️ BETA: cua-driver-rs is a cross-platform Rust port of the Swift"+echo " cua-driver. Windows and Linux support is feature-complete; macOS"+echo " parity with the Swift binary is in progress. For production macOS"+echo " use, prefer the original install:"+echo " /bin/bash -c \"\$(curl -fsSL https://raw.githubusercontent.com/trycua/cua/main/libs/cua-driver/scripts/install.sh)\""diff --git a/libs/cua-driver/scripts/install.ps1 b/libs/cua-driver/scripts/install.ps1index 174aacaaa6..1378fef668 100644--- a/libs/cua-driver/scripts/install.ps1+++ b/libs/cua-driver/scripts/install.ps1@@ -5,11 +5,11 @@# required, no admin elevation.## Usage (one-liner — recommended):-# irm https://raw.githubusercontent.com/trycua/cua/main/libs/cua-driver-rs/scripts/install.ps1 | iex+# irm https://raw.githubusercontent.com/trycua/cua/main/libs/cua-driver/scripts/install.ps1 | iex## Pin a version:# $env:CUA_DRIVER_RS_VERSION = "0.2.0"-# irm https://raw.githubusercontent.com/trycua/cua/main/libs/cua-driver-rs/scripts/install.ps1 | iex+# irm https://raw.githubusercontent.com/trycua/cua/main/libs/cua-driver/scripts/install.ps1 | iex## Layout on disk (three tiers, two directory junctions):#diff --git a/libs/cua-driver/scripts/install.sh b/libs/cua-driver/scripts/install.shindex 68f3fda4fc..e2c9b5b267 100755--- a/libs/cua-driver/scripts/install.sh+++ b/libs/cua-driver/scripts/install.sh@@ -14,7 +14,7 @@# shell rc when ~/.local/bin is missing from PATH# --experimental-rust opt into the experimental cua-driver-rs (Rust port)# backend instead of the Swift binary. Delegates to-# libs/cua-driver-rs/scripts/install.sh — see that+# libs/cua-driver/scripts/_install-rust.sh — see that# script for backend-specific env vars. Installs to a# separate bundle (CuaDriverRs.app) so the Swift# binary is left untouched. Also accepted as@@ -37,11 +37,13 @@ APP_DEST="/Applications/$APP_NAME"BIN_DIR="${CUA_DRIVER_BIN_DIR:-$HOME/.local/bin}"NO_MODIFY_PATH="${CUA_DRIVER_NO_MODIFY_PATH:-0}"-# Rust-backend delegation target. Kept in sync with the canonical path on-# main; --experimental-rust below either execs the on-disk copy (when this-# script runs from a checked-out tree) or curls this URL and pipes it to-# bash (the `curl ... | bash` install path).-RUST_INSTALLER_URL="https://raw.githubusercontent.com/trycua/cua/main/libs/cua-driver-rs/scripts/install.sh"+# Rust-backend delegation target. The Rust install logic is a private+# helper script colocated with this one — _install-rust.sh — so that+# this directory holds the single user-facing install.sh per platform.+# `--experimental-rust` below either execs the on-disk helper (dev /+# checked-out-tree case) or curls this URL and pipes it to bash+# (`curl ... | bash` install case).+RUST_INSTALLER_URL="https://raw.githubusercontent.com/trycua/cua/main/libs/cua-driver/scripts/_install-rust.sh"# Lightweight flag parsing (avoid getopt; macOS getopt is GNU-incompatible).#@@ -108,7 +110,7 @@ fi# --- Optional delegation to the experimental Rust backend ---------------## If the user opted in with --experimental-rust / --backend=rust, hand the-# rest of argv to cua-driver-rs/scripts/install.sh and exit. The Swift+# rest of argv to _install-rust.sh and exit. The Swift# install path below is never touched in this case, so the Swift binary# (if present) is left exactly as-is — users can roll back by deleting# /Applications/CuaDriverRs.app and re-running this script without the flag.@@ -128,9 +130,19 @@ if [[ "$USE_RUST_BACKEND" == "1" ]]; thenLOCAL_RUST_INSTALLER=""if [[ -n "${BASH_SOURCE[0]:-}" && "${BASH_SOURCE[0]}" != "-" && -f "${BASH_SOURCE[0]}" ]]; thenSCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"- CANDIDATE="$SCRIPT_DIR/../../cua-driver-rs/scripts/install.sh"+ # New canonical location — colocated helper under cua-driver/scripts/.+ CANDIDATE="$SCRIPT_DIR/_install-rust.sh"if [[ -f "$CANDIDATE" ]]; thenLOCAL_RUST_INSTALLER="$CANDIDATE"+ else+ # Backward-compat: if someone is running this script from a+ # tree where the helper hasn't been moved yet (e.g. a+ # historical checkout being used with a freshly-pulled+ # install.sh), fall through to the cua-driver-rs location.+ CANDIDATE="$SCRIPT_DIR/../../cua-driver-rs/scripts/install.sh"+ if [[ -f "$CANDIDATE" ]]; then+ LOCAL_RUST_INSTALLER="$CANDIDATE"+ fififi