Skip to content

Compose the docs' copied parts from their owners at build, and parse HTML through SourceDocument - #2660

Merged
max-sixty merged 2 commits into
mainfrom
compose-docs-from-owners
Oct 12, 2026
Merged

max-sixty merged 2 commits into
mainfrom
compose-docs-from-owners

Conversation

@max-sixty

@max-sixty max-sixty commented Oct 12, 2026 •

Copy link
Copy Markdown
Owner

The product documents under docs/ carried copies of facts other sources own, each
kept current by a rewrite command or a sync test: the site route bar pasted into eight
pages, the catalog captions (copied from each example's description), seventeen catalog
preview addresses (content hashes, regex-rewritten into the docs on every preview
refresh), the event-log page's verb table (copied from the registries' x-state), and
the registry page's x- key index (copied from $keys).

Each is now an empty slot in the authored page, and leaf_dev.docs.compose fills it
from its owner whenever a builder reads a product document
(page_fixtures.authored_markup): the site build, leaf-dev preview, and the render
harness all go through it, so a local preview shows the derived parts too and refreshes
when one of their owners, such as an example's description, is edited. A catalog
image names its preview by the example it links to; the address comes from whichever
asset tree the build reads, the pin or refresh-previews' draft. A slot that holds
content is refused. Edits splice into the source at the parser's own spans, so every
authored byte outside a slot publishes unchanged.

Removed with the copies: leaf-dev catalog, leaf-dev keydocs, leaf_assets'
regex rewrite of the docs' preview addresses (publication now moves only the pin and the
README, which GitHub renders without a build), the site build's source_markup draft
override, and the four sync tests (navigation, catalog captions, verb table, key index).
The package cards in extending.html stay authored: their names, blurbs and links have
no other owner, and only their set comes from examples/layer.json, which a test still
checks.

HTML that is read rather than composed goes through SourceDocument:
leaf-dev corpus finds each page's <main>, eyebrow and contents map in the parse tree
(the generated corpus is byte-identical), and the product-page tests read code blocks,
notes, the sample template, links, package cards and shown commands from the tree. The
shown-commands sweep now reads the composed pages and finds 27 more leaf commands in
how-it-works.html (inline <code> with attributes or nested markup, which the regex
skipped); all resolve. SourceDocument.offsets gives a parser span's source offsets.

User-visible behavior: none. The published product pages are the same documents. For
examples.html, the built markup before and after differs only in whitespace inside
the caption tags, and in the commented-out Command hub card, which is now in the slot
form; normalizing tag whitespace, the diff is:

@@ -220,3 +220,3 @@
 <span class="example-preview">
-<img src="/media/dd29c008a2efe27c.jpg" alt="" loading="lazy">
+<img alt="" loading="lazy">
 </span>
@@ -225,3 +225,4 @@
 <span class="example-title" role="heading" aria-level="3">Command hub</span>
-<span class="example-description">See which task, agent, worktree, and operation is holding a dense importer rewrite—and act beside the stopped goal.</span>
+<span class="example-description">
+</span>

Every other product page's built markup is identical under the same normalization,
apart from registry.html losing its two $keys marker comments.

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

…HTML through SourceDocument

The product documents under `docs/` carried copies of facts other sources own, each
kept current by a rewrite command or a sync test: the site route bar pasted into eight
pages, the catalog captions (copied from each example's description), seventeen catalog
preview addresses (content hashes, regex-rewritten into the docs on every preview
refresh), the event-log page's verb table (copied from the registries' `x-state`), and
the registry page's `x-` key index (copied from `$keys`).

Each is now an empty slot in the authored page, and `leaf_dev.docs.compose` fills it
from its owner whenever a builder reads a product document
(`page_fixtures.authored_markup`): the site build, `leaf-dev preview`, and the render
harness all go through it, so a local preview shows the derived parts too. A catalog
image names its preview by the example it links to; the address comes from whichever
asset tree the build reads, the pin or `refresh-previews`' draft. A slot that holds
content is refused. Edits splice into the source at the parser's own spans, so every
authored byte outside a slot publishes unchanged.

Removed with the copies: `leaf-dev catalog`, `leaf-dev keydocs`, `leaf_assets`'
regex rewrite of the docs' preview addresses (publication now moves only the pin and the
README, which GitHub renders without a build), the site build's `source_markup` draft
override, and the four sync tests (navigation, catalog captions, verb table, key index).
The package cards in `extending.html` stay authored: their names, blurbs and links have
no other owner, and only their set comes from `examples/layer.json`, which a test still
checks.

HTML that is read rather than composed goes through `SourceDocument`:
`leaf-dev corpus` finds each page's `<main>`, eyebrow and contents map in the parse tree
(the generated corpus is byte-identical), and the product-page tests read code blocks,
notes, the sample template, links, package cards and shown commands from the tree. The
shown-commands sweep now reads the composed pages and finds 27 more `leaf` commands in
`how-it-works.html` (inline `<code>` with attributes or nested markup, which the regex
skipped); all resolve. `SourceDocument.offsets` gives a parser span's source offsets.

User-visible behavior: none. The published product pages are the same documents. For
`examples.html`, the built markup before and after differs only in whitespace inside
the caption tags, and in the commented-out Command hub card, which is now in the slot
form; normalizing tag whitespace, the diff is:

```
@@ -220,3 +220,3 @@
 <span class="example-preview">
-<img src="/media/dd29c008a2efe27c.jpg" alt="" loading="lazy">
+<img alt="" loading="lazy">
 </span>
@@ -225,3 +225,4 @@
 <span class="example-title" role="heading" aria-level="3">Command hub</span>
-<span class="example-description">See which task, agent, worktree, and operation is holding a dense importer rewrite—and act beside the stopped goal.</span>
+<span class="example-description">
+</span>
```

Every other product page's built markup is identical under the same normalization,
apart from `registry.html` losing its two `$keys` marker comments.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Editing an example's <meta name="description"> leaves an open leaf-dev preview docs/examples.html showing the old caption. incoming_files composes captions from those files, but watch_paths does not subscribe to the linked example sources; its relevant() reading for examples/review-a-plan.html is false. Include the catalog's linked example files among the preview inputs so the live preview refreshes when a caption's owner changes.

Comment thread dev/leaf_dev/docs.py Resolved
…a preview

A link's preview image with an authored src now refuses like every other composed slot,
and a docs preview watches the example sources and registries its composed parts read,
so an example's description edit refreshes an open catalog preview. User-visible
behavior: none on the site.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit bd4d0a7 into main Oct 12, 2026
3 checks passed
@max-sixty
max-sixty deleted the compose-docs-from-owners branch October 12, 2026 21:15
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]>
leaf-agent added a commit that referenced this pull request Nov 22, 2026
This week's duplicate sweep of `dev/`, `build/`, `tests/` and `worker/`
(week 47) moves six duplicated helpers onto one home each and moves
every caller. Behavior stays the same. The touched model tests, the dev
js_facts tests and the Worker's routing, storage and index tests pass. A
script compared the old and new outputs of the consolidated `leaf_dev`
functions and the seeded-log reads across the corpus, and they match.

| Question | Home | Copies removed (introducing PR) |
|---|---|---|
| Which stylesheets do the core and the bundled packages ship, leaving
out vendored files? | new `interact_support.shipped_sheets` | `sheets()`
in `test_interface_fonts.py` (#4804) and `test_theme_tokens.py` (#6025).
Five inline loops in `test_interact_layer.py` (#3138, #3886) |
| Run `tests/js_facts.mjs` | `interact_support.js_facts` (#2666) | its
own subprocess call in `dev/tests/test_js_facts.py` (#5118) |
| Lowercase hex of bytes in the Worker | `routing.hex`, which is
`newSessionId` (#313) renamed, plus a `sha256Hex` in `storage.ts` | the
publication-identity and chunk-digest copies in `storage.ts` (#2652) |
| Is this pid alive? | `leaf.machine.pid_alive` | `_alive` in
`tests/process/test_codex_tool.py` (#3331). `running()` in
`test_interact_layer.py` (#1774) |
| Read an example's seeded log | `read_event_lines(seed_log(source))`
(#4484) | inline parsers in `test_render_pages.py`,
`test_interact_product.py` (#924) and `test_render_gate.py` (#509). The
last one split lines with `splitlines()`, which also breaks at U+2028 |
| Paths of the bundled registries and packages; which registry keys name
elements | `leaf.schema.ASSETS` / `BUNDLED_PACKAGES` /
`DEFAULT_PACKAGE`, `leaf.registry.contract.is_element_name`,
`docs.registries()` | `docs.py`'s own `ASSETS`/`PACKAGES` (#3593) and
its `startswith("lf-")` checks (#2660). `logs usage`'s hand-written
regex and registry list (#5970). `ROOT / "packages" / "default"` in
`stills.py` (#3927) and `test_product_page.py` (#3593) |

`is_element_name` and the two checks it replaces give the same answer
for every key in the bundled registries today. A selector key such as
`lf-options.selected` would have passed the `lf-` prefix test.

<details><summary>Sets found and left alone</summary>

- **Sets an open PR is changing.** Nothing in this diff overlaps another
open PR's hunks. #6732 moves tests out of `test_render_gate.py`,
`test_render_pages.py` and `test_interact_layer.py`, but none of the
tests changed here.
- **Changes to browser tests with nothing run to check them.** The WCAG
contrast computation exists as about 11 copies across browser, journey
and model tests. Other copies: about 9 `EDITOR_ROOTS` shadow-root
keepers, the `/api/interaction` batch predicates, CDP `touch()`
closures, one-line patch templates, reply-holding route handlers, and
the `data-lf-entry` runtime-module import snippet in
`dev/leaf_dev/states.py` and in tests. Each would mean editing browser
tests that this sweep can't run on a shared host. They suit a sweep that
can run those tests.
- **Vendor bundling.** `build/browser/build.mjs` builds signals-core and
Lit with esbuild calls that repeat `build/vendor.mjs`'s `bundle()`.
Merging them changes build options and needs a full `check:browser` byte
comparison, so it was left for a change that runs that.
- **Copies that are near but not the same.** `_build.py`'s `check_links`
repeats `leaf_website.released_path`, but it also needs the matched
page's root and kind. The list of API-key variables an eval drops is
repeated across Python and the Promptfoo configs, as subsets and
supersets of one another. The Codex token-expiry check has different
thresholds, 1 h and 60 s.
- **Too small to be worth it.** Picking a free loopback port
(`eval_user.py`, `interact_support.available_loopback_port`). The XDG
state root in `leaf_dev.state_home` and `leaf.state.state_home`. The
`settled` helper in two `tests/runtime` files.

</details>

Co-authored-by: leaf-agent <[email protected]>
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