@louisultra/dsh-verymath 0.5.1 → 0.7.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.
- package/CHANGELOG.md +90 -8
- package/lib/client.js +638 -66
- package/lib/core/exec.d.ts +31 -0
- package/lib/core/exec.js +137 -0
- package/lib/core/glossary.d.ts +18 -0
- package/lib/core/glossary.js +20 -0
- package/lib/core/index.d.ts +3 -2
- package/lib/core/index.js +2 -1
- package/lib/http.d.ts +51 -0
- package/lib/http.js +707 -0
- package/lib/index.d.ts +5 -13
- package/lib/index.js +50 -8
- package/lib/tool/index.d.ts +2 -23
- package/lib/tool/index.js +7 -112
- package/package.json +4 -1
- package/skills/math-glossary/scripts/glossary_export.py +5 -0
package/lib/index.d.ts
CHANGED
|
@@ -7,11 +7,10 @@
|
|
|
7
7
|
* package name**. The root entry exists because the host resolves a client
|
|
8
8
|
* plugin's package manifest from the loader entry name: with only `/core` and
|
|
9
9
|
* `/tool` entries the specifier lookup returns undefined, so `dsh.client` is
|
|
10
|
-
* never read and the browser bundle is never served.
|
|
11
|
-
* the whole reason this module is mountable.
|
|
10
|
+
* never read and the browser bundle is never served.
|
|
12
11
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
12
|
+
* It also registers the routes that back the browser panel (see `./http`), so the
|
|
13
|
+
* panel and the chat tools read one implementation of the same logic.
|
|
15
14
|
*
|
|
16
15
|
* Upstream: VeryMath AI4Math repositories (MIT). See NOTICE.md and
|
|
17
16
|
* UPSTREAM.json for per-repository provenance.
|
|
@@ -22,13 +21,6 @@ import type { Context } from '@deepseek-ai/cordis';
|
|
|
22
21
|
export * as core from './core/index.ts';
|
|
23
22
|
export * as tool from './tool/index.ts';
|
|
24
23
|
export declare const name = "verymath-client";
|
|
25
|
-
/**
|
|
24
|
+
/** `connection` is optional on purpose: see the apply comment. */
|
|
26
25
|
export declare const inject: string[];
|
|
27
|
-
|
|
28
|
-
* Mount point for the bare-name loader entry. Deliberately empty: the service and
|
|
29
|
-
* the tools are mounted from `./core` and `./tool`, and the browser half is
|
|
30
|
-
* served by the host from `dsh.client`. Keeping the function (rather than a
|
|
31
|
-
* module without `apply`) means the host mounts an ordinary plugin instead of
|
|
32
|
-
* warning about a module it cannot apply.
|
|
33
|
-
*/
|
|
34
|
-
export declare const apply: (_ctx: Context) => void;
|
|
26
|
+
export declare const apply: (ctx: Context) => void;
|
package/lib/index.js
CHANGED
|
@@ -1,15 +1,57 @@
|
|
|
1
|
+
import { registerHttp } from "./http.js";
|
|
1
2
|
export * as core from "./core/index.js";
|
|
2
3
|
export * as tool from "./tool/index.js";
|
|
3
4
|
export const name = 'verymath-client';
|
|
4
|
-
/**
|
|
5
|
+
/** `connection` is optional on purpose: see the apply comment. */
|
|
5
6
|
export const inject = [];
|
|
6
7
|
/**
|
|
7
|
-
*
|
|
8
|
-
* the tools are mounted from `./core` and `./tool`, and the browser half is
|
|
9
|
-
* served by the host from `dsh.client`. Keeping the function (rather than a
|
|
10
|
-
* module without `apply`) means the host mounts an ordinary plugin instead of
|
|
11
|
-
* warning about a module it cannot apply.
|
|
8
|
+
* Look up an optional host service. The cast is explained where it happens.
|
|
12
9
|
*/
|
|
13
|
-
|
|
14
|
-
//
|
|
10
|
+
function optionalService(ctx, service) {
|
|
11
|
+
// SAFETY: `Context.get` is typed by the cordis service map of the host build,
|
|
12
|
+
// which this package does not import (the workspace registry lives in an
|
|
13
|
+
// optional host package). The cast only narrows an `unknown` that every caller
|
|
14
|
+
// re-checks field by field, so nothing is treated as more than the fields read.
|
|
15
|
+
return ctx.get(service);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The workspace the panel browses.
|
|
19
|
+
*
|
|
20
|
+
* Preferred source is the host's `workspaceRegistry` (each record carries the
|
|
21
|
+
* canonical directory); when that service is absent — a different host build, or
|
|
22
|
+
* a headless run — fall back to the process cwd. The resolved root is returned to
|
|
23
|
+
* the panel so the user can see which directory it reads instead of wondering why
|
|
24
|
+
* a glossary is "missing".
|
|
25
|
+
*/
|
|
26
|
+
function resolveWorkspace(ctx) {
|
|
27
|
+
const registry = optionalService(ctx, 'workspaceRegistry');
|
|
28
|
+
const entities = registry?.entities;
|
|
29
|
+
if (entities instanceof Map) {
|
|
30
|
+
for (const entity of entities.values()) {
|
|
31
|
+
const path = entity?.path;
|
|
32
|
+
if (typeof path === 'string' && path.length > 0)
|
|
33
|
+
return path;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return process.cwd();
|
|
37
|
+
}
|
|
38
|
+
export const apply = (ctx) => {
|
|
39
|
+
ctx.inject(['connection'], (inner) => {
|
|
40
|
+
const connection = optionalService(inner, 'connection');
|
|
41
|
+
// The routes must share the service's write lock and cache instead of keeping
|
|
42
|
+
// their own: two independent lock chains let a panel write and a tool write drop
|
|
43
|
+
// each other's update, and an un-invalidated cache leaves the agent answering
|
|
44
|
+
// from the pre-write snapshot.
|
|
45
|
+
const service = optionalService(inner, 'verymath');
|
|
46
|
+
registerHttp({
|
|
47
|
+
workspace: () => resolveWorkspace(inner),
|
|
48
|
+
log: (message) => inner.logger?.warn?.(message),
|
|
49
|
+
...(service?.withGlossaryWrite !== undefined
|
|
50
|
+
? { withWrite: service.withGlossaryWrite.bind(service) }
|
|
51
|
+
: {}),
|
|
52
|
+
...(service?.invalidateAllGlossaries !== undefined
|
|
53
|
+
? { invalidateGlossaryCache: service.invalidateAllGlossaries.bind(service) }
|
|
54
|
+
: {}),
|
|
55
|
+
}, connection);
|
|
56
|
+
});
|
|
15
57
|
};
|
package/lib/tool/index.d.ts
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import type { Context } from '@deepseek-ai/cordis';
|
|
8
8
|
import z from '@deepseek-ai/schemastery';
|
|
9
|
+
import { executableSearchDirs, resolveExecutable, resolveSageExecutable, sageSearchDirs } from '@louisultra/dsh-verymath/core';
|
|
10
|
+
export { executableSearchDirs, resolveExecutable, resolveSageExecutable, sageSearchDirs };
|
|
9
11
|
export declare const name = "tool-verymath";
|
|
10
12
|
export declare const inject: string[];
|
|
11
13
|
/** Config for the tool layer. */
|
|
@@ -17,28 +19,5 @@ export interface Config {
|
|
|
17
19
|
readonly glossaryHome?: string;
|
|
18
20
|
}
|
|
19
21
|
export declare const Config: z<Config>;
|
|
20
|
-
/**
|
|
21
|
-
* Search path for the SageMath probe only. `sage` is normally installed as a
|
|
22
|
-
* *named* conda environment (`conda create -n sage sage=10.9`), so the base-env
|
|
23
|
-
* directories above are not where it lives; this adds `<root>/envs/<name>/bin`
|
|
24
|
-
* for each known distribution root. Kept separate from the generic search path
|
|
25
|
-
* so TeX and other lookups do not start probing unrelated environment trees.
|
|
26
|
-
*/
|
|
27
|
-
export declare function sageSearchDirs(): string[];
|
|
28
|
-
/**
|
|
29
|
-
* Resolve the `sage` executable: an explicit `VERYMATH_SAGE` path wins, then the
|
|
30
|
-
* SageMath search path (PATH, TeX/conda base dirs, named conda environments).
|
|
31
|
-
* An override that is not executable is ignored rather than reported as found.
|
|
32
|
-
*/
|
|
33
|
-
export declare function resolveSageExecutable(): string | undefined;
|
|
34
|
-
/**
|
|
35
|
-
* Resolve an executable name to an absolute path. Resolving in-process avoids
|
|
36
|
-
* `which`/`where`, which are not both available and which cannot see the TeX
|
|
37
|
-
* fallback directories above. On Windows the `PATHEXT` suffixes are tried.
|
|
38
|
-
* @param name - bare executable name, or a path containing a separator.
|
|
39
|
-
* @param searchDirs - directories probed for a bare name (defaults to PATH plus fallbacks).
|
|
40
|
-
* @returns the resolved absolute path, or undefined when nothing is executable.
|
|
41
|
-
*/
|
|
42
|
-
export declare function resolveExecutable(name: string, searchDirs?: readonly string[]): string | undefined;
|
|
43
22
|
/** Register the VeryMath glossary and paper tools. */
|
|
44
23
|
export declare const apply: (ctx: Context, config?: Config) => void;
|
package/lib/tool/index.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import z from '@deepseek-ai/schemastery';
|
|
2
2
|
import { defineTool } from '@deepseek-ai/dsh-tools';
|
|
3
3
|
import { spawn } from 'node:child_process';
|
|
4
|
-
import {
|
|
5
|
-
import { homedir } from 'node:os';
|
|
6
|
-
import { delimiter, isAbsolute, join, resolve } from 'node:path';
|
|
4
|
+
import { isAbsolute, resolve } from 'node:path';
|
|
7
5
|
import { VeryMathError, isVeryMathError } from '@louisultra/dsh-verymath/core';
|
|
8
|
-
import { bundledSkillsDir, checkGate, computeTopology, dependencySummary, findExcerpt, focusClosure, loadManifest, mergeBatches, mergeStructures, parsePaperBatch, parsePaperStructure, readCorpusDocWindow, renderMermaid, resolveCorpusRoot, searchSageRefs, termsFor, upsertTerms } from '@louisultra/dsh-verymath/core';
|
|
6
|
+
import { bundledSkillsDir, checkGate, computeTopology, dependencySummary, executableSearchDirs, findExcerpt, focusClosure, loadManifest, mergeBatches, mergeStructures, parsePaperBatch, parsePaperStructure, readCorpusDocWindow, renderMermaid, resolveCorpusRoot, resolveExecutable, resolveSageExecutable, sageSearchDirs, searchSageRefs, termsFor, upsertTerms } from '@louisultra/dsh-verymath/core';
|
|
7
|
+
// Re-exported for the tool-level tests and for callers that imported these from
|
|
8
|
+
// the tool module before they moved into `core`. There is exactly one
|
|
9
|
+
// implementation now — two copies used to drift, which is how the panel ended up
|
|
10
|
+
// reporting SageMath missing while `verymath_sage_check` found it.
|
|
11
|
+
export { executableSearchDirs, resolveExecutable, resolveSageExecutable, sageSearchDirs };
|
|
9
12
|
export const name = 'tool-verymath';
|
|
10
13
|
export const inject = ['tools', 'verymath', 'fs'];
|
|
11
14
|
export const Config = z.object({
|
|
@@ -119,114 +122,6 @@ function probeCommand(executable, args, timeoutMs = 5_000) {
|
|
|
119
122
|
});
|
|
120
123
|
}
|
|
121
124
|
/**
|
|
122
|
-
* Directories a TeX distribution installs into without adding them to the
|
|
123
|
-
* inherited PATH. Desktop applications launched from Finder or the Start menu
|
|
124
|
-
* do not read the login shell profile, so MacTeX's `/Library/TeX/texbin` is
|
|
125
|
-
* commonly invisible to a bare `spawn(name)` even when the toolchain is
|
|
126
|
-
* installed. Nothing here is required: an empty result just means PATH decides.
|
|
127
|
-
*/
|
|
128
|
-
function texBinFallbackDirs() {
|
|
129
|
-
return process.platform === 'darwin' ? ['/Library/TeX/texbin'] : [];
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Directories conda-style installs put `python3`/`sage` in but rarely add to the
|
|
133
|
-
* PATH a desktop app inherits: a macOS app launched from Finder reads no login
|
|
134
|
-
* shell profile, so a `sage` installed under `~/miniforge3` is invisible even
|
|
135
|
-
* though the user "has SageMath installed". Derived from the home directory, so
|
|
136
|
-
* nothing here is machine-specific.
|
|
137
|
-
*/
|
|
138
|
-
function condaBinFallbackDirs() {
|
|
139
|
-
const home = homedir();
|
|
140
|
-
return ['miniforge3', 'mambaforge', 'miniconda3', 'anaconda3', 'micromamba']
|
|
141
|
-
.map(name => join(home, name, 'bin'));
|
|
142
|
-
}
|
|
143
|
-
/** Conda distribution roots this package knows about, including its own docs' layout. */
|
|
144
|
-
function condaRoots() {
|
|
145
|
-
const home = homedir();
|
|
146
|
-
return [
|
|
147
|
-
join(home, '.verymath', 'miniforge'),
|
|
148
|
-
join(home, 'miniforge3'),
|
|
149
|
-
join(home, 'mambaforge'),
|
|
150
|
-
join(home, 'miniconda3'),
|
|
151
|
-
join(home, 'anaconda3'),
|
|
152
|
-
];
|
|
153
|
-
}
|
|
154
|
-
/** Executable search path: the inherited PATH first, then platform fallbacks. */
|
|
155
|
-
function executableSearchDirs() {
|
|
156
|
-
const fromEnv = (process.env.PATH ?? '').split(delimiter).filter((dir) => dir.length > 0);
|
|
157
|
-
return [...new Set([...fromEnv, ...texBinFallbackDirs(), ...condaBinFallbackDirs()])];
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Search path for the SageMath probe only. `sage` is normally installed as a
|
|
161
|
-
* *named* conda environment (`conda create -n sage sage=10.9`), so the base-env
|
|
162
|
-
* directories above are not where it lives; this adds `<root>/envs/<name>/bin`
|
|
163
|
-
* for each known distribution root. Kept separate from the generic search path
|
|
164
|
-
* so TeX and other lookups do not start probing unrelated environment trees.
|
|
165
|
-
*/
|
|
166
|
-
export function sageSearchDirs() {
|
|
167
|
-
const dirs = [...executableSearchDirs()];
|
|
168
|
-
for (const root of condaRoots()) {
|
|
169
|
-
const envsDir = join(root, 'envs');
|
|
170
|
-
let names;
|
|
171
|
-
try {
|
|
172
|
-
names = readdirSync(envsDir).sort((left, right) => left.localeCompare(right));
|
|
173
|
-
}
|
|
174
|
-
catch {
|
|
175
|
-
continue;
|
|
176
|
-
}
|
|
177
|
-
for (const name of names)
|
|
178
|
-
dirs.push(join(envsDir, name, 'bin'));
|
|
179
|
-
}
|
|
180
|
-
return [...new Set(dirs)];
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Resolve the `sage` executable: an explicit `VERYMATH_SAGE` path wins, then the
|
|
184
|
-
* SageMath search path (PATH, TeX/conda base dirs, named conda environments).
|
|
185
|
-
* An override that is not executable is ignored rather than reported as found.
|
|
186
|
-
*/
|
|
187
|
-
export function resolveSageExecutable() {
|
|
188
|
-
const override = process.env.VERYMATH_SAGE;
|
|
189
|
-
if (override !== undefined && override.trim().length > 0) {
|
|
190
|
-
const resolved = resolveExecutable(override.trim(), []);
|
|
191
|
-
if (resolved !== undefined)
|
|
192
|
-
return resolved;
|
|
193
|
-
}
|
|
194
|
-
return resolveExecutable('sage', sageSearchDirs());
|
|
195
|
-
}
|
|
196
|
-
/** Whether `candidate` exists and the current user may execute it. */
|
|
197
|
-
function isExecutableFile(candidate) {
|
|
198
|
-
try {
|
|
199
|
-
accessSync(candidate, constants.X_OK);
|
|
200
|
-
return true;
|
|
201
|
-
}
|
|
202
|
-
catch {
|
|
203
|
-
return false;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* Resolve an executable name to an absolute path. Resolving in-process avoids
|
|
208
|
-
* `which`/`where`, which are not both available and which cannot see the TeX
|
|
209
|
-
* fallback directories above. On Windows the `PATHEXT` suffixes are tried.
|
|
210
|
-
* @param name - bare executable name, or a path containing a separator.
|
|
211
|
-
* @param searchDirs - directories probed for a bare name (defaults to PATH plus fallbacks).
|
|
212
|
-
* @returns the resolved absolute path, or undefined when nothing is executable.
|
|
213
|
-
*/
|
|
214
|
-
export function resolveExecutable(name, searchDirs = executableSearchDirs()) {
|
|
215
|
-
if (isAbsolute(name) || name.includes('/') || name.includes('\\')) {
|
|
216
|
-
return isExecutableFile(name) ? name : undefined;
|
|
217
|
-
}
|
|
218
|
-
const extensions = process.platform === 'win32'
|
|
219
|
-
? ['', ...(process.env.PATHEXT ?? '.COM;.EXE;.BAT;.CMD').split(';').filter((ext) => ext.length > 0)]
|
|
220
|
-
: [''];
|
|
221
|
-
for (const dir of searchDirs) {
|
|
222
|
-
for (const extension of extensions) {
|
|
223
|
-
const candidate = join(dir, name + extension);
|
|
224
|
-
if (isExecutableFile(candidate))
|
|
225
|
-
return candidate;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
return undefined;
|
|
229
|
-
}
|
|
230
125
|
/**
|
|
231
126
|
* Probe the math-beamer TeX toolchain: latexmk and xelatex binaries (resolved on
|
|
232
127
|
* PATH, then in the distribution's own bin directory, followed by a `--version`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@louisultra/dsh-verymath",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "VeryMath capabilities for DSH: 16 bundled math skills and 14 tools covering paper reading, bilingual glossary, writing, Beamer, optimization, computation, Lean formalization, research workflows, Sage doc lookup and MATLAB. Community plugin for issue ECNU/EduWork#152.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -73,8 +73,11 @@
|
|
|
73
73
|
"@deepseek-ai/dsh-tool-executor-native": "0.2.2-rc.1",
|
|
74
74
|
"@deepseek-ai/dsh-tools": "0.2.2-rc.1",
|
|
75
75
|
"@deepseek-ai/schemastery": "3.19.0",
|
|
76
|
+
"@testing-library/dom": "10.4.2",
|
|
77
|
+
"@testing-library/react": "16.3.3",
|
|
76
78
|
"@types/js-yaml": "4.0.9",
|
|
77
79
|
"@types/node": "24.19.2",
|
|
80
|
+
"jsdom": "31.0.0",
|
|
78
81
|
"typescript": "6.0.3",
|
|
79
82
|
"vitest": "4.1.8"
|
|
80
83
|
},
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
# DSH bundling note (not upstream): openpyxl's stubs type Worksheet/worksheet cells as
|
|
2
|
+
# Optional, so six reportOptionalMemberAccess / reportAttributeAccessIssue findings fire on
|
|
3
|
+
# code that is correct at runtime (the upstream test suite exercises this path and passes).
|
|
4
|
+
# Scoped to this file only; behaviour is unchanged.
|
|
5
|
+
# pyright: reportOptionalMemberAccess=false, reportAttributeAccessIssue=false
|
|
1
6
|
"""术语库 Excel 导入导出工具。"""
|
|
2
7
|
|
|
3
8
|
from __future__ import annotations
|