@qmingjun/dsh-eda-mcp 0.0.0-stage → 1.1.12
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/AGENTS.md +63 -0
- package/CHANGELOG.md +792 -0
- package/CONTRIBUTING.md +154 -0
- package/LICENSE +55 -0
- package/README.md +290 -2
- package/README.zh.md +449 -0
- package/cordis.patch.yml +7 -0
- package/docs/design-rules.md +254 -0
- package/docs/dsh-version-sweep.md +73 -0
- package/docs/pitfalls.md +99 -0
- package/docs/project-status.md +100 -0
- package/docs/release.md +215 -0
- package/docs/schematic-workflow.md +297 -0
- package/docs/tools.md +184 -0
- package/jlc-extension/api-bridge.js +879 -0
- package/jlc-extension/extension.json +104 -0
- package/lib/bridge.mjs +4179 -0
- package/lib/client.js +1605 -0
- package/lib/extension-digest.json +6 -0
- package/lib/index.js +1261 -0
- package/package.json +144 -4
- package/src/bridge/design-intake.ts +133 -0
- package/src/bridge/design-rules.ts +228 -0
- package/src/bridge/eda-launch.ts +267 -0
- package/src/bridge/extension-package.ts +35 -0
- package/src/bridge/index.ts +3576 -0
- package/src/bridge/netlist-erc.ts +305 -0
- package/src/bridge/schematic-audit.ts +131 -0
- package/src/bridge/workflow-guide.ts +65 -0
- package/src/bridge-diagnostics.ts +185 -0
- package/src/client/EdaMcpSettingsCard.tsx +571 -0
- package/src/client/index.ts +40 -0
- package/src/client/locales.ts +83 -0
- package/src/client/settings-scope.ts +160 -0
- package/src/config-values.ts +60 -0
- package/src/guidance.ts +35 -0
- package/src/index.ts +365 -0
- package/src/loopback.ts +48 -0
- package/src/node-runtime.ts +120 -0
- package/src/routes.ts +377 -0
- package/src/skills-content.ts +309 -0
- package/src/skills.ts +91 -0
- package/test/config-values.test.ts +60 -0
- package/test/design-intake.test.ts +40 -0
- package/test/design-rules.test.ts +72 -0
- package/test/eda-launch.test.ts +114 -0
- package/test/extension-package.test.ts +27 -0
- package/test/extension-routes.test.ts +116 -0
- package/test/netlist-erc.test.ts +90 -0
- package/test/node-runtime.test.ts +65 -0
- package/test/schematic-audit.test.ts +71 -0
- package/test/seams.test.ts +164 -0
- package/test/skills.test.ts +68 -0
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Launching JLCEDA Pro (EasyEDA Pro) from a tool call.
|
|
3
|
+
*
|
|
4
|
+
* Nothing here is machine-specific: the executable is resolved from an explicit
|
|
5
|
+
* override, an environment variable, the registry entry the installer creates, a
|
|
6
|
+
* list of conventional install directories, and finally PATH. Every step is
|
|
7
|
+
* skipped when its inputs are absent.
|
|
8
|
+
*
|
|
9
|
+
* String operations only (no regex literals): the discovery rules stay readable
|
|
10
|
+
* and the resolution order is unit-tested without spawning anything.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export type Platform = 'win32' | 'darwin' | 'linux' | (string & {})
|
|
14
|
+
|
|
15
|
+
/** Everything the resolver needs from the outside world. */
|
|
16
|
+
export interface LaunchProbe {
|
|
17
|
+
platform: Platform
|
|
18
|
+
env: Record<string, string | undefined>
|
|
19
|
+
exists: (path: string) => boolean
|
|
20
|
+
/** Raw stdout of the registry query, or undefined when the key does not exist. */
|
|
21
|
+
registryQuery: (key: string, valueName?: string) => string | undefined
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface ResolveOptions {
|
|
25
|
+
executable?: string
|
|
26
|
+
project?: string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type ExecutableSource = 'config' | 'env' | 'registry' | 'install-dir' | 'path'
|
|
30
|
+
|
|
31
|
+
export interface ResolvedLaunch {
|
|
32
|
+
executable: string
|
|
33
|
+
source: ExecutableSource
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const EXECUTABLE_ENV_KEYS = ['DSH_EDA_EXECUTABLE', 'JLCEDA_EXECUTABLE'] as const
|
|
37
|
+
export const EXECUTABLE_NAMES = ['lceda-pro.exe', 'lceda-pro', 'LCEDA Pro'] as const
|
|
38
|
+
export const PROJECT_EXTENSIONS = ['.eprj2', '.eprj'] as const
|
|
39
|
+
|
|
40
|
+
const CN_PRO_EDITION = '嘉立创EDA专业版'
|
|
41
|
+
const CLASSES = 'Software\\Classes'
|
|
42
|
+
|
|
43
|
+
export const INSTALL_SUFFIXES = [
|
|
44
|
+
'lceda-pro',
|
|
45
|
+
'Program Files\\lceda-pro',
|
|
46
|
+
'Program Files (x86)\\lceda-pro',
|
|
47
|
+
'Program Files\\' + CN_PRO_EDITION,
|
|
48
|
+
'Program Files (x86)\\' + CN_PRO_EDITION,
|
|
49
|
+
] as const
|
|
50
|
+
|
|
51
|
+
/** Strip trailing path separators from a directory. */
|
|
52
|
+
function trimSeparator(value: string): string {
|
|
53
|
+
let end = value.length
|
|
54
|
+
while (end > 0) {
|
|
55
|
+
const ch = value[end - 1]
|
|
56
|
+
if (ch !== '\\' && ch !== '/') break
|
|
57
|
+
end -= 1
|
|
58
|
+
}
|
|
59
|
+
return value.slice(0, end)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Strip leading path separators. */
|
|
63
|
+
function trimLeadingSeparators(value: string): string {
|
|
64
|
+
let start = 0
|
|
65
|
+
while (start < value.length && (value[start] === '\\' || value[start] === '/')) start += 1
|
|
66
|
+
return value.slice(start)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function joinPath(platform: Platform, ...parts: string[]): string {
|
|
70
|
+
const separator = platform === 'win32' ? '\\' : '/'
|
|
71
|
+
return parts
|
|
72
|
+
.filter(part => part !== '')
|
|
73
|
+
.map((part, index) => (index === 0 ? part : trimLeadingSeparators(part)))
|
|
74
|
+
.join(separator)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Split an install suffix into path segments, on either separator. */
|
|
78
|
+
function splitSegments(value: string): string[] {
|
|
79
|
+
return value.split('\\').join('/').split('/').filter(part => part !== '')
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Pull the executable out of a registered open command such as
|
|
84
|
+
* `"D:\\lceda-pro\\lceda-pro.exe" "%1"` or `C:\\App\\lceda-pro.exe %1`.
|
|
85
|
+
*/
|
|
86
|
+
export function parseExecutableFromCommand(command: string | undefined): string | undefined {
|
|
87
|
+
const text = (command ?? '').trim()
|
|
88
|
+
if (text === '') return undefined
|
|
89
|
+
if (text.startsWith('"')) {
|
|
90
|
+
const end = text.indexOf('"', 1)
|
|
91
|
+
if (end === -1) return undefined
|
|
92
|
+
const quoted = text.slice(1, end).trim()
|
|
93
|
+
return quoted === '' ? undefined : quoted
|
|
94
|
+
}
|
|
95
|
+
const space = text.indexOf(' ')
|
|
96
|
+
const tab = text.indexOf(String.fromCharCode(9))
|
|
97
|
+
const stops = [space, tab].filter(index => index > 0)
|
|
98
|
+
const end = stops.length === 0 ? text.length : Math.min(...stops)
|
|
99
|
+
const first = text.slice(0, end).trim()
|
|
100
|
+
return first === '' ? undefined : first
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Decode `reg` output. The tool writes in the console code page (GBK on a Chinese
|
|
105
|
+
* Windows), and progid names are non-ASCII, so a UTF-8 decode can produce
|
|
106
|
+
* replacement characters that no longer match a registry key. When that happens,
|
|
107
|
+
* decode again as GBK (both decoders ship with the Node the host provides).
|
|
108
|
+
*/
|
|
109
|
+
export function decodeRegistryOutput(raw: Uint8Array): string {
|
|
110
|
+
const utf8 = new TextDecoder('utf-8').decode(raw)
|
|
111
|
+
if (!utf8.includes(String.fromCharCode(0xFFFD))) return utf8
|
|
112
|
+
try {
|
|
113
|
+
return new TextDecoder('gbk').decode(raw)
|
|
114
|
+
} catch {
|
|
115
|
+
return utf8
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Take the string payload of a registry line (`... REG_SZ <value>`). */
|
|
120
|
+
export function parseRegStringValue(output: string | undefined): string | undefined {
|
|
121
|
+
for (const raw of (output ?? '').split(String.fromCharCode(10))) {
|
|
122
|
+
const line = raw.trim()
|
|
123
|
+
const index = line.toUpperCase().indexOf('REG_SZ')
|
|
124
|
+
if (index === -1) continue
|
|
125
|
+
const value = line.slice(index + 'REG_SZ'.length).trim()
|
|
126
|
+
// `reg query` prints "(value not set)" for an unset default; it is not a value.
|
|
127
|
+
if (value === '' || value.startsWith('(')) continue
|
|
128
|
+
return value
|
|
129
|
+
}
|
|
130
|
+
return undefined
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** Value names of a registry listing (the first column of every value line). */
|
|
134
|
+
export function parseRegValueNames(output: string | undefined): string[] {
|
|
135
|
+
const names: string[] = []
|
|
136
|
+
for (const raw of (output ?? '').split(String.fromCharCode(10))) {
|
|
137
|
+
const line = raw.trim()
|
|
138
|
+
const marker = line.indexOf('REG_')
|
|
139
|
+
if (marker <= 0) continue
|
|
140
|
+
const name = line.slice(0, marker).trim()
|
|
141
|
+
if (name !== '' && !name.startsWith('HKEY')) names.push(name)
|
|
142
|
+
}
|
|
143
|
+
return names
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function firstExisting(probe: LaunchProbe, candidates: string[]): string | undefined {
|
|
147
|
+
for (const candidate of candidates) {
|
|
148
|
+
if (candidate !== '' && probe.exists(candidate)) return candidate
|
|
149
|
+
}
|
|
150
|
+
return undefined
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** Candidate executables derived from environment variables (no registry access). */
|
|
154
|
+
export function envCandidates(probe: LaunchProbe): string[] {
|
|
155
|
+
const env = probe.env
|
|
156
|
+
const roots = [
|
|
157
|
+
env.ProgramFiles,
|
|
158
|
+
env['ProgramFiles(x86)'],
|
|
159
|
+
env.LOCALAPPDATA === undefined ? undefined : joinPath(probe.platform, env.LOCALAPPDATA, 'Programs'),
|
|
160
|
+
env.APPDATA === undefined ? undefined : joinPath(probe.platform, env.APPDATA, 'Programs'),
|
|
161
|
+
env.SystemDrive,
|
|
162
|
+
env.USERPROFILE,
|
|
163
|
+
env.HOME,
|
|
164
|
+
].filter((root): root is string => typeof root === 'string' && root !== '')
|
|
165
|
+
|
|
166
|
+
const candidates: string[] = []
|
|
167
|
+
for (const root of roots) {
|
|
168
|
+
for (const suffix of INSTALL_SUFFIXES) {
|
|
169
|
+
for (const name of EXECUTABLE_NAMES) {
|
|
170
|
+
candidates.push(joinPath(probe.platform, trimSeparator(root), ...splitSegments(suffix), name))
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return candidates
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** Look for the executable in the directories listed on PATH. */
|
|
178
|
+
export function pathCandidates(probe: LaunchProbe): string[] {
|
|
179
|
+
const raw = probe.env.PATH ?? probe.env.Path ?? ''
|
|
180
|
+
const separator = probe.platform === 'win32' ? ';' : ':'
|
|
181
|
+
return raw
|
|
182
|
+
.split(separator)
|
|
183
|
+
.filter(dir => dir.trim() !== '')
|
|
184
|
+
.flatMap(dir => EXECUTABLE_NAMES.map(name => joinPath(probe.platform, trimSeparator(dir), name)))
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Ask the registry where the installer registered the project handler.
|
|
189
|
+
*
|
|
190
|
+
* The extension's default progid is often empty while `OpenWithProgids` lists the
|
|
191
|
+
* real one, so both are consulted. HKCU wins over HKLM; HKCR is skipped because
|
|
192
|
+
* it merges the two.
|
|
193
|
+
*/
|
|
194
|
+
export function registryCandidates(probe: LaunchProbe): string[] {
|
|
195
|
+
if (probe.platform !== 'win32') return []
|
|
196
|
+
const found: string[] = []
|
|
197
|
+
for (const hive of ['HKCU', 'HKLM']) {
|
|
198
|
+
for (const extension of PROJECT_EXTENSIONS) {
|
|
199
|
+
const base = hive + '\\' + CLASSES + '\\' + extension
|
|
200
|
+
const defaults = [parseRegStringValue(probe.registryQuery(base, '')), parseRegStringValue(probe.registryQuery(base))]
|
|
201
|
+
const progids = [
|
|
202
|
+
...defaults.filter((value): value is string => value !== undefined),
|
|
203
|
+
...parseRegValueNames(probe.registryQuery(base + '\\OpenWithProgids')),
|
|
204
|
+
]
|
|
205
|
+
for (const progid of progids) {
|
|
206
|
+
if (progid.startsWith('Applications' + '\\')) continue
|
|
207
|
+
const command = parseRegStringValue(
|
|
208
|
+
probe.registryQuery(hive + '\\' + CLASSES + '\\' + progid + '\\shell\\open\\command'),
|
|
209
|
+
)
|
|
210
|
+
const executable = parseExecutableFromCommand(command)
|
|
211
|
+
if (executable !== undefined) found.push(executable)
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return found
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** Resolve the executable, or undefined when nothing on this machine matches. */
|
|
219
|
+
export function resolveExecutable(probe: LaunchProbe, options: ResolveOptions = {}): ResolvedLaunch | undefined {
|
|
220
|
+
const override = options.executable?.trim()
|
|
221
|
+
if (override !== undefined && override !== '' && probe.exists(override)) {
|
|
222
|
+
return { executable: override, source: 'config' }
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
for (const key of EXECUTABLE_ENV_KEYS) {
|
|
226
|
+
const value = probe.env[key]?.trim()
|
|
227
|
+
if (value !== undefined && value !== '' && probe.exists(value)) return { executable: value, source: 'env' }
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const fromRegistry = firstExisting(probe, registryCandidates(probe))
|
|
231
|
+
if (fromRegistry !== undefined) return { executable: fromRegistry, source: 'registry' }
|
|
232
|
+
|
|
233
|
+
const fromInstallDir = firstExisting(probe, envCandidates(probe))
|
|
234
|
+
if (fromInstallDir !== undefined) return { executable: fromInstallDir, source: 'install-dir' }
|
|
235
|
+
|
|
236
|
+
const fromPath = firstExisting(probe, pathCandidates(probe))
|
|
237
|
+
if (fromPath !== undefined) return { executable: fromPath, source: 'path' }
|
|
238
|
+
|
|
239
|
+
return undefined
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** Arguments used to open the app (and optionally a project) on each platform. */
|
|
243
|
+
export function buildLaunchArgs(platform: Platform, executable: string, project?: string): { command: string; args: string[] } {
|
|
244
|
+
const target = project?.trim()
|
|
245
|
+
const hasProject = target !== undefined && target !== ''
|
|
246
|
+
if (platform === 'darwin') {
|
|
247
|
+
return hasProject
|
|
248
|
+
? { command: 'open', args: ['-a', executable, target as string] }
|
|
249
|
+
: { command: 'open', args: ['-a', executable] }
|
|
250
|
+
}
|
|
251
|
+
return hasProject ? { command: executable, args: [target as string] } : { command: executable, args: [] }
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Windows script used to hand the launch to the running Explorer shell.
|
|
256
|
+
*
|
|
257
|
+
* Spawning `lceda-pro.exe` directly from a host process (or even through
|
|
258
|
+
* `Start-Process`) makes it start and exit immediately, while double-clicking the
|
|
259
|
+
* same executable works. Explorer runs in the interactive desktop, so executing a
|
|
260
|
+
* script through it reproduces the double-click context; the script then starts the
|
|
261
|
+
* app with the optional project argument.
|
|
262
|
+
*/
|
|
263
|
+
export function buildLaunchScript(executable: string, project?: string): string {
|
|
264
|
+
const target = project?.trim()
|
|
265
|
+
const args = target === undefined || target === '' ? '' : ' "' + target + '"'
|
|
266
|
+
return ['@echo off', 'start "" "' + executable + '"' + args, ''].join(String.fromCharCode(13, 10))
|
|
267
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extension zip packaging helpers: the plugin ships
|
|
3
|
+
* `dsh-eda-bridge-extension-<wire version>.zip`, the download server publishes the same
|
|
4
|
+
* file, and a user who installs the plugin from npm must be able to tell whether the copy
|
|
5
|
+
* they got is byte-identical to the one the bridge expects.
|
|
6
|
+
*/
|
|
7
|
+
import { createHash } from 'node:crypto'
|
|
8
|
+
|
|
9
|
+
export function sha256Of(bytes: Uint8Array): string {
|
|
10
|
+
return createHash('sha256').update(bytes).digest('hex')
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function extensionZipName(version: string): string {
|
|
14
|
+
return 'dsh-eda-bridge-extension-' + version + '.zip'
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Normalises a base URL ('…/eda' or '…/eda/') and appends the zip name. */
|
|
18
|
+
export function extensionDownloadUrl(base: string, version: string): string {
|
|
19
|
+
const normalised = base.endsWith('/') ? base : base + '/'
|
|
20
|
+
return new URL(extensionZipName(version), normalised).toString()
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type DigestVerdict = 'match' | 'mismatch' | 'unverified'
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* A missing expected digest is reported as 'unverified', never as a pass: an absent
|
|
27
|
+
* comparison is not evidence of equality.
|
|
28
|
+
*/
|
|
29
|
+
export function compareDigest(expected: string | null | undefined, actual: string | null | undefined): DigestVerdict {
|
|
30
|
+
if (typeof expected !== 'string' || typeof actual !== 'string') return 'unverified'
|
|
31
|
+
const left = expected.trim().toLowerCase()
|
|
32
|
+
const right = actual.trim().toLowerCase()
|
|
33
|
+
if (left === '' || right === '') return 'unverified'
|
|
34
|
+
return left === right ? 'match' : 'mismatch'
|
|
35
|
+
}
|