Repository navigation
Address delivered documents and resources in one parsed walk - #1280
Merged
Merged
Conversation
Every host now addresses what a document or resource names through one parsed walk, `rebase_document(source, address)` in `revision_delivery.py`, with an `address` function of its own: `DeliveryAddress(page_root, asset_root)` for the live server, the MCP page server, the website container and the published live shell, an embedding function for export and the MCP snapshot, and the page root for frozen message markup and the site's link check. The walk reads the same references capture reads (`attribute_references` in `structure.py` now serves both), including declarative shadow roots. Layer JavaScript is served as captured: the document's import map sends its rooted `/runtime/`, `/vendor/` and `/widgets/` imports to the revision, and the runtime finds its own files beside the registry the delivery declares. The regex scopers in `http.py`, their `addressed` guard, `deliver_document`, export's second walk (`_bind_authored_modules`, the old `inline_assets` body) and `media.js`'s split constants are gone. Behaviour that moved: - Media answers at the page root wherever a page names it. A document's `<img>`, `<a href>`, style and widget attributes used to point at the revision's captured copy while messages, drafts and widgets resolved the page root; now every context uses the page root, which every host serves. - An authored module's string literals stay as written. The scoper used to rewrite a quoted Leaf route in them under a prefixed host; delivery now addresses only an authored module's imports. - Layer modules keep their rooted imports and are no longer rewritten per request; stylesheets addressed for a revision are parsed once per server. On the corpus served locally (15 alternating cold loads each), requests and JavaScript requests by presentation are unchanged (250 / 229), bytes fall by 3.4 KB, and HTML first byte drops from 85 to 38 ms median. The head is still composed in three places; `TODO.md` keeps that half.
leaf-agent
previously approved these changes
Sep 27, 2026
# Conflicts: # scripts/site.py
leaf-agent
approved these changes
Sep 27, 2026
max-sixty
added a commit
that referenced
this pull request
Sep 27, 2026
Every delivered document is now composed once, by `compose_document` in `revision_delivery.py`, and each host states what it adds as a `Delivery` value: the address its references go to (#1280), whether stylesheets are embedded, a policy for the document's nonce, an import map, the runtime's inline script, head metadata, the canonical page root, and marks on `<html>` and `<body>` and before `</body>`. The hosts cut over: - The HTTP server and the published live shell build theirs with `http.page_delivery`. The website adds its link card, the MCP page server its readiness module, and a specimen its `data-lf-contained`, `data-lf-user-scope` and `inert` marks, each by overriding `PageEndpoint._delivery`. - Export passes its offline policy, `leaf:` import map and embedded payload. - The MCP snapshot and the direct MCP probe use `exporting.embedding`, which embeds styles and media and leaves modules as named. This deletes `runtime_document`, `supervised_document`, `head_open_end_offset`, `authorize_inline_scripts`, `inline_assets`, the `_document_head` hook, and the two regex splices in `_content` overrides: the MCP ready signal's `rfind("</body>")` and the specimen's `<html`/`<body` substitutions. `SourceDocument` now reads where the source's `html`, `head` and `body` start tags and its last `</body>` stand, and a source that leaves `<html>` implicit gets the tag written before its head. Behaviour that moved: - A served document now starts with a UTF-8 byte-order mark, as the export and the MCP snapshot did. - A specimen's marks and a host's attributes follow the source's own attributes on its start tag instead of being spliced in right after the tag name. - An exported file writes the theme before the adopted sheets rather than after, and marks its import map `data-lf-runtime` like the served one. Startup, the corpus served locally, base (this branch with #1280 merged) against candidate, 11 alternating cold loads each in Chromium: requests and JavaScript requests by presentation are unchanged (250 / 229), and presented median is 3,855 / 3,776 ms. The served document grows by the 3-byte mark. This deletes the `TODO.md` bullet "Compose a delivered page's head once". > _This was written by Claude Code on behalf of max-sixty_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
max-sixty
added a commit
that referenced
this pull request
Sep 27, 2026
…mports below the page root (#1312) `test_a_detached_board_releases_and_restores_its_lifecycle` has failed on main's nightly since #1280 (runs 36305818409 and 36312044583). It found the layer's address by reading `data-lf-probe` off the first `script[data-lf-runtime]` in the document. Since #1280 that element is the import map, which carries no `data-lf-probe`. The probe came back undefined, so `new URL('vendor/sortable.esm.js', …)` resolved beside `/versions/v1.html` and 404'd. The page itself was not affected. No runtime module or host reads the first runtime script; each selects the element that declares what it needs (`[data-lf-probe]`, `[data-lf-server]`, `currentScript`). The layer at `/versions/` addresses is already exercised by the everyday `test_render_mcp` and `test_live_shell_artifact`. - The test now imports `/vendor/sortable.esm.js`, the board's own specifier. The document's import map sends it to the revision, so the test holds the instance the board constructs from. - `test_a_browser_executes_the_published_capture_with_live_api_routes`, which the everyday gate runs, now asserts that a rooted layer import from a document one directory below the page root (`/versions/v1.html`) is the revision's `runtime/widget-api.js` instance, bundled and unbundled. With the import map removed from `page_delivery`, both cases fail. Of the nightly run's other failures, only this one comes from #1280. `test_a_shipped_log_replays_its_example_state` still fails on the same `.lf-margin-spill` click timeout it failed on before #1280. > _This was written by Claude Code on behalf of max-sixty_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
added a commit
that referenced
this pull request
Nov 15, 2026
…amps from files.py (#6039) This is the weekly duplicate sweep of `src/leaf/` and `hooks/` (ISO week 46). It moves four capabilities that were implemented more than once to one home each, and moves every caller. Behavior does not change. Every replaced copy computed the same result as the home it now calls. - **Applying non-overlapping `(start, end, text)` edits to a source.** The new home is `structure.splice`, which is `revision_delivery._spliced` moved and generalised to str or bytes. It replaces five copies: - `revision_delivery._spliced`, from #3313, removed. - The reverse-slice loop in `revision_artifact.bind_imports`, from #1280. - The loop in `structure.rewrite_attribute_references`, from #1658. - The loop in `leaf_dev.docs.compose`, from #2660. - The loop in `leaf_dev.arrangement_eval`, from #4629. The four reverse-slice loops copied the whole source once per edit. Each of them applies edits that don't overlap and don't start at the same offset, so splicing them in one pass gives the same output. - **The file name of a stamped version.** `live_shell` wrote `f"v{version}.html"` inline, from #666. It now calls `files.version_name`. - **Whether a note stamps a revision.** `validation/source_history.py` scanned for the note inline, from fe4e8ea. It now calls `files.stamped_version`, which was added in the same commit. - **The `sha256:` digest of a revision's HTML.** `revision_artifact._capture_artifact` hashed `document.data` again, from #666. It now reads `SourceDocument.digest`, from #606, which holds the same value. I left `compose_document`'s two-insertion loop in `revision_delivery.py` alone. `splice` orders edits at the same offset by their text, but that loop relies on list order when `<html>` and `<head>` are both implicit. **Verification.** `ruff` and `ty` pass on the touched files. These model tests pass: `test_module_url_delivery`, `test_revision_delivery`, `test_live_shell_artifact`, `test_product_page`, `test_interact_document`, `test_interact_anchors` and `test_interact_layer`, 626 tests in all. In `dev/tests/model/test_product_page.py`, the second case of `test_a_composed_part_refuses_an_authored_copy` fails at `assert slot in authored`, before `compose` runs. Its fixture string expects `<img` followed by `alt="Sandbox` at 16 spaces of indentation, and `docs/index.html` on `main` now indents that line by 18. The failure is in the test's fixture, not in this change. <details><summary>Sets found but not consolidated here</summary> Another open pull request already changes each of these: - **Claude Code and Codex config homes, and the inline-delivery opening, repeated in `leaf_dev`.** #6014 moves them onto `harness.claude_code_config`, `harness.codex_home` and `hook_transport.INLINE_OPENING`. - **`hooks._awaits_agent` repeats `holding.running_turns`.** #6032 rewrites `running_turns`. - **The "N user updates with no answer" sentence**, written in both `activity.unanswered` and the `page-open-owes` finding. `activity.py`, `findings.py` and `session.py` are all being changed in #5979, #6018 and #6032. - **Raster magic bytes**, read in both `media._UPLOAD_TYPES` and `revision_delivery.media_size`. `media.py` is being changed in #6014. These are not worth a shared helper, because they are one-line stdlib idioms or the copies differ in meaning: - `json.dumps(..., sort_keys=True)` used as a cache key. - Compact `json.dumps` with `separators=(",", ":")`. - The `script_kind(...) in {"module", "classic"}` membership test. - `lock_is_held(page_dir / SERVER_LOCK)`. - Inline closed-object JSON schemas. **Not consolidated, needs a separate look.** `sample_content._non_json_number` repeats `http.reject_json_constant`. The real question is where Leaf refuses non-finite numbers. The HTTP path refuses NaN and numbers past a double's range. Sample fixtures refuse only NaN and infinity. No other reader of event JSON in `src/leaf/` passes `parse_constant`. Sharing the helper would change the `sample-json` message without settling that question, so it is left out of this PR. </details> Co-authored-by: leaf-agent <[email protected]>
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.
Every host now addresses what a document or resource names through one parsed walk,
rebase_document(source, address)inrevision_delivery.py, with anaddressof its own:DeliveryAddress(page_root, asset_root)for the live server, the MCP page server, the website container, and the published live shell;The walk reads the references capture reads (
attribute_referencesinstructure.pynow serves both), including declarative shadow roots. Layer JavaScript is served as captured: the document's import map sends its rooted/runtime/,/vendor/and/widgets/imports to the revision, and the runtime finds its own files (icon.svg,shadow.css, the registry, widget modules) beside the registry the delivery declares. This deletes the regex scopers inhttp.pyand theiraddressedguard,deliver_document, export's second walk (_bind_authored_modulesand the oldinline_assetsbody), and the split constantsmedia.jsused to get past the scoper.Behaviour that moved:
<img>,<a href>, style, and widget attributes (anlf-shot'sbefore/after) pointed at the revision's captured copy, while messages, drafts, and widgets resolved the page root, and the regex pass sent a style's media to the page root but an attribute's to the revision.page-storage.mddefines media as the page's, shared across revisions; every host serves it at the page root, and the site verifier already requires media there. A revision still captures the media its document names, which export embeds.test_render_mcpasserted the old rewrite and now asserts the literal.rebase_cssis cached on the valueDeliveryAddress).Startup, corpus served locally, base (
ddf725b76) against candidate, 15 alternating cold loads each in Chromium: requests by presentation 250 / 250, JavaScript requests 229 / 229, bytes 10,175,035 / 10,171,628, HTML first byte 85 / 38 ms median, presented 4,532 / 4,371 ms median.The head is still composed in three places; this narrows the
TODO.mdbullet to that half, which a follow-up PR takes.🤖 Generated with Claude Code