dsh-browser-cdp 1.12.0 → 1.12.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,23 @@
1
+ ## 1.12.2 (2026-11-15)
2
+
3
+ **修掉「关了但面板不刷新」。**
4
+
5
+ - **现象**:ego-cli 通道上点 × 关新浪,浏览器里确实没了(`browser.listTabs()` 5 → 4),但面板标签条还挂着那一行。
6
+ - **根因**:面板标签条只认 `spaces` SSE 事件;在 CLI 通道上这个事件是**搭帧广播的车**发的(`writeCliImages` 里 `includeSpaces`),而帧广播在**没有图**时直接 early-return。关闭是结构性变更,不该等下一次成功截图——面板空闲时就是永远等不到。
7
+ - **修法**:`closeCliTab` 的 ego 分支在关闭成功后主动拉一次真实清单并 `broadcastCliSpaces`,用 `void (async …)()` 发射,**不阻塞**给用户的响应(点击不该等第二次 CLI 往返)。新增 `buildEgoListTabsScript`(`src/cast/panel-actions.ts`)与 `PanelActionRunner.listTabs`,走同一套 `taskSpaces.useOrCreate` + `browser.listTabs` + sentinel 协议。
8
+ - 拉清单失败时静默降级——下一次轮询 tick 会自己追上,不因此让关闭报错。
9
+ - 新增 6 条契约测试(`ego-close-contract` 3 条 + 新增 `ego-list-tabs-contract` 3 条):关闭分支必须在返回 `closed` 前广播、清单走 facade、发射不阻塞。
10
+
11
+ ## 1.12.1 (2026-11-15)
12
+
13
+ **修掉面板 × 在 ego-cli 通道上点了没反应。**
14
+
15
+ - **根因不是权限,是硬闸**:`/api/bcdp/close` 的 CLI 分支调 `closeCliTab`,而它第一行是 `if (channel.tabbitInventory !== true) return 'channel-cannot-close'`——ego-cli 通道恒被拒(实测 409)。但运行时**确实提供** `browser.closeTab(targetId)`(实测 5 个标签 → 3 个,新标签页与百度都真关掉了),所以错的是这道闸,不是通道能力。
16
+ - **ego-cli 走 panel-action heredoc 关闭**:新增 `buildEgoCloseTabScript`(`src/cast/panel-actions.ts`),与 size/navigate/switch 同一套 `taskSpaces.useOrCreate` + `browser.*` + sentinel 协议;`PanelActionRunner` 增加 `closeTab`,`closeCliTab` 在 `egoRuntime === true` 时先试它,只有两者都不具备的通道才答 `channel-cannot-close`。
17
+ - **共用同一个 runner 实例**:把 `makePanelActions(ctx, cfg)` 提到 `initCastServer` 之前存成局部变量,关闭与尺寸/导航/切页串行在**同一把 ego 锁**上,不再各建一个。
18
+ - **两道守卫**:`last-tab`(只剩一个标签时拒绝,避免把面板吊死在空清单)、`tab-not-found`(陈旧行不抛异常,让客户端能安静丢行)。关闭后**回读 inventory 验证**,真没了才答 `closed`。
19
+ - 新增 10 条契约测试(`tests/ego-close-contract.test.ts`):走 facade 不走裸 CDP、拒绝最后标签、陈旧行降级、sentinel 分支齐全、ego 分支先于拒绝分支、runner 唯一构造点。
20
+
1
21
  ## 1.12.0 (2026-11-15)
2
22
 
3
23
  **设置分节排版:连接目标置顶,评审(JEV / Laya)组可抽屉折叠。**
package/dsh-plugin.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "$schema": "https://dsh.community/schemas/dsh-plugin-0.15.json",
3
3
  "id": "dsh-browser-cdp",
4
4
  "name": "dsh-browser-cdp",
5
- "version": "1.12.0",
5
+ "version": "1.12.2",
6
6
  "manifestVersion": "0.15",
7
7
  "facets": {
8
8
  "host": {
package/lib/client.js CHANGED
@@ -326,7 +326,7 @@ function shouldShowGen1SettingsGear(hasConfigForms, hasOpenSettingsDocument) {
326
326
  *
327
327
  * Keep in sync with package.json — `node scripts/bump.mjs <version>` writes both.
328
328
  */
329
- const CLIENT_BUILD = "1.12.0";
329
+ const CLIENT_BUILD = "1.12.2";
330
330
 
331
331
  //#endregion
332
332
  //#region src/client/index.ts
package/lib/index.js CHANGED
@@ -2169,7 +2169,7 @@ function focusIdFrom(value) {
2169
2169
  *
2170
2170
  * Keep in sync with package.json — `node scripts/bump.mjs <version>` writes both.
2171
2171
  */
2172
- const CLIENT_BUILD = "1.12.0";
2172
+ const CLIENT_BUILD = "1.12.2";
2173
2173
 
2174
2174
  //#endregion
2175
2175
  //#region src/cast-server.ts
@@ -3938,6 +3938,36 @@ function buildEgoSwitchTabScript(spaceJson, body) {
3938
3938
  return `const __bcdpTarget = ${js$1(pickTargetId(body))}\ntry {\n if (__bcdpTarget === '') throw new Error('targetId required')\n await taskSpaces.useOrCreate(${spaceJson})\n const __tabs = await browser.listTabs()\n const __hit = __tabs.find((t) => t.targetId === __bcdpTarget)\n if (!__hit) throw new Error('tab not found: ' + __bcdpTarget)\n if (__hit.active !== true) await browser.switchTab({ targetId: __bcdpTarget })\n console.log(${js$1(PANEL_SENTINEL)} + JSON.stringify({ ok: true, targetId: __bcdpTarget, url: __hit.url || '', title: __hit.title || '' }))\n} catch (__bcdpErr) {\n console.log(${js$1(PANEL_SENTINEL)} + JSON.stringify({ ok: false, error: String((__bcdpErr && __bcdpErr.message) || __bcdpErr) }))\n}\n`;
3939
3939
  }
3940
3940
  /**
3941
+ * tab-inventory heredoc — the panel's tab strip, read from the browser.
3942
+ *
3943
+ * Used after a structural change (a close) so the strip updates NOW instead of
3944
+ * waiting for the next successful frame capture. Prints the raw rows as JSON
3945
+ * behind the sentinel; the host maps them onto its CliSpaceRow contract.
3946
+ */
3947
+ function buildEgoListTabsScript(spaceJson) {
3948
+ return `try {\n await taskSpaces.useOrCreate(${spaceJson})\n const __tabs = await browser.listTabs()\n const __rows = __tabs.map((t) => ({ targetId: String(t.targetId || ''), url: String(t.url || ''), title: String(t.title || ''), active: t.active === true }))\n console.log(${js$1(PANEL_SENTINEL)} + JSON.stringify({ ok: true, tabs: __rows }))\n} catch (__bcdpErr) {\n console.log(${js$1(PANEL_SENTINEL)} + JSON.stringify({ ok: false, error: String((__bcdpErr && __bcdpErr.message) || __bcdpErr) }))\n}\n`;
3949
+ }
3950
+ /**
3951
+ * close-tab heredoc — the user clicked × in the panel.
3952
+ *
3953
+ * An `ego-cli` link injects no CDP websocket, so `/api/bcdp/close` used to
3954
+ * answer 409 `channel-cannot-close` for it: the × looked dead. The runtime does
3955
+ * expose `browser.closeTab(targetId)` (measured: two tabs closed, inventory went
3956
+ * 5 → 3), so the same operation runs here as a heredoc on the channel real tools
3957
+ * use.
3958
+ *
3959
+ * Two guards, both learned the hard way:
3960
+ * - **Last tab is refused.** Closing the only page leaves the space with nothing
3961
+ * to show, and the panel renders a strip no tool can recover from without
3962
+ * opening a new tab first.
3963
+ * - **Only close what is really there.** A stale panel row (tab already gone from
3964
+ * another window) answers `tab-not-found` instead of throwing, so the client can
3965
+ * drop the row rather than retry forever.
3966
+ */
3967
+ function buildEgoCloseTabScript(spaceJson, body) {
3968
+ return `const __bcdpTarget = ${js$1(pickTargetId(body))}\ntry {\n if (__bcdpTarget === '') throw new Error('targetId required')\n await taskSpaces.useOrCreate(${spaceJson})\n const __tabs = await browser.listTabs()\n const __hit = __tabs.find((t) => t.targetId === __bcdpTarget)\n if (!__hit) {\n console.log(${js$1(PANEL_SENTINEL)} + JSON.stringify({ ok: false, reason: 'tab-not-found', targetId: __bcdpTarget }))\n } else if (__tabs.length <= 1) {\n console.log(${js$1(PANEL_SENTINEL)} + JSON.stringify({ ok: false, reason: 'last-tab', targetId: __bcdpTarget }))\n } else {\n await browser.closeTab(__bcdpTarget)\n const __left = await browser.listTabs()\n const __gone = !__left.some((t) => t.targetId === __bcdpTarget)\n console.log(${js$1(PANEL_SENTINEL)} + JSON.stringify({ ok: __gone, closed: __gone, reason: __gone ? '' : 'still-open', targetId: __bcdpTarget, remaining: __left.length }))\n }\n} catch (__bcdpErr) {\n console.log(${js$1(PANEL_SENTINEL)} + JSON.stringify({ ok: false, error: String((__bcdpErr && __bcdpErr.message) || __bcdpErr) }))\n}\n`;
3969
+ }
3970
+ /**
3941
3971
  * navigate heredoc — panel refresh / manual URL. Uses the runtime facades
3942
3972
  * (`page.reload` / `page.goto`) rather than raw CDP so the CLI keeps its own
3943
3973
  * load-state semantics and navigation guards.
@@ -8014,6 +8044,14 @@ async function runRefreshSync(plan, deps) {
8014
8044
  //#endregion
8015
8045
  //#region src/runtime/close-plan.ts
8016
8046
  const CLOSE_SCRATCH_TASK = "dsh-panel-shot";
8047
+ function planCloseTasks(tasks, tabId, lastTaskName) {
8048
+ const ordered = [
8049
+ tasks.find((task) => task.ownedTabIds.includes(tabId))?.taskName ?? "",
8050
+ lastTaskName,
8051
+ CLOSE_SCRATCH_TASK
8052
+ ].map((name$1) => name$1.trim()).filter((name$1) => name$1 !== "");
8053
+ return [...new Set(ordered)];
8054
+ }
8017
8055
 
8018
8056
  //#endregion
8019
8057
  //#region src/cast/run-queue.ts
@@ -11501,7 +11539,22 @@ function makePanelActions(ctx, cfg) {
11501
11539
  return {
11502
11540
  windowSize: (body) => run((spaceJson) => buildEgoWindowSizeScript(spaceJson, body)),
11503
11541
  navigate: (body) => run((spaceJson) => buildEgoNavigateScript(spaceJson, body)),
11504
- switchTab: (body) => run((spaceJson) => buildEgoSwitchTabScript(spaceJson, body))
11542
+ switchTab: (body) => run((spaceJson) => buildEgoSwitchTabScript(spaceJson, body)),
11543
+ closeTab: (body) => run((spaceJson) => buildEgoCloseTabScript(spaceJson, body)),
11544
+ listTabs: async () => {
11545
+ if (resolveCliPanelSpace(cfg) === null) return [];
11546
+ const parsed = await run((spaceJson) => buildEgoListTabsScript(spaceJson));
11547
+ const raw = parsed.tabs;
11548
+ if (parsed.ok !== true || !Array.isArray(raw)) return [];
11549
+ const now = Date.now();
11550
+ return raw.filter((t) => typeof t.targetId === "string" && t.targetId !== "").map((t) => ({
11551
+ targetId: String(t.targetId),
11552
+ url: String(t.url ?? ""),
11553
+ title: String(t.title ?? ""),
11554
+ active: t.active === true,
11555
+ lastActive: now
11556
+ }));
11557
+ }
11505
11558
  };
11506
11559
  }
11507
11560
  /**
@@ -11792,6 +11845,10 @@ let _tabbitWindowId = 0;
11792
11845
  const TABBIT_PANEL_TASK = "dsh-panel";
11793
11846
  /** Upper bound on pages one task may own; each extra page slows every call. */
11794
11847
  const TABBIT_MAX_OWNED_PAGES = 2;
11848
+ /** How long the close guard may stay armed. A tabbit snippet that never resolves
11849
+ * must not stall the frame poller forever; 15 s is comfortably past the measured
11850
+ * fast path (~560 ms) and the claim-release path (~47 ms + close). */
11851
+ const CLOSE_INFLIGHT_MAX_MS = 15e3;
11795
11852
  /** Last close attempt, echoed in the stats snapshot: the panel's × is verified by
11796
11853
  * INVENTORY, not by the receipt status (page.close() kills the receipt). */
11797
11854
  let lastClose = null;
@@ -13411,12 +13468,35 @@ function apply(ctx, config = {}) {
13411
13468
  });
13412
13469
  ctx.inject?.(["webServer"], (wctx) => {
13413
13470
  try {
13414
- initCastServer(wctx, cfg, bridge, ffmpegManager, () => openAgentWindow(ctx, cfg), (opts) => importLoginCookies(opts, { subprocess: ctx.subprocess }), cliPoller, makePanelActions(ctx, cfg), () => tabbitSpaceRows(), async (targetId) => {
13471
+ const panelActions = makePanelActions(ctx, cfg);
13472
+ initCastServer(wctx, cfg, bridge, ffmpegManager, () => openAgentWindow(ctx, cfg), (opts) => importLoginCookies(opts, { subprocess: ctx.subprocess }), cliPoller, panelActions, () => tabbitSpaceRows(), async (targetId) => {
13415
13473
  const eff = resolveEffectiveLink(cfg.links, cfg.activeTargetId);
13416
- if (runtimeOfLink(eff?.link)?.channel.tabbitInventory !== true) return {
13417
- ok: false,
13418
- reason: "channel-cannot-close"
13419
- };
13474
+ const __ch = runtimeOfLink(eff?.link)?.channel;
13475
+ if (__ch?.tabbitInventory !== true) {
13476
+ if (__ch?.egoRuntime === true) {
13477
+ const out = await panelActions.closeTab({ targetId });
13478
+ if (out.ok === true) {
13479
+ (async () => {
13480
+ try {
13481
+ const tabs = await panelActions.listTabs();
13482
+ if (tabs.length > 0) broadcastCliSpaces(tabs);
13483
+ } catch {}
13484
+ })();
13485
+ return {
13486
+ ok: true,
13487
+ reason: "closed"
13488
+ };
13489
+ }
13490
+ return {
13491
+ ok: false,
13492
+ reason: typeof out.reason === "string" && out.reason !== "" ? out.reason : "close-failed"
13493
+ };
13494
+ }
13495
+ return {
13496
+ ok: false,
13497
+ reason: "channel-cannot-close"
13498
+ };
13499
+ }
13420
13500
  const cli = resolveTabbitCli((eff?.link)?.cliPath);
13421
13501
  if (!cli.found) return {
13422
13502
  ok: false,
@@ -13427,33 +13507,51 @@ function apply(ctx, config = {}) {
13427
13507
  ok: false,
13428
13508
  reason: "bad-target"
13429
13509
  };
13510
+ const invNow = tabbitSpaceRows();
13511
+ if (invNow.tabs.length <= 1 && invNow.complete) return {
13512
+ ok: false,
13513
+ reason: "last-tab"
13514
+ };
13430
13515
  const startedAt = Date.now();
13431
13516
  const withDeadline = async (work, ms, fallback) => {
13432
13517
  return Promise.race([work, new Promise((resolve$1) => setTimeout(() => resolve$1(fallback), ms))]);
13433
13518
  };
13434
13519
  _closeInFlight = true;
13520
+ let released = false;
13521
+ const release = () => {
13522
+ if (released) return;
13523
+ released = true;
13524
+ _closeInFlight = false;
13525
+ };
13526
+ const watchdog = setTimeout(release, CLOSE_INFLIGHT_MAX_MS);
13435
13527
  let state$1 = "";
13436
13528
  let closer = CLOSE_SCRATCH_TASK;
13529
+ let owner = "";
13437
13530
  try {
13438
13531
  const inv = await withDeadline(tabbitListTabs(ctx.subprocess, cli.cliPath, TABBIT_PANEL_TASK), 3e3, null);
13439
13532
  state$1 = String(inv?.tabs.find((t) => t.tabId === tabId)?.state ?? "");
13440
- if (state$1 === "owned") {
13441
- await withDeadline(tabbitFinishTask(ctx.subprocess, cli.cliPath, TABBIT_PANEL_TASK, false), 3e3, void 0);
13442
- _tabbitOwnerCache = {
13443
- at: 0,
13444
- owners: /* @__PURE__ */ new Map()
13445
- };
13446
- } else if (state$1 === "claimed") {
13447
- let owner = _tabbitOwnerCache.owners.get(tabId);
13448
- if (owner === void 0) {
13533
+ if (state$1 === "owned" || state$1 === "claimed") {
13534
+ let tasks = _tabbitOwnerCache.at !== 0 && _tabbitOwnerCache.owners.has(tabId) ? [{
13535
+ taskName: String(_tabbitOwnerCache.owners.get(tabId) ?? ""),
13536
+ ownedTabIds: [tabId]
13537
+ }] : [];
13538
+ if (tasks.length === 0) {
13449
13539
  const diag = await withDeadline(tabbitDiagnose(ctx.subprocess, cli.cliPath), 3e3, null);
13450
- if (diag) owner = parseTabbitTasks(diag.raw).find((t) => t.ownedTabIds.includes(tabId))?.taskName;
13540
+ if (diag) tasks = parseTabbitTasks(diag.raw);
13451
13541
  }
13452
- if (owner !== void 0 && owner !== "") closer = owner;
13542
+ owner = planCloseTasks(tasks, tabId, _tabbitLastTaskName)[0] ?? "";
13543
+ if (state$1 === "owned" && owner !== "") {
13544
+ await withDeadline(tabbitFinishTask(ctx.subprocess, cli.cliPath, owner, false), 3e3, void 0);
13545
+ forgetTabbitTaskState();
13546
+ if (_tabbitLastTaskName === owner) _tabbitLastTaskName = "";
13547
+ _tabbitOwnerCache = {
13548
+ at: 0,
13549
+ owners: /* @__PURE__ */ new Map()
13550
+ };
13551
+ }
13552
+ if (owner !== "") closer = owner;
13453
13553
  }
13454
- } finally {
13455
- _closeInFlight = false;
13456
- }
13554
+ } catch {}
13457
13555
  runTabbitSnippet$1(ctx.subprocess, "await page.close().catch(() => {}); return { closed: page.isClosed() };", {
13458
13556
  cliPath: cli.cliPath,
13459
13557
  taskName: closer,
@@ -13480,17 +13578,21 @@ function apply(ctx, config = {}) {
13480
13578
  _tabbitTabCache.total = _tabbitTabCache.tabs.length;
13481
13579
  broadcastCliSpaces(tabbitSpaceRows().tabs);
13482
13580
  } else ctx.logger?.info?.(`dsh-browser-cdp: close tab ${tabId} via ${closer} did not close (${fired.receipt.status})`);
13483
- }).catch(() => void 0);
13484
- lastClose = {
13485
- tabId,
13486
- task: closer,
13487
- state: state$1 || "unknown",
13488
- status: "dispatched",
13489
- closedByReceipt: false,
13490
- stillThere: true,
13491
- ms: Date.now() - startedAt,
13492
- at: Date.now()
13493
- };
13581
+ }).catch(() => {
13582
+ lastClose = {
13583
+ tabId,
13584
+ task: closer,
13585
+ state: state$1 || "unknown",
13586
+ status: "error",
13587
+ closedByReceipt: false,
13588
+ stillThere: true,
13589
+ ms: Date.now() - startedAt,
13590
+ at: Date.now()
13591
+ };
13592
+ }).finally(() => {
13593
+ clearTimeout(watchdog);
13594
+ release();
13595
+ });
13494
13596
  return {
13495
13597
  ok: true,
13496
13598
  reason: "dispatched"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-browser-cdp",
3
- "version": "1.12.0",
3
+ "version": "1.12.2",
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",
@@ -124,7 +124,7 @@
124
124
  "@deepseek-ai/dsh-session": "^0.2.1-rc.3",
125
125
  "@deepseek-ai/dsh-skill": "^0.2.1-rc.3",
126
126
  "@deepseek-ai/dsh-system-prompt": "^0.2.1-rc.3",
127
- "@deepseek-ai/dsh-tools": ">=0.2.1-rc.1 <0.2.2-0",
127
+ "@deepseek-ai/dsh-tools": ">=0.2.1-rc.1 <=0.2.2-rc.3",
128
128
  "@deepseek-ai/dsh-user-approval": "^0.2.1-rc.3",
129
129
  "@deepseek-ai/dsh-working-directory": "^0.2.1-rc.3",
130
130
  "@types/node": "^22.20.1",