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.
Files changed (49) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +111 -45
  3. package/dist/{analyze-DBkWgG82.mjs → analyze-TRlZx-Jv.mjs} +2 -190
  4. package/dist/{cli-B3GGyoP_.mjs → cli-1_urvve3.mjs} +5 -3
  5. package/dist/{cli-BegYbK44.mjs → cli-C8-HjAP0.mjs} +2 -2
  6. package/dist/cli-CHbcaMwS.mjs +1 -0
  7. package/dist/cli-CXk5pvVm.mjs +1253 -0
  8. package/dist/cli-CZEoeuFW.mjs +1 -0
  9. package/dist/{cli-DphIx1EQ.mjs → cli-CZmNLW3Q.mjs} +1 -1
  10. package/dist/{cli-BekOvZjB.mjs → cli-DFqBHofJ.mjs} +19 -3
  11. package/dist/cli-bridge-server.mjs +1 -1
  12. package/dist/cli-bridge.mjs +1 -1
  13. package/dist/cli-cdp.mjs +1 -1
  14. package/dist/cli-mcp.mjs +1 -1
  15. package/dist/cli.mjs +1 -1
  16. package/dist/config-BKbwyvsG.mjs +516 -0
  17. package/dist/{discover-D4ouuCrn.mjs → discover-DmRYlAlR.mjs} +13 -90
  18. package/dist/environment-BegP0n2N.mjs +439 -0
  19. package/dist/environment-Clx1-nDW.mjs +146 -0
  20. package/dist/http-Cdp6S2rm.mjs +366 -0
  21. package/dist/http-D7sYy2y4.mjs +1 -0
  22. package/dist/index.d.mts +226 -6
  23. package/dist/index.mjs +12 -9
  24. package/dist/{main-CzMqMptH.mjs → main-B3aaKvqY.mjs} +695 -90
  25. package/dist/mcpHost-CRoN6MnG.mjs +331 -0
  26. package/dist/{registry-DaqVJuvF.mjs → registry-3WTFCZsR.mjs} +86 -25
  27. package/dist/registry-DdJ8LEdd.mjs +1 -0
  28. package/dist/{server-qYlcXfzp.mjs → server-zw6t1Pmk.mjs} +10 -15
  29. package/dist/{targets-DYfgkrq3.mjs → session-AQbRX6Ys.mjs} +3 -37
  30. package/dist/{sideEffects-D33hMchc.mjs → sideEffects-Ds_T-_B4.mjs} +3 -2
  31. package/dist/stdio-BZPlcfDR.mjs +27 -0
  32. package/dist/stdio-Du1oLqfJ.mjs +1 -0
  33. package/dist/targets-8LBEgvbq.mjs +36 -0
  34. package/dist/term-DlGIoccA.mjs +27 -0
  35. package/dist/{touchstone-DOhfmSNh.mjs → touchstone-D4Fdg4Om.mjs} +1 -1
  36. package/dist/{verbs-CD4ZM9Es.mjs → verbs-DjQQTL2k.mjs} +191 -53
  37. package/dist/windowsHost-CTZXMA8D.mjs +1 -0
  38. package/dist/windowsHost-CtRidgJp.mjs +309 -0
  39. package/dist/zip-CAd_yYte.mjs +190 -0
  40. package/docs/architecture.md +81 -0
  41. package/docs/environments.md +175 -0
  42. package/docs/extensions.md +207 -0
  43. package/docs/quickstart.md +59 -4
  44. package/docs/transports.md +189 -0
  45. package/package.json +6 -2
  46. package/dist/cli-BqILMvnF.mjs +0 -1
  47. package/dist/cli-BzrDKC7x.mjs +0 -1
  48. package/dist/registry-5K1G1XmC.mjs +0 -1
  49. package/dist/server-DNMAlzZJ.mjs +0 -1
@@ -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";
@@ -0,0 +1,36 @@
1
+ import { c as fetchJson } from "./discover-DmRYlAlR.mjs";
2
+ // src/cdp/targets.ts
3
+ /** `GET /json/list`;拿不到或返回不是数组时返回空列表(与源仓库一致)。 */
4
+ async function listTargets(host, port, timeoutMs, signal) {
5
+ const payload = await fetchJson(host, port, "/json/list", timeoutMs, signal);
6
+ if (!Array.isArray(payload)) return [];
7
+ return payload.filter((item) => item !== null && typeof item === "object" && !Array.isArray(item));
8
+ }
9
+ /** 打开 Page 域并取当前页面的 frame 树。 */
10
+ async function fetchFrameTree(session) {
11
+ await session.call("Page.enable");
12
+ return (await session.call("Page.getFrameTree")).frameTree ?? null;
13
+ }
14
+ /** 深度优先压平 frame 树;name 缺失时用 `(main)` 占位(源仓库口径)。 */
15
+ function flattenFrameTree(tree, depth = 0) {
16
+ if (!tree) return [];
17
+ const frame = tree.frame ?? {};
18
+ const rows = [{
19
+ depth,
20
+ name: typeof frame.name === "string" && frame.name !== "" ? frame.name : "(main)",
21
+ url: typeof frame.url === "string" && frame.url !== "" ? frame.url : "about:blank"
22
+ }];
23
+ for (const child of tree.childFrames ?? []) rows.push(...flattenFrameTree(child, depth + 1));
24
+ return rows;
25
+ }
26
+ /** 每行 frame 输出两行文本:`- name` 与缩进后的 url(与源仓库 `frames` 同形)。 */
27
+ function formatFrameTree(rows) {
28
+ const lines = [];
29
+ for (const row of rows) {
30
+ const indent = " ".repeat(row.depth);
31
+ lines.push(`${indent}- ${row.name}`);
32
+ lines.push(`${indent} ${row.url}`);
33
+ }
34
+ return lines;
35
+ }
36
+ export { listTargets as i, flattenFrameTree as n, formatFrameTree as r, fetchFrameTree as t };
@@ -0,0 +1,27 @@
1
+ // src/core/term.ts
2
+ /** 极简 ANSI 着色:非 TTY / NO_COLOR / --json 场景自动降级为纯文本。 */
3
+ const COLOR_ENABLED = (() => {
4
+ const env = process.env;
5
+ if (env.NO_COLOR !== void 0 && env.NO_COLOR !== "") return false;
6
+ if (env.FORCE_COLOR !== void 0 && env.FORCE_COLOR !== "0") return true;
7
+ return Boolean(process.stdout.isTTY);
8
+ })();
9
+ function painter(open, close) {
10
+ return (text) => COLOR_ENABLED ? `\u001B[${open}m${text}\u001B[${close}m` : text;
11
+ }
12
+ const paint = {
13
+ cyan: painter(36, 39),
14
+ green: painter(32, 39),
15
+ yellow: painter(33, 39),
16
+ red: painter(31, 39),
17
+ gray: painter(90, 39),
18
+ white: painter(97, 39),
19
+ darkRed: painter(31, 39),
20
+ bold: painter(1, 22),
21
+ dim: painter(2, 22)
22
+ };
23
+ /** 中文对齐时 `-` 分隔线(按显示宽度无关的固定长度即可)。 */
24
+ function hr(width = 58) {
25
+ return "-".repeat(width);
26
+ }
27
+ export { paint as n, hr as t };
@@ -1,7 +1,7 @@
1
1
  import { n as assetPath } from "./assets-D48xh-kr.mjs";
2
2
  import { t as run } from "./exec-FuC8m-_m.mjs";
3
3
  import { t as ToolError } from "./types-D5d7ZRYF.mjs";
4
- import { Ct as safeWriteText, St as safeWriteJson, r as collect, vt as assertSafeWorkDirEntries, xt as safeWriteFile, yt as ensureSafeOutputDir } from "./analyze-DBkWgG82.mjs";
4
+ import { dt as assertSafeWorkDirEntries, ft as ensureSafeOutputDir, gt as safeWriteText, ht as safeWriteJson, mt as safeWriteFile, r as collect } from "./analyze-TRlZx-Jv.mjs";
5
5
  import os from "node:os";
6
6
  import path from "node:path";
7
7
  import { existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
@@ -1,9 +1,11 @@
1
- import { _ as asCdpError, a as defaultPortFromEnv, i as browserUuid, m as versionBrowser, o as discover, p as resolveEndpoint } from "./discover-D4ouuCrn.mjs";
1
+ import { c as liveStrategy, n as cdpProbeHosts, r as describeEnvironment } from "./environment-BegP0n2N.mjs";
2
2
  import { o as readAssetJson } from "./assets-D48xh-kr.mjs";
3
3
  import { t as packageVersion } from "./version-B39-elun.mjs";
4
+ import { a as defaultPortFromEnv, c as fetchJson, h as versionBrowser, i as browserUuid, m as resolveEndpoint, o as discover, v as asCdpError } from "./discover-DmRYlAlR.mjs";
4
5
  import "./protocol-B4UcGrGa.mjs";
5
6
  import { i as execute, r as discover$1, s as windows, t as BridgeClientError } from "./client-_LVz5Zg0.mjs";
6
- import { a as CdpSession, c as evaluateExpression, i as listTargets } from "./targets-DYfgkrq3.mjs";
7
+ import { i as evaluateExpression, t as CdpSession } from "./session-AQbRX6Ys.mjs";
8
+ import { i as listTargets } from "./targets-8LBEgvbq.mjs";
7
9
  import path from "node:path";
8
10
  import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
9
11
  import { createHash } from "node:crypto";
@@ -188,7 +190,7 @@ function bridgeCheckFromEndpoint(endpoint, host) {
188
190
  hint: "在客户端加载并启用 run-api-gateway 扩展"
189
191
  };
190
192
  }
191
- /** 探测本机 bridge。找不到是 missing;身份/协议错误是 unavailable。 */
193
+ /** 探测 bridge。找不到是 missing;身份/协议错误是 unavailable。 */
192
194
  async function probeBridgeChannel(options = {}) {
193
195
  const host = options.host ?? "127.0.0.1";
194
196
  try {
@@ -224,6 +226,7 @@ function cdpCheckFromOutput(output, host) {
224
226
  reason_code: "ok",
225
227
  detail: `${host}:${best.port} · ${browser || "unknown"}`,
226
228
  hint: "",
229
+ port: best.port,
227
230
  version: {
228
231
  browser: browser || null,
229
232
  protocol: best.version !== null && typeof best.version === "object" && typeof best.version["Protocol-Version"] === "string" ? best.version["Protocol-Version"] : null,
@@ -231,27 +234,105 @@ function cdpCheckFromOutput(output, host) {
231
234
  }
232
235
  };
233
236
  }
234
- /** 探测 CDP 端点。默认先看 profile 的端口文件,再试 9222 / EASYEDA_CDP_PORT。 */
237
+ const EASYEDA_TARGET_MARKERS = [
238
+ /嘉立创\s*EDA/i,
239
+ /EasyEDA/i,
240
+ /easyeda/i,
241
+ /pro\.lceda\.cn/i,
242
+ /client\/editor/i
243
+ ];
244
+ /**
245
+ * 判断 CDP 端口背后是不是嘉立创 EDA。
246
+ * `/json/version` 只能证明“这是 Chromium”,任何 Electron 应用都满足;要看 target 标题/URL。
247
+ * 目标列表为空时返回 null(应用刚启动、还没建页面,不做判断)。
248
+ */
249
+ function identifyCdpApplication(targets) {
250
+ if (!Array.isArray(targets)) return null;
251
+ const pages = targets.filter((item) => item !== null && typeof item === "object");
252
+ if (pages.length === 0) return null;
253
+ for (const page of pages) {
254
+ const title = typeof page.title === "string" ? page.title : "";
255
+ const url = typeof page.url === "string" ? page.url : "";
256
+ const text = `${title} ${url}`;
257
+ if (EASYEDA_TARGET_MARKERS.some((marker) => marker.test(text))) return {
258
+ match: true,
259
+ sample: title || url
260
+ };
261
+ }
262
+ const first = pages[0] ?? {};
263
+ return {
264
+ match: false,
265
+ sample: typeof first.title === "string" && first.title || typeof first.url === "string" && first.url || "(unknown target)"
266
+ };
267
+ }
268
+ async function probeCdpApplication(host, port, timeoutMs) {
269
+ try {
270
+ return identifyCdpApplication(await fetchJson(host, port, "/json/list", timeoutMs));
271
+ } catch {
272
+ return null;
273
+ }
274
+ }
275
+ /**
276
+ * 探测 CDP。按 hosts 顺序尝试,命中即返回;全部失败时把试过的地址写进 detail。
277
+ * 默认先看 profile 的端口文件,再试 9222 / EASYEDA_CDP_PORT。
278
+ */
235
279
  async function probeCdpChannel(options = {}) {
236
- const host = options.host ?? "127.0.0.1";
237
280
  const env = options.env ?? process.env;
238
281
  const port = options.port ?? defaultPortFromEnv(env) ?? 9222;
239
- try {
240
- return cdpCheckFromOutput(await discover(host, {
241
- port,
242
- scan: options.scan,
243
- timeoutMs: options.timeoutMs ?? CDP_PROBE_TIMEOUT_MS,
244
- env
245
- }), host);
246
- } catch (error) {
247
- return {
248
- id: "cdp-endpoint",
249
- status: "unavailable",
250
- reason_code: "probe_failed",
251
- detail: error instanceof Error ? error.message : String(error),
252
- hint: "只允许回环地址;确认客户端与端口配置"
253
- };
282
+ const hosts = options.hosts && options.hosts.length > 0 ? options.hosts : [options.host ?? "127.0.0.1"];
283
+ const tried = [];
284
+ let last = null;
285
+ for (const host of hosts) {
286
+ tried.push(host);
287
+ try {
288
+ const check = cdpCheckFromOutput(await discover(host, {
289
+ port,
290
+ scan: options.scan,
291
+ timeoutMs: options.timeoutMs ?? CDP_PROBE_TIMEOUT_MS,
292
+ env,
293
+ allowedHosts: hosts
294
+ }), host);
295
+ if (check.status === "ready") {
296
+ const port = Number(check.port ?? 0);
297
+ if (port > 0) {
298
+ const app = await probeCdpApplication(host, port, Math.min(options.timeoutMs ?? CDP_PROBE_TIMEOUT_MS, 1200));
299
+ if (app && !app.match) return {
300
+ ...check,
301
+ status: "partial",
302
+ reason_code: "wrong_application",
303
+ detail: `${host}:${port} · ${app.sample}`,
304
+ hint: "该 CDP 端口不是嘉立创EDA(可能是其它 Electron 应用);请用 --port 指定 EDA 的调试端口,或关闭占用程序后重启客户端",
305
+ hosts: tried
306
+ };
307
+ }
308
+ return {
309
+ ...check,
310
+ hosts: tried
311
+ };
312
+ }
313
+ last = check;
314
+ } catch (error) {
315
+ last = {
316
+ id: "cdp-endpoint",
317
+ status: "unavailable",
318
+ reason_code: "probe_failed",
319
+ detail: error instanceof Error ? error.message : String(error),
320
+ hint: `试过 ${tried.join(" → ")};确认客户端调试端口、Windows 防火墙或 WSL 网络模式`
321
+ };
322
+ }
254
323
  }
324
+ const base = last ?? {
325
+ id: "cdp-endpoint",
326
+ status: "missing",
327
+ reason_code: "service_unavailable",
328
+ detail: "",
329
+ hint: "彻底退出客户端后带 --remote-debugging-port=9222 启动;或用 lceda-connect cdp start"
330
+ };
331
+ return {
332
+ ...base,
333
+ detail: base.detail || `试过 ${tried.join(" → ")}`,
334
+ hosts: tried
335
+ };
255
336
  }
256
337
  function checkNodeVersion(nodeVersion) {
257
338
  const match = /^v?(\d+)\./.exec(nodeVersion.trim());
@@ -273,9 +354,18 @@ function versionFingerprint(bridge, cdp) {
273
354
  } : null
274
355
  };
275
356
  }
357
+ /** 是否是「WSL2 NAT + 客户端在 Windows 宿主」这种跨命名空间组合。 */
358
+ function isCrossOsHostEnvironment(info) {
359
+ if (!info || info.kind !== "wsl2") return false;
360
+ if (info.networkingMode === "mirrored") return false;
361
+ if (info.clientLocations.includes("vm")) return false;
362
+ return true;
363
+ }
276
364
  /** 完整自检;`probeBridge` / `probeCdp` 可注入,便于离线测试四态。 */
277
365
  async function checkEnvironment(options = {}) {
278
366
  const env = options.env ?? process.env;
367
+ const info = options.environment;
368
+ const strategy = options.strategy ?? (info ? liveStrategy(info) : void 0);
279
369
  const nodeItem = checkNodeVersion(options.nodeVersion ?? process.version);
280
370
  const cdpModuleItem = {
281
371
  id: "cdp-module",
@@ -284,9 +374,23 @@ async function checkEnvironment(options = {}) {
284
374
  detail: "内置 CDP 连接层(src/cdp)",
285
375
  hint: ""
286
376
  };
287
- const bridgeItem = options.probeBridge ? await options.probeBridge() : await probeBridgeChannel(options.bridge);
377
+ const bridgeHost = options.bridgeHost ?? options.bridge?.host ?? (info ? strategy?.bridgeHost ?? "127.0.0.1" : "127.0.0.1");
378
+ const cdpHosts = options.cdpHosts ?? (info ? cdpProbeHosts(info) : void 0) ?? (options.cdp?.hosts && options.cdp.hosts.length > 0 ? options.cdp.hosts : [options.cdp?.host ?? "127.0.0.1"]);
379
+ let bridgeItem = options.probeBridge ? await options.probeBridge() : await probeBridgeChannel({
380
+ ...options.bridge,
381
+ host: bridgeHost
382
+ });
383
+ if (!options.probeBridge && isCrossOsHostEnvironment(info)) {
384
+ if (bridgeItem.status === "missing" || bridgeItem.status === "unavailable") bridgeItem = {
385
+ ...bridgeItem,
386
+ reason_code: "cross_os_loopback",
387
+ hint: strategy?.nextAction ?? "bridge 只监听回环,跨 WSL/Windows 不可达;在 Windows 侧运行 MCP 或启用 WSL mirrored 网络"
388
+ };
389
+ }
288
390
  const cdpItem = options.probeCdp ? await options.probeCdp() : await probeCdpChannel({
289
391
  ...options.cdp,
392
+ host: cdpHosts[0],
393
+ hosts: cdpHosts,
290
394
  env
291
395
  });
292
396
  const bridgeOk = bridgeItem.status === "ready";
@@ -304,23 +408,27 @@ async function checkEnvironment(options = {}) {
304
408
  status = "needs_setup";
305
409
  }
306
410
  const sessionOk = bridgeOk || cdpOk;
307
- const checks = [
308
- nodeItem,
309
- cdpModuleItem,
310
- {
311
- id: "client-session",
312
- status: sessionOk ? "ready" : "missing",
313
- reason_code: sessionOk ? "ok" : "service_unavailable",
314
- detail: sessionOk ? "至少一条通道可见客户端" : "两条通道都看不到客户端",
315
- hint: sessionOk ? "" : "先启动客户端;bridge 需加载扩展,CDP 需带调试端口启动"
316
- },
317
- bridgeItem,
318
- cdpItem
319
- ];
411
+ const crossOs = isCrossOsHostEnvironment(info);
412
+ const checks = [];
413
+ if (info) checks.push({
414
+ id: "environment",
415
+ status: "ready",
416
+ reason_code: "ok",
417
+ detail: describeEnvironment(info),
418
+ hint: strategy?.summary ?? ""
419
+ });
420
+ checks.push(nodeItem, cdpModuleItem, {
421
+ id: "client-session",
422
+ status: sessionOk ? "ready" : "missing",
423
+ reason_code: sessionOk ? "ok" : crossOs ? "cross_os_loopback" : "service_unavailable",
424
+ detail: sessionOk ? "至少一条通道可见客户端" : crossOs ? "两条通道都看不到客户端(WSL2 与 Windows 宿主回环不互通)" : "两条通道都看不到客户端",
425
+ hint: sessionOk ? "" : crossOs ? strategy?.nextAction ?? "在 Windows 侧运行 MCP,或启用 WSL mirrored 网络" : "先启动客户端;bridge 需加载扩展,CDP 需带调试端口启动"
426
+ }, bridgeItem, cdpItem);
320
427
  const functionalDegradations = [];
321
428
  if (!bridgeOk) functionalDegradations.push("无官方 API 面:工程管理、制造导出不可用");
322
429
  if (!cdpOk) functionalDegradations.push("无视觉回路:截图类审查降级为人工截图");
323
- const nextAction = status === "ready" ? "两条通道都可用,直接进入路由决策" : status === "partial" ? "单通道可用:按路由表执行,跳过不可用通道相关的动词" : "先搭一条通道:bridge 需启动服务并加载扩展,或按 setup-guide 开 CDP 端口";
430
+ if (crossOs) functionalDegradations.push("WSL2 NAT:在线通道跨命名空间,bridge 不可达(CDP 仅在客户端监听非回环时可达)");
431
+ const nextAction = status === "ready" ? "两条通道都可用,直接进入路由决策" : status === "partial" ? "单通道可用:按路由表执行,跳过不可用通道相关的动词" : strategy?.nextAction ?? "先搭一条通道:bridge 需启动服务并加载扩展,或按 setup-guide 开 CDP 端口";
324
432
  return {
325
433
  status,
326
434
  channel_state: channelState,
@@ -350,7 +458,21 @@ async function checkEnvironment(options = {}) {
350
458
  functional_degradations: functionalDegradations,
351
459
  version_fingerprint: versionFingerprint(bridgeItem, cdpItem),
352
460
  next_action: nextAction,
353
- exit_code: status === "ready" ? 0 : status === "partial" ? 1 : 2
461
+ exit_code: status === "ready" ? 0 : status === "partial" ? 1 : 2,
462
+ ...info ? {
463
+ environment: info,
464
+ live_strategy: strategy ? {
465
+ summary: strategy.summary,
466
+ next_action: strategy.nextAction,
467
+ locations: strategy.locations
468
+ } : void 0
469
+ } : {},
470
+ client_exe: options.clientExe ? {
471
+ status: options.clientExe.status,
472
+ path: options.clientExe.path,
473
+ location: options.clientExe.location,
474
+ source: options.clientExe.source
475
+ } : null
354
476
  };
355
477
  }
356
478
  // src/eda/payloads.ts
@@ -944,12 +1066,16 @@ function pageCandidates(targets, match) {
944
1066
  }
945
1067
  /** CDP 适配器:逐页探测文档类型,选中匹配页后求值。 */
946
1068
  var DefaultCdpChannel = class {
947
- host;
1069
+ hosts;
1070
+ allowedHosts;
1071
+ activeHost;
948
1072
  portOption;
949
1073
  env;
950
1074
  defaultTimeoutMs;
951
1075
  constructor(options = {}) {
952
- this.host = options.host ?? "127.0.0.1";
1076
+ this.hosts = options.hosts && options.hosts.length > 0 ? options.hosts : [options.host ?? "127.0.0.1"];
1077
+ this.activeHost = this.hosts[0] ?? "127.0.0.1";
1078
+ this.allowedHosts = options.allowedHosts ?? this.hosts;
953
1079
  this.portOption = options.port;
954
1080
  this.env = options.env ?? process.env;
955
1081
  this.defaultTimeoutMs = options.defaultTimeoutMs;
@@ -967,7 +1093,8 @@ var DefaultCdpChannel = class {
967
1093
  session = await CdpSession.connect(String(page.webSocketDebuggerUrl), {
968
1094
  env: this.env,
969
1095
  timeoutMs: options.timeoutMs ?? this.defaultTimeoutMs,
970
- signal: options.signal
1096
+ signal: options.signal,
1097
+ allowedHosts: this.allowedHosts
971
1098
  });
972
1099
  } catch (error) {
973
1100
  if (error?.code === "CANCELLED") throw error;
@@ -1015,23 +1142,31 @@ var DefaultCdpChannel = class {
1015
1142
  }
1016
1143
  async endpoint(signal) {
1017
1144
  const port = this.portOption ?? defaultPortFromEnv(this.env);
1018
- try {
1019
- const endpoint = await resolveEndpoint(this.host, {
1020
- port,
1021
- env: this.env,
1022
- signal
1023
- });
1024
- if (!endpoint) throw new ChannelError("cdp", "CDP_NOT_FOUND", "找不到 CDP 端点:客户端需带 --remote-debugging-port 启动", 2);
1025
- return { port: endpoint.port };
1026
- } catch (error) {
1027
- if (error?.code === "CANCELLED") throw error;
1028
- if (error instanceof ChannelError) throw error;
1029
- throw timeoutExitCode("cdp", error);
1145
+ const tried = [];
1146
+ let lastMessage = "";
1147
+ for (const host of this.hosts) {
1148
+ tried.push(host);
1149
+ try {
1150
+ const endpoint = await resolveEndpoint(host, {
1151
+ port,
1152
+ env: this.env,
1153
+ signal,
1154
+ allowedHosts: this.allowedHosts
1155
+ });
1156
+ if (endpoint) {
1157
+ this.activeHost = host;
1158
+ return { port: endpoint.port };
1159
+ }
1160
+ } catch (error) {
1161
+ if (error?.code === "CANCELLED") throw error;
1162
+ lastMessage = error instanceof Error ? error.message : String(error);
1163
+ }
1030
1164
  }
1165
+ throw new ChannelError("cdp", "CDP_NOT_FOUND", `找不到 CDP 端点:试过 ${tried.join(" → ")}${lastMessage ? `(${lastMessage})` : ""};客户端需带 --remote-debugging-port 启动`, 2);
1031
1166
  }
1032
1167
  async targets(port, signal) {
1033
1168
  try {
1034
- return await listTargets(this.host, port, void 0, signal);
1169
+ return await listTargets(this.activeHost, port, void 0, signal);
1035
1170
  } catch (error) {
1036
1171
  if (error?.code === "CANCELLED") throw error;
1037
1172
  throw timeoutExitCode("cdp", error);
@@ -1044,13 +1179,16 @@ function createDefaultExecContext(options = {}) {
1044
1179
  return {
1045
1180
  env,
1046
1181
  bridge: new DefaultBridgeChannel({
1182
+ host: options.bridgeHost,
1047
1183
  portFirst: options.bridgePortFirst,
1048
1184
  portLast: options.bridgePortLast,
1049
1185
  env
1050
1186
  }),
1051
1187
  cdp: new DefaultCdpChannel({
1188
+ hosts: options.cdpHosts,
1052
1189
  port: options.cdpPort,
1053
- env
1190
+ env,
1191
+ allowedHosts: options.allowedHosts ?? options.cdpHosts
1054
1192
  }),
1055
1193
  match: options.match,
1056
1194
  windowId: options.windowId,
@@ -0,0 +1 @@
1
+ export { t as normalizeMcpEnv, o as resolveWslFacingHost } from "./windowsHost-CtRidgJp.mjs";