@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,81 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import difflib
|
|
4
|
+
import re
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from detect_sorry import scan_text
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
DECL_RE = re.compile(r"^\s*(theorem|lemma|def|class|structure|inductive)\s+([A-Za-z_][\w'.]*)\b(.*)")
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def collect_declarations(text: str) -> dict[str, str]:
|
|
15
|
+
declarations: dict[str, str] = {}
|
|
16
|
+
for line in text.splitlines():
|
|
17
|
+
match = DECL_RE.match(line)
|
|
18
|
+
if not match:
|
|
19
|
+
continue
|
|
20
|
+
kind, name, rest = match.groups()
|
|
21
|
+
header = f"{kind} {name} {rest}".split(":=", 1)[0].strip()
|
|
22
|
+
declarations[name] = re.sub(r"\s+", " ", header)
|
|
23
|
+
return declarations
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def review_patch(before_text: str, after_text: str, allow_statement_changes: bool = False) -> dict[str, Any]:
|
|
27
|
+
after_scan = scan_text(after_text, source="after")
|
|
28
|
+
before_decls = collect_declarations(before_text)
|
|
29
|
+
after_decls = collect_declarations(after_text)
|
|
30
|
+
statement_changes = []
|
|
31
|
+
for name, before_header in before_decls.items():
|
|
32
|
+
after_header = after_decls.get(name)
|
|
33
|
+
if after_header and before_header != after_header:
|
|
34
|
+
statement_changes.append({
|
|
35
|
+
"declaration": name,
|
|
36
|
+
"before": before_header,
|
|
37
|
+
"after": after_header,
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
findings: list[dict[str, Any]] = []
|
|
41
|
+
findings.extend(after_scan.get("findings", []))
|
|
42
|
+
if statement_changes and not allow_statement_changes:
|
|
43
|
+
findings.append({
|
|
44
|
+
"kind": "statement_changed",
|
|
45
|
+
"changes": statement_changes,
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
"ok": not findings,
|
|
50
|
+
"status": "ok" if not findings else "patch_safety_violation",
|
|
51
|
+
"forbidden_findings": after_scan.get("findings", []),
|
|
52
|
+
"statement_changes": statement_changes,
|
|
53
|
+
"diff": "\n".join(difflib.unified_diff(
|
|
54
|
+
before_text.splitlines(),
|
|
55
|
+
after_text.splitlines(),
|
|
56
|
+
fromfile="before",
|
|
57
|
+
tofile="after",
|
|
58
|
+
lineterm="",
|
|
59
|
+
)),
|
|
60
|
+
"findings": findings,
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def review_files(before: str | Path, after: str | Path, allow_statement_changes: bool = False) -> dict[str, Any]:
|
|
65
|
+
before_path = Path(before).expanduser().resolve()
|
|
66
|
+
after_path = Path(after).expanduser().resolve()
|
|
67
|
+
if not before_path.exists() or not after_path.exists():
|
|
68
|
+
missing = [str(path) for path in (before_path, after_path) if not path.exists()]
|
|
69
|
+
return {
|
|
70
|
+
"ok": False,
|
|
71
|
+
"status": "file_not_found",
|
|
72
|
+
"errors": [{"severity": "error", "data": f"Missing files: {', '.join(missing)}"}],
|
|
73
|
+
}
|
|
74
|
+
result = review_patch(
|
|
75
|
+
before_path.read_text(encoding="utf-8", errors="replace"),
|
|
76
|
+
after_path.read_text(encoding="utf-8", errors="replace"),
|
|
77
|
+
allow_statement_changes=allow_statement_changes,
|
|
78
|
+
)
|
|
79
|
+
result["before"] = str(before_path)
|
|
80
|
+
result["after"] = str(after_path)
|
|
81
|
+
return result
|
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import json
|
|
5
|
+
import sys
|
|
6
|
+
import tempfile
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
from check_lean_project import check_project
|
|
11
|
+
from common import run_command
|
|
12
|
+
from configure_lean import inspect_environment
|
|
13
|
+
from direct_task import run_direct_task
|
|
14
|
+
from extract_minimal_failure import extract
|
|
15
|
+
from smoke_test import run_smoke_test
|
|
16
|
+
from tool_status import doctor, find_tool
|
|
17
|
+
from validate_patch import review_files
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
RUNTIME_ROOT = Path(__file__).resolve().parents[1]
|
|
21
|
+
SKILLS_ROOT = RUNTIME_ROOT.parent
|
|
22
|
+
FORMALIZATION_ROOT = SKILLS_ROOT / "lean-formalization"
|
|
23
|
+
SETUP_ROOT = SKILLS_ROOT / "lean-setup"
|
|
24
|
+
REQUIRED_FORMALIZATION_FILES = [
|
|
25
|
+
"SKILL.md",
|
|
26
|
+
"agents/openai.yaml",
|
|
27
|
+
]
|
|
28
|
+
REQUIRED_RUNTIME_FILES = [
|
|
29
|
+
"config/lean_agent.example.toml",
|
|
30
|
+
"config/numina_runtime.example.toml",
|
|
31
|
+
"examples/smoke/LocalLeanSmoke.lean",
|
|
32
|
+
"schemas/task.schema.json",
|
|
33
|
+
"schemas/result.schema.json",
|
|
34
|
+
"schemas/config.schema.json",
|
|
35
|
+
"references/lean_runtime_configuration.md",
|
|
36
|
+
"references/backend_adapter_checklist.md",
|
|
37
|
+
"references/interactive_orchestration.md",
|
|
38
|
+
"references/direct_lean_workflow.md",
|
|
39
|
+
"references/specialist_agent_patterns.md",
|
|
40
|
+
"references/lean_agent_capability_map.md",
|
|
41
|
+
"references/lean_lsp_mcp_adapter.md",
|
|
42
|
+
"references/numina_runtime.md",
|
|
43
|
+
"references/numina_subagent_troubleshooting.md",
|
|
44
|
+
"references/review_checklist.md",
|
|
45
|
+
"references/failure_taxonomy.md",
|
|
46
|
+
"references/numina_reverse_analysis.md",
|
|
47
|
+
"scripts/ai4m_lean.py",
|
|
48
|
+
"scripts/configure_lean.py",
|
|
49
|
+
"scripts/direct_task.py",
|
|
50
|
+
"scripts/numina_runtime.py",
|
|
51
|
+
"scripts/smoke_test.py",
|
|
52
|
+
"scripts/validate_patch.py",
|
|
53
|
+
"scripts/extract_minimal_failure.py",
|
|
54
|
+
]
|
|
55
|
+
REQUIRED_COMMANDS = {
|
|
56
|
+
"env",
|
|
57
|
+
"doctor",
|
|
58
|
+
"configure",
|
|
59
|
+
"check",
|
|
60
|
+
"prove",
|
|
61
|
+
"formalize",
|
|
62
|
+
"repair",
|
|
63
|
+
"complete-sorries",
|
|
64
|
+
"batch",
|
|
65
|
+
"review",
|
|
66
|
+
"detect-sorry",
|
|
67
|
+
"minimize-failure",
|
|
68
|
+
"smoke-test",
|
|
69
|
+
"verify-delivery",
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _parser_commands() -> set[str]:
|
|
74
|
+
from ai4m_lean import build_parser
|
|
75
|
+
|
|
76
|
+
parser = build_parser()
|
|
77
|
+
for action in parser._actions:
|
|
78
|
+
if isinstance(action, argparse._SubParsersAction):
|
|
79
|
+
return set(action.choices)
|
|
80
|
+
return set()
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def _load_schema(path: Path) -> dict[str, Any]:
|
|
84
|
+
return json.loads(path.read_text(encoding="utf-8"))
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def _package_hygiene() -> dict[str, Any]:
|
|
88
|
+
package_roots = [RUNTIME_ROOT]
|
|
89
|
+
for root in (FORMALIZATION_ROOT, SETUP_ROOT):
|
|
90
|
+
if root.exists():
|
|
91
|
+
package_roots.append(root)
|
|
92
|
+
generated = [
|
|
93
|
+
str(path.relative_to(SKILLS_ROOT))
|
|
94
|
+
for root in package_roots
|
|
95
|
+
for path in root.rglob("*")
|
|
96
|
+
if "__pycache__" in path.parts or path.suffix == ".pyc"
|
|
97
|
+
]
|
|
98
|
+
suspicious_secret_patterns = [
|
|
99
|
+
"sk-" + "ant-",
|
|
100
|
+
"sk-" + "proj-",
|
|
101
|
+
"BEGIN " + "OPENAI API KEY",
|
|
102
|
+
]
|
|
103
|
+
secret_hits: list[str] = []
|
|
104
|
+
for root in package_roots:
|
|
105
|
+
paths = root.rglob("*")
|
|
106
|
+
for path in paths:
|
|
107
|
+
if not path.is_file() or "__pycache__" in path.parts or path.suffix == ".pyc":
|
|
108
|
+
continue
|
|
109
|
+
try:
|
|
110
|
+
text = path.read_text(encoding="utf-8", errors="replace")
|
|
111
|
+
except OSError:
|
|
112
|
+
continue
|
|
113
|
+
if any(pattern in text for pattern in suspicious_secret_patterns):
|
|
114
|
+
secret_hits.append(str(path.relative_to(SKILLS_ROOT)))
|
|
115
|
+
return {
|
|
116
|
+
"ok": not secret_hits,
|
|
117
|
+
"scanned_roots": [str(path) for path in package_roots],
|
|
118
|
+
"generated_files": generated,
|
|
119
|
+
"generated_files_note": "ignored by .gitignore; remove before packaging if creating an archive" if generated else None,
|
|
120
|
+
"secret_pattern_hits": secret_hits,
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def _guidance_first_check() -> dict[str, Any]:
|
|
125
|
+
text = (FORMALIZATION_ROOT / "SKILL.md").read_text(encoding="utf-8", errors="replace")
|
|
126
|
+
orchestration = (RUNTIME_ROOT / "references" / "interactive_orchestration.md").read_text(encoding="utf-8", errors="replace")
|
|
127
|
+
required_phrases = [
|
|
128
|
+
"## Agent Playbook",
|
|
129
|
+
"## Helper Toolbox",
|
|
130
|
+
"This is a coding-agent-first Lean skill.",
|
|
131
|
+
"The coding agent is the primary Lean worker.",
|
|
132
|
+
"Lean-specialist backend adapters are adapter-first optional escalation paths.",
|
|
133
|
+
"adapter-first",
|
|
134
|
+
"Built-in recommended adapter: official Numina Lean Agent runtime",
|
|
135
|
+
"Numina and Archon are recommended adapter candidates, not defaults or hard requirements",
|
|
136
|
+
"Other Lean-specialist backends may be connected by the coding agent through the backend adapter checklist",
|
|
137
|
+
"do not call any backend until deployment, readiness checks, invocation, validation, and failure triage are documented",
|
|
138
|
+
"Default coding-agent Lean work must not require any backend adapter.",
|
|
139
|
+
"Use a backend adapter only when the user asks for the official Lean Agent, Numina, Archon, batch proof search, or an approved external subagent run.",
|
|
140
|
+
"Default execution mode is coding-agent mode.",
|
|
141
|
+
"Incorporate publicly documented Lean-specialist agent patterns into the default coding-agent workflow.",
|
|
142
|
+
"Treat specialist-agent patterns as mechanisms, not mandatory external services.",
|
|
143
|
+
"This skill must act as a distilled Lean-agent capability layer",
|
|
144
|
+
"lean_agent_capability_map.md",
|
|
145
|
+
"lean_lsp_mcp_adapter.md",
|
|
146
|
+
"project gate, statement normalization, local context pack, retrieve-before-inventing, bounded tactic/proof attempts, failed-route memory, local validation, and minimal failure handoff",
|
|
147
|
+
"Use the bundled smoke test when no user target is available.",
|
|
148
|
+
"Lead the interaction; do not wait for the user to drive every step.",
|
|
149
|
+
"If the user's language is ambiguous, default to Chinese.",
|
|
150
|
+
"A language switch is not a task reset.",
|
|
151
|
+
"If no target is available, run or propose a safe local smoke/readiness check.",
|
|
152
|
+
"Avoid ending with only \"send me a file\"",
|
|
153
|
+
"Opening readiness should inspect local Lean readiness first",
|
|
154
|
+
"inspect Numina or another backend readiness only when the user asks for an optional Lean-specialist backend",
|
|
155
|
+
"Do not require API keys for the default coding-agent path.",
|
|
156
|
+
"Shared workspace is the default Lean project context; Numina may target it instead of upstream examples.",
|
|
157
|
+
"offer a small next-step menu",
|
|
158
|
+
"Ask at most one blocking question at a time.",
|
|
159
|
+
"The bundled CLI is a helper toolbox, not the workflow driver.",
|
|
160
|
+
"Use backend adapters through a human-in-the-loop workflow.",
|
|
161
|
+
"Do not turn helper commands into a closed proof workflow.",
|
|
162
|
+
"Do not remove the built-in official Numina adapter recipe.",
|
|
163
|
+
]
|
|
164
|
+
missing = [phrase for phrase in required_phrases if phrase not in text]
|
|
165
|
+
orchestration_required = [
|
|
166
|
+
"## Session Opening",
|
|
167
|
+
"This is a coding-agent-first Lean skill.",
|
|
168
|
+
"Backend integration is adapter-first.",
|
|
169
|
+
"Built-in recommended adapter: official Numina Lean Agent runtime",
|
|
170
|
+
"Numina and Archon are recommended adapter candidates, not defaults or hard requirements",
|
|
171
|
+
"Other Lean-specialist backends may be connected by the coding agent through the backend adapter checklist",
|
|
172
|
+
"The default coding-agent path should still absorb Lean-specialist agent mechanisms as a distilled Lean-agent loop:",
|
|
173
|
+
"distilled Lean-agent loop",
|
|
174
|
+
"local context packs",
|
|
175
|
+
"retrieve-before-inventing",
|
|
176
|
+
"lean_agent_capability_map.md",
|
|
177
|
+
"lean_lsp_mcp_adapter.md",
|
|
178
|
+
"Use the bundled smoke test when no user target is available.",
|
|
179
|
+
"Lead the interaction; do not wait for the user to drive every step.",
|
|
180
|
+
"A language switch is not a task reset.",
|
|
181
|
+
"If no target is available, run or propose a safe local smoke/readiness check.",
|
|
182
|
+
"Avoid ending with only \"send me a file\"",
|
|
183
|
+
"Opening readiness should inspect local Lean readiness first",
|
|
184
|
+
"Inspect Numina or another backend readiness only when the user asks for an optional Lean-specialist backend.",
|
|
185
|
+
"Do not require API keys for the default coding-agent path.",
|
|
186
|
+
"Shared workspace is the default Lean project context; Numina may target it instead of upstream examples.",
|
|
187
|
+
"A good opening ends with one decision question, not a checklist.",
|
|
188
|
+
]
|
|
189
|
+
orchestration_missing = [phrase for phrase in orchestration_required if phrase not in orchestration]
|
|
190
|
+
openai_yaml = (FORMALIZATION_ROOT / "agents" / "openai.yaml").read_text(encoding="utf-8", errors="replace")
|
|
191
|
+
openai_required = [
|
|
192
|
+
"请用中文开始",
|
|
193
|
+
"如果用户明确使用其他语言",
|
|
194
|
+
"默认走 distilled coding-agent Lean 工作流",
|
|
195
|
+
"该 skill 参考并整合",
|
|
196
|
+
"distilled coding-agent Lean 工作流",
|
|
197
|
+
"Lean-agent capability distillation",
|
|
198
|
+
"local context pack",
|
|
199
|
+
"retrieve-before-inventing",
|
|
200
|
+
"failed-route memory",
|
|
201
|
+
"adapter-first",
|
|
202
|
+
"当前内置推荐 adapter 是 official Numina Lean Agent runtime",
|
|
203
|
+
"Numina 和 Archon 是推荐 adapter candidates,不是默认项或硬依赖",
|
|
204
|
+
"Lean LSP/MCP 只有在用户明确要求",
|
|
205
|
+
"其他 backend 可由 coding agent 按 backend adapter checklist 接入",
|
|
206
|
+
"默认开场检查本地 Lean/shared workspace readiness",
|
|
207
|
+
"仅当用户要求 optional backend 时再检查 backend readiness",
|
|
208
|
+
]
|
|
209
|
+
openai_missing = [phrase for phrase in openai_required if phrase not in openai_yaml]
|
|
210
|
+
return {
|
|
211
|
+
"ok": not missing and not orchestration_missing and not openai_missing and "## Commands" not in text,
|
|
212
|
+
"missing_phrases": missing,
|
|
213
|
+
"orchestration_missing_phrases": orchestration_missing,
|
|
214
|
+
"openai_yaml_missing_phrases": openai_missing,
|
|
215
|
+
"commands_section_present": "## Commands" in text,
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def _root_discovery_boundary_check() -> dict[str, Any]:
|
|
220
|
+
repo_root = SKILLS_ROOT.parent
|
|
221
|
+
root_skill = repo_root / "SKILL.md"
|
|
222
|
+
if not root_skill.exists():
|
|
223
|
+
return {
|
|
224
|
+
"ok": True,
|
|
225
|
+
"root_skill": None,
|
|
226
|
+
"skipped": True,
|
|
227
|
+
"root_setup_only_trigger_hits": [],
|
|
228
|
+
}
|
|
229
|
+
text = root_skill.read_text(encoding="utf-8", errors="replace")
|
|
230
|
+
frontmatter = text.split("---", 2)[1] if text.startswith("---") and text.count("---") >= 2 else text
|
|
231
|
+
setup_only_triggers = [
|
|
232
|
+
"Lean environment setup",
|
|
233
|
+
"installing Lean",
|
|
234
|
+
"install Lean",
|
|
235
|
+
"checking elan",
|
|
236
|
+
"elan/lake",
|
|
237
|
+
"mathlib workspace",
|
|
238
|
+
"shared Lean environment",
|
|
239
|
+
]
|
|
240
|
+
hits = [phrase for phrase in setup_only_triggers if phrase in frontmatter]
|
|
241
|
+
return {
|
|
242
|
+
"ok": not hits,
|
|
243
|
+
"root_skill": str(root_skill),
|
|
244
|
+
"skipped": False,
|
|
245
|
+
"root_setup_only_trigger_hits": hits,
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
def _lean_setup_entrypoint_check() -> dict[str, Any]:
|
|
250
|
+
skill_path = SETUP_ROOT / "SKILL.md"
|
|
251
|
+
openai_path = SETUP_ROOT / "agents" / "openai.yaml"
|
|
252
|
+
helper_script = RUNTIME_ROOT / "scripts" / "ai4m_lean.py"
|
|
253
|
+
required_files = [skill_path, openai_path]
|
|
254
|
+
if not all(path.exists() for path in required_files):
|
|
255
|
+
return {
|
|
256
|
+
"ok": False,
|
|
257
|
+
"setup_root": str(SETUP_ROOT),
|
|
258
|
+
"helper_script": str(helper_script),
|
|
259
|
+
"helper_script_exists": helper_script.exists(),
|
|
260
|
+
"missing_files": [str(path) for path in required_files if not path.exists()],
|
|
261
|
+
"missing_phrases": [],
|
|
262
|
+
"openai_yaml_missing_phrases": [],
|
|
263
|
+
"repo_root_command_hits": [],
|
|
264
|
+
}
|
|
265
|
+
text = skill_path.read_text(encoding="utf-8", errors="replace")
|
|
266
|
+
openai_yaml = openai_path.read_text(encoding="utf-8", errors="replace")
|
|
267
|
+
required_phrases = [
|
|
268
|
+
"Use this setup-only entrypoint",
|
|
269
|
+
"Do not ask for a theorem target in setup-only mode.",
|
|
270
|
+
"The shared implementation lives in `../lean-runtime/`.",
|
|
271
|
+
"../lean-runtime/scripts/ai4m_lean.py",
|
|
272
|
+
"Install Lean through the official `elan` channel",
|
|
273
|
+
"When creating an isolated test directory or workspace",
|
|
274
|
+
"suggest a safe default name",
|
|
275
|
+
"use the default if the user has no naming preference",
|
|
276
|
+
"canonical managed workspace",
|
|
277
|
+
"AI4Math managed baseline toolchain `leanprover/lean4:v4.28.0`",
|
|
278
|
+
"reuse it instead of rebuilding or downloading again",
|
|
279
|
+
"Do not overwrite the canonical managed workspace",
|
|
280
|
+
"lean-workspaces/<version-key>/",
|
|
281
|
+
"After successful setup or smoke-test validation",
|
|
282
|
+
"Offer a short next-step menu",
|
|
283
|
+
"inspect an existing Lean/Lake project",
|
|
284
|
+
"repair a Lean file or complete `sorry`",
|
|
285
|
+
"formalize a natural-language or LaTeX theorem",
|
|
286
|
+
"mention optional Numina only when the user explicitly asks",
|
|
287
|
+
"Lean core ready",
|
|
288
|
+
"mathlib ready",
|
|
289
|
+
"partial readiness",
|
|
290
|
+
"`import Mathlib` tasks are blocked",
|
|
291
|
+
"Do not present this as full mathlib workspace readiness.",
|
|
292
|
+
"Do not recommend formalization, `sorry` completion, or Numina as the default next step while mathlib is missing.",
|
|
293
|
+
"git ls-remote https://github.com/leanprover-community/mathlib4.git HEAD",
|
|
294
|
+
"Remove-Item -Recurse -Force .lake\\packages\\mathlib",
|
|
295
|
+
"Do not require API keys for Lean/mathlib workspace setup.",
|
|
296
|
+
"hand off to `lean-formalization`",
|
|
297
|
+
]
|
|
298
|
+
repo_root_commands = [
|
|
299
|
+
"python skills/lean-formalization/scripts/ai4m_lean.py",
|
|
300
|
+
]
|
|
301
|
+
repo_root_command_hits = [phrase for phrase in repo_root_commands if phrase in text]
|
|
302
|
+
openai_required = [
|
|
303
|
+
"不要向用户索要 theorem target",
|
|
304
|
+
"已有 Lake 项目优先沿用项目自己的 lean-toolchain 和 lake-manifest",
|
|
305
|
+
"standalone 任务默认复用 ~/.ai4math/lean-workspace",
|
|
306
|
+
"AI4Math managed baseline leanprover/lean4:v4.28.0",
|
|
307
|
+
"避免重复下载和路径分裂",
|
|
308
|
+
"setup 完成后主动给出下一步菜单",
|
|
309
|
+
"区分 Lean core ready 和 mathlib ready",
|
|
310
|
+
"mathlib 未完成时不要把正式形式化、sorry completion 或 Numina 作为默认下一步",
|
|
311
|
+
"所有实现应复用 lean-runtime",
|
|
312
|
+
"默认 Lean/mathlib 环境配置不需要 API key",
|
|
313
|
+
"不要把 Numina 或其他 backend 放进默认下一步",
|
|
314
|
+
"应交接到 lean-formalization",
|
|
315
|
+
]
|
|
316
|
+
return {
|
|
317
|
+
"ok": (
|
|
318
|
+
helper_script.exists()
|
|
319
|
+
and not repo_root_command_hits
|
|
320
|
+
and all(phrase in text for phrase in required_phrases)
|
|
321
|
+
and all(phrase in openai_yaml for phrase in openai_required)
|
|
322
|
+
),
|
|
323
|
+
"setup_root": str(SETUP_ROOT),
|
|
324
|
+
"helper_script": str(helper_script),
|
|
325
|
+
"helper_script_exists": helper_script.exists(),
|
|
326
|
+
"missing_phrases": [phrase for phrase in required_phrases if phrase not in text],
|
|
327
|
+
"openai_yaml_missing_phrases": [phrase for phrase in openai_required if phrase not in openai_yaml],
|
|
328
|
+
"repo_root_command_hits": repo_root_command_hits,
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
def verify(
|
|
333
|
+
cwd: str | Path = ".",
|
|
334
|
+
require_environment: bool = False,
|
|
335
|
+
include_workspace_build: bool = False,
|
|
336
|
+
run_tests: bool = False,
|
|
337
|
+
) -> dict[str, Any]:
|
|
338
|
+
cwd_path = Path(cwd).resolve()
|
|
339
|
+
files = [
|
|
340
|
+
{"path": f"lean-formalization/{item}", "exists": (FORMALIZATION_ROOT / item).exists()}
|
|
341
|
+
for item in REQUIRED_FORMALIZATION_FILES
|
|
342
|
+
] + [
|
|
343
|
+
{"path": f"lean-runtime/{item}", "exists": (RUNTIME_ROOT / item).exists()}
|
|
344
|
+
for item in REQUIRED_RUNTIME_FILES
|
|
345
|
+
]
|
|
346
|
+
commands = _parser_commands()
|
|
347
|
+
schemas = []
|
|
348
|
+
for name in ("task.schema.json", "result.schema.json", "config.schema.json"):
|
|
349
|
+
path = RUNTIME_ROOT / "schemas" / name
|
|
350
|
+
try:
|
|
351
|
+
_load_schema(path)
|
|
352
|
+
schemas.append({"path": f"schemas/{name}", "ok": True})
|
|
353
|
+
except Exception as exc: # noqa: BLE001 - report schema parse failure in JSON
|
|
354
|
+
schemas.append({"path": f"schemas/{name}", "ok": False, "error": str(exc)})
|
|
355
|
+
|
|
356
|
+
fixtures = RUNTIME_ROOT / "tests" / "fixtures"
|
|
357
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
358
|
+
dry_root = Path(tmp)
|
|
359
|
+
dry_target = dry_root / "Failure.lean"
|
|
360
|
+
(dry_root / "lean-toolchain").write_text("leanprover/lean4:v4.28.0\n", encoding="utf-8")
|
|
361
|
+
(dry_root / "lakefile.toml").write_text('name = "verify_delivery"\n', encoding="utf-8")
|
|
362
|
+
dry_target.write_text((fixtures / "failure.lean").read_text(encoding="utf-8"), encoding="utf-8")
|
|
363
|
+
dry_run = run_direct_task("prove", dry_root, dry_target, dry_run=True)
|
|
364
|
+
review = review_files(fixtures / "before.lean", fixtures / "after_bad.lean")
|
|
365
|
+
failure = extract(fixtures / "failure.lean", target=None, run_lean=False)
|
|
366
|
+
smoke = run_smoke_test(cwd_path, dry_run=True)
|
|
367
|
+
|
|
368
|
+
tool_report = doctor(cwd_path) if require_environment else None
|
|
369
|
+
env_report = inspect_environment(cwd_path) if require_environment else None
|
|
370
|
+
workspace_check = None
|
|
371
|
+
workspace_build = None
|
|
372
|
+
if include_workspace_build:
|
|
373
|
+
env_for_workspace = env_report or inspect_environment(cwd_path)
|
|
374
|
+
workspace_root = env_for_workspace.get("lean", {}).get("workspace_project_root")
|
|
375
|
+
if workspace_root:
|
|
376
|
+
workspace_check = check_project(workspace_root, skip_build=True)
|
|
377
|
+
lake = find_tool("lake") or "lake"
|
|
378
|
+
workspace_build = run_command([lake, "build"], cwd=workspace_root, timeout=1800)
|
|
379
|
+
else:
|
|
380
|
+
workspace_check = {"ok": False, "status": "missing_workspace"}
|
|
381
|
+
|
|
382
|
+
tests = None
|
|
383
|
+
if run_tests:
|
|
384
|
+
tests = run_command([sys.executable, "-m", "unittest", "discover", "-s", str(RUNTIME_ROOT / "tests")], cwd=RUNTIME_ROOT, timeout=300)
|
|
385
|
+
|
|
386
|
+
hygiene = _package_hygiene()
|
|
387
|
+
guidance_first = _guidance_first_check()
|
|
388
|
+
discovery_boundaries = _root_discovery_boundary_check()
|
|
389
|
+
lean_setup_entrypoint = _lean_setup_entrypoint_check()
|
|
390
|
+
checks = {
|
|
391
|
+
"required_files": all(item["exists"] for item in files),
|
|
392
|
+
"required_commands": REQUIRED_COMMANDS.issubset(commands),
|
|
393
|
+
"no_parallel_numina_commands": not any(command.startswith("numina") for command in commands),
|
|
394
|
+
"schemas": all(item["ok"] for item in schemas),
|
|
395
|
+
"guidance_first_skill": bool(guidance_first.get("ok")),
|
|
396
|
+
"discovery_boundaries": bool(discovery_boundaries.get("ok")),
|
|
397
|
+
"lean_setup_entrypoint": bool(lean_setup_entrypoint.get("ok")),
|
|
398
|
+
"dry_run_prove": bool(dry_run.get("ok") and dry_run.get("status") == "dry_run"),
|
|
399
|
+
"patch_guard": bool(not review.get("ok") and review.get("findings")),
|
|
400
|
+
"minimal_failure": bool(failure.get("ok") and failure.get("minimal_failure", {}).get("snippet")),
|
|
401
|
+
"bundled_smoke_test": bool(smoke.get("ok") and smoke.get("status") == "dry_run" and Path(smoke.get("smoke_file", "")).exists()),
|
|
402
|
+
"package_hygiene": bool(hygiene.get("ok")),
|
|
403
|
+
}
|
|
404
|
+
if require_environment:
|
|
405
|
+
checks["tool_environment"] = bool(tool_report and tool_report.get("ok"))
|
|
406
|
+
checks["lean_agent_environment"] = bool(env_report and env_report.get("ok"))
|
|
407
|
+
if include_workspace_build:
|
|
408
|
+
checks["workspace_check"] = bool(workspace_check and workspace_check.get("ok"))
|
|
409
|
+
checks["workspace_build"] = bool(workspace_build and workspace_build.get("ok"))
|
|
410
|
+
if run_tests:
|
|
411
|
+
checks["unit_tests"] = bool(tests and tests.get("ok"))
|
|
412
|
+
|
|
413
|
+
ok = all(checks.values())
|
|
414
|
+
return {
|
|
415
|
+
"ok": ok,
|
|
416
|
+
"status": "delivery_ready" if ok else "delivery_blocked",
|
|
417
|
+
"cwd": str(cwd_path),
|
|
418
|
+
"runtime_root": str(RUNTIME_ROOT),
|
|
419
|
+
"formalization_root": str(FORMALIZATION_ROOT),
|
|
420
|
+
"setup_root": str(SETUP_ROOT),
|
|
421
|
+
"checks": checks,
|
|
422
|
+
"files": files,
|
|
423
|
+
"commands": {
|
|
424
|
+
"required": sorted(REQUIRED_COMMANDS),
|
|
425
|
+
"available": sorted(commands),
|
|
426
|
+
"missing": sorted(REQUIRED_COMMANDS - commands),
|
|
427
|
+
},
|
|
428
|
+
"schemas": schemas,
|
|
429
|
+
"guidance_first_skill": guidance_first,
|
|
430
|
+
"discovery_boundaries": discovery_boundaries,
|
|
431
|
+
"lean_setup_entrypoint": lean_setup_entrypoint,
|
|
432
|
+
"dry_run_prove": {
|
|
433
|
+
"ok": dry_run.get("ok"),
|
|
434
|
+
"status": dry_run.get("status"),
|
|
435
|
+
"backend": dry_run.get("backend"),
|
|
436
|
+
"agent_mode": dry_run.get("agent_mode"),
|
|
437
|
+
"missing_config": dry_run.get("missing_config"),
|
|
438
|
+
},
|
|
439
|
+
"patch_guard": {
|
|
440
|
+
"ok": review.get("ok"),
|
|
441
|
+
"status": review.get("status"),
|
|
442
|
+
"finding_count": len(review.get("findings", [])),
|
|
443
|
+
},
|
|
444
|
+
"minimal_failure": {
|
|
445
|
+
"ok": failure.get("ok"),
|
|
446
|
+
"status": failure.get("status"),
|
|
447
|
+
"start_line": failure.get("minimal_failure", {}).get("start_line"),
|
|
448
|
+
"end_line": failure.get("minimal_failure", {}).get("end_line"),
|
|
449
|
+
},
|
|
450
|
+
"bundled_smoke_test": {
|
|
451
|
+
"ok": smoke.get("ok"),
|
|
452
|
+
"status": smoke.get("status"),
|
|
453
|
+
"smoke_file": smoke.get("smoke_file"),
|
|
454
|
+
"project_root": smoke.get("project_root"),
|
|
455
|
+
},
|
|
456
|
+
"hygiene": hygiene,
|
|
457
|
+
"tool_environment": tool_report,
|
|
458
|
+
"lean_agent_environment": env_report,
|
|
459
|
+
"workspace_check": workspace_check,
|
|
460
|
+
"workspace_build": workspace_build,
|
|
461
|
+
"unit_tests": tests,
|
|
462
|
+
"external_api_note": "env, doctor, check, review, tests, and dry-runs do not call external APIs. configure --setup-numina and approved official Numina runs may clone/install/call external tools, then final Lean changes must be validated locally.",
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
|
|
466
|
+
def main(argv: list[str] | None = None) -> None:
|
|
467
|
+
parser = argparse.ArgumentParser(description="Verify Lean Formalization delivery readiness")
|
|
468
|
+
parser.add_argument("--cwd", default=".")
|
|
469
|
+
parser.add_argument("--require-environment", action="store_true")
|
|
470
|
+
parser.add_argument("--include-workspace-build", action="store_true")
|
|
471
|
+
parser.add_argument("--run-tests", action="store_true")
|
|
472
|
+
args = parser.parse_args(argv)
|
|
473
|
+
result = verify(
|
|
474
|
+
cwd=args.cwd,
|
|
475
|
+
require_environment=args.require_environment,
|
|
476
|
+
include_workspace_build=args.include_workspace_build,
|
|
477
|
+
run_tests=args.run_tests,
|
|
478
|
+
)
|
|
479
|
+
print(json.dumps(result, indent=2, ensure_ascii=False))
|
|
480
|
+
raise SystemExit(0 if result.get("ok") else 1)
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
if __name__ == "__main__":
|
|
484
|
+
main()
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
import tempfile
|
|
5
|
+
import unittest
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from unittest.mock import patch
|
|
8
|
+
|
|
9
|
+
SCRIPT_DIR = Path(__file__).resolve().parents[1] / "scripts"
|
|
10
|
+
sys.path.insert(0, str(SCRIPT_DIR))
|
|
11
|
+
|
|
12
|
+
from check_lean_project import check_project, find_project_root, read_mathlib_revision, read_toolchain # noqa: E402
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class CheckLeanProjectTests(unittest.TestCase):
|
|
16
|
+
def test_finds_project_root_and_versions(self) -> None:
|
|
17
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
18
|
+
root = (Path(tmp) / "proj").resolve()
|
|
19
|
+
nested = root / "A" / "B"
|
|
20
|
+
nested.mkdir(parents=True)
|
|
21
|
+
(root / "lean-toolchain").write_text("leanprover/lean4:v4.26.0\n", encoding="utf-8")
|
|
22
|
+
(root / "lakefile.toml").write_text(
|
|
23
|
+
'name = "proj"\n\n[[require]]\nname = "mathlib"\nscope = "leanprover-community"\nrev = "v4.26.0"\n',
|
|
24
|
+
encoding="utf-8",
|
|
25
|
+
)
|
|
26
|
+
target = nested / "T.lean"
|
|
27
|
+
target.write_text("example : True := by trivial\n", encoding="utf-8")
|
|
28
|
+
|
|
29
|
+
self.assertEqual(find_project_root(target), root)
|
|
30
|
+
self.assertEqual(read_toolchain(root), "leanprover/lean4:v4.26.0")
|
|
31
|
+
self.assertEqual(read_mathlib_revision(root), "v4.26.0")
|
|
32
|
+
|
|
33
|
+
result = check_project(root, skip_build=True)
|
|
34
|
+
self.assertTrue(result["ok"])
|
|
35
|
+
self.assertEqual(result["status"], "ok_skip_build")
|
|
36
|
+
|
|
37
|
+
def test_build_uses_discovered_lake_binary(self) -> None:
|
|
38
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
39
|
+
root = Path(tmp)
|
|
40
|
+
(root / "lean-toolchain").write_text("leanprover/lean4:v4.28.0\n", encoding="utf-8")
|
|
41
|
+
(root / "lakefile.toml").write_text('name = "proj"\n', encoding="utf-8")
|
|
42
|
+
|
|
43
|
+
with patch("check_lean_project.find_tool", return_value="/custom/bin/lake"), \
|
|
44
|
+
patch("check_lean_project.run_command", return_value={
|
|
45
|
+
"ok": True,
|
|
46
|
+
"returncode": 0,
|
|
47
|
+
"stdout": "",
|
|
48
|
+
"stderr": "",
|
|
49
|
+
"command": ["/custom/bin/lake", "build"],
|
|
50
|
+
}) as run:
|
|
51
|
+
result = check_project(root)
|
|
52
|
+
|
|
53
|
+
self.assertTrue(result["ok"])
|
|
54
|
+
run.assert_called_once()
|
|
55
|
+
self.assertEqual(run.call_args.args[0], ["/custom/bin/lake", "build"])
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
if __name__ == "__main__":
|
|
59
|
+
unittest.main()
|