Skip to content

feat(nix): guardrails capability module — the org's semantic gates - #1495

Merged
c-vigo merged 1 commit into
devfrom
feature/1488-guardrails-module
Aug 13, 2026
Merged

c-vigo merged 1 commit into
devfrom
feature/1488-guardrails-module

Conversation

@gerchowl

Copy link
Copy Markdown
Contributor

Implements #1488 with the layer decision from #1492. Closes the guardrails half of #1400.

What lands

devkit shipped 26 hooks to consumers and every one was syntactic — formatting, whitespace, YAML validity, typos, commit-message shape. Useful, and not one of them can tell you the code does what it says. Every semantic gate the org relies on lived in gerchowl/guardrails, a personal repo that both devkit consumers and filesender depended on.

Those 15 gates are now devkit's:

no-fake-impl · no-hardcoded · no-commented-code · no-debug-leftovers · no-raw-trace-fields · derived-docs · duplication · ci-shim · protect-trunk · protect-trunk-push · adr-matrix · numerical-obligation · no-conflict-markers · perf-budget · perf-record

plus the guardrails CLI, the guardrails-trace per-hook JSONL wrapper, and the freshness/stale/ledger tools — 25 executables, matching upstream exactly.

Packages only — no contract change

#1488 originally proposed a v2 hooks field. That was wrong, and #1492 settled why with four independent reviews.

.pre-commit-config.yaml is read by the runner from a bare git working tree, by CI containers that never enter nix develop, and by humans reading a PR diff. Its lifecycle is the scaffold's, not the shell's. Every consumer today owns a committed config, and the generated path refuses to overwrite it — so flake-contributed entries would be silently discarded, or discarded with a warning on every shell entry.

It is closed at the tool level too, independently confirmed: neither prek nor pre-commit has include/extends (pre-commit#1203: "multiple configs / inclusion is not going to be implemented, sorry"), one repo: stanza cannot pull a hook set, and prek's workspace mode scopes each sub-config to its own directory tree.

So the module does the one thing v1 already allows: puts the gates on PATH. Hook entries stay a scaffold concern.

The canary is the point

checks.guardrails-canary feeds every gate a known-bad fixture and asserts it fires, and a known-good one and asserts it stays quiet — running upstream's own harness against the packaged scripts, not a copy.

Four of this org's eight recorded gate failures were "listed in the config, did not run". A check that reads YAML would have caught none of them. "Protected" has to mean the gate rejected a known-bad input, because that is the only claim config drift cannot counterfeit.

It earned itself during this PR: it caught that the share/ copies the fixtures execute are unwrapped, so their runtime dependencies were absent in the sandbox. One passthru list now feeds both the wrapper and the check, so a dependency added to one cannot be forgotten in the other.

Verified

  • nix flake check green, including the new guardrails-canary and guardrails-shellcheck
  • 67 Python tests, 4 new for this module (registry, gates on PATH, unknown gate, unknown option)
  • Hook drift gate green — both committed YAMLs re-synced to nix/hooks.nix
  • Consumer proof: gerchowl/filesender migrated off the flake input onto modules = [ "guardrails" ]. Six lock nodes removed. All 21 guardrails-ok source annotations, the GUARDRAILS_* env vars and every hook id unchanged. Its just precommit (both stages + nix flake check) and 77 tests green

Decisions worth reviewing

  1. Names kept exactly. guardrails-ok is an annotation living in consumer source (21 sites in one repo). Renaming to match devkit would break every consumer's source for no gain — devkit already ships ruff and typos under upstream ids.
  2. Vendored, not an input. 3,000 lines of dependency-free shell: no lock node, nothing fetched at eval, and the bus-factor problem removed rather than formalised. The upstream repo gets archived (still needs crates/tunables → Rust pack and a decision on tools/).
  3. Shell kept, not ported. Re-decided rather than inherited: shellcheck-clean at -S warning, every gate has a fixture, and the absent set -e is correct (these gates grep; -e would abort on the quiet path). New gates go in Python; port only the stateful ones.
  4. Vendored tree excluded from the style-severity shellcheck hook, with checks.guardrails-shellcheck enforcing error+warning instead. Rewriting 3,000 lines of working, fixture-covered shell for SC2181 is the trade this repo already declined.

Known wart

The shellcheck exclude is shared between the runner config and the scaffold copy, because portableFor's includeAll selects which hooks render, not per-artifact fields. Consumers get a dead ^assets/guardrails/ regex — no behaviour change. Fixing it properly means a runnerYaml override plus a drift-gate update; worth doing, not worth bundling here.

Also in this PR

One real shellcheck error fixed in the vendored tree — a malformed # shellcheck disable=SC2254 -- reason directive that parsed as garbage and therefore disabled nothing. Three typos false positives whitelisted rather than edited into the scripts ([Ss]tatus:, an fnd() helper, and the real word "mis-attributes"). Upstream's templates/ deliberately not vendored — devkit is the scaffolding system.

Blocked on nothing: gerchowl/guardrails is now Apache-2.0 (gerchowl/guardrails#50), same holder as devkit, so the vendored copies need no separate attribution.

devkit shipped 26 hooks to consumers and every one of them was
syntactic: formatting, whitespace, YAML validity, typos, commit-message
shape. Useful, and not one of them can tell you the code does what it
says. Every semantic gate the org relies on lived in a PERSONAL repo
that devkit and filesender both depended on.

These 15 gates are now devkit's. Vendored from gerchowl/guardrails under
Apache-2.0 — the same licence and holder as devkit, deliberately, so the
copies need no separate attribution block. The upstream repo had no
licence at all until gerchowl/guardrails#50; vendoring before that would
have shipped all-rights-reserved files from the repo that enforces
licence policy.

PACKAGES ONLY, NO CONTRACT CHANGE. The obvious design is for this module
to contribute hook ENTRIES too, and #1488 originally proposed exactly
that as a v2 contract field. It was wrong and #1492 settled why:
.pre-commit-config.yaml is read by the runner from a bare git tree, by
CI containers that never enter `nix develop`, and by humans reading a
diff — its lifecycle is the SCAFFOLD's, not the shell's. Flake-side
entries would be silently discarded for every consumer that owns a
committed config, which is all of them. It is closed at the tool level
too: neither prek nor pre-commit has include/extends, one `repo:` stanza
cannot pull a hook set, and prek's workspace mode scopes each sub-config
to its own directory tree.

So the module does the one thing v1 already allows — puts the gates on
PATH — and hook entries stay a scaffold concern.

THE CANARY IS THE POINT. checks.guardrails-canary feeds every gate a
known-bad fixture and asserts it fires, plus a known-good one and
asserts it stays quiet, running upstream's own harness against the
PACKAGED scripts rather than a copy. Four of this org's eight recorded
gate failures were "listed in the config, did not run" — a check that
reads YAML would have caught none of them. "Protected" has to mean the
gate rejected a known-bad input, because that is the only claim config
drift cannot counterfeit.

It earned itself immediately: it caught that the share/ copies the
fixtures execute are unwrapped, so their runtime dependencies were not
on PATH in the sandbox. One passthru list now feeds both the wrapper and
the check, so a dependency added to one cannot be forgotten in the other.

Also here: one real shellcheck ERROR fixed in the vendored tree (a
malformed `disable=` directive that silently disabled nothing), three
typos false positives whitelisted rather than edited into the scripts,
and upstream's `templates/` deliberately not vendored — devkit IS the
scaffolding system, and a second unreferenced one would just drift.

KNOWN WART, deliberately not fixed here: the shellcheck exclude is shared
between the runner config and the scaffold copy, because portableFor's
`includeAll` selects WHICH hooks render, not per-artifact fields. So a
consumer's .pre-commit-config.yaml now carries `^assets/guardrails/`,
which means nothing in their repo. It is a dead regex, not a behaviour
change. Fixing it properly means a `runnerYaml` override in hooks.nix
and a drift-gate update — worth doing, not worth bundling into this.

Refs: #1488, #1492
@gerchowl
gerchowl marked this pull request as ready for review August 13, 2026 09:47
@c-vigo
c-vigo merged commit 5fe47d5 into dev Aug 13, 2026
14 checks passed
@c-vigo
c-vigo deleted the feature/1488-guardrails-module branch August 13, 2026 11:20
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