Repository navigation
Canonicalize page preparation and validation - #606
Conversation
…e-showcase # Conflicts: # skills/leaf/scripts/leaf/conversation.py # tests/test_interact_document.py
leaf-agent
left a comment
There was a problem hiding this comment.
Two findings; the rest of the delivery-head rework reads coherent, and the freeze/override plumbing traces cleanly through PageSnapshot.
The exported copy no longer declares its encoding where a parser will read it. The delivery head now goes in at head_open_end, ahead of the authored <meta charset="utf-8">. Once inline_assets folds the theme into a copy, that declaration lands ~347k characters in — measured by running export_page over a leaf_page fixture — far past the 1024 bytes HTML gives an encoding declaration. HTTP delivery is unaffected, because Content-Type carries the charset, and Chrome's own UTF-8 detector still rescues the file:// case (checked: document.characterSet stays UTF-8). But a copy is made to be handed around and re-hosted, and a static host that sends text/html with no charset parameter leaves it with no declaration a conforming parser can see. Emitting the charset first in the composed head covers every delivery path at once; with the inline suggestion applied the copy's declaration sits at offset 68. One test pins the current order incidentally and needs the charset meta allowed for: test_the_live_root_places_its_delivery_at_the_parsers_head_boundary asserts "<head>" + marker.
A late-settling page now loses the rest of the gate's readings. replayed meant "the page applied its current state", which is why a pageSettled timeout left it true while the three earlier stages cleared it — the comments at each use say so ("a page that never applied that projection … supplies no comparison"). Folding the settle stage into failed_stage is None makes a page that reached presented but kept moving skip _verbatim_findings, silentWords, undeclaredAttrs, the retirement-outcome comparison, and replayOverrides for that scheme. The gate still goes red on the motion, but everything else it found is withheld until that is fixed.
leaf-agent
left a comment
There was a problem hiding this comment.
Both earlier findings are closed: the encoding declaration now leads the composed head on every delivery path, and a pageSettled timeout keeps the rest of the gate's readings. One consequence of the first is left open.
Every delivered document now declares its encoding twice. _delivery_prelude emits <meta charset="utf-8" data-lf-runtime> at head_open_end while the authored head still carries its own — running runtime_document over examples/heat-loss.html returns a head that opens <head><meta charset="utf-8" data-lf-runtime><meta name="lf-revision" …> and still holds the authored <meta charset="utf-8" /> further down. HTML allows one <meta charset> per document, so every page the server delivers and every copy version export writes is non-conforming. Browsers ignore the second one, but a conformance check over a published page — leaf.page's own documents included — reports an error whose cause is delivery's markup rather than anything the page's author wrote.
The encoding became delivery's property in this commit on exactly the argument the PR already applies to the CSP, the theme link, and the runtime module: all three left the authored pages, and validation/source.py now refuses them as delivery's. The scaffold in references/page-authoring.md still has authors write <meta charset="utf-8">, and the sentence introducing it — "Leaf adds the CSP, identity, theme, runtime, and canonical address when it delivers the document" — doesn't name the encoding it now adds too. Dropping that line from the scaffold, the shipped pages and the page fixtures, and naming the encoding in that sentence, would put the declaration under one owner. Say the word and I'll push it here.
…e-showcase # Conflicts: # scripts/site.py # skills/leaf/scripts/leaf/event_endpoint.py
leaf-agent
left a comment
There was a problem hiding this comment.
One finding. The encoding hand-off itself reads clean — the refusal in validation/source.py, the declaration at head_open_end, and the BOM on the serverless paths line up, and the sweep covers every shipped page, fixture, and the corpus generator.
The demo recorder still authors the declaration version stamp now refuses. demo_page's scaffold in scripts/record-demo.py lost its CSP, theme link, and runtime script in this PR, but the <meta charset="utf-8"> line directly above its viewport meta stayed. record-demo.sh therefore dies at its first leaf version stamp with refusing to stamp index.html: <meta charset> (line 4) belongs to delivery; Leaf declares UTF-8 before authored head content, and docs/demo.gif can no longer be regenerated. Reproduced on the merged tree: uv run pytest tests/test_product_page.py -q -n0 fails test_demo_recording_drives_the_browser_journey with exactly that message. Because that case carries @pytest.mark.nightly, ci's test job runs broad discovery and stays green — the failure surfaces on the scheduled complete run after this lands.
Deleting that one line is the whole fix. Say the word and I'll push it here.
Test selection run against the merged tree
uv run pytest tests/test_interact_document.py tests/test_product_page.py -q -n0— 162 passed, 1 failed (the case above)uv run pytest tests/test_interact_server.py tests/test_interact_mcp.py -q -n0 -k "charset or encoding or head or parser"— passeduv run pytest tests/test_render_export.py -q -n0 -k "charset or encoding or export_page or copy"— passed
Two pairs of copies from the concept survey, each cut over to one owner. Eval arms and children. `scripts/eval_harness.py` now builds every arm (the plugin payload at one git ref: manifest, hooks, launcher, skills, uv project) and every `claude -p` child (a scratch cwd outside any repository, project-only settings, no MCP servers, auto-memory off, and the running agent session's identity variables removed). `scripts/eval_claude_delivery.py` and `notes/arrangement-eval/harness.py` import it, and `evals/README.md`'s A/B recipe builds its other arm with `uv run scripts/eval_harness.py REF DEST`. Behaviour that moved: - The delivery eval's children ran from `.tmp/` inside the checkout. Claude Code loads every `CLAUDE.md` above the cwd, so both arms read this checkout's `CLAUDE.md`, and, because the checkout sits under `$HOME`, the user's `~/.claude/CLAUDE.md` as a project file. With auto-memory on, they also read the repository's memory. A probe child confirmed all three before the change; after it, one Haiku round of the delivery eval reports no memory paths, a cwd under the system temp directory, and the arm's payload as its only plugin. - The delivery eval compares BASE_REF with HEAD, both built as payload archives, instead of a `git worktree` of BASE_REF against the live checkout, so uncommitted edits are no longer measured. `arms.json` records both commits. - The arrangement harness's children and `leaf` calls no longer inherit the running agent session's variables (`CLAUDE_JOB_DIR`, `CLAUDE_EFFORT`, the session id), and the harness runs in the project environment instead of its own PEP 723 header, which it needs to import `leaf.host`. Page-fixture preparation. `test_page_fixtures_pass_check` and `test_every_seeded_fragment_passes_the_door_it_never_came_through` build their pages with `scripts/page_fixtures.prepare_page`, which gains an `each_version` hook the first test uses to run `version check` on every stamped version. The second test's own builder had diverged from `prepare_page` since #606 on three inputs: it always used `examples/layer.json` with no `--no-packages` fallback, always copied `examples/media`, and skipped a sibling `.page` directory. Nothing in the test or its history motivated those differences, and they agreed only because the one seeded page carrying message markup (`ship-review`) lives in `examples/` with the shared layer and media. Behaviour that moved in the tests: each version is now stamped, as preview and the site stamp it, rather than activated; the seed log goes in after the first stamp instead of before every version; and the door test walks every version instead of stamping only the current one. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
…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]>
Summary
SourceDocumentreading carried through validation, projection, and deliveryPageSnapshotand derive export readiness from that served stateValidation
uv run pre-commit run --all-filesuv run pytest tests(1,033 passed after integrating currentmain)