dsh-browser-cdp 0.18.21 → 1.2.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
@@ -215,6 +215,33 @@ dshx list # 应显示:[on] dsh-
215
215
  | 元工具 | `bcdp_help` `bcdp_doctor` `bcdp_http` |
216
216
  | 评审(JEV/Laya,外接判定服务可选) | `bcdp_jev_status` `bcdp_jev_frame` `bcdp_jev_ask` `bcdp_jev_run` `bcdp_jev_attempt` |
217
217
 
218
+ ## 工具注入分级(懒注册 / 分级 / 锁定)
219
+
220
+ 38 个工具全量注册时,**每个会话每一轮**都要为它们的 schema 付费(实测 `description` + `parameters` ≈ 25.6K 字符 ≈ 5–7K token),而不碰浏览器的会话一个也用不上。插件因此把「谁能出现在模型面前」收成一处策略(`src/toolTiers.ts`),分四级注入:
221
+
222
+ | 级别 | 成员 | 何时出现 |
223
+ |---|---|---|
224
+ | **core** 常驻(6) | `bcdp_status` `bcdp_doctor` `bcdp_help` `bcdp_space_open` `bcdp_navigate` `bcdp_snapshot` | 永远在场,不可封印——否则 lazy 模式连解锁入口都没有 |
225
+ | **browse** 基础操作(14) | 点击/填写/键鼠/截图/读取/等待/关闭空间 等 | `lazy` 下等首次活动;`always` 下挂载即在 |
226
+ | **extended** 扩展能力(13) | 拖拽/上传/下载/对话框/裸 CDP/脚本逃生舱/登录搬运 | 同上 |
227
+ | **judge** 评审链(5) | `bcdp_jev_*` | 除解锁外,**还要求配了 JEV 或 Laya Key**——没 Key 它们只能回答「未配置」 |
228
+
229
+ 设置项在插件设置页**最上方**的「工具封印」分块(全部 volatile,翻完当场生效,不重启插件)——一级一个开关,形状照 dsh-prime-memory 的「工具封印」:
230
+
231
+ - **`toolInjection`** `lazy`(**默认**:只常驻 core,首次 `bcdp_*` 调用后按开关注入)/ `always`(挂载即全量,历史行为)。
232
+ - **`toolBrowse`**(14)/ **`toolExtended`**(13)/ **`toolJudge`**(5):开 = 开放注册,关 = 该级从模型工具列表移除。三级各自独立,封一级不波及别级;`core` 级不给开关(封了就没了活动入口)。
233
+
234
+ 行为要点:
235
+
236
+ - **封印 = 反注册**(工具从模型的工具列表里消失),不是执行期拒绝。解锁信号挂在 `bcdp_*` 调用的公共出口上,工具体不知道分级存在;`bcdp_status` / `bcdp_help` / `bcdp_doctor` 自身也算活动信号(读了指南就得有工具可用)。
237
+ - **闲置自动收回**:`lazy` + `idleTimeoutMin > 0` 时,空闲回收把后台浏览器停掉的同一刻收回扩展面;下次活动重新铺开。`always` 模式不受影响。
238
+ - `legacyEgoToolNames` 的 `ego_*` 别名跟随其 `bcdp_*` 本体的级别。
239
+ - 当前注入面写在 `bcdp_doctor` 报告首行(`tool injection: mode=lazy browse=open extended=open judge=open judgeKey=none active=no → live 6 / sealed 32`),不用猜。
240
+ - 默认档下不碰浏览器的会话只有 **6** 个工具在场(≈ 2.9K 字符,−88.6%);要回到历史行为把 `toolInjection` 改成 `always`(38 件全在场需再配一个评审 Key)。
241
+ - 四个字段都带 schema `.default()`:volatile 字段的表单描述符直接拿 schema 默认值,不写默认会出现「面板显示 A、运行时用 B」。
242
+
243
+ > 取舍提醒:窄工具(一个动作一个工具)是模型写对参数、少重试的护栏。把交互原子合并成脚本逃生舱会省上下文,但代价是模型要自己写 heredoc、出错率上升——本插件保持全部 38 个工具的签名不变,只改**出现时机**。
244
+
218
245
  ## 观察窗怎么用
219
246
 
220
247
  右下角 **🌐 常驻小球** → 点开:
@@ -4317,7 +4317,15 @@ var CaptureManager = class {
4317
4317
 
4318
4318
  //#endregion
4319
4319
  //#region src/worker/mp4-fragments.ts
4320
+ /**
4321
+ * Incremental parser for fragmented-MP4 streams produced by FFmpeg
4322
+ * (`empty_moov+default_base_moof+frag_keyframe`). Splits the byte stream on
4323
+ * box boundaries and emits two callback events: the init segment
4324
+ * (ftyp+moov) once, then each media fragment (moof+mdat) as it completes.
4325
+ * Only 32-bit box headers are supported; any other box order is an error.
4326
+ */
4320
4327
  const MAX_BOX_BYTES = 64 * 1024 * 1024;
4328
+ /** Stateful box splitter: feed via push(), close with end() to detect truncation. */
4321
4329
  var Mp4FragmentParser = class {
4322
4330
  onInit;
4323
4331
  onFragment;
@@ -4335,6 +4343,7 @@ var Mp4FragmentParser = class {
4335
4343
  this.fragmentBoxes = [];
4336
4344
  this.ready = false;
4337
4345
  }
4346
+ /** Append a raw chunk and emit every MP4 box that is now fully buffered. */
4338
4347
  push(chunk) {
4339
4348
  this.buffer = Buffer.concat([this.buffer, Buffer.from(chunk)]);
4340
4349
  while (this.buffer.length >= 8) {
@@ -4348,9 +4357,11 @@ var Mp4FragmentParser = class {
4348
4357
  this.#box(type, box);
4349
4358
  }
4350
4359
  }
4360
+ /** Signal end of stream; throws if a partial box is still buffered. */
4351
4361
  end() {
4352
4362
  if (this.buffer.length !== 0) throw new Error("truncated MP4 stream");
4353
4363
  }
4364
+ /** Route one complete box: init phase collects ftyp/moov, media phase pairs moof+mdat. */
4354
4365
  #box(type, box) {
4355
4366
  if (!this.ready) {
4356
4367
  if (type !== "ftyp" && type !== "moov") throw new Error(`unexpected MP4 init box ${type}`);
@@ -4379,6 +4390,7 @@ var Mp4FragmentParser = class {
4379
4390
  //#endregion
4380
4391
  //#region src/worker/capture-platform.ts
4381
4392
  const execFile$1 = promisify(execFile);
4393
+ /** Emit the FFmpeg input arguments for this platform: win32 gfxcapture filter, darwin avfoundation, X11 x11grab; throws on Wayland. */
4382
4394
  function buildCaptureInput({ platform: platform$1 = process.platform, env = process.env, source, fps, maxWidth, encoder }) {
4383
4395
  if (platform$1 === "win32") {
4384
4396
  if (source.sourceType !== "window-hwnd" || !source.hwnd) {
@@ -4434,6 +4446,7 @@ function buildCaptureInput({ platform: platform$1 = process.platform, env = proc
4434
4446
  `${display}+${source.captureX},${source.captureY}`
4435
4447
  ];
4436
4448
  }
4449
+ /** Emit the FFmpeg output/encoder arguments: Windows h264_mf/libx264 fast-start paths vs. the crop+scale baseline path, both streaming fragmented MP4 to stdout. */
4437
4450
  function buildEncoderArgs({ encoder, fps, maxWidth, bitrateKbps = 4e3, source, platform: platform$1 = process.platform }) {
4438
4451
  const maxrateKbps = Math.round(bitrateKbps * 1.25);
4439
4452
  const bufsizeKbps = bitrateKbps * 2;
@@ -4502,6 +4515,7 @@ function buildEncoderArgs({ encoder, fps, maxWidth, bitrateKbps = 4e3, source, p
4502
4515
  "pipe:1"
4503
4516
  ];
4504
4517
  }
4518
+ /** Pick the window closest to CDP-reported bounds (±8px tolerance), preferring a title match among the closest candidates. */
4505
4519
  function selectWindowCandidate(windows, bounds, targetTitle = "") {
4506
4520
  const candidates = windows.filter((window) => window.hwnd && window.width > 0 && window.height > 0);
4507
4521
  if (candidates.length === 0) return null;
@@ -4519,6 +4533,7 @@ function selectWindowCandidate(windows, bounds, targetTitle = "") {
4519
4533
  }
4520
4534
  return ranked[0].window;
4521
4535
  }
4536
+ /** List visible top-level windows owned by `browserPid` (Windows only) by running an inline PowerShell script that P/invokes user32.dll. */
4522
4537
  async function enumerateWindowsForPid(browserPid, run = execFile$1) {
4523
4538
  if (!Number.isInteger(browserPid) || browserPid <= 0) return [];
4524
4539
  const script = `
@@ -4584,6 +4599,7 @@ ConvertTo-Json -Compress -InputObject @($items)
4584
4599
  const parsed = JSON.parse(stdout.trim() || "[]");
4585
4600
  return Array.isArray(parsed) ? parsed : [parsed];
4586
4601
  }
4602
+ /** Resolve the capture source for a CDP target: window-geometry probe via Runtime.evaluate, then hwnd matching (win32) or display-crop math elsewhere; throws coded errors when the target is missing/not visible/minimized. */
4587
4603
  async function resolveCaptureSource({ sessions, targetId, browserPid, platform: platform$1 = process.platform, windowEnumerator = enumerateWindowsForPid }) {
4588
4604
  const value = (await sessions.call(targetId, "Runtime.evaluate", {
4589
4605
  expression: "({screenX,screenY,outerWidth,outerHeight,innerWidth,innerHeight,devicePixelRatio,title:document.title})",
package/dsh-plugin.json CHANGED
@@ -1,148 +1,190 @@
1
- {
2
- "$schema": "https://dsh.community/schemas/dsh-plugin-0.15.json",
3
- "id": "dsh-browser-cdp",
4
- "name": "dsh-browser-cdp",
5
- "version": "0.18.21",
6
- "manifestVersion": "0.15",
7
- "facets": {
8
- "host": {
9
- "entry": "lib/index.js",
10
- "apiVersion": "v1alpha1"
11
- }
12
- },
13
- "requires": {
14
- "contracts": [
15
- {
16
- "apiVersion": "presentation.dsh/v1alpha1",
17
- "kind": "OpenExternal",
18
- "optional": true,
19
- "fallback": "report the URL as text instead of opening it"
20
- },
21
- {
22
- "apiVersion": "presentation.dsh/v1alpha1",
23
- "kind": "Notification",
24
- "optional": true,
25
- "fallback": "log the notice to the browser-status scene"
26
- }
27
- ]
28
- },
29
- "permissions": [],
30
- "contributes": {
31
- "commands": [],
32
- "x-dsh-tui": [
33
- {
34
- "apiVersion": "tui.dsh/v1alpha1",
35
- "kind": "Scene",
36
- "id": "dsh-browser-cdp.watch",
37
- "name": "agent_browser",
38
- "spec": {
39
- "title": "Agent 浏览器",
40
- "titles": {
41
- "en": "Agent Browser",
42
- "zh": "Agent 浏览器"
43
- }
44
- }
45
- },
46
- {
47
- "apiVersion": "tui.dsh/v1alpha1",
48
- "kind": "SettingsSection",
49
- "id": "dsh-browser-cdp.settings",
50
- "name": "dsh_browser_cdp_settings",
51
- "spec": {
52
- "namespace": "dsh-browser-cdp",
53
- "title": "Agent 浏览器",
54
- "titles": {
55
- "en": "Agent Browser",
56
- "zh": "Agent 浏览器"
57
- },
58
- "fields": [
59
- {
60
- "path": [
61
- "isolateSpaces"
62
- ],
63
- "label": "任务空间沙盒隔离 (Space isolation)",
64
- "kind": "boolean",
65
- "hint": "默认关闭:使用磁盘持久化 Profile,任务中登录的账号跨电脑重启永久保留;开启后使用内存临时沙盒隔离,任务结束不落盘。"
66
- },
67
- {
68
- "path": [
69
- "idleTimeoutMin"
70
- ],
71
- "label": "空闲自动回收 (Idle auto-stop, minutes)",
72
- "kind": "number",
73
- "hint": "N 分钟没有任何 bcdp_* 调用后自动关闭后台浏览器进程(0 = 关闭此功能)。下次调用会自动冷启动(约 2-4 秒)。观察窗正在观看不算活动。"
74
- },
75
- {
76
- "path": [
77
- "chromePath"
78
- ],
79
- "label": "Browser binary path",
80
- "kind": "text",
81
- "hint": "Path to the Chrome/Chromium/Edge binary. Empty = auto-detect."
82
- },
83
- {
84
- "path": [
85
- "captureBackend"
86
- ],
87
- "label": "Capture backend",
88
- "kind": "select",
89
- "options": [
90
- {
91
- "value": "auto",
92
- "label": "Auto"
93
- },
94
- {
95
- "value": "cdp",
96
- "label": "CDP"
97
- },
98
- {
99
- "value": "ffmpeg",
100
- "label": "FFmpeg"
101
- }
102
- ]
103
- },
104
- {
105
- "path": [
106
- "streamProfile"
107
- ],
108
- "label": "Quality profile",
109
- "kind": "select",
110
- "options": [
111
- {
112
- "value": "balanced",
113
- "label": "Balanced"
114
- },
115
- {
116
- "value": "quality",
117
- "label": "Quality"
118
- },
119
- {
120
- "value": "speed",
121
- "label": "Speed"
122
- }
123
- ]
124
- },
125
- {
126
- "path": [
127
- "ffmpegPath"
128
- ],
129
- "label": "FFmpeg binary path",
130
- "kind": "text",
131
- "hint": "Path to ffmpeg. Empty = auto-detect / on-demand install."
132
- }
133
- ]
134
- }
135
- }
136
- ]
137
- },
138
- "subscriptions": [],
139
- "license": "MIT",
140
- "source": {
141
- "repository": "https://github.com/drscrewdriver/dsh-browser-cdp"
142
- },
143
- "compat": {
144
- "hosts": [
145
- "dsh-tui"
146
- ]
147
- }
148
- }
1
+ {
2
+ "$schema": "https://dsh.community/schemas/dsh-plugin-0.15.json",
3
+ "id": "dsh-browser-cdp",
4
+ "name": "dsh-browser-cdp",
5
+ "version": "1.2.0",
6
+ "manifestVersion": "0.15",
7
+ "facets": {
8
+ "host": {
9
+ "entry": "lib/index.js",
10
+ "apiVersion": "v1alpha1"
11
+ }
12
+ },
13
+ "requires": {
14
+ "contracts": [
15
+ {
16
+ "apiVersion": "presentation.dsh/v1alpha1",
17
+ "kind": "OpenExternal",
18
+ "optional": true,
19
+ "fallback": "report the URL as text instead of opening it"
20
+ },
21
+ {
22
+ "apiVersion": "presentation.dsh/v1alpha1",
23
+ "kind": "Notification",
24
+ "optional": true,
25
+ "fallback": "log the notice to the browser-status scene"
26
+ }
27
+ ]
28
+ },
29
+ "permissions": [],
30
+ "contributes": {
31
+ "commands": [],
32
+ "x-dsh-tui": [
33
+ {
34
+ "apiVersion": "tui.dsh/v1alpha1",
35
+ "kind": "Scene",
36
+ "id": "dsh-browser-cdp.watch",
37
+ "name": "agent_browser",
38
+ "spec": {
39
+ "title": "Agent 浏览器",
40
+ "titles": {
41
+ "en": "Agent Browser",
42
+ "zh": "Agent 浏览器"
43
+ }
44
+ }
45
+ },
46
+ {
47
+ "apiVersion": "tui.dsh/v1alpha1",
48
+ "kind": "SettingsSection",
49
+ "id": "dsh-browser-cdp.settings",
50
+ "name": "dsh_browser_cdp_settings",
51
+ "spec": {
52
+ "namespace": "dsh-browser-cdp",
53
+ "title": "Agent 浏览器",
54
+ "titles": {
55
+ "en": "Agent Browser",
56
+ "zh": "Agent 浏览器"
57
+ },
58
+ "fields": [
59
+ {
60
+ "path": [
61
+ "toolInjection"
62
+ ],
63
+ "label": "工具注入模式 (Tool injection mode)",
64
+ "kind": "select",
65
+ "options": [
66
+ {
67
+ "value": "lazy",
68
+ "label": "lazy"
69
+ },
70
+ {
71
+ "value": "always",
72
+ "label": "always"
73
+ }
74
+ ],
75
+ "hint": "lazy(默认)= 只常驻核心 6 个,首次 bcdp_* 调用后按下方开关注入,闲置回收时收回;always = 挂载即注册全部 38 个(历史行为)。"
76
+ },
77
+ {
78
+ "path": [
79
+ "toolBrowse"
80
+ ],
81
+ "label": "基础操作工具(14 个)",
82
+ "kind": "boolean",
83
+ "hint": "开(默认)= 浏览器活动后正常注册;关 = 14 个工具从模型工具列表移除(点击/填写/键鼠/截图/读取/等待…)。"
84
+ },
85
+ {
86
+ "path": [
87
+ "toolExtended"
88
+ ],
89
+ "label": "扩展能力工具(13 个)",
90
+ "kind": "boolean",
91
+ "hint": "开(默认)= 正常注册;关 = 13 个工具移除(拖拽/上传/下载/对话框/裸 CDP/脚本逃生舱/登录导入)。"
92
+ },
93
+ {
94
+ "path": [
95
+ "toolJudge"
96
+ ],
97
+ "label": "评审工具 bcdp_jev_*(5 个)",
98
+ "kind": "boolean",
99
+ "hint": "开仍需配了 JEV 或 Laya Key:没 Key 的评审工具只能回答「未配置」,依旧不注入。关 = 任何情况下都不注入。"
100
+ },
101
+ {
102
+ "path": [
103
+ "isolateSpaces"
104
+ ],
105
+ "label": "任务空间沙盒隔离 (Space isolation)",
106
+ "kind": "boolean",
107
+ "hint": "默认关闭:使用磁盘持久化 Profile,任务中登录的账号跨电脑重启永久保留;开启后使用内存临时沙盒隔离,任务结束不落盘。"
108
+ },
109
+ {
110
+ "path": [
111
+ "idleTimeoutMin"
112
+ ],
113
+ "label": "空闲自动回收 (Idle auto-stop, minutes)",
114
+ "kind": "number",
115
+ "hint": "N 分钟没有任何 bcdp_* 调用后自动关闭后台浏览器进程(0 = 关闭此功能)。下次调用会自动冷启动(约 2-4 秒)。观察窗正在观看不算活动。"
116
+ },
117
+ {
118
+ "path": [
119
+ "chromePath"
120
+ ],
121
+ "label": "Browser binary path",
122
+ "kind": "text",
123
+ "hint": "Path to the Chrome/Chromium/Edge binary. Empty = auto-detect."
124
+ },
125
+ {
126
+ "path": [
127
+ "captureBackend"
128
+ ],
129
+ "label": "Capture backend",
130
+ "kind": "select",
131
+ "options": [
132
+ {
133
+ "value": "auto",
134
+ "label": "Auto"
135
+ },
136
+ {
137
+ "value": "cdp",
138
+ "label": "CDP"
139
+ },
140
+ {
141
+ "value": "ffmpeg",
142
+ "label": "FFmpeg"
143
+ }
144
+ ]
145
+ },
146
+ {
147
+ "path": [
148
+ "streamProfile"
149
+ ],
150
+ "label": "Quality profile",
151
+ "kind": "select",
152
+ "options": [
153
+ {
154
+ "value": "balanced",
155
+ "label": "Balanced"
156
+ },
157
+ {
158
+ "value": "quality",
159
+ "label": "Quality"
160
+ },
161
+ {
162
+ "value": "speed",
163
+ "label": "Speed"
164
+ }
165
+ ]
166
+ },
167
+ {
168
+ "path": [
169
+ "ffmpegPath"
170
+ ],
171
+ "label": "FFmpeg binary path",
172
+ "kind": "text",
173
+ "hint": "Path to ffmpeg. Empty = auto-detect / on-demand install."
174
+ }
175
+ ]
176
+ }
177
+ }
178
+ ]
179
+ },
180
+ "subscriptions": [],
181
+ "license": "MIT",
182
+ "source": {
183
+ "repository": "https://github.com/drscrewdriver/dsh-browser-cdp"
184
+ },
185
+ "compat": {
186
+ "hosts": [
187
+ "dsh-tui"
188
+ ]
189
+ }
190
+ }