Skip to content

Let a page draw its own margin through the public interface, with lf-x-margin as the example - #6161

Closed
max-sixty wants to merge 19 commits into
mainfrom
agent-a737301eb13005c4a
Closed

max-sixty wants to merge 19 commits into
mainfrom
agent-a737301eb13005c4a

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

A page whose body has data-annotations="page" draws its own annotations. A trial that built Leaf's margin on that route from the shipped references alone found the route short in eight places and the references wrong in four. This finishes the route and ships the trial's widget, rewritten onto it, as a live sample in the feature gallery (lf-x-margin, in the Threads tab). Core's margin stays the default and draws as before.

What the route gains, for two new public names (anchorTo, watchAnnotationLayer):

  • Every thread with a place reaches the presentation, each with placement.status and live ranges. The comment box's placement carries its ranges too.
  • placePageThreads(owner, render, {reveal}). t, Show on page and threadActions.open ask the presentation to draw a thread it hasn't, and the handle's update() returns the pass that places the result.
  • threadSummary says what a mark for the thread shows: line, progress, unread.
  • view.place(entry, row, item) takes a row before it is appended, and placed rows are what g m and g t letter.
  • anchorTo stands a box on the anchor Leaf's own marks use. watchAnnotationLayer joins the layer o hides, and core's two watchers now come in through it.

Where to look

  • thread/surfaces.js, revealOnPage. A reveal that can draw nothing is never asked again by the pass it ran. A reviewer hung the page here twice, by two routes, before this held.
  • annotation-layer.js moved out of annotation-overlay/. Hide annotations now shows disabled on a page with nothing to hide, as Changes does.
  • contribution-controls.js: a contributed control every surface had released is drawn again when one takes it back. This one reaches default pages, as a fix.

Not delivered

  • Pointing at and pressing commented words. The example's tint is inert. Core owns that reading (markHit, threadPreview) and loads it only with its own margin, and the platform's highlightsFromPoint is the method notes/browser-support.md already turned down. Who should own it on this route is a separate decision.
  • In the example, pins cover words on a phone, since placement stays core's. Its card stands beside the column only from about 1650px, since a thread's head in a page outlet needs 359px, and at 390px the head's status is cut.

max-sixty chose this on a decision page. Two fresh reviewers, one reading the code and one using the sample cold, each went two rounds, and what they found is fixed or listed above.

Tests: pnpm run check (996 runtime tests), the four browser tests of the route, the 77 browser tests of the surfaces it shares, and page check --render on the gallery. test_a_selection_of_the_whole_page_still_finds_its_passage errors at teardown on a 400 from /api/draft, the same on main. Chromium only, with one Firefox probe of the example.

This was written by Claude Code on behalf of max-sixty

…x-margin as the example

A page whose body has data-annotations="page" presents its own annotations
(module-annotations.md, "Page annotation presentation"). A trial that built
Leaf's margin on that route from the shipped references alone found the route
short in eight places and the references wrong in four. This finishes the route
and ships the trial's widget, rewritten onto it, as the feature gallery's
worked example.

What the route now gives a page's presentation:

- Every thread whose anchor has a place, not only exact matches, each with
  `placement.status`, `place` and, for a passage, live `ranges`. The comment
  box's placement carries `ranges` too, kept as a thread's are. The widget
  resolves no quote itself.
- `placePageThreads(owner, render, {reveal})`. A presentation that draws a
  thread only when asked returns null for it, and a route to the thread (`t`,
  Show on page in the panel, `threadActions.open`) calls `reveal(key)`. Leaf
  then places the outlet and lands the user in it. `reveal` returning false
  leaves the thread to the panel. The handle's own `reveal` went: it opened a
  thread through Leaf, which `threadActions.open` already does.
- The handle's `update()` returns the thread pass that places the result, as a
  primary reader's does. A state application never holds that pass back, so a
  route that waits on a reveal can run inside one.
- `view.place(entry, row)` accepts a row before it is appended, and checks that
  it stands inside the owner once `render` returns.
- `threadSummary(thread)` gains `status` and `progress`, the margin's own
  reading of a thread's line and its progress face (margin-model.js,
  `threadMarks`).
- `anchorTo(box, context, at)` stands a box by page content on the anchor
  Leaf's own marks use (css-anchors.js, `anchorFor` and `anchorAt`), so the
  browser carries it through each scroll.
- `watchAnnotationLayer(watch)` joins a package's drawing to the layer `o`
  hides. annotation-layer.js moves from annotation-overlay/ into the core
  runtime for it, and on a page that presents its own annotations the command
  and its row in the leaf's menu stand only once something watches.

Three capabilities needed no name. An entry's target is `view.target(entry)`,
now documented. A key pressed in a card reaches a scope declared on its outlet,
which module-input.md already says. Hit-testing a range is the platform's
`CSS.highlights.highlightsFromPoint`, and a thread previews from its words
through `lfPreview` on the block holding them.

The references gain the placement, entry, item and handle shapes, an anchor's
`quote`, `prefix` and `suffix` with a link to events.md, and the statement that
no declaration binds a widget's key for the whole page.

Leaf's own margin is unchanged: a probe of review-a-plan read the same rows,
marks, card, Escape landing and `o` on the merge base and on this tree.

Tests: `test_page_annotation_view_seats_obligations_and_contributed_controls`
now places each row before appending it and reads each entry's target. Two
tests are new in the same module, one for the route and one for the example,
with a runtime test for the awaited update.
`revealOnPage` asked `reveal(key)` for any thread a route named. A thread with no
place, as a quote the page no longer holds, is never among the presentation's
targets, so a presentation that recorded it open and returned, as its reference
says, had no outlet to give. The route fell to the panel as the last resort, and
`returnToPage`, which runs after every thread pass, asked again; each ask ran a
pass of its own. A reviewer's probe counted 41 asks in 800 ms with a cap in the
fixture, and a hung page without one.

The ask now goes only for a thread `pageTarget` admits. The route test opens a
thread whose words are gone and reads that the page was asked nothing; with the
check removed the test's page hangs and the run times out.

`placePageThreads` no longer type-checks `reveal`: a value that isn't callable
throws where it is called, and `revealOnPage` reports that failure.
The layer had two ways in: `watchAnnotations` for Leaf's own margin and passage
paint, and the public `watchAnnotationLayer`, which also mounted the command and
restored the tab's state on its first call. `leaf.js` mounted and restored only
on a page with Leaf's own margin. A page presenting its own annotations could
therefore hide the layer and lose the command with its last watcher: press `o`,
let a revision take the page's margin away, and `data-lf-annotations="hidden"`
stayed with nothing to show it again until a reload.

Now `watchAnnotationLayer` is the only door, and Leaf's two watchers use it. The
command mounts at boot on every page and takes a press while something watches
or the layer is hidden; with neither its row in the leaf's menu stands disabled.
The tab's state is restored at boot on every page.

A watcher hears each change, and hears at once only a layer that stands hidden
as it joins. It no longer hears `false` on joining a shown layer, which it
already draws.

`tests/runtime/annotation-layer.test.mjs` holds each of these: with any one of
the join call, the repaint on joining or leaving, the hidden-layer clause of
`when`, or the restore removed, it fails.
`paintPending` built a `Range` for each segment of the draft's passage on every
paint, though placement now keeps live ranges for the draft as it does for a
thread (`placePending`). It reads those.

A runtime test holds that placement gives a thread's passage and the draft's a
range over their words and keeps the same ranges across a reading that moves
nothing; with the draft's ranges dropped it fails.
On a page presenting its own annotations Go-to had no margin: `g m` and `g t`
found nothing, since the sequence reads margin targets from Leaf's overlay,
which such a page doesn't have.

The page's annotation view already knows the rows the page ties to each entry
(`view.place`). The presses in those rows are now the page's margin targets,
handed to the sequence through the seam the overlay uses (`marginEntries`), so
`g m` letters them. `view.place` takes the item a row stands for as an optional
third argument; a row standing for a thread's item is among `g t`'s Thread
controls. No public name is added.
…nread

`threadSummary` gave a page's own mark a `status` line and the agent's
`progress`. A mark with no room for words, as a pin, had nothing to say that a
thread holds something unread while its line said whose turn it is.

The line is now `line`, the margin's and Page Map's word for it (Threads calls
a thread's state its status, and a placement has a `status` of its own), and
the summary adds `unread`, the count Leaf's margin dots a mark for. A runtime
test holds the three fields; blanking any one fails it.
A page's annotation view that stopped showing an entry's contributed controls
and then showed them again, as `lf-x-margin` does across hiding and showing
annotations, got them back disabled: `aria-disabled="true"` at half opacity,
taking no press.

`clearContributionControls` releases a control no surface holds, which drops its
command scope and its availability. `materializeContributionControls` then found
the control still in its directory with the record it last drew and skipped
drawing it. A control it takes up after a release is now drawn again.
…e's rules

A reader who used the gallery's scenario cold, and a code review, found the
example and its references short of what the route gives. The example now:

- says on each mark whose turn the thread is and that it holds something
  unread, by colour and a dot that a pin keeps, and in its accessible name and
  its preview where a pin has no room for the line;
- closes its card on a press elsewhere, and Leaf keeps the words typed there;
- stands a card beside the column where the margin has 16rem for one, and
  under its words otherwise, at the width Leaf's thread needs to say a
  message's line whole;
- keeps every card and the comment box inside the window clear of Leaf's
  panel, so Leaf seats the comment box by its words at every width, and shows
  nothing for an empty outlet;
- ties each mark to its entry and item, so Go-to letters it (`g m`, `g t`);
- reads Tab down the page, a card after its mark;
- while annotations are hidden, drops its pins, tints and card, and keeps the
  marks that stand clear of the column;
- measures the window with `shownWindow`, not `innerWidth`.

It no longer reads the pointer on commented words. Its hit test, the preview it
declared on the page's own elements and its press-to-open are gone: Leaf's own
margin does these from an index no public call reaches, and the example's copy
was a second implementation of it. The tint stays, under a rule that names the
elements holding the words (`data-lf-marked-words`), which Firefox needs and
which keeps the rule from restyling every element.

The references say what the route gives: ranges stay the same objects while
they cover the passage; `fallback` is also what a datum reads before its widget
draws; `reveal` is asked only for a thread among the targets; Leaf seats the
comment box only clear of its panel; a placed row is a Go-to target; Leaf reads
no pointing or pressing on a passage's words on such a page; and an `anchorTo`
box is not cut at a scroller's edge and, inside a scaled box, needs placing
again at `scrollend` in Firefox and WebKit.

Tests: the route test reads that a script's write ahead of a passage leaves its
ranges the same objects, and that the menu row for hiding annotations stands
disabled with nothing over the page. A new test holds that the page handle's
`update()` places its threads while a server reading is being applied, which
failed when the update asked for the document's pass. The example's test works
it as the scenario's steps do, at a width where its marks pin.
#6134 removed the key: a module at `widgets/<tag>.js` now makes a widget
upgraded, and a registry that still writes the key is refused as unknown.
A window that opened with no room beside the column, as the gallery's sample
does, drew the card under its words at the beside width (22rem), where a
window resized to that width drew it at 26rem: the widget wrote the width's
attribute only when the room changed, and its initial value was already the
no-room one.

The example's test now opens in such a window and reads the card's place and
width; it fails without this.
…phone

The scenario's guide said where a pin stands "is still Leaf's to decide well",
which told a reader nothing. It now says what the widget does and what takes
the pins off the words.
… for

A presentation whose `reveal` took a thread and whose `render` then returned no
outlet for it kept the page in a loop. The thread went to the panel as the last
resort, `returnToPage` asked the page to take it back after every thread pass,
and each ask it accepted ran another pass: 41 reveals and 42 passes in 1.5 s
with a cap in the fixture, and no end without one. e01c72e closed only the
thread with no place.

The cause is an ask that can draw nothing being made again by the pass it ran,
so the ask is what stops. A taken reveal whose pass places no outlet for the
thread is the presentation's failure: Leaf reports it where a failed `render`
is reported, and doesn't ask for that thread again until the presentation draws
it or calls `update()`, which says that what it would draw has changed. The
thread then goes back to the page from the panel on that pass.

The check that a thread is among the presentation's targets stays. Without it
the new rule also ends the loop for a thread with no place, after one ask, but
by reporting a failure against a presentation that did what its reference says
and was never handed the thread.

The route test's fixture now caps `reveal` and the test counts the asks once
the page has settled, for both cases. With either rule removed, or both, it
fails by an assertion in under five seconds, where it ran to a 300 s timeout.
… its rule reaches

The reference told a page presentation to set `data-lf-marked-words` for its
highlight's rule and not that it must take it off again, nor that a rule in the
document doesn't paint words inside a shadow tree.
… head needs

A second cold read of the gallery scenario found four defects in the example.

An open card covered the marks below its own. Under its words it ran to the
window's edge, over the pin column, so a press where the Waiting on me pin
stood landed on the card. It now ends short of the marks, pinned or beside the
column, and starts where its words start, as Leaf's own comment box does. A
pinned row of two controls stacks them, so the pins take one column.

A card beside the column cut its first message's line to "Me 00:43 ·…". The
head of a thread's first message keeps room for the thread's action, its own
controls and a notice of news, 132px in all, so a card needs 22.5rem to say
"Queued for Claude" whole (measured: 359px), where Leaf's own margin card says
it at 294px with its controls in a column of its own. A card is now 26rem
wherever the window can give that, and stands beside the column only where the
margin has that much room, about 1650px of window; narrower, it stands under
its words. The comment box, which has no such head, still stands beside the
column from 16rem of room. Sizing the card to its content was tried and
dropped: it grew from 358px to 416px as a reply was typed.

On a phone the card has 330px clear of the pins, 26px short of what a queued
thread's head needs there, so that line is still cut at 390px.

The comment box flipped above its words hid the Accept and Reject marks beside
the line above. It no longer reaches them. It still covers part of that line
when the panel takes the room below, as Leaf's own box does.

Under a finger the unread dot stood centred above the symbol: it was placed
from the edge of a press that is 44px wide there. It is placed from the press's
centre.

The widget also takes `data-lf-marked-words` off before it drops its highlight
when it leaves, and marks only elements in the document's own tree, which is as
far as its rule reaches.

The example's test puts its passage at the column's edge and reads that every
mark still takes a press with the card open, the card's width, and the dot's
place in a press of either width; each fails with its fix undone.
A page presentation chooses its outlets' widths, and nothing told its author
that a thread's first message cuts its line in a narrow one: the head keeps
room for the thread's controls, and needs 359px to say "Queued for Claude"
whole. `lf-x-margin` drew its card at 240px and lost the line.
# Conflicts:
#	skills/leaf/references/module-scroll-and-motion.md
#6148 removed `.eyebrow` from Leaf's words and from every other label in the
gallery; this one arrived with the merge still wearing it.
leaf-agent
leaf-agent previously approved these changes Nov 16, 2026
Two files conflicted, and main's #6234 broke the page-margin scenario
without a textual conflict.

- annotation-layer.js: this branch moved it from annotation-overlay/ to
  browser/runtime/ and rewrote it around watchAnnotationLayer; main's #6245
  changed it in place so that setAnnotationsHidden toggles
  `data-lf-annotations-hidden` on the chrome's root instead of writing
  `data-lf-annotations="hidden"` on html. The moved file takes #6245's
  write (chromeRoot.toggleAttribute) and its header paragraph saying why,
  and the annotation-overlay/ copy stays deleted. The branch's readers of
  the old html attribute move to the chrome root's, as #6245 moved its
  tests: tests/runtime/annotation-layer.test.mjs, and the two `o` checks
  in test_thread_surfaces.py's page-presentation and gallery tests. The
  gallery's lf-x-margin reads the layer through its watcher, not the
  attribute, so it needed no change.
- feature-gallery.html: main's #6237 took `layout-flow` out of the
  author vocabulary, so the #bg-page-margin section drops the class, and
  #bg-native-replies keeps main's plain section.
- #6234 regrouped registry declarations and removed `choose` from
  lf-options. lf-x-margin's gallery entry moves to the new shape
  (`attributes`, `content`, `author.instructions`, `author.example`), and
  the scenario's and its test's option groups drop `choose`.
max-sixty added a commit that referenced this pull request Nov 17, 2026
On a page that draws its own annotations (`data-annotations="page"`),
commented words got no marks, because the anchor paint, which marks
them, previews their thread under the pointer and opens it on a press,
came with the overlay renderer. It now runs on every page, so on such a
page pointing at commented words previews the thread and a press opens
it in the panel. Core gets smaller, by a net 21 lines of code:
`anchor-paint.js`, `visual-mark-paint.js` and `annotation-layer.js` move
out of `annotation-overlay/` (about 30 lines each way are path changes),
the overlay-only mark stylesheet and its delivery go, and the anchor
paint is no longer nullable.

**To weigh.** Page-mode pages now load three more modules before the
page shows the server's state: `anchor-paint.js` (37 KB),
`visual-mark-paint.js` (1.8 KB) and `annotation-layer.js` (3.3 KB). In a
trial on #6161's branch the first two cost no main-thread time separable
from noise over ten interleaved rounds; this branch's startup wasn't
measured. `o` now also hides the word marks on page-mode pages. Pages
with Leaf's own margin are unchanged: `leaf-dev stills --base main`
shows no changed pixels in 18 margin and comment-mark states in Chromium
and 8 in Firefox.

max-sixty asked on a decision page to test this answer to "who reads
pointing at commented words on a page that draws its own margin", and to
land changes there only where they make the code simpler.

Tests: `pnpm run check` (1008 runtime tests); 34 browser and journey
test functions (61 cases) on page mode, the mark stylesheets, the
annotation layer, `o` and the hand cursor; behavior probes in Chromium
and Firefox, the long press in Chromium only.

> _This was written by Claude Code on behalf of max-sixty_
@max-sixty

Copy link
Copy Markdown
Owner Author

Closing: max-sixty asked to land changes here only where they make the code simpler, and this adds a net 230 lines of core and two public names, plus a 783-line sample and 749 lines of tests. Its one standalone simplification, painting the draft's mark from the ranges placement keeps, is #6322. #6321 has since had core read commented words on every page. The direction this branch started, a widget outside core presenting margin items in any design, is #6314, which can start from this branch.

This was written by Claude Code on behalf of max-sixty

@max-sixty max-sixty closed this Nov 17, 2026
max-sixty added a commit that referenced this pull request Nov 17, 2026
Placement already kept live ranges for each thread's passage, reused
across readings that move nothing, but the draft's anchor came back
without them. So `paintPending` built its own `Range` for each segment
of the draft's passage on every paint. Now placement resolves the draft
the same way it resolves a thread (`placePending`, over `liveRanges`),
and the anchor paint reads those ranges. Building a passage's ranges now
has one home instead of two, and the page looks the same. Code is net +3
lines; a runtime test (+45) holds that placement keeps the draft's
ranges, and it fails with them dropped.

This comes from #6161, which max-sixty is leaving unmerged because it
adds code. He asked to land the parts that make main simpler and better.
The other standalone part of #6161, a fix for a contributed control
redrawn disabled, isn't here: main has no surface that releases a
control and takes it back up, and no reproduction found one.

Tests: `pnpm run check` (1011 runtime tests), and the 19 browser test
functions that read the draft's mark plus two on anchors and contributed
controls (29 cases).

> _This was written by Claude Code on behalf of max-sixty_
max-sixty added a commit that referenced this pull request Nov 23, 2026
Agents that wrote packages from the shipped references alone were left
stuck or guessing in places where the references were silent, wrong or
pointed nowhere. This corrects those places, from two rounds: six faults
that two earlier trials found, and the documentation gaps from a trial
in which six agents each wrote a different kind of package (a widget
that asks, one bound to data, a reordered list, a drawing with parts, a
theme, a widget that also runs off Leaf).

What an author now finds: the shape of a target's `placement`, of
`consumeAnnotations`' entries and items, and of the `placePageThreads`
handle (`module-annotations.md`); `keeps-first-box` and how to reserve a
first box, what `verbatim` says, how `--package` reads a path, and where
the install keeps the files these references link to (`packages.md`);
that a `value` record's attribute is a string, which keywords a verb's
`detail` takes, what a position record's container is and what page
state gives for it, and that a stamp records a `restated` retraction
(`package-data.md`); where the user undoes, when a widget calls
`defer()`, and what `this.state` does off Leaf (`module-state.md`); what
a revision keeps in a widget that declares `lfPatch`, which the text
overstated (`module-authoring.md`, "Revisions"); and how to try a theme
while writing it and see its dark scheme (`package-themes.md`).

Three statements in #6161's wording, which first carried four of these
corrections, are false on `main` and are left out: that every thread
with a place arrives as a target, that `update()` can be awaited, and
that `reveal` is a callback passed at registration.

To stay under the 30,000 characters the skill's size test allows a file,
the last commit moves the `views` helpers from `module-authoring.md` to
`module-state.md` word for word and cuts ten sentences that repeated a
neighbour or described a helper's internals; its message quotes each.
`module-input.md` is seven characters under. Three sentences follow
fixes to Leaf's own code that have merged: a keyed control in a shadow
root belongs to its widget (#6785), `themes.toml` may name `reading` as
its default, and `m` leaves a question's premise out only where the
premise stands outside the widget (both #6781). Other faults the trial
found in Leaf's code are not fixed here.

Max hasn't read this. A subagent wrote it and confirmed most added
statements by running them with `leaf-dev probe` or the command
concerned, and its commit messages say which it only read; a fresh agent
then answered seventeen author questions from the skill alone, sixteen
from the text. I read both diffs. Tests: the reference tests in
`tests/model/test_interact_layer.py`,
`tests/model/test_theme_tokens.py`, `tests/runtime/widget-api.test.mjs`,
and pre-commit.

> _This was written by Claude Code on behalf of max-sixty_
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.

2 participants