Skip to content

Add cigen explain <job>: what a job's hash covers - #14

Merged
ndbroadbent merged 8 commits into
mainfrom
tools/explain
Dec 4, 2026
Merged

ndbroadbent merged 8 commits into
mainfrom
tools/explain

Conversation

@ndbroadbent

@ndbroadbent ndbroadbent commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

Item 3 of the agent-tools work. Stacked on #13, which is stacked on #9. The base is tools/validate; it retargets as those merge.

What changed

  • Job hashing moved into the library (src/hashing/). files.rs holds FileHasher, HashCache and pattern listing. job.rs holds hash_job, which returns a JobHash: the digest plus the declared inputs with each pattern's matched files, the derived inputs, and what else is hashed. src/commands/hash.rs goes from 571 to 169 lines.
  • The digest is unchanged. I kept the pre-change binary and compared it with the new one on the same tree. All 9 of cigen's own jobs and the rails fixture's job give identical hashes, with and without --cache, and pattern mode (hash -p) matches too.
  • cigen explain <job> [--config] [--base-dir] [--format text|json] calls the same hash_job, so its hash is exactly what cigen hash --job prints. It shows:
    • the declared inputs, in order, with @groups expanded (including nested groups) and the files each pattern matched;
    • the derived inputs from src/inputs.rs: config parts by label (command:<name>, service:<name>, provider:<name>, package.json:packageManager) and files with a reason (toolchain pin, lockfile, named in a step);
    • what else is hashed (cigen's version, the job definition, the workflow's settings);
    • the hash.
  • An unknown job is a ConfigError with the closest id as its suggestion, for hash --job too.
  • The "The config has N problems" footer now prints only for more than one error.

For the modules worker: I didn't change src/inputs.rs. The file reasons come from its TOOLCHAIN_PINS and LOCKFILES lists in hashing/job.rs. When modules contribute inputs, inputs::Derived could carry a reason for each file, and explain would show it.

Tests

tests/explain.rs:

  • the JSON lists declared inputs (a nested group, a plain pattern with no matches), the derived config and files with their reasons;
  • the explain hash equals hash --job's, before and after a derived input changes;
  • the exact text layout;
  • an unknown job suggests the closest one.

task ci passes with no warnings.


Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Job hashing moves from the hash command into the library (src/hashing/):
file digests and the on-disk cache in files.rs, and hash_job in job.rs,
which returns the hash with what went into it. hash --job and explain
both call it, so explain always describes the hash hash --job prints.
The digest is unchanged: the old and new binaries give the same hash for
every job in this repo and the fixtures, with and without --cache.

explain prints the job's inputs with @groups expanded and the files each
pattern matched, the derived inputs (config parts, and files with their
reason), what else is hashed, and the hash, as text or JSON. An unknown
job is a ConfigError that suggests the closest id.

The config-error footer ("The config has N problems") now prints only
when there's more than one.
The CLI page documents cigen explain: its options, what the text output lists
for an example config, and the JSON fields. The overview, roadmap and homepage
list it as built.
Ports #30's needs hashing into hashing::hash_job: a job's hash covers the
hashes of the jobs it needs, transitively, and without --modules-digest it uses
the modules digest this cigen computes. cigen explain lists the needed jobs
with their hashes.
#38 made every package.json a derived input, through the same list as the
patterns modules contribute, so explain labelled `**/package.json` as coming
from a module. Derived patterns now carry a reason, `from a module` or
`every package.json`, like derived files do.
Ports #51: hashing::hash_job mixes a GitHub matrix entry into the job's hash
(matrix_entry.rs moved to src/hashing/matrix.rs with its tests), so hash
--matrix still gives each entry its own hash. cigen explain takes --matrix to
show an entry's hash, and for a job that runs a matrix without one, says each
entry is hashed in.
…t need module jobs

The explain commit had dropped "The config has 1 problem." for a single error,
which the quick start still shows; main's report.rs is back. STATUS says that a
job needing a job with modules gets a new hash once, since needed jobs are
hashed with this cigen's modules digest.
@ndbroadbent
ndbroadbent merged commit bb269bd into main Dec 4, 2026
8 checks passed
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.

1 participant