@louisultra/dsh-verymath 0.0.0-stage → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +133 -0
- package/LICENSE +21 -0
- package/NOTICE.md +35 -0
- package/README.md +108 -2
- package/README_EN.md +105 -0
- package/UPSTREAM.json +106 -0
- package/cordis.patch.yml +12 -0
- package/docs/capability-examples.md +581 -0
- package/docs/examples/README.md +32 -0
- package/docs/examples/bad_scan.md +10 -0
- package/docs/examples/broken-proof.lean +9 -0
- package/docs/examples/claims.md +7 -0
- package/docs/examples/knapsack.json +10 -0
- package/docs/examples/matrix.json +1 -0
- package/docs/examples/points.csv +21 -0
- package/docs/examples/qp.json +8 -0
- package/docs/examples/research-ws/project/GOALS.yaml +4 -0
- package/docs/examples/research-ws/workstreams/ws-lsa/report.md +13 -0
- package/docs/examples/research-ws/workstreams/ws-lsa/reviews/r1.json +1 -0
- package/docs/examples/research-ws/workstreams/ws-lsa/status.yaml +1 -0
- package/docs/examples/source.csv +4 -0
- package/lib/core/error.d.ts +20 -0
- package/lib/core/error.js +25 -0
- package/lib/core/gates.d.ts +42 -0
- package/lib/core/gates.js +217 -0
- package/lib/core/glossary.d.ts +101 -0
- package/lib/core/glossary.js +243 -0
- package/lib/core/graph.d.ts +118 -0
- package/lib/core/graph.js +460 -0
- package/lib/core/index.d.ts +120 -0
- package/lib/core/index.js +197 -0
- package/lib/core/paper.d.ts +163 -0
- package/lib/core/paper.js +73 -0
- package/lib/core/paths.d.ts +2 -0
- package/lib/core/paths.js +12 -0
- package/lib/core/sage.d.ts +61 -0
- package/lib/core/sage.js +212 -0
- package/lib/core/skills.d.ts +11 -0
- package/lib/core/skills.js +110 -0
- package/lib/tool/index.d.ts +21 -0
- package/lib/tool/index.js +1144 -0
- package/package.json +92 -4
- package/skills/after-ocr/SKILL.md +123 -0
- package/skills/after-ocr/references/audit-schema.md +94 -0
- package/skills/after-ocr/references/error-taxonomy.md +179 -0
- package/skills/after-ocr/scripts/merge_audit_logs.py +329 -0
- package/skills/after-ocr/scripts/scan_markdown_ocr.py +350 -0
- package/skills/after-ocr/tests/test_scripts.py +84 -0
- package/skills/discover-math-problems/SKILL.md +115 -0
- package/skills/discover-math-problems/references/artifact-contract.md +93 -0
- package/skills/discover-math-problems/references/autonomous-research-protocol.md +86 -0
- package/skills/discover-math-problems/references/conjecture-generation-protocol.md +63 -0
- package/skills/discover-math-problems/references/extremal-graph-variants.md +53 -0
- package/skills/graph-theory-paper-reading/SKILL.md +600 -0
- package/skills/invariant-computation/SKILL.md +169 -0
- package/skills/invariant-computation/examples/invariant_summary.example.json +51 -0
- package/skills/invariant-computation/manifest.yaml +46 -0
- package/skills/invariant-computation/references/INDEX.md +20 -0
- package/skills/invariant-computation/references/failure_modes.md +40 -0
- package/skills/invariant-computation/references/method_route_map.md +177 -0
- package/skills/invariant-computation/references/source_notes.md +19 -0
- package/skills/invariant-computation/references/tool_catalog.md +65 -0
- package/skills/invariant-computation/references/validation_checks.md +52 -0
- package/skills/invariant-computation/schema/invariant_summary.schema.json +260 -0
- package/skills/lean-formalization/SKILL.md +111 -0
- package/skills/lean-formalization/lean-runtime/config/env.example +5 -0
- package/skills/lean-formalization/lean-runtime/config/lean_agent.example.toml +28 -0
- package/skills/lean-formalization/lean-runtime/config/numina_runtime.example.toml +12 -0
- package/skills/lean-formalization/lean-runtime/examples/smoke/LocalLeanSmoke.lean +7 -0
- package/skills/lean-formalization/lean-runtime/prompts/complete_sorries.md +3 -0
- package/skills/lean-formalization/lean-runtime/prompts/formalize_statement.md +3 -0
- package/skills/lean-formalization/lean-runtime/prompts/prove_theorem.md +3 -0
- package/skills/lean-formalization/lean-runtime/prompts/repair_lean_file.md +3 -0
- package/skills/lean-formalization/lean-runtime/references/backend_adapter_checklist.md +36 -0
- package/skills/lean-formalization/lean-runtime/references/direct_lean_workflow.md +48 -0
- package/skills/lean-formalization/lean-runtime/references/failure_taxonomy.md +17 -0
- package/skills/lean-formalization/lean-runtime/references/interactive_orchestration.md +83 -0
- package/skills/lean-formalization/lean-runtime/references/lean_agent_capability_map.md +116 -0
- package/skills/lean-formalization/lean-runtime/references/lean_lsp_mcp_adapter.md +219 -0
- package/skills/lean-formalization/lean-runtime/references/lean_runtime_configuration.md +92 -0
- package/skills/lean-formalization/lean-runtime/references/numina_reverse_analysis.md +80 -0
- package/skills/lean-formalization/lean-runtime/references/numina_runtime.md +41 -0
- package/skills/lean-formalization/lean-runtime/references/numina_subagent_troubleshooting.md +77 -0
- package/skills/lean-formalization/lean-runtime/references/review_checklist.md +10 -0
- package/skills/lean-formalization/lean-runtime/references/specialist_agent_patterns.md +65 -0
- package/skills/lean-formalization/lean-runtime/schemas/config.schema.json +12 -0
- package/skills/lean-formalization/lean-runtime/schemas/result.schema.json +33 -0
- package/skills/lean-formalization/lean-runtime/schemas/task.schema.json +30 -0
- package/skills/lean-formalization/lean-runtime/scripts/ai4m_lean.py +222 -0
- package/skills/lean-formalization/lean-runtime/scripts/check_lean_project.py +134 -0
- package/skills/lean-formalization/lean-runtime/scripts/common.py +296 -0
- package/skills/lean-formalization/lean-runtime/scripts/configure_lean.py +222 -0
- package/skills/lean-formalization/lean-runtime/scripts/detect_sorry.py +49 -0
- package/skills/lean-formalization/lean-runtime/scripts/direct_task.py +100 -0
- package/skills/lean-formalization/lean-runtime/scripts/extract_minimal_failure.py +74 -0
- package/skills/lean-formalization/lean-runtime/scripts/numina_runtime.py +414 -0
- package/skills/lean-formalization/lean-runtime/scripts/smoke_test.py +75 -0
- package/skills/lean-formalization/lean-runtime/scripts/tool_status.py +79 -0
- package/skills/lean-formalization/lean-runtime/scripts/validate_patch.py +81 -0
- package/skills/lean-formalization/lean-runtime/scripts/verify_delivery.py +484 -0
- package/skills/lean-formalization/lean-runtime/tests/fixtures/after_bad.lean +4 -0
- package/skills/lean-formalization/lean-runtime/tests/fixtures/after_statement_changed.lean +4 -0
- package/skills/lean-formalization/lean-runtime/tests/fixtures/before.lean +4 -0
- package/skills/lean-formalization/lean-runtime/tests/fixtures/failure.lean +7 -0
- package/skills/lean-formalization/lean-runtime/tests/test_check_lean_project.py +59 -0
- package/skills/lean-formalization/lean-runtime/tests/test_cli.py +377 -0
- package/skills/lean-formalization/lean-runtime/tests/test_common_config.py +84 -0
- package/skills/lean-formalization/lean-runtime/tests/test_configure_lean.py +138 -0
- package/skills/lean-formalization/lean-runtime/tests/test_detect_sorry.py +24 -0
- package/skills/lean-formalization/lean-runtime/tests/test_direct_task.py +69 -0
- package/skills/lean-formalization/lean-runtime/tests/test_numina_runtime.py +168 -0
- package/skills/lean-formalization/lean-runtime/tests/test_validate_patch.py +29 -0
- package/skills/lean-setup/SKILL.md +99 -0
- package/skills/least-squares/README.md +85 -0
- package/skills/least-squares/SKILL.md +613 -0
- package/skills/least-squares/examples.md +380 -0
- package/skills/math-beamer/SKILL.md +325 -0
- package/skills/math-beamer/references/build-and-layout-audit.md +63 -0
- package/skills/math-beamer/references/math-domain-patterns.md +56 -0
- package/skills/math-beamer/references/template-policy.md +43 -0
- package/skills/math-beamer/references/template-source-index.md +51 -0
- package/skills/math-beamer/templates/catalog.yaml +235 -0
- package/skills/math-beamer/templates/packs/algebra-number-theory-talk/main.tex +45 -0
- package/skills/math-beamer/templates/packs/algebra-number-theory-talk/template.yaml +9 -0
- package/skills/math-beamer/templates/packs/algorithm-talk/main.tex +43 -0
- package/skills/math-beamer/templates/packs/algorithm-talk/template.yaml +9 -0
- package/skills/math-beamer/templates/packs/analysis-core-talk/main.tex +49 -0
- package/skills/math-beamer/templates/packs/analysis-core-talk/template.yaml +19 -0
- package/skills/math-beamer/templates/packs/backup-heavy-talk/main.tex +40 -0
- package/skills/math-beamer/templates/packs/backup-heavy-talk/template.yaml +9 -0
- package/skills/math-beamer/templates/packs/beamerposter-a0/main.tex +45 -0
- package/skills/math-beamer/templates/packs/beamerposter-a0/template.yaml +12 -0
- package/skills/math-beamer/templates/packs/combinatorics-graph-talk/main.tex +53 -0
- package/skills/math-beamer/templates/packs/combinatorics-graph-talk/template.yaml +18 -0
- package/skills/math-beamer/templates/packs/control-systems-talk/main.tex +51 -0
- package/skills/math-beamer/templates/packs/control-systems-talk/template.yaml +18 -0
- package/skills/math-beamer/templates/packs/course-lecture-zh/main.tex +43 -0
- package/skills/math-beamer/templates/packs/course-lecture-zh/template.yaml +9 -0
- package/skills/math-beamer/templates/packs/data-experiment-results/main.tex +45 -0
- package/skills/math-beamer/templates/packs/data-experiment-results/template.yaml +9 -0
- package/skills/math-beamer/templates/packs/dynamical-systems-talk/main.tex +42 -0
- package/skills/math-beamer/templates/packs/dynamical-systems-talk/template.yaml +9 -0
- package/skills/math-beamer/templates/packs/geometry-topology-talk/main.tex +43 -0
- package/skills/math-beamer/templates/packs/geometry-topology-talk/template.yaml +9 -0
- package/skills/math-beamer/templates/packs/information-coding-crypto-talk/main.tex +49 -0
- package/skills/math-beamer/templates/packs/information-coding-crypto-talk/template.yaml +18 -0
- package/skills/math-beamer/templates/packs/logic-foundations-category-talk/main.tex +51 -0
- package/skills/math-beamer/templates/packs/logic-foundations-category-talk/template.yaml +18 -0
- package/skills/math-beamer/templates/packs/numerical-analysis-talk/main.tex +51 -0
- package/skills/math-beamer/templates/packs/numerical-analysis-talk/template.yaml +9 -0
- package/skills/math-beamer/templates/packs/optimization-talk/main.tex +58 -0
- package/skills/math-beamer/templates/packs/optimization-talk/template.yaml +9 -0
- package/skills/math-beamer/templates/packs/pde-analysis-talk/main.tex +49 -0
- package/skills/math-beamer/templates/packs/pde-analysis-talk/template.yaml +9 -0
- package/skills/math-beamer/templates/packs/probability-statistics-talk/main.tex +52 -0
- package/skills/math-beamer/templates/packs/probability-statistics-talk/template.yaml +9 -0
- package/skills/math-beamer/templates/packs/reading-group-paper/main.tex +46 -0
- package/skills/math-beamer/templates/packs/reading-group-paper/template.yaml +9 -0
- package/skills/math-beamer/templates/packs/seminar-minimal-en/main.tex +60 -0
- package/skills/math-beamer/templates/packs/seminar-minimal-en/template.yaml +13 -0
- package/skills/math-beamer/templates/packs/seminar-minimal-zh/main.tex +60 -0
- package/skills/math-beamer/templates/packs/seminar-minimal-zh/template.yaml +13 -0
- package/skills/math-beamer/templates/packs/theorem-proof-talk/main.tex +60 -0
- package/skills/math-beamer/templates/packs/theorem-proof-talk/template.yaml +9 -0
- package/skills/math-beamer/templates/packs/thesis-defense/main.tex +42 -0
- package/skills/math-beamer/templates/packs/thesis-defense/template.yaml +9 -0
- package/skills/math-beamer/templates/packs/workshop-tutorial/main.tex +32 -0
- package/skills/math-beamer/templates/packs/workshop-tutorial/template.yaml +9 -0
- package/skills/math-beamer/templates/preview-gallery.md +32 -0
- package/skills/math-beamer/templates/previews/algebra-number-theory-talk-content.png +0 -0
- package/skills/math-beamer/templates/previews/algebra-number-theory-talk-cover.png +0 -0
- package/skills/math-beamer/templates/previews/algorithm-talk-content.png +0 -0
- package/skills/math-beamer/templates/previews/algorithm-talk-cover.png +0 -0
- package/skills/math-beamer/templates/previews/analysis-core-talk-content.png +0 -0
- package/skills/math-beamer/templates/previews/analysis-core-talk-cover.png +0 -0
- package/skills/math-beamer/templates/previews/backup-heavy-talk-content.png +0 -0
- package/skills/math-beamer/templates/previews/backup-heavy-talk-cover.png +0 -0
- package/skills/math-beamer/templates/previews/beamerposter-a0-content.png +0 -0
- package/skills/math-beamer/templates/previews/beamerposter-a0-cover.png +0 -0
- package/skills/math-beamer/templates/previews/combinatorics-graph-talk-content.png +0 -0
- package/skills/math-beamer/templates/previews/combinatorics-graph-talk-cover.png +0 -0
- package/skills/math-beamer/templates/previews/control-systems-talk-content.png +0 -0
- package/skills/math-beamer/templates/previews/control-systems-talk-cover.png +0 -0
- package/skills/math-beamer/templates/previews/course-lecture-zh-content.png +0 -0
- package/skills/math-beamer/templates/previews/course-lecture-zh-cover.png +0 -0
- package/skills/math-beamer/templates/previews/data-experiment-results-content.png +0 -0
- package/skills/math-beamer/templates/previews/data-experiment-results-cover.png +0 -0
- package/skills/math-beamer/templates/previews/dynamical-systems-talk-content.png +0 -0
- package/skills/math-beamer/templates/previews/dynamical-systems-talk-cover.png +0 -0
- package/skills/math-beamer/templates/previews/geometry-topology-talk-content.png +0 -0
- package/skills/math-beamer/templates/previews/geometry-topology-talk-cover.png +0 -0
- package/skills/math-beamer/templates/previews/information-coding-crypto-talk-content.png +0 -0
- package/skills/math-beamer/templates/previews/information-coding-crypto-talk-cover.png +0 -0
- package/skills/math-beamer/templates/previews/logic-foundations-category-talk-content.png +0 -0
- package/skills/math-beamer/templates/previews/logic-foundations-category-talk-cover.png +0 -0
- package/skills/math-beamer/templates/previews/numerical-analysis-talk-content.png +0 -0
- package/skills/math-beamer/templates/previews/numerical-analysis-talk-cover.png +0 -0
- package/skills/math-beamer/templates/previews/optimization-talk-content.png +0 -0
- package/skills/math-beamer/templates/previews/optimization-talk-cover.png +0 -0
- package/skills/math-beamer/templates/previews/pde-analysis-talk-content.png +0 -0
- package/skills/math-beamer/templates/previews/pde-analysis-talk-cover.png +0 -0
- package/skills/math-beamer/templates/previews/probability-statistics-talk-content.png +0 -0
- package/skills/math-beamer/templates/previews/probability-statistics-talk-cover.png +0 -0
- package/skills/math-beamer/templates/previews/reading-group-paper-content.png +0 -0
- package/skills/math-beamer/templates/previews/reading-group-paper-cover.png +0 -0
- package/skills/math-beamer/templates/previews/seminar-minimal-en-content.png +0 -0
- package/skills/math-beamer/templates/previews/seminar-minimal-en-cover.png +0 -0
- package/skills/math-beamer/templates/previews/seminar-minimal-zh-content.png +0 -0
- package/skills/math-beamer/templates/previews/seminar-minimal-zh-cover.png +0 -0
- package/skills/math-beamer/templates/previews/theorem-proof-talk-content.png +0 -0
- package/skills/math-beamer/templates/previews/theorem-proof-talk-cover.png +0 -0
- package/skills/math-beamer/templates/previews/thesis-defense-content.png +0 -0
- package/skills/math-beamer/templates/previews/thesis-defense-cover.png +0 -0
- package/skills/math-beamer/templates/previews/workshop-tutorial-content.png +0 -0
- package/skills/math-beamer/templates/previews/workshop-tutorial-cover.png +0 -0
- package/skills/math-beamer/templates/review-report.md +54 -0
- package/skills/math-beamer/templates/slide-source-ledger.md +22 -0
- package/skills/math-beamer/templates/source-packet.md +50 -0
- package/skills/math-glossary/SKILL.md +347 -0
- package/skills/math-glossary/references/glossary-schema.md +71 -0
- package/skills/math-glossary/references/glossary-usage-guide.md +176 -0
- package/skills/math-glossary/references/glossary-web-template.md +127 -0
- package/skills/math-glossary/references/glossary.schema.json +76 -0
- package/skills/math-glossary/references/user-manual.md +435 -0
- package/skills/math-glossary/requirements-ai.txt +3 -0
- package/skills/math-glossary/requirements.txt +3 -0
- package/skills/math-glossary/scripts/glossary_backup.py +42 -0
- package/skills/math-glossary/scripts/glossary_build.py +467 -0
- package/skills/math-glossary/scripts/glossary_enrich_examples.py +283 -0
- package/skills/math-glossary/scripts/glossary_export.py +333 -0
- package/skills/math-glossary/scripts/glossary_web.py +1265 -0
- package/skills/math-paper-reading/README.md +163 -0
- package/skills/math-paper-reading/SKILL.md +48 -0
- package/skills/math-paper-reading/agent_router.md +36 -0
- package/skills/math-paper-reading/references/proof_pattern_taxonomy.md +123 -0
- package/skills/math-paper-reading/references/quality_rubric.md +36 -0
- package/skills/math-paper-reading/skill_base.md +627 -0
- package/skills/math-paper-reading/skill_literature_search.md +866 -0
- package/skills/math-paper-reading/skill_paper_deep_read.md +1024 -0
- package/skills/math-paper-reading/skill_pathway_proof.md +718 -0
- package/skills/math-paper-reading/skill_reference_manager.md +746 -0
- package/skills/matlab-runner/SKILL.md +217 -0
- package/skills/matlab-runner/examples/README.md +33 -0
- package/skills/matlab-runner/examples/matrix_report.m +28 -0
- package/skills/matlab-runner/examples/plot_damped_sine.m +64 -0
- package/skills/matlab-runner/examples/test_vector_norm.m +12 -0
- package/skills/matlab-runner/references/client-setup.md +24 -0
- package/skills/matlab-runner/references/file-session-safety.md +86 -0
- package/skills/matlab-runner/references/numerical-safety.md +126 -0
- package/skills/matlab-runner/references/resource-safety.md +125 -0
- package/skills/mixed-integer-programming/SKILL.md +119 -0
- package/skills/mixed-integer-programming/lp-examples.md +251 -0
- package/skills/mixed-integer-programming/mip-examples-verified.md +118 -0
- package/skills/open-problem-research-pipeline/SKILL.md +76 -0
- package/skills/open-problem-research-pipeline/skill_literature_analysis.md +201 -0
- package/skills/open-problem-research-pipeline/skill_literature_proof_framework.md +206 -0
- package/skills/open-problem-research-pipeline/skill_literature_search.md +172 -0
- package/skills/open-problem-research-pipeline/skill_qskill.md +177 -0
- package/skills/osqp-solver/SKILL.md +245 -0
- package/skills/osqp-solver/references/citation.md +25 -0
- package/skills/osqp-solver/references/dual-infeasible-example.json +14 -0
- package/skills/osqp-solver/references/feasible-example.json +21 -0
- package/skills/osqp-solver/references/primal-infeasible-example.json +17 -0
- package/skills/osqp-solver/references/python-api.md +95 -0
- package/skills/osqp-solver/references/verification.md +94 -0
- package/skills/osqp-solver/scripts/check_osqp_environment.py +120 -0
- package/skills/osqp-solver/scripts/solve_qp.py +943 -0
- package/skills/paper-writing/SKILL.md +115 -0
- package/skills/paper-writing/skill_claim_evidence_ledger.md +55 -0
- package/skills/paper-writing/skill_formula_environment_and_readability.md +41 -0
- package/skills/paper-writing/skill_latex_build_and_layout_audit.md +73 -0
- package/skills/paper-writing/skill_notation_and_variable_consistency.md +42 -0
- package/skills/paper-writing/skill_paper_skeleton_and_logical_architecture.md +54 -0
- package/skills/paper-writing/skill_proof_obligation_and_assumption_audit.md +57 -0
- package/skills/paper-writing/templates/claim-evidence-ledger.md +23 -0
- package/skills/paper-writing/templates/proof-obligation-ledger.md +22 -0
- package/skills/paper-writing/templates/rapid-prototype-paper-skeleton.md +46 -0
- package/skills/paper-writing/templates/source-packet.md +37 -0
- package/skills/paper-writing/templates/submission-readiness.md +41 -0
- package/skills/proof-blueprint-review/SKILL.md +129 -0
- package/skills/proof-blueprint-review/references/agent-mediated-proof-protocol.md +57 -0
- package/skills/proof-blueprint-review/references/generation-agent.md +45 -0
- package/skills/proof-blueprint-review/references/proof-acceptance-contract.md +41 -0
- package/skills/proof-blueprint-review/references/verification-agent.md +37 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# Lean-Specialist Agent Pattern Integration
|
|
2
|
+
|
|
3
|
+
This reference explains how the coding-agent-first skill incorporates publicly documented Lean-specialist agent designs without making any external agent mandatory. Preserve the mechanism, not prompts, benchmark-specific assumptions, or private implementation details. For the capability-by-capability distillation contract, read `lean_agent_capability_map.md`; for Lean LSP/MCP setup and tool policy, read `lean_lsp_mcp_adapter.md`.
|
|
4
|
+
|
|
5
|
+
## Source Families
|
|
6
|
+
|
|
7
|
+
- Numina-style coding-agent orchestration: project setup, official runner calls, Claude/MCP/tool integration, bounded external proof attempts, and local Lean validation.
|
|
8
|
+
- LeanDojo/ReProver-style loops: theorem state as the central object, premise retrieval, tactic generation, execution feedback, and proof search evaluation.
|
|
9
|
+
- LeanCopilot-style assistance: programmatic tactic, premise, and proof-search hooks that a human/coding agent can treat as optional suggestions.
|
|
10
|
+
- COPRA-style proof search: stateful attempts, backtracking, failed-strategy memory, and compact proof-state reporting.
|
|
11
|
+
- Lean LSP/MCP-style integration: editor/server feedback, goal inspection, diagnostics, and tool scope tied to the target project.
|
|
12
|
+
- Lightweight iterative agents: small edit/check loops, local context retrieval, and explicit stop conditions.
|
|
13
|
+
|
|
14
|
+
These sources provide patterns to adapt and integrate. Do not claim parity with a specialist prover unless the original backend is actually called and validated.
|
|
15
|
+
|
|
16
|
+
Public source anchors:
|
|
17
|
+
|
|
18
|
+
- Numina Lean Agent: `https://github.com/project-numina/numina-lean-agent`
|
|
19
|
+
- LeanDojo/ReProver: `https://github.com/lean-dojo/LeanDojo`
|
|
20
|
+
- LeanCopilot: `https://github.com/lean-dojo/LeanCopilot`
|
|
21
|
+
- COPRA: `https://github.com/trishullab/copra`
|
|
22
|
+
|
|
23
|
+
## Integrated Default Workflow
|
|
24
|
+
|
|
25
|
+
1. Gate the project: identify the Lake root, toolchain, mathlib revision, imports, and build status before proof work.
|
|
26
|
+
2. Normalize the target: locate the authoritative theorem statement, declaration name, hypotheses, namespace, and allowed statement changes.
|
|
27
|
+
3. Build a local context pack: nearby lemmas, imported modules, relevant declarations from `rg`, current goals, and prior failed attempts.
|
|
28
|
+
4. Run the theorem-state loop: make one small edit, run Lean, read the first concrete error or goal, update the context pack, and continue.
|
|
29
|
+
5. Use bounded search: try a small number of plausible tactic/proof routes; record failed routes so the agent does not cycle.
|
|
30
|
+
6. Retrieve before inventing: search existing project/mathlib names and nearby proofs before adding helper lemmas.
|
|
31
|
+
7. Validate as oracle: Lean/Lake success is required; final patches must not contain `sorry`, `admit`, new `axiom`, or unapproved statement drift.
|
|
32
|
+
8. Escalate deliberately: call a documented backend adapter only after that adapter has an explicit contract and validation gates, and only after explaining target, credentials/proxy/MCP state, result directory, and validation plan.
|
|
33
|
+
9. Hand off minimally: when blocked, return the smallest failing Lean fragment, exact goals/errors, tried routes, and the next mathematical decision.
|
|
34
|
+
|
|
35
|
+
## Pattern Map
|
|
36
|
+
|
|
37
|
+
| Specialist mechanism | Coding-agent integration |
|
|
38
|
+
| --- | --- |
|
|
39
|
+
| Runtime/environment gate | `env`, `doctor`, `configure`, direct Lake root inspection |
|
|
40
|
+
| Theorem-state centered search | Lean error/goal loop after each small edit |
|
|
41
|
+
| Premise retrieval | `rg`, nearby imports/proofs, project declarations, optional external search |
|
|
42
|
+
| Bounded proof attempts | `max_rounds`, local iteration caps, failed-strategy notes |
|
|
43
|
+
| Backtracking/failure memory | Record tried tactic families and rejected statement changes |
|
|
44
|
+
| Lean LSP/MCP goal tooling | Optional adapter recipe for goal state, diagnostics, hover, local search, external search, and multi-attempt screening |
|
|
45
|
+
| Lean-specialist backend adapter | Adapter-first optional escalation; Numina, Lean LSP/MCP, Archon, and LeanCopilot are adapter candidates, never required for default work |
|
|
46
|
+
| Validation oracle | Lean/Lake plus `review` and `detect-sorry` |
|
|
47
|
+
| Failure artifact | `minimize-failure` and exact errors/goals |
|
|
48
|
+
|
|
49
|
+
## Escalation Rule
|
|
50
|
+
|
|
51
|
+
Default to integrated local patterns. Escalate to a real specialist backend only when:
|
|
52
|
+
|
|
53
|
+
- the user asks for Numina, official Lean Agent, batch proof search, or an approved external subagent;
|
|
54
|
+
- local bounded attempts are cycling and the user approves a backend call;
|
|
55
|
+
- the required credentials, proxy, MCP scope, and target project are understood;
|
|
56
|
+
- all backend output will still be reviewed and checked locally.
|
|
57
|
+
|
|
58
|
+
## Anti-Patterns
|
|
59
|
+
|
|
60
|
+
- Do not replace proof work with a CLI workflow that only asks the user for more input.
|
|
61
|
+
- Do not treat a missing Numina key or backend adapter as blocking ordinary coding-agent Lean work.
|
|
62
|
+
- Do not copy upstream prompts or claim hidden benchmark behavior.
|
|
63
|
+
- Do not add helper lemmas or theorem statement changes just to make a proof easier unless the user approves.
|
|
64
|
+
- Do not let an external backend output bypass local Lean validation and patch review.
|
|
65
|
+
- Do not call a backend adapter unless its setup, call, credential, mutation, and validation contracts are documented.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"title": "AI4Math Lean Agent Config",
|
|
4
|
+
"type": "object",
|
|
5
|
+
"properties": {
|
|
6
|
+
"lean": {"type": "object", "additionalProperties": true},
|
|
7
|
+
"agent": {"type": "object", "additionalProperties": true},
|
|
8
|
+
"policy": {"type": "object", "additionalProperties": true},
|
|
9
|
+
"numina": {"type": "object", "additionalProperties": true}
|
|
10
|
+
},
|
|
11
|
+
"additionalProperties": false
|
|
12
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"title": "AI4Math Lean Agent Result",
|
|
4
|
+
"type": "object",
|
|
5
|
+
"properties": {
|
|
6
|
+
"ok": {"type": "boolean"},
|
|
7
|
+
"status": {"type": "string"},
|
|
8
|
+
"agent_mode": {"type": "string"},
|
|
9
|
+
"backend": {"type": "string"},
|
|
10
|
+
"task_type": {"type": "string"},
|
|
11
|
+
"cwd": {"type": "string"},
|
|
12
|
+
"target": {"type": "string"},
|
|
13
|
+
"project_root": {"type": ["string", "null"]},
|
|
14
|
+
"target_project_root": {"type": ["string", "null"]},
|
|
15
|
+
"workspace_project_root": {"type": ["string", "null"]},
|
|
16
|
+
"workspace_path": {"type": ["string", "null"]},
|
|
17
|
+
"workspace_mode": {"type": "string"},
|
|
18
|
+
"toolchain": {"type": ["string", "null"]},
|
|
19
|
+
"mathlib_revision": {"type": ["string", "null"]},
|
|
20
|
+
"configuration_status": {"type": "string"},
|
|
21
|
+
"missing_config": {"type": "array", "items": {"type": "string"}},
|
|
22
|
+
"required_inputs": {"type": "array", "items": {"type": "string"}},
|
|
23
|
+
"numina_workflow": {"type": "array", "items": {"type": "string"}},
|
|
24
|
+
"direct_workflow": {"type": "array", "items": {"type": "string"}},
|
|
25
|
+
"changed_files": {"type": "array", "items": {"type": "string"}},
|
|
26
|
+
"errors": {"type": "array", "items": {"type": "object", "additionalProperties": true}},
|
|
27
|
+
"warnings": {"type": "array", "items": {"type": "object", "additionalProperties": true}},
|
|
28
|
+
"minimal_failure": {"type": "object", "additionalProperties": true},
|
|
29
|
+
"recommended_next_action": {"type": "string"}
|
|
30
|
+
},
|
|
31
|
+
"required": ["ok", "status"],
|
|
32
|
+
"additionalProperties": true
|
|
33
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"title": "AI4Math Lean Agent Task",
|
|
4
|
+
"type": "object",
|
|
5
|
+
"properties": {
|
|
6
|
+
"task_id": {"type": "string"},
|
|
7
|
+
"task_type": {
|
|
8
|
+
"type": "string",
|
|
9
|
+
"enum": ["check", "configure", "prove_theorem", "formalize_statement", "repair_file", "complete_sorries", "batch", "review", "minimize_failure"]
|
|
10
|
+
},
|
|
11
|
+
"agent_mode": {"type": "string", "enum": ["coding-agent", "numina-subagent", "hybrid"], "default": "coding-agent"},
|
|
12
|
+
"backend": {"type": "string", "enum": ["none", "official-numina"], "default": "none"},
|
|
13
|
+
"cwd": {"type": "string"},
|
|
14
|
+
"file": {"type": "string"},
|
|
15
|
+
"folder": {"type": "string"},
|
|
16
|
+
"target": {"type": "string"},
|
|
17
|
+
"source_statement": {"type": "string"},
|
|
18
|
+
"source_statement_file": {"type": "string"},
|
|
19
|
+
"source_format": {"type": "string", "enum": ["natural_language", "latex", "lean", "mixed"]},
|
|
20
|
+
"statement_confirmed": {"type": "boolean", "default": false},
|
|
21
|
+
"interaction_mode": {"type": "string", "enum": ["interactive", "noninteractive"], "default": "interactive"},
|
|
22
|
+
"configuration": {"type": "object", "additionalProperties": true},
|
|
23
|
+
"subtasks": {"type": "array", "items": {"type": "object", "additionalProperties": true}},
|
|
24
|
+
"max_rounds": {"type": "integer", "minimum": 1, "default": 5},
|
|
25
|
+
"dry_run": {"type": "boolean", "default": false},
|
|
26
|
+
"constraints": {"type": "object", "additionalProperties": true}
|
|
27
|
+
},
|
|
28
|
+
"required": ["task_type"],
|
|
29
|
+
"additionalProperties": false
|
|
30
|
+
}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import argparse
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from check_lean_project import check_file, check_project
|
|
9
|
+
from common import emit_json
|
|
10
|
+
from configure_lean import configure, inspect_environment
|
|
11
|
+
from detect_sorry import scan_file
|
|
12
|
+
from direct_task import run_direct_task
|
|
13
|
+
from extract_minimal_failure import extract
|
|
14
|
+
from numina_runtime import numina_readiness
|
|
15
|
+
from smoke_test import run_smoke_test
|
|
16
|
+
from tool_status import doctor
|
|
17
|
+
from validate_patch import review_files
|
|
18
|
+
from verify_delivery import verify as verify_delivery
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
EXIT_OK = 0
|
|
22
|
+
EXIT_MISSING_CONFIG = 4
|
|
23
|
+
EXIT_LEAN_FAILED = 6
|
|
24
|
+
EXIT_PATCH_VIOLATION = 7
|
|
25
|
+
EXIT_INTERACTIVE_REQUIRED = 10
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _exit_code(result: dict[str, Any], default_fail: int = 1) -> int:
|
|
29
|
+
if result.get("ok"):
|
|
30
|
+
return EXIT_OK
|
|
31
|
+
status = result.get("status")
|
|
32
|
+
if status in {"missing_config", "direct_task_missing_config"}:
|
|
33
|
+
return EXIT_MISSING_CONFIG
|
|
34
|
+
if status in {"missing_lean_project", "lean_build_failed", "lean_file_failed", "lean_workspace_setup_failed"}:
|
|
35
|
+
return EXIT_LEAN_FAILED
|
|
36
|
+
if status == "patch_safety_violation":
|
|
37
|
+
return EXIT_PATCH_VIOLATION
|
|
38
|
+
if status == "interactive_required":
|
|
39
|
+
return EXIT_INTERACTIVE_REQUIRED
|
|
40
|
+
return default_fail
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _finish(result: dict[str, Any], json_output: str | None = None, fail_code: int = 1) -> None:
|
|
44
|
+
emit_json(result, json_output=json_output)
|
|
45
|
+
raise SystemExit(_exit_code(result, default_fail=fail_code))
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def add_common(parser: argparse.ArgumentParser) -> None:
|
|
49
|
+
parser.add_argument("--cwd", default=".", help="Lean project or workspace directory")
|
|
50
|
+
parser.add_argument("--config", default=None, help="Optional TOML config path")
|
|
51
|
+
parser.add_argument("--json-output", default=None, help="Write JSON result to this path")
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
55
|
+
parser = argparse.ArgumentParser(description="AI4Math coding-agent Lean skill CLI with optional Lean-specialist backend adapter support")
|
|
56
|
+
sub = parser.add_subparsers(dest="command", required=True)
|
|
57
|
+
|
|
58
|
+
env = sub.add_parser("env", help="Inspect Lean workspace and optional backend adapter environment")
|
|
59
|
+
add_common(env)
|
|
60
|
+
env.add_argument("--target", default=None)
|
|
61
|
+
|
|
62
|
+
doctor_parser = sub.add_parser("doctor", help="Report local tool availability")
|
|
63
|
+
add_common(doctor_parser)
|
|
64
|
+
|
|
65
|
+
check = sub.add_parser("check", help="Check Lean project or file")
|
|
66
|
+
add_common(check)
|
|
67
|
+
check.add_argument("--file", default=None)
|
|
68
|
+
check.add_argument("--skip-build", action="store_true")
|
|
69
|
+
check.add_argument("--timeout", type=int, default=300)
|
|
70
|
+
|
|
71
|
+
smoke = sub.add_parser("smoke-test", help="Run the bundled Lean smoke target in the shared workspace")
|
|
72
|
+
add_common(smoke)
|
|
73
|
+
smoke.add_argument("--timeout", type=int, default=120)
|
|
74
|
+
smoke.add_argument("--dry-run", action="store_true")
|
|
75
|
+
|
|
76
|
+
configure_parser = sub.add_parser("configure", help="Inspect or create local Lean workspace configuration")
|
|
77
|
+
add_common(configure_parser)
|
|
78
|
+
configure_parser.add_argument("--target", default=None)
|
|
79
|
+
configure_parser.add_argument("--create-workspace", action="store_true")
|
|
80
|
+
configure_parser.add_argument("--toolchain", default=None, help="Override the default AI4Math managed workspace toolchain")
|
|
81
|
+
configure_parser.add_argument("--save-local", action="store_true")
|
|
82
|
+
configure_parser.add_argument("--dry-run", action="store_true")
|
|
83
|
+
configure_parser.add_argument("--setup-numina", action="store_true", help="Install/configure official Numina runtime after review")
|
|
84
|
+
configure_parser.add_argument("--project-name", default=None, help="Lean project name for official Numina tutorial setup")
|
|
85
|
+
|
|
86
|
+
for name in ("prove", "formalize", "repair", "complete-sorries"):
|
|
87
|
+
proof = sub.add_parser(name, help=f"Prepare a coding-agent {name} task")
|
|
88
|
+
add_common(proof)
|
|
89
|
+
proof.add_argument("--file", required=True)
|
|
90
|
+
proof.add_argument("--target", default=None)
|
|
91
|
+
proof.add_argument("--max-rounds", type=int, default=5)
|
|
92
|
+
proof.add_argument("--prompt-file", default=None)
|
|
93
|
+
proof.add_argument("--result-dir", default=None)
|
|
94
|
+
proof.add_argument("--dry-run", action="store_true")
|
|
95
|
+
if name == "formalize":
|
|
96
|
+
proof.add_argument("--statement-file", default=None)
|
|
97
|
+
|
|
98
|
+
batch = sub.add_parser("batch", help="Prepare a coding-agent folder task")
|
|
99
|
+
add_common(batch)
|
|
100
|
+
batch.add_argument("--folder", required=True)
|
|
101
|
+
batch.add_argument("--max-rounds", type=int, default=5)
|
|
102
|
+
batch.add_argument("--prompt-file", default=None)
|
|
103
|
+
batch.add_argument("--result-dir", default=None)
|
|
104
|
+
batch.add_argument("--dry-run", action="store_true")
|
|
105
|
+
|
|
106
|
+
review = sub.add_parser("review", help="Review before/after Lean patch")
|
|
107
|
+
review.add_argument("--before", required=True)
|
|
108
|
+
review.add_argument("--after", required=True)
|
|
109
|
+
review.add_argument("--allow-statement-changes", action="store_true")
|
|
110
|
+
review.add_argument("--json-output", default=None)
|
|
111
|
+
|
|
112
|
+
detect = sub.add_parser("detect-sorry", help="Detect sorry/admit/axiom")
|
|
113
|
+
detect.add_argument("--file", required=True)
|
|
114
|
+
detect.add_argument("--json-output", default=None)
|
|
115
|
+
|
|
116
|
+
minimize = sub.add_parser("minimize-failure", help="Extract a small failing Lean fragment")
|
|
117
|
+
add_common(minimize)
|
|
118
|
+
minimize.add_argument("--file", required=True)
|
|
119
|
+
minimize.add_argument("--target", default=None)
|
|
120
|
+
minimize.add_argument("--run-lean", action="store_true")
|
|
121
|
+
minimize.add_argument("--timeout", type=int, default=120)
|
|
122
|
+
|
|
123
|
+
delivery = sub.add_parser("verify-delivery", help="Run delivery readiness checks for this skill")
|
|
124
|
+
add_common(delivery)
|
|
125
|
+
delivery.add_argument("--require-environment", action="store_true")
|
|
126
|
+
delivery.add_argument("--include-workspace-build", action="store_true")
|
|
127
|
+
delivery.add_argument("--run-tests", action="store_true")
|
|
128
|
+
|
|
129
|
+
return parser
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def main(argv: list[str] | None = None) -> None:
|
|
133
|
+
args = build_parser().parse_args(argv)
|
|
134
|
+
|
|
135
|
+
if args.command == "env":
|
|
136
|
+
result = inspect_environment(args.cwd, config_path=args.config, target=args.target)
|
|
137
|
+
_finish(result, args.json_output, fail_code=EXIT_MISSING_CONFIG)
|
|
138
|
+
|
|
139
|
+
if args.command == "doctor":
|
|
140
|
+
result = doctor(args.cwd)
|
|
141
|
+
result["numina"] = numina_readiness(args.cwd)
|
|
142
|
+
_finish(result, args.json_output)
|
|
143
|
+
|
|
144
|
+
if args.command == "check":
|
|
145
|
+
if args.file:
|
|
146
|
+
result = check_project(args.cwd, skip_build=True, file=args.file, timeout=args.timeout) if args.skip_build else check_file(args.file, timeout=args.timeout)
|
|
147
|
+
else:
|
|
148
|
+
result = check_project(args.cwd, skip_build=args.skip_build, timeout=args.timeout)
|
|
149
|
+
_finish(result, args.json_output, fail_code=EXIT_LEAN_FAILED)
|
|
150
|
+
|
|
151
|
+
if args.command == "smoke-test":
|
|
152
|
+
result = run_smoke_test(args.cwd, config_path=args.config, timeout=args.timeout, dry_run=args.dry_run)
|
|
153
|
+
_finish(result, args.json_output, fail_code=EXIT_LEAN_FAILED)
|
|
154
|
+
|
|
155
|
+
if args.command == "configure":
|
|
156
|
+
result = configure(
|
|
157
|
+
args.cwd,
|
|
158
|
+
config_path=args.config,
|
|
159
|
+
target=args.target,
|
|
160
|
+
create_workspace=args.create_workspace,
|
|
161
|
+
toolchain=args.toolchain,
|
|
162
|
+
save_local=args.save_local,
|
|
163
|
+
dry_run=args.dry_run,
|
|
164
|
+
setup_numina=args.setup_numina,
|
|
165
|
+
project_name=args.project_name,
|
|
166
|
+
)
|
|
167
|
+
_finish(result, args.json_output, fail_code=EXIT_INTERACTIVE_REQUIRED)
|
|
168
|
+
|
|
169
|
+
if args.command in {"prove", "formalize", "repair", "complete-sorries"}:
|
|
170
|
+
result = run_direct_task(
|
|
171
|
+
args.command,
|
|
172
|
+
cwd=args.cwd,
|
|
173
|
+
target=args.file,
|
|
174
|
+
max_rounds=args.max_rounds,
|
|
175
|
+
config_path=args.config,
|
|
176
|
+
prompt_file=args.prompt_file,
|
|
177
|
+
result_dir=args.result_dir,
|
|
178
|
+
dry_run=args.dry_run,
|
|
179
|
+
)
|
|
180
|
+
if args.command == "formalize" and args.statement_file:
|
|
181
|
+
result["statement_file"] = str(Path(args.statement_file).expanduser().resolve())
|
|
182
|
+
if args.target:
|
|
183
|
+
result["target_declaration"] = args.target
|
|
184
|
+
_finish(result, args.json_output, fail_code=EXIT_MISSING_CONFIG)
|
|
185
|
+
|
|
186
|
+
if args.command == "batch":
|
|
187
|
+
result = run_direct_task(
|
|
188
|
+
"batch",
|
|
189
|
+
cwd=args.cwd,
|
|
190
|
+
target=args.folder,
|
|
191
|
+
max_rounds=args.max_rounds,
|
|
192
|
+
config_path=args.config,
|
|
193
|
+
prompt_file=args.prompt_file,
|
|
194
|
+
result_dir=args.result_dir,
|
|
195
|
+
dry_run=args.dry_run,
|
|
196
|
+
)
|
|
197
|
+
_finish(result, args.json_output, fail_code=EXIT_MISSING_CONFIG)
|
|
198
|
+
|
|
199
|
+
if args.command == "review":
|
|
200
|
+
result = review_files(args.before, args.after, allow_statement_changes=args.allow_statement_changes)
|
|
201
|
+
_finish(result, args.json_output, fail_code=EXIT_PATCH_VIOLATION)
|
|
202
|
+
|
|
203
|
+
if args.command == "detect-sorry":
|
|
204
|
+
result = scan_file(args.file)
|
|
205
|
+
_finish(result, args.json_output, fail_code=EXIT_PATCH_VIOLATION)
|
|
206
|
+
|
|
207
|
+
if args.command == "minimize-failure":
|
|
208
|
+
result = extract(args.file, target=args.target, run_lean=args.run_lean, timeout=args.timeout)
|
|
209
|
+
_finish(result, args.json_output, fail_code=EXIT_LEAN_FAILED)
|
|
210
|
+
|
|
211
|
+
if args.command == "verify-delivery":
|
|
212
|
+
result = verify_delivery(
|
|
213
|
+
cwd=args.cwd,
|
|
214
|
+
require_environment=args.require_environment,
|
|
215
|
+
include_workspace_build=args.include_workspace_build,
|
|
216
|
+
run_tests=args.run_tests,
|
|
217
|
+
)
|
|
218
|
+
_finish(result, args.json_output)
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
if __name__ == "__main__":
|
|
222
|
+
main()
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import re
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from common import run_command
|
|
9
|
+
from tool_status import find_tool
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def has_lakefile(path: Path) -> bool:
|
|
13
|
+
return (path / "lakefile.toml").exists() or (path / "lakefile.lean").exists()
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def find_project_root(path: str | Path) -> Path | None:
|
|
17
|
+
target = Path(path).expanduser().resolve()
|
|
18
|
+
current = target.parent if target.is_file() else target
|
|
19
|
+
while True:
|
|
20
|
+
if (current / "lean-toolchain").exists() and has_lakefile(current):
|
|
21
|
+
return current
|
|
22
|
+
if current.parent == current:
|
|
23
|
+
return None
|
|
24
|
+
current = current.parent
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def read_toolchain(root: Path | None) -> str | None:
|
|
28
|
+
if not root:
|
|
29
|
+
return None
|
|
30
|
+
toolchain = root / "lean-toolchain"
|
|
31
|
+
if not toolchain.exists():
|
|
32
|
+
return None
|
|
33
|
+
return toolchain.read_text(encoding="utf-8", errors="replace").strip() or None
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _search_manifest(value: Any) -> str | None:
|
|
37
|
+
if isinstance(value, dict):
|
|
38
|
+
name = value.get("name")
|
|
39
|
+
if name == "mathlib":
|
|
40
|
+
for key in ("rev", "revision", "inputRev", "gitRev"):
|
|
41
|
+
found = value.get(key)
|
|
42
|
+
if isinstance(found, str) and found:
|
|
43
|
+
return found
|
|
44
|
+
for item in value.values():
|
|
45
|
+
found = _search_manifest(item)
|
|
46
|
+
if found:
|
|
47
|
+
return found
|
|
48
|
+
elif isinstance(value, list):
|
|
49
|
+
for item in value:
|
|
50
|
+
found = _search_manifest(item)
|
|
51
|
+
if found:
|
|
52
|
+
return found
|
|
53
|
+
return None
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def read_mathlib_revision(root: Path | None) -> str | None:
|
|
57
|
+
if not root:
|
|
58
|
+
return None
|
|
59
|
+
manifest = root / "lake-manifest.json"
|
|
60
|
+
if manifest.exists():
|
|
61
|
+
try:
|
|
62
|
+
return _search_manifest(json.loads(manifest.read_text(encoding="utf-8")))
|
|
63
|
+
except json.JSONDecodeError:
|
|
64
|
+
pass
|
|
65
|
+
|
|
66
|
+
for lakefile in (root / "lakefile.toml", root / "lakefile.lean"):
|
|
67
|
+
if not lakefile.exists():
|
|
68
|
+
continue
|
|
69
|
+
text = lakefile.read_text(encoding="utf-8", errors="replace")
|
|
70
|
+
require_match = re.search(r'name\s*=\s*"mathlib".{0,400}?rev\s*=\s*"([^"]+)"', text, re.S)
|
|
71
|
+
if require_match:
|
|
72
|
+
return require_match.group(1)
|
|
73
|
+
lean_match = re.search(r'require\s+mathlib\b.*?@\s*"?([A-Za-z0-9_.:/-]+)"?', text)
|
|
74
|
+
if lean_match:
|
|
75
|
+
return lean_match.group(1)
|
|
76
|
+
return None
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def check_project(cwd: str | Path = ".", skip_build: bool = False, file: str | Path | None = None, timeout: int = 300) -> dict[str, Any]:
|
|
80
|
+
target = Path(file).expanduser().resolve() if file else Path(cwd).expanduser().resolve()
|
|
81
|
+
root = find_project_root(target)
|
|
82
|
+
result: dict[str, Any] = {
|
|
83
|
+
"ok": root is not None,
|
|
84
|
+
"status": "ok" if root else "missing_lean_project",
|
|
85
|
+
"cwd": str(Path(cwd).expanduser().resolve()),
|
|
86
|
+
"target": str(target),
|
|
87
|
+
"project_root": str(root) if root else None,
|
|
88
|
+
"toolchain": read_toolchain(root),
|
|
89
|
+
"mathlib_revision": read_mathlib_revision(root),
|
|
90
|
+
"has_lakefile": bool(root and has_lakefile(root)),
|
|
91
|
+
"build": None,
|
|
92
|
+
"errors": [],
|
|
93
|
+
}
|
|
94
|
+
if root is None:
|
|
95
|
+
result["errors"].append({"severity": "error", "data": "No ancestor contains both lean-toolchain and lakefile.toml/lakefile.lean"})
|
|
96
|
+
return result
|
|
97
|
+
if skip_build:
|
|
98
|
+
result["status"] = "ok_skip_build"
|
|
99
|
+
return result
|
|
100
|
+
lake = find_tool("lake") or "lake"
|
|
101
|
+
build = run_command([lake, "build"], cwd=root, timeout=timeout)
|
|
102
|
+
result["build"] = build
|
|
103
|
+
result["ok"] = bool(build["ok"])
|
|
104
|
+
result["status"] = "ok" if build["ok"] else "lean_build_failed"
|
|
105
|
+
if not build["ok"]:
|
|
106
|
+
result["errors"].append({"severity": "error", "data": build.get("stderr") or build.get("stdout") or "lake build failed"})
|
|
107
|
+
return result
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def check_file(file: str | Path, timeout: int = 300) -> dict[str, Any]:
|
|
111
|
+
file_path = Path(file).expanduser().resolve()
|
|
112
|
+
root = find_project_root(file_path)
|
|
113
|
+
if root is None:
|
|
114
|
+
return {
|
|
115
|
+
"ok": False,
|
|
116
|
+
"status": "missing_lean_project",
|
|
117
|
+
"file": str(file_path),
|
|
118
|
+
"project_root": None,
|
|
119
|
+
"toolchain": None,
|
|
120
|
+
"mathlib_revision": None,
|
|
121
|
+
"errors": [{"severity": "error", "data": "File is not inside a Lake project"}],
|
|
122
|
+
}
|
|
123
|
+
lake = find_tool("lake") or "lake"
|
|
124
|
+
run = run_command([lake, "env", "lean", str(file_path)], cwd=root, timeout=timeout)
|
|
125
|
+
return {
|
|
126
|
+
"ok": bool(run["ok"]),
|
|
127
|
+
"status": "ok" if run["ok"] else "lean_file_failed",
|
|
128
|
+
"file": str(file_path),
|
|
129
|
+
"project_root": str(root),
|
|
130
|
+
"toolchain": read_toolchain(root),
|
|
131
|
+
"mathlib_revision": read_mathlib_revision(root),
|
|
132
|
+
"lean": run,
|
|
133
|
+
"errors": [] if run["ok"] else [{"severity": "error", "data": run.get("stderr") or run.get("stdout") or "lean check failed"}],
|
|
134
|
+
}
|