Repository navigation
Read the kernel registry's facts from one file in both runtimes - #4197
Conversation
Python read the kernel facts ($events, $passages, $marks, $names, $authored) from
browser/registry.json, while the browser read copies that build/registry.mjs
generated into six runtime modules. An edit to the registry reached Python at once
and the browser only after a build: raising $passages.context to 31 left the served
kernel's anchor loop starting at 24.
The kernel facts now live in browser/runtime/kernel-registry.json, part of the
runtime the serving Leaf supplies. Python reads it (state.KERNEL_REGISTRY), and the
browser imports it as a JSON module through runtime/kernel-facts.js, which derives
what the generated modules held. Because the file sits where the runtime is served
from, Node, tsc, vite, dependency-cruiser and rolldown resolve the import on disk
with no mapping, and a page's vendored /registry.json, whose copy of these facts came
from the Leaf that vendored it, is never read for them. Composition merges the
kernel registry first and each layer over it, so a page's composed vocabulary is
unchanged and the protocol stays at its number.
The kernel keeps the JSON import external, so it holds no copy to go stale; the
website's rebundle does the same and leaves it out of modulepreload.
runtime/syntax-languages.js stays generated, now by build/vendor.mjs beside the
grammars it names, since Shiki's aliases come from that build.
A module dependency may now be JSON as well as JavaScript. Capture refused any
non-JavaScript import, which blocked the runtime's JSON module in an export; a JSON
import without `with { type: "json" }` still fails in the browser, and page check
reports it as a console error. The invalid-dependency test now holds the refusal
with a .txt import.
The $names and $passages descriptions said a page's runtime keeps the copy it was
vendored with, untrue since #3448; they now say both runtimes read the serving
Leaf's copy and why a change still bumps the protocol.
Closes #4113
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The kernel imported the whole kernel registry, 68 KB of record schemas, handling text and descriptions, to read the 3 KB of values kernel-facts.js exports. A rolldown plugin now evaluates kernel-facts.js in Node at build time, from a data: URL with its JSON inlined so a long build never reads a cached copy, and emits its exports as literals; the serializer refuses a value it has no literal for. The kernel records the registry's hash among its inputs, and the install guard hashes every file the record names beside the .js modules, so a registry edit serves the source modules, which read the JSON live, until the kernel is rebuilt. A registry edit now takes a rebuild in the same change, as a runtime module does. Recording the inlined file rather than a suffix rule keeps the guard following the compiler: a base arm without kernel-facts.js gets no new input, so `leaf-dev probe --base` judges main's kernel current. The website rebundle compiles the facts in the same way, so the JSON never reaches its module graph; the modulepreload filter and the JSON branch in native() and the graph walk go. Capture still admits a JSON module import, which an export taken while the kernel is stale needs. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
left a comment
There was a problem hiding this comment.
JSON module admission also needs support in the website's dependency graph. A widget importing ../page/data.json with { type: "json" } now passes resource_reference, but publishing that layer fails: bundleRuntime follows the native dependency into page/data.json and calls nativeImports(), which parses it as JavaScript. Calling the website's bundleLayer() with that widget and {"value":1} in the JSON file reproduces SyntaxError: Unexpected token (1:8).
The kernel's special evaluator avoids this for its own registry, but leaves the newly admitted page capability incomplete. JSON dependencies need to be treated as data leaves in the website graph, including the preload path that consumes that graph, so a page using the admitted import can also be published.
…s as values The kernel record hashed the .js modules and the files kernelFacts inlined, but rolldown also compiles in any JSON a runtime module imports, which landed in `replaces` without a hash: an edit to such a file left the guard judging the kernel current, the failure #4113 removes. The record's `inputs` now hold every file the compiler read, the modules it compiled and the files it inlined among them. A probe JSON imported from runtime/words.js is listed in both now, and editing it serves the source modules; under the previous compiler the kernel stayed in use. The kernel registry joins `replaces` too, since the kernel holds its values: a runtime serving the kernel no longer carries the 68 KB file, while the source modules, which read it, still do. test_a_leaf_serves_the_kernel_only_while_it_matches_the_tree now holds both sides: an edit to vendor/initial-dependencies.json, which no kernel reads, keeps the kernel, and an edit to the kernel registry serves the source modules with the edited file. Leaving the registry out of `inputs` fails that assertion. literal() now keeps -0, computes a `__proto__` key so it stays an own key, and names the value it refuses, such as undefined or an object with no prototype. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…, and rebuild the kernel Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The framework now sits in browser/runtime/framework*.js and its types in browser/types/. Both sides' notes on dependency-cruiser's exclusions stay, the build keeps main's licence notices without the registry generator, and the kernel is rebuilt from the merged tree. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…cides field) into the kernel registry, and rebuild the kernel Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Closes #4113
Python and the browser now read the kernel registry's facts (
$events,$passages,$marks,$names,$authored) from one file,browser/runtime/kernel-registry.json. Neither needs a build between an edit and reading it. The six modulesbuild/registry.mjsgenerated, and the generator, are gone. Page startup loads the same requests as main and 45 more bytes.Which copy each side reads
Python already read the serving Leaf's own registry (
state.kernel_registry), never a page's vendored/registry.json, whose copy of these facts came from whichever Leaf vendored it. The browser must read the same copy, or a fact changed without a protocol bump splits again across Leaf updates. A page's runtime is the serving Leaf's (runtime_selection), so the copy belongs in the runtime.Serving the existing
browser/registry.jsonat a second URL would need that path mapped in every resolver: Python's runtime,tscpaths, dependency-cruiser, Node's test loaders,node worker/bundle-runtime.mjsand vitest. I tried it first, andtest:browserand the worker's tests failed to resolve the import until each got its own mapping. So the kernel facts moved into the runtime directory:browser/runtime/kernel-registry.jsonholds the five kernel sections, moved by text with their formatting.browser/registry.jsonkeeps the core layer's vocabulary ($keys,$languages, idioms, and the rest).runtime/kernel-facts.jsimports it as./kernel-registry.jsonwith{ type: "json" }and derives what the generated modules held (COLLAPSE,TEXT_BLOCK,CONTEXT,WIDGET_NAME,marks,MESSAGE_KINDS,VERB_WRITERS,drawingSchema,DRAFT_FORMAT). Every tool resolves the import on disk. The server serves it with the rest ofruntime/, where no layer can replace it.state.KERNEL_REGISTRYis the file's one Python name.incoming_registrymerges it first and each layer over it. A page's composed vocabulary is unchanged: composing with the split and with the whole file gave identical dicts.The kernel carries the values, not the file
The browser reads about 3 KB of the 68 KB file; the rest is record schemas, handling text and descriptions that only Python and agents read. So the kernel build (
build/runtime-bundle.mjs,kernelFacts) evaluateskernel-facts.jsin Node and emits its exports as literals:data:URL with its JSON inlined, so a long build never reads a copy Node cached earlier. The serializer throws on any value it has no literal for.kernel.json'sinputshash every file the compiler read: each.jsmodule, everything it compiled in, and the fileskernelFactsinlined. The install guard (read_runtime) hashes each.jsmodule and each other file the record names. After a registry edit, an install serves the source modules, wherekernel-facts.jsreads the JSON live, until the kernel is rebuilt. The same holds for any JSON a runtime module imports, which rolldown compiles in: a proberuntime/zz-test.jsonimported fromwords.jsmade the kernel stale when edited, and under the previous compiler, which hashed onlykernelFacts' reads, the kernel stayed in use.replaces, so a runtime serving the kernel no longer carries the 68 KB file. The source modules, which read it, still do.kernel-facts.jsgets no new input, soleaf-dev probe --basestill judges main's kernel current. Hashing every.jsonwould have caughtvendor/initial-dependencies.jsonand sent main's arm to its source modules.runtime/syntax-languages.jsstays generated, now bybuild/vendor.mjsbeside the grammars it names. Its aliases come from Shiki, and its literal imports point at bundles only that build writes.Rebuild before landing: a change to
runtime/kernel-registry.jsonnow takespnpm run build:browserin the same change, as a runtime.jsmodule does (build/AGENTS.md). Leaving it out costs no correctness: installs serve the source modules until the kernel matches again.check:browserreports the stale kernel.A restriction this lifts
Capture refused any non-JavaScript module import (
resource_urls,module-type). It now admits.json, which an export taken while the kernel is stale needs for the source modules' JSON import. The browser still refuses a JSON import withoutwith { type: "json" }, and page check reports that as a console error. Pages gain JSON modules too.test_invalid_dependencies_leave_the_previous_revision_activenow holdsmodule-typewith a.txtimport.Repro, before and after
I raised
$passages.contextfrom 24 to 31 and ran no build:for (let width = 24;)leaf server runCONTEXTis 31, read fromkernel-registry.jsonleaf-dev probe's prepared install)for (let width = 31;;kernel-registry.jsonnever requestedStartup
uv run leaf-dev probe <page> --base, Chromium, compiled kernel. Main's arm is built with this PR's compiler, which reproduces main'sdist/kernel. Measured atpresented, when the page first shows the server's state:Times are left out: the host's load average was 33–52 during these runs, and single runs swung by a second. The previous revision of this PR added one request and about 65 KB.
Protocol
No bump of its own. Main has since bumped to 27, and the merge carries that into
kernel-registry.json; outside the descriptions this PR rewrote, the split file andbrowser/registry.jsontogether equal main's registry. A vendored page's composed registry has the same content, the event records and what a page sends are unchanged, the public package API is unchanged (check-api.jsstill re-exportsTEXT_BLOCK), andDRAFT_FORMATkeeps its value. The deleted modules were private runtime modules, which a page never vendors.protocol-baseline.jsonis unchanged.The
$namesand$passagesdescriptions said a page's runtime keeps the copy it was vendored with, which hasn't been true since #3448. They now say both runtimes read the serving Leaf's copy, and give the reason a change still bumps the protocol:$names.widgetsorts a vendored registry's keys, and anchors and passages in the log were read bycollapseandblocks. A change tocontextalone sets only how much a new anchor captures.Tests
pnpm run check: build check, framework/build tests,test:runtime(563), the worker's tsc and vitest (85).tests/model/interact_contract/(its regtest snapshot names the new file),test_interact_layer.py,test_interact_product.py,test_claims.py,test_revision_delivery.py,test_render_export.py,test_distribution.py(model and dev;test_a_leaf_serves_the_kernel_only_while_it_matches_the_treenow holds that an edit tovendor/initial-dependencies.jsonkeeps the kernel and an edit to the kernel registry serves the source modules, and fails at that assertion when the registry is left out ofinputs),test_live_shell_artifact.py,test_product_page.py,process/test_interact_server.py,process/website_server/test_routes.py,dev/tests/model/test_product_page.py, and the seed test indev/tests/model/test_interact_preview.py.-k: interactive-export tests intests/browser/test_render_export.py, and the browser/Python capture-agreement tests intest_render_anchors.py.leaf-dev probe --firefoxon release-notes: boots with no console errors (on the first revision).Not run locally: the broad suite, the journeys tier (
tests/journeys/test_interact_layer.pywas edited), and the website's delivery checks (leaf-dev verify-site website-worker), all of which CI runs. The eval casefirst-command-says-what-comesnames the new path, and the eval format has no per-arm value, so a--baserun of this branch points its base arm at a file main lacks. Once this lands, every later merge base has the file.