agent-relay 4.0.31 → 4.0.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. package/bin/agent-relay-broker-darwin-arm64 +0 -0
  2. package/bin/agent-relay-broker-darwin-x64 +0 -0
  3. package/bin/agent-relay-broker-linux-arm64 +0 -0
  4. package/bin/agent-relay-broker-linux-x64 +0 -0
  5. package/dist/index.cjs +210 -75
  6. package/dist/src/cli/commands/on/start.d.ts.map +1 -1
  7. package/dist/src/cli/commands/on/start.js +149 -111
  8. package/dist/src/cli/commands/on/start.js.map +1 -1
  9. package/node_modules/@agent-relay/cloud/package.json +2 -2
  10. package/node_modules/@agent-relay/config/package.json +1 -1
  11. package/node_modules/@agent-relay/hooks/package.json +4 -4
  12. package/node_modules/@agent-relay/sdk/README.md +3 -0
  13. package/node_modules/@agent-relay/sdk/dist/relay.d.ts +16 -0
  14. package/node_modules/@agent-relay/sdk/dist/relay.d.ts.map +1 -1
  15. package/node_modules/@agent-relay/sdk/dist/relay.js +83 -0
  16. package/node_modules/@agent-relay/sdk/dist/relay.js.map +1 -1
  17. package/node_modules/@agent-relay/sdk/package.json +2 -2
  18. package/node_modules/@agent-relay/telemetry/package.json +1 -1
  19. package/node_modules/@agent-relay/trajectory/package.json +2 -2
  20. package/node_modules/@agent-relay/user-directory/package.json +2 -2
  21. package/node_modules/@agent-relay/utils/package.json +2 -2
  22. package/node_modules/@relayfile/local-mount/README.md +215 -0
  23. package/node_modules/@relayfile/local-mount/dist/auto-sync.d.ts +31 -0
  24. package/node_modules/@relayfile/local-mount/dist/auto-sync.js +466 -0
  25. package/node_modules/@relayfile/local-mount/dist/dotfiles.d.ts +18 -0
  26. package/node_modules/@relayfile/local-mount/dist/dotfiles.js +43 -0
  27. package/node_modules/@relayfile/local-mount/dist/index.d.ts +4 -0
  28. package/node_modules/@relayfile/local-mount/dist/index.js +3 -0
  29. package/node_modules/@relayfile/local-mount/dist/launch.d.ts +50 -0
  30. package/node_modules/@relayfile/local-mount/dist/launch.js +129 -0
  31. package/node_modules/@relayfile/local-mount/dist/symlink-mount.d.ts +23 -0
  32. package/{dist/src/cli/commands/on → node_modules/@relayfile/local-mount/dist}/symlink-mount.js +88 -20
  33. package/node_modules/@relayfile/local-mount/node_modules/chokidar/LICENSE +21 -0
  34. package/node_modules/@relayfile/local-mount/node_modules/chokidar/README.md +305 -0
  35. package/node_modules/@relayfile/local-mount/node_modules/chokidar/esm/handler.d.ts +90 -0
  36. package/node_modules/@relayfile/local-mount/node_modules/chokidar/esm/handler.js +629 -0
  37. package/node_modules/@relayfile/local-mount/node_modules/chokidar/esm/index.d.ts +215 -0
  38. package/node_modules/@relayfile/local-mount/node_modules/chokidar/esm/index.js +798 -0
  39. package/node_modules/@relayfile/local-mount/node_modules/chokidar/esm/package.json +1 -0
  40. package/node_modules/@relayfile/local-mount/node_modules/chokidar/handler.d.ts +90 -0
  41. package/node_modules/@relayfile/local-mount/node_modules/chokidar/handler.js +635 -0
  42. package/node_modules/@relayfile/local-mount/node_modules/chokidar/index.d.ts +215 -0
  43. package/node_modules/@relayfile/local-mount/node_modules/chokidar/index.js +804 -0
  44. package/node_modules/@relayfile/local-mount/node_modules/chokidar/package.json +69 -0
  45. package/node_modules/@relayfile/local-mount/node_modules/readdirp/LICENSE +21 -0
  46. package/node_modules/@relayfile/local-mount/node_modules/readdirp/README.md +120 -0
  47. package/node_modules/@relayfile/local-mount/node_modules/readdirp/esm/index.d.ts +108 -0
  48. package/node_modules/@relayfile/local-mount/node_modules/readdirp/esm/index.js +257 -0
  49. package/node_modules/@relayfile/local-mount/node_modules/readdirp/esm/package.json +1 -0
  50. package/node_modules/@relayfile/local-mount/node_modules/readdirp/index.d.ts +108 -0
  51. package/node_modules/@relayfile/local-mount/node_modules/readdirp/index.js +263 -0
  52. package/node_modules/@relayfile/local-mount/node_modules/readdirp/package.json +70 -0
  53. package/node_modules/@relayfile/local-mount/package.json +47 -0
  54. package/node_modules/@smithy/config-resolver/package.json +2 -2
  55. package/node_modules/@smithy/core/dist-cjs/index.js +2 -1
  56. package/node_modules/@smithy/core/dist-cjs/submodules/cbor/index.js +32 -14
  57. package/node_modules/@smithy/core/dist-cjs/submodules/endpoints/index.js +2 -2
  58. package/node_modules/@smithy/core/dist-cjs/submodules/event-streams/index.js +16 -8
  59. package/node_modules/@smithy/core/dist-cjs/submodules/protocols/index.js +17 -10
  60. package/node_modules/@smithy/core/dist-cjs/submodules/schema/index.js +6 -1
  61. package/node_modules/@smithy/core/dist-cjs/submodules/serde/index.js +6 -3
  62. package/node_modules/@smithy/core/dist-cjs/util-identity-and-auth/DefaultIdentityProviderConfig.js +2 -1
  63. package/node_modules/@smithy/core/dist-es/submodules/cbor/CborCodec.js +23 -11
  64. package/node_modules/@smithy/core/dist-es/submodules/cbor/parseCborBody.js +9 -3
  65. package/node_modules/@smithy/core/dist-es/submodules/endpoints/toEndpointV1.js +2 -2
  66. package/node_modules/@smithy/core/dist-es/submodules/event-streams/EventStreamSerde.js +16 -8
  67. package/node_modules/@smithy/core/dist-es/submodules/protocols/HttpBindingProtocol.js +9 -4
  68. package/node_modules/@smithy/core/dist-es/submodules/protocols/HttpProtocol.js +8 -6
  69. package/node_modules/@smithy/core/dist-es/submodules/schema/TypeRegistry.js +6 -1
  70. package/node_modules/@smithy/core/dist-es/submodules/serde/parse-utils.js +6 -3
  71. package/node_modules/@smithy/core/dist-es/util-identity-and-auth/DefaultIdentityProviderConfig.js +2 -1
  72. package/node_modules/@smithy/core/dist-types/submodules/schema/TypeRegistry.d.ts +1 -1
  73. package/node_modules/@smithy/core/package.json +2 -2
  74. package/node_modules/@smithy/middleware-endpoint/package.json +3 -3
  75. package/node_modules/@smithy/middleware-retry/package.json +5 -5
  76. package/node_modules/@smithy/middleware-serde/package.json +2 -2
  77. package/node_modules/@smithy/node-http-handler/dist-cjs/index.js +188 -93
  78. package/node_modules/@smithy/node-http-handler/dist-es/http2/ClientHttp2SessionRef.js +45 -0
  79. package/node_modules/@smithy/node-http-handler/dist-es/node-http2-connection-manager.js +71 -35
  80. package/node_modules/@smithy/node-http-handler/dist-es/node-http2-connection-pool.js +32 -18
  81. package/node_modules/@smithy/node-http-handler/dist-es/node-http2-handler.js +41 -40
  82. package/node_modules/@smithy/node-http-handler/dist-types/http2/ClientHttp2SessionRef.d.ts +42 -0
  83. package/node_modules/@smithy/node-http-handler/dist-types/node-http2-connection-manager.d.ts +34 -14
  84. package/node_modules/@smithy/node-http-handler/dist-types/node-http2-connection-pool.d.ts +32 -8
  85. package/node_modules/@smithy/node-http-handler/dist-types/node-http2-handler.d.ts +0 -5
  86. package/node_modules/@smithy/node-http-handler/package.json +1 -1
  87. package/node_modules/@smithy/service-error-classification/dist-cjs/index.js +5 -0
  88. package/node_modules/@smithy/service-error-classification/dist-es/index.js +4 -0
  89. package/node_modules/@smithy/service-error-classification/dist-types/index.d.ts +6 -0
  90. package/node_modules/@smithy/service-error-classification/package.json +1 -1
  91. package/node_modules/@smithy/smithy-client/package.json +4 -4
  92. package/node_modules/@smithy/util-defaults-mode-browser/package.json +2 -2
  93. package/node_modules/@smithy/util-defaults-mode-node/package.json +3 -3
  94. package/node_modules/@smithy/util-endpoints/dist-cjs/index.js +65 -53
  95. package/node_modules/@smithy/util-endpoints/dist-es/utils/evaluateCondition.js +9 -7
  96. package/node_modules/@smithy/util-endpoints/dist-es/utils/evaluateConditions.js +12 -8
  97. package/node_modules/@smithy/util-endpoints/dist-es/utils/evaluateEndpointRule.js +14 -13
  98. package/node_modules/@smithy/util-endpoints/dist-es/utils/evaluateErrorRule.js +7 -4
  99. package/node_modules/@smithy/util-endpoints/dist-es/utils/evaluateExpression.js +10 -8
  100. package/node_modules/@smithy/util-endpoints/dist-es/utils/evaluateRules.js +4 -4
  101. package/node_modules/@smithy/util-endpoints/dist-es/utils/getEndpointHeaders.js +5 -5
  102. package/node_modules/@smithy/util-endpoints/dist-es/utils/getEndpointProperties.js +4 -4
  103. package/node_modules/@smithy/util-endpoints/dist-types/types/shared.d.ts +3 -3
  104. package/node_modules/@smithy/util-endpoints/dist-types/utils/endpointFunctions.d.ts +2 -15
  105. package/node_modules/@smithy/util-endpoints/dist-types/utils/evaluateCondition.d.ts +6 -3
  106. package/node_modules/@smithy/util-endpoints/dist-types/utils/evaluateConditions.d.ts +3 -3
  107. package/node_modules/@smithy/util-endpoints/dist-types/utils/getEndpointHeaders.d.ts +1 -1
  108. package/node_modules/@smithy/util-endpoints/dist-types/utils/getEndpointProperties.d.ts +2 -2
  109. package/node_modules/@smithy/util-endpoints/dist-types/utils/getReferenceValue.d.ts +2 -2
  110. package/node_modules/@smithy/util-endpoints/package.json +1 -1
  111. package/node_modules/@smithy/util-retry/package.json +2 -2
  112. package/node_modules/@smithy/util-stream/package.json +2 -2
  113. package/node_modules/agent-trajectories/dist/{chunk-2XT3DOJC.js → chunk-27AQPWHK.js} +136 -72
  114. package/node_modules/agent-trajectories/dist/chunk-27AQPWHK.js.map +1 -0
  115. package/node_modules/agent-trajectories/dist/cli/index.js +135 -71
  116. package/node_modules/agent-trajectories/dist/cli/index.js.map +1 -1
  117. package/node_modules/agent-trajectories/dist/{index-thTh5iI8.d.ts → index-C7XhwsoN.d.ts} +24 -0
  118. package/node_modules/agent-trajectories/dist/index.d.ts +2 -2
  119. package/node_modules/agent-trajectories/dist/index.js +1 -1
  120. package/node_modules/agent-trajectories/dist/sdk/index.d.ts +1 -1
  121. package/node_modules/agent-trajectories/dist/sdk/index.js +1 -1
  122. package/node_modules/agent-trajectories/package.json +1 -1
  123. package/package.json +25 -11
  124. package/packages/cloud/package.json +2 -2
  125. package/packages/config/package.json +1 -1
  126. package/packages/hooks/package.json +4 -4
  127. package/packages/sdk/README.md +3 -0
  128. package/packages/sdk/dist/relay.d.ts +16 -0
  129. package/packages/sdk/dist/relay.d.ts.map +1 -1
  130. package/packages/sdk/dist/relay.js +83 -0
  131. package/packages/sdk/dist/relay.js.map +1 -1
  132. package/packages/sdk/package.json +2 -2
  133. package/packages/telemetry/package.json +1 -1
  134. package/packages/trajectory/package.json +2 -2
  135. package/packages/user-directory/package.json +2 -2
  136. package/packages/utils/package.json +2 -2
  137. package/dist/src/cli/commands/on/symlink-mount.d.ts +0 -12
  138. package/dist/src/cli/commands/on/symlink-mount.d.ts.map +0 -1
  139. package/dist/src/cli/commands/on/symlink-mount.js.map +0 -1
  140. package/node_modules/agent-trajectories/dist/chunk-2XT3DOJC.js.map +0 -1
Binary file
Binary file
Binary file
Binary file
package/dist/index.cjs CHANGED
@@ -16708,7 +16708,7 @@ function delay2(time3) {
16708
16708
  setTimeout(resolve4, time3);
16709
16709
  });
16710
16710
  }
16711
- var import_node_util3, import_util6, import_os, import_string_decoder, import_stream2, import_rfdc, import_crypto2, ANSI_ESCAPE2, ANSI_ESCAPE_CODES, ListrEnvironmentVariables, ListrErrorTypes, ListrEventType, ListrRendererSelection, ListrTaskEventType, ListrTaskState, EventManager, BaseEventMap, CLEAR_LINE_REGEX, BELL_REGEX, color, FIGURES_MAIN, FIGURES_FALLBACK, figures, ListrLogLevels, LISTR_LOGGER_STYLE, LISTR_LOGGER_STDERR_LEVELS, ListrLogger, ProcessOutputBuffer, ProcessOutputStream, ProcessOutput, ListrPromptAdapter, Spinner, ListrDefaultRendererLogLevels, LISTR_DEFAULT_RENDERER_STYLE, PRESET_TIMER, PRESET_TIMESTAMP, DefaultRenderer, SilentRenderer, SimpleRenderer, TestRendererSerializer, TestRenderer, VerboseRenderer, RENDERERS, clone2, Concurrency, ListrError, ListrRendererError, PromptError, TaskWrapper, ListrTaskEventManager, Task, ListrEventManager, Listr;
16711
+ var import_node_util3, import_util6, import_os, import_string_decoder, import_stream2, import_rfdc, import_crypto3, ANSI_ESCAPE2, ANSI_ESCAPE_CODES, ListrEnvironmentVariables, ListrErrorTypes, ListrEventType, ListrRendererSelection, ListrTaskEventType, ListrTaskState, EventManager, BaseEventMap, CLEAR_LINE_REGEX, BELL_REGEX, color, FIGURES_MAIN, FIGURES_FALLBACK, figures, ListrLogLevels, LISTR_LOGGER_STYLE, LISTR_LOGGER_STDERR_LEVELS, ListrLogger, ProcessOutputBuffer, ProcessOutputStream, ProcessOutput, ListrPromptAdapter, Spinner, ListrDefaultRendererLogLevels, LISTR_DEFAULT_RENDERER_STYLE, PRESET_TIMER, PRESET_TIMESTAMP, DefaultRenderer, SilentRenderer, SimpleRenderer, TestRendererSerializer, TestRenderer, VerboseRenderer, RENDERERS, clone2, Concurrency, ListrError, ListrRendererError, PromptError, TaskWrapper, ListrTaskEventManager, Task, ListrEventManager, Listr;
16712
16712
  var init_dist = __esm({
16713
16713
  "node_modules/listr2/dist/index.mjs"() {
16714
16714
  init_eventemitter3();
@@ -16718,7 +16718,7 @@ var init_dist = __esm({
16718
16718
  import_string_decoder = require("string_decoder");
16719
16719
  import_stream2 = require("stream");
16720
16720
  import_rfdc = __toESM(require_rfdc(), 1);
16721
- import_crypto2 = require("crypto");
16721
+ import_crypto3 = require("crypto");
16722
16722
  ANSI_ESCAPE2 = "\x1B[";
16723
16723
  ANSI_ESCAPE_CODES = {
16724
16724
  CURSOR_HIDE: ANSI_ESCAPE2 + "?25l",
@@ -18049,7 +18049,7 @@ var init_dist = __esm({
18049
18049
  };
18050
18050
  Task = class extends ListrTaskEventManager {
18051
18051
  /** Unique id per task, can be used for identifying a Task. */
18052
- id = (0, import_crypto2.randomUUID)();
18052
+ id = (0, import_crypto3.randomUUID)();
18053
18053
  /** The current state of the task. */
18054
18054
  state = ListrTaskState.WAITING;
18055
18055
  /** Subtasks of the current task. */
@@ -43582,6 +43582,7 @@ var AgentRelay = class {
43582
43582
  onDeliveryUpdate = null;
43583
43583
  onAgentExitRequested = null;
43584
43584
  onAgentIdle = null;
43585
+ onAgentActivityChanged = null;
43585
43586
  onChannelSubscribed = null;
43586
43587
  onChannelUnsubscribed = null;
43587
43588
  // ── Public accessors ────────────────────────────────────────────────────
@@ -43617,6 +43618,7 @@ var AgentRelay = class {
43617
43618
  exitedAgents = /* @__PURE__ */ new Set();
43618
43619
  idleAgents = /* @__PURE__ */ new Set();
43619
43620
  deliveryStates = /* @__PURE__ */ new Map();
43621
+ agentActivityStates = /* @__PURE__ */ new Map();
43620
43622
  outputListeners = /* @__PURE__ */ new Map();
43621
43623
  exitResolvers = /* @__PURE__ */ new Map();
43622
43624
  exitResolverSeq = 0;
@@ -44154,6 +44156,7 @@ var AgentRelay = class {
44154
44156
  this.exitedAgents.clear();
44155
44157
  this.idleAgents.clear();
44156
44158
  this.deliveryStates.clear();
44159
+ this.agentActivityStates.clear();
44157
44160
  this.outputListeners.clear();
44158
44161
  for (const entry of this.exitResolvers.values()) {
44159
44162
  entry.resolve("released");
@@ -44177,6 +44180,68 @@ var AgentRelay = class {
44177
44180
  updateDeliveryState(eventId, to2, status, updatedAt) {
44178
44181
  this.deliveryStates.set(eventId, { eventId, to: to2, status, updatedAt });
44179
44182
  }
44183
+ ensureAgentActivityState(name) {
44184
+ const existing = this.agentActivityStates.get(name);
44185
+ if (existing) {
44186
+ return existing;
44187
+ }
44188
+ const state = {
44189
+ active: false,
44190
+ pendingDeliveries: /* @__PURE__ */ new Map()
44191
+ };
44192
+ this.agentActivityStates.set(name, state);
44193
+ return state;
44194
+ }
44195
+ getDeliveryActivityKey(deliveryId, eventId) {
44196
+ return deliveryId || eventId;
44197
+ }
44198
+ markAgentDeliveryPending(name, deliveryId, eventId, reason) {
44199
+ const state = this.ensureAgentActivityState(name);
44200
+ state.pendingDeliveries.set(this.getDeliveryActivityKey(deliveryId, eventId), eventId);
44201
+ this.setAgentActivity(name, state, state.pendingDeliveries.size > 0, reason, eventId);
44202
+ }
44203
+ closeAgentDelivery(name, reason, eventId, deliveryId) {
44204
+ const state = this.agentActivityStates.get(name);
44205
+ if (!state)
44206
+ return;
44207
+ const key = deliveryId && eventId ? this.getDeliveryActivityKey(deliveryId, eventId) : void 0;
44208
+ if (key) {
44209
+ state.pendingDeliveries.delete(key);
44210
+ } else if (eventId) {
44211
+ const matchingEntry = Array.from(state.pendingDeliveries.entries()).find(([, pendingEventId]) => {
44212
+ return pendingEventId === eventId;
44213
+ });
44214
+ if (matchingEntry) {
44215
+ state.pendingDeliveries.delete(matchingEntry[0]);
44216
+ } else {
44217
+ const oldestKey = state.pendingDeliveries.keys().next().value;
44218
+ if (oldestKey) {
44219
+ state.pendingDeliveries.delete(oldestKey);
44220
+ }
44221
+ }
44222
+ }
44223
+ this.setAgentActivity(name, state, state.pendingDeliveries.size > 0, reason, eventId);
44224
+ }
44225
+ clearAgentDeliveries(name, reason, eventId) {
44226
+ const state = this.agentActivityStates.get(name);
44227
+ if (!state)
44228
+ return;
44229
+ state.pendingDeliveries.clear();
44230
+ this.setAgentActivity(name, state, false, reason, eventId);
44231
+ }
44232
+ setAgentActivity(name, state, active, reason, eventId) {
44233
+ if (state.active === active) {
44234
+ return;
44235
+ }
44236
+ state.active = active;
44237
+ this.onAgentActivityChanged?.({
44238
+ name,
44239
+ active,
44240
+ pendingDeliveries: state.pendingDeliveries.size,
44241
+ reason,
44242
+ eventId
44243
+ });
44244
+ }
44180
44245
  resolveEventTimestamp(candidate) {
44181
44246
  return typeof candidate === "number" ? candidate : Date.now();
44182
44247
  }
@@ -44321,10 +44386,12 @@ var AgentRelay = class {
44321
44386
  this.unsubEvent = client.onEvent((event) => {
44322
44387
  switch (event.kind) {
44323
44388
  case "relay_inbound": {
44389
+ this.closeAgentDelivery(event.from, "relay_inbound", event.event_id);
44324
44390
  if (this.knownAgents.has(event.from)) {
44325
44391
  this.messageReadyAgents.add(event.from);
44326
44392
  this.exitedAgents.delete(event.from);
44327
44393
  }
44394
+ this.clearAgentDeliveries(event.from, "relay_inbound", event.event_id);
44328
44395
  const msg = {
44329
44396
  eventId: event.event_id,
44330
44397
  from: event.from,
@@ -44347,6 +44414,7 @@ var AgentRelay = class {
44347
44414
  }
44348
44415
  case "agent_released": {
44349
44416
  const agent = this.knownAgents.get(event.name) ?? this.ensureAgentHandle(event.name, "pty", []);
44417
+ this.clearAgentDeliveries(event.name, "agent_released");
44350
44418
  this.exitedAgents.add(event.name);
44351
44419
  this.readyAgents.delete(event.name);
44352
44420
  this.messageReadyAgents.delete(event.name);
@@ -44362,6 +44430,7 @@ var AgentRelay = class {
44362
44430
  }
44363
44431
  case "agent_exited": {
44364
44432
  const agent = this.knownAgents.get(event.name) ?? this.ensureAgentHandle(event.name, "pty", []);
44433
+ this.clearAgentDeliveries(event.name, "agent_exited");
44365
44434
  this.exitedAgents.add(event.name);
44366
44435
  this.readyAgents.delete(event.name);
44367
44436
  this.messageReadyAgents.delete(event.name);
@@ -44402,14 +44471,17 @@ var AgentRelay = class {
44402
44471
  break;
44403
44472
  }
44404
44473
  case "delivery_queued": {
44474
+ this.markAgentDeliveryPending(event.name, event.delivery_id, event.event_id, "delivery_queued");
44405
44475
  this.updateDeliveryState(event.event_id, event.name, "queued", this.resolveEventTimestamp(event.timestamp));
44406
44476
  break;
44407
44477
  }
44408
44478
  case "delivery_injected": {
44479
+ this.markAgentDeliveryPending(event.name, event.delivery_id, event.event_id, "delivery_injected");
44409
44480
  this.updateDeliveryState(event.event_id, event.name, "injected", this.resolveEventTimestamp(event.timestamp));
44410
44481
  break;
44411
44482
  }
44412
44483
  case "delivery_active": {
44484
+ this.markAgentDeliveryPending(event.name, event.delivery_id, event.event_id, "delivery_active");
44413
44485
  this.updateDeliveryState(event.event_id, event.name, "active", this.resolveEventTimestamp());
44414
44486
  break;
44415
44487
  }
@@ -44417,7 +44489,11 @@ var AgentRelay = class {
44417
44489
  this.updateDeliveryState(event.event_id, event.name, "verified", this.resolveEventTimestamp());
44418
44490
  break;
44419
44491
  }
44492
+ case "delivery_ack": {
44493
+ break;
44494
+ }
44420
44495
  case "delivery_failed": {
44496
+ this.closeAgentDelivery(event.name, "delivery_failed", event.event_id, event.delivery_id);
44421
44497
  this.updateDeliveryState(event.event_id, event.name, "failed", this.resolveEventTimestamp());
44422
44498
  break;
44423
44499
  }
@@ -44432,6 +44508,7 @@ var AgentRelay = class {
44432
44508
  break;
44433
44509
  }
44434
44510
  case "agent_idle": {
44511
+ this.clearAgentDeliveries(event.name, "agent_idle");
44435
44512
  this.idleAgents.add(event.name);
44436
44513
  this.onAgentIdle?.({
44437
44514
  name: event.name,
@@ -44717,6 +44794,7 @@ var AgentRelay = class {
44717
44794
  this.messageReadyAgents.delete(name);
44718
44795
  this.exitedAgents.delete(name);
44719
44796
  this.idleAgents.delete(name);
44797
+ this.agentActivityStates.delete(name);
44720
44798
  }
44721
44799
  normalizeReleaseOptions(reasonOrOptions) {
44722
44800
  if (typeof reasonOrOptions === "string" || reasonOrOptions === void 0) {
@@ -53135,9 +53213,10 @@ function delay(ms2) {
53135
53213
  // packages/sdk/dist/workflows/trajectory.js
53136
53214
  var import_node_path27 = require("node:path");
53137
53215
 
53138
- // node_modules/agent-trajectories/dist/chunk-2XT3DOJC.js
53216
+ // node_modules/agent-trajectories/dist/chunk-27AQPWHK.js
53139
53217
  var import_module = require("module");
53140
53218
  var import_crypto = require("crypto");
53219
+ var import_crypto2 = require("crypto");
53141
53220
  var import_fs5 = require("fs");
53142
53221
  var import_promises7 = require("fs/promises");
53143
53222
  var import_path4 = require("path");
@@ -53689,6 +53768,16 @@ function expandPath(path24) {
53689
53768
  }
53690
53769
  return path24;
53691
53770
  }
53771
+ var indexLocks = /* @__PURE__ */ new Map();
53772
+ function withIndexLock(path24, task) {
53773
+ const prev = indexLocks.get(path24) ?? Promise.resolve();
53774
+ const next = prev.then(task, task);
53775
+ indexLocks.set(
53776
+ path24,
53777
+ next.catch(() => void 0)
53778
+ );
53779
+ return next;
53780
+ }
53692
53781
  var FileStorage = class {
53693
53782
  baseDir;
53694
53783
  trajectoriesDir;
@@ -53715,10 +53804,10 @@ var FileStorage = class {
53715
53804
  await (0, import_promises7.mkdir)(this.activeDir, { recursive: true });
53716
53805
  await (0, import_promises7.mkdir)(this.completedDir, { recursive: true });
53717
53806
  if (!(0, import_fs5.existsSync)(this.indexPath)) {
53718
- await this.saveIndex({
53719
- version: 1,
53720
- lastUpdated: (/* @__PURE__ */ new Date()).toISOString(),
53721
- trajectories: {}
53807
+ await withIndexLock(this.indexPath, async () => {
53808
+ if (!(0, import_fs5.existsSync)(this.indexPath)) {
53809
+ await this.saveIndex(this.emptyIndex());
53810
+ }
53722
53811
  });
53723
53812
  }
53724
53813
  await this.reconcileIndex();
@@ -53746,49 +53835,51 @@ var FileStorage = class {
53746
53835
  skippedSchemaViolation: 0,
53747
53836
  skippedIoError: 0
53748
53837
  };
53749
- const index = await this.loadIndex();
53750
- const before = Object.keys(index.trajectories).length;
53751
- const discovered = [];
53752
- try {
53753
- const activeFiles = await (0, import_promises7.readdir)(this.activeDir);
53754
- for (const file2 of activeFiles) {
53755
- if (!file2.endsWith(".json")) continue;
53756
- discovered.push((0, import_path4.join)(this.activeDir, file2));
53757
- }
53758
- } catch (error48) {
53759
- if (error48.code !== "ENOENT") throw error48;
53760
- }
53761
- await this.walkJsonFilesInto(this.completedDir, discovered);
53762
- for (const filePath of discovered) {
53763
- summary.scanned += 1;
53764
- const result = await this.readTrajectoryFile(filePath);
53765
- if (!result.ok) {
53766
- if (result.reason === "malformed_json") {
53767
- summary.skippedMalformedJson += 1;
53768
- } else if (result.reason === "schema_violation") {
53769
- summary.skippedSchemaViolation += 1;
53770
- } else {
53771
- summary.skippedIoError += 1;
53838
+ await withIndexLock(this.indexPath, async () => {
53839
+ const index = await this.loadIndex();
53840
+ const before = Object.keys(index.trajectories).length;
53841
+ const discovered = [];
53842
+ try {
53843
+ const activeFiles = await (0, import_promises7.readdir)(this.activeDir);
53844
+ for (const file2 of activeFiles) {
53845
+ if (!file2.endsWith(".json")) continue;
53846
+ discovered.push((0, import_path4.join)(this.activeDir, file2));
53772
53847
  }
53773
- continue;
53848
+ } catch (error48) {
53849
+ if (error48.code !== "ENOENT") throw error48;
53850
+ }
53851
+ await this.walkJsonFilesInto(this.completedDir, discovered);
53852
+ for (const filePath of discovered) {
53853
+ summary.scanned += 1;
53854
+ const result = await this.readTrajectoryFile(filePath);
53855
+ if (!result.ok) {
53856
+ if (result.reason === "malformed_json") {
53857
+ summary.skippedMalformedJson += 1;
53858
+ } else if (result.reason === "schema_violation") {
53859
+ summary.skippedSchemaViolation += 1;
53860
+ } else {
53861
+ summary.skippedIoError += 1;
53862
+ }
53863
+ continue;
53864
+ }
53865
+ const trajectory2 = result.trajectory;
53866
+ if (index.trajectories[trajectory2.id]) {
53867
+ summary.alreadyIndexed += 1;
53868
+ continue;
53869
+ }
53870
+ index.trajectories[trajectory2.id] = {
53871
+ title: trajectory2.task.title,
53872
+ status: trajectory2.status,
53873
+ startedAt: trajectory2.startedAt,
53874
+ completedAt: trajectory2.completedAt,
53875
+ path: filePath
53876
+ };
53877
+ summary.added += 1;
53774
53878
  }
53775
- const trajectory2 = result.trajectory;
53776
- if (index.trajectories[trajectory2.id]) {
53777
- summary.alreadyIndexed += 1;
53778
- continue;
53879
+ if (Object.keys(index.trajectories).length !== before) {
53880
+ await this.saveIndex(index);
53779
53881
  }
53780
- index.trajectories[trajectory2.id] = {
53781
- title: trajectory2.task.title,
53782
- status: trajectory2.status,
53783
- startedAt: trajectory2.startedAt,
53784
- completedAt: trajectory2.completedAt,
53785
- path: filePath
53786
- };
53787
- summary.added += 1;
53788
- }
53789
- if (Object.keys(index.trajectories).length !== before) {
53790
- await this.saveIndex(index);
53791
- }
53882
+ });
53792
53883
  const hadSkips = summary.skippedMalformedJson + summary.skippedSchemaViolation + summary.skippedIoError > 0;
53793
53884
  if (summary.added > 0 || hadSkips) {
53794
53885
  const parts = [`reconciled ${summary.added}/${summary.scanned}`];
@@ -53991,17 +54082,19 @@ var FileStorage = class {
53991
54082
  if ((0, import_fs5.existsSync)(activePath)) {
53992
54083
  await (0, import_promises7.unlink)(activePath);
53993
54084
  }
53994
- const index = await this.loadIndex();
53995
- const entry = index.trajectories[id];
53996
- if (entry?.path && (0, import_fs5.existsSync)(entry.path)) {
53997
- await (0, import_promises7.unlink)(entry.path);
53998
- const mdPath = entry.path.replace(".json", ".md");
53999
- if ((0, import_fs5.existsSync)(mdPath)) {
54000
- await (0, import_promises7.unlink)(mdPath);
54085
+ await withIndexLock(this.indexPath, async () => {
54086
+ const index = await this.loadIndex();
54087
+ const entry = index.trajectories[id];
54088
+ if (entry?.path && (0, import_fs5.existsSync)(entry.path)) {
54089
+ await (0, import_promises7.unlink)(entry.path);
54090
+ const mdPath = entry.path.replace(".json", ".md");
54091
+ if ((0, import_fs5.existsSync)(mdPath)) {
54092
+ await (0, import_promises7.unlink)(mdPath);
54093
+ }
54001
54094
  }
54002
- }
54003
- delete index.trajectories[id];
54004
- await this.saveIndex(index);
54095
+ delete index.trajectories[id];
54096
+ await this.saveIndex(index);
54097
+ });
54005
54098
  }
54006
54099
  /**
54007
54100
  * Search trajectories by text
@@ -54079,10 +54172,23 @@ var FileStorage = class {
54079
54172
  const result = await this.readTrajectoryFile(path24);
54080
54173
  return result.ok ? result.trajectory : null;
54081
54174
  }
54175
+ /**
54176
+ * Read and parse the on-disk index.
54177
+ *
54178
+ * Tolerances (belt-and-braces against the read/write race):
54179
+ * - ENOENT: first-run, return an empty index silently.
54180
+ * - Empty file: a concurrent writer truncated index.json in "w" mode
54181
+ * right before we read. Return an empty index silently — this is
54182
+ * not a real corruption, just an interleaving the mutex + atomic
54183
+ * rename should already prevent. Logging here would be noise.
54184
+ * - Non-empty but malformed JSON: genuinely corrupted on disk (hand
54185
+ * edit, disk error, etc). Log it and return an empty index so the
54186
+ * caller can recover, but keep the log so the problem is visible.
54187
+ */
54082
54188
  async loadIndex() {
54189
+ let content;
54083
54190
  try {
54084
- const content = await (0, import_promises7.readFile)(this.indexPath, "utf-8");
54085
- return JSON.parse(content);
54191
+ content = await (0, import_promises7.readFile)(this.indexPath, "utf-8");
54086
54192
  } catch (error48) {
54087
54193
  if (error48.code !== "ENOENT") {
54088
54194
  console.error(
@@ -54090,27 +54196,56 @@ var FileStorage = class {
54090
54196
  error48
54091
54197
  );
54092
54198
  }
54093
- return {
54094
- version: 1,
54095
- lastUpdated: (/* @__PURE__ */ new Date()).toISOString(),
54096
- trajectories: {}
54097
- };
54199
+ return this.emptyIndex();
54200
+ }
54201
+ if (content.length === 0) {
54202
+ return this.emptyIndex();
54203
+ }
54204
+ try {
54205
+ return JSON.parse(content);
54206
+ } catch (error48) {
54207
+ console.error(
54208
+ "Error loading trajectory index, using empty index:",
54209
+ error48
54210
+ );
54211
+ return this.emptyIndex();
54098
54212
  }
54099
54213
  }
54214
+ emptyIndex() {
54215
+ return {
54216
+ version: 1,
54217
+ lastUpdated: (/* @__PURE__ */ new Date()).toISOString(),
54218
+ trajectories: {}
54219
+ };
54220
+ }
54221
+ /**
54222
+ * Atomic write: stage into a process-unique temp path in the same directory
54223
+ * and then rename over the live file. `rename` is atomic on POSIX, so
54224
+ * concurrent readers in any process either see the old complete file or
54225
+ * the new complete file — never a half-written / zero-byte state.
54226
+ *
54227
+ * Callers MUST hold `withIndexLock(this.indexPath, ...)` so the in-process
54228
+ * read-modify-write cycle stays serialized; the unique temp name also keeps
54229
+ * parallel writers in other processes from colliding on a shared tmp path.
54230
+ */
54100
54231
  async saveIndex(index) {
54101
54232
  index.lastUpdated = (/* @__PURE__ */ new Date()).toISOString();
54102
- await (0, import_promises7.writeFile)(this.indexPath, JSON.stringify(index, null, 2), "utf-8");
54233
+ const tmpPath = `${this.indexPath}.${process.pid}.${(0, import_crypto2.randomUUID)()}.tmp`;
54234
+ await (0, import_promises7.writeFile)(tmpPath, JSON.stringify(index, null, 2), "utf-8");
54235
+ await (0, import_promises7.rename)(tmpPath, this.indexPath);
54103
54236
  }
54104
54237
  async updateIndex(trajectory2, filePath) {
54105
- const index = await this.loadIndex();
54106
- index.trajectories[trajectory2.id] = {
54107
- title: trajectory2.task.title,
54108
- status: trajectory2.status,
54109
- startedAt: trajectory2.startedAt,
54110
- completedAt: trajectory2.completedAt,
54111
- path: filePath
54112
- };
54113
- await this.saveIndex(index);
54238
+ await withIndexLock(this.indexPath, async () => {
54239
+ const index = await this.loadIndex();
54240
+ index.trajectories[trajectory2.id] = {
54241
+ title: trajectory2.task.title,
54242
+ status: trajectory2.status,
54243
+ startedAt: trajectory2.startedAt,
54244
+ completedAt: trajectory2.completedAt,
54245
+ path: filePath
54246
+ };
54247
+ await this.saveIndex(index);
54248
+ });
54114
54249
  }
54115
54250
  };
54116
54251
  var require22 = (0, import_module.createRequire)(import_meta_url);
@@ -1 +1 @@
1
- {"version":3,"file":"start.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/on/start.ts"],"names":[],"mappings":"AAyBA,UAAU,SAAS;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,UAAU,gBAAgB;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,UAAU,WAAW;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,gBAAgB,EAAE,CAAC;CAC5B;AAQD,KAAK,KAAK,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;AAc1C,UAAU,qBAAqB;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,UAAU,gBAAiB,SAAQ,qBAAqB;IACtD,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,KAAK,OAAO,GAAG,OAAO,KAAK,CAAC;AAE5B,UAAU,uB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