Skip to content

Add LeafElement, a Lit widget base class, on five widgets; hold only the dragged widget during a drag - #2869

Merged
max-sixty merged 9 commits into
mainfrom
selection-keyed-repaint
Oct 14, 2026
Merged

max-sixty merged 9 commits into
mainfrom
selection-keyed-repaint

Conversation

@max-sixty

@max-sixty max-sixty commented Oct 14, 2026 •

Copy link
Copy Markdown
Owner

Adds LeafElement, a Lit base class for widgets whose render() reads Leaf state directly and draws again when anything it read moves, and converts five widgets to it as a prototype before converting the rest. It also removes the page-wide drag hold, so only the widget being dragged holds its drawing.

Why

A widget today draws through two paths beside Lit: the widget controller's subscribe/renderState, and watchData for bound data. Each repeats the same duties (claim the render region, hold while away or deferred, settle presentation proof, show the fail-soft box). LeafElement (skills/leaf/assets/runtime/leaf-element.js) does them once: render() reads through collected readers (the widget's reading and state, this.data(input), asks, reports, the time), and a move in any of them claims the widget's region inside the publication and draws on the next update, which settles the claim as it commits.

What's converted

lf-atlas-worker and lf-atlas-tree (command hub, and the corpus copies), lf-options, lf-board, lf-file-editor, and the work fixtures lf-test-worker and lf-test-tree. The converted widgets drop their subscription and paint plumbing (net −12 lines across the seven files: lf-file-editor grew by 23, the rest shrank) and pass their existing browser tests. The controller path and watchData stay for the 13 widgets not yet converted; the controller's defer() and an ancestor's remount refresh reach a LeafElement through drawsItself.

Failures

A failed draw shows the fail-soft box at the head of the widget's render root, beside the nodes it drew, and the next draw takes it away, so a widget that paints retained nodes (lf-options paints its authored options) still has them to draw on. The same placement takes a rejected present() preparation and a module's own failSoft(this, …) (placesFailure in widget-upgrade.js). A setup() that throws shows its failure and the element draws nothing after it. An update's claim settles once updated has run too, and a failure anywhere in the update rejects it.

Drag hold

While any widget held a drag, every widget, every controller subscription and the document-wide projection pass held new state until the hand was down. Now only the widget whose drag moves its own nodes holds its drawing, through its controller's defer() (lf-board already did); the hand still holds back a new revision and an undo. This deletes the drag waiters in LeafElement and the controller, the projection's drag gate and deferral, watchDragRelease, and the framework's PRESENTATION_HELD. test_foreign_state_draws_beside_a_live_drag covers the new behaviour: a draft above a board grows mid-drag, the board moves 174px under the pointer, and the drop still records the move.

Trade-off: a board inside an lf-old/lf-new suggestion that someone else accepts or rejects mid-drag is retired under the hand.

Behaviour changes

  • Converted widgets draw on the microtask after the publication that moves their reading, not during it.
  • Foreign state draws beside a live drag rather than waiting for its release.

Navigating the diff

  • skills/leaf/assets/runtime/leaf-element.js and tests/runtime/leaf-element.test.mjs: the base class and its tests.
  • skills/leaf/assets/runtime/data.js, reports.js, widget-controller.js: the readers LeafElement collects, and the controller's hand-off to it.
  • projection/presentation.js, projection/state.js, build/browser/presentation.ts: the drag-hold removal.
  • The widget files: the conversions.

TODO.md gains an unconfirmed item: let Lit's SignalWatcher follow a widget's reads once Leaf's publication is TC39 signals.

Inherited CI failure: the test job's pre-commit step reformats tests/browser/test_render_navigation.py (ruff format), a file this branch does not touch; main carries the same line.

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

max-sixty and others added 5 commits October 14, 2026 09:32
A prototype of a Lit-first widget contract, measured on five widgets before deciding
whether to convert the rest. `LeafElement` (runtime/leaf-element.js) is a LitElement
base class whose render() reads through collected readers (its reading and state, a
bound data source through `this.data(input)`, asks, reports, the time) and draws again
when any of them moves. It owns the widget's render region: a move claims it inside the
publication, the next update that draws settles the claim as it commits, and a failed
update settles it with the fail-soft box in the render root. It draws nothing while
away, holds through the controller's defer() and a drag, gates on an incomplete startup
reading, and holds the data version for a tag that declares x-data. Bound data moves
only as state application delivers it, as a watchData subscription's staged paint does.
A reading of presentation proof (`proofReading`), such as the new `reportsReady`
narration gate, draws again without claiming, since a claim would move that proof.

Converted: lf-atlas-worker and lf-atlas-tree (command hub, and the corpus copies),
lf-options, lf-board, lf-file-editor, and the work fixtures lf-test-worker and
lf-test-tree. The controller's subscribe/renderState path and watchData stay for the
widgets not converted; the controller's defer() and an ancestor's remount refresh reach
a LeafElement through `drawsItself`, and both share `widgetMounted`.

Behaviour change: converted widgets draw on the microtask after the publication that
moves their reading, not during it.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…every failure

An update settles the claim it started with; a claim its own reads make while it runs
is the next update's. A draw queued as the element left waits for its return even
before the arrival batch reports the departure. A failure in the gate or after the
draw is reported and shown once, rather than swallowed. Accepted data claims the
element's region inside the publication that accepts it and draws at delivery, as a
watchData subscription's staged ticket does. The ownership test runs with LeafElement
widgets too, covering a remounted part whose owner places it.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
While any widget held a drag, every LeafElement, every controller subscription and
the document-wide projection pass held new state until the last hand was down. Now
only the widget whose drag moves its own nodes holds its drawing, through its
controller's defer() (lf-board already did); the hand still holds back a new revision
and an undo, which would replace the nodes under it. Other widgets draw foreign state
during a drag: a draft above a board that grows mid-drag moves the board 174px under
the pointer, and the drop still records the move Sortable made.

This deletes the drag waiters in LeafElement and the controller, the projection's
drag gate and its deferral reading, watchDragRelease, and the framework's
PRESENTATION_HELD, whose only producer was that gate. Tests that asserted the
page-wide hold now assert the new behaviour or, where the hold was their subject
(a report held behind a body drag, the drag release's projection wake), are deleted.

TODO.md gains an unconfirmed item: let Lit's SignalWatcher follow a widget's reads
once Leaf's publication is TC39 signals.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts:
#	skills/leaf/assets/runtime/semantic-state.js

@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.

LeafElement.update() resolves the presentation ticket before Lit calls updated(). If updated() throws, performUpdate() shows the fail-soft box, but the coordinator has already recorded a successful commit. I reproduced this with a LeafElement whose updated() throws: the error box appeared while readApplicationPresentation() reported pending: [] and presentedEpoch: 1. The converted tree widgets call projectData() from updated(), so a failure there can also let data delivery stamp its version before datum projection completes. Keep the ticket open through the full update lifecycle and reject it when that later work fails.

max-sixty and others added 2 commits October 14, 2026 11:07
# Conflicts:
#	skills/leaf/packages/file-editor/widgets/lf-file-editor.js
…aim after updated

A failed draw replaced the render root's children with the fail-soft box, so a widget
that paints retained nodes, as lf-options paints its authored options, had nothing to
draw on afterwards: the next reading removed the box and left the options gone. The
box now stands at the head of the render root beside what the element drew, and the
next update that draws takes it away (`placesFailure` in widget-upgrade.js, which a
LeafElement registers). The same placement takes a rejected `present()` preparation
and a module's own `failSoft(this, …)`, which had replaced a shadow widget's whole
stage and detached its render root. A `setup()` that throws shows its failure and the
element draws nothing after it, so lf-file-editor-style builds need no catch of their
own.

An update's claim now moves at its gate and settles once Lit has run all of it,
`updated` included; a failure anywhere, `willUpdate` too, rejects it rather than the
coordinator recording a commit before work after the draw failed (leaf-agent's
finding). A draw nested in another's `updated` with no claim of its own fails the
enclosing one. The hold is one flag, since the controller's `defer()` refuses a
second, and the refresh is a private method rather than a symbol.

lf-file-editor.js takes prettier's indentation after the merge of #2867.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
leaf-agent previously approved these changes Oct 14, 2026
…raw's failure its own

A draw that failed under a claim was reported only by the presentation coordinator, as
"Presentation failed", with no widget named. The element now reports it as the widget's
own failure before rejecting the claim, so the agent that wrote the widget can find it,
and a failure on a claim the coordinator has since retired is still reported.

A nested draw's failure no longer rethrows into the enclosing update: Lit's catch there
cleared the update a nested publication had queued. Each draw settles its own claim.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

@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.

A nested draw can fail while the page records the enclosing update as successfully presented. The inline suggestion keeps that failure tied to the open presentation claim.

…fails

leaf-agent's suggestion: a draw that updated() starts at once, as lf-file-editor's
paint() may, and that fails with no claim of its own now rejects the enclosing
update's claim rather than letting it record a commit beside a fail-soft box.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit 6305a9c into main Oct 14, 2026
4 of 5 checks passed
@max-sixty
max-sixty deleted the selection-keyed-repaint branch October 14, 2026 19:19
max-sixty added a commit that referenced this pull request Oct 14, 2026
…he render check (#2898)

Converts ten more widgets from the widget controller's
`subscribe`/`renderState` route and `watchData` to `LeafElement`
(#2869), and makes the render check's replay cover `LeafElement`
widgets.

### Converted

- `lf-draft`, `lf-playground` (default and playground packages),
`lf-call-diff` (diff package), `lf-text-document` (default package).
- `lf-atlas-task` (command hub, and the corpus copy), `lf-pr-brief` (PR
walkthrough, and the corpus copy).
- The test widgets `lf-test-task`, and the page-script fixtures
`seated-ask`, `drift` and `relative`.

Each now draws in `render()` from what it reads (`this.state`,
`this.reading`, `this.data(input)`), with its one-time build in
`setup()`. Behaviour is unchanged; the widgets' existing browser tests
pass. `lf-playground` no longer catches its own build failure: a
`setup()` that throws shows its failure through `LeafElement`.

Widgets that wait on asynchronous work start it with
`controller.present()`: `lf-text-document` starts its existing
highlighting and preview from `updated()`, and `lf-pr-brief` waits for
the Markdown renderer once a delivery, then draws a Lit template and
highlights after the draw. For that, a `LeafElement` whose tag declares
`x-data` now holds the page's data version on both its widget regions,
render and preparation (`joinDataDelivery` in `data.js`), so the version
is not stamped before highlighting or a preview frame lands.

### Render check

`relativeReplays` (`render-checks/replay.js`) replays a `LeafElement`
through its new `redraw()`, which draws its render alone again, outside
any claim and outside Lit's schedule, and throws what fails (not
`updated()`, whose work may start preparation that lands after the
synchronous check reads the page); a `renderState` widget still replays
through `renderState` until the rest are converted. The `relative`
fixture, now a `LeafElement`, still yields both relative-render
findings.

### Tests

-
`test_a_widget_presents_its_authored_state_offline_and_the_log_on_recovery`
(startup): an `lf-options` presents its authored state when the first
read fails and draws the logged choice once a read succeeds.
- A runtime test that `redraw()` leaves the update a move queued, with
its claim.

### Left for later PRs

`lf-suggestion`, `lf-visual-review`, `lf-diff` and `lf-trace`, the test
files' inline widgets, the module-authoring references, and then the
controller's paint route and `watchData` themselves. `lf-suggestion`'s
fold measures the retiring slot before the layer marks it retired, which
needs the widget to draw inside the publication, as the controller route
did; that timing change to `LeafElement` comes with it.

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

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
max-sixty added a commit that referenced this pull request Oct 14, 2026
…prose in plain prose (#2905)

The rest of the prose rewrite that #2897 started: Leaf's references,
maintainer guidance, module headers, CLI and finding text, registry
prose and the site's how-it-works and threads pages, rewritten in short
plain prose that names the real case before stating the rule, with
guidance that didn't help cut. Root `AGENTS.md` and
`skills/leaf/SKILL.md` are held back for the maintainer's own review.

Each area was rewritten by one agent and reviewed by a second for
accuracy, lost rules and readability; every review's findings are
applied. Commit messages list every cut.

| Area | Words |
| --- | --- |
| Widget and package references (`module-*.md`, `package-data.md`,
`package-themes.md`) | 22,139 → 15,036 (−32%) |
| Authoring references (`page-*.md`, `authoring-*.md`,
`serving-pages.md`, `live-samples.md`, `packages.md`, the Codex and Pi
harnesses) | 20,059 → 14,024 (−30%) |
| Area `AGENTS.md` files, `/developing-leaf` and its glossary | 27,626 →
21,263 (−23%) |
| Module headers (`codex.py`, `todos.py`, `hook_transport.py`,
`workflows.py`, `delivery.py`, `detached.py`, runtime
`semantic-state.js`, `projection/presentation.js` and others) and CLI
help and finding text | −10%; several headers grew where they now name
their real callers |
| Registry `$` declarations and delivered `handling`/`answering` clauses
| −26% |
| `docs/how-it-works.html`, `docs/threads.html` | rewritten sections −9%
|

**Evals.** The six cases whose rules the authoring-reference cuts
touched (`sidebar-page-ask-grants-its-evidence-room`,
`pin-takes-no-page-room`, `long-read-beside-a-panel-is-a-document`,
`page-arrangement-uses-layouts`, `approach-page-leaves-the-choice-open`,
`source-code-readable`) score the same on base and candidate on Claude
Code (7/8 each; the same case fails on both). The two cases that paste
the delivered clauses (`user-rewrite-answered`,
`user-rewrite-retitles-its-thread`) are re-pasted with the new wording
and pass 16/16 cold and mid-session on Claude Code and Codex.

**Corrections to claims that were wrong on main:**
- `handling.report.0` and `docs/event-log.html` said `page check`
refuses markup that contradicts a report without answering it; #2020
removed that gate.
- `packages.md` said `grows-with-content` never sees a part scroll
inside a workspace; `widget_quality.py` draws each example in a
workspace pane too.
- `module-authoring.md` listed `UPGRADE` among importable startup
events; `widget-api.js` doesn't export it. It also lost `### Retained
nodes` in #2869, which three files cite; restored.
- `navigateToDatum`/`indicate` take the referring widget first; a
changed widget `id` (not declaration) makes the controller report every
action unavailable; `x-exhibit` is declared only on `lf-sample`.
- `assets/AGENTS.md` placed `comment-placement.js` and
`floating-response.js` in the default package; they are in
`runtime/annotation-overlay/`.
- `task end`'s note and the `finished-in-view` finding now say what
`work.open_ids` checks (the element shows unfolded on the newest
revision).
- `reconnect.py`: the resume `SessionStart` hook publishes reconnect
notices too.

**Other changes:** the "Re-vendoring and layer epochs" heading is now
"Re-vendoring", with its citations updated. The kernel is rebuilt for
the reworded runtime comments and registry prose. One contract test now
matches the reworded `unoverruled` finding, five regtest snapshots and
the CLI help snapshot are re-recorded (wording only), and
`test_stop_guard.py` matches the reworded report clause.

No code behavior changes.

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

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
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