@cydm/pie 4.12.0 → 4.12.2

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.
@@ -3,7 +3,7 @@ import {
3
3
  isWindowsServiceManager,
4
4
  launchWindowsServiceUpgradeActor,
5
5
  resolveAbsoluteActorEnv
6
- } from "../../../chunks/chunk-6U6UGM4C.js";
6
+ } from "../../../chunks/chunk-Y6AVNVOD.js";
7
7
  import {
8
8
  DISPATCH_PREFIX,
9
9
  IPC_PROTOCOL_VERSION,
@@ -26,12 +26,12 @@ import {
26
26
  } from "../../../chunks/chunk-F7EBZTZO.js";
27
27
  import {
28
28
  liveSessionHolder
29
- } from "../../../chunks/chunk-322WLBDY.js";
29
+ } from "../../../chunks/chunk-Q5PSWX3B.js";
30
30
  import {
31
31
  claimOwnership,
32
- pidDefinitelyDead,
32
+ isPositivelyDeadHolder,
33
33
  readOwnership
34
- } from "../../../chunks/chunk-BSITHT43.js";
34
+ } from "../../../chunks/chunk-Q4NJEPIZ.js";
35
35
  import {
36
36
  loadResolvedModelsConfig
37
37
  } from "../../../chunks/chunk-IZ4DYCJ7.js";
@@ -1232,7 +1232,7 @@ function readLock(binding) {
1232
1232
  return readOwnership(lockPath(binding), (v) => v.binding === binding);
1233
1233
  }
1234
1234
  function lockAlive(info, _now = Date.now()) {
1235
- return !!info && !pidDefinitelyDead(info.pid);
1235
+ return !!info && !isPositivelyDeadHolder(info.pid, info.heartbeatAt);
1236
1236
  }
1237
1237
  function tryClaimConsumer(binding, holder, onLost, shouldYield) {
1238
1238
  try {
@@ -1737,12 +1737,7 @@ function liveManagerForBinding(binding) {
1737
1737
  try {
1738
1738
  const peer = JSON.parse(fs5.readFileSync(pathJoin(ipcDiscoveryRoot(), file), "utf8"));
1739
1739
  if (peer.pid === process.pid || peer.isManager !== true || peer.imBinding !== binding || !Number.isInteger(peer.pid) || !peer.pid || peer.pid <= 0) continue;
1740
- try {
1741
- process.kill(peer.pid, 0);
1742
- return true;
1743
- } catch (error) {
1744
- if (error.code !== "ESRCH") return true;
1745
- }
1740
+ if (!isPositivelyDeadHolder(peer.pid, typeof peer.startedAt === "number" ? peer.startedAt : void 0)) return true;
1746
1741
  } catch {
1747
1742
  }
1748
1743
  }
@@ -3183,9 +3178,17 @@ function connect(binary, profile, targetKind = "chat", settings = { targetId: ""
3183
3178
  /permission/i,
3184
3179
  /connect|network|dns|timeout/i
3185
3180
  ];
3181
+ let botIdentityRetryTimer;
3182
+ const clearBotIdentityRetry = () => {
3183
+ if (botIdentityRetryTimer) {
3184
+ clearTimeout(botIdentityRetryTimer);
3185
+ botIdentityRetryTimer = void 0;
3186
+ }
3187
+ };
3186
3188
  const fail = (reason) => {
3187
3189
  if (!failed && !stopped) {
3188
3190
  failed = true;
3191
+ clearBotIdentityRetry();
3189
3192
  callbacks.failure(lastErrorLine ? `${reason} \u2014 ${lastErrorLine}` : reason);
3190
3193
  }
3191
3194
  };
@@ -3203,19 +3206,40 @@ function connect(binary, profile, targetKind = "chat", settings = { targetId: ""
3203
3206
  }
3204
3207
  };
3205
3208
  const botIdentity = { openId: void 0, attempts: 0, pending: void 0, nextAttemptAt: 0 };
3209
+ const scheduleBotIdentityRetry = (delayMs) => {
3210
+ if (stopped || closed || failed || botIdentity.openId || botIdentityRetryTimer) return;
3211
+ botIdentityRetryTimer = setTimeout(() => {
3212
+ botIdentityRetryTimer = void 0;
3213
+ if (stopped || closed || failed || botIdentity.openId) return;
3214
+ void resolveBotIdentity();
3215
+ }, delayMs);
3216
+ botIdentityRetryTimer.unref?.();
3217
+ };
3206
3218
  const resolveBotIdentity = () => {
3207
3219
  if (botIdentity.openId) return Promise.resolve();
3208
3220
  if (botIdentity.pending) return botIdentity.pending;
3209
3221
  const now = Date.now();
3210
- if (now < botIdentity.nextAttemptAt) return Promise.resolve();
3211
- botIdentity.nextAttemptAt = now + Math.min(5e3 * 2 ** botIdentity.attempts, 6e5);
3222
+ if (now < botIdentity.nextAttemptAt) {
3223
+ scheduleBotIdentityRetry(Math.max(100, botIdentity.nextAttemptAt - now));
3224
+ return Promise.resolve();
3225
+ }
3226
+ const backoffMs = Math.min(5e3 * 2 ** botIdentity.attempts, 6e4);
3227
+ botIdentity.nextAttemptAt = now + backoffMs;
3212
3228
  botIdentity.attempts += 1;
3229
+ clearBotIdentityRetry();
3213
3230
  const req = call(["api", "GET", "/open-apis/bot/v3/info", "--as", "bot"]).then((info) => {
3214
3231
  if (typeof info?.open_id === "string") {
3215
3232
  botIdentity.openId = info.open_id;
3216
3233
  botIdentity.attempts = 0;
3217
- } else console.warn(`[im-forward] bot identity lookup returned no open_id (attempt ${botIdentity.attempts}); group gating stays UNCLASSIFIED \u2014 new group conversations are refused until the identity resolves`);
3218
- }).catch(() => console.warn(`[im-forward] bot identity lookup failed (attempt ${botIdentity.attempts}); group gating stays UNCLASSIFIED \u2014 new group conversations are refused until the identity resolves`)).finally(() => {
3234
+ clearBotIdentityRetry();
3235
+ } else {
3236
+ console.warn(`[im-forward] bot identity lookup returned no open_id (attempt ${botIdentity.attempts}); group gating stays UNCLASSIFIED \u2014 retrying in ${Math.round(backoffMs / 1e3)}s`);
3237
+ scheduleBotIdentityRetry(backoffMs);
3238
+ }
3239
+ }).catch(() => {
3240
+ console.warn(`[im-forward] bot identity lookup failed (attempt ${botIdentity.attempts}); group gating stays UNCLASSIFIED \u2014 retrying in ${Math.round(backoffMs / 1e3)}s`);
3241
+ scheduleBotIdentityRetry(backoffMs);
3242
+ }).finally(() => {
3219
3243
  botIdentity.pending = void 0;
3220
3244
  });
3221
3245
  botIdentity.pending = req;
@@ -3272,6 +3296,7 @@ function connect(binary, profile, targetKind = "chat", settings = { targetId: ""
3272
3296
  }
3273
3297
  return { async stop() {
3274
3298
  stopped = true;
3299
+ clearBotIdentityRetry();
3275
3300
  for (const timer of optionalRespawnTimers.values()) clearTimeout(timer);
3276
3301
  optionalRespawnTimers.clear();
3277
3302
  await Promise.allSettled([...children].map((child2) => shutdownConsumer(child2)));
@@ -15,8 +15,8 @@ import {
15
15
  } from "../../../chunks/chunk-7RJXKN7N.js";
16
16
  import {
17
17
  liveSessionHolder
18
- } from "../../../chunks/chunk-322WLBDY.js";
19
- import "../../../chunks/chunk-BSITHT43.js";
18
+ } from "../../../chunks/chunk-Q5PSWX3B.js";
19
+ import "../../../chunks/chunk-Q4NJEPIZ.js";
20
20
  import {
21
21
  loadResolvedModelsConfig
22
22
  } from "../../../chunks/chunk-IZ4DYCJ7.js";
@@ -17,14 +17,23 @@ when stopped or idle.
17
17
  inherited attach/profile env). Always call `stop` on your named session once
18
18
  the task finishes so the background Chrome exits immediately instead of
19
19
  waiting for the 10-minute idle timeout.
20
+ - **Dedicated persistent Agent Profile (recommended whenever recurring login
21
+ state is needed)** → set `CHROME_DEVTOOLS_AXI_PROFILE=<name>` (stored under
22
+ `~/.chrome-devtools-axi/profiles/<name>`, or pass an explicit
23
+ `CHROME_DEVTOOLS_AXI_USER_DATA_DIR=<dir>`). Log in once visibly with
24
+ `CHROME_DEVTOOLS_AXI_PROFILE=<name> CHROME_DEVTOOLS_AXI_HEADED=1`, run
25
+ `stop`, and then reuse `CHROME_DEVTOOLS_AXI_PROFILE=<name>` headless in the
26
+ background with **zero remote-debugging approval dialogs**, **zero Dock/focus
27
+ disturbance**, and without touching the user's personal Chrome.
20
28
  - **Visible isolated browser** (e.g. user asked "打开页面给我看" without
21
29
  needing their personal login) → `CHROME_DEVTOOLS_AXI_HEADED=1`.
22
- - **User's running Chrome (explicit opt-in ONLY when personal login state /
23
- existing tabs are genuinely required)** → `CHROME_DEVTOOLS_AXI_AUTO_CONNECT=1`
24
- (or `CHROME_DEVTOOLS_AXI_ATTACH=1`). Requires the one-time
25
- `chrome://inspect/#remote-debugging` enable and triggers Chrome's "Allow
26
- remote debugging?" dialog; use a dedicated `CHROME_DEVTOOLS_AXI_SESSION` so
27
- it never collides with background headless sessions.
30
+ - **User's running Chrome (explicit opt-in ONLY when personal Chrome's existing
31
+ tabs / already-open session are strictly required)** →
32
+ `CHROME_DEVTOOLS_AXI_AUTO_CONNECT=1` (or `CHROME_DEVTOOLS_AXI_ATTACH=1`).
33
+ Requires the one-time `chrome://inspect/#remote-debugging` enable and
34
+ triggers Chrome's "Allow remote debugging?" dialog; use a dedicated
35
+ `CHROME_DEVTOOLS_AXI_SESSION` so it never collides with background headless
36
+ sessions.
28
37
  - **Explicit external endpoint** → `CHROME_DEVTOOLS_AXI_BROWSER_URL`
29
38
  (`http(s)://` or `ws(s)://`).
30
39
  - **Native desktop apps / non-browser windows** → use `computer-use-axi`
@@ -2,7 +2,10 @@
2
2
  import { createRequire as __axiRequire } from "node:module"; const require = __axiRequire(import.meta.url);
3
3
  import {
4
4
  BRIDGE_PORT_IN_USE_EXIT_CODE,
5
+ BRIDGE_PROFILE_IN_USE_EXIT_CODE,
6
+ CHROME_GENERATION_FLAG_PREFIX,
5
7
  PAGE_IDENTITY_CHANGED_ERROR,
8
+ acquirePersistentProfileLease,
6
9
  allocateOwnedProfileDir,
7
10
  cleanupOwnedProfileDir,
8
11
  clearSelectedPageId,
@@ -11,16 +14,23 @@ import {
11
14
  isAttachTransportMode,
12
15
  isAutoConnectMode,
13
16
  isManagedIsolatedMode,
17
+ isPersistentProfileLeaseOwnedBy,
14
18
  isSupervisorGone,
15
19
  parseSupervisorAnchor,
20
+ preflightPersistentProfile,
21
+ pruneStaleSessionDirs,
16
22
  readSelfStartTime,
23
+ reapPersistentProfileForDeadOwner,
17
24
  reapStaleOwnedProfiles,
25
+ releasePersistentProfileLease,
26
+ resolvePersistentProfileDir,
18
27
  resolveSessionLogFile,
19
28
  resolveSessionName,
20
29
  resolveSessionPidFile,
21
30
  resolveSessionPort,
22
- resolveSessionStateDir
23
- } from "./chunk-HAUDUMDO.js";
31
+ resolveSessionStateDir,
32
+ terminateProfileHolders
33
+ } from "./chunk-NL3FSRAW.js";
24
34
  import {
25
35
  __commonJS,
26
36
  __export,
@@ -19619,7 +19629,8 @@ function writePidFile(port, meta2 = {}) {
19619
19629
  port,
19620
19630
  startTime: readSelfStartTime(),
19621
19631
  ...meta2.mode ? { mode: meta2.mode } : {},
19622
- ...meta2.ownedProfileDir ? { ownedProfileDir: meta2.ownedProfileDir } : {}
19632
+ ...meta2.ownedProfileDir ? { ownedProfileDir: meta2.ownedProfileDir } : {},
19633
+ ...meta2.persistentProfileDir ? { persistentProfileDir: meta2.persistentProfileDir } : {}
19623
19634
  })
19624
19635
  );
19625
19636
  }
@@ -20005,9 +20016,14 @@ function parseLauncherHeader(value) {
20005
20016
  const startTime = colon === -1 ? void 0 : raw.slice(colon + 1);
20006
20017
  return startTime ? { pid, startTime } : { pid };
20007
20018
  }
20019
+ var DEFAULT_DISCONNECTED_IDLE_SHUTDOWN_MS = 2 * 6e4;
20008
20020
  function createBridgeLifecycle(shutdown, opts = {}) {
20009
20021
  const heartbeatMs = opts.heartbeatMs ?? DEFAULT_HEARTBEAT_MS;
20010
20022
  const idleShutdownMs = opts.idleShutdownMs ?? DEFAULT_IDLE_SHUTDOWN_MS;
20023
+ const disconnectedIdleShutdownMs = Math.min(
20024
+ idleShutdownMs,
20025
+ opts.disconnectedIdleShutdownMs ?? DEFAULT_DISCONNECTED_IDLE_SHUTDOWN_MS
20026
+ );
20011
20027
  const now = opts.now ?? Date.now;
20012
20028
  const suspendIdleWhileSupervisorAlive = opts.suspendIdleWhileSupervisorAlive ?? true;
20013
20029
  let supervisor;
@@ -20035,9 +20051,14 @@ function createBridgeLifecycle(shutdown, opts = {}) {
20035
20051
  fire(`supervisor pid ${supervisor.pid} is gone and no requests since; shutting down`);
20036
20052
  return;
20037
20053
  }
20038
- const supervisorSuspendsIdle = Boolean(supervisor) && suspendIdleWhileSupervisorAlive;
20039
- if (!supervisorSuspendsIdle && inFlightRequests === 0 && t - lastRequestAt >= idleShutdownMs) {
20040
- fire(`idle ${Math.round((t - lastRequestAt) / 1e3)}s \u2265 ${Math.round(idleShutdownMs / 1e3)}s with no requests; shutting down`);
20054
+ const suspendIdle = typeof suspendIdleWhileSupervisorAlive === "function" ? suspendIdleWhileSupervisorAlive() : suspendIdleWhileSupervisorAlive;
20055
+ const disconnected = Boolean(opts.isDisconnected?.());
20056
+ const effectiveIdleMs = disconnected ? disconnectedIdleShutdownMs : idleShutdownMs;
20057
+ const supervisorSuspendsIdle = Boolean(supervisor) && suspendIdle && !disconnected;
20058
+ if (!supervisorSuspendsIdle && inFlightRequests === 0 && t - lastRequestAt >= effectiveIdleMs) {
20059
+ fire(
20060
+ disconnected ? `CDP disconnected and idle ${Math.round((t - lastRequestAt) / 1e3)}s \u2265 ${Math.round(effectiveIdleMs / 1e3)}s; shutting down` : `idle ${Math.round((t - lastRequestAt) / 1e3)}s \u2265 ${Math.round(idleShutdownMs / 1e3)}s with no requests; shutting down`
20061
+ );
20041
20062
  return;
20042
20063
  }
20043
20064
  };
@@ -20089,7 +20110,7 @@ function buildTransportArgs(opts = {}) {
20089
20110
  const args = ["-y", "chrome-devtools-mcp@1.13.0"];
20090
20111
  const freshInstance = process.env.CHROME_DEVTOOLS_AXI_FRESH === "1";
20091
20112
  const browserUrl = process.env.CHROME_DEVTOOLS_AXI_BROWSER_URL?.trim();
20092
- const userDataDir = process.env.CHROME_DEVTOOLS_AXI_USER_DATA_DIR?.trim();
20113
+ const persistentProfileDir = resolvePersistentProfileDir();
20093
20114
  const channel = process.env.CHROME_DEVTOOLS_AXI_CHANNEL?.trim();
20094
20115
  const autoConnect = !freshInstance && (process.env.CHROME_DEVTOOLS_AXI_AUTO_CONNECT === "1" || process.env.CHROME_DEVTOOLS_AXI_ATTACH === "1");
20095
20116
  if (autoConnect) {
@@ -20129,8 +20150,11 @@ function buildTransportArgs(opts = {}) {
20129
20150
  args.push(`--browserUrl=${browserUrl}`);
20130
20151
  }
20131
20152
  } else {
20132
- if (userDataDir) {
20133
- args.push(`--userDataDir=${userDataDir}`);
20153
+ if (persistentProfileDir) {
20154
+ args.push(`--userDataDir=${persistentProfileDir}`);
20155
+ if (opts.persistentGenToken) {
20156
+ args.push(`--chrome-arg=${CHROME_GENERATION_FLAG_PREFIX}${opts.persistentGenToken}`);
20157
+ }
20134
20158
  } else if (opts.ownedProfileDir) {
20135
20159
  args.push(`--userDataDir=${opts.ownedProfileDir}`);
20136
20160
  } else {
@@ -20490,9 +20514,82 @@ async function runBridge(port = resolveSessionPort()) {
20490
20514
  const attachMode = isAttachTransportMode();
20491
20515
  const autoConnect = isAutoConnectMode();
20492
20516
  const managedIsolated = isManagedIsolatedMode();
20517
+ const persistentProfileDir = resolvePersistentProfileDir();
20493
20518
  const modeFingerprint = computeTransportModeFingerprint();
20519
+ const selfOwner = { pid: process.pid, startTime: readSelfStartTime() };
20494
20520
  void reapStaleOwnedProfiles(sessionStateDir, process.pid).catch(() => {
20495
20521
  });
20522
+ try {
20523
+ pruneStaleSessionDirs({ excludeSession: sessionName });
20524
+ } catch {
20525
+ }
20526
+ let persistentProfileLeaseToken;
20527
+ let persistentGenToken;
20528
+ let launchedPersistentBrowser = false;
20529
+ if (persistentProfileDir) {
20530
+ mkdirSync(persistentProfileDir, { recursive: true, mode: 448 });
20531
+ let lease = acquirePersistentProfileLease(
20532
+ persistentProfileDir,
20533
+ sessionName,
20534
+ process.pid
20535
+ );
20536
+ if (!lease.acquired && lease.recoveryRequired) {
20537
+ const recovered = await reapPersistentProfileForDeadOwner(
20538
+ persistentProfileDir,
20539
+ lease.recoveryRequired
20540
+ );
20541
+ if (recovered.status === "reaped" || recovered.status === "not_owned") {
20542
+ lease = acquirePersistentProfileLease(
20543
+ persistentProfileDir,
20544
+ sessionName,
20545
+ process.pid
20546
+ );
20547
+ } else if (recovered.status === "busy") {
20548
+ logBridgeMessage(
20549
+ `Persistent profile "${persistentProfileDir}" is currently being recovered by another session`
20550
+ );
20551
+ process.exit(BRIDGE_PROFILE_IN_USE_EXIT_CODE);
20552
+ } else {
20553
+ logBridgeMessage(
20554
+ `Failed to recover stale persistent profile "${persistentProfileDir}" from dead session "${lease.recoveryRequired.sessionName}" (remaining=${recovered.remainingPids.join(",") || "unknown"})`
20555
+ );
20556
+ process.exit(1);
20557
+ }
20558
+ }
20559
+ if (!lease.acquired) {
20560
+ logBridgeMessage(
20561
+ `Persistent profile "${persistentProfileDir}" is already leased by session "${lease.conflictSession ?? "unknown"}" (pid ${lease.conflictPid ?? "unknown"})`
20562
+ );
20563
+ process.exit(BRIDGE_PROFILE_IN_USE_EXIT_CODE);
20564
+ }
20565
+ persistentProfileLeaseToken = lease.token;
20566
+ persistentGenToken = lease.genToken;
20567
+ const preflight = await preflightPersistentProfile(persistentProfileDir);
20568
+ if (preflight.kind === "in_use") {
20569
+ releasePersistentProfileLease(persistentProfileDir, {
20570
+ ...selfOwner,
20571
+ token: persistentProfileLeaseToken
20572
+ });
20573
+ persistentProfileLeaseToken = void 0;
20574
+ persistentGenToken = void 0;
20575
+ logBridgeMessage(
20576
+ `Persistent profile "${persistentProfileDir}" is already in use by Chrome process(es): ${preflight.pids.join(", ")}`
20577
+ );
20578
+ process.exit(BRIDGE_PROFILE_IN_USE_EXIT_CODE);
20579
+ }
20580
+ if (preflight.kind === "unknown") {
20581
+ releasePersistentProfileLease(persistentProfileDir, {
20582
+ ...selfOwner,
20583
+ token: persistentProfileLeaseToken
20584
+ });
20585
+ persistentProfileLeaseToken = void 0;
20586
+ persistentGenToken = void 0;
20587
+ logBridgeMessage(
20588
+ `Refusing persistent profile "${persistentProfileDir}" startup because process scan failed closed (${preflight.reason})`
20589
+ );
20590
+ process.exit(1);
20591
+ }
20592
+ }
20496
20593
  const ownedProfile = managedIsolated ? allocateOwnedProfileDir(sessionStateDir, process.pid) : void 0;
20497
20594
  let keepalive;
20498
20595
  let lifecycle;
@@ -20530,6 +20627,35 @@ async function runBridge(port = resolveSessionPort()) {
20530
20627
  );
20531
20628
  if (finalExitCode === 0) finalExitCode = 1;
20532
20629
  }
20630
+ } else if (persistentProfileDir && persistentProfileLeaseToken) {
20631
+ const tokenOwner = { ...selfOwner, token: persistentProfileLeaseToken };
20632
+ if (!launchedPersistentBrowser || !persistentGenToken) {
20633
+ cleanupConfirmed = releasePersistentProfileLease(persistentProfileDir, tokenOwner);
20634
+ if (cleanupConfirmed) persistentProfileLeaseToken = void 0;
20635
+ } else if (isPersistentProfileLeaseOwnedBy(persistentProfileDir, tokenOwner)) {
20636
+ const reaped = await terminateProfileHolders(persistentProfileDir, {
20637
+ generationToken: persistentGenToken
20638
+ }).catch(() => ({ clean: false, remainingPids: [] }));
20639
+ if (reaped.clean) {
20640
+ cleanupConfirmed = releasePersistentProfileLease(persistentProfileDir, tokenOwner);
20641
+ if (cleanupConfirmed) {
20642
+ persistentProfileLeaseToken = void 0;
20643
+ } else {
20644
+ logBridgeMessage(
20645
+ `Persistent profile lease release failed for ${persistentProfileDir}`
20646
+ );
20647
+ if (finalExitCode === 0) finalExitCode = 1;
20648
+ }
20649
+ } else {
20650
+ cleanupConfirmed = false;
20651
+ logBridgeMessage(
20652
+ `Persistent profile Chrome cleanup incomplete for ${persistentProfileDir} (remaining=${reaped.remainingPids.join(",") || "unknown"})`
20653
+ );
20654
+ if (finalExitCode === 0) finalExitCode = 1;
20655
+ }
20656
+ } else {
20657
+ cleanupConfirmed = true;
20658
+ }
20533
20659
  } else {
20534
20660
  cleanupConfirmed = true;
20535
20661
  }
@@ -20554,12 +20680,32 @@ async function runBridge(port = resolveSessionPort()) {
20554
20680
  try {
20555
20681
  const selection = resolveTransport(
20556
20682
  DEFAULT_MCP_PATH_PROBE,
20557
- ownedProfile ? { ownedProfileDir: ownedProfile.profileDir } : {}
20683
+ {
20684
+ ...ownedProfile ? { ownedProfileDir: ownedProfile.profileDir } : {},
20685
+ ...persistentGenToken ? { persistentGenToken } : {}
20686
+ }
20558
20687
  );
20688
+ if (persistentProfileDir) {
20689
+ launchedPersistentBrowser = true;
20690
+ }
20559
20691
  bridgeTransport = createTransport(selection);
20560
20692
  const client = createBridgeClient();
20561
20693
  const bridgeClient = createRootsAwareBridgeClient(client, { autoConnect });
20562
20694
  await client.connect(bridgeTransport.transport);
20695
+ if (shuttingDown) {
20696
+ return;
20697
+ }
20698
+ if (selection.kind === "stdio") {
20699
+ const prevOnClose = bridgeTransport.transport.onclose;
20700
+ bridgeTransport.transport.onclose = () => {
20701
+ prevOnClose?.();
20702
+ if (!shuttingDown) {
20703
+ bridgeClient.markDisconnected?.("MCP transport closed");
20704
+ logBridgeMessage("MCP stdio transport closed unexpectedly; shutting down");
20705
+ void shutdown(1);
20706
+ }
20707
+ };
20708
+ }
20563
20709
  logBridgeMessage(`Connected to chrome-devtools-mcp (mode=${modeFingerprint})`);
20564
20710
  const pendingDroppedSelectionLatch = { value: false };
20565
20711
  if (attachMode) {
@@ -20591,15 +20737,17 @@ async function runBridge(port = resolveSessionPort()) {
20591
20737
  modeFingerprint
20592
20738
  );
20593
20739
  const supervisorAnchor = parseSupervisorAnchor2();
20594
- const suspendIdleWhileSupervisorAlive = attachMode;
20740
+ const suspendIdleWhileSupervisorAlive = attachMode ? () => bridgeClient.getStatus?.().cdpState === "connected" : false;
20741
+ const isDisconnected = attachMode ? () => bridgeClient.getStatus?.().cdpState === "failed" : void 0;
20595
20742
  const idleShutdownMs = resolveIdleShutdownMs(attachMode);
20596
20743
  lifecycle = createBridgeLifecycle(() => shutdown(0), {
20597
20744
  anchor: supervisorAnchor,
20598
20745
  idleShutdownMs,
20599
- suspendIdleWhileSupervisorAlive
20746
+ suspendIdleWhileSupervisorAlive,
20747
+ ...isDisconnected ? { isDisconnected } : {}
20600
20748
  });
20601
20749
  logBridgeMessage(
20602
- `Lifecycle: mode=${modeFingerprint}, supervisor=${supervisorAnchor ? supervisorAnchor.pid : "none"}, idleMs=${idleShutdownMs}, suspendIdle=${suspendIdleWhileSupervisorAlive}`
20750
+ `Lifecycle: mode=${modeFingerprint}, supervisor=${supervisorAnchor ? supervisorAnchor.pid : "none"}, idleMs=${idleShutdownMs}, suspendIdle=${attachMode ? "connected-only" : "false"}`
20603
20751
  );
20604
20752
  server.on("request", (req, res) => lifecycle?.observeRequest(req, res));
20605
20753
  server.on("error", (error2) => {
@@ -20610,7 +20758,8 @@ async function runBridge(port = resolveSessionPort()) {
20610
20758
  server.listen(port, "127.0.0.1", () => {
20611
20759
  writePidFile(port, {
20612
20760
  mode: modeFingerprint,
20613
- ...ownedProfile ? { ownedProfileDir: ownedProfile.profileDir } : {}
20761
+ ...ownedProfile ? { ownedProfileDir: ownedProfile.profileDir } : {},
20762
+ ...persistentProfileDir ? { persistentProfileDir } : {}
20614
20763
  });
20615
20764
  logBridgeMessage(`Listening on http://127.0.0.1:${port}`);
20616
20765
  writeReadySignal();
@@ -21,6 +21,6 @@ function tryFastPath(argv, options) {
21
21
 
22
22
  // vendor/chrome-devtools-axi/bin/chrome-devtools-axi.ts
23
23
  if (!tryFastPath(process.argv.slice(2), { version: VERSION })) {
24
- const { main } = await import("./cli-K7ESY3XD.js");
24
+ const { main } = await import("./cli-QAJYAXI4.js");
25
25
  await main(process.argv.slice(2));
26
26
  }