dsh-browser-cdp 1.2.3 → 1.2.5

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/lib/index.js CHANGED
@@ -1004,6 +1004,19 @@ function parseCliStatus(stdout) {
1004
1004
  }
1005
1005
  }
1006
1006
  /**
1007
+ * R4 — the ego CLI may route the embedded runtime's output to either stream.
1008
+ * 0.6.0.16 on Windows sends everything (console.log, process.stdout.write and
1009
+ * our sentinels) to stderr and leaves stdout empty, so every sentinel/facade
1010
+ * reader must look at both. stdout goes first: when a CLI writes to both, the
1011
+ * authoritative payload stays where it always was.
1012
+ * @internal exported for tests
1013
+ */
1014
+ function mergeCliOutput(result) {
1015
+ if (result.stdout === "") return result.stderr;
1016
+ if (result.stderr === "") return result.stdout;
1017
+ return `${result.stdout}\n${result.stderr}`;
1018
+ }
1019
+ /**
1007
1020
  * Probe one link end to end: resolve → pick a working shape → (optionally)
1008
1021
  * read `--status` → confirm with a real heredoc round-trip.
1009
1022
  *
@@ -1055,11 +1068,11 @@ async function probeCliLink(input, io) {
1055
1068
  };
1056
1069
  let running;
1057
1070
  if (statusRun && statusRun.exitCode === 0 && !statusRun.timedOut) {
1058
- const parsed = parseCliStatus(statusRun.stdout);
1071
+ const parsed = parseCliStatus(mergeCliOutput(statusRun));
1059
1072
  if (parsed.ok) running = parsed.running;
1060
1073
  }
1061
1074
  const sdkArgs = input.useSdkPath === true && (input.sdkPath ?? "") !== "" ? ["--sdk-path", input.sdkPath] : [];
1062
- const script = `console.log(${JSON.stringify(CLI_READY_SENTINEL)})\n`;
1075
+ const script = `console.log(${JSON.stringify(CLI_READY_SENTINEL)}, typeof taskSpaces, typeof browser)\n`;
1063
1076
  const runHeredoc = (extra) => io.run({
1064
1077
  argv: spawnArgvFor(shape, cliPath, ["nodejs", ...extra]),
1065
1078
  stdin: script,
@@ -1092,12 +1105,15 @@ async function probeCliLink(input, io) {
1092
1105
  message: `spawn failed: ${result.spawnErrorCode}`,
1093
1106
  ...base
1094
1107
  };
1095
- if (result.exitCode !== 0 || !result.stdout.includes(CLI_READY_SENTINEL)) {
1108
+ const facadeMatch = (/* @__PURE__ */ new RegExp(`${CLI_READY_SENTINEL} (\\w+) (\\w+)`)).exec(mergeCliOutput(result));
1109
+ const facadesOk = input.useSdkPath !== true || facadeMatch?.[1] === "object" && facadeMatch?.[2] === "object";
1110
+ if (result.exitCode !== 0 || !mergeCliOutput(result).includes(CLI_READY_SENTINEL) || !facadesOk) {
1096
1111
  const tail = (result.stderr || result.stdout).trim().slice(-400);
1112
+ const facadeNote = facadesOk ? "" : `; the SDK harness did not expose the facade (taskSpaces=${facadeMatch?.[1] ?? "undefined"}, browser=${facadeMatch?.[2] ?? "undefined"})`;
1097
1113
  return {
1098
1114
  ok: false,
1099
1115
  code: "cli-probe-failed",
1100
- message: `the ego CLI ran but did not reach the readiness sentinel (exit ${String(result.exitCode)})${tail ? `: ${tail}` : ""}`,
1116
+ message: `the ego CLI ran but did not reach the readiness sentinel (exit ${String(result.exitCode)})${facadeNote}${tail ? `: ${tail}` : ""}`,
1101
1117
  ...base
1102
1118
  };
1103
1119
  }
@@ -1517,6 +1533,7 @@ async function refreshCliAttach(input, cache, suggested, link, now) {
1517
1533
  message: probe.warning ?? (coldStart ? "local ego CLI reachable; the backing browser is not running yet and will start on the first call" : "local ego CLI ready"),
1518
1534
  cliPath: probe.cliPath,
1519
1535
  cliShape: probe.shape,
1536
+ sdkPath: link.useSdkPath === true && probe.warning === void 0 ? input.sdkPath ?? "" : "",
1520
1537
  latencyMs: probe.latencyMs,
1521
1538
  resolvedAt: now()
1522
1539
  });
@@ -3533,11 +3550,11 @@ const CORE = [
3533
3550
  "bcdp_doctor",
3534
3551
  "bcdp_help",
3535
3552
  "bcdp_space_open",
3553
+ "bcdp_space_close",
3536
3554
  "bcdp_navigate",
3537
3555
  "bcdp_snapshot"
3538
3556
  ];
3539
3557
  const BROWSE = [
3540
- "bcdp_space_close",
3541
3558
  "bcdp_click",
3542
3559
  "bcdp_fill",
3543
3560
  "bcdp_key",
@@ -3583,6 +3600,30 @@ const TIER_OF_TOOL = new Map([
3583
3600
  ].flatMap(([tier, names]) => names.map((n) => [n, tier])));
3584
3601
  /** 去掉 `bcdp_`/`ego_` 前缀后的裸名,便于策略表保持前缀无关。 */
3585
3602
  const bareToolName = (name$1) => name$1.replace(/^(?:bcdp|ego)_/, "");
3603
+ /** 批次放行顺序(索引即 rank)。 */
3604
+ const BATCH_ORDER = [
3605
+ "act",
3606
+ "observe",
3607
+ "wait"
3608
+ ];
3609
+ /** `browse` 级工具 → 批次。未登记的名字按 'act' 处理,绝不因缺表而被卡住。 */
3610
+ const BROWSE_BATCH = {
3611
+ click: "act",
3612
+ fill: "act",
3613
+ key: "act",
3614
+ hover: "act",
3615
+ scroll: "act",
3616
+ select: "act",
3617
+ check: "act",
3618
+ screenshot: "observe",
3619
+ page_info: "observe",
3620
+ read_element: "observe",
3621
+ js: "observe",
3622
+ wait: "wait",
3623
+ wait_for_selector: "wait"
3624
+ };
3625
+ /** 某工具的注入批次(前缀无关)。 */
3626
+ const batchOfTool = (name$1) => BROWSE_BATCH[bareToolName(name$1)] ?? "act";
3586
3627
  /**
3587
3628
  * 工具所属分级。未登记的名字落到 `extended`(最严的一档:宁可等活动解锁,
3588
3629
  * 也不让新工具悄悄回到常驻面);调用方应当在启动时打一条 warn,见
@@ -3626,7 +3667,15 @@ function tierAllowed(tier, p) {
3626
3667
  return p.injection === "always" || p.active;
3627
3668
  }
3628
3669
  /** 某工具此刻是否允许注册(名字 → 分级 → 策略)。 */
3629
- const toolAllowed = (name$1, p) => tierAllowed(tierOfTool(name$1), p);
3670
+ function toolAllowed(name$1, p) {
3671
+ const tier = tierOfTool(name$1);
3672
+ if (!tierAllowed(tier, p)) return false;
3673
+ if (tier === "browse" && p.injection !== "always") {
3674
+ const depth = p.batchDepth ?? BATCH_ORDER.length;
3675
+ if (BATCH_ORDER.indexOf(batchOfTool(name$1)) >= depth) return false;
3676
+ }
3677
+ return true;
3678
+ }
3630
3679
  function createTierInjector(o) {
3631
3680
  const label = o.label ?? "dsh-browser-cdp";
3632
3681
  /** 全部已登记工具,插入序。 */
@@ -7323,6 +7372,10 @@ async function openAgentWindow(ctx, cfg) {
7323
7372
  ok: false,
7324
7373
  error: gate
7325
7374
  };
7375
+ if (defaultAttachCache.get().linkKind === EGO_CLI_KIND) {
7376
+ ctx.logger?.info?.("dsh-browser-cdp: ego-cli: browser already visible, skipping --open");
7377
+ return { ok: true };
7378
+ }
7326
7379
  const handle = ctx.subprocess.spawn({
7327
7380
  argv: [...cfg.egoArgvPrefix, "--open"],
7328
7381
  cwd: process.cwd(),
@@ -7357,6 +7410,7 @@ async function runWithStaleSpaceRetry(ctx, cfg, exec, buildScript, graceOverride
7357
7410
  return result;
7358
7411
  }
7359
7412
  /** Find the last line carrying the sentinel and JSON-parse its payload. */
7413
+ /** @internal exported for tests */
7360
7414
  function parseSentinel(stdout) {
7361
7415
  const lines = stdout.split("\n");
7362
7416
  for (let i = lines.length - 1; i >= 0; i--) {
@@ -7370,6 +7424,33 @@ function parseSentinel(stdout) {
7370
7424
  }
7371
7425
  }
7372
7426
  }
7427
+ /** R2/R3 — sentinel + payload for the `bcdp_status` facade probe. @internal exported for tests */
7428
+ const STATUS_FACADE_SENTINEL = "__BCDP_STATUS__";
7429
+ /** @internal exported for tests — the exact heredoc the status probe runs. */
7430
+ const STATUS_FACADE_SCRIPT = `console.log(${JSON.stringify(STATUS_FACADE_SENTINEL)} + JSON.stringify({ taskSpaces: typeof taskSpaces, browser: typeof browser, page: typeof page }))
7431
+ `;
7432
+ /**
7433
+ * Parse the facade payload the status probe prints; `undefined` if absent.
7434
+ * @internal exported for tests
7435
+ */
7436
+ function parseStatusFacades(stdout) {
7437
+ const lines = stdout.split("\n");
7438
+ for (let i = lines.length - 1; i >= 0; i--) {
7439
+ const idx = lines[i].indexOf(STATUS_FACADE_SENTINEL);
7440
+ if (idx === -1) continue;
7441
+ const payload = lines[i].slice(idx + 15).trim();
7442
+ try {
7443
+ const parsed = JSON.parse(payload);
7444
+ return {
7445
+ taskSpaces: typeof parsed.taskSpaces === "string" ? parsed.taskSpaces : "undefined",
7446
+ browser: typeof parsed.browser === "string" ? parsed.browser : "undefined",
7447
+ page: typeof parsed.page === "string" ? parsed.page : "undefined"
7448
+ };
7449
+ } catch {
7450
+ return;
7451
+ }
7452
+ }
7453
+ }
7373
7454
  /**
7374
7455
  * R7 — is the upstream plugin installed anywhere under this DSH home?
7375
7456
  *
@@ -7388,16 +7469,28 @@ function findUpstreamPluginInstall(home = process.env.HOME || process.env.USERPR
7388
7469
  } catch {}
7389
7470
  return "";
7390
7471
  }
7472
+ /**
7473
+ * R1 — argv for one tool run. Single source of truth for the `--sdk-path`
7474
+ * injection: `bcdp_status` and `runEgoScript` must probe/run under the exact
7475
+ * same conditions, otherwise "available" and "actually works" diverge again.
7476
+ * @internal exported for tests
7477
+ */
7478
+ function buildEgoToolArgv(prefix, attach, runtimeArgs) {
7479
+ const extraCliArgs = filterArgs(runtimeArgs, EGO_CLI_BLOCKED);
7480
+ const sdkArgs = attach.linkKind === EGO_CLI_KIND && (attach.sdkPath ?? "") !== "" ? ["--sdk-path", attach.sdkPath] : [];
7481
+ return [
7482
+ ...prefix,
7483
+ "nodejs",
7484
+ ...sdkArgs,
7485
+ ...extraCliArgs
7486
+ ];
7487
+ }
7391
7488
  async function runEgoScript(subprocess, script, exec, cfg, graceOverrideMs) {
7392
7489
  let handle;
7393
7490
  try {
7394
- const extraCliArgs = filterArgs(cfg.runtimeArgs ?? "", EGO_CLI_BLOCKED);
7491
+ const attach = defaultAttachCache.get();
7395
7492
  handle = subprocess.spawn({
7396
- argv: [
7397
- ...cfg.egoArgvPrefix,
7398
- "nodejs",
7399
- ...extraCliArgs
7400
- ],
7493
+ argv: buildEgoToolArgv(cfg.egoArgvPrefix, attach, cfg.runtimeArgs ?? ""),
7401
7494
  cwd: process.cwd(),
7402
7495
  env: resolveEgoEnv(cfg),
7403
7496
  stdio: {
@@ -7407,8 +7500,8 @@ async function runEgoScript(subprocess, script, exec, cfg, graceOverrideMs) {
7407
7500
  spill: { maxBytes: cfg.maxOutputBytes }
7408
7501
  },
7409
7502
  stderr: {
7410
- maxBytes: 512e3,
7411
- spill: { maxBytes: 2e6 }
7503
+ maxBytes: cfg.maxOutputBytes,
7504
+ spill: { maxBytes: cfg.maxOutputBytes }
7412
7505
  }
7413
7506
  },
7414
7507
  graceMs: Number.isFinite(graceOverrideMs) && graceOverrideMs > 0 ? graceOverrideMs : cfg.graceMs,
@@ -7447,10 +7540,13 @@ async function runEgoScript(subprocess, script, exec, cfg, graceOverrideMs) {
7447
7540
  stdout,
7448
7541
  stderr
7449
7542
  };
7450
- const value = parseSentinel(stdout);
7543
+ const value = parseSentinel(mergeCliOutput({
7544
+ stdout,
7545
+ stderr
7546
+ }));
7451
7547
  if (value === void 0) return {
7452
7548
  ok: false,
7453
- error: `ego-browser finished but no ${SENTINEL} JSON payload was found on stdout${describeStderr(stderr)}`,
7549
+ error: `ego-browser finished but no ${SENTINEL} JSON payload was found on stdout/stderr${describeStderr(stderr)}`,
7454
7550
  stdout,
7455
7551
  stderr
7456
7552
  };
@@ -7702,6 +7798,7 @@ function apply(ctx, config = {}) {
7702
7798
  }
7703
7799
  };
7704
7800
  let browserActive = false;
7801
+ let browseBatchDepth = 0;
7705
7802
  const tiers = createTierInjector({
7706
7803
  register: (tool) => {
7707
7804
  const dispose = ctx.tools.register(tool);
@@ -7717,15 +7814,20 @@ function apply(ctx, config = {}) {
7717
7814
  jevKey: cfg.jevKey,
7718
7815
  layaKey: cfg.layaKey
7719
7816
  }),
7720
- active: browserActive
7817
+ active: browserActive,
7818
+ batchDepth: browseBatchDepth
7721
7819
  }),
7722
7820
  logger: ctx.logger
7723
7821
  });
7724
- /** 活动信号:只翻一次牌,重复调用零成本。 */
7822
+ /**
7823
+ * 活动信号:每次 bcdp_* 调用推进 browse 批次(act → observe → wait),
7824
+ * 到顶即止。只有注入面真的变了才 reapply。
7825
+ */
7725
7826
  const pulseActivity = () => {
7726
- if (browserActive) return;
7827
+ const before = browseBatchDepth;
7727
7828
  browserActive = true;
7728
- tiers.reapply();
7829
+ browseBatchDepth = Math.min(BATCH_ORDER.length, browseBatchDepth + 1);
7830
+ if (before !== browseBatchDepth) tiers.reapply();
7729
7831
  };
7730
7832
  {
7731
7833
  const offActivity = onEgoActivity(pulseActivity);
@@ -7738,6 +7840,7 @@ function apply(ctx, config = {}) {
7738
7840
  const sealAfterReap = () => {
7739
7841
  if (cfg.toolInjection !== "lazy" || !browserActive) return;
7740
7842
  browserActive = false;
7843
+ browseBatchDepth = 0;
7741
7844
  tiers.reapply();
7742
7845
  };
7743
7846
  /**
@@ -7867,6 +7970,11 @@ function apply(ctx, config = {}) {
7867
7970
  const last = getLastEgoActivity();
7868
7971
  if (!shouldReapBrowser(Date.now(), last, cfg.idleTimeoutMin)) return;
7869
7972
  if (last <= reapedFor) return;
7973
+ if (defaultAttachCache.get().linkKind === EGO_CLI_KIND) {
7974
+ reapedFor = last;
7975
+ ctx.logger?.info?.("dsh-browser-cdp: idle reaper skipped: ego-cli owns the user's browser (never --stop it)");
7976
+ return;
7977
+ }
7870
7978
  try {
7871
7979
  const { localBrowserInfo, stopLocalBrowser: stopLocalBrowser$1 } = await import("./launcher-h0Ca5NV1.js");
7872
7980
  if (localBrowserInfo()) {
@@ -7909,6 +8017,10 @@ function apply(ctx, config = {}) {
7909
8017
  }, "dsh-browser-cdp: idle reaper");
7910
8018
  ctx.effect?.(() => {
7911
8019
  try {
8020
+ if (defaultAttachCache.get().linkKind === EGO_CLI_KIND) {
8021
+ ctx.logger?.info?.("dsh-browser-cdp: teardown skipped --stop: ego-cli owns the user's browser");
8022
+ return;
8023
+ }
7912
8024
  ctx.subprocess.spawn({
7913
8025
  argv: [
7914
8026
  process.execPath,
@@ -7928,11 +8040,11 @@ function apply(ctx, config = {}) {
7928
8040
  });
7929
8041
  ctx.logger?.info?.(`dsh-browser-cdp: mounted (egoBin=${cfg.egoBin}, defaultSpace=${cfg.defaultSpace})`);
7930
8042
  }
7931
- /** `bcdp_status` probes CLI availability by running the real `--status` path. */
8043
+ /** `bcdp_status` probes the SAME channel work uses: a `nodejs` heredoc. */
7932
8044
  function registerEgoStatus(ctx, cfg, reg, tiers) {
7933
8045
  reg(defineTool({
7934
8046
  name: "bcdp_status",
7935
- description: "Check whether the ego-browser CLI is usable (runs `ego-browser --status`). Use this first when other bcdp_* tools report \"CLI not found\".",
8047
+ description: "Check whether the ego-browser CLI can actually run bcdp_* tools (probes the taskSpaces/browser/page facade over the nodejs channel). Use this first when other bcdp_* tools report \"CLI not found\".",
7936
8048
  parameters: {},
7937
8049
  output: {
7938
8050
  schema: {
@@ -7948,34 +8060,48 @@ function registerEgoStatus(ctx, cfg, reg, tiers) {
7948
8060
  required: true
7949
8061
  },
7950
8062
  path: { type: "string" },
7951
- exitCode: { type: "integer" }
8063
+ exitCode: { type: "integer" },
8064
+ facades: {
8065
+ type: "object",
8066
+ additionalProperties: false,
8067
+ properties: {
8068
+ taskSpaces: { type: "string" },
8069
+ browser: { type: "string" },
8070
+ page: { type: "string" }
8071
+ }
8072
+ }
7952
8073
  }
7953
8074
  },
7954
8075
  render: renderText
7955
8076
  },
7956
- timeoutMs: 25e3,
8077
+ timeoutMs: 15e3,
7957
8078
  execute: async () => {
7958
8079
  tiers.pulse();
7959
8080
  return withEgoLock(async () => {
7960
8081
  try {
8082
+ const attach = defaultAttachCache.get();
7961
8083
  const handle = ctx.subprocess.spawn({
7962
- argv: [...cfg.egoArgvPrefix, "--status"],
8084
+ argv: buildEgoToolArgv(cfg.egoArgvPrefix, attach, cfg.runtimeArgs ?? ""),
7963
8085
  cwd: process.cwd(),
7964
8086
  env: resolveEgoEnv(cfg),
7965
8087
  stdio: {
7966
- stdin: { data: "" },
8088
+ stdin: { data: STATUS_FACADE_SCRIPT },
7967
8089
  stdout: { maxBytes: 4096 },
7968
8090
  stderr: { maxBytes: 4096 }
7969
8091
  },
7970
- graceMs: 25e3
8092
+ graceMs: 15e3
7971
8093
  });
7972
8094
  const outcome = await handle.done;
7973
- const out = readAll(handle.collected.stdout).trim();
8095
+ const facades = parseStatusFacades(mergeCliOutput({
8096
+ stdout: readAll(handle.collected.stdout),
8097
+ stderr: readAll(handle.collected.stderr)
8098
+ }));
7974
8099
  return {
7975
8100
  ok: true,
7976
- available: outcome.exitCode === 0 && out !== "",
7977
- path: cfg.egoBin,
7978
- exitCode: outcome.exitCode
8101
+ available: outcome.exitCode === 0 && facades?.taskSpaces === "object" && facades?.browser === "object",
8102
+ path: attach.cliPath ?? cfg.egoBin,
8103
+ exitCode: outcome.exitCode,
8104
+ ...facades ? { facades } : {}
7979
8105
  };
7980
8106
  } catch (err) {
7981
8107
  return {
@@ -8074,27 +8200,27 @@ function registerAuthFlush(ctx, cfg, reg) {
8074
8200
  function registerLoginImport(ctx, cfg, reg) {
8075
8201
  reg(defineTool({
8076
8202
  name: "bcdp_login_import",
8077
- description: "Import login cookies from the system browser (Chrome/Edge/Brave) into the agent browser, so sites open already logged in. Works via a throwaway headless instance of the REAL system browser (CDP passthrough — no offline decryption; survives Chrome App-Bound Encryption). Run with dryRun=true first to see what is importable, then import with an explicit domains list (e.g. [\"bilibili.com\"]). The agent browser must be running (call bcdp_status first). Imported logins persist in the on-disk profile across restarts. Cookie values are never shown — only domain names and counts.",
8203
+ description: "Import login cookies from the system browser (Chrome/Edge/Brave) into the agent browser via CDP passthrough, so sites open logged in. Run dryRun first, then import explicit domains; logins persist in the profile. Cookie values are never shown.",
8078
8204
  parameters: {
8079
8205
  source: {
8080
8206
  type: "string",
8081
- description: "chrome | edge | brave | auto (default: auto = first detected browser)."
8207
+ description: "chrome | edge | brave | auto (default auto)."
8082
8208
  },
8083
8209
  domains: {
8084
8210
  type: "json",
8085
- description: "Optional array of domains to import, e.g. [\"bilibili.com\",\"zhihu.com\"] (subdomains included). Omit = ALL cookies — prefer an explicit list."
8211
+ description: "Domains to import, e.g. [\"bilibili.com\"] (subdomains included). Omit = all cookies; prefer an explicit list."
8086
8212
  },
8087
8213
  profile: {
8088
8214
  type: "string",
8089
- description: "Source browser profile directory name, e.g. \"Default\" or \"Profile 1\" (default: the first profile)."
8215
+ description: "Source profile dir, e.g. \"Default\" (default: first profile)."
8090
8216
  },
8091
8217
  closeSource: {
8092
8218
  type: "boolean",
8093
- description: "A running source browser holds an exclusive lock on its cookie store (Windows). true = gracefully close it first (its windows/tabs restore on next launch). false (default) = return an actionable error instead."
8219
+ description: "true = gracefully close a running source browser first (tabs restore); false = return an actionable error (default)."
8094
8220
  },
8095
8221
  dryRun: {
8096
8222
  type: "boolean",
8097
- description: "true = only report what would be imported (domains + cookie counts), write nothing."
8223
+ description: "true = report what would be imported; write nothing."
8098
8224
  }
8099
8225
  },
8100
8226
  output: {
@@ -8247,27 +8373,27 @@ function registerActionTools(ctx, cfg, reg) {
8247
8373
  }));
8248
8374
  reg(t({
8249
8375
  name: "bcdp_click",
8250
- description: "Click an element in the current page. Target with a CSS selector, an xpath=.../loc=.../ref=N value from bcdp_snapshot, or viewport coordinates.",
8376
+ description: "Click an element: CSS/xpath/loc/ref selector, or viewport x+y coordinates.",
8251
8377
  parameters: {
8252
8378
  selector: {
8253
8379
  type: "string",
8254
- description: "CSS selector, xpath=..., loc=..., or ref=N from the snapshot. Required unless x/y are given."
8380
+ description: "CSS/xpath/loc/ref=N from bcdp_snapshot; required unless x,y."
8255
8381
  },
8256
8382
  x: {
8257
8383
  type: "number",
8258
- description: "Viewport x coordinate for a coordinate click."
8384
+ description: "Viewport x for a coordinate click."
8259
8385
  },
8260
8386
  y: {
8261
8387
  type: "number",
8262
- description: "Viewport y coordinate for a coordinate click."
8388
+ description: "Viewport y for a coordinate click."
8263
8389
  },
8264
8390
  label: {
8265
8391
  type: "string",
8266
- description: "Short human label for the action, e.g. \"click submit button\"."
8392
+ description: "Short action label, e.g. \"click submit\"."
8267
8393
  },
8268
8394
  double: {
8269
8395
  type: "boolean",
8270
- description: "Double-click instead of single-click. Useful for opening files/rows or triggering dblclick handlers."
8396
+ description: "Double-click instead of single."
8271
8397
  },
8272
8398
  space: spaceParam
8273
8399
  },
@@ -8377,20 +8503,20 @@ function registerActionTools(ctx, cfg, reg) {
8377
8503
  }));
8378
8504
  reg(t({
8379
8505
  name: "bcdp_wait_for_selector",
8380
- description: "Wait until an element matching a CSS selector appears (state=visible, default) or disappears (state=hidden). Use instead of a blind fixed wait when a page renders asynchronously.",
8506
+ description: "Wait until a CSS selector appears (state=visible, default) or disappears (state=hidden). Use instead of a fixed wait for async pages.",
8381
8507
  parameters: {
8382
8508
  selector: {
8383
8509
  type: "string",
8384
8510
  required: true,
8385
- description: "CSS selector of the element to wait for, e.g. '.results' or '[data-id=done]'."
8511
+ description: "CSS selector to wait for, e.g. '.results' or '[data-id=done]'."
8386
8512
  },
8387
8513
  state: {
8388
8514
  type: "string",
8389
- description: "Target state: 'visible' (default) | 'attached' | 'hidden' | 'detached'."
8515
+ description: "'visible' (default) | 'attached' | 'hidden' | 'detached'."
8390
8516
  },
8391
8517
  timeout: {
8392
8518
  type: "number",
8393
- description: "How long to wait in ms (default 10000)."
8519
+ description: "Wait in ms (default 10000)."
8394
8520
  },
8395
8521
  space: spaceParam
8396
8522
  },
@@ -8423,20 +8549,20 @@ function registerActionTools(ctx, cfg, reg) {
8423
8549
  }));
8424
8550
  reg(t({
8425
8551
  name: "bcdp_wait_for_response",
8426
- description: "Wait for a network response matching a URL/glob/regex and return it. Optionally return the body (text or JSON) — ideal for scraping API responses or confirming a submission.",
8552
+ description: "Wait for a network response matching a URL/glob/regex and return it; optionally return the body (text or JSON).",
8427
8553
  parameters: {
8428
8554
  url: {
8429
8555
  type: "string",
8430
8556
  required: true,
8431
- description: "URL/glob/regex to match, e.g. '/api/search' or 'https://*.com/data'."
8557
+ description: "URL/glob/regex, e.g. '/api/search' or 'https://*.com/data'."
8432
8558
  },
8433
8559
  timeout: {
8434
8560
  type: "number",
8435
- description: "How long to wait in ms (default 10000)."
8561
+ description: "Wait in ms (default 10000)."
8436
8562
  },
8437
8563
  body: {
8438
8564
  type: "string",
8439
- description: "Return the response body: 'none' (default) | 'text' | 'json'."
8565
+ description: "'none' (default) | 'text' | 'json'."
8440
8566
  },
8441
8567
  space: spaceParam
8442
8568
  },
@@ -8449,15 +8575,15 @@ function registerActionTools(ctx, cfg, reg) {
8449
8575
  }));
8450
8576
  reg(t({
8451
8577
  name: "bcdp_key",
8452
- description: "Press a keyboard key or shortcut combination on the current page, e.g. 'Enter', 'Tab', 'Control+a', 'Escape', 'ArrowDown'. Useful for forms, shortcuts and navigation. Pass `text` to type a string of characters instead (keyboard.type).",
8578
+ description: "Press a key/combo ('Enter', 'Tab', 'Control+a', 'Escape') or type text character-by-character.",
8453
8579
  parameters: {
8454
8580
  key: {
8455
8581
  type: "string",
8456
- description: "Key or combo: 'Enter', 'Tab', 'Control+c', 'Meta+v', 'ArrowDown', 'Escape', 'F5', etc. (ignored when `text` is given)."
8582
+ description: "Key/combo: 'Enter', 'Control+c', 'ArrowDown', 'F5' (ignored when text is given)."
8457
8583
  },
8458
8584
  text: {
8459
8585
  type: "string",
8460
- description: "Type this text character-by-character (keyboard.type). Use instead of `key` for typing words into the focused element."
8586
+ description: "Type this text instead (keyboard.type)."
8461
8587
  },
8462
8588
  space: spaceParam
8463
8589
  },
@@ -8496,16 +8622,16 @@ function registerActionTools(ctx, cfg, reg) {
8496
8622
  }));
8497
8623
  reg(t({
8498
8624
  name: "bcdp_read_element",
8499
- description: "Read a single element (by selector): its text, HTML, input value, an attribute, or visibility/enabled/count. Cheaper and more precise than a full-page snapshot.",
8625
+ description: "Read one element: text, HTML, value, an attribute, or visible/enabled/count.",
8500
8626
  parameters: {
8501
8627
  selector: {
8502
8628
  type: "string",
8503
8629
  required: true,
8504
- description: "CSS selector of the target element."
8630
+ description: "CSS selector of the target."
8505
8631
  },
8506
8632
  what: {
8507
8633
  type: "string",
8508
- description: "What to read: 'text' (default) | 'html' | 'value' | 'attribute' | 'visible' | 'enabled' | 'count'."
8634
+ description: "'text' (default) | 'html' | 'value' | 'attribute' | 'visible' | 'enabled' | 'count'."
8509
8635
  },
8510
8636
  attribute: {
8511
8637
  type: "string",
@@ -8633,23 +8759,23 @@ function registerActionTools(ctx, cfg, reg) {
8633
8759
  }));
8634
8760
  reg(t({
8635
8761
  name: "bcdp_download",
8636
- description: "Wait for a file download triggered by the current action, then return its saved path. Provide `triggerSelector` (a download button/link to click) or `triggerScript` (arbitrary JS that triggers the download). The file is captured into a temp dir and (optionally) copied to `savePath`. Returns { path, suggestedFilename, url }.",
8762
+ description: "Wait for a download triggered by the current action, then return its saved path. Trigger with triggerSelector or triggerScript; optionally copy to savePath.",
8637
8763
  parameters: {
8638
8764
  triggerSelector: {
8639
8765
  type: "string",
8640
- description: "CSS selector of the element (button/link) whose click starts the download."
8766
+ description: "CSS selector of the button/link whose click starts the download."
8641
8767
  },
8642
8768
  triggerScript: {
8643
8769
  type: "string",
8644
- description: "Full JS snippet that triggers the download (e.g. window.open() or a fetch-to-blob download); runs in the page before waiting for the download."
8770
+ description: "JS snippet that triggers the download (runs before waiting)."
8645
8771
  },
8646
8772
  savePath: {
8647
8773
  type: "string",
8648
- description: "Optional absolute destination path to also copy the downloaded file to. Otherwise only the temp-captured path is returned."
8774
+ description: "Absolute path to also copy the file to."
8649
8775
  },
8650
8776
  timeout: {
8651
8777
  type: "number",
8652
- description: "How long to wait for the download in ms (default 30000)."
8778
+ description: "Wait timeout in ms (default 30000)."
8653
8779
  },
8654
8780
  space: spaceParam
8655
8781
  },
@@ -8707,7 +8833,7 @@ function registerActionTools(ctx, cfg, reg) {
8707
8833
  }));
8708
8834
  reg(t({
8709
8835
  name: "bcdp_http",
8710
- description: "Make an HTTP request and return status + body. Default runs in the agent page's browser context (cross-origin allowed when the server's CORS permits); set `mode: server` to use Node-side fetch.server. Use to scrape an API, POST data, or hit a service. (Note: on the vendored ego-linux Windows runtime, fetch.server can hit a libuv crash, so prefer the default browser mode there.)",
8836
+ description: "Make an HTTP request and return status + body. Default runs in the page's browser context; mode=server uses Node-side fetch.server (may crash on the vendored ego-linux Windows runtime, so prefer browser mode).",
8711
8837
  parameters: {
8712
8838
  url: {
8713
8839
  type: "string",
@@ -8716,7 +8842,7 @@ function registerActionTools(ctx, cfg, reg) {
8716
8842
  },
8717
8843
  method: {
8718
8844
  type: "string",
8719
- description: "HTTP method, default GET."
8845
+ description: "HTTP method (default GET)."
8720
8846
  },
8721
8847
  headers: {
8722
8848
  type: "object",
@@ -8725,7 +8851,7 @@ function registerActionTools(ctx, cfg, reg) {
8725
8851
  },
8726
8852
  body: {
8727
8853
  type: "string",
8728
- description: "Request body (for POST/PUT)."
8854
+ description: "Request body (POST/PUT)."
8729
8855
  },
8730
8856
  timeout: {
8731
8857
  type: "number",
@@ -8733,11 +8859,11 @@ function registerActionTools(ctx, cfg, reg) {
8733
8859
  },
8734
8860
  mode: {
8735
8861
  type: "string",
8736
- description: "'browser' (default) runs via the page context; 'server' uses Node-side fetch.server."
8862
+ description: "'browser' (default) or 'server' (Node-side fetch)."
8737
8863
  },
8738
8864
  credentials: {
8739
8865
  type: "string",
8740
- description: "Browser mode only: 'include' attaches the page profile's cookies even cross-origin (reuse login state on API endpoints); 'omit' / 'same-origin' also accepted. Omitted = engine default (cross-origin credentials not sent). Ignored in server mode."
8866
+ description: "Browser mode: 'include' sends the profile's cookies cross-origin; 'omit'/'same-origin' also accepted. Default: engine default."
8741
8867
  },
8742
8868
  space: spaceParam
8743
8869
  },
@@ -8777,6 +8903,10 @@ function registerActionTools(ctx, cfg, reg) {
8777
8903
  required: true
8778
8904
  },
8779
8905
  stderr: { type: "string" },
8906
+ output: {
8907
+ type: "string",
8908
+ description: "Merged stdout+stderr text of the CLI run. The ego CLI writes script output to stderr on Windows, so read this when `stdout` looks empty."
8909
+ },
8780
8910
  result: { type: "json" }
8781
8911
  }
8782
8912
  },
@@ -8787,11 +8917,12 @@ function registerActionTools(ctx, cfg, reg) {
8787
8917
  markEgoToolCall(callingSessionId(exec));
8788
8918
  const result = await runWithStaleSpaceRetry(ctx, cfg, exec, () => str(args.script, ""));
8789
8919
  if (!result.ok) throw new Error(result.error);
8790
- const parsed = parseSentinel(result.stdout);
8920
+ const parsed = parseSentinel(mergeCliOutput(result));
8791
8921
  return {
8792
8922
  ok: true,
8793
8923
  stdout: result.stdout,
8794
8924
  stderr: result.stderr,
8925
+ output: mergeCliOutput(result),
8795
8926
  result: parsed ?? null
8796
8927
  };
8797
8928
  },
@@ -8843,7 +8974,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
8843
8974
  kind: null,
8844
8975
  error: result.error
8845
8976
  };
8846
- const hc = (parseSentinel(result.stdout) || {}).humanCheck;
8977
+ const hc = (parseSentinel(mergeCliOutput(result)) || {}).humanCheck;
8847
8978
  return {
8848
8979
  ok: true,
8849
8980
  detected: !!hc?.detected,
@@ -9063,6 +9194,10 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
9063
9194
  required: true
9064
9195
  },
9065
9196
  stderr: { type: "string" },
9197
+ output: {
9198
+ type: "string",
9199
+ description: "Merged stdout+stderr text of the CLI run. The ego CLI writes script output to stderr on Windows, so read this when `stdout` looks empty."
9200
+ },
9066
9201
  result: { type: "json" },
9067
9202
  durationMs: { type: "integer" },
9068
9203
  timedOut: { type: "boolean" },
@@ -9082,15 +9217,17 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
9082
9217
  ok: false,
9083
9218
  stdout: result.stdout,
9084
9219
  stderr: result.stderr,
9220
+ output: mergeCliOutput(result),
9085
9221
  durationMs,
9086
9222
  timedOut: false,
9087
9223
  error: result.error
9088
9224
  };
9089
- const parsed = parseSentinel(result.stdout);
9225
+ const parsed = parseSentinel(mergeCliOutput(result));
9090
9226
  return {
9091
9227
  ok: true,
9092
9228
  stdout: result.stdout,
9093
9229
  stderr: result.stderr,
9230
+ output: mergeCliOutput(result),
9094
9231
  result: parsed ?? null,
9095
9232
  durationMs,
9096
9233
  timedOut: false
@@ -9234,28 +9371,28 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
9234
9371
  }));
9235
9372
  reg(defineTool({
9236
9373
  name: "bcdp_jev_ask",
9237
- description: "Assemble the JEV/Laya judgement request for the CURRENT page plus an intent, and either return the assembled request body (dryRun, default) or send it and return the answer. Use dryRun to inspect exactly what would be sent.",
9374
+ description: "Assemble the JEV/Laya judgement request for the current page + intent; return it (dryRun) or send it.",
9238
9375
  parameters: {
9239
9376
  goal: {
9240
9377
  type: "string",
9241
9378
  required: true,
9242
- description: "What we are trying to accomplish, in your own words."
9379
+ description: "What we are trying to accomplish."
9243
9380
  },
9244
9381
  kind: {
9245
9382
  type: "string",
9246
- description: "Intent kind: navigate | extract | fill | click | verify | other (default other)."
9383
+ description: "navigate | extract | fill | click | verify | other."
9247
9384
  },
9248
9385
  hints: {
9249
9386
  type: "string",
9250
- description: "One target hint per line. Hints only — never a CSS selector."
9387
+ description: "Target hint per line; never a selector."
9251
9388
  },
9252
9389
  successCriteria: {
9253
9390
  type: "string",
9254
- description: "One observable success condition per line."
9391
+ description: "Success condition per line."
9255
9392
  },
9256
9393
  stopConditions: {
9257
9394
  type: "string",
9258
- description: "One stop condition per line, e.g. \"a captcha appears\"."
9395
+ description: "Stop condition per line."
9259
9396
  },
9260
9397
  dryRun: {
9261
9398
  type: "boolean",
@@ -9263,19 +9400,19 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
9263
9400
  },
9264
9401
  includeImage: {
9265
9402
  type: "boolean",
9266
- description: "Also return the base64 frame image (default false)."
9403
+ description: "Also return the base64 frame (default false)."
9267
9404
  },
9268
9405
  maxCandidates: {
9269
9406
  type: "integer",
9270
- description: "Override the candidate ceiling for this call."
9407
+ description: "Candidate ceiling for this call."
9271
9408
  },
9272
9409
  round: {
9273
9410
  type: "string",
9274
- description: "Which round to assemble: 'control' (should we act), 'chapter' (which part of the page), or 'pick' (which numbered candidate). Default control."
9411
+ description: "'control' | 'chapter' | 'pick' (default control)."
9275
9412
  },
9276
9413
  chapter: {
9277
9414
  type: "string",
9278
- description: "Chapter key to restrict a 'pick' round to, e.g. form#1. From the chapter round's options."
9415
+ description: "Chapter key for a 'pick' round, e.g. form#1."
9279
9416
  }
9280
9417
  },
9281
9418
  output: {
@@ -9493,7 +9630,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
9493
9630
  }));
9494
9631
  reg(defineTool({
9495
9632
  name: "bcdp_jev_run",
9496
- description: "Run the JEV judgement loop against the current page for one goal: capture a frame, ask the judge, act, verify. Stops on done (VERIFIED against successCriteria), blocked, exhausted, stuck, unavailable or error. Returns a per-step trace.",
9633
+ description: "Run the JEV loop for one goal; returns a step trace.",
9497
9634
  parameters: {
9498
9635
  goal: {
9499
9636
  type: "string",
@@ -9506,23 +9643,23 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
9506
9643
  },
9507
9644
  hints: {
9508
9645
  type: "string",
9509
- description: "One target hint per line (never a selector)."
9646
+ description: "Target hint per line (never a selector)."
9510
9647
  },
9511
9648
  successCriteria: {
9512
9649
  type: "string",
9513
- description: "One observable success condition per line. REQUIRED for a trustworthy `done`."
9650
+ description: "Success condition per line; required for done."
9514
9651
  },
9515
9652
  stopConditions: {
9516
9653
  type: "string",
9517
- description: "One stop condition per line."
9654
+ description: "Stop condition per line."
9518
9655
  },
9519
9656
  stepBudget: {
9520
9657
  type: "integer",
9521
- description: "Judgement rounds allowed (default from settings)."
9658
+ description: "Max judgement rounds (default settings)."
9522
9659
  },
9523
9660
  wallMs: {
9524
9661
  type: "integer",
9525
- description: "Wall-clock ceiling in ms (default from settings)."
9662
+ description: "Wall-clock ceiling in ms (default settings)."
9526
9663
  }
9527
9664
  },
9528
9665
  output: {
@@ -9601,12 +9738,12 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
9601
9738
  }));
9602
9739
  reg(defineTool({
9603
9740
  name: "bcdp_jev_attempt",
9604
- description: "Open a URL and let the decision model (laya/jev) ATTEMPT one goal on it: every round the option table is the page's DOM candidates plus an `end` option; the model spends up to N actions (default 5) or picks `end` by itself, then a receipt comes back. The judge context is the DOM tree only (the model cannot read the screenshot). Verify the result yourself afterwards via bcdp_cdp / bcdp_screenshot using the returned targetId — the receipt is a report, not a proof.",
9741
+ description: "Open a URL and let the decision model attempt one goal: each round it picks from the page's DOM candidates plus `end`, up to N actions. Returns a receipt; verify yourself via bcdp_cdp/bcdp_screenshot (a receipt is a report, not proof).",
9605
9742
  parameters: {
9606
9743
  url: {
9607
9744
  type: "string",
9608
9745
  required: true,
9609
- description: "Absolute URL to open, e.g. https://example.com/path."
9746
+ description: "Absolute URL to open."
9610
9747
  },
9611
9748
  goal: {
9612
9749
  type: "string",
@@ -9615,11 +9752,11 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
9615
9752
  },
9616
9753
  successCriteria: {
9617
9754
  type: "string",
9618
- description: "One observable success condition per line. Helps the model decide when to pick `end`."
9755
+ description: "Success condition per line; helps the model decide when to stop."
9619
9756
  },
9620
9757
  maxActions: {
9621
9758
  type: "integer",
9622
- description: "Action budget for the decision model (default 5, capped at 20)."
9759
+ description: "Action budget (default 5, max 20)."
9623
9760
  }
9624
9761
  },
9625
9762
  output: {
@@ -9707,4 +9844,4 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
9707
9844
  }
9708
9845
 
9709
9846
  //#endregion
9710
- export { Config, apply, cdpAttachError, createActiveSpaceTracker, decideCdpAttach, findChromeBinary, findUpstreamPluginInstall, inject, name, resolveEgoEnv, runWithStaleSpaceRetry, shouldReapBrowser };
9847
+ export { Config, STATUS_FACADE_SCRIPT, STATUS_FACADE_SENTINEL, apply, buildEgoToolArgv, cdpAttachError, createActiveSpaceTracker, decideCdpAttach, findChromeBinary, findUpstreamPluginInstall, inject, name, parseSentinel, parseStatusFacades, resolveEgoEnv, runWithStaleSpaceRetry, shouldReapBrowser };