@louisultra/dsh-verymath 0.0.0-stage → 0.3.1

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.
Files changed (270) hide show
  1. package/CHANGELOG.md +110 -0
  2. package/LICENSE +21 -0
  3. package/NOTICE.md +35 -0
  4. package/README.md +104 -2
  5. package/README_EN.md +105 -0
  6. package/UPSTREAM.json +106 -0
  7. package/cordis.patch.yml +12 -0
  8. package/lib/core/error.d.ts +20 -0
  9. package/lib/core/error.js +25 -0
  10. package/lib/core/gates.d.ts +42 -0
  11. package/lib/core/gates.js +217 -0
  12. package/lib/core/glossary.d.ts +101 -0
  13. package/lib/core/glossary.js +243 -0
  14. package/lib/core/graph.d.ts +118 -0
  15. package/lib/core/graph.js +460 -0
  16. package/lib/core/index.d.ts +120 -0
  17. package/lib/core/index.js +197 -0
  18. package/lib/core/paper.d.ts +163 -0
  19. package/lib/core/paper.js +73 -0
  20. package/lib/core/paths.d.ts +2 -0
  21. package/lib/core/paths.js +12 -0
  22. package/lib/core/sage.d.ts +61 -0
  23. package/lib/core/sage.js +212 -0
  24. package/lib/core/skills.d.ts +11 -0
  25. package/lib/core/skills.js +110 -0
  26. package/lib/tool/index.d.ts +21 -0
  27. package/lib/tool/index.js +1144 -0
  28. package/package.json +90 -4
  29. package/skills/after-ocr/SKILL.md +123 -0
  30. package/skills/after-ocr/references/audit-schema.md +94 -0
  31. package/skills/after-ocr/references/error-taxonomy.md +179 -0
  32. package/skills/after-ocr/scripts/merge_audit_logs.py +329 -0
  33. package/skills/after-ocr/scripts/scan_markdown_ocr.py +350 -0
  34. package/skills/after-ocr/tests/test_scripts.py +84 -0
  35. package/skills/discover-math-problems/SKILL.md +115 -0
  36. package/skills/discover-math-problems/references/artifact-contract.md +93 -0
  37. package/skills/discover-math-problems/references/autonomous-research-protocol.md +86 -0
  38. package/skills/discover-math-problems/references/conjecture-generation-protocol.md +63 -0
  39. package/skills/discover-math-problems/references/extremal-graph-variants.md +53 -0
  40. package/skills/graph-theory-paper-reading/SKILL.md +600 -0
  41. package/skills/invariant-computation/SKILL.md +169 -0
  42. package/skills/invariant-computation/examples/invariant_summary.example.json +51 -0
  43. package/skills/invariant-computation/manifest.yaml +46 -0
  44. package/skills/invariant-computation/references/INDEX.md +20 -0
  45. package/skills/invariant-computation/references/failure_modes.md +40 -0
  46. package/skills/invariant-computation/references/method_route_map.md +177 -0
  47. package/skills/invariant-computation/references/source_notes.md +19 -0
  48. package/skills/invariant-computation/references/tool_catalog.md +65 -0
  49. package/skills/invariant-computation/references/validation_checks.md +52 -0
  50. package/skills/invariant-computation/schema/invariant_summary.schema.json +260 -0
  51. package/skills/lean-formalization/SKILL.md +110 -0
  52. package/skills/lean-formalization/lean-runtime/config/env.example +5 -0
  53. package/skills/lean-formalization/lean-runtime/config/lean_agent.example.toml +28 -0
  54. package/skills/lean-formalization/lean-runtime/config/numina_runtime.example.toml +12 -0
  55. package/skills/lean-formalization/lean-runtime/examples/smoke/LocalLeanSmoke.lean +7 -0
  56. package/skills/lean-formalization/lean-runtime/prompts/complete_sorries.md +3 -0
  57. package/skills/lean-formalization/lean-runtime/prompts/formalize_statement.md +3 -0
  58. package/skills/lean-formalization/lean-runtime/prompts/prove_theorem.md +3 -0
  59. package/skills/lean-formalization/lean-runtime/prompts/repair_lean_file.md +3 -0
  60. package/skills/lean-formalization/lean-runtime/references/backend_adapter_checklist.md +36 -0
  61. package/skills/lean-formalization/lean-runtime/references/direct_lean_workflow.md +48 -0
  62. package/skills/lean-formalization/lean-runtime/references/failure_taxonomy.md +17 -0
  63. package/skills/lean-formalization/lean-runtime/references/interactive_orchestration.md +83 -0
  64. package/skills/lean-formalization/lean-runtime/references/lean_agent_capability_map.md +116 -0
  65. package/skills/lean-formalization/lean-runtime/references/lean_lsp_mcp_adapter.md +219 -0
  66. package/skills/lean-formalization/lean-runtime/references/lean_runtime_configuration.md +92 -0
  67. package/skills/lean-formalization/lean-runtime/references/numina_reverse_analysis.md +80 -0
  68. package/skills/lean-formalization/lean-runtime/references/numina_runtime.md +41 -0
  69. package/skills/lean-formalization/lean-runtime/references/numina_subagent_troubleshooting.md +77 -0
  70. package/skills/lean-formalization/lean-runtime/references/review_checklist.md +10 -0
  71. package/skills/lean-formalization/lean-runtime/references/specialist_agent_patterns.md +65 -0
  72. package/skills/lean-formalization/lean-runtime/schemas/config.schema.json +12 -0
  73. package/skills/lean-formalization/lean-runtime/schemas/result.schema.json +33 -0
  74. package/skills/lean-formalization/lean-runtime/schemas/task.schema.json +30 -0
  75. package/skills/lean-formalization/lean-runtime/scripts/ai4m_lean.py +222 -0
  76. package/skills/lean-formalization/lean-runtime/scripts/check_lean_project.py +134 -0
  77. package/skills/lean-formalization/lean-runtime/scripts/common.py +296 -0
  78. package/skills/lean-formalization/lean-runtime/scripts/configure_lean.py +222 -0
  79. package/skills/lean-formalization/lean-runtime/scripts/detect_sorry.py +49 -0
  80. package/skills/lean-formalization/lean-runtime/scripts/direct_task.py +100 -0
  81. package/skills/lean-formalization/lean-runtime/scripts/extract_minimal_failure.py +74 -0
  82. package/skills/lean-formalization/lean-runtime/scripts/numina_runtime.py +414 -0
  83. package/skills/lean-formalization/lean-runtime/scripts/smoke_test.py +75 -0
  84. package/skills/lean-formalization/lean-runtime/scripts/tool_status.py +79 -0
  85. package/skills/lean-formalization/lean-runtime/scripts/validate_patch.py +81 -0
  86. package/skills/lean-formalization/lean-runtime/scripts/verify_delivery.py +484 -0
  87. package/skills/lean-formalization/lean-runtime/tests/fixtures/after_bad.lean +4 -0
  88. package/skills/lean-formalization/lean-runtime/tests/fixtures/after_statement_changed.lean +4 -0
  89. package/skills/lean-formalization/lean-runtime/tests/fixtures/before.lean +4 -0
  90. package/skills/lean-formalization/lean-runtime/tests/fixtures/failure.lean +7 -0
  91. package/skills/lean-formalization/lean-runtime/tests/test_check_lean_project.py +59 -0
  92. package/skills/lean-formalization/lean-runtime/tests/test_cli.py +377 -0
  93. package/skills/lean-formalization/lean-runtime/tests/test_common_config.py +84 -0
  94. package/skills/lean-formalization/lean-runtime/tests/test_configure_lean.py +138 -0
  95. package/skills/lean-formalization/lean-runtime/tests/test_detect_sorry.py +24 -0
  96. package/skills/lean-formalization/lean-runtime/tests/test_direct_task.py +69 -0
  97. package/skills/lean-formalization/lean-runtime/tests/test_numina_runtime.py +168 -0
  98. package/skills/lean-formalization/lean-runtime/tests/test_validate_patch.py +29 -0
  99. package/skills/lean-setup/SKILL.md +99 -0
  100. package/skills/least-squares/README.md +85 -0
  101. package/skills/least-squares/SKILL.md +613 -0
  102. package/skills/least-squares/examples.md +380 -0
  103. package/skills/math-beamer/SKILL.md +325 -0
  104. package/skills/math-beamer/references/build-and-layout-audit.md +63 -0
  105. package/skills/math-beamer/references/math-domain-patterns.md +56 -0
  106. package/skills/math-beamer/references/template-policy.md +43 -0
  107. package/skills/math-beamer/references/template-source-index.md +51 -0
  108. package/skills/math-beamer/templates/catalog.yaml +235 -0
  109. package/skills/math-beamer/templates/packs/algebra-number-theory-talk/main.tex +45 -0
  110. package/skills/math-beamer/templates/packs/algebra-number-theory-talk/template.yaml +9 -0
  111. package/skills/math-beamer/templates/packs/algorithm-talk/main.tex +43 -0
  112. package/skills/math-beamer/templates/packs/algorithm-talk/template.yaml +9 -0
  113. package/skills/math-beamer/templates/packs/analysis-core-talk/main.tex +49 -0
  114. package/skills/math-beamer/templates/packs/analysis-core-talk/template.yaml +19 -0
  115. package/skills/math-beamer/templates/packs/backup-heavy-talk/main.tex +40 -0
  116. package/skills/math-beamer/templates/packs/backup-heavy-talk/template.yaml +9 -0
  117. package/skills/math-beamer/templates/packs/beamerposter-a0/main.tex +45 -0
  118. package/skills/math-beamer/templates/packs/beamerposter-a0/template.yaml +12 -0
  119. package/skills/math-beamer/templates/packs/combinatorics-graph-talk/main.tex +53 -0
  120. package/skills/math-beamer/templates/packs/combinatorics-graph-talk/template.yaml +18 -0
  121. package/skills/math-beamer/templates/packs/control-systems-talk/main.tex +51 -0
  122. package/skills/math-beamer/templates/packs/control-systems-talk/template.yaml +18 -0
  123. package/skills/math-beamer/templates/packs/course-lecture-zh/main.tex +43 -0
  124. package/skills/math-beamer/templates/packs/course-lecture-zh/template.yaml +9 -0
  125. package/skills/math-beamer/templates/packs/data-experiment-results/main.tex +45 -0
  126. package/skills/math-beamer/templates/packs/data-experiment-results/template.yaml +9 -0
  127. package/skills/math-beamer/templates/packs/dynamical-systems-talk/main.tex +42 -0
  128. package/skills/math-beamer/templates/packs/dynamical-systems-talk/template.yaml +9 -0
  129. package/skills/math-beamer/templates/packs/geometry-topology-talk/main.tex +43 -0
  130. package/skills/math-beamer/templates/packs/geometry-topology-talk/template.yaml +9 -0
  131. package/skills/math-beamer/templates/packs/information-coding-crypto-talk/main.tex +49 -0
  132. package/skills/math-beamer/templates/packs/information-coding-crypto-talk/template.yaml +18 -0
  133. package/skills/math-beamer/templates/packs/logic-foundations-category-talk/main.tex +51 -0
  134. package/skills/math-beamer/templates/packs/logic-foundations-category-talk/template.yaml +18 -0
  135. package/skills/math-beamer/templates/packs/numerical-analysis-talk/main.tex +51 -0
  136. package/skills/math-beamer/templates/packs/numerical-analysis-talk/template.yaml +9 -0
  137. package/skills/math-beamer/templates/packs/optimization-talk/main.tex +58 -0
  138. package/skills/math-beamer/templates/packs/optimization-talk/template.yaml +9 -0
  139. package/skills/math-beamer/templates/packs/pde-analysis-talk/main.tex +49 -0
  140. package/skills/math-beamer/templates/packs/pde-analysis-talk/template.yaml +9 -0
  141. package/skills/math-beamer/templates/packs/probability-statistics-talk/main.tex +52 -0
  142. package/skills/math-beamer/templates/packs/probability-statistics-talk/template.yaml +9 -0
  143. package/skills/math-beamer/templates/packs/reading-group-paper/main.tex +46 -0
  144. package/skills/math-beamer/templates/packs/reading-group-paper/template.yaml +9 -0
  145. package/skills/math-beamer/templates/packs/seminar-minimal-en/main.tex +60 -0
  146. package/skills/math-beamer/templates/packs/seminar-minimal-en/template.yaml +13 -0
  147. package/skills/math-beamer/templates/packs/seminar-minimal-zh/main.tex +60 -0
  148. package/skills/math-beamer/templates/packs/seminar-minimal-zh/template.yaml +13 -0
  149. package/skills/math-beamer/templates/packs/theorem-proof-talk/main.tex +60 -0
  150. package/skills/math-beamer/templates/packs/theorem-proof-talk/template.yaml +9 -0
  151. package/skills/math-beamer/templates/packs/thesis-defense/main.tex +42 -0
  152. package/skills/math-beamer/templates/packs/thesis-defense/template.yaml +9 -0
  153. package/skills/math-beamer/templates/packs/workshop-tutorial/main.tex +32 -0
  154. package/skills/math-beamer/templates/packs/workshop-tutorial/template.yaml +9 -0
  155. package/skills/math-beamer/templates/preview-gallery.md +32 -0
  156. package/skills/math-beamer/templates/previews/algebra-number-theory-talk-content.png +0 -0
  157. package/skills/math-beamer/templates/previews/algebra-number-theory-talk-cover.png +0 -0
  158. package/skills/math-beamer/templates/previews/algorithm-talk-content.png +0 -0
  159. package/skills/math-beamer/templates/previews/algorithm-talk-cover.png +0 -0
  160. package/skills/math-beamer/templates/previews/analysis-core-talk-content.png +0 -0
  161. package/skills/math-beamer/templates/previews/analysis-core-talk-cover.png +0 -0
  162. package/skills/math-beamer/templates/previews/backup-heavy-talk-content.png +0 -0
  163. package/skills/math-beamer/templates/previews/backup-heavy-talk-cover.png +0 -0
  164. package/skills/math-beamer/templates/previews/beamerposter-a0-content.png +0 -0
  165. package/skills/math-beamer/templates/previews/beamerposter-a0-cover.png +0 -0
  166. package/skills/math-beamer/templates/previews/combinatorics-graph-talk-content.png +0 -0
  167. package/skills/math-beamer/templates/previews/combinatorics-graph-talk-cover.png +0 -0
  168. package/skills/math-beamer/templates/previews/control-systems-talk-content.png +0 -0
  169. package/skills/math-beamer/templates/previews/control-systems-talk-cover.png +0 -0
  170. package/skills/math-beamer/templates/previews/course-lecture-zh-content.png +0 -0
  171. package/skills/math-beamer/templates/previews/course-lecture-zh-cover.png +0 -0
  172. package/skills/math-beamer/templates/previews/data-experiment-results-content.png +0 -0
  173. package/skills/math-beamer/templates/previews/data-experiment-results-cover.png +0 -0
  174. package/skills/math-beamer/templates/previews/dynamical-systems-talk-content.png +0 -0
  175. package/skills/math-beamer/templates/previews/dynamical-systems-talk-cover.png +0 -0
  176. package/skills/math-beamer/templates/previews/geometry-topology-talk-content.png +0 -0
  177. package/skills/math-beamer/templates/previews/geometry-topology-talk-cover.png +0 -0
  178. package/skills/math-beamer/templates/previews/information-coding-crypto-talk-content.png +0 -0
  179. package/skills/math-beamer/templates/previews/information-coding-crypto-talk-cover.png +0 -0
  180. package/skills/math-beamer/templates/previews/logic-foundations-category-talk-content.png +0 -0
  181. package/skills/math-beamer/templates/previews/logic-foundations-category-talk-cover.png +0 -0
  182. package/skills/math-beamer/templates/previews/numerical-analysis-talk-content.png +0 -0
  183. package/skills/math-beamer/templates/previews/numerical-analysis-talk-cover.png +0 -0
  184. package/skills/math-beamer/templates/previews/optimization-talk-content.png +0 -0
  185. package/skills/math-beamer/templates/previews/optimization-talk-cover.png +0 -0
  186. package/skills/math-beamer/templates/previews/pde-analysis-talk-content.png +0 -0
  187. package/skills/math-beamer/templates/previews/pde-analysis-talk-cover.png +0 -0
  188. package/skills/math-beamer/templates/previews/probability-statistics-talk-content.png +0 -0
  189. package/skills/math-beamer/templates/previews/probability-statistics-talk-cover.png +0 -0
  190. package/skills/math-beamer/templates/previews/reading-group-paper-content.png +0 -0
  191. package/skills/math-beamer/templates/previews/reading-group-paper-cover.png +0 -0
  192. package/skills/math-beamer/templates/previews/seminar-minimal-en-content.png +0 -0
  193. package/skills/math-beamer/templates/previews/seminar-minimal-en-cover.png +0 -0
  194. package/skills/math-beamer/templates/previews/seminar-minimal-zh-content.png +0 -0
  195. package/skills/math-beamer/templates/previews/seminar-minimal-zh-cover.png +0 -0
  196. package/skills/math-beamer/templates/previews/theorem-proof-talk-content.png +0 -0
  197. package/skills/math-beamer/templates/previews/theorem-proof-talk-cover.png +0 -0
  198. package/skills/math-beamer/templates/previews/thesis-defense-content.png +0 -0
  199. package/skills/math-beamer/templates/previews/thesis-defense-cover.png +0 -0
  200. package/skills/math-beamer/templates/previews/workshop-tutorial-content.png +0 -0
  201. package/skills/math-beamer/templates/previews/workshop-tutorial-cover.png +0 -0
  202. package/skills/math-beamer/templates/review-report.md +54 -0
  203. package/skills/math-beamer/templates/slide-source-ledger.md +22 -0
  204. package/skills/math-beamer/templates/source-packet.md +50 -0
  205. package/skills/math-glossary/SKILL.md +347 -0
  206. package/skills/math-glossary/references/glossary-schema.md +71 -0
  207. package/skills/math-glossary/references/glossary-usage-guide.md +176 -0
  208. package/skills/math-glossary/references/glossary-web-template.md +127 -0
  209. package/skills/math-glossary/references/glossary.schema.json +76 -0
  210. package/skills/math-glossary/references/user-manual.md +435 -0
  211. package/skills/math-glossary/requirements-ai.txt +3 -0
  212. package/skills/math-glossary/requirements.txt +3 -0
  213. package/skills/math-glossary/scripts/glossary_backup.py +42 -0
  214. package/skills/math-glossary/scripts/glossary_build.py +467 -0
  215. package/skills/math-glossary/scripts/glossary_enrich_examples.py +283 -0
  216. package/skills/math-glossary/scripts/glossary_export.py +333 -0
  217. package/skills/math-glossary/scripts/glossary_web.py +1265 -0
  218. package/skills/math-paper-reading/README.md +163 -0
  219. package/skills/math-paper-reading/SKILL.md +48 -0
  220. package/skills/math-paper-reading/agent_router.md +36 -0
  221. package/skills/math-paper-reading/references/proof_pattern_taxonomy.md +123 -0
  222. package/skills/math-paper-reading/references/quality_rubric.md +36 -0
  223. package/skills/math-paper-reading/skill_base.md +627 -0
  224. package/skills/math-paper-reading/skill_literature_search.md +866 -0
  225. package/skills/math-paper-reading/skill_paper_deep_read.md +1024 -0
  226. package/skills/math-paper-reading/skill_pathway_proof.md +718 -0
  227. package/skills/math-paper-reading/skill_reference_manager.md +746 -0
  228. package/skills/matlab-runner/SKILL.md +217 -0
  229. package/skills/matlab-runner/examples/README.md +33 -0
  230. package/skills/matlab-runner/examples/matrix_report.m +28 -0
  231. package/skills/matlab-runner/examples/plot_damped_sine.m +64 -0
  232. package/skills/matlab-runner/examples/test_vector_norm.m +12 -0
  233. package/skills/matlab-runner/references/client-setup.md +24 -0
  234. package/skills/matlab-runner/references/file-session-safety.md +86 -0
  235. package/skills/matlab-runner/references/numerical-safety.md +126 -0
  236. package/skills/matlab-runner/references/resource-safety.md +125 -0
  237. package/skills/mixed-integer-programming/SKILL.md +119 -0
  238. package/skills/mixed-integer-programming/lp-examples.md +251 -0
  239. package/skills/mixed-integer-programming/mip-examples-verified.md +118 -0
  240. package/skills/open-problem-research-pipeline/SKILL.md +76 -0
  241. package/skills/open-problem-research-pipeline/skill_literature_analysis.md +201 -0
  242. package/skills/open-problem-research-pipeline/skill_literature_proof_framework.md +206 -0
  243. package/skills/open-problem-research-pipeline/skill_literature_search.md +172 -0
  244. package/skills/open-problem-research-pipeline/skill_qskill.md +177 -0
  245. package/skills/osqp-solver/SKILL.md +245 -0
  246. package/skills/osqp-solver/references/citation.md +25 -0
  247. package/skills/osqp-solver/references/dual-infeasible-example.json +14 -0
  248. package/skills/osqp-solver/references/feasible-example.json +21 -0
  249. package/skills/osqp-solver/references/primal-infeasible-example.json +17 -0
  250. package/skills/osqp-solver/references/python-api.md +95 -0
  251. package/skills/osqp-solver/references/verification.md +94 -0
  252. package/skills/osqp-solver/scripts/check_osqp_environment.py +120 -0
  253. package/skills/osqp-solver/scripts/solve_qp.py +943 -0
  254. package/skills/paper-writing/SKILL.md +115 -0
  255. package/skills/paper-writing/skill_claim_evidence_ledger.md +55 -0
  256. package/skills/paper-writing/skill_formula_environment_and_readability.md +41 -0
  257. package/skills/paper-writing/skill_latex_build_and_layout_audit.md +73 -0
  258. package/skills/paper-writing/skill_notation_and_variable_consistency.md +42 -0
  259. package/skills/paper-writing/skill_paper_skeleton_and_logical_architecture.md +54 -0
  260. package/skills/paper-writing/skill_proof_obligation_and_assumption_audit.md +57 -0
  261. package/skills/paper-writing/templates/claim-evidence-ledger.md +23 -0
  262. package/skills/paper-writing/templates/proof-obligation-ledger.md +22 -0
  263. package/skills/paper-writing/templates/rapid-prototype-paper-skeleton.md +46 -0
  264. package/skills/paper-writing/templates/source-packet.md +37 -0
  265. package/skills/paper-writing/templates/submission-readiness.md +41 -0
  266. package/skills/proof-blueprint-review/SKILL.md +129 -0
  267. package/skills/proof-blueprint-review/references/agent-mediated-proof-protocol.md +57 -0
  268. package/skills/proof-blueprint-review/references/generation-agent.md +45 -0
  269. package/skills/proof-blueprint-review/references/proof-acceptance-contract.md +41 -0
  270. package/skills/proof-blueprint-review/references/verification-agent.md +37 -0
@@ -0,0 +1,74 @@
1
+ from __future__ import annotations
2
+
3
+ import re
4
+ from pathlib import Path
5
+ from typing import Any
6
+
7
+ from check_lean_project import check_file
8
+ from detect_sorry import scan_text
9
+
10
+
11
+ DECL_START_RE = re.compile(r"^\s*(theorem|lemma|def|example|instance)\s+")
12
+
13
+
14
+ def _line_window(lines: list[str], center: int, radius: int = 8) -> tuple[int, int, str]:
15
+ start = max(1, center - radius)
16
+ end = min(len(lines), center + radius)
17
+ snippet = "\n".join(lines[start - 1:end])
18
+ return start, end, snippet
19
+
20
+
21
+ def _target_block(lines: list[str], target: str) -> tuple[int, int, str] | None:
22
+ start_index = None
23
+ for index, line in enumerate(lines):
24
+ if re.search(rf"\b{re.escape(target)}\b", line) and DECL_START_RE.search(line):
25
+ start_index = index
26
+ break
27
+ if start_index is None:
28
+ return None
29
+ end_index = len(lines)
30
+ for index in range(start_index + 1, len(lines)):
31
+ if DECL_START_RE.search(lines[index]):
32
+ end_index = index
33
+ break
34
+ return start_index + 1, end_index, "\n".join(lines[start_index:end_index])
35
+
36
+
37
+ def extract(file: str | Path, target: str | None = None, run_lean: bool = False, timeout: int = 120) -> dict[str, Any]:
38
+ file_path = Path(file).expanduser().resolve()
39
+ if not file_path.exists():
40
+ return {
41
+ "ok": False,
42
+ "status": "file_not_found",
43
+ "minimal_failure": {},
44
+ "errors": [{"severity": "error", "data": f"File not found: {file_path}"}],
45
+ }
46
+ text = file_path.read_text(encoding="utf-8", errors="replace")
47
+ lines = text.splitlines()
48
+ block = _target_block(lines, target) if target else None
49
+ if block is None:
50
+ scan = scan_text(text, source=str(file_path))
51
+ if scan.get("findings"):
52
+ first = scan["findings"][0]
53
+ block = _line_window(lines, int(first["line"]))
54
+ else:
55
+ block = (1, min(len(lines), 40), "\n".join(lines[:40]))
56
+
57
+ lean_result = check_file(file_path, timeout=timeout) if run_lean else None
58
+ start, end, snippet = block
59
+ status = "minimal_failure_extracted"
60
+ ok = True
61
+ if lean_result and not lean_result.get("ok"):
62
+ status = "lean_failure_minimized"
63
+ return {
64
+ "ok": ok,
65
+ "status": status,
66
+ "file": str(file_path),
67
+ "target": target,
68
+ "minimal_failure": {
69
+ "start_line": start,
70
+ "end_line": end,
71
+ "snippet": snippet,
72
+ "lean": lean_result,
73
+ },
74
+ }
@@ -0,0 +1,414 @@
1
+ from __future__ import annotations
2
+
3
+ import os
4
+ import shlex
5
+ from pathlib import Path
6
+ from typing import Any
7
+
8
+ from common import ENV_KEY_RE, ai4math_home, ensure_ai4math_gitignore, expand_path, run_command
9
+ from tool_status import tool_versions
10
+
11
+
12
+ DEFAULT_UPSTREAM_URL = "https://github.com/project-numina/numina-lean-agent"
13
+ DEFAULT_PROMPT_FILE = "prompts/autosearch/main_entry.md"
14
+ CLAUDE_ENV_KEYS = ["ANTHROPIC_AUTH_TOKEN", "ANTHROPIC_BASE_URL", "ANTHROPIC_MODEL"]
15
+ SKILL_ENV_KEYS = ["GEMINI_API_KEY", "OPENAI_API_KEY", "LEAN_LEANDEX_API_KEY", "AXLE_API_KEY"]
16
+
17
+
18
+ def runtime_root(cwd: str | Path) -> Path:
19
+ cwd_path = Path(cwd).resolve()
20
+ override = os.environ.get("AI4MATH_NUMINA_HOME")
21
+ if override:
22
+ return expand_path(override, cwd_path) or (ai4math_home(cwd_path) / "numina-runtime")
23
+ return ai4math_home(cwd_path) / "numina-runtime"
24
+
25
+
26
+ def runtime_paths(cwd: str | Path) -> dict[str, str]:
27
+ root = runtime_root(cwd)
28
+ return {
29
+ "root": str(root),
30
+ "upstream": str(root / "upstream"),
31
+ "projects": str(root / "upstream" / "projects"),
32
+ "results": str(root / "results"),
33
+ "env_local": str(root / ".env.local"),
34
+ "local_config": str(root / "numina_runtime.local.toml"),
35
+ "default_upstream_url": DEFAULT_UPSTREAM_URL,
36
+ }
37
+
38
+
39
+ def upstream_url() -> str:
40
+ return os.environ.get("AI4MATH_NUMINA_UPSTREAM_URL") or DEFAULT_UPSTREAM_URL
41
+
42
+
43
+ def upstream_ref() -> str | None:
44
+ return os.environ.get("AI4MATH_NUMINA_UPSTREAM_REF") or None
45
+
46
+
47
+ def _parse_env_file(path: Path) -> dict[str, str]:
48
+ if not path.exists():
49
+ return {}
50
+ values: dict[str, str] = {}
51
+ for raw_line in path.read_text(encoding="utf-8", errors="replace").splitlines():
52
+ line = raw_line.strip()
53
+ if not line or line.startswith("#"):
54
+ continue
55
+ try:
56
+ parts = shlex.split(line, comments=True, posix=True)
57
+ except ValueError:
58
+ continue
59
+ if parts and parts[0] == "export":
60
+ parts = parts[1:]
61
+ for part in parts:
62
+ if "=" not in part:
63
+ continue
64
+ key, value = part.split("=", 1)
65
+ if ENV_KEY_RE.match(key):
66
+ values[key] = value
67
+ return values
68
+
69
+
70
+ def read_numina_env_local(cwd: str | Path) -> dict[str, str]:
71
+ return _parse_env_file(runtime_root(cwd) / ".env.local")
72
+
73
+
74
+ def _redact(value: str | None) -> str | None:
75
+ return "<redacted>" if value else None
76
+
77
+
78
+ def credential_report(env: dict[str, str] | None = None) -> dict[str, Any]:
79
+ merged = dict(os.environ)
80
+ if env:
81
+ merged.update(env)
82
+ claude_variables = {key: _redact(merged.get(key)) for key in CLAUDE_ENV_KEYS}
83
+ skill_keys = {key: _redact(merged.get(key)) for key in SKILL_ENV_KEYS}
84
+ return {
85
+ "claude": {
86
+ "configured": bool(merged.get("ANTHROPIC_AUTH_TOKEN")),
87
+ "variables": claude_variables,
88
+ },
89
+ "skill_keys": skill_keys,
90
+ "missing_skill_keys": [key for key in SKILL_ENV_KEYS if not merged.get(key)],
91
+ }
92
+
93
+
94
+ def _action(name: str, command: list[str], cwd: str | Path, *, dry_run: bool = False, timeout: int = 300) -> dict[str, Any]:
95
+ item: dict[str, Any] = {
96
+ "name": name,
97
+ "command": command,
98
+ "cwd": str(Path(cwd).resolve()),
99
+ "timeout": timeout,
100
+ }
101
+ if dry_run:
102
+ item["skipped"] = True
103
+ item["reason"] = "dry_run"
104
+ return item
105
+
106
+
107
+ def inspect_upstream(cwd: str | Path) -> dict[str, Any]:
108
+ upstream = runtime_root(cwd) / "upstream"
109
+ if not upstream.exists():
110
+ return {
111
+ "exists": False,
112
+ "installed": False,
113
+ "path": str(upstream),
114
+ "status": "missing",
115
+ "remote": None,
116
+ "head": None,
117
+ "dirty": False,
118
+ }
119
+ if not (upstream / ".git").exists():
120
+ return {
121
+ "exists": True,
122
+ "installed": False,
123
+ "path": str(upstream),
124
+ "status": "path_exists_non_git",
125
+ "remote": None,
126
+ "head": None,
127
+ "dirty": None,
128
+ }
129
+ remote = run_command(["git", "remote", "get-url", "origin"], cwd=upstream)
130
+ head = run_command(["git", "rev-parse", "HEAD"], cwd=upstream)
131
+ dirty = run_command(["git", "status", "--short"], cwd=upstream)
132
+ dirty_stdout = (dirty.get("stdout") or "").strip()
133
+ return {
134
+ "exists": True,
135
+ "installed": True,
136
+ "path": str(upstream),
137
+ "status": "installed",
138
+ "remote": (remote.get("stdout") or "").strip() if remote.get("ok") else None,
139
+ "head": (head.get("stdout") or "").strip() if head.get("ok") else None,
140
+ "dirty": bool(dirty_stdout),
141
+ "dirty_status": dirty_stdout.splitlines()[:20],
142
+ "dirty_check_ok": bool(dirty.get("ok")),
143
+ }
144
+
145
+
146
+ def build_install_plan(cwd: str | Path, *, dry_run: bool = False) -> dict[str, Any]:
147
+ cwd_path = Path(cwd).resolve()
148
+ root = runtime_root(cwd_path)
149
+ upstream = root / "upstream"
150
+ ref = upstream_ref()
151
+ actions: list[dict[str, Any]] = []
152
+
153
+ if upstream.exists() and not (upstream / ".git").exists():
154
+ return {
155
+ "ok": False,
156
+ "status": "upstream_path_exists_non_git",
157
+ "paths": runtime_paths(cwd_path),
158
+ "actions": [],
159
+ "recommended_next_action": f"move or remove {upstream} before setup",
160
+ }
161
+
162
+ if not upstream.exists():
163
+ actions.append(_action(
164
+ "clone_numina_upstream",
165
+ ["git", "clone", upstream_url(), str(upstream)],
166
+ cwd_path,
167
+ dry_run=dry_run,
168
+ timeout=1800,
169
+ ))
170
+ else:
171
+ upstream_info = inspect_upstream(cwd_path)
172
+ if not upstream_info.get("dirty_check_ok", True):
173
+ return {
174
+ "ok": False,
175
+ "status": "upstream_status_failed",
176
+ "paths": runtime_paths(cwd_path),
177
+ "upstream": upstream_info,
178
+ "actions": [],
179
+ "recommended_next_action": "inspect the Numina upstream checkout before setup",
180
+ }
181
+ if upstream_info.get("dirty"):
182
+ return {
183
+ "ok": False,
184
+ "status": "dirty_upstream",
185
+ "paths": runtime_paths(cwd_path),
186
+ "upstream": upstream_info,
187
+ "actions": [],
188
+ "recommended_next_action": "review or commit local changes under the Numina upstream checkout before setup",
189
+ }
190
+ actions.append(_action(
191
+ "fetch_numina_upstream",
192
+ ["git", "fetch", "--all", "--prune"],
193
+ upstream,
194
+ dry_run=dry_run,
195
+ timeout=900,
196
+ ))
197
+
198
+ if ref:
199
+ actions.append(_action(
200
+ "checkout_numina_ref",
201
+ ["git", "checkout", ref],
202
+ upstream,
203
+ dry_run=dry_run,
204
+ ))
205
+
206
+ return {
207
+ "ok": True,
208
+ "status": "install_plan_ready",
209
+ "paths": runtime_paths(cwd_path),
210
+ "upstream_ref": ref,
211
+ "actions": actions,
212
+ "recommended_next_action": "review actions, then run configure --setup-numina --project-name <name>",
213
+ }
214
+
215
+
216
+ def build_configure_plan(
217
+ cwd: str | Path,
218
+ *,
219
+ project_name: str | None,
220
+ dry_run: bool = False,
221
+ ) -> dict[str, Any]:
222
+ cwd_path = Path(cwd).resolve()
223
+ if not project_name:
224
+ return {
225
+ "ok": False,
226
+ "status": "missing_project_name",
227
+ "paths": runtime_paths(cwd_path),
228
+ "actions": [],
229
+ "recommended_next_action": "rerun configure --setup-numina with --project-name <name>",
230
+ }
231
+
232
+ install = build_install_plan(cwd_path, dry_run=dry_run)
233
+ if not install.get("ok"):
234
+ return {
235
+ "ok": False,
236
+ "status": install.get("status", "install_plan_failed"),
237
+ "paths": runtime_paths(cwd_path),
238
+ "install": install,
239
+ "actions": [],
240
+ "recommended_next_action": install.get("recommended_next_action"),
241
+ }
242
+
243
+ upstream = runtime_root(cwd_path) / "upstream"
244
+ actions = list(install.get("actions", []))
245
+ actions.extend([
246
+ _action(
247
+ "setup_numina_project",
248
+ ["./setup.sh", project_name],
249
+ upstream / "tutorial",
250
+ dry_run=dry_run,
251
+ timeout=3600,
252
+ ),
253
+ _action(
254
+ "uv_python_install",
255
+ ["uv", "python", "install"],
256
+ upstream,
257
+ dry_run=dry_run,
258
+ timeout=1800,
259
+ ),
260
+ _action(
261
+ "uv_sync",
262
+ ["uv", "sync"],
263
+ upstream,
264
+ dry_run=dry_run,
265
+ timeout=1800,
266
+ ),
267
+ ])
268
+
269
+ return {
270
+ "ok": True,
271
+ "status": "dry_run" if dry_run else "configure_plan_ready",
272
+ "paths": runtime_paths(cwd_path),
273
+ "project_name": project_name,
274
+ "install": install,
275
+ "actions": actions,
276
+ "recommended_next_action": "run official Numina on a buildable Lean project, then validate locally with check/review",
277
+ }
278
+
279
+
280
+ def execute_configure_plan(
281
+ cwd: str | Path,
282
+ *,
283
+ project_name: str | None,
284
+ dry_run: bool = False,
285
+ ) -> dict[str, Any]:
286
+ cwd_path = Path(cwd).resolve()
287
+ plan = build_configure_plan(cwd_path, project_name=project_name, dry_run=dry_run)
288
+ if dry_run or not plan.get("ok"):
289
+ return plan
290
+
291
+ ensure_ai4math_gitignore(cwd_path)
292
+ runtime_root(cwd_path).mkdir(parents=True, exist_ok=True)
293
+ env = read_numina_env_local(cwd_path)
294
+ executed: list[dict[str, Any]] = []
295
+ ok = True
296
+ for action in plan.get("actions", []):
297
+ result = run_command(
298
+ action["command"],
299
+ cwd=action.get("cwd"),
300
+ timeout=int(action.get("timeout", 300)),
301
+ env=env if env else None,
302
+ )
303
+ executed_action = dict(action)
304
+ executed_action.update({
305
+ "ok": result.get("ok"),
306
+ "returncode": result.get("returncode"),
307
+ "stdout": result.get("stdout"),
308
+ "stderr": result.get("stderr"),
309
+ })
310
+ executed.append(executed_action)
311
+ if not result.get("ok"):
312
+ ok = False
313
+ break
314
+
315
+ plan["actions"] = executed
316
+ plan["ok"] = ok
317
+ plan["status"] = "configured" if ok else "numina_setup_failed"
318
+ if not ok:
319
+ plan["recommended_next_action"] = "inspect the failed setup action, then rerun configure --setup-numina after fixing the local environment"
320
+ return plan
321
+
322
+
323
+ def build_run_plan(
324
+ cwd: str | Path,
325
+ *,
326
+ file: str | Path,
327
+ mode: str = "from-folder",
328
+ prompt_file: str = DEFAULT_PROMPT_FILE,
329
+ result_dir: str | Path | None = None,
330
+ max_iters: int = 10,
331
+ reference_resources: str | None = None,
332
+ ) -> dict[str, Any]:
333
+ cwd_path = Path(cwd).resolve()
334
+ target = expand_path(str(file), cwd_path) or Path(file).expanduser().resolve()
335
+ upstream = runtime_root(cwd_path) / "upstream"
336
+ if mode not in {"run", "batch", "from-folder"}:
337
+ return {
338
+ "ok": False,
339
+ "status": "unsupported_numina_mode",
340
+ "mode": mode,
341
+ "supported_modes": ["run", "batch", "from-folder"],
342
+ }
343
+ result_path = expand_path(str(result_dir), cwd_path) if result_dir else runtime_root(cwd_path) / "results" / "manual"
344
+ command = [
345
+ "uv",
346
+ "run",
347
+ "python",
348
+ "-m",
349
+ "scripts.run_claude",
350
+ mode,
351
+ str(target),
352
+ "--prompt-file",
353
+ prompt_file,
354
+ "--max-rounds",
355
+ str(max_iters),
356
+ "--result-dir",
357
+ str(result_path),
358
+ ]
359
+ env = {}
360
+ if reference_resources:
361
+ env["REFERENCE_RESOURCES"] = reference_resources
362
+ return {
363
+ "ok": True,
364
+ "status": "run_plan_ready",
365
+ "cwd": str(upstream),
366
+ "mode": mode,
367
+ "command": command,
368
+ "env": env,
369
+ "target": str(target),
370
+ "result_dir": str(result_path),
371
+ "recommended_next_action": "explain the run to the user, execute only after approval, then validate the resulting Lean patch locally",
372
+ }
373
+
374
+
375
+ def build_batch_plan(cwd: str | Path, *, folder: str | Path, **kwargs: Any) -> dict[str, Any]:
376
+ return build_run_plan(cwd, file=folder, mode="from-folder", **kwargs)
377
+
378
+
379
+ def numina_readiness(cwd: str | Path, target: str | Path | None = None) -> dict[str, Any]:
380
+ cwd_path = Path(cwd).resolve()
381
+ env_local = read_numina_env_local(cwd_path)
382
+ credentials = credential_report(env_local)
383
+ tools = tool_versions(["git", "curl", "uv", "claude"])
384
+ missing_tools = [name for name, info in tools.items() if not info.get("available")]
385
+ upstream = inspect_upstream(cwd_path)
386
+ missing: list[str] = []
387
+ if missing_tools:
388
+ missing.append("tools")
389
+ if not upstream.get("installed"):
390
+ missing.append("upstream")
391
+ can_call_claude = bool(tools.get("claude", {}).get("available")) or credentials["claude"]["configured"]
392
+ if not can_call_claude:
393
+ missing.append("claude_cli_or_auth")
394
+
395
+ result: dict[str, Any] = {
396
+ "ok": not missing,
397
+ "status": "ready" if not missing else "needs_setup",
398
+ "paths": runtime_paths(cwd_path),
399
+ "tools": tools,
400
+ "missing_tools": missing_tools,
401
+ "credentials": credentials,
402
+ "upstream": upstream,
403
+ "missing": missing,
404
+ "readiness": {
405
+ "can_clone_upstream": bool(tools.get("git", {}).get("available")),
406
+ "can_run_setup": all(tools.get(name, {}).get("available") for name in ("git", "curl")),
407
+ "can_sync_python": bool(tools.get("uv", {}).get("available")),
408
+ "can_call_claude_cli": can_call_claude,
409
+ },
410
+ "recommended_next_action": "run configure --setup-numina --project-name <name>" if missing else "ready to discuss an official Numina run",
411
+ }
412
+ if target:
413
+ result["target"] = str(Path(target).expanduser().resolve())
414
+ return result
@@ -0,0 +1,75 @@
1
+ from __future__ import annotations
2
+
3
+ from pathlib import Path
4
+ from typing import Any
5
+
6
+ from common import run_command
7
+ from configure_lean import inspect_environment
8
+ from tool_status import find_tool
9
+
10
+
11
+ SKILL_ROOT = Path(__file__).resolve().parents[1]
12
+ SMOKE_FILE = SKILL_ROOT / "examples" / "smoke" / "LocalLeanSmoke.lean"
13
+
14
+
15
+ def run_smoke_test(
16
+ cwd: str | Path = ".",
17
+ *,
18
+ config_path: str | Path | None = None,
19
+ timeout: int = 120,
20
+ dry_run: bool = False,
21
+ ) -> dict[str, Any]:
22
+ cwd_path = Path(cwd).resolve()
23
+ env = inspect_environment(cwd_path, config_path=config_path)
24
+ lean = env.get("lean", {})
25
+ workspace_root = lean.get("workspace_project_root") or lean.get("project_root")
26
+ lake = find_tool("lake") or "lake"
27
+ command = [lake, "env", "lean", str(SMOKE_FILE)]
28
+ if dry_run:
29
+ return {
30
+ "ok": SMOKE_FILE.exists(),
31
+ "status": "dry_run",
32
+ "cwd": str(cwd_path),
33
+ "project_root": str(workspace_root) if workspace_root else None,
34
+ "smoke_file": str(SMOKE_FILE),
35
+ "command": command,
36
+ "missing_config": [] if workspace_root else ["lean_workspace"],
37
+ "theorems": [
38
+ "ai4math_local_smoke_add_zero",
39
+ "ai4math_local_smoke_le_succ",
40
+ ],
41
+ "external_api_call": False,
42
+ "recommended_next_action": "run the bundled smoke target, then start the coding-agent Lean task or discuss an adapter-first optional backend path",
43
+ }
44
+ if not workspace_root:
45
+ return {
46
+ "ok": False,
47
+ "status": "missing_lean_workspace",
48
+ "cwd": str(cwd_path),
49
+ "smoke_file": str(SMOKE_FILE),
50
+ "project_root": None,
51
+ "environment": env,
52
+ "recommended_next_action": "run configure --create-workspace, then rerun smoke-test",
53
+ }
54
+
55
+ result: dict[str, Any] = {
56
+ "ok": True,
57
+ "status": "ready",
58
+ "cwd": str(cwd_path),
59
+ "project_root": str(workspace_root),
60
+ "smoke_file": str(SMOKE_FILE),
61
+ "command": command,
62
+ "theorems": [
63
+ "ai4math_local_smoke_add_zero",
64
+ "ai4math_local_smoke_le_succ",
65
+ ],
66
+ "external_api_call": False,
67
+ "recommended_next_action": "use this verified workspace for the next coding-agent Lean task; call official Numina only if the optional backend path is approved",
68
+ }
69
+ lean_result = run_command(command, cwd=workspace_root, timeout=timeout)
70
+ result["lean"] = lean_result
71
+ result["ok"] = bool(lean_result.get("ok"))
72
+ result["status"] = "ok" if result["ok"] else "lean_smoke_failed"
73
+ if not result["ok"]:
74
+ result["recommended_next_action"] = "inspect the Lean smoke error, then repair the shared workspace before any Lean task or optional backend call"
75
+ return result
@@ -0,0 +1,79 @@
1
+ from __future__ import annotations
2
+
3
+ import shutil
4
+ from pathlib import Path
5
+ from typing import Any
6
+
7
+ from common import run_command
8
+
9
+
10
+ DEFAULT_TOOLS = ["git", "python3", "elan", "lean", "lake", "curl", "uv", "claude"]
11
+ EXTRA_BIN_DIRS = [
12
+ Path.home() / ".elan" / "bin",
13
+ Path.home() / ".local" / "bin",
14
+ Path.home() / ".cargo" / "bin",
15
+ ]
16
+
17
+
18
+ def find_tool(name: str) -> str | None:
19
+ found = shutil.which(name)
20
+ if found:
21
+ return found
22
+ for directory in EXTRA_BIN_DIRS:
23
+ candidate = directory / name
24
+ if candidate.exists() and candidate.is_file():
25
+ return str(candidate)
26
+ return None
27
+
28
+
29
+ def tool_versions(names: list[str] | None = None) -> dict[str, Any]:
30
+ tools: dict[str, Any] = {}
31
+ for name in names or DEFAULT_TOOLS:
32
+ path = find_tool(name)
33
+ info: dict[str, Any] = {"path": path, "available": bool(path)}
34
+ if path:
35
+ if name in {"lean", "lake"} and ".elan/bin" in path:
36
+ info["version_ok"] = None
37
+ info["version"] = []
38
+ info["version_note"] = "skipped to avoid implicit elan toolchain download"
39
+ tools[name] = info
40
+ continue
41
+ version = run_command([path, "--version"], timeout=20)
42
+ info["version_ok"] = bool(version.get("ok"))
43
+ info["version"] = (version.get("stdout") or version.get("stderr") or "").strip().splitlines()[:3]
44
+ tools[name] = info
45
+ return tools
46
+
47
+
48
+ def doctor(cwd: str | Path = ".") -> dict[str, Any]:
49
+ tools = tool_versions()
50
+ missing = [name for name, info in tools.items() if not info["available"]]
51
+ missing_for_lean_workspace = [name for name in ("lake",) if not tools[name]["available"]]
52
+ missing_for_clone = [name for name in ("git",) if not tools[name]["available"]]
53
+ return {
54
+ "ok": True,
55
+ "status": "reported",
56
+ "cwd": str(Path(cwd).resolve()),
57
+ "tools": tools,
58
+ "missing_tools": missing,
59
+ "readiness": {
60
+ "can_create_lean_workspace": not missing_for_lean_workspace,
61
+ "missing_for_lean_workspace": missing_for_lean_workspace,
62
+ "missing_for_clone": missing_for_clone,
63
+ },
64
+ "recommended_next_action": _recommend(
65
+ missing_for_clone,
66
+ missing_for_lean_workspace,
67
+ ),
68
+ }
69
+
70
+
71
+ def _recommend(
72
+ missing_clone: list[str],
73
+ missing_lean: list[str],
74
+ ) -> str:
75
+ if missing_clone:
76
+ return "install git before using Lake projects with remote dependencies"
77
+ if missing_lean:
78
+ return "install Lean/elan before creating the reusable Lean workspace"
79
+ return "ready for coding-agent Lean workflow and adapter-first optional backend orchestration"