Repository navigation
Carry the page reading's context down its walk, and route text walks through it - #1334
Merged
Merged
Conversation
…through it
The passage walk asked every text node where it stood by climbing: `uiInside` and
`closest(silenced)` per node for `says`, then `readPage` climbed again for the
generated element and for the passage cell (`upFrom` to the body for an ordinary
paragraph), `readSegments` and `pageBlocks` climbed for each segment's block, and
`readPage` pushed one `{node, offset}` object per character into `origin` while
growing `raw` a character at a time. On the corpus (208k characters, 8.5k text
nodes, 9.3k elements) that made a rebuild ~20 ms, most of it `closest`.
The walk now carries a context down the composed tree (`enter`): each element says
once whether it starts chrome (a declared label nearer than `.lf-ui` wins), silence,
generated words, a text block, a Markdown island, or a passage-cell candidate.
Chrome, silence and the generated marks start over inside a declared shadow root,
as `closest` does; blocks and cells cross it, as `closestAcross`/`upFrom` do. A
slotted node reads in its host's light context. `contextAt` folds the same `enter`
over an element's ancestors: the walk starts from it at its root, and the watcher's
`pageReads` asks it where a mutation landed, so what the reading skips and what it
ignores changing are one rule run in two directions.
`pageText()` drops `origin` for a segment index: `starts[k]` is where segment k
begins in `raw`, `raw` is joined from slices, and `pointAt(reading, i)` (binary
search) is the one way from a position to `{node, offset, segment}`. `spanOf`,
`neighbourhood`, `findQuote`, `findText`, `contextAround` and capture's snapping all
read through it; `neighbourhood` takes the reading rather than `(origin, fences)`.
Each segment carries the `block` its walk knew (`segmentBlock` for where a quote
puts a seam space), so `quoteFrom`, `pageBlocks`, capture's `sameRun` and anchor
resolution's `place` no longer climb.
The readings are named: `textNodesUnder(root, "says" | "wrote" | "unsilenced",
boundary)`. `unsilenced` is the render check's "is a settled slot still showing
words" reading, which passed a predicate before. `elementReading(el, reading)` keys
its kept value by reading name as well as element (it keyed by element alone, so a
`wrote` after a `says` would have returned the `says` answer), answers a kept value
before asking where the element stands, and keeps nothing for a node of another
document (a parsed revision). The two opaque-part sets are one `passageFences`.
Text walks outside passages.js move to the owner: `capturePlace` reads a block with
`elementReading` instead of walking it per candidate on every revision install,
and `blocksOnScreen` asks `readingRegionFor` once per block; drawing reads
`pageText().segments`; `leadingTitle` and `addressableSays` use `elementReading`;
`domValue` (projection/authored.js) uses `elementReading`; the version view's
inline comparison uses the named `wrote` reading.
Two walks stay. `addressableSays`'s `omitted` branch subtracts a subtree that varies
per call, so it walks the owner's `says` segments and filters them rather than keep
a cache keyed on the pair. go-to-sequence's `innerText` names chrome controls by
their rendered text (chrome included, CSS-hidden text excluded, text-transform
applied); the passage readings are structural by design, so the file side can
reproduce them, and none of them is that reading.
Tests: `passage-boundaries.test.mjs` gains cases for the carried context (chrome
stops at a declared root; a slotted node reads in its host's chrome; a declared
label is read to its last word), for `pointAt` across empty text nodes and edges,
and for `says`/`wrote` kept apart; its fence case moves to the new `neighbourhood`
signature. Each new case fails with its mechanism reverted.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts: # skills/leaf/assets/runtime/anchor-resolution.js
…ce once An element whose attributes start nothing (a class, an id) now returns its parent's context rather than a copy of it, and a childList record asks pageReads of its target once rather than once per added or removed node. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
previously approved these changes
Sep 27, 2026
A reading rooted at a shadow root started from nothing, so its words lost the host's block: `says(host.shadowRoot)` over `<span>12</span><span>%</span>` inside a `<p>` read "12 %" where it read "12%" before (render-checks' x-says check reads this way). It now starts from the host's context with the tree-local facts crossed, as the walk does when it enters that tree. The walk's marker tests are the selectors the point readings climb with, asked with `matches`: `UI_MARKS` (now exported beside `SAID` for `uiInside`), `GENERATED` (which `authored` climbs with), `GEN`, `ISLAND`, `TEXT_BLOCK`. `chromeMark` is `uiInside`'s rule at one element, and the watcher's `speaks` asks it instead of `uiInside(node, node)`. Segments carry the generated element their words stand in (`gen`) beside their block, so capture's `sameRun` and the target chooser's `matchOwner` read the segment instead of climbing. `unsilenced` states that its chrome is bounded at the root's frame. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
approved these changes
Sep 27, 2026
max-sixty
added a commit
that referenced
this pull request
Sep 27, 2026
) Activating a revision took every authored attribute, class token and inline declaration off `html` and `body` and put the arriving revision's back on, including the ones both revisions write. A class taken off `body` and put back restyles the whole document, so every corpus revision paid a full restyle for attributes that hadn't changed. This came out of re-profiling revisions after the recent performance PRs (#1321, #1324, #1334). `replaceAuthoredAttributes` now takes off only what the outgoing revision wrote and the arriving one doesn't, and writes only what differs, through the layer's identical-write rule (`keeps`). Declarations are compared by name, so an empty custom property (`--x: ;`, which reads back as `""`) stays, and a newly declared empty one is written as the single space that parses to it, since `setProperty` with `""` removes; the old code dropped both. Runtime-owned attributes and inline properties survive, as before; the existing live-revision test covers adding, retiring and the runtime-owned `--lf-thread-panel-width`. Measured on the corpus with `scripts/profile_page.py corpus revision` (3 runs each, current main, load ~20): | | main | this branch | |---|---|---| | style per revision | 149.5 ms | 54.6 ms | | install task | 313–357 ms | 160–188 ms | Most of what's left in that task is `reachScrollers`, which #1340 takes down separately; the two together bring style per revision to about 15 ms. New test: a revision that changes only the title makes no authored attribute write on either root. It fails on the old code. > _This was written by Claude Code on behalf of max-sixty_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The passage walk asked every text node where it stood by climbing:
uiInsideandclosest(silenced)per node forsays, thenreadPageclimbed again for the generated element and for the passage cell (upFromto the body for an ordinary paragraph),readSegmentsandpageBlocksclimbed for each segment's block, andreadPagepushed one{node, offset}object per character intooriginwhile growingrawa character at a time. On the corpus (208k characters, 8.5k text nodes, 9.3k elements) a rebuild took ~18–22 ms, most of it inclosest.One walk that carries its context (#23). The walk now carries a context down the composed tree (
enter). Each element says once whether it starts chrome (a declared label nearer than.lf-uiwins), silence, generated words, a text block, a Markdown island, or a passage-cell candidate. It asks each withmatchesagainst the selectors the point readings climb with (UI_MARKS/SAIDforuiInside,GENERATEDforauthored,TEXT_BLOCK), so a marker added to one of them reaches both;chromeMarkisuiInside's rule at one element, and the watcher'sspeaksasks it too. Chrome, silence and the generated marks start over inside a declared shadow root, asclosestdoes. Blocks and cells cross it, asclosestAcross/upFromdo. A slotted node reads in its host's light context, and a reading rooted at a shadow root starts from its host's context with the tree-local facts crossed.contextAtfolds the sameenterover an element's ancestors: the walk starts from it at its root, and the watcher'spageReadsasks it where a mutation landed. What the reading skips and what it ignores changing are therefore one rule, run in two directions. The composed-tree walk is otherwise unchanged: declaredx-shadowroots only, slots byassignedNodes({flatten: true}), and theboundaryhook that render-checks'shownVerbatimuses.pageText()dropsoriginfor a segment index.starts[k]is where segment k begins inraw,rawis joined from slices, andpointAt(reading, i)(a binary search) is the one way from a position to{node, offset, segment}.spanOf,neighbourhood,findQuote,findText,contextAroundand capture's snapping all read through it.neighbourhoodnow takes the reading rather than(origin, fences). Each segment carries theblockits walk knew (segmentBlockgives the unit a quote's seam space breaks on) and the generated element its words stand in (gen), soquoteFrom,pageBlocks, capture'ssameRun, the target chooser'smatchOwnerand anchor resolution'splaceno longer climb. The two opaque-part sets are onepassageFences.The readings are named:
textNodesUnder(root, "says" | "wrote" | "unsilenced", boundary).unsilencedis the render check's "is a settled slot still showing words" reading, which passed a predicate before. Like every reading, its chrome is bounded at the root's frame, which for a settled slot (lf-old,lf-new) is the slot itself; the predicate used unboundedinUi. They differ only for a holder outside.lf-chromebut under a bare.lf-uiancestor, where the words the slot still shows are now reported as showing.elementReading(el, reading)keys its kept value by reading name as well as element. It keyed by element alone, so awroteafter asayswould have returned thesaysanswer. It also answers a kept value before asking where the element stands, and keeps nothing for a node of another document (a parsed revision).Text walks outside passages.js (#27).
capturePlacereads a block withelementReadinginstead of walking it per candidate on every revision install.blocksOnScreenasksreadingRegionForonce per block.pageText().segments.leadingTitleandaddressableSaysuseelementReading, and so doesdomValue(projection/authored.js).wrotereading, since it needsreadingFrom's units.One walk stays: go-to-sequence's
innerTextnames chrome controls by their rendered text, which includes chrome, leaves out CSS-hidden text and applies text-transform. The passage readings are structural by design, so that the file side can reproduce them, and none of them is that reading. Its layout is already clean by then, since the loop readsbadgeBoxandcheckVisibilityfirst. Theomittedbranch ofaddressableSaysis already gone on main.Measured on the corpus, on a shared machine running three other agents' suites:
pageText()rebuild, in page (4 rounds, median of 25 each)move, pairedone_transition.py corpus move 10(painted, median)move,profile_page.pyper run:closestself /pageTextinclusiverevision,profile_page.pyper run:closestself /pageBlocksinclusive /activateRevisioninclusiveThe paired
revisionruns (2 × 4) are dominated by noise at load ~40 (1.3–5.0 s per run on both arms): base median 2.6 s, head 2.3 s. The profile rows above are what attributes the change.Tests.
passage-boundaries.test.mjsgains cases for the carried context: chrome stops at a declared root, a slotted node reads in its host's chrome, and a declared label is read to its last word. It also covers a reading rooted at a shadow tree reading in its host's block,pointAtacross empty text nodes and edges, andsaysandwrotekept apart; its fence case moves to the newneighbourhoodsignature. Each new case fails with its mechanism reverted. Run locally:npm run test:runtime,test_render_anchors,test_revision_delivery,test_render_drawing,test_render_aim,test_render_widgets,test_render_projection,test_render_gate, andtest_render_navigation.test_render_navigation::test_a_delayed_thread_reveal_reports_that_new_user_focus_cancelled_itfails locally, and fails the same way on origin/main (ad29d53); so dotest_render_anchors::test_a_diff_surface_keeps_the_complete_thread_lifecycle_inline[light|dark].🤖 Generated with Claude Code