dsh-browser-cdp 1.3.1 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -221,7 +221,9 @@ dshx list # 应显示:[on] dsh-
221
221
 
222
222
  ## 工具注入分级(懒注册 / 分级 / 锁定)
223
223
 
224
- 38 个工具全量注册时,**每个会话每一轮**都要为它们的 schema 付费(AST 实测 `description` + `parameters` ≈ 18.8K 字符 ≈ 5.4K token),而不碰浏览器的会话一个也用不上。插件因此把「谁能出现在模型面前」收成一处策略(`src/toolTiers.ts`),分**八批**注入:
224
+ 38 个工具全量注册时,**每个会话每一轮**都要为它们的 schema 付费(AST 实测 `description` + `parameters` ≈ 19.3K 字符 ≈ 5.5K token),而不碰浏览器的会话一个也用不上。插件因此把「谁能出现在模型面前」收成一处策略(`src/toolTiers.ts`),分**八批**注入。
225
+
226
+ > **8 批 ≠ 8 个开关**。批次是*注入时机*,开关是*用户面*(§9.3「开关与批次解耦」)。当前 4 个开关管 8 批:`toolBrowse` 管 act+observe+wait 三批并按波次放行,`toolExtended` 管 power+session,`toolEscape`、`toolJudge` 各管一批。所以「`toolBrowse` = 16 个」指的是**并集上限**,实际第一波只放 8 个。
225
227
 
226
228
  | 批次 | 成员 | schema | 何时出现 |
227
229
  |---|---|---:|---|
@@ -231,8 +233,9 @@ dshx list # 应显示:[on] dsh-
231
233
  | **wait** 等待(4) | wait / wait_for_selector / wait_for_url / wait_for_response | 1,695 | 第三次活动 |
232
234
  | **power** 重量级(5) | raw CDP / http / upload / download / dialog | 2,947 | 首次活动(同 `toolExtended`) |
233
235
  | **session** 登录态(3) | captcha / auth_flush / login_import | 1,689 | 首次活动(同 `toolExtended`) |
234
- | **escape** 逃生舱(2) | cli / script | 1,224 | **冷启动即在**,不吃活动闸(见下) |
236
+ | **escape** 逃生舱(2) | cli / script | 1,677 | **冷启动即在**,不吃活动闸(见下) |
235
237
  | **judge** 评审链(5) | `bcdp_jev_*` | 3,183 | 除解锁外,**还要求配了 JEV 或 Laya Key** |
238
+ | **合计** | 38 | **19,287** | — |
236
239
 
237
240
  设置项在插件设置页**最上方**的「工具封印」分块(全部 volatile,翻完当场生效,不重启插件)——一个开关管一组批次,形状照 dsh-prime-memory 的「工具封印」:
238
241
 
@@ -247,7 +250,8 @@ dshx list # 应显示:[on] dsh-
247
250
  - **闲置自动收回**:`lazy` + `idleTimeoutMin > 0` 时,空闲回收把后台浏览器停掉的同一刻收回扩展面;下次活动重新铺开。`always` 模式不受影响。
248
251
  - `legacyEgoToolNames` 的 `ego_*` 别名跟随其 `bcdp_*` 本体的级别。
249
252
  - 当前注入面写在 `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)。
253
+ - 默认档下不碰浏览器的会话只有 **9** 个工具在场(core 7 + escape 2 = 4,287 字符 ≈ 1,225 token,−77.8%);要回到历史行为把 `toolInjection` 改成 `always`(38 件全在场需再配一个评审 Key)。
254
+ - **各档实测注入面**(AST 口径,1.3.1):默认 9 个 / 1,225 tok → 首次活动 25 个 / 3,642 tok → 第 2 波 29 个 / 4,117 tok → 第 3 波 33 个 / 4,601 tok → 全量 38 个 / 5,511 tok。工具**个数**在每一档都不高于 1.2.5(默认 7→9 是 escape 常驻的代价,首次活动 27→25 反而更小)。
251
255
  - 五个字段都带 schema `.default()`:volatile 字段的表单描述符直接拿 schema 默认值,不写默认会出现「面板显示 A、运行时用 B」。
252
256
 
253
257
  > 取舍提醒:窄工具(一个动作一个工具)是模型写对参数、少重试的护栏。把交互原子合并成脚本逃生舱会省上下文,但代价是模型要自己写 heredoc、出错率上升——本插件保持全部 38 个工具的签名不变,只改**出现时机**。
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.3.1",
5
+ "version": "1.3.2",
6
6
  "manifestVersion": "0.15",
7
7
  "facets": {
8
8
  "host": {
package/lib/index.js CHANGED
@@ -7434,14 +7434,57 @@ function parseSentinel(stdout) {
7434
7434
  return;
7435
7435
  }
7436
7436
  }
7437
- for (let i = lines.length - 1; i >= 0; i--) {
7438
- const text = lines[i].trim();
7439
- if (text.length < 2 || text[0] !== "{" || text[text.length - 1] !== "}") continue;
7437
+ return lastJsonObject(stdout);
7438
+ }
7439
+ /**
7440
+ * The last balanced `{...}` run in `text` that parses as a JSON object.
7441
+ *
7442
+ * Tracks double-quoted strings (JSON's only string syntax) so braces inside a
7443
+ * string value do not unbalance the scan. Invalid candidates are skipped, not
7444
+ * fatal: log noise before the payload is common.
7445
+ *
7446
+ * A candidate must begin its own line (leading whitespace is fine). That keeps
7447
+ * pretty-printed payloads working while refusing an object merely mentioned in
7448
+ * prose: `[warn] retrying {"attempt":2}` must not become the result, because a
7449
+ * silently wrong payload is worse than no payload at all.
7450
+ */
7451
+ function lastJsonObject(text) {
7452
+ let best;
7453
+ let depth = 0;
7454
+ let start = -1;
7455
+ let inString = false;
7456
+ let escaped = false;
7457
+ for (let i = 0; i < text.length; i++) {
7458
+ const c = text[i];
7459
+ if (inString) {
7460
+ if (escaped) escaped = false;
7461
+ else if (c === "\\") escaped = true;
7462
+ else if (c === "\"") inString = false;
7463
+ continue;
7464
+ }
7465
+ if (c === "\"") {
7466
+ inString = true;
7467
+ continue;
7468
+ }
7469
+ if (c === "{") {
7470
+ if (depth === 0) start = i;
7471
+ depth += 1;
7472
+ continue;
7473
+ }
7474
+ if (c !== "}") continue;
7475
+ if (depth === 0) continue;
7476
+ depth -= 1;
7477
+ if (depth !== 0 || start < 0) continue;
7478
+ let p = start - 1;
7479
+ while (p >= 0 && (text[p] === " " || text[p] === " " || text[p] === "\r")) p -= 1;
7480
+ const atLineStart = p < 0 || text[p] === "\n";
7440
7481
  try {
7441
- const parsed = JSON.parse(text);
7442
- if (parsed !== null && typeof parsed === "object" && !Array.isArray(parsed)) return parsed;
7482
+ const parsed = atLineStart ? JSON.parse(text.slice(start, i + 1)) : null;
7483
+ if (parsed !== null && typeof parsed === "object" && !Array.isArray(parsed)) best = parsed;
7443
7484
  } catch {}
7485
+ start = -1;
7444
7486
  }
7487
+ return best;
7445
7488
  }
7446
7489
  /** R2/R3 — sentinel + payload for the `bcdp_status` facade probe. @internal exported for tests */
7447
7490
  const STATUS_FACADE_SENTINEL = "__BCDP_STATUS__";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-browser-cdp",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
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",