jig-harness/jig
M2

Generated-artifact freshness

Drift gates for anything derived from a source of truth
1 · The idearead this first

Repos accumulate files derived from other files: API specs from route definitions, ORM types from migrations, doc indexes from doc trees, dependency notices from lockfiles — and prose that states countable facts (we have 120 skills). Each derived copy silently rots the moment its source changes, and both humans and agents then act on the stale copy. This module makes staleness mechanically impossible — or at least mechanically loud.

Invariantthe rule, independent of any tool

Nothing derived is trusted at rest. A derived file is either (a) not committed at all, (b) not committed but its would-be content is CI-checked against reality, or (c) committed with the full freshness triad: a regenerate script, a CI drift check that fails when stale, and a commit-time auto-regenerate-and-stage hook.

Every committed derived file is declared once, in one inventory: its outputs, its source, its regenerate command and its check. CI runs every declared check through one generic runner, never one hand-added step per generator, so a generator cannot ship without its check.

Derivation runs one way: an artifact that disagrees with its source is regenerated, never edited to match. A generator reaches every input that exists, and a regeneration after a merge reaches the protected branch through a pull request, as every other change does.

A number in prose that constrains its content stays; one that tallies an adjacent list is dropped, or declared as a fact and checked against its source on every run.

2 · The practicewhat each level asks of your repository

M2 Lite — minimum useful

inventory exists: every derived file in the repo is listed once with its regenerate command; hand-editing them is documented as forbidden.

What the audit checks at Lite convention-only is enough must be mechanically enforced
  1. Every committed derived file is listed in one canonical place together with the command that regenerates it.
    derived-inventory-existsWhat the audit looks for (2)
    • an inventory (README section, docs page, or manifest) pairs each derived file with its generator
    • no committed derived file is missing from the inventory
  2. Hand-editing derived files is documented as forbidden, and each derived file's header identifies it as generated with its regenerate command; where the format cannot carry a header (JSON, a vendored file pinned by its hash), the file's inventory entry says it is not edited by hand.
    hand-editing-forbiddenWhat the audit looks for (3)
    • instruction file or inventory states the hand-editing ban
    • derived files open with a generated-file marker naming the regenerate command
    • a derived file whose format takes no comment, or whose bytes are pinned, has an inventory entry with its regenerate command and that it is not edited by hand

M2 Standard — production teams

every committed derived file has the full triad; each generator that selects its inputs by a list has a coverage check; structured artifacts are compared as parsed data; at least prose path-references in instruction files are checked to exist; the instruction file states which numbers in prose may stay; every toolchain version pin equals its one declared source, and a check in CI fails one that differs.

What the audit checks at Standard convention-only is enough must be mechanically enforced
  1. The universal instruction file states the test for a number in prose: one that constrains its content stays, one that tallies an adjacent list is dropped or registered as a fact a commit-nothing check derives.
    numbers-in-prose-rule-statedWhat the audit looks for (2)
    • the universal instruction file, or a rule it links, states the constraint-versus-tally test with an example of each
    • the rule names what a tally that stays needs: a registered fact with a check, or a marker saying the number is a measurement
  2. Every committed derived file has the full freshness triad: a regenerate script, a CI drift check that fails when the file is stale, and a pre-commit hook that regenerates and stages it when its inputs change.
    committed-derived-full-triadWhat the audit looks for (3)
    • a runnable regenerate script exists per derived file
    • a CI job regenerates to a temp location, diffs, and fails on mismatch
    • hook-manager config (lefthook/husky/pre-commit) auto-stages the regenerated file
  3. A CI check verifies that repo paths referenced in instruction files resolve to existing files or directories.
    instruction-path-references-checkedWhat the audit looks for (1)
    • CI job runs a referenced-path-exists check over the instruction files
  4. Each toolchain version (the runtime, the compiler, the package manager) is declared in one source file; every other place that repeats it (CI setup steps, container build arguments, package-manager fields, a type package that tracks the runtime) is checked in CI to equal it; and a pin that differs on purpose is registered as an exception with a reason.
    toolchain-pins-one-sourceWhat the audit looks for (3)
    • one file (a version manager's file, a project file) is named as the source of each tool's version, and the places that repeat it are listed with it
    • a check in CI reads every listed pin site and fails when a pin differs from the source, names no version, or is gone
    • a deliberate exception (a canary on the next release) is registered with a reason, and the check fails an exception that excuses nothing
  5. Every generator that selects its inputs by a list it maintains has a CI check that the set it reads equals the set of inputs that exist, reporting an unreached input and a listed input that no longer exists.
    generator-reaches-every-inputWhat the audit looks for (3)
    • for each generator with a maintained input list (stubs, includes, a roster), a check enumerates the inputs that exist and the inputs the generator reads and fails on any difference
    • the check runs under a required check, beside the artifact's freshness check or as part of its inventory entry's `check`
    • the check fails closed when either enumeration cannot be read or finds nothing
  6. A contract artifact that disagrees with its source is regenerated, never edited to match; each link of a chain of derived files has its own drift check; a structured artifact's drift check compares parsed data with both sides normalized identically; and no derived schema is authored twice.
    derivation-one-way-compared-as-dataWhat the audit looks for (3)
    • the hand-edit ban names the source as the place to change and the regenerate command as the only fix; no artifact is both generated and maintained by hand
    • the drift check of each JSON or YAML artifact parses both copies and compares data, naming the differing paths, and any normalization is one function applied to both sides
    • where one derived file feeds another, each link has its own check with its own fresh output

M2 Strict — regulated / compliance posture

derivable prose facts are declared in a registry and CI-checked (commit-nothing); schema-like artifacts use ephemeral replay; every derived file is declared with its outputs, its source, its regenerate command and its check, and every declared check runs through one generic runner in CI, with no per-generator step; a regeneration after a merge goes through a pull request.

What the audit checks at Strict convention-only is enough must be mechanically enforced
  1. Derivable facts stated in prose (counts, rosters) are re-derived and compared by a CI check that commits no generated file.
    prose-facts-ci-checkedWhat the audit looks for (3)
    • a registry declares each fact once, with the source it derives from and the phrasings a stated copy may take
    • CI job re-derives each registered fact and fails when a stated copy, in any registered phrasing, disagrees, and passes when none is stated
    • no generated cache of the derived facts is committed to the repo
  2. Every schema-like committed artifact's drift check replays its source of truth from scratch in a throwaway environment, normalizes both sides identically, and compares.
    schema-artifacts-use-ephemeral-replayWhat the audit looks for (2)
    • drift check spins an ephemeral database/container and applies migrations from zero
    • committed artifact and fresh dump pass through the same normalization before diff
  3. Every derived file is declared once in one inventory, with its outputs, its source, its regenerate command and its check, and CI runs every declared check through one generic runner under a required check, with no per-generator CI step, so a generator cannot ship without its check.
    artifact-inventory-generated-and-gatedWhat the audit looks for (3)
    • one inventory (a standalone file or the change-area catalog's `generated:` entries) declares each derived file's outputs, source, regenerate command and check, each output once
    • one CI step under a required check runs every declared check through a runner that reports every check's result and fails closed on an inventory it cannot read or a check that cannot start
    • no generator's freshness check has a hand-added CI step or workflow of its own (a post-merge regeneration workflow publishes rather than checks, and is not one), and an entry without a check is refused by the inventory's validation
  4. Every derived file regenerated after a merge reaches the protected branch through a pull request on a fixed branch per generator that a person merges, with no CI-skip marker on its branch commit or its merge commit, published with a credential scoped to contents and pull requests.
    regeneration-after-merge-via-pull-requestWhat the audit looks for (3)
    • a workflow on the push to the integration branch, filtered to the generator's inputs and never its outputs, regenerates and publishes through a pull request; no step pushes a generated commit straight to the protected branch
    • the branch name is fixed per generator, so an open pull request is updated rather than duplicated; the job neither merges it nor arms an automatic merge, and overwrites the branch only while every commit on it is the generator's own, with the push leased to the tip it inspected
    • the publish step refuses a branch commit message carrying any of the platform's CI-skip instructions, no merge commit message (subject, body or trailers) carries one, and the step fails before any work when the publishing credential is missing

Adoption steps

  1. Declare every derived file in the repository once, with its outputs, its source, its regenerate command and its check, in one inventory (templates/generated-files.yaml, or the change-area catalog’s generated: entries), and state that derived files are never edited by hand; give each derived file a generated-file header naming its regenerate command, or, where its format cannot carry one (JSON, a vendored file pinned by its hash), say in its inventory entry that it is not edited by hand. This is Lite.
  2. For each derived file, walk the ladder: drop it if no consumer needs it at rest; otherwise give it the full triad (reference/triad/); give each generator that keeps a list of its inputs a coverage check (reference/generator-coverage/) and compare each structured artifact as data (reference/compare-as-data/). Check the paths that instruction files reference with reference/prose-facts/check-referenced-paths.ts; a path that lives in another repository is not this one’s to check, so name that repository with it, as a link to the file there (a URL is never checked) or with the repository as a placeholder prefix (<other-repo>/scripts/update.sh; a placeholder is never checked), rather than moving the text out of the instruction file. State in the instruction file that a number which tallies a list is dropped or registered, and one that constrains stays. Declare each toolchain version’s source and pin sites and run reference/toolchain-pins/ on every change. This is Standard.
  3. Declare the facts prose states in a registry and check them with reference/prose-facts/check-registered-facts.ts, with the tally lint beside it advisory (lint-derivable-counts.ts), replay schema-like artifacts from scratch (reference/ephemeral-replay/), and run every declared check through the one runner (reference/inventory/) as the only generated-file step in CI, and publish any regeneration after a merge through a pull request (templates/regenerate-after-merge.yml). This is Strict.
3 · The mechanicsopen what you need
The decision ladder: drop > check > commitOrdered by preference — materializing a derived file at rest is a liability (it can drift and it merge-conflicts when parallel branches both regenerate it), so:Open

Ordered by preference — materializing a derived file at rest is a liability (it can drift and it merge-conflicts when parallel branches both regenerate it), so:

  1. Drop — generate at build/consume time; never commit the artifact. Choose when no consumer needs the file in the repo.
  2. CI-check without committing — for derivable facts stated in prose (counts, rosters, path references in instruction files): a CI job recomputes the fact and fails on mismatch, but no generated file is committed. Committed generated includes are the tempting alternative, and they fail: every parallel branch that touches their inputs regenerates them, so every merge conflicts on the generated file.
  3. Commit + triad — when consumers genuinely need the artifact at rest (published specs, generated types consumed by builds): regenerate script + drift gate in CI + auto-stage twin in the pre-commit hook, so local commits go out fresh and CI catches everything else.

For schema-like artifacts, the strongest drift check is ephemeral replay: spin a throwaway database/container, replay the source of truth (migrations) from scratch, dump, normalize, and compare — testing the whole chain, not just file timestamps.

One version sourceA toolchain version (the runtime, the compiler, the package manager a repository builds and tests with) is a derived fact with many copies. It is declared once, in the file the…Open

A toolchain version (the runtime, the compiler, the package manager a repository builds and tests with) is a derived fact with many copies. It is declared once, in the file the developers’ version manager reads, and then repeated wherever something installs the tool on its own: a CI setup step, a container build argument, a package-manager field, a type package that tracks the runtime. Each copy is a pin site, and pin sites drift the way every derived copy does: one is left out and floats to the tool’s latest release, which changes on the day the tool releases; one is missed by an upgrade and stays a version behind. Code then runs under one version in CI, another in the container and a third on a laptop, and the difference shows up as a failure nobody can reproduce.

The rule is rung 2 of the ladder applied to a version: one file is the source, every other pin site is gated to equal it, and nothing is generated. A declaration names, per tool, the source and every pin site with how to read each; a gate fails a pin that differs, a site whose pin is gone, and a setup step that names no version at all. A pin that differs on purpose, such as the runtime canary that runs the suites on the tool’s next release, is registered as an exception with a reason, and the exception prunes itself: one that excuses nothing (its value is the source’s now, or no pin holds it) is a finding, as M1 asks of every exception. Version ranges (engines, a minimum in a project file) are not pins and stay out: a range stays true across an upgrade, and the install checks it. reference/toolchain-pins/ is the gate; the sites per ecosystem are in mappings. An upgrade then changes the source and lets the gate list every site to follow; upgrade-deps (ROADMAP item 3) is planned as the runnable form of that upgrade.

The inventory and the one runnerA triad per derived file is not enough on its own: each triad's drift check protects the file only while CI runs it, and when that wiring is one hand-added step per generator, the next…Open

A triad per derived file is not enough on its own: each triad’s drift check protects the file only while CI runs it, and when that wiring is one hand-added step per generator, the next generator ships with a check nobody wired, green until its artifact rots. So the declaration and the wiring are one thing, the generated-file inventory:

  • Every derived file is declared once, with its outputs (the committed files), its source (globs of the files whose change calls for a regeneration), the command that regenerates it and the check that fails when it is stale.
  • CI runs every declared check through one generic runner (reference/inventory/), the only CI step the practice needs. A new generator adds an entry, never a workflow step; an entry without a check does not parse.
  • The runner reports every check’s result, not only the first failure, and fails closed on an inventory it cannot read or a check that cannot start.
  • The inventory validates what it can: each output is a file declared once, each source resolves to a repository file.

The inventory is a standalone file (templates/generated-files.yaml) or, in a repository with a change-area catalog, the generated: entries of the areas that own the files, which the runner reads in the same format. Then the catalog couples each artifact to its area, an area on the shallow validation profile carries this module’s freshness gate without escalating to full code validation, and the regenerate command lives in one place rather than in a hook, a CI step and a paragraph of prose. Jig’s own derived files are declared that way, in its catalog, and bun run gates runs their checks through the runner.

Regeneration after merge goes through a pull requestSome derived files are regenerated after the merge rather than demanded fresh on every pull request: a derivation too heavy to wait for on every change, a reference document the merge…Open

Some derived files are regenerated after the merge rather than demanded fresh on every pull request: a derivation too heavy to wait for on every change, a reference document the merge need not block on. Such a file has no required drift check on pull requests, since that check would fail every pull request that changes its inputs and block the merge the regeneration waits for; the run after the merge is how it stays fresh. Every other derived file keeps its required check, and for those, regeneration after merge is the backstop the per-change check cannot be: two pull requests each fresh on their own are stale together once both have merged, because each regenerated against a branch without the other, and only a run after the merge sees the combined state.

The regenerated commit is a change like any other, and it reaches the protected branch the way every change does: through a pull request that passes the required checks and that a person merges, since the merge is a human act (M7).

  • A direct push cannot, where a required check runs only on pull requests. Required checks are evaluated per commit, and a check that runs only on pull requests never runs for a commit pushed straight to the branch, so a branch that admits a change only with that check green refuses the push every time. That is not a race, and no retry helps. The other design, a branch rule that names one automation as the actor allowed past it, admits the push and runs the checks on it afterwards; that actor must then be the narrowest thing the platform can name, with a credential minted per run, and the module’s reference design remains the pull request.
  • One pull request per generator, on a fixed branch. Each run pushes the fresh content to that branch, opens the pull request if none is open, and returns: it neither merges nor waits for the checks. A pull request that went stale while open is overwritten by the next run; one stuck on a real failure is updated, never duplicated. The branch is overwritten or deleted only while every commit on it is the generator’s own (authored and committed by its bot, so an amended commit is a person’s), and the push that overwrites or deletes it is leased to the tip the run inspected, so a commit a person added to it is never destroyed. A concurrency group on the job serializes the runs of one generator without cancelling one in progress.
  • No commit carries a CI-skip marker. The branch commit carries none of the platform’s skip instructions, or the pull request’s checks would not run on it, and the publish step refuses one before any work. The merge commit carries none either: such a marker suppresses every workflow on the push, integration checks and downstream generators as well as this one. Recursion is prevented instead by the trigger, which lists the generator’s inputs and never its outputs, and by the no-change exit below: a run on the merged output regenerates identical content and opens nothing.
  • A path-filtered trigger has a limit. A platform that evaluates the filter against only part of a large push (GitHub Actions: the first 3,000 changed files) can leave the workflow unstarted after a very large merge. A manual run from the integration branch is the recovery.
  • A credential of its own. The identity that pushes the branch and opens the pull request is not the ambient token: it is minted per run with write to contents and pull requests and nothing else, and its absence fails the run before any work.
  • Only from the integration branch. A manual run started from another branch or tag does nothing, and the pull request’s base is the integration branch as configured, never the ref the run started from: otherwise an unmerged generator runs with the publishing credential.
  • Nothing changed, nothing opened, and a pull request an earlier run left open is closed: what it carries is no longer what the generator produces.

This is the “every push to the integration branch” row of M13’s placement rule: an artifact with a required drift check keeps it on every pull request, and the run after the merge is its backstop. The actions the workflow uses are pinned to immutable revisions (M1, third-party automation integrity), which M13’s workflow-convention lint checks. templates/regenerate-after-merge.yml is the GitHub Actions skeleton; mappings.md gives the steps for other providers.

Generators reach every inputA freshness check proves one thing: the artifact equals what the generator writes. It cannot see an input the generator never reads. A route the application mounts but the spec…Open

A freshness check proves one thing: the artifact equals what the generator writes. It cannot see an input the generator never reads. A route the application mounts but the spec generator does not stub, a migration outside the replay’s list, a module a roster omits: each is absent from the artifact, the artifact is fresh, and nothing fails. So every generator that selects its inputs by a list it maintains has a check that the set it reads equals the set that exists, enumerated from where the inputs live, with both directions reported: an input unreached, and a listed input that no longer exists. A generator that walks its inputs reaches them by construction and needs none. reference/generator-coverage/ compares the two enumerations.

Derivation runs one wayWhen a contract artifact (an API description, a schema file, generated types) disagrees with its source, the artifact is regenerated, never edited to match. A constraint the artifact…Open

When a contract artifact (an API description, a schema file, generated types) disagrees with its source, the artifact is regenerated, never edited to match. A constraint the artifact needs that the source cannot express is added to the source layer, which must be able to emit everything the artifact enforces; otherwise the next regeneration drops the hand-made part. In a chain of derived files, each link has its own check with its own fresh output, since a check over the ends of the chain cannot say which link went stale. A structured artifact is compared as the data it encodes, not as bytes: a formatter’s reflow or a key sort is not drift, and a byte comparison that reports it on every run teaches the team to regenerate without reading the diff, where real drift then hides. Whatever normalization the comparison needs applies to both sides through one function: applied to one side only, every later fix to it looks like drift of every committed artifact. And every derived schema comes from one source: a second generator from the same source is fine, a second artifact maintained by hand beside the generated one is not. reference/compare-as-data/ compares two copies as parsed data and names each difference by its path.

Which numbers in prose may stayA number in prose either constrains its content or describes it, and only the second is a derived file. A number that constrains (a limit, a budget, a retry count, a threshold: ≤ 8000…Open

A number in prose either constrains its content or describes it, and only the second is a derived file. A number that constrains (a limit, a budget, a retry count, a threshold: ≤ 8000 chars, 3 retries) is part of what the text means and stays. A number that tallies an adjacent list (the 6 passes, 120 skills, a count beside the list it counts) is a cache of that list written by hand: it drifts the moment the list changes, it conflicts when two branches change the list, and it tells the reader nothing the list does not. The test is one question: does the number constrain the content, or describe it?

A tally is dropped, letting the list speak, or it earns its place and is registered: declared once in a facts registry with its source (globs over the repository’s files, or a command) and the phrasings a stated copy may take, and re-derived on every run by a check that commits nothing and fails when a stated copy disagrees (reference/prose-facts/). The registry flags drift, never presence: a fact nobody states has nothing to check.

The exact check cannot see a tally nobody registered. An advisory presence lint over all prose finds a number that reads as one (a cardinal before a noun the repository counts), judged by shape, and exempts a constraint in its own clause, a label, an identifier, code, a registered copy and a line carrying the measured marker <!-- measured -->. It is the one carve-out from “flag drift, not presence”: it never blocks, and a finding is a prompt to drop, register or mark. The universal instruction file states the rule (M0’s skeleton) so a reviewer applies it where the lint’s shape test cannot.

In your toolsThe same rule, wired into a specific CI provider, hook manager or tracker. Shows only your stack.Open

The module’s invariant and its drop > check > commit ladder (see README.md) are tool-independent. This file maps each rung’s checks onto concrete CI providers, git hook managers, and container/database stacks. Replace <placeholders> with your repo’s values.

Every command below is a TypeScript script run with Bun: bun <script>.ts. The runner (CI job, hook or container) needs Bun installed at a pinned version first — see the toolchain note in M1’s mappings.

Run the schema replay script from a pinned Jig checkout: it shares the plugin’s retry, clock and trace helpers as well as lib/. A standalone copy must retain those relative dependencies.

CI providers, per rung

RungCheckReference script
2 — CI-check, commit nothingstated-counts drift; referenced-path-existsreference/prose-facts/
2 — registered factseach fact re-derived from its source, every registered phrasing of a stated copy checkedreference/prose-facts/check-registered-facts.ts
2 — unchecked tallies (advisory)a number that reads as a tally with no check behind it; <!-- measured --> exempts a linereference/prose-facts/lint-derivable-counts.ts
3 — commit + triadregenerate-to-temp-and-diff drift gatereference/triad/check-index-fresh.ts
3 (Strict, schema-like)ephemeral replayreference/ephemeral-replay/check-schema-drift.ts
every rung-3 check, one CI stepthe generic runner over the generated-file inventoryreference/inventory/run-generated-checks.ts
3 — generator coveragethe inputs the generator reads equal the inputs that existreference/generator-coverage/check-generator-coverage.ts
3 — structured artifactscommitted copy and fresh output compared as parsed datareference/compare-as-data/compare-as-data.ts
after the mergeregeneration published through a pull request on a fixed branch, merged by a persontemplates/regenerate-after-merge.yml

GitHub Actions

yaml
# Rung 2 — commit-nothing prose checks. Land advisory, promote by deleting
# `continue-on-error` — no script change needed. Add these under any job's
# `steps:` key.
steps:
  - name: Stated-counts drift (advisory)
    run: bun reference/prose-facts/check-stated-counts.ts <instruction-file> <dir> <noun>
    continue-on-error: true
  - name: Referenced paths exist (advisory)
    run: bun reference/prose-facts/check-referenced-paths.ts <instruction-file>
    continue-on-error: true
  - name: Registered facts (advisory)
    run: bun reference/prose-facts/check-registered-facts.ts <facts.yaml> <instruction-file>
    continue-on-error: true
  - name: Unchecked tallies (advisory; stays advisory)
    run: bun reference/prose-facts/lint-derivable-counts.ts --registry <facts.yaml> <prose-file>...
    continue-on-error: true
yaml
# Rung 3 — triad drift gate. Blocking; path-filter to the artifact's inputs.
# .github/workflows/freshness.yml
on:
  pull_request:
    paths: ['<docs-dir>/**/*.md']
jobs:
  freshness:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@<full-commit-sha> # v4
      - run: bun reference/triad/check-index-fresh.ts <docs-dir>
yaml
# Every declared check, one step: the runner reads the inventory (or the
# change-area catalog's `generated:` entries) and runs each entry's `check`.
# A generator added later needs an inventory entry and no change here. Put
# it in the workflow that is a required check.
steps:
  - uses: actions/checkout@<full-commit-sha> # v4
  - run: bun reference/inventory/run-generated-checks.ts <inventory.yaml>
yaml
# Rung 3 Strict — ephemeral replay. A separate workflow, path-filtered to the
# schema's own inputs, so migration/schema changes trigger it even when no
# docs changed (GitHub Actions filters `on.pull_request.paths` per workflow,
# not per job — hence the separate file rather than a second job above).
# Ubuntu runners ship docker.
# .github/workflows/schema-drift.yml
on:
  pull_request:
    paths: ['<migrations-dir>/**', '<schema.sql>']
jobs:
  schema-drift:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@<full-commit-sha> # v4
      - run: bun reference/ephemeral-replay/check-schema-drift.ts <migrations-dir> <schema.sql>

GitLab CI

yaml
# Rung 2 — advisory via allow_failure; promote by deleting that line.
prose-facts:
  script:
    - bun reference/prose-facts/check-stated-counts.ts <instruction-file> <dir> <noun>
    - bun reference/prose-facts/check-referenced-paths.ts <instruction-file>
    - bun reference/prose-facts/check-registered-facts.ts <facts.yaml> <instruction-file>
  allow_failure: true

# The tally lint stays advisory: it judges by shape.
unchecked-tallies:
  script: bun reference/prose-facts/lint-derivable-counts.ts --registry <facts.yaml> <prose-file>...
  allow_failure: true

# Rung 3 — triad drift gate, run only when the inputs changed.
index-freshness:
  script: bun reference/triad/check-index-fresh.ts <docs-dir>
  rules:
    - changes: ['<docs-dir>/**/*.md']

# Every declared check in one job, whatever changed; blocking.
generated-files:
  script: bun reference/inventory/run-generated-checks.ts <inventory.yaml>

# Rung 3 Strict — ephemeral replay via docker-in-docker...
schema-drift:
  image: docker:27
  services: ['docker:27-dind']
  script: bun reference/ephemeral-replay/check-schema-drift.ts <migrations-dir> <schema.sql>

# ...or skip the container entirely with a GitLab service database: replay
# migrations into the `postgres` service with psql, dump with pg_dump, then
# compare through the reference script's normalizeSchema step.

Other providers follow the same shape: any CI that can run a shell script can run all three rungs. The only provider-specific decisions are the advisory mechanism (continue-on-error / allow_failure / equivalent) and how the runner reaches a database (local docker, docker-in-docker, or a provider-managed service container).

Regeneration after merge, through a pull request

The steps are the same on every provider: run on the push to the integration branch, filtered to the generator’s inputs and never its outputs; serialize the generator’s runs; regenerate; when something changed, commit on a fixed branch per generator, push it leased to the tip the run inspected and only while every commit on that branch is the generator’s own, open the pull request if none is open, and stop there: a person merges it. No commit, the branch commit or the merge commit, carries any of the platform’s skip instructions; the inputs-only filter and the no-change exit keep the run from starting itself again. When nothing changed, close a pull request an earlier run left open, deleting its branch under the same lease and ownership check. Where the platform evaluates a path filter against only part of a large push, a manual run is the recovery. A manual run from any ref other than the integration branch does nothing, and the pull request’s base is the integration branch as configured, never the ref the run started from. The credential that pushes and opens the pull request has write to contents and pull requests and nothing else, and its absence fails the run before any work.

ProviderWhere each step lives
GitHub Actionstemplates/regenerate-after-merge.yml: on.push.paths for the inputs; a concurrency group per generator; a GitHub App installation token minted per run (actions/create-github-app-token, pinned) or a fine-grained token in a secret; the branch’s commits checked through gh api repos/:owner/:repo/compare, then git push --force-with-lease and gh pr create on the fixed branch. The path filter sees only the first 3,000 changed files of a push; workflow_dispatch is the recovery
GitLab CIa job with rules: [{ if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH, changes: [<inputs>] }] and resource_group: regenerate-<artifact> to serialize; the branch’s commits checked through the repository compare API, then git push --force-with-lease -o merge_request.create -o merge_request.target=<branch> -o merge_request.remove_source_branch origin <fixed branch> with a project access token that has write_repository; a person merges the merge request. When nothing changed, close the open merge request through the merge request API (glab mr close), which needs a token with the api scope, since write_repository alone cannot close it

Hook managers (rung 3’s auto-stage twin)

The pre-commit hook regenerates the artifact and stages it when its inputs are staged. The hook is a convenience; CI remains the authority.

ManagerAuto-stage wiring
lefthookglob on the inputs; run the generator then git add <artifact>; stage_fixed: true
huskyin .husky/pre-commit: guard with git diff --cached --name-only | grep -q '<inputs-pattern>', then generate + git add <artifact>
pre-commit frameworka local repo: local hook with files: <inputs-pattern> running the generator; it stages nothing itself, but any file the hook modifies fails the commit, and the standard workflow is git add + retry

Lefthook example (the fullest expression — glob filtering, staging, and timeout are all declarative):

yaml
pre-commit:
  commands:
    <artifact>-fresh:
      glob: "<inputs-glob>"
      timeout: 2m
      run: |
        <generate-command>
        git add <artifact-path>
      stage_fixed: true

pre-commit framework example:

yaml
repos:
  - repo: local
    hooks:
      - id: <artifact>-fresh
        name: regenerate <artifact>
        entry: <generate-command>
        language: system
        files: '<inputs-pattern>'
        pass_filenames: false

Container and database variants (ephemeral replay)

StackNotes
docker + PostgresThe reference script. Pin the image to a digest (PG_IMAGE); two-gate readiness (init sentinel, then pg_isready); dump with pg_dump --schema-only --no-owner --no-privileges --no-tablespaces --no-security-labels
podman + PostgresThe script runs a docker executable, so install podman’s docker-compatible command (e.g. the podman-docker package); a shell alias is not enough. Rootless mode avoids CI privilege requirements
CI service containerGitHub Actions services: / GitLab services: start the database for you — replay with a psql client and keep only the script’s normalize-and-compare step
testcontainersSame recipe inside a test framework, when the repo already uses one; readiness and teardown come for free
MySQL/MariaDBDump with mysqldump --no-data; normalize away AUTO_INCREMENT= values, /*! version comments, and the dump-date footer
SQLiteNo container at all: replay migrations into a temp file with sqlite3, dump with .schema, diff. The cheapest full-chain replay there is

Whatever the engine, the invariants hold: replay from zero, pin versions and ordering, normalize both sides identically, and always tear down, even on failure or interrupt.

Toolchain pin sites

reference/toolchain-pins/ takes a declaration of each tool’s one source and its pin sites, each with how to read it: a toml:, json: or yaml: dotted path; a step: naming a CI setup action with the input that holds its version (with:) and the one that names a version file (with-file:), read from the parsed workflow so a comment is no step and a step without its input is caught (a step reading a file agrees only for actions/setup-node and oven-sh/setup-bun, whose own readers the check mirrors, when that reader takes the source’s value from it; any other setup action, and a file the action reads in a way the check does not follow such as mise.toml or global.json, sets its version explicitly); or a pattern: whose first capture group is the version, for files that are text. The rows name the sites a repository commonly has and the reader for each; a declaration lists the sites the repository has and nothing else, because a declared glob that matches no file fails the check. A version range (engines, requires-python, a >= in a project file) is not a pin and is left out.

ToolOne sourcePin sites, with the reader
Bunmise.toml (toml: tools.bun), or .tool-versions (pattern: '^bun (\S+)$')package.json packageManager (json: packageManager with pattern: '^bun@(.+)$'); @types/bun, released with the runtime (json: devDependencies.@types/bun); oven-sh/setup-bun steps (step: oven-sh/setup-bun, with: bun-version, with-file: bun-version-file; a step with neither installs the latest); a Dockerfile (pattern: '^ARG BUN_VERSION=(\S+)$', with FROM oven/bun:${BUN_VERSION} so the image follows the argument)
Node.js.node-version or .nvmrc (pattern: '^v?(\S+)$'), or mise.toml (toml: tools.node)actions/setup-node steps (step: actions/setup-node, with: node-version, with-file: node-version-file); a Dockerfile (pattern: '^FROM node:(\d+\.\d+\.\d+)'); @types/node tracks the major only, so it is a second tool whose source and site are read with a pattern that captures the major
Python.python-version (pattern: '^(\S+)$'), or mise.tomlactions/setup-python steps (step: actions/setup-python, with: python-version, with-file: python-version-file); a Dockerfile (pattern: '^FROM python:(\d+\.\d+\.\d+)')
Gogo.mod (pattern: '^go (\S+)$', and ^toolchain go(\S+)$ where one is set)actions/setup-go steps (step: actions/setup-go, with: go-version, with-file: go-version-file); a Dockerfile (pattern: '^FROM golang:(\S+)')
Rustrust-toolchain.toml (toml: toolchain.channel)dtolnay/rust-toolchain@<channel> steps, whose channel is the action’s @ref and so is read with a pattern anchored at the step (pattern: '^\s*(?:-\s+)?uses: dtolnay/rust-toolchain@(\S+)'); a Dockerfile (pattern: '^FROM rust:(\S+)')
Ruby.ruby-version (pattern: '^(\S+)$')ruby/setup-ruby steps (step: ruby/setup-ruby, with: ruby-version); a Dockerfile (pattern: '^FROM ruby:(\S+)')
JVM.sdkmanrc (pattern: '^java=(\S+)$') or .java-versionactions/setup-java steps (step: actions/setup-java, with: java-version, with-file: java-version-file); a Dockerfile (pattern: '^FROM eclipse-temurin:(\S+)'); a language level in the build file is a different fact from the runtime, so it is its own tool entry if pinned
.NETglobal.json (json: sdk.version)actions/setup-dotnet steps (step: actions/setup-dotnet, with: dotnet-version; global.json is a structured source, so a step reading it through global-json-file is a finding); a Dockerfile (pattern: '^FROM mcr\.microsoft\.com/dotnet/sdk:(\S+)')
pnpm, Yarnpackage.json packageManager (json: packageManager with pattern: '^pnpm@(.+)$')pnpm/action-setup steps (step: pnpm/action-setup, with: version; a step without it reads packageManager, the source, so a repository whose steps all leave it out declares no such site); corepack prepare pnpm@(\S+) in scripts and a Dockerfile

Other CI providers’ files are read with a path or an anchored pattern: a GitLab CI job pins an image (pattern: '^\s*image: oven/bun:(\S+)' in .gitlab-ci.yml), a CircleCI job a docker: image. Where the version manager is mise or asdf, one file is the source for every runtime, with one tool entry per runtime in the declaration. The pin a runtime canary holds (canary, nightly, head, a release candidate) is registered as an exception with that reason.

Source: modules/M2-generated-artifact-freshness/mappings.md

4 · Statuswhat is built, and what is left out on purpose

What this module provides:

  • reference/triad/ — a worked freshness triad: a deterministic index generator, its drift check and a fixture, with the hook and CI wiring.
  • reference/prose-facts/ — the commit-nothing checks: a facts registry checked exactly, the one-fact count check, the referenced-paths check and the advisory lint over unchecked tallies, with the constraint-versus-tally rule, fixtures for each outcome and the self-tests of the registry check and the lint beside them.
  • reference/ephemeral-replay/ — a schema drift check that replays migrations into a throwaway Postgres container with docker, plus the normalization and operational lessons.
  • reference/toolchain-pins/ — the one version source: a gate that reads a declaration of each tool’s source and pin sites and fails a pin that differs, with fixtures and a self-test; Jig runs it on its own pins (bun run pins).
  • reference/inventory/ — the generated-file inventory’s format and the generic runner that runs every declared check, with fixtures for each outcome and its self-test beside it.
  • reference/generator-coverage/ — the check that the inputs a generator reads are the inputs that exist, with fixtures and its self-test beside it.
  • reference/compare-as-data/ — the comparison of a structured artifact with its fresh output as parsed data, each difference named by its path, with fixtures and its self-test beside it.
  • templates/generated-files.yaml — a copyable inventory starter.
  • templates/regenerate-after-merge.yml — the GitHub Actions skeleton that regenerates after a merge and publishes through a pull request a person merges.
  • mappings.md (CI providers, hook managers, container and database variants, toolchain pin sites) and the module’s maturity criteria.

The self-tests for the triad, the one-fact count and referenced-paths checks and the ephemeral-replay reference are in scripts/freshness.test.ts; the toolchain-pins gate’s is beside it. The /jig:fix-ci skill uses this module’s vocabulary when a drift check fails: it finds the regenerate command beside the check and runs it.

Deliberately left out: further triad instances (error-code catalogs, seed data), because they would add domain values without adding mechanism — the worked index example carries the whole pattern. The registry practice an error-code catalog is generated from (one registry, every copy generated, no code minted elsewhere) is M15’s, with neutral values.

Future: a check that every file whose header names a generator is declared in the inventory, so an undeclared derived file is found by its own marker; promoting the tally lint from advisory to blocking, once a repository has run it blocking without teaching its team to add the measured marker by reflex; deciding whether the regeneration criterion admits the named-actor variant (a branch rule that lets one automation push a regenerated commit whose checks then run on the push) or keeps asking for the pull request.