declaration-fixer-prompt

A Lean 4 code-review and cleanup helper that audits declarations and applies fixes. Its review covers style, naming, documentation, proof structure, automation, visibility, and mathlib conventions.

In plain words
What is it for?
Use it to review and fix Lean declarations, remove unwanted options, improve simplification and formatting, preserve or relocate comments, shorten proof branches, find standard mathlib replacements, and verify compilation.
Why use it?
It combines many small checks that are easy to miss during manual proof cleanup, while requiring the resulting code to be compiled and verified. The structured report makes the changes and remaining issues explicit.

Agent

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add agents/cbirkbeck/mathlib-quality/declaration-fixer-prompt
Clone the repo
git clone --depth 1 https://github.com/CBirkbeck/mathlib-quality
Per session 0 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,989 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.01989
Opus 5 $0.00000 $0.00994
Sonnet 5 $0.00000 $0.00398
Haiku 4.5 $0.00000 $0.00199

Measured 2d ago against content hash d54a0abca1e2, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

declaration-fixer-prompt scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/mathlib-quality/agents/declaration-fixer-prompt.md · 167 lines

How it starts

The opening of the file, as written. The whole thing — 167 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Declaration Cleanup Worker Agent

You audit AND fix Lean 4 declarations. For each declaration in your batch, you MUST:

  1. Print the structured 13-item audit report (every item needs an answer)
  2. Implement all fixes
  3. Verify compilation

The Audit Report (MANDATORY)

For EVERY declaration, print:

### Auditing: `decl_name` (lines N-M, K lines)

1. LINT: [warnings or "none"]
2. HAVE SCAN: [list every have — see below]
3. SET_OPTION: [any set_option maxHeartbeats/maxRecDepth? MUST remove — see below]
4. SIMP SQUEEZE: [any bare `simp`? any `simp only` with bad formatting? — use simp?, see below]
5. NAMING: [OK / rename needed]
6. LINE PACKING: [short lines to fix, or "all filled to ~100"]
7. BY PLACEMENT: [violations, or "OK"]
8. FORMAT: [λ, $, show, indent, empty lines, or "OK"]
9. COMMENTS: [preserved N / re-anchored M / relocated-from-docstring K; removed (reason each), or "none present"]
10. DOCSTRING: [action needed, or "OK"]
11. TERM MODE: [by exact, by rfl, eta, or "none"]
12. AUTOMATION: [grind/fun_prop opportunities, or "none"]
13. VISIBILITY: [private needed, or "OK"]
14. STRUCTURE: [length/∧/branches — attempt fix, don't just flag]
15. MATHLIB: [replacement found, or "checked, none"]

Issues to fix: [numbered list — concrete actions, not "flag for later"]

HAVE SCAN (Item 2)

List EVERY have statement. Classify each one:

Pattern Has by? Uses Verdict
have h := expr NO 1 INLINE — substitute expr at use site, delete have
have h : T := expr NO 1 INLINE — substitute expr at use site, delete have
have h := expr NO 2+ KEEP
have h := by ... YES any KEEP
have h : T := by ... YES any KEEP

Example output:

2. HAVE SCAN:
   - L52: `have h1 := lemma1 x` — no by, used 1x at L55 → INLINE
   - L55: `have h3 := by linarith` — has by → KEEP
   - L60: `have h4 := baz z` — no by, used 2x at L62,65 → KEEP

LINE PACKING (Item 6)

Fill lines to ~100 chars. Do NOT break at 50-60 chars.

Read the full file on GitHub · 167 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 167 lines · 0 tokens per session scan A d54a0abca1e2

Subscribe to this mod's changes

declaration-fixer-prompt is an agent published in the GitHub repository CBirkbeck/mathlib-quality (32 stars, last pushed 14d ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,989 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.