From 30e7756d29cdc9769226c1e7aa6c68c847b2e53a Mon Sep 17 00:00:00 2001 From: Contributor Date: Tue, 19 May 2026 10:28:54 +0800 Subject: [PATCH 1/2] fix(cua-driver-rs): warn + force prompt:false for check_permissions in CLI mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #1561. When cua-driver check_permissions is called from a shell or IDE terminal without a running daemon, macOS attributes the calling process to the parent application (Terminal.app, VS Code, Cursor, etc.) rather than to CuaDriver.app. AXIsProcessTrusted() therefore reflects the parent's Accessibility grant, not CuaDriver.app's — so results can be stale or misleading after tccutil reset Accessibility com.trycua.driver. This is the same bug that exists in the Swift binary; Swift's CallCommand.swift already handles it (lines 148-171). This commit ports that fix to the Rust CLI. Changes: - cli.rs: when no daemon is listening and tool == check_permissions, emit a stderr warning and force prompt:false (same logic as Swift). Prevents a TCC dialog being attributed to the wrong bundle identity. - check_permissions.rs: add the caveat to the tool description so MCP clients and cua-driver describe output surface the limitation. - status.rs: document the AXIsProcessTrusted() attribution caveat in the accessibility_granted() doc comment. The fix is purely additive — no behaviour change when the daemon is running (requests are forwarded through the Unix socket and run inside CuaDriver.app where attribution is correct). --- .../crates/cua-driver/src/cli.rs | 32 +++++++++++++++++++ .../platform-macos/src/permissions/status.rs | 15 +++++++++ .../src/tools/check_permissions.rs | 10 +++++- 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/libs/cua-driver-rs/crates/cua-driver/src/cli.rs b/libs/cua-driver-rs/crates/cua-driver/src/cli.rs index 67687796672..fc61d65484f 100644 --- a/libs/cua-driver-rs/crates/cua-driver/src/cli.rs +++ b/libs/cua-driver-rs/crates/cua-driver/src/cli.rs @@ -649,6 +649,38 @@ pub fn run_call( process::exit(64); } + // `check_permissions` in-process is ONLY correct when the process is + // running from CuaDriver.app (the daemon). Any one-shot CLI spawned by + // an IDE terminal (VS Code, Cursor, Claude Code, etc.) inherits the + // IDE's TCC responsibility chain, so AXIsProcessTrusted() reads against + // the IDE's bundle — not com.trycua.driver — and may report stale or + // wrong results after `tccutil reset Accessibility com.trycua.driver`. + // + // If the daemon were up we would already have forwarded above; reaching + // this branch means no daemon is listening. Warn the user and force + // `prompt: false` — the tool's default would otherwise raise a TCC + // dialog attributed to the calling shell/IDE bundle, not CuaDriver.app, + // so the user would grant the wrong identity. + // + // Mirrors Swift CallCommand.swift lines 148-171. + let json_args = if tool == "check_permissions" { + eprintln!( + "⚠️ Not running inside the cua-driver daemon process. \ +Results may be inaccurate — TCC checks the calling process, not CuaDriver.app, \ +so permissions granted to CuaDriver.app may read as \"NOT granted\" here.\n\ +For authoritative results, start the daemon first: `cua-driver serve`, \ +then re-run this check." + ); + let mut coerced = json_args + .unwrap_or_else(|| serde_json::Value::Object(serde_json::Map::new())); + if let serde_json::Value::Object(ref mut map) = coerced { + map.insert("prompt".into(), serde_json::Value::Bool(false)); + } + Some(coerced) + } else { + json_args + }; + let rt = tokio::runtime::Builder::new_multi_thread() .enable_all() .build() diff --git a/libs/cua-driver-rs/crates/platform-macos/src/permissions/status.rs b/libs/cua-driver-rs/crates/platform-macos/src/permissions/status.rs index 2721d17ff4e..a9e67aa533f 100644 --- a/libs/cua-driver-rs/crates/platform-macos/src/permissions/status.rs +++ b/libs/cua-driver-rs/crates/platform-macos/src/permissions/status.rs @@ -41,6 +41,21 @@ pub fn current_status() -> PermissionsStatus { } /// Live AX trust state — `AXIsProcessTrusted()`. +/// +/// ⚠️ Attribution caveat: when called from a CLI process spawned by a +/// terminal application (Terminal.app, VS Code, Cursor, etc.), macOS +/// attributes the calling process to the *responsible* parent application +/// rather than to the codesigned CuaDriver.app bundle. This means +/// `AXIsProcessTrusted()` reflects the parent's Accessibility grant, not +/// CuaDriver.app's — so results can be stale or misleading after +/// `tccutil reset Accessibility com.trycua.driver`. +/// +/// This is only a concern for in-process CLI calls without a running daemon. +/// When the daemon is up, `run_call` forwards through the Unix socket and +/// the check runs inside the daemon process (CuaDriver.app), where the +/// attribution is correct. +/// +/// See: https://github.com/trycua/cua/issues/1561 pub fn accessibility_granted() -> bool { unsafe { crate::ax::bindings::AXIsProcessTrusted() } } diff --git a/libs/cua-driver-rs/crates/platform-macos/src/tools/check_permissions.rs b/libs/cua-driver-rs/crates/platform-macos/src/tools/check_permissions.rs index 7d87269f060..6459ff50bc9 100644 --- a/libs/cua-driver-rs/crates/platform-macos/src/tools/check_permissions.rs +++ b/libs/cua-driver-rs/crates/platform-macos/src/tools/check_permissions.rs @@ -19,7 +19,15 @@ fn def() -> &'static ToolDef { By default also raises the system permission dialogs for any missing grants — \ Apple's request APIs are no-ops when the grant is already active, so this is \ safe to call repeatedly. Pass {\"prompt\": false} for a purely read-only \ - status check.".into(), + status check.\n\n\ + ⚠️ CLI caveat: when called from a shell or IDE terminal without a running \ + cua-driver daemon, macOS attributes the calling process to the parent \ + application (Terminal.app, VS Code, Cursor, etc.) rather than to \ + CuaDriver.app. AXIsProcessTrusted() therefore reflects the parent's \ + Accessibility grant, not CuaDriver.app's — so the result can be stale or \ + misleading after `tccutil reset Accessibility com.trycua.driver`. \ + For authoritative results, start the daemon first \ + (`cua-driver serve` or open CuaDriver.app), then re-run this check.".into(), input_schema: serde_json::json!({ "type": "object", "properties": { From 992e512feb24e13923c57218d18fa3616b73d03f Mon Sep 17 00:00:00 2001 From: Contributor Date: Tue, 19 May 2026 17:36:23 +0800 Subject: [PATCH 2/2] fix(cli): force prompt:false for all json_args shapes in check_permissions Address CodeRabbit review on PR #1575. The previous coercion used 'if let Object' which silently skipped non-object json_args (e.g. true, [], "str"), leaving prompt defaulting to true and re-enabling the misattributed TCC dialog. Replace with a match that always produces a fresh Object with prompt:false, regardless of the original arg shape. --- libs/cua-driver-rs/crates/cua-driver/src/cli.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libs/cua-driver-rs/crates/cua-driver/src/cli.rs b/libs/cua-driver-rs/crates/cua-driver/src/cli.rs index fc61d65484f..8e7aba97e41 100644 --- a/libs/cua-driver-rs/crates/cua-driver/src/cli.rs +++ b/libs/cua-driver-rs/crates/cua-driver/src/cli.rs @@ -671,12 +671,12 @@ so permissions granted to CuaDriver.app may read as \"NOT granted\" here.\n\ For authoritative results, start the daemon first: `cua-driver serve`, \ then re-run this check." ); - let mut coerced = json_args - .unwrap_or_else(|| serde_json::Value::Object(serde_json::Map::new())); - if let serde_json::Value::Object(ref mut map) = coerced { - map.insert("prompt".into(), serde_json::Value::Bool(false)); - } - Some(coerced) + let mut map = match json_args { + Some(serde_json::Value::Object(m)) => m, + _ => serde_json::Map::new(), + }; + map.insert("prompt".into(), serde_json::Value::Bool(false)); + Some(serde_json::Value::Object(map)) } else { json_args };