@moxt-ai/mobius 0.0.69 → 0.0.70

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -20893,11 +20893,32 @@ function parseNativeHistoryText(text3) {
20893
20893
  });
20894
20894
  return { text: plainText, images };
20895
20895
  }
20896
- var historyMessage = external_exports.strictObject({
20897
- role: external_exports.enum(["user", "assistant"]),
20896
+ var nativeMessageActivitySchema = external_exports.strictObject({
20897
+ activityId: external_exports.string().min(1).max(128),
20898
+ activityType: external_exports.string().min(1).max(128),
20899
+ content: external_exports.array(displayContentSchema).max(100).readonly(),
20900
+ input: external_exports.string().max(1e5),
20901
+ locations: external_exports.array(external_exports.string().min(1).max(2048)).max(100).readonly(),
20902
+ name: external_exports.string().max(128),
20903
+ output: external_exports.string().max(1e5),
20904
+ sequence: external_exports.number().int().nonnegative(),
20905
+ status: external_exports.string().min(1).max(64),
20906
+ title: external_exports.string().max(500),
20907
+ toolKind: external_exports.string().max(64)
20908
+ }).readonly();
20909
+ var userHistoryMessage = external_exports.strictObject({
20910
+ role: external_exports.literal("user"),
20898
20911
  text: external_exports.string().max(SESSION_HISTORY_CHARACTER_LIMIT),
20899
20912
  images: external_exports.array(historyImage).max(8).readonly().optional()
20900
20913
  }).readonly();
20914
+ var assistantHistoryMessage = external_exports.strictObject({
20915
+ activities: external_exports.array(nativeMessageActivitySchema).max(100).readonly().default([]),
20916
+ content: external_exports.array(displayContentSchema).max(100).readonly().default([]),
20917
+ role: external_exports.literal("assistant"),
20918
+ text: external_exports.string().max(SESSION_HISTORY_CHARACTER_LIMIT),
20919
+ images: external_exports.array(historyImage).max(8).readonly().optional()
20920
+ }).readonly();
20921
+ var historyMessage = external_exports.discriminatedUnion("role", [userHistoryMessage, assistantHistoryMessage]);
20901
20922
  var availableSessionHistoryObjectSchema = external_exports.strictObject({
20902
20923
  status: external_exports.literal("available"),
20903
20924
  messages: external_exports.array(historyMessage).max(SESSION_HISTORY_MESSAGE_LIMIT).readonly(),
@@ -20906,19 +20927,28 @@ var availableSessionHistoryObjectSchema = external_exports.strictObject({
20906
20927
  coveredMessageIds: external_exports.array(external_exports.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}:(?:user|agent)$/)).max(2e4).readonly().default([])
20907
20928
  });
20908
20929
  var availableSessionHistorySchema = availableSessionHistoryObjectSchema.readonly();
20909
- var unavailableSessionHistoryObjectSchema = external_exports.strictObject({ status: external_exports.literal("unavailable") });
20930
+ var unavailableSessionHistoryObjectSchema = external_exports.strictObject({
20931
+ status: external_exports.literal("unavailable"),
20932
+ cause: external_exports.strictObject({
20933
+ code: external_exports.string().regex(/^[a-z][a-z0-9_]{0,127}$/),
20934
+ message: external_exports.string().min(1).max(1e3)
20935
+ }).readonly()
20936
+ });
20910
20937
  var unavailableSessionHistorySchema = unavailableSessionHistoryObjectSchema.readonly();
20911
20938
  function withinHistoryContentLimits(history) {
20912
20939
  if (history.status === "unavailable" || history.messages === void 0) {
20913
20940
  return true;
20914
20941
  }
20915
- return history.messages.reduce((total, message) => total + message.text.length, 0) <= SESSION_HISTORY_CHARACTER_LIMIT && history.messages.reduce(
20942
+ return history.messages.reduce(
20943
+ (total, message) => total + message.text.length + (message.role === "assistant" ? JSON.stringify(message.activities).length + JSON.stringify(message.content).length : 0),
20944
+ 0
20945
+ ) <= SESSION_HISTORY_CHARACTER_LIMIT && history.messages.reduce(
20916
20946
  (total, message) => total + (message.images ?? []).reduce((size, image) => size + image.data.length, 0),
20917
20947
  0
20918
20948
  ) <= SESSION_HISTORY_IMAGE_CHARACTER_LIMIT;
20919
20949
  }
20920
20950
  var sessionHistorySchema = external_exports.discriminatedUnion("status", [availableSessionHistorySchema, unavailableSessionHistorySchema]).refine(withinHistoryContentLimits);
20921
- var sessionHistoryPageSchema = external_exports.discriminatedUnion("status", [
20951
+ var nativeMessagePageSchema = external_exports.discriminatedUnion("status", [
20922
20952
  availableSessionHistoryObjectSchema.extend({ nextCursor: external_exports.string().max(512).nullable() }).readonly(),
20923
20953
  unavailableSessionHistoryObjectSchema.extend({ nextCursor: external_exports.null() }).readonly()
20924
20954
  ]).refine(withinHistoryContentLimits);
@@ -22701,8 +22731,8 @@ function captureActivityDetail(content3, input2, output2) {
22701
22731
  originalBytes
22702
22732
  };
22703
22733
  }
22704
- function recordedDetail(activity) {
22705
- return activity?.detail.kind === "recorded" ? activity.detail : null;
22734
+ function recordedDetail(activity2) {
22735
+ return activity2?.detail.kind === "recorded" ? activity2.detail : null;
22706
22736
  }
22707
22737
  function emptyDisplayContent(type) {
22708
22738
  return {
@@ -22920,7 +22950,7 @@ var AcpActivityTracker = class {
22920
22950
  const previous2 = this.#activities.get(key);
22921
22951
  const identity2 = this.#identity(key);
22922
22952
  const fullOutput = `${recordedDetail(previous2)?.output ?? previous2?.output ?? ""}${text3}`;
22923
- const activity = new AcpActivity(
22953
+ const activity2 = new AcpActivity(
22924
22954
  identity2.id,
22925
22955
  activityType,
22926
22956
  "",
@@ -22934,7 +22964,7 @@ var AcpActivityTracker = class {
22934
22964
  [],
22935
22965
  captureActivityDetail([], "", fullOutput)
22936
22966
  );
22937
- await this.#record(key, activity);
22967
+ await this.#record(key, activity2);
22938
22968
  this.#activeNarrativeKey = key;
22939
22969
  };
22940
22970
  recordPlan = async (plan) => {
@@ -23056,21 +23086,21 @@ var AcpActivityTracker = class {
23056
23086
  return;
23057
23087
  }
23058
23088
  this.#activeNarrativeKey = "";
23059
- const activity = this.#activities.get(key);
23060
- if (activity === void 0) {
23089
+ const activity2 = this.#activities.get(key);
23090
+ if (activity2 === void 0) {
23061
23091
  return;
23062
23092
  }
23063
- const completed = activity.complete();
23064
- if (completed !== activity) {
23093
+ const completed = activity2.complete();
23094
+ if (completed !== activity2) {
23065
23095
  await this.#record(key, completed);
23066
23096
  }
23067
23097
  };
23068
23098
  finish = async () => {
23069
23099
  await this.finishNarrative();
23070
23100
  const entries = [...this.#activities.entries()].sort((left, right) => left[1].sequence - right[1].sequence);
23071
- for (const [key, activity] of entries) {
23072
- const completed = activity.complete();
23073
- if (completed !== activity) {
23101
+ for (const [key, activity2] of entries) {
23102
+ const completed = activity2.complete();
23103
+ if (completed !== activity2) {
23074
23104
  await this.#record(key, completed);
23075
23105
  }
23076
23106
  }
@@ -23085,9 +23115,9 @@ var AcpActivityTracker = class {
23085
23115
  this.#identities.set(key, identity2);
23086
23116
  return identity2;
23087
23117
  };
23088
- #record = async (key, activity) => {
23089
- this.#activities.set(key, activity);
23090
- await this.#onActivity(activity);
23118
+ #record = async (key, activity2) => {
23119
+ this.#activities.set(key, activity2);
23120
+ await this.#onActivity(activity2);
23091
23121
  };
23092
23122
  #recordPlanEntries = async (key, entries) => {
23093
23123
  const identity2 = this.#identity(key);
@@ -30715,19 +30745,74 @@ function sessionConfigProtocolForAgent(agentId) {
30715
30745
 
30716
30746
  // src/acp/session-history.ts
30717
30747
  var AcpHistoryReplay = class {
30748
+ #activities = /* @__PURE__ */ new Map();
30718
30749
  #messages = [];
30750
+ #turnActivityIds = /* @__PURE__ */ new Set();
30751
+ #activityTracker = new AcpActivityTracker(async (activity2) => {
30752
+ this.#activities.set(activity2.activityId, activity2);
30753
+ this.#turnActivityIds.add(activity2.activityId);
30754
+ const latest = this.#messages.at(-1);
30755
+ if (latest?.role === "assistant") {
30756
+ this.#messages[this.#messages.length - 1] = {
30757
+ ...latest,
30758
+ activityIds: [...this.#turnActivityIds]
30759
+ };
30760
+ }
30761
+ });
30719
30762
  #lastMessageId = null;
30720
30763
  #characters = 0;
30721
30764
  #truncated = false;
30722
- record = (update) => {
30765
+ record = async (update) => {
30766
+ if (update.sessionUpdate === "agent_thought_chunk") {
30767
+ if (update.content.type === "text") {
30768
+ await this.#activityTracker.recordNarrative(
30769
+ "reasoning",
30770
+ update.messageId ?? "current",
30771
+ update.content.text
30772
+ );
30773
+ }
30774
+ return;
30775
+ }
30776
+ if (update.sessionUpdate === "tool_call") {
30777
+ await this.#activityTracker.recordToolCall(update);
30778
+ return;
30779
+ }
30780
+ if (update.sessionUpdate === "tool_call_update") {
30781
+ await this.#activityTracker.recordToolCallUpdate(update);
30782
+ return;
30783
+ }
30784
+ if (update.sessionUpdate === "plan") {
30785
+ await this.#activityTracker.recordPlan(update);
30786
+ return;
30787
+ }
30788
+ if (update.sessionUpdate === "plan_update") {
30789
+ await this.#activityTracker.recordPlanUpdate(update);
30790
+ return;
30791
+ }
30792
+ if (update.sessionUpdate === "plan_removed") {
30793
+ await this.#activityTracker.removePlan(update);
30794
+ return;
30795
+ }
30723
30796
  if (update.sessionUpdate !== "user_message_chunk" && update.sessionUpdate !== "agent_message_chunk") {
30724
30797
  return;
30725
30798
  }
30726
30799
  if (update.sessionUpdate === "agent_message_chunk" && isProgressMessage(update)) {
30800
+ if (update.content.type === "text") {
30801
+ await this.#activityTracker.recordNarrative(
30802
+ "progress",
30803
+ update.messageId ?? "current",
30804
+ update.content.text
30805
+ );
30806
+ }
30727
30807
  return;
30728
30808
  }
30729
30809
  const role = update.sessionUpdate === "user_message_chunk" ? "user" : "assistant";
30730
30810
  const content3 = update.content;
30811
+ if (role === "assistant" && content3.type !== "text") {
30812
+ await this.#activityTracker.finishNarrative();
30813
+ this.recordAssistantContent(update.messageId ?? null, normalizeContentBlock(content3));
30814
+ return;
30815
+ }
30731
30816
  const text3 = content3.type === "text" ? content3.text : content3.type === "image" ? content3.data.length > 0 ? `[@image](data:${content3.mimeType};base64,${content3.data})` : content3.uri != null && content3.uri.length > 0 ? `[@image](${content3.uri})` : "[image attachment]" : `[${content3.type} attachment]`;
30732
30817
  if (text3.length === 0) {
30733
30818
  return;
@@ -30735,19 +30820,84 @@ var AcpHistoryReplay = class {
30735
30820
  const previous2 = this.#messages.at(-1);
30736
30821
  const id = update.messageId ?? null;
30737
30822
  const continuation = previous2?.role === role && id === this.#lastMessageId;
30823
+ if (role === "user" && !continuation) {
30824
+ await this.#activityTracker.finish();
30825
+ this.#turnActivityIds.clear();
30826
+ }
30738
30827
  const combined = continuation ? `${previous2.text}${text3}` : text3;
30739
30828
  if (continuation) {
30740
30829
  this.#messages.pop();
30741
30830
  this.#characters -= previous2.text.length;
30742
30831
  }
30743
- const bounded = combined.slice(-SESSION_HISTORY_CHARACTER_LIMIT);
30744
- this.#truncated ||= bounded.length < combined.length;
30745
- this.#messages.push({
30746
- role,
30747
- text: bounded
30748
- });
30749
- this.#characters += bounded.length;
30832
+ const bounded2 = combined.slice(-SESSION_HISTORY_CHARACTER_LIMIT);
30833
+ this.#truncated ||= bounded2.length < combined.length;
30834
+ this.#messages.push(
30835
+ role === "user" ? { role, text: bounded2 } : {
30836
+ activityIds: [...this.#turnActivityIds],
30837
+ content: previous2?.role === "assistant" ? previous2.content : [],
30838
+ role,
30839
+ text: bounded2
30840
+ }
30841
+ );
30842
+ this.#characters += bounded2.length;
30750
30843
  this.#lastMessageId = id;
30844
+ this.trimMessages();
30845
+ };
30846
+ snapshot = async () => {
30847
+ await this.#activityTracker.finish();
30848
+ return {
30849
+ status: "available",
30850
+ messages: this.#messages.map(
30851
+ (message) => message.role === "user" ? message : {
30852
+ role: "assistant",
30853
+ text: message.text,
30854
+ content: message.content,
30855
+ activities: message.activityIds.flatMap((id) => {
30856
+ const activity2 = this.#activities.get(id);
30857
+ return activity2 === void 0 ? [] : [
30858
+ {
30859
+ activityId: activity2.activityId,
30860
+ activityType: activity2.activityType,
30861
+ content: activity2.content,
30862
+ input: activity2.input,
30863
+ locations: activity2.locations,
30864
+ name: activity2.name,
30865
+ output: activity2.output,
30866
+ sequence: activity2.sequence,
30867
+ status: activity2.status,
30868
+ title: activity2.title,
30869
+ toolKind: activity2.toolKind
30870
+ }
30871
+ ];
30872
+ })
30873
+ }
30874
+ ),
30875
+ truncated: this.#truncated,
30876
+ coveredCommandIds: [],
30877
+ coveredMessageIds: []
30878
+ };
30879
+ };
30880
+ recordAssistantContent = (messageId, content3) => {
30881
+ const previous2 = this.#messages.at(-1);
30882
+ const continuation = previous2?.role === "assistant" && messageId === this.#lastMessageId;
30883
+ if (continuation) {
30884
+ this.#messages[this.#messages.length - 1] = {
30885
+ ...previous2,
30886
+ activityIds: [...this.#turnActivityIds],
30887
+ content: [...previous2.content, content3]
30888
+ };
30889
+ } else {
30890
+ this.#messages.push({
30891
+ activityIds: [...this.#turnActivityIds],
30892
+ content: [content3],
30893
+ role: "assistant",
30894
+ text: ""
30895
+ });
30896
+ }
30897
+ this.#lastMessageId = messageId;
30898
+ this.trimMessages();
30899
+ };
30900
+ trimMessages = () => {
30751
30901
  while (this.#messages.length > SESSION_HISTORY_PREVIEW_MESSAGE_LIMIT || this.#characters > SESSION_HISTORY_CHARACTER_LIMIT) {
30752
30902
  const removed = this.#messages.shift();
30753
30903
  if (removed !== void 0) {
@@ -30756,13 +30906,6 @@ var AcpHistoryReplay = class {
30756
30906
  this.#truncated = true;
30757
30907
  }
30758
30908
  };
30759
- snapshot = () => ({
30760
- status: "available",
30761
- messages: [...this.#messages],
30762
- truncated: this.#truncated,
30763
- coveredCommandIds: [],
30764
- coveredMessageIds: []
30765
- });
30766
30909
  };
30767
30910
 
30768
30911
  // src/acp/session-store.ts
@@ -31688,7 +31831,13 @@ var AcpProcessSession = class _AcpProcessSession {
31688
31831
  );
31689
31832
  loadHistory = async (signal) => {
31690
31833
  if (!this.#capabilities.loadSession) {
31691
- return { status: "unavailable" };
31834
+ return {
31835
+ status: "unavailable",
31836
+ cause: {
31837
+ code: "native_history_unsupported",
31838
+ message: "This Agent restores context but does not provide message history."
31839
+ }
31840
+ };
31692
31841
  }
31693
31842
  const history = new AcpHistoryReplay();
31694
31843
  this.#replay = { kind: "capture", history };
@@ -31709,7 +31858,7 @@ var AcpProcessSession = class _AcpProcessSession {
31709
31858
  );
31710
31859
  await this.#updateTail;
31711
31860
  signal.throwIfAborted();
31712
- return await embedLocalHistoryImages(history.snapshot(), signal);
31861
+ return await embedLocalHistoryImages(await history.snapshot(), signal);
31713
31862
  } finally {
31714
31863
  this.#replay = { kind: "idle" };
31715
31864
  }
@@ -32553,7 +32702,7 @@ var AcpProcessSession = class _AcpProcessSession {
32553
32702
  this.assertNativeSession(notification.sessionId);
32554
32703
  const update = notification.update;
32555
32704
  if (this.#replay.kind === "capture") {
32556
- this.#replay.history.record(update);
32705
+ await this.#replay.history.record(update);
32557
32706
  }
32558
32707
  if (this.#replay.kind !== "idle" && (update.sessionUpdate === "user_message_chunk" || update.sessionUpdate === "agent_message_chunk" || update.sessionUpdate === "agent_thought_chunk" || update.sessionUpdate === "tool_call" || update.sessionUpdate === "tool_call_update" || update.sessionUpdate === "plan" || update.sessionUpdate === "plan_update" || update.sessionUpdate === "plan_removed")) {
32559
32708
  return;
@@ -32844,10 +32993,12 @@ var AcpSessionManager = class {
32844
32993
  #startingProcessCount = 0;
32845
32994
  #transientProcessCount = 0;
32846
32995
  #store;
32996
+ #nativeHistoryReader;
32847
32997
  #observer;
32848
- constructor(observer = new NullAcpSessionObserver(), store = new MemoryAcpSessionStore()) {
32998
+ constructor(observer = new NullAcpSessionObserver(), store = new MemoryAcpSessionStore(), nativeHistoryReader = null) {
32849
32999
  this.#observer = observer;
32850
33000
  this.#store = store;
33001
+ this.#nativeHistoryReader = nativeHistoryReader;
32851
33002
  }
32852
33003
  setObserver = (observer) => {
32853
33004
  this.#observer = observer;
@@ -33609,7 +33760,15 @@ var AcpSessionManager = class {
33609
33760
  loadSessionHistory = async (options) => {
33610
33761
  this.#beginSessionUse(options.sessionId);
33611
33762
  try {
33612
- return await (await this.ensureSession(options)).loadHistory(options.signal);
33763
+ const runtime = await this.ensureSession(options);
33764
+ const stored = this.#store.read(options.sessionId);
33765
+ if (stored instanceof FoundAcpStoredSession && this.#nativeHistoryReader !== null) {
33766
+ const history = await this.#nativeHistoryReader.read(options, stored.session.nativeSessionId);
33767
+ if (history !== null) {
33768
+ return history;
33769
+ }
33770
+ }
33771
+ return await runtime.loadHistory(options.signal);
33613
33772
  } finally {
33614
33773
  this.#endSessionUse(options.sessionId);
33615
33774
  }
@@ -37832,10 +37991,6 @@ var WorkspaceDirectoryService = class {
37832
37991
  };
37833
37992
  };
37834
37993
 
37835
- // src/native-sessions/service.ts
37836
- import { randomUUID as randomUUID2 } from "node:crypto";
37837
- import { basename as basename6 } from "node:path";
37838
-
37839
37994
  // src/native-sessions/codex-history.ts
37840
37995
  import { spawn as spawn4 } from "node:child_process";
37841
37996
  var responseSchema = external_exports.union([
@@ -37853,7 +38008,12 @@ var threadSchema = external_exports.object({
37853
38008
  })
37854
38009
  });
37855
38010
  var turnsSchema = external_exports.object({
37856
- data: external_exports.array(external_exports.object({ items: external_exports.array(external_exports.unknown()).max(1e5) })).max(SESSION_HISTORY_PREVIEW_MESSAGE_LIMIT),
38011
+ data: external_exports.array(
38012
+ external_exports.object({
38013
+ error: external_exports.unknown().nullish(),
38014
+ items: external_exports.array(external_exports.unknown()).max(1e5)
38015
+ })
38016
+ ).max(SESSION_HISTORY_PREVIEW_MESSAGE_LIMIT),
37857
38017
  nextCursor: external_exports.string().nullish()
37858
38018
  });
37859
38019
  var itemTypeSchema = external_exports.object({ type: external_exports.string().min(1).max(80) });
@@ -37863,12 +38023,62 @@ var userMessageSchema = external_exports.object({
37863
38023
  var textSchema = external_exports.object({ text: external_exports.string() });
37864
38024
  var imageSchema = external_exports.object({ url: external_exports.string() });
37865
38025
  var agentMessageSchema = textSchema.extend({ phase: external_exports.string().nullish() });
37866
- function decodeHistory(thread, value) {
38026
+ var reasoningSchema = external_exports.object({
38027
+ id: external_exports.string(),
38028
+ summary: external_exports.array(external_exports.string()).max(1e4),
38029
+ content: external_exports.array(external_exports.string()).max(1e4)
38030
+ });
38031
+ var commandExecutionSchema = external_exports.object({
38032
+ id: external_exports.string(),
38033
+ command: external_exports.string(),
38034
+ cwd: external_exports.string(),
38035
+ status: external_exports.string(),
38036
+ commandActions: external_exports.array(external_exports.object({ type: external_exports.string() }).passthrough()).max(100),
38037
+ aggregatedOutput: external_exports.string().nullish(),
38038
+ exitCode: external_exports.number().int().nullish()
38039
+ });
38040
+ function bounded(value, maximum) {
38041
+ return value.slice(0, maximum);
38042
+ }
38043
+ function activity(activityId, activityType, sequence, fields) {
38044
+ return {
38045
+ activityId: bounded(activityId, 128) || `history-${sequence.toString()}`,
38046
+ activityType,
38047
+ content: [],
38048
+ input: bounded(fields.input, 1e5),
38049
+ locations: fields.locations.filter((location) => location.length > 0).map((location) => bounded(location, 2048)).slice(0, 100),
38050
+ name: bounded(fields.name, 128),
38051
+ output: bounded(fields.output, 1e5),
38052
+ sequence,
38053
+ status: bounded(fields.status, 64),
38054
+ title: bounded(fields.title, 500),
38055
+ toolKind: bounded(fields.toolKind, 64)
38056
+ };
38057
+ }
38058
+ function errorMessage(value) {
38059
+ if (typeof value === "string") {
38060
+ return value;
38061
+ }
38062
+ if (typeof value === "object" && value !== null) {
38063
+ const message = Reflect.get(value, "message");
38064
+ if (typeof message === "string") {
38065
+ return message;
38066
+ }
38067
+ }
38068
+ return JSON.stringify(value) ?? "Codex stopped before completing this turn.";
38069
+ }
38070
+ function messageSize(message) {
38071
+ return message.text.length + (message.role === "assistant" ? JSON.stringify(message.activities).length + JSON.stringify(message.content).length : 0);
38072
+ }
38073
+ function decodeHistory(thread, value, options) {
37867
38074
  const page = turnsSchema.parse(value);
37868
38075
  const messages = [];
37869
38076
  let characters = 0;
37870
38077
  let truncated = page.nextCursor != null;
37871
38078
  for (const turn of page.data.toReversed()) {
38079
+ const activities = [];
38080
+ let sequence = 0;
38081
+ let assistantMessageIndex = null;
37872
38082
  for (const item of turn.items) {
37873
38083
  const { type } = itemTypeSchema.parse(item);
37874
38084
  let message;
@@ -37891,9 +38101,60 @@ function decodeHistory(thread, value) {
37891
38101
  } else if (type === "agentMessage") {
37892
38102
  const agent = agentMessageSchema.parse(item);
37893
38103
  if (agent.phase === "commentary") {
38104
+ if (options.detail === "rich" && agent.text.length > 0) {
38105
+ activities.push(
38106
+ activity(`progress-${sequence.toString()}`, "progress", sequence, {
38107
+ input: "",
38108
+ locations: [],
38109
+ name: "",
38110
+ output: agent.text,
38111
+ status: "completed",
38112
+ title: "Progress",
38113
+ toolKind: ""
38114
+ })
38115
+ );
38116
+ sequence += 1;
38117
+ }
37894
38118
  continue;
37895
38119
  }
37896
- message = { role: "assistant", text: agent.text };
38120
+ message = { activities: activities.slice(-100), content: [], role: "assistant", text: agent.text };
38121
+ } else if (type === "reasoning" && options.detail === "rich") {
38122
+ const reasoning = reasoningSchema.parse(item);
38123
+ const output2 = (reasoning.summary.length > 0 ? reasoning.summary : reasoning.content).join("\n\n");
38124
+ if (output2.length > 0) {
38125
+ activities.push(
38126
+ activity(reasoning.id, "reasoning", sequence, {
38127
+ input: "",
38128
+ locations: [],
38129
+ name: "",
38130
+ output: output2,
38131
+ status: "completed",
38132
+ title: "Reasoning",
38133
+ toolKind: ""
38134
+ })
38135
+ );
38136
+ sequence += 1;
38137
+ }
38138
+ continue;
38139
+ } else if (type === "commandExecution" && options.detail === "rich") {
38140
+ const command = commandExecutionSchema.parse(item);
38141
+ const action = command.commandActions[0]?.type ?? "execute";
38142
+ activities.push(
38143
+ activity(command.id, "tool", sequence, {
38144
+ input: JSON.stringify({ command: command.command, cwd: command.cwd }),
38145
+ locations: [command.cwd],
38146
+ name: "",
38147
+ output: JSON.stringify({
38148
+ formatted_output: command.aggregatedOutput ?? "",
38149
+ ...command.exitCode == null ? {} : { exit_code: command.exitCode }
38150
+ }),
38151
+ status: command.status === "completed" ? "completed" : "failed",
38152
+ title: command.command,
38153
+ toolKind: action
38154
+ })
38155
+ );
38156
+ sequence += 1;
38157
+ continue;
37897
38158
  } else {
37898
38159
  continue;
37899
38160
  }
@@ -37903,14 +38164,48 @@ function decodeHistory(thread, value) {
37903
38164
  }
37904
38165
  truncated ||= text3.length < message.text.length;
37905
38166
  messages.push({ ...message, text: text3 });
37906
- characters += text3.length;
37907
- while (messages.length > SESSION_HISTORY_PREVIEW_MESSAGE_LIMIT || characters > SESSION_HISTORY_CHARACTER_LIMIT) {
37908
- const removed = messages.shift();
37909
- if (removed !== void 0) {
37910
- characters -= removed.text.length;
37911
- }
37912
- truncated = true;
38167
+ if (message.role === "assistant") {
38168
+ assistantMessageIndex = messages.length - 1;
38169
+ }
38170
+ characters += messageSize({ ...message, text: text3 });
38171
+ }
38172
+ if (options.detail === "rich" && turn.error != null) {
38173
+ activities.push(
38174
+ activity(`agent-error-${sequence.toString()}`, "tool", sequence, {
38175
+ input: "",
38176
+ locations: [],
38177
+ name: "",
38178
+ output: errorMessage(turn.error),
38179
+ status: "failed",
38180
+ title: "Agent error",
38181
+ toolKind: "other"
38182
+ })
38183
+ );
38184
+ }
38185
+ if (assistantMessageIndex !== null) {
38186
+ const assistant = messages[assistantMessageIndex];
38187
+ if (assistant?.role === "assistant") {
38188
+ characters -= messageSize(assistant);
38189
+ const updated = { ...assistant, activities: activities.slice(-100) };
38190
+ messages[assistantMessageIndex] = updated;
38191
+ characters += messageSize(updated);
38192
+ }
38193
+ } else if (activities.length > 0) {
38194
+ const message = {
38195
+ activities: activities.slice(-100),
38196
+ content: [],
38197
+ role: "assistant",
38198
+ text: ""
38199
+ };
38200
+ messages.push(message);
38201
+ characters += messageSize(message);
38202
+ }
38203
+ while (messages.length > SESSION_HISTORY_PREVIEW_MESSAGE_LIMIT || characters > SESSION_HISTORY_CHARACTER_LIMIT) {
38204
+ const removed = messages.shift();
38205
+ if (removed !== void 0) {
38206
+ characters -= messageSize(removed);
37913
38207
  }
38208
+ truncated = true;
37914
38209
  }
37915
38210
  }
37916
38211
  return {
@@ -37925,7 +38220,7 @@ function decodeHistory(thread, value) {
37925
38220
  }
37926
38221
  };
37927
38222
  }
37928
- async function readCodexHistory(agent, cwd, nativeSessionId, signal) {
38223
+ async function readCodexHistoryWithOptions(agent, cwd, nativeSessionId, signal, options) {
37929
38224
  signal.throwIfAborted();
37930
38225
  nativeSessionIdSchema.parse(nativeSessionId);
37931
38226
  if (agent.id !== "codex" || !await revalidateExecutable(agent.agentIdentity)) {
@@ -38019,13 +38314,13 @@ async function readCodexHistory(agent, cwd, nativeSessionId, signal) {
38019
38314
  threadId: nativeSessionId,
38020
38315
  limit: SESSION_HISTORY_PREVIEW_MESSAGE_LIMIT,
38021
38316
  sortDirection: "desc",
38022
- itemsView: "summary"
38317
+ itemsView: options.detail === "rich" ? "full" : "summary"
38023
38318
  }
38024
38319
  });
38025
38320
  break;
38026
38321
  }
38027
38322
  case "turns":
38028
- response.resolve(decodeHistory(state.thread, message.result));
38323
+ response.resolve(decodeHistory(state.thread, message.result, options));
38029
38324
  return;
38030
38325
  default: {
38031
38326
  const unhandled = state;
@@ -38082,8 +38377,12 @@ async function readCodexHistory(agent, cwd, nativeSessionId, signal) {
38082
38377
  child.removeListener("exit", onExit);
38083
38378
  }
38084
38379
  }
38380
+ var readCodexHistory = async (agent, cwd, nativeSessionId, signal) => await readCodexHistoryWithOptions(agent, cwd, nativeSessionId, signal, { detail: "messages" });
38381
+ var readCodexFullHistory = async (agent, cwd, nativeSessionId, signal) => await readCodexHistoryWithOptions(agent, cwd, nativeSessionId, signal, { detail: "rich" });
38085
38382
 
38086
38383
  // src/native-sessions/service.ts
38384
+ import { randomUUID as randomUUID2 } from "node:crypto";
38385
+ import { basename as basename6 } from "node:path";
38087
38386
  var NativeSessionService = class {
38088
38387
  #entries = /* @__PURE__ */ new Map();
38089
38388
  #cursors = /* @__PURE__ */ new Map();
@@ -40186,28 +40485,28 @@ var CoalescingDaemonActivityPublisher = class {
40186
40485
  }
40187
40486
  this.#pending.clear();
40188
40487
  this.#scheduled.clear();
40189
- for (const activity of activities) {
40190
- this.#publish(activity);
40488
+ for (const activity2 of activities) {
40489
+ this.#publish(activity2);
40191
40490
  }
40192
40491
  };
40193
- record = (activity) => {
40194
- if (activity.status !== "pending" && activity.status !== "running") {
40195
- this.#discardPending(activity.activityId);
40196
- this.#publishedActivityIds.add(activity.activityId);
40197
- this.#publish(activity);
40492
+ record = (activity2) => {
40493
+ if (activity2.status !== "pending" && activity2.status !== "running") {
40494
+ this.#discardPending(activity2.activityId);
40495
+ this.#publishedActivityIds.add(activity2.activityId);
40496
+ this.#publish(activity2);
40198
40497
  return Promise.resolve();
40199
40498
  }
40200
- if (!this.#publishedActivityIds.has(activity.activityId)) {
40201
- this.#publishedActivityIds.add(activity.activityId);
40202
- this.#publish(activity);
40499
+ if (!this.#publishedActivityIds.has(activity2.activityId)) {
40500
+ this.#publishedActivityIds.add(activity2.activityId);
40501
+ this.#publish(activity2);
40203
40502
  return Promise.resolve();
40204
40503
  }
40205
- this.#pending.set(activity.activityId, activity);
40206
- if (!this.#scheduled.has(activity.activityId)) {
40504
+ this.#pending.set(activity2.activityId, activity2);
40505
+ if (!this.#scheduled.has(activity2.activityId)) {
40207
40506
  this.#scheduled.set(
40208
- activity.activityId,
40507
+ activity2.activityId,
40209
40508
  this.#timer.schedule(
40210
- () => this.#flushActivity(activity.activityId),
40509
+ () => this.#flushActivity(activity2.activityId),
40211
40510
  AGENT_ACTIVITY_COALESCING_MILLISECONDS
40212
40511
  )
40213
40512
  );
@@ -40220,30 +40519,30 @@ var CoalescingDaemonActivityPublisher = class {
40220
40519
  this.#pending.delete(activityId);
40221
40520
  };
40222
40521
  #flushActivity = (activityId) => {
40223
- const activity = this.#pending.get(activityId);
40522
+ const activity2 = this.#pending.get(activityId);
40224
40523
  this.#discardPending(activityId);
40225
- if (activity !== void 0) {
40226
- this.#publish(activity);
40524
+ if (activity2 !== void 0) {
40525
+ this.#publish(activity2);
40227
40526
  }
40228
40527
  };
40229
40528
  };
40230
- function daemonActivity(command, activity) {
40529
+ function daemonActivity(command, activity2) {
40231
40530
  return {
40232
- activityId: activity.activityId,
40233
- activityType: activity.activityType,
40531
+ activityId: activity2.activityId,
40532
+ activityType: activity2.activityType,
40234
40533
  commandId: command.commandId,
40235
- content: activity.content,
40236
- detail: activity.detail,
40237
- input: activity.input,
40534
+ content: activity2.content,
40535
+ detail: activity2.detail,
40536
+ input: activity2.input,
40238
40537
  kind: AGENT_ACTIVITY_KIND,
40239
- locations: activity.locations,
40240
- name: activity.name,
40241
- output: activity.output,
40242
- sequence: activity.sequence,
40538
+ locations: activity2.locations,
40539
+ name: activity2.name,
40540
+ output: activity2.output,
40541
+ sequence: activity2.sequence,
40243
40542
  sessionId: command.sessionId,
40244
- status: activity.status,
40245
- title: activity.title,
40246
- toolKind: activity.toolKind
40543
+ status: activity2.status,
40544
+ title: activity2.title,
40545
+ toolKind: activity2.toolKind
40247
40546
  };
40248
40547
  }
40249
40548
  function reportFailure(publisher, command, code, message, attemptId) {
@@ -40742,7 +41041,10 @@ async function executeSessionLiveHistoryLoad(socket, command, config2, directori
40742
41041
  sessionId: command.sessionId
40743
41042
  });
40744
41043
  send(socket, {
40745
- history: { status: "unavailable" },
41044
+ history: {
41045
+ status: "unavailable",
41046
+ cause: { code: operationErrorCode(error62), message: operationErrorMessage(error62) }
41047
+ },
40746
41048
  kind: "session.live-history.loaded",
40747
41049
  requestId: command.requestId,
40748
41050
  sessionId: command.sessionId
@@ -40789,8 +41091,8 @@ async function executeSessionConfigure(publisher, socket, command, config2, dire
40789
41091
  }
40790
41092
  }
40791
41093
  async function executePrompt(outbox, publisher, command, config2, directories, audit, sessions, attemptId, activateAttempt, timer, signal) {
40792
- const activities = new CoalescingDaemonActivityPublisher(timer, (activity) => {
40793
- publisher.recordAttempt(command.sessionId, daemonActivity(command, activity), attemptId);
41094
+ const activities = new CoalescingDaemonActivityPublisher(timer, (activity2) => {
41095
+ publisher.recordAttempt(command.sessionId, daemonActivity(command, activity2), attemptId);
40794
41096
  });
40795
41097
  const text3 = new CoalescingTextPublisher(
40796
41098
  timer,
@@ -42187,7 +42489,9 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
42187
42489
  }
42188
42490
  publisher.recordAttempt(sessionId, event, attemptId);
42189
42491
  };
42190
- const sessions = new AcpSessionManager(new DaemonAcpObserver(recordSessionEvent), sessionStore);
42492
+ const sessions = new AcpSessionManager(new DaemonAcpObserver(recordSessionEvent), sessionStore, {
42493
+ read: async (options2, nativeSessionId) => options2.agent.id === "codex" ? (await readCodexFullHistory(options2.agent, options2.cwd, nativeSessionId, options2.signal)).history : null
42494
+ });
42191
42495
  const directories = new WorkspaceDirectoryService(config2.bindingId, config2.defaultWorkspace);
42192
42496
  const installationObserver = new DaemonInstallationObserver();
42193
42497
  const diagnostics = new RelayConnectionDiagnostics(audit, config2.channelId, config2.relayUrl);