Skip to content

Prototype: Leaf widget calls as Effect UI Command services - #7378

Merged
max-sixty merged 5 commits into
mainfrom
effect-ui-services
Nov 27, 2026
Merged

max-sixty merged 5 commits into
mainfrom
effect-ui-services

Conversation

@max-sixty

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

Copy link
Copy Markdown
Owner

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 functions widget-api.js exports. 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.js defines RecordAction, the protocol's lf-action. Its success is the delivery Leaf gives the event: admitted, refused or unrecorded. A widget can react to a refusal there, which an Effect UI event can't carry back. The module also defines NextOnMe, which is obligationActions.next.
  • defineWidget provides leafServices(element) at each mount. WidgetEvents goes, so a component's events speak only to the page around it.
  • The adapter moves from lib/ to /runtime/effect-widget.js, because it now reaches runtime services. The facade rule in dependency-cruiser.mjs lets widget-services.js reach the application, as widget-api.js and widget-controller.js do. This module is separate from widget-api.js so that pages without an Effect UI widget never load the Effect bundle.
  • lf-tally issues NextOnMe. tests/runtime/lf-tally-story.test.mjs checks its press with Effect UI's Story, against a fake, with no page or element. Story is imported from node_modules in the test, and it works across the two Effect copies. Vendoring it would add 175 KB to every page that loads the bundle.
  • The two kernel-bundle tests stub every public runtime module they don't trace, not only the library's.

Worth weighing

  • A Command runs in a microtask of the task that handled the gesture, not inside the click handler. Leaf still records the gesture before the next frame (a runtime test asserts this), but a widget can no longer read the new state on the line after it records.
  • TakeBack (lf-undo) is left out until a widget needs it.
  • While this is a prototype, two capabilities have two routes: NextOnMe beside obligationActions.next, and RecordAction beside LeafElement.record. Both read the delivery through one helper, sendGesture. If the services are adopted, the older routes go as their callers move.
  • lf-tally.js exports Tally for the story test. In the end state, every component module would export its component this way.

Tests

  • pnpm run check and pre-commit.
  • The tally browser tests: the Next On Me walk, initial delivery, and the crossed thread responses.
  • tests/journeys/test_widget_quality.py.

🤖 Generated with Claude Code

https://claude.ai/code/session_01V22NWd3erndyoj2G9LEP7y

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


Generated by Claude Code

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
@max-sixty max-sixty self-assigned this Nov 27, 2026

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

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.

  • NextOnMe is obligationActions.next, which widget-api.js still exports. An Effect UI widget calls one, and every other widget calls the other.
  • RecordAction restates lf-action. Its send copies LeafElement's private #send (dispatch the event, then read event.delivery), but returns the result in a different shape: "admitted" | "refused" | "unrecorded", where LeafElement.record returns Promise<event | null> | null. So the same answer reaches a widget in two shapes depending on how it draws. If the services are the direction, LeafElement could 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
Base automatically changed from effect-ui-worktrees to main November 27, 2026 10:14
# Conflicts:
#	browser/runtime/lib/effect-widget.js
#	packages/diff/widgets/lf-worktree-diffs.js
#	packages/diff/widgets/lf-worktree.js
@max-sixty
max-sixty marked this pull request as ready for review November 27, 2026 15:26

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

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
@max-sixty
max-sixty merged commit 3fa2e5a into main Nov 27, 2026
5 checks passed
@max-sixty
max-sixty deleted the effect-ui-services branch November 27, 2026 15:53
max-sixty added a commit that referenced this pull request Nov 28, 2026
`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_
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.

3 participants