Repository navigation
Give each of leaf-dev's internal mechanisms one home - #6014
Merged
Merged
Conversation
A command module was imported as a library: the three harness journeys imported `Isolation`, `Terminal`, `User` and the rest from the command `journey run`, `journey session` and `journey chart` did too, and the journey, `logs timeline` and the delivery eval read each input's milestones from the command `logs response-times`. - `commands/journey/run.py` keeps the command, `target_session` and `website_session`; everything the targets share (the user, both ends, the terminal, isolation, `samples_path`, `HARNESS_TARGETS`, `CASES`) moves to `commands/journey/_journey.py`, whose header now carries the journey's design. `git show -C` shows it as a copy of run.py. - `journey_claude_code.py`, `journey_codex.py` and `journey_pi.py`, which only the journey group imports, move to `commands/journey/_claude_code.py`, `_codex.py` and `_pi.py`. - The reading behind `logs response-times` (`page_timings`, `distribution`, `spread` and their helpers) moves to `leaf_dev/page_timings.py`; the command module keeps the Click command. - `leaf_dev/suite.py`, which only the suite group imports, moves to `commands/suite/_runs.py`. `dev/AGENTS.md` now says code only one group's commands need is that group's `_name.py`. No behavior changes; the tests that reached these names by their old modules import the new ones.
`placement pins` ran its own loop: serve each arm, open a tab per viewport, load, read and screenshot. It now visits each arm in each window through `leaf_dev.visits`, the loop `placement cards`, `stills` and `probe` share, and reads and captures every case in the visit's `read`. `capture` takes the arms and the fixture and returns each arm's readings; it no longer serves or opens tabs itself. Behavior: each arm now serves the page once per viewport rather than once for both, so a run takes a few seconds longer (18 s without --base on a loaded host), and the tab carries visits' observers. A run's report and its 52 full screenshots are identical to the old loop's, byte for byte and pixel for pixel.
`run_leaf` takes an optional arm (None runs this environment's Leaf, `LEAF_COMMAND`), an optional state home, an `env` to start from and the exception a failed check raises. The site build's `leaf` (quiet, exiting with what the command said) and `fork_eval.Leaf.run` (the session's environment, a RuntimeError) are now calls of it, and their copies are deleted. Behavior: the site build's commands no longer run with the repository root as their cwd, and a failure's message also says the exit status. The fork eval's failure message carries the command's stdout as well as its stderr. Two runners stay: `preview.leaf` streams the command's stderr to the developer as it runs, keeps the session's environment and exits with the command's own status (`LeafFailed`); `eval report`'s `leaf` initializes the developer's own report page, with their personal configuration, which `run_leaf` deliberately leaves out.
Five places built the command that runs code with an arm's own Leaf, each its own way: `retire_sessions` and `build_arm`'s compile ran the arm's `.venv/bin/python`, the fork eval with `-I`, the usability fixture `uv run --with dev`, the website eval and the preview worker `uv run --with-editable`, and `eval report`'s phase export `uv run --no-dev`. `arm_python(arm, dev=None)` is the one command: the arm's interpreter with `-I`, or with `dev`, that `leaf_dev` tree laid over the arm's environment by `uv run --with-editable`. Each caller now starts its command with it. Behavior: `retire_sessions`, the compile and `eval report`'s export run the arm's interpreter isolated (`-I`); the export no longer syncs the arm's environment first, which its install already synced; the usability fixture overlays `dev/` editable rather than as a built copy.
`leaf.media.write_media(directory, data, suffix)` is the writer `_store_media` ran inside its page transaction: name the bytes, write them unless the name holds them already, and refuse a digest collision. `_store_media` now calls it under the transaction, and the dev copies that wrote a media directory by hand, `gallery.media` (the pins, cards and eval report pages) and `site media` (the leaf-assets checkout), call it too. `require_media_type` is `cmd_media`'s refusal of a file Leaf doesn't serve, which `site media` had copied; both call it. Behavior: a gallery or `site media` write whose name already holds other bytes now fails rather than overwriting them; `site media`'s refusal of an unserved type is a Leaf refusal (exit 1) rather than a usage error.
Six passes of `site verify`, and the journey's local session, opened a page the same way: watch its startup and errors, load it, require the document, and wait for it to present. `verify.load_presented(page, url, unloaded)` is that step; each caller keeps only what it adds, such as the startup report it expects around the load or the headers it reads after. Behavior: the saved-state pass now checks that the private document came from the durable record after the page presented rather than before, so a page that fails both reports the durable-source check second.
`server_paths.scratch_state` and `site previews`' `serve_examples` each saved, set and restored `XDG_STATE_HOME` by hand. Both now hold it with the standard library's `unittest.mock.patch.dict(os.environ)`, and `scratch_state` is deleted. Behavior: on leaving, `patch.dict` restores the whole environment, so a variable set inside the block no longer outlives it. Checked with `leaf-dev bench --read server --sizes 32,64`.
`visits.console_findings` was `render_gate.scheme.collect_page_errors` copied with console warnings kept (#3405 replaced a call with the copy). `collect_page_errors` takes `warnings` instead, and `visits` calls it with warnings on; `console_findings` is deleted. The diagnostics test drops it from the collectors it compares, since `observe_startup` reaches the same collector. No behavior changes.
`tests/render_harness.py::marked_tops` walked every pixel in Python to find the follow tests' two marks, beside `panel_paint.ink_box`, which finds a colour with Pillow. `ink_box` now takes a window, a range per channel, and `near(colour, tolerance)` gives the ±30 window the panel's mark and ring were read with; `marked_tops` reads its marks' wide windows through it. No behavior changes: on 300 blurred, downsampled, JPEG-compressed frames the new `marked_tops` returns exactly what the pixel walk did, at a ninth of its time (2.3 ms against 20.9 ms on an 800x450 frame).
`evals/ui-review-detection/provider.mjs` rebuilt in Node the isolated Claude Code home `arms.claude_home` makes (the keychain link, a copy of the credentials) and its own version of `claude_environment`'s environment. It now asks Python for both through `arms.mjs`'s `python`, as `screenshot_judge.mjs` reaches Python, and keeps only its guard against ambient API keys. Behavior: the reader's environment is `arms.environment`'s, so it also drops the agent session's identity and Leaf's launcher variables, and keeps `CODEX_*` variables it used to drop, which a Claude reader doesn't read. `evals/control-legibility/provider.mjs` copies none of this: it keeps the host's home and isolates its reader through the Agent SDK's options alone, so it is unchanged.
Three readers parsed the context a Leaf hook hands Claude Code inline: `harness.claude_code_entered`, the Claude Code journey (`deliveries` and its mid-turn check) and `logs timeline`'s `told`, which matched a hand-shortened copy of `INLINE_OPENING`. `hook_transport.inline_delivery` beside `INLINE_OPENING` is the one parser: the delivery a context handed over, or None. Each reader takes the event ids from what it returns; the journey's mid-turn check is now `deliveries` read for a PostToolBatch hook, and the timeline's `DELIVERY_OPENING` is deleted. Behavior: the timeline shows a context whose delivery JSON doesn't parse line by line, as any other context, rather than as one clipped line.
The arrangement eval (`phase_traces`) and the usability eval (`Run.traces`) each split a native session's records at the `eval_phase` marks its driver notes. `arms.phase_traces`, beside `read_trace`, is the one splitter, with the usability eval's reading: each phase opens with its mark, and records before the first mark are a phase of their own. The arrangement eval keys those phases by the mark's phase number. No behavior changes: the usability eval's phases are what its loop made (checked on 2,000 random traces), so its judge's driver evidence keeps the marks; the arrangement eval's phases now hold their mark too, which its only reader, `trace_summary`, doesn't count.
`usability_eval.anchor` built a comment's anchor by hand: 24 characters of the element's words on either side of the quote, from `SourceReading`. It now asks `leaf.anchor_capture.capture_anchor`, which writes an anchor the way a selection's is, its context reaching to the passage's fences (`$passages.context`), and `said` is deleted. Behavior: an anchor's prefix and suffix are Leaf's captured context rather than 24 raw characters, and a quote the element doesn't hold, or holds twice, is refused rather than taken at its first occurrence. Every anchor the usability cases and fixtures name captures in its fixture.
…_directory `suite flake`, `suite bugback` and `eval run` each made their run directory by hand, named by the time it started, beside `arms.run_directory`, which the other commands use and named `run-` only. `run_directory` now names each `run-` and its start time, and the three call it. Behavior: every command's run directory is `run-YYYYMMDD-HHMMSS-…`; the arm commands' gain the time, so a listing sorts by age, and flake, bugback and eval runs gain the `run-` prefix CI's and the docs' `run-*` globs already match.
…arness Seven places in `leaf_dev` resolved `CLAUDE_CONFIG_DIR` or `CODEX_HOME` against their defaults by hand, beside the product's `leaf.harness.claude_code_config` and `codex_home`: `arms`' login homes, Pi's home and the authoring sandbox's host plugins, `logs timeline`'s `claude_directory` (deleted), `reply_phases`' transcript lookup and `eval run`'s provider config. Each now calls the product function. Behavior: an empty `CLAUDE_CONFIG_DIR` or `CODEX_HOME` now means the default directory in `arms` and `eval run` too, as it did in the product.
- `journey chart` escapes its chart's source with `html.escape` rather than three `replace` calls. - `draw_failures.placed` reads the page's log with `read_events`. - The fork eval's tool calls and the Codex journey's MCP check walk a trace's content blocks with `arms.blocks`. - `_journey.checkout_version` takes the working tree's commit from `arms.arm_commit`, and `working_version`, its only helper, folds into it. - `bench.exponent` fits its slope with `statistics.linear_regression` (the same slope as the hand-written fit on 3,000 random readings). No behavior changes.
…nner did
A page's layer resolves a relative package path against the working directory of
the `page init` naming it, and the site's docs/layer.json names `./docs/package`.
Since run_leaf absorbed the site build's runner, `leaf-dev site build` and `site
previews` failed outside the repository root ("package './docs/package' is not a
directory"). Also rewraps dev/AGENTS.md's group-helper sentence.
# Conflicts: # dev/leaf_dev/commands/logs/timeline.py
leaf-agent
previously approved these changes
Nov 15, 2026
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]>
# Conflicts: # dev/leaf_dev/commands/eval/run.py # dev/leaf_dev/commands/journey/run.py # dev/leaf_dev/commands/logs/timeline.py # dev/leaf_dev/commands/placement/pins.py # dev/leaf_dev/draw_failures.py # dev/leaf_dev/gallery.py # dev/leaf_dev/panel_paint.py # tests/browser/test_render_floating_panel.py # tests/render_harness.py
leaf-agent
approved these changes
Nov 18, 2026
This was referenced Nov 18, 2026
max-sixty
added a commit
that referenced
this pull request
Nov 18, 2026
… modules (#6380) Follow-up to #6014, which left other code importing from `leaf-dev` command modules. Now a command module is imported only by the CLI and by the tests of that command: the code other modules borrowed lives in helper modules, and `dev/AGENTS.md` states the rule. - `dev/leaf_dev/website.py` reaches leaf.page or the local build from a browser: page loads, state reads, activation, user sessions, the local adapter and the local Worker, and the built site's paths (`SITE`, `asset_site`, `install_tree`, `site_lock`). It came out of `site verify`, from which `journey run` imported a dozen names, and `site build`. Its browser script (`website.js`, formerly `verify_browser.js`) and `wrangler_server.mjs` moved beside it, and `startup_profile` and `startup_line` joined `startup.py`. - `dev/leaf_dev/corpus.py` is the corpus generator, which `named_source`, `page_fixtures` and `states` call on demand. - `server_paths.py` folded into `commands/bench.py`, its only user, which ends their import cycle. Its names that collided with bench's took a `server` prefix (`measure_server`, `SERVER_FITTED`, …). - `arms.py` holds `preview_lease` and the `terminated` stop handler, which the Codex journey and `website_eval` imported from `preview`. - Group helpers: `placement/_pin_cases.py`, the catalogue `tests/browser/margin/test_pins.py` asserts, and `site/_build.py` and `site/_distribution.py`, the pipeline `site previews` and the product tests use. `pins.py`, `build.py` and `distribution.py` keep their commands. The code moved unchanged apart from those renames and two paths: `website.py` reads the build's manifest through `leaf_website.SITE_MANIFEST` and its lock through `site_lock`, where `site verify` had spelled both out a second time. To weigh: `site previews` now ends with the build `site build` runs (`_build.build_site`), which also takes the site's lock and bundles the published runtime, so the `.tmp/site` it leaves is one `site verify website-worker` can read; before, it rebuilt `.tmp/site` unlocked and unbundled. git records `_build.py`, `_distribution.py` and `_pin_cases.py` as new files, so their history before this change is on `build.py`, `distribution.py` and `pins.py`. Checks: every touched command's `--help`; `generate corpus`, `bench events --read server`, `placement pins`, `site distribution` and `site build` end to end; the dev tests over the moved code, where only the ten tests #6374 fixes fail, as on main; the product tests that import it; and pre-commit on every changed file. `site verify website-worker` times out at its first activation through the local Worker on this machine, on main as well, so that pass is unverified here. Each moved definition matches its original by AST apart from the changes above. Max asked for this as the follow-up #6014's description named. > _This was written by Claude Code on behalf of max-sixty_
max-sixty
added a commit
that referenced
this pull request
Nov 18, 2026
…ey read (#6374) Ten tests under `dev/tests` failed on main because five main commits changed what they read, and nothing in CI runs `dev/tests`. Each test still protects behavior that holds, so the fix is in the tests' fixtures and expectations; no developer tool changes. - #5964 put a `leaf` command's refusal in its stdout JSON. The desktop Codex `server start` cases and the unavailable-delivery `start`/`run` handoffs in `test_interact_preview.py` now read it there. - #4198 made the preview follow more files in its checkout. The assets-pin test's fake checkout now creates every file `worker_inputs` names, so the preview no longer subscribes the whole checkout recursively. - #6237 re-indented `docs/index.html`, and the composed-image case in `test_product_page.py` matched on the old indentation. It now matches on `alt` alone. - #5228 changed the journey's page-text read, and #6090 shortened the release marker to seven characters. `test_website_server.py`'s fake page and its expected marker follow both. To weigh: these breaks went unseen for up to three weeks because `dev/AGENTS.md` keeps `dev/tests` out of every CI selection. This PR leaves that rule unchanged. Dispatched by max-sixty from the session that landed #6014. Tests: the three changed modules, 91 passed on macOS. > _This was written by Claude Code on behalf of max-sixty_
max-sixty
added a commit
that referenced
this pull request
Nov 18, 2026
…ts a leaf-dev command module (#6407) Makes `dev/AGENTS.md`'s rule that only the CLI and tests import a `leaf-dev` command module a ruff check. `banned-api` (TID251) bans `leaf_dev.commands` everywhere except `cli.py`, the commands themselves and the two test trees, so pre-commit, CI and `wt merge` refuse a helper module that imports a command, with a message saying where the code goes. Five commits between 19 October and 3 November added such imports, and #6014 and #6380 then took two PRs to move them out; this check would have refused each one at commit time. It doesn't see one group's command importing another group's command. Nothing on main does that: every import inside `commands/` is of the importer's own group's `_name.py`. Max asked whether to add this as the follow-up to #6380. Checks: `pre-commit run ruff-check --all-files` passes on main, and a used `from leaf_dev.commands.site.verify import PAGES` added to `dev/leaf_dev/website_eval.py` fails with the message. > _This was written by Claude Code on behalf of max-sixty_
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.
Follow-up to #5965, which grouped
leaf-dev's commands: this merges the developer tooling's internal duplicates, so each mechanism has one home. 52 files, +2541 / −2581; most of the ± is code moving between modules.Group helpers instead of command modules used as libraries
Isolation,Terminal,User, …) moved out of the commandcommands/journey/run.pyintocommands/journey/_journey.py, and the harness journeys intocommands/journey/_claude_code.py,_codex.pyand_pi.py.run.pykeeps the command.logs response-times' reader moved toleaf_dev/page_timings.py, since the journey,logs timelineanddelivery_evalimported it from the command;suite.pymoved tocommands/suite/_runs.py.dev/AGENTS.mdsays where a helper only one group uses goes (_name.py, whichcli.pylists as no command).Command modules other code still imports as libraries remain:
site verify's page and session helpers (the journey imports 12 names, and this PR addsload_presented),generate corpus,preview's lease,bench(withserver_paths, a cycle),journey snapshotsandsite build/distribution. Moving them needs about 600 lines out ofverify; that's a separate decision.placement pinsonleaf_dev.visitsplacement pinsnow visits its arms through the loopplacement cards,stillsandprobeshare. Its report and all 52 full screenshots are byte- and pixel-identical to the old loop's, with and without--base.Merged duplicates
arms.run_leaf(arm | None, state | None, env=, error=)runs Leaf for the site build and the fork eval too, from the repository root, against which a page's layer resolves a relative package such as the docs'./docs/package;arms.arm_pythonbuilds the command for code run in an arm's interpreter (five callers).leaf.media.write_mediawrites developer media, withrequire_media_typefor the refusalsite mediahad copied.site verifyopens each page through oneload_presented; its saved-state pass now checks the durable source after presentation rather than before, which changes only which failure is reported first.patch.dict; visits' console readings throughcollect_page_errors(warnings=); a mark's colour throughpanel_paint.ink_boxwith a per-channel window, which reproducesmarked_topson 300 blurred frames and runs 9x faster.provider.mjsasks Python for the Claude login home and environment (arms.claude_home,arms.environment) instead of copying them.hook_transport.inline_deliveryreads a hook's inline delivery for the Claude Code journey,logs timelineand the harness;arms.phase_tracessplits a stream trace at itseval_phasemarks (equivalent on 2,000 random traces).anchor_capture. Anchors now carry Leaf's captured context and refuse a quote their element holds twice, as Leaf does, where the hand-built one took the first match; every anchor the cases and fixtures name still captures.suite flake,suite bugbackand eval runs allocate their directories withrun_directory, now namedrun-YYYYMMDD-HHMMSS-…; CI'srun-*globs still match, and no code parses the name.leaf.harness, and five hand-written one-liners call the library orleaf_devhelper they repeated.Left as copies, because their behaviour differs in ways one parameter can't carry:
preview's own runner (streams stderr, keeps the session environment, exits with Leaf's status),eval report's Leaf (builds the developer's own page with their configuration),control-legibility's provider, Node'sCODEX_HOMElookup, archiving a sample's pages, and the judge inputsregrade.pyandauthoring_assertion.mjsbuild, which name the pages differently, so merging them changes what judges read.Checks
uv run leaf-dev --helpand every touched command's--help;placement pins(with and without--base),placement cards --case words-long,probewith thepanel_paintjourney,bench --read server,preview,journey chartandlogs timelineend to end; the site build'spage initfrom outside the repository root.dev/testscovering the touched modules, thetests/model, process and browser tests that import them, and pre-commit (ruff, vulture, ty, knip, prettier, eslint, typos) on every changed file.1289a479d5), so none is this branch's:test_preview_file_subscription_follows_atomic_replacements,test_desktop_start_requires_its_validated_native_chat(3 cases) andtest_serving_connects_codex_feedback_before_handing_over_its_url(4 cases) intest_interact_preview.py, one case oftest_product_page.py::test_a_composed_part_refuses_an_authored_copy, andtest_the_page_a_turn_has_just_written_waits_for_its_revision_after_presentation, which has failed since Let a page's header, nav and footer stand beside main #5228 (its fake page returns a list for the newinnerTextread).journey/run.pywere carried into_journey.py(the seven-character release hash,open_news's selector,send_commentwithoutpassage); on the merged head, pre-commit, the dev tests, the product tests over the resolved conflicts (panel paint, pins, frame marks, website routes, media),placement pins(with and without--base),placement cards --case words-long, thepanel_paintprobe,bench --read server,preview,journey chartandlogs timelinewere rerun.