@moxt-ai/mobius 0.0.295 → 0.0.298

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
@@ -5398,7 +5398,7 @@ var program = new Command();
5398
5398
  // package.json
5399
5399
  var package_default = {
5400
5400
  name: "@moxt-ai/mobius",
5401
- version: "0.0.295",
5401
+ version: "0.0.298",
5402
5402
  description: "Mobius CLI for pairing and running local AI agent services.",
5403
5403
  type: "module",
5404
5404
  bin: {
@@ -70813,7 +70813,7 @@ function reasoningText(item) {
70813
70813
  if (item.type !== "reasoning") {
70814
70814
  return null;
70815
70815
  }
70816
- return boundedParagraphs(item.summary.length > 0 ? item.summary : item.content, TOOL_OUTPUT_CHARACTER_LIMIT);
70816
+ return boundedParagraphs(item.content.length > 0 ? item.content : item.summary, TOOL_OUTPUT_CHARACTER_LIMIT);
70817
70817
  }
70818
70818
 
70819
70819
  // src/acp/harness/codex/borrowed-agent.ts
@@ -71193,7 +71193,7 @@ var CodexOwnedAcpAgent = class {
71193
71193
  #context;
71194
71194
  #appServer;
71195
71195
  #settings;
71196
- #streamedReasoningItemIds = /* @__PURE__ */ new Set();
71196
+ #streamedReasoningSources = /* @__PURE__ */ new Map();
71197
71197
  #agentMessages = /* @__PURE__ */ new Map();
71198
71198
  #turn = null;
71199
71199
  #nativeTurnId = null;
@@ -71401,7 +71401,12 @@ var CodexOwnedAcpAgent = class {
71401
71401
  if (method === "item/reasoning/summaryTextDelta" || method === "item/reasoning/textDelta") {
71402
71402
  const decoded = reasoningTextDeltaParamsSchema.safeParse(params);
71403
71403
  if (decoded.success && decoded.data.threadId === this.#context.threadId() && this.#turn !== null && decoded.data.turnId === this.#turn.turn.id && decoded.data.delta.length > 0) {
71404
- this.#streamedReasoningItemIds.add(decoded.data.itemId);
71404
+ const source = method === "item/reasoning/textDelta" ? "content" : "summary";
71405
+ const previous = this.#streamedReasoningSources.get(decoded.data.itemId);
71406
+ this.#streamedReasoningSources.set(
71407
+ decoded.data.itemId,
71408
+ previous === "content" || source === "content" ? "content" : "summary"
71409
+ );
71405
71410
  await this.#enqueue(async () => {
71406
71411
  await this.#context.emit({
71407
71412
  content: { text: decoded.data.delta, type: "text" },
@@ -71469,8 +71474,12 @@ var CodexOwnedAcpAgent = class {
71469
71474
  }
71470
71475
  const reasoning = reasoningText(item);
71471
71476
  if (reasoning !== null) {
71472
- const streamed = method === "item/completed" && this.#streamedReasoningItemIds.delete(item.id);
71473
- if (method === "item/completed" && reasoning.length > 0 && !streamed) {
71477
+ const streamedSource = method === "item/completed" ? this.#streamedReasoningSources.get(item.id) : void 0;
71478
+ if (method === "item/completed") {
71479
+ this.#streamedReasoningSources.delete(item.id);
71480
+ }
71481
+ const needsCompletedContent = method === "item/completed" && reasoning.length > 0 && (streamedSource === void 0 || streamedSource === "summary" && item.type === "reasoning" && item.content.length > 0);
71482
+ if (needsCompletedContent) {
71474
71483
  await this.#enqueue(async () => {
71475
71484
  await this.#context.emit({
71476
71485
  content: { text: reasoning, type: "text" },
@@ -71622,7 +71631,7 @@ var CodexOwnedAcpAgent = class {
71622
71631
  signal.addEventListener("abort", aborted2, { once: true });
71623
71632
  const turn = { completion, turn: { id: "" } };
71624
71633
  this.#agentMessages.clear();
71625
- this.#streamedReasoningItemIds.clear();
71634
+ this.#streamedReasoningSources.clear();
71626
71635
  this.#turn = turn;
71627
71636
  this.#nativeTurnId = null;
71628
71637
  try {
@@ -71647,7 +71656,7 @@ var CodexOwnedAcpAgent = class {
71647
71656
  if (this.#turn === turn) {
71648
71657
  this.#turn = null;
71649
71658
  this.#agentMessages.clear();
71650
- this.#streamedReasoningItemIds.clear();
71659
+ this.#streamedReasoningSources.clear();
71651
71660
  }
71652
71661
  }
71653
71662
  };
@@ -82150,31 +82159,9 @@ function decodeHistory(thread, value, options) {
82150
82159
  text: text2
82151
82160
  });
82152
82161
  } else if (historyItem.type === "agentMessage") {
82153
- if (historyItem.phase === "commentary") {
82154
- if (historyItem.text.length > 0) {
82155
- append({
82156
- activities: [
82157
- activity(historyItem.id ?? `reasoning-${sequence.toString()}`, "reasoning", sequence, {
82158
- input: "",
82159
- locations: [],
82160
- name: "",
82161
- output: historyItem.text,
82162
- status: "completed",
82163
- title: "Reasoning",
82164
- toolKind: "think"
82165
- })
82166
- ],
82167
- content: [],
82168
- role: "assistant",
82169
- text: ""
82170
- });
82171
- sequence += 1;
82172
- }
82173
- continue;
82174
- }
82175
82162
  append({ activities: [], content: [], role: "assistant", text: historyItem.text });
82176
82163
  } else if (historyItem.type === "reasoning") {
82177
- const output2 = (historyItem.summary.length > 0 ? historyItem.summary : historyItem.content).join(
82164
+ const output2 = (historyItem.content.length > 0 ? historyItem.content : historyItem.summary).join(
82178
82165
  "\n\n"
82179
82166
  );
82180
82167
  if (output2.length > 0) {
@@ -96846,37 +96833,44 @@ async function runRelayConnection({
96846
96833
  // src/runtime/relay/session-event-publisher.ts
96847
96834
  import { WebSocket as WebSocket8 } from "undici";
96848
96835
  var MAX_BUFFERED_BYTES = 32 * 1024 * 1024;
96836
+ var MAX_PENDING_BYTES2 = 32 * 1024 * 1024;
96849
96837
  var MAX_EVENT_BATCH_BYTES = 1024 * 1024;
96850
96838
  var MAX_FRAME_BYTES = 8 * 1024 * 1024;
96851
96839
  var LOCAL_BACKPRESSURE_CLOSE_CODE = 4009;
96852
96840
  var EMPTY_ENVELOPE_BYTES = Buffer.byteLength(JSON.stringify({ events: [], kind: SESSION_EVENT_KIND }));
96853
96841
  var SESSION_EVENT_BATCH_WINDOW_MILLISECONDS = 100;
96854
96842
  var RuntimeSessionEventPublisher = class {
96855
- #pendingEvents = [];
96856
- #pendingBytes = EMPTY_ENVELOPE_BYTES;
96843
+ #pending = [];
96844
+ #pendingBytes = 0;
96845
+ #overflowReported = false;
96857
96846
  #pendingTask = null;
96858
- #socket = null;
96847
+ #connection = { kind: "disconnected" };
96859
96848
  #timer;
96860
96849
  constructor(timer) {
96861
96850
  this.#timer = timer;
96862
96851
  }
96863
96852
  connect = (socket) => {
96864
- this.dropPendingEvents();
96865
- this.#socket = socket;
96853
+ if (this.#connection.kind === "closed") {
96854
+ return;
96855
+ }
96856
+ this.#connection = { kind: "connected", socket };
96857
+ this.flushEvents(socket);
96866
96858
  };
96867
96859
  disconnect = (socket) => {
96868
- if (this.#socket === socket) {
96869
- this.#socket = null;
96870
- this.dropPendingEvents();
96860
+ if (this.#connection.kind === "connected" && this.#connection.socket === socket) {
96861
+ this.#connection = { kind: "disconnected" };
96862
+ this.cancelFlush();
96871
96863
  }
96872
96864
  };
96873
96865
  close = () => {
96874
- this.#socket = null;
96875
- this.dropPendingEvents();
96866
+ this.#connection = { kind: "closed" };
96867
+ this.cancelFlush();
96868
+ this.#pending.length = 0;
96869
+ this.#pendingBytes = 0;
96876
96870
  };
96877
96871
  flush = () => {
96878
- if (this.#socket !== null) {
96879
- this.flushEvents(this.#socket);
96872
+ if (this.#connection.kind === "connected") {
96873
+ this.flushEvents(this.#connection.socket);
96880
96874
  }
96881
96875
  };
96882
96876
  publishOperationFailure = (sessionId, requestId, code, message) => {
@@ -96886,10 +96880,11 @@ var RuntimeSessionEventPublisher = class {
96886
96880
  publishInfo = (event) => this.#send(event);
96887
96881
  publishClosed = (event) => this.#send(event);
96888
96882
  #send = (message) => {
96889
- const socket = this.#socket;
96890
- if (socket === null || socket.readyState !== WebSocket8.OPEN) {
96883
+ const connection = this.#connection;
96884
+ if (connection.kind !== "connected" || connection.socket.readyState !== WebSocket8.OPEN) {
96891
96885
  return;
96892
96886
  }
96887
+ const socket = connection.socket;
96893
96888
  const encoded = encodeDaemonToServiceMessage(message);
96894
96889
  if (socket.bufferedAmount + Buffer.byteLength(encoded, "utf8") > MAX_BUFFERED_BYTES) {
96895
96890
  socket.close(LOCAL_BACKPRESSURE_CLOSE_CODE, "Live event transport overloaded");
@@ -96901,8 +96896,7 @@ var RuntimeSessionEventPublisher = class {
96901
96896
  }
96902
96897
  };
96903
96898
  publish = (event) => {
96904
- const socket = this.#socket;
96905
- if (socket === null || socket.readyState !== WebSocket8.OPEN) {
96899
+ if (this.#connection.kind === "closed") {
96906
96900
  return;
96907
96901
  }
96908
96902
  const bytes = Buffer.byteLength(JSON.stringify(event), "utf8") + 1;
@@ -96915,15 +96909,34 @@ var RuntimeSessionEventPublisher = class {
96915
96909
  });
96916
96910
  return;
96917
96911
  }
96918
- if (this.#pendingEvents.length > 0 && this.#pendingBytes + bytes > MAX_EVENT_BATCH_BYTES) {
96919
- this.flushEvents(socket);
96920
- if (socket.readyState !== WebSocket8.OPEN) {
96921
- return;
96912
+ let batch = this.#pending.at(-1);
96913
+ const newBatch = batch === void 0 || batch.events.length >= SESSION_EVENT_BATCH_MAX_SIZE || batch.bytes + bytes > MAX_EVENT_BATCH_BYTES;
96914
+ const additionalBytes = bytes + (newBatch ? EMPTY_ENVELOPE_BYTES : 0);
96915
+ if (this.#pendingBytes + additionalBytes > MAX_PENDING_BYTES2) {
96916
+ if (!this.#overflowReported) {
96917
+ this.#overflowReported = true;
96918
+ console.warn("Live Session output exceeded the pending buffer limit", {
96919
+ code: "live_event_buffer_full",
96920
+ sessionId: event.sessionId,
96921
+ eventId: event.eventId,
96922
+ maximumBytes: MAX_PENDING_BYTES2
96923
+ });
96922
96924
  }
96925
+ return;
96923
96926
  }
96924
- this.#pendingEvents.push(event);
96925
- this.#pendingBytes += bytes;
96926
- if (this.#pendingEvents.length >= SESSION_EVENT_BATCH_MAX_SIZE || this.#pendingBytes >= MAX_EVENT_BATCH_BYTES) {
96927
+ if (batch === void 0 || newBatch) {
96928
+ batch = { events: [], bytes: EMPTY_ENVELOPE_BYTES };
96929
+ this.#pending.push(batch);
96930
+ }
96931
+ batch.events.push(event);
96932
+ batch.bytes += bytes;
96933
+ this.#pendingBytes += additionalBytes;
96934
+ const connection = this.#connection;
96935
+ if (connection.kind !== "connected" || connection.socket.readyState !== WebSocket8.OPEN) {
96936
+ return;
96937
+ }
96938
+ const socket = connection.socket;
96939
+ if (this.#pending.length > 1 || batch.events.length >= SESSION_EVENT_BATCH_MAX_SIZE || batch.bytes >= MAX_EVENT_BATCH_BYTES) {
96927
96940
  this.flushEvents(socket);
96928
96941
  return;
96929
96942
  }
@@ -96932,29 +96945,35 @@ var RuntimeSessionEventPublisher = class {
96932
96945
  SESSION_EVENT_BATCH_WINDOW_MILLISECONDS
96933
96946
  );
96934
96947
  };
96935
- dropPendingEvents = () => {
96948
+ cancelFlush = () => {
96936
96949
  this.#pendingTask?.cancel();
96937
96950
  this.#pendingTask = null;
96938
- this.#pendingEvents = [];
96939
- this.#pendingBytes = EMPTY_ENVELOPE_BYTES;
96940
96951
  };
96941
96952
  flushEvents = (socket) => {
96942
- this.#pendingTask?.cancel();
96943
- this.#pendingTask = null;
96944
- const events = this.#pendingEvents;
96945
- this.#pendingEvents = [];
96946
- this.#pendingBytes = EMPTY_ENVELOPE_BYTES;
96947
- if (events.length === 0 || this.#socket !== socket || socket.readyState !== WebSocket8.OPEN) {
96953
+ this.cancelFlush();
96954
+ const connection = this.#connection;
96955
+ if (connection.kind !== "connected" || connection.socket !== socket || socket.readyState !== WebSocket8.OPEN) {
96948
96956
  return;
96949
96957
  }
96950
- const encoded = encodeDaemonToServiceMessage({ events, kind: SESSION_EVENT_KIND });
96951
- if (socket.bufferedAmount + Buffer.byteLength(encoded, "utf8") > MAX_BUFFERED_BYTES) {
96952
- socket.close(LOCAL_BACKPRESSURE_CLOSE_CODE, "Live event transport overloaded");
96953
- return;
96958
+ let attempted = 0;
96959
+ for (const batch of this.#pending) {
96960
+ const encoded = encodeDaemonToServiceMessage({ events: batch.events, kind: SESSION_EVENT_KIND });
96961
+ if (socket.bufferedAmount + Buffer.byteLength(encoded, "utf8") > MAX_BUFFERED_BYTES) {
96962
+ socket.close(LOCAL_BACKPRESSURE_CLOSE_CODE, "Live event transport overloaded");
96963
+ break;
96964
+ }
96965
+ attempted += 1;
96966
+ this.#pendingBytes -= batch.bytes;
96967
+ try {
96968
+ socket.send(encoded);
96969
+ } catch {
96970
+ console.warn("Live Session output could not be sent", { code: "live_event_send_failed" });
96971
+ break;
96972
+ }
96954
96973
  }
96955
- try {
96956
- socket.send(encoded);
96957
- } catch {
96974
+ this.#pending.splice(0, attempted);
96975
+ if (this.#pending.length === 0) {
96976
+ this.#overflowReported = false;
96958
96977
  }
96959
96978
  };
96960
96979
  };