@xiaoqiong0v0/opencode-browser-tool 1.4.0 → 1.5.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/dist/client.js +36 -6
- package/dist/index.js +6 -10
- package/package.json +44 -44
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.5.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
|
+
}
|