Skip to content

Document every widget-api export or mark it internal, and test that the two agree - #2538

Merged
max-sixty merged 6 commits into
mainfrom
agent-ae99ab11aed3a87cb
Oct 12, 2026
Merged

max-sixty merged 6 commits into
mainfrom
agent-ae99ab11aed3a87cb

Conversation

@max-sixty

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

Copy link
Copy Markdown
Owner

widget-api.js is the helper surface package behavior modules import, and module-authoring.md documents it for package authors; 83 of its exports were named nowhere in that reference. Each export is now one of two kinds, read from the module's source: exports above its // Internal: comment are the authoring API and are documented in module-authoring.md, and exports below it serve Leaf's bundled packages and kernel widgets alone. Of the 83, 71 are now documented in the section that owns their topic, 11 moved below the marker (mountSample, dressSamples, wear, landInThread, threadInput, setRuntimeRootStyle, removeRuntimeRootStyle, shownParts, renderRetired, textNodesUnder, isPagePaint), and offerElement left the surface because nothing imported it from there. The new tests/runtime/widget-api.test.mjs parses widget-api.js and the importing modules with acorn and fails when an authoring export is undocumented, an internal export is documented or has no bundled importer, a behavior module imports a name the module does not export, or the reference calls a helper it does not export. It replaces test_every_widget_api_export_has_a_behavior_module_reader, including the import check #2533 added to it.

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

max-sixty and others added 4 commits October 12, 2026 00:02
…he two agree

widget-api.js is the helper surface package behavior modules import, and
module-authoring.md is its documentation for package authors. Every export is now
one of two kinds, read from the module's own source: an export above its
`// Internal:` comment is the authoring API, and module-authoring.md documents it;
an export below serves Leaf's bundled packages and kernel widgets alone.

tests/runtime/widget-api.test.mjs parses widget-api.js with acorn and fails when an
authoring export is not named in module-authoring.md's code, when an internal export
is documented or no bundled package or kernel widget imports it, or when the
reference calls a helper widget-api.js does not export. It replaces
test_every_widget_api_export_has_a_behavior_module_reader, whose rule (every export
has a reader) the new one subsumes.

Of the 83 exports module-authoring.md did not name:
- 71 are now documented where their topic lives (drafts, reports, syntax, image
  comparison, text alignment, scrolling, notices, registry reads, and the rest);
- 11 are internal: mountSample, dressSamples, wear, landInThread, threadInput,
  setRuntimeRootStyle, removeRuntimeRootStyle, shownParts, renderRetired,
  textNodesUnder, isPagePaint;
- offerElement leaves the surface, since nothing imports it from there.

saveDraft was named only by a contribution example's method of the same name; the
example's method is now save(), and the draft helpers are documented together.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
main bumped $events.protocol to 2 without regenerating
build/browser/protocol-contract.d.ts, so check:browser reported a stale contract.
This is pnpm run build:browser's output.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
leaf-agent previously approved these changes Oct 12, 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.

The generated protocol-contract.d.ts change is identical to #2539. One PR can drop that file so the protocol update has one owner.

… test

#2533 added to the deleted Python test a check that every name a behavior module
imports from widget-api.js is exported; tests/runtime/widget-api.test.mjs now holds
it, reading package, kernel-widget, example and fixture modules (HTML module scripts
included) with acorn. createRef joins the documented Lit exports, and main's
first-paint section now names keepView and tabStore.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
leaf-agent previously approved these changes Oct 12, 2026
Main exported readingPaint from presence.js (#2568), which lf-diff imports and
module-authoring.md documents, so it stays an authoring export; this branch's removal
of renderRetired and textNodesUnder stands. Main also split a margin control's
receipts out of presentContributionEntry into presentContributionReceipts (#2522), so
the reference documents both.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit d015fc9 into main Oct 12, 2026
3 checks passed
@max-sixty
max-sixty deleted the agent-ae99ab11aed3a87cb branch October 12, 2026 16:02
max-sixty added a commit that referenced this pull request Oct 12, 2026
Main squash-merged #2538, which this branch was built on, so the two histories hold the
same content for these files; the merge keeps this branch's versions.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
max-sixty added a commit that referenced this pull request Oct 12, 2026
…, and correct the claims the code contradicts (#2612)

`module-authoring.md` is the package author's reference for the helpers
`widget-api.js` exports. #2538 documented every authoring export, adding
each to the section that owned its topic, so the reference had grown
piecemeal. It now follows the task a package author is doing rather than
`widget-api.js`'s order, which groups exports by owning file and
scatters one task across the list. Each helper is documented once, with
its signature and return value where it was only named before, and other
sections point at it by name. Mechanism a package author doesn't act on
is cut. The file goes from 1657 to about 1770 lines.

Every behavioral claim was checked against the runtime, and a second
pass tried to refute about 110 of them. Claims the code contradicted are
corrected, among them:

- `readingRegion(id)` was documented but is not exported.
- `motion()` returns null only under reduced motion or before
presentation; the restored-state case went in #2332.
- `quietWord`: Leaf writes quiet words on elements it marks rewritten,
changed by the user, or reported. `x-paints` went in #2555.
- `renderState` runs only while the widget has a subscriber, and a
throwing `renderState` or subscriber replaces the widget with its
fail-soft box.
- Only subscriptions built on the owner lifetime pause while the owner
is away; `watchDraft`, `onUserInput`, `watchReadingRegionTransitions`,
`claimTraversals` and `boundFile.watch` do not.
- `afterScript` coalesces by function identity, so a new arrow each call
runs each time.
- `watchDraft` takes `{input}`, which the restructure first dropped: it
hands the user's caret to the replacement box across a live revision.
Its callback also fires with `null` when the box's own send goes.
- `threadActions.open` tries the registered primary reader, then the
open Threads panel, then inline, then Threads.
- `reach` is read from a row only; `readWork().done` is a count;
`compareImages` also returns `width` and `height`; `alignedNodes`
renders `same` runs as spans; the contribution kind is `ask`.

`tabStore` has its own section, "Tab-local working state", and "Sticky
headers" is its own section, which the glossary now cites.
`assets/AGENTS.md` cites "Retained nodes" for the placement guarantees.
`motion.js`'s header loses the same stale restored-state clause.

`tests/runtime/widget-api.test.mjs` let `readingRegion(id)` through:
when a following code span opened with a brace, it read the call as a
method an example defines. A method head must now sit on one line; the
test fails on the old reference and passes on the new one.

Tests: `node --test tests/runtime/widget-api.test.mjs` and `pnpm run
test:runtime` pass; pre-commit passes.

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