Computer use CLI for AI agents
Rust accessibilityaccessibility-apiai-agentsautomationclicomputer-usecomputer-use-agentcomputer-use-agentsdesktop-automationmacosmcprust
fix: keep the macOS cursor overlay in place across headed commands (#715)
Chris Tatee8934a5e95e1
diff --git a/CONCEPTS.md b/CONCEPTS.mdindex 34f06d85e..f2f9337c5 100644--- a/CONCEPTS.md+++ b/CONCEPTS.md@@ -234,7 +234,7 @@ The side-effect contract attached to an action request, controlling whether theCore owns the precondition each action declares: a focused window for keyboard or focus-sensitive work, a focused window plus a verified cursor target for pointer delivery. Core satisfies it before dispatch. For a window-owned ref action, core focuses the exact source window, not merely the owning application. For an application-owned target, core can focus the app and still verify any pointer target. macOS native application-menu items use that application-level path for click, right-click, double-click, and triple-click. `hover` and `drag` remain window-owned and fail when the ref has no source window. The platform adapter owns the OS-specific focus primitive and delivery mechanism. Raw coordinate input has no ref identity, so it never infers or focuses a window. Which actions a headed policy makes physical rather than semantic is per-action and per-platform, and is settled by that action's own chain rather than by the policy. On Windows, `type` has no semantic headless path, because UIA offers no insert-at-selection write. Strict-headless `type` therefore fails at policy, and `set-value` is the headless text path. Headed `type` synthesizes keys physically (A4-1).### Agent Cursor Overlay-An optional presentation-only cursor driven by verified action destinations. Its whole configuration (label, colours, size, and click effects) is set once per session with `session start --cursor` or `cursor-overlay enable`; action and batch commands inherit it and take no cursor flags. Motion models a human hand and the cursor never rotates or resizes. The renderer acknowledges arrival before the action dispatches, under a bounded timeout, so the picture and the real effect stay in step. A click plays a ripple and flashes an outline around the element. A `--headed` mutating command hides the overlay before it dispatches and shows it again afterwards; on Windows the renderer stays suppressed for headed input and draws only for headless semantic actions. It never moves or replaces the OS pointer and never changes Interaction Policy, action delivery, or response semantics. Configuration, motion, and effect timing live in `agent-desktop-core`; macOS, Windows and Linux (X11 only) supply native renderers, and an adapter that does not override `update_cursor_overlay` refuses with `PLATFORM_NOT_SUPPORTED`, which dispatch treats as `rendered: false`.+An optional presentation-only cursor driven by verified action destinations. Its whole configuration (label, colours, size, and click effects) is set once per session with `session start --cursor` or `cursor-overlay enable`; action and batch commands inherit it and take no cursor flags. Motion models a human hand and the cursor never rotates or resizes. The renderer acknowledges arrival before the action dispatches, under a bounded timeout, so the picture and the real effect stay in step. A click plays a ripple and flashes an outline around the element. A `--headed` mutating command hides the overlay before it dispatches and shows it again afterwards; on Windows the renderer stays suppressed for headed input and draws only for headless semantic actions. On macOS the cursor stays on screen through that hide and starts its next move from where it last landed; only a hide that cancels a drag takes it off screen and forgets the grab point. It never moves or replaces the OS pointer and never changes Interaction Policy, action delivery, or response semantics. Configuration, motion, and effect timing live in `agent-desktop-core`; macOS, Windows and Linux (X11 only) supply native renderers, and an adapter that does not override `update_cursor_overlay` refuses with `PLATFORM_NOT_SUPPORTED`, which dispatch treats as `rendered: false`.For harness subagents, `session start --cursor --multi-agent` enables a cursor per `(session-id, agent-id)` (macOS, Windows, and Linux X11). The harness assigns each subagent a stable global `--agent-id` or `AGENT_DESKTOP_AGENT_ID`. The CLI requires this identity for desktop UI actions in that mode. The interaction lease still serializes physical input on the shared OS pointer. A headless action moves its cursor before it takes the lease, so several agents' cursors travel at the same time while their actions take turns. Commands that draw the same cursor take turns from its travel to its click effect. Each cursor reuses the same rendering and fade behavior; snapshots remain shared by session. Optional agent profiles override presentation only, and session disable/end removes every cursor.diff --git a/crates/macos/src/system/cursor_overlay/child.rs b/crates/macos/src/system/cursor_overlay/child.rsindex 722d20218..ac19ad052 100644--- a/crates/macos/src/system/cursor_overlay/child.rs+++ b/crates/macos/src/system/cursor_overlay/child.rs@@ -21,6 +21,7 @@ struct OverlayState {motion: CursorMotionProfile,moves: u64,at: Option<Point>,+ dragging: bool,resting: bool,}@@ -152,13 +153,12 @@ fn handle(control: &CursorOverlayControl, state: &mut OverlayState) -> Result<boif let Some(image_changed) = absorb_settings(control, state) {bridge::apply_style(&state.style, image_changed);}- if control.is_hide() {- bridge::hide();- apply_landing_memory(control, state, None);- return Ok(true);- }- if control.is_show() {- bridge::show();+ if control.is_hide() || control.is_show() {+ if control.is_show() {+ bridge::show();+ } else if state.dragging {+ bridge::hide();+ }apply_landing_memory(control, state, None);return Ok(true);}@@ -210,7 +210,9 @@ fn apply_landing_memory(instruction: Option<&CursorOverlayInstruction>,) {if control.is_hide() {- state.at = None;+ if std::mem::take(&mut state.dragging) {+ state.at = None;+ }return;}if control.is_show() {@@ -222,7 +224,8 @@ fn apply_landing_memory(if bridge::is_caret(instruction) {return;}- state.at = Some(if instruction.phase() == CursorPhase::Drag {+ state.dragging = instruction.phase() == CursorPhase::Drag;+ state.at = Some(if state.dragging {instruction.drag_from().unwrap_or(instruction.destination())diff --git a/crates/macos/src/system/cursor_overlay/child_tests.rs b/crates/macos/src/system/cursor_overlay/child_tests.rsindex 341acfa33..aea94674c 100644--- a/crates/macos/src/system/cursor_overlay/child_tests.rs+++ b/crates/macos/src/system/cursor_overlay/child_tests.rs@@ -138,13 +138,53 @@ fn presented(session: &str, instruction: CursorOverlayInstruction) -> CursorOver}#[test]-fn hide_clears_the_remembered_landing_for_the_next_travel() {- let mut remembered = state(Some(Point { x: 100.0, y: 100.0 }));+fn hide_after_a_drag_clears_the_remembered_landing_for_the_next_travel() {+ let mut remembered = OverlayState {+ at: Some(Point { x: 100.0, y: 100.0 }),+ dragging: true,+ ..OverlayState::default()+ };let control = CursorOverlayControl::hide("run-failed-drag".into());apply_landing_memory(&control, &mut remembered, None);assert_eq!(remembered.at, None);+ assert!(!remembered.dragging);+}++#[test]+fn hide_around_a_headed_command_keeps_the_remembered_landing() {+ let previous = Point { x: 100.0, y: 100.0 };+ let mut remembered = state(Some(previous.clone()));+ let hide = CursorOverlayControl::hide("run-headed".into());++ apply_landing_memory(&hide, &mut remembered, None);+ assert_eq!(remembered.at, Some(previous.clone()));++ let next = Point { x: 800.0, y: 300.0 };+ let frames = motion_frames(+ &remembered,+ &instruction(next.clone(), false),+ &screen(),+ 120,+ );+ assert_eq!(frames.first().map(|pose| &pose.point), Some(&previous));+ assert_eq!(frames.last().map(|pose| &pose.point), Some(&next));+}++#[test]+fn travel_and_effect_phases_end_the_drag() {+ let mut remembered = OverlayState {+ dragging: true,+ ..OverlayState::default()+ };+ let travel = instruction(Point { x: 10.0, y: 10.0 }, false);+ apply_landing_memory(+ &presented("run", travel.clone()),+ &mut remembered,+ Some(&travel),+ );+ assert!(!remembered.dragging);}#[test]