@moxt-ai/mobius 0.0.77 → 0.0.79

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/runtime.js CHANGED
@@ -21189,6 +21189,14 @@ var modelListResponseSchema = external_exports.object({
21189
21189
  data: external_exports.array(modelSchema).max(1e3),
21190
21190
  nextCursor: boundedText(1024).nullish()
21191
21191
  });
21192
+ var threadSettingsUpdatedSchema = external_exports.object({
21193
+ threadId: boundedText(256),
21194
+ threadSettings: external_exports.object({
21195
+ collaborationMode: external_exports.object({
21196
+ mode: external_exports.enum(["default", "plan"])
21197
+ }).nullish()
21198
+ })
21199
+ });
21192
21200
 
21193
21201
  // src/acp/codex/app-server-client.ts
21194
21202
  var INITIALIZE_TIMEOUT_MILLISECONDS = 3e4;
@@ -21373,7 +21381,10 @@ var CodexAppServerClient = class {
21373
21381
  initialize = async (signal) => {
21374
21382
  await this.request(
21375
21383
  "initialize",
21376
- { clientInfo: { name: "mobius", version: "1.0.0" } },
21384
+ {
21385
+ capabilities: { experimentalApi: true },
21386
+ clientInfo: { name: "mobius", version: "1.0.0" }
21387
+ },
21377
21388
  AbortSignal.any([signal, AbortSignal.timeout(INITIALIZE_TIMEOUT_MILLISECONDS)])
21378
21389
  );
21379
21390
  this.notify("initialized", void 0);
@@ -21533,6 +21544,7 @@ var MODEL_SETTING_ID = "model";
21533
21544
  var REASONING_EFFORT_SETTING_ID = "reasoning_effort";
21534
21545
  var MODE_SETTING_ID = "mode";
21535
21546
  var FAST_MODE_SETTING_ID = "fast-mode";
21547
+ var COLLABORATION_MODE_SETTING_ID = "collaboration_mode";
21536
21548
  var MODEL_CATALOG_LIMIT = 1e3;
21537
21549
  var FAST_TIER = "fast";
21538
21550
  var SERVICE_TIER_FAST = "priority";
@@ -21662,6 +21674,22 @@ function modeSetting(currentValue) {
21662
21674
  type: "select"
21663
21675
  };
21664
21676
  }
21677
+ var COLLABORATION_MODES = Object.freeze([
21678
+ { description: "Codex answers and makes changes directly", name: "Build", value: "default" },
21679
+ { description: "Codex plans before making changes", name: "Plan", value: "plan" }
21680
+ ]);
21681
+ function collaborationModeSetting(currentValue) {
21682
+ const current = COLLABORATION_MODES.some((mode) => mode.value === currentValue) ? currentValue : COLLABORATION_MODES[0]?.value ?? "default";
21683
+ return {
21684
+ category: "collaboration_mode",
21685
+ currentValue: current,
21686
+ description: "How Codex collaborates for subsequent turns",
21687
+ id: COLLABORATION_MODE_SETTING_ID,
21688
+ name: "Collaboration mode",
21689
+ options: [...COLLABORATION_MODES],
21690
+ type: "select"
21691
+ };
21692
+ }
21665
21693
  function fastModeSetting(model, enabled) {
21666
21694
  if (model?.additionalSpeedTiers?.includes(FAST_TIER) !== true) {
21667
21695
  return null;
@@ -21723,11 +21751,19 @@ var CodexAcpAgent = class {
21723
21751
  // Whether the current turn must carry a policy at all. Until the user picks a mode, Codex's own
21724
21752
  // configuration decides, so `turn/start` omits the fields and inherits what the host set up.
21725
21753
  #policySelected = false;
21754
+ // Whether a collaboration mode choice has been made in this session. A restored thread keeps
21755
+ // the mode Codex already persisted, so the first turn does not reset it to Build.
21756
+ #collaborationModeSelected = false;
21757
+ // Whether the app-server accepts collaboration mode on `turn/start`, probed once per
21758
+ // app-server. An older Codex rejects the experimental field, and the setting must disappear
21759
+ // rather than break every turn.
21760
+ #collaborationModeSupported = null;
21726
21761
  #selection;
21727
21762
  #turn = null;
21728
21763
  #updateTail = Promise.resolve();
21729
21764
  constructor(options) {
21730
21765
  this.#selection = {
21766
+ collaborationMode: "default",
21731
21767
  effort: "",
21732
21768
  fastMode: false,
21733
21769
  mode: initialMode(options.environment),
@@ -21768,9 +21804,12 @@ var CodexAcpAgent = class {
21768
21804
  this.#nativeSessionId = created.thread.id;
21769
21805
  this.#selection = {
21770
21806
  ...this.#selection,
21807
+ collaborationMode: "default",
21771
21808
  effort: created.reasoningEffort ?? "",
21772
21809
  model: created.model ?? ""
21773
21810
  };
21811
+ this.#collaborationModeSelected = false;
21812
+ await this.#probeCollaborationMode(context.signal);
21774
21813
  return { configOptions: this.#configOptions(), sessionId: created.thread.id };
21775
21814
  }).onRequest(methods.agent.session.setConfigOption, async (context) => {
21776
21815
  this.#applySelection(context.params.configId, context.params.value);
@@ -21787,8 +21826,9 @@ var CodexAcpAgent = class {
21787
21826
  )
21788
21827
  );
21789
21828
  this.#selectRestoredThread(resumed);
21829
+ await this.#probeCollaborationMode(context.signal);
21790
21830
  await this.#replayHistory(resumed.turns);
21791
- return {};
21831
+ return { configOptions: this.#configOptions() };
21792
21832
  }).onRequest(methods.agent.session.fork, async (context) => {
21793
21833
  const forked = threadForkResponseSchema.parse(
21794
21834
  await this.#appServer.request(
@@ -21802,8 +21842,9 @@ var CodexAcpAgent = class {
21802
21842
  )
21803
21843
  );
21804
21844
  this.#selectRestoredThread(forked);
21845
+ await this.#probeCollaborationMode(context.signal);
21805
21846
  await this.#replayHistory(forked.turns);
21806
- return { sessionId: forked.thread.id };
21847
+ return { configOptions: this.#configOptions(), sessionId: forked.thread.id };
21807
21848
  }).onRequest(methods.agent.session.resume, async (context) => {
21808
21849
  const resumed = threadResumeResponseSchema.parse(
21809
21850
  await this.#appServer.request(
@@ -21813,7 +21854,8 @@ var CodexAcpAgent = class {
21813
21854
  )
21814
21855
  );
21815
21856
  this.#selectRestoredThread(resumed);
21816
- return {};
21857
+ await this.#probeCollaborationMode(context.signal);
21858
+ return { configOptions: this.#configOptions() };
21817
21859
  }).onRequest(methods.agent.session.prompt, async (context) => {
21818
21860
  return await this.#runTurn(promptInput(context.params.prompt), context.signal);
21819
21861
  }).onRequest(methods.agent.session.list, async (context) => {
@@ -21885,6 +21927,27 @@ var CodexAcpAgent = class {
21885
21927
  this.#models = Object.freeze(models.slice(0, MODEL_CATALOG_LIMIT));
21886
21928
  };
21887
21929
  #model = (id) => this.#models.find((model) => model.id === id);
21930
+ /**
21931
+ * Learns, once per app-server, whether collaboration mode can be applied. An empty settings
21932
+ * update is a no-op on a supporting Codex; an older Codex answers an error, which costs the
21933
+ * Build/Plan selector alone without changing a restored thread's persisted mode.
21934
+ */
21935
+ #probeCollaborationMode = async (signal) => {
21936
+ if (this.#collaborationModeSupported !== null) {
21937
+ return;
21938
+ }
21939
+ try {
21940
+ await this.#appServer.request(
21941
+ "thread/settings/update",
21942
+ { threadId: this.#nativeSessionId },
21943
+ AbortSignal.any([signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
21944
+ );
21945
+ this.#collaborationModeSupported = true;
21946
+ } catch {
21947
+ signal.throwIfAborted();
21948
+ this.#collaborationModeSupported = false;
21949
+ }
21950
+ };
21888
21951
  /** The ACP settings Mobius discovers and renders in Run settings. */
21889
21952
  #configOptions = () => {
21890
21953
  const options = [];
@@ -21900,6 +21963,9 @@ var CodexAcpAgent = class {
21900
21963
  if (fastMode !== null) {
21901
21964
  options.push(fastMode);
21902
21965
  }
21966
+ if (this.#collaborationModeSupported === true) {
21967
+ options.push(collaborationModeSetting(this.#selection.collaborationMode));
21968
+ }
21903
21969
  options.push(modeSetting(this.#selection.mode));
21904
21970
  return options;
21905
21971
  };
@@ -21992,6 +22058,18 @@ var CodexAcpAgent = class {
21992
22058
  this.#policySelected = true;
21993
22059
  return;
21994
22060
  }
22061
+ if (configId === COLLABORATION_MODE_SETTING_ID) {
22062
+ if (!COLLABORATION_MODES.some((mode) => mode.value === value)) {
22063
+ throw new AcpExecutionError(
22064
+ "The requested Codex collaboration mode is unavailable",
22065
+ {},
22066
+ "invalid_session_configuration"
22067
+ );
22068
+ }
22069
+ this.#selection = { ...this.#selection, collaborationMode: value };
22070
+ this.#collaborationModeSelected = true;
22071
+ return;
22072
+ }
21995
22073
  if (configId === MODEL_SETTING_ID) {
21996
22074
  if (value === this.#selection.model) {
21997
22075
  return;
@@ -22040,6 +22118,17 @@ var CodexAcpAgent = class {
22040
22118
  update
22041
22119
  });
22042
22120
  };
22121
+ /** Pushes the current settings so a mode change Codex applied reaches the Run settings panel. */
22122
+ #emitConfigOptionsUpdate = async () => {
22123
+ const connection = this.#connection;
22124
+ if (connection === null || this.#nativeSessionId.length === 0) {
22125
+ return;
22126
+ }
22127
+ await connection.client.notify(methods.client.session.update, {
22128
+ sessionId: this.#nativeSessionId,
22129
+ update: { configOptions: this.#configOptions(), sessionUpdate: "config_option_update" }
22130
+ });
22131
+ };
22043
22132
  // Notifications are serialized so two app-server items cannot interleave into one ACP update
22044
22133
  // stream, and the caller awaits the result: `turn/completed` must not resolve the prompt before
22045
22134
  // the updates it precedes have reached the client.
@@ -22072,6 +22161,19 @@ var CodexAcpAgent = class {
22072
22161
  }
22073
22162
  return;
22074
22163
  }
22164
+ if (method === "thread/settings/updated") {
22165
+ const decoded = threadSettingsUpdatedSchema.safeParse(params);
22166
+ if (decoded.success && decoded.data.threadId === this.#nativeSessionId) {
22167
+ const mode = decoded.data.threadSettings.collaborationMode?.mode;
22168
+ if (mode !== void 0 && mode !== this.#selection.collaborationMode) {
22169
+ this.#selection = { ...this.#selection, collaborationMode: mode };
22170
+ await this.#enqueue(async () => {
22171
+ await this.#emitConfigOptionsUpdate();
22172
+ });
22173
+ }
22174
+ }
22175
+ return;
22176
+ }
22075
22177
  if (method === "turn/plan/updated") {
22076
22178
  const plan = params.plan;
22077
22179
  if (Array.isArray(plan) && params.threadId === this.#nativeSessionId) {
@@ -22250,6 +22352,19 @@ var CodexAcpAgent = class {
22250
22352
  approvalsReviewer: mode.approvalsReviewer,
22251
22353
  sandboxPolicy: mode.sandboxPolicy
22252
22354
  } : {},
22355
+ // The collaboration mode rides on the turn: Codex applies it to the
22356
+ // thread, where it persists until changed. "Build" is Codex's `default`
22357
+ // mode, so it is only sent once a choice exists to apply.
22358
+ ...this.#collaborationModeSupported && (selection.collaborationMode !== "default" || this.#collaborationModeSelected) ? {
22359
+ collaborationMode: {
22360
+ mode: selection.collaborationMode,
22361
+ settings: {
22362
+ developer_instructions: null,
22363
+ model: selection.model,
22364
+ reasoning_effort: selection.effort.length === 0 ? null : selection.effort
22365
+ }
22366
+ }
22367
+ } : {},
22253
22368
  ...selection.effort.length === 0 ? {} : { effort: selection.effort },
22254
22369
  input: input2,
22255
22370
  ...selection.model.length === 0 ? {} : { model: selection.model },
@@ -25543,6 +25658,8 @@ var encodeRecordedSessionEvent = (event) => JSON.stringify(decodeRecordedSession
25543
25658
  // ../protocol/src/session-live-history.ts
25544
25659
  var SESSION_LIVE_HISTORY_LOAD_KIND = "session.live-history.load";
25545
25660
  var SESSION_LIVE_HISTORY_LOADED_KIND = "session.live-history.loaded";
25661
+ var SESSION_LIVE_HISTORY_PAGE_LOAD_KIND = "session.live-history.page.load";
25662
+ var SESSION_LIVE_HISTORY_PAGE_LOADED_KIND = "session.live-history.page.loaded";
25546
25663
  var identifier2 = external_exports.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/);
25547
25664
  var directoryIdentifier = external_exports.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,2047}$/);
25548
25665
  var sessionLiveHistoryLoadSchema = external_exports.strictObject({
@@ -25560,6 +25677,23 @@ var sessionLiveHistoryLoadedSchema = external_exports.strictObject({
25560
25677
  requestId: identifier2,
25561
25678
  sessionId: identifier2
25562
25679
  }).readonly();
25680
+ var sessionLiveHistoryPageLoadSchema = external_exports.strictObject({
25681
+ additionalDirectoryIds: external_exports.array(directoryIdentifier).max(16).readonly(),
25682
+ agentId: identifier2,
25683
+ bindingId: identifier2,
25684
+ cursor: external_exports.string().min(1).max(512).nullable(),
25685
+ directoryId: directoryIdentifier,
25686
+ kind: external_exports.literal(SESSION_LIVE_HISTORY_PAGE_LOAD_KIND),
25687
+ limit: external_exports.number().int().min(1).max(100),
25688
+ requestId: identifier2,
25689
+ sessionId: identifier2
25690
+ }).readonly();
25691
+ var sessionLiveHistoryPageLoadedSchema = external_exports.strictObject({
25692
+ kind: external_exports.literal(SESSION_LIVE_HISTORY_PAGE_LOADED_KIND),
25693
+ page: nativeMessagePageSchema,
25694
+ requestId: identifier2,
25695
+ sessionId: identifier2
25696
+ }).readonly();
25563
25697
  function decode6(schema, encoded) {
25564
25698
  try {
25565
25699
  const value = JSON.parse(encoded);
@@ -25572,6 +25706,10 @@ var decodeSessionLiveHistoryLoad = (encoded) => decode6(sessionLiveHistoryLoadSc
25572
25706
  var decodeSessionLiveHistoryLoaded = (encoded) => decode6(sessionLiveHistoryLoadedSchema, encoded);
25573
25707
  var encodeSessionLiveHistoryLoad = (value) => JSON.stringify(sessionLiveHistoryLoadSchema.parse(value));
25574
25708
  var encodeSessionLiveHistoryLoaded = (value) => JSON.stringify(sessionLiveHistoryLoadedSchema.parse(value));
25709
+ var decodeSessionLiveHistoryPageLoad = (encoded) => decode6(sessionLiveHistoryPageLoadSchema, encoded);
25710
+ var decodeSessionLiveHistoryPageLoaded = (encoded) => decode6(sessionLiveHistoryPageLoadedSchema, encoded);
25711
+ var encodeSessionLiveHistoryPageLoad = (value) => JSON.stringify(sessionLiveHistoryPageLoadSchema.parse(value));
25712
+ var encodeSessionLiveHistoryPageLoaded = (value) => JSON.stringify(sessionLiveHistoryPageLoadedSchema.parse(value));
25575
25713
 
25576
25714
  // ../protocol/src/daemon-transport.ts
25577
25715
  function defineMessageSignature(kind, encoder, decoder) {
@@ -25675,6 +25813,11 @@ var serviceToDaemonSignatures = {
25675
25813
  encodeSessionLiveHistoryLoad,
25676
25814
  decodeSessionLiveHistoryLoad
25677
25815
  ),
25816
+ [SESSION_LIVE_HISTORY_PAGE_LOAD_KIND]: defineMessageSignature(
25817
+ SESSION_LIVE_HISTORY_PAGE_LOAD_KIND,
25818
+ encodeSessionLiveHistoryPageLoad,
25819
+ decodeSessionLiveHistoryPageLoad
25820
+ ),
25678
25821
  [SESSION_PERMISSION_RESPOND_KIND]: defineMessageSignature(
25679
25822
  SESSION_PERMISSION_RESPOND_KIND,
25680
25823
  encodeSessionPermissionRespondCommand,
@@ -25785,6 +25928,11 @@ var daemonToServiceSignatures = {
25785
25928
  encodeSessionLiveHistoryLoaded,
25786
25929
  decodeSessionLiveHistoryLoaded
25787
25930
  ),
25931
+ [SESSION_LIVE_HISTORY_PAGE_LOADED_KIND]: defineMessageSignature(
25932
+ SESSION_LIVE_HISTORY_PAGE_LOADED_KIND,
25933
+ encodeSessionLiveHistoryPageLoaded,
25934
+ decodeSessionLiveHistoryPageLoaded
25935
+ ),
25788
25936
  [SESSION_READY_KIND]: defineMessageSignature(SESSION_READY_KIND, encodeSessionReadyEvent, decodeSessionReadyEvent),
25789
25937
  [WORKSPACE_ENTRIES_KIND]: defineMessageSignature(
25790
25938
  WORKSPACE_ENTRIES_KIND,
@@ -34380,6 +34528,29 @@ function sessionConfigProtocolForAgent(agentId) {
34380
34528
  }
34381
34529
 
34382
34530
  // src/acp/session-history.ts
34531
+ var HISTORY_ACTIVITY_FIELD_LIMIT = 1e5;
34532
+ var HISTORY_ACTIVITY_LIMIT = 100;
34533
+ function historyActivity(activity2) {
34534
+ return {
34535
+ activityId: activity2.activityId.slice(0, 128),
34536
+ activityType: activity2.activityType.slice(0, 128),
34537
+ content: activity2.content.slice(0, 100),
34538
+ input: activity2.input.slice(0, HISTORY_ACTIVITY_FIELD_LIMIT),
34539
+ locations: activity2.locations.slice(0, 100).map((location) => location.slice(0, 2048)),
34540
+ name: activity2.name.slice(0, 128),
34541
+ output: activity2.output.slice(0, HISTORY_ACTIVITY_FIELD_LIMIT),
34542
+ sequence: activity2.sequence,
34543
+ status: activity2.status.slice(0, 64),
34544
+ title: activity2.title.slice(0, 500),
34545
+ toolKind: activity2.toolKind.slice(0, 64)
34546
+ };
34547
+ }
34548
+ function historyContentCharacters(messages) {
34549
+ return messages.reduce(
34550
+ (total, message) => total + message.text.length + (message.role === "assistant" ? JSON.stringify(message.activities).length + JSON.stringify(message.content).length : 0),
34551
+ 0
34552
+ );
34553
+ }
34383
34554
  var AcpHistoryReplay = class {
34384
34555
  #activities = /* @__PURE__ */ new Map();
34385
34556
  #messages = [];
@@ -34486,33 +34657,45 @@ var AcpHistoryReplay = class {
34486
34657
  };
34487
34658
  snapshot = async () => {
34488
34659
  await this.#activityTracker.finish();
34660
+ const messages = this.#messages.map((message) => {
34661
+ if (message.role === "user") {
34662
+ return message;
34663
+ }
34664
+ const activities = message.activityIds.flatMap((id) => {
34665
+ const activity2 = this.#activities.get(id);
34666
+ return activity2 === void 0 ? [] : [historyActivity(activity2)];
34667
+ });
34668
+ if (activities.length > HISTORY_ACTIVITY_LIMIT) {
34669
+ this.#truncated = true;
34670
+ }
34671
+ return {
34672
+ role: "assistant",
34673
+ text: message.text,
34674
+ content: message.content.slice(0, 100),
34675
+ activities: activities.slice(-HISTORY_ACTIVITY_LIMIT)
34676
+ };
34677
+ });
34678
+ while (historyContentCharacters(messages) > SESSION_HISTORY_CHARACTER_LIMIT) {
34679
+ const richIndex = messages.findIndex(
34680
+ (message) => message.role === "assistant" && (message.activities.length > 0 || message.content.length > 0)
34681
+ );
34682
+ if (richIndex === -1) {
34683
+ messages.shift();
34684
+ } else {
34685
+ const message = messages[richIndex];
34686
+ if (message?.role === "assistant") {
34687
+ messages[richIndex] = {
34688
+ ...message,
34689
+ activities: message.activities.length > 0 ? message.activities.slice(1) : message.activities,
34690
+ content: message.activities.length === 0 && message.content.length > 0 ? message.content.slice(1) : message.content
34691
+ };
34692
+ }
34693
+ }
34694
+ this.#truncated = true;
34695
+ }
34489
34696
  return {
34490
34697
  status: "available",
34491
- messages: this.#messages.map(
34492
- (message) => message.role === "user" ? message : {
34493
- role: "assistant",
34494
- text: message.text,
34495
- content: message.content,
34496
- activities: message.activityIds.flatMap((id) => {
34497
- const activity2 = this.#activities.get(id);
34498
- return activity2 === void 0 ? [] : [
34499
- {
34500
- activityId: activity2.activityId,
34501
- activityType: activity2.activityType,
34502
- content: activity2.content,
34503
- input: activity2.input,
34504
- locations: activity2.locations,
34505
- name: activity2.name,
34506
- output: activity2.output,
34507
- sequence: activity2.sequence,
34508
- status: activity2.status,
34509
- title: activity2.title,
34510
- toolKind: activity2.toolKind
34511
- }
34512
- ];
34513
- })
34514
- }
34515
- ),
34698
+ messages,
34516
34699
  truncated: this.#truncated,
34517
34700
  coveredCommandIds: [],
34518
34701
  coveredMessageIds: []
@@ -41903,6 +42086,70 @@ async function executeSessionPrepare(publisher, socket, command, config2, direct
41903
42086
  reportOperationFailure(socket, command.requestId, command.sessionId, error62, metrics.snapshot());
41904
42087
  }
41905
42088
  }
42089
+ function liveHistoryCursor(sessionId, endIndex) {
42090
+ return Buffer.from(JSON.stringify({ endIndex, sessionId }), "utf8").toString("base64url");
42091
+ }
42092
+ function liveHistoryEndIndex(cursor, sessionId) {
42093
+ try {
42094
+ if (!/^[A-Za-z0-9_-]{1,512}$/u.test(cursor)) {
42095
+ throw new Error("Invalid cursor alphabet");
42096
+ }
42097
+ const value = JSON.parse(Buffer.from(cursor, "base64url").toString("utf8"));
42098
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
42099
+ throw new Error("Invalid cursor shape");
42100
+ }
42101
+ const record2 = Object.fromEntries(Object.entries(value));
42102
+ if (Object.keys(record2).sort().join(",") !== "endIndex,sessionId" || record2["sessionId"] !== sessionId || typeof record2["endIndex"] !== "number" || !Number.isSafeInteger(record2["endIndex"]) || record2["endIndex"] < 0) {
42103
+ throw new Error("Invalid cursor target");
42104
+ }
42105
+ return record2["endIndex"];
42106
+ } catch (cause) {
42107
+ throw new AcpExecutionError("The native Session history cursor is invalid", { cause }, "invalid_cursor");
42108
+ }
42109
+ }
42110
+ function liveHistoryCoveredTurnRanges(history) {
42111
+ const ranges = [];
42112
+ let historyIndex = history.messages.length;
42113
+ for (const commandId of history.coveredCommandIds) {
42114
+ let assistantStartIndex = historyIndex;
42115
+ while (assistantStartIndex > 0 && history.messages[assistantStartIndex - 1]?.role === "assistant") {
42116
+ assistantStartIndex -= 1;
42117
+ }
42118
+ const userIndex = assistantStartIndex - 1;
42119
+ if (assistantStartIndex === historyIndex || history.messages[userIndex]?.role !== "user") {
42120
+ break;
42121
+ }
42122
+ ranges.push({ assistantEndIndex: historyIndex, assistantStartIndex, commandId, userIndex });
42123
+ historyIndex = userIndex;
42124
+ }
42125
+ return ranges;
42126
+ }
42127
+ function paginateLiveSessionHistory(history, sessionId, cursor, limit) {
42128
+ if (history.status === "unavailable") {
42129
+ if (cursor !== null) {
42130
+ throw new AcpExecutionError("Unavailable native Session history has no cursor", {}, "invalid_cursor");
42131
+ }
42132
+ return { cause: history.cause, nextCursor: null, status: "unavailable" };
42133
+ }
42134
+ const endIndex = cursor === null ? history.messages.length : liveHistoryEndIndex(cursor, sessionId);
42135
+ if (endIndex > history.messages.length) {
42136
+ throw new AcpExecutionError("The native Session history cursor is invalid", {}, "invalid_cursor");
42137
+ }
42138
+ const startIndex = Math.max(0, endIndex - limit);
42139
+ const coveredMessageIds = new Set(history.coveredMessageIds);
42140
+ const ranges = liveHistoryCoveredTurnRanges(history);
42141
+ return {
42142
+ coveredCommandIds: ranges.filter((range) => range.userIndex >= startIndex && range.assistantEndIndex <= endIndex).map((range) => range.commandId),
42143
+ coveredMessageIds: ranges.flatMap((range) => [
42144
+ ...range.userIndex >= startIndex && range.userIndex < endIndex && coveredMessageIds.has(`${range.commandId}:user`) ? [`${range.commandId}:user`] : [],
42145
+ ...range.assistantStartIndex >= startIndex && range.assistantEndIndex <= endIndex && coveredMessageIds.has(`${range.commandId}:agent`) ? [`${range.commandId}:agent`] : []
42146
+ ]),
42147
+ messages: history.messages.slice(startIndex, endIndex),
42148
+ nextCursor: startIndex > 0 ? liveHistoryCursor(sessionId, startIndex) : null,
42149
+ status: "available",
42150
+ truncated: history.truncated
42151
+ };
42152
+ }
41906
42153
  async function executeSessionLiveHistoryLoad(socket, command, config2, directories, audit, sessions, signal) {
41907
42154
  try {
41908
42155
  const resolved = await resolveSessionDirectories(
@@ -41952,6 +42199,57 @@ async function executeSessionLiveHistoryLoad(socket, command, config2, directori
41952
42199
  });
41953
42200
  }
41954
42201
  }
42202
+ async function executeSessionLiveHistoryPageLoad(socket, command, config2, directories, audit, sessions, signal) {
42203
+ try {
42204
+ const resolved = await resolveSessionDirectories(
42205
+ directories,
42206
+ config2.bindingId,
42207
+ command.directoryId,
42208
+ command.additionalDirectoryIds,
42209
+ signal
42210
+ );
42211
+ const history = await sessions.loadSessionHistory({
42212
+ additionalDirectories: resolved.additionalDirectories,
42213
+ agent: config2.catalog.find(command.agentId),
42214
+ cwd: resolved.cwd,
42215
+ sessionId: command.sessionId,
42216
+ signal
42217
+ });
42218
+ signal.throwIfAborted();
42219
+ const page = paginateLiveSessionHistory(history, command.sessionId, command.cursor, command.limit);
42220
+ audit.record({
42221
+ commandId: command.requestId,
42222
+ event: "session_history_loaded",
42223
+ sessionId: command.sessionId
42224
+ });
42225
+ send(socket, {
42226
+ kind: "session.live-history.page.loaded",
42227
+ page,
42228
+ requestId: command.requestId,
42229
+ sessionId: command.sessionId
42230
+ });
42231
+ } catch (error62) {
42232
+ if (signal.aborted) {
42233
+ return;
42234
+ }
42235
+ audit.record({
42236
+ commandId: command.requestId,
42237
+ details: { code: operationErrorCode(error62) },
42238
+ event: "session_history_unavailable",
42239
+ sessionId: command.sessionId
42240
+ });
42241
+ send(socket, {
42242
+ kind: "session.live-history.page.loaded",
42243
+ page: {
42244
+ status: "unavailable",
42245
+ cause: { code: operationErrorCode(error62), message: operationErrorMessage(error62) },
42246
+ nextCursor: null
42247
+ },
42248
+ requestId: command.requestId,
42249
+ sessionId: command.sessionId
42250
+ });
42251
+ }
42252
+ }
41955
42253
  async function executeSessionConfigure(publisher, socket, command, config2, directories, audit, sessions, signal) {
41956
42254
  try {
41957
42255
  const resolved = await resolveSessionDirectories(
@@ -42811,6 +43109,19 @@ async function runRelayConnection(config2, directories, audit, sessions, install
42811
43109
  );
42812
43110
  return;
42813
43111
  }
43112
+ if (kind === SESSION_LIVE_HISTORY_PAGE_LOAD_KIND) {
43113
+ const command2 = decodeSessionLiveHistoryPageLoad(encoded);
43114
+ void executeSessionLiveHistoryPageLoad(
43115
+ socket,
43116
+ command2,
43117
+ config2,
43118
+ directories,
43119
+ audit,
43120
+ sessions,
43121
+ connectionController.signal
43122
+ );
43123
+ return;
43124
+ }
42814
43125
  if (kind === NATIVE_SESSION_CANCEL_KIND) {
42815
43126
  const command2 = message;
42816
43127
  const pending = nativeRequests.get(command2.requestId);