@moxt-ai/mobius 0.0.172 → 0.0.174

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 (66) hide show
  1. package/dist/agent-catalog/agent-specification.js +1 -1
  2. package/dist/cli.js +129 -863
  3. package/dist/cli.js.map +4 -4
  4. package/dist/daemon-command-handler.d.ts +1 -2
  5. package/dist/daemon-command-handler.d.ts.map +1 -1
  6. package/dist/daemon-command-handler.js +6 -26
  7. package/dist/daemon-command-handler.js.map +1 -1
  8. package/dist/daemon-history-commands.d.ts +1 -3
  9. package/dist/daemon-history-commands.d.ts.map +1 -1
  10. package/dist/daemon-history-commands.js +1 -48
  11. package/dist/daemon-history-commands.js.map +1 -1
  12. package/dist/daemon-turn-registry.d.ts +13 -13
  13. package/dist/generated/acp-session-store-migrations.d.ts +3 -0
  14. package/dist/generated/acp-session-store-migrations.d.ts.map +1 -1
  15. package/dist/generated/acp-session-store-migrations.js +5 -1
  16. package/dist/generated/acp-session-store-migrations.js.map +1 -1
  17. package/dist/index.js +114 -848
  18. package/dist/index.js.map +4 -4
  19. package/dist/native-sessions/service.d.ts.map +1 -1
  20. package/dist/native-sessions/service.js +0 -55
  21. package/dist/native-sessions/service.js.map +1 -1
  22. package/dist/relay-connection/run-relay-connection.d.ts +1 -2
  23. package/dist/relay-connection/run-relay-connection.d.ts.map +1 -1
  24. package/dist/relay-connection/run-relay-connection.js +1 -2
  25. package/dist/relay-connection/run-relay-connection.js.map +1 -1
  26. package/dist/run-daemon.d.ts +0 -1
  27. package/dist/run-daemon.d.ts.map +1 -1
  28. package/dist/run-daemon.js +0 -6
  29. package/dist/run-daemon.js.map +1 -1
  30. package/dist/runtime.d.ts +0 -1
  31. package/dist/runtime.d.ts.map +1 -1
  32. package/dist/runtime.js +108 -842
  33. package/dist/runtime.js.map +4 -4
  34. package/dist/schema/acp-session-store/index.d.ts +0 -1
  35. package/dist/schema/acp-session-store/index.d.ts.map +1 -1
  36. package/dist/schema/acp-session-store/index.js +0 -1
  37. package/dist/schema/acp-session-store/index.js.map +1 -1
  38. package/package.json +1 -1
  39. package/dist/agent-catalog/handle-agent-catalog-refresh.d.ts +0 -21
  40. package/dist/agent-catalog/handle-agent-catalog-refresh.d.ts.map +0 -1
  41. package/dist/agent-catalog/handle-agent-catalog-refresh.js +0 -119
  42. package/dist/agent-catalog/handle-agent-catalog-refresh.js.map +0 -1
  43. package/dist/native-sessions/acp-adapter.d.ts +0 -3
  44. package/dist/native-sessions/acp-adapter.d.ts.map +0 -1
  45. package/dist/native-sessions/acp-adapter.js +0 -6
  46. package/dist/native-sessions/acp-adapter.js.map +0 -1
  47. package/dist/native-sessions/acp-history.d.ts +0 -6
  48. package/dist/native-sessions/acp-history.d.ts.map +0 -1
  49. package/dist/native-sessions/acp-history.js +0 -27
  50. package/dist/native-sessions/acp-history.js.map +0 -1
  51. package/dist/native-sessions/agent-adapter.d.ts +0 -16
  52. package/dist/native-sessions/agent-adapter.d.ts.map +0 -1
  53. package/dist/native-sessions/agent-adapter.js +0 -19
  54. package/dist/native-sessions/agent-adapter.js.map +0 -1
  55. package/dist/native-sessions/codex-adapter.d.ts +0 -3
  56. package/dist/native-sessions/codex-adapter.d.ts.map +0 -1
  57. package/dist/native-sessions/codex-adapter.js +0 -20
  58. package/dist/native-sessions/codex-adapter.js.map +0 -1
  59. package/dist/native-sessions/live-history-page.d.ts +0 -4
  60. package/dist/native-sessions/live-history-page.d.ts.map +0 -1
  61. package/dist/native-sessions/live-history-page.js +0 -258
  62. package/dist/native-sessions/live-history-page.js.map +0 -1
  63. package/dist/schema/acp-session-store/session-event-v2.d.ts +0 -72
  64. package/dist/schema/acp-session-store/session-event-v2.d.ts.map +0 -1
  65. package/dist/schema/acp-session-store/session-event-v2.js +0 -11
  66. package/dist/schema/acp-session-store/session-event-v2.js.map +0 -1
package/dist/runtime.js CHANGED
@@ -3354,11 +3354,11 @@ var $ZodDate = /* @__PURE__ */ $constructor("$ZodDate", (inst, def) => {
3354
3354
  return payload;
3355
3355
  };
3356
3356
  });
3357
- function handleArrayResult(result, final, index2) {
3357
+ function handleArrayResult(result, final, index) {
3358
3358
  if (result.issues.length) {
3359
- final.issues.push(...prefixIssues(index2, result.issues));
3359
+ final.issues.push(...prefixIssues(index, result.issues));
3360
3360
  }
3361
- final.value[index2] = result.value;
3361
+ final.value[index] = result.value;
3362
3362
  }
3363
3363
  var $ZodArray = /* @__PURE__ */ $constructor("$ZodArray", (inst, def) => {
3364
3364
  $ZodType.init(inst, def);
@@ -3969,14 +3969,14 @@ function mergeValues(a, b) {
3969
3969
  return { valid: false, mergeErrorPath: [] };
3970
3970
  }
3971
3971
  const newArray = [];
3972
- for (let index2 = 0; index2 < a.length; index2++) {
3973
- const itemA = a[index2];
3974
- const itemB = b[index2];
3972
+ for (let index = 0; index < a.length; index++) {
3973
+ const itemA = a[index];
3974
+ const itemB = b[index];
3975
3975
  const sharedValue = mergeValues(itemA, itemB);
3976
3976
  if (!sharedValue.valid) {
3977
3977
  return {
3978
3978
  valid: false,
3979
- mergeErrorPath: [index2, ...sharedValue.mergeErrorPath]
3979
+ mergeErrorPath: [index, ...sharedValue.mergeErrorPath]
3980
3980
  };
3981
3981
  }
3982
3982
  newArray.push(sharedValue.data);
@@ -4127,11 +4127,11 @@ function getTupleOptStart(items, key) {
4127
4127
  }
4128
4128
  return 0;
4129
4129
  }
4130
- function handleTupleResult(result, final, index2) {
4130
+ function handleTupleResult(result, final, index) {
4131
4131
  if (result.issues.length) {
4132
- final.issues.push(...prefixIssues(index2, result.issues));
4132
+ final.issues.push(...prefixIssues(index, result.issues));
4133
4133
  }
4134
- final.value[index2] = result.value;
4134
+ final.value[index] = result.value;
4135
4135
  }
4136
4136
  function handleTupleResults(itemResults, final, items, input2, optoutStart) {
4137
4137
  for (let i = 0; i < items.length; i++) {
@@ -18812,7 +18812,7 @@ function detectVersion(schema, defaultTarget) {
18812
18812
  return defaultTarget ?? "draft-2020-12";
18813
18813
  }
18814
18814
  function applyMinItems(items, minItems) {
18815
- return items.map((item, index2) => index2 < minItems ? item : item.optional());
18815
+ return items.map((item, index) => index < minItems ? item : item.optional());
18816
18816
  }
18817
18817
  function decodeJSONPointerSegment(segment) {
18818
18818
  return segment.replace(/~1/g, "/").replace(/~0/g, "~");
@@ -19789,9 +19789,6 @@ var AGENT_INSTALL_CANCELLED_KIND = "agent.integration.install.cancelled";
19789
19789
  var AGENT_SETTINGS_DISCOVER_KIND = "agent.settings.discover";
19790
19790
  var AGENT_SETTINGS_DISCOVERED_KIND = "agent.settings.discovered";
19791
19791
  var AGENT_SETTINGS_DISCOVERY_FAILED_KIND = "agent.settings.discovery.failed";
19792
- var AGENT_CATALOG_REFRESH_KIND = "agent.catalog.refresh";
19793
- var AGENT_CATALOG_REFRESHED_KIND = "agent.catalog.refreshed";
19794
- var AGENT_CATALOG_REFRESH_FAILED_KIND = "agent.catalog.refresh.failed";
19795
19792
  var FILE_READ_KIND = "file.read";
19796
19793
  var FILE_BEGIN_KIND = "file.begin";
19797
19794
  var FILE_CHUNK_KIND = "file.chunk";
@@ -19953,20 +19950,6 @@ var agentSettingsDiscoveryFailedEventSchema = external_exports.object({
19953
19950
  message: external_exports.string().min(1).max(500),
19954
19951
  requestId: identifierStringSchema
19955
19952
  }).readonly();
19956
- var agentCatalogRefreshCommandSchema = external_exports.object({
19957
- kind: external_exports.literal(AGENT_CATALOG_REFRESH_KIND),
19958
- requestId: identifierStringSchema
19959
- }).readonly();
19960
- var agentCatalogRefreshedEventSchema = external_exports.object({
19961
- kind: external_exports.literal(AGENT_CATALOG_REFRESHED_KIND),
19962
- requestId: identifierStringSchema
19963
- }).readonly();
19964
- var agentCatalogRefreshFailedEventSchema = external_exports.object({
19965
- code: identifierStringSchema,
19966
- kind: external_exports.literal(AGENT_CATALOG_REFRESH_FAILED_KIND),
19967
- message: external_exports.string().min(1).max(500),
19968
- requestId: identifierStringSchema
19969
- }).readonly();
19970
19953
  var sessionConfigurationSelectionSchema = external_exports.object({
19971
19954
  booleanValue: external_exports.boolean(),
19972
19955
  configId: identifierStringSchema,
@@ -20014,12 +19997,12 @@ var DEFAULT_AGENT_EXECUTION_CONFIGURATION = Object.freeze({
20014
19997
  });
20015
19998
  var sessionConfigurationSelectionsSchema = external_exports.array(sessionConfigurationSelectionSchema).max(100).superRefine((selections, context) => {
20016
19999
  const identifiers = /* @__PURE__ */ new Set();
20017
- for (const [index2, selection] of selections.entries()) {
20000
+ for (const [index, selection] of selections.entries()) {
20018
20001
  if (identifiers.has(selection.configId)) {
20019
20002
  context.addIssue({
20020
20003
  code: "custom",
20021
20004
  message: "Session configuration identifiers must be unique",
20022
- path: [index2, "configId"]
20005
+ path: [index, "configId"]
20023
20006
  });
20024
20007
  }
20025
20008
  identifiers.add(selection.configId);
@@ -20371,12 +20354,6 @@ var decodeAgentSettingsDiscoveredEvent = (encoded) => decode3(encoded, agentSett
20371
20354
  var encodeAgentSettingsDiscoveredEvent = (message) => encode3(message, agentSettingsDiscoveredEventSchema);
20372
20355
  var decodeAgentSettingsDiscoveryFailedEvent = (encoded) => decode3(encoded, agentSettingsDiscoveryFailedEventSchema);
20373
20356
  var encodeAgentSettingsDiscoveryFailedEvent = (message) => encode3(message, agentSettingsDiscoveryFailedEventSchema);
20374
- var decodeAgentCatalogRefreshCommand = (encoded) => decode3(encoded, agentCatalogRefreshCommandSchema);
20375
- var encodeAgentCatalogRefreshCommand = (message) => encode3(message, agentCatalogRefreshCommandSchema);
20376
- var decodeAgentCatalogRefreshedEvent = (encoded) => decode3(encoded, agentCatalogRefreshedEventSchema);
20377
- var encodeAgentCatalogRefreshedEvent = (message) => encode3(message, agentCatalogRefreshedEventSchema);
20378
- var decodeAgentCatalogRefreshFailedEvent = (encoded) => decode3(encoded, agentCatalogRefreshFailedEventSchema);
20379
- var encodeAgentCatalogRefreshFailedEvent = (message) => encode3(message, agentCatalogRefreshFailedEventSchema);
20380
20357
  var decodeFileReadCommand = (encoded) => decode3(encoded, fileReadCommandSchema);
20381
20358
  var encodeFileReadCommand = (message) => encode3(message, fileReadCommandSchema);
20382
20359
  var decodeFileBeginEvent = (encoded) => decode3(encoded, fileBeginEventSchema);
@@ -20445,6 +20422,8 @@ var SESSION_CANCEL_KIND = "session.cancel";
20445
20422
  var RUNTIME_LIVENESS_READY_KIND = "runtime.liveness.ready";
20446
20423
  var RUNTIME_HEARTBEAT_KIND = "runtime.heartbeat";
20447
20424
  var RUNTIME_HEARTBEAT_ACK_KIND = "runtime.heartbeat.ack";
20425
+ var RUNTIME_PING_KIND = "runtime.ping";
20426
+ var RUNTIME_PONG_KIND = "runtime.pong";
20448
20427
  var SESSION_STARTED_KIND = "session.started";
20449
20428
  var SESSION_QUEUED_KIND = "session.queued";
20450
20429
  var AGENT_MESSAGE_DELTA_KIND = "agent.message.delta";
@@ -20757,6 +20736,16 @@ function decodeRuntimeHeartbeatAckEvent(encoded) {
20757
20736
  kind: RUNTIME_HEARTBEAT_ACK_KIND
20758
20737
  };
20759
20738
  }
20739
+ function decodeRuntimePingCommand(encoded) {
20740
+ const value = parseJson2(encoded);
20741
+ assertKind(value, RUNTIME_PING_KIND);
20742
+ return { kind: RUNTIME_PING_KIND, requestId: readIdentifier(value, "requestId") };
20743
+ }
20744
+ function decodeRuntimePongEvent(encoded) {
20745
+ const value = parseJson2(encoded);
20746
+ assertKind(value, RUNTIME_PONG_KIND);
20747
+ return { kind: RUNTIME_PONG_KIND, requestId: readIdentifier(value, "requestId") };
20748
+ }
20760
20749
  function decodeSessionStartedEvent(encoded) {
20761
20750
  const value = parseJson2(encoded);
20762
20751
  assertKind(value, SESSION_STARTED_KIND);
@@ -20854,6 +20843,12 @@ function encodeRuntimeHeartbeatEvent(message) {
20854
20843
  function encodeRuntimeHeartbeatAckEvent(message) {
20855
20844
  return JSON.stringify(decodeRuntimeHeartbeatAckEvent(JSON.stringify(message)));
20856
20845
  }
20846
+ function encodeRuntimePingCommand(message) {
20847
+ return JSON.stringify(decodeRuntimePingCommand(JSON.stringify(message)));
20848
+ }
20849
+ function encodeRuntimePongEvent(message) {
20850
+ return JSON.stringify(decodeRuntimePongEvent(JSON.stringify(message)));
20851
+ }
20857
20852
  function decodeAgentActivityNarrationEvent(encoded) {
20858
20853
  const value = parseJson2(encoded);
20859
20854
  assertKind(value, AGENT_ACTIVITY_NARRATION_KIND);
@@ -20967,10 +20962,6 @@ function withinHistoryContentLimits(history) {
20967
20962
  ) <= SESSION_HISTORY_IMAGE_CHARACTER_LIMIT;
20968
20963
  }
20969
20964
  var sessionHistorySchema = external_exports.discriminatedUnion("status", [availableSessionHistorySchema, unavailableSessionHistorySchema]).refine(withinHistoryContentLimits);
20970
- var nativeMessagePageSchema = external_exports.discriminatedUnion("status", [
20971
- availableSessionHistoryObjectSchema.extend({ nextCursor: external_exports.string().max(512).nullable() }).readonly(),
20972
- unavailableSessionHistoryObjectSchema.extend({ nextCursor: external_exports.null() }).readonly()
20973
- ]).refine(withinHistoryContentLimits);
20974
20965
 
20975
20966
  // ../protocol/src/native-sessions.ts
20976
20967
  var NATIVE_SESSION_REQUEST_KIND = "native.session.request";
@@ -21036,10 +21027,7 @@ var identity = {
21036
21027
  directoryId
21037
21028
  };
21038
21029
  var nativeSessionRequestSchema = external_exports.discriminatedUnion("action", [
21039
- external_exports.object({ ...identity, action: external_exports.literal("create") }).readonly(),
21040
21030
  external_exports.object({ ...identity, action: external_exports.literal("active-turn"), targetSessionId: identifierStringSchema }).readonly(),
21041
- external_exports.object({ ...identity, action: external_exports.literal("preview"), entryId: identifierStringSchema }).readonly(),
21042
- external_exports.object({ ...identity, action: external_exports.literal("history"), entryId: identifierStringSchema }).readonly(),
21043
21031
  external_exports.object({ ...identity, action: external_exports.literal("find"), nativeSessionId: identifierStringSchema }).readonly(),
21044
21032
  external_exports.object({
21045
21033
  ...identity,
@@ -21065,10 +21053,7 @@ var nativeSessionRequestSchema = external_exports.discriminatedUnion("action", [
21065
21053
  }).readonly()
21066
21054
  ]);
21067
21055
  var nativeSessionCommandSchema = external_exports.discriminatedUnion("action", [
21068
- external_exports.object({ ...identity, action: external_exports.literal("create") }).readonly(),
21069
21056
  external_exports.object({ ...identity, action: external_exports.literal("active-turn"), targetSessionId: identifierStringSchema }).readonly(),
21070
- external_exports.object({ ...identity, action: external_exports.literal("preview"), entryId: identifierStringSchema }).readonly(),
21071
- external_exports.object({ ...identity, action: external_exports.literal("history"), entryId: identifierStringSchema }).readonly(),
21072
21057
  external_exports.object({ ...identity, action: external_exports.literal("find"), nativeSessionId: identifierStringSchema }).readonly(),
21073
21058
  external_exports.object({
21074
21059
  ...identity,
@@ -21108,7 +21093,6 @@ var resultEnvelope = {
21108
21093
  kind: external_exports.literal(NATIVE_SESSION_RESULT_KIND)
21109
21094
  };
21110
21095
  var nativeSessionResultSchema = external_exports.discriminatedUnion("action", [
21111
- external_exports.object({ ...resultEnvelope, action: external_exports.literal("create"), nativeSessionId: identifierStringSchema }).readonly(),
21112
21096
  external_exports.object({
21113
21097
  ...resultEnvelope,
21114
21098
  action: external_exports.literal("active-turn"),
@@ -21141,22 +21125,6 @@ var nativeSessionResultSchema = external_exports.discriminatedUnion("action", [
21141
21125
  ready: sessionReadyEventSchema,
21142
21126
  title: external_exports.string().max(500)
21143
21127
  }).readonly(),
21144
- external_exports.object({
21145
- ...resultEnvelope,
21146
- action: external_exports.literal("preview"),
21147
- entryId: identifierStringSchema,
21148
- targetSessionId: identifierStringSchema,
21149
- reason: external_exports.enum(["continuation_unavailable", "requested"]),
21150
- history: sessionHistorySchema,
21151
- title: external_exports.string().max(500)
21152
- }).readonly(),
21153
- external_exports.object({
21154
- ...resultEnvelope,
21155
- action: external_exports.literal("history"),
21156
- entryId: identifierStringSchema,
21157
- history: sessionHistorySchema,
21158
- title: external_exports.string().max(500)
21159
- }).readonly(),
21160
21128
  external_exports.object({
21161
21129
  ...resultEnvelope,
21162
21130
  action: external_exports.literal("delete"),
@@ -21563,12 +21531,12 @@ var sessionExportV2Schema = external_exports.object({
21563
21531
  }).readonly().superRefine((session, context) => {
21564
21532
  let previousPosition = 0n;
21565
21533
  const eventIds = /* @__PURE__ */ new Set();
21566
- for (const [index2, event] of session.events.entries()) {
21534
+ for (const [index, event] of session.events.entries()) {
21567
21535
  if (event.sessionId !== session.sessionId) {
21568
21536
  context.addIssue({
21569
21537
  code: "custom",
21570
21538
  message: "Exported event belongs to a different Session",
21571
- path: ["events", index2, "sessionId"]
21539
+ path: ["events", index, "sessionId"]
21572
21540
  });
21573
21541
  }
21574
21542
  const position = BigInt(event.position);
@@ -21576,14 +21544,14 @@ var sessionExportV2Schema = external_exports.object({
21576
21544
  context.addIssue({
21577
21545
  code: "custom",
21578
21546
  message: "Exported events are not in increasing position order",
21579
- path: ["events", index2, "position"]
21547
+ path: ["events", index, "position"]
21580
21548
  });
21581
21549
  }
21582
21550
  if (eventIds.has(event.eventId)) {
21583
21551
  context.addIssue({
21584
21552
  code: "custom",
21585
21553
  message: "Exported event identities are not unique",
21586
- path: ["events", index2, "eventId"]
21554
+ path: ["events", index, "eventId"]
21587
21555
  });
21588
21556
  }
21589
21557
  previousPosition = position;
@@ -21727,28 +21695,9 @@ function decodeRecordedSessionEvent(encoded) {
21727
21695
  var encodeRecordedSessionEvent = (event) => JSON.stringify(decodeRecordedSessionEvent(JSON.stringify(event)));
21728
21696
 
21729
21697
  // ../protocol/src/session-live-history.ts
21730
- var SESSION_LIVE_HISTORY_PAGE_LOAD_KIND = "session.live-history.page.load";
21731
- var SESSION_LIVE_HISTORY_PAGE_LOADED_KIND = "session.live-history.page.loaded";
21732
21698
  var SESSION_LIVE_HISTORY_V2_PAGE_LOAD_KIND = "session.live-history.v2.page.load";
21733
21699
  var SESSION_LIVE_HISTORY_V2_PAGE_LOADED_KIND = "session.live-history.v2.page.loaded";
21734
21700
  var directoryIdentifier = external_exports.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,2047}$/);
21735
- var sessionLiveHistoryPageLoadSchema = external_exports.object({
21736
- additionalDirectoryIds: external_exports.array(directoryIdentifier).max(16).readonly(),
21737
- agentId: identifierStringSchema,
21738
- bindingId: identifierStringSchema,
21739
- cursor: external_exports.string().min(1).max(512).nullable(),
21740
- directoryId: directoryIdentifier,
21741
- kind: external_exports.literal(SESSION_LIVE_HISTORY_PAGE_LOAD_KIND),
21742
- limit: external_exports.number().int().min(1).max(100),
21743
- requestId: identifierStringSchema,
21744
- sessionId: identifierStringSchema
21745
- }).readonly();
21746
- var sessionLiveHistoryPageLoadedSchema = external_exports.object({
21747
- kind: external_exports.literal(SESSION_LIVE_HISTORY_PAGE_LOADED_KIND),
21748
- page: nativeMessagePageSchema,
21749
- requestId: identifierStringSchema,
21750
- sessionId: identifierStringSchema
21751
- }).readonly();
21752
21701
  var sessionLiveHistoryV2PageLoadSchema = external_exports.object({
21753
21702
  additionalDirectoryIds: external_exports.array(directoryIdentifier).max(16).readonly(),
21754
21703
  agentId: identifierStringSchema,
@@ -21774,10 +21723,6 @@ function decode7(schema, encoded) {
21774
21723
  throw new ProtocolMessageError("Invalid live Session history message", { cause });
21775
21724
  }
21776
21725
  }
21777
- var decodeSessionLiveHistoryPageLoad = (encoded) => decode7(sessionLiveHistoryPageLoadSchema, encoded);
21778
- var decodeSessionLiveHistoryPageLoaded = (encoded) => decode7(sessionLiveHistoryPageLoadedSchema, encoded);
21779
- var encodeSessionLiveHistoryPageLoad = (value) => JSON.stringify(sessionLiveHistoryPageLoadSchema.parse(value));
21780
- var encodeSessionLiveHistoryPageLoaded = (value) => JSON.stringify(sessionLiveHistoryPageLoadedSchema.parse(value));
21781
21726
  var decodeSessionLiveHistoryV2PageLoad = (encoded) => decode7(sessionLiveHistoryV2PageLoadSchema, encoded);
21782
21727
  var decodeSessionLiveHistoryV2PageLoaded = (encoded) => decode7(sessionLiveHistoryV2PageLoadedSchema, encoded);
21783
21728
  var encodeSessionLiveHistoryV2PageLoad = (value) => JSON.stringify(sessionLiveHistoryV2PageLoadSchema.parse(value));
@@ -21794,11 +21739,6 @@ function defineMessageSignature(kind, encoder, decoder) {
21794
21739
  };
21795
21740
  }
21796
21741
  var serviceToDaemonSignatures = {
21797
- [AGENT_CATALOG_REFRESH_KIND]: defineMessageSignature(
21798
- AGENT_CATALOG_REFRESH_KIND,
21799
- encodeAgentCatalogRefreshCommand,
21800
- decodeAgentCatalogRefreshCommand
21801
- ),
21802
21742
  [AGENT_INSTALL_CANCEL_KIND]: defineMessageSignature(
21803
21743
  AGENT_INSTALL_CANCEL_KIND,
21804
21744
  encodeAgentInstallCancelCommand,
@@ -21841,6 +21781,7 @@ var serviceToDaemonSignatures = {
21841
21781
  encodeRuntimeLivenessReadyEvent,
21842
21782
  decodeRuntimeLivenessReadyEvent
21843
21783
  ),
21784
+ [RUNTIME_PING_KIND]: defineMessageSignature(RUNTIME_PING_KIND, encodeRuntimePingCommand, decodeRuntimePingCommand),
21844
21785
  [SESSION_CANCEL_KIND]: defineMessageSignature(
21845
21786
  SESSION_CANCEL_KIND,
21846
21787
  encodeSessionCancelCommand,
@@ -21856,11 +21797,6 @@ var serviceToDaemonSignatures = {
21856
21797
  encodeSessionElicitationRespondCommand,
21857
21798
  decodeSessionElicitationRespondCommand
21858
21799
  ),
21859
- [SESSION_LIVE_HISTORY_PAGE_LOAD_KIND]: defineMessageSignature(
21860
- SESSION_LIVE_HISTORY_PAGE_LOAD_KIND,
21861
- encodeSessionLiveHistoryPageLoad,
21862
- decodeSessionLiveHistoryPageLoad
21863
- ),
21864
21800
  [SESSION_LIVE_HISTORY_V2_PAGE_LOAD_KIND]: defineMessageSignature(
21865
21801
  SESSION_LIVE_HISTORY_V2_PAGE_LOAD_KIND,
21866
21802
  encodeSessionLiveHistoryV2PageLoad,
@@ -21902,16 +21838,6 @@ function decodeServiceToDaemonMessage(encoded) {
21902
21838
  return signature.decoder(encoded);
21903
21839
  }
21904
21840
  var daemonToServiceSignatures = {
21905
- [AGENT_CATALOG_REFRESHED_KIND]: defineMessageSignature(
21906
- AGENT_CATALOG_REFRESHED_KIND,
21907
- encodeAgentCatalogRefreshedEvent,
21908
- decodeAgentCatalogRefreshedEvent
21909
- ),
21910
- [AGENT_CATALOG_REFRESH_FAILED_KIND]: defineMessageSignature(
21911
- AGENT_CATALOG_REFRESH_FAILED_KIND,
21912
- encodeAgentCatalogRefreshFailedEvent,
21913
- decodeAgentCatalogRefreshFailedEvent
21914
- ),
21915
21841
  [AGENT_INSTALL_CANCELLED_KIND]: defineMessageSignature(
21916
21842
  AGENT_INSTALL_CANCELLED_KIND,
21917
21843
  encodeAgentInstallCancelledEvent,
@@ -21981,6 +21907,7 @@ var daemonToServiceSignatures = {
21981
21907
  encodeRuntimeHeartbeatEvent,
21982
21908
  decodeRuntimeHeartbeatEvent
21983
21909
  ),
21910
+ [RUNTIME_PONG_KIND]: defineMessageSignature(RUNTIME_PONG_KIND, encodeRuntimePongEvent, decodeRuntimePongEvent),
21984
21911
  [SESSION_EVENT_KIND]: defineMessageSignature(
21985
21912
  SESSION_EVENT_KIND,
21986
21913
  encodeSessionEventEnvelope,
@@ -21996,11 +21923,6 @@ var daemonToServiceSignatures = {
21996
21923
  encodeSessionOperationFailedEvent,
21997
21924
  decodeSessionOperationFailedEvent
21998
21925
  ),
21999
- [SESSION_LIVE_HISTORY_PAGE_LOADED_KIND]: defineMessageSignature(
22000
- SESSION_LIVE_HISTORY_PAGE_LOADED_KIND,
22001
- encodeSessionLiveHistoryPageLoaded,
22002
- decodeSessionLiveHistoryPageLoaded
22003
- ),
22004
21926
  [SESSION_LIVE_HISTORY_V2_PAGE_LOADED_KIND]: defineMessageSignature(
22005
21927
  SESSION_LIVE_HISTORY_V2_PAGE_LOADED_KIND,
22006
21928
  encodeSessionLiveHistoryV2PageLoaded,
@@ -26671,9 +26593,9 @@ function comparePrerelease(left, right) {
26671
26593
  if (left.length === 0 || right.length === 0) {
26672
26594
  return left.length === right.length ? 0 : left.length === 0 ? 1 : -1;
26673
26595
  }
26674
- for (let index2 = 0; index2 < Math.max(left.length, right.length); index2 += 1) {
26675
- const leftPart = left[index2];
26676
- const rightPart = right[index2];
26596
+ for (let index = 0; index < Math.max(left.length, right.length); index += 1) {
26597
+ const leftPart = left[index];
26598
+ const rightPart = right[index];
26677
26599
  if (leftPart === void 0 || rightPart === void 0) {
26678
26600
  return leftPart === rightPart ? 0 : leftPart === void 0 ? -1 : 1;
26679
26601
  }
@@ -26698,8 +26620,8 @@ function compareAgentVersions(left, right) {
26698
26620
  if (parsedLeft === null || parsedRight === null) {
26699
26621
  return null;
26700
26622
  }
26701
- for (let index2 = 0; index2 < Math.max(parsedLeft.core.length, parsedRight.core.length); index2 += 1) {
26702
- const difference = (parsedLeft.core[index2] ?? 0) - (parsedRight.core[index2] ?? 0);
26623
+ for (let index = 0; index < Math.max(parsedLeft.core.length, parsedRight.core.length); index += 1) {
26624
+ const difference = (parsedLeft.core[index] ?? 0) - (parsedRight.core[index] ?? 0);
26703
26625
  if (difference !== 0) {
26704
26626
  return Math.sign(difference);
26705
26627
  }
@@ -27309,7 +27231,7 @@ function startsWith(bytes, signature, offset = 0) {
27309
27231
  if (bytes.byteLength < offset + signature.byteLength) {
27310
27232
  return false;
27311
27233
  }
27312
- return signature.every((value, index2) => bytes[offset + index2] === value);
27234
+ return signature.every((value, index) => bytes[offset + index] === value);
27313
27235
  }
27314
27236
  function sniffRasterMime(bytes) {
27315
27237
  if (startsWith(bytes, PNG_SIGNATURE)) {
@@ -27437,7 +27359,7 @@ function startsWith2(bytes, signature, offset = 0) {
27437
27359
  if (bytes.byteLength < offset + signature.byteLength) {
27438
27360
  return false;
27439
27361
  }
27440
- return signature.every((value, index2) => bytes[offset + index2] === value);
27362
+ return signature.every((value, index) => bytes[offset + index] === value);
27441
27363
  }
27442
27364
  function sniffVideoMime(bytes) {
27443
27365
  if (startsWith2(bytes, MP4_FILE_TYPE, 4)) {
@@ -27566,10 +27488,10 @@ async function replaceImageMarkers(text2, replace) {
27566
27488
  let cursor = 0;
27567
27489
  let rewritten = "";
27568
27490
  for (const match of matches) {
27569
- const index2 = match.index ?? 0;
27570
- rewritten += text2.slice(cursor, index2);
27491
+ const index = match.index ?? 0;
27492
+ rewritten += text2.slice(cursor, index);
27571
27493
  rewritten += await replace(match[1] ?? "");
27572
- cursor = index2 + match[0].length;
27494
+ cursor = index + match[0].length;
27573
27495
  }
27574
27496
  return `${rewritten}${text2.slice(cursor)}`;
27575
27497
  }
@@ -30694,7 +30616,7 @@ function haveSameKeys(left, right) {
30694
30616
  const leftKeys = Object.keys(left);
30695
30617
  const rightKeys = Object.keys(right);
30696
30618
  if (leftKeys.length !== rightKeys.length) return false;
30697
- for (const [index2, key] of leftKeys.entries()) if (key !== rightKeys[index2]) return false;
30619
+ for (const [index, key] of leftKeys.entries()) if (key !== rightKeys[index]) return false;
30698
30620
  return true;
30699
30621
  }
30700
30622
  function mapUpdateSet(table, values) {
@@ -32200,60 +32122,6 @@ function sqliteTableWithCasing(casing) {
32200
32122
  }
32201
32123
  var sqliteTable = sqliteTableWithCasing(void 0);
32202
32124
 
32203
- // ../../node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_@cloudflare+workers-types@5.20260918.1_@types+better-sqlite3@7.6_f872c171b7e1945bb1fa42180063dab2/node_modules/drizzle-orm/sqlite-core/indexes.js
32204
- var IndexBuilderOn = class {
32205
- static [entityKind] = "SQLiteIndexBuilderOn";
32206
- constructor(name2, unique) {
32207
- this.name = name2;
32208
- this.unique = unique;
32209
- }
32210
- on(...columns) {
32211
- return new IndexBuilder(this.name, columns, this.unique);
32212
- }
32213
- };
32214
- var IndexBuilder = class {
32215
- static [entityKind] = "SQLiteIndexBuilder";
32216
- /** @internal */
32217
- config;
32218
- constructor(name2, columns, unique) {
32219
- this.config = {
32220
- name: name2,
32221
- columns,
32222
- unique,
32223
- where: void 0
32224
- };
32225
- }
32226
- /**
32227
- * Condition for partial index.
32228
- */
32229
- where(condition) {
32230
- this.config.where = condition;
32231
- return this;
32232
- }
32233
- /** @internal */
32234
- build(table) {
32235
- return new Index(this.config, table);
32236
- }
32237
- };
32238
- var Index = class {
32239
- static [entityKind] = "SQLiteIndex";
32240
- config;
32241
- isNameExplicit;
32242
- constructor(config2, table) {
32243
- this.config = {
32244
- ...config2,
32245
- table
32246
- };
32247
- this.isNameExplicit = !!config2.name;
32248
- }
32249
- };
32250
- function index(name2) {
32251
- return new IndexBuilderOn(name2, false);
32252
- }
32253
- function uniqueIndex(name2) {
32254
- return new IndexBuilderOn(name2, true);
32255
- }
32256
-
32257
32125
  // ../../node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_@cloudflare+workers-types@5.20260918.1_@types+better-sqlite3@7.6_f872c171b7e1945bb1fa42180063dab2/node_modules/drizzle-orm/sqlite-core/utils.js
32258
32126
  function extractUsedTable(table) {
32259
32127
  if (is(table, SQLiteTable)) return [`${table[Table.Symbol.BaseName]}`];
@@ -33078,8 +32946,8 @@ var SQLiteDialect = class {
33078
32946
  buildJoins(joins) {
33079
32947
  if (!joins || joins.length === 0) return;
33080
32948
  const joinsArray = [];
33081
- if (joins) for (const [index2, joinMeta] of joins.entries()) {
33082
- if (index2 === 0) joinsArray.push(sql` `);
32949
+ if (joins) for (const [index, joinMeta] of joins.entries()) {
32950
+ if (index === 0) joinsArray.push(sql` `);
33083
32951
  const table = joinMeta.table;
33084
32952
  const onSql = joinMeta.on ? sql` on ${joinMeta.on}` : void 0;
33085
32953
  if (is(table, SQLiteTable)) {
@@ -33089,7 +32957,7 @@ var SQLiteDialect = class {
33089
32957
  const alias = tableName === origTableName ? void 0 : joinMeta.alias;
33090
32958
  joinsArray.push(sql`${sql.raw(joinMeta.joinType)} join ${tableSchema ? sql`${sql.identifier(tableSchema)}.` : void 0}${sql.identifier(origTableName)}${alias && sql` ${sql.identifier(alias)}`}${onSql}`);
33091
32959
  } else joinsArray.push(sql`${sql.raw(joinMeta.joinType)} join ${table}${onSql}`);
33092
- if (index2 < joins.length - 1) joinsArray.push(sql` `);
32960
+ if (index < joins.length - 1) joinsArray.push(sql` `);
33093
32961
  }
33094
32962
  return sql.join(joinsArray);
33095
32963
  }
@@ -33098,9 +32966,9 @@ var SQLiteDialect = class {
33098
32966
  }
33099
32967
  buildOrderBy(orderBy) {
33100
32968
  const orderByList = [];
33101
- if (orderBy) for (const [index2, orderByValue] of orderBy.entries()) {
32969
+ if (orderBy) for (const [index, orderByValue] of orderBy.entries()) {
33102
32970
  orderByList.push(orderByValue);
33103
- if (index2 < orderBy.length - 1) orderByList.push(sql`, `);
32971
+ if (index < orderBy.length - 1) orderByList.push(sql`, `);
33104
32972
  }
33105
32973
  return orderByList.length > 0 ? sql` order by ${sql.join(orderByList)}` : void 0;
33106
32974
  }
@@ -33128,9 +32996,9 @@ var SQLiteDialect = class {
33128
32996
  const whereSql = where ? sql` where ${where}` : void 0;
33129
32997
  const havingSql = having ? sql` having ${having}` : void 0;
33130
32998
  const groupByList = [];
33131
- if (groupBy) for (const [index2, groupByValue] of groupBy.entries()) {
32999
+ if (groupBy) for (const [index, groupByValue] of groupBy.entries()) {
33132
33000
  groupByList.push(groupByValue);
33133
- if (index2 < groupBy.length - 1) groupByList.push(sql`, `);
33001
+ if (index < groupBy.length - 1) groupByList.push(sql`, `);
33134
33002
  }
33135
33003
  const finalQuery = sql`${withSql}select${distinctSql} ${selection} from ${tableSql}${joinsSql}${whereSql}${groupByList.length > 0 ? sql` group by ${sql.join(groupByList)}` : void 0}${havingSql}${this.buildOrderBy(orderBy)}${this.buildLimit(limit)}${offset ? sql` offset ${offset}` : void 0}`;
33136
33004
  if (setOperators.length > 0) return this.buildSetOperations(finalQuery, setOperators);
@@ -34422,6 +34290,10 @@ var acpSessionStoreMigrations = [
34422
34290
  {
34423
34291
  "name": "0002_equal_black_queen.sql",
34424
34292
  "sql": "CREATE TABLE `session_event_v2` (\n `event_id` text PRIMARY KEY NOT NULL,\n `event_json` text NOT NULL,\n `position` integer NOT NULL,\n `session_id` text NOT NULL\n);\n--> statement-breakpoint\nCREATE UNIQUE INDEX `session_event_v2_session_position_unique` ON `session_event_v2` (`session_id`,`position`);--> statement-breakpoint\nCREATE INDEX `session_event_v2_session_position_index` ON `session_event_v2` (`session_id`,`position`);"
34293
+ },
34294
+ {
34295
+ "name": "0003_silky_ravenous.sql",
34296
+ "sql": "DROP TABLE `session_event_v2`;"
34425
34297
  }
34426
34298
  ];
34427
34299
 
@@ -34443,21 +34315,6 @@ var deletedAcpSession = sqliteTable("deleted_acp_session", {
34443
34315
  sessionId: text("session_id").primaryKey()
34444
34316
  });
34445
34317
 
34446
- // src/schema/acp-session-store/session-event-v2.ts
34447
- var sessionEventV2 = sqliteTable(
34448
- "session_event_v2",
34449
- {
34450
- eventId: text("event_id").primaryKey(),
34451
- eventJson: text("event_json").notNull(),
34452
- position: integer2("position").notNull(),
34453
- sessionId: text("session_id").notNull()
34454
- },
34455
- (table) => [
34456
- uniqueIndex("session_event_v2_session_position_unique").on(table.sessionId, table.position),
34457
- index("session_event_v2_session_position_index").on(table.sessionId, table.position)
34458
- ]
34459
- );
34460
-
34461
34318
  // src/acp/session-store.ts
34462
34319
  var AcpStoredSession = class {
34463
34320
  additionalDirectories;
@@ -34574,15 +34431,15 @@ var SqliteAcpSessionStore = class {
34574
34431
  this.#sqliteDatabase.close();
34575
34432
  throw new Error("The ACP Session database was created by a newer Mobius version");
34576
34433
  }
34577
- for (let index2 = version2; index2 < acpSessionStoreMigrations.length; index2 += 1) {
34578
- const migration = acpSessionStoreMigrations[index2];
34434
+ for (let index = version2; index < acpSessionStoreMigrations.length; index += 1) {
34435
+ const migration = acpSessionStoreMigrations[index];
34579
34436
  if (migration === void 0) {
34580
34437
  throw new Error("The ACP Session migration is unavailable");
34581
34438
  }
34582
34439
  this.#sqliteDatabase.exec("BEGIN IMMEDIATE");
34583
34440
  try {
34584
34441
  this.#sqliteDatabase.exec(migration.sql);
34585
- this.#sqliteDatabase.exec(`PRAGMA user_version = ${index2 + 1}`);
34442
+ this.#sqliteDatabase.exec(`PRAGMA user_version = ${index + 1}`);
34586
34443
  this.#sqliteDatabase.exec("COMMIT");
34587
34444
  } catch (error62) {
34588
34445
  this.#sqliteDatabase.exec("ROLLBACK");
@@ -34658,7 +34515,7 @@ var RetryableAcpInitializationError = class extends AcpExecutionError {
34658
34515
  }
34659
34516
  };
34660
34517
  function arraysEqual(left, right) {
34661
- return left.length === right.length && left.every((value, index2) => value === right[index2]);
34518
+ return left.length === right.length && left.every((value, index) => value === right[index]);
34662
34519
  }
34663
34520
  function recordsEqual(left, right) {
34664
34521
  const leftEntries = Object.entries(left);
@@ -36394,9 +36251,6 @@ var LocalExternalContentStore = class {
36394
36251
  };
36395
36252
 
36396
36253
  // src/native-sessions/chat-agent.ts
36397
- function supportsNativeChat(agentId) {
36398
- return agentId === "codex" || agentId === "claude" || agentId === "opencode" || agentId === "pi";
36399
- }
36400
36254
  function isNativeChatSessionId(agentId, sessionId) {
36401
36255
  if (!nativeSessionIdSchema.safeParse(sessionId).success) {
36402
36256
  return false;
@@ -36455,9 +36309,9 @@ var AcpProcessCapacityLock = class {
36455
36309
  return await waiter.completion.promise;
36456
36310
  } finally {
36457
36311
  signal.removeEventListener("abort", waiter.cancel);
36458
- const index2 = this.#waiters.indexOf(waiter);
36459
- if (index2 >= 0) {
36460
- this.#waiters.splice(index2, 1);
36312
+ const index = this.#waiters.indexOf(waiter);
36313
+ if (index >= 0) {
36314
+ this.#waiters.splice(index, 1);
36461
36315
  }
36462
36316
  }
36463
36317
  };
@@ -38511,8 +38365,8 @@ var ACTIVE_TURN_TEXT_CHUNK_LIMIT = Math.floor(SESSION_HISTORY_CHARACTER_LIMIT /
38511
38365
  function boundedRecoveryMessages(messages) {
38512
38366
  const selected = [];
38513
38367
  let remainingCharacters = SESSION_HISTORY_CHARACTER_LIMIT;
38514
- for (let index2 = messages.length - 1; index2 >= 0 && selected.length < SESSION_HISTORY_MESSAGE_LIMIT; index2 -= 1) {
38515
- const message = messages[index2];
38368
+ for (let index = messages.length - 1; index >= 0 && selected.length < SESSION_HISTORY_MESSAGE_LIMIT; index -= 1) {
38369
+ const message = messages[index];
38516
38370
  if (message === void 0) {
38517
38371
  break;
38518
38372
  }
@@ -38653,7 +38507,7 @@ var ActiveDaemonTurn = class {
38653
38507
  ];
38654
38508
  } else {
38655
38509
  this.#timeline = this.#timeline.map(
38656
- (entry, index2) => index2 === target && entry.kind === "message" ? { ...entry, content: new Map([...entry.content, [event.contentId, event.content]]) } : entry
38510
+ (entry, index) => index === target && entry.kind === "message" ? { ...entry, content: new Map([...entry.content, [event.contentId, event.content]]) } : entry
38657
38511
  );
38658
38512
  }
38659
38513
  } else if (event.kind === SESSION_PERMISSION_REQUESTED_KIND || event.kind === SESSION_ELICITATION_REQUESTED_KIND) {
@@ -39654,7 +39508,6 @@ async function readCodexHistoryWithOptions(agent, cwd, nativeSessionId, signal,
39654
39508
  child2.removeListener("exit", onExit);
39655
39509
  }
39656
39510
  }
39657
- var readCodexHistory = async (agent, cwd, nativeSessionId, signal) => await readCodexHistoryWithOptions(agent, cwd, nativeSessionId, signal, { detail: "messages" });
39658
39511
  var readCodexFullHistory = async (agent, cwd, nativeSessionId, signal, nativeTurn) => await readCodexHistoryWithOptions(agent, cwd, nativeSessionId, signal, {
39659
39512
  detail: "rich",
39660
39513
  ...nativeTurn === void 0 ? {} : { nativeTurn }
@@ -39663,84 +39516,6 @@ var readCodexFullHistory = async (agent, cwd, nativeSessionId, signal, nativeTur
39663
39516
  // src/native-sessions/service.ts
39664
39517
  import { randomUUID as randomUUID3 } from "node:crypto";
39665
39518
  import { basename as basename4 } from "node:path";
39666
-
39667
- // src/native-sessions/acp-history.ts
39668
- async function readAcpHistory(sessions, directories, bindingId, options, nativeSessionId) {
39669
- let cursor = null;
39670
- let inspected = 0;
39671
- for (let pageNumber = 0; pageNumber < 500 && inspected < 500; pageNumber += 1) {
39672
- const page = await sessions.listNativeSessions(options, cursor);
39673
- inspected += page.sessions.length;
39674
- const found = page.sessions.find((entry) => entry.sessionId === nativeSessionId);
39675
- if (found !== void 0) {
39676
- const primary = await directories.identify(bindingId, found.cwd, options.signal);
39677
- const additional = await Promise.all(
39678
- found.additionalDirectories.map(
39679
- async (directory) => await directories.identify(bindingId, directory, options.signal)
39680
- )
39681
- );
39682
- if (primary.path !== options.cwd || additional.length !== options.additionalDirectories.length || additional.some((directory, index2) => directory.path !== options.additionalDirectories[index2])) {
39683
- throw new AcpExecutionError(
39684
- "The native Session belongs to another workspace.",
39685
- {},
39686
- "session_identity_mismatch"
39687
- );
39688
- }
39689
- return await sessions.previewNativeSession(options, nativeSessionId);
39690
- }
39691
- if (page.nextCursor === null || page.nextCursor === cursor) {
39692
- break;
39693
- }
39694
- cursor = page.nextCursor ?? null;
39695
- }
39696
- throw new AcpExecutionError("The native Session was not found.", {}, "native_session_not_found");
39697
- }
39698
-
39699
- // src/native-sessions/acp-adapter.ts
39700
- var acpSessionAdapter = {
39701
- history: async ({ sessions, directories, bindingId, options, nativeSessionId }) => await readAcpHistory(sessions, directories, bindingId, options, nativeSessionId),
39702
- preview: async ({ sessions, options, nativeSessionId }) => await sessions.previewNativeSession(options, nativeSessionId)
39703
- };
39704
-
39705
- // src/native-sessions/codex-adapter.ts
39706
- async function verifiedHistory(context, full) {
39707
- const { options, nativeSessionId, directories, bindingId } = context;
39708
- const snapshot = full ? await readCodexFullHistory(options.agent, options.cwd, nativeSessionId, options.signal) : await readCodexHistory(options.agent, options.cwd, nativeSessionId, options.signal);
39709
- const resolved = await directories.identify(bindingId, snapshot.cwd, options.signal);
39710
- if (snapshot.nativeSessionId !== nativeSessionId || resolved.path !== options.cwd) {
39711
- throw new AcpExecutionError(
39712
- "Codex returned history for a different session or workspace.",
39713
- {},
39714
- "invalid_native_session_response"
39715
- );
39716
- }
39717
- return snapshot.history;
39718
- }
39719
- var codexSessionAdapter = {
39720
- history: async (context) => await verifiedHistory(context, true),
39721
- // Codex enforces an exclusive writer per thread. Its read-only app-server
39722
- // history path keeps externally owned conversations previewable.
39723
- preview: async (context) => await verifiedHistory(context, false)
39724
- };
39725
-
39726
- // src/native-sessions/agent-adapter.ts
39727
- var genericSessionAdapter = {
39728
- history: async () => {
39729
- throw new AcpExecutionError("Native history is unavailable for this Agent", {}, "native_session_unsupported");
39730
- },
39731
- preview: async ({ sessions, options, nativeSessionId }) => await sessions.previewNativeSession(options, nativeSessionId)
39732
- };
39733
- function nativeSessionAdapter(agentId) {
39734
- if (agentId === "codex") {
39735
- return codexSessionAdapter;
39736
- }
39737
- if (agentId === "claude" || agentId === "opencode" || agentId === "pi") {
39738
- return acpSessionAdapter;
39739
- }
39740
- return genericSessionAdapter;
39741
- }
39742
-
39743
- // src/native-sessions/service.ts
39744
39519
  var NativeSessionService = class {
39745
39520
  #entries = /* @__PURE__ */ new Map();
39746
39521
  #cursors = /* @__PURE__ */ new Map();
@@ -39784,25 +39559,6 @@ var NativeSessionService = class {
39784
39559
  ...await this.#activeTurn(command, options)
39785
39560
  };
39786
39561
  }
39787
- if (command.action === "create") {
39788
- if (!supportsNativeChat(options.agent.id)) {
39789
- throw new AcpExecutionError(
39790
- "Native session creation is unavailable for this Agent",
39791
- {},
39792
- "native_session_unsupported"
39793
- );
39794
- }
39795
- const nativeSessionId = await this.#sessions.createNativeSession(options);
39796
- signal.throwIfAborted();
39797
- this.record(command, "native_session_created");
39798
- return {
39799
- action: "create",
39800
- kind: "native.session.result",
39801
- nativeSessionId: decodeIdentifier(nativeSessionId),
39802
- requestId: command.requestId,
39803
- sessionId: command.sessionId
39804
- };
39805
- }
39806
39562
  if (command.action === "fork-recorded") {
39807
39563
  const source = this.#sessions.findSessions([command.sessionId])[0];
39808
39564
  if (source === void 0 || !source.prompted) {
@@ -39812,7 +39568,7 @@ var NativeSessionService = class {
39812
39568
  "native_session_not_found"
39813
39569
  );
39814
39570
  }
39815
- if (source.agentId !== command.agentId || source.cwd !== cwd || source.additionalDirectories.length !== additionalDirectories.length || source.additionalDirectories.some((path2, index2) => path2 !== additionalDirectories[index2])) {
39571
+ if (source.agentId !== command.agentId || source.cwd !== cwd || source.additionalDirectories.length !== additionalDirectories.length || source.additionalDirectories.some((path2, index) => path2 !== additionalDirectories[index])) {
39816
39572
  throw new AcpExecutionError(
39817
39573
  "The source conversation execution target does not match the fork request",
39818
39574
  {},
@@ -39833,8 +39589,8 @@ var NativeSessionService = class {
39833
39589
  signal.throwIfAborted();
39834
39590
  const directory = await this.#directories.list(this.#config.bindingId, command.directoryId, signal);
39835
39591
  const ready2 = {
39836
- additionalDirectories: additionalDirectories.map((path2, index2) => ({
39837
- directoryId: command.additionalDirectoryIds[index2] ?? command.directoryId,
39592
+ additionalDirectories: additionalDirectories.map((path2, index) => ({
39593
+ directoryId: command.additionalDirectoryIds[index] ?? command.directoryId,
39838
39594
  name: basename4(path2) || path2
39839
39595
  })),
39840
39596
  agentId: command.agentId,
@@ -39995,44 +39751,6 @@ var NativeSessionService = class {
39995
39751
  );
39996
39752
  }
39997
39753
  const target = await this.resolveTarget(command, options, selected);
39998
- if (command.action === "history") {
39999
- const history = await nativeSessionAdapter(options.agent.id).history({
40000
- sessions: this.#sessions,
40001
- directories: this.#directories,
40002
- bindingId: command.bindingId,
40003
- options: { ...options, cwd: target.cwd, additionalDirectories: target.additionalDirectories },
40004
- nativeSessionId: target.info.sessionId
40005
- });
40006
- signal.throwIfAborted();
40007
- this.record(command, "native_session_history_read");
40008
- return {
40009
- ...envelope2,
40010
- action: "history",
40011
- entryId: command.entryId,
40012
- history,
40013
- title: target.info.title ?? "Untitled session"
40014
- };
40015
- }
40016
- if (command.action === "preview") {
40017
- const history = await nativeSessionAdapter(options.agent.id).preview({
40018
- sessions: this.#sessions,
40019
- directories: this.#directories,
40020
- bindingId: command.bindingId,
40021
- options: { ...options, cwd: target.cwd, additionalDirectories: target.additionalDirectories },
40022
- nativeSessionId: target.info.sessionId
40023
- });
40024
- signal.throwIfAborted();
40025
- this.record(command, "native_session_previewed");
40026
- return {
40027
- ...envelope2,
40028
- action: "preview",
40029
- entryId: command.entryId,
40030
- targetSessionId: command.sessionId,
40031
- reason: "requested",
40032
- title: target.info.title ?? "Untitled session",
40033
- history
40034
- };
40035
- }
40036
39754
  if (command.action === "delete") {
40037
39755
  if (!prepared.capabilities.deleteSession) {
40038
39756
  throw new AcpExecutionError(
@@ -40167,7 +39885,7 @@ var NativeSessionService = class {
40167
39885
  resolveTarget = async (command, options, selected) => {
40168
39886
  let cursor = null;
40169
39887
  const visited = /* @__PURE__ */ new Set();
40170
- for (let index2 = 0; index2 < 100; index2 += 1) {
39888
+ for (let index = 0; index < 100; index += 1) {
40171
39889
  const page = await this.#sessions.listNativeSessions(options, cursor);
40172
39890
  const info = page.sessions.find((entry) => entry.sessionId === selected.nativeSessionId);
40173
39891
  if (info !== void 0) {
@@ -40175,7 +39893,7 @@ var NativeSessionService = class {
40175
39893
  if (target === null) {
40176
39894
  throw new LocalAuthorizationError("The selected native session is not authorized");
40177
39895
  }
40178
- if (target.cwd !== selected.cwd || target.additionalDirectories.length !== selected.additionalDirectories.length || target.additionalDirectories.some((path2, index3) => path2 !== selected.additionalDirectories[index3])) {
39896
+ if (target.cwd !== selected.cwd || target.additionalDirectories.length !== selected.additionalDirectories.length || target.additionalDirectories.some((path2, index2) => path2 !== selected.additionalDirectories[index2])) {
40179
39897
  throw new AcpExecutionError(
40180
39898
  "This session's directory changed. Refresh the list before continuing.",
40181
39899
  {},
@@ -40436,135 +40154,13 @@ var RelayConnectionDiagnostics = class {
40436
40154
  };
40437
40155
 
40438
40156
  // src/relay-connection/run-relay-connection.ts
40439
- import { WebSocket as WebSocket8 } from "undici";
40157
+ import { WebSocket as WebSocket7 } from "undici";
40440
40158
 
40441
40159
  // src/daemon-command-handler.ts
40442
- import { WebSocket as WebSocket6 } from "undici";
40443
-
40444
- // src/agent-catalog/handle-agent-catalog-refresh.ts
40445
- import { WebSocket as WebSocket3 } from "undici";
40446
- async function retainStillInstalledAgents(previous, refreshed, signal) {
40447
- const refreshedIdentifiers = new Set(refreshed.map((agent) => agent.id));
40448
- const retained = [];
40449
- for (const agent of previous) {
40450
- if (refreshedIdentifiers.has(agent.id)) {
40451
- continue;
40452
- }
40453
- signal.throwIfAborted();
40454
- if (await revalidateExecutable(agent.agentIdentity)) {
40455
- retained.push(agent);
40456
- }
40457
- }
40458
- return Object.freeze([...refreshed, ...retained]);
40459
- }
40460
- async function refreshAgentCatalog(config2, resolveEnvironment, signal) {
40461
- signal.throwIfAborted();
40462
- const shellEnvironment = await resolveEnvironment(signal);
40463
- const environment = new DaemonLocalContext(config2.localContext.stateDirectory, shellEnvironment).environment;
40464
- signal.throwIfAborted();
40465
- const inventory = await discoverLocalAgentInventory({
40466
- defaultWorkspace: config2.defaultWorkspace,
40467
- environment,
40468
- signal
40469
- });
40470
- const previousCatalog = config2.catalog.read();
40471
- const refreshedAgents = inventory.readyAgents().map((agent) => withDaemonEnvironment(agent, environment));
40472
- const agents = await retainStillInstalledAgents(previousCatalog.agents, refreshedAgents, signal);
40473
- const verifiedIdentifiers = new Set(agents.map((agent) => agent.id));
40474
- config2.catalog.transition(
40475
- agents,
40476
- inventory.installable.filter((agent) => !verifiedIdentifiers.has(agent.id))
40477
- );
40478
- try {
40479
- await publishAgentCatalog(config2, signal);
40480
- } catch (error62) {
40481
- config2.catalog.transition(previousCatalog.agents, previousCatalog.installableAgents);
40482
- throw error62;
40483
- }
40484
- }
40485
- function createAgentCatalogRefreshHandler(dependencies) {
40486
- const { config: config2, audit, diagnostics, socket, signal, timer, resolveEnvironment } = dependencies;
40487
- const agentCatalogRefreshes = /* @__PURE__ */ new Map();
40488
- const handle = (command) => {
40489
- if (agentCatalogRefreshes.has(command.requestId) || agentCatalogRefreshes.size > 0) {
40490
- if (socket.readyState === WebSocket3.OPEN) {
40491
- send(socket, {
40492
- code: "agent_catalog_refresh_busy",
40493
- kind: AGENT_CATALOG_REFRESH_FAILED_KIND,
40494
- message: "Another local Agent catalog refresh is already running",
40495
- requestId: command.requestId
40496
- });
40497
- }
40498
- return;
40499
- }
40500
- const controller = new AbortController();
40501
- const operationSignal = AbortSignal.any([signal, controller.signal]);
40502
- const timeout = timer.schedule(
40503
- () => controller.abort(
40504
- new AcpExecutionError(
40505
- "The local Agent catalog refresh timed out",
40506
- {},
40507
- "agent_catalog_refresh_timeout"
40508
- )
40509
- ),
40510
- 9e4
40511
- );
40512
- const completion = (async () => {
40513
- try {
40514
- await refreshAgentCatalog(config2, resolveEnvironment, operationSignal);
40515
- audit.record({
40516
- commandId: command.requestId,
40517
- event: "agent_catalog_refreshed",
40518
- sessionId: "agent-catalog"
40519
- });
40520
- if (socket.readyState === WebSocket3.OPEN) {
40521
- send(socket, {
40522
- kind: AGENT_CATALOG_REFRESHED_KIND,
40523
- requestId: command.requestId
40524
- });
40525
- }
40526
- } catch (error62) {
40527
- const failure2 = operationSignal.aborted ? controller.signal.reason ?? new AcpExecutionError(
40528
- "The local Agent catalog refresh was cancelled",
40529
- {},
40530
- "agent_catalog_refresh_cancelled"
40531
- ) : error62;
40532
- audit.record({
40533
- commandId: command.requestId,
40534
- details: { code: operationErrorCode(failure2) },
40535
- event: "agent_catalog_refresh_failed",
40536
- sessionId: "agent-catalog"
40537
- });
40538
- diagnostics.daemonDiagnostic(
40539
- "agent_catalog_refresh_failed",
40540
- command.requestId,
40541
- { code: operationErrorCode(failure2) },
40542
- failure2
40543
- );
40544
- if (socket.readyState === WebSocket3.OPEN) {
40545
- send(socket, {
40546
- code: operationErrorCode(failure2),
40547
- kind: AGENT_CATALOG_REFRESH_FAILED_KIND,
40548
- message: operationErrorMessage(failure2),
40549
- requestId: command.requestId
40550
- });
40551
- }
40552
- } finally {
40553
- timeout.cancel();
40554
- agentCatalogRefreshes.delete(command.requestId);
40555
- }
40556
- })();
40557
- agentCatalogRefreshes.set(command.requestId, { completion, controller });
40558
- return;
40559
- };
40560
- const settle2 = async () => {
40561
- await Promise.all([...agentCatalogRefreshes.values()].map((request) => request.completion));
40562
- };
40563
- return { handle, settle: settle2 };
40564
- }
40160
+ import { WebSocket as WebSocket5 } from "undici";
40565
40161
 
40566
40162
  // src/agent-catalog/handle-agent-settings-discovery.ts
40567
- import { WebSocket as WebSocket4 } from "undici";
40163
+ import { WebSocket as WebSocket3 } from "undici";
40568
40164
 
40569
40165
  // src/agent-catalog/discover-agent-settings.ts
40570
40166
  import { createHash as createHash5 } from "node:crypto";
@@ -41052,7 +40648,7 @@ function createAgentSettingsDiscoveryHandler(dependencies) {
41052
40648
  (request) => request.agentId === command.agentId && !request.controller.signal.aborted
41053
40649
  );
41054
40650
  if ([...agentSettingsDiscoveries.values()].some((request) => request.requestIds.has(command.requestId))) {
41055
- if (socket.readyState === WebSocket4.OPEN) {
40651
+ if (socket.readyState === WebSocket3.OPEN) {
41056
40652
  send(socket, {
41057
40653
  code: "agent_settings_discovery_busy",
41058
40654
  kind: AGENT_SETTINGS_DISCOVERY_FAILED_KIND,
@@ -41067,7 +40663,7 @@ function createAgentSettingsDiscoveryHandler(dependencies) {
41067
40663
  return;
41068
40664
  }
41069
40665
  if (existing !== void 0) {
41070
- if (socket.readyState === WebSocket4.OPEN) {
40666
+ if (socket.readyState === WebSocket3.OPEN) {
41071
40667
  send(socket, {
41072
40668
  code: "agent_settings_discovery_busy",
41073
40669
  kind: AGENT_SETTINGS_DISCOVERY_FAILED_KIND,
@@ -41078,7 +40674,7 @@ function createAgentSettingsDiscoveryHandler(dependencies) {
41078
40674
  return;
41079
40675
  }
41080
40676
  if (agentSettingsDiscoveries.size >= 4) {
41081
- if (socket.readyState === WebSocket4.OPEN) {
40677
+ if (socket.readyState === WebSocket3.OPEN) {
41082
40678
  send(socket, {
41083
40679
  code: "agent_settings_discovery_busy",
41084
40680
  kind: AGENT_SETTINGS_DISCOVERY_FAILED_KIND,
@@ -41124,7 +40720,7 @@ function createAgentSettingsDiscoveryHandler(dependencies) {
41124
40720
  event: "agent_settings_discovered",
41125
40721
  sessionId: `agent-settings:${command.agentId}`
41126
40722
  });
41127
- if (socket.readyState === WebSocket4.OPEN) {
40723
+ if (socket.readyState === WebSocket3.OPEN) {
41128
40724
  send(socket, { ...result.event, requestId });
41129
40725
  }
41130
40726
  }
@@ -41150,7 +40746,7 @@ function createAgentSettingsDiscoveryHandler(dependencies) {
41150
40746
  `
41151
40747
  );
41152
40748
  }
41153
- if (socket.readyState === WebSocket4.OPEN) {
40749
+ if (socket.readyState === WebSocket3.OPEN) {
41154
40750
  for (const requestId of requestIds) {
41155
40751
  send(socket, {
41156
40752
  code: operationErrorCode(failure2),
@@ -41296,300 +40892,7 @@ async function resolveSessionDirectories(directories, bindingId, directoryId2, a
41296
40892
  return new ResolvedSessionDirectories(cwd, additionalDirectories, additionalDirectoryEntries);
41297
40893
  }
41298
40894
 
41299
- // src/native-sessions/live-history-page.ts
41300
- function encodeLiveHistoryCursor(cursor) {
41301
- return Buffer.from(JSON.stringify(cursor), "utf8").toString("base64url");
41302
- }
41303
- function decodeLiveHistoryCursor(cursor, sessionId) {
41304
- try {
41305
- if (!/^[A-Za-z0-9_-]{1,512}$/u.test(cursor)) {
41306
- throw new Error("Invalid cursor alphabet");
41307
- }
41308
- const value = JSON.parse(Buffer.from(cursor, "base64url").toString("utf8"));
41309
- if (typeof value !== "object" || value === null || Array.isArray(value)) {
41310
- throw new Error("Invalid cursor shape");
41311
- }
41312
- const record2 = Object.fromEntries(Object.entries(value));
41313
- const keys = Object.keys(record2).sort().join(",");
41314
- const legacyNative = keys === "endIndex,sessionId";
41315
- const kind = legacyNative ? "native" : record2["kind"];
41316
- if (keys !== "endIndex,kind,sessionId" && keys !== "endIndex,epoch,kind,sessionId" && !legacyNative || record2["sessionId"] !== sessionId || kind !== "active" && kind !== "native" || typeof record2["endIndex"] !== "number" || !Number.isSafeInteger(record2["endIndex"]) || record2["endIndex"] < 0) {
41317
- throw new Error("Invalid cursor target");
41318
- }
41319
- if (kind === "active") {
41320
- if (keys !== "endIndex,epoch,kind,sessionId" || typeof record2["epoch"] !== "string") {
41321
- throw new Error("Invalid active cursor target");
41322
- }
41323
- return { endIndex: record2["endIndex"], epoch: record2["epoch"], kind, sessionId };
41324
- }
41325
- if (keys !== "endIndex,kind,sessionId" && !legacyNative) {
41326
- throw new Error("Invalid native cursor target");
41327
- }
41328
- return { endIndex: record2["endIndex"], kind, sessionId };
41329
- } catch (cause) {
41330
- throw new AcpExecutionError("The native Session history cursor is invalid", { cause }, "invalid_cursor");
41331
- }
41332
- }
41333
- function activeHistoryCursor(sessionId, epoch, endIndex) {
41334
- return encodeLiveHistoryCursor({ endIndex, epoch, kind: "active", sessionId });
41335
- }
41336
- function nativeHistoryCursor(sessionId, endIndex) {
41337
- return encodeLiveHistoryCursor({ endIndex, kind: "native", sessionId });
41338
- }
41339
- function liveHistoryCoveredTurnRanges(history) {
41340
- const ranges = [];
41341
- let historyIndex = history.messages.length;
41342
- for (const commandId of history.coveredCommandIds) {
41343
- let assistantStartIndex = historyIndex;
41344
- while (assistantStartIndex > 0 && history.messages[assistantStartIndex - 1]?.role === "assistant") {
41345
- assistantStartIndex -= 1;
41346
- }
41347
- const userIndex = assistantStartIndex - 1;
41348
- if (assistantStartIndex === historyIndex || history.messages[userIndex]?.role !== "user") {
41349
- break;
41350
- }
41351
- ranges.push({ assistantEndIndex: historyIndex, assistantStartIndex, commandId, userIndex });
41352
- historyIndex = userIndex;
41353
- }
41354
- return ranges;
41355
- }
41356
- function historyMessageCharacters(message) {
41357
- return message.text.length + (message.role === "assistant" ? JSON.stringify(message.activities).length + JSON.stringify(message.content).length : 0);
41358
- }
41359
- function isNativeHistoryImageMimeType(mimeType) {
41360
- return mimeType === "image/png" || mimeType === "image/jpeg" || mimeType === "image/gif" || mimeType === "image/webp";
41361
- }
41362
- function selectMessagesBefore(messages, endIndex, messageLimit, characterLimit) {
41363
- const selected = [];
41364
- let remainingCharacters = characterLimit;
41365
- let startIndex = endIndex;
41366
- for (let index2 = endIndex - 1; index2 >= 0 && selected.length < messageLimit; index2 -= 1) {
41367
- const message = messages[index2];
41368
- if (message === void 0) {
41369
- break;
41370
- }
41371
- const characters = historyMessageCharacters(message);
41372
- if (characters > remainingCharacters) {
41373
- break;
41374
- }
41375
- selected.unshift(message);
41376
- remainingCharacters -= characters;
41377
- startIndex = index2;
41378
- }
41379
- if (selected.length === 0 && endIndex > 0) {
41380
- throw new AcpExecutionError(
41381
- "A native Session history item exceeds the page budget",
41382
- {},
41383
- "history_item_too_large"
41384
- );
41385
- }
41386
- return { characters: characterLimit - remainingCharacters, messages: selected, startIndex };
41387
- }
41388
- function nativeActiveMessage(message) {
41389
- if (message.role === "assistant") {
41390
- return {
41391
- activities: message.activities,
41392
- content: message.content,
41393
- role: "assistant",
41394
- text: message.text
41395
- };
41396
- }
41397
- const images = (message.images ?? []).flatMap((image) => {
41398
- if (image.data.length < 4 || image.data.length % 4 !== 0 || !/^[A-Za-z0-9+/]*={0,2}$/u.test(image.data) || !isNativeHistoryImageMimeType(image.mimeType)) {
41399
- return [];
41400
- }
41401
- return [{ data: image.data, mimeType: image.mimeType, name: image.name }];
41402
- });
41403
- return { ...images.length === 0 ? {} : { images }, role: "user", text: message.text };
41404
- }
41405
- function nativeHistoryCoversCompletedRecovery(history, recovery) {
41406
- const root = recovery.messages.find((message) => message.role === "user" && message.id === recovery.commandId);
41407
- if (root === void 0) {
41408
- return false;
41409
- }
41410
- const rootIndex = history.messages.findLastIndex(
41411
- (message) => message.role === "user" && message.text === root.text
41412
- );
41413
- if (rootIndex < 0) {
41414
- return false;
41415
- }
41416
- const nativeAssistant = history.messages.slice(rootIndex + 1).filter((message) => message.role === "assistant");
41417
- if (nativeAssistant.length === 0) {
41418
- return false;
41419
- }
41420
- const recoveryAssistant = recovery.messages.filter((message) => message.role === "assistant");
41421
- const recoveryText = recoveryAssistant.map((message) => message.text).join("");
41422
- const nativeText = nativeAssistant.map((message) => message.text).join("");
41423
- if (recoveryText.length > 0 && !nativeText.includes(recoveryText)) {
41424
- return false;
41425
- }
41426
- const nativeContent = new Set(
41427
- nativeAssistant.flatMap((message) => message.content).map((content) => JSON.stringify(content))
41428
- );
41429
- return recoveryAssistant.flatMap((message) => message.content).every((content) => nativeContent.has(JSON.stringify(content)));
41430
- }
41431
- function historyBeforeActiveTurn(history, activeTurn) {
41432
- if (history.status === "unavailable") {
41433
- return history;
41434
- }
41435
- const activeRoot = activeTurn.messages.find(
41436
- (message) => message.role === "user" && message.id === activeTurn.commandId
41437
- );
41438
- const matchingActiveUserIndex = activeRoot === void 0 ? -1 : activeTurn.state === "completed" || history.messages.at(-1)?.role === "user" && history.messages.at(-1)?.text === activeRoot.text || history.coveredCommandIds.includes(activeTurn.commandId) ? history.messages.findLastIndex((message) => message.role === "user" && message.text === activeRoot.text) : -1;
41439
- const activeUserIndex = matchingActiveUserIndex >= 0 ? matchingActiveUserIndex : liveHistoryCoveredTurnRanges(history).find((range) => range.commandId === activeTurn.commandId)?.userIndex ?? -1;
41440
- if (activeUserIndex < 0) {
41441
- return history;
41442
- }
41443
- return {
41444
- ...history,
41445
- coveredCommandIds: history.coveredCommandIds.filter((id) => id !== activeTurn.commandId),
41446
- coveredMessageIds: history.coveredMessageIds.filter(
41447
- (id) => id !== `${activeTurn.commandId}:user` && id !== `${activeTurn.commandId}:agent`
41448
- ),
41449
- messages: history.messages.slice(0, activeUserIndex)
41450
- };
41451
- }
41452
- function paginateAvailableNativeHistory(history, sessionId, endIndex, limit, characterLimit) {
41453
- if (endIndex > history.messages.length) {
41454
- throw new AcpExecutionError("The native Session history cursor is invalid", {}, "invalid_cursor");
41455
- }
41456
- const selected = selectMessagesBefore(history.messages, endIndex, limit, characterLimit);
41457
- const coveredMessageIds = new Set(history.coveredMessageIds);
41458
- const ranges = liveHistoryCoveredTurnRanges(history);
41459
- return {
41460
- coveredCommandIds: ranges.filter((range) => range.userIndex >= selected.startIndex && range.assistantEndIndex <= endIndex).map((range) => range.commandId),
41461
- coveredMessageIds: ranges.flatMap((range) => [
41462
- ...range.userIndex >= selected.startIndex && range.userIndex < endIndex && coveredMessageIds.has(`${range.commandId}:user`) ? [`${range.commandId}:user`] : [],
41463
- ...range.assistantStartIndex >= selected.startIndex && range.assistantEndIndex <= endIndex && coveredMessageIds.has(`${range.commandId}:agent`) ? [`${range.commandId}:agent`] : []
41464
- ]),
41465
- messages: selected.messages,
41466
- nextCursor: selected.startIndex > 0 ? nativeHistoryCursor(sessionId, selected.startIndex) : null,
41467
- status: "available",
41468
- truncated: history.truncated
41469
- };
41470
- }
41471
- function paginateNativeHistory(history, sessionId, cursor, limit) {
41472
- if (cursor?.kind === "active") {
41473
- throw new AcpExecutionError("The native Session history cursor is invalid", {}, "invalid_cursor");
41474
- }
41475
- if (history.status === "unavailable") {
41476
- if (cursor !== null) {
41477
- throw new AcpExecutionError("Unavailable native Session history has no cursor", {}, "invalid_cursor");
41478
- }
41479
- return { cause: history.cause, nextCursor: null, status: "unavailable" };
41480
- }
41481
- return paginateAvailableNativeHistory(
41482
- history,
41483
- sessionId,
41484
- cursor?.endIndex ?? history.messages.length,
41485
- limit,
41486
- SESSION_HISTORY_CHARACTER_LIMIT
41487
- );
41488
- }
41489
- function paginateActiveTurn(history, activeTurn, sessionId, endIndex, limit) {
41490
- if (endIndex > activeTurn.messages.length) {
41491
- throw new AcpExecutionError("The native Session history cursor is invalid", {}, "invalid_cursor");
41492
- }
41493
- const activeMessages = activeTurn.messages.map(nativeActiveMessage);
41494
- const active = selectMessagesBefore(activeMessages, endIndex, limit, SESSION_HISTORY_CHARACTER_LIMIT);
41495
- const historicalLimit = limit - active.messages.length;
41496
- const historicalCharacterLimit = SESSION_HISTORY_CHARACTER_LIMIT - active.characters;
41497
- const pendingHistoricalCursor = history.status === "available" && history.messages.length > 0 ? nativeHistoryCursor(sessionId, history.messages.length) : null;
41498
- const latestHistoricalMessage = history.status === "available" ? history.messages.at(-1) : void 0;
41499
- const historicalPageFits = latestHistoricalMessage === void 0 || historyMessageCharacters(latestHistoricalMessage) <= historicalCharacterLimit;
41500
- const historical = active.startIndex === 0 && history.status === "available" && historicalLimit > 0 && historicalPageFits ? paginateAvailableNativeHistory(
41501
- history,
41502
- sessionId,
41503
- history.messages.length,
41504
- historicalLimit,
41505
- historicalCharacterLimit
41506
- ) : null;
41507
- return {
41508
- streamPosition: { commandId: activeTurn.commandId, epoch: activeTurn.epoch, sequence: activeTurn.sequence },
41509
- coveredCommandIds: historical?.coveredCommandIds ?? [],
41510
- coveredMessageIds: [
41511
- ...historical?.coveredMessageIds ?? [],
41512
- ...active.startIndex === 0 ? [`${activeTurn.commandId}:user`, `${activeTurn.commandId}:agent`] : []
41513
- ],
41514
- messages: [...historical?.messages ?? [], ...active.messages],
41515
- nextCursor: active.startIndex > 0 ? activeHistoryCursor(sessionId, activeTurn.epoch, active.startIndex) : historical === null ? pendingHistoricalCursor : historical.nextCursor,
41516
- status: "available",
41517
- truncated: activeTurn.truncated || (historical?.truncated ?? false)
41518
- };
41519
- }
41520
- function paginateLiveSessionHistory(history, activeTurn, sessionId, encodedCursor, limit) {
41521
- const cursor = encodedCursor === null ? null : decodeLiveHistoryCursor(encodedCursor, sessionId);
41522
- if (activeTurn === null || activeTurn.state === "completed" && history.status === "available" && nativeHistoryCoversCompletedRecovery(history, activeTurn)) {
41523
- return paginateNativeHistory(history, sessionId, cursor, limit);
41524
- }
41525
- const historical = historyBeforeActiveTurn(history, activeTurn);
41526
- if (cursor?.kind === "native") {
41527
- return paginateNativeHistory(historical, sessionId, cursor, limit);
41528
- }
41529
- if (cursor !== null && cursor.epoch !== activeTurn.epoch) {
41530
- throw new AcpExecutionError("The active Turn history cursor is stale", {}, "stale_cursor");
41531
- }
41532
- return paginateActiveTurn(historical, activeTurn, sessionId, cursor?.endIndex ?? activeTurn.messages.length, limit);
41533
- }
41534
-
41535
40895
  // src/daemon-history-commands.ts
41536
- async function executeSessionLiveHistoryPageLoad(socket, command, config2, directories, audit, sessions, activeTurn, signal) {
41537
- try {
41538
- const resolved = await resolveSessionDirectories(
41539
- directories,
41540
- config2.bindingId,
41541
- command.directoryId,
41542
- command.additionalDirectoryIds,
41543
- signal
41544
- );
41545
- const history = await sessions.loadSessionHistory({
41546
- additionalDirectories: resolved.additionalDirectories,
41547
- agent: config2.catalog.find(command.agentId),
41548
- cwd: resolved.cwd,
41549
- sessionId: command.sessionId,
41550
- signal
41551
- });
41552
- signal.throwIfAborted();
41553
- const page = paginateLiveSessionHistory(
41554
- history,
41555
- activeTurn(command.sessionId),
41556
- command.sessionId,
41557
- command.cursor,
41558
- command.limit
41559
- );
41560
- audit.record({
41561
- commandId: command.requestId,
41562
- event: "session_history_loaded",
41563
- sessionId: command.sessionId
41564
- });
41565
- send(socket, {
41566
- kind: "session.live-history.page.loaded",
41567
- page,
41568
- requestId: command.requestId,
41569
- sessionId: command.sessionId
41570
- });
41571
- } catch (error62) {
41572
- if (signal.aborted) {
41573
- return;
41574
- }
41575
- audit.record({
41576
- commandId: command.requestId,
41577
- details: { code: operationErrorCode(error62) },
41578
- event: "session_history_unavailable",
41579
- sessionId: command.sessionId
41580
- });
41581
- send(socket, {
41582
- kind: "session.live-history.page.loaded",
41583
- page: {
41584
- status: "unavailable",
41585
- cause: { code: operationErrorCode(error62), message: operationErrorMessage(error62) },
41586
- nextCursor: null
41587
- },
41588
- requestId: command.requestId,
41589
- sessionId: command.sessionId
41590
- });
41591
- }
41592
- }
41593
40896
  async function executeSessionLiveHistoryV2PageLoad(socket, command, config2, directories, audit, diagnostics, sessions, eventLogV2, signal) {
41594
40897
  try {
41595
40898
  const resolved = await resolveSessionDirectories(
@@ -41610,7 +40913,7 @@ async function executeSessionLiveHistoryV2PageLoad(socket, command, config2, dir
41610
40913
  const replay = await sessions.loadSessionEventsV2(loadOptions, command.eventLimit, command.cursor);
41611
40914
  signal.throwIfAborted();
41612
40915
  const events = replay.events.map(
41613
- (event, index2) => eventLogV2.event(command.sessionId, replay.startPosition + index2, event, "1970-01-01T00:00:00.000Z")
40916
+ (event, index) => eventLogV2.event(command.sessionId, replay.startPosition + index, event, "1970-01-01T00:00:00.000Z")
41614
40917
  );
41615
40918
  const tailCursor = events.at(-1)?.eventId ?? "";
41616
40919
  audit.record({
@@ -42360,7 +41663,7 @@ async function executeSessionConfigure(publisher, socket, command, config2, dire
42360
41663
  }
42361
41664
 
42362
41665
  // src/native-sessions/handle-native-requests.ts
42363
- import { WebSocket as WebSocket5 } from "undici";
41666
+ import { WebSocket as WebSocket4 } from "undici";
42364
41667
  function createNativeSessionRequestHandler(dependencies) {
42365
41668
  const { audit, diagnostics, nativeSessions, publisher, signal, socket, timer } = dependencies;
42366
41669
  const pending = /* @__PURE__ */ new Map();
@@ -42425,7 +41728,7 @@ function createNativeSessionRequestHandler(dependencies) {
42425
41728
  }
42426
41729
  ]);
42427
41730
  }
42428
- if (socket.readyState === WebSocket5.OPEN) {
41731
+ if (socket.readyState === WebSocket4.OPEN) {
42429
41732
  send(socket, result);
42430
41733
  }
42431
41734
  } catch (error62) {
@@ -42484,8 +41787,7 @@ function createDaemonCommandHandler({
42484
41787
  socket,
42485
41788
  signal,
42486
41789
  runtimeSignal,
42487
- timer,
42488
- resolveAgentCatalogEnvironment
41790
+ timer
42489
41791
  }) {
42490
41792
  const handleSettingsDiscovery = createAgentSettingsDiscoveryHandler({
42491
41793
  config: config2,
@@ -42497,20 +41799,10 @@ function createDaemonCommandHandler({
42497
41799
  signal,
42498
41800
  timer
42499
41801
  });
42500
- const handleCatalogRefresh = createAgentCatalogRefreshHandler({
42501
- config: config2,
42502
- audit,
42503
- diagnostics,
42504
- socket,
42505
- signal,
42506
- timer,
42507
- resolveEnvironment: resolveAgentCatalogEnvironment
42508
- });
42509
41802
  const queueChanged = (sessionId) => {
42510
41803
  publisher.publish(sessionId, { kind: "session.queue.changed", sessionId });
42511
41804
  eventLogV2.queueChanged(sessionId);
42512
41805
  };
42513
- const activeTurnRecovery = (sessionId) => activeTurns.recovery((command) => command.sessionId === sessionId);
42514
41806
  const nativeRequestHandler = createNativeSessionRequestHandler({
42515
41807
  audit,
42516
41808
  diagnostics,
@@ -42523,18 +41815,8 @@ function createDaemonCommandHandler({
42523
41815
  return {
42524
41816
  handle: (message) => {
42525
41817
  const kind = message.kind;
42526
- if (kind === SESSION_LIVE_HISTORY_PAGE_LOAD_KIND) {
42527
- const command2 = message;
42528
- void executeSessionLiveHistoryPageLoad(
42529
- socket,
42530
- command2,
42531
- config2,
42532
- directories,
42533
- audit,
42534
- sessions,
42535
- activeTurnRecovery,
42536
- signal
42537
- );
41818
+ if (kind === RUNTIME_PING_KIND) {
41819
+ send(socket, { kind: RUNTIME_PONG_KIND, requestId: message.requestId });
42538
41820
  return;
42539
41821
  }
42540
41822
  if (kind === SESSION_LIVE_HISTORY_V2_PAGE_LOAD_KIND) {
@@ -42559,10 +41841,6 @@ function createDaemonCommandHandler({
42559
41841
  handleSettingsDiscovery.handle(message);
42560
41842
  return;
42561
41843
  }
42562
- if (kind === AGENT_CATALOG_REFRESH_KIND) {
42563
- handleCatalogRefresh.handle(message);
42564
- return;
42565
- }
42566
41844
  if (kind === NATIVE_SESSION_REQUEST_KIND) {
42567
41845
  nativeRequestHandler.handle(message);
42568
41846
  return;
@@ -42576,7 +41854,7 @@ function createDaemonCommandHandler({
42576
41854
  sessions.findSessions([command2.sessionId])[0]?.cwd ?? null,
42577
41855
  externalContent
42578
41856
  ).catch((error62) => {
42579
- if (socket.readyState !== WebSocket6.OPEN || signal.aborted) {
41857
+ if (socket.readyState !== WebSocket5.OPEN || signal.aborted) {
42580
41858
  return;
42581
41859
  }
42582
41860
  send(socket, {
@@ -42782,17 +42060,13 @@ function createDaemonCommandHandler({
42782
42060
  });
42783
42061
  },
42784
42062
  settle: async () => {
42785
- await Promise.all([
42786
- nativeRequestHandler.settle(),
42787
- handleSettingsDiscovery.settle(),
42788
- handleCatalogRefresh.settle()
42789
- ]);
42063
+ await Promise.all([nativeRequestHandler.settle(), handleSettingsDiscovery.settle()]);
42790
42064
  }
42791
42065
  };
42792
42066
  }
42793
42067
 
42794
42068
  // src/relay-connection/connect.ts
42795
- import { WebSocket as WebSocket7 } from "undici";
42069
+ import { WebSocket as WebSocket6 } from "undici";
42796
42070
 
42797
42071
  // src/relay-connection/runtime-revocation.ts
42798
42072
  var runtimeRevocationCloseCode = 1008;
@@ -42830,7 +42104,7 @@ function connectRelay(url2, signal) {
42830
42104
  const endpoint = new URL(url2);
42831
42105
  const headers = runtimeAuthorization(endpoint);
42832
42106
  endpoint.searchParams.delete("token");
42833
- const socket = new WebSocket7(endpoint, {
42107
+ const socket = new WebSocket6(endpoint, {
42834
42108
  dispatcher: environmentProxyDispatcher,
42835
42109
  headers
42836
42110
  });
@@ -43048,8 +42322,7 @@ async function runRelayConnection({
43048
42322
  diagnostics,
43049
42323
  onConnected,
43050
42324
  signal,
43051
- timer,
43052
- resolveAgentCatalogEnvironment
42325
+ timer
43053
42326
  }) {
43054
42327
  const relayUrl = new URL(config2.relayUrl);
43055
42328
  relayUrl.searchParams.set("liveness", "1");
@@ -43072,8 +42345,7 @@ async function runRelayConnection({
43072
42345
  socket,
43073
42346
  signal: connectionController.signal,
43074
42347
  runtimeSignal: signal,
43075
- timer,
43076
- resolveAgentCatalogEnvironment
42348
+ timer
43077
42349
  });
43078
42350
  installationObserver.connect(socket);
43079
42351
  onConnected();
@@ -43119,14 +42391,14 @@ async function runRelayConnection({
43119
42391
  };
43120
42392
  const connectionLiveness = new RelayConnectionLiveness(timer, {
43121
42393
  send: (message) => {
43122
- if (socket.readyState !== WebSocket8.OPEN) {
42394
+ if (socket.readyState !== WebSocket7.OPEN) {
43123
42395
  return false;
43124
42396
  }
43125
42397
  try {
43126
42398
  send(socket, message);
43127
42399
  return true;
43128
42400
  } catch (error62) {
43129
- if (socket.readyState !== WebSocket8.OPEN) {
42401
+ if (socket.readyState !== WebSocket7.OPEN) {
43130
42402
  return false;
43131
42403
  }
43132
42404
  throw error62;
@@ -43215,7 +42487,7 @@ async function runRelayConnection({
43215
42487
  }
43216
42488
 
43217
42489
  // src/relay-connection/session-event-publisher.ts
43218
- import { WebSocket as WebSocket9 } from "undici";
42490
+ import { WebSocket as WebSocket8 } from "undici";
43219
42491
  var MAX_BUFFERED_BYTES = 32 * 1024 * 1024;
43220
42492
  var DaemonSessionEventPublisher = class {
43221
42493
  #socket = null;
@@ -43232,7 +42504,7 @@ var DaemonSessionEventPublisher = class {
43232
42504
  };
43233
42505
  publish = (sessionId, event) => {
43234
42506
  const socket = this.#socket;
43235
- if (socket === null || socket.readyState !== WebSocket9.OPEN) {
42507
+ if (socket === null || socket.readyState !== WebSocket8.OPEN) {
43236
42508
  return;
43237
42509
  }
43238
42510
  const encoded = encodeDaemonToServiceMessage({
@@ -43256,7 +42528,7 @@ var DaemonSessionEventPublisher = class {
43256
42528
  };
43257
42529
  publishStatus = (event) => {
43258
42530
  const socket = this.#socket;
43259
- if (socket === null || socket.readyState !== WebSocket9.OPEN) {
42531
+ if (socket === null || socket.readyState !== WebSocket8.OPEN) {
43260
42532
  return;
43261
42533
  }
43262
42534
  const encoded = encodeDaemonToServiceMessage(event);
@@ -43271,7 +42543,7 @@ var DaemonSessionEventPublisher = class {
43271
42543
  };
43272
42544
  publishV2 = (event) => {
43273
42545
  const socket = this.#socket;
43274
- if (socket === null || socket.readyState !== WebSocket9.OPEN) {
42546
+ if (socket === null || socket.readyState !== WebSocket8.OPEN) {
43275
42547
  return;
43276
42548
  }
43277
42549
  const encoded = encodeDaemonToServiceMessage({ event, kind: SESSION_EVENT_V2_KIND });
@@ -43320,7 +42592,7 @@ function promptContent(command) {
43320
42592
  }
43321
42593
  return content;
43322
42594
  }
43323
- function sessionEventV22(daemonGenerationId, sessionId, position, event, recordedAt) {
42595
+ function sessionEventV2(daemonGenerationId, sessionId, position, event, recordedAt) {
43324
42596
  const sessionPrefix = createHash6("sha256").update(sessionId).digest("hex").slice(0, 16);
43325
42597
  return {
43326
42598
  eventId: `event-${daemonGenerationId}-${sessionPrefix}-${position.toString().padStart(16, "0")}`,
@@ -43356,7 +42628,7 @@ var DaemonSessionEventLogV2 = class {
43356
42628
  record = (sessionId, event, position) => {
43357
42629
  this.#publisher.publishV2(this.event(sessionId, position, event, (/* @__PURE__ */ new Date()).toISOString()));
43358
42630
  };
43359
- event = (sessionId, position, event, recordedAt) => sessionEventV22(this.daemonGenerationId, sessionId, position, event, recordedAt);
42631
+ event = (sessionId, position, event, recordedAt) => sessionEventV2(this.daemonGenerationId, sessionId, position, event, recordedAt);
43360
42632
  queueChanged = (_sessionId) => void 0;
43361
42633
  completed = (sessionId, commandId, _stopReason) => {
43362
42634
  const request = this.#queued.get(commandId);
@@ -43493,7 +42765,7 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
43493
42765
  options2.signal
43494
42766
  );
43495
42767
  return cwd === options2.cwd && additionalDirectories.length === options2.additionalDirectories.length && additionalDirectories.every(
43496
- (directory, index2) => directory === options2.additionalDirectories[index2]
42768
+ (directory, index) => directory === options2.additionalDirectories[index]
43497
42769
  );
43498
42770
  });
43499
42771
  }
@@ -43510,10 +42782,6 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
43510
42782
  let connectionAnnounced = false;
43511
42783
  let catalogPublished = false;
43512
42784
  let readinessAnnounced = false;
43513
- const resolveAgentCatalogEnvironment = options.resolveAgentCatalogEnvironment ?? (async (catalogSignal) => {
43514
- catalogSignal.throwIfAborted();
43515
- return config2.localContext.environment;
43516
- });
43517
42785
  const startAutomaticIntegrationProvisioning = () => {
43518
42786
  if (!connectionAnnounced || !catalogPublished || automaticIntegrationProvisioningStarted) {
43519
42787
  return;
@@ -43591,8 +42859,7 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
43591
42859
  announceConnection();
43592
42860
  },
43593
42861
  signal,
43594
- timer,
43595
- resolveAgentCatalogEnvironment
42862
+ timer
43596
42863
  });
43597
42864
  } catch (error62) {
43598
42865
  if (signal.aborted) {
@@ -43965,16 +43232,16 @@ var RuntimeInstallationStore = class _RuntimeInstallationStore {
43965
43232
  };
43966
43233
  #readConnectionForChannel = async (channelId, signal) => {
43967
43234
  const normalizedChannelId = validateIdentifier(channelId, "invalid_channel_id");
43968
- const index2 = decodeChannelIndex(
43235
+ const index = decodeChannelIndex(
43969
43236
  await readJsonFile(this.channelIndexPath(normalizedChannelId), signal, "connection_not_found")
43970
43237
  );
43971
- if (index2.applicationId !== this.applicationId || index2.installationId !== this.installationId || index2.channelId !== normalizedChannelId) {
43238
+ if (index.applicationId !== this.applicationId || index.installationId !== this.installationId || index.channelId !== normalizedChannelId) {
43972
43239
  throw new RuntimeInstallationStoreError(
43973
43240
  "connection_owner_mismatch",
43974
43241
  "The saved Runtime connection belongs to another installation"
43975
43242
  );
43976
43243
  }
43977
- return await this.readConnection(index2.connectionId, signal);
43244
+ return await this.readConnection(index.connectionId, signal);
43978
43245
  };
43979
43246
  saveConnection = async (input2, signal) => {
43980
43247
  const stored = new VerifiedRuntimeConnection(
@@ -44500,8 +43767,7 @@ var MobiusRuntimeEngine = class {
44500
43767
  const audit = new AuditStore();
44501
43768
  try {
44502
43769
  await runDaemon(this.#config, audit, signal, void 0, {
44503
- ...this.#options.onConnectionStatus === void 0 ? {} : { onConnectionStatus: this.#options.onConnectionStatus },
44504
- ...this.#options.resolveAgentCatalogEnvironment === void 0 ? {} : { resolveAgentCatalogEnvironment: this.#options.resolveAgentCatalogEnvironment }
43770
+ ...this.#options.onConnectionStatus === void 0 ? {} : { onConnectionStatus: this.#options.onConnectionStatus }
44505
43771
  });
44506
43772
  } finally {
44507
43773
  audit.close();