formwork

module
v0.24.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2026 License: Apache-2.0

README

formwork

License

A generic guardrails engine for repositories: one Go binary that evaluates lockdown rules declared in tracked YAML (.formwork/), replacing fleets of shell "gate" scripts (grep/awk/perl checks wired into git hooks and CI).

Why

Repos accumulate guardrail scripts — forbidden patterns, required anchors, cross-file consistency checks — each one a separate process that re-walks the tree, with its own quoting bugs and platform hazards. Formwork replaces them with:

  • One engine, one scan. All fast rules evaluate against a single shared filesystem scan; each file is read once.
  • Rules as reviewable config. Guardrails are declared in YAML, tracked in the adopting repo, and strictly validated (unknown fields are errors).
  • Built-in self-testing. Rules ship with fixtures (formwork test) and the system audits its own integrity (formwork lint) — escape hatches and exemptions are always enumerated, never silent.
  • Operator-tuned ignores. If tooling creates checkouts or noisy trees inside your repo (agent-harness worktrees under .claude/worktrees/, vendored source, generated output), declare them once in formwork.yaml — scan.ignore takes doublestar globs, each with a mandatory reason, and formwork lint enumerates every entry with its live match count so nothing is hidden silently.
  • Portability. A single static binary; no BSD-grep/bash-3.2 divergence.

The first validating target is a private production repo whose 533 check-*.sh gate scripts define the parity benchmark: v1 is done when all of them run under formwork with equivalent firing behaviour.

Install

Releases ship four static tarballs (linux/darwin x amd64/arm64) plus checksums.txt. There is nothing to build and no runtime to install.

VERSION=0.3.0        # pick a release and write the number down
OS=$(uname -s | tr '[:upper:]' '[:lower:]')          # linux | darwin
ARCH=$(uname -m | sed 's/x86_64/amd64/; s/aarch64/arm64/')

gh release download "v${VERSION}" --repo buildfoundry-nz/formwork \
  --pattern "formwork_${VERSION}_${OS}_${ARCH}.tar.gz" \
  --pattern checksums.txt

shasum -a 256 -c checksums.txt --ignore-missing      # sha256sum -c on Linux
tar xzf "formwork_${VERSION}_${OS}_${ARCH}.tar.gz" formwork

Pin the version and verify the checksum. This binary is about to decide whether your CI passes, and an unpinned gate that silently changes semantics is worse than no gate. Then declare the same floor in formwork.yaml so a mismatched binary refuses to run instead of evaluating with unknown semantics:

engine: ">= 0.3.0"

docs/quickstart.md has the resolve-the-latest-release variant and the reasoning.

Usage

formwork check     # evaluate all rules; exit 0 pass, 1 violations, 2 error
formwork check-content --path src/a.go < src/a.go  # eligible file-local rules only
formwork check-content --batch < records.jsonl      # one {path, content} per line
formwork serve --mcp                                # MCP check_file over stdio
formwork test      # run every rule against its fixtures
formwork lint      # self-integrity checks over the config itself
formwork rules-for <path>...   # which rules govern these paths
formwork explain <rule-id>     # one rule in full
formwork list rules|lanes|types|preprocessors
formwork version

check-content reads the supplied bytes, not the path's disk contents, and emits one versioned JSON object. Tree-dependent rules are explicitly deferred; zero eligible rules is reported differently from eligible rules passing. It is a single-file verdict, not a repository-wide green. With --batch, stdin and stdout are newline-delimited JSON: one strict {path, content} input object and one independent schema-1 result per line. Configuration loads once for the whole batch; empty or malformed input is exit 2.

serve --mcp exposes the same evaluator as MCP check_file. Supply complete unsaved content, or omit it to read the on-disk file. The structured response uses the check-content schema. See MCP check_file.

This repo self-hosts: its own rules live in .formwork/.

The exit codes are the contract worth wiring correctly: 1 means your repo has violations, 2 means the engine never got far enough to say. Collapsing them (formwork check || true) discards the difference between "clean" and "never ran".

Getting started

docs/reference.md is the operator reference: every rule type and its parameters, every preprocessor, the formwork.yaml schema, the exemption grammar, and the exit-code contract. Its type and preprocessor lists are checked against the binary's registries by a test, so it cannot fall behind the engine silently.

docs/rule-authoring.md is the judgement layer above the reference: which rules are worth writing, how a corpus rots, and for each practice either the formwork lint check that enforces it or a plain statement that it is judgement with no enforcer.

docs/quickstart.md walks from nothing to a working guardrail — install, first rule, fixtures that prove it fires, a pre-commit hook and a CI lane — in about twenty minutes. examples/quickstart/ is the finished version: five rules, each commented to introduce one concept.

stdlib/generic/ is the portable hygiene pack — Go/Dart/SQL rules that are not product-specific. Opt in with library: [generic] in .formwork/formwork.yaml (requires engine: ">= 0.6.0"). Local rules override pack rules by id.

Development

make test     # full suite with race detector
make build    # build ./formwork
make check    # self-host check of this repo
make verify   # the full gate CI runs: unit tests, vet, gofmt, the self-host
              # check, every rule against its fixtures, config self-integrity,
              # and the end-to-end proofs

make help lists every target with its one-line description. It reads the Makefile, so unlike a list written out here it cannot fall behind what verify actually depends on.

The approved design lives in docs/specs/2026-07-09-formwork-design.md — read it before changing architecture, config schema, rule types, or the CLI surface. Development is strictly test-first; the non-negotiables are in CONTRIBUTING.md.

Project policies

  • CONTRIBUTING.md — how work enters the repo, and the non-negotiables (test-first, the exit-code contract, the fail-open defect class, the fixture obligation).
  • SECURITY.md — private vulnerability reporting, and the threat model. Worth reading before adopting: command: rules execute programs declared in tracked config, so .formwork/ carries the same power as your CI workflow definitions.
  • VERSIONING.md — what counts as API (config schema, rule vocabulary, exit codes, JSON output) and what 0.x means for each. Pin the binary and declare engine:.

Status

0.x — see VERSIONING.md. The engine and the exit-code contract are stable; the rule-type vocabulary is still growing as real corpora demand new types, and that is the surface most likely to move under you.

License

Apache License 2.0 — see LICENSE. Binary distributions embed third-party work (notably libpg_query and its PostgreSQL-derived code, via wasilibs/go-pgquery); attributions are in NOTICE.

Directories

Path Synopsis
cmd
assert-trusted-stamp command
Command assert-trusted-stamp asserts the GoReleaser-built binary in dist/ is version-stamped and TRUSTED.
Command assert-trusted-stamp asserts the GoReleaser-built binary in dist/ is version-stamped and TRUSTED.
formwork command
Command formwork evaluates repository guardrail rules defined in .formwork/ YAML configuration.
Command formwork evaluates repository guardrail rules defined in .formwork/ YAML configuration.
formwork-anchor-census command
formwork-anchor-census — no `go/per-func-count-relation` arm may go unanchored: it must declare either the funcs it applies to or the side of the relation that constrains.
formwork-anchor-census — no `go/per-func-count-relation` arm may go unanchored: it must declare either the funcs it applies to or the side of the relation that constrains.
formwork-arm-census command
embedded.go — the fourth way a rule ARM can be written so that it cannot fail: a `required-pattern` whose pattern is a SUBSTRING of a longer identifier that already appears in its own scope.
embedded.go — the fourth way a rule ARM can be written so that it cannot fail: a `required-pattern` whose pattern is a SUBSTRING of a longer identifier that already appears in its own scope.
formwork-pair-unit-census command
formwork-pair-unit-census — the count-blindness census for pair-consistency arms (#12249).
formwork-pair-unit-census — the count-blindness census for pair-consistency arms (#12249).
formwork-subject-census command
formwork-subject-census — a name-anchored rule must still be able to SEE its subject.
formwork-subject-census — a name-anchored rule must still be able to SEE its subject.
formwork-universal-cure-census command
formwork-universal-cure-census — ratchet R3: no rule arm may pair an EXISTENTIAL detector with a UNIVERSAL cure.
formwork-universal-cure-census — ratchet R3: no rule arm may pair an EXISTENTIAL detector with a UNIVERSAL cure.
formwork-vacuity-census command
Corpus-independent calibration for the class-2 verdict probes (#15917).
Corpus-independent calibration for the class-2 verdict probes (#15917).
Package corpus is the public API for analysing a formwork rule corpus.
Package corpus is the public API for analysing a formwork rule corpus.
internal
census
Package census holds the shape and the bookkeeping every rule-corpus census shares.
Package census holds the shape and the bookkeeping every rule-corpus census shares.
cli
Package cli wires config, scan, engine, and report behind the formwork command surface and owns the exit-code contract (spec §6).
Package cli wires config, scan, engine, and report behind the formwork command surface and owns the exit-code contract (spec §6).
config
Package config loads .formwork/ YAML strictly and compiles rule envelopes into executable rules (spec §5).
Package config loads .formwork/ YAML strictly and compiles rule envelopes into executable rules (spec §5).
cputime
Package cputime is the single seam through which rule code runs work off its calling thread while retaining per-rule CPU attribution.
Package cputime is the single seam through which rule code runs work off its calling thread while retaining per-rule CPU attribution.
declspan
Package declspan answers one question: which lines does the declaration that a given line opens span?
Package declspan answers one question: which lines does the declaration that a given line opens span?
engine
Package engine runs compiled rules over a FileSet: phase 1 fans files out to a worker pool, phase 2 fans finalizers out to a second one (spec §6).
Package engine runs compiled rules over a FileSet: phase 1 fans files out to a worker pool, phase 2 fans finalizers out to a second one (spec §6).
finding
Package finding defines the result type every rule evaluation produces.
Package finding defines the result type every rule evaluation produces.
fixturetest
Package fixturetest runs each rule against its fire/pass fixture trees and asserts findings match declared expectations exactly (spec §7).
Package fixturetest runs each rule against its fire/pass fixture trees and asserts findings match declared expectations exactly (spec §7).
hooks
Hook wiring that is not formwork's.
Hook wiring that is not formwork's.
meta
census.go — the escape-hatch enumeration (spec §9).
census.go — the escape-hatch enumeration (spec §9).
preprocess
Package preprocess provides line-preserving content transforms that rules select via the envelope's preprocess: param (spec §5, §6; phase-3a design §1).
Package preprocess provides line-preserving content transforms that rules select via the envelope's preprocess: param (spec §5, §6; phase-3a design §1).
repoproof
Package repoproof holds gates over this repository's OWN tooling — the Makefile's verdict handling, the clone harness's refusals, the installed git hooks — as Go tests rather than shell scripts.
Package repoproof holds gates over this repository's OWN tooling — the Makefile's verdict handling, the clone harness's refusals, the installed git hooks — as Go tests rather than shell scripts.
report
Package report renders findings.
Package report renders findings.
rules
Package rules defines the checker contract and the registry mapping YAML `type:` strings to implementations (spec §4).
Package rules defines the checker contract and the registry mapping YAML `type:` strings to implementations (spec §4).
rules/baseline
Package baseline implements the `baseline` rule type (spec §5): it extracts a set of values from the in-scope files and compares that set to a tracked baseline file.
Package baseline implements the `baseline` rule type (spec §5): it extracts a set of values from the in-scope files and compares that set to a tracked baseline file.
rules/binarycontent
Package binarycontent implements the `binary-content` rule type (spec §5): a per-file guard against oversized or binary blobs in tracked files.
Package binarycontent implements the `binary-content` rule type (spec §5): a per-file guard against oversized or binary blobs in tracked files.
rules/command
Package command implements the `command` rule type (spec §5): the interim escape hatch for toolchain gates that cannot be expressed declaratively.
Package command implements the `command` rule type (spec §5): the interim escape hatch for toolchain gates that cannot be expressed declaratively.
rules/dartscan
Package dartscan implements heuristic analyzers for Dart source.
Package dartscan implements heuristic analyzers for Dart source.
rules/docpathexists
Package docpathexists implements the `doc-path-exists` rule type (spec §5): repo-relative paths cited in docs and comments must exist on disk.
Package docpathexists implements the `doc-path-exists` rule type (spec §5): repo-relative paths cited in docs and comments must exist on disk.
rules/filenaming
Package filenaming implements the `file-naming` rule type (spec §5): naming constraints over in-scope file paths (never their content).
Package filenaming implements the `file-naming` rule type (spec §5): naming constraints over in-scope file paths (never their content).
rules/filesize
Package filesize implements the `file-size` rule type: per-file line-count caps.
Package filesize implements the `file-size` rule type: per-file line-count caps.
rules/gitdiff
Package gitdiff implements the `git-diff` rule type (spec §5): assertions over the added/removed lines of a git range — "no new X", "don't delete Y".
Package gitdiff implements the `git-diff` rule type (spec §5): assertions over the added/removed lines of a git range — "no new X", "don't delete Y".
rules/goast
Package goast implements the built-in Go-AST analyzer rule types (spec §4, phase 4).
Package goast implements the built-in Go-AST analyzer rule types (spec §4, phase 4).
rules/gotypes
Package gotypes is the go/types rule family: rules that resolve what a Go name refers to, which the syntax-only go/* family cannot.
Package gotypes is the go/types rule family: rules that resolve what a Go name refers to, which the syntax-only go/* family cannot.
rules/ordering
Package ordering implements the `ordering` rule type (spec §5): within each file, a `before` pattern must precede an `after` pattern.
Package ordering implements the `ordering` rule type (spec §5): within each file, a `before` pattern must precede an `after` pattern.
rules/pairconsistency
Package pairconsistency implements the `pair-consistency` rule type (spec §5): a `trigger` match obliges a `requires` match within the same UNIT.
Package pairconsistency implements the `pair-consistency` rule type (spec §5): a `trigger` match obliges a `requires` match within the same UNIT.
rules/pattern
Package pattern implements the line-oriented pattern rule types (spec §5: forbidden-pattern, required-pattern).
Package pattern implements the line-oriented pattern rule types (spec §5: forbidden-pattern, required-pattern).
rules/patterncount
Package patterncount implements the `pattern-count` rule type (spec §5): a whole-scope assertion on how many lines match a regex across the in-scope file set.
Package patterncount implements the `pattern-count` rule type (spec §5): a whole-scope assertion on how many lines match a regex across the in-scope file set.
rules/setrelation
Package setrelation implements the `set-relation` rule type (spec §5): a cross-file join that extracts a string set from each of two file groups and asserts a relation (subset, equal, disjoint) between them.
Package setrelation implements the `set-relation` rule type (spec §5): a cross-file join that extracts a string set from each of two file groups and asserts a relation (subset, equal, disjoint) between them.
rules/sqlparse
Package sqlparse implements the parse-tree-backed SQL rule types (sql/parses, sql/locking-select-order).
Package sqlparse implements the parse-tree-backed SQL rule types (sql/parses, sql/locking-select-order).
rules/sqltext
Package sqltext implements the `sql/statement-predicate` rule type: a predicate over individual SQL statements, sourced both from `.sql` files (used verbatim) and from SQL embedded in Go string literals (`.go` files, reassembled heuristically — see sqlextract).
Package sqltext implements the `sql/statement-predicate` rule type: a predicate over individual SQL statements, sourced both from `.sql` files (used verbatim) and from SQL embedded in Go string literals (`.go` files, reassembled heuristically — see sqlextract).
scan
restrict.go — the file-set intersection: which walked files are the ones a caller's path list named, including where the two spell the same filename with different bytes (#98).
restrict.go — the file-set intersection: which walked files are the ones a caller's path list named, including where the two spell the same filename with different bytes (#98).
sqlextract
Package sqlextract reassembles SQL held in Go string literals and reports the compositions it could not reassemble.
Package sqlextract reassembles SQL held in Go string literals and reports the compositions it could not reassemble.
vacuity
Package vacuity judges whether a PASS fixture could ever have failed its rule.
Package vacuity judges whether a PASS fixture could ever have failed its rule.
vcs
The guard that belongs to FORMWORK_GIT_ENV=inherit itself.
The guard that belongs to FORMWORK_GIT_ENV=inherit itself.
vcs/gitseal
Package gitseal seals a test binary's process environment against the developer's ambient git configuration.
Package gitseal seals a test binary's process environment against the developer's ambient git configuration.
Package stdlib is the versioned generic rule packs shipped with the binary.
Package stdlib is the versioned generic rule packs shipped with the binary.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL