Lean 4 & Mathlib Upstream Porting and PR Lifecycle
Generalize reusable in-tree lemmas to Mathlib4/Stdlib conventions and manage the full upstream pull-request lifecycle cleanly and transparently.
Routing
- USE FOR: generalizing project-local lemmas to Mathlib4 style, branch/commit hygiene, PR titles/labels
(
feat(Algebra/...): ...), AI-assistance disclosure, andborsreview loops. - DO NOT USE FOR: shrinking upstream bug reproducers (
@lean-mwe) or vendoring external repos into your project (@lean-dependency-management).
Workflow
- Deduplicate & Generalize -- Search
lean_search(source: "loogle" | "code")to confirm the lemma is absent upstream; strip project-specific scaling/wrappers and generalize typeclasses to minimal Mathlib4 mixins. - Enforce Mathlib4 Style -- Apply
snake_casenaming,set_option autoImplicit falsecompatibility,/-- ... -/docstrings, explicit module imports, and#lintpass (references/protocols/mathlib4-conventions.md). - Prepare PR & Disclosure -- Format conventional title, summary, dependency links (
- [ ] depends on: #...), and mandatory AI-tooling disclosure per upstream repository policy. - Human-in-the-Loop Gate -- Present the final diff,
#lintoutput, and PR body for explicit human approval before executinggh pr create.
Recovery & STOP
- Never push directly to
main/masteror open an external upstream PR without explicit human sign-off. - If
lean_searchfinds an existing Mathlib lemma up to argument order or ring morphism, abort the port and replace the local copy with the Mathlib lemma.
Handoffs
- Predecessors:
lean-proof-review,lean-proof-refactor,lean-mwe. - Successors:
lean-retro-methodology.
Detailed reference
- Layer-1 Fast Lookup Card (read first):
references/cards/lean-upstream-pr-tables.md - Full handbook:
../../references/handbooks/lean-upstream-pr-handbook.md - PR template:
../../templates/workflow/Template_PR.md
See also
../../references/protocols/mathlib4-conventions.md-- Mathlib4 style & naming guide../lean-mwe/SKILL.md-- Minimal working examples for upstream bug reports
