dsh-browser-cdp 1.1.5 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [简体中文](README.md) | [Français](README.fr.md) | [Deutsch](README.de.md) | [Italiano](README.it.md) | [Русский](README.ru.md) | [Español](README.es.md)
4
4
 
5
5
  <p align="center">
6
- <img src="https://img.shields.io/badge/DSH-%3E%3D0.2.0--rc.1-blue" alt="DSH >= 0.2.0-rc.1">
6
+ <img src="https://img.shields.io/badge/DSH-0.1.7--rc.1~0.2.1--rc.1-blue" alt="DSH 0.1.7-rc.1 ~ 0.2.1-rc.1">
7
7
  <img src="https://img.shields.io/badge/DSH--better--sidebar-%3E%3D0.12.2(optional)-red" alt="dsh-better-sidebar >= 0.12.2 (optional)">
8
8
  <img src="https://img.shields.io/badge/Node-%3E%3D22-brightgreen?logo=node.js&logoColor=white" alt="Node >= 22">
9
9
  </p>
@@ -14,11 +14,11 @@
14
14
 
15
15
  | 依赖 | 最低版本 | 推荐版本 | 说明 |
16
16
  |---|---|---|---|
17
- | **DSH** (DeepSeek Harness) | `0.2.0-rc.1` | `≥ 0.2.0-rc.1 <0.2.1-0` | 0.2.0 线:peer 依赖同步锁定 `>=0.2.0-rc.1 <0.2.1-0`;宿主对插件 API 向后兼容(0.2.0 的 composer/`forkSession` 为签名扩展,插件仅作调用方,免改)。声明式设置面自 0.1.7 引入(Config `.volatile()` 字段自动生成设置表单),0.2.0 延续该形态。DSH `0.1.2-rc.1` ~ `0.1.7` 请使用 **0.17.x** 版本线,0.1.0-rc.x / 0.1.1-rc.x 请使用 v0.8.0 及更早版本 |
17
+ | **DSH** (DeepSeek Harness) | `0.1.7-rc.1` | `0.1.7-rc.1 ~ 0.2.1-rc.1`(精确枚举) | 精确枚举 5 个 rc 版本,engines 与全部 dsh peer 同串(无区间/caret):`0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1`;宿主对插件 API 向后兼容(0.2.0 的 composer/`forkSession` 为签名扩展,插件仅作调用方,免改)。声明式设置面自 0.1.7 引入(Config `.volatile()` 字段自动生成设置表单),0.2.0/0.2.1 延续该形态。DSH `0.1.2-rc.1` ~ `0.1.5-rc.3` 请使用 **0.17.x** 版本线,0.1.0-rc.x / 0.1.1-rc.x 请使用 v0.8.0 及更早版本 |
18
18
  | **dsh-better-sidebar** | `0.12.2`(可选) | `≥ 0.17.1` | 未安装时自动回退浮动观察球;`< 0.12.2` 可运行但外部链接拦截(`urlTarget`)静默降级 |
19
19
  | **Node.js** | `22` | — | harness 环境自带 |
20
20
 
21
- **DSH 全版本适配说明**:本版本(**v0.18.0 起,0.2.0 线**)面向 DSH `0.2.0-rc.1+`:相对 0.1.7 线(v0.17.x)**零代码改动**,纯依赖/元数据换代——0.2.0 宿主对插件 API 向后兼容,本插件经 `ctx.get('conversation').input` 门面投递选区(不调 `submit()`、不 override),不在 0.2.0 变更影响面内。声明式设置面自 0.1.7 引入:插件不再注册任何设置节(`ctx.settings` 注册类 API 已被宿主删除),改为在 Config schema 上以 `.volatile()` 标记可配置字段,由宿主设置页自动生成表单;volatile 字段变更通过 `loader/volatile-update` 事件热生效,无需重载插件。核心宿主 API(`defineTool`、`ctx.tools.register`、`ctx.subprocess.spawn`、`ctx.webServer.register`、`ctx.inject`、`ModuleLoader` CJS factory、`cordis.patch.yml`)沿用 0.1.2 以来形态。DSH `0.1.2-rc.1` ~ `0.1.7` 请使用 **0.17.x** 版本线。
21
+ **DSH 全版本适配说明**:本版本(**1.2.1 起**)面向 DSH `0.1.7-rc.1 ~ 0.2.1-rc.1`(精确枚举 5 个 rc):相对 0.1.7 线(v0.17.x)**零代码改动**,纯依赖/元数据换代——0.2.0 宿主对插件 API 向后兼容,本插件经 `ctx.get('conversation').input` 门面投递选区(不调 `submit()`、不 override),不在 0.2.0 变更影响面内。声明式设置面自 0.1.7 引入:插件不再注册任何设置节(`ctx.settings` 注册类 API 已被宿主删除),改为在 Config schema 上以 `.volatile()` 标记可配置字段,由宿主设置页自动生成表单;volatile 字段变更通过 `loader/volatile-update` 事件热生效,无需重载插件。核心宿主 API(`defineTool`、`ctx.tools.register`、`ctx.subprocess.spawn`、`ctx.webServer.register`、`ctx.inject`、`ModuleLoader` CJS factory、`cordis.patch.yml`)沿用 0.1.2 以来形态。DSH `0.1.2-rc.1` ~ `0.1.5-rc.3` 请使用 **0.17.x** 版本线。
22
22
 
23
23
  **dsh-better-sidebar 适配说明**:本插件通过 `ctx.betterSidebar` 服务(try-catch 防御性获取)注册侧边栏 Tab 并监听外部链接。关键 API 引入版本:
24
24
 
@@ -215,6 +215,33 @@ dshx list # 应显示:[on] dsh-
215
215
  | 元工具 | `bcdp_help` `bcdp_doctor` `bcdp_http` |
216
216
  | 评审(JEV/Laya,外接判定服务可选) | `bcdp_jev_status` `bcdp_jev_frame` `bcdp_jev_ask` `bcdp_jev_run` `bcdp_jev_attempt` |
217
217
 
218
+ ## 工具注入分级(懒注册 / 分级 / 锁定)
219
+
220
+ 38 个工具全量注册时,**每个会话每一轮**都要为它们的 schema 付费(实测 `description` + `parameters` ≈ 25.6K 字符 ≈ 5–7K token),而不碰浏览器的会话一个也用不上。插件因此把「谁能出现在模型面前」收成一处策略(`src/toolTiers.ts`),分四级注入:
221
+
222
+ | 级别 | 成员 | 何时出现 |
223
+ |---|---|---|
224
+ | **core** 常驻(6) | `bcdp_status` `bcdp_doctor` `bcdp_help` `bcdp_space_open` `bcdp_navigate` `bcdp_snapshot` | 永远在场,不可封印——否则 lazy 模式连解锁入口都没有 |
225
+ | **browse** 基础操作(14) | 点击/填写/键鼠/截图/读取/等待/关闭空间 等 | `lazy` 下等首次活动;`always` 下挂载即在 |
226
+ | **extended** 扩展能力(13) | 拖拽/上传/下载/对话框/裸 CDP/脚本逃生舱/登录搬运 | 同上 |
227
+ | **judge** 评审链(5) | `bcdp_jev_*` | 除解锁外,**还要求配了 JEV 或 Laya Key**——没 Key 它们只能回答「未配置」 |
228
+
229
+ 设置项在插件设置页**最上方**的「工具封印」分块(全部 volatile,翻完当场生效,不重启插件)——一级一个开关,形状照 dsh-prime-memory 的「工具封印」:
230
+
231
+ - **`toolInjection`** `lazy`(**默认**:只常驻 core,首次 `bcdp_*` 调用后按开关注入)/ `always`(挂载即全量,历史行为)。
232
+ - **`toolBrowse`**(14)/ **`toolExtended`**(13)/ **`toolJudge`**(5):开 = 开放注册,关 = 该级从模型工具列表移除。三级各自独立,封一级不波及别级;`core` 级不给开关(封了就没了活动入口)。
233
+
234
+ 行为要点:
235
+
236
+ - **封印 = 反注册**(工具从模型的工具列表里消失),不是执行期拒绝。解锁信号挂在 `bcdp_*` 调用的公共出口上,工具体不知道分级存在;`bcdp_status` / `bcdp_help` / `bcdp_doctor` 自身也算活动信号(读了指南就得有工具可用)。
237
+ - **闲置自动收回**:`lazy` + `idleTimeoutMin > 0` 时,空闲回收把后台浏览器停掉的同一刻收回扩展面;下次活动重新铺开。`always` 模式不受影响。
238
+ - `legacyEgoToolNames` 的 `ego_*` 别名跟随其 `bcdp_*` 本体的级别。
239
+ - 当前注入面写在 `bcdp_doctor` 报告首行(`tool injection: mode=lazy browse=open extended=open judge=open judgeKey=none active=no → live 6 / sealed 32`),不用猜。
240
+ - 默认档下不碰浏览器的会话只有 **6** 个工具在场(≈ 2.9K 字符,−88.6%);要回到历史行为把 `toolInjection` 改成 `always`(38 件全在场需再配一个评审 Key)。
241
+ - 四个字段都带 schema `.default()`:volatile 字段的表单描述符直接拿 schema 默认值,不写默认会出现「面板显示 A、运行时用 B」。
242
+
243
+ > 取舍提醒:窄工具(一个动作一个工具)是模型写对参数、少重试的护栏。把交互原子合并成脚本逃生舱会省上下文,但代价是模型要自己写 heredoc、出错率上升——本插件保持全部 38 个工具的签名不变,只改**出现时机**。
244
+
218
245
  ## 观察窗怎么用
219
246
 
220
247
  右下角 **🌐 常驻小球** → 点开:
@@ -4317,7 +4317,15 @@ var CaptureManager = class {
4317
4317
 
4318
4318
  //#endregion
4319
4319
  //#region src/worker/mp4-fragments.ts
4320
+ /**
4321
+ * Incremental parser for fragmented-MP4 streams produced by FFmpeg
4322
+ * (`empty_moov+default_base_moof+frag_keyframe`). Splits the byte stream on
4323
+ * box boundaries and emits two callback events: the init segment
4324
+ * (ftyp+moov) once, then each media fragment (moof+mdat) as it completes.
4325
+ * Only 32-bit box headers are supported; any other box order is an error.
4326
+ */
4320
4327
  const MAX_BOX_BYTES = 64 * 1024 * 1024;
4328
+ /** Stateful box splitter: feed via push(), close with end() to detect truncation. */
4321
4329
  var Mp4FragmentParser = class {
4322
4330
  onInit;
4323
4331
  onFragment;
@@ -4335,6 +4343,7 @@ var Mp4FragmentParser = class {
4335
4343
  this.fragmentBoxes = [];
4336
4344
  this.ready = false;
4337
4345
  }
4346
+ /** Append a raw chunk and emit every MP4 box that is now fully buffered. */
4338
4347
  push(chunk) {
4339
4348
  this.buffer = Buffer.concat([this.buffer, Buffer.from(chunk)]);
4340
4349
  while (this.buffer.length >= 8) {
@@ -4348,9 +4357,11 @@ var Mp4FragmentParser = class {
4348
4357
  this.#box(type, box);
4349
4358
  }
4350
4359
  }
4360
+ /** Signal end of stream; throws if a partial box is still buffered. */
4351
4361
  end() {
4352
4362
  if (this.buffer.length !== 0) throw new Error("truncated MP4 stream");
4353
4363
  }
4364
+ /** Route one complete box: init phase collects ftyp/moov, media phase pairs moof+mdat. */
4354
4365
  #box(type, box) {
4355
4366
  if (!this.ready) {
4356
4367
  if (type !== "ftyp" && type !== "moov") throw new Error(`unexpected MP4 init box ${type}`);
@@ -4379,6 +4390,7 @@ var Mp4FragmentParser = class {
4379
4390
  //#endregion
4380
4391
  //#region src/worker/capture-platform.ts
4381
4392
  const execFile$1 = promisify(execFile);
4393
+ /** Emit the FFmpeg input arguments for this platform: win32 gfxcapture filter, darwin avfoundation, X11 x11grab; throws on Wayland. */
4382
4394
  function buildCaptureInput({ platform: platform$1 = process.platform, env = process.env, source, fps, maxWidth, encoder }) {
4383
4395
  if (platform$1 === "win32") {
4384
4396
  if (source.sourceType !== "window-hwnd" || !source.hwnd) {
@@ -4434,6 +4446,7 @@ function buildCaptureInput({ platform: platform$1 = process.platform, env = proc
4434
4446
  `${display}+${source.captureX},${source.captureY}`
4435
4447
  ];
4436
4448
  }
4449
+ /** Emit the FFmpeg output/encoder arguments: Windows h264_mf/libx264 fast-start paths vs. the crop+scale baseline path, both streaming fragmented MP4 to stdout. */
4437
4450
  function buildEncoderArgs({ encoder, fps, maxWidth, bitrateKbps = 4e3, source, platform: platform$1 = process.platform }) {
4438
4451
  const maxrateKbps = Math.round(bitrateKbps * 1.25);
4439
4452
  const bufsizeKbps = bitrateKbps * 2;
@@ -4502,6 +4515,7 @@ function buildEncoderArgs({ encoder, fps, maxWidth, bitrateKbps = 4e3, source, p
4502
4515
  "pipe:1"
4503
4516
  ];
4504
4517
  }
4518
+ /** Pick the window closest to CDP-reported bounds (±8px tolerance), preferring a title match among the closest candidates. */
4505
4519
  function selectWindowCandidate(windows, bounds, targetTitle = "") {
4506
4520
  const candidates = windows.filter((window) => window.hwnd && window.width > 0 && window.height > 0);
4507
4521
  if (candidates.length === 0) return null;
@@ -4519,6 +4533,7 @@ function selectWindowCandidate(windows, bounds, targetTitle = "") {
4519
4533
  }
4520
4534
  return ranked[0].window;
4521
4535
  }
4536
+ /** List visible top-level windows owned by `browserPid` (Windows only) by running an inline PowerShell script that P/invokes user32.dll. */
4522
4537
  async function enumerateWindowsForPid(browserPid, run = execFile$1) {
4523
4538
  if (!Number.isInteger(browserPid) || browserPid <= 0) return [];
4524
4539
  const script = `
@@ -4584,6 +4599,7 @@ ConvertTo-Json -Compress -InputObject @($items)
4584
4599
  const parsed = JSON.parse(stdout.trim() || "[]");
4585
4600
  return Array.isArray(parsed) ? parsed : [parsed];
4586
4601
  }
4602
+ /** Resolve the capture source for a CDP target: window-geometry probe via Runtime.evaluate, then hwnd matching (win32) or display-crop math elsewhere; throws coded errors when the target is missing/not visible/minimized. */
4587
4603
  async function resolveCaptureSource({ sessions, targetId, browserPid, platform: platform$1 = process.platform, windowEnumerator = enumerateWindowsForPid }) {
4588
4604
  const value = (await sessions.call(targetId, "Runtime.evaluate", {
4589
4605
  expression: "({screenX,screenY,outerWidth,outerHeight,innerWidth,innerHeight,devicePixelRatio,title:document.title})",
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.1.3",
5
+ "version": "1.2.1",
6
6
  "manifestVersion": "0.15",
7
7
  "facets": {
8
8
  "host": {
@@ -56,6 +56,48 @@
56
56
  "zh": "Agent 浏览器"
57
57
  },
58
58
  "fields": [
59
+ {
60
+ "path": [
61
+ "toolInjection"
62
+ ],
63
+ "label": "工具注入模式 (Tool injection mode)",
64
+ "kind": "select",
65
+ "options": [
66
+ {
67
+ "value": "lazy",
68
+ "label": "lazy"
69
+ },
70
+ {
71
+ "value": "always",
72
+ "label": "always"
73
+ }
74
+ ],
75
+ "hint": "lazy(默认)= 只常驻核心 6 个,首次 bcdp_* 调用后按下方开关注入,闲置回收时收回;always = 挂载即注册全部 38 个(历史行为)。"
76
+ },
77
+ {
78
+ "path": [
79
+ "toolBrowse"
80
+ ],
81
+ "label": "基础操作工具(14 个)",
82
+ "kind": "boolean",
83
+ "hint": "开(默认)= 浏览器活动后正常注册;关 = 14 个工具从模型工具列表移除(点击/填写/键鼠/截图/读取/等待…)。"
84
+ },
85
+ {
86
+ "path": [
87
+ "toolExtended"
88
+ ],
89
+ "label": "扩展能力工具(13 个)",
90
+ "kind": "boolean",
91
+ "hint": "开(默认)= 正常注册;关 = 13 个工具移除(拖拽/上传/下载/对话框/裸 CDP/脚本逃生舱/登录导入)。"
92
+ },
93
+ {
94
+ "path": [
95
+ "toolJudge"
96
+ ],
97
+ "label": "评审工具 bcdp_jev_*(5 个)",
98
+ "kind": "boolean",
99
+ "hint": "开仍需配了 JEV 或 Laya Key:没 Key 的评审工具只能回答「未配置」,依旧不注入。关 = 任何情况下都不注入。"
100
+ },
59
101
  {
60
102
  "path": [
61
103
  "isolateSpaces"
package/lib/client.js CHANGED
@@ -1,5 +1,30 @@
1
1
  window.__ModuleLoader__.load({ id: "dsh-browser-cdp", factory: (require) => {
2
2
  var module = { exports: {} }; var exports = module.exports;
3
+ //#region rolldown:runtime
4
+ var __create = Object.create;
5
+ var __defProp = Object.defineProperty;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
12
+ key = keys[i];
13
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
21
+ value: mod,
22
+ enumerable: true
23
+ }) : target, mod));
24
+
25
+ //#endregion
26
+ let react = require("react");
27
+ react = __toESM(react);
3
28
 
4
29
  //#region src/client/fam-links.ts
5
30
  /**
@@ -196,6 +221,155 @@ function applyProbe(links, id, outcome, at) {
196
221
  });
197
222
  }
198
223
 
224
+ //#endregion
225
+ //#region src/client/family-host.ts
226
+ /** 家族节固定 id 与子席位 key(与 thinking-levels 的声明严格一致)。 */
227
+ const FAMILY_SECTION_ID = "dsh-family";
228
+ const FAMILY_CHILD_KEY = "dsh-family.tab";
229
+ /**
230
+ * 接管分级——唯一真源是 `mine-dsh-plugins/_tools/family-rank.mjs`(离线实测 GitHub
231
+ * star + npm 周下载量加权)。延迟 = BASE + RANK * STEP;rank 越大越靠后兜底。
232
+ */
233
+ const FAMILY_CLAIM_RANK = 5;
234
+ const FAMILY_CLAIM_BASE_MS = 200;
235
+ const FAMILY_CLAIM_STEP_MS = 900;
236
+ /** 派生而非硬编码:改 rank 表就自动改时刻。 */
237
+ const FAMILY_CLAIM_DELAY_MS = FAMILY_CLAIM_BASE_MS + FAMILY_CLAIM_RANK * FAMILY_CLAIM_STEP_MS;
238
+ /** 接管行的遮蔽优先级:必须大于任何正牌 owner(TL 无=0、guard=10),
239
+ * 这样 owner 一旦上位就自然遮蔽本兜底行(宿主规则:同 cell 最低者渲染)。 */
240
+ const FAMILY_HOST_PRIORITY = 50;
241
+ const NO_TABS = [];
242
+ /** 通用容器渲染:按 order 依次画出账本里每张贡献卡,不含任何"本插件特例"。 */
243
+ function FamilyHostSection(props) {
244
+ const raw = props.hooks?.tabs;
245
+ const [polled, setPolled] = (0, react.useState)(() => raw?.getSnapshot() ?? NO_TABS);
246
+ (0, react.useEffect)(() => {
247
+ if (props.useTabs !== void 0 || raw === void 0) return;
248
+ return raw.subscribe(() => setPolled(raw.getSnapshot()));
249
+ });
250
+ return (0, react.createElement)("div", { style: {
251
+ display: "grid",
252
+ gap: "12px"
253
+ } }, (props.useTabs !== void 0 ? props.useTabs((value) => value) : polled).map((row) => (0, react.createElement)("div", { key: row.id }, props.renderSlot ? props.renderSlot(FAMILY_CHILD_KEY, {}, {
254
+ only: row.id,
255
+ fallback: null
256
+ }) : props.renderContributor?.(row.id) ?? null)));
257
+ }
258
+ /** 取条目上的具名面(宿主条目是结构化对象,这里只做安全读取)。 */
259
+ function face(entry, key) {
260
+ if (entry === null || typeof entry !== "object") return void 0;
261
+ return entry[key];
262
+ }
263
+ /** 条目的 options 收窄(宿主侧是结构化对象,缺失时当空对象读)。 */
264
+ function optionsOf(entry) {
265
+ const raw = face(entry, "options");
266
+ return raw !== null && typeof raw === "object" ? raw : {};
267
+ }
268
+ /** 把账本条目投影成标题行:label 可能是函数,抛错退化成 id,绝不带崩整节。 */
269
+ function projectLedger(slots) {
270
+ return slots.entries(FAMILY_CHILD_KEY).map((rawEntry) => {
271
+ const options = rawEntry.options ?? {};
272
+ const id = String(options["id"] ?? "");
273
+ const rawLabel = options["label"];
274
+ let label = id;
275
+ if (typeof rawLabel === "function") try {
276
+ label = String(rawLabel() ?? id);
277
+ } catch {
278
+ label = id;
279
+ }
280
+ else if (typeof rawLabel === "string") label = rawLabel;
281
+ return {
282
+ id,
283
+ order: Number(options["order"] ?? 0),
284
+ label
285
+ };
286
+ }).sort((a, b) => a.order - b.order);
287
+ }
288
+ /**
289
+ * 若到点仍无人声明子席位,则自己接管容器。
290
+ * @param slots - 客户端槽门面。
291
+ * @param isHeld - 探针:本插件的 tab 工厂是否已被执行(= 有人声明了子席位)。
292
+ * @param label - 导航标题;家族共享节的标题,不是本插件名。
293
+ * @param log - console 前缀(带插件名)。
294
+ * @returns 取消定时器与撤销接管注册的 disposer。
295
+ */
296
+ function claimFamilyHostIfOrphaned(slots, isHeld, label, log) {
297
+ let disposeClaim;
298
+ let claimed = false;
299
+ const timer = setTimeout(() => {
300
+ if (isHeld()) return;
301
+ const ledger = {
302
+ getSnapshot: () => projectLedger(slots),
303
+ subscribe: (listener) => slots.subscribe ? slots.subscribe(FAMILY_CHILD_KEY, listener) : () => void 0
304
+ };
305
+ /** ≤0.1.5 壳没有 renderSlot:从账本条目现挂组件,失败一律 null。 */
306
+ const renderContributor = (id) => {
307
+ try {
308
+ const entry = slots.entries(FAMILY_CHILD_KEY).find((candidate) => String(optionsOf(candidate)["id"] ?? "") === id);
309
+ const component = entry ? face(entry, "component") : void 0;
310
+ const inject$1 = entry ? face(entry, "inject") : void 0;
311
+ if (typeof component !== "function") return null;
312
+ return (0, react.createElement)(component, (typeof inject$1 === "function" ? inject$1() : {}) ?? {});
313
+ } catch {
314
+ return null;
315
+ }
316
+ };
317
+ try {
318
+ const dispose = slots.register({
319
+ name: "settings.section",
320
+ id: FAMILY_SECTION_ID,
321
+ order: 40,
322
+ priority: FAMILY_HOST_PRIORITY,
323
+ label,
324
+ inject: () => ({
325
+ hooks: { tabs: ledger },
326
+ renderContributor
327
+ }),
328
+ children: { [FAMILY_CHILD_KEY]: {
329
+ kind: "list",
330
+ scope: "root"
331
+ } }
332
+ }, FamilyHostSection);
333
+ if (typeof dispose === "function") disposeClaim = dispose;
334
+ claimed = true;
335
+ console.warn(`${log} family container unclaimed — took it over (children declared)`);
336
+ } catch (error) {
337
+ console.warn(`${log} family claim lost — withdrawing (${error instanceof Error ? error.message : String(error)})`);
338
+ }
339
+ }, FAMILY_CLAIM_DELAY_MS);
340
+ return () => {
341
+ clearTimeout(timer);
342
+ if (claimed) disposeClaim?.();
343
+ };
344
+ }
345
+
346
+ //#endregion
347
+ //#region src/client/fam-write.ts
348
+ const defaultSleep = (ms) => new Promise((resolve) => {
349
+ setTimeout(resolve, ms);
350
+ });
351
+ /**
352
+ * 提交一个字段写入,被拒(revision 冲突 / 瞬态故障)时有限次重试。
353
+ * @param scope - 任一条数据轨的 scope(`set` 同签名)。
354
+ * @param field - 顶层字段名。
355
+ * @param value - 要落的值。
356
+ * @param options - 预算与计时注入点。
357
+ * @returns 宿主最终是否接受了这次写入。
358
+ */
359
+ function commitField(scope, field, value, options = {}) {
360
+ const budget = Math.max(1, options.attempts ?? 3);
361
+ const retryMs = options.retryMs ?? 300;
362
+ const sleep = options.sleep ?? defaultSleep;
363
+ let attempt = 0;
364
+ const again = () => {
365
+ attempt += 1;
366
+ if (attempt >= budget) return Promise.resolve(false);
367
+ return sleep(retryMs).then(once);
368
+ };
369
+ const once = () => Promise.resolve().then(() => scope.set(field, value)).then((ok) => ok === true ? true : again(), again);
370
+ return once();
371
+ }
372
+
199
373
  //#endregion
200
374
  //#region src/client/index.ts
201
375
  var React = require("react");
@@ -1098,8 +1272,17 @@ function makeBridgeScope() {
1098
1272
  notify();
1099
1273
  return true;
1100
1274
  }
1101
- if (body && body.code === "settings-conflict") refresh();
1102
- return false;
1275
+ return Promise.resolve(refresh()).then(function() {
1276
+ return false;
1277
+ }, function() {
1278
+ return false;
1279
+ });
1280
+ }, function() {
1281
+ return Promise.resolve(refresh()).then(function() {
1282
+ return false;
1283
+ }, function() {
1284
+ return false;
1285
+ });
1103
1286
  });
1104
1287
  }
1105
1288
  };
@@ -1108,7 +1291,9 @@ function mountFamilySettingsCard(ctx) {
1108
1291
  var forms = typeof ctx.get === "function" ? ctx.get("configForms") : void 0;
1109
1292
  var scope = forms && typeof forms.get === "function" ? forms.get("dsh-browser-cdp") : void 0;
1110
1293
  if (!scope) scope = makeBridgeScope();
1294
+ var familyTabHeld = false;
1111
1295
  ctx.slots.inject("dsh-family.tab", function() {
1296
+ familyTabHeld = true;
1112
1297
  return ctx.slots.register({
1113
1298
  name: "dsh-family.tab",
1114
1299
  id: "dsh-browser-cdp",
@@ -1121,6 +1306,14 @@ function mountFamilySettingsCard(ctx) {
1121
1306
  }
1122
1307
  }, FamilySettingsCard);
1123
1308
  }, "dsh-browser-cdp: family settings tab");
1309
+ var claim = claimFamilyHostIfOrphaned(ctx.slots, function() {
1310
+ return familyTabHeld;
1311
+ }, function() {
1312
+ return "起子插件设置";
1313
+ }, "[dsh-browser-cdp]");
1314
+ if (typeof ctx.effect === "function") ctx.effect(function() {
1315
+ return claim;
1316
+ }, "dsh-browser-cdp: family host backstop");
1124
1317
  }
1125
1318
  function mountPluginsPageCard(ctx) {
1126
1319
  var forms = typeof ctx.get === "function" ? ctx.get("configForms") : void 0;
@@ -1137,6 +1330,38 @@ function mountPluginsPageCard(ctx) {
1137
1330
  }, "dsh-browser-cdp: plugins-page config card");
1138
1331
  }
1139
1332
  var FAM_FIELD_GROUPS = [
1333
+ {
1334
+ gk: "gTools",
1335
+ en: "Tool sealing",
1336
+ zh: "工具封印",
1337
+ fields: [
1338
+ {
1339
+ k: "toolInjection",
1340
+ kind: "sel",
1341
+ options: ["lazy", "always"],
1342
+ en: ["Injection mode", "lazy (default) = only the 6 core tools stay resident; the rest are injected after the first bcdp_* call and sealed back on idle reaping. always = every tool registered at mount (historical)"],
1343
+ zh: ["工具注入模式", "lazy(默认)= 只常驻核心 6 个,首次 bcdp_* 调用后铺开、闲置回收时收回;always = 挂载即注册全部(历史行为)"]
1344
+ },
1345
+ {
1346
+ k: "toolBrowse",
1347
+ kind: "bool",
1348
+ en: ["Basic browsing tools (14)", "On (default) = registered after browser activity; off = 14 tools removed from the model tool list (click / fill / key / screenshot / read / wait ...)"],
1349
+ zh: ["基础操作工具(14 个)", "开(默认)= 浏览器活动后正常注册;关 = 14 个工具从模型工具列表移除(点击/填写/键鼠/截图/读取/等待…)"]
1350
+ },
1351
+ {
1352
+ k: "toolExtended",
1353
+ kind: "bool",
1354
+ en: ["Extended tools (13)", "On (default) = registered; off = 13 tools removed (drag / upload / download / dialog / raw CDP / script escape hatches / login import)"],
1355
+ zh: ["扩展能力工具(13 个)", "开(默认)= 正常注册;关 = 13 个工具移除(拖拽/上传/下载/对话框/裸 CDP/脚本逃生舱/登录导入)"]
1356
+ },
1357
+ {
1358
+ k: "toolJudge",
1359
+ kind: "bool",
1360
+ en: ["Judgement tools bcdp_jev_* (5)", "On still requires a JEV or Laya key — without one they can only answer \"not configured\", so they stay sealed anyway"],
1361
+ zh: ["评审工具 bcdp_jev_*(5 个)", "开仍需配了 JEV/Laya Key;没 Key 它们本来也只能回答「未配置」,依旧不注入"]
1362
+ }
1363
+ ]
1364
+ },
1140
1365
  {
1141
1366
  gk: "gBasic",
1142
1367
  en: "Basics",
@@ -1535,14 +1760,12 @@ function FamField(props) {
1535
1760
  color: "var(--dsw-alias-label-tertiary, rgba(127,127,127,.8))",
1536
1761
  lineHeight: 1.5
1537
1762
  } }, famText(f, "desc")));
1538
- if (f.kind === "bool") return h("div", { style: rowStyle }, label, h("input", {
1539
- type: "checkbox",
1540
- checked: value[f.k] === true,
1541
- disabled: !writable,
1542
- onChange: function(e) {
1543
- scope.set(f.k, e.target.checked);
1544
- }
1545
- }));
1763
+ if (f.kind === "bool") return h(FamBoolRow, {
1764
+ f,
1765
+ value,
1766
+ writable,
1767
+ scope
1768
+ });
1546
1769
  if (f.kind === "num") return h("div", { style: rowStyle }, label, h(FamNumInput, {
1547
1770
  f,
1548
1771
  v: value[f.k],
@@ -1561,7 +1784,7 @@ function FamField(props) {
1561
1784
  padding: "4px 8px"
1562
1785
  },
1563
1786
  onChange: function(e) {
1564
- scope.set(f.k, e.target.value);
1787
+ commitField(scope, f.k, e.target.value);
1565
1788
  }
1566
1789
  }, f.options.map(function(o) {
1567
1790
  return h("option", {
@@ -1580,6 +1803,109 @@ function FamField(props) {
1580
1803
  scope
1581
1804
  }));
1582
1805
  }
1806
+ function FamSwitch(props) {
1807
+ var h = React.createElement;
1808
+ var on = props.checked === true;
1809
+ var busy = props.busy === true;
1810
+ var disabled = props.writable !== true || busy;
1811
+ return h("button", {
1812
+ type: "button",
1813
+ role: "switch",
1814
+ "aria-checked": on,
1815
+ "aria-label": props.ariaLabel || "",
1816
+ disabled,
1817
+ title: props.title || "",
1818
+ style: {
1819
+ flex: "0 0 auto",
1820
+ width: "38px",
1821
+ height: "22px",
1822
+ padding: 0,
1823
+ boxSizing: "border-box",
1824
+ position: "relative",
1825
+ cursor: disabled ? "default" : "pointer",
1826
+ borderRadius: "999px",
1827
+ border: "1px solid transparent",
1828
+ background: on ? "var(--dsw-alias-bg-brand, #3a76f0)" : "var(--dsw-alias-bg-module-platform, rgba(127,127,127,.28))",
1829
+ opacity: busy ? .55 : 1,
1830
+ transition: "background .16s ease, opacity .16s ease"
1831
+ },
1832
+ onClick: function() {
1833
+ props.onToggle(!on);
1834
+ }
1835
+ }, h("span", { style: {
1836
+ position: "absolute",
1837
+ top: "1px",
1838
+ left: "1px",
1839
+ width: "18px",
1840
+ height: "18px",
1841
+ borderRadius: "999px",
1842
+ boxSizing: "border-box",
1843
+ background: "var(--dsw-alias-label-inverse, #fff)",
1844
+ boxShadow: "0 1px 2px rgba(0,0,0,.35)",
1845
+ transform: on ? "translateX(16px)" : "translateX(0)",
1846
+ transition: "transform .16s ease"
1847
+ } }));
1848
+ }
1849
+ function FamBoolRow(props) {
1850
+ var f = props.f;
1851
+ var scope = props.scope;
1852
+ var writable = props.writable;
1853
+ var h = React.createElement;
1854
+ var host = props.value[f.k] === true;
1855
+ var pendingState = React.useState(void 0);
1856
+ var pending = pendingState[0], setPending = pendingState[1];
1857
+ var errState = React.useState(false);
1858
+ var failed = errState[0], setFailed = errState[1];
1859
+ React.useEffect(function() {
1860
+ if (pending !== void 0 && props.value[f.k] === pending) setPending(void 0);
1861
+ }, [props.value[f.k]]);
1862
+ var shown = pending === void 0 ? host : pending === true;
1863
+ var rowStyle = {
1864
+ display: "flex",
1865
+ alignItems: "center",
1866
+ justifyContent: "space-between",
1867
+ gap: "12px",
1868
+ padding: "6px 0"
1869
+ };
1870
+ var textCol = {
1871
+ display: "flex",
1872
+ flexDirection: "column",
1873
+ gap: "2px",
1874
+ minWidth: 0
1875
+ };
1876
+ var titleStyle = {
1877
+ fontSize: "13px",
1878
+ color: "var(--dsw-alias-label-primary, inherit)"
1879
+ };
1880
+ var descStyle = {
1881
+ fontSize: "12px",
1882
+ color: "var(--dsw-alias-label-tertiary, rgba(127,127,127,.8))",
1883
+ lineHeight: 1.5
1884
+ };
1885
+ function toggle(next) {
1886
+ if (writable !== true || pending !== void 0) return;
1887
+ setFailed(false);
1888
+ setPending(next);
1889
+ commitField(scope, f.k, next).then(function(ok) {
1890
+ if (ok === true) return;
1891
+ setPending(void 0);
1892
+ setFailed(true);
1893
+ });
1894
+ }
1895
+ return h("div", { style: {
1896
+ display: "grid",
1897
+ gap: "2px"
1898
+ } }, h("div", { style: rowStyle }, h("div", { style: textCol }, h("span", { style: titleStyle }, famText(f, "title")), f.desc === false || !famText(f, "desc") ? null : h("span", { style: descStyle }, famText(f, "desc"))), h(FamSwitch, {
1899
+ checked: shown,
1900
+ busy: pending !== void 0,
1901
+ writable,
1902
+ ariaLabel: famText(f, "title"),
1903
+ onToggle: toggle
1904
+ })), failed ? h("span", { style: {
1905
+ fontSize: "12px",
1906
+ color: "var(--dsw-alias-text-danger, #e5534b)"
1907
+ } }, _egoLocale === "zh" ? "保存未成功(已重试),开关已回到宿主当前值。" : "Save failed after retries; the switch is back to the host value.") : null);
1908
+ }
1583
1909
  function FamNumInput(props) {
1584
1910
  var f = props.f;
1585
1911
  var h = React.createElement;
@@ -1614,7 +1940,7 @@ function FamNumInput(props) {
1614
1940
  n = Math.round(n / (f.step || 1)) * (f.step || 1);
1615
1941
  if (f.min !== void 0) n = Math.max(f.min, n);
1616
1942
  if (f.max !== void 0) n = Math.min(f.max, n);
1617
- props.scope.set(f.k, n);
1943
+ commitField(props.scope, f.k, n);
1618
1944
  }
1619
1945
  });
1620
1946
  }
@@ -1644,10 +1970,10 @@ function FamStrInput(props) {
1644
1970
  setV(e.target.value);
1645
1971
  },
1646
1972
  onBlur: function() {
1647
- props.scope.set(f.k, v);
1973
+ commitField(props.scope, f.k, v);
1648
1974
  },
1649
1975
  onKeyDown: function(e) {
1650
- if (e.key === "Enter") props.scope.set(f.k, v);
1976
+ if (e.key === "Enter") commitField(props.scope, f.k, v);
1651
1977
  }
1652
1978
  });
1653
1979
  }
@@ -1739,7 +2065,7 @@ function FamLinks(props) {
1739
2065
  padding: "3px 8px"
1740
2066
  };
1741
2067
  function writeLinks(next) {
1742
- Promise.resolve(scope.set("links", next)).then(function(ok) {
2068
+ commitField(scope, "links", next).then(function(ok) {
1743
2069
  if (ok === false) setErrText(wt("linksWriteFailed"));
1744
2070
  }, function() {
1745
2071
  setErrText(wt("linksWriteFailed"));
@@ -1762,7 +2088,7 @@ function FamLinks(props) {
1762
2088
  return;
1763
2089
  }
1764
2090
  writeLinks(res.links);
1765
- if (activeId === "") scope.set("activeTargetId", res.links[res.links.length - 1].id);
2091
+ if (activeId === "") commitField(scope, "activeTargetId", res.links[res.links.length - 1].id);
1766
2092
  setAddLabel("");
1767
2093
  setAddEndpoint("");
1768
2094
  setErrText("");
@@ -1777,7 +2103,7 @@ function FamLinks(props) {
1777
2103
  return;
1778
2104
  }
1779
2105
  writeLinks(res.links);
1780
- if (activeId === "") scope.set("activeTargetId", res.links[res.links.length - 1].id);
2106
+ if (activeId === "") commitField(scope, "activeTargetId", res.links[res.links.length - 1].id);
1781
2107
  setAddCliPath("");
1782
2108
  setErrText("");
1783
2109
  }
@@ -1791,14 +2117,14 @@ function FamLinks(props) {
1791
2117
  return;
1792
2118
  }
1793
2119
  writeLinks(res.links);
1794
- if (activeId === "") scope.set("activeTargetId", res.links[res.links.length - 1].id);
2120
+ if (activeId === "") commitField(scope, "activeTargetId", res.links[res.links.length - 1].id);
1795
2121
  setAddLpPath("");
1796
2122
  setErrText("");
1797
2123
  }
1798
2124
  function removeOne(row) {
1799
2125
  var res = removeRow(links, row.id);
1800
2126
  writeLinks(res.links);
1801
- if (res.removed && res.removed.id !== void 0 && res.removed.id === activeId) scope.set("activeTargetId", "");
2127
+ if (res.removed && res.removed.id !== void 0 && res.removed.id === activeId) commitField(scope, "activeTargetId", "");
1802
2128
  }
1803
2129
  function probeOne(row) {
1804
2130
  if (probingId !== "" || !isValidEndpoint(row.endpoint)) return;
@@ -1836,13 +2162,12 @@ function FamLinks(props) {
1836
2162
  alignItems: "center",
1837
2163
  gap: "8px",
1838
2164
  flexWrap: "wrap"
1839
- } }, h("input", {
1840
- type: "checkbox",
2165
+ } }, h(FamSwitch, {
1841
2166
  checked: value.allowLocalFallback === true,
1842
- disabled: !writable,
2167
+ writable,
1843
2168
  title: wt("linksLocalEnableHint"),
1844
- onChange: function(e) {
1845
- scope.set("allowLocalFallback", e.target.checked);
2169
+ onToggle: function(next) {
2170
+ commitField(scope, "allowLocalFallback", next);
1846
2171
  }
1847
2172
  }), h("span", { style: badgeStyle }, "LOCAL"), h("span", { style: {
1848
2173
  fontSize: "13px",
@@ -1860,7 +2185,7 @@ function FamLinks(props) {
1860
2185
  disabled: !writable,
1861
2186
  style: btnStyle,
1862
2187
  onClick: function() {
1863
- scope.set("cdpMode", "local");
2188
+ commitField(scope, "cdpMode", "local");
1864
2189
  }
1865
2190
  }, wt("linksActivate"))));
1866
2191
  return h("div", { style: {
@@ -1903,13 +2228,12 @@ function FamLinks(props) {
1903
2228
  alignItems: "center",
1904
2229
  gap: "8px",
1905
2230
  flexWrap: "wrap"
1906
- } }, h("input", {
1907
- type: "checkbox",
2231
+ } }, h(FamSwitch, {
1908
2232
  checked: row.enabled === true,
1909
- disabled: !writable,
2233
+ writable,
1910
2234
  title: wt("linksEnabled"),
1911
- onChange: function(e) {
1912
- writeLinks(updateRow(links, row.id, { enabled: e.target.checked }));
2235
+ onToggle: function(next) {
2236
+ writeLinks(updateRow(links, row.id, { enabled: next }));
1913
2237
  }
1914
2238
  }), h("span", { style: badgeStyle }, isCli ? "CLI" : isLp ? "LP·无头" : "CDP"), h(FamRowInput, {
1915
2239
  v: row.label || "",
@@ -1928,8 +2252,8 @@ function FamLinks(props) {
1928
2252
  title: row.enabled === false ? wt("linksDisabledHint") : void 0,
1929
2253
  style: btnStyle,
1930
2254
  onClick: function() {
1931
- scope.set("activeTargetId", row.id);
1932
- if (cdpMode === "local") scope.set("cdpMode", "auto");
2255
+ commitField(scope, "activeTargetId", row.id);
2256
+ if (cdpMode === "local") commitField(scope, "cdpMode", "auto");
1933
2257
  }
1934
2258
  }, wt("linksActivate"))), h("div", { style: {
1935
2259
  display: "flex",
@@ -1962,13 +2286,12 @@ function FamLinks(props) {
1962
2286
  fontSize: "11px",
1963
2287
  color: "var(--dsw-alias-label-tertiary, rgba(127,127,127,.7))",
1964
2288
  flex: "0 0 auto"
1965
- } }, h("input", {
1966
- type: "checkbox",
2289
+ } }, h(FamSwitch, {
1967
2290
  checked: row.useSdkPath === true,
1968
- disabled: !writable,
2291
+ writable,
1969
2292
  title: wt("linksCliSdk"),
1970
- onChange: function(e) {
1971
- writeLinks(updateRow(links, row.id, { useSdkPath: e.target.checked }));
2293
+ onToggle: function(next) {
2294
+ writeLinks(updateRow(links, row.id, { useSdkPath: next }));
1972
2295
  }
1973
2296
  }), wt("linksCliSdk")) : null, !isCli && !isLp ? h("button", {
1974
2297
  type: "button",
package/lib/index.js CHANGED
@@ -1772,9 +1772,23 @@ let lastEgoActivity = 0;
1772
1772
  function getLastEgoActivity() {
1773
1773
  return lastEgoActivity;
1774
1774
  }
1775
+ const activityListeners = /* @__PURE__ */ new Set();
1776
+ /**
1777
+ * Subscribe to "one bcdp_* call just landed".
1778
+ * @returns the unsubscribe function.
1779
+ */
1780
+ function onEgoActivity(cb) {
1781
+ activityListeners.add(cb);
1782
+ return () => {
1783
+ activityListeners.delete(cb);
1784
+ };
1785
+ }
1775
1786
  function markEgoToolCall(sessionId) {
1776
1787
  toolCallCount += 1;
1777
1788
  lastEgoActivity = Date.now();
1789
+ for (const cb of [...activityListeners]) try {
1790
+ cb();
1791
+ } catch {}
1778
1792
  const payload = sessionId === void 0 || sessionId === "" ? { count: toolCallCount } : {
1779
1793
  count: toolCallCount,
1780
1794
  sessionId
@@ -2537,6 +2551,7 @@ const cdpMode = z.union([
2537
2551
  "local",
2538
2552
  "remote"
2539
2553
  ]);
2554
+ const toolInjection = z.union(["lazy", "always"]);
2540
2555
  const encoder = z.union([
2541
2556
  "auto",
2542
2557
  "software",
@@ -2641,6 +2656,10 @@ const Config$1 = z.object({
2641
2656
  cursorName: z.string().description("Name label shown in the cursor HUD."),
2642
2657
  allowLocalFallback: z.boolean().description("auto mode may fall back to launching a local browser when the activated target is unreachable. Off by default: the fallback must be explicit.").volatile(),
2643
2658
  legacyEgoToolNames: z.boolean().description("ALSO register the tools under their old ego_* names for scripts written before the bcdp_* rename. Off by default; mutually exclusive with installing the upstream ego-browser plugin (same tool names)."),
2659
+ toolInjection: toolInjection.default("lazy").description("lazy = keep only the core tier resident and inject the rest after the first bcdp_* activity (the idle reaper seals them back); always = register every allowed tool at mount (the historical behaviour).").volatile(),
2660
+ toolBrowse: z.boolean().default(true).description("Basic browsing tier (14 tools: click / fill / key / hover / scroll / select / check / screenshot / page_info / read_element / js / wait / wait_for_selector / space_close). Off = sealed: removed from the model tool list.").volatile(),
2661
+ toolExtended: z.boolean().default(true).description("Extended tier (13 tools: drag / upload / download / dialog / raw CDP / http / cli / script / captcha / auth_flush / login_import / wait_for_url / wait_for_response). Off = sealed even after browser activity.").volatile(),
2662
+ toolJudge: z.boolean().default(true).description("Judgement tier (5 bcdp_jev_* tools). On still requires a JEV or Laya key: without one they can only answer \"not configured\", so they stay sealed anyway.").volatile(),
2644
2663
  localHeadless: z.boolean().description("Run the locally launched browser headless."),
2645
2664
  remoteEnabled: z.boolean().description("Master switch for REMOTE attach. Off = the configured target sequence is preserved but inert (nothing probes or connects remotely); flip back on any time. Does not affect cdpMode=local.").volatile(),
2646
2665
  localUserDataDir: z.string().description("Profile dir for the locally launched browser. Empty = managed dir; never point at your daily Chrome profile."),
@@ -2832,6 +2851,13 @@ function judgeSettingsOf(config) {
2832
2851
  wallMs: config.jevWallMs
2833
2852
  };
2834
2853
  }
2854
+ /**
2855
+ * 分级开关的默认极性 = 开放。只有显式的假值才是封印:`undefined`(用户从没碰
2856
+ * 过表单)与手改 YAML 写出的 `'false'` / `0` 都得认,否则一个空字段就会把
2857
+ * 14 个工具静默封掉。prime-memory 的 `v.toolRoom !== false` 同式,只是这里把
2858
+ * 手改形状一并接住。
2859
+ */
2860
+ const tierOpenByDefault = (value) => !(value === false || value === "false" || value === 0);
2835
2861
  function resolveConfig(config = {}) {
2836
2862
  config = derefVolatileConfig(config);
2837
2863
  const legacyFps = finiteIn(config.castFpsCap, 0, 60) ? config.castFpsCap === 0 ? 20 : Math.max(5, Math.min(30, config.castFpsCap)) : 20;
@@ -2896,6 +2922,10 @@ function resolveConfig(config = {}) {
2896
2922
  cursorName: typeof config.cursorName === "string" && config.cursorName.trim() !== "" ? config.cursorName : "DeepSeek",
2897
2923
  allowLocalFallback: config.allowLocalFallback === void 0 ? false : Boolean(config.allowLocalFallback),
2898
2924
  legacyEgoToolNames: Boolean(config.legacyEgoToolNames),
2925
+ toolInjection: oneOf(config.toolInjection, ["lazy", "always"], "lazy"),
2926
+ toolBrowse: tierOpenByDefault(config.toolBrowse),
2927
+ toolExtended: tierOpenByDefault(config.toolExtended),
2928
+ toolJudge: tierOpenByDefault(config.toolJudge),
2899
2929
  localHeadless: config.localHeadless === void 0 ? false : Boolean(config.localHeadless),
2900
2930
  localUserDataDir: typeof config.localUserDataDir === "string" ? config.localUserDataDir : "",
2901
2931
  lightpandaArgs: trimmed(config.lightpandaArgs),
@@ -3141,7 +3171,7 @@ function envelopeError(code, message) {
3141
3171
  * add/change a tool, remember to sync an entry here or bcdp_help won't find it.
3142
3172
  */
3143
3173
  const EGO_HELP_INDEX = {
3144
- overview: "CDP 浏览器代理:结构化浏览器工具。导航/交互/观察/表单/网络/等待/键鼠皆有专项工具,另提供 bcdp_help(本索引)、bcdp_doctor(体检)、bcdp_cli/bcdp_script(自由脚本逃生舱)。连接与激活见 topic=links。分类见: tools / navigate / observe / input / keyboard-mouse / form / wait / network / login / script / doctor / lightpanda。用 `topic` 查询,或直接给工具名。",
3174
+ overview: "CDP 浏览器代理:结构化浏览器工具。导航/交互/观察/表单/网络/等待/键鼠皆有专项工具,另提供 bcdp_help(本索引)、bcdp_doctor(体检)、bcdp_cli/bcdp_script(自由脚本逃生舱)。连接与激活见 topic=links。分类见: tools / navigate / observe / input / keyboard-mouse / form / wait / network / login / script / doctor / lightpanda / injection。用 `topic` 查询,或直接给工具名。",
3145
3175
  tools: "工具清单: bcdp_status, bcdp_space_open, bcdp_space_close, bcdp_snapshot, bcdp_navigate, bcdp_click(+double), bcdp_fill, bcdp_js, bcdp_cdp, bcdp_screenshot(+selector), bcdp_page_info, bcdp_wait, bcdp_wait_for_selector, bcdp_wait_for_url, bcdp_wait_for_response, bcdp_key(+text/type), bcdp_hover, bcdp_read_element, bcdp_select, bcdp_drag, bcdp_scroll, bcdp_upload, bcdp_check, bcdp_dialog, bcdp_download, bcdp_http, bcdp_captcha, bcdp_auth_flush, bcdp_login_import, bcdp_help, bcdp_doctor, bcdp_cli, bcdp_script, bcdp_jev_status, bcdp_jev_frame, bcdp_jev_attempt, bcdp_jev_ask, bcdp_jev_run。",
3146
3176
  links: "连接序列(设置面板):有序列表,顺序即优先级,被激活的一项驱动每一次 bcdp_* 调用。两种类型——CDP 端点(注入 EGO_LINUX_CDP_URL,指向已开调试端口的浏览器)与 本机 ego CLI(不注入端点,由本机 ego CLI 直接驱动 ego-lite 浏览器;仅限本机,全局至多一条)。cdpMode: auto=按激活项;remote=仅接受 CDP 端点;local=受管本地启动器。cdpMode=remote 与「本机 ego CLI」组合会显式报 mode-kind-mismatch。remoteEnabled 只管远端 CDP,不影响本机 CLI 连接。",
3147
3177
  navigate: "bcdp_navigate: 打开URL或切tab(同任务复用当前tab)。bcdp_wait_for_url: 等跳转(登录/分页)。",
@@ -3155,7 +3185,8 @@ const EGO_HELP_INDEX = {
3155
3185
  captcha: "bcdp_captcha: 检测页面人机验证(CAPTCHA)并返回{detected,kind}; 检测到请让用户去 ego 浏览器完成; bcdp_page_info 也附带 humanCheck。",
3156
3186
  login: "bcdp_auth_flush: 把登录cookie落盘到ego profile; 观察窗登录引导条+『已登录,保存』按钮触发同一动作。bcdp_login_import: 从系统浏览器(Chrome/Edge/Brave)按域名导入登录cookie(source/domains/dryRun; 先dryRun看可导入项; ego浏览器须已在运行)。",
3157
3187
  script: "bcdp_cli / bcdp_script: 原样运行任意内置运行时 heredoc 脚本(page/browser/taskSpaces/site/fetch/cdp预载)。bcdp_script额外返回 duration/timedOut。",
3158
- doctor: "bcdp_doctor: 体检环境(浏览器候选、vendored runtime、状态目录、CDP端口、任务空间、引擎与降级清单)。",
3188
+ doctor: "bcdp_doctor: 体检环境(浏览器候选、vendored runtime、状态目录、CDP端口、任务空间、引擎与降级清单);首行附工具注入面快照。",
3189
+ injection: "工具分级注入(不是工具,是出现时机):38 个 bcdp_* 分四级——core(status/doctor/help/space_open/navigate/snapshot,常驻不可封印)/ browse(基础操作)/ extended(拖拽上传下载对话框裸CDP脚本登录搬运)/ judge(bcdp_jev_*)。设置旋钮(全 volatile,一级一个开关):toolInjection = lazy(默认,只常驻 core,首次 bcdp_* 调用后铺开)/ always(挂载即全量,历史行为);toolBrowse / toolExtended / toolJudge 三把开关——开 = 开放注册,关 = 该级从工具列表移除(core 级不给开关,封了就没解锁入口);judge 级即使开了仍需配 JEV/Laya Key。封印 = 从工具列表里反注册,不是执行期报错;lazy 下闲置回收会把扩展面收回。**若某个 bcdp_* 工具不在你的工具列表里**:它被分级封印了——先跑 bcdp_status 或 bcdp_doctor(两者也算浏览器活动,会把面铺开),或让用户在设置页「工具封印」里打开对应档位的开关;别猜测不存在的工具名。",
3159
3190
  lightpanda: "Lightpanda 作为后端(无头文本渲染引擎,beta):设置面板「添加 Lightpanda(受管)」——受管 serve 行(本机单例,插件负责拉起/复用/停止;win32 经 WSL2,linux/mac 本机直装),激活后 probe 自动识别 engine 并全链降级;也可用普通 CDP 端点接已自起的 serve(http://127.0.0.1:9222)。**有头/无头与顺序语义**:CDP 端点/本机 Chrome/ego CLI 是有头类型——可人工兜底(手动输账号、过验证码),是兜底主力;Lightpanda 是无头类型——无法人工介入,只适合快速试验。顺序即优先级:把 Lightpanda 排在前面 = 快速场景优先用它;排在有头类型后面 = 有头兜底优先,Lightpanda 实际不会被启用。安装——linux/macOS:`curl -fsSL https://pkg.lightpanda.io/install.sh | bash`(装入 ~/.local/bin,确保 PATH 含它),`lightpanda serve --host 127.0.0.1 --port 9222`;Windows:无原生版,用 WSL2(管理员 `wsl --install`,WSL 内同上;WSL2 自动把端口映射到宿主 localhost)或 Docker(`docker run -d -p 127.0.0.1:9222:9222 lightpanda/browser:nightly`)。可用:navigate/js/click/fill/key/snapshot(AX树)/http/login_import 等;降级:截图=PNG 文本渲染(jev 输出带 engine/rendering 元数据);关闭:观察窗实时画面、面板点选、bcdp_download(调用即结构化报错)、auth_flush(返回 degraded)",
3160
3191
  judge: "JEV/Laya 判定(阶段 10):机械采集「截图 + 编号 DOM + 意图 + 操作进度」→ 组装问题 → 取选择 → 执行 → 验证。判定器只能回传编号,绝不给选择器(幻觉选择器在结构上不可能)。四件套:bcdp_jev_status(先跑这个:判定链可用性 + 配置体检,不发任何请求)/ bcdp_jev_frame(采一帧,看判定器会看到什么)/bcdp_jev_ask(组装请求体;dryRun 默认 true,可指定 round=control|chapter|pick|evaluate 逐级看)/ bcdp_jev_run(跑循环,返回逐步 trace)。bcdp_jev_attempt(平的尝试循环):给 url + goal,开页后每轮选项 = DOM 候选 + end 项,判定模型在 maxActions(默认 5)预算内行动或自选 end 结束,回执含每步 anchor;判定上下文只走 DOM 树文本(模型不读截图),完成后你用 bcdp_cdp/bcdp_screenshot 按 targetId 自行核验——回执是报告不是证明。**三级缩小**:control(要不要动手,固定 5 项)→ chapter(哪个章节,按 AX 容器聚簇)→ pick(章节内哪个编号 + 风险度)。分章节不是装饰:阈值按候选数分桶,把 20 选 1 拆成「几选 1 × 几选 1」会让两轮都落在更严的桶里。单章节时不问章节轮。**判定上下文是隔离的**:只允许 INTENT / PROGRESS / FRAME / HISTORY 四段,**绝不带 agent 会话 session 前缀**;多出任何一段都会在组装时直接抛错(不靠约定,靠断言)。PROGRESS 由循环自己机械生成,不让模型写(模型写的进度是第二个人幻觉通道)。**评估开关 jevEvaluate(默认开)**:每步执行后判定器再判进度 inprogress/done/fail;fail 或「未验真的 done」不猜下一步,直接 escalate——带有序 RecoveryOption(reload 排第一,因陈旧渲染会藏住已写入的确认),交回你来恢复或停手。被操作元素会保留 class 等定位特征(只剥离检视器外壳 token)随 escalate 回传,便于恢复。**默认链路是 laya -> rule**:JEV 目前无法注册,所以默认不写它;将来可用时把 jev 加回跳序并填 URL 即可。不可用的跳**跳过不调用**(laya-api 强制鉴权无匿名分支,缺 key 必然 401),每一跳的跳过与失败都记进 trace,绝不静默回落;refuse 是结果不是异常。阈值一律用选中项概率 top(不是 confidence:后者是归一化熵,2 选 1 与 20 选 1 不可比)。设置面板键:layaUrl/layaKey/layaModel(laya 端口 8000,不是 7789)、judgePrefer、jevChunkSize、jevMaxImageBytes、jevHistoryLimit、jevArchiveImage、jevStepBudget、jevWallMs;jevUrl/jevKey/jevModel 留空即可(JEV 未开放注册)。"
3161
3192
  };
@@ -3236,7 +3267,7 @@ function installSettingsAuto(ctx, config) {
3236
3267
  return;
3237
3268
  }
3238
3269
  })();
3239
- if (typeof legacyModule.installSettingsSection === "function" && typeof legacyModule.settingsNamespace === "function") {
3270
+ if (typeof legacyModule?.installSettingsSection === "function" && typeof legacyModule?.settingsNamespace === "function") {
3240
3271
  const listeners = /* @__PURE__ */ new Set();
3241
3272
  let current = derefVolatileConfig(config);
3242
3273
  const notify = () => {
@@ -3458,6 +3489,154 @@ function registerSettingsBridge(wctx, ctx) {
3458
3489
  });
3459
3490
  }
3460
3491
 
3492
+ //#endregion
3493
+ //#region src/toolTiers.ts
3494
+ const CORE = [
3495
+ "bcdp_status",
3496
+ "bcdp_doctor",
3497
+ "bcdp_help",
3498
+ "bcdp_space_open",
3499
+ "bcdp_navigate",
3500
+ "bcdp_snapshot"
3501
+ ];
3502
+ const BROWSE = [
3503
+ "bcdp_space_close",
3504
+ "bcdp_click",
3505
+ "bcdp_fill",
3506
+ "bcdp_key",
3507
+ "bcdp_hover",
3508
+ "bcdp_scroll",
3509
+ "bcdp_select",
3510
+ "bcdp_check",
3511
+ "bcdp_screenshot",
3512
+ "bcdp_page_info",
3513
+ "bcdp_read_element",
3514
+ "bcdp_js",
3515
+ "bcdp_wait",
3516
+ "bcdp_wait_for_selector"
3517
+ ];
3518
+ const EXTENDED = [
3519
+ "bcdp_drag",
3520
+ "bcdp_upload",
3521
+ "bcdp_download",
3522
+ "bcdp_dialog",
3523
+ "bcdp_cdp",
3524
+ "bcdp_http",
3525
+ "bcdp_cli",
3526
+ "bcdp_script",
3527
+ "bcdp_captcha",
3528
+ "bcdp_auth_flush",
3529
+ "bcdp_login_import",
3530
+ "bcdp_wait_for_url",
3531
+ "bcdp_wait_for_response"
3532
+ ];
3533
+ const JUDGE = [
3534
+ "bcdp_jev_status",
3535
+ "bcdp_jev_ask",
3536
+ "bcdp_jev_frame",
3537
+ "bcdp_jev_run",
3538
+ "bcdp_jev_attempt"
3539
+ ];
3540
+ /** 工具名 → 分级。`ego_*` 旧名(legacyEgoToolNames 别名)与 bcdp_* 同名同组。 */
3541
+ const TIER_OF_TOOL = new Map([
3542
+ ["core", CORE],
3543
+ ["browse", BROWSE],
3544
+ ["extended", EXTENDED],
3545
+ ["judge", JUDGE]
3546
+ ].flatMap(([tier, names]) => names.map((n) => [n, tier])));
3547
+ /** 去掉 `bcdp_`/`ego_` 前缀后的裸名,便于策略表保持前缀无关。 */
3548
+ const bareToolName = (name$1) => name$1.replace(/^(?:bcdp|ego)_/, "");
3549
+ /**
3550
+ * 工具所属分级。未登记的名字落到 `extended`(最严的一档:宁可等活动解锁,
3551
+ * 也不让新工具悄悄回到常驻面);调用方应当在启动时打一条 warn,见
3552
+ * `unknownTieredTools`。分级表漂移由 `tests/tool-tiers.test.ts` 的覆盖率断言
3553
+ * 兜住,这里只是运行期兜底。
3554
+ */
3555
+ function tierOfTool(name$1) {
3556
+ const bare = bareToolName(name$1);
3557
+ for (const [known, tier] of TIER_OF_TOOL) if (bareToolName(known) === bare) return tier;
3558
+ return "extended";
3559
+ }
3560
+ /** 名单里所有查不到分级登记的工具名(启动自检 / 测试用)。 */
3561
+ const unknownTieredTools = (names) => names.filter((n) => ![...TIER_OF_TOOL.keys()].some((k) => bareToolName(k) === bareToolName(n)));
3562
+ /**
3563
+ * 评审链是否「已配置」:至少有一个可用的 key。`layaUrl` 有默认值(sidecar
3564
+ * 本机 8000),所以 URL 非空说明不了任何事——只有 key 才是配置证据。
3565
+ * 两个 hop 独立可达,任一有 key 就算配置(见 config.ts 的 jev/laya 分离说明)。
3566
+ */
3567
+ const judgeConfigured = (c) => (c.jevKey ?? "").trim() !== "" || (c.layaKey ?? "").trim() !== "";
3568
+ /** 某级开关的当前极性;`core` 恒开放。 */
3569
+ const tierOpen = (tier, p) => {
3570
+ switch (tier) {
3571
+ case "browse": return p.toolBrowse;
3572
+ case "extended": return p.toolExtended;
3573
+ case "judge": return p.toolJudge;
3574
+ default: return true;
3575
+ }
3576
+ };
3577
+ /**
3578
+ * 该分级此刻是否允许注册。
3579
+ *
3580
+ * 三条独立闸,任一不过即封印:
3581
+ * ① 本级开关(一级一个,ON = 开放);
3582
+ * ② 评审级额外要求已配 Key(没 Key 的 `bcdp_jev_*` 只能回「未配置」);
3583
+ * ③ 注入模式:`lazy` 下非 core 级要等活动,`always` 下不设时机闸。
3584
+ */
3585
+ function tierAllowed(tier, p) {
3586
+ if (!tierOpen(tier, p)) return false;
3587
+ if (tier === "judge" && !p.judgeConfigured) return false;
3588
+ if (tier === "core") return true;
3589
+ return p.injection === "always" || p.active;
3590
+ }
3591
+ /** 某工具此刻是否允许注册(名字 → 分级 → 策略)。 */
3592
+ const toolAllowed = (name$1, p) => tierAllowed(tierOfTool(name$1), p);
3593
+ function createTierInjector(o) {
3594
+ const label = o.label ?? "dsh-browser-cdp";
3595
+ /** 全部已登记工具,插入序。 */
3596
+ const all = /* @__PURE__ */ new Map();
3597
+ /** 此刻注册在宿主上的工具 → disposer。 */
3598
+ const live = /* @__PURE__ */ new Map();
3599
+ /** 无名字的工具(不该出现,兜底直注不误伤既有行为)。 */
3600
+ let anon = 0;
3601
+ const reapply = () => {
3602
+ const p = o.policy();
3603
+ const added = [];
3604
+ const removed = [];
3605
+ for (const [name$1, tool] of all) {
3606
+ const allowed = toolAllowed(name$1, p);
3607
+ if (allowed && !live.has(name$1)) {
3608
+ live.set(name$1, o.register(tool));
3609
+ added.push(name$1);
3610
+ } else if (!allowed && live.has(name$1)) {
3611
+ live.get(name$1)?.();
3612
+ live.delete(name$1);
3613
+ removed.push(name$1);
3614
+ }
3615
+ }
3616
+ if (added.length > 0) o.logger?.info?.(`${label}: 工具注入 +${added.length} (${added.join(" ")})`);
3617
+ if (removed.length > 0) o.logger?.warn?.(`${label}: 工具封印 -${removed.length} (${removed.join(" ")})`);
3618
+ };
3619
+ return {
3620
+ offer(tool) {
3621
+ const name$1 = typeof tool?.name === "string" ? tool.name : "";
3622
+ if (name$1 === "") {
3623
+ anon += 1;
3624
+ live.set(`#anon${anon}`, o.register(tool));
3625
+ return;
3626
+ }
3627
+ all.set(name$1, tool);
3628
+ reapply();
3629
+ },
3630
+ reapply,
3631
+ surface() {
3632
+ return {
3633
+ live: [...live.keys()],
3634
+ sealed: [...all.keys()].filter((n) => !live.has(n))
3635
+ };
3636
+ }
3637
+ };
3638
+ }
3639
+
3461
3640
  //#endregion
3462
3641
  //#region src/ffmpeg-manifest.ts
3463
3642
  const BTBN_TAG = "autobuild-2026-08-17-13-05";
@@ -7385,6 +7564,18 @@ function apply(ctx, config = {}) {
7385
7564
  get idleTimeoutMin() {
7386
7565
  return resolveConfig(bridge.source()).idleTimeoutMin;
7387
7566
  },
7567
+ get toolInjection() {
7568
+ return resolveConfig(bridge.source()).toolInjection;
7569
+ },
7570
+ get toolBrowse() {
7571
+ return resolveConfig(bridge.source()).toolBrowse;
7572
+ },
7573
+ get toolExtended() {
7574
+ return resolveConfig(bridge.source()).toolExtended;
7575
+ },
7576
+ get toolJudge() {
7577
+ return resolveConfig(bridge.source()).toolJudge;
7578
+ },
7388
7579
  get links() {
7389
7580
  return resolveConfig(bridge.source()).links;
7390
7581
  },
@@ -7473,27 +7664,83 @@ function apply(ctx, config = {}) {
7473
7664
  return judgeSettingsOf(resolveConfig(bridge.source())).wallMs;
7474
7665
  }
7475
7666
  };
7667
+ let browserActive = false;
7668
+ const tiers = createTierInjector({
7669
+ register: (tool) => {
7670
+ const dispose = ctx.tools.register(tool);
7671
+ ctx.effect?.(() => dispose);
7672
+ return dispose;
7673
+ },
7674
+ policy: () => ({
7675
+ injection: cfg.toolInjection,
7676
+ toolBrowse: cfg.toolBrowse,
7677
+ toolExtended: cfg.toolExtended,
7678
+ toolJudge: cfg.toolJudge,
7679
+ judgeConfigured: judgeConfigured({
7680
+ jevKey: cfg.jevKey,
7681
+ layaKey: cfg.layaKey
7682
+ }),
7683
+ active: browserActive
7684
+ }),
7685
+ logger: ctx.logger
7686
+ });
7687
+ /** 活动信号:只翻一次牌,重复调用零成本。 */
7688
+ const pulseActivity = () => {
7689
+ if (browserActive) return;
7690
+ browserActive = true;
7691
+ tiers.reapply();
7692
+ };
7693
+ {
7694
+ const offActivity = onEgoActivity(pulseActivity);
7695
+ ctx.effect?.(() => offActivity);
7696
+ }
7697
+ /**
7698
+ * 闲置回收后把注入面收回 core 级(lazy 模式专属):浏览器已经停了,模型
7699
+ * 面上留着 30 多个驱动它的工具只是白付。下一次活动会重新铺开。
7700
+ */
7701
+ const sealAfterReap = () => {
7702
+ if (cfg.toolInjection !== "lazy" || !browserActive) return;
7703
+ browserActive = false;
7704
+ tiers.reapply();
7705
+ };
7706
+ /**
7707
+ * 常驻级工具看到的分级视图:`pulse` = 把本次调用当成一次浏览器活动;
7708
+ * `surface` = 当前注入面(doctor 直接打出来,开关状态得看得见)。
7709
+ */
7710
+ const tierView = {
7711
+ pulse: pulseActivity,
7712
+ active: () => browserActive,
7713
+ surface: () => tiers.surface()
7714
+ };
7476
7715
  const reg = (tool) => {
7477
- const dispose = ctx.tools.register(tool);
7478
- ctx.effect?.(() => dispose);
7716
+ tiers.offer(tool);
7479
7717
  if (cfg.legacyEgoToolNames && typeof tool.name === "string" && tool.name.startsWith("bcdp_")) {
7480
7718
  const alias = {
7481
7719
  ...tool,
7482
7720
  name: "ego_" + tool.name.slice(5)
7483
7721
  };
7484
7722
  try {
7485
- const disposeAlias = ctx.tools.register(alias);
7486
- ctx.effect?.(() => disposeAlias);
7723
+ tiers.offer(alias);
7487
7724
  } catch (error) {
7488
7725
  ctx.logger?.warn?.(`dsh-browser-cdp: legacy alias ${alias.name} not registered: ${error.message}`);
7489
7726
  }
7490
7727
  }
7491
7728
  };
7492
- registerEgoStatus(ctx, cfg, reg);
7729
+ registerEgoStatus(ctx, cfg, reg, tierView);
7493
7730
  registerAuthFlush(ctx, cfg, reg);
7494
7731
  registerLoginImport(ctx, cfg, reg);
7495
7732
  registerActionTools(ctx, cfg, reg);
7496
- registerHelpAndDoctor(ctx, cfg, reg);
7733
+ registerHelpAndDoctor(ctx, cfg, reg, tierView);
7734
+ {
7735
+ const s = tiers.surface();
7736
+ const unlisted = unknownTieredTools([...s.live, ...s.sealed]);
7737
+ if (unlisted.length > 0) ctx.logger?.warn?.(`dsh-browser-cdp: tools missing from the tier table (defaulted to extended): ${unlisted.join(" ")}`);
7738
+ ctx.logger?.info?.(`dsh-browser-cdp: tool surface ${s.live.length}/${s.live.length + s.sealed.length} (injection=${cfg.toolInjection}, switches browse=${cfg.toolBrowse ? "open" : "sealed"} extended=${cfg.toolExtended ? "open" : "sealed"} judge=${cfg.toolJudge ? "open" : "sealed"}, judgeConfigured=${judgeConfigured({
7739
+ jevKey: cfg.jevKey,
7740
+ layaKey: cfg.layaKey
7741
+ })})`);
7742
+ }
7743
+ bridge.onChange(() => tiers.reapply());
7497
7744
  const triggerCdpRefresh = (() => {
7498
7745
  let inFlight = false;
7499
7746
  let pending = false;
@@ -7617,6 +7864,7 @@ function apply(ctx, config = {}) {
7617
7864
  },
7618
7865
  graceMs: 8e3
7619
7866
  }).done.catch(() => null);
7867
+ sealAfterReap();
7620
7868
  } catch {}
7621
7869
  })();
7622
7870
  }, 6e4);
@@ -7644,7 +7892,7 @@ function apply(ctx, config = {}) {
7644
7892
  ctx.logger?.info?.(`dsh-browser-cdp: mounted (egoBin=${cfg.egoBin}, defaultSpace=${cfg.defaultSpace})`);
7645
7893
  }
7646
7894
  /** `bcdp_status` probes CLI availability by running the real `--status` path. */
7647
- function registerEgoStatus(ctx, cfg, reg) {
7895
+ function registerEgoStatus(ctx, cfg, reg, tiers) {
7648
7896
  reg(defineTool({
7649
7897
  name: "bcdp_status",
7650
7898
  description: "Check whether the ego-browser CLI is usable (runs `ego-browser --status`). Use this first when other bcdp_* tools report \"CLI not found\".",
@@ -7669,37 +7917,40 @@ function registerEgoStatus(ctx, cfg, reg) {
7669
7917
  render: renderText
7670
7918
  },
7671
7919
  timeoutMs: 25e3,
7672
- execute: async () => withEgoLock(async () => {
7673
- try {
7674
- const handle = ctx.subprocess.spawn({
7675
- argv: [...cfg.egoArgvPrefix, "--status"],
7676
- cwd: process.cwd(),
7677
- env: resolveEgoEnv(cfg),
7678
- stdio: {
7679
- stdin: { data: "" },
7680
- stdout: { maxBytes: 4096 },
7681
- stderr: { maxBytes: 4096 }
7682
- },
7683
- graceMs: 25e3
7684
- });
7685
- const outcome = await handle.done;
7686
- const out = readAll(handle.collected.stdout).trim();
7687
- return {
7688
- ok: true,
7689
- available: outcome.exitCode === 0 && out !== "",
7690
- path: cfg.egoBin,
7691
- exitCode: outcome.exitCode
7692
- };
7693
- } catch (err) {
7694
- return {
7695
- ok: true,
7696
- available: false,
7697
- path: "",
7698
- exitCode: null,
7699
- error: describeSpawnFailure(err)
7700
- };
7701
- }
7702
- }),
7920
+ execute: async () => {
7921
+ tiers.pulse();
7922
+ return withEgoLock(async () => {
7923
+ try {
7924
+ const handle = ctx.subprocess.spawn({
7925
+ argv: [...cfg.egoArgvPrefix, "--status"],
7926
+ cwd: process.cwd(),
7927
+ env: resolveEgoEnv(cfg),
7928
+ stdio: {
7929
+ stdin: { data: "" },
7930
+ stdout: { maxBytes: 4096 },
7931
+ stderr: { maxBytes: 4096 }
7932
+ },
7933
+ graceMs: 25e3
7934
+ });
7935
+ const outcome = await handle.done;
7936
+ const out = readAll(handle.collected.stdout).trim();
7937
+ return {
7938
+ ok: true,
7939
+ available: outcome.exitCode === 0 && out !== "",
7940
+ path: cfg.egoBin,
7941
+ exitCode: outcome.exitCode
7942
+ };
7943
+ } catch (err) {
7944
+ return {
7945
+ ok: true,
7946
+ available: false,
7947
+ path: "",
7948
+ exitCode: null,
7949
+ error: describeSpawnFailure(err)
7950
+ };
7951
+ }
7952
+ });
7953
+ },
7703
7954
  presentCall: () => ({
7704
7955
  card: "generic",
7705
7956
  title: "bcdp_status",
@@ -8509,7 +8760,7 @@ function registerActionTools(ctx, cfg, reg) {
8509
8760
  })());
8510
8761
  }
8511
8762
  /** Register bcdp_help / bcdp_doctor / bcdp_script. */
8512
- function registerHelpAndDoctor(ctx, cfg, reg) {
8763
+ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
8513
8764
  reg(defineTool({
8514
8765
  name: "bcdp_captcha",
8515
8766
  description: "Check the current page for a human-verification (CAPTCHA) challenge — reCAPTCHA / hCaptcha / Cloudflare / Turnstile — and return { detected, kind }. If detected=true, ALERT THE USER that they must complete the verification in the 'ego lite - agent' browser window (it is the same live session shown in the watch panel), then continue after they have.",
@@ -8595,6 +8846,7 @@ function registerHelpAndDoctor(ctx, cfg, reg) {
8595
8846
  },
8596
8847
  timeoutMs: 1e4,
8597
8848
  execute: async (args) => {
8849
+ tiers.pulse();
8598
8850
  const q = str(args.topic, "").trim().toLowerCase();
8599
8851
  const key = Object.prototype.hasOwnProperty.call(EGO_HELP_INDEX, q) ? q : "";
8600
8852
  const text = key ? EGO_HELP_INDEX[key] : q ? `未找到 topic "${q}"。可用: ` + Object.keys(EGO_HELP_INDEX).filter((k) => k !== "overview").join(", ") + "\n\noverview: " + EGO_HELP_INDEX.overview : EGO_HELP_INDEX.overview;
@@ -8634,7 +8886,16 @@ function registerHelpAndDoctor(ctx, cfg, reg) {
8634
8886
  },
8635
8887
  timeoutMs: 25e3,
8636
8888
  execute: async () => {
8889
+ tiers.pulse();
8637
8890
  const lines = [];
8891
+ {
8892
+ const s = tiers.surface();
8893
+ const key = judgeConfigured({
8894
+ jevKey: cfg.jevKey,
8895
+ layaKey: cfg.layaKey
8896
+ });
8897
+ lines.push(`tool injection: mode=${cfg.toolInjection} browse=${cfg.toolBrowse ? "open" : "sealed"} extended=${cfg.toolExtended ? "open" : "sealed"} judge=${cfg.toolJudge ? "open" : "sealed"} judgeKey=${key ? "set" : "none"} active=${tiers.active() ? "yes" : "no"} → live ${s.live.length} / sealed ${s.sealed.length}`);
8898
+ }
8638
8899
  lines.push(`egoBin: ${cfg.egoBin}`);
8639
8900
  try {
8640
8901
  lines.push(`egoBin exists: ${existsSync(cfg.egoBin)}`);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-browser-cdp",
3
- "version": "1.1.5",
4
- "description": "dsh-browser-cdp: DSH browser plugin — attach to a running Chrome/Edge over CDP (no bundled browser needed); structured browser-automation tools (30+ bcdp_*) that drive the vendored ego runtime through ctx.subprocess, plus a realtime watch panel (live SSE screencast + direct mouse interaction + download capture + human-verification notice). Web shell: floating watch panel without dsh-better-sidebar, sidebar tab with it. Headless/TUI hosts: tools-only. [DSH 0.2.0-rc.1+ line: declarative settings via Config .volatile() fields; for DSH 0.1.2-rc.1 ~ 0.1.7 use the 0.17.x line]",
3
+ "version": "1.2.1",
4
+ "description": "dsh-browser-cdp: DSH browser plugin — attach to a running Chrome/Edge over CDP (no bundled browser needed); structured browser-automation tools (30+ bcdp_*) that drive the vendored ego runtime through ctx.subprocess, plus a realtime watch panel (live SSE screencast + direct mouse interaction + download capture + human-verification notice). Web shell: floating watch panel without dsh-better-sidebar, sidebar tab with it. Headless/TUI hosts: tools-only. [DSH 0.1.7-rc.1 ~ 0.2.1-rc.1 line (exact rc enumeration): declarative settings via Config .volatile() fields; for DSH 0.1.2-rc.1 ~ 0.1.5-rc.3 use the 0.17.x line]",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
7
7
  "exports": {
@@ -21,7 +21,7 @@
21
21
  ],
22
22
  "dsh": {
23
23
  "engines": {
24
- "dsh": ">=0.1.0-0 <0.3.0-0"
24
+ "dsh": "0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1"
25
25
  },
26
26
  "bundle": {
27
27
  "patch": "./cordis.patch.yml"
@@ -34,14 +34,11 @@
34
34
  },
35
35
  "compatibility": {
36
36
  "dshReleases": {
37
- "0.1.2-rc.1": "compatible",
38
- "0.1.5-rc.1": "compatible",
39
- "0.1.5-rc.2": "compatible",
40
- "0.1.5-rc.3": "compatible",
41
37
  "0.1.7-rc.1": "compatible",
42
38
  "0.1.7-rc.2": "compatible",
43
39
  "0.2.0-rc.1": "compatible",
44
- "0.2.0-rc.2": "compatible"
40
+ "0.2.0-rc.2": "compatible",
41
+ "0.2.1-rc.1": "compatible"
45
42
  }
46
43
  }
47
44
  },
@@ -55,12 +52,12 @@
55
52
  "@deepseek-ai/schemastery": "^3.18.4"
56
53
  },
57
54
  "peerDependencies": {
58
- "@deepseek-ai/dsh-client-locale": ">=0.1.0-0 <0.3.0-0",
59
- "@deepseek-ai/dsh-client-store": ">=0.1.0-0 <0.3.0-0",
60
- "@deepseek-ai/dsh-client-ui-settings-plugins": ">=0.1.0-0 <0.3.0-0",
61
- "@deepseek-ai/dsh-client-ui-slots": ">=0.1.0-0 <0.3.0-0",
62
- "@deepseek-ai/dsh-settings": ">=0.1.0-0 <0.3.0-0",
63
- "@deepseek-ai/dsh-tools": ">=0.1.0-0 <0.3.0-0",
55
+ "@deepseek-ai/dsh-client-locale": "0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1",
56
+ "@deepseek-ai/dsh-client-store": "0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1",
57
+ "@deepseek-ai/dsh-client-ui-settings-plugins": "0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1",
58
+ "@deepseek-ai/dsh-client-ui-slots": "0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1",
59
+ "@deepseek-ai/dsh-settings": "0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1",
60
+ "@deepseek-ai/dsh-tools": "0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1",
64
61
  "react": "^18.2.0"
65
62
  },
66
63
  "peerDependenciesMeta": {
@@ -98,7 +95,7 @@
98
95
  },
99
96
  "engines": {
100
97
  "node": ">=22",
101
- "dsh": ">=0.1.0-0 <0.3.0-0"
98
+ "dsh": "0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1"
102
99
  },
103
100
  "license": "MIT",
104
101
  "repository": {
@@ -106,6 +103,7 @@
106
103
  "url": "git+https://github.com/drscrewdriver/dsh-browser-cdp.git"
107
104
  },
108
105
  "publishConfig": {
106
+ "registry": "https://registry.npmjs.org",
109
107
  "tag": "dsh-1.1.0"
110
108
  }
111
109
  }