Skip to content

Hold widget outputs outside the application state, bind them by contract, and move wt-merge and rust-sort onto them - #6690

Closed
max-sixty wants to merge 15 commits into
mainfrom
widget-state-experiments
Closed

max-sixty wants to merge 15 commits into
mainfrom
widget-state-experiments

Conversation

@max-sixty

@max-sixty max-sixty commented Nov 22, 2026 •

Copy link
Copy Markdown
Owner

Duplicates draft #5981 and #6008, so I recommend closing it. #5981 builds the same binding by contract, message check and wt-merge invoker buttons, and replaces publishOutput with a property and change, where this keeps it. #6008 lights rust-sort's line through the existing for attribute rather than a new follows. The one open difference, what carries a value, is the first question on #5981's review page.

Widgets that share a value already do it through outputs: lf-diff, lf-file-editor and three example widgets publish one, and lf-file-tree and lf-text-document read one. This change makes publishing cheaper and binding simpler, and moves two examples off their hand-rolled wiring.

What changes

  • Outputs leave the application state. browser/runtime/data.js holds them behind one signal, so a publish no longer re-derives the page's state. On wt-merge a publish nobody reads took 0.09 ms of script rather than 0.19 in Chromium, 90 function calls rather than 1,344.
  • A reader binds by contract. An input with a reference reads the one output of its contract that the referenced widget declares, so inputs lose output, and page check refuses a target declaring none or several. lf-file-tree and lf-text-document drop their output name.
  • A data widget's <pre> stands in for its input that names a source. An input bound only by reference, such as lf-code's playhead, leaves the <pre> alone. The browser's first read, the registry check and the markup check follow the same rule.
  • A thread message names only its own ids and the page's. The browser resolves a reference in the message and then the page, so one naming another message's widget used to pass admission and draw nothing. Admission now refuses it.
  • wt-merge publishes its film's moment as a frame output, and each step's title is an HTML invoker button (commandfor="merge-film" command="--seek" value="squash"). film-frame, announce(), seekChapter() and the list's id lookup go.
  • rust-sort publishes the lines each step runs as a source-lines output, and each lf-code excerpt with follows="sort-film" marks its line and keeps it in view inside its own pane, never moving the page. lf-code becomes a LeafElement, and scrollersOf joins the portable API.
  • References: package-data.md ("Widget outputs") says when a value is an output, module-input.md gains "Invoker commands", and module-state.md's table gains a row for outputs.

Size

33 files, +736/−341: runtime and checks +158/−177 with +87/−11 of tests, references +34/−24, wt-merge's move +151/−81 with its "Invoker commands" section, and the rust-sort part above.

Testing

pnpm run check passes, including 1,078 runtime tests. The interaction-contract model tests and the changed document tests pass. Focused browser tests pass for the merge film, the sort source's marked line, a file tree opening an editor's and a diff's files, a text document reading a generated document, and lf-code's excerpts, wrapping and notes. A Codex review of the port onto main's flat registry keys found one stale refusal message, fixed. The broad suite fails one test: skills/leaf/references/module-input.md is now 30,941 bytes, over the size one read takes, from the "Invoker commands" section.

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

…er commands

The film publishes the moment it shows (chapter, caption, tone, per-step
status) as a typed `frame` output under a `merge-frame` contract the
example's registry owns, and the step list binds it as an `x-data` input
through its `for` reference. The list is now a LeafElement, since Leaf
delivers bound inputs only through that lifecycle; it draws the current
frame whichever widget upgrades first, so the film's `announce()` and the
`film-frame` event go away, along with the list's `getElementById`.

Each step's button is an authored invoker,
`commandfor="merge-film" command="--seek" value="<step>"`, and the film
handles the `command` event, replacing `seekChapter`. The button's value
is now the step's only key, so `data-chapter` is gone. A press elsewhere
on a step's row still presses its button.

Behavior is unchanged: playing, following the playing step, pointer and
keyboard seeks, and step availability after flags, in Chromium and
Firefox. The existing merge-film tests pass as written.
Restores the feature #4115 removed with `indicate()`: as the sort film steps,
the lf-code excerpt quoting the slice.rs line that step runs marks it and keeps
it in view in the source pane. It now travels on the outputs channel, to test
whether that channel suits a playhead.

- The film declares `x-output: {"playhead": {"contract": "source-lines"}}` and
  publishes the step's lines (sort.js's restored per-step `line` names and
  `LINES` table), or null on the last step.
- The default package declares the `source-lines` contract (a string in
  lf-code's range grammar). lf-code binds it as an `x-data` input through
  `follows` (`x-refers`), reads it as its `playhead` property, marks the rows it
  addresses (`data-lf-at`, the accent face the indicated line wore), and brings
  the first into view within the box scrolling the block, never the page.
- lf-code becomes a `LeafElement`, since Leaf delivers inputs only to
  LeafElements (element-data.js through leaf-element.js). It draws no Lit
  template; its source draw is its update's completion, replacing the
  pending-task event. A plain host sets `playhead` itself.
- An `x-content: data` widget's `<pre>` used to stand in for its one input, so
  lf-code could not take a playhead and keep its `<pre>`: page check refused the
  `<pre>` once `follows` bound, and element-data.js would have set the playhead
  to the source text. The input the `<pre>` stands in for is now the one marked
  `"body": true` (lf-diff's and lf-text-document's); other inputs leave the
  `<pre>` alone.
- `scrollersOf` joins portable-api.js so a widget can bound a reveal to the box
  the layout scrolls it in.

Behavior changes: lf-code is a LeafElement on every page; a data widget's
second, non-body input is now allowed.
…runs no fold or selection

A widget output was a field of the application root. Each `publishOutput` ran the
whole `publish`: it folded the page's threads and widgets again, bumped
`semanticEpoch`, and made every selection on the page derive its part again. `data.js`
now keeps the values with the element that published them, behind one signal only
output readers read, and `outputs`, its epoch term and `applicationState.publishOutput`
are gone. A reader follows the instance under its bound id as before, and a producer's
connection or a changed value moves the signal.

Behavior changes:
- Publishing an output moves no root: `watchSemantic` and every selection stay quiet.
  The user-view report no longer follows an output change; its 10 s interval and the
  page's other moves still send it.
- Nothing about a reader's proof changes. Its region is claimed in the publishing
  stack, as any `LeafElement`'s is, so `applicationPresented()` turns false at once and
  `whenApplicationPresented()` waits for the draw. A probe on both arms reads the same
  at each wait. `whenDocumentPresented()` called in the publishing task does not wait
  for a reader on either arm, because Lit queues the update a microtask later.

Measured in Chromium with CDP `ScriptDuration` over three interleaved rounds, minimum
per phase, load 14-28 (script ms per change; calls per change don't move with load):

  page                 nobody reads it, every frame     reader draws
                       before -> after  calls           before -> after  calls
  wt-merge             0.19 -> 0.09     1,344 -> 90     0.93 -> 0.75     40.4k -> 39.1k
  rust-sort            0.56 -> 0.50     1,740 -> 368    1.97 -> 1.85     54.2k -> 52.8k
  wt-merge+50 threads  0.28 -> 0.10     6,401 -> 405    2.36 -> 2.24     84.6k -> 78.4k
  wt-merge+200 threads 0.43 -> 0.09     21.3k -> 734    2.81 -> 2.48     136k -> 115k

The publication's cost grew by about 100 calls per thread before and is flat after.
A keyboard step is unchanged within noise (wt-merge 1.97 -> 1.84), since its time goes
to the film's paint and style.

Most of a reader's cost remains, and it never came from the publication:
`LeafElement.updated` calls `paintKeysWithin`, which asks for the page-wide repaint
frame (command hints, close requests, input hints, keys) after any widget's draw,
whatever moved it. Taking that one call out removes 98% of wt-merge's calls per change
(39.1k -> 749) and 0.49 ms of its 0.75 ms script. It is left in, because the frame
reads nodes a draw can change and that is a decision about every widget, not outputs.
An `x-data` input bound through `reference` named the producer's port as well as the
contract, so a consumer knew an implementation detail of whichever widget it was
pointed at, and a second producer of the same contract had to reuse the port's name.

The `output` key is gone. An input reads the one output of its contract that the widget
named by its reference declares. `page check` (`output-contract`) refuses a producer
with none, or with more than one, naming the outputs it found. `lf-file-tree`,
`lf-text-document`, `lf-code` and `lf-merge-steps` move over in this commit, with the
fixtures, `package-data.md` and the registry's description of each key.

Behavior changes:
- A registry that declares `output` on an input now fails registry validation with an
  unknown-key error, which is what a page's own package sees; deleting the key fixes it.
  Bundled packages are composed by the serving Leaf, so no page needs a protocol bump
  (`layer-registry.md`, "Page protocol").
- A producer may declare a second output of another contract without affecting readers.
  Two outputs of one contract are refused only where an input binds that producer.
- The runtime's contract-mismatch error now only concerns sources, since an output's
  contract is what selects it.

Also corrects the registry's `x-data` description, which still said an `x-content: data`
element's one input reads its `<pre>`; it is the input marked `body`.
`commandfor="merge-flim"` and `command="seek"` passed `page check`, and the browser
reports nothing for either, so a dead button reached the user.

A tag now lists the custom commands it handles in its registry entry, `x-commands`, a
map from `--name` to what it does. `page check` and the message gate refuse an authored
`commandfor`:
- naming no element, with the same `unknown-reference` finding as an `x-refers` attribute;
- with a `--` command its target's tag doesn't declare (`undeclared-command`, which lists
  what it does declare);
- with a command that is neither `--` nor one of HTML's six keywords, or with none
  (`unknown-command`).

Chromium and Firefox both reflect exactly those six keywords and `--` names through
`button.command`, in any case, so `toggle-popover` and `show-modal` stay untouched. One
of them aimed at something it can't act on, such as `toggle-popover` on a widget, still
passes.

How the two scopes relate: `commandfor` is the browser's reading, the first element with
that id in the button's own tree, and `x-refers` (`runtime/references.js`) looks in the
reader's message first and then the page. A message stands in the page's light DOM, so a
button in one reaches the page's widget; a probe pressed one and the film moved. On a
duplicate id they would disagree. A probe that put an element with the film's id in the
message's body sent the message's button to the page's film, where `x-refers` would take
the message's element; the same element placed before the film took the press. The checks
already keep that from a user, since `ids-taken` refuses a message reusing an id of the
page or a thread, and `ids-taken-by-messages` refuses a revision reusing a message's. A
live sample is its own document, checked on its own ids. A message may name an id in
another thread's message, as `x-refers` may; that button does nothing while the other
thread isn't drawn.
Package authors had the mechanics of outputs and no rule for choosing between them and
a command. `package-data.md` now says a value one widget holds now goes through an
output, and the reader draws its own mark from it. `module-state.md` says the reader has
to be a `LeafElement` and the producer can be any element whose tag declares the output.
`module-input.md` gains "Invoker commands", for a request to do something now, declared
in `x-commands`. Each points at the other for the case it doesn't own.

Behavior changes: none in the code. `notes/named-widget-interfaces.md`, a deferred
proposal nothing references, is deleted.
`page check` looked for a bound input's output only on an `lf-*` target, so
`for="some-paragraph"` passed and the input always read null. A target that stands in
the document and isn't a widget now gets the same `output-contract` finding as a widget
declaring none. An id that names nothing still gets `unknown-reference`.
… frame

Admission accepted an `x-refers` or `commandfor` naming an id in another message, but
`references.js` reads only the message's own document and the page, so the reference
drew nothing. It is now refused with `unknown-reference`, where the agent writes it.

`lf-merge-steps` returned early on a null frame, keeping the last step's caption and
disabled buttons after the film left. It now draws the unset state.
…line a third down

A fresh reader found the followed line pinned to the pane's foot, with the panel at the
window's foot covering it, and the pane snapping back within half a second of a wheel
during play. `lf-code` now puts the line a third of the way down the box when it leaves
the middle of it, and leaves the box alone once the reader has moved it, until the mark
is back in view. At rust-sort's default 2x, the pane cuts 23 times in 10 s rather than
48, and a wheel away holds for as long as the reader stays there.

The references now say in the state table when a value goes through an output, in the
skill's route where sharing state and asking a widget to act are covered, and that a
press before the target has loaded does nothing: a fresh author building a timer from
the references alone named each as a place it had to guess.
# Conflicts:
#	browser/types/contract.d.ts
Main dropped the `x-` prefix and flattened a widget declaration (#6234,
#6257), so the branch's keys move with it: an input lives under `inputs`,
an output under `outputs`, a relation under `refers`.

Two of the branch's additions go in the port, to keep the declared
interface as small as #6134 left it:

- `x-commands` and its check are gone. A widget names the custom
  commands it handles in its `instructions`; `page check` no longer
  refuses a `commandfor` with no target or an undeclared `--` command.
  The wt-merge film still takes `--seek` from its steps' buttons.
- The `body` flag on an input is gone. A `content: data` widget's `<pre>`
  stands in for its input that names a `source`, since that is the input
  an authored value could replace; an input bound only by reference, as
  lf-code's `playhead` is, leaves the `<pre>` alone. Python's registry and
  markup checks and the browser's first read follow the same rule.

Main's new output readers, lf-text-document and lf-file-tree, drop their
`output` name and bind their producer's one output of the contract, as
the branch does for every reader. lf-code keeps main's wrapping and notes
toolbar, and the playhead mark takes the theme's prefixed accent tokens.
`notes/named-widget-interfaces.md` stays as main has it, since #4065 was
closed as postponed with that note as its plan.

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two open backlog issues cover the parts this PR does, and the description links neither. Each needs a Closes or a Part of line so that merging doesn't leave stale work on the backlog:

  • #6008 (rust-sort's source lights the line its sort film runs). If the rust-sort part survives your pick, this PR does what #6008 asks, so Closes #6008 fits. One difference is a decision worth making before landing: #6008 bound the excerpt with for, "since for is the rule's attribute for reading another widget's output". This PR adds a new follows attribute instead. If the part comes out, the issue stays open.
  • #5981 (share a widget's value as a property and change, ask by invoker command, drop role-typed references). This PR lands part of it: outputs leave the application state, an input binds by contract with no output field, wt-merge uses invoker commands instead of film-frame/seekChapter(), and a message can no longer reference another message's id. #5981's value channel is a property plus change replacing publishOutput. This PR keeps publishOutput, so it answers that open question the other way, and #5981's commandfor check in page check isn't here. Part of #5981, with which of those it settles, would let the last part's review tell when #5981 is done.

The verdict waits on the two picks under "Waiting on Max". The focused model tests for output contracts and message references pass locally, as does tests/runtime/data-subscriptions.test.mjs.

@max-sixty

Copy link
Copy Markdown
Owner Author

Closing as a duplicate of draft #5981 and #6008, which build the same binding by contract, message check and wt-merge invoker buttons, and light rust-sort's line through the existing for attribute. The one difference this PR carried, keeping publishOutput as the value channel, is a question on #5981's review page.

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

@max-sixty max-sixty closed this Nov 22, 2026
max-sixty added a commit that referenced this pull request Nov 23, 2026
…e answer it shows (#6759)

`shows` stops being a declared fact. The board's module already placed a
card by the answer it shows and refused a drop the other widget can't
take, while the server kept rules of its own about the same cards. This
deletes the server's copy: `shown_answers.py`, the `shows` and
`awaits.key` schema, nine findings and the public `shownAnswer`, which
moves into the board. That leaves 27 facts and 229 fewer lines of
production code. `browser/AGENTS.md` now states the rule this applies:
add a fact only where some part of Leaf must act on it without running
the widget's module, and the module can't keep the same rule itself.

A correctly written board draws and records the same as on `main`. What
changes is what an author is told:

- `page check` no longer refuses a card whose `shows` names an element
with no answer. The board reports it when the page draws, so `page check
--render` fails on it, and it also reports a card whose question gives
its options no `value`.
- In a thread message nothing draws the board before the user opens the
thread, so a card there that names a page's widget, which admission
refused, is first met by the user. The agent then hears of it as the
page's error.
- Three pieces of `page check` advice about valid cards go: a card
written apart from its authored answer, which moves when the page draws;
a board with no column for an unanswered question; and a column whose
value the question can't answer.
- The server admits a board move of a `shows` card that a command writes
to the log. The page ignores it, and the board never sends one.

Max picked this rule on the run's Leaf page, with the first and last of
those costs in front of him; the other two came out of review and he
hasn't seen them or the diff. A typed `refers` contract for `shows`
would bring the static refusal back without core code, at the cost of a
registry map listing each widget a card may show.

It conflicts with #5981 in five files and with #6690 in the generated
`contract.d.ts`; whichever lands second carries the merge.

Tests: four browser tests of cards that show an answer, 825 registry and
vocabulary model tests, and `pnpm run check`. The `AGENTS.md` passage
was scored in a scratch A/B and changed nothing on a plainly stated case
(the module, 3 of 3 on both arms). The new sentences in `lf-card`'s
instructions and `packages.md` are unscored, since no eval covers a
board or what a package declares.

> _This was written by Claude Code on behalf of max-sixty_
max-sixty added a commit that referenced this pull request Nov 23, 2026
**What it does.** The sort film holds the slice.rs lines its step runs
as its `playhead` output (contract `source-lines`, declared by the
default package). Each `lf-code` names the film in `for` and marks those
lines. `for` rather than the experiment's `follows`, since `for` is the
rule's attribute for reading another widget's output.

**What a reader sees.** The running line gets an accent bar and number.
When it leaves view, the code pane glides it to its middle; the page
never moves. A single step elsewhere, such as insert_head's call site,
moves nothing. Scrolling or clicking in the pane stops the following;
pressing the film resumes it.

**Measured** on 21 November, the default film at 1440×900, one journey
on this branch and on #6690, which lights the same line and follows
every one. While the film plays its minute, the pane moves 42 times here
against 116, travels about 42,600 px against about 99,000, and shows the
lit line 76% of the time against 100%, never out of view for more than
0.7 s. The right line is lit at each of the 451 key steps that run one.
Chromium, Firefox and WebKit agree on those counts. A page of 200 code
blocks is presented about 750 ms after load here and on main: a median 6
ms slower over 12 paired runs, slower in 7.

**Costs.** lf-code is a LeafElement on every page. A data widget's
`<pre>` feeds only its `value` input. `scrollIntoView` bounded `within`
a box applies `block` and `behavior` there. `scrollersOf`,
`alreadyShown` and `onUserInput` join portable-api; the block reads the
reader's hand in its pane from `onUserInput`, with no listener of its
own.

**Instructions scored** on 21 November against the base branch, three
samples an arm on Claude Code. Asked to make an excerpt show the line a
page-owned stepper is on, authors bound `for` to a declared
`source-lines` output in 3/3 with the new lf-code instructions and 0/3
without, where each reached the excerpt from the stepper's module. The
three passing replies run as real pages. The task's three other lf-code
contexts passed 8/9 and 9/9; the one failure used no lf-code. The case
is `source-code-readable/lines-follow-a-widget`.

**Current with main as of 23 November**, through #5981: the block stands
on main's reworked lf-code (a language named by a class on `<code>`, the
notes toolbar), main's declaration names (`inputs`, `outputs`, `refers`)
and its reworked `landing-scroll.js`, and its colours use the prefixed
tokens.

**Asked for by Max**, who picked lighting the line on 14 November and
asked for this to land with #5981 on 23 November without having read the
diff in full. The quieter follower costs 150 lines in lf-code against 73
for #6690's, which follows every line; that call is his to reverse.

> _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