Development
Read the complete source ↗
mathlib-quality
Mathlib code quality and style enforcement for Lean 4
CBirkbeck · Static checks on file
Installation
Read the source and dependencies before running a command. Copying does not install or execute anything.
npx skills add CBirkbeck/mathlib-quality --skill mathlib-qualityAbout this skill
name: mathlib-quality description: Mathlib code quality and style enforcement for Lean 4 trigger: filePatterns: - "*.lean" keywords: - mathlib - style - cleanup - golf - PR - submit - bump - upgrade - update - status - progress - bottleneck - stuck - frontier - blueprint - unformalise - unformalize - leanblueprint - latex - dep-graph - prose - sketch - render - mathlibable - mathlib-fit - mathlib-ready - generality - generalise - generalize
Mathlib Quality Skill
Activation Triggers
This skill activates when:
- Working with
.leanfiles intended for mathlib contribution - User mentions "mathlib style", "cleanup", "golf", "PR submission", or "pre-submit"
- User asks to fix reviewer feedback on a mathlib PR
- User wants to check code against mathlib conventions
- User asks "what's the project status?", "where are we stuck?", "what's the
bottleneck?", "what's the worker doing?", "show me progress" → run
/project-status
Overview
This skill helps bring Lean 4 code up to mathlib standards by:
- Enforcing style rules (line length, formatting, indentation)
- Checking naming conventions
- Ensuring proper documentation
- Golfing proofs to be shorter and cleaner
- Preparing code for PR submission
Available Commands
| Command | Description |
|---|---|
/develop | Planning only, with binding methodical-decomposition pre-work. Phases 1a–1d: gather context, study references, search mathlib, design API. Phase 1e (binding pre-work): for each top-level result, write the prose proof, decompose into ordered lemmas, physically state every lemma as := by sorry in the project's Lean files (Step 2.5 — skeleton must lake build clean), then tension against the references with a verbatim source quote per leaf and a Lean ↔ source match paragraph (Step 3). Verify every leaf is discharged from mathlib (cited + verified) or already-developed project code — gaps become explicit API-gap sub-trees. Save decomposition.md. Only after every leaf is verified across (Lean declaration + verbatim quote + citation) does ticket creation (1g) proceed. Then ChatGPT validation (1h) and user approval (1i). Workers run via /beastmode. Flag --decompose runs ONLY Phase 1e and stops — for iterating on the skeleton / decomposition / source quotes before committing to a ticket board. |
/beastmode | Marathon execution. Stops at nothing — but stays on-target. Pick a ticket, finish the goal no matter how deep the path goes. Spawn sub-tickets in /develop's template format; replan via /develop --continue when a sketch is wrong; no recursion cap, no time budget. Continuously checks on-target before each sub-ticket and step (serves the plan? stays in the project's mathematical area? a refinement not a divergence?). Welcomes scope growth that stays on target — a "two lemmas" step turning into ten is great news, not a stop signal. Super Saiyan ethos: the harder the work, the more energy goes in. Mandatory post-proof cleanup (Phase 6.5): after gates pass and before mark-done, invokes Skill(mathlib-quality:cleanup) on every new declaration — full 11-phase workflow, no phase-skipping (enforced via /cleanup's own phase checklist), including the 6.5 simplify and 6.6 buzz (performance) hand-offs; decompose flags spawn /decompose-proof sub-tickets, rename queue drained inside /cleanup's Phase 5b. Only stops: DONE / SCOPE-DEFINITION ERROR / OFF-TRACK (drift outside the project's mathematical scope, with concrete evidence) / BROKEN BASELINE. "This is multi-session work" is NOT a stop — it is the target signal. Beastmode exists to collapse multi-session work into one continuous run. |
/cleanup | Style audit + cleanup + golf (whole file or single declaration). 11-phase methodical workflow: doctor (baseline build) → prepare → audit punch-list → file-level fixes → per-declaration deep golf with diff gates → refactoring (5a non-rename + 5b rename pass) → final gates + cumulative checks → built-in /simplify pass → /buzz performance pass → report. Absorbed: /check-style (Phase 2 audit), /check-mathlib (Phase 4 item 13 — five-method search + six strict rules + common-equivalents lookup), the inline mechanical pass of /generalise (Phase 4 item 18), and shouyi-style diff gates (Phase 4 + 6). Phase 6.5 hand-off to the built-in /simplify skill catches holistic issues the rule-driven pass missed; Phase 6.6 hand-off to /buzz gets every declaration under the elaboration budget (deferrals feed /decompose-proof). |
/cleanup-all | Orchestrator-worker pattern for project-wide cleanup. Main session is the orchestrator: enumerates files, buckets by size, dispatches batched Agent calls with a ~1200-char verbatim prompt (working dir + branch + build + file list + target), narrates progress in one-line scoreboards between dispatches. Workers do the file reading, LSP, edits, Phase-4 sub-worker dispatch, and build verification in fresh contexts. Orchestrator never reads/edits/builds. The pattern that sustained a 28-day, 9000-message marathon. |
/decompose-proof | Break long proofs into helper lemmas |
/buzz | Profile → trace → fix slow declarations (target <1s each). One profiled compile per file → per-decl timing table → trace-driven diagnosis against the eight-cause taxonomy in references/profiling.md → measured fixes, with same-issue propagation across the remaining slow decls. Statements byte-identical; limit raises forbidden (existing maxHeartbeats removed); profiling scaffolding gate-checked out. PR mode by default; also <file>, <file> <decl>, --all, --budget <ms>. Runs automatically as /cleanup Phase 6.6. |
/overview | Project survey + per-decl mathlibable assessment. Inventory + cross-file analyses (mathlib API audit, duplications, generalisation, missing API, junk) + ** |