@moxt-ai/mobius 0.0.129 → 0.0.131

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.
@@ -3,81 +3,15 @@ import { captureProcessTree, stopProcessTree } from "../../process/executable.js
3
3
  import { AcpExecutionError } from "../acp-error.js";
4
4
  import { acpEndpointTerminationError, } from "../in-process/acp-endpoint.js";
5
5
  import { CodexAppServerClient } from "./app-server-client.js";
6
- import { commandApprovalParamsSchema, fileChangeApprovalParamsSchema, mcpElicitationParamsSchema, modelListResponseSchema, reasoningTextDeltaParamsSchema, requestUserInputParamsSchema, threadForkResponseSchema, threadListResponseSchema, threadResumeResponseSchema, threadSettingsUpdatedSchema, threadStartResponseSchema, turnNotificationSchema, turnSchema, turnSteerResponseSchema, } from "./app-server-protocol.js";
6
+ import { commandApprovalParamsSchema, fileChangeApprovalParamsSchema, mcpElicitationParamsSchema, reasoningTextDeltaParamsSchema, requestUserInputParamsSchema, threadForkResponseSchema, threadListResponseSchema, threadResumeResponseSchema, threadSettingsUpdatedSchema, threadStartResponseSchema, turnNotificationSchema, turnSchema, turnSteerResponseSchema, } from "./app-server-protocol.js";
7
7
  import { agentMessageMeta, decodeThreadItem, reasoningText, toolCallUpdate } from "./items.js";
8
+ import { CodexSettings } from "./settings.js";
8
9
  const APPROVAL_REASON_CHARACTER_LIMIT = 500;
9
10
  const APPROVAL_TIMEOUT_MILLISECONDS = 3_600_000;
10
11
  const CODEX_AGENT_VERSION = "0.154.0";
11
12
  // Listing a directory must answer promptly: it is an interactive browser request, not a turn.
12
13
  const SESSION_LIST_TIMEOUT_MILLISECONDS = 30_000;
13
- // The setting identifiers Mobius matches on. These are the ids the retired
14
- // `@agentclientprotocol/codex-acp` adapter advertised, so conversations that stored a selection
15
- // under them keep applying after the move in-process.
16
- const MODEL_SETTING_ID = "model";
17
- const REASONING_EFFORT_SETTING_ID = "reasoning_effort";
18
- const MODE_SETTING_ID = "mode";
19
- const FAST_MODE_SETTING_ID = "fast-mode";
20
- const COLLABORATION_MODE_SETTING_ID = "collaboration_mode";
21
- const MODEL_CATALOG_LIMIT = 1_000;
22
- // `additionalSpeedTiers` and `serviceTier` are two vocabularies for one concept: a model advertises
23
- // "fast" while the thread reports the resolved tier as "priority". Fast mode is offered per model,
24
- // because most models have no speed tier at all.
25
- const FAST_TIER = "fast";
26
- const SERVICE_TIER_FAST = "priority";
27
14
  const CODEX_COMMANDS = Object.freeze([{ description: "Compact the conversation context", name: "compact" }]);
28
- const WORKSPACE_WRITE_POLICY = Object.freeze({
29
- excludeSlashTmp: false,
30
- excludeTmpdirEnvVar: false,
31
- networkAccess: false,
32
- type: "workspaceWrite",
33
- writableRoots: [],
34
- });
35
- /**
36
- * The approval and sandboxing presets Mobius offers, matching the adapter this Agent replaced so an
37
- * existing conversation's stored selection keeps its meaning. Each preset carries the full policy
38
- * pair, because Codex takes approval and sandboxing together.
39
- */
40
- const READ_ONLY_MODE = Object.freeze({
41
- approvalPolicy: "on-request",
42
- approvalsReviewer: "user",
43
- description: "Always ask to edit external files and use the internet",
44
- id: "read-only",
45
- name: "Ask for approval",
46
- sandboxPolicy: WORKSPACE_WRITE_POLICY,
47
- });
48
- const AGENT_MODE = Object.freeze({
49
- approvalPolicy: "on-request",
50
- approvalsReviewer: "auto_review",
51
- description: "Only ask for actions detected as potentially unsafe",
52
- id: "agent",
53
- name: "Approve for me",
54
- sandboxPolicy: WORKSPACE_WRITE_POLICY,
55
- });
56
- const FULL_ACCESS_MODE = Object.freeze({
57
- approvalPolicy: "never",
58
- approvalsReviewer: "user",
59
- description: "Unrestricted access to the internet and any file on your computer",
60
- id: "agent-full-access",
61
- name: "Full access",
62
- sandboxPolicy: { type: "dangerFullAccess" },
63
- });
64
- const AGENT_MODES = Object.freeze([READ_ONLY_MODE, AGENT_MODE, FULL_ACCESS_MODE]);
65
- const DEFAULT_MODE = AGENT_MODE;
66
- /**
67
- * The mode the session opens in, from the same `INITIAL_AGENT_MODE` variable the adapter this Agent
68
- * replaced honoured. The default is only a fallback: a host that configured the variable keeps the
69
- * behavior it had.
70
- */
71
- function initialMode(environment) {
72
- const requested = environment["INITIAL_AGENT_MODE"];
73
- if (requested === undefined) {
74
- return DEFAULT_MODE.id;
75
- }
76
- return AGENT_MODES.some((mode) => mode.id === requested) ? requested : DEFAULT_MODE.id;
77
- }
78
- function capitalize(value) {
79
- return value.length === 0 ? value : value.charAt(0).toUpperCase() + value.slice(1);
80
- }
81
15
  /** The choices Mobius offers when the app-server asks it to approve a local side effect. */
82
16
  const APPROVAL_OPTIONS = Object.freeze([
83
17
  { kind: "allow_once", name: "Allow once", optionId: "accept" },
@@ -168,130 +102,6 @@ function steeringPromptInput(prompt) {
168
102
  }
169
103
  return input;
170
104
  }
171
- function modelValues(models) {
172
- return models.map((model) => ({
173
- description: model.description ?? "",
174
- name: model.displayName ?? model.id,
175
- value: model.id,
176
- }));
177
- }
178
- function effortValues(model) {
179
- return (model?.supportedReasoningEfforts ?? []).map((option) => ({
180
- description: option.description ?? "",
181
- name: capitalize(option.reasoningEffort),
182
- value: option.reasoningEffort,
183
- }));
184
- }
185
- function supportedSelection(models, reportedModel, reportedEffort) {
186
- const model = models.find((candidate) => candidate.id === reportedModel) ??
187
- models.find((candidate) => candidate.isDefault === true) ??
188
- models[0];
189
- if (model === undefined) {
190
- return { model: reportedModel, effort: reportedEffort };
191
- }
192
- const efforts = model.supportedReasoningEfforts ?? [];
193
- return {
194
- model: model.id,
195
- effort: efforts.some((candidate) => candidate.reasoningEffort === reportedEffort)
196
- ? reportedEffort
197
- : (model.defaultReasoningEffort ?? efforts[0]?.reasoningEffort ?? ""),
198
- };
199
- }
200
- function modelSetting(models, currentValue) {
201
- const values = modelValues(models);
202
- // A model left in config.toml may be absent from the account's catalog. Offer a catalog model
203
- // as the selection so a new Session can start with a model Codex actually supports.
204
- const current = values.some((value) => value.value === currentValue)
205
- ? currentValue
206
- : (models.find((model) => model.isDefault === true)?.id ?? values[0]?.value ?? "");
207
- if (current.length === 0) {
208
- return null;
209
- }
210
- return {
211
- category: "model",
212
- currentValue: current,
213
- description: "Model Codex uses for the session",
214
- id: MODEL_SETTING_ID,
215
- name: "Model",
216
- options: values,
217
- type: "select",
218
- };
219
- }
220
- function modeSetting(currentValue) {
221
- return {
222
- category: "mode",
223
- currentValue,
224
- description: "Approval and sandboxing preset for the session",
225
- id: MODE_SETTING_ID,
226
- name: "Mode",
227
- options: AGENT_MODES.map((mode) => ({
228
- description: mode.description,
229
- name: mode.name,
230
- value: mode.id,
231
- })),
232
- type: "select",
233
- };
234
- }
235
- /**
236
- * How Codex collaborates on subsequent turns. "Build" is Codex's `default` mode; "Plan" makes Codex
237
- * research and propose a plan before making changes. The ids match the retired
238
- * `@agentclientprotocol/codex-acp` adapter so a saved selection keeps applying.
239
- */
240
- const COLLABORATION_MODES = Object.freeze([
241
- { description: "Codex answers and makes changes directly", name: "Build", value: "default" },
242
- { description: "Codex plans before making changes", name: "Plan", value: "plan" },
243
- ]);
244
- function collaborationModeSetting(currentValue) {
245
- const current = COLLABORATION_MODES.some((mode) => mode.value === currentValue)
246
- ? currentValue
247
- : (COLLABORATION_MODES[0]?.value ?? "default");
248
- return {
249
- category: "collaboration_mode",
250
- currentValue: current,
251
- description: "How Codex collaborates for subsequent turns",
252
- id: COLLABORATION_MODE_SETTING_ID,
253
- name: "Collaboration mode",
254
- options: [...COLLABORATION_MODES],
255
- type: "select",
256
- };
257
- }
258
- /**
259
- * Fast mode is a toggle, and it is only offered for a model that has a speed tier. A model without
260
- * one is not a disabled toggle: switching to it removes the setting, which is how the adapter this
261
- * Agent replaced behaved and why the option disappears rather than greys out.
262
- */
263
- function fastModeSetting(model, enabled) {
264
- if (model?.additionalSpeedTiers?.includes(FAST_TIER) !== true) {
265
- return null;
266
- }
267
- return {
268
- category: "model_config",
269
- currentValue: enabled,
270
- description: "1.5x speed, increased usage",
271
- id: FAST_MODE_SETTING_ID,
272
- name: "Fast mode",
273
- type: "boolean",
274
- };
275
- }
276
- function effortSetting(model, currentValue) {
277
- const values = effortValues(model);
278
- if (values.length === 0) {
279
- return null;
280
- }
281
- const current = values.some((value) => value.value === currentValue) ? currentValue : (values[0]?.value ?? "");
282
- if (current.length === 0) {
283
- return null;
284
- }
285
- return {
286
- category: "thought_level",
287
- currentValue: current,
288
- description: "How much reasoning effort the model should use",
289
- id: REASONING_EFFORT_SETTING_ID,
290
- name: "Reasoning effort",
291
- options: values,
292
- type: "select",
293
- };
294
- }
295
105
  function userInputSchema(questions) {
296
106
  const properties = {};
297
107
  const required = [];
@@ -330,31 +140,13 @@ export class CodexAcpAgent {
330
140
  terminated;
331
141
  #closePromise = null;
332
142
  #connection = null;
333
- #models = [];
143
+ #settings;
334
144
  #nativeSessionId = "";
335
- // Whether the current turn must carry a policy at all. Until the user picks a mode, Codex's own
336
- // configuration decides, so `turn/start` omits the fields and inherits what the host set up.
337
- #policySelected = false;
338
- // Whether a collaboration mode choice has been made in this session. A restored thread keeps
339
- // the mode Codex already persisted, so the first turn does not reset it to Build.
340
- #collaborationModeSelected = false;
341
- // Whether the app-server accepts collaboration mode on `turn/start`, probed once per
342
- // app-server. An older Codex rejects the experimental field, and the setting must disappear
343
- // rather than break every turn.
344
- #collaborationModeSupported = null;
345
- #selection;
346
145
  #streamedReasoningItemIds = new Set();
347
146
  #turn = null;
348
147
  #nativeTurnId = null;
349
148
  #updateTail = Promise.resolve();
350
149
  constructor(options) {
351
- this.#selection = {
352
- collaborationMode: "default",
353
- effort: "",
354
- fastMode: false,
355
- mode: initialMode(options.environment),
356
- model: "",
357
- };
358
150
  this.#appServer = new CodexAppServerClient({
359
151
  command: options.command,
360
152
  cwd: options.cwd,
@@ -368,6 +160,7 @@ export class CodexAcpAgent {
368
160
  },
369
161
  },
370
162
  });
163
+ this.#settings = new CodexSettings(this.#appServer, options.environment);
371
164
  this.terminated = this.#appServer.terminated;
372
165
  void this.terminated.then((termination) => {
373
166
  this.#turn?.completion.reject(acpEndpointTerminationError(termination));
@@ -399,38 +192,31 @@ export class CodexAcpAgent {
399
192
  // session it was given instead of imposing policy the user did not ask for.
400
193
  const created = threadStartResponseSchema.parse(await this.#appServer.request("thread/start", { cwd: context.params.cwd }, AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])));
401
194
  this.#nativeSessionId = created.thread.id;
402
- // A new thread always starts in the default mode, so only the model and effort come
403
- // from Codex. The mode is re-applied on the first turn.
404
- const supported = supportedSelection(this.#models, created.model ?? "", created.reasoningEffort ?? "");
405
- this.#selection = {
406
- ...this.#selection,
407
- collaborationMode: "default",
408
- ...supported,
409
- };
410
- this.#collaborationModeSelected = false;
411
- await this.#probeCollaborationMode(context.signal);
195
+ this.#settings.selectNewThread(created);
196
+ await this.#settings.probeCollaborationMode(this.#nativeSessionId, context.signal);
412
197
  await this.#emitAvailableCommands();
413
198
  // The settings Mobius discovers come from this response. Without them the Run
414
199
  // settings panel has nothing to render and saved selections cannot be re-applied.
415
- return { configOptions: this.#configOptions(), sessionId: created.thread.id };
200
+ return { configOptions: this.#settings.configOptions(), sessionId: created.thread.id };
416
201
  })
417
202
  .onRequest(methods.agent.session.setConfigOption, async (context) => {
418
- this.#applySelection(context.params.configId, context.params.value);
419
- return { configOptions: this.#configOptions() };
203
+ this.#settings.applySelection(context.params.configId, context.params.value);
204
+ return { configOptions: this.#settings.configOptions() };
420
205
  })
421
206
  // Mobius routes a `category: "mode"` selection here rather than through
422
207
  // set_config_option, so the mode needs its own entry point.
423
208
  .onRequest(methods.agent.session.setMode, async (context) => {
424
- this.#applySelection(MODE_SETTING_ID, context.params.modeId);
209
+ this.#settings.applySelection("mode", context.params.modeId);
425
210
  return {};
426
211
  })
427
212
  .onRequest(methods.agent.session.load, async (context) => {
428
213
  const resumed = threadResumeResponseSchema.parse(await this.#appServer.request("thread/resume", { cwd: context.params.cwd, excludeTurns: false, threadId: context.params.sessionId }, AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])));
429
- this.#selectRestoredThread(resumed);
430
- await this.#probeCollaborationMode(context.signal);
214
+ this.#nativeSessionId = resumed.thread.id;
215
+ this.#settings.selectRestoredThread(resumed);
216
+ await this.#settings.probeCollaborationMode(this.#nativeSessionId, context.signal);
431
217
  await this.#replayHistory(resumed.turns);
432
218
  await this.#emitAvailableCommands();
433
- return { configOptions: this.#configOptions() };
219
+ return { configOptions: this.#settings.configOptions() };
434
220
  })
435
221
  .onRequest(methods.agent.session.fork, async (context) => {
436
222
  const forked = threadForkResponseSchema.parse(await this.#appServer.request("thread/fork", {
@@ -438,18 +224,20 @@ export class CodexAcpAgent {
438
224
  excludeTurns: false,
439
225
  threadId: context.params.sessionId,
440
226
  }, AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])));
441
- this.#selectRestoredThread(forked);
442
- await this.#probeCollaborationMode(context.signal);
227
+ this.#nativeSessionId = forked.thread.id;
228
+ this.#settings.selectRestoredThread(forked);
229
+ await this.#settings.probeCollaborationMode(this.#nativeSessionId, context.signal);
443
230
  await this.#replayHistory(forked.turns);
444
231
  await this.#emitAvailableCommands();
445
- return { configOptions: this.#configOptions(), sessionId: forked.thread.id };
232
+ return { configOptions: this.#settings.configOptions(), sessionId: forked.thread.id };
446
233
  })
447
234
  .onRequest(methods.agent.session.resume, async (context) => {
448
235
  const resumed = threadResumeResponseSchema.parse(await this.#appServer.request("thread/resume", { cwd: context.params.cwd, excludeTurns: true, threadId: context.params.sessionId }, AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])));
449
- this.#selectRestoredThread(resumed);
450
- await this.#probeCollaborationMode(context.signal);
236
+ this.#nativeSessionId = resumed.thread.id;
237
+ this.#settings.selectRestoredThread(resumed);
238
+ await this.#settings.probeCollaborationMode(this.#nativeSessionId, context.signal);
451
239
  await this.#emitAvailableCommands();
452
- return { configOptions: this.#configOptions() };
240
+ return { configOptions: this.#settings.configOptions() };
453
241
  })
454
242
  .onRequest(methods.agent.session.prompt, async (context) => {
455
243
  if (isCompactPrompt(context.params.prompt)) {
@@ -484,7 +272,7 @@ export class CodexAcpAgent {
484
272
  /** Starts the app-server, performs its handshake, and reads the model catalog Codex offers. */
485
273
  initialize = async (signal) => {
486
274
  await this.#appServer.initialize(signal);
487
- await this.#loadModels(signal);
275
+ await this.#settings.loadModels(signal);
488
276
  };
489
277
  /**
490
278
  * Releases the app-server and every process it started. Mirrors the adapter path's teardown so a
@@ -512,71 +300,6 @@ export class CodexAcpAgent {
512
300
  * the Run settings panel its model selector; it must not cost the conversation itself, so the
513
301
  * turn lifecycle continues without settings rather than failing initialization.
514
302
  */
515
- #loadModels = async (signal) => {
516
- const models = [];
517
- let cursor = null;
518
- try {
519
- do {
520
- const decoded = modelListResponseSchema.parse(await this.#appServer.request("model/list", { cursor, limit: null }, AbortSignal.any([signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])));
521
- models.push(...decoded.data);
522
- cursor = decoded.nextCursor ?? null;
523
- } while (cursor !== null && models.length < MODEL_CATALOG_LIMIT);
524
- }
525
- catch (error) {
526
- signal.throwIfAborted();
527
- process.stderr.write(`[codex-acp] model catalog unavailable: ${String(error)}\n`);
528
- }
529
- this.#models = Object.freeze(models.slice(0, MODEL_CATALOG_LIMIT));
530
- };
531
- #model = (id) => this.#models.find((model) => model.id === id);
532
- /**
533
- * Learns, once per app-server, whether collaboration mode can be applied. An empty settings
534
- * update is a no-op on a supporting Codex; an older Codex answers an error, which costs the
535
- * Build/Plan selector alone without changing a restored thread's persisted mode.
536
- */
537
- #probeCollaborationMode = async (signal) => {
538
- if (this.#collaborationModeSupported !== null) {
539
- return;
540
- }
541
- try {
542
- await this.#appServer.request("thread/settings/update", { threadId: this.#nativeSessionId }, AbortSignal.any([signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)]));
543
- this.#collaborationModeSupported = true;
544
- }
545
- catch {
546
- signal.throwIfAborted();
547
- this.#collaborationModeSupported = false;
548
- }
549
- };
550
- /** The ACP settings Mobius discovers and renders in Run settings. */
551
- #configOptions = () => {
552
- const options = [];
553
- const model = modelSetting(this.#models, this.#selection.model);
554
- if (model !== null) {
555
- options.push(model);
556
- }
557
- const effort = effortSetting(this.#model(this.#selection.model), this.#selection.effort);
558
- if (effort !== null) {
559
- options.push(effort);
560
- }
561
- const fastMode = fastModeSetting(this.#model(this.#selection.model), this.#selection.fastMode);
562
- if (fastMode !== null) {
563
- options.push(fastMode);
564
- }
565
- if (this.#collaborationModeSupported === true) {
566
- options.push(collaborationModeSetting(this.#selection.collaborationMode));
567
- }
568
- options.push(modeSetting(this.#selection.mode));
569
- return options;
570
- };
571
- #selectRestoredThread = (thread) => {
572
- this.#nativeSessionId = thread.thread.id;
573
- const supported = supportedSelection(this.#models, thread.model ?? this.#selection.model, thread.reasoningEffort ?? this.#selection.effort);
574
- this.#selection = {
575
- ...this.#selection,
576
- ...supported,
577
- fastMode: thread.serviceTier === SERVICE_TIER_FAST,
578
- };
579
- };
580
303
  #replayHistory = async (turns) => {
581
304
  for (const turn of turns ?? []) {
582
305
  for (const rawItem of turn.items) {
@@ -620,74 +343,6 @@ export class CodexAcpAgent {
620
343
  }
621
344
  }
622
345
  };
623
- /**
624
- * Applies one `session/set_config_option`. Switching models re-resolves the effort the way Codex
625
- * does — the current effort when the new model supports it, otherwise the model's own default —
626
- * so the reply never advertises an effort the selected model cannot run.
627
- */
628
- #applySelection = (configId, value) => {
629
- if (configId === FAST_MODE_SETTING_ID) {
630
- if (typeof value !== "boolean") {
631
- throw new AcpExecutionError("The requested Codex setting is invalid", {}, "invalid_session_configuration");
632
- }
633
- // A model without a speed tier has no fast mode, so enabling it there would advertise a
634
- // capability the next turn cannot honour.
635
- if (value && this.#model(this.#selection.model)?.additionalSpeedTiers?.includes(FAST_TIER) !== true) {
636
- throw new AcpExecutionError("The selected Codex model has no fast mode", {}, "invalid_session_configuration");
637
- }
638
- this.#selection = { ...this.#selection, fastMode: value };
639
- return;
640
- }
641
- if (typeof value !== "string") {
642
- throw new AcpExecutionError("The requested Codex setting is invalid", {}, "invalid_session_configuration");
643
- }
644
- if (configId === MODE_SETTING_ID) {
645
- if (!AGENT_MODES.some((mode) => mode.id === value)) {
646
- throw new AcpExecutionError("The requested Codex mode is unavailable", {}, "invalid_session_configuration");
647
- }
648
- this.#selection = { ...this.#selection, mode: value };
649
- this.#policySelected = true;
650
- return;
651
- }
652
- if (configId === COLLABORATION_MODE_SETTING_ID) {
653
- if (!COLLABORATION_MODES.some((mode) => mode.value === value)) {
654
- throw new AcpExecutionError("The requested Codex collaboration mode is unavailable", {}, "invalid_session_configuration");
655
- }
656
- this.#selection = { ...this.#selection, collaborationMode: value };
657
- this.#collaborationModeSelected = true;
658
- return;
659
- }
660
- if (configId === MODEL_SETTING_ID) {
661
- if (value === this.#selection.model) {
662
- return;
663
- }
664
- const model = this.#model(value);
665
- if (model === undefined) {
666
- throw new AcpExecutionError("The requested Codex model is unavailable", {}, "invalid_session_configuration");
667
- }
668
- const supported = (model.supportedReasoningEfforts ?? []).map((option) => option.reasoningEffort);
669
- const effort = supported.includes(this.#selection.effort)
670
- ? this.#selection.effort
671
- : (model.defaultReasoningEffort ?? supported[0] ?? "");
672
- // Fast mode follows the model: a model with no speed tier drops a fast mode that was on.
673
- this.#selection = {
674
- ...this.#selection,
675
- effort,
676
- fastMode: this.#selection.fastMode && model.additionalSpeedTiers?.includes(FAST_TIER) === true,
677
- model: value,
678
- };
679
- return;
680
- }
681
- if (configId === REASONING_EFFORT_SETTING_ID) {
682
- const supported = (this.#model(this.#selection.model)?.supportedReasoningEfforts ?? []).map((option) => option.reasoningEffort);
683
- if (!supported.includes(value)) {
684
- throw new AcpExecutionError("The requested Codex reasoning effort is unavailable", {}, "invalid_session_configuration");
685
- }
686
- this.#selection = { ...this.#selection, effort: value };
687
- return;
688
- }
689
- throw new AcpExecutionError("The requested Codex setting is unavailable", {}, "invalid_session_configuration");
690
- };
691
346
  #emit = async (update) => {
692
347
  const connection = this.#connection;
693
348
  if (connection === null || this.#nativeSessionId.length === 0) {
@@ -712,7 +367,7 @@ export class CodexAcpAgent {
712
367
  }
713
368
  await connection.client.notify(methods.client.session.update, {
714
369
  sessionId: this.#nativeSessionId,
715
- update: { configOptions: this.#configOptions(), sessionUpdate: "config_option_update" },
370
+ update: { configOptions: this.#settings.configOptions(), sessionUpdate: "config_option_update" },
716
371
  });
717
372
  };
718
373
  // Notifications are serialized so two app-server items cannot interleave into one ACP update
@@ -752,8 +407,7 @@ export class CodexAcpAgent {
752
407
  const decoded = threadSettingsUpdatedSchema.safeParse(params);
753
408
  if (decoded.success && decoded.data.threadId === this.#nativeSessionId) {
754
409
  const mode = decoded.data.threadSettings.collaborationMode?.mode;
755
- if (mode !== undefined && mode !== this.#selection.collaborationMode) {
756
- this.#selection = { ...this.#selection, collaborationMode: mode };
410
+ if (this.#settings.observeCollaborationMode(mode)) {
757
411
  await this.#enqueue(async () => {
758
412
  await this.#emitConfigOptionsUpdate();
759
413
  });
@@ -966,40 +620,9 @@ export class CodexAcpAgent {
966
620
  // The selection rides on the turn rather than the thread, so a choice made between turns
967
621
  // applies to the next one without restarting the conversation. Approval and sandboxing
968
622
  // travel as a pair: Codex resolves them together into the mode's single preset.
969
- const selection = this.#selection;
970
- const mode = AGENT_MODES.find((candidate) => candidate.id === selection.mode) ?? DEFAULT_MODE;
971
- const supportsFast = this.#model(selection.model)?.additionalSpeedTiers?.includes(FAST_TIER) === true;
972
623
  const started = turnSchema.parse((await this.#appServer.request("turn/start", {
973
- // Until a mode is chosen, `config.toml` decides the sandbox and approval
974
- // policy, and those fields stay off the turn so the host's own setup is
975
- // inherited rather than overridden.
976
- ...(this.#policySelected
977
- ? {
978
- approvalPolicy: mode.approvalPolicy,
979
- approvalsReviewer: mode.approvalsReviewer,
980
- sandboxPolicy: mode.sandboxPolicy,
981
- }
982
- : {}),
983
- // The collaboration mode rides on the turn: Codex applies it to the
984
- // thread, where it persists until changed. "Build" is Codex's `default`
985
- // mode, so it is only sent once a choice exists to apply.
986
- ...(this.#collaborationModeSupported &&
987
- (selection.collaborationMode !== "default" || this.#collaborationModeSelected)
988
- ? {
989
- collaborationMode: {
990
- mode: selection.collaborationMode,
991
- settings: {
992
- developer_instructions: null,
993
- model: selection.model,
994
- reasoning_effort: selection.effort.length === 0 ? null : selection.effort,
995
- },
996
- },
997
- }
998
- : {}),
999
- ...(selection.effort.length === 0 ? {} : { effort: selection.effort }),
624
+ ...this.#settings.turnParameters(),
1000
625
  input,
1001
- ...(selection.model.length === 0 ? {} : { model: selection.model }),
1002
- ...(selection.fastMode && supportsFast ? { serviceTier: SERVICE_TIER_FAST } : {}),
1003
626
  threadId: this.#nativeSessionId,
1004
627
  }, signal)).turn);
1005
628
  if (this.#turn === turn) {