Skip to content

Computer use CLI for AI agents

refactor!: over-engineering audit cleanup (#64)

Lahfirdbb2be639ecc
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 8f7538ce2..43887e66d 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -126,7 +126,7 @@ jobs:
trap 'rm -f "npm/bin/${NAME}"' EXIT
cp target/ci/agent-desktop "npm/bin/${NAME}"
chmod +x "npm/bin/${NAME}"
- node npm/bin/agent-desktop.js version --json > /tmp/agent-desktop-version.json
+ node npm/bin/agent-desktop.js version > /tmp/agent-desktop-version.json
node -e "
const out = require('fs').readFileSync('/tmp/agent-desktop-version.json', 'utf8');
const json = JSON.parse(out);
diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml
index 45dd81d3c..053f2f09c 100644
--- a/crates/core/Cargo.toml
+++ b/crates/core/Cargo.toml
@@ -3,6 +3,7 @@ name = "agent-desktop-core"
version.workspace = true
edition.workspace = true
license.workspace = true
+publish = false
[dependencies]
serde.workspace = true
diff --git a/crates/core/src/commands/batch.rs b/crates/core/src/commands/batch.rs
index 3a792ece6..080d08789 100644
--- a/crates/core/src/commands/batch.rs
+++ b/crates/core/src/commands/batch.rs
@@ -2,11 +2,6 @@ use crate::error::AppError;
use serde::Deserialize;
use serde_json::Value;
-pub struct BatchArgs {
- pub commands_json: String,
- pub stop_on_error: bool,
-}
-
#[derive(Debug, Deserialize)]
pub struct BatchCommand {
pub command: String,
diff --git a/crates/core/src/commands/helpers.rs b/crates/core/src/commands/helpers.rs
index ee675fdb1..aba02ca47 100644
--- a/crates/core/src/commands/helpers.rs
+++ b/crates/core/src/commands/helpers.rs
@@ -157,7 +157,7 @@ pub(crate) fn window_op_command(
response_key: &'static str,
) -> Result<Value, AppError> {
let pid = resolve_app_pid(args.app.as_deref(), adapter)?;
- let win = match find_window_for_pid(pid, adapter) {
+ let win = match window_lookup::find_window_for_pid(pid, adapter) {
Ok(win) => win,
Err(_) if matches!(op, WindowOp::Restore) => WindowInfo {
id: String::new(),
@@ -173,19 +173,12 @@ pub(crate) fn window_op_command(
Ok(json!({ response_key: true }))
}
-pub(crate) fn find_window_for_pid(
- pid: i32,
- adapter: &dyn PlatformAdapter,
-) -> Result<WindowInfo, AppError> {
- window_lookup::find_window_for_pid(pid, adapter)
-}
-
pub(crate) fn resolve_window_for_app(
app: Option<&str>,
adapter: &dyn PlatformAdapter,
) -> Result<WindowInfo, AppError> {
let pid = resolve_app_pid(app, adapter)?;
- find_window_for_pid(pid, adapter)
+ window_lookup::find_window_for_pid(pid, adapter)
}
#[cfg(test)]
diff --git a/crates/core/src/commands/permissions.rs b/crates/core/src/commands/permissions.rs
index 4bfd2d2dc..07f572b3f 100644
--- a/crates/core/src/commands/permissions.rs
+++ b/crates/core/src/commands/permissions.rs
@@ -15,13 +15,9 @@ pub fn execute_with_report(
} else {
report.clone()
};
- Ok(render(report))
-}
-
-fn render(report: PermissionReport) -> Value {
- json!({
+ Ok(json!({
"accessibility": report.accessibility,
"screen_recording": report.screen_recording,
"automation": report.automation
- })
+ }))
}
diff --git a/crates/core/src/commands/right_click.rs b/crates/core/src/commands/right_click.rs
index 10abf77ed..802cebf34 100644
--- a/crates/core/src/commands/right_click.rs
+++ b/crates/core/src/commands/right_click.rs
@@ -1,7 +1,7 @@
use crate::{
action::Action,
adapter::{PlatformAdapter, SnapshotSurface, TreeOptions},
- commands::helpers::{RefArgs, execute_ref_action_result_with_context, find_window_for_pid},
+ commands::helpers::{RefArgs, execute_ref_action_result_with_context},
context::CommandContext,
error::AppError,
interaction_policy::InteractionPolicy,
@@ -61,7 +61,7 @@ fn probe_app_name(adapter: &dyn PlatformAdapter, entry: &RefEntry) -> Option<Str
if entry.source_app.is_some() {
return entry.source_app.clone();
}
- find_window_for_pid(entry.pid, adapter)
+ crate::window_lookup::find_window_for_pid(entry.pid, adapter)
.ok()
.map(|window| window.app)
}
diff --git a/crates/core/src/commands/version.rs b/crates/core/src/commands/version.rs
index 6a8c593be..0f711affb 100644
--- a/crates/core/src/commands/version.rs
+++ b/crates/core/src/commands/version.rs
@@ -1,11 +1,7 @@
use crate::error::AppError;
use serde_json::{Value, json};
-pub struct VersionArgs {
- pub json: bool,
-}
-
-pub fn execute(_args: VersionArgs) -> Result<Value, AppError> {
+pub fn execute() -> Result<Value, AppError> {
Ok(json!({
"version": env!("CARGO_PKG_VERSION"),
"target": std::env::consts::ARCH,
diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs
index 6808d772c..bc0999fe6 100644
--- a/crates/core/src/lib.rs
+++ b/crates/core/src/lib.rs
@@ -51,7 +51,7 @@ pub use error::{AdapterError, AppError, ErrorCode};
pub use interaction_policy::InteractionPolicy;
pub use node::{AccessibilityNode, AppInfo, Rect, WindowInfo};
pub use notification::{NotificationFilter, NotificationInfo};
-pub use output::{AppContext, ErrorPayload, Response, WindowContext};
+pub use output::{ErrorPayload, Response};
pub use permission_report::PermissionReport;
pub use permission_state::PermissionState;
pub use refs::{RefEntry, RefMap};
diff --git a/crates/core/src/output.rs b/crates/core/src/output.rs
index a6a6ed78d..859e0e83c 100644
--- a/crates/core/src/output.rs
+++ b/crates/core/src/output.rs
@@ -12,26 +12,11 @@ pub struct Response {
pub ok: bool,
pub command: String,
#[serde(skip_serializing_if = "Option::is_none")]
- pub app: Option<AppContext>,
- #[serde(skip_serializing_if = "Option::is_none")]
pub data: Option<Value>,
#[serde(skip_serializing_if = "Option::is_none")]
pub error: Option<ErrorPayload>,
}
-#[derive(Debug, Serialize)]
-pub struct AppContext {
- pub name: String,
- #[serde(skip_serializing_if = "Option::is_none")]
- pub window: Option<WindowContext>,
-}
-
-#[derive(Debug, Serialize)]
-pub struct WindowContext {
- pub id: String,
- pub title: String,
-}
-
#[derive(Debug, Serialize)]
pub struct ErrorPayload {
pub code: String,
@@ -52,7 +37,6 @@ impl Response {
version: ENVELOPE_VERSION,
ok: true,
command: command.into(),
- app: None,
data: Some(data),
error: None,
}
@@ -63,16 +47,10 @@ impl Response {
version: ENVELOPE_VERSION,
ok: false,
command: command.into(),
- app: None,
data: None,
error: Some(payload),
}
}
-
- pub fn with_app(mut self, ctx: AppContext) -> Self {
- self.app = Some(ctx);
- self
- }
}
impl ErrorPayload {
diff --git a/crates/core/src/ref_alloc.rs b/crates/core/src/ref_alloc.rs
index ec3fb2d72..34851c031 100644
--- a/crates/core/src/ref_alloc.rs
+++ b/crates/core/src/ref_alloc.rs
@@ -150,7 +150,9 @@ fn allocate_refs_at_path(
);
entry.source_surface = config.source_surface;
entry.path_is_absolute = config.root_ref_id.is_some();
- strip_ref_bounds_when_hidden(&mut entry, config.include_bounds);
+ if !config.include_bounds {
+ entry.bounds = None;
+ }
node.ref_id = Some(refmap.allocate(entry));
}
@@ -171,7 +173,9 @@ fn allocate_refs_at_path(
);
entry.source_surface = config.source_surface;
entry.available_actions = vec![];
- strip_ref_bounds_when_hidden(&mut entry, config.include_bounds);
+ if !config.include_bounds {
+ entry.bounds = None;
+ }
node.ref_id = Some(refmap.allocate(entry));
}
@@ -206,12 +210,6 @@ fn allocate_refs_at_path(
node
}
-fn strip_ref_bounds_when_hidden(entry: &mut RefEntry, include_bounds: bool) {
- if !include_bounds {
- entry.bounds = None;
- }
-}
-
fn meaningful_string(value: Option<String>) -> Option<String> {
value.filter(|text| !text.is_empty())
}
diff --git a/crates/core/src/refs_lock.rs b/crates/core/src/refs_lock.rs
index 929708055..2e50cef5c 100644
--- a/crates/core/src/refs_lock.rs
+++ b/crates/core/src/refs_lock.rs
@@ -170,10 +170,7 @@ fn lock_token() -> String {
#[cfg(unix)]
fn process_is_alive(pid: u32) -> Option<bool> {
- unsafe extern "C" {
- fn kill(pid: i32, sig: i32) -> i32;
- }
- let result = unsafe { kill(pid as i32, 0) };
+ let result = unsafe { libc::kill(pid as i32, 0) };
if result == 0 {
return Some(true);
}
diff --git a/crates/ffi/src/actions/conversion.rs b/crates/ffi/src/actions/conversion.rs
index 786fdc95d..8d35bfacd 100644
--- a/crates/ffi/src/actions/conversion.rs
+++ b/crates/ffi/src/actions/conversion.rs
@@ -2,15 +2,6 @@ use crate::convert::string::c_to_string;
use crate::types::{AdAction, AdActionKind, AdDirection, AdKeyCombo, AdModifier};
use agent_desktop_core::action::{Action, Direction, KeyCombo as CoreKeyCombo, Modifier};
-fn direction_from_c(d: AdDirection) -> Direction {
- match d {
- AdDirection::Up => Direction::Up,
- AdDirection::Down => Direction::Down,
- AdDirection::Left => Direction::Left,
- AdDirection::Right => Direction::Right,
- }
-}
-
/// Four modifier keys exist (`AdModifier::{Cmd, Ctrl, Alt, Shift}`),
/// so a combo can name at most four. Anything larger must be bogus
/// input — bail out instead of trusting it into `from_raw_parts`.
@@ -75,9 +66,14 @@ pub(crate) unsafe fn action_from_c(action: &AdAction) -> Result<Action, &'static
Ok(Action::TypeText(text))
}
AdActionKind::Scroll => {
- let raw_dir = AdDirection::from_c(action.scroll.direction)
- .ok_or("invalid scroll direction discriminant")?;
- let dir = direction_from_c(raw_dir);
+ let dir = match AdDirection::from_c(action.scroll.direction)
+ .ok_or("invalid scroll direction discriminant")?
+ {
+ AdDirection::Up => Direction::Up,
+ AdDirection::Down => Direction::Down,
+ AdDirection::Left => Direction::Left,
+ AdDirection::Right => Direction::Right,
+ };
Ok(Action::Scroll(dir, action.scroll.amount))
}
AdActionKind::PressKey => {
diff --git a/crates/ffi/src/convert/surface.rs b/crates/ffi/src/convert/surface.rs
index a017cc441..93fbf9916 100644
--- a/crates/ffi/src/convert/surface.rs
+++ b/crates/ffi/src/convert/surface.rs
@@ -16,24 +16,20 @@ pub(crate) fn surface_info_to_c(s: &SurfaceInfo) -> AdSurfaceInfo {
}
}
-pub(crate) fn snapshot_surface_to_core(surface: AdSnapshotSurface) -> SnapshotSurface {
- match surface {
- AdSnapshotSurface::Window => SnapshotSurface::Window,
- AdSnapshotSurface::Focused => SnapshotSurface::Focused,
- AdSnapshotSurface::Menu => SnapshotSurface::Menu,
- AdSnapshotSurface::Menubar => SnapshotSurface::Menubar,
- AdSnapshotSurface::Sheet => SnapshotSurface::Sheet,
- AdSnapshotSurface::Popover => SnapshotSurface::Popover,
- AdSnapshotSurface::Alert => SnapshotSurface::Alert,
- }
-}
-
pub(crate) fn snapshot_surface_from_c(
raw: i32,
field: &str,
) -> Result<SnapshotSurface, AdapterError> {
AdSnapshotSurface::from_c(raw)
- .map(snapshot_surface_to_core)
+ .map(|surface| match surface {
+ AdSnapshotSurface::Window => SnapshotSurface::Window,
+ AdSnapshotSurface::Focused => SnapshotSurface::Focused,
+ AdSnapshotSurface::Menu => SnapshotSurface::Menu,
+ AdSnapshotSurface::Menubar => SnapshotSurface::Menubar,
+ AdSnapshotSurface::Sheet => SnapshotSurface::Sheet,
+ AdSnapshotSurface::Popover => SnapshotSurface::Popover,
+ AdSnapshotSurface::Alert => SnapshotSurface::Alert,
+ })
.ok_or_else(|| {
AdapterError::new(
ErrorCode::InvalidArgs,
diff --git a/crates/ffi/src/enum_validation.rs b/crates/ffi/src/enum_validation.rs
index 9eca47259..b2430b9a0 100644
--- a/crates/ffi/src/enum_validation.rs
+++ b/crates/ffi/src/enum_validation.rs
@@ -9,8 +9,8 @@
//! returns `AD_RESULT_ERR_INVALID_ARGS`.
use crate::types::{
- AdActionKind, AdDirection, AdImageFormat, AdModifier, AdMouseButton, AdMouseEventKind,
- AdPolicyKind, AdScreenshotKind, AdSnapshotSurface, AdWindowOpKind,
+ AdActionKind, AdDirection, AdModifier, AdMouseButton, AdMouseEventKind, AdPolicyKind,
+ AdScreenshotKind, AdSnapshotSurface, AdWindowOpKind,
};
macro_rules! try_from_c_enum {
@@ -80,12 +80,6 @@ try_from_c_enum! {
}
}
-try_from_c_enum! {
- AdImageFormat {
- Png = 0, Jpg = 1,
- }
-}
-
try_from_c_enum! {
AdSnapshotSurface {
Window = 0, Focused = 1, Menu = 2, Menubar = 3,
@@ -165,13 +159,6 @@ mod tests {
assert!(AdScreenshotKind::from_c(3).is_none());
}
- #[test]
- fn test_image_format_valid_range() {
- assert!(AdImageFormat::from_c(0).is_some());
- assert!(AdImageFormat::from_c(1).is_some());
- assert!(AdImageFormat::from_c(2).is_none());
- }
-
#[test]
fn typed_enum_cast_round_trips_through_raw_i32() {
let raw = AdActionKind::Scroll as i32;
@@ -191,7 +178,6 @@ mod tests {
let _ = AdMouseEventKind::from_c(raw);
let _ = AdWindowOpKind::from_c(raw);
let _ = AdScreenshotKind::from_c(raw);
- let _ = AdImageFormat::from_c(raw);
}
}
}
diff --git a/crates/ffi/src/error.rs b/crates/ffi/src/error.rs
index 242a46ffd..a8df68e42 100644
--- a/crates/ffi/src/error.rs
+++ b/crates/ffi/src/error.rs
@@ -2,53 +2,6 @@ use agent_desktop_core::error::{AdapterError, ErrorCode};
use std::cell::RefCell;
use std::ffi::{CStr, CString, c_char};
-const fn error_code_variant_count() -> usize {
- let variants = [
- ErrorCode::PermDenied,
- ErrorCode::ElementNotFound,
- ErrorCode::AppNotFound,
- ErrorCode::ActionFailed,
- ErrorCode::ActionNotSupported,
- ErrorCode::StaleRef,
- ErrorCode::AmbiguousTarget,
- ErrorCode::WindowNotFound,
- ErrorCode::PlatformNotSupported,
- ErrorCode::Timeout,
- ErrorCode::InvalidArgs,
- ErrorCode::NotificationNotFound,
- ErrorCode::SnapshotNotFound,
- ErrorCode::PolicyDenied,
- ErrorCode::Internal,
- ];
- variants.len()
-}
-
-const fn ad_result_error_variant_count() -> usize {
- let variants = [
- AdResult::ErrPermDenied,
- AdResult::ErrElementNotFound,
- AdResult::ErrAppNotFound,
- AdResult::ErrActionFailed,
- AdResult::ErrActionNotSupported,
- AdResult::ErrStaleRef,
- AdResult::ErrAmbiguousTarget,
- AdResult::ErrWindowNotFound,
- AdResult::ErrPlatformNotSupported,
- AdResult::ErrTimeout,
- AdResult::ErrInvalidArgs,
- AdResult::ErrNotificationNotFound,
- AdResult::ErrInternal,
- AdResult::ErrSnapshotNotFound,
- AdResult::ErrPolicyDenied,
- ];
- variants.len()
-}
-
-const _: () = assert!(
- error_code_variant_count() == ad_result_error_variant_count(),
- "ErrorCode variants must match AdResult error-code variants one-to-one"
-);
-
#[repr(i32)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AdResult {
@@ -122,6 +75,12 @@ thread_local! {
static LAST_ERROR: RefCell<Option<StoredError>> = const { RefCell::new(None) };
}
+/// Maps a core `ErrorCode` to its stable C-ABI `AdResult`. `ErrorCode` and the
+/// error variants of `AdResult` are a bijection: each maps to exactly one of the
+/// other. This match is exhaustive over `ErrorCode`, so a new `ErrorCode` cannot
+/// be added without a result here (forward-drift guard); the reverse direction is
+/// guarded by `error_code_and_ad_result_error_variants_stay_in_bijection` in the
+/// tests. When adding an error, update both this match and the `AdResult` enum.
fn error_code_to_result(code: &ErrorCode) -> AdResult {
match code {
ErrorCode::PermDenied => AdResult::ErrPermDenied,
diff --git a/crates/ffi/src/error_tests.rs b/crates/ffi/src/error_tests.rs
index f833b211e..377612b71 100644
--- a/crates/ffi/src/error_tests.rs
+++ b/crates/ffi/src/error_tests.rs
@@ -46,6 +46,61 @@ fn result_discriminants_preserve_existing_abi_values() {
assert_eq!(AdResult::ErrAmbiguousTarget as i32, -15);
}
+/// Reverse of `error_code_to_result`, kept solely to guard the bijection. The
+/// forward map is exhaustive over `ErrorCode`; this exhaustive match over
+/// `AdResult` is its mirror, so a new `AdResult` error variant cannot be added
+/// without declaring its `ErrorCode` origin here — closing the reverse-drift
+/// direction (a new `AdResult` with no `ErrorCode`) the removed cardinality
+/// counters approximated.
+fn error_code_origin(result: AdResult) -> Option<ErrorCode> {
+ Some(match result {
+ AdResult::Ok => return None,
+ AdResult::ErrPermDenied => ErrorCode::PermDenied,
+ AdResult::ErrElementNotFound => ErrorCode::ElementNotFound,
+ AdResult::ErrAppNotFound => ErrorCode::AppNotFound,
+ AdResult::ErrActionFailed => ErrorCode::ActionFailed,
+ AdResult::ErrActionNotSupported => ErrorCode::ActionNotSupported,
+ AdResult::ErrStaleRef => ErrorCode::StaleRef,
+ AdResult::ErrWindowNotFound => ErrorCode::WindowNotFound,
+ AdResult::ErrPlatformNotSupported => ErrorCode::PlatformNotSupported,
+ AdResult::ErrTimeout => ErrorCode::Timeout,
+ AdResult::ErrInvalidArgs => ErrorCode::InvalidArgs,
+ AdResult::ErrNotificationNotFound => ErrorCode::NotificationNotFound,
+ AdResult::ErrInternal => ErrorCode::Internal,
+ AdResult::ErrSnapshotNotFound => ErrorCode::SnapshotNotFound,
+ AdResult::ErrPolicyDenied => ErrorCode::PolicyDenied,
+ AdResult::ErrAmbiguousTarget => ErrorCode::AmbiguousTarget,
+ })
+}
+
+#[test]
+fn error_code_and_ad_result_error_variants_stay_in_bijection() {
+ for result in [
+ AdResult::ErrPermDenied,
+ AdResult::ErrElementNotFound,
+ AdResult::ErrAppNotFound,
+ AdResult::ErrActionFailed,
+ AdResult::ErrActionNotSupported,
+ AdResult::ErrStaleRef,
+ AdResult::ErrWindowNotFound,
+ AdResult::ErrPlatformNotSupported,
+ AdResult::ErrTimeout,
+ AdResult::ErrInvalidArgs,
+ AdResult::ErrNotificationNotFound,
+ AdResult::ErrInternal,
+ AdResult::ErrSnapshotNotFound,
+ AdResult::ErrPolicyDenied,
+ AdResult::ErrAmbiguousTarget,
+ ] {
+ let code = error_code_origin(result).expect("error variant must have an ErrorCode origin");
+ assert_eq!(
+ error_code_to_result(&code),
+ result,
+ "forward/reverse mapping disagree for {result:?}"
+ );
+ }
+}
+
#[test]
fn test_set_and_get_error() {
let err = AdapterError::new(ErrorCode::ElementNotFound, "element @e5 gone")
diff --git a/crates/linux/Cargo.toml b/crates/linux/Cargo.toml
index 558f46c60..89d9a116d 100644
--- a/crates/linux/Cargo.toml
+++ b/crates/linux/Cargo.toml
@@ -3,6 +3,7 @@ name = "agent-desktop-linux"
version.workspace = true
edition.workspace = true
license.workspace = true
+publish = false
[dependencies]
agent-desktop-core.workspace = true
diff --git a/crates/macos/Cargo.toml b/crates/macos/Cargo.toml
index 208a4317e..c652a4cf3 100644
--- a/crates/macos/Cargo.toml
+++ b/crates/macos/Cargo.toml
@@ -3,6 +3,7 @@ name = "agent-desktop-macos"
version.workspace = true
edition.workspace = true
license.workspace = true
+publish = false
[dependencies]
smallvec.workspace = true
diff --git a/crates/macos/src/system/app_inventory.rs b/crates/macos/src/system/app_inventory.rs
index ec79cba23..2b5e3a8d0 100644
--- a/crates/macos/src/system/app_inventory.rs
+++ b/crates/macos/src/system/app_inventory.rs
@@ -94,7 +94,7 @@ fn merge_apps(apps: &mut Vec<AppInfo>, incoming: Vec<AppInfo>) {
let mut seen_pids = apps
.iter()
.map(|app| app.pid)
- .collect::<std::collections::HashSet<_>>();
+ .collect::<rustc_hash::FxHashSet<_>>();
for app in incoming {
if seen_pids.insert(app.pid) {
diff --git a/crates/macos/src/system/key_dispatch.rs b/crates/macos/src/system/key_dispatch.rs
index 0a6e1ebda..6854de7d4 100644
--- a/crates/macos/src/system/key_dispatch.rs
+++ b/crates/macos/src/system/key_dispatch.rs
@@ -212,71 +212,10 @@ fn format_combo(combo: &KeyCombo) -> String {
#[cfg(target_os = "macos")]
fn key_to_keycode(key: &str) -> Option<u16> {
- Some(match key {
- "a" => 0,
- "b" => 11,
- "c" => 8,
- "d" => 2,
- "e" => 14,
- "f" => 3,
- "g" => 5,
- "h" => 4,
- "i" => 34,
- "j" => 38,
- "k" => 40,
- "l" => 37,
- "m" => 46,
- "n" => 45,
- "o" => 31,
- "p" => 35,
- "q" => 12,
- "r" => 15,
- "s" => 1,
- "t" => 17,
- "u" => 32,
- "v" => 9,
- "w" => 13,
- "x" => 7,
- "y" => 16,
- "z" => 6,
- "0" => 29,
- "1" => 18,
- "2" => 19,
- "3" => 20,
- "4" => 21,
- "5" => 23,
- "6" => 22,
- "7" => 26,
- "8" => 28,
- "9" => 25,
- "return" | "enter" => 36,
- "escape" | "esc" => 53,
- "tab" => 48,
- "space" => 49,
- "delete" | "backspace" => 51,
- "forwarddelete" => 117,
- "home" => 115,
- "end" => 119,
- "pageup" => 116,
- "pagedown" => 121,
- "left" => 123,
- "right" => 124,
- "down" => 125,
- "up" => 126,
- "f1" => 122,
- "f2" => 120,
- "f3" => 99,
- "f4" => 118,
- "f5" => 96,
- "f6" => 97,
- "f7" => 98,
- "f8" => 100,
- "f9" => 101,
- "f10" => 109,
- "f11" => 103,
- "f12" => 111,
- _ => return None,
- })
+ match key {
+ "cmd" | "command" | "shift" | "alt" | "option" | "ctrl" | "control" => None,
+ other => crate::input::keyboard_map::key_name_to_code(other).ok(),
+ }
}
#[cfg(target_os = "macos")]
diff --git a/crates/macos/src/system/permissions.rs b/crates/macos/src/system/permissions.rs
index 33521dde2..18536dc05 100644
--- a/crates/macos/src/system/permissions.rs
+++ b/crates/macos/src/system/permissions.rs
@@ -86,11 +86,7 @@ fn permission_state(granted: bool, suggestion: &'static str) -> PermissionState
}
fn accessibility_report_state() -> PermissionState {
- if imp::is_trusted() {
- return PermissionState::Granted;
- }
-
- permission_state(false, ACCESSIBILITY_SUGGESTION)
+ permission_state(imp::is_trusted(), ACCESSIBILITY_SUGGESTION)
}
fn screen_recording_report_state() -> PermissionState {
diff --git a/crates/macos/src/system/process.rs b/crates/macos/src/system/process.rs
index c6add2005..e98a2936d 100644
--- a/crates/macos/src/system/process.rs
+++ b/crates/macos/src/system/process.rs
@@ -1,6 +1,6 @@
use agent_desktop_core::error::AdapterError;
use std::io::Read;
-use std::process::{Command, ExitStatus, Output, Stdio};
+use std::process::{Command, Output, Stdio};
use std::thread;
use std::time::{Duration, Instant};
@@ -42,7 +42,11 @@ pub(crate) fn run_with_timeout(
let stdout = join_drain(stdout_handle);
let stderr = join_drain(stderr_handle);
- Ok(make_output(status, stdout, stderr))
+ Ok(Output {
+ status,
+ stdout,
+ stderr,
+ })
}
fn spawn_drain<R>(mut reader: R) -> thread::JoinHandle<Vec<u8>>
@@ -60,14 +64,6 @@ fn join_drain(handle: Option<thread::JoinHandle<Vec<u8>>>) -> Vec<u8> {
handle.and_then(|h| h.join().ok()).unwrap_or_default()
}
-fn make_output(status: ExitStatus, stdout: Vec<u8>, stderr: Vec<u8>) -> Output {
- Output {
- status,
- stdout,
- stderr,
- }
-}
-
#[cfg(all(test, unix))]
mod tests {
use super::*;
diff --git a/crates/macos/src/system/process_apps.rs b/crates/macos/src/system/process_apps.rs
index 3c3cd9441..ebb603e8b 100644
--- a/crates/macos/src/system/process_apps.rs
+++ b/crates/macos/src/system/process_apps.rs
@@ -18,7 +18,7 @@ pub(crate) fn list_apps() -> Vec<AppInfo> {
}
};
let text = String::from_utf8_lossy(&output.stdout);
- let mut seen_pids = std::collections::HashSet::new();
+ let mut seen_pids = rustc_hash::FxHashSet::default();
let mut apps = Vec::new();
for line in text.lines() {
diff --git a/crates/macos/src/system/window_inventory.rs b/crates/macos/src/system/window_inventory.rs
index 44040b08a..373ace0e7 100644
--- a/crates/macos/src/system/window_inventory.rs
+++ b/crates/macos/src/system/window_inventory.rs
@@ -11,7 +11,7 @@ pub(crate) fn visible_apps() -> Vec<AppInfo> {
}
fn apps_from_window_records(records: &[cg_window::WindowRecord]) -> Vec<AppInfo> {
- let mut seen_pids = std::collections::HashSet::new();
+ let mut seen_pids = rustc_hash::FxHashSet::default();
let mut apps = Vec::new();
for record in records {
@@ -94,14 +94,7 @@ fn visible_windows_from_records(
.cloned()
.collect();
- windows_from_records(candidates, filter.focused_only)
-}
-
-fn windows_from_records(
- records: Vec<cg_window::WindowRecord>,
- focused_only: bool,
-) -> Vec<WindowInfo> {
- windows_from_records_with_focus(records, focused_only, focused_window_identity)
+ windows_from_records_with_focus(candidates, filter.focused_only, focused_window_identity)
}
fn windows_from_records_with_focus(
diff --git a/crates/macos/src/system/workspace_apps.rs b/crates/macos/src/system/workspace_apps.rs
index 30a51418d..5228158db 100644
--- a/crates/macos/src/system/workspace_apps.rs
+++ b/crates/macos/src/system/workspace_apps.rs
@@ -89,7 +89,7 @@ fn apps_from_running_array(
let name_sel = sel_registerName(c"localizedName".as_ptr());
let bundle_sel = sel_registerName(c"bundleIdentifier".as_ptr());
- let mut seen_pids = std::collections::HashSet::new();
+ let mut seen_pids = rustc_hash::FxHashSet::default();
let mut apps = Vec::new();
for idx in 0..count {
let app = send_object(running, object_sel, idx);
diff --git a/crates/macos/src/tree/builder.rs b/crates/macos/src/tree/builder.rs
index a2ef91827..b62870e68 100644
--- a/crates/macos/src/tree/builder.rs
+++ b/crates/macos/src/tree/builder.rs
@@ -26,7 +26,7 @@ pub fn window_element_for(pid: i32, win_title: &str) -> AXElement {
let mut child_candidate = None;
let mut partial_candidate = None;
for win in &windows {
- if !is_window_candidate(win) {
+ if copy_string_attr(win, kAXRoleAttribute).as_deref() != Some("AXWindow") {
continue;
}
first_candidate.get_or_insert_with(|| win.clone());
@@ -67,11 +67,6 @@ fn window_titles_are_partial_match(candidate_title: &str, requested_title: &str)
&& (candidate_title.contains(requested_title) || requested_title.contains(candidate_title))
}
-#[cfg(target_os = "macos")]
-fn is_window_candidate(el: &AXElement) -> bool {
- copy_string_attr(el, kAXRoleAttribute).as_deref() == Some("AXWindow")
-}
-
#[cfg(target_os = "macos")]
pub fn build_subtree(
el: &AXElement,
diff --git a/crates/macos/src/tree/resolve_classify.rs b/crates/macos/src/tree/resolve_classify.rs
index 46453bc1c..1618e72e6 100644
--- a/crates/macos/src/tree/resolve_classify.rs
+++ b/crates/macos/src/tree/resolve_classify.rs
@@ -100,10 +100,9 @@ fn candidate_summaries(matches: &[AXElement]) -> Vec<serde_json::Value> {
.enumerate()
.map(|(index, element)| {
let ax_role = copy_string_attr(element, accessibility_sys::kAXRoleAttribute);
- let role = crate::tree::roles::normalized_role_for_element(element, ax_role.as_deref());
- let name = crate::tree::roles::normalized_role_and_label(element, ax_role.as_deref())
- .1
- .or_else(|| resolve_element_name(element));
+ let (role, label) =
+ crate::tree::roles::normalized_role_and_label(element, ax_role.as_deref());
+ let name = label.or_else(|| resolve_element_name(element));
let description = copy_string_attr(element, accessibility_sys::kAXDescriptionAttribute);
let bounds = crate::tree::read_bounds(element);
serde_json::json!({
diff --git a/crates/macos/src/tree/roles.rs b/crates/macos/src/tree/roles.rs
index cb1d555e4..4b899aa91 100644
--- a/crates/macos/src/tree/roles.rs
+++ b/crates/macos/src/tree/roles.rs
@@ -52,10 +52,6 @@ pub fn ax_role_to_str(ax_role: &str) -> &'static str {
}
}
-pub fn normalized_role_for_element(el: &crate::tree::AXElement, ax_role: Option<&str>) -> String {
- normalized_role_and_label(el, ax_role).0
-}
-
pub fn normalized_role_and_label(
el: &crate::tree::AXElement,
ax_role: Option<&str>,
diff --git a/crates/windows/Cargo.toml b/crates/windows/Cargo.toml
index c3e1033bf..ab883b2fd 100644
--- a/crates/windows/Cargo.toml
+++ b/crates/windows/Cargo.toml
@@ -3,6 +3,7 @@ name = "agent-desktop-windows"
version.workspace = true
edition.workspace = true
license.workspace = true
+publish = false
[dependencies]
agent-desktop-core.workspace = true
diff --git a/skills/agent-desktop/SKILL.md b/skills/agent-desktop/SKILL.md
index 8db0e644a..9e9ca1711 100644
--- a/skills/agent-desktop/SKILL.md
+++ b/skills/agent-desktop/SKILL.md
@@ -232,7 +232,7 @@ agent-desktop wait --notification --app "App" # Wait for new notification
agent-desktop status # Health check
agent-desktop permissions # Check permission
agent-desktop permissions --request # Trigger permission dialog
-agent-desktop version --json # Version info
+agent-desktop version # Version info (always JSON envelope)
agent-desktop batch '[...]' --stop-on-error # Batch uses the same typed command path as CLI
agent-desktop skills # List bundled skill docs
agent-desktop skills get desktop --full # Load this skill + all references
diff --git a/skills/agent-desktop/references/commands-system.md b/skills/agent-desktop/references/commands-system.md
index 08f9068c4..49145e526 100644
--- a/skills/agent-desktop/references/commands-system.md
+++ b/skills/agent-desktop/references/commands-system.md
@@ -294,9 +294,8 @@ Checks the cached per-process permission report: `accessibility`, `screen_record
### version
```bash
agent-desktop version
-agent-desktop version --json
```
-Returns version string. Use `--json` for `{ "version": "0.1.3", "platform": "macos", "arch": "aarch64" }`.
+Returns `{ "version": "0.3.1", "target": "aarch64", "os": "macos" }`. Always emitted as a JSON envelope (`ok: true`, `data: { version, target, os }`).
## Skills (bundled docs)
diff --git a/src/batch/mod.rs b/src/batch/mod.rs
index cf9a841c7..681eea614 100644
--- a/src/batch/mod.rs
+++ b/src/batch/mod.rs
@@ -100,7 +100,7 @@ pub(crate) fn parse_command(item: BatchCommand) -> Result<Commands, AppError> {
"wait" => decode(command, item.args).map(Commands::Wait),
"status" => no_args(command, item.args).map(|()| Commands::Status),
"permissions" => decode(command, item.args).map(Commands::Permissions),
- "version" => decode(command, item.args).map(Commands::Version),
+ "version" => no_args(command, item.args).map(|()| Commands::Version),
"skills" => parse_skills(item.args).map(Commands::Skills),
"batch" => Err(AppError::invalid_input_with_suggestion(
"Batch commands cannot be nested",
diff --git a/src/batch/tests.rs b/src/batch/tests.rs
index 348bc85a1..54577d3da 100644
--- a/src/batch/tests.rs
+++ b/src/batch/tests.rs
@@ -74,12 +74,20 @@ fn rejects_unknown_wait_batch_args_after_flattening() {
assert_eq!(err.code(), "INVALID_ARGS");
}
+#[test]
+fn rejects_version_args_after_json_flag_removal() {
+ let err = parse_command(item("version", serde_json::json!({ "json": true })))
+ .expect_err("version no longer accepts args");
+
+ assert_eq!(err.code(), "INVALID_ARGS");
+}
+
#[test]
fn stop_on_error_halts_after_first_failure() {
let args = BatchArgs {
commands_json: serde_json::json!([
{"command": "missing", "args": {}},
- {"command": "version", "args": {"json": true}}
+ {"command": "version", "args": {}}
])
.to_string(),
stop_on_error: true,
diff --git a/src/cli/help_after.txt b/src/cli/help_after.txt
index 32957ce11..98d504825 100644
--- a/src/cli/help_after.txt
+++ b/src/cli/help_after.txt
@@ -75,7 +75,7 @@ WAIT
SYSTEM
status Adapter health, platform, and permission state
permissions Check nested permission states: {state,...}
- version Version string (--json for machine-readable)
+ version Show version, target architecture, and OS
skills Bundled skill docs for AI agents (list, get, path)
BATCH
diff --git a/src/cli/mod.rs b/src/cli/mod.rs
index c71aa8886..3a35854da 100644
--- a/src/cli/mod.rs
+++ b/src/cli/mod.rs
@@ -15,7 +15,7 @@ use crate::cli_args::{
system::{
AppRefArgs, BatchArgs, ClipboardSetArgs, CloseAppArgs, FocusWindowArgs, LaunchArgs,
ListAppsArgs, ListWindowsArgs, MoveWindowCliArgs, PermissionsArgs, ResizeWindowCliArgs,
- VersionArgs, WaitArgs,
+ WaitArgs,
},
};
@@ -179,8 +179,8 @@ pub(crate) enum Commands {
about = "Check nested permission states: accessibility/screen_recording/automation each return {state,...}"
)]
Permissions(PermissionsArgs),
- #[command(about = "Show version (--json for machine-readable output)")]
- Version(VersionArgs),
+ #[command(about = "Show version, target architecture, and OS")]
+ Version,
#[command(about = "Execute multiple commands from a JSON array (--stop-on-error)")]
Batch(BatchArgs),
#[command(about = "Bundled skill docs for AI agents (list, get, path)")]
@@ -241,7 +241,7 @@ impl Commands {
Self::Wait(_) => "wait",
Self::Status => "status",
Self::Permissions(_) => "permissions",
- Self::Version(_) => "version",
+ Self::Version => "version",
Self::Batch(_) => "batch",
Self::Skills(_) => "skills",
}
diff --git a/src/cli_args/system.rs b/src/cli_args/system.rs
index 283f38bcf..d6e738b78 100644
--- a/src/cli_args/system.rs
+++ b/src/cli_args/system.rs
@@ -185,14 +185,6 @@ pub(crate) struct PermissionsArgs {
pub request: bool,
}
-#[derive(Parser, Debug, Deserialize)]
-#[serde(deny_unknown_fields)]
-pub(crate) struct VersionArgs {
- #[arg(long, help = "Output version as JSON object")]
- #[serde(default)]
- pub json: bool,
-}
-
#[derive(Parser, Debug)]
pub(crate) struct BatchArgs {
#[arg(value_name = "JSON", help = "JSON array of {command, args} objects")]
diff --git a/src/command_policy/mod.rs b/src/command_policy/mod.rs
index 1136fecff..30fce0174 100644
--- a/src/command_policy/mod.rs
+++ b/src/command_policy/mod.rs
@@ -17,7 +17,7 @@ pub(crate) enum PermissionNeed {
pub(crate) fn policy_for(cmd: &Commands) -> PermissionNeed {
use PermissionNeed::{Accessibility, AccessibilityAndScreenRecording, None, ScreenRecording};
match cmd {
- Commands::Version(_) | Commands::Skills(_) => None,
+ Commands::Version | Commands::Skills(_) => None,
Commands::Status | Commands::Permissions(_) => None,
Commands::ListWindows(_) | Commands::ListApps(_) => None,
Commands::ClipboardGet | Commands::ClipboardSet(_) | Commands::ClipboardClear => None,
@@ -190,7 +190,7 @@ fn validate_args(cmd: &Commands) -> Result<(), AppError> {
| Commands::ClipboardClear
| Commands::Status
| Commands::Permissions(_)
- | Commands::Version(_)
+ | Commands::Version
| Commands::Batch(_)
| Commands::Skills(_) => {}
}
diff --git a/src/dispatch/mod.rs b/src/dispatch/mod.rs
index eb96027de..c535af5f9 100644
--- a/src/dispatch/mod.rs
+++ b/src/dispatch/mod.rs
@@ -341,7 +341,7 @@ pub(crate) fn dispatch(
permission_report,
),
- Commands::Version(a) => version::execute(version::VersionArgs { json: a.json }),
+ Commands::Version => version::execute(),
Commands::Skills(a) => match a.action.unwrap_or(SkillsAction::List) {
SkillsAction::List => skills::list(),
diff --git a/src/main.rs b/src/main.rs
index 1367be96c..9f8bcac37 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -54,10 +54,8 @@ fn main() {
let cmd_name = cmd.name();
match cmd {
- Commands::Version(a) => {
- let result = agent_desktop_core::commands::version::execute(
- agent_desktop_core::commands::version::VersionArgs { json: a.json },
- );
+ Commands::Version => {
+ let result = agent_desktop_core::commands::version::execute();
finish(cmd_name, result);
}
Commands::Skills(a) => {
diff --git a/src/tests/snapshot_test.rs b/src/tests/snapshot_test.rs
index 0de05111d..d074dfd22 100644
--- a/src/tests/snapshot_test.rs
+++ b/src/tests/snapshot_test.rs
@@ -57,7 +57,7 @@ mod tests {
return;
}
let output = Command::new(&bin)
- .args(["version", "--json"])
+ .args(["version"])
.output()
.expect("failed to run agent-desktop");