Repository navigation
Run a package's scripts with leaf package run, and keep the suite offline - #1097
Conversation
…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
left a comment
There was a problem hiding this comment.
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.
…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
left a comment
There was a problem hiding this comment.
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]>
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.leaf page guidanceglobally 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.named_package, the same lookuppage init --packageuses, so installed packages work too. It then execsuv run --quiet --script <package>/scripts/SCRIPT ARGS, which leaves stdin, stdout, stderr and the exit status to the script.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.package installcopies a package'sscripts/, so a third-party package can ship producer tools. Pages never vendorscripts/.package check, and thereforeinstall, refuses a script without a PEP 723 header, whose script would otherwise run in the caller's project environment, and a dependency orrequires-pythonthat is anything but a floor. Reading the header addspackaging(andtomlibefore Python 3.11) to Leaf's runtime dependencies.uv run --no-projectdoes not isolate a headerless script, so the check is the one mechanism.The everyday suite runs offline again.
uv run patch_manifest.py, which needed the network on a cold cache, whiletests/AGENTS.mdpromises the suite needs none after setup.unidiffjoins the dev group, souv.lockpins what the suite runs, and the tests run the script under the project's Python.package run. RootAGENTS.mdstates this.leaf data setrefuses empty input. Whenpatch_manifestrefused a patch,data setthen printedinvalid 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.
package checkandinstallrefuse.UV_OFFLINE=1and an empty uv cache.npm run test:runtime: 91 passed. The nightly diff tests (12) andtest_site.py(49) passed.🤖 Generated with Claude Code