@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
package/lib/core/sage.js
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SageMath reference search engine — clean-room TypeScript implementation of
|
|
3
|
+
* the lookup scoring contract described by the VeryMath `sage_ref_search.py`
|
|
4
|
+
* behavior (query/term scoring weights, excerpt extraction). No GPLv3 code is
|
|
5
|
+
* copied: this module only implements a documented scoring shape against a
|
|
6
|
+
* CC BY-SA corpus (SageMath official docs) that the user places outside the
|
|
7
|
+
* package (default `~/.verymath/sagemath-corpus`).
|
|
8
|
+
* @module @louisultra/dsh-verymath/core
|
|
9
|
+
*/
|
|
10
|
+
import { createReadStream } from 'node:fs';
|
|
11
|
+
import { readFile, stat } from 'node:fs/promises';
|
|
12
|
+
import { homedir } from 'node:os';
|
|
13
|
+
import { join, resolve } from 'node:path';
|
|
14
|
+
import readline from 'node:readline';
|
|
15
|
+
import { VeryMathError } from "./error.js";
|
|
16
|
+
/** Default corpus root (user-side, outside the npm package). */
|
|
17
|
+
export function defaultCorpusRoot() {
|
|
18
|
+
const env = process.env.VERYMATH_SAGE_CORPUS;
|
|
19
|
+
return env !== undefined && env.length > 0 ? resolve(env) : join(homedir(), '.verymath', 'sagemath-corpus');
|
|
20
|
+
}
|
|
21
|
+
/** Resolve and validate the corpus root: manifest + api/ must exist. */
|
|
22
|
+
export async function resolveCorpusRoot(configured) {
|
|
23
|
+
const root = configured !== undefined && configured.length > 0 ? resolve(configured) : defaultCorpusRoot();
|
|
24
|
+
const manifestPath = join(root, 'reference_manifest.jsonl');
|
|
25
|
+
try {
|
|
26
|
+
const info = await stat(manifestPath);
|
|
27
|
+
if (!info.isFile())
|
|
28
|
+
throw new Error('manifest is not a file');
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
throw new VeryMathError(`SageMath reference corpus not found at ${root} (expected reference_manifest.jsonl + api/). ` +
|
|
32
|
+
'Place the SageMath docs corpus there, or set VERYMATH_SAGE_CORPUS. ' +
|
|
33
|
+
'The corpus is SageMath official documentation (CC BY-SA 3.0) and is distributed separately from this MIT package.', 'VERYMATH_SAGE_CORPUS_MISSING', { cause: error });
|
|
34
|
+
}
|
|
35
|
+
return root;
|
|
36
|
+
}
|
|
37
|
+
/** Tokenize a query into lowercase terms (>1 char, alphanumeric+underscore). */
|
|
38
|
+
export function termsFor(query) {
|
|
39
|
+
return (query.match(/[A-Za-z0-9_]+/g) ?? [])
|
|
40
|
+
.filter(term => term.length > 1)
|
|
41
|
+
.map(term => term.toLowerCase());
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Score one manifest row against the query, mirroring the documented weight
|
|
45
|
+
* table: exact-substring boosts on title/path/symbols/methods/headings/preview
|
|
46
|
+
* plus per-term additive scores capped on full-text repetition.
|
|
47
|
+
*/
|
|
48
|
+
export function scoreRow(row, query, terms, text) {
|
|
49
|
+
const queryLower = query.toLowerCase().trim();
|
|
50
|
+
const title = row.title.toLowerCase();
|
|
51
|
+
const path = row.api_path.toLowerCase();
|
|
52
|
+
const symbols = row.symbols.join(' ').toLowerCase();
|
|
53
|
+
const methods = row.methods.join(' ').toLowerCase();
|
|
54
|
+
const headings = row.headings.join(' ').toLowerCase();
|
|
55
|
+
const preview = row.preview.toLowerCase();
|
|
56
|
+
const textLower = text.toLowerCase();
|
|
57
|
+
let score = 0;
|
|
58
|
+
if (queryLower.length > 0) {
|
|
59
|
+
if (title.includes(queryLower))
|
|
60
|
+
score += 90;
|
|
61
|
+
if (path.includes(queryLower))
|
|
62
|
+
score += 70;
|
|
63
|
+
if (symbols.includes(queryLower))
|
|
64
|
+
score += 80;
|
|
65
|
+
if (methods.includes(queryLower))
|
|
66
|
+
score += 75;
|
|
67
|
+
if (headings.includes(queryLower))
|
|
68
|
+
score += 55;
|
|
69
|
+
if (preview.includes(queryLower))
|
|
70
|
+
score += 35;
|
|
71
|
+
if (textLower.includes(queryLower))
|
|
72
|
+
score += 25;
|
|
73
|
+
}
|
|
74
|
+
for (const term of terms) {
|
|
75
|
+
if (title.includes(term))
|
|
76
|
+
score += 16;
|
|
77
|
+
if (symbols.includes(term))
|
|
78
|
+
score += 12;
|
|
79
|
+
if (methods.includes(term))
|
|
80
|
+
score += 10;
|
|
81
|
+
if (path.includes(term))
|
|
82
|
+
score += 8;
|
|
83
|
+
if (headings.includes(term))
|
|
84
|
+
score += 6;
|
|
85
|
+
if (preview.includes(term))
|
|
86
|
+
score += 4;
|
|
87
|
+
const count = textLower.split(term).length - 1;
|
|
88
|
+
if (count > 0)
|
|
89
|
+
score += Math.min(18, count);
|
|
90
|
+
}
|
|
91
|
+
return score;
|
|
92
|
+
}
|
|
93
|
+
/** Extract a numbered context snippet around the first match in a document. */
|
|
94
|
+
export function findExcerpt(lines, query, terms, context = 2) {
|
|
95
|
+
const queryLower = query.toLowerCase().trim();
|
|
96
|
+
for (const [index, line] of lines.entries()) {
|
|
97
|
+
const lowered = line.toLowerCase();
|
|
98
|
+
if ((queryLower.length > 0 && lowered.includes(queryLower)) || terms.some(term => lowered.includes(term))) {
|
|
99
|
+
const start = Math.max(0, index - context);
|
|
100
|
+
const stop = Math.min(lines.length, index + context + 1);
|
|
101
|
+
const snippet = [];
|
|
102
|
+
for (let lineno = start; lineno < stop; lineno += 1) {
|
|
103
|
+
const value = lines[lineno]?.replace(/\s+$/u, '') ?? '';
|
|
104
|
+
if (value.length > 0)
|
|
105
|
+
snippet.push(`${lineno + 1}: ${value}`);
|
|
106
|
+
}
|
|
107
|
+
return snippet.join('\n');
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return '';
|
|
111
|
+
}
|
|
112
|
+
/** Parse one JSONL manifest line into a row (tolerating absent optional fields). */
|
|
113
|
+
function parseRow(value) {
|
|
114
|
+
const record = (typeof value === 'object' && value !== null ? value : {});
|
|
115
|
+
const asArray = (input) => Array.isArray(input) ? input.map(item => String(item)) : [];
|
|
116
|
+
return {
|
|
117
|
+
path: String(record.path ?? ''),
|
|
118
|
+
api_path: String(record.api_path ?? ''),
|
|
119
|
+
domain: String(record.domain ?? ''),
|
|
120
|
+
title: String(record.title ?? ''),
|
|
121
|
+
symbols: asArray(record.symbols),
|
|
122
|
+
methods: asArray(record.methods),
|
|
123
|
+
headings: asArray(record.headings),
|
|
124
|
+
preview: String(record.preview ?? ''),
|
|
125
|
+
examples: asArray(record.examples),
|
|
126
|
+
bytes: Number(record.bytes ?? 0),
|
|
127
|
+
lines: Number(record.lines ?? 0),
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Load the full manifest (3196 rows, ~4.6MB JSONL — parsed per call; callers
|
|
132
|
+
* batching multiple queries should hold the result).
|
|
133
|
+
*/
|
|
134
|
+
export async function loadManifest(corpusRoot) {
|
|
135
|
+
const root = await resolveCorpusRoot(corpusRoot);
|
|
136
|
+
const raw = await readFile(join(root, 'reference_manifest.jsonl'), 'utf8');
|
|
137
|
+
const rows = [];
|
|
138
|
+
for (const line of raw.split('\n')) {
|
|
139
|
+
if (line.trim().length === 0)
|
|
140
|
+
continue;
|
|
141
|
+
try {
|
|
142
|
+
rows.push(parseRow(JSON.parse(line)));
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
// Skip malformed lines rather than failing the whole manifest.
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return rows;
|
|
149
|
+
}
|
|
150
|
+
/** Resolve a manifest `path` (which carries a `references/api/` prefix) against the corpus root. */
|
|
151
|
+
export function docPath(root, row) {
|
|
152
|
+
const stripped = row.path.replace(/^references\//u, '');
|
|
153
|
+
return join(root, stripped);
|
|
154
|
+
}
|
|
155
|
+
/** Read one corpus document as text + line array. */
|
|
156
|
+
export async function readCorpusDoc(root, row) {
|
|
157
|
+
const text = await readFile(docPath(root, row), 'utf8');
|
|
158
|
+
return { text, lines: text.split('\n') };
|
|
159
|
+
}
|
|
160
|
+
/** Read only the lines around `aroundLine` (1-based) from a large corpus doc. */
|
|
161
|
+
export async function readCorpusDocWindow(root, row, aroundLine, windowSize = 40) {
|
|
162
|
+
const lines = [];
|
|
163
|
+
const start = Math.max(1, aroundLine - windowSize);
|
|
164
|
+
const stop = aroundLine + windowSize;
|
|
165
|
+
const stream = createReadStream(docPath(root, row), { encoding: 'utf8' });
|
|
166
|
+
const reader = readline.createInterface({ input: stream, crlfDelay: Infinity });
|
|
167
|
+
let lineno = 0;
|
|
168
|
+
for await (const line of reader) {
|
|
169
|
+
lineno += 1;
|
|
170
|
+
if (lineno < start)
|
|
171
|
+
continue;
|
|
172
|
+
lines.push(line);
|
|
173
|
+
if (lineno >= stop)
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
return lines;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Search the corpus: score every manifest row (title/path/symbols/methods/
|
|
180
|
+
* headings/preview against the manifest's own metadata — no doc reads for
|
|
181
|
+
* scoring), take the top hits, then load excerpts for the best `withExcerpts`.
|
|
182
|
+
* @param rows - manifest rows (from {@link loadManifest}).
|
|
183
|
+
* @param query - user query, e.g. "elliptic curve rank" or "solve ODE".
|
|
184
|
+
* @param options - result cap (default 8) and how many excerpts to extract (default 3).
|
|
185
|
+
*/
|
|
186
|
+
export async function searchSageRefs(rows, query, options = {}) {
|
|
187
|
+
const limit = options.limit ?? 8;
|
|
188
|
+
const withExcerpts = options.withExcerpts ?? 3;
|
|
189
|
+
const terms = termsFor(query);
|
|
190
|
+
const scored = rows
|
|
191
|
+
.map(row => ({ row, score: scoreRow(row, query, terms, row.preview) }))
|
|
192
|
+
.sort((left, right) => right.score - left.score)
|
|
193
|
+
.slice(0, limit);
|
|
194
|
+
if (withExcerpts <= 0)
|
|
195
|
+
return scored.map(item => ({ row: item.row, score: item.score, excerpt: '' }));
|
|
196
|
+
const root = await resolveCorpusRoot(options.corpusRoot);
|
|
197
|
+
const hits = [];
|
|
198
|
+
for (const [index, item] of scored.entries()) {
|
|
199
|
+
let excerpt = '';
|
|
200
|
+
if (index < withExcerpts) {
|
|
201
|
+
try {
|
|
202
|
+
const doc = await readCorpusDoc(root, item.row);
|
|
203
|
+
excerpt = findExcerpt(doc.lines, query, terms);
|
|
204
|
+
}
|
|
205
|
+
catch {
|
|
206
|
+
excerpt = '';
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
hits.push({ row: item.row, score: item.score, excerpt });
|
|
210
|
+
}
|
|
211
|
+
return hits;
|
|
212
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type SkillProvider, type SkillCandidate, type SkillDefinition, type SkillLookupOptions } from '@deepseek-ai/dsh-skill';
|
|
2
|
+
/**
|
|
3
|
+
* Provider over the plugin package's `skills/` directory.
|
|
4
|
+
* Registered on `ctx.skills` during `apply()`; bodies are loaded from disk
|
|
5
|
+
* on demand so registry startup stays cheap.
|
|
6
|
+
*/
|
|
7
|
+
export declare class VeryMathSkillProvider implements SkillProvider {
|
|
8
|
+
readonly name = "verymath-bundled";
|
|
9
|
+
list(options: SkillLookupOptions): Promise<readonly SkillCandidate[]>;
|
|
10
|
+
get(candidate: SkillCandidate, options: SkillLookupOptions): Promise<SkillDefinition | undefined>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bundled-skill provider for the VeryMath capability seam: exposes the
|
|
3
|
+
* skills shipped inside the plugin package through the DSH skill registry,
|
|
4
|
+
* mirroring the filesystem provider's bundled-root behavior (rank 600,
|
|
5
|
+
* `source: 'bundled'`, directory resource bases).
|
|
6
|
+
* @module @louisultra/dsh-verymath/core
|
|
7
|
+
*/
|
|
8
|
+
import { readFile, realpath, readdir } from 'node:fs/promises';
|
|
9
|
+
import { join } from 'node:path';
|
|
10
|
+
import { BUNDLED_SKILL_RANK, isSkillName } from '@deepseek-ai/dsh-skill';
|
|
11
|
+
import { bundledSkillsDir } from "./paths.js";
|
|
12
|
+
/** Minimal YAML frontmatter parse for SKILL.md (name/description/whenToUse). */
|
|
13
|
+
function parseFrontmatter(raw) {
|
|
14
|
+
const match = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?([\s\S]*)$/.exec(raw);
|
|
15
|
+
if (match === null || match[1] === undefined || match[2] === undefined)
|
|
16
|
+
return undefined;
|
|
17
|
+
const data = {};
|
|
18
|
+
for (const line of match[1].split(/\r?\n/)) {
|
|
19
|
+
const entry = /^([A-Za-z][\w-]*):\s*(.*)$/.exec(line);
|
|
20
|
+
if (entry === null || entry[1] === undefined || entry[2] === undefined)
|
|
21
|
+
continue;
|
|
22
|
+
data[entry[1]] = entry[2].trim().replace(/^["']|["']$/g, '');
|
|
23
|
+
}
|
|
24
|
+
return { data, body: match[2] };
|
|
25
|
+
}
|
|
26
|
+
/** Real discovery: read `<skills>/<name>/SKILL.md` frontmatter for each entry. */
|
|
27
|
+
async function listBundledSkills(signal) {
|
|
28
|
+
const root = bundledSkillsDir();
|
|
29
|
+
let entries;
|
|
30
|
+
try {
|
|
31
|
+
entries = await readdir(root, { withFileTypes: true, encoding: 'utf8' });
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
if (signal?.aborted === true)
|
|
37
|
+
return [];
|
|
38
|
+
const candidates = [];
|
|
39
|
+
for (const entry of [...entries].sort((left, right) => left.name.localeCompare(right.name))) {
|
|
40
|
+
if (!entry.isDirectory())
|
|
41
|
+
continue;
|
|
42
|
+
const directory = join(root, entry.name);
|
|
43
|
+
const skillPath = join(directory, 'SKILL.md');
|
|
44
|
+
let raw;
|
|
45
|
+
try {
|
|
46
|
+
raw = await readFile(skillPath, { encoding: 'utf8', signal });
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
const parsed = parseFrontmatter(raw);
|
|
52
|
+
const name = parsed?.data.name;
|
|
53
|
+
const description = parsed?.data.description;
|
|
54
|
+
if (parsed === undefined || name === undefined || description === undefined || !isSkillName(name))
|
|
55
|
+
continue;
|
|
56
|
+
candidates.push({
|
|
57
|
+
name,
|
|
58
|
+
description,
|
|
59
|
+
...(parsed.data.whenToUse !== undefined ? { whenToUse: parsed.data.whenToUse } : {}),
|
|
60
|
+
invocation: { modelInvocable: true, userInvocable: true },
|
|
61
|
+
provider: 'verymath-bundled',
|
|
62
|
+
source: 'bundled',
|
|
63
|
+
rank: BUNDLED_SKILL_RANK,
|
|
64
|
+
locator: { path: skillPath, directory },
|
|
65
|
+
resourceBase: { kind: 'directory', path: directory },
|
|
66
|
+
path: skillPath,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return candidates;
|
|
70
|
+
}
|
|
71
|
+
/** Load one bundled skill body from its locator. */
|
|
72
|
+
async function loadBundledSkill(candidate, signal) {
|
|
73
|
+
const locator = candidate.locator;
|
|
74
|
+
let raw;
|
|
75
|
+
try {
|
|
76
|
+
const resolved = await realpath(locator.path);
|
|
77
|
+
raw = await readFile(resolved, { encoding: 'utf8', signal });
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
const parsed = parseFrontmatter(raw);
|
|
83
|
+
if (parsed === undefined)
|
|
84
|
+
return undefined;
|
|
85
|
+
return {
|
|
86
|
+
name: parsed.data.name ?? candidate.name,
|
|
87
|
+
description: parsed.data.description ?? candidate.description,
|
|
88
|
+
...(parsed.data.whenToUse !== undefined ? { whenToUse: parsed.data.whenToUse } : {}),
|
|
89
|
+
invocation: { modelInvocable: true, userInvocable: true },
|
|
90
|
+
provider: 'verymath-bundled',
|
|
91
|
+
source: 'bundled',
|
|
92
|
+
resourceBase: { kind: 'directory', path: locator.directory },
|
|
93
|
+
path: locator.path,
|
|
94
|
+
content: parsed.body.trim(),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Provider over the plugin package's `skills/` directory.
|
|
99
|
+
* Registered on `ctx.skills` during `apply()`; bodies are loaded from disk
|
|
100
|
+
* on demand so registry startup stays cheap.
|
|
101
|
+
*/
|
|
102
|
+
export class VeryMathSkillProvider {
|
|
103
|
+
name = 'verymath-bundled';
|
|
104
|
+
async list(options) {
|
|
105
|
+
return listBundledSkills(options.signal);
|
|
106
|
+
}
|
|
107
|
+
async get(candidate, options) {
|
|
108
|
+
return loadBundledSkill(candidate, options.signal);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model-facing VeryMath tools over `ctx.verymath`: bilingual glossary query
|
|
3
|
+
* and Python-bridged glossary construction, plus paper-structure validation
|
|
4
|
+
* for the adaptive `math-paper-reading` skill artifacts.
|
|
5
|
+
* @module @louisultra/dsh-verymath/tool
|
|
6
|
+
*/
|
|
7
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
8
|
+
import z from '@deepseek-ai/schemastery';
|
|
9
|
+
export declare const name = "tool-verymath";
|
|
10
|
+
export declare const inject: string[];
|
|
11
|
+
/** Config for the tool layer. */
|
|
12
|
+
export interface Config {
|
|
13
|
+
/**
|
|
14
|
+
* Default glossary document path used when a call omits `glossaryPath`.
|
|
15
|
+
* Relative paths resolve against the calling agent's workspace cwd.
|
|
16
|
+
*/
|
|
17
|
+
readonly glossaryHome?: string;
|
|
18
|
+
}
|
|
19
|
+
export declare const Config: z<Config>;
|
|
20
|
+
/** Register the VeryMath glossary and paper tools. */
|
|
21
|
+
export declare const apply: (ctx: Context, config?: Config) => void;
|