@moxt-ai/mobius 0.0.68 → 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/cli.js CHANGED
@@ -11,7 +11,7 @@ import { mkdir as mkdir6 } from "node:fs/promises";
11
11
  // package.json
12
12
  var package_default = {
13
13
  name: "@moxt-ai/mobius",
14
- version: "0.0.68",
14
+ version: "0.0.70",
15
15
  description: "Mobius CLI for pairing and running local AI agent services.",
16
16
  type: "module",
17
17
  bin: {
@@ -23781,11 +23781,32 @@ function parseNativeHistoryText(text3) {
23781
23781
  });
23782
23782
  return { text: plainText, images };
23783
23783
  }
23784
- var historyMessage = external_exports.strictObject({
23785
- role: external_exports.enum(["user", "assistant"]),
23784
+ var nativeMessageActivitySchema = external_exports.strictObject({
23785
+ activityId: external_exports.string().min(1).max(128),
23786
+ activityType: external_exports.string().min(1).max(128),
23787
+ content: external_exports.array(displayContentSchema).max(100).readonly(),
23788
+ input: external_exports.string().max(1e5),
23789
+ locations: external_exports.array(external_exports.string().min(1).max(2048)).max(100).readonly(),
23790
+ name: external_exports.string().max(128),
23791
+ output: external_exports.string().max(1e5),
23792
+ sequence: external_exports.number().int().nonnegative(),
23793
+ status: external_exports.string().min(1).max(64),
23794
+ title: external_exports.string().max(500),
23795
+ toolKind: external_exports.string().max(64)
23796
+ }).readonly();
23797
+ var userHistoryMessage = external_exports.strictObject({
23798
+ role: external_exports.literal("user"),
23786
23799
  text: external_exports.string().max(SESSION_HISTORY_CHARACTER_LIMIT),
23787
23800
  images: external_exports.array(historyImage).max(8).readonly().optional()
23788
23801
  }).readonly();
23802
+ var assistantHistoryMessage = external_exports.strictObject({
23803
+ activities: external_exports.array(nativeMessageActivitySchema).max(100).readonly().default([]),
23804
+ content: external_exports.array(displayContentSchema).max(100).readonly().default([]),
23805
+ role: external_exports.literal("assistant"),
23806
+ text: external_exports.string().max(SESSION_HISTORY_CHARACTER_LIMIT),
23807
+ images: external_exports.array(historyImage).max(8).readonly().optional()
23808
+ }).readonly();
23809
+ var historyMessage = external_exports.discriminatedUnion("role", [userHistoryMessage, assistantHistoryMessage]);
23789
23810
  var availableSessionHistoryObjectSchema = external_exports.strictObject({
23790
23811
  status: external_exports.literal("available"),
23791
23812
  messages: external_exports.array(historyMessage).max(SESSION_HISTORY_MESSAGE_LIMIT).readonly(),
@@ -23794,19 +23815,28 @@ var availableSessionHistoryObjectSchema = external_exports.strictObject({
23794
23815
  coveredMessageIds: external_exports.array(external_exports.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}:(?:user|agent)$/)).max(2e4).readonly().default([])
23795
23816
  });
23796
23817
  var availableSessionHistorySchema = availableSessionHistoryObjectSchema.readonly();
23797
- var unavailableSessionHistoryObjectSchema = external_exports.strictObject({ status: external_exports.literal("unavailable") });
23818
+ var unavailableSessionHistoryObjectSchema = external_exports.strictObject({
23819
+ status: external_exports.literal("unavailable"),
23820
+ cause: external_exports.strictObject({
23821
+ code: external_exports.string().regex(/^[a-z][a-z0-9_]{0,127}$/),
23822
+ message: external_exports.string().min(1).max(1e3)
23823
+ }).readonly()
23824
+ });
23798
23825
  var unavailableSessionHistorySchema = unavailableSessionHistoryObjectSchema.readonly();
23799
23826
  function withinHistoryContentLimits(history) {
23800
23827
  if (history.status === "unavailable" || history.messages === void 0) {
23801
23828
  return true;
23802
23829
  }
23803
- return history.messages.reduce((total, message) => total + message.text.length, 0) <= SESSION_HISTORY_CHARACTER_LIMIT && history.messages.reduce(
23830
+ return history.messages.reduce(
23831
+ (total, message) => total + message.text.length + (message.role === "assistant" ? JSON.stringify(message.activities).length + JSON.stringify(message.content).length : 0),
23832
+ 0
23833
+ ) <= SESSION_HISTORY_CHARACTER_LIMIT && history.messages.reduce(
23804
23834
  (total, message) => total + (message.images ?? []).reduce((size, image) => size + image.data.length, 0),
23805
23835
  0
23806
23836
  ) <= SESSION_HISTORY_IMAGE_CHARACTER_LIMIT;
23807
23837
  }
23808
23838
  var sessionHistorySchema = external_exports.discriminatedUnion("status", [availableSessionHistorySchema, unavailableSessionHistorySchema]).refine(withinHistoryContentLimits);
23809
- var sessionHistoryPageSchema = external_exports.discriminatedUnion("status", [
23839
+ var nativeMessagePageSchema = external_exports.discriminatedUnion("status", [
23810
23840
  availableSessionHistoryObjectSchema.extend({ nextCursor: external_exports.string().max(512).nullable() }).readonly(),
23811
23841
  unavailableSessionHistoryObjectSchema.extend({ nextCursor: external_exports.null() }).readonly()
23812
23842
  ]).refine(withinHistoryContentLimits);
@@ -25769,8 +25799,8 @@ function captureActivityDetail(content3, input2, output2) {
25769
25799
  originalBytes
25770
25800
  };
25771
25801
  }
25772
- function recordedDetail(activity) {
25773
- return activity?.detail.kind === "recorded" ? activity.detail : null;
25802
+ function recordedDetail(activity2) {
25803
+ return activity2?.detail.kind === "recorded" ? activity2.detail : null;
25774
25804
  }
25775
25805
  function emptyDisplayContent(type) {
25776
25806
  return {
@@ -25988,7 +26018,7 @@ var AcpActivityTracker = class {
25988
26018
  const previous2 = this.#activities.get(key);
25989
26019
  const identity2 = this.#identity(key);
25990
26020
  const fullOutput = `${recordedDetail(previous2)?.output ?? previous2?.output ?? ""}${text3}`;
25991
- const activity = new AcpActivity(
26021
+ const activity2 = new AcpActivity(
25992
26022
  identity2.id,
25993
26023
  activityType,
25994
26024
  "",
@@ -26002,7 +26032,7 @@ var AcpActivityTracker = class {
26002
26032
  [],
26003
26033
  captureActivityDetail([], "", fullOutput)
26004
26034
  );
26005
- await this.#record(key, activity);
26035
+ await this.#record(key, activity2);
26006
26036
  this.#activeNarrativeKey = key;
26007
26037
  };
26008
26038
  recordPlan = async (plan) => {
@@ -26124,21 +26154,21 @@ var AcpActivityTracker = class {
26124
26154
  return;
26125
26155
  }
26126
26156
  this.#activeNarrativeKey = "";
26127
- const activity = this.#activities.get(key);
26128
- if (activity === void 0) {
26157
+ const activity2 = this.#activities.get(key);
26158
+ if (activity2 === void 0) {
26129
26159
  return;
26130
26160
  }
26131
- const completed = activity.complete();
26132
- if (completed !== activity) {
26161
+ const completed = activity2.complete();
26162
+ if (completed !== activity2) {
26133
26163
  await this.#record(key, completed);
26134
26164
  }
26135
26165
  };
26136
26166
  finish = async () => {
26137
26167
  await this.finishNarrative();
26138
26168
  const entries = [...this.#activities.entries()].sort((left, right) => left[1].sequence - right[1].sequence);
26139
- for (const [key, activity] of entries) {
26140
- const completed = activity.complete();
26141
- if (completed !== activity) {
26169
+ for (const [key, activity2] of entries) {
26170
+ const completed = activity2.complete();
26171
+ if (completed !== activity2) {
26142
26172
  await this.#record(key, completed);
26143
26173
  }
26144
26174
  }
@@ -26153,9 +26183,9 @@ var AcpActivityTracker = class {
26153
26183
  this.#identities.set(key, identity2);
26154
26184
  return identity2;
26155
26185
  };
26156
- #record = async (key, activity) => {
26157
- this.#activities.set(key, activity);
26158
- await this.#onActivity(activity);
26186
+ #record = async (key, activity2) => {
26187
+ this.#activities.set(key, activity2);
26188
+ await this.#onActivity(activity2);
26159
26189
  };
26160
26190
  #recordPlanEntries = async (key, entries) => {
26161
26191
  const identity2 = this.#identity(key);
@@ -33783,19 +33813,74 @@ function sessionConfigProtocolForAgent(agentId) {
33783
33813
 
33784
33814
  // src/acp/session-history.ts
33785
33815
  var AcpHistoryReplay = class {
33816
+ #activities = /* @__PURE__ */ new Map();
33786
33817
  #messages = [];
33818
+ #turnActivityIds = /* @__PURE__ */ new Set();
33819
+ #activityTracker = new AcpActivityTracker(async (activity2) => {
33820
+ this.#activities.set(activity2.activityId, activity2);
33821
+ this.#turnActivityIds.add(activity2.activityId);
33822
+ const latest = this.#messages.at(-1);
33823
+ if (latest?.role === "assistant") {
33824
+ this.#messages[this.#messages.length - 1] = {
33825
+ ...latest,
33826
+ activityIds: [...this.#turnActivityIds]
33827
+ };
33828
+ }
33829
+ });
33787
33830
  #lastMessageId = null;
33788
33831
  #characters = 0;
33789
33832
  #truncated = false;
33790
- record = (update) => {
33833
+ record = async (update) => {
33834
+ if (update.sessionUpdate === "agent_thought_chunk") {
33835
+ if (update.content.type === "text") {
33836
+ await this.#activityTracker.recordNarrative(
33837
+ "reasoning",
33838
+ update.messageId ?? "current",
33839
+ update.content.text
33840
+ );
33841
+ }
33842
+ return;
33843
+ }
33844
+ if (update.sessionUpdate === "tool_call") {
33845
+ await this.#activityTracker.recordToolCall(update);
33846
+ return;
33847
+ }
33848
+ if (update.sessionUpdate === "tool_call_update") {
33849
+ await this.#activityTracker.recordToolCallUpdate(update);
33850
+ return;
33851
+ }
33852
+ if (update.sessionUpdate === "plan") {
33853
+ await this.#activityTracker.recordPlan(update);
33854
+ return;
33855
+ }
33856
+ if (update.sessionUpdate === "plan_update") {
33857
+ await this.#activityTracker.recordPlanUpdate(update);
33858
+ return;
33859
+ }
33860
+ if (update.sessionUpdate === "plan_removed") {
33861
+ await this.#activityTracker.removePlan(update);
33862
+ return;
33863
+ }
33791
33864
  if (update.sessionUpdate !== "user_message_chunk" && update.sessionUpdate !== "agent_message_chunk") {
33792
33865
  return;
33793
33866
  }
33794
33867
  if (update.sessionUpdate === "agent_message_chunk" && isProgressMessage(update)) {
33868
+ if (update.content.type === "text") {
33869
+ await this.#activityTracker.recordNarrative(
33870
+ "progress",
33871
+ update.messageId ?? "current",
33872
+ update.content.text
33873
+ );
33874
+ }
33795
33875
  return;
33796
33876
  }
33797
33877
  const role = update.sessionUpdate === "user_message_chunk" ? "user" : "assistant";
33798
33878
  const content3 = update.content;
33879
+ if (role === "assistant" && content3.type !== "text") {
33880
+ await this.#activityTracker.finishNarrative();
33881
+ this.recordAssistantContent(update.messageId ?? null, normalizeContentBlock(content3));
33882
+ return;
33883
+ }
33799
33884
  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]`;
33800
33885
  if (text3.length === 0) {
33801
33886
  return;
@@ -33803,19 +33888,84 @@ var AcpHistoryReplay = class {
33803
33888
  const previous2 = this.#messages.at(-1);
33804
33889
  const id = update.messageId ?? null;
33805
33890
  const continuation = previous2?.role === role && id === this.#lastMessageId;
33891
+ if (role === "user" && !continuation) {
33892
+ await this.#activityTracker.finish();
33893
+ this.#turnActivityIds.clear();
33894
+ }
33806
33895
  const combined = continuation ? `${previous2.text}${text3}` : text3;
33807
33896
  if (continuation) {
33808
33897
  this.#messages.pop();
33809
33898
  this.#characters -= previous2.text.length;
33810
33899
  }
33811
- const bounded = combined.slice(-SESSION_HISTORY_CHARACTER_LIMIT);
33812
- this.#truncated ||= bounded.length < combined.length;
33813
- this.#messages.push({
33814
- role,
33815
- text: bounded
33816
- });
33817
- this.#characters += bounded.length;
33900
+ const bounded2 = combined.slice(-SESSION_HISTORY_CHARACTER_LIMIT);
33901
+ this.#truncated ||= bounded2.length < combined.length;
33902
+ this.#messages.push(
33903
+ role === "user" ? { role, text: bounded2 } : {
33904
+ activityIds: [...this.#turnActivityIds],
33905
+ content: previous2?.role === "assistant" ? previous2.content : [],
33906
+ role,
33907
+ text: bounded2
33908
+ }
33909
+ );
33910
+ this.#characters += bounded2.length;
33818
33911
  this.#lastMessageId = id;
33912
+ this.trimMessages();
33913
+ };
33914
+ snapshot = async () => {
33915
+ await this.#activityTracker.finish();
33916
+ return {
33917
+ status: "available",
33918
+ messages: this.#messages.map(
33919
+ (message) => message.role === "user" ? message : {
33920
+ role: "assistant",
33921
+ text: message.text,
33922
+ content: message.content,
33923
+ activities: message.activityIds.flatMap((id) => {
33924
+ const activity2 = this.#activities.get(id);
33925
+ return activity2 === void 0 ? [] : [
33926
+ {
33927
+ activityId: activity2.activityId,
33928
+ activityType: activity2.activityType,
33929
+ content: activity2.content,
33930
+ input: activity2.input,
33931
+ locations: activity2.locations,
33932
+ name: activity2.name,
33933
+ output: activity2.output,
33934
+ sequence: activity2.sequence,
33935
+ status: activity2.status,
33936
+ title: activity2.title,
33937
+ toolKind: activity2.toolKind
33938
+ }
33939
+ ];
33940
+ })
33941
+ }
33942
+ ),
33943
+ truncated: this.#truncated,
33944
+ coveredCommandIds: [],
33945
+ coveredMessageIds: []
33946
+ };
33947
+ };
33948
+ recordAssistantContent = (messageId, content3) => {
33949
+ const previous2 = this.#messages.at(-1);
33950
+ const continuation = previous2?.role === "assistant" && messageId === this.#lastMessageId;
33951
+ if (continuation) {
33952
+ this.#messages[this.#messages.length - 1] = {
33953
+ ...previous2,
33954
+ activityIds: [...this.#turnActivityIds],
33955
+ content: [...previous2.content, content3]
33956
+ };
33957
+ } else {
33958
+ this.#messages.push({
33959
+ activityIds: [...this.#turnActivityIds],
33960
+ content: [content3],
33961
+ role: "assistant",
33962
+ text: ""
33963
+ });
33964
+ }
33965
+ this.#lastMessageId = messageId;
33966
+ this.trimMessages();
33967
+ };
33968
+ trimMessages = () => {
33819
33969
  while (this.#messages.length > SESSION_HISTORY_PREVIEW_MESSAGE_LIMIT || this.#characters > SESSION_HISTORY_CHARACTER_LIMIT) {
33820
33970
  const removed = this.#messages.shift();
33821
33971
  if (removed !== void 0) {
@@ -33824,13 +33974,6 @@ var AcpHistoryReplay = class {
33824
33974
  this.#truncated = true;
33825
33975
  }
33826
33976
  };
33827
- snapshot = () => ({
33828
- status: "available",
33829
- messages: [...this.#messages],
33830
- truncated: this.#truncated,
33831
- coveredCommandIds: [],
33832
- coveredMessageIds: []
33833
- });
33834
33977
  };
33835
33978
 
33836
33979
  // src/acp/session-store.ts
@@ -34756,7 +34899,13 @@ var AcpProcessSession = class _AcpProcessSession {
34756
34899
  );
34757
34900
  loadHistory = async (signal) => {
34758
34901
  if (!this.#capabilities.loadSession) {
34759
- return { status: "unavailable" };
34902
+ return {
34903
+ status: "unavailable",
34904
+ cause: {
34905
+ code: "native_history_unsupported",
34906
+ message: "This Agent restores context but does not provide message history."
34907
+ }
34908
+ };
34760
34909
  }
34761
34910
  const history = new AcpHistoryReplay();
34762
34911
  this.#replay = { kind: "capture", history };
@@ -34777,7 +34926,7 @@ var AcpProcessSession = class _AcpProcessSession {
34777
34926
  );
34778
34927
  await this.#updateTail;
34779
34928
  signal.throwIfAborted();
34780
- return await embedLocalHistoryImages(history.snapshot(), signal);
34929
+ return await embedLocalHistoryImages(await history.snapshot(), signal);
34781
34930
  } finally {
34782
34931
  this.#replay = { kind: "idle" };
34783
34932
  }
@@ -35621,7 +35770,7 @@ var AcpProcessSession = class _AcpProcessSession {
35621
35770
  this.assertNativeSession(notification.sessionId);
35622
35771
  const update = notification.update;
35623
35772
  if (this.#replay.kind === "capture") {
35624
- this.#replay.history.record(update);
35773
+ await this.#replay.history.record(update);
35625
35774
  }
35626
35775
  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")) {
35627
35776
  return;
@@ -35796,6 +35945,9 @@ var AcpProcessSession = class _AcpProcessSession {
35796
35945
  "authentication_required"
35797
35946
  );
35798
35947
  }
35948
+ if (error62 instanceof RequestError3) {
35949
+ throw new AcpExecutionError(truncate3(error62.message, 500), { cause: error62 }, "acp_agent_error");
35950
+ }
35799
35951
  throw error62;
35800
35952
  }
35801
35953
  } finally {
@@ -35909,10 +36061,12 @@ var AcpSessionManager = class {
35909
36061
  #startingProcessCount = 0;
35910
36062
  #transientProcessCount = 0;
35911
36063
  #store;
36064
+ #nativeHistoryReader;
35912
36065
  #observer;
35913
- constructor(observer = new NullAcpSessionObserver(), store = new MemoryAcpSessionStore()) {
36066
+ constructor(observer = new NullAcpSessionObserver(), store = new MemoryAcpSessionStore(), nativeHistoryReader = null) {
35914
36067
  this.#observer = observer;
35915
36068
  this.#store = store;
36069
+ this.#nativeHistoryReader = nativeHistoryReader;
35916
36070
  }
35917
36071
  setObserver = (observer) => {
35918
36072
  this.#observer = observer;
@@ -36674,7 +36828,15 @@ var AcpSessionManager = class {
36674
36828
  loadSessionHistory = async (options) => {
36675
36829
  this.#beginSessionUse(options.sessionId);
36676
36830
  try {
36677
- return await (await this.ensureSession(options)).loadHistory(options.signal);
36831
+ const runtime = await this.ensureSession(options);
36832
+ const stored = this.#store.read(options.sessionId);
36833
+ if (stored instanceof FoundAcpStoredSession && this.#nativeHistoryReader !== null) {
36834
+ const history = await this.#nativeHistoryReader.read(options, stored.session.nativeSessionId);
36835
+ if (history !== null) {
36836
+ return history;
36837
+ }
36838
+ }
36839
+ return await runtime.loadHistory(options.signal);
36678
36840
  } finally {
36679
36841
  this.#endSessionUse(options.sessionId);
36680
36842
  }
@@ -37890,10 +38052,6 @@ var WorkspaceDirectoryService = class {
37890
38052
  };
37891
38053
  };
37892
38054
 
37893
- // src/native-sessions/service.ts
37894
- import { randomUUID as randomUUID2 } from "node:crypto";
37895
- import { basename as basename6 } from "node:path";
37896
-
37897
38055
  // src/native-sessions/codex-history.ts
37898
38056
  import { spawn as spawn4 } from "node:child_process";
37899
38057
  var responseSchema = external_exports.union([
@@ -37911,7 +38069,12 @@ var threadSchema = external_exports.object({
37911
38069
  })
37912
38070
  });
37913
38071
  var turnsSchema = external_exports.object({
37914
- data: external_exports.array(external_exports.object({ items: external_exports.array(external_exports.unknown()).max(1e5) })).max(SESSION_HISTORY_PREVIEW_MESSAGE_LIMIT),
38072
+ data: external_exports.array(
38073
+ external_exports.object({
38074
+ error: external_exports.unknown().nullish(),
38075
+ items: external_exports.array(external_exports.unknown()).max(1e5)
38076
+ })
38077
+ ).max(SESSION_HISTORY_PREVIEW_MESSAGE_LIMIT),
37915
38078
  nextCursor: external_exports.string().nullish()
37916
38079
  });
37917
38080
  var itemTypeSchema = external_exports.object({ type: external_exports.string().min(1).max(80) });
@@ -37921,12 +38084,62 @@ var userMessageSchema = external_exports.object({
37921
38084
  var textSchema = external_exports.object({ text: external_exports.string() });
37922
38085
  var imageSchema = external_exports.object({ url: external_exports.string() });
37923
38086
  var agentMessageSchema = textSchema.extend({ phase: external_exports.string().nullish() });
37924
- function decodeHistory(thread, value) {
38087
+ var reasoningSchema = external_exports.object({
38088
+ id: external_exports.string(),
38089
+ summary: external_exports.array(external_exports.string()).max(1e4),
38090
+ content: external_exports.array(external_exports.string()).max(1e4)
38091
+ });
38092
+ var commandExecutionSchema = external_exports.object({
38093
+ id: external_exports.string(),
38094
+ command: external_exports.string(),
38095
+ cwd: external_exports.string(),
38096
+ status: external_exports.string(),
38097
+ commandActions: external_exports.array(external_exports.object({ type: external_exports.string() }).passthrough()).max(100),
38098
+ aggregatedOutput: external_exports.string().nullish(),
38099
+ exitCode: external_exports.number().int().nullish()
38100
+ });
38101
+ function bounded(value, maximum) {
38102
+ return value.slice(0, maximum);
38103
+ }
38104
+ function activity(activityId, activityType, sequence, fields) {
38105
+ return {
38106
+ activityId: bounded(activityId, 128) || `history-${sequence.toString()}`,
38107
+ activityType,
38108
+ content: [],
38109
+ input: bounded(fields.input, 1e5),
38110
+ locations: fields.locations.filter((location) => location.length > 0).map((location) => bounded(location, 2048)).slice(0, 100),
38111
+ name: bounded(fields.name, 128),
38112
+ output: bounded(fields.output, 1e5),
38113
+ sequence,
38114
+ status: bounded(fields.status, 64),
38115
+ title: bounded(fields.title, 500),
38116
+ toolKind: bounded(fields.toolKind, 64)
38117
+ };
38118
+ }
38119
+ function errorMessage(value) {
38120
+ if (typeof value === "string") {
38121
+ return value;
38122
+ }
38123
+ if (typeof value === "object" && value !== null) {
38124
+ const message = Reflect.get(value, "message");
38125
+ if (typeof message === "string") {
38126
+ return message;
38127
+ }
38128
+ }
38129
+ return JSON.stringify(value) ?? "Codex stopped before completing this turn.";
38130
+ }
38131
+ function messageSize(message) {
38132
+ return message.text.length + (message.role === "assistant" ? JSON.stringify(message.activities).length + JSON.stringify(message.content).length : 0);
38133
+ }
38134
+ function decodeHistory(thread, value, options) {
37925
38135
  const page = turnsSchema.parse(value);
37926
38136
  const messages = [];
37927
38137
  let characters = 0;
37928
38138
  let truncated = page.nextCursor != null;
37929
38139
  for (const turn of page.data.toReversed()) {
38140
+ const activities = [];
38141
+ let sequence = 0;
38142
+ let assistantMessageIndex = null;
37930
38143
  for (const item of turn.items) {
37931
38144
  const { type } = itemTypeSchema.parse(item);
37932
38145
  let message;
@@ -37949,9 +38162,60 @@ function decodeHistory(thread, value) {
37949
38162
  } else if (type === "agentMessage") {
37950
38163
  const agent = agentMessageSchema.parse(item);
37951
38164
  if (agent.phase === "commentary") {
38165
+ if (options.detail === "rich" && agent.text.length > 0) {
38166
+ activities.push(
38167
+ activity(`progress-${sequence.toString()}`, "progress", sequence, {
38168
+ input: "",
38169
+ locations: [],
38170
+ name: "",
38171
+ output: agent.text,
38172
+ status: "completed",
38173
+ title: "Progress",
38174
+ toolKind: ""
38175
+ })
38176
+ );
38177
+ sequence += 1;
38178
+ }
37952
38179
  continue;
37953
38180
  }
37954
- message = { role: "assistant", text: agent.text };
38181
+ message = { activities: activities.slice(-100), content: [], role: "assistant", text: agent.text };
38182
+ } else if (type === "reasoning" && options.detail === "rich") {
38183
+ const reasoning = reasoningSchema.parse(item);
38184
+ const output2 = (reasoning.summary.length > 0 ? reasoning.summary : reasoning.content).join("\n\n");
38185
+ if (output2.length > 0) {
38186
+ activities.push(
38187
+ activity(reasoning.id, "reasoning", sequence, {
38188
+ input: "",
38189
+ locations: [],
38190
+ name: "",
38191
+ output: output2,
38192
+ status: "completed",
38193
+ title: "Reasoning",
38194
+ toolKind: ""
38195
+ })
38196
+ );
38197
+ sequence += 1;
38198
+ }
38199
+ continue;
38200
+ } else if (type === "commandExecution" && options.detail === "rich") {
38201
+ const command = commandExecutionSchema.parse(item);
38202
+ const action = command.commandActions[0]?.type ?? "execute";
38203
+ activities.push(
38204
+ activity(command.id, "tool", sequence, {
38205
+ input: JSON.stringify({ command: command.command, cwd: command.cwd }),
38206
+ locations: [command.cwd],
38207
+ name: "",
38208
+ output: JSON.stringify({
38209
+ formatted_output: command.aggregatedOutput ?? "",
38210
+ ...command.exitCode == null ? {} : { exit_code: command.exitCode }
38211
+ }),
38212
+ status: command.status === "completed" ? "completed" : "failed",
38213
+ title: command.command,
38214
+ toolKind: action
38215
+ })
38216
+ );
38217
+ sequence += 1;
38218
+ continue;
37955
38219
  } else {
37956
38220
  continue;
37957
38221
  }
@@ -37961,14 +38225,48 @@ function decodeHistory(thread, value) {
37961
38225
  }
37962
38226
  truncated ||= text3.length < message.text.length;
37963
38227
  messages.push({ ...message, text: text3 });
37964
- characters += text3.length;
37965
- while (messages.length > SESSION_HISTORY_PREVIEW_MESSAGE_LIMIT || characters > SESSION_HISTORY_CHARACTER_LIMIT) {
37966
- const removed = messages.shift();
37967
- if (removed !== void 0) {
37968
- characters -= removed.text.length;
37969
- }
37970
- truncated = true;
38228
+ if (message.role === "assistant") {
38229
+ assistantMessageIndex = messages.length - 1;
38230
+ }
38231
+ characters += messageSize({ ...message, text: text3 });
38232
+ }
38233
+ if (options.detail === "rich" && turn.error != null) {
38234
+ activities.push(
38235
+ activity(`agent-error-${sequence.toString()}`, "tool", sequence, {
38236
+ input: "",
38237
+ locations: [],
38238
+ name: "",
38239
+ output: errorMessage(turn.error),
38240
+ status: "failed",
38241
+ title: "Agent error",
38242
+ toolKind: "other"
38243
+ })
38244
+ );
38245
+ }
38246
+ if (assistantMessageIndex !== null) {
38247
+ const assistant = messages[assistantMessageIndex];
38248
+ if (assistant?.role === "assistant") {
38249
+ characters -= messageSize(assistant);
38250
+ const updated = { ...assistant, activities: activities.slice(-100) };
38251
+ messages[assistantMessageIndex] = updated;
38252
+ characters += messageSize(updated);
38253
+ }
38254
+ } else if (activities.length > 0) {
38255
+ const message = {
38256
+ activities: activities.slice(-100),
38257
+ content: [],
38258
+ role: "assistant",
38259
+ text: ""
38260
+ };
38261
+ messages.push(message);
38262
+ characters += messageSize(message);
38263
+ }
38264
+ while (messages.length > SESSION_HISTORY_PREVIEW_MESSAGE_LIMIT || characters > SESSION_HISTORY_CHARACTER_LIMIT) {
38265
+ const removed = messages.shift();
38266
+ if (removed !== void 0) {
38267
+ characters -= messageSize(removed);
37971
38268
  }
38269
+ truncated = true;
37972
38270
  }
37973
38271
  }
37974
38272
  return {
@@ -37983,7 +38281,7 @@ function decodeHistory(thread, value) {
37983
38281
  }
37984
38282
  };
37985
38283
  }
37986
- async function readCodexHistory(agent, cwd, nativeSessionId, signal) {
38284
+ async function readCodexHistoryWithOptions(agent, cwd, nativeSessionId, signal, options) {
37987
38285
  signal.throwIfAborted();
37988
38286
  nativeSessionIdSchema.parse(nativeSessionId);
37989
38287
  if (agent.id !== "codex" || !await revalidateExecutable(agent.agentIdentity)) {
@@ -38077,13 +38375,13 @@ async function readCodexHistory(agent, cwd, nativeSessionId, signal) {
38077
38375
  threadId: nativeSessionId,
38078
38376
  limit: SESSION_HISTORY_PREVIEW_MESSAGE_LIMIT,
38079
38377
  sortDirection: "desc",
38080
- itemsView: "summary"
38378
+ itemsView: options.detail === "rich" ? "full" : "summary"
38081
38379
  }
38082
38380
  });
38083
38381
  break;
38084
38382
  }
38085
38383
  case "turns":
38086
- response.resolve(decodeHistory(state.thread, message.result));
38384
+ response.resolve(decodeHistory(state.thread, message.result, options));
38087
38385
  return;
38088
38386
  default: {
38089
38387
  const unhandled = state;
@@ -38140,8 +38438,12 @@ async function readCodexHistory(agent, cwd, nativeSessionId, signal) {
38140
38438
  child.removeListener("exit", onExit);
38141
38439
  }
38142
38440
  }
38441
+ var readCodexHistory = async (agent, cwd, nativeSessionId, signal) => await readCodexHistoryWithOptions(agent, cwd, nativeSessionId, signal, { detail: "messages" });
38442
+ var readCodexFullHistory = async (agent, cwd, nativeSessionId, signal) => await readCodexHistoryWithOptions(agent, cwd, nativeSessionId, signal, { detail: "rich" });
38143
38443
 
38144
38444
  // src/native-sessions/service.ts
38445
+ import { randomUUID as randomUUID2 } from "node:crypto";
38446
+ import { basename as basename6 } from "node:path";
38145
38447
  var NativeSessionService = class {
38146
38448
  #entries = /* @__PURE__ */ new Map();
38147
38449
  #cursors = /* @__PURE__ */ new Map();
@@ -40264,28 +40566,28 @@ var CoalescingDaemonActivityPublisher = class {
40264
40566
  }
40265
40567
  this.#pending.clear();
40266
40568
  this.#scheduled.clear();
40267
- for (const activity of activities) {
40268
- this.#publish(activity);
40569
+ for (const activity2 of activities) {
40570
+ this.#publish(activity2);
40269
40571
  }
40270
40572
  };
40271
- record = (activity) => {
40272
- if (activity.status !== "pending" && activity.status !== "running") {
40273
- this.#discardPending(activity.activityId);
40274
- this.#publishedActivityIds.add(activity.activityId);
40275
- this.#publish(activity);
40573
+ record = (activity2) => {
40574
+ if (activity2.status !== "pending" && activity2.status !== "running") {
40575
+ this.#discardPending(activity2.activityId);
40576
+ this.#publishedActivityIds.add(activity2.activityId);
40577
+ this.#publish(activity2);
40276
40578
  return Promise.resolve();
40277
40579
  }
40278
- if (!this.#publishedActivityIds.has(activity.activityId)) {
40279
- this.#publishedActivityIds.add(activity.activityId);
40280
- this.#publish(activity);
40580
+ if (!this.#publishedActivityIds.has(activity2.activityId)) {
40581
+ this.#publishedActivityIds.add(activity2.activityId);
40582
+ this.#publish(activity2);
40281
40583
  return Promise.resolve();
40282
40584
  }
40283
- this.#pending.set(activity.activityId, activity);
40284
- if (!this.#scheduled.has(activity.activityId)) {
40585
+ this.#pending.set(activity2.activityId, activity2);
40586
+ if (!this.#scheduled.has(activity2.activityId)) {
40285
40587
  this.#scheduled.set(
40286
- activity.activityId,
40588
+ activity2.activityId,
40287
40589
  this.#timer.schedule(
40288
- () => this.#flushActivity(activity.activityId),
40590
+ () => this.#flushActivity(activity2.activityId),
40289
40591
  AGENT_ACTIVITY_COALESCING_MILLISECONDS
40290
40592
  )
40291
40593
  );
@@ -40298,30 +40600,30 @@ var CoalescingDaemonActivityPublisher = class {
40298
40600
  this.#pending.delete(activityId);
40299
40601
  };
40300
40602
  #flushActivity = (activityId) => {
40301
- const activity = this.#pending.get(activityId);
40603
+ const activity2 = this.#pending.get(activityId);
40302
40604
  this.#discardPending(activityId);
40303
- if (activity !== void 0) {
40304
- this.#publish(activity);
40605
+ if (activity2 !== void 0) {
40606
+ this.#publish(activity2);
40305
40607
  }
40306
40608
  };
40307
40609
  };
40308
- function daemonActivity(command, activity) {
40610
+ function daemonActivity(command, activity2) {
40309
40611
  return {
40310
- activityId: activity.activityId,
40311
- activityType: activity.activityType,
40612
+ activityId: activity2.activityId,
40613
+ activityType: activity2.activityType,
40312
40614
  commandId: command.commandId,
40313
- content: activity.content,
40314
- detail: activity.detail,
40315
- input: activity.input,
40615
+ content: activity2.content,
40616
+ detail: activity2.detail,
40617
+ input: activity2.input,
40316
40618
  kind: AGENT_ACTIVITY_KIND,
40317
- locations: activity.locations,
40318
- name: activity.name,
40319
- output: activity.output,
40320
- sequence: activity.sequence,
40619
+ locations: activity2.locations,
40620
+ name: activity2.name,
40621
+ output: activity2.output,
40622
+ sequence: activity2.sequence,
40321
40623
  sessionId: command.sessionId,
40322
- status: activity.status,
40323
- title: activity.title,
40324
- toolKind: activity.toolKind
40624
+ status: activity2.status,
40625
+ title: activity2.title,
40626
+ toolKind: activity2.toolKind
40325
40627
  };
40326
40628
  }
40327
40629
  function reportFailure(publisher, command, code, message, attemptId) {
@@ -40820,7 +41122,10 @@ async function executeSessionLiveHistoryLoad(socket, command, config2, directori
40820
41122
  sessionId: command.sessionId
40821
41123
  });
40822
41124
  send(socket, {
40823
- history: { status: "unavailable" },
41125
+ history: {
41126
+ status: "unavailable",
41127
+ cause: { code: operationErrorCode(error62), message: operationErrorMessage(error62) }
41128
+ },
40824
41129
  kind: "session.live-history.loaded",
40825
41130
  requestId: command.requestId,
40826
41131
  sessionId: command.sessionId
@@ -40867,8 +41172,8 @@ async function executeSessionConfigure(publisher, socket, command, config2, dire
40867
41172
  }
40868
41173
  }
40869
41174
  async function executePrompt(outbox, publisher, command, config2, directories, audit, sessions, attemptId, activateAttempt, timer, signal) {
40870
- const activities = new CoalescingDaemonActivityPublisher(timer, (activity) => {
40871
- publisher.recordAttempt(command.sessionId, daemonActivity(command, activity), attemptId);
41175
+ const activities = new CoalescingDaemonActivityPublisher(timer, (activity2) => {
41176
+ publisher.recordAttempt(command.sessionId, daemonActivity(command, activity2), attemptId);
40872
41177
  });
40873
41178
  const text3 = new CoalescingTextPublisher(
40874
41179
  timer,
@@ -42265,7 +42570,9 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
42265
42570
  }
42266
42571
  publisher.recordAttempt(sessionId, event, attemptId);
42267
42572
  };
42268
- const sessions = new AcpSessionManager(new DaemonAcpObserver(recordSessionEvent), sessionStore);
42573
+ const sessions = new AcpSessionManager(new DaemonAcpObserver(recordSessionEvent), sessionStore, {
42574
+ read: async (options2, nativeSessionId) => options2.agent.id === "codex" ? (await readCodexFullHistory(options2.agent, options2.cwd, nativeSessionId, options2.signal)).history : null
42575
+ });
42269
42576
  const directories = new WorkspaceDirectoryService(config2.bindingId, config2.defaultWorkspace);
42270
42577
  const installationObserver = new DaemonInstallationObserver();
42271
42578
  const diagnostics = new RelayConnectionDiagnostics(audit, config2.channelId, config2.relayUrl);