Repository navigation
Prototype: Leaf widget calls as Effect UI Command services - #7378
Conversation
Both widgets now mount through `defineWidget` in a shadow root with `lfPatch: "members"`, and their inputs read the element's and its members' attributes. A descendant's `lf-connect` reads them again, so a kept widget redraws in place and its native disclosure keeps its open state and focus. `worktree-view.js` and `worktree-diffs-view.js` are deleted. `lf-worktree-diffs`'s view wraps the overview and slot in a `display: contents` div, since an Effect UI view has one root. Stills show one visible difference: "+7" kerns as one text node rather than Lit's two. The adapter reads `inputs` through one guarded call, so a throw from a descendant's `lf-connect` stays on the widget as a signal-driven one does. The capture test now drives the defined elements rather than the deleted view functions. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01V22NWd3erndyoj2G9LEP7y
What an Effect UI widget asks of Leaf becomes a `Command.Service` in `/runtime/widget-services.js`: `RecordAction` (the protocol's `lf-action`, whose success is the delivery: admitted, refused or unrecorded) and `NextOnMe` (`obligationActions.next`). The adapter, now `/runtime/effect-widget.js` since it provides runtime services, provides `leafServices(element)` at each mount, so a component names what it needs from Leaf in its requirements and a test provides a fake. A Command runs in a microtask of the task that handled the gesture, so Leaf records it before the next frame. `WidgetEvents` goes: a component's events now speak only to the page around it. The tally issues `NextOnMe`, and a story test (`Story`, @effect/ui/testing) checks its press with no page, element or Leaf behind it. The bundle tests stub every public runtime module they don't trace, rather than only the library's, and the facade rule lets the services module reach the application as `widget-api.js` does. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01V22NWd3erndyoj2G9LEP7y
leaf-agent
left a comment
There was a problem hiding this comment.
For the maintainer's call on the interface: widget-services.js gives two capabilities a second call route beside the one they already have. AGENTS.md's Fix the underlying issue asks for one canonical API per capability, so if this direction is adopted the older route should go with it.
NextOnMeisobligationActions.next, whichwidget-api.jsstill exports. An Effect UI widget calls one, and every other widget calls the other.RecordActionrestateslf-action. ItssendcopiesLeafElement's private#send(dispatch the event, then readevent.delivery), but returns the result in a different shape:"admitted" | "refused" | "unrecorded", whereLeafElement.recordreturnsPromise<event | null> | null. So the same answer reaches a widget in two shapes depending on how it draws. If the services are the direction,LeafElementcould read the delivery through the same helper, so the delivery has one definition. Otherwise, mapping the existing shape keeps one vocabulary.
export const Tally is exported only so the story test can import it. That puts a test-only name on a bundled package module.
`sendGesture` (lib/widget-events.js) dispatches `lf-action` or `lf-undo` and returns the delivery Leaf sets on the event. `LeafElement.record` and the `RecordAction` service both call it, so the delivery has one definition and the service only maps its result. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01V22NWd3erndyoj2G9LEP7y
# Conflicts: # browser/runtime/lib/effect-widget.js # packages/diff/widgets/lf-worktree-diffs.js # packages/diff/widgets/lf-worktree.js
leaf-agent
left a comment
There was a problem hiding this comment.
This head conflicts with main in browser/runtime/effect-widget.js and browser/vendor/effect-ui.js. #7388 ("compare a DOM node an Effect UI widget reads by reference, not structurally") landed on main and touched the adapter at its old lib/ path. Because of the conflict, GitHub runs no pull_request CI on this head, so nothing has checked the merged result. Merging main means carrying #7388's change into the moved runtime/effect-widget.js and rebuilding the bundle. Apart from that, I have no findings beyond the draft review, and sendGesture settles its point about reading the delivery in one place.
# Conflicts: # browser/runtime/effect-widget.js # browser/vendor/effect-ui.js
`leaf-dev interface --base` now reports the names the Effect UI ports made available to packages. Before this change it read functions from `widget-api.js` and `portable-api.js` alone, so it reported nothing for them. Run on each port's own commit against its parent, it now reports additions for every one of #7374, #7378, #7397, #7399, #7400 and #7395. For example, against the commit before #7374 it lists `/runtime/effect-widget.js`, `/runtime/widget-services.js` and `/vendor/effect-ui.js` as modules, `defineWidget`, `widgetProps` and the eight `widget-services.js` exports as functions, and Effect UI's 16 exports. The census now reads every module `$public-modules` lists outside the library, with each module's exports, including the vendored ones. It also reads every mark any reference gives, which adds 21 documented marks it missed, such as `data-lf-focus-visible`, and the chrome parts `package-themes.md` lists. Root `AGENTS.md`'s "Keep the package interface small" now names the public modules and their exports as part of the interface, and the references that gave Lit as the only way to follow a page reading, or `widget-api.js` as the only module to import, now name the Effect UI forms too. What the move to Effect UI keeps and retires is left to the guidance change that states Max's call on it. To weigh: a vendored module's exports count as names, so a Lit bump that adds an export shows as an addition. A widget's own `part` names are its package's, so the census doesn't count them. A function's options count as part of that function, so `--base` doesn't list them. Asked for by Max from the parts-column-scroll page and in the session. Codex reviewed five rounds. Tests: `dev/tests/model/test_interface.py`, `tests/runtime/widget-api.test.mjs`. Evals: `widget-controller-lifetime` and `widget-ratings-recorded-by-leaf`, 12/12 on both arms. > _This was written by Claude Code on behalf of max-sixty_
Requested by Maximilian · project thread
This changes the package interface (
AGENTS.md, "Growing the package interface").This prototype defines what an Effect UI widget asks of Leaf as
Command.Services, rather than as events the adapter translates or functionswidget-api.jsexports. A component names the services it needs in its requirements, and the adapter provides Leaf's live implementations for each element. A test provides fakes, with no page.What changes
/runtime/widget-services.jsdefinesRecordAction, the protocol'slf-action. Its success is the delivery Leaf gives the event:admitted,refusedorunrecorded. A widget can react to a refusal there, which an Effect UI event can't carry back. The module also definesNextOnMe, which isobligationActions.next.defineWidgetprovidesleafServices(element)at each mount.WidgetEventsgoes, so a component's events speak only to the page around it.lib/to/runtime/effect-widget.js, because it now reaches runtime services. The facade rule independency-cruiser.mjsletswidget-services.jsreach the application, aswidget-api.jsandwidget-controller.jsdo. This module is separate fromwidget-api.jsso that pages without an Effect UI widget never load the Effect bundle.lf-tallyissuesNextOnMe.tests/runtime/lf-tally-story.test.mjschecks its press with Effect UI'sStory, against a fake, with no page or element.Storyis imported fromnode_modulesin the test, and it works across the two Effect copies. Vendoring it would add 175 KB to every page that loads the bundle.Worth weighing
stateon the line after it records.TakeBack(lf-undo) is left out until a widget needs it.NextOnMebesideobligationActions.next, andRecordActionbesideLeafElement.record. Both read the delivery through one helper,sendGesture. If the services are adopted, the older routes go as their callers move.lf-tally.jsexportsTallyfor the story test. In the end state, every component module would export its component this way.Tests
pnpm run checkand pre-commit.tests/journeys/test_widget_quality.py.🤖 Generated with Claude Code
https://claude.ai/code/session_01V22NWd3erndyoj2G9LEP7y
Generated by Claude Code