dsh-browser-cdp 1.2.4 → 1.3.0

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
@@ -221,28 +221,34 @@ dshx list # 应显示:[on] dsh-
221
221
 
222
222
  ## 工具注入分级(懒注册 / 分级 / 锁定)
223
223
 
224
- 38 个工具全量注册时,**每个会话每一轮**都要为它们的 schema 付费(实测 `description` + `parameters` ≈ 25.6K 字符 ≈ 5–7K token),而不碰浏览器的会话一个也用不上。插件因此把「谁能出现在模型面前」收成一处策略(`src/toolTiers.ts`),分四级注入:
224
+ 38 个工具全量注册时,**每个会话每一轮**都要为它们的 schema 付费(AST 实测 `description` + `parameters` ≈ 18.8K 字符 ≈ 5.4K token),而不碰浏览器的会话一个也用不上。插件因此把「谁能出现在模型面前」收成一处策略(`src/toolTiers.ts`),分**八批**注入:
225
225
 
226
- | 级别 | 成员 | 何时出现 |
227
- |---|---|---|
228
- | **core** 常驻(6) | `bcdp_status` `bcdp_doctor` `bcdp_help` `bcdp_space_open` `bcdp_navigate` `bcdp_snapshot` | 永远在场,不可封印——否则 lazy 模式连解锁入口都没有 |
229
- | **browse** 基础操作(14) | 点击/填写/键鼠/截图/读取/等待/关闭空间 等 | `lazy` 下等首次活动;`always` 下挂载即在 |
230
- | **extended** 扩展能力(13) | 拖拽/上传/下载/对话框/裸 CDP/脚本逃生舱/登录搬运 | 同上 |
231
- | **judge** 评审链(5) | `bcdp_jev_*` | 除解锁外,**还要求配了 JEV 或 Laya Key**——没 Key 它们只能回答「未配置」 |
226
+ | 批次 | 成员 | schema | 何时出现 |
227
+ |---|---|---:|---|
228
+ | **core** 常驻(7) | `bcdp_status` `bcdp_doctor` `bcdp_help` `bcdp_space_open` `bcdp_space_close` `bcdp_navigate` `bcdp_snapshot` | 2,610 | 永远在场,不可封印——否则 lazy 模式连解锁入口都没有 |
229
+ | **act** 动手(8) | click / fill / key / hover / scroll / select / check / drag | 3,823 | `lazy` 下首次活动放第一波 |
230
+ | **observe** 观察(4) | screenshot / page_info / read_element / js | 1,663 | 第二次活动 |
231
+ | **wait** 等待(4) | wait / wait_for_selector / wait_for_url / wait_for_response | 1,695 | 第三次活动 |
232
+ | **power** 重量级(5) | raw CDP / http / upload / download / dialog | 2,947 | 首次活动(同 `toolExtended`) |
233
+ | **session** 登录态(3) | captcha / auth_flush / login_import | 1,689 | 首次活动(同 `toolExtended`) |
234
+ | **escape** 逃生舱(2) | cli / script | 1,224 | **冷启动即在**,不吃活动闸(见下) |
235
+ | **judge** 评审链(5) | `bcdp_jev_*` | 3,183 | 除解锁外,**还要求配了 JEV 或 Laya Key** |
236
+
237
+ 设置项在插件设置页**最上方**的「工具封印」分块(全部 volatile,翻完当场生效,不重启插件)——一个开关管一组批次,形状照 dsh-prime-memory 的「工具封印」:
232
238
 
233
- 设置项在插件设置页**最上方**的「工具封印」分块(全部 volatile,翻完当场生效,不重启插件)——一级一个开关,形状照 dsh-prime-memory 的「工具封印」:
239
+ - **`toolInjection`** `lazy`(**默认**:常驻 core + escape,其余首次 `bcdp_*` 调用后按开关注入)/ `always`(挂载即全量,历史行为)。
240
+ - **`toolBrowse`**(act + observe + wait = 16)/ **`toolExtended`**(power + session = 8)/ **`toolEscape`**(cli + script = 2)/ **`toolJudge`**(5):开 = 开放注册,关 = 该批从模型工具列表移除。四组各自独立,封一组不波及别组;`core` 级不给开关(封了就没了活动入口)。
234
241
 
235
- - **`toolInjection`** `lazy`(**默认**:只常驻 core,首次 `bcdp_*` 调用后按开关注入)/ `always`(挂载即全量,历史行为)。
236
- - **`toolBrowse`**(14)/ **`toolExtended`**(13)/ **`toolJudge`**(5):开 = 开放注册,关 = 该级从模型工具列表移除。三级各自独立,封一级不波及别级;`core` 级不给开关(封了就没了活动入口)。
242
+ **escape 批为什么单独成组、且不等活动**:`cli` / `script` 是唯一能在一次调用里干完任意多步任务的入口(`page` / `browser` / `taskSpaces` / `fetch` / `cdp` 全预置),其余 36 个工具能做的事它都能做。所以它必须始终可达——否则模型遇到「结构化工具没覆盖」的情形时手里没有任何逃生手段。这也让它成为**按需只开逃生舱**的合法姿势:关掉 `toolExtended`、留着 `toolEscape`,只留 2 个工具。
237
243
 
238
244
  行为要点:
239
245
 
240
246
  - **封印 = 反注册**(工具从模型的工具列表里消失),不是执行期拒绝。解锁信号挂在 `bcdp_*` 调用的公共出口上,工具体不知道分级存在;`bcdp_status` / `bcdp_help` / `bcdp_doctor` 自身也算活动信号(读了指南就得有工具可用)。
241
247
  - **闲置自动收回**:`lazy` + `idleTimeoutMin > 0` 时,空闲回收把后台浏览器停掉的同一刻收回扩展面;下次活动重新铺开。`always` 模式不受影响。
242
248
  - `legacyEgoToolNames` 的 `ego_*` 别名跟随其 `bcdp_*` 本体的级别。
243
- - 当前注入面写在 `bcdp_doctor` 报告首行(`tool injection: mode=lazy browse=open extended=open judge=open judgeKey=none active=no → live 6 / sealed 32`),不用猜。
244
- - 默认档下不碰浏览器的会话只有 **6** 个工具在场(≈ 2.9K 字符,−88.6%);要回到历史行为把 `toolInjection` 改成 `always`(38 件全在场需再配一个评审 Key)。
245
- - 四个字段都带 schema `.default()`:volatile 字段的表单描述符直接拿 schema 默认值,不写默认会出现「面板显示 A、运行时用 B」。
249
+ - 当前注入面写在 `bcdp_doctor` 报告首行(`tool injection: mode=lazy browse=open extended=open escape=open judge=open judgeKey=none active=no → live 9 / sealed 29`),不用猜。
250
+ - 默认档下不碰浏览器的会话只有 **9** 个工具在场(core 7 + escape 2 ≈ 3.8K 字符,−79.6%);要回到历史行为把 `toolInjection` 改成 `always`(38 件全在场需再配一个评审 Key)。
251
+ - 五个字段都带 schema `.default()`:volatile 字段的表单描述符直接拿 schema 默认值,不写默认会出现「面板显示 A、运行时用 B」。
246
252
 
247
253
  > 取舍提醒:窄工具(一个动作一个工具)是模型写对参数、少重试的护栏。把交互原子合并成脚本逃生舱会省上下文,但代价是模型要自己写 heredoc、出错率上升——本插件保持全部 38 个工具的签名不变,只改**出现时机**。
248
254
 
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.2.4",
5
+ "version": "1.3.0",
6
6
  "manifestVersion": "0.15",
7
7
  "facets": {
8
8
  "host": {
@@ -72,23 +72,31 @@
72
72
  "label": "always"
73
73
  }
74
74
  ],
75
- "hint": "lazy(默认)= 只常驻核心 6 个,首次 bcdp_* 调用后按下方开关注入,闲置回收时收回;always = 挂载即注册全部 38 个(历史行为)。"
75
+ "hint": "lazy(默认)= 常驻核心 7 个 + 逃生舱 2 个,其余首次 bcdp_* 调用后按下方开关注入,闲置回收时收回;always = 挂载即注册全部 38 个(历史行为)。"
76
76
  },
77
77
  {
78
78
  "path": [
79
79
  "toolBrowse"
80
80
  ],
81
- "label": "基础操作工具(14 个)",
81
+ "label": "基础操作工具(16 个)",
82
82
  "kind": "boolean",
83
- "hint": "开(默认)= 浏览器活动后正常注册;关 = 14 个工具从模型工具列表移除(点击/填写/键鼠/截图/读取/等待…)。"
83
+ "hint": "开(默认)= 浏览器活动后按 act → observe → wait 三波放行;关 = 16 个工具从模型工具列表移除(点击/填写/键鼠/拖拽/截图/读取/等待…)。"
84
84
  },
85
85
  {
86
86
  "path": [
87
87
  "toolExtended"
88
88
  ],
89
- "label": "扩展能力工具(13 个)",
89
+ "label": "扩展能力工具(8 个)",
90
90
  "kind": "boolean",
91
- "hint": "开(默认)= 正常注册;关 = 13 个工具移除(拖拽/上传/下载/对话框/裸 CDP/脚本逃生舱/登录导入)。"
91
+ "hint": "开(默认)= 浏览器活动后注册;关 = 8 个工具移除(裸 CDP/HTTP/上传/下载/对话框/验证码/登录落盘/登录导入)。"
92
+ },
93
+ {
94
+ "path": [
95
+ "toolEscape"
96
+ ],
97
+ "label": "逃生舱 cli / script(2 个)",
98
+ "kind": "boolean",
99
+ "hint": "始终可用——与其它档不同,它不等浏览器活动,因为一个 heredoc 就能做到其余 36 个工具的事。关 = 封印。"
92
100
  },
93
101
  {
94
102
  "path": [
package/lib/client.js CHANGED
@@ -1360,20 +1360,26 @@ var FAM_FIELD_GROUPS = [
1360
1360
  k: "toolInjection",
1361
1361
  kind: "sel",
1362
1362
  options: ["lazy", "always"],
1363
- 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)"],
1364
- zh: ["工具注入模式", "lazy(默认)= 只常驻核心 6 个,首次 bcdp_* 调用后铺开、闲置回收时收回;always = 挂载即注册全部(历史行为)"]
1363
+ en: ["Injection mode", "lazy (default) = the 7 core tools plus the 2 escape-hatch 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)"],
1364
+ zh: ["工具注入模式", "lazy(默认)= 常驻核心 7 个 + 逃生舱 2 个,其余在首次 bcdp_* 调用后铺开、闲置回收时收回;always = 挂载即注册全部(历史行为)"]
1365
1365
  },
1366
1366
  {
1367
1367
  k: "toolBrowse",
1368
1368
  kind: "bool",
1369
- 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 ...)"],
1370
- zh: ["基础操作工具(14 个)", "开(默认)= 浏览器活动后正常注册;关 = 14 个工具从模型工具列表移除(点击/填写/键鼠/截图/读取/等待…)"]
1369
+ en: ["Basic browsing tools (16)", "On (default) = released in three waves after browser activity (act → observe → wait); off = 16 tools removed from the model tool list (click / fill / key / drag / screenshot / read / wait ...)"],
1370
+ zh: ["基础操作工具(16 个)", "开(默认)= 浏览器活动后按 act → observe → wait 三波放行;关 = 16 个工具从模型工具列表移除(点击/填写/键鼠/拖拽/截图/读取/等待…)"]
1371
1371
  },
1372
1372
  {
1373
1373
  k: "toolExtended",
1374
1374
  kind: "bool",
1375
- en: ["Extended tools (13)", "On (default) = registered; off = 13 tools removed (drag / upload / download / dialog / raw CDP / script escape hatches / login import)"],
1376
- zh: ["扩展能力工具(13 个)", "开(默认)= 正常注册;关 = 13 个工具移除(拖拽/上传/下载/对话框/裸 CDP/脚本逃生舱/登录导入)"]
1375
+ en: ["Extended tools (8)", "On (default) = registered after browser activity; off = 8 tools removed (raw CDP / http / upload / download / dialog / captcha / auth flush / login import)"],
1376
+ zh: ["扩展能力工具(8 个)", "开(默认)= 浏览器活动后注册;关 = 8 个工具移除(裸 CDP/HTTP/上传/下载/对话框/验证码/登录落盘/登录导入)"]
1377
+ },
1378
+ {
1379
+ k: "toolEscape",
1380
+ kind: "bool",
1381
+ en: ["Escape hatch (2: cli / script)", "Always available — unlike the other tiers it does not wait for browser activity, because one heredoc can do what any of the other 36 tools do. Off = sealed"],
1382
+ zh: ["逃生舱(2 个:cli / script)", "始终可用——与其它档不同,它不等浏览器活动,因为一个 heredoc 就能做到其余 36 个工具的事。关 = 封印"]
1377
1383
  },
1378
1384
  {
1379
1385
  k: "toolJudge",
package/lib/index.js CHANGED
@@ -1004,6 +1004,19 @@ function parseCliStatus(stdout) {
1004
1004
  }
1005
1005
  }
1006
1006
  /**
1007
+ * R4 — the ego CLI may route the embedded runtime's output to either stream.
1008
+ * 0.6.0.16 on Windows sends everything (console.log, process.stdout.write and
1009
+ * our sentinels) to stderr and leaves stdout empty, so every sentinel/facade
1010
+ * reader must look at both. stdout goes first: when a CLI writes to both, the
1011
+ * authoritative payload stays where it always was.
1012
+ * @internal exported for tests
1013
+ */
1014
+ function mergeCliOutput(result) {
1015
+ if (result.stdout === "") return result.stderr;
1016
+ if (result.stderr === "") return result.stdout;
1017
+ return `${result.stdout}\n${result.stderr}`;
1018
+ }
1019
+ /**
1007
1020
  * Probe one link end to end: resolve → pick a working shape → (optionally)
1008
1021
  * read `--status` → confirm with a real heredoc round-trip.
1009
1022
  *
@@ -1055,7 +1068,7 @@ async function probeCliLink(input, io) {
1055
1068
  };
1056
1069
  let running;
1057
1070
  if (statusRun && statusRun.exitCode === 0 && !statusRun.timedOut) {
1058
- const parsed = parseCliStatus(statusRun.stdout);
1071
+ const parsed = parseCliStatus(mergeCliOutput(statusRun));
1059
1072
  if (parsed.ok) running = parsed.running;
1060
1073
  }
1061
1074
  const sdkArgs = input.useSdkPath === true && (input.sdkPath ?? "") !== "" ? ["--sdk-path", input.sdkPath] : [];
@@ -1092,9 +1105,9 @@ async function probeCliLink(input, io) {
1092
1105
  message: `spawn failed: ${result.spawnErrorCode}`,
1093
1106
  ...base
1094
1107
  };
1095
- const facadeMatch = (/* @__PURE__ */ new RegExp(`${CLI_READY_SENTINEL} (\\w+) (\\w+)`)).exec(result.stdout);
1108
+ const facadeMatch = (/* @__PURE__ */ new RegExp(`${CLI_READY_SENTINEL} (\\w+) (\\w+)`)).exec(mergeCliOutput(result));
1096
1109
  const facadesOk = input.useSdkPath !== true || facadeMatch?.[1] === "object" && facadeMatch?.[2] === "object";
1097
- if (result.exitCode !== 0 || !result.stdout.includes(CLI_READY_SENTINEL) || !facadesOk) {
1110
+ if (result.exitCode !== 0 || !mergeCliOutput(result).includes(CLI_READY_SENTINEL) || !facadesOk) {
1098
1111
  const tail = (result.stderr || result.stdout).trim().slice(-400);
1099
1112
  const facadeNote = facadesOk ? "" : `; the SDK harness did not expose the facade (taskSpaces=${facadeMatch?.[1] ?? "undefined"}, browser=${facadeMatch?.[2] ?? "undefined"})`;
1100
1113
  return {
@@ -2700,6 +2713,7 @@ const Config$1 = z.object({
2700
2713
  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(),
2701
2714
  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(),
2702
2715
  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(),
2716
+ toolEscape: z.boolean().default(true).description("Escape-hatch tier (2 tools: cli / script — run an arbitrary heredoc with page/browser/taskSpaces/fetch/cdp preloaded). Unlike every other non-core tier it is NOT held back until browser activity: the one tool that can do anything in a single call must always be reachable. Off = sealed.").volatile(),
2703
2717
  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(),
2704
2718
  localHeadless: z.boolean().description("Run the locally launched browser headless."),
2705
2719
  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(),
@@ -2966,6 +2980,7 @@ function resolveConfig(config = {}) {
2966
2980
  toolInjection: oneOf(config.toolInjection, ["lazy", "always"], "lazy"),
2967
2981
  toolBrowse: tierOpenByDefault(config.toolBrowse),
2968
2982
  toolExtended: tierOpenByDefault(config.toolExtended),
2983
+ toolEscape: tierOpenByDefault(config.toolEscape),
2969
2984
  toolJudge: tierOpenByDefault(config.toolJudge),
2970
2985
  localHeadless: config.localHeadless === void 0 ? false : Boolean(config.localHeadless),
2971
2986
  localUserDataDir: typeof config.localUserDataDir === "string" ? config.localUserDataDir : "",
@@ -3227,7 +3242,7 @@ const EGO_HELP_INDEX = {
3227
3242
  login: "bcdp_auth_flush: 把登录cookie落盘到ego profile; 观察窗登录引导条+『已登录,保存』按钮触发同一动作。bcdp_login_import: 从系统浏览器(Chrome/Edge/Brave)按域名导入登录cookie(source/domains/dryRun; 先dryRun看可导入项; ego浏览器须已在运行)。",
3228
3243
  script: "bcdp_cli / bcdp_script: 原样运行任意内置运行时 heredoc 脚本(page/browser/taskSpaces/site/fetch/cdp预载)。bcdp_script额外返回 duration/timedOut。",
3229
3244
  doctor: "bcdp_doctor: 体检环境(浏览器候选、vendored runtime、状态目录、CDP端口、任务空间、引擎与降级清单);首行附工具注入面快照。",
3230
- 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(两者也算浏览器活动,会把面铺开),或让用户在设置页「工具封印」里打开对应档位的开关;别猜测不存在的工具名。",
3245
+ injection: "工具分级注入(不是工具,是出现时机):38 个 bcdp_* 分八批——core(status/doctor/help/space_open/space_close/navigate/snapshot,常驻不可封印)/ act(点击填写键鼠拖拽)/ observe(截图页面信息读取js)/ wait(等待类)/ power(裸CDP/HTTP/上传/下载/对话框)/ session(验证码/登录落盘/登录导入)/ escape(cli/script 逃生舱)/ judge(bcdp_jev_*)。设置旋钮(全 volatile):toolInjection = lazy(默认,常驻 core + escape,首次 bcdp_* 调用后铺开其余)/ always(挂载即全量,历史行为);toolBrowse(act+observe+wait,内部按 act→observe→wait 三波放行)/ toolExtended(power+session)/ toolEscape(cli+script)/ toolJudge 四把开关——开 = 开放注册,关 = 该批从工具列表移除(core 级不给开关,封了就没解锁入口);judge 级即使开了仍需配 JEV/Laya Key。**escape 批不吃活动闸**:cli/script 是唯一的「一次调用干完任意多步任务」的入口,必须始终可达,不排在首次活动之后。封印 = 从工具列表里反注册,不是执行期报错;lazy 下闲置回收会把扩展面收回。**若某个 bcdp_* 工具不在你的工具列表里**:它被分级封印了——先跑 bcdp_status 或 bcdp_doctor(两者也算浏览器活动,会把面铺开),或让用户在设置页「工具封印」里打开对应档位的开关;别猜测不存在的工具名。",
3231
3246
  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)",
3232
3247
  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 未开放注册)。"
3233
3248
  };
@@ -3541,7 +3556,7 @@ const CORE = [
3541
3556
  "bcdp_navigate",
3542
3557
  "bcdp_snapshot"
3543
3558
  ];
3544
- const BROWSE = [
3559
+ const ACT = [
3545
3560
  "bcdp_click",
3546
3561
  "bcdp_fill",
3547
3562
  "bcdp_key",
@@ -3549,28 +3564,33 @@ const BROWSE = [
3549
3564
  "bcdp_scroll",
3550
3565
  "bcdp_select",
3551
3566
  "bcdp_check",
3567
+ "bcdp_drag"
3568
+ ];
3569
+ const OBSERVE = [
3552
3570
  "bcdp_screenshot",
3553
3571
  "bcdp_page_info",
3554
3572
  "bcdp_read_element",
3555
- "bcdp_js",
3573
+ "bcdp_js"
3574
+ ];
3575
+ const WAIT = [
3556
3576
  "bcdp_wait",
3557
- "bcdp_wait_for_selector"
3577
+ "bcdp_wait_for_selector",
3578
+ "bcdp_wait_for_url",
3579
+ "bcdp_wait_for_response"
3558
3580
  ];
3559
- const EXTENDED = [
3560
- "bcdp_drag",
3561
- "bcdp_upload",
3562
- "bcdp_download",
3563
- "bcdp_dialog",
3581
+ const POWER = [
3564
3582
  "bcdp_cdp",
3565
3583
  "bcdp_http",
3566
- "bcdp_cli",
3567
- "bcdp_script",
3584
+ "bcdp_upload",
3585
+ "bcdp_download",
3586
+ "bcdp_dialog"
3587
+ ];
3588
+ const SESSION = [
3568
3589
  "bcdp_captcha",
3569
3590
  "bcdp_auth_flush",
3570
- "bcdp_login_import",
3571
- "bcdp_wait_for_url",
3572
- "bcdp_wait_for_response"
3591
+ "bcdp_login_import"
3573
3592
  ];
3593
+ const ESCAPE = ["bcdp_cli", "bcdp_script"];
3574
3594
  const JUDGE = [
3575
3595
  "bcdp_jev_status",
3576
3596
  "bcdp_jev_ask",
@@ -3581,8 +3601,12 @@ const JUDGE = [
3581
3601
  /** 工具名 → 分级。`ego_*` 旧名(legacyEgoToolNames 别名)与 bcdp_* 同名同组。 */
3582
3602
  const TIER_OF_TOOL = new Map([
3583
3603
  ["core", CORE],
3584
- ["browse", BROWSE],
3585
- ["extended", EXTENDED],
3604
+ ["act", ACT],
3605
+ ["observe", OBSERVE],
3606
+ ["wait", WAIT],
3607
+ ["power", POWER],
3608
+ ["session", SESSION],
3609
+ ["escape", ESCAPE],
3586
3610
  ["judge", JUDGE]
3587
3611
  ].flatMap(([tier, names]) => names.map((n) => [n, tier])));
3588
3612
  /** 去掉 `bcdp_`/`ego_` 前缀后的裸名,便于策略表保持前缀无关。 */
@@ -3593,34 +3617,16 @@ const BATCH_ORDER = [
3593
3617
  "observe",
3594
3618
  "wait"
3595
3619
  ];
3596
- /** `browse` 级工具 → 批次。未登记的名字按 'act' 处理,绝不因缺表而被卡住。 */
3597
- const BROWSE_BATCH = {
3598
- click: "act",
3599
- fill: "act",
3600
- key: "act",
3601
- hover: "act",
3602
- scroll: "act",
3603
- select: "act",
3604
- check: "act",
3605
- screenshot: "observe",
3606
- page_info: "observe",
3607
- read_element: "observe",
3608
- js: "observe",
3609
- wait: "wait",
3610
- wait_for_selector: "wait"
3611
- };
3612
- /** 某工具的注入批次(前缀无关)。 */
3613
- const batchOfTool = (name$1) => BROWSE_BATCH[bareToolName(name$1)] ?? "act";
3614
3620
  /**
3615
- * 工具所属分级。未登记的名字落到 `extended`(最严的一档:宁可等活动解锁,
3616
- * 也不让新工具悄悄回到常驻面);调用方应当在启动时打一条 warn,见
3621
+ * 工具所属分级。未登记的名字落到 `power`(最严的一档:宁可等活动解锁,也不
3622
+ * 让新工具悄悄回到常驻面);调用方应当在启动时打一条 warn,见
3617
3623
  * `unknownTieredTools`。分级表漂移由 `tests/tool-tiers.test.ts` 的覆盖率断言
3618
3624
  * 兜住,这里只是运行期兜底。
3619
3625
  */
3620
3626
  function tierOfTool(name$1) {
3621
3627
  const bare = bareToolName(name$1);
3622
3628
  for (const [known, tier] of TIER_OF_TOOL) if (bareToolName(known) === bare) return tier;
3623
- return "extended";
3629
+ return "power";
3624
3630
  }
3625
3631
  /** 名单里所有查不到分级登记的工具名(启动自检 / 测试用)。 */
3626
3632
  const unknownTieredTools = (names) => names.filter((n) => ![...TIER_OF_TOOL.keys()].some((k) => bareToolName(k) === bareToolName(n)));
@@ -3633,36 +3639,43 @@ const judgeConfigured = (c) => (c.jevKey ?? "").trim() !== "" || (c.layaKey ?? "
3633
3639
  /** 某级开关的当前极性;`core` 恒开放。 */
3634
3640
  const tierOpen = (tier, p) => {
3635
3641
  switch (tier) {
3636
- case "browse": return p.toolBrowse;
3637
- case "extended": return p.toolExtended;
3642
+ case "core": return true;
3643
+ case "act":
3644
+ case "observe":
3645
+ case "wait": return p.toolBrowse;
3646
+ case "power":
3647
+ case "session": return p.toolExtended;
3648
+ case "escape": return p.toolEscape;
3638
3649
  case "judge": return p.toolJudge;
3639
- default: return true;
3640
3650
  }
3641
3651
  };
3642
3652
  /**
3643
3653
  * 该分级此刻是否允许注册。
3644
3654
  *
3645
- * 三条独立闸,任一不过即封印:
3646
- * ① 本级开关(一级一个,ON = 开放);
3655
+ * 四条独立闸,任一不过即封印:
3656
+ * ① 本级开关(见 tierOpen);
3647
3657
  * ② 评审级额外要求已配 Key(没 Key 的 `bcdp_jev_*` 只能回「未配置」);
3648
- * ③ 注入模式:`lazy` 下非 core 级要等活动,`always` 下不设时机闸。
3658
+ * ③ 活动闸:`lazy` 下非 core 级要等活动,`always` 下不设时机闸;
3659
+ * ④ 批次闸:只在 act/observe/wait 三批上按 batchDepth 递增放行。
3660
+ *
3661
+ * `escape` 是唯一的例外:它不吃③。逃生舱必须在模型手里始终可达——否则遇到
3662
+ * 「结构化工具没覆盖」的情形时,模型既调不动它、也没法用别的工具绕过。
3649
3663
  */
3650
3664
  function tierAllowed(tier, p) {
3665
+ if (tier === "core") return true;
3651
3666
  if (!tierOpen(tier, p)) return false;
3652
3667
  if (tier === "judge" && !p.judgeConfigured) return false;
3653
- if (tier === "core") return true;
3654
- return p.injection === "always" || p.active;
3655
- }
3656
- /** 某工具此刻是否允许注册(名字 → 分级 → 策略)。 */
3657
- function toolAllowed(name$1, p) {
3658
- const tier = tierOfTool(name$1);
3659
- if (!tierAllowed(tier, p)) return false;
3660
- if (tier === "browse" && p.injection !== "always") {
3668
+ if (tier === "escape") return true;
3669
+ if (p.injection === "always") return true;
3670
+ if (tier === "act" || tier === "observe" || tier === "wait") {
3671
+ if (!p.active) return false;
3661
3672
  const depth = p.batchDepth ?? BATCH_ORDER.length;
3662
- if (BATCH_ORDER.indexOf(batchOfTool(name$1)) >= depth) return false;
3673
+ return BATCH_ORDER.indexOf(tier) < depth;
3663
3674
  }
3664
- return true;
3675
+ return p.active;
3665
3676
  }
3677
+ /** 某工具此刻是否允许注册(名字 → 分级 → 策略)。 */
3678
+ const toolAllowed = (name$1, p) => tierAllowed(tierOfTool(name$1), p);
3666
3679
  function createTierInjector(o) {
3667
3680
  const label = o.label ?? "dsh-browser-cdp";
3668
3681
  /** 全部已登记工具,插入序。 */
@@ -7397,6 +7410,7 @@ async function runWithStaleSpaceRetry(ctx, cfg, exec, buildScript, graceOverride
7397
7410
  return result;
7398
7411
  }
7399
7412
  /** Find the last line carrying the sentinel and JSON-parse its payload. */
7413
+ /** @internal exported for tests */
7400
7414
  function parseSentinel(stdout) {
7401
7415
  const lines = stdout.split("\n");
7402
7416
  for (let i = lines.length - 1; i >= 0; i--) {
@@ -7486,8 +7500,8 @@ async function runEgoScript(subprocess, script, exec, cfg, graceOverrideMs) {
7486
7500
  spill: { maxBytes: cfg.maxOutputBytes }
7487
7501
  },
7488
7502
  stderr: {
7489
- maxBytes: 512e3,
7490
- spill: { maxBytes: 2e6 }
7503
+ maxBytes: cfg.maxOutputBytes,
7504
+ spill: { maxBytes: cfg.maxOutputBytes }
7491
7505
  }
7492
7506
  },
7493
7507
  graceMs: Number.isFinite(graceOverrideMs) && graceOverrideMs > 0 ? graceOverrideMs : cfg.graceMs,
@@ -7526,10 +7540,13 @@ async function runEgoScript(subprocess, script, exec, cfg, graceOverrideMs) {
7526
7540
  stdout,
7527
7541
  stderr
7528
7542
  };
7529
- const value = parseSentinel(stdout);
7543
+ const value = parseSentinel(mergeCliOutput({
7544
+ stdout,
7545
+ stderr
7546
+ }));
7530
7547
  if (value === void 0) return {
7531
7548
  ok: false,
7532
- error: `ego-browser finished but no ${SENTINEL} JSON payload was found on stdout${describeStderr(stderr)}`,
7549
+ error: `ego-browser finished but no ${SENTINEL} JSON payload was found on stdout/stderr${describeStderr(stderr)}`,
7533
7550
  stdout,
7534
7551
  stderr
7535
7552
  };
@@ -7689,6 +7706,9 @@ function apply(ctx, config = {}) {
7689
7706
  get toolExtended() {
7690
7707
  return resolveConfig(bridge.source()).toolExtended;
7691
7708
  },
7709
+ get toolEscape() {
7710
+ return resolveConfig(bridge.source()).toolEscape;
7711
+ },
7692
7712
  get toolJudge() {
7693
7713
  return resolveConfig(bridge.source()).toolJudge;
7694
7714
  },
@@ -7792,6 +7812,7 @@ function apply(ctx, config = {}) {
7792
7812
  injection: cfg.toolInjection,
7793
7813
  toolBrowse: cfg.toolBrowse,
7794
7814
  toolExtended: cfg.toolExtended,
7815
+ toolEscape: cfg.toolEscape,
7795
7816
  toolJudge: cfg.toolJudge,
7796
7817
  judgeConfigured: judgeConfigured({
7797
7818
  jevKey: cfg.jevKey,
@@ -7857,8 +7878,8 @@ function apply(ctx, config = {}) {
7857
7878
  {
7858
7879
  const s = tiers.surface();
7859
7880
  const unlisted = unknownTieredTools([...s.live, ...s.sealed]);
7860
- if (unlisted.length > 0) ctx.logger?.warn?.(`dsh-browser-cdp: tools missing from the tier table (defaulted to extended): ${unlisted.join(" ")}`);
7861
- 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({
7881
+ if (unlisted.length > 0) ctx.logger?.warn?.(`dsh-browser-cdp: tools missing from the tier table (defaulted to power): ${unlisted.join(" ")}`);
7882
+ 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"} escape=${cfg.toolEscape ? "open" : "sealed"} judge=${cfg.toolJudge ? "open" : "sealed"}, judgeConfigured=${judgeConfigured({
7862
7883
  jevKey: cfg.jevKey,
7863
7884
  layaKey: cfg.layaKey
7864
7885
  })})`);
@@ -8075,7 +8096,10 @@ function registerEgoStatus(ctx, cfg, reg, tiers) {
8075
8096
  graceMs: 15e3
8076
8097
  });
8077
8098
  const outcome = await handle.done;
8078
- const facades = parseStatusFacades(readAll(handle.collected.stdout));
8099
+ const facades = parseStatusFacades(mergeCliOutput({
8100
+ stdout: readAll(handle.collected.stdout),
8101
+ stderr: readAll(handle.collected.stderr)
8102
+ }));
8079
8103
  return {
8080
8104
  ok: true,
8081
8105
  available: outcome.exitCode === 0 && facades?.taskSpaces === "object" && facades?.browser === "object",
@@ -8883,6 +8907,10 @@ function registerActionTools(ctx, cfg, reg) {
8883
8907
  required: true
8884
8908
  },
8885
8909
  stderr: { type: "string" },
8910
+ output: {
8911
+ type: "string",
8912
+ description: "Merged stdout+stderr text of the CLI run. The ego CLI writes script output to stderr on Windows, so read this when `stdout` looks empty."
8913
+ },
8886
8914
  result: { type: "json" }
8887
8915
  }
8888
8916
  },
@@ -8893,11 +8921,12 @@ function registerActionTools(ctx, cfg, reg) {
8893
8921
  markEgoToolCall(callingSessionId(exec));
8894
8922
  const result = await runWithStaleSpaceRetry(ctx, cfg, exec, () => str(args.script, ""));
8895
8923
  if (!result.ok) throw new Error(result.error);
8896
- const parsed = parseSentinel(result.stdout);
8924
+ const parsed = parseSentinel(mergeCliOutput(result));
8897
8925
  return {
8898
8926
  ok: true,
8899
8927
  stdout: result.stdout,
8900
8928
  stderr: result.stderr,
8929
+ output: mergeCliOutput(result),
8901
8930
  result: parsed ?? null
8902
8931
  };
8903
8932
  },
@@ -8949,7 +8978,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
8949
8978
  kind: null,
8950
8979
  error: result.error
8951
8980
  };
8952
- const hc = (parseSentinel(result.stdout) || {}).humanCheck;
8981
+ const hc = (parseSentinel(mergeCliOutput(result)) || {}).humanCheck;
8953
8982
  return {
8954
8983
  ok: true,
8955
8984
  detected: !!hc?.detected,
@@ -9045,7 +9074,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
9045
9074
  jevKey: cfg.jevKey,
9046
9075
  layaKey: cfg.layaKey
9047
9076
  });
9048
- 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}`);
9077
+ lines.push(`tool injection: mode=${cfg.toolInjection} browse=${cfg.toolBrowse ? "open" : "sealed"} extended=${cfg.toolExtended ? "open" : "sealed"} escape=${cfg.toolEscape ? "open" : "sealed"} judge=${cfg.toolJudge ? "open" : "sealed"} judgeKey=${key ? "set" : "none"} active=${tiers.active() ? "yes" : "no"} → live ${s.live.length} / sealed ${s.sealed.length}`);
9049
9078
  }
9050
9079
  lines.push(`egoBin: ${cfg.egoBin}`);
9051
9080
  try {
@@ -9169,6 +9198,10 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
9169
9198
  required: true
9170
9199
  },
9171
9200
  stderr: { type: "string" },
9201
+ output: {
9202
+ type: "string",
9203
+ description: "Merged stdout+stderr text of the CLI run. The ego CLI writes script output to stderr on Windows, so read this when `stdout` looks empty."
9204
+ },
9172
9205
  result: { type: "json" },
9173
9206
  durationMs: { type: "integer" },
9174
9207
  timedOut: { type: "boolean" },
@@ -9188,15 +9221,17 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
9188
9221
  ok: false,
9189
9222
  stdout: result.stdout,
9190
9223
  stderr: result.stderr,
9224
+ output: mergeCliOutput(result),
9191
9225
  durationMs,
9192
9226
  timedOut: false,
9193
9227
  error: result.error
9194
9228
  };
9195
- const parsed = parseSentinel(result.stdout);
9229
+ const parsed = parseSentinel(mergeCliOutput(result));
9196
9230
  return {
9197
9231
  ok: true,
9198
9232
  stdout: result.stdout,
9199
9233
  stderr: result.stderr,
9234
+ output: mergeCliOutput(result),
9200
9235
  result: parsed ?? null,
9201
9236
  durationMs,
9202
9237
  timedOut: false
@@ -9813,4 +9848,4 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
9813
9848
  }
9814
9849
 
9815
9850
  //#endregion
9816
- export { Config, STATUS_FACADE_SCRIPT, STATUS_FACADE_SENTINEL, apply, buildEgoToolArgv, cdpAttachError, createActiveSpaceTracker, decideCdpAttach, findChromeBinary, findUpstreamPluginInstall, inject, name, parseStatusFacades, resolveEgoEnv, runWithStaleSpaceRetry, shouldReapBrowser };
9851
+ export { Config, STATUS_FACADE_SCRIPT, STATUS_FACADE_SENTINEL, apply, buildEgoToolArgv, cdpAttachError, createActiveSpaceTracker, decideCdpAttach, findChromeBinary, findUpstreamPluginInstall, inject, name, parseSentinel, parseStatusFacades, resolveEgoEnv, runWithStaleSpaceRetry, shouldReapBrowser };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-browser-cdp",
3
- "version": "1.2.4",
3
+ "version": "1.3.0",
4
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",