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.

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.

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

Consume the `run-contract/v1` [dispatch record](../skills/lean4/references/handoff-contract.md#dispatch-record-parent--worker) (`record == "dispatch"`): read `target`/`scope`, the `context` envelope (pre-collected LSP state — use it as the starting state when MCP is unavailable), and `owned_files` + `file_baseline` (fail closed on these — see below). Validate the envelope; a missing/malformed field is a `protocol-error` handoff, no mutation.

`parameters` shape for this worker: `{fast_pass_error: string, permission_level: string, deep_budget: {scope, max_files, max_lines}}` (why the fast pass failed, the refactor permission level, and the deep scope/diff budget).

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). Once this run has edited an imported module (deep mode permits that within the header fence), gate with `lake lean <path/to/File.lean>` for the importing target instead — the file gate checks against built `.olean`s and does not rebuild changed imports ([File Gate Scope](../skills/lean4/references/cycle-engine.md#file-gate-scope))

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

Output

At the return boundary, emit a complete `run-contract/v1` [handoff record](../skills/lean4/references/handoff-contract.md) — echo `target`/`scope`/`mode`; report `files_owned`/`files_changed` + the final adopted `file_baseline`; set `blocker_kind`/`blocker_class` only when blocker-driven (a deep-safety abort is `blocker_kind: safety-guard`, `blocker_class: null`); and `next_action`. The human-readable phase reports below are in addition to that record.

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 a `run-contract/v1` dispatch carries `owned_files`, its `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 -
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.