Run compiler-guided proof repair on a Lean file using iterative error feedback and automated solvers
Automates iterative proof repair for Lean files using compiler feedback and solver cascades. Use this when you have a Lean file with multiple proof errors that need systematic fixing.
/plugin marketplace add cameronfreer/lean4-skills/plugin install lean4-theorem-proving@lean4-skillsRun iterative proof repair on <PATH> using compiler feedback to drive targeted fixes.
Strategy: Compile → Parse Error → Try Solvers → Agent Repair → Apply → Verify (loop)
Inspired by: APOLLO (https://arxiv.org/abs/2505.05758) - compiler-guided repair with low sampling budgets
<PATH>: Path to Lean file to repair (required)--max-attempts=24: Maximum repair attempts (default: 24)--repeat-limit=3: Bail after N identical errors (default: 3)--stage2-threshold=3: Escalate to Stage 2 after N repeats (default: 3)You will orchestrate a compiler-guided repair loop:
Read(<PATH>).repair/.repair/attempts.ndjsonFor each attempt (up to --max-attempts):
Step 1: Compile
lake build <PATH> 2> .repair/errs.txt
Step 2: Parse Error
python3 scripts/parseLeanErrors.py .repair/errs.txt > .repair/context.json
Extract from context.json:
errorHash: Track for repeatserrorType: Route to appropriate fixmessage: Show to usergoal, localContext, codeSnippet: Provide to agentStep 3: Check for Repeated Error
errorHash same as previous:
--repeat-limit:
Step 4: Try Solver Cascade (fast path)
python3 scripts/solverCascade.py .repair/context.json <PATH> > .repair/solver.diff
Solver order: rfl → simp → ring → linarith → nlinarith → omega → exact? → apply? → aesop
git apply .repair/solver.diff
→ Continue to next attempt (recompile)Step 5: Agent Repair
Dispatch lean4-proof-repair agent with Task tool:
You are repairing a Lean proof with compiler-guided feedback.
**Error Context:**
FILE: <PATH>
ERROR_TYPE: {errorType}
ERROR_HASH: {errorHash}
LINE: {line}
COLUMN: {column}
MESSAGE:
{message}
GOAL:
{goal}
LOCAL CONTEXT:
{localContext}
CODE SNIPPET:
{codeSnippet}
**Stage:** {stage}
(Stage 1 = Haiku fast, Stage 2 = Sonnet precise)
**Task:**
Generate a MINIMAL unified diff that fixes this error.
**Output:** ONLY the unified diff. No explanations.
Consult `.claude/docs/lean4/compiler-guided-repair.md` for repair strategies.
Agent configuration:
lean4-proof-repair (Haiku, thinking off)Step 6: Apply Patch
Agent returns diff. Apply it:
git apply --ignore-whitespace .repair/agent.diff
If apply fails:
git apply --ignore-whitespace --3way .repair/agent.diff
If both fail:
Step 7: Log Attempt
Append to .repair/attempts.ndjson:
{
"attempt": N,
"errorHash": "...",
"errorType": "...",
"stage": 1 or 2,
"solverSuccess": true/false,
"agentCalled": true/false,
"patchApplied": true/false,
"elapsed": seconds
}
Success:
✅ Proof repair SUCCESSFUL after N attempts!
Summary:
- File: <PATH>
- Total attempts: N
- Solver cascade wins: K
- Agent repairs: M
- Stage 2 escalations: L
- Total time: Xs
Attempt log: .repair/attempts.ndjson
Failure:
❌ Repair failed after N attempts
Last error:
- Type: {errorType}
- Hash: {errorHash}
- Message: {message}
Attempt log: .repair/attempts.ndjson
Suggestions:
- Review .repair/attempts.ndjson to see what was tried
- Try /lean4-theorem-proving:repair-interactive for manual control
- Escalate complex errors to manual review
User runs:
/lean4-theorem-proving:repair-file MyProofs.lean --max-attempts=12
You execute:
Attempt 1/12:
Compile: ❌ type mismatch at line 42
Solver cascade: ❌ (tried 9 solvers)
Agent (Stage 1): ✓ Generated patch
Applied: ✓
Attempt 2/12:
Compile: ❌ unsolved goals at line 45
Solver cascade: ✓ (simp succeeded!)
Applied: ✓
Attempt 3/12:
Compile: ✅ SUCCESS!
✅ Proof repair SUCCESSFUL after 3 attempts!
Use TodoWrite to track:
1. Compile and check (Attempt 1/24)
2. Fix error: type_mismatch (Attempt 2/24)
3. Fix error: unsolved_goals (Attempt 3/24)
...
Mark completed as you go.
Error handling:
Budget management:
Compiler-guided repair inspired by APOLLO (https://arxiv.org/abs/2505.05758)