Repository navigation
narrow_inputs: an opt-in that gives a job only the toolchain files it uses - #26
Open
ndbroadbent wants to merge 3 commits into
Open
ndbroadbent wants to merge 3 commits into
ndbroadbent wants to merge 3 commits into
Conversation
ndbroadbent
added a commit
that referenced
this pull request
Dec 4, 2026
The shell reader now makes a job opaque whenever it can't positively
understand what a line runs:
- Runners are read for the command they run: bundle exec, npx, pnpm
exec/dlx, yarn exec/dlx, npm exec, bunx, uv run, poetry run, corepack.
cargo and go subcommands that run project code (run, xtask, generate,
aliases) are opaque.
- Only a real heredoc (unquoted <<WORD, <<-WORD, <<'WORD' outside quotes
and comments) hides lines; an unquoted << parameter >> or a heredoc
that never ends is opaque, and a command after a heredoc is read.
- -c or -s inside combined shell flags (bash -lc, sh -ec) is opaque.
- A cd in a subshell, pipeline or function leaves the directory unknown,
so later scripts and toolchain commands are opaque.
- Commands hidden in arguments are opaque: trap, git aliases, git
rebase --exec, submodule foreach, bisect run, awk system/getline,
sed's e command and flag, ${X:-$(cmd)}, <(cmd), tar --to-command.
Also: a toolchain's pins and lockfiles count in each directory its
commands ran in and above; Windows runners and runners from expressions
are opaque; more pin files (go.mod, go.work, .terraform.lock.hcl,
.yarnrc.yml, .npmrc, Gradle and Maven wrappers, mise's config files).
Words are split respecting quotes.
ndbroadbent
force-pushed
the
modules/narrow
branch
from
December 4, 2026 02:23
189b641 to
ae5f800
Compare
… uses By default every job still gets every toolchain family's pins and lockfiles. With narrow_inputs: true (top level, or per job) a job gets its modules' families, the families whose commands it visibly runs, and every family when it runs anything cigen can't see into. Scripts resolve in the step's working directory and after literal cds; every package.json's scripts count when a Node package manager runs; every file read becomes an input.
The shell reader now makes a job opaque whenever it can't positively
understand what a line runs:
- Runners are read for the command they run: bundle exec, npx, pnpm
exec/dlx, yarn exec/dlx, npm exec, bunx, uv run, poetry run, corepack.
cargo and go subcommands that run project code (run, xtask, generate,
aliases) are opaque.
- Only a real heredoc (unquoted <<WORD, <<-WORD, <<'WORD' outside quotes
and comments) hides lines; an unquoted << parameter >> or a heredoc
that never ends is opaque, and a command after a heredoc is read.
- -c or -s inside combined shell flags (bash -lc, sh -ec) is opaque.
- A cd in a subshell, pipeline or function leaves the directory unknown,
so later scripts and toolchain commands are opaque.
- Commands hidden in arguments are opaque: trap, git aliases, git
rebase --exec, submodule foreach, bisect run, awk system/getline,
sed's e command and flag, ${X:-$(cmd)}, <(cmd), tar --to-command.
Also: a toolchain's pins and lockfiles count in each directory its
commands ran in and above; Windows runners and runners from expressions
are opaque; more pin files (go.mod, go.work, .terraform.lock.hcl,
.yarnrc.yml, .npmrc, Gradle and Maven wrappers, mise's config files).
Words are split respecting quotes.
- Toolchain commands that run commands: rustup run <toolchain>, gem exec, and a word pnpm, Yarn or Bun runs that isn't their own subcommand or a package script. cargo-<plugin> is checked like cargo <plugin>. Family command handling moves to src/inputs/shell/family.rs. - A toolchain command counts however it's written (\cargo, ca''rgo). - A cd that might not happen (under if, loops, case, after ||, or after && once the list ends) leaves the directory unknown. - Options that move a tool are followed (--cwd, -C, --dir, -chdir, --manifest-path, go -C); runners that pick packages (--filter, --workspace, -r) and find -execdir are opaque. - A quoted CircleCI parameter as the command is opaque. - Settings that name commands are opaque: alias x=, sort --compress-program, GIT_* command variables, git config keys outside a plain list. - A job's toolchains: [node, ...] adds families a narrowed job uses without cigen seeing it; unknown names are config errors with a fix. - A narrowed job gets the package.json files only with node. - Docs: the common ways the trust model fails, the toolchains key, and the keys tables (modules, narrow_inputs, toolchains; packages removed).
ndbroadbent
force-pushed
the
modules/narrow
branch
from
December 4, 2026 02:47
ae5f800 to
74235be
Compare
This branch has not been deployed
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.
Build PR 2 of the modules design (#10):
narrow_inputs.What changed
narrow_inputs, an explicit opt-in, at the top level or per job (the job's value wins). By default every job still gets every toolchain family's pins and lockfiles, modules or not.A narrowed job gets:
The shared pins (
.tool-versionsand mise's config files) go into every job either way.What cigen reads (
src/inputs/narrow.rs,src/inputs/shell/):package.jsonin the project.Every file it read goes into the hash, so changing a script that decided the families reruns the job.
Working directories: scripts resolve where they run: a step's
working-directory, GitHub'sdefaults.run(job, workflow, top level), and literalcds, including... A sourced script'scdcarries on; a subshell's doesn't. Acdcigen can't follow makes later scripts opaque.Runners are read for the command they run:
bundle exec,gem exec,npx,pnpm exec/dlx,yarn exec/dlx,npm exec,bunx,rustup run <toolchain>,uv run,poetry run,corepack,find -exec, a word pnpm, Yarn or Bun runs that isn't their own subcommand or a package script, and prefixes such astimeoutandsudo. A toolchain command counts however it's quoted or escaped (\cargo).toolchains: [node, rust]on a job adds families it uses without cigen seeing it; an unknown name is a config error with a suggestion. A narrowed job gets thepackage.jsonfiles (now a default input, Every package.json is a derived input: npm run runs its scripts #38) only with node.Tool directory options are followed:
--cwd,pnpm -C/--dir,terraform -chdir,cargo --manifest-path,go -C.A toolchain's own commands are trusted to use only that toolchain (
cargo test,rake,pnpm build). That's the one assumption narrowing makes; it's in the docs and STATUS (problem 23), with its common failure modes, and a job names what cigen can't see withtoolchains: [node].Pins where the toolchain runs: a family's pins and lockfiles count in each directory its commands ran in and the directories above, as well as the root (
cd web && pnpm installbringsweb/pnpm-lock.yaml).Opaque cases (anything the reader can't positively understand):
PATH), aliases (git my-alias, cargo aliases) and unknown actions;cargo run,cargo xtask,go run,go generate;sh -c(bash -lc,sh -ec),-s, a shell reading its input,trap, commands from variables;git rebase --exec,git submodule foreach,git bisect run, awksystem/getline, sed'se,${X:-$(cmd)},<(cmd),tar --to-command;<<that isn't a readable heredoc (an unquoted CircleCI<< parameter >>), or a heredoc that never ends;cdit can't follow, including one in a subshell, a pipeline or a function, or one that might not happen (underif, a loop,case, after||, or after&&once the list ends), before a script or a toolchain command;pnpm --filter … exec,npm exec --workspace),find -execdir,cargo-make;alias x=,sort --compress-program,GIT_EXTERNAL_DIFF=and other GIT_* command variables,git configkeys outside a plain list;shell:isn't a POSIX shell, a Windows runner, or a runner chosen by an expression.More pin files, in every job by default too (so default hashes change once):
go.mod,go.work,go.work.sum,.terraform.lock.hcl,.yarnrc.yml,.npmrc, the Gradle and Maven wrapper properties, and mise's other config files.A CircleCI job's
working_directoryneeds nothing: the checkout goes there, so commands start in the project root.Reasons: each family's choice carries a reason (
FamilyChoice: "modulerust", "it runsbundleinscripts/more.sh", "narrowed: nothing the job runs uses it"), ready forcigen explain.src/inputs.rsis nowsrc/inputs/: families, files, narrowing and the shell reader each have their own module, all under 300 lines.Docs: a
narrow_inputssection in the Inputs page, with the trade-off; STATUS problem 1 says narrowing is opt-in.Tests
tests/narrow_inputs.rs, in mockci:package.jsonwhose scripts it runs (the root's or a sub-package's);working-directoryand aftercd;make,shell: pythonand apwshdefault give every family;cdresolution, unfollowable directories, subshell scoping, and bare commands.src/inputs/shell/tests/hidden.rs: one test per false skip the independent review found (runner subcommands, fake heredocs, combined shell flags,cdin a subshell, commands hidden in arguments). Each fails on the first commit (189b641) and passes now.tests/narrow_inputs_readers.rs, by hash: default working directories, Windows runners and runners from expressions, CircleCI orb and unknown named steps, a CircleCIworking_directory, known, unknown and local (composite and not) actions, pins where a toolchain runs, and the new pin files. The Windows, pins-in-directories and new-pin tests fail on 189b641; the rest cover behaviour that already worked.src/inputs/shell/tests/second_review.rs: one test per finding of the second review (runners likerustup run, escaped commands, conditionalcd, directory options, quoted CircleCI parameters, command-naming settings). Each failed before its fix.tests/narrow_inputs_readers.rsalso checkstoolchains(and its error) and that a narrowed job getspackage.jsononly with node.makescenario;cd/working-directoryscenario;package.jsonfails the sub-package scenario;shell:fails theshell:scenario.task cipasses with no warnings.