@moxt-ai/mobius 0.0.140 → 0.0.142

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
@@ -3381,7 +3381,7 @@ var program = new Command();
3381
3381
  // package.json
3382
3382
  var package_default = {
3383
3383
  name: "@moxt-ai/mobius",
3384
- version: "0.0.140",
3384
+ version: "0.0.142",
3385
3385
  description: "Mobius CLI for pairing and running local AI agent services.",
3386
3386
  type: "module",
3387
3387
  bin: {
@@ -42213,6 +42213,7 @@ var ActiveDaemonTurn = class {
42213
42213
  state: "running"
42214
42214
  } : null;
42215
42215
  matches = (cancellation) => cancellation.commandId === this.command.commandId && cancellation.sessionId === this.command.sessionId;
42216
+ matchesInteraction = (interactionId, sessionId) => this.command.sessionId === sessionId && this.#interaction?.interactionId === interactionId;
42216
42217
  requestCancellation = () => {
42217
42218
  if (this.#cancellationRequested) {
42218
42219
  return "already-requested";
@@ -42281,6 +42282,13 @@ var DaemonTurnRegistry = class {
42281
42282
  return turn.recordEvent(event);
42282
42283
  }
42283
42284
  }
42285
+ if (event.kind === SESSION_PERMISSION_RESOLVED_KIND || event.kind === SESSION_ELICITATION_RESOLVED_KIND) {
42286
+ for (const turn of this.#turns.values()) {
42287
+ if (turn.matchesInteraction(event.interactionId, event.sessionId)) {
42288
+ return turn.recordEvent(event);
42289
+ }
42290
+ }
42291
+ }
42284
42292
  return event;
42285
42293
  };
42286
42294
  executionSnapshot = async (matches) => {
@@ -42441,6 +42449,69 @@ function errorMessage(value) {
42441
42449
  function messageSize(message) {
42442
42450
  return message.text.length + (message.role === "assistant" ? JSON.stringify(message.activities).length + JSON.stringify(message.content).length : 0);
42443
42451
  }
42452
+ var SESSION_HISTORY_MESSAGE_CHARACTER_LIMIT = Math.floor(SESSION_HISTORY_CHARACTER_LIMIT / 2);
42453
+ function fitActivity(activity2, maximumCharacters) {
42454
+ const truncate5 = (limit) => ({
42455
+ ...activity2,
42456
+ input: bounded(activity2.input, limit),
42457
+ locations: activity2.locations.map((location) => bounded(location, Math.max(1, limit))),
42458
+ name: bounded(activity2.name, limit),
42459
+ output: bounded(activity2.output, limit),
42460
+ title: bounded(activity2.title, limit),
42461
+ toolKind: bounded(activity2.toolKind, limit)
42462
+ });
42463
+ let minimum = 1;
42464
+ let maximum = 1e5;
42465
+ let fitted = truncate5(0);
42466
+ while (minimum <= maximum) {
42467
+ const limit = Math.floor((minimum + maximum) / 2);
42468
+ const candidate = truncate5(limit);
42469
+ if (JSON.stringify(candidate).length <= maximumCharacters) {
42470
+ fitted = candidate;
42471
+ minimum = limit + 1;
42472
+ } else {
42473
+ maximum = limit - 1;
42474
+ }
42475
+ }
42476
+ return fitted;
42477
+ }
42478
+ function fitActivities(activities, maximumCharacters) {
42479
+ if (activities.length === 0) {
42480
+ return activities;
42481
+ }
42482
+ const arrayCharacters = 2 + activities.length - 1;
42483
+ const maximumActivityCharacters = Math.floor(Math.max(0, maximumCharacters - arrayCharacters) / activities.length);
42484
+ return activities.map((activity2) => fitActivity(activity2, maximumActivityCharacters));
42485
+ }
42486
+ function fitHistoryMessage(message) {
42487
+ const text2 = message.text.slice(-SESSION_HISTORY_MESSAGE_CHARACTER_LIMIT);
42488
+ if (message.role === "user") {
42489
+ return {
42490
+ message: { ...message, text: text2 },
42491
+ truncated: text2.length < message.text.length
42492
+ };
42493
+ }
42494
+ let activities = message.activities;
42495
+ const content = message.content;
42496
+ let fitted = { ...message, activities, content, text: text2 };
42497
+ if (messageSize(fitted) > SESSION_HISTORY_MESSAGE_CHARACTER_LIMIT && activities.length > 0) {
42498
+ const maximumCharacters = SESSION_HISTORY_MESSAGE_CHARACTER_LIMIT - text2.length - JSON.stringify(content).length;
42499
+ activities = fitActivities(activities, maximumCharacters);
42500
+ fitted = { ...fitted, activities };
42501
+ }
42502
+ const excess = Math.max(0, messageSize(fitted) - SESSION_HISTORY_MESSAGE_CHARACTER_LIMIT);
42503
+ if (excess > 0) {
42504
+ const maximumTextLength = Math.max(0, fitted.text.length - excess);
42505
+ fitted = {
42506
+ ...fitted,
42507
+ text: maximumTextLength === 0 ? "" : fitted.text.slice(-maximumTextLength)
42508
+ };
42509
+ }
42510
+ return {
42511
+ message: fitted,
42512
+ truncated: fitted.text.length < message.text.length || JSON.stringify(activities).length < JSON.stringify(message.activities).length
42513
+ };
42514
+ }
42444
42515
  function turnOutcome(status) {
42445
42516
  switch (status) {
42446
42517
  case "completed":
@@ -42467,14 +42538,20 @@ function decodeHistory(thread, value, options) {
42467
42538
  for (const turn of page.data.toReversed()) {
42468
42539
  const outcome = turnOutcome(turn.status);
42469
42540
  const activities = [];
42541
+ let assignedActivityCount = 0;
42470
42542
  let sequence = 0;
42471
42543
  let assistantMessageIndex = null;
42544
+ const activitySlice = () => {
42545
+ const assigned = activities.slice(assignedActivityCount).slice(-100);
42546
+ assignedActivityCount = activities.length;
42547
+ return assigned;
42548
+ };
42472
42549
  for (const item of turn.items) {
42473
42550
  const { type } = itemTypeSchema.parse(item);
42474
42551
  let message;
42475
42552
  if (type === "userMessage") {
42476
42553
  const { content } = userMessageSchema.parse(item);
42477
- const text3 = content.map((block) => {
42554
+ const text2 = content.map((block) => {
42478
42555
  const { type: type2 } = itemTypeSchema.parse(block);
42479
42556
  if (type2 === "text") {
42480
42557
  return textSchema.parse(block).text;
@@ -42486,7 +42563,7 @@ function decodeHistory(thread, value, options) {
42486
42563
  }).join("");
42487
42564
  message = {
42488
42565
  role: "user",
42489
- text: text3
42566
+ text: text2
42490
42567
  };
42491
42568
  } else if (type === "agentMessage") {
42492
42569
  const agent = agentMessageSchema.parse(item);
@@ -42507,7 +42584,7 @@ function decodeHistory(thread, value, options) {
42507
42584
  }
42508
42585
  continue;
42509
42586
  }
42510
- message = { activities: activities.slice(-100), content: [], role: "assistant", text: agent.text };
42587
+ message = { activities: activitySlice(), content: [], role: "assistant", text: agent.text };
42511
42588
  } else if (type === "reasoning" && options.detail === "rich") {
42512
42589
  const reasoning = reasoningSchema.parse(item);
42513
42590
  const output2 = (reasoning.summary.length > 0 ? reasoning.summary : reasoning.content).join("\n\n");
@@ -42548,16 +42625,16 @@ function decodeHistory(thread, value, options) {
42548
42625
  } else {
42549
42626
  continue;
42550
42627
  }
42551
- const text2 = message.text.slice(-SESSION_HISTORY_CHARACTER_LIMIT);
42552
- if (text2.length === 0 && (message.images?.length ?? 0) === 0) {
42628
+ const fitted = fitHistoryMessage(message);
42629
+ if (fitted.message.text.length === 0 && (fitted.message.images?.length ?? 0) === 0) {
42553
42630
  continue;
42554
42631
  }
42555
- truncated ||= text2.length < message.text.length;
42556
- messages.push({ ...message, text: text2 });
42632
+ truncated ||= fitted.truncated;
42633
+ messages.push(fitted.message);
42557
42634
  if (message.role === "assistant") {
42558
42635
  assistantMessageIndex = messages.length - 1;
42559
42636
  }
42560
- characters += messageSize({ ...message, text: text2 });
42637
+ characters += messageSize(fitted.message);
42561
42638
  }
42562
42639
  if (options.detail === "rich" && turn.error != null) {
42563
42640
  activities.push(
@@ -42572,17 +42649,29 @@ function decodeHistory(thread, value, options) {
42572
42649
  })
42573
42650
  );
42574
42651
  }
42652
+ if (options.detail === "rich" && activities.length > assignedActivityCount) {
42653
+ const message = {
42654
+ activities: activitySlice(),
42655
+ content: [],
42656
+ role: "assistant",
42657
+ text: ""
42658
+ };
42659
+ messages.push(message);
42660
+ assistantMessageIndex = messages.length - 1;
42661
+ characters += messageSize(message);
42662
+ }
42575
42663
  if (assistantMessageIndex !== null) {
42576
42664
  const assistant = messages[assistantMessageIndex];
42577
42665
  if (assistant?.role === "assistant") {
42578
42666
  characters -= messageSize(assistant);
42579
42667
  const updated = {
42580
42668
  ...assistant,
42581
- ...outcome === void 0 ? {} : { outcome },
42582
- activities: activities.slice(-100)
42669
+ ...outcome === void 0 ? {} : { outcome }
42583
42670
  };
42584
- messages[assistantMessageIndex] = updated;
42585
- characters += messageSize(updated);
42671
+ const fitted = fitHistoryMessage(updated);
42672
+ truncated ||= fitted.truncated;
42673
+ messages[assistantMessageIndex] = fitted.message;
42674
+ characters += messageSize(fitted.message);
42586
42675
  }
42587
42676
  } else if (activities.length > 0 || outcome !== void 0) {
42588
42677
  const message = {
@@ -42592,8 +42681,10 @@ function decodeHistory(thread, value, options) {
42592
42681
  ...outcome === void 0 ? {} : { outcome },
42593
42682
  text: ""
42594
42683
  };
42595
- messages.push(message);
42596
- characters += messageSize(message);
42684
+ const fitted = fitHistoryMessage(message);
42685
+ truncated ||= fitted.truncated;
42686
+ messages.push(fitted.message);
42687
+ characters += messageSize(fitted.message);
42597
42688
  }
42598
42689
  while (messages.length > (options.detail === "rich" ? SESSION_HISTORY_MESSAGE_LIMIT : SESSION_HISTORY_PREVIEW_MESSAGE_LIMIT) || characters > SESSION_HISTORY_CHARACTER_LIMIT) {
42599
42690
  const removed = messages.shift();