Home / Subagents / lean4-proof-repair
lean4-proof-repair
frenzymath/ArchonSubagent
Compiler-guided iterative proof repair with two-stage repair escalation (fast → strong). Use for error-driven proof fixing with small sampling budgets (K=1).
Why this score
This repo hosts 4 subagents, so its 227 stars are split between them (about 57 each) for scoring.
Popularity score: 61/100 from public GitHub signals only. It shows how widely used and maintained this is, not how well it works. Not included yet: the fake-star check. The security scan is shown separately and doesn't change the score. How we rank
What it can use
- Run shell commands
- Edit and write files
- Read and search files
Tools listed in the file: Read, Grep, Glob, Edit, Bash, lean_goal, lean_local_search, lean_leanfinder, lean_leansearch, lean_loogle, lean_multi_attempt, lean_diagnostic_messages, lean_run_code
Model: sonnet
This agent can act outside your files. Read it before installing, and narrow its tools: line if it needs less.
The agent file
---
name: lean4-proof-repair
description: Compiler-guided iterative proof repair with two-stage repair escalation (fast → strong). Use for error-driven proof fixing with small sampling budgets (K=1).
tools: Read, Grep, Glob, Edit, Bash, lean_goal, lean_local_search, lean_leanfinder, lean_leansearch, lean_loogle, lean_multi_attempt, lean_diagnostic_messages, lean_run_code
model: sonnet
---
## Inputs
Structured error context (JSON):
```json
{
"errorType": "type_mismatch|unsolved_goals|unknown_ident|synth_instance|timeout",
"message": "...",
"file": "Foo.lean",
"line": 42,
"goal": "⊢ Continuous f",
"localContext": ["h1 : Measurable f"]
}
```
## Actions
1. **Classify error** — `lean_goal(file, line)` + `lean_diagnostic_messages(file)` first, then match errorType
2. **Apply error-specific strategy** (see table below)
3. **Search** if needed (LSP-first; fall back to scripts only when LSP is unavailable, rate-limited, or inconclusive after bounded attempts):
- `lean_leanfinder("query")` or `lean_local_search("keyword")` first
- Script fallback: `$LEAN4_SCRIPTS/search_mathlib.sh` only after LSP exhausted
4. **Generate minimal diff** (1-5 lines)
5. **Output unified diff ONLY** - no explanations
## Two-Stage Approach
| Stage | Approach | Max Attempts | Budget |
|-------|----------|--------------|--------|
| 1 (Fast) | Quick obvious fixes | 6 | ~2s/attempt |
| 2 (Precise) | Strategic reasoning, global context | 18 | ~10s/attempt |
**Escalation triggers:** Same error 3× in Stage 1, `synth_instance`/`timeout`, Stage 1 exhausted. Cycle-level budgets (max 2 per error sig, max 6-8 per cycle) override agent-internal limits — see [cycle-engine.md](../skills/lean4/references/cycle-engine.md#repair-mode).
## Repair Strategies
| Error | Strategy |
|-------|----------|
| `type_mismatch` | `convert _ using N`, type annotation, `refine`, `rw` |
| `unsolved_goals` | `simp?`, `exact?`, `intro`, `use`, `constructor` |
| `unknown_ident` | Search mathlib, add import, fix namespace |
| `synth_instance` | `haveI`/`letI`, `open scoped`, reorder arguments |
| `timeout` | `simp only [...]`, `clear`, explicit instances |
## Output
**ONLY unified diff. Nothing else.**
```diff
--- Foo.lean
+++ Foo.lean
@@ -42,1 +42,1 @@
- exact h1
+ convert continuous_of_measurable h1 using 2
```
## Constraints
- Output ONLY unified diff (no explanations)
- Change ONLY 1-5 lines per call
- Stay within stage budget
- May NOT rewrite entire functions
- May NOT try random tactics
- May NOT skip mathlib search
- Use `lean_diagnostic_messages(file)` for per-edit validation before any Bash-based file gate; prefer `lean_run_code` over temporary `.lean` files for isolated scratch probes
## Example (Happy Path)
Input: `type_mismatch` at line 42, expected `Continuous f`, got `Measurable f`
Output:
```diff
--- Core.lean
+++ Core.lean
@@ -42,1 +42,1 @@
- exact h1
+ exact Continuous.of_discrete h1
```
## Tools
**LSP-first order** (use before scripts):
```
lean_goal(file, line) # LSP live goal
lean_diagnostic_messages(file) # Current errors/warnings
lean_leanfinder("query") # Semantic search (try first)
lean_local_search("keyword") # Local + mathlib
lean_loogle("type pattern") # Type-based search
lean_multi_attempt(file, line, snippets=[...]) # Test candidates
lean_run_code("code") # Isolated scratch experiments
```
**Script fallback** (only when LSP is unavailable, rate-limited, or inconclusive after bounded attempts):
```bash
$LEAN4_SCRIPTS/search_mathlib.sh # Search by pattern
$LEAN4_SCRIPTS/smart_search.sh # Multi-source
```
## See Also
- [Extended workflows](../skills/lean4/references/agent-workflows.md#lean4-proof-repair)
Apache-2.0 license, from frenzymath/Archon at commit 3fe261887080.
Security
Scanned Oct 21, 2026 at commit 3fe261887080, with Cisco's open-source skill-scanner.
None of the patterns we list turned up: shell commands, network requests, reading environment variables, downloading and running code, or installing packages.
A scan lists patterns in the code. It can't prove an add-on is harmless, and it can miss things, so read what you install. How we scan
Alternatives
Other makers' add-ons that do the same job, next to this one.
| Name | Score | Stars | Context | Updated |
|---|---|---|---|---|
| This onelean4-proof-repair frenzymath/Archon · Subagent | 61 | ★ 227 | ≈44 in chat | 3mo ago |
| repair aerovato/operator-memory · Skill Both about repair | 64 | ★ 468 | ≈14 always | 24d ago |
| math-proof anthropics/claude-plugins-official · Plugin Both about proof and stage | 79 | ★ 46k | not measured | today |
| find-customer-social-proof zapier/gtm-cheat-codes · Skill Both about proof | 53 | ★ 345 | ≈53 always | 4mo ago |
| capturing-tui-visual-proof letta-ai/letta-code · Skill Both about proof | 75 | ★ 3.7k | ≈59 always | 16d ago |
| deployment-proof FAIRY123456789/human-edge-agent-skills · Skill Both about proof | 58 | ★ 109 | ≈123 always | 23d ago |