agent-relay 6.3.5 → 7.0.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/index.cjs CHANGED
@@ -3181,7 +3181,7 @@ var require_stream = __commonJS({
3181
3181
  };
3182
3182
  duplex._final = function(callback) {
3183
3183
  if (ws2.readyState === ws2.CONNECTING) {
3184
- ws2.once("open", function open2() {
3184
+ ws2.once("open", function open3() {
3185
3185
  duplex._final(callback);
3186
3186
  });
3187
3187
  return;
@@ -3202,7 +3202,7 @@ var require_stream = __commonJS({
3202
3202
  };
3203
3203
  duplex._write = function(chunk, encoding, callback) {
3204
3204
  if (ws2.readyState === ws2.CONNECTING) {
3205
- ws2.once("open", function open2() {
3205
+ ws2.once("open", function open3() {
3206
3206
  duplex._write(chunk, encoding, callback);
3207
3207
  });
3208
3208
  return;
@@ -5133,18 +5133,18 @@ var require_source = __commonJS({
5133
5133
  }
5134
5134
  }
5135
5135
  });
5136
- var createStyler = (open2, close, parent) => {
5136
+ var createStyler = (open3, close, parent) => {
5137
5137
  let openAll;
5138
5138
  let closeAll;
5139
5139
  if (parent === void 0) {
5140
- openAll = open2;
5140
+ openAll = open3;
5141
5141
  closeAll = close;
5142
5142
  } else {
5143
- openAll = parent.openAll + open2;
5143
+ openAll = parent.openAll + open3;
5144
5144
  closeAll = close + parent.closeAll;
5145
5145
  }
5146
5146
  return {
5147
- open: open2,
5147
+ open: open3,
5148
5148
  close,
5149
5149
  openAll,
5150
5150
  closeAll,
@@ -13358,7 +13358,7 @@ var require_rfdc = __commonJS({
13358
13358
  });
13359
13359
 
13360
13360
  // node_modules/environment/index.js
13361
- var isBrowser, isNode, isBun, isDeno, isElectron, isJsDom, isWebWorker, isDedicatedWorker, isSharedWorker, isServiceWorker, platform, isMacOs, isWindows, isLinux, isIos, isAndroid;
13361
+ var isBrowser, isNode, isBun, isDeno, isElectron, isJsDom, isWebWorker, isDedicatedWorker, isSharedWorker, isServiceWorker, platform2, isMacOs, isWindows, isLinux, isIos, isAndroid;
13362
13362
  var init_environment = __esm({
13363
13363
  "node_modules/environment/index.js"() {
13364
13364
  isBrowser = globalThis.window?.document !== void 0;
@@ -13371,12 +13371,12 @@ var init_environment = __esm({
13371
13371
  isDedicatedWorker = typeof DedicatedWorkerGlobalScope !== "undefined" && globalThis instanceof DedicatedWorkerGlobalScope;
13372
13372
  isSharedWorker = typeof SharedWorkerGlobalScope !== "undefined" && globalThis instanceof SharedWorkerGlobalScope;
13373
13373
  isServiceWorker = typeof ServiceWorkerGlobalScope !== "undefined" && globalThis instanceof ServiceWorkerGlobalScope;
13374
- platform = globalThis.navigator?.userAgentData?.platform;
13375
- isMacOs = platform === "macOS" || globalThis.navigator?.platform === "MacIntel" || globalThis.navigator?.userAgent?.includes(" Mac ") === true || globalThis.process?.platform === "darwin";
13376
- isWindows = platform === "Windows" || globalThis.navigator?.platform === "Win32" || globalThis.process?.platform === "win32";
13377
- isLinux = platform === "Linux" || globalThis.navigator?.platform?.startsWith("Linux") === true || globalThis.navigator?.userAgent?.includes(" Linux ") === true || globalThis.process?.platform === "linux";
13378
- isIos = platform === "iOS" || globalThis.navigator?.platform === "MacIntel" && globalThis.navigator?.maxTouchPoints > 1 || /iPad|iPhone|iPod/.test(globalThis.navigator?.platform);
13379
- isAndroid = platform === "Android" || globalThis.navigator?.platform === "Android" || globalThis.navigator?.userAgent?.includes(" Android ") === true || globalThis.process?.platform === "android";
13374
+ platform2 = globalThis.navigator?.userAgentData?.platform;
13375
+ isMacOs = platform2 === "macOS" || globalThis.navigator?.platform === "MacIntel" || globalThis.navigator?.userAgent?.includes(" Mac ") === true || globalThis.process?.platform === "darwin";
13376
+ isWindows = platform2 === "Windows" || globalThis.navigator?.platform === "Win32" || globalThis.process?.platform === "win32";
13377
+ isLinux = platform2 === "Linux" || globalThis.navigator?.platform?.startsWith("Linux") === true || globalThis.navigator?.userAgent?.includes(" Linux ") === true || globalThis.process?.platform === "linux";
13378
+ isIos = platform2 === "iOS" || globalThis.navigator?.platform === "MacIntel" && globalThis.navigator?.maxTouchPoints > 1 || /iPad|iPhone|iPod/.test(globalThis.navigator?.platform);
13379
+ isAndroid = platform2 === "Android" || globalThis.navigator?.platform === "Android" || globalThis.navigator?.userAgent?.includes(" Android ") === true || globalThis.process?.platform === "android";
13380
13380
  }
13381
13381
  });
13382
13382
 
@@ -13421,11 +13421,11 @@ __export(base_exports, {
13421
13421
  setCwd: () => setCwd,
13422
13422
  synchronizedOutput: () => synchronizedOutput
13423
13423
  });
13424
- var import_node_process, import_node_os13, ESC, OSC, BEL, SEP, isTerminalApp, isWindows2, isTmux, cwdFunction, wrapOsc, cursorTo, cursorMove, cursorUp, cursorDown, cursorForward, cursorBackward, cursorLeft, cursorSavePosition, cursorRestorePosition, cursorGetPosition, cursorNextLine, cursorPrevLine, cursorHide, cursorShow, eraseLines, eraseEndLine, eraseStartLine, eraseLine, eraseDown, eraseUp, eraseScreen, scrollUp, scrollDown, clearScreen, clearViewport, isOldWindows, clearTerminal, enterAlternativeScreen, exitAlternativeScreen, beginSynchronizedOutput, endSynchronizedOutput, synchronizedOutput, beep, link, image, iTerm, ConEmu, setCwd;
13424
+ var import_node_process, import_node_os14, ESC, OSC, BEL, SEP, isTerminalApp, isWindows2, isTmux, cwdFunction, wrapOsc, cursorTo, cursorMove, cursorUp, cursorDown, cursorForward, cursorBackward, cursorLeft, cursorSavePosition, cursorRestorePosition, cursorGetPosition, cursorNextLine, cursorPrevLine, cursorHide, cursorShow, eraseLines, eraseEndLine, eraseStartLine, eraseLine, eraseDown, eraseUp, eraseScreen, scrollUp, scrollDown, clearScreen, clearViewport, isOldWindows, clearTerminal, enterAlternativeScreen, exitAlternativeScreen, beginSynchronizedOutput, endSynchronizedOutput, synchronizedOutput, beep, link, image, iTerm, ConEmu, setCwd;
13425
13425
  var init_base = __esm({
13426
13426
  "node_modules/ansi-escapes/base.js"() {
13427
13427
  import_node_process = __toESM(require("node:process"), 1);
13428
- import_node_os13 = __toESM(require("node:os"), 1);
13428
+ import_node_os14 = __toESM(require("node:os"), 1);
13429
13429
  init_environment();
13430
13430
  ESC = "\x1B[";
13431
13431
  OSC = "\x1B]";
@@ -13505,7 +13505,7 @@ var init_base = __esm({
13505
13505
  if (isBrowser || !isWindows2) {
13506
13506
  return false;
13507
13507
  }
13508
- const parts = import_node_os13.default.release().split(".");
13508
+ const parts = import_node_os14.default.release().split(".");
13509
13509
  const major = Number(parts[0]);
13510
13510
  const build = Number(parts[2] ?? 0);
13511
13511
  if (major < 10) {
@@ -31566,12 +31566,12 @@ var require_form_data = __commonJS({
31566
31566
  if (value.end != void 0 && value.end != Infinity && value.start != void 0) {
31567
31567
  callback(null, value.end + 1 - (value.start ? value.start : 0));
31568
31568
  } else {
31569
- fs15.stat(value.path, function(err, stat2) {
31569
+ fs15.stat(value.path, function(err, stat3) {
31570
31570
  if (err) {
31571
31571
  callback(err);
31572
31572
  return;
31573
31573
  }
31574
- var fileSize = stat2.size - (value.start ? value.start : 0);
31574
+ var fileSize = stat3.size - (value.start ? value.start : 0);
31575
31575
  callback(null, fileSize);
31576
31576
  });
31577
31577
  }
@@ -34615,14 +34615,14 @@ var require_axios = __commonJS({
34615
34615
  navigator: _navigator,
34616
34616
  origin
34617
34617
  });
34618
- var platform2 = {
34618
+ var platform3 = {
34619
34619
  ...utils,
34620
34620
  ...platform$1
34621
34621
  };
34622
34622
  function toURLEncodedForm(data, options) {
34623
- return toFormData(data, new platform2.classes.URLSearchParams(), {
34623
+ return toFormData(data, new platform3.classes.URLSearchParams(), {
34624
34624
  visitor: function(value, key, path29, helpers) {
34625
- if (platform2.isNode && utils$1.isBuffer(value)) {
34625
+ if (platform3.isNode && utils$1.isBuffer(value)) {
34626
34626
  this.append(key, value.toString("base64"));
34627
34627
  return false;
34628
34628
  }
@@ -34773,8 +34773,8 @@ var require_axios = __commonJS({
34773
34773
  maxContentLength: -1,
34774
34774
  maxBodyLength: -1,
34775
34775
  env: {
34776
- FormData: platform2.classes.FormData,
34777
- Blob: platform2.classes.Blob
34776
+ FormData: platform3.classes.FormData,
34777
+ Blob: platform3.classes.Blob
34778
34778
  },
34779
34779
  validateStatus: function validateStatus(status) {
34780
34780
  return status >= 200 && status < 300;
@@ -34915,7 +34915,7 @@ var require_axios = __commonJS({
34915
34915
  }
34916
34916
  var DATA_URL_PATTERN = /^([^,;]+\/[^,;]+)?((?:;[^,;=]+=[^,;]+)*)(;base64)?,([\s\S]*)$/;
34917
34917
  function fromDataURI(uri, asBlob, options) {
34918
- const _Blob = options && options.Blob || platform2.classes.Blob;
34918
+ const _Blob = options && options.Blob || platform3.classes.Blob;
34919
34919
  const protocol = parseProtocol(uri);
34920
34920
  if (asBlob === void 0 && _Blob) {
34921
34921
  asBlob = true;
@@ -35074,7 +35074,7 @@ var require_axios = __commonJS({
35074
35074
  yield blob;
35075
35075
  }
35076
35076
  };
35077
- var BOUNDARY_ALPHABET = platform2.ALPHABET.ALPHA_DIGIT + "-_";
35077
+ var BOUNDARY_ALPHABET = platform3.ALPHABET.ALPHA_DIGIT + "-_";
35078
35078
  var textEncoder = typeof TextEncoder === "function" ? new TextEncoder() : new util2.TextEncoder();
35079
35079
  var CRLF = "\r\n";
35080
35080
  var CRLF_BYTES = textEncoder.encode(CRLF);
@@ -35122,7 +35122,7 @@ var require_axios = __commonJS({
35122
35122
  const {
35123
35123
  tag = "form-data-boundary",
35124
35124
  size = 25,
35125
- boundary = tag + "-" + platform2.generateString(size, BOUNDARY_ALPHABET)
35125
+ boundary = tag + "-" + platform3.generateString(size, BOUNDARY_ALPHABET)
35126
35126
  } = options || {};
35127
35127
  if (!utils$1.isFormData(form)) {
35128
35128
  throw TypeError("FormData instance required");
@@ -35522,7 +35522,7 @@ var require_axios = __commonJS({
35522
35522
  cache.set(key, agent);
35523
35523
  return agent;
35524
35524
  }
35525
- var supportedProtocols = platform2.protocols.map((protocol) => {
35525
+ var supportedProtocols = platform3.protocols.map((protocol) => {
35526
35526
  return protocol + ":";
35527
35527
  });
35528
35528
  var decodeURIComponentSafe = (value) => {
@@ -35883,7 +35883,7 @@ var require_axios = __commonJS({
35883
35883
  }
35884
35884
  });
35885
35885
  const fullPath = buildFullPath(config2.baseURL, config2.url, config2.allowAbsoluteUrls);
35886
- const parsed = new URL(fullPath, platform2.hasBrowserEnv ? platform2.origin : void 0);
35886
+ const parsed = new URL(fullPath, platform3.hasBrowserEnv ? platform3.origin : void 0);
35887
35887
  const protocol = parsed.protocol || supportedProtocols[0];
35888
35888
  if (protocol === "data:") {
35889
35889
  if (config2.maxContentLength > -1) {
@@ -36284,11 +36284,11 @@ var require_axios = __commonJS({
36284
36284
  }
36285
36285
  });
36286
36286
  };
36287
- var isURLSameOrigin = platform2.hasStandardBrowserEnv ? /* @__PURE__ */ ((origin2, isMSIE) => (url3) => {
36288
- url3 = new URL(url3, platform2.origin);
36287
+ var isURLSameOrigin = platform3.hasStandardBrowserEnv ? /* @__PURE__ */ ((origin2, isMSIE) => (url3) => {
36288
+ url3 = new URL(url3, platform3.origin);
36289
36289
  return origin2.protocol === url3.protocol && origin2.host === url3.host && (isMSIE || origin2.port === url3.port);
36290
- })(new URL(platform2.origin), platform2.navigator && /(msie|trident)/i.test(platform2.navigator.userAgent)) : () => true;
36291
- var cookies = platform2.hasStandardBrowserEnv ? (
36290
+ })(new URL(platform3.origin), platform3.navigator && /(msie|trident)/i.test(platform3.navigator.userAgent)) : () => true;
36291
+ var cookies = platform3.hasStandardBrowserEnv ? (
36292
36292
  // Standard browser envs support document.cookie
36293
36293
  {
36294
36294
  write(name, value, expires, path29, domain2, secure, sameSite) {
@@ -36468,13 +36468,13 @@ var require_axios = __commonJS({
36468
36468
  headers.set("Authorization", "Basic " + btoa((auth.username || "") + ":" + (auth.password ? encodeUTF8(auth.password) : "")));
36469
36469
  }
36470
36470
  if (utils$1.isFormData(data)) {
36471
- if (platform2.hasStandardBrowserEnv || platform2.hasStandardBrowserWebWorkerEnv) {
36471
+ if (platform3.hasStandardBrowserEnv || platform3.hasStandardBrowserWebWorkerEnv) {
36472
36472
  headers.setContentType(void 0);
36473
36473
  } else if (utils$1.isFunction(data.getHeaders)) {
36474
36474
  setFormDataHeaders(headers, data.getHeaders(), own2("formDataHeaderPolicy"));
36475
36475
  }
36476
36476
  }
36477
- if (platform2.hasStandardBrowserEnv) {
36477
+ if (platform3.hasStandardBrowserEnv) {
36478
36478
  if (utils$1.isFunction(withXSRFToken)) {
36479
36479
  withXSRFToken = withXSRFToken(newConfig);
36480
36480
  }
@@ -36610,7 +36610,7 @@ var require_axios = __commonJS({
36610
36610
  }
36611
36611
  }
36612
36612
  const protocol = parseProtocol(_config.url);
36613
- if (protocol && !platform2.protocols.includes(protocol)) {
36613
+ if (protocol && !platform3.protocols.includes(protocol)) {
36614
36614
  reject(new AxiosError("Unsupported protocol " + protocol + ":", AxiosError.ERR_BAD_REQUEST, config2));
36615
36615
  return;
36616
36616
  }
@@ -36773,7 +36773,7 @@ var require_axios = __commonJS({
36773
36773
  const encodeText = isFetchSupported && (typeof TextEncoder2 === "function" ? /* @__PURE__ */ ((encoder) => (str) => encoder.encode(str))(new TextEncoder2()) : async (str) => new Uint8Array(await new Request(str).arrayBuffer()));
36774
36774
  const supportsRequestStream = isRequestSupported && isReadableStreamSupported && test(() => {
36775
36775
  let duplexAccessed = false;
36776
- const request = new Request(platform2.origin, {
36776
+ const request = new Request(platform3.origin, {
36777
36777
  body: new ReadableStream2(),
36778
36778
  method: "POST",
36779
36779
  get duplex() {
@@ -36810,7 +36810,7 @@ var require_axios = __commonJS({
36810
36810
  return body.size;
36811
36811
  }
36812
36812
  if (utils$1.isSpecCompliantForm(body)) {
36813
- const _request = new Request(platform2.origin, {
36813
+ const _request = new Request(platform3.origin, {
36814
36814
  method: "POST",
36815
36815
  body
36816
36816
  });
@@ -43503,6 +43503,7 @@ __export(index_exports, {
43503
43503
  DEFAULT_PROXY_ENV_REGISTRY: () => DEFAULT_PROXY_ENV_REGISTRY,
43504
43504
  DefaultModels: () => DefaultModels,
43505
43505
  ERROR_SEARCH_HINT: () => ERROR_SEARCH_HINT,
43506
+ EventBus: () => EventBus,
43506
43507
  GEMINI_MODEL_OPTIONS: () => GEMINI_MODEL_OPTIONS,
43507
43508
  GeminiModels: () => GeminiModels,
43508
43509
  GitHubClient: () => GitHubClient,
@@ -43560,6 +43561,7 @@ __export(index_exports, {
43560
43561
  checkOutputContains: () => checkOutputContains,
43561
43562
  cleanLines: () => cleanLines,
43562
43563
  clearBinaryCache: () => clearBinaryCache,
43564
+ clearBrokerLogs: () => clearBrokerLogs,
43563
43565
  clearResolveCache: () => clearResolveCache,
43564
43566
  collectCliSession: () => collectCliSession,
43565
43567
  collectOutput: () => collectOutput,
@@ -43613,6 +43615,7 @@ __export(index_exports, {
43613
43615
  generateUniqueAgentName: () => generateUniqueAgentName,
43614
43616
  getAgentName: () => getAgentName,
43615
43617
  getBaseCli: () => getBaseCli,
43618
+ getBrokerLogDir: () => getBrokerLogDir,
43616
43619
  getCachedRelayPtyPath: () => getCachedRelayPtyPath,
43617
43620
  getCliDefinition: () => getCliDefinition,
43618
43621
  getCliRegistry: () => getCliRegistry,
@@ -43656,6 +43659,7 @@ __export(index_exports, {
43656
43659
  isTrajectoryTrackingAvailable: () => isTrajectoryTrackingAvailable,
43657
43660
  isValidAgentName: () => isValidAgentName,
43658
43661
  isWorktreeStep: () => isWorktreeStep,
43662
+ listBrokerLogs: () => listBrokerLogs,
43659
43663
  listLoggedAgents: () => listLoggedAgents,
43660
43664
  listPersonas: () => listPersonas,
43661
43665
  listWorkflowSchedules: () => listWorkflowSchedules,
@@ -43671,6 +43675,7 @@ __export(index_exports, {
43671
43675
  parseTsxStderr: () => parseTsxStderr,
43672
43676
  parseVoteCommand: () => parseVoteCommand,
43673
43677
  printUpdateNotification: () => printUpdateNotification,
43678
+ pruneBrokerLogs: () => pruneBrokerLogs,
43674
43679
  readInbox: () => readInbox,
43675
43680
  resetPatternMetrics: () => resetPatternMetrics,
43676
43681
  resolveAllCustomSteps: () => resolveAllCustomSteps,
@@ -43703,6 +43708,7 @@ __export(index_exports, {
43703
43708
  stripAnsi: () => stripAnsi,
43704
43709
  stripAnsiFast: () => stripAnsiFast,
43705
43710
  stripInjectedTaskEcho: () => stripInjectedTaskEcho,
43711
+ tailBrokerLog: () => tailBrokerLog,
43706
43712
  toReleaseResult: () => toReleaseResult,
43707
43713
  toSpawnResult: () => toSpawnResult,
43708
43714
  trackPatternPerformance: () => trackPatternPerformance,
@@ -44234,8 +44240,8 @@ var import_node_child_process = require("node:child_process");
44234
44240
  var import_node_module = require("node:module");
44235
44241
  var import_node_url = require("node:url");
44236
44242
  var BROKER_NAME = "agent-relay-broker";
44237
- function getOptionalDepPackageName(platform2 = process.platform, arch = process.arch) {
44238
- return `@agent-relay/broker-${platform2}-${arch}`;
44243
+ function getOptionalDepPackageName(platform3 = process.platform, arch = process.arch) {
44244
+ return `@agent-relay/broker-${platform3}-${arch}`;
44239
44245
  }
44240
44246
  function addUniquePath(paths, candidate) {
44241
44247
  if (!candidate || paths.includes(candidate)) {
@@ -44423,6 +44429,77 @@ function formatBrokerNotFoundError() {
44423
44429
  return `@agent-relay/sdk couldn't find an agent-relay-broker binary for ${process.platform}-${process.arch}. The optional dependency ${pkgName} is expected to be installed alongside @agent-relay/sdk. Try reinstalling with --include=optional, or set BROKER_BINARY_PATH to point at a broker binary you've downloaded manually.`;
44424
44430
  }
44425
44431
 
44432
+ // packages/sdk/dist/event-bus.js
44433
+ var EventBus = class {
44434
+ // Stored type uses `unknown` for `R` so a single Set can hold handlers
44435
+ // from any overload — the dispatcher casts back when it cares about a
44436
+ // non-void return value (see `runBeforeSpawn` in `client.ts`).
44437
+ handlers = /* @__PURE__ */ new Map();
44438
+ /**
44439
+ * Register a handler for `event`. Returns an unsubscribe function that
44440
+ * removes the handler when called.
44441
+ *
44442
+ * The `R` generic is inferred from the handler return type; callers
44443
+ * that don't care about the return get the default `void` shape, while
44444
+ * events like `beforeAgentSpawn` can pass handlers that return a
44445
+ * `SpawnPatch`.
44446
+ */
44447
+ addListener(event, handler) {
44448
+ let set2 = this.handlers.get(event);
44449
+ if (!set2) {
44450
+ set2 = /* @__PURE__ */ new Set();
44451
+ this.handlers.set(event, set2);
44452
+ }
44453
+ set2.add(handler);
44454
+ return () => {
44455
+ const current = this.handlers.get(event);
44456
+ if (current !== set2)
44457
+ return;
44458
+ current.delete(handler);
44459
+ if (current.size === 0) {
44460
+ this.handlers.delete(event);
44461
+ }
44462
+ };
44463
+ }
44464
+ /** Remove a previously-registered handler. Idempotent. */
44465
+ removeListener(event, handler) {
44466
+ const set2 = this.handlers.get(event);
44467
+ if (!set2)
44468
+ return;
44469
+ set2.delete(handler);
44470
+ if (set2.size === 0) {
44471
+ this.handlers.delete(event);
44472
+ }
44473
+ }
44474
+ /** Number of currently-registered handlers for `event`. Useful for tests. */
44475
+ listenerCount(event) {
44476
+ return this.handlers.get(event)?.size ?? 0;
44477
+ }
44478
+ /** Snapshot the handlers for `event` so iteration is safe under concurrent mutation. */
44479
+ listeners(event) {
44480
+ const set2 = this.handlers.get(event);
44481
+ return set2 ? Array.from(set2) : [];
44482
+ }
44483
+ /**
44484
+ * Fire `event` with `args`, awaiting each handler sequentially in
44485
+ * registration order. Handler exceptions are caught and logged; they
44486
+ * never abort the dispatch chain.
44487
+ *
44488
+ * Return value is intentionally `void`; consumers that need to collect
44489
+ * patches (e.g. `beforeAgentSpawn`'s shallow-merge contract) iterate
44490
+ * `listeners()` directly so they can capture each handler's return.
44491
+ */
44492
+ async emit(event, ...args) {
44493
+ for (const handler of this.listeners(event)) {
44494
+ try {
44495
+ await handler(...args);
44496
+ } catch (err) {
44497
+ console.error(`[agent-relay] listener for "${String(event)}" threw:`, err);
44498
+ }
44499
+ }
44500
+ }
44501
+ };
44502
+
44426
44503
  // packages/sdk/dist/client.js
44427
44504
  function isHeadlessProvider(value) {
44428
44505
  return value === "claude" || value === "opencode";
@@ -44430,6 +44507,45 @@ function isHeadlessProvider(value) {
44430
44507
  function resolveSpawnTransport(input) {
44431
44508
  return input.transport ?? (input.provider === "opencode" ? "headless" : "pty");
44432
44509
  }
44510
+ function buildSpawnPtyBody(input) {
44511
+ return {
44512
+ name: input.name,
44513
+ cli: input.cli,
44514
+ ...input.model !== void 0 ? { model: input.model } : {},
44515
+ args: input.args ?? [],
44516
+ ...input.task !== void 0 ? { task: input.task } : {},
44517
+ channels: input.channels ?? [],
44518
+ ...input.cwd !== void 0 ? { cwd: input.cwd } : {},
44519
+ ...input.team !== void 0 ? { team: input.team } : {},
44520
+ ...input.agentToken !== void 0 ? { agentToken: input.agentToken } : {},
44521
+ ...input.shadowOf !== void 0 ? { shadowOf: input.shadowOf } : {},
44522
+ ...input.shadowMode !== void 0 ? { shadowMode: input.shadowMode } : {},
44523
+ ...input.continueFrom !== void 0 ? { continueFrom: input.continueFrom } : {},
44524
+ ...input.idleThresholdSecs !== void 0 ? { idleThresholdSecs: input.idleThresholdSecs } : {},
44525
+ ...input.restartPolicy !== void 0 ? { restartPolicy: input.restartPolicy } : {},
44526
+ ...input.skipRelayPrompt !== void 0 ? { skipRelayPrompt: input.skipRelayPrompt } : {}
44527
+ };
44528
+ }
44529
+ function buildSpawnProviderBody(input, transport) {
44530
+ return {
44531
+ name: input.name,
44532
+ cli: input.provider,
44533
+ ...input.model !== void 0 ? { model: input.model } : {},
44534
+ args: input.args ?? [],
44535
+ ...input.task !== void 0 ? { task: input.task } : {},
44536
+ channels: input.channels ?? [],
44537
+ ...input.cwd !== void 0 ? { cwd: input.cwd } : {},
44538
+ ...input.team !== void 0 ? { team: input.team } : {},
44539
+ ...input.agentToken !== void 0 ? { agentToken: input.agentToken } : {},
44540
+ ...input.shadowOf !== void 0 ? { shadowOf: input.shadowOf } : {},
44541
+ ...input.shadowMode !== void 0 ? { shadowMode: input.shadowMode } : {},
44542
+ ...input.continueFrom !== void 0 ? { continueFrom: input.continueFrom } : {},
44543
+ ...input.idleThresholdSecs !== void 0 ? { idleThresholdSecs: input.idleThresholdSecs } : {},
44544
+ ...input.restartPolicy !== void 0 ? { restartPolicy: input.restartPolicy } : {},
44545
+ ...input.skipRelayPrompt !== void 0 ? { skipRelayPrompt: input.skipRelayPrompt } : {},
44546
+ transport
44547
+ };
44548
+ }
44433
44549
  function isProcessRunning(pid) {
44434
44550
  if (!Number.isInteger(pid) || pid <= 0) {
44435
44551
  return false;
@@ -44466,8 +44582,16 @@ var AgentRelayClient = class _AgentRelayClient {
44466
44582
  child = null;
44467
44583
  /** Lease renewal timer (only for spawned brokers). */
44468
44584
  leaseTimer = null;
44585
+ brokerExitInfo = null;
44586
+ brokerExitListeners = /* @__PURE__ */ new Set();
44469
44587
  workspaceKey;
44588
+ /** Resolved broker URL — captured so call-site lifecycle contexts can surface it. */
44589
+ baseUrl;
44590
+ /** Shared multi-listener registry. Created bare when no `eventBus` is passed in. */
44591
+ eventBus;
44470
44592
  constructor(options) {
44593
+ this.baseUrl = options.baseUrl;
44594
+ this.eventBus = options.eventBus ?? new EventBus();
44471
44595
  this.transport = new BrokerTransport({
44472
44596
  baseUrl: options.baseUrl,
44473
44597
  apiKey: options.apiKey,
@@ -44475,6 +44599,32 @@ var AgentRelayClient = class _AgentRelayClient {
44475
44599
  requestTimeoutMs: options.requestTimeoutMs
44476
44600
  });
44477
44601
  }
44602
+ addListener(event, handler) {
44603
+ return this.eventBus.addListener(event, handler);
44604
+ }
44605
+ removeListener(event, handler) {
44606
+ this.eventBus.removeListener(event, handler);
44607
+ }
44608
+ /**
44609
+ * Fold `beforeAgentSpawn` patches into the input. Listeners run in
44610
+ * registration order; each may return a {@link SpawnPatch} that is
44611
+ * shallow-merged over the running result. Handler exceptions are caught
44612
+ * and logged but do not abort the chain.
44613
+ */
44614
+ async runBeforeSpawn(ctx) {
44615
+ let resolved = { ...ctx.input };
44616
+ for (const handler of this.eventBus.listeners("beforeAgentSpawn")) {
44617
+ try {
44618
+ const patch = await handler({ ...ctx, input: resolved });
44619
+ if (patch && typeof patch === "object") {
44620
+ resolved = { ...resolved, ...patch };
44621
+ }
44622
+ } catch (err) {
44623
+ console.error("[agent-relay] beforeAgentSpawn listener threw:", err);
44624
+ }
44625
+ }
44626
+ return resolved;
44627
+ }
44478
44628
  /**
44479
44629
  * Connect to an already-running broker by reading its connection file.
44480
44630
  *
@@ -44504,7 +44654,11 @@ var AgentRelayClient = class _AgentRelayClient {
44504
44654
  if (!isProcessRunning(conn.pid)) {
44505
44655
  throw new Error(`Stale broker connection file (${connPath}) points to dead pid ${conn.pid}. Start the broker with 'agent-relay up' or use AgentRelayClient.spawn().`);
44506
44656
  }
44507
- return new _AgentRelayClient({ baseUrl: conn.url, apiKey: conn.api_key });
44657
+ return new _AgentRelayClient({
44658
+ baseUrl: conn.url,
44659
+ apiKey: conn.api_key,
44660
+ ...options?.eventBus ? { eventBus: options.eventBus } : {}
44661
+ });
44508
44662
  }
44509
44663
  /**
44510
44664
  * Spawn a local broker process and return a connected client.
@@ -44564,9 +44718,11 @@ var AgentRelayClient = class _AgentRelayClient {
44564
44718
  const client = new _AgentRelayClient({
44565
44719
  baseUrl,
44566
44720
  apiKey,
44567
- requestTimeoutMs: options?.requestTimeoutMs
44721
+ requestTimeoutMs: options?.requestTimeoutMs,
44722
+ ...options?.eventBus ? { eventBus: options.eventBus } : {}
44568
44723
  });
44569
44724
  client.child = child;
44725
+ client.installManagedBrokerExitHandler(child, stderrLines);
44570
44726
  const brokerExited = new Promise((_2, reject) => {
44571
44727
  child.once("exit", (code) => {
44572
44728
  reject(new Error(formatBrokerStartupError(`Broker process exited with code ${code} during initial handshake`, child, { binaryPath, args, cwd, stdoutLines, stderrLines })));
@@ -44587,18 +44743,13 @@ var AgentRelayClient = class _AgentRelayClient {
44587
44743
  await new Promise((resolve4) => setTimeout(resolve4, 1e3));
44588
44744
  }
44589
44745
  }
44590
- client.connectEvents();
44591
- client.leaseTimer = setInterval(() => {
44592
- client.renewLease().catch(() => {
44593
- });
44594
- }, 6e4);
44595
- child.on("exit", () => {
44596
- client.disconnectEvents();
44597
- if (client.leaseTimer) {
44598
- clearInterval(client.leaseTimer);
44599
- client.leaseTimer = null;
44600
- }
44601
- });
44746
+ if (!client.brokerExitInfo) {
44747
+ client.connectEvents();
44748
+ client.leaseTimer = setInterval(() => {
44749
+ client.renewLease().catch(() => {
44750
+ });
44751
+ }, 6e4);
44752
+ }
44602
44753
  return client;
44603
44754
  }
44604
44755
  /** PID of the managed broker process, if spawned locally. */
@@ -44624,6 +44775,33 @@ var AgentRelayClient = class _AgentRelayClient {
44624
44775
  onEvent(listener) {
44625
44776
  return this.transport.onEvent(listener);
44626
44777
  }
44778
+ /**
44779
+ * Subscribe to managed broker child-process exit.
44780
+ *
44781
+ * Clients created with `new AgentRelayClient(...)` or `connect()` do not own a
44782
+ * broker child process, so this is a no-op for them.
44783
+ */
44784
+ onBrokerExit(listener) {
44785
+ if (!this.child && !this.brokerExitInfo) {
44786
+ return () => {
44787
+ };
44788
+ }
44789
+ this.brokerExitListeners.add(listener);
44790
+ if (this.brokerExitInfo) {
44791
+ const info = cloneBrokerExitInfo(this.brokerExitInfo);
44792
+ queueMicrotask(() => {
44793
+ if (this.brokerExitListeners.has(listener)) {
44794
+ try {
44795
+ listener(info);
44796
+ } catch {
44797
+ }
44798
+ }
44799
+ });
44800
+ }
44801
+ return () => {
44802
+ this.brokerExitListeners.delete(listener);
44803
+ };
44804
+ }
44627
44805
  queryEvents(filter) {
44628
44806
  return this.transport.queryEvents(filter);
44629
44807
  }
@@ -44632,53 +44810,52 @@ var AgentRelayClient = class _AgentRelayClient {
44632
44810
  }
44633
44811
  // ── Agent lifecycle ────────────────────────────────────────────────
44634
44812
  async spawnPty(input) {
44635
- return this.transport.request("/api/spawn", {
44636
- method: "POST",
44637
- body: JSON.stringify({
44638
- name: input.name,
44639
- cli: input.cli,
44640
- ...input.model !== void 0 ? { model: input.model } : {},
44641
- args: input.args ?? [],
44642
- ...input.task !== void 0 ? { task: input.task } : {},
44643
- channels: input.channels ?? [],
44644
- ...input.cwd !== void 0 ? { cwd: input.cwd } : {},
44645
- ...input.team !== void 0 ? { team: input.team } : {},
44646
- ...input.agentToken !== void 0 ? { agentToken: input.agentToken } : {},
44647
- ...input.shadowOf !== void 0 ? { shadowOf: input.shadowOf } : {},
44648
- ...input.shadowMode !== void 0 ? { shadowMode: input.shadowMode } : {},
44649
- ...input.continueFrom !== void 0 ? { continueFrom: input.continueFrom } : {},
44650
- ...input.idleThresholdSecs !== void 0 ? { idleThresholdSecs: input.idleThresholdSecs } : {},
44651
- ...input.restartPolicy !== void 0 ? { restartPolicy: input.restartPolicy } : {},
44652
- ...input.skipRelayPrompt !== void 0 ? { skipRelayPrompt: input.skipRelayPrompt } : {}
44653
- })
44654
- });
44813
+ const beforeCtx = {
44814
+ kind: "pty",
44815
+ input,
44816
+ spawnerPid: process.pid,
44817
+ spawnStartTs: (/* @__PURE__ */ new Date()).toISOString(),
44818
+ baseUrl: this.baseUrl
44819
+ };
44820
+ const t0 = Date.now();
44821
+ const resolvedInput = await this.runBeforeSpawn(beforeCtx);
44822
+ try {
44823
+ const result = await this.transport.request("/api/spawn", {
44824
+ method: "POST",
44825
+ body: JSON.stringify(buildSpawnPtyBody(resolvedInput))
44826
+ });
44827
+ await this.emitAfterSpawn(beforeCtx, resolvedInput, t0, result, void 0);
44828
+ return result;
44829
+ } catch (err) {
44830
+ await this.emitAfterSpawn(beforeCtx, resolvedInput, t0, void 0, err);
44831
+ throw err;
44832
+ }
44655
44833
  }
44656
44834
  async spawnProvider(input) {
44657
44835
  const transport = resolveSpawnTransport(input);
44658
44836
  if (transport === "headless" && !isHeadlessProvider(input.provider)) {
44659
44837
  throw new Error(`provider '${input.provider}' does not support headless transport (supported: claude, opencode)`);
44660
44838
  }
44661
- return this.transport.request("/api/spawn", {
44662
- method: "POST",
44663
- body: JSON.stringify({
44664
- name: input.name,
44665
- cli: input.provider,
44666
- ...input.model !== void 0 ? { model: input.model } : {},
44667
- args: input.args ?? [],
44668
- ...input.task !== void 0 ? { task: input.task } : {},
44669
- channels: input.channels ?? [],
44670
- ...input.cwd !== void 0 ? { cwd: input.cwd } : {},
44671
- ...input.team !== void 0 ? { team: input.team } : {},
44672
- ...input.agentToken !== void 0 ? { agentToken: input.agentToken } : {},
44673
- ...input.shadowOf !== void 0 ? { shadowOf: input.shadowOf } : {},
44674
- ...input.shadowMode !== void 0 ? { shadowMode: input.shadowMode } : {},
44675
- ...input.continueFrom !== void 0 ? { continueFrom: input.continueFrom } : {},
44676
- ...input.idleThresholdSecs !== void 0 ? { idleThresholdSecs: input.idleThresholdSecs } : {},
44677
- ...input.restartPolicy !== void 0 ? { restartPolicy: input.restartPolicy } : {},
44678
- ...input.skipRelayPrompt !== void 0 ? { skipRelayPrompt: input.skipRelayPrompt } : {},
44679
- transport
44680
- })
44681
- });
44839
+ const beforeCtx = {
44840
+ kind: "provider",
44841
+ input,
44842
+ spawnerPid: process.pid,
44843
+ spawnStartTs: (/* @__PURE__ */ new Date()).toISOString(),
44844
+ baseUrl: this.baseUrl
44845
+ };
44846
+ const t0 = Date.now();
44847
+ const resolvedInput = await this.runBeforeSpawn(beforeCtx);
44848
+ try {
44849
+ const result = await this.transport.request("/api/spawn", {
44850
+ method: "POST",
44851
+ body: JSON.stringify(buildSpawnProviderBody(resolvedInput, transport))
44852
+ });
44853
+ await this.emitAfterSpawn(beforeCtx, resolvedInput, t0, result, void 0);
44854
+ return result;
44855
+ } catch (err) {
44856
+ await this.emitAfterSpawn(beforeCtx, resolvedInput, t0, void 0, err);
44857
+ throw err;
44858
+ }
44682
44859
  }
44683
44860
  async spawnHeadless(input) {
44684
44861
  return this.spawnProvider({ ...input, transport: "headless" });
@@ -44690,10 +44867,39 @@ var AgentRelayClient = class _AgentRelayClient {
44690
44867
  return this.spawnProvider({ ...input, provider: "opencode" });
44691
44868
  }
44692
44869
  async release(name, reason) {
44693
- return this.transport.request(`/api/spawned/${encodeURIComponent(name)}`, {
44694
- method: "DELETE",
44695
- ...reason ? { body: JSON.stringify({ reason }) } : {}
44696
- });
44870
+ const beforeCtx = { name, reason, baseUrl: this.baseUrl };
44871
+ const t0 = Date.now();
44872
+ await this.eventBus.emit("beforeAgentRelease", beforeCtx);
44873
+ try {
44874
+ const result = await this.transport.request(`/api/spawned/${encodeURIComponent(name)}`, {
44875
+ method: "DELETE",
44876
+ ...reason ? { body: JSON.stringify({ reason }) } : {}
44877
+ });
44878
+ const afterCtx = {
44879
+ ...beforeCtx,
44880
+ durationMs: Date.now() - t0
44881
+ };
44882
+ await this.eventBus.emit("afterAgentRelease", afterCtx);
44883
+ return result;
44884
+ } catch (err) {
44885
+ const afterCtx = {
44886
+ ...beforeCtx,
44887
+ error: err instanceof Error ? err : new Error(String(err)),
44888
+ durationMs: Date.now() - t0
44889
+ };
44890
+ await this.eventBus.emit("afterAgentRelease", afterCtx);
44891
+ throw err;
44892
+ }
44893
+ }
44894
+ async emitAfterSpawn(beforeCtx, resolvedInput, startMs, result, error51) {
44895
+ const afterCtx = {
44896
+ ...beforeCtx,
44897
+ resolvedInput,
44898
+ ...result ? { result } : {},
44899
+ ...error51 !== void 0 ? { error: error51 instanceof Error ? error51 : new Error(String(error51)) } : {},
44900
+ durationMs: Date.now() - startMs
44901
+ };
44902
+ await this.eventBus.emit("afterAgentSpawn", afterCtx);
44697
44903
  }
44698
44904
  async listAgents() {
44699
44905
  const result = await this.transport.request("/api/spawned");
@@ -44912,6 +45118,40 @@ var AgentRelayClient = class _AgentRelayClient {
44912
45118
  async getConfig() {
44913
45119
  return this.transport.request("/api/config");
44914
45120
  }
45121
+ notifyBrokerExit(info) {
45122
+ if (this.brokerExitInfo)
45123
+ return;
45124
+ this.brokerExitInfo = cloneBrokerExitInfo(info);
45125
+ for (const listener of this.brokerExitListeners) {
45126
+ try {
45127
+ listener(cloneBrokerExitInfo(info));
45128
+ } catch {
45129
+ }
45130
+ }
45131
+ }
45132
+ installManagedBrokerExitHandler(child, stderrLines) {
45133
+ const handleExit = (code, signal) => {
45134
+ this.notifyBrokerExit({
45135
+ code,
45136
+ signal,
45137
+ pid: child.pid,
45138
+ recentStderr: [...stderrLines]
45139
+ });
45140
+ this.disconnectEvents();
45141
+ if (this.leaseTimer) {
45142
+ clearInterval(this.leaseTimer);
45143
+ this.leaseTimer = null;
45144
+ }
45145
+ if (this.child === child) {
45146
+ this.child = null;
45147
+ }
45148
+ };
45149
+ if (child.exitCode !== null || child.signalCode !== null) {
45150
+ handleExit(child.exitCode, child.signalCode);
45151
+ return;
45152
+ }
45153
+ child.once("exit", handleExit);
45154
+ }
44915
45155
  };
44916
45156
  async function waitForApiUrl(child, timeoutMs, debug) {
44917
45157
  const { createInterface: createInterface2 } = await import("node:readline");
@@ -44975,6 +45215,12 @@ function pushBufferedLine(lines, line) {
44975
45215
  lines.splice(0, lines.length - 40);
44976
45216
  }
44977
45217
  }
45218
+ function cloneBrokerExitInfo(info) {
45219
+ return {
45220
+ ...info,
45221
+ recentStderr: [...info.recentStderr]
45222
+ };
45223
+ }
44978
45224
  function formatBrokerStartupError(message, child, debug) {
44979
45225
  const details = [
44980
45226
  `pid=${child.pid ?? "unknown"}`,
@@ -70529,20 +70775,22 @@ function toWorkspaceRegistryEntry(value) {
70529
70775
  };
70530
70776
  }
70531
70777
  var AgentRelay = class {
70532
- // Event hooks — assign a callback or null to clear.
70533
- onMessageReceived = null;
70534
- onMessageSent = null;
70535
- onAgentSpawned = null;
70536
- onAgentReleased = null;
70537
- onAgentExited = null;
70538
- onAgentReady = null;
70539
- onWorkerOutput = null;
70540
- onDeliveryUpdate = null;
70541
- onAgentExitRequested = null;
70542
- onAgentIdle = null;
70543
- onAgentActivityChanged = null;
70544
- onChannelSubscribed = null;
70545
- onChannelUnsubscribed = null;
70778
+ /**
70779
+ * Multi-listener event registry. Subscribe via {@link addListener} or
70780
+ * `bus.addListener` directly; emit happens internally as broker events
70781
+ * arrive and at SDK call sites for the spawn / release lifecycle hooks.
70782
+ *
70783
+ * The bus is shared with the underlying `AgentRelayClient` (created via
70784
+ * {@link ensureStarted}) so listeners registered on either object see
70785
+ * the same events.
70786
+ */
70787
+ bus = new EventBus();
70788
+ addListener(event, handler) {
70789
+ return this.bus.addListener(event, handler);
70790
+ }
70791
+ removeListener(event, handler) {
70792
+ this.bus.removeListener(event, handler);
70793
+ }
70546
70794
  // ── Public accessors ────────────────────────────────────────────────────
70547
70795
  /** The resolved Relaycast workspace API key (available after first spawn). */
70548
70796
  get workspaceKey() {
@@ -70893,7 +71141,7 @@ var AgentRelay = class {
70893
71141
  data: input.data,
70894
71142
  mode: input.mode
70895
71143
  };
70896
- this.onMessageSent?.(msg);
71144
+ void this.bus.emit("messageSent", msg);
70897
71145
  return msg;
70898
71146
  }
70899
71147
  };
@@ -71268,7 +71516,7 @@ var AgentRelay = class {
71268
71516
  return;
71269
71517
  }
71270
71518
  state.active = active;
71271
- this.onAgentActivityChanged?.({
71519
+ void this.bus.emit("agentActivityChanged", {
71272
71520
  name,
71273
71521
  active,
71274
71522
  pendingDeliveries: state.pendingDeliveries.size,
@@ -71385,6 +71633,7 @@ var AgentRelay = class {
71385
71633
  return this.startPromise;
71386
71634
  this.startPromise = this.ensureRelaycastApiKey().then(() => AgentRelayClient.spawn({
71387
71635
  ...this.clientOptions,
71636
+ eventBus: this.bus,
71388
71637
  onStderr: (line) => {
71389
71638
  for (const listener of this.stderrListeners) {
71390
71639
  try {
@@ -71434,7 +71683,7 @@ var AgentRelay = class {
71434
71683
  threadId: event.thread_id,
71435
71684
  mode: event.injection_mode ?? event.mode
71436
71685
  };
71437
- this.onMessageReceived?.(msg);
71686
+ void this.bus.emit("messageReceived", msg);
71438
71687
  break;
71439
71688
  }
71440
71689
  case "agent_spawned": {
@@ -71443,7 +71692,7 @@ var AgentRelay = class {
71443
71692
  this.messageReadyAgents.delete(event.name);
71444
71693
  this.exitedAgents.delete(event.name);
71445
71694
  this.idleAgents.delete(event.name);
71446
- this.onAgentSpawned?.(agent);
71695
+ void this.bus.emit("agentSpawned", agent);
71447
71696
  break;
71448
71697
  }
71449
71698
  case "agent_released": {
@@ -71453,7 +71702,7 @@ var AgentRelay = class {
71453
71702
  this.readyAgents.delete(event.name);
71454
71703
  this.messageReadyAgents.delete(event.name);
71455
71704
  this.idleAgents.delete(event.name);
71456
- this.onAgentReleased?.(agent);
71705
+ void this.bus.emit("agentReleased", agent);
71457
71706
  this.knownAgents.delete(event.name);
71458
71707
  this.outputListeners.delete(event.name);
71459
71708
  this.exitResolvers.get(event.name)?.resolve("released");
@@ -71474,7 +71723,7 @@ var AgentRelay = class {
71474
71723
  if (event.reason !== void 0) {
71475
71724
  agent.exitReason = event.reason;
71476
71725
  }
71477
- this.onAgentExited?.(agent);
71726
+ void this.bus.emit("agentExited", agent);
71478
71727
  this.knownAgents.delete(event.name);
71479
71728
  this.outputListeners.delete(event.name);
71480
71729
  this.exitResolvers.get(event.name)?.resolve("exited");
@@ -71486,7 +71735,7 @@ var AgentRelay = class {
71486
71735
  case "agent_exit": {
71487
71736
  const agent = this.knownAgents.get(event.name) ?? this.ensureAgentHandle(event.name, "pty", []);
71488
71737
  agent.exitReason = event.reason;
71489
- this.onAgentExitRequested?.({ name: event.name, reason: event.reason });
71738
+ void this.bus.emit("agentExitRequested", { name: event.name, reason: event.reason });
71490
71739
  break;
71491
71740
  }
71492
71741
  case "worker_ready": {
@@ -71494,17 +71743,17 @@ var AgentRelay = class {
71494
71743
  this.readyAgents.add(event.name);
71495
71744
  this.exitedAgents.delete(event.name);
71496
71745
  this.idleAgents.delete(event.name);
71497
- this.onAgentReady?.(agent);
71746
+ void this.bus.emit("agentReady", agent);
71498
71747
  break;
71499
71748
  }
71500
71749
  case "channel_subscribed": {
71501
71750
  this.addAgentChannels(event.name, event.channels);
71502
- this.onChannelSubscribed?.(event.name, event.channels);
71751
+ void this.bus.emit("channelSubscribed", { agent: event.name, channels: event.channels });
71503
71752
  break;
71504
71753
  }
71505
71754
  case "channel_unsubscribed": {
71506
71755
  this.removeAgentChannels(event.name, event.channels);
71507
- this.onChannelUnsubscribed?.(event.name, event.channels);
71756
+ void this.bus.emit("channelUnsubscribed", { agent: event.name, channels: event.channels });
71508
71757
  break;
71509
71758
  }
71510
71759
  case "delivery_queued": {
@@ -71550,7 +71799,7 @@ var AgentRelay = class {
71550
71799
  }
71551
71800
  case "worker_stream": {
71552
71801
  this.idleAgents.delete(event.name);
71553
- this.onWorkerOutput?.({
71802
+ void this.bus.emit("workerOutput", {
71554
71803
  name: event.name,
71555
71804
  stream: event.stream,
71556
71805
  chunk: event.chunk
@@ -71561,7 +71810,7 @@ var AgentRelay = class {
71561
71810
  case "agent_idle": {
71562
71811
  this.clearAgentDeliveries(event.name, "agent_idle");
71563
71812
  this.idleAgents.add(event.name);
71564
- this.onAgentIdle?.({
71813
+ void this.bus.emit("agentIdle", {
71565
71814
  name: event.name,
71566
71815
  idleSecs: event.idle_secs
71567
71816
  });
@@ -71571,7 +71820,7 @@ var AgentRelay = class {
71571
71820
  }
71572
71821
  }
71573
71822
  if (event.kind.startsWith("delivery_") || event.kind.startsWith("message_delivery_")) {
71574
- this.onDeliveryUpdate?.(event);
71823
+ void this.bus.emit("deliveryUpdate", event);
71575
71824
  }
71576
71825
  });
71577
71826
  }
@@ -71730,7 +71979,7 @@ var AgentRelay = class {
71730
71979
  data: input.data,
71731
71980
  mode: input.mode
71732
71981
  };
71733
- relay.onMessageSent?.(msg);
71982
+ void relay.bus.emit("messageSent", msg);
71734
71983
  return msg;
71735
71984
  },
71736
71985
  async subscribe(channelsToAdd) {
@@ -71855,6 +72104,161 @@ var AgentRelay = class {
71855
72104
  }
71856
72105
  };
71857
72106
 
72107
+ // packages/sdk/dist/broker-logs.js
72108
+ var import_node_os4 = require("node:os");
72109
+ var import_node_path8 = require("node:path");
72110
+ var import_promises2 = require("node:fs/promises");
72111
+ var LOG_NAME_PATTERN = /^(?<brokerId>.+)\.log(?:\.(?<date>\d{4}-\d{2}-\d{2}))?$/;
72112
+ function getBrokerLogDir() {
72113
+ const home = (0, import_node_os4.homedir)();
72114
+ switch ((0, import_node_os4.platform)()) {
72115
+ case "darwin":
72116
+ return (0, import_node_path8.join)(home, "Library", "Logs", "agent-relay");
72117
+ case "win32": {
72118
+ const localAppData = process.env.LOCALAPPDATA ?? (0, import_node_path8.join)(home, "AppData", "Local");
72119
+ return (0, import_node_path8.join)(localAppData, "agent-relay", "Logs");
72120
+ }
72121
+ default: {
72122
+ const stateHome = process.env.XDG_STATE_HOME && process.env.XDG_STATE_HOME.length > 0 ? process.env.XDG_STATE_HOME : (0, import_node_path8.join)(home, ".local", "state");
72123
+ return (0, import_node_path8.join)(stateHome, "agent-relay", "logs");
72124
+ }
72125
+ }
72126
+ }
72127
+ async function listBrokerLogs(dir) {
72128
+ const logDir = dir ?? getBrokerLogDir();
72129
+ let entries;
72130
+ try {
72131
+ entries = await (0, import_promises2.readdir)(logDir);
72132
+ } catch (err) {
72133
+ if (err.code === "ENOENT")
72134
+ return [];
72135
+ throw err;
72136
+ }
72137
+ const files = [];
72138
+ for (const name of entries) {
72139
+ const match = LOG_NAME_PATTERN.exec(name);
72140
+ if (!match || !match.groups)
72141
+ continue;
72142
+ const fullPath = (0, import_node_path8.join)(logDir, name);
72143
+ let info;
72144
+ try {
72145
+ info = await (0, import_promises2.stat)(fullPath);
72146
+ } catch {
72147
+ continue;
72148
+ }
72149
+ if (!info.isFile())
72150
+ continue;
72151
+ files.push({
72152
+ path: fullPath,
72153
+ name,
72154
+ brokerId: match.groups.brokerId,
72155
+ date: match.groups.date ?? null,
72156
+ size: info.size,
72157
+ mtime: info.mtime
72158
+ });
72159
+ }
72160
+ files.sort((a, b2) => b2.mtime.getTime() - a.mtime.getTime());
72161
+ return files;
72162
+ }
72163
+ async function tailBrokerLog(brokerId, options = {}) {
72164
+ const lines = options.lines ?? 200;
72165
+ const files = (await listBrokerLogs(options.dir)).filter((f2) => f2.brokerId === brokerId);
72166
+ if (files.length === 0)
72167
+ return null;
72168
+ const target = files[0];
72169
+ return { path: target.path, content: await tailFile2(target.path, lines) };
72170
+ }
72171
+ async function pruneBrokerLogs(options = {}) {
72172
+ const keepDays = options.keepDays ?? 7;
72173
+ const cutoff = Date.now() - keepDays * 24 * 60 * 60 * 1e3;
72174
+ const files = await listBrokerLogs(options.dir);
72175
+ const removed = [];
72176
+ const kept = [];
72177
+ for (const file2 of files) {
72178
+ if (options.brokerId && file2.brokerId !== options.brokerId) {
72179
+ kept.push(file2);
72180
+ continue;
72181
+ }
72182
+ if (file2.date === null) {
72183
+ kept.push(file2);
72184
+ continue;
72185
+ }
72186
+ if (file2.mtime.getTime() >= cutoff) {
72187
+ kept.push(file2);
72188
+ continue;
72189
+ }
72190
+ if (!options.dryRun) {
72191
+ try {
72192
+ await (0, import_promises2.unlink)(file2.path);
72193
+ } catch (err) {
72194
+ if (err.code !== "ENOENT")
72195
+ throw err;
72196
+ }
72197
+ }
72198
+ removed.push(file2);
72199
+ }
72200
+ return { removed, kept };
72201
+ }
72202
+ async function clearBrokerLogs(options = {}) {
72203
+ const files = await listBrokerLogs(options.dir);
72204
+ const target = options.brokerId ? files.filter((f2) => f2.brokerId === options.brokerId) : files;
72205
+ if (options.dryRun)
72206
+ return target;
72207
+ for (const file2 of target) {
72208
+ try {
72209
+ await (0, import_promises2.unlink)(file2.path);
72210
+ } catch (err) {
72211
+ if (err.code !== "ENOENT")
72212
+ throw err;
72213
+ }
72214
+ }
72215
+ return target;
72216
+ }
72217
+ async function tailFile2(filePath, lines) {
72218
+ const CHUNK = 8192;
72219
+ let fh;
72220
+ try {
72221
+ fh = await (0, import_promises2.open)(filePath, "r");
72222
+ const { size } = await fh.stat();
72223
+ if (size === 0)
72224
+ return "";
72225
+ if (size <= CHUNK) {
72226
+ const buf = Buffer.alloc(size);
72227
+ await fh.read(buf, 0, size, 0);
72228
+ return tailLines(buf.toString("utf-8"), lines);
72229
+ }
72230
+ const chunks = [];
72231
+ let position = size;
72232
+ let newlines = 0;
72233
+ while (position > 0 && newlines <= lines) {
72234
+ const readSize = Math.min(CHUNK, position);
72235
+ position -= readSize;
72236
+ const buf = Buffer.alloc(readSize);
72237
+ await fh.read(buf, 0, readSize, position);
72238
+ chunks.unshift(buf);
72239
+ newlines += countNewlines(buf);
72240
+ }
72241
+ const combined = Buffer.concat(chunks).toString("utf-8");
72242
+ return tailLines(combined, lines);
72243
+ } finally {
72244
+ if (fh)
72245
+ await fh.close();
72246
+ }
72247
+ }
72248
+ function tailLines(text, count) {
72249
+ const split = text.split("\n");
72250
+ if (split.length > 0 && split[split.length - 1] === "")
72251
+ split.pop();
72252
+ return split.slice(-count).join("\n");
72253
+ }
72254
+ function countNewlines(buf) {
72255
+ let n = 0;
72256
+ for (const byte of buf)
72257
+ if (byte === 10)
72258
+ n++;
72259
+ return n;
72260
+ }
72261
+
71858
72262
  // packages/sdk/dist/consensus.js
71859
72263
  var import_node_crypto3 = require("node:crypto");
71860
72264
  var import_node_events = require("node:events");
@@ -72394,7 +72798,7 @@ var ShadowManager = class {
72394
72798
  * Determine which shadows should receive a copy of a message
72395
72799
  * between `from` and `to`. Returns a list of shadow copies to deliver.
72396
72800
  *
72397
- * Call this from your `onMessageReceived` / `onMessageSent` hooks
72801
+ * Call this from your `messageReceived` / `messageSent` listeners
72398
72802
  * to fan out shadow copies.
72399
72803
  */
72400
72804
  intercept(from, to2) {
@@ -72709,9 +73113,9 @@ function isRestrictedAgent(agent) {
72709
73113
  var import_node_child_process8 = require("node:child_process");
72710
73114
  var import_node_crypto8 = require("node:crypto");
72711
73115
  var import_node_fs21 = require("node:fs");
72712
- var import_promises8 = require("node:fs/promises");
72713
- var import_node_os9 = require("node:os");
72714
- var import_node_path29 = __toESM(require("node:path"), 1);
73116
+ var import_promises9 = require("node:fs/promises");
73117
+ var import_node_os10 = require("node:os");
73118
+ var import_node_path30 = __toESM(require("node:path"), 1);
72715
73119
  var import_chalk = __toESM(require_source(), 1);
72716
73120
  var import_ignore2 = __toESM(require_ignore(), 1);
72717
73121
  var import_yaml2 = __toESM(require_dist(), 1);
@@ -72882,15 +73286,15 @@ async function spawnFromEnv(options = {}) {
72882
73286
  cwd: policy.cwd ?? process.cwd(),
72883
73287
  env
72884
73288
  });
72885
- relay.onAgentSpawned = (agent) => {
73289
+ relay.addListener("agentSpawned", (agent) => {
72886
73290
  console.log(`[spawn-from-env] Agent spawned: ${agent.name}`);
72887
- };
72888
- relay.onAgentReady = (agent) => {
73291
+ });
73292
+ relay.addListener("agentReady", (agent) => {
72889
73293
  console.log(`[spawn-from-env] Agent ready: ${agent.name}`);
72890
- };
72891
- relay.onAgentExited = (agent) => {
73294
+ });
73295
+ relay.addListener("agentExited", (agent) => {
72892
73296
  console.log(`[spawn-from-env] Agent exited: ${agent.name} code=${agent.exitCode ?? "none"} signal=${agent.exitSignal ?? "none"}`);
72893
- };
73297
+ });
72894
73298
  try {
72895
73299
  const agent = await relay.spawnPty({
72896
73300
  name: policy.name,
@@ -72912,10 +73316,10 @@ async function spawnFromEnv(options = {}) {
72912
73316
 
72913
73317
  // packages/sdk/dist/cli-resolver.js
72914
73318
  var import_node_child_process4 = require("node:child_process");
72915
- var import_promises2 = require("node:fs/promises");
73319
+ var import_promises3 = require("node:fs/promises");
72916
73320
  var import_node_fs5 = require("node:fs");
72917
- var import_node_path8 = require("node:path");
72918
- var import_node_os4 = require("node:os");
73321
+ var import_node_path9 = require("node:path");
73322
+ var import_node_os5 = require("node:os");
72919
73323
  var import_node_util2 = require("node:util");
72920
73324
  var execFileAsync = (0, import_node_util2.promisify)(import_node_child_process4.execFile);
72921
73325
  var resolveCache = /* @__PURE__ */ new Map();
@@ -72924,7 +73328,7 @@ function clearResolveCache() {
72924
73328
  }
72925
73329
  function expandHome2(p2) {
72926
73330
  if (p2.startsWith("~/")) {
72927
- return (0, import_node_path8.join)((0, import_node_os4.homedir)(), p2.slice(2));
73331
+ return (0, import_node_path9.join)((0, import_node_os5.homedir)(), p2.slice(2));
72928
73332
  }
72929
73333
  return p2;
72930
73334
  }
@@ -72953,9 +73357,9 @@ async function resolveCli(cli) {
72953
73357
  if (seen.has(expanded))
72954
73358
  continue;
72955
73359
  seen.add(expanded);
72956
- const candidate = (0, import_node_path8.join)(expanded, binary);
73360
+ const candidate = (0, import_node_path9.join)(expanded, binary);
72957
73361
  try {
72958
- await (0, import_promises2.access)(candidate, import_promises2.constants.X_OK);
73362
+ await (0, import_promises3.access)(candidate, import_promises3.constants.X_OK);
72959
73363
  const result = { binary, path: candidate };
72960
73364
  resolveCache.set(cli, result);
72961
73365
  return result;
@@ -72992,7 +73396,7 @@ function resolveCliSync(cli) {
72992
73396
  if (seen.has(expanded))
72993
73397
  continue;
72994
73398
  seen.add(expanded);
72995
- const candidate = (0, import_node_path8.join)(expanded, binary);
73399
+ const candidate = (0, import_node_path9.join)(expanded, binary);
72996
73400
  try {
72997
73401
  (0, import_node_fs5.accessSync)(candidate, import_node_fs5.constants.X_OK);
72998
73402
  const result = { binary, path: candidate };
@@ -73099,11 +73503,11 @@ function isProxyEnabled(agentDef, swarmConfig) {
73099
73503
 
73100
73504
  // packages/sdk/dist/workflows/custom-steps.js
73101
73505
  var import_node_fs6 = require("node:fs");
73102
- var import_node_path9 = __toESM(require("node:path"), 1);
73506
+ var import_node_path10 = __toESM(require("node:path"), 1);
73103
73507
  var import_yaml = __toESM(require_dist(), 1);
73104
73508
  var CUSTOM_STEPS_FILE = ".relay/steps.yaml";
73105
73509
  function loadCustomSteps(cwd) {
73106
- const stepsPath = import_node_path9.default.join(cwd, CUSTOM_STEPS_FILE);
73510
+ const stepsPath = import_node_path10.default.join(cwd, CUSTOM_STEPS_FILE);
73107
73511
  const steps = /* @__PURE__ */ new Map();
73108
73512
  if (!(0, import_node_fs6.existsSync)(stepsPath)) {
73109
73513
  return steps;
@@ -73359,20 +73763,20 @@ function resolveAllCustomSteps(steps, customSteps) {
73359
73763
  return steps.map((step) => resolveCustomStep(step, customSteps));
73360
73764
  }
73361
73765
  function customStepsFileExists(cwd) {
73362
- return (0, import_node_fs6.existsSync)(import_node_path9.default.join(cwd, CUSTOM_STEPS_FILE));
73766
+ return (0, import_node_fs6.existsSync)(import_node_path10.default.join(cwd, CUSTOM_STEPS_FILE));
73363
73767
  }
73364
73768
  function getCustomStepsPath(cwd) {
73365
- return import_node_path9.default.join(cwd, CUSTOM_STEPS_FILE);
73769
+ return import_node_path10.default.join(cwd, CUSTOM_STEPS_FILE);
73366
73770
  }
73367
73771
 
73368
73772
  // packages/sdk/dist/provisioner/index.js
73369
73773
  var import_node_fs16 = require("node:fs");
73370
- var import_node_path23 = __toESM(require("node:path"), 1);
73774
+ var import_node_path24 = __toESM(require("node:path"), 1);
73371
73775
 
73372
73776
  // packages/sdk/dist/provisioner/audit.js
73373
- var import_promises3 = require("node:fs/promises");
73374
- var import_node_path10 = __toESM(require("node:path"), 1);
73375
- var DEFAULT_PERMISSION_AUDIT_RELATIVE_PATH = import_node_path10.default.join(".agent-relay", "permission-audit.json");
73777
+ var import_promises4 = require("node:fs/promises");
73778
+ var import_node_path11 = __toESM(require("node:path"), 1);
73779
+ var DEFAULT_PERMISSION_AUDIT_RELATIVE_PATH = import_node_path11.default.join(".agent-relay", "permission-audit.json");
73376
73780
  function isPlainObject4(value) {
73377
73781
  return typeof value === "object" && value !== null && !Array.isArray(value);
73378
73782
  }
@@ -73395,7 +73799,7 @@ function sanitizeJsonValue(value, key) {
73395
73799
  return String(value);
73396
73800
  }
73397
73801
  function getDefaultPermissionAuditPath(projectDir) {
73398
- return import_node_path10.default.resolve(projectDir, DEFAULT_PERMISSION_AUDIT_RELATIVE_PATH);
73802
+ return import_node_path11.default.resolve(projectDir, DEFAULT_PERMISSION_AUDIT_RELATIVE_PATH);
73399
73803
  }
73400
73804
  var PermissionAuditLog = class {
73401
73805
  entries = [];
@@ -73420,8 +73824,8 @@ var PermissionAuditLog = class {
73420
73824
  };
73421
73825
  }
73422
73826
  async writeTo(filePath) {
73423
- await (0, import_promises3.mkdir)(import_node_path10.default.dirname(filePath), { recursive: true });
73424
- await (0, import_promises3.writeFile)(filePath, `${JSON.stringify(this.toJSON(), null, 2)}
73827
+ await (0, import_promises4.mkdir)(import_node_path11.default.dirname(filePath), { recursive: true });
73828
+ await (0, import_promises4.writeFile)(filePath, `${JSON.stringify(this.toJSON(), null, 2)}
73425
73829
  `, "utf8");
73426
73830
  }
73427
73831
  summary() {
@@ -73442,7 +73846,7 @@ var PermissionAuditLog = class {
73442
73846
  // packages/sdk/dist/provisioner/compiler.js
73443
73847
  var import_ignore = __toESM(require_ignore(), 1);
73444
73848
  var import_node_fs7 = require("node:fs");
73445
- var import_node_path11 = __toESM(require("node:path"), 1);
73849
+ var import_node_path12 = __toESM(require("node:path"), 1);
73446
73850
  var SKIPPED_DIRS = /* @__PURE__ */ new Set([".git", ".relay", "node_modules"]);
73447
73851
  function cleanPatterns(content) {
73448
73852
  return content.split(/\r?\n/u).map((line) => line.trim()).filter((line) => line !== "" && !line.startsWith("#"));
@@ -73485,15 +73889,15 @@ function createMatcher(patterns) {
73485
73889
  return matcher;
73486
73890
  }
73487
73891
  function loadDotfileRules(projectDir, agentName) {
73488
- const resolvedProjectDir = import_node_path11.default.resolve(projectDir);
73892
+ const resolvedProjectDir = import_node_path12.default.resolve(projectDir);
73489
73893
  return {
73490
73894
  deny: unique([
73491
- ...readPatternFile(import_node_path11.default.join(resolvedProjectDir, ".agentignore")),
73492
- ...readPatternFile(import_node_path11.default.join(resolvedProjectDir, `.${agentName}.agentignore`))
73895
+ ...readPatternFile(import_node_path12.default.join(resolvedProjectDir, ".agentignore")),
73896
+ ...readPatternFile(import_node_path12.default.join(resolvedProjectDir, `.${agentName}.agentignore`))
73493
73897
  ]),
73494
73898
  readonly: unique([
73495
- ...readPatternFile(import_node_path11.default.join(resolvedProjectDir, ".agentreadonly")),
73496
- ...readPatternFile(import_node_path11.default.join(resolvedProjectDir, `.${agentName}.agentreadonly`))
73899
+ ...readPatternFile(import_node_path12.default.join(resolvedProjectDir, ".agentreadonly")),
73900
+ ...readPatternFile(import_node_path12.default.join(resolvedProjectDir, `.${agentName}.agentreadonly`))
73497
73901
  ])
73498
73902
  };
73499
73903
  }
@@ -73508,9 +73912,9 @@ function resolveScopedWorkdirPatterns(projectDir, workdir) {
73508
73912
  if (!workdir) {
73509
73913
  return void 0;
73510
73914
  }
73511
- const resolvedProjectDir = import_node_path11.default.resolve(projectDir);
73512
- const resolvedWorkdir = import_node_path11.default.resolve(resolvedProjectDir, workdir);
73513
- const relativeWorkdir = normalizeRelativePath(import_node_path11.default.relative(resolvedProjectDir, resolvedWorkdir));
73915
+ const resolvedProjectDir = import_node_path12.default.resolve(projectDir);
73916
+ const resolvedWorkdir = import_node_path12.default.resolve(resolvedProjectDir, workdir);
73917
+ const relativeWorkdir = normalizeRelativePath(import_node_path12.default.relative(resolvedProjectDir, resolvedWorkdir));
73514
73918
  if (relativeWorkdir === "" || relativeWorkdir === ".") {
73515
73919
  return void 0;
73516
73920
  }
@@ -73528,8 +73932,8 @@ function walkProjectFiles(projectDir, currentDir = projectDir, files = []) {
73528
73932
  if (entry.isDirectory() && SKIPPED_DIRS.has(entry.name)) {
73529
73933
  continue;
73530
73934
  }
73531
- const fullPath = import_node_path11.default.join(currentDir, entry.name);
73532
- const relativePath = normalizeRelativePath(import_node_path11.default.relative(projectDir, fullPath));
73935
+ const fullPath = import_node_path12.default.join(currentDir, entry.name);
73936
+ const relativePath = normalizeRelativePath(import_node_path12.default.relative(projectDir, fullPath));
73533
73937
  if (entry.isDirectory()) {
73534
73938
  walkProjectFiles(projectDir, fullPath, files);
73535
73939
  continue;
@@ -73573,7 +73977,7 @@ function buildSources(dotfileRules, preset, presetRules, fileRules, rawScopes, i
73573
73977
  function buildAcl(agentName, readonlyPaths, readwritePaths, deniedPaths) {
73574
73978
  const aclMap = /* @__PURE__ */ new Map();
73575
73979
  const addRule = (relativePath, rule) => {
73576
- const aclDir = normalizeAclDir(import_node_path11.default.posix.dirname(normalizeRelativePath(relativePath)));
73980
+ const aclDir = normalizeAclDir(import_node_path12.default.posix.dirname(normalizeRelativePath(relativePath)));
73577
73981
  const rules = aclMap.get(aclDir) ?? /* @__PURE__ */ new Set();
73578
73982
  rules.add(rule);
73579
73983
  aclMap.set(aclDir, rules);
@@ -73587,13 +73991,13 @@ function buildAcl(agentName, readonlyPaths, readwritePaths, deniedPaths) {
73587
73991
  }
73588
73992
  const deniedDirs = /* @__PURE__ */ new Map();
73589
73993
  for (const relativePath of deniedPaths) {
73590
- const aclDir = normalizeAclDir(import_node_path11.default.posix.dirname(normalizeRelativePath(relativePath)));
73994
+ const aclDir = normalizeAclDir(import_node_path12.default.posix.dirname(normalizeRelativePath(relativePath)));
73591
73995
  const summary = deniedDirs.get(aclDir) ?? { denied: 0, allowed: 0 };
73592
73996
  summary.denied += 1;
73593
73997
  deniedDirs.set(aclDir, summary);
73594
73998
  }
73595
73999
  for (const relativePath of [...readonlyPaths, ...readwritePaths]) {
73596
- const aclDir = normalizeAclDir(import_node_path11.default.posix.dirname(normalizeRelativePath(relativePath)));
74000
+ const aclDir = normalizeAclDir(import_node_path12.default.posix.dirname(normalizeRelativePath(relativePath)));
73597
74001
  const summary = deniedDirs.get(aclDir) ?? { denied: 0, allowed: 0 };
73598
74002
  summary.allowed += 1;
73599
74003
  deniedDirs.set(aclDir, summary);
@@ -73643,7 +74047,7 @@ function compileAgentPermissions(input) {
73643
74047
  const permissions = input.permissions ?? {};
73644
74048
  const effectiveAccess = permissions.access ?? "readwrite";
73645
74049
  const inherited = effectiveAccess !== "full" && permissions.inherit !== false;
73646
- const projectDir = import_node_path11.default.resolve(input.projectDir);
74050
+ const projectDir = import_node_path12.default.resolve(input.projectDir);
73647
74051
  const scopedInput = input;
73648
74052
  const dotfileRules = inherited ? loadDotfileRules(projectDir, input.agentName) : { deny: [], readonly: [] };
73649
74053
  const presetRules = expandPreset(effectiveAccess, {
@@ -73747,16 +74151,16 @@ function mergePermissionSources(dotfileScopes, yamlScopes, rawScopes) {
73747
74151
  var import_node_child_process5 = require("node:child_process");
73748
74152
  var import_node_crypto4 = require("node:crypto");
73749
74153
  var import_node_fs8 = require("node:fs");
73750
- var import_promises4 = require("node:fs/promises");
74154
+ var import_promises5 = require("node:fs/promises");
73751
74155
  var import_node_https = __toESM(require("node:https"), 1);
73752
- var import_node_os5 = __toESM(require("node:os"), 1);
73753
- var import_node_path12 = __toESM(require("node:path"), 1);
74156
+ var import_node_os6 = __toESM(require("node:os"), 1);
74157
+ var import_node_path13 = __toESM(require("node:path"), 1);
73754
74158
  var RELAYFILE_VERSION = "0.1.6";
73755
74159
  var RELEASE_BASE_URL = "https://github.com/AgentWorkforce/relayfile/releases/download";
73756
74160
  var CHECKSUMS_FILE = "checksums.txt";
73757
- var CACHE_DIR = import_node_path12.default.join(import_node_os5.default.homedir(), ".agent-relay", "bin");
73758
- var CACHE_PATH = import_node_path12.default.join(CACHE_DIR, "relayfile-mount");
73759
- var VERSION_PATH = import_node_path12.default.join(CACHE_DIR, "relayfile-mount.version");
74161
+ var CACHE_DIR = import_node_path13.default.join(import_node_os6.default.homedir(), ".agent-relay", "bin");
74162
+ var CACHE_PATH = import_node_path13.default.join(CACHE_DIR, "relayfile-mount");
74163
+ var VERSION_PATH = import_node_path13.default.join(CACHE_DIR, "relayfile-mount.version");
73760
74164
  var SUPPORTED_TARGETS = ["darwin-arm64", "darwin-amd64", "linux-arm64", "linux-amd64"].join(", ");
73761
74165
  var PLATFORM_ARCH_MAP = {
73762
74166
  "darwin:arm64": "darwin-arm64",
@@ -73768,9 +74172,9 @@ function ensureCacheDir() {
73768
74172
  (0, import_node_fs8.mkdirSync)(CACHE_DIR, { recursive: true });
73769
74173
  }
73770
74174
  function getRelayfileTarget() {
73771
- const target = PLATFORM_ARCH_MAP[`${import_node_os5.default.platform()}:${import_node_os5.default.arch()}`];
74175
+ const target = PLATFORM_ARCH_MAP[`${import_node_os6.default.platform()}:${import_node_os6.default.arch()}`];
73772
74176
  if (!target) {
73773
- throw new Error(`Unsupported platform for relayfile-mount: ${import_node_os5.default.platform()}-${import_node_os5.default.arch()}. Supported targets: ${SUPPORTED_TARGETS}.`);
74177
+ throw new Error(`Unsupported platform for relayfile-mount: ${import_node_os6.default.platform()}-${import_node_os6.default.arch()}. Supported targets: ${SUPPORTED_TARGETS}.`);
73774
74178
  }
73775
74179
  return target;
73776
74180
  }
@@ -73883,7 +74287,7 @@ function getExpectedChecksum(checksumContent, binaryName) {
73883
74287
  if (!match) {
73884
74288
  continue;
73885
74289
  }
73886
- const entryName = import_node_path12.default.basename(match[2].trim());
74290
+ const entryName = import_node_path13.default.basename(match[2].trim());
73887
74291
  if (entryName === binaryName) {
73888
74292
  return match[1].toLowerCase();
73889
74293
  }
@@ -73900,7 +74304,7 @@ async function verifyChecksum(filePath, binaryName) {
73900
74304
  }
73901
74305
  }
73902
74306
  function resignBinaryForMacOS(binaryPath) {
73903
- if (import_node_os5.default.platform() !== "darwin") {
74307
+ if (import_node_os6.default.platform() !== "darwin") {
73904
74308
  return;
73905
74309
  }
73906
74310
  try {
@@ -73913,7 +74317,7 @@ async function ensureRelayfileMountBinary(binaryPath) {
73913
74317
  return binaryPath;
73914
74318
  }
73915
74319
  if (process.env.RELAYFILE_ROOT) {
73916
- return import_node_path12.default.join(process.env.RELAYFILE_ROOT, "bin", "relayfile-mount");
74320
+ return import_node_path13.default.join(process.env.RELAYFILE_ROOT, "bin", "relayfile-mount");
73917
74321
  }
73918
74322
  const target = getRelayfileTarget();
73919
74323
  const binaryName = `relayfile-mount-${target}`;
@@ -73925,7 +74329,7 @@ async function ensureRelayfileMountBinary(binaryPath) {
73925
74329
  }
73926
74330
  return CACHE_PATH;
73927
74331
  }
73928
- const tempPath = import_node_path12.default.join(CACHE_DIR, `relayfile-mount.${process.pid}.${Date.now()}.download`);
74332
+ const tempPath = import_node_path13.default.join(CACHE_DIR, `relayfile-mount.${process.pid}.${Date.now()}.download`);
73929
74333
  try {
73930
74334
  await downloadBinary(downloadUrl, tempPath);
73931
74335
  await verifyChecksum(tempPath, binaryName);
@@ -73997,7 +74401,7 @@ async function ensureRelayfileMount(config2) {
73997
74401
  if (!(0, import_node_fs8.existsSync)(binaryPath)) {
73998
74402
  throw new Error(`missing relayfile mount binary: ${binaryPath}`);
73999
74403
  }
74000
- const mountPoint = config2.mountPoint ?? await (0, import_promises4.mkdtemp)(import_node_path12.default.join(import_node_os5.default.tmpdir(), `relayfile-mount-${config2.workspace}-`));
74404
+ const mountPoint = config2.mountPoint ?? await (0, import_promises5.mkdtemp)(import_node_path13.default.join(import_node_os6.default.tmpdir(), `relayfile-mount-${config2.workspace}-`));
74001
74405
  (0, import_node_fs8.mkdirSync)(mountPoint, { recursive: true });
74002
74406
  const mountBaseArgs = [
74003
74407
  "--base-url",
@@ -74041,12 +74445,12 @@ async function ensureRelayfileMount(config2) {
74041
74445
  if (mountProc) {
74042
74446
  await stopMountProcess(mountProc).catch(() => void 0);
74043
74447
  }
74044
- await (0, import_promises4.rm)(mountPoint, { recursive: true, force: true }).catch(() => void 0);
74448
+ await (0, import_promises5.rm)(mountPoint, { recursive: true, force: true }).catch(() => void 0);
74045
74449
  const message = error51 instanceof Error ? error51.message : String(error51);
74046
74450
  throw new Error(`${startupPhase} failed for ${config2.workspace}: ${message}`);
74047
74451
  }
74048
74452
  if (!mountProc || typeof mountProc.pid !== "number") {
74049
- await (0, import_promises4.rm)(mountPoint, { recursive: true, force: true }).catch(() => void 0);
74453
+ await (0, import_promises5.rm)(mountPoint, { recursive: true, force: true }).catch(() => void 0);
74050
74454
  throw new Error(`mount process startup failed for ${config2.workspace}: missing process id`);
74051
74455
  }
74052
74456
  let stopped = false;
@@ -74059,7 +74463,7 @@ async function ensureRelayfileMount(config2) {
74059
74463
  }
74060
74464
  stopped = true;
74061
74465
  await stopMountProcess(mountProc).catch(() => void 0);
74062
- await (0, import_promises4.rm)(mountPoint, { recursive: true, force: true }).catch(() => void 0);
74466
+ await (0, import_promises5.rm)(mountPoint, { recursive: true, force: true }).catch(() => void 0);
74063
74467
  }
74064
74468
  };
74065
74469
  }
@@ -74905,7 +75309,7 @@ var debugEnabled2 = (() => {
74905
75309
 
74906
75310
  // packages/sdk/dist/provisioner/seeder.js
74907
75311
  var import_node_fs15 = __toESM(require("node:fs"), 1);
74908
- var import_node_path22 = __toESM(require("node:path"), 1);
75312
+ var import_node_path23 = __toESM(require("node:path"), 1);
74909
75313
 
74910
75314
  // node_modules/tar/dist/esm/index.min.js
74911
75315
  var import_events = __toESM(require("events"), 1);
@@ -74913,7 +75317,7 @@ var import_fs = __toESM(require("fs"), 1);
74913
75317
  var import_node_events2 = require("node:events");
74914
75318
  var import_node_stream = __toESM(require("node:stream"), 1);
74915
75319
  var import_node_string_decoder = require("node:string_decoder");
74916
- var import_node_path13 = __toESM(require("node:path"), 1);
75320
+ var import_node_path14 = __toESM(require("node:path"), 1);
74917
75321
  var import_node_fs9 = __toESM(require("node:fs"), 1);
74918
75322
  var import_path = require("path");
74919
75323
  var import_events2 = require("events");
@@ -74921,27 +75325,27 @@ var import_assert = __toESM(require("assert"), 1);
74921
75325
  var import_buffer = require("buffer");
74922
75326
  var vs = __toESM(require("zlib"), 1);
74923
75327
  var import_zlib = __toESM(require("zlib"), 1);
74924
- var import_node_path14 = require("node:path");
74925
75328
  var import_node_path15 = require("node:path");
75329
+ var import_node_path16 = require("node:path");
74926
75330
  var import_fs2 = __toESM(require("fs"), 1);
74927
75331
  var import_fs3 = __toESM(require("fs"), 1);
74928
75332
  var import_path2 = __toESM(require("path"), 1);
74929
- var import_node_path16 = require("node:path");
75333
+ var import_node_path17 = require("node:path");
74930
75334
  var import_path3 = __toESM(require("path"), 1);
74931
75335
  var import_node_fs10 = __toESM(require("node:fs"), 1);
74932
75336
  var import_node_assert = __toESM(require("node:assert"), 1);
74933
75337
  var import_node_crypto5 = require("node:crypto");
74934
75338
  var import_node_fs11 = __toESM(require("node:fs"), 1);
74935
- var import_node_path17 = __toESM(require("node:path"), 1);
75339
+ var import_node_path18 = __toESM(require("node:path"), 1);
74936
75340
  var import_fs4 = __toESM(require("fs"), 1);
74937
75341
  var import_node_fs12 = __toESM(require("node:fs"), 1);
74938
- var import_node_path18 = __toESM(require("node:path"), 1);
74939
- var import_node_fs13 = __toESM(require("node:fs"), 1);
74940
- var import_promises5 = __toESM(require("node:fs/promises"), 1);
74941
75342
  var import_node_path19 = __toESM(require("node:path"), 1);
74942
- var import_node_path20 = require("node:path");
75343
+ var import_node_fs13 = __toESM(require("node:fs"), 1);
75344
+ var import_promises6 = __toESM(require("node:fs/promises"), 1);
75345
+ var import_node_path20 = __toESM(require("node:path"), 1);
75346
+ var import_node_path21 = require("node:path");
74943
75347
  var import_node_fs14 = __toESM(require("node:fs"), 1);
74944
- var import_node_path21 = __toESM(require("node:path"), 1);
75348
+ var import_node_path22 = __toESM(require("node:path"), 1);
74945
75349
  var vr = Object.defineProperty;
74946
75350
  var Mr = (s3, t) => {
74947
75351
  for (var e in t) vr(s3, e, { get: t[e], enumerable: true });
@@ -75834,12 +76238,12 @@ var k = class {
75834
76238
  }
75835
76239
  };
75836
76240
  var ln = (s3, t) => {
75837
- let i = s3, r = "", n, o = import_node_path14.posix.parse(s3).root || ".";
76241
+ let i = s3, r = "", n, o = import_node_path15.posix.parse(s3).root || ".";
75838
76242
  if (Buffer.byteLength(i) < 100) n = [i, r, false];
75839
76243
  else {
75840
- r = import_node_path14.posix.dirname(i), i = import_node_path14.posix.basename(i);
76244
+ r = import_node_path15.posix.dirname(i), i = import_node_path15.posix.basename(i);
75841
76245
  do
75842
- Buffer.byteLength(i) <= 100 && Buffer.byteLength(r) <= t ? n = [i, r, false] : Buffer.byteLength(i) > 100 && Buffer.byteLength(r) <= t ? n = [i.slice(0, 99), r, true] : (i = import_node_path14.posix.join(import_node_path14.posix.basename(r), i), r = import_node_path14.posix.dirname(r));
76246
+ Buffer.byteLength(i) <= 100 && Buffer.byteLength(r) <= t ? n = [i, r, false] : Buffer.byteLength(i) > 100 && Buffer.byteLength(r) <= t ? n = [i.slice(0, 99), r, true] : (i = import_node_path15.posix.join(import_node_path15.posix.basename(r), i), r = import_node_path15.posix.dirname(r));
75843
76247
  while (r !== o && n === void 0);
75844
76248
  n || (n = [s3.slice(0, 99), "", true]);
75845
76249
  }
@@ -75885,7 +76289,7 @@ var ct = class s {
75885
76289
  if (t === "") return Buffer.allocUnsafe(0);
75886
76290
  let e = Buffer.byteLength(t), i = 512 * Math.ceil(1 + e / 512), r = Buffer.allocUnsafe(i);
75887
76291
  for (let n = 0; n < 512; n++) r[n] = 0;
75888
- new k({ path: ("PaxHeader/" + (0, import_node_path15.basename)(this.path ?? "")).slice(0, 99), mode: this.mode || 420, uid: this.uid, gid: this.gid, size: e, mtime: this.mtime, type: this.global ? "GlobalExtendedHeader" : "ExtendedHeader", linkpath: "", uname: this.uname || "", gname: this.gname || "", devmaj: 0, devmin: 0, atime: this.atime, ctime: this.ctime }).encode(r), r.write(t, 512, e, "utf8");
76292
+ new k({ path: ("PaxHeader/" + (0, import_node_path16.basename)(this.path ?? "")).slice(0, 99), mode: this.mode || 420, uid: this.uid, gid: this.gid, size: e, mtime: this.mtime, type: this.global ? "GlobalExtendedHeader" : "ExtendedHeader", linkpath: "", uname: this.uname || "", gname: this.gname || "", devmaj: 0, devmin: 0, atime: this.atime, ctime: this.ctime }).encode(r), r.write(t, 512, e, "utf8");
75889
76293
  for (let n = e + 512; n < r.length; n++) r[n] = 0;
75890
76294
  return r;
75891
76295
  }
@@ -76297,7 +76701,7 @@ var Ct = K(An, In, (s3) => new st(s3), (s3) => new st(s3), (s3, t) => {
76297
76701
  t?.length && $i(s3, t), s3.noResume || Dn(s3);
76298
76702
  });
76299
76703
  var Xi = (s3, t, e) => (s3 &= 4095, e && (s3 = (s3 | 384) & -19), t && (s3 & 256 && (s3 |= 64), s3 & 32 && (s3 |= 8), s3 & 4 && (s3 |= 1)), s3);
76300
- var { isAbsolute: kn, parse: Ks } = import_node_path16.win32;
76704
+ var { isAbsolute: kn, parse: Ks } = import_node_path17.win32;
76301
76705
  var ce = (s3) => {
76302
76706
  let t = "", e = Ks(s3);
76303
76707
  for (; kn(s3) || e.root; ) {
@@ -77006,11 +77410,11 @@ var Wn = (s3, t) => {
77006
77410
  };
77007
77411
  var hr = (s3, t) => {
77008
77412
  t.forEach((e) => {
77009
- e.charAt(0) === "@" ? Ct({ file: import_node_path13.default.resolve(s3.cwd, e.slice(1)), sync: true, noResume: true, onReadEntry: (i) => s3.add(i) }) : s3.add(e);
77413
+ e.charAt(0) === "@" ? Ct({ file: import_node_path14.default.resolve(s3.cwd, e.slice(1)), sync: true, noResume: true, onReadEntry: (i) => s3.add(i) }) : s3.add(e);
77010
77414
  }), s3.end();
77011
77415
  };
77012
77416
  var ar = async (s3, t) => {
77013
- for (let e of t) e.charAt(0) === "@" ? await Ct({ file: import_node_path13.default.resolve(String(s3.cwd), e.slice(1)), noResume: true, onReadEntry: (i) => {
77417
+ for (let e of t) e.charAt(0) === "@" ? await Ct({ file: import_node_path14.default.resolve(String(s3.cwd), e.slice(1)), noResume: true, onReadEntry: (i) => {
77014
77418
  s3.add(i);
77015
77419
  } }) : s3.add(e);
77016
77420
  s3.end();
@@ -77048,13 +77452,13 @@ var pi = (s3, t, e, i) => {
77048
77452
  });
77049
77453
  };
77050
77454
  var qn = (s3, t, e, i, r) => {
77051
- if (t.isDirectory()) us(import_node_path18.default.resolve(s3, t.name), e, i, (n) => {
77455
+ if (t.isDirectory()) us(import_node_path19.default.resolve(s3, t.name), e, i, (n) => {
77052
77456
  if (n) return r(n);
77053
- let o = import_node_path18.default.resolve(s3, t.name);
77457
+ let o = import_node_path19.default.resolve(s3, t.name);
77054
77458
  pi(o, e, i, r);
77055
77459
  });
77056
77460
  else {
77057
- let n = import_node_path18.default.resolve(s3, t.name);
77461
+ let n = import_node_path19.default.resolve(s3, t.name);
77058
77462
  pi(n, e, i, r);
77059
77463
  }
77060
77464
  };
@@ -77075,7 +77479,7 @@ var us = (s3, t, e, i) => {
77075
77479
  });
77076
77480
  };
77077
77481
  var Qn = (s3, t, e, i) => {
77078
- t.isDirectory() && ms(import_node_path18.default.resolve(s3, t.name), e, i), ds(import_node_path18.default.resolve(s3, t.name), e, i);
77482
+ t.isDirectory() && ms(import_node_path19.default.resolve(s3, t.name), e, i), ds(import_node_path19.default.resolve(s3, t.name), e, i);
77079
77483
  };
77080
77484
  var ms = (s3, t, e) => {
77081
77485
  let i;
@@ -77124,13 +77528,13 @@ var wr = (s3, t, e) => {
77124
77528
  E ? e(E) : x && a ? us(x, o, h, (Le) => S(Le)) : n ? import_node_fs13.default.chmod(s3, r, e) : e();
77125
77529
  };
77126
77530
  if (s3 === d) return jn(s3, S);
77127
- if (l) return import_promises5.default.mkdir(s3, { mode: r, recursive: true }).then((E) => S(null, E ?? void 0), S);
77128
- let N = f(import_node_path19.default.relative(d, s3)).split("/");
77531
+ if (l) return import_promises6.default.mkdir(s3, { mode: r, recursive: true }).then((E) => S(null, E ?? void 0), S);
77532
+ let N = f(import_node_path20.default.relative(d, s3)).split("/");
77129
77533
  ps(d, N, r, c, d, void 0, S);
77130
77534
  };
77131
77535
  var ps = (s3, t, e, i, r, n, o) => {
77132
77536
  if (t.length === 0) return o(null, n);
77133
- let h = t.shift(), a = f(import_node_path19.default.resolve(s3 + "/" + h));
77537
+ let h = t.shift(), a = f(import_node_path20.default.resolve(s3 + "/" + h));
77134
77538
  import_node_fs13.default.mkdir(a, e, Sr(a, t, e, i, r, n, o));
77135
77539
  };
77136
77540
  var Sr = (s3, t, e, i, r, n, o) => (h) => {
@@ -77164,9 +77568,9 @@ var yr = (s3, t) => {
77164
77568
  };
77165
77569
  if (s3 === c) return to(c), d();
77166
77570
  if (a) return d(import_node_fs13.default.mkdirSync(s3, { mode: i, recursive: true }) ?? void 0);
77167
- let T = f(import_node_path19.default.relative(c, s3)).split("/"), N;
77571
+ let T = f(import_node_path20.default.relative(c, s3)).split("/"), N;
77168
77572
  for (let E = T.shift(), x = c; E && (x += "/" + E); E = T.shift()) {
77169
- x = f(import_node_path19.default.resolve(x));
77573
+ x = f(import_node_path20.default.resolve(x));
77170
77574
  try {
77171
77575
  import_node_fs13.default.mkdirSync(x, i), N = N || x;
77172
77576
  } catch {
@@ -77195,14 +77599,14 @@ var eo = process.env.TESTING_TAR_FAKE_PLATFORM || process.platform;
77195
77599
  var io = eo === "win32";
77196
77600
  var so = (s3) => s3.split("/").slice(0, -1).reduce((e, i) => {
77197
77601
  let r = e.at(-1);
77198
- return r !== void 0 && (i = (0, import_node_path20.join)(r, i)), e.push(i || "/"), e;
77602
+ return r !== void 0 && (i = (0, import_node_path21.join)(r, i)), e.push(i || "/"), e;
77199
77603
  }, []);
77200
77604
  var Si = class {
77201
77605
  #t = /* @__PURE__ */ new Map();
77202
77606
  #i = /* @__PURE__ */ new Map();
77203
77607
  #s = /* @__PURE__ */ new Set();
77204
77608
  reserve(t, e) {
77205
- t = io ? ["win32 parallelization disabled"] : t.map((r) => mt((0, import_node_path20.join)(gr(r))));
77609
+ t = io ? ["win32 parallelization disabled"] : t.map((r) => mt((0, import_node_path21.join)(gr(r))));
77206
77610
  let i = new Set(t.map((r) => so(r)).reduce((r, n) => r.concat(n)));
77207
77611
  this.#i.set(e, { dirs: i, paths: t });
77208
77612
  for (let r of t) {
@@ -77342,7 +77746,7 @@ var qt = class extends st {
77342
77746
  if (t.preserveOwner) throw new TypeError("cannot preserve owner in archive and also set owner explicitly");
77343
77747
  this.uid = t.uid, this.gid = t.gid, this.setOwner = true;
77344
77748
  } else this.uid = void 0, this.gid = void 0, this.setOwner = false;
77345
- this.preserveOwner = t.preserveOwner === void 0 && typeof t.uid != "number" ? !!(process.getuid && process.getuid() === 0) : !!t.preserveOwner, this.processUid = (this.preserveOwner || this.setOwner) && process.getuid ? process.getuid() : void 0, this.processGid = (this.preserveOwner || this.setOwner) && process.getgid ? process.getgid() : void 0, this.maxDepth = typeof t.maxDepth == "number" ? t.maxDepth : oo, this.forceChown = t.forceChown === true, this.win32 = !!t.win32 || Te, this.newer = !!t.newer, this.keep = !!t.keep, this.noMtime = !!t.noMtime, this.preservePaths = !!t.preservePaths, this.unlink = !!t.unlink, this.cwd = f(import_node_path17.default.resolve(t.cwd || process.cwd())), this.strip = Number(t.strip) || 0, this.processUmask = this.chmod ? typeof t.processUmask == "number" ? t.processUmask : _r() : 0, this.umask = typeof t.umask == "number" ? t.umask : this.processUmask, this.dmode = t.dmode || 511 & ~this.umask, this.fmode = t.fmode || 438 & ~this.umask, this.on("entry", (e) => this[Or](e));
77749
+ this.preserveOwner = t.preserveOwner === void 0 && typeof t.uid != "number" ? !!(process.getuid && process.getuid() === 0) : !!t.preserveOwner, this.processUid = (this.preserveOwner || this.setOwner) && process.getuid ? process.getuid() : void 0, this.processGid = (this.preserveOwner || this.setOwner) && process.getgid ? process.getgid() : void 0, this.maxDepth = typeof t.maxDepth == "number" ? t.maxDepth : oo, this.forceChown = t.forceChown === true, this.win32 = !!t.win32 || Te, this.newer = !!t.newer, this.keep = !!t.keep, this.noMtime = !!t.noMtime, this.preservePaths = !!t.preservePaths, this.unlink = !!t.unlink, this.cwd = f(import_node_path18.default.resolve(t.cwd || process.cwd())), this.strip = Number(t.strip) || 0, this.processUmask = this.chmod ? typeof t.processUmask == "number" ? t.processUmask : _r() : 0, this.umask = typeof t.umask == "number" ? t.umask : this.processUmask, this.dmode = t.dmode || 511 & ~this.umask, this.fmode = t.fmode || 438 & ~this.umask, this.on("entry", (e) => this[Or](e));
77346
77750
  }
77347
77751
  warn(t, e, i = {}) {
77348
77752
  return (t === "TAR_BAD_ARCHIVE" || t === "TAR_ABORT") && (i.recoverable = false), super.warn(t, e, i);
@@ -77356,7 +77760,7 @@ var qt = class extends st {
77356
77760
  let [n, o] = ce(i), h = o.replaceAll(/\\/g, "/").split("/");
77357
77761
  if (h.includes("..") || Te && /^[a-z]:\.\.$/i.test(h[0] ?? "")) {
77358
77762
  if (e === "path" || r === "Link") return this.warn("TAR_ENTRY_ERROR", `${e} contains '..'`, { entry: t, [e]: i }), false;
77359
- let a = import_node_path17.default.posix.dirname(t.path), l = import_node_path17.default.posix.normalize(import_node_path17.default.posix.join(a, h.join("/")));
77763
+ let a = import_node_path18.default.posix.dirname(t.path), l = import_node_path18.default.posix.normalize(import_node_path18.default.posix.join(a, h.join("/")));
77360
77764
  if (l.startsWith("../") || l === "..") return this.warn("TAR_ENTRY_ERROR", `${e} escapes extraction directory`, { entry: t, [e]: i }), false;
77361
77765
  }
77362
77766
  return n && (t[e] = String(o), this.warn("TAR_ENTRY_INFO", `stripping ${n} from absolute ${e}`, { entry: t, [e]: i })), true;
@@ -77374,12 +77778,12 @@ var qt = class extends st {
77374
77778
  }
77375
77779
  if (isFinite(this.maxDepth) && i.length > this.maxDepth) return this.warn("TAR_ENTRY_ERROR", "path excessively deep", { entry: t, path: e, depth: i.length, maxDepth: this.maxDepth }), false;
77376
77780
  if (!this[ws](t, "path") || !this[ws](t, "linkpath")) return false;
77377
- if (t.absolute = import_node_path17.default.isAbsolute(t.path) ? f(import_node_path17.default.resolve(t.path)) : f(import_node_path17.default.resolve(this.cwd, t.path)), !this.preservePaths && typeof t.absolute == "string" && t.absolute.indexOf(this.cwd + "/") !== 0 && t.absolute !== this.cwd) return this.warn("TAR_ENTRY_ERROR", "path escaped extraction target", { entry: t, path: f(t.path), resolvedPath: t.absolute, cwd: this.cwd }), false;
77781
+ if (t.absolute = import_node_path18.default.isAbsolute(t.path) ? f(import_node_path18.default.resolve(t.path)) : f(import_node_path18.default.resolve(this.cwd, t.path)), !this.preservePaths && typeof t.absolute == "string" && t.absolute.indexOf(this.cwd + "/") !== 0 && t.absolute !== this.cwd) return this.warn("TAR_ENTRY_ERROR", "path escaped extraction target", { entry: t, path: f(t.path), resolvedPath: t.absolute, cwd: this.cwd }), false;
77378
77782
  if (t.absolute === this.cwd && t.type !== "Directory" && t.type !== "GNUDumpDir") return false;
77379
77783
  if (this.win32) {
77380
- let { root: r } = import_node_path17.default.win32.parse(String(t.absolute));
77784
+ let { root: r } = import_node_path18.default.win32.parse(String(t.absolute));
77381
77785
  t.absolute = r + Qi(String(t.absolute).slice(r.length));
77382
- let { root: n } = import_node_path17.default.win32.parse(t.path);
77786
+ let { root: n } = import_node_path18.default.win32.parse(t.path);
77383
77787
  t.path = n + Qi(t.path.slice(n.length));
77384
77788
  }
77385
77789
  return true;
@@ -77467,13 +77871,13 @@ var qt = class extends st {
77467
77871
  t.unsupported = true, this.warn("TAR_ENTRY_UNSUPPORTED", `unsupported entry type: ${t.type}`, { entry: t }), t.resume();
77468
77872
  }
77469
77873
  [xr](t, e) {
77470
- let i = f(import_node_path17.default.relative(this.cwd, import_node_path17.default.resolve(import_node_path17.default.dirname(String(t.absolute)), String(t.linkpath)))).split("/");
77874
+ let i = f(import_node_path18.default.relative(this.cwd, import_node_path18.default.resolve(import_node_path18.default.dirname(String(t.absolute)), String(t.linkpath)))).split("/");
77471
77875
  this[Re](t, this.cwd, i, () => this[Ri](t, String(t.linkpath), "symlink", e), (r) => {
77472
77876
  this[O](r, t), e();
77473
77877
  });
77474
77878
  }
77475
77879
  [Lr](t, e) {
77476
- let i = f(import_node_path17.default.resolve(this.cwd, String(t.linkpath))), r = f(String(t.linkpath)).split("/");
77880
+ let i = f(import_node_path18.default.resolve(this.cwd, String(t.linkpath))), r = f(String(t.linkpath)).split("/");
77477
77881
  this[Re](t, this.cwd, r, () => this[Ri](t, i, "link", e), (n) => {
77478
77882
  this[O](n, t), e();
77479
77883
  });
@@ -77481,10 +77885,10 @@ var qt = class extends st {
77481
77885
  [Re](t, e, i, r, n) {
77482
77886
  let o = i.shift();
77483
77887
  if (this.preservePaths || o === void 0) return r();
77484
- let h = import_node_path17.default.resolve(e, o);
77888
+ let h = import_node_path18.default.resolve(e, o);
77485
77889
  import_node_fs11.default.lstat(h, (a, l) => {
77486
77890
  if (a) return r();
77487
- if (l?.isSymbolicLink()) return n(new St(h, import_node_path17.default.resolve(h, i.join("/"))));
77891
+ if (l?.isSymbolicLink()) return n(new St(h, import_node_path18.default.resolve(h, i.join("/"))));
77488
77892
  this[Re](t, h, i, r, n);
77489
77893
  });
77490
77894
  }
@@ -77518,7 +77922,7 @@ var qt = class extends st {
77518
77922
  });
77519
77923
  }, n = () => {
77520
77924
  if (t.absolute !== this.cwd) {
77521
- let h = f(import_node_path17.default.dirname(String(t.absolute)));
77925
+ let h = f(import_node_path18.default.dirname(String(t.absolute)));
77522
77926
  if (h !== this.cwd) return this[yt](h, this.dmode, (a) => {
77523
77927
  if (a) {
77524
77928
  this[O](a, t), i();
@@ -77593,7 +77997,7 @@ var xe = class extends qt {
77593
77997
  this[Oe] = true;
77594
77998
  }
77595
77999
  if (t.absolute !== this.cwd) {
77596
- let n = f(import_node_path17.default.dirname(String(t.absolute)));
78000
+ let n = f(import_node_path18.default.dirname(String(t.absolute)));
77597
78001
  if (n !== this.cwd) {
77598
78002
  let o = this[yt](n, this.dmode);
77599
78003
  if (o) return this[O](o, t);
@@ -77693,10 +78097,10 @@ var xe = class extends qt {
77693
78097
  if (this.preservePaths || i.length === 0) return r();
77694
78098
  let o = e;
77695
78099
  for (let h of i) {
77696
- o = import_node_path17.default.resolve(o, h);
78100
+ o = import_node_path18.default.resolve(o, h);
77697
78101
  let [a, l] = ye(() => import_node_fs11.default.lstatSync(o));
77698
78102
  if (a) return r();
77699
- if (l.isSymbolicLink()) return n(new St(o, import_node_path17.default.resolve(e, i.join("/"))));
78103
+ if (l.isSymbolicLink()) return n(new St(o, import_node_path18.default.resolve(e, i.join("/"))));
77700
78104
  }
77701
78105
  r();
77702
78106
  }
@@ -77800,11 +78204,11 @@ var po = (s3, t) => {
77800
78204
  };
77801
78205
  var Eo = (s3, t) => {
77802
78206
  t.forEach((e) => {
77803
- e.charAt(0) === "@" ? Ct({ file: import_node_path21.default.resolve(s3.cwd, e.slice(1)), sync: true, noResume: true, onReadEntry: (i) => s3.add(i) }) : s3.add(e);
78207
+ e.charAt(0) === "@" ? Ct({ file: import_node_path22.default.resolve(s3.cwd, e.slice(1)), sync: true, noResume: true, onReadEntry: (i) => s3.add(i) }) : s3.add(e);
77804
78208
  }), s3.end();
77805
78209
  };
77806
78210
  var wo = async (s3, t) => {
77807
- for (let e of t) e.charAt(0) === "@" ? await Ct({ file: import_node_path21.default.resolve(String(s3.cwd), e.slice(1)), noResume: true, onReadEntry: (i) => s3.add(i) }) : s3.add(e);
78211
+ for (let e of t) e.charAt(0) === "@" ? await Ct({ file: import_node_path22.default.resolve(String(s3.cwd), e.slice(1)), noResume: true, onReadEntry: (i) => s3.add(i) }) : s3.add(e);
77808
78212
  s3.end();
77809
78213
  };
77810
78214
  var vt = K(uo, po, () => {
@@ -77881,7 +78285,7 @@ function isUtf8(raw) {
77881
78285
  }
77882
78286
  }
77883
78287
  function buildSeedFilePayload(filePath, rootDir) {
77884
- const relative3 = import_node_path22.default.relative(rootDir, filePath).split(import_node_path22.default.sep).join("/");
78288
+ const relative3 = import_node_path23.default.relative(rootDir, filePath).split(import_node_path23.default.sep).join("/");
77885
78289
  const raw = import_node_fs15.default.readFileSync(filePath);
77886
78290
  if (isUtf8(raw)) {
77887
78291
  return { path: `/${relative3}`, content: raw.toString("utf8"), encoding: "utf-8" };
@@ -77889,7 +78293,7 @@ function buildSeedFilePayload(filePath, rootDir) {
77889
78293
  return { path: `/${relative3}`, content: raw.toString("base64"), encoding: "base64" };
77890
78294
  }
77891
78295
  function collectSeedPaths(rootDir, currentRelative, excludeDirs, output) {
77892
- const absoluteDir = import_node_path22.default.join(rootDir, currentRelative);
78296
+ const absoluteDir = import_node_path23.default.join(rootDir, currentRelative);
77893
78297
  const entries = import_node_fs15.default.readdirSync(absoluteDir, { withFileTypes: true });
77894
78298
  for (const entry of entries) {
77895
78299
  if (excludeDirs.has(entry.name)) {
@@ -77899,7 +78303,7 @@ function collectSeedPaths(rootDir, currentRelative, excludeDirs, output) {
77899
78303
  continue;
77900
78304
  }
77901
78305
  const nextRelative = currentRelative ? `${currentRelative}/${entry.name}` : entry.name;
77902
- const absolutePath = import_node_path22.default.join(rootDir, nextRelative);
78306
+ const absolutePath = import_node_path23.default.join(rootDir, nextRelative);
77903
78307
  if (excludeDirs.has(nextRelative)) {
77904
78308
  continue;
77905
78309
  }
@@ -77914,15 +78318,15 @@ function collectSeedPaths(rootDir, currentRelative, excludeDirs, output) {
77914
78318
  if (entry.isSymbolicLink()) {
77915
78319
  try {
77916
78320
  const resolved = import_node_fs15.default.realpathSync(absolutePath);
77917
- if (!resolved.startsWith(rootDir + import_node_path22.default.sep) && resolved !== rootDir) {
78321
+ if (!resolved.startsWith(rootDir + import_node_path23.default.sep) && resolved !== rootDir) {
77918
78322
  continue;
77919
78323
  }
77920
- const stat2 = import_node_fs15.default.statSync(resolved);
77921
- if (stat2.isDirectory()) {
78324
+ const stat3 = import_node_fs15.default.statSync(resolved);
78325
+ if (stat3.isDirectory()) {
77922
78326
  collectSeedPaths(rootDir, nextRelative, excludeDirs, output);
77923
78327
  continue;
77924
78328
  }
77925
- if (stat2.isFile()) {
78329
+ if (stat3.isFile()) {
77926
78330
  output.push(absolutePath);
77927
78331
  }
77928
78332
  } catch {
@@ -78050,7 +78454,7 @@ async function seedAclRules(baseUrl, token, workspaceId, aclRules) {
78050
78454
  }
78051
78455
  async function seedWorkspace(baseUrl, token, workspaceId, projectDir, excludeDirs) {
78052
78456
  const workspace = normalizeWorkspaceId2(workspaceId);
78053
- const rootDir = import_node_path22.default.resolve(projectDir);
78457
+ const rootDir = import_node_path23.default.resolve(projectDir);
78054
78458
  const excludes = normalizeExcludeDirs([...DEFAULT_EXCLUDED_DIRS, ...excludeDirs]);
78055
78459
  const seedPaths = [];
78056
78460
  collectSeedPaths(rootDir, "", excludes, seedPaths);
@@ -78223,7 +78627,7 @@ function buildSummary(compilations) {
78223
78627
  function buildAgentResult(projectDir, name, token, compiled, mountPoint) {
78224
78628
  return {
78225
78629
  name,
78226
- tokenPath: import_node_path23.default.resolve(projectDir, ".relay", "tokens", `${name}.jwt`),
78630
+ tokenPath: import_node_path24.default.resolve(projectDir, ".relay", "tokens", `${name}.jwt`),
78227
78631
  token,
78228
78632
  scopes: [...compiled.scopes],
78229
78633
  compiled,
@@ -78282,7 +78686,7 @@ async function provisionWorkflowAgents(config2) {
78282
78686
  action: "mint",
78283
78687
  details: {
78284
78688
  workspace: config2.workspace,
78285
- jwtPath: import_node_path23.default.resolve(config2.projectDir, ".relay", "tokens", `${agent.name}.jwt`),
78689
+ jwtPath: import_node_path24.default.resolve(config2.projectDir, ".relay", "tokens", `${agent.name}.jwt`),
78286
78690
  scopeCount: compiled.scopes.length,
78287
78691
  scopes: [...compiled.scopes],
78288
78692
  ttlSeconds: config2.tokenTtlSeconds ?? null
@@ -78360,7 +78764,7 @@ async function provisionWorkflowAgents(config2) {
78360
78764
  });
78361
78765
  }
78362
78766
  if (!config2.skipMount) {
78363
- const mountRoot = import_node_path23.default.resolve(config2.mountBaseDir ?? import_node_path23.default.join(config2.projectDir, ".relay"));
78767
+ const mountRoot = import_node_path24.default.resolve(config2.mountBaseDir ?? import_node_path24.default.join(config2.projectDir, ".relay"));
78364
78768
  try {
78365
78769
  for (const agent of agents) {
78366
78770
  const token = tokens.get(agent.name);
@@ -78373,7 +78777,7 @@ async function provisionWorkflowAgents(config2) {
78373
78777
  relayfileUrl: config2.relayfileBaseUrl,
78374
78778
  workspace: config2.workspace,
78375
78779
  token,
78376
- mountPoint: import_node_path23.default.join(mountRoot, `workspace-${sanitizePathComponent(config2.workspace)}-${sanitizePathComponent(agent.name)}`)
78780
+ mountPoint: import_node_path24.default.join(mountRoot, `workspace-${sanitizePathComponent(config2.workspace)}-${sanitizePathComponent(agent.name)}`)
78377
78781
  });
78378
78782
  mounts.set(agent.name, mountHandle);
78379
78783
  agentResults[agent.name] = buildAgentResult(config2.projectDir, agent.name, token, compiled, mountHandle.mountPoint);
@@ -78428,13 +78832,13 @@ async function provisionWorkflowAgents(config2) {
78428
78832
 
78429
78833
  // packages/sdk/dist/workflows/collectors/claude.js
78430
78834
  var import_node_fs17 = require("node:fs");
78431
- var import_promises6 = require("node:fs/promises");
78432
- var import_node_os6 = require("node:os");
78433
- var import_node_path24 = __toESM(require("node:path"), 1);
78835
+ var import_promises7 = require("node:fs/promises");
78836
+ var import_node_os7 = require("node:os");
78837
+ var import_node_path25 = __toESM(require("node:path"), 1);
78434
78838
  var import_node_readline = require("node:readline");
78435
- var CLAUDE_HOME = import_node_path24.default.join((0, import_node_os6.homedir)(), ".claude");
78436
- var HISTORY_PATH = import_node_path24.default.join(CLAUDE_HOME, "history.jsonl");
78437
- var PROJECTS_PATH = import_node_path24.default.join(CLAUDE_HOME, "projects");
78839
+ var CLAUDE_HOME = import_node_path25.default.join((0, import_node_os7.homedir)(), ".claude");
78840
+ var HISTORY_PATH = import_node_path25.default.join(CLAUDE_HOME, "history.jsonl");
78841
+ var PROJECTS_PATH = import_node_path25.default.join(CLAUDE_HOME, "projects");
78438
78842
  var HISTORY_LOOKBACK_MS = 5e3;
78439
78843
  var ClaudeCodeCollector = class {
78440
78844
  canCollect() {
@@ -78445,7 +78849,7 @@ var ClaudeCodeCollector = class {
78445
78849
  if (!historyEntry) {
78446
78850
  return null;
78447
78851
  }
78448
- const sessionPath = import_node_path24.default.join(PROJECTS_PATH, encodeProjectPath(historyEntry.project), `${historyEntry.sessionId}.jsonl`);
78852
+ const sessionPath = import_node_path25.default.join(PROJECTS_PATH, encodeProjectPath(historyEntry.project), `${historyEntry.sessionId}.jsonl`);
78449
78853
  if (!await isReadableFileAsync(sessionPath)) {
78450
78854
  return null;
78451
78855
  }
@@ -78730,7 +79134,7 @@ function isReadableDirectory(dirPath) {
78730
79134
  }
78731
79135
  async function isReadableFileAsync(filePath) {
78732
79136
  try {
78733
- await (0, import_promises6.access)(filePath);
79137
+ await (0, import_promises7.access)(filePath);
78734
79138
  return true;
78735
79139
  } catch {
78736
79140
  return false;
@@ -78739,13 +79143,13 @@ async function isReadableFileAsync(filePath) {
78739
79143
 
78740
79144
  // packages/sdk/dist/workflows/collectors/codex.js
78741
79145
  var import_node_fs18 = __toESM(require("node:fs"), 1);
78742
- var import_node_os7 = __toESM(require("node:os"), 1);
78743
- var import_node_path25 = __toESM(require("node:path"), 1);
79146
+ var import_node_os8 = __toESM(require("node:os"), 1);
79147
+ var import_node_path26 = __toESM(require("node:path"), 1);
78744
79148
  var import_node_module2 = require("node:module");
78745
79149
  var require2 = (0, import_node_module2.createRequire)(import_meta_url);
78746
- var CODEX_HOME = import_node_path25.default.join(import_node_os7.default.homedir(), ".codex");
78747
- var DEFAULT_HISTORY_PATH = import_node_path25.default.join(CODEX_HOME, "history.jsonl");
78748
- var DEFAULT_STATE_PATH = import_node_path25.default.join(CODEX_HOME, "state_5.sqlite");
79150
+ var CODEX_HOME = import_node_path26.default.join(import_node_os8.default.homedir(), ".codex");
79151
+ var DEFAULT_HISTORY_PATH = import_node_path26.default.join(CODEX_HOME, "history.jsonl");
79152
+ var DEFAULT_STATE_PATH = import_node_path26.default.join(CODEX_HOME, "state_5.sqlite");
78749
79153
  function loadBetterSqlite3() {
78750
79154
  try {
78751
79155
  return require2("better-sqlite3");
@@ -78979,11 +79383,11 @@ var CodexCollector = class {
78979
79383
 
78980
79384
  // packages/sdk/dist/workflows/collectors/opencode.js
78981
79385
  var import_node_fs19 = __toESM(require("node:fs"), 1);
78982
- var import_node_os8 = __toESM(require("node:os"), 1);
78983
- var import_node_path26 = __toESM(require("node:path"), 1);
79386
+ var import_node_os9 = __toESM(require("node:os"), 1);
79387
+ var import_node_path27 = __toESM(require("node:path"), 1);
78984
79388
  var import_node_module3 = require("node:module");
78985
79389
  var require3 = (0, import_node_module3.createRequire)(import_meta_url);
78986
- var OPENCODE_DB_PATH = import_node_path26.default.join(import_node_os8.default.homedir(), ".local", "share", "opencode", "opencode.db");
79390
+ var OPENCODE_DB_PATH = import_node_path27.default.join(import_node_os9.default.homedir(), ".local", "share", "opencode", "opencode.db");
78987
79391
  var MATCH_WINDOW_GRACE_MS = 5e3;
78988
79392
  var ERROR_LINE_PATTERN = /^(Error|error:|Command failed|FAIL)\b/;
78989
79393
  function loadDatabaseConstructor() {
@@ -79724,7 +80128,7 @@ var import_node_child_process7 = require("node:child_process");
79724
80128
  // packages/sdk/dist/workflows/verification.js
79725
80129
  var import_node_child_process6 = require("node:child_process");
79726
80130
  var import_node_fs20 = require("node:fs");
79727
- var import_node_path27 = __toESM(require("node:path"), 1);
80131
+ var import_node_path28 = __toESM(require("node:path"), 1);
79728
80132
  var WorkflowCompletionError = class extends Error {
79729
80133
  completionReason;
79730
80134
  constructor(message, completionReason) {
@@ -79916,9 +80320,9 @@ function checkCustom(value, output, cwd = process.cwd()) {
79916
80320
  }
79917
80321
  }
79918
80322
  function checkFileExists(filePath, cwd = process.cwd()) {
79919
- const normalizedCwd = import_node_path27.default.resolve(cwd);
79920
- const resolved = import_node_path27.default.isAbsolute(filePath) ? import_node_path27.default.resolve(filePath) : import_node_path27.default.resolve(normalizedCwd, filePath);
79921
- if (!import_node_path27.default.isAbsolute(filePath) && !resolved.startsWith(normalizedCwd + import_node_path27.default.sep) && resolved !== normalizedCwd) {
80323
+ const normalizedCwd = import_node_path28.default.resolve(cwd);
80324
+ const resolved = import_node_path28.default.isAbsolute(filePath) ? import_node_path28.default.resolve(filePath) : import_node_path28.default.resolve(normalizedCwd, filePath);
80325
+ if (!import_node_path28.default.isAbsolute(filePath) && !resolved.startsWith(normalizedCwd + import_node_path28.default.sep) && resolved !== normalizedCwd) {
79922
80326
  return false;
79923
80327
  }
79924
80328
  return (0, import_node_fs20.existsSync)(resolved);
@@ -80751,14 +81155,14 @@ function delay(ms2) {
80751
81155
  }
80752
81156
 
80753
81157
  // packages/sdk/dist/workflows/trajectory.js
80754
- var import_node_path28 = require("node:path");
81158
+ var import_node_path29 = require("node:path");
80755
81159
 
80756
81160
  // node_modules/agent-trajectories/dist/chunk-WMJRBQB4.js
80757
81161
  var import_module = require("module");
80758
81162
  var import_crypto = require("crypto");
80759
81163
  var import_crypto2 = require("crypto");
80760
81164
  var import_fs5 = require("fs");
80761
- var import_promises7 = require("fs/promises");
81165
+ var import_promises8 = require("fs/promises");
80762
81166
  var import_path4 = require("path");
80763
81167
  var ALPHABET = "abcdefghijklmnopqrstuvwxyz0123456789";
80764
81168
  var ID_LENGTH = 12;
@@ -81355,9 +81759,9 @@ var FileStorage = class {
81355
81759
  * Initialize storage directories
81356
81760
  */
81357
81761
  async initialize() {
81358
- await (0, import_promises7.mkdir)(this.trajectoriesDir, { recursive: true });
81359
- await (0, import_promises7.mkdir)(this.activeDir, { recursive: true });
81360
- await (0, import_promises7.mkdir)(this.completedDir, { recursive: true });
81762
+ await (0, import_promises8.mkdir)(this.trajectoriesDir, { recursive: true });
81763
+ await (0, import_promises8.mkdir)(this.activeDir, { recursive: true });
81764
+ await (0, import_promises8.mkdir)(this.completedDir, { recursive: true });
81361
81765
  if (!(0, import_fs5.existsSync)(this.indexPath)) {
81362
81766
  await withIndexLock(this.indexPath, async () => {
81363
81767
  if (!(0, import_fs5.existsSync)(this.indexPath)) {
@@ -81396,7 +81800,7 @@ var FileStorage = class {
81396
81800
  const before = Object.keys(index.trajectories).length;
81397
81801
  const discovered = [];
81398
81802
  try {
81399
- const activeFiles = await (0, import_promises7.readdir)(this.activeDir);
81803
+ const activeFiles = await (0, import_promises8.readdir)(this.activeDir);
81400
81804
  for (const file2 of activeFiles) {
81401
81805
  if (!file2.endsWith(".json")) continue;
81402
81806
  discovered.push((0, import_path4.join)(this.activeDir, file2));
@@ -81482,13 +81886,13 @@ var FileStorage = class {
81482
81886
  if (candidates.length === 0) {
81483
81887
  return { moved: [], targetDir };
81484
81888
  }
81485
- await (0, import_promises7.mkdir)(targetDir, { recursive: true });
81889
+ await (0, import_promises8.mkdir)(targetDir, { recursive: true });
81486
81890
  const moved = [];
81487
81891
  for (const failure of candidates) {
81488
81892
  const dest = await this.resolveQuarantineDest(failure.path, targetDir);
81489
81893
  try {
81490
- await (0, import_promises7.mkdir)((0, import_path4.dirname)(dest), { recursive: true });
81491
- await (0, import_promises7.rename)(failure.path, dest);
81894
+ await (0, import_promises8.mkdir)((0, import_path4.dirname)(dest), { recursive: true });
81895
+ await (0, import_promises8.rename)(failure.path, dest);
81492
81896
  moved.push(failure);
81493
81897
  } catch (error51) {
81494
81898
  console.warn(
@@ -81530,7 +81934,7 @@ var FileStorage = class {
81530
81934
  async walkJsonFilesInto(dir, out) {
81531
81935
  let entries;
81532
81936
  try {
81533
- entries = await (0, import_promises7.readdir)(dir, { withFileTypes: true });
81937
+ entries = await (0, import_promises8.readdir)(dir, { withFileTypes: true });
81534
81938
  } catch (error51) {
81535
81939
  if (error51.code === "ENOENT") return;
81536
81940
  throw error51;
@@ -81570,19 +81974,19 @@ var FileStorage = class {
81570
81974
  this.completedDir,
81571
81975
  `${date5.getFullYear()}-${String(date5.getMonth() + 1).padStart(2, "0")}`
81572
81976
  );
81573
- await (0, import_promises7.mkdir)(monthDir, { recursive: true });
81977
+ await (0, import_promises8.mkdir)(monthDir, { recursive: true });
81574
81978
  filePath = (0, import_path4.join)(monthDir, `${trajectory2.id}.json`);
81575
81979
  const activePath = (0, import_path4.join)(this.activeDir, `${trajectory2.id}.json`);
81576
81980
  if ((0, import_fs5.existsSync)(activePath)) {
81577
- await (0, import_promises7.unlink)(activePath);
81981
+ await (0, import_promises8.unlink)(activePath);
81578
81982
  }
81579
81983
  const mdPath = (0, import_path4.join)(monthDir, `${trajectory2.id}.md`);
81580
81984
  const markdown = exportToMarkdown(trajectory2);
81581
- await (0, import_promises7.writeFile)(mdPath, markdown, "utf-8");
81985
+ await (0, import_promises8.writeFile)(mdPath, markdown, "utf-8");
81582
81986
  } else {
81583
81987
  filePath = (0, import_path4.join)(this.activeDir, `${trajectory2.id}.json`);
81584
81988
  }
81585
- await (0, import_promises7.writeFile)(filePath, JSON.stringify(trajectory2, null, 2), "utf-8");
81989
+ await (0, import_promises8.writeFile)(filePath, JSON.stringify(trajectory2, null, 2), "utf-8");
81586
81990
  await this.updateIndex(trajectory2, filePath);
81587
81991
  }
81588
81992
  /**
@@ -81603,7 +82007,7 @@ var FileStorage = class {
81603
82007
  if ((0, import_fs5.existsSync)(flatPath)) {
81604
82008
  return this.readTrajectoryOrNull(flatPath);
81605
82009
  }
81606
- const months = await (0, import_promises7.readdir)(this.completedDir);
82010
+ const months = await (0, import_promises8.readdir)(this.completedDir);
81607
82011
  for (const month of months) {
81608
82012
  const filePath = (0, import_path4.join)(this.completedDir, month, `${id}.json`);
81609
82013
  if ((0, import_fs5.existsSync)(filePath)) {
@@ -81622,7 +82026,7 @@ var FileStorage = class {
81622
82026
  */
81623
82027
  async getActive() {
81624
82028
  try {
81625
- const files = await (0, import_promises7.readdir)(this.activeDir);
82029
+ const files = await (0, import_promises8.readdir)(this.activeDir);
81626
82030
  const jsonFiles = files.filter((f2) => f2.endsWith(".json"));
81627
82031
  if (jsonFiles.length === 0) {
81628
82032
  return null;
@@ -81707,16 +82111,16 @@ var FileStorage = class {
81707
82111
  async delete(id) {
81708
82112
  const activePath = (0, import_path4.join)(this.activeDir, `${id}.json`);
81709
82113
  if ((0, import_fs5.existsSync)(activePath)) {
81710
- await (0, import_promises7.unlink)(activePath);
82114
+ await (0, import_promises8.unlink)(activePath);
81711
82115
  }
81712
82116
  await withIndexLock(this.indexPath, async () => {
81713
82117
  const index = await this.loadIndex();
81714
82118
  const entry = index.trajectories[id];
81715
82119
  if (entry?.path && (0, import_fs5.existsSync)(entry.path)) {
81716
- await (0, import_promises7.unlink)(entry.path);
82120
+ await (0, import_promises8.unlink)(entry.path);
81717
82121
  const mdPath = entry.path.replace(".json", ".md");
81718
82122
  if ((0, import_fs5.existsSync)(mdPath)) {
81719
- await (0, import_promises7.unlink)(mdPath);
82123
+ await (0, import_promises8.unlink)(mdPath);
81720
82124
  }
81721
82125
  }
81722
82126
  delete index.trajectories[id];
@@ -81769,7 +82173,7 @@ var FileStorage = class {
81769
82173
  async readTrajectoryFile(path28) {
81770
82174
  let content;
81771
82175
  try {
81772
- content = await (0, import_promises7.readFile)(path28, "utf-8");
82176
+ content = await (0, import_promises8.readFile)(path28, "utf-8");
81773
82177
  } catch (error51) {
81774
82178
  return { ok: false, reason: "io_error", path: path28, error: error51 };
81775
82179
  }
@@ -81815,7 +82219,7 @@ var FileStorage = class {
81815
82219
  async loadIndex() {
81816
82220
  let content;
81817
82221
  try {
81818
- content = await (0, import_promises7.readFile)(this.indexPath, "utf-8");
82222
+ content = await (0, import_promises8.readFile)(this.indexPath, "utf-8");
81819
82223
  } catch (error51) {
81820
82224
  if (error51.code !== "ENOENT") {
81821
82225
  console.error(
@@ -81858,8 +82262,8 @@ var FileStorage = class {
81858
82262
  async saveIndex(index) {
81859
82263
  index.lastUpdated = (/* @__PURE__ */ new Date()).toISOString();
81860
82264
  const tmpPath = `${this.indexPath}.${process.pid}.${(0, import_crypto2.randomUUID)()}.tmp`;
81861
- await (0, import_promises7.writeFile)(tmpPath, JSON.stringify(index, null, 2), "utf-8");
81862
- await (0, import_promises7.rename)(tmpPath, this.indexPath);
82265
+ await (0, import_promises8.writeFile)(tmpPath, JSON.stringify(index, null, 2), "utf-8");
82266
+ await (0, import_promises8.rename)(tmpPath, this.indexPath);
81863
82267
  }
81864
82268
  async updateIndex(trajectory2, filePath) {
81865
82269
  await withIndexLock(this.indexPath, async () => {
@@ -81983,8 +82387,8 @@ var WorkflowTrajectory = class {
81983
82387
  this.reflectOnConverge = cfg.reflectOnConverge !== false;
81984
82388
  this.autoDecisions = cfg.autoDecisions !== false;
81985
82389
  this.runId = runId;
81986
- const dataDir = process.env.TRAJECTORIES_DATA_DIR ?? (0, import_node_path28.join)(cwd, ".trajectories");
81987
- this.storageBaseDir = process.env.TRAJECTORIES_DATA_DIR ? (0, import_node_path28.dirname)(dataDir) : cwd;
82390
+ const dataDir = process.env.TRAJECTORIES_DATA_DIR ?? (0, import_node_path29.join)(cwd, ".trajectories");
82391
+ this.storageBaseDir = process.env.TRAJECTORIES_DATA_DIR ? (0, import_node_path29.dirname)(dataDir) : cwd;
81988
82392
  }
81989
82393
  async start(workflowName, stepCount, trackInfo, description, pattern) {
81990
82394
  if (!this.enabled)
@@ -82414,6 +82818,7 @@ var WorkflowRunner = class _WorkflowRunner {
82414
82818
  runStartTime;
82415
82819
  /** Unsubscribe handle for broker stderr listener wired during a run. */
82416
82820
  unsubBrokerStderr;
82821
+ unsubRelayListeners = [];
82417
82822
  /** Tracks last idle log time per agent to debounce idle warnings (30s multiples). */
82418
82823
  lastIdleLog = /* @__PURE__ */ new Map();
82419
82824
  /** Tracks last logged activity type per agent to avoid duplicate status lines. */
@@ -82442,8 +82847,8 @@ var WorkflowRunner = class _WorkflowRunner {
82442
82847
  this.workspaceId = options.workspaceId ?? "local";
82443
82848
  this.relayOptions = options.relay ?? {};
82444
82849
  this.cwd = options.cwd ?? process.cwd();
82445
- this.summaryDir = options.summaryDir ?? import_node_path29.default.join(this.cwd, ".relay", "summaries");
82446
- this.workersPath = import_node_path29.default.join(this.cwd, ".agent-relay", "team", "workers.json");
82850
+ this.summaryDir = options.summaryDir ?? import_node_path30.default.join(this.cwd, ".relay", "summaries");
82851
+ this.workersPath = import_node_path30.default.join(this.cwd, ".agent-relay", "team", "workers.json");
82447
82852
  this.executor = options.executor;
82448
82853
  this.processBackend = options.processBackend;
82449
82854
  this.envSecrets = options.envSecrets;
@@ -82481,7 +82886,7 @@ var WorkflowRunner = class _WorkflowRunner {
82481
82886
  }
82482
82887
  seenNames.add(pd.name);
82483
82888
  const expanded = _WorkflowRunner.resolveEnvVars(pd.path);
82484
- const abs = import_node_path29.default.resolve(baseCwd, expanded);
82889
+ const abs = import_node_path30.default.resolve(baseCwd, expanded);
82485
82890
  resolved.set(pd.name, abs);
82486
82891
  const isRequired = pd.required !== false;
82487
82892
  if (!(0, import_node_fs21.existsSync)(abs)) {
@@ -82813,7 +83218,7 @@ var WorkflowRunner = class _WorkflowRunner {
82813
83218
  return resolved;
82814
83219
  }
82815
83220
  if (agent.cwd) {
82816
- return import_node_path29.default.resolve(this.cwd, agent.cwd);
83221
+ return import_node_path30.default.resolve(this.cwd, agent.cwd);
82817
83222
  }
82818
83223
  return this.cwd;
82819
83224
  }
@@ -82832,7 +83237,7 @@ var WorkflowRunner = class _WorkflowRunner {
82832
83237
  }
82833
83238
  resolveEffectiveCwd(step, agentDef) {
82834
83239
  if (step.cwd) {
82835
- return import_node_path29.default.resolve(this.cwd, step.cwd);
83240
+ return import_node_path30.default.resolve(this.cwd, step.cwd);
82836
83241
  }
82837
83242
  return this.resolveStepWorkdir(step) ?? (agentDef ? this.resolveAgentCwd(agentDef) : this.cwd);
82838
83243
  }
@@ -82841,14 +83246,14 @@ var WorkflowRunner = class _WorkflowRunner {
82841
83246
  if (!mount) {
82842
83247
  return cwd;
82843
83248
  }
82844
- const relative3 = import_node_path29.default.relative(this.cwd, cwd);
83249
+ const relative3 = import_node_path30.default.relative(this.cwd, cwd);
82845
83250
  if (relative3 === "") {
82846
83251
  return mount.mountPoint;
82847
83252
  }
82848
- if (relative3 === ".." || relative3.startsWith(`..${import_node_path29.default.sep}`)) {
83253
+ if (relative3 === ".." || relative3.startsWith(`..${import_node_path30.default.sep}`)) {
82849
83254
  return cwd;
82850
83255
  }
82851
- return import_node_path29.default.resolve(mount.mountPoint, relative3);
83256
+ return import_node_path30.default.resolve(mount.mountPoint, relative3);
82852
83257
  }
82853
83258
  resolveExecutionCwd(step, agentDef) {
82854
83259
  const cwd = this.resolveEffectiveCwd(step, agentDef);
@@ -83153,7 +83558,7 @@ ${next}` : next;
83153
83558
  }
83154
83559
  uniqueEvidenceRoots(roots) {
83155
83560
  return [
83156
- ...new Set(roots.filter((root) => Boolean(root)).map((root) => import_node_path29.default.resolve(root)))
83561
+ ...new Set(roots.filter((root) => Boolean(root)).map((root) => import_node_path30.default.resolve(root)))
83157
83562
  ];
83158
83563
  }
83159
83564
  captureFileSnapshot(root) {
@@ -83171,7 +83576,7 @@ ${next}` : next;
83171
83576
  if (entry.isDirectory() && _WorkflowRunner.EVIDENCE_IGNORED_DIRS.has(entry.name)) {
83172
83577
  continue;
83173
83578
  }
83174
- const fullPath = import_node_path29.default.join(currentPath, entry.name);
83579
+ const fullPath = import_node_path30.default.join(currentPath, entry.name);
83175
83580
  if (entry.isDirectory()) {
83176
83581
  visit(fullPath);
83177
83582
  continue;
@@ -83223,9 +83628,9 @@ ${next}` : next;
83223
83628
  return changes.sort((a, b2) => a.path.localeCompare(b2.path));
83224
83629
  }
83225
83630
  normalizeEvidencePath(filePath) {
83226
- const relative3 = import_node_path29.default.relative(this.cwd, filePath);
83631
+ const relative3 = import_node_path30.default.relative(this.cwd, filePath);
83227
83632
  if (!relative3 || relative3 === "")
83228
- return import_node_path29.default.basename(filePath);
83633
+ return import_node_path30.default.basename(filePath);
83229
83634
  return relative3.startsWith("..") ? filePath : relative3;
83230
83635
  }
83231
83636
  buildStepCompletionDecision(stepName, completionReason) {
@@ -83611,8 +84016,8 @@ ${next}` : next;
83611
84016
  // ── Parsing & validation ────────────────────────────────────────────────
83612
84017
  /** Parse a relay.yaml file from disk. */
83613
84018
  async parseYamlFile(filePath) {
83614
- const absPath = import_node_path29.default.resolve(this.cwd, filePath);
83615
- const raw = await (0, import_promises8.readFile)(absPath, "utf-8");
84019
+ const absPath = import_node_path30.default.resolve(this.cwd, filePath);
84020
+ const raw = await (0, import_promises9.readFile)(absPath, "utf-8");
83616
84021
  return this.parseYamlString(raw, absPath);
83617
84022
  }
83618
84023
  /** Parse a relay.yaml string. */
@@ -83811,14 +84216,14 @@ ${err.suggestion}`);
83811
84216
  }
83812
84217
  for (const agent of resolved.agents) {
83813
84218
  if (agent.cwd) {
83814
- const resolvedCwd = import_node_path29.default.resolve(this.cwd, agent.cwd);
84219
+ const resolvedCwd = import_node_path30.default.resolve(this.cwd, agent.cwd);
83815
84220
  if (!(0, import_node_fs21.existsSync)(resolvedCwd)) {
83816
84221
  warnings.push(`Agent "${agent.name}" cwd "${agent.cwd}" resolves to "${resolvedCwd}" which does not exist`);
83817
84222
  }
83818
84223
  }
83819
84224
  if (agent.additionalPaths) {
83820
84225
  for (const ap of agent.additionalPaths) {
83821
- const resolvedPath = import_node_path29.default.resolve(this.cwd, ap);
84226
+ const resolvedPath = import_node_path30.default.resolve(this.cwd, ap);
83822
84227
  if (!(0, import_node_fs21.existsSync)(resolvedPath)) {
83823
84228
  warnings.push(`Agent "${agent.name}" additionalPath "${ap}" resolves to "${resolvedPath}" which does not exist`);
83824
84229
  }
@@ -84393,7 +84798,7 @@ ${err.suggestion}`);
84393
84798
  }
84394
84799
  }
84395
84800
  this.log("Starting broker...");
84396
- const brokerBaseName = import_node_path29.default.basename(this.cwd) || "workflow";
84801
+ const brokerBaseName = import_node_path30.default.basename(this.cwd) || "workflow";
84397
84802
  const brokerName = `${brokerBaseName}-${runId.slice(0, 8)}`;
84398
84803
  this.relay = new AgentRelay({
84399
84804
  ...this.relayOptions,
@@ -84405,7 +84810,7 @@ ${err.suggestion}`);
84405
84810
  // long-running PTY processes from earlier steps. 120s gives room to breathe.
84406
84811
  requestTimeoutMs: this.relayOptions.requestTimeoutMs ?? 12e4
84407
84812
  });
84408
- this.relay.onWorkerOutput = ({ name, chunk }) => {
84813
+ this.unsubRelayListeners.push(this.relay.addListener("workerOutput", ({ name, chunk }) => {
84409
84814
  const listener = this.ptyListeners.get(name);
84410
84815
  if (listener)
84411
84816
  listener(chunk);
@@ -84415,7 +84820,7 @@ ${err.suggestion}`);
84415
84820
  if (/Read\(/.test(stripped)) {
84416
84821
  const m2 = stripped.match(/Read\(\s*~?([^\s)"']{8,})/);
84417
84822
  if (m2) {
84418
- const base = import_node_path29.default.basename(m2[1]);
84823
+ const base = import_node_path30.default.basename(m2[1]);
84419
84824
  activity = base.length >= 3 ? `Reading ${base}` : "Reading file...";
84420
84825
  } else {
84421
84826
  activity = "Reading file...";
@@ -84423,7 +84828,7 @@ ${err.suggestion}`);
84423
84828
  } else if (/Edit\(/.test(stripped)) {
84424
84829
  const m2 = stripped.match(/Edit\(\s*~?([^\s)"']{8,})/);
84425
84830
  if (m2) {
84426
- const base = import_node_path29.default.basename(m2[1]);
84831
+ const base = import_node_path30.default.basename(m2[1]);
84427
84832
  activity = base.length >= 3 ? `Editing ${base}` : "Editing file...";
84428
84833
  } else {
84429
84834
  activity = "Editing file...";
@@ -84444,8 +84849,8 @@ ${err.suggestion}`);
84444
84849
  this.lastActivity.set(name, activity);
84445
84850
  this.log(`[${shortName}] ${activity}`);
84446
84851
  }
84447
- };
84448
- this.relay.onMessageReceived = (msg) => {
84852
+ }));
84853
+ this.unsubRelayListeners.push(this.relay.addListener("messageReceived", (msg) => {
84449
84854
  this.emit({
84450
84855
  type: "broker:event",
84451
84856
  runId,
@@ -84482,8 +84887,8 @@ ${err.suggestion}`);
84482
84887
  });
84483
84888
  void this.trajectory?.ownerMonitoringEvent(supervision.stepName, supervision.logicalName, `Messaged ${msg.to}: ${msg.text.slice(0, 120)}`, { to: msg.to, text: msg.text });
84484
84889
  }
84485
- };
84486
- this.relay.onAgentSpawned = (agent) => {
84890
+ }));
84891
+ this.unsubRelayListeners.push(this.relay.addListener("agentSpawned", (agent) => {
84487
84892
  this.emit({
84488
84893
  type: "broker:event",
84489
84894
  runId,
@@ -84496,8 +84901,8 @@ ${err.suggestion}`);
84496
84901
  if (!this.activeAgentHandles.has(agent.name)) {
84497
84902
  this.log(`[spawned] ${agent.name} (${agent.runtime})`);
84498
84903
  }
84499
- };
84500
- this.relay.onAgentReleased = (agent) => {
84904
+ }));
84905
+ this.unsubRelayListeners.push(this.relay.addListener("agentReleased", (agent) => {
84501
84906
  this.emit({
84502
84907
  type: "broker:event",
84503
84908
  runId,
@@ -84506,8 +84911,8 @@ ${err.suggestion}`);
84506
84911
  name: agent.name
84507
84912
  }
84508
84913
  });
84509
- };
84510
- this.relay.onAgentExited = (agent) => {
84914
+ }));
84915
+ this.unsubRelayListeners.push(this.relay.addListener("agentExited", (agent) => {
84511
84916
  this.emit({
84512
84917
  type: "broker:event",
84513
84918
  runId,
@@ -84523,11 +84928,11 @@ ${err.suggestion}`);
84523
84928
  if (!this.activeAgentHandles.has(agent.name)) {
84524
84929
  this.log(`[exited] ${agent.name} (code: ${agent.exitCode ?? "?"})`);
84525
84930
  }
84526
- };
84527
- this.relay.onDeliveryUpdate = (event) => {
84931
+ }));
84932
+ this.unsubRelayListeners.push(this.relay.addListener("deliveryUpdate", (event) => {
84528
84933
  this.emit({ type: "broker:event", runId, event });
84529
- };
84530
- this.relay.onAgentIdle = ({ name, idleSecs }) => {
84934
+ }));
84935
+ this.unsubRelayListeners.push(this.relay.addListener("agentIdle", ({ name, idleSecs }) => {
84531
84936
  this.emit({
84532
84937
  type: "broker:event",
84533
84938
  runId,
@@ -84543,7 +84948,7 @@ ${err.suggestion}`);
84543
84948
  const shortName = name.replace(/-[a-f0-9]{6,}$/, "");
84544
84949
  this.log(`[idle] ${shortName} silent for ${bucket}s`);
84545
84950
  }
84546
- };
84951
+ }));
84547
84952
  this.relaycast = void 0;
84548
84953
  this.relaycastAgent = void 0;
84549
84954
  this.unsubBrokerStderr = this.relay.onBrokerStderr((line) => {
@@ -84654,15 +85059,13 @@ ${err.suggestion}`);
84654
85059
  this.ptyListeners.clear();
84655
85060
  this.unsubBrokerStderr?.();
84656
85061
  this.unsubBrokerStderr = void 0;
84657
- if (this.relay) {
84658
- this.relay.onMessageReceived = null;
84659
- this.relay.onAgentSpawned = null;
84660
- this.relay.onAgentReleased = null;
84661
- this.relay.onAgentExited = null;
84662
- this.relay.onAgentIdle = null;
84663
- this.relay.onWorkerOutput = null;
84664
- this.relay.onDeliveryUpdate = null;
85062
+ for (const off of this.unsubRelayListeners) {
85063
+ try {
85064
+ off();
85065
+ } catch {
85066
+ }
84665
85067
  }
85068
+ this.unsubRelayListeners = [];
84666
85069
  this.lastIdleLog.clear();
84667
85070
  this.lastActivity.clear();
84668
85071
  this.supervisedRuntimeAgents.clear();
@@ -85266,14 +85669,14 @@ Repair only what is needed for this step to produce the required artifact or evi
85266
85669
  const stepOutputContext = this.buildStepOutputContext(stepStates, runId);
85267
85670
  const branch = this.interpolateStepTask(step.branch ?? "", stepOutputContext);
85268
85671
  const baseBranch = step.baseBranch ? this.interpolateStepTask(step.baseBranch, stepOutputContext) : "HEAD";
85269
- const worktreePath = step.path ? this.interpolateStepTask(step.path, stepOutputContext) : import_node_path29.default.join(".worktrees", step.name);
85672
+ const worktreePath = step.path ? this.interpolateStepTask(step.path, stepOutputContext) : import_node_path30.default.join(".worktrees", step.name);
85270
85673
  const createBranch2 = step.createBranch !== false;
85271
85674
  const stepCwd = this.resolveStepWorkdir(step) ?? this.cwd;
85272
85675
  this.beginStepEvidence(step.name, [stepCwd], state.row.startedAt);
85273
85676
  if (!branch) {
85274
85677
  throw new Error('Worktree step missing required "branch" field');
85275
85678
  }
85276
- const absoluteWorktreePath = import_node_path29.default.resolve(stepCwd, worktreePath);
85679
+ const absoluteWorktreePath = import_node_path30.default.resolve(stepCwd, worktreePath);
85277
85680
  let branchExists = false;
85278
85681
  await new Promise((resolve4) => {
85279
85682
  const checkChild = (0, import_node_child_process8.spawn)("git", ["rev-parse", "--verify", "--quiet", branch], {
@@ -86356,8 +86759,8 @@ WORKER COMPLETION CONTRACT:
86356
86759
  promptTaskText: taskText
86357
86760
  };
86358
86761
  }
86359
- const taskTmpDir = (0, import_node_fs21.mkdtempSync)(import_node_path29.default.join((0, import_node_os9.tmpdir)(), "relay-pty-task-"));
86360
- const taskTmpFile = import_node_path29.default.join(taskTmpDir, `${agentName}-${Date.now()}.txt`);
86762
+ const taskTmpDir = (0, import_node_fs21.mkdtempSync)(import_node_path30.default.join((0, import_node_os10.tmpdir)(), "relay-pty-task-"));
86763
+ const taskTmpFile = import_node_path30.default.join(taskTmpDir, `${agentName}-${Date.now()}.txt`);
86361
86764
  (0, import_node_fs21.writeFileSync)(taskTmpFile, taskText, { encoding: "utf8", mode: 384, flag: "wx" });
86362
86765
  const promptTaskText = `TASK_FILE:${taskTmpFile}
86363
86766
  Read that file completely before taking any action.
@@ -86763,7 +87166,7 @@ DO NOT:
86763
87166
  - Output only status messages without the actual deliverable content`;
86764
87167
  const { cmd, args } = _WorkflowRunner.buildNonInteractiveCommand(agentDef.cli, taskWithDeliverable, modelArgs);
86765
87168
  const logsDir = this.getWorkerLogsDir();
86766
- const logPath = import_node_path29.default.join(logsDir, `${agentName}.log`);
87169
+ const logPath = import_node_path30.default.join(logsDir, `${agentName}.log`);
86767
87170
  const logStream = (0, import_node_fs21.createWriteStream)(logPath, { flags: "a" });
86768
87171
  this.registerWorker(agentName, agentDef.cli, step.task ?? "", void 0, false);
86769
87172
  let stopHeartbeat;
@@ -86931,7 +87334,7 @@ DO NOT:
86931
87334
  const preparedTask = this.prepareInteractiveSpawnTask(agentName, taskWithExit);
86932
87335
  this.ptyOutputBuffers.set(agentName, []);
86933
87336
  const logsDir = this.getWorkerLogsDir();
86934
- const logStream = (0, import_node_fs21.createWriteStream)(import_node_path29.default.join(logsDir, `${agentName}.log`), { flags: "a" });
87337
+ const logStream = (0, import_node_fs21.createWriteStream)(import_node_path30.default.join(logsDir, `${agentName}.log`), { flags: "a" });
86935
87338
  this.ptyLogStreams.set(agentName, logStream);
86936
87339
  this.ptyListeners.set(agentName, (chunk) => {
86937
87340
  const stripped = _WorkflowRunner.stripAnsi(chunk);
@@ -86981,8 +87384,8 @@ DO NOT:
86981
87384
  const oldName = agentName;
86982
87385
  this.ptyOutputBuffers.set(agent.name, this.ptyOutputBuffers.get(oldName) ?? []);
86983
87386
  this.ptyOutputBuffers.delete(oldName);
86984
- const oldLogPath = import_node_path29.default.join(logsDir, `${oldName}.log`);
86985
- const newLogPath = import_node_path29.default.join(logsDir, `${agent.name}.log`);
87387
+ const oldLogPath = import_node_path30.default.join(logsDir, `${oldName}.log`);
87388
+ const newLogPath = import_node_path30.default.join(logsDir, `${agent.name}.log`);
86986
87389
  const oldLogStream = this.ptyLogStreams.get(oldName);
86987
87390
  if (oldLogStream) {
86988
87391
  oldLogStream.end();
@@ -87092,15 +87495,15 @@ DO NOT:
87092
87495
  this.supervisedRuntimeAgents.delete(agentName);
87093
87496
  this.runtimeStepAgents.delete(agentName);
87094
87497
  if (preparedTask.taskTmpFile) {
87095
- await (0, import_promises8.unlink)(preparedTask.taskTmpFile).catch(() => void 0);
87498
+ await (0, import_promises9.unlink)(preparedTask.taskTmpFile).catch(() => void 0);
87096
87499
  }
87097
87500
  }
87098
87501
  let output;
87099
87502
  if (ptyChunks.length > 0) {
87100
87503
  output = ptyChunks.join("");
87101
87504
  } else {
87102
- const summaryPath = import_node_path29.default.join(this.summaryDir, `${step.name}.md`);
87103
- output = (0, import_node_fs21.existsSync)(summaryPath) ? await (0, import_promises8.readFile)(summaryPath, "utf-8") : exitResult === "timeout" ? "Agent completed (released after idle timeout)" : exitResult === "released" ? "Agent completed (idle \u2014 treated as done)" : `Agent exited (${exitResult})`;
87505
+ const summaryPath = import_node_path30.default.join(this.summaryDir, `${step.name}.md`);
87506
+ output = (0, import_node_fs21.existsSync)(summaryPath) ? await (0, import_promises9.readFile)(summaryPath, "utf-8") : exitResult === "timeout" ? "Agent completed (released after idle timeout)" : exitResult === "released" ? "Agent completed (idle \u2014 treated as done)" : `Agent exited (${exitResult})`;
87104
87507
  }
87105
87508
  if (ptyChunks.length === 0) {
87106
87509
  this.captureStepTerminalEvidence(evidenceStepName, { stdout: output, combined: output }, { exitCode: agent?.exitCode, exitSignal: agent?.exitSignal }, {
@@ -87552,7 +87955,7 @@ DO NOT:
87552
87955
  }
87553
87956
  }
87554
87957
  const outputDir = this.getStepOutputDir(runId);
87555
- const logsDir = import_node_path29.default.join(this.cwd, ".agent-relay", "team", "worker-logs");
87958
+ const logsDir = import_node_path30.default.join(this.cwd, ".agent-relay", "team", "worker-logs");
87556
87959
  console.log("");
87557
87960
  console.log(` Run ID: ${runId}`);
87558
87961
  console.log(` Step output: ${outputDir}`);
@@ -87638,7 +88041,7 @@ ${excerpt}` : "";
87638
88041
  if (!target)
87639
88042
  return;
87640
88043
  try {
87641
- (0, import_node_fs21.mkdirSync)(import_node_path29.default.dirname(target), { recursive: true });
88044
+ (0, import_node_fs21.mkdirSync)(import_node_path30.default.dirname(target), { recursive: true });
87642
88045
  (0, import_node_fs21.writeFileSync)(target, runId + "\n", "utf8");
87643
88046
  } catch {
87644
88047
  }
@@ -87675,16 +88078,16 @@ ${excerpt}` : "";
87675
88078
  /** Directory for persisted step outputs: .agent-relay/step-outputs/{runId}/ */
87676
88079
  getStepOutputDir(runId) {
87677
88080
  this.validateRunId(runId);
87678
- return import_node_path29.default.join(this.cwd, ".agent-relay", "step-outputs", runId);
88081
+ return import_node_path30.default.join(this.cwd, ".agent-relay", "step-outputs", runId);
87679
88082
  }
87680
88083
  /** Persist step output to disk and post full output as a channel message. */
87681
88084
  async persistStepOutput(runId, stepName, output) {
87682
- const outputPath = import_node_path29.default.join(this.getStepOutputDir(runId), `${stepName}.md`);
88085
+ const outputPath = import_node_path30.default.join(this.getStepOutputDir(runId), `${stepName}.md`);
87683
88086
  try {
87684
88087
  const dir = this.getStepOutputDir(runId);
87685
88088
  (0, import_node_fs21.mkdirSync)(dir, { recursive: true });
87686
88089
  const cleaned = _WorkflowRunner.stripAnsi(output);
87687
- await (0, import_promises8.writeFile)(outputPath, cleaned);
88090
+ await (0, import_promises9.writeFile)(outputPath, cleaned);
87688
88091
  } catch {
87689
88092
  }
87690
88093
  this.recordStepToolSideEffect(stepName, {
@@ -87709,32 +88112,32 @@ ${preview}
87709
88112
  \`\`\``, { stepName });
87710
88113
  }
87711
88114
  async persistAgentReport(runId, stepName, report) {
87712
- const reportPath = import_node_path29.default.join(this.getStepOutputDir(runId), `${stepName}.report.json`);
88115
+ const reportPath = import_node_path30.default.join(this.getStepOutputDir(runId), `${stepName}.report.json`);
87713
88116
  try {
87714
88117
  (0, import_node_fs21.mkdirSync)(this.getStepOutputDir(runId), { recursive: true });
87715
- await (0, import_promises8.writeFile)(reportPath, JSON.stringify(report, null, 2), "utf8");
88118
+ await (0, import_promises9.writeFile)(reportPath, JSON.stringify(report, null, 2), "utf8");
87716
88119
  } catch {
87717
88120
  }
87718
88121
  }
87719
88122
  /** Scan .agent-relay/step-outputs/ for the most recent run directory containing the needed steps. */
87720
88123
  findMostRecentRunWithSteps(stepNames) {
87721
88124
  try {
87722
- const baseDir = import_node_path29.default.join(this.cwd, ".agent-relay", "step-outputs");
88125
+ const baseDir = import_node_path30.default.join(this.cwd, ".agent-relay", "step-outputs");
87723
88126
  if (!(0, import_node_fs21.existsSync)(baseDir))
87724
88127
  return void 0;
87725
88128
  const entries = (0, import_node_fs21.readdirSync)(baseDir);
87726
88129
  let best;
87727
88130
  for (const entry of entries) {
87728
- const dirPath = import_node_path29.default.join(baseDir, entry);
88131
+ const dirPath = import_node_path30.default.join(baseDir, entry);
87729
88132
  try {
87730
- const stat2 = (0, import_node_fs21.statSync)(dirPath);
87731
- if (!stat2.isDirectory())
88133
+ const stat3 = (0, import_node_fs21.statSync)(dirPath);
88134
+ if (!stat3.isDirectory())
87732
88135
  continue;
87733
- const hasAny = [...stepNames].some((name) => (0, import_node_fs21.existsSync)(import_node_path29.default.join(dirPath, `${name}.md`)));
88136
+ const hasAny = [...stepNames].some((name) => (0, import_node_fs21.existsSync)(import_node_path30.default.join(dirPath, `${name}.md`)));
87734
88137
  if (!hasAny)
87735
88138
  continue;
87736
- if (!best || stat2.mtimeMs > best.mtime) {
87737
- best = { name: entry, mtime: stat2.mtimeMs };
88139
+ if (!best || stat3.mtimeMs > best.mtime) {
88140
+ best = { name: entry, mtime: stat3.mtimeMs };
87738
88141
  }
87739
88142
  } catch {
87740
88143
  continue;
@@ -87748,7 +88151,7 @@ ${preview}
87748
88151
  /** Load persisted step output from disk. */
87749
88152
  loadStepOutput(runId, stepName) {
87750
88153
  try {
87751
- const filePath = import_node_path29.default.join(this.getStepOutputDir(runId), `${stepName}.md`);
88154
+ const filePath = import_node_path30.default.join(this.getStepOutputDir(runId), `${stepName}.md`);
87752
88155
  if (!(0, import_node_fs21.existsSync)(filePath))
87753
88156
  return void 0;
87754
88157
  return (0, import_node_fs21.readFileSync)(filePath, "utf-8");
@@ -87777,7 +88180,7 @@ ${preview}
87777
88180
  return null;
87778
88181
  let resumeConfig = config2 ?? this.currentConfig;
87779
88182
  if (!resumeConfig) {
87780
- const yamlPath = import_node_path29.default.join(this.cwd, "relay.yaml");
88183
+ const yamlPath = import_node_path30.default.join(this.cwd, "relay.yaml");
87781
88184
  if ((0, import_node_fs21.existsSync)(yamlPath)) {
87782
88185
  try {
87783
88186
  const raw = (0, import_node_fs21.readFileSync)(yamlPath, "utf-8");
@@ -87806,8 +88209,8 @@ ${preview}
87806
88209
  let earliestMtime = Date.now();
87807
88210
  for (const stepName of cachedStepNames) {
87808
88211
  try {
87809
- const mdPath = import_node_path29.default.join(stepOutputDir, `${stepName}.md`);
87810
- const reportPath = import_node_path29.default.join(stepOutputDir, `${stepName}.report.json`);
88212
+ const mdPath = import_node_path30.default.join(stepOutputDir, `${stepName}.md`);
88213
+ const reportPath = import_node_path30.default.join(stepOutputDir, `${stepName}.report.json`);
87811
88214
  const mdStat = (0, import_node_fs21.existsSync)(mdPath) ? (0, import_node_fs21.statSync)(mdPath) : null;
87812
88215
  const reportStat = (0, import_node_fs21.existsSync)(reportPath) ? (0, import_node_fs21.statSync)(reportPath) : null;
87813
88216
  const mtime = Math.max(mdStat?.mtimeMs ?? 0, reportStat?.mtimeMs ?? 0);
@@ -87861,7 +88264,7 @@ ${preview}
87861
88264
  }
87862
88265
  /** Get or create the worker logs directory (.agent-relay/team/worker-logs) */
87863
88266
  getWorkerLogsDir() {
87864
- const logsDir = import_node_path29.default.join(this.cwd, ".agent-relay", "team", "worker-logs");
88267
+ const logsDir = import_node_path30.default.join(this.cwd, ".agent-relay", "team", "worker-logs");
87865
88268
  (0, import_node_fs21.mkdirSync)(logsDir, { recursive: true });
87866
88269
  return logsDir;
87867
88270
  }
@@ -87873,12 +88276,12 @@ ${preview}
87873
88276
  spawnedAt: Date.now(),
87874
88277
  pid,
87875
88278
  interactive,
87876
- logFile: import_node_path29.default.join(this.getWorkerLogsDir(), `${agentName}.log`)
88279
+ logFile: import_node_path30.default.join(this.getWorkerLogsDir(), `${agentName}.log`)
87877
88280
  };
87878
88281
  this.activeWorkers.set(agentName, workerEntry);
87879
88282
  this.workersFileLock = this.workersFileLock.then(() => {
87880
88283
  try {
87881
- (0, import_node_fs21.mkdirSync)(import_node_path29.default.dirname(this.workersPath), { recursive: true });
88284
+ (0, import_node_fs21.mkdirSync)(import_node_path30.default.dirname(this.workersPath), { recursive: true });
87882
88285
  const existing = this.readWorkers().filter((w2) => w2.name !== agentName);
87883
88286
  existing.push({ name: agentName, ...workerEntry });
87884
88287
  this.writeWorkers(existing);
@@ -87915,8 +88318,8 @@ ${preview}
87915
88318
 
87916
88319
  // packages/sdk/dist/workflows/file-db.js
87917
88320
  var import_node_fs22 = require("node:fs");
87918
- var import_node_os10 = __toESM(require("node:os"), 1);
87919
- var import_node_path30 = __toESM(require("node:path"), 1);
88321
+ var import_node_os11 = __toESM(require("node:os"), 1);
88322
+ var import_node_path31 = __toESM(require("node:path"), 1);
87920
88323
  var JsonFileWorkflowDb = class _JsonFileWorkflowDb {
87921
88324
  filePath;
87922
88325
  /** Whether persistence is active. False = in-memory-only mode. */
@@ -87932,7 +88335,7 @@ var JsonFileWorkflowDb = class _JsonFileWorkflowDb {
87932
88335
  constructor(filePathOrOptions) {
87933
88336
  const options = typeof filePathOrOptions === "string" ? { filePath: filePathOrOptions } : filePathOrOptions;
87934
88337
  this.onWriteFailure = options.onWriteFailure;
87935
- const requestedPath = options.filePath ?? import_node_path30.default.join(".agent-relay", "workflow-runs.jsonl");
88338
+ const requestedPath = options.filePath ?? import_node_path31.default.join(".agent-relay", "workflow-runs.jsonl");
87936
88339
  const homeFallback = options.homeFallback ?? false;
87937
88340
  const { resolvedPath, writable } = _JsonFileWorkflowDb.resolveStoragePath(requestedPath, homeFallback);
87938
88341
  this.filePath = resolvedPath;
@@ -87949,7 +88352,7 @@ var JsonFileWorkflowDb = class _JsonFileWorkflowDb {
87949
88352
  }
87950
88353
  hasStepOutputs(runId) {
87951
88354
  try {
87952
- const dir = import_node_path30.default.join(import_node_path30.default.dirname(this.filePath), "step-outputs", runId);
88355
+ const dir = import_node_path31.default.join(import_node_path31.default.dirname(this.filePath), "step-outputs", runId);
87953
88356
  return (0, import_node_fs22.existsSync)(dir) && (0, import_node_fs22.readdirSync)(dir).length > 0;
87954
88357
  } catch {
87955
88358
  return false;
@@ -87959,16 +88362,16 @@ var JsonFileWorkflowDb = class _JsonFileWorkflowDb {
87959
88362
  static resolveStoragePath(requestedPath, homeFallback) {
87960
88363
  const candidates = [requestedPath];
87961
88364
  if (homeFallback) {
87962
- const base = import_node_path30.default.basename(requestedPath) || "workflow-runs.jsonl";
87963
- candidates.push(import_node_path30.default.join(import_node_os10.default.homedir(), ".agent-relay", `workflow-runs-${base}`));
88365
+ const base = import_node_path31.default.basename(requestedPath) || "workflow-runs.jsonl";
88366
+ candidates.push(import_node_path31.default.join(import_node_os11.default.homedir(), ".agent-relay", `workflow-runs-${base}`));
87964
88367
  }
87965
88368
  for (let i = 0; i < candidates.length; i++) {
87966
88369
  const candidate = candidates[i];
87967
88370
  const isLastCandidate = i === candidates.length - 1;
87968
88371
  try {
87969
- (0, import_node_fs22.mkdirSync)(import_node_path30.default.dirname(candidate), { recursive: true });
88372
+ (0, import_node_fs22.mkdirSync)(import_node_path31.default.dirname(candidate), { recursive: true });
87970
88373
  if (!isLastCandidate) {
87971
- (0, import_node_fs22.accessSync)(import_node_path30.default.dirname(candidate), import_node_fs22.constants.W_OK);
88374
+ (0, import_node_fs22.accessSync)(import_node_path31.default.dirname(candidate), import_node_fs22.constants.W_OK);
87972
88375
  if ((0, import_node_fs22.existsSync)(candidate)) {
87973
88376
  (0, import_node_fs22.accessSync)(candidate, import_node_fs22.constants.W_OK);
87974
88377
  }
@@ -88257,17 +88660,17 @@ async function runWorkflow(yamlPath, options = {}) {
88257
88660
  }
88258
88661
 
88259
88662
  // packages/cloud/src/auth.ts
88260
- var import_promises9 = __toESM(require("node:fs/promises"), 1);
88663
+ var import_promises10 = __toESM(require("node:fs/promises"), 1);
88261
88664
  var import_node_http = __toESM(require("node:http"), 1);
88262
- var import_node_os12 = __toESM(require("node:os"), 1);
88263
- var import_node_path32 = __toESM(require("node:path"), 1);
88665
+ var import_node_os13 = __toESM(require("node:os"), 1);
88666
+ var import_node_path33 = __toESM(require("node:path"), 1);
88264
88667
  var import_node_child_process9 = require("node:child_process");
88265
88668
 
88266
88669
  // packages/cloud/src/types.ts
88267
- var import_node_os11 = __toESM(require("node:os"), 1);
88268
- var import_node_path31 = __toESM(require("node:path"), 1);
88670
+ var import_node_os12 = __toESM(require("node:os"), 1);
88671
+ var import_node_path32 = __toESM(require("node:path"), 1);
88269
88672
  var REFRESH_WINDOW_MS = 6e4;
88270
- var AUTH_FILE_PATH = import_node_path31.default.join(import_node_os11.default.homedir(), ".agent-relay", "cloud-auth.json");
88673
+ var AUTH_FILE_PATH = import_node_path32.default.join(import_node_os12.default.homedir(), ".agent-relay", "cloud-auth.json");
88271
88674
  function defaultApiUrl() {
88272
88675
  return process.env.CLOUD_API_URL?.trim() || "https://agentrelay.com/cloud";
88273
88676
  }
@@ -88335,7 +88738,7 @@ async function readStoredAuth(env = process.env) {
88335
88738
  return envAuth;
88336
88739
  }
88337
88740
  try {
88338
- const file2 = await import_promises9.default.readFile(AUTH_FILE_PATH, "utf8");
88741
+ const file2 = await import_promises10.default.readFile(AUTH_FILE_PATH, "utf8");
88339
88742
  const parsed = JSON.parse(file2);
88340
88743
  return isValidStoredAuth(parsed) ? parsed : null;
88341
88744
  } catch {
@@ -88343,11 +88746,11 @@ async function readStoredAuth(env = process.env) {
88343
88746
  }
88344
88747
  }
88345
88748
  async function writeStoredAuth(auth) {
88346
- await import_promises9.default.mkdir(import_node_path32.default.dirname(AUTH_FILE_PATH), {
88749
+ await import_promises10.default.mkdir(import_node_path33.default.dirname(AUTH_FILE_PATH), {
88347
88750
  recursive: true,
88348
88751
  mode: 448
88349
88752
  });
88350
- await import_promises9.default.writeFile(AUTH_FILE_PATH, `${JSON.stringify(auth, null, 2)}
88753
+ await import_promises10.default.writeFile(AUTH_FILE_PATH, `${JSON.stringify(auth, null, 2)}
88351
88754
  `, {
88352
88755
  encoding: "utf8",
88353
88756
  mode: 384
@@ -88361,11 +88764,11 @@ function shouldRefresh(accessTokenExpiresAt) {
88361
88764
  return expiresAt - Date.now() <= REFRESH_WINDOW_MS;
88362
88765
  }
88363
88766
  function openBrowser(url2) {
88364
- const platform2 = import_node_os12.default.platform();
88365
- if (platform2 === "darwin") {
88767
+ const platform3 = import_node_os13.default.platform();
88768
+ if (platform3 === "darwin") {
88366
88769
  return (0, import_node_child_process9.spawn)("open", [url2], { stdio: "ignore", detached: true });
88367
88770
  }
88368
- if (platform2 === "win32") {
88771
+ if (platform3 === "win32") {
88369
88772
  return (0, import_node_child_process9.spawn)("cmd", ["/c", "start", "", url2], { stdio: "ignore", detached: true });
88370
88773
  }
88371
88774
  return (0, import_node_child_process9.spawn)("xdg-open", [url2], { stdio: "ignore", detached: true });
@@ -88562,8 +88965,8 @@ async function authorizedApiFetch(auth, requestPath, init) {
88562
88965
  }
88563
88966
 
88564
88967
  // packages/cloud/src/workflows.ts
88565
- var import_promises10 = __toESM(require("node:fs/promises"), 1);
88566
- var import_node_path33 = __toESM(require("node:path"), 1);
88968
+ var import_promises11 = __toESM(require("node:fs/promises"), 1);
88969
+ var import_node_path34 = __toESM(require("node:path"), 1);
88567
88970
  var import_ignore3 = __toESM(require_ignore(), 1);
88568
88971
  function validateYamlWorkflow(content) {
88569
88972
  const hasField = (field) => new RegExp(`^${field}\\s*:`, "m").test(content);
@@ -88623,7 +89026,7 @@ ${message}`);
88623
89026
  }
88624
89027
  }
88625
89028
  function inferWorkflowFileType(filePath) {
88626
- const ext = import_node_path33.default.extname(filePath).toLowerCase();
89029
+ const ext = import_node_path34.default.extname(filePath).toLowerCase();
88627
89030
  switch (ext) {
88628
89031
  case ".yaml":
88629
89032
  case ".yml":
@@ -88639,9 +89042,9 @@ function inferWorkflowFileType(filePath) {
88639
89042
  }
88640
89043
  }
88641
89044
  async function resolveWorkflowInput(workflowArg, explicitFileType) {
88642
- const looksLikeFile = import_node_path33.default.isAbsolute(workflowArg) || workflowArg.includes(import_node_path33.default.sep) || inferWorkflowFileType(workflowArg) !== null;
89045
+ const looksLikeFile = import_node_path34.default.isAbsolute(workflowArg) || workflowArg.includes(import_node_path34.default.sep) || inferWorkflowFileType(workflowArg) !== null;
88643
89046
  try {
88644
- const workflow2 = await import_promises10.default.readFile(workflowArg, "utf-8");
89047
+ const workflow2 = await import_promises11.default.readFile(workflowArg, "utf-8");
88645
89048
  const fileType = explicitFileType ?? inferWorkflowFileType(workflowArg);
88646
89049
  if (!fileType) {
88647
89050
  throw new Error(`Could not infer workflow type from ${workflowArg}. Use --file-type.`);
@@ -88680,7 +89083,7 @@ async function scheduleWorkflow(workflowArg, options = {}) {
88680
89083
  validateYamlWorkflow(input.workflow);
88681
89084
  }
88682
89085
  const requestBody = {
88683
- name: options.name?.trim() || import_node_path33.default.basename(workflowArg),
89086
+ name: options.name?.trim() || import_node_path34.default.basename(workflowArg),
88684
89087
  schedule_type: hasCron ? "cron" : "once",
88685
89088
  timezone: options.timezone?.trim() || "UTC",
88686
89089
  workflowRequest: {
@@ -88781,7 +89184,7 @@ function isMissingFileError(error51) {
88781
89184
  var DEBUG = process.env.AGENT_RELAY_DEBUG_SSH === "1";
88782
89185
 
88783
89186
  // packages/sdk/dist/workflows/builder.js
88784
- var import_node_path34 = __toESM(require("node:path"), 1);
89187
+ var import_node_path35 = __toESM(require("node:path"), 1);
88785
89188
  var import_yaml3 = __toESM(require_dist(), 1);
88786
89189
 
88787
89190
  // packages/sdk/dist/workflows/cloud-runner.js
@@ -89140,7 +89543,7 @@ var WorkflowBuilder = class {
89140
89543
  async run(options = {}) {
89141
89544
  const config2 = this.toConfig();
89142
89545
  const runnerCwd = options.cwd ?? process.cwd();
89143
- const dbPath = import_node_path34.default.join(runnerCwd, ".agent-relay", "workflow-runs.jsonl");
89546
+ const dbPath = import_node_path35.default.join(runnerCwd, ".agent-relay", "workflow-runs.jsonl");
89144
89547
  const db = new JsonFileWorkflowDb(dbPath);
89145
89548
  const runner = new WorkflowRunner({
89146
89549
  cwd: options.cwd,
@@ -90058,7 +90461,7 @@ var StateStore = class extends import_node_events5.EventEmitter {
90058
90461
 
90059
90462
  // packages/sdk/dist/workflows/templates.js
90060
90463
  var import_node_fs23 = require("node:fs");
90061
- var import_node_path35 = __toESM(require("node:path"), 1);
90464
+ var import_node_path36 = __toESM(require("node:path"), 1);
90062
90465
  var import_node_url2 = require("node:url");
90063
90466
  var import_yaml4 = __toESM(require_dist(), 1);
90064
90467
  var YAML_EXTENSIONS = [".yaml", ".yml"];
@@ -90083,7 +90486,7 @@ var TemplateRegistry = class {
90083
90486
  fetcher;
90084
90487
  constructor(options = {}) {
90085
90488
  this.builtInTemplatesDir = this.resolveBuiltInTemplatesDir(options.builtInTemplatesDir);
90086
- this.customTemplatesDir = options.customTemplatesDir ? import_node_path35.default.resolve(options.customTemplatesDir) : import_node_path35.default.resolve(options.workspaceDir ?? process.cwd(), ".relay/workflows");
90489
+ this.customTemplatesDir = options.customTemplatesDir ? import_node_path36.default.resolve(options.customTemplatesDir) : import_node_path36.default.resolve(options.workspaceDir ?? process.cwd(), ".relay/workflows");
90087
90490
  this.fetcher = options.fetcher ?? fetch;
90088
90491
  }
90089
90492
  listBuiltInTemplates() {
@@ -90157,12 +90560,12 @@ var TemplateRegistry = class {
90157
90560
  if (!templateName) {
90158
90561
  throw new Error('Template name is required. Provide name explicitly or include a string "name" field.');
90159
90562
  }
90160
- if (templateName.includes("/") || templateName.includes("\\") || templateName.includes("..") || import_node_path35.default.isAbsolute(templateName)) {
90563
+ if (templateName.includes("/") || templateName.includes("\\") || templateName.includes("..") || import_node_path36.default.isAbsolute(templateName)) {
90161
90564
  throw new Error(`Invalid template name: "${templateName}" contains path separators or traversal sequences`);
90162
90565
  }
90163
90566
  this.validateRelayConfig(parsed, url2);
90164
90567
  await import_node_fs23.promises.mkdir(this.customTemplatesDir, { recursive: true });
90165
- const targetPath = import_node_path35.default.join(this.customTemplatesDir, `${templateName}.yaml`);
90568
+ const targetPath = import_node_path36.default.join(this.customTemplatesDir, `${templateName}.yaml`);
90166
90569
  await import_node_fs23.promises.writeFile(targetPath, (0, import_yaml4.stringify)(parsed), "utf-8");
90167
90570
  return targetPath;
90168
90571
  }
@@ -90184,12 +90587,12 @@ var TemplateRegistry = class {
90184
90587
  }
90185
90588
  resolveBuiltInTemplatesDir(explicitDir) {
90186
90589
  if (explicitDir) {
90187
- return import_node_path35.default.resolve(explicitDir);
90590
+ return import_node_path36.default.resolve(explicitDir);
90188
90591
  }
90189
- const currentDir = import_node_path35.default.dirname((0, import_node_url2.fileURLToPath)(import_meta_url));
90592
+ const currentDir = import_node_path36.default.dirname((0, import_node_url2.fileURLToPath)(import_meta_url));
90190
90593
  const candidates = [
90191
- import_node_path35.default.resolve(currentDir, "builtin-templates"),
90192
- import_node_path35.default.resolve(currentDir, "../workflows/builtin-templates")
90594
+ import_node_path36.default.resolve(currentDir, "builtin-templates"),
90595
+ import_node_path36.default.resolve(currentDir, "../workflows/builtin-templates")
90193
90596
  ];
90194
90597
  for (const candidate of candidates) {
90195
90598
  if ((0, import_node_fs23.existsSync)(candidate)) {
@@ -90212,10 +90615,10 @@ var TemplateRegistry = class {
90212
90615
  }
90213
90616
  async findTemplatePath(directory, templateName) {
90214
90617
  for (const ext of YAML_EXTENSIONS) {
90215
- const candidate = import_node_path35.default.join(directory, `${templateName}${ext}`);
90618
+ const candidate = import_node_path36.default.join(directory, `${templateName}${ext}`);
90216
90619
  try {
90217
- const stat2 = await import_node_fs23.promises.stat(candidate);
90218
- if (stat2.isFile()) {
90620
+ const stat3 = await import_node_fs23.promises.stat(candidate);
90621
+ if (stat3.isFile()) {
90219
90622
  return candidate;
90220
90623
  }
90221
90624
  } catch {
@@ -90560,7 +90963,7 @@ function pythonVerifyCommand() {
90560
90963
 
90561
90964
  // packages/sdk/dist/workflows/run-script.js
90562
90965
  var import_node_fs24 = __toESM(require("node:fs"), 1);
90563
- var import_node_path36 = __toESM(require("node:path"), 1);
90966
+ var import_node_path37 = __toESM(require("node:path"), 1);
90564
90967
  var import_node_child_process10 = require("node:child_process");
90565
90968
  function diag(msg) {
90566
90969
  try {
@@ -90575,12 +90978,12 @@ function diag(msg) {
90575
90978
  }
90576
90979
  }
90577
90980
  function findLocalSdkWorkspace(startDir) {
90578
- let current = import_node_path36.default.resolve(startDir);
90579
- const root = import_node_path36.default.parse(current).root;
90981
+ let current = import_node_path37.default.resolve(startDir);
90982
+ const root = import_node_path37.default.parse(current).root;
90580
90983
  while (true) {
90581
- const packageJsonPath = import_node_path36.default.join(current, "package.json");
90582
- const sdkDir = import_node_path36.default.join(current, "packages", "sdk");
90583
- const sdkPackageJsonPath = import_node_path36.default.join(sdkDir, "package.json");
90984
+ const packageJsonPath = import_node_path37.default.join(current, "package.json");
90985
+ const sdkDir = import_node_path37.default.join(current, "packages", "sdk");
90986
+ const sdkPackageJsonPath = import_node_path37.default.join(sdkDir, "package.json");
90584
90987
  try {
90585
90988
  if (import_node_fs24.default.existsSync(packageJsonPath) && import_node_fs24.default.existsSync(sdkPackageJsonPath)) {
90586
90989
  const pkg = JSON.parse(import_node_fs24.default.readFileSync(packageJsonPath, "utf8"));
@@ -90593,14 +90996,14 @@ function findLocalSdkWorkspace(startDir) {
90593
90996
  }
90594
90997
  if (current === root)
90595
90998
  return null;
90596
- current = import_node_path36.default.dirname(current);
90999
+ current = import_node_path37.default.dirname(current);
90597
91000
  }
90598
91001
  }
90599
91002
  function ensureLocalSdkWorkflowRuntime(startDir, execRunner = import_node_child_process10.execFileSync) {
90600
91003
  const workspace = findLocalSdkWorkspace(startDir);
90601
91004
  if (!workspace)
90602
91005
  return;
90603
- const workflowsEntry = import_node_path36.default.join(workspace.sdkDir, "dist", "workflows", "index.js");
91006
+ const workflowsEntry = import_node_path37.default.join(workspace.sdkDir, "dist", "workflows", "index.js");
90604
91007
  if (import_node_fs24.default.existsSync(workflowsEntry))
90605
91008
  return;
90606
91009
  console.log("[agent-relay] Detected local @agent-relay/sdk workspace without built workflows runtime; building SDK workflow dependencies...");
@@ -90663,8 +91066,8 @@ function resolveLocalTypeScriptImport(fromFile, specifier) {
90663
91066
  if (!specifier.startsWith(".") && !specifier.startsWith("/")) {
90664
91067
  return null;
90665
91068
  }
90666
- const basePath = specifier.startsWith("/") ? import_node_path36.default.resolve(specifier) : import_node_path36.default.resolve(import_node_path36.default.dirname(fromFile), specifier);
90667
- const ext = import_node_path36.default.extname(basePath);
91069
+ const basePath = specifier.startsWith("/") ? import_node_path37.default.resolve(specifier) : import_node_path37.default.resolve(import_node_path37.default.dirname(fromFile), specifier);
91070
+ const ext = import_node_path37.default.extname(basePath);
90668
91071
  const candidates = ext === ".js" || ext === ".mjs" || ext === ".cjs" ? [
90669
91072
  `${basePath.slice(0, -ext.length)}.ts`,
90670
91073
  `${basePath.slice(0, -ext.length)}.tsx`,
@@ -90676,10 +91079,10 @@ function resolveLocalTypeScriptImport(fromFile, specifier) {
90676
91079
  `${basePath}.tsx`,
90677
91080
  `${basePath}.mts`,
90678
91081
  `${basePath}.cts`,
90679
- import_node_path36.default.join(basePath, "index.ts"),
90680
- import_node_path36.default.join(basePath, "index.tsx"),
90681
- import_node_path36.default.join(basePath, "index.mts"),
90682
- import_node_path36.default.join(basePath, "index.cts")
91082
+ import_node_path37.default.join(basePath, "index.ts"),
91083
+ import_node_path37.default.join(basePath, "index.tsx"),
91084
+ import_node_path37.default.join(basePath, "index.mts"),
91085
+ import_node_path37.default.join(basePath, "index.cts")
90683
91086
  ];
90684
91087
  for (const candidate of candidates) {
90685
91088
  if (/\.(?:ts|tsx|mts|cts)$/.test(candidate) && import_node_fs24.default.existsSync(candidate)) {
@@ -90700,7 +91103,7 @@ function findStaticLocalTypeScriptImports(filePath, source) {
90700
91103
  return imports;
90701
91104
  }
90702
91105
  function shouldSkipNodeStripTypesPreflight(filePath, seen = /* @__PURE__ */ new Set(), isEntry = true) {
90703
- const resolvedPath = import_node_path36.default.resolve(filePath);
91106
+ const resolvedPath = import_node_path37.default.resolve(filePath);
90704
91107
  if (seen.has(resolvedPath)) {
90705
91108
  return false;
90706
91109
  }
@@ -90829,14 +91232,14 @@ async function spawnRunnerWithStderrCapture(command, args, env) {
90829
91232
  }
90830
91233
  async function runScriptWorkflow(filePath, options = {}) {
90831
91234
  diag(`runScriptWorkflow: resolving ${filePath}`);
90832
- const resolved = import_node_path36.default.resolve(filePath);
91235
+ const resolved = import_node_path37.default.resolve(filePath);
90833
91236
  if (!import_node_fs24.default.existsSync(resolved)) {
90834
91237
  throw new Error(`File not found: ${resolved}`);
90835
91238
  }
90836
- const ext = import_node_path36.default.extname(resolved).toLowerCase();
90837
- const runIdFile = import_node_path36.default.join(process.cwd(), ".agent-relay", `script-run-id-${process.pid}-${Date.now()}.txt`);
91239
+ const ext = import_node_path37.default.extname(resolved).toLowerCase();
91240
+ const runIdFile = import_node_path37.default.join(process.cwd(), ".agent-relay", `script-run-id-${process.pid}-${Date.now()}.txt`);
90838
91241
  try {
90839
- import_node_fs24.default.mkdirSync(import_node_path36.default.dirname(runIdFile), { recursive: true });
91242
+ import_node_fs24.default.mkdirSync(import_node_path37.default.dirname(runIdFile), { recursive: true });
90840
91243
  } catch {
90841
91244
  }
90842
91245
  const childEnv = { ...process.env, AGENT_RELAY_RUN_ID_FILE: runIdFile };
@@ -90874,7 +91277,7 @@ Run ID: ${runId}`;
90874
91277
  };
90875
91278
  if (ext === ".ts" || ext === ".tsx") {
90876
91279
  diag("runScriptWorkflow: ensureLocalSdkWorkflowRuntime start");
90877
- ensureLocalSdkWorkflowRuntime(import_node_path36.default.dirname(resolved));
91280
+ ensureLocalSdkWorkflowRuntime(import_node_path37.default.dirname(resolved));
90878
91281
  diag("runScriptWorkflow: ensureLocalSdkWorkflowRuntime done");
90879
91282
  const wrapRunnerError = (runner, result) => {
90880
91283
  const parsed = parseTsxStderr(result.stderr);
@@ -92300,7 +92703,7 @@ function isValidAgentName(name) {
92300
92703
 
92301
92704
  // packages/utils/dist/logger.js
92302
92705
  var import_node_fs25 = __toESM(require("node:fs"), 1);
92303
- var import_node_path37 = __toESM(require("node:path"), 1);
92706
+ var import_node_path38 = __toESM(require("node:path"), 1);
92304
92707
  function getLogFile() {
92305
92708
  return process.env.AGENT_RELAY_LOG_FILE;
92306
92709
  }
@@ -92318,7 +92721,7 @@ var LEVEL_PRIORITY = {
92318
92721
  };
92319
92722
  var createdLogDirs = /* @__PURE__ */ new Set();
92320
92723
  function ensureLogDir(logFile) {
92321
- const logDir = import_node_path37.default.dirname(logFile);
92724
+ const logDir = import_node_path38.default.dirname(logFile);
92322
92725
  if (!createdLogDirs.has(logDir) && !import_node_fs25.default.existsSync(logDir)) {
92323
92726
  import_node_fs25.default.mkdirSync(logDir, { recursive: true });
92324
92727
  createdLogDirs.add(logDir);
@@ -92764,16 +93167,16 @@ function getRepoFullNameFromPath(workingDirectory) {
92764
93167
 
92765
93168
  // packages/utils/dist/update-checker.js
92766
93169
  var import_node_fs27 = __toESM(require("node:fs"), 1);
92767
- var import_node_path38 = __toESM(require("node:path"), 1);
93170
+ var import_node_path39 = __toESM(require("node:path"), 1);
92768
93171
  var import_node_https2 = __toESM(require("node:https"), 1);
92769
- var import_node_os14 = __toESM(require("node:os"), 1);
93172
+ var import_node_os15 = __toESM(require("node:os"), 1);
92770
93173
  var import_compare_versions = __toESM(require_umd(), 1);
92771
93174
  var PACKAGE_NAME = "agent-relay";
92772
93175
  var CHECK_INTERVAL_MS = 60 * 60 * 1e3;
92773
93176
  var NPM_REGISTRY_URL = `https://registry.npmjs.org/${PACKAGE_NAME}/latest`;
92774
93177
  function getCachePath() {
92775
- const cacheDir = import_node_path38.default.join(import_node_os14.default.homedir(), ".agent-relay");
92776
- return import_node_path38.default.join(cacheDir, "update-cache.json");
93178
+ const cacheDir = import_node_path39.default.join(import_node_os15.default.homedir(), ".agent-relay");
93179
+ return import_node_path39.default.join(cacheDir, "update-cache.json");
92777
93180
  }
92778
93181
  function readCache() {
92779
93182
  try {
@@ -92789,7 +93192,7 @@ function readCache() {
92789
93192
  function writeCache(cache) {
92790
93193
  try {
92791
93194
  const cachePath = getCachePath();
92792
- const cacheDir = import_node_path38.default.dirname(cachePath);
93195
+ const cacheDir = import_node_path39.default.dirname(cachePath);
92793
93196
  if (!import_node_fs27.default.existsSync(cacheDir)) {
92794
93197
  import_node_fs27.default.mkdirSync(cacheDir, { recursive: true });
92795
93198
  }
@@ -93073,8 +93476,8 @@ function validateModelForCli(cli, model) {
93073
93476
 
93074
93477
  // packages/utils/dist/relay-pty-path.js
93075
93478
  var import_node_fs28 = __toESM(require("node:fs"), 1);
93076
- var import_node_os15 = __toESM(require("node:os"), 1);
93077
- var import_node_path39 = __toESM(require("node:path"), 1);
93479
+ var import_node_os16 = __toESM(require("node:os"), 1);
93480
+ var import_node_path40 = __toESM(require("node:path"), 1);
93078
93481
  var SUPPORTED_PLATFORMS = {
93079
93482
  darwin: {
93080
93483
  arm64: "relay-pty-darwin-arm64",
@@ -93086,14 +93489,14 @@ var SUPPORTED_PLATFORMS = {
93086
93489
  }
93087
93490
  };
93088
93491
  function getPlatformBinaryName() {
93089
- const platform2 = import_node_os15.default.platform();
93090
- const arch = import_node_os15.default.arch();
93091
- return SUPPORTED_PLATFORMS[platform2]?.[arch] ?? null;
93492
+ const platform3 = import_node_os16.default.platform();
93493
+ const arch = import_node_os16.default.arch();
93494
+ return SUPPORTED_PLATFORMS[platform3]?.[arch] ?? null;
93092
93495
  }
93093
93496
  function isPlatformSupported() {
93094
- const platform2 = import_node_os15.default.platform();
93095
- const arch = import_node_os15.default.arch();
93096
- return SUPPORTED_PLATFORMS[platform2]?.[arch] !== void 0;
93497
+ const platform3 = import_node_os16.default.platform();
93498
+ const arch = import_node_os16.default.arch();
93499
+ return SUPPORTED_PLATFORMS[platform3]?.[arch] !== void 0;
93097
93500
  }
93098
93501
  function getSupportedPlatforms() {
93099
93502
  const platforms = [];
@@ -93122,19 +93525,19 @@ function findRelayPtyBinary(callerDirname) {
93122
93525
  const scopedMatch = normalizedCaller.match(/^(.+?\/node_modules)\/@agent-relay\//);
93123
93526
  const directMatch = normalizedCaller.match(/^(.+?\/node_modules\/agent-relay)/);
93124
93527
  if (scopedMatch) {
93125
- packageRoots.push(import_node_path39.default.join(scopedMatch[1], "agent-relay"));
93528
+ packageRoots.push(import_node_path40.default.join(scopedMatch[1], "agent-relay"));
93126
93529
  }
93127
93530
  if (directMatch) {
93128
93531
  packageRoots.push(directMatch[1]);
93129
93532
  }
93130
93533
  const home = process.env.HOME || process.env.USERPROFILE || "";
93131
93534
  if (home) {
93132
- const npxCacheBase = import_node_path39.default.join(home, ".npm", "_npx");
93535
+ const npxCacheBase = import_node_path40.default.join(home, ".npm", "_npx");
93133
93536
  if (import_node_fs28.default.existsSync(npxCacheBase)) {
93134
93537
  try {
93135
93538
  const entries = import_node_fs28.default.readdirSync(npxCacheBase);
93136
93539
  for (const entry of entries) {
93137
- const npxPackage = import_node_path39.default.join(npxCacheBase, entry, "node_modules", "agent-relay");
93540
+ const npxPackage = import_node_path40.default.join(npxCacheBase, entry, "node_modules", "agent-relay");
93138
93541
  if (import_node_fs28.default.existsSync(npxPackage)) {
93139
93542
  packageRoots.push(npxPackage);
93140
93543
  }
@@ -93143,42 +93546,42 @@ function findRelayPtyBinary(callerDirname) {
93143
93546
  }
93144
93547
  }
93145
93548
  }
93146
- packageRoots.push(import_node_path39.default.join(process.cwd(), "node_modules", "agent-relay"));
93549
+ packageRoots.push(import_node_path40.default.join(process.cwd(), "node_modules", "agent-relay"));
93147
93550
  if (home) {
93148
- packageRoots.push(import_node_path39.default.join(home, ".nvm", "versions", "node", process.version, "lib", "node_modules", "agent-relay"));
93149
- packageRoots.push(import_node_path39.default.join(home, ".volta", "tools", "image", "packages", "agent-relay", "lib", "node_modules", "agent-relay"));
93150
- packageRoots.push(import_node_path39.default.join(home, ".fnm", "node-versions", process.version, "installation", "lib", "node_modules", "agent-relay"));
93151
- packageRoots.push(import_node_path39.default.join(home, "n", "lib", "node_modules", "agent-relay"));
93152
- packageRoots.push(import_node_path39.default.join(home, ".asdf", "installs", "nodejs", process.version.replace("v", ""), "lib", "node_modules", "agent-relay"));
93153
- packageRoots.push(import_node_path39.default.join(home, ".local", "share", "pnpm", "global", "node_modules", "agent-relay"));
93154
- packageRoots.push(import_node_path39.default.join(home, ".config", "yarn", "global", "node_modules", "agent-relay"));
93155
- packageRoots.push(import_node_path39.default.join(home, ".yarn", "global", "node_modules", "agent-relay"));
93156
- }
93157
- const bashInstallerDir = process.env.AGENT_RELAY_INSTALL_DIR ? import_node_path39.default.join(process.env.AGENT_RELAY_INSTALL_DIR, "bin") : home ? import_node_path39.default.join(home, ".agent-relay", "bin") : null;
93158
- const bashInstallerBinDir = process.env.AGENT_RELAY_BIN_DIR || (home ? import_node_path39.default.join(home, ".local", "bin") : null);
93159
- const nodePrefix = import_node_path39.default.resolve(import_node_path39.default.dirname(process.execPath), "..");
93160
- packageRoots.push(import_node_path39.default.join(nodePrefix, "lib", "node_modules", "agent-relay"));
93551
+ packageRoots.push(import_node_path40.default.join(home, ".nvm", "versions", "node", process.version, "lib", "node_modules", "agent-relay"));
93552
+ packageRoots.push(import_node_path40.default.join(home, ".volta", "tools", "image", "packages", "agent-relay", "lib", "node_modules", "agent-relay"));
93553
+ packageRoots.push(import_node_path40.default.join(home, ".fnm", "node-versions", process.version, "installation", "lib", "node_modules", "agent-relay"));
93554
+ packageRoots.push(import_node_path40.default.join(home, "n", "lib", "node_modules", "agent-relay"));
93555
+ packageRoots.push(import_node_path40.default.join(home, ".asdf", "installs", "nodejs", process.version.replace("v", ""), "lib", "node_modules", "agent-relay"));
93556
+ packageRoots.push(import_node_path40.default.join(home, ".local", "share", "pnpm", "global", "node_modules", "agent-relay"));
93557
+ packageRoots.push(import_node_path40.default.join(home, ".config", "yarn", "global", "node_modules", "agent-relay"));
93558
+ packageRoots.push(import_node_path40.default.join(home, ".yarn", "global", "node_modules", "agent-relay"));
93559
+ }
93560
+ const bashInstallerDir = process.env.AGENT_RELAY_INSTALL_DIR ? import_node_path40.default.join(process.env.AGENT_RELAY_INSTALL_DIR, "bin") : home ? import_node_path40.default.join(home, ".agent-relay", "bin") : null;
93561
+ const bashInstallerBinDir = process.env.AGENT_RELAY_BIN_DIR || (home ? import_node_path40.default.join(home, ".local", "bin") : null);
93562
+ const nodePrefix = import_node_path40.default.resolve(import_node_path40.default.dirname(process.execPath), "..");
93563
+ packageRoots.push(import_node_path40.default.join(nodePrefix, "lib", "node_modules", "agent-relay"));
93161
93564
  packageRoots.push("/usr/local/lib/node_modules/agent-relay");
93162
93565
  packageRoots.push("/opt/homebrew/lib/node_modules/agent-relay");
93163
93566
  packageRoots.push("/usr/lib/node_modules/agent-relay");
93164
93567
  const candidates = [];
93165
93568
  for (const root of packageRoots) {
93166
93569
  if (platformBinary) {
93167
- candidates.push(import_node_path39.default.join(root, "bin", platformBinary));
93570
+ candidates.push(import_node_path40.default.join(root, "bin", platformBinary));
93168
93571
  }
93169
- candidates.push(import_node_path39.default.join(root, "bin", "relay-pty"));
93572
+ candidates.push(import_node_path40.default.join(root, "bin", "relay-pty"));
93170
93573
  }
93171
93574
  if (bashInstallerDir) {
93172
93575
  if (platformBinary) {
93173
- candidates.push(import_node_path39.default.join(bashInstallerDir, platformBinary));
93576
+ candidates.push(import_node_path40.default.join(bashInstallerDir, platformBinary));
93174
93577
  }
93175
- candidates.push(import_node_path39.default.join(bashInstallerDir, "relay-pty"));
93578
+ candidates.push(import_node_path40.default.join(bashInstallerDir, "relay-pty"));
93176
93579
  }
93177
93580
  if (bashInstallerBinDir) {
93178
93581
  if (platformBinary) {
93179
- candidates.push(import_node_path39.default.join(bashInstallerBinDir, platformBinary));
93582
+ candidates.push(import_node_path40.default.join(bashInstallerBinDir, platformBinary));
93180
93583
  }
93181
- candidates.push(import_node_path39.default.join(bashInstallerBinDir, "relay-pty"));
93584
+ candidates.push(import_node_path40.default.join(bashInstallerBinDir, "relay-pty"));
93182
93585
  }
93183
93586
  candidates.push("/app/bin/relay-pty");
93184
93587
  candidates.push("/usr/local/bin/relay-pty");
@@ -93209,11 +93612,11 @@ function isPlatformCompatibleBinary(filePath) {
93209
93612
  return false;
93210
93613
  }
93211
93614
  const magic = header.readUInt32BE(0);
93212
- const platform2 = import_node_os15.default.platform();
93213
- if (platform2 === "darwin") {
93615
+ const platform3 = import_node_os16.default.platform();
93616
+ if (platform3 === "darwin") {
93214
93617
  return isMachOBinary(magic);
93215
93618
  }
93216
- if (platform2 === "linux") {
93619
+ if (platform3 === "linux") {
93217
93620
  return magic === 2135247942;
93218
93621
  }
93219
93622
  return true;
@@ -93842,52 +94245,52 @@ var import_node_child_process15 = require("node:child_process");
93842
94245
 
93843
94246
  // packages/config/dist/project-namespace.js
93844
94247
  var import_node_crypto16 = __toESM(require("node:crypto"), 1);
93845
- var import_node_path40 = __toESM(require("node:path"), 1);
94248
+ var import_node_path41 = __toESM(require("node:path"), 1);
93846
94249
  var import_node_fs29 = __toESM(require("node:fs"), 1);
93847
- var import_node_os16 = __toESM(require("node:os"), 1);
94250
+ var import_node_os17 = __toESM(require("node:os"), 1);
93848
94251
  function getGlobalBaseDir2() {
93849
94252
  if (process.env.AGENT_RELAY_DATA_DIR) {
93850
94253
  return process.env.AGENT_RELAY_DATA_DIR;
93851
94254
  }
93852
94255
  const xdgDataHome = process.env.XDG_DATA_HOME;
93853
94256
  if (xdgDataHome) {
93854
- return import_node_path40.default.join(xdgDataHome, "agent-relay");
94257
+ return import_node_path41.default.join(xdgDataHome, "agent-relay");
93855
94258
  }
93856
- return import_node_path40.default.join(import_node_os16.default.homedir(), ".agent-relay");
94259
+ return import_node_path41.default.join(import_node_os17.default.homedir(), ".agent-relay");
93857
94260
  }
93858
94261
  var GLOBAL_BASE_DIR2 = getGlobalBaseDir2();
93859
94262
  var PROJECT_DATA_DIR = ".agent-relay";
93860
94263
  function hashPath(projectPath) {
93861
- const normalized = import_node_path40.default.resolve(projectPath);
94264
+ const normalized = import_node_path41.default.resolve(projectPath);
93862
94265
  const hash2 = import_node_crypto16.default.createHash("sha256").update(normalized).digest("hex");
93863
94266
  return hash2.substring(0, 12);
93864
94267
  }
93865
94268
  function findProjectRoot(startDir = process.cwd()) {
93866
94269
  if (process.env.AGENT_RELAY_PROJECT) {
93867
- return import_node_path40.default.resolve(process.env.AGENT_RELAY_PROJECT);
94270
+ return import_node_path41.default.resolve(process.env.AGENT_RELAY_PROJECT);
93868
94271
  }
93869
- let current = import_node_path40.default.resolve(startDir);
93870
- const root = import_node_path40.default.parse(current).root;
94272
+ let current = import_node_path41.default.resolve(startDir);
94273
+ const root = import_node_path41.default.parse(current).root;
93871
94274
  const markers = [".git", "package.json", "Cargo.toml", "go.mod", "pyproject.toml", ".agent-relay"];
93872
94275
  while (current !== root) {
93873
94276
  for (const marker of markers) {
93874
- if (import_node_fs29.default.existsSync(import_node_path40.default.join(current, marker))) {
94277
+ if (import_node_fs29.default.existsSync(import_node_path41.default.join(current, marker))) {
93875
94278
  return current;
93876
94279
  }
93877
94280
  }
93878
- current = import_node_path40.default.dirname(current);
94281
+ current = import_node_path41.default.dirname(current);
93879
94282
  }
93880
- return import_node_path40.default.resolve(startDir);
94283
+ return import_node_path41.default.resolve(startDir);
93881
94284
  }
93882
94285
  function getProjectPaths2(projectRoot) {
93883
94286
  const root = projectRoot ?? findProjectRoot();
93884
94287
  const projectId = hashPath(root);
93885
- const dataDir = import_node_path40.default.join(root, PROJECT_DATA_DIR);
94288
+ const dataDir = import_node_path41.default.join(root, PROJECT_DATA_DIR);
93886
94289
  return {
93887
94290
  dataDir,
93888
- teamDir: import_node_path40.default.join(dataDir, "team"),
93889
- dbPath: import_node_path40.default.join(dataDir, "messages.sqlite"),
93890
- socketPath: import_node_path40.default.join(dataDir, "relay.sock"),
94291
+ teamDir: import_node_path41.default.join(dataDir, "team"),
94292
+ dbPath: import_node_path41.default.join(dataDir, "messages.sqlite"),
94293
+ socketPath: import_node_path41.default.join(dataDir, "relay.sock"),
93891
94294
  projectRoot: root,
93892
94295
  projectId
93893
94296
  };
@@ -93895,22 +94298,22 @@ function getProjectPaths2(projectRoot) {
93895
94298
 
93896
94299
  // packages/config/dist/trajectory-config.js
93897
94300
  var import_node_fs30 = require("node:fs");
93898
- var import_node_path41 = require("node:path");
93899
- var import_node_os17 = require("node:os");
94301
+ var import_node_path42 = require("node:path");
94302
+ var import_node_os18 = require("node:os");
93900
94303
  var import_node_crypto17 = require("node:crypto");
93901
94304
  function getAgentRelayConfigDir() {
93902
- return process.env.AGENT_RELAY_CONFIG_DIR ?? (0, import_node_path41.join)((0, import_node_os17.homedir)(), ".config", "agent-relay");
94305
+ return process.env.AGENT_RELAY_CONFIG_DIR ?? (0, import_node_path42.join)((0, import_node_os18.homedir)(), ".config", "agent-relay");
93903
94306
  }
93904
94307
  var configCache = null;
93905
94308
  function getRelayConfigPath(_projectRoot) {
93906
- return (0, import_node_path41.join)(getAgentRelayConfigDir(), "relay.json");
94309
+ return (0, import_node_path42.join)(getAgentRelayConfigDir(), "relay.json");
93907
94310
  }
93908
94311
  function readRelayConfig(projectRoot) {
93909
94312
  const configPath = getRelayConfigPath(projectRoot);
93910
94313
  if (configCache && configCache.path === configPath) {
93911
94314
  try {
93912
- const stat2 = (0, import_node_fs30.statSync)(configPath);
93913
- if (stat2.mtimeMs === configCache.mtime) {
94315
+ const stat3 = (0, import_node_fs30.statSync)(configPath);
94316
+ if (stat3.mtimeMs === configCache.mtime) {
93914
94317
  return configCache.config;
93915
94318
  }
93916
94319
  } catch {
@@ -93923,8 +94326,8 @@ function readRelayConfig(projectRoot) {
93923
94326
  const content = (0, import_node_fs30.readFileSync)(configPath, "utf-8");
93924
94327
  const config2 = JSON.parse(content);
93925
94328
  try {
93926
- const stat2 = (0, import_node_fs30.statSync)(configPath);
93927
- configCache = { path: configPath, config: config2, mtime: stat2.mtimeMs };
94329
+ const stat3 = (0, import_node_fs30.statSync)(configPath);
94330
+ configCache = { path: configPath, config: config2, mtime: stat3.mtimeMs };
93928
94331
  } catch {
93929
94332
  }
93930
94333
  return config2;
@@ -93943,12 +94346,12 @@ function getProjectHash(projectRoot) {
93943
94346
  }
93944
94347
  function getUserTrajectoriesDir(projectRoot) {
93945
94348
  const projectHash = getProjectHash(projectRoot);
93946
- const configDir = process.env.XDG_CONFIG_HOME || (0, import_node_path41.join)((0, import_node_os17.homedir)(), ".config");
93947
- return (0, import_node_path41.join)(configDir, "agent-relay", "trajectories", projectHash);
94349
+ const configDir = process.env.XDG_CONFIG_HOME || (0, import_node_path42.join)((0, import_node_os18.homedir)(), ".config");
94350
+ return (0, import_node_path42.join)(configDir, "agent-relay", "trajectories", projectHash);
93948
94351
  }
93949
94352
  function getRepoTrajectoriesDir(projectRoot) {
93950
94353
  const root = projectRoot ?? getProjectPaths2().projectRoot;
93951
- return (0, import_node_path41.join)(root, ".trajectories");
94354
+ return (0, import_node_path42.join)(root, ".trajectories");
93952
94355
  }
93953
94356
  function getPrimaryTrajectoriesDir(projectRoot) {
93954
94357
  if (shouldStoreInRepo(projectRoot)) {
@@ -94589,7 +94992,7 @@ var HookEmitter = class {
94589
94992
 
94590
94993
  // packages/hooks/dist/inbox-check/utils.js
94591
94994
  var import_node_fs31 = require("node:fs");
94592
- var import_node_path42 = require("node:path");
94995
+ var import_node_path43 = require("node:path");
94593
94996
  var DEFAULT_INBOX_DIR = "/tmp/agent-relay";
94594
94997
  function getAgentName() {
94595
94998
  return process.env.AGENT_RELAY_NAME;
@@ -94599,7 +95002,7 @@ function getInboxPath(config2) {
94599
95002
  if (!agentName) {
94600
95003
  throw new Error("Agent name not configured. Set AGENT_RELAY_NAME env var.");
94601
95004
  }
94602
- return (0, import_node_path42.join)(config2.inboxDir, agentName, "inbox.md");
95005
+ return (0, import_node_path43.join)(config2.inboxDir, agentName, "inbox.md");
94603
95006
  }
94604
95007
  function inboxExists(inboxPath) {
94605
95008
  return (0, import_node_fs31.existsSync)(inboxPath);
@@ -94695,6 +95098,7 @@ init_dist2();
94695
95098
  DEFAULT_PROXY_ENV_REGISTRY,
94696
95099
  DefaultModels,
94697
95100
  ERROR_SEARCH_HINT,
95101
+ EventBus,
94698
95102
  GEMINI_MODEL_OPTIONS,
94699
95103
  GeminiModels,
94700
95104
  GitHubClient,
@@ -94752,6 +95156,7 @@ init_dist2();
94752
95156
  checkOutputContains,
94753
95157
  cleanLines,
94754
95158
  clearBinaryCache,
95159
+ clearBrokerLogs,
94755
95160
  clearResolveCache,
94756
95161
  collectCliSession,
94757
95162
  collectOutput,
@@ -94805,6 +95210,7 @@ init_dist2();
94805
95210
  generateUniqueAgentName,
94806
95211
  getAgentName,
94807
95212
  getBaseCli,
95213
+ getBrokerLogDir,
94808
95214
  getCachedRelayPtyPath,
94809
95215
  getCliDefinition,
94810
95216
  getCliRegistry,
@@ -94848,6 +95254,7 @@ init_dist2();
94848
95254
  isTrajectoryTrackingAvailable,
94849
95255
  isValidAgentName,
94850
95256
  isWorktreeStep,
95257
+ listBrokerLogs,
94851
95258
  listLoggedAgents,
94852
95259
  listPersonas,
94853
95260
  listWorkflowSchedules,
@@ -94863,6 +95270,7 @@ init_dist2();
94863
95270
  parseTsxStderr,
94864
95271
  parseVoteCommand,
94865
95272
  printUpdateNotification,
95273
+ pruneBrokerLogs,
94866
95274
  readInbox,
94867
95275
  resetPatternMetrics,
94868
95276
  resolveAllCustomSteps,
@@ -94895,6 +95303,7 @@ init_dist2();
94895
95303
  stripAnsi,
94896
95304
  stripAnsiFast,
94897
95305
  stripInjectedTaskEcho,
95306
+ tailBrokerLog,
94898
95307
  toReleaseResult,
94899
95308
  toSpawnResult,
94900
95309
  trackPatternPerformance,