Repository navigation
Write the element-id, data-source and contract grammars into composed declarations - #5294
Merged
Merged
Conversation
… declarations
Composition now writes the grammar of each name Leaf looks up into the
attribute that holds it (`registry.contract.stamp_grammars`), beside the
`enum` that `stamp_words` already writes. Each grammar keeps one home in
`leaf/schema.py`: `ELEMENT_ID` for an element's `id` and for every
`x-refers` attribute that names an element by id, `DATA_SOURCE_NAME` for
an `x-data` input's source attribute, and `DATA_CONTRACT_NAME` for a
verb's `contract` attribute. A verb that creates a child names it by its
fold unit, and `contract.detail_schema` now holds that field to the
element-id grammar, in the same reading that already makes it non-empty.
Package authors now declare each of these attributes as
`{"type": "string"}`, and composition replaces any pattern a declaration
gives. The 87 copies in the bundled, example, fixture and eval
registries are gone, as are the copies in the starter declaration that
`package init --widget` writes, in the tests' inline declarations and in
the docs. A keyed reference, such as a playground setting's `for`, names
a member by the member's key attribute and keeps the grammar it
declares. `packages.md`, "A widget", tells package authors the rule.
The validators that compared each copy with the literal now check only
that the attribute is declared a string: `creates-id`, `creates-detail`
(whose id field is exactly `{"type": "string"}`), `data-source` and
`verb-contract`. Their messages say so.
The composed vocabulary of every bundled package is unchanged apart from
the `lf-options` `add` detail, which no longer spells the pattern.
`$states`, which carries that detail as admission reads it, is
unchanged. In the examples and test fixtures, six widgets declared `id`
and two declared a reference attribute as a plain string; these now take
the element-id grammar, and every value their pages use matches it.
The page protocol doesn't move. `build/browser/protocol.mjs` compares
the kernel's event records and their ownership, the `state.Record`
schemas and the composer's draft, and the build's protocol schemas still
equal the baseline. A page's log is unchanged too: an `add` still
records the same detail schema in `meaning.state`. The kernel registry
is untouched, so `dist/kernel/` needs no rebuild.
The grammars stay in Python rather than in the kernel registry's
`$names`, which holds the grammars both runtimes read: the browser
checks none of these names. The playground's `NAME` in
`lf-playground.js` is the grammar of its configuration keys, which its
registry declares on `lf-playground-control`'s `name`, so this change
leaves it alone.
Tests: `test_composition_writes_the_grammar_of_each_name_leaf_looks_up`
and `test_the_id_of_a_created_child_reads_as_an_element_id` are new, and
each fails without the stamp or the reading it covers. The `creates-id`
and `data-source` refusal cases now declare a non-string id and source
rather than a different pattern. Four tests that compared a composed
entry with the authored one whole now compare the part they are about,
or the authored entry as composition completes it.
…their targets
A page's candidate vocabulary skipped validation when it equalled the
active revision's vocabulary, but the revision's is stamped and the
candidate's merge isn't. Since the previous commit gives every composed
`id` a pattern while a page declaration spells `{"type": "string"}`, a
page declaring its own widget was validated again on every candidate
read; one whose widget declared `x-state` or `x-tone` already was.
`compose_page_registry` now takes the layer and page declarations a
validated composition was made from, and skips validation for a
composition of the same two. `RevisionReading.inputs` gives the active
revision's after composing its vocabulary under this Leaf, so after a Leaf
update the page's declarations are still validated over the new layer
once per process, as before. A composition that declares anything over
the layer is now stamped whether or not it was validated. In a scratch
measurement, a candidate read of a page declaring one widget went from
validated 5 times of 5 at 17.5 ms to none at 3.7 ms; the stamp it now
always runs costs about 1 ms on the default layer.
An `x-refers` attribute no longer takes the element-id grammar. `page
check` resolves its value to the element it names, keyed or not, so the
grammar only refused a reference to an authored element whose id no
widget could carry, such as `<section id="Plan_Notes">`, which
`$keys.x-refers` says an empty contract accepts. The playground's keyed
`for` declarations drop their copies of the pattern for the same reason.
References in the bundled packages, which carried the pattern on main,
now accept such a target too.
The playground's `NAME` stays. Its registry spells the configuration-key
grammar three times, on a control's `name` and on the `values` keys of
`tune` and `choose`, so reading one of those copies from JavaScript would
not give the grammar one home.
Tests: `test_a_fresh_server_does_not_revalidate_the_active_revisions_inputs`
now also covers a page declaring its own widget, and
`test_a_reference_names_any_element_the_page_holds` is new; each fails
against the behavior it replaces. `test_composition_writes_the_grammar_of_each_name_leaf_looks_up`
now expects a reference to keep what it declares, and a stale docstring
in `test_data_contracts.py` no longer says a package may narrow a source's
pattern.
…posed over `revision_inputs` composed the revision's vocabulary and then resolved the selected layer again for the pair it returned. A `package install` landing between the two paired the new layer with declarations validated only over the old one, and the cached `RevisionReading.inputs` then let every candidate read in the process skip validation. The revision's memo now holds its vocabulary together with the layer vocabulary and declarations that composition read, and `revision_vocabulary` and `revision_inputs` both return from that one entry. Tests: the skip's focused tests (`tests/model/interact_contract/`, `test_revision_delivery.py`, `test_interact_document.py`) pass unchanged.
# Conflicts: # tests/browser/test_render_anchors.py # tests/render_cases_interaction.py
leaf-agent
approved these changes
Nov 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of the 2026-11-03 sweep for duplicate implementations (#5291 changes how review and Tend look for them). The element-id grammar was written out 87 times across the bundled, example, fixture and eval registries, the starter declaration
package init --widgetwrites, test declarations and the docs. Composition now writes it, and the copies are gone.registry.contract.stamp_grammarswrites the grammar of each name Leaf looks up into the attribute that holds it, beside theenumthatstamp_wordsalready writes. Each grammar keeps one home inleaf/schema.py:ELEMENT_IDfor an element'sid,DATA_SOURCE_NAMEfor anx-datainput's source attribute, andDATA_CONTRACT_NAMEfor a verb'scontractattribute. A verb that creates a child names it by its fold unit, andcontract.detail_schemaholds that field to the element-id grammar. Package authors declare each of these attributes as{"type": "string"}, and composition replaces any pattern a declaration gives;packages.md, "A widget", says so. The validators that compared each copy with the literal (creates-id,creates-detail,data-source,verb-contract) now check only that the attribute is declared a string.x-refersattribute no longer takes the element-id grammar.page checkresolves its value to the element it names, so the grammar only refused a reference to an authored element whose id no widget could carry, such as<section id="Plan_Notes">, which$keys.x-referssays an empty contract accepts. A keyed reference, such as a playground setting'sfor, names a member by the member's key attribute and keeps the grammar it declares.compose_page_registrynow skips validation for a composition of the same layer and page declarations a validated one was made from, whichRevisionReading.inputsgives. The revision's memo holds its vocabulary together with the layer and declarations composition read, so apackage installlanding mid-read can't pair a new layer with declarations validated over the old one. In a scratch measurement, a candidate read of a page declaring one widget went from validated 5 times of 5 at 17.5 ms to none at 3.7 ms.The page protocol doesn't move:
build/browser/protocol.mjs's baseline still matches, anaddstill records the same detail schema inmeaning.state, and the kernel registry anddist/kernel/are untouched. The composed vocabulary of every bundled package is unchanged apart from thelf-optionsadddetail, which no longer spells the pattern. In examples and fixtures, six widgets declaredidand two a reference attribute as a plain string; these now take the grammar, and every value their pages use matches it. The grammars stay in Python rather than the kernel registry's$names, since the browser checks none of these names; the playground'sNAME, the grammar of its configuration keys, stays where it is.Tests:
test_composition_writes_the_grammar_of_each_name_leaf_looks_up,test_the_id_of_a_created_child_reads_as_an_element_idandtest_a_reference_names_any_element_the_page_holdsare new, andtest_a_fresh_server_does_not_revalidate_the_active_revisions_inputsnow covers a page declaring its own widget; each fails against the behavior it replaces.