Computer use CLI for AI agents
Rust accessibilityaccessibility-apiai-agentsautomationclicomputer-usecomputer-use-agentcomputer-use-agentsdesktop-automationmacosmcprust
feat: surface-targeted snapshot, menu wait, list-surfaces command
Lahfir39178b291602
diff --git a/crates/core/src/adapter.rs b/crates/core/src/adapter.rsindex 9f71f8f48..e1ad6ff8a 100644--- a/crates/core/src/adapter.rs+++ b/crates/core/src/adapter.rs@@ -1,7 +1,7 @@use crate::{action::{Action, ActionResult},error::AdapterError,- node::{AccessibilityNode, AppInfo, WindowInfo},+ node::{AccessibilityNode, AppInfo, SurfaceInfo, WindowInfo},refs::RefEntry,};use std::marker::PhantomData;@@ -11,11 +11,23 @@ pub struct WindowFilter {pub app: Option<String>,}+#[derive(Debug, Clone, Copy, Default)]+pub enum SnapshotSurface {+ #[default]+ Window,+ Focused,+ Menu,+ Sheet,+ Popover,+ Alert,+}+pub struct TreeOptions {pub max_depth: u8,pub include_bounds: bool,pub interactive_only: bool,pub compact: bool,+ pub surface: SnapshotSurface,}impl Default for TreeOptions {@@ -25,6 +37,7 @@ impl Default for TreeOptions {include_bounds: false,interactive_only: false,compact: false,+ surface: SnapshotSurface::Window,}}}@@ -157,4 +170,12 @@ pub trait PlatformAdapter: Send + Sync {fn get_live_value(&self, _handle: &NativeHandle) -> Result<Option<String>, AdapterError> {Err(AdapterError::not_supported("get_live_value"))}++ fn wait_for_menu(&self, _pid: i32, _open: bool, _timeout_ms: u64) -> Result<(), AdapterError> {+ Err(AdapterError::not_supported("wait_for_menu"))+ }++ fn list_surfaces(&self, _pid: i32) -> Result<Vec<SurfaceInfo>, AdapterError> {+ Err(AdapterError::not_supported("list_surfaces"))+ }}diff --git a/crates/core/src/commands/helpers.rs b/crates/core/src/commands/helpers.rsindex 5bf3eab7e..1affded8c 100644--- a/crates/core/src/commands/helpers.rs+++ b/crates/core/src/commands/helpers.rs@@ -1,5 +1,5 @@use crate::{- adapter::{NativeHandle, PlatformAdapter},+ adapter::{NativeHandle, PlatformAdapter, WindowFilter},error::AppError,refs::{RefEntry, RefMap},};@@ -32,6 +32,22 @@ pub fn validate_ref_id(ref_id: &str) -> Result<(), AppError> {Ok(())}+pub fn resolve_app_pid(app: Option<&str>, adapter: &dyn PlatformAdapter) -> Result<i32, AppError> {+ if let Some(name) = app {+ let apps = adapter.list_apps()?;+ apps.into_iter()+ .find(|a| a.name.eq_ignore_ascii_case(name))+ .map(|a| a.pid)+ .ok_or_else(|| AppError::invalid_input(format!("App '{name}' not found")))+ } else {+ let filter = WindowFilter { focused_only: true, app: None };+ let windows = adapter.list_windows(&filter)?;+ windows.first()+ .map(|w| w.pid)+ .ok_or_else(|| AppError::invalid_input("No focused window. Use --app to specify."))+ }+}+#[cfg(test)]mod tests {use super::*;diff --git a/crates/core/src/commands/list_surfaces.rs b/crates/core/src/commands/list_surfaces.rsnew file mode 100644index 000000000..43ac6c142--- /dev/null+++ b/crates/core/src/commands/list_surfaces.rs@@ -0,0 +1,12 @@+use crate::{adapter::PlatformAdapter, commands::helpers::resolve_app_pid, error::AppError};+use serde_json::{json, Value};++pub struct ListSurfacesArgs {+ pub app: Option<String>,+}++pub fn execute(args: ListSurfacesArgs, adapter: &dyn PlatformAdapter) -> Result<Value, AppError> {+ let pid = resolve_app_pid(args.app.as_deref(), adapter)?;+ let surfaces = adapter.list_surfaces(pid).map_err(AppError::Adapter)?;+ Ok(json!({ "pid": pid, "surfaces": surfaces }))+}diff --git a/crates/core/src/commands/mod.rs b/crates/core/src/commands/mod.rsindex e5b21a7b4..fee53bd2c 100644--- a/crates/core/src/commands/mod.rs+++ b/crates/core/src/commands/mod.rs@@ -14,6 +14,7 @@ pub mod helpers;pub mod is_check;pub mod launch;pub mod list_apps;+pub mod list_surfaces;pub mod list_windows;pub mod permissions;pub mod press;diff --git a/crates/core/src/commands/snapshot.rs b/crates/core/src/commands/snapshot.rsindex dff307a2d..a2331aa5f 100644--- a/crates/core/src/commands/snapshot.rs+++ b/crates/core/src/commands/snapshot.rs@@ -1,4 +1,8 @@-use crate::{adapter::PlatformAdapter, error::AppError, snapshot};+use crate::{+ adapter::{PlatformAdapter, SnapshotSurface},+ error::AppError,+ snapshot,+};use serde_json::{json, Value};pub struct SnapshotArgs {@@ -8,6 +12,7 @@ pub struct SnapshotArgs {pub include_bounds: bool,pub interactive_only: bool,pub compact: bool,+ pub surface: SnapshotSurface,}pub fn execute(args: SnapshotArgs, adapter: &dyn PlatformAdapter) -> Result<Value, AppError> {@@ -16,6 +21,7 @@ pub fn execute(args: SnapshotArgs, adapter: &dyn PlatformAdapter) -> Result<Valuinclude_bounds: args.include_bounds,interactive_only: args.interactive_only,compact: args.compact,+ surface: args.surface,};let result = snapshot::run(diff --git a/crates/core/src/commands/wait.rs b/crates/core/src/commands/wait.rsindex 31c3eb3b2..1309dd5a0 100644--- a/crates/core/src/commands/wait.rs+++ b/crates/core/src/commands/wait.rs@@ -1,6 +1,6 @@use crate::{adapter::{PlatformAdapter, WindowFilter},- commands::helpers::validate_ref_id,+ commands::helpers::{resolve_app_pid, validate_ref_id},error::AppError,refs::RefMap,};@@ -12,6 +12,9 @@ pub struct WaitArgs {pub element: Option<String>,pub window: Option<String>,pub timeout_ms: u64,+ pub menu: bool,+ pub menu_closed: bool,+ pub app: Option<String>,}pub fn execute(args: WaitArgs, adapter: &dyn PlatformAdapter) -> Result<Value, AppError> {@@ -20,6 +23,14 @@ pub fn execute(args: WaitArgs, adapter: &dyn PlatformAdapter) -> Result<Value, Areturn Ok(json!({ "waited_ms": ms }));}+ if args.menu || args.menu_closed {+ let pid = resolve_app_pid(args.app.as_deref(), adapter)?;+ let start = Instant::now();+ adapter.wait_for_menu(pid, args.menu, args.timeout_ms).map_err(AppError::Adapter)?;+ let elapsed = start.elapsed().as_millis();+ return Ok(json!({ "found": true, "elapsed_ms": elapsed }));+ }+if let Some(ref_id) = args.element {validate_ref_id(&ref_id)?;return wait_for_element(ref_id, args.timeout_ms, adapter);@@ -30,7 +41,7 @@ pub fn execute(args: WaitArgs, adapter: &dyn PlatformAdapter) -> Result<Value, A}Err(AppError::invalid_input(- "Provide a duration (ms), --element <ref>, or --window <title>",+ "Provide a duration (ms), --menu, --element <ref>, or --window <title>",))}diff --git a/crates/core/src/node.rs b/crates/core/src/node.rsindex d0004a269..4629033f2 100644--- a/crates/core/src/node.rs+++ b/crates/core/src/node.rs@@ -69,3 +69,13 @@ pub struct AppInfo {pub pid: i32,pub bundle_id: Option<String>,}++#[derive(Debug, Clone, Serialize, Deserialize)]+pub struct SurfaceInfo {+ #[serde(rename = "type")]+ pub kind: String,+ #[serde(skip_serializing_if = "Option::is_none")]+ pub title: Option<String>,+ #[serde(skip_serializing_if = "Option::is_none")]+ pub item_count: Option<usize>,+}diff --git a/crates/core/src/snapshot.rs b/crates/core/src/snapshot.rsindex 88ece5225..a070fce7f 100644--- a/crates/core/src/snapshot.rs+++ b/crates/core/src/snapshot.rs@@ -65,14 +65,7 @@ pub fn build(})?};- let tree_opts = TreeOptions {- max_depth: opts.max_depth,- include_bounds: opts.include_bounds,- interactive_only: opts.interactive_only,- compact: opts.compact,- };-- let raw_tree = adapter.get_tree(&window, &tree_opts)?;+ let raw_tree = adapter.get_tree(&window, opts)?;let mut refmap = RefMap::new();let tree = allocate_refs(diff --git a/crates/macos/src/adapter.rs b/crates/macos/src/adapter.rsindex 5d36853b2..5e6065c75 100644--- a/crates/macos/src/adapter.rs+++ b/crates/macos/src/adapter.rs@@ -1,11 +1,11 @@use agent_desktop_core::{action::{Action, ActionResult},adapter::{- ImageBuffer, NativeHandle, PermissionStatus, PlatformAdapter, ScreenshotTarget, TreeOptions,- WindowFilter,+ ImageBuffer, NativeHandle, PermissionStatus, PlatformAdapter, ScreenshotTarget,+ SnapshotSurface, TreeOptions, WindowFilter,},error::AdapterError,- node::{AccessibilityNode, AppInfo, WindowInfo},+ node::{AccessibilityNode, AppInfo, SurfaceInfo, WindowInfo},refs::RefEntry,};use rustc_hash::FxHashSet;@@ -34,10 +34,22 @@ impl PlatformAdapter for MacOSAdapter {win: &WindowInfo,opts: &TreeOptions,) -> Result<AccessibilityNode, AdapterError> {+ let el = match opts.surface {+ SnapshotSurface::Window => crate::tree::window_element_for(win.pid, &win.title),+ SnapshotSurface::Focused => crate::surfaces::focused_surface_for_pid(win.pid)+ .ok_or_else(|| AdapterError::internal("No focused surface found"))?,+ SnapshotSurface::Menu => crate::surfaces::menu_element_for_pid(win.pid)+ .ok_or_else(|| AdapterError::element_not_found("No open context menu"))?,+ SnapshotSurface::Sheet => crate::surfaces::sheet_for_pid(win.pid)+ .ok_or_else(|| AdapterError::element_not_found("No open sheet"))?,+ SnapshotSurface::Popover => crate::surfaces::popover_for_pid(win.pid)+ .ok_or_else(|| AdapterError::element_not_found("No visible popover"))?,+ SnapshotSurface::Alert => crate::surfaces::alert_for_pid(win.pid)+ .ok_or_else(|| AdapterError::element_not_found("No open alert or dialog"))?,+ };let mut visited = FxHashSet::default();- let el = crate::tree::window_element_for(win.pid, &win.title);crate::tree::build_subtree(&el, 0, opts.max_depth, opts.include_bounds, &mut visited)- .ok_or_else(|| AdapterError::internal("Empty AX tree for window"))+ .ok_or_else(|| AdapterError::internal("Empty AX tree for surface"))}fn execute_action(@@ -88,6 +100,14 @@ impl PlatformAdapter for MacOSAdapter {crate::clipboard::set(text)}+ fn wait_for_menu(&self, pid: i32, open: bool, timeout_ms: u64) -> Result<(), AdapterError> {+ crate::wait::wait_for_menu(pid, open, timeout_ms)+ }++ fn list_surfaces(&self, pid: i32) -> Result<Vec<SurfaceInfo>, AdapterError> {+ Ok(crate::surfaces::list_surfaces_for_pid(pid))+ }+fn focused_window(&self) -> Result<Option<WindowInfo>, AdapterError> {let filter = WindowFilter { focused_only: true, app: None };let windows = self.list_windows(&filter)?;diff --git a/crates/macos/src/lib.rs b/crates/macos/src/lib.rsindex 6e33b868e..426e24324 100644--- a/crates/macos/src/lib.rs+++ b/crates/macos/src/lib.rs@@ -6,6 +6,8 @@ pub mod input;pub mod permissions;pub mod roles;pub mod screenshot;+pub mod surfaces;pub mod tree;+pub mod wait;pub use adapter::MacOSAdapter;diff --git a/crates/macos/src/screenshot.rs b/crates/macos/src/screenshot.rsindex d6853f7de..c3eb6fa9d 100644--- a/crates/macos/src/screenshot.rs+++ b/crates/macos/src/screenshot.rs@@ -79,7 +79,6 @@ mod imp {fn CGWindowListCopyWindowInfo(option: u32, window_id: u32) -> CFTypeRef;}- // kCGWindowListOptionOnScreenOnly (1) | kCGWindowListExcludeDesktopElements (16) = 17let info_ref = unsafe { CGWindowListCopyWindowInfo(17, 0) };if info_ref.is_null() {return None;@@ -108,7 +107,6 @@ mod imp {if int_field("kCGWindowOwnerPID") != Some(pid) {continue;}- // Skip non-normal layers (menus, panels, overlays)if int_field("kCGWindowLayer").unwrap_or(99) != 0 {continue;}@@ -118,7 +116,6 @@ mod imp {None => continue,};- // Pick the window with the largest area (the main window)let bounds_key = CFString::new("kCGWindowBounds");let area = if let Some(bounds_val) = dict.find(&bounds_key) {let bounds_dict = unsafe {diff --git a/crates/macos/src/surfaces.rs b/crates/macos/src/surfaces.rsnew file mode 100644index 000000000..421be69c2--- /dev/null+++ b/crates/macos/src/surfaces.rs@@ -0,0 +1,116 @@+use crate::tree::{copy_ax_array, copy_string_attr, element_for_pid, AXElement};+use agent_desktop_core::node::SurfaceInfo;++#[cfg(target_os = "macos")]+mod imp {+ use super::*;+ use accessibility_sys::{kAXErrorSuccess, AXUIElementCopyAttributeValue, AXUIElementRef};+ use core_foundation::{base::{CFTypeRef, TCFType}, string::CFString};++ fn copy_element_attr(el: &AXElement, attr: &str) -> Option<AXElement> {+ let cf_attr = CFString::new(attr);+ let mut value: CFTypeRef = std::ptr::null_mut();+ let err = unsafe {+ AXUIElementCopyAttributeValue(el.0, cf_attr.as_concrete_TypeRef(), &mut value)+ };+ if err != kAXErrorSuccess || value.is_null() {+ return None;+ }+ Some(AXElement(value as AXUIElementRef))+ }++ fn focused_window_element(pid: i32) -> Option<AXElement> {+ let app = element_for_pid(pid);+ copy_element_attr(&app, "AXFocusedWindow")+ }++ pub fn menu_element_for_pid(pid: i32) -> Option<AXElement> {+ let app = element_for_pid(pid);+ copy_ax_array(&app, "AXMenus")?.into_iter().next()+ }++ pub fn focused_surface_for_pid(pid: i32) -> Option<AXElement> {+ focused_window_element(pid)+ }++ fn first_child_with_subrole(pid: i32, subrole: &str) -> Option<AXElement> {+ let win = focused_window_element(pid)?;+ let children = copy_ax_array(&win, "AXChildren")?;+ children.into_iter().find(|child| {+ copy_string_attr(child, "AXSubrole").as_deref() == Some(subrole)+ })+ }++ pub fn sheet_for_pid(pid: i32) -> Option<AXElement> {+ first_child_with_subrole(pid, "AXSheet")+ }++ pub fn popover_for_pid(pid: i32) -> Option<AXElement> {+ first_child_with_subrole(pid, "AXPopover")+ }++ pub fn alert_for_pid(pid: i32) -> Option<AXElement> {+ let win = focused_window_element(pid)?;+ let children = copy_ax_array(&win, "AXChildren")?;+ children.into_iter().find(|child| {+ let subrole = copy_string_attr(child, "AXSubrole");+ matches!(subrole.as_deref(), Some("AXDialog") | Some("AXAlert"))+ })+ }++ pub fn is_menu_open(pid: i32) -> bool {+ let app = element_for_pid(pid);+ copy_ax_array(&app, "AXMenus").map(|v| !v.is_empty()).unwrap_or(false)+ }++ pub fn list_surfaces_for_pid(pid: i32) -> Vec<SurfaceInfo> {+ let mut surfaces = Vec::new();+ let app = element_for_pid(pid);++ if let Some(menus) = copy_ax_array(&app, "AXMenus") {+ for menu in &menus {+ let title = copy_string_attr(menu, "AXTitle")+ .or_else(|| copy_string_attr(menu, "AXDescription"));+ let item_count = copy_ax_array(menu, "AXChildren").map(|v| v.len());+ surfaces.push(SurfaceInfo { kind: "menu".into(), title, item_count });+ }+ }++ if let Some(win) = focused_window_element(pid) {+ if let Some(children) = copy_ax_array(&win, "AXChildren") {+ for child in &children {+ let subrole = copy_string_attr(child, "AXSubrole");+ let kind = match subrole.as_deref() {+ Some("AXSheet") => "sheet",+ Some("AXPopover") => "popover",+ Some("AXDialog") | Some("AXAlert") => "alert",+ _ => continue,+ };+ let title = copy_string_attr(child, "AXTitle")+ .or_else(|| copy_string_attr(child, "AXDescription"));+ surfaces.push(SurfaceInfo { kind: kind.into(), title, item_count: None });+ }+ }+ }++ surfaces+ }+}++#[cfg(not(target_os = "macos"))]+mod imp {+ use super::*;++ pub fn menu_element_for_pid(_pid: i32) -> Option<AXElement> { None }+ pub fn focused_surface_for_pid(_pid: i32) -> Option<AXElement> { None }+ pub fn sheet_for_pid(_pid: i32) -> Option<AXElement> { None }+ pub fn popover_for_pid(_pid: i32) -> Option<AXElement> { None }+ pub fn alert_for_pid(_pid: i32) -> Option<AXElement> { None }+ pub fn is_menu_open(_pid: i32) -> bool { false }+ pub fn list_surfaces_for_pid(_pid: i32) -> Vec<SurfaceInfo> { Vec::new() }+}++pub use imp::{+ alert_for_pid, focused_surface_for_pid, is_menu_open, list_surfaces_for_pid,+ menu_element_for_pid, popover_for_pid, sheet_for_pid,+};diff --git a/crates/macos/src/tree.rs b/crates/macos/src/tree.rsindex 85a988d48..88e0d359a 100644--- a/crates/macos/src/tree.rs+++ b/crates/macos/src/tree.rs@@ -43,7 +43,6 @@ mod imp {pub fn element_for_pid(pid: i32) -> AXElement {let el = AXElement(unsafe { AXUIElementCreateApplication(pid) });if !el.0.is_null() {- // 2-second timeout prevents hung/slow processes from blocking the tree walkunsafe { AXUIElementSetMessagingTimeout(el.0, 2.0) };}el@@ -118,7 +117,6 @@ mod imp {return Some(s.to_string());}match idx {- // value: may be CFBoolean (checkbox) or CFNumber (slider, stepper)3 => {if let Some(b) = item.downcast::<CFBoolean>() { return Some(bool::from(b).to_string()); }if let Some(n) = item.downcast::<CFNumber>() {@@ -127,7 +125,6 @@ mod imp {}None}- // enabled / focused are always CFBoolean4 | 5 => item.downcast::<CFBoolean>().map(|b| bool::from(b).to_string()),_ => None,}@@ -188,7 +185,6 @@ mod imp {let name = title.clone().or_else(|| ax_desc.clone());let description = if title.is_some() { ax_desc } else { None };- // AXStaticText stores its visible text in kAXValueAttribute, not title/descriptionlet name = if name.is_none() && ax_role.as_deref() == Some("AXStaticText") {value.clone().or(name)} else {@@ -201,11 +197,7 @@ mod imp {let bounds = if include_bounds { read_bounds(el) } else { None };- // Children fetched before name resolution so we can extract labels from themlet children_raw = copy_children(el, ax_role.as_deref()).unwrap_or_default();-- // Last-resort name: walk immediate children for AXStaticText or AXCell→AXStaticText- // This resolves AXRow (sidebar items, list rows) whose label lives in a child text nodelet name = name.or_else(|| label_from_children(&children_raw));let children = children_rawdiff --git a/crates/macos/src/wait.rs b/crates/macos/src/wait.rsnew file mode 100644index 000000000..3d8f162f6--- /dev/null+++ b/crates/macos/src/wait.rs@@ -0,0 +1,37 @@+use agent_desktop_core::error::AdapterError;+use std::time::{Duration, Instant};++#[cfg(target_os = "macos")]+mod imp {+ use super::*;+ use crate::surfaces::is_menu_open;++ pub fn wait_for_menu(pid: i32, open: bool, timeout_ms: u64) -> Result<(), AdapterError> {+ let deadline = Instant::now() + Duration::from_millis(timeout_ms);+ loop {+ if is_menu_open(pid) == open {+ return Ok(());+ }+ if Instant::now() >= deadline {+ let msg = if open {+ format!("No context menu opened within {timeout_ms}ms")+ } else {+ format!("Context menu did not close within {timeout_ms}ms")+ };+ return Err(AdapterError::timeout(msg));+ }+ std::thread::sleep(Duration::from_millis(50));+ }+ }+}++#[cfg(not(target_os = "macos"))]+mod imp {+ use super::*;++ pub fn wait_for_menu(_pid: i32, _open: bool, _timeout_ms: u64) -> Result<(), AdapterError> {+ Err(AdapterError::not_supported("wait_for_menu"))+ }+}++pub use imp::wait_for_menu;diff --git a/src/cli.rs b/src/cli.rsindex d15c64f9d..73640c5cb 100644--- a/src/cli.rs+++ b/src/cli.rs@@ -1,4 +1,4 @@-use clap::{Parser, Subcommand};+use clap::{Parser, Subcommand, ValueEnum};#[derive(Parser, Debug)]#[command(@@ -7,7 +7,7 @@ use clap::{Parser, Subcommand};about = "Desktop automation for AI agents",after_help = "\CATEGORIES:- Observation: snapshot, find, screenshot, get, is+ Observation: snapshot, find, screenshot, get, is, list-surfacesInteraction: click, double-click, right-click, type, set-value, focus, select,toggle, expand, collapse, scroll, pressApp/Window: launch, close-app, list-windows, list-apps, focus-window@@ -24,6 +24,17 @@ pub struct Cli {pub command: Option<Commands>,}+#[derive(ValueEnum, Clone, Debug, Default)]+pub enum Surface {+ #[default]+ Window,+ Focused,+ Menu,+ Sheet,+ Popover,+ Alert,+}+#[derive(Subcommand, Debug)]pub enum Commands {Snapshot(SnapshotArgs),@@ -48,6 +59,7 @@ pub enum Commands {ListWindows(ListWindowsArgs),ListApps,FocusWindow(FocusWindowArgs),+ ListSurfaces(ListSurfacesArgs),ClipboardGet,ClipboardSet(ClipboardSetArgs),Wait(WaitArgs),@@ -82,6 +94,7 @@ impl Commands {Self::ListWindows(_) => "list-windows",Self::ListApps => "list-apps",Self::FocusWindow(_) => "focus-window",+ Self::ListSurfaces(_) => "list-surfaces",Self::ClipboardGet => "clipboard-get",Self::ClipboardSet(_) => "clipboard-set",Self::Wait(_) => "wait",@@ -107,6 +120,8 @@ pub struct SnapshotArgs {pub interactive_only: bool,#[arg(long)]pub compact: bool,+ #[arg(long, value_enum, default_value_t = Surface::Window)]+ pub surface: Surface,}#[derive(Parser, Debug)]@@ -241,6 +256,18 @@ pub struct WaitArgs {pub window: Option<String>,#[arg(long, default_value = "30000")]pub timeout: u64,+ #[arg(long)]+ pub menu: bool,+ #[arg(long)]+ pub menu_closed: bool,+ #[arg(long)]+ pub app: Option<String>,+}++#[derive(Parser, Debug)]+pub struct ListSurfacesArgs {+ #[arg(long)]+ pub app: Option<String>,}#[derive(Parser, Debug)]diff --git a/src/dispatch.rs b/src/dispatch.rsindex e8dad50d5..689b90bba 100644--- a/src/dispatch.rs+++ b/src/dispatch.rs@@ -3,9 +3,9 @@ use agent_desktop_core::{adapter::PlatformAdapter,commands::{batch, click, clipboard_get, clipboard_set, close_app, collapse, double_click, expand,- find, focus, focus_window, get, helpers, is_check, launch, list_apps, list_windows,- permissions, press, right_click, screenshot, scroll, select, set_value, snapshot, status,- toggle, type_text, version, wait,+ find, focus, focus_window, get, helpers, is_check, launch, list_apps, list_surfaces,+ list_windows, permissions, press, right_click, screenshot, scroll, select, set_value,+ snapshot, status, toggle, type_text, version, wait,},error::AppError,};@@ -23,6 +23,7 @@ pub fn dispatch(cmd: Commands, adapter: &dyn PlatformAdapter) -> Result<Value, Ainclude_bounds: a.include_bounds,interactive_only: a.interactive_only,compact: a.compact,+ surface: cli_surface_to_core(&a.surface),},adapter,),@@ -113,6 +114,11 @@ pub fn dispatch(cmd: Commands, adapter: &dyn PlatformAdapter) -> Result<Value, ACommands::ListApps => list_apps::execute(adapter),+ Commands::ListSurfaces(a) => list_surfaces::execute(+ list_surfaces::ListSurfacesArgs { app: a.app },+ adapter,+ ),+Commands::FocusWindow(a) => focus_window::execute(focus_window::FocusWindowArgs {window_id: a.window_id,@@ -131,6 +137,9 @@ pub fn dispatch(cmd: Commands, adapter: &dyn PlatformAdapter) -> Result<Value, Aelement: a.element,window: a.window,timeout_ms: a.timeout,+ menu: a.menu,+ menu_closed: a.menu_closed,+ app: a.app,},adapter,),@@ -191,6 +200,7 @@ fn dispatch_batch_command(include_bounds: args.get("include_bounds").and_then(|v| v.as_bool()).unwrap_or(false),interactive_only: args.get("interactive_only").and_then(|v| v.as_bool()).unwrap_or(false),compact: args.get("compact").and_then(|v| v.as_bool()).unwrap_or(false),+ surface: parse_batch_surface(args.get("surface").and_then(|v| v.as_str())),},adapter,),@@ -331,10 +341,18 @@ fn dispatch_batch_command(element: str_field(&args, "element"),window: str_field(&args, "window"),timeout_ms: args.get("timeout_ms").and_then(|v| v.as_u64()).unwrap_or(30000),+ menu: args.get("menu").and_then(|v| v.as_bool()).unwrap_or(false),+ menu_closed: args.get("menu_closed").and_then(|v| v.as_bool()).unwrap_or(false),+ app: str_field(&args, "app"),},adapter,),+ "list-surfaces" => list_surfaces::execute(+ list_surfaces::ListSurfacesArgs { app: str_field(&args, "app") },+ adapter,+ ),+"status" => status::execute(adapter),"permissions" => permissions::execute(@@ -395,3 +413,28 @@ fn parse_direction(s: &str) -> Result<Direction, AppError> {))),}}++fn cli_surface_to_core(s: &crate::cli::Surface) -> agent_desktop_core::adapter::SnapshotSurface {+ use agent_desktop_core::adapter::SnapshotSurface;+ use crate::cli::Surface;+ match s {+ Surface::Window => SnapshotSurface::Window,+ Surface::Focused => SnapshotSurface::Focused,+ Surface::Menu => SnapshotSurface::Menu,+ Surface::Sheet => SnapshotSurface::Sheet,+ Surface::Popover => SnapshotSurface::Popover,+ Surface::Alert => SnapshotSurface::Alert,+ }+}++fn parse_batch_surface(s: Option<&str>) -> agent_desktop_core::adapter::SnapshotSurface {+ use agent_desktop_core::adapter::SnapshotSurface;+ match s {+ Some("menu") => SnapshotSurface::Menu,+ Some("sheet") => SnapshotSurface::Sheet,+ Some("popover") => SnapshotSurface::Popover,+ Some("alert") => SnapshotSurface::Alert,+ Some("focused") => SnapshotSurface::Focused,+ _ => SnapshotSurface::Window,+ }+}