@moxt-ai/mobius 0.0.173 → 0.0.175

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 (86) hide show
  1. package/dist/acp/agent-runtime-manager.d.ts +0 -1
  2. package/dist/acp/agent-runtime-manager.d.ts.map +1 -1
  3. package/dist/acp/agent-runtime-manager.js +2 -37
  4. package/dist/acp/agent-runtime-manager.js.map +1 -1
  5. package/dist/acp/agent-session.d.ts +0 -1
  6. package/dist/acp/agent-session.d.ts.map +1 -1
  7. package/dist/acp/agent-session.js +5 -17
  8. package/dist/acp/agent-session.js.map +1 -1
  9. package/dist/acp/session-store.d.ts +1 -8
  10. package/dist/acp/session-store.d.ts.map +1 -1
  11. package/dist/acp/session-store.js +8 -73
  12. package/dist/acp/session-store.js.map +1 -1
  13. package/dist/agent-catalog/agent-specification.js +1 -1
  14. package/dist/cli.js +66 -981
  15. package/dist/cli.js.map +4 -4
  16. package/dist/daemon-command-handler.d.ts +1 -2
  17. package/dist/daemon-command-handler.d.ts.map +1 -1
  18. package/dist/daemon-command-handler.js +6 -27
  19. package/dist/daemon-command-handler.js.map +1 -1
  20. package/dist/daemon-history-commands.d.ts +1 -3
  21. package/dist/daemon-history-commands.d.ts.map +1 -1
  22. package/dist/daemon-history-commands.js +1 -48
  23. package/dist/daemon-history-commands.js.map +1 -1
  24. package/dist/daemon-turn-registry.d.ts +13 -13
  25. package/dist/generated/acp-session-store-migrations.d.ts +3 -0
  26. package/dist/generated/acp-session-store-migrations.d.ts.map +1 -1
  27. package/dist/generated/acp-session-store-migrations.js +5 -1
  28. package/dist/generated/acp-session-store-migrations.js.map +1 -1
  29. package/dist/index.js +65 -980
  30. package/dist/index.js.map +4 -4
  31. package/dist/native-sessions/handle-native-requests.d.ts +0 -2
  32. package/dist/native-sessions/handle-native-requests.d.ts.map +1 -1
  33. package/dist/native-sessions/handle-native-requests.js +1 -12
  34. package/dist/native-sessions/handle-native-requests.js.map +1 -1
  35. package/dist/native-sessions/service.d.ts.map +1 -1
  36. package/dist/native-sessions/service.js +0 -117
  37. package/dist/native-sessions/service.js.map +1 -1
  38. package/dist/relay-connection/run-relay-connection.d.ts +1 -2
  39. package/dist/relay-connection/run-relay-connection.d.ts.map +1 -1
  40. package/dist/relay-connection/run-relay-connection.js +1 -2
  41. package/dist/relay-connection/run-relay-connection.js.map +1 -1
  42. package/dist/run-daemon.d.ts +0 -1
  43. package/dist/run-daemon.d.ts.map +1 -1
  44. package/dist/run-daemon.js +0 -6
  45. package/dist/run-daemon.js.map +1 -1
  46. package/dist/runtime.d.ts +0 -1
  47. package/dist/runtime.d.ts.map +1 -1
  48. package/dist/runtime.js +67 -982
  49. package/dist/runtime.js.map +4 -4
  50. package/dist/schema/acp-session-store/acp-session.d.ts +0 -16
  51. package/dist/schema/acp-session-store/acp-session.d.ts.map +1 -1
  52. package/dist/schema/acp-session-store/acp-session.js +0 -1
  53. package/dist/schema/acp-session-store/acp-session.js.map +1 -1
  54. package/dist/schema/acp-session-store/index.d.ts +0 -1
  55. package/dist/schema/acp-session-store/index.d.ts.map +1 -1
  56. package/dist/schema/acp-session-store/index.js +0 -1
  57. package/dist/schema/acp-session-store/index.js.map +1 -1
  58. package/package.json +1 -1
  59. package/dist/agent-catalog/handle-agent-catalog-refresh.d.ts +0 -21
  60. package/dist/agent-catalog/handle-agent-catalog-refresh.d.ts.map +0 -1
  61. package/dist/agent-catalog/handle-agent-catalog-refresh.js +0 -119
  62. package/dist/agent-catalog/handle-agent-catalog-refresh.js.map +0 -1
  63. package/dist/native-sessions/acp-adapter.d.ts +0 -3
  64. package/dist/native-sessions/acp-adapter.d.ts.map +0 -1
  65. package/dist/native-sessions/acp-adapter.js +0 -6
  66. package/dist/native-sessions/acp-adapter.js.map +0 -1
  67. package/dist/native-sessions/acp-history.d.ts +0 -6
  68. package/dist/native-sessions/acp-history.d.ts.map +0 -1
  69. package/dist/native-sessions/acp-history.js +0 -27
  70. package/dist/native-sessions/acp-history.js.map +0 -1
  71. package/dist/native-sessions/agent-adapter.d.ts +0 -16
  72. package/dist/native-sessions/agent-adapter.d.ts.map +0 -1
  73. package/dist/native-sessions/agent-adapter.js +0 -19
  74. package/dist/native-sessions/agent-adapter.js.map +0 -1
  75. package/dist/native-sessions/codex-adapter.d.ts +0 -3
  76. package/dist/native-sessions/codex-adapter.d.ts.map +0 -1
  77. package/dist/native-sessions/codex-adapter.js +0 -20
  78. package/dist/native-sessions/codex-adapter.js.map +0 -1
  79. package/dist/native-sessions/live-history-page.d.ts +0 -4
  80. package/dist/native-sessions/live-history-page.d.ts.map +0 -1
  81. package/dist/native-sessions/live-history-page.js +0 -258
  82. package/dist/native-sessions/live-history-page.js.map +0 -1
  83. package/dist/schema/acp-session-store/deleted-acp-session.d.ts +0 -24
  84. package/dist/schema/acp-session-store/deleted-acp-session.d.ts.map +0 -1
  85. package/dist/schema/acp-session-store/deleted-acp-session.js +0 -5
  86. package/dist/schema/acp-session-store/deleted-acp-session.js.map +0 -1
package/dist/index.js CHANGED
@@ -19815,9 +19815,6 @@ var AGENT_INSTALL_CANCELLED_KIND = "agent.integration.install.cancelled";
19815
19815
  var AGENT_SETTINGS_DISCOVER_KIND = "agent.settings.discover";
19816
19816
  var AGENT_SETTINGS_DISCOVERED_KIND = "agent.settings.discovered";
19817
19817
  var AGENT_SETTINGS_DISCOVERY_FAILED_KIND = "agent.settings.discovery.failed";
19818
- var AGENT_CATALOG_REFRESH_KIND = "agent.catalog.refresh";
19819
- var AGENT_CATALOG_REFRESHED_KIND = "agent.catalog.refreshed";
19820
- var AGENT_CATALOG_REFRESH_FAILED_KIND = "agent.catalog.refresh.failed";
19821
19818
  var FILE_READ_KIND = "file.read";
19822
19819
  var FILE_BEGIN_KIND = "file.begin";
19823
19820
  var FILE_CHUNK_KIND = "file.chunk";
@@ -19979,20 +19976,6 @@ var agentSettingsDiscoveryFailedEventSchema = external_exports.object({
19979
19976
  message: external_exports.string().min(1).max(500),
19980
19977
  requestId: identifierStringSchema
19981
19978
  }).readonly();
19982
- var agentCatalogRefreshCommandSchema = external_exports.object({
19983
- kind: external_exports.literal(AGENT_CATALOG_REFRESH_KIND),
19984
- requestId: identifierStringSchema
19985
- }).readonly();
19986
- var agentCatalogRefreshedEventSchema = external_exports.object({
19987
- kind: external_exports.literal(AGENT_CATALOG_REFRESHED_KIND),
19988
- requestId: identifierStringSchema
19989
- }).readonly();
19990
- var agentCatalogRefreshFailedEventSchema = external_exports.object({
19991
- code: identifierStringSchema,
19992
- kind: external_exports.literal(AGENT_CATALOG_REFRESH_FAILED_KIND),
19993
- message: external_exports.string().min(1).max(500),
19994
- requestId: identifierStringSchema
19995
- }).readonly();
19996
19979
  var sessionConfigurationSelectionSchema = external_exports.object({
19997
19980
  booleanValue: external_exports.boolean(),
19998
19981
  configId: identifierStringSchema,
@@ -20397,12 +20380,6 @@ var decodeAgentSettingsDiscoveredEvent = (encoded) => decode3(encoded, agentSett
20397
20380
  var encodeAgentSettingsDiscoveredEvent = (message) => encode3(message, agentSettingsDiscoveredEventSchema);
20398
20381
  var decodeAgentSettingsDiscoveryFailedEvent = (encoded) => decode3(encoded, agentSettingsDiscoveryFailedEventSchema);
20399
20382
  var encodeAgentSettingsDiscoveryFailedEvent = (message) => encode3(message, agentSettingsDiscoveryFailedEventSchema);
20400
- var decodeAgentCatalogRefreshCommand = (encoded) => decode3(encoded, agentCatalogRefreshCommandSchema);
20401
- var encodeAgentCatalogRefreshCommand = (message) => encode3(message, agentCatalogRefreshCommandSchema);
20402
- var decodeAgentCatalogRefreshedEvent = (encoded) => decode3(encoded, agentCatalogRefreshedEventSchema);
20403
- var encodeAgentCatalogRefreshedEvent = (message) => encode3(message, agentCatalogRefreshedEventSchema);
20404
- var decodeAgentCatalogRefreshFailedEvent = (encoded) => decode3(encoded, agentCatalogRefreshFailedEventSchema);
20405
- var encodeAgentCatalogRefreshFailedEvent = (message) => encode3(message, agentCatalogRefreshFailedEventSchema);
20406
20383
  var decodeFileReadCommand = (encoded) => decode3(encoded, fileReadCommandSchema);
20407
20384
  var encodeFileReadCommand = (message) => encode3(message, fileReadCommandSchema);
20408
20385
  var decodeFileBeginEvent = (encoded) => decode3(encoded, fileBeginEventSchema);
@@ -20471,6 +20448,8 @@ var SESSION_CANCEL_KIND = "session.cancel";
20471
20448
  var RUNTIME_LIVENESS_READY_KIND = "runtime.liveness.ready";
20472
20449
  var RUNTIME_HEARTBEAT_KIND = "runtime.heartbeat";
20473
20450
  var RUNTIME_HEARTBEAT_ACK_KIND = "runtime.heartbeat.ack";
20451
+ var RUNTIME_PING_KIND = "runtime.ping";
20452
+ var RUNTIME_PONG_KIND = "runtime.pong";
20474
20453
  var SESSION_STARTED_KIND = "session.started";
20475
20454
  var SESSION_QUEUED_KIND = "session.queued";
20476
20455
  var AGENT_MESSAGE_DELTA_KIND = "agent.message.delta";
@@ -20783,6 +20762,16 @@ function decodeRuntimeHeartbeatAckEvent(encoded) {
20783
20762
  kind: RUNTIME_HEARTBEAT_ACK_KIND
20784
20763
  };
20785
20764
  }
20765
+ function decodeRuntimePingCommand(encoded) {
20766
+ const value = parseJson2(encoded);
20767
+ assertKind(value, RUNTIME_PING_KIND);
20768
+ return { kind: RUNTIME_PING_KIND, requestId: readIdentifier(value, "requestId") };
20769
+ }
20770
+ function decodeRuntimePongEvent(encoded) {
20771
+ const value = parseJson2(encoded);
20772
+ assertKind(value, RUNTIME_PONG_KIND);
20773
+ return { kind: RUNTIME_PONG_KIND, requestId: readIdentifier(value, "requestId") };
20774
+ }
20786
20775
  function decodeSessionStartedEvent(encoded) {
20787
20776
  const value = parseJson2(encoded);
20788
20777
  assertKind(value, SESSION_STARTED_KIND);
@@ -20880,6 +20869,12 @@ function encodeRuntimeHeartbeatEvent(message) {
20880
20869
  function encodeRuntimeHeartbeatAckEvent(message) {
20881
20870
  return JSON.stringify(decodeRuntimeHeartbeatAckEvent(JSON.stringify(message)));
20882
20871
  }
20872
+ function encodeRuntimePingCommand(message) {
20873
+ return JSON.stringify(decodeRuntimePingCommand(JSON.stringify(message)));
20874
+ }
20875
+ function encodeRuntimePongEvent(message) {
20876
+ return JSON.stringify(decodeRuntimePongEvent(JSON.stringify(message)));
20877
+ }
20883
20878
  function decodeAgentActivityNarrationEvent(encoded) {
20884
20879
  const value = parseJson2(encoded);
20885
20880
  assertKind(value, AGENT_ACTIVITY_NARRATION_KIND);
@@ -20993,10 +20988,6 @@ function withinHistoryContentLimits(history) {
20993
20988
  ) <= SESSION_HISTORY_IMAGE_CHARACTER_LIMIT;
20994
20989
  }
20995
20990
  var sessionHistorySchema = external_exports.discriminatedUnion("status", [availableSessionHistorySchema, unavailableSessionHistorySchema]).refine(withinHistoryContentLimits);
20996
- var nativeMessagePageSchema = external_exports.discriminatedUnion("status", [
20997
- availableSessionHistoryObjectSchema.extend({ nextCursor: external_exports.string().max(512).nullable() }).readonly(),
20998
- unavailableSessionHistoryObjectSchema.extend({ nextCursor: external_exports.null() }).readonly()
20999
- ]).refine(withinHistoryContentLimits);
21000
20991
 
21001
20992
  // ../protocol/src/native-sessions.ts
21002
20993
  var NATIVE_SESSION_REQUEST_KIND = "native.session.request";
@@ -21062,10 +21053,7 @@ var identity = {
21062
21053
  directoryId
21063
21054
  };
21064
21055
  var nativeSessionRequestSchema = external_exports.discriminatedUnion("action", [
21065
- external_exports.object({ ...identity, action: external_exports.literal("create") }).readonly(),
21066
21056
  external_exports.object({ ...identity, action: external_exports.literal("active-turn"), targetSessionId: identifierStringSchema }).readonly(),
21067
- external_exports.object({ ...identity, action: external_exports.literal("preview"), entryId: identifierStringSchema }).readonly(),
21068
- external_exports.object({ ...identity, action: external_exports.literal("history"), entryId: identifierStringSchema }).readonly(),
21069
21057
  external_exports.object({ ...identity, action: external_exports.literal("find"), nativeSessionId: identifierStringSchema }).readonly(),
21070
21058
  external_exports.object({
21071
21059
  ...identity,
@@ -21077,24 +21065,10 @@ var nativeSessionRequestSchema = external_exports.discriminatedUnion("action", [
21077
21065
  action: external_exports.enum(["import", "fork"]),
21078
21066
  entryId: identifierStringSchema,
21079
21067
  targetSessionId: identifierStringSchema
21080
- }).readonly(),
21081
- external_exports.object({
21082
- ...identity,
21083
- action: external_exports.literal("fork-recorded"),
21084
- targetSessionId: identifierStringSchema,
21085
- throughCommandId: identifierStringSchema
21086
- }).readonly(),
21087
- external_exports.object({
21088
- ...identity,
21089
- action: external_exports.literal("delete"),
21090
- entryId: identifierStringSchema
21091
21068
  }).readonly()
21092
21069
  ]);
21093
21070
  var nativeSessionCommandSchema = external_exports.discriminatedUnion("action", [
21094
- external_exports.object({ ...identity, action: external_exports.literal("create") }).readonly(),
21095
21071
  external_exports.object({ ...identity, action: external_exports.literal("active-turn"), targetSessionId: identifierStringSchema }).readonly(),
21096
- external_exports.object({ ...identity, action: external_exports.literal("preview"), entryId: identifierStringSchema }).readonly(),
21097
- external_exports.object({ ...identity, action: external_exports.literal("history"), entryId: identifierStringSchema }).readonly(),
21098
21072
  external_exports.object({ ...identity, action: external_exports.literal("find"), nativeSessionId: identifierStringSchema }).readonly(),
21099
21073
  external_exports.object({
21100
21074
  ...identity,
@@ -21106,17 +21080,6 @@ var nativeSessionCommandSchema = external_exports.discriminatedUnion("action", [
21106
21080
  action: external_exports.enum(["import", "fork"]),
21107
21081
  entryId: identifierStringSchema,
21108
21082
  targetSessionId: identifierStringSchema
21109
- }).readonly(),
21110
- external_exports.object({
21111
- ...identity,
21112
- action: external_exports.literal("fork-recorded"),
21113
- targetSessionId: identifierStringSchema,
21114
- throughCommandId: identifierStringSchema
21115
- }).readonly(),
21116
- external_exports.object({
21117
- ...identity,
21118
- action: external_exports.literal("delete"),
21119
- entryId: identifierStringSchema
21120
21083
  }).readonly()
21121
21084
  ]);
21122
21085
  var nativeSessionEntrySchema = external_exports.object({
@@ -21134,7 +21097,6 @@ var resultEnvelope = {
21134
21097
  kind: external_exports.literal(NATIVE_SESSION_RESULT_KIND)
21135
21098
  };
21136
21099
  var nativeSessionResultSchema = external_exports.discriminatedUnion("action", [
21137
- external_exports.object({ ...resultEnvelope, action: external_exports.literal("create"), nativeSessionId: identifierStringSchema }).readonly(),
21138
21100
  external_exports.object({
21139
21101
  ...resultEnvelope,
21140
21102
  action: external_exports.literal("active-turn"),
@@ -21162,32 +21124,10 @@ var nativeSessionResultSchema = external_exports.discriminatedUnion("action", [
21162
21124
  }).readonly(),
21163
21125
  external_exports.object({
21164
21126
  ...resultEnvelope,
21165
- action: external_exports.enum(["import", "fork", "fork-recorded"]),
21127
+ action: external_exports.enum(["import", "fork"]),
21166
21128
  targetSessionId: identifierStringSchema,
21167
21129
  ready: sessionReadyEventSchema,
21168
21130
  title: external_exports.string().max(500)
21169
- }).readonly(),
21170
- external_exports.object({
21171
- ...resultEnvelope,
21172
- action: external_exports.literal("preview"),
21173
- entryId: identifierStringSchema,
21174
- targetSessionId: identifierStringSchema,
21175
- reason: external_exports.enum(["continuation_unavailable", "requested"]),
21176
- history: sessionHistorySchema,
21177
- title: external_exports.string().max(500)
21178
- }).readonly(),
21179
- external_exports.object({
21180
- ...resultEnvelope,
21181
- action: external_exports.literal("history"),
21182
- entryId: identifierStringSchema,
21183
- history: sessionHistorySchema,
21184
- title: external_exports.string().max(500)
21185
- }).readonly(),
21186
- external_exports.object({
21187
- ...resultEnvelope,
21188
- action: external_exports.literal("delete"),
21189
- entryId: identifierStringSchema,
21190
- deletedSessionIds: external_exports.array(identifierStringSchema).max(500).readonly()
21191
21131
  }).readonly()
21192
21132
  ]);
21193
21133
  var nativeSessionCancelSchema = external_exports.object({ ...envelope, kind: external_exports.literal(NATIVE_SESSION_CANCEL_KIND) }).readonly();
@@ -21753,28 +21693,9 @@ function decodeRecordedSessionEvent(encoded) {
21753
21693
  var encodeRecordedSessionEvent = (event) => JSON.stringify(decodeRecordedSessionEvent(JSON.stringify(event)));
21754
21694
 
21755
21695
  // ../protocol/src/session-live-history.ts
21756
- var SESSION_LIVE_HISTORY_PAGE_LOAD_KIND = "session.live-history.page.load";
21757
- var SESSION_LIVE_HISTORY_PAGE_LOADED_KIND = "session.live-history.page.loaded";
21758
21696
  var SESSION_LIVE_HISTORY_V2_PAGE_LOAD_KIND = "session.live-history.v2.page.load";
21759
21697
  var SESSION_LIVE_HISTORY_V2_PAGE_LOADED_KIND = "session.live-history.v2.page.loaded";
21760
21698
  var directoryIdentifier = external_exports.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,2047}$/);
21761
- var sessionLiveHistoryPageLoadSchema = external_exports.object({
21762
- additionalDirectoryIds: external_exports.array(directoryIdentifier).max(16).readonly(),
21763
- agentId: identifierStringSchema,
21764
- bindingId: identifierStringSchema,
21765
- cursor: external_exports.string().min(1).max(512).nullable(),
21766
- directoryId: directoryIdentifier,
21767
- kind: external_exports.literal(SESSION_LIVE_HISTORY_PAGE_LOAD_KIND),
21768
- limit: external_exports.number().int().min(1).max(100),
21769
- requestId: identifierStringSchema,
21770
- sessionId: identifierStringSchema
21771
- }).readonly();
21772
- var sessionLiveHistoryPageLoadedSchema = external_exports.object({
21773
- kind: external_exports.literal(SESSION_LIVE_HISTORY_PAGE_LOADED_KIND),
21774
- page: nativeMessagePageSchema,
21775
- requestId: identifierStringSchema,
21776
- sessionId: identifierStringSchema
21777
- }).readonly();
21778
21699
  var sessionLiveHistoryV2PageLoadSchema = external_exports.object({
21779
21700
  additionalDirectoryIds: external_exports.array(directoryIdentifier).max(16).readonly(),
21780
21701
  agentId: identifierStringSchema,
@@ -21800,10 +21721,6 @@ function decode7(schema, encoded) {
21800
21721
  throw new ProtocolMessageError("Invalid live Session history message", { cause });
21801
21722
  }
21802
21723
  }
21803
- var decodeSessionLiveHistoryPageLoad = (encoded) => decode7(sessionLiveHistoryPageLoadSchema, encoded);
21804
- var decodeSessionLiveHistoryPageLoaded = (encoded) => decode7(sessionLiveHistoryPageLoadedSchema, encoded);
21805
- var encodeSessionLiveHistoryPageLoad = (value) => JSON.stringify(sessionLiveHistoryPageLoadSchema.parse(value));
21806
- var encodeSessionLiveHistoryPageLoaded = (value) => JSON.stringify(sessionLiveHistoryPageLoadedSchema.parse(value));
21807
21724
  var decodeSessionLiveHistoryV2PageLoad = (encoded) => decode7(sessionLiveHistoryV2PageLoadSchema, encoded);
21808
21725
  var decodeSessionLiveHistoryV2PageLoaded = (encoded) => decode7(sessionLiveHistoryV2PageLoadedSchema, encoded);
21809
21726
  var encodeSessionLiveHistoryV2PageLoad = (value) => JSON.stringify(sessionLiveHistoryV2PageLoadSchema.parse(value));
@@ -21820,11 +21737,6 @@ function defineMessageSignature(kind, encoder, decoder) {
21820
21737
  };
21821
21738
  }
21822
21739
  var serviceToDaemonSignatures = {
21823
- [AGENT_CATALOG_REFRESH_KIND]: defineMessageSignature(
21824
- AGENT_CATALOG_REFRESH_KIND,
21825
- encodeAgentCatalogRefreshCommand,
21826
- decodeAgentCatalogRefreshCommand
21827
- ),
21828
21740
  [AGENT_INSTALL_CANCEL_KIND]: defineMessageSignature(
21829
21741
  AGENT_INSTALL_CANCEL_KIND,
21830
21742
  encodeAgentInstallCancelCommand,
@@ -21867,6 +21779,7 @@ var serviceToDaemonSignatures = {
21867
21779
  encodeRuntimeLivenessReadyEvent,
21868
21780
  decodeRuntimeLivenessReadyEvent
21869
21781
  ),
21782
+ [RUNTIME_PING_KIND]: defineMessageSignature(RUNTIME_PING_KIND, encodeRuntimePingCommand, decodeRuntimePingCommand),
21870
21783
  [SESSION_CANCEL_KIND]: defineMessageSignature(
21871
21784
  SESSION_CANCEL_KIND,
21872
21785
  encodeSessionCancelCommand,
@@ -21882,11 +21795,6 @@ var serviceToDaemonSignatures = {
21882
21795
  encodeSessionElicitationRespondCommand,
21883
21796
  decodeSessionElicitationRespondCommand
21884
21797
  ),
21885
- [SESSION_LIVE_HISTORY_PAGE_LOAD_KIND]: defineMessageSignature(
21886
- SESSION_LIVE_HISTORY_PAGE_LOAD_KIND,
21887
- encodeSessionLiveHistoryPageLoad,
21888
- decodeSessionLiveHistoryPageLoad
21889
- ),
21890
21798
  [SESSION_LIVE_HISTORY_V2_PAGE_LOAD_KIND]: defineMessageSignature(
21891
21799
  SESSION_LIVE_HISTORY_V2_PAGE_LOAD_KIND,
21892
21800
  encodeSessionLiveHistoryV2PageLoad,
@@ -21928,16 +21836,6 @@ function decodeServiceToDaemonMessage(encoded) {
21928
21836
  return signature.decoder(encoded);
21929
21837
  }
21930
21838
  var daemonToServiceSignatures = {
21931
- [AGENT_CATALOG_REFRESHED_KIND]: defineMessageSignature(
21932
- AGENT_CATALOG_REFRESHED_KIND,
21933
- encodeAgentCatalogRefreshedEvent,
21934
- decodeAgentCatalogRefreshedEvent
21935
- ),
21936
- [AGENT_CATALOG_REFRESH_FAILED_KIND]: defineMessageSignature(
21937
- AGENT_CATALOG_REFRESH_FAILED_KIND,
21938
- encodeAgentCatalogRefreshFailedEvent,
21939
- decodeAgentCatalogRefreshFailedEvent
21940
- ),
21941
21839
  [AGENT_INSTALL_CANCELLED_KIND]: defineMessageSignature(
21942
21840
  AGENT_INSTALL_CANCELLED_KIND,
21943
21841
  encodeAgentInstallCancelledEvent,
@@ -22007,6 +21905,7 @@ var daemonToServiceSignatures = {
22007
21905
  encodeRuntimeHeartbeatEvent,
22008
21906
  decodeRuntimeHeartbeatEvent
22009
21907
  ),
21908
+ [RUNTIME_PONG_KIND]: defineMessageSignature(RUNTIME_PONG_KIND, encodeRuntimePongEvent, decodeRuntimePongEvent),
22010
21909
  [SESSION_EVENT_KIND]: defineMessageSignature(
22011
21910
  SESSION_EVENT_KIND,
22012
21911
  encodeSessionEventEnvelope,
@@ -22022,11 +21921,6 @@ var daemonToServiceSignatures = {
22022
21921
  encodeSessionOperationFailedEvent,
22023
21922
  decodeSessionOperationFailedEvent
22024
21923
  ),
22025
- [SESSION_LIVE_HISTORY_PAGE_LOADED_KIND]: defineMessageSignature(
22026
- SESSION_LIVE_HISTORY_PAGE_LOADED_KIND,
22027
- encodeSessionLiveHistoryPageLoaded,
22028
- decodeSessionLiveHistoryPageLoaded
22029
- ),
22030
21924
  [SESSION_LIVE_HISTORY_V2_PAGE_LOADED_KIND]: defineMessageSignature(
22031
21925
  SESSION_LIVE_HISTORY_V2_PAGE_LOADED_KIND,
22032
21926
  encodeSessionLiveHistoryV2PageLoaded,
@@ -30168,6 +30062,10 @@ var acpSessionStoreMigrations = [
30168
30062
  {
30169
30063
  "name": "0003_silky_ravenous.sql",
30170
30064
  "sql": "DROP TABLE `session_event_v2`;"
30065
+ },
30066
+ {
30067
+ "name": "0004_special_mathemanic.sql",
30068
+ "sql": "DROP TABLE `deleted_acp_session`;--> statement-breakpoint\nALTER TABLE `acp_session` DROP COLUMN `last_terminal_command_id`;"
30171
30069
  }
30172
30070
  ];
30173
30071
 
@@ -30178,33 +30076,25 @@ var acpSession = sqliteTable("acp_session", {
30178
30076
  nativeSessionId: text("native_session_id").notNull(),
30179
30077
  cwd: text("cwd").notNull(),
30180
30078
  additionalDirectories: text("additional_directories").notNull(),
30181
- lastTerminalCommandId: text("last_terminal_command_id"),
30182
30079
  prompted: integer2("prompted", { mode: "boolean" }).notNull(),
30183
30080
  title: text("title").notNull(),
30184
30081
  updatedAt: text("updated_at").notNull()
30185
30082
  });
30186
30083
 
30187
- // src/schema/acp-session-store/deleted-acp-session.ts
30188
- var deletedAcpSession = sqliteTable("deleted_acp_session", {
30189
- sessionId: text("session_id").primaryKey()
30190
- });
30191
-
30192
30084
  // src/acp/session-store.ts
30193
30085
  var AcpStoredSession = class {
30194
30086
  additionalDirectories;
30195
30087
  agentId;
30196
30088
  cwd;
30197
- lastTerminalCommandId;
30198
30089
  nativeSessionId;
30199
30090
  prompted;
30200
30091
  sessionId;
30201
30092
  title;
30202
30093
  updatedAt;
30203
- constructor(sessionId, agentId, nativeSessionId, cwd, additionalDirectories, prompted, title2, updatedAt = (/* @__PURE__ */ new Date()).toISOString(), lastTerminalCommandId = null) {
30094
+ constructor(sessionId, agentId, nativeSessionId, cwd, additionalDirectories, prompted, title2, updatedAt = (/* @__PURE__ */ new Date()).toISOString()) {
30204
30095
  this.additionalDirectories = [...additionalDirectories];
30205
30096
  this.agentId = agentId;
30206
30097
  this.cwd = cwd;
30207
- this.lastTerminalCommandId = lastTerminalCommandId;
30208
30098
  this.nativeSessionId = nativeSessionId;
30209
30099
  this.prompted = prompted;
30210
30100
  this.sessionId = sessionId;
@@ -30225,32 +30115,16 @@ var FoundAcpStoredSession = class extends AcpStoredSessionLookup {
30225
30115
  this.session = session;
30226
30116
  }
30227
30117
  };
30228
- var DeletedAcpStoredSession = class extends AcpStoredSessionLookup {
30229
- found = false;
30230
- };
30231
30118
  var MemoryAcpSessionStore = class {
30232
30119
  #sessions = /* @__PURE__ */ new Map();
30233
- #deleted = /* @__PURE__ */ new Set();
30234
30120
  close = () => {
30235
30121
  this.#sessions.clear();
30236
- this.#deleted.clear();
30237
30122
  };
30238
30123
  findNative = (agentId, nativeSessionId) => [...this.#sessions.values()].filter(
30239
30124
  (session) => session.agentId === agentId && session.nativeSessionId === nativeSessionId
30240
30125
  );
30241
30126
  list = () => [...this.#sessions.values()].toSorted((left, right) => right.updatedAt.localeCompare(left.updatedAt));
30242
- markDeleted = (agentId, nativeSessionId) => {
30243
- const ids = this.findNative(agentId, nativeSessionId).map((session) => session.sessionId);
30244
- for (const id of ids) {
30245
- this.#sessions.delete(id);
30246
- this.#deleted.add(id);
30247
- }
30248
- return ids;
30249
- };
30250
30127
  read = (sessionId) => {
30251
- if (this.#deleted.has(sessionId)) {
30252
- return new DeletedAcpStoredSession();
30253
- }
30254
30128
  const session = this.#sessions.get(sessionId);
30255
30129
  return session === void 0 ? new MissingAcpStoredSession() : new FoundAcpStoredSession(session);
30256
30130
  };
@@ -30265,14 +30139,12 @@ var storedSessionRowSchema = external_exports.object({
30265
30139
  additionalDirectories: external_exports.string(),
30266
30140
  agentId: external_exports.string(),
30267
30141
  cwd: external_exports.string(),
30268
- lastTerminalCommandId: external_exports.string().nullable(),
30269
30142
  nativeSessionId: external_exports.string(),
30270
30143
  prompted: external_exports.boolean(),
30271
30144
  sessionId: external_exports.string(),
30272
30145
  title: external_exports.string(),
30273
30146
  updatedAt: external_exports.string()
30274
30147
  });
30275
- var sessionIdRowSchema = external_exports.object({ sessionId: external_exports.string() });
30276
30148
  function decodeStoredSession(value) {
30277
30149
  const row = storedSessionRowSchema.parse(value);
30278
30150
  const decodedAdditionalDirectories = JSON.parse(row.additionalDirectories);
@@ -30285,8 +30157,7 @@ function decodeStoredSession(value) {
30285
30157
  additionalDirectories,
30286
30158
  row.prompted,
30287
30159
  row.title,
30288
- row.updatedAt,
30289
- row.lastTerminalCommandId
30160
+ row.updatedAt
30290
30161
  );
30291
30162
  }
30292
30163
  var SqliteAcpSessionStore = class {
@@ -30321,37 +30192,12 @@ var SqliteAcpSessionStore = class {
30321
30192
  }
30322
30193
  }
30323
30194
  };
30324
- #transaction = (operation) => {
30325
- this.#sqliteDatabase.exec("BEGIN IMMEDIATE");
30326
- try {
30327
- operation();
30328
- this.#sqliteDatabase.exec("COMMIT");
30329
- } catch (error62) {
30330
- this.#sqliteDatabase.exec("ROLLBACK");
30331
- throw error62;
30332
- }
30333
- };
30334
30195
  close = () => {
30335
30196
  this.#sqliteDatabase.close();
30336
30197
  };
30337
30198
  findNative = (agentId, nativeSessionId) => this.#database.select().from(acpSession).where(and(eq(acpSession.agentId, agentId), eq(acpSession.nativeSessionId, nativeSessionId))).all().map(decodeStoredSession);
30338
30199
  list = () => this.#database.select().from(acpSession).orderBy(desc(acpSession.updatedAt)).all().map(decodeStoredSession);
30339
- markDeleted = (agentId, nativeSessionId) => {
30340
- const ids = this.#database.select({ sessionId: acpSession.sessionId }).from(acpSession).where(and(eq(acpSession.agentId, agentId), eq(acpSession.nativeSessionId, nativeSessionId))).all().map((row) => sessionIdRowSchema.parse(row).sessionId);
30341
- this.#transaction(() => {
30342
- this.#database.delete(acpSession).where(and(eq(acpSession.agentId, agentId), eq(acpSession.nativeSessionId, nativeSessionId))).run();
30343
- for (const id of ids) {
30344
- this.#database.insert(deletedAcpSession).values({ sessionId: id }).onConflictDoNothing().run();
30345
- }
30346
- });
30347
- return ids;
30348
- };
30349
30200
  read = (sessionId) => {
30350
- const deleted = this.#database.select({ sessionId: deletedAcpSession.sessionId }).from(deletedAcpSession).where(eq(deletedAcpSession.sessionId, sessionId)).get();
30351
- if (deleted !== void 0) {
30352
- sessionIdRowSchema.parse(deleted);
30353
- return new DeletedAcpStoredSession();
30354
- }
30355
30201
  const row = this.#database.select().from(acpSession).where(eq(acpSession.sessionId, sessionId)).get();
30356
30202
  return row === void 0 ? new MissingAcpStoredSession() : new FoundAcpStoredSession(decodeStoredSession(row));
30357
30203
  };
@@ -30363,20 +30209,13 @@ var SqliteAcpSessionStore = class {
30363
30209
  additionalDirectories: JSON.stringify(session.additionalDirectories),
30364
30210
  agentId: session.agentId,
30365
30211
  cwd: session.cwd,
30366
- lastTerminalCommandId: session.lastTerminalCommandId,
30367
30212
  nativeSessionId: session.nativeSessionId,
30368
30213
  prompted: session.prompted,
30369
30214
  sessionId: session.sessionId,
30370
30215
  title: session.title,
30371
30216
  updatedAt: session.updatedAt
30372
30217
  };
30373
- this.#transaction(() => {
30374
- this.#database.delete(deletedAcpSession).where(eq(deletedAcpSession.sessionId, session.sessionId)).run();
30375
- this.#database.insert(acpSession).values(value).onConflictDoUpdate({
30376
- target: acpSession.sessionId,
30377
- set: value
30378
- }).run();
30379
- });
30218
+ this.#database.insert(acpSession).values(value).onConflictDoUpdate({ target: acpSession.sessionId, set: value }).run();
30380
30219
  };
30381
30220
  };
30382
30221
 
@@ -30417,7 +30256,6 @@ var AgentSession = class _AgentSession {
30417
30256
  #commands = [];
30418
30257
  #configRevision = 0;
30419
30258
  #configOptions = [];
30420
- #lastTerminalCommandId = null;
30421
30259
  #nativeHistoryOwnership = { kind: "unbound" };
30422
30260
  #prompted = false;
30423
30261
  #nativePrompt = null;
@@ -30730,13 +30568,6 @@ var AgentSession = class _AgentSession {
30730
30568
  this.#store.remove(this.#mobiusSessionId);
30731
30569
  stored = this.#metrics.measureSync("session-state-read", () => this.#store.read(this.#mobiusSessionId));
30732
30570
  }
30733
- if (stored instanceof DeletedAcpStoredSession) {
30734
- throw new AcpExecutionError(
30735
- "The native Agent session was deleted. Start a new chat.",
30736
- {},
30737
- "native_session_deleted"
30738
- );
30739
- }
30740
30571
  let lifecycleResponse;
30741
30572
  if (origin?.kind === "fork") {
30742
30573
  if (!this.#capabilities.unstableForkSession) {
@@ -30784,7 +30615,6 @@ var AgentSession = class _AgentSession {
30784
30615
  } else if (stored instanceof FoundAcpStoredSession && stored.session.agentId === this.#agentId && stored.session.cwd === this.#cwd && arraysEqual(stored.session.additionalDirectories, this.#additionalDirectories)) {
30785
30616
  this.selectNativeSession(stored.session.nativeSessionId);
30786
30617
  this.#prompted = stored.session.prompted;
30787
- this.#lastTerminalCommandId = stored.session.lastTerminalCommandId;
30788
30618
  this.#sessionTitle = stored.session.title;
30789
30619
  this.#restored = true;
30790
30620
  if (this.#capabilities.resumeSession) {
@@ -30860,8 +30690,7 @@ var AgentSession = class _AgentSession {
30860
30690
  this.#additionalDirectories,
30861
30691
  this.#prompted,
30862
30692
  this.#sessionTitle ?? "",
30863
- (/* @__PURE__ */ new Date()).toISOString(),
30864
- this.#lastTerminalCommandId
30693
+ (/* @__PURE__ */ new Date()).toISOString()
30865
30694
  )
30866
30695
  );
30867
30696
  };
@@ -30890,24 +30719,6 @@ var AgentSession = class _AgentSession {
30890
30719
  }
30891
30720
  return decoded.data;
30892
30721
  };
30893
- deleteNativeSession = async (nativeSessionId, signal) => {
30894
- if (!this.#capabilities.deleteSession || !this.#capabilities.listSessions) {
30895
- throw new AcpExecutionError(
30896
- "This Agent does not support native session deletion",
30897
- {},
30898
- "native_session_unsupported"
30899
- );
30900
- }
30901
- await this.race(
30902
- this.#connection.connection.agent.request(
30903
- methods3.agent.session.delete,
30904
- { sessionId: nativeSessionIdSchema.parse(nativeSessionId) },
30905
- { cancellationSignal: signal }
30906
- ),
30907
- "ACP agent exited while deleting a session",
30908
- signal
30909
- );
30910
- };
30911
30722
  nativeSessionId = () => this.#updates.sessionId();
30912
30723
  adoptNativeSessionId = (sessionId) => {
30913
30724
  if (this.#prompted || this.#updates.sessionId() !== sessionId) {
@@ -31063,8 +30874,7 @@ var AgentSession = class _AgentSession {
31063
30874
  this.#additionalDirectories,
31064
30875
  true,
31065
30876
  this.#sessionTitle,
31066
- (/* @__PURE__ */ new Date()).toISOString(),
31067
- this.#lastTerminalCommandId
30877
+ (/* @__PURE__ */ new Date()).toISOString()
31068
30878
  )
31069
30879
  );
31070
30880
  this.#prompted = true;
@@ -31133,7 +30943,6 @@ var AgentSession = class _AgentSession {
31133
30943
  usage: result.usage ?? null
31134
30944
  });
31135
30945
  }
31136
- this.#lastTerminalCommandId = options.commandId;
31137
30946
  this.#store.write(
31138
30947
  new AcpStoredSession(
31139
30948
  this.#mobiusSessionId,
@@ -31143,8 +30952,7 @@ var AgentSession = class _AgentSession {
31143
30952
  this.#additionalDirectories,
31144
30953
  true,
31145
30954
  this.#sessionTitle ?? "",
31146
- (/* @__PURE__ */ new Date()).toISOString(),
31147
- this.#lastTerminalCommandId
30955
+ (/* @__PURE__ */ new Date()).toISOString()
31148
30956
  )
31149
30957
  );
31150
30958
  if (lifecycleV2 !== void 0) {
@@ -31432,8 +31240,7 @@ var AgentSession = class _AgentSession {
31432
31240
  this.#additionalDirectories,
31433
31241
  this.#prompted,
31434
31242
  this.#sessionTitle ?? "",
31435
- (/* @__PURE__ */ new Date()).toISOString(),
31436
- this.#lastTerminalCommandId
31243
+ (/* @__PURE__ */ new Date()).toISOString()
31437
31244
  )
31438
31245
  );
31439
31246
  }
@@ -32125,9 +31932,6 @@ var LocalExternalContentStore = class {
32125
31932
  };
32126
31933
 
32127
31934
  // src/native-sessions/chat-agent.ts
32128
- function supportsNativeChat(agentId) {
32129
- return agentId === "codex" || agentId === "claude" || agentId === "opencode" || agentId === "pi";
32130
- }
32131
31935
  function isNativeChatSessionId(agentId, sessionId) {
32132
31936
  if (!nativeSessionIdSchema.safeParse(sessionId).success) {
32133
31937
  return false;
@@ -32477,13 +32281,6 @@ var AgentRuntimeManager = class {
32477
32281
  }
32478
32282
  prepareSession = async (options, metrics = unmeasuredOperationMetrics) => this.#operations.run(options, async (options2) => {
32479
32283
  const stored = metrics.measureSync("session-state-read", () => this.#store.read(options2.sessionId));
32480
- if (stored instanceof DeletedAcpStoredSession) {
32481
- throw new AcpExecutionError(
32482
- "The native Agent session was deleted. Start a new chat.",
32483
- {},
32484
- "native_session_deleted"
32485
- );
32486
- }
32487
32284
  if (stored instanceof FoundAcpStoredSession && this.#nativeOperations.has(`${stored.session.agentId}:${stored.session.nativeSessionId}`)) {
32488
32285
  throw new AcpExecutionError("The native session is being managed", {}, "session_busy");
32489
32286
  }
@@ -32932,7 +32729,7 @@ var AgentRuntimeManager = class {
32932
32729
  }
32933
32730
  });
32934
32731
  }
32935
- if (this.#executionProcesses.get(options2.sessionId) !== void 0 || this.#executionProcesses.pending(options2.sessionId) !== void 0 || this.#store.read(options2.sessionId) instanceof FoundAcpStoredSession || this.#store.read(options2.sessionId) instanceof DeletedAcpStoredSession) {
32732
+ if (this.#executionProcesses.get(options2.sessionId) !== void 0 || this.#executionProcesses.pending(options2.sessionId) !== void 0 || this.#store.read(options2.sessionId) instanceof FoundAcpStoredSession) {
32936
32733
  throw new AcpExecutionError(
32937
32734
  "The destination conversation already exists",
32938
32735
  {},
@@ -32978,40 +32775,6 @@ var AgentRuntimeManager = class {
32978
32775
  }
32979
32776
  });
32980
32777
  });
32981
- deleteNativeSession = async (options, nativeSessionId) => this.#operations.run(options, async (options2) => {
32982
- return await this.#queryProcesses.use(options2, async (runtime) => {
32983
- const key = `${options2.agent.id}:${nativeSessionId}`;
32984
- const linked = this.#store.findNative(options2.agent.id, nativeSessionId);
32985
- if (this.#nativeOperations.has(key) || linked.some(
32986
- (entry) => this.#executions.command(entry.sessionId) !== void 0 || this.#executionProcesses.pending(entry.sessionId) !== void 0
32987
- )) {
32988
- throw new AcpExecutionError(
32989
- "Wait for the native session's running operation to finish",
32990
- {},
32991
- "session_busy"
32992
- );
32993
- }
32994
- this.#nativeOperations.add(key);
32995
- try {
32996
- for (const entry of linked) {
32997
- const active = this.#executionProcesses.get(entry.sessionId);
32998
- if (active !== void 0 && active !== runtime) {
32999
- await this.#retireSessionProcess(entry.sessionId, active, async () => await active.close());
33000
- }
33001
- }
33002
- options2.signal.throwIfAborted();
33003
- await runtime.deleteNativeSession(nativeSessionId, options2.signal);
33004
- const deleted = this.#store.markDeleted(options2.agent.id, nativeSessionId);
33005
- if (runtime.nativeSessionId() === nativeSessionId) {
33006
- await this.#queryProcesses.retire(options2.sessionId, runtime);
33007
- }
33008
- return deleted;
33009
- } finally {
33010
- this.#nativeOperations.delete(key);
33011
- this.#processes.notifyChanged();
33012
- }
33013
- });
33014
- });
33015
32778
  };
33016
32779
 
33017
32780
  // src/acp/run-prompt.ts
@@ -40473,7 +40236,6 @@ async function readCodexHistoryWithOptions(agent, cwd, nativeSessionId, signal,
40473
40236
  child2.removeListener("exit", onExit);
40474
40237
  }
40475
40238
  }
40476
- var readCodexHistory = async (agent, cwd, nativeSessionId, signal) => await readCodexHistoryWithOptions(agent, cwd, nativeSessionId, signal, { detail: "messages" });
40477
40239
  var readCodexFullHistory = async (agent, cwd, nativeSessionId, signal, nativeTurn) => await readCodexHistoryWithOptions(agent, cwd, nativeSessionId, signal, {
40478
40240
  detail: "rich",
40479
40241
  ...nativeTurn === void 0 ? {} : { nativeTurn }
@@ -40481,85 +40243,6 @@ var readCodexFullHistory = async (agent, cwd, nativeSessionId, signal, nativeTur
40481
40243
 
40482
40244
  // src/native-sessions/service.ts
40483
40245
  import { randomUUID as randomUUID4 } from "node:crypto";
40484
- import { basename as basename5 } from "node:path";
40485
-
40486
- // src/native-sessions/acp-history.ts
40487
- async function readAcpHistory(sessions, directories, bindingId, options, nativeSessionId) {
40488
- let cursor = null;
40489
- let inspected = 0;
40490
- for (let pageNumber = 0; pageNumber < 500 && inspected < 500; pageNumber += 1) {
40491
- const page = await sessions.listNativeSessions(options, cursor);
40492
- inspected += page.sessions.length;
40493
- const found = page.sessions.find((entry) => entry.sessionId === nativeSessionId);
40494
- if (found !== void 0) {
40495
- const primary = await directories.identify(bindingId, found.cwd, options.signal);
40496
- const additional = await Promise.all(
40497
- found.additionalDirectories.map(
40498
- async (directory) => await directories.identify(bindingId, directory, options.signal)
40499
- )
40500
- );
40501
- if (primary.path !== options.cwd || additional.length !== options.additionalDirectories.length || additional.some((directory, index) => directory.path !== options.additionalDirectories[index])) {
40502
- throw new AcpExecutionError(
40503
- "The native Session belongs to another workspace.",
40504
- {},
40505
- "session_identity_mismatch"
40506
- );
40507
- }
40508
- return await sessions.previewNativeSession(options, nativeSessionId);
40509
- }
40510
- if (page.nextCursor === null || page.nextCursor === cursor) {
40511
- break;
40512
- }
40513
- cursor = page.nextCursor ?? null;
40514
- }
40515
- throw new AcpExecutionError("The native Session was not found.", {}, "native_session_not_found");
40516
- }
40517
-
40518
- // src/native-sessions/acp-adapter.ts
40519
- var acpSessionAdapter = {
40520
- history: async ({ sessions, directories, bindingId, options, nativeSessionId }) => await readAcpHistory(sessions, directories, bindingId, options, nativeSessionId),
40521
- preview: async ({ sessions, options, nativeSessionId }) => await sessions.previewNativeSession(options, nativeSessionId)
40522
- };
40523
-
40524
- // src/native-sessions/codex-adapter.ts
40525
- async function verifiedHistory(context, full) {
40526
- const { options, nativeSessionId, directories, bindingId } = context;
40527
- const snapshot = full ? await readCodexFullHistory(options.agent, options.cwd, nativeSessionId, options.signal) : await readCodexHistory(options.agent, options.cwd, nativeSessionId, options.signal);
40528
- const resolved = await directories.identify(bindingId, snapshot.cwd, options.signal);
40529
- if (snapshot.nativeSessionId !== nativeSessionId || resolved.path !== options.cwd) {
40530
- throw new AcpExecutionError(
40531
- "Codex returned history for a different session or workspace.",
40532
- {},
40533
- "invalid_native_session_response"
40534
- );
40535
- }
40536
- return snapshot.history;
40537
- }
40538
- var codexSessionAdapter = {
40539
- history: async (context) => await verifiedHistory(context, true),
40540
- // Codex enforces an exclusive writer per thread. Its read-only app-server
40541
- // history path keeps externally owned conversations previewable.
40542
- preview: async (context) => await verifiedHistory(context, false)
40543
- };
40544
-
40545
- // src/native-sessions/agent-adapter.ts
40546
- var genericSessionAdapter = {
40547
- history: async () => {
40548
- throw new AcpExecutionError("Native history is unavailable for this Agent", {}, "native_session_unsupported");
40549
- },
40550
- preview: async ({ sessions, options, nativeSessionId }) => await sessions.previewNativeSession(options, nativeSessionId)
40551
- };
40552
- function nativeSessionAdapter(agentId) {
40553
- if (agentId === "codex") {
40554
- return codexSessionAdapter;
40555
- }
40556
- if (agentId === "claude" || agentId === "opencode" || agentId === "pi") {
40557
- return acpSessionAdapter;
40558
- }
40559
- return genericSessionAdapter;
40560
- }
40561
-
40562
- // src/native-sessions/service.ts
40563
40246
  var NativeSessionService = class {
40564
40247
  #entries = /* @__PURE__ */ new Map();
40565
40248
  #cursors = /* @__PURE__ */ new Map();
@@ -40603,83 +40286,6 @@ var NativeSessionService = class {
40603
40286
  ...await this.#activeTurn(command, options)
40604
40287
  };
40605
40288
  }
40606
- if (command.action === "create") {
40607
- if (!supportsNativeChat(options.agent.id)) {
40608
- throw new AcpExecutionError(
40609
- "Native session creation is unavailable for this Agent",
40610
- {},
40611
- "native_session_unsupported"
40612
- );
40613
- }
40614
- const nativeSessionId = await this.#sessions.createNativeSession(options);
40615
- signal.throwIfAborted();
40616
- this.record(command, "native_session_created");
40617
- return {
40618
- action: "create",
40619
- kind: "native.session.result",
40620
- nativeSessionId: decodeIdentifier(nativeSessionId),
40621
- requestId: command.requestId,
40622
- sessionId: command.sessionId
40623
- };
40624
- }
40625
- if (command.action === "fork-recorded") {
40626
- const source = this.#sessions.findSessions([command.sessionId])[0];
40627
- if (source === void 0 || !source.prompted) {
40628
- throw new AcpExecutionError(
40629
- "The source conversation has no resumable native Agent session",
40630
- {},
40631
- "native_session_not_found"
40632
- );
40633
- }
40634
- if (source.agentId !== command.agentId || source.cwd !== cwd || source.additionalDirectories.length !== additionalDirectories.length || source.additionalDirectories.some((path2, index) => path2 !== additionalDirectories[index])) {
40635
- throw new AcpExecutionError(
40636
- "The source conversation execution target does not match the fork request",
40637
- {},
40638
- "native_session_target_changed"
40639
- );
40640
- }
40641
- if (source.lastTerminalCommandId !== command.throughCommandId) {
40642
- throw new AcpExecutionError(
40643
- "The selected Turn is no longer the source conversation head",
40644
- {},
40645
- "fork_point_stale"
40646
- );
40647
- }
40648
- const opened2 = await this.#sessions.openNativeSession(
40649
- { ...options, sessionId: command.targetSessionId },
40650
- { kind: "fork", nativeSessionId: source.nativeSessionId }
40651
- );
40652
- signal.throwIfAborted();
40653
- const directory = await this.#directories.list(this.#config.bindingId, command.directoryId, signal);
40654
- const ready2 = {
40655
- additionalDirectories: additionalDirectories.map((path2, index) => ({
40656
- directoryId: command.additionalDirectoryIds[index] ?? command.directoryId,
40657
- name: basename5(path2) || path2
40658
- })),
40659
- agentId: command.agentId,
40660
- agentName: opened2.prepared.agentName,
40661
- agentVersion: opened2.prepared.agentVersion,
40662
- capabilities: opened2.prepared.capabilities,
40663
- commands: opened2.prepared.commands,
40664
- configOptions: opened2.prepared.configOptions,
40665
- directoryId: command.directoryId,
40666
- directoryLabel: directory.directoryLabel,
40667
- kind: "session.ready",
40668
- requestId: command.requestId,
40669
- restored: true,
40670
- sessionId: opened2.sessionId
40671
- };
40672
- this.record(command, "native_recorded_session_forked");
40673
- return {
40674
- action: "fork-recorded",
40675
- kind: "native.session.result",
40676
- ready: ready2,
40677
- requestId: command.requestId,
40678
- sessionId: command.sessionId,
40679
- targetSessionId: command.targetSessionId,
40680
- title: source.title || "Untitled session"
40681
- };
40682
- }
40683
40289
  const prepared = await this.#sessions.prepareNativeSessionBrowser(options);
40684
40290
  if (!prepared.capabilities.listSessions) {
40685
40291
  throw new AcpExecutionError(
@@ -40814,63 +40420,6 @@ var NativeSessionService = class {
40814
40420
  );
40815
40421
  }
40816
40422
  const target = await this.resolveTarget(command, options, selected);
40817
- if (command.action === "history") {
40818
- const history = await nativeSessionAdapter(options.agent.id).history({
40819
- sessions: this.#sessions,
40820
- directories: this.#directories,
40821
- bindingId: command.bindingId,
40822
- options: { ...options, cwd: target.cwd, additionalDirectories: target.additionalDirectories },
40823
- nativeSessionId: target.info.sessionId
40824
- });
40825
- signal.throwIfAborted();
40826
- this.record(command, "native_session_history_read");
40827
- return {
40828
- ...envelope2,
40829
- action: "history",
40830
- entryId: command.entryId,
40831
- history,
40832
- title: target.info.title ?? "Untitled session"
40833
- };
40834
- }
40835
- if (command.action === "preview") {
40836
- const history = await nativeSessionAdapter(options.agent.id).preview({
40837
- sessions: this.#sessions,
40838
- directories: this.#directories,
40839
- bindingId: command.bindingId,
40840
- options: { ...options, cwd: target.cwd, additionalDirectories: target.additionalDirectories },
40841
- nativeSessionId: target.info.sessionId
40842
- });
40843
- signal.throwIfAborted();
40844
- this.record(command, "native_session_previewed");
40845
- return {
40846
- ...envelope2,
40847
- action: "preview",
40848
- entryId: command.entryId,
40849
- targetSessionId: command.sessionId,
40850
- reason: "requested",
40851
- title: target.info.title ?? "Untitled session",
40852
- history
40853
- };
40854
- }
40855
- if (command.action === "delete") {
40856
- if (!prepared.capabilities.deleteSession) {
40857
- throw new AcpExecutionError(
40858
- "This Agent does not support native session deletion",
40859
- {},
40860
- "native_session_unsupported"
40861
- );
40862
- }
40863
- signal.throwIfAborted();
40864
- this.record(command, "native_session_delete_authorized");
40865
- const deletedSessionIds = await this.#sessions.deleteNativeSession(options, target.info.sessionId);
40866
- this.record(command, "native_session_deleted");
40867
- return {
40868
- ...envelope2,
40869
- action: "delete",
40870
- entryId: command.entryId,
40871
- deletedSessionIds: deletedSessionIds.map(decodeIdentifier)
40872
- };
40873
- }
40874
40423
  const action = command.action;
40875
40424
  if (action === "import" && !prepared.capabilities.loadSession && !prepared.capabilities.resumeSession) {
40876
40425
  throw new AcpExecutionError("This Agent cannot import native sessions", {}, "native_session_unsupported");
@@ -41255,135 +40804,13 @@ var RelayConnectionDiagnostics = class {
41255
40804
  };
41256
40805
 
41257
40806
  // src/relay-connection/run-relay-connection.ts
41258
- import { WebSocket as WebSocket8 } from "undici";
40807
+ import { WebSocket as WebSocket7 } from "undici";
41259
40808
 
41260
40809
  // src/daemon-command-handler.ts
41261
- import { WebSocket as WebSocket6 } from "undici";
41262
-
41263
- // src/agent-catalog/handle-agent-catalog-refresh.ts
41264
- import { WebSocket as WebSocket3 } from "undici";
41265
- async function retainStillInstalledAgents(previous, refreshed, signal) {
41266
- const refreshedIdentifiers = new Set(refreshed.map((agent) => agent.id));
41267
- const retained = [];
41268
- for (const agent of previous) {
41269
- if (refreshedIdentifiers.has(agent.id)) {
41270
- continue;
41271
- }
41272
- signal.throwIfAborted();
41273
- if (await revalidateExecutable(agent.agentIdentity)) {
41274
- retained.push(agent);
41275
- }
41276
- }
41277
- return Object.freeze([...refreshed, ...retained]);
41278
- }
41279
- async function refreshAgentCatalog(config2, resolveEnvironment, signal) {
41280
- signal.throwIfAborted();
41281
- const shellEnvironment = await resolveEnvironment(signal);
41282
- const environment = new DaemonLocalContext(config2.localContext.stateDirectory, shellEnvironment).environment;
41283
- signal.throwIfAborted();
41284
- const inventory = await discoverLocalAgentInventory({
41285
- defaultWorkspace: config2.defaultWorkspace,
41286
- environment,
41287
- signal
41288
- });
41289
- const previousCatalog = config2.catalog.read();
41290
- const refreshedAgents = inventory.readyAgents().map((agent) => withDaemonEnvironment(agent, environment));
41291
- const agents = await retainStillInstalledAgents(previousCatalog.agents, refreshedAgents, signal);
41292
- const verifiedIdentifiers = new Set(agents.map((agent) => agent.id));
41293
- config2.catalog.transition(
41294
- agents,
41295
- inventory.installable.filter((agent) => !verifiedIdentifiers.has(agent.id))
41296
- );
41297
- try {
41298
- await publishAgentCatalog(config2, signal);
41299
- } catch (error62) {
41300
- config2.catalog.transition(previousCatalog.agents, previousCatalog.installableAgents);
41301
- throw error62;
41302
- }
41303
- }
41304
- function createAgentCatalogRefreshHandler(dependencies) {
41305
- const { config: config2, audit, diagnostics, socket, signal, timer, resolveEnvironment } = dependencies;
41306
- const agentCatalogRefreshes = /* @__PURE__ */ new Map();
41307
- const handle = (command) => {
41308
- if (agentCatalogRefreshes.has(command.requestId) || agentCatalogRefreshes.size > 0) {
41309
- if (socket.readyState === WebSocket3.OPEN) {
41310
- send(socket, {
41311
- code: "agent_catalog_refresh_busy",
41312
- kind: AGENT_CATALOG_REFRESH_FAILED_KIND,
41313
- message: "Another local Agent catalog refresh is already running",
41314
- requestId: command.requestId
41315
- });
41316
- }
41317
- return;
41318
- }
41319
- const controller = new AbortController();
41320
- const operationSignal = AbortSignal.any([signal, controller.signal]);
41321
- const timeout = timer.schedule(
41322
- () => controller.abort(
41323
- new AcpExecutionError(
41324
- "The local Agent catalog refresh timed out",
41325
- {},
41326
- "agent_catalog_refresh_timeout"
41327
- )
41328
- ),
41329
- 9e4
41330
- );
41331
- const completion = (async () => {
41332
- try {
41333
- await refreshAgentCatalog(config2, resolveEnvironment, operationSignal);
41334
- audit.record({
41335
- commandId: command.requestId,
41336
- event: "agent_catalog_refreshed",
41337
- sessionId: "agent-catalog"
41338
- });
41339
- if (socket.readyState === WebSocket3.OPEN) {
41340
- send(socket, {
41341
- kind: AGENT_CATALOG_REFRESHED_KIND,
41342
- requestId: command.requestId
41343
- });
41344
- }
41345
- } catch (error62) {
41346
- const failure2 = operationSignal.aborted ? controller.signal.reason ?? new AcpExecutionError(
41347
- "The local Agent catalog refresh was cancelled",
41348
- {},
41349
- "agent_catalog_refresh_cancelled"
41350
- ) : error62;
41351
- audit.record({
41352
- commandId: command.requestId,
41353
- details: { code: operationErrorCode(failure2) },
41354
- event: "agent_catalog_refresh_failed",
41355
- sessionId: "agent-catalog"
41356
- });
41357
- diagnostics.daemonDiagnostic(
41358
- "agent_catalog_refresh_failed",
41359
- command.requestId,
41360
- { code: operationErrorCode(failure2) },
41361
- failure2
41362
- );
41363
- if (socket.readyState === WebSocket3.OPEN) {
41364
- send(socket, {
41365
- code: operationErrorCode(failure2),
41366
- kind: AGENT_CATALOG_REFRESH_FAILED_KIND,
41367
- message: operationErrorMessage(failure2),
41368
- requestId: command.requestId
41369
- });
41370
- }
41371
- } finally {
41372
- timeout.cancel();
41373
- agentCatalogRefreshes.delete(command.requestId);
41374
- }
41375
- })();
41376
- agentCatalogRefreshes.set(command.requestId, { completion, controller });
41377
- return;
41378
- };
41379
- const settle2 = async () => {
41380
- await Promise.all([...agentCatalogRefreshes.values()].map((request) => request.completion));
41381
- };
41382
- return { handle, settle: settle2 };
41383
- }
40810
+ import { WebSocket as WebSocket5 } from "undici";
41384
40811
 
41385
40812
  // src/agent-catalog/handle-agent-settings-discovery.ts
41386
- import { WebSocket as WebSocket4 } from "undici";
40813
+ import { WebSocket as WebSocket3 } from "undici";
41387
40814
 
41388
40815
  // src/agent-catalog/discover-agent-settings.ts
41389
40816
  import { createHash as createHash6 } from "node:crypto";
@@ -41871,7 +41298,7 @@ function createAgentSettingsDiscoveryHandler(dependencies) {
41871
41298
  (request) => request.agentId === command.agentId && !request.controller.signal.aborted
41872
41299
  );
41873
41300
  if ([...agentSettingsDiscoveries.values()].some((request) => request.requestIds.has(command.requestId))) {
41874
- if (socket.readyState === WebSocket4.OPEN) {
41301
+ if (socket.readyState === WebSocket3.OPEN) {
41875
41302
  send(socket, {
41876
41303
  code: "agent_settings_discovery_busy",
41877
41304
  kind: AGENT_SETTINGS_DISCOVERY_FAILED_KIND,
@@ -41886,7 +41313,7 @@ function createAgentSettingsDiscoveryHandler(dependencies) {
41886
41313
  return;
41887
41314
  }
41888
41315
  if (existing !== void 0) {
41889
- if (socket.readyState === WebSocket4.OPEN) {
41316
+ if (socket.readyState === WebSocket3.OPEN) {
41890
41317
  send(socket, {
41891
41318
  code: "agent_settings_discovery_busy",
41892
41319
  kind: AGENT_SETTINGS_DISCOVERY_FAILED_KIND,
@@ -41897,7 +41324,7 @@ function createAgentSettingsDiscoveryHandler(dependencies) {
41897
41324
  return;
41898
41325
  }
41899
41326
  if (agentSettingsDiscoveries.size >= 4) {
41900
- if (socket.readyState === WebSocket4.OPEN) {
41327
+ if (socket.readyState === WebSocket3.OPEN) {
41901
41328
  send(socket, {
41902
41329
  code: "agent_settings_discovery_busy",
41903
41330
  kind: AGENT_SETTINGS_DISCOVERY_FAILED_KIND,
@@ -41943,7 +41370,7 @@ function createAgentSettingsDiscoveryHandler(dependencies) {
41943
41370
  event: "agent_settings_discovered",
41944
41371
  sessionId: `agent-settings:${command.agentId}`
41945
41372
  });
41946
- if (socket.readyState === WebSocket4.OPEN) {
41373
+ if (socket.readyState === WebSocket3.OPEN) {
41947
41374
  send(socket, { ...result.event, requestId });
41948
41375
  }
41949
41376
  }
@@ -41969,7 +41396,7 @@ function createAgentSettingsDiscoveryHandler(dependencies) {
41969
41396
  `
41970
41397
  );
41971
41398
  }
41972
- if (socket.readyState === WebSocket4.OPEN) {
41399
+ if (socket.readyState === WebSocket3.OPEN) {
41973
41400
  for (const requestId of requestIds) {
41974
41401
  send(socket, {
41975
41402
  code: operationErrorCode(failure2),
@@ -42002,7 +41429,7 @@ function createAgentSettingsDiscoveryHandler(dependencies) {
42002
41429
  // src/artifacts/local-file-streamer.ts
42003
41430
  import { createReadStream as createReadStream2 } from "node:fs";
42004
41431
  import { realpath as realpath10, stat as stat9 } from "node:fs/promises";
42005
- import { basename as basename6, isAbsolute as isAbsolute10, normalize as normalize4, resolve as resolve7 } from "node:path";
41432
+ import { basename as basename5, isAbsolute as isAbsolute10, normalize as normalize4, resolve as resolve7 } from "node:path";
42006
41433
  import { fileURLToPath as fileURLToPath2 } from "node:url";
42007
41434
  var CHUNK_BYTES = 192 * 1024;
42008
41435
  function requestedPath(value) {
@@ -42054,7 +41481,7 @@ async function streamLocalFile(command, send2, signal, workingDirectory, externa
42054
41481
  kind: FILE_BEGIN_KIND,
42055
41482
  mediaType: external?.mediaType ?? raster?.mimeType ?? "application/octet-stream",
42056
41483
  modifiedAt: before.mtime.toISOString(),
42057
- name: external?.name ?? (basename6(target) || "file"),
41484
+ name: external?.name ?? (basename5(target) || "file"),
42058
41485
  requestId: command.requestId,
42059
41486
  sessionId: command.sessionId
42060
41487
  });
@@ -42084,7 +41511,7 @@ async function streamLocalFile(command, send2, signal, workingDirectory, externa
42084
41511
  }
42085
41512
 
42086
41513
  // src/authorization/resolve-session-directories.ts
42087
- import { basename as basename7 } from "node:path";
41514
+ import { basename as basename6 } from "node:path";
42088
41515
  var ResolvedSessionDirectories = class {
42089
41516
  additionalDirectories;
42090
41517
  additionalDirectoryEntries;
@@ -42109,306 +41536,13 @@ async function resolveSessionDirectories(directories, bindingId, directoryId2, a
42109
41536
  additionalDirectories.push(directory);
42110
41537
  additionalDirectoryEntries.push({
42111
41538
  directoryId: additionalDirectoryId,
42112
- name: basename7(directory)
41539
+ name: basename6(directory)
42113
41540
  });
42114
41541
  }
42115
41542
  return new ResolvedSessionDirectories(cwd, additionalDirectories, additionalDirectoryEntries);
42116
41543
  }
42117
41544
 
42118
- // src/native-sessions/live-history-page.ts
42119
- function encodeLiveHistoryCursor(cursor) {
42120
- return Buffer.from(JSON.stringify(cursor), "utf8").toString("base64url");
42121
- }
42122
- function decodeLiveHistoryCursor(cursor, sessionId) {
42123
- try {
42124
- if (!/^[A-Za-z0-9_-]{1,512}$/u.test(cursor)) {
42125
- throw new Error("Invalid cursor alphabet");
42126
- }
42127
- const value = JSON.parse(Buffer.from(cursor, "base64url").toString("utf8"));
42128
- if (typeof value !== "object" || value === null || Array.isArray(value)) {
42129
- throw new Error("Invalid cursor shape");
42130
- }
42131
- const record2 = Object.fromEntries(Object.entries(value));
42132
- const keys = Object.keys(record2).sort().join(",");
42133
- const legacyNative = keys === "endIndex,sessionId";
42134
- const kind = legacyNative ? "native" : record2["kind"];
42135
- 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) {
42136
- throw new Error("Invalid cursor target");
42137
- }
42138
- if (kind === "active") {
42139
- if (keys !== "endIndex,epoch,kind,sessionId" || typeof record2["epoch"] !== "string") {
42140
- throw new Error("Invalid active cursor target");
42141
- }
42142
- return { endIndex: record2["endIndex"], epoch: record2["epoch"], kind, sessionId };
42143
- }
42144
- if (keys !== "endIndex,kind,sessionId" && !legacyNative) {
42145
- throw new Error("Invalid native cursor target");
42146
- }
42147
- return { endIndex: record2["endIndex"], kind, sessionId };
42148
- } catch (cause) {
42149
- throw new AcpExecutionError("The native Session history cursor is invalid", { cause }, "invalid_cursor");
42150
- }
42151
- }
42152
- function activeHistoryCursor(sessionId, epoch, endIndex) {
42153
- return encodeLiveHistoryCursor({ endIndex, epoch, kind: "active", sessionId });
42154
- }
42155
- function nativeHistoryCursor(sessionId, endIndex) {
42156
- return encodeLiveHistoryCursor({ endIndex, kind: "native", sessionId });
42157
- }
42158
- function liveHistoryCoveredTurnRanges(history) {
42159
- const ranges = [];
42160
- let historyIndex = history.messages.length;
42161
- for (const commandId of history.coveredCommandIds) {
42162
- let assistantStartIndex = historyIndex;
42163
- while (assistantStartIndex > 0 && history.messages[assistantStartIndex - 1]?.role === "assistant") {
42164
- assistantStartIndex -= 1;
42165
- }
42166
- const userIndex = assistantStartIndex - 1;
42167
- if (assistantStartIndex === historyIndex || history.messages[userIndex]?.role !== "user") {
42168
- break;
42169
- }
42170
- ranges.push({ assistantEndIndex: historyIndex, assistantStartIndex, commandId, userIndex });
42171
- historyIndex = userIndex;
42172
- }
42173
- return ranges;
42174
- }
42175
- function historyMessageCharacters(message) {
42176
- return message.text.length + (message.role === "assistant" ? JSON.stringify(message.activities).length + JSON.stringify(message.content).length : 0);
42177
- }
42178
- function isNativeHistoryImageMimeType(mimeType) {
42179
- return mimeType === "image/png" || mimeType === "image/jpeg" || mimeType === "image/gif" || mimeType === "image/webp";
42180
- }
42181
- function selectMessagesBefore(messages, endIndex, messageLimit, characterLimit) {
42182
- const selected = [];
42183
- let remainingCharacters = characterLimit;
42184
- let startIndex = endIndex;
42185
- for (let index = endIndex - 1; index >= 0 && selected.length < messageLimit; index -= 1) {
42186
- const message = messages[index];
42187
- if (message === void 0) {
42188
- break;
42189
- }
42190
- const characters = historyMessageCharacters(message);
42191
- if (characters > remainingCharacters) {
42192
- break;
42193
- }
42194
- selected.unshift(message);
42195
- remainingCharacters -= characters;
42196
- startIndex = index;
42197
- }
42198
- if (selected.length === 0 && endIndex > 0) {
42199
- throw new AcpExecutionError(
42200
- "A native Session history item exceeds the page budget",
42201
- {},
42202
- "history_item_too_large"
42203
- );
42204
- }
42205
- return { characters: characterLimit - remainingCharacters, messages: selected, startIndex };
42206
- }
42207
- function nativeActiveMessage(message) {
42208
- if (message.role === "assistant") {
42209
- return {
42210
- activities: message.activities,
42211
- content: message.content,
42212
- role: "assistant",
42213
- text: message.text
42214
- };
42215
- }
42216
- const images = (message.images ?? []).flatMap((image) => {
42217
- if (image.data.length < 4 || image.data.length % 4 !== 0 || !/^[A-Za-z0-9+/]*={0,2}$/u.test(image.data) || !isNativeHistoryImageMimeType(image.mimeType)) {
42218
- return [];
42219
- }
42220
- return [{ data: image.data, mimeType: image.mimeType, name: image.name }];
42221
- });
42222
- return { ...images.length === 0 ? {} : { images }, role: "user", text: message.text };
42223
- }
42224
- function nativeHistoryCoversCompletedRecovery(history, recovery) {
42225
- const root = recovery.messages.find((message) => message.role === "user" && message.id === recovery.commandId);
42226
- if (root === void 0) {
42227
- return false;
42228
- }
42229
- const rootIndex = history.messages.findLastIndex(
42230
- (message) => message.role === "user" && message.text === root.text
42231
- );
42232
- if (rootIndex < 0) {
42233
- return false;
42234
- }
42235
- const nativeAssistant = history.messages.slice(rootIndex + 1).filter((message) => message.role === "assistant");
42236
- if (nativeAssistant.length === 0) {
42237
- return false;
42238
- }
42239
- const recoveryAssistant = recovery.messages.filter((message) => message.role === "assistant");
42240
- const recoveryText = recoveryAssistant.map((message) => message.text).join("");
42241
- const nativeText = nativeAssistant.map((message) => message.text).join("");
42242
- if (recoveryText.length > 0 && !nativeText.includes(recoveryText)) {
42243
- return false;
42244
- }
42245
- const nativeContent = new Set(
42246
- nativeAssistant.flatMap((message) => message.content).map((content) => JSON.stringify(content))
42247
- );
42248
- return recoveryAssistant.flatMap((message) => message.content).every((content) => nativeContent.has(JSON.stringify(content)));
42249
- }
42250
- function historyBeforeActiveTurn(history, activeTurn) {
42251
- if (history.status === "unavailable") {
42252
- return history;
42253
- }
42254
- const activeRoot = activeTurn.messages.find(
42255
- (message) => message.role === "user" && message.id === activeTurn.commandId
42256
- );
42257
- 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;
42258
- const activeUserIndex = matchingActiveUserIndex >= 0 ? matchingActiveUserIndex : liveHistoryCoveredTurnRanges(history).find((range) => range.commandId === activeTurn.commandId)?.userIndex ?? -1;
42259
- if (activeUserIndex < 0) {
42260
- return history;
42261
- }
42262
- return {
42263
- ...history,
42264
- coveredCommandIds: history.coveredCommandIds.filter((id) => id !== activeTurn.commandId),
42265
- coveredMessageIds: history.coveredMessageIds.filter(
42266
- (id) => id !== `${activeTurn.commandId}:user` && id !== `${activeTurn.commandId}:agent`
42267
- ),
42268
- messages: history.messages.slice(0, activeUserIndex)
42269
- };
42270
- }
42271
- function paginateAvailableNativeHistory(history, sessionId, endIndex, limit, characterLimit) {
42272
- if (endIndex > history.messages.length) {
42273
- throw new AcpExecutionError("The native Session history cursor is invalid", {}, "invalid_cursor");
42274
- }
42275
- const selected = selectMessagesBefore(history.messages, endIndex, limit, characterLimit);
42276
- const coveredMessageIds = new Set(history.coveredMessageIds);
42277
- const ranges = liveHistoryCoveredTurnRanges(history);
42278
- return {
42279
- coveredCommandIds: ranges.filter((range) => range.userIndex >= selected.startIndex && range.assistantEndIndex <= endIndex).map((range) => range.commandId),
42280
- coveredMessageIds: ranges.flatMap((range) => [
42281
- ...range.userIndex >= selected.startIndex && range.userIndex < endIndex && coveredMessageIds.has(`${range.commandId}:user`) ? [`${range.commandId}:user`] : [],
42282
- ...range.assistantStartIndex >= selected.startIndex && range.assistantEndIndex <= endIndex && coveredMessageIds.has(`${range.commandId}:agent`) ? [`${range.commandId}:agent`] : []
42283
- ]),
42284
- messages: selected.messages,
42285
- nextCursor: selected.startIndex > 0 ? nativeHistoryCursor(sessionId, selected.startIndex) : null,
42286
- status: "available",
42287
- truncated: history.truncated
42288
- };
42289
- }
42290
- function paginateNativeHistory(history, sessionId, cursor, limit) {
42291
- if (cursor?.kind === "active") {
42292
- throw new AcpExecutionError("The native Session history cursor is invalid", {}, "invalid_cursor");
42293
- }
42294
- if (history.status === "unavailable") {
42295
- if (cursor !== null) {
42296
- throw new AcpExecutionError("Unavailable native Session history has no cursor", {}, "invalid_cursor");
42297
- }
42298
- return { cause: history.cause, nextCursor: null, status: "unavailable" };
42299
- }
42300
- return paginateAvailableNativeHistory(
42301
- history,
42302
- sessionId,
42303
- cursor?.endIndex ?? history.messages.length,
42304
- limit,
42305
- SESSION_HISTORY_CHARACTER_LIMIT
42306
- );
42307
- }
42308
- function paginateActiveTurn(history, activeTurn, sessionId, endIndex, limit) {
42309
- if (endIndex > activeTurn.messages.length) {
42310
- throw new AcpExecutionError("The native Session history cursor is invalid", {}, "invalid_cursor");
42311
- }
42312
- const activeMessages = activeTurn.messages.map(nativeActiveMessage);
42313
- const active = selectMessagesBefore(activeMessages, endIndex, limit, SESSION_HISTORY_CHARACTER_LIMIT);
42314
- const historicalLimit = limit - active.messages.length;
42315
- const historicalCharacterLimit = SESSION_HISTORY_CHARACTER_LIMIT - active.characters;
42316
- const pendingHistoricalCursor = history.status === "available" && history.messages.length > 0 ? nativeHistoryCursor(sessionId, history.messages.length) : null;
42317
- const latestHistoricalMessage = history.status === "available" ? history.messages.at(-1) : void 0;
42318
- const historicalPageFits = latestHistoricalMessage === void 0 || historyMessageCharacters(latestHistoricalMessage) <= historicalCharacterLimit;
42319
- const historical = active.startIndex === 0 && history.status === "available" && historicalLimit > 0 && historicalPageFits ? paginateAvailableNativeHistory(
42320
- history,
42321
- sessionId,
42322
- history.messages.length,
42323
- historicalLimit,
42324
- historicalCharacterLimit
42325
- ) : null;
42326
- return {
42327
- streamPosition: { commandId: activeTurn.commandId, epoch: activeTurn.epoch, sequence: activeTurn.sequence },
42328
- coveredCommandIds: historical?.coveredCommandIds ?? [],
42329
- coveredMessageIds: [
42330
- ...historical?.coveredMessageIds ?? [],
42331
- ...active.startIndex === 0 ? [`${activeTurn.commandId}:user`, `${activeTurn.commandId}:agent`] : []
42332
- ],
42333
- messages: [...historical?.messages ?? [], ...active.messages],
42334
- nextCursor: active.startIndex > 0 ? activeHistoryCursor(sessionId, activeTurn.epoch, active.startIndex) : historical === null ? pendingHistoricalCursor : historical.nextCursor,
42335
- status: "available",
42336
- truncated: activeTurn.truncated || (historical?.truncated ?? false)
42337
- };
42338
- }
42339
- function paginateLiveSessionHistory(history, activeTurn, sessionId, encodedCursor, limit) {
42340
- const cursor = encodedCursor === null ? null : decodeLiveHistoryCursor(encodedCursor, sessionId);
42341
- if (activeTurn === null || activeTurn.state === "completed" && history.status === "available" && nativeHistoryCoversCompletedRecovery(history, activeTurn)) {
42342
- return paginateNativeHistory(history, sessionId, cursor, limit);
42343
- }
42344
- const historical = historyBeforeActiveTurn(history, activeTurn);
42345
- if (cursor?.kind === "native") {
42346
- return paginateNativeHistory(historical, sessionId, cursor, limit);
42347
- }
42348
- if (cursor !== null && cursor.epoch !== activeTurn.epoch) {
42349
- throw new AcpExecutionError("The active Turn history cursor is stale", {}, "stale_cursor");
42350
- }
42351
- return paginateActiveTurn(historical, activeTurn, sessionId, cursor?.endIndex ?? activeTurn.messages.length, limit);
42352
- }
42353
-
42354
41545
  // src/daemon-history-commands.ts
42355
- async function executeSessionLiveHistoryPageLoad(socket, command, config2, directories, audit, sessions, activeTurn, signal) {
42356
- try {
42357
- const resolved = await resolveSessionDirectories(
42358
- directories,
42359
- config2.bindingId,
42360
- command.directoryId,
42361
- command.additionalDirectoryIds,
42362
- signal
42363
- );
42364
- const history = await sessions.loadSessionHistory({
42365
- additionalDirectories: resolved.additionalDirectories,
42366
- agent: config2.catalog.find(command.agentId),
42367
- cwd: resolved.cwd,
42368
- sessionId: command.sessionId,
42369
- signal
42370
- });
42371
- signal.throwIfAborted();
42372
- const page = paginateLiveSessionHistory(
42373
- history,
42374
- activeTurn(command.sessionId),
42375
- command.sessionId,
42376
- command.cursor,
42377
- command.limit
42378
- );
42379
- audit.record({
42380
- commandId: command.requestId,
42381
- event: "session_history_loaded",
42382
- sessionId: command.sessionId
42383
- });
42384
- send(socket, {
42385
- kind: "session.live-history.page.loaded",
42386
- page,
42387
- requestId: command.requestId,
42388
- sessionId: command.sessionId
42389
- });
42390
- } catch (error62) {
42391
- if (signal.aborted) {
42392
- return;
42393
- }
42394
- audit.record({
42395
- commandId: command.requestId,
42396
- details: { code: operationErrorCode(error62) },
42397
- event: "session_history_unavailable",
42398
- sessionId: command.sessionId
42399
- });
42400
- send(socket, {
42401
- kind: "session.live-history.page.loaded",
42402
- page: {
42403
- status: "unavailable",
42404
- cause: { code: operationErrorCode(error62), message: operationErrorMessage(error62) },
42405
- nextCursor: null
42406
- },
42407
- requestId: command.requestId,
42408
- sessionId: command.sessionId
42409
- });
42410
- }
42411
- }
42412
41546
  async function executeSessionLiveHistoryV2PageLoad(socket, command, config2, directories, audit, diagnostics, sessions, eventLogV2, signal) {
42413
41547
  try {
42414
41548
  const resolved = await resolveSessionDirectories(
@@ -43179,9 +42313,9 @@ async function executeSessionConfigure(publisher, socket, command, config2, dire
43179
42313
  }
43180
42314
 
43181
42315
  // src/native-sessions/handle-native-requests.ts
43182
- import { WebSocket as WebSocket5 } from "undici";
42316
+ import { WebSocket as WebSocket4 } from "undici";
43183
42317
  function createNativeSessionRequestHandler(dependencies) {
43184
- const { audit, diagnostics, nativeSessions, publisher, signal, socket, timer } = dependencies;
42318
+ const { audit, diagnostics, nativeSessions, signal, socket, timer } = dependencies;
43185
42319
  const pending = /* @__PURE__ */ new Map();
43186
42320
  const cancel = (command) => {
43187
42321
  const request = pending.get(command.requestId);
@@ -43233,18 +42367,7 @@ function createNativeSessionRequestHandler(dependencies) {
43233
42367
  }
43234
42368
  operationSignal.throwIfAborted();
43235
42369
  const result = await nativeSessions.execute(command, operationSignal);
43236
- if (command.action === "fork-recorded" && result.action === "fork-recorded") {
43237
- publisher.publishBatch(result.ready.sessionId, [
43238
- result.ready,
43239
- {
43240
- kind: "session.forked",
43241
- sessionId: result.ready.sessionId,
43242
- sourceSessionId: command.sessionId,
43243
- throughCommandId: command.throughCommandId
43244
- }
43245
- ]);
43246
- }
43247
- if (socket.readyState === WebSocket5.OPEN) {
42370
+ if (socket.readyState === WebSocket4.OPEN) {
43248
42371
  send(socket, result);
43249
42372
  }
43250
42373
  } catch (error62) {
@@ -43303,8 +42426,7 @@ function createDaemonCommandHandler({
43303
42426
  socket,
43304
42427
  signal,
43305
42428
  runtimeSignal,
43306
- timer,
43307
- resolveAgentCatalogEnvironment
42429
+ timer
43308
42430
  }) {
43309
42431
  const handleSettingsDiscovery = createAgentSettingsDiscoveryHandler({
43310
42432
  config: config2,
@@ -43316,25 +42438,14 @@ function createDaemonCommandHandler({
43316
42438
  signal,
43317
42439
  timer
43318
42440
  });
43319
- const handleCatalogRefresh = createAgentCatalogRefreshHandler({
43320
- config: config2,
43321
- audit,
43322
- diagnostics,
43323
- socket,
43324
- signal,
43325
- timer,
43326
- resolveEnvironment: resolveAgentCatalogEnvironment
43327
- });
43328
42441
  const queueChanged = (sessionId) => {
43329
42442
  publisher.publish(sessionId, { kind: "session.queue.changed", sessionId });
43330
42443
  eventLogV2.queueChanged(sessionId);
43331
42444
  };
43332
- const activeTurnRecovery = (sessionId) => activeTurns.recovery((command) => command.sessionId === sessionId);
43333
42445
  const nativeRequestHandler = createNativeSessionRequestHandler({
43334
42446
  audit,
43335
42447
  diagnostics,
43336
42448
  nativeSessions,
43337
- publisher,
43338
42449
  signal,
43339
42450
  socket,
43340
42451
  timer
@@ -43342,18 +42453,8 @@ function createDaemonCommandHandler({
43342
42453
  return {
43343
42454
  handle: (message) => {
43344
42455
  const kind = message.kind;
43345
- if (kind === SESSION_LIVE_HISTORY_PAGE_LOAD_KIND) {
43346
- const command2 = message;
43347
- void executeSessionLiveHistoryPageLoad(
43348
- socket,
43349
- command2,
43350
- config2,
43351
- directories,
43352
- audit,
43353
- sessions,
43354
- activeTurnRecovery,
43355
- signal
43356
- );
42456
+ if (kind === RUNTIME_PING_KIND) {
42457
+ send(socket, { kind: RUNTIME_PONG_KIND, requestId: message.requestId });
43357
42458
  return;
43358
42459
  }
43359
42460
  if (kind === SESSION_LIVE_HISTORY_V2_PAGE_LOAD_KIND) {
@@ -43378,10 +42479,6 @@ function createDaemonCommandHandler({
43378
42479
  handleSettingsDiscovery.handle(message);
43379
42480
  return;
43380
42481
  }
43381
- if (kind === AGENT_CATALOG_REFRESH_KIND) {
43382
- handleCatalogRefresh.handle(message);
43383
- return;
43384
- }
43385
42482
  if (kind === NATIVE_SESSION_REQUEST_KIND) {
43386
42483
  nativeRequestHandler.handle(message);
43387
42484
  return;
@@ -43395,7 +42492,7 @@ function createDaemonCommandHandler({
43395
42492
  sessions.findSessions([command2.sessionId])[0]?.cwd ?? null,
43396
42493
  externalContent
43397
42494
  ).catch((error62) => {
43398
- if (socket.readyState !== WebSocket6.OPEN || signal.aborted) {
42495
+ if (socket.readyState !== WebSocket5.OPEN || signal.aborted) {
43399
42496
  return;
43400
42497
  }
43401
42498
  send(socket, {
@@ -43601,17 +42698,13 @@ function createDaemonCommandHandler({
43601
42698
  });
43602
42699
  },
43603
42700
  settle: async () => {
43604
- await Promise.all([
43605
- nativeRequestHandler.settle(),
43606
- handleSettingsDiscovery.settle(),
43607
- handleCatalogRefresh.settle()
43608
- ]);
42701
+ await Promise.all([nativeRequestHandler.settle(), handleSettingsDiscovery.settle()]);
43609
42702
  }
43610
42703
  };
43611
42704
  }
43612
42705
 
43613
42706
  // src/relay-connection/connect.ts
43614
- import { WebSocket as WebSocket7 } from "undici";
42707
+ import { WebSocket as WebSocket6 } from "undici";
43615
42708
  var CONNECTION_TIMEOUT_MILLISECONDS = 6e4;
43616
42709
  var RelayConnectionError = class extends Error {
43617
42710
  code;
@@ -43629,7 +42722,7 @@ function connectRelay(url2, signal) {
43629
42722
  const endpoint = new URL(url2);
43630
42723
  const headers = runtimeAuthorization(endpoint);
43631
42724
  endpoint.searchParams.delete("token");
43632
- const socket = new WebSocket7(endpoint, {
42725
+ const socket = new WebSocket6(endpoint, {
43633
42726
  dispatcher: environmentProxyDispatcher,
43634
42727
  headers
43635
42728
  });
@@ -43847,8 +42940,7 @@ async function runRelayConnection({
43847
42940
  diagnostics,
43848
42941
  onConnected,
43849
42942
  signal,
43850
- timer,
43851
- resolveAgentCatalogEnvironment
42943
+ timer
43852
42944
  }) {
43853
42945
  const relayUrl = new URL(config2.relayUrl);
43854
42946
  relayUrl.searchParams.set("liveness", "1");
@@ -43871,8 +42963,7 @@ async function runRelayConnection({
43871
42963
  socket,
43872
42964
  signal: connectionController.signal,
43873
42965
  runtimeSignal: signal,
43874
- timer,
43875
- resolveAgentCatalogEnvironment
42966
+ timer
43876
42967
  });
43877
42968
  installationObserver.connect(socket);
43878
42969
  onConnected();
@@ -43918,14 +43009,14 @@ async function runRelayConnection({
43918
43009
  };
43919
43010
  const connectionLiveness = new RelayConnectionLiveness(timer, {
43920
43011
  send: (message) => {
43921
- if (socket.readyState !== WebSocket8.OPEN) {
43012
+ if (socket.readyState !== WebSocket7.OPEN) {
43922
43013
  return false;
43923
43014
  }
43924
43015
  try {
43925
43016
  send(socket, message);
43926
43017
  return true;
43927
43018
  } catch (error62) {
43928
- if (socket.readyState !== WebSocket8.OPEN) {
43019
+ if (socket.readyState !== WebSocket7.OPEN) {
43929
43020
  return false;
43930
43021
  }
43931
43022
  throw error62;
@@ -44014,7 +43105,7 @@ async function runRelayConnection({
44014
43105
  }
44015
43106
 
44016
43107
  // src/relay-connection/session-event-publisher.ts
44017
- import { WebSocket as WebSocket9 } from "undici";
43108
+ import { WebSocket as WebSocket8 } from "undici";
44018
43109
  var MAX_BUFFERED_BYTES = 32 * 1024 * 1024;
44019
43110
  var DaemonSessionEventPublisher = class {
44020
43111
  #socket = null;
@@ -44031,7 +43122,7 @@ var DaemonSessionEventPublisher = class {
44031
43122
  };
44032
43123
  publish = (sessionId, event) => {
44033
43124
  const socket = this.#socket;
44034
- if (socket === null || socket.readyState !== WebSocket9.OPEN) {
43125
+ if (socket === null || socket.readyState !== WebSocket8.OPEN) {
44035
43126
  return;
44036
43127
  }
44037
43128
  const encoded = encodeDaemonToServiceMessage({
@@ -44055,7 +43146,7 @@ var DaemonSessionEventPublisher = class {
44055
43146
  };
44056
43147
  publishStatus = (event) => {
44057
43148
  const socket = this.#socket;
44058
- if (socket === null || socket.readyState !== WebSocket9.OPEN) {
43149
+ if (socket === null || socket.readyState !== WebSocket8.OPEN) {
44059
43150
  return;
44060
43151
  }
44061
43152
  const encoded = encodeDaemonToServiceMessage(event);
@@ -44070,7 +43161,7 @@ var DaemonSessionEventPublisher = class {
44070
43161
  };
44071
43162
  publishV2 = (event) => {
44072
43163
  const socket = this.#socket;
44073
- if (socket === null || socket.readyState !== WebSocket9.OPEN) {
43164
+ if (socket === null || socket.readyState !== WebSocket8.OPEN) {
44074
43165
  return;
44075
43166
  }
44076
43167
  const encoded = encodeDaemonToServiceMessage({ event, kind: SESSION_EVENT_V2_KIND });
@@ -44309,10 +43400,6 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
44309
43400
  let connectionAnnounced = false;
44310
43401
  let catalogPublished = false;
44311
43402
  let readinessAnnounced = false;
44312
- const resolveAgentCatalogEnvironment = options.resolveAgentCatalogEnvironment ?? (async (catalogSignal) => {
44313
- catalogSignal.throwIfAborted();
44314
- return config2.localContext.environment;
44315
- });
44316
43403
  const startAutomaticIntegrationProvisioning = () => {
44317
43404
  if (!connectionAnnounced || !catalogPublished || automaticIntegrationProvisioningStarted) {
44318
43405
  return;
@@ -44390,8 +43477,7 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
44390
43477
  announceConnection();
44391
43478
  },
44392
43479
  signal,
44393
- timer,
44394
- resolveAgentCatalogEnvironment
43480
+ timer
44395
43481
  });
44396
43482
  } catch (error62) {
44397
43483
  if (signal.aborted) {
@@ -44560,8 +43646,7 @@ var MobiusRuntimeEngine = class {
44560
43646
  const audit = new AuditStore();
44561
43647
  try {
44562
43648
  await runDaemon(this.#config, audit, signal, void 0, {
44563
- ...this.#options.onConnectionStatus === void 0 ? {} : { onConnectionStatus: this.#options.onConnectionStatus },
44564
- ...this.#options.resolveAgentCatalogEnvironment === void 0 ? {} : { resolveAgentCatalogEnvironment: this.#options.resolveAgentCatalogEnvironment }
43649
+ ...this.#options.onConnectionStatus === void 0 ? {} : { onConnectionStatus: this.#options.onConnectionStatus }
44565
43650
  });
44566
43651
  } finally {
44567
43652
  audit.close();