@moxt-ai/mobius 0.0.71 → 0.0.72

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 (80) 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 +397 -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 +191 -0
  14. package/dist/acp/codex/app-server-protocol.d.ts.map +1 -0
  15. package/dist/acp/codex/app-server-protocol.js +172 -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 +4 -15
  26. package/dist/acp/session-manager.d.ts.map +1 -1
  27. package/dist/acp/session-manager.js +49 -35
  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 +5065 -4061
  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/index.js +1109 -105
  69. package/dist/index.js.map +4 -4
  70. package/dist/native-sessions/codex-history.d.ts +3 -3
  71. package/dist/native-sessions/codex-history.d.ts.map +1 -1
  72. package/dist/native-sessions/codex-history.js +1 -1
  73. package/dist/native-sessions/codex-history.js.map +1 -1
  74. package/dist/pairing/pair-local-machine.d.ts.map +1 -1
  75. package/dist/pairing/pair-local-machine.js.map +1 -1
  76. package/dist/run-daemon.js +1 -1
  77. package/dist/run-daemon.js.map +1 -1
  78. package/dist/runtime.js +8965 -7961
  79. package/dist/runtime.js.map +4 -4
  80. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -22085,30 +22085,36 @@ function readTrustedIdentity(path2) {
22085
22085
  metadata.ctimeMs
22086
22086
  );
22087
22087
  }
22088
- var LocalAgentDefinition = class _LocalAgentDefinition {
22089
- adapterIdentity;
22090
- adapterPath;
22091
- adapterVersion;
22088
+ var AgentDefinition = class {
22092
22089
  agentIdentity;
22093
22090
  agentVersion;
22094
- arguments;
22095
- command;
22096
22091
  capabilities;
22092
+ command;
22097
22093
  environment;
22098
22094
  id;
22099
22095
  label;
22100
- constructor(id, label, command, arguments_, environment = {}, adapterVersion = "", agentVersion = "", adapterIdentity = readTrustedIdentity(command), agentIdentity = adapterIdentity, capabilities = unsupportedSessionCapabilities()) {
22101
- this.adapterIdentity = adapterIdentity;
22102
- this.adapterPath = adapterIdentity.realPath;
22103
- this.adapterVersion = adapterVersion;
22096
+ constructor(id, label, _command, environment, agentVersion, agentIdentity, capabilities) {
22104
22097
  this.agentIdentity = agentIdentity;
22105
22098
  this.agentVersion = agentVersion;
22106
22099
  this.capabilities = Object.freeze({ ...capabilities });
22100
+ this.command = agentIdentity.realPath;
22101
+ this.environment = Object.freeze({ ...environment });
22107
22102
  this.id = id;
22108
22103
  this.label = label;
22109
- this.command = adapterIdentity.realPath;
22104
+ }
22105
+ };
22106
+ var LocalAgentDefinition = class _LocalAgentDefinition extends AgentDefinition {
22107
+ kind = "acp-adapter-process";
22108
+ adapterIdentity;
22109
+ adapterPath;
22110
+ adapterVersion;
22111
+ arguments;
22112
+ constructor(id, label, command, arguments_, environment = {}, adapterVersion = "", agentVersion = "", adapterIdentity = readTrustedIdentity(command), agentIdentity = adapterIdentity, capabilities = unsupportedSessionCapabilities()) {
22113
+ super(id, label, command, environment, agentVersion, agentIdentity, capabilities);
22114
+ this.adapterIdentity = adapterIdentity;
22115
+ this.adapterPath = adapterIdentity.realPath;
22116
+ this.adapterVersion = adapterVersion;
22110
22117
  this.arguments = Object.freeze([...arguments_]);
22111
- this.environment = Object.freeze({ ...environment });
22112
22118
  }
22113
22119
  withEnvironment = (environment) => new _LocalAgentDefinition(
22114
22120
  this.id,
@@ -22123,6 +22129,24 @@ var LocalAgentDefinition = class _LocalAgentDefinition {
22123
22129
  this.capabilities
22124
22130
  );
22125
22131
  };
22132
+ var InProcessAcpAgentDefinition = class _InProcessAcpAgentDefinition extends AgentDefinition {
22133
+ kind = "in-process-acp";
22134
+ createEndpoint;
22135
+ constructor(id, label, command, createEndpoint, environment = {}, agentVersion = "", agentIdentity = readTrustedIdentity(command), capabilities = unsupportedSessionCapabilities()) {
22136
+ super(id, label, command, environment, agentVersion, agentIdentity, capabilities);
22137
+ this.createEndpoint = createEndpoint;
22138
+ }
22139
+ withEnvironment = (environment) => new _InProcessAcpAgentDefinition(
22140
+ this.id,
22141
+ this.label,
22142
+ this.command,
22143
+ this.createEndpoint,
22144
+ environment,
22145
+ this.agentVersion,
22146
+ this.agentIdentity,
22147
+ this.capabilities
22148
+ );
22149
+ };
22126
22150
  var InstallableAgentDefinition = class {
22127
22151
  id;
22128
22152
  label;
@@ -22593,6 +22617,30 @@ async function replaceImageMarkers(text3, replace) {
22593
22617
  return `${rewritten}${text3.slice(cursor)}`;
22594
22618
  }
22595
22619
 
22620
+ // src/acp/acp-error.ts
22621
+ var AcpExecutionError = class extends Error {
22622
+ code;
22623
+ constructor(message, options = {}, code = "acp_execution_failed") {
22624
+ super(message, options);
22625
+ this.code = code;
22626
+ this.name = "AcpExecutionError";
22627
+ }
22628
+ };
22629
+ var AcpConfigurationValueUnavailableError = class extends AcpExecutionError {
22630
+ configId;
22631
+ offeredValueCount;
22632
+ offeredValues;
22633
+ requestedValue;
22634
+ constructor(configId, requestedValue, offeredValues) {
22635
+ super("The requested ACP configuration value is unavailable", {}, "invalid_session_configuration");
22636
+ this.name = "AcpConfigurationValueUnavailableError";
22637
+ this.configId = configId.slice(0, 128);
22638
+ this.requestedValue = requestedValue.slice(0, 128);
22639
+ this.offeredValueCount = offeredValues.length;
22640
+ this.offeredValues = Object.freeze(offeredValues.slice(0, 32).map((value) => value.slice(0, 128)));
22641
+ }
22642
+ };
22643
+
22596
22644
  // src/acp/activity.ts
22597
22645
  var TRUNCATION_MARKER = "\n\u2026 output truncated by Mobius";
22598
22646
  function isRecord3(value) {
@@ -31148,28 +31196,6 @@ var AcpAgentSettingsSnapshot = class {
31148
31196
  this.configOptions = configOptions;
31149
31197
  }
31150
31198
  };
31151
- var AcpExecutionError = class extends Error {
31152
- code;
31153
- constructor(message, options = {}, code = "acp_execution_failed") {
31154
- super(message, options);
31155
- this.code = code;
31156
- this.name = "AcpExecutionError";
31157
- }
31158
- };
31159
- var AcpConfigurationValueUnavailableError = class extends AcpExecutionError {
31160
- configId;
31161
- offeredValueCount;
31162
- offeredValues;
31163
- requestedValue;
31164
- constructor(configId, requestedValue, offeredValues) {
31165
- super("The requested ACP configuration value is unavailable", {}, "invalid_session_configuration");
31166
- this.name = "AcpConfigurationValueUnavailableError";
31167
- this.configId = configId.slice(0, 128);
31168
- this.requestedValue = requestedValue.slice(0, 128);
31169
- this.offeredValueCount = offeredValues.length;
31170
- this.offeredValues = Object.freeze(offeredValues.slice(0, 32).map((value) => value.slice(0, 128)));
31171
- }
31172
- };
31173
31199
  var RetryableAcpInitializationError = class extends AcpExecutionError {
31174
31200
  constructor(cause) {
31175
31201
  super("ACP agent initialization failed", { cause });
@@ -31666,16 +31692,18 @@ var AcpProcessSession = class _AcpProcessSession {
31666
31692
  #additionalDirectories;
31667
31693
  #acceptedUrlElicitations = /* @__PURE__ */ new Map();
31668
31694
  #agentId;
31669
- #child;
31670
31695
  #connection;
31671
31696
  #cwd;
31672
31697
  #environment;
31673
31698
  #getObserver;
31699
+ #inProcessAgent;
31674
31700
  #mobiusSessionId;
31675
31701
  #pendingElicitations = /* @__PURE__ */ new Map();
31676
31702
  #pendingPermissions = /* @__PURE__ */ new Map();
31677
31703
  #preSessionUpdates = [];
31704
+ // The adapter-process topology only. An in-process agent owns the app-server child itself.
31678
31705
  #processExit;
31706
+ #runtimeChild;
31679
31707
  #metrics;
31680
31708
  #sessionConfigProtocol;
31681
31709
  #store;
@@ -31710,18 +31738,33 @@ var AcpProcessSession = class _AcpProcessSession {
31710
31738
  this.#sessionConfigProtocol = sessionConfigProtocolForAgent(agent.id);
31711
31739
  this.#store = store;
31712
31740
  this.#verifiedAgentVersion = agent.agentVersion;
31713
- this.#child = spawn2(agent.adapterPath, [...agent.arguments], {
31741
+ if (agent.kind === "in-process-acp") {
31742
+ const inProcess = agent.createEndpoint({
31743
+ command: agent.command,
31744
+ cwd,
31745
+ environment: agent.environment
31746
+ });
31747
+ this.#inProcessAgent = inProcess;
31748
+ this.#runtimeChild = null;
31749
+ this.#processExit = new Promise(() => {
31750
+ });
31751
+ this.#connection = createAcpClient(this).connect(inProcess.app());
31752
+ return;
31753
+ }
31754
+ this.#inProcessAgent = null;
31755
+ const child = spawn2(agent.adapterPath, [...agent.arguments], {
31714
31756
  cwd,
31715
31757
  detached: process.platform !== "win32",
31716
31758
  env: { ...process.env, ...agent.environment },
31717
31759
  shell: false,
31718
31760
  stdio: ["pipe", "pipe", "pipe"]
31719
31761
  });
31720
- const stdin = this.#child.stdin;
31721
- const stdout = this.#child.stdout;
31722
- const stderr = this.#child.stderr;
31762
+ this.#runtimeChild = child;
31763
+ const stdin = child.stdin;
31764
+ const stdout = child.stdout;
31765
+ const stderr = child.stderr;
31723
31766
  if (stdin === null || stdout === null || stderr === null) {
31724
- this.#child.kill("SIGKILL");
31767
+ child.kill("SIGKILL");
31725
31768
  throw new AcpExecutionError("ACP process streams are unavailable");
31726
31769
  }
31727
31770
  stderr.setEncoding("utf8");
@@ -31729,8 +31772,8 @@ var AcpProcessSession = class _AcpProcessSession {
31729
31772
  process.stderr.write(`[${agent.id}-acp] ${chunk}`);
31730
31773
  });
31731
31774
  this.#processExit = new Promise((resolve8) => {
31732
- this.#child.once("error", resolve8);
31733
- this.#child.once("exit", resolve8);
31775
+ child.once("error", resolve8);
31776
+ child.once("exit", resolve8);
31734
31777
  });
31735
31778
  const stream = ndJsonStream(createWritableAcpStream(stdin), readableWebStream(stdout));
31736
31779
  this.#connection = createAcpClient(this).connect(stream);
@@ -31738,15 +31781,16 @@ var AcpProcessSession = class _AcpProcessSession {
31738
31781
  static async #start(options, getObserver, store, initialize, metrics) {
31739
31782
  for (let attempt = 1; attempt <= 2; attempt += 1) {
31740
31783
  options.signal.throwIfAborted();
31741
- const [adapterUnchanged, agentUnchanged] = await metrics.measure(
31784
+ const unchanged = await metrics.measure(
31742
31785
  "executable-validation",
31743
31786
  async () => await Promise.all([
31744
- revalidateExecutable(options.agent.adapterIdentity),
31787
+ // Only the adapter topology has an adapter executable to revalidate.
31788
+ options.agent.kind === "acp-adapter-process" ? revalidateExecutable(options.agent.adapterIdentity) : Promise.resolve(true),
31745
31789
  revalidateExecutable(options.agent.agentIdentity)
31746
31790
  ])
31747
31791
  );
31748
31792
  options.signal.throwIfAborted();
31749
- if (!adapterUnchanged || !agentUnchanged) {
31793
+ if (unchanged.some((result) => !result)) {
31750
31794
  throw new AcpExecutionError(
31751
31795
  "The local Agent runtime changed; restart Mobius before starting a new conversation",
31752
31796
  {},
@@ -31979,6 +32023,16 @@ var AcpProcessSession = class _AcpProcessSession {
31979
32023
  await this.#metrics.measure("agent-initialize", async () => await this.#initializeAgentOperation(signal));
31980
32024
  }
31981
32025
  async #initializeAgentOperation(signal) {
32026
+ if (this.#inProcessAgent !== null) {
32027
+ await this.race(
32028
+ this.#inProcessAgent.initialize(signal),
32029
+ "The Codex app-server exited during initialization",
32030
+ signal
32031
+ ).catch((cause) => {
32032
+ signal.throwIfAborted();
32033
+ throw new RetryableAcpInitializationError(cause);
32034
+ });
32035
+ }
31982
32036
  const initialized = await this.race(
31983
32037
  this.#connection.agent.request(
31984
32038
  methods3.agent.initialize,
@@ -32471,7 +32525,7 @@ var AcpProcessSession = class _AcpProcessSession {
32471
32525
  );
32472
32526
  };
32473
32527
  cancel = async () => {
32474
- const capturedProcesses = await captureProcessTree(this.#child);
32528
+ const capturedProcesses = this.#runtimeChild === null ? [] : await captureProcessTree(this.#runtimeChild);
32475
32529
  try {
32476
32530
  await this.cancelPendingInteractions();
32477
32531
  if (this.#turn.running) {
@@ -32834,7 +32888,11 @@ var AcpProcessSession = class _AcpProcessSession {
32834
32888
  };
32835
32889
  closeProcess = async (capturedProcesses = []) => {
32836
32890
  try {
32837
- await stopProcessTree(this.#child, capturedProcesses);
32891
+ if (this.#runtimeChild === null) {
32892
+ await this.#inProcessAgent?.close();
32893
+ return;
32894
+ }
32895
+ await stopProcessTree(this.#runtimeChild, capturedProcesses);
32838
32896
  } finally {
32839
32897
  this.#connection.close();
32840
32898
  }
@@ -34523,6 +34581,21 @@ var DirectAcpAgentDefinition = class extends LocalAgentSpecification {
34523
34581
  this.managedAgentExecutablePath = this.managedAdapterExecutablePath;
34524
34582
  }
34525
34583
  };
34584
+ var InProcessAcpAgentDefinition2 = class extends LocalAgentSpecification {
34585
+ launchArguments = Object.freeze([]);
34586
+ adapterOverrideVariable;
34587
+ adapterVersion = "in-process";
34588
+ agentOverrideVariable;
34589
+ managedAdapterExecutablePath;
34590
+ managedAgentExecutablePath;
34591
+ constructor(executableOverrideVariable, managedExecutablePath) {
34592
+ super();
34593
+ this.adapterOverrideVariable = executableOverrideVariable;
34594
+ this.agentOverrideVariable = executableOverrideVariable;
34595
+ this.managedAdapterExecutablePath = Object.freeze([...managedExecutablePath]);
34596
+ this.managedAgentExecutablePath = this.managedAdapterExecutablePath;
34597
+ }
34598
+ };
34526
34599
  var BridgedAcpAgentDefinition = class extends LocalAgentSpecification {
34527
34600
  launchArguments = Object.freeze([]);
34528
34601
  get adapterExecutable() {
@@ -34564,31 +34637,909 @@ var ClaudeCodeAgentSpecification = class extends BridgedAcpAgentDefinition {
34564
34637
  managedAgentExecutablePath = ["agents", "claude", "home", ".local", "bin", "claude"];
34565
34638
  };
34566
34639
 
34640
+ // src/acp/codex/agent.ts
34641
+ import {
34642
+ agent as createAgentApp,
34643
+ methods as methods4,
34644
+ PROTOCOL_VERSION as PROTOCOL_VERSION2
34645
+ } from "@agentclientprotocol/sdk";
34646
+
34647
+ // src/acp/codex/app-server-client.ts
34648
+ import { spawn as spawn3 } from "node:child_process";
34649
+
34650
+ // src/acp/codex/app-server-protocol.ts
34651
+ var boundedText = (maximum) => external_exports.string().max(maximum);
34652
+ var jsonValue = external_exports.lazy(() => external_exports.unknown());
34653
+ var requestIdSchema = external_exports.union([external_exports.number(), external_exports.string()]).refine((value) => typeof value === "number" || value.length <= 256);
34654
+ var errorResponseSchema = external_exports.object({
34655
+ error: external_exports.object({ code: external_exports.number(), message: boundedText(4096) }),
34656
+ id: requestIdSchema
34657
+ });
34658
+ var resultResponseSchema = external_exports.object({ id: requestIdSchema, result: external_exports.unknown() });
34659
+ var serverRequestSchema = external_exports.object({
34660
+ id: requestIdSchema,
34661
+ method: external_exports.string(),
34662
+ params: external_exports.unknown().optional()
34663
+ });
34664
+ var serverNotificationSchema = external_exports.object({
34665
+ method: external_exports.string(),
34666
+ params: external_exports.unknown().optional()
34667
+ });
34668
+ function decodeAppServerMessage(value) {
34669
+ const record2 = external_exports.record(external_exports.string(), external_exports.unknown()).parse(value);
34670
+ const error62 = errorResponseSchema.safeParse(record2);
34671
+ if (error62.success) {
34672
+ return {
34673
+ code: error62.data.error.code,
34674
+ id: error62.data.id,
34675
+ kind: "error-response",
34676
+ message: error62.data.error.message
34677
+ };
34678
+ }
34679
+ const result = resultResponseSchema.safeParse(record2);
34680
+ if (result.success) {
34681
+ return { id: result.data.id, kind: "result-response", result: result.data.result };
34682
+ }
34683
+ const request = serverRequestSchema.safeParse(record2);
34684
+ if (request.success) {
34685
+ return {
34686
+ id: request.data.id,
34687
+ kind: "server-request",
34688
+ method: request.data.method,
34689
+ params: request.data.params ?? {}
34690
+ };
34691
+ }
34692
+ const notification = serverNotificationSchema.parse(record2);
34693
+ return { kind: "notification", method: notification.method, params: notification.params ?? {} };
34694
+ }
34695
+ var turnStatusSchema = external_exports.enum(["inProgress", "completed", "interrupted", "failed"]);
34696
+ var messagePhaseSchema = external_exports.enum(["commentary", "final_answer"]);
34697
+ var commandExecutionStatusSchema = external_exports.enum(["inProgress", "completed", "failed", "declined"]);
34698
+ var patchApplyStatusSchema = external_exports.enum(["inProgress", "completed", "failed", "declined"]);
34699
+ var mcpToolCallStatusSchema = external_exports.enum(["inProgress", "completed", "failed"]);
34700
+ var dynamicToolCallStatusSchema = external_exports.enum(["inProgress", "completed", "failed"]);
34701
+ var fileUpdateChangeSchema = external_exports.object({
34702
+ diff: boundedText(1e6),
34703
+ kind: external_exports.unknown(),
34704
+ path: boundedText(4096)
34705
+ });
34706
+ var threadItemSchema = external_exports.discriminatedUnion("type", [
34707
+ external_exports.object({
34708
+ id: boundedText(256),
34709
+ text: boundedText(1e6),
34710
+ type: external_exports.literal("agentMessage"),
34711
+ phase: messagePhaseSchema.nullish()
34712
+ }),
34713
+ external_exports.object({ content: external_exports.array(external_exports.unknown()).max(1e4), id: boundedText(256), type: external_exports.literal("userMessage") }),
34714
+ external_exports.object({
34715
+ aggregatedOutput: boundedText(4e6).nullish(),
34716
+ command: boundedText(32768),
34717
+ cwd: boundedText(4096),
34718
+ durationMs: external_exports.number().nullish(),
34719
+ exitCode: external_exports.number().nullish(),
34720
+ id: boundedText(256),
34721
+ processId: external_exports.string().nullish(),
34722
+ status: commandExecutionStatusSchema,
34723
+ type: external_exports.literal("commandExecution")
34724
+ }),
34725
+ external_exports.object({
34726
+ changes: external_exports.array(fileUpdateChangeSchema).max(1e4),
34727
+ id: boundedText(256),
34728
+ status: patchApplyStatusSchema,
34729
+ type: external_exports.literal("fileChange")
34730
+ }),
34731
+ external_exports.object({
34732
+ arguments: jsonValue.optional(),
34733
+ error: external_exports.unknown().nullish(),
34734
+ id: boundedText(256),
34735
+ result: external_exports.unknown().nullish(),
34736
+ server: boundedText(256),
34737
+ status: mcpToolCallStatusSchema,
34738
+ tool: boundedText(256),
34739
+ type: external_exports.literal("mcpToolCall")
34740
+ }),
34741
+ external_exports.object({
34742
+ arguments: jsonValue.optional(),
34743
+ contentItems: external_exports.array(external_exports.unknown()).max(1e4).nullish(),
34744
+ id: boundedText(256),
34745
+ namespace: external_exports.string().nullish(),
34746
+ status: dynamicToolCallStatusSchema,
34747
+ success: external_exports.boolean().nullish(),
34748
+ tool: boundedText(256),
34749
+ type: external_exports.literal("dynamicToolCall")
34750
+ }),
34751
+ external_exports.object({
34752
+ content: external_exports.array(boundedText(1e6)).max(1e3),
34753
+ id: boundedText(256),
34754
+ summary: external_exports.array(boundedText(1e6)).max(1e3),
34755
+ type: external_exports.literal("reasoning")
34756
+ }),
34757
+ external_exports.object({ id: boundedText(256), text: boundedText(1e6), type: external_exports.literal("plan") })
34758
+ ]);
34759
+ var turnSchema = external_exports.object({
34760
+ durationMs: external_exports.number().nullish(),
34761
+ error: external_exports.object({ message: boundedText(4096) }).nullish(),
34762
+ id: boundedText(256),
34763
+ status: turnStatusSchema
34764
+ });
34765
+ var turnNotificationSchema = external_exports.object({
34766
+ thread: external_exports.object({ id: boundedText(256) }).nullish(),
34767
+ threadId: boundedText(256),
34768
+ turn: turnSchema
34769
+ });
34770
+ var commandApprovalParamsSchema = external_exports.object({
34771
+ command: external_exports.string().nullish(),
34772
+ commandActions: external_exports.array(external_exports.unknown()).max(1e3).nullish(),
34773
+ cwd: external_exports.string().nullish(),
34774
+ itemId: boundedText(256),
34775
+ reason: external_exports.string().nullish(),
34776
+ threadId: boundedText(256),
34777
+ turnId: boundedText(256)
34778
+ });
34779
+ var fileChangeApprovalParamsSchema = external_exports.object({
34780
+ grantRoot: external_exports.string().nullish(),
34781
+ itemId: boundedText(256),
34782
+ reason: external_exports.string().nullish(),
34783
+ threadId: boundedText(256),
34784
+ turnId: boundedText(256)
34785
+ });
34786
+ var userInputOptionSchema = external_exports.object({
34787
+ description: boundedText(4096),
34788
+ label: boundedText(1024)
34789
+ });
34790
+ var userInputQuestionSchema = external_exports.object({
34791
+ header: boundedText(1024),
34792
+ id: boundedText(256),
34793
+ options: external_exports.array(userInputOptionSchema).max(1e3).nullish(),
34794
+ question: boundedText(4096)
34795
+ });
34796
+ var requestUserInputParamsSchema = external_exports.object({
34797
+ itemId: boundedText(256).nullish(),
34798
+ questions: external_exports.array(userInputQuestionSchema).max(1e3),
34799
+ threadId: boundedText(256),
34800
+ turnId: boundedText(256)
34801
+ });
34802
+ var mcpElicitationParamsSchema = external_exports.object({
34803
+ message: boundedText(4096),
34804
+ mode: external_exports.enum(["form", "url"]).or(external_exports.string()),
34805
+ requestedSchema: external_exports.unknown().optional(),
34806
+ serverName: boundedText(256),
34807
+ threadId: boundedText(256).nullish(),
34808
+ turnId: boundedText(256).nullish(),
34809
+ url: external_exports.string().optional()
34810
+ });
34811
+ var threadStartResponseSchema = external_exports.object({
34812
+ thread: external_exports.object({ id: boundedText(256) })
34813
+ });
34814
+
34815
+ // src/acp/codex/app-server-client.ts
34816
+ var INITIALIZE_TIMEOUT_MILLISECONDS = 3e4;
34817
+ var OUTPUT_LIMIT_BYTES = 32 * 1024 * 1024;
34818
+ var CodexAppServerError = class extends Error {
34819
+ code;
34820
+ constructor(code, message, options = {}) {
34821
+ super(message, options);
34822
+ this.code = code;
34823
+ this.name = "CodexAppServerError";
34824
+ }
34825
+ };
34826
+ var CodexAppServerClient = class {
34827
+ #child;
34828
+ #handlers;
34829
+ #pending = /* @__PURE__ */ new Map();
34830
+ #processExit;
34831
+ #failure = null;
34832
+ #nextRequestId = 1;
34833
+ #pendingBuffer = "";
34834
+ #receivedBytes = 0;
34835
+ #closed = false;
34836
+ constructor(options) {
34837
+ this.#handlers = options.handlers;
34838
+ this.#child = spawn3(options.command, ["app-server"], {
34839
+ cwd: options.cwd,
34840
+ detached: process.platform !== "win32",
34841
+ env: { ...process.env, ...options.environment },
34842
+ shell: false,
34843
+ stdio: ["pipe", "pipe", "pipe"]
34844
+ });
34845
+ const stdin = this.#child.stdin;
34846
+ const stdout = this.#child.stdout;
34847
+ const stderr = this.#child.stderr;
34848
+ if (stdin === null || stdout === null || stderr === null) {
34849
+ this.#child.kill("SIGKILL");
34850
+ throw new CodexAppServerError("codex_app_server_unavailable", "The Codex app-server is unavailable");
34851
+ }
34852
+ stdout.setEncoding("utf8");
34853
+ stdout.on("data", (chunk) => {
34854
+ this.#consume(chunk);
34855
+ });
34856
+ stderr.setEncoding("utf8");
34857
+ stderr.on("data", (chunk) => {
34858
+ process.stderr.write(`[codex-app-server] ${chunk}`);
34859
+ });
34860
+ this.#processExit = new Promise((resolve8) => {
34861
+ this.#child.once("error", resolve8);
34862
+ this.#child.once("exit", resolve8);
34863
+ });
34864
+ }
34865
+ child = () => this.#child;
34866
+ #fail = (error62) => {
34867
+ this.#failure ??= error62;
34868
+ for (const [id, pending] of this.#pending) {
34869
+ this.#pending.delete(id);
34870
+ pending.completion.reject(error62);
34871
+ }
34872
+ };
34873
+ #exitedFailure = (method) => this.#failure ?? new CodexAppServerError("codex_app_server_exited", `The Codex app-server stopped during ${method}`);
34874
+ #consume = (chunk) => {
34875
+ try {
34876
+ this.#receivedBytes += Buffer.byteLength(chunk);
34877
+ if (this.#receivedBytes > OUTPUT_LIMIT_BYTES) {
34878
+ throw new CodexAppServerError(
34879
+ "codex_app_server_output_limit",
34880
+ "The Codex app-server produced too much output"
34881
+ );
34882
+ }
34883
+ this.#pendingBuffer += chunk;
34884
+ let newline = this.#pendingBuffer.indexOf("\n");
34885
+ while (newline >= 0) {
34886
+ const line = this.#pendingBuffer.slice(0, newline);
34887
+ this.#pendingBuffer = this.#pendingBuffer.slice(newline + 1);
34888
+ newline = this.#pendingBuffer.indexOf("\n");
34889
+ if (line.trim().length === 0) {
34890
+ continue;
34891
+ }
34892
+ const value = JSON.parse(line);
34893
+ this.#dispatch(decodeAppServerMessage(value));
34894
+ }
34895
+ } catch (error62) {
34896
+ this.#fail(
34897
+ error62 instanceof CodexAppServerError ? error62 : new CodexAppServerError(
34898
+ "codex_app_server_protocol_error",
34899
+ "The Codex app-server sent an unreadable message",
34900
+ { cause: error62 }
34901
+ )
34902
+ );
34903
+ this.#child.kill("SIGKILL");
34904
+ }
34905
+ };
34906
+ // Handler failures are recorded as the app-server's terminal failure: an ACP client that cannot
34907
+ // accept an update or answer an approval has no way to resume the conversation.
34908
+ #runHandler = (operation) => {
34909
+ void operation.catch((error62) => {
34910
+ this.#fail(
34911
+ error62 instanceof CodexAppServerError ? error62 : new CodexAppServerError(
34912
+ "codex_app_server_client_error",
34913
+ "Mobius could not process a Codex app-server message",
34914
+ { cause: error62 }
34915
+ )
34916
+ );
34917
+ });
34918
+ };
34919
+ #dispatch = (message) => {
34920
+ if (message.kind === "result-response") {
34921
+ const pending = this.#pending.get(message.id);
34922
+ if (pending === void 0) {
34923
+ return;
34924
+ }
34925
+ this.#pending.delete(message.id);
34926
+ pending.completion.resolve(message.result);
34927
+ return;
34928
+ }
34929
+ if (message.kind === "error-response") {
34930
+ const pending = this.#pending.get(message.id);
34931
+ if (pending === void 0) {
34932
+ return;
34933
+ }
34934
+ this.#pending.delete(message.id);
34935
+ pending.completion.reject(
34936
+ new CodexAppServerError("codex_app_server_request_failed", message.message, {
34937
+ cause: { code: message.code }
34938
+ })
34939
+ );
34940
+ return;
34941
+ }
34942
+ if (message.kind === "server-request") {
34943
+ this.#runHandler(
34944
+ this.#handlers.onServerRequest({ id: message.id, method: message.method, params: message.params })
34945
+ );
34946
+ return;
34947
+ }
34948
+ this.#runHandler(this.#handlers.onNotification(message.method, message.params));
34949
+ };
34950
+ /** Sends a request and waits for its response, bounded by the caller's cancellation signal. */
34951
+ request = async (method, params, signal) => {
34952
+ signal.throwIfAborted();
34953
+ if (this.#closed) {
34954
+ throw new CodexAppServerError("codex_app_server_closed", "The Codex app-server is closed");
34955
+ }
34956
+ const id = this.#nextRequestId;
34957
+ this.#nextRequestId += 1;
34958
+ const completion = Promise.withResolvers();
34959
+ this.#pending.set(id, { completion });
34960
+ const abort = () => {
34961
+ if (this.#pending.delete(id)) {
34962
+ completion.reject(signal.reason ?? new Error("Codex app-server request was cancelled"));
34963
+ }
34964
+ };
34965
+ signal.addEventListener("abort", abort, { once: true });
34966
+ try {
34967
+ this.#write({ id, method, params });
34968
+ return await Promise.race([completion.promise, this.#processExit.then(() => this.#exitedFailure(method))]);
34969
+ } finally {
34970
+ signal.removeEventListener("abort", abort);
34971
+ this.#pending.delete(id);
34972
+ }
34973
+ };
34974
+ notify = (method, params) => {
34975
+ this.#write({ method, params });
34976
+ };
34977
+ respond = (id, result) => {
34978
+ this.#write({ id, result });
34979
+ };
34980
+ respondWithError = (id, code, message) => {
34981
+ this.#write({ error: { code, message }, id });
34982
+ };
34983
+ #write = (message) => {
34984
+ if (this.#closed) {
34985
+ return;
34986
+ }
34987
+ const stdin = this.#child.stdin;
34988
+ if (stdin === null || stdin.destroyed) {
34989
+ throw new CodexAppServerError("codex_app_server_closed", "The Codex app-server input is closed");
34990
+ }
34991
+ stdin.write(`${JSON.stringify(message)}
34992
+ `);
34993
+ };
34994
+ /** Performs the `initialize` / `initialized` handshake. */
34995
+ initialize = async (signal) => {
34996
+ await this.request(
34997
+ "initialize",
34998
+ { clientInfo: { name: "mobius", version: "1.0.0" } },
34999
+ AbortSignal.any([signal, AbortSignal.timeout(INITIALIZE_TIMEOUT_MILLISECONDS)])
35000
+ );
35001
+ this.notify("initialized", void 0);
35002
+ };
35003
+ /**
35004
+ * Rejects every in-flight request and marks the conversation closed without waiting on the
35005
+ * process. Process teardown stays with the caller, which owns the process tree: it stops the
35006
+ * app-server and every tool subprocess it started.
35007
+ */
35008
+ detach = () => {
35009
+ if (this.#closed) {
35010
+ return;
35011
+ }
35012
+ this.#closed = true;
35013
+ this.#fail(new CodexAppServerError("codex_app_server_closed", "The Codex app-server is closed"));
35014
+ const stdin = this.#child.stdin;
35015
+ if (stdin !== null && !stdin.destroyed) {
35016
+ stdin.end();
35017
+ }
35018
+ };
35019
+ };
35020
+
35021
+ // src/acp/codex/items.ts
35022
+ var TOOL_OUTPUT_CHARACTER_LIMIT = 32768;
35023
+ var TITLE_CHARACTER_LIMIT = 500;
35024
+ var CODEX_META_KEY = "codex";
35025
+ function truncate4(value, limit) {
35026
+ return value.length <= limit ? value : value.slice(0, limit);
35027
+ }
35028
+ function textContent(text3) {
35029
+ const block = { text: truncate4(text3, TOOL_OUTPUT_CHARACTER_LIMIT), type: "text" };
35030
+ return { content: block, type: "content" };
35031
+ }
35032
+ function firstLine(value) {
35033
+ const line = value.split("\n", 1)[0] ?? "";
35034
+ return line.trim().length > 0 ? line.trim() : value.trim();
35035
+ }
35036
+ function commandStatus(status) {
35037
+ if (status === "inProgress") {
35038
+ return "in_progress";
35039
+ }
35040
+ return status === "completed" ? "completed" : "failed";
35041
+ }
35042
+ function patchStatus(status) {
35043
+ if (status === "inProgress") {
35044
+ return "in_progress";
35045
+ }
35046
+ return status === "completed" ? "completed" : "failed";
35047
+ }
35048
+ function mcpStatus(status) {
35049
+ return status === "inProgress" ? "in_progress" : status === "completed" ? "completed" : "failed";
35050
+ }
35051
+ function presentToolItem(item) {
35052
+ if (item.type === "commandExecution") {
35053
+ const output2 = item.aggregatedOutput ?? "";
35054
+ const content3 = [];
35055
+ if (output2.length > 0) {
35056
+ content3.push(textContent(output2));
35057
+ }
35058
+ if (item.exitCode != null && item.exitCode !== 0) {
35059
+ content3.push(textContent(`Exit code ${item.exitCode}`));
35060
+ }
35061
+ return {
35062
+ content: content3,
35063
+ kind: "execute",
35064
+ locations: [],
35065
+ rawInput: { command: item.command, cwd: item.cwd },
35066
+ rawOutput: { exitCode: item.exitCode, output: truncate4(output2, TOOL_OUTPUT_CHARACTER_LIMIT) },
35067
+ status: commandStatus(item.status),
35068
+ title: truncate4(firstLine(item.command), TITLE_CHARACTER_LIMIT)
35069
+ };
35070
+ }
35071
+ if (item.type === "fileChange") {
35072
+ const paths = item.changes.map((change) => change.path);
35073
+ const content3 = item.changes.map((change) => ({
35074
+ newText: truncate4(change.diff, TOOL_OUTPUT_CHARACTER_LIMIT),
35075
+ path: change.path,
35076
+ type: "diff"
35077
+ }));
35078
+ return {
35079
+ content: content3,
35080
+ kind: "edit",
35081
+ locations: paths.map((path2) => ({ path: path2 })),
35082
+ rawInput: { changes: item.changes.map((change) => change.path) },
35083
+ rawOutput: null,
35084
+ status: patchStatus(item.status),
35085
+ title: truncate4(paths.join(", "), TITLE_CHARACTER_LIMIT)
35086
+ };
35087
+ }
35088
+ if (item.type === "mcpToolCall") {
35089
+ const label = `${item.server}/${item.tool}`;
35090
+ const content3 = [];
35091
+ if (item.result != null) {
35092
+ content3.push(textContent(JSON.stringify(item.result)));
35093
+ }
35094
+ if (item.error != null) {
35095
+ content3.push(textContent(JSON.stringify(item.error)));
35096
+ }
35097
+ return {
35098
+ content: content3,
35099
+ kind: "other",
35100
+ locations: [],
35101
+ rawInput: item.arguments ?? null,
35102
+ rawOutput: item.error ?? item.result ?? null,
35103
+ status: mcpStatus(item.status),
35104
+ title: truncate4(label, TITLE_CHARACTER_LIMIT)
35105
+ };
35106
+ }
35107
+ if (item.type === "dynamicToolCall") {
35108
+ const label = item.namespace == null ? item.tool : `${item.namespace}/${item.tool}`;
35109
+ const content3 = (item.contentItems ?? []).map((entry) => textContent(JSON.stringify(entry)));
35110
+ return {
35111
+ content: content3,
35112
+ kind: "other",
35113
+ locations: [],
35114
+ rawInput: item.arguments ?? null,
35115
+ rawOutput: item.success === true ? null : item.contentItems ?? null,
35116
+ status: mcpStatus(item.status),
35117
+ title: truncate4(label, TITLE_CHARACTER_LIMIT)
35118
+ };
35119
+ }
35120
+ return null;
35121
+ }
35122
+ function toolCallUpdate(item) {
35123
+ const presentation = presentToolItem(item);
35124
+ if (presentation === null) {
35125
+ return null;
35126
+ }
35127
+ return {
35128
+ content: [...presentation.content],
35129
+ kind: presentation.kind,
35130
+ locations: [...presentation.locations],
35131
+ rawInput: presentation.rawInput,
35132
+ rawOutput: presentation.rawOutput,
35133
+ status: presentation.status,
35134
+ title: presentation.title,
35135
+ toolCallId: item.id
35136
+ };
35137
+ }
35138
+ function decodeThreadItem(value) {
35139
+ const decoded = threadItemSchema.safeParse(value);
35140
+ return decoded.success ? decoded.data : null;
35141
+ }
35142
+ function agentMessageMeta(phase) {
35143
+ if (phase == null) {
35144
+ return null;
35145
+ }
35146
+ return { [CODEX_META_KEY]: { phase } };
35147
+ }
35148
+
35149
+ // src/acp/codex/agent.ts
35150
+ var APPROVAL_REASON_CHARACTER_LIMIT = 500;
35151
+ var APPROVAL_TIMEOUT_MILLISECONDS = 36e5;
35152
+ var CODEX_AGENT_VERSION = "0.154.0";
35153
+ var APPROVAL_OPTIONS = Object.freeze([
35154
+ { kind: "allow_once", name: "Allow once", optionId: "accept" },
35155
+ { kind: "allow_always", name: "Allow for this session", optionId: "acceptForSession" },
35156
+ { kind: "reject_once", name: "Deny", optionId: "decline" }
35157
+ ]);
35158
+ function permissionDecision(optionId) {
35159
+ if (optionId === "accept" || optionId === "acceptForSession" || optionId === "decline") {
35160
+ return optionId;
35161
+ }
35162
+ return "cancel";
35163
+ }
35164
+ function promptInput(prompt) {
35165
+ const input2 = [];
35166
+ for (const block of prompt) {
35167
+ if (block.type === "text") {
35168
+ input2.push({ text: block.text, text_elements: [], type: "text" });
35169
+ continue;
35170
+ }
35171
+ if (block.type === "image") {
35172
+ input2.push({ type: "image", url: `data:${block.mimeType};base64,${block.data}` });
35173
+ continue;
35174
+ }
35175
+ if (block.type === "resource") {
35176
+ const resource = block.resource;
35177
+ input2.push({
35178
+ text: "text" in resource ? resource.text ?? "" : "",
35179
+ text_elements: [],
35180
+ type: "text"
35181
+ });
35182
+ continue;
35183
+ }
35184
+ if (block.type === "resource_link") {
35185
+ input2.push({ text: `Resource: ${block.uri}`, text_elements: [], type: "text" });
35186
+ }
35187
+ }
35188
+ return input2;
35189
+ }
35190
+ function userInputSchema(questions) {
35191
+ const properties = {};
35192
+ const required2 = [];
35193
+ for (const question of questions) {
35194
+ required2.push(question.id);
35195
+ properties[question.id] = {
35196
+ description: question.question,
35197
+ title: question.header,
35198
+ type: "string",
35199
+ ...question.options == null || question.options.length === 0 ? {} : {
35200
+ oneOf: question.options.map((option) => ({
35201
+ const: option.label,
35202
+ description: option.description,
35203
+ title: option.label
35204
+ }))
35205
+ }
35206
+ };
35207
+ }
35208
+ return { properties, required: required2, type: "object" };
35209
+ }
35210
+ var CodexAcpAgent = class {
35211
+ #app;
35212
+ #appServer;
35213
+ #connection = null;
35214
+ #nativeSessionId = "";
35215
+ #turn = null;
35216
+ #updateTail = Promise.resolve();
35217
+ constructor(options) {
35218
+ this.#appServer = new CodexAppServerClient({
35219
+ command: options.command,
35220
+ cwd: options.cwd,
35221
+ environment: options.environment,
35222
+ handlers: {
35223
+ onNotification: async (method, params) => {
35224
+ await this.#onNotification(method, params);
35225
+ },
35226
+ onServerRequest: async (request) => {
35227
+ await this.#onServerRequest(request);
35228
+ }
35229
+ }
35230
+ });
35231
+ this.#app = createAgentApp({ name: "mobius-codex" }).onConnect((connection) => {
35232
+ this.#connection = connection;
35233
+ }).onRequest(methods4.agent.initialize, async () => ({
35234
+ agentCapabilities: {
35235
+ loadSession: false,
35236
+ promptCapabilities: { embeddedContext: true, image: true },
35237
+ sessionCapabilities: { close: {} }
35238
+ },
35239
+ agentInfo: { name: "Codex", version: CODEX_AGENT_VERSION },
35240
+ authMethods: [],
35241
+ protocolVersion: PROTOCOL_VERSION2
35242
+ })).onRequest(methods4.agent.session.new, async (context) => {
35243
+ const created = threadStartResponseSchema.parse(
35244
+ await this.#appServer.request(
35245
+ "thread/start",
35246
+ { cwd: context.params.cwd },
35247
+ AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
35248
+ )
35249
+ );
35250
+ this.#nativeSessionId = created.thread.id;
35251
+ return { sessionId: created.thread.id };
35252
+ }).onRequest(methods4.agent.session.prompt, async (context) => {
35253
+ return await this.#runTurn(promptInput(context.params.prompt), context.signal);
35254
+ }).onRequest(methods4.agent.session.close, async () => {
35255
+ await this.#interruptTurn();
35256
+ }).onNotification(methods4.agent.session.cancel, async () => {
35257
+ await this.#interruptTurn();
35258
+ });
35259
+ }
35260
+ /** The ACP agent app Mobius connects its own ACP client to, in-process. */
35261
+ app = () => this.#app;
35262
+ /** Starts the app-server and performs its handshake. */
35263
+ initialize = async (signal) => {
35264
+ await this.#appServer.initialize(signal);
35265
+ };
35266
+ /**
35267
+ * Releases the app-server and every process it started. Mirrors the adapter path's teardown so a
35268
+ * cancelled or closed session cannot leak the tool subprocesses running under the app-server.
35269
+ */
35270
+ close = async () => {
35271
+ const child = this.#appServer.child();
35272
+ const captured = await captureProcessTree(child);
35273
+ this.#appServer.detach();
35274
+ await stopProcessTree(child, captured);
35275
+ };
35276
+ #emit = async (update) => {
35277
+ const connection = this.#connection;
35278
+ if (connection === null || this.#nativeSessionId.length === 0) {
35279
+ return;
35280
+ }
35281
+ await connection.client.notify(methods4.client.session.update, {
35282
+ sessionId: this.#nativeSessionId,
35283
+ update
35284
+ });
35285
+ };
35286
+ // Notifications are serialized so two app-server items cannot interleave into one ACP update
35287
+ // stream, and the caller awaits the result: `turn/completed` must not resolve the prompt before
35288
+ // the updates it precedes have reached the client.
35289
+ #enqueue = async (operation) => {
35290
+ const pending = this.#updateTail.then(operation, operation);
35291
+ this.#updateTail = pending;
35292
+ await pending;
35293
+ };
35294
+ #onNotification = async (method, params) => {
35295
+ if (method === "turn/started") {
35296
+ const decoded = turnNotificationSchema.safeParse(params);
35297
+ if (decoded.success && decoded.data.threadId === this.#nativeSessionId && this.#turn !== null) {
35298
+ this.#turn = { completion: this.#turn.completion, turn: { id: decoded.data.turn.id } };
35299
+ }
35300
+ return;
35301
+ }
35302
+ if (method === "turn/completed") {
35303
+ const decoded = turnNotificationSchema.safeParse(params);
35304
+ if (decoded.success && decoded.data.threadId === this.#nativeSessionId) {
35305
+ await this.#completeTurn(decoded.data.turn);
35306
+ }
35307
+ return;
35308
+ }
35309
+ if (method === "thread/name/updated") {
35310
+ const threadName = params.threadName;
35311
+ if (typeof threadName === "string" && threadName.length > 0) {
35312
+ await this.#enqueue(async () => {
35313
+ await this.#emit({ sessionUpdate: "session_info_update", title: threadName });
35314
+ });
35315
+ }
35316
+ return;
35317
+ }
35318
+ if (method === "turn/plan/updated") {
35319
+ const plan = params.plan;
35320
+ if (Array.isArray(plan) && params.threadId === this.#nativeSessionId) {
35321
+ const entries = plan.map((step) => ({
35322
+ content: typeof step === "object" && step !== null && "step" in step ? String(Reflect.get(step, "step")) : "",
35323
+ priority: "medium",
35324
+ status: "in_progress"
35325
+ }));
35326
+ await this.#enqueue(async () => {
35327
+ await this.#emit({ entries, sessionUpdate: "plan" });
35328
+ });
35329
+ }
35330
+ return;
35331
+ }
35332
+ if (method !== "item/started" && method !== "item/completed") {
35333
+ return;
35334
+ }
35335
+ const item = decodeThreadItem(params.item);
35336
+ if (item === null) {
35337
+ return;
35338
+ }
35339
+ if (item.type === "agentMessage") {
35340
+ if (method === "item/started") {
35341
+ return;
35342
+ }
35343
+ await this.#enqueue(async () => {
35344
+ await this.#emit({
35345
+ _meta: agentMessageMeta(item.phase),
35346
+ content: { text: item.text, type: "text" },
35347
+ messageId: item.id,
35348
+ sessionUpdate: "agent_message_chunk"
35349
+ });
35350
+ });
35351
+ return;
35352
+ }
35353
+ const update = toolCallUpdate(item);
35354
+ if (update !== null) {
35355
+ await this.#enqueue(async () => {
35356
+ await this.#emit({ ...update, sessionUpdate: "tool_call_update" });
35357
+ });
35358
+ }
35359
+ };
35360
+ #onServerRequest = async (request) => {
35361
+ if (request.method === "item/commandExecution/requestApproval" || request.method === "item/fileChange/requestApproval") {
35362
+ await this.#requestApproval(request);
35363
+ return;
35364
+ }
35365
+ if (request.method === "item/tool/requestUserInput") {
35366
+ await this.#requestUserInput(request);
35367
+ return;
35368
+ }
35369
+ if (request.method === "mcpServer/elicitation/request") {
35370
+ await this.#requestMcpElicitation(request);
35371
+ return;
35372
+ }
35373
+ this.#appServer.respondWithError(request.id, -32601, `Mobius does not support ${request.method}`);
35374
+ };
35375
+ #askPermission = async (title2, toolCallId, signal) => {
35376
+ const connection = this.#connection;
35377
+ if (connection === null) {
35378
+ return "cancel";
35379
+ }
35380
+ const response = await connection.client.request(
35381
+ methods4.client.session.requestPermission,
35382
+ {
35383
+ options: [...APPROVAL_OPTIONS],
35384
+ sessionId: this.#nativeSessionId,
35385
+ toolCall: { title: title2, toolCallId }
35386
+ },
35387
+ { cancellationSignal: signal }
35388
+ );
35389
+ return response.outcome.outcome === "selected" ? permissionDecision(response.outcome.optionId) : "cancel";
35390
+ };
35391
+ #requestApproval = async (request) => {
35392
+ const decoded = request.method === "item/commandExecution/requestApproval" ? commandApprovalParamsSchema.safeParse(request.params) : fileChangeApprovalParamsSchema.safeParse(request.params);
35393
+ if (!decoded.success) {
35394
+ this.#appServer.respondWithError(request.id, -32602, "Mobius could not read the approval request");
35395
+ return;
35396
+ }
35397
+ const params = decoded.data;
35398
+ const command = "command" in params ? params.command : void 0;
35399
+ const title2 = (command ?? params.reason ?? "Approve a local change").slice(0, APPROVAL_REASON_CHARACTER_LIMIT);
35400
+ const turn = this.#turn;
35401
+ const decision = await this.#askPermission(
35402
+ title2,
35403
+ params.itemId,
35404
+ AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)
35405
+ );
35406
+ void turn;
35407
+ this.#appServer.respond(request.id, { decision });
35408
+ };
35409
+ #requestUserInput = async (request) => {
35410
+ const decoded = requestUserInputParamsSchema.safeParse(request.params);
35411
+ const connection = this.#connection;
35412
+ if (!decoded.success || connection === null) {
35413
+ this.#appServer.respond(request.id, { answers: {} });
35414
+ return;
35415
+ }
35416
+ const questions = decoded.data.questions;
35417
+ const response = await connection.client.request(
35418
+ methods4.client.elicitation.create,
35419
+ {
35420
+ message: questions.map((question) => question.question).join("\n\n").slice(0, 2e3),
35421
+ mode: "form",
35422
+ requestedSchema: userInputSchema(questions),
35423
+ sessionId: this.#nativeSessionId,
35424
+ ...decoded.data.itemId == null ? {} : { toolCallId: decoded.data.itemId }
35425
+ },
35426
+ { cancellationSignal: AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS) }
35427
+ );
35428
+ const content3 = response.action === "accept" ? Reflect.get(response, "content") : void 0;
35429
+ const answers = {};
35430
+ for (const question of questions) {
35431
+ const value = typeof content3 === "object" && content3 !== null ? Reflect.get(content3, question.id) : void 0;
35432
+ answers[question.id] = { answers: typeof value === "string" && value.length > 0 ? [value] : [] };
35433
+ }
35434
+ this.#appServer.respond(request.id, { answers });
35435
+ };
35436
+ #requestMcpElicitation = async (request) => {
35437
+ const decoded = mcpElicitationParamsSchema.safeParse(request.params);
35438
+ const connection = this.#connection;
35439
+ if (!decoded.success || connection === null) {
35440
+ this.#appServer.respondWithError(request.id, -32602, "Mobius could not read the elicitation request");
35441
+ return;
35442
+ }
35443
+ const params = decoded.data;
35444
+ const signal = AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS);
35445
+ if (params.mode === "url" && params.url !== void 0) {
35446
+ const response2 = await connection.client.request(
35447
+ methods4.client.elicitation.create,
35448
+ {
35449
+ elicitationId: `${this.#nativeSessionId}-${String(request.id)}`,
35450
+ message: params.message,
35451
+ mode: "url",
35452
+ sessionId: this.#nativeSessionId,
35453
+ url: params.url
35454
+ },
35455
+ { cancellationSignal: signal }
35456
+ );
35457
+ this.#appServer.respond(request.id, { action: response2.action });
35458
+ return;
35459
+ }
35460
+ const response = await connection.client.request(
35461
+ methods4.client.elicitation.create,
35462
+ {
35463
+ message: params.message,
35464
+ mode: "form",
35465
+ requestedSchema: params.requestedSchema ?? { properties: {}, required: [], type: "object" },
35466
+ sessionId: this.#nativeSessionId
35467
+ },
35468
+ { cancellationSignal: signal }
35469
+ );
35470
+ const content3 = response.action === "accept" ? Reflect.get(response, "content") ?? null : null;
35471
+ this.#appServer.respond(request.id, { action: response.action, content: content3 });
35472
+ };
35473
+ #runTurn = async (input2, signal) => {
35474
+ if (this.#turn !== null) {
35475
+ throw new AcpExecutionError("Another prompt is already running in this conversation", {}, "session_busy");
35476
+ }
35477
+ const completion = Promise.withResolvers();
35478
+ const turn = { completion, turn: { id: "" } };
35479
+ this.#turn = turn;
35480
+ try {
35481
+ const started = turnSchema.parse(
35482
+ (await this.#appServer.request(
35483
+ "turn/start",
35484
+ { input: input2, threadId: this.#nativeSessionId },
35485
+ signal
35486
+ )).turn
35487
+ );
35488
+ if (this.#turn === turn) {
35489
+ turn.turn.id = started.id;
35490
+ }
35491
+ return await completion.promise;
35492
+ } finally {
35493
+ if (this.#turn === turn) {
35494
+ this.#turn = null;
35495
+ }
35496
+ }
35497
+ };
35498
+ #interruptTurn = async () => {
35499
+ const turn = this.#turn;
35500
+ if (turn === null) {
35501
+ return;
35502
+ }
35503
+ this.#turn = null;
35504
+ if (turn.turn.id.length > 0) {
35505
+ try {
35506
+ await this.#appServer.request(
35507
+ "turn/interrupt",
35508
+ { threadId: this.#nativeSessionId, turnId: turn.turn.id },
35509
+ AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)
35510
+ );
35511
+ } catch {
35512
+ }
35513
+ }
35514
+ turn.completion.resolve({ stopReason: "cancelled" });
35515
+ };
35516
+ #completeTurn = async (turn) => {
35517
+ const active = this.#turn;
35518
+ if (active === null) {
35519
+ return;
35520
+ }
35521
+ this.#turn = null;
35522
+ await this.#updateTail;
35523
+ if (turn.status === "failed") {
35524
+ active.completion.reject(
35525
+ new AcpExecutionError(turn.error?.message ?? "The Codex turn failed", {}, "codex_turn_failed")
35526
+ );
35527
+ return;
35528
+ }
35529
+ active.completion.resolve({ stopReason: turn.status === "interrupted" ? "cancelled" : "end_turn" });
35530
+ };
35531
+ };
35532
+
34567
35533
  // src/agent-catalog/agents/codex-agent.ts
34568
- var CodexAgentSpecification = class extends BridgedAcpAgentDefinition {
35534
+ var CodexAgentSpecification = class extends InProcessAcpAgentDefinition2 {
34569
35535
  versionProbeTimeoutMilliseconds = 1e4;
34570
- adapterEnvironmentVariable = "CODEX_PATH";
34571
- adapterOverrideVariable = "MOBIUS_CODEX_ACP_PATH";
34572
- adapterPackageDefinition = new ManagedNpmPackageDefinition(
34573
- "@agentclientprotocol/codex-acp",
34574
- "1.8.0",
34575
- "codex-acp"
34576
- );
34577
35536
  agentExecutable = "codex";
34578
- agentOverrideVariable = "MOBIUS_CODEX_PATH";
35537
+ createEndpoint = (options) => new CodexAcpAgent(options);
34579
35538
  id = "codex";
34580
35539
  label = "Codex";
34581
- managedAdapterExecutablePath = [
34582
- "adapters",
34583
- "codex",
34584
- "1.8.0",
34585
- "node_modules",
34586
- "@agentclientprotocol",
34587
- "codex-acp",
34588
- "dist",
34589
- "index.js"
34590
- ];
34591
- managedAgentExecutablePath = ["agents", "codex", "bin", "codex"];
35540
+ constructor() {
35541
+ super("MOBIUS_CODEX_PATH", ["agents", "codex", "bin", "codex"]);
35542
+ }
34592
35543
  };
34593
35544
 
34594
35545
  // src/agent-catalog/agent-probe-error.ts
@@ -34616,10 +35567,10 @@ async function resolveUserLocalExecutable(executableName, context) {
34616
35567
  }
34617
35568
 
34618
35569
  // src/agent-catalog/agents/verify-session-creation.ts
34619
- import { methods as methods4 } from "@agentclientprotocol/sdk";
35570
+ import { methods as methods5 } from "@agentclientprotocol/sdk";
34620
35571
  async function verifySessionCreation(connection, capabilities, defaultWorkspace, signal, label) {
34621
35572
  const session = await connection.agent.request(
34622
- methods4.agent.session.new,
35573
+ methods5.agent.session.new,
34623
35574
  {
34624
35575
  additionalDirectories: [],
34625
35576
  cwd: defaultWorkspace,
@@ -34632,7 +35583,7 @@ async function verifySessionCreation(connection, capabilities, defaultWorkspace,
34632
35583
  }
34633
35584
  if (capabilities.sessionCapabilities?.close != null) {
34634
35585
  await connection.agent.request(
34635
- methods4.agent.session.close,
35586
+ methods5.agent.session.close,
34636
35587
  { sessionId: session.sessionId },
34637
35588
  { cancellationSignal: signal }
34638
35589
  );
@@ -35011,7 +35962,7 @@ var HermesAgentSpecification = class extends DirectAcpAgentDefinition {
35011
35962
 
35012
35963
  // src/agent-catalog/agents/oh-my-pi-agent.ts
35013
35964
  import {
35014
- methods as methods5
35965
+ methods as methods6
35015
35966
  } from "@agentclientprotocol/sdk";
35016
35967
  var ACP_PROBE_TIMEOUT_MILLISECONDS2 = 3e4;
35017
35968
  var OH_MY_PI_TESTED_VERSION = "18.2.7";
@@ -35032,7 +35983,7 @@ var OhMyPiAgentSpecification = class extends DirectAcpAgentDefinition {
35032
35983
  throw new AgentProbeError("acp_incompatible", "Oh My Pi does not support ACP session recovery");
35033
35984
  }
35034
35985
  const session = await connection.agent.request(
35035
- methods5.agent.session.new,
35986
+ methods6.agent.session.new,
35036
35987
  { additionalDirectories: [], cwd: defaultWorkspace, mcpServers: [] },
35037
35988
  { cancellationSignal: signal }
35038
35989
  );
@@ -35040,7 +35991,7 @@ var OhMyPiAgentSpecification = class extends DirectAcpAgentDefinition {
35040
35991
  throw new AgentProbeError("acp_incompatible", "Oh My Pi returned an invalid ACP session");
35041
35992
  }
35042
35993
  const prompt = await connection.agent.request(
35043
- methods5.agent.session.prompt,
35994
+ methods6.agent.session.prompt,
35044
35995
  { prompt: [{ text: "/session", type: "text" }], sessionId: session.sessionId },
35045
35996
  { cancellationSignal: signal }
35046
35997
  );
@@ -35365,7 +36316,7 @@ var OpenCodeAgentSpecification = class extends DirectAcpAgentDefinition {
35365
36316
  // src/agent-catalog/agents/pi-agent.ts
35366
36317
  import { join as join11 } from "node:path";
35367
36318
  import {
35368
- methods as methods6
36319
+ methods as methods7
35369
36320
  } from "@agentclientprotocol/sdk";
35370
36321
 
35371
36322
  // src/agent-installation/pi-managed-packages.ts
@@ -35432,7 +36383,7 @@ var PiAgentSpecification = class extends BridgedAcpAgentDefinition {
35432
36383
  throw new AgentProbeError("acp_incompatible", "Pi ACP adapter does not support session recovery");
35433
36384
  }
35434
36385
  const session = await connection.agent.request(
35435
- methods6.agent.session.new,
36386
+ methods7.agent.session.new,
35436
36387
  {
35437
36388
  additionalDirectories: [],
35438
36389
  cwd: defaultWorkspace,
@@ -35444,7 +36395,7 @@ var PiAgentSpecification = class extends BridgedAcpAgentDefinition {
35444
36395
  throw new AgentProbeError("acp_incompatible", "Pi ACP adapter returned an invalid session");
35445
36396
  }
35446
36397
  const prompt = await connection.agent.request(
35447
- methods6.agent.session.prompt,
36398
+ methods7.agent.session.prompt,
35448
36399
  {
35449
36400
  prompt: [{ text: "/session", type: "text" }],
35450
36401
  sessionId: session.sessionId
@@ -35565,11 +36516,11 @@ function supportedLocalAgentSpecifications() {
35565
36516
  }
35566
36517
 
35567
36518
  // src/agent-catalog/acp-readiness-probe.ts
35568
- import { spawn as spawn3 } from "node:child_process";
36519
+ import { spawn as spawn4 } from "node:child_process";
35569
36520
  import {
35570
- methods as methods7,
36521
+ methods as methods8,
35571
36522
  ndJsonStream as ndJsonStream2,
35572
- PROTOCOL_VERSION as PROTOCOL_VERSION2,
36523
+ PROTOCOL_VERSION as PROTOCOL_VERSION3,
35573
36524
  RequestError as RequestError3
35574
36525
  } from "@agentclientprotocol/sdk";
35575
36526
  var ACP_OUTPUT_LIMIT_BYTES = 1024 * 1024;
@@ -35642,6 +36593,44 @@ function writableAcpStream(output2) {
35642
36593
  }
35643
36594
  });
35644
36595
  }
36596
+ async function probeInProcessReadiness(agent, environment, defaultWorkspace, controller) {
36597
+ const inProcess = agent.createEndpoint({
36598
+ command: agent.command,
36599
+ cwd: defaultWorkspace,
36600
+ environment: { ...filterEnvironment(environment), ...agent.environment }
36601
+ });
36602
+ try {
36603
+ await inProcess.initialize(controller.signal);
36604
+ const connection = createAcpClient(new DiscoveryAcpHandler()).connect(inProcess.app());
36605
+ const initialized = await connection.agent.request(
36606
+ methods8.agent.initialize,
36607
+ {
36608
+ clientCapabilities: {},
36609
+ clientInfo: { name: "mobius", version: "0.0.3" },
36610
+ protocolVersion: PROTOCOL_VERSION3
36611
+ },
36612
+ { cancellationSignal: controller.signal }
36613
+ );
36614
+ if (initialized.protocolVersion !== PROTOCOL_VERSION3) {
36615
+ throw new AgentProbeError("acp_incompatible", "ACP agent selected an unsupported protocol version");
36616
+ }
36617
+ return new VerifiedAcpReadiness(
36618
+ normalizeVersionOutput(initialized.agentInfo?.version ?? ""),
36619
+ normalizeAcpCapabilities(initialized)
36620
+ );
36621
+ } finally {
36622
+ await inProcess.close();
36623
+ }
36624
+ }
36625
+ function filterEnvironment(environment) {
36626
+ const filtered = {};
36627
+ for (const [name, value] of Object.entries(environment)) {
36628
+ if (typeof value === "string") {
36629
+ filtered[name] = value;
36630
+ }
36631
+ }
36632
+ return filtered;
36633
+ }
35645
36634
  async function probeAcpReadiness(specification, agent, environment, defaultWorkspace, signal) {
35646
36635
  signal.throwIfAborted();
35647
36636
  const controller = new AbortController();
@@ -35655,7 +36644,23 @@ async function probeAcpReadiness(specification, agent, environment, defaultWorks
35655
36644
  if (signal.aborted) {
35656
36645
  abort();
35657
36646
  }
35658
- const child = spawn3(agent.adapterPath, [...agent.arguments], {
36647
+ if (agent.kind === "in-process-acp") {
36648
+ try {
36649
+ return await probeInProcessReadiness(agent, environment, defaultWorkspace, controller);
36650
+ } catch (error62) {
36651
+ if (signal.aborted) {
36652
+ signal.throwIfAborted();
36653
+ }
36654
+ if (timedOut) {
36655
+ throw new AgentProbeError("adapter_probe_timeout", "ACP agent probe timed out", { cause: error62 });
36656
+ }
36657
+ throw error62;
36658
+ } finally {
36659
+ clearTimeout(timeout);
36660
+ signal.removeEventListener("abort", abort);
36661
+ }
36662
+ }
36663
+ const child = spawn4(agent.adapterPath, [...agent.arguments], {
35659
36664
  cwd: defaultWorkspace,
35660
36665
  detached: process.platform !== "win32",
35661
36666
  env: { ...environment, ...agent.environment },
@@ -35691,17 +36696,17 @@ async function probeAcpReadiness(specification, agent, environment, defaultWorks
35691
36696
  try {
35692
36697
  const initialized = await Promise.race([
35693
36698
  connection.agent.request(
35694
- methods7.agent.initialize,
36699
+ methods8.agent.initialize,
35695
36700
  {
35696
36701
  clientCapabilities: {},
35697
36702
  clientInfo: { name: "mobius", version: "0.0.3" },
35698
- protocolVersion: PROTOCOL_VERSION2
36703
+ protocolVersion: PROTOCOL_VERSION3
35699
36704
  },
35700
36705
  { cancellationSignal: controller.signal }
35701
36706
  ),
35702
36707
  processExit
35703
36708
  ]);
35704
- if (initialized.protocolVersion !== PROTOCOL_VERSION2) {
36709
+ if (initialized.protocolVersion !== PROTOCOL_VERSION3) {
35705
36710
  throw new AgentProbeError("acp_incompatible", "ACP adapter selected an unsupported protocol version");
35706
36711
  }
35707
36712
  await specification.verifyAcp(connection, initialized, defaultWorkspace, controller.signal);
@@ -35876,7 +36881,7 @@ async function resolveAgentExecutables(specification, context) {
35876
36881
  );
35877
36882
  }
35878
36883
  async function resolveAdapterExecutables(specification, context) {
35879
- if (specification instanceof DirectAcpAgentDefinition) {
36884
+ if (specification instanceof DirectAcpAgentDefinition || specification instanceof InProcessAcpAgentDefinition2) {
35880
36885
  return await resolveAgentExecutables(specification, context);
35881
36886
  }
35882
36887
  if (!(specification instanceof BridgedAcpAgentDefinition)) {
@@ -36021,7 +37026,7 @@ async function discoverAgent(specification, context) {
36021
37026
  agent.identity.requestedPath,
36022
37027
  agentVersion
36023
37028
  );
36024
- if (adapters.length === 0) {
37029
+ if (adapters.length === 0 && !(specification instanceof InProcessAcpAgentDefinition2)) {
36025
37030
  return new MissingAdapter(specification, installedAgent);
36026
37031
  }
36027
37032
  for (const adapter of adapters) {
@@ -36056,23 +37061,33 @@ async function discoverAgent(specification, context) {
36056
37061
  lastFailure = integrationProbeFailure(specification, installedAgent, error62);
36057
37062
  continue;
36058
37063
  }
36059
- const definition2 = new LocalAgentDefinition(
37064
+ const buildDefinition = (verifiedAdapterVersion, capabilities) => specification instanceof InProcessAcpAgentDefinition2 ? new InProcessAcpAgentDefinition(
37065
+ specification.id,
37066
+ specification.label,
37067
+ agent.path,
37068
+ specification.createEndpoint,
37069
+ launchEnvironment,
37070
+ agentVersion.length > 0 ? agentVersion : verifiedAdapterVersion,
37071
+ agent.identity,
37072
+ capabilities
37073
+ ) : new LocalAgentDefinition(
36060
37074
  specification.id,
36061
37075
  specification.label,
36062
37076
  adapter.path,
36063
37077
  specification.launchArguments,
36064
37078
  launchEnvironment,
36065
- adapterVersion,
37079
+ verifiedAdapterVersion,
36066
37080
  agentVersion,
36067
37081
  adapter.identity,
36068
- agent.identity
37082
+ agent.identity,
37083
+ capabilities
36069
37084
  );
36070
37085
  try {
36071
37086
  const readiness = await probeWithRetry(
36072
37087
  context.signal,
36073
37088
  async () => await probeAcpReadiness(
36074
37089
  specification,
36075
- definition2,
37090
+ buildDefinition(adapterVersion, unsupportedSessionCapabilities()),
36076
37091
  context.environment,
36077
37092
  context.defaultWorkspace,
36078
37093
  context.signal
@@ -36084,18 +37099,7 @@ async function discoverAgent(specification, context) {
36084
37099
  }
36085
37100
  return new AvailableAgent(
36086
37101
  specification,
36087
- new LocalAgentDefinition(
36088
- specification.id,
36089
- specification.label,
36090
- adapter.path,
36091
- specification.launchArguments,
36092
- launchEnvironment,
36093
- verifiedAdapterVersion,
36094
- agentVersion,
36095
- adapter.identity,
36096
- agent.identity,
36097
- readiness.capabilities
36098
- )
37102
+ buildDefinition(verifiedAdapterVersion, readiness.capabilities)
36099
37103
  );
36100
37104
  } catch (error62) {
36101
37105
  if (context.signal.aborted) {
@@ -37747,7 +38751,7 @@ var FixedInstallationExecutor = class {
37747
38751
  const verified = inventory.available.find((candidate) => candidate.specification.id === agentId);
37748
38752
  if (verified instanceof AvailableAgent) {
37749
38753
  this.#audit.record("agent_installation_acp_verified", requestId, agentId, {
37750
- adapterVersion: verified.agent.adapterVersion,
38754
+ adapterVersion: verified.agent.kind === "acp-adapter-process" ? verified.agent.adapterVersion : verified.agent.agentVersion,
37751
38755
  agentVersion: verified.agent.agentVersion
37752
38756
  });
37753
38757
  await this.#publishDiscoveredAgent(agentId, inventory, environment, signal);
@@ -38027,7 +39031,7 @@ var WorkspaceDirectoryService = class {
38027
39031
  };
38028
39032
 
38029
39033
  // src/native-sessions/codex-history.ts
38030
- import { spawn as spawn4 } from "node:child_process";
39034
+ import { spawn as spawn5 } from "node:child_process";
38031
39035
  var responseSchema = external_exports.union([
38032
39036
  external_exports.object({
38033
39037
  id: external_exports.number(),
@@ -38266,7 +39270,7 @@ async function readCodexHistoryWithOptions(agent, cwd, nativeSessionId, signal,
38266
39270
  );
38267
39271
  }
38268
39272
  signal.throwIfAborted();
38269
- const child = spawn4(agent.agentIdentity.realPath, ["app-server"], {
39273
+ const child = spawn5(agent.agentIdentity.realPath, ["app-server"], {
38270
39274
  cwd,
38271
39275
  env: { ...process.env, ...agent.environment },
38272
39276
  detached: process.platform !== "win32",
@@ -40910,7 +41914,7 @@ function settingsRevision(agent, reportedAgentVersion, settings, modelEffort) {
40910
41914
  };
40911
41915
  return createHash4("sha256").update(
40912
41916
  JSON.stringify({
40913
- adapterVersion: agent.adapterVersion,
41917
+ adapterVersion: agent.kind === "acp-adapter-process" ? agent.adapterVersion : agent.agentVersion,
40914
41918
  agentId: agent.id,
40915
41919
  agentVersion: agent.agentVersion,
40916
41920
  modelEffort: revisionModelEffort,