Skip to content

Computer use CLI for AI agents

refactor: resolve code review findings from notification PR

Lahfir8aa672c668a4
diff --git a/crates/core/src/adapter.rs b/crates/core/src/adapter.rs
index 5501a3cf0..af3732d0c 100644
--- a/crates/core/src/adapter.rs
+++ b/crates/core/src/adapter.rs
@@ -230,6 +230,13 @@ pub trait PlatformAdapter: Send + Sync {
Err(AdapterError::not_supported("dismiss_notification"))
}
+ fn dismiss_all_notifications(
+ &self,
+ _app_filter: Option<&str>,
+ ) -> Result<(Vec<NotificationInfo>, Vec<String>), AdapterError> {
+ Err(AdapterError::not_supported("dismiss_all_notifications"))
+ }
+
fn notification_action(
&self,
_index: usize,
diff --git a/crates/core/src/commands/dismiss_all_notifications.rs b/crates/core/src/commands/dismiss_all_notifications.rs
index 5e1380266..06a3b894b 100644
--- a/crates/core/src/commands/dismiss_all_notifications.rs
+++ b/crates/core/src/commands/dismiss_all_notifications.rs
@@ -1,4 +1,4 @@
-use crate::{adapter::PlatformAdapter, error::AppError, notification::NotificationFilter};
+use crate::{adapter::PlatformAdapter, error::AppError};
use serde_json::{json, Value};
pub struct DismissAllNotificationsArgs {
@@ -9,21 +9,13 @@ 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;
- }
+ let (dismissed, failures) = adapter.dismiss_all_notifications(args.app.as_deref())?;
+ let mut result = json!({
+ "dismissed_count": dismissed.len(),
+ });
+ if !failures.is_empty() {
+ result["failures"] = json!(failures);
+ result["failed_count"] = json!(failures.len());
}
- Ok(json!({
- "dismissed_count": dismissed,
- }))
+ Ok(result)
}
diff --git a/crates/core/src/commands/wait.rs b/crates/core/src/commands/wait.rs
index d74a41c9f..816b9d2eb 100644
--- a/crates/core/src/commands/wait.rs
+++ b/crates/core/src/commands/wait.rs
@@ -19,7 +19,6 @@ pub struct WaitArgs {
pub menu: bool,
pub menu_closed: bool,
pub notification: bool,
- pub poll_interval_ms: u64,
pub app: Option<String>,
}
@@ -165,32 +164,38 @@ fn wait_for_notification(
) -> Result<Value, AppError> {
let filter = NotificationFilter {
app: args.app.clone(),
- text: None,
+ text: args.text.clone(),
..Default::default()
};
let baseline = adapter.list_notifications(&filter)?;
- let baseline_count = baseline.len();
- let interval = Duration::from_millis(args.poll_interval_ms);
+ let baseline_indices: std::collections::HashSet<usize> =
+ baseline.iter().map(|n| n.index).collect();
+ let interval = Duration::from_millis(500);
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,
- }));
+ let new_notif = current
+ .iter()
+ .find(|n| !baseline_indices.contains(&n.index));
+ if let Some(notif) = new_notif.or(current.last()) {
+ if current.len() > baseline_indices.len() {
+ let elapsed = start.elapsed().as_millis();
+ return Ok(json!({
+ "condition": "notification",
+ "matched": true,
+ "notification": notif,
+ "elapsed_ms": elapsed,
+ }));
+ }
}
+ std::thread::sleep(interval);
}
}
diff --git a/crates/core/src/notification.rs b/crates/core/src/notification.rs
index 140f12a81..adfb4249b 100644
--- a/crates/core/src/notification.rs
+++ b/crates/core/src/notification.rs
@@ -7,8 +7,6 @@ pub struct NotificationInfo {
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>,
}
@@ -31,12 +29,10 @@ mod tests {
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"));
}
@@ -47,12 +43,10 @@ mod tests {
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"]));
}
diff --git a/crates/macos/src/adapter.rs b/crates/macos/src/adapter.rs
index adbd67a93..adddc6448 100644
--- a/crates/macos/src/adapter.rs
+++ b/crates/macos/src/adapter.rs
@@ -191,6 +191,13 @@ impl PlatformAdapter for MacOSAdapter {
crate::notifications::actions::dismiss_notification(index, app_filter)
}
+ fn dismiss_all_notifications(
+ &self,
+ app_filter: Option<&str>,
+ ) -> Result<(Vec<NotificationInfo>, Vec<String>), AdapterError> {
+ crate::notifications::actions::dismiss_all(app_filter)
+ }
+
fn notification_action(
&self,
index: usize,
diff --git a/crates/macos/src/notifications/actions.rs b/crates/macos/src/notifications/actions.rs
index 64a736224..a43b210a2 100644
--- a/crates/macos/src/notifications/actions.rs
+++ b/crates/macos/src/notifications/actions.rs
@@ -4,7 +4,7 @@ use agent_desktop_core::{
notification::{NotificationFilter, NotificationInfo},
};
-use super::NcSession;
+use super::nc_session::NcSession;
pub fn dismiss_notification(
index: usize,
@@ -16,6 +16,15 @@ pub fn dismiss_notification(
result
}
+pub fn dismiss_all(
+ app_filter: Option<&str>,
+) -> Result<(Vec<NotificationInfo>, Vec<String>), AdapterError> {
+ let session = NcSession::open()?;
+ let result = dismiss_all_impl(app_filter);
+ session.close()?;
+ result
+}
+
pub fn notification_action(index: usize, action_name: &str) -> Result<ActionResult, AdapterError> {
let session = NcSession::open()?;
let result = action_impl(index, action_name);
@@ -25,10 +34,6 @@ pub fn notification_action(index: usize, action_name: &str) -> Result<ActionResu
#[cfg(target_os = "macos")]
fn dismiss_impl(index: usize, app_filter: Option<&str>) -> Result<NotificationInfo, AdapterError> {
- use crate::actions::ax_helpers::{list_ax_actions, try_action_from_list, try_ax_action};
- use crate::tree::copy_ax_array;
- use accessibility_sys::kAXChildrenAttribute;
-
let filter = build_filter(app_filter);
let entries = super::list::list_entries(&filter)?;
@@ -38,40 +43,66 @@ fn dismiss_impl(index: usize, app_filter: Option<&str>) -> Result<NotificationIn
.ok_or_else(|| AdapterError::notification_not_found(index))?;
let info = entry.info;
+ dismiss_entry(&entry.element)?;
+ Ok(info)
+}
+
+#[cfg(target_os = "macos")]
+fn dismiss_all_impl(
+ app_filter: Option<&str>,
+) -> Result<(Vec<NotificationInfo>, Vec<String>), AdapterError> {
+ let filter = build_filter(app_filter);
+ let entries = super::list::list_entries(&filter)?;
+
+ let mut dismissed = Vec::new();
+ let mut failures = Vec::new();
+
+ for entry in entries.into_iter().rev() {
+ match dismiss_entry(&entry.element) {
+ Ok(()) => dismissed.push(entry.info),
+ Err(e) => failures.push(format!("#{}: {}", entry.info.index, e)),
+ }
+ }
+
+ Ok((dismissed, failures))
+}
+
+#[cfg(target_os = "macos")]
+fn dismiss_entry(element: &crate::tree::AXElement) -> Result<(), AdapterError> {
+ use crate::actions::ax_helpers::{list_ax_actions, try_action_from_list, try_ax_action};
+ use crate::tree::copy_ax_array;
+ use accessibility_sys::kAXChildrenAttribute;
- // Headless first: try AX actions directly on the notification group
- let actions = list_ax_actions(&entry.element);
+ let actions = list_ax_actions(element);
if try_action_from_list(
- &entry.element,
+ element,
&actions,
&["AXDismiss", "AXRemoveFromParent", "AXPress"],
) {
- return Ok(info);
+ return Ok(());
}
- // Headless: look for close/clear/dismiss button without hovering
- let children = copy_ax_array(&entry.element, kAXChildrenAttribute).unwrap_or_default();
+ let children = copy_ax_array(element, kAXChildrenAttribute).unwrap_or_default();
if try_dismiss_button(&children) {
- return Ok(info);
+ return Ok(());
}
- // Last resort: hover to reveal hidden close button, then try again
- hover_over(&entry.element)?;
+ hover_over(element)?;
std::thread::sleep(std::time::Duration::from_millis(200));
- let children = copy_ax_array(&entry.element, kAXChildrenAttribute).unwrap_or_default();
+ let children = copy_ax_array(element, kAXChildrenAttribute).unwrap_or_default();
if try_dismiss_button(&children) {
- return Ok(info);
+ return Ok(());
}
- if !try_ax_action(&entry.element, "AXPress") {
- return Err(AdapterError::new(
- ErrorCode::ActionFailed,
- "All dismiss strategies failed (AX actions, close button, hover+close, AXPress)",
- ));
+ if try_ax_action(element, "AXPress") {
+ return Ok(());
}
- Ok(info)
+ Err(AdapterError::new(
+ ErrorCode::ActionFailed,
+ "All dismiss strategies failed (AX actions, close button, hover+close, AXPress)",
+ ))
}
#[cfg(target_os = "macos")]
@@ -175,6 +206,13 @@ fn dismiss_impl(
Err(AdapterError::not_supported("dismiss_notification"))
}
+#[cfg(not(target_os = "macos"))]
+fn dismiss_all_impl(
+ _app_filter: Option<&str>,
+) -> Result<(Vec<NotificationInfo>, Vec<String>), AdapterError> {
+ Err(AdapterError::not_supported("dismiss_all_notifications"))
+}
+
#[cfg(not(target_os = "macos"))]
fn action_impl(_index: usize, _action_name: &str) -> Result<ActionResult, AdapterError> {
Err(AdapterError::not_supported("notification_action"))
diff --git a/crates/macos/src/notifications/list.rs b/crates/macos/src/notifications/list.rs
index ae1b6e42b..5dc5275a6 100644
--- a/crates/macos/src/notifications/list.rs
+++ b/crates/macos/src/notifications/list.rs
@@ -3,7 +3,7 @@ use agent_desktop_core::{
notification::{NotificationFilter, NotificationInfo},
};
-use super::NcSession;
+use super::nc_session::NcSession;
pub fn list_notifications(
filter: &NotificationFilter,
@@ -126,13 +126,12 @@ fn is_notification_group(role: Option<&str>, children: &[crate::tree::AXElement]
if role != Some("AXGroup") {
return false;
}
- let has_static_text = children
- .iter()
- .any(|c| copy_string_attr(c, kAXRoleAttribute).as_deref() == Some("AXStaticText"));
- let has_button = children
- .iter()
- .any(|c| copy_string_attr(c, kAXRoleAttribute).as_deref() == Some("AXButton"));
- has_static_text || has_button
+ children.iter().any(|c| {
+ matches!(
+ copy_string_attr(c, kAXRoleAttribute).as_deref(),
+ Some("AXStaticText") | Some("AXButton")
+ )
+ })
}
#[cfg(target_os = "macos")]
@@ -197,7 +196,6 @@ fn extract_notification(
app_name,
title,
body,
- timestamp: None,
actions,
})
}
@@ -242,7 +240,6 @@ mod tests {
app_name: app.into(),
title: title.into(),
body: body.map(String::from),
- timestamp: None,
actions: vec![],
}
}
diff --git a/crates/macos/src/notifications/mod.rs b/crates/macos/src/notifications/mod.rs
index da071276e..f0b4ebb52 100644
--- a/crates/macos/src/notifications/mod.rs
+++ b/crates/macos/src/notifications/mod.rs
@@ -1,5 +1,3 @@
pub mod actions;
pub mod list;
pub mod nc_session;
-
-pub use nc_session::NcSession;
diff --git a/crates/macos/src/notifications/nc_session.rs b/crates/macos/src/notifications/nc_session.rs
index ecf36e4b7..80f517c10 100644
--- a/crates/macos/src/notifications/nc_session.rs
+++ b/crates/macos/src/notifications/nc_session.rs
@@ -1,11 +1,11 @@
use agent_desktop_core::error::AdapterError;
-pub struct NcSession {
+pub(crate) struct NcSession {
was_already_open: bool,
}
impl NcSession {
- pub fn open() -> Result<Self, AdapterError> {
+ pub(crate) fn open() -> Result<Self, AdapterError> {
let was_already_open = is_nc_open();
if !was_already_open {
open_nc()?;
@@ -14,7 +14,7 @@ impl NcSession {
Ok(Self { was_already_open })
}
- pub fn close(self) -> Result<(), AdapterError> {
+ pub(crate) fn close(self) -> Result<(), AdapterError> {
if !self.was_already_open {
close_nc()?;
}
@@ -35,7 +35,7 @@ impl Drop for NcSession {
#[cfg(target_os = "macos")]
pub(super) fn nc_pid() -> Option<i32> {
- let output = std::process::Command::new("pgrep")
+ let output = std::process::Command::new("/usr/bin/pgrep")
.arg("-x")
.arg("NotificationCenter")
.output()
@@ -72,7 +72,7 @@ fn open_nc() -> Result<(), AdapterError> {
click (first menu bar item of menu bar 1 whose description is "Clock")
end tell"#;
- let mut child = std::process::Command::new("osascript")
+ let mut child = std::process::Command::new("/usr/bin/osascript")
.arg("-e")
.arg(script)
.stdout(std::process::Stdio::null())
@@ -81,7 +81,21 @@ fn open_nc() -> Result<(), AdapterError> {
.map_err(|e| AdapterError::internal(format!("Failed to spawn osascript: {e}")))?;
std::thread::sleep(std::time::Duration::from_millis(500));
- let _ = child.try_wait();
+ let deadline = std::time::Instant::now() + std::time::Duration::from_secs(2);
+ loop {
+ match child.try_wait() {
+ Ok(Some(_)) => break,
+ Ok(None) => {
+ if std::time::Instant::now() > deadline {
+ let _ = child.kill();
+ let _ = child.wait();
+ break;
+ }
+ std::thread::sleep(std::time::Duration::from_millis(50));
+ }
+ Err(_) => break,
+ }
+ }
Ok(())
}
diff --git a/docs/phases.md b/docs/phases.md
index 9290675f4..895991bd7 100644
--- a/docs/phases.md
+++ b/docs/phases.md
@@ -215,16 +215,16 @@ RefMap persisted at `~/.agent-desktop/last_refmap.json` with `0o600` permissions
### New Commands — Notification & System Tray (Post Phase 1)
-> **Note:** Notification management and system tray interaction were not part of the original Phase 1 delivery. These are **new features to be implemented across all platforms** as each platform adapter is built. The macOS implementations should be added first as a follow-up to Phase 1, then Windows (Phase 2) and Linux (Phase 3) implementations follow the same pattern.
+> **Note:** Notification management and system tray interaction were not part of the original Phase 1 delivery. These are **new features to be implemented across all platforms** as each platform adapter is built. The macOS implementations were added as a follow-up to Phase 1. Windows (Phase 2) and Linux (Phase 3) implementations follow the same pattern.
-#### Notification Commands (New — Not Yet Implemented)
+#### Notification Commands (macOS — Completed)
-| Command | Description | Flags |
-|---------|-------------|-------|
-| `list-notifications` | List current notifications with app, title, body, timestamp, and available actions | `--app` (filter by app), `--limit` (max results) |
-| `dismiss-notification` | Dismiss a specific notification by ID | `<notification-id>` |
-| `dismiss-all-notifications` | Clear all notifications, optionally filtered by app | `--app` (filter by app) |
-| `notification-action` | Click an action button on a specific notification | `<notification-id> <action-name>` |
+| Command | Description | Flags | Status |
+|---------|-------------|-------|--------|
+| `list-notifications` | List current notifications with app, title, body, and available actions | `--app` (filter by app), `--text` (filter by text), `--limit` (max results) | **Completed** |
+| `dismiss-notification` | Dismiss a specific notification by 1-based index | `<index>`, `--app` (filter by app) | **Completed** |
+| `dismiss-all-notifications` | Clear all notifications, optionally filtered by app (single NC session, reports failures) | `--app` (filter by app) | **Completed** |
+| `notification-action` | Click an action button on a specific notification | `<index> <action-name>` | **Completed** |
#### System Tray / Status Area Commands (New — Not Yet Implemented)
@@ -234,12 +234,13 @@ RefMap persisted at `~/.agent-desktop/last_refmap.json` with `0o600` permissions
| `click-tray-item` | Click a system tray item by ID or app name | `<tray-item-id>` |
| `open-tray-menu` | Click a tray item and snapshot its resulting menu for ref-based interaction | `<tray-item-id>` |
-#### Wait Command Update (Not Yet Implemented)
+#### Wait Command Update (Notification — Completed, Menu — Completed)
-The existing `wait` command should be extended with a `--notification` flag:
-- `wait --notification` — Wait for any notification to appear
+The `wait` command has been extended with notification and menu support:
+- `wait --notification` — Wait for any new notification to appear (index-diff based detection)
- `wait --notification --app Safari` — Wait for a notification from a specific app
- `wait --notification --text "Download complete"` — Wait for a notification containing specific text
+- `wait --menu` / `wait --menu-closed` — Wait for context menu open/close
### Commands Shipped (57)
@@ -467,7 +468,7 @@ crates/windows/src/
### Notification Management (New Feature — Windows Implementation)
-Windows notification management must be implemented from scratch as part of Phase 2. This is a new feature, not a port of existing macOS code (macOS notification support is also new and added as a follow-up to Phase 1).
+Windows notification management must be implemented from scratch as part of Phase 2. The macOS notification implementation (completed as a follow-up to Phase 1) serves as the reference pattern — same `PlatformAdapter` trait methods (`list_notifications`, `dismiss_notification`, `dismiss_all_notifications`, `notification_action`), same JSON output contract, same 1-based indexing.
**Implementation approach:**
- **List notifications:** Open Action Center via UIA (`Windows.UI.Notifications`). Traverse the notification list — each toast is a UIA element with `Name` (title), `FullDescription` (body), app info, and child action buttons
@@ -673,7 +674,7 @@ crates/linux/src/
### Notification Management (New Feature — Linux Implementation)
-Linux notification management must be implemented from scratch as part of Phase 3. This is a new feature across all platforms.
+Linux notification management must be implemented from scratch as part of Phase 3. The macOS implementation (completed) and Windows implementation (Phase 2) serve as reference patterns — same trait methods, same JSON output contract, same 1-based indexing.
**Implementation approach:**
- **List notifications:** The standard `org.freedesktop.Notifications` D-Bus interface does NOT provide a "list current notifications" method. Approach varies by desktop environment:
diff --git a/src/batch_dispatch_ext.rs b/src/batch_dispatch_ext.rs
index 985e2db35..32af51c00 100644
--- a/src/batch_dispatch_ext.rs
+++ b/src/batch_dispatch_ext.rs
@@ -171,10 +171,6 @@ pub fn dispatch(
.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,
diff --git a/src/cli.rs b/src/cli.rs
index afce33841..5b6f17963 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -1,6 +1,7 @@
use clap::{Parser, Subcommand};
pub use crate::cli_args::*;
+pub use crate::cli_args_notifications::*;
#[derive(Parser, Debug)]
#[command(
@@ -209,11 +210,11 @@ pub enum Commands {
#[command(about = "List accessibility surfaces for an app (window, menu, sheet ...)")]
ListSurfaces(ListSurfacesArgs),
#[command(about = "List notifications from Notification Center")]
- ListNotifications(ListNotificationsArgs),
+ ListNotifications(ListNotificationsCliArgs),
#[command(about = "Dismiss a notification by index")]
DismissNotification(DismissNotificationCliArgs),
#[command(about = "Dismiss all notifications (--app to filter)")]
- DismissAllNotifications(DismissAllNotificationsArgs),
+ DismissAllNotifications(DismissAllNotificationsCliArgs),
#[command(about = "Click an action button on a notification")]
NotificationAction(NotificationActionCliArgs),
#[command(about = "Read plain-text clipboard contents")]
diff --git a/src/cli_args.rs b/src/cli_args.rs
index 08cb8ba3f..5ad2192fb 100644
--- a/src/cli_args.rs
+++ b/src/cli_args.rs
@@ -298,43 +298,6 @@ 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")]
@@ -366,12 +329,6 @@ pub struct WaitArgs {
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/cli_args_notifications.rs b/src/cli_args_notifications.rs
new file mode 100644
index 000000000..8e9c19d29
--- /dev/null
+++ b/src/cli_args_notifications.rs
@@ -0,0 +1,38 @@
+use clap::Parser;
+
+#[derive(Parser, Debug)]
+pub struct ListNotificationsCliArgs {
+ #[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 DismissAllNotificationsCliArgs {
+ #[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,
+}
diff --git a/src/dispatch.rs b/src/dispatch.rs
index 4e098de61..7b34c8409 100644
--- a/src/dispatch.rs
+++ b/src/dispatch.rs
@@ -3,13 +3,11 @@ use agent_desktop_core::{
adapter::PlatformAdapter,
commands::{
batch, check, clear, click, clipboard_clear, clipboard_get, clipboard_set, close_app,
- 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,
+ 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,
},
error::AppError,
};
@@ -267,35 +265,12 @@ 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::ListNotifications(_)
+ | Commands::DismissNotification(_)
+ | Commands::DismissAllNotifications(_)
+ | Commands::NotificationAction(_) => {
+ crate::dispatch_notifications::dispatch_notification(cmd, adapter)
+ }
Commands::ClipboardGet => clipboard_get::execute(adapter),
Commands::ClipboardSet(a) => clipboard_set::execute(a.text, adapter),
@@ -311,7 +286,6 @@ pub fn dispatch(cmd: Commands, adapter: &dyn PlatformAdapter) -> Result<Value, A
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/dispatch_notifications.rs b/src/dispatch_notifications.rs
new file mode 100644
index 000000000..704df7ec0
--- /dev/null
+++ b/src/dispatch_notifications.rs
@@ -0,0 +1,45 @@
+use agent_desktop_core::{
+ adapter::PlatformAdapter,
+ commands::{
+ dismiss_all_notifications, dismiss_notification, list_notifications, notification_action,
+ },
+ error::AppError,
+};
+use serde_json::Value;
+
+use crate::cli::Commands;
+
+pub fn dispatch_notification(
+ cmd: Commands,
+ adapter: &dyn PlatformAdapter,
+) -> Result<Value, AppError> {
+ match cmd {
+ 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,
+ ),
+ _ => unreachable!(),
+ }
+}
diff --git a/src/main.rs b/src/main.rs
index 50e8a543b..d38061071 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -2,7 +2,9 @@ mod batch_dispatch;
mod batch_dispatch_ext;
mod cli;
mod cli_args;
+mod cli_args_notifications;
mod dispatch;
+mod dispatch_notifications;
use agent_desktop_core::adapter::PlatformAdapter;
use clap::{CommandFactory, Parser};