# prompt-evolve — Specification
Formal reference, checked against the code on 2026-11-08. For the idea see [CONCEPTS.md](./CONCEPTS.md).
The pre-release proposal is [docs/proposals/PROMPT-EVOLVE_SPEC.md](../proposals/PROMPT-EVOLVE_SPEC.md)
(historical); the plugin README lists where this implementation is narrower.
## 1. Components
| File | Role |
|---|---|
| `skills/prompt-evolve/SKILL.md` | the two paths and the rewrite-from-failures loop |
| `commands/prompt-evolve-run.md`, `prompt-evolve-report.md` | slash commands |
| `scripts/pevolve.py` | `run` / `score` / `report`, stdlib only, no network, no model calls |
No MCP server and no hook.
## 2. Data model
```
/
├── prompt.tmpl # current template; only a literal {input} placeholder is supported
├── testset.jsonl # {"input": ..., "expected"?: ..., "rubric"?: ...} one per line
├── generations/
│ ├── v1.tmpl v2.tmpl … # every version, kept
│ └── scores.jsonl # {version, avg_score, per_case:[{id,score,note}], failures:[id...]}
└── report.md # generated by `report`
```
## 3. CLI
`python3 scripts/pevolve.py [--dir DIR] {run,score,report} ...`
| Command | Options |
|---|---|
| `run` | `--target`, `--max-iter`, `--threshold`, `--dry-rounds`, `--scorer {exact_match,regex,schema}`, `--force` |
| `score` | `--version N` and `--outputs FILE` (required), `--scorer {exact_match,regex,schema,rubric}`, `--threshold`, `--save-prompt FILE` |
| `report` | - |
`--outputs` is one `{"input": ..., "output": ...}` object per line, in `testset.jsonl` order. Matching is
by position; a count mismatch is an error.
## 4. Scorers
| Scorer | Uses | Passes when |
|---|---|---|
| `exact_match` (default) | `expected` | trimmed output equals it |
| `regex` | `rubric` (a pattern) | `re.search(rubric, output)` matches |
| `schema` | `rubric` (a JSON array of key names) | the output parses to an object with every key (not full JSON Schema) |
| `rubric` (`score` only) | the outputs line's `score` (0..1) and `note` | saved as given; a missing or out-of-range score exits 1 |
`run` and `score` share one scoring function.
## 5. Environment
CLI flags win.
| Variable | Default | Meaning |
|---|---|---|
| `PEVOLVE_DIR` | `.` | default `--dir` |
| `PEVOLVE_TARGET` | `0.9` | `run` stops at `avg_score` ≥ target |
| `PEVOLVE_MAX_ITER` | `8` | `run` stops after this many generations |
| `PEVOLVE_THRESHOLD` | `0.8` | per-case pass line for the `failures` list |
| `PEVOLVE_DRY_ROUNDS` | `2` | `run` stops when `best_so_far` has not improved for this many rounds |
## 6. Guarantees
- `run` refuses to overwrite an existing `generations/scores.jsonl` unless `--force`.
- `score` only appends to `scores.jsonl`; `score` and `report` delete nothing.
- A written generation is never removed (except by `run --force`, which starts over at v1).
## 7. Other tools
The skill exports with the script bundled (`npx kktest-dev`, tier "with fallbacks": needs python3).
Slash commands stay Claude Code only.