Agent-first GUI control for Linux desktops — a single 229 KB binary with zero
runtime dependencies, built for LLM agents.
- Single binary, zero Python/Node/JVM — perception in, actions out, JSON both ways.
- AT-SPI2: `state`, `find`, `act`, `type`, `watch` on GTK, Qt and Chromium.
- `state --via cdp`: the whole page DOM in **~60 ms**, real DOM `click()` — beats
headless-browser tools at their own game (benchmarks below).
- `state --expand`: scroll-sweeps Chromium's viewport-limited tree to full coverage.
- Drives your **live, signed-in browser session** — the thing headless tools
cannot touch — plus browser chrome, dialogs and the rest of the desktop.
- The Linux answer to [Windows-Use](https://github.com/Jeomon/Windows-Use),
written in [machin (MFL)](https://github.com/javimosch/machin).
🤖 **Driving this from an agent?** Read [`.agents/skills/linux-use/SKILL.md`](.agents/skills/linux-use/SKILL.md) — a drop-in skill for Claude Code / Devin / anything that reads `SKILL.md`. `linux-use guide` embeds the same manual in the binary.
📖 **[Docs & changelog](https://javimosch.github.io/linux-use/)** ·
📦 **[Releases](https://github.com/javimosch/linux-use/releases)** ·
✨ **[awesome-machin](https://github.com/javimosch/awesome-machin)**
**v0.7.1** — perception (memoized collection queries + walk fallback), actuation, a
filterable event stream, and a warm-registry daemon, aligned to [cli-specs.intrane.fr](https://cli-specs.intrane.fr/).
## The design bet
Windows-Use is a Python library with the LLM *inside* it (LangChain, provider
keys, its own `max_steps` agent loop). linux-use inverts that: it ships **zero
LLM code**. It is a pure sensor/actuator binary — perception in, actions out,
JSON both ways. Claude/Devin *is* the loop.
That makes it model-agnostic, testable, fast, and a natural fit for the
agent-first CLI specs.
## What actually works, and what is untested
Every "verified" row below was exercised by hand on this machine and is
reproducible from the commands in this README. Rows that say **not tested** are
not claims — they are gaps.
| Target | Status | Evidence |
|---|---|---|
| **GTK 3/4 apps** | verified | gnome-calculator, gnome-text-editor, gnome-control-center, gnome-disks, seahorse, Nautilus — read, act, type, watch |
| **Qt 5 apps** | verified | QDBusViewer: 12 interactive elements; `act` fired `ShowMenu` and the File menu opened |
| **Chromium/Edge web content** | verified, **needs `--force-renderer-accessibility`** | a test page exposed 41 elements incl. real DOM buttons/inputs; Microsoft Teams navigated, composed and sent |
| Chromium/Edge **without** that flag | **broken by design** | exposes exactly one `frame` — zero web content |
| **Electron apps** | not tested | expected to need the same flag |
| **Java (Swing/AWT)** | not tested | needs `java-atk-wrapper` |
| **Flutter / canvas / games** | expected to expose nothing | not tested |
| **Wayland** | `click`/`key`/`paste` exit 91 (`no_injector`) | XTEST cannot reach native Wayland clients; AT-SPI paths are expected to keep working (not tested). A Wayland injector is not planned ([#1](https://github.com/javimosch/linux-use/issues/1)) |
**Tested on exactly one configuration:** Ubuntu 22.04.3, GNOME 42.9, X11,
at-spi2-core 2.44.0, x86-64. Everything else is unknown territory:
- **Not tested:** Wayland, KDE/XFCE/other desktops, other distros or GNOME
versions, HiDPI or fractional scaling, multi-monitor, non-US keyboard
layouts (`key` maps keysyms through the active layout), arm64.
- **There is no automated test suite.** All verification was manual and
exploratory — the numbers and behaviours in this README are real measurements,
but nothing re-checks them on commit. `test/env.sh` is an isolation harness,
not a test runner. Treat this as a v0.x tool.
### Things that went wrong while building it
Documented because they are the honest failure modes of driving a desktop, not
because they are fixed forever:
- **It crashed a browser three times** before the cause was isolated to AT-SPI
key synthesis vs `--force-renderer-accessibility` ([#4](https://github.com/javimosch/linux-use/issues/4), fixed in 0.6.2 by
defaulting to the clipboard).
- **It broke the developer's live accessibility bus once**, because a private
Xvfb + D-Bus test environment still shares `at-spi-bus-launcher`'s socket path
unless `XDG_RUNTIME_DIR` is overridden too. Every already-running app went
invisible to accessibility until restarted. `test/env.sh` now sets it.
- **Two published measurements were wrong** and were corrected in later release
notes — a "zero memory growth" claim read off too short a run, and a
regression that turned out to predate the change blamed for it.
## Install
```sh
sudo apt install libatspi2.0-dev libxtst-dev libx11-dev libglib2.0-dev
gsettings set org.gnome.desktop.interface toolkit-accessibility true
./build.sh
```
`linux-use doctor` will tell you if anything is missing.
## The loop
```sh
linux-use apps # who is running and exposes a11y
linux-use state --app gnome-calculator # interactive elements, with refs
linux-use act 'gnome-calculator:/0/1/0/1/0/0/1/0/22#18124260'
linux-use read # verify the effect
```
An element ref comes in two kinds, and `ref_kind` says which:
- **path** — `app:/0/1/0/22#18124260` — addressed by child indices.
- **geometry** — `app:@43~150,352,64,44#18124261` — addressed by role and
on-screen rectangle, issued when a node has no provable path (see below).
Pass refs back verbatim. When the UI changes underneath one, the fingerprint
mismatches and you get **exit 83 `ref_stale`** with a suggestion to re-run
`state` — the tool never silently acts on the wrong widget.
### act vs click
`act` invokes the widget's own accessible action: no focus change, no pointer
movement, and **it works while the window is fully occluded by another window**.
`click` synthesizes a real XTEST pointer event and is the fallback for widgets
that expose no action. Prefer `act`.
## Recipes
[javimosch/linux-use-recipes](https://github.com/javimosch/linux-use-recipes)
collects field-tested patterns: a headless Xvfb browser linux-use can drive,
the AT-SPI gotchas that silently break automations (offscreen elements, paste
semantics, missing WM), posting a Reddit comment end-to-end, and verifying
actions server-side.
## Commands
```
apps applications with pid, toolkit, window count
windows [--app X] top-level windows: geometry, title, active
state --app X [--pid N] [--depth N] [--role R] [--all] [--collection|--walk]
find [--app X] search elements by name substring
act [--action N] invoke the accessible action (preferred)
read text, name, description
type [--replace] [--allow-password]
sendtext [--via auto|clipboard|atspi]
type at the current focus (no ref needed)
paste [--no-restore] clipboard + ctrl+v
key [--dry-run] e.g. ctrl+shift+t, alt+F4 (X11 only)
click | --x N --y N [--button B]
launch [--wait-for APP] [--timeout MS]
watch [--app X] [--role R] [--events ...] [--max-events N] [--duration MS]
[--max-rss KB]
stream AT-SPI events as NDJSON
roles every valid --role name
pointer current pointer position
doctor environment health
serve [--host] [--port] | daemon start|stop|status [--host] [--port]
guide [--human] | help-json | version
feedback report a bug/idea (FEEDBACK_RELAY=off to skip relay)
telemetry [--off] show the exact anonymous payload / disable it
update [--check] [--force] self-update from the content-hash version endpoint
install [--prefix DIR] copy binary to DIR (default ~/.local/bin)
uninstall [--prefix DIR] remove it
```
## watch — block on a UI change instead of polling
```sh
linux-use watch --app gnome-calculator --duration 5000
{"event":"object:text-changed:insert","app":"gnome-calculator","role":"editbar",
"name":"","ref":"gnome-calculator:/0/1/0/1/0/1/1/0#749312667","ref_ok":true,
"detail1":0,"detail2":1,"ts":1786455..}
```
One JSON object per line on stdout, flushed immediately; the banner goes to
stderr so stdout stays pure NDJSON. `--max-events N` stops after **exactly** N.
`--duration MS` bounds the wait. Events are real AT-SPI callbacks — no polling.
Each event carries a reconstructed `ref` (walked UP from the event source to
its application) plus **`ref_ok`**. `ref_ok:false` means an ancestor index could
not be determined and the ref would be wrong — it is reported as unusable
rather than emitted as a plausible lie.
Two behaviours worth knowing:
- **Observer effect.** Reading the tree (`state`/`find`) makes toolkits emit
accessibility events. In one measured run, 72 of 101 events were
`state-changed:checked` churn induced by linux-use's own walks. That event
type is therefore **not** in the default set (opt back in with `--events`);
the same run then yielded 38 events, all genuine.
- **`--role` is the cheapest noise filter.** One sample run went from 54 events
to the 6 that mattered by adding `--role editbar`.
- **A label's name IS its text.** So a ref captured from an event on a label
reports `ref_stale` on the next read — correctly: the staleness *is* the
signal that the content changed. Drop the `#fingerprint` to address the path
alone, or re-run `state`.
## Geometry refs: when a widget has no provable path
v0.5 fell back to a full tree walk whenever a collection match could not be
pathed (14 of 37 elements in gnome-control-center). Diagnosing it turned up
something more interesting than an identity bug — **broken parent/child
reciprocity**:
```
NODE filler '' [472,112 578x100]
parent panel '' [472,112 578x100] children=1 index_in_parent=-1
-> pointer match: -1 | role+name+extents match: -1
```
The node's `get_parent()` returns a container that does **not** list it among
its children, by any comparison. Such a node is reachable top-down but has no
child-index path at all — impossible, not merely unknown. No identity test
could ever have fixed it.
So those nodes get a **geometry ref** instead: `app:@~x,y,w,h#`,
resolved with a collection query for that role, matched on exact extents and
verified by the same role+name fingerprint. Two widgets sharing a role and
rectangle are reported ambiguous; a rectangle with no match returns exit 84.
A geometry ref never silently resolves to the wrong widget — but it *is* tied
to screen position, so moving or resizing the window invalidates it.
The `collection+walk` fallback is gone. Every match is addressable:
| app | method | default | `--walk` | geometry refs |
|---|---|---|---|---|
| gnome-calculator | collection | **15 ms** | 65 ms | 0 |
| gnome-text-editor | collection | **12 ms** | 53 ms | 0 |
| gnome-control-center | collection | **25 ms** | 44 ms | 14 |
All three return the same element set as the walk with every ref usable.
All 14 geometry refs in gnome-control-center resolve to the widget they
describe; `act` through one drives the app correctly.
## Collection queries: measured, not assumed
`state`/`find` ask AT-SPI's **Collection** interface to match server-side in one
round trip, and fall back to a tree walk when a match's ref cannot be proven.
v0.4 memoizes the climb from a match back to the application root — collection
matches are siblings sharing ancestors, so without it the same chain was
re-walked once per match and ate the entire benefit. Measured across six apps:
| app | default | method | `--walk` |
|---|---|---|---|
| gnome-text-editor | **12 ms** | collection | 71 ms |
| gnome-calculator | **23 ms** | collection | 97 ms |
| gnome-disks | **5 ms** | collection | 15 ms |
| seahorse | **15 ms** | collection | 29 ms |
| Nautilus | **560 ms** | collection | 625 ms |
| gnome-control-center | 76 ms | collection+walk | 69 ms |
| gnome-control-center `--role "push button"` | **4 ms** | collection | 47 ms |
Five of six apps are 1.1–5.9x faster with identical refs. The sixth cannot path
every match, so the query is re-run as a walk (`method: "collection+walk"`) and
costs ~10% more than walking directly — the price of never returning an
incomplete set by default.
Forcing: `--collection` keeps the fast result *including* `ref_ok:false`
entries; `--walk` skips the query entirely. `method` always reports what ran.
`linux-use roles` lists all 130 role names and flags the 18 interactive by
default. An unknown `--role` matches nothing and says so on stderr.
## The `watch` memory growth is upstream, and now bounded
`watch` grows about **0.14 kB per event**. v0.5 set out to close it and instead
proved it is not ours to close.
A probe with three callback bodies — a **no-op that only counts**, one that
reads role+name, and the full path-reconstructing one — all leak at the same
rate:
| callback | kB/event |
|---|---|
| null (count only) | +0.163 |
| props (role + name) | +0.157 |
| full (+ parent climb) | +0.181 |
Every allocation the probe makes lives inside an `arena` block, including its
own periodic reporting. A callback that does *nothing* still grows, so the
growth is inside libatspi's event delivery on at-spi2-core 2.44 — not in
linux-use. (The historical `AtspiEventListener` leak was fixed upstream in
2.21.1; this is a separate residual.) `atspi_accessible_clear_cache()` makes it
*worse*: +0.886 kB/event and roughly half the event throughput.
So the fix is to make it **bounded** rather than pretend it is closed:
```sh
# exit 90 above the ceiling; a supervisor restarts and keeps streaming
while :; do
linux-use watch --app firefox --max-rss 262144 || [ $? -eq 90 ] || break
done
```
`--max-rss` is off by default. At 0.14 kB/event a 256 MB ceiling is roughly
1.8 million events, so most agent workloads never reach it — bound short runs
with `--duration`/`--max-events` instead and this never comes up.
## Addressing the right app, and the right key
**Two apps can share a name.** Two browser profiles both publish `Microsoft
Edge`. A plain `--app` matching more than one is now **refused** with
`app_ambiguous` (exit 80) rather than resolving to whichever the desktop lists
first:
```
$ linux-use apps
{"name":"Microsoft Edge","pid":872010,"toolkit":"Chromium","windows":1,
"ref":"Microsoft Edge#pid872010"}
{"name":"Microsoft Edge","pid":924858,...,"ref":"Microsoft Edge#pid924858"}
"ambiguous_names":["Microsoft Edge"]
$ linux-use state --app 'Microsoft Edge' # -> app_ambiguous, exit 80
$ linux-use state --app 'Microsoft Edge#pid924858' # -> 39 elements
$ linux-use state --app 'Microsoft Edge' --pid 924858 # -> same
```
`apps` reports each `pid`, `toolkit` and a ready-made `ref` selector, and warns
on stderr when names collide. `windows` and `find` honour the same filter.
**X keysym names are case-sensitive.** `key` used to lowercase the whole combo
before lookup, so `alt+F4` failed with `unknown_key` while aliases like `enter`
masked the problem. Resolution now tries the alias table (case-insensitive),
then the token exactly as written, then capitalised:
| combo | resolves to |
|---|---|
| `alt+F4` / `alt+f4` | `Alt_L + F4` |
| `ctrl+F12`, `Print`, `Menu`, `shift+Insert`, `Pause` | as written |
| `ctrl+shift+t`, `enter`, `esc`, `pageup`, `super+left` | unchanged |
`key --dry-run` resolves and reports without injecting — so a combo can
be validated without closing a window to find out.
## Text entry: the clipboard is the default, for a reason
AT-SPI key synthesis (`atspi_generate_keyboard_event`) **crashes Chromium/Edge
launched with `--force-renderer-accessibility`** — reproduced on a bare
`` page with focus verified, 3/3 times, payloads of 11/16/112 chars
([#4](https://github.com/javimosch/linux-use/issues/4)). Since that flag is the
only way to make a browser expose web content to AT-SPI, the crash lands exactly
where the tool is most useful.
So since v0.6.2 text entry goes through the **clipboard** by default: set the
CLIPBOARD selection, send `ctrl+v` via XTEST, restore the previous clipboard.
That path never touches the AT-SPI input controller.
| command | what it does |
|---|---|
| `type ` | editable-text interface if available; else verifies focus, then clipboard |
| `sendtext ` | types at current focus; `--via auto` (default) picks clipboard when `xclip` is present |
| `paste ` | clipboard + `ctrl+v` explicitly |
Measured A/B on the repro page, focus verified on the input:
| mechanism | result |
|---|---|
| default (`clipboard+ctrl_v`) | text lands, **browser alive** |
| `sendtext --via atspi` | **browser dead** |
`linux-use doctor` reports which backend is actually in use, and warns if
`xclip` is missing (in which case entry falls back to the crashing path and says
so on stderr rather than silently killing a browser).
`type ` also **verifies the element actually took focus** before
synthesizing anything — `grab_focus` silently does nothing on some web
elements, and typing into an unknown focus is how a stray space presses whatever
button happens to be focused.
## Depth: shallow answers are now loud
v0.1 defaulted to `--depth 14` and silently returned a shallow tree.
gnome-text-editor's document node lives at depth 16, so `state --role text`
returned **0 elements** — an agent would conclude "there is no text field".
v0.2 defaults to `--depth 64` and every walk reports `deepest`,
`nodes_visited`, `depth_limit`, `depth_limited` and `truncated`. When a subtree
*is* cut, it warns on stderr and sets `depth_limited:true`:
```
$ linux-use state --app gnome-text-editor --role text --depth 14
warning: subtrees were cut at --depth 14 — deeper widgets are NOT in this result
-> count 0, depth_limited true # v0.1 said count 0 and nothing else
$ linux-use state --app gnome-text-editor --role text
-> count 1, deepest 16, depth_limited false
```
## Testing without touching your desktop
`test/env.sh` brings up a private Xvfb `:99` with its own D-Bus session **and
its own `XDG_RUNTIME_DIR`**:
```sh
. test/env.sh start # exports DISPLAY, DBUS_SESSION_BUS_ADDRESS, XDG_RUNTIME_DIR
. test/env.sh stop
```
The `XDG_RUNTIME_DIR` override is **not optional**. `at-spi-bus-launcher` puts
its socket at `$XDG_RUNTIME_DIR/at-spi/bus_0` — a fixed per-user path that does
*not* vary with `DBUS_SESSION_BUS_ADDRESS`. Without the override a private
launcher shares that path with the real session, and tearing the test
environment down **deletes the real session's a11y socket**, breaking
accessibility for every already-running app until it restarts. This was learned
by doing it.
## Spec compliance
| Spec | Status |
|---|---|
| cli-output-spec | ✅ stdout JSON only, stderr for warnings, semantic exit codes, typed errors with `recoverable` + `suggestions`, `help-json` exit-code map |
| cli-guide-spec | ✅ `guide` (JSON) and `guide --human`, plus `help-json` and `GET /guide`, `GET /llms.txt` on the daemon |
| cli-daemon-spec | ✅ `serve --host` (loopback `127.0.0.1` default, real bind), `daemon start\|stop\|status` idempotent, `GET /_health` with `service`+`pid`, `POST /_shutdown` responds then exits, bearer-token gated off-loopback |
| cli-update-spec | ✅ `update [--check] [--force]` content-hash update via `GET /version.json`, atomic swap with `.bak` rollback, `install`/`uninstall`, hourly passive nudge on stderr (`LINUX_USE_NO_NUDGE=1` to silence) |
| cli-feedback-spec | ✅ `feedback ` — relay-only variant, idempotent id, never fails the caller (`FEEDBACK_RELAY=off` to skip) |
| cli-telemetry-spec | ✅ `telemetry [--off]` — allow-listed fields only (`tool`/`version`/`event`/`verb`/`os`/`arch`/`exit_class`/`ts`), off in CI, honors `DO_NOT_TRACK=1` and `LINUX_USE_TELEMETRY=0`, one-shot disclosure on stderr |
| cli-trial-spec | ⬜ N/A — local tool, no hosted trial tier |
Exit codes: `0` ok · `3` daemon stopped · `5` update available · `80` usage ·
`81` no_a11y · `82` app_not_found · `83` ref_stale · `84` ref_not_found ·
`85` no_capability · `86` action_failed · `87` no_display · `88` daemon ·
`89` refused · `90` rss_limit/permission · `91` no_injector · `100` external · `110` internal.
Ambiguous `--app` reports `app_ambiguous` under exit `80`.
Telemetry is anonymous and allow-listed; run `linux-use telemetry` to see the
exact payload that would be sent. `linux-use telemetry --off` persists the
opt-out, and `DO_NOT_TRACK=1` is honored. Telemetry never affects exit codes
or command behavior.
## Measurements (Ubuntu 22.04, GNOME 42.9, X11 — on an isolated Xvfb desktop)
- **Perception**: 20+ apps enumerated; `gnome-calculator` → 28 interactive
elements in **88 ms**. Microsoft Edge (Chromium) exposes its tree too.
- **Full loop**: `find 7 / + / 5 / =` → four `act` calls → tree shows
`label '7+5'` and `label '12'`. The window was **occluded the whole time**.
- **type**: inserted 25 chars into gnome-text-editor via the editable-text
interface, read back byte-identical.
- **key**: `ctrl+shift+z` resolved to `Control_L + Shift_L + z` through the
live keyboard layout and injected via XTEST.
- **Errors**: tampered fingerprint → exit 83; bad path → 84; unknown app → 82.
- **Daemon**: warm registry, `/v1/apps` in ~50 ms, clean `/_shutdown`.
- **Refcounting**: RSS 4500 → 4532 kB across **300 tree walks** (~8,700 nodes);
4488 → 4512 kB across 200 walks at the new depth 64. Essentially flat.
- **watch**: 450 events streamed while driving the app; `--max-events 5`
returned exactly 5; an event ref resolved to the right widget once the
volatile fingerprint was accounted for.
- **Collection**: identical refs to the walk on every app tested, zero wrong
refs; 1.1–5.9x faster on five of six apps after memoizing path reconstruction.
- **watch --role**: 54 events → 6 with `--role editbar`.
- **watch memory**: the arena fix cut per-event growth from **~17 kB/event**
(8304 → 15812 kB over 450 events) to **~0.17 kB/event** — a ~100x reduction,
but *not* zero. An earlier version of this README claimed zero; that was read
off two samples that happened to coincide over a short run. Measured across
~1000 events, v0.3 and v0.4 both grow ~190 kB per 1000 events. Bound long
watches with `--duration`/`--max-events`; see Known limitations.
## vs CDP browser tools (flashbrowse, Playwright) — measured, and complementary
Same machine, dedicated-profile Edge on Xvfb (linux-use 0.7.1) vs headless
Chrome over CDP ([flashbrowse](https://github.com/nhrbuilds/flashbrowse)
v1.2.1, built from source):
| page | linux-use `state` | linux-use `state --expand` | linux-use `state --via cdp` | flashbrowse `open` |
|---|---|---|---|---|
| 300-row table (1,500 widgets) | 0.7 s — 568 elements: rows ~0–54, the rest never entered the AT-SPI tree | ~6 s — **all 300 rows (3,018 elements)** | **0.4 s — all 900 widgets, full document** | ~1.3 s incl. cold Chrome spawn — **all 1,200 actions** |
| MDN HTML reference (real) | — | — | 0.37 s — 422 elements | 2.7–4.7 s — 150 actions |
| Wikipedia population list (heavy) | 0.48 s — 120 elements (viewport only) | — | 0.48 s — 1,767 elements | 5.1–9.4 s — 1,954 actions |
| 3,000-row table (15,000 widgets) | 0.85 s — same ~560-element window; `--all` 4.6 s, truncated at 20k nodes | incremental (per-viewport scrolls, no all-or-nothing fetch) | one DOM query, same shape | no output in 90 s — full-AX-tree fetch/settle never finished |
Warm `act` is a bigger gap than cold `state`: linux-use fires a DOM click
through a ref that carries its own address (~70 ms median), while
flashbrowse re-fetches the whole AX tree to rebuild its action map on every
`act` call (~850 ms measured on the same session).
`state --via cdp` skips the AX tree entirely: one `Runtime.evaluate` DOM
query returns every interactive element with document coordinates and an
xpath ref (~60 ms internal on this page; wall time is mostly binary
startup). `act` on a `cdp:#fp` ref fires a real DOM `click()`
through the same channel — no pointer, no focus, works while the window is
occluded. It needs `--remote-debugging-port` on the browser's command line,
which means a **dedicated profile** (`contrib/a11y-browser` with
`A11Y_CDP_PORT=PORT`) — Chromium refuses the flag on the live profile, and
that is the correct boundary anyway.
Neither column is a "linux-use is faster" claim. AT-SPI is fast because
Chromium only materializes AX nodes near the viewport; `--expand` closes the
coverage gap by driving the scrollable container's own `scrollForward`
accessible action and merging passes by ref path — incremental, so it still
completes on pages where a full-tree fetch stalls.
**The two tools are complements, not competitors.** flashbrowse reads the
whole document in one shot from a browser it owns — the right answer for
websites with no live-session requirement (public-web scraping, CI
automation; its compressed action tree also runs ~7–18x fewer tokens than
Playwright AX snapshots). linux-use is the only door when the target is the
user's signed-in browser (Chrome refuses `--remote-debugging-port` on the
default profile), the browser chrome itself (omnibox, dialogs, permission
prompts), or anything that is not a web page. A typical agent run uses both:
flashbrowse for the public web, linux-use for the session.
### Closing the remaining gap — roadmap
- [x] **coverage** — `state --expand`: whole page via the container's own
scroll actions (landed)
- [x] **payload size** — `--format lines`: ~half the tokens of the JSON
envelope (landed)
- [x] **`find --expand`** — sweep below the fold and return only matches
(`find "Action 295"` → ref in ~7 s; landed)
- [x] **adaptive settle** — a short pre-probe delay plus re-probe-on-idle
instead of a fixed per-scroll wait (landed)
- [x] **metrics trail** — `state`/`find` append to
`~/.cache/linux-use/metrics.jsonl`; `linux-use stats` aggregates
min/avg/max ms per op (landed)
- [x] **CDP fast path** (`state --via cdp` + `act` on `cdp:` refs) — one
`Runtime.evaluate` DOM query for the whole page (~60 ms internal),
xpath refs, real DOM `click()` for act; dedicated-profile instances only
(landed)
## Hard-won machin FFI findings
These cost real debugging time and are the non-obvious part of this codebase.
1. **A `string` returned across the FFI boundary ALIASES the C buffer — it does
not copy.** A helper returning a shared static buffer is therefore unsafe:
the next call clobbers every outstanding value. This showed up as `role` and
`app` both reading `"Calculator"`.
2. **The copy is lazy enough that `g_free` beats it.** `substr(v, 0, len(v))`
*looks* like a copy and survives a buffer overwrite, but freeing the
underlying pointer afterwards yields **silently truncated strings**, not a
crash. `bytes_str(bytes(v))` forces a materialized copy and is safe — that
is what `takestr()` uses, and the reason it is written that way.
3. **`len()` on an FFI-aliased string can return a stale length**, so even a
C-provided `strlen` does not rescue `substr`.
4. **Do not name a function after a machweb/framework parameter.** A top-level
`func handler(...)` collides with `serve(port, handler)`'s parameter and
surfaces as the misleading `cannot infer struct type for field .path`.
5. **`cflags` must come from `pkg-config --cflags atspi-2`** — atspi's headers
pull in `dbus/dbus.h`, which is not on the default include path.
6. **A long-lived FFI callback needs an `arena` block.** Per-request work in a
machweb daemon is freed when its goroutine ends, but an AT-SPI event
callback runs forever in one frame — every string it builds accumulates
(measured: ~17 kB/event). Wrapping the body in `arena { }` made growth
exactly zero. Two constraints: the callback must be **captureless** (globals
only — a captured variable is a compile error), and **no `return` may appear
inside the arena block** (ARENA002), so early exits become a flag.
7. **`atspi_accessible_get_index_in_parent` cannot be trusted, in two ways.**
It returns -1 for some nodes (skipping that level builds a ref that looks
valid and resolves to the WRONG widget), and — worse — it can return a
*confidently wrong* non-negative value: in gnome-control-center it reported
0 for a child actually at index 1, producing refs that did not resolve at
all. Refs are addressed with `get_child_at_index`, so that is the authority:
treat the index as a hint, verify it, and scan the parent when it fails.
8. **`atspi_accessible_get_id` is not a usable identity here.** Tried as a
fallback for pointer comparison, it produced false matches and therefore
confidently wrong refs — worse than admitting ignorance. Reverted to pointer
identity, accepting `ref_ok:false` for the nodes it cannot prove.
9. **An empty AT-SPI match criterion must use `MATCH_ALL`, not `MATCH_ANY`.**
"Any of zero" is false, so a rule with `MATCH_ANY` over NULL attributes and
interfaces matches *nothing* — the query runs, succeeds, and returns an
empty array. Only the roles list uses `MATCH_ANY`.
10. MFL specifics: `for` is range-only (use `while`); no `eprintln`
(`write(2, …)`); `int()` does not parse strings (`parse_int`); lowercase is
`to_lower`; a lambda passed to `serve` must be inlined at the call site for
struct-field inference to flow.
## Known limitations
- **`SHOWING` != visible to the user.** An occluded widget is still `SHOWING`.
Real visibility needs the window stack; the guide warns agents about this.
- **Coverage is not universal.** GTK and Qt are verified; Chromium needs a
launch flag; Java, Electron and canvas-drawn UIs are untested or expected to
expose nothing. `state` returning 0 elements means "no accessibility", not
"empty window" — see the capability table above.
- **Wayland is unsupported for synthetic input.** XTEST cannot reach native
Wayland clients, so on Wayland `click`/`key`/`paste` fail with exit 91
(`no_injector`) rather than pretending to succeed; `--injector xtest` forces
XTEST for XWayland apps. AT-SPI `act`/`read` do not depend on the injector.
Wayland input is **not planned** ([#1](https://github.com/javimosch/linux-use/issues/1), closed); note that Ubuntu 24.04+
defaults to Wayland.
- **On long web pages, `state`/`find` see only viewport-realized nodes.**
Measured: a 300-row table exposed ~55 rows. Widgets below the fold are
absent from the tree entirely — scroll, then re-run `state`. See the CDP
comparison above for when a full-document tool is the better fit.
- **No automated tests.** See above.
- **x86-64 only.** No arm64 build.
- The tree walk is still recursive with a node budget; it warns and sets
`truncated:true`/`depth_limited:true` rather than silently capping.
- `watch` cannot yet dedupe repeated events; a chatty app produces a lot of
lines. Filter with `--role`/`--events` and bound with `--max-events`/`--duration`.
- `watch` grows ~0.14 kB per event inside **libatspi**, not linux-use (proven
with a no-op callback; see above). Bound long-lived listeners with
`--max-rss` and restart on exit 90.
## Next
1. **An automated test suite.** The most valuable missing thing: today every
claim here rests on manual runs.
2. Consecutive-event dedupe in `watch`.
3. Screenshots + a vision fallback for the apps that expose no tree.
## Layout
```
.agents/skills/ an agent skill describing how to drive this tool
contrib/ a11y-browser: launch Chromium a11y-forced, with its own profile
src/main.src the CLI (one file)
lu_helpers.h C shims: FFI string ownership + AtspiEvent accessors
build.sh machin encode (machweb + flags + app) -> machin build
test/env.sh isolated Xvfb + D-Bus + XDG_RUNTIME_DIR test desktop
spike/ the original feasibility spike, kept for reference
```
## Built with
- **[machin (MFL)](https://github.com/javimosch/machin)** — the Machine-First Language this is written in.
One source file plus a small C shim, compiled through C to a static binary.
- **[awesome-machin](https://github.com/javimosch/awesome-machin)** — other things built with machin.
- **[cli-specs.intrane.fr](https://cli-specs.intrane.fr/)** — the agent-first CLI spec family this follows.
## Author
Built by [Javier Arancibia](https://www.linkedin.com/in/arancibiajav/) · [intrane.fr](https://intrane.fr)
## License
MIT — see [LICENSE](LICENSE).