@moxt-ai/mobius 0.0.101 → 0.0.103

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
@@ -25415,12 +25415,18 @@ function decodeSessionStartedEvent(encoded) {
25415
25415
  }
25416
25416
  function decodeAgentMessageDeltaEvent(encoded) {
25417
25417
  const value = parseJson2(encoded);
25418
- assertExactKeys(value, ["commandId", "kind", "messageId", "sessionId", "text"]);
25418
+ assertExactKeys(value, ["commandId", "epoch", "kind", "messageId", "sequence", "sessionId", "text"]);
25419
25419
  assertKind(value, AGENT_MESSAGE_DELTA_KIND);
25420
+ const sequence = readSequence(value, "sequence");
25421
+ if (sequence === 0) {
25422
+ throw new ProtocolMessageError("Invalid live sequence");
25423
+ }
25420
25424
  return {
25421
25425
  commandId: readIdentifier(value, "commandId"),
25426
+ epoch: readIdentifier(value, "epoch"),
25422
25427
  kind: AGENT_MESSAGE_DELTA_KIND,
25423
25428
  messageId: value["messageId"] === void 0 ? "" : readText(value, "messageId", 255),
25429
+ sequence,
25424
25430
  sessionId: readIdentifier(value, "sessionId"),
25425
25431
  text: readString(value, "text", MAX_EVENT_TEXT_LENGTH)
25426
25432
  };
@@ -25662,6 +25668,7 @@ var nativeSessionTurnForkCommandSchema = external_exports.strictObject({
25662
25668
  var nativeSessionRequestSchema = external_exports.discriminatedUnion("action", [
25663
25669
  external_exports.strictObject({ ...identity, action: external_exports.literal("create") }).readonly(),
25664
25670
  external_exports.strictObject({ ...identity, action: external_exports.literal("linked-history"), targetSessionId: identifier }).readonly(),
25671
+ external_exports.strictObject({ ...identity, action: external_exports.literal("active-turn"), targetSessionId: identifier }).readonly(),
25665
25672
  external_exports.strictObject({ ...identity, action: external_exports.literal("preview"), entryId: identifier }).readonly(),
25666
25673
  external_exports.strictObject({ ...identity, action: external_exports.literal("history"), entryId: identifier }).readonly(),
25667
25674
  external_exports.strictObject({ ...identity, action: external_exports.literal("find"), nativeSessionId: identifier }).readonly(),
@@ -25685,6 +25692,7 @@ var nativeSessionRequestSchema = external_exports.discriminatedUnion("action", [
25685
25692
  var nativeSessionCommandSchema = external_exports.discriminatedUnion("action", [
25686
25693
  external_exports.strictObject({ ...identity, action: external_exports.literal("create") }).readonly(),
25687
25694
  external_exports.strictObject({ ...identity, action: external_exports.literal("linked-history"), targetSessionId: identifier }).readonly(),
25695
+ external_exports.strictObject({ ...identity, action: external_exports.literal("active-turn"), targetSessionId: identifier }).readonly(),
25688
25696
  external_exports.strictObject({ ...identity, action: external_exports.literal("preview"), entryId: identifier }).readonly(),
25689
25697
  external_exports.strictObject({ ...identity, action: external_exports.literal("history"), entryId: identifier }).readonly(),
25690
25698
  external_exports.strictObject({ ...identity, action: external_exports.literal("find"), nativeSessionId: identifier }).readonly(),
@@ -25732,6 +25740,20 @@ var nativeSessionResultSchema = external_exports.discriminatedUnion("action", [
25732
25740
  targetSessionId: identifier,
25733
25741
  history: sessionHistorySchema
25734
25742
  }).readonly(),
25743
+ external_exports.strictObject({
25744
+ ...resultEnvelope,
25745
+ action: external_exports.literal("active-turn"),
25746
+ targetSessionId: identifier,
25747
+ turn: external_exports.strictObject({
25748
+ commandId: identifier,
25749
+ prompt: external_exports.string().max(1e5),
25750
+ text: external_exports.string().max(1e5),
25751
+ truncated: external_exports.boolean(),
25752
+ epoch: identifier,
25753
+ sequence: external_exports.number().int().nonnegative(),
25754
+ state: external_exports.literal("running")
25755
+ }).readonly().nullable()
25756
+ }).readonly(),
25735
25757
  external_exports.strictObject({
25736
25758
  ...resultEnvelope,
25737
25759
  action: external_exports.literal("unlinked-history"),
@@ -26295,7 +26317,7 @@ function createDaemonConfig(connection, agents = [], installableAgents = [], loc
26295
26317
  }
26296
26318
 
26297
26319
  // src/run-daemon.ts
26298
- import { randomUUID as randomUUID4 } from "node:crypto";
26320
+ import { randomUUID as randomUUID5 } from "node:crypto";
26299
26321
  import { styleText } from "node:util";
26300
26322
  import { WebSocket as WebSocket5 } from "undici";
26301
26323
 
@@ -33000,7 +33022,7 @@ async function executeSessionConfigure(publisher, socket, command, config2, dire
33000
33022
  reportOperationFailure(socket, command.requestId, command.sessionId, error62);
33001
33023
  }
33002
33024
  }
33003
- async function executePrompt(outbox, publisher, command, config2, directories, audit, sessions, attemptId, activateAttempt, timer, signal) {
33025
+ async function executePrompt(outbox, publisher, command, config2, directories, audit, sessions, attemptId, activateAttempt, timer, signal, recordLiveText) {
33004
33026
  const activities = new CoalescingDaemonActivityPublisher(timer, (activity2) => {
33005
33027
  publisher.recordAttempt(command.sessionId, daemonActivity(command, activity2), attemptId);
33006
33028
  });
@@ -33027,12 +33049,15 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
33027
33049
  const text = new CoalescingTextPublisher(
33028
33050
  timer,
33029
33051
  (messageId, delta) => {
33052
+ const stream = recordLiveText(delta);
33030
33053
  publisher.recordAttempt(
33031
33054
  command.sessionId,
33032
33055
  {
33033
33056
  commandId: command.commandId,
33057
+ epoch: stream.epoch,
33034
33058
  kind: AGENT_MESSAGE_DELTA_KIND,
33035
33059
  messageId,
33060
+ sequence: stream.sequence,
33036
33061
  sessionId: command.sessionId,
33037
33062
  text: delta
33038
33063
  },
@@ -33319,14 +33344,21 @@ var DaemonInstallationObserver = class {
33319
33344
  };
33320
33345
 
33321
33346
  // src/daemon-turn-reconciliation.ts
33347
+ import { randomUUID as randomUUID2 } from "node:crypto";
33322
33348
  import { fetch as fetch4 } from "undici";
33323
33349
  var ACTIVE_TURN_RECONCILIATION_TIMEOUT_MILLISECONDS = 2e4;
33350
+ var ACTIVE_TURN_TEXT_LIMIT = 1e5;
33324
33351
  var ActiveDaemonTurn = class {
33325
33352
  attemptId;
33326
33353
  command;
33327
33354
  #controller;
33328
33355
  #finished = Promise.withResolvers();
33329
33356
  #cancellationRequested = false;
33357
+ #accepted = false;
33358
+ #text = "";
33359
+ #truncated = false;
33360
+ #sequence = 0;
33361
+ #epoch = randomUUID2();
33330
33362
  constructor(command, attemptId) {
33331
33363
  this.attemptId = attemptId;
33332
33364
  this.command = command;
@@ -33336,6 +33368,27 @@ var ActiveDaemonTurn = class {
33336
33368
  this.#controller.abort();
33337
33369
  };
33338
33370
  finish = () => this.#finished.resolve();
33371
+ accept = () => {
33372
+ this.#accepted = true;
33373
+ };
33374
+ recordText = (delta) => {
33375
+ this.#sequence += 1;
33376
+ this.#text += delta;
33377
+ if (this.#text.length > ACTIVE_TURN_TEXT_LIMIT) {
33378
+ this.#text = this.#text.slice(-ACTIVE_TURN_TEXT_LIMIT);
33379
+ this.#truncated = true;
33380
+ }
33381
+ return { epoch: this.#epoch, sequence: this.#sequence };
33382
+ };
33383
+ snapshot = () => this.#accepted ? {
33384
+ commandId: this.command.commandId,
33385
+ prompt: this.command.prompt,
33386
+ text: this.#text,
33387
+ truncated: this.#truncated,
33388
+ epoch: this.#epoch,
33389
+ sequence: this.#sequence,
33390
+ state: "running"
33391
+ } : null;
33339
33392
  matches = (cancellation) => cancellation.commandId === this.command.commandId && cancellation.sessionId === this.command.sessionId;
33340
33393
  requestCancellation = () => {
33341
33394
  if (this.#cancellationRequested) {
@@ -33859,7 +33912,7 @@ var readCodexHistory = async (agent, cwd, nativeSessionId, signal) => await read
33859
33912
  var readCodexFullHistory = async (agent, cwd, nativeSessionId, signal) => await readCodexHistoryWithOptions(agent, cwd, nativeSessionId, signal, { detail: "rich" });
33860
33913
 
33861
33914
  // src/native-sessions/service.ts
33862
- import { randomUUID as randomUUID2 } from "node:crypto";
33915
+ import { randomUUID as randomUUID3 } from "node:crypto";
33863
33916
  import { basename as basename6 } from "node:path";
33864
33917
 
33865
33918
  // src/native-sessions/acp-history.ts
@@ -33951,11 +34004,13 @@ var NativeSessionService = class {
33951
34004
  #directories;
33952
34005
  #sessions;
33953
34006
  #audit;
33954
- constructor(config2, directories, sessions, audit) {
34007
+ #activeTurn;
34008
+ constructor(config2, directories, sessions, audit, activeTurn) {
33955
34009
  this.#config = config2;
33956
34010
  this.#directories = directories;
33957
34011
  this.#sessions = sessions;
33958
34012
  this.#audit = audit;
34013
+ this.#activeTurn = activeTurn;
33959
34014
  }
33960
34015
  execute = async (command, signal) => {
33961
34016
  signal.throwIfAborted();
@@ -33973,6 +34028,18 @@ var NativeSessionService = class {
33973
34028
  sessionId: command.sessionId,
33974
34029
  signal
33975
34030
  };
34031
+ if (command.action === "active-turn") {
34032
+ nativeSessionIdSchema.parse(command.targetSessionId);
34033
+ this.record(command, "active_turn_read");
34034
+ return {
34035
+ action: "active-turn",
34036
+ kind: "native.session.result",
34037
+ requestId: command.requestId,
34038
+ sessionId: command.sessionId,
34039
+ targetSessionId: command.targetSessionId,
34040
+ turn: this.#activeTurn(command)
34041
+ };
34042
+ }
33976
34043
  if (command.action === "linked-history") {
33977
34044
  const nativeSessionId = nativeSessionIdSchema.parse(command.targetSessionId);
33978
34045
  if (this.#sessions.hasPreparedSession(nativeSessionId, options.agent.id, cwd, additionalDirectories) && await this.#sessions.loadLinkedSessionHistory({ ...options, sessionId: nativeSessionId }) === null) {
@@ -34043,7 +34110,7 @@ var NativeSessionService = class {
34043
34110
  if (authorized === null) {
34044
34111
  return null;
34045
34112
  }
34046
- const entryId = randomUUID2();
34113
+ const entryId = randomUUID3();
34047
34114
  if (this.#entries.size >= 5e3) {
34048
34115
  this.#entries.clear();
34049
34116
  }
@@ -34098,7 +34165,7 @@ var NativeSessionService = class {
34098
34165
  "invalid_native_session_response"
34099
34166
  );
34100
34167
  }
34101
- nextCursor = randomUUID2();
34168
+ nextCursor = randomUUID3();
34102
34169
  if (this.#cursors.size >= 500) {
34103
34170
  this.#cursors.clear();
34104
34171
  }
@@ -34717,7 +34784,7 @@ var RelayConnectionDiagnostics = class {
34717
34784
  };
34718
34785
 
34719
34786
  // src/relay-connection/liveness.ts
34720
- import { randomUUID as randomUUID3 } from "node:crypto";
34787
+ import { randomUUID as randomUUID4 } from "node:crypto";
34721
34788
  var HEARTBEAT_ACK_TIMEOUT_MILLISECONDS = 1e4;
34722
34789
  var HEARTBEAT_INTERVAL_MILLISECONDS = 2e4;
34723
34790
  var RelayLivenessState = class {
@@ -34806,7 +34873,7 @@ var RelayConnectionLiveness = class {
34806
34873
  }
34807
34874
  throw new Error("Heartbeat was scheduled in an invalid state");
34808
34875
  }
34809
- const heartbeatId = randomUUID3();
34876
+ const heartbeatId = randomUUID4();
34810
34877
  this.#state = new AwaitingHeartbeatAckState(
34811
34878
  heartbeatId,
34812
34879
  this.#timer.schedule(this.#handleTimeout, HEARTBEAT_ACK_TIMEOUT_MILLISECONDS)
@@ -35654,7 +35721,7 @@ async function installDetectedAgentIntegrations(config2, installations, signal)
35654
35721
  {
35655
35722
  agentId: agent.id,
35656
35723
  kind: AGENT_INSTALL_REQUEST_KIND,
35657
- requestId: `automatic-integration-${randomUUID4()}`
35724
+ requestId: `automatic-integration-${randomUUID5()}`
35658
35725
  },
35659
35726
  signal
35660
35727
  );
@@ -35782,12 +35849,13 @@ async function runRelayConnection(config2, directories, audit, sessions, install
35782
35849
  const turn = new ActiveDaemonTurn(command, receipt.attemptId);
35783
35850
  activeTurns.set(command.commandId, turn);
35784
35851
  const activateAttempt = () => {
35852
+ turn.accept();
35785
35853
  if (trackActiveAttempt) {
35786
35854
  activeAttemptIds.set(command.sessionId, receipt.attemptId);
35787
35855
  }
35788
35856
  };
35789
35857
  try {
35790
- await execute(receipt.attemptId, activateAttempt, turn.signal);
35858
+ await execute(receipt.attemptId, activateAttempt, turn.signal, turn);
35791
35859
  } finally {
35792
35860
  activeTurns.delete(command.commandId);
35793
35861
  if (activeAttemptIds.get(command.sessionId) === receipt.attemptId) {
@@ -35877,7 +35945,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
35877
35945
  delivery,
35878
35946
  command,
35879
35947
  command.disposition !== SessionPromptDisposition.Steer,
35880
- (attemptId, activateAttempt, executionSignal) => executePrompt(
35948
+ (attemptId, activateAttempt, executionSignal, turn) => executePrompt(
35881
35949
  outbox,
35882
35950
  publisher,
35883
35951
  command,
@@ -35888,7 +35956,8 @@ async function runRelayConnection(config2, directories, audit, sessions, install
35888
35956
  attemptId,
35889
35957
  activateAttempt,
35890
35958
  timer,
35891
- executionSignal
35959
+ executionSignal,
35960
+ turn.recordText
35892
35961
  )
35893
35962
  );
35894
35963
  return;
@@ -36317,7 +36386,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
36317
36386
  const previous = [...nativeRequests.values()].filter(
36318
36387
  (request) => request.agentId === command2.agentId
36319
36388
  );
36320
- if (nativeRequests.has(command2.requestId) || nativeRequests.size >= 4 || command2.action !== "linked-history" && previous.some((request) => !request.controller.signal.aborted)) {
36389
+ if (nativeRequests.has(command2.requestId) || nativeRequests.size >= 4 || command2.action !== "linked-history" && command2.action !== "active-turn" && previous.some((request) => !request.controller.signal.aborted)) {
36321
36390
  reportOperationFailure(
36322
36391
  socket,
36323
36392
  command2.requestId,
@@ -36345,7 +36414,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
36345
36414
  const completion = (async () => {
36346
36415
  try {
36347
36416
  operationSignal.throwIfAborted();
36348
- if (previous.length > 0) {
36417
+ if (previous.length > 0 && command2.action !== "active-turn") {
36349
36418
  await new Promise((resolve9, reject2) => {
36350
36419
  const cancel = () => reject2(operationSignal.reason);
36351
36420
  operationSignal.addEventListener("abort", cancel, {
@@ -36639,12 +36708,14 @@ async function runRelayConnection(config2, directories, audit, sessions, install
36639
36708
  sessions,
36640
36709
  receipt.attemptId,
36641
36710
  () => {
36711
+ turn.accept();
36642
36712
  if (command.disposition !== SessionPromptDisposition.Steer) {
36643
36713
  activeAttemptIds.set(command.sessionId, receipt.attemptId);
36644
36714
  }
36645
36715
  },
36646
36716
  timer,
36647
- turn.signal
36717
+ turn.signal,
36718
+ turn.recordText
36648
36719
  ).catch((error62) => {
36649
36720
  console.error("Mobius daemon turn failed", error62);
36650
36721
  }).finally(() => {
@@ -36764,7 +36835,14 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
36764
36835
  config2.relayUrl,
36765
36836
  new DaemonDiagnosticLog(stateDirectory)
36766
36837
  );
36767
- const nativeSessions = new NativeSessionService(config2, directories, sessions, audit);
36838
+ const nativeSessions = new NativeSessionService(config2, directories, sessions, audit, (request) => {
36839
+ const turn = [...activeTurns.values()].find(
36840
+ (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(
36841
+ (directoryId2, index) => directoryId2 === request.additionalDirectoryIds[index]
36842
+ )
36843
+ );
36844
+ return turn?.snapshot() ?? null;
36845
+ });
36768
36846
  const installations = new AgentInstallationManager(
36769
36847
  specifications,
36770
36848
  installationExecutor,
@@ -36909,7 +36987,7 @@ import { basename as basename7, resolve as resolve6 } from "node:path";
36909
36987
  import { fetch as fetch5 } from "undici";
36910
36988
 
36911
36989
  // src/storage/runtime-installation-store.ts
36912
- import { createHash as createHash5, randomUUID as randomUUID5 } from "node:crypto";
36990
+ import { createHash as createHash5, randomUUID as randomUUID6 } from "node:crypto";
36913
36991
  import { mkdir as mkdir4, open as open5, readdir as readdir3, rename as rename3, unlink, writeFile as writeFile3 } from "node:fs/promises";
36914
36992
  import { dirname as dirname4, join as join17, resolve as resolve5 } from "node:path";
36915
36993
  var APPLICATION_ID_PATTERN = /^[a-z][a-z0-9]*(?:[.-][a-z0-9]+){1,31}$/;
@@ -37040,10 +37118,10 @@ function parseRelayOrigin(value) {
37040
37118
  return origin;
37041
37119
  }
37042
37120
  function connectionId() {
37043
- return `mcn_${randomUUID5().replaceAll("-", "")}`;
37121
+ return `mcn_${randomUUID6().replaceAll("-", "")}`;
37044
37122
  }
37045
37123
  function installationId() {
37046
- return `min_${randomUUID5().replaceAll("-", "")}`;
37124
+ return `min_${randomUUID6().replaceAll("-", "")}`;
37047
37125
  }
37048
37126
  function channelIndexFileName(channelId) {
37049
37127
  return `mci_${createHash5("sha256").update(channelId).digest("hex")}.json`;
@@ -37155,7 +37233,7 @@ async function readJsonFile(path2, signal, missingCode) {
37155
37233
  async function writeJsonAtomically(path2, value, signal) {
37156
37234
  signal.throwIfAborted();
37157
37235
  const directory = dirname4(path2);
37158
- const temporaryPath = join17(directory, `.${randomUUID5()}.tmp`);
37236
+ const temporaryPath = join17(directory, `.${randomUUID6()}.tmp`);
37159
37237
  try {
37160
37238
  await mkdir4(directory, { mode: 448, recursive: true });
37161
37239
  signal.throwIfAborted();