The script walkthrough.sh runs every step of the tutorial babregen step by step as a terminal session, without Quarto or Jupyter. It builds the package mathregen in a temporary git repository, in the stages of the tutorial, and runs the real babregen, pytest and git commands there. The section titles are those of the tutorial, so the two can be read side by side. The exercise sheet has the same commands for typing them yourself.
Run it
You need uv and git. The script is one file of the babregen repository, docs/tutorials/walkthrough.sh. It is also a file of this site:
The example package is not part of babregen. The script clones the repository babregen-examples at the tag babregen-v0.1.0 into its temporary directory and copies the files of each stage from the folder mathregen/ of the clone. uv installs Python 3.13 or later, babregen and pytest from PyPI into the temporary repository, in the versions of the lock file of the example. Nothing outside the temporary directory is changed, and the directory is removed at the end.
The script pauses after every section; Enter continues. A full run takes about a minute. --help prints the head of the script:
code, out = script("--help")print(out)
walkthrough.sh: the tutorial "babregen step by step" (docs/tutorials/step-by-step.qmd),
run in a terminal instead of a Quarto page.
The script builds the package mathregen in a temporary git repository, in the stages of
the tutorial, and runs the real babregen, pytest and git commands there. Every command
is printed after a "$", followed by its output; the commands of babregen, pytest and the
script of the package also print their exit code. The section titles are those of the
tutorial, so the two can be read side by side. The files of each stage are copied from
the folder mathregen/ of the repository babregen-examples, which the script clones at
the tag named in examples_ref below; planted faults exist only in the temporary
repository.
Usage:
walkthrough.sh pause after every section (Enter continues)
walkthrough.sh --no-pause run through without pauses, e.g. as a smoke test
walkthrough.sh --keep keep the temporary directory at the end
Needs uv and git. uv installs Python 3.13 or later, babregen and pytest from PyPI into
the temporary repository, in the versions of the lock file of the example; nothing
outside the temporary directory is changed. Two environment variables:
BABREGEN_EXAMPLES=<path> use this checkout of babregen-examples, do not clone
BABREGEN_SRC=<path> test this checkout of babregen, not the release on PyPI
The model run of the tutorial is not repeated: it needs a local model server, and a
language model is not deterministic. The script reads its archive in
mathregen/regen/runs/ of the examples.
Exit status: 0 if every command ended with the exit code that the tutorial shows, 1 if
one did not, 2 for a wrong option.
A run needs a network connection for the clone and for the packages. With BABREGEN_EXAMPLES set to an existing checkout of babregen-examples, the script does not clone; the checkout is used as it is, without a checkout of the tag.
What it prints
Every command is printed after a $, followed by its output. The commands of babregen, pytest and the script of the package also print their exit code as [exit N]. If that code differs from the one in the tutorial, a line !!! the tutorial shows exit N here follows. A line that starts with # is a note of the script, for example an edit that plants a fault.
Example 1 (One section of a run) This is the section “A unit record, drafted by the tool” of the run that was made when this page was rendered, with babregen 0.1.0. The page cuts a long output, here the drafted record and the explanation of the check ID; the script prints both in full.
excerpt("A unit record, drafted by the tool")
========== A unit record, drafted by the tool ==========
$ babregen new-unit fibonacci --pace fast
wrote regen/units/fibonacci.toml
next: write the intent items and evaluations, then run babregen check
still open (babregen check will report):
regen/units/fibonacci.toml:4: error INTENT01 declares no intent item (a unit without intent cannot be regenerated)
[exit 0]
$ cat regen/units/fibonacci.toml
... (40 lines)
$ babregen check
regen/units/fibonacci.toml:4: error INTENT01 declares no intent item (a unit without intent cannot be regenerated)
regen check: 1 units, 1 errors, 0 warnings
[exit 1]
# What a check ID means:
$ babregen explain INTENT01
INTENT01 (error): a unit record declares no intent item
Wrong, in regen/units/core.calc.toml:
... (14 more lines)
[exit 0]
The run ends with a summary:
========== Summary ==========
Every command ended with the exit code that the tutorial shows.
The exit status is 0 if every command ended with the exit code that the tutorial shows, 1 if one did not, and 2 for an unknown option. The script runs to the end in any case, so every difference is marked.
The sections
Table 1 lists the sections of the script with the commands of babregen that each of them runs (the other commands are uv, pytest, git and tools of the shell). The table is made from the log of the run and from the headings of the tutorial.
Table 1: The sections of the script, the sections of the tutorial that they follow, and the babregen commands of each.
The section “The idea” of the tutorial runs no command and has no counterpart. Two commands are not run: local, which needs a model server, and example, which the tutorial does not use (Commands shows it).
How it differs from the tutorial
The files of each stage are copied from mathregen/ of the clone. The tutorial creates the package with uv init --lib mathregen and uv add --dev pytest ruff babregen; the script prints these commands as a note and runs uv sync with the lock file of the example. Files are shown with cat and sed, and the output is not shortened, so babregen score prints the whole run record. The paths are those of the temporary directory, where the tutorial writes <repo> and <tmp>. The records that the tool drafts carry the date of the run.
The commands that write a record are run as in the tutorial: add-consumer for the undeclared script, new-decision and add-intent for the third function, each with --dry-run first or with a refused name (Write the records).
The model run is not repeated. It needs a local model server such as LM Studio, and a language model is not deterministic (Scoring and regeneration). The script prints the table [generator] of the archived run record, which holds what produced the run, and shows the archive in mathregen/regen/runs/ of the clone. It then judges the archived candidate of fibonacci again, in a clone of the examples:
$ git clone --quiet '<examples>' ../clone && cd ../clone/mathregen
Note: switching to '044b1390883b0d58c385dacd9295c4eaad594b20'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:
git switch -c <new-branch-name>
Or undo this operation with:
git switch -
Turn off this advice by setting config variable advice.detachedHead to false
$ babregen score fibonacci regen/runs/2026-11-28-fibonacci-qwen-qwen3-coder-30b-seed1/fibonacci-2.py --base e1a764a186e2 --out ../../again | tail -n 1
run directory: <tmp>/again
[exit 0]
$ grep '^accepted =' ../../again/run.toml
accepted = true
# The hashes of the bundle, of the replaced module and of the judged candidate, from
# the new record and from the archived one. Every line occurs twice: the records agree.
$ for f in ../../again/run.toml '<examples>/mathregen/regen/runs/2026-11-28-fibonacci-qwen-qwen3-coder-30b-seed1/run.toml'; do sed -n '/^\[inputs\]/,/^\[final\]/p; /^\[final\]/,/^$/p' "$f" | grep -E '^(bundle_sha256|module_sha256|sha256) ='; done | sort | uniq -c
2 bundle_sha256 = "381da6da6b1e4b15474b9c712e2d0ae8c0cc9f4aade6706520e31eb9c1832b02"
2 module_sha256 = "6e0c1414b03418bc64d216dc5d2fe2ba381e7e164f53433aa993abaea9bd3c2b"
2 sha256 = "dc818e6b63a5e5e8eb02c80ed50b18f58a9c21d1b5b9d88d0e21fe5d7552a2a5"
As a smoke test
walkthrough.sh --no-pause exits with 1 if a command of the tutorial ended with another exit code. With BABREGEN_SRC set to a checkout of babregen, the script installs that checkout into the temporary repository in place of the release on PyPI. Run in the root of a babregen checkout,
tests that checkout against the tutorial before a release. A render of this page does the same: it runs the script against the checkout and stops if the exit status is not 0.