Skip to main content

babregen

Regenerative Software tooling, version 0.3.1

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.lock
uv 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 subprocess
import sys
import tempfile
from pathlib import Path

from babregen import make_sample_repo

tmp = 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()))
['docs/guide.qmd', 'pytest.ini', 'regen/architecture.toml', 'regen/decisions/why-add.toml', 'regen/units/core.calc.toml', 'src/samplepkg/__init__.py', 'src/samplepkg/app/__init__.py', 'src/samplepkg/app/main.py', 'src/samplepkg/core/__init__.py', 'src/samplepkg/core/calc.py', 'tests/test_regen_eval_calc.py']

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")
$ babregen check
regen check: 1 units, 0 errors, 0 warnings
[exit 0]

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:

(root / "scripts").mkdir()
(root / "scripts" / "use_it.py").write_text("from samplepkg.core import calc\n")
babregen("check")
$ 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:

babregen("add-consumer", "core.calc", "scripts/use_it.py", "--note", "example script")
babregen("check")
$ babregen add-consumer core.calc scripts/use_it.py --note example script
wrote regen/units/core.calc.toml
next: run babregen check
[exit 0]
$ babregen check
regen check: 1 units, 0 errors, 0 warnings
[exit 0]

The check tutorial walks through this; the schema page describes the regen/ files and lists every check ID.

Where to go next

you want to read
write the regen/ files Schema and check IDs, Editor support
see every command with an example Commands
learn babregen from an empty directory to a regenerated module babregen step by step, with its exercise sheet and the same steps in a terminal
learn the commands on a live repository the tutorials
move records written for spotregen 0.15 Coming from spotregen
judge a candidate, or regenerate a unit with a local model Scoring and regeneration
use the functions from Python the API reference

Design

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.