@moxt-ai/mobius 0.0.130 → 0.0.132

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -31368,6 +31368,48 @@ var RetainedAgentProcesses = class {
31368
31368
  };
31369
31369
  };
31370
31370
 
31371
+ // src/acp/runtime-operations.ts
31372
+ var RuntimeOperations = class {
31373
+ #shutdown = new AbortController();
31374
+ #pending = /* @__PURE__ */ new Set();
31375
+ #closing = null;
31376
+ run = async (options, operation) => {
31377
+ const signal = AbortSignal.any([options.signal, this.#shutdown.signal]);
31378
+ signal.throwIfAborted();
31379
+ const pending = Promise.resolve().then(() => operation({ ...options, signal }));
31380
+ this.#pending.add(pending);
31381
+ try {
31382
+ const result = await pending;
31383
+ signal.throwIfAborted();
31384
+ return result;
31385
+ } finally {
31386
+ this.#pending.delete(pending);
31387
+ }
31388
+ };
31389
+ close = (release) => {
31390
+ if (this.#closing !== null) {
31391
+ return this.#closing;
31392
+ }
31393
+ this.#shutdown.abort();
31394
+ this.#closing = (async () => {
31395
+ await Promise.allSettled([...this.#pending]);
31396
+ await release();
31397
+ })();
31398
+ return this.#closing;
31399
+ };
31400
+ };
31401
+ async function waitForPreparation(pending, signal) {
31402
+ signal.throwIfAborted();
31403
+ const cancelled = Promise.withResolvers();
31404
+ const abort = () => cancelled.reject(signal.reason);
31405
+ signal.addEventListener("abort", abort, { once: true });
31406
+ try {
31407
+ return await Promise.race([pending, cancelled.promise]);
31408
+ } finally {
31409
+ signal.removeEventListener("abort", abort);
31410
+ }
31411
+ }
31412
+
31371
31413
  // src/acp/agent-query-processes.ts
31372
31414
  var AgentQueryProcesses = class {
31373
31415
  #processesByQuery;
@@ -31414,7 +31456,7 @@ var AgentQueryProcesses = class {
31414
31456
  prepare = async (options) => {
31415
31457
  const pending = this.#processesByQuery.pending(options.sessionId);
31416
31458
  if (pending !== void 0) {
31417
- const runtime2 = await pending;
31459
+ const runtime2 = await waitForPreparation(pending, options.signal);
31418
31460
  if (runtime2.belongsTo(options.agent.id, options.cwd, options.additionalDirectories)) {
31419
31461
  this.#processesByQuery.touch(options.sessionId, runtime2);
31420
31462
  return runtime2.prepared();
@@ -31693,6 +31735,7 @@ var AgentProcessPool = class {
31693
31735
  // src/acp/agent-runtime-manager.ts
31694
31736
  var SESSION_CONTROL_TIMEOUT_MILLISECONDS = 3e4;
31695
31737
  var AgentRuntimeManager = class {
31738
+ #operations = new RuntimeOperations();
31696
31739
  #processes = new AgentProcessPool();
31697
31740
  #executionProcesses = new RetainedAgentProcesses({
31698
31741
  touch: this.#processes.touch,
@@ -31815,8 +31858,8 @@ var AgentRuntimeManager = class {
31815
31858
  return runtime;
31816
31859
  });
31817
31860
  }
31818
- prepareSession = async (options, metrics = unmeasuredOperationMetrics) => {
31819
- const stored = metrics.measureSync("session-state-read", () => this.#store.read(options.sessionId));
31861
+ prepareSession = async (options, metrics = unmeasuredOperationMetrics) => this.#operations.run(options, async (options2) => {
31862
+ const stored = metrics.measureSync("session-state-read", () => this.#store.read(options2.sessionId));
31820
31863
  if (stored instanceof DeletedAcpStoredSession) {
31821
31864
  throw new AcpExecutionError(
31822
31865
  "The native Agent session was deleted. Start a new chat.",
@@ -31827,19 +31870,22 @@ var AgentRuntimeManager = class {
31827
31870
  if (stored instanceof FoundAcpStoredSession && this.#nativeOperations.has(`${stored.session.agentId}:${stored.session.nativeSessionId}`)) {
31828
31871
  throw new AcpExecutionError("The native session is being managed", {}, "session_busy");
31829
31872
  }
31830
- const pending = this.#executionProcesses.pending(options.sessionId);
31873
+ const pending = this.#executionProcesses.pending(options2.sessionId);
31831
31874
  if (pending !== void 0) {
31832
- const runtime2 = await metrics.measure("session-preparation-wait", async () => await pending);
31833
- if (runtime2.belongsTo(options.agent.id, options.cwd, options.additionalDirectories)) {
31834
- this.#executionProcesses.touch(options.sessionId, runtime2);
31875
+ const runtime2 = await metrics.measure(
31876
+ "session-preparation-wait",
31877
+ async () => await waitForPreparation(pending, options2.signal)
31878
+ );
31879
+ if (runtime2.belongsTo(options2.agent.id, options2.cwd, options2.additionalDirectories)) {
31880
+ this.#executionProcesses.touch(options2.sessionId, runtime2);
31835
31881
  return runtime2.prepared();
31836
31882
  }
31837
- return await this.prepareSession(options, metrics);
31883
+ return await this.prepareSession(options2, metrics);
31838
31884
  }
31839
- const existing = this.#executionProcesses.get(options.sessionId);
31885
+ const existing = this.#executionProcesses.get(options2.sessionId);
31840
31886
  if (existing !== void 0) {
31841
- if (existing.belongsTo(options.agent.id, options.cwd, options.additionalDirectories)) {
31842
- this.#executionProcesses.touch(options.sessionId, existing);
31887
+ if (existing.belongsTo(options2.agent.id, options2.cwd, options2.additionalDirectories)) {
31888
+ this.#executionProcesses.touch(options2.sessionId, existing);
31843
31889
  return existing.prepared();
31844
31890
  }
31845
31891
  if (!existing.canRebind()) {
@@ -31849,85 +31895,91 @@ var AgentRuntimeManager = class {
31849
31895
  "session_identity_mismatch"
31850
31896
  );
31851
31897
  }
31852
- const runtime2 = await this.#replacePreparation(existing, options, metrics);
31898
+ const runtime2 = await this.#replacePreparation(existing, options2, metrics);
31853
31899
  return runtime2.prepared();
31854
31900
  }
31855
- const runtime = await this.#startPreparation(options, metrics);
31901
+ const runtime = await this.#startPreparation(options2, metrics);
31856
31902
  return runtime.prepared();
31857
- };
31903
+ });
31858
31904
  /**
31859
31905
  * Opens a short-lived native ACP session only to read the local Agent's
31860
31906
  * authoritative settings. Its identity and store are private to this
31861
31907
  * operation and never become a Mobius Session.
31862
31908
  */
31863
- inspectAgentSettings = async (options) => await this.#processes.runTransient(
31864
- options.signal,
31865
- async () => await AgentSession.start(
31866
- {
31867
- ...options,
31868
- sessionId: `agent-settings-${crypto.randomUUID()}`
31909
+ inspectAgentSettings = async (options) => this.#operations.run(options, async (options2) => {
31910
+ return await this.#processes.runTransient(
31911
+ options2.signal,
31912
+ async () => await AgentSession.start(
31913
+ {
31914
+ ...options2,
31915
+ sessionId: `agent-settings-${crypto.randomUUID()}`
31916
+ },
31917
+ () => this.#agentSettingsObserver,
31918
+ new MemoryAcpSessionStore()
31919
+ ),
31920
+ async (runtime) => {
31921
+ const prepared = runtime.prepared();
31922
+ const model = options2.model;
31923
+ const configOptions = model === void 0 ? prepared.configOptions : await runtime.configure({
31924
+ ...options2,
31925
+ booleanValue: false,
31926
+ configId: prepared.configOptions.find(
31927
+ (option) => option.id === "model" || option.category === "model"
31928
+ )?.id ?? "model",
31929
+ requestId: "agent-settings-model",
31930
+ sessionId: `agent-settings-${crypto.randomUUID()}`,
31931
+ value: model,
31932
+ valueType: "select"
31933
+ });
31934
+ return new AcpAgentSettingsSnapshot(prepared.agentName, prepared.agentVersion, configOptions);
31869
31935
  },
31870
- () => this.#agentSettingsObserver,
31871
- new MemoryAcpSessionStore()
31872
- ),
31873
- async (runtime) => {
31874
- const prepared = runtime.prepared();
31875
- const model = options.model;
31876
- const configOptions = model === void 0 ? prepared.configOptions : await runtime.configure({
31877
- ...options,
31878
- booleanValue: false,
31879
- configId: prepared.configOptions.find(
31880
- (option) => option.id === "model" || option.category === "model"
31881
- )?.id ?? "model",
31882
- requestId: "agent-settings-model",
31883
- sessionId: `agent-settings-${crypto.randomUUID()}`,
31884
- value: model,
31885
- valueType: "select"
31886
- });
31887
- return new AcpAgentSettingsSnapshot(prepared.agentName, prepared.agentVersion, configOptions);
31888
- },
31889
- async (runtime) => await runtime.close()
31890
- );
31936
+ async (runtime) => await runtime.close()
31937
+ );
31938
+ });
31891
31939
  /**
31892
31940
  * Retained for Agents that expose a separate persisted configuration channel.
31893
31941
  * Use inspectAgentSettings for Agent-scoped settings discovery.
31894
31942
  */
31895
- inspectSession = async (options, metrics = unmeasuredOperationMetrics) => {
31896
- if (this.#executionProcesses.pending(options.sessionId) !== void 0 || this.#executionProcesses.get(options.sessionId) !== void 0) {
31897
- throw new AcpExecutionError("The configuration inspection session is already in use", {}, "session_busy");
31943
+ inspectSession = async (options, metrics = unmeasuredOperationMetrics) => this.#operations.run(options, async (options2) => {
31944
+ if (this.#executionProcesses.pending(options2.sessionId) !== void 0 || this.#executionProcesses.get(options2.sessionId) !== void 0) {
31945
+ throw new AcpExecutionError(
31946
+ "The configuration inspection session is already in use",
31947
+ {},
31948
+ "session_busy"
31949
+ );
31898
31950
  }
31899
- return await this.#executionProcesses.use(options.sessionId, async () => {
31900
- const runtime = await this.#startPreparation(options, metrics);
31951
+ return await this.#executionProcesses.use(options2.sessionId, async () => {
31952
+ const runtime = await this.#startPreparation(options2, metrics);
31901
31953
  try {
31902
31954
  return runtime.prepared();
31903
31955
  } finally {
31904
31956
  try {
31905
- await this.#retireSessionProcess(options.sessionId, runtime, async () => await runtime.close());
31957
+ await this.#retireSessionProcess(options2.sessionId, runtime, async () => await runtime.close());
31906
31958
  } finally {
31907
- this.#store.remove(options.sessionId);
31959
+ this.#store.remove(options2.sessionId);
31908
31960
  }
31909
31961
  }
31910
31962
  });
31911
- };
31912
- prepareExecutionSession = async (options) => {
31913
- const pending = this.#executionProcesses.pending(options.sessionId);
31963
+ });
31964
+ prepareExecutionSession = async (options) => this.#operations.run(options, async (options2) => {
31965
+ const pending = this.#executionProcesses.pending(options2.sessionId);
31914
31966
  if (pending !== void 0) {
31915
- await pending;
31916
- return await this.prepareExecutionSession(options);
31967
+ await waitForPreparation(pending, options2.signal);
31968
+ return await this.prepareExecutionSession(options2);
31917
31969
  }
31918
- const existing = this.#executionProcesses.get(options.sessionId);
31970
+ const existing = this.#executionProcesses.get(options2.sessionId);
31919
31971
  if (existing === void 0) {
31920
- return (await this.#startPreparation(options)).prepared();
31972
+ return (await this.#startPreparation(options2)).prepared();
31921
31973
  }
31922
- if (!existing.belongsTo(options.agent.id, options.cwd, options.additionalDirectories)) {
31974
+ if (!existing.belongsTo(options2.agent.id, options2.cwd, options2.additionalDirectories)) {
31923
31975
  throw new AcpExecutionError(
31924
31976
  "The agent or workspace cannot change after a conversation has started",
31925
31977
  {},
31926
31978
  "session_identity_mismatch"
31927
31979
  );
31928
31980
  }
31929
- if (existing.usesEnvironment(options.agent.environment)) {
31930
- this.#executionProcesses.touch(options.sessionId, existing);
31981
+ if (existing.usesEnvironment(options2.agent.environment)) {
31982
+ this.#executionProcesses.touch(options2.sessionId, existing);
31931
31983
  return existing.prepared();
31932
31984
  }
31933
31985
  if (existing.hasRunningTurn()) {
@@ -31937,15 +31989,15 @@ var AgentRuntimeManager = class {
31937
31989
  "session_busy"
31938
31990
  );
31939
31991
  }
31940
- return (await this.#replaceExecutionPreparation(existing, options)).prepared();
31941
- };
31942
- prepareNativeSessionBrowser = (options) => this.#queryProcesses.prepare(options);
31943
- configureSession = async (options) => {
31944
- return await this.#executionProcesses.use(options.sessionId, async () => {
31945
- const runtime = await this.ensureSession(options);
31946
- return await runtime.configure(options);
31992
+ return (await this.#replaceExecutionPreparation(existing, options2)).prepared();
31993
+ });
31994
+ prepareNativeSessionBrowser = (options) => this.#operations.run(options, (scoped) => this.#queryProcesses.prepare(scoped));
31995
+ configureSession = async (options) => this.#operations.run(options, async (options2) => {
31996
+ return await this.#executionProcesses.use(options2.sessionId, async () => {
31997
+ const runtime = await this.ensureSession(options2);
31998
+ return await runtime.configure(options2);
31947
31999
  });
31948
- };
32000
+ });
31949
32001
  cancelPrompt = async (sessionId) => {
31950
32002
  await this.#executions.cancel(sessionId, async () => {
31951
32003
  const runtime = this.#executionProcesses.get(sessionId);
@@ -31960,19 +32012,19 @@ var AgentRuntimeManager = class {
31960
32012
  }
31961
32013
  });
31962
32014
  };
31963
- steerPrompt = async (options) => {
31964
- if (this.#executions.command(options.sessionId) !== options.targetCommandId) {
32015
+ steerPrompt = async (options) => this.#operations.run(options, async (options2) => {
32016
+ if (this.#executions.command(options2.sessionId) !== options2.targetCommandId) {
31965
32017
  throw new AcpExecutionError("The target turn is no longer active", {}, "steering_target_unavailable");
31966
32018
  }
31967
- const pending = this.#executionProcesses.pending(options.sessionId);
32019
+ const pending = this.#executionProcesses.pending(options2.sessionId);
31968
32020
  if (pending !== void 0) {
31969
- await pending;
32021
+ await waitForPreparation(pending, options2.signal);
31970
32022
  }
31971
- if (this.#executions.command(options.sessionId) !== options.targetCommandId) {
32023
+ if (this.#executions.command(options2.sessionId) !== options2.targetCommandId) {
31972
32024
  throw new AcpExecutionError("The target turn is no longer active", {}, "steering_target_unavailable");
31973
32025
  }
31974
- const runtime = this.#executionProcesses.get(options.sessionId);
31975
- if (runtime === void 0 || !runtime.belongsTo(options.agent.id, options.cwd, options.additionalDirectories)) {
32026
+ const runtime = this.#executionProcesses.get(options2.sessionId);
32027
+ if (runtime === void 0 || !runtime.belongsTo(options2.agent.id, options2.cwd, options2.additionalDirectories)) {
31976
32028
  throw new AcpExecutionError(
31977
32029
  "The target turn execution context is unavailable",
31978
32030
  {},
@@ -31989,8 +32041,8 @@ var AgentRuntimeManager = class {
31989
32041
  deadline.unref();
31990
32042
  try {
31991
32043
  return await runtime.steer({
31992
- ...options,
31993
- signal: AbortSignal.any([options.signal, deadlineController.signal])
32044
+ ...options2,
32045
+ signal: AbortSignal.any([options2.signal, deadlineController.signal])
31994
32046
  });
31995
32047
  } catch (error62) {
31996
32048
  if (error62 instanceof AcpExecutionError) {
@@ -32000,44 +32052,44 @@ var AgentRuntimeManager = class {
32000
32052
  } finally {
32001
32053
  clearTimeout(deadline);
32002
32054
  }
32003
- };
32004
- runPrompt = async (options) => {
32005
- const stored = this.#store.read(options.sessionId);
32055
+ });
32056
+ runPrompt = async (options) => this.#operations.run(options, async (options2) => {
32057
+ const stored = this.#store.read(options2.sessionId);
32006
32058
  if (stored instanceof FoundAcpStoredSession && this.#nativeOperations.has(`${stored.session.agentId}:${stored.session.nativeSessionId}`)) {
32007
32059
  throw new AcpExecutionError("The native session is being managed", {}, "session_busy");
32008
32060
  }
32009
- this.#executions.begin(options.sessionId, options.commandId);
32061
+ this.#executions.begin(options2.sessionId, options2.commandId);
32010
32062
  try {
32011
- if (this.#executions.cancellation(options.sessionId) !== void 0) {
32063
+ if (this.#executions.cancellation(options2.sessionId) !== void 0) {
32012
32064
  return { stopReason: "cancelled" };
32013
32065
  }
32014
- const runtime = await this.ensureSession(options);
32015
- if (this.#nativeOperations.has(`${options.agent.id}:${runtime.nativeSessionId()}`)) {
32066
+ const runtime = await this.ensureSession(options2);
32067
+ if (this.#nativeOperations.has(`${options2.agent.id}:${runtime.nativeSessionId()}`)) {
32016
32068
  throw new AcpExecutionError("The native session is being managed", {}, "session_busy");
32017
32069
  }
32018
- if (this.#executions.cancellation(options.sessionId) !== void 0) {
32070
+ if (this.#executions.cancellation(options2.sessionId) !== void 0) {
32019
32071
  return { stopReason: "cancelled" };
32020
32072
  }
32021
32073
  try {
32022
- const result = await runtime.prompt(options);
32023
- return this.#executions.cancellation(options.sessionId) !== void 0 ? { stopReason: "cancelled" } : result;
32074
+ const result = await runtime.prompt(options2);
32075
+ return this.#executions.cancellation(options2.sessionId) !== void 0 ? { stopReason: "cancelled" } : result;
32024
32076
  } catch (error62) {
32025
- if (this.#executions.cancellation(options.sessionId) !== void 0) {
32026
- await this.#executions.cancellation(options.sessionId);
32077
+ if (this.#executions.cancellation(options2.sessionId) !== void 0) {
32078
+ await this.#executions.cancellation(options2.sessionId);
32027
32079
  return { stopReason: "cancelled" };
32028
32080
  }
32029
32081
  throw error62;
32030
32082
  }
32031
32083
  } catch (error62) {
32032
- const failedRuntime = this.#executionProcesses.get(options.sessionId);
32084
+ const failedRuntime = this.#executionProcesses.get(options2.sessionId);
32033
32085
  if (failedRuntime !== void 0) {
32034
32086
  await this.#retireSessionProcess(
32035
- options.sessionId,
32087
+ options2.sessionId,
32036
32088
  failedRuntime,
32037
32089
  async () => await failedRuntime.close()
32038
32090
  );
32039
32091
  }
32040
- if (this.#executions.cancellation(options.sessionId) !== void 0) {
32092
+ if (this.#executions.cancellation(options2.sessionId) !== void 0) {
32041
32093
  return { stopReason: "cancelled" };
32042
32094
  }
32043
32095
  if (error62 instanceof AcpExecutionError) {
@@ -32048,14 +32100,14 @@ var AgentRuntimeManager = class {
32048
32100
  });
32049
32101
  } finally {
32050
32102
  try {
32051
- await this.#executions.cancellation(options.sessionId);
32103
+ await this.#executions.cancellation(options2.sessionId);
32052
32104
  } finally {
32053
- this.#executions.finish(options.sessionId, options.commandId);
32054
- this.#executionProcesses.touch(options.sessionId);
32105
+ this.#executions.finish(options2.sessionId, options2.commandId);
32106
+ this.#executionProcesses.touch(options2.sessionId);
32055
32107
  this.#processes.notifyChanged();
32056
32108
  }
32057
32109
  }
32058
- };
32110
+ });
32059
32111
  respondPermission = async (options) => {
32060
32112
  const runtime = this.#executionProcesses.get(options.sessionId);
32061
32113
  if (runtime === void 0) {
@@ -32070,7 +32122,7 @@ var AgentRuntimeManager = class {
32070
32122
  }
32071
32123
  await runtime.respondElicitation(options);
32072
32124
  };
32073
- close = async () => {
32125
+ close = async () => this.#operations.close(async () => {
32074
32126
  const sessions = [...this.#executionProcesses.entries()];
32075
32127
  await Promise.all([
32076
32128
  ...sessions.map(
@@ -32078,23 +32130,23 @@ var AgentRuntimeManager = class {
32078
32130
  ),
32079
32131
  this.#queryProcesses.close()
32080
32132
  ]);
32081
- };
32133
+ });
32082
32134
  findSessions = (sessionIds) => sessionIds.flatMap((sessionId) => {
32083
32135
  const stored = this.#store.read(sessionId);
32084
32136
  return stored instanceof FoundAcpStoredSession ? [stored.session] : [];
32085
32137
  });
32086
32138
  findLinkedSessions = (agentId, nativeSessionId) => this.#store.findNative(agentId, nativeSessionId);
32087
32139
  hasPreparedSession = (sessionId, agentId, cwd, additionalDirectories) => this.#executionProcesses.get(sessionId)?.belongsTo(agentId, cwd, additionalDirectories) === true;
32088
- createNativeSession = async (options) => {
32140
+ createNativeSession = async (options) => this.#operations.run(options, async (options2) => {
32089
32141
  const temporarySessionId = `new-${crypto.randomUUID()}`;
32090
- const temporaryOptions = { ...options, sessionId: temporarySessionId };
32142
+ const temporaryOptions = { ...options2, sessionId: temporarySessionId };
32091
32143
  return await this.#executionProcesses.use(temporarySessionId, async () => {
32092
32144
  try {
32093
32145
  const runtime = await this.#startPreparation(temporaryOptions);
32094
32146
  let adopted = false;
32095
32147
  try {
32096
32148
  const nativeSessionId = runtime.nativeSessionId();
32097
- if (!isNativeChatSessionId(options.agent.id, nativeSessionId) || this.#executionProcesses.get(nativeSessionId) !== void 0 || !(this.#store.read(nativeSessionId) instanceof MissingAcpStoredSession)) {
32149
+ if (!isNativeChatSessionId(options2.agent.id, nativeSessionId) || this.#executionProcesses.get(nativeSessionId) !== void 0 || !(this.#store.read(nativeSessionId) instanceof MissingAcpStoredSession)) {
32098
32150
  throw new AcpExecutionError(
32099
32151
  "The Agent returned an invalid new Session ID",
32100
32152
  {},
@@ -32120,36 +32172,36 @@ var AgentRuntimeManager = class {
32120
32172
  this.#store.remove(temporarySessionId);
32121
32173
  }
32122
32174
  });
32123
- };
32124
- ensureSession = async (options) => {
32125
- const existing = this.#executionProcesses.get(options.sessionId);
32175
+ });
32176
+ ensureSession = async (options) => this.#operations.run(options, async (options2) => {
32177
+ const existing = this.#executionProcesses.get(options2.sessionId);
32126
32178
  if (existing !== void 0) {
32127
- if (!existing.belongsTo(options.agent.id, options.cwd, options.additionalDirectories)) {
32179
+ if (!existing.belongsTo(options2.agent.id, options2.cwd, options2.additionalDirectories)) {
32128
32180
  throw new AcpExecutionError(
32129
32181
  "The agent or workspace cannot change after a conversation has started",
32130
32182
  {},
32131
32183
  "session_identity_mismatch"
32132
32184
  );
32133
32185
  }
32134
- this.#executionProcesses.touch(options.sessionId, existing);
32186
+ this.#executionProcesses.touch(options2.sessionId, existing);
32135
32187
  return existing;
32136
32188
  }
32137
- await this.prepareSession(options);
32138
- const started = this.#executionProcesses.get(options.sessionId);
32189
+ await this.prepareSession(options2);
32190
+ const started = this.#executionProcesses.get(options2.sessionId);
32139
32191
  if (started === void 0) {
32140
32192
  throw new AcpExecutionError("ACP session did not start");
32141
32193
  }
32142
32194
  return started;
32143
- };
32144
- listNativeSessions = async (options, cursor) => {
32195
+ });
32196
+ listNativeSessions = async (options, cursor) => this.#operations.run(options, async (options2) => {
32145
32197
  return await this.#queryProcesses.use(
32146
- options,
32147
- async (runtime) => await runtime.listNativeSessions(cursor, options.signal)
32198
+ options2,
32199
+ async (runtime) => await runtime.listNativeSessions(cursor, options2.signal)
32148
32200
  );
32149
- };
32150
- previewNativeSession = async (options, nativeSessionId) => {
32151
- const key = `${options.agent.id}:${nativeSessionId}`;
32152
- const linked = this.#store.findNative(options.agent.id, nativeSessionId);
32201
+ });
32202
+ previewNativeSession = async (options, nativeSessionId) => this.#operations.run(options, async (options2) => {
32203
+ const key = `${options2.agent.id}:${nativeSessionId}`;
32204
+ const linked = this.#store.findNative(options2.agent.id, nativeSessionId);
32153
32205
  if (this.#nativeOperations.has(key) || linked.some(
32154
32206
  (entry) => this.#executions.command(entry.sessionId) !== void 0 || this.#executionProcesses.pending(entry.sessionId) !== void 0
32155
32207
  )) {
@@ -32161,18 +32213,18 @@ var AgentRuntimeManager = class {
32161
32213
  }
32162
32214
  this.#nativeOperations.add(key);
32163
32215
  try {
32164
- return await this.#queryProcesses.preview(options, nativeSessionId);
32216
+ return await this.#queryProcesses.preview(options2, nativeSessionId);
32165
32217
  } finally {
32166
32218
  this.#nativeOperations.delete(key);
32167
32219
  }
32168
- };
32169
- loadSessionHistory = async (options) => {
32170
- return await this.#executionProcesses.use(options.sessionId, async () => {
32171
- const runtime = await this.ensureSession(options);
32172
- const stored = this.#store.read(options.sessionId);
32220
+ });
32221
+ loadSessionHistory = async (options) => this.#operations.run(options, async (options2) => {
32222
+ return await this.#executionProcesses.use(options2.sessionId, async () => {
32223
+ const runtime = await this.ensureSession(options2);
32224
+ const stored = this.#store.read(options2.sessionId);
32173
32225
  if (stored instanceof FoundAcpStoredSession && this.#nativeHistoryReader !== null) {
32174
32226
  const history = await this.#nativeHistoryReader.read(
32175
- options,
32227
+ options2,
32176
32228
  stored.session.nativeSessionId,
32177
32229
  runtime.nativeHistoryTurn
32178
32230
  );
@@ -32180,15 +32232,15 @@ var AgentRuntimeManager = class {
32180
32232
  return history;
32181
32233
  }
32182
32234
  }
32183
- return await runtime.loadHistory(options.signal);
32235
+ return await runtime.loadHistory(options2.signal);
32184
32236
  });
32185
- };
32186
- openNativeSession = async (options, origin) => {
32187
- const key = `${options.agent.id}:${origin.nativeSessionId}`;
32237
+ });
32238
+ openNativeSession = async (options, origin) => this.#operations.run(options, async (options2) => {
32239
+ const key = `${options2.agent.id}:${origin.nativeSessionId}`;
32188
32240
  if (this.#nativeOperations.has(key)) {
32189
32241
  throw new AcpExecutionError("The native session is being managed", {}, "session_busy");
32190
32242
  }
32191
- const linked = this.#store.findNative(options.agent.id, origin.nativeSessionId);
32243
+ const linked = this.#store.findNative(options2.agent.id, origin.nativeSessionId);
32192
32244
  if (linked.some(
32193
32245
  (entry) => this.#executions.command(entry.sessionId) !== void 0 || this.#executionProcesses.pending(entry.sessionId) !== void 0
32194
32246
  )) {
@@ -32202,7 +32254,7 @@ var AgentRuntimeManager = class {
32202
32254
  if (origin.kind === "import" && existing !== void 0) {
32203
32255
  return await this.#executionProcesses.use(existing.sessionId, async () => {
32204
32256
  const runtime = await this.ensureSession({
32205
- ...options,
32257
+ ...options2,
32206
32258
  sessionId: existing.sessionId
32207
32259
  });
32208
32260
  if (this.#executions.command(existing.sessionId) !== void 0 || this.#nativeOperations.has(key)) {
@@ -32224,18 +32276,22 @@ var AgentRuntimeManager = class {
32224
32276
  }
32225
32277
  });
32226
32278
  }
32227
- if (this.#executionProcesses.get(options.sessionId) !== void 0 || this.#executionProcesses.pending(options.sessionId) !== void 0 || this.#store.read(options.sessionId) instanceof FoundAcpStoredSession || this.#store.read(options.sessionId) instanceof DeletedAcpStoredSession) {
32228
- throw new AcpExecutionError("The destination conversation already exists", {}, "session_identity_mismatch");
32279
+ if (this.#executionProcesses.get(options2.sessionId) !== void 0 || this.#executionProcesses.pending(options2.sessionId) !== void 0 || this.#store.read(options2.sessionId) instanceof FoundAcpStoredSession || this.#store.read(options2.sessionId) instanceof DeletedAcpStoredSession) {
32280
+ throw new AcpExecutionError(
32281
+ "The destination conversation already exists",
32282
+ {},
32283
+ "session_identity_mismatch"
32284
+ );
32229
32285
  }
32230
- return await this.#executionProcesses.use(options.sessionId, async () => {
32286
+ return await this.#executionProcesses.use(options2.sessionId, async () => {
32231
32287
  this.#nativeOperations.add(key);
32232
32288
  try {
32233
- const runtime = await this.#startPreparation({ ...options, origin });
32234
- const openedKey = `${options.agent.id}:${runtime.nativeSessionId()}`;
32289
+ const runtime = await this.#startPreparation({ ...options2, origin });
32290
+ const openedKey = `${options2.agent.id}:${runtime.nativeSessionId()}`;
32235
32291
  this.#nativeOperations.add(openedKey);
32236
32292
  try {
32237
32293
  return {
32238
- sessionId: options.sessionId,
32294
+ sessionId: options2.sessionId,
32239
32295
  prepared: runtime.prepared()
32240
32296
  };
32241
32297
  } finally {
@@ -32243,11 +32299,11 @@ var AgentRuntimeManager = class {
32243
32299
  this.#processes.notifyChanged();
32244
32300
  }
32245
32301
  } catch (error62) {
32246
- this.#store.remove(options.sessionId);
32247
- const runtime = this.#executionProcesses.get(options.sessionId);
32302
+ this.#store.remove(options2.sessionId);
32303
+ const runtime = this.#executionProcesses.get(options2.sessionId);
32248
32304
  if (runtime !== void 0) {
32249
32305
  await this.#retireSessionProcess(
32250
- options.sessionId,
32306
+ options2.sessionId,
32251
32307
  runtime,
32252
32308
  async () => await runtime.closeProcess()
32253
32309
  );
@@ -32257,11 +32313,11 @@ var AgentRuntimeManager = class {
32257
32313
  this.#nativeOperations.delete(key);
32258
32314
  }
32259
32315
  });
32260
- };
32261
- deleteNativeSession = async (options, nativeSessionId) => {
32262
- return await this.#queryProcesses.use(options, async (runtime) => {
32263
- const key = `${options.agent.id}:${nativeSessionId}`;
32264
- const linked = this.#store.findNative(options.agent.id, nativeSessionId);
32316
+ });
32317
+ deleteNativeSession = async (options, nativeSessionId) => this.#operations.run(options, async (options2) => {
32318
+ return await this.#queryProcesses.use(options2, async (runtime) => {
32319
+ const key = `${options2.agent.id}:${nativeSessionId}`;
32320
+ const linked = this.#store.findNative(options2.agent.id, nativeSessionId);
32265
32321
  if (this.#nativeOperations.has(key) || linked.some(
32266
32322
  (entry) => this.#executions.command(entry.sessionId) !== void 0 || this.#executionProcesses.pending(entry.sessionId) !== void 0
32267
32323
  )) {
@@ -32279,11 +32335,11 @@ var AgentRuntimeManager = class {
32279
32335
  await this.#retireSessionProcess(entry.sessionId, active, async () => await active.close());
32280
32336
  }
32281
32337
  }
32282
- options.signal.throwIfAborted();
32283
- await runtime.deleteNativeSession(nativeSessionId, options.signal);
32284
- const deleted = this.#store.markDeleted(options.agent.id, nativeSessionId);
32338
+ options2.signal.throwIfAborted();
32339
+ await runtime.deleteNativeSession(nativeSessionId, options2.signal);
32340
+ const deleted = this.#store.markDeleted(options2.agent.id, nativeSessionId);
32285
32341
  if (runtime.nativeSessionId() === nativeSessionId) {
32286
- await this.#queryProcesses.retire(options.sessionId, runtime);
32342
+ await this.#queryProcesses.retire(options2.sessionId, runtime);
32287
32343
  }
32288
32344
  return deleted;
32289
32345
  } finally {
@@ -32291,7 +32347,7 @@ var AgentRuntimeManager = class {
32291
32347
  this.#processes.notifyChanged();
32292
32348
  }
32293
32349
  });
32294
- };
32350
+ });
32295
32351
  };
32296
32352
 
32297
32353
  // src/acp/run-prompt.ts
@@ -33506,11 +33562,8 @@ function agentMessageMeta(phase) {
33506
33562
  return { [CODEX_META_KEY]: { phase } };
33507
33563
  }
33508
33564
 
33509
- // src/acp/codex/agent.ts
33510
- var APPROVAL_REASON_CHARACTER_LIMIT = 500;
33565
+ // src/acp/codex/settings.ts
33511
33566
  var APPROVAL_TIMEOUT_MILLISECONDS = 36e5;
33512
- var CODEX_AGENT_VERSION = "0.154.0";
33513
- var SESSION_LIST_TIMEOUT_MILLISECONDS = 3e4;
33514
33567
  var MODEL_SETTING_ID = "model";
33515
33568
  var REASONING_EFFORT_SETTING_ID = "reasoning_effort";
33516
33569
  var MODE_SETTING_ID = "mode";
@@ -33519,7 +33572,6 @@ var COLLABORATION_MODE_SETTING_ID = "collaboration_mode";
33519
33572
  var MODEL_CATALOG_LIMIT = 1e3;
33520
33573
  var FAST_TIER = "fast";
33521
33574
  var SERVICE_TIER_FAST = "priority";
33522
- var CODEX_COMMANDS = Object.freeze([{ description: "Compact the conversation context", name: "compact" }]);
33523
33575
  var WORKSPACE_WRITE_POLICY = Object.freeze({
33524
33576
  excludeSlashTmp: false,
33525
33577
  excludeTmpdirEnvVar: false,
@@ -33563,94 +33615,6 @@ function initialMode(environment) {
33563
33615
  function capitalize(value) {
33564
33616
  return value.length === 0 ? value : value.charAt(0).toUpperCase() + value.slice(1);
33565
33617
  }
33566
- var APPROVAL_OPTIONS = Object.freeze([
33567
- { kind: "allow_once", name: "Allow once", optionId: "accept" },
33568
- { kind: "allow_always", name: "Allow for this session", optionId: "acceptForSession" },
33569
- { kind: "reject_once", name: "Deny", optionId: "decline" }
33570
- ]);
33571
- function permissionDecision(optionId) {
33572
- if (optionId === "accept" || optionId === "acceptForSession" || optionId === "decline") {
33573
- return optionId;
33574
- }
33575
- return "cancel";
33576
- }
33577
- function promptInput(prompt) {
33578
- const input2 = [];
33579
- for (const block of prompt) {
33580
- if (block.type === "text") {
33581
- input2.push({ text: block.text, text_elements: [], type: "text" });
33582
- continue;
33583
- }
33584
- if (block.type === "image") {
33585
- input2.push({ type: "image", url: `data:${block.mimeType};base64,${block.data}` });
33586
- continue;
33587
- }
33588
- if (block.type === "resource") {
33589
- const resource = block.resource;
33590
- input2.push({
33591
- text: "text" in resource ? resource.text ?? "" : "",
33592
- text_elements: [],
33593
- type: "text"
33594
- });
33595
- continue;
33596
- }
33597
- if (block.type === "resource_link") {
33598
- input2.push({ text: `Resource: ${block.uri}`, text_elements: [], type: "text" });
33599
- }
33600
- }
33601
- return input2;
33602
- }
33603
- function isCompactPrompt(prompt) {
33604
- return prompt.length === 1 && prompt[0]?.type === "text" && prompt[0].text.trim() === "/compact";
33605
- }
33606
- function steeringPromptInput(prompt) {
33607
- const input2 = [];
33608
- for (const block of prompt) {
33609
- if (typeof block !== "object" || block === null) {
33610
- throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
33611
- }
33612
- const type = Reflect.get(block, "type");
33613
- if (type === "text") {
33614
- const text2 = Reflect.get(block, "text");
33615
- if (typeof text2 !== "string") {
33616
- throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
33617
- }
33618
- input2.push({ text: text2, text_elements: [], type: "text" });
33619
- continue;
33620
- }
33621
- if (type === "image") {
33622
- const data = Reflect.get(block, "data");
33623
- const mimeType = Reflect.get(block, "mimeType");
33624
- if (typeof data !== "string" || typeof mimeType !== "string") {
33625
- throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
33626
- }
33627
- input2.push({ type: "image", url: `data:${mimeType};base64,${data}` });
33628
- continue;
33629
- }
33630
- if (type === "resource") {
33631
- const resource = Reflect.get(block, "resource");
33632
- if (typeof resource !== "object" || resource === null) {
33633
- throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
33634
- }
33635
- const text2 = Reflect.get(resource, "text");
33636
- if (text2 !== void 0 && typeof text2 !== "string") {
33637
- throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
33638
- }
33639
- input2.push({ text: text2 ?? "", text_elements: [], type: "text" });
33640
- continue;
33641
- }
33642
- if (type === "resource_link") {
33643
- const uri = Reflect.get(block, "uri");
33644
- if (typeof uri !== "string") {
33645
- throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
33646
- }
33647
- input2.push({ text: `Resource: ${uri}`, text_elements: [], type: "text" });
33648
- continue;
33649
- }
33650
- throw new AcpExecutionError("Codex received an unsupported steering prompt", {}, "invalid_request");
33651
- }
33652
- return input2;
33653
- }
33654
33618
  function modelValues(models) {
33655
33619
  return models.map((model) => ({
33656
33620
  description: model.description ?? "",
@@ -33755,34 +33719,9 @@ function effortSetting(model, currentValue) {
33755
33719
  type: "select"
33756
33720
  };
33757
33721
  }
33758
- function userInputSchema(questions) {
33759
- const properties = {};
33760
- const required2 = [];
33761
- for (const question of questions) {
33762
- required2.push(question.id);
33763
- properties[question.id] = {
33764
- description: question.question,
33765
- title: question.header,
33766
- type: "string",
33767
- ...question.options == null || question.options.length === 0 ? {} : {
33768
- oneOf: question.options.map((option) => ({
33769
- const: option.label,
33770
- description: option.description,
33771
- title: option.label
33772
- }))
33773
- }
33774
- };
33775
- }
33776
- return { properties, required: required2, type: "object" };
33777
- }
33778
- var CodexAcpAgent = class {
33779
- #app;
33722
+ var CodexSettings = class {
33780
33723
  #appServer;
33781
- terminated;
33782
- #closePromise = null;
33783
- #connection = null;
33784
33724
  #models = [];
33785
- #nativeSessionId = "";
33786
33725
  // Whether the current turn must carry a policy at all. Until the user picks a mode, Codex's own
33787
33726
  // configuration decides, so `turn/start` omits the fields and inherits what the host set up.
33788
33727
  #policySelected = false;
@@ -33794,185 +33733,64 @@ var CodexAcpAgent = class {
33794
33733
  // rather than break every turn.
33795
33734
  #collaborationModeSupported = null;
33796
33735
  #selection;
33797
- #streamedReasoningItemIds = /* @__PURE__ */ new Set();
33798
- #turn = null;
33799
- #nativeTurnId = null;
33800
- #updateTail = Promise.resolve();
33801
- constructor(options) {
33736
+ constructor(appServer, environment) {
33737
+ this.#appServer = appServer;
33802
33738
  this.#selection = {
33803
33739
  collaborationMode: "default",
33804
33740
  effort: "",
33805
33741
  fastMode: false,
33806
- mode: initialMode(options.environment),
33742
+ mode: initialMode(environment),
33807
33743
  model: ""
33808
33744
  };
33809
- this.#appServer = new CodexAppServerClient({
33810
- command: options.command,
33811
- cwd: options.cwd,
33812
- environment: options.environment,
33813
- handlers: {
33814
- onNotification: async (method, params) => {
33815
- await this.#onNotification(method, params);
33816
- },
33817
- onServerRequest: async (request) => {
33818
- await this.#onServerRequest(request);
33745
+ }
33746
+ selectNewThread = (created) => {
33747
+ const supported = supportedSelection(this.#models, created.model ?? "", created.reasoningEffort ?? "");
33748
+ this.#selection = {
33749
+ ...this.#selection,
33750
+ collaborationMode: "default",
33751
+ ...supported
33752
+ };
33753
+ this.#collaborationModeSelected = false;
33754
+ };
33755
+ observeCollaborationMode = (mode) => {
33756
+ if (mode === void 0 || mode === this.#selection.collaborationMode) {
33757
+ return false;
33758
+ }
33759
+ this.#selection = { ...this.#selection, collaborationMode: mode };
33760
+ return true;
33761
+ };
33762
+ turnParameters = () => {
33763
+ const selection = this.#selection;
33764
+ const mode = AGENT_MODES.find((candidate) => candidate.id === selection.mode) ?? DEFAULT_MODE;
33765
+ const supportsFast = this.#model(selection.model)?.additionalSpeedTiers?.includes(FAST_TIER) === true;
33766
+ return {
33767
+ // Until a mode is chosen, `config.toml` decides the sandbox and approval
33768
+ // policy, and those fields stay off the turn so the host's own setup is
33769
+ // inherited rather than overridden.
33770
+ ...this.#policySelected ? {
33771
+ approvalPolicy: mode.approvalPolicy,
33772
+ approvalsReviewer: mode.approvalsReviewer,
33773
+ sandboxPolicy: mode.sandboxPolicy
33774
+ } : {},
33775
+ // The collaboration mode rides on the turn: Codex applies it to the
33776
+ // thread, where it persists until changed. "Build" is Codex's `default`
33777
+ // mode, so it is only sent once a choice exists to apply.
33778
+ ...this.#collaborationModeSupported && (selection.collaborationMode !== "default" || this.#collaborationModeSelected) ? {
33779
+ collaborationMode: {
33780
+ mode: selection.collaborationMode,
33781
+ settings: {
33782
+ developer_instructions: null,
33783
+ model: selection.model,
33784
+ reasoning_effort: selection.effort.length === 0 ? null : selection.effort
33785
+ }
33819
33786
  }
33820
- }
33821
- });
33822
- this.terminated = this.#appServer.terminated;
33823
- void this.terminated.then((termination) => {
33824
- this.#turn?.completion.reject(acpEndpointTerminationError(termination));
33825
- if (termination.kind === "failed") {
33826
- void this.close().catch((cause) => {
33827
- console.error("The failed Codex endpoint could not release its process tree", cause);
33828
- });
33829
- }
33830
- });
33831
- this.#app = createAgentApp({ name: "mobius-codex" }).onConnect((connection) => {
33832
- this.#connection = connection;
33833
- }).onRequest(methods4.agent.initialize, async () => ({
33834
- _meta: { steering: { supported: true } },
33835
- agentCapabilities: {
33836
- loadSession: true,
33837
- promptCapabilities: { embeddedContext: true, image: true },
33838
- sessionCapabilities: { close: {}, fork: {}, list: {} }
33839
- },
33840
- agentInfo: { name: "Codex", version: CODEX_AGENT_VERSION },
33841
- authMethods: [],
33842
- protocolVersion: PROTOCOL_VERSION2
33843
- })).onRequest(methods4.agent.session.new, async (context) => {
33844
- const created = threadStartResponseSchema.parse(
33845
- await this.#appServer.request(
33846
- "thread/start",
33847
- { cwd: context.params.cwd },
33848
- AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
33849
- )
33850
- );
33851
- this.#nativeSessionId = created.thread.id;
33852
- const supported = supportedSelection(this.#models, created.model ?? "", created.reasoningEffort ?? "");
33853
- this.#selection = {
33854
- ...this.#selection,
33855
- collaborationMode: "default",
33856
- ...supported
33857
- };
33858
- this.#collaborationModeSelected = false;
33859
- await this.#probeCollaborationMode(context.signal);
33860
- await this.#emitAvailableCommands();
33861
- return { configOptions: this.#configOptions(), sessionId: created.thread.id };
33862
- }).onRequest(methods4.agent.session.setConfigOption, async (context) => {
33863
- this.#applySelection(context.params.configId, context.params.value);
33864
- return { configOptions: this.#configOptions() };
33865
- }).onRequest(methods4.agent.session.setMode, async (context) => {
33866
- this.#applySelection(MODE_SETTING_ID, context.params.modeId);
33867
- return {};
33868
- }).onRequest(methods4.agent.session.load, async (context) => {
33869
- const resumed = threadResumeResponseSchema.parse(
33870
- await this.#appServer.request(
33871
- "thread/resume",
33872
- { cwd: context.params.cwd, excludeTurns: false, threadId: context.params.sessionId },
33873
- AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
33874
- )
33875
- );
33876
- this.#selectRestoredThread(resumed);
33877
- await this.#probeCollaborationMode(context.signal);
33878
- await this.#replayHistory(resumed.turns);
33879
- await this.#emitAvailableCommands();
33880
- return { configOptions: this.#configOptions() };
33881
- }).onRequest(methods4.agent.session.fork, async (context) => {
33882
- const forked = threadForkResponseSchema.parse(
33883
- await this.#appServer.request(
33884
- "thread/fork",
33885
- {
33886
- cwd: context.params.cwd,
33887
- excludeTurns: false,
33888
- threadId: context.params.sessionId
33889
- },
33890
- AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
33891
- )
33892
- );
33893
- this.#selectRestoredThread(forked);
33894
- await this.#probeCollaborationMode(context.signal);
33895
- await this.#replayHistory(forked.turns);
33896
- await this.#emitAvailableCommands();
33897
- return { configOptions: this.#configOptions(), sessionId: forked.thread.id };
33898
- }).onRequest(methods4.agent.session.resume, async (context) => {
33899
- const resumed = threadResumeResponseSchema.parse(
33900
- await this.#appServer.request(
33901
- "thread/resume",
33902
- { cwd: context.params.cwd, excludeTurns: true, threadId: context.params.sessionId },
33903
- AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
33904
- )
33905
- );
33906
- this.#selectRestoredThread(resumed);
33907
- await this.#probeCollaborationMode(context.signal);
33908
- await this.#emitAvailableCommands();
33909
- return { configOptions: this.#configOptions() };
33910
- }).onRequest(methods4.agent.session.prompt, async (context) => {
33911
- if (isCompactPrompt(context.params.prompt)) {
33912
- return await this.#compact(context.signal);
33913
- }
33914
- return await this.#runTurn(promptInput(context.params.prompt), context.signal);
33915
- }).onRequest(
33916
- "_session/steering",
33917
- (params) => params,
33918
- async (context) => await this.#steerTurn(context.params, context.signal)
33919
- ).onRequest(methods4.agent.session.list, async (context) => {
33920
- const decoded = threadListResponseSchema.parse(
33921
- await this.#appServer.request(
33922
- "thread/list",
33923
- { cursor: context.params.cursor ?? null },
33924
- AbortSignal.any([context.signal, AbortSignal.timeout(SESSION_LIST_TIMEOUT_MILLISECONDS)])
33925
- )
33926
- );
33927
- return {
33928
- nextCursor: decoded.nextCursor ?? null,
33929
- sessions: decoded.data.map((thread) => ({
33930
- additionalDirectories: [],
33931
- cwd: thread.cwd,
33932
- sessionId: thread.id,
33933
- title: thread.name ?? thread.preview ?? null,
33934
- updatedAt: new Date(thread.updatedAt * 1e3).toISOString()
33935
- }))
33936
- };
33937
- }).onRequest(methods4.agent.session.close, async () => {
33938
- await this.#interruptTurn();
33939
- }).onNotification(methods4.agent.session.cancel, async () => {
33940
- await this.#interruptTurn();
33941
- });
33942
- }
33943
- /** The ACP agent app Mobius connects its own ACP client to, in-process. */
33944
- app = () => this.#app;
33945
- nativeTurnId = () => this.#nativeTurnId;
33946
- /** Starts the app-server, performs its handshake, and reads the model catalog Codex offers. */
33947
- initialize = async (signal) => {
33948
- await this.#appServer.initialize(signal);
33949
- await this.#loadModels(signal);
33950
- };
33951
- /**
33952
- * Releases the app-server and every process it started. Mirrors the adapter path's teardown so a
33953
- * cancelled or closed session cannot leak the tool subprocesses running under the app-server.
33954
- */
33955
- close = () => {
33956
- if (this.#closePromise === null) {
33957
- this.#appServer.detach();
33958
- this.#closePromise = (async () => {
33959
- const child = this.#appServer.child();
33960
- try {
33961
- const captured = await captureProcessTree(child);
33962
- await stopProcessTree(child, captured);
33963
- } finally {
33964
- this.#connection?.close();
33965
- }
33966
- })();
33967
- }
33968
- return this.#closePromise;
33787
+ } : {},
33788
+ ...selection.effort.length === 0 ? {} : { effort: selection.effort },
33789
+ ...selection.model.length === 0 ? {} : { model: selection.model },
33790
+ ...selection.fastMode && supportsFast ? { serviceTier: SERVICE_TIER_FAST } : {}
33791
+ };
33969
33792
  };
33970
- /**
33971
- * Reads the model catalog once per app-server. A failure leaves the catalog empty, which costs
33972
- * the Run settings panel its model selector; it must not cost the conversation itself, so the
33973
- * turn lifecycle continues without settings rather than failing initialization.
33974
- */
33975
- #loadModels = async (signal) => {
33793
+ loadModels = async (signal) => {
33976
33794
  const models = [];
33977
33795
  let cursor = null;
33978
33796
  try {
@@ -34000,14 +33818,14 @@ var CodexAcpAgent = class {
34000
33818
  * update is a no-op on a supporting Codex; an older Codex answers an error, which costs the
34001
33819
  * Build/Plan selector alone without changing a restored thread's persisted mode.
34002
33820
  */
34003
- #probeCollaborationMode = async (signal) => {
33821
+ probeCollaborationMode = async (threadId, signal) => {
34004
33822
  if (this.#collaborationModeSupported !== null) {
34005
33823
  return;
34006
33824
  }
34007
33825
  try {
34008
33826
  await this.#appServer.request(
34009
33827
  "thread/settings/update",
34010
- { threadId: this.#nativeSessionId },
33828
+ { threadId },
34011
33829
  AbortSignal.any([signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
34012
33830
  );
34013
33831
  this.#collaborationModeSupported = true;
@@ -34017,7 +33835,7 @@ var CodexAcpAgent = class {
34017
33835
  }
34018
33836
  };
34019
33837
  /** The ACP settings Mobius discovers and renders in Run settings. */
34020
- #configOptions = () => {
33838
+ configOptions = () => {
34021
33839
  const options = [];
34022
33840
  const model = modelSetting(this.#models, this.#selection.model);
34023
33841
  if (model !== null) {
@@ -34037,8 +33855,7 @@ var CodexAcpAgent = class {
34037
33855
  options.push(modeSetting(this.#selection.mode));
34038
33856
  return options;
34039
33857
  };
34040
- #selectRestoredThread = (thread) => {
34041
- this.#nativeSessionId = thread.thread.id;
33858
+ selectRestoredThread = (thread) => {
34042
33859
  const supported = supportedSelection(
34043
33860
  this.#models,
34044
33861
  thread.model ?? this.#selection.model,
@@ -34050,53 +33867,12 @@ var CodexAcpAgent = class {
34050
33867
  fastMode: thread.serviceTier === SERVICE_TIER_FAST
34051
33868
  };
34052
33869
  };
34053
- #replayHistory = async (turns) => {
34054
- for (const turn of turns ?? []) {
34055
- for (const rawItem of turn.items) {
34056
- const item = decodeThreadItem(rawItem);
34057
- if (item === null) {
34058
- continue;
34059
- }
34060
- if (item.type === "userMessage") {
34061
- const text2 = item.content.flatMap((content) => {
34062
- if (typeof content !== "object" || content === null) {
34063
- return [];
34064
- }
34065
- const type = Reflect.get(content, "type");
34066
- const text3 = Reflect.get(content, "text");
34067
- return type === "text" && typeof text3 === "string" ? [text3] : [];
34068
- }).join("");
34069
- if (text2.length > 0) {
34070
- await this.#emit({
34071
- content: { text: text2, type: "text" },
34072
- messageId: item.id,
34073
- sessionUpdate: "user_message_chunk"
34074
- });
34075
- }
34076
- continue;
34077
- }
34078
- if (item.type === "agentMessage") {
34079
- await this.#emit({
34080
- _meta: agentMessageMeta(item.phase),
34081
- content: { text: item.text, type: "text" },
34082
- messageId: item.id,
34083
- sessionUpdate: "agent_message_chunk"
34084
- });
34085
- continue;
34086
- }
34087
- const update = toolCallUpdate(item, "snapshot");
34088
- if (update !== null) {
34089
- await this.#emit({ ...update, sessionUpdate: "tool_call_update" });
34090
- }
34091
- }
34092
- }
34093
- };
34094
33870
  /**
34095
33871
  * Applies one `session/set_config_option`. Switching models re-resolves the effort the way Codex
34096
33872
  * does — the current effort when the new model supports it, otherwise the model's own default —
34097
33873
  * so the reply never advertises an effort the selected model cannot run.
34098
33874
  */
34099
- #applySelection = (configId, value) => {
33875
+ applySelection = (configId, value) => {
34100
33876
  if (configId === FAST_MODE_SETTING_ID) {
34101
33877
  if (typeof value !== "boolean") {
34102
33878
  throw new AcpExecutionError(
@@ -34180,6 +33956,340 @@ var CodexAcpAgent = class {
34180
33956
  }
34181
33957
  throw new AcpExecutionError("The requested Codex setting is unavailable", {}, "invalid_session_configuration");
34182
33958
  };
33959
+ };
33960
+
33961
+ // src/acp/codex/agent.ts
33962
+ var APPROVAL_REASON_CHARACTER_LIMIT = 500;
33963
+ var APPROVAL_TIMEOUT_MILLISECONDS2 = 36e5;
33964
+ var CODEX_AGENT_VERSION = "0.154.0";
33965
+ var SESSION_LIST_TIMEOUT_MILLISECONDS = 3e4;
33966
+ var CODEX_COMMANDS = Object.freeze([{ description: "Compact the conversation context", name: "compact" }]);
33967
+ var APPROVAL_OPTIONS = Object.freeze([
33968
+ { kind: "allow_once", name: "Allow once", optionId: "accept" },
33969
+ { kind: "allow_always", name: "Allow for this session", optionId: "acceptForSession" },
33970
+ { kind: "reject_once", name: "Deny", optionId: "decline" }
33971
+ ]);
33972
+ function permissionDecision(optionId) {
33973
+ if (optionId === "accept" || optionId === "acceptForSession" || optionId === "decline") {
33974
+ return optionId;
33975
+ }
33976
+ return "cancel";
33977
+ }
33978
+ function promptInput(prompt) {
33979
+ const input2 = [];
33980
+ for (const block of prompt) {
33981
+ if (block.type === "text") {
33982
+ input2.push({ text: block.text, text_elements: [], type: "text" });
33983
+ continue;
33984
+ }
33985
+ if (block.type === "image") {
33986
+ input2.push({ type: "image", url: `data:${block.mimeType};base64,${block.data}` });
33987
+ continue;
33988
+ }
33989
+ if (block.type === "resource") {
33990
+ const resource = block.resource;
33991
+ input2.push({
33992
+ text: "text" in resource ? resource.text ?? "" : "",
33993
+ text_elements: [],
33994
+ type: "text"
33995
+ });
33996
+ continue;
33997
+ }
33998
+ if (block.type === "resource_link") {
33999
+ input2.push({ text: `Resource: ${block.uri}`, text_elements: [], type: "text" });
34000
+ }
34001
+ }
34002
+ return input2;
34003
+ }
34004
+ function isCompactPrompt(prompt) {
34005
+ return prompt.length === 1 && prompt[0]?.type === "text" && prompt[0].text.trim() === "/compact";
34006
+ }
34007
+ function steeringPromptInput(prompt) {
34008
+ const input2 = [];
34009
+ for (const block of prompt) {
34010
+ if (typeof block !== "object" || block === null) {
34011
+ throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
34012
+ }
34013
+ const type = Reflect.get(block, "type");
34014
+ if (type === "text") {
34015
+ const text2 = Reflect.get(block, "text");
34016
+ if (typeof text2 !== "string") {
34017
+ throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
34018
+ }
34019
+ input2.push({ text: text2, text_elements: [], type: "text" });
34020
+ continue;
34021
+ }
34022
+ if (type === "image") {
34023
+ const data = Reflect.get(block, "data");
34024
+ const mimeType = Reflect.get(block, "mimeType");
34025
+ if (typeof data !== "string" || typeof mimeType !== "string") {
34026
+ throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
34027
+ }
34028
+ input2.push({ type: "image", url: `data:${mimeType};base64,${data}` });
34029
+ continue;
34030
+ }
34031
+ if (type === "resource") {
34032
+ const resource = Reflect.get(block, "resource");
34033
+ if (typeof resource !== "object" || resource === null) {
34034
+ throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
34035
+ }
34036
+ const text2 = Reflect.get(resource, "text");
34037
+ if (text2 !== void 0 && typeof text2 !== "string") {
34038
+ throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
34039
+ }
34040
+ input2.push({ text: text2 ?? "", text_elements: [], type: "text" });
34041
+ continue;
34042
+ }
34043
+ if (type === "resource_link") {
34044
+ const uri = Reflect.get(block, "uri");
34045
+ if (typeof uri !== "string") {
34046
+ throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
34047
+ }
34048
+ input2.push({ text: `Resource: ${uri}`, text_elements: [], type: "text" });
34049
+ continue;
34050
+ }
34051
+ throw new AcpExecutionError("Codex received an unsupported steering prompt", {}, "invalid_request");
34052
+ }
34053
+ return input2;
34054
+ }
34055
+ function userInputSchema(questions) {
34056
+ const properties = {};
34057
+ const required2 = [];
34058
+ for (const question of questions) {
34059
+ required2.push(question.id);
34060
+ properties[question.id] = {
34061
+ description: question.question,
34062
+ title: question.header,
34063
+ type: "string",
34064
+ ...question.options == null || question.options.length === 0 ? {} : {
34065
+ oneOf: question.options.map((option) => ({
34066
+ const: option.label,
34067
+ description: option.description,
34068
+ title: option.label
34069
+ }))
34070
+ }
34071
+ };
34072
+ }
34073
+ return { properties, required: required2, type: "object" };
34074
+ }
34075
+ var CodexAcpAgent = class {
34076
+ #app;
34077
+ #appServer;
34078
+ terminated;
34079
+ #closePromise = null;
34080
+ #connection = null;
34081
+ #settings;
34082
+ #nativeSessionId = "";
34083
+ #streamedReasoningItemIds = /* @__PURE__ */ new Set();
34084
+ #turn = null;
34085
+ #nativeTurnId = null;
34086
+ #updateTail = Promise.resolve();
34087
+ constructor(options) {
34088
+ this.#appServer = new CodexAppServerClient({
34089
+ command: options.command,
34090
+ cwd: options.cwd,
34091
+ environment: options.environment,
34092
+ handlers: {
34093
+ onNotification: async (method, params) => {
34094
+ await this.#onNotification(method, params);
34095
+ },
34096
+ onServerRequest: async (request) => {
34097
+ await this.#onServerRequest(request);
34098
+ }
34099
+ }
34100
+ });
34101
+ this.#settings = new CodexSettings(this.#appServer, options.environment);
34102
+ this.terminated = this.#appServer.terminated;
34103
+ void this.terminated.then((termination) => {
34104
+ this.#turn?.completion.reject(acpEndpointTerminationError(termination));
34105
+ if (termination.kind === "failed") {
34106
+ void this.close().catch((cause) => {
34107
+ console.error("The failed Codex endpoint could not release its process tree", cause);
34108
+ });
34109
+ }
34110
+ });
34111
+ this.#app = createAgentApp({ name: "mobius-codex" }).onConnect((connection) => {
34112
+ this.#connection = connection;
34113
+ }).onRequest(methods4.agent.initialize, async () => ({
34114
+ _meta: { steering: { supported: true } },
34115
+ agentCapabilities: {
34116
+ loadSession: true,
34117
+ promptCapabilities: { embeddedContext: true, image: true },
34118
+ sessionCapabilities: { close: {}, fork: {}, list: {} }
34119
+ },
34120
+ agentInfo: { name: "Codex", version: CODEX_AGENT_VERSION },
34121
+ authMethods: [],
34122
+ protocolVersion: PROTOCOL_VERSION2
34123
+ })).onRequest(methods4.agent.session.new, async (context) => {
34124
+ const created = threadStartResponseSchema.parse(
34125
+ await this.#appServer.request(
34126
+ "thread/start",
34127
+ { cwd: context.params.cwd },
34128
+ AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2)])
34129
+ )
34130
+ );
34131
+ this.#nativeSessionId = created.thread.id;
34132
+ this.#settings.selectNewThread(created);
34133
+ await this.#settings.probeCollaborationMode(this.#nativeSessionId, context.signal);
34134
+ await this.#emitAvailableCommands();
34135
+ return { configOptions: this.#settings.configOptions(), sessionId: created.thread.id };
34136
+ }).onRequest(methods4.agent.session.setConfigOption, async (context) => {
34137
+ this.#settings.applySelection(context.params.configId, context.params.value);
34138
+ return { configOptions: this.#settings.configOptions() };
34139
+ }).onRequest(methods4.agent.session.setMode, async (context) => {
34140
+ this.#settings.applySelection("mode", context.params.modeId);
34141
+ return {};
34142
+ }).onRequest(methods4.agent.session.load, async (context) => {
34143
+ const resumed = threadResumeResponseSchema.parse(
34144
+ await this.#appServer.request(
34145
+ "thread/resume",
34146
+ { cwd: context.params.cwd, excludeTurns: false, threadId: context.params.sessionId },
34147
+ AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2)])
34148
+ )
34149
+ );
34150
+ this.#nativeSessionId = resumed.thread.id;
34151
+ this.#settings.selectRestoredThread(resumed);
34152
+ await this.#settings.probeCollaborationMode(this.#nativeSessionId, context.signal);
34153
+ await this.#replayHistory(resumed.turns);
34154
+ await this.#emitAvailableCommands();
34155
+ return { configOptions: this.#settings.configOptions() };
34156
+ }).onRequest(methods4.agent.session.fork, async (context) => {
34157
+ const forked = threadForkResponseSchema.parse(
34158
+ await this.#appServer.request(
34159
+ "thread/fork",
34160
+ {
34161
+ cwd: context.params.cwd,
34162
+ excludeTurns: false,
34163
+ threadId: context.params.sessionId
34164
+ },
34165
+ AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2)])
34166
+ )
34167
+ );
34168
+ this.#nativeSessionId = forked.thread.id;
34169
+ this.#settings.selectRestoredThread(forked);
34170
+ await this.#settings.probeCollaborationMode(this.#nativeSessionId, context.signal);
34171
+ await this.#replayHistory(forked.turns);
34172
+ await this.#emitAvailableCommands();
34173
+ return { configOptions: this.#settings.configOptions(), sessionId: forked.thread.id };
34174
+ }).onRequest(methods4.agent.session.resume, async (context) => {
34175
+ const resumed = threadResumeResponseSchema.parse(
34176
+ await this.#appServer.request(
34177
+ "thread/resume",
34178
+ { cwd: context.params.cwd, excludeTurns: true, threadId: context.params.sessionId },
34179
+ AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2)])
34180
+ )
34181
+ );
34182
+ this.#nativeSessionId = resumed.thread.id;
34183
+ this.#settings.selectRestoredThread(resumed);
34184
+ await this.#settings.probeCollaborationMode(this.#nativeSessionId, context.signal);
34185
+ await this.#emitAvailableCommands();
34186
+ return { configOptions: this.#settings.configOptions() };
34187
+ }).onRequest(methods4.agent.session.prompt, async (context) => {
34188
+ if (isCompactPrompt(context.params.prompt)) {
34189
+ return await this.#compact(context.signal);
34190
+ }
34191
+ return await this.#runTurn(promptInput(context.params.prompt), context.signal);
34192
+ }).onRequest(
34193
+ "_session/steering",
34194
+ (params) => params,
34195
+ async (context) => await this.#steerTurn(context.params, context.signal)
34196
+ ).onRequest(methods4.agent.session.list, async (context) => {
34197
+ const decoded = threadListResponseSchema.parse(
34198
+ await this.#appServer.request(
34199
+ "thread/list",
34200
+ { cursor: context.params.cursor ?? null },
34201
+ AbortSignal.any([context.signal, AbortSignal.timeout(SESSION_LIST_TIMEOUT_MILLISECONDS)])
34202
+ )
34203
+ );
34204
+ return {
34205
+ nextCursor: decoded.nextCursor ?? null,
34206
+ sessions: decoded.data.map((thread) => ({
34207
+ additionalDirectories: [],
34208
+ cwd: thread.cwd,
34209
+ sessionId: thread.id,
34210
+ title: thread.name ?? thread.preview ?? null,
34211
+ updatedAt: new Date(thread.updatedAt * 1e3).toISOString()
34212
+ }))
34213
+ };
34214
+ }).onRequest(methods4.agent.session.close, async () => {
34215
+ await this.#interruptTurn();
34216
+ }).onNotification(methods4.agent.session.cancel, async () => {
34217
+ await this.#interruptTurn();
34218
+ });
34219
+ }
34220
+ /** The ACP agent app Mobius connects its own ACP client to, in-process. */
34221
+ app = () => this.#app;
34222
+ nativeTurnId = () => this.#nativeTurnId;
34223
+ /** Starts the app-server, performs its handshake, and reads the model catalog Codex offers. */
34224
+ initialize = async (signal) => {
34225
+ await this.#appServer.initialize(signal);
34226
+ await this.#settings.loadModels(signal);
34227
+ };
34228
+ /**
34229
+ * Releases the app-server and every process it started. Mirrors the adapter path's teardown so a
34230
+ * cancelled or closed session cannot leak the tool subprocesses running under the app-server.
34231
+ */
34232
+ close = () => {
34233
+ if (this.#closePromise === null) {
34234
+ this.#appServer.detach();
34235
+ this.#closePromise = (async () => {
34236
+ const child = this.#appServer.child();
34237
+ try {
34238
+ const captured = await captureProcessTree(child);
34239
+ await stopProcessTree(child, captured);
34240
+ } finally {
34241
+ this.#connection?.close();
34242
+ }
34243
+ })();
34244
+ }
34245
+ return this.#closePromise;
34246
+ };
34247
+ /**
34248
+ * Reads the model catalog once per app-server. A failure leaves the catalog empty, which costs
34249
+ * the Run settings panel its model selector; it must not cost the conversation itself, so the
34250
+ * turn lifecycle continues without settings rather than failing initialization.
34251
+ */
34252
+ #replayHistory = async (turns) => {
34253
+ for (const turn of turns ?? []) {
34254
+ for (const rawItem of turn.items) {
34255
+ const item = decodeThreadItem(rawItem);
34256
+ if (item === null) {
34257
+ continue;
34258
+ }
34259
+ if (item.type === "userMessage") {
34260
+ const text2 = item.content.flatMap((content) => {
34261
+ if (typeof content !== "object" || content === null) {
34262
+ return [];
34263
+ }
34264
+ const type = Reflect.get(content, "type");
34265
+ const text3 = Reflect.get(content, "text");
34266
+ return type === "text" && typeof text3 === "string" ? [text3] : [];
34267
+ }).join("");
34268
+ if (text2.length > 0) {
34269
+ await this.#emit({
34270
+ content: { text: text2, type: "text" },
34271
+ messageId: item.id,
34272
+ sessionUpdate: "user_message_chunk"
34273
+ });
34274
+ }
34275
+ continue;
34276
+ }
34277
+ if (item.type === "agentMessage") {
34278
+ await this.#emit({
34279
+ _meta: agentMessageMeta(item.phase),
34280
+ content: { text: item.text, type: "text" },
34281
+ messageId: item.id,
34282
+ sessionUpdate: "agent_message_chunk"
34283
+ });
34284
+ continue;
34285
+ }
34286
+ const update = toolCallUpdate(item, "snapshot");
34287
+ if (update !== null) {
34288
+ await this.#emit({ ...update, sessionUpdate: "tool_call_update" });
34289
+ }
34290
+ }
34291
+ }
34292
+ };
34183
34293
  #emit = async (update) => {
34184
34294
  const connection = this.#connection;
34185
34295
  if (connection === null || this.#nativeSessionId.length === 0) {
@@ -34204,7 +34314,7 @@ var CodexAcpAgent = class {
34204
34314
  }
34205
34315
  await connection.client.notify(methods4.client.session.update, {
34206
34316
  sessionId: this.#nativeSessionId,
34207
- update: { configOptions: this.#configOptions(), sessionUpdate: "config_option_update" }
34317
+ update: { configOptions: this.#settings.configOptions(), sessionUpdate: "config_option_update" }
34208
34318
  });
34209
34319
  };
34210
34320
  // Notifications are serialized so two app-server items cannot interleave into one ACP update
@@ -34244,8 +34354,7 @@ var CodexAcpAgent = class {
34244
34354
  const decoded = threadSettingsUpdatedSchema.safeParse(params);
34245
34355
  if (decoded.success && decoded.data.threadId === this.#nativeSessionId) {
34246
34356
  const mode = decoded.data.threadSettings.collaborationMode?.mode;
34247
- if (mode !== void 0 && mode !== this.#selection.collaborationMode) {
34248
- this.#selection = { ...this.#selection, collaborationMode: mode };
34357
+ if (this.#settings.observeCollaborationMode(mode)) {
34249
34358
  await this.#enqueue(async () => {
34250
34359
  await this.#emitConfigOptionsUpdate();
34251
34360
  });
@@ -34367,7 +34476,7 @@ var CodexAcpAgent = class {
34367
34476
  const decision = await this.#askPermission(
34368
34477
  title2,
34369
34478
  params.itemId,
34370
- AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)
34479
+ AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2)
34371
34480
  );
34372
34481
  void turn;
34373
34482
  this.#appServer.respond(request.id, { decision });
@@ -34389,7 +34498,7 @@ var CodexAcpAgent = class {
34389
34498
  sessionId: this.#nativeSessionId,
34390
34499
  ...decoded.data.itemId == null ? {} : { toolCallId: decoded.data.itemId }
34391
34500
  },
34392
- { cancellationSignal: AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS) }
34501
+ { cancellationSignal: AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2) }
34393
34502
  );
34394
34503
  const content = response.action === "accept" ? Reflect.get(response, "content") : void 0;
34395
34504
  const answers = {};
@@ -34407,7 +34516,7 @@ var CodexAcpAgent = class {
34407
34516
  return;
34408
34517
  }
34409
34518
  const params = decoded.data;
34410
- const signal = AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS);
34519
+ const signal = AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2);
34411
34520
  if (params.mode === "url" && params.url !== void 0) {
34412
34521
  const response2 = await connection.client.request(
34413
34522
  methods4.client.elicitation.create,
@@ -34456,38 +34565,12 @@ var CodexAcpAgent = class {
34456
34565
  this.#turn = turn;
34457
34566
  this.#nativeTurnId = null;
34458
34567
  try {
34459
- const selection = this.#selection;
34460
- const mode = AGENT_MODES.find((candidate) => candidate.id === selection.mode) ?? DEFAULT_MODE;
34461
- const supportsFast = this.#model(selection.model)?.additionalSpeedTiers?.includes(FAST_TIER) === true;
34462
34568
  const started = turnSchema.parse(
34463
34569
  (await this.#appServer.request(
34464
34570
  "turn/start",
34465
34571
  {
34466
- // Until a mode is chosen, `config.toml` decides the sandbox and approval
34467
- // policy, and those fields stay off the turn so the host's own setup is
34468
- // inherited rather than overridden.
34469
- ...this.#policySelected ? {
34470
- approvalPolicy: mode.approvalPolicy,
34471
- approvalsReviewer: mode.approvalsReviewer,
34472
- sandboxPolicy: mode.sandboxPolicy
34473
- } : {},
34474
- // The collaboration mode rides on the turn: Codex applies it to the
34475
- // thread, where it persists until changed. "Build" is Codex's `default`
34476
- // mode, so it is only sent once a choice exists to apply.
34477
- ...this.#collaborationModeSupported && (selection.collaborationMode !== "default" || this.#collaborationModeSelected) ? {
34478
- collaborationMode: {
34479
- mode: selection.collaborationMode,
34480
- settings: {
34481
- developer_instructions: null,
34482
- model: selection.model,
34483
- reasoning_effort: selection.effort.length === 0 ? null : selection.effort
34484
- }
34485
- }
34486
- } : {},
34487
- ...selection.effort.length === 0 ? {} : { effort: selection.effort },
34572
+ ...this.#settings.turnParameters(),
34488
34573
  input: input2,
34489
- ...selection.model.length === 0 ? {} : { model: selection.model },
34490
- ...selection.fastMode && supportsFast ? { serviceTier: SERVICE_TIER_FAST } : {},
34491
34574
  threadId: this.#nativeSessionId
34492
34575
  },
34493
34576
  signal
@@ -34556,7 +34639,7 @@ var CodexAcpAgent = class {
34556
34639
  await this.#appServer.request(
34557
34640
  "turn/steer",
34558
34641
  { expectedTurnId: active.turn.id, input: input2, threadId: this.#nativeSessionId },
34559
- AbortSignal.any([signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
34642
+ AbortSignal.any([signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2)])
34560
34643
  )
34561
34644
  );
34562
34645
  if (response.turnId !== active.turn.id) {
@@ -34575,7 +34658,7 @@ var CodexAcpAgent = class {
34575
34658
  await this.#appServer.request(
34576
34659
  "turn/interrupt",
34577
34660
  { threadId: this.#nativeSessionId, turnId: turn.turn.id },
34578
- AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)
34661
+ AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2)
34579
34662
  );
34580
34663
  } catch {
34581
34664
  }