dsh-browser-cdp 1.14.9 → 1.14.11

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
@@ -1,4 +1,4 @@
1
- import { d as localBrowserInfo, f as stopLocalBrowser, l as launchLocalBrowser, p as windowsEnvChromeCandidates } from "./launcher-DfE6ivh_.js";
1
+ import { _ as windowsEnvChromeCandidates, f as launchLocalBrowser, g as stopLocalBrowser, h as posixChromeCandidates, m as localBrowserInfo, s as darwinChromeCandidates } from "./launcher-BnxRC9AU.js";
2
2
  import { createRequire } from "node:module";
3
3
  import { defineTool } from "@deepseek-ai/dsh-tools";
4
4
  import { appendFileSync, constants, createReadStream, createWriteStream, existsSync, mkdirSync, readFileSync, readdirSync } from "node:fs";
@@ -2164,15 +2164,16 @@ function createFocusStore(now = () => Date.now()) {
2164
2164
  };
2165
2165
  return {
2166
2166
  get: () => focus,
2167
- set(targetId, source, at) {
2167
+ set(targetId, source, at, sessionId) {
2168
2168
  const id = String(targetId ?? "").trim();
2169
+ const sid = typeof sessionId === "string" && sessionId.trim() !== "" ? sessionId.trim() : void 0;
2169
2170
  if (id === "") {
2170
2171
  if (focus === null) return null;
2171
2172
  focus = null;
2172
2173
  emit();
2173
2174
  return null;
2174
2175
  }
2175
- if (focus !== null && focus.targetId === id && focus.source === source) {
2176
+ if (focus !== null && focus.targetId === id && focus.source === source && focus.sessionId === sid) {
2176
2177
  focus = {
2177
2178
  ...focus,
2178
2179
  at: at ?? now()
@@ -2180,6 +2181,7 @@ function createFocusStore(now = () => Date.now()) {
2180
2181
  return focus;
2181
2182
  }
2182
2183
  focus = {
2184
+ ...sid === void 0 ? {} : { sessionId: sid },
2183
2185
  targetId: id,
2184
2186
  source,
2185
2187
  at: at ?? now()
@@ -2261,7 +2263,7 @@ function focusIdFrom(value) {
2261
2263
  *
2262
2264
  * Keep in sync with package.json — `node scripts/bump.mjs <version>` writes both.
2263
2265
  */
2264
- const CLIENT_BUILD = "1.12.2";
2266
+ const CLIENT_BUILD = "1.14.11";
2265
2267
 
2266
2268
  //#endregion
2267
2269
  //#region src/cast-server.ts
@@ -2413,6 +2415,91 @@ function getLastEgoActivity() {
2413
2415
  }
2414
2416
  const activityListeners = /* @__PURE__ */ new Set();
2415
2417
  /**
2418
+ * 面板活动药丸的动作词(与页面内覆盖层的词表同义,但**故意分开维护**)。
2419
+ *
2420
+ * 为什么 host 侧也要一份:客户端 bundle 与 host 是两条独立产物,客户端不能
2421
+ * `import` 这个模块;而让两边各自硬编码又必然漂移。取舍是——**host 侧是唯一
2422
+ * 真源**(它查表后把 {zh,en} 塞进 SSE payload),客户端只负责显示,
2423
+ * 所以客户端的词永远跟着 host 走,页面角标那份则是独立的、只影响页面。
2424
+ *
2425
+ * 未列入的工具(`bcdp_status`、`bcdp_help` 这类元工具)没有动作词:它们不改
2426
+ * 页面,"正在读取页面"对它们来说是假话,宁可不显示药丸。
2427
+ */
2428
+ const TOOL_ACTION_LABELS = {
2429
+ bcdp_snapshot: {
2430
+ zh: "正在读取页面",
2431
+ en: "Reading page"
2432
+ },
2433
+ bcdp_page_info: {
2434
+ zh: "正在读取页面",
2435
+ en: "Reading page"
2436
+ },
2437
+ bcdp_js: {
2438
+ zh: "正在执行脚本",
2439
+ en: "Running script"
2440
+ },
2441
+ bcdp_script: {
2442
+ zh: "正在执行脚本",
2443
+ en: "Running script"
2444
+ },
2445
+ bcdp_click: {
2446
+ zh: "正在点击",
2447
+ en: "Clicking"
2448
+ },
2449
+ bcdp_fill: {
2450
+ zh: "正在输入",
2451
+ en: "Typing"
2452
+ },
2453
+ bcdp_key: {
2454
+ zh: "正在按键",
2455
+ en: "Pressing keys"
2456
+ },
2457
+ bcdp_scroll: {
2458
+ zh: "正在滚动",
2459
+ en: "Scrolling"
2460
+ },
2461
+ bcdp_navigate: {
2462
+ zh: "正在打开页面",
2463
+ en: "Navigating"
2464
+ },
2465
+ bcdp_screenshot: {
2466
+ zh: "正在截图",
2467
+ en: "Screenshot"
2468
+ },
2469
+ bcdp_hover: {
2470
+ zh: "正在悬停",
2471
+ en: "Hovering"
2472
+ },
2473
+ bcdp_select: {
2474
+ zh: "正在选择",
2475
+ en: "Selecting"
2476
+ },
2477
+ bcdp_check: {
2478
+ zh: "正在勾选",
2479
+ en: "Checking"
2480
+ },
2481
+ bcdp_drag: {
2482
+ zh: "正在拖拽",
2483
+ en: "Dragging"
2484
+ },
2485
+ bcdp_wait: {
2486
+ zh: "正在等待",
2487
+ en: "Waiting"
2488
+ },
2489
+ bcdp_tab: {
2490
+ zh: "正在切换标签页",
2491
+ en: "Tab"
2492
+ },
2493
+ bcdp_upload: {
2494
+ zh: "正在上传",
2495
+ en: "Uploading"
2496
+ },
2497
+ bcdp_download: {
2498
+ zh: "正在下载",
2499
+ en: "Downloading"
2500
+ }
2501
+ };
2502
+ /**
2416
2503
  * Subscribe to "one bcdp_* call just landed".
2417
2504
  * @returns the unsubscribe function.
2418
2505
  */
@@ -2422,16 +2509,21 @@ function onEgoActivity(cb) {
2422
2509
  activityListeners.delete(cb);
2423
2510
  };
2424
2511
  }
2425
- function markEgoToolCall(sessionId) {
2512
+ function markEgoToolCall(sessionId, toolName) {
2426
2513
  toolCallCount += 1;
2427
2514
  lastEgoActivity = Date.now();
2428
2515
  for (const cb of [...activityListeners]) try {
2429
2516
  cb(sessionId);
2430
2517
  } catch {}
2431
- const payload = sessionId === void 0 || sessionId === "" ? { count: toolCallCount } : {
2518
+ const label = toolName === void 0 ? void 0 : TOOL_ACTION_LABELS[toolName];
2519
+ let payload = sessionId === void 0 || sessionId === "" ? { count: toolCallCount } : {
2432
2520
  count: toolCallCount,
2433
2521
  sessionId
2434
2522
  };
2523
+ if (label !== void 0) payload = {
2524
+ ...payload,
2525
+ label
2526
+ };
2435
2527
  const frame = `event: tool-call\ndata: ${JSON.stringify(payload)}\n\n`;
2436
2528
  for (const res of sseClients) try {
2437
2529
  res.write(frame);
@@ -2495,7 +2587,8 @@ function broadcastFocus(focus) {
2495
2587
  const payload = focus === null ? null : {
2496
2588
  targetId: focus.targetId,
2497
2589
  source: focus.source,
2498
- at: focus.at
2590
+ at: focus.at,
2591
+ ...focus.sessionId === void 0 ? {} : { sessionId: focus.sessionId }
2499
2592
  };
2500
2593
  const chunk = `event: focus\ndata: ${JSON.stringify(payload)}\n\n`;
2501
2594
  for (const client of sseClients) try {
@@ -2519,10 +2612,14 @@ function setFocusPusher(fn) {
2519
2612
  *
2520
2613
  * This is the single entry point for BOTH producers: an operator click and a
2521
2614
  * tool result that reports the tab it just drove.
2615
+ *
2616
+ * A tool result also knows WHICH session drove it (`sessionId`), so the panel can
2617
+ * answer "who is driving this page" instead of guessing from the tool-call
2618
+ * counter. Operator paths leave it out and read as "you".
2522
2619
  */
2523
- async function pushFocus(targetId, source = "agent") {
2620
+ async function pushFocus(targetId, source = "agent", sessionId) {
2524
2621
  const id = String(targetId ?? "").trim();
2525
- const focus = defaultFocusStore.set(id, source);
2622
+ const focus = defaultFocusStore.set(id, source, void 0, sessionId);
2526
2623
  broadcastFocus(focus);
2527
2624
  if (id !== "" && focusPusher !== null) {
2528
2625
  const result = await focusPusher(id).catch(() => null);
@@ -10897,6 +10994,62 @@ const AUTO_SPACE_PREFIX = "dsh-agent-";
10897
10994
  const DEFAULT_MAX_OUTPUT_BYTES = 4 * 1024 * 1024;
10898
10995
  const DEFAULT_GRACE_MS = 15e3;
10899
10996
  const TOOL_TIMEOUT_MS = 12e4;
10997
+ /**
10998
+ * 页面内活动覆盖层(CDP 路径):agent 每次真正碰页面前,先在页面右上角挂一个
10999
+ * 「DSH · 正在读取页面 / 点击 / 输入 …」的小徽标,让正在看同一屏的人知道
11000
+ * 浏览器正在被谁驱动、在做什么。
11001
+ *
11002
+ * 约束(都是为了不污染 agent 自己的读取面):
11003
+ * - **closed shadow DOM**:页面 innerText / 正文抽取看不到覆盖层文字;
11004
+ * - `aria-hidden="true"`:AX 树 / bcdp_snapshot 的元素编号不会把徽标算进去;
11005
+ * - `pointer-events:none`:绝不挡住真实点击;
11006
+ * - 全部 try/catch + 4s 自动淡出:覆盖层失败绝不影响工具本身。
11007
+ *
11008
+ * 只在 ego/CDP 通道的 buildScript 前缀里注入(tabbit 的 exec 面不走此路径)。
11009
+ */
11010
+ const OVERLAY_ACTIONS = TOOL_ACTION_LABELS;
11011
+ /** 页面内覆盖层更新表达式(`page.evaluate` 的字符串形式)。 */
11012
+ function pageOverlayExpr(zh, en) {
11013
+ return `(function(){
11014
+ try {
11015
+ var __zh = ((navigator.language||'').toLowerCase().indexOf('zh') === 0);
11016
+ var __label = __zh ? ${j(zh)} : ${j(en)};
11017
+ var host = document.getElementById('__dsh_overlay__');
11018
+ if (!host) {
11019
+ host = document.createElement('div');
11020
+ host.id = '__dsh_overlay__';
11021
+ host.setAttribute('aria-hidden', 'true');
11022
+ host.style.cssText = 'position:fixed;right:16px;top:16px;z-index:2147483647;pointer-events:none;transition:opacity .25s;';
11023
+ var root = host.attachShadow ? host.attachShadow({ mode: 'closed' }) : host;
11024
+ root.innerHTML = '<style>#b{display:flex;align-items:center;gap:6px;padding:6px 10px;border-radius:999px;background:rgba(17,24,39,.92);color:#fff;font:12px/1.4 -apple-system,BlinkMacSystemFont,Segoe UI,sans-serif;box-shadow:0 4px 16px rgba(0,0,0,.28);white-space:nowrap}#d{width:6px;height:6px;border-radius:50%;background:#60a5fa;display:inline-block}</style><div id="b"><span id="d"></span><span id="t"></span></div>';
11025
+ document.documentElement.appendChild(host);
11026
+ window.__dshOverlayRoot = root;
11027
+ }
11028
+ var r = window.__dshOverlayRoot || host;
11029
+ var t = r.querySelector ? r.querySelector('#t') : null;
11030
+ if (t) t.textContent = 'DSH · ' + __label;
11031
+ host.style.opacity = '1';
11032
+ clearTimeout(window.__dshOverlayTimer);
11033
+ window.__dshOverlayTimer = setTimeout(function(){ try { host.style.opacity = '0'; } catch(e){} }, 4000);
11034
+ } catch (e) {}
11035
+ })()`;
11036
+ }
11037
+ /** 给脚本加一行覆盖层更新前缀;未知工具原样返回(零开销)。 */
11038
+ /**
11039
+ * 页面覆盖层**不接**的工具(词表里仍有它们,见下方注释)。
11040
+ *
11041
+ * `bcdp_wait` 的 `op=function` 脚本必须让 `waitForFunction(...)` 处在最外层——
11042
+ * 包裹在 try 里会撞 SDK 的 "Object reference chain is too long"(P0-2 实测)。
11043
+ * 覆盖层前缀本身就是一个 try 块,两者不能共存;因此页面侧让位,
11044
+ * 而**面板药丸照旧显示「正在等待」**——面板不往页面里塞脚本,没有这条约束。
11045
+ */
11046
+ const PAGE_OVERLAY_EXCLUDED = new Set(["bcdp_wait"]);
11047
+ function withPageOverlay(name$1, script) {
11048
+ if (PAGE_OVERLAY_EXCLUDED.has(name$1)) return script;
11049
+ const action = OVERLAY_ACTIONS[name$1];
11050
+ if (action === void 0) return script;
11051
+ return `try { await page.evaluate(${j(pageOverlayExpr(action.zh, action.en))}) } catch (__ov) {}\n` + script;
11052
+ }
10900
11053
  /** Build the script that runs the probe and emits a sentinel payload. */
10901
11054
  function humanCheckScript(space) {
10902
11055
  return `${useSpace(space)}${ensureRealTab()}let __hc = null\ntry { __hc = await page.evaluate(${j(HUMAN_CHECK_PROBE)}) } catch { __hc = null }\nconsole.log('${SENTINEL}' + JSON.stringify({ ok: true, humanCheck: __hc }))\n`;
@@ -11144,17 +11297,6 @@ const BUNDLED_WRAPPER = fileURLToPath(new URL("../bin/cdp-chrome-wrapper.sh", im
11144
11297
  const IS_WIN = process.platform === "win32";
11145
11298
  const IS_DARWIN = process.platform === "darwin";
11146
11299
  const AUTO_ADAPT_OFF = /^(0|false|no)$/i.test(process.env.EGO_BROWSER_AUTO_ADAPT ?? "");
11147
- const COMMON_CHROME_BINS = [
11148
- "google-chrome-stable",
11149
- "google-chrome",
11150
- "chromium",
11151
- "chromium-browser",
11152
- "/usr/bin/google-chrome-stable",
11153
- "/usr/bin/google-chrome",
11154
- "/usr/bin/chromium",
11155
- "/usr/bin/chromium-browser",
11156
- "/opt/google/chrome/google-chrome"
11157
- ];
11158
11300
  /** Windows registry-free probe of the usual install dirs (no subprocess). */
11159
11301
  function windowsChromeCandidates() {
11160
11302
  return windowsEnvChromeCandidates(process.env);
@@ -11162,24 +11304,14 @@ function windowsChromeCandidates() {
11162
11304
  /**
11163
11305
  * macOS registry-free probe of the usual `.app` bundles (no subprocess).
11164
11306
  *
11165
- * Chrome on macOS is never on PATH: the launcher lives inside the bundle at
11166
- * `<App>.app/Contents/MacOS/<binary>`. Both the system-wide and per-user
11167
- * `/Applications` locations are probed, Chrome first so that a machine with
11168
- * several browsers picks the same one the README documents.
11169
- */
11170
- function darwinChromeCandidates() {
11171
- const roots = ["/Applications"];
11172
- if (process.env.HOME) roots.push(`${process.env.HOME}/Applications`);
11173
- const bundles = [
11174
- "Google Chrome.app/Contents/MacOS/Google Chrome",
11175
- "Chromium.app/Contents/MacOS/Chromium",
11176
- "Microsoft Edge.app/Contents/MacOS/Microsoft Edge",
11177
- "Brave Browser.app/Contents/MacOS/Brave Browser",
11178
- "Tungsten Edge.app/Contents/MacOS/Tungsten Edge"
11179
- ];
11180
- const out = [];
11181
- for (const root of roots) for (const bundle of bundles) out.push(`${root}/${bundle}`);
11182
- return out;
11307
+ * Delegates to the launcher's canonical bundle list (issue #19 family): the
11308
+ * launcher lives inside the bundle at `<App>.app/Contents/MacOS/<binary>`.
11309
+ * Both the system-wide and per-user `/Applications` locations are probed,
11310
+ * Chrome first so that a machine with several browsers picks the same one the
11311
+ * README documents.
11312
+ */
11313
+ function darwinChromeCandidates$1() {
11314
+ return darwinChromeCandidates(process.env);
11183
11315
  }
11184
11316
  /** Find a usable Chrome binary by scanning PATH + common fixed locations. */
11185
11317
  function findChromeBinary() {
@@ -11201,21 +11333,14 @@ function findChromeBinary() {
11201
11333
  return;
11202
11334
  }
11203
11335
  if (IS_DARWIN) {
11204
- for (const p of darwinChromeCandidates()) try {
11336
+ for (const p of darwinChromeCandidates$1()) try {
11205
11337
  if (existsSync(p)) return p;
11206
11338
  } catch {}
11207
11339
  return;
11208
11340
  }
11209
- for (const name$1 of COMMON_CHROME_BINS) if (name$1.includes("/")) try {
11210
- if (existsSync(name$1)) return name$1;
11341
+ for (const p of posixChromeCandidates(process.env)) try {
11342
+ if (existsSync(p)) return p;
11211
11343
  } catch {}
11212
- else for (const dir of (process.env.PATH ?? "").split(":")) {
11213
- if (!dir) continue;
11214
- const p = `${dir}/${name$1}`;
11215
- try {
11216
- if (existsSync(p)) return p;
11217
- } catch {}
11218
- }
11219
11344
  }
11220
11345
  /** Root detection only makes sense on POSIX; Windows doesn't gate on sandbox. */
11221
11346
  function isPosixRoot(platform = process.platform) {
@@ -12036,13 +12161,17 @@ const commonOutputSchema = {
12036
12161
  * #15 — a session id scopes the write into that session's focus slot; a call
12037
12162
  * with no session (operator paths, old clients) keeps the global store. The
12038
12163
  * global write stays best-effort exactly as before.
12164
+ *
12165
+ * The same session id also rides on the focus EVENT (M6): this function is the
12166
+ * only place that holds a targetId and its sessionId at the same time, so it is
12167
+ * the only place that can pair them for the panel's "who is driving" line.
12039
12168
  */
12040
12169
  function noteToolFocus(value, sessionId) {
12041
12170
  const targetId = focusIdFrom(value);
12042
12171
  if (targetId === null) return;
12043
12172
  const sid = typeof sessionId === "string" ? sessionId.trim() : "";
12044
12173
  if (sid !== "") sessionFocusStores.for(sid).set(targetId, "agent");
12045
- pushFocus(targetId, "agent").catch(() => null);
12174
+ pushFocus(targetId, "agent", sid === "" ? void 0 : sid).catch(() => null);
12046
12175
  }
12047
12176
  function callingSessionId(exec) {
12048
12177
  const id = (exec?.agent)?.session?.id;
@@ -12658,7 +12787,7 @@ function friendlyTabbitScriptError(message) {
12658
12787
  }
12659
12788
  /** 受管本地浏览器是否已经起着(纯读,不 spawn)。 */
12660
12789
  async function managedBrowserIsUp() {
12661
- const { localBrowserInfo: localBrowserInfo$1 } = await import("./launcher-YRO_KCPS.js");
12790
+ const { localBrowserInfo: localBrowserInfo$1 } = await import("./launcher-y5sx1g6M.js");
12662
12791
  return localBrowserInfo$1() !== null;
12663
12792
  }
12664
12793
  /**
@@ -12702,7 +12831,7 @@ async function ensureManagedBrowser(ctx, cfg, options = {}) {
12702
12831
  ok: false,
12703
12832
  message: notStartedMessage(cfg.localLaunchPolicy, localBrowserPower)
12704
12833
  };
12705
- const { localBrowserInfo: localBrowserInfo$1 } = await import("./launcher-YRO_KCPS.js");
12834
+ const { localBrowserInfo: localBrowserInfo$1 } = await import("./launcher-y5sx1g6M.js");
12706
12835
  if (localBrowserInfo$1() !== null) return { ok: true };
12707
12836
  const attach = await refreshAttach({
12708
12837
  targets: cfg.links,
@@ -12741,7 +12870,7 @@ function defineEgoTool(ctx, cfg, opts) {
12741
12870
  timeoutMs: TOOL_TIMEOUT_MS,
12742
12871
  execute: async (args, exec) => withEgoLock(async () => {
12743
12872
  cfg.spaceTracker.setCurrentSession(callingSessionId(exec), resolveEffectiveLink(cfg.links, cfg.activeTargetId)?.link.id ?? "");
12744
- markEgoToolCall(callingSessionId(exec));
12873
+ markEgoToolCall(callingSessionId(exec), opts.name);
12745
12874
  pendingViewport = cfg;
12746
12875
  if (typeof opts.gate === "function") {
12747
12876
  const blocked = opts.gate(args);
@@ -12772,14 +12901,14 @@ function defineEgoTool(ctx, cfg, opts) {
12772
12901
  }
12773
12902
  }
12774
12903
  if (opts.tabRevive) {
12775
- const { result: result$1, recoveredFrom } = await runWithTabRevive(ctx, cfg, exec, () => opts.buildScript(args));
12904
+ const { result: result$1, recoveredFrom } = await runWithTabRevive(ctx, cfg, exec, () => withPageOverlay(opts.name, opts.buildScript(args)));
12776
12905
  if (!result$1.ok) throw new Error(recoveredFrom ? `${result$1.error}\n${recoveredFrom}` : result$1.error);
12777
12906
  if (result$1.value && typeof result$1.value === "object") result$1.value.recoveredFrom = recoveredFrom;
12778
12907
  if (typeof opts.afterExecute === "function") opts.afterExecute(args, result$1.value);
12779
12908
  noteToolFocus(result$1.value, callingSessionId(exec));
12780
12909
  return toolPayload(result$1);
12781
12910
  }
12782
- const result = await runWithStaleSpaceRetry(ctx, cfg, exec, () => opts.buildScript(args));
12911
+ const result = await runWithStaleSpaceRetry(ctx, cfg, exec, () => withPageOverlay(opts.name, opts.buildScript(args)));
12783
12912
  if (!result.ok) throw new Error(result.error);
12784
12913
  if (typeof opts.afterExecute === "function") opts.afterExecute(args, result.value);
12785
12914
  noteToolFocus(result.value, callingSessionId(exec));
@@ -13235,7 +13364,7 @@ function apply(ctx, config = {}) {
13235
13364
  stop: async () => {
13236
13365
  localBrowserPower = "off";
13237
13366
  try {
13238
- const { localBrowserInfo: localBrowserInfo$1, stopLocalBrowser: stopLocalBrowser$1 } = await import("./launcher-YRO_KCPS.js");
13367
+ const { localBrowserInfo: localBrowserInfo$1, stopLocalBrowser: stopLocalBrowser$1 } = await import("./launcher-y5sx1g6M.js");
13239
13368
  if (localBrowserInfo$1() === null) return { ok: true };
13240
13369
  const out = await stopLocalBrowser$1();
13241
13370
  if (out.ok) {
@@ -14074,7 +14203,7 @@ function apply(ctx, config = {}) {
14074
14203
  return;
14075
14204
  }
14076
14205
  try {
14077
- const { localBrowserInfo: localBrowserInfo$1, stopLocalBrowser: stopLocalBrowser$1 } = await import("./launcher-YRO_KCPS.js");
14206
+ const { localBrowserInfo: localBrowserInfo$1, stopLocalBrowser: stopLocalBrowser$1 } = await import("./launcher-y5sx1g6M.js");
14078
14207
  if (localBrowserInfo$1()) {
14079
14208
  await stopLocalBrowser$1();
14080
14209
  ctx.logger?.info?.("dsh-browser-cdp: idle reaper stopped the locally launched browser");
@@ -14143,6 +14272,14 @@ function apply(ctx, config = {}) {
14143
14272
  * Tabbit 激活时被封在注入面之外的工具清单 + 兜底路径。由 `bcdp_status` 的
14144
14273
  * `guidance` 字段带出——工具「不在列表」时模型需要知道它不是坏了。
14145
14274
  */
14275
+ /**
14276
+ * 覆盖层的行为提示(随 `bcdp_status` 返回体下发一次)。
14277
+ *
14278
+ * 为什么需要它:页面角标说明"机器在做什么",但模型并不知道角标存在,
14279
+ * 于是会出现「静默连发 5 个调用、用户看着屏幕自己动」这种最坏形态。
14280
+ * 一条英文(模型侧语言)说明就够,别做成每次调用都推的常驻噪声。
14281
+ */
14282
+ const OVERLAY_GUIDANCE = "Each bcdp_* call shows a \"DSH · reading/clicking/typing\" pill on the page and beside the panel title for ~4s. The pill says WHAT the machine is doing; you owe the WHY — say one line before a batch of actions and one line after (result + next step), including read-only calls. Never fire three or more calls in a row silently. Ask before actions that need the human (login, CAPTCHA, payment, delete, submit).";
14146
14283
  const TABBIT_SEALED_GUIDANCE = "On the tabbit backend these tools are sealed (not broken): bcdp_cdp, bcdp_key, bcdp_scroll, hover/select/check/drag, bcdp_wait, upload/download/dialog, captcha/auth/login_import, bcdp_jev_*. Use bcdp_js for a single expression (e.g. window.scrollBy(0,600)) or bcdp_script for multi-step work.";
14147
14284
  function registerEgoStatus(ctx, cfg, reg, tiers) {
14148
14285
  reg(defineTool({
@@ -14177,6 +14314,7 @@ function registerEgoStatus(ctx, cfg, reg, tiers) {
14177
14314
  }
14178
14315
  },
14179
14316
  guidance: { type: "string" },
14317
+ overlay: { type: "string" },
14180
14318
  cached: { type: "boolean" },
14181
14319
  facades: {
14182
14320
  type: "object",
@@ -14213,6 +14351,7 @@ function registerEgoStatus(ctx, cfg, reg, tiers) {
14213
14351
  live: face.live.length,
14214
14352
  sealed: face.sealed.length
14215
14353
  },
14354
+ overlay: OVERLAY_GUIDANCE,
14216
14355
  ...kind === "tabbit-cli" ? { guidance: TABBIT_SEALED_GUIDANCE } : {}
14217
14356
  };
14218
14357
  }
@@ -14230,6 +14369,7 @@ function registerEgoStatus(ctx, cfg, reg, tiers) {
14230
14369
  live: face.live.length,
14231
14370
  sealed: face.sealed.length
14232
14371
  },
14372
+ overlay: OVERLAY_GUIDANCE,
14233
14373
  ...kind === "tabbit-cli" ? { guidance: TABBIT_SEALED_GUIDANCE } : {}
14234
14374
  };
14235
14375
  const statusRuntime = runtimeOfLink(resolveEffectiveLink(cfg.links, cfg.activeTargetId)?.link);
@@ -15189,7 +15329,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
15189
15329
  timeoutMs: 15e3,
15190
15330
  execute: async (args, exec) => withEgoLock(async () => {
15191
15331
  cfg.spaceTracker.setCurrentSession(callingSessionId(exec), resolveEffectiveLink(cfg.links, cfg.activeTargetId)?.link.id ?? "");
15192
- markEgoToolCall(callingSessionId(exec));
15332
+ markEgoToolCall(callingSessionId(exec), "bcdp_captcha");
15193
15333
  pendingViewport = cfg;
15194
15334
  const result = await runWithStaleSpaceRetry(ctx, cfg, { signal: exec?.signal }, () => humanCheckScript(str(args.space, cfg.activeSpace)));
15195
15335
  if (!result.ok) return {
@@ -15271,7 +15411,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
15271
15411
  timeoutMs: 32e4,
15272
15412
  execute: async (args, exec) => withEgoLock(async () => {
15273
15413
  cfg.spaceTracker.setCurrentSession(callingSessionId(exec), resolveEffectiveLink(cfg.links, cfg.activeTargetId)?.link.id ?? "");
15274
- markEgoToolCall(callingSessionId(exec));
15414
+ markEgoToolCall(callingSessionId(exec), "bcdp_wait_for_human");
15275
15415
  pendingViewport = cfg;
15276
15416
  const timeoutMs = Math.max(1e3, Math.min(3e5, num(args.timeoutMs, 12e4)));
15277
15417
  const selector = str(args.selector, "");
@@ -15575,7 +15715,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
15575
15715
  timeoutMs: TOOL_TIMEOUT_MS,
15576
15716
  execute: async (args, exec) => {
15577
15717
  cfg.spaceTracker.setCurrentSession(callingSessionId(exec), resolveEffectiveLink(cfg.links, cfg.activeTargetId)?.link.id ?? "");
15578
- markEgoToolCall(callingSessionId(exec));
15718
+ markEgoToolCall(callingSessionId(exec), "bcdp_script");
15579
15719
  pendingViewport = cfg;
15580
15720
  {
15581
15721
  const scriptRuntime = runtimeOfLink(resolveEffectiveLink(cfg.links, cfg.activeTargetId)?.link);
@@ -15725,7 +15865,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
15725
15865
  timeoutMs: 1e4,
15726
15866
  execute: async (_args, exec) => {
15727
15867
  cfg.spaceTracker.setCurrentSession(callingSessionId(exec), resolveEffectiveLink(cfg.links, cfg.activeTargetId)?.link.id ?? "");
15728
- markEgoToolCall(callingSessionId(exec));
15868
+ markEgoToolCall(callingSessionId(exec), "bcdp_jev_status");
15729
15869
  pendingViewport = cfg;
15730
15870
  const judge = judgeCfg();
15731
15871
  const runtime = judgeRuntimeOf();
@@ -15827,7 +15967,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
15827
15967
  timeoutMs: 6e4,
15828
15968
  execute: async (args, exec) => {
15829
15969
  cfg.spaceTracker.setCurrentSession(callingSessionId(exec), resolveEffectiveLink(cfg.links, cfg.activeTargetId)?.link.id ?? "");
15830
- markEgoToolCall(callingSessionId(exec));
15970
+ markEgoToolCall(callingSessionId(exec), "bcdp_jev_ask");
15831
15971
  pendingViewport = cfg;
15832
15972
  const blocked = attachGate();
15833
15973
  if (blocked !== "") return {
@@ -15968,7 +16108,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
15968
16108
  timeoutMs: 6e4,
15969
16109
  execute: async (args, exec) => {
15970
16110
  cfg.spaceTracker.setCurrentSession(callingSessionId(exec), resolveEffectiveLink(cfg.links, cfg.activeTargetId)?.link.id ?? "");
15971
- markEgoToolCall(callingSessionId(exec));
16111
+ markEgoToolCall(callingSessionId(exec), "bcdp_jev_frame");
15972
16112
  pendingViewport = cfg;
15973
16113
  const blocked = attachGate();
15974
16114
  if (blocked !== "") return {
@@ -16080,7 +16220,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
16080
16220
  timeoutMs: TOOL_TIMEOUT_MS,
16081
16221
  execute: async (args, exec) => {
16082
16222
  cfg.spaceTracker.setCurrentSession(callingSessionId(exec), resolveEffectiveLink(cfg.links, cfg.activeTargetId)?.link.id ?? "");
16083
- markEgoToolCall(callingSessionId(exec));
16223
+ markEgoToolCall(callingSessionId(exec), "bcdp_jev_run");
16084
16224
  pendingViewport = cfg;
16085
16225
  const blocked = attachGate();
16086
16226
  if (blocked !== "") return {
@@ -16180,7 +16320,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
16180
16320
  timeoutMs: TOOL_TIMEOUT_MS,
16181
16321
  execute: async (args, exec) => {
16182
16322
  cfg.spaceTracker.setCurrentSession(callingSessionId(exec), resolveEffectiveLink(cfg.links, cfg.activeTargetId)?.link.id ?? "");
16183
- markEgoToolCall(callingSessionId(exec));
16323
+ markEgoToolCall(callingSessionId(exec), "bcdp_jev_attempt");
16184
16324
  pendingViewport = cfg;
16185
16325
  const blocked = attachGate();
16186
16326
  if (blocked !== "") return {
@@ -16247,4 +16387,4 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
16247
16387
  }
16248
16388
 
16249
16389
  //#endregion
16250
- export { ATTACH_SESSION_HINT, CDP_CONNECT_FAIL_RE, Config, GLOBAL_SESSION_KEY, STATUS_FACADE_SCRIPT, STATUS_FACADE_SENTINEL, TAB_STUCK_RE, apply, attachSessionHint, buildEgoToolArgv, cdpAttachError, createActiveSpaceTracker, createSessionSpaceTracker, decideCdpAttach, deriveSlotDefaultName, effectiveChannel, egoLockBusy, findChromeBinary, findUpstreamPluginInstall, getCliFrameDiag, inject, isTabStuckFailure, localBrowserPowerState, name, parseSentinel, parseStatusFacades, resolveCliPanelSpace, resolveEgoEnv, rowsWithPrimaryActive, runWithStaleSpaceRetry, runWithTabRevive, sessionSpaceToken, setLocalBrowserPower, shouldReapBrowser, tabbitSpaceRows, waitForHumanScript };
16390
+ export { ATTACH_SESSION_HINT, CDP_CONNECT_FAIL_RE, Config, GLOBAL_SESSION_KEY, STATUS_FACADE_SCRIPT, STATUS_FACADE_SENTINEL, TAB_STUCK_RE, apply, attachSessionHint, buildEgoToolArgv, cdpAttachError, createActiveSpaceTracker, createSessionSpaceTracker, decideCdpAttach, deriveSlotDefaultName, effectiveChannel, egoLockBusy, findChromeBinary, findUpstreamPluginInstall, getCliFrameDiag, inject, isTabStuckFailure, localBrowserPowerState, name, pageOverlayExpr, parseSentinel, parseStatusFacades, resolveCliPanelSpace, resolveEgoEnv, rowsWithPrimaryActive, runWithStaleSpaceRetry, runWithTabRevive, sessionSpaceToken, setLocalBrowserPower, shouldReapBrowser, tabbitSpaceRows, waitForHumanScript };
@@ -72,15 +72,6 @@ const defaultIo = () => ({
72
72
  return port;
73
73
  }
74
74
  });
75
- const PLATFORM_CANDIDATES = {
76
- darwin: ["/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"],
77
- linux: [
78
- "/usr/bin/google-chrome",
79
- "/usr/bin/google-chrome-stable",
80
- "/usr/bin/chromium",
81
- "/usr/bin/chromium-browser"
82
- ]
83
- };
84
75
  /**
85
76
  * Env-var-driven probe of the usual Windows install dirs — the ONE canonical
86
77
  * list, consumed by both the launcher (`discoverChromeBinary`) and the
@@ -89,6 +80,13 @@ const PLATFORM_CANDIDATES = {
89
80
  * Edge, so a machine with just the 32-bit Edge (`Program Files (x86)`) got
90
81
  * "No Chrome/Chromium/Edge binary found" while `bcdp_doctor` happily
91
82
  * reported the very same binary.
83
+ *
84
+ * Issue #19 family, second pass: the same doctor-vs-launcher drift existed on
85
+ * the other two platforms — the launcher knew exactly one macOS bundle
86
+ * (Google Chrome in /Applications) and four fixed /usr/bin paths, while the
87
+ * doctor probed Chromium/Edge/Brave bundles, `~/Applications`, bare PATH
88
+ * names and /opt. The canonical darwin/posix lists now live HERE and the
89
+ * doctor delegates, so "installed" means the same thing to both again.
92
90
  */
93
91
  function windowsEnvChromeCandidates(env) {
94
92
  const pf = env.ProgramFiles;
@@ -114,9 +112,59 @@ const WIN32_FALLBACK_CANDIDATES = [
114
112
  "C:/Program Files/Microsoft/Edge/Application/msedge.exe",
115
113
  "C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"
116
114
  ];
115
+ /**
116
+ * macOS Chrome-family `.app` bundles the doctor has always probed — Chrome
117
+ * on macOS is never on PATH: the binary lives inside the bundle at
118
+ * `<App>.app/Contents/MacOS/<binary>`. Canonical here so the launcher finds
119
+ * the same installs the doctor reports (issue #19 family).
120
+ */
121
+ const DARWIN_CHROME_BUNDLES = [
122
+ "Google Chrome.app/Contents/MacOS/Google Chrome",
123
+ "Chromium.app/Contents/MacOS/Chromium",
124
+ "Microsoft Edge.app/Contents/MacOS/Microsoft Edge",
125
+ "Brave Browser.app/Contents/MacOS/Brave Browser",
126
+ "Tungsten Edge.app/Contents/MacOS/Tungsten Edge"
127
+ ];
128
+ /** System-wide first, then per-user `/Applications` (matches the README). */
129
+ function darwinChromeCandidates(env = process.env) {
130
+ const roots = ["/Applications"];
131
+ if (env.HOME) roots.push(`${env.HOME}/Applications`);
132
+ const out = [];
133
+ for (const root of roots) for (const bundle of DARWIN_CHROME_BUNDLES) out.push(`${root}/${bundle}`);
134
+ return out;
135
+ }
136
+ /**
137
+ * POSIX Chrome-family binaries — bare names are expanded over `PATH`
138
+ * (name-major, so `google-chrome-stable` anywhere on PATH beats `google-chrome`
139
+ * in the first dir, exactly the doctor's old walk), interleaved with the fixed
140
+ * absolute locations. Canonical here so the launcher and the doctor agree.
141
+ */
142
+ const POSIX_CHROME_BINS = [
143
+ "google-chrome-stable",
144
+ "google-chrome",
145
+ "chromium",
146
+ "chromium-browser",
147
+ "/usr/bin/google-chrome-stable",
148
+ "/usr/bin/google-chrome",
149
+ "/usr/bin/chromium",
150
+ "/usr/bin/chromium-browser",
151
+ "/opt/google/chrome/google-chrome"
152
+ ];
153
+ function posixChromeCandidates(env = process.env) {
154
+ const dirs = (env.PATH ?? "").split(":").filter(Boolean);
155
+ const out = [];
156
+ for (const name of POSIX_CHROME_BINS) {
157
+ if (name.includes("/")) {
158
+ out.push(name);
159
+ continue;
160
+ }
161
+ for (const dir of dirs) out.push(`${dir}/${name}`);
162
+ }
163
+ return out;
164
+ }
117
165
  function discoverChromeBinary(explicit, platform, exists, env = process.env) {
118
166
  if (explicit !== "") return exists(explicit) ? explicit : "";
119
- const candidates = platform === "win32" ? [...windowsEnvChromeCandidates(env), ...WIN32_FALLBACK_CANDIDATES] : PLATFORM_CANDIDATES[platform] ?? [];
167
+ const candidates = platform === "win32" ? [...windowsEnvChromeCandidates(env), ...WIN32_FALLBACK_CANDIDATES] : platform === "darwin" ? darwinChromeCandidates(env) : posixChromeCandidates(env);
120
168
  for (const candidate of candidates) if (exists(candidate)) return candidate;
121
169
  return "";
122
170
  }
@@ -430,4 +478,4 @@ function localBrowserInfo(statePath, io) {
430
478
  }
431
479
 
432
480
  //#endregion
433
- export { defaultLauncherStatePath as a, discoverLightpandaBinary as c, localBrowserInfo as d, stopLocalBrowser as f, buildServeArgs as i, launchLocalBrowser as l, buildEngineArgv as n, defaultManagedProfileDir as o, windowsEnvChromeCandidates as p, buildLaunchArgs as r, discoverChromeBinary as s, WSL_LAUNCH as t, lightpandaSpawnEnv as u };
481
+ export { windowsEnvChromeCandidates as _, buildLaunchArgs as a, defaultLauncherStatePath as c, discoverLightpandaBinary as d, launchLocalBrowser as f, stopLocalBrowser as g, posixChromeCandidates as h, buildEngineArgv as i, defaultManagedProfileDir as l, localBrowserInfo as m, POSIX_CHROME_BINS as n, buildServeArgs as o, lightpandaSpawnEnv as p, WSL_LAUNCH as r, darwinChromeCandidates as s, DARWIN_CHROME_BUNDLES as t, discoverChromeBinary as u };
@@ -0,0 +1,3 @@
1
+ import { _ as windowsEnvChromeCandidates, a as buildLaunchArgs, c as defaultLauncherStatePath, d as discoverLightpandaBinary, f as launchLocalBrowser, g as stopLocalBrowser, h as posixChromeCandidates, i as buildEngineArgv, l as defaultManagedProfileDir, m as localBrowserInfo, n as POSIX_CHROME_BINS, o as buildServeArgs, p as lightpandaSpawnEnv, r as WSL_LAUNCH, s as darwinChromeCandidates, t as DARWIN_CHROME_BUNDLES, u as discoverChromeBinary } from "./launcher-BnxRC9AU.js";
2
+
3
+ export { DARWIN_CHROME_BUNDLES, POSIX_CHROME_BINS, WSL_LAUNCH, buildEngineArgv, buildLaunchArgs, buildServeArgs, darwinChromeCandidates, defaultLauncherStatePath, defaultManagedProfileDir, discoverChromeBinary, discoverLightpandaBinary, launchLocalBrowser, lightpandaSpawnEnv, localBrowserInfo, posixChromeCandidates, stopLocalBrowser, windowsEnvChromeCandidates };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-browser-cdp",
3
- "version": "1.14.9",
3
+ "version": "1.14.11",
4
4
  "description": "dsh-browser-cdp: visible agent browser for DSH — drives the vendored ego-compatible Chromium over CDP, and can also attach to a running Chrome/Edge/Brave or route through egolite, Tabbit and Lightpanda backends. 35 structured bcdp_* tools; only bcdp_status stays resident by default (lazy injection, −91.9% schema per turn for non-browser sessions). Realtime watch panel with direct click/scroll/IME input, element picks quoted into the composer, human-verification notices; non-CDP channels sync frames by 3s polling. Web shell: floating watch ball without dsh-better-sidebar, sidebar tab with it. Headless/TUI hosts: tools-only. [DSH 0.1.0-rc.2 ~ 0.2.2-rc.1: declarative settings via Config .volatile() fields on 0.1.7+; imperative installSection / module-level registration + describe/mutate bridge on 0.1.0 ~ 0.1.5 (experimental, pending farm). Client peers stay optional so gen-1 hosts without dsh-client-store still load; for a production install on the current line use the 0.17.x line]",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",