@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/cli.js CHANGED
@@ -3381,7 +3381,7 @@ var program = new Command();
3381
3381
  // package.json
3382
3382
  var package_default = {
3383
3383
  name: "@moxt-ai/mobius",
3384
- version: "0.0.130",
3384
+ version: "0.0.132",
3385
3385
  description: "Mobius CLI for pairing and running local AI agent services.",
3386
3386
  type: "module",
3387
3387
  bin: {
@@ -25105,11 +25105,8 @@ function agentMessageMeta(phase) {
25105
25105
  return { [CODEX_META_KEY]: { phase } };
25106
25106
  }
25107
25107
 
25108
- // src/acp/codex/agent.ts
25109
- var APPROVAL_REASON_CHARACTER_LIMIT = 500;
25108
+ // src/acp/codex/settings.ts
25110
25109
  var APPROVAL_TIMEOUT_MILLISECONDS = 36e5;
25111
- var CODEX_AGENT_VERSION = "0.154.0";
25112
- var SESSION_LIST_TIMEOUT_MILLISECONDS = 3e4;
25113
25110
  var MODEL_SETTING_ID = "model";
25114
25111
  var REASONING_EFFORT_SETTING_ID = "reasoning_effort";
25115
25112
  var MODE_SETTING_ID = "mode";
@@ -25118,7 +25115,6 @@ var COLLABORATION_MODE_SETTING_ID = "collaboration_mode";
25118
25115
  var MODEL_CATALOG_LIMIT = 1e3;
25119
25116
  var FAST_TIER = "fast";
25120
25117
  var SERVICE_TIER_FAST = "priority";
25121
- var CODEX_COMMANDS = Object.freeze([{ description: "Compact the conversation context", name: "compact" }]);
25122
25118
  var WORKSPACE_WRITE_POLICY = Object.freeze({
25123
25119
  excludeSlashTmp: false,
25124
25120
  excludeTmpdirEnvVar: false,
@@ -25162,94 +25158,6 @@ function initialMode(environment) {
25162
25158
  function capitalize(value) {
25163
25159
  return value.length === 0 ? value : value.charAt(0).toUpperCase() + value.slice(1);
25164
25160
  }
25165
- var APPROVAL_OPTIONS = Object.freeze([
25166
- { kind: "allow_once", name: "Allow once", optionId: "accept" },
25167
- { kind: "allow_always", name: "Allow for this session", optionId: "acceptForSession" },
25168
- { kind: "reject_once", name: "Deny", optionId: "decline" }
25169
- ]);
25170
- function permissionDecision(optionId) {
25171
- if (optionId === "accept" || optionId === "acceptForSession" || optionId === "decline") {
25172
- return optionId;
25173
- }
25174
- return "cancel";
25175
- }
25176
- function promptInput(prompt) {
25177
- const input2 = [];
25178
- for (const block of prompt) {
25179
- if (block.type === "text") {
25180
- input2.push({ text: block.text, text_elements: [], type: "text" });
25181
- continue;
25182
- }
25183
- if (block.type === "image") {
25184
- input2.push({ type: "image", url: `data:${block.mimeType};base64,${block.data}` });
25185
- continue;
25186
- }
25187
- if (block.type === "resource") {
25188
- const resource = block.resource;
25189
- input2.push({
25190
- text: "text" in resource ? resource.text ?? "" : "",
25191
- text_elements: [],
25192
- type: "text"
25193
- });
25194
- continue;
25195
- }
25196
- if (block.type === "resource_link") {
25197
- input2.push({ text: `Resource: ${block.uri}`, text_elements: [], type: "text" });
25198
- }
25199
- }
25200
- return input2;
25201
- }
25202
- function isCompactPrompt(prompt) {
25203
- return prompt.length === 1 && prompt[0]?.type === "text" && prompt[0].text.trim() === "/compact";
25204
- }
25205
- function steeringPromptInput(prompt) {
25206
- const input2 = [];
25207
- for (const block of prompt) {
25208
- if (typeof block !== "object" || block === null) {
25209
- throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
25210
- }
25211
- const type = Reflect.get(block, "type");
25212
- if (type === "text") {
25213
- const text2 = Reflect.get(block, "text");
25214
- if (typeof text2 !== "string") {
25215
- throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
25216
- }
25217
- input2.push({ text: text2, text_elements: [], type: "text" });
25218
- continue;
25219
- }
25220
- if (type === "image") {
25221
- const data = Reflect.get(block, "data");
25222
- const mimeType = Reflect.get(block, "mimeType");
25223
- if (typeof data !== "string" || typeof mimeType !== "string") {
25224
- throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
25225
- }
25226
- input2.push({ type: "image", url: `data:${mimeType};base64,${data}` });
25227
- continue;
25228
- }
25229
- if (type === "resource") {
25230
- const resource = Reflect.get(block, "resource");
25231
- if (typeof resource !== "object" || resource === null) {
25232
- throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
25233
- }
25234
- const text2 = Reflect.get(resource, "text");
25235
- if (text2 !== void 0 && typeof text2 !== "string") {
25236
- throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
25237
- }
25238
- input2.push({ text: text2 ?? "", text_elements: [], type: "text" });
25239
- continue;
25240
- }
25241
- if (type === "resource_link") {
25242
- const uri = Reflect.get(block, "uri");
25243
- if (typeof uri !== "string") {
25244
- throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
25245
- }
25246
- input2.push({ text: `Resource: ${uri}`, text_elements: [], type: "text" });
25247
- continue;
25248
- }
25249
- throw new AcpExecutionError("Codex received an unsupported steering prompt", {}, "invalid_request");
25250
- }
25251
- return input2;
25252
- }
25253
25161
  function modelValues(models) {
25254
25162
  return models.map((model) => ({
25255
25163
  description: model.description ?? "",
@@ -25354,6 +25262,339 @@ function effortSetting(model, currentValue) {
25354
25262
  type: "select"
25355
25263
  };
25356
25264
  }
25265
+ var CodexSettings = class {
25266
+ #appServer;
25267
+ #models = [];
25268
+ // Whether the current turn must carry a policy at all. Until the user picks a mode, Codex's own
25269
+ // configuration decides, so `turn/start` omits the fields and inherits what the host set up.
25270
+ #policySelected = false;
25271
+ // Whether a collaboration mode choice has been made in this session. A restored thread keeps
25272
+ // the mode Codex already persisted, so the first turn does not reset it to Build.
25273
+ #collaborationModeSelected = false;
25274
+ // Whether the app-server accepts collaboration mode on `turn/start`, probed once per
25275
+ // app-server. An older Codex rejects the experimental field, and the setting must disappear
25276
+ // rather than break every turn.
25277
+ #collaborationModeSupported = null;
25278
+ #selection;
25279
+ constructor(appServer, environment) {
25280
+ this.#appServer = appServer;
25281
+ this.#selection = {
25282
+ collaborationMode: "default",
25283
+ effort: "",
25284
+ fastMode: false,
25285
+ mode: initialMode(environment),
25286
+ model: ""
25287
+ };
25288
+ }
25289
+ selectNewThread = (created) => {
25290
+ const supported = supportedSelection(this.#models, created.model ?? "", created.reasoningEffort ?? "");
25291
+ this.#selection = {
25292
+ ...this.#selection,
25293
+ collaborationMode: "default",
25294
+ ...supported
25295
+ };
25296
+ this.#collaborationModeSelected = false;
25297
+ };
25298
+ observeCollaborationMode = (mode) => {
25299
+ if (mode === void 0 || mode === this.#selection.collaborationMode) {
25300
+ return false;
25301
+ }
25302
+ this.#selection = { ...this.#selection, collaborationMode: mode };
25303
+ return true;
25304
+ };
25305
+ turnParameters = () => {
25306
+ const selection = this.#selection;
25307
+ const mode = AGENT_MODES.find((candidate) => candidate.id === selection.mode) ?? DEFAULT_MODE;
25308
+ const supportsFast = this.#model(selection.model)?.additionalSpeedTiers?.includes(FAST_TIER) === true;
25309
+ return {
25310
+ // Until a mode is chosen, `config.toml` decides the sandbox and approval
25311
+ // policy, and those fields stay off the turn so the host's own setup is
25312
+ // inherited rather than overridden.
25313
+ ...this.#policySelected ? {
25314
+ approvalPolicy: mode.approvalPolicy,
25315
+ approvalsReviewer: mode.approvalsReviewer,
25316
+ sandboxPolicy: mode.sandboxPolicy
25317
+ } : {},
25318
+ // The collaboration mode rides on the turn: Codex applies it to the
25319
+ // thread, where it persists until changed. "Build" is Codex's `default`
25320
+ // mode, so it is only sent once a choice exists to apply.
25321
+ ...this.#collaborationModeSupported && (selection.collaborationMode !== "default" || this.#collaborationModeSelected) ? {
25322
+ collaborationMode: {
25323
+ mode: selection.collaborationMode,
25324
+ settings: {
25325
+ developer_instructions: null,
25326
+ model: selection.model,
25327
+ reasoning_effort: selection.effort.length === 0 ? null : selection.effort
25328
+ }
25329
+ }
25330
+ } : {},
25331
+ ...selection.effort.length === 0 ? {} : { effort: selection.effort },
25332
+ ...selection.model.length === 0 ? {} : { model: selection.model },
25333
+ ...selection.fastMode && supportsFast ? { serviceTier: SERVICE_TIER_FAST } : {}
25334
+ };
25335
+ };
25336
+ loadModels = async (signal) => {
25337
+ const models = [];
25338
+ let cursor = null;
25339
+ try {
25340
+ do {
25341
+ const decoded = modelListResponseSchema.parse(
25342
+ await this.#appServer.request(
25343
+ "model/list",
25344
+ { cursor, limit: null },
25345
+ AbortSignal.any([signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
25346
+ )
25347
+ );
25348
+ models.push(...decoded.data);
25349
+ cursor = decoded.nextCursor ?? null;
25350
+ } while (cursor !== null && models.length < MODEL_CATALOG_LIMIT);
25351
+ } catch (error62) {
25352
+ signal.throwIfAborted();
25353
+ process.stderr.write(`[codex-acp] model catalog unavailable: ${String(error62)}
25354
+ `);
25355
+ }
25356
+ this.#models = Object.freeze(models.slice(0, MODEL_CATALOG_LIMIT));
25357
+ };
25358
+ #model = (id) => this.#models.find((model) => model.id === id);
25359
+ /**
25360
+ * Learns, once per app-server, whether collaboration mode can be applied. An empty settings
25361
+ * update is a no-op on a supporting Codex; an older Codex answers an error, which costs the
25362
+ * Build/Plan selector alone without changing a restored thread's persisted mode.
25363
+ */
25364
+ probeCollaborationMode = async (threadId, signal) => {
25365
+ if (this.#collaborationModeSupported !== null) {
25366
+ return;
25367
+ }
25368
+ try {
25369
+ await this.#appServer.request(
25370
+ "thread/settings/update",
25371
+ { threadId },
25372
+ AbortSignal.any([signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
25373
+ );
25374
+ this.#collaborationModeSupported = true;
25375
+ } catch {
25376
+ signal.throwIfAborted();
25377
+ this.#collaborationModeSupported = false;
25378
+ }
25379
+ };
25380
+ /** The ACP settings Mobius discovers and renders in Run settings. */
25381
+ configOptions = () => {
25382
+ const options = [];
25383
+ const model = modelSetting(this.#models, this.#selection.model);
25384
+ if (model !== null) {
25385
+ options.push(model);
25386
+ }
25387
+ const effort = effortSetting(this.#model(this.#selection.model), this.#selection.effort);
25388
+ if (effort !== null) {
25389
+ options.push(effort);
25390
+ }
25391
+ const fastMode = fastModeSetting(this.#model(this.#selection.model), this.#selection.fastMode);
25392
+ if (fastMode !== null) {
25393
+ options.push(fastMode);
25394
+ }
25395
+ if (this.#collaborationModeSupported === true) {
25396
+ options.push(collaborationModeSetting(this.#selection.collaborationMode));
25397
+ }
25398
+ options.push(modeSetting(this.#selection.mode));
25399
+ return options;
25400
+ };
25401
+ selectRestoredThread = (thread) => {
25402
+ const supported = supportedSelection(
25403
+ this.#models,
25404
+ thread.model ?? this.#selection.model,
25405
+ thread.reasoningEffort ?? this.#selection.effort
25406
+ );
25407
+ this.#selection = {
25408
+ ...this.#selection,
25409
+ ...supported,
25410
+ fastMode: thread.serviceTier === SERVICE_TIER_FAST
25411
+ };
25412
+ };
25413
+ /**
25414
+ * Applies one `session/set_config_option`. Switching models re-resolves the effort the way Codex
25415
+ * does — the current effort when the new model supports it, otherwise the model's own default —
25416
+ * so the reply never advertises an effort the selected model cannot run.
25417
+ */
25418
+ applySelection = (configId, value) => {
25419
+ if (configId === FAST_MODE_SETTING_ID) {
25420
+ if (typeof value !== "boolean") {
25421
+ throw new AcpExecutionError(
25422
+ "The requested Codex setting is invalid",
25423
+ {},
25424
+ "invalid_session_configuration"
25425
+ );
25426
+ }
25427
+ if (value && this.#model(this.#selection.model)?.additionalSpeedTiers?.includes(FAST_TIER) !== true) {
25428
+ throw new AcpExecutionError(
25429
+ "The selected Codex model has no fast mode",
25430
+ {},
25431
+ "invalid_session_configuration"
25432
+ );
25433
+ }
25434
+ this.#selection = { ...this.#selection, fastMode: value };
25435
+ return;
25436
+ }
25437
+ if (typeof value !== "string") {
25438
+ throw new AcpExecutionError("The requested Codex setting is invalid", {}, "invalid_session_configuration");
25439
+ }
25440
+ if (configId === MODE_SETTING_ID) {
25441
+ if (!AGENT_MODES.some((mode) => mode.id === value)) {
25442
+ throw new AcpExecutionError(
25443
+ "The requested Codex mode is unavailable",
25444
+ {},
25445
+ "invalid_session_configuration"
25446
+ );
25447
+ }
25448
+ this.#selection = { ...this.#selection, mode: value };
25449
+ this.#policySelected = true;
25450
+ return;
25451
+ }
25452
+ if (configId === COLLABORATION_MODE_SETTING_ID) {
25453
+ if (!COLLABORATION_MODES.some((mode) => mode.value === value)) {
25454
+ throw new AcpExecutionError(
25455
+ "The requested Codex collaboration mode is unavailable",
25456
+ {},
25457
+ "invalid_session_configuration"
25458
+ );
25459
+ }
25460
+ this.#selection = { ...this.#selection, collaborationMode: value };
25461
+ this.#collaborationModeSelected = true;
25462
+ return;
25463
+ }
25464
+ if (configId === MODEL_SETTING_ID) {
25465
+ if (value === this.#selection.model) {
25466
+ return;
25467
+ }
25468
+ const model = this.#model(value);
25469
+ if (model === void 0) {
25470
+ throw new AcpExecutionError(
25471
+ "The requested Codex model is unavailable",
25472
+ {},
25473
+ "invalid_session_configuration"
25474
+ );
25475
+ }
25476
+ const supported = (model.supportedReasoningEfforts ?? []).map((option) => option.reasoningEffort);
25477
+ const effort = supported.includes(this.#selection.effort) ? this.#selection.effort : model.defaultReasoningEffort ?? supported[0] ?? "";
25478
+ this.#selection = {
25479
+ ...this.#selection,
25480
+ effort,
25481
+ fastMode: this.#selection.fastMode && model.additionalSpeedTiers?.includes(FAST_TIER) === true,
25482
+ model: value
25483
+ };
25484
+ return;
25485
+ }
25486
+ if (configId === REASONING_EFFORT_SETTING_ID) {
25487
+ const supported = (this.#model(this.#selection.model)?.supportedReasoningEfforts ?? []).map(
25488
+ (option) => option.reasoningEffort
25489
+ );
25490
+ if (!supported.includes(value)) {
25491
+ throw new AcpExecutionError(
25492
+ "The requested Codex reasoning effort is unavailable",
25493
+ {},
25494
+ "invalid_session_configuration"
25495
+ );
25496
+ }
25497
+ this.#selection = { ...this.#selection, effort: value };
25498
+ return;
25499
+ }
25500
+ throw new AcpExecutionError("The requested Codex setting is unavailable", {}, "invalid_session_configuration");
25501
+ };
25502
+ };
25503
+
25504
+ // src/acp/codex/agent.ts
25505
+ var APPROVAL_REASON_CHARACTER_LIMIT = 500;
25506
+ var APPROVAL_TIMEOUT_MILLISECONDS2 = 36e5;
25507
+ var CODEX_AGENT_VERSION = "0.154.0";
25508
+ var SESSION_LIST_TIMEOUT_MILLISECONDS = 3e4;
25509
+ var CODEX_COMMANDS = Object.freeze([{ description: "Compact the conversation context", name: "compact" }]);
25510
+ var APPROVAL_OPTIONS = Object.freeze([
25511
+ { kind: "allow_once", name: "Allow once", optionId: "accept" },
25512
+ { kind: "allow_always", name: "Allow for this session", optionId: "acceptForSession" },
25513
+ { kind: "reject_once", name: "Deny", optionId: "decline" }
25514
+ ]);
25515
+ function permissionDecision(optionId) {
25516
+ if (optionId === "accept" || optionId === "acceptForSession" || optionId === "decline") {
25517
+ return optionId;
25518
+ }
25519
+ return "cancel";
25520
+ }
25521
+ function promptInput(prompt) {
25522
+ const input2 = [];
25523
+ for (const block of prompt) {
25524
+ if (block.type === "text") {
25525
+ input2.push({ text: block.text, text_elements: [], type: "text" });
25526
+ continue;
25527
+ }
25528
+ if (block.type === "image") {
25529
+ input2.push({ type: "image", url: `data:${block.mimeType};base64,${block.data}` });
25530
+ continue;
25531
+ }
25532
+ if (block.type === "resource") {
25533
+ const resource = block.resource;
25534
+ input2.push({
25535
+ text: "text" in resource ? resource.text ?? "" : "",
25536
+ text_elements: [],
25537
+ type: "text"
25538
+ });
25539
+ continue;
25540
+ }
25541
+ if (block.type === "resource_link") {
25542
+ input2.push({ text: `Resource: ${block.uri}`, text_elements: [], type: "text" });
25543
+ }
25544
+ }
25545
+ return input2;
25546
+ }
25547
+ function isCompactPrompt(prompt) {
25548
+ return prompt.length === 1 && prompt[0]?.type === "text" && prompt[0].text.trim() === "/compact";
25549
+ }
25550
+ function steeringPromptInput(prompt) {
25551
+ const input2 = [];
25552
+ for (const block of prompt) {
25553
+ if (typeof block !== "object" || block === null) {
25554
+ throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
25555
+ }
25556
+ const type = Reflect.get(block, "type");
25557
+ if (type === "text") {
25558
+ const text2 = Reflect.get(block, "text");
25559
+ if (typeof text2 !== "string") {
25560
+ throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
25561
+ }
25562
+ input2.push({ text: text2, text_elements: [], type: "text" });
25563
+ continue;
25564
+ }
25565
+ if (type === "image") {
25566
+ const data = Reflect.get(block, "data");
25567
+ const mimeType = Reflect.get(block, "mimeType");
25568
+ if (typeof data !== "string" || typeof mimeType !== "string") {
25569
+ throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
25570
+ }
25571
+ input2.push({ type: "image", url: `data:${mimeType};base64,${data}` });
25572
+ continue;
25573
+ }
25574
+ if (type === "resource") {
25575
+ const resource = Reflect.get(block, "resource");
25576
+ if (typeof resource !== "object" || resource === null) {
25577
+ throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
25578
+ }
25579
+ const text2 = Reflect.get(resource, "text");
25580
+ if (text2 !== void 0 && typeof text2 !== "string") {
25581
+ throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
25582
+ }
25583
+ input2.push({ text: text2 ?? "", text_elements: [], type: "text" });
25584
+ continue;
25585
+ }
25586
+ if (type === "resource_link") {
25587
+ const uri = Reflect.get(block, "uri");
25588
+ if (typeof uri !== "string") {
25589
+ throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
25590
+ }
25591
+ input2.push({ text: `Resource: ${uri}`, text_elements: [], type: "text" });
25592
+ continue;
25593
+ }
25594
+ throw new AcpExecutionError("Codex received an unsupported steering prompt", {}, "invalid_request");
25595
+ }
25596
+ return input2;
25597
+ }
25357
25598
  function userInputSchema(questions) {
25358
25599
  const properties = {};
25359
25600
  const required2 = [];
@@ -25380,31 +25621,13 @@ var CodexAcpAgent = class {
25380
25621
  terminated;
25381
25622
  #closePromise = null;
25382
25623
  #connection = null;
25383
- #models = [];
25624
+ #settings;
25384
25625
  #nativeSessionId = "";
25385
- // Whether the current turn must carry a policy at all. Until the user picks a mode, Codex's own
25386
- // configuration decides, so `turn/start` omits the fields and inherits what the host set up.
25387
- #policySelected = false;
25388
- // Whether a collaboration mode choice has been made in this session. A restored thread keeps
25389
- // the mode Codex already persisted, so the first turn does not reset it to Build.
25390
- #collaborationModeSelected = false;
25391
- // Whether the app-server accepts collaboration mode on `turn/start`, probed once per
25392
- // app-server. An older Codex rejects the experimental field, and the setting must disappear
25393
- // rather than break every turn.
25394
- #collaborationModeSupported = null;
25395
- #selection;
25396
25626
  #streamedReasoningItemIds = /* @__PURE__ */ new Set();
25397
25627
  #turn = null;
25398
25628
  #nativeTurnId = null;
25399
25629
  #updateTail = Promise.resolve();
25400
25630
  constructor(options) {
25401
- this.#selection = {
25402
- collaborationMode: "default",
25403
- effort: "",
25404
- fastMode: false,
25405
- mode: initialMode(options.environment),
25406
- model: ""
25407
- };
25408
25631
  this.#appServer = new CodexAppServerClient({
25409
25632
  command: options.command,
25410
25633
  cwd: options.cwd,
@@ -25418,6 +25641,7 @@ var CodexAcpAgent = class {
25418
25641
  }
25419
25642
  }
25420
25643
  });
25644
+ this.#settings = new CodexSettings(this.#appServer, options.environment);
25421
25645
  this.terminated = this.#appServer.terminated;
25422
25646
  void this.terminated.then((termination) => {
25423
25647
  this.#turn?.completion.reject(acpEndpointTerminationError(termination));
@@ -25444,39 +25668,34 @@ var CodexAcpAgent = class {
25444
25668
  await this.#appServer.request(
25445
25669
  "thread/start",
25446
25670
  { cwd: context.params.cwd },
25447
- AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
25671
+ AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2)])
25448
25672
  )
25449
25673
  );
25450
25674
  this.#nativeSessionId = created.thread.id;
25451
- const supported = supportedSelection(this.#models, created.model ?? "", created.reasoningEffort ?? "");
25452
- this.#selection = {
25453
- ...this.#selection,
25454
- collaborationMode: "default",
25455
- ...supported
25456
- };
25457
- this.#collaborationModeSelected = false;
25458
- await this.#probeCollaborationMode(context.signal);
25675
+ this.#settings.selectNewThread(created);
25676
+ await this.#settings.probeCollaborationMode(this.#nativeSessionId, context.signal);
25459
25677
  await this.#emitAvailableCommands();
25460
- return { configOptions: this.#configOptions(), sessionId: created.thread.id };
25678
+ return { configOptions: this.#settings.configOptions(), sessionId: created.thread.id };
25461
25679
  }).onRequest(methods.agent.session.setConfigOption, async (context) => {
25462
- this.#applySelection(context.params.configId, context.params.value);
25463
- return { configOptions: this.#configOptions() };
25680
+ this.#settings.applySelection(context.params.configId, context.params.value);
25681
+ return { configOptions: this.#settings.configOptions() };
25464
25682
  }).onRequest(methods.agent.session.setMode, async (context) => {
25465
- this.#applySelection(MODE_SETTING_ID, context.params.modeId);
25683
+ this.#settings.applySelection("mode", context.params.modeId);
25466
25684
  return {};
25467
25685
  }).onRequest(methods.agent.session.load, async (context) => {
25468
25686
  const resumed = threadResumeResponseSchema.parse(
25469
25687
  await this.#appServer.request(
25470
25688
  "thread/resume",
25471
25689
  { cwd: context.params.cwd, excludeTurns: false, threadId: context.params.sessionId },
25472
- AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
25690
+ AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2)])
25473
25691
  )
25474
25692
  );
25475
- this.#selectRestoredThread(resumed);
25476
- await this.#probeCollaborationMode(context.signal);
25693
+ this.#nativeSessionId = resumed.thread.id;
25694
+ this.#settings.selectRestoredThread(resumed);
25695
+ await this.#settings.probeCollaborationMode(this.#nativeSessionId, context.signal);
25477
25696
  await this.#replayHistory(resumed.turns);
25478
25697
  await this.#emitAvailableCommands();
25479
- return { configOptions: this.#configOptions() };
25698
+ return { configOptions: this.#settings.configOptions() };
25480
25699
  }).onRequest(methods.agent.session.fork, async (context) => {
25481
25700
  const forked = threadForkResponseSchema.parse(
25482
25701
  await this.#appServer.request(
@@ -25486,26 +25705,28 @@ var CodexAcpAgent = class {
25486
25705
  excludeTurns: false,
25487
25706
  threadId: context.params.sessionId
25488
25707
  },
25489
- AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
25708
+ AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2)])
25490
25709
  )
25491
25710
  );
25492
- this.#selectRestoredThread(forked);
25493
- await this.#probeCollaborationMode(context.signal);
25711
+ this.#nativeSessionId = forked.thread.id;
25712
+ this.#settings.selectRestoredThread(forked);
25713
+ await this.#settings.probeCollaborationMode(this.#nativeSessionId, context.signal);
25494
25714
  await this.#replayHistory(forked.turns);
25495
25715
  await this.#emitAvailableCommands();
25496
- return { configOptions: this.#configOptions(), sessionId: forked.thread.id };
25716
+ return { configOptions: this.#settings.configOptions(), sessionId: forked.thread.id };
25497
25717
  }).onRequest(methods.agent.session.resume, async (context) => {
25498
25718
  const resumed = threadResumeResponseSchema.parse(
25499
25719
  await this.#appServer.request(
25500
25720
  "thread/resume",
25501
25721
  { cwd: context.params.cwd, excludeTurns: true, threadId: context.params.sessionId },
25502
- AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
25722
+ AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2)])
25503
25723
  )
25504
25724
  );
25505
- this.#selectRestoredThread(resumed);
25506
- await this.#probeCollaborationMode(context.signal);
25725
+ this.#nativeSessionId = resumed.thread.id;
25726
+ this.#settings.selectRestoredThread(resumed);
25727
+ await this.#settings.probeCollaborationMode(this.#nativeSessionId, context.signal);
25507
25728
  await this.#emitAvailableCommands();
25508
- return { configOptions: this.#configOptions() };
25729
+ return { configOptions: this.#settings.configOptions() };
25509
25730
  }).onRequest(methods.agent.session.prompt, async (context) => {
25510
25731
  if (isCompactPrompt(context.params.prompt)) {
25511
25732
  return await this.#compact(context.signal);
@@ -25545,7 +25766,7 @@ var CodexAcpAgent = class {
25545
25766
  /** Starts the app-server, performs its handshake, and reads the model catalog Codex offers. */
25546
25767
  initialize = async (signal) => {
25547
25768
  await this.#appServer.initialize(signal);
25548
- await this.#loadModels(signal);
25769
+ await this.#settings.loadModels(signal);
25549
25770
  };
25550
25771
  /**
25551
25772
  * Releases the app-server and every process it started. Mirrors the adapter path's teardown so a
@@ -25571,84 +25792,6 @@ var CodexAcpAgent = class {
25571
25792
  * the Run settings panel its model selector; it must not cost the conversation itself, so the
25572
25793
  * turn lifecycle continues without settings rather than failing initialization.
25573
25794
  */
25574
- #loadModels = async (signal) => {
25575
- const models = [];
25576
- let cursor = null;
25577
- try {
25578
- do {
25579
- const decoded = modelListResponseSchema.parse(
25580
- await this.#appServer.request(
25581
- "model/list",
25582
- { cursor, limit: null },
25583
- AbortSignal.any([signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
25584
- )
25585
- );
25586
- models.push(...decoded.data);
25587
- cursor = decoded.nextCursor ?? null;
25588
- } while (cursor !== null && models.length < MODEL_CATALOG_LIMIT);
25589
- } catch (error62) {
25590
- signal.throwIfAborted();
25591
- process.stderr.write(`[codex-acp] model catalog unavailable: ${String(error62)}
25592
- `);
25593
- }
25594
- this.#models = Object.freeze(models.slice(0, MODEL_CATALOG_LIMIT));
25595
- };
25596
- #model = (id) => this.#models.find((model) => model.id === id);
25597
- /**
25598
- * Learns, once per app-server, whether collaboration mode can be applied. An empty settings
25599
- * update is a no-op on a supporting Codex; an older Codex answers an error, which costs the
25600
- * Build/Plan selector alone without changing a restored thread's persisted mode.
25601
- */
25602
- #probeCollaborationMode = async (signal) => {
25603
- if (this.#collaborationModeSupported !== null) {
25604
- return;
25605
- }
25606
- try {
25607
- await this.#appServer.request(
25608
- "thread/settings/update",
25609
- { threadId: this.#nativeSessionId },
25610
- AbortSignal.any([signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
25611
- );
25612
- this.#collaborationModeSupported = true;
25613
- } catch {
25614
- signal.throwIfAborted();
25615
- this.#collaborationModeSupported = false;
25616
- }
25617
- };
25618
- /** The ACP settings Mobius discovers and renders in Run settings. */
25619
- #configOptions = () => {
25620
- const options = [];
25621
- const model = modelSetting(this.#models, this.#selection.model);
25622
- if (model !== null) {
25623
- options.push(model);
25624
- }
25625
- const effort = effortSetting(this.#model(this.#selection.model), this.#selection.effort);
25626
- if (effort !== null) {
25627
- options.push(effort);
25628
- }
25629
- const fastMode = fastModeSetting(this.#model(this.#selection.model), this.#selection.fastMode);
25630
- if (fastMode !== null) {
25631
- options.push(fastMode);
25632
- }
25633
- if (this.#collaborationModeSupported === true) {
25634
- options.push(collaborationModeSetting(this.#selection.collaborationMode));
25635
- }
25636
- options.push(modeSetting(this.#selection.mode));
25637
- return options;
25638
- };
25639
- #selectRestoredThread = (thread) => {
25640
- this.#nativeSessionId = thread.thread.id;
25641
- const supported = supportedSelection(
25642
- this.#models,
25643
- thread.model ?? this.#selection.model,
25644
- thread.reasoningEffort ?? this.#selection.effort
25645
- );
25646
- this.#selection = {
25647
- ...this.#selection,
25648
- ...supported,
25649
- fastMode: thread.serviceTier === SERVICE_TIER_FAST
25650
- };
25651
- };
25652
25795
  #replayHistory = async (turns) => {
25653
25796
  for (const turn of turns ?? []) {
25654
25797
  for (const rawItem of turn.items) {
@@ -25690,95 +25833,6 @@ var CodexAcpAgent = class {
25690
25833
  }
25691
25834
  }
25692
25835
  };
25693
- /**
25694
- * Applies one `session/set_config_option`. Switching models re-resolves the effort the way Codex
25695
- * does — the current effort when the new model supports it, otherwise the model's own default —
25696
- * so the reply never advertises an effort the selected model cannot run.
25697
- */
25698
- #applySelection = (configId, value) => {
25699
- if (configId === FAST_MODE_SETTING_ID) {
25700
- if (typeof value !== "boolean") {
25701
- throw new AcpExecutionError(
25702
- "The requested Codex setting is invalid",
25703
- {},
25704
- "invalid_session_configuration"
25705
- );
25706
- }
25707
- if (value && this.#model(this.#selection.model)?.additionalSpeedTiers?.includes(FAST_TIER) !== true) {
25708
- throw new AcpExecutionError(
25709
- "The selected Codex model has no fast mode",
25710
- {},
25711
- "invalid_session_configuration"
25712
- );
25713
- }
25714
- this.#selection = { ...this.#selection, fastMode: value };
25715
- return;
25716
- }
25717
- if (typeof value !== "string") {
25718
- throw new AcpExecutionError("The requested Codex setting is invalid", {}, "invalid_session_configuration");
25719
- }
25720
- if (configId === MODE_SETTING_ID) {
25721
- if (!AGENT_MODES.some((mode) => mode.id === value)) {
25722
- throw new AcpExecutionError(
25723
- "The requested Codex mode is unavailable",
25724
- {},
25725
- "invalid_session_configuration"
25726
- );
25727
- }
25728
- this.#selection = { ...this.#selection, mode: value };
25729
- this.#policySelected = true;
25730
- return;
25731
- }
25732
- if (configId === COLLABORATION_MODE_SETTING_ID) {
25733
- if (!COLLABORATION_MODES.some((mode) => mode.value === value)) {
25734
- throw new AcpExecutionError(
25735
- "The requested Codex collaboration mode is unavailable",
25736
- {},
25737
- "invalid_session_configuration"
25738
- );
25739
- }
25740
- this.#selection = { ...this.#selection, collaborationMode: value };
25741
- this.#collaborationModeSelected = true;
25742
- return;
25743
- }
25744
- if (configId === MODEL_SETTING_ID) {
25745
- if (value === this.#selection.model) {
25746
- return;
25747
- }
25748
- const model = this.#model(value);
25749
- if (model === void 0) {
25750
- throw new AcpExecutionError(
25751
- "The requested Codex model is unavailable",
25752
- {},
25753
- "invalid_session_configuration"
25754
- );
25755
- }
25756
- const supported = (model.supportedReasoningEfforts ?? []).map((option) => option.reasoningEffort);
25757
- const effort = supported.includes(this.#selection.effort) ? this.#selection.effort : model.defaultReasoningEffort ?? supported[0] ?? "";
25758
- this.#selection = {
25759
- ...this.#selection,
25760
- effort,
25761
- fastMode: this.#selection.fastMode && model.additionalSpeedTiers?.includes(FAST_TIER) === true,
25762
- model: value
25763
- };
25764
- return;
25765
- }
25766
- if (configId === REASONING_EFFORT_SETTING_ID) {
25767
- const supported = (this.#model(this.#selection.model)?.supportedReasoningEfforts ?? []).map(
25768
- (option) => option.reasoningEffort
25769
- );
25770
- if (!supported.includes(value)) {
25771
- throw new AcpExecutionError(
25772
- "The requested Codex reasoning effort is unavailable",
25773
- {},
25774
- "invalid_session_configuration"
25775
- );
25776
- }
25777
- this.#selection = { ...this.#selection, effort: value };
25778
- return;
25779
- }
25780
- throw new AcpExecutionError("The requested Codex setting is unavailable", {}, "invalid_session_configuration");
25781
- };
25782
25836
  #emit = async (update) => {
25783
25837
  const connection = this.#connection;
25784
25838
  if (connection === null || this.#nativeSessionId.length === 0) {
@@ -25803,7 +25857,7 @@ var CodexAcpAgent = class {
25803
25857
  }
25804
25858
  await connection.client.notify(methods.client.session.update, {
25805
25859
  sessionId: this.#nativeSessionId,
25806
- update: { configOptions: this.#configOptions(), sessionUpdate: "config_option_update" }
25860
+ update: { configOptions: this.#settings.configOptions(), sessionUpdate: "config_option_update" }
25807
25861
  });
25808
25862
  };
25809
25863
  // Notifications are serialized so two app-server items cannot interleave into one ACP update
@@ -25843,8 +25897,7 @@ var CodexAcpAgent = class {
25843
25897
  const decoded = threadSettingsUpdatedSchema.safeParse(params);
25844
25898
  if (decoded.success && decoded.data.threadId === this.#nativeSessionId) {
25845
25899
  const mode = decoded.data.threadSettings.collaborationMode?.mode;
25846
- if (mode !== void 0 && mode !== this.#selection.collaborationMode) {
25847
- this.#selection = { ...this.#selection, collaborationMode: mode };
25900
+ if (this.#settings.observeCollaborationMode(mode)) {
25848
25901
  await this.#enqueue(async () => {
25849
25902
  await this.#emitConfigOptionsUpdate();
25850
25903
  });
@@ -25966,7 +26019,7 @@ var CodexAcpAgent = class {
25966
26019
  const decision = await this.#askPermission(
25967
26020
  title2,
25968
26021
  params.itemId,
25969
- AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)
26022
+ AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2)
25970
26023
  );
25971
26024
  void turn;
25972
26025
  this.#appServer.respond(request.id, { decision });
@@ -25988,7 +26041,7 @@ var CodexAcpAgent = class {
25988
26041
  sessionId: this.#nativeSessionId,
25989
26042
  ...decoded.data.itemId == null ? {} : { toolCallId: decoded.data.itemId }
25990
26043
  },
25991
- { cancellationSignal: AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS) }
26044
+ { cancellationSignal: AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2) }
25992
26045
  );
25993
26046
  const content = response.action === "accept" ? Reflect.get(response, "content") : void 0;
25994
26047
  const answers = {};
@@ -26006,7 +26059,7 @@ var CodexAcpAgent = class {
26006
26059
  return;
26007
26060
  }
26008
26061
  const params = decoded.data;
26009
- const signal = AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS);
26062
+ const signal = AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2);
26010
26063
  if (params.mode === "url" && params.url !== void 0) {
26011
26064
  const response2 = await connection.client.request(
26012
26065
  methods.client.elicitation.create,
@@ -26055,38 +26108,12 @@ var CodexAcpAgent = class {
26055
26108
  this.#turn = turn;
26056
26109
  this.#nativeTurnId = null;
26057
26110
  try {
26058
- const selection = this.#selection;
26059
- const mode = AGENT_MODES.find((candidate) => candidate.id === selection.mode) ?? DEFAULT_MODE;
26060
- const supportsFast = this.#model(selection.model)?.additionalSpeedTiers?.includes(FAST_TIER) === true;
26061
26111
  const started = turnSchema.parse(
26062
26112
  (await this.#appServer.request(
26063
26113
  "turn/start",
26064
26114
  {
26065
- // Until a mode is chosen, `config.toml` decides the sandbox and approval
26066
- // policy, and those fields stay off the turn so the host's own setup is
26067
- // inherited rather than overridden.
26068
- ...this.#policySelected ? {
26069
- approvalPolicy: mode.approvalPolicy,
26070
- approvalsReviewer: mode.approvalsReviewer,
26071
- sandboxPolicy: mode.sandboxPolicy
26072
- } : {},
26073
- // The collaboration mode rides on the turn: Codex applies it to the
26074
- // thread, where it persists until changed. "Build" is Codex's `default`
26075
- // mode, so it is only sent once a choice exists to apply.
26076
- ...this.#collaborationModeSupported && (selection.collaborationMode !== "default" || this.#collaborationModeSelected) ? {
26077
- collaborationMode: {
26078
- mode: selection.collaborationMode,
26079
- settings: {
26080
- developer_instructions: null,
26081
- model: selection.model,
26082
- reasoning_effort: selection.effort.length === 0 ? null : selection.effort
26083
- }
26084
- }
26085
- } : {},
26086
- ...selection.effort.length === 0 ? {} : { effort: selection.effort },
26115
+ ...this.#settings.turnParameters(),
26087
26116
  input: input2,
26088
- ...selection.model.length === 0 ? {} : { model: selection.model },
26089
- ...selection.fastMode && supportsFast ? { serviceTier: SERVICE_TIER_FAST } : {},
26090
26117
  threadId: this.#nativeSessionId
26091
26118
  },
26092
26119
  signal
@@ -26155,7 +26182,7 @@ var CodexAcpAgent = class {
26155
26182
  await this.#appServer.request(
26156
26183
  "turn/steer",
26157
26184
  { expectedTurnId: active.turn.id, input: input2, threadId: this.#nativeSessionId },
26158
- AbortSignal.any([signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
26185
+ AbortSignal.any([signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2)])
26159
26186
  )
26160
26187
  );
26161
26188
  if (response.turnId !== active.turn.id) {
@@ -26174,7 +26201,7 @@ var CodexAcpAgent = class {
26174
26201
  await this.#appServer.request(
26175
26202
  "turn/interrupt",
26176
26203
  { threadId: this.#nativeSessionId, turnId: turn.turn.id },
26177
- AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)
26204
+ AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2)
26178
26205
  );
26179
26206
  } catch {
26180
26207
  }
@@ -39735,6 +39762,48 @@ var RetainedAgentProcesses = class {
39735
39762
  };
39736
39763
  };
39737
39764
 
39765
+ // src/acp/runtime-operations.ts
39766
+ var RuntimeOperations = class {
39767
+ #shutdown = new AbortController();
39768
+ #pending = /* @__PURE__ */ new Set();
39769
+ #closing = null;
39770
+ run = async (options, operation) => {
39771
+ const signal = AbortSignal.any([options.signal, this.#shutdown.signal]);
39772
+ signal.throwIfAborted();
39773
+ const pending = Promise.resolve().then(() => operation({ ...options, signal }));
39774
+ this.#pending.add(pending);
39775
+ try {
39776
+ const result = await pending;
39777
+ signal.throwIfAborted();
39778
+ return result;
39779
+ } finally {
39780
+ this.#pending.delete(pending);
39781
+ }
39782
+ };
39783
+ close = (release) => {
39784
+ if (this.#closing !== null) {
39785
+ return this.#closing;
39786
+ }
39787
+ this.#shutdown.abort();
39788
+ this.#closing = (async () => {
39789
+ await Promise.allSettled([...this.#pending]);
39790
+ await release();
39791
+ })();
39792
+ return this.#closing;
39793
+ };
39794
+ };
39795
+ async function waitForPreparation(pending, signal) {
39796
+ signal.throwIfAborted();
39797
+ const cancelled = Promise.withResolvers();
39798
+ const abort = () => cancelled.reject(signal.reason);
39799
+ signal.addEventListener("abort", abort, { once: true });
39800
+ try {
39801
+ return await Promise.race([pending, cancelled.promise]);
39802
+ } finally {
39803
+ signal.removeEventListener("abort", abort);
39804
+ }
39805
+ }
39806
+
39738
39807
  // src/acp/agent-query-processes.ts
39739
39808
  var AgentQueryProcesses = class {
39740
39809
  #processesByQuery;
@@ -39781,7 +39850,7 @@ var AgentQueryProcesses = class {
39781
39850
  prepare = async (options) => {
39782
39851
  const pending = this.#processesByQuery.pending(options.sessionId);
39783
39852
  if (pending !== void 0) {
39784
- const runtime2 = await pending;
39853
+ const runtime2 = await waitForPreparation(pending, options.signal);
39785
39854
  if (runtime2.belongsTo(options.agent.id, options.cwd, options.additionalDirectories)) {
39786
39855
  this.#processesByQuery.touch(options.sessionId, runtime2);
39787
39856
  return runtime2.prepared();
@@ -40060,6 +40129,7 @@ var AgentProcessPool = class {
40060
40129
  // src/acp/agent-runtime-manager.ts
40061
40130
  var SESSION_CONTROL_TIMEOUT_MILLISECONDS = 3e4;
40062
40131
  var AgentRuntimeManager = class {
40132
+ #operations = new RuntimeOperations();
40063
40133
  #processes = new AgentProcessPool();
40064
40134
  #executionProcesses = new RetainedAgentProcesses({
40065
40135
  touch: this.#processes.touch,
@@ -40182,8 +40252,8 @@ var AgentRuntimeManager = class {
40182
40252
  return runtime;
40183
40253
  });
40184
40254
  }
40185
- prepareSession = async (options, metrics = unmeasuredOperationMetrics) => {
40186
- const stored = metrics.measureSync("session-state-read", () => this.#store.read(options.sessionId));
40255
+ prepareSession = async (options, metrics = unmeasuredOperationMetrics) => this.#operations.run(options, async (options2) => {
40256
+ const stored = metrics.measureSync("session-state-read", () => this.#store.read(options2.sessionId));
40187
40257
  if (stored instanceof DeletedAcpStoredSession) {
40188
40258
  throw new AcpExecutionError(
40189
40259
  "The native Agent session was deleted. Start a new chat.",
@@ -40194,19 +40264,22 @@ var AgentRuntimeManager = class {
40194
40264
  if (stored instanceof FoundAcpStoredSession && this.#nativeOperations.has(`${stored.session.agentId}:${stored.session.nativeSessionId}`)) {
40195
40265
  throw new AcpExecutionError("The native session is being managed", {}, "session_busy");
40196
40266
  }
40197
- const pending = this.#executionProcesses.pending(options.sessionId);
40267
+ const pending = this.#executionProcesses.pending(options2.sessionId);
40198
40268
  if (pending !== void 0) {
40199
- const runtime2 = await metrics.measure("session-preparation-wait", async () => await pending);
40200
- if (runtime2.belongsTo(options.agent.id, options.cwd, options.additionalDirectories)) {
40201
- this.#executionProcesses.touch(options.sessionId, runtime2);
40269
+ const runtime2 = await metrics.measure(
40270
+ "session-preparation-wait",
40271
+ async () => await waitForPreparation(pending, options2.signal)
40272
+ );
40273
+ if (runtime2.belongsTo(options2.agent.id, options2.cwd, options2.additionalDirectories)) {
40274
+ this.#executionProcesses.touch(options2.sessionId, runtime2);
40202
40275
  return runtime2.prepared();
40203
40276
  }
40204
- return await this.prepareSession(options, metrics);
40277
+ return await this.prepareSession(options2, metrics);
40205
40278
  }
40206
- const existing = this.#executionProcesses.get(options.sessionId);
40279
+ const existing = this.#executionProcesses.get(options2.sessionId);
40207
40280
  if (existing !== void 0) {
40208
- if (existing.belongsTo(options.agent.id, options.cwd, options.additionalDirectories)) {
40209
- this.#executionProcesses.touch(options.sessionId, existing);
40281
+ if (existing.belongsTo(options2.agent.id, options2.cwd, options2.additionalDirectories)) {
40282
+ this.#executionProcesses.touch(options2.sessionId, existing);
40210
40283
  return existing.prepared();
40211
40284
  }
40212
40285
  if (!existing.canRebind()) {
@@ -40216,85 +40289,91 @@ var AgentRuntimeManager = class {
40216
40289
  "session_identity_mismatch"
40217
40290
  );
40218
40291
  }
40219
- const runtime2 = await this.#replacePreparation(existing, options, metrics);
40292
+ const runtime2 = await this.#replacePreparation(existing, options2, metrics);
40220
40293
  return runtime2.prepared();
40221
40294
  }
40222
- const runtime = await this.#startPreparation(options, metrics);
40295
+ const runtime = await this.#startPreparation(options2, metrics);
40223
40296
  return runtime.prepared();
40224
- };
40297
+ });
40225
40298
  /**
40226
40299
  * Opens a short-lived native ACP session only to read the local Agent's
40227
40300
  * authoritative settings. Its identity and store are private to this
40228
40301
  * operation and never become a Mobius Session.
40229
40302
  */
40230
- inspectAgentSettings = async (options) => await this.#processes.runTransient(
40231
- options.signal,
40232
- async () => await AgentSession.start(
40233
- {
40234
- ...options,
40235
- sessionId: `agent-settings-${crypto.randomUUID()}`
40303
+ inspectAgentSettings = async (options) => this.#operations.run(options, async (options2) => {
40304
+ return await this.#processes.runTransient(
40305
+ options2.signal,
40306
+ async () => await AgentSession.start(
40307
+ {
40308
+ ...options2,
40309
+ sessionId: `agent-settings-${crypto.randomUUID()}`
40310
+ },
40311
+ () => this.#agentSettingsObserver,
40312
+ new MemoryAcpSessionStore()
40313
+ ),
40314
+ async (runtime) => {
40315
+ const prepared = runtime.prepared();
40316
+ const model = options2.model;
40317
+ const configOptions = model === void 0 ? prepared.configOptions : await runtime.configure({
40318
+ ...options2,
40319
+ booleanValue: false,
40320
+ configId: prepared.configOptions.find(
40321
+ (option) => option.id === "model" || option.category === "model"
40322
+ )?.id ?? "model",
40323
+ requestId: "agent-settings-model",
40324
+ sessionId: `agent-settings-${crypto.randomUUID()}`,
40325
+ value: model,
40326
+ valueType: "select"
40327
+ });
40328
+ return new AcpAgentSettingsSnapshot(prepared.agentName, prepared.agentVersion, configOptions);
40236
40329
  },
40237
- () => this.#agentSettingsObserver,
40238
- new MemoryAcpSessionStore()
40239
- ),
40240
- async (runtime) => {
40241
- const prepared = runtime.prepared();
40242
- const model = options.model;
40243
- const configOptions = model === void 0 ? prepared.configOptions : await runtime.configure({
40244
- ...options,
40245
- booleanValue: false,
40246
- configId: prepared.configOptions.find(
40247
- (option) => option.id === "model" || option.category === "model"
40248
- )?.id ?? "model",
40249
- requestId: "agent-settings-model",
40250
- sessionId: `agent-settings-${crypto.randomUUID()}`,
40251
- value: model,
40252
- valueType: "select"
40253
- });
40254
- return new AcpAgentSettingsSnapshot(prepared.agentName, prepared.agentVersion, configOptions);
40255
- },
40256
- async (runtime) => await runtime.close()
40257
- );
40330
+ async (runtime) => await runtime.close()
40331
+ );
40332
+ });
40258
40333
  /**
40259
40334
  * Retained for Agents that expose a separate persisted configuration channel.
40260
40335
  * Use inspectAgentSettings for Agent-scoped settings discovery.
40261
40336
  */
40262
- inspectSession = async (options, metrics = unmeasuredOperationMetrics) => {
40263
- if (this.#executionProcesses.pending(options.sessionId) !== void 0 || this.#executionProcesses.get(options.sessionId) !== void 0) {
40264
- throw new AcpExecutionError("The configuration inspection session is already in use", {}, "session_busy");
40337
+ inspectSession = async (options, metrics = unmeasuredOperationMetrics) => this.#operations.run(options, async (options2) => {
40338
+ if (this.#executionProcesses.pending(options2.sessionId) !== void 0 || this.#executionProcesses.get(options2.sessionId) !== void 0) {
40339
+ throw new AcpExecutionError(
40340
+ "The configuration inspection session is already in use",
40341
+ {},
40342
+ "session_busy"
40343
+ );
40265
40344
  }
40266
- return await this.#executionProcesses.use(options.sessionId, async () => {
40267
- const runtime = await this.#startPreparation(options, metrics);
40345
+ return await this.#executionProcesses.use(options2.sessionId, async () => {
40346
+ const runtime = await this.#startPreparation(options2, metrics);
40268
40347
  try {
40269
40348
  return runtime.prepared();
40270
40349
  } finally {
40271
40350
  try {
40272
- await this.#retireSessionProcess(options.sessionId, runtime, async () => await runtime.close());
40351
+ await this.#retireSessionProcess(options2.sessionId, runtime, async () => await runtime.close());
40273
40352
  } finally {
40274
- this.#store.remove(options.sessionId);
40353
+ this.#store.remove(options2.sessionId);
40275
40354
  }
40276
40355
  }
40277
40356
  });
40278
- };
40279
- prepareExecutionSession = async (options) => {
40280
- const pending = this.#executionProcesses.pending(options.sessionId);
40357
+ });
40358
+ prepareExecutionSession = async (options) => this.#operations.run(options, async (options2) => {
40359
+ const pending = this.#executionProcesses.pending(options2.sessionId);
40281
40360
  if (pending !== void 0) {
40282
- await pending;
40283
- return await this.prepareExecutionSession(options);
40361
+ await waitForPreparation(pending, options2.signal);
40362
+ return await this.prepareExecutionSession(options2);
40284
40363
  }
40285
- const existing = this.#executionProcesses.get(options.sessionId);
40364
+ const existing = this.#executionProcesses.get(options2.sessionId);
40286
40365
  if (existing === void 0) {
40287
- return (await this.#startPreparation(options)).prepared();
40366
+ return (await this.#startPreparation(options2)).prepared();
40288
40367
  }
40289
- if (!existing.belongsTo(options.agent.id, options.cwd, options.additionalDirectories)) {
40368
+ if (!existing.belongsTo(options2.agent.id, options2.cwd, options2.additionalDirectories)) {
40290
40369
  throw new AcpExecutionError(
40291
40370
  "The agent or workspace cannot change after a conversation has started",
40292
40371
  {},
40293
40372
  "session_identity_mismatch"
40294
40373
  );
40295
40374
  }
40296
- if (existing.usesEnvironment(options.agent.environment)) {
40297
- this.#executionProcesses.touch(options.sessionId, existing);
40375
+ if (existing.usesEnvironment(options2.agent.environment)) {
40376
+ this.#executionProcesses.touch(options2.sessionId, existing);
40298
40377
  return existing.prepared();
40299
40378
  }
40300
40379
  if (existing.hasRunningTurn()) {
@@ -40304,15 +40383,15 @@ var AgentRuntimeManager = class {
40304
40383
  "session_busy"
40305
40384
  );
40306
40385
  }
40307
- return (await this.#replaceExecutionPreparation(existing, options)).prepared();
40308
- };
40309
- prepareNativeSessionBrowser = (options) => this.#queryProcesses.prepare(options);
40310
- configureSession = async (options) => {
40311
- return await this.#executionProcesses.use(options.sessionId, async () => {
40312
- const runtime = await this.ensureSession(options);
40313
- return await runtime.configure(options);
40386
+ return (await this.#replaceExecutionPreparation(existing, options2)).prepared();
40387
+ });
40388
+ prepareNativeSessionBrowser = (options) => this.#operations.run(options, (scoped) => this.#queryProcesses.prepare(scoped));
40389
+ configureSession = async (options) => this.#operations.run(options, async (options2) => {
40390
+ return await this.#executionProcesses.use(options2.sessionId, async () => {
40391
+ const runtime = await this.ensureSession(options2);
40392
+ return await runtime.configure(options2);
40314
40393
  });
40315
- };
40394
+ });
40316
40395
  cancelPrompt = async (sessionId) => {
40317
40396
  await this.#executions.cancel(sessionId, async () => {
40318
40397
  const runtime = this.#executionProcesses.get(sessionId);
@@ -40327,19 +40406,19 @@ var AgentRuntimeManager = class {
40327
40406
  }
40328
40407
  });
40329
40408
  };
40330
- steerPrompt = async (options) => {
40331
- if (this.#executions.command(options.sessionId) !== options.targetCommandId) {
40409
+ steerPrompt = async (options) => this.#operations.run(options, async (options2) => {
40410
+ if (this.#executions.command(options2.sessionId) !== options2.targetCommandId) {
40332
40411
  throw new AcpExecutionError("The target turn is no longer active", {}, "steering_target_unavailable");
40333
40412
  }
40334
- const pending = this.#executionProcesses.pending(options.sessionId);
40413
+ const pending = this.#executionProcesses.pending(options2.sessionId);
40335
40414
  if (pending !== void 0) {
40336
- await pending;
40415
+ await waitForPreparation(pending, options2.signal);
40337
40416
  }
40338
- if (this.#executions.command(options.sessionId) !== options.targetCommandId) {
40417
+ if (this.#executions.command(options2.sessionId) !== options2.targetCommandId) {
40339
40418
  throw new AcpExecutionError("The target turn is no longer active", {}, "steering_target_unavailable");
40340
40419
  }
40341
- const runtime = this.#executionProcesses.get(options.sessionId);
40342
- if (runtime === void 0 || !runtime.belongsTo(options.agent.id, options.cwd, options.additionalDirectories)) {
40420
+ const runtime = this.#executionProcesses.get(options2.sessionId);
40421
+ if (runtime === void 0 || !runtime.belongsTo(options2.agent.id, options2.cwd, options2.additionalDirectories)) {
40343
40422
  throw new AcpExecutionError(
40344
40423
  "The target turn execution context is unavailable",
40345
40424
  {},
@@ -40356,8 +40435,8 @@ var AgentRuntimeManager = class {
40356
40435
  deadline.unref();
40357
40436
  try {
40358
40437
  return await runtime.steer({
40359
- ...options,
40360
- signal: AbortSignal.any([options.signal, deadlineController.signal])
40438
+ ...options2,
40439
+ signal: AbortSignal.any([options2.signal, deadlineController.signal])
40361
40440
  });
40362
40441
  } catch (error62) {
40363
40442
  if (error62 instanceof AcpExecutionError) {
@@ -40367,44 +40446,44 @@ var AgentRuntimeManager = class {
40367
40446
  } finally {
40368
40447
  clearTimeout(deadline);
40369
40448
  }
40370
- };
40371
- runPrompt = async (options) => {
40372
- const stored = this.#store.read(options.sessionId);
40449
+ });
40450
+ runPrompt = async (options) => this.#operations.run(options, async (options2) => {
40451
+ const stored = this.#store.read(options2.sessionId);
40373
40452
  if (stored instanceof FoundAcpStoredSession && this.#nativeOperations.has(`${stored.session.agentId}:${stored.session.nativeSessionId}`)) {
40374
40453
  throw new AcpExecutionError("The native session is being managed", {}, "session_busy");
40375
40454
  }
40376
- this.#executions.begin(options.sessionId, options.commandId);
40455
+ this.#executions.begin(options2.sessionId, options2.commandId);
40377
40456
  try {
40378
- if (this.#executions.cancellation(options.sessionId) !== void 0) {
40457
+ if (this.#executions.cancellation(options2.sessionId) !== void 0) {
40379
40458
  return { stopReason: "cancelled" };
40380
40459
  }
40381
- const runtime = await this.ensureSession(options);
40382
- if (this.#nativeOperations.has(`${options.agent.id}:${runtime.nativeSessionId()}`)) {
40460
+ const runtime = await this.ensureSession(options2);
40461
+ if (this.#nativeOperations.has(`${options2.agent.id}:${runtime.nativeSessionId()}`)) {
40383
40462
  throw new AcpExecutionError("The native session is being managed", {}, "session_busy");
40384
40463
  }
40385
- if (this.#executions.cancellation(options.sessionId) !== void 0) {
40464
+ if (this.#executions.cancellation(options2.sessionId) !== void 0) {
40386
40465
  return { stopReason: "cancelled" };
40387
40466
  }
40388
40467
  try {
40389
- const result = await runtime.prompt(options);
40390
- return this.#executions.cancellation(options.sessionId) !== void 0 ? { stopReason: "cancelled" } : result;
40468
+ const result = await runtime.prompt(options2);
40469
+ return this.#executions.cancellation(options2.sessionId) !== void 0 ? { stopReason: "cancelled" } : result;
40391
40470
  } catch (error62) {
40392
- if (this.#executions.cancellation(options.sessionId) !== void 0) {
40393
- await this.#executions.cancellation(options.sessionId);
40471
+ if (this.#executions.cancellation(options2.sessionId) !== void 0) {
40472
+ await this.#executions.cancellation(options2.sessionId);
40394
40473
  return { stopReason: "cancelled" };
40395
40474
  }
40396
40475
  throw error62;
40397
40476
  }
40398
40477
  } catch (error62) {
40399
- const failedRuntime = this.#executionProcesses.get(options.sessionId);
40478
+ const failedRuntime = this.#executionProcesses.get(options2.sessionId);
40400
40479
  if (failedRuntime !== void 0) {
40401
40480
  await this.#retireSessionProcess(
40402
- options.sessionId,
40481
+ options2.sessionId,
40403
40482
  failedRuntime,
40404
40483
  async () => await failedRuntime.close()
40405
40484
  );
40406
40485
  }
40407
- if (this.#executions.cancellation(options.sessionId) !== void 0) {
40486
+ if (this.#executions.cancellation(options2.sessionId) !== void 0) {
40408
40487
  return { stopReason: "cancelled" };
40409
40488
  }
40410
40489
  if (error62 instanceof AcpExecutionError) {
@@ -40415,14 +40494,14 @@ var AgentRuntimeManager = class {
40415
40494
  });
40416
40495
  } finally {
40417
40496
  try {
40418
- await this.#executions.cancellation(options.sessionId);
40497
+ await this.#executions.cancellation(options2.sessionId);
40419
40498
  } finally {
40420
- this.#executions.finish(options.sessionId, options.commandId);
40421
- this.#executionProcesses.touch(options.sessionId);
40499
+ this.#executions.finish(options2.sessionId, options2.commandId);
40500
+ this.#executionProcesses.touch(options2.sessionId);
40422
40501
  this.#processes.notifyChanged();
40423
40502
  }
40424
40503
  }
40425
- };
40504
+ });
40426
40505
  respondPermission = async (options) => {
40427
40506
  const runtime = this.#executionProcesses.get(options.sessionId);
40428
40507
  if (runtime === void 0) {
@@ -40437,7 +40516,7 @@ var AgentRuntimeManager = class {
40437
40516
  }
40438
40517
  await runtime.respondElicitation(options);
40439
40518
  };
40440
- close = async () => {
40519
+ close = async () => this.#operations.close(async () => {
40441
40520
  const sessions = [...this.#executionProcesses.entries()];
40442
40521
  await Promise.all([
40443
40522
  ...sessions.map(
@@ -40445,23 +40524,23 @@ var AgentRuntimeManager = class {
40445
40524
  ),
40446
40525
  this.#queryProcesses.close()
40447
40526
  ]);
40448
- };
40527
+ });
40449
40528
  findSessions = (sessionIds) => sessionIds.flatMap((sessionId) => {
40450
40529
  const stored = this.#store.read(sessionId);
40451
40530
  return stored instanceof FoundAcpStoredSession ? [stored.session] : [];
40452
40531
  });
40453
40532
  findLinkedSessions = (agentId, nativeSessionId) => this.#store.findNative(agentId, nativeSessionId);
40454
40533
  hasPreparedSession = (sessionId, agentId, cwd, additionalDirectories) => this.#executionProcesses.get(sessionId)?.belongsTo(agentId, cwd, additionalDirectories) === true;
40455
- createNativeSession = async (options) => {
40534
+ createNativeSession = async (options) => this.#operations.run(options, async (options2) => {
40456
40535
  const temporarySessionId = `new-${crypto.randomUUID()}`;
40457
- const temporaryOptions = { ...options, sessionId: temporarySessionId };
40536
+ const temporaryOptions = { ...options2, sessionId: temporarySessionId };
40458
40537
  return await this.#executionProcesses.use(temporarySessionId, async () => {
40459
40538
  try {
40460
40539
  const runtime = await this.#startPreparation(temporaryOptions);
40461
40540
  let adopted = false;
40462
40541
  try {
40463
40542
  const nativeSessionId = runtime.nativeSessionId();
40464
- if (!isNativeChatSessionId(options.agent.id, nativeSessionId) || this.#executionProcesses.get(nativeSessionId) !== void 0 || !(this.#store.read(nativeSessionId) instanceof MissingAcpStoredSession)) {
40543
+ if (!isNativeChatSessionId(options2.agent.id, nativeSessionId) || this.#executionProcesses.get(nativeSessionId) !== void 0 || !(this.#store.read(nativeSessionId) instanceof MissingAcpStoredSession)) {
40465
40544
  throw new AcpExecutionError(
40466
40545
  "The Agent returned an invalid new Session ID",
40467
40546
  {},
@@ -40487,36 +40566,36 @@ var AgentRuntimeManager = class {
40487
40566
  this.#store.remove(temporarySessionId);
40488
40567
  }
40489
40568
  });
40490
- };
40491
- ensureSession = async (options) => {
40492
- const existing = this.#executionProcesses.get(options.sessionId);
40569
+ });
40570
+ ensureSession = async (options) => this.#operations.run(options, async (options2) => {
40571
+ const existing = this.#executionProcesses.get(options2.sessionId);
40493
40572
  if (existing !== void 0) {
40494
- if (!existing.belongsTo(options.agent.id, options.cwd, options.additionalDirectories)) {
40573
+ if (!existing.belongsTo(options2.agent.id, options2.cwd, options2.additionalDirectories)) {
40495
40574
  throw new AcpExecutionError(
40496
40575
  "The agent or workspace cannot change after a conversation has started",
40497
40576
  {},
40498
40577
  "session_identity_mismatch"
40499
40578
  );
40500
40579
  }
40501
- this.#executionProcesses.touch(options.sessionId, existing);
40580
+ this.#executionProcesses.touch(options2.sessionId, existing);
40502
40581
  return existing;
40503
40582
  }
40504
- await this.prepareSession(options);
40505
- const started = this.#executionProcesses.get(options.sessionId);
40583
+ await this.prepareSession(options2);
40584
+ const started = this.#executionProcesses.get(options2.sessionId);
40506
40585
  if (started === void 0) {
40507
40586
  throw new AcpExecutionError("ACP session did not start");
40508
40587
  }
40509
40588
  return started;
40510
- };
40511
- listNativeSessions = async (options, cursor) => {
40589
+ });
40590
+ listNativeSessions = async (options, cursor) => this.#operations.run(options, async (options2) => {
40512
40591
  return await this.#queryProcesses.use(
40513
- options,
40514
- async (runtime) => await runtime.listNativeSessions(cursor, options.signal)
40592
+ options2,
40593
+ async (runtime) => await runtime.listNativeSessions(cursor, options2.signal)
40515
40594
  );
40516
- };
40517
- previewNativeSession = async (options, nativeSessionId) => {
40518
- const key = `${options.agent.id}:${nativeSessionId}`;
40519
- const linked = this.#store.findNative(options.agent.id, nativeSessionId);
40595
+ });
40596
+ previewNativeSession = async (options, nativeSessionId) => this.#operations.run(options, async (options2) => {
40597
+ const key = `${options2.agent.id}:${nativeSessionId}`;
40598
+ const linked = this.#store.findNative(options2.agent.id, nativeSessionId);
40520
40599
  if (this.#nativeOperations.has(key) || linked.some(
40521
40600
  (entry) => this.#executions.command(entry.sessionId) !== void 0 || this.#executionProcesses.pending(entry.sessionId) !== void 0
40522
40601
  )) {
@@ -40528,18 +40607,18 @@ var AgentRuntimeManager = class {
40528
40607
  }
40529
40608
  this.#nativeOperations.add(key);
40530
40609
  try {
40531
- return await this.#queryProcesses.preview(options, nativeSessionId);
40610
+ return await this.#queryProcesses.preview(options2, nativeSessionId);
40532
40611
  } finally {
40533
40612
  this.#nativeOperations.delete(key);
40534
40613
  }
40535
- };
40536
- loadSessionHistory = async (options) => {
40537
- return await this.#executionProcesses.use(options.sessionId, async () => {
40538
- const runtime = await this.ensureSession(options);
40539
- const stored = this.#store.read(options.sessionId);
40614
+ });
40615
+ loadSessionHistory = async (options) => this.#operations.run(options, async (options2) => {
40616
+ return await this.#executionProcesses.use(options2.sessionId, async () => {
40617
+ const runtime = await this.ensureSession(options2);
40618
+ const stored = this.#store.read(options2.sessionId);
40540
40619
  if (stored instanceof FoundAcpStoredSession && this.#nativeHistoryReader !== null) {
40541
40620
  const history = await this.#nativeHistoryReader.read(
40542
- options,
40621
+ options2,
40543
40622
  stored.session.nativeSessionId,
40544
40623
  runtime.nativeHistoryTurn
40545
40624
  );
@@ -40547,15 +40626,15 @@ var AgentRuntimeManager = class {
40547
40626
  return history;
40548
40627
  }
40549
40628
  }
40550
- return await runtime.loadHistory(options.signal);
40629
+ return await runtime.loadHistory(options2.signal);
40551
40630
  });
40552
- };
40553
- openNativeSession = async (options, origin) => {
40554
- const key = `${options.agent.id}:${origin.nativeSessionId}`;
40631
+ });
40632
+ openNativeSession = async (options, origin) => this.#operations.run(options, async (options2) => {
40633
+ const key = `${options2.agent.id}:${origin.nativeSessionId}`;
40555
40634
  if (this.#nativeOperations.has(key)) {
40556
40635
  throw new AcpExecutionError("The native session is being managed", {}, "session_busy");
40557
40636
  }
40558
- const linked = this.#store.findNative(options.agent.id, origin.nativeSessionId);
40637
+ const linked = this.#store.findNative(options2.agent.id, origin.nativeSessionId);
40559
40638
  if (linked.some(
40560
40639
  (entry) => this.#executions.command(entry.sessionId) !== void 0 || this.#executionProcesses.pending(entry.sessionId) !== void 0
40561
40640
  )) {
@@ -40569,7 +40648,7 @@ var AgentRuntimeManager = class {
40569
40648
  if (origin.kind === "import" && existing !== void 0) {
40570
40649
  return await this.#executionProcesses.use(existing.sessionId, async () => {
40571
40650
  const runtime = await this.ensureSession({
40572
- ...options,
40651
+ ...options2,
40573
40652
  sessionId: existing.sessionId
40574
40653
  });
40575
40654
  if (this.#executions.command(existing.sessionId) !== void 0 || this.#nativeOperations.has(key)) {
@@ -40591,18 +40670,22 @@ var AgentRuntimeManager = class {
40591
40670
  }
40592
40671
  });
40593
40672
  }
40594
- 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) {
40595
- throw new AcpExecutionError("The destination conversation already exists", {}, "session_identity_mismatch");
40673
+ 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) {
40674
+ throw new AcpExecutionError(
40675
+ "The destination conversation already exists",
40676
+ {},
40677
+ "session_identity_mismatch"
40678
+ );
40596
40679
  }
40597
- return await this.#executionProcesses.use(options.sessionId, async () => {
40680
+ return await this.#executionProcesses.use(options2.sessionId, async () => {
40598
40681
  this.#nativeOperations.add(key);
40599
40682
  try {
40600
- const runtime = await this.#startPreparation({ ...options, origin });
40601
- const openedKey = `${options.agent.id}:${runtime.nativeSessionId()}`;
40683
+ const runtime = await this.#startPreparation({ ...options2, origin });
40684
+ const openedKey = `${options2.agent.id}:${runtime.nativeSessionId()}`;
40602
40685
  this.#nativeOperations.add(openedKey);
40603
40686
  try {
40604
40687
  return {
40605
- sessionId: options.sessionId,
40688
+ sessionId: options2.sessionId,
40606
40689
  prepared: runtime.prepared()
40607
40690
  };
40608
40691
  } finally {
@@ -40610,11 +40693,11 @@ var AgentRuntimeManager = class {
40610
40693
  this.#processes.notifyChanged();
40611
40694
  }
40612
40695
  } catch (error62) {
40613
- this.#store.remove(options.sessionId);
40614
- const runtime = this.#executionProcesses.get(options.sessionId);
40696
+ this.#store.remove(options2.sessionId);
40697
+ const runtime = this.#executionProcesses.get(options2.sessionId);
40615
40698
  if (runtime !== void 0) {
40616
40699
  await this.#retireSessionProcess(
40617
- options.sessionId,
40700
+ options2.sessionId,
40618
40701
  runtime,
40619
40702
  async () => await runtime.closeProcess()
40620
40703
  );
@@ -40624,11 +40707,11 @@ var AgentRuntimeManager = class {
40624
40707
  this.#nativeOperations.delete(key);
40625
40708
  }
40626
40709
  });
40627
- };
40628
- deleteNativeSession = async (options, nativeSessionId) => {
40629
- return await this.#queryProcesses.use(options, async (runtime) => {
40630
- const key = `${options.agent.id}:${nativeSessionId}`;
40631
- const linked = this.#store.findNative(options.agent.id, nativeSessionId);
40710
+ });
40711
+ deleteNativeSession = async (options, nativeSessionId) => this.#operations.run(options, async (options2) => {
40712
+ return await this.#queryProcesses.use(options2, async (runtime) => {
40713
+ const key = `${options2.agent.id}:${nativeSessionId}`;
40714
+ const linked = this.#store.findNative(options2.agent.id, nativeSessionId);
40632
40715
  if (this.#nativeOperations.has(key) || linked.some(
40633
40716
  (entry) => this.#executions.command(entry.sessionId) !== void 0 || this.#executionProcesses.pending(entry.sessionId) !== void 0
40634
40717
  )) {
@@ -40646,11 +40729,11 @@ var AgentRuntimeManager = class {
40646
40729
  await this.#retireSessionProcess(entry.sessionId, active, async () => await active.close());
40647
40730
  }
40648
40731
  }
40649
- options.signal.throwIfAborted();
40650
- await runtime.deleteNativeSession(nativeSessionId, options.signal);
40651
- const deleted = this.#store.markDeleted(options.agent.id, nativeSessionId);
40732
+ options2.signal.throwIfAborted();
40733
+ await runtime.deleteNativeSession(nativeSessionId, options2.signal);
40734
+ const deleted = this.#store.markDeleted(options2.agent.id, nativeSessionId);
40652
40735
  if (runtime.nativeSessionId() === nativeSessionId) {
40653
- await this.#queryProcesses.retire(options.sessionId, runtime);
40736
+ await this.#queryProcesses.retire(options2.sessionId, runtime);
40654
40737
  }
40655
40738
  return deleted;
40656
40739
  } finally {
@@ -40658,7 +40741,7 @@ var AgentRuntimeManager = class {
40658
40741
  this.#processes.notifyChanged();
40659
40742
  }
40660
40743
  });
40661
- };
40744
+ });
40662
40745
  };
40663
40746
 
40664
40747
  // src/agent-catalog/publish-agent-catalog.ts