dsh-mworks-ai 1.1.0 → 1.1.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/README.md +43 -14
- package/client.js +4 -4
- package/cordis.patch.yml +12 -3
- package/icon.png +0 -0
- package/lib/index.js +623 -141
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -20,6 +20,18 @@ The package declares `dsh.bundle.patch` (`cordis.patch.yml`) and `dsh.client`, s
|
|
|
20
20
|
| Instructions | The official MWORKS working rules: Syslab needs `read_syslab_skill` → `detect_syslab_toolboxes` before any code execution; prefer `Ty*` packages; confirm APIs from local help; call `session_manager` before other Sysplorer tools; keep outputs out of the installation directories. Plus the recovery rule: a MWORKS call that stops answering is not fixed by retrying — read `mworks_mcp_status` and rebuild the server instead. |
|
|
21
21
|
| UI | A **Runtime environment** section on this bundle's own page under **Plugins**, below the configuration the Plugin Manager draws. It lists the detected Syslab and Sysplorer installations and versions, the Julia runtime, both MCP servers with their live connection state, and the MWORKS skills this session can call, with **Re-detect** and, for a server that is not connected, **Reconnect**. The section renders nothing on any other plugin's page. Nothing is added to the conversation. |
|
|
22
22
|
|
|
23
|
+
## The two HTTP routes
|
|
24
|
+
|
|
25
|
+
The section reads `GET /api/dsh-mworks-ai/environment`; its **Reconnect** control posts to `POST /api/dsh-mworks-ai/restart`. Both are gated the way the Host's own routes are:
|
|
26
|
+
|
|
27
|
+
| Layer | What it stops |
|
|
28
|
+
|---|---|
|
|
29
|
+
| `ctx.connection.requestRejection(request)` | The Host's access check: a `Host` fence (loopback, the bind address or `trustedHosts`) that a rebinding page cannot forge, the cross-site and `Origin` fences, and the browser login cookie. Its `401`/`403` is written as-is, and its verdict is **final** — this plugin does not add a second opinion when the service is mounted, because it cannot see the deployment's `trustedHosts`. |
|
|
30
|
+
| Local same-origin test | Fallback for a profile that mounts no `connection` service. On its own it cannot see a bare browser read over plain HTTP, so it is never the only defence. |
|
|
31
|
+
| `application/json` required on `/restart` | A cross-site "simple request" can carry `text/plain` without a CORS preflight; anything else is `415` before the body is parsed. |
|
|
32
|
+
|
|
33
|
+
A guard that throws refuses rather than falling through.
|
|
34
|
+
|
|
23
35
|
## Why the MCP servers are owned by the MCP manager
|
|
24
36
|
|
|
25
37
|
`cordis.patch.yml` contains only this plugin's own row: the two servers are contributed at runtime through `ctx.mcpManager.register()`, not as bare `@deepseek-ai/dsh-mcp-client` rows. That buys two things a bare row cannot:
|
|
@@ -29,6 +41,19 @@ The package declares `dsh.bundle.patch` (`cordis.patch.yml`) and `dsh.client`, s
|
|
|
29
41
|
|
|
30
42
|
Both matter because of a failure mode that otherwise stays invisible: when Sysplorer is restarted underneath a running session, the MCP child keeps running but stays attached to the old engine port. It emits no close and no error, so the client bridge has nothing to reconnect on, and every subsequent call blocks until `toolCallTimeoutMs` (five minutes) expires. Killing/remounting the child is what re-runs engine discovery and re-attaches to the live port — verified by killing a wedged child and watching a fresh one attach to the new port.
|
|
31
43
|
|
|
44
|
+
## Skills
|
|
45
|
+
|
|
46
|
+
The MWORKS skills are **registered by this plugin from the copies inside the MWORKS installation** (`<Sysplorer>/Tools/sysplorer_mcp/resources/modeling_skills` and `<Syslab>/Tools/syslab-skills`), the same way a skill bundle registers its own `skills/` directory. That matters because the MWORKS installers also copy those bundles into an AI client's folder (`%USERPROFILE%\.config\opencode\skills` for OpenCode), and no DeepSeek Harness provider scans that path on its own — without an explicit contribution, the skills reach the catalog only when some other plugin happens to read that directory.
|
|
47
|
+
|
|
48
|
+
- **No dependency on OpenCode.** OpenCode need not be installed and its folder need not exist; the plugin reads the installation instead.
|
|
49
|
+
- **No interference.** The plugin writes nothing into any client's skill folder, and it fills a gap only: when the registry already resolves any MWORKS skill, it registers nothing, so it never duplicates or overrides another provider's decisions (including a per-skill disable list).
|
|
50
|
+
- **Only MWORKS skills are taken from shared folders.** Every bundle counts inside the installation directories; from a shared client directory such as OpenCode's, only names MWORKS owns (`ty-`, `syslab-`, `ta-`, `modelica-library-workflow`, `sysplorer-mds-docs`) are claimed.
|
|
51
|
+
- **Gap fill by name.** A skill the registry already resolves is left to whichever provider supplies it; only missing names are registered from the installation.
|
|
52
|
+
- **Opt out.** Set `registerSkills: false` on this plugin's row to stop the contribution entirely, for example when another provider manages the MWORKS skills and you want its per-skill filtering to win.
|
|
53
|
+
- **Names come from frontmatter.** Folded (`>-`) and literal (`|`) descriptions are parsed, and each registration carries a directory `resourceBase`, so a skill's `references/`, `templates/` and `tests/` resolve against the installed bundle.
|
|
54
|
+
|
|
55
|
+
The Runtime environment section and `mworks_environment` report what the registry actually resolves and say whether that answer came from the registry or from the on-disk scan.
|
|
56
|
+
|
|
32
57
|
## Configuration
|
|
33
58
|
|
|
34
59
|
Server definitions (command, args, env, cwd, timeouts, reconnect policy) live in the `SERVERS` table of `lib/index.js`. Defaults:
|
|
@@ -43,25 +68,29 @@ A profile must mount `@deepseek-ai/dsh-mcp-manager` (the Web and Desktop profile
|
|
|
43
68
|
|
|
44
69
|
## Requirements
|
|
45
70
|
|
|
46
|
-
- A local MWORKS installation. The
|
|
47
|
-
|
|
48
|
-
- Sysplorer `E:\MWORKS\Sysplorer 2026b`
|
|
49
|
-
- Julia `C:\Users\Public\TongYuan\julia-1.10.10`
|
|
50
|
-
|
|
51
|
-
Edit `cordis.patch.yml` if MWORKS lives elsewhere; the Runtime environment section and `mworks_environment` report what is actually found.
|
|
52
|
-
- The MWORKS skills you want the agent to follow, installed into a skill root the Harness scans (for example `~/.config/opencode/skills`, where the MWORKS installers put them).
|
|
71
|
+
- A local MWORKS installation. The plugin ships **no paths**: at load time it resolves each installation and derives the MCP command, args and working directory from what it found. A product that is not installed contributes no server, and the plugin still loads.
|
|
72
|
+
- The profile must mount `@deepseek-ai/dsh-skill` (every standard profile does) for the skills to reach the agent, and `@deepseek-ai/dsh-mcp-manager` for the MCP servers. Both are part of the Web and Desktop profiles.
|
|
53
73
|
|
|
54
|
-
##
|
|
74
|
+
## How the installation is found
|
|
55
75
|
|
|
56
|
-
|
|
76
|
+
Resolution is three steps, first hit wins:
|
|
57
77
|
|
|
58
|
-
|
|
|
78
|
+
| Step | Source |
|
|
59
79
|
|---|---|
|
|
60
|
-
|
|
|
61
|
-
|
|
|
62
|
-
|
|
|
80
|
+
| 1 | This row's config: `syslabRoot`, `sysplorerRoot`, `juliaRoot`, `workspace`, `registerSkills` |
|
|
81
|
+
| 2 | The environment: `MWORKS_HOME`, `MWORKS_SYSLAB_HOME`, `MWORKS_SYSPLORER_HOME`, `MWORKS_JULIA_HOME`, `MWORKS_WORKSPACE` (plus the products' own `SYSLAB_HOME` / `JULIA_ROOT`) |
|
|
82
|
+
| 3 | A directory scan for `<Syslab|Sysplorer> <release>` inside the usual install bases (`%ProgramFiles%`, `%ProgramFiles(x86)%`, `%LOCALAPPDATA%`, the user profile, `<drive>\MWORKS`), newest release first; a directory only counts when the product's payload is present |
|
|
83
|
+
|
|
84
|
+
A Julia directory only counts when it really is a runtime (`bin/julia`, not a folder that merely resembles one — Syslab also keeps a `syslab-julia` data directory). The modeling workspace defaults to `~/.dsh-mworks-ai/workspace`, created on demand, so nothing is ever written into the installation directories.
|
|
63
85
|
|
|
64
|
-
|
|
86
|
+
## Startup parameters that matter
|
|
87
|
+
|
|
88
|
+
`cordis.patch.yml` inserts one row, this plugin's own; the two MCP servers are contributed at runtime (see above). Two flags cost a debugging session each:
|
|
89
|
+
|
|
90
|
+
| Where | Detail |
|
|
91
|
+
|---|---|
|
|
92
|
+
| Syslab args | `--syslab-display-mode=nodesktop` keeps Julia calls off an open Syslab desktop; `--syslab-root` is mandatory or the server panics. |
|
|
93
|
+
| Sysplorer entry | Start through `Tools/sysplorer_mcp/main.py`, the launcher that exports `MCP_DEPLOY_ROOT`. Starting the inner `main.py` breaks `resources_retrieval` while `tools/list` still looks healthy. |
|
|
65
94
|
|
|
66
95
|
## Checks
|
|
67
96
|
|
package/client.js
CHANGED
|
@@ -59,8 +59,8 @@ window.__ModuleLoader__.load({
|
|
|
59
59
|
reconnectFailed: '重新连接失败:{error}',
|
|
60
60
|
managedTools: '{count} 个工具已注册',
|
|
61
61
|
skills: '本会话可用的 MWORKS 技能',
|
|
62
|
-
skillsHint: '
|
|
63
|
-
noSkills: '
|
|
62
|
+
skillsHint: '由本插件从 MWORKS 安装目录注册,不依赖其它客户端的 skill 目录。',
|
|
63
|
+
noSkills: '未找到可加载的 MWORKS 技能:请确认 MWORKS 已安装,或本机 skill 目录中存在 MWORKS 技能。',
|
|
64
64
|
version: '版本 {version}',
|
|
65
65
|
buildDate: '构建于 {date}',
|
|
66
66
|
moreRoots: '另有 {count} 个安装目录',
|
|
@@ -100,8 +100,8 @@ window.__ModuleLoader__.load({
|
|
|
100
100
|
reconnectFailed: 'Reconnect failed: {error}',
|
|
101
101
|
managedTools: '{count} tools registered',
|
|
102
102
|
skills: 'MWORKS skills available in this session',
|
|
103
|
-
skillsHint: '
|
|
104
|
-
noSkills: 'No MWORKS skill is
|
|
103
|
+
skillsHint: 'Registered by this plugin from the MWORKS installation, not from another client\'s skill folder.',
|
|
104
|
+
noSkills: 'No MWORKS skill could be loaded: check that MWORKS is installed, or that its skills exist in a local skill folder.',
|
|
105
105
|
version: 'Version {version}',
|
|
106
106
|
buildDate: 'Built {date}',
|
|
107
107
|
moreRoots: '{count} more installation directories',
|
package/cordis.patch.yml
CHANGED
|
@@ -13,9 +13,18 @@
|
|
|
13
13
|
# detached — it emits no close or error, so the client bridge has nothing to
|
|
14
14
|
# reconnect on.
|
|
15
15
|
#
|
|
16
|
-
# Server definitions
|
|
17
|
-
#
|
|
18
|
-
# the
|
|
16
|
+
# Server definitions and their startup parameters live in lib/index.js. The
|
|
17
|
+
# plugin carries no machine path: at load time it resolves each installation
|
|
18
|
+
# from (in this order) this row's config, the environment, and a directory scan,
|
|
19
|
+
# then derives the command, args and working directory from what it found. A
|
|
20
|
+
# product that is not installed contributes no server at all.
|
|
21
|
+
# - config, e.g. `config: { syslabRoot: D:\MWORKS\Syslab 2026b }` (keys:
|
|
22
|
+
# syslabRoot, sysplorerRoot, juliaRoot, workspace, registerSkills)
|
|
23
|
+
# - environment: MWORKS_HOME, MWORKS_SYSLAB_HOME, MWORKS_SYSPLORER_HOME,
|
|
24
|
+
# MWORKS_JULIA_HOME, MWORKS_WORKSPACE (and SYSLAB_HOME / JULIA_ROOT as the
|
|
25
|
+
# products' own spellings)
|
|
26
|
+
#
|
|
27
|
+
# Startup parameters were verified against the installed servers:
|
|
19
28
|
# - Syslab needs --syslab-root (the server panics without it) and must run
|
|
20
29
|
# --syslab-display-mode=nodesktop, or Julia calls attach to an already open
|
|
21
30
|
# Syslab desktop and leave stray processes behind.
|
package/icon.png
ADDED
|
Binary file
|
package/lib/index.js
CHANGED
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
* @module dsh-mworks-ai
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
|
-
import { existsSync, readFileSync, readdirSync } from 'node:fs'
|
|
29
|
-
import { join } from 'node:path'
|
|
28
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync } from 'node:fs'
|
|
29
|
+
import { basename, join } from 'node:path'
|
|
30
30
|
import { homedir } from 'node:os'
|
|
31
31
|
|
|
32
32
|
/** Cordis plugin name. */
|
|
@@ -38,37 +38,152 @@ export const inject = ['tools', 'systemPrompt']
|
|
|
38
38
|
const ROUTE_PREFIX = '/api/dsh-mworks-ai'
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
41
|
+
* Where an installation may live, resolved from the environment at runtime.
|
|
42
|
+
*
|
|
43
|
+
* Nothing here is a literal machine path: a name is a product convention
|
|
44
|
+
* (`Syslab 2026b`), and every root comes from the environment — the profile's
|
|
45
|
+
* own config, a MWORKS environment variable, or the well-known Windows base
|
|
46
|
+
* directories — so the same bundle works on another machine, another drive, or
|
|
47
|
+
* another MWORKS release.
|
|
48
|
+
*/
|
|
49
|
+
const ENV_KEYS = {
|
|
50
|
+
syslab: ['MWORKS_SYSLAB_HOME', 'SYSLAB_HOME'],
|
|
51
|
+
sysplorer: ['MWORKS_SYSPLORER_HOME', 'SYSPLORER_HOME'],
|
|
52
|
+
julia: ['MWORKS_JULIA_HOME', 'SYSLAB_JULIA_HOME', 'JULIA_ROOT'],
|
|
53
|
+
workspace: ['MWORKS_WORKSPACE'],
|
|
54
|
+
home: ['MWORKS_HOME'],
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Product directory prefixes; the year/edition suffix is whatever is installed. */
|
|
58
|
+
const PRODUCT_NAMES = { syslab: 'Syslab', sysplorer: 'Sysplorer' }
|
|
59
|
+
|
|
60
|
+
/** Directory children, tolerating a missing or unreadable parent. */
|
|
61
|
+
function children(dir) {
|
|
62
|
+
try {
|
|
63
|
+
return readdirSync(dir, { withFileTypes: true })
|
|
64
|
+
.filter((entry) => entry.isDirectory())
|
|
65
|
+
.map((entry) => join(dir, entry.name))
|
|
66
|
+
} catch {
|
|
67
|
+
return []
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Every environment-named value, in precedence order. */
|
|
72
|
+
function envValues(names) {
|
|
73
|
+
return names
|
|
74
|
+
.map((key) => process.env[key])
|
|
75
|
+
.filter((value) => typeof value === 'string' && value.length > 0)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Drive roots, taken from the platform rather than assumed. */
|
|
79
|
+
function driveRoots() {
|
|
80
|
+
if (process.platform !== 'win32') return []
|
|
81
|
+
const roots = []
|
|
82
|
+
for (const letter of 'ABCDEFGHIJKLMNOPQRSTUVWXYZ') {
|
|
83
|
+
const root = `${letter}:\\`
|
|
84
|
+
if (existsSync(root)) roots.push(root)
|
|
85
|
+
}
|
|
86
|
+
return roots
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Directories to look inside for a product folder.
|
|
91
|
+
*
|
|
92
|
+
* A drive is scanned only through its `MWORKS` folder — the installer's default
|
|
93
|
+
* layout — so discovery never walks a whole disk.
|
|
94
|
+
*/
|
|
95
|
+
function productBases() {
|
|
96
|
+
const bases = new Set()
|
|
97
|
+
const add = (value) => {
|
|
98
|
+
if (typeof value === 'string' && value.length > 0) bases.add(value)
|
|
99
|
+
}
|
|
100
|
+
for (const key of ENV_KEYS.home) add(process.env[key])
|
|
101
|
+
add(process.env.ProgramFiles)
|
|
102
|
+
add(process.env['ProgramFiles(x86)'])
|
|
103
|
+
add(process.env.LOCALAPPDATA)
|
|
104
|
+
add(homedir())
|
|
105
|
+
if (process.env.ProgramFiles !== undefined) add(join(process.env.ProgramFiles, 'MWORKS'))
|
|
106
|
+
for (const drive of driveRoots()) add(join(drive, 'MWORKS'))
|
|
107
|
+
return [...bases]
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Resolve one product directory.
|
|
112
|
+
*
|
|
113
|
+
* Precedence: the profile's own config, then the product's environment
|
|
114
|
+
* variables, then a directory scan. A scan hit only counts when the product's
|
|
115
|
+
* payload is there, so a leftover folder cannot be mistaken for an install.
|
|
116
|
+
*
|
|
117
|
+
* @param kind - `syslab` or `sysplorer`.
|
|
118
|
+
* @param configured - an explicit path from the plugin's config, if any.
|
|
119
|
+
* @returns every matching directory, best first.
|
|
43
120
|
*/
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
]
|
|
52
|
-
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
]
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
121
|
+
function resolveProduct(kind, configured) {
|
|
122
|
+
const explicit = [
|
|
123
|
+
...(typeof configured === 'string' && configured.length > 0 ? [configured] : []),
|
|
124
|
+
...envValues(ENV_KEYS[kind]),
|
|
125
|
+
].filter((path) => existsSync(path))
|
|
126
|
+
|
|
127
|
+
const prefix = PRODUCT_NAMES[kind]
|
|
128
|
+
const scanned = []
|
|
129
|
+
for (const base of productBases()) {
|
|
130
|
+
for (const dir of children(base)) {
|
|
131
|
+
if (!basename(dir).startsWith(`${prefix} `)) continue
|
|
132
|
+
scanned.push(dir)
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Newest release name first, so a 2026b install wins over 2025a.
|
|
137
|
+
const ordered = [...new Set([...explicit, ...scanned.sort().reverse()])]
|
|
138
|
+
return ordered
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** Whether a directory is a Julia runtime rather than a folder that merely resembles one. */
|
|
142
|
+
function isJuliaRuntime(dir) {
|
|
143
|
+
if (!existsSync(dir)) return false
|
|
144
|
+
const executable = process.platform === 'win32' ? 'julia.exe' : 'julia'
|
|
145
|
+
return existsSync(join(dir, 'bin', executable))
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** Julia runtimes, from config, then the environment, then the usual trees. */
|
|
149
|
+
function resolveJulia(configured) {
|
|
150
|
+
const explicit = [
|
|
151
|
+
...(typeof configured === 'string' && configured.length > 0 ? [configured] : []),
|
|
152
|
+
...envValues(ENV_KEYS.julia),
|
|
153
|
+
].filter(isJuliaRuntime)
|
|
154
|
+
|
|
155
|
+
const bases = [
|
|
156
|
+
process.env.PUBLIC,
|
|
157
|
+
process.env.LOCALAPPDATA === undefined ? undefined : join(process.env.LOCALAPPDATA, 'Programs'),
|
|
158
|
+
homedir(),
|
|
159
|
+
].filter((base) => typeof base === 'string' && base.length > 0)
|
|
160
|
+
|
|
161
|
+
const scanned = []
|
|
162
|
+
for (const base of bases) {
|
|
163
|
+
// `<base>/julia-*` and `<base>/<vendor>/julia-*`: MWORKS keeps its runtime
|
|
164
|
+
// either beside the vendor folder or one level inside it.
|
|
165
|
+
for (const parent of [base, ...children(base)]) {
|
|
166
|
+
for (const dir of children(parent)) {
|
|
167
|
+
const name = basename(dir)
|
|
168
|
+
if (!name.startsWith('julia')) continue
|
|
169
|
+
if (isJuliaRuntime(dir)) scanned.push(dir)
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return [...new Set([...explicit, ...scanned.sort().reverse()])]
|
|
175
|
+
}
|
|
66
176
|
|
|
67
177
|
/** Preferred workspace for modeling output; the installation dirs stay read-only. */
|
|
68
|
-
|
|
178
|
+
function resolveWorkspace(configured) {
|
|
179
|
+
for (const value of [configured, ...envValues(ENV_KEYS.workspace)]) {
|
|
180
|
+
if (typeof value === 'string' && value.length > 0) return value
|
|
181
|
+
}
|
|
182
|
+
return join(homedir(), '.dsh-mworks-ai', 'workspace')
|
|
183
|
+
}
|
|
69
184
|
|
|
70
185
|
/**
|
|
71
|
-
*
|
|
186
|
+
* What each MCP server is, independent of where it lives.
|
|
72
187
|
*
|
|
73
188
|
* Startup parameters were verified against the installed servers:
|
|
74
189
|
* - Syslab needs `--syslab-root` (the server panics without it) and must run
|
|
@@ -78,57 +193,83 @@ const WORKSPACE = 'E:\\MWORKS'
|
|
|
78
193
|
* that exports MCP_DEPLOY_ROOT; starting the inner `main.py` breaks
|
|
79
194
|
* resources_retrieval while `tools/list` still looks healthy.
|
|
80
195
|
*/
|
|
81
|
-
const
|
|
82
|
-
{
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
'
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
196
|
+
const SERVER_META = {
|
|
197
|
+
mworks_syslab: { label: 'Syslab MCP Server', declaredTools: 8 },
|
|
198
|
+
mworks_sysplorer: { label: 'Sysplorer MCP Server', declaredTools: 15 },
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const SERVER_NAMES = Object.keys(SERVER_META)
|
|
202
|
+
|
|
203
|
+
/** Timeouts shared by both servers; a check or simulation can take minutes. */
|
|
204
|
+
function serverTimeouts() {
|
|
205
|
+
return {
|
|
206
|
+
toolCallTimeoutMs: 300000,
|
|
207
|
+
startupTimeoutMs: 60000,
|
|
208
|
+
closeTimeoutMs: 15000,
|
|
209
|
+
reconnect: { enabled: true, initialDelayMs: 500, maxDelayMs: 5000, maxAttempts: 10 },
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Build the MCP server entries from what was actually found.
|
|
215
|
+
*
|
|
216
|
+
* A product that is not installed contributes no server at all: registering a
|
|
217
|
+
* command that cannot start would only turn into a failing server in the list.
|
|
218
|
+
*
|
|
219
|
+
* @param installation - the resolved installation facts.
|
|
220
|
+
* @param workspace - the resolved working directory.
|
|
221
|
+
*/
|
|
222
|
+
function resolveServers(installation, workspace) {
|
|
223
|
+
const servers = []
|
|
224
|
+
const { syslab, sysplorer, julia } = installation
|
|
225
|
+
|
|
226
|
+
if (syslab.mcpServer !== undefined) {
|
|
227
|
+
servers.push({
|
|
228
|
+
serverName: 'mworks_syslab',
|
|
229
|
+
...SERVER_META.mworks_syslab,
|
|
230
|
+
entry: {
|
|
231
|
+
transport: 'stdio',
|
|
232
|
+
command: syslab.mcpServer,
|
|
233
|
+
args: [
|
|
234
|
+
`--syslab-root=${syslab.root}`,
|
|
235
|
+
...(julia.root === undefined ? [] : [`--julia-root=${julia.root}`]),
|
|
236
|
+
'--syslab-display-mode=nodesktop',
|
|
237
|
+
'--initialize-syslab-on-startup=false',
|
|
238
|
+
'--pkg-offline=true',
|
|
239
|
+
`--initial-working-folder=${workspace}`,
|
|
240
|
+
],
|
|
241
|
+
env: { PYTHONUTF8: '1', PYTHONIOENCODING: 'utf-8' },
|
|
242
|
+
cwd: workspace,
|
|
243
|
+
...serverTimeouts(),
|
|
244
|
+
},
|
|
245
|
+
})
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (sysplorer.mcpLauncher !== undefined && sysplorer.mcpPython !== undefined) {
|
|
249
|
+
servers.push({
|
|
250
|
+
serverName: 'mworks_sysplorer',
|
|
251
|
+
...SERVER_META.mworks_sysplorer,
|
|
252
|
+
entry: {
|
|
253
|
+
transport: 'stdio',
|
|
254
|
+
command: sysplorer.mcpPython,
|
|
255
|
+
args: [
|
|
256
|
+
sysplorer.mcpLauncher,
|
|
257
|
+
'--mworks-install-dir',
|
|
258
|
+
sysplorer.root,
|
|
259
|
+
'--sysplorer-platform-label',
|
|
260
|
+
basename(sysplorer.root),
|
|
261
|
+
'--workspace-dir',
|
|
262
|
+
workspace,
|
|
263
|
+
],
|
|
264
|
+
env: { PYTHONUTF8: '1', PYTHONIOENCODING: 'utf-8' },
|
|
265
|
+
cwd: workspace,
|
|
266
|
+
...serverTimeouts(),
|
|
267
|
+
},
|
|
268
|
+
})
|
|
269
|
+
}
|
|
130
270
|
|
|
131
|
-
|
|
271
|
+
return servers
|
|
272
|
+
}
|
|
132
273
|
|
|
133
274
|
/** Read the first existing file from a list of candidates, bounded and tolerant. */
|
|
134
275
|
function readFirstText(paths) {
|
|
@@ -165,38 +306,161 @@ function readBuildInfo(root) {
|
|
|
165
306
|
}
|
|
166
307
|
}
|
|
167
308
|
|
|
168
|
-
/**
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
309
|
+
/** Skill names MWORKS owns; everything else in a shared directory is left alone. */
|
|
310
|
+
const MWORKS_SKILL_PREFIXES = ['ty-', 'syslab-', 'ta-']
|
|
311
|
+
|
|
312
|
+
/** Whether a skill name belongs to MWORKS rather than another product. */
|
|
313
|
+
function isMworksSkillName(name) {
|
|
314
|
+
if (typeof name !== 'string' || name.length === 0) return false
|
|
315
|
+
if (name === 'modelica-library-workflow' || name === 'sysplorer-mds-docs') return true
|
|
316
|
+
return MWORKS_SKILL_PREFIXES.some((prefix) => name.startsWith(prefix))
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Read a `SKILL.md` frontmatter block.
|
|
321
|
+
*
|
|
322
|
+
* Handles the two shapes MWORKS actually ships: `key: value`, and a folded or
|
|
323
|
+
* literal block (`>-`, `|`, …) whose body is the following indented lines. A
|
|
324
|
+
* nested block such as `metadata:` is skipped, because a name and description
|
|
325
|
+
* are all the registry needs.
|
|
326
|
+
*
|
|
327
|
+
* @param text - the whole file.
|
|
328
|
+
* @returns the top-level scalar fields, or `undefined` without frontmatter.
|
|
329
|
+
*/
|
|
330
|
+
function parseSkillFrontmatter(text) {
|
|
331
|
+
const match = /^---\r?\n([\s\S]*?)\r?\n---/.exec(text)
|
|
332
|
+
if (match === null) return undefined
|
|
333
|
+
const lines = match[1].split(/\r?\n/)
|
|
334
|
+
const fields = {}
|
|
335
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
336
|
+
const line = lines[index]
|
|
337
|
+
if (line.trim().length === 0 || line.trim().startsWith('#')) continue
|
|
338
|
+
if (/^\s/.test(line)) continue
|
|
339
|
+
const colon = line.indexOf(':')
|
|
340
|
+
if (colon <= 0) continue
|
|
341
|
+
const key = line.slice(0, colon).trim()
|
|
342
|
+
let value = line.slice(colon + 1).trim()
|
|
343
|
+
if (value === '>-' || value === '>' || value === '|' || value === '|-') {
|
|
344
|
+
const folded = value.startsWith('>')
|
|
345
|
+
const collected = []
|
|
346
|
+
let next = index + 1
|
|
347
|
+
while (next < lines.length && (lines[next].trim().length === 0 || /^\s/.test(lines[next]))) {
|
|
348
|
+
collected.push(lines[next].trim())
|
|
349
|
+
next += 1
|
|
350
|
+
}
|
|
351
|
+
index = next - 1
|
|
352
|
+
fields[key] = folded
|
|
353
|
+
? collected.join(' ').replace(/\s+/g, ' ').trim()
|
|
354
|
+
: collected.join('\n').trim()
|
|
355
|
+
continue
|
|
356
|
+
}
|
|
357
|
+
if (value.length >= 2 && ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'")))) {
|
|
358
|
+
value = value.slice(1, -1)
|
|
359
|
+
}
|
|
360
|
+
fields[key] = value
|
|
180
361
|
}
|
|
362
|
+
return fields
|
|
181
363
|
}
|
|
182
364
|
|
|
183
|
-
/**
|
|
184
|
-
|
|
365
|
+
/**
|
|
366
|
+
* Directories that hold MWORKS skills, most authoritative first.
|
|
367
|
+
*
|
|
368
|
+
* The installation's own copies come first: they ship with the product and are
|
|
369
|
+
* byte-identical to what the MWORKS installers copy into an AI client's skill
|
|
370
|
+
* directory. The client directories are a fallback for an installation whose
|
|
371
|
+
* `Tools/` payload was pruned but whose skills were already installed
|
|
372
|
+
* elsewhere.
|
|
373
|
+
*/
|
|
374
|
+
function skillCandidateRoots(installation) {
|
|
185
375
|
return [
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
376
|
+
// Everything below the installation's own skill directories is MWORKS', so
|
|
377
|
+
// no name filter applies: a new bundle must not need a code change here.
|
|
378
|
+
{ path: installation.sysplorer.modelingSkillsDir, authoritative: true },
|
|
379
|
+
{ path: installation.syslab.skillsDir, authoritative: true },
|
|
380
|
+
// Shared client directories hold other products' skills too, so only names
|
|
381
|
+
// MWORKS is known to own are taken from them.
|
|
382
|
+
{ path: join(homedir(), '.config', 'opencode', 'skills'), authoritative: false },
|
|
383
|
+
{ path: join(homedir(), '.claude', 'skills'), authoritative: false },
|
|
384
|
+
].filter((root) => typeof root.path === 'string' && root.path.length > 0 && existsSync(root.path))
|
|
190
385
|
}
|
|
191
386
|
|
|
387
|
+
/**
|
|
388
|
+
* Discover the MWORKS skill bundles under an explicit list of roots.
|
|
389
|
+
*
|
|
390
|
+
* Pure with respect to the machine: the caller supplies the roots, so a test
|
|
391
|
+
* can drive it from a fixture tree instead of needing MWORKS installed.
|
|
392
|
+
*
|
|
393
|
+
* @param roots - `{ path, authoritative }` entries, most authoritative first.
|
|
394
|
+
* @returns the bundles, keyed by skill name, in root order.
|
|
395
|
+
*/
|
|
396
|
+
function discoverSkillBundlesIn(roots) {
|
|
397
|
+
const bundles = new Map()
|
|
398
|
+
|
|
399
|
+
for (const root of roots) {
|
|
400
|
+
let entries = []
|
|
401
|
+
try {
|
|
402
|
+
entries = readdirSync(root.path, { withFileTypes: true })
|
|
403
|
+
} catch {
|
|
404
|
+
continue
|
|
405
|
+
}
|
|
406
|
+
for (const entry of entries) {
|
|
407
|
+
if (!entry.isDirectory() || entry.name.startsWith('.')) continue
|
|
408
|
+
if (!root.authoritative && !isMworksSkillName(entry.name)) continue
|
|
409
|
+
if (bundles.has(entry.name)) continue
|
|
410
|
+
|
|
411
|
+
const dir = join(root.path, entry.name)
|
|
412
|
+
const file = join(dir, 'SKILL.md')
|
|
413
|
+
if (!existsSync(file)) continue
|
|
414
|
+
let text
|
|
415
|
+
try {
|
|
416
|
+
text = readFileSync(file, { encoding: 'utf8', flag: 'r' })
|
|
417
|
+
} catch {
|
|
418
|
+
continue
|
|
419
|
+
}
|
|
420
|
+
const fields = parseSkillFrontmatter(text)
|
|
421
|
+
if (fields === undefined) continue
|
|
422
|
+
const declaredName = typeof fields.name === 'string' && fields.name.length > 0 ? fields.name : entry.name
|
|
423
|
+
const description = typeof fields.description === 'string' ? fields.description.trim() : ''
|
|
424
|
+
if (description.length === 0) continue
|
|
425
|
+
// `name` must match the kebab-case grammar the registry enforces.
|
|
426
|
+
if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(declaredName)) continue
|
|
427
|
+
|
|
428
|
+
bundles.set(declaredName, {
|
|
429
|
+
name: declaredName,
|
|
430
|
+
description,
|
|
431
|
+
whenToUse: typeof fields.whenToUse === 'string' ? fields.whenToUse.trim() : undefined,
|
|
432
|
+
dir,
|
|
433
|
+
content: text.slice(text.indexOf('---', 3) + 3).replace(/^\r?\n+/, ''),
|
|
434
|
+
})
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
return [...bundles.values()]
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* Discover the MWORKS skill bundles this machine actually has.
|
|
443
|
+
*
|
|
444
|
+
* @param installation - the resolved installation facts.
|
|
445
|
+
* @returns the bundles and the roots that were scanned.
|
|
446
|
+
*/
|
|
447
|
+
function discoverSkillBundles(installation) {
|
|
448
|
+
const roots = skillCandidateRoots(installation)
|
|
449
|
+
return { bundles: discoverSkillBundlesIn(roots), roots }
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
|
|
192
453
|
/**
|
|
193
454
|
* Filesystem installation facts. Pure and synchronous: the route, the tools and
|
|
194
455
|
* the prompt all read the same value.
|
|
456
|
+
*
|
|
457
|
+
* @param config - optional explicit paths (`syslabRoot`, `sysplorerRoot`,
|
|
458
|
+
* `juliaRoot`, `workspace`); detection falls back to the environment.
|
|
195
459
|
*/
|
|
196
|
-
function detectInstallation() {
|
|
197
|
-
const syslab = pickRoot(
|
|
198
|
-
const sysplorer = pickRoot(
|
|
199
|
-
const julia = pickRoot(
|
|
460
|
+
function detectInstallation(config = {}) {
|
|
461
|
+
const syslab = pickRoot(resolveProduct('syslab', config?.syslabRoot))
|
|
462
|
+
const sysplorer = pickRoot(resolveProduct('sysplorer', config?.sysplorerRoot))
|
|
463
|
+
const julia = pickRoot(resolveJulia(config?.juliaRoot))
|
|
200
464
|
|
|
201
465
|
const syslabServer = syslab.root === undefined
|
|
202
466
|
? undefined
|
|
@@ -209,9 +473,13 @@ function detectInstallation() {
|
|
|
209
473
|
const sysplorerLauncher = sysplorer.root === undefined
|
|
210
474
|
? undefined
|
|
211
475
|
: join(sysplorer.root, 'Tools', 'sysplorer_mcp', 'main.py')
|
|
476
|
+
// The bundled interpreter is `python.exe` on Windows; the other names keep the
|
|
477
|
+
// probe honest on a POSIX host (and in tests that run off Windows).
|
|
212
478
|
const sysplorerPython = sysplorer.root === undefined
|
|
213
479
|
? undefined
|
|
214
|
-
:
|
|
480
|
+
: ['python.exe', 'python3', 'python']
|
|
481
|
+
.map((file) => join(sysplorer.root, 'External', 'python64', file))
|
|
482
|
+
.find((path) => existsSync(path))
|
|
215
483
|
|
|
216
484
|
const modelingSkills = sysplorer.root === undefined
|
|
217
485
|
? undefined
|
|
@@ -220,16 +488,6 @@ function detectInstallation() {
|
|
|
220
488
|
? undefined
|
|
221
489
|
: join(syslab.root, 'Tools', 'syslab-skills')
|
|
222
490
|
|
|
223
|
-
const detectedSkillRoots = skillRoots().map(scanSkills).filter((entry) => entry !== undefined)
|
|
224
|
-
const mworksSkills = new Set()
|
|
225
|
-
for (const entry of detectedSkillRoots) {
|
|
226
|
-
for (const skillName of entry.names) {
|
|
227
|
-
if (skillName.startsWith('ty-') || skillName.startsWith('syslab-') || skillName === 'modelica-library-workflow') {
|
|
228
|
-
mworksSkills.add(skillName)
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
491
|
return {
|
|
234
492
|
syslab: {
|
|
235
493
|
installed: syslab.root !== undefined,
|
|
@@ -255,13 +513,136 @@ function detectInstallation() {
|
|
|
255
513
|
root: julia.root,
|
|
256
514
|
otherRoots: julia.existing.slice(1),
|
|
257
515
|
},
|
|
258
|
-
skills: {
|
|
259
|
-
roots: detectedSkillRoots.map((entry) => ({ path: entry.path, count: entry.count })),
|
|
260
|
-
mworks: [...mworksSkills].sort(),
|
|
261
|
-
},
|
|
262
516
|
}
|
|
263
517
|
}
|
|
264
518
|
|
|
519
|
+
/** The skill registry, when the profile mounts one. */
|
|
520
|
+
function skillRegistryOf(ctx) {
|
|
521
|
+
try {
|
|
522
|
+
const registry = typeof ctx.get === 'function' ? ctx.get('skills') : undefined
|
|
523
|
+
return registry !== undefined && registry !== null && typeof registry.register === 'function' ? registry : undefined
|
|
524
|
+
} catch {
|
|
525
|
+
return undefined
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* Which MWORKS skills the agent can actually load right now.
|
|
531
|
+
*
|
|
532
|
+
* The registry is the authority: it merges every provider, so its answer
|
|
533
|
+
* already accounts for whatever else supplies skills in this profile (a local
|
|
534
|
+
* directory provider, or another plugin that reads some client's skill folder).
|
|
535
|
+
* The on-disk discovery is the fallback for a profile with no registry, and
|
|
536
|
+
* always supplies the root list for diagnosis.
|
|
537
|
+
*
|
|
538
|
+
* @param ctx - a context that can resolve `skills`.
|
|
539
|
+
* @param installation - the resolved installation facts.
|
|
540
|
+
*/
|
|
541
|
+
async function readSkillCatalog(ctx, installation) {
|
|
542
|
+
const { bundles, roots } = discoverSkillBundles(installation)
|
|
543
|
+
const onDisk = bundles.map((bundle) => bundle.name).sort()
|
|
544
|
+
|
|
545
|
+
const registry = skillRegistryOf(ctx)
|
|
546
|
+
if (registry === undefined || typeof registry.list !== 'function') {
|
|
547
|
+
return { source: 'filesystem', registry: false, onDisk, roots: roots.map((root) => ({ path: root.path, authoritative: root.authoritative === true })), mworks: onDisk }
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
try {
|
|
551
|
+
const all = await registry.list({})
|
|
552
|
+
const names = all
|
|
553
|
+
.map((skill) => skill.name)
|
|
554
|
+
.filter((name) => isMworksSkillName(name))
|
|
555
|
+
.sort()
|
|
556
|
+
return { source: 'registry', registry: true, onDisk, roots: roots.map((root) => ({ path: root.path, authoritative: root.authoritative === true })), mworks: names }
|
|
557
|
+
} catch {
|
|
558
|
+
return { source: 'filesystem', registry: false, onDisk, roots: roots.map((root) => ({ path: root.path, authoritative: root.authoritative === true })), mworks: onDisk }
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* Make the MWORKS skills loadable without depending on another client's folder.
|
|
564
|
+
*
|
|
565
|
+
* MWORKS installers copy the skill bundles into an AI client's skill directory
|
|
566
|
+
* (`%USERPROFILE%\\.config\\opencode\\skills` for OpenCode), and no DeepSeek
|
|
567
|
+
* Harness provider scans that path on its own — so today those skills reach the
|
|
568
|
+
* catalog only when a plugin like `@michengai/dsh-skills-manager` happens to
|
|
569
|
+
* read that directory. This plugin instead registers them from the copies that
|
|
570
|
+
* ship inside the MWORKS installation, the way a skill bundle registers its own
|
|
571
|
+
* `skills/` directory.
|
|
572
|
+
*
|
|
573
|
+
* It fills gaps by name: a skill the registry already resolves is left to the
|
|
574
|
+
* provider that supplies it, and only the missing names are registered from the
|
|
575
|
+
* installation. That keeps the plugin from duplicating an entry or from
|
|
576
|
+
* silently re-enabling a skill another provider filtered out — set
|
|
577
|
+
* `registerSkills: false` on the row to opt out of the contribution entirely.
|
|
578
|
+
*
|
|
579
|
+
* @param ctx - the plugin context.
|
|
580
|
+
* @param logger - diagnostics sink.
|
|
581
|
+
* @param options - `registerSkills` false disables the contribution.
|
|
582
|
+
*/
|
|
583
|
+
function contributeSkills(ctx, logger, options = {}) {
|
|
584
|
+
if (options.registerSkills === false) {
|
|
585
|
+
logger?.info?.('dsh-mworks-ai: skill contribution disabled by config')
|
|
586
|
+
return
|
|
587
|
+
}
|
|
588
|
+
ctx.inject(['skills'], (skillCtx) => {
|
|
589
|
+
skillCtx.effect(() => {
|
|
590
|
+
const installation = detectInstallation()
|
|
591
|
+
const { bundles } = discoverSkillBundles(installation)
|
|
592
|
+
if (bundles.length === 0) return () => {}
|
|
593
|
+
|
|
594
|
+
let cancelled = false
|
|
595
|
+
const disposers = []
|
|
596
|
+
|
|
597
|
+
void (async () => {
|
|
598
|
+
let already = []
|
|
599
|
+
try {
|
|
600
|
+
already = await skillCtx.skills.list({})
|
|
601
|
+
} catch {
|
|
602
|
+
already = []
|
|
603
|
+
}
|
|
604
|
+
if (cancelled) return
|
|
605
|
+
|
|
606
|
+
const present = new Set(already.map((skill) => skill.name))
|
|
607
|
+
const missing = bundles.filter((bundle) => !present.has(bundle.name))
|
|
608
|
+
if (missing.length === 0) {
|
|
609
|
+
logger?.info?.(`dsh-mworks-ai: all ${bundles.length} MWORKS skills already resolve from another provider`)
|
|
610
|
+
return
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
for (const bundle of missing) {
|
|
614
|
+
try {
|
|
615
|
+
disposers.push(skillCtx.skills.register({
|
|
616
|
+
name: bundle.name,
|
|
617
|
+
description: bundle.description,
|
|
618
|
+
whenToUse: bundle.whenToUse,
|
|
619
|
+
content: bundle.content,
|
|
620
|
+
resourceBase: { kind: 'directory', path: bundle.dir },
|
|
621
|
+
source: 'custom',
|
|
622
|
+
}))
|
|
623
|
+
} catch (error) {
|
|
624
|
+
logger?.warn?.(`dsh-mworks-ai: registering skill ${bundle.name} failed: ${String(error)}`)
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
if (disposers.length > 0) {
|
|
628
|
+
logger?.info?.(`dsh-mworks-ai: registered ${disposers.length} MWORKS skills from the installation (${bundles.length - missing.length} already provided)`)
|
|
629
|
+
}
|
|
630
|
+
})()
|
|
631
|
+
|
|
632
|
+
return () => {
|
|
633
|
+
cancelled = true
|
|
634
|
+
for (const dispose of disposers.splice(0)) {
|
|
635
|
+
try {
|
|
636
|
+
dispose()
|
|
637
|
+
} catch {
|
|
638
|
+
// A failed unregister during teardown must not mask the rest.
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
}, 'dsh-mworks-ai: MWORKS skills')
|
|
643
|
+
})
|
|
644
|
+
}
|
|
645
|
+
|
|
265
646
|
/** The MCP manager, when the profile mounts one. */
|
|
266
647
|
function mcpManagerOf(ctx) {
|
|
267
648
|
try {
|
|
@@ -288,10 +669,10 @@ function readMcpStatus(ctx) {
|
|
|
288
669
|
if (manager === undefined) {
|
|
289
670
|
return {
|
|
290
671
|
manager: false,
|
|
291
|
-
servers:
|
|
292
|
-
server:
|
|
293
|
-
label:
|
|
294
|
-
declaredTools:
|
|
672
|
+
servers: SERVER_NAMES.map((name) => ({
|
|
673
|
+
server: name,
|
|
674
|
+
label: SERVER_META[name].label,
|
|
675
|
+
declaredTools: SERVER_META[name].declaredTools,
|
|
295
676
|
state: 'unmanaged',
|
|
296
677
|
healthy: false,
|
|
297
678
|
detail: 'No MCP manager in this profile, so this plugin cannot report or restart the server.',
|
|
@@ -306,13 +687,13 @@ function readMcpStatus(ctx) {
|
|
|
306
687
|
views = []
|
|
307
688
|
}
|
|
308
689
|
|
|
309
|
-
const servers =
|
|
310
|
-
const view = views.find((entry) => entry.name ===
|
|
690
|
+
const servers = SERVER_NAMES.map((name) => {
|
|
691
|
+
const view = views.find((entry) => entry.name === name)
|
|
311
692
|
const status = view === undefined || view.status === undefined ? { state: 'absent' } : view.status
|
|
312
693
|
return {
|
|
313
|
-
server:
|
|
314
|
-
label:
|
|
315
|
-
declaredTools:
|
|
694
|
+
server: name,
|
|
695
|
+
label: SERVER_META[name].label,
|
|
696
|
+
declaredTools: SERVER_META[name].declaredTools,
|
|
316
697
|
state: status.state,
|
|
317
698
|
healthy: status.state === 'connected',
|
|
318
699
|
toolCount: typeof status.toolCount === 'number' ? status.toolCount : undefined,
|
|
@@ -349,15 +730,17 @@ function describeState(status) {
|
|
|
349
730
|
}
|
|
350
731
|
}
|
|
351
732
|
|
|
352
|
-
/** Full report: installation facts
|
|
353
|
-
function detectEnvironment(ctx) {
|
|
733
|
+
/** Full report: installation facts, live MCP state, and the loadable skills. */
|
|
734
|
+
async function detectEnvironment(ctx) {
|
|
354
735
|
const installation = detectInstallation()
|
|
355
736
|
const mcp = readMcpStatus(ctx)
|
|
737
|
+
const skills = await readSkillCatalog(ctx, installation)
|
|
356
738
|
return {
|
|
357
739
|
generatedAt: new Date().toISOString(),
|
|
358
740
|
platform: process.platform,
|
|
359
741
|
...installation,
|
|
360
742
|
mcp,
|
|
743
|
+
skills,
|
|
361
744
|
mcpServers: mcp.servers.map((server) => ({
|
|
362
745
|
server: server.server,
|
|
363
746
|
label: server.label,
|
|
@@ -402,10 +785,19 @@ function renderEnvironment(environment) {
|
|
|
402
785
|
lines.push(' (no MCP manager in this profile: state cannot be reported or repaired)')
|
|
403
786
|
}
|
|
404
787
|
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
if (
|
|
408
|
-
|
|
788
|
+
const skills = environment.skills
|
|
789
|
+
lines.push('', `MWORKS skills loadable in this session: ${skills.mworks.length}`)
|
|
790
|
+
if (skills.mworks.length > 0) lines.push(` ${skills.mworks.join(', ')}`)
|
|
791
|
+
if (skills.source === 'registry') {
|
|
792
|
+
lines.push(' (resolved from the skill registry, which merges every provider in this profile)')
|
|
793
|
+
} else {
|
|
794
|
+
lines.push(' (no skill registry answered: this list is what the MWORKS installation ships)')
|
|
795
|
+
}
|
|
796
|
+
if (skills.onDisk.length !== skills.mworks.length) {
|
|
797
|
+
lines.push(` on disk: ${skills.onDisk.length} MWORKS skill bundles`)
|
|
798
|
+
}
|
|
799
|
+
if (skills.roots.length > 0) {
|
|
800
|
+
lines.push(` skill roots: ${skills.roots.map((entry) => entry.path).join(', ')}`)
|
|
409
801
|
}
|
|
410
802
|
|
|
411
803
|
return lines.join('\n')
|
|
@@ -521,6 +913,61 @@ function isSameOrigin(request) {
|
|
|
521
913
|
}
|
|
522
914
|
}
|
|
523
915
|
|
|
916
|
+
/** The connection service, when the profile mounts one. */
|
|
917
|
+
function connectionOf(ctx) {
|
|
918
|
+
try {
|
|
919
|
+
const connection = typeof ctx.get === 'function' ? ctx.get('connection') : undefined
|
|
920
|
+
return connection !== undefined && connection !== null && typeof connection.requestRejection === 'function'
|
|
921
|
+
? connection
|
|
922
|
+
: undefined
|
|
923
|
+
} catch {
|
|
924
|
+
return undefined
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
/**
|
|
929
|
+
* Decide whether a request may reach the route.
|
|
930
|
+
*
|
|
931
|
+
* When the profile mounts the Host's `connection` service, that service alone
|
|
932
|
+
* decides — the same call the Host's own routes make. It is the authority on
|
|
933
|
+
* this question: it owns the Host fence (what defeats DNS rebinding), the
|
|
934
|
+
* cross-site and Origin fences, the browser credential, and the deployment's
|
|
935
|
+
* `trustedHosts` policy. Re-checking its verdict locally would be both
|
|
936
|
+
* redundant and wrong: this plugin cannot see `trustedHosts`, so a second
|
|
937
|
+
* opinion could reject traffic the deployment deliberately trusts (a Proxy that
|
|
938
|
+
* rewrites `Host`, for example).
|
|
939
|
+
*
|
|
940
|
+
* Without that service there is nothing to delegate to, so the local
|
|
941
|
+
* same-origin test runs instead as a weaker fallback. It is deliberately not
|
|
942
|
+
* the only defence even there: a browser read over plain HTTP carries neither
|
|
943
|
+
* Origin nor Fetch-Metadata, so `/restart` also requires a JSON media type.
|
|
944
|
+
*
|
|
945
|
+
* @returns true when the response is already finished and the route must stop.
|
|
946
|
+
*/
|
|
947
|
+
function refuseRequest(ctx, request, response) {
|
|
948
|
+
const connection = connectionOf(ctx)
|
|
949
|
+
if (connection !== undefined) {
|
|
950
|
+
let rejection
|
|
951
|
+
try {
|
|
952
|
+
rejection = connection.requestRejection(request)
|
|
953
|
+
} catch {
|
|
954
|
+
// A guard that fails must refuse, never fall through.
|
|
955
|
+
rejection = 403
|
|
956
|
+
}
|
|
957
|
+
if (rejection !== undefined && rejection !== null) {
|
|
958
|
+
response.writeHead(rejection, { 'cache-control': 'no-store' })
|
|
959
|
+
response.end()
|
|
960
|
+
return true
|
|
961
|
+
}
|
|
962
|
+
return false
|
|
963
|
+
}
|
|
964
|
+
if (!isSameOrigin(request)) {
|
|
965
|
+
sendJson(response, 403, { ok: false, error: 'cross-site request refused' })
|
|
966
|
+
return true
|
|
967
|
+
}
|
|
968
|
+
return false
|
|
969
|
+
}
|
|
970
|
+
|
|
524
971
|
/** Read a bounded JSON body. */
|
|
525
972
|
async function readJsonBody(request, limit = 8192) {
|
|
526
973
|
return await new Promise((resolve, reject) => {
|
|
@@ -560,13 +1007,36 @@ export function apply(ctx, config) {
|
|
|
560
1007
|
void config
|
|
561
1008
|
const logger = ctx.logger
|
|
562
1009
|
|
|
1010
|
+
// -------------------------------------------------------------------- skills
|
|
1011
|
+
// Register the MWORKS skill bundles from the installation's own copies, so a
|
|
1012
|
+
// session does not depend on another AI client's skill folder.
|
|
1013
|
+
contributeSkills(ctx, logger, { registerSkills: config?.registerSkills !== false })
|
|
1014
|
+
|
|
563
1015
|
// ------------------------------------------------------------------ MCP servers
|
|
564
1016
|
// Contributed through the manager so their state is observable and one of
|
|
565
1017
|
// them can be rebuilt in place. Without a manager the tools below still load
|
|
566
1018
|
// and say so, instead of failing the whole plugin.
|
|
1019
|
+
//
|
|
1020
|
+
// The entries are resolved here, not at module scope: their command, args and
|
|
1021
|
+
// working directory all come from what this machine has installed.
|
|
1022
|
+
const installation = detectInstallation(config)
|
|
1023
|
+
const workspace = resolveWorkspace(config?.workspace)
|
|
1024
|
+
const servers = resolveServers(installation, workspace)
|
|
1025
|
+
if (servers.length < SERVER_NAMES.length) {
|
|
1026
|
+
const missing = SERVER_NAMES.filter((name) => !servers.some((server) => server.serverName === name))
|
|
1027
|
+
logger?.info?.(`dsh-mworks-ai: no MCP server for ${missing.join(', ')}; the product is not installed or not found`)
|
|
1028
|
+
}
|
|
1029
|
+
if (servers.length > 0) {
|
|
1030
|
+
try {
|
|
1031
|
+
mkdirSync(workspace, { recursive: true })
|
|
1032
|
+
} catch (error) {
|
|
1033
|
+
logger?.warn?.(`dsh-mworks-ai: could not create the workspace ${workspace}: ${String(error)}`)
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
|
|
567
1037
|
ctx.inject(['mcpManager'], (mcpCtx) => {
|
|
568
1038
|
const manager = mcpCtx.mcpManager
|
|
569
|
-
for (const server of
|
|
1039
|
+
for (const server of servers) {
|
|
570
1040
|
mcpCtx.effect(() => {
|
|
571
1041
|
try {
|
|
572
1042
|
const dispose = manager.register(server.serverName, { ...server.entry })
|
|
@@ -599,7 +1069,7 @@ export function apply(ctx, config) {
|
|
|
599
1069
|
render: (_args, value) => [{ type: 'text', text: renderEnvironment(value) }],
|
|
600
1070
|
},
|
|
601
1071
|
async execute() {
|
|
602
|
-
return compact(detectEnvironment(ctx))
|
|
1072
|
+
return compact(await detectEnvironment(ctx))
|
|
603
1073
|
},
|
|
604
1074
|
}), 'dsh-mworks-ai: mworks_environment tool')
|
|
605
1075
|
|
|
@@ -676,18 +1146,15 @@ export function apply(ctx, config) {
|
|
|
676
1146
|
serverCtx.effect(() => serverCtx.webServer.register({
|
|
677
1147
|
kind: 'exact',
|
|
678
1148
|
path: `${ROUTE_PREFIX}/environment`,
|
|
679
|
-
handler: (request, response) => {
|
|
1149
|
+
handler: async (request, response) => {
|
|
1150
|
+
if (refuseRequest(ctx, request, response)) return
|
|
680
1151
|
if (request.method !== 'GET' && request.method !== 'HEAD') {
|
|
681
1152
|
response.writeHead(405, { allow: 'GET, HEAD' })
|
|
682
1153
|
response.end()
|
|
683
1154
|
return
|
|
684
1155
|
}
|
|
685
|
-
if (!isSameOrigin(request)) {
|
|
686
|
-
sendJson(response, 403, { ok: false, error: 'cross-site request refused' })
|
|
687
|
-
return
|
|
688
|
-
}
|
|
689
1156
|
try {
|
|
690
|
-
sendJson(response, 200, detectEnvironment(ctx))
|
|
1157
|
+
sendJson(response, 200, await detectEnvironment(ctx))
|
|
691
1158
|
} catch (error) {
|
|
692
1159
|
logger?.warn?.(`dsh-mworks-ai: environment route failed: ${String(error)}`)
|
|
693
1160
|
sendJson(response, 500, { ok: false, error: String(error) })
|
|
@@ -699,13 +1166,17 @@ export function apply(ctx, config) {
|
|
|
699
1166
|
kind: 'exact',
|
|
700
1167
|
path: `${ROUTE_PREFIX}/restart`,
|
|
701
1168
|
handler: async (request, response) => {
|
|
1169
|
+
if (refuseRequest(ctx, request, response)) return
|
|
702
1170
|
if (request.method !== 'POST') {
|
|
703
1171
|
response.writeHead(405, { allow: 'POST' })
|
|
704
1172
|
response.end()
|
|
705
1173
|
return
|
|
706
1174
|
}
|
|
707
|
-
|
|
708
|
-
|
|
1175
|
+
// A cross-site "simple request" can carry text/plain without a preflight,
|
|
1176
|
+
// so the media type is part of the gate rather than a nicety.
|
|
1177
|
+
const mediaType = String(request.headers?.['content-type'] ?? '').split(';')[0].trim().toLowerCase()
|
|
1178
|
+
if (mediaType !== 'application/json') {
|
|
1179
|
+
sendJson(response, 415, { ok: false, error: 'expected application/json' })
|
|
709
1180
|
return
|
|
710
1181
|
}
|
|
711
1182
|
let body
|
|
@@ -740,4 +1211,15 @@ export function apply(ctx, config) {
|
|
|
740
1211
|
logger?.info?.('dsh-mworks-ai: MWORKS AI host half active')
|
|
741
1212
|
}
|
|
742
1213
|
|
|
743
|
-
export {
|
|
1214
|
+
export {
|
|
1215
|
+
detectInstallation,
|
|
1216
|
+
detectEnvironment,
|
|
1217
|
+
readMcpStatus,
|
|
1218
|
+
discoverSkillBundles,
|
|
1219
|
+
discoverSkillBundlesIn,
|
|
1220
|
+
isMworksSkillName,
|
|
1221
|
+
resolveServers,
|
|
1222
|
+
resolveWorkspace,
|
|
1223
|
+
SERVER_META,
|
|
1224
|
+
SERVER_NAMES,
|
|
1225
|
+
}
|
package/locale/en.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "MWORKS AI",
|
|
4
|
-
"description": "Brings MWORKS into DeepSeek Harness the way the official Syslab AI and Sysplorer AI assistants do. It contributes the two official MCP servers (mcp__mworks_syslab__* for Julia execution, environment detection, help search and MATLAB-to-Julia mapping; mcp__mworks_sysplorer__* for Modelica modeling, checking, translation, simulation, results and library documentation) through the Host MCP manager, so their connection state is visible and either one can be rebuilt in place without restarting DeepSeek Harness. It also adds the official MWORKS working rules to the agent instructions, plus the recovery rule: when a MWORKS call stops answering, check the state and reconnect the server instead of retrying, which only burns another timeout. On this bundle page a Runtime environment section reports the detected Syslab and Sysplorer installations and versions, the Julia runtime, the live state of both MCP servers with a Reconnect control for one that is not connected, and the MWORKS skills this session can call. Nothing is added to the conversation. Servers start on stdio from the installed products, so Syslab must be present for the Julia tools and Sysplorer for the Modelica tools; a profile without the MCP manager gets no MWORKS MCP tools and a report saying so. The plugin only reads installation paths and version files and writes nothing into the MWORKS directories. Tool calls can run for minutes, so they use a five-minute timeout. Turning it off removes both MCP servers, the tools, the instructions and the section.",
|
|
4
|
+
"description": "Brings MWORKS into DeepSeek Harness the way the official Syslab AI and Sysplorer AI assistants do. It contributes the two official MCP servers (mcp__mworks_syslab__* for Julia execution, environment detection, help search and MATLAB-to-Julia mapping; mcp__mworks_sysplorer__* for Modelica modeling, checking, translation, simulation, results and library documentation) through the Host MCP manager, so their connection state is visible and either one can be rebuilt in place without restarting DeepSeek Harness. It also adds the official MWORKS working rules to the agent instructions, plus the recovery rule: when a MWORKS call stops answering, check the state and reconnect the server instead of retrying, which only burns another timeout. On this bundle page a Runtime environment section reports the detected Syslab and Sysplorer installations and versions, the Julia runtime, the live state of both MCP servers with a Reconnect control for one that is not connected, and the MWORKS skills this session can call. Nothing is added to the conversation. Servers start on stdio from the installed products, so Syslab must be present for the Julia tools and Sysplorer for the Modelica tools; a profile without the MCP manager gets no MWORKS MCP tools and a report saying so. The plugin only reads installation paths and version files and writes nothing into the MWORKS directories. Tool calls can run for minutes, so they use a five-minute timeout. Turning it off removes both MCP servers, the tools, the instructions and the section. It also registers the MWORKS skill bundles into the session from the copies that ship inside the MWORKS installation, so those skills load whether or not another AI client (such as OpenCode) is installed; when the skill registry already resolves them from somewhere the user configured, the plugin registers nothing and leaves that choice alone.",
|
|
5
5
|
"detail": "docs/DETAIL.md"
|
|
6
6
|
}
|
|
7
7
|
}
|
package/locale/zh.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "MWORKS AI",
|
|
4
|
-
"description": "按官方 Syslab AI / Sysplorer AI 的方式把 MWORKS 接入 DeepSeek Harness。两个官方 MCP 服务(mcp__mworks_syslab__* 提供 Julia 执行、环境检测、帮助检索与 MATLAB 转 Julia 映射;mcp__mworks_sysplorer__* 提供 Modelica 建模、检查、翻译、仿真、结果读取与库文档)通过宿主 MCP 管理器托管,因此连接状态可见,并且单个服务可以就地重建而无需重启 DeepSeek Harness。插件同时把官方 MWORKS 工作规则加入智能体指令,其中包括故障处置规则:MWORKS 调用不再响应时,应查看状态并重连该服务,而不是重试——重试只会再烧掉一个完整超时。本插件页的「运行环境」一节显示检测到的 Syslab / Sysplorer 安装与版本、Julia 运行时、两个 MCP 服务的实时状态(未连接时可点「重新连接」),以及本会话可调用的 MWORKS 技能。插件不向对话界面添加任何内容。服务以 stdio 方式从已安装产品启动,因此 Julia 类工具依赖本机 Syslab,Modelica 类工具依赖本机 Sysplorer;若 profile 未挂载 MCP 管理器,则没有 MWORKS MCP 工具,报告也会如实说明。插件只读取安装路径与版本文件,不向 MWORKS 安装目录写入任何内容。模型检查、翻译、仿真等调用可能持续数分钟,因此工具超时设为 5 分钟。关闭插件会同时移除两个 MCP
|
|
4
|
+
"description": "按官方 Syslab AI / Sysplorer AI 的方式把 MWORKS 接入 DeepSeek Harness。两个官方 MCP 服务(mcp__mworks_syslab__* 提供 Julia 执行、环境检测、帮助检索与 MATLAB 转 Julia 映射;mcp__mworks_sysplorer__* 提供 Modelica 建模、检查、翻译、仿真、结果读取与库文档)通过宿主 MCP 管理器托管,因此连接状态可见,并且单个服务可以就地重建而无需重启 DeepSeek Harness。插件同时把官方 MWORKS 工作规则加入智能体指令,其中包括故障处置规则:MWORKS 调用不再响应时,应查看状态并重连该服务,而不是重试——重试只会再烧掉一个完整超时。本插件页的「运行环境」一节显示检测到的 Syslab / Sysplorer 安装与版本、Julia 运行时、两个 MCP 服务的实时状态(未连接时可点「重新连接」),以及本会话可调用的 MWORKS 技能。插件不向对话界面添加任何内容。服务以 stdio 方式从已安装产品启动,因此 Julia 类工具依赖本机 Syslab,Modelica 类工具依赖本机 Sysplorer;若 profile 未挂载 MCP 管理器,则没有 MWORKS MCP 工具,报告也会如实说明。插件只读取安装路径与版本文件,不向 MWORKS 安装目录写入任何内容。模型检查、翻译、仿真等调用可能持续数分钟,因此工具超时设为 5 分钟。关闭插件会同时移除两个 MCP 服务、工具、指令与这一节。插件还会把 MWORKS 技能从安装目录里的副本注册进本会话,因此无论是否安装了其它 AI 客户端(如 OpenCode),这些技能都能加载;若技能注册表已经能通过用户自己配置的来源解析到它们,插件不注册任何东西,也不改变那一选择。",
|
|
5
5
|
"detail": "docs/DETAIL.zh.md"
|
|
6
6
|
}
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-mworks-ai",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "MWORKS AI for DeepSeek Harness: Syslab and Sysplorer MCP servers owned by the MCP manager (live state plus in-place reconnect), official MWORKS skills and working rules, and a Runtime environment section on the plugin page.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -18,11 +18,12 @@
|
|
|
18
18
|
"locale/*.json",
|
|
19
19
|
"docs",
|
|
20
20
|
"icon.svg",
|
|
21
|
+
"icon.png",
|
|
21
22
|
"README.md",
|
|
22
23
|
"LICENSE"
|
|
23
24
|
],
|
|
24
25
|
"engines": {
|
|
25
|
-
|
|
26
|
+
"dsh": ">=0.2.1-rc.1 <0.3.0-0"
|
|
26
27
|
},
|
|
27
28
|
"scripts": {
|
|
28
29
|
"test": "node test/render-check.mjs && node test/class-check.mjs && node test/metadata-check.mjs && node test/host-check.mjs"
|