lceda-connect 0.2.0 → 0.4.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 +28 -0
- package/README.md +111 -45
- package/dist/{analyze-DBkWgG82.mjs → analyze-TRlZx-Jv.mjs} +2 -190
- package/dist/{cli-B3GGyoP_.mjs → cli-1_urvve3.mjs} +5 -3
- package/dist/{cli-BegYbK44.mjs → cli-C8-HjAP0.mjs} +2 -2
- package/dist/cli-CHbcaMwS.mjs +1 -0
- package/dist/cli-CXk5pvVm.mjs +1253 -0
- package/dist/cli-CZEoeuFW.mjs +1 -0
- package/dist/{cli-DphIx1EQ.mjs → cli-CZmNLW3Q.mjs} +1 -1
- package/dist/{cli-BekOvZjB.mjs → cli-DFqBHofJ.mjs} +19 -3
- package/dist/cli-bridge-server.mjs +1 -1
- package/dist/cli-bridge.mjs +1 -1
- package/dist/cli-cdp.mjs +1 -1
- package/dist/cli-mcp.mjs +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/config-BKbwyvsG.mjs +516 -0
- package/dist/{discover-D4ouuCrn.mjs → discover-DmRYlAlR.mjs} +13 -90
- package/dist/environment-BegP0n2N.mjs +439 -0
- package/dist/environment-Clx1-nDW.mjs +146 -0
- package/dist/http-Cdp6S2rm.mjs +366 -0
- package/dist/http-D7sYy2y4.mjs +1 -0
- package/dist/index.d.mts +226 -6
- package/dist/index.mjs +12 -9
- package/dist/{main-CzMqMptH.mjs → main-B3aaKvqY.mjs} +695 -90
- package/dist/mcpHost-CRoN6MnG.mjs +331 -0
- package/dist/{registry-DaqVJuvF.mjs → registry-3WTFCZsR.mjs} +86 -25
- package/dist/registry-DdJ8LEdd.mjs +1 -0
- package/dist/{server-qYlcXfzp.mjs → server-zw6t1Pmk.mjs} +10 -15
- package/dist/{targets-DYfgkrq3.mjs → session-AQbRX6Ys.mjs} +3 -37
- package/dist/{sideEffects-D33hMchc.mjs → sideEffects-Ds_T-_B4.mjs} +3 -2
- package/dist/stdio-BZPlcfDR.mjs +27 -0
- package/dist/stdio-Du1oLqfJ.mjs +1 -0
- package/dist/targets-8LBEgvbq.mjs +36 -0
- package/dist/term-DlGIoccA.mjs +27 -0
- package/dist/{touchstone-DOhfmSNh.mjs → touchstone-D4Fdg4Om.mjs} +1 -1
- package/dist/{verbs-CD4ZM9Es.mjs → verbs-DjQQTL2k.mjs} +191 -53
- package/dist/windowsHost-CTZXMA8D.mjs +1 -0
- package/dist/windowsHost-CtRidgJp.mjs +309 -0
- package/dist/zip-CAd_yYte.mjs +190 -0
- package/docs/architecture.md +81 -0
- package/docs/environments.md +175 -0
- package/docs/extensions.md +207 -0
- package/docs/quickstart.md +59 -4
- package/docs/transports.md +189 -0
- package/package.json +6 -2
- package/dist/cli-BqILMvnF.mjs +0 -1
- package/dist/cli-BzrDKC7x.mjs +0 -1
- package/dist/registry-5K1G1XmC.mjs +0 -1
- package/dist/server-DNMAlzZJ.mjs +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as runSimCommand } from "./cli-C8-HjAP0.mjs";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as parseArgs, n as boolValue, o as stringValue, r as formatOptions, t as CliUsageError } from "./cliArgs-BI3bJgCZ.mjs";
|
|
2
|
-
import { c as runSingle, lt as ProjectError, o as inspectProject, s as runDiff, t as analyzeSummary } from "./analyze-
|
|
2
|
+
import { c as runSingle, lt as ProjectError, o as inspectProject, s as runDiff, t as analyzeSummary } from "./analyze-TRlZx-Jv.mjs";
|
|
3
3
|
// src/epro2/cli.ts
|
|
4
4
|
const ANALYZE_OPTIONS = [
|
|
5
5
|
{
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { a as parseArgs, i as numberValue, n as boolValue, o as stringValue, r as formatOptions, t as CliUsageError } from "./cliArgs-BI3bJgCZ.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { i as loadConfig } from "./config-BKbwyvsG.mjs";
|
|
3
|
+
import { c as liveStrategy, r as describeEnvironment } from "./environment-BegP0n2N.mjs";
|
|
4
|
+
import { n as paint, t as hr } from "./term-DlGIoccA.mjs";
|
|
5
|
+
import { a as routeNets, c as EdaVerbError, d as capabilitySummary, f as lookupCapability, i as readBoardState, l as createDefaultExecContext, n as docInfo, o as routeNetsPreview, r as evalApi, s as runDrc, t as boardDigestState, u as checkEnvironment } from "./verbs-DjQQTL2k.mjs";
|
|
4
6
|
import { readFileSync } from "node:fs";
|
|
5
7
|
// src/eda/cli.ts
|
|
6
8
|
/**
|
|
@@ -139,6 +141,9 @@ function contextOf(parsed, env) {
|
|
|
139
141
|
return createDefaultExecContext({
|
|
140
142
|
env,
|
|
141
143
|
cdpPort: cfg.cdp.port,
|
|
144
|
+
cdpHosts: cfg.cdp.hosts,
|
|
145
|
+
bridgeHost: cfg.bridge.host,
|
|
146
|
+
allowedHosts: cfg.cdp.hosts,
|
|
142
147
|
bridgePortFirst: cfg.bridge.portFirst,
|
|
143
148
|
bridgePortLast: cfg.bridge.portLast,
|
|
144
149
|
match: stringValue(parsed, "match"),
|
|
@@ -158,6 +163,7 @@ function printAttempts(io, attempts) {
|
|
|
158
163
|
}
|
|
159
164
|
}
|
|
160
165
|
function printStatus(io, report) {
|
|
166
|
+
if (report.environment) io.out(` 环境: ${describeEnvironment(report.environment)}`);
|
|
161
167
|
io.out(` 状态: ${report.status}(${report.channel_state})`);
|
|
162
168
|
for (const check of report.checks) {
|
|
163
169
|
const mark = check.status === "ready" ? "OK " : check.status === "partial" ? "PART" : "MISS";
|
|
@@ -166,6 +172,7 @@ function printStatus(io, report) {
|
|
|
166
172
|
if (check.hint) io.out(paint.gray(` ${check.hint}`));
|
|
167
173
|
}
|
|
168
174
|
for (const note of report.functional_degradations) io.out(paint.gray(` 降级: ${note}`));
|
|
175
|
+
if (report.live_strategy?.summary) io.out(paint.gray(` 策略: ${report.live_strategy.summary}`));
|
|
169
176
|
io.out(` 下一步: ${report.next_action}`);
|
|
170
177
|
}
|
|
171
178
|
function printDoc(io, result) {
|
|
@@ -229,7 +236,16 @@ function printRoutePlan(io, nets) {
|
|
|
229
236
|
io.out(paint.gray(" 本次未加 --confirm,只打印计划,没有改动任何数据。"));
|
|
230
237
|
}
|
|
231
238
|
async function runStatus(io, parsed, env) {
|
|
232
|
-
const
|
|
239
|
+
const cfg = loadConfig(env);
|
|
240
|
+
const strategy = liveStrategy(cfg.environment);
|
|
241
|
+
const report = await checkEnvironment({
|
|
242
|
+
env,
|
|
243
|
+
environment: cfg.environment,
|
|
244
|
+
strategy,
|
|
245
|
+
clientExe: cfg.client.exe,
|
|
246
|
+
cdpHosts: cfg.cdp.hosts,
|
|
247
|
+
bridgeHost: cfg.bridge.host
|
|
248
|
+
});
|
|
233
249
|
if (boolValue(parsed, "json")) printJson(io, {
|
|
234
250
|
...report,
|
|
235
251
|
capability_map: capabilitySummary()
|
|
@@ -4,8 +4,8 @@ import os from "node:os";
|
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { randomBytes, randomUUID, timingSafeEqual } from "node:crypto";
|
|
6
6
|
import { createConnection, isIP } from "node:net";
|
|
7
|
-
import { mkdir, unlink, writeFile } from "node:fs/promises";
|
|
8
7
|
import { createServer } from "node:http";
|
|
8
|
+
import { mkdir, unlink, writeFile } from "node:fs/promises";
|
|
9
9
|
import { WebSocketServer } from "ws";
|
|
10
10
|
// src/bridge/server.ts
|
|
11
11
|
/** 没有任何可用的编辑器窗口 / 目标窗口已断开。HTTP 层要把它映射成 503。 */
|
package/dist/cli-bridge.mjs
CHANGED
package/dist/cli-cdp.mjs
CHANGED
package/dist/cli-mcp.mjs
CHANGED
package/dist/cli.mjs
CHANGED
|
@@ -0,0 +1,516 @@
|
|
|
1
|
+
import { a as hostOverrideWarning, i as detectEnvironment, l as windowsPathToWslPath, n as cdpProbeHosts, s as isWindowsDrivePath, t as bridgeProbeHost, u as wslPathToWindowsPath } from "./environment-BegP0n2N.mjs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import { spawnSync } from "node:child_process";
|
|
6
|
+
// src/core/exeDiscovery.ts
|
|
7
|
+
const EXE_NAME = "lceda-pro.exe";
|
|
8
|
+
const DRIVE_LETTERS = [
|
|
9
|
+
"c",
|
|
10
|
+
"d",
|
|
11
|
+
"e",
|
|
12
|
+
"f"
|
|
13
|
+
];
|
|
14
|
+
const PROGRAM_DIRS = ["Program Files", "Program Files (x86)"];
|
|
15
|
+
const WSL_HOST_EXE_NAMES = [
|
|
16
|
+
"lceda-pro.exe",
|
|
17
|
+
"lceda-pro",
|
|
18
|
+
"easyeda-pro.exe"
|
|
19
|
+
];
|
|
20
|
+
const POSIX_EXE_NAMES = [
|
|
21
|
+
"lceda-pro",
|
|
22
|
+
"lceda-pro.exe",
|
|
23
|
+
"easyeda-pro",
|
|
24
|
+
"easyeda-pro.AppImage"
|
|
25
|
+
];
|
|
26
|
+
function stripQuotes(value) {
|
|
27
|
+
const trimmed = value.trim();
|
|
28
|
+
if (trimmed.length >= 2 && trimmed.startsWith("\"") && trimmed.endsWith("\"")) return trimmed.slice(1, -1);
|
|
29
|
+
return trimmed;
|
|
30
|
+
}
|
|
31
|
+
function splitPath(value, delimiter) {
|
|
32
|
+
if (!value) return [];
|
|
33
|
+
return value.split(delimiter).map((entry) => entry.trim()).filter((entry) => entry.length > 0);
|
|
34
|
+
}
|
|
35
|
+
function pushCandidate(list, seen, candidate) {
|
|
36
|
+
const key = candidate.path.toLowerCase();
|
|
37
|
+
if (seen.has(key)) return;
|
|
38
|
+
seen.add(key);
|
|
39
|
+
list.push(candidate);
|
|
40
|
+
}
|
|
41
|
+
/** macOS `.app` 包展开成包内可执行文件候选;不是 app 包时返回空数组。 */
|
|
42
|
+
function expandMacAppBundle(value) {
|
|
43
|
+
if (!value.toLowerCase().endsWith(".app")) return [];
|
|
44
|
+
return [
|
|
45
|
+
path.join(value, "Contents", "MacOS", "lceda-pro"),
|
|
46
|
+
path.join(value, "Contents", "MacOS", "EasyEDA Pro"),
|
|
47
|
+
path.join(value, "Contents", "MacOS", "EasyEDA")
|
|
48
|
+
];
|
|
49
|
+
}
|
|
50
|
+
function windowsNativeCandidates(env) {
|
|
51
|
+
const list = [];
|
|
52
|
+
const seen = /* @__PURE__ */ new Set();
|
|
53
|
+
for (const base of [env.ProgramFiles, env["ProgramFiles(x86)"]]) if (base) pushCandidate(list, seen, {
|
|
54
|
+
path: path.win32.join(base, "lceda-pro", EXE_NAME),
|
|
55
|
+
source: "Program Files"
|
|
56
|
+
});
|
|
57
|
+
if (env.LOCALAPPDATA) {
|
|
58
|
+
pushCandidate(list, seen, {
|
|
59
|
+
path: path.win32.join(env.LOCALAPPDATA, "Programs", "lceda-pro", EXE_NAME),
|
|
60
|
+
source: "LOCALAPPDATA\\Programs"
|
|
61
|
+
});
|
|
62
|
+
pushCandidate(list, seen, {
|
|
63
|
+
path: path.win32.join(env.LOCALAPPDATA, "lceda-pro", EXE_NAME),
|
|
64
|
+
source: "LOCALAPPDATA"
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
pushCandidate(list, seen, {
|
|
68
|
+
path: "D:\\Program Files\\lceda-pro\\lceda-pro.exe",
|
|
69
|
+
source: "历史默认路径"
|
|
70
|
+
});
|
|
71
|
+
for (const entry of splitPath(env.PATH ?? env.Path, ";")) pushCandidate(list, seen, {
|
|
72
|
+
path: path.win32.join(entry, EXE_NAME),
|
|
73
|
+
source: "PATH"
|
|
74
|
+
});
|
|
75
|
+
return list;
|
|
76
|
+
}
|
|
77
|
+
function wslHostCandidates(env) {
|
|
78
|
+
const list = [];
|
|
79
|
+
const seen = /* @__PURE__ */ new Set();
|
|
80
|
+
const entries = splitPath(env.PATH, ":");
|
|
81
|
+
const hinted = entries.filter((entry) => /lceda|easyeda/i.test(entry));
|
|
82
|
+
const hintedSet = new Set(hinted);
|
|
83
|
+
const others = entries.filter((entry) => !hintedSet.has(entry)).slice(0, 24);
|
|
84
|
+
for (const entry of [...hinted, ...others]) for (const name of WSL_HOST_EXE_NAMES) pushCandidate(list, seen, {
|
|
85
|
+
path: path.posix.join(entry, name),
|
|
86
|
+
source: "WSL PATH"
|
|
87
|
+
});
|
|
88
|
+
for (const drive of DRIVE_LETTERS) for (const dir of PROGRAM_DIRS) pushCandidate(list, seen, {
|
|
89
|
+
path: `/mnt/${drive}/${dir}/lceda-pro/${EXE_NAME}`,
|
|
90
|
+
source: `/mnt/${drive}/${dir}`
|
|
91
|
+
});
|
|
92
|
+
return list;
|
|
93
|
+
}
|
|
94
|
+
function posixCandidates(env, home, options = {}) {
|
|
95
|
+
const list = [];
|
|
96
|
+
const seen = /* @__PURE__ */ new Set();
|
|
97
|
+
for (const entry of splitPath(env.PATH, ":")) {
|
|
98
|
+
if (options.excludeWindowsMounts && /^\/mnt\//i.test(entry)) continue;
|
|
99
|
+
for (const name of POSIX_EXE_NAMES) pushCandidate(list, seen, {
|
|
100
|
+
path: path.posix.join(entry, name),
|
|
101
|
+
source: "PATH"
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
for (const fixed of [
|
|
105
|
+
"/opt/lceda-pro/lceda-pro",
|
|
106
|
+
"/opt/easyeda-pro/lceda-pro",
|
|
107
|
+
"/usr/local/bin/lceda-pro",
|
|
108
|
+
"/usr/bin/lceda-pro"
|
|
109
|
+
]) pushCandidate(list, seen, {
|
|
110
|
+
path: fixed,
|
|
111
|
+
source: "常见安装目录"
|
|
112
|
+
});
|
|
113
|
+
if (home) for (const name of POSIX_EXE_NAMES) pushCandidate(list, seen, {
|
|
114
|
+
path: path.posix.join(home, ".local", "bin", name),
|
|
115
|
+
source: "~/.local/bin"
|
|
116
|
+
});
|
|
117
|
+
return list;
|
|
118
|
+
}
|
|
119
|
+
function macosCandidates(env) {
|
|
120
|
+
const list = [];
|
|
121
|
+
const seen = /* @__PURE__ */ new Set();
|
|
122
|
+
for (const bundle of [
|
|
123
|
+
"/Applications/lceda-pro.app",
|
|
124
|
+
"/Applications/EasyEDA Pro.app",
|
|
125
|
+
path.posix.join(env.HOME ?? "", "Applications", "lceda-pro.app")
|
|
126
|
+
]) for (const inner of expandMacAppBundle(bundle)) pushCandidate(list, seen, {
|
|
127
|
+
path: inner,
|
|
128
|
+
source: "Applications"
|
|
129
|
+
});
|
|
130
|
+
for (const entry of splitPath(env.PATH, ":")) for (const name of POSIX_EXE_NAMES) pushCandidate(list, seen, {
|
|
131
|
+
path: path.posix.join(entry, name),
|
|
132
|
+
source: "PATH"
|
|
133
|
+
});
|
|
134
|
+
return list;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* 生成候选列表。纯函数:不碰文件系统,顺序即优先级。
|
|
138
|
+
* `explicitPath` 不在这里(它单独处理,避免被候选顺序淹没)。
|
|
139
|
+
*/
|
|
140
|
+
function clientExeCandidates(environment, env = process.env, location = environment.clientLocations[0] ?? "host") {
|
|
141
|
+
const list = [];
|
|
142
|
+
const seen = /* @__PURE__ */ new Set();
|
|
143
|
+
const fromEnv = stripQuotes(env.LCEDA_PRO_EXE ?? "");
|
|
144
|
+
if (fromEnv) {
|
|
145
|
+
if (environment.kind === "wsl2" && isWindowsDrivePath(fromEnv)) pushCandidate(list, seen, {
|
|
146
|
+
path: windowsPathToWslPath(fromEnv),
|
|
147
|
+
source: "env:LCEDA_PRO_EXE(Windows 路径已转 WSL)"
|
|
148
|
+
});
|
|
149
|
+
else pushCandidate(list, seen, {
|
|
150
|
+
path: fromEnv,
|
|
151
|
+
source: "env:LCEDA_PRO_EXE"
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
switch (environment.kind) {
|
|
155
|
+
case "windows-native": return [...list, ...windowsNativeCandidates(env)];
|
|
156
|
+
case "wsl2": return [...list, ...location === "vm" ? posixCandidates(env, env.HOME, { excludeWindowsMounts: true }) : wslHostCandidates(env)];
|
|
157
|
+
case "linux-native": return [...list, ...posixCandidates(env, env.HOME)];
|
|
158
|
+
case "macos-native": return [...list, ...macosCandidates(env)];
|
|
159
|
+
default: return list;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/** 显式路径归一:Windows 路径在 WSL2 + host 下自动转换;macOS .app 包展开为内部可执行文件。 */
|
|
163
|
+
function normalizeExplicitExe(value, environment, location = environment.clientLocations[0] ?? "host") {
|
|
164
|
+
const cleaned = stripQuotes(value);
|
|
165
|
+
if (!cleaned) return {
|
|
166
|
+
candidates: [],
|
|
167
|
+
hostPath: null
|
|
168
|
+
};
|
|
169
|
+
let hostPath = null;
|
|
170
|
+
const candidates = [];
|
|
171
|
+
if (environment.kind === "wsl2" && location === "host" && isWindowsDrivePath(cleaned)) {
|
|
172
|
+
candidates.push(windowsPathToWslPath(cleaned));
|
|
173
|
+
hostPath = cleaned;
|
|
174
|
+
} else if (environment.kind === "wsl2") {
|
|
175
|
+
candidates.push(cleaned);
|
|
176
|
+
hostPath = wslPathToWindowsPath(cleaned);
|
|
177
|
+
} else {
|
|
178
|
+
candidates.push(cleaned);
|
|
179
|
+
if (environment.kind === "windows-native") hostPath = cleaned;
|
|
180
|
+
}
|
|
181
|
+
if (environment.kind === "macos-native") for (const inner of expandMacAppBundle(cleaned)) candidates.push(inner);
|
|
182
|
+
return {
|
|
183
|
+
candidates: [...new Set(candidates)],
|
|
184
|
+
hostPath
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
function defaultRunText(command, args, timeoutMs) {
|
|
188
|
+
try {
|
|
189
|
+
const result = spawnSync(command, [...args], {
|
|
190
|
+
timeout: timeoutMs,
|
|
191
|
+
encoding: "utf8",
|
|
192
|
+
windowsHide: true
|
|
193
|
+
});
|
|
194
|
+
if (result.status !== 0) return null;
|
|
195
|
+
return `${result.stdout ?? ""}`.trim() || null;
|
|
196
|
+
} catch {
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
function deepProbeCandidates(environment, location, runText) {
|
|
201
|
+
const runner = runText ?? defaultRunText;
|
|
202
|
+
const list = [];
|
|
203
|
+
const seen = /* @__PURE__ */ new Set();
|
|
204
|
+
if (environment.kind === "wsl2" && location === "host") {
|
|
205
|
+
const output = runner("cmd.exe", [
|
|
206
|
+
"/c",
|
|
207
|
+
"where",
|
|
208
|
+
"lceda-pro.exe"
|
|
209
|
+
], 8e3);
|
|
210
|
+
if (output) for (const line of output.split(/\r?\n/)) {
|
|
211
|
+
const value = line.trim();
|
|
212
|
+
if (!value) continue;
|
|
213
|
+
pushCandidate(list, seen, {
|
|
214
|
+
path: isWindowsDrivePath(value) ? windowsPathToWslPath(value) : value,
|
|
215
|
+
source: "Windows where.exe"
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
return list;
|
|
219
|
+
}
|
|
220
|
+
if (environment.kind === "windows-native") {
|
|
221
|
+
const output = runner("where.exe", ["lceda-pro.exe"], 5e3);
|
|
222
|
+
if (output) for (const line of output.split(/\r?\n/)) {
|
|
223
|
+
const value = line.trim();
|
|
224
|
+
if (value) pushCandidate(list, seen, {
|
|
225
|
+
path: value,
|
|
226
|
+
source: "where.exe"
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
return list;
|
|
230
|
+
}
|
|
231
|
+
if (environment.kind === "macos-native" || environment.kind === "linux-native" || environment.kind === "wsl2" && location === "vm") {
|
|
232
|
+
const output = runner("sh", ["-lc", "command -v lceda-pro || command -v easyeda-pro"], 5e3);
|
|
233
|
+
if (output) for (const line of output.split(/\r?\n/)) {
|
|
234
|
+
const value = line.trim();
|
|
235
|
+
if (value) pushCandidate(list, seen, {
|
|
236
|
+
path: value,
|
|
237
|
+
source: "command -v"
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return list;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* 发现客户端可执行文件。
|
|
245
|
+
*
|
|
246
|
+
* 显式路径优先且**不回退**:用户说了用哪个就必须用哪个,找不到要明确报错,
|
|
247
|
+
* 不能悄悄换成自动发现的结果(否则排查时会以为显式参数生效了)。
|
|
248
|
+
*/
|
|
249
|
+
function discoverClientExe(options) {
|
|
250
|
+
const { environment } = options;
|
|
251
|
+
const env = options.env ?? process.env;
|
|
252
|
+
const location = options.location ?? environment.clientLocations[0] ?? "host";
|
|
253
|
+
const exists = options.exists ?? ((file) => fs.existsSync(file));
|
|
254
|
+
const warnings = [];
|
|
255
|
+
const candidates = [];
|
|
256
|
+
if (options.explicitPath && options.explicitPath.trim()) {
|
|
257
|
+
const explicit = normalizeExplicitExe(options.explicitPath, environment, location);
|
|
258
|
+
for (const candidate of explicit.candidates) {
|
|
259
|
+
const present = exists(candidate);
|
|
260
|
+
candidates.push({
|
|
261
|
+
path: candidate,
|
|
262
|
+
source: "显式指定",
|
|
263
|
+
exists: present
|
|
264
|
+
});
|
|
265
|
+
if (present) return {
|
|
266
|
+
status: "explicit",
|
|
267
|
+
path: candidate,
|
|
268
|
+
hostPath: explicit.hostPath,
|
|
269
|
+
source: "显式指定",
|
|
270
|
+
location,
|
|
271
|
+
candidates,
|
|
272
|
+
warnings,
|
|
273
|
+
environment: environment.kind
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
warnings.push(`显式指定的客户端路径不存在:${options.explicitPath}`);
|
|
277
|
+
return {
|
|
278
|
+
status: "explicit_missing",
|
|
279
|
+
path: null,
|
|
280
|
+
hostPath: explicit.hostPath,
|
|
281
|
+
source: "显式指定",
|
|
282
|
+
location,
|
|
283
|
+
candidates,
|
|
284
|
+
warnings,
|
|
285
|
+
environment: environment.kind
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
const list = clientExeCandidates(environment, env, location);
|
|
289
|
+
for (const candidate of list) {
|
|
290
|
+
const present = exists(candidate.path);
|
|
291
|
+
candidates.push({
|
|
292
|
+
...candidate,
|
|
293
|
+
exists: present
|
|
294
|
+
});
|
|
295
|
+
if (present) return {
|
|
296
|
+
status: "discovered",
|
|
297
|
+
path: candidate.path,
|
|
298
|
+
hostPath: wslPathToWindowsPath(candidate.path) ?? candidate.path,
|
|
299
|
+
source: candidate.source,
|
|
300
|
+
location,
|
|
301
|
+
candidates,
|
|
302
|
+
warnings,
|
|
303
|
+
environment: environment.kind
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
if (options.deep) for (const candidate of deepProbeCandidates(environment, location, options.runText)) {
|
|
307
|
+
const present = exists(candidate.path);
|
|
308
|
+
candidates.push({
|
|
309
|
+
...candidate,
|
|
310
|
+
exists: present
|
|
311
|
+
});
|
|
312
|
+
if (present) return {
|
|
313
|
+
status: "discovered",
|
|
314
|
+
path: candidate.path,
|
|
315
|
+
hostPath: wslPathToWindowsPath(candidate.path) ?? candidate.path,
|
|
316
|
+
source: candidate.source,
|
|
317
|
+
location,
|
|
318
|
+
candidates,
|
|
319
|
+
warnings,
|
|
320
|
+
environment: environment.kind
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
if (environment.kind === "unknown") warnings.push("环境未知:无法生成客户端候选路径,请用 --exe 显式指定");
|
|
324
|
+
return {
|
|
325
|
+
status: "not_found",
|
|
326
|
+
path: null,
|
|
327
|
+
hostPath: null,
|
|
328
|
+
source: "",
|
|
329
|
+
location,
|
|
330
|
+
candidates,
|
|
331
|
+
warnings,
|
|
332
|
+
environment: environment.kind
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* 发现结果缓存:loadConfig 在 MCP 进程里会被多次调用(每个 server / 每次自检),
|
|
337
|
+
* 而候选路径的 stat 在 WSL 的 /mnt 上并不便宜。文件系统探测结果按环境 + PATH 缓存;
|
|
338
|
+
* 注入探针(测试)不缓存。
|
|
339
|
+
*/
|
|
340
|
+
const planCache = /* @__PURE__ */ new Map();
|
|
341
|
+
function planCacheKey(options) {
|
|
342
|
+
if (options.exists || options.runText) return null;
|
|
343
|
+
const env = options.env ?? process.env;
|
|
344
|
+
return [
|
|
345
|
+
options.environment.kind,
|
|
346
|
+
options.environment.clientLocations.join(","),
|
|
347
|
+
options.explicitPath ?? "",
|
|
348
|
+
env.PATH ?? "",
|
|
349
|
+
env.LCEDA_PRO_EXE ?? "",
|
|
350
|
+
env.HOME ?? "",
|
|
351
|
+
env.ProgramFiles ?? "",
|
|
352
|
+
env["ProgramFiles(x86)"] ?? "",
|
|
353
|
+
env.LOCALAPPDATA ?? "",
|
|
354
|
+
options.deep ? "deep" : ""
|
|
355
|
+
].join("\0");
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* 按客户端位置优先级依次发现。显式路径在所有位置下都会尝试,
|
|
359
|
+
* 命中即返回该位置;显式路径全都不存在时,整体按 explicit_missing 处理,不回退。
|
|
360
|
+
*/
|
|
361
|
+
function discoverClientExePlan(options) {
|
|
362
|
+
const cacheKey = planCacheKey(options);
|
|
363
|
+
if (cacheKey) {
|
|
364
|
+
const hit = planCache.get(cacheKey);
|
|
365
|
+
if (hit) return structuredClone(hit);
|
|
366
|
+
}
|
|
367
|
+
const warnings = [];
|
|
368
|
+
const locations = [];
|
|
369
|
+
const targets = options.environment.clientLocations.length ? options.environment.clientLocations : ["host"];
|
|
370
|
+
for (const location of targets) {
|
|
371
|
+
const result = discoverClientExe({
|
|
372
|
+
...options,
|
|
373
|
+
location
|
|
374
|
+
});
|
|
375
|
+
locations.push(result);
|
|
376
|
+
warnings.push(...result.warnings);
|
|
377
|
+
if (result.status === "explicit" || result.status === "discovered") return rememberPlan(cacheKey, {
|
|
378
|
+
locations,
|
|
379
|
+
primary: result,
|
|
380
|
+
warnings
|
|
381
|
+
});
|
|
382
|
+
if (result.status === "explicit_missing") return rememberPlan(cacheKey, {
|
|
383
|
+
locations,
|
|
384
|
+
primary: null,
|
|
385
|
+
warnings
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
return rememberPlan(cacheKey, {
|
|
389
|
+
locations,
|
|
390
|
+
primary: null,
|
|
391
|
+
warnings
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
function rememberPlan(cacheKey, plan) {
|
|
395
|
+
if (cacheKey) planCache.set(cacheKey, structuredClone(plan));
|
|
396
|
+
return plan;
|
|
397
|
+
}
|
|
398
|
+
// src/core/config.ts
|
|
399
|
+
/** 立创EDA专业版历史默认安装路径(仅 Windows 原生环境;可用 `--exe` / LCEDA_PRO_EXE 覆盖)。 */
|
|
400
|
+
const DEFAULT_PRO_EXE = "D:\\Program Files\\lceda-pro\\lceda-pro.exe";
|
|
401
|
+
const DEFAULT_CDP_PORT = 9222;
|
|
402
|
+
const LOOPBACK = "127.0.0.1";
|
|
403
|
+
/** bridge-server.mjs 的固定契约,改动前请同步核对服务端。 */
|
|
404
|
+
const BRIDGE_PORT_FIRST = 49620;
|
|
405
|
+
const BRIDGE_PORT_LAST = 49629;
|
|
406
|
+
const BRIDGE_SERVICE_ID = "easyeda-bridge";
|
|
407
|
+
const BRIDGE_MAX_LOG_BYTES = 5242880;
|
|
408
|
+
const BRIDGE_START_WAIT_MS = 2e4;
|
|
409
|
+
const BRIDGE_RESTART_DELAY_MS = 3e3;
|
|
410
|
+
/** CDP 启动后等待端点就绪的上限(旧脚本为 60 秒)。 */
|
|
411
|
+
const CDP_START_WAIT_MS = 6e4;
|
|
412
|
+
const KIND_SOURCES = [
|
|
413
|
+
"argv",
|
|
414
|
+
"config-file",
|
|
415
|
+
"env",
|
|
416
|
+
"auto-detected"
|
|
417
|
+
];
|
|
418
|
+
function kindSourceOf(raw, fallback) {
|
|
419
|
+
return KIND_SOURCES.includes(raw) ? raw : fallback;
|
|
420
|
+
}
|
|
421
|
+
function locationSourceOf(raw) {
|
|
422
|
+
if (raw === "argv" || raw === "config-file" || raw === "env" || raw === "default") return raw;
|
|
423
|
+
}
|
|
424
|
+
function intFromEnv(raw, fallback) {
|
|
425
|
+
if (!raw) return fallback;
|
|
426
|
+
const parsed = Number.parseInt(raw, 10);
|
|
427
|
+
return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;
|
|
428
|
+
}
|
|
429
|
+
function scanFromEnv(raw) {
|
|
430
|
+
if (!raw) return void 0;
|
|
431
|
+
const match = /^(\d+)\s*[-:]\s*(\d+)$/.exec(raw.trim());
|
|
432
|
+
if (!match) return void 0;
|
|
433
|
+
const start = Number.parseInt(match[1] ?? "", 10);
|
|
434
|
+
const end = Number.parseInt(match[2] ?? "", 10);
|
|
435
|
+
if (!Number.isFinite(start) || !Number.isFinite(end) || start <= 0 || end < start) return void 0;
|
|
436
|
+
return [start, end];
|
|
437
|
+
}
|
|
438
|
+
function homeDir(env = process.env) {
|
|
439
|
+
return env.USERPROFILE || env.HOME || homedir();
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* 配置优先级:命令行参数 > 配置文件 > .env > 环境变量 > 内置默认值
|
|
443
|
+
* (前四级由 core/runtimeConfig 合并成 env,这里只处理 env + 显式 overrides)。
|
|
444
|
+
*
|
|
445
|
+
* 目录约定:
|
|
446
|
+
* - CDP 运行态放在 ~/.lceda-connect/cdp(可用 LCEDA_CONNECT_HOME 改根)
|
|
447
|
+
* - Bridge 运行态沿用 %LOCALAPPDATA%\lceda-bridge,保证老的 state.json / bridge.log 继续可用
|
|
448
|
+
*/
|
|
449
|
+
function loadConfig(env = process.env, overrides = {}, options = {}) {
|
|
450
|
+
const home = homeDir(env);
|
|
451
|
+
const connectHome = env.LCEDA_CONNECT_HOME || path.join(home, ".lceda-connect");
|
|
452
|
+
const cdpDir = path.join(connectHome, "cdp");
|
|
453
|
+
const localAppData = env.LOCALAPPDATA || path.join(home, "AppData", "Local");
|
|
454
|
+
const bridgeDir = env.LCEDA_BRIDGE_RUNTIME || path.join(localAppData, "lceda-bridge");
|
|
455
|
+
const detectOptions = {
|
|
456
|
+
...options.detect,
|
|
457
|
+
kind: options.detect?.kind ?? env.LCEDA_ENV ?? null,
|
|
458
|
+
windowsHost: options.detect?.windowsHost ?? env.LCEDA_WINDOWS_HOST ?? null,
|
|
459
|
+
clientLocations: options.detect?.clientLocations ?? env.LCEDA_LEDA_IN ?? null,
|
|
460
|
+
cache: options.detect?.probes === void 0
|
|
461
|
+
};
|
|
462
|
+
if (options.detect?.kindSource === void 0 && env.LCEDA_ENV_SOURCE) detectOptions.kindSource = kindSourceOf(env.LCEDA_ENV_SOURCE, "env");
|
|
463
|
+
if (options.detect?.windowsHostSource === void 0 && env.LCEDA_WINDOWS_HOST_SOURCE) detectOptions.windowsHostSource = kindSourceOf(env.LCEDA_WINDOWS_HOST_SOURCE, "env");
|
|
464
|
+
if (options.detect?.clientLocationSource === void 0 && env.LCEDA_LEDA_IN_SOURCE) detectOptions.clientLocationSource = locationSourceOf(env.LCEDA_LEDA_IN_SOURCE);
|
|
465
|
+
const environment = detectEnvironment(detectOptions);
|
|
466
|
+
for (const [value, label] of [[env.LCEDA_CDP_HOST, "CDP 探测地址"], [env.LCEDA_BRIDGE_HOST, "bridge 探测地址"]]) {
|
|
467
|
+
const warning = hostOverrideWarning(environment, value, label);
|
|
468
|
+
if (warning) environment.warnings.push(warning);
|
|
469
|
+
}
|
|
470
|
+
const cdpHosts = cdpProbeHosts(environment, env.LCEDA_CDP_HOST);
|
|
471
|
+
const bridgeHost = bridgeProbeHost(environment, env.LCEDA_BRIDGE_HOST);
|
|
472
|
+
const explicitExe = overrides.cdp?.exePath ?? env.LCEDA_PRO_EXE;
|
|
473
|
+
const exePlan = discoverClientExePlan({
|
|
474
|
+
environment,
|
|
475
|
+
env,
|
|
476
|
+
explicitPath: explicitExe,
|
|
477
|
+
deep: options.deepExe ?? false,
|
|
478
|
+
exists: options.exists
|
|
479
|
+
});
|
|
480
|
+
return {
|
|
481
|
+
cdp: {
|
|
482
|
+
exePath: explicitExe ?? "D:\\Program Files\\lceda-pro\\lceda-pro.exe",
|
|
483
|
+
port: overrides.cdp?.port ?? intFromEnv(env.LCEDA_CDP_PORT, 9222),
|
|
484
|
+
bindHost: LOOPBACK,
|
|
485
|
+
host: cdpHosts[0] ?? "127.0.0.1",
|
|
486
|
+
hosts: cdpHosts,
|
|
487
|
+
runtimeDir: cdpDir,
|
|
488
|
+
pidFile: path.join(cdpDir, "lceda-cdp.pid"),
|
|
489
|
+
logFile: path.join(cdpDir, "lceda-cdp.log"),
|
|
490
|
+
legacyPidFile: path.join(home, ".lceda-cdp", "lceda-cdp.pid"),
|
|
491
|
+
startWaitMs: CDP_START_WAIT_MS,
|
|
492
|
+
scan: scanFromEnv(env.LCEDA_CDP_SCAN)
|
|
493
|
+
},
|
|
494
|
+
bridge: {
|
|
495
|
+
portFirst: intFromEnv(env.LCEDA_BRIDGE_PORT_FIRST, BRIDGE_PORT_FIRST),
|
|
496
|
+
portLast: intFromEnv(env.LCEDA_BRIDGE_PORT_LAST, BRIDGE_PORT_LAST),
|
|
497
|
+
bindHost: LOOPBACK,
|
|
498
|
+
host: bridgeHost,
|
|
499
|
+
serviceId: BRIDGE_SERVICE_ID,
|
|
500
|
+
runtimeDir: bridgeDir,
|
|
501
|
+
logFile: path.join(bridgeDir, "bridge.log"),
|
|
502
|
+
stateFile: path.join(bridgeDir, "state.json"),
|
|
503
|
+
maxLogBytes: BRIDGE_MAX_LOG_BYTES,
|
|
504
|
+
startWaitMs: BRIDGE_START_WAIT_MS,
|
|
505
|
+
restartDelayMs: BRIDGE_RESTART_DELAY_MS,
|
|
506
|
+
nodePath: overrides.bridge?.nodePath ?? env.LCEDA_NODE,
|
|
507
|
+
bridgeScript: overrides.bridge?.bridgeScript ?? env.LCEDA_BRIDGE_SCRIPT
|
|
508
|
+
},
|
|
509
|
+
environment,
|
|
510
|
+
client: {
|
|
511
|
+
plan: exePlan,
|
|
512
|
+
exe: exePlan.primary
|
|
513
|
+
}
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
export { loadConfig as i, DEFAULT_PRO_EXE as n, homeDir as r, DEFAULT_CDP_PORT as t };
|