dsh-browser-cdp 1.2.3 → 1.2.4

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
@@ -1059,7 +1059,7 @@ async function probeCliLink(input, io) {
1059
1059
  if (parsed.ok) running = parsed.running;
1060
1060
  }
1061
1061
  const sdkArgs = input.useSdkPath === true && (input.sdkPath ?? "") !== "" ? ["--sdk-path", input.sdkPath] : [];
1062
- const script = `console.log(${JSON.stringify(CLI_READY_SENTINEL)})\n`;
1062
+ const script = `console.log(${JSON.stringify(CLI_READY_SENTINEL)}, typeof taskSpaces, typeof browser)\n`;
1063
1063
  const runHeredoc = (extra) => io.run({
1064
1064
  argv: spawnArgvFor(shape, cliPath, ["nodejs", ...extra]),
1065
1065
  stdin: script,
@@ -1092,12 +1092,15 @@ async function probeCliLink(input, io) {
1092
1092
  message: `spawn failed: ${result.spawnErrorCode}`,
1093
1093
  ...base
1094
1094
  };
1095
- if (result.exitCode !== 0 || !result.stdout.includes(CLI_READY_SENTINEL)) {
1095
+ const facadeMatch = (/* @__PURE__ */ new RegExp(`${CLI_READY_SENTINEL} (\\w+) (\\w+)`)).exec(result.stdout);
1096
+ const facadesOk = input.useSdkPath !== true || facadeMatch?.[1] === "object" && facadeMatch?.[2] === "object";
1097
+ if (result.exitCode !== 0 || !result.stdout.includes(CLI_READY_SENTINEL) || !facadesOk) {
1096
1098
  const tail = (result.stderr || result.stdout).trim().slice(-400);
1099
+ const facadeNote = facadesOk ? "" : `; the SDK harness did not expose the facade (taskSpaces=${facadeMatch?.[1] ?? "undefined"}, browser=${facadeMatch?.[2] ?? "undefined"})`;
1097
1100
  return {
1098
1101
  ok: false,
1099
1102
  code: "cli-probe-failed",
1100
- message: `the ego CLI ran but did not reach the readiness sentinel (exit ${String(result.exitCode)})${tail ? `: ${tail}` : ""}`,
1103
+ message: `the ego CLI ran but did not reach the readiness sentinel (exit ${String(result.exitCode)})${facadeNote}${tail ? `: ${tail}` : ""}`,
1101
1104
  ...base
1102
1105
  };
1103
1106
  }
@@ -1517,6 +1520,7 @@ async function refreshCliAttach(input, cache, suggested, link, now) {
1517
1520
  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
1521
  cliPath: probe.cliPath,
1519
1522
  cliShape: probe.shape,
1523
+ sdkPath: link.useSdkPath === true && probe.warning === void 0 ? input.sdkPath ?? "" : "",
1520
1524
  latencyMs: probe.latencyMs,
1521
1525
  resolvedAt: now()
1522
1526
  });
@@ -3533,11 +3537,11 @@ const CORE = [
3533
3537
  "bcdp_doctor",
3534
3538
  "bcdp_help",
3535
3539
  "bcdp_space_open",
3540
+ "bcdp_space_close",
3536
3541
  "bcdp_navigate",
3537
3542
  "bcdp_snapshot"
3538
3543
  ];
3539
3544
  const BROWSE = [
3540
- "bcdp_space_close",
3541
3545
  "bcdp_click",
3542
3546
  "bcdp_fill",
3543
3547
  "bcdp_key",
@@ -3583,6 +3587,30 @@ const TIER_OF_TOOL = new Map([
3583
3587
  ].flatMap(([tier, names]) => names.map((n) => [n, tier])));
3584
3588
  /** 去掉 `bcdp_`/`ego_` 前缀后的裸名,便于策略表保持前缀无关。 */
3585
3589
  const bareToolName = (name$1) => name$1.replace(/^(?:bcdp|ego)_/, "");
3590
+ /** 批次放行顺序(索引即 rank)。 */
3591
+ const BATCH_ORDER = [
3592
+ "act",
3593
+ "observe",
3594
+ "wait"
3595
+ ];
3596
+ /** `browse` 级工具 → 批次。未登记的名字按 'act' 处理,绝不因缺表而被卡住。 */
3597
+ const BROWSE_BATCH = {
3598
+ click: "act",
3599
+ fill: "act",
3600
+ key: "act",
3601
+ hover: "act",
3602
+ scroll: "act",
3603
+ select: "act",
3604
+ check: "act",
3605
+ screenshot: "observe",
3606
+ page_info: "observe",
3607
+ read_element: "observe",
3608
+ js: "observe",
3609
+ wait: "wait",
3610
+ wait_for_selector: "wait"
3611
+ };
3612
+ /** 某工具的注入批次(前缀无关)。 */
3613
+ const batchOfTool = (name$1) => BROWSE_BATCH[bareToolName(name$1)] ?? "act";
3586
3614
  /**
3587
3615
  * 工具所属分级。未登记的名字落到 `extended`(最严的一档:宁可等活动解锁,
3588
3616
  * 也不让新工具悄悄回到常驻面);调用方应当在启动时打一条 warn,见
@@ -3626,7 +3654,15 @@ function tierAllowed(tier, p) {
3626
3654
  return p.injection === "always" || p.active;
3627
3655
  }
3628
3656
  /** 某工具此刻是否允许注册(名字 → 分级 → 策略)。 */
3629
- const toolAllowed = (name$1, p) => tierAllowed(tierOfTool(name$1), p);
3657
+ function toolAllowed(name$1, p) {
3658
+ const tier = tierOfTool(name$1);
3659
+ if (!tierAllowed(tier, p)) return false;
3660
+ if (tier === "browse" && p.injection !== "always") {
3661
+ const depth = p.batchDepth ?? BATCH_ORDER.length;
3662
+ if (BATCH_ORDER.indexOf(batchOfTool(name$1)) >= depth) return false;
3663
+ }
3664
+ return true;
3665
+ }
3630
3666
  function createTierInjector(o) {
3631
3667
  const label = o.label ?? "dsh-browser-cdp";
3632
3668
  /** 全部已登记工具,插入序。 */
@@ -7323,6 +7359,10 @@ async function openAgentWindow(ctx, cfg) {
7323
7359
  ok: false,
7324
7360
  error: gate
7325
7361
  };
7362
+ if (defaultAttachCache.get().linkKind === EGO_CLI_KIND) {
7363
+ ctx.logger?.info?.("dsh-browser-cdp: ego-cli: browser already visible, skipping --open");
7364
+ return { ok: true };
7365
+ }
7326
7366
  const handle = ctx.subprocess.spawn({
7327
7367
  argv: [...cfg.egoArgvPrefix, "--open"],
7328
7368
  cwd: process.cwd(),
@@ -7370,6 +7410,33 @@ function parseSentinel(stdout) {
7370
7410
  }
7371
7411
  }
7372
7412
  }
7413
+ /** R2/R3 — sentinel + payload for the `bcdp_status` facade probe. @internal exported for tests */
7414
+ const STATUS_FACADE_SENTINEL = "__BCDP_STATUS__";
7415
+ /** @internal exported for tests — the exact heredoc the status probe runs. */
7416
+ const STATUS_FACADE_SCRIPT = `console.log(${JSON.stringify(STATUS_FACADE_SENTINEL)} + JSON.stringify({ taskSpaces: typeof taskSpaces, browser: typeof browser, page: typeof page }))
7417
+ `;
7418
+ /**
7419
+ * Parse the facade payload the status probe prints; `undefined` if absent.
7420
+ * @internal exported for tests
7421
+ */
7422
+ function parseStatusFacades(stdout) {
7423
+ const lines = stdout.split("\n");
7424
+ for (let i = lines.length - 1; i >= 0; i--) {
7425
+ const idx = lines[i].indexOf(STATUS_FACADE_SENTINEL);
7426
+ if (idx === -1) continue;
7427
+ const payload = lines[i].slice(idx + 15).trim();
7428
+ try {
7429
+ const parsed = JSON.parse(payload);
7430
+ return {
7431
+ taskSpaces: typeof parsed.taskSpaces === "string" ? parsed.taskSpaces : "undefined",
7432
+ browser: typeof parsed.browser === "string" ? parsed.browser : "undefined",
7433
+ page: typeof parsed.page === "string" ? parsed.page : "undefined"
7434
+ };
7435
+ } catch {
7436
+ return;
7437
+ }
7438
+ }
7439
+ }
7373
7440
  /**
7374
7441
  * R7 — is the upstream plugin installed anywhere under this DSH home?
7375
7442
  *
@@ -7388,16 +7455,28 @@ function findUpstreamPluginInstall(home = process.env.HOME || process.env.USERPR
7388
7455
  } catch {}
7389
7456
  return "";
7390
7457
  }
7458
+ /**
7459
+ * R1 — argv for one tool run. Single source of truth for the `--sdk-path`
7460
+ * injection: `bcdp_status` and `runEgoScript` must probe/run under the exact
7461
+ * same conditions, otherwise "available" and "actually works" diverge again.
7462
+ * @internal exported for tests
7463
+ */
7464
+ function buildEgoToolArgv(prefix, attach, runtimeArgs) {
7465
+ const extraCliArgs = filterArgs(runtimeArgs, EGO_CLI_BLOCKED);
7466
+ const sdkArgs = attach.linkKind === EGO_CLI_KIND && (attach.sdkPath ?? "") !== "" ? ["--sdk-path", attach.sdkPath] : [];
7467
+ return [
7468
+ ...prefix,
7469
+ "nodejs",
7470
+ ...sdkArgs,
7471
+ ...extraCliArgs
7472
+ ];
7473
+ }
7391
7474
  async function runEgoScript(subprocess, script, exec, cfg, graceOverrideMs) {
7392
7475
  let handle;
7393
7476
  try {
7394
- const extraCliArgs = filterArgs(cfg.runtimeArgs ?? "", EGO_CLI_BLOCKED);
7477
+ const attach = defaultAttachCache.get();
7395
7478
  handle = subprocess.spawn({
7396
- argv: [
7397
- ...cfg.egoArgvPrefix,
7398
- "nodejs",
7399
- ...extraCliArgs
7400
- ],
7479
+ argv: buildEgoToolArgv(cfg.egoArgvPrefix, attach, cfg.runtimeArgs ?? ""),
7401
7480
  cwd: process.cwd(),
7402
7481
  env: resolveEgoEnv(cfg),
7403
7482
  stdio: {
@@ -7702,6 +7781,7 @@ function apply(ctx, config = {}) {
7702
7781
  }
7703
7782
  };
7704
7783
  let browserActive = false;
7784
+ let browseBatchDepth = 0;
7705
7785
  const tiers = createTierInjector({
7706
7786
  register: (tool) => {
7707
7787
  const dispose = ctx.tools.register(tool);
@@ -7717,15 +7797,20 @@ function apply(ctx, config = {}) {
7717
7797
  jevKey: cfg.jevKey,
7718
7798
  layaKey: cfg.layaKey
7719
7799
  }),
7720
- active: browserActive
7800
+ active: browserActive,
7801
+ batchDepth: browseBatchDepth
7721
7802
  }),
7722
7803
  logger: ctx.logger
7723
7804
  });
7724
- /** 活动信号:只翻一次牌,重复调用零成本。 */
7805
+ /**
7806
+ * 活动信号:每次 bcdp_* 调用推进 browse 批次(act → observe → wait),
7807
+ * 到顶即止。只有注入面真的变了才 reapply。
7808
+ */
7725
7809
  const pulseActivity = () => {
7726
- if (browserActive) return;
7810
+ const before = browseBatchDepth;
7727
7811
  browserActive = true;
7728
- tiers.reapply();
7812
+ browseBatchDepth = Math.min(BATCH_ORDER.length, browseBatchDepth + 1);
7813
+ if (before !== browseBatchDepth) tiers.reapply();
7729
7814
  };
7730
7815
  {
7731
7816
  const offActivity = onEgoActivity(pulseActivity);
@@ -7738,6 +7823,7 @@ function apply(ctx, config = {}) {
7738
7823
  const sealAfterReap = () => {
7739
7824
  if (cfg.toolInjection !== "lazy" || !browserActive) return;
7740
7825
  browserActive = false;
7826
+ browseBatchDepth = 0;
7741
7827
  tiers.reapply();
7742
7828
  };
7743
7829
  /**
@@ -7867,6 +7953,11 @@ function apply(ctx, config = {}) {
7867
7953
  const last = getLastEgoActivity();
7868
7954
  if (!shouldReapBrowser(Date.now(), last, cfg.idleTimeoutMin)) return;
7869
7955
  if (last <= reapedFor) return;
7956
+ if (defaultAttachCache.get().linkKind === EGO_CLI_KIND) {
7957
+ reapedFor = last;
7958
+ ctx.logger?.info?.("dsh-browser-cdp: idle reaper skipped: ego-cli owns the user's browser (never --stop it)");
7959
+ return;
7960
+ }
7870
7961
  try {
7871
7962
  const { localBrowserInfo, stopLocalBrowser: stopLocalBrowser$1 } = await import("./launcher-h0Ca5NV1.js");
7872
7963
  if (localBrowserInfo()) {
@@ -7909,6 +8000,10 @@ function apply(ctx, config = {}) {
7909
8000
  }, "dsh-browser-cdp: idle reaper");
7910
8001
  ctx.effect?.(() => {
7911
8002
  try {
8003
+ if (defaultAttachCache.get().linkKind === EGO_CLI_KIND) {
8004
+ ctx.logger?.info?.("dsh-browser-cdp: teardown skipped --stop: ego-cli owns the user's browser");
8005
+ return;
8006
+ }
7912
8007
  ctx.subprocess.spawn({
7913
8008
  argv: [
7914
8009
  process.execPath,
@@ -7928,11 +8023,11 @@ function apply(ctx, config = {}) {
7928
8023
  });
7929
8024
  ctx.logger?.info?.(`dsh-browser-cdp: mounted (egoBin=${cfg.egoBin}, defaultSpace=${cfg.defaultSpace})`);
7930
8025
  }
7931
- /** `bcdp_status` probes CLI availability by running the real `--status` path. */
8026
+ /** `bcdp_status` probes the SAME channel work uses: a `nodejs` heredoc. */
7932
8027
  function registerEgoStatus(ctx, cfg, reg, tiers) {
7933
8028
  reg(defineTool({
7934
8029
  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\".",
8030
+ 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
8031
  parameters: {},
7937
8032
  output: {
7938
8033
  schema: {
@@ -7948,34 +8043,45 @@ function registerEgoStatus(ctx, cfg, reg, tiers) {
7948
8043
  required: true
7949
8044
  },
7950
8045
  path: { type: "string" },
7951
- exitCode: { type: "integer" }
8046
+ exitCode: { type: "integer" },
8047
+ facades: {
8048
+ type: "object",
8049
+ additionalProperties: false,
8050
+ properties: {
8051
+ taskSpaces: { type: "string" },
8052
+ browser: { type: "string" },
8053
+ page: { type: "string" }
8054
+ }
8055
+ }
7952
8056
  }
7953
8057
  },
7954
8058
  render: renderText
7955
8059
  },
7956
- timeoutMs: 25e3,
8060
+ timeoutMs: 15e3,
7957
8061
  execute: async () => {
7958
8062
  tiers.pulse();
7959
8063
  return withEgoLock(async () => {
7960
8064
  try {
8065
+ const attach = defaultAttachCache.get();
7961
8066
  const handle = ctx.subprocess.spawn({
7962
- argv: [...cfg.egoArgvPrefix, "--status"],
8067
+ argv: buildEgoToolArgv(cfg.egoArgvPrefix, attach, cfg.runtimeArgs ?? ""),
7963
8068
  cwd: process.cwd(),
7964
8069
  env: resolveEgoEnv(cfg),
7965
8070
  stdio: {
7966
- stdin: { data: "" },
8071
+ stdin: { data: STATUS_FACADE_SCRIPT },
7967
8072
  stdout: { maxBytes: 4096 },
7968
8073
  stderr: { maxBytes: 4096 }
7969
8074
  },
7970
- graceMs: 25e3
8075
+ graceMs: 15e3
7971
8076
  });
7972
8077
  const outcome = await handle.done;
7973
- const out = readAll(handle.collected.stdout).trim();
8078
+ const facades = parseStatusFacades(readAll(handle.collected.stdout));
7974
8079
  return {
7975
8080
  ok: true,
7976
- available: outcome.exitCode === 0 && out !== "",
7977
- path: cfg.egoBin,
7978
- exitCode: outcome.exitCode
8081
+ available: outcome.exitCode === 0 && facades?.taskSpaces === "object" && facades?.browser === "object",
8082
+ path: attach.cliPath ?? cfg.egoBin,
8083
+ exitCode: outcome.exitCode,
8084
+ ...facades ? { facades } : {}
7979
8085
  };
7980
8086
  } catch (err) {
7981
8087
  return {
@@ -8074,27 +8180,27 @@ function registerAuthFlush(ctx, cfg, reg) {
8074
8180
  function registerLoginImport(ctx, cfg, reg) {
8075
8181
  reg(defineTool({
8076
8182
  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.",
8183
+ 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
8184
  parameters: {
8079
8185
  source: {
8080
8186
  type: "string",
8081
- description: "chrome | edge | brave | auto (default: auto = first detected browser)."
8187
+ description: "chrome | edge | brave | auto (default auto)."
8082
8188
  },
8083
8189
  domains: {
8084
8190
  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."
8191
+ description: "Domains to import, e.g. [\"bilibili.com\"] (subdomains included). Omit = all cookies; prefer an explicit list."
8086
8192
  },
8087
8193
  profile: {
8088
8194
  type: "string",
8089
- description: "Source browser profile directory name, e.g. \"Default\" or \"Profile 1\" (default: the first profile)."
8195
+ description: "Source profile dir, e.g. \"Default\" (default: first profile)."
8090
8196
  },
8091
8197
  closeSource: {
8092
8198
  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."
8199
+ description: "true = gracefully close a running source browser first (tabs restore); false = return an actionable error (default)."
8094
8200
  },
8095
8201
  dryRun: {
8096
8202
  type: "boolean",
8097
- description: "true = only report what would be imported (domains + cookie counts), write nothing."
8203
+ description: "true = report what would be imported; write nothing."
8098
8204
  }
8099
8205
  },
8100
8206
  output: {
@@ -8247,27 +8353,27 @@ function registerActionTools(ctx, cfg, reg) {
8247
8353
  }));
8248
8354
  reg(t({
8249
8355
  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.",
8356
+ description: "Click an element: CSS/xpath/loc/ref selector, or viewport x+y coordinates.",
8251
8357
  parameters: {
8252
8358
  selector: {
8253
8359
  type: "string",
8254
- description: "CSS selector, xpath=..., loc=..., or ref=N from the snapshot. Required unless x/y are given."
8360
+ description: "CSS/xpath/loc/ref=N from bcdp_snapshot; required unless x,y."
8255
8361
  },
8256
8362
  x: {
8257
8363
  type: "number",
8258
- description: "Viewport x coordinate for a coordinate click."
8364
+ description: "Viewport x for a coordinate click."
8259
8365
  },
8260
8366
  y: {
8261
8367
  type: "number",
8262
- description: "Viewport y coordinate for a coordinate click."
8368
+ description: "Viewport y for a coordinate click."
8263
8369
  },
8264
8370
  label: {
8265
8371
  type: "string",
8266
- description: "Short human label for the action, e.g. \"click submit button\"."
8372
+ description: "Short action label, e.g. \"click submit\"."
8267
8373
  },
8268
8374
  double: {
8269
8375
  type: "boolean",
8270
- description: "Double-click instead of single-click. Useful for opening files/rows or triggering dblclick handlers."
8376
+ description: "Double-click instead of single."
8271
8377
  },
8272
8378
  space: spaceParam
8273
8379
  },
@@ -8377,20 +8483,20 @@ function registerActionTools(ctx, cfg, reg) {
8377
8483
  }));
8378
8484
  reg(t({
8379
8485
  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.",
8486
+ description: "Wait until a CSS selector appears (state=visible, default) or disappears (state=hidden). Use instead of a fixed wait for async pages.",
8381
8487
  parameters: {
8382
8488
  selector: {
8383
8489
  type: "string",
8384
8490
  required: true,
8385
- description: "CSS selector of the element to wait for, e.g. '.results' or '[data-id=done]'."
8491
+ description: "CSS selector to wait for, e.g. '.results' or '[data-id=done]'."
8386
8492
  },
8387
8493
  state: {
8388
8494
  type: "string",
8389
- description: "Target state: 'visible' (default) | 'attached' | 'hidden' | 'detached'."
8495
+ description: "'visible' (default) | 'attached' | 'hidden' | 'detached'."
8390
8496
  },
8391
8497
  timeout: {
8392
8498
  type: "number",
8393
- description: "How long to wait in ms (default 10000)."
8499
+ description: "Wait in ms (default 10000)."
8394
8500
  },
8395
8501
  space: spaceParam
8396
8502
  },
@@ -8423,20 +8529,20 @@ function registerActionTools(ctx, cfg, reg) {
8423
8529
  }));
8424
8530
  reg(t({
8425
8531
  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.",
8532
+ description: "Wait for a network response matching a URL/glob/regex and return it; optionally return the body (text or JSON).",
8427
8533
  parameters: {
8428
8534
  url: {
8429
8535
  type: "string",
8430
8536
  required: true,
8431
- description: "URL/glob/regex to match, e.g. '/api/search' or 'https://*.com/data'."
8537
+ description: "URL/glob/regex, e.g. '/api/search' or 'https://*.com/data'."
8432
8538
  },
8433
8539
  timeout: {
8434
8540
  type: "number",
8435
- description: "How long to wait in ms (default 10000)."
8541
+ description: "Wait in ms (default 10000)."
8436
8542
  },
8437
8543
  body: {
8438
8544
  type: "string",
8439
- description: "Return the response body: 'none' (default) | 'text' | 'json'."
8545
+ description: "'none' (default) | 'text' | 'json'."
8440
8546
  },
8441
8547
  space: spaceParam
8442
8548
  },
@@ -8449,15 +8555,15 @@ function registerActionTools(ctx, cfg, reg) {
8449
8555
  }));
8450
8556
  reg(t({
8451
8557
  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).",
8558
+ description: "Press a key/combo ('Enter', 'Tab', 'Control+a', 'Escape') or type text character-by-character.",
8453
8559
  parameters: {
8454
8560
  key: {
8455
8561
  type: "string",
8456
- description: "Key or combo: 'Enter', 'Tab', 'Control+c', 'Meta+v', 'ArrowDown', 'Escape', 'F5', etc. (ignored when `text` is given)."
8562
+ description: "Key/combo: 'Enter', 'Control+c', 'ArrowDown', 'F5' (ignored when text is given)."
8457
8563
  },
8458
8564
  text: {
8459
8565
  type: "string",
8460
- description: "Type this text character-by-character (keyboard.type). Use instead of `key` for typing words into the focused element."
8566
+ description: "Type this text instead (keyboard.type)."
8461
8567
  },
8462
8568
  space: spaceParam
8463
8569
  },
@@ -8496,16 +8602,16 @@ function registerActionTools(ctx, cfg, reg) {
8496
8602
  }));
8497
8603
  reg(t({
8498
8604
  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.",
8605
+ description: "Read one element: text, HTML, value, an attribute, or visible/enabled/count.",
8500
8606
  parameters: {
8501
8607
  selector: {
8502
8608
  type: "string",
8503
8609
  required: true,
8504
- description: "CSS selector of the target element."
8610
+ description: "CSS selector of the target."
8505
8611
  },
8506
8612
  what: {
8507
8613
  type: "string",
8508
- description: "What to read: 'text' (default) | 'html' | 'value' | 'attribute' | 'visible' | 'enabled' | 'count'."
8614
+ description: "'text' (default) | 'html' | 'value' | 'attribute' | 'visible' | 'enabled' | 'count'."
8509
8615
  },
8510
8616
  attribute: {
8511
8617
  type: "string",
@@ -8633,23 +8739,23 @@ function registerActionTools(ctx, cfg, reg) {
8633
8739
  }));
8634
8740
  reg(t({
8635
8741
  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 }.",
8742
+ 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
8743
  parameters: {
8638
8744
  triggerSelector: {
8639
8745
  type: "string",
8640
- description: "CSS selector of the element (button/link) whose click starts the download."
8746
+ description: "CSS selector of the button/link whose click starts the download."
8641
8747
  },
8642
8748
  triggerScript: {
8643
8749
  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."
8750
+ description: "JS snippet that triggers the download (runs before waiting)."
8645
8751
  },
8646
8752
  savePath: {
8647
8753
  type: "string",
8648
- description: "Optional absolute destination path to also copy the downloaded file to. Otherwise only the temp-captured path is returned."
8754
+ description: "Absolute path to also copy the file to."
8649
8755
  },
8650
8756
  timeout: {
8651
8757
  type: "number",
8652
- description: "How long to wait for the download in ms (default 30000)."
8758
+ description: "Wait timeout in ms (default 30000)."
8653
8759
  },
8654
8760
  space: spaceParam
8655
8761
  },
@@ -8707,7 +8813,7 @@ function registerActionTools(ctx, cfg, reg) {
8707
8813
  }));
8708
8814
  reg(t({
8709
8815
  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.)",
8816
+ 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
8817
  parameters: {
8712
8818
  url: {
8713
8819
  type: "string",
@@ -8716,7 +8822,7 @@ function registerActionTools(ctx, cfg, reg) {
8716
8822
  },
8717
8823
  method: {
8718
8824
  type: "string",
8719
- description: "HTTP method, default GET."
8825
+ description: "HTTP method (default GET)."
8720
8826
  },
8721
8827
  headers: {
8722
8828
  type: "object",
@@ -8725,7 +8831,7 @@ function registerActionTools(ctx, cfg, reg) {
8725
8831
  },
8726
8832
  body: {
8727
8833
  type: "string",
8728
- description: "Request body (for POST/PUT)."
8834
+ description: "Request body (POST/PUT)."
8729
8835
  },
8730
8836
  timeout: {
8731
8837
  type: "number",
@@ -8733,11 +8839,11 @@ function registerActionTools(ctx, cfg, reg) {
8733
8839
  },
8734
8840
  mode: {
8735
8841
  type: "string",
8736
- description: "'browser' (default) runs via the page context; 'server' uses Node-side fetch.server."
8842
+ description: "'browser' (default) or 'server' (Node-side fetch)."
8737
8843
  },
8738
8844
  credentials: {
8739
8845
  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."
8846
+ description: "Browser mode: 'include' sends the profile's cookies cross-origin; 'omit'/'same-origin' also accepted. Default: engine default."
8741
8847
  },
8742
8848
  space: spaceParam
8743
8849
  },
@@ -9234,28 +9340,28 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
9234
9340
  }));
9235
9341
  reg(defineTool({
9236
9342
  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.",
9343
+ description: "Assemble the JEV/Laya judgement request for the current page + intent; return it (dryRun) or send it.",
9238
9344
  parameters: {
9239
9345
  goal: {
9240
9346
  type: "string",
9241
9347
  required: true,
9242
- description: "What we are trying to accomplish, in your own words."
9348
+ description: "What we are trying to accomplish."
9243
9349
  },
9244
9350
  kind: {
9245
9351
  type: "string",
9246
- description: "Intent kind: navigate | extract | fill | click | verify | other (default other)."
9352
+ description: "navigate | extract | fill | click | verify | other."
9247
9353
  },
9248
9354
  hints: {
9249
9355
  type: "string",
9250
- description: "One target hint per line. Hints only — never a CSS selector."
9356
+ description: "Target hint per line; never a selector."
9251
9357
  },
9252
9358
  successCriteria: {
9253
9359
  type: "string",
9254
- description: "One observable success condition per line."
9360
+ description: "Success condition per line."
9255
9361
  },
9256
9362
  stopConditions: {
9257
9363
  type: "string",
9258
- description: "One stop condition per line, e.g. \"a captcha appears\"."
9364
+ description: "Stop condition per line."
9259
9365
  },
9260
9366
  dryRun: {
9261
9367
  type: "boolean",
@@ -9263,19 +9369,19 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
9263
9369
  },
9264
9370
  includeImage: {
9265
9371
  type: "boolean",
9266
- description: "Also return the base64 frame image (default false)."
9372
+ description: "Also return the base64 frame (default false)."
9267
9373
  },
9268
9374
  maxCandidates: {
9269
9375
  type: "integer",
9270
- description: "Override the candidate ceiling for this call."
9376
+ description: "Candidate ceiling for this call."
9271
9377
  },
9272
9378
  round: {
9273
9379
  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."
9380
+ description: "'control' | 'chapter' | 'pick' (default control)."
9275
9381
  },
9276
9382
  chapter: {
9277
9383
  type: "string",
9278
- description: "Chapter key to restrict a 'pick' round to, e.g. form#1. From the chapter round's options."
9384
+ description: "Chapter key for a 'pick' round, e.g. form#1."
9279
9385
  }
9280
9386
  },
9281
9387
  output: {
@@ -9493,7 +9599,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
9493
9599
  }));
9494
9600
  reg(defineTool({
9495
9601
  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.",
9602
+ description: "Run the JEV loop for one goal; returns a step trace.",
9497
9603
  parameters: {
9498
9604
  goal: {
9499
9605
  type: "string",
@@ -9506,23 +9612,23 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
9506
9612
  },
9507
9613
  hints: {
9508
9614
  type: "string",
9509
- description: "One target hint per line (never a selector)."
9615
+ description: "Target hint per line (never a selector)."
9510
9616
  },
9511
9617
  successCriteria: {
9512
9618
  type: "string",
9513
- description: "One observable success condition per line. REQUIRED for a trustworthy `done`."
9619
+ description: "Success condition per line; required for done."
9514
9620
  },
9515
9621
  stopConditions: {
9516
9622
  type: "string",
9517
- description: "One stop condition per line."
9623
+ description: "Stop condition per line."
9518
9624
  },
9519
9625
  stepBudget: {
9520
9626
  type: "integer",
9521
- description: "Judgement rounds allowed (default from settings)."
9627
+ description: "Max judgement rounds (default settings)."
9522
9628
  },
9523
9629
  wallMs: {
9524
9630
  type: "integer",
9525
- description: "Wall-clock ceiling in ms (default from settings)."
9631
+ description: "Wall-clock ceiling in ms (default settings)."
9526
9632
  }
9527
9633
  },
9528
9634
  output: {
@@ -9601,12 +9707,12 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
9601
9707
  }));
9602
9708
  reg(defineTool({
9603
9709
  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.",
9710
+ 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
9711
  parameters: {
9606
9712
  url: {
9607
9713
  type: "string",
9608
9714
  required: true,
9609
- description: "Absolute URL to open, e.g. https://example.com/path."
9715
+ description: "Absolute URL to open."
9610
9716
  },
9611
9717
  goal: {
9612
9718
  type: "string",
@@ -9615,11 +9721,11 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
9615
9721
  },
9616
9722
  successCriteria: {
9617
9723
  type: "string",
9618
- description: "One observable success condition per line. Helps the model decide when to pick `end`."
9724
+ description: "Success condition per line; helps the model decide when to stop."
9619
9725
  },
9620
9726
  maxActions: {
9621
9727
  type: "integer",
9622
- description: "Action budget for the decision model (default 5, capped at 20)."
9728
+ description: "Action budget (default 5, max 20)."
9623
9729
  }
9624
9730
  },
9625
9731
  output: {
@@ -9707,4 +9813,4 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
9707
9813
  }
9708
9814
 
9709
9815
  //#endregion
9710
- export { Config, apply, cdpAttachError, createActiveSpaceTracker, decideCdpAttach, findChromeBinary, findUpstreamPluginInstall, inject, name, resolveEgoEnv, runWithStaleSpaceRetry, shouldReapBrowser };
9816
+ export { Config, STATUS_FACADE_SCRIPT, STATUS_FACADE_SENTINEL, apply, buildEgoToolArgv, cdpAttachError, createActiveSpaceTracker, decideCdpAttach, findChromeBinary, findUpstreamPluginInstall, inject, name, parseStatusFacades, resolveEgoEnv, runWithStaleSpaceRetry, shouldReapBrowser };