lceda-connect 0.3.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 +22 -0
- package/README.md +92 -30
- package/dist/{cli-CjcJVM6z.mjs → cli-1_urvve3.mjs} +4 -4
- package/dist/{cli-C4ZkWlV2.mjs → cli-CXk5pvVm.mjs} +1 -1
- package/dist/{cli-C6saKrQp.mjs → cli-DFqBHofJ.mjs} +18 -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-D5mRrsxg.mjs → discover-DmRYlAlR.mjs} +13 -64
- 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 +7 -5
- package/dist/{main-CcKvXSJG.mjs → main-B3aaKvqY.mjs} +688 -89
- package/dist/mcpHost-CRoN6MnG.mjs +331 -0
- package/dist/{registry-Dmti2u6s.mjs → registry-3WTFCZsR.mjs} +84 -24
- package/dist/registry-DdJ8LEdd.mjs +1 -0
- package/dist/{server-BduSjwzu.mjs → server-zw6t1Pmk.mjs} +9 -14
- package/dist/{session-DvIXO5Hf.mjs → session-AQbRX6Ys.mjs} +2 -2
- package/dist/{sideEffects-DF_tIVsf.mjs → sideEffects-Ds_T-_B4.mjs} +3 -3
- package/dist/stdio-BZPlcfDR.mjs +27 -0
- package/dist/stdio-Du1oLqfJ.mjs +1 -0
- package/dist/{targets-D5nmbsyz.mjs → targets-8LBEgvbq.mjs} +1 -1
- package/dist/{verbs-5M7rj1-E.mjs → verbs-DjQQTL2k.mjs} +191 -54
- package/dist/windowsHost-CTZXMA8D.mjs +1 -0
- package/dist/windowsHost-CtRidgJp.mjs +309 -0
- package/docs/architecture.md +81 -0
- package/docs/environments.md +175 -0
- package/docs/quickstart.md +59 -4
- package/docs/transports.md +189 -0
- package/package.json +5 -2
- package/dist/registry-zIKWeXV6.mjs +0 -1
- package/dist/server-Chka6eAQ.mjs +0 -1
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
import { a as resolveWindowsNode, i as resolveWindowsMcpEntry, r as resolveWindowsEnvironment } from "./windowsHost-CtRidgJp.mjs";
|
|
2
|
+
import { n as paint } from "./term-DlGIoccA.mjs";
|
|
3
|
+
import { spawn } from "node:child_process";
|
|
4
|
+
// src/commands/mcpHost.ts
|
|
5
|
+
/**
|
|
6
|
+
* `lceda-connect mcp host`:在 WSL 里用 stdio 拉起 **Windows 侧**的 lceda-connect MCP。
|
|
7
|
+
*
|
|
8
|
+
* 为什么不是普通代理:WSL 的 stdio 客户端直接 spawn `/mnt/c/.../node.exe Windows\dist\cli-mcp.mjs`
|
|
9
|
+
* 就能工作(已实测),但路径/环境需要人来翻。这个命令把「找 Windows node、找 Windows
|
|
10
|
+
* 安装入口、翻译 /mnt 配置路径、构造干净的 Windows 环境」收成一条命令,MCP 客户端
|
|
11
|
+
* 仍按 stdio 标准调用。`--print-config` 则直接输出可粘贴的客户端配置。
|
|
12
|
+
*/
|
|
13
|
+
const HOST_CONFIG_ENV_KEYS = [
|
|
14
|
+
"LCEDA_ENV",
|
|
15
|
+
"LCEDA_ENV_SOURCE",
|
|
16
|
+
"LCEDA_LEDA_IN",
|
|
17
|
+
"LCEDA_LEDA_IN_SOURCE",
|
|
18
|
+
"LCEDA_WINDOWS_HOST",
|
|
19
|
+
"LCEDA_CDP_HOST",
|
|
20
|
+
"LCEDA_CDP_PORT",
|
|
21
|
+
"LCEDA_CDP_SCAN",
|
|
22
|
+
"LCEDA_BRIDGE_HOST",
|
|
23
|
+
"LCEDA_BRIDGE_PORT_FIRST",
|
|
24
|
+
"LCEDA_BRIDGE_PORT_LAST",
|
|
25
|
+
"LCEDA_PRO_EXE",
|
|
26
|
+
"LCEDA_CONFIG",
|
|
27
|
+
"LCEDA_ENV_FILE",
|
|
28
|
+
"LCEDA_CONNECT_HOME",
|
|
29
|
+
"LCEDA_CONNECT_ASSETS",
|
|
30
|
+
"LCEDA_NODE",
|
|
31
|
+
"LCEDA_BRIDGE_SCRIPT",
|
|
32
|
+
"LCEDA_TOOLSETS",
|
|
33
|
+
"LCEDA_ALLOWED_ROOTS",
|
|
34
|
+
"EASYEDA_CDP_TIMEOUT"
|
|
35
|
+
];
|
|
36
|
+
/**
|
|
37
|
+
* 纯决策:客户端已在目标端口就跑;已在别的端口/没端口就报错而**不杀进程**。
|
|
38
|
+
* 这是“未保存工程确认”的工程化表达:只启动,不结束任何用户进程。
|
|
39
|
+
*/
|
|
40
|
+
function decideClientStart(status, desiredPort) {
|
|
41
|
+
const instances = status?.instances ?? [];
|
|
42
|
+
const ports = (status?.debugFlagged ?? []).map((item) => item.port).filter((port) => port > 0);
|
|
43
|
+
if (ports.includes(desiredPort)) return {
|
|
44
|
+
action: "skip",
|
|
45
|
+
reason: `客户端已在 ${desiredPort} 上运行`,
|
|
46
|
+
runningPort: desiredPort
|
|
47
|
+
};
|
|
48
|
+
if (instances.length > 0) {
|
|
49
|
+
if (ports.length > 0) return {
|
|
50
|
+
action: "error",
|
|
51
|
+
reason: `客户端已在运行,调试端口是 ${ports.join("/")},与目标 ${desiredPort} 不同;请先保存并手动退出客户端再重试(不会自动结束进程)`,
|
|
52
|
+
runningPort: ports[0]
|
|
53
|
+
};
|
|
54
|
+
return {
|
|
55
|
+
action: "error",
|
|
56
|
+
reason: "客户端已在运行但没有调试端口;请先保存并手动退出客户端,再重试 --start-client(不会自动结束进程)"
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
action: "start",
|
|
61
|
+
reason: `客户端未运行,将在 ${desiredPort} 上启动`
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/** 构造启动计划;找不到 Windows node 或安装入口时返回错误字符串。 */
|
|
65
|
+
function buildMcpHostPlan(options = { io: {
|
|
66
|
+
out: () => {},
|
|
67
|
+
err: () => {}
|
|
68
|
+
} }) {
|
|
69
|
+
const env = { ...options.env ?? process.env };
|
|
70
|
+
if (options.nodePath) env.LCEDA_WINDOWS_NODE = options.nodePath;
|
|
71
|
+
if (options.scriptPath) env.LCEDA_WINDOWS_MCP = options.scriptPath;
|
|
72
|
+
const node = resolveWindowsNode(env, options.probes);
|
|
73
|
+
if (!node) return {
|
|
74
|
+
plan: null,
|
|
75
|
+
error: "找不到 Windows 的 node.exe。先在 Windows 装 Node 20+,或用 --node 'C:\\Program Files\\nodejs\\node.exe' 指定。"
|
|
76
|
+
};
|
|
77
|
+
const entry = resolveWindowsMcpEntry(env, options.probes);
|
|
78
|
+
if (!entry) return {
|
|
79
|
+
plan: null,
|
|
80
|
+
error: "Windows 侧没有找到 lceda-connect 安装。先在 Windows 执行 `pnpm add -g lceda-connect`(或 npm),或用 --script 'D:\\path\\lceda-connect\\dist\\cli-mcp.mjs' 指定。"
|
|
81
|
+
};
|
|
82
|
+
const windows = resolveWindowsEnvironment(env, options.probes);
|
|
83
|
+
return {
|
|
84
|
+
plan: {
|
|
85
|
+
node,
|
|
86
|
+
entry,
|
|
87
|
+
childEnv: windows.env,
|
|
88
|
+
warnings: windows.warnings
|
|
89
|
+
},
|
|
90
|
+
error: null
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function cliEntryOf(plan) {
|
|
94
|
+
if (!/cli-mcp\.mjs$/i.test(plan.entry.winPath)) return null;
|
|
95
|
+
return plan.entry.winPath.replace(/cli-mcp\.mjs$/i, "cli.mjs");
|
|
96
|
+
}
|
|
97
|
+
function parseJsonOutput(text) {
|
|
98
|
+
const trimmed = text.trim();
|
|
99
|
+
if (!trimmed) return null;
|
|
100
|
+
try {
|
|
101
|
+
return JSON.parse(trimmed);
|
|
102
|
+
} catch {
|
|
103
|
+
const start = trimmed.indexOf("{");
|
|
104
|
+
const end = trimmed.lastIndexOf("}");
|
|
105
|
+
if (start < 0 || end <= start) return null;
|
|
106
|
+
try {
|
|
107
|
+
return JSON.parse(trimmed.slice(start, end + 1));
|
|
108
|
+
} catch {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
function runWindowsCli(plan, args, timeoutMs) {
|
|
114
|
+
const cli = cliEntryOf(plan);
|
|
115
|
+
if (!cli) return Promise.resolve({
|
|
116
|
+
code: 1,
|
|
117
|
+
stdout: "",
|
|
118
|
+
stderr: "当前 Windows 入口不是 cli-mcp.mjs,无法定位 cli.mjs 来启动客户端"
|
|
119
|
+
});
|
|
120
|
+
return new Promise((resolve) => {
|
|
121
|
+
const child = spawn(plan.node.wslPath, [cli, ...args], {
|
|
122
|
+
env: plan.childEnv,
|
|
123
|
+
windowsHide: true,
|
|
124
|
+
stdio: [
|
|
125
|
+
"ignore",
|
|
126
|
+
"pipe",
|
|
127
|
+
"pipe"
|
|
128
|
+
]
|
|
129
|
+
});
|
|
130
|
+
let stdout = "";
|
|
131
|
+
let stderr = "";
|
|
132
|
+
const timer = setTimeout(() => {
|
|
133
|
+
child.kill("SIGTERM");
|
|
134
|
+
resolve({
|
|
135
|
+
code: 124,
|
|
136
|
+
stdout,
|
|
137
|
+
stderr: `${stderr}\n超时(${timeoutMs}ms)`
|
|
138
|
+
});
|
|
139
|
+
}, timeoutMs);
|
|
140
|
+
child.stdout?.on("data", (chunk) => {
|
|
141
|
+
stdout += chunk.toString("utf8");
|
|
142
|
+
});
|
|
143
|
+
child.stderr?.on("data", (chunk) => {
|
|
144
|
+
stderr += chunk.toString("utf8");
|
|
145
|
+
});
|
|
146
|
+
child.once("error", (error) => {
|
|
147
|
+
clearTimeout(timer);
|
|
148
|
+
resolve({
|
|
149
|
+
code: 1,
|
|
150
|
+
stdout,
|
|
151
|
+
stderr: `${stderr}\n${error.message}`
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
child.once("exit", (code) => {
|
|
155
|
+
clearTimeout(timer);
|
|
156
|
+
resolve({
|
|
157
|
+
code: code ?? 1,
|
|
158
|
+
stdout,
|
|
159
|
+
stderr
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
function waitForWindowsCdp(plan, port, timeoutMs) {
|
|
165
|
+
const script = "const http=require('http');const p=Number(process.argv[1]);const t0=Date.now();const tryOnce=()=>{const req=http.get({host:'127.0.0.1',port:p,path:'/json/version',timeout:800},r=>{let b='';r.on('data',c=>b+=c);r.on('end',()=>{try{const j=JSON.parse(b);if(j.Browser&&j['Protocol-Version']){console.log('READY '+j.Browser);process.exit(0)}}catch{}if(Date.now()-t0>t){console.log('TIMEOUT');process.exit(2)}setTimeout(tryOnce,300)})});req.on('error',()=>{if(Date.now()-t0>t){console.log('TIMEOUT');process.exit(2)}setTimeout(tryOnce,300)});req.on('timeout',()=>req.destroy())};const t=" + String(timeoutMs) + ";tryOnce();";
|
|
166
|
+
return new Promise((resolve) => {
|
|
167
|
+
const child = spawn(plan.node.wslPath, [
|
|
168
|
+
"-e",
|
|
169
|
+
script,
|
|
170
|
+
String(port)
|
|
171
|
+
], {
|
|
172
|
+
env: plan.childEnv,
|
|
173
|
+
windowsHide: true,
|
|
174
|
+
stdio: [
|
|
175
|
+
"ignore",
|
|
176
|
+
"pipe",
|
|
177
|
+
"pipe"
|
|
178
|
+
]
|
|
179
|
+
});
|
|
180
|
+
let stdout = "";
|
|
181
|
+
let stderr = "";
|
|
182
|
+
const timer = setTimeout(() => {
|
|
183
|
+
child.kill("SIGTERM");
|
|
184
|
+
resolve({
|
|
185
|
+
ok: false,
|
|
186
|
+
detail: `等待端点超时(${timeoutMs}ms)`
|
|
187
|
+
});
|
|
188
|
+
}, timeoutMs + 5e3);
|
|
189
|
+
child.stdout?.on("data", (chunk) => {
|
|
190
|
+
stdout += chunk.toString("utf8");
|
|
191
|
+
});
|
|
192
|
+
child.stderr?.on("data", (chunk) => {
|
|
193
|
+
stderr += chunk.toString("utf8");
|
|
194
|
+
});
|
|
195
|
+
child.once("error", (error) => {
|
|
196
|
+
clearTimeout(timer);
|
|
197
|
+
resolve({
|
|
198
|
+
ok: false,
|
|
199
|
+
detail: error.message
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
child.once("exit", (code) => {
|
|
203
|
+
clearTimeout(timer);
|
|
204
|
+
const text = stdout.trim();
|
|
205
|
+
resolve({
|
|
206
|
+
ok: code === 0 && text.startsWith("READY"),
|
|
207
|
+
detail: text || stderr.trim() || `退出码 ${code ?? "unknown"}`
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
async function ensureClient(plan, desiredPort, io) {
|
|
213
|
+
const statusRun = await runWindowsCli(plan, [
|
|
214
|
+
"cdp",
|
|
215
|
+
"status",
|
|
216
|
+
"--json"
|
|
217
|
+
], 3e4);
|
|
218
|
+
const status = statusRun.code === 0 ? parseJsonOutput(statusRun.stdout) : null;
|
|
219
|
+
if (!status) {
|
|
220
|
+
io.err(paint.yellow(` ! 无法读取客户端状态(cdp status 退出码 ${statusRun.code});尝试直接启动`));
|
|
221
|
+
io.err(paint.gray(` ${(statusRun.stderr || statusRun.stdout).trim().slice(0, 300)}`));
|
|
222
|
+
}
|
|
223
|
+
const decision = decideClientStart(status, desiredPort);
|
|
224
|
+
if (decision.action === "error") {
|
|
225
|
+
io.err(paint.red(` ${decision.reason}`));
|
|
226
|
+
return false;
|
|
227
|
+
}
|
|
228
|
+
if (decision.action === "skip") {
|
|
229
|
+
io.err(paint.green(` ${decision.reason}`));
|
|
230
|
+
return true;
|
|
231
|
+
}
|
|
232
|
+
io.err(paint.gray(` ${decision.reason}…`));
|
|
233
|
+
const cli = cliEntryOf(plan);
|
|
234
|
+
if (!cli) {
|
|
235
|
+
io.err(paint.red(" 无法定位 Windows 侧 cli.mjs,不能自动启动客户端"));
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
const starter = spawn(plan.node.wslPath, [
|
|
239
|
+
cli,
|
|
240
|
+
"cdp",
|
|
241
|
+
"start",
|
|
242
|
+
"--port",
|
|
243
|
+
String(desiredPort)
|
|
244
|
+
], {
|
|
245
|
+
env: plan.childEnv,
|
|
246
|
+
windowsHide: true,
|
|
247
|
+
stdio: "ignore"
|
|
248
|
+
});
|
|
249
|
+
starter.once("error", (error) => {
|
|
250
|
+
io.err(paint.yellow(` ! 启动客户端失败:${error.message}`));
|
|
251
|
+
});
|
|
252
|
+
starter.unref();
|
|
253
|
+
const waited = await waitForWindowsCdp(plan, desiredPort, 45e3);
|
|
254
|
+
if (!waited.ok) {
|
|
255
|
+
io.err(paint.red(` EasyEDA 未在预期时间内就绪:${waited.detail}`));
|
|
256
|
+
return false;
|
|
257
|
+
}
|
|
258
|
+
io.err(paint.green(` 客户端已启动:127.0.0.1:${desiredPort}(${waited.detail.replace(/^READY\s*/, "")})`));
|
|
259
|
+
return true;
|
|
260
|
+
}
|
|
261
|
+
function envForPrintConfig(plan) {
|
|
262
|
+
const picked = {};
|
|
263
|
+
for (const key of HOST_CONFIG_ENV_KEYS) {
|
|
264
|
+
const value = plan.childEnv[key];
|
|
265
|
+
if (value === void 0 || value === "") continue;
|
|
266
|
+
picked[key] = value;
|
|
267
|
+
}
|
|
268
|
+
return picked;
|
|
269
|
+
}
|
|
270
|
+
function printClientConfig(io, plan, args) {
|
|
271
|
+
const config = { mcpServers: { lceda: {
|
|
272
|
+
type: "stdio",
|
|
273
|
+
command: plan.node.wslPath,
|
|
274
|
+
args: [plan.entry.winPath, ...args],
|
|
275
|
+
env: envForPrintConfig(plan)
|
|
276
|
+
} } };
|
|
277
|
+
io.out(JSON.stringify(config, null, 2));
|
|
278
|
+
}
|
|
279
|
+
async function runMcpHost(options) {
|
|
280
|
+
const { io } = options;
|
|
281
|
+
const built = buildMcpHostPlan(options);
|
|
282
|
+
if (!built.plan) {
|
|
283
|
+
io.err(paint.red(` ${built.error ?? "无法构造 Windows 启动计划"}`));
|
|
284
|
+
return 1;
|
|
285
|
+
}
|
|
286
|
+
const { plan } = built;
|
|
287
|
+
const forwardArgs = [...options.forwardArgs ?? []];
|
|
288
|
+
if (options.printConfig) {
|
|
289
|
+
for (const warning of plan.warnings) io.err(paint.yellow(` ! ${warning}`));
|
|
290
|
+
printClientConfig(io, plan, forwardArgs);
|
|
291
|
+
return 0;
|
|
292
|
+
}
|
|
293
|
+
io.err(paint.gray(` Windows node: ${plan.node.wslPath}(${plan.node.source})`));
|
|
294
|
+
io.err(paint.gray(` Windows MCP: ${plan.entry.winPath}(${plan.entry.source})`));
|
|
295
|
+
for (const warning of plan.warnings) io.err(paint.yellow(` ! ${warning}`));
|
|
296
|
+
if (options.startClient) {
|
|
297
|
+
const port = options.clientPort ?? Number.parseInt(plan.childEnv.LCEDA_CDP_PORT ?? "9222", 10);
|
|
298
|
+
if (!await ensureClient(plan, Number.isFinite(port) && port > 0 ? port : 9222, io)) return 1;
|
|
299
|
+
}
|
|
300
|
+
const child = spawn(plan.node.wslPath, [plan.entry.winPath, ...forwardArgs], {
|
|
301
|
+
stdio: [
|
|
302
|
+
"pipe",
|
|
303
|
+
"inherit",
|
|
304
|
+
"inherit"
|
|
305
|
+
],
|
|
306
|
+
env: plan.childEnv,
|
|
307
|
+
windowsHide: true
|
|
308
|
+
});
|
|
309
|
+
process.stdin.pipe(child.stdin);
|
|
310
|
+
process.stdin.once("end", () => child.stdin?.end());
|
|
311
|
+
let exiting = false;
|
|
312
|
+
const forward = (signal) => {
|
|
313
|
+
if (exiting) return;
|
|
314
|
+
exiting = true;
|
|
315
|
+
child.kill(signal);
|
|
316
|
+
};
|
|
317
|
+
process.once("SIGINT", () => forward("SIGINT"));
|
|
318
|
+
process.once("SIGTERM", () => forward("SIGTERM"));
|
|
319
|
+
process.stdin.once("end", () => forward("SIGTERM"));
|
|
320
|
+
return await new Promise((resolve) => {
|
|
321
|
+
child.once("error", (error) => {
|
|
322
|
+
io.err(paint.red(` 启动 Windows MCP 失败:${error.message}`));
|
|
323
|
+
resolve(1);
|
|
324
|
+
});
|
|
325
|
+
child.once("exit", (code, signal) => {
|
|
326
|
+
if (signal) io.err(paint.gray(` Windows MCP 因信号 ${signal} 退出`));
|
|
327
|
+
resolve(code ?? (signal ? 1 : 0));
|
|
328
|
+
});
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
export { runMcpHost };
|
|
@@ -3,18 +3,19 @@ import { a as search, i as getFormatDoc, n as apiDocsAvailable, r as getEntry }
|
|
|
3
3
|
import { a as requireConnected, i as execute, n as bridgeErrorHint, o as selectWindow, r as discover, s as windows, t as BridgeClientError } from "./client-_LVz5Zg0.mjs";
|
|
4
4
|
import { t as packageVersion } from "./version-B39-elun.mjs";
|
|
5
5
|
import { c as BRIDGE_MAX_CODE_BYTES, h as BRIDGE_SERVICE_ID } from "./protocol-B4UcGrGa.mjs";
|
|
6
|
-
import { a as cdpInputActionSchema, c as listDocuments, d as detectState, f as normalizeState, i as screenshotToFile, l as openDocument, o as sendCdpInput, s as activeDocument, t as classifyEval, u as Board } from "./sideEffects-
|
|
7
|
-
import {
|
|
8
|
-
import { a as evaluateInContext, l as redact, o as planEval } from "./session-
|
|
9
|
-
import { i as listTargets } from "./targets-
|
|
10
|
-
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-
|
|
6
|
+
import { a as cdpInputActionSchema, c as listDocuments, d as detectState, f as normalizeState, i as screenshotToFile, l as openDocument, o as sendCdpInput, s as activeDocument, t as classifyEval, u as Board } from "./sideEffects-Ds_T-_B4.mjs";
|
|
7
|
+
import { g as versionWebSocketUrl, h as versionBrowser, m as resolveEndpoint, o as discover$1, r as attributionOf, s as endpointUrl, u as parsePortRange, v as asCdpError } from "./discover-DmRYlAlR.mjs";
|
|
8
|
+
import { a as evaluateInContext, l as redact, o as planEval } from "./session-AQbRX6Ys.mjs";
|
|
9
|
+
import { i as listTargets } from "./targets-8LBEgvbq.mjs";
|
|
10
|
+
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";
|
|
11
|
+
import { c as liveStrategy } from "./environment-BegP0n2N.mjs";
|
|
11
12
|
import { C as compare, D as summarize, c as runSingle, ft as ensureSafeOutputDir, gt as safeWriteText, ht as safeWriteJson, lt as ProjectError, n as checkConsistency, o as inspectProject, r as collect, s as runDiff, t as analyzeSummary } from "./analyze-TRlZx-Jv.mjs";
|
|
12
13
|
import { D as documentFiles, F as resolveProjectPath, G as readDocumentFile, M as loadEprj3Project, Y as reduceDocSection, g as netlistProject, i as EPRJ3_GATE_NAMES, j as inspectEprj3Project, m as runEprj3Script, n as EPRJ3_EDIT_OPS, r as EPRJ3_GATES, s as eprj3GateArgs, t as validateEprj3Project, u as isEprj3EditOp } from "./validate-COx5r3o4.mjs";
|
|
13
14
|
import { a as getPrimitive, i as getFormatLog, o as listTypes, r as getExample } from "./knowledge-CX8Hrnoe.mjs";
|
|
14
15
|
import { i as validateLine, r as validateFormat } from "./record-CHXWiMWA.mjs";
|
|
15
16
|
import { A as listSimSidecarScripts, At as generateNetlist, Cn as SimError, D as viaParasitics, Et as validateIr, F as simSidecarDir, I as readNetlistFile, L as runSimulation, Ot as buildPinNetTable, P as runSimSidecar, T as traceParams, bt as loadSimIr, c as touchstoneMetrics, et as parseRawFile, hn as loadSimConfig, j as probePython, m as Stackup, mt as probeNgspice, o as parseTouchstone, rt as computeMetrics, tt as plotsToCsv, vt as fromEpro2File } from "./touchstone-D4Fdg4Om.mjs";
|
|
16
17
|
import { i as listAssetFiles, r as assetsDir, s as readAssetText, t as assetExists } from "./assets-D48xh-kr.mjs";
|
|
17
|
-
import "./main-
|
|
18
|
+
import "./main-B3aaKvqY.mjs";
|
|
18
19
|
import path from "node:path";
|
|
19
20
|
import { existsSync, readFileSync } from "node:fs";
|
|
20
21
|
import { z } from "zod";
|
|
@@ -1090,7 +1091,7 @@ const bridgeTools = [
|
|
|
1090
1091
|
const endpoint = await discover({
|
|
1091
1092
|
portFirst,
|
|
1092
1093
|
portLast,
|
|
1093
|
-
host: ctx.cfg.bridge.
|
|
1094
|
+
host: ctx.cfg.bridge.host,
|
|
1094
1095
|
signal: ctx.signal
|
|
1095
1096
|
});
|
|
1096
1097
|
if (!endpoint) return {
|
|
@@ -1126,12 +1127,12 @@ const bridgeTools = [
|
|
|
1126
1127
|
const endpoint = await discover({
|
|
1127
1128
|
portFirst,
|
|
1128
1129
|
portLast,
|
|
1129
|
-
host: ctx.cfg.bridge.
|
|
1130
|
+
host: ctx.cfg.bridge.host,
|
|
1130
1131
|
signal: ctx.signal
|
|
1131
1132
|
});
|
|
1132
1133
|
if (!endpoint) throw new BridgeClientError("NO_BRIDGE", `端口区间 ${portFirst}-${portLast} 里没有 ${BRIDGE_SERVICE_ID}`);
|
|
1133
1134
|
const list = await windows(endpoint.port, {
|
|
1134
|
-
host: ctx.cfg.bridge.
|
|
1135
|
+
host: ctx.cfg.bridge.host,
|
|
1135
1136
|
signal: ctx.signal
|
|
1136
1137
|
});
|
|
1137
1138
|
return {
|
|
@@ -1159,12 +1160,12 @@ const bridgeTools = [
|
|
|
1159
1160
|
const endpoint = await discover({
|
|
1160
1161
|
portFirst,
|
|
1161
1162
|
portLast,
|
|
1162
|
-
host: ctx.cfg.bridge.
|
|
1163
|
+
host: ctx.cfg.bridge.host,
|
|
1163
1164
|
signal: ctx.signal
|
|
1164
1165
|
});
|
|
1165
1166
|
if (!endpoint) throw new BridgeClientError("NO_BRIDGE", `端口区间 ${portFirst}-${portLast} 里没有 ${BRIDGE_SERVICE_ID}`);
|
|
1166
1167
|
const result = await selectWindow(endpoint.port, windowId, {
|
|
1167
|
-
host: ctx.cfg.bridge.
|
|
1168
|
+
host: ctx.cfg.bridge.host,
|
|
1168
1169
|
signal: ctx.signal
|
|
1169
1170
|
});
|
|
1170
1171
|
return {
|
|
@@ -1204,18 +1205,18 @@ const bridgeTools = [
|
|
|
1204
1205
|
const endpoint = await discover({
|
|
1205
1206
|
portFirst,
|
|
1206
1207
|
portLast,
|
|
1207
|
-
host: ctx.cfg.bridge.
|
|
1208
|
+
host: ctx.cfg.bridge.host,
|
|
1208
1209
|
signal: ctx.signal
|
|
1209
1210
|
});
|
|
1210
1211
|
if (!endpoint) throw new BridgeClientError("NO_BRIDGE", `端口区间 ${portFirst}-${portLast} 里没有 ${BRIDGE_SERVICE_ID}`);
|
|
1211
1212
|
await requireConnected(endpoint.port, {
|
|
1212
|
-
host: ctx.cfg.bridge.
|
|
1213
|
+
host: ctx.cfg.bridge.host,
|
|
1213
1214
|
signal: ctx.signal
|
|
1214
1215
|
});
|
|
1215
1216
|
const result = await execute(endpoint.port, code, {
|
|
1216
1217
|
windowId,
|
|
1217
1218
|
timeoutMs,
|
|
1218
|
-
host: ctx.cfg.bridge.
|
|
1219
|
+
host: ctx.cfg.bridge.host,
|
|
1219
1220
|
signal: ctx.signal
|
|
1220
1221
|
});
|
|
1221
1222
|
return {
|
|
@@ -1295,7 +1296,8 @@ const cdpDiscoverTool = defineTool({
|
|
|
1295
1296
|
description: "发现并验证本机立创EDA专业版的 CDP 端点(只读)。前置条件:客户端必须用 `lceda-connect cdp start` 带调试端口启动(已运行的实例无法事后追加端口)。判定标准是 /json/version 同时返回 Browser 与 Protocol-Version;uuidMatch 表示 profile 端口文件里的 browser uuid 与当前实例是否一致,优先使用 uuid 匹配的端点。没有任何可用端点时返回 CDP_NOT_FOUND 错误,details 里带各候选端口的诊断明细。",
|
|
1296
1297
|
input: {
|
|
1297
1298
|
port: PORT_FIELD,
|
|
1298
|
-
scan: z.string().optional().describe("附加扫描的端口区间,形如 9200-9300(一般不需要)")
|
|
1299
|
+
scan: z.string().optional().describe("附加扫描的端口区间,形如 9200-9300(一般不需要)"),
|
|
1300
|
+
host: z.string().optional().describe("探测地址;默认取当前环境推导(WSL2 下通常是 Windows 宿主地址)")
|
|
1299
1301
|
},
|
|
1300
1302
|
annotations: {
|
|
1301
1303
|
readOnlyHint: true,
|
|
@@ -1303,20 +1305,36 @@ const cdpDiscoverTool = defineTool({
|
|
|
1303
1305
|
},
|
|
1304
1306
|
handler: async (args, ctx) => {
|
|
1305
1307
|
try {
|
|
1306
|
-
const
|
|
1308
|
+
const hosts = args.host ? [args.host] : ctx.cfg.cdp.hosts;
|
|
1309
|
+
let host = hosts[0] ?? "127.0.0.1";
|
|
1310
|
+
let output = await discover$1(host, {
|
|
1307
1311
|
port: portArg(args, ctx),
|
|
1308
1312
|
scan: parseScan(args.scan),
|
|
1309
1313
|
env: ctx.env,
|
|
1310
|
-
signal: ctx.signal
|
|
1314
|
+
signal: ctx.signal,
|
|
1315
|
+
allowedHosts: ctx.cfg.cdp.hosts
|
|
1311
1316
|
});
|
|
1317
|
+
for (const candidate of hosts.slice(1)) {
|
|
1318
|
+
if (output.usable.length > 0) break;
|
|
1319
|
+
host = candidate;
|
|
1320
|
+
output = await discover$1(host, {
|
|
1321
|
+
port: portArg(args, ctx),
|
|
1322
|
+
scan: parseScan(args.scan),
|
|
1323
|
+
env: ctx.env,
|
|
1324
|
+
signal: ctx.signal,
|
|
1325
|
+
allowedHosts: ctx.cfg.cdp.hosts
|
|
1326
|
+
});
|
|
1327
|
+
}
|
|
1312
1328
|
const best = output.usable[0] ?? null;
|
|
1313
|
-
if (!best) throw new ToolError("CDP_NOT_FOUND", "
|
|
1329
|
+
if (!best) throw new ToolError("CDP_NOT_FOUND", `候选地址(${hosts.join(" → ")})的端口都不响应 /json/version:不像 CDP,或端口文件已经过期。请确认客户端是用 \`lceda-connect cdp start\` 带调试端口启动的。`, {
|
|
1314
1330
|
livePorts: output.livePorts,
|
|
1331
|
+
hosts,
|
|
1315
1332
|
results: output.results.map(discoverView)
|
|
1316
1333
|
});
|
|
1317
1334
|
return {
|
|
1318
1335
|
found: true,
|
|
1319
|
-
|
|
1336
|
+
host,
|
|
1337
|
+
endpoint: endpointUrl(host, best.port),
|
|
1320
1338
|
browser: redact(versionBrowser(best.version)) || null,
|
|
1321
1339
|
webSocketDebuggerUrl: redact(versionWebSocketUrl(best.version)) || null,
|
|
1322
1340
|
livePorts: output.livePorts,
|
|
@@ -1680,6 +1698,9 @@ function execContext(args, ctx) {
|
|
|
1680
1698
|
return createDefaultExecContext({
|
|
1681
1699
|
env: ctx.env,
|
|
1682
1700
|
cdpPort: ctx.cfg.cdp.port,
|
|
1701
|
+
cdpHosts: ctx.cfg.cdp.hosts,
|
|
1702
|
+
bridgeHost: ctx.cfg.bridge.host,
|
|
1703
|
+
allowedHosts: ctx.cfg.cdp.hosts,
|
|
1683
1704
|
bridgePortFirst: ctx.cfg.bridge.portFirst,
|
|
1684
1705
|
bridgePortLast: ctx.cfg.bridge.portLast,
|
|
1685
1706
|
match: args.match,
|
|
@@ -1696,7 +1717,7 @@ const OUT_DIR_FIELD = z.string().optional().describe("可选:把 result.json
|
|
|
1696
1717
|
const edaTools = [
|
|
1697
1718
|
defineTool({
|
|
1698
1719
|
name: "lceda_status",
|
|
1699
|
-
description: "
|
|
1720
|
+
description: "双通道环境自检(只读):先报告执行环境(windows-native / wsl2 / linux-native / macos-native、WSL 网络模式、客户端实例位置 host/vm、Windows 宿主地址、客户端可执行文件),再检查 bridge 服务与 CDP 端点,返回 channel_state 四态(both / bridge-only / cdp-only / none)、逐项 checks(含 reason_code 与 hint)、live_strategy 与 next_action。WSL2 NAT 下 bridge 跨命名空间不可达会报 cross_os_loopback 并给出可执行建议。只做探测,不安装、不登录、不改配置、不启动进程。退出码口径:0 双通道 / 1 单通道 / 2 都不可用。结论来自实际探测,不是猜测;某条通道报告 partial 时不要把它当作可用通道继续写操作。",
|
|
1700
1721
|
input: {},
|
|
1701
1722
|
annotations: {
|
|
1702
1723
|
readOnlyHint: true,
|
|
@@ -1705,7 +1726,14 @@ const edaTools = [
|
|
|
1705
1726
|
handler: async (_args, ctx) => {
|
|
1706
1727
|
try {
|
|
1707
1728
|
return {
|
|
1708
|
-
...await checkEnvironment({
|
|
1729
|
+
...await checkEnvironment({
|
|
1730
|
+
env: ctx.env,
|
|
1731
|
+
environment: ctx.cfg.environment,
|
|
1732
|
+
strategy: liveStrategy(ctx.cfg.environment),
|
|
1733
|
+
clientExe: ctx.cfg.client.exe,
|
|
1734
|
+
cdpHosts: ctx.cfg.cdp.hosts,
|
|
1735
|
+
bridgeHost: ctx.cfg.bridge.host
|
|
1736
|
+
}),
|
|
1709
1737
|
capability_map: capabilitySummary()
|
|
1710
1738
|
};
|
|
1711
1739
|
} catch (error) {
|
|
@@ -2112,7 +2140,7 @@ const skillDocsTool = defineTool({
|
|
|
2112
2140
|
});
|
|
2113
2141
|
const coreTools = [defineTool({
|
|
2114
2142
|
name: "lceda_info",
|
|
2115
|
-
description: "返回 lceda-connect 的版本、assets
|
|
2143
|
+
description: "返回 lceda-connect 的版本、assets 位置、执行环境与已注册的工具清单,用来确认 MCP 服务是否就绪。",
|
|
2116
2144
|
input: {},
|
|
2117
2145
|
output: {
|
|
2118
2146
|
name: z.string(),
|
|
@@ -2121,7 +2149,23 @@ const coreTools = [defineTool({
|
|
|
2121
2149
|
platform: z.string(),
|
|
2122
2150
|
node: z.string(),
|
|
2123
2151
|
tools: z.array(z.string()),
|
|
2124
|
-
toolsets: z.record(z.string(), z.array(z.string()))
|
|
2152
|
+
toolsets: z.record(z.string(), z.array(z.string())),
|
|
2153
|
+
environment: z.object({
|
|
2154
|
+
kind: z.string(),
|
|
2155
|
+
hostOs: z.string(),
|
|
2156
|
+
distro: z.string().nullable(),
|
|
2157
|
+
networkingMode: z.string(),
|
|
2158
|
+
windowsHost: z.string().nullable(),
|
|
2159
|
+
clientLocations: z.array(z.string()),
|
|
2160
|
+
explicit: z.boolean(),
|
|
2161
|
+
warnings: z.array(z.string())
|
|
2162
|
+
}).optional(),
|
|
2163
|
+
clientExe: z.object({
|
|
2164
|
+
status: z.string(),
|
|
2165
|
+
path: z.string().nullable(),
|
|
2166
|
+
location: z.string(),
|
|
2167
|
+
source: z.string()
|
|
2168
|
+
}).nullable().optional()
|
|
2125
2169
|
},
|
|
2126
2170
|
annotations: {
|
|
2127
2171
|
readOnlyHint: true,
|
|
@@ -2134,7 +2178,23 @@ const coreTools = [defineTool({
|
|
|
2134
2178
|
platform: process.platform,
|
|
2135
2179
|
node: process.version,
|
|
2136
2180
|
tools: [...ctx.toolNames ?? []],
|
|
2137
|
-
toolsets: Object.fromEntries(Object.entries(ctx.toolsets ?? {}).map(([key, names]) => [key, [...names]]))
|
|
2181
|
+
toolsets: Object.fromEntries(Object.entries(ctx.toolsets ?? {}).map(([key, names]) => [key, [...names]])),
|
|
2182
|
+
environment: {
|
|
2183
|
+
kind: ctx.cfg.environment.kind,
|
|
2184
|
+
hostOs: ctx.cfg.environment.hostOs,
|
|
2185
|
+
distro: ctx.cfg.environment.distro,
|
|
2186
|
+
networkingMode: ctx.cfg.environment.networkingMode,
|
|
2187
|
+
windowsHost: ctx.cfg.environment.windowsHost,
|
|
2188
|
+
clientLocations: [...ctx.cfg.environment.clientLocations],
|
|
2189
|
+
explicit: ctx.cfg.environment.explicit,
|
|
2190
|
+
warnings: [...ctx.cfg.environment.warnings]
|
|
2191
|
+
},
|
|
2192
|
+
clientExe: ctx.cfg.client.exe ? {
|
|
2193
|
+
status: ctx.cfg.client.exe.status,
|
|
2194
|
+
path: ctx.cfg.client.exe.path,
|
|
2195
|
+
location: ctx.cfg.client.exe.location,
|
|
2196
|
+
source: ctx.cfg.client.exe.source
|
|
2197
|
+
} : null
|
|
2138
2198
|
})
|
|
2139
2199
|
}), skillDocsTool];
|
|
2140
2200
|
// src/mcp/registry.ts
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { r as toolsForEnv } from "./registry-3WTFCZsR.mjs";
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { i as listAssetFiles, s as readAssetText } from "./assets-D48xh-kr.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { i as loadConfig } from "./config-BKbwyvsG.mjs";
|
|
3
3
|
import { pt as resolveMcpWritePath } from "./analyze-TRlZx-Jv.mjs";
|
|
4
4
|
import { t as packageVersion } from "./version-B39-elun.mjs";
|
|
5
|
-
import "./
|
|
6
|
-
import { i as toolsetsForTools, r as toolsForEnv } from "./registry-Dmti2u6s.mjs";
|
|
5
|
+
import { i as toolsetsForTools, r as toolsForEnv } from "./registry-3WTFCZsR.mjs";
|
|
7
6
|
import { r as normalizeToolContext, t as ToolError } from "./types-D5d7ZRYF.mjs";
|
|
8
7
|
import os from "node:os";
|
|
9
8
|
import path from "node:path";
|
|
@@ -12,7 +11,6 @@ import { fileURLToPath } from "node:url";
|
|
|
12
11
|
import { randomBytes } from "node:crypto";
|
|
13
12
|
import { RootsListChangedNotificationSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
14
13
|
import { McpServer, ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
15
|
-
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
16
14
|
// src/mcp/result.ts
|
|
17
15
|
/** 单个工具结果文本的上限。超出时完整落盘并返回资源 URI。 */
|
|
18
16
|
const MAX_RESULT_BYTES = 65536;
|
|
@@ -313,14 +311,11 @@ function createServer(options = {}) {
|
|
|
313
311
|
});
|
|
314
312
|
return server;
|
|
315
313
|
}
|
|
316
|
-
/**
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
const transport = new StdioServerTransport();
|
|
323
|
-
await server.connect(transport);
|
|
324
|
-
process.stderr.write(`[${SERVER_NAME}] MCP 服务已在 stdio 上就绪 (v${packageVersion()})\n`);
|
|
314
|
+
/**
|
|
315
|
+
* 组装工厂:传输适配器只依赖这个函数,不依赖 createServer 的细节。
|
|
316
|
+
* 每次调用必须返回独立的 McpServer(HTTP 每个 session 一个)。
|
|
317
|
+
*/
|
|
318
|
+
function createServerFactory(options = {}) {
|
|
319
|
+
return () => createServer(options);
|
|
325
320
|
}
|
|
326
|
-
export {
|
|
321
|
+
export { createServer as n, createServerFactory as r, SERVER_NAME as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { _ as CdpError, b as coerceText, f as requireAllowedHost, n as DEFAULT_CDP_PORT, y as clipText } from "./discover-DmRYlAlR.mjs";
|
|
2
2
|
import { t as ToolError } from "./types-D5d7ZRYF.mjs";
|
|
3
3
|
import { createHash, randomBytes } from "node:crypto";
|
|
4
4
|
import net from "node:net";
|
|
@@ -672,7 +672,7 @@ var CdpSession = class CdpSession {
|
|
|
672
672
|
}
|
|
673
673
|
if (url.protocol !== "ws:") throw new CdpError("WS_PROTOCOL", `只支持 ws:// 回环地址,收到 ${url.protocol}//${url.host}`, { exitCode: 3 });
|
|
674
674
|
const host = url.hostname.replace(/^\[|\]$/g, "");
|
|
675
|
-
|
|
675
|
+
requireAllowedHost(host, options.allowedHosts);
|
|
676
676
|
const port = url.port ? Number.parseInt(url.port, 10) : DEFAULT_CDP_PORT;
|
|
677
677
|
const timeoutMs = options.timeoutMs ?? cdpTimeoutMs(options.env ?? process.env);
|
|
678
678
|
const ws = await WsClient.connect({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { _ as CdpError, b as coerceText, m as resolveEndpoint, t as DEFAULT_CDP_HOST, y as clipText } from "./discover-DmRYlAlR.mjs";
|
|
2
2
|
import { t as ToolError } from "./types-D5d7ZRYF.mjs";
|
|
3
|
-
import { i as evaluateExpression, r as apiExpression, s as UI_SHELL_MARKERS, t as CdpSession } from "./session-
|
|
4
|
-
import { i as listTargets } from "./targets-
|
|
3
|
+
import { i as evaluateExpression, r as apiExpression, s as UI_SHELL_MARKERS, t as CdpSession } from "./session-AQbRX6Ys.mjs";
|
|
4
|
+
import { i as listTargets } from "./targets-8LBEgvbq.mjs";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import fs from "node:fs";
|
|
7
7
|
import { z } from "zod";
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { t as packageVersion } from "./version-B39-elun.mjs";
|
|
2
|
+
import { r as createServerFactory, t as SERVER_NAME } from "./server-zw6t1Pmk.mjs";
|
|
3
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
|
+
// src/mcp/transports/stdio.ts
|
|
5
|
+
async function startStdioTransport(options) {
|
|
6
|
+
const server = (options.serverFactory ?? createServerFactory(options))();
|
|
7
|
+
const transport = new StdioServerTransport();
|
|
8
|
+
await server.connect(transport);
|
|
9
|
+
(options.log ?? ((line) => process.stderr.write(`${line}\n`)))(`[${SERVER_NAME}] MCP 服务已在 stdio 上就绪 (v${packageVersion()})`);
|
|
10
|
+
let closed = false;
|
|
11
|
+
return {
|
|
12
|
+
kind: "stdio",
|
|
13
|
+
close: async () => {
|
|
14
|
+
if (closed) return;
|
|
15
|
+
closed = true;
|
|
16
|
+
await server.close();
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/** 兼容旧入口:连接后即返回(进程由 stdio 传输保持存活)。 */
|
|
21
|
+
async function serveStdio(env = process.env, toolsets) {
|
|
22
|
+
await startStdioTransport({
|
|
23
|
+
env,
|
|
24
|
+
toolsets
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
export { startStdioTransport as n, serveStdio as t };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as serveStdio } from "./stdio-BZPlcfDR.mjs";
|