Computer use CLI for AI agents
Rust accessibilityaccessibility-apiai-agentsautomationclicomputer-usecomputer-use-agentcomputer-use-agentsdesktop-automationmacosmcprust
fix: align error codes with spec (APP_NOT_FOUND, PERM_DENIED) and add -i shorthand
Lahfir6dc567a4aedf
diff --git a/README.md b/README.mdindex 0effc6ba0..5c4fe9e6f 100644--- a/README.md+++ b/README.md@@ -143,7 +143,7 @@ Errors follow the same envelope with a structured error object:|------|---------|| `PERM_DENIED` | Accessibility permission not granted || `ELEMENT_NOT_FOUND` | No element matched the given ref or query |-| `APP_NOT_FOUND` | Target application is not running |+| `APP_NOT_FOUND` | Application is not running or has no open windows || `ACTION_FAILED` | The OS rejected the action || `ACTION_NOT_SUPPORTED` | Element does not support the requested action || `STALE_REF` | Ref is from a previous snapshot |diff --git a/crates/core/src/error.rs b/crates/core/src/error.rsindex 4d57f214b..73eb49ecd 100644--- a/crates/core/src/error.rs+++ b/crates/core/src/error.rs@@ -4,9 +4,9 @@ use thiserror::Error;#[derive(Debug, Clone, Serialize, PartialEq, Eq)]#[serde(rename_all = "SCREAMING_SNAKE_CASE")]pub enum ErrorCode {- PermissionDenied,+ PermDenied,ElementNotFound,- ApplicationNotFound,+ AppNotFound,ActionFailed,ActionNotSupported,StaleRef,@@ -20,9 +20,9 @@ pub enum ErrorCode {impl ErrorCode {pub fn as_str(&self) -> &'static str {match self {- ErrorCode::PermissionDenied => "PERMISSION_DENIED",+ ErrorCode::PermDenied => "PERM_DENIED",ErrorCode::ElementNotFound => "ELEMENT_NOT_FOUND",- ErrorCode::ApplicationNotFound => "APPLICATION_NOT_FOUND",+ ErrorCode::AppNotFound => "APP_NOT_FOUND",ErrorCode::ActionFailed => "ACTION_FAILED",ErrorCode::ActionNotSupported => "ACTION_NOT_SUPPORTED",ErrorCode::StaleRef => "STALE_REF",@@ -99,7 +99,7 @@ impl AdapterError {}pub fn permission_denied() -> Self {- Self::new(ErrorCode::PermissionDenied, "Accessibility permission not granted")+ Self::new(ErrorCode::PermDenied, "Accessibility permission not granted").with_suggestion("Open System Settings > Privacy & Security > Accessibility and add your terminal",)diff --git a/crates/core/src/snapshot.rs b/crates/core/src/snapshot.rsindex af37a80f4..48a999359 100644--- a/crates/core/src/snapshot.rs+++ b/crates/core/src/snapshot.rs@@ -47,7 +47,7 @@ pub fn build(}).ok_or_else(|| {AppError::Adapter(crate::error::AdapterError::new(- crate::error::ErrorCode::ApplicationNotFound,+ crate::error::ErrorCode::AppNotFound,format!("No window found for app '{app}'"),))})?diff --git a/crates/macos/src/app_ops.rs b/crates/macos/src/app_ops.rsindex 6ee37130d..691bf59f2 100644--- a/crates/macos/src/app_ops.rs+++ b/crates/macos/src/app_ops.rs@@ -62,7 +62,7 @@ pub fn launch_app_impl(id: &str, wait: bool) -> Result<WindowInfo, AdapterError>}}return Err(AdapterError::new(- agent_desktop_core::error::ErrorCode::ApplicationNotFound,+ agent_desktop_core::error::ErrorCode::AppNotFound,format!("App '{id}' launched but no window found within timeout"),).with_suggestion(diff --git a/src/cli.rs b/src/cli.rsindex 7b4d392a4..d15c64f9d 100644--- a/src/cli.rs+++ b/src/cli.rs@@ -103,7 +103,7 @@ pub struct SnapshotArgs {pub max_depth: u8,#[arg(long)]pub include_bounds: bool,- #[arg(long)]+ #[arg(long, short = 'i')]pub interactive_only: bool,#[arg(long)]pub compact: bool,diff --git a/src/main.rs b/src/main.rsindex 8f93f3678..4b3f4afa7 100644--- a/src/main.rs+++ b/src/main.rs@@ -72,7 +72,7 @@ fn main() {"ok": false,"command": cmd_name,"error": {- "code": "PERMISSION_DENIED",+ "code": "PERM_DENIED","message": "Accessibility permission not granted","suggestion": suggestion}