Computer use CLI for AI agents
Rust accessibilityaccessibility-apiai-agentsautomationclicomputer-usecomputer-use-agentcomputer-use-agentsdesktop-automationmacosmcprust
fix(windows): let launch take a bare name without .exe (#276)
Lahfir483427eb8482
diff --git a/crates/windows/src/system/launch.rs b/crates/windows/src/system/launch.rsindex e367cee79..1535ab5b2 100644--- a/crates/windows/src/system/launch.rs+++ b/crates/windows/src/system/launch.rs@@ -11,7 +11,7 @@ use super::app_ops::{ProcessRow, process_snapshot};#[cfg(target_os = "windows")]use super::hresult::win32_last_error;use super::launch_path::{- child_environment_block, image_file_name, resolve_executable, validate_app_identifier,+ child_environment_block, image_file_name, launch_identifier, resolve_executable,validate_launch_options,};use super::permissions::ensure_budget;@@ -23,7 +23,7 @@ pub(crate) fn launch_app_impl(options: &LaunchOptions,parent_deadline: Deadline,) -> Result<LaunchResult, AdapterError> {- validate_app_identifier(id).map_err(before_launch)?;+ let id = &launch_identifier(id).map_err(before_launch)?;validate_launch_options(options).map_err(before_launch)?;let deadline = if options.timeout_ms == 0 {parent_deadlinediff --git a/crates/windows/src/system/launch_path.rs b/crates/windows/src/system/launch_path.rsindex d9a7a94e6..0726a8ba0 100644--- a/crates/windows/src/system/launch_path.rs+++ b/crates/windows/src/system/launch_path.rs@@ -6,12 +6,18 @@ const MAX_ARGUMENT_COUNT: usize = 256;const MAX_ENVIRONMENT_COUNT: usize = 256;const MAX_LAUNCH_TEXT_BYTES: usize = 1024 * 1024;-pub(super) fn validate_app_identifier(id: &str) -> Result<(), AdapterError> {+pub(super) fn launch_identifier(id: &str) -> Result<String, AdapterError> {if id.is_empty() || id.contains("..") || id.chars().any(char::is_control) {return Err(invalid_identifier(id));}- if is_absolute_launch_path(id) || is_bare_name(id) {- return Ok(());+ if is_absolute_launch_path(id) {+ return Ok(id.to_owned());+ }+ if is_bare_name(id) {+ if std::path::Path::new(id).extension().is_some() {+ return Ok(id.to_owned());+ }+ return Ok(format!("{id}.exe"));}Err(invalid_identifier(id))}@@ -216,10 +222,18 @@ mod tests {#[test]fn absolute_and_bare_names_are_accepted() {- assert!(validate_app_identifier(r"C:\Windows\System32\notepad.exe").is_ok());- assert!(validate_app_identifier(r"\\?\C:\Windows\notepad.exe").is_ok());- assert!(validate_app_identifier(r"\\server\share\app.exe").is_ok());- assert!(validate_app_identifier("notepad.exe").is_ok());+ assert!(launch_identifier(r"C:\Windows\System32\notepad.exe").is_ok());+ assert!(launch_identifier(r"\\?\C:\Windows\notepad.exe").is_ok());+ assert!(launch_identifier(r"\\server\share\app.exe").is_ok());+ assert!(launch_identifier("notepad.exe").is_ok());+ }++ #[test]+ fn a_bare_name_without_an_extension_names_its_exe_image() {+ assert_eq!(launch_identifier("notepad").unwrap(), "notepad.exe");+ assert_eq!(launch_identifier("notepad.exe").unwrap(), "notepad.exe");+ assert_eq!(launch_identifier("mmc.msc").unwrap(), "mmc.msc");+ assert_eq!(launch_identifier(r"C:\Tools\app").unwrap(), r"C:\Tools\app");}#[test]@@ -234,7 +248,7 @@ mod tests {"bad\0name","bad\nname",] {- let error = validate_app_identifier(identifier).expect_err("unsafe identifier");+ let error = launch_identifier(identifier).expect_err("unsafe identifier");assert_eq!(error.code, ErrorCode::InvalidArgs);}}diff --git a/docs/phases.md b/docs/phases.mdindex d0ac4db93..04957691a 100644--- a/docs/phases.md+++ b/docs/phases.md@@ -1211,7 +1211,7 @@ Every Phase 2 sub-phase below is held to the same definition of done, stated onc**Goal:** Land process/window lifecycle — launch, close, resize/move/minimize/maximize/restore — with the same `ProcessState` liveness contract (U14) macOS ships.**Scope:**-- `launch_app` with `LaunchOptions` via `CreateProcessW` (args/env/cwd — Windows honours a launch `cwd` where macOS Launch Services rejects it — attach-vs-fail via `attach_if_running`). The `id` is an absolute path (drive + backslash, UNC, or `\\?\`) or a bare name that resolves only against the system directories (`System32`, the Windows directory) — never the calling-process directory, the current directory, or `PATH`, so a planted same-named binary cannot hijack execution (A21-1; `launch_path.rs`). Any other identifier is `INVALID_ARGS` before a native call. `CreateProcessW` is chosen over `ShellExecuteEx` because it is manifest-ready under already-enabled `Win32_System_Threading` and returns a `PROCESS_INFORMATION` handle that is a strong single identity primitive, so Windows needs less "launched" verification ceremony than macOS's four-signal `NSWorkspace` dance (A21-1, A21-8). Launch-by-display-name / AUMID (`ShellExecuteExW` / `IApplicationActivationManager`) is out of this sub-phase: A21-8 validated the shell binding in standalone scratch with `expand_2_9: false`, and §2.14 owns the capability+- `launch_app` with `LaunchOptions` via `CreateProcessW` (args/env/cwd — Windows honours a launch `cwd` where macOS Launch Services rejects it — attach-vs-fail via `attach_if_running`). The `id` is an absolute path (drive + backslash, UNC, or `\\?\`) or a bare name that resolves only against the system directories (`System32`, the Windows directory), where a name without an extension means its `.exe` image — never the calling-process directory, the current directory, or `PATH`, so a planted same-named binary cannot hijack execution (A21-1; `launch_path.rs`). Any other identifier is `INVALID_ARGS` before a native call. `CreateProcessW` is chosen over `ShellExecuteEx` because it is manifest-ready under already-enabled `Win32_System_Threading` and returns a `PROCESS_INFORMATION` handle that is a strong single identity primitive, so Windows needs less "launched" verification ceremony than macOS's four-signal `NSWorkspace` dance (A21-1, A21-8). Launch-by-display-name / AUMID (`ShellExecuteExW` / `IApplicationActivationManager`) is out of this sub-phase: A21-8 validated the shell binding in standalone scratch with `expand_2_9: false`, and §2.14 owns the capability- `close_app` with verified termination — success only after the process is observed gone via creation-time token + `WaitForSingleObject`/`GetExitCodeProcess` (A21-3), never an optimistic `closed: true` before exit (mirrors the v0.3.0 macOS `close-app` correction). Graceful posts `WM_CLOSE` to every top-level window owned by the target pid; force uses `TerminateProcess`. A protected process is refused with `INVALID_ARGS` + `not_delivered` before any native close (`crates/core/src/commands/close_app.rs` via `invalid_input_with_suggestion`; dogfood J2) — not `PERM_DENIED`- `window_op` (`SetWindowPos`/`ShowWindow` for resize/move/minimize/maximize/restore), verified by `GetWindowPlacement`/`GetWindowRect` re-read within an 8 px tolerance after ~80 ms wait-then-re-read (A21-5) — never UIA `-32000`/`IsOffscreen` (A1-2/A5-3/A14-8)- `ProcessState` probes: `IsHungAppWindow` as a cheap pre-check that agrees with authoritative `SendMessageTimeout(WM_NULL, SMTO_ABORTIFHUNG)` → `Unresponsive` (A21-4); exit-code inspection → `Exited`/`Crashed` (A21-3 NTSTATUS high-nibble rule)diff --git a/skills/agent-desktop-windows/SKILL.md b/skills/agent-desktop-windows/SKILL.mdindex b0ffa83ee..9dc03a549 100644--- a/skills/agent-desktop-windows/SKILL.md+++ b/skills/agent-desktop-windows/SKILL.md@@ -37,7 +37,7 @@ observation, actions and capture there fail or return nothing.| Multi-click and focus | `double-click`, `triple-click`, `focus` | Works with global `--headed`; focus is headed-required (A3-4, A19-5) || Keyboard and mouse | `press`, `hover`, `drag`, `mouse-click`, `mouse-move`, `mouse-wheel` | Works; cursor-moving input requires `--headed`; `press --app` synthesizes into the foreground queue after verification (fails closed headless if not already frontmost; non-interactive callers report `delivered_unverified`) || Held input | `key-down`, `key-up`, `mouse-down`, `mouse-up` | Fails closed with `ACTION_NOT_SUPPORTED` on every platform until a daemon owns held-input lifetime |-| App and window | `launch`, `close-app`, `list-windows`, `list-apps`, `focus-window`, `resize-window`, `move-window`, `minimize`, `maximize`, `restore` | Works; `launch` resolves an absolute path or a bare name under System32 or the Windows directory (A21-1), not display names |+| App and window | `launch`, `close-app`, `list-windows`, `list-apps`, `focus-window`, `resize-window`, `move-window`, `minimize`, `maximize`, `restore` | Works; `launch` resolves an absolute path or a bare name, with or without `.exe`, under System32 or the Windows directory (A21-1), not display names || Displays | `list-displays` | Works || Clipboard | `clipboard-get`, `clipboard-set`, `clipboard-clear` | Works; typed text and image content || Wait | `wait` | Works for ms, `--element`, `--window`, `--text`, `--menu`, `--menu-closed`, `--event`, and `--notification` predicates |@@ -71,7 +71,7 @@ observation, actions and capture there fail or return nothing.non-interactive caller (service, scheduled task, CI job) gets`delivered_unverified`.- **`launch` needs an absolute path** or a bare name under System32 or the- Windows directory, not a display name. Use `list-apps` to find a running app.+ Windows directory (`notepad` or `notepad.exe`), not a display name. Use `list-apps` to find a running app.- **Notifications:** `list-notifications` with the Action Center closed needs`--headed`. Single-item `dismiss-notification` and `notification-action` need`--headed` and `--expected-app` or `--expected-title` for the entry at INDEX.@@ -91,7 +91,7 @@ observation, actions and capture there fail or return nothing.- Ref actions are semantic UI Automation calls, in headless and `--headed` mode.- Notifications work over the Action Center and need `--headed`.- `launch` takes an absolute path or a bare name under System32 or the Windows- directory, not a display name.+ directory, with or without `.exe`, not a display name.- Held-input commands fail closed on every platform.- The cursor overlay renders only for headless semantic actions.- In key combos, `cmd` and `meta` are the Windows key, so `meta+c` is a shell