@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/runtime.js CHANGED
@@ -23465,11 +23465,8 @@ function agentMessageMeta(phase) {
23465
23465
  return { [CODEX_META_KEY]: { phase } };
23466
23466
  }
23467
23467
 
23468
- // src/acp/codex/agent.ts
23469
- var APPROVAL_REASON_CHARACTER_LIMIT = 500;
23468
+ // src/acp/codex/settings.ts
23470
23469
  var APPROVAL_TIMEOUT_MILLISECONDS = 36e5;
23471
- var CODEX_AGENT_VERSION = "0.154.0";
23472
- var SESSION_LIST_TIMEOUT_MILLISECONDS = 3e4;
23473
23470
  var MODEL_SETTING_ID = "model";
23474
23471
  var REASONING_EFFORT_SETTING_ID = "reasoning_effort";
23475
23472
  var MODE_SETTING_ID = "mode";
@@ -23478,7 +23475,6 @@ var COLLABORATION_MODE_SETTING_ID = "collaboration_mode";
23478
23475
  var MODEL_CATALOG_LIMIT = 1e3;
23479
23476
  var FAST_TIER = "fast";
23480
23477
  var SERVICE_TIER_FAST = "priority";
23481
- var CODEX_COMMANDS = Object.freeze([{ description: "Compact the conversation context", name: "compact" }]);
23482
23478
  var WORKSPACE_WRITE_POLICY = Object.freeze({
23483
23479
  excludeSlashTmp: false,
23484
23480
  excludeTmpdirEnvVar: false,
@@ -23522,94 +23518,6 @@ function initialMode(environment) {
23522
23518
  function capitalize(value) {
23523
23519
  return value.length === 0 ? value : value.charAt(0).toUpperCase() + value.slice(1);
23524
23520
  }
23525
- var APPROVAL_OPTIONS = Object.freeze([
23526
- { kind: "allow_once", name: "Allow once", optionId: "accept" },
23527
- { kind: "allow_always", name: "Allow for this session", optionId: "acceptForSession" },
23528
- { kind: "reject_once", name: "Deny", optionId: "decline" }
23529
- ]);
23530
- function permissionDecision(optionId) {
23531
- if (optionId === "accept" || optionId === "acceptForSession" || optionId === "decline") {
23532
- return optionId;
23533
- }
23534
- return "cancel";
23535
- }
23536
- function promptInput(prompt) {
23537
- const input2 = [];
23538
- for (const block of prompt) {
23539
- if (block.type === "text") {
23540
- input2.push({ text: block.text, text_elements: [], type: "text" });
23541
- continue;
23542
- }
23543
- if (block.type === "image") {
23544
- input2.push({ type: "image", url: `data:${block.mimeType};base64,${block.data}` });
23545
- continue;
23546
- }
23547
- if (block.type === "resource") {
23548
- const resource = block.resource;
23549
- input2.push({
23550
- text: "text" in resource ? resource.text ?? "" : "",
23551
- text_elements: [],
23552
- type: "text"
23553
- });
23554
- continue;
23555
- }
23556
- if (block.type === "resource_link") {
23557
- input2.push({ text: `Resource: ${block.uri}`, text_elements: [], type: "text" });
23558
- }
23559
- }
23560
- return input2;
23561
- }
23562
- function isCompactPrompt(prompt) {
23563
- return prompt.length === 1 && prompt[0]?.type === "text" && prompt[0].text.trim() === "/compact";
23564
- }
23565
- function steeringPromptInput(prompt) {
23566
- const input2 = [];
23567
- for (const block of prompt) {
23568
- if (typeof block !== "object" || block === null) {
23569
- throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
23570
- }
23571
- const type = Reflect.get(block, "type");
23572
- if (type === "text") {
23573
- const text2 = Reflect.get(block, "text");
23574
- if (typeof text2 !== "string") {
23575
- throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
23576
- }
23577
- input2.push({ text: text2, text_elements: [], type: "text" });
23578
- continue;
23579
- }
23580
- if (type === "image") {
23581
- const data = Reflect.get(block, "data");
23582
- const mimeType = Reflect.get(block, "mimeType");
23583
- if (typeof data !== "string" || typeof mimeType !== "string") {
23584
- throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
23585
- }
23586
- input2.push({ type: "image", url: `data:${mimeType};base64,${data}` });
23587
- continue;
23588
- }
23589
- if (type === "resource") {
23590
- const resource = Reflect.get(block, "resource");
23591
- if (typeof resource !== "object" || resource === null) {
23592
- throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
23593
- }
23594
- const text2 = Reflect.get(resource, "text");
23595
- if (text2 !== void 0 && typeof text2 !== "string") {
23596
- throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
23597
- }
23598
- input2.push({ text: text2 ?? "", text_elements: [], type: "text" });
23599
- continue;
23600
- }
23601
- if (type === "resource_link") {
23602
- const uri = Reflect.get(block, "uri");
23603
- if (typeof uri !== "string") {
23604
- throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
23605
- }
23606
- input2.push({ text: `Resource: ${uri}`, text_elements: [], type: "text" });
23607
- continue;
23608
- }
23609
- throw new AcpExecutionError("Codex received an unsupported steering prompt", {}, "invalid_request");
23610
- }
23611
- return input2;
23612
- }
23613
23521
  function modelValues(models) {
23614
23522
  return models.map((model) => ({
23615
23523
  description: model.description ?? "",
@@ -23714,6 +23622,339 @@ function effortSetting(model, currentValue) {
23714
23622
  type: "select"
23715
23623
  };
23716
23624
  }
23625
+ var CodexSettings = class {
23626
+ #appServer;
23627
+ #models = [];
23628
+ // Whether the current turn must carry a policy at all. Until the user picks a mode, Codex's own
23629
+ // configuration decides, so `turn/start` omits the fields and inherits what the host set up.
23630
+ #policySelected = false;
23631
+ // Whether a collaboration mode choice has been made in this session. A restored thread keeps
23632
+ // the mode Codex already persisted, so the first turn does not reset it to Build.
23633
+ #collaborationModeSelected = false;
23634
+ // Whether the app-server accepts collaboration mode on `turn/start`, probed once per
23635
+ // app-server. An older Codex rejects the experimental field, and the setting must disappear
23636
+ // rather than break every turn.
23637
+ #collaborationModeSupported = null;
23638
+ #selection;
23639
+ constructor(appServer, environment) {
23640
+ this.#appServer = appServer;
23641
+ this.#selection = {
23642
+ collaborationMode: "default",
23643
+ effort: "",
23644
+ fastMode: false,
23645
+ mode: initialMode(environment),
23646
+ model: ""
23647
+ };
23648
+ }
23649
+ selectNewThread = (created) => {
23650
+ const supported = supportedSelection(this.#models, created.model ?? "", created.reasoningEffort ?? "");
23651
+ this.#selection = {
23652
+ ...this.#selection,
23653
+ collaborationMode: "default",
23654
+ ...supported
23655
+ };
23656
+ this.#collaborationModeSelected = false;
23657
+ };
23658
+ observeCollaborationMode = (mode) => {
23659
+ if (mode === void 0 || mode === this.#selection.collaborationMode) {
23660
+ return false;
23661
+ }
23662
+ this.#selection = { ...this.#selection, collaborationMode: mode };
23663
+ return true;
23664
+ };
23665
+ turnParameters = () => {
23666
+ const selection = this.#selection;
23667
+ const mode = AGENT_MODES.find((candidate) => candidate.id === selection.mode) ?? DEFAULT_MODE;
23668
+ const supportsFast = this.#model(selection.model)?.additionalSpeedTiers?.includes(FAST_TIER) === true;
23669
+ return {
23670
+ // Until a mode is chosen, `config.toml` decides the sandbox and approval
23671
+ // policy, and those fields stay off the turn so the host's own setup is
23672
+ // inherited rather than overridden.
23673
+ ...this.#policySelected ? {
23674
+ approvalPolicy: mode.approvalPolicy,
23675
+ approvalsReviewer: mode.approvalsReviewer,
23676
+ sandboxPolicy: mode.sandboxPolicy
23677
+ } : {},
23678
+ // The collaboration mode rides on the turn: Codex applies it to the
23679
+ // thread, where it persists until changed. "Build" is Codex's `default`
23680
+ // mode, so it is only sent once a choice exists to apply.
23681
+ ...this.#collaborationModeSupported && (selection.collaborationMode !== "default" || this.#collaborationModeSelected) ? {
23682
+ collaborationMode: {
23683
+ mode: selection.collaborationMode,
23684
+ settings: {
23685
+ developer_instructions: null,
23686
+ model: selection.model,
23687
+ reasoning_effort: selection.effort.length === 0 ? null : selection.effort
23688
+ }
23689
+ }
23690
+ } : {},
23691
+ ...selection.effort.length === 0 ? {} : { effort: selection.effort },
23692
+ ...selection.model.length === 0 ? {} : { model: selection.model },
23693
+ ...selection.fastMode && supportsFast ? { serviceTier: SERVICE_TIER_FAST } : {}
23694
+ };
23695
+ };
23696
+ loadModels = async (signal) => {
23697
+ const models = [];
23698
+ let cursor = null;
23699
+ try {
23700
+ do {
23701
+ const decoded = modelListResponseSchema.parse(
23702
+ await this.#appServer.request(
23703
+ "model/list",
23704
+ { cursor, limit: null },
23705
+ AbortSignal.any([signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
23706
+ )
23707
+ );
23708
+ models.push(...decoded.data);
23709
+ cursor = decoded.nextCursor ?? null;
23710
+ } while (cursor !== null && models.length < MODEL_CATALOG_LIMIT);
23711
+ } catch (error62) {
23712
+ signal.throwIfAborted();
23713
+ process.stderr.write(`[codex-acp] model catalog unavailable: ${String(error62)}
23714
+ `);
23715
+ }
23716
+ this.#models = Object.freeze(models.slice(0, MODEL_CATALOG_LIMIT));
23717
+ };
23718
+ #model = (id) => this.#models.find((model) => model.id === id);
23719
+ /**
23720
+ * Learns, once per app-server, whether collaboration mode can be applied. An empty settings
23721
+ * update is a no-op on a supporting Codex; an older Codex answers an error, which costs the
23722
+ * Build/Plan selector alone without changing a restored thread's persisted mode.
23723
+ */
23724
+ probeCollaborationMode = async (threadId, signal) => {
23725
+ if (this.#collaborationModeSupported !== null) {
23726
+ return;
23727
+ }
23728
+ try {
23729
+ await this.#appServer.request(
23730
+ "thread/settings/update",
23731
+ { threadId },
23732
+ AbortSignal.any([signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
23733
+ );
23734
+ this.#collaborationModeSupported = true;
23735
+ } catch {
23736
+ signal.throwIfAborted();
23737
+ this.#collaborationModeSupported = false;
23738
+ }
23739
+ };
23740
+ /** The ACP settings Mobius discovers and renders in Run settings. */
23741
+ configOptions = () => {
23742
+ const options = [];
23743
+ const model = modelSetting(this.#models, this.#selection.model);
23744
+ if (model !== null) {
23745
+ options.push(model);
23746
+ }
23747
+ const effort = effortSetting(this.#model(this.#selection.model), this.#selection.effort);
23748
+ if (effort !== null) {
23749
+ options.push(effort);
23750
+ }
23751
+ const fastMode = fastModeSetting(this.#model(this.#selection.model), this.#selection.fastMode);
23752
+ if (fastMode !== null) {
23753
+ options.push(fastMode);
23754
+ }
23755
+ if (this.#collaborationModeSupported === true) {
23756
+ options.push(collaborationModeSetting(this.#selection.collaborationMode));
23757
+ }
23758
+ options.push(modeSetting(this.#selection.mode));
23759
+ return options;
23760
+ };
23761
+ selectRestoredThread = (thread) => {
23762
+ const supported = supportedSelection(
23763
+ this.#models,
23764
+ thread.model ?? this.#selection.model,
23765
+ thread.reasoningEffort ?? this.#selection.effort
23766
+ );
23767
+ this.#selection = {
23768
+ ...this.#selection,
23769
+ ...supported,
23770
+ fastMode: thread.serviceTier === SERVICE_TIER_FAST
23771
+ };
23772
+ };
23773
+ /**
23774
+ * Applies one `session/set_config_option`. Switching models re-resolves the effort the way Codex
23775
+ * does — the current effort when the new model supports it, otherwise the model's own default —
23776
+ * so the reply never advertises an effort the selected model cannot run.
23777
+ */
23778
+ applySelection = (configId, value) => {
23779
+ if (configId === FAST_MODE_SETTING_ID) {
23780
+ if (typeof value !== "boolean") {
23781
+ throw new AcpExecutionError(
23782
+ "The requested Codex setting is invalid",
23783
+ {},
23784
+ "invalid_session_configuration"
23785
+ );
23786
+ }
23787
+ if (value && this.#model(this.#selection.model)?.additionalSpeedTiers?.includes(FAST_TIER) !== true) {
23788
+ throw new AcpExecutionError(
23789
+ "The selected Codex model has no fast mode",
23790
+ {},
23791
+ "invalid_session_configuration"
23792
+ );
23793
+ }
23794
+ this.#selection = { ...this.#selection, fastMode: value };
23795
+ return;
23796
+ }
23797
+ if (typeof value !== "string") {
23798
+ throw new AcpExecutionError("The requested Codex setting is invalid", {}, "invalid_session_configuration");
23799
+ }
23800
+ if (configId === MODE_SETTING_ID) {
23801
+ if (!AGENT_MODES.some((mode) => mode.id === value)) {
23802
+ throw new AcpExecutionError(
23803
+ "The requested Codex mode is unavailable",
23804
+ {},
23805
+ "invalid_session_configuration"
23806
+ );
23807
+ }
23808
+ this.#selection = { ...this.#selection, mode: value };
23809
+ this.#policySelected = true;
23810
+ return;
23811
+ }
23812
+ if (configId === COLLABORATION_MODE_SETTING_ID) {
23813
+ if (!COLLABORATION_MODES.some((mode) => mode.value === value)) {
23814
+ throw new AcpExecutionError(
23815
+ "The requested Codex collaboration mode is unavailable",
23816
+ {},
23817
+ "invalid_session_configuration"
23818
+ );
23819
+ }
23820
+ this.#selection = { ...this.#selection, collaborationMode: value };
23821
+ this.#collaborationModeSelected = true;
23822
+ return;
23823
+ }
23824
+ if (configId === MODEL_SETTING_ID) {
23825
+ if (value === this.#selection.model) {
23826
+ return;
23827
+ }
23828
+ const model = this.#model(value);
23829
+ if (model === void 0) {
23830
+ throw new AcpExecutionError(
23831
+ "The requested Codex model is unavailable",
23832
+ {},
23833
+ "invalid_session_configuration"
23834
+ );
23835
+ }
23836
+ const supported = (model.supportedReasoningEfforts ?? []).map((option) => option.reasoningEffort);
23837
+ const effort = supported.includes(this.#selection.effort) ? this.#selection.effort : model.defaultReasoningEffort ?? supported[0] ?? "";
23838
+ this.#selection = {
23839
+ ...this.#selection,
23840
+ effort,
23841
+ fastMode: this.#selection.fastMode && model.additionalSpeedTiers?.includes(FAST_TIER) === true,
23842
+ model: value
23843
+ };
23844
+ return;
23845
+ }
23846
+ if (configId === REASONING_EFFORT_SETTING_ID) {
23847
+ const supported = (this.#model(this.#selection.model)?.supportedReasoningEfforts ?? []).map(
23848
+ (option) => option.reasoningEffort
23849
+ );
23850
+ if (!supported.includes(value)) {
23851
+ throw new AcpExecutionError(
23852
+ "The requested Codex reasoning effort is unavailable",
23853
+ {},
23854
+ "invalid_session_configuration"
23855
+ );
23856
+ }
23857
+ this.#selection = { ...this.#selection, effort: value };
23858
+ return;
23859
+ }
23860
+ throw new AcpExecutionError("The requested Codex setting is unavailable", {}, "invalid_session_configuration");
23861
+ };
23862
+ };
23863
+
23864
+ // src/acp/codex/agent.ts
23865
+ var APPROVAL_REASON_CHARACTER_LIMIT = 500;
23866
+ var APPROVAL_TIMEOUT_MILLISECONDS2 = 36e5;
23867
+ var CODEX_AGENT_VERSION = "0.154.0";
23868
+ var SESSION_LIST_TIMEOUT_MILLISECONDS = 3e4;
23869
+ var CODEX_COMMANDS = Object.freeze([{ description: "Compact the conversation context", name: "compact" }]);
23870
+ var APPROVAL_OPTIONS = Object.freeze([
23871
+ { kind: "allow_once", name: "Allow once", optionId: "accept" },
23872
+ { kind: "allow_always", name: "Allow for this session", optionId: "acceptForSession" },
23873
+ { kind: "reject_once", name: "Deny", optionId: "decline" }
23874
+ ]);
23875
+ function permissionDecision(optionId) {
23876
+ if (optionId === "accept" || optionId === "acceptForSession" || optionId === "decline") {
23877
+ return optionId;
23878
+ }
23879
+ return "cancel";
23880
+ }
23881
+ function promptInput(prompt) {
23882
+ const input2 = [];
23883
+ for (const block of prompt) {
23884
+ if (block.type === "text") {
23885
+ input2.push({ text: block.text, text_elements: [], type: "text" });
23886
+ continue;
23887
+ }
23888
+ if (block.type === "image") {
23889
+ input2.push({ type: "image", url: `data:${block.mimeType};base64,${block.data}` });
23890
+ continue;
23891
+ }
23892
+ if (block.type === "resource") {
23893
+ const resource = block.resource;
23894
+ input2.push({
23895
+ text: "text" in resource ? resource.text ?? "" : "",
23896
+ text_elements: [],
23897
+ type: "text"
23898
+ });
23899
+ continue;
23900
+ }
23901
+ if (block.type === "resource_link") {
23902
+ input2.push({ text: `Resource: ${block.uri}`, text_elements: [], type: "text" });
23903
+ }
23904
+ }
23905
+ return input2;
23906
+ }
23907
+ function isCompactPrompt(prompt) {
23908
+ return prompt.length === 1 && prompt[0]?.type === "text" && prompt[0].text.trim() === "/compact";
23909
+ }
23910
+ function steeringPromptInput(prompt) {
23911
+ const input2 = [];
23912
+ for (const block of prompt) {
23913
+ if (typeof block !== "object" || block === null) {
23914
+ throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
23915
+ }
23916
+ const type = Reflect.get(block, "type");
23917
+ if (type === "text") {
23918
+ const text2 = Reflect.get(block, "text");
23919
+ if (typeof text2 !== "string") {
23920
+ throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
23921
+ }
23922
+ input2.push({ text: text2, text_elements: [], type: "text" });
23923
+ continue;
23924
+ }
23925
+ if (type === "image") {
23926
+ const data = Reflect.get(block, "data");
23927
+ const mimeType = Reflect.get(block, "mimeType");
23928
+ if (typeof data !== "string" || typeof mimeType !== "string") {
23929
+ throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
23930
+ }
23931
+ input2.push({ type: "image", url: `data:${mimeType};base64,${data}` });
23932
+ continue;
23933
+ }
23934
+ if (type === "resource") {
23935
+ const resource = Reflect.get(block, "resource");
23936
+ if (typeof resource !== "object" || resource === null) {
23937
+ throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
23938
+ }
23939
+ const text2 = Reflect.get(resource, "text");
23940
+ if (text2 !== void 0 && typeof text2 !== "string") {
23941
+ throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
23942
+ }
23943
+ input2.push({ text: text2 ?? "", text_elements: [], type: "text" });
23944
+ continue;
23945
+ }
23946
+ if (type === "resource_link") {
23947
+ const uri = Reflect.get(block, "uri");
23948
+ if (typeof uri !== "string") {
23949
+ throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
23950
+ }
23951
+ input2.push({ text: `Resource: ${uri}`, text_elements: [], type: "text" });
23952
+ continue;
23953
+ }
23954
+ throw new AcpExecutionError("Codex received an unsupported steering prompt", {}, "invalid_request");
23955
+ }
23956
+ return input2;
23957
+ }
23717
23958
  function userInputSchema(questions) {
23718
23959
  const properties = {};
23719
23960
  const required2 = [];
@@ -23740,31 +23981,13 @@ var CodexAcpAgent = class {
23740
23981
  terminated;
23741
23982
  #closePromise = null;
23742
23983
  #connection = null;
23743
- #models = [];
23744
- #nativeSessionId = "";
23745
- // Whether the current turn must carry a policy at all. Until the user picks a mode, Codex's own
23746
- // configuration decides, so `turn/start` omits the fields and inherits what the host set up.
23747
- #policySelected = false;
23748
- // Whether a collaboration mode choice has been made in this session. A restored thread keeps
23749
- // the mode Codex already persisted, so the first turn does not reset it to Build.
23750
- #collaborationModeSelected = false;
23751
- // Whether the app-server accepts collaboration mode on `turn/start`, probed once per
23752
- // app-server. An older Codex rejects the experimental field, and the setting must disappear
23753
- // rather than break every turn.
23754
- #collaborationModeSupported = null;
23755
- #selection;
23984
+ #settings;
23985
+ #nativeSessionId = "";
23756
23986
  #streamedReasoningItemIds = /* @__PURE__ */ new Set();
23757
23987
  #turn = null;
23758
23988
  #nativeTurnId = null;
23759
23989
  #updateTail = Promise.resolve();
23760
23990
  constructor(options) {
23761
- this.#selection = {
23762
- collaborationMode: "default",
23763
- effort: "",
23764
- fastMode: false,
23765
- mode: initialMode(options.environment),
23766
- model: ""
23767
- };
23768
23991
  this.#appServer = new CodexAppServerClient({
23769
23992
  command: options.command,
23770
23993
  cwd: options.cwd,
@@ -23778,6 +24001,7 @@ var CodexAcpAgent = class {
23778
24001
  }
23779
24002
  }
23780
24003
  });
24004
+ this.#settings = new CodexSettings(this.#appServer, options.environment);
23781
24005
  this.terminated = this.#appServer.terminated;
23782
24006
  void this.terminated.then((termination) => {
23783
24007
  this.#turn?.completion.reject(acpEndpointTerminationError(termination));
@@ -23804,39 +24028,34 @@ var CodexAcpAgent = class {
23804
24028
  await this.#appServer.request(
23805
24029
  "thread/start",
23806
24030
  { cwd: context.params.cwd },
23807
- AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
24031
+ AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2)])
23808
24032
  )
23809
24033
  );
23810
24034
  this.#nativeSessionId = created.thread.id;
23811
- const supported = supportedSelection(this.#models, created.model ?? "", created.reasoningEffort ?? "");
23812
- this.#selection = {
23813
- ...this.#selection,
23814
- collaborationMode: "default",
23815
- ...supported
23816
- };
23817
- this.#collaborationModeSelected = false;
23818
- await this.#probeCollaborationMode(context.signal);
24035
+ this.#settings.selectNewThread(created);
24036
+ await this.#settings.probeCollaborationMode(this.#nativeSessionId, context.signal);
23819
24037
  await this.#emitAvailableCommands();
23820
- return { configOptions: this.#configOptions(), sessionId: created.thread.id };
24038
+ return { configOptions: this.#settings.configOptions(), sessionId: created.thread.id };
23821
24039
  }).onRequest(methods.agent.session.setConfigOption, async (context) => {
23822
- this.#applySelection(context.params.configId, context.params.value);
23823
- return { configOptions: this.#configOptions() };
24040
+ this.#settings.applySelection(context.params.configId, context.params.value);
24041
+ return { configOptions: this.#settings.configOptions() };
23824
24042
  }).onRequest(methods.agent.session.setMode, async (context) => {
23825
- this.#applySelection(MODE_SETTING_ID, context.params.modeId);
24043
+ this.#settings.applySelection("mode", context.params.modeId);
23826
24044
  return {};
23827
24045
  }).onRequest(methods.agent.session.load, async (context) => {
23828
24046
  const resumed = threadResumeResponseSchema.parse(
23829
24047
  await this.#appServer.request(
23830
24048
  "thread/resume",
23831
24049
  { cwd: context.params.cwd, excludeTurns: false, threadId: context.params.sessionId },
23832
- AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
24050
+ AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2)])
23833
24051
  )
23834
24052
  );
23835
- this.#selectRestoredThread(resumed);
23836
- await this.#probeCollaborationMode(context.signal);
24053
+ this.#nativeSessionId = resumed.thread.id;
24054
+ this.#settings.selectRestoredThread(resumed);
24055
+ await this.#settings.probeCollaborationMode(this.#nativeSessionId, context.signal);
23837
24056
  await this.#replayHistory(resumed.turns);
23838
24057
  await this.#emitAvailableCommands();
23839
- return { configOptions: this.#configOptions() };
24058
+ return { configOptions: this.#settings.configOptions() };
23840
24059
  }).onRequest(methods.agent.session.fork, async (context) => {
23841
24060
  const forked = threadForkResponseSchema.parse(
23842
24061
  await this.#appServer.request(
@@ -23846,26 +24065,28 @@ var CodexAcpAgent = class {
23846
24065
  excludeTurns: false,
23847
24066
  threadId: context.params.sessionId
23848
24067
  },
23849
- AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
24068
+ AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2)])
23850
24069
  )
23851
24070
  );
23852
- this.#selectRestoredThread(forked);
23853
- await this.#probeCollaborationMode(context.signal);
24071
+ this.#nativeSessionId = forked.thread.id;
24072
+ this.#settings.selectRestoredThread(forked);
24073
+ await this.#settings.probeCollaborationMode(this.#nativeSessionId, context.signal);
23854
24074
  await this.#replayHistory(forked.turns);
23855
24075
  await this.#emitAvailableCommands();
23856
- return { configOptions: this.#configOptions(), sessionId: forked.thread.id };
24076
+ return { configOptions: this.#settings.configOptions(), sessionId: forked.thread.id };
23857
24077
  }).onRequest(methods.agent.session.resume, async (context) => {
23858
24078
  const resumed = threadResumeResponseSchema.parse(
23859
24079
  await this.#appServer.request(
23860
24080
  "thread/resume",
23861
24081
  { cwd: context.params.cwd, excludeTurns: true, threadId: context.params.sessionId },
23862
- AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
24082
+ AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2)])
23863
24083
  )
23864
24084
  );
23865
- this.#selectRestoredThread(resumed);
23866
- await this.#probeCollaborationMode(context.signal);
24085
+ this.#nativeSessionId = resumed.thread.id;
24086
+ this.#settings.selectRestoredThread(resumed);
24087
+ await this.#settings.probeCollaborationMode(this.#nativeSessionId, context.signal);
23867
24088
  await this.#emitAvailableCommands();
23868
- return { configOptions: this.#configOptions() };
24089
+ return { configOptions: this.#settings.configOptions() };
23869
24090
  }).onRequest(methods.agent.session.prompt, async (context) => {
23870
24091
  if (isCompactPrompt(context.params.prompt)) {
23871
24092
  return await this.#compact(context.signal);
@@ -23905,7 +24126,7 @@ var CodexAcpAgent = class {
23905
24126
  /** Starts the app-server, performs its handshake, and reads the model catalog Codex offers. */
23906
24127
  initialize = async (signal) => {
23907
24128
  await this.#appServer.initialize(signal);
23908
- await this.#loadModels(signal);
24129
+ await this.#settings.loadModels(signal);
23909
24130
  };
23910
24131
  /**
23911
24132
  * Releases the app-server and every process it started. Mirrors the adapter path's teardown so a
@@ -23931,84 +24152,6 @@ var CodexAcpAgent = class {
23931
24152
  * the Run settings panel its model selector; it must not cost the conversation itself, so the
23932
24153
  * turn lifecycle continues without settings rather than failing initialization.
23933
24154
  */
23934
- #loadModels = async (signal) => {
23935
- const models = [];
23936
- let cursor = null;
23937
- try {
23938
- do {
23939
- const decoded = modelListResponseSchema.parse(
23940
- await this.#appServer.request(
23941
- "model/list",
23942
- { cursor, limit: null },
23943
- AbortSignal.any([signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
23944
- )
23945
- );
23946
- models.push(...decoded.data);
23947
- cursor = decoded.nextCursor ?? null;
23948
- } while (cursor !== null && models.length < MODEL_CATALOG_LIMIT);
23949
- } catch (error62) {
23950
- signal.throwIfAborted();
23951
- process.stderr.write(`[codex-acp] model catalog unavailable: ${String(error62)}
23952
- `);
23953
- }
23954
- this.#models = Object.freeze(models.slice(0, MODEL_CATALOG_LIMIT));
23955
- };
23956
- #model = (id) => this.#models.find((model) => model.id === id);
23957
- /**
23958
- * Learns, once per app-server, whether collaboration mode can be applied. An empty settings
23959
- * update is a no-op on a supporting Codex; an older Codex answers an error, which costs the
23960
- * Build/Plan selector alone without changing a restored thread's persisted mode.
23961
- */
23962
- #probeCollaborationMode = async (signal) => {
23963
- if (this.#collaborationModeSupported !== null) {
23964
- return;
23965
- }
23966
- try {
23967
- await this.#appServer.request(
23968
- "thread/settings/update",
23969
- { threadId: this.#nativeSessionId },
23970
- AbortSignal.any([signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
23971
- );
23972
- this.#collaborationModeSupported = true;
23973
- } catch {
23974
- signal.throwIfAborted();
23975
- this.#collaborationModeSupported = false;
23976
- }
23977
- };
23978
- /** The ACP settings Mobius discovers and renders in Run settings. */
23979
- #configOptions = () => {
23980
- const options = [];
23981
- const model = modelSetting(this.#models, this.#selection.model);
23982
- if (model !== null) {
23983
- options.push(model);
23984
- }
23985
- const effort = effortSetting(this.#model(this.#selection.model), this.#selection.effort);
23986
- if (effort !== null) {
23987
- options.push(effort);
23988
- }
23989
- const fastMode = fastModeSetting(this.#model(this.#selection.model), this.#selection.fastMode);
23990
- if (fastMode !== null) {
23991
- options.push(fastMode);
23992
- }
23993
- if (this.#collaborationModeSupported === true) {
23994
- options.push(collaborationModeSetting(this.#selection.collaborationMode));
23995
- }
23996
- options.push(modeSetting(this.#selection.mode));
23997
- return options;
23998
- };
23999
- #selectRestoredThread = (thread) => {
24000
- this.#nativeSessionId = thread.thread.id;
24001
- const supported = supportedSelection(
24002
- this.#models,
24003
- thread.model ?? this.#selection.model,
24004
- thread.reasoningEffort ?? this.#selection.effort
24005
- );
24006
- this.#selection = {
24007
- ...this.#selection,
24008
- ...supported,
24009
- fastMode: thread.serviceTier === SERVICE_TIER_FAST
24010
- };
24011
- };
24012
24155
  #replayHistory = async (turns) => {
24013
24156
  for (const turn of turns ?? []) {
24014
24157
  for (const rawItem of turn.items) {
@@ -24050,95 +24193,6 @@ var CodexAcpAgent = class {
24050
24193
  }
24051
24194
  }
24052
24195
  };
24053
- /**
24054
- * Applies one `session/set_config_option`. Switching models re-resolves the effort the way Codex
24055
- * does — the current effort when the new model supports it, otherwise the model's own default —
24056
- * so the reply never advertises an effort the selected model cannot run.
24057
- */
24058
- #applySelection = (configId, value) => {
24059
- if (configId === FAST_MODE_SETTING_ID) {
24060
- if (typeof value !== "boolean") {
24061
- throw new AcpExecutionError(
24062
- "The requested Codex setting is invalid",
24063
- {},
24064
- "invalid_session_configuration"
24065
- );
24066
- }
24067
- if (value && this.#model(this.#selection.model)?.additionalSpeedTiers?.includes(FAST_TIER) !== true) {
24068
- throw new AcpExecutionError(
24069
- "The selected Codex model has no fast mode",
24070
- {},
24071
- "invalid_session_configuration"
24072
- );
24073
- }
24074
- this.#selection = { ...this.#selection, fastMode: value };
24075
- return;
24076
- }
24077
- if (typeof value !== "string") {
24078
- throw new AcpExecutionError("The requested Codex setting is invalid", {}, "invalid_session_configuration");
24079
- }
24080
- if (configId === MODE_SETTING_ID) {
24081
- if (!AGENT_MODES.some((mode) => mode.id === value)) {
24082
- throw new AcpExecutionError(
24083
- "The requested Codex mode is unavailable",
24084
- {},
24085
- "invalid_session_configuration"
24086
- );
24087
- }
24088
- this.#selection = { ...this.#selection, mode: value };
24089
- this.#policySelected = true;
24090
- return;
24091
- }
24092
- if (configId === COLLABORATION_MODE_SETTING_ID) {
24093
- if (!COLLABORATION_MODES.some((mode) => mode.value === value)) {
24094
- throw new AcpExecutionError(
24095
- "The requested Codex collaboration mode is unavailable",
24096
- {},
24097
- "invalid_session_configuration"
24098
- );
24099
- }
24100
- this.#selection = { ...this.#selection, collaborationMode: value };
24101
- this.#collaborationModeSelected = true;
24102
- return;
24103
- }
24104
- if (configId === MODEL_SETTING_ID) {
24105
- if (value === this.#selection.model) {
24106
- return;
24107
- }
24108
- const model = this.#model(value);
24109
- if (model === void 0) {
24110
- throw new AcpExecutionError(
24111
- "The requested Codex model is unavailable",
24112
- {},
24113
- "invalid_session_configuration"
24114
- );
24115
- }
24116
- const supported = (model.supportedReasoningEfforts ?? []).map((option) => option.reasoningEffort);
24117
- const effort = supported.includes(this.#selection.effort) ? this.#selection.effort : model.defaultReasoningEffort ?? supported[0] ?? "";
24118
- this.#selection = {
24119
- ...this.#selection,
24120
- effort,
24121
- fastMode: this.#selection.fastMode && model.additionalSpeedTiers?.includes(FAST_TIER) === true,
24122
- model: value
24123
- };
24124
- return;
24125
- }
24126
- if (configId === REASONING_EFFORT_SETTING_ID) {
24127
- const supported = (this.#model(this.#selection.model)?.supportedReasoningEfforts ?? []).map(
24128
- (option) => option.reasoningEffort
24129
- );
24130
- if (!supported.includes(value)) {
24131
- throw new AcpExecutionError(
24132
- "The requested Codex reasoning effort is unavailable",
24133
- {},
24134
- "invalid_session_configuration"
24135
- );
24136
- }
24137
- this.#selection = { ...this.#selection, effort: value };
24138
- return;
24139
- }
24140
- throw new AcpExecutionError("The requested Codex setting is unavailable", {}, "invalid_session_configuration");
24141
- };
24142
24196
  #emit = async (update) => {
24143
24197
  const connection = this.#connection;
24144
24198
  if (connection === null || this.#nativeSessionId.length === 0) {
@@ -24163,7 +24217,7 @@ var CodexAcpAgent = class {
24163
24217
  }
24164
24218
  await connection.client.notify(methods.client.session.update, {
24165
24219
  sessionId: this.#nativeSessionId,
24166
- update: { configOptions: this.#configOptions(), sessionUpdate: "config_option_update" }
24220
+ update: { configOptions: this.#settings.configOptions(), sessionUpdate: "config_option_update" }
24167
24221
  });
24168
24222
  };
24169
24223
  // Notifications are serialized so two app-server items cannot interleave into one ACP update
@@ -24203,8 +24257,7 @@ var CodexAcpAgent = class {
24203
24257
  const decoded = threadSettingsUpdatedSchema.safeParse(params);
24204
24258
  if (decoded.success && decoded.data.threadId === this.#nativeSessionId) {
24205
24259
  const mode = decoded.data.threadSettings.collaborationMode?.mode;
24206
- if (mode !== void 0 && mode !== this.#selection.collaborationMode) {
24207
- this.#selection = { ...this.#selection, collaborationMode: mode };
24260
+ if (this.#settings.observeCollaborationMode(mode)) {
24208
24261
  await this.#enqueue(async () => {
24209
24262
  await this.#emitConfigOptionsUpdate();
24210
24263
  });
@@ -24326,7 +24379,7 @@ var CodexAcpAgent = class {
24326
24379
  const decision = await this.#askPermission(
24327
24380
  title2,
24328
24381
  params.itemId,
24329
- AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)
24382
+ AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2)
24330
24383
  );
24331
24384
  void turn;
24332
24385
  this.#appServer.respond(request.id, { decision });
@@ -24348,7 +24401,7 @@ var CodexAcpAgent = class {
24348
24401
  sessionId: this.#nativeSessionId,
24349
24402
  ...decoded.data.itemId == null ? {} : { toolCallId: decoded.data.itemId }
24350
24403
  },
24351
- { cancellationSignal: AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS) }
24404
+ { cancellationSignal: AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2) }
24352
24405
  );
24353
24406
  const content = response.action === "accept" ? Reflect.get(response, "content") : void 0;
24354
24407
  const answers = {};
@@ -24366,7 +24419,7 @@ var CodexAcpAgent = class {
24366
24419
  return;
24367
24420
  }
24368
24421
  const params = decoded.data;
24369
- const signal = AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS);
24422
+ const signal = AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2);
24370
24423
  if (params.mode === "url" && params.url !== void 0) {
24371
24424
  const response2 = await connection.client.request(
24372
24425
  methods.client.elicitation.create,
@@ -24415,38 +24468,12 @@ var CodexAcpAgent = class {
24415
24468
  this.#turn = turn;
24416
24469
  this.#nativeTurnId = null;
24417
24470
  try {
24418
- const selection = this.#selection;
24419
- const mode = AGENT_MODES.find((candidate) => candidate.id === selection.mode) ?? DEFAULT_MODE;
24420
- const supportsFast = this.#model(selection.model)?.additionalSpeedTiers?.includes(FAST_TIER) === true;
24421
24471
  const started = turnSchema.parse(
24422
24472
  (await this.#appServer.request(
24423
24473
  "turn/start",
24424
24474
  {
24425
- // Until a mode is chosen, `config.toml` decides the sandbox and approval
24426
- // policy, and those fields stay off the turn so the host's own setup is
24427
- // inherited rather than overridden.
24428
- ...this.#policySelected ? {
24429
- approvalPolicy: mode.approvalPolicy,
24430
- approvalsReviewer: mode.approvalsReviewer,
24431
- sandboxPolicy: mode.sandboxPolicy
24432
- } : {},
24433
- // The collaboration mode rides on the turn: Codex applies it to the
24434
- // thread, where it persists until changed. "Build" is Codex's `default`
24435
- // mode, so it is only sent once a choice exists to apply.
24436
- ...this.#collaborationModeSupported && (selection.collaborationMode !== "default" || this.#collaborationModeSelected) ? {
24437
- collaborationMode: {
24438
- mode: selection.collaborationMode,
24439
- settings: {
24440
- developer_instructions: null,
24441
- model: selection.model,
24442
- reasoning_effort: selection.effort.length === 0 ? null : selection.effort
24443
- }
24444
- }
24445
- } : {},
24446
- ...selection.effort.length === 0 ? {} : { effort: selection.effort },
24475
+ ...this.#settings.turnParameters(),
24447
24476
  input: input2,
24448
- ...selection.model.length === 0 ? {} : { model: selection.model },
24449
- ...selection.fastMode && supportsFast ? { serviceTier: SERVICE_TIER_FAST } : {},
24450
24477
  threadId: this.#nativeSessionId
24451
24478
  },
24452
24479
  signal
@@ -24515,7 +24542,7 @@ var CodexAcpAgent = class {
24515
24542
  await this.#appServer.request(
24516
24543
  "turn/steer",
24517
24544
  { expectedTurnId: active.turn.id, input: input2, threadId: this.#nativeSessionId },
24518
- AbortSignal.any([signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
24545
+ AbortSignal.any([signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2)])
24519
24546
  )
24520
24547
  );
24521
24548
  if (response.turnId !== active.turn.id) {
@@ -24534,7 +24561,7 @@ var CodexAcpAgent = class {
24534
24561
  await this.#appServer.request(
24535
24562
  "turn/interrupt",
24536
24563
  { threadId: this.#nativeSessionId, turnId: turn.turn.id },
24537
- AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)
24564
+ AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2)
24538
24565
  );
24539
24566
  } catch {
24540
24567
  }
@@ -35416,6 +35443,48 @@ var RetainedAgentProcesses = class {
35416
35443
  };
35417
35444
  };
35418
35445
 
35446
+ // src/acp/runtime-operations.ts
35447
+ var RuntimeOperations = class {
35448
+ #shutdown = new AbortController();
35449
+ #pending = /* @__PURE__ */ new Set();
35450
+ #closing = null;
35451
+ run = async (options, operation) => {
35452
+ const signal = AbortSignal.any([options.signal, this.#shutdown.signal]);
35453
+ signal.throwIfAborted();
35454
+ const pending = Promise.resolve().then(() => operation({ ...options, signal }));
35455
+ this.#pending.add(pending);
35456
+ try {
35457
+ const result = await pending;
35458
+ signal.throwIfAborted();
35459
+ return result;
35460
+ } finally {
35461
+ this.#pending.delete(pending);
35462
+ }
35463
+ };
35464
+ close = (release) => {
35465
+ if (this.#closing !== null) {
35466
+ return this.#closing;
35467
+ }
35468
+ this.#shutdown.abort();
35469
+ this.#closing = (async () => {
35470
+ await Promise.allSettled([...this.#pending]);
35471
+ await release();
35472
+ })();
35473
+ return this.#closing;
35474
+ };
35475
+ };
35476
+ async function waitForPreparation(pending, signal) {
35477
+ signal.throwIfAborted();
35478
+ const cancelled = Promise.withResolvers();
35479
+ const abort = () => cancelled.reject(signal.reason);
35480
+ signal.addEventListener("abort", abort, { once: true });
35481
+ try {
35482
+ return await Promise.race([pending, cancelled.promise]);
35483
+ } finally {
35484
+ signal.removeEventListener("abort", abort);
35485
+ }
35486
+ }
35487
+
35419
35488
  // src/acp/agent-query-processes.ts
35420
35489
  var AgentQueryProcesses = class {
35421
35490
  #processesByQuery;
@@ -35462,7 +35531,7 @@ var AgentQueryProcesses = class {
35462
35531
  prepare = async (options) => {
35463
35532
  const pending = this.#processesByQuery.pending(options.sessionId);
35464
35533
  if (pending !== void 0) {
35465
- const runtime2 = await pending;
35534
+ const runtime2 = await waitForPreparation(pending, options.signal);
35466
35535
  if (runtime2.belongsTo(options.agent.id, options.cwd, options.additionalDirectories)) {
35467
35536
  this.#processesByQuery.touch(options.sessionId, runtime2);
35468
35537
  return runtime2.prepared();
@@ -35741,6 +35810,7 @@ var AgentProcessPool = class {
35741
35810
  // src/acp/agent-runtime-manager.ts
35742
35811
  var SESSION_CONTROL_TIMEOUT_MILLISECONDS = 3e4;
35743
35812
  var AgentRuntimeManager = class {
35813
+ #operations = new RuntimeOperations();
35744
35814
  #processes = new AgentProcessPool();
35745
35815
  #executionProcesses = new RetainedAgentProcesses({
35746
35816
  touch: this.#processes.touch,
@@ -35863,8 +35933,8 @@ var AgentRuntimeManager = class {
35863
35933
  return runtime;
35864
35934
  });
35865
35935
  }
35866
- prepareSession = async (options, metrics = unmeasuredOperationMetrics) => {
35867
- const stored = metrics.measureSync("session-state-read", () => this.#store.read(options.sessionId));
35936
+ prepareSession = async (options, metrics = unmeasuredOperationMetrics) => this.#operations.run(options, async (options2) => {
35937
+ const stored = metrics.measureSync("session-state-read", () => this.#store.read(options2.sessionId));
35868
35938
  if (stored instanceof DeletedAcpStoredSession) {
35869
35939
  throw new AcpExecutionError(
35870
35940
  "The native Agent session was deleted. Start a new chat.",
@@ -35875,19 +35945,22 @@ var AgentRuntimeManager = class {
35875
35945
  if (stored instanceof FoundAcpStoredSession && this.#nativeOperations.has(`${stored.session.agentId}:${stored.session.nativeSessionId}`)) {
35876
35946
  throw new AcpExecutionError("The native session is being managed", {}, "session_busy");
35877
35947
  }
35878
- const pending = this.#executionProcesses.pending(options.sessionId);
35948
+ const pending = this.#executionProcesses.pending(options2.sessionId);
35879
35949
  if (pending !== void 0) {
35880
- const runtime2 = await metrics.measure("session-preparation-wait", async () => await pending);
35881
- if (runtime2.belongsTo(options.agent.id, options.cwd, options.additionalDirectories)) {
35882
- this.#executionProcesses.touch(options.sessionId, runtime2);
35950
+ const runtime2 = await metrics.measure(
35951
+ "session-preparation-wait",
35952
+ async () => await waitForPreparation(pending, options2.signal)
35953
+ );
35954
+ if (runtime2.belongsTo(options2.agent.id, options2.cwd, options2.additionalDirectories)) {
35955
+ this.#executionProcesses.touch(options2.sessionId, runtime2);
35883
35956
  return runtime2.prepared();
35884
35957
  }
35885
- return await this.prepareSession(options, metrics);
35958
+ return await this.prepareSession(options2, metrics);
35886
35959
  }
35887
- const existing = this.#executionProcesses.get(options.sessionId);
35960
+ const existing = this.#executionProcesses.get(options2.sessionId);
35888
35961
  if (existing !== void 0) {
35889
- if (existing.belongsTo(options.agent.id, options.cwd, options.additionalDirectories)) {
35890
- this.#executionProcesses.touch(options.sessionId, existing);
35962
+ if (existing.belongsTo(options2.agent.id, options2.cwd, options2.additionalDirectories)) {
35963
+ this.#executionProcesses.touch(options2.sessionId, existing);
35891
35964
  return existing.prepared();
35892
35965
  }
35893
35966
  if (!existing.canRebind()) {
@@ -35897,85 +35970,91 @@ var AgentRuntimeManager = class {
35897
35970
  "session_identity_mismatch"
35898
35971
  );
35899
35972
  }
35900
- const runtime2 = await this.#replacePreparation(existing, options, metrics);
35973
+ const runtime2 = await this.#replacePreparation(existing, options2, metrics);
35901
35974
  return runtime2.prepared();
35902
35975
  }
35903
- const runtime = await this.#startPreparation(options, metrics);
35976
+ const runtime = await this.#startPreparation(options2, metrics);
35904
35977
  return runtime.prepared();
35905
- };
35978
+ });
35906
35979
  /**
35907
35980
  * Opens a short-lived native ACP session only to read the local Agent's
35908
35981
  * authoritative settings. Its identity and store are private to this
35909
35982
  * operation and never become a Mobius Session.
35910
35983
  */
35911
- inspectAgentSettings = async (options) => await this.#processes.runTransient(
35912
- options.signal,
35913
- async () => await AgentSession.start(
35914
- {
35915
- ...options,
35916
- sessionId: `agent-settings-${crypto.randomUUID()}`
35984
+ inspectAgentSettings = async (options) => this.#operations.run(options, async (options2) => {
35985
+ return await this.#processes.runTransient(
35986
+ options2.signal,
35987
+ async () => await AgentSession.start(
35988
+ {
35989
+ ...options2,
35990
+ sessionId: `agent-settings-${crypto.randomUUID()}`
35991
+ },
35992
+ () => this.#agentSettingsObserver,
35993
+ new MemoryAcpSessionStore()
35994
+ ),
35995
+ async (runtime) => {
35996
+ const prepared = runtime.prepared();
35997
+ const model = options2.model;
35998
+ const configOptions = model === void 0 ? prepared.configOptions : await runtime.configure({
35999
+ ...options2,
36000
+ booleanValue: false,
36001
+ configId: prepared.configOptions.find(
36002
+ (option) => option.id === "model" || option.category === "model"
36003
+ )?.id ?? "model",
36004
+ requestId: "agent-settings-model",
36005
+ sessionId: `agent-settings-${crypto.randomUUID()}`,
36006
+ value: model,
36007
+ valueType: "select"
36008
+ });
36009
+ return new AcpAgentSettingsSnapshot(prepared.agentName, prepared.agentVersion, configOptions);
35917
36010
  },
35918
- () => this.#agentSettingsObserver,
35919
- new MemoryAcpSessionStore()
35920
- ),
35921
- async (runtime) => {
35922
- const prepared = runtime.prepared();
35923
- const model = options.model;
35924
- const configOptions = model === void 0 ? prepared.configOptions : await runtime.configure({
35925
- ...options,
35926
- booleanValue: false,
35927
- configId: prepared.configOptions.find(
35928
- (option) => option.id === "model" || option.category === "model"
35929
- )?.id ?? "model",
35930
- requestId: "agent-settings-model",
35931
- sessionId: `agent-settings-${crypto.randomUUID()}`,
35932
- value: model,
35933
- valueType: "select"
35934
- });
35935
- return new AcpAgentSettingsSnapshot(prepared.agentName, prepared.agentVersion, configOptions);
35936
- },
35937
- async (runtime) => await runtime.close()
35938
- );
36011
+ async (runtime) => await runtime.close()
36012
+ );
36013
+ });
35939
36014
  /**
35940
36015
  * Retained for Agents that expose a separate persisted configuration channel.
35941
36016
  * Use inspectAgentSettings for Agent-scoped settings discovery.
35942
36017
  */
35943
- inspectSession = async (options, metrics = unmeasuredOperationMetrics) => {
35944
- if (this.#executionProcesses.pending(options.sessionId) !== void 0 || this.#executionProcesses.get(options.sessionId) !== void 0) {
35945
- throw new AcpExecutionError("The configuration inspection session is already in use", {}, "session_busy");
36018
+ inspectSession = async (options, metrics = unmeasuredOperationMetrics) => this.#operations.run(options, async (options2) => {
36019
+ if (this.#executionProcesses.pending(options2.sessionId) !== void 0 || this.#executionProcesses.get(options2.sessionId) !== void 0) {
36020
+ throw new AcpExecutionError(
36021
+ "The configuration inspection session is already in use",
36022
+ {},
36023
+ "session_busy"
36024
+ );
35946
36025
  }
35947
- return await this.#executionProcesses.use(options.sessionId, async () => {
35948
- const runtime = await this.#startPreparation(options, metrics);
36026
+ return await this.#executionProcesses.use(options2.sessionId, async () => {
36027
+ const runtime = await this.#startPreparation(options2, metrics);
35949
36028
  try {
35950
36029
  return runtime.prepared();
35951
36030
  } finally {
35952
36031
  try {
35953
- await this.#retireSessionProcess(options.sessionId, runtime, async () => await runtime.close());
36032
+ await this.#retireSessionProcess(options2.sessionId, runtime, async () => await runtime.close());
35954
36033
  } finally {
35955
- this.#store.remove(options.sessionId);
36034
+ this.#store.remove(options2.sessionId);
35956
36035
  }
35957
36036
  }
35958
36037
  });
35959
- };
35960
- prepareExecutionSession = async (options) => {
35961
- const pending = this.#executionProcesses.pending(options.sessionId);
36038
+ });
36039
+ prepareExecutionSession = async (options) => this.#operations.run(options, async (options2) => {
36040
+ const pending = this.#executionProcesses.pending(options2.sessionId);
35962
36041
  if (pending !== void 0) {
35963
- await pending;
35964
- return await this.prepareExecutionSession(options);
36042
+ await waitForPreparation(pending, options2.signal);
36043
+ return await this.prepareExecutionSession(options2);
35965
36044
  }
35966
- const existing = this.#executionProcesses.get(options.sessionId);
36045
+ const existing = this.#executionProcesses.get(options2.sessionId);
35967
36046
  if (existing === void 0) {
35968
- return (await this.#startPreparation(options)).prepared();
36047
+ return (await this.#startPreparation(options2)).prepared();
35969
36048
  }
35970
- if (!existing.belongsTo(options.agent.id, options.cwd, options.additionalDirectories)) {
36049
+ if (!existing.belongsTo(options2.agent.id, options2.cwd, options2.additionalDirectories)) {
35971
36050
  throw new AcpExecutionError(
35972
36051
  "The agent or workspace cannot change after a conversation has started",
35973
36052
  {},
35974
36053
  "session_identity_mismatch"
35975
36054
  );
35976
36055
  }
35977
- if (existing.usesEnvironment(options.agent.environment)) {
35978
- this.#executionProcesses.touch(options.sessionId, existing);
36056
+ if (existing.usesEnvironment(options2.agent.environment)) {
36057
+ this.#executionProcesses.touch(options2.sessionId, existing);
35979
36058
  return existing.prepared();
35980
36059
  }
35981
36060
  if (existing.hasRunningTurn()) {
@@ -35985,15 +36064,15 @@ var AgentRuntimeManager = class {
35985
36064
  "session_busy"
35986
36065
  );
35987
36066
  }
35988
- return (await this.#replaceExecutionPreparation(existing, options)).prepared();
35989
- };
35990
- prepareNativeSessionBrowser = (options) => this.#queryProcesses.prepare(options);
35991
- configureSession = async (options) => {
35992
- return await this.#executionProcesses.use(options.sessionId, async () => {
35993
- const runtime = await this.ensureSession(options);
35994
- return await runtime.configure(options);
36067
+ return (await this.#replaceExecutionPreparation(existing, options2)).prepared();
36068
+ });
36069
+ prepareNativeSessionBrowser = (options) => this.#operations.run(options, (scoped) => this.#queryProcesses.prepare(scoped));
36070
+ configureSession = async (options) => this.#operations.run(options, async (options2) => {
36071
+ return await this.#executionProcesses.use(options2.sessionId, async () => {
36072
+ const runtime = await this.ensureSession(options2);
36073
+ return await runtime.configure(options2);
35995
36074
  });
35996
- };
36075
+ });
35997
36076
  cancelPrompt = async (sessionId) => {
35998
36077
  await this.#executions.cancel(sessionId, async () => {
35999
36078
  const runtime = this.#executionProcesses.get(sessionId);
@@ -36008,19 +36087,19 @@ var AgentRuntimeManager = class {
36008
36087
  }
36009
36088
  });
36010
36089
  };
36011
- steerPrompt = async (options) => {
36012
- if (this.#executions.command(options.sessionId) !== options.targetCommandId) {
36090
+ steerPrompt = async (options) => this.#operations.run(options, async (options2) => {
36091
+ if (this.#executions.command(options2.sessionId) !== options2.targetCommandId) {
36013
36092
  throw new AcpExecutionError("The target turn is no longer active", {}, "steering_target_unavailable");
36014
36093
  }
36015
- const pending = this.#executionProcesses.pending(options.sessionId);
36094
+ const pending = this.#executionProcesses.pending(options2.sessionId);
36016
36095
  if (pending !== void 0) {
36017
- await pending;
36096
+ await waitForPreparation(pending, options2.signal);
36018
36097
  }
36019
- if (this.#executions.command(options.sessionId) !== options.targetCommandId) {
36098
+ if (this.#executions.command(options2.sessionId) !== options2.targetCommandId) {
36020
36099
  throw new AcpExecutionError("The target turn is no longer active", {}, "steering_target_unavailable");
36021
36100
  }
36022
- const runtime = this.#executionProcesses.get(options.sessionId);
36023
- if (runtime === void 0 || !runtime.belongsTo(options.agent.id, options.cwd, options.additionalDirectories)) {
36101
+ const runtime = this.#executionProcesses.get(options2.sessionId);
36102
+ if (runtime === void 0 || !runtime.belongsTo(options2.agent.id, options2.cwd, options2.additionalDirectories)) {
36024
36103
  throw new AcpExecutionError(
36025
36104
  "The target turn execution context is unavailable",
36026
36105
  {},
@@ -36037,8 +36116,8 @@ var AgentRuntimeManager = class {
36037
36116
  deadline.unref();
36038
36117
  try {
36039
36118
  return await runtime.steer({
36040
- ...options,
36041
- signal: AbortSignal.any([options.signal, deadlineController.signal])
36119
+ ...options2,
36120
+ signal: AbortSignal.any([options2.signal, deadlineController.signal])
36042
36121
  });
36043
36122
  } catch (error62) {
36044
36123
  if (error62 instanceof AcpExecutionError) {
@@ -36048,44 +36127,44 @@ var AgentRuntimeManager = class {
36048
36127
  } finally {
36049
36128
  clearTimeout(deadline);
36050
36129
  }
36051
- };
36052
- runPrompt = async (options) => {
36053
- const stored = this.#store.read(options.sessionId);
36130
+ });
36131
+ runPrompt = async (options) => this.#operations.run(options, async (options2) => {
36132
+ const stored = this.#store.read(options2.sessionId);
36054
36133
  if (stored instanceof FoundAcpStoredSession && this.#nativeOperations.has(`${stored.session.agentId}:${stored.session.nativeSessionId}`)) {
36055
36134
  throw new AcpExecutionError("The native session is being managed", {}, "session_busy");
36056
36135
  }
36057
- this.#executions.begin(options.sessionId, options.commandId);
36136
+ this.#executions.begin(options2.sessionId, options2.commandId);
36058
36137
  try {
36059
- if (this.#executions.cancellation(options.sessionId) !== void 0) {
36138
+ if (this.#executions.cancellation(options2.sessionId) !== void 0) {
36060
36139
  return { stopReason: "cancelled" };
36061
36140
  }
36062
- const runtime = await this.ensureSession(options);
36063
- if (this.#nativeOperations.has(`${options.agent.id}:${runtime.nativeSessionId()}`)) {
36141
+ const runtime = await this.ensureSession(options2);
36142
+ if (this.#nativeOperations.has(`${options2.agent.id}:${runtime.nativeSessionId()}`)) {
36064
36143
  throw new AcpExecutionError("The native session is being managed", {}, "session_busy");
36065
36144
  }
36066
- if (this.#executions.cancellation(options.sessionId) !== void 0) {
36145
+ if (this.#executions.cancellation(options2.sessionId) !== void 0) {
36067
36146
  return { stopReason: "cancelled" };
36068
36147
  }
36069
36148
  try {
36070
- const result = await runtime.prompt(options);
36071
- return this.#executions.cancellation(options.sessionId) !== void 0 ? { stopReason: "cancelled" } : result;
36149
+ const result = await runtime.prompt(options2);
36150
+ return this.#executions.cancellation(options2.sessionId) !== void 0 ? { stopReason: "cancelled" } : result;
36072
36151
  } catch (error62) {
36073
- if (this.#executions.cancellation(options.sessionId) !== void 0) {
36074
- await this.#executions.cancellation(options.sessionId);
36152
+ if (this.#executions.cancellation(options2.sessionId) !== void 0) {
36153
+ await this.#executions.cancellation(options2.sessionId);
36075
36154
  return { stopReason: "cancelled" };
36076
36155
  }
36077
36156
  throw error62;
36078
36157
  }
36079
36158
  } catch (error62) {
36080
- const failedRuntime = this.#executionProcesses.get(options.sessionId);
36159
+ const failedRuntime = this.#executionProcesses.get(options2.sessionId);
36081
36160
  if (failedRuntime !== void 0) {
36082
36161
  await this.#retireSessionProcess(
36083
- options.sessionId,
36162
+ options2.sessionId,
36084
36163
  failedRuntime,
36085
36164
  async () => await failedRuntime.close()
36086
36165
  );
36087
36166
  }
36088
- if (this.#executions.cancellation(options.sessionId) !== void 0) {
36167
+ if (this.#executions.cancellation(options2.sessionId) !== void 0) {
36089
36168
  return { stopReason: "cancelled" };
36090
36169
  }
36091
36170
  if (error62 instanceof AcpExecutionError) {
@@ -36096,14 +36175,14 @@ var AgentRuntimeManager = class {
36096
36175
  });
36097
36176
  } finally {
36098
36177
  try {
36099
- await this.#executions.cancellation(options.sessionId);
36178
+ await this.#executions.cancellation(options2.sessionId);
36100
36179
  } finally {
36101
- this.#executions.finish(options.sessionId, options.commandId);
36102
- this.#executionProcesses.touch(options.sessionId);
36180
+ this.#executions.finish(options2.sessionId, options2.commandId);
36181
+ this.#executionProcesses.touch(options2.sessionId);
36103
36182
  this.#processes.notifyChanged();
36104
36183
  }
36105
36184
  }
36106
- };
36185
+ });
36107
36186
  respondPermission = async (options) => {
36108
36187
  const runtime = this.#executionProcesses.get(options.sessionId);
36109
36188
  if (runtime === void 0) {
@@ -36118,7 +36197,7 @@ var AgentRuntimeManager = class {
36118
36197
  }
36119
36198
  await runtime.respondElicitation(options);
36120
36199
  };
36121
- close = async () => {
36200
+ close = async () => this.#operations.close(async () => {
36122
36201
  const sessions = [...this.#executionProcesses.entries()];
36123
36202
  await Promise.all([
36124
36203
  ...sessions.map(
@@ -36126,23 +36205,23 @@ var AgentRuntimeManager = class {
36126
36205
  ),
36127
36206
  this.#queryProcesses.close()
36128
36207
  ]);
36129
- };
36208
+ });
36130
36209
  findSessions = (sessionIds) => sessionIds.flatMap((sessionId) => {
36131
36210
  const stored = this.#store.read(sessionId);
36132
36211
  return stored instanceof FoundAcpStoredSession ? [stored.session] : [];
36133
36212
  });
36134
36213
  findLinkedSessions = (agentId, nativeSessionId) => this.#store.findNative(agentId, nativeSessionId);
36135
36214
  hasPreparedSession = (sessionId, agentId, cwd, additionalDirectories) => this.#executionProcesses.get(sessionId)?.belongsTo(agentId, cwd, additionalDirectories) === true;
36136
- createNativeSession = async (options) => {
36215
+ createNativeSession = async (options) => this.#operations.run(options, async (options2) => {
36137
36216
  const temporarySessionId = `new-${crypto.randomUUID()}`;
36138
- const temporaryOptions = { ...options, sessionId: temporarySessionId };
36217
+ const temporaryOptions = { ...options2, sessionId: temporarySessionId };
36139
36218
  return await this.#executionProcesses.use(temporarySessionId, async () => {
36140
36219
  try {
36141
36220
  const runtime = await this.#startPreparation(temporaryOptions);
36142
36221
  let adopted = false;
36143
36222
  try {
36144
36223
  const nativeSessionId = runtime.nativeSessionId();
36145
- if (!isNativeChatSessionId(options.agent.id, nativeSessionId) || this.#executionProcesses.get(nativeSessionId) !== void 0 || !(this.#store.read(nativeSessionId) instanceof MissingAcpStoredSession)) {
36224
+ if (!isNativeChatSessionId(options2.agent.id, nativeSessionId) || this.#executionProcesses.get(nativeSessionId) !== void 0 || !(this.#store.read(nativeSessionId) instanceof MissingAcpStoredSession)) {
36146
36225
  throw new AcpExecutionError(
36147
36226
  "The Agent returned an invalid new Session ID",
36148
36227
  {},
@@ -36168,36 +36247,36 @@ var AgentRuntimeManager = class {
36168
36247
  this.#store.remove(temporarySessionId);
36169
36248
  }
36170
36249
  });
36171
- };
36172
- ensureSession = async (options) => {
36173
- const existing = this.#executionProcesses.get(options.sessionId);
36250
+ });
36251
+ ensureSession = async (options) => this.#operations.run(options, async (options2) => {
36252
+ const existing = this.#executionProcesses.get(options2.sessionId);
36174
36253
  if (existing !== void 0) {
36175
- if (!existing.belongsTo(options.agent.id, options.cwd, options.additionalDirectories)) {
36254
+ if (!existing.belongsTo(options2.agent.id, options2.cwd, options2.additionalDirectories)) {
36176
36255
  throw new AcpExecutionError(
36177
36256
  "The agent or workspace cannot change after a conversation has started",
36178
36257
  {},
36179
36258
  "session_identity_mismatch"
36180
36259
  );
36181
36260
  }
36182
- this.#executionProcesses.touch(options.sessionId, existing);
36261
+ this.#executionProcesses.touch(options2.sessionId, existing);
36183
36262
  return existing;
36184
36263
  }
36185
- await this.prepareSession(options);
36186
- const started = this.#executionProcesses.get(options.sessionId);
36264
+ await this.prepareSession(options2);
36265
+ const started = this.#executionProcesses.get(options2.sessionId);
36187
36266
  if (started === void 0) {
36188
36267
  throw new AcpExecutionError("ACP session did not start");
36189
36268
  }
36190
36269
  return started;
36191
- };
36192
- listNativeSessions = async (options, cursor) => {
36270
+ });
36271
+ listNativeSessions = async (options, cursor) => this.#operations.run(options, async (options2) => {
36193
36272
  return await this.#queryProcesses.use(
36194
- options,
36195
- async (runtime) => await runtime.listNativeSessions(cursor, options.signal)
36273
+ options2,
36274
+ async (runtime) => await runtime.listNativeSessions(cursor, options2.signal)
36196
36275
  );
36197
- };
36198
- previewNativeSession = async (options, nativeSessionId) => {
36199
- const key = `${options.agent.id}:${nativeSessionId}`;
36200
- const linked = this.#store.findNative(options.agent.id, nativeSessionId);
36276
+ });
36277
+ previewNativeSession = async (options, nativeSessionId) => this.#operations.run(options, async (options2) => {
36278
+ const key = `${options2.agent.id}:${nativeSessionId}`;
36279
+ const linked = this.#store.findNative(options2.agent.id, nativeSessionId);
36201
36280
  if (this.#nativeOperations.has(key) || linked.some(
36202
36281
  (entry) => this.#executions.command(entry.sessionId) !== void 0 || this.#executionProcesses.pending(entry.sessionId) !== void 0
36203
36282
  )) {
@@ -36209,18 +36288,18 @@ var AgentRuntimeManager = class {
36209
36288
  }
36210
36289
  this.#nativeOperations.add(key);
36211
36290
  try {
36212
- return await this.#queryProcesses.preview(options, nativeSessionId);
36291
+ return await this.#queryProcesses.preview(options2, nativeSessionId);
36213
36292
  } finally {
36214
36293
  this.#nativeOperations.delete(key);
36215
36294
  }
36216
- };
36217
- loadSessionHistory = async (options) => {
36218
- return await this.#executionProcesses.use(options.sessionId, async () => {
36219
- const runtime = await this.ensureSession(options);
36220
- const stored = this.#store.read(options.sessionId);
36295
+ });
36296
+ loadSessionHistory = async (options) => this.#operations.run(options, async (options2) => {
36297
+ return await this.#executionProcesses.use(options2.sessionId, async () => {
36298
+ const runtime = await this.ensureSession(options2);
36299
+ const stored = this.#store.read(options2.sessionId);
36221
36300
  if (stored instanceof FoundAcpStoredSession && this.#nativeHistoryReader !== null) {
36222
36301
  const history = await this.#nativeHistoryReader.read(
36223
- options,
36302
+ options2,
36224
36303
  stored.session.nativeSessionId,
36225
36304
  runtime.nativeHistoryTurn
36226
36305
  );
@@ -36228,15 +36307,15 @@ var AgentRuntimeManager = class {
36228
36307
  return history;
36229
36308
  }
36230
36309
  }
36231
- return await runtime.loadHistory(options.signal);
36310
+ return await runtime.loadHistory(options2.signal);
36232
36311
  });
36233
- };
36234
- openNativeSession = async (options, origin) => {
36235
- const key = `${options.agent.id}:${origin.nativeSessionId}`;
36312
+ });
36313
+ openNativeSession = async (options, origin) => this.#operations.run(options, async (options2) => {
36314
+ const key = `${options2.agent.id}:${origin.nativeSessionId}`;
36236
36315
  if (this.#nativeOperations.has(key)) {
36237
36316
  throw new AcpExecutionError("The native session is being managed", {}, "session_busy");
36238
36317
  }
36239
- const linked = this.#store.findNative(options.agent.id, origin.nativeSessionId);
36318
+ const linked = this.#store.findNative(options2.agent.id, origin.nativeSessionId);
36240
36319
  if (linked.some(
36241
36320
  (entry) => this.#executions.command(entry.sessionId) !== void 0 || this.#executionProcesses.pending(entry.sessionId) !== void 0
36242
36321
  )) {
@@ -36250,7 +36329,7 @@ var AgentRuntimeManager = class {
36250
36329
  if (origin.kind === "import" && existing !== void 0) {
36251
36330
  return await this.#executionProcesses.use(existing.sessionId, async () => {
36252
36331
  const runtime = await this.ensureSession({
36253
- ...options,
36332
+ ...options2,
36254
36333
  sessionId: existing.sessionId
36255
36334
  });
36256
36335
  if (this.#executions.command(existing.sessionId) !== void 0 || this.#nativeOperations.has(key)) {
@@ -36272,18 +36351,22 @@ var AgentRuntimeManager = class {
36272
36351
  }
36273
36352
  });
36274
36353
  }
36275
- 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) {
36276
- throw new AcpExecutionError("The destination conversation already exists", {}, "session_identity_mismatch");
36354
+ 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) {
36355
+ throw new AcpExecutionError(
36356
+ "The destination conversation already exists",
36357
+ {},
36358
+ "session_identity_mismatch"
36359
+ );
36277
36360
  }
36278
- return await this.#executionProcesses.use(options.sessionId, async () => {
36361
+ return await this.#executionProcesses.use(options2.sessionId, async () => {
36279
36362
  this.#nativeOperations.add(key);
36280
36363
  try {
36281
- const runtime = await this.#startPreparation({ ...options, origin });
36282
- const openedKey = `${options.agent.id}:${runtime.nativeSessionId()}`;
36364
+ const runtime = await this.#startPreparation({ ...options2, origin });
36365
+ const openedKey = `${options2.agent.id}:${runtime.nativeSessionId()}`;
36283
36366
  this.#nativeOperations.add(openedKey);
36284
36367
  try {
36285
36368
  return {
36286
- sessionId: options.sessionId,
36369
+ sessionId: options2.sessionId,
36287
36370
  prepared: runtime.prepared()
36288
36371
  };
36289
36372
  } finally {
@@ -36291,11 +36374,11 @@ var AgentRuntimeManager = class {
36291
36374
  this.#processes.notifyChanged();
36292
36375
  }
36293
36376
  } catch (error62) {
36294
- this.#store.remove(options.sessionId);
36295
- const runtime = this.#executionProcesses.get(options.sessionId);
36377
+ this.#store.remove(options2.sessionId);
36378
+ const runtime = this.#executionProcesses.get(options2.sessionId);
36296
36379
  if (runtime !== void 0) {
36297
36380
  await this.#retireSessionProcess(
36298
- options.sessionId,
36381
+ options2.sessionId,
36299
36382
  runtime,
36300
36383
  async () => await runtime.closeProcess()
36301
36384
  );
@@ -36305,11 +36388,11 @@ var AgentRuntimeManager = class {
36305
36388
  this.#nativeOperations.delete(key);
36306
36389
  }
36307
36390
  });
36308
- };
36309
- deleteNativeSession = async (options, nativeSessionId) => {
36310
- return await this.#queryProcesses.use(options, async (runtime) => {
36311
- const key = `${options.agent.id}:${nativeSessionId}`;
36312
- const linked = this.#store.findNative(options.agent.id, nativeSessionId);
36391
+ });
36392
+ deleteNativeSession = async (options, nativeSessionId) => this.#operations.run(options, async (options2) => {
36393
+ return await this.#queryProcesses.use(options2, async (runtime) => {
36394
+ const key = `${options2.agent.id}:${nativeSessionId}`;
36395
+ const linked = this.#store.findNative(options2.agent.id, nativeSessionId);
36313
36396
  if (this.#nativeOperations.has(key) || linked.some(
36314
36397
  (entry) => this.#executions.command(entry.sessionId) !== void 0 || this.#executionProcesses.pending(entry.sessionId) !== void 0
36315
36398
  )) {
@@ -36327,11 +36410,11 @@ var AgentRuntimeManager = class {
36327
36410
  await this.#retireSessionProcess(entry.sessionId, active, async () => await active.close());
36328
36411
  }
36329
36412
  }
36330
- options.signal.throwIfAborted();
36331
- await runtime.deleteNativeSession(nativeSessionId, options.signal);
36332
- const deleted = this.#store.markDeleted(options.agent.id, nativeSessionId);
36413
+ options2.signal.throwIfAborted();
36414
+ await runtime.deleteNativeSession(nativeSessionId, options2.signal);
36415
+ const deleted = this.#store.markDeleted(options2.agent.id, nativeSessionId);
36333
36416
  if (runtime.nativeSessionId() === nativeSessionId) {
36334
- await this.#queryProcesses.retire(options.sessionId, runtime);
36417
+ await this.#queryProcesses.retire(options2.sessionId, runtime);
36335
36418
  }
36336
36419
  return deleted;
36337
36420
  } finally {
@@ -36339,7 +36422,7 @@ var AgentRuntimeManager = class {
36339
36422
  this.#processes.notifyChanged();
36340
36423
  }
36341
36424
  });
36342
- };
36425
+ });
36343
36426
  };
36344
36427
 
36345
36428
  // src/agent-catalog/publish-agent-catalog.ts