dsh-browser-cdp 1.4.1 → 1.6.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.de.md CHANGED
@@ -173,11 +173,11 @@ Beziehungen zu anderen Schaltern:
173
173
 
174
174
  | Kategorie | Werkzeuge |
175
175
  |---|---|
176
- | Task-Spaces | `bcdp_space_open` `bcdp_space_close` `bcdp_status` |
176
+ | Task-Spaces | `bcdp_space` (open/close/list/handoff/takeover) `bcdp_status` |
177
177
  | Seitenlesen | `bcdp_snapshot` (semantischer Baum) `bcdp_page_info` `bcdp_read_element` |
178
- | Navigation/Warten | `bcdp_navigate` (Tab-Wiederverwendung) `bcdp_wait` `bcdp_wait_for_selector` `bcdp_wait_for_url` `bcdp_wait_for_response` |
178
+ | Navigation/Warten | `bcdp_navigate` (Tab-Wiederverwendung) `bcdp_wait` (duration/selector/url/response/load/function/request/event) |
179
179
  | Interaktion | `bcdp_click` `bcdp_fill` `bcdp_hover` `bcdp_drag` `bcdp_select` `bcdp_check` `bcdp_key` `bcdp_scroll` |
180
- | Ausführung/Debugging | `bcdp_js` (Seitenauswertung) `bcdp_cdp` (rohes CDP) `bcdp_cli` (beliebiger heredoc) `bcdp_script` (Mehrstufen-Skript) |
180
+ | Ausführung/Debugging | `bcdp_js` (Seitenauswertung) `bcdp_cdp` (rohes CDP) `bcdp_script` (heredoc; verbatim = raw, no preamble) |
181
181
  | Ausgaben | `bcdp_screenshot` `bcdp_download` `bcdp_upload` |
182
182
  | Sitzung/Sicherheit | `bcdp_auth_flush` (Login-Persistenz) `bcdp_login_import` (browserübergreifender Login-Import) `bcdp_captcha` `bcdp_dialog` |
183
183
  | Meta-Werkzeuge | `bcdp_help` `bcdp_doctor` `bcdp_http` |
package/README.es.md CHANGED
@@ -173,11 +173,11 @@ Relación con otros interruptores:
173
173
 
174
174
  | Categoría | Herramientas |
175
175
  |---|---|
176
- | Espacios de tareas | `bcdp_space_open` `bcdp_space_close` `bcdp_status` |
176
+ | Espacios de tareas | `bcdp_space` (open/close/list/handoff/takeover) `bcdp_status` |
177
177
  | Lectura de páginas | `bcdp_snapshot` (árbol semántico) `bcdp_page_info` `bcdp_read_element` |
178
- | Navegación/espera | `bcdp_navigate` (reutiliza la pestaña) `bcdp_wait` `bcdp_wait_for_selector` `bcdp_wait_for_url` `bcdp_wait_for_response` |
178
+ | Navegación/espera | `bcdp_navigate` (reutiliza la pestaña) `bcdp_wait` (duration/selector/url/response/load/function/request/event) |
179
179
  | Interacción | `bcdp_click` `bcdp_fill` `bcdp_hover` `bcdp_drag` `bcdp_select` `bcdp_check` `bcdp_key` `bcdp_scroll` |
180
- | Ejecución/depuración | `bcdp_js` (evaluación en la página) `bcdp_cdp` (CDP crudo) `bcdp_cli` (heredoc arbitrario) `bcdp_script` (script multietapa) |
180
+ | Ejecución/depuración | `bcdp_js` (evaluación en la página) `bcdp_cdp` (CDP crudo) `bcdp_script` (heredoc; verbatim = raw, no preamble) |
181
181
  | Salidas | `bcdp_screenshot` `bcdp_download` `bcdp_upload` |
182
182
  | Sesión/seguridad | `bcdp_auth_flush` (persistencia de sesión) `bcdp_login_import` (importación de sesión entre navegadores) `bcdp_captcha` `bcdp_dialog` |
183
183
  | Metaherramientas | `bcdp_help` `bcdp_doctor` `bcdp_http` |
package/README.fr.md CHANGED
@@ -173,11 +173,11 @@ Relations avec les autres commutateurs :
173
173
 
174
174
  | Catégorie | Outils |
175
175
  |---|---|
176
- | Espaces de tâches | `bcdp_space_open` `bcdp_space_close` `bcdp_status` |
176
+ | Espaces de tâches | `bcdp_space` (open/close/list/handoff/takeover) `bcdp_status` |
177
177
  | Lecture de page | `bcdp_snapshot` (arbre sémantique) `bcdp_page_info` `bcdp_read_element` |
178
- | Navigation/attente | `bcdp_navigate` (réutilise l'onglet) `bcdp_wait` `bcdp_wait_for_selector` `bcdp_wait_for_url` `bcdp_wait_for_response` |
178
+ | Navigation/attente | `bcdp_navigate` (réutilise l'onglet) `bcdp_wait` (duration/selector/url/response/load/function/request/event) |
179
179
  | Interaction | `bcdp_click` `bcdp_fill` `bcdp_hover` `bcdp_drag` `bcdp_select` `bcdp_check` `bcdp_key` `bcdp_scroll` |
180
- | Exécution/débogage | `bcdp_js` (évaluation dans la page) `bcdp_cdp` (CDP brut) `bcdp_cli` (heredoc arbitraire) `bcdp_script` (script multi-étapes) |
180
+ | Exécution/débogage | `bcdp_js` (évaluation dans la page) `bcdp_cdp` (CDP brut) `bcdp_script` (heredoc; verbatim = raw, no preamble) |
181
181
  | Sorties | `bcdp_screenshot` `bcdp_download` `bcdp_upload` |
182
182
  | Session/sécurité | `bcdp_auth_flush` (persistance de la connexion) `bcdp_login_import` (import inter-navigateurs de l'état de connexion) `bcdp_captcha` `bcdp_dialog` |
183
183
  | Méta-outils | `bcdp_help` `bcdp_doctor` `bcdp_http` |
package/README.it.md CHANGED
@@ -173,11 +173,11 @@ Relazioni con gli altri interruttori:
173
173
 
174
174
  | Categoria | Strumenti |
175
175
  |---|---|
176
- | Spazi di lavoro | `bcdp_space_open` `bcdp_space_close` `bcdp_status` |
176
+ | Spazi di lavoro | `bcdp_space` (open/close/list/handoff/takeover) `bcdp_status` |
177
177
  | Lettura pagina | `bcdp_snapshot` (albero semantico) `bcdp_page_info` `bcdp_read_element` |
178
- | Navigazione/attesa | `bcdp_navigate` (riusa la tab) `bcdp_wait` `bcdp_wait_for_selector` `bcdp_wait_for_url` `bcdp_wait_for_response` |
178
+ | Navigazione/attesa | `bcdp_navigate` (riusa la tab) `bcdp_wait` (duration/selector/url/response/load/function/request/event) |
179
179
  | Interazione | `bcdp_click` `bcdp_fill` `bcdp_hover` `bcdp_drag` `bcdp_select` `bcdp_check` `bcdp_key` `bcdp_scroll` |
180
- | Esecuzione/debug | `bcdp_js` (valutazione nella pagina) `bcdp_cdp` (CDP grezzo) `bcdp_cli` (heredoc arbitrario) `bcdp_script` (script multistep) |
180
+ | Esecuzione/debug | `bcdp_js` (valutazione nella pagina) `bcdp_cdp` (CDP grezzo) `bcdp_script` (heredoc; verbatim = raw, no preamble) |
181
181
  | Output | `bcdp_screenshot` `bcdp_download` `bcdp_upload` |
182
182
  | Sessione/sicurezza | `bcdp_auth_flush` (persistenza dell'accesso) `bcdp_login_import` (import dell'accesso tra browser) `bcdp_captcha` `bcdp_dialog` |
183
183
  | Meta-strumenti | `bcdp_help` `bcdp_doctor` `bcdp_http` |
package/README.md CHANGED
@@ -36,7 +36,7 @@
36
36
 
37
37
  **登录态导入(v0.8.5 新增)**:工具 `bcdp_login_import`,把你日常 Chrome/Edge/Brave 里的登录 cookie **按域名**复制进 agent 浏览器(真实二进制无头启动 + CDP 透传读取,兼容 Chrome 127+ 的 App-Bound Encryption,不做离线解密;源浏览器运行中可选择优雅关闭后导入,窗口下次启动自动恢复)。cookie 值不出现在任何日志与输出中;导入前自动备份源 cookie 库,异常清空自动还原。配合默认的磁盘持久化 Profile,导入的登录态跨重启永久保留。
38
38
 
39
- 一款 **CDP 浏览器代理**:把 [CitroLabs/ego-lite](https://github.com/CitroLabs/ego-lite)(给 AI Agent 用的 Chromium)作为内置运行时接入 DeepSeek Harness,以 **41 个结构化 `bcdp_*` 工具**驱动浏览器,并配一套**实时观察前端口**——agent 后台操作网页时,你能像看直播一样看到它正在浏览的每个页面,还能直接操作它。
39
+ 一款 **CDP 浏览器代理**:把 [CitroLabs/ego-lite](https://github.com/CitroLabs/ego-lite)(给 AI Agent 用的 Chromium)作为内置运行时接入 DeepSeek Harness,以 **34 个结构化 `bcdp_*` 工具**驱动浏览器,并配一套**实时观察前端口**——agent 后台操作网页时,你能像看直播一样看到它正在浏览的每个页面,还能直接操作它。
40
40
 
41
41
  **一点私藏的独特之处(self-observation)**:agent 用的就是这一个 Chromium——连它操作 **DSH 自身**(管理会话、任务看板、调设置)时,观察窗也实时显示、你能随时接手。不只是"看得见 agent 在网页上干活",连 agent 操作 DSH 界面本身都是全程可见、可掌控的。
42
42
 
@@ -50,7 +50,7 @@
50
50
 
51
51
  | 能力 | 本插件(本仓库) | 同类插件(Da1dr1em/dsh-ego-browser) |
52
52
  |---|---|---|
53
- | 结构化工具数 | **41 个**,职责单一、可确定性调用 | **3 个**(`run`/`help`/`status`) |
53
+ | 结构化工具数 | **34 个**,职责单一、可确定性调用 | **3 个**(`run`/`help`/`status`) |
54
54
  | 实时观察窗(CDP JPEG / FFmpeg H.264 双后端 + 标签条 + 历史抽屉) | ✅ 有 | ❌ 无 |
55
55
  | 监控窗鼠标**直接操作**真实浏览器(点击/拖拽/滚动回传 CDP) | ✅ 有 | ❌ 无 |
56
56
  | **观察窗点选元素 → 捕获并引用进对话输入框**(`[CDP-PICKS]` 结构化块,人工指认目标) | ✅ 有 | ❌ 无 |
@@ -64,7 +64,7 @@
64
64
  - **控得住**:别家只读;我们监控窗**直接驱动**同一个 agent 浏览器,需要时你亲手接管(缩放/拖拽/点击),不必打断 agent 重来。
65
65
  - **指得准**:你在观察窗里**点选**页面元素,插件捕获其 `backendNodeId`/`tag`/`id` 与语义描述,以 `[CDP-PICKS]` 结构化块并入对话输入框草稿(同页多元素自动合并编号)——agent 拿到的是精确目标,不用猜"你说的按钮是哪个"。
66
66
 
67
- > 以上对比基于公开可见的可核实事实:本仓库代码(`bin/cdp-cast-worker.mjs` 实时推流 + CDP 输入回传、`lib/index.js` 41 个注册工具、`lib/cast-server.js` host 桥接、`lib/client.js` 的 `deliverPickToConversation` 点选引用)与同类插件的源码/README(其 `src/tools.ts` 仅注册 `ego_browser_run` / `ego_browser_help` / `ego_browser_status`)。此文档不含对任何他人的贬低——我们只陈述自己多实现并验证了哪些能力。
67
+ > 以上对比基于公开可见的可核实事实:本仓库代码(`bin/cdp-cast-worker.mjs` 实时推流 + CDP 输入回传、`lib/index.js` 34 个注册工具、`lib/cast-server.js` host 桥接、`lib/client.js` 的 `deliverPickToConversation` 点选引用)与同类插件的源码/README(其 `src/tools.ts` 仅注册 `ego_browser_run` / `ego_browser_help` / `ego_browser_status`)。此文档不含对任何他人的贬低——我们只陈述自己多实现并验证了哪些能力。
68
68
 
69
69
  **相对 [ego-lite](https://github.com/CitroLabs/ego-lite) 本体,我们多做了这些(都可对照本仓库代码核实):**
70
70
 
@@ -205,63 +205,90 @@ dshx list # 应显示:[on] dsh-
205
205
 
206
206
  识别失败的端点(`engine: unknown`)保持**全能力**——误判只应"少给",不应"错给"。
207
207
 
208
- ## 工具清单(41 个,前缀 `bcdp_`,完整索引见 `bcdp_help`)
208
+ ## 工具清单(34 个,前缀 `bcdp_`,完整索引见 `bcdp_help`)
209
209
 
210
210
  | 类别 | 工具 |
211
211
  |---|---|
212
- | 任务空间 | `bcdp_space_open` `bcdp_space_close` `bcdp_space`(列出/移交/接管) `bcdp_status` |
212
+ | 任务空间 | `bcdp_space`(open / close / list / handoff / takeover) `bcdp_status` |
213
213
  | 页面读取 | `bcdp_snapshot`(语义树) `bcdp_page_info` `bcdp_read_element` |
214
- | 导航/标签/等待 | `bcdp_navigate`(复用 tab / reload) `bcdp_tab`(list/current/new/switch/close) `bcdp_wait` `bcdp_wait_page`(load/function/request/event) `bcdp_wait_for_selector` `bcdp_wait_for_url` `bcdp_wait_for_response` |
214
+ | 导航/标签/等待 | `bcdp_navigate`(复用 tab / reload) `bcdp_tab`(list/current/new/switch/close) `bcdp_wait`(duration / selector / url / response / load / function / request / event) |
215
215
  | 交互 | `bcdp_click` `bcdp_fill` `bcdp_hover` `bcdp_drag` `bcdp_select` `bcdp_check` `bcdp_key`(type/insert) `bcdp_scroll` |
216
- | 执行/调试 | `bcdp_js`(页面求值) `bcdp_cdp`(原始 CDP) `bcdp_cli`(任意 heredoc) `bcdp_script`(多步脚本) |
216
+ | 执行/调试 | `bcdp_js`(页面求值) `bcdp_cdp`(原始 CDP) `bcdp_script`(多步脚本;`verbatim:true` = 原 `bcdp_cli` 的裸 heredoc) |
217
217
  | 输出 | `bcdp_screenshot` `bcdp_download` `bcdp_upload` |
218
218
  | 会话/安全 | `bcdp_auth_flush`(登录落盘) `bcdp_login_import`(跨浏览器登录态导入) `bcdp_captcha` `bcdp_dialog` |
219
219
  | 元工具 | `bcdp_help` `bcdp_doctor` `bcdp_http` |
220
220
  | 评审(JEV/Laya,外接判定服务可选) | `bcdp_jev_status` `bcdp_jev_frame` `bcdp_jev_ask` `bcdp_jev_run` `bcdp_jev_attempt` |
221
221
 
222
+
223
+ ### 1.5.0 迁移表(旧名 → 新调用)
224
+
225
+ wait / space / escape 三族已按 `op` 合并,旧工具名**移除**(不保留别名——别名同样吃 schema 预算,等于没省)。其余工具名不变。
226
+
227
+ | 旧调用 | 新调用 |
228
+ |---|---|
229
+ | `bcdp_wait` `{ms}` | `bcdp_wait` `{op:"duration", ms}` |
230
+ | `bcdp_wait_for_selector` `{selector, state, timeout}` | `bcdp_wait` `{op:"selector", selector, state, timeout}` |
231
+ | `bcdp_wait_for_url` `{pattern, timeout}` | `bcdp_wait` `{op:"url", pattern, timeout}` |
232
+ | `bcdp_wait_for_response` `{url, body, timeout}` | `bcdp_wait` `{op:"response", url, body, timeout}` |
233
+ | `bcdp_wait_page` `{op:"load"\|"function"\|"request"\|"event", …}` | `bcdp_wait` 同名 op(`op` 取值不变,直接搬家) |
234
+ | `bcdp_space_open` `{name}` | `bcdp_space` `{op:"open", name}` |
235
+ | `bcdp_space_close` `{name, keep}` | `bcdp_space` `{op:"close", name, keep}` |
236
+ | `bcdp_cli` `{script}` | `bcdp_script` `{script, verbatim:true}` |
237
+
238
+ > `op` 合并后各 op 的必需参数写在工具描述里;缺参会返回带 op 名的 `reason`(如 `bcdp_wait: selector is required for op=selector`),不会静默降级。
239
+
222
240
  ## 工具注入分级(懒注册 / 分级 / 锁定)
223
241
 
224
- 41 个工具全量注册时,**每个会话每一轮**都要为它们的 schema 付费(挂载级实测 `description` + `parameters` 序列化 ≈ 24.0K 字符 ≈ 6.9K token;1.3.2 的 38 工具基线用同一口径实测为 ≈ 21.0K,本版本 3 新工具 + 3 扩展把全量面抬高 **+14.7%**,锁在 ≤+15% 门禁内),而不碰浏览器的会话一个也用不上。插件因此把「谁能出现在模型面前」收成一处策略(`src/toolTiers.ts`),分**八批**注入。
242
+ 34 个工具全量注册时,**每个会话每一轮**都要为它们的 schema 付费(挂载级实测 `description` + `parameters` 序列化 = **22,224 字符** ≈ 6.4K token;1.3.2 的 38 工具基线用同一口径实测为 20,951,1.5.0 三族合并后仅高出 **+6.1%**,远低于 ≤+15% 门禁),而不碰浏览器的会话一个也用不上。插件因此把「谁能出现在模型面前」收成一处策略(`src/toolTiers.ts`),分**八批**注入。
225
243
 
226
- > **8 批 ≠ 8 个开关**。批次是*注入时机*,开关是*用户面*(§9.3「开关与批次解耦」)。当前 4 个开关管 8 批:`toolBrowse` 管 act+observe+wait 三批并按波次放行,`toolExtended` 管 power+session,`toolEscape`、`toolJudge` 各管一批。所以「`toolBrowse` = 18 个」指的是**并集上限**,实际第一波只放 9 个。
244
+ > **8 批 ≠ 8 个开关**。批次是*注入时机*,开关是*用户面*(§9.3「开关与批次解耦」)。当前 4 个开关管 8 批:`toolBrowse` 管 act+observe+wait 三批并按波次放行,`toolExtended` 管 power+session,`toolEscape`、`toolJudge` 各管一批。所以「`toolBrowse` = 14 个」指的是**并集上限**,实际第一波只放 9 个。
227
245
 
228
246
  | 批次 | 成员 | schema | 何时出现 |
229
247
  |---|---|---:|---|
230
- | **core** 常驻(8) | `bcdp_status` `bcdp_doctor` `bcdp_help` `bcdp_space_open` `bcdp_space_close` `bcdp_space` `bcdp_navigate` `bcdp_snapshot` | 3,892 | 永远在场,不可封印——否则 lazy 模式连解锁入口都没有 |
248
+ | **core** 常驻(6) | `bcdp_status` `bcdp_doctor` `bcdp_help` `bcdp_space` `bcdp_navigate` `bcdp_snapshot` | 3,589 | 永远在场,不可封印——否则 lazy 模式连解锁入口都没有 |
231
249
  | **act** 动手(9) | click / fill / key / hover / scroll / select / check / drag / tab | 5,243 | `lazy` 下首次活动放第一波 |
232
250
  | **observe** 观察(4) | screenshot / page_info / read_element / js | 2,037 | 第二次活动 |
233
- | **wait** 等待(5) | wait / wait_page / wait_for_selector / wait_for_url / wait_for_response | 2,925 | 第三次活动 |
251
+ | **wait** 等待(1) | `bcdp_wait`(duration / selector / url / response / load / function / request / event) | 1,925 | 第三次活动 |
234
252
  | **power** 重量级(5) | raw CDP / http / upload / download / dialog | 3,283 | 首次活动(同 `toolExtended`) |
235
253
  | **session** 登录态(3) | captcha / auth_flush / login_import | 1,694 | 首次活动(同 `toolExtended`) |
236
- | **escape** 逃生舱(2) | cli / script | 1,897 | **冷启动即在**,不吃活动闸(见下) |
254
+ | **escape** 逃生舱(1) | `bcdp_script`(`verbatim:true` = 原 cli 的裸 heredoc) | 1,389 | **冷启动即在**,不吃活动闸(见下) |
237
255
  | **judge** 评审链(5) | `bcdp_jev_*` | 3,064 | 除解锁外,**还要求配了 JEV 或 Laya Key** |
238
- | **合计** | 41 | **24,035** | — |
256
+ | **合计** | 34 | **22,224** | — |
239
257
 
240
258
  设置项在插件设置页**最上方**的「工具封印」分块(全部 volatile,翻完当场生效,不重启插件)——一个开关管一组批次,形状照 dsh-prime-memory 的「工具封印」:
241
259
 
242
260
  - **`toolInjection`** `lazy`(**默认**:常驻 core + escape,其余首次 `bcdp_*` 调用后按开关注入)/ `always`(挂载即全量,历史行为)。
243
- - **`toolBrowse`**(act + observe + wait = 16)/ **`toolExtended`**(power + session = 8)/ **`toolEscape`**(cli + script = 2)/ **`toolJudge`**(5):开 = 开放注册,关 = 该批从模型工具列表移除。四组各自独立,封一组不波及别组;`core` 级不给开关(封了就没了活动入口)。
261
+ - **`toolBrowse`**(act + observe + wait = 14)/ **`toolExtended`**(power + session = 8)/ **`toolEscape`**(script = 1)/ **`toolJudge`**(5):开 = 开放注册,关 = 该批从模型工具列表移除。四组各自独立,封一组不波及别组;`core` 级不给开关(封了就没了活动入口)。
244
262
 
245
- **escape 批为什么单独成组、且不等活动**:`cli` / `script` 是唯一能在一次调用里干完任意多步任务的入口(`page` / `browser` / `taskSpaces` / `fetch` / `cdp` 全预置),其余 39 个工具能做的事它都能做。所以它必须始终可达——否则模型遇到「结构化工具没覆盖」的情形时手里没有任何逃生手段。这也让它成为**按需只开逃生舱**的合法姿势:关掉 `toolExtended`、留着 `toolEscape`,只留 2 个工具。
263
+ **escape 批为什么单独成组、且不等活动**:`bcdp_script` 是唯一能在一次调用里干完任意多步任务的入口(`page` / `browser` / `taskSpaces` / `fetch` / `cdp` 全预置),其余 33 个工具能做的事它都能做。所以它必须始终可达——否则模型遇到「结构化工具没覆盖」的情形时手里没有任何逃生手段。这也让它成为**按需只开逃生舱**的合法姿势:关掉 `toolExtended`、留着 `toolEscape`,只留 1 个工具。
246
264
 
247
265
  行为要点:
248
266
 
249
267
  - **封印 = 反注册**(工具从模型的工具列表里消失),不是执行期拒绝。解锁信号挂在 `bcdp_*` 调用的公共出口上,工具体不知道分级存在;`bcdp_status` / `bcdp_help` / `bcdp_doctor` 自身也算活动信号(读了指南就得有工具可用)。
250
268
  - **闲置自动收回**:`lazy` + `idleTimeoutMin > 0` 时,空闲回收把后台浏览器停掉的同一刻收回扩展面;下次活动重新铺开。`always` 模式不受影响。
251
269
  - `legacyEgoToolNames` 的 `ego_*` 别名跟随其 `bcdp_*` 本体的级别。
252
- - 当前注入面写在 `bcdp_doctor` 报告首行(`tool injection: mode=lazy browse=open extended=open escape=open judge=open judgeKey=none active=no → live 10 / sealed 31`),不用猜。
253
- - 默认档下不碰浏览器的会话只有 **10** 个工具在场(core 8 + escape 2 = 5,789 字符 ≈ 1,665 token,−75.9%);要回到历史行为把 `toolInjection` 改成 `always`(41 件全在场需再配一个评审 Key)。
254
- - **各档实测注入面**(挂载级口径,1.4.1):默认 10 个 / 1,665 tok → 首次活动 27 个 / 4,602 tok → 第 2 波(observe)31 个 / 5,189 tok → 第 3 波(wait)36 个 / 6,031 tok → 全量 41 个 / 6,910 tok。
270
+ - 当前注入面写在 `bcdp_doctor` 报告首行(`tool injection: mode=lazy browse=open extended=open escape=open judge=open judgeKey=none active=no → live 7 / sealed 27`),不用猜。
271
+ - 默认档下不碰浏览器的会话只有 **7** 个工具在场(core 6 + escape 1 = 4,978 字符 ≈ 1,430 token,−77.6%);要回到历史行为把 `toolInjection` 改成 `always`(34 件全在场需再配一个评审 Key)。
272
+ - **各档实测注入面**(挂载级口径,1.5.0;字符为实测,token 按同一比例折算):默认 7 个 / 4,978 字符 ≈1,430 tok → 首次活动 24 个 / 15,198 ≈4,370 tok → 第 2 波(observe)28 个 / 17,235 ≈4,955 tok → 第 3 波(wait)29 个 / 19,160 ≈5,509 tok → 全量 34 个 / 22,224 ≈6,389 tok。
255
273
  - 五个字段都带 schema `.default()`:volatile 字段的表单描述符直接拿 schema 默认值,不写默认会出现「面板显示 A、运行时用 B」。
256
274
 
257
- > 取舍提醒:窄工具(一个动作一个工具)是模型写对参数、少重试的护栏。把交互原子合并成脚本逃生舱会省上下文,但代价是模型要自己写 heredoc、出错率上升——本插件保持全部 41 个工具的签名不变,只改**出现时机**。
275
+ > 取舍提醒:窄工具(一个动作一个工具)是模型写对参数、少重试的护栏。1.5.0 只合并了 **wait / space / escape** 三族同源冗余(41 → 34,省 1,869 字符 schema):五个 wait 共用同一 preamble 与 timeout 语义、三个 space 本就是同一个 op 工具的碎片、cli/script 是同一 heredoc 运行时。代价是这三族的旧工具名不再存在(见上方迁移表);交互原子(click/fill/key…)**不合并**,因为它们是模型写对参数的护栏。
276
+
277
+ ## 任务空间命名与并发隔离(1.6.0)
258
278
 
259
- ## 任务空间命名与并发隔离(1.4.1)
279
+ > **默认就是会话隔离**:不传 `space` 的调用落在**本会话自己的**任务空间 `dsh-agent-<会话id前8位>`,两个会话永远不会共用或抢占同一个浏览上下文。**只有显式写 `space: 'default'`(或 `bcdp_space op=open name='default'`)才会用那个跨会话共享的具名槽。**
280
+
281
+ | 你怎么写 | 落到哪个空间 |
282
+ |---|---|
283
+ | 省略 `space`(默认,`defaultSpace` 未设 = `:auto`) | `dsh-agent-<会话id前8位>`,每会话独立 |
284
+ | `space: 'default'` / `op=open name='default'` | 共享具名槽 `default`(此后该会话固定用它) |
285
+ | `defaultSpace: 'default'`(配置项改成具名) | 所有会话默认都用 `default`(退回旧行为,全局生效) |
286
+ | 无 session 的调用(`__global__`) | `default`,保证向后兼容 |
260
287
 
261
- - **默认空间名统一为 `default`**:代码常量 `DEFAULT_SPACE='default'`、`bcdp_space_open` 描述、`Config.defaultSpace` 三者一致。持久化 Profile 模式(默认)下**始终复用这一个具名槽**——登录态、tab、stream 跨会话保留;不要因为"当前在做任务 X"就另开编号空间(`#4`/`#5`),那会丢持久化。
262
- - **`defaultSpace` 可配(A)**:`Config.defaultSpace` 是 volatile 标量,留空折叠为 `'default'`,热更新不重注册。注意区分两个概念:配置值 `cfg.defaultSpace`(schema 里那个)和运行时的**当前会话活值** `cfg.activeSpace`(命令实际用的 `useSpace(...)` 入参);前者是设置,后者随会话切换。
288
+ - **`defaultSpace`(A)**:volatile 标量,**留空/缺失折叠为 `:auto`**(1.6.0 起,此前折叠为 `default`),热更新不重注册。注意区分两个概念:配置值 `cfg.defaultSpace`(schema 里那个,可以是 `:auto` 或具名)与运行时**当前会话活值** `cfg.activeSpace`(命令实际用的 `useSpace(...)` 入参);前者是设置,后者随会话与显式选择切换。
289
+ - **`:auto` 派生(C)**:`:auto` 在**两种模式**下都派生 `dsh-agent-<sid8>` —— 空间**命名**与 `isolateSpaces`(那个只管 Profile 落盘还是内存沙箱)是两条独立的轴。会话 id 会先剥掉 `session-` 前缀再取 8 位:真实 DSH id 形如 `session-52adc205-…`,直接 `slice(0,8)` 会得到 `session-`,让**所有会话撞成同一个空间**——这正是隔离失效的经典坑,已用 `sessionSpaceToken()` 修掉并有回归测试。
263
290
  - **会话级隔离(B)**:活动空间追踪器按 `sessionId` 键控成一张槽位表(`Map<string,Slot>`,无 session 的调用落 `__global__` 槽保持向后兼容)。每个 `bcdp_*` 调用一进来就 `setCurrentSession(callingSessionId(exec))`,所以**并发多会话各开各的空间互不漂移**——A 会话重启空间不波及 B。
264
- - **`:auto` 哨兵(C)**:沙箱模式(`isolateSpaces:true`)下默认名派生为 `dsh-agent-<sessionId 前 8 位>`,给每个会话一个独立命名空间;持久模式下 `:auto` 折叠为具名单槽 `default`。`resolveConfig` 把 `:auto` 原样保留,由追踪器据 sessionId + 模式决定真正落点。
291
+ - **不要再手动建编号空间**:不需要 `#4`/`#5` 这类手工命名,隔离已经由会话派生自动完成;需要共享就走显式 `default`。
265
292
 
266
293
  ### 跨调用稳定定位(D1)
267
294
 
package/README.ru.md CHANGED
@@ -173,11 +173,11 @@ dshx list # должно пока
173
173
 
174
174
  | Категория | Инструменты |
175
175
  |---|---|
176
- | Пространства задач | `bcdp_space_open` `bcdp_space_close` `bcdp_status` |
176
+ | Пространства задач | `bcdp_space` (open/close/list/handoff/takeover) `bcdp_status` |
177
177
  | Чтение страниц | `bcdp_snapshot` (семантическое дерево) `bcdp_page_info` `bcdp_read_element` |
178
- | Навигация/ожидание | `bcdp_navigate` (повторно использует вкладку) `bcdp_wait` `bcdp_wait_for_selector` `bcdp_wait_for_url` `bcdp_wait_for_response` |
178
+ | Навигация/ожидание | `bcdp_navigate` (повторно использует вкладку) `bcdp_wait` (duration/selector/url/response/load/function/request/event) |
179
179
  | Взаимодействие | `bcdp_click` `bcdp_fill` `bcdp_hover` `bcdp_drag` `bcdp_select` `bcdp_check` `bcdp_key` `bcdp_scroll` |
180
- | Выполнение/отладка | `bcdp_js` (вычисление на странице) `bcdp_cdp` (сырой CDP) `bcdp_cli` (произвольный heredoc) `bcdp_script` (многошаговый скрипт) |
180
+ | Выполнение/отладка | `bcdp_js` (вычисление на странице) `bcdp_cdp` (сырой CDP) `bcdp_script` (heredoc; verbatim = raw, no preamble) |
181
181
  | Вывод | `bcdp_screenshot` `bcdp_download` `bcdp_upload` |
182
182
  | Сессия/безопасность | `bcdp_auth_flush` (персистентность входа) `bcdp_login_import` (импорт входа между браузерами) `bcdp_captcha` `bcdp_dialog` |
183
183
  | Мета-инструменты | `bcdp_help` `bcdp_doctor` `bcdp_http` |
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.4.1",
5
+ "version": "1.6.0",
6
6
  "manifestVersion": "0.15",
7
7
  "facets": {
8
8
  "host": {
package/lib/index.js CHANGED
@@ -2620,7 +2620,7 @@ const encoder = z.union([
2620
2620
  ]);
2621
2621
  const Config$1 = z.object({
2622
2622
  isolateSpaces: z.boolean().description("Space isolation: false = persistent profile (keep logins across restarts); true = isolated sandbox.").volatile(),
2623
- defaultSpace: z.string().description("Default task-space name when a bcdp_* call omits `space`. Persistent-profile mode reuses this single named slot — set it to the same value across sessions to share login state. Set `:auto` in isolated-sandbox mode to derive a per-session name (dsh-agent-<sessionId8>). Leave default (\"default\") unless you are running multiple agents in parallel.").volatile(),
2623
+ defaultSpace: z.string().description("Task space used when an bcdp_* call omits `space`. Default `:auto` = derive a per-session space `dsh-agent-<sessionId8>`, so concurrent sessions never share or hijack each other's browsing context. Set a fixed name (e.g. `default`) to reuse ONE shared slot across sessions — pass `space: \"default\"` on a single call for the same effect. Note this only names spaces; whether the browser profile itself persists is controlled by isolateSpaces.").volatile(),
2624
2624
  idleTimeoutMin: z.number().min(0).max(1440).step(1).description("Auto-stop the backing browser after N minutes without an bcdp_* call (0 = off). Relaunches on demand at the next call.").volatile(),
2625
2625
  chromePath: z.string().description("Path to Chrome/Chromium. Empty = auto-detect.").volatile(),
2626
2626
  captureBackend: backend.description("Capture backend: auto, cdp, or ffmpeg.").volatile(),
@@ -2967,7 +2967,7 @@ function resolveConfig(config = {}) {
2967
2967
  runtimeArgs: typeof config.runtimeArgs === "string" ? config.runtimeArgs : typeof config.egoCliArgs === "string" ? config.egoCliArgs : "",
2968
2968
  chromeArgs: typeof config.chromeArgs === "string" ? config.chromeArgs : "",
2969
2969
  isolateSpaces: typeof config.isolateSpaces === "boolean" ? config.isolateSpaces : config.isolateSpaces === "true" || config.isolateSpaces === "1" || config.isolateSpaces === 1,
2970
- defaultSpace: typeof config.defaultSpace === "string" && config.defaultSpace.trim() !== "" ? config.defaultSpace.trim() : "default",
2970
+ defaultSpace: typeof config.defaultSpace === "string" && config.defaultSpace.trim() !== "" ? config.defaultSpace.trim() : AUTO_SPACE_SENTINEL,
2971
2971
  idleTimeoutMin: finiteIn(config.idleTimeoutMin, 0, 1440) ? config.idleTimeoutMin : 0,
2972
2972
  links: sanitizeLinks(config.links ?? config.cdpTargets).links.map(normalizeProbeState),
2973
2973
  activeTargetId: typeof config.activeTargetId === "string" ? config.activeTargetId : "",
@@ -3231,22 +3231,22 @@ function envelopeError(code, message) {
3231
3231
  * add/change a tool, remember to sync an entry here or bcdp_help won't find it.
3232
3232
  */
3233
3233
  const EGO_HELP_INDEX = {
3234
- 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` 查询,或直接给工具名。",
3235
- tools: "工具清单: bcdp_status, bcdp_space_open, bcdp_space, bcdp_space_close, bcdp_snapshot, bcdp_navigate, bcdp_tab, bcdp_click(+double), bcdp_fill, bcdp_js, bcdp_cdp, bcdp_screenshot(+selector), bcdp_page_info, bcdp_wait, bcdp_wait_page, bcdp_wait_for_selector, bcdp_wait_for_url, bcdp_wait_for_response, bcdp_key(+text/type/insert), 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。",
3234
+ overview: "CDP 浏览器代理:结构化浏览器工具。导航/交互/观察/表单/网络/等待/键鼠皆有专项工具,另提供 bcdp_help(本索引)、bcdp_doctor(体检)、bcdp_script(自由脚本逃生舱;verbatim:true 为裸 heredoc)。连接与激活见 topic=links。分类见: tools / navigate / observe / input / keyboard-mouse / form / wait / network / login / script / doctor / lightpanda / injection。用 `topic` 查询,或直接给工具名。",
3235
+ tools: "工具清单: bcdp_status, bcdp_space(+op:open/close/list/handoff/takeover), bcdp_snapshot, bcdp_navigate, bcdp_tab, bcdp_click(+double), bcdp_fill, bcdp_js, bcdp_cdp, bcdp_screenshot(+selector), bcdp_page_info, bcdp_wait(+op:duration/selector/url/response/load/function/request/event), bcdp_key(+text/type/insert), 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_script(+verbatim), bcdp_jev_status, bcdp_jev_frame, bcdp_jev_attempt, bcdp_jev_ask, bcdp_jev_run。",
3236
3236
  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 连接。",
3237
- navigate: "bcdp_navigate: 打开URL或切tab(同任务复用当前tab)。bcdp_wait_for_url: 等跳转(登录/分页)。",
3237
+ navigate: "bcdp_navigate: 打开URL或切tab(同任务复用当前tab)。bcdp_wait op=url: 等跳转(登录/分页)。",
3238
3238
  observe: "bcdp_snapshot: 整页语义树(带[ref]/loc供点击); bcdp_page_info: url/标题/视口/滚动/对话框/人机验证; bcdp_read_element: 读单元素文本/HTML/值/属性/可见性/计数; bcdp_screenshot(+selector): 整页或元素截图。",
3239
3239
  input: "bcdp_click(selector/坐标, double双击); bcdp_fill(填框); bcdp_key(press组合键 或 text连续键入); bcdp_check(勾选/取消); bcdp_select(下拉); bcdp_upload(文件上传); bcdp_dialog(接受/取消JS对话框)。",
3240
3240
  "keyboard-mouse": "bcdp_key: 键盘(press/text); bcdp_hover: 悬停; bcdp_drag: 拖拽(元素或坐标); bcdp_scroll: 滚轮/滚到元素; bcdp_click: 点击/双击。",
3241
3241
  form: "bcdp_fill 填输入框; bcdp_select 下拉; bcdp_check checkbox/radio; bcdp_upload 文件; bcdp_key 回车/Tab导航; bcdp_dialog 处理提交弹窗。",
3242
- wait: "bcdp_wait(固定毫秒); bcdp_wait_for_selector(等元素出现/消失); bcdp_wait_for_url(等跳转); bcdp_wait_for_response(等网络响应并可读body)。",
3243
- network: "bcdp_http: 发HTTP请求(默认浏览器上下文 fetch.browser, mode=server走Node fetch.server); bcdp_wait_for_response: 等并读接口响应。",
3242
+ wait: "bcdp_wait 一个工具八个 op:duration(固定毫秒); selector(等元素出现/消失, 可带 state); url(等跳转); response(等网络响应, body=text|json 可读体); load(等加载状态); function(页内表达式变真); request(等请求); event(等下载)。",
3243
+ network: "bcdp_http: 发HTTP请求(默认浏览器上下文 fetch.browser, mode=server走Node fetch.server); bcdp_wait op=response: 等并读接口响应。",
3244
3244
  download: "bcdp_download: 等下载事件并落到指定路径(triggerSelector/triggerScript + 可选 savePath)。",
3245
3245
  captcha: "bcdp_captcha: 检测页面人机验证(CAPTCHA)并返回{detected,kind}; 检测到请让用户去 ego 浏览器完成; bcdp_page_info 也附带 humanCheck。",
3246
3246
  login: "bcdp_auth_flush: 把登录cookie落盘到ego profile; 观察窗登录引导条+『已登录,保存』按钮触发同一动作。bcdp_login_import: 从系统浏览器(Chrome/Edge/Brave)按域名导入登录cookie(source/domains/dryRun; 先dryRun看可导入项; ego浏览器须已在运行)。",
3247
- script: "bcdp_cli / bcdp_script: 原样运行任意内置运行时 heredoc 脚本(page/browser/taskSpaces/site/fetch/cdp预载)。bcdp_script额外返回 duration/timedOut。",
3247
+ script: "bcdp_script: 原样运行任意内置运行时 heredoc 脚本(page/browser/taskSpaces/site/fetch/cdp预载)。默认加 preamble(选区+激活真实 tab)并额外返回 duration/timedOut; verbatim:true 则完全原样、无 preamble(原 bcdp_cli 行为, 需自行 taskSpaces.useOrCreate)。",
3248
3248
  doctor: "bcdp_doctor: 体检环境(浏览器候选、vendored runtime、状态目录、CDP端口、任务空间、引擎与降级清单);首行附工具注入面快照。",
3249
- injection: "工具分级注入(不是工具,是出现时机):41 个 bcdp_* 分八批——core(status/doctor/help/space_open/space_close/space/navigate/snapshot,常驻不可封印)/ act(点击填写键鼠拖拽+tab 标签管理)/ observe(截图页面信息读取js)/ wait(等待类+wait_page 页面级等待)/ 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(两者也算浏览器活动,会把面铺开),或让用户在设置页「工具封印」里打开对应档位的开关;别猜测不存在的工具名。",
3249
+ injection: "工具分级注入(不是工具,是出现时机):34 个 bcdp_* 分八批——core(status/doctor/help/space/navigate/snapshot,常驻不可封印)/ act(点击填写键鼠拖拽+tab 标签管理)/ observe(截图页面信息读取js)/ wait(bcdp_wait 全 op)/ power(裸CDP/HTTP/上传/下载/对话框)/ session(验证码/登录落盘/登录导入)/ escape(script 逃生舱)/ judge(bcdp_jev_*)。设置旋钮(全 volatile):toolInjection = lazy(默认,常驻 core + escape,首次 bcdp_* 调用后铺开其余)/ always(挂载即全量,历史行为);toolBrowse(act+observe+wait,内部按 act→observe→wait 三波放行)/ toolExtended(power+session)/ toolEscape(script)/ toolJudge 四把开关——开 = 开放注册,关 = 该批从工具列表移除(core 级不给开关,封了就没解锁入口);judge 级即使开了仍需配 JEV/Laya Key。**escape 批不吃活动闸**:script 是唯一的「一次调用干完任意多步任务」的入口,必须始终可达,不排在首次活动之后。封印 = 从工具列表里反注册,不是执行期报错;lazy 下闲置回收会把扩展面收回。**若某个 bcdp_* 工具不在你的工具列表里**:它被分级封印了——先跑 bcdp_status 或 bcdp_doctor(两者也算浏览器活动,会把面铺开),或让用户在设置页「工具封印」里打开对应档位的开关;别猜测不存在的工具名。",
3250
3250
  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)",
3251
3251
  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 未开放注册)。"
3252
3252
  };
@@ -3555,8 +3555,6 @@ const CORE = [
3555
3555
  "bcdp_status",
3556
3556
  "bcdp_doctor",
3557
3557
  "bcdp_help",
3558
- "bcdp_space_open",
3559
- "bcdp_space_close",
3560
3558
  "bcdp_space",
3561
3559
  "bcdp_navigate",
3562
3560
  "bcdp_snapshot"
@@ -3578,13 +3576,7 @@ const OBSERVE = [
3578
3576
  "bcdp_read_element",
3579
3577
  "bcdp_js"
3580
3578
  ];
3581
- const WAIT = [
3582
- "bcdp_wait",
3583
- "bcdp_wait_for_selector",
3584
- "bcdp_wait_for_url",
3585
- "bcdp_wait_for_response",
3586
- "bcdp_wait_page"
3587
- ];
3579
+ const WAIT = ["bcdp_wait"];
3588
3580
  const POWER = [
3589
3581
  "bcdp_cdp",
3590
3582
  "bcdp_http",
@@ -3597,7 +3589,7 @@ const SESSION = [
3597
3589
  "bcdp_auth_flush",
3598
3590
  "bcdp_login_import"
3599
3591
  ];
3600
- const ESCAPE = ["bcdp_cli", "bcdp_script"];
3592
+ const ESCAPE = ["bcdp_script"];
3601
3593
  const JUDGE = [
3602
3594
  "bcdp_jev_status",
3603
3595
  "bcdp_jev_ask",
@@ -7167,20 +7159,52 @@ function createActiveSpaceTracker(defaultSpace = DEFAULT_SPACE) {
7167
7159
  }
7168
7160
  const GLOBAL_SESSION_KEY = "__global__";
7169
7161
  /**
7170
- * C — resolve the fallback slot name for a session. `:auto` only expands to a
7171
- * per-session `dsh-agent-<sid8>` in isolated-sandbox mode; persistent mode
7172
- * (and the no-session global slot) collapse to the single named `default`,
7173
- * protecting login reuse. Any other configured value passes through verbatim.
7162
+ * C — resolve the fallback slot name for a session.
7163
+ *
7164
+ * v1.6.0 — SESSION ISOLATION IS THE DEFAULT. `defaultSpace` ships as `:auto`,
7165
+ * so a call that omits `space` lands in a per-session task space
7166
+ * `dsh-agent-<sid8>` instead of the shared `default` slot. The sentinel is
7167
+ * honoured regardless of `isolateSpaces`, because space NAMING and PROFILE
7168
+ * persistence are two different axes: `isolateSpaces` only decides whether the
7169
+ * browser profile lives on disk or in an in-memory sandbox.
7170
+ *
7171
+ * A caller that deliberately wants the shared slot sets `defaultSpace` to a
7172
+ * named value (e.g. `default`) or passes `space: 'default'` on a call — the
7173
+ * tracker then pins that session to it. Calls carrying NO session id always
7174
+ * fall back to the named shared slot so pre-existing behaviour keeps working.
7175
+ * Any other configured value passes through verbatim.
7174
7176
  * @internal exported for tests
7175
7177
  */
7176
7178
  function deriveSlotDefaultName(rc, sessionKey) {
7177
7179
  const name$1 = rc.defaultSpace;
7178
7180
  if (name$1 === AUTO_SPACE_SENTINEL) {
7179
- if (!rc.isolateSpaces) return DEFAULT_SPACE;
7180
- return sessionKey === GLOBAL_SESSION_KEY ? DEFAULT_SPACE : AUTO_SPACE_PREFIX + sessionKey.slice(0, 8);
7181
+ if (sessionKey === GLOBAL_SESSION_KEY) return DEFAULT_SPACE;
7182
+ return AUTO_SPACE_PREFIX + sessionSpaceToken(sessionKey);
7181
7183
  }
7182
7184
  return name$1;
7183
7185
  }
7186
+ /**
7187
+ * A stable, space-name-safe 8-char token for a DSH session id.
7188
+ *
7189
+ * DSH session ids look like `session-52adc205-3251-…`, so the old
7190
+ * `slice(0, 8)` yielded the literal `session-` for EVERY session — silently
7191
+ * collapsing all sessions into one space, i.e. exactly the failure this
7192
+ * feature exists to prevent. The known prefix is stripped and
7193
+ * hyphens kept, other non-alphanumerics dropped, then sliced to 8; a short id
7194
+ * is used as-is (still unique), and only a degenerate/empty id falls back to a
7195
+ * deterministic FNV-1a hash so the name is never empty.
7196
+ * @internal exported for tests
7197
+ */
7198
+ function sessionSpaceToken(sessionId) {
7199
+ const bare = sessionId.replace(/^session-/, "").replace(/[^A-Za-z0-9-]/g, "");
7200
+ if (bare.length > 0) return bare.slice(0, 8);
7201
+ let h = 2166136261;
7202
+ for (let i = 0; i < sessionId.length; i += 1) {
7203
+ h ^= sessionId.charCodeAt(i);
7204
+ h = Math.imul(h, 16777619) >>> 0;
7205
+ }
7206
+ return h.toString(16).padStart(8, "0").slice(0, 8);
7207
+ }
7184
7208
  function createSessionSpaceTracker(defaultNameFor = () => DEFAULT_SPACE) {
7185
7209
  const slots = /* @__PURE__ */ new Map();
7186
7210
  let sessionKey = GLOBAL_SESSION_KEY;
@@ -7558,7 +7582,7 @@ async function runWithTabRevive(ctx, cfg, exec, buildScript, graceOverrideMs) {
7558
7582
  /**
7559
7583
  * Find the last line carrying the sentinel and JSON-parse its payload.
7560
7584
  *
7561
- * Fallback: `bcdp_script` / `bcdp_cli` run user-authored heredocs, and both
7585
+ * Fallback: `bcdp_script` (with verbatim:true) runs user-authored heredocs, which
7562
7586
  * tool descriptions tell the model to "end with console.log(JSON.stringify(...))"
7563
7587
  * �?without the sentinel prefix. A script written to that instruction used to
7564
7588
  * succeed and still be reported as a failure ("no @@DSH_RESULT@@ payload"), so
@@ -7777,7 +7801,7 @@ const useSpace = (name$1) => `const task = await taskSpaces.useOrCreate(${j(name
7777
7801
  */
7778
7802
  const ensureRealTab = () => "const __tabs = await browser.listTabs()\nconst __real = __tabs.find(t => !t.url.startsWith('about:') && !t.url.startsWith('chrome://')) ?? __tabs[0]\nif (__real) await browser.switchTab(__real.targetId)\n";
7779
7803
  /**
7780
- * G �?a raw heredoc (`bcdp_cli` / `bcdp_script`) that touches `page.*` without
7804
+ * G �?a raw heredoc (`bcdp_script` with verbatim:true) that touches `page.*` without
7781
7805
  * first selecting a task space dies with the runtime's "no active tab to attach
7782
7806
  * session". Structured bcdp_* tools never hit this because each wraps its body
7783
7807
  * in `useSpace(...)` + `ensureRealTab()`; a hand-written heredoc has no such
@@ -8525,9 +8549,11 @@ function registerActionTools(ctx, cfg, reg) {
8525
8549
  ...opts,
8526
8550
  afterExecute: (args, result) => {
8527
8551
  if (!result || result.ok === false) return;
8528
- if (opts.name === "bcdp_space_open") cfg.spaceTracker.opened(args, result);
8529
- else if (opts.name === "bcdp_space_close") cfg.spaceTracker.closed(args.name, result.done);
8530
- else if (args && args.space !== void 0 && args.space !== "") cfg.spaceTracker.selected(args.space);
8552
+ const a = args;
8553
+ const op = typeof a?.op === "string" ? a.op.trim() : "";
8554
+ if (opts.name === "bcdp_space" && op === "open") cfg.spaceTracker.opened(args, result);
8555
+ else if (opts.name === "bcdp_space" && op === "close") cfg.spaceTracker.closed(a.name, result.done);
8556
+ else if (a && a.space !== void 0 && a.space !== "") cfg.spaceTracker.selected(a.space);
8531
8557
  opts.afterExecute?.(args, result);
8532
8558
  }
8533
8559
  });
@@ -8535,50 +8561,22 @@ function registerActionTools(ctx, cfg, reg) {
8535
8561
  type: "string",
8536
8562
  description: "Task-space name or numeric id; defaults to the most recently opened or explicitly selected space."
8537
8563
  };
8538
- reg(t({
8539
- name: "bcdp_space_open",
8540
- get description() {
8541
- return cfg.isolateSpaces ? "Open (or reuse) an ego-lite task space in isolated sandbox mode." : "Open (or reuse) the ego-lite task space. In persistent profile mode (default), ALWAYS use or reuse the single 'default' space. Login credentials automatically persist on disk across restarts �?if a page requires login, prompt user to log in manually in the opened window. DO NOT create numbered spaces like #4, #5.";
8542
- },
8543
- parameters: { name: {
8544
- type: "string",
8545
- required: true,
8546
- get description() {
8547
- return cfg.isolateSpaces ? "Task-space name or numeric id." : "Task-space name. In persistent mode, ALWAYS specify 'default'. Reuse this single space for all browsing tasks.";
8548
- }
8549
- } },
8550
- buildScript: (args) => `${useSpace(str(args.name, cfg.activeSpace))}console.log('${SENTINEL}' + JSON.stringify({ ok: true, id: task.id ?? null, name: task.name ?? ${j(str(args.name, cfg.activeSpace))} }))\n`
8551
- }));
8552
- reg(t({
8553
- name: "bcdp_space_close",
8554
- get description() {
8555
- return cfg.isolateSpaces ? "Complete (close) an ego-lite task space in sandbox mode." : "Close an ego-lite task space. WARNING: In persistent profile mode, DO NOT call this tool when finishing tasks! Keep the space, tabs, and browser window alive so login sessions and streams remain intact. Conclude tasks by replying to the user directly without closing the space.";
8556
- },
8557
- parameters: {
8558
- name: {
8559
- type: "string",
8560
- required: true,
8561
- description: "Task-space name or numeric id to close."
8562
- },
8563
- keep: {
8564
- type: "boolean",
8565
- description: "Keep the live page open (default false: close it)."
8566
- }
8567
- },
8568
- buildScript: (args) => `const res = await taskSpaces.complete(${j(str(args.name, cfg.activeSpace))}, { keep: ${bool(args.keep, false)} })\nconsole.log('${SENTINEL}' + JSON.stringify({ ok: true, done: !!res.done, skipped: !!res.skipped, reason: res.skipped ? ${j("target space was not agent-owned")} : null }))\n`
8569
- }));
8570
8564
  reg(t({
8571
8565
  name: "bcdp_space",
8572
- description: "Inspect or transfer a task space: op=list|handoff|takeover. handoff yields control to the human (stop driving until they hand back); takeover resumes agent control.",
8566
+ description: "Task space: op=open (or reuse) | close | list | handoff | takeover. Omitting `space` targets THIS session's own space (dsh-agent-<sessionId8>), so concurrent sessions never share or hijack each other's browsing context — this is the default and needs no setup. To reuse ONE shared slot across sessions, pass `space: 'default'` (or op=open with name='default') deliberately; do NOT create numbered spaces like #4/#5. The browser profile (logins) persists on disk across restarts unless isolateSpaces is on; if a page needs login, prompt the user to log in manually. handoff yields control to the human (stop driving until they hand back); takeover resumes agent control.",
8573
8567
  parameters: {
8574
8568
  op: {
8575
8569
  type: "string",
8576
8570
  required: true,
8577
- description: "\"list\" | \"handoff\" | \"takeover\"."
8571
+ description: "\"open\" | \"close\" | \"list\" | \"handoff\" | \"takeover\"."
8578
8572
  },
8579
8573
  name: {
8580
8574
  type: "string",
8581
- description: "Task-space name or id (default: the configured space)."
8575
+ description: "op=open/close: task-space name. Omit to use this session's own space (dsh-agent-<sessionId8>); pass 'default' only when you deliberately want the ONE shared slot. op=handoff/takeover: default = this session's space."
8576
+ },
8577
+ keep: {
8578
+ type: "boolean",
8579
+ description: "op=close: keep the live page open (default false: close it)."
8582
8580
  },
8583
8581
  space: spaceParam
8584
8582
  },
@@ -8586,10 +8584,12 @@ function registerActionTools(ctx, cfg, reg) {
8586
8584
  const send = (expr) => `console.log('${SENTINEL}' + JSON.stringify(${expr}))\n`;
8587
8585
  const op = str(args.op, "").trim();
8588
8586
  const name$1 = str(args.name, str(args.space, cfg.activeSpace));
8589
- if (op === "list") return `const __sp = await taskSpaces.list()\n` + send(`{ ok: true, spaces: __sp.map(s => ({ id: s.id ?? null, name: s.name ?? null, ownership: s.ownership ?? null })) }`);
8587
+ if (op === "open") return `${useSpace(str(args.name, cfg.activeSpace))}` + send(`{ ok: true, op: 'open', id: task.id ?? null, name: task.name ?? ${j(str(args.name, cfg.activeSpace))} }`);
8588
+ if (op === "close") return `const res = await taskSpaces.complete(${j(name$1)}, { keep: ${bool(args.keep, false)} })\n` + send(`{ ok: true, op: 'close', done: !!res.done, skipped: !!res.skipped, reason: res.skipped ? ${j("target space was not agent-owned")} : null }`);
8589
+ if (op === "list") return `const __sp = await taskSpaces.list()\n` + send(`{ ok: true, op: 'list', spaces: __sp.map(s => ({ id: s.id ?? null, name: s.name ?? null, ownership: s.ownership ?? null })) }`);
8590
8590
  if (op === "handoff") return `${useSpace(name$1)}const __h = await taskSpaces.handOff(${j(name$1)})\n` + send(`{ ok: true, op: 'handoff', name: ${j(name$1)}, done: !!__h.done, skipped: __h.skipped ?? null, hint: 'user now has control; ask them to confirm before calling op=takeover' }`);
8591
8591
  if (op === "takeover") return `await taskSpaces.takeOver(${j(name$1)})\nconst __info = await page.info()\n` + send(`{ ok: true, op: 'takeover', name: ${j(name$1)}, page: __info }`);
8592
- return send(`{ ok: false, reason: ${j("bcdp_space: op must be one of list|handoff|takeover")} }`);
8592
+ return send(`{ ok: false, reason: ${j("bcdp_space: op must be one of open|close|list|handoff|takeover")} }`);
8593
8593
  }
8594
8594
  }));
8595
8595
  reg(t({
@@ -8834,131 +8834,88 @@ function registerActionTools(ctx, cfg, reg) {
8834
8834
  }));
8835
8835
  reg(t({
8836
8836
  name: "bcdp_wait",
8837
- description: "Pause for a fixed number of milliseconds (e.g. for animations or partial loads). For load waits prefer bcdp_navigate's wait option.",
8838
- parameters: { ms: {
8839
- type: "number",
8840
- required: true,
8841
- description: "Milliseconds to wait."
8842
- } },
8843
- buildScript: (args) => `await page.waitForTimeout(${Math.max(0, num(args.ms, 1e3))})\nconsole.log('${SENTINEL}' + JSON.stringify({ ok: true, waitedMs: ${Math.max(0, num(args.ms, 1e3))} }))\n`
8844
- }));
8845
- reg(t({
8846
- name: "bcdp_wait_for_selector",
8847
- description: "Wait until a CSS selector appears (state=visible, default) or disappears (state=hidden). Use instead of a fixed wait for async pages.",
8837
+ description: "Wait. op=duration (fixed ms) | selector (element appears/disappears) | url (navigation) | response (network reply) | load (page load state) | function (in-page expression becomes truthy) | request (network request) | event (a download). selector takes `selector` + optional `state` (visible|attached|hidden|detached); url takes `pattern`; response takes `url` + optional `body` (none|text|json); load takes `state` (load|domcontentloaded|networkidle); function takes `expression`; request takes `url`. `timeout` in ms (default 10000; page-level ops load/function/request/event default 30000). Every op except duration accepts `space`.",
8848
8838
  parameters: {
8849
- selector: {
8839
+ op: {
8850
8840
  type: "string",
8851
8841
  required: true,
8852
- description: "CSS selector to wait for, e.g. '.results' or '[data-id=done]'."
8842
+ description: "\"duration\" | \"selector\" | \"url\" | \"response\" | \"load\" | \"function\" | \"request\" | \"event\"."
8853
8843
  },
8854
- state: {
8855
- type: "string",
8856
- description: "'visible' (default) | 'attached' | 'hidden' | 'detached'."
8857
- },
8858
- timeout: {
8844
+ ms: {
8859
8845
  type: "number",
8860
- description: "Wait in ms (default 10000)."
8846
+ description: "op=duration: milliseconds to wait (default 1000)."
8861
8847
  },
8862
- space: spaceParam
8863
- },
8864
- buildScript: (args) => {
8865
- const sel = str(args.selector, "").trim();
8866
- if (sel === "") return `console.log('${SENTINEL}' + JSON.stringify({ ok: false, waited: false, reason: 'bcdp_wait_for_selector: selector is required' }))\n`;
8867
- return `${useSpace(str(args.space, cfg.activeSpace))}${ensureRealTab()}await page.waitForSelector(${j(sel)}, { state: ${j(str(args.state, "visible"))}, timeout: ${num(args.timeout, 1e4)} })\nconsole.log('${SENTINEL}' + JSON.stringify({ ok: true, waited: true, selector: ${j(sel)}, state: ${j(str(args.state, "visible"))} }))\n`;
8868
- }
8869
- }));
8870
- reg(t({
8871
- name: "bcdp_wait_for_url",
8872
- description: "Wait until the page navigates to a URL matching a substring / glob / regex. Use to catch login redirects or pagination.",
8873
- parameters: {
8874
- pattern: {
8848
+ selector: {
8875
8849
  type: "string",
8876
- required: true,
8877
- description: "URL/glob to match (e.g. '/login?done', 'https://*/post/*', or a /regex/)."
8850
+ description: "op=selector: CSS selector to wait for, e.g. '.results' or '[data-id=done]'."
8878
8851
  },
8879
- timeout: {
8880
- type: "number",
8881
- description: "How long to wait in ms (default 10000)."
8882
- },
8883
- space: spaceParam
8884
- },
8885
- buildScript: (args) => {
8886
- const p = str(args.pattern, "").trim();
8887
- if (p === "") return `console.log('${SENTINEL}' + JSON.stringify({ ok: false, reached: false, reason: 'bcdp_wait_for_url: pattern is required' }))\n`;
8888
- return `${useSpace(str(args.space, cfg.activeSpace))}${ensureRealTab()}const __ok = await page.waitForURL(${j(p)}, { timeout: ${num(args.timeout, 1e4)} }).catch(() => false)\nconst __u = await page.url()\nconsole.log('${SENTINEL}' + JSON.stringify({ ok: !!__ok, reached: !!__ok, url: __u }))\n`;
8889
- }
8890
- }));
8891
- reg(t({
8892
- name: "bcdp_wait_for_response",
8893
- description: "Wait for a network response matching a URL/glob/regex and return it; optionally return the body (text or JSON).",
8894
- parameters: {
8895
- url: {
8852
+ state: {
8896
8853
  type: "string",
8897
- required: true,
8898
- description: "URL/glob/regex, e.g. '/api/search' or 'https://*.com/data'."
8854
+ description: "op=selector: \"visible\" (default) | \"attached\" | \"hidden\" | \"detached\". op=load: \"load\" (default) | \"domcontentloaded\" | \"networkidle\"."
8899
8855
  },
8900
- timeout: {
8901
- type: "number",
8902
- description: "Wait in ms (default 10000)."
8903
- },
8904
- body: {
8856
+ pattern: {
8905
8857
  type: "string",
8906
- description: "'none' (default) | 'text' | 'json'."
8858
+ description: "op=url: URL/glob to match (e.g. '/login?done', 'https://*/post/*', or a /regex/)."
8907
8859
  },
8908
- space: spaceParam
8909
- },
8910
- buildScript: (args) => {
8911
- const u = str(args.url, "").trim();
8912
- const mode = str(args.body, "none");
8913
- const wantBody = mode === "text" || mode === "json";
8914
- return `${useSpace(str(args.space, cfg.activeSpace))}${ensureRealTab()}const __res = await page.waitForResponse(${j(u)}, { timeout: ${num(args.timeout, 1e4)} })\n${wantBody ? `const __body = ${mode === "json" ? "await __res.json().catch(()=>null)" : "await __res.text().catch(()=>null)"}\n` : ""}console.log('${SENTINEL}' + JSON.stringify({ ok: true, url: __res.url(), status: __res.status()${wantBody ? ", body: __body" : ""} }))\n`;
8915
- }
8916
- }));
8917
- reg(t({
8918
- name: "bcdp_wait_page",
8919
- description: "Page-level wait, op=load|function|request|event. load: a load state (state=load|domcontentloaded|networkidle). function: in-page JS `expression` until truthy (returns the value). request: a request whose URL matches `url` (substring/glob/regex). event: a download. load/function time out softly (ok:false); request/event surface their timeout as ok:false.",
8920
- parameters: {
8921
- op: {
8860
+ url: {
8922
8861
  type: "string",
8923
- required: true,
8924
- description: "\"load\" | \"function\" | \"request\" | \"event\"."
8862
+ description: "op=response: URL/glob/regex, e.g. '/api/search'. op=request: URL substring / glob / regex."
8925
8863
  },
8926
- state: {
8864
+ body: {
8927
8865
  type: "string",
8928
- description: "op=load: \"load\" (default) | \"domcontentloaded\" | \"networkidle\"."
8866
+ description: "op=response: 'none' (default) | 'text' | 'json'."
8929
8867
  },
8930
8868
  expression: {
8931
8869
  type: "string",
8932
8870
  description: "op=function: in-page JS expression evaluated until truthy."
8933
8871
  },
8934
- url: {
8935
- type: "string",
8936
- description: "op=request: URL substring / glob / regex."
8937
- },
8938
8872
  timeout: {
8939
8873
  type: "number",
8940
- description: "Wait in ms (default 30000)."
8874
+ description: "Wait in ms (default 10000; page-level ops default 30000)."
8941
8875
  },
8942
8876
  space: spaceParam
8943
8877
  },
8944
8878
  buildScript: (args) => {
8945
8879
  const send = (expr) => `console.log('${SENTINEL}' + JSON.stringify(${expr}))\n`;
8946
8880
  const op = str(args.op, "").trim();
8947
- const to = num(args.timeout, 0) > 0 ? num(args.timeout, 0) : 3e4;
8881
+ const asked = num(args.timeout, 0);
8882
+ const to = asked > 0 ? asked : 1e4;
8883
+ const pageTo = asked > 0 ? asked : 3e4;
8948
8884
  const head = `${useSpace(str(args.space, cfg.activeSpace))}${ensureRealTab()}`;
8949
- if (op === "load") return head + `const __ok = await page.waitForLoadState(${j(str(args.state, "load"))}, { timeout: ${to} })\n` + send(`{ ok: !!__ok, op: 'load', state: ${j(str(args.state, "load"))}, reason: __ok ? null : 'timed out: load state not reached within ${to}ms' }`);
8885
+ if (op === "duration") {
8886
+ const ms = Math.max(0, num(args.ms, 1e3));
8887
+ return `await page.waitForTimeout(${ms})\n` + send(`{ ok: true, op: 'duration', waitedMs: ${ms} }`);
8888
+ }
8889
+ if (op === "selector") {
8890
+ const sel = str(args.selector, "").trim();
8891
+ if (sel === "") return send(`{ ok: false, op: 'selector', waited: false, reason: 'bcdp_wait: selector is required for op=selector' }`);
8892
+ return head + `await page.waitForSelector(${j(sel)}, { state: ${j(str(args.state, "visible"))}, timeout: ${to} })\n` + send(`{ ok: true, op: 'selector', waited: true, selector: ${j(sel)}, state: ${j(str(args.state, "visible"))} }`);
8893
+ }
8894
+ if (op === "url") {
8895
+ const p = str(args.pattern, "").trim();
8896
+ if (p === "") return send(`{ ok: false, op: 'url', reached: false, reason: 'bcdp_wait: pattern is required for op=url' }`);
8897
+ return head + `const __ok = await page.waitForURL(${j(p)}, { timeout: ${to} }).catch(() => false)\nconst __u = await page.url()\n` + send(`{ ok: !!__ok, op: 'url', reached: !!__ok, url: __u }`);
8898
+ }
8899
+ if (op === "response") {
8900
+ const u = str(args.url, "").trim();
8901
+ if (u === "") return send(`{ ok: false, op: 'response', reason: 'bcdp_wait: url is required for op=response' }`);
8902
+ const mode = str(args.body, "none");
8903
+ const wantBody = mode === "text" || mode === "json";
8904
+ return head + `const __res = await page.waitForResponse(${j(u)}, { timeout: ${to} })\n${wantBody ? `const __body = ${mode === "json" ? "await __res.json().catch(()=>null)" : "await __res.text().catch(()=>null)"}\n` : ""}` + send(`{ ok: true, op: 'response', url: __res.url(), status: __res.status()${wantBody ? ", body: __body" : ""} }`);
8905
+ }
8906
+ if (op === "load") return head + `const __ok = await page.waitForLoadState(${j(str(args.state, "load"))}, { timeout: ${pageTo} })\n` + send(`{ ok: !!__ok, op: 'load', state: ${j(str(args.state, "load"))}, reason: __ok ? null : 'timed out: load state not reached within ${pageTo}ms' }`);
8950
8907
  if (op === "function") {
8951
8908
  const expr = str(args.expression, "").trim();
8952
- if (expr === "") return send(`{ ok: false, op: 'function', reason: 'bcdp_wait_page: expression is required for op=function' }`);
8953
- return head + `const __v = await page.waitForFunction(${j(safeEvalWrap(expr, true))}, undefined, { timeout: ${to} })\n` + send(`{ ok: !!__v, op: 'function', value: __v === false ? null : __v, reason: __v === false ? 'timed out: expression never became truthy within ${to}ms' : null }`);
8909
+ if (expr === "") return send(`{ ok: false, op: 'function', reason: 'bcdp_wait: expression is required for op=function' }`);
8910
+ return head + `const __v = await page.waitForFunction(${j(safeEvalWrap(expr, true))}, undefined, { timeout: ${pageTo} })\n` + send(`{ ok: !!__v, op: 'function', value: __v === false ? null : __v, reason: __v === false ? 'timed out: expression never became truthy within ${pageTo}ms' : null }`);
8954
8911
  }
8955
8912
  if (op === "request") {
8956
8913
  const u = str(args.url, "").trim();
8957
- if (u === "") return send(`{ ok: false, op: 'request', reason: 'bcdp_wait_page: url is required for op=request' }`);
8958
- return head + `try { const __req = await page.waitForRequest(${j(u)}, { timeout: ${to} })\n` + send(`{ ok: true, op: 'request', url: __req.url(), method: __req.method() }`) + `} catch (e) { ${send(`{ ok: false, op: 'request', reason: String(e && e.message || e) }`)} }\n`;
8914
+ if (u === "") return send(`{ ok: false, op: 'request', reason: 'bcdp_wait: url is required for op=request' }`);
8915
+ return head + `try { const __req = await page.waitForRequest(${j(u)}, { timeout: ${pageTo} })\n` + send(`{ ok: true, op: 'request', url: __req.url(), method: __req.method() }`) + `} catch (e) { ${send(`{ ok: false, op: 'request', reason: String(e && e.message || e) }`)} }\n`;
8959
8916
  }
8960
- if (op === "event") return head + `try { const __ev = await page.waitForEvent('download', { timeout: ${to} })\nconst __p = await __ev.path().catch(() => null)\n` + send(`{ ok: true, op: 'event', event: 'download', suggestedFilename: __ev.suggestedFilename(), url: __ev.url(), path: __p }`) + `} catch (e) { ${send(`{ ok: false, op: 'event', reason: String(e && e.message || e) }`)} }\n`;
8961
- return send(`{ ok: false, reason: ${j("bcdp_wait_page: op must be one of load|function|request|event")} }`);
8917
+ if (op === "event") return head + `try { const __ev = await page.waitForEvent('download', { timeout: ${pageTo} })\nconst __p = await __ev.path().catch(() => null)\n` + send(`{ ok: true, op: 'event', event: 'download', suggestedFilename: __ev.suggestedFilename(), url: __ev.url(), path: __p }`) + `} catch (e) { ${send(`{ ok: false, op: 'event', reason: String(e && e.message || e) }`)} }\n`;
8918
+ return send(`{ ok: false, reason: ${j("bcdp_wait: op must be one of duration|selector|url|response|load|function|request|event")} }`);
8962
8919
  }
8963
8920
  }));
8964
8921
  reg(t({
@@ -9275,61 +9232,6 @@ function registerActionTools(ctx, cfg, reg) {
9275
9232
  return `${mode === "server" ? "" : `${useSpace(str(args.space, cfg.activeSpace))}${ensureRealTab()}`}${SAFE_FN}const __r = await fetch.${mode === "server" ? "server" : "browser"}(${j(str(args.url, ""))}, ${j(opts)})\nconst __status = typeof __r.status !== "undefined" ? __r.status : 200\nlet __body = null\ntry { __body = typeof __r.text === "function" ? await __r.text() : (typeof __r === "string" ? __r : JSON.stringify(safe(__r))) } catch { __body = null }\nconsole.log('${SENTINEL}' + JSON.stringify({ ok: true, mode: ${j(mode)}, status: __status, body: __body, url: ${j(str(args.url, ""))} }))\n`;
9276
9233
  }
9277
9234
  }));
9278
- reg((() => {
9279
- return defineTool({
9280
- name: "bcdp_cli",
9281
- description: "Escape hatch: run an arbitrary `ego-browser nodejs` heredoc script VERBATIM (facades page/browser/taskSpaces/site/fetch and the raw cdp() are preloaded; no preamble is added, so select the task space yourself before touching page.*). Use when the structured bcdp_* tools do not cover the task. Returns the raw output plus the parsed console.log payload when present. These scripts expose the vendored SDK (`taskSpaces`, `page.locator()`, global `cdp()`, `fetch.browser|server`) �?NOT the official docs' `taskSpace()` / `page.click()`.",
9282
- parameters: { script: {
9283
- type: "string",
9284
- required: true,
9285
- description: "Full JS script body for the heredoc; ego-browser helpers are preloaded. Runs verbatim �?call `await taskSpaces.useOrCreate(name)` first if your script uses page.*. End with console.log(JSON.stringify(payload)) to get it back as `result`."
9286
- } },
9287
- output: {
9288
- schema: {
9289
- type: "object",
9290
- additionalProperties: false,
9291
- properties: {
9292
- ok: {
9293
- type: "boolean",
9294
- required: true
9295
- },
9296
- stdout: {
9297
- type: "string",
9298
- required: true
9299
- },
9300
- stderr: { type: "string" },
9301
- output: {
9302
- type: "string",
9303
- 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."
9304
- },
9305
- result: { type: "json" }
9306
- }
9307
- },
9308
- render: renderText
9309
- },
9310
- timeoutMs: TOOL_TIMEOUT_MS,
9311
- execute: async (args, exec) => {
9312
- cfg.spaceTracker.setCurrentSession(callingSessionId(exec));
9313
- markEgoToolCall(callingSessionId(exec));
9314
- const result = await runWithStaleSpaceRetry(ctx, cfg, exec, () => str(args.script, ""));
9315
- if (!result.ok) throw new Error(attachSessionHint(result.error));
9316
- const parsed = parseSentinel(mergeCliOutput(result));
9317
- return {
9318
- ok: true,
9319
- stdout: result.stdout,
9320
- stderr: result.stderr,
9321
- output: mergeCliOutput(result),
9322
- result: parsed ?? null
9323
- };
9324
- },
9325
- presentCall: () => ({
9326
- card: "generic",
9327
- title: "bcdp_cli",
9328
- kind: "other",
9329
- rawInput: null
9330
- })
9331
- });
9332
- })());
9333
9235
  }
9334
9236
  /** Register bcdp_help / bcdp_doctor / bcdp_script. */
9335
9237
  function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
@@ -9565,7 +9467,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
9565
9467
  reg((() => {
9566
9468
  return defineTool({
9567
9469
  name: "bcdp_script",
9568
- description: "Run an arbitrary `ego-browser nodejs` heredoc script in ONE invocation (page/…locator/browser/taskSpaces/site/fetch/cdp preloaded), and return structured {ok, stdout, stderr, result, durationMs, timedOut}. Use for a full multi-step browser task as a single script. The task space is selected and a real (non-blank) tab activated for you before your script runs, so page.* works directly. Differs from bcdp_cli, which runs the body verbatim with no preamble. These scripts expose the vendored SDK (`taskSpaces`, `page.locator()`, global `cdp()`, `fetch.browser|server`) �?NOT the official docs' `taskSpace()` / `page.click()`.",
9470
+ description: "Run an arbitrary `ego-browser nodejs` heredoc script in ONE invocation (page/…locator/browser/taskSpaces/site/fetch/cdp preloaded), and return structured {ok, stdout, stderr, result, durationMs, timedOut}. Use for a full multi-step browser task as a single script. The task space is selected and a real (non-blank) tab activated for you before your script runs, so page.* works directly. Set verbatim:true to run the body verbatim with no preamble (the retired bcdp_cli behaviour). These scripts expose the vendored SDK (`taskSpaces`, `page.locator()`, global `cdp()`, `fetch.browser|server`) �?NOT the official docs' `taskSpace()` / `page.click()`.",
9569
9471
  parameters: {
9570
9472
  script: {
9571
9473
  type: "string",
@@ -9575,6 +9477,10 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
9575
9477
  timeoutMs: {
9576
9478
  type: "integer",
9577
9479
  description: "Per-run timeout in ms (default plugin grace)."
9480
+ },
9481
+ verbatim: {
9482
+ type: "boolean",
9483
+ description: "Run the body verbatim with NO preamble (no task-space selection, no real-tab activation) — the retired bcdp_cli behaviour. Default false prepends the preamble so page.* works directly. In verbatim mode select the space yourself (`await taskSpaces.useOrCreate(name)`) before touching page.*."
9578
9484
  }
9579
9485
  },
9580
9486
  output: {
@@ -9609,7 +9515,9 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
9609
9515
  markEgoToolCall(callingSessionId(exec));
9610
9516
  const timeoutMs = typeof args.timeoutMs === "number" && Number.isFinite(args.timeoutMs) && args.timeoutMs > 0 ? args.timeoutMs : void 0;
9611
9517
  const start = Date.now();
9518
+ const verbatimMode = bool(args.verbatim, false);
9612
9519
  const preamble = (body) => {
9520
+ if (verbatimMode) return body;
9613
9521
  if (/taskSpaces\s*\.\s*useOrCreate\s*\(/.test(body)) return body;
9614
9522
  return `${useSpace(cfg.activeSpace)}${ensureRealTab()}${body}`;
9615
9523
  };
@@ -10251,4 +10159,4 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
10251
10159
  }
10252
10160
 
10253
10161
  //#endregion
10254
- export { ATTACH_SESSION_HINT, Config, GLOBAL_SESSION_KEY, STATUS_FACADE_SCRIPT, STATUS_FACADE_SENTINEL, TAB_STUCK_RE, apply, attachSessionHint, buildEgoToolArgv, cdpAttachError, createActiveSpaceTracker, createSessionSpaceTracker, decideCdpAttach, deriveSlotDefaultName, findChromeBinary, findUpstreamPluginInstall, inject, isTabStuckFailure, name, parseSentinel, parseStatusFacades, resolveEgoEnv, runWithStaleSpaceRetry, runWithTabRevive, shouldReapBrowser };
10162
+ export { ATTACH_SESSION_HINT, Config, GLOBAL_SESSION_KEY, STATUS_FACADE_SCRIPT, STATUS_FACADE_SENTINEL, TAB_STUCK_RE, apply, attachSessionHint, buildEgoToolArgv, cdpAttachError, createActiveSpaceTracker, createSessionSpaceTracker, decideCdpAttach, deriveSlotDefaultName, findChromeBinary, findUpstreamPluginInstall, inject, isTabStuckFailure, name, parseSentinel, parseStatusFacades, resolveEgoEnv, runWithStaleSpaceRetry, runWithTabRevive, sessionSpaceToken, shouldReapBrowser };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-browser-cdp",
3
- "version": "1.4.1",
3
+ "version": "1.6.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",