Skip to content

fix(macos): reach the Dock, menu bar status items and system panels - #480

Merged
lahfir merged 76 commits into
mainfrom
laf/macos-shell-surfaces
Nov 3, 2026
Merged

lahfir merged 76 commits into
mainfrom
laf/macos-shell-surfaces

Conversation

@lahfir

@lahfir lahfir commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator
  1. On macOS, agent-desktop could not see or act on the Dock, menu bar status items, menu-bar-only apps, or panels like Control Center, because none of them has an ordinary window.
  2. Background apps with no window are now observed and driven through their process, so snapshot, find, click, set-value and --headed clicks work on them, --surface dock and --surface menu-bar-extras work on macOS, and --app also matches an app's executable name.
  3. Builds on feat(identity): resolve Linux and Windows refs through a capture ruleย #442 (stacked on its branch).

Known cost: list-row selection adds one AXParent read per press-less row during snapshots, about +7% on deep snapshots against #442.

Before

The status items and the Dock are not reachable: both lookups fail with PLATFORM_NOT_SUPPORTED and nothing on screen changes.

before.mp4

After

Fully headless: the agent opens Control Center, drills into Sound, sets the volume to 50%, then launches Calendar from the Dock. Each step shows the exact command and how long it took.

after.mp4

lahfir added 30 commits October 31, 2026 18:22
Every CLI call and batch item now runs in its own process, as on Windows
and Linux, instead of being forwarded to a long-lived background host.

- delete src/command_host, its process test and the libc dependency
- drop the forwarding branches in main and batch, needs_caller_process,
  and the host env scrubbing in the permission guide
- add a process test that commands start no host and connect to no host
  socket
- ask macOS users upgrading from 0.10.0 or later to restart once, note
  that permissions apply per CLI call, and that old refs must be retaken
Leftover hosts are now found from this user's process list: a shipped
agent-desktop executable whose environment carries the host marker. Each
one is checked by owner and start time before SIGTERM, and stopped with
SIGKILL if it is still running after 500 ms. The cleanup no longer reads
or depends on any file, so the old socket directory does not matter.
Old hosts are found by the environment marker alone, since a copied or
renamed binary still carries it. npm install now runs the new binary once
on macOS, so a leftover host stops at upgrade instead of at the next call.

Tested against real 1.0.2 hosts, including one started from a renamed copy:
both stop on npm install and the bin entry stays hard-linked.
The first agent-desktop call after the upgrade stops old hosts, so the
npm install step is not needed. Old hosts have no SIGTERM handler, so
SIGTERM alone ends them and the grace wait and SIGKILL are gone. The
tests keep the cases that guard safety: only an exact environment
marker counts, unmarked processes are left alone, and no command
reaches or removes a host socket.

Checked against two real 1.0.2 hosts, one started from a renamed copy:
both exit after one new call.
A host started with SIGTERM ignored, or one that is stopped, survives
SIGTERM. The process is chosen by its owner and environment marker, so
the signal adds no risk to other processes.
Without this, an old host keeps serving between the upgrade and the
first agent-desktop call. The install runs the new binary once after
linking on every successful path. A failure only warns and names the
command that stops the hosts; the install and the link are unaffected.
Calls still stop hosts too, which covers installs that skip scripts.
Without the host, a ref to a row in a list whose rows share an
identifier can act on another row after the list changes. The
CHANGELOG and the macOS skill say so, and ref_churn skips the checks
that relied on the host until identity-based resolution lands.

The sweep now reads each process's arguments once into a reused
buffer and checks start times only for marked processes, which cuts
its cost from about 5.7 ms to about 4 ms per call on a Mac running
around 730 processes. Checked in a VM against real 1.0.2 hosts:
normal, renamed, and one ignoring SIGTERM while stopped all exit.

Also: the decoy-socket test fails if any other host file appears, a
new test proves a marked copy running version is not killed, the
stale host-kill loop is gone from the E2E harness, and the identity
doc now limits its retained-token claim to macOS.
The sweep killed any process with the old host marker in its
environment, including a test Python process. It now also requires the
running process's code-signing identifier to be agent-desktop's, read
with csops. Every release is ad-hoc signed by cargo with an identifier
like agent_desktop-<hash>, which survives renaming and deletion of the
executable, so renamed and unlinked hosts are still stopped. The check
runs only for marked processes, so the per-call cost does not change.

Checked in a VM: real 1.0.2 hosts (normal, renamed, and one ignoring
SIGTERM while stopped) exit after one call, and a marked Python
process keeps running.

The pinned session namespace had no production caller once the host
was gone, so its field, builder, guards and tests are removed.
โ€ฆpture rule

macOS refs now carry a retained object from the accessibility remote-token
calls, looked up at runtime: a ref resolves to that exact element in a later
process, and a dead or mismatched one returns STALE_REF without a search.
Refs without one resolve only when they were unique over complete evidence at
capture and exactly one live element matches the same predicate now; anything
else is refused. Linux paths and Windows runtime ids no longer count as
identity. The in-memory retained session from the removed host is deleted.
โ€ฆm each landing

The census now reads the observed evidence, so a twin holding an id second-hand or an unread field still counts. A path landing is re-checked against the recorded predicate before it is used, a resolution under a held lease reuses it, and shell-surface refs find their container again.
Tokenless refs already go through the shared capture rule in core, so the macOS path fast path and broad search had no CLI caller left. FFI find now lands its fresh match through the locator anchor on every platform.
Saved refs on Windows resolve through core's capture rule and the locator anchor, and FFI find lands through the anchor too, so the strict path walk, broad search, tie-break and chrome repair tiers were dead. The verified process stamp check moved into an anchor test.
โ€ฆ read

A shallow capture without element tokens now reads the whole window once, counts uniqueness there, and presents its skeleton or subtree cut from that same read, so skeleton anchors and drilled refs can resolve on Linux and Windows. A drill reuses the walk its root resolution performs. Captures whose refs all carry element tokens keep their single walk.
โ€ฆ substitution

macOS ships bash 3.2, which cannot parse a case pattern's closing paren inside $( ), so the assertion failed with a syntax error even though the hint was right.
โ€ฆrills to their own capture

Pre-dispatch validation compared only a native id, so a recycled Linux path with new text could still take the action. A re-drill compared paths across captures and could prune its own root. Drill depth now counts from the drilled element, and a cut boundary that can never become a ref no longer forces a whole-window read.
The ref churn checks were skipped while a removed row's ref could land on its surviving neighbour. Element tokens fix that, so the checks run again, and the CHANGELOG limitation becomes the fix it now is.
โ€ฆ the lease for final pointer checks

Interval typing reused one handle after the first keystroke, so a replacement element could take the rest of the text; each keystroke now repeats the live identity check under its lease. Final hover and drag checks dropped the held lease and could wait on it again, and a tokenless drill skipped the depth validation every other snapshot runs.
โ€ฆ came from

find materialized every tokenless ref with unique_at_capture false, so a unique match could not be used on Linux or Windows. It now runs the same census over its own observation when that observation is a complete whole-window read.
โ€ฆ Windows, prove rooted find refs

Linux menu refs scope a tokenless entry to the open popup instead of refusing it, and tests that relied on an AT-SPI path as identity now refuse replacements through the predicate. Windows anchors land by position and leave identity to core's full-predicate check. A tokenless find --root evaluates over the whole-window read its root resolution performs, so its refs carry that read's capture proof.
โ€ฆandings in FFI find, popup-bound menu refs

Every tokenless ref is now proven by its own recorded predicate over the whole-window read it was published from, at snapshot, drill, find and hydration alike. FFI find re-identifies a landed handle before publishing it. A Linux menu ref keeps its popup binding through positional landing and is refused without it.
โ€ฆe exhaustive check, align docs

The exact-entry FFI calls now always refuse, so the ABI major moves to 7 and the docs say so. Capture proof and tokenless resolution share one ObservedTree::is_exhaustive check, LivePredicate moves to its own file, and AGENTS.md, the CHANGELOG, the Linux skill and the Windows twin E2E leg describe the capture rule as shipped.
Inline a one-use test helper, drop a completeness check the selection
probe already makes, collapse the verdict cache miss and the absent action
list into direct returns, fold the Windows empty-owner guard into its match,
drop a redundant serde default, let the E2E scenario keep its ref in the
cleanup-visible variable, and point the macOS page at the surface rules
instead of repeating them. No behavior change.
find --root on a root carrying an element token observed the whole window
to re-identify it, though a token re-identifies itself. Drill-down already
reads such a root's subtree directly. Both now go through one helper,
read_saved_root: a token root is read as its subtree and stands when the
subtree publishes no tokenless ref; otherwise, and for every tokenless
root, the whole-window capture proof still applies.
โ€ฆsaved ref

Resolving a tokenless ref re-reads its whole window to prove it is still unique. For a Chromium or Electron window that read ran the settle loop: three equal node counts 200 ms apart, so every action paid about 400 ms of sleep. On a page that kept changing the loop gave up, the observation was marked incomplete, and the ref was refused as unproven even though the element was identifiable.

Settling belongs to capture, where refs are published and proven unique. A read that only resolves a saved ref now walks once. Ambiguity, an absent element and a walk cut short by its budget are still refused.
โ€ฆooted find

The subtree fast path counted only nodes already known to be ref-able, so a
tokenless member whose actions were still unread passed the check, and
hydration could then publish it without a window-wide capture proof; acting
on it later failed with identity_not_unique. An unsettled node now counts as
addressable, as an unread token already counts as absent, so such a subtree
falls back to the window proof.
cargo deny fails the audit on a yanked crate. 1.14.1 is the latest
compatible release; nothing else in the lock file moves.
โ€ฆt exhaust

The 100 ms budget only bounded how fast an unrelated /usr/bin/true exits, so
a busy machine skipped the final group probe and failed the test. The reap
poll returns as soon as the child exits, so a 5 s ceiling keeps the test as
fast while removing the flake.
@lahfir
lahfir changed the base branch from laf/identity-linux-windows to main November 2, 2026 22:09
The observation command page still said macOS has no shell surfaces, and
the surfaces page and skill said a shell surface never takes --app, which
is wrong for macOS menu-bar-extras.

Two core tests now pin the process-owner path: a ref captured from a
windowless app resolves from its live process without the window list and
goes stale after a relaunch, and a locator observation of a process owner
saves a process-owned ref.
โ€ฆtract

macOS never implemented open_system_surface, so every call fell to the
trait default and said the whole command was unsupported, even for dock
and menu-bar-extras, which snapshot already reads. Those two are always
on screen, so opening one now returns it through the same resolve path,
behind the same --headed floor as Windows and Linux. Any other kind gets
a refusal that names the kinds to use and how to open Control Center or
Notification Center.
- A press that keeps focus on the same editor but replaces its content
  now counts as an observed effect. Notes' New Note answers AXPress with
  -25205 while creating the note, and the click reported ACTION_FAILED.
- A stepped control's value is re-read briefly after each step before
  the loop decides it stopped moving. A one-step-late readback made
  set-value give up halfway on the Control Center volume slider.
- When a step jumps over the target, the error now says the step skips
  that value and names the two values the control can reach.
- open-system-surface on macOS no longer needs --headed: the Dock and the
  menu bar extras are always on screen, so nothing is raised.
A caller that asks for a surface kind this OS does not have used to get
PLATFORM_NOT_SUPPORTED, which reads as the whole capability being missing.
Only the argument was wrong, so every platform now answers INVALID_ARGS,
names the kind, and lists the kinds this OS accepts. Genuine platform
limits (no shell session, no tray watcher) keep their code.

Docs and skills follow, and note that macOS open-system-surface returns
dock and menu-bar-extras headless.
The INVALID_ARGS change also caught adapters that support no snapshot
surface at all, such as the FFI stub adapter and a Linux session with no
bus. There the argument is fine and the platform cannot snapshot, so that
case returns PLATFORM_NOT_SUPPORTED again. A kind the platform lacks while
it roots others stays INVALID_ARGS. The Windows capability test now
expects INVALID_ARGS for quick-settings, matching the Windows skill.
List-row selection (rows with no press action, selected through their
container) is unrelated to the Dock, menu bar and windowless-app fixes,
so it moves to its own pull request. The stepped-control failure now has
one message: the steps cannot reach the target, with the last step's
before and after values.
โ€ฆace's window

- A focused editor that keeps focus and changes its text counts as a
  press's effect only when it sits in the pressed element's own window.
  Text changing in an unrelated window no longer verifies a press.
- open-system-surface leaves `window` out when no window presents the
  surface (the macOS Dock and menu bar extras), as snapshot already does,
  instead of returning an empty id.
- macOS shell-surface lookup reports an incomplete app inventory instead
  of concluding the surface is absent.
- A windowless owner with no title is refused instead of falling through
  to the app's only window.
- Core and Linux share one builder for the unavailable-surface refusal.

BREAKING CHANGE: a surface kind the OS does not have now returns
INVALID_ARGS instead of PLATFORM_NOT_SUPPORTED (an adapter with no
surfaces still returns PLATFORM_NOT_SUPPORTED), and on macOS
open-system-surface for dock and menu-bar-extras succeeds headless with
no `window` in its data.
โ€ฆ contract

macOS supports dock and menu-bar-extras headless and returns no window.
An unavailable surface kind returns INVALID_ARGS; an adapter with no
surfaces still returns PLATFORM_NOT_SUPPORTED.
โ€ฆ its effect

A press whose return code proves nothing was verified only when focus
landed on the pressed element or the same focused editor changed its
text. Pressing Notes' New Note while focus sat in the notes list moved
focus into the new note's editor, which neither rule saw, so a press that
created the note reported ACTION_FAILED. Any focus move or content change
inside the pressed element's own window now counts; changes in other
windows still prove nothing.
@lahfir
lahfir merged commit 31b757a into main Nov 3, 2026
38 checks passed
lucamaraschi added a commit to lucamaraschi/agent-desktop that referenced this pull request Nov 3, 2026
Picks up the Dock, menu bar status item and system panel support (vercel-labs#480).
The macOS skill keeps main's --app identity wording, which already
covers the bundle id the policy branch had added.
lucamaraschi added a commit to lucamaraschi/agent-desktop that referenced this pull request Nov 4, 2026
Picks up the Dock, menu bar status item and system panel support (vercel-labs#480).
The macOS skill keeps main's --app identity wording, which already
covers the bundle id the policy branch had added.
immakermatty added a commit to Lazurio/agent-desktop that referenced this pull request Nov 18, 2026
os_surfaces.sh clicked the menu-bar-extras Control Center item with
--wait-for "button:Sound". The scenario came with vercel-labs#480, when a post-action
wait read the whole app. vercel-labs#376 then made the wait keep a process-owned
ref's source surface (pinned by
process_owned_wait_uses_process_window_and_refuses_unmarked_missing_window
and documented in commands-interaction.md), so the wait reads only the
AXExtrasMenuBar root of the item. On a test Mac (macOS 26.6.2) every poll
of the 30 s wait visited the same 7 nodes (the bar and its six status
items) while the panel was open as a dialog under the Control Center app
root, still named "Sound" with role button.

Follow the documented way to observe a surface outside the ref's scope:
click the item, require ok=True, then wait for the Sound button with
snapshot --app "Control Center" -i --wait-for. The rest of the leg is
unchanged. A contract test keeps the click and the panel wait apart and
gates the Sound click on both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants