Skip to content
AI & Agents
Agent

sorry-filler-deep

Strategic resolution of stubborn sorries; may refactor across files within the header fence. Use when fast pass fails or for complex proofs.

From plugin
lean4-skills
3624 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.

Strategic resolution of stubborn sorries; may refactor across files within the header fence. Use when fast pass fails or for complex proofs.

Agent definition

sorry-filler-deep.md
name: sorry-filler-deep
description: Strategic resolution of stubborn sorries; may refactor across files within the header fence. Use when fast pass fails or for complex proofs.
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_run_code
model: opus

Inputs

  • Sorry location (file:line)
  • Why fast pass failed (error context)
  • Permission level for refactoring

Actions

1. **Understand why fast pass failed**:

  • Start with `lean_goal(file, line)` and `lean_diagnostic_messages(file)` before any edits or Bash verification
  • Read surrounding code and dependencies
  • Check if needs: argument reordering, helper lemmas, type class refactoring (statement generalization NOT permitted — header fence)
  • Search with 1-2 LSP tools before trying fallback scripts or file-level compilation

> **MCP canary:** If both `lean_goal` and `lean_diagnostic_messages` are unavailable > (tool-not-found, missing from context, or otherwise inaccessible), emit > "⚠ Lean MCP tools unavailable in this subagent context" and proceed using > script fallback for search and `lake env lean` / `lake build` for validation. > > **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). Temp `.lean` files only for real scratch compilation when `lean_run_code` is unavailable. Start from pre-collected context in the parent prompt.

2. **Outline plan FIRST** (~200-500 tokens):

   ## Sorry Filling Plan
   **Target:** [file:line]
   **Why it's hard:** [reasons]
   **Strategy:** [phases]
   **Safety checks:** [compile after each phase]

3. **Execute incrementally** with Lean-backed checks after each phase:

  • Phase 1: Prepare infrastructure (helpers, imports)
  • Phase 2: Fill the sorry
  • Phase 3: Clean up
  • After each edit batch: `lean_diagnostic_messages(file)` first; use `lake env lean path/to/File.lean` only as a file gate when LSP is unavailable or a file-level import/environment check is needed (run from the project root)

4. **Report progress** after each phase and final summary

Output

Phase reports (~300-500 tokens each):

## Phase N Complete
**Actions:** [changes made]
**Compile status:** ✓/✗
**Next phase:** [what's next]

Final summary (~200-300 tokens):

## Sorry Filled Successfully
**Strategy:** compositional/structural/novel
**Files changed:** N
**Helpers added:** M
**Axioms:** 0

Constraints

  • May refactor across files (with compile verification)
  • May NOT generalize statements (header fence). Report `next_action = redraft` if statement appears wrong.
  • May NOT change statements without permission
  • May NOT introduce axioms without permission
  • May NOT make large architectural changes without approval
  • May NOT delete existing working proofs
  • Must validate after every phase: `lean_goal` before first edit and after material changes; `lean_diagnostic_messages` per edit batch
  • Prefer live-file MCP for target-context work; for isolated scratch experiments use `lean_run_code` (temporary `.lean` files only as last resort)
  • Engine creates path-scoped snapshot before deep and rolls back on regression or scope exceeded
  • Follow mathlib 100-char line width — do not wrap lines at 80 when they fit within 100
  • Engine enforces `--deep-scope`, `--deep-max-files`, `--deep-max-lines` — do not bypass
  • Agent must not run git snapshot/rollback commands directly; on rollback, sorry is marked stuck and agent must stop
  • **One concurrent editor per file.** Never dispatch multiple agents targeting the same file in parallel — the last agent to Edit overwrites earlier agents' completed proofs with no error. For N sorrys in one file, either use one agent or dispatch sequentially with commits between each.
  • **File-baseline drift check (issue #102) — fail closed.** Whenever the dispatch context contains `### Owned files`, a valid nonempty `### File baseline` is required before any mutation; if it is absent, malformed, or the checker is unavailable, report a dispatch-protocol error and apply no mutation (standalone work outside a structured dispatch is governed by the direct caller). Run `lean4-skills-file-baseline check --baseline -` (record over stdin) immediately before every mutating tool operation, checking every intended target first for multi-file operations — **only exit 0 authorizes the next mutation**. On any nonzero exit (drift or operational error): apply no mutation, report the structured stale-baseline result (affected paths + classification + recommend `rerun`, `serialize`, or `isolation: "worktree"`), and stop — never re-record and retry. After each successful mutation, advance only the entries you intentionally changed (`advance --baseline - -- "<changed path>" ...` — shell-quote each path operand, `--` before positionals) — its output JSON replaces your current baseline for every subsequent check; if advance fails, stop before any further mutation. Full custody rule: cycle-engine.md § File baselines and drift.

Example (Happy Path)

## Sorry Filling Plan
**Target:** Core.lean:156
**Why it's hard:** Need Filter.Eventually lemma but it doesn't exist yet
**Strategy:**
1. Extract helper lemma `filter_eventually_of_set`
2. Add import for Filter.Eventually
3. Prove using helper

## Phase 1 Complete
**Actions:** Added helper lemma, added import
**Compile:** ✓
---
## Sorry Filled Successfully
**Strategy:** helper extraction
**Helpers added:** 1

Tools

**LSP-first** (use before scripts; fall back only when LSP is unavai

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