@moxt-ai/mobius 0.0.131 → 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