@53able/pi-agent-browser 0.4.2 → 0.5.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.ja-JP.md CHANGED
@@ -177,7 +177,9 @@ https://example.com をブラウザ経由で読み、outputs/browser/example.md
177
177
  agent-browser doctor
178
178
  ```
179
179
 
180
- または Pi に `agent_browser_doctor` を実行させてください。
180
+ または Pi に `agent_browser_doctor` を実行させてください。インストール、Chrome、daemon、security、provider、network、launch test を確認します。`agent_browser_login_handoff` で作ったセッションでまだ開いているログインブラウザも報告し、期限切れ追跡データを自動削除します。
181
+
182
+ `agent_browser_login_handoff` で作ったセッションの中で、まだ生存しているログインブラウザがあれば、`agent_browser_doctor` がそれらを報告します(セッション名、プロセス ID、デバッグポート、最後に開いていた URL を表示)。終わったら各セッションに対して `agent_browser_close` を呼んでください — これらのセッションはブラウザを閉じるまでリモートデバッグポートが開いたままです。期限切れエントリ(実行中でなくなったプロセスの追跡データ)は、何も通知することなく自動削除されます。
181
183
 
182
184
  よくある修正:
183
185
 
package/README.md CHANGED
@@ -179,7 +179,9 @@ Run:
179
179
  agent-browser doctor
180
180
  ```
181
181
 
182
- Or ask Pi to run `agent_browser_doctor`.
182
+ Or ask Pi to run `agent_browser_doctor`. This verifies installation, Chrome, daemon, security, providers, network, and launch tests. It also reports any live login-handoff browsers left open and cleans up stale tracking entries.
183
+
184
+ If you have sessions created with `agent_browser_login_handoff`, `agent_browser_doctor` will report any that still have live login browsers running, showing the session name, process ID, debugging port, and last known URL. Call `agent_browser_close` for each session when done — these hold an open remote-debugging port until closed. Stale entries (tracking data for processes no longer running) are cleaned up automatically with no notification.
183
185
 
184
186
  Common fixes:
185
187
 
package/index.ts CHANGED
@@ -275,6 +275,15 @@ function killPidBestEffort(pid?: number): void {
275
275
  try { process.kill(pid); } catch { /* already gone / not ours */ }
276
276
  }
277
277
 
278
+ function isPidAlive(pid: number): boolean {
279
+ try {
280
+ process.kill(pid, 0); // signal 0 = no-op existence/permission check, does not actually kill
281
+ return true;
282
+ } catch (err) {
283
+ return (err as NodeJS.ErrnoException).code !== "ESRCH"; // ESRCH = no such process (dead); any other error (e.g. EPERM) means it exists
284
+ }
285
+ }
286
+
278
287
  function abortableDelay(ms: number, signal?: AbortSignal): Promise<void> {
279
288
  return new Promise((resolveDelay) => {
280
289
  if (signal?.aborted) {
@@ -1052,15 +1061,43 @@ export default function agentBrowserExtension(pi: ExtensionAPI) {
1052
1061
  pi.registerTool({
1053
1062
  name: "agent_browser_doctor",
1054
1063
  label: "Agent Browser Doctor",
1055
- description: "Run agent-browser doctor to verify installation, Chrome, daemon, security, providers, network, and launch tests.",
1056
- promptSnippet: "Use agent_browser_doctor when browser automation fails or before relying on agent-browser in a workflow.",
1064
+ description: "Run agent-browser doctor to verify installation, Chrome, daemon, security, providers, network, and launch tests. Also reports and cleans up tracked login-handoff browsers (see agent_browser_login_handoff).",
1065
+ promptSnippet: "Use agent_browser_doctor when browser automation fails or before relying on agent-browser in a workflow. It also flags any live login-handoff browsers left open and cleans up stale tracking entries.",
1057
1066
  parameters: DoctorSchema,
1058
1067
  async execute(_id, rawParams, signal, onUpdate, ctx) {
1059
1068
  const params = rawParams as JsonObject;
1060
1069
  const args = ["doctor"];
1061
1070
  if (params.fix === true) args.push("--fix");
1062
1071
  const result = await runAgentBrowser(args, { signal, timeoutMs: params.timeoutMs as number | undefined, cwd: ctx.cwd, onUpdate });
1063
- return buildTextResult(result);
1072
+ const textResult = buildTextResult(result);
1073
+
1074
+ const states = await readSessionStates(ctx.cwd);
1075
+ const liveBrowsers: { session: string; pid: number; port: number | undefined; lastUrl?: string }[] = [];
1076
+ for (const [session, state] of Object.entries(states)) {
1077
+ if (!state.loginBrowserPid) continue;
1078
+ if (!isPidAlive(state.loginBrowserPid)) {
1079
+ await writeSessionState(ctx.cwd, session, { clearLoginBrowserPid: true });
1080
+ continue;
1081
+ }
1082
+ liveBrowsers.push({
1083
+ session: session === DEFAULT_SESSION_KEY ? "(default)" : session,
1084
+ pid: state.loginBrowserPid,
1085
+ port: state.loginDebugPort,
1086
+ lastUrl: state.lastUrl,
1087
+ });
1088
+ }
1089
+
1090
+ if (liveBrowsers.length > 0) {
1091
+ const lines = [
1092
+ "",
1093
+ "Live login browsers (from agent_browser_login_handoff) still open:",
1094
+ ...liveBrowsers.map((b) => `- ${b.session}: pid ${b.pid}, debug port ${b.port ?? "?"}${b.lastUrl ? `, last url ${b.lastUrl}` : ""}`),
1095
+ "Call agent_browser_close for each session when done — these hold an open remote-debugging port until closed.",
1096
+ ];
1097
+ textResult.content[0].text += lines.join("\n");
1098
+ }
1099
+
1100
+ return textResult;
1064
1101
  },
1065
1102
  });
1066
1103
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@53able/pi-agent-browser",
3
- "version": "0.4.2",
3
+ "version": "0.5.0",
4
4
  "description": "Typed Pi tools for browser automation, rendered-page context extraction, screenshots, and saved session state via agent-browser.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -64,6 +64,8 @@ After the human confirms login is complete, subsequent `agent_browser_open`, `ag
64
64
 
65
65
  **Security note:** The login browser's `--remote-debugging-port` remains open on localhost for as long as the session is alive. This gives any local process full browser control — the same caveat agent-browser's own docs give about `--remote-debugging-port`. Call `agent_browser_close` when done with a session that went through login handoff, rather than leaving it open indefinitely. `agent_browser_close` will terminate the tracked login Chrome process and clean up its debugging port.
66
66
 
67
+ Run `agent_browser_doctor` to see which sessions still have live login browsers open. It reports any that are still running (session name, process ID, debugging port, and last known URL) with a reminder to call `agent_browser_close`. Stale tracking entries for processes no longer running are cleaned up silently with no user notification.
68
+
67
69
  Re-running `agent_browser_login_handoff` for the same session name will terminate any previous live login browser for that session before spawning a new one.
68
70
 
69
71
  ## Common examples