Skip to content

Computer use CLI for AI agents

fix(macos): draw overlay controls as they arrive and hide a cleared label (#346)

Chris Tate893a4140d352
diff --git a/crates/macos/src/system/cursor_overlay/child.rs b/crates/macos/src/system/cursor_overlay/child.rs
index 472a3c70b..52d86f03c 100644
--- a/crates/macos/src/system/cursor_overlay/child.rs
+++ b/crates/macos/src/system/cursor_overlay/child.rs
@@ -7,7 +7,6 @@ use std::io::{Read, Write};
use std::os::unix::fs::PermissionsExt;
use std::os::unix::net::{UnixListener, UnixStream};
use std::path::{Path, PathBuf};
-use std::thread;
use std::time::Duration;
use super::bridge;
@@ -111,7 +110,7 @@ fn run() -> Result<(), AdapterError> {
bridge::rest();
state.resting = true;
}
- thread::sleep(Duration::from_millis(8));
+ wait_for_connection(&listener, Duration::from_millis(8));
}
Err(error) => {
let _ = cleanup(socket);
@@ -124,6 +123,20 @@ fn run() -> Result<(), AdapterError> {
}
}
+/// Waits up to `timeout` for the next control, waking as soon as one
+/// connects, so a control is drawn within the frame it was sent in rather
+/// than after a fixed sleep.
+fn wait_for_connection(listener: &std::os::unix::net::UnixListener, timeout: Duration) {
+ use std::os::fd::AsRawFd;
+ let mut ready = libc::pollfd {
+ fd: listener.as_raw_fd(),
+ events: libc::POLLIN,
+ revents: 0,
+ };
+ let millis = libc::c_int::try_from(timeout.as_millis()).unwrap_or(libc::c_int::MAX);
+ unsafe { libc::poll(&mut ready, 1, millis) };
+}
+
fn prepare_stream(stream: &UnixStream) -> std::io::Result<()> {
stream.set_nonblocking(false)?;
stream.set_read_timeout(Some(Duration::from_secs(1)))?;
@@ -152,7 +165,9 @@ fn handle(control: &CursorOverlayControl, state: &mut OverlayState) -> Result<bo
let instruction = if let Some(instruction) = control.instruction() {
instruction
} else {
- let config = CursorOverlayConfig::enabled(control.label().map(str::to_owned), 12)?;
+ let greeting_over_image = control.is_enable() && state.style.image().is_some();
+ let label = control.label().filter(|_| !greeting_over_image);
+ let config = CursorOverlayConfig::enabled(label.map(str::to_owned), 12)?;
owned = CursorOverlayInstruction::new(bridge::initial_point()?, &config, false)?;
&owned
};
diff --git a/crates/macos/src/system/cursor_overlay/child_tests.rs b/crates/macos/src/system/cursor_overlay/child_tests.rs
index 1b6d6294e..341acfa33 100644
--- a/crates/macos/src/system/cursor_overlay/child_tests.rs
+++ b/crates/macos/src/system/cursor_overlay/child_tests.rs
@@ -1,4 +1,5 @@
use super::*;
+use std::thread;
#[test]
fn accepted_stream_waits_for_a_delayed_control() {
diff --git a/crates/macos/src/system/cursor_overlay/cursor_overlay_bridge.m b/crates/macos/src/system/cursor_overlay/cursor_overlay_bridge.m
index 42ecd5a0e..24480c2d9 100644
--- a/crates/macos/src/system/cursor_overlay/cursor_overlay_bridge.m
+++ b/crates/macos/src/system/cursor_overlay/cursor_overlay_bridge.m
@@ -319,6 +319,9 @@ bool agent_desktop_cursor_overlay_run(const AgentDesktopCursorFrame *frames,
NSString *nextLabel = showsBubble ? @(config->label) : @"";
bool changedLabel = ![ADBubbleText.stringValue isEqualToString:nextLabel];
ADBubbleText.stringValue = nextLabel;
+ if (!showsBubble) {
+ [ADBubbleWindow orderOut:nil];
+ }
NSRect bubbleFrame = NSMakeRect(config->bubbleX,
mainHeight - config->bubbleY - ADBubbleHeight,
ADBubbleWidth,
diff --git a/skills/agent-desktop/references/commands-system.md b/skills/agent-desktop/references/commands-system.md
index 50434d15c..b9f6211cb 100644
--- a/skills/agent-desktop/references/commands-system.md
+++ b/skills/agent-desktop/references/commands-system.md
@@ -193,7 +193,7 @@ On macOS:
On macOS and Windows:
-- `--image` and `--pointer-image` take a PNG of at most 2 MiB and 1024 pixels per side, drawn at `--size` with the hotspot on the point the cursor targets. Relative paths resolve at `enable`. `--fill` and `--rim` conflict with `--image`. A missing or invalid image falls back to the arrow.
+- `--image` and `--pointer-image` take a PNG of at most 2 MiB and 1024 pixels per side, drawn at `--size` with the hotspot on the point the cursor targets. Relative paths resolve at `enable`. `--fill` and `--rim` conflict with `--image`. A missing or invalid image falls back to the arrow. With `--image`, `enable` draws no greeting.
- The pointer image shows on arrival at a pressable control. Text fields keep the arrow.
Windows accepts the motion settings but keeps its built-in motion.