Repository navigation
feat: minimal tree encoding, max_tree_bytes, and get_tree_page search - #504
Conversation
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]>
There was a problem hiding this comment.
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_actionandset_valueignoretree_detailandmax_tree_bytes. Both go throughcapture_element_observation, which rebuilds the tree capture params fromDefaultand so drops the two new fields. The schema, README and SKILL.md advertise them on every mutating tool.- Docs say a
queryalone reads the whole tree after aninteractive_onlysnapshot; the code searches only the interactive view. The PR's own testquery_finds_page_text_an_interactive_view_left_outasserts the code's behaviour. withincombined 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: falselabels 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.
There was a problem hiding this comment.
🟡 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
- 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]>
|
Thanks for the reviews. All six findings are addressed in c59edae: |
There was a problem hiding this comment.
This is an auto review done by revuto.
Revuto completed the review and found no evidence-backed concerns.

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"onget_app_state,get_tree_pageand post-actioninclude_tree(newNodeDetail::MinimalandMinimalNodeinsrc/tree_encoding.rs).max_tree_bytesonget_app_stateand post-actioninclude_tree(fit_tree_cappedaroundfit_tree).0returns no nodes while the whole tree is still read, cached under a newsnapshot_idand spilled.get_tree_pagequery,role,within, plusinteractive_onlyandtree_detailoverrides (tree_page_view).interactive_onlyonget_app_statealso keeps the whole compacted tree beside the interactive view (CachedAccessibilitySnapshot::search_nodes), read only byget_tree_page.All new behaviour is opt-in, and existing behaviour is unchanged (see Compatibility).
Compatibility
Snapshots taken with
interactive_only: truekeep two lists.nodesis exactly what v0.7.60 cached: the interactive view, with its reparentedparent_indexvalues. Every action path reads it as before:element_indexresolution, semantic selectors, bounds and KWin frame lookups, and target recovery.search_nodesholds the whole compacted tree and is read only byget_tree_page. With no filter and the snapshot's own view,get_tree_pagepagesnodesexactly as before (same nodes and message). Withquery,role,withinorinteractive_only: false, it readssearch_nodes, so non-interactive text and containers stay searchable.withinis 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_stateagain withoutinteractive_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_onlysnapshot 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 byelement_index, read its title and price. Bytes are the tool-result text the host receives; tokens are estimated at ~3.5 bytes per token.These figures were taken before the compatibility change above, which only affects how an
interactive_onlysnapshot 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, newsnapshot_id; the cache held all 791 compacted nodes (322 interactive); a second call refreshes.element_indexfrom amax_tree_bytes: 0snapshot works forclick(search box, listing link) andscroll; minimal and full pages give the same indices.include_tree+max_tree_bytes: 0returnok: falsewithisError; a successful action returnsok, its message and the new snapshot.get_app_state(whole tree,interactive_only,verbose) andget_tree_pageoffset 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 wasperform_actionwith 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).role: link,role: link+name,text: "£",role: heading,role: section,role: static, an entry by name): identical results and messages.query: "£"withinteractive_only: falsereturns all 10 price texts.withinthe "Results" landmark (not in the interactive view) returns its 8 headings and links in the interactive view, or all 41 nodes withinteractive_only: false. A link found that way resolves for actions.Tests
tree_encoding::tests::minimal_*andtree_detail_parses_lowercase_names;server::tree_page_search_tests(interactive view vs whole cache, unchanged unfiltered paging, query, case,withinbounded 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) ininteractive_snapshot_pages_its_view_but_caches_the_whole_tree, andresearch_hit_on_a_link_is_clickable_in_the_interactive_snapshot;server::tree_spill_server_tests::max_tree_bytes_*.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, Pibuild:checkandtypecheck, Pi catalog--check.npm test: 12/12 tests pass locally.index.test.tsandpi-integration.test.tsdon't load on my Node 20 (fs.globSyncneeds Node 22+); CI runs them on Node 24.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_pagerow, post-action list), SKILL.md (+ plugin copy), CHANGELOG[Unreleased], and the regenerated Pi catalog.🤖 Generated with Claude Code