dsh-browser-cdp 1.3.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dsh-plugin.json CHANGED
@@ -1,198 +1,198 @@
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.3.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(默认)= 常驻核心 7 个 + 逃生舱 2 个,其余首次 bcdp_* 调用后按下方开关注入,闲置回收时收回;always = 挂载即注册全部 38 个(历史行为)。"
76
- },
77
- {
78
- "path": [
79
- "toolBrowse"
80
- ],
81
- "label": "基础操作工具(16 个)",
82
- "kind": "boolean",
83
- "hint": "开(默认)= 浏览器活动后按 act → observe → wait 三波放行;关 = 16 个工具从模型工具列表移除(点击/填写/键鼠/拖拽/截图/读取/等待…)。"
84
- },
85
- {
86
- "path": [
87
- "toolExtended"
88
- ],
89
- "label": "扩展能力工具(8 个)",
90
- "kind": "boolean",
91
- "hint": "开(默认)= 浏览器活动后注册;关 = 8 个工具移除(裸 CDP/HTTP/上传/下载/对话框/验证码/登录落盘/登录导入)。"
92
- },
93
- {
94
- "path": [
95
- "toolEscape"
96
- ],
97
- "label": "逃生舱 cli / script(2 个)",
98
- "kind": "boolean",
99
- "hint": "始终可用——与其它档不同,它不等浏览器活动,因为一个 heredoc 就能做到其余 36 个工具的事。关 = 封印。"
100
- },
101
- {
102
- "path": [
103
- "toolJudge"
104
- ],
105
- "label": "评审工具 bcdp_jev_*(5 个)",
106
- "kind": "boolean",
107
- "hint": "开仍需配了 JEV 或 Laya Key:没 Key 的评审工具只能回答「未配置」,依旧不注入。关 = 任何情况下都不注入。"
108
- },
109
- {
110
- "path": [
111
- "isolateSpaces"
112
- ],
113
- "label": "任务空间沙盒隔离 (Space isolation)",
114
- "kind": "boolean",
115
- "hint": "默认关闭:使用磁盘持久化 Profile,任务中登录的账号跨电脑重启永久保留;开启后使用内存临时沙盒隔离,任务结束不落盘。"
116
- },
117
- {
118
- "path": [
119
- "idleTimeoutMin"
120
- ],
121
- "label": "空闲自动回收 (Idle auto-stop, minutes)",
122
- "kind": "number",
123
- "hint": "N 分钟没有任何 bcdp_* 调用后自动关闭后台浏览器进程(0 = 关闭此功能)。下次调用会自动冷启动(约 2-4 秒)。观察窗正在观看不算活动。"
124
- },
125
- {
126
- "path": [
127
- "chromePath"
128
- ],
129
- "label": "Browser binary path",
130
- "kind": "text",
131
- "hint": "Path to the Chrome/Chromium/Edge binary. Empty = auto-detect."
132
- },
133
- {
134
- "path": [
135
- "captureBackend"
136
- ],
137
- "label": "Capture backend",
138
- "kind": "select",
139
- "options": [
140
- {
141
- "value": "auto",
142
- "label": "Auto"
143
- },
144
- {
145
- "value": "cdp",
146
- "label": "CDP"
147
- },
148
- {
149
- "value": "ffmpeg",
150
- "label": "FFmpeg"
151
- }
152
- ]
153
- },
154
- {
155
- "path": [
156
- "streamProfile"
157
- ],
158
- "label": "Quality profile",
159
- "kind": "select",
160
- "options": [
161
- {
162
- "value": "balanced",
163
- "label": "Balanced"
164
- },
165
- {
166
- "value": "quality",
167
- "label": "Quality"
168
- },
169
- {
170
- "value": "speed",
171
- "label": "Speed"
172
- }
173
- ]
174
- },
175
- {
176
- "path": [
177
- "ffmpegPath"
178
- ],
179
- "label": "FFmpeg binary path",
180
- "kind": "text",
181
- "hint": "Path to ffmpeg. Empty = auto-detect / on-demand install."
182
- }
183
- ]
184
- }
185
- }
186
- ]
187
- },
188
- "subscriptions": [],
189
- "license": "MIT",
190
- "source": {
191
- "repository": "https://github.com/drscrewdriver/dsh-browser-cdp"
192
- },
193
- "compat": {
194
- "hosts": [
195
- "dsh-tui"
196
- ]
197
- }
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.3.1",
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(默认)= 常驻核心 7 个 + 逃生舱 2 个,其余首次 bcdp_* 调用后按下方开关注入,闲置回收时收回;always = 挂载即注册全部 38 个(历史行为)。"
76
+ },
77
+ {
78
+ "path": [
79
+ "toolBrowse"
80
+ ],
81
+ "label": "基础操作工具(16 个)",
82
+ "kind": "boolean",
83
+ "hint": "开(默认)= 浏览器活动后按 act → observe → wait 三波放行;关 = 16 个工具从模型工具列表移除(点击/填写/键鼠/拖拽/截图/读取/等待…)。"
84
+ },
85
+ {
86
+ "path": [
87
+ "toolExtended"
88
+ ],
89
+ "label": "扩展能力工具(8 个)",
90
+ "kind": "boolean",
91
+ "hint": "开(默认)= 浏览器活动后注册;关 = 8 个工具移除(裸 CDP/HTTP/上传/下载/对话框/验证码/登录落盘/登录导入)。"
92
+ },
93
+ {
94
+ "path": [
95
+ "toolEscape"
96
+ ],
97
+ "label": "逃生舱 cli / script(2 个)",
98
+ "kind": "boolean",
99
+ "hint": "始终可用——与其它档不同,它不等浏览器活动,因为一个 heredoc 就能做到其余 36 个工具的事。关 = 封印。"
100
+ },
101
+ {
102
+ "path": [
103
+ "toolJudge"
104
+ ],
105
+ "label": "评审工具 bcdp_jev_*(5 个)",
106
+ "kind": "boolean",
107
+ "hint": "开仍需配了 JEV 或 Laya Key:没 Key 的评审工具只能回答「未配置」,依旧不注入。关 = 任何情况下都不注入。"
108
+ },
109
+ {
110
+ "path": [
111
+ "isolateSpaces"
112
+ ],
113
+ "label": "任务空间沙盒隔离 (Space isolation)",
114
+ "kind": "boolean",
115
+ "hint": "默认关闭:使用磁盘持久化 Profile,任务中登录的账号跨电脑重启永久保留;开启后使用内存临时沙盒隔离,任务结束不落盘。"
116
+ },
117
+ {
118
+ "path": [
119
+ "idleTimeoutMin"
120
+ ],
121
+ "label": "空闲自动回收 (Idle auto-stop, minutes)",
122
+ "kind": "number",
123
+ "hint": "N 分钟没有任何 bcdp_* 调用后自动关闭后台浏览器进程(0 = 关闭此功能)。下次调用会自动冷启动(约 2-4 秒)。观察窗正在观看不算活动。"
124
+ },
125
+ {
126
+ "path": [
127
+ "chromePath"
128
+ ],
129
+ "label": "Browser binary path",
130
+ "kind": "text",
131
+ "hint": "Path to the Chrome/Chromium/Edge binary. Empty = auto-detect."
132
+ },
133
+ {
134
+ "path": [
135
+ "captureBackend"
136
+ ],
137
+ "label": "Capture backend",
138
+ "kind": "select",
139
+ "options": [
140
+ {
141
+ "value": "auto",
142
+ "label": "Auto"
143
+ },
144
+ {
145
+ "value": "cdp",
146
+ "label": "CDP"
147
+ },
148
+ {
149
+ "value": "ffmpeg",
150
+ "label": "FFmpeg"
151
+ }
152
+ ]
153
+ },
154
+ {
155
+ "path": [
156
+ "streamProfile"
157
+ ],
158
+ "label": "Quality profile",
159
+ "kind": "select",
160
+ "options": [
161
+ {
162
+ "value": "balanced",
163
+ "label": "Balanced"
164
+ },
165
+ {
166
+ "value": "quality",
167
+ "label": "Quality"
168
+ },
169
+ {
170
+ "value": "speed",
171
+ "label": "Speed"
172
+ }
173
+ ]
174
+ },
175
+ {
176
+ "path": [
177
+ "ffmpegPath"
178
+ ],
179
+ "label": "FFmpeg binary path",
180
+ "kind": "text",
181
+ "hint": "Path to ffmpeg. Empty = auto-detect / on-demand install."
182
+ }
183
+ ]
184
+ }
185
+ }
186
+ ]
187
+ },
188
+ "subscriptions": [],
189
+ "license": "MIT",
190
+ "source": {
191
+ "repository": "https://github.com/drscrewdriver/dsh-browser-cdp"
192
+ },
193
+ "compat": {
194
+ "hosts": [
195
+ "dsh-tui"
196
+ ]
197
+ }
198
198
  }
package/lib/index.js CHANGED
@@ -7409,8 +7409,19 @@ async function runWithStaleSpaceRetry(ctx, cfg, exec, buildScript, graceOverride
7409
7409
  }
7410
7410
  return result;
7411
7411
  }
7412
- /** Find the last line carrying the sentinel and JSON-parse its payload. */
7413
- /** @internal exported for tests */
7412
+ /**
7413
+ * Find the last line carrying the sentinel and JSON-parse its payload.
7414
+ *
7415
+ * Fallback: `bcdp_script` / `bcdp_cli` run user-authored heredocs, and both
7416
+ * tool descriptions tell the model to "end with console.log(JSON.stringify(...))"
7417
+ * — without the sentinel prefix. A script written to that instruction used to
7418
+ * succeed and still be reported as a failure ("no @@DSH_RESULT@@ payload"), so
7419
+ * when no sentinel line exists we accept the last line that parses as a JSON
7420
+ * object. The sentinel still wins whenever it is present (it marks the payload
7421
+ * deliberately, across any amount of surrounding log noise).
7422
+ *
7423
+ * @internal exported for tests
7424
+ */
7414
7425
  function parseSentinel(stdout) {
7415
7426
  const lines = stdout.split("\n");
7416
7427
  for (let i = lines.length - 1; i >= 0; i--) {
@@ -7423,6 +7434,14 @@ function parseSentinel(stdout) {
7423
7434
  return;
7424
7435
  }
7425
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;
7440
+ try {
7441
+ const parsed = JSON.parse(text);
7442
+ if (parsed !== null && typeof parsed === "object" && !Array.isArray(parsed)) return parsed;
7443
+ } catch {}
7444
+ }
7426
7445
  }
7427
7446
  /** R2/R3 — sentinel + payload for the `bcdp_status` facade probe. @internal exported for tests */
7428
7447
  const STATUS_FACADE_SENTINEL = "__BCDP_STATUS__";
@@ -8887,11 +8906,11 @@ function registerActionTools(ctx, cfg, reg) {
8887
8906
  reg((() => {
8888
8907
  return defineTool({
8889
8908
  name: "bcdp_cli",
8890
- description: "Escape hatch: run an arbitrary `ego-browser nodejs` heredoc script verbatim (facades page/browser/taskSpaces/site/fetch and the raw cdp() are preloaded). Use when the structured bcdp_* tools do not cover the task. Returns raw stdout plus the parsed console.log payload when present.",
8909
+ 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.",
8891
8910
  parameters: { script: {
8892
8911
  type: "string",
8893
8912
  required: true,
8894
- description: "Full JS script body for the heredoc; ego-browser helpers are preloaded. End with console.log(JSON.stringify(...)) for a parseable sentinel payload."
8913
+ 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`."
8895
8914
  } },
8896
8915
  output: {
8897
8916
  schema: {
@@ -9172,12 +9191,12 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
9172
9191
  reg((() => {
9173
9192
  return defineTool({
9174
9193
  name: "bcdp_script",
9175
- description: "Run an arbitrary `ego-browser nodejs` heredoc script in ONE invocation (same runtime/API as bcdp_cli: 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.",
9194
+ 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.",
9176
9195
  parameters: {
9177
9196
  script: {
9178
9197
  type: "string",
9179
9198
  required: true,
9180
- description: "Full JS script body; end with console.log(JSON.stringify(...)) for a parseable sentinel payload."
9199
+ description: "Full JS script body. You may end with console.log(JSON.stringify(payload)) — bare or prefixed with the sentinel — and it is returned as `result`. Without one, `output` still carries everything the script printed."
9181
9200
  },
9182
9201
  timeoutMs: {
9183
9202
  type: "integer",
@@ -9215,7 +9234,11 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
9215
9234
  markEgoToolCall(callingSessionId(exec));
9216
9235
  const timeoutMs = typeof args.timeoutMs === "number" && Number.isFinite(args.timeoutMs) && args.timeoutMs > 0 ? args.timeoutMs : void 0;
9217
9236
  const start = Date.now();
9218
- const result = await runWithStaleSpaceRetry(ctx, cfg, exec, () => str(args.script, ""), timeoutMs);
9237
+ const preamble = (body) => {
9238
+ if (/taskSpaces\s*\.\s*useOrCreate\s*\(/.test(body)) return body;
9239
+ return `${useSpace(cfg.defaultSpace)}${ensureRealTab()}${body}`;
9240
+ };
9241
+ const result = await runWithStaleSpaceRetry(ctx, cfg, exec, () => preamble(str(args.script, "")), timeoutMs);
9219
9242
  const durationMs = Date.now() - start;
9220
9243
  if (!result.ok) return {
9221
9244
  ok: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-browser-cdp",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
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",