Skip to content

feat: minimal tree encoding, max_tree_bytes, and get_tree_page search - #504

Merged
avifenesh merged 2 commits into
agent-sh:mainfrom
edjash:compact-tree-detail
Nov 24, 2026
Merged

avifenesh merged 2 commits into
agent-sh:mainfrom
edjash:compact-tree-detail

Conversation

@edjash

@edjash edjash commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Closes #503

Summary

Opt-in options that let agents keep the whole accessibility tree in the local snapshot and retrieve only what they need, for long browser research sessions:

  • tree_detail: "minimal" | "compact" | "full" on get_app_state, get_tree_page and post-action include_tree (new NodeDetail::Minimal and MinimalNode in src/tree_encoding.rs).
  • max_tree_bytes on get_app_state and post-action include_tree (fit_tree_capped around fit_tree). 0 returns no nodes while the whole tree is still read, cached under a new snapshot_id and spilled.
  • get_tree_page query, role, within, plus interactive_only and tree_detail overrides (tree_page_view).
  • interactive_only on get_app_state also keeps the whole compacted tree beside the interactive view (CachedAccessibilitySnapshot::search_nodes), read only by get_tree_page.

All new behaviour is opt-in, and existing behaviour is unchanged (see Compatibility).

Compatibility

Snapshots taken with interactive_only: true keep two lists. nodes is exactly what v0.7.60 cached: the interactive view, with its reparented parent_index values. Every action path reads it as before: element_index resolution, semantic selectors, bounds and KWin frame lookups, and target recovery. search_nodes holds the whole compacted tree and is read only by get_tree_page. With no filter and the snapshot's own view, get_tree_page pages nodes exactly as before (same nodes and message). With query, role, within or interactive_only: false, it reads search_nodes, so non-interactive text and containers stay searchable. within is resolved on the whole tree, so a container the interactive view drops (a results landmark) still bounds a search of that view.

Why keep the whole tree: an agent navigates with the interactive view, then needs non-interactive content from the same page (prices, descriptions, headings) along with the indices of the links it will click next. In v0.7.60 that content is not in the snapshot, so the agent calls get_app_state again without interactive_only. That replaces the snapshot, so the indices it was about to use are refused. With this PR, one snapshot serves both. Hits on non-interactive nodes are evidence to read, not targets: their indices stay refused for actions, as in v0.7.60, while interactive hits (links, buttons) are clickable from the same snapshot.

Cost: an interactive_only snapshot holds a second copy of the tree in memory until the next snapshot replaces it.

Measurements

Debian 13, GNOME Shell 48.7 on X11, Chrome with --force-renderer-accessibility, eBay UK. Each sequence ran in one server process: go to eBay home, find the search box, search "handmade shortbread", read listing titles and prices, open the first listing by element_index, read its title and price. Bytes are the tool-result text the host receives; tokens are estimated at ~3.5 bytes per token.

Phase v0.7.60 (best effort: one snapshot per page, page until found) This PR
Find search box, search 94 KB (6 calls) 4.1 KB (5)
Read titles and prices 153 KB (5) 31 KB (3)
Read listing title and price 154 KB (5) 2.7 KB (3)
Whole sequence ~404 KB, 20 calls (~115k tokens) ~41 KB, 15 calls (~12k tokens)

These figures were taken before the compatibility change above, which only affects how an interactive_only snapshot resolves actions. Every call in the sequence and its result size is the same.

That is about 10x less tool-response text (~90% fewer bytes) for this workflow, against a baseline that stays within the MCP interface. An agent with shell access could instead search the v0.7.60 spill file directly at lower cost than paging; this PR gives a comparable result through MCP alone, which also works over HTTP (mcp --listen) and for hosts without file access. Token figures are estimates from byte counts.

Live checks against the same page (21/21):

  • max_tree_bytes: 0: no inline nodes, new snapshot_id; the cache held all 791 compacted nodes (322 interactive); a second call refreshes.
  • Queries run against that snapshot; a replaced snapshot is refused with its message.
  • element_index from a max_tree_bytes: 0 snapshot works for click (search box, listing link) and scroll; minimal and full pages give the same indices.
  • Readiness and truncation are still reported; a stale-snapshot click and a failed action with include_tree + max_tree_bytes: 0 return ok: false with isError; a successful action returns ok, its message and the new snapshot.
  • Without the new parameters, get_app_state (whole tree, interactive_only, verbose) and get_tree_page offset paging are identical between v0.7.60 and this branch (snapshot ids, spill paths and the timing-dependent readiness block excluded).

Action compatibility, live, after get_app_state(interactive_only: true) in v0.7.60 and in this branch on the same Chrome page. Each probe was perform_action with an action name no element has, which fails before any AT-SPI action is invoked, so nothing was clicked:

  • element_index: all 129 indices of the page resolve identically (84 resolved, the same 45 non-interactive nodes refused).
  • Selectors (role: link, role: link + name, text: "£", role: heading, role: section, role: static, an entry by name): identical results and messages.
  • Research on the same snapshot: query: "£" with interactive_only: false returns all 10 price texts. within the "Results" landmark (not in the interactive view) returns its 8 headings and links in the interactive view, or all 41 nodes with interactive_only: false. A link found that way resolves for actions.

Tests

  • New unit tests: tree_encoding::tests::minimal_* and tree_detail_parses_lowercase_names; server::tree_page_search_tests (interactive view vs whole cache, unchanged unfiltered paging, query, case, within bounded by a dropped container, role + minimal, stale snapshot). Regression tests compare against the v0.7.60 cache of the same tree: interactive_snapshot_resolves_element_index_exactly_as_v0_7_60, interactive_snapshot_resolves_selectors_exactly_as_v0_7_60, the default page (nodes and message) in interactive_snapshot_pages_its_view_but_caches_the_whole_tree, and research_hit_on_a_link_is_clickable_in_the_interactive_snapshot; server::tree_spill_server_tests::max_tree_bytes_*.
  • Passing locally: cargo fmt --check, cargo clippy --locked --all-targets -D warnings, cargo test --locked --no-fail-fast (868 lib tests plus integration), cargo doc -D warnings, mcp_safety_check.py, check_plugins.sh --binary, zod schema check, Pi build:check and typecheck, Pi catalog --check.
  • Pi npm test: 12/12 tests pass locally. index.test.ts and pi-integration.test.ts don't load on my Node 20 (fs.globSync needs Node 22+); CI runs them on Node 24.
  • Not run locally: cargo publish --dry-run, cargo audit, install_sh_test.sh, agnix, npm wrapper pack and tests (no packaging, install or dependency changes).

Docs

README (new "Low-token trees and searching the snapshot" section, get_tree_page row, post-action list), SKILL.md (+ plugin copy), CHANGELOG [Unreleased], and the regenerated Pi catalog.

🤖 Generated with Claude Code

Agents doing long web research through Chromium pay for the accessibility
tree on every look: a results page fills the 32 KB inline budget, and the
text they need (prices, descriptions) sits past it, so they page through
hundreds of KB with get_tree_page.

- tree_detail ("minimal" | "compact" | "full") on get_app_state,
  get_tree_page and post-action include_tree. Minimal keeps index, role,
  name, text that differs from the name, value, and non-routine states.
- max_tree_bytes on get_app_state and include_tree caps the inline tree;
  0 returns no nodes but still reads, caches and spills the whole tree, and
  leaves errors, warnings, truncation and readiness in the result.
- get_tree_page query / role / within search the cached snapshot without
  reading the desktop again; within is bounded on the whole tree.
- An interactive_only snapshot also keeps the whole compacted tree
  (search_nodes), read only by get_tree_page. Actions resolve against the
  interactive view exactly as before, and unfiltered paging is unchanged.

Measured on an eBay search-and-listing sequence: ~404 KB of tool results
in 20 calls before, ~41 KB in 15 calls after. Existing behaviour is
unchanged: get_app_state and get_tree_page output match v0.7.60 on a live
page, and after interactive_only all 129 element indices and the selector
probes resolve identically to v0.7.60.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@edjash
edjash requested a review from avifenesh as a code owner November 23, 2026 22:41
Copilot AI balanced review requested due to automatic review settings November 23, 2026 22:41

@revuto-review revuto-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an auto review done by revuto.


One functional gap and three smaller inconsistencies, all traced by reading the code (nothing was built or run).

  • perform_action and set_value ignore tree_detail and max_tree_bytes. Both go through capture_element_observation, which rebuilds the tree capture params from Default and so drops the two new fields. The schema, README and SKILL.md advertise them on every mutating tool.
  • Docs say a query alone reads the whole tree after an interactive_only snapshot; the code searches only the interactive view. The PR's own test query_finds_page_text_an_interactive_view_left_out asserts the code's behaviour.
  • within combined with the interactive view recomputes that view on the subtree alone, so it can differ from the snapshot's view.
  • Paging the whole tree with interactive_only: false labels the result "the interactive view".

Otherwise the compatibility claim holds as far as I traced it: action paths still read only nodes, nothing mutates the cached snapshot in place, and an empty tree with max_tree_bytes: 0 does not write a spill file.

Comment thread src/server.rs Resolved
Comment thread src/server.rs Resolved
Comment thread src/server.rs Resolved
Comment thread src/server.rs Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved defects drop requested tree options, omit valid live-region nodes from subtree results, hide spill-failure diagnostics, and add unnecessary full-tree cloning.

4 open issues
What changed in this PR

Adds opt-in controls to the Linux computer-use server that reduce accessibility-tree response size during long research sessions, addressing #503.

Changes:

  • Adds minimal node encoding and inline byte caps for snapshots and post-action trees.
  • Adds cached-tree searches by text, role, and subtree while preserving the interactive view used by actions.
  • Adds regression tests, usage documentation, and updated Pi tool schemas.
File Description
src/​tree_encoding.rs Adds minimal node serialization and encoding tests.
src/​server.rs Implements tree options, searchable snapshots, and regression tests.
skills/​computer-use-linux/​SKILL.md Documents low-token snapshot and post-action workflows.
README.md Explains encoding, byte caps, and snapshot searches.
plugins/​computer-use-linux/​skills/​computer-use-linux/​SKILL.md Updates the plugin’s matching workflow guidance.
pi/​extension/​generated-tools.ts Regenerates tool schemas, descriptions, and catalog hashes.
CHANGELOG.md Records the new tree retrieval capabilities.

Review effort: Balanced

Comment thread src/server.rs Resolved
Comment thread src/server.rs Resolved
Comment thread src/server.rs Resolved
Comment thread src/server.rs Resolved
- perform_action and set_value now pass tree_detail and max_tree_bytes to
  their include_tree capture (element_tree_capture) instead of defaults.
- get_tree_page resolves `within` on the whole tree and applies it to the
  snapshot's own interactive view (or one computed on the whole tree), so
  live-region text and parent_index values match the snapshot.
- get_tree_page copies only what a request reads; an unfiltered page in the
  snapshot's view copies the cached nodes alone, as before.
- Paging the whole tree no longer labels the page "the interactive view".
- A capped tree whose spill write fails keeps the write error in its note.
- Docs: query, role and within search the snapshot's view unless
  interactive_only=false is passed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@edjash

edjash commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the reviews. All six findings are addressed in c59edae: perform_action/set_value now pass tree_detail and max_tree_bytes through; within is resolved on the whole tree and applied to the snapshot's own interactive view; get_tree_page copies only what a request reads; the whole-tree page label and the query docs are corrected; and a failed spill write is reported under max_tree_bytes. Each code fix has a regression test.

@revuto-review revuto-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an auto review done by revuto.


Revuto completed the review and found no evidence-backed concerns.

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.

Low-token accessibility trees for long browser research sessions (minimal encoding, inline cap, snapshot search)

3 participants