axiom-eliminator
Remove nonconstructive axioms by refactoring proofs to structure (kernels, measurability,…
Compiler-guided iterative proof repair with two-stage repair escalation (fast → strong). Use for error-driven proof fixing with small sampling budgets (K=1).
> /plugin marketplace add cameronfreer/lean4-skillsHow it fires
How this agent gets triggered: by you, by Claude, or both.
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).
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
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"]
}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):
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)
| 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).
| 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 |
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).
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
**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
Lean 4 workflow pack for AI coding agents. Gives your agent a structured prove/review/golf loop, mathlib search, axiom checking, and safety guardrails.
Remove nonconstructive axioms by refactoring proofs to structure (kernels, measurability,…
Golf Lean 4 proofs after they compile; improve proofs for directness, clarity, performance,…
Strategic resolution of stubborn sorries; may refactor across files within the header fence.…