@moxt-ai/mobius 0.0.71 → 0.0.73

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 (92) hide show
  1. package/dist/acp/acp-error.d.ts +17 -0
  2. package/dist/acp/acp-error.d.ts.map +1 -0
  3. package/dist/acp/acp-error.js +28 -0
  4. package/dist/acp/acp-error.js.map +1 -0
  5. package/dist/acp/codex/agent.d.ts +26 -0
  6. package/dist/acp/codex/agent.d.ts.map +1 -0
  7. package/dist/acp/codex/agent.js +706 -0
  8. package/dist/acp/codex/agent.js.map +1 -0
  9. package/dist/acp/codex/app-server-client.d.ts +45 -0
  10. package/dist/acp/codex/app-server-client.d.ts.map +1 -0
  11. package/dist/acp/codex/app-server-client.js +195 -0
  12. package/dist/acp/codex/app-server-client.js.map +1 -0
  13. package/dist/acp/codex/app-server-protocol.d.ts +225 -0
  14. package/dist/acp/codex/app-server-protocol.d.ts.map +1 -0
  15. package/dist/acp/codex/app-server-protocol.js +197 -0
  16. package/dist/acp/codex/app-server-protocol.js.map +1 -0
  17. package/dist/acp/codex/items.d.ts +17 -0
  18. package/dist/acp/codex/items.d.ts.map +1 -0
  19. package/dist/acp/codex/items.js +141 -0
  20. package/dist/acp/codex/items.js.map +1 -0
  21. package/dist/acp/in-process/acp-endpoint.d.ts +33 -0
  22. package/dist/acp/in-process/acp-endpoint.d.ts.map +1 -0
  23. package/dist/acp/in-process/acp-endpoint.js +2 -0
  24. package/dist/acp/in-process/acp-endpoint.js.map +1 -0
  25. package/dist/acp/session-manager.d.ts +5 -16
  26. package/dist/acp/session-manager.d.ts.map +1 -1
  27. package/dist/acp/session-manager.js +63 -38
  28. package/dist/acp/session-manager.js.map +1 -1
  29. package/dist/agent-catalog/acp-readiness-probe.d.ts +2 -2
  30. package/dist/agent-catalog/acp-readiness-probe.d.ts.map +1 -1
  31. package/dist/agent-catalog/acp-readiness-probe.js +55 -0
  32. package/dist/agent-catalog/acp-readiness-probe.js.map +1 -1
  33. package/dist/agent-catalog/agent-diagnostics.d.ts.map +1 -1
  34. package/dist/agent-catalog/agent-diagnostics.js +4 -1
  35. package/dist/agent-catalog/agent-diagnostics.js.map +1 -1
  36. package/dist/agent-catalog/agent-discovery.d.ts +4 -4
  37. package/dist/agent-catalog/agent-discovery.d.ts.map +1 -1
  38. package/dist/agent-catalog/agent-discovery.js.map +1 -1
  39. package/dist/agent-catalog/agent-settings-adapter.d.ts +8 -8
  40. package/dist/agent-catalog/agent-settings-adapter.d.ts.map +1 -1
  41. package/dist/agent-catalog/agent-settings-adapter.js.map +1 -1
  42. package/dist/agent-catalog/agent-specification.d.ts +21 -0
  43. package/dist/agent-catalog/agent-specification.d.ts.map +1 -1
  44. package/dist/agent-catalog/agent-specification.js +25 -0
  45. package/dist/agent-catalog/agent-specification.js.map +1 -1
  46. package/dist/agent-catalog/agents/codex-agent.d.ts +5 -9
  47. package/dist/agent-catalog/agents/codex-agent.d.ts.map +1 -1
  48. package/dist/agent-catalog/agents/codex-agent.js +9 -18
  49. package/dist/agent-catalog/agents/codex-agent.js.map +1 -1
  50. package/dist/agent-catalog/discover-agent.d.ts.map +1 -1
  51. package/dist/agent-catalog/discover-agent.js +11 -6
  52. package/dist/agent-catalog/discover-agent.js.map +1 -1
  53. package/dist/agent-catalog/executable-discovery.d.ts.map +1 -1
  54. package/dist/agent-catalog/executable-discovery.js +2 -2
  55. package/dist/agent-catalog/executable-discovery.js.map +1 -1
  56. package/dist/agent-catalog/local-agent.d.ts +25 -11
  57. package/dist/agent-catalog/local-agent.d.ts.map +1 -1
  58. package/dist/agent-catalog/local-agent.js +32 -12
  59. package/dist/agent-catalog/local-agent.js.map +1 -1
  60. package/dist/agent-installation/fixed-installation-executor.d.ts.map +1 -1
  61. package/dist/agent-installation/fixed-installation-executor.js +3 -1
  62. package/dist/agent-installation/fixed-installation-executor.js.map +1 -1
  63. package/dist/cli.js +8045 -6582
  64. package/dist/cli.js.map +4 -4
  65. package/dist/config.d.ts +5 -4
  66. package/dist/config.d.ts.map +1 -1
  67. package/dist/config.js.map +1 -1
  68. package/dist/daemon-diagnostic-log.d.ts +6 -0
  69. package/dist/daemon-diagnostic-log.d.ts.map +1 -0
  70. package/dist/daemon-diagnostic-log.js +48 -0
  71. package/dist/daemon-diagnostic-log.js.map +1 -0
  72. package/dist/index.js +1630 -167
  73. package/dist/index.js.map +4 -4
  74. package/dist/native-sessions/codex-history.d.ts +3 -3
  75. package/dist/native-sessions/codex-history.d.ts.map +1 -1
  76. package/dist/native-sessions/codex-history.js +1 -1
  77. package/dist/native-sessions/codex-history.js.map +1 -1
  78. package/dist/native-sessions/service.d.ts.map +1 -1
  79. package/dist/native-sessions/service.js +6 -5
  80. package/dist/native-sessions/service.js.map +1 -1
  81. package/dist/pairing/pair-local-machine.d.ts.map +1 -1
  82. package/dist/pairing/pair-local-machine.js.map +1 -1
  83. package/dist/relay-connection/diagnostics.d.ts +3 -1
  84. package/dist/relay-connection/diagnostics.d.ts.map +1 -1
  85. package/dist/relay-connection/diagnostics.js +16 -1
  86. package/dist/relay-connection/diagnostics.js.map +1 -1
  87. package/dist/run-daemon.d.ts.map +1 -1
  88. package/dist/run-daemon.js +17 -2
  89. package/dist/run-daemon.js.map +1 -1
  90. package/dist/runtime.js +5526 -4063
  91. package/dist/runtime.js.map +4 -4
  92. package/package.json +1 -1
@@ -6,6 +6,7 @@ import { readInlineVideo } from "../authorization/local-video.js";
6
6
  import { unmeasuredOperationMetrics } from "../infra/operation-metrics.js";
7
7
  import { embedLocalHistoryImages } from "../native-sessions/history-images.js";
8
8
  import { captureProcessTree, revalidateExecutable, stopProcessTree, } from "../process/executable.js";
9
+ import { AcpConfigurationValueUnavailableError, AcpExecutionError } from "./acp-error.js";
9
10
  import { AcpActivityTracker, imageDisplayContent, isProgressMessage, normalizeContentBlock, } from "./activity.js";
10
11
  import { createAcpClient } from "./create-client.js";
11
12
  import { emitMarkdownChunksWithLocalImages } from "./markdown-images.js";
@@ -21,6 +22,15 @@ const MAX_PRE_SESSION_UPDATES = 100;
21
22
  const MAX_PRE_SESSION_UPDATE_BYTES = 1024 * 1024;
22
23
  const SESSION_CONTROL_COMMAND_ID = "session-control";
23
24
  const SESSION_CONTROL_TIMEOUT_MILLISECONDS = 30_000;
25
+ function nativeHistoryNotRetained() {
26
+ return {
27
+ cause: {
28
+ code: "native_history_not_retained",
29
+ message: "Native message history is not retained in the cloud for this Session.",
30
+ },
31
+ status: "unavailable",
32
+ };
33
+ }
24
34
  export class NullAcpSessionObserver {
25
35
  onCommands = () => Promise.resolve();
26
36
  onConfig = () => Promise.resolve();
@@ -58,28 +68,7 @@ export class AcpAgentSettingsSnapshot {
58
68
  this.configOptions = configOptions;
59
69
  }
60
70
  }
61
- export class AcpExecutionError extends Error {
62
- code;
63
- constructor(message, options = {}, code = "acp_execution_failed") {
64
- super(message, options);
65
- this.code = code;
66
- this.name = "AcpExecutionError";
67
- }
68
- }
69
- export class AcpConfigurationValueUnavailableError extends AcpExecutionError {
70
- configId;
71
- offeredValueCount;
72
- offeredValues;
73
- requestedValue;
74
- constructor(configId, requestedValue, offeredValues) {
75
- super("The requested ACP configuration value is unavailable", {}, "invalid_session_configuration");
76
- this.name = "AcpConfigurationValueUnavailableError";
77
- this.configId = configId.slice(0, 128);
78
- this.requestedValue = requestedValue.slice(0, 128);
79
- this.offeredValueCount = offeredValues.length;
80
- this.offeredValues = Object.freeze(offeredValues.slice(0, 32).map((value) => value.slice(0, 128)));
81
- }
82
- }
71
+ export { AcpConfigurationValueUnavailableError, AcpExecutionError } from "./acp-error.js";
83
72
  class RetryableAcpInitializationError extends AcpExecutionError {
84
73
  constructor(cause) {
85
74
  super("ACP agent initialization failed", { cause });
@@ -538,16 +527,18 @@ class AcpProcessSession {
538
527
  #additionalDirectories;
539
528
  #acceptedUrlElicitations = new Map();
540
529
  #agentId;
541
- #child;
542
530
  #connection;
543
531
  #cwd;
544
532
  #environment;
545
533
  #getObserver;
534
+ #inProcessAgent;
546
535
  #mobiusSessionId;
547
536
  #pendingElicitations = new Map();
548
537
  #pendingPermissions = new Map();
549
538
  #preSessionUpdates = [];
539
+ // The adapter-process topology only. An in-process agent owns the app-server child itself.
550
540
  #processExit;
541
+ #runtimeChild;
551
542
  #metrics;
552
543
  #sessionConfigProtocol;
553
544
  #store;
@@ -582,18 +573,34 @@ class AcpProcessSession {
582
573
  this.#sessionConfigProtocol = sessionConfigProtocolForAgent(agent.id);
583
574
  this.#store = store;
584
575
  this.#verifiedAgentVersion = agent.agentVersion;
585
- this.#child = spawn(agent.adapterPath, [...agent.arguments], {
576
+ if (agent.kind === "in-process-acp") {
577
+ // Mobius hosts the ACP Agent in-process and drives the vendor's own protocol, so there is
578
+ // no adapter process to spawn or supervise here. The endpoint owns its own resources.
579
+ const inProcess = agent.createEndpoint({
580
+ command: agent.command,
581
+ cwd,
582
+ environment: agent.environment,
583
+ });
584
+ this.#inProcessAgent = inProcess;
585
+ this.#runtimeChild = null;
586
+ this.#processExit = new Promise(() => { });
587
+ this.#connection = createAcpClient(this).connect(inProcess.app());
588
+ return;
589
+ }
590
+ this.#inProcessAgent = null;
591
+ const child = spawn(agent.adapterPath, [...agent.arguments], {
586
592
  cwd,
587
593
  detached: process.platform !== "win32",
588
594
  env: { ...process.env, ...agent.environment },
589
595
  shell: false,
590
596
  stdio: ["pipe", "pipe", "pipe"],
591
597
  });
592
- const stdin = this.#child.stdin;
593
- const stdout = this.#child.stdout;
594
- const stderr = this.#child.stderr;
598
+ this.#runtimeChild = child;
599
+ const stdin = child.stdin;
600
+ const stdout = child.stdout;
601
+ const stderr = child.stderr;
595
602
  if (stdin === null || stdout === null || stderr === null) {
596
- this.#child.kill("SIGKILL");
603
+ child.kill("SIGKILL");
597
604
  throw new AcpExecutionError("ACP process streams are unavailable");
598
605
  }
599
606
  stderr.setEncoding("utf8");
@@ -601,8 +608,8 @@ class AcpProcessSession {
601
608
  process.stderr.write(`[${agent.id}-acp] ${chunk}`);
602
609
  });
603
610
  this.#processExit = new Promise((resolve) => {
604
- this.#child.once("error", resolve);
605
- this.#child.once("exit", resolve);
611
+ child.once("error", resolve);
612
+ child.once("exit", resolve);
606
613
  });
607
614
  const stream = ndJsonStream(createWritableAcpStream(stdin), readableWebStream(stdout));
608
615
  this.#connection = createAcpClient(this).connect(stream);
@@ -610,12 +617,15 @@ class AcpProcessSession {
610
617
  static async #start(options, getObserver, store, initialize, metrics) {
611
618
  for (let attempt = 1; attempt <= 2; attempt += 1) {
612
619
  options.signal.throwIfAborted();
613
- const [adapterUnchanged, agentUnchanged] = await metrics.measure("executable-validation", async () => await Promise.all([
614
- revalidateExecutable(options.agent.adapterIdentity),
620
+ const unchanged = await metrics.measure("executable-validation", async () => await Promise.all([
621
+ // Only the adapter topology has an adapter executable to revalidate.
622
+ options.agent.kind === "acp-adapter-process"
623
+ ? revalidateExecutable(options.agent.adapterIdentity)
624
+ : Promise.resolve(true),
615
625
  revalidateExecutable(options.agent.agentIdentity),
616
626
  ]));
617
627
  options.signal.throwIfAborted();
618
- if (!adapterUnchanged || !agentUnchanged) {
628
+ if (unchanged.some((result) => !result)) {
619
629
  throw new AcpExecutionError("The local Agent runtime changed; restart Mobius before starting a new conversation", {}, "agent_runtime_changed");
620
630
  }
621
631
  const runtime = metrics.measureSync("process-spawn", () => new AcpProcessSession(options.agent, options.cwd, options.additionalDirectories, options.sessionId, getObserver, store, metrics));
@@ -800,6 +810,14 @@ class AcpProcessSession {
800
810
  await this.#metrics.measure("agent-initialize", async () => await this.#initializeAgentOperation(signal));
801
811
  }
802
812
  async #initializeAgentOperation(signal) {
813
+ if (this.#inProcessAgent !== null) {
814
+ // The ACP agent runs in this process, but it still owns an app-server child that must
815
+ // start and complete its own handshake before the ACP conversation can begin.
816
+ await this.race(this.#inProcessAgent.initialize(signal), "The Codex app-server exited during initialization", signal).catch((cause) => {
817
+ signal.throwIfAborted();
818
+ throw new RetryableAcpInitializationError(cause);
819
+ });
820
+ }
803
821
  const initialized = await this.race(this.#connection.agent.request(methods.agent.initialize, {
804
822
  clientCapabilities: {
805
823
  elicitation: { form: {}, url: {} },
@@ -1107,7 +1125,7 @@ class AcpProcessSession {
1107
1125
  throw new AcpExecutionError("ACP agent returned an invalid steering response", {}, "acp_invalid_steering_response");
1108
1126
  };
1109
1127
  cancel = async () => {
1110
- const capturedProcesses = await captureProcessTree(this.#child);
1128
+ const capturedProcesses = this.#runtimeChild === null ? [] : await captureProcessTree(this.#runtimeChild);
1111
1129
  try {
1112
1130
  await this.cancelPendingInteractions();
1113
1131
  if (this.#turn.running) {
@@ -1433,7 +1451,12 @@ class AcpProcessSession {
1433
1451
  };
1434
1452
  closeProcess = async (capturedProcesses = []) => {
1435
1453
  try {
1436
- await stopProcessTree(this.#child, capturedProcesses);
1454
+ if (this.#runtimeChild === null) {
1455
+ // The in-process agent owns its app-server child and its process tree.
1456
+ await this.#inProcessAgent?.close();
1457
+ return;
1458
+ }
1459
+ await stopProcessTree(this.#runtimeChild, capturedProcesses);
1437
1460
  }
1438
1461
  finally {
1439
1462
  this.#connection.close();
@@ -2290,7 +2313,7 @@ export class AcpSessionManager {
2290
2313
  this.#endSessionUse(options.sessionId);
2291
2314
  }
2292
2315
  };
2293
- openNativeSession = async (options, origin) => {
2316
+ openNativeSession = async (options, origin, loadHistory) => {
2294
2317
  const key = `${options.agent.id}:${origin.nativeSessionId}`;
2295
2318
  if (this.#nativeOperations.has(key)) {
2296
2319
  throw new AcpExecutionError("The native session is being managed", {}, "session_busy");
@@ -2312,7 +2335,9 @@ export class AcpSessionManager {
2312
2335
  }
2313
2336
  this.#nativeOperations.add(key);
2314
2337
  try {
2315
- const history = await runtime.loadHistory(options.signal);
2338
+ const history = loadHistory
2339
+ ? await runtime.loadHistory(options.signal)
2340
+ : nativeHistoryNotRetained();
2316
2341
  return {
2317
2342
  prepared: runtime.prepared(),
2318
2343
  sessionId: existing.sessionId,
@@ -2345,7 +2370,7 @@ export class AcpSessionManager {
2345
2370
  const openedKey = `${options.agent.id}:${runtime.nativeSessionId()}`;
2346
2371
  this.#nativeOperations.add(openedKey);
2347
2372
  try {
2348
- const history = await runtime.loadHistory(options.signal);
2373
+ const history = loadHistory ? await runtime.loadHistory(options.signal) : nativeHistoryNotRetained();
2349
2374
  return {
2350
2375
  sessionId: options.sessionId,
2351
2376
  prepared: runtime.prepared(),