Metadata-Version: 2.4
Name: loopmath
Version: 0.5.0
Summary: Plan agent workflows, record how they went, and learn from your own Claude Code and Codex logs
Author: loopmath
License-Expression: MIT
Project-URL: Homepage, https://github.com/loopmath/loopmath
Project-URL: Issues, https://github.com/loopmath/loopmath/issues
Project-URL: Repository, https://github.com/loopmath/loopmath.git
Keywords: agents,claude code,codex,cost analysis,developer tools,workflow analysis
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Software Development
Classifier: Topic :: Software Development :: Quality Assurance
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: jsonschema>=4
Requires-Dist: numpy
Requires-Dist: pandas
Requires-Dist: scipy
Provides-Extra: bayes
Requires-Dist: pymc>=5; extra == "bayes"
Requires-Dist: pytensor; extra == "bayes"
Dynamic: license-file

# loopmath

loopmath finds out which change to keep, from as few scored runs as it can.

You have an agent or a pipeline, and a change to it: a new prompt, another model, a higher effort, a new tool. Is the change better, or as good and cheaper? loopmath tells your runner which runs to make, takes each run's score and cost, and stops when it is sure enough, with a verdict: adopt the change, keep what you have, or the best of many. Scores may come late, from several judges, and earlier scores can start it off.

loopmath runs nothing itself. Your runner, your agent or your CI job makes every run and gives every score; loopmath is a command line they call, reading and printing JSON. Everything runs locally. Once a day loopmath asks pypi.org whether a newer loopmath exists; it sends only its version and uploads nothing. `LOOPMATH_NO_UPDATE_CHECK=1` turns the check off, and it is off when `CI` is set. Pages are served on 127.0.0.1 only.

## Install

Python 3.11 or newer.

```sh
pipx install loopmath          # or: uv tool install loopmath, or pip install loopmath in a venv
loopmath self status
```

From a clone of this repository:

```sh
python3 -m venv .venv
.venv/bin/python -m pip install -e .
```

Installing needs the network: pip, pipx and uv download the build backend and the dependencies, from a clone too.

`loopmath self update` says whether a newer loopmath is out and prints the command that upgrades it for how you installed it. loopmath never upgrades itself.

## With a coding agent

```sh
loopmath self skill install
```

It writes one skill, `loopmath`, for Claude Code and Codex. Then ask your agent, for example "check whether the new prompt is better with loopmath". The skill sends the agent to `loopmath guide`, which prints the steps for each thing you want, from the installed loopmath, so they always match its commands:

| Topic | For |
|---|---|
| `check` | is a new config better than the one you run, or as good and cheaper |
| `frontier` | many configs, such as models by efforts: which is best for the goal and the budget |
| `improve` | let a loop propose edits, run them and keep what helps |
| `late-scores` | scores that come hours or days later, several judges, corrections |
| `judges` | which judge to trust, judge studies, forms for a person to score |
| `live` | a real task to do now: which config to do it with |
| `pipeline` | the verdict as a step in a build pipeline |
| `from-scores` | start from earlier scores, or from what someone knows |
| `upgrade` | moving from loopmath 0.4 |
| `files` | every file, line and exit code the topics name |

## The loop

An experiment is a set of tasks, the config you run today (the base), one or more candidates, a goal and a budget, in one input file:

```json
{"id": "prompt-v2",
 "tasks": {"ids": ["t1", "t2", "t3", "t4", "t5", "t6"]},
 "candidates": [{"name": "old", "base": true, "parts": {"prompt": "v1"}},
                {"name": "new", "parts": {"prompt": "v2"}}],
 "goal": {"kind": "best_under_cost", "score": "quality"},
 "scoring": [{"name": "quality", "scale": "fraction"}],
 "budget": {"runs": 24}}
```

Then the loop:

```sh
loopmath experiment define --file experiment.json
loopmath next --experiment prompt-v2 --json        # the runs to make, or wait, or stop with a verdict
loopmath record add rows.jsonl                     # one row for each run your runner made
loopmath score add scores.jsonl                    # scores that came later, when there are any
loopmath next --experiment prompt-v2 --json > answer.json   # again, until it says stop
loopmath next act --did adopt --by ana --answer answer.json # when the user adopts
loopmath describe --experiment prompt-v2
```

Each run that `next` lists has an id to write on its row, so a score that comes later finds its run. The verdict is `adopt`, `keep`, `best` or `undecided`, with how sure it is and what it rests on. `loopmath next --check` says it in the exit status, for a build pipeline. The loop can stop and start at any point: everything it needs is in the log.

[Connecting your own agent runner](docs/integration.md) walks the loop with a made-up runner, its adapter and its loop, start to end.

## The commands

| Group | Holds |
|---|---|
| `loopmath experiment` | `define`, `add`, `list`, `show`: the experiments |
| `loopmath next` | what to do next; `next act` writes what was decided |
| `loopmath record` | `add`, `check`, `repair`: the rows of runs, and the log |
| `loopmath score` | `add` and `show`, and the judge tools: `study`, `fit`, `judges`, `rubric`, `trust`, `steps`, `labels`, `sheet`, `simulate` |
| `loopmath describe` | what the log says so far, with ranges |
| `loopmath prior` | `from-scores`, `state`, `show`, `remove`, `import`, `export`: what is known before the first run |
| `loopmath generate` | `edits`, `grid`, `screen`: candidates from a base and a list of edits |
| `loopmath route` | live work: a config for the task at hand |
| `loopmath guide` | the steps for each thing you want |
| `loopmath ui` | pages |
| `loopmath self` | `status`, `config`, `doctor`, `drill`, `fit`, `import`, `plugins`, `prices`, `rebuild`, `refit`, `skill`, `update` |

Every command in the table takes `--json` and then prints one JSON object whose `schema` names its shape. A plugin's commands print what the plugin says: `harness watch --json`, for one, prints one object per event, one per line, and `harness schema --json` prints a JSON Schema. Exit 0 is done; 1 is a command that parsed but cannot be done, or a line that was refused; 2 is a command line that does not parse, or a name or file that is not there. `loopmath guide files` lists the rest.

## The log and privacy

The log is the record: a folder of JSON lines files, one for each machine that writes, under the root folder (`~/.loopmath`, or `LOOPMATH_HOME`, or `--home`). It holds what your runner recorded: rows, scores, decisions and experiments, and the documents attached to them. A line is never changed; a correction is a new line. The store under the root folder is made from the log, and `loopmath self rebuild` makes it again. Settings in `config.toml` are not in the log, and a rebuild does not bring them back: keep a copy. Do not edit the log by hand.

`loopmath prior export --preview` prints what a shared file of your runs would hold. Only `prior export --out FILE` writes it, and sending it is up to you. For each run the file holds its outcome, score values, dollars and status, and these labels: the names of its scores; the task's type, subtype and features; the workflow, its steps and their roles, artifacts, edges, gates and rescue; and for each setting its name, harness, model id, family and provider, effort and context policy. A label goes in as written when it is a short identifier (letters, digits and `_ . : + -`, at most 64 characters), and as a salted hash when it is not. Preview and export protect the whole slash label with a salted code by default (`--subtypes hash`). With `guess`, short slash labels such as `configs/release.toml` or `tests/unit` can travel as written. With `full`, the entire slash label travels as written, including any private text. Run, task, repository and slate ids and the organization are always salted hashes, salted with a secret made in the root folder at the first preview or export; node and attempt ids are renumbered (`n1`, `a1`). Left out: experiment names, candidate names and parts, titles, options (which hold commands and flags), run times and any other free text. A private model, workflow or step name that looks like an identifier travels as written.

## Moving from 0.4

```sh
loopmath self import --from ~/.loopmath
loopmath self skill install
```

The import reads the root folder of 0.4 and writes what it holds to the log; it changes nothing there. `loopmath guide upgrade` maps each command of 0.4 to its place in 0.5. The commands of 0.4 that read other tools' logs, `adapt`, `graph`, `analyze` and `onboard`, are in the [adapters plugin](plugins/adapters/README.md), under `adapters`, and `ocp migrate` is `ocp-old migrate` in the ocp-old plugin. `loopmath self plugins list` shows the plugins.

## More

- [Connecting your own agent runner](docs/integration.md): the row, six rules, scores that come later, several runners, and the verdict in a pipeline
- [The log](spec/log.md): every line, how lines are appended, read and linked, and the experiment's input file
- [The row of a run](spec/harness-runs.md)
- [OCP, the run format](spec/OCP.md), and the [versioning promise](spec/VERSIONING.md)
- [Packaged model prices](src/loopmath/prices.toml)
- [Plugins](plugins/README.md): loopmath's own four, and how to write one
- [Changelog](CHANGELOG.md)

## License

MIT.
