Skip to content

Computer use CLI for AI agents

feat: add notification command types, adapter trait, and CLI wiring

Lahfirc5b05bab600a
diff --git a/crates/core/src/adapter.rs b/crates/core/src/adapter.rs
index 63196b742..5501a3cf0 100644
--- a/crates/core/src/adapter.rs
+++ b/crates/core/src/adapter.rs
@@ -2,6 +2,7 @@ use crate::{
action::{Action, ActionResult, DragParams, MouseEvent, WindowOp},
error::AdapterError,
node::{AccessibilityNode, AppInfo, Rect, SurfaceInfo, WindowInfo},
+ notification::{NotificationFilter, NotificationInfo},
refs::RefEntry,
};
use std::marker::PhantomData;
@@ -213,4 +214,27 @@ pub trait PlatformAdapter: Send + Sync {
fn clear_clipboard(&self) -> Result<(), AdapterError> {
Err(AdapterError::not_supported("clear_clipboard"))
}
+
+ fn list_notifications(
+ &self,
+ _filter: &NotificationFilter,
+ ) -> Result<Vec<NotificationInfo>, AdapterError> {
+ Err(AdapterError::not_supported("list_notifications"))
+ }
+
+ fn dismiss_notification(
+ &self,
+ _index: usize,
+ _app_filter: Option<&str>,
+ ) -> Result<NotificationInfo, AdapterError> {
+ Err(AdapterError::not_supported("dismiss_notification"))
+ }
+
+ fn notification_action(
+ &self,
+ _index: usize,
+ _action_name: &str,
+ ) -> Result<ActionResult, AdapterError> {
+ Err(AdapterError::not_supported("notification_action"))
+ }
}
diff --git a/crates/core/src/commands/dismiss_all_notifications.rs b/crates/core/src/commands/dismiss_all_notifications.rs
new file mode 100644
index 000000000..5e1380266
--- /dev/null
+++ b/crates/core/src/commands/dismiss_all_notifications.rs
@@ -0,0 +1,29 @@
+use crate::{adapter::PlatformAdapter, error::AppError, notification::NotificationFilter};
+use serde_json::{json, Value};
+
+pub struct DismissAllNotificationsArgs {
+ pub app: Option<String>,
+}
+
+pub fn execute(
+ args: DismissAllNotificationsArgs,
+ adapter: &dyn PlatformAdapter,
+) -> Result<Value, AppError> {
+ let filter = NotificationFilter {
+ app: args.app.clone(),
+ ..Default::default()
+ };
+ let notifications = adapter.list_notifications(&filter)?;
+ let mut dismissed = 0;
+ for notif in notifications.iter().rev() {
+ if adapter
+ .dismiss_notification(notif.index, args.app.as_deref())
+ .is_ok()
+ {
+ dismissed += 1;
+ }
+ }
+ Ok(json!({
+ "dismissed_count": dismissed,
+ }))
+}
diff --git a/crates/core/src/commands/dismiss_notification.rs b/crates/core/src/commands/dismiss_notification.rs
new file mode 100644
index 000000000..76400d0ed
--- /dev/null
+++ b/crates/core/src/commands/dismiss_notification.rs
@@ -0,0 +1,17 @@
+use crate::{adapter::PlatformAdapter, error::AppError};
+use serde_json::{json, Value};
+
+pub struct DismissNotificationArgs {
+ pub index: usize,
+ pub app: Option<String>,
+}
+
+pub fn execute(
+ args: DismissNotificationArgs,
+ adapter: &dyn PlatformAdapter,
+) -> Result<Value, AppError> {
+ let dismissed = adapter.dismiss_notification(args.index, args.app.as_deref())?;
+ Ok(json!({
+ "dismissed": dismissed,
+ }))
+}
diff --git a/crates/core/src/commands/list_notifications.rs b/crates/core/src/commands/list_notifications.rs
new file mode 100644
index 000000000..7b7deb44d
--- /dev/null
+++ b/crates/core/src/commands/list_notifications.rs
@@ -0,0 +1,24 @@
+use crate::{adapter::PlatformAdapter, error::AppError, notification::NotificationFilter};
+use serde_json::{json, Value};
+
+pub struct ListNotificationsArgs {
+ pub app: Option<String>,
+ pub text: Option<String>,
+ pub limit: Option<usize>,
+}
+
+pub fn execute(
+ args: ListNotificationsArgs,
+ adapter: &dyn PlatformAdapter,
+) -> Result<Value, AppError> {
+ let filter = NotificationFilter {
+ app: args.app,
+ text: args.text,
+ limit: args.limit,
+ };
+ let notifications = adapter.list_notifications(&filter)?;
+ Ok(json!({
+ "count": notifications.len(),
+ "notifications": notifications,
+ }))
+}
diff --git a/crates/core/src/commands/mod.rs b/crates/core/src/commands/mod.rs
index 922e55919..8a9f5783b 100644
--- a/crates/core/src/commands/mod.rs
+++ b/crates/core/src/commands/mod.rs
@@ -7,6 +7,8 @@ pub mod clipboard_get;
pub mod clipboard_set;
pub mod close_app;
pub mod collapse;
+pub mod dismiss_all_notifications;
+pub mod dismiss_notification;
pub mod double_click;
pub mod drag;
pub mod expand;
@@ -21,6 +23,7 @@ pub mod key_down;
pub mod key_up;
pub mod launch;
pub mod list_apps;
+pub mod list_notifications;
pub mod list_surfaces;
pub mod list_windows;
pub mod maximize;
@@ -30,6 +33,7 @@ pub mod mouse_down;
pub mod mouse_move;
pub mod mouse_up;
pub mod move_window;
+pub mod notification_action;
pub mod permissions;
pub mod press;
pub mod resize_window;
diff --git a/crates/core/src/commands/notification_action.rs b/crates/core/src/commands/notification_action.rs
new file mode 100644
index 000000000..8923a603e
--- /dev/null
+++ b/crates/core/src/commands/notification_action.rs
@@ -0,0 +1,17 @@
+use crate::{adapter::PlatformAdapter, error::AppError};
+use serde_json::{json, Value};
+
+pub struct NotificationActionArgs {
+ pub index: usize,
+ pub action: String,
+}
+
+pub fn execute(
+ args: NotificationActionArgs,
+ adapter: &dyn PlatformAdapter,
+) -> Result<Value, AppError> {
+ let result = adapter.notification_action(args.index, &args.action)?;
+ Ok(json!({
+ "action": result.action,
+ }))
+}
diff --git a/crates/core/src/commands/wait.rs b/crates/core/src/commands/wait.rs
index 1f9598618..d74a41c9f 100644
--- a/crates/core/src/commands/wait.rs
+++ b/crates/core/src/commands/wait.rs
@@ -3,6 +3,7 @@ use crate::{
commands::helpers::{resolve_app_pid, validate_ref_id},
error::AppError,
node::AccessibilityNode,
+ notification::NotificationFilter,
refs::RefMap,
snapshot,
};
@@ -17,6 +18,8 @@ pub struct WaitArgs {
pub timeout_ms: u64,
pub menu: bool,
pub menu_closed: bool,
+ pub notification: bool,
+ pub poll_interval_ms: u64,
pub app: Option<String>,
}
@@ -36,6 +39,10 @@ pub fn execute(args: WaitArgs, adapter: &dyn PlatformAdapter) -> Result<Value, A
return Ok(json!({ "found": true, "elapsed_ms": elapsed }));
}
+ if args.notification {
+ return wait_for_notification(&args, adapter);
+ }
+
if let Some(ref_id) = args.element {
validate_ref_id(&ref_id)?;
return wait_for_element(ref_id, args.timeout_ms, adapter);
@@ -50,7 +57,7 @@ pub fn execute(args: WaitArgs, adapter: &dyn PlatformAdapter) -> Result<Value, A
}
Err(AppError::invalid_input(
- "Provide a duration (ms), --menu, --element <ref>, --window <title>, or --text <text>",
+ "Provide a duration (ms), --menu, --notification, --element <ref>, --window <title>, or --text <text>",
))
}
@@ -152,6 +159,41 @@ struct TextMatch {
role: String,
}
+fn wait_for_notification(
+ args: &WaitArgs,
+ adapter: &dyn PlatformAdapter,
+) -> Result<Value, AppError> {
+ let filter = NotificationFilter {
+ app: args.app.clone(),
+ text: None,
+ ..Default::default()
+ };
+ let baseline = adapter.list_notifications(&filter)?;
+ let baseline_count = baseline.len();
+ let interval = Duration::from_millis(args.poll_interval_ms);
+ let deadline = Instant::now() + Duration::from_millis(args.timeout_ms);
+ let start = Instant::now();
+
+ loop {
+ std::thread::sleep(interval);
+ if Instant::now() > deadline {
+ return Err(AppError::Adapter(crate::error::AdapterError::timeout(
+ format!("No new notification within {}ms", args.timeout_ms),
+ )));
+ }
+ let current = adapter.list_notifications(&filter)?;
+ if current.len() > baseline_count {
+ let elapsed = start.elapsed().as_millis();
+ return Ok(json!({
+ "condition": "notification",
+ "matched": true,
+ "notification": current[0],
+ "elapsed_ms": elapsed,
+ }));
+ }
+ }
+}
+
fn find_text_in_tree(node: &AccessibilityNode, text_lower: &str) -> Option<TextMatch> {
let in_name = node
.name
diff --git a/crates/core/src/error.rs b/crates/core/src/error.rs
index 1aefc5200..8c3506b49 100644
--- a/crates/core/src/error.rs
+++ b/crates/core/src/error.rs
@@ -14,6 +14,7 @@ pub enum ErrorCode {
PlatformNotSupported,
Timeout,
InvalidArgs,
+ NotificationNotFound,
Internal,
}
@@ -30,6 +31,7 @@ impl ErrorCode {
ErrorCode::PlatformNotSupported => "PLATFORM_NOT_SUPPORTED",
ErrorCode::Timeout => "TIMEOUT",
ErrorCode::InvalidArgs => "INVALID_ARGS",
+ ErrorCode::NotificationNotFound => "NOTIFICATION_NOT_FOUND",
ErrorCode::Internal => "INTERNAL",
}
}
@@ -100,6 +102,14 @@ impl AdapterError {
.with_suggestion("The target application may be busy or unresponsive")
}
+ pub fn notification_not_found(index: usize) -> Self {
+ Self::new(
+ ErrorCode::NotificationNotFound,
+ format!("Notification at index {index} not found"),
+ )
+ .with_suggestion("Notification may have been dismissed or expired. Run 'list-notifications' to see current notifications")
+ }
+
pub fn internal(msg: impl Into<String>) -> Self {
Self::new(ErrorCode::Internal, msg)
}
diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs
index 03665f400..f0ee82242 100644
--- a/crates/core/src/lib.rs
+++ b/crates/core/src/lib.rs
@@ -4,6 +4,7 @@ pub mod commands;
pub mod error;
pub mod hints;
pub mod node;
+pub mod notification;
pub mod output;
pub mod refs;
pub mod snapshot;
@@ -18,5 +19,6 @@ pub use adapter::{
};
pub use error::{AdapterError, AppError, ErrorCode};
pub use node::{AccessibilityNode, AppInfo, Rect, WindowInfo};
+pub use notification::{NotificationFilter, NotificationInfo};
pub use output::{AppContext, ErrorPayload, Response, WindowContext};
pub use refs::{RefEntry, RefMap};
diff --git a/crates/core/src/notification.rs b/crates/core/src/notification.rs
new file mode 100644
index 000000000..140f12a81
--- /dev/null
+++ b/crates/core/src/notification.rs
@@ -0,0 +1,66 @@
+use serde::{Deserialize, Serialize};
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+pub struct NotificationInfo {
+ pub index: usize,
+ pub app_name: String,
+ pub title: String,
+ #[serde(skip_serializing_if = "Option::is_none")]
+ pub body: Option<String>,
+ #[serde(skip_serializing_if = "Option::is_none")]
+ pub timestamp: Option<String>,
+ #[serde(skip_serializing_if = "Vec::is_empty", default)]
+ pub actions: Vec<String>,
+}
+
+#[derive(Debug, Clone, Default)]
+pub struct NotificationFilter {
+ pub app: Option<String>,
+ pub text: Option<String>,
+ pub limit: Option<usize>,
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn notification_info_serialization_omits_none_fields() {
+ let info = NotificationInfo {
+ index: 1,
+ app_name: "Messages".into(),
+ title: "New message".into(),
+ body: None,
+ timestamp: None,
+ actions: vec![],
+ };
+ let json = serde_json::to_value(&info).unwrap();
+ assert!(!json.as_object().unwrap().contains_key("body"));
+ assert!(!json.as_object().unwrap().contains_key("timestamp"));
+ assert!(!json.as_object().unwrap().contains_key("actions"));
+ }
+
+ #[test]
+ fn notification_info_serialization_includes_present_fields() {
+ let info = NotificationInfo {
+ index: 2,
+ app_name: "Slack".into(),
+ title: "Channel update".into(),
+ body: Some("New message in #general".into()),
+ timestamp: Some("2026-02-27T10:00:00Z".into()),
+ actions: vec!["Reply".into(), "Open".into()],
+ };
+ let json = serde_json::to_value(&info).unwrap();
+ assert_eq!(json["body"], "New message in #general");
+ assert_eq!(json["timestamp"], "2026-02-27T10:00:00Z");
+ assert_eq!(json["actions"], serde_json::json!(["Reply", "Open"]));
+ }
+
+ #[test]
+ fn notification_filter_default_is_unfiltered() {
+ let filter = NotificationFilter::default();
+ assert!(filter.app.is_none());
+ assert!(filter.text.is_none());
+ assert!(filter.limit.is_none());
+ }
+}
diff --git a/src/batch_dispatch.rs b/src/batch_dispatch.rs
index 908616c83..7296e0d03 100644
--- a/src/batch_dispatch.rs
+++ b/src/batch_dispatch.rs
@@ -1,11 +1,9 @@
use agent_desktop_core::{
commands::{
- check, clear, click, clipboard_clear, clipboard_get, clipboard_set, close_app, collapse,
- double_click, drag, expand, find, focus, focus_window, get, helpers, hover, is_check,
- key_down, key_up, launch, list_apps, list_surfaces, list_windows, maximize, minimize,
- mouse_click, mouse_down, mouse_move, mouse_up, move_window, permissions, press,
- resize_window, restore, right_click, screenshot, scroll, scroll_to, select, set_value,
- snapshot, status, toggle, triple_click, type_text, uncheck, version, wait,
+ check, clear, click, collapse, double_click, drag, expand, find, focus, get, helpers,
+ hover, is_check, key_down, key_up, mouse_click, mouse_down, mouse_move, mouse_up, press,
+ right_click, screenshot, scroll, scroll_to, select, set_value, snapshot, toggle,
+ triple_click, type_text, uncheck,
},
error::AppError,
};
@@ -18,16 +16,6 @@ pub fn dispatch_batch_command(
args: Value,
adapter: &dyn agent_desktop_core::adapter::PlatformAdapter,
) -> Result<Value, AppError> {
- fn str_field(v: &Value, key: &str) -> Option<String> {
- v.get(key).and_then(|v| v.as_str()).map(String::from)
- }
-
- fn req_str(v: &Value, key: &str) -> Result<String, AppError> {
- str_field(v, key).ok_or_else(|| {
- AppError::invalid_input(format!("Batch: missing required field '{key}'"))
- })
- }
-
match command {
"snapshot" => snapshot::execute(
snapshot::SnapshotArgs {
@@ -328,133 +316,17 @@ pub fn dispatch_batch_command(
)
}
- "launch" => launch::execute(
- launch::LaunchArgs {
- app: req_str(&args, "app")?,
- timeout_ms: args
- .get("timeout")
- .and_then(|v| v.as_u64())
- .unwrap_or(30000),
- },
- adapter,
- ),
-
- "close-app" => close_app::execute(
- close_app::CloseAppArgs {
- app: req_str(&args, "app")?,
- force: args.get("force").and_then(|v| v.as_bool()).unwrap_or(false),
- },
- adapter,
- ),
-
- "list-windows" => list_windows::execute(
- list_windows::ListWindowsArgs {
- app: str_field(&args, "app"),
- },
- adapter,
- ),
-
- "list-apps" => list_apps::execute(adapter),
-
- "focus-window" => focus_window::execute(
- focus_window::FocusWindowArgs {
- window_id: str_field(&args, "window_id"),
- app: str_field(&args, "app"),
- title: str_field(&args, "title"),
- },
- adapter,
- ),
-
- "resize-window" => resize_window::execute(
- resize_window::ResizeWindowArgs {
- app: str_field(&args, "app"),
- width: args.get("width").and_then(|v| v.as_f64()).unwrap_or(800.0),
- height: args.get("height").and_then(|v| v.as_f64()).unwrap_or(600.0),
- },
- adapter,
- ),
-
- "move-window" => move_window::execute(
- move_window::MoveWindowArgs {
- app: str_field(&args, "app"),
- x: args.get("x").and_then(|v| v.as_f64()).unwrap_or(0.0),
- y: args.get("y").and_then(|v| v.as_f64()).unwrap_or(0.0),
- },
- adapter,
- ),
-
- "minimize" => minimize::execute(
- minimize::MinimizeArgs {
- app: str_field(&args, "app"),
- },
- adapter,
- ),
-
- "maximize" => maximize::execute(
- maximize::MaximizeArgs {
- app: str_field(&args, "app"),
- },
- adapter,
- ),
-
- "restore" => restore::execute(
- restore::RestoreArgs {
- app: str_field(&args, "app"),
- },
- adapter,
- ),
-
- "clipboard-get" => clipboard_get::execute(adapter),
- "clipboard-set" => clipboard_set::execute(req_str(&args, "text")?, adapter),
- "clipboard-clear" => clipboard_clear::execute(adapter),
-
- "wait" => wait::execute(
- wait::WaitArgs {
- ms: args.get("ms").and_then(|v| v.as_u64()),
- element: str_field(&args, "element"),
- window: str_field(&args, "window"),
- text: str_field(&args, "text"),
- 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(
- permissions::PermissionsArgs {
- request: args
- .get("request")
- .and_then(|v| v.as_bool())
- .unwrap_or(false),
- },
- adapter,
- ),
+ other => crate::batch_dispatch_ext::dispatch(other, args, adapter),
+ }
+}
- "version" => version::execute(version::VersionArgs {
- json: args.get("json").and_then(|v| v.as_bool()).unwrap_or(false),
- }),
+pub(crate) fn str_field(v: &Value, key: &str) -> Option<String> {
+ v.get(key).and_then(|v| v.as_str()).map(String::from)
+}
- other => Err(AppError::invalid_input(format!(
- "Unknown batch command '{other}'"
- ))),
- }
+pub(crate) fn req_str(v: &Value, key: &str) -> Result<String, AppError> {
+ str_field(v, key)
+ .ok_or_else(|| AppError::invalid_input(format!("Batch: missing required field '{key}'")))
}
fn parse_batch_surface(s: Option<&str>) -> agent_desktop_core::adapter::SnapshotSurface {
diff --git a/src/batch_dispatch_ext.rs b/src/batch_dispatch_ext.rs
new file mode 100644
index 000000000..985e2db35
--- /dev/null
+++ b/src/batch_dispatch_ext.rs
@@ -0,0 +1,210 @@
+use agent_desktop_core::{
+ commands::{
+ clipboard_clear, clipboard_get, clipboard_set, close_app, dismiss_all_notifications,
+ dismiss_notification, focus_window, launch, list_apps, list_notifications, list_surfaces,
+ list_windows, maximize, minimize, move_window, notification_action, permissions,
+ resize_window, restore, status, version, wait,
+ },
+ error::AppError,
+};
+use serde_json::Value;
+
+use crate::batch_dispatch::{req_str, str_field};
+
+pub fn dispatch(
+ command: &str,
+ args: Value,
+ adapter: &dyn agent_desktop_core::adapter::PlatformAdapter,
+) -> Result<Value, AppError> {
+ match command {
+ "launch" => launch::execute(
+ launch::LaunchArgs {
+ app: req_str(&args, "app")?,
+ timeout_ms: args
+ .get("timeout")
+ .and_then(|v| v.as_u64())
+ .unwrap_or(30000),
+ },
+ adapter,
+ ),
+
+ "close-app" => close_app::execute(
+ close_app::CloseAppArgs {
+ app: req_str(&args, "app")?,
+ force: args.get("force").and_then(|v| v.as_bool()).unwrap_or(false),
+ },
+ adapter,
+ ),
+
+ "list-windows" => list_windows::execute(
+ list_windows::ListWindowsArgs {
+ app: str_field(&args, "app"),
+ },
+ adapter,
+ ),
+
+ "list-apps" => list_apps::execute(adapter),
+
+ "focus-window" => focus_window::execute(
+ focus_window::FocusWindowArgs {
+ window_id: str_field(&args, "window_id"),
+ app: str_field(&args, "app"),
+ title: str_field(&args, "title"),
+ },
+ adapter,
+ ),
+
+ "resize-window" => resize_window::execute(
+ resize_window::ResizeWindowArgs {
+ app: str_field(&args, "app"),
+ width: args.get("width").and_then(|v| v.as_f64()).unwrap_or(800.0),
+ height: args.get("height").and_then(|v| v.as_f64()).unwrap_or(600.0),
+ },
+ adapter,
+ ),
+
+ "move-window" => move_window::execute(
+ move_window::MoveWindowArgs {
+ app: str_field(&args, "app"),
+ x: args.get("x").and_then(|v| v.as_f64()).unwrap_or(0.0),
+ y: args.get("y").and_then(|v| v.as_f64()).unwrap_or(0.0),
+ },
+ adapter,
+ ),
+
+ "minimize" => minimize::execute(
+ minimize::MinimizeArgs {
+ app: str_field(&args, "app"),
+ },
+ adapter,
+ ),
+
+ "maximize" => maximize::execute(
+ maximize::MaximizeArgs {
+ app: str_field(&args, "app"),
+ },
+ adapter,
+ ),
+
+ "restore" => restore::execute(
+ restore::RestoreArgs {
+ app: str_field(&args, "app"),
+ },
+ adapter,
+ ),
+
+ "list-notifications" => list_notifications::execute(
+ list_notifications::ListNotificationsArgs {
+ app: str_field(&args, "app"),
+ text: str_field(&args, "text"),
+ limit: args
+ .get("limit")
+ .and_then(|v| v.as_u64())
+ .map(|v| v as usize),
+ },
+ adapter,
+ ),
+
+ "dismiss-notification" => {
+ let index = args
+ .get("index")
+ .and_then(|v| v.as_u64())
+ .map(|v| v as usize)
+ .ok_or_else(|| AppError::invalid_input("Batch: missing required field 'index'"))?;
+ if index == 0 {
+ return Err(AppError::invalid_input("Index must be >= 1"));
+ }
+ dismiss_notification::execute(
+ dismiss_notification::DismissNotificationArgs {
+ index,
+ app: str_field(&args, "app"),
+ },
+ adapter,
+ )
+ }
+
+ "dismiss-all-notifications" => dismiss_all_notifications::execute(
+ dismiss_all_notifications::DismissAllNotificationsArgs {
+ app: str_field(&args, "app"),
+ },
+ adapter,
+ ),
+
+ "notification-action" => {
+ let index = args
+ .get("index")
+ .and_then(|v| v.as_u64())
+ .map(|v| v as usize)
+ .ok_or_else(|| AppError::invalid_input("Batch: missing required field 'index'"))?;
+ if index == 0 {
+ return Err(AppError::invalid_input("Index must be >= 1"));
+ }
+ notification_action::execute(
+ notification_action::NotificationActionArgs {
+ index,
+ action: req_str(&args, "action")?,
+ },
+ adapter,
+ )
+ }
+
+ "clipboard-get" => clipboard_get::execute(adapter),
+ "clipboard-set" => clipboard_set::execute(req_str(&args, "text")?, adapter),
+ "clipboard-clear" => clipboard_clear::execute(adapter),
+
+ "wait" => wait::execute(
+ wait::WaitArgs {
+ ms: args.get("ms").and_then(|v| v.as_u64()),
+ element: str_field(&args, "element"),
+ window: str_field(&args, "window"),
+ text: str_field(&args, "text"),
+ 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),
+ notification: args
+ .get("notification")
+ .and_then(|v| v.as_bool())
+ .unwrap_or(false),
+ poll_interval_ms: args
+ .get("poll_interval_ms")
+ .and_then(|v| v.as_u64())
+ .unwrap_or(3000),
+ 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(
+ permissions::PermissionsArgs {
+ request: args
+ .get("request")
+ .and_then(|v| v.as_bool())
+ .unwrap_or(false),
+ },
+ adapter,
+ ),
+
+ "version" => version::execute(version::VersionArgs {
+ json: args.get("json").and_then(|v| v.as_bool()).unwrap_or(false),
+ }),
+
+ other => Err(AppError::invalid_input(format!(
+ "Unknown batch command '{other}'"
+ ))),
+ }
+}
diff --git a/src/cli.rs b/src/cli.rs
index 0e6e4a431..afce33841 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -59,6 +59,12 @@ APP & WINDOW
maximize Maximize/zoom window
restore Restore minimized/maximized window
+NOTIFICATIONS
+ list-notifications List notifications from Notification Center
+ dismiss-notification <n> Dismiss notification by index
+ dismiss-all-notifications Dismiss all notifications
+ notification-action <n> <action> Click action button on notification
+
CLIPBOARD
clipboard-get Read plain-text clipboard
clipboard-set <text> Write text to clipboard
@@ -69,6 +75,7 @@ WAIT
wait --element <ref> Block until element appears (--timeout ms)
wait --window <title> Block until window appears
wait --text <text> Block until text appears in app
+ wait --notification Block until a new notification arrives
SYSTEM
status Adapter health, platform, and permission state
@@ -201,6 +208,14 @@ pub enum Commands {
Restore(AppRefArgs),
#[command(about = "List accessibility surfaces for an app (window, menu, sheet ...)")]
ListSurfaces(ListSurfacesArgs),
+ #[command(about = "List notifications from Notification Center")]
+ ListNotifications(ListNotificationsArgs),
+ #[command(about = "Dismiss a notification by index")]
+ DismissNotification(DismissNotificationCliArgs),
+ #[command(about = "Dismiss all notifications (--app to filter)")]
+ DismissAllNotifications(DismissAllNotificationsArgs),
+ #[command(about = "Click an action button on a notification")]
+ NotificationAction(NotificationActionCliArgs),
#[command(about = "Read plain-text clipboard contents")]
ClipboardGet,
#[command(about = "Write text to the clipboard")]
@@ -263,6 +278,10 @@ impl Commands {
Self::Maximize(_) => "maximize",
Self::Restore(_) => "restore",
Self::ListSurfaces(_) => "list-surfaces",
+ Self::ListNotifications(_) => "list-notifications",
+ Self::DismissNotification(_) => "dismiss-notification",
+ Self::DismissAllNotifications(_) => "dismiss-all-notifications",
+ Self::NotificationAction(_) => "notification-action",
Self::ClipboardGet => "clipboard-get",
Self::ClipboardSet(_) => "clipboard-set",
Self::ClipboardClear => "clipboard-clear",
diff --git a/src/cli_args.rs b/src/cli_args.rs
index 2048a7351..08cb8ba3f 100644
--- a/src/cli_args.rs
+++ b/src/cli_args.rs
@@ -298,6 +298,43 @@ pub struct AppRefArgs {
pub app: Option<String>,
}
+#[derive(Parser, Debug)]
+pub struct ListNotificationsArgs {
+ #[arg(long, help = "Filter to notifications from this app")]
+ pub app: Option<String>,
+ #[arg(long, help = "Filter to notifications containing this text")]
+ pub text: Option<String>,
+ #[arg(long, help = "Maximum number of notifications to return")]
+ pub limit: Option<usize>,
+}
+
+#[derive(Parser, Debug)]
+pub struct DismissNotificationCliArgs {
+ #[arg(value_name = "INDEX", help = "1-based notification index from list-notifications",
+ value_parser = clap::value_parser!(u64).range(1..))]
+ pub index: u64,
+ #[arg(long, help = "Filter notifications by app before selecting index")]
+ pub app: Option<String>,
+}
+
+#[derive(Parser, Debug)]
+pub struct DismissAllNotificationsArgs {
+ #[arg(long, help = "Only dismiss notifications from this app")]
+ pub app: Option<String>,
+}
+
+#[derive(Parser, Debug)]
+pub struct NotificationActionCliArgs {
+ #[arg(value_name = "INDEX", help = "1-based notification index from list-notifications",
+ value_parser = clap::value_parser!(u64).range(1..))]
+ pub index: u64,
+ #[arg(
+ value_name = "ACTION",
+ help = "Name of the action button to click (e.g., Reply, Open)"
+ )]
+ pub action: String,
+}
+
#[derive(Parser, Debug)]
pub struct ClipboardSetArgs {
#[arg(value_name = "TEXT", help = "Text to write to the clipboard")]
@@ -327,6 +364,14 @@ pub struct WaitArgs {
pub menu: bool,
#[arg(long, help = "Block until the context menu is dismissed")]
pub menu_closed: bool,
+ #[arg(long, help = "Block until a new notification arrives")]
+ pub notification: bool,
+ #[arg(
+ long,
+ help = "Poll interval in ms for notification wait",
+ default_value = "3000"
+ )]
+ pub poll_interval: u64,
#[arg(long, help = "Scope element, window, or text wait to this application")]
pub app: Option<String>,
}
diff --git a/src/dispatch.rs b/src/dispatch.rs
index c04cd5d4f..4e098de61 100644
--- a/src/dispatch.rs
+++ b/src/dispatch.rs
@@ -3,11 +3,13 @@ use agent_desktop_core::{
adapter::PlatformAdapter,
commands::{
batch, check, clear, click, clipboard_clear, clipboard_get, clipboard_set, close_app,
- collapse, double_click, drag, expand, find, focus, focus_window, get, helpers, hover,
- is_check, key_down, key_up, launch, list_apps, list_surfaces, list_windows, maximize,
- minimize, mouse_click, mouse_down, mouse_move, mouse_up, move_window, permissions, press,
- resize_window, restore, right_click, screenshot, scroll, scroll_to, select, set_value,
- snapshot, status, toggle, triple_click, type_text, uncheck, version, wait,
+ collapse, dismiss_all_notifications, dismiss_notification, double_click, drag, expand,
+ find, focus, focus_window, get, helpers, hover, is_check, key_down, key_up, launch,
+ list_apps, list_notifications, list_surfaces, list_windows, maximize, minimize,
+ mouse_click, mouse_down, mouse_move, mouse_up, move_window, notification_action,
+ permissions, press, resize_window, restore, right_click, screenshot, scroll, scroll_to,
+ select, set_value, snapshot, status, toggle, triple_click, type_text, uncheck, version,
+ wait,
},
error::AppError,
};
@@ -265,6 +267,36 @@ pub fn dispatch(cmd: Commands, adapter: &dyn PlatformAdapter) -> Result<Value, A
Commands::Restore(a) => restore::execute(restore::RestoreArgs { app: a.app }, adapter),
+ Commands::ListNotifications(a) => list_notifications::execute(
+ list_notifications::ListNotificationsArgs {
+ app: a.app,
+ text: a.text,
+ limit: a.limit,
+ },
+ adapter,
+ ),
+
+ Commands::DismissNotification(a) => dismiss_notification::execute(
+ dismiss_notification::DismissNotificationArgs {
+ index: a.index as usize,
+ app: a.app,
+ },
+ adapter,
+ ),
+
+ Commands::DismissAllNotifications(a) => dismiss_all_notifications::execute(
+ dismiss_all_notifications::DismissAllNotificationsArgs { app: a.app },
+ adapter,
+ ),
+
+ Commands::NotificationAction(a) => notification_action::execute(
+ notification_action::NotificationActionArgs {
+ index: a.index as usize,
+ action: a.action,
+ },
+ adapter,
+ ),
+
Commands::ClipboardGet => clipboard_get::execute(adapter),
Commands::ClipboardSet(a) => clipboard_set::execute(a.text, adapter),
Commands::ClipboardClear => clipboard_clear::execute(adapter),
@@ -278,6 +310,8 @@ pub fn dispatch(cmd: Commands, adapter: &dyn PlatformAdapter) -> Result<Value, A
timeout_ms: a.timeout,
menu: a.menu,
menu_closed: a.menu_closed,
+ notification: a.notification,
+ poll_interval_ms: a.poll_interval,
app: a.app,
},
adapter,
diff --git a/src/main.rs b/src/main.rs
index e0543a894..50e8a543b 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,4 +1,5 @@
mod batch_dispatch;
+mod batch_dispatch_ext;
mod cli;
mod cli_args;
mod dispatch;