Skip to content

Run a package's scripts with leaf package run, and keep the suite offline - #1097

Merged
max-sixty merged 5 commits into
mainfrom
package-scripts
Sep 24, 2026
Merged

max-sixty merged 5 commits into
mainfrom
package-scripts

Conversation

@max-sixty

@max-sixty max-sixty commented Sep 24, 2026 •

Copy link
Copy Markdown
Owner

Fixes from a review of #1082, which moved git patch parsing into a script the diff package ships.

leaf package run PACKAGE SCRIPT [ARGS]... replaces the <leaf-packages> placeholder.

  • The problem: Store only derived meaning, fold fragments into records, and move patch parsing to the diff package #1082 had leaf page guidance globally replace <leaf-packages> with the bundled packages directory. That worked only for bundled packages, hard-coded the package's own directory in its guidance, and printed an unquoted machine path.
  • The door: it finds the package with named_package, the same lookup page init --package uses, so installed packages work too. It then execs uv run --quiet --script <package>/scripts/SCRIPT ARGS, which leaves stdin, stdout, stderr and the exit status to the script.
  • Guidance: it now reads git diff … | leaf package run diff patch_manifest.py | leaf data set "$PAGE" <source-id>. It names a package and a script and prints no path, so there is nothing to substitute or quote.
  • Install: package install copies a package's scripts/, so a third-party package can ship producer tools. Pages never vendor scripts/.
  • Script check: package check, and therefore install, refuses a script without a PEP 723 header, whose script would otherwise run in the caller's project environment, and a dependency or requires-python that is anything but a floor. Reading the header adds packaging (and tomli before Python 3.11) to Leaf's runtime dependencies. uv run --no-project does not isolate a headerless script, so the check is the one mechanism.

The everyday suite runs offline again.

  • What broke: since Store only derived meaning, fold fragments into records, and move patch parsing to the diff package #1082 the patch tests ran uv run patch_manifest.py, which needed the network on a cold cache, while tests/AGENTS.md promises the suite needs none after setup.
  • The fix: unidiff joins the dev group, so uv.lock pins what the suite runs, and the tests run the script under the project's Python.
  • A guard test requires every dependency a bundled script declares to be in the dev group.
  • Hosts: package scripts declare floors with no cap and ship no lock, so a host resolves them on its first package run. Root AGENTS.md states this.

leaf data set refuses empty input. When patch_manifest refused a patch, data set then printed invalid JSON (Expecting value…) for its empty stdin. It now says no value arrived on stdin and that the command piped into it likely failed.

Tests.

  • New tests cover:
    • the door, run against an installed package: stdin, arguments, stdout, exit-status pass-through, and the unknown-package and unknown-script refusals;
    • the empty-stdin refusal;
    • the dev-group guard;
    • six malformed scripts that package check and install refuse.
  • The patch tests pass with UV_OFFLINE=1 and an empty uv cache.
  • Everyday suite, on the merge with main: 1373 passed.
  • npm run test:runtime: 91 passed. The nightly diff tests (12) and test_site.py (49) passed.

🤖 Generated with Claude Code

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

max-sixty and others added 2 commits September 23, 2026 23:58
…idiff

Follow-up to #1082's move of patch parsing into the diff package.

**A package's scripts are addressable by package name.**
- New door: `leaf package run PACKAGE SCRIPT [ARGS]...` finds the package through `named_package`, the lookup `--package NAME` resolves through, and execs `uv run --script` on `scripts/SCRIPT`. The script owns stdin, stdout, stderr and the exit status, and arguments after SCRIPT pass through untouched, options included.
- `package install` now copies `scripts/`, so an installed third-party package can ship producer tools on the same terms as a bundled one. A page still never vendors them.
- The `<leaf-packages>` placeholder and its global substitution in `page_guidance` are gone. The diff producer guidance now prints `git diff … | leaf package run diff patch_manifest.py | leaf data set "$PAGE" <source-id>`, with no machine path and nothing to quote.
- *Behavior moved:* guidance output no longer carries an absolute packages path, and `packages.md` documents `scripts/` as a package directory, not a bundled-only one.

**`leaf data set` refuses empty input by name.** A producer that refuses its patch writes nothing. `data set` used to follow its error with `invalid JSON (Expecting value, line 1)`. It now says no value arrived on stdin and points back at the upstream command's error. An empty `--file` is named as empty.

**The everyday suite needs no network again.** `scripts/example_data.patch_manifest` ran `uv run patch_manifest.py`, which on a cold uv cache has to resolve unidiff from the index. It now runs the script as a process under the project interpreter. The dev group repeats `unidiff>=1`, so `uv.lock` pins the version the suite runs against. A test holds that every requirement in a bundled script's header is in the dev group. AGENTS.md, "The install runs this tree", now states the policy: scripts declare floors and no cap and ship no lock, and hosts resolve them on first `package run`.

Tests: the guidance test now checks that the printed pipeline names a script the run door reaches. A new test installs a package with a dependency-free script and runs it through the door, checking stdin, arguments, stdout, exit status and the refusals. Another new test covers the empty-stdin refusal. The CLI help snapshot gains `run`.

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.

package check and package install accept a scripts/*.py file without the required PEP 723 header. Running that installed script then uses the caller's project environment instead of a script-specific one: I checked, installed, and ran a headerless script, and it printed this checkout's .venv/bin/python. That makes an accepted package's producer depend on whichever project the agent happens to run it from, contrary to the package script contract. Validate the scripts' inline metadata when checking a package so installation refuses this shape; the same validation can enforce the declared dependency floors.

max-sixty and others added 2 commits September 24, 2026 00:23
…ints

`uv run --script` builds an environment of its own only for a file that carries a PEP 723 `script` block. It runs a file without one in whatever project the caller's directory reaches, so an installed producer depended on where the agent ran it. `--no-project` does not close that: uv still picks the caller's `.venv` for a headerless file (measured). The header is therefore the one guarantee, and `package check` now enforces it.

- *Behavior moved:* `package check` reports, and `package install` refuses, a `scripts/*.py` with no single `script` block, with malformed metadata, or with a `requires-python` or dependency constraint other than a `>=` floor. That includes caps, `==`, bare names and URLs. Subdirectories of `scripts/` hold helpers and are not checked or run.
- Bundled packages never pass through install, so the suite runs `package check` on every bundled package that ships scripts.
- `packaging` and, before Python 3.11, `tomli` become runtime dependencies to read that metadata. The floors are `packaging>=22`, which the new tests pass on, and `tomli>=1.1`.

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.

The offline dependency guard misses valid multiline PEP 723 dependency lists. check_package_scripts accepts a script with # dependencies = [ spread across comment lines, but this test's re.findall sees only a single-line array. I reproduced a header accepted by package validation for which the test collects no dependencies. Because the existing diff script still supplies unidiff>=1, adding a bundled script in this form can leave a new requirement out of the dev group while the guard stays green, and the suite may need the network on a cold cache again. Read dependencies through the same parsed metadata used by package validation so the guard covers every accepted header.

The suite's pin guard matched a single-line dependency array with a regex, so a
header package check accepts with the list spread over several comment lines
went unread and a new requirement could miss the dev group. script_requirements
now holds the reading and the policy, and both package check and the guard use it.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit baa0acf into main Sep 24, 2026
5 checks passed
@max-sixty
max-sixty deleted the package-scripts branch September 24, 2026 08:05
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