Skip to content
AI & Agents
Agent

proof-repair

Compiler-guided iterative proof repair with two-stage repair escalation (fast → strong). Use for error-driven proof fixing with small sampling budgets (K=1).

BOOST
From plugin
lean4-skills
4484 skills4 agents14 commands
Install
> /plugin marketplace add cameronfreer/lean4-skills

How it fires

How this agent gets triggered: by you, by Claude, or both.

  • Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
  • You can call itInvoke it directly when you want it.

Context preview

The summary Claude sees to decide when to auto-load this agent.

Compiler-guided iterative proof repair with two-stage repair escalation (fast → strong). Use for error-driven proof fixing with small sampling budgets (K=1).

Agent definition

proof-repair.md
name: 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, mcp__lean-lsp__lean_goal, mcp__lean-lsp__lean_local_search, mcp__lean-lsp__lean_leanfinder, mcp__lean-lsp__lean_leansearch, mcp__lean-lsp__lean_loogle, mcp__lean-lsp__lean_multi_attempt, mcp__lean-lsp__lean_diagnostic_messages, mcp__lean-lsp__lean_code_actions, mcp__lean-lsp__lean_run_code
model: sonnet

Inputs

Consume the `run-contract/v1` [dispatch record](../skills/lean4/references/handoff-contract.md#dispatch-record-parent--worker) (`record == "dispatch"`): read `target`, the `context` envelope, and `parameters.error` (the structured error to repair). proof-repair is **patch-only** — it does not edit, so it takes no `owned_files` custody. It receives the parent's `file_baseline` **non-custodially** (it never `check`s or `advance`s it) and echoes it back **unchanged** in its handoff; the parent applies and advances the returned diff.

`parameters.error` shape:

{
  "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

> **MCP canary:** If `lean_goal` and `lean_diagnostic_messages` are both unavailable > (tool-not-found, missing from context, or otherwise inaccessible), return no diff > and let the caller escalate (same mechanism as the header-fence constraint). > > **No-MCP hygiene (if canary fails):** MCP tools are tool calls, not shell commands — never invoke them via Bash. Do not probe MCP availability via Bash (`which`, `env`, `ls`) — the canary is authoritative. Stop retrying MCP for this run. Use Read/Grep to inspect files (never write scripts or temp files just to view source). Start from pre-collected context in the parent prompt.

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-skills-search-mathlib` only after LSP exhausted

4. **Generate minimal diff** (1-5 lines) 5. **Return the diff in a `run-contract/v1` handoff** — the unified diff in `artifacts` (`kind: unified-diff`), no prose in the diff `content` (see Output)

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` | local instance via plain `have`/`let`, `open scoped`, reorder arguments | | `timeout` | `simp only [...]`, `clear`, explicit instances |

Output

Return a complete `run-contract/v1` [handoff record](../skills/lean4/references/handoff-contract.md) with the unified diff carried in `artifacts` (proof-repair does **not** edit): `files_changed: []`, the parent's `file_baseline` echoed unchanged, and

"artifacts": [{"kind": "unified-diff", "content": "--- Foo.lean\n+++ Foo.lean\n@@ -42,1 +42,1 @@\n-  exact h1\n+  convert continuous_of_measurable h1 using 2\n"}]

The diff itself is line-number-anchored, nothing else in `content`. `status`/`blocker_kind`/`next_action` follow the outcome (a repaired goal → `next_action: continue`; an un-repairable one → `status: stuck`, `blocker_kind: proof`). The **parent** checks, applies, and advances the patch (§ File baselines and drift).

Constraints

  • The diff `content` is unified-diff ONLY (no explanations); it rides in the handoff's `artifacts`
  • 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
  • May NOT modify declaration headers (header fence). If the fix requires a signature change, return no diff and let the caller escalate.
  • 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
  • Follow mathlib 100-char line width — do not wrap lines at 80 when they fit within 100

Example (Happy Path)

Input: `type_mismatch` at line 42, expected `Continuous f`, got `Measurable f`

Output:

--- 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_code_actions(file, line)        # Resolve "Try this" suggestions to edits
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):

lean4-skills-search-mathlib    # Search by pattern
lean4-skills-smar
Read more
Ships withlean4-skills

Lean 4 workflow pack for AI coding agents. Gives your agent a structured prove/review/golf loop, mathlib search, axiom checking, and safety guardrails.

Get the whole plugin
Stats
449
Stars
47
Forks
Active
Maintenance
Python
Language
MIT
License
17h ago
Last commit
11mo ago
Created

Repo: cameronfreer/lean4-skills

Other agents on lean4-skills.