Skip to content

Write the element-id, data-source and contract grammars into composed declarations - #5294

Merged
max-sixty merged 4 commits into
mainfrom
agent-a3416c64dcdd98dd1
Nov 4, 2026
Merged

max-sixty merged 4 commits into
mainfrom
agent-a3416c64dcdd98dd1

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

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 --widget writes, test declarations and the docs. Composition now writes it, and the copies are gone.

  • Grammars written at composition. registry.contract.stamp_grammars writes the grammar of each name Leaf looks up into the attribute that holds it, beside the enum that stamp_words already writes. Each grammar keeps one home in leaf/schema.py: ELEMENT_ID for an element's 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 holds 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.
  • References name any element. An x-refers attribute no longer takes the element-id grammar. page check resolves 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-refers says an empty contract accepts. 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.
  • Validation skipped by its inputs. A candidate vocabulary used to skip validation when it equalled the active revision's, which stamping would have defeated for every page declaring its own widget. compose_page_registry now skips validation for a composition of the same layer and page declarations a validated one was made from, which RevisionReading.inputs gives. The revision's memo holds its vocabulary together with the layer and declarations composition read, so a package install landing 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, an add still records the same detail schema in meaning.state, and the kernel registry and dist/kernel/ are untouched. The composed vocabulary of every bundled package is unchanged apart from the lf-options add detail, which no longer spells the pattern. In examples and fixtures, six widgets declared id and 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's NAME, 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_id and test_a_reference_names_any_element_the_page_holds are new, and test_a_fresh_server_does_not_revalidate_the_active_revisions_inputs now covers a page declaring its own widget; each fails against the behavior it replaces.

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

… 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
@max-sixty
max-sixty merged commit 2046fd0 into main Nov 4, 2026
4 checks passed
@max-sixty
max-sixty deleted the agent-a3416c64dcdd98dd1 branch November 4, 2026 07:00
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