@moxt-ai/mobius 0.0.101 → 0.0.102

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
@@ -25662,6 +25662,7 @@ var nativeSessionTurnForkCommandSchema = external_exports.strictObject({
25662
25662
  var nativeSessionRequestSchema = external_exports.discriminatedUnion("action", [
25663
25663
  external_exports.strictObject({ ...identity, action: external_exports.literal("create") }).readonly(),
25664
25664
  external_exports.strictObject({ ...identity, action: external_exports.literal("linked-history"), targetSessionId: identifier }).readonly(),
25665
+ external_exports.strictObject({ ...identity, action: external_exports.literal("active-turn"), targetSessionId: identifier }).readonly(),
25665
25666
  external_exports.strictObject({ ...identity, action: external_exports.literal("preview"), entryId: identifier }).readonly(),
25666
25667
  external_exports.strictObject({ ...identity, action: external_exports.literal("history"), entryId: identifier }).readonly(),
25667
25668
  external_exports.strictObject({ ...identity, action: external_exports.literal("find"), nativeSessionId: identifier }).readonly(),
@@ -25685,6 +25686,7 @@ var nativeSessionRequestSchema = external_exports.discriminatedUnion("action", [
25685
25686
  var nativeSessionCommandSchema = external_exports.discriminatedUnion("action", [
25686
25687
  external_exports.strictObject({ ...identity, action: external_exports.literal("create") }).readonly(),
25687
25688
  external_exports.strictObject({ ...identity, action: external_exports.literal("linked-history"), targetSessionId: identifier }).readonly(),
25689
+ external_exports.strictObject({ ...identity, action: external_exports.literal("active-turn"), targetSessionId: identifier }).readonly(),
25688
25690
  external_exports.strictObject({ ...identity, action: external_exports.literal("preview"), entryId: identifier }).readonly(),
25689
25691
  external_exports.strictObject({ ...identity, action: external_exports.literal("history"), entryId: identifier }).readonly(),
25690
25692
  external_exports.strictObject({ ...identity, action: external_exports.literal("find"), nativeSessionId: identifier }).readonly(),
@@ -25732,6 +25734,20 @@ var nativeSessionResultSchema = external_exports.discriminatedUnion("action", [
25732
25734
  targetSessionId: identifier,
25733
25735
  history: sessionHistorySchema
25734
25736
  }).readonly(),
25737
+ external_exports.strictObject({
25738
+ ...resultEnvelope,
25739
+ action: external_exports.literal("active-turn"),
25740
+ targetSessionId: identifier,
25741
+ turn: external_exports.strictObject({
25742
+ commandId: identifier,
25743
+ prompt: external_exports.string().max(1e5),
25744
+ text: external_exports.string().max(1e5),
25745
+ truncated: external_exports.boolean(),
25746
+ epoch: identifier,
25747
+ sequence: external_exports.number().int().nonnegative(),
25748
+ state: external_exports.literal("running")
25749
+ }).readonly().nullable()
25750
+ }).readonly(),
25735
25751
  external_exports.strictObject({
25736
25752
  ...resultEnvelope,
25737
25753
  action: external_exports.literal("unlinked-history"),
@@ -26295,7 +26311,7 @@ function createDaemonConfig(connection, agents = [], installableAgents = [], loc
26295
26311
  }
26296
26312
 
26297
26313
  // src/run-daemon.ts
26298
- import { randomUUID as randomUUID4 } from "node:crypto";
26314
+ import { randomUUID as randomUUID5 } from "node:crypto";
26299
26315
  import { styleText } from "node:util";
26300
26316
  import { WebSocket as WebSocket5 } from "undici";
26301
26317
 
@@ -33000,7 +33016,7 @@ async function executeSessionConfigure(publisher, socket, command, config2, dire
33000
33016
  reportOperationFailure(socket, command.requestId, command.sessionId, error62);
33001
33017
  }
33002
33018
  }
33003
- async function executePrompt(outbox, publisher, command, config2, directories, audit, sessions, attemptId, activateAttempt, timer, signal) {
33019
+ async function executePrompt(outbox, publisher, command, config2, directories, audit, sessions, attemptId, activateAttempt, timer, signal, recordLiveText) {
33004
33020
  const activities = new CoalescingDaemonActivityPublisher(timer, (activity2) => {
33005
33021
  publisher.recordAttempt(command.sessionId, daemonActivity(command, activity2), attemptId);
33006
33022
  });
@@ -33133,6 +33149,7 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
33133
33149
  return Promise.resolve();
33134
33150
  },
33135
33151
  onText: (delta, messageId) => {
33152
+ recordLiveText(delta);
33136
33153
  text.record(messageId, delta);
33137
33154
  return Promise.resolve();
33138
33155
  },
@@ -33319,14 +33336,21 @@ var DaemonInstallationObserver = class {
33319
33336
  };
33320
33337
 
33321
33338
  // src/daemon-turn-reconciliation.ts
33339
+ import { randomUUID as randomUUID2 } from "node:crypto";
33322
33340
  import { fetch as fetch4 } from "undici";
33323
33341
  var ACTIVE_TURN_RECONCILIATION_TIMEOUT_MILLISECONDS = 2e4;
33342
+ var ACTIVE_TURN_TEXT_LIMIT = 1e5;
33324
33343
  var ActiveDaemonTurn = class {
33325
33344
  attemptId;
33326
33345
  command;
33327
33346
  #controller;
33328
33347
  #finished = Promise.withResolvers();
33329
33348
  #cancellationRequested = false;
33349
+ #accepted = false;
33350
+ #text = "";
33351
+ #truncated = false;
33352
+ #sequence = 0;
33353
+ #epoch = randomUUID2();
33330
33354
  constructor(command, attemptId) {
33331
33355
  this.attemptId = attemptId;
33332
33356
  this.command = command;
@@ -33336,6 +33360,26 @@ var ActiveDaemonTurn = class {
33336
33360
  this.#controller.abort();
33337
33361
  };
33338
33362
  finish = () => this.#finished.resolve();
33363
+ accept = () => {
33364
+ this.#accepted = true;
33365
+ };
33366
+ recordText = (delta) => {
33367
+ this.#sequence += 1;
33368
+ this.#text += delta;
33369
+ if (this.#text.length > ACTIVE_TURN_TEXT_LIMIT) {
33370
+ this.#text = this.#text.slice(-ACTIVE_TURN_TEXT_LIMIT);
33371
+ this.#truncated = true;
33372
+ }
33373
+ };
33374
+ snapshot = () => this.#accepted ? {
33375
+ commandId: this.command.commandId,
33376
+ prompt: this.command.prompt,
33377
+ text: this.#text,
33378
+ truncated: this.#truncated,
33379
+ epoch: this.#epoch,
33380
+ sequence: this.#sequence,
33381
+ state: "running"
33382
+ } : null;
33339
33383
  matches = (cancellation) => cancellation.commandId === this.command.commandId && cancellation.sessionId === this.command.sessionId;
33340
33384
  requestCancellation = () => {
33341
33385
  if (this.#cancellationRequested) {
@@ -33859,7 +33903,7 @@ var readCodexHistory = async (agent, cwd, nativeSessionId, signal) => await read
33859
33903
  var readCodexFullHistory = async (agent, cwd, nativeSessionId, signal) => await readCodexHistoryWithOptions(agent, cwd, nativeSessionId, signal, { detail: "rich" });
33860
33904
 
33861
33905
  // src/native-sessions/service.ts
33862
- import { randomUUID as randomUUID2 } from "node:crypto";
33906
+ import { randomUUID as randomUUID3 } from "node:crypto";
33863
33907
  import { basename as basename6 } from "node:path";
33864
33908
 
33865
33909
  // src/native-sessions/acp-history.ts
@@ -33951,11 +33995,13 @@ var NativeSessionService = class {
33951
33995
  #directories;
33952
33996
  #sessions;
33953
33997
  #audit;
33954
- constructor(config2, directories, sessions, audit) {
33998
+ #activeTurn;
33999
+ constructor(config2, directories, sessions, audit, activeTurn) {
33955
34000
  this.#config = config2;
33956
34001
  this.#directories = directories;
33957
34002
  this.#sessions = sessions;
33958
34003
  this.#audit = audit;
34004
+ this.#activeTurn = activeTurn;
33959
34005
  }
33960
34006
  execute = async (command, signal) => {
33961
34007
  signal.throwIfAborted();
@@ -33973,6 +34019,18 @@ var NativeSessionService = class {
33973
34019
  sessionId: command.sessionId,
33974
34020
  signal
33975
34021
  };
34022
+ if (command.action === "active-turn") {
34023
+ nativeSessionIdSchema.parse(command.targetSessionId);
34024
+ this.record(command, "active_turn_read");
34025
+ return {
34026
+ action: "active-turn",
34027
+ kind: "native.session.result",
34028
+ requestId: command.requestId,
34029
+ sessionId: command.sessionId,
34030
+ targetSessionId: command.targetSessionId,
34031
+ turn: this.#activeTurn(command)
34032
+ };
34033
+ }
33976
34034
  if (command.action === "linked-history") {
33977
34035
  const nativeSessionId = nativeSessionIdSchema.parse(command.targetSessionId);
33978
34036
  if (this.#sessions.hasPreparedSession(nativeSessionId, options.agent.id, cwd, additionalDirectories) && await this.#sessions.loadLinkedSessionHistory({ ...options, sessionId: nativeSessionId }) === null) {
@@ -34043,7 +34101,7 @@ var NativeSessionService = class {
34043
34101
  if (authorized === null) {
34044
34102
  return null;
34045
34103
  }
34046
- const entryId = randomUUID2();
34104
+ const entryId = randomUUID3();
34047
34105
  if (this.#entries.size >= 5e3) {
34048
34106
  this.#entries.clear();
34049
34107
  }
@@ -34098,7 +34156,7 @@ var NativeSessionService = class {
34098
34156
  "invalid_native_session_response"
34099
34157
  );
34100
34158
  }
34101
- nextCursor = randomUUID2();
34159
+ nextCursor = randomUUID3();
34102
34160
  if (this.#cursors.size >= 500) {
34103
34161
  this.#cursors.clear();
34104
34162
  }
@@ -34717,7 +34775,7 @@ var RelayConnectionDiagnostics = class {
34717
34775
  };
34718
34776
 
34719
34777
  // src/relay-connection/liveness.ts
34720
- import { randomUUID as randomUUID3 } from "node:crypto";
34778
+ import { randomUUID as randomUUID4 } from "node:crypto";
34721
34779
  var HEARTBEAT_ACK_TIMEOUT_MILLISECONDS = 1e4;
34722
34780
  var HEARTBEAT_INTERVAL_MILLISECONDS = 2e4;
34723
34781
  var RelayLivenessState = class {
@@ -34806,7 +34864,7 @@ var RelayConnectionLiveness = class {
34806
34864
  }
34807
34865
  throw new Error("Heartbeat was scheduled in an invalid state");
34808
34866
  }
34809
- const heartbeatId = randomUUID3();
34867
+ const heartbeatId = randomUUID4();
34810
34868
  this.#state = new AwaitingHeartbeatAckState(
34811
34869
  heartbeatId,
34812
34870
  this.#timer.schedule(this.#handleTimeout, HEARTBEAT_ACK_TIMEOUT_MILLISECONDS)
@@ -35654,7 +35712,7 @@ async function installDetectedAgentIntegrations(config2, installations, signal)
35654
35712
  {
35655
35713
  agentId: agent.id,
35656
35714
  kind: AGENT_INSTALL_REQUEST_KIND,
35657
- requestId: `automatic-integration-${randomUUID4()}`
35715
+ requestId: `automatic-integration-${randomUUID5()}`
35658
35716
  },
35659
35717
  signal
35660
35718
  );
@@ -35782,12 +35840,13 @@ async function runRelayConnection(config2, directories, audit, sessions, install
35782
35840
  const turn = new ActiveDaemonTurn(command, receipt.attemptId);
35783
35841
  activeTurns.set(command.commandId, turn);
35784
35842
  const activateAttempt = () => {
35843
+ turn.accept();
35785
35844
  if (trackActiveAttempt) {
35786
35845
  activeAttemptIds.set(command.sessionId, receipt.attemptId);
35787
35846
  }
35788
35847
  };
35789
35848
  try {
35790
- await execute(receipt.attemptId, activateAttempt, turn.signal);
35849
+ await execute(receipt.attemptId, activateAttempt, turn.signal, turn);
35791
35850
  } finally {
35792
35851
  activeTurns.delete(command.commandId);
35793
35852
  if (activeAttemptIds.get(command.sessionId) === receipt.attemptId) {
@@ -35877,7 +35936,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
35877
35936
  delivery,
35878
35937
  command,
35879
35938
  command.disposition !== SessionPromptDisposition.Steer,
35880
- (attemptId, activateAttempt, executionSignal) => executePrompt(
35939
+ (attemptId, activateAttempt, executionSignal, turn) => executePrompt(
35881
35940
  outbox,
35882
35941
  publisher,
35883
35942
  command,
@@ -35888,7 +35947,8 @@ async function runRelayConnection(config2, directories, audit, sessions, install
35888
35947
  attemptId,
35889
35948
  activateAttempt,
35890
35949
  timer,
35891
- executionSignal
35950
+ executionSignal,
35951
+ turn.recordText
35892
35952
  )
35893
35953
  );
35894
35954
  return;
@@ -36317,7 +36377,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
36317
36377
  const previous = [...nativeRequests.values()].filter(
36318
36378
  (request) => request.agentId === command2.agentId
36319
36379
  );
36320
- if (nativeRequests.has(command2.requestId) || nativeRequests.size >= 4 || command2.action !== "linked-history" && previous.some((request) => !request.controller.signal.aborted)) {
36380
+ if (nativeRequests.has(command2.requestId) || nativeRequests.size >= 4 || command2.action !== "linked-history" && command2.action !== "active-turn" && previous.some((request) => !request.controller.signal.aborted)) {
36321
36381
  reportOperationFailure(
36322
36382
  socket,
36323
36383
  command2.requestId,
@@ -36345,7 +36405,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
36345
36405
  const completion = (async () => {
36346
36406
  try {
36347
36407
  operationSignal.throwIfAborted();
36348
- if (previous.length > 0) {
36408
+ if (previous.length > 0 && command2.action !== "active-turn") {
36349
36409
  await new Promise((resolve9, reject2) => {
36350
36410
  const cancel = () => reject2(operationSignal.reason);
36351
36411
  operationSignal.addEventListener("abort", cancel, {
@@ -36639,12 +36699,14 @@ async function runRelayConnection(config2, directories, audit, sessions, install
36639
36699
  sessions,
36640
36700
  receipt.attemptId,
36641
36701
  () => {
36702
+ turn.accept();
36642
36703
  if (command.disposition !== SessionPromptDisposition.Steer) {
36643
36704
  activeAttemptIds.set(command.sessionId, receipt.attemptId);
36644
36705
  }
36645
36706
  },
36646
36707
  timer,
36647
- turn.signal
36708
+ turn.signal,
36709
+ turn.recordText
36648
36710
  ).catch((error62) => {
36649
36711
  console.error("Mobius daemon turn failed", error62);
36650
36712
  }).finally(() => {
@@ -36764,7 +36826,14 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
36764
36826
  config2.relayUrl,
36765
36827
  new DaemonDiagnosticLog(stateDirectory)
36766
36828
  );
36767
- const nativeSessions = new NativeSessionService(config2, directories, sessions, audit);
36829
+ const nativeSessions = new NativeSessionService(config2, directories, sessions, audit, (request) => {
36830
+ const turn = [...activeTurns.values()].find(
36831
+ (candidate) => candidate.command.sessionId === request.targetSessionId && candidate.command.agentId === request.agentId && candidate.command.directoryId === request.directoryId && candidate.command.additionalDirectoryIds.length === request.additionalDirectoryIds.length && candidate.command.additionalDirectoryIds.every(
36832
+ (directoryId2, index) => directoryId2 === request.additionalDirectoryIds[index]
36833
+ )
36834
+ );
36835
+ return turn?.snapshot() ?? null;
36836
+ });
36768
36837
  const installations = new AgentInstallationManager(
36769
36838
  specifications,
36770
36839
  installationExecutor,
@@ -36909,7 +36978,7 @@ import { basename as basename7, resolve as resolve6 } from "node:path";
36909
36978
  import { fetch as fetch5 } from "undici";
36910
36979
 
36911
36980
  // src/storage/runtime-installation-store.ts
36912
- import { createHash as createHash5, randomUUID as randomUUID5 } from "node:crypto";
36981
+ import { createHash as createHash5, randomUUID as randomUUID6 } from "node:crypto";
36913
36982
  import { mkdir as mkdir4, open as open5, readdir as readdir3, rename as rename3, unlink, writeFile as writeFile3 } from "node:fs/promises";
36914
36983
  import { dirname as dirname4, join as join17, resolve as resolve5 } from "node:path";
36915
36984
  var APPLICATION_ID_PATTERN = /^[a-z][a-z0-9]*(?:[.-][a-z0-9]+){1,31}$/;
@@ -37040,10 +37109,10 @@ function parseRelayOrigin(value) {
37040
37109
  return origin;
37041
37110
  }
37042
37111
  function connectionId() {
37043
- return `mcn_${randomUUID5().replaceAll("-", "")}`;
37112
+ return `mcn_${randomUUID6().replaceAll("-", "")}`;
37044
37113
  }
37045
37114
  function installationId() {
37046
- return `min_${randomUUID5().replaceAll("-", "")}`;
37115
+ return `min_${randomUUID6().replaceAll("-", "")}`;
37047
37116
  }
37048
37117
  function channelIndexFileName(channelId) {
37049
37118
  return `mci_${createHash5("sha256").update(channelId).digest("hex")}.json`;
@@ -37155,7 +37224,7 @@ async function readJsonFile(path2, signal, missingCode) {
37155
37224
  async function writeJsonAtomically(path2, value, signal) {
37156
37225
  signal.throwIfAborted();
37157
37226
  const directory = dirname4(path2);
37158
- const temporaryPath = join17(directory, `.${randomUUID5()}.tmp`);
37227
+ const temporaryPath = join17(directory, `.${randomUUID6()}.tmp`);
37159
37228
  try {
37160
37229
  await mkdir4(directory, { mode: 448, recursive: true });
37161
37230
  signal.throwIfAborted();