@moxt-ai/mobius 0.0.72 → 0.0.74

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.
Files changed (52) hide show
  1. package/dist/acp/activity.d.ts +9 -1
  2. package/dist/acp/activity.d.ts.map +1 -1
  3. package/dist/acp/activity.js +51 -13
  4. package/dist/acp/activity.js.map +1 -1
  5. package/dist/acp/codex/agent.d.ts +1 -1
  6. package/dist/acp/codex/agent.d.ts.map +1 -1
  7. package/dist/acp/codex/agent.js +415 -6
  8. package/dist/acp/codex/agent.js.map +1 -1
  9. package/dist/acp/codex/app-server-protocol.d.ts +68 -0
  10. package/dist/acp/codex/app-server-protocol.d.ts.map +1 -1
  11. package/dist/acp/codex/app-server-protocol.js +51 -0
  12. package/dist/acp/codex/app-server-protocol.js.map +1 -1
  13. package/dist/acp/run-prompt.d.ts +2 -1
  14. package/dist/acp/run-prompt.d.ts.map +1 -1
  15. package/dist/acp/run-prompt.js +1 -0
  16. package/dist/acp/run-prompt.js.map +1 -1
  17. package/dist/acp/session-history.d.ts.map +1 -1
  18. package/dist/acp/session-history.js +4 -1
  19. package/dist/acp/session-history.js.map +1 -1
  20. package/dist/acp/session-manager.d.ts +7 -2
  21. package/dist/acp/session-manager.d.ts.map +1 -1
  22. package/dist/acp/session-manager.js +18 -7
  23. package/dist/acp/session-manager.js.map +1 -1
  24. package/dist/cli.js +854 -62
  25. package/dist/cli.js.map +4 -4
  26. package/dist/daemon-diagnostic-log.d.ts +6 -0
  27. package/dist/daemon-diagnostic-log.d.ts.map +1 -0
  28. package/dist/daemon-diagnostic-log.js +48 -0
  29. package/dist/daemon-diagnostic-log.js.map +1 -0
  30. package/dist/index.js +856 -63
  31. package/dist/index.js.map +4 -4
  32. package/dist/native-sessions/service.d.ts.map +1 -1
  33. package/dist/native-sessions/service.js +6 -5
  34. package/dist/native-sessions/service.js.map +1 -1
  35. package/dist/relay-connection/coalescing-narration-publisher.d.ts +31 -0
  36. package/dist/relay-connection/coalescing-narration-publisher.d.ts.map +1 -0
  37. package/dist/relay-connection/coalescing-narration-publisher.js +61 -0
  38. package/dist/relay-connection/coalescing-narration-publisher.js.map +1 -0
  39. package/dist/relay-connection/diagnostics.d.ts +3 -1
  40. package/dist/relay-connection/diagnostics.d.ts.map +1 -1
  41. package/dist/relay-connection/diagnostics.js +16 -1
  42. package/dist/relay-connection/diagnostics.js.map +1 -1
  43. package/dist/relay-connection/session-event-outbox.d.ts +6 -0
  44. package/dist/relay-connection/session-event-outbox.d.ts.map +1 -1
  45. package/dist/relay-connection/session-event-outbox.js +13 -0
  46. package/dist/relay-connection/session-event-outbox.js.map +1 -1
  47. package/dist/run-daemon.d.ts.map +1 -1
  48. package/dist/run-daemon.js +104 -7
  49. package/dist/run-daemon.js.map +1 -1
  50. package/dist/runtime.js +866 -74
  51. package/dist/runtime.js.map +4 -4
  52. package/package.json +1 -1
@@ -1,7 +1,7 @@
1
1
  import { createHash, randomUUID } from "node:crypto";
2
2
  import { basename } from "node:path";
3
3
  import { styleText } from "node:util";
4
- import { AGENT_ACTIVITY_KIND, AGENT_CATALOG_REFRESH_FAILED_KIND, AGENT_CATALOG_REFRESH_KIND, AGENT_CATALOG_REFRESHED_KIND, AGENT_INSTALL_CANCEL_KIND, AGENT_INSTALL_CANCELLED_KIND, AGENT_INSTALL_COMPLETED_KIND, AGENT_INSTALL_FAILED_KIND, AGENT_INSTALL_PROGRESS_KIND, AGENT_INSTALL_REQUEST_KIND, AGENT_INSTALL_STARTED_KIND, AGENT_MESSAGE_DELTA_KIND, AGENT_MODEL_EFFORT_RESOLUTION_COMPLETE, AGENT_MODEL_EFFORT_RESOLUTION_ON_MODEL_SELECTION, AGENT_MODEL_EFFORT_RESOLUTION_UNAVAILABLE, AGENT_SETTINGS_DISCOVER_KIND, AGENT_SETTINGS_DISCOVERED_KIND, AGENT_SETTINGS_DISCOVERY_FAILED_KIND, decodeServiceToDaemonMessage, decodeSessionEventEnvelope, decodeSessionLiveHistoryLoad, encodeDaemonToServiceMessage, encodeRecordedSessionEvent, FILE_FAILED_KIND, FILE_READ_KIND, NATIVE_SESSION_CANCEL_KIND, NATIVE_SESSION_REQUEST_KIND, NATIVE_SESSION_TURN_FORK_KIND, RUNTIME_DELIVERY_COMMITTED_KIND, RUNTIME_DELIVERY_KIND, RUNTIME_DELIVERY_RECEIVED_KIND, RUNTIME_HEARTBEAT_ACK_KIND, RUNTIME_LIVENESS_READY_KIND, SESSION_CANCEL_KIND, SESSION_COMPLETED_KIND, SESSION_CONFIGURE_KIND, SESSION_ELICITATION_RESPOND_KIND, SESSION_EVENT_ACK_KIND, SESSION_EVENT_DEFERRED_KIND, SESSION_EVENT_REJECTED_KIND, SESSION_FAILED_KIND, SESSION_LIVE_HISTORY_LOAD_KIND, SESSION_PERMISSION_RESPOND_KIND, SESSION_PREPARE_KIND, SESSION_PROMPT_KIND, SESSION_STARTED_KIND, SessionPromptDisposition, WORKSPACE_LIST_KIND, } from "@moxt-ai/mobius-protocol";
4
+ import { AGENT_ACTIVITY_KIND, AGENT_ACTIVITY_NARRATION_KIND, AGENT_CATALOG_REFRESH_FAILED_KIND, AGENT_CATALOG_REFRESH_KIND, AGENT_CATALOG_REFRESHED_KIND, AGENT_INSTALL_CANCEL_KIND, AGENT_INSTALL_CANCELLED_KIND, AGENT_INSTALL_COMPLETED_KIND, AGENT_INSTALL_FAILED_KIND, AGENT_INSTALL_PROGRESS_KIND, AGENT_INSTALL_REQUEST_KIND, AGENT_INSTALL_STARTED_KIND, AGENT_MESSAGE_DELTA_KIND, AGENT_MODEL_EFFORT_RESOLUTION_COMPLETE, AGENT_MODEL_EFFORT_RESOLUTION_ON_MODEL_SELECTION, AGENT_MODEL_EFFORT_RESOLUTION_UNAVAILABLE, AGENT_SETTINGS_DISCOVER_KIND, AGENT_SETTINGS_DISCOVERED_KIND, AGENT_SETTINGS_DISCOVERY_FAILED_KIND, decodeServiceToDaemonMessage, decodeSessionEventEnvelope, decodeSessionLiveHistoryLoad, encodeDaemonToServiceMessage, encodeRecordedSessionEvent, FILE_FAILED_KIND, FILE_READ_KIND, NATIVE_SESSION_CANCEL_KIND, NATIVE_SESSION_REQUEST_KIND, NATIVE_SESSION_TURN_FORK_KIND, RUNTIME_DELIVERY_COMMITTED_KIND, RUNTIME_DELIVERY_KIND, RUNTIME_DELIVERY_RECEIVED_KIND, RUNTIME_HEARTBEAT_ACK_KIND, RUNTIME_LIVENESS_READY_KIND, SESSION_CANCEL_KIND, SESSION_COMPLETED_KIND, SESSION_CONFIGURE_KIND, SESSION_ELICITATION_RESPOND_KIND, SESSION_EVENT_ACK_KIND, SESSION_EVENT_DEFERRED_KIND, SESSION_EVENT_REJECTED_KIND, SESSION_FAILED_KIND, SESSION_LIVE_HISTORY_LOAD_KIND, SESSION_PERMISSION_RESPOND_KIND, SESSION_PREPARE_KIND, SESSION_PROMPT_KIND, SESSION_STARTED_KIND, SessionPromptDisposition, WORKSPACE_LIST_KIND, } from "@moxt-ai/mobius-protocol";
5
5
  import { fetch, WebSocket } from "undici";
6
6
  import { AcpConfigurationValueUnavailableError, AcpExecutionError, AcpSessionManager, } from "./acp/session-manager.js";
7
7
  import { SqliteAcpSessionStore } from "./acp/session-store.js";
@@ -15,19 +15,21 @@ import { streamLocalFile } from "./artifacts/local-file-streamer.js";
15
15
  import { LocalAuthorizationError } from "./authorization/local-authorization-error.js";
16
16
  import { WorkspaceDirectoryService } from "./authorization/workspace-directory.js";
17
17
  import { DaemonLocalContext, withDaemonEnvironment } from "./config.js";
18
+ import { DaemonDiagnosticLog } from "./daemon-diagnostic-log.js";
18
19
  import { AccumulatingOperationMetrics } from "./infra/operation-metrics.js";
19
20
  import { readCodexFullHistory } from "./native-sessions/codex-history.js";
20
21
  import { NativeSessionService } from "./native-sessions/service.js";
21
22
  import { environmentProxyDispatcher } from "./network/environment-proxy.js";
22
23
  import { revalidateExecutable } from "./process/executable.js";
23
24
  import { PromptArtifactError, resolvePromptArtifacts } from "./prompt-artifact-resolver.js";
25
+ import { CoalescingNarrationPublisher } from "./relay-connection/coalescing-narration-publisher.js";
24
26
  import { CoalescingTextPublisher } from "./relay-connection/coalescing-text-publisher.js";
25
27
  import { connectRelay } from "./relay-connection/connect.js";
26
28
  import { RelayConnectionDiagnostics } from "./relay-connection/diagnostics.js";
27
29
  import { RelayConnectionLiveness } from "./relay-connection/liveness.js";
28
30
  import { relayHttpEndpoint, runtimeAuthorization } from "./relay-connection/runtime-authentication.js";
29
31
  import { isRuntimeRelayRevocation, RuntimeRelayRevokedError } from "./relay-connection/runtime-revocation.js";
30
- import { RuntimeDeliveryInboxCapacityError, SessionEventOutbox } from "./relay-connection/session-event-outbox.js";
32
+ import { RuntimeDeliveryInboxCapacityError, SessionEventOutbox, SessionEventOutboxCapacityError, } from "./relay-connection/session-event-outbox.js";
31
33
  import { systemDaemonTimer } from "./relay-connection/timer.js";
32
34
  const RELAY_RECONNECT_DELAY_MILLISECONDS = 500;
33
35
  const AGENT_ACTIVITY_COALESCING_MILLISECONDS = 100;
@@ -347,6 +349,20 @@ class ConnectedDaemonSessionEventState extends DaemonSessionEventConnectionState
347
349
  const SESSION_EVENT_REPLAY_WINDOW = 16;
348
350
  const SESSION_EVENT_SOURCE_REPLAY_WINDOW = 4;
349
351
  const SESSION_EVENT_REPLAY_BYTE_LIMIT = 32 * 1024 * 1024;
352
+ /**
353
+ * Events that settle a Turn reserve capacity streaming events cannot consume. A
354
+ * completed narrative activity carries the text that supersedes its increments, so it
355
+ * is the only event that can settle a streamed narration; without the reservation the
356
+ * snapshot could be shed after its increments were, losing the text entirely.
357
+ */
358
+ function reservesSessionEventCapacity(event) {
359
+ if (event.kind === SESSION_COMPLETED_KIND || event.kind === SESSION_FAILED_KIND) {
360
+ return true;
361
+ }
362
+ return (event.kind === AGENT_ACTIVITY_KIND &&
363
+ (event.activityType === "progress" || event.activityType === "reasoning") &&
364
+ (event.status === "completed" || event.status === "failed"));
365
+ }
350
366
  class InFlightSessionEvent {
351
367
  byteLength;
352
368
  sourceKey;
@@ -364,6 +380,7 @@ class DaemonSessionEventPublisher {
364
380
  #outbox;
365
381
  #inFlightEvents = new Map();
366
382
  #pausedSources = new Map();
383
+ #shedEventKinds = new Set();
367
384
  #timer;
368
385
  #inFlightBytes = 0;
369
386
  #connection = new DisconnectedDaemonSessionEventState();
@@ -385,18 +402,67 @@ class DaemonSessionEventPublisher {
385
402
  };
386
403
  recordAttempt = (sessionId, event, attemptId) => {
387
404
  const encoded = encodeRecordedSessionEvent(event);
388
- if (event.kind === SESSION_COMPLETED_KIND || event.kind === SESSION_FAILED_KIND) {
389
- this.#outbox.enqueueCritical(sessionId, encoded, attemptId);
405
+ if (reservesSessionEventCapacity(event)) {
406
+ this.#enqueueReserved(sessionId, encoded, attemptId, event.kind);
390
407
  }
391
408
  else {
392
- this.#outbox.enqueue(sessionId, encoded, attemptId);
409
+ this.#enqueueStandard(sessionId, encoded, attemptId, event.kind);
393
410
  }
394
411
  this.#publishNextBatch();
395
412
  };
396
413
  recordRuntime = (sessionId, event) => {
397
- this.#outbox.enqueue(sessionId, encodeRecordedSessionEvent(event));
414
+ this.#enqueueStandard(sessionId, encodeRecordedSessionEvent(event), "", event.kind);
398
415
  this.#publishNextBatch();
399
416
  };
417
+ /**
418
+ * Enqueue a standard event, shedding it instead of ending the daemon when the
419
+ * durable outbox is full.
420
+ *
421
+ * A capacity error used to escape the coalescing timer that publishes activities,
422
+ * so the process exited and every restart died on the same retained backlog. A full
423
+ * outbox is a recoverable runtime condition, not a fatal one: narration increments are
424
+ * superseded by the completed snapshot, so they are shed first, and any other streaming
425
+ * event is shed only at the wall rather than terminating the daemon.
426
+ */
427
+ #enqueueStandard = (sessionId, encoded, attemptId, kind) => {
428
+ if (kind === AGENT_ACTIVITY_NARRATION_KIND && this.#outbox.standardCapacityRemaining() <= 0) {
429
+ this.#reportShedEvent(kind);
430
+ return;
431
+ }
432
+ try {
433
+ this.#outbox.enqueue(sessionId, encoded, attemptId);
434
+ }
435
+ catch (error) {
436
+ if (!(error instanceof SessionEventOutboxCapacityError)) {
437
+ throw error;
438
+ }
439
+ this.#reportShedEvent(kind);
440
+ }
441
+ };
442
+ /**
443
+ * Enqueue on the reserved budget, degrading to a reported drop instead of raising.
444
+ * Streaming events are shed before this budget is reached, so a Turn's terminal
445
+ * events and the completed snapshot that carries its narration still land; a drop
446
+ * here is the last resort for a backlog no acknowledgement can drain.
447
+ */
448
+ #enqueueReserved = (sessionId, encoded, attemptId, kind) => {
449
+ try {
450
+ this.#outbox.enqueueCritical(sessionId, encoded, attemptId);
451
+ }
452
+ catch (error) {
453
+ if (!(error instanceof SessionEventOutboxCapacityError)) {
454
+ throw error;
455
+ }
456
+ this.#reportShedEvent(kind);
457
+ }
458
+ };
459
+ #reportShedEvent = (kind) => {
460
+ if (this.#shedEventKinds.has(kind)) {
461
+ return;
462
+ }
463
+ this.#shedEventKinds.add(kind);
464
+ console.warn(`Mobius daemon is dropping durable "${kind}" events because the Session event outbox is full`);
465
+ };
400
466
  acknowledge = (acknowledgement) => {
401
467
  if (!this.#outbox.acknowledge(acknowledgement)) {
402
468
  return;
@@ -1089,6 +1155,17 @@ async function executePrompt(outbox, publisher, command, config, directories, au
1089
1155
  const activities = new CoalescingDaemonActivityPublisher(timer, (activity) => {
1090
1156
  publisher.recordAttempt(command.sessionId, daemonActivity(command, activity), attemptId);
1091
1157
  });
1158
+ const narration = new CoalescingNarrationPublisher(timer, (increment) => {
1159
+ publisher.recordAttempt(command.sessionId, {
1160
+ activityId: increment.activityId,
1161
+ activityType: increment.activityType,
1162
+ commandId: command.commandId,
1163
+ kind: AGENT_ACTIVITY_NARRATION_KIND,
1164
+ sequence: increment.sequence,
1165
+ sessionId: command.sessionId,
1166
+ text: increment.text,
1167
+ }, attemptId);
1168
+ }, AGENT_ACTIVITY_COALESCING_MILLISECONDS, AGENT_TEXT_MAXIMUM_LENGTH);
1092
1169
  const text = new CoalescingTextPublisher(timer, (messageId, delta) => {
1093
1170
  publisher.recordAttempt(command.sessionId, {
1094
1171
  commandId: command.commandId,
@@ -1168,6 +1245,10 @@ async function executePrompt(outbox, publisher, command, config, directories, au
1168
1245
  disposition: command.disposition,
1169
1246
  images: attachments.images,
1170
1247
  onActivity: activities.record,
1248
+ onNarration: (increment) => {
1249
+ narration.record(increment);
1250
+ return Promise.resolve();
1251
+ },
1171
1252
  onText: (delta, messageId) => {
1172
1253
  text.record(messageId, delta);
1173
1254
  return Promise.resolve();
@@ -1181,6 +1262,7 @@ async function executePrompt(outbox, publisher, command, config, directories, au
1181
1262
  stopReason = result.stopReason;
1182
1263
  }
1183
1264
  text.flush();
1265
+ narration.flush();
1184
1266
  activities.flush();
1185
1267
  publisher.recordAttempt(command.sessionId, {
1186
1268
  commandId: command.commandId,
@@ -1197,6 +1279,7 @@ async function executePrompt(outbox, publisher, command, config, directories, au
1197
1279
  }
1198
1280
  catch (error) {
1199
1281
  text.flush();
1282
+ narration.flush();
1200
1283
  activities.flush();
1201
1284
  audit.record({
1202
1285
  commandId: command.commandId,
@@ -1812,6 +1895,7 @@ async function runRelayConnection(config, directories, audit, sessions, installa
1812
1895
  event: "agent_settings_model_unsupported",
1813
1896
  sessionId: `agent-settings:${command.agentId}`,
1814
1897
  });
1898
+ diagnostics.daemonDiagnostic("agent_settings_model_unsupported", command.requestId, details);
1815
1899
  process.stderr.write(`Mobius daemon diagnostic ${JSON.stringify({ event: "agent_settings_model_unsupported", requestId: command.requestId, ...details })}\n`);
1816
1900
  }
1817
1901
  audit.record({
@@ -1839,6 +1923,7 @@ async function runRelayConnection(config, directories, audit, sessions, installa
1839
1923
  event: "agent_settings_discovery_failed",
1840
1924
  sessionId: `agent-settings:${command.agentId}`,
1841
1925
  });
1926
+ diagnostics.daemonDiagnostic("agent_settings_discovery_failed", command.requestId, details, failure);
1842
1927
  if (failure instanceof AcpConfigurationValueUnavailableError) {
1843
1928
  process.stderr.write(`Mobius daemon diagnostic ${JSON.stringify({ event: "agent_settings_discovery_failed", requestId: command.requestId, ...details })}\n`);
1844
1929
  }
@@ -1905,6 +1990,7 @@ async function runRelayConnection(config, directories, audit, sessions, installa
1905
1990
  event: "agent_catalog_refresh_failed",
1906
1991
  sessionId: "agent-catalog",
1907
1992
  });
1993
+ diagnostics.daemonDiagnostic("agent_catalog_refresh_failed", command.requestId, { code: operationErrorCode(failure) }, failure);
1908
1994
  if (socket.readyState === WebSocket.OPEN) {
1909
1995
  send(socket, {
1910
1996
  code: operationErrorCode(failure),
@@ -1969,6 +2055,12 @@ async function runRelayConnection(config, directories, audit, sessions, installa
1969
2055
  event: "native_session_operation_failed",
1970
2056
  details: { code: operationErrorCode(failure) },
1971
2057
  });
2058
+ diagnostics.daemonDiagnostic("native_session_operation_failed", command.requestId, {
2059
+ action: command.action,
2060
+ agentId: command.agentId,
2061
+ code: operationErrorCode(failure),
2062
+ sessionId: command.sessionId,
2063
+ }, failure);
1972
2064
  reportOperationFailure(socket, command.requestId, command.sessionId, failure);
1973
2065
  }
1974
2066
  finally {
@@ -2029,6 +2121,11 @@ async function runRelayConnection(config, directories, audit, sessions, installa
2029
2121
  event: "native_session_turn_fork_failed",
2030
2122
  sessionId: command.sessionId,
2031
2123
  });
2124
+ diagnostics.daemonDiagnostic("native_session_turn_fork_failed", command.requestId, {
2125
+ agentId: command.agentId,
2126
+ code: operationErrorCode(failure),
2127
+ sessionId: command.sessionId,
2128
+ }, failure);
2032
2129
  reportOperationFailure(socket, command.requestId, command.sessionId, failure);
2033
2130
  }
2034
2131
  finally {
@@ -2262,7 +2359,7 @@ export async function runDaemon(config, audit, signal, timer = systemDaemonTimer
2262
2359
  });
2263
2360
  const directories = new WorkspaceDirectoryService(config.bindingId, config.defaultWorkspace);
2264
2361
  const installationObserver = new DaemonInstallationObserver();
2265
- const diagnostics = new RelayConnectionDiagnostics(audit, config.channelId, config.relayUrl);
2362
+ const diagnostics = new RelayConnectionDiagnostics(audit, config.channelId, config.relayUrl, new DaemonDiagnosticLog(stateDirectory));
2266
2363
  const nativeSessions = new NativeSessionService(config, directories, sessions, audit);
2267
2364
  const installations = new AgentInstallationManager(specifications, installationExecutor, installationObserver, installationAudit);
2268
2365
  let connectionEpoch = 0;