Skip to content

feat(android): give agents a compact UI tree - #395

Merged
ElbertePlinio merged 4 commits into
mainfrom
feat/351-compact-ui-tree
Oct 28, 2026
Merged

ElbertePlinio merged 4 commits into
mainfrom
feat/351-compact-ui-tree

Conversation

@ElbertePlinio

Copy link
Copy Markdown
Member

android_get_ui_tree returned the raw uiautomator dump XML. A busy screen cost thousands of tokens, and most nodes held nothing an agent could read or act on, so agents skipped the tree and guessed from screenshots.

The tool now returns a compact tree by default. It keeps the hierarchy, actionable ancestors and every node with text, a label or a resource id, with pixel bounds, the screen density and an explicit size limit that says when it cuts. Raw XML stays available with raw: true. Labels are redacted as whole values before they are cut or quoted.

Proof: fixtures from Android Settings, a Flutter app and a Compose app on a real emulator keep their labels and hierarchy, and a live tap at a compact bounds centre hit the right button. The full suite passes (3364 tests).

Sol review: round 1 found two redaction-order leaks (blockers), round 2 approved. The regex nit on malformed XML stays open as non-blocking.

Closes #351

Tokens before and after (old MCP JSON body against the new summary plus tree text):

Fixture Raw nodes Kept o200k before o200k after
Settings 54 51 5778 1001
Flutter 30 14 3242 393
Compose 32 25 3405 515
Requirement How verified Scenario and edge cases Result Evidence
Compare callstack/agent-device first Read its Android hierarchy and snapshot source Its capture installs a helper APK and runs its own daemon and sessions Approach reused, CLI not wrapped ~/.pickforge/investigations/351/agent-device/
Compact default keeps hierarchy, actionable ancestors and labelled nodes; raw XML as an option packages/android/test/ui-tree.test.ts, packages/mcp-server/test/android.test.ts Compact default, raw: true Met CI
Pixel bounds and density MCP test with fake adb (physical 440, override 420); live emulator Override density wins; live tap at the compact bounds centre of the Compose + button Density 420 in the test; the live tap changed Count 0 to 1 ~/.pickforge/investigations/351/
Explicit size limit that reports truncation Unit test with maxChars 1000; MCP test rejects maxChars 10 before any adb call Cut at a line boundary Ends with a truncation line; truncated: true in JSON CI
Empty tree reported as empty; no secure claim Unit tests for no nodes and only passive nodes Text never matches /secure/i empty: true with a reason CI
Real fixtures keep labels and hierarchy; token counts recorded Emulator dumps (API 37), tokenizer script Settings, Flutter release APK, Compose debug APK Table above ~/.pickforge/investigations/351/token-table.md, tok/measure.ts
Same redaction as other stored output Unit test with the real redactSecrets A long label ending in a token; a quoted credential Whole values are redacted before the cut and the quoting CI
Tool description and docs Diff Tool description, README, Android prompt and release note updated Diff
QA pass Lab Android session, CLI and MCP journeys Compact tree on Settings, tap from bounds, raw mode Passed ~/.pickforge/investigations/qa-351-231/

Follow-ups: #384 (compact tree in the CLI), #385 (password flags in raw XML redaction), #386 (launch-app on a sleeping screen), #387 (Compose role folding).

android_get_ui_tree now returns a compact tree by default. It keeps nodes
with text, a content description, a resource id or an action, and their
hierarchy. Bounds stay in pixels and the result reports screen density.
Output has a maxChars limit and says when it truncates. raw=true returns
the XML. Fixtures come from Settings, Flutter and Compose on an emulator.

Closes #351
@ElbertePlinio
ElbertePlinio merged commit d0b0501 into main Oct 28, 2026
14 of 15 checks passed
@ElbertePlinio
ElbertePlinio deleted the feat/351-compact-ui-tree branch October 28, 2026 19:10
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.

android: compact UI tree for agents

1 participant