@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/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.77",
14
+ version: "0.0.79",
15
15
  description: "Mobius CLI for pairing and running local AI agent services.",
16
16
  type: "module",
17
17
  bin: {
@@ -21317,6 +21317,14 @@ var modelListResponseSchema = external_exports.object({
21317
21317
  data: external_exports.array(modelSchema).max(1e3),
21318
21318
  nextCursor: boundedText(1024).nullish()
21319
21319
  });
21320
+ var threadSettingsUpdatedSchema = external_exports.object({
21321
+ threadId: boundedText(256),
21322
+ threadSettings: external_exports.object({
21323
+ collaborationMode: external_exports.object({
21324
+ mode: external_exports.enum(["default", "plan"])
21325
+ }).nullish()
21326
+ })
21327
+ });
21320
21328
 
21321
21329
  // src/acp/codex/app-server-client.ts
21322
21330
  var INITIALIZE_TIMEOUT_MILLISECONDS = 3e4;
@@ -21501,7 +21509,10 @@ var CodexAppServerClient = class {
21501
21509
  initialize = async (signal) => {
21502
21510
  await this.request(
21503
21511
  "initialize",
21504
- { clientInfo: { name: "mobius", version: "1.0.0" } },
21512
+ {
21513
+ capabilities: { experimentalApi: true },
21514
+ clientInfo: { name: "mobius", version: "1.0.0" }
21515
+ },
21505
21516
  AbortSignal.any([signal, AbortSignal.timeout(INITIALIZE_TIMEOUT_MILLISECONDS)])
21506
21517
  );
21507
21518
  this.notify("initialized", void 0);
@@ -21661,6 +21672,7 @@ var MODEL_SETTING_ID = "model";
21661
21672
  var REASONING_EFFORT_SETTING_ID = "reasoning_effort";
21662
21673
  var MODE_SETTING_ID = "mode";
21663
21674
  var FAST_MODE_SETTING_ID = "fast-mode";
21675
+ var COLLABORATION_MODE_SETTING_ID = "collaboration_mode";
21664
21676
  var MODEL_CATALOG_LIMIT = 1e3;
21665
21677
  var FAST_TIER = "fast";
21666
21678
  var SERVICE_TIER_FAST = "priority";
@@ -21790,6 +21802,22 @@ function modeSetting(currentValue) {
21790
21802
  type: "select"
21791
21803
  };
21792
21804
  }
21805
+ var COLLABORATION_MODES = Object.freeze([
21806
+ { description: "Codex answers and makes changes directly", name: "Build", value: "default" },
21807
+ { description: "Codex plans before making changes", name: "Plan", value: "plan" }
21808
+ ]);
21809
+ function collaborationModeSetting(currentValue) {
21810
+ const current = COLLABORATION_MODES.some((mode) => mode.value === currentValue) ? currentValue : COLLABORATION_MODES[0]?.value ?? "default";
21811
+ return {
21812
+ category: "collaboration_mode",
21813
+ currentValue: current,
21814
+ description: "How Codex collaborates for subsequent turns",
21815
+ id: COLLABORATION_MODE_SETTING_ID,
21816
+ name: "Collaboration mode",
21817
+ options: [...COLLABORATION_MODES],
21818
+ type: "select"
21819
+ };
21820
+ }
21793
21821
  function fastModeSetting(model, enabled) {
21794
21822
  if (model?.additionalSpeedTiers?.includes(FAST_TIER) !== true) {
21795
21823
  return null;
@@ -21851,11 +21879,19 @@ var CodexAcpAgent = class {
21851
21879
  // Whether the current turn must carry a policy at all. Until the user picks a mode, Codex's own
21852
21880
  // configuration decides, so `turn/start` omits the fields and inherits what the host set up.
21853
21881
  #policySelected = false;
21882
+ // Whether a collaboration mode choice has been made in this session. A restored thread keeps
21883
+ // the mode Codex already persisted, so the first turn does not reset it to Build.
21884
+ #collaborationModeSelected = false;
21885
+ // Whether the app-server accepts collaboration mode on `turn/start`, probed once per
21886
+ // app-server. An older Codex rejects the experimental field, and the setting must disappear
21887
+ // rather than break every turn.
21888
+ #collaborationModeSupported = null;
21854
21889
  #selection;
21855
21890
  #turn = null;
21856
21891
  #updateTail = Promise.resolve();
21857
21892
  constructor(options) {
21858
21893
  this.#selection = {
21894
+ collaborationMode: "default",
21859
21895
  effort: "",
21860
21896
  fastMode: false,
21861
21897
  mode: initialMode(options.environment),
@@ -21896,9 +21932,12 @@ var CodexAcpAgent = class {
21896
21932
  this.#nativeSessionId = created.thread.id;
21897
21933
  this.#selection = {
21898
21934
  ...this.#selection,
21935
+ collaborationMode: "default",
21899
21936
  effort: created.reasoningEffort ?? "",
21900
21937
  model: created.model ?? ""
21901
21938
  };
21939
+ this.#collaborationModeSelected = false;
21940
+ await this.#probeCollaborationMode(context.signal);
21902
21941
  return { configOptions: this.#configOptions(), sessionId: created.thread.id };
21903
21942
  }).onRequest(methods.agent.session.setConfigOption, async (context) => {
21904
21943
  this.#applySelection(context.params.configId, context.params.value);
@@ -21915,8 +21954,9 @@ var CodexAcpAgent = class {
21915
21954
  )
21916
21955
  );
21917
21956
  this.#selectRestoredThread(resumed);
21957
+ await this.#probeCollaborationMode(context.signal);
21918
21958
  await this.#replayHistory(resumed.turns);
21919
- return {};
21959
+ return { configOptions: this.#configOptions() };
21920
21960
  }).onRequest(methods.agent.session.fork, async (context) => {
21921
21961
  const forked = threadForkResponseSchema.parse(
21922
21962
  await this.#appServer.request(
@@ -21930,8 +21970,9 @@ var CodexAcpAgent = class {
21930
21970
  )
21931
21971
  );
21932
21972
  this.#selectRestoredThread(forked);
21973
+ await this.#probeCollaborationMode(context.signal);
21933
21974
  await this.#replayHistory(forked.turns);
21934
- return { sessionId: forked.thread.id };
21975
+ return { configOptions: this.#configOptions(), sessionId: forked.thread.id };
21935
21976
  }).onRequest(methods.agent.session.resume, async (context) => {
21936
21977
  const resumed = threadResumeResponseSchema.parse(
21937
21978
  await this.#appServer.request(
@@ -21941,7 +21982,8 @@ var CodexAcpAgent = class {
21941
21982
  )
21942
21983
  );
21943
21984
  this.#selectRestoredThread(resumed);
21944
- return {};
21985
+ await this.#probeCollaborationMode(context.signal);
21986
+ return { configOptions: this.#configOptions() };
21945
21987
  }).onRequest(methods.agent.session.prompt, async (context) => {
21946
21988
  return await this.#runTurn(promptInput(context.params.prompt), context.signal);
21947
21989
  }).onRequest(methods.agent.session.list, async (context) => {
@@ -22013,6 +22055,27 @@ var CodexAcpAgent = class {
22013
22055
  this.#models = Object.freeze(models.slice(0, MODEL_CATALOG_LIMIT));
22014
22056
  };
22015
22057
  #model = (id) => this.#models.find((model) => model.id === id);
22058
+ /**
22059
+ * Learns, once per app-server, whether collaboration mode can be applied. An empty settings
22060
+ * update is a no-op on a supporting Codex; an older Codex answers an error, which costs the
22061
+ * Build/Plan selector alone without changing a restored thread's persisted mode.
22062
+ */
22063
+ #probeCollaborationMode = async (signal) => {
22064
+ if (this.#collaborationModeSupported !== null) {
22065
+ return;
22066
+ }
22067
+ try {
22068
+ await this.#appServer.request(
22069
+ "thread/settings/update",
22070
+ { threadId: this.#nativeSessionId },
22071
+ AbortSignal.any([signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
22072
+ );
22073
+ this.#collaborationModeSupported = true;
22074
+ } catch {
22075
+ signal.throwIfAborted();
22076
+ this.#collaborationModeSupported = false;
22077
+ }
22078
+ };
22016
22079
  /** The ACP settings Mobius discovers and renders in Run settings. */
22017
22080
  #configOptions = () => {
22018
22081
  const options = [];
@@ -22028,6 +22091,9 @@ var CodexAcpAgent = class {
22028
22091
  if (fastMode !== null) {
22029
22092
  options.push(fastMode);
22030
22093
  }
22094
+ if (this.#collaborationModeSupported === true) {
22095
+ options.push(collaborationModeSetting(this.#selection.collaborationMode));
22096
+ }
22031
22097
  options.push(modeSetting(this.#selection.mode));
22032
22098
  return options;
22033
22099
  };
@@ -22120,6 +22186,18 @@ var CodexAcpAgent = class {
22120
22186
  this.#policySelected = true;
22121
22187
  return;
22122
22188
  }
22189
+ if (configId === COLLABORATION_MODE_SETTING_ID) {
22190
+ if (!COLLABORATION_MODES.some((mode) => mode.value === value)) {
22191
+ throw new AcpExecutionError(
22192
+ "The requested Codex collaboration mode is unavailable",
22193
+ {},
22194
+ "invalid_session_configuration"
22195
+ );
22196
+ }
22197
+ this.#selection = { ...this.#selection, collaborationMode: value };
22198
+ this.#collaborationModeSelected = true;
22199
+ return;
22200
+ }
22123
22201
  if (configId === MODEL_SETTING_ID) {
22124
22202
  if (value === this.#selection.model) {
22125
22203
  return;
@@ -22168,6 +22246,17 @@ var CodexAcpAgent = class {
22168
22246
  update
22169
22247
  });
22170
22248
  };
22249
+ /** Pushes the current settings so a mode change Codex applied reaches the Run settings panel. */
22250
+ #emitConfigOptionsUpdate = async () => {
22251
+ const connection = this.#connection;
22252
+ if (connection === null || this.#nativeSessionId.length === 0) {
22253
+ return;
22254
+ }
22255
+ await connection.client.notify(methods.client.session.update, {
22256
+ sessionId: this.#nativeSessionId,
22257
+ update: { configOptions: this.#configOptions(), sessionUpdate: "config_option_update" }
22258
+ });
22259
+ };
22171
22260
  // Notifications are serialized so two app-server items cannot interleave into one ACP update
22172
22261
  // stream, and the caller awaits the result: `turn/completed` must not resolve the prompt before
22173
22262
  // the updates it precedes have reached the client.
@@ -22200,6 +22289,19 @@ var CodexAcpAgent = class {
22200
22289
  }
22201
22290
  return;
22202
22291
  }
22292
+ if (method === "thread/settings/updated") {
22293
+ const decoded = threadSettingsUpdatedSchema.safeParse(params);
22294
+ if (decoded.success && decoded.data.threadId === this.#nativeSessionId) {
22295
+ const mode = decoded.data.threadSettings.collaborationMode?.mode;
22296
+ if (mode !== void 0 && mode !== this.#selection.collaborationMode) {
22297
+ this.#selection = { ...this.#selection, collaborationMode: mode };
22298
+ await this.#enqueue(async () => {
22299
+ await this.#emitConfigOptionsUpdate();
22300
+ });
22301
+ }
22302
+ }
22303
+ return;
22304
+ }
22203
22305
  if (method === "turn/plan/updated") {
22204
22306
  const plan = params.plan;
22205
22307
  if (Array.isArray(plan) && params.threadId === this.#nativeSessionId) {
@@ -22378,6 +22480,19 @@ var CodexAcpAgent = class {
22378
22480
  approvalsReviewer: mode.approvalsReviewer,
22379
22481
  sandboxPolicy: mode.sandboxPolicy
22380
22482
  } : {},
22483
+ // The collaboration mode rides on the turn: Codex applies it to the
22484
+ // thread, where it persists until changed. "Build" is Codex's `default`
22485
+ // mode, so it is only sent once a choice exists to apply.
22486
+ ...this.#collaborationModeSupported && (selection.collaborationMode !== "default" || this.#collaborationModeSelected) ? {
22487
+ collaborationMode: {
22488
+ mode: selection.collaborationMode,
22489
+ settings: {
22490
+ developer_instructions: null,
22491
+ model: selection.model,
22492
+ reasoning_effort: selection.effort.length === 0 ? null : selection.effort
22493
+ }
22494
+ }
22495
+ } : {},
22381
22496
  ...selection.effort.length === 0 ? {} : { effort: selection.effort },
22382
22497
  input: input2,
22383
22498
  ...selection.model.length === 0 ? {} : { model: selection.model },
@@ -25623,6 +25738,8 @@ var encodeRecordedSessionEvent = (event) => JSON.stringify(decodeRecordedSession
25623
25738
  // ../protocol/src/session-live-history.ts
25624
25739
  var SESSION_LIVE_HISTORY_LOAD_KIND = "session.live-history.load";
25625
25740
  var SESSION_LIVE_HISTORY_LOADED_KIND = "session.live-history.loaded";
25741
+ var SESSION_LIVE_HISTORY_PAGE_LOAD_KIND = "session.live-history.page.load";
25742
+ var SESSION_LIVE_HISTORY_PAGE_LOADED_KIND = "session.live-history.page.loaded";
25626
25743
  var identifier2 = external_exports.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/);
25627
25744
  var directoryIdentifier = external_exports.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,2047}$/);
25628
25745
  var sessionLiveHistoryLoadSchema = external_exports.strictObject({
@@ -25640,6 +25757,23 @@ var sessionLiveHistoryLoadedSchema = external_exports.strictObject({
25640
25757
  requestId: identifier2,
25641
25758
  sessionId: identifier2
25642
25759
  }).readonly();
25760
+ var sessionLiveHistoryPageLoadSchema = external_exports.strictObject({
25761
+ additionalDirectoryIds: external_exports.array(directoryIdentifier).max(16).readonly(),
25762
+ agentId: identifier2,
25763
+ bindingId: identifier2,
25764
+ cursor: external_exports.string().min(1).max(512).nullable(),
25765
+ directoryId: directoryIdentifier,
25766
+ kind: external_exports.literal(SESSION_LIVE_HISTORY_PAGE_LOAD_KIND),
25767
+ limit: external_exports.number().int().min(1).max(100),
25768
+ requestId: identifier2,
25769
+ sessionId: identifier2
25770
+ }).readonly();
25771
+ var sessionLiveHistoryPageLoadedSchema = external_exports.strictObject({
25772
+ kind: external_exports.literal(SESSION_LIVE_HISTORY_PAGE_LOADED_KIND),
25773
+ page: nativeMessagePageSchema,
25774
+ requestId: identifier2,
25775
+ sessionId: identifier2
25776
+ }).readonly();
25643
25777
  function decode6(schema, encoded) {
25644
25778
  try {
25645
25779
  const value = JSON.parse(encoded);
@@ -25652,6 +25786,10 @@ var decodeSessionLiveHistoryLoad = (encoded) => decode6(sessionLiveHistoryLoadSc
25652
25786
  var decodeSessionLiveHistoryLoaded = (encoded) => decode6(sessionLiveHistoryLoadedSchema, encoded);
25653
25787
  var encodeSessionLiveHistoryLoad = (value) => JSON.stringify(sessionLiveHistoryLoadSchema.parse(value));
25654
25788
  var encodeSessionLiveHistoryLoaded = (value) => JSON.stringify(sessionLiveHistoryLoadedSchema.parse(value));
25789
+ var decodeSessionLiveHistoryPageLoad = (encoded) => decode6(sessionLiveHistoryPageLoadSchema, encoded);
25790
+ var decodeSessionLiveHistoryPageLoaded = (encoded) => decode6(sessionLiveHistoryPageLoadedSchema, encoded);
25791
+ var encodeSessionLiveHistoryPageLoad = (value) => JSON.stringify(sessionLiveHistoryPageLoadSchema.parse(value));
25792
+ var encodeSessionLiveHistoryPageLoaded = (value) => JSON.stringify(sessionLiveHistoryPageLoadedSchema.parse(value));
25655
25793
 
25656
25794
  // ../protocol/src/daemon-transport.ts
25657
25795
  function defineMessageSignature(kind, encoder, decoder) {
@@ -25755,6 +25893,11 @@ var serviceToDaemonSignatures = {
25755
25893
  encodeSessionLiveHistoryLoad,
25756
25894
  decodeSessionLiveHistoryLoad
25757
25895
  ),
25896
+ [SESSION_LIVE_HISTORY_PAGE_LOAD_KIND]: defineMessageSignature(
25897
+ SESSION_LIVE_HISTORY_PAGE_LOAD_KIND,
25898
+ encodeSessionLiveHistoryPageLoad,
25899
+ decodeSessionLiveHistoryPageLoad
25900
+ ),
25758
25901
  [SESSION_PERMISSION_RESPOND_KIND]: defineMessageSignature(
25759
25902
  SESSION_PERMISSION_RESPOND_KIND,
25760
25903
  encodeSessionPermissionRespondCommand,
@@ -25865,6 +26008,11 @@ var daemonToServiceSignatures = {
25865
26008
  encodeSessionLiveHistoryLoaded,
25866
26009
  decodeSessionLiveHistoryLoaded
25867
26010
  ),
26011
+ [SESSION_LIVE_HISTORY_PAGE_LOADED_KIND]: defineMessageSignature(
26012
+ SESSION_LIVE_HISTORY_PAGE_LOADED_KIND,
26013
+ encodeSessionLiveHistoryPageLoaded,
26014
+ decodeSessionLiveHistoryPageLoaded
26015
+ ),
25868
26016
  [SESSION_READY_KIND]: defineMessageSignature(SESSION_READY_KIND, encodeSessionReadyEvent, decodeSessionReadyEvent),
25869
26017
  [WORKSPACE_ENTRIES_KIND]: defineMessageSignature(
25870
26018
  WORKSPACE_ENTRIES_KIND,
@@ -35375,6 +35523,29 @@ function sessionConfigProtocolForAgent(agentId) {
35375
35523
  }
35376
35524
 
35377
35525
  // src/acp/session-history.ts
35526
+ var HISTORY_ACTIVITY_FIELD_LIMIT = 1e5;
35527
+ var HISTORY_ACTIVITY_LIMIT = 100;
35528
+ function historyActivity(activity2) {
35529
+ return {
35530
+ activityId: activity2.activityId.slice(0, 128),
35531
+ activityType: activity2.activityType.slice(0, 128),
35532
+ content: activity2.content.slice(0, 100),
35533
+ input: activity2.input.slice(0, HISTORY_ACTIVITY_FIELD_LIMIT),
35534
+ locations: activity2.locations.slice(0, 100).map((location) => location.slice(0, 2048)),
35535
+ name: activity2.name.slice(0, 128),
35536
+ output: activity2.output.slice(0, HISTORY_ACTIVITY_FIELD_LIMIT),
35537
+ sequence: activity2.sequence,
35538
+ status: activity2.status.slice(0, 64),
35539
+ title: activity2.title.slice(0, 500),
35540
+ toolKind: activity2.toolKind.slice(0, 64)
35541
+ };
35542
+ }
35543
+ function historyContentCharacters(messages) {
35544
+ return messages.reduce(
35545
+ (total, message) => total + message.text.length + (message.role === "assistant" ? JSON.stringify(message.activities).length + JSON.stringify(message.content).length : 0),
35546
+ 0
35547
+ );
35548
+ }
35378
35549
  var AcpHistoryReplay = class {
35379
35550
  #activities = /* @__PURE__ */ new Map();
35380
35551
  #messages = [];
@@ -35481,33 +35652,45 @@ var AcpHistoryReplay = class {
35481
35652
  };
35482
35653
  snapshot = async () => {
35483
35654
  await this.#activityTracker.finish();
35655
+ const messages = this.#messages.map((message) => {
35656
+ if (message.role === "user") {
35657
+ return message;
35658
+ }
35659
+ const activities = message.activityIds.flatMap((id) => {
35660
+ const activity2 = this.#activities.get(id);
35661
+ return activity2 === void 0 ? [] : [historyActivity(activity2)];
35662
+ });
35663
+ if (activities.length > HISTORY_ACTIVITY_LIMIT) {
35664
+ this.#truncated = true;
35665
+ }
35666
+ return {
35667
+ role: "assistant",
35668
+ text: message.text,
35669
+ content: message.content.slice(0, 100),
35670
+ activities: activities.slice(-HISTORY_ACTIVITY_LIMIT)
35671
+ };
35672
+ });
35673
+ while (historyContentCharacters(messages) > SESSION_HISTORY_CHARACTER_LIMIT) {
35674
+ const richIndex = messages.findIndex(
35675
+ (message) => message.role === "assistant" && (message.activities.length > 0 || message.content.length > 0)
35676
+ );
35677
+ if (richIndex === -1) {
35678
+ messages.shift();
35679
+ } else {
35680
+ const message = messages[richIndex];
35681
+ if (message?.role === "assistant") {
35682
+ messages[richIndex] = {
35683
+ ...message,
35684
+ activities: message.activities.length > 0 ? message.activities.slice(1) : message.activities,
35685
+ content: message.activities.length === 0 && message.content.length > 0 ? message.content.slice(1) : message.content
35686
+ };
35687
+ }
35688
+ }
35689
+ this.#truncated = true;
35690
+ }
35484
35691
  return {
35485
35692
  status: "available",
35486
- messages: this.#messages.map(
35487
- (message) => message.role === "user" ? message : {
35488
- role: "assistant",
35489
- text: message.text,
35490
- content: message.content,
35491
- activities: message.activityIds.flatMap((id) => {
35492
- const activity2 = this.#activities.get(id);
35493
- return activity2 === void 0 ? [] : [
35494
- {
35495
- activityId: activity2.activityId,
35496
- activityType: activity2.activityType,
35497
- content: activity2.content,
35498
- input: activity2.input,
35499
- locations: activity2.locations,
35500
- name: activity2.name,
35501
- output: activity2.output,
35502
- sequence: activity2.sequence,
35503
- status: activity2.status,
35504
- title: activity2.title,
35505
- toolKind: activity2.toolKind
35506
- }
35507
- ];
35508
- })
35509
- }
35510
- ),
35693
+ messages,
35511
35694
  truncated: this.#truncated,
35512
35695
  coveredCommandIds: [],
35513
35696
  coveredMessageIds: []
@@ -42898,6 +43081,70 @@ async function executeSessionPrepare(publisher, socket, command, config2, direct
42898
43081
  reportOperationFailure(socket, command.requestId, command.sessionId, error62, metrics.snapshot());
42899
43082
  }
42900
43083
  }
43084
+ function liveHistoryCursor(sessionId, endIndex) {
43085
+ return Buffer.from(JSON.stringify({ endIndex, sessionId }), "utf8").toString("base64url");
43086
+ }
43087
+ function liveHistoryEndIndex(cursor, sessionId) {
43088
+ try {
43089
+ if (!/^[A-Za-z0-9_-]{1,512}$/u.test(cursor)) {
43090
+ throw new Error("Invalid cursor alphabet");
43091
+ }
43092
+ const value = JSON.parse(Buffer.from(cursor, "base64url").toString("utf8"));
43093
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
43094
+ throw new Error("Invalid cursor shape");
43095
+ }
43096
+ const record2 = Object.fromEntries(Object.entries(value));
43097
+ if (Object.keys(record2).sort().join(",") !== "endIndex,sessionId" || record2["sessionId"] !== sessionId || typeof record2["endIndex"] !== "number" || !Number.isSafeInteger(record2["endIndex"]) || record2["endIndex"] < 0) {
43098
+ throw new Error("Invalid cursor target");
43099
+ }
43100
+ return record2["endIndex"];
43101
+ } catch (cause) {
43102
+ throw new AcpExecutionError("The native Session history cursor is invalid", { cause }, "invalid_cursor");
43103
+ }
43104
+ }
43105
+ function liveHistoryCoveredTurnRanges(history) {
43106
+ const ranges = [];
43107
+ let historyIndex = history.messages.length;
43108
+ for (const commandId of history.coveredCommandIds) {
43109
+ let assistantStartIndex = historyIndex;
43110
+ while (assistantStartIndex > 0 && history.messages[assistantStartIndex - 1]?.role === "assistant") {
43111
+ assistantStartIndex -= 1;
43112
+ }
43113
+ const userIndex = assistantStartIndex - 1;
43114
+ if (assistantStartIndex === historyIndex || history.messages[userIndex]?.role !== "user") {
43115
+ break;
43116
+ }
43117
+ ranges.push({ assistantEndIndex: historyIndex, assistantStartIndex, commandId, userIndex });
43118
+ historyIndex = userIndex;
43119
+ }
43120
+ return ranges;
43121
+ }
43122
+ function paginateLiveSessionHistory(history, sessionId, cursor, limit) {
43123
+ if (history.status === "unavailable") {
43124
+ if (cursor !== null) {
43125
+ throw new AcpExecutionError("Unavailable native Session history has no cursor", {}, "invalid_cursor");
43126
+ }
43127
+ return { cause: history.cause, nextCursor: null, status: "unavailable" };
43128
+ }
43129
+ const endIndex = cursor === null ? history.messages.length : liveHistoryEndIndex(cursor, sessionId);
43130
+ if (endIndex > history.messages.length) {
43131
+ throw new AcpExecutionError("The native Session history cursor is invalid", {}, "invalid_cursor");
43132
+ }
43133
+ const startIndex = Math.max(0, endIndex - limit);
43134
+ const coveredMessageIds = new Set(history.coveredMessageIds);
43135
+ const ranges = liveHistoryCoveredTurnRanges(history);
43136
+ return {
43137
+ coveredCommandIds: ranges.filter((range) => range.userIndex >= startIndex && range.assistantEndIndex <= endIndex).map((range) => range.commandId),
43138
+ coveredMessageIds: ranges.flatMap((range) => [
43139
+ ...range.userIndex >= startIndex && range.userIndex < endIndex && coveredMessageIds.has(`${range.commandId}:user`) ? [`${range.commandId}:user`] : [],
43140
+ ...range.assistantStartIndex >= startIndex && range.assistantEndIndex <= endIndex && coveredMessageIds.has(`${range.commandId}:agent`) ? [`${range.commandId}:agent`] : []
43141
+ ]),
43142
+ messages: history.messages.slice(startIndex, endIndex),
43143
+ nextCursor: startIndex > 0 ? liveHistoryCursor(sessionId, startIndex) : null,
43144
+ status: "available",
43145
+ truncated: history.truncated
43146
+ };
43147
+ }
42901
43148
  async function executeSessionLiveHistoryLoad(socket, command, config2, directories, audit, sessions, signal) {
42902
43149
  try {
42903
43150
  const resolved = await resolveSessionDirectories(
@@ -42947,6 +43194,57 @@ async function executeSessionLiveHistoryLoad(socket, command, config2, directori
42947
43194
  });
42948
43195
  }
42949
43196
  }
43197
+ async function executeSessionLiveHistoryPageLoad(socket, command, config2, directories, audit, sessions, signal) {
43198
+ try {
43199
+ const resolved = await resolveSessionDirectories(
43200
+ directories,
43201
+ config2.bindingId,
43202
+ command.directoryId,
43203
+ command.additionalDirectoryIds,
43204
+ signal
43205
+ );
43206
+ const history = await sessions.loadSessionHistory({
43207
+ additionalDirectories: resolved.additionalDirectories,
43208
+ agent: config2.catalog.find(command.agentId),
43209
+ cwd: resolved.cwd,
43210
+ sessionId: command.sessionId,
43211
+ signal
43212
+ });
43213
+ signal.throwIfAborted();
43214
+ const page = paginateLiveSessionHistory(history, command.sessionId, command.cursor, command.limit);
43215
+ audit.record({
43216
+ commandId: command.requestId,
43217
+ event: "session_history_loaded",
43218
+ sessionId: command.sessionId
43219
+ });
43220
+ send(socket, {
43221
+ kind: "session.live-history.page.loaded",
43222
+ page,
43223
+ requestId: command.requestId,
43224
+ sessionId: command.sessionId
43225
+ });
43226
+ } catch (error62) {
43227
+ if (signal.aborted) {
43228
+ return;
43229
+ }
43230
+ audit.record({
43231
+ commandId: command.requestId,
43232
+ details: { code: operationErrorCode(error62) },
43233
+ event: "session_history_unavailable",
43234
+ sessionId: command.sessionId
43235
+ });
43236
+ send(socket, {
43237
+ kind: "session.live-history.page.loaded",
43238
+ page: {
43239
+ status: "unavailable",
43240
+ cause: { code: operationErrorCode(error62), message: operationErrorMessage(error62) },
43241
+ nextCursor: null
43242
+ },
43243
+ requestId: command.requestId,
43244
+ sessionId: command.sessionId
43245
+ });
43246
+ }
43247
+ }
42950
43248
  async function executeSessionConfigure(publisher, socket, command, config2, directories, audit, sessions, signal) {
42951
43249
  try {
42952
43250
  const resolved = await resolveSessionDirectories(
@@ -43806,6 +44104,19 @@ async function runRelayConnection(config2, directories, audit, sessions, install
43806
44104
  );
43807
44105
  return;
43808
44106
  }
44107
+ if (kind === SESSION_LIVE_HISTORY_PAGE_LOAD_KIND) {
44108
+ const command2 = decodeSessionLiveHistoryPageLoad(encoded);
44109
+ void executeSessionLiveHistoryPageLoad(
44110
+ socket,
44111
+ command2,
44112
+ config2,
44113
+ directories,
44114
+ audit,
44115
+ sessions,
44116
+ connectionController.signal
44117
+ );
44118
+ return;
44119
+ }
43809
44120
  if (kind === NATIVE_SESSION_CANCEL_KIND) {
43810
44121
  const command2 = message;
43811
44122
  const pending = nativeRequests.get(command2.requestId);