@moxt-ai/mobius 0.0.187 → 0.0.189

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 (43) hide show
  1. package/dist/acp/agent-runtime-manager.d.ts +2 -2
  2. package/dist/acp/agent-runtime-manager.d.ts.map +1 -1
  3. package/dist/acp/agent-runtime-manager.js +17 -8
  4. package/dist/acp/agent-runtime-manager.js.map +1 -1
  5. package/dist/acp/codex/agent.d.ts.map +1 -1
  6. package/dist/acp/codex/agent.js +32 -10
  7. package/dist/acp/codex/agent.js.map +1 -1
  8. package/dist/acp/codex/app-server-protocol.d.ts +7 -0
  9. package/dist/acp/codex/app-server-protocol.d.ts.map +1 -1
  10. package/dist/acp/codex/app-server-protocol.js +5 -0
  11. package/dist/acp/codex/app-server-protocol.js.map +1 -1
  12. package/dist/acp/session-contracts.d.ts +10 -3
  13. package/dist/acp/session-contracts.d.ts.map +1 -1
  14. package/dist/acp/session-contracts.js +3 -0
  15. package/dist/acp/session-contracts.js.map +1 -1
  16. package/dist/acp/session-event-store-v2.d.ts +1 -0
  17. package/dist/acp/session-event-store-v2.d.ts.map +1 -1
  18. package/dist/acp/session-event-store-v2.js +3 -0
  19. package/dist/acp/session-event-store-v2.js.map +1 -1
  20. package/dist/cli.js +362 -52
  21. package/dist/cli.js.map +4 -4
  22. package/dist/daemon-command-handler.d.ts.map +1 -1
  23. package/dist/daemon-command-handler.js +6 -2
  24. package/dist/daemon-command-handler.js.map +1 -1
  25. package/dist/daemon-history-commands.d.ts +2 -1
  26. package/dist/daemon-history-commands.d.ts.map +1 -1
  27. package/dist/daemon-history-commands.js +54 -1
  28. package/dist/daemon-history-commands.js.map +1 -1
  29. package/dist/index.js +363 -53
  30. package/dist/index.js.map +4 -4
  31. package/dist/native-sessions/codex-history.d.ts.map +1 -1
  32. package/dist/native-sessions/codex-history.js +9 -1
  33. package/dist/native-sessions/codex-history.js.map +1 -1
  34. package/dist/native-sessions/native-history-events-v2.d.ts +8 -0
  35. package/dist/native-sessions/native-history-events-v2.d.ts.map +1 -0
  36. package/dist/native-sessions/native-history-events-v2.js +147 -0
  37. package/dist/native-sessions/native-history-events-v2.js.map +1 -0
  38. package/dist/run-daemon.d.ts.map +1 -1
  39. package/dist/run-daemon.js +6 -3
  40. package/dist/run-daemon.js.map +1 -1
  41. package/dist/runtime.js +361 -51
  42. package/dist/runtime.js.map +4 -4
  43. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -3381,7 +3381,7 @@ var program = new Command();
3381
3381
  // package.json
3382
3382
  var package_default = {
3383
3383
  name: "@moxt-ai/mobius",
3384
- version: "0.0.187",
3384
+ version: "0.0.189",
3385
3385
  description: "Mobius CLI for pairing and running local AI agent services.",
3386
3386
  type: "module",
3387
3387
  bin: {
@@ -24854,6 +24854,11 @@ var threadLifecycleResponseSchema = external_exports.object({
24854
24854
  serviceTier: boundedText(256).nullish(),
24855
24855
  thread: external_exports.object({ id: boundedText(256), turns: threadTurnsSchema })
24856
24856
  });
24857
+ var CODEX_HISTORY_TURN_PAGE_LIMIT = 20;
24858
+ var threadTurnsPageSchema = external_exports.object({
24859
+ data: external_exports.array(threadTurnSchema).max(CODEX_HISTORY_TURN_PAGE_LIMIT),
24860
+ nextCursor: boundedText(1024).nullish()
24861
+ });
24857
24862
  var threadResumeResponseSchema = threadLifecycleResponseSchema;
24858
24863
  var threadForkResponseSchema = threadLifecycleResponseSchema;
24859
24864
  var threadTitleSchema = external_exports.string().transform((value) => value.slice(0, 500));
@@ -25928,14 +25933,14 @@ var CodexAcpAgent = class {
25928
25933
  const resumed = threadResumeResponseSchema.parse(
25929
25934
  await this.#appServer.request(
25930
25935
  "thread/resume",
25931
- { cwd: context.params.cwd, excludeTurns: false, threadId: context.params.sessionId },
25936
+ { cwd: context.params.cwd, excludeTurns: true, threadId: context.params.sessionId },
25932
25937
  AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2)])
25933
25938
  )
25934
25939
  );
25935
25940
  this.#nativeSessionId = resumed.thread.id;
25936
25941
  this.#settings.selectRestoredThread(resumed);
25937
25942
  await this.#settings.probeCollaborationMode(this.#nativeSessionId, context.signal);
25938
- await this.#replayHistory(resumed.thread.turns);
25943
+ await this.#replaySavedHistory(context.signal);
25939
25944
  await this.#emitAvailableCommands();
25940
25945
  return { configOptions: this.#settings.configOptions() };
25941
25946
  }).onRequest(methods.agent.session.fork, async (context) => {
@@ -26030,14 +26035,46 @@ var CodexAcpAgent = class {
26030
26035
  }
26031
26036
  return this.#closePromise;
26032
26037
  };
26033
- /**
26034
- * Reads the model catalog once per app-server. A failure leaves the catalog empty, which costs
26035
- * the Run settings panel its model selector; it must not cost the conversation itself, so the
26036
- * turn lifecycle continues without settings rather than failing initialization.
26037
- */
26038
- #replayHistory = async (turns) => {
26039
- for (const turn of turns ?? []) {
26038
+ // ACP load requires chronological replay. Resume only restores execution;
26039
+ // native pages supply history without a single full-transcript response.
26040
+ #replaySavedHistory = async (signal) => {
26041
+ const deadline = AbortSignal.any([signal, AbortSignal.timeout(6e4)]);
26042
+ const seenCursors = /* @__PURE__ */ new Set();
26043
+ let cursor = null;
26044
+ for (; ; ) {
26045
+ deadline.throwIfAborted();
26046
+ const page = threadTurnsPageSchema.parse(
26047
+ await this.#appServer.request(
26048
+ "thread/turns/list",
26049
+ {
26050
+ threadId: this.#nativeSessionId,
26051
+ limit: CODEX_HISTORY_TURN_PAGE_LIMIT,
26052
+ sortDirection: "asc",
26053
+ itemsView: "full",
26054
+ ...cursor === null ? {} : { cursor }
26055
+ },
26056
+ deadline
26057
+ )
26058
+ );
26059
+ await this.#replayHistory(page.data, deadline);
26060
+ if (page.nextCursor == null) {
26061
+ return;
26062
+ }
26063
+ if (page.data.length === 0 || seenCursors.has(page.nextCursor)) {
26064
+ throw new AcpExecutionError(
26065
+ "Codex repeated a history page cursor",
26066
+ {},
26067
+ "invalid_native_session_response"
26068
+ );
26069
+ }
26070
+ seenCursors.add(page.nextCursor);
26071
+ cursor = page.nextCursor;
26072
+ }
26073
+ };
26074
+ #replayHistory = async (turns, signal) => {
26075
+ for (const turn of turns) {
26040
26076
  for (const rawItem of turn.items) {
26077
+ signal.throwIfAborted();
26041
26078
  const item = decodeThreadItem(rawItem);
26042
26079
  if (item === null) {
26043
26080
  continue;
@@ -30086,24 +30123,28 @@ var decodeAcpSessionUpdateV2 = (value) => decode5(value, acpSessionUpdateV2Schem
30086
30123
  // ../protocol/src/session-live-history.ts
30087
30124
  var SESSION_LIVE_HISTORY_V2_PAGE_LOAD_KIND = "session.live-history.v2.page.load";
30088
30125
  var SESSION_LIVE_HISTORY_V2_PAGE_LOADED_KIND = "session.live-history.v2.page.loaded";
30126
+ var SESSION_PREVIEW_HISTORY_PAGE_LOAD_KIND = "session.preview-history.page.load";
30127
+ var SESSION_PREVIEW_HISTORY_PAGE_LOADED_KIND = "session.preview-history.page.loaded";
30089
30128
  var directoryIdentifier = external_exports.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,2047}$/);
30090
- var sessionLiveHistoryV2PageLoadSchema = external_exports.object({
30129
+ var pageLoadFields = {
30091
30130
  additionalDirectoryIds: external_exports.array(directoryIdentifier).max(16).readonly(),
30092
30131
  agentId: identifierStringSchema,
30093
30132
  bindingId: identifierStringSchema,
30094
30133
  cursor: external_exports.string().min(1).max(512).nullable(),
30095
30134
  directoryId: directoryIdentifier,
30096
- kind: external_exports.literal(SESSION_LIVE_HISTORY_V2_PAGE_LOAD_KIND),
30097
30135
  eventLimit: external_exports.number().int().min(1).max(1e4),
30098
30136
  requestId: identifierStringSchema,
30099
30137
  sessionId: identifierStringSchema
30100
- }).readonly();
30101
- var sessionLiveHistoryV2PageLoadedSchema = external_exports.object({
30138
+ };
30139
+ var sessionLiveHistoryV2PageLoadSchema = external_exports.object({ ...pageLoadFields, kind: external_exports.literal(SESSION_LIVE_HISTORY_V2_PAGE_LOAD_KIND) }).readonly();
30140
+ var sessionPreviewHistoryPageLoadSchema = external_exports.object({ ...pageLoadFields, kind: external_exports.literal(SESSION_PREVIEW_HISTORY_PAGE_LOAD_KIND) }).readonly();
30141
+ var pageLoadedFields = {
30102
30142
  events: nativeSessionEventsV2Schema,
30103
- kind: external_exports.literal(SESSION_LIVE_HISTORY_V2_PAGE_LOADED_KIND),
30104
30143
  requestId: identifierStringSchema,
30105
30144
  sessionId: identifierStringSchema
30106
- }).readonly();
30145
+ };
30146
+ var sessionLiveHistoryV2PageLoadedSchema = external_exports.object({ ...pageLoadedFields, kind: external_exports.literal(SESSION_LIVE_HISTORY_V2_PAGE_LOADED_KIND) }).readonly();
30147
+ var sessionPreviewHistoryPageLoadedSchema = external_exports.object({ ...pageLoadedFields, kind: external_exports.literal(SESSION_PREVIEW_HISTORY_PAGE_LOADED_KIND) }).readonly();
30107
30148
  function decode6(schema, encoded) {
30108
30149
  try {
30109
30150
  const value = JSON.parse(encoded);
@@ -30114,8 +30155,12 @@ function decode6(schema, encoded) {
30114
30155
  }
30115
30156
  var decodeSessionLiveHistoryV2PageLoad = (encoded) => decode6(sessionLiveHistoryV2PageLoadSchema, encoded);
30116
30157
  var decodeSessionLiveHistoryV2PageLoaded = (encoded) => decode6(sessionLiveHistoryV2PageLoadedSchema, encoded);
30158
+ var decodeSessionPreviewHistoryPageLoad = (encoded) => decode6(sessionPreviewHistoryPageLoadSchema, encoded);
30159
+ var decodeSessionPreviewHistoryPageLoaded = (encoded) => decode6(sessionPreviewHistoryPageLoadedSchema, encoded);
30117
30160
  var encodeSessionLiveHistoryV2PageLoad = (value) => JSON.stringify(sessionLiveHistoryV2PageLoadSchema.parse(value));
30118
30161
  var encodeSessionLiveHistoryV2PageLoaded = (value) => JSON.stringify(sessionLiveHistoryV2PageLoadedSchema.parse(value));
30162
+ var encodeSessionPreviewHistoryPageLoad = (value) => JSON.stringify(sessionPreviewHistoryPageLoadSchema.parse(value));
30163
+ var encodeSessionPreviewHistoryPageLoaded = (value) => JSON.stringify(sessionPreviewHistoryPageLoadedSchema.parse(value));
30119
30164
 
30120
30165
  // ../protocol/src/daemon-transport.ts
30121
30166
  function defineMessageSignature(kind, encoder, decoder) {
@@ -30128,6 +30173,11 @@ function defineMessageSignature(kind, encoder, decoder) {
30128
30173
  };
30129
30174
  }
30130
30175
  var serviceToDaemonSignatures = {
30176
+ [SESSION_PREVIEW_HISTORY_PAGE_LOAD_KIND]: defineMessageSignature(
30177
+ SESSION_PREVIEW_HISTORY_PAGE_LOAD_KIND,
30178
+ encodeSessionPreviewHistoryPageLoad,
30179
+ decodeSessionPreviewHistoryPageLoad
30180
+ ),
30131
30181
  [AGENT_INSTALL_CANCEL_KIND]: defineMessageSignature(
30132
30182
  AGENT_INSTALL_CANCEL_KIND,
30133
30183
  encodeAgentInstallCancelCommand,
@@ -30232,6 +30282,11 @@ function decodeServiceToDaemonMessage(encoded) {
30232
30282
  return signature.decoder(encoded);
30233
30283
  }
30234
30284
  var daemonToServiceSignatures = {
30285
+ [SESSION_PREVIEW_HISTORY_PAGE_LOADED_KIND]: defineMessageSignature(
30286
+ SESSION_PREVIEW_HISTORY_PAGE_LOADED_KIND,
30287
+ encodeSessionPreviewHistoryPageLoaded,
30288
+ decodeSessionPreviewHistoryPageLoaded
30289
+ ),
30235
30290
  [SESSION_CONFIG_UPDATED_KIND]: defineMessageSignature(
30236
30291
  SESSION_CONFIG_UPDATED_KIND,
30237
30292
  encodeSessionConfigUpdatedEvent,
@@ -30411,7 +30466,7 @@ function createDaemonConfig(connection, agents = [], installableAgents = [], loc
30411
30466
 
30412
30467
  // src/daemon-manager.ts
30413
30468
  import { spawn as spawn6 } from "node:child_process";
30414
- import { createHash as createHash8, randomBytes } from "node:crypto";
30469
+ import { createHash as createHash9, randomBytes } from "node:crypto";
30415
30470
  import { readFile as readFile3, unlink as unlink2, writeFile as writeFile5 } from "node:fs/promises";
30416
30471
  import { createConnection, createServer } from "node:net";
30417
30472
  import { tmpdir } from "node:os";
@@ -31245,7 +31300,7 @@ var AuditStore = class {
31245
31300
  };
31246
31301
 
31247
31302
  // src/run-daemon.ts
31248
- import { createHash as createHash7, randomUUID as randomUUID9 } from "node:crypto";
31303
+ import { createHash as createHash8, randomUUID as randomUUID9 } from "node:crypto";
31249
31304
  import { join as join19 } from "node:path";
31250
31305
  import { styleText } from "node:util";
31251
31306
 
@@ -32140,7 +32195,7 @@ var AcpActivity = class _AcpActivity {
32140
32195
  toolKind;
32141
32196
  content;
32142
32197
  detail;
32143
- constructor(activityId, activityType, input2, locations, name2, output2, sequence, status, title2, toolKind, content = [], detail = captureActivityDetail(content, input2, output2)) {
32198
+ constructor(activityId, activityType, input2, locations, name2, output2, sequence, status, title2, toolKind2, content = [], detail = captureActivityDetail(content, input2, output2)) {
32144
32199
  this.activityId = activityId;
32145
32200
  this.activityType = activityType;
32146
32201
  this.input = input2;
@@ -32150,7 +32205,7 @@ var AcpActivity = class _AcpActivity {
32150
32205
  this.sequence = sequence;
32151
32206
  this.status = status;
32152
32207
  this.title = title2;
32153
- this.toolKind = toolKind;
32208
+ this.toolKind = toolKind2;
32154
32209
  this.content = content;
32155
32210
  this.detail = detail;
32156
32211
  }
@@ -32807,6 +32862,9 @@ function sessionConfigProtocolForAgent(_agentId) {
32807
32862
  }
32808
32863
 
32809
32864
  // src/acp/session-contracts.ts
32865
+ var acpNativeHistoryReader = {
32866
+ access: () => ({ kind: "acp" })
32867
+ };
32810
32868
  var NullAcpSessionObserver = class {
32811
32869
  onSessionEventV2 = (_sessionId, _event, _position) => Promise.resolve();
32812
32870
  onCommands = () => Promise.resolve();
@@ -38457,6 +38515,15 @@ function eventPage(sessionGenerationId, eventCount, eventLimit, cursor, read) {
38457
38515
  truncated: startPosition > 0
38458
38516
  };
38459
38517
  }
38518
+ function pageAcpSessionEventsV2(sessionGenerationId, events, eventLimit, cursor) {
38519
+ return eventPage(
38520
+ sessionGenerationId,
38521
+ events.length,
38522
+ eventLimit,
38523
+ cursor,
38524
+ (startPosition, endPosition) => events.slice(startPosition - 1, endPosition)
38525
+ );
38526
+ }
38460
38527
  var MemoryAcpSessionEventStoreV2 = class {
38461
38528
  #events = /* @__PURE__ */ new Map();
38462
38529
  #session = (sessionId) => {
@@ -40579,6 +40646,147 @@ function isNativeChatSessionId(agentId, sessionId) {
40579
40646
  return (agentId === "codex" || agentId === "claude" || agentId === "pi") && /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/iu.test(sessionId);
40580
40647
  }
40581
40648
 
40649
+ // src/native-sessions/native-history-events-v2.ts
40650
+ import { createHash as createHash4 } from "node:crypto";
40651
+ function contentBlock(content) {
40652
+ switch (content.type) {
40653
+ case "text":
40654
+ return { text: content.text, type: "text" };
40655
+ case "image":
40656
+ return {
40657
+ data: content.data,
40658
+ mimeType: content.mimeType,
40659
+ type: "image",
40660
+ ...content.uri.length === 0 ? {} : { uri: content.uri }
40661
+ };
40662
+ case "resource_link":
40663
+ return {
40664
+ name: content.name.length === 0 ? content.uri : content.name,
40665
+ type: "resource_link",
40666
+ uri: content.uri,
40667
+ ...content.mimeType.length === 0 ? {} : { mimeType: content.mimeType }
40668
+ };
40669
+ case "resource":
40670
+ return {
40671
+ resource: content.text.length > 0 ? {
40672
+ text: content.text,
40673
+ uri: content.uri,
40674
+ ...content.mimeType.length === 0 ? {} : { mimeType: content.mimeType }
40675
+ } : {
40676
+ blob: content.data,
40677
+ uri: content.uri,
40678
+ ...content.mimeType.length === 0 ? {} : { mimeType: content.mimeType }
40679
+ },
40680
+ type: "resource"
40681
+ };
40682
+ case "diff":
40683
+ case "terminal":
40684
+ case "video":
40685
+ return null;
40686
+ default: {
40687
+ const unhandled = content.type;
40688
+ throw new Error(`Unknown native history content: ${String(unhandled)}`);
40689
+ }
40690
+ }
40691
+ }
40692
+ function toolContent2(content) {
40693
+ if (content.type === "diff") {
40694
+ return {
40695
+ newText: content.newText,
40696
+ path: content.path,
40697
+ type: "diff",
40698
+ ...content.oldText.length === 0 ? {} : { oldText: content.oldText }
40699
+ };
40700
+ }
40701
+ if (content.type === "terminal") {
40702
+ return { terminalId: content.terminalId, type: "terminal" };
40703
+ }
40704
+ const block = contentBlock(content);
40705
+ return block === null ? null : { content: block, type: "content" };
40706
+ }
40707
+ function toolKind(value) {
40708
+ switch (value) {
40709
+ case "read":
40710
+ case "edit":
40711
+ case "delete":
40712
+ case "move":
40713
+ case "search":
40714
+ case "execute":
40715
+ case "think":
40716
+ case "fetch":
40717
+ case "switch_mode":
40718
+ case "other":
40719
+ return value;
40720
+ default:
40721
+ return "other";
40722
+ }
40723
+ }
40724
+ function toolStatus(value) {
40725
+ switch (value) {
40726
+ case "pending":
40727
+ return "pending";
40728
+ case "running":
40729
+ case "in_progress":
40730
+ return "in_progress";
40731
+ case "completed":
40732
+ return "completed";
40733
+ default:
40734
+ return "failed";
40735
+ }
40736
+ }
40737
+ function activityEvent(activity2) {
40738
+ const content = activity2.content.flatMap((item) => {
40739
+ const converted = toolContent2(item);
40740
+ return converted === null ? [] : [converted];
40741
+ });
40742
+ return {
40743
+ payload: {
40744
+ content,
40745
+ kind: toolKind(activity2.toolKind),
40746
+ locations: activity2.locations.map((path3) => ({ path: path3 })),
40747
+ rawInput: activity2.input,
40748
+ rawOutput: activity2.output,
40749
+ sessionUpdate: "tool_call",
40750
+ status: toolStatus(activity2.status),
40751
+ title: activity2.title,
40752
+ toolCallId: activity2.activityId,
40753
+ ...activity2.name.length === 0 ? {} : { name: activity2.name }
40754
+ },
40755
+ type: "acp"
40756
+ };
40757
+ }
40758
+ function contentEvent(sessionUpdate, messageId, content) {
40759
+ return { payload: { content, messageId, sessionUpdate }, type: "acp" };
40760
+ }
40761
+ function historyEvents(history) {
40762
+ return history.messages.flatMap((message, index2) => {
40763
+ const messageId = `native-history-${index2.toString()}`;
40764
+ const sessionUpdate = message.role === "user" ? "user_message_chunk" : "agent_message_chunk";
40765
+ const images = (message.images ?? []).map(
40766
+ (image) => contentEvent(sessionUpdate, messageId, {
40767
+ data: image.data,
40768
+ mimeType: image.mimeType,
40769
+ type: "image"
40770
+ })
40771
+ );
40772
+ const text2 = message.text.length === 0 ? [] : [contentEvent(sessionUpdate, messageId, { text: message.text, type: "text" })];
40773
+ if (message.role === "user") {
40774
+ return [...images, ...text2];
40775
+ }
40776
+ const activities = message.activities.map(activityEvent);
40777
+ const content = message.content.flatMap((item) => {
40778
+ const converted = contentBlock(item);
40779
+ return converted === null ? [] : [contentEvent(sessionUpdate, messageId, converted)];
40780
+ });
40781
+ return [...activities, ...content, ...images, ...text2];
40782
+ });
40783
+ }
40784
+ function nativeHistoryEventsV2(nativeSessionId, history, eventLimit, cursor) {
40785
+ const events = historyEvents(history);
40786
+ const generationId = createHash4("sha256").update(nativeSessionId).update("\0").update(JSON.stringify(events)).digest("hex");
40787
+ return pageAcpSessionEventsV2(generationId, events, eventLimit, cursor);
40788
+ }
40789
+
40582
40790
  // src/acp/process-capacity.ts
40583
40791
  var AcpProcessCapacityLease = class {
40584
40792
  #releaseCapacity;
@@ -40791,7 +40999,7 @@ var AgentRuntimeManager = class {
40791
40999
  #onSessionStatusChanged;
40792
41000
  #contentExternalizer;
40793
41001
  #observer;
40794
- constructor(observer = new NullAcpSessionObserver(), store = new MemoryAcpSessionStore(), nativeHistoryReader = null, sessionIdentity = "assigned", onSessionStatusChanged = () => void 0, contentExternalizer = new AcpContentExternalizer(new UnretainedExternalContentStore())) {
41002
+ constructor(observer = new NullAcpSessionObserver(), store = new MemoryAcpSessionStore(), nativeHistoryReader = acpNativeHistoryReader, sessionIdentity = "assigned", onSessionStatusChanged = () => void 0, contentExternalizer = new AcpContentExternalizer(new UnretainedExternalContentStore())) {
40795
41003
  this.#observer = observer;
40796
41004
  this.#store = store;
40797
41005
  this.#nativeHistoryReader = nativeHistoryReader;
@@ -41321,6 +41529,14 @@ var AgentRuntimeManager = class {
41321
41529
  }
41322
41530
  this.#nativeOperations.add(key);
41323
41531
  try {
41532
+ const historyAccess = this.#nativeHistoryReader.access(options2);
41533
+ if (historyAccess.kind === "direct") {
41534
+ const history = await historyAccess.read(nativeSessionId, () => null);
41535
+ if (history.status === "unavailable") {
41536
+ throw new AcpExecutionError(history.cause.message, {}, history.cause.code);
41537
+ }
41538
+ return nativeHistoryEventsV2(nativeSessionId, history, eventLimit, cursor);
41539
+ }
41324
41540
  return await this.#queryProcesses.previewEventsV2(options2, nativeSessionId, eventLimit, cursor);
41325
41541
  } finally {
41326
41542
  this.#nativeOperations.delete(key);
@@ -41330,15 +41546,9 @@ var AgentRuntimeManager = class {
41330
41546
  return await this.#executionProcesses.use(options2.sessionId, async () => {
41331
41547
  const runtime = await this.ensureSession(options2);
41332
41548
  const stored = this.#store.read(options2.sessionId);
41333
- if (stored instanceof FoundAcpStoredSession && this.#nativeHistoryReader !== null) {
41334
- const history = await this.#nativeHistoryReader.read(
41335
- options2,
41336
- stored.session.nativeSessionId,
41337
- runtime.nativeHistoryTurn
41338
- );
41339
- if (history !== null) {
41340
- return history;
41341
- }
41549
+ const historyAccess = this.#nativeHistoryReader.access(options2);
41550
+ if (stored instanceof FoundAcpStoredSession && historyAccess.kind === "direct") {
41551
+ return await historyAccess.read(stored.session.nativeSessionId, runtime.nativeHistoryTurn);
41342
41552
  }
41343
41553
  return await runtime.loadHistory(options2.signal);
41344
41554
  });
@@ -42231,7 +42441,7 @@ import { WebSocket as WebSocket2 } from "undici";
42231
42441
  import { WebSocket } from "undici";
42232
42442
 
42233
42443
  // src/prompt-artifact-resolver.ts
42234
- import { createHash as createHash4 } from "node:crypto";
42444
+ import { createHash as createHash5 } from "node:crypto";
42235
42445
  import { fetch as fetch4 } from "undici";
42236
42446
  var ARTIFACT_SCHEME = "mobius-artifact:";
42237
42447
  var ARTIFACT_DOWNLOAD_TIMEOUT_MILLISECONDS = 2e4;
@@ -42369,7 +42579,7 @@ async function download(config2, command, reference, signal) {
42369
42579
  );
42370
42580
  }
42371
42581
  const bytes = await responseBytes(response, reference.byteLength, requestSignal);
42372
- if (createHash4("sha256").update(bytes).digest("hex") !== reference.sha256) {
42582
+ if (createHash5("sha256").update(bytes).digest("hex") !== reference.sha256) {
42373
42583
  throw new PromptArtifactError(
42374
42584
  "artifact_integrity_failed",
42375
42585
  "The prompt artifact failed integrity validation"
@@ -43390,6 +43600,14 @@ var historyItemSchema = external_exports.discriminatedUnion("type", [
43390
43600
  dynamicToolCallSchema,
43391
43601
  planSchema
43392
43602
  ]);
43603
+ var CodexHistoryResponseError = class extends Error {
43604
+ code;
43605
+ constructor(response) {
43606
+ super(response.message);
43607
+ this.code = response.code;
43608
+ this.name = "CodexHistoryResponseError";
43609
+ }
43610
+ };
43393
43611
  function bounded(value, maximum) {
43394
43612
  return value.slice(0, maximum);
43395
43613
  }
@@ -43429,7 +43647,7 @@ function formatted(value) {
43429
43647
  }
43430
43648
  return JSON.stringify(value) ?? "";
43431
43649
  }
43432
- function toolStatus(status) {
43650
+ function toolStatus2(status) {
43433
43651
  return status === "inProgress" ? "running" : status === "completed" ? "completed" : "failed";
43434
43652
  }
43435
43653
  function diffDisplayContent(path3, newText) {
@@ -43636,7 +43854,7 @@ function decodeHistory(thread, value, options) {
43636
43854
  formatted_output: historyItem.aggregatedOutput ?? "",
43637
43855
  ...historyItem.exitCode == null ? {} : { exit_code: historyItem.exitCode }
43638
43856
  }),
43639
- status: toolStatus(historyItem.status),
43857
+ status: toolStatus2(historyItem.status),
43640
43858
  title: historyItem.command,
43641
43859
  toolKind: action
43642
43860
  })
@@ -43658,7 +43876,7 @@ function decodeHistory(thread, value, options) {
43658
43876
  locations: paths,
43659
43877
  name: "",
43660
43878
  output: "",
43661
- status: toolStatus(historyItem.status),
43879
+ status: toolStatus2(historyItem.status),
43662
43880
  title: paths.join(", "),
43663
43881
  toolKind: "edit"
43664
43882
  })
@@ -43676,7 +43894,7 @@ function decodeHistory(thread, value, options) {
43676
43894
  locations: [],
43677
43895
  name: historyItem.tool,
43678
43896
  output: formatted(historyItem.error ?? historyItem.result),
43679
- status: toolStatus(historyItem.status),
43897
+ status: toolStatus2(historyItem.status),
43680
43898
  title: `${historyItem.server}/${historyItem.tool}`,
43681
43899
  toolKind: "other"
43682
43900
  })
@@ -43694,7 +43912,7 @@ function decodeHistory(thread, value, options) {
43694
43912
  locations: [],
43695
43913
  name: historyItem.tool,
43696
43914
  output: formatted(historyItem.contentItems),
43697
- status: toolStatus(historyItem.status),
43915
+ status: toolStatus2(historyItem.status),
43698
43916
  title: historyItem.namespace == null ? historyItem.tool : `${historyItem.namespace}/${historyItem.tool}`,
43699
43917
  toolKind: "other"
43700
43918
  })
@@ -43860,7 +44078,7 @@ async function readCodexHistoryWithOptions(agent, cwd, nativeSessionId, signal,
43860
44078
  fail(
43861
44079
  new AcpExecutionError(
43862
44080
  "Saved Codex history could not be read.",
43863
- { cause: message.error },
44081
+ { cause: new CodexHistoryResponseError(message.error) },
43864
44082
  "native_history_unavailable"
43865
44083
  )
43866
44084
  );
@@ -44368,7 +44586,7 @@ var NativeSessionService = class {
44368
44586
  };
44369
44587
 
44370
44588
  // src/relay-connection/daemon-operation-state.ts
44371
- import { createHash as createHash5, randomUUID as randomUUID6 } from "node:crypto";
44589
+ import { createHash as createHash6, randomUUID as randomUUID6 } from "node:crypto";
44372
44590
  var MAX_TERMINAL_RECEIPTS = 1024;
44373
44591
  function isTerminal(state) {
44374
44592
  return state === "succeeded" || state === "failed" || state === "cancelled";
@@ -44377,7 +44595,7 @@ var DaemonOperationState = class {
44377
44595
  #executions = /* @__PURE__ */ new Map();
44378
44596
  #terminalCount = 0;
44379
44597
  claimExecution = (commandId, sessionId, commandJson) => {
44380
- const commandHash = createHash5("sha256").update(commandJson).digest("hex");
44598
+ const commandHash = createHash6("sha256").update(commandJson).digest("hex");
44381
44599
  const existing = this.#executions.get(commandId);
44382
44600
  if (existing !== void 0) {
44383
44601
  if (existing.sessionId !== sessionId || existing.commandHash !== commandHash) {
@@ -44599,7 +44817,7 @@ import { WebSocket as WebSocket5 } from "undici";
44599
44817
  import { WebSocket as WebSocket3 } from "undici";
44600
44818
 
44601
44819
  // src/agent-catalog/discover-agent-settings.ts
44602
- import { createHash as createHash6 } from "node:crypto";
44820
+ import { createHash as createHash7 } from "node:crypto";
44603
44821
 
44604
44822
  // src/agent-catalog/agent-settings-base.ts
44605
44823
  var AgentSettingsConfigurationError = class extends Error {
@@ -45063,7 +45281,7 @@ function settingsRevision(agent, reportedAgentVersion, settings, modelEffort) {
45063
45281
  unsupportedModelIds: modelEffort.unsupportedModelIds,
45064
45282
  valuesByModel: {}
45065
45283
  };
45066
- return createHash6("sha256").update(
45284
+ return createHash7("sha256").update(
45067
45285
  JSON.stringify({
45068
45286
  adapterVersion: agent.kind === "acp-adapter-process" ? agent.adapterVersion : agent.agentVersion,
45069
45287
  agentId: agent.id,
@@ -45375,7 +45593,7 @@ async function executeSessionLiveHistoryV2PageLoad(socket, command, config2, dir
45375
45593
  },
45376
45594
  queuedPromptRequests: recovery.queuedPromptRequests
45377
45595
  },
45378
- kind: "session.live-history.v2.page.loaded",
45596
+ kind: SESSION_LIVE_HISTORY_V2_PAGE_LOADED_KIND,
45379
45597
  requestId: command.requestId,
45380
45598
  sessionId: command.sessionId
45381
45599
  });
@@ -45404,6 +45622,81 @@ async function executeSessionLiveHistoryV2PageLoad(socket, command, config2, dir
45404
45622
  }
45405
45623
  }
45406
45624
  }
45625
+ async function executeSessionPreviewHistoryPageLoad(socket, command, config2, directories, audit, diagnostics, sessions, eventLogV2, signal) {
45626
+ try {
45627
+ const resolved = await resolveSessionDirectories(
45628
+ directories,
45629
+ config2.bindingId,
45630
+ command.directoryId,
45631
+ command.additionalDirectoryIds,
45632
+ signal
45633
+ );
45634
+ const replay = await sessions.previewNativeSessionEventsV2(
45635
+ {
45636
+ additionalDirectories: resolved.additionalDirectories,
45637
+ agent: config2.catalog.find(command.agentId),
45638
+ cwd: resolved.cwd,
45639
+ sessionId: command.sessionId,
45640
+ signal
45641
+ },
45642
+ command.sessionId,
45643
+ command.eventLimit,
45644
+ command.cursor
45645
+ );
45646
+ signal.throwIfAborted();
45647
+ const events = replay.events.map(
45648
+ (event, index2) => eventLogV2.event(
45649
+ command.sessionId,
45650
+ replay.sessionGenerationId,
45651
+ replay.startPosition + index2,
45652
+ event,
45653
+ "1970-01-01T00:00:00.000Z"
45654
+ )
45655
+ );
45656
+ const tailCursor = events.at(-1)?.eventId ?? "";
45657
+ audit.record({
45658
+ commandId: command.requestId,
45659
+ event: "session_event_log_v2_loaded",
45660
+ sessionId: command.sessionId
45661
+ });
45662
+ send(socket, {
45663
+ events: {
45664
+ events: {
45665
+ events,
45666
+ nextCursor: replay.nextCursor,
45667
+ sessionGenerationId: replay.sessionGenerationId,
45668
+ tailCursor,
45669
+ truncated: replay.truncated,
45670
+ version: 2
45671
+ },
45672
+ queuedPromptRequests: []
45673
+ },
45674
+ kind: SESSION_PREVIEW_HISTORY_PAGE_LOADED_KIND,
45675
+ requestId: command.requestId,
45676
+ sessionId: command.sessionId
45677
+ });
45678
+ } catch (error62) {
45679
+ if (!signal.aborted) {
45680
+ diagnostics.daemonDiagnostic(
45681
+ "session_history_v2_load_failed",
45682
+ command.requestId,
45683
+ {
45684
+ agentId: command.agentId,
45685
+ code: operationErrorCode(error62),
45686
+ sessionId: command.sessionId
45687
+ },
45688
+ error62
45689
+ );
45690
+ audit.record({
45691
+ commandId: command.requestId,
45692
+ details: { agentId: command.agentId, code: operationErrorCode(error62) },
45693
+ event: "session_history_v2_load_failed",
45694
+ sessionId: command.sessionId
45695
+ });
45696
+ reportOperationFailure(socket, command.requestId, command.sessionId, error62);
45697
+ }
45698
+ }
45699
+ }
45407
45700
 
45408
45701
  // src/acp/session-config/apply-session-configuration.ts
45409
45702
  import { randomUUID as randomUUID7 } from "node:crypto";
@@ -46153,6 +46446,20 @@ function createDaemonCommandHandler({
46153
46446
  );
46154
46447
  return;
46155
46448
  }
46449
+ if (kind === SESSION_PREVIEW_HISTORY_PAGE_LOAD_KIND) {
46450
+ void executeSessionPreviewHistoryPageLoad(
46451
+ socket,
46452
+ message,
46453
+ config2,
46454
+ directories,
46455
+ audit,
46456
+ diagnostics,
46457
+ sessions,
46458
+ eventLogV2,
46459
+ signal
46460
+ );
46461
+ return;
46462
+ }
46156
46463
  if (kind === NATIVE_SESSION_CANCEL_KIND) {
46157
46464
  nativeRequestHandler.cancel(message);
46158
46465
  return;
@@ -47124,7 +47431,7 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
47124
47431
  publishCatalog: async (installationSignal) => await publishAgentCatalog(config2, installationSignal),
47125
47432
  stateDirectory
47126
47433
  });
47127
- const channelHash = createHash7("sha256").update(config2.channelId).digest("hex");
47434
+ const channelHash = createHash8("sha256").update(config2.channelId).digest("hex");
47128
47435
  const sessionDatabase = openAcpSessionDatabase(join19(stateDirectory, "sessions", `${channelHash}.sqlite`));
47129
47436
  let eventsV2;
47130
47437
  try {
@@ -47150,13 +47457,16 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
47150
47457
  }, eventLogV2.record),
47151
47458
  sessionStore,
47152
47459
  {
47153
- read: async (options2, nativeSessionId, nativeTurn) => options2.agent.id === "codex" ? (await readCodexFullHistory(
47154
- options2.agent,
47155
- options2.cwd,
47156
- nativeSessionId,
47157
- options2.signal,
47158
- nativeTurn
47159
- )).history : null
47460
+ access: (options2) => options2.agent.id === "codex" ? {
47461
+ kind: "direct",
47462
+ read: async (nativeSessionId, nativeTurn) => (await readCodexFullHistory(
47463
+ options2.agent,
47464
+ options2.cwd,
47465
+ nativeSessionId,
47466
+ options2.signal,
47467
+ nativeTurn
47468
+ )).history
47469
+ } : { kind: "acp" }
47160
47470
  },
47161
47471
  "native",
47162
47472
  publisher.publishStatus,
@@ -47421,7 +47731,7 @@ function isRecord12(value) {
47421
47731
  return typeof value === "object" && value !== null && !Array.isArray(value);
47422
47732
  }
47423
47733
  function controlSocketPath(stateDirectory) {
47424
- const installationHash = createHash8("sha256").update(stateDirectory).digest("hex").slice(0, 32);
47734
+ const installationHash = createHash9("sha256").update(stateDirectory).digest("hex").slice(0, 32);
47425
47735
  return process.platform === "win32" ? `\\\\.\\pipe\\mobius-${installationHash}` : join20(tmpdir(), `mobius-${installationHash}.sock`);
47426
47736
  }
47427
47737
  function controlTokenPath(stateDirectory) {