@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,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Service Definition for the VeryMath capability seam (`ctx.verymath`):
|
|
3
|
+
* glossary library resolution and querying, Python interpreter discovery for
|
|
4
|
+
* the upstream `math-glossary` scripts, and registration of the bundled
|
|
5
|
+
* VeryMath skills into the DSH skill registry.
|
|
6
|
+
* @module @louisultra/dsh-verymath/core
|
|
7
|
+
*/
|
|
8
|
+
import { Service } from '@deepseek-ai/cordis';
|
|
9
|
+
import z from '@deepseek-ai/schemastery';
|
|
10
|
+
import { spawn } from 'node:child_process';
|
|
11
|
+
import { readFile } from 'node:fs/promises';
|
|
12
|
+
import { normalize } from 'node:path';
|
|
13
|
+
import { VeryMathError } from "./error.js";
|
|
14
|
+
import { parseGlossary, queryGlossary, validateGlossaryInvariants } from "./glossary.js";
|
|
15
|
+
import { bundledSkillsDir } from "./paths.js";
|
|
16
|
+
import { VeryMathSkillProvider } from "./skills.js";
|
|
17
|
+
export { VeryMathError, isVeryMathError } from "./error.js";
|
|
18
|
+
export { bundledSkillsDir } from "./paths.js";
|
|
19
|
+
export { VeryMathSkillProvider } from "./skills.js";
|
|
20
|
+
export { parseGlossary, queryGlossary, sortGlossary, upsertTerms, validateGlossaryInvariants } from "./glossary.js";
|
|
21
|
+
export { parsePaperStructure, dependencySummary } from "./paper.js";
|
|
22
|
+
export { checkGate, checkGoalApproval, checkWorkstreamCompletion, checkFinalRender, loadGoals, listWorkstreams, hasSection, } from "./gates.js";
|
|
23
|
+
export { loadManifest, searchSageRefs, scoreRow, termsFor, findExcerpt, readCorpusDoc, readCorpusDocWindow, resolveCorpusRoot, defaultCorpusRoot, docPath, } from "./sage.js";
|
|
24
|
+
export { mergeBatches, collectEntities, computeTopology, renderMermaid, focusClosure, mermaidDisplayText, stripUncertain, isSingleStructure, requireStructure, } from "./graph.js";
|
|
25
|
+
/**
|
|
26
|
+
* The VeryMath access service, registered as `ctx.verymath`. Owns glossary
|
|
27
|
+
* parsing/querying, Python discovery, and bundled-skill registration.
|
|
28
|
+
*/
|
|
29
|
+
export class VeryMathRuntime extends Service {
|
|
30
|
+
/** The bundled-skill provider needs the host skill registry. */
|
|
31
|
+
static inject = ['skills'];
|
|
32
|
+
static Config = z.object({
|
|
33
|
+
pythonExecutable: z.string(),
|
|
34
|
+
queryMaxHits: z.number(),
|
|
35
|
+
});
|
|
36
|
+
/** Resolved service config with every default applied. */
|
|
37
|
+
config;
|
|
38
|
+
glossaryCache = new Map();
|
|
39
|
+
pythonProbe;
|
|
40
|
+
constructor(ctx, config = {}) {
|
|
41
|
+
super(ctx, 'verymath');
|
|
42
|
+
this.config = {
|
|
43
|
+
pythonExecutable: config.pythonExecutable ?? process.env.DSH_OFFICE_PYTHON ?? 'python3',
|
|
44
|
+
queryMaxHits: config.queryMaxHits ?? 20,
|
|
45
|
+
};
|
|
46
|
+
this.registerBundledSkills(ctx);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Register the bundled-skill provider on the DSH skill registry when the
|
|
50
|
+
* host provides one. Registration is global-layer (unscoped context); the
|
|
51
|
+
* returned disposer is folded into this service's lifecycle so plugin
|
|
52
|
+
* unload removes the provider and invalidates skill catalogs.
|
|
53
|
+
*/
|
|
54
|
+
registerBundledSkills(ctx) {
|
|
55
|
+
const skills = ctx.get('skills');
|
|
56
|
+
if (skills === undefined) {
|
|
57
|
+
this.ctx.logger?.warn?.('verymath: skills service unavailable; bundled skills not registered');
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const dispose = skills.registerProvider(() => new VeryMathSkillProvider());
|
|
61
|
+
this.ctx.effect(() => dispose, 'verymath bundled skills');
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Load and validate a glossary JSON document from disk. Valid documents are
|
|
65
|
+
* cached by absolute path; invalid ones raise `VERYMATH_GLOSSARY_*`.
|
|
66
|
+
* @param path - absolute or workspace-relative path of `glossary.json`.
|
|
67
|
+
* @param signal - cancels the read.
|
|
68
|
+
*/
|
|
69
|
+
async loadGlossary(path, signal) {
|
|
70
|
+
const key = normalize(path);
|
|
71
|
+
const cached = this.glossaryCache.get(key);
|
|
72
|
+
if (cached !== undefined)
|
|
73
|
+
return { path: key, terms: cached };
|
|
74
|
+
let raw;
|
|
75
|
+
try {
|
|
76
|
+
raw = await readFile(key, { encoding: 'utf8', ...(signal !== undefined ? { signal } : {}) });
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
throw new VeryMathError(`cannot read glossary at ${key}: ${error instanceof Error ? error.message : String(error)}`, 'VERYMATH_GLOSSARY_UNAVAILABLE', { cause: error });
|
|
80
|
+
}
|
|
81
|
+
let parsed;
|
|
82
|
+
try {
|
|
83
|
+
parsed = JSON.parse(raw);
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
throw new VeryMathError(`glossary at ${key} is not valid JSON`, 'VERYMATH_GLOSSARY_INVALID', { cause: error });
|
|
87
|
+
}
|
|
88
|
+
const terms = parseGlossary(parsed);
|
|
89
|
+
validateGlossaryInvariants(terms);
|
|
90
|
+
this.glossaryCache.set(key, terms);
|
|
91
|
+
return { path: key, terms };
|
|
92
|
+
}
|
|
93
|
+
/** Forget any cached glossary for `path` so a later load re-reads from disk. */
|
|
94
|
+
invalidateGlossary(path) {
|
|
95
|
+
this.glossaryCache.delete(normalize(path));
|
|
96
|
+
}
|
|
97
|
+
/** Forget every cached glossary (used when a build script's output path is unknown). */
|
|
98
|
+
invalidateAllGlossaries() {
|
|
99
|
+
this.glossaryCache.clear();
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Query a glossary document for terms matching a bilingual query.
|
|
103
|
+
* @param path - glossary document path.
|
|
104
|
+
* @param query - English term, Chinese term, term_id, or subfield name.
|
|
105
|
+
* @param signal - cancels the load.
|
|
106
|
+
*/
|
|
107
|
+
async queryGlossaryFile(path, query, options = {}) {
|
|
108
|
+
const { signal, ...queryOptions } = options;
|
|
109
|
+
const { terms } = await this.loadGlossary(path, signal);
|
|
110
|
+
return queryGlossary(terms, query, { limit: this.config.queryMaxHits, ...queryOptions });
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Locate a Python interpreter able to run the upstream `math-glossary`
|
|
114
|
+
* scripts: the configured executable, then `python3`, then `python`.
|
|
115
|
+
* Resolution runs once and is cached; missing interpreters map to
|
|
116
|
+
* `VERYMATH_PYTHON_UNAVAILABLE` at call sites.
|
|
117
|
+
* @returns the resolved executable, or undefined when none was found.
|
|
118
|
+
*/
|
|
119
|
+
async resolvePython() {
|
|
120
|
+
this.pythonProbe ??= this.probePython();
|
|
121
|
+
return this.pythonProbe;
|
|
122
|
+
}
|
|
123
|
+
async probePython() {
|
|
124
|
+
const candidates = [...new Set([this.config.pythonExecutable, 'python3', 'python'])];
|
|
125
|
+
for (const candidate of candidates) {
|
|
126
|
+
const probe = await this.runPython(candidate, ['--version'], 5_000).catch(() => undefined);
|
|
127
|
+
if (probe !== undefined && probe.exitCode === 0)
|
|
128
|
+
return candidate;
|
|
129
|
+
}
|
|
130
|
+
return undefined;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Run one upstream `math-glossary` script with the resolved interpreter.
|
|
134
|
+
* @param script - script filename inside the upstream `scripts/` directory.
|
|
135
|
+
* @param args - argument list passed to the script.
|
|
136
|
+
* @param timeoutMs - hard kill timeout (default 120s).
|
|
137
|
+
*/
|
|
138
|
+
async runGlossaryScript(script, args, timeoutMs = 120_000) {
|
|
139
|
+
const python = await this.resolvePython();
|
|
140
|
+
if (python === undefined) {
|
|
141
|
+
throw new VeryMathError('no Python interpreter found; install Python 3 and either set the verymath.pythonExecutable config or DSH_OFFICE_PYTHON', 'VERYMATH_PYTHON_UNAVAILABLE');
|
|
142
|
+
}
|
|
143
|
+
if (!/^[\w.-]+\.py$/.test(script)) {
|
|
144
|
+
throw new VeryMathError(`invalid glossary script name ${JSON.stringify(script)}`, 'VERYMATH_IO');
|
|
145
|
+
}
|
|
146
|
+
const scriptPath = bundledSkillsDir() + '/math-glossary/scripts/' + script;
|
|
147
|
+
return this.runPython(python, [scriptPath, ...args], timeoutMs);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Run a Python executable directly with an explicit argument list. Public on
|
|
151
|
+
* purpose for skill-script bridges (e.g. the after-ocr scanner) whose files
|
|
152
|
+
* are bundled inside the plugin package; call sites must keep the script
|
|
153
|
+
* path inside the package and the argument list fully constructed.
|
|
154
|
+
*/
|
|
155
|
+
runPythonCommand(executable, args, timeoutMs) {
|
|
156
|
+
return this.runPython(executable, args, timeoutMs ?? 60_000);
|
|
157
|
+
}
|
|
158
|
+
runPython(executable, args, timeoutMs) {
|
|
159
|
+
return new Promise((resolvePromise, rejectPromise) => {
|
|
160
|
+
let child;
|
|
161
|
+
try {
|
|
162
|
+
child = spawn(executable, [...args], { stdio: ['ignore', 'pipe', 'pipe'] });
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
rejectPromise(error);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
const stdout = [];
|
|
169
|
+
const stderr = [];
|
|
170
|
+
const out = child.stdout;
|
|
171
|
+
const err = child.stderr;
|
|
172
|
+
if (out === null || err === null) {
|
|
173
|
+
rejectPromise(new VeryMathError('python subprocess streams unavailable', 'VERYMATH_IO'));
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
const timer = setTimeout(() => {
|
|
177
|
+
child.kill('SIGKILL');
|
|
178
|
+
rejectPromise(new VeryMathError(`python run exceeded ${timeoutMs}ms`, 'VERYMATH_IO'));
|
|
179
|
+
}, timeoutMs);
|
|
180
|
+
out.on('data', (chunk) => stdout.push(chunk));
|
|
181
|
+
err.on('data', (chunk) => stderr.push(chunk));
|
|
182
|
+
child.on('error', (error) => {
|
|
183
|
+
clearTimeout(timer);
|
|
184
|
+
rejectPromise(error);
|
|
185
|
+
});
|
|
186
|
+
child.on('close', (code) => {
|
|
187
|
+
clearTimeout(timer);
|
|
188
|
+
resolvePromise({
|
|
189
|
+
exitCode: code ?? -1,
|
|
190
|
+
stdout: Buffer.concat(stdout).toString('utf8'),
|
|
191
|
+
stderr: Buffer.concat(stderr).toString('utf8'),
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
export default VeryMathRuntime;
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/** Paper metadata block. */
|
|
2
|
+
export interface PaperMeta {
|
|
3
|
+
readonly title: string;
|
|
4
|
+
readonly authors: readonly string[];
|
|
5
|
+
readonly venue?: string;
|
|
6
|
+
readonly year?: number;
|
|
7
|
+
readonly arxiv_id?: string | null;
|
|
8
|
+
readonly source_file?: string | null;
|
|
9
|
+
readonly language?: 'EN' | 'CN' | 'other';
|
|
10
|
+
readonly analysis_date?: string;
|
|
11
|
+
readonly skill_version?: string;
|
|
12
|
+
readonly paper_type?: readonly string[];
|
|
13
|
+
readonly complexity_estimate?: {
|
|
14
|
+
readonly entity_count_estimate?: number;
|
|
15
|
+
readonly proof_directions?: number;
|
|
16
|
+
readonly skill2_effort?: 'low' | 'medium' | 'high' | 'very_high';
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/** One section in the section map. */
|
|
20
|
+
export interface PaperSection {
|
|
21
|
+
readonly section: string;
|
|
22
|
+
readonly title: string;
|
|
23
|
+
readonly section_type: string;
|
|
24
|
+
readonly core_action?: string;
|
|
25
|
+
readonly key_labels?: readonly string[];
|
|
26
|
+
readonly skill2_action?: '正常提取' | '无需处理' | '提取 proof_variant:2';
|
|
27
|
+
readonly appendix?: boolean;
|
|
28
|
+
}
|
|
29
|
+
/** One related-work comparison entry. */
|
|
30
|
+
export interface RelatedWorkEntry {
|
|
31
|
+
readonly ref: string;
|
|
32
|
+
readonly authors: string;
|
|
33
|
+
readonly year?: number;
|
|
34
|
+
readonly result_summary: string;
|
|
35
|
+
}
|
|
36
|
+
/** One proof method variant. */
|
|
37
|
+
export interface ProofMethod {
|
|
38
|
+
readonly proof_variant?: number;
|
|
39
|
+
readonly method: string;
|
|
40
|
+
readonly detail?: string;
|
|
41
|
+
readonly location?: string;
|
|
42
|
+
}
|
|
43
|
+
/** One main theorem. */
|
|
44
|
+
export interface MainTheorem {
|
|
45
|
+
readonly label: string;
|
|
46
|
+
readonly short_title?: string;
|
|
47
|
+
readonly statement: string;
|
|
48
|
+
readonly location?: {
|
|
49
|
+
readonly section: string;
|
|
50
|
+
readonly page?: string;
|
|
51
|
+
};
|
|
52
|
+
readonly proof_methods?: readonly ProofMethod[];
|
|
53
|
+
readonly role?: 'main' | 'supporting' | 'corollary';
|
|
54
|
+
}
|
|
55
|
+
/** Entity kinds recognized by the upstream extraction contract. */
|
|
56
|
+
export type EntityKind = 'DEFINITION' | 'LEMMA' | 'PROPOSITION' | 'THEOREM' | 'COROLLARY' | 'CONSTRUCTION' | 'CLAIM' | 'OBSERVATION' | 'REMARK';
|
|
57
|
+
/** One structural entity (definition, lemma, theorem, …) with dependency edges. */
|
|
58
|
+
export interface PaperEntity {
|
|
59
|
+
readonly type: EntityKind;
|
|
60
|
+
readonly label: string;
|
|
61
|
+
readonly statement: string;
|
|
62
|
+
readonly location?: {
|
|
63
|
+
readonly section: string;
|
|
64
|
+
readonly page?: string;
|
|
65
|
+
};
|
|
66
|
+
readonly dependencies?: readonly string[];
|
|
67
|
+
readonly uncertain_dependencies?: readonly string[];
|
|
68
|
+
readonly cited_by?: readonly string[];
|
|
69
|
+
readonly external_refs?: readonly string[];
|
|
70
|
+
readonly proof_methods?: readonly ProofMethod[];
|
|
71
|
+
readonly parent_result?: string | null;
|
|
72
|
+
readonly role_in_parent?: string | null;
|
|
73
|
+
readonly shared_node?: boolean;
|
|
74
|
+
readonly auto_labeled?: boolean;
|
|
75
|
+
}
|
|
76
|
+
/** One numeric/computational table. */
|
|
77
|
+
export interface PaperTable {
|
|
78
|
+
readonly label: string;
|
|
79
|
+
readonly title: string;
|
|
80
|
+
readonly data_source?: 'computer_search' | 'formula' | 'mixed';
|
|
81
|
+
readonly location?: {
|
|
82
|
+
readonly section: string;
|
|
83
|
+
readonly page?: string;
|
|
84
|
+
};
|
|
85
|
+
readonly rows?: readonly {
|
|
86
|
+
readonly parameter: string;
|
|
87
|
+
readonly value: string;
|
|
88
|
+
readonly source?: string;
|
|
89
|
+
readonly open?: boolean;
|
|
90
|
+
}[];
|
|
91
|
+
}
|
|
92
|
+
/** Proof framework summary. */
|
|
93
|
+
export interface ProofFramework {
|
|
94
|
+
readonly center_theorem?: string;
|
|
95
|
+
readonly dependency_tree?: string;
|
|
96
|
+
readonly proof_strategies?: readonly {
|
|
97
|
+
readonly direction?: string;
|
|
98
|
+
readonly proof_variant?: number;
|
|
99
|
+
readonly method: string;
|
|
100
|
+
readonly object_constructed?: string | null;
|
|
101
|
+
readonly case_split?: string | null;
|
|
102
|
+
readonly key_tools?: readonly string[];
|
|
103
|
+
}[];
|
|
104
|
+
readonly timeline?: readonly {
|
|
105
|
+
readonly step: number;
|
|
106
|
+
readonly label: string;
|
|
107
|
+
readonly establishes: string;
|
|
108
|
+
readonly method: string;
|
|
109
|
+
readonly location?: string;
|
|
110
|
+
readonly used_by?: readonly string[];
|
|
111
|
+
}[];
|
|
112
|
+
readonly strategy_summary?: string;
|
|
113
|
+
}
|
|
114
|
+
/** Completeness review block. */
|
|
115
|
+
export interface CompletenessCheck {
|
|
116
|
+
readonly dependency_integrity?: readonly {
|
|
117
|
+
readonly edge: string;
|
|
118
|
+
readonly status: 'ok' | 'missing' | 'external';
|
|
119
|
+
readonly note?: string;
|
|
120
|
+
}[];
|
|
121
|
+
readonly self_containment?: 'high' | 'medium' | 'low';
|
|
122
|
+
readonly external_deps?: readonly {
|
|
123
|
+
readonly label: string;
|
|
124
|
+
readonly ref: string;
|
|
125
|
+
readonly impact?: string;
|
|
126
|
+
}[];
|
|
127
|
+
readonly isolated_results?: readonly {
|
|
128
|
+
readonly label: string;
|
|
129
|
+
readonly possible_reasons?: readonly string[];
|
|
130
|
+
}[];
|
|
131
|
+
readonly circular_deps?: readonly string[];
|
|
132
|
+
}
|
|
133
|
+
/** The complete `<slug>_structure.json` artifact. */
|
|
134
|
+
export interface PaperStructure {
|
|
135
|
+
readonly paper: PaperMeta;
|
|
136
|
+
readonly section_map?: readonly PaperSection[];
|
|
137
|
+
readonly related_work?: readonly RelatedWorkEntry[];
|
|
138
|
+
readonly paper_summary?: string;
|
|
139
|
+
readonly main_theorems?: readonly MainTheorem[];
|
|
140
|
+
readonly theorem_relations?: string;
|
|
141
|
+
readonly entities?: readonly PaperEntity[];
|
|
142
|
+
readonly tables?: readonly PaperTable[];
|
|
143
|
+
readonly proof_framework?: ProofFramework;
|
|
144
|
+
readonly completeness_check?: CompletenessCheck;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Parse and structurally validate one paper-structure artifact: paper
|
|
148
|
+
* metadata must be present, entities must use recognized kinds, and
|
|
149
|
+
* dependency labels must reference known entities or main theorems.
|
|
150
|
+
* @param value - the parsed JSON value of a `<slug>_structure.json`.
|
|
151
|
+
* @returns the validated structure.
|
|
152
|
+
*/
|
|
153
|
+
export declare function parsePaperStructure(value: unknown): PaperStructure;
|
|
154
|
+
/**
|
|
155
|
+
* Compute a compact dependency summary: per-entity dependent counts and the
|
|
156
|
+
* entities no other entity depends on (roots of the dependency forest).
|
|
157
|
+
* @param structure - a validated paper structure.
|
|
158
|
+
* @returns counts by label plus root labels.
|
|
159
|
+
*/
|
|
160
|
+
export declare function dependencySummary(structure: PaperStructure): {
|
|
161
|
+
readonly dependentCounts: Readonly<Record<string, number>>;
|
|
162
|
+
readonly roots: readonly string[];
|
|
163
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured extraction artifact for mathematical papers, aligned with the
|
|
3
|
+
* upstream VeryMath `math-paper-reading` skill contract (skill_base.md v4.2
|
|
4
|
+
* JSON schema): paper metadata, section map, main theorems, entities with
|
|
5
|
+
* dependency edges, tables, proof framework, and completeness review.
|
|
6
|
+
* @module @louisultra/dsh-verymath/core
|
|
7
|
+
*/
|
|
8
|
+
import { VeryMathError } from "./error.js";
|
|
9
|
+
const ENTITY_KINDS = [
|
|
10
|
+
'DEFINITION', 'LEMMA', 'PROPOSITION', 'THEOREM', 'COROLLARY',
|
|
11
|
+
'CONSTRUCTION', 'CLAIM', 'OBSERVATION', 'REMARK',
|
|
12
|
+
];
|
|
13
|
+
function isRecord(value) {
|
|
14
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Parse and structurally validate one paper-structure artifact: paper
|
|
18
|
+
* metadata must be present, entities must use recognized kinds, and
|
|
19
|
+
* dependency labels must reference known entities or main theorems.
|
|
20
|
+
* @param value - the parsed JSON value of a `<slug>_structure.json`.
|
|
21
|
+
* @returns the validated structure.
|
|
22
|
+
*/
|
|
23
|
+
export function parsePaperStructure(value) {
|
|
24
|
+
if (!isRecord(value)) {
|
|
25
|
+
throw new VeryMathError('paper structure must be a JSON object', 'VERYMATH_PAPER_INVALID');
|
|
26
|
+
}
|
|
27
|
+
const paper = value.paper;
|
|
28
|
+
if (!isRecord(paper) || typeof paper.title !== 'string' || paper.title.length === 0) {
|
|
29
|
+
throw new VeryMathError('paper structure requires paper.title', 'VERYMATH_PAPER_INVALID');
|
|
30
|
+
}
|
|
31
|
+
// SAFETY: every required field was validated above (paper.title) and every
|
|
32
|
+
// consumed field below is re-narrowed at its use site (ENTITY_KINDS check,
|
|
33
|
+
// dependency label set), so the loosely-typed record satisfies PaperStructure
|
|
34
|
+
// for all fields this module reads; optional fields may be absent per the
|
|
35
|
+
// upstream v4.2 compact form and are handled with `?? []` everywhere.
|
|
36
|
+
const structure = value;
|
|
37
|
+
const entities = structure.entities ?? [];
|
|
38
|
+
const labels = new Set();
|
|
39
|
+
for (const entity of entities) {
|
|
40
|
+
if (!ENTITY_KINDS.includes(entity.type)) {
|
|
41
|
+
throw new VeryMathError(`entity ${entity.label}: unknown type ${String(entity.type)}`, 'VERYMATH_PAPER_INVALID');
|
|
42
|
+
}
|
|
43
|
+
labels.add(entity.label);
|
|
44
|
+
}
|
|
45
|
+
for (const theorem of structure.main_theorems ?? [])
|
|
46
|
+
labels.add(theorem.label);
|
|
47
|
+
for (const entity of entities) {
|
|
48
|
+
for (const dependency of entity.dependencies ?? []) {
|
|
49
|
+
if (!labels.has(dependency)) {
|
|
50
|
+
throw new VeryMathError(`entity ${entity.label} depends on unknown label ${dependency}`, 'VERYMATH_PAPER_INVALID');
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return structure;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Compute a compact dependency summary: per-entity dependent counts and the
|
|
58
|
+
* entities no other entity depends on (roots of the dependency forest).
|
|
59
|
+
* @param structure - a validated paper structure.
|
|
60
|
+
* @returns counts by label plus root labels.
|
|
61
|
+
*/
|
|
62
|
+
export function dependencySummary(structure) {
|
|
63
|
+
const dependentCounts = {};
|
|
64
|
+
const dependedOn = new Set();
|
|
65
|
+
for (const entity of structure.entities ?? []) {
|
|
66
|
+
dependentCounts[entity.label] = (dependentCounts[entity.label] ?? 0) + (entity.cited_by?.length ?? 0);
|
|
67
|
+
for (const dependency of entity.dependencies ?? [])
|
|
68
|
+
dependedOn.add(dependency);
|
|
69
|
+
}
|
|
70
|
+
const known = new Set([...(structure.entities ?? []).map(entity => entity.label), ...(structure.main_theorems ?? []).map(theorem => theorem.label)]);
|
|
71
|
+
const roots = [...known].filter(label => !dependedOn.has(label)).sort();
|
|
72
|
+
return { dependentCounts, roots };
|
|
73
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Package-internal path resolution for bundled resources.
|
|
3
|
+
* @module @louisultra/dsh-verymath/core
|
|
4
|
+
*/
|
|
5
|
+
import { dirname, join, normalize } from 'node:path';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
/** Directory of the compiled `core` module; bundled skills live at `../../skills`. */
|
|
8
|
+
const moduleDir = dirname(fileURLToPath(import.meta.url));
|
|
9
|
+
/** Resolve the bundled skills directory shipped inside the plugin package. */
|
|
10
|
+
export function bundledSkillsDir() {
|
|
11
|
+
return normalize(join(moduleDir, '..', '..', 'skills'));
|
|
12
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/** Default corpus root (user-side, outside the npm package). */
|
|
2
|
+
export declare function defaultCorpusRoot(): string;
|
|
3
|
+
/** One manifest row (subset of fields the scorer uses). */
|
|
4
|
+
export interface SageRefRow {
|
|
5
|
+
readonly path: string;
|
|
6
|
+
readonly api_path: string;
|
|
7
|
+
readonly domain: string;
|
|
8
|
+
readonly title: string;
|
|
9
|
+
readonly symbols: readonly string[];
|
|
10
|
+
readonly methods: readonly string[];
|
|
11
|
+
readonly headings: readonly string[];
|
|
12
|
+
readonly preview: string;
|
|
13
|
+
readonly examples: readonly string[];
|
|
14
|
+
readonly bytes: number;
|
|
15
|
+
readonly lines: number;
|
|
16
|
+
}
|
|
17
|
+
/** One scored search hit. */
|
|
18
|
+
export interface SageRefHit {
|
|
19
|
+
readonly row: SageRefRow;
|
|
20
|
+
readonly score: number;
|
|
21
|
+
readonly excerpt: string;
|
|
22
|
+
}
|
|
23
|
+
/** Resolve and validate the corpus root: manifest + api/ must exist. */
|
|
24
|
+
export declare function resolveCorpusRoot(configured?: string): Promise<string>;
|
|
25
|
+
/** Tokenize a query into lowercase terms (>1 char, alphanumeric+underscore). */
|
|
26
|
+
export declare function termsFor(query: string): string[];
|
|
27
|
+
/**
|
|
28
|
+
* Score one manifest row against the query, mirroring the documented weight
|
|
29
|
+
* table: exact-substring boosts on title/path/symbols/methods/headings/preview
|
|
30
|
+
* plus per-term additive scores capped on full-text repetition.
|
|
31
|
+
*/
|
|
32
|
+
export declare function scoreRow(row: SageRefRow, query: string, terms: readonly string[], text: string): number;
|
|
33
|
+
/** Extract a numbered context snippet around the first match in a document. */
|
|
34
|
+
export declare function findExcerpt(lines: readonly string[], query: string, terms: readonly string[], context?: number): string;
|
|
35
|
+
/**
|
|
36
|
+
* Load the full manifest (3196 rows, ~4.6MB JSONL — parsed per call; callers
|
|
37
|
+
* batching multiple queries should hold the result).
|
|
38
|
+
*/
|
|
39
|
+
export declare function loadManifest(corpusRoot?: string): Promise<SageRefRow[]>;
|
|
40
|
+
/** Resolve a manifest `path` (which carries a `references/api/` prefix) against the corpus root. */
|
|
41
|
+
export declare function docPath(root: string, row: Pick<SageRefRow, 'path'>): string;
|
|
42
|
+
/** Read one corpus document as text + line array. */
|
|
43
|
+
export declare function readCorpusDoc(root: string, row: SageRefRow): Promise<{
|
|
44
|
+
text: string;
|
|
45
|
+
lines: string[];
|
|
46
|
+
}>;
|
|
47
|
+
/** Read only the lines around `aroundLine` (1-based) from a large corpus doc. */
|
|
48
|
+
export declare function readCorpusDocWindow(root: string, row: SageRefRow, aroundLine: number, windowSize?: number): Promise<string[]>;
|
|
49
|
+
/**
|
|
50
|
+
* Search the corpus: score every manifest row (title/path/symbols/methods/
|
|
51
|
+
* headings/preview against the manifest's own metadata — no doc reads for
|
|
52
|
+
* scoring), take the top hits, then load excerpts for the best `withExcerpts`.
|
|
53
|
+
* @param rows - manifest rows (from {@link loadManifest}).
|
|
54
|
+
* @param query - user query, e.g. "elliptic curve rank" or "solve ODE".
|
|
55
|
+
* @param options - result cap (default 8) and how many excerpts to extract (default 3).
|
|
56
|
+
*/
|
|
57
|
+
export declare function searchSageRefs(rows: readonly SageRefRow[], query: string, options?: {
|
|
58
|
+
readonly limit?: number;
|
|
59
|
+
readonly withExcerpts?: number;
|
|
60
|
+
readonly corpusRoot?: string;
|
|
61
|
+
}): Promise<SageRefHit[]>;
|