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.

Uninstall resets app permissions before removal; guide says switch on when listed (CUA-2282, CUA-2283) (#5937)

cua-agents[bot]96b1faef67ce
diff --git a/apps/cua-spaces-macos/README.md b/apps/cua-spaces-macos/README.md
index 8035a9cf77..cd3c40720c 100644
--- a/apps/cua-spaces-macos/README.md
+++ b/apps/cua-spaces-macos/README.md
@@ -419,7 +419,7 @@ and removing Local's setup removes only Local's. The names come from
Rebuilding is the same command. To remove it:
```sh
-scripts/uninstall-local.sh # asks first; --yes to skip, --with-lume-local to include lume-local
+scripts/uninstall-local.sh # asks first; --yes to skip, --with-lume-local to include lume-local; --keep-permissions keeps the macOS permissions (reset by default, before the app goes)
```
It unregisters the Local helper login item and removes the app, `cua-local`,
diff --git a/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Models/LoginItem.swift b/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Models/LoginItem.swift
index 8faf3462c9..e93421090a 100644
--- a/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Models/LoginItem.swift
+++ b/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Models/LoginItem.swift
@@ -193,9 +193,13 @@ public enum HelperService {
case "register":
do { try service.register() } catch { failure = error.localizedDescription }
case "unregister":
- // Not registered is already done.
+ // Not registered is already done. So is an item that ends up
+ // not registered or not found (a bundle moved or replaced since
+ // it registered), even when macOS said no on the way.
if service.status != .notRegistered {
- do { try service.unregister() } catch { failure = error.localizedDescription }
+ do { try service.unregister() } catch {
+ if status() != .notRegistered, status() != .notFound { failure = error.localizedDescription }
+ }
}
case "status": break
default:
diff --git a/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Models/PermissionGuide.swift b/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Models/PermissionGuide.swift
index 7d8851eda4..45dfbcb89f 100644
--- a/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Models/PermissionGuide.swift
+++ b/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Models/PermissionGuide.swift
@@ -51,11 +51,135 @@ public enum PermissionGuide {
private static var controller: PermissionFlowController?
+ // MARK: - Listed or not (CUA-2283)
+
+ /// What the guide tells the person to do in a pane's list.
+ enum Instruction: Equatable {
+ /// The app is not in the list yet: drag it in (PermissionFlow's panel).
+ case drag
+ /// The app is already in the list: only its switch needs turning on.
+ case switchOn
+ }
+
+ /// macOS has no public call that says whether an app has a row in a
+ /// privacy list, so the guide remembers it: the permission was seen
+ /// granted (a revoked grant keeps its row). An app dragged in but never
+ /// switched on is not noticed, and keeps the drag guide. An
+ /// uninstall that resets the permissions removes the app's preferences
+ /// with this note.
+ nonisolated(unsafe) static var listedStore: UserDefaults = .standard
+
+ nonisolated static func listedKey(_ pane: PermissionFlowPane) -> String { "permissionListed.\(pane.rawValue)" }
+
+ nonisolated static func isListed(_ pane: PermissionFlowPane) -> Bool {
+ listedStore.bool(forKey: listedKey(pane))
+ }
+
+ nonisolated static func markListed(_ pane: PermissionFlowPane, _ listed: Bool = true) {
+ listedStore.set(listed, forKey: listedKey(pane))
+ }
+
+ nonisolated static func instruction(for pane: PermissionFlowPane, listed: Bool) -> Instruction {
+ listed ? .switchOn : .drag
+ }
+
+ /// The line of the switch-on hint.
+ nonisolated static func switchOnText(appName: String) -> String {
+ "Switch on \(appName) in the list."
+ }
+
+ private static var hint: NSPanel?
+
+ private static func closeHint() {
+ hint?.close()
+ hint = nil
+ }
+
+ /// A small panel over System Settings for a pane whose list already has
+ /// this app: no dragging, just the switch. "Not in the list?" falls back
+ /// to the drag guide.
+ private static func showSwitchOnHint(for pane: PermissionFlowPane, url: String) {
+ closeHint()
+ let name = FileManager.default.displayName(atPath: Bundle.main.bundlePath)
+ let label = NSTextField(labelWithString: switchOnText(appName: name))
+ label.font = .systemFont(ofSize: 14)
+ let fallback = NSButton(title: "Not in the list?", target: nil, action: nil)
+ fallback.bezelStyle = .inline
+ let close = NSButton(image: NSImage(systemSymbolName: "xmark.circle.fill", accessibilityDescription: "Close") ?? NSImage(),
+ target: nil, action: nil)
+ close.isBordered = false
+ let row = NSStackView(views: [label, fallback, close])
+ row.spacing = 10
+ row.edgeInsets = NSEdgeInsets(top: 10, left: 14, bottom: 10, right: 12)
+ let box = NSVisualEffectView()
+ box.material = .hudWindow
+ box.state = .active
+ box.wantsLayer = true
+ box.layer?.cornerRadius = 12
+ row.translatesAutoresizingMaskIntoConstraints = false
+ box.addSubview(row)
+ NSLayoutConstraint.activate([
+ row.leadingAnchor.constraint(equalTo: box.leadingAnchor),
+ row.trailingAnchor.constraint(equalTo: box.trailingAnchor),
+ row.topAnchor.constraint(equalTo: box.topAnchor),
+ row.bottomAnchor.constraint(equalTo: box.bottomAnchor),
+ ])
+ let panel = NSPanel(contentRect: .zero, styleMask: [.borderless, .nonactivatingPanel], backing: .buffered, defer: false)
+ panel.isOpaque = false
+ panel.backgroundColor = .clear
+ panel.hasShadow = true
+ panel.level = .floating
+ panel.hidesOnDeactivate = false
+ panel.collectionBehavior = [.canJoinAllSpaces, .fullScreenAuxiliary]
+ panel.isReleasedWhenClosed = false
+ panel.contentView = box
+ let size = box.fittingSize
+ if let screen = NSScreen.main?.visibleFrame {
+ panel.setFrame(NSRect(x: screen.midX - size.width / 2, y: screen.maxY - size.height - 16,
+ width: size.width, height: size.height), display: true)
+ }
+ let actions = HintActions(
+ close: { closeHint() },
+ fallback: {
+ markListed(pane, false)
+ closeHint()
+ guide(url)
+ })
+ fallback.target = actions
+ fallback.action = #selector(HintActions.fallbackTapped)
+ close.target = actions
+ close.action = #selector(HintActions.closeTapped)
+ objc_setAssociatedObject(panel, &HintActions.key, actions, .OBJC_ASSOCIATION_RETAIN)
+ panel.orderFrontRegardless()
+ hint = panel
+ }
+
+ private final class HintActions: NSObject {
+ nonisolated(unsafe) static var key: UInt8 = 0
+ let close: () -> Void
+ let fallback: () -> Void
+ init(close: @escaping () -> Void, fallback: @escaping () -> Void) {
+ self.close = close
+ self.fallback = fallback
+ }
+ @objc func closeTapped() { close() }
+ @objc func fallbackTapped() { fallback() }
+ }
+
/// Guides `url`'s pane: false when the guide doesn't know it (open it
/// plainly then).
@discardableResult
public static func guide(_ url: String) -> Bool {
guard let pane = pane(for: url) else { return false }
+ closeHint()
+ // Already in the list: say "switch on", not "drag".
+ if instruction(for: pane, listed: isListed(pane)) == .switchOn, let u = URL(string: url) {
+ controller?.closePanel()
+ NSWorkspace.shared.open(u)
+ showSwitchOnHint(for: pane, url: url)
+ watch(pane)
+ return true
+ }
let app = Bundle.main.bundleURL
let flow = controller ?? PermissionFlowController(configuration: .init(requiredAppURLs: [app]))
controller = flow
@@ -156,9 +280,13 @@ public enum PermissionGuide {
while !Task.isCancelled, clock.now < deadline {
let now = await readGranted()
guard !Task.isCancelled else { return }
+ // A grant, even one revoked later, means the app has its row.
+ for p in now { markListed(p) }
if now.contains(pane) { granted(pane, others: now); return }
try? await Task.sleep(for: pollInterval)
}
+ // Gave up (a replaced or finished watch must not close a newer hint).
+ if !Task.isCancelled { closeHint() }
}
}
@@ -166,6 +294,7 @@ public enum PermissionGuide {
watching = nil
reopening?.cancel()
controller?.closePanel()
+ closeHint()
let followUp = {
switch next(after: pane, isGranted: others.contains) {
case .guide(let other):
diff --git a/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/PermissionGuideTests.swift b/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/PermissionGuideTests.swift
index 9cc88a92c4..3d33b30bd5 100644
--- a/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/PermissionGuideTests.swift
+++ b/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/PermissionGuideTests.swift
@@ -39,6 +39,26 @@ struct PermissionGuideTests {
}
}
+ @MainActor
+ @Test func saysSwitchOnWhenTheAppIsListedAndDragWhenItIsNot() {
+ let saved = PermissionGuide.listedStore
+ defer { PermissionGuide.listedStore = saved }
+ let suite = "PermissionGuideTests.\(UUID().uuidString)"
+ let store = UserDefaults(suiteName: suite)!
+ defer { store.removePersistentDomain(forName: suite) }
+ PermissionGuide.listedStore = store
+
+ #expect(!PermissionGuide.isListed(.accessibility))
+ #expect(PermissionGuide.instruction(for: .accessibility, listed: PermissionGuide.isListed(.accessibility)) == .drag)
+ PermissionGuide.markListed(.accessibility)
+ #expect(PermissionGuide.isListed(.accessibility))
+ #expect(!PermissionGuide.isListed(.screenRecording))
+ #expect(PermissionGuide.instruction(for: .accessibility, listed: PermissionGuide.isListed(.accessibility)) == .switchOn)
+ PermissionGuide.markListed(.accessibility, false)
+ #expect(PermissionGuide.instruction(for: .accessibility, listed: PermissionGuide.isListed(.accessibility)) == .drag)
+ #expect(PermissionGuide.switchOnText(appName: "Cua Spaces Local") == "Switch on Cua Spaces Local in the list.")
+ }
+
@Test func readsWhatAFreshProcessReports() {
#expect(PermissionGuide.parseGrants("screen-recording=1 accessibility=0\n") == [.screenRecording])
#expect(PermissionGuide.parseGrants("screen-recording=0 accessibility=1") == [.accessibility])
diff --git a/apps/cua-spaces-macos/scripts/_local-common.sh b/apps/cua-spaces-macos/scripts/_local-common.sh
index 94f44ba810..6b501bc11c 100644
--- a/apps/cua-spaces-macos/scripts/_local-common.sh
+++ b/apps/cua-spaces-macos/scripts/_local-common.sh
@@ -158,7 +158,11 @@ quit_local_app() {
retire_local_app() {
local app="$1"
if [ -x "$app/Contents/MacOS/CuaSpacesMac" ]; then
+ # A second try, then the state decides: a login item that is not
+ # registered or not found is gone, whatever the exit status said.
CUA_CHANNEL=local "$app/Contents/MacOS/CuaSpacesMac" --service-helper unregister >/dev/null 2>&1 \
+ || CUA_CHANNEL=local "$app/Contents/MacOS/CuaSpacesMac" --service-helper unregister >/dev/null 2>&1 \
+ || ! local_helper_registered "$app" \
|| warn "the app could not unregister its helper; remove $LOCAL_APP_DIR_NAME from System Settings > Login Items if it stays."
fi
quit_local_app "$app"
@@ -192,6 +196,42 @@ local_helper_enabled() {
CUA_CHANNEL=local "$app/Contents/MacOS/CuaSpacesMac" --service-helper status 2>/dev/null | grep -q '"status":"enabled"'
}
+# Succeeds when the helper login item of the Local app at `app` is still
+# registered, or waits for approval in System Settings (`--service-helper
+# status`). Not registered, not found and no answer are not.
+local_helper_registered() {
+ local app="$1"
+ [ -x "$app/Contents/MacOS/CuaSpacesMac" ] || return 1
+ CUA_CHANNEL=local "$app/Contents/MacOS/CuaSpacesMac" --service-helper status 2>/dev/null \
+ | grep -Eq '"status":"(enabled|requires-approval)"'
+}
+
+# Clears every macOS privacy permission (Screen Recording, Accessibility,
+# Automation and the rest: `tccutil reset All`) the Local bundle id holds, for
+# the Local app at `app`. `tccutil` resolves a bundle id through LaunchServices
+# and fails with "No such bundle identifier" once the app is gone, so this runs
+# while the app is still installed, after it is stopped. `id` is the Local id
+# (or the old Local id). Best effort; Stable's id is never passed.
+reset_local_permissions() {
+ local app="$1" id="$2"
+ case "$id" in
+ "$LOCAL_BUNDLE_ID"|"$LOCAL_LEGACY_BUNDLE_ID") ;;
+ *) return 0 ;;
+ esac
+ if ! command -v tccutil >/dev/null 2>&1; then
+ warn "tccutil is missing: remove $LOCAL_APP_DIR_NAME from the Privacy & Security lists in System Settings yourself."
+ return 0
+ fi
+ if [ -x "$LSREGISTER" ] && [ -d "$app" ]; then
+ "$LSREGISTER" -f "$app" >/dev/null 2>&1 || true
+ fi
+ if tccutil reset All "$id" >/dev/null 2>&1; then
+ log "reset the macOS permissions of $id (Screen Recording, Accessibility and the rest)"
+ else
+ warn "could not reset the permissions of $id; run: tccutil reset All $id"
+ fi
+}
+
# Registers the helper login item of the Local app at `app` (the app does it
# itself: only a bundle's own code may), best effort. `what` names the app in
# the warning.
diff --git a/apps/cua-spaces-macos/scripts/tests/install-local-test.sh b/apps/cua-spaces-macos/scripts/tests/install-local-test.sh
index 98e54a6044..4945cc4492 100755
--- a/apps/cua-spaces-macos/scripts/tests/install-local-test.sh
+++ b/apps/cua-spaces-macos/scripts/tests/install-local-test.sh
@@ -105,6 +105,8 @@ int main(int argc, char **argv) {
fprintf(f, " [CUA_CHANNEL=%s]\n", channel ? channel : "");
fclose(f);
}
+ // STUB_UNREGISTER_FAIL=1: `--service-helper unregister` exits 1.
+ if (argc >= 3 && strcmp(argv[2], "unregister") == 0 && getenv("STUB_UNREGISTER_FAIL")) return 1;
return 0;
}
EOF
@@ -249,7 +251,10 @@ EOF
# arguments to shim.log.
write_shim() { printf '#!/bin/bash\n%s\n' "$2" > "$SHIMS/$1"; chmod +x "$SHIMS/$1"; }
write_shim launchctl 'echo "launchctl $*" >> "$SHIM_LOG"'
-write_shim tccutil 'echo "tccutil $*" >> "$SHIM_LOG"'
+# tccutil, like the real one, can only resolve a bundle id while its app is
+# installed: the second log says whether the Local app was still there.
+write_shim tccutil 'echo "tccutil $*" >> "$SHIM_LOG"
+echo "$* app=$([ -d "$HOME/Applications/Cua Spaces Local.app" ] && echo present || echo gone)" >> "$SHIM_LOG.tcc"'
write_shim open 'echo "open $*" >> "$SHIM_LOG"'
write_shim lsregister 'echo "lsregister $*" >> "$SHIM_LOG"'
# security: a Keychain with one item per service until it is deleted; or the
@@ -1275,19 +1280,23 @@ echo 'state' > "$FAKE_HOME/Library/Saved Application State/com.trycua.spaces.mac
echo 'mine' > "$FAKE_HOME/Cua Volume Local/keep.txt"
write_local_cli
BEFORE_UNINSTALL="$(snap_all)"
-: > "$SHIM_LOG"; : > "$STUB_LOG"
+: > "$SHIM_LOG"; : > "$STUB_LOG"; : > "$SHIM_LOG.tcc"
STDIN_FILE="$WORK/answer-n"; echo n > "$STDIN_FILE"
uninstall
check "answering n removes nothing" '[ "$RC" = 0 ] && [ "$(snap_all)" = "$BEFORE_UNINSTALL" ] && printf "%s" "$OUT" | grep >/dev/null cancelled'
STDIN_FILE=/dev/null
uninstall
-check "no answer (no terminal) removes nothing" '[ "$(snap_all)" = "$BEFORE_UNINSTALL" ]'
+check "no answer (no terminal) removes nothing" '[ "$(snap_all)" = "$BEFORE_UNINSTALL" ] && [ ! -s "$SHIM_LOG.tcc" ]'
STDIN_FILE="$WORK/answer-y"; echo y > "$STDIN_FILE"
uninstall
check "answering y removes Local (status $RC)" '[ "$RC" = 0 ] && [ ! -e "$LOCAL_APP" ] && [ ! -e "$LOCAL_CLI" ] && [ ! -L "$LOCAL_CLI" ]'
STDIN_FILE=/dev/null
+check "every Local permission was reset in one call, for the Local bundle id only, while the app was still installed" \
+ '[ "$(cat "$SHIM_LOG.tcc")" = "reset All com.trycua.spaces.macos.local app=present" ] && [ "$(grep -c "^tccutil" "$SHIM_LOG")" = 1 ]'
+check "the plan said the permissions are reset, and the closing line no longer says they are kept" \
+ 'printf "%s" "$OUT" | grep >/dev/null "permissions: reset" && ! printf "%s" "$OUT" | grep >/dev/null "and the permissions macOS granted"'
check "the Local home and its app support folder are gone" '[ ! -e "$FAKE_HOME/.cua-local" ] && [ ! -e "$FAKE_HOME/Library/Application Support/com.trycua.spaces.macos.local" ]'
check "the Local bundle id's preferences, caches, web view data, cookies and window state are gone" \
'[ ! -e "$FAKE_HOME/Library/Preferences/com.trycua.spaces.macos.local.plist" ] && [ ! -e "$FAKE_HOME/Library/Caches/com.trycua.spaces.macos.local" ] && [ ! -e "$FAKE_HOME/Library/HTTPStorages/com.trycua.spaces.macos.local" ] && [ ! -e "$FAKE_HOME/Library/WebKit/com.trycua.spaces.macos.local" ] && [ ! -e "$FAKE_HOME/Library/Cookies/com.trycua.spaces.macos.local.binarycookies" ] && [ ! -e "$FAKE_HOME/Library/Saved Application State/com.trycua.spaces.macos.local.savedState" ]'
@@ -1308,6 +1317,28 @@ check "only the Local Keychain services were deleted (both of them)" \
check "the Local volume folder is kept" '[ "$(cat "$FAKE_HOME/Cua Volume Local/keep.txt")" = mine ]'
check "Stable files are byte-identical after uninstall" '[ "$(snap_stable)" = "$STABLE_BEFORE" ]'
+echo "== uninstall --keep-permissions, and a login item that will not unregister =="
+reset_fixture
+install
+: > "$SHIM_LOG"; : > "$SHIM_LOG.tcc"
+uninstall --yes --keep-permissions
+check "--keep-permissions removes Local and resets nothing (status $RC)" \
+ '[ "$RC" = 0 ] && [ ! -e "$LOCAL_APP" ] && [ ! -s "$SHIM_LOG.tcc" ] && ! grep >/dev/null "^tccutil" "$SHIM_LOG"'
+check "and it says the permissions are kept" \
+ 'printf "%s" "$OUT" | grep >/dev/null "permissions: kept" && printf "%s" "$OUT" | grep >/dev/null "and the permissions macOS granted"'
+reset_fixture
+install
+: > "$SHIM_LOG.tcc"; : > "$STUB_LOG"
+run env STUB_UNREGISTER_FAIL=1 STUB_HELPER_STATUS=not-registered "$FAKE_SCRIPTS/uninstall-local.sh" --yes
+check "an unregister that exits 1 is retried once, and a login item that is not registered raises no warning (status $RC)" \
+ '[ "$RC" = 0 ] && [ "$(grep -c -- "--service-helper unregister" "$STUB_LOG")" = 2 ] && ! printf "%s" "$OUT" | grep >/dev/null "could not unregister its helper"'
+reset_fixture
+install
+: > "$STUB_LOG"
+run env STUB_UNREGISTER_FAIL=1 STUB_HELPER_STATUS=enabled "$FAKE_SCRIPTS/uninstall-local.sh" --yes
+check "a login item that is still enabled after the retry is reported, and the uninstall goes on" \
+ '[ "$RC" = 0 ] && [ ! -e "$LOCAL_APP" ] && printf "%s" "$OUT" | grep >/dev/null "could not unregister its helper"'
+
echo "== uninstall and the old Local id =="
reset_fixture
make_legacy_local
@@ -1333,7 +1364,7 @@ uninstall --yes
check "uninstall removes the leftovers of both ids when no app is installed (status $RC)" \
'[ "$RC" = 0 ] && legacy_data_gone && [ ! -e "$FAKE_HOME/Library/Application Support/com.trycua.spaces.macos.local" ] && [ ! -e "$FAKE_HOME/Library/Caches/com.trycua.spaces.macos.local" ]'
check "and Stable files, whose names the new Local id extends, are byte-identical" '[ "$(snap_stable)" = "$STABLE_BEFORE" ]'
-check "uninstall never resets permission rows (macOS keeps them for a reinstall)" '! grep >/dev/null "^tccutil" "$SHIM_LOG"'
+check "with no app installed no permission rows are reset (tccutil cannot resolve a bundle id whose app is gone)" '! grep >/dev/null "^tccutil" "$SHIM_LOG"'
echo "== uninstall takes this Mac off the relay, safely =="
# A stray environment of the released Cua Spaces in the caller's shell: its
diff --git a/apps/cua-spaces-macos/scripts/uninstall-local.sh b/apps/cua-spaces-macos/scripts/uninstall-local.sh
index 431e008c4f..f087b29f25 100755
--- a/apps/cua-spaces-macos/scripts/uninstall-local.sh
+++ b/apps/cua-spaces-macos/scripts/uninstall-local.sh
@@ -7,9 +7,12 @@
# ~/.lume and their launchd jobs and Keychain items have other names and are
# never reached.
#
-# scripts/uninstall-local.sh [--yes] [--with-lume-local] [--prefix DIR]
+# scripts/uninstall-local.sh [--yes] [--keep-permissions] [--with-lume-local] [--prefix DIR]
#
# --yes, -y do not ask first
+# --keep-permissions keep the permissions macOS granted the app (Screen
+# Recording, Accessibility and the rest); without it
+# they are reset, before the app goes
# --with-lume-local also remove lume-local (without it, it asks, and with
# --yes it stays); its VMs in ~/.lume-local go with it
# --prefix DIR where install-local.sh put the app and `cua-local`
@@ -24,6 +27,9 @@
# the CLI and ~/.cua-local, which records what Local wrote, go; the released
# app's entries and `cua-driver` stay
# - the Local helper login item (unregistered) and the Local host runner job
+# - the permissions macOS granted the Local bundle id (`tccutil reset All`,
+# run while the app is still installed: it cannot resolve an app that is
+# gone), unless --keep-permissions
# - ~/Applications/Cua Spaces Local.app
# - ~/.local/bin/cua-local
# - ~/.cua-local (the Local sign-in, host and Spaces state)
@@ -35,8 +41,8 @@
# path and its ~/Library files
# - the Local Keychain items (ai.cua.session.local, ai.cua.session.local.staging)
# - optionally lume-local (libs/lume/scripts/uninstall-local.sh)
-# It keeps the Cua Volume Local folder and the permissions macOS granted the
-# app. It refuses, changing nothing, when the app at the Local path is not a
+# It keeps the Cua Volume Local folder (and, with --keep-permissions, the
+# permissions macOS granted the app). It refuses, changing nothing, when the app at the Local path is not a
# Cua Spaces Local bundle.
set -euo pipefail
@@ -52,6 +58,7 @@ die() { err "$*"; exit 1; }
YES=0
PREFIX=""
WITH_LUME_LOCAL=0
+KEEP_PERMISSIONS=0
usage() { sed -n '/^# Removes Cua Spaces Local/,/^# Cua Spaces Local bundle\./p' "$0" | sed 's/^# \{0,1\}//'; }
@@ -59,6 +66,7 @@ while [ "$#" -gt 0 ]; do
case "$1" in
--yes|-y) YES=1 ;;
--with-lume-local) WITH_LUME_LOCAL=1 ;;
+ --keep-permissions) KEEP_PERMISSIONS=1 ;;
--prefix)
[ "$#" -ge 2 ] || die "--prefix needs a directory"
PREFIX="$2"
@@ -125,6 +133,11 @@ echo " CLI: $CLI_LINK"
echo " state: $LOCAL_HOME and $LOCAL_APP_SUPPORT"
echo " macOS leftovers: the $LOCAL_BUNDLE_ID preferences, caches, web view data and window state in ~/Library"
echo " (and those of the old id $LOCAL_LEGACY_BUNDLE_ID, if any)"
+if [ "$KEEP_PERMISSIONS" = 1 ]; then
+ echo " permissions: kept (--keep-permissions)"
+else
+ echo " permissions: reset (Screen Recording, Accessibility and the rest for $LOCAL_BUNDLE_ID)"
+fi
echo " Keychain items: ${LOCAL_KEYCHAIN_SERVICES[*]}"
echo " relay: this Mac's entry, if Local is signed in"
echo " coding agents: Local's MCP server ($LOCAL_CLI_NAME) and its *-local skills; the released app's entries stay"
@@ -278,6 +291,15 @@ if [ -x "$APP_DEST/Contents/MacOS/CuaSpacesMac" ]; then
log "unregistering the helper login item"
fi
retire_local_app "$APP_DEST"
+# Permissions next, while the app is still installed: tccutil resolves the
+# bundle id through the app and fails once it is gone.
+if [ "$KEEP_PERMISSIONS" != 1 ]; then
+ if [ -d "$APP_DEST" ] && [ -f "$APP_DEST/Contents/Info.plist" ]; then
+ reset_local_permissions "$APP_DEST" "$(bundle_id_of "$APP_DEST")"
+ else
+ log "no app is installed, so macOS cannot reset its permissions: install Local again and rerun this to clear them"
+ fi
+fi
# The plain runner (`cua host setup` without the app) has its own Local label.
launchctl bootout "$GUI_DOMAIN/$LOCAL_HOST_LABEL" >/dev/null 2>&1 || true
if [ -f "$HOST_JOB_PLIST" ]; then
@@ -377,4 +399,8 @@ fi
echo ""
ok "Cua Spaces Local was removed; the released Cua Spaces was left untouched."
-echo "Kept: ~/$LOCAL_VOLUME_NAME (your files) and the permissions macOS granted $LOCAL_BUNDLE_ID."
+if [ "$KEEP_PERMISSIONS" = 1 ]; then
+ echo "Kept: ~/$LOCAL_VOLUME_NAME (your files) and the permissions macOS granted $LOCAL_BUNDLE_ID."
+else
+ echo "Kept: ~/$LOCAL_VOLUME_NAME (your files)."
+fi
diff --git a/scripts/install/README.md b/scripts/install/README.md
index 96c59e7cfa..cc2de4718f 100644
--- a/scripts/install/README.md
+++ b/scripts/install/README.md
@@ -103,6 +103,7 @@ It lists what it found, asks once (`--yes` skips the question; without a termina
| (default) | (default) | Removes the app, the CLI, the host service, Cua Spaces' agent skills and MCP entry, launch at login, your sign-in and Cua's settings and caches. Keeps Spaces and their data, and Cua Driver's and other tools' entries in your agents |
| `--keep-data` | `-KeepData` | Keeps `~/.cua` (settings, the Spaces registry, the Cua Volume cache, the device key) and the app's settings. Still removes programs, services, integrations and the sign-in |
| `--delete-spaces` | `-DeleteSpaces` | Also deletes the Spaces on this computer and their data: Space disks, the local Cua Volume files, the Keyvault. Running Spaces are listed and stopped first; asks you to type `delete` (not with `--yes`). Cannot be combined with `--keep-data` |
+| `--keep-permissions` | | Keeps the macOS permissions granted to the Cua Spaces app (macOS only; by default they are reset before the app is removed) |
| `--all` | `-All` | Also runs the Cua Driver uninstaller (`cua.ai/driver/uninstall.sh` / `.ps1`), takes Cua Driver's skill and MCP server out of your agents (`cua agents remove --include-cua-driver`) and, on macOS, runs Lume's uninstaller (`cua.ai/lume/uninstall.sh`). Lume keeps your VMs unless `--delete-spaces` is given too |
| `--prefix DIR` | `-Prefix DIR` | Also removes what `install.sh --prefix DIR` put under `DIR/bin` and `DIR/Applications` |
| `--no-modify-path` | `-NoModifyPath` | Never edits your shell profile (user PATH on Windows) |
@@ -116,7 +117,7 @@ What it removes, in this order (each step is best effort and bounded, so one fai
3. `cua agents remove --agents all --yes`: the Cua Spaces skills and the `cua` MCP server (`cua-local` for Local) in your agents. The `cua-driver` skill and MCP server (`cua-driver-local` for Local) and every other tool's entries stay, unless `--all` adds `--include-cua-driver`. A `cua` older than the version with `--include-cua-driver` and `--dry-run` would also strip Cua Driver's entries, so the script skips this step, says what stays in the agents and how to remove it (install the latest `cua`, run `cua agents remove`), removes the rest and still exits 0; a dry run says so too. The record `cua agents remove` works from (`~/.cua/agent-setup.json`) stays unless `--delete-spaces`.
4. `cua daemon stop`, and the Cua Volume mount (`~/Cua Volume` on macOS, `~/cua-volume` on Linux) is unmounted before any file is deleted.
5. Signs out (`cua auth logout`, which revokes the session) and removes a leftover `credentials.json`.
-6. The app: `Cua Spaces.app` in `/Applications` and `~/Applications` (macOS, only when its bundle id is Cua's); the `cua-spaces` package with apt (Linux .deb), the AppImage, its desktop entry and autostart entry; on Windows the app's own uninstaller (silent), which also removes launch at login. On macOS the app registered itself as a login item, which a script cannot unregister: with the app gone it has nothing to start, and System Settings, Login Items shows how to remove a leftover row.
+6. The app: `Cua Spaces.app` in `/Applications` and `~/Applications` (macOS, only when its bundle id is Cua's); the `cua-spaces` package with apt (Linux .deb), the AppImage, its desktop entry and autostart entry; on Windows the app's own uninstaller (silent), which also removes launch at login. On macOS the app's login item is unregistered through the app itself before the app is removed, and the permissions macOS granted the app (Screen Recording, Accessibility and the rest) are reset with `tccutil reset All com.trycua.spaces.macos` while the app is still installed, since `tccutil` cannot resolve an app that is gone; `--keep-permissions` skips the reset. Cua Driver's permissions are never touched.
7. The CLI: `~/.local/bin/cua`, `/usr/local/bin/cua` (and `DIR/bin/cua`), only when it is the Cua CLI (`cua --version` says `cua X.Y.Z`, or a link into the app). A `cua` from pip, npm or Homebrew is left alone and named. On Windows, `%LOCALAPPDATA%\Programs\cua\bin\cua.exe` and its user PATH entry.
8. The `# Added by the cua installer` PATH line in your shell profile (kept while `cua-driver` or `lume` still lives in the same folder).
9. Credentials: the macOS Keychain items of service `run.cua.ai` and `staging.run.cua.ai` (account `cua-cli` for the session; the device key and agent keys too unless `--keep-data`; this includes the legacy `run.cua.ai` label), and the Windows Credential Manager entries `cua-cli.*.run.cua.ai`. With `--delete-spaces` also the Keyvault master key (`Cua Keyvault`).
diff --git a/scripts/install/tests/test_uninstall.py b/scripts/install/tests/test_uninstall.py
index d58f343f94..3406738af1 100644
--- a/scripts/install/tests/test_uninstall.py
+++ b/scripts/install/tests/test_uninstall.py
@@ -373,9 +373,63 @@ class UninstallMacTest(unittest.TestCase):
self.assertIn("[dry-run] cua agents remove --agents all: skipped, this cua is older than", result.stdout)
self.assertIn("cua host remove --force --uninstalling", result.stdout)
- def test_the_app_helper_goes_but_its_permissions_stay(self):
+ @staticmethod
+ def app_id_defaults(box, app_id="com.trycua.spaces.macos"):
+ """`defaults read <app>/Contents/Info CFBundleIdentifier` answers `app_id`."""
+ box.put("Applications/Cua Spaces.app/Contents/Info.plist", "plist\n")
+ write_executable(box.bin / "defaults", f"#!/bin/sh\nprintf 'defaults: %s\\n' \"$*\" >>\"$FAKE_CALLS\"\n"
+ f"case \"$*\" in *CFBundleIdentifier*) echo {app_id} ;; esac\nexit 0\n")
+
+ def test_keep_permissions_leaves_them_alone(self):
box = self.box()
installed_mac(box)
+ self.app_id_defaults(box)
+ result = box.run("--yes", "--keep-permissions", "--prefix", str(box.home))
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ self.assertEqual(box.index("tccutil"), -1)
+ self.assertFalse(box.exists("Applications/Cua Spaces.app"))
+ dry = box.run("--dry-run", "--keep-permissions")
+ self.assertNotIn("tccutil", dry.stdout)
+
+ def test_permissions_are_reset_before_the_app_is_removed(self):
+ box = self.box()
+ installed_mac(box)
+ self.app_id_defaults(box)
+ # The fake tccutil, like the real one, fails once the app is gone.
+ write_executable(box.bin / "tccutil",
+ "#!/bin/sh\nprintf 'tccutil: %s\\n' \"$*\" >>\"$FAKE_CALLS\"\n"
+ f"[ -d {shlex.quote(str(box.home / 'Applications/Cua Spaces.app'))} ] || exit 1\n")
+ result = box.run("--yes", "--prefix", str(box.home))
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ self.assertGreaterEqual(box.index("tccutil: reset All com.trycua.spaces.macos"), 0)
+ self.assertNotIn("could not reset the permissions", result.stderr)
+ self.assertFalse(box.exists("Applications/Cua Spaces.app"))
+
+ def test_another_apps_bundle_id_is_never_reset(self):
+ box = self.box()
+ installed_mac(box)
+ self.app_id_defaults(box, "com.trycua.driver")
+ result = box.run("--yes", "--prefix", str(box.home))
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ self.assertEqual(box.index("tccutil"), -1)
+
+ def test_a_login_item_that_stays_is_reported(self):
+ box = self.box()
+ installed_mac(box)
+ box.put("Applications/Cua Spaces.app/Contents/Library/LaunchAgents/com.trycua.spaces.helper.plist", "plist\n")
+ write_executable(box.home / "Applications/Cua Spaces.app/Contents/MacOS/CuaSpacesMac",
+ "#!/bin/sh\nprintf 'app: %s\\n' \"$*\" >>\"$FAKE_CALLS\"\n"
+ "case \"$2\" in unregister) exit 1 ;; status) echo '{\"status\":\"enabled\"}' ;; esac\n")
+ result = box.run("--yes", "--prefix", str(box.home))
+ self.assertIn("could not unregister the Cua Spaces login item", result.stderr)
+ self.assertIn("still registered", result.stdout)
+ # Tried twice before giving up.
+ self.assertEqual(len([c for c in box.call_log() if c == "app: --service-helper unregister"]), 2)
+
+ def test_the_app_helper_goes_and_its_permissions_are_reset_first(self):
+ box = self.box()
+ installed_mac(box)
+ self.app_id_defaults(box)
# Cua Spaces 0.10+: the host service is the app's login item.
box.put("Applications/Cua Spaces.app/Contents/Library/LaunchAgents/com.trycua.spaces.helper.plist", "plist\n")
write_executable(box.home / "Applications/Cua Spaces.app/Contents/MacOS/CuaSpacesMac",
@@ -384,7 +438,7 @@ class UninstallMacTest(unittest.TestCase):
dry = box.run("--dry-run")
self.assertEqual(dry.returncode, 0, dry.stdout + dry.stderr)
self.assertIn("--service-helper unregister", dry.stdout)
- self.assertNotIn("tccutil", dry.stdout)
+ self.assertIn("[dry-run] tccutil reset All com.trycua.spaces.macos", dry.stdout)
self.assertEqual(box.index("tccutil"), -1)
self.assertTrue(box.exists(".cua/helper/service.json"))
result = box.run("--yes", "--prefix", str(box.home))
@@ -392,7 +446,10 @@ class UninstallMacTest(unittest.TestCase):
# Unregistered by the app before the app goes, then stopped.
self.assertGreaterEqual(box.index("app: --service-helper unregister"), 0)
self.assertGreaterEqual(box.index("launchctl: bootout gui/1000/com.trycua.spaces.helper"), 0)
- self.assertEqual(box.index("tccutil"), -1)
+ # Permissions of the app's own id only, reset while the app is installed.
+ self.assertGreaterEqual(box.index("tccutil: reset All com.trycua.spaces.macos"), 0)
+ self.assertEqual([c for c in box.call_log() if c.startswith("tccutil")],
+ ["tccutil: reset All com.trycua.spaces.macos"])
self.assertIn("minus button", result.stdout)
for gone in (".cua/helper", "Applications/Cua Spaces.app",
"Library/LaunchAgents/com.trycua.spacesd.host.plist", ".cua/host/bin/cua-spacesd"):
@@ -642,8 +699,11 @@ class OtherToolsTest(unittest.TestCase):
self.assertEqual([call for call in box.call_log() if call.startswith("tccutil")], [])
for name in ("uninstall.sh", "uninstall.ps1"):
script = (Path(__file__).resolve().parent.parent / name).read_text()
- self.assertNotIn("tccutil", script, name)
self.assertNotIn("reset-permissions", script, name)
+ # Only the Cua Spaces app's own id is ever reset, never the driver's.
+ for line in script.splitlines():
+ if "tccutil" in line and "has tccutil" not in line and not line.lstrip().startswith("#"):
+ self.assertTrue("$app_id" in line or "spaces.macos" in line, line)
def test_on_linux_lume_is_skipped_and_the_driver_runs_even_with_nothing_else_installed(self):
box = Sandbox(tempfile.mkdtemp(dir=self.tmp.name), "Linux")
diff --git a/scripts/install/uninstall.sh b/scripts/install/uninstall.sh
index 69ed659acf..05d7d4e3d7 100755
--- a/scripts/install/uninstall.sh
+++ b/scripts/install/uninstall.sh
@@ -33,6 +33,11 @@ Options:
(Space disks, the local Cua Volume files, the Keyvault).
Running Spaces are listed and stopped first. Cannot be
undone; asks you to type "delete" unless --yes is given
+ --keep-permissions keep the macOS permissions (Screen Recording,
+ Accessibility, ...) granted to the Cua Spaces app; by
+ default they are reset while the app is still installed
+ (macOS cannot reset them once it is gone). Cua Driver's
+ permissions are never touched
--all also run the Cua Driver and Lume uninstallers, and remove
Cua Driver's skill and MCP server from your agents
(Lume keeps your VMs unless --delete-spaces is given too)
@@ -65,6 +70,7 @@ DISPOSABLE="cache cache.json cua.sock keyvault.sock x.sock daemon.json daemon.st
SESSION_FILES="credentials.json spaces-session.json spaces-credentials.json"
keep_data=0
+keep_permissions=0
delete_spaces=0
all_tools=0
prefix=""
@@ -97,6 +103,7 @@ parse_args() {
while [ $# -gt 0 ]; do
case "$1" in
--keep-data) keep_data=1 ;;
+ --keep-permissions) keep_permissions=1 ;;
--delete-spaces) delete_spaces=1 ;;
--all) all_tools=1 ;;
--prefix)
@@ -609,7 +616,15 @@ EOF
if [ "$dry_run" = 1 ]; then
say "[dry-run] $app/Contents/MacOS/CuaSpacesMac --service-helper unregister"
else
- bounded 30 "$app/Contents/MacOS/CuaSpacesMac" --service-helper unregister >/dev/null 2>&1 || true
+ # A second try, then the state decides: not registered or not
+ # found is gone, whatever the exit status said.
+ bounded 30 "$app/Contents/MacOS/CuaSpacesMac" --service-helper unregister >/dev/null 2>&1 ||
+ bounded 30 "$app/Contents/MacOS/CuaSpacesMac" --service-helper unregister >/dev/null 2>&1 || true
+ if bounded 30 "$app/Contents/MacOS/CuaSpacesMac" --service-helper status 2>/dev/null |
+ grep -Eq '"status":"(enabled|requires-approval)"'; then
+ helper_left=1
+ warn "could not unregister the Cua Spaces login item; switch it off in System Settings, Login Items"
+ fi
fi
done <<EOF
$(app_candidates)
@@ -620,8 +635,8 @@ EOF
launchctl bootout "gui/$(id -u)/com.trycua.spaces.helper" >/dev/null 2>&1 || true
fi
rm_path "$HOME/.cua/helper"
- # The privacy permissions macOS keeps for the app stay: an uninstall
- # never revokes them (see the driver uninstaller, 18 Oct 2026).
+ # The app's privacy permissions are reset in remove_app, while the
+ # app is still installed (--keep-permissions skips that).
if [ "$old_agent" = 1 ]; then
info "System Settings may still list \"cua-spacesd\" under Privacy & Security (Screen Recording, Accessibility); select it and click the minus button to remove it"
fi
@@ -733,7 +748,7 @@ EOF
# daemon unmounts it when it stops. Make sure, and never delete files while it
# is mounted.
volume_mounted=0
-app_removed=0
+helper_left=0
unmount_volume() {
case "$os" in
darwin) mount_point="$HOME/Cua Volume" ;;
@@ -785,6 +800,31 @@ $(cua_homes)
EOF
}
+# reset_app_permissions APP: clears every macOS privacy permission (Screen
+# Recording, Accessibility, Automation, ...) held by the Cua Spaces app's own
+# bundle id, unless --keep-permissions. `tccutil` resolves a bundle id through
+# LaunchServices and fails with "No such bundle identifier" once the app is
+# gone, so this runs before the app is removed. Only the app's id is named:
+# Cua Driver's permissions are never touched. Best effort.
+reset_app_permissions() {
+ [ "$keep_permissions" = 0 ] || return 0
+ has tccutil || return 0
+ app_id=""
+ if has defaults && [ -f "$1/Contents/Info.plist" ]; then
+ app_id="$(defaults read "$1/Contents/Info" CFBundleIdentifier 2>/dev/null || true)"
+ fi
+ [ "$app_id" = com.trycua.spaces.macos ] || return 0
+ if [ "$dry_run" = 1 ]; then
+ say "[dry-run] tccutil reset All $app_id"
+ return 0
+ fi
+ if bounded 20 tccutil reset All "$app_id" >/dev/null 2>&1; then
+ info "reset the macOS permissions of Cua Spaces (--keep-permissions keeps them)"
+ else
+ warn "could not reset the permissions of $app_id; run: tccutil reset All $app_id"
+ fi
+}
+
# remove_app: the Cua Spaces app and what it put outside its own folder.
remove_app() {
case "$os" in
@@ -792,8 +832,8 @@ remove_app() {
while IFS= read -r app; do
[ -n "$app" ] || continue
if is_cua_app "$app"; then
+ reset_app_permissions "$app"
rm_path "$app"
- if [ "$dry_run" = 0 ] && [ ! -e "$app" ]; then app_removed=1; fi
else
info "leaving $app (not the Cua Spaces app)"
fi
@@ -1152,6 +1192,13 @@ confirm_plan() {
if [ "$all_tools" = 0 ]; then
say "Cua Driver's skill and MCP server in your agents, and other tools' entries, stay."
fi
+ if [ "$os" = darwin ]; then
+ if [ "$keep_permissions" = 1 ]; then
+ say "It keeps the macOS permissions granted to Cua Spaces (--keep-permissions)."
+ else
+ say "It resets the macOS permissions granted to Cua Spaces (--keep-permissions keeps them)."
+ fi
+ fi
if [ "$keep_data" = 1 ]; then
say "It keeps $cua_home and the Cua Volume cache (--keep-data)."
elif [ "$delete_spaces" = 1 ]; then
@@ -1229,8 +1276,8 @@ main() {
if [ "$all_tools" = 0 ] && { has cua-driver || [ -e "$HOME/.local/bin/cua-driver" ]; }; then
info "Cua Driver is separate and was kept; run this with --all to remove it too"
fi
- if [ "$app_removed" = 1 ]; then
- info "the app registered itself as a login item, which a script cannot unregister; if Cua Spaces still shows in System Settings, Login Items, switch it off there"
+ if [ "$helper_left" = 1 ]; then
+ info "the Cua Spaces login item is still registered; switch it off in System Settings, Login Items"
fi
if [ "$failed" = 1 ]; then
info "finished, but some steps need your attention (see the warnings above)"