Chad Fowler’s Regenerative Software treats code as disposable and the system’s knowledge as the asset. A module is safely replaceable when it can be deleted and rebuilt from knowledge that lives outside its implementation, and when the rebuilt module is judged by an oracle that outlives the code. babregen reads that knowledge from a tracked regen/ tree and checks it against the source tree.
babregen is the successor of spotregen 0.15.0; a repository with spotregen records follows Coming from spotregen. The complete example project of the tutorials, mathregen, is in the public repository babregen-examples; the tutorial babregen step by step builds it from an empty directory.
NoteWhat you get
A static check, babregen check, that fails when the knowledge and the code disagree. It is deterministic, belongs in make guard, and prints text or, for CI, --format json.
Writers that create a record or append one block without rewriting existing text: new-unit, new-decision, add-intent and add-consumer. Prose in a record is wrapped over several lines with no backslash (see the schema).
Help while writing: explain ID says what a check means, example KIND prints one complete record, and schema KIND gives an editor the JSON Schema of the records (see Editor support).
Reports: deletion-test, context (the regeneration bundle) and compact.
Measures: measures (intent coverage and specification size) and mutate (mutation score: the evaluations run against planted mutants; slow, never part of make guard). See the tutorial.
score and one driver. babregen score judges a candidate module for a unit by the acceptance rule accept/1; babregen local regenerates a unit with a local model. Neither belongs in make guard, and local is not deterministic (see scoring and regeneration).
The two human steps of a study, coding and gate: a person codes why rejected runs were rejected, and rates surviving mutants with a sealed plant, each on an offline page with files of a fixed format (see The two human steps).
Zero runtime dependencies. The tool uses the standard library only and never imports the modules it describes; it reads source files with ast.
Install
uv add --dev babregen # a development dependency, pinned in uv.lockuv run babregen --help
Python 3.13 or later is required. python -m babregen works as well.
A first check
make_sample_repo writes a minimal, consistent repository: a package samplepkg with two subpackages, one regenerable unit, one decision, one evaluation file and one documentation page. The same repository drives the test suite, the docstring examples and the tutorials.
import subprocessimport sysimport tempfilefrom pathlib import Pathfrom babregen import make_sample_repotmp = tempfile.TemporaryDirectory()root = make_sample_repo(Path(tmp.name) /"demo")print(sorted(str(p.relative_to(root)) for p in root.rglob("*") if p.is_file()))
Run the check in that repository, as you would on the command line:
def babregen(*args):"""Run `babregen` in the sample repository and show the call and its output.""" done = subprocess.run( [sys.executable, "-m", "babregen", *args], cwd=root, capture_output=True, text=True, check=False, )print("$ babregen", *args)print(done.stdout + done.stderr, end="")print(f"[exit {done.returncode}]")babregen("check")
The summary line regen check: N units, E errors, W warnings is stable, and the exit code is 0 when no error was found (with --strict, when no warning was found either). Break something and the check says what and where:
$ babregen check
regen/units/core.calc.toml:1: error DELETE01 scripts/use_it.py depends on the unit but is not a declared consumer
regen check: 1 units, 1 errors, 0 warnings
[exit 1]
A file outside the declared consumers depends on the unit (DELETE01). babregen explain DELETE01 says what that means. The fix is a record, and add-consumer writes it without an editor:
The package and its command line are recorded in ADR 0001. babregen checks itself with its own static check: its regen/ tree is part of the repository.