@cydm/pie 4.4.2 → 4.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.
Files changed (48) hide show
  1. package/dist/builtin/extensions/ask-user/index.js +6 -6
  2. package/dist/builtin/extensions/changelog/index.js +1 -1
  3. package/dist/builtin/extensions/cron/index.js +55 -7
  4. package/dist/builtin/extensions/document-attachments/index.js +1 -1
  5. package/dist/builtin/extensions/herdr-agent-state/index.js +1 -1
  6. package/dist/builtin/extensions/im-forward/README.md +3 -1
  7. package/dist/builtin/extensions/im-forward/index.js +364 -118
  8. package/dist/builtin/extensions/init/index.js +1 -1
  9. package/dist/builtin/extensions/mcp-adapter/index.js +2 -2
  10. package/dist/builtin/extensions/memory/index.js +9 -11
  11. package/dist/builtin/extensions/pie-ipc/index.js +70 -19
  12. package/dist/builtin/extensions/pie-proc/index.js +27 -13
  13. package/dist/builtin/extensions/plan-mode/index.js +6 -6
  14. package/dist/builtin/extensions/subagent/index.js +9 -11
  15. package/dist/builtin/extensions/todo/index.js +6 -6
  16. package/dist/builtin/skills/chrome-devtools-axi/SKILL.md +24 -1
  17. package/dist/builtin/skills/chrome-devtools-axi/chrome-devtools-axi-bridge.js +86 -21
  18. package/dist/builtin/skills/chrome-devtools-axi/chrome-devtools-axi-cli.js +6 -1
  19. package/dist/builtin/skills/chrome-devtools-axi/chrome-devtools-axi-runtime.js +1 -1
  20. package/dist/builtin/skills/chrome-devtools-axi/{cli-CHC7XYFU.js → cli-NLPMVDGG.js} +32 -4
  21. package/dist/builtin/skills/computer-use-axi/computer-use-axi-broker.js +220 -22
  22. package/dist/chunks/{auth-storage-RABPRJ6T.js → auth-storage-C3FZMT7J.js} +3 -3
  23. package/dist/chunks/{chunk-OFLKAWI4.js → chunk-2CJIENLY.js} +90 -100
  24. package/dist/chunks/{chunk-R7VO46EK.js → chunk-3W3SXVPB.js} +5 -4
  25. package/dist/chunks/{chunk-IPLMGAML.js → chunk-5KI4Y4LA.js} +1 -1
  26. package/dist/chunks/{chunk-YNTIOWCD.js → chunk-BLDI2GRF.js} +5 -5
  27. package/dist/chunks/{chunk-UCKOXAME.js → chunk-CBDQJMUI.js} +9 -44
  28. package/dist/chunks/chunk-CGSFBWOM.js +100 -0
  29. package/dist/chunks/{chunk-7LTQLJJF.js → chunk-LAJXWOKS.js} +15 -10
  30. package/dist/chunks/{chunk-RZGYXAJU.js → chunk-LZQXQOPJ.js} +1 -12
  31. package/dist/chunks/{chunk-EQOI6RZV.js → chunk-NHV2CALB.js} +3 -5
  32. package/dist/chunks/{chunk-OV7SLSHR.js → chunk-SW2E33UL.js} +2 -4
  33. package/dist/chunks/{chunk-BPSCGGVF.js → chunk-XXGYUYXI.js} +1 -1
  34. package/dist/chunks/{chunk-XO3NM7BB.js → chunk-Y3I2UV5Y.js} +3 -3
  35. package/dist/chunks/{chunk-IZDNZW3S.js → chunk-Z2FKA2ZH.js} +8 -8
  36. package/dist/chunks/chunk-ZPJ3BNQB.js +126 -0
  37. package/dist/chunks/{config-HF2PDLN5.js → config-4EOI5NOU.js} +2 -4
  38. package/dist/chunks/{manager-cli-BYCF4RKN.js → manager-cli-2ATPC47M.js} +35 -5
  39. package/dist/chunks/manager-upgrade-5CPKTRJ7.js +562 -0
  40. package/dist/chunks/{model-registry-7FNIUYPF.js → model-registry-3XAHXXTA.js} +5 -5
  41. package/dist/chunks/{src-OVWRBWKU.js → src-B44QWSGM.js} +4 -4
  42. package/dist/chunks/{src-A5YI46OD.js → src-CLE5ILN4.js} +6 -6
  43. package/dist/chunks/{src-OA3TP6DS.js → src-EGXFJ3WA.js} +5 -5
  44. package/dist/chunks/{src-TF2RAGRU.js → src-Q7LU27C2.js} +3 -3
  45. package/dist/chunks/{test-stream-7YZDGBPO.js → test-stream-OR3EJBNF.js} +3 -3
  46. package/dist/cli.js +173 -136
  47. package/package.json +3 -3
  48. package/dist/chunks/chunk-7KLWHWZD.js +0 -164
@@ -2000,6 +2000,7 @@ function spawnBridgeProcess(port, sessionName) {
2000
2000
  return child;
2001
2001
  }
2002
2002
  function resolveSharedMcpMode() {
2003
+ if (process.env.CHROME_DEVTOOLS_AXI_FRESH === "1") return null;
2003
2004
  const sharedServerUrl = process.env.CHROME_DEVTOOLS_AXI_MCP_SERVER_URL?.trim();
2004
2005
  if (!sharedServerUrl) return null;
2005
2006
  return process.env.CHROME_DEVTOOLS_AXI_MCP_PATH?.trim() ? "proxy" : "direct";
@@ -2112,12 +2113,23 @@ async function ensureBridge(spawnBridge = spawnBridgeProcess, notice) {
2112
2113
  }
2113
2114
  await sleep(500);
2114
2115
  }
2116
+ const failingGeneration = child.pid !== void 0 && childExited === false ? { pid: child.pid, startTime: inspectProcessIdentity(child.pid)?.startTime ?? void 0 } : pidInfo !== null && sawShallowReady ? { pid: pidInfo.pid, startTime: pidInfo.startTime } : void 0;
2117
+ if (failingGeneration) {
2118
+ try {
2119
+ await stopBridge({ expectedGeneration: failingGeneration });
2120
+ } catch {
2121
+ }
2122
+ }
2115
2123
  const seconds = Math.round(timeoutMs / 1e3);
2116
2124
  const sharedMcpMode = resolveSharedMcpMode();
2117
2125
  if (sawShallowReady) {
2126
+ const autoConnectDefault = !(process.env.CHROME_DEVTOOLS_AXI_FRESH === "1" || process.env.CHROME_DEVTOOLS_AXI_AUTO_CONNECT === "0");
2118
2127
  const suggestions2 = sharedMcpMode ? [
2119
2128
  ...sharedMcpSuggestions(sharedMcpMode),
2120
2129
  "The shared MCP service may be reachable while its attached Chrome target is unavailable."
2130
+ ] : autoConnectDefault ? [
2131
+ "DEFAULT mode attaches to YOUR running Chrome (login state included). That requires remote debugging enabled ONCE in Chrome: open chrome://inspect/#remote-debugging and follow the dialog, then re-run. Chrome will ask you to approve each connection.",
2132
+ "For an isolated headless instance instead (no user login state), set CHROME_DEVTOOLS_AXI_FRESH=1."
2121
2133
  ] : [
2122
2134
  "The Chrome/Electron instance the bridge was attached to may have exited.",
2123
2135
  "Verify the target is still listening on its remote-debugging port, then re-run the command.",
@@ -2218,7 +2230,16 @@ function resolveToolArgs(name, args, reconnected) {
2218
2230
  }
2219
2231
  async function callTool(name, args = {}) {
2220
2232
  const notice = { pageIdentityChanged: false };
2221
- const port = await ensureBridge(void 0, notice);
2233
+ let port;
2234
+ try {
2235
+ port = await ensureBridge(void 0, notice);
2236
+ } catch (error) {
2237
+ if (error instanceof CdpError && error.code === "BRIDGE_NOT_READY") {
2238
+ port = await ensureBridge(void 0, notice);
2239
+ } else {
2240
+ throw error;
2241
+ }
2242
+ }
2222
2243
  let resolved = args;
2223
2244
  let newPageCreated = false;
2224
2245
  try {
@@ -2365,16 +2386,23 @@ async function getSessionSnapshotIfRunning() {
2365
2386
  return null;
2366
2387
  }
2367
2388
  }
2368
- async function stopBridge() {
2389
+ async function stopBridge(options = {}) {
2369
2390
  const pidInfo = readPidFile();
2370
2391
  if (!pidInfo) return "noop";
2371
2392
  if (!isProcessAlive(pidInfo.pid)) return "noop";
2393
+ if (options.expectedGeneration && (options.expectedGeneration.pid !== pidInfo.pid || options.expectedGeneration.startTime !== pidInfo.startTime)) {
2394
+ return "noop";
2395
+ }
2372
2396
  const verdict = await judgeRecordedBridge(pidInfo, resolveSessionName());
2373
2397
  if (!verdict.terminate) return "noop";
2374
- const terminated = await terminateBridgeProcess(verdict.targetPid ?? pidInfo.pid, {
2398
+ const targetPid = verdict.targetPid ?? pidInfo.pid;
2399
+ if (options.expectedGeneration && targetPid !== options.expectedGeneration.pid) {
2400
+ return "noop";
2401
+ }
2402
+ const terminated = await terminateBridgeProcess(targetPid, {
2375
2403
  killProcessGroup: verdict.killProcessGroup,
2376
2404
  requireBridgeIdentity: true,
2377
- expectedStartTime: verdict.expectedStartTime
2405
+ expectedStartTime: options.expectedGeneration ? options.expectedGeneration.startTime ?? verdict.expectedStartTime : verdict.expectedStartTime
2378
2406
  });
2379
2407
  clearSelectedPageId();
2380
2408
  return terminated ? "stopped" : "failed";
@@ -4344,7 +4344,7 @@ var init_permissions2 = __esm({
4344
4344
  // vendor/computer-use-axi/src/broker-server.ts
4345
4345
  init_test_backend_guard();
4346
4346
  import { createHash as createHash4, randomUUID as randomUUID8 } from "node:crypto";
4347
- import { chmodSync as chmodSync2, lstatSync as lstatSync4, readFileSync as readFileSync4, unlinkSync as unlinkSync4, writeFileSync as writeFileSync3 } from "node:fs";
4347
+ import { chmodSync as chmodSync2, lstatSync as lstatSync4, readFileSync as readFileSync5, unlinkSync as unlinkSync4, writeFileSync as writeFileSync4 } from "node:fs";
4348
4348
  import net3 from "node:net";
4349
4349
  import path14 from "node:path";
4350
4350
 
@@ -5368,9 +5368,9 @@ function artifactsRoot(env = process.env) {
5368
5368
 
5369
5369
  // vendor/computer-use-axi/src/bridge.ts
5370
5370
  init_test_backend_guard();
5371
- import { spawn as spawn4 } from "node:child_process";
5371
+ import { execFileSync, spawn as spawn4 } from "node:child_process";
5372
5372
  import { randomUUID as randomUUID7 } from "node:crypto";
5373
- import { constants as fsConstants5, mkdtempSync } from "node:fs";
5373
+ import { constants as fsConstants5, mkdirSync as mkdirSync6, mkdtempSync, readFileSync as readFileSync4, rmSync, writeFileSync as writeFileSync3 } from "node:fs";
5374
5374
  import { access as access4 } from "node:fs/promises";
5375
5375
  import net2 from "node:net";
5376
5376
  import os4 from "node:os";
@@ -8195,29 +8195,113 @@ async function waitForExit(child, timeoutMs) {
8195
8195
  child.once("exit", finish);
8196
8196
  });
8197
8197
  }
8198
+ function escapeEre(value) {
8199
+ return value.replace(/[\\^$.|?*+()[{]/g, (ch) => `\\${ch}`);
8200
+ }
8201
+ async function scanProfileHolders(profile) {
8202
+ if (process.platform === "win32") return { kind: "ok", pids: [] };
8203
+ const pattern = `user-data-dir=${escapeEre(profile)}([^a-zA-Z0-9_-]|$)`;
8204
+ return await new Promise((resolve2) => {
8205
+ execFile("pgrep", ["-f", pattern], { timeout: 1500 }, (error, stdout) => {
8206
+ if (!error) {
8207
+ const pids = String(stdout ?? "").split(/\s+/).map(Number).filter((n) => Number.isInteger(n) && n > 0 && n !== process.pid);
8208
+ resolve2({ kind: "ok", pids });
8209
+ return;
8210
+ }
8211
+ const code = error.code;
8212
+ if (code === 1) {
8213
+ resolve2({ kind: "none" });
8214
+ return;
8215
+ }
8216
+ resolve2({ kind: "unknown" });
8217
+ });
8218
+ });
8219
+ }
8220
+ async function verifyProfileHolder(pid, profile) {
8221
+ if (process.platform === "darwin") {
8222
+ return await new Promise((resolve2) => {
8223
+ execFile("ps", ["-o", "command=", "-p", String(pid)], { timeout: 1500 }, (error, stdout) => {
8224
+ if (error) {
8225
+ resolve2(false);
8226
+ return;
8227
+ }
8228
+ const command = String(stdout ?? "").trim();
8229
+ if (!command) {
8230
+ resolve2(false);
8231
+ return;
8232
+ }
8233
+ resolve2(commandIncludesExactUserDataDir(command, profile));
8234
+ });
8235
+ });
8236
+ }
8237
+ return await new Promise((resolve2) => {
8238
+ execFile("cat", [`/proc/${pid}/cmdline`], { timeout: 1500 }, (error, stdout) => {
8239
+ if (error) {
8240
+ resolve2(false);
8241
+ return;
8242
+ }
8243
+ const argv = String(stdout ?? "").split("\0").filter(Boolean);
8244
+ resolve2(argv.some((arg, i) => arg === `--user-data-dir=${profile}` || arg === "--user-data-dir" && argv[i + 1] === profile));
8245
+ });
8246
+ });
8247
+ }
8248
+ function commandIncludesExactUserDataDir(command, profile) {
8249
+ const marker = "--user-data-dir=";
8250
+ let index = command.indexOf(marker);
8251
+ while (index !== -1) {
8252
+ const start = index + marker.length;
8253
+ if (command.startsWith(profile, start)) {
8254
+ const after = start + profile.length;
8255
+ if (after === command.length || /[^a-zA-Z0-9_-]/.test(command[after])) return true;
8256
+ }
8257
+ index = command.indexOf(marker, index + 1);
8258
+ }
8259
+ return false;
8260
+ }
8261
+ async function signalTreeOfProfile(profile, signal) {
8262
+ const scan = await scanProfileHolders(profile);
8263
+ if (scan.kind !== "ok") return scan.kind === "none" ? 0 : -1;
8264
+ let signalled = 0;
8265
+ for (const pid of scan.pids) {
8266
+ if (!await verifyProfileHolder(pid, profile)) continue;
8267
+ try {
8268
+ process.kill(pid, signal);
8269
+ signalled++;
8270
+ } catch {
8271
+ }
8272
+ }
8273
+ if (signalled > 0) await new Promise((resolve2) => setTimeout(resolve2, 150));
8274
+ return signalled;
8275
+ }
8276
+ async function countProfileHolders(profile) {
8277
+ const scan = await scanProfileHolders(profile);
8278
+ if (scan.kind === "none") return 0;
8279
+ if (scan.kind === "unknown") return -1;
8280
+ let count = 0;
8281
+ for (const pid of scan.pids) {
8282
+ if (await verifyProfileHolder(pid, profile)) count++;
8283
+ }
8284
+ return count;
8285
+ }
8198
8286
  async function releaseOwnedBrowser(child, port, profile) {
8199
- if (child && child.exitCode === null && child.signalCode === null) {
8287
+ const mainAlive = () => Boolean(child && child.exitCode === null && child.signalCode === null);
8288
+ if (mainAlive()) {
8200
8289
  if (port) await requestBrowserClose(port).catch(() => void 0);
8201
8290
  if (!await waitForExit(child, 700)) {
8202
8291
  if (process.platform === "win32" && child.pid) {
8203
8292
  const pid = child.pid;
8204
8293
  await new Promise((resolve2) => {
8205
- execFile("taskkill.exe", ["/PID", String(pid), "/T", "/F"], {
8206
- windowsHide: true,
8207
- timeout: 2e3
8208
- }, () => resolve2());
8294
+ execFile("taskkill.exe", ["/PID", String(pid), "/T", "/F"], { windowsHide: true, timeout: 2e3 }, () => resolve2());
8209
8295
  });
8210
8296
  if (!await waitForExit(child, 1500)) {
8211
8297
  try {
8212
8298
  process.kill(pid);
8213
8299
  } catch {
8214
8300
  }
8215
- if (!await waitForExit(child, 2e3)) {
8216
- throw new Error(`Owned browser process ${pid} survived taskkill escalation.`);
8217
- }
8301
+ if (!await waitForExit(child, 2e3)) throw new Error(`Owned browser process ${pid} survived taskkill escalation.`);
8218
8302
  }
8219
- } else child.kill("SIGTERM");
8220
- if (process.platform !== "win32") {
8303
+ } else {
8304
+ child.kill("SIGTERM");
8221
8305
  if (!await waitForExit(child, 2e3)) {
8222
8306
  child.kill("SIGKILL");
8223
8307
  if (!await waitForExit(child, 2e3)) throw new Error("Owned browser did not exit.");
@@ -8225,6 +8309,20 @@ async function releaseOwnedBrowser(child, port, profile) {
8225
8309
  }
8226
8310
  }
8227
8311
  }
8312
+ if (profile && process.platform !== "win32") {
8313
+ await signalTreeOfProfile(profile, "SIGTERM");
8314
+ let holders = await countProfileHolders(profile);
8315
+ if (holders > 0) {
8316
+ await signalTreeOfProfile(profile, "SIGKILL");
8317
+ holders = await countProfileHolders(profile);
8318
+ }
8319
+ if (holders > 0) {
8320
+ throw new Error(`Owned browser helpers survived SIGKILL (${holders} pids hold ${profile}); refusing to remove the profile while processes may still write it.`);
8321
+ }
8322
+ if (holders < 0) {
8323
+ throw new Error(`Cannot verify that no process holds ${profile} (process scan unavailable); refusing to remove the profile.`);
8324
+ }
8325
+ }
8228
8326
  if (profile) {
8229
8327
  const resolved = path12.resolve(profile);
8230
8328
  if (path12.dirname(resolved) !== path12.resolve(os3.tmpdir()) || !/^pie-(chrome|helium)-cdp-/.test(path12.basename(resolved))) {
@@ -8237,6 +8335,7 @@ async function releaseOwnedBrowserState(owner) {
8237
8335
  await releaseOwnedBrowser(owner.managedBrowser, owner.managedBrowserCdpPort, owner.managedBrowserProfileDir);
8238
8336
  owner.managedBrowser = void 0;
8239
8337
  owner.managedBrowserProfileDir = void 0;
8338
+ owner.managedBrowserPid = void 0;
8240
8339
  }
8241
8340
 
8242
8341
  // vendor/computer-use-axi/src/root-selection.ts
@@ -8543,6 +8642,102 @@ function expireStateForArtifactEviction(stateId2) {
8543
8642
  }
8544
8643
  function persistRuntimeBridgeState() {
8545
8644
  }
8645
+ function managedBrowserManifestPath() {
8646
+ return path13.join(stateRootDir(process.env), "managed-browser.json");
8647
+ }
8648
+ function writeManagedBrowserManifest(entry) {
8649
+ try {
8650
+ if (!entry) {
8651
+ rmSync(managedBrowserManifestPath(), { force: true });
8652
+ return;
8653
+ }
8654
+ mkdirSync6(stateRootDir(process.env), { recursive: true });
8655
+ writeFileSync3(managedBrowserManifestPath(), JSON.stringify({ ...entry, startedAt: Date.now() }), { encoding: "utf8" });
8656
+ } catch {
8657
+ }
8658
+ }
8659
+ function clearManagedBrowserManifest() {
8660
+ writeManagedBrowserManifest(void 0);
8661
+ }
8662
+ function killManagedBrowserFast() {
8663
+ try {
8664
+ const pid = runtimeState.managedBrowserPid;
8665
+ if (pid !== void 0) {
8666
+ try {
8667
+ process.kill(pid, "SIGKILL");
8668
+ } catch {
8669
+ }
8670
+ }
8671
+ const profile = runtimeState.managedBrowserProfileDir;
8672
+ if (profile) {
8673
+ try {
8674
+ const out = execFileSync("pgrep", ["-f", `user-data-dir=${escapeEre(profile)}([^a-zA-Z0-9_-]|$)`], { timeout: 1500, killSignal: "SIGKILL", stdio: ["ignore", "pipe", "ignore"] });
8675
+ for (const pidText of String(out).split(/\s+/)) {
8676
+ const pid2 = Number(pidText);
8677
+ if (Number.isInteger(pid2) && pid2 > 0 && pid2 !== process.pid) {
8678
+ try {
8679
+ process.kill(pid2, "SIGKILL");
8680
+ } catch {
8681
+ }
8682
+ }
8683
+ }
8684
+ } catch {
8685
+ }
8686
+ }
8687
+ } catch {
8688
+ }
8689
+ }
8690
+ function processAlive(pid) {
8691
+ try {
8692
+ process.kill(pid, 0);
8693
+ return true;
8694
+ } catch (error) {
8695
+ return error.code === "EPERM";
8696
+ }
8697
+ }
8698
+ async function manifestPidIsOurBrowser(pid, profileDir) {
8699
+ if (pid === void 0 || !processAlive(pid)) return false;
8700
+ return await verifyProfileHolder(pid, profileDir);
8701
+ }
8702
+ async function sweepOrphanedManagedBrowser() {
8703
+ let manifest;
8704
+ try {
8705
+ manifest = JSON.parse(readFileSync4(managedBrowserManifestPath(), "utf8"));
8706
+ } catch {
8707
+ clearManagedBrowserManifest();
8708
+ return;
8709
+ }
8710
+ const profileDir = typeof manifest.profileDir === "string" ? manifest.profileDir : void 0;
8711
+ const port = typeof manifest.port === "string" ? manifest.port : void 0;
8712
+ const pid = typeof manifest.pid === "number" ? manifest.pid : void 0;
8713
+ if (!profileDir) {
8714
+ clearManagedBrowserManifest();
8715
+ return;
8716
+ }
8717
+ const resolved = path13.resolve(profileDir);
8718
+ const tmp = path13.resolve(os4.tmpdir());
8719
+ if (path13.dirname(resolved) !== tmp || !/^pie-(chrome|helium)-cdp-/.test(path13.basename(resolved))) {
8720
+ clearManagedBrowserManifest();
8721
+ return;
8722
+ }
8723
+ if (port) await requestBrowserClose(port).catch(() => void 0);
8724
+ if (pid !== void 0 && await manifestPidIsOurBrowser(pid, resolved)) {
8725
+ try {
8726
+ process.kill(pid, "SIGTERM");
8727
+ } catch {
8728
+ }
8729
+ await new Promise((resolve2) => setTimeout(resolve2, 400));
8730
+ if (processAlive(pid)) {
8731
+ try {
8732
+ process.kill(pid, "SIGKILL");
8733
+ } catch {
8734
+ }
8735
+ await new Promise((resolve2) => setTimeout(resolve2, 300));
8736
+ }
8737
+ }
8738
+ await releaseOwnedBrowser(void 0, void 0, resolved);
8739
+ clearManagedBrowserManifest();
8740
+ }
8546
8741
  function operationState() {
8547
8742
  return savedStates.current();
8548
8743
  }
@@ -8579,6 +8774,8 @@ async function releaseComputerUseSession() {
8579
8774
  runtimeState.previousCdpPort = void 0;
8580
8775
  if (runtimeState.managedBrowser === void 0) {
8581
8776
  runtimeState.managedBrowserCdpPort = void 0;
8777
+ runtimeState.managedBrowserPid = void 0;
8778
+ clearManagedBrowserManifest();
8582
8779
  }
8583
8780
  savedStates.clear();
8584
8781
  clearStoredOutputs();
@@ -10259,17 +10456,11 @@ async function performLaunchBrowser(params, signal) {
10259
10456
  ];
10260
10457
  const managedBrowser = spawn4(executable, args, { stdio: "ignore", detached: true });
10261
10458
  managedBrowser.unref();
10262
- const stalePid = runtimeState.managedBrowserPid;
10263
- if (stalePid !== void 0 && stalePid !== managedBrowser.pid) {
10264
- try {
10265
- process.kill(stalePid, "SIGTERM");
10266
- } catch {
10267
- }
10268
- }
10269
10459
  runtimeState.managedBrowser = managedBrowser;
10270
10460
  runtimeState.managedBrowserCdpPort = String(port);
10271
10461
  runtimeState.managedBrowserPid = managedBrowser.pid;
10272
10462
  runtimeState.managedBrowserProfileDir = profileDir;
10463
+ writeManagedBrowserManifest({ pid: managedBrowser.pid, port: String(port), profileDir });
10273
10464
  persistRuntimeBridgeState();
10274
10465
  setManagedCdpPort(String(port));
10275
10466
  try {
@@ -10280,6 +10471,7 @@ async function performLaunchBrowser(params, signal) {
10280
10471
  setManagedCdpPort(void 0);
10281
10472
  runtimeState.managedBrowserCdpPort = void 0;
10282
10473
  runtimeState.previousCdpPort = void 0;
10474
+ clearManagedBrowserManifest();
10283
10475
  }
10284
10476
  throw error;
10285
10477
  }
@@ -10314,6 +10506,7 @@ async function performEvaluateBrowser(params) {
10314
10506
  const result = await cdpEvaluateForContext(contextId, expression);
10315
10507
  if (!result) throw new Error(`Browser context '${contextId}' is no longer available. Observe it again.`);
10316
10508
  const successor = await refreshBrowserSnapshot(contextId, "evaluate_browser", { stateId: baseSnapshot.snapshotId, outline: baseSnapshot.outline });
10509
+ if (!successor.details) throw new Error("Browser refresh produced no observation details.");
10317
10510
  const details = {
10318
10511
  tool: "evaluate_browser",
10319
10512
  baseStateId: baseSnapshot.snapshotId,
@@ -10432,7 +10625,7 @@ function acquireBootstrapLock(directory) {
10432
10625
  const lockPath = path14.join(directory, "broker.lock");
10433
10626
  for (let attempt = 0; attempt < 100; attempt += 1) {
10434
10627
  try {
10435
- writeFileSync3(lockPath, String(process.pid), { flag: "wx", mode: 384 });
10628
+ writeFileSync4(lockPath, String(process.pid), { flag: "wx", mode: 384 });
10436
10629
  return () => {
10437
10630
  try {
10438
10631
  unlinkSync4(lockPath);
@@ -10443,7 +10636,7 @@ function acquireBootstrapLock(directory) {
10443
10636
  if (error.code !== "EEXIST") throw error;
10444
10637
  let ownerPid = 0;
10445
10638
  try {
10446
- ownerPid = Number.parseInt(readFileSync4(lockPath, "utf8").trim(), 10);
10639
+ ownerPid = Number.parseInt(readFileSync5(lockPath, "utf8").trim(), 10);
10447
10640
  } catch {
10448
10641
  }
10449
10642
  if (Number.isInteger(ownerPid) && ownerPid > 0 && isAlive(ownerPid)) {
@@ -10997,6 +11190,10 @@ async function startBroker(options = {}) {
10997
11190
  artifacts.cleanupOtherGenerations(generation);
10998
11191
  } catch {
10999
11192
  }
11193
+ try {
11194
+ await sweepOrphanedManagedBrowser();
11195
+ } catch {
11196
+ }
11000
11197
  configureEngineRuntime({
11001
11198
  generation,
11002
11199
  helperGeneration: helperGeneration2,
@@ -11152,6 +11349,7 @@ async function main() {
11152
11349
  process.on("uncaughtException", (error) => {
11153
11350
  process.stderr.write(`computer-use-axi broker fatal: ${error instanceof Error ? error.stack ?? error.message : String(error)}
11154
11351
  `);
11352
+ killManagedBrowserFast();
11155
11353
  process.exit(1);
11156
11354
  });
11157
11355
  process.on("unhandledRejection", (reason) => {
@@ -3,9 +3,9 @@ import {
3
3
  AuthStorage,
4
4
  FileAuthStorageBackend,
5
5
  InMemoryAuthStorageBackend
6
- } from "./chunk-OV7SLSHR.js";
7
- import "./chunk-UCKOXAME.js";
8
- import "./chunk-RZGYXAJU.js";
6
+ } from "./chunk-SW2E33UL.js";
7
+ import "./chunk-CBDQJMUI.js";
8
+ import "./chunk-LZQXQOPJ.js";
9
9
  export {
10
10
  AuthStorage,
11
11
  FileAuthStorageBackend,