Metadata-Version: 2.4
Name: babregen
Version: 0.2.0
Summary: Regenerative Software tooling, the successor of spotregen: check intent, evaluations and provenance of regenerable units, and drive regeneration
Author: bartzbeielstein
Author-email: bartzbeielstein <32470350+bartzbeielstein@users.noreply.github.com>
License-Expression: AGPL-3.0-or-later
License-File: LICENSES/AGPL-3.0-or-later.txt
Classifier: Development Status :: 3 - Alpha
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Software Development :: Quality Assurance
Requires-Python: >=3.13
Project-URL: Documentation, https://advm1.gm.fh-koeln.de/~bartz/babregen/
Project-URL: Repository, https://gitlab.git.nrw/thomas.bartz-beielstein/babregen
Project-URL: Issues, https://gitlab.git.nrw/thomas.bartz-beielstein/babregen/-/issues
Description-Content-Type: text/markdown

# babregen

babregen checks the knowledge about a Python package, kept as TOML records in a tracked
`regen/` tree, against the source tree, and regenerates a module from that knowledge. It is
the successor of spotregen: version 0.0.1 starts from spotregen 0.15.0, and spotregen gets
no further release.

The idea is Chad Fowler's Regenerative Software: code is disposable, the knowledge around it
is the asset. A module is safely replaceable when it can be deleted and rebuilt from
knowledge that lives outside its implementation.

* Standard library only: zero runtime dependencies, Python 3.13 or later.
* It never imports the modules it describes; it reads the source with `ast`.
* A deterministic static check, `babregen check`, for CI and `make guard`, with text or
  JSON output.
* Commands that write records without rewriting them, `explain` and `example` that teach
  the format, reports, measures, a judge for a candidate module and one driver for a local
  model.

## Install

```bash
pip install babregen
```

or, as a development dependency of a project:

```bash
uv add --dev babregen
```

`babregen --version` prints the version; `python -m babregen` works as well.

## The first records in ten minutes

In a project with `src/acme/util.py` and an evaluation in `tests/test_regen_eval_util.py`,
write the architecture record once (`babregen example architecture` prints a model), then let
the commands write the rest:

```bash
babregen new-unit util --pace fast
babregen new-decision why-clamp --title "Values are clamped in one place" \
    --driver "Three modules had their own copy of the range check." \
    --decision "acme.util.clamp is the only place that limits a value." \
    --approved-by maintainer
babregen add-intent util --scope clamp --invariant "clamp(v, lo, hi) lies between lo and hi" \
    --reason "Callers use the result as an index." \
    --evaluation test_clamp_limits_the_value --decision why-clamp
babregen check
```

A finding names the file, the line and, when one exists, the name you probably meant, and
`babregen explain ID` says what an ID means. Prose in a record is wrapped over several lines
and needs no backslash. The complete walk-through, with a project that you build and a
sample repository that you break and repair, is the
[Quickstart](https://gitlab.git.nrw/thomas.bartz-beielstein/babregen/-/blob/main/QUICKSTART.md).

## Commands

```bash
babregen check [--strict] [--format json]  # the static check: exit 1 on errors
babregen deletion-test UNIT          # blast radius and knowledge gaps
babregen context UNIT [-o FILE]      # regeneration bundle, no bodies
babregen compact                     # compaction candidates
babregen measures                    # pace, intent coverage and specification size
babregen mutate UNIT [--out FILE]    # mutation score: planted mutants
babregen new-unit MODULE --pace P [--dry-run]
babregen new-decision ID --title T --driver T --decision T --approved-by NAME [--dry-run]
babregen add-intent UNIT --scope T --invariant T --reason T [--evaluation NAME]... [--dry-run]
babregen add-consumer UNIT REF [--kind K] [--note T] [--dry-run]
babregen explain ID                  # what a check means: a wrong and a right fragment, the fix
babregen example KIND                # one complete, commented record of a kind
babregen schema KIND [-o FILE]       # JSON Schema of architecture, unit or decision, for editors
babregen score UNIT FILE [--base REV] # judge a candidate module: evaluations, unit tests, dependents
babregen local UNIT --model M --model-sha256 HEX --context-length N --protocol ID [...]
                                      # regenerate with a local LM Studio model
babregen coding start DIR RUN...     # code why rejected runs were rejected: steps start,
babregen coding check DIR [RUN]      #   check, page and intake; the rater answers on an
babregen coding page DIR             #   two offline pages: own answer, then final answer
babregen coding intake DIR FILE
babregen gate start DIR REPORT...    # rate the surviving mutants with a sealed plant: steps start,
babregen gate assign DIR             #   assign, seal, page, intake and check, on three
babregen gate seal DIR               #   offline pages
babregen gate page DIR
babregen gate intake DIR FILE
babregen gate check DIR
```

`--root DIR` selects the repository (default: search upwards for
`regen/architecture.toml`). A repository carries:

* `regen/architecture.toml`: the compilation target (allowed imports, accepted
  cycles, pace policy, conventions, scan directories).
* `regen/units/<stem>.toml`: one regenerable unit with intent, evaluations and
  consumers. The unit is `<package>.<stem>` and the module path follows from the name.
* `regen/decisions/<id>.toml`: provenance records.

`coding` and `gate` are the two human steps of a study; see [The two human
steps](docs/review.qmd).

`score`, `local` and `mutate` need a git repository with a commit; the project (the folder
with `regen/`) may be the repository itself or a subfolder of it.

A command that writes a record only creates a file or appends one complete block; it never
rewrites existing text, checks the result with the strict loader first, prompts for nothing
and has `--dry-run`. The loaders are strict: a key outside the schema stops the tool with
exit code 2.

## The seven primitives

The tool presents Fowler's seven primitives. Each has a record artefact, a family of check
IDs named after it, and a command that a reader can run. A test reads the IDs from the
table of checks, so this table cannot go stale.

| primitive | record artefact | IDs | command |
|:--|:--|:--|:--|
| intent | `[[intent]]` of `regen/units/<stem>.toml` | `INTENT01`–`INTENT02` | `context` (section Intent) |
| compilation | `regen/architecture.toml`; unit `public` and `depends_on` | `COMPILE01`–`COMPILE08` | `check` |
| evaluation | evaluation files; unit `evaluations`, item `evaluations` | `EVAL01`–`EVAL05` | `mutate`, `score` |
| provenance | `regen/decisions/<id>.toml`; `regen/runs/*/run.toml` | `PROV01`–`PROV10` | `context` (section Provenance), `check` |
| pace | unit `pace`; `[pace]` of `architecture.toml` | `PACE01`–`PACE04` | `measures` (column pace), `context` (the policy of the pace) |
| deletion | `[[consumers]]` of a unit | `DELETE01`–`DELETE03` | `deletion-test`, `score`, `local` |
| compaction | `known_cycles`; decision `status` | `COMPACT01`–`COMPACT07` | `compact` |

## Documentation and links

* Documentation: <https://advm1.gm.fh-koeln.de/~bartz/babregen/>, with
  [every command](https://advm1.gm.fh-koeln.de/~bartz/babregen/docs/commands.html), the
  [schema, the check IDs and the stability contract](https://advm1.gm.fh-koeln.de/~bartz/babregen/docs/schema.html#sec-stability),
  [editor support](https://advm1.gm.fh-koeln.de/~bartz/babregen/docs/editor.html) and the
  tutorials.
* Records written for spotregen 0.15:
  [Coming from spotregen](https://advm1.gm.fh-koeln.de/~bartz/babregen/docs/spotregen.html).
* Example project, `mathregen`, to clone and run:
  <https://gitlab.git.nrw/thomas.bartz-beielstein/babregen-examples>.
* Design: [ADR 0001](https://gitlab.git.nrw/thomas.bartz-beielstein/babregen/-/blob/main/docs/adr/0001-babregen-package.md);
  for what it carries over, the
  [ADRs of spotregen 0.15.0](https://git-ce.rwth-aachen.de/thomas.bartz-beielstein/spotregen/-/tree/v0.15.0/docs/adr).
* Source and issues: <https://gitlab.git.nrw/thomas.bartz-beielstein/babregen>.

## Develop

```bash
make sync && make test-fast     # environment and fast tests
make verify                     # guard + lint + test + doc, the pre-release verification
```

See [CONTRIBUTING.md](https://gitlab.git.nrw/thomas.bartz-beielstein/babregen/-/blob/main/CONTRIBUTING.md)
and [RELEASING.md](https://gitlab.git.nrw/thomas.bartz-beielstein/babregen/-/blob/main/RELEASING.md).

## License

AGPL-3.0-or-later.
