@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/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.101",
3384
+ version: "0.0.103",
3385
3385
  description: "Mobius CLI for pairing and running local AI agent services.",
3386
3386
  type: "module",
3387
3387
  bin: {
@@ -28894,12 +28894,18 @@ function decodeSessionStartedEvent(encoded) {
28894
28894
  }
28895
28895
  function decodeAgentMessageDeltaEvent(encoded) {
28896
28896
  const value = parseJson2(encoded);
28897
- assertExactKeys(value, ["commandId", "kind", "messageId", "sessionId", "text"]);
28897
+ assertExactKeys(value, ["commandId", "epoch", "kind", "messageId", "sequence", "sessionId", "text"]);
28898
28898
  assertKind(value, AGENT_MESSAGE_DELTA_KIND);
28899
+ const sequence = readSequence(value, "sequence");
28900
+ if (sequence === 0) {
28901
+ throw new ProtocolMessageError("Invalid live sequence");
28902
+ }
28899
28903
  return {
28900
28904
  commandId: readIdentifier(value, "commandId"),
28905
+ epoch: readIdentifier(value, "epoch"),
28901
28906
  kind: AGENT_MESSAGE_DELTA_KIND,
28902
28907
  messageId: value["messageId"] === void 0 ? "" : readText(value, "messageId", 255),
28908
+ sequence,
28903
28909
  sessionId: readIdentifier(value, "sessionId"),
28904
28910
  text: readString(value, "text", MAX_EVENT_TEXT_LENGTH)
28905
28911
  };
@@ -29141,6 +29147,7 @@ var nativeSessionTurnForkCommandSchema = external_exports.strictObject({
29141
29147
  var nativeSessionRequestSchema = external_exports.discriminatedUnion("action", [
29142
29148
  external_exports.strictObject({ ...identity, action: external_exports.literal("create") }).readonly(),
29143
29149
  external_exports.strictObject({ ...identity, action: external_exports.literal("linked-history"), targetSessionId: identifier }).readonly(),
29150
+ external_exports.strictObject({ ...identity, action: external_exports.literal("active-turn"), targetSessionId: identifier }).readonly(),
29144
29151
  external_exports.strictObject({ ...identity, action: external_exports.literal("preview"), entryId: identifier }).readonly(),
29145
29152
  external_exports.strictObject({ ...identity, action: external_exports.literal("history"), entryId: identifier }).readonly(),
29146
29153
  external_exports.strictObject({ ...identity, action: external_exports.literal("find"), nativeSessionId: identifier }).readonly(),
@@ -29164,6 +29171,7 @@ var nativeSessionRequestSchema = external_exports.discriminatedUnion("action", [
29164
29171
  var nativeSessionCommandSchema = external_exports.discriminatedUnion("action", [
29165
29172
  external_exports.strictObject({ ...identity, action: external_exports.literal("create") }).readonly(),
29166
29173
  external_exports.strictObject({ ...identity, action: external_exports.literal("linked-history"), targetSessionId: identifier }).readonly(),
29174
+ external_exports.strictObject({ ...identity, action: external_exports.literal("active-turn"), targetSessionId: identifier }).readonly(),
29167
29175
  external_exports.strictObject({ ...identity, action: external_exports.literal("preview"), entryId: identifier }).readonly(),
29168
29176
  external_exports.strictObject({ ...identity, action: external_exports.literal("history"), entryId: identifier }).readonly(),
29169
29177
  external_exports.strictObject({ ...identity, action: external_exports.literal("find"), nativeSessionId: identifier }).readonly(),
@@ -29211,6 +29219,20 @@ var nativeSessionResultSchema = external_exports.discriminatedUnion("action", [
29211
29219
  targetSessionId: identifier,
29212
29220
  history: sessionHistorySchema
29213
29221
  }).readonly(),
29222
+ external_exports.strictObject({
29223
+ ...resultEnvelope,
29224
+ action: external_exports.literal("active-turn"),
29225
+ targetSessionId: identifier,
29226
+ turn: external_exports.strictObject({
29227
+ commandId: identifier,
29228
+ prompt: external_exports.string().max(1e5),
29229
+ text: external_exports.string().max(1e5),
29230
+ truncated: external_exports.boolean(),
29231
+ epoch: identifier,
29232
+ sequence: external_exports.number().int().nonnegative(),
29233
+ state: external_exports.literal("running")
29234
+ }).readonly().nullable()
29235
+ }).readonly(),
29214
29236
  external_exports.strictObject({
29215
29237
  ...resultEnvelope,
29216
29238
  action: external_exports.literal("unlinked-history"),
@@ -30611,7 +30633,7 @@ var AuditStore = class {
30611
30633
  };
30612
30634
 
30613
30635
  // src/run-daemon.ts
30614
- import { randomUUID as randomUUID5 } from "node:crypto";
30636
+ import { randomUUID as randomUUID6 } from "node:crypto";
30615
30637
  import { styleText } from "node:util";
30616
30638
  import { WebSocket as WebSocket5 } from "undici";
30617
30639
 
@@ -37316,7 +37338,7 @@ async function executeSessionConfigure(publisher, socket, command, config2, dire
37316
37338
  reportOperationFailure(socket, command.requestId, command.sessionId, error62);
37317
37339
  }
37318
37340
  }
37319
- async function executePrompt(outbox, publisher, command, config2, directories, audit, sessions, attemptId, activateAttempt, timer, signal) {
37341
+ async function executePrompt(outbox, publisher, command, config2, directories, audit, sessions, attemptId, activateAttempt, timer, signal, recordLiveText) {
37320
37342
  const activities = new CoalescingDaemonActivityPublisher(timer, (activity2) => {
37321
37343
  publisher.recordAttempt(command.sessionId, daemonActivity(command, activity2), attemptId);
37322
37344
  });
@@ -37343,12 +37365,15 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
37343
37365
  const text = new CoalescingTextPublisher(
37344
37366
  timer,
37345
37367
  (messageId, delta) => {
37368
+ const stream = recordLiveText(delta);
37346
37369
  publisher.recordAttempt(
37347
37370
  command.sessionId,
37348
37371
  {
37349
37372
  commandId: command.commandId,
37373
+ epoch: stream.epoch,
37350
37374
  kind: AGENT_MESSAGE_DELTA_KIND,
37351
37375
  messageId,
37376
+ sequence: stream.sequence,
37352
37377
  sessionId: command.sessionId,
37353
37378
  text: delta
37354
37379
  },
@@ -37635,14 +37660,21 @@ var DaemonInstallationObserver = class {
37635
37660
  };
37636
37661
 
37637
37662
  // src/daemon-turn-reconciliation.ts
37663
+ import { randomUUID as randomUUID3 } from "node:crypto";
37638
37664
  import { fetch as fetch5 } from "undici";
37639
37665
  var ACTIVE_TURN_RECONCILIATION_TIMEOUT_MILLISECONDS = 2e4;
37666
+ var ACTIVE_TURN_TEXT_LIMIT = 1e5;
37640
37667
  var ActiveDaemonTurn = class {
37641
37668
  attemptId;
37642
37669
  command;
37643
37670
  #controller;
37644
37671
  #finished = Promise.withResolvers();
37645
37672
  #cancellationRequested = false;
37673
+ #accepted = false;
37674
+ #text = "";
37675
+ #truncated = false;
37676
+ #sequence = 0;
37677
+ #epoch = randomUUID3();
37646
37678
  constructor(command, attemptId) {
37647
37679
  this.attemptId = attemptId;
37648
37680
  this.command = command;
@@ -37652,6 +37684,27 @@ var ActiveDaemonTurn = class {
37652
37684
  this.#controller.abort();
37653
37685
  };
37654
37686
  finish = () => this.#finished.resolve();
37687
+ accept = () => {
37688
+ this.#accepted = true;
37689
+ };
37690
+ recordText = (delta) => {
37691
+ this.#sequence += 1;
37692
+ this.#text += delta;
37693
+ if (this.#text.length > ACTIVE_TURN_TEXT_LIMIT) {
37694
+ this.#text = this.#text.slice(-ACTIVE_TURN_TEXT_LIMIT);
37695
+ this.#truncated = true;
37696
+ }
37697
+ return { epoch: this.#epoch, sequence: this.#sequence };
37698
+ };
37699
+ snapshot = () => this.#accepted ? {
37700
+ commandId: this.command.commandId,
37701
+ prompt: this.command.prompt,
37702
+ text: this.#text,
37703
+ truncated: this.#truncated,
37704
+ epoch: this.#epoch,
37705
+ sequence: this.#sequence,
37706
+ state: "running"
37707
+ } : null;
37655
37708
  matches = (cancellation) => cancellation.commandId === this.command.commandId && cancellation.sessionId === this.command.sessionId;
37656
37709
  requestCancellation = () => {
37657
37710
  if (this.#cancellationRequested) {
@@ -38175,7 +38228,7 @@ var readCodexHistory = async (agent, cwd, nativeSessionId, signal) => await read
38175
38228
  var readCodexFullHistory = async (agent, cwd, nativeSessionId, signal) => await readCodexHistoryWithOptions(agent, cwd, nativeSessionId, signal, { detail: "rich" });
38176
38229
 
38177
38230
  // src/native-sessions/service.ts
38178
- import { randomUUID as randomUUID3 } from "node:crypto";
38231
+ import { randomUUID as randomUUID4 } from "node:crypto";
38179
38232
  import { basename as basename7 } from "node:path";
38180
38233
 
38181
38234
  // src/native-sessions/acp-history.ts
@@ -38267,11 +38320,13 @@ var NativeSessionService = class {
38267
38320
  #directories;
38268
38321
  #sessions;
38269
38322
  #audit;
38270
- constructor(config2, directories, sessions, audit) {
38323
+ #activeTurn;
38324
+ constructor(config2, directories, sessions, audit, activeTurn) {
38271
38325
  this.#config = config2;
38272
38326
  this.#directories = directories;
38273
38327
  this.#sessions = sessions;
38274
38328
  this.#audit = audit;
38329
+ this.#activeTurn = activeTurn;
38275
38330
  }
38276
38331
  execute = async (command, signal) => {
38277
38332
  signal.throwIfAborted();
@@ -38289,6 +38344,18 @@ var NativeSessionService = class {
38289
38344
  sessionId: command.sessionId,
38290
38345
  signal
38291
38346
  };
38347
+ if (command.action === "active-turn") {
38348
+ nativeSessionIdSchema.parse(command.targetSessionId);
38349
+ this.record(command, "active_turn_read");
38350
+ return {
38351
+ action: "active-turn",
38352
+ kind: "native.session.result",
38353
+ requestId: command.requestId,
38354
+ sessionId: command.sessionId,
38355
+ targetSessionId: command.targetSessionId,
38356
+ turn: this.#activeTurn(command)
38357
+ };
38358
+ }
38292
38359
  if (command.action === "linked-history") {
38293
38360
  const nativeSessionId = nativeSessionIdSchema.parse(command.targetSessionId);
38294
38361
  if (this.#sessions.hasPreparedSession(nativeSessionId, options.agent.id, cwd, additionalDirectories) && await this.#sessions.loadLinkedSessionHistory({ ...options, sessionId: nativeSessionId }) === null) {
@@ -38359,7 +38426,7 @@ var NativeSessionService = class {
38359
38426
  if (authorized === null) {
38360
38427
  return null;
38361
38428
  }
38362
- const entryId = randomUUID3();
38429
+ const entryId = randomUUID4();
38363
38430
  if (this.#entries.size >= 5e3) {
38364
38431
  this.#entries.clear();
38365
38432
  }
@@ -38414,7 +38481,7 @@ var NativeSessionService = class {
38414
38481
  "invalid_native_session_response"
38415
38482
  );
38416
38483
  }
38417
- nextCursor = randomUUID3();
38484
+ nextCursor = randomUUID4();
38418
38485
  if (this.#cursors.size >= 500) {
38419
38486
  this.#cursors.clear();
38420
38487
  }
@@ -39033,7 +39100,7 @@ var RelayConnectionDiagnostics = class {
39033
39100
  };
39034
39101
 
39035
39102
  // src/relay-connection/liveness.ts
39036
- import { randomUUID as randomUUID4 } from "node:crypto";
39103
+ import { randomUUID as randomUUID5 } from "node:crypto";
39037
39104
  var HEARTBEAT_ACK_TIMEOUT_MILLISECONDS = 1e4;
39038
39105
  var HEARTBEAT_INTERVAL_MILLISECONDS = 2e4;
39039
39106
  var RelayLivenessState = class {
@@ -39122,7 +39189,7 @@ var RelayConnectionLiveness = class {
39122
39189
  }
39123
39190
  throw new Error("Heartbeat was scheduled in an invalid state");
39124
39191
  }
39125
- const heartbeatId = randomUUID4();
39192
+ const heartbeatId = randomUUID5();
39126
39193
  this.#state = new AwaitingHeartbeatAckState(
39127
39194
  heartbeatId,
39128
39195
  this.#timer.schedule(this.#handleTimeout, HEARTBEAT_ACK_TIMEOUT_MILLISECONDS)
@@ -39970,7 +40037,7 @@ async function installDetectedAgentIntegrations(config2, installations, signal)
39970
40037
  {
39971
40038
  agentId: agent.id,
39972
40039
  kind: AGENT_INSTALL_REQUEST_KIND,
39973
- requestId: `automatic-integration-${randomUUID5()}`
40040
+ requestId: `automatic-integration-${randomUUID6()}`
39974
40041
  },
39975
40042
  signal
39976
40043
  );
@@ -40098,12 +40165,13 @@ async function runRelayConnection(config2, directories, audit, sessions, install
40098
40165
  const turn = new ActiveDaemonTurn(command, receipt.attemptId);
40099
40166
  activeTurns.set(command.commandId, turn);
40100
40167
  const activateAttempt = () => {
40168
+ turn.accept();
40101
40169
  if (trackActiveAttempt) {
40102
40170
  activeAttemptIds.set(command.sessionId, receipt.attemptId);
40103
40171
  }
40104
40172
  };
40105
40173
  try {
40106
- await execute(receipt.attemptId, activateAttempt, turn.signal);
40174
+ await execute(receipt.attemptId, activateAttempt, turn.signal, turn);
40107
40175
  } finally {
40108
40176
  activeTurns.delete(command.commandId);
40109
40177
  if (activeAttemptIds.get(command.sessionId) === receipt.attemptId) {
@@ -40193,7 +40261,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
40193
40261
  delivery,
40194
40262
  command,
40195
40263
  command.disposition !== SessionPromptDisposition.Steer,
40196
- (attemptId, activateAttempt, executionSignal) => executePrompt(
40264
+ (attemptId, activateAttempt, executionSignal, turn) => executePrompt(
40197
40265
  outbox,
40198
40266
  publisher,
40199
40267
  command,
@@ -40204,7 +40272,8 @@ async function runRelayConnection(config2, directories, audit, sessions, install
40204
40272
  attemptId,
40205
40273
  activateAttempt,
40206
40274
  timer,
40207
- executionSignal
40275
+ executionSignal,
40276
+ turn.recordText
40208
40277
  )
40209
40278
  );
40210
40279
  return;
@@ -40633,7 +40702,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
40633
40702
  const previous = [...nativeRequests.values()].filter(
40634
40703
  (request) => request.agentId === command2.agentId
40635
40704
  );
40636
- if (nativeRequests.has(command2.requestId) || nativeRequests.size >= 4 || command2.action !== "linked-history" && previous.some((request) => !request.controller.signal.aborted)) {
40705
+ if (nativeRequests.has(command2.requestId) || nativeRequests.size >= 4 || command2.action !== "linked-history" && command2.action !== "active-turn" && previous.some((request) => !request.controller.signal.aborted)) {
40637
40706
  reportOperationFailure(
40638
40707
  socket,
40639
40708
  command2.requestId,
@@ -40661,7 +40730,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
40661
40730
  const completion = (async () => {
40662
40731
  try {
40663
40732
  operationSignal.throwIfAborted();
40664
- if (previous.length > 0) {
40733
+ if (previous.length > 0 && command2.action !== "active-turn") {
40665
40734
  await new Promise((resolve9, reject2) => {
40666
40735
  const cancel = () => reject2(operationSignal.reason);
40667
40736
  operationSignal.addEventListener("abort", cancel, {
@@ -40955,12 +41024,14 @@ async function runRelayConnection(config2, directories, audit, sessions, install
40955
41024
  sessions,
40956
41025
  receipt.attemptId,
40957
41026
  () => {
41027
+ turn.accept();
40958
41028
  if (command.disposition !== SessionPromptDisposition.Steer) {
40959
41029
  activeAttemptIds.set(command.sessionId, receipt.attemptId);
40960
41030
  }
40961
41031
  },
40962
41032
  timer,
40963
- turn.signal
41033
+ turn.signal,
41034
+ turn.recordText
40964
41035
  ).catch((error62) => {
40965
41036
  console.error("Mobius daemon turn failed", error62);
40966
41037
  }).finally(() => {
@@ -41080,7 +41151,14 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
41080
41151
  config2.relayUrl,
41081
41152
  new DaemonDiagnosticLog(stateDirectory)
41082
41153
  );
41083
- const nativeSessions = new NativeSessionService(config2, directories, sessions, audit);
41154
+ const nativeSessions = new NativeSessionService(config2, directories, sessions, audit, (request) => {
41155
+ const turn = [...activeTurns.values()].find(
41156
+ (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(
41157
+ (directoryId2, index) => directoryId2 === request.additionalDirectoryIds[index]
41158
+ )
41159
+ );
41160
+ return turn?.snapshot() ?? null;
41161
+ });
41084
41162
  const installations = new AgentInstallationManager(
41085
41163
  specifications,
41086
41164
  installationExecutor,