fix(web): put on-screen text in the snapshot tree instead of losing it
Summary
On --platform web, text that is on the screen reached the reader only when the backend happened to mint a ref for it. Two independent causes, both fixed here. Stacked on #3547 (feat(snapshot)!: make a node's ref optional and mint it per producer), which owns the contract and the address surfaces; this PR owns the web capture. 9 files, 750 gross lines.
1. The capture asked for --compact, and that flag deletes text along with its container. agent-browser's compaction removes a ref-less element together with the text under it. Same page, same moment:
raw - status\n - StaticText "Hello Zed" ← the announcement is there
compact (both lines gone)
Role census on a 408-ref page, raw vs compact: ListMarker 200 → 0, status 1 → 0, every ref-bearing role unchanged. The flag that exists to hide noise was what hid a status region that had just announced something.
2. The projection dropped every line without a ref (if (!ref) continue), so static text, a paragraph, a label element and a status announcement never became nodes at all.
--compact is no longer requested. The pruning it existed to do is owned by the projection, which can tell an empty container from the text inside it: a ref-less line carrying no text (form, list, paragraph, a silent status) and a presentational role (listmarker) produce no node, and a dropped line's children re-parent to its parent rather than to whichever node was kept last.
Text with no ref becomes a node carrying that text on value, not label: the backend spells a control's visible string twice — as the control's accessible name and as its own text line — and a second label claiming it makes an ordinary label="Name" read refuse as ambiguous. Measured through the real pipeline before choosing: text="Name" → ambiguous when both carry it as label, resolves the textbox when the text line carries it as value. Every text door already reads value (wait text, find text, get text, text=, the scope filter, the printed line).
Suppression of a text line is a structural relation read off the tree, not a page-global denylist: a line is a duplicate when it renders inside a <label> element whose control reports the string as its name, or sits inside the control that reports it as its name or value. Anything else keeps its own node, which is what preserves the content this capture exists to publish — an announcement that happens to repeat a button's label, or a table cell echoing a field's contents, is content. extractQuotedText parses and unescapes an escaped quoted payload; the trailing : value form stays raw, because that is what the backend prints and unescaping it would publish a value the page does not hold.
A ref is now read only from a ref=eN annotation or an @eN token outside quoted text: StaticText "retry in e3 seconds" names no element, and used to be handed the ref of something else.
agent-device snapshot # [text] "Hello Zed" (was: absent)
agent-device wait text "Hello Zed" # exit 0 (was: timeout)
agent-device get text text="Hello Zed" # Hello Zed (was: no match)
Validation
Tested at 20b6693ae, rebased on #3547 e67b761af (which is rebased on origin/main). pnpm check:affected --run --base feat/snapshot-optional-refs on that head under the machine-wide gate lock: all runnable checks passed.
The rule this PR exists for is now pinned through the router. The emulated web page (test/integration/provider-scenarios/web-world.ts:232) ends with the line a real capture prints for content it cannot address — text on value, no ref, no box — and web-desktop.test.ts asserts, through the request router, that snapshot --json publishes it with no ref key, find text <it> list prints = (no ref) [text] "Order saved", wait text <it> answers it, and click text=<it> refuses with selector_not_found. Mutation-checked: deleting the snapshotRefMinting(data) argument at snapshot-state.ts:83 mints the node e7 and fails the first assertion. That test also found a real defect — toDaemonFindData re-added an own-property ref whose value was not a ref, which the CLI formatter, the MCP pin merge and a Node consumer all read — fixed on #3547. This head rebases ddf73fdc5 onto #3547's rebased head and adds the two review commits above; the capture and the projection are unchanged by the move, and the minting mode that decides this tree's refs is unchanged for the only pair the web interactor can produce ({ backend: 'web', producer: 'agent-browser' } → backend-issued). Projection tests are driven by payloads captured from the real backend (form after submit, role vocabulary, list with markers, empty form), not hand-written approximations: the announcement keeps its text and loses its address, a label's text is subsumed under the control that carries it as its name, empty containers and list markers drop out with children re-parented, geometry attaches only to measurable nodes, and ref-shaped text stays content.
Live before/after — local page on port 8766, managed agent-browser 0.27.1, fill label="Name" Zed then click role=button label="Submit", base origin/main vs this head:
| command | base | head |
|---|---|---|
snapshot | 8 nodes, no announcement | 9 nodes, [text] "Hello Zed" |
wait text "Hello Zed" | times out | exit 0 |
find text "Hello Zed" exists | no match | Found: true |
find text "Hello" list | 0 matches | = (no ref) [text] "Hello Zed" |
get text text="Hello Zed" | no match | Hello Zed |
click text="Hello Zed" | refuses | refuses (unchanged, correctly) |
label="Name" still resolves uniquely to the textbox with a visible <label> on the page, and is visible label="Name" still works before and after a fill.
Documented limitation
A ref-less node has no rect — the backend measures boxes for refs and has no handle for this content — so is visible answers for it through its nearest visibility anchor (verified live: is visible passes, is hidden refuses) and it is never a tap target. snapshot -i still shows interactive elements only. Recorded in website/docs/docs/commands.md, next to the iOS text-pair note that users read for the same question.
Review round
All five cubic threads on this PR are replied to and resolved: four fixed in 0ab9b9ddd (structural suppression instead of a name denylist, extractQuotedText unescaping, the attachRefs JSDoc, the kernel's snapshotRefBodies replacing the selector-side ref filter) and the fifth answered with live-backend evidence in a1d1eb862 rather than changed — the trailing : value form is raw on the wire, so unescaping it would publish a value the page does not hold, and the dedup it worried about already happens.
The branch was then split for the 1,000-line budget: the contract and address surfaces moved to #3547, which this branch now stacks on. Content is unchanged by the split (git diff --stat across both branches reproduces the old head's file set), and the review threads' commits remain reachable from this PR's history.
Closes #3509