@bastani/atomic 0.9.72 → 0.9.73

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/CHANGELOG.md CHANGED
@@ -2,6 +2,26 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.9.73] - 2026-11-08
6
+
7
+ Intercom connects in every session of a multi-directory process.
8
+
9
+ - **Intercom per agent directory.** A process that starts a second session with a different `ATOMIC_CODING_AGENT_DIR` now connects that session to its own directory's broker, so messaging works in both sessions instead of never connecting ([#4561](https://github.com/bastani-inc/atomic/issues/4561), [#4562](https://github.com/bastani-inc/atomic/pull/4562)).
10
+
11
+ ### Fixed
12
+
13
+ - Fixed Intercom never connecting when one process starts a second session with a different agent directory (`ATOMIC_CODING_AGENT_DIR`): the session now starts and connects to the broker for its own directory instead of finding the first directory's broker and then querying a directory with none ([#4561](https://github.com/bastani-inc/atomic/issues/4561))
14
+
15
+ ## [0.9.73-alpha.1] - 2026-11-08
16
+
17
+ Intercom connects in every session of a multi-directory process.
18
+
19
+ - **Intercom per agent directory.** A process that starts a second session with a different `ATOMIC_CODING_AGENT_DIR` now connects that session to its own directory's broker, so messaging works in both sessions instead of never connecting ([#4561](https://github.com/bastani-inc/atomic/issues/4561), [#4562](https://github.com/bastani-inc/atomic/pull/4562)).
20
+
21
+ ### Fixed
22
+
23
+ - Fixed Intercom never connecting when one process starts a second session with a different agent directory (`ATOMIC_CODING_AGENT_DIR`): the session now starts and connects to the broker for its own directory instead of finding the first directory's broker and then querying a directory with none ([#4561](https://github.com/bastani-inc/atomic/issues/4561))
24
+
5
25
  ## [0.9.72] - 2026-11-08
6
26
 
7
27
  Waiting agents let go of their sessions, work resumes on any machine, and teams share storage with one command.
@@ -4,6 +4,26 @@ All notable changes to the `pi-intercom` extension will be documented in this fi
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [0.9.73] - 2026-11-08
8
+
9
+ Intercom connects in every session of a multi-directory process.
10
+
11
+ - **Intercom per agent directory.** A process that starts a second session with a different `ATOMIC_CODING_AGENT_DIR` now connects that session to its own directory's broker, so messaging works in both sessions instead of never connecting ([#4561](https://github.com/bastani-inc/atomic/issues/4561), [#4562](https://github.com/bastani-inc/atomic/pull/4562)).
12
+
13
+ ### Fixed
14
+
15
+ - Fixed Intercom never connecting when one process starts a second session with a different agent directory (`ATOMIC_CODING_AGENT_DIR`): the session now starts and connects to the broker for its own directory instead of finding the first directory's broker and then querying a directory with none ([#4561](https://github.com/bastani-inc/atomic/issues/4561))
16
+
17
+ ## [0.9.73-alpha.1] - 2026-11-08
18
+
19
+ Intercom connects in every session of a multi-directory process.
20
+
21
+ - **Intercom per agent directory.** A process that starts a second session with a different `ATOMIC_CODING_AGENT_DIR` now connects that session to its own directory's broker, so messaging works in both sessions instead of never connecting ([#4561](https://github.com/bastani-inc/atomic/issues/4561), [#4562](https://github.com/bastani-inc/atomic/pull/4562)).
22
+
23
+ ### Fixed
24
+
25
+ - Fixed Intercom never connecting when one process starts a second session with a different agent directory (`ATOMIC_CODING_AGENT_DIR`): the session now starts and connects to the broker for its own directory instead of finding the first directory's broker and then querying a directory with none ([#4561](https://github.com/bastani-inc/atomic/issues/4561))
26
+
7
27
  ## [0.9.72] - 2026-11-08
8
28
 
9
29
  Released subagents stay reachable, and newer sessions replace older brokers.
@@ -66,7 +66,6 @@ import {
66
66
  workflowSendPredictionFields,
67
67
  } from "../workflow-prediction-fields.js";
68
68
 
69
- const BROKER_SOCKET = getBrokerSocketPath();
70
69
  /** How long `connect()` waits for the broker to answer `register`. */
71
70
  export const BROKER_CONNECT_TIMEOUT_MS = 10_000;
72
71
  /** How long an acknowledged pending-stage route registration waits for the broker's answer. */
@@ -128,8 +127,8 @@ function isLostBrokerSignature(error: Error): boolean {
128
127
  * that still answers closed the connection for its own reasons (a refused or malformed registration), so the failure
129
128
  * stays what it was.
130
129
  */
131
- async function classifyRegistrationFailure(error: Error): Promise<Error> {
132
- if (!isLostBrokerSignature(error) || (await isSocketAnswering(BROKER_SOCKET))) return error;
130
+ async function classifyRegistrationFailure(error: Error, socketPath: string): Promise<Error> {
131
+ if (!isLostBrokerSignature(error) || (await isSocketAnswering(socketPath))) return error;
133
132
  return new IntercomBrokerRetiringError(`Intercom broker went away before it registered this session: ${error.message}`, {
134
133
  cause: error,
135
134
  });
@@ -177,6 +176,8 @@ export interface IntercomClientOptions {
177
176
  * refuse one run's route on its own and keep the connection open for the others.
178
177
  */
179
178
  readonly multiplexesPendingStageRoutes?: true;
179
+ /** Broker socket this client connects to; defaults to the one for the agent directory current when it is created (#4561). */
180
+ readonly brokerSocketPath?: string;
180
181
  }
181
182
 
182
183
  export interface ReleasedChildReply {
@@ -372,6 +373,7 @@ export class IntercomClient extends EventEmitter {
372
373
  private readonly preferredSessionId: string | undefined;
373
374
  private readonly acknowledgesReceipt: boolean;
374
375
  private readonly connectTimeoutMs: number;
376
+ private readonly brokerSocketPath: string;
375
377
  /** #3761: the broker of the current registration echoed `acknowledgesReceipt`, so it understands `received`. */
376
378
  private brokerAcknowledgesReceipt = false;
377
379
  /** The broker of the current registration answers a pending-stage route registration that carries a `requestId`. */
@@ -465,6 +467,7 @@ export class IntercomClient extends EventEmitter {
465
467
  this.acknowledgesReceipt = options.acknowledgesReceipt === true;
466
468
  this.connectTimeoutMs = options.connectTimeoutMs ?? BROKER_CONNECT_TIMEOUT_MS;
467
469
  this.multiplexesPendingStageRoutes = options.multiplexesPendingStageRoutes === true;
470
+ this.brokerSocketPath = options.brokerSocketPath ?? getBrokerSocketPath();
468
471
  }
469
472
 
470
473
  private failPending(error: Error): void {
@@ -563,7 +566,7 @@ export class IntercomClient extends EventEmitter {
563
566
  if (attempt.signal.aborted) throw connectAborted();
564
567
  if (!(error instanceof Error)) throw error;
565
568
  if (!isBacklogRefusal(error) || retry >= BROKER_BACKLOG_RETRIES) {
566
- const classified = await classifyRegistrationFailure(error);
569
+ const classified = await classifyRegistrationFailure(error, this.brokerSocketPath);
567
570
  if (attempt.signal.aborted) throw connectAborted();
568
571
  if (expectedRouting?.verify === true && classified instanceof ConnectionClosedBeforeRegistrationError) {
569
572
  throw new IntercomRoutingUnavailableError("unsupported", "register");
@@ -596,7 +599,7 @@ export class IntercomClient extends EventEmitter {
596
599
  this.registrationExpectedRouting = expectedRouting;
597
600
 
598
601
  return new Promise((resolve, reject) => {
599
- const socket = net.connect(BROKER_SOCKET);
602
+ const socket = net.connect(this.brokerSocketPath);
600
603
  this.socket = socket;
601
604
  this.disconnectError = null;
602
605
  let settled = false;
@@ -51,13 +51,7 @@ export function resolveBrokerEntrypoint(packageRoot: string): string {
51
51
  }
52
52
 
53
53
 
54
- const INTERCOM_DIR = getIntercomDirPath();
55
54
  const EXTENSION_DIR = resolveIntercomPackageRoot(import.meta.url);
56
- const BROKER_SOCKET = getBrokerSocketPath();
57
- const BROKER_PID = getBrokerPidPath();
58
- const BROKER_SPAWN_LOCK = getBrokerSpawnLockPath();
59
- const BROKER_LOG = getBrokerLogPath();
60
- const BROKER_START_ANNOUNCEMENT = getBrokerStartAnnouncementPath();
61
55
 
62
56
  function ensurePrivateDirectory(path: string): void {
63
57
  mkdirSync(path, { recursive: true, mode: 0o700 });
@@ -155,7 +149,7 @@ function quoteWindowsArg(value: string): string {
155
149
  return `"${value.replace(/"/g, '""')}"`;
156
150
  }
157
151
 
158
- export function getWindowsHiddenLauncherPath(intercomDir: string = INTERCOM_DIR): string {
152
+ export function getWindowsHiddenLauncherPath(intercomDir: string = getIntercomDirPath()): string {
159
153
  return join(intercomDir, "broker-launch.vbs");
160
154
  }
161
155
 
@@ -231,10 +225,10 @@ export function getBrokerLaunchSpec(
231
225
  brokerArgs: string[],
232
226
  extensionDir: string = EXTENSION_DIR,
233
227
  platform: NodeJS.Platform = process.platform,
234
- intercomDir: string = INTERCOM_DIR,
228
+ intercomDir: string = getIntercomDirPath(),
235
229
  nodePath: string = process.execPath,
236
230
  runtime: BrokerRuntime = getCurrentBrokerRuntime(),
237
- logPath: string = BROKER_LOG,
231
+ logPath: string = getBrokerLogPath(),
238
232
  ): BrokerLaunchSpec {
239
233
  if (platform === "win32") {
240
234
  const launcherPath = getWindowsHiddenLauncherPath(intercomDir);
@@ -312,7 +306,7 @@ export const BROKER_LOG_RELEASE_WAIT_MS = 1_000;
312
306
  * Preserve a bounded previous log across truncation. Returns false when a
313
307
  * Windows launcher holds the log through its stderr redirect.
314
308
  */
315
- function resetBrokerLog(logPath: string = BROKER_LOG): boolean {
309
+ function resetBrokerLog(logPath: string = getBrokerLogPath()): boolean {
316
310
  ensurePrivateDirectory(dirname(logPath));
317
311
  try {
318
312
  const previous = readBrokerLogTail(logPath);
@@ -347,7 +341,7 @@ async function resetBrokerLogOnceReleased(): Promise<boolean> {
347
341
  }
348
342
 
349
343
  /** Read at most {@link BROKER_LOG_TAIL_BYTES} trailing bytes of the broker log. */
350
- export function readBrokerLogTail(logPath: string = BROKER_LOG, maxBytes: number = BROKER_LOG_TAIL_BYTES): string {
344
+ export function readBrokerLogTail(logPath: string = getBrokerLogPath(), maxBytes: number = BROKER_LOG_TAIL_BYTES): string {
351
345
  let fd: number | undefined;
352
346
  try {
353
347
  fd = openSync(logPath, "r");
@@ -372,7 +366,7 @@ export function readBrokerLogTail(logPath: string = BROKER_LOG, maxBytes: number
372
366
  }
373
367
 
374
368
  /** Path plus bounded stderr tail, appended to every broker startup failure. */
375
- export function describeBrokerLog(logPath: string = BROKER_LOG): string {
369
+ export function describeBrokerLog(logPath: string = getBrokerLogPath()): string {
376
370
  const tail = readBrokerLogTail(logPath);
377
371
  if (tail.length === 0) return `Broker log: ${logPath} (empty)`;
378
372
  return `Broker log: ${logPath}\n--- broker stderr (last ${Buffer.byteLength(tail)} bytes) ---\n${tail}`;
@@ -388,7 +382,7 @@ export async function spawnBrokerIfNeeded(
388
382
  readyTimeoutMs: number = BROKER_READY_TIMEOUT_MS,
389
383
  extensionDir: string = EXTENSION_DIR,
390
384
  ): Promise<void> {
391
- ensurePrivateDirectory(INTERCOM_DIR);
385
+ ensurePrivateDirectory(getIntercomDirPath());
392
386
 
393
387
  if (await isBrokerRunning()) {
394
388
  return;
@@ -425,7 +419,7 @@ async function spawnBrokerHoldingLock(
425
419
  // The Windows launcher hides the broker's pid and exit, so there the broker announces its pid, which this watches.
426
420
  // Elsewhere the child is the broker and its exit event says how it ended.
427
421
  const announcement: BrokerStartAnnouncement | undefined =
428
- launch.kind === "windows-launcher" ? { path: BROKER_START_ANNOUNCEMENT, token: randomUUID() } : undefined;
422
+ launch.kind === "windows-launcher" ? { path: getBrokerStartAnnouncementPath(), token: randomUUID() } : undefined;
429
423
  if (announcement !== undefined) {
430
424
  try {
431
425
  unlinkSync(announcement.path);
@@ -444,7 +438,7 @@ async function spawnBrokerHoldingLock(
444
438
  // The Windows launcher redirects the broker's own stderr, so only the direct spawn
445
439
  // needs the descriptor. Node duplicates it during spawn, so the parent copy is closed
446
440
  // immediately afterwards rather than being held open for the broker's lifetime.
447
- const logFd = launch.kind === "direct" ? openSync(BROKER_LOG, "a") : undefined;
441
+ const logFd = launch.kind === "direct" ? openSync(getBrokerLogPath(), "a") : undefined;
448
442
  let child: ReturnType<typeof spawn>;
449
443
  try {
450
444
  child = spawn(launch.command, launch.args, getBrokerSpawnOptions(extensionDir, logFd ?? "ignore", announcement));
@@ -554,7 +548,7 @@ export async function upgradeBroker(
554
548
  own: BrokerProtocolRange = BROKER_PROTOCOL,
555
549
  stopTimeoutMs: number = BROKER_UPGRADE_STOP_TIMEOUT_MS,
556
550
  ): Promise<BrokerUpgradeOutcome> {
557
- ensurePrivateDirectory(INTERCOM_DIR);
551
+ ensurePrivateDirectory(getIntercomDirPath());
558
552
  const acquired = await acquireSpawnLockWithin(readyTimeoutMs + stopTimeoutMs);
559
553
  if (acquired === undefined) return "busy";
560
554
  let lockOwner = acquired;
@@ -564,7 +558,7 @@ export async function upgradeBroker(
564
558
  return spawnBrokerHoldingLock(lockOwner, brokerCommand, brokerArgs, readyTimeoutMs, extensionDir, false);
565
559
  };
566
560
  try {
567
- const answer = await controlRequest(BROKER_SOCKET, "broker_status", "broker_status", BROKER_CONTROL_TIMEOUT_MS);
561
+ const answer = await controlRequest(getBrokerSocketPath(), "broker_status", "broker_status", BROKER_CONTROL_TIMEOUT_MS);
568
562
  if (!answer.connected) {
569
563
  await spawnHoldingLock();
570
564
  return "started";
@@ -580,7 +574,7 @@ export async function upgradeBroker(
580
574
  if (report.storage?.digest !== successorStorageDigest()) return "storage-differs";
581
575
  const failed = (phase: "stop" | "start", cause?: Error): IntercomBrokerUpgradeError =>
582
576
  new IntercomBrokerUpgradeError({ phase, previousPid: report.pid, previousProtocolMax: running.max }, { cause });
583
- if ((await requestBrokerShutdown(BROKER_SOCKET)) === "unanswered") throw failed("stop");
577
+ if ((await requestBrokerShutdown(getBrokerSocketPath())) === "unanswered") throw failed("stop");
584
578
  try {
585
579
  await waitForBrokerExit(report.pid, stopTimeoutMs, () => {
586
580
  lockOwner = renewSpawnLock(lockOwner);
@@ -605,7 +599,7 @@ export async function upgradeBroker(
605
599
 
606
600
  /** The digest of the shared storage selection a broker started from this process reads, as its `broker_status` reports it. */
607
601
  function successorStorageDigest(): string | undefined {
608
- const setting = readSharedStorageSetting(dirname(INTERCOM_DIR), {
602
+ const setting = readSharedStorageSetting(dirname(getIntercomDirPath()), {
609
603
  [BROKER_STORAGE_ENV]: processSharedStorageSelection() ?? "",
610
604
  });
611
605
  return setting === undefined ? undefined : sharedStorageDigest(setting);
@@ -626,10 +620,10 @@ async function isBrokerRunning(): Promise<boolean> {
626
620
  return true;
627
621
  }
628
622
 
629
- if (!existsSync(BROKER_PID)) return false;
623
+ if (!existsSync(getBrokerPidPath())) return false;
630
624
 
631
625
  try {
632
- const pid = parseInt(readFileSync(BROKER_PID, "utf-8").trim(), 10);
626
+ const pid = parseInt(readFileSync(getBrokerPidPath(), "utf-8").trim(), 10);
633
627
  if (!Number.isFinite(pid)) return false;
634
628
  process.kill(pid, 0);
635
629
  return checkSocketConnectable();
@@ -640,14 +634,14 @@ async function isBrokerRunning(): Promise<boolean> {
640
634
  }
641
635
 
642
636
  function checkSocketConnectable(): Promise<boolean> {
643
- return isSocketAnswering(BROKER_SOCKET);
637
+ return isSocketAnswering(getBrokerSocketPath());
644
638
  }
645
639
 
646
640
  /** Records the still-starting broker on the lock so staleness follows that process instead of the spawner. */
647
641
  function handSpawnLockToBroker(pid: number | undefined, owner: string): boolean {
648
642
  if (pid === undefined || !ownsSpawnLock(owner)) return false;
649
643
  try {
650
- appendFileSync(BROKER_SPAWN_LOCK, `${pid}\n`);
644
+ appendFileSync(getBrokerSpawnLockPath(), `${pid}\n`);
651
645
  return true;
652
646
  } catch {
653
647
  // The startup error must still reach the caller; an unrecorded lock is released like any other.
@@ -667,17 +661,17 @@ function renewSpawnLock(owner: string, nowMs: number = Date.now()): string {
667
661
  const writtenAt = Number.parseInt(owner.split("\n")[1] ?? "", 10);
668
662
  if (nowMs - writtenAt < SPAWN_LOCK_RENEW_AFTER_MS || !ownsSpawnLock(owner)) return owner;
669
663
  const renewed = `${process.pid}\n${nowMs}\n`;
670
- const staged = `${BROKER_SPAWN_LOCK}.${process.pid}.renew`;
664
+ const staged = `${getBrokerSpawnLockPath()}.${process.pid}.renew`;
671
665
  try {
672
666
  writeFileSync(staged, renewed);
673
- renameSync(staged, BROKER_SPAWN_LOCK);
667
+ renameSync(staged, getBrokerSpawnLockPath());
674
668
  return renewed;
675
669
  } catch {
676
670
  return owner;
677
671
  }
678
672
  }
679
673
 
680
- function ownsSpawnLock(owner: string, lockPath: string = BROKER_SPAWN_LOCK): boolean {
674
+ function ownsSpawnLock(owner: string, lockPath: string = getBrokerSpawnLockPath()): boolean {
681
675
  try {
682
676
  return readFileSync(lockPath, "utf-8").startsWith(owner);
683
677
  } catch {
@@ -691,7 +685,7 @@ function acquireSpawnLock(): string | undefined {
691
685
  for (let attempt = 0; attempt < maxRetries; attempt++) {
692
686
  const owner = `${process.pid}\n${Date.now()}\n`;
693
687
  try {
694
- writeFileSync(BROKER_SPAWN_LOCK, owner, { flag: "wx" });
688
+ writeFileSync(getBrokerSpawnLockPath(), owner, { flag: "wx" });
695
689
  return owner;
696
690
  } catch (error) {
697
691
  if (!(error instanceof Error) || (error as NodeJS.ErrnoException).code !== "EEXIST") {
@@ -699,7 +693,7 @@ function acquireSpawnLock(): string | undefined {
699
693
  }
700
694
  if (isSpawnLockStale()) {
701
695
  try {
702
- unlinkSync(BROKER_SPAWN_LOCK);
696
+ unlinkSync(getBrokerSpawnLockPath());
703
697
  } catch {
704
698
  // If we can't delete the stale lock, retry a few times before giving up
705
699
  }
@@ -724,7 +718,7 @@ function isProcessAlive(pid: number): boolean {
724
718
  * A lock is stale once the broker it recorded is gone, or, while no broker is recorded, once its
725
719
  * spawner is gone. A live broker keeps the lock even if its spawner died, until the age backstop.
726
720
  */
727
- export function isSpawnLockStale(lockPath: string = BROKER_SPAWN_LOCK, nowMs: number = Date.now()): boolean {
721
+ export function isSpawnLockStale(lockPath: string = getBrokerSpawnLockPath(), nowMs: number = Date.now()): boolean {
728
722
  if (!existsSync(lockPath)) {
729
723
  return false;
730
724
  }
@@ -745,7 +739,7 @@ export function isSpawnLockStale(lockPath: string = BROKER_SPAWN_LOCK, nowMs: nu
745
739
  }
746
740
 
747
741
  /** Removes the lock only while it is still the one `owner` wrote; a spawner that replaced a stale lock keeps its own. */
748
- export function releaseSpawnLock(owner: string, lockPath: string = BROKER_SPAWN_LOCK): void {
742
+ export function releaseSpawnLock(owner: string, lockPath: string = getBrokerSpawnLockPath()): void {
749
743
  if (!ownsSpawnLock(owner, lockPath)) return;
750
744
  try {
751
745
  unlinkSync(lockPath);
@@ -1835,8 +1835,8 @@ function isLostBrokerSignature(error) {
1835
1835
  const code = error.code;
1836
1836
  return code === "ENOENT" || code === "ECONNRESET" || code === "EPIPE";
1837
1837
  }
1838
- async function classifyRegistrationFailure(error) {
1839
- if (!isLostBrokerSignature(error) || await isSocketAnswering(BROKER_SOCKET))
1838
+ async function classifyRegistrationFailure(error, socketPath) {
1839
+ if (!isLostBrokerSignature(error) || await isSocketAnswering(socketPath))
1840
1840
  return error;
1841
1841
  return new IntercomBrokerRetiringError(`Intercom broker went away before it registered this session: ${error.message}`, {
1842
1842
  cause: error
@@ -1861,7 +1861,7 @@ function isWorkflowFutureStageRosterEntries(value) {
1861
1861
  function isWorkflowStageRosterEntries(value) {
1862
1862
  return Array.isArray(value) && value.every((entry) => typeof entry === "object" && entry !== null && entry.kind === "workflow-stage" && typeof entry.runId === "string" && typeof entry.stageId === "string" && typeof entry.stageName === "string" && typeof entry.target === "string" && (entry.lifecycle === "pending" || entry.lifecycle === "running") && typeof entry.group === "string" && (entry.sessionId === undefined || typeof entry.sessionId === "string"));
1863
1863
  }
1864
- var BROKER_SOCKET, BROKER_CONNECT_TIMEOUT_MS = 1e4, PENDING_STAGE_ROUTE_ACK_TIMEOUT_MS = 1e4, GROUP_REQUEST_TIMEOUT_MS = 5000, PRESENCE_ACK_TIMEOUT_MS = 5000, RESTORING_RECIPIENT_REQUEST_TIMEOUT_MS = 5000, BROKER_BACKLOG_RETRIES = 6, BROKER_BACKLOG_RETRY_BASE_MS = 25, ConnectionClosedBeforeRegistrationError, HELD_SEND_GRACE_MS = 5000, IntercomPendingStageRouteRefusedError, PENDING_STAGE_ROUTE_REFUSAL_CODES, IntercomClient;
1864
+ var BROKER_CONNECT_TIMEOUT_MS = 1e4, PENDING_STAGE_ROUTE_ACK_TIMEOUT_MS = 1e4, GROUP_REQUEST_TIMEOUT_MS = 5000, PRESENCE_ACK_TIMEOUT_MS = 5000, RESTORING_RECIPIENT_REQUEST_TIMEOUT_MS = 5000, BROKER_BACKLOG_RETRIES = 6, BROKER_BACKLOG_RETRY_BASE_MS = 25, ConnectionClosedBeforeRegistrationError, HELD_SEND_GRACE_MS = 5000, IntercomPendingStageRouteRefusedError, PENDING_STAGE_ROUTE_REFUSAL_CODES, IntercomClient;
1865
1865
  var init_client = __esm(() => {
1866
1866
  init_broker_status();
1867
1867
  init_paths();
@@ -1880,7 +1880,6 @@ var init_client = __esm(() => {
1880
1880
  init_workflow_prediction_fields();
1881
1881
  init_released_child_errors();
1882
1882
  init_released_reply_errors();
1883
- BROKER_SOCKET = getBrokerSocketPath();
1884
1883
  ConnectionClosedBeforeRegistrationError = class ConnectionClosedBeforeRegistrationError extends Error {
1885
1884
  constructor() {
1886
1885
  super("Connection closed before registration");
@@ -1907,6 +1906,7 @@ var init_client = __esm(() => {
1907
1906
  preferredSessionId;
1908
1907
  acknowledgesReceipt;
1909
1908
  connectTimeoutMs;
1909
+ brokerSocketPath;
1910
1910
  brokerAcknowledgesReceipt = false;
1911
1911
  brokerAcknowledgesPendingStageRoutes = false;
1912
1912
  multiplexesPendingStageRoutes;
@@ -1983,6 +1983,7 @@ var init_client = __esm(() => {
1983
1983
  this.acknowledgesReceipt = options.acknowledgesReceipt === true;
1984
1984
  this.connectTimeoutMs = options.connectTimeoutMs ?? BROKER_CONNECT_TIMEOUT_MS;
1985
1985
  this.multiplexesPendingStageRoutes = options.multiplexesPendingStageRoutes === true;
1986
+ this.brokerSocketPath = options.brokerSocketPath ?? getBrokerSocketPath();
1986
1987
  }
1987
1988
  failPending(error) {
1988
1989
  this.pendingSends.rejectAll(error);
@@ -2065,7 +2066,7 @@ var init_client = __esm(() => {
2065
2066
  if (!(error instanceof Error))
2066
2067
  throw error;
2067
2068
  if (!isBacklogRefusal(error) || retry >= BROKER_BACKLOG_RETRIES) {
2068
- const classified = await classifyRegistrationFailure(error);
2069
+ const classified = await classifyRegistrationFailure(error, this.brokerSocketPath);
2069
2070
  if (attempt.signal.aborted)
2070
2071
  throw connectAborted();
2071
2072
  if (expectedRouting?.verify === true && classified instanceof ConnectionClosedBeforeRegistrationError) {
@@ -2090,7 +2091,7 @@ var init_client = __esm(() => {
2090
2091
  this._groups = normalizeGroups(session.groups, session.group);
2091
2092
  this.registrationExpectedRouting = expectedRouting;
2092
2093
  return new Promise((resolve, reject) => {
2093
- const socket = net2.connect(BROKER_SOCKET);
2094
+ const socket = net2.connect(this.brokerSocketPath);
2094
2095
  this.socket = socket;
2095
2096
  this.disconnectError = null;
2096
2097
  let settled = false;
@@ -3465,7 +3466,7 @@ function getDefaultBrokerCommandParts(brokerPath, extensionDir, runtimePath, run
3465
3466
  function quoteWindowsArg(value) {
3466
3467
  return `"${value.replace(/"/g, '""')}"`;
3467
3468
  }
3468
- function getWindowsHiddenLauncherPath(intercomDir = INTERCOM_DIR) {
3469
+ function getWindowsHiddenLauncherPath(intercomDir = getIntercomDirPath()) {
3469
3470
  return join3(intercomDir, "broker-launch.vbs");
3470
3471
  }
3471
3472
  function usesDefaultBrokerCommand(brokerCommand, brokerArgs) {
@@ -3497,7 +3498,7 @@ function writeWindowsHiddenLauncher(commandLine, launcherPath = getWindowsHidden
3497
3498
  writeFileSync2(launcherPath, getWindowsHiddenLauncherScript(commandLine), "utf-8");
3498
3499
  return launcherPath;
3499
3500
  }
3500
- function getBrokerLaunchSpec(brokerPath, brokerCommand, brokerArgs, extensionDir = EXTENSION_DIR, platform = process.platform, intercomDir = INTERCOM_DIR, nodePath = process.execPath, runtime = getCurrentBrokerRuntime(), logPath = BROKER_LOG) {
3501
+ function getBrokerLaunchSpec(brokerPath, brokerCommand, brokerArgs, extensionDir = EXTENSION_DIR, platform = process.platform, intercomDir = getIntercomDirPath(), nodePath = process.execPath, runtime = getCurrentBrokerRuntime(), logPath = getBrokerLogPath()) {
3501
3502
  if (platform === "win32") {
3502
3503
  const launcherPath = getWindowsHiddenLauncherPath(intercomDir);
3503
3504
  return {
@@ -3536,7 +3537,7 @@ function getBrokerSpawnOptions(extensionDir = EXTENSION_DIR, stderr = "ignore",
3536
3537
  windowsHide: true
3537
3538
  };
3538
3539
  }
3539
- function resetBrokerLog(logPath = BROKER_LOG) {
3540
+ function resetBrokerLog(logPath = getBrokerLogPath()) {
3540
3541
  ensurePrivateDirectory(dirname(logPath));
3541
3542
  try {
3542
3543
  const previous = readBrokerLogTail(logPath);
@@ -3566,7 +3567,7 @@ async function resetBrokerLogOnceReleased() {
3566
3567
  }
3567
3568
  return true;
3568
3569
  }
3569
- function readBrokerLogTail(logPath = BROKER_LOG, maxBytes = BROKER_LOG_TAIL_BYTES) {
3570
+ function readBrokerLogTail(logPath = getBrokerLogPath(), maxBytes = BROKER_LOG_TAIL_BYTES) {
3570
3571
  let fd;
3571
3572
  try {
3572
3573
  fd = openSync(logPath, "r");
@@ -3587,7 +3588,7 @@ function readBrokerLogTail(logPath = BROKER_LOG, maxBytes = BROKER_LOG_TAIL_BYTE
3587
3588
  }
3588
3589
  }
3589
3590
  }
3590
- function describeBrokerLog(logPath = BROKER_LOG) {
3591
+ function describeBrokerLog(logPath = getBrokerLogPath()) {
3591
3592
  const tail = readBrokerLogTail(logPath);
3592
3593
  if (tail.length === 0)
3593
3594
  return `Broker log: ${logPath} (empty)`;
@@ -3599,7 +3600,7 @@ function toError3(error) {
3599
3600
  return error instanceof Error ? error : new Error(String(error));
3600
3601
  }
3601
3602
  async function spawnBrokerIfNeeded(brokerCommand, brokerArgs, readyTimeoutMs = BROKER_READY_TIMEOUT_MS, extensionDir = EXTENSION_DIR) {
3602
- ensurePrivateDirectory(INTERCOM_DIR);
3603
+ ensurePrivateDirectory(getIntercomDirPath());
3603
3604
  if (await isBrokerRunning()) {
3604
3605
  return;
3605
3606
  }
@@ -3618,7 +3619,7 @@ async function spawnBrokerHoldingLock(lockOwner, brokerCommand, brokerArgs, read
3618
3619
  }
3619
3620
  const brokerPath = resolveBrokerEntrypoint(extensionDir);
3620
3621
  const launch = getBrokerLaunchSpec(brokerPath, brokerCommand, brokerArgs, extensionDir);
3621
- const announcement = launch.kind === "windows-launcher" ? { path: BROKER_START_ANNOUNCEMENT, token: randomUUID4() } : undefined;
3622
+ const announcement = launch.kind === "windows-launcher" ? { path: getBrokerStartAnnouncementPath(), token: randomUUID4() } : undefined;
3622
3623
  if (announcement !== undefined) {
3623
3624
  try {
3624
3625
  unlinkSync2(announcement.path);
@@ -3631,7 +3632,7 @@ async function spawnBrokerHoldingLock(lockOwner, brokerCommand, brokerArgs, read
3631
3632
  await waitForBroker(readyTimeoutMs);
3632
3633
  return;
3633
3634
  }
3634
- const logFd = launch.kind === "direct" ? openSync(BROKER_LOG, "a") : undefined;
3635
+ const logFd = launch.kind === "direct" ? openSync(getBrokerLogPath(), "a") : undefined;
3635
3636
  let child;
3636
3637
  try {
3637
3638
  child = spawn(launch.command, launch.args, getBrokerSpawnOptions(extensionDir, logFd ?? "ignore", announcement));
@@ -3685,7 +3686,7 @@ ${describeBrokerLog()}`);
3685
3686
  }
3686
3687
  }
3687
3688
  async function upgradeBroker(brokerCommand, brokerArgs, readyTimeoutMs = BROKER_READY_TIMEOUT_MS, extensionDir = EXTENSION_DIR, own = BROKER_PROTOCOL, stopTimeoutMs = BROKER_UPGRADE_STOP_TIMEOUT_MS) {
3688
- ensurePrivateDirectory(INTERCOM_DIR);
3689
+ ensurePrivateDirectory(getIntercomDirPath());
3689
3690
  const acquired = await acquireSpawnLockWithin(readyTimeoutMs + stopTimeoutMs);
3690
3691
  if (acquired === undefined)
3691
3692
  return "busy";
@@ -3696,7 +3697,7 @@ async function upgradeBroker(brokerCommand, brokerArgs, readyTimeoutMs = BROKER_
3696
3697
  return spawnBrokerHoldingLock(lockOwner, brokerCommand, brokerArgs, readyTimeoutMs, extensionDir, false);
3697
3698
  };
3698
3699
  try {
3699
- const answer = await controlRequest(BROKER_SOCKET2, "broker_status", "broker_status", BROKER_CONTROL_TIMEOUT_MS);
3700
+ const answer = await controlRequest(getBrokerSocketPath(), "broker_status", "broker_status", BROKER_CONTROL_TIMEOUT_MS);
3700
3701
  if (!answer.connected) {
3701
3702
  await spawnHoldingLock();
3702
3703
  return "started";
@@ -3711,7 +3712,7 @@ async function upgradeBroker(brokerCommand, brokerArgs, readyTimeoutMs = BROKER_
3711
3712
  if (report.storage?.digest !== successorStorageDigest())
3712
3713
  return "storage-differs";
3713
3714
  const failed = (phase, cause) => new IntercomBrokerUpgradeError({ phase, previousPid: report.pid, previousProtocolMax: running.max }, { cause });
3714
- if (await requestBrokerShutdown(BROKER_SOCKET2) === "unanswered")
3715
+ if (await requestBrokerShutdown(getBrokerSocketPath()) === "unanswered")
3715
3716
  throw failed("stop");
3716
3717
  try {
3717
3718
  await waitForBrokerExit(report.pid, stopTimeoutMs, () => {
@@ -3736,7 +3737,7 @@ async function upgradeBroker(brokerCommand, brokerArgs, readyTimeoutMs = BROKER_
3736
3737
  }
3737
3738
  }
3738
3739
  function successorStorageDigest() {
3739
- const setting = readSharedStorageSetting(dirname(INTERCOM_DIR), {
3740
+ const setting = readSharedStorageSetting(dirname(getIntercomDirPath()), {
3740
3741
  [BROKER_STORAGE_ENV]: processSharedStorageSelection() ?? ""
3741
3742
  });
3742
3743
  return setting === undefined ? undefined : sharedStorageDigest(setting);
@@ -3754,10 +3755,10 @@ async function isBrokerRunning() {
3754
3755
  if (await checkSocketConnectable()) {
3755
3756
  return true;
3756
3757
  }
3757
- if (!existsSync(BROKER_PID))
3758
+ if (!existsSync(getBrokerPidPath()))
3758
3759
  return false;
3759
3760
  try {
3760
- const pid = parseInt(readFileSync3(BROKER_PID, "utf-8").trim(), 10);
3761
+ const pid = parseInt(readFileSync3(getBrokerPidPath(), "utf-8").trim(), 10);
3761
3762
  if (!Number.isFinite(pid))
3762
3763
  return false;
3763
3764
  process.kill(pid, 0);
@@ -3767,13 +3768,13 @@ async function isBrokerRunning() {
3767
3768
  }
3768
3769
  }
3769
3770
  function checkSocketConnectable() {
3770
- return isSocketAnswering(BROKER_SOCKET2);
3771
+ return isSocketAnswering(getBrokerSocketPath());
3771
3772
  }
3772
3773
  function handSpawnLockToBroker(pid, owner) {
3773
3774
  if (pid === undefined || !ownsSpawnLock(owner))
3774
3775
  return false;
3775
3776
  try {
3776
- appendFileSync(BROKER_SPAWN_LOCK, `${pid}
3777
+ appendFileSync(getBrokerSpawnLockPath(), `${pid}
3777
3778
  `);
3778
3779
  return true;
3779
3780
  } catch {
@@ -3788,16 +3789,16 @@ function renewSpawnLock(owner, nowMs = Date.now()) {
3788
3789
  const renewed = `${process.pid}
3789
3790
  ${nowMs}
3790
3791
  `;
3791
- const staged = `${BROKER_SPAWN_LOCK}.${process.pid}.renew`;
3792
+ const staged = `${getBrokerSpawnLockPath()}.${process.pid}.renew`;
3792
3793
  try {
3793
3794
  writeFileSync2(staged, renewed);
3794
- renameSync(staged, BROKER_SPAWN_LOCK);
3795
+ renameSync(staged, getBrokerSpawnLockPath());
3795
3796
  return renewed;
3796
3797
  } catch {
3797
3798
  return owner;
3798
3799
  }
3799
3800
  }
3800
- function ownsSpawnLock(owner, lockPath = BROKER_SPAWN_LOCK) {
3801
+ function ownsSpawnLock(owner, lockPath = getBrokerSpawnLockPath()) {
3801
3802
  try {
3802
3803
  return readFileSync3(lockPath, "utf-8").startsWith(owner);
3803
3804
  } catch {
@@ -3811,7 +3812,7 @@ function acquireSpawnLock() {
3811
3812
  ${Date.now()}
3812
3813
  `;
3813
3814
  try {
3814
- writeFileSync2(BROKER_SPAWN_LOCK, owner, { flag: "wx" });
3815
+ writeFileSync2(getBrokerSpawnLockPath(), owner, { flag: "wx" });
3815
3816
  return owner;
3816
3817
  } catch (error) {
3817
3818
  if (!(error instanceof Error) || error.code !== "EEXIST") {
@@ -3819,7 +3820,7 @@ ${Date.now()}
3819
3820
  }
3820
3821
  if (isSpawnLockStale()) {
3821
3822
  try {
3822
- unlinkSync2(BROKER_SPAWN_LOCK);
3823
+ unlinkSync2(getBrokerSpawnLockPath());
3823
3824
  } catch {}
3824
3825
  continue;
3825
3826
  }
@@ -3836,7 +3837,7 @@ function isProcessAlive2(pid) {
3836
3837
  return error.code === "EPERM";
3837
3838
  }
3838
3839
  }
3839
- function isSpawnLockStale(lockPath = BROKER_SPAWN_LOCK, nowMs = Date.now()) {
3840
+ function isSpawnLockStale(lockPath = getBrokerSpawnLockPath(), nowMs = Date.now()) {
3840
3841
  if (!existsSync(lockPath)) {
3841
3842
  return false;
3842
3843
  }
@@ -3855,7 +3856,7 @@ function isSpawnLockStale(lockPath = BROKER_SPAWN_LOCK, nowMs = Date.now()) {
3855
3856
  return true;
3856
3857
  }
3857
3858
  }
3858
- function releaseSpawnLock(owner, lockPath = BROKER_SPAWN_LOCK) {
3859
+ function releaseSpawnLock(owner, lockPath = getBrokerSpawnLockPath()) {
3859
3860
  if (!ownsSpawnLock(owner, lockPath))
3860
3861
  return;
3861
3862
  try {
@@ -3883,7 +3884,7 @@ ${describeBrokerLog()}`);
3883
3884
  ` + "The broker did not answer on its socket in time; it may still be starting, which a busy machine or an empty jiti " + "cache slows. Try again, or raise `brokerStartupTimeoutMs` in the Intercom config.json (default " + `${BROKER_READY_TIMEOUT_MS} ms).
3884
3885
  ${describeBrokerLog()}`);
3885
3886
  }
3886
- var INTERCOM_DIR, EXTENSION_DIR, BROKER_SOCKET2, BROKER_PID, BROKER_SPAWN_LOCK, BROKER_LOG, BROKER_START_ANNOUNCEMENT, BROKER_LOG_TAIL_BYTES, BROKER_POLL_INITIAL_INTERVAL_MS = 10, BROKER_POLL_MAX_INTERVAL_MS = 100, BROKER_SPAWN_LOCK_MAX_AGE_MS = 60000, INTERNAL_INTERCOM_BROKER_ARG = "--atomic-internal-intercom-broker", BROKER_LOG_RELEASE_WAIT_MS = 1000, UPGRADE_LOCK_POLL_MS = 50, SPAWN_LOCK_RENEW_AFTER_MS = 1e4;
3887
+ var EXTENSION_DIR, BROKER_LOG_TAIL_BYTES, BROKER_POLL_INITIAL_INTERVAL_MS = 10, BROKER_POLL_MAX_INTERVAL_MS = 100, BROKER_SPAWN_LOCK_MAX_AGE_MS = 60000, INTERNAL_INTERCOM_BROKER_ARG = "--atomic-internal-intercom-broker", BROKER_LOG_RELEASE_WAIT_MS = 1000, UPGRADE_LOCK_POLL_MS = 50, SPAWN_LOCK_RENEW_AFTER_MS = 1e4;
3887
3888
  var init_spawn = __esm(() => {
3888
3889
  init_socket_liveness();
3889
3890
  init_start_announcement();
@@ -3893,13 +3894,7 @@ var init_spawn = __esm(() => {
3893
3894
  init_protocol_version();
3894
3895
  init_shared_storage_setting();
3895
3896
  init_paths();
3896
- INTERCOM_DIR = getIntercomDirPath();
3897
3897
  EXTENSION_DIR = resolveIntercomPackageRoot(import.meta.url);
3898
- BROKER_SOCKET2 = getBrokerSocketPath();
3899
- BROKER_PID = getBrokerPidPath();
3900
- BROKER_SPAWN_LOCK = getBrokerSpawnLockPath();
3901
- BROKER_LOG = getBrokerLogPath();
3902
- BROKER_START_ANNOUNCEMENT = getBrokerStartAnnouncementPath();
3903
3898
  BROKER_LOG_TAIL_BYTES = 8 * 1024;
3904
3899
  });
3905
3900
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bastani/intercom",
3
- "version": "0.9.72",
3
+ "version": "0.9.73",
4
4
  "private": true,
5
5
  "description": "Atomic extension providing a private coordination channel between parent and child agent sessions. Fork of: https://github.com/nicobailon/pi-intercom",
6
6
  "contributors": [
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bastani/mcp",
3
- "version": "0.9.72",
3
+ "version": "0.9.73",
4
4
  "private": true,
5
5
  "description": "Atomic's pi-compatible MCP integration for server connections, OAuth, tools, resources, and terminal management.",
6
6
  "contributors": [
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bastani/subagents",
3
- "version": "0.9.72",
3
+ "version": "0.9.73",
4
4
  "private": true,
5
5
  "description": "Atomic extension for delegating tasks to subagents with parallel execution. Fork of: https://github.com/nicobailon/pi-subagents",
6
6
  "contributors": [
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bastani/web-access",
3
- "version": "0.9.72",
3
+ "version": "0.9.73",
4
4
  "private": true,
5
5
  "description": "Atomic extension for web search, URL fetching, GitHub repo cloning, PDF/video extraction. Fork of: https://github.com/nicobailon/pi-web-access",
6
6
  "contributors": [
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bastani/workflows",
3
- "version": "0.9.72",
3
+ "version": "0.9.73",
4
4
  "private": true,
5
5
  "description": "Atomic extension for multi-stage workflow authoring and execution.",
6
6
  "contributors": [