@xiaoqiong0v0/opencode-browser-tool 1.5.0 → 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.md +3 -1
- package/dist/client.js +36 -6
- package/dist/index.js +6 -10
- package/package.json +44 -44
package/README.md
CHANGED
|
@@ -102,6 +102,8 @@ opencode(Bun)
|
|
|
102
102
|
- 除 spawn 本地 shell 外,也可用 `BT_SHELL_URL` / `BT_SHELL_PORT` **附着到已运行的 shell**(不 spawn,适用于 shell 跑在 WSL/Linux、插件跑在 Windows)
|
|
103
103
|
- 跨平台:Windows / Linux / macOS
|
|
104
104
|
- 真多标签:每标签独立 page Webview,切换不重载;`target=_blank` / `window.open` 链接通过 WebView2 原生事件拦截并打开为新标签
|
|
105
|
+
- 地址栏/标题/图标**事件驱动同步(无轮询)**:导航用 `on_navigation`(请求即更新)+ `on_page_load`(完成后读真实 `location.href`/`title`);站内 SPA(`pushState`/`replaceState`/`popstate`/`hashchange`)与标题/图标变化由注入脚本上报 `POST /api/page-event`。`TabState.url` 只反映**最后一次真实导航请求**,内部/错误 scheme(`chrome-error:`/`about:`/`tauri:`/`data:` 等)不覆盖地址栏
|
|
106
|
+
- 刷新语义:标签处于错误页(`errored`)时,工具栏刷新 / `bt_reload` **重新导航原 URL**(而非刷错误页);否则走原生 reload
|
|
105
107
|
- 窗口无标题栏,自定义窗口按钮在标签行右侧;最小尺寸 500×400(逻辑像素)
|
|
106
108
|
|
|
107
109
|
## 工具
|
|
@@ -140,7 +142,7 @@ opencode(Bun)
|
|
|
140
142
|
| `bt_resize` | `width`, `height`(number) 必填 | 调整窗口尺寸(逻辑像素) |
|
|
141
143
|
| `bt_set_device` | `name`(string) 可选 | 应用设备预设(空参数列出 13 种预设) |
|
|
142
144
|
| `bt_devtools` | `action`(string):`toggle`/`open`/`close` | 开关开发者工具 |
|
|
143
|
-
| `bt_reload` | 无 |
|
|
145
|
+
| `bt_reload` | 无 | 刷新当前页面;若当前为错误页则**重新导航原 URL**(返回 `retried`) |
|
|
144
146
|
| `bt_close` | 无 | 退出浏览器外壳 |
|
|
145
147
|
| `bt_show_notification` | `message`(string), `type`(string):`ok`/`bad`/`err` | 显示页面通知气泡 |
|
|
146
148
|
| `bt_scroll` | `direction`(string):`up`/`down`/`left`/`right`, `amount`(number) | 滚动页面 |
|
package/dist/client.js
CHANGED
|
@@ -228,16 +228,47 @@ export async function startService(nodePath, browsersPath, sessionIsolation, bro
|
|
|
228
228
|
serviceReady = true;
|
|
229
229
|
log.info(`Shell service ready on port ${port} (${shell})`);
|
|
230
230
|
}
|
|
231
|
+
/** 等待子进程退出(有界超时);已退出/出错返回 true,超时返回 false */
|
|
232
|
+
function waitForExit(proc, timeoutMs) {
|
|
233
|
+
return new Promise((resolveExit) => {
|
|
234
|
+
if (!proc || proc.exitCode !== null || proc.signalCode !== null)
|
|
235
|
+
return resolveExit(true);
|
|
236
|
+
let done = false;
|
|
237
|
+
const finish = (v) => {
|
|
238
|
+
if (done)
|
|
239
|
+
return;
|
|
240
|
+
done = true;
|
|
241
|
+
clearTimeout(timer);
|
|
242
|
+
resolveExit(v);
|
|
243
|
+
};
|
|
244
|
+
const timer = setTimeout(() => finish(false), timeoutMs);
|
|
245
|
+
proc.once("exit", () => finish(true));
|
|
246
|
+
proc.once("error", () => finish(true));
|
|
247
|
+
});
|
|
248
|
+
}
|
|
231
249
|
export async function stopService() {
|
|
232
250
|
if (attachMode) {
|
|
233
|
-
// 附着模式:外部 shell
|
|
251
|
+
// 附着模式:外部 shell 进程不归插件管,**绝不 kill**,只清空本地状态
|
|
234
252
|
log.info("Detached from external bt-shell (process left running)");
|
|
253
|
+
serviceReady = false;
|
|
254
|
+
serviceBaseUrl = "";
|
|
255
|
+
attachMode = false;
|
|
256
|
+
return;
|
|
235
257
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
258
|
+
const proc = serviceProcess;
|
|
259
|
+
if (proc) {
|
|
260
|
+
// 先等 shell 自己退出(Rust /api/close 已 app.exit(0) 优雅退出);有界 5s,仍存活才按该 PID 补 SIGTERM
|
|
261
|
+
const exited = await waitForExit(proc, 5000);
|
|
262
|
+
if (exited) {
|
|
263
|
+
log.info("bt-shell exited gracefully");
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
log.info(`bt-shell did not exit within 5s; sending SIGTERM to pid=${proc.pid}`);
|
|
267
|
+
try {
|
|
268
|
+
proc.kill("SIGTERM");
|
|
269
|
+
}
|
|
270
|
+
catch { }
|
|
239
271
|
}
|
|
240
|
-
catch { }
|
|
241
272
|
serviceProcess = null;
|
|
242
273
|
}
|
|
243
274
|
serviceReady = false;
|
|
@@ -327,7 +358,6 @@ export const service = {
|
|
|
327
358
|
expectResponse: cmd("expect-response"),
|
|
328
359
|
assertResponse: cmd("assert-response"),
|
|
329
360
|
panelConfig: cmd("panel-config"),
|
|
330
|
-
closeSession: cmd("close-session"),
|
|
331
361
|
status: cmd("status"),
|
|
332
362
|
tabs: cmd("tabs"),
|
|
333
363
|
annotateToggle: cmd("annotate/toggle"),
|
package/dist/index.js
CHANGED
|
@@ -286,19 +286,15 @@ export const opencodeBrowserTool = async ({ client, worktree, directory, serverU
|
|
|
286
286
|
return {
|
|
287
287
|
event: async ({ event }) => {
|
|
288
288
|
// 缓存最近会话 id:这是投递批注最可靠的 sessionID 来源
|
|
289
|
-
if (event.type
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
else {
|
|
289
|
+
if (event.type === "session.deleted") {
|
|
290
|
+
// 删除会话:只清缓存,**绝不触碰 shell** —— 否则会经 service.closeSession → callApi → ensureService
|
|
291
|
+
// → spawn(bt-shell) 弹出浏览器窗口(而 /api/close-session 是空壳,唯一实际效果就是启动浏览器)
|
|
293
292
|
const delId = extractSessionIDFromEvent(event);
|
|
294
|
-
if (delId)
|
|
293
|
+
if (delId)
|
|
295
294
|
sessionCache.clearIf(delId);
|
|
296
|
-
|
|
297
|
-
await service.closeSession({ _sessionId: delId });
|
|
298
|
-
}
|
|
299
|
-
catch { }
|
|
300
|
-
}
|
|
295
|
+
return;
|
|
301
296
|
}
|
|
297
|
+
sessionCache.updateFromEvent(event);
|
|
302
298
|
},
|
|
303
299
|
// 用户发消息 / 调工具时刷新当前会话 id(参考项目用 ctx.sessionID,此处为等价钩子来源)
|
|
304
300
|
"chat.message": async (input) => {
|
package/package.json
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@xiaoqiong0v0/opencode-browser-tool",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "opencode 浏览器工具插件:WebView2 外壳渲染 + 零注入视觉元素选取面板",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"build": "tsc",
|
|
8
|
-
"dev": "tsc --watch",
|
|
9
|
-
"build:frontend": "cd frontend && npm install && npm run build"
|
|
10
|
-
},
|
|
11
|
-
"keywords": [
|
|
12
|
-
"opencode",
|
|
13
|
-
"browser",
|
|
14
|
-
"webview2",
|
|
15
|
-
"plugin"
|
|
16
|
-
],
|
|
17
|
-
"author": "",
|
|
18
|
-
"license": "ISC",
|
|
19
|
-
"type": "module",
|
|
20
|
-
"files": [
|
|
21
|
-
"dist"
|
|
22
|
-
],
|
|
23
|
-
"dependencies": {
|
|
24
|
-
"@xiaoqiong0v0/opencode-plugin-logger": "^1.0.5",
|
|
25
|
-
"string-argv": "^0.3.2"
|
|
26
|
-
},
|
|
27
|
-
"peerDependencies": {
|
|
28
|
-
"@opencode-ai/plugin": "^1.18.4"
|
|
29
|
-
},
|
|
30
|
-
"devDependencies": {
|
|
31
|
-
"@types/node": "^26.1.1",
|
|
32
|
-
"typescript": "^7.0.2"
|
|
33
|
-
},
|
|
34
|
-
"publishConfig": {
|
|
35
|
-
"access": "public"
|
|
36
|
-
},
|
|
37
|
-
"repository": {
|
|
38
|
-
"type": "git",
|
|
39
|
-
"url": "git+https://github.com/xiaoqiong0v0/opencode-browser-tool.git"
|
|
40
|
-
},
|
|
41
|
-
"volta": {
|
|
42
|
-
"node": "24.16.0"
|
|
43
|
-
}
|
|
44
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@xiaoqiong0v0/opencode-browser-tool",
|
|
3
|
+
"version": "1.6.0",
|
|
4
|
+
"description": "opencode 浏览器工具插件:WebView2 外壳渲染 + 零注入视觉元素选取面板",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "tsc",
|
|
8
|
+
"dev": "tsc --watch",
|
|
9
|
+
"build:frontend": "cd frontend && npm install && npm run build"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"opencode",
|
|
13
|
+
"browser",
|
|
14
|
+
"webview2",
|
|
15
|
+
"plugin"
|
|
16
|
+
],
|
|
17
|
+
"author": "",
|
|
18
|
+
"license": "ISC",
|
|
19
|
+
"type": "module",
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@xiaoqiong0v0/opencode-plugin-logger": "^1.0.5",
|
|
25
|
+
"string-argv": "^0.3.2"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"@opencode-ai/plugin": "^1.18.4"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/node": "^26.1.1",
|
|
32
|
+
"typescript": "^7.0.2"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
36
|
+
},
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "git+https://github.com/xiaoqiong0v0/opencode-browser-tool.git"
|
|
40
|
+
},
|
|
41
|
+
"volta": {
|
|
42
|
+
"node": "24.16.0"
|
|
43
|
+
}
|
|
44
|
+
}
|