rho-coding-agent 3.3.0

A fast Rust agent harness with a small footprint and opinionated defaults
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
//! Every agent setting `config.toml` holds, declared once.
//!
//! This table is the only map between [`Config`] fields and their TOML keys
//! (which are also their protocol keys). Loading, saving, and the settings
//! schema all walk [`AGENT_SETTINGS`]; the structured tables that stay
//! hand-edited are listed in `config_load::FILE_ONLY`.

use std::num::NonZeroU64;

use rho_protocol::{IntegerUnit, ModelRuntime};

use super::setting::{
    any_value, AnySetting, Apply, IntegerSpec, ModelSetting, ModelSpec, Setting, SettingMeta,
};
use super::{
    CodemodeMode, Config, EditTool, ExaSearchConnection, InternalAgentModelConfig,
    InternalAgentTarget, OpenAiSearchConnection, SearchBackend, WebSearchMode,
};
use {
    crate::agent::{ADVISOR_AGENT_ID, PERMISSION_CLASSIFIER_AGENT_ID},
    crate::permission::PermissionMode,
    rho_providers::credentials::CredentialStoreBackend,
    rho_providers::reasoning::ReasoningLevel,
};

/// Every agent setting, in schema order.
pub(crate) static AGENT_SETTINGS: &[&dyn AnySetting<Config>] = &[
    &MODEL,
    &REASONING,
    &FAST_MODE,
    &PERMISSION_MODE,
    &PERMISSION_CLASSIFIER_MODEL,
    &PERMISSION_CLASSIFIER_REASONING,
    &ADVISOR_MODE,
    &ADVISOR_MODEL,
    &ADVISOR_REASONING,
    &ENABLE_SUBAGENTS,
    &AGENT_CONCURRENCY,
    &QUESTIONNAIRE_TIMEOUT,
    &WORKSPACE_REWIND,
    &KEEP_CACHE_WARM,
    &AUTO_COMPACT,
    &COMPACT_THRESHOLD,
    &COMPACT_TARGET,
    &MAX_OUTPUT_BYTES,
    &INLINE_SHELL,
    &EDIT_TOOL,
    &RTK,
    &CODEMODE,
    &WEB_SEARCH_MODE,
    &WEB_SEARCH_BACKEND,
    &OPENAI_SEARCH_CONNECTION,
    &OPENAI_SEARCH_URL,
    &EXA_SEARCH_CONNECTION,
    &EXA_SEARCH_URL,
    &EXA_MCP_URL,
    &BRAVE_SEARCH_URL,
    &FIRECRAWL_SEARCH_URL,
    &XAI_IMAGE_GENERATION,
    &WORKTREE_FROM_REMOTE,
    &CREDENTIAL_STORE,
];

const fn meta(
    category: &'static str,
    section: Option<&'static str>,
    label: &'static str,
    help: &'static str,
    applies: Apply,
) -> SettingMeta {
    SettingMeta {
        category,
        section,
        label,
        help,
        applies,
        overridable_per_project: true,
    }
}

/// A setting that sizes or wires the daemon itself, so a project never
/// overrides it.
const fn daemon_wide(meta: SettingMeta) -> SettingMeta {
    SettingMeta {
        overridable_per_project: false,
        ..meta
    }
}

const RHO_ONLY: ModelSpec = ModelSpec {
    runtimes: &[ModelRuntime::Rho],
};
const RHO_OR_CLAUDE_CLI: ModelSpec = ModelSpec {
    runtimes: &[ModelRuntime::Rho, ModelRuntime::ClaudeCli],
};

/// Percent of the effective context window; the loader clamped to this
/// range before 3.0.
const PERCENT: IntegerSpec = IntegerSpec {
    min: 1,
    max: Some(100),
    unit: Some(IntegerUnit::Percent),
};

static MODEL: Setting<Config, ModelSetting> = Setting {
    key: "model",
    meta: meta(
        "models",
        None,
        "Conversation model",
        "Model used for conversation turns.",
        Apply::NextSession,
    ),
    spec: RHO_ONLY,
    get: |config| ModelSetting::Rho {
        provider: config.provider.clone(),
        model: match config.current_model_alias() {
            Some(alias) => format!("@{alias}"),
            None => config.model.clone(),
        },
        auth: config.auth.clone(),
    },
    set: |config, model| match model {
        ModelSetting::Rho {
            provider,
            model,
            auth,
        } => {
            config.provider = provider;
            config.model = model;
            config.auth = auth;
            // A chosen model replaces the alias it was resolved from;
            // loading resolves an `@alias` model again.
            config.model_alias = None;
        }
        // RHO_ONLY keeps the reader from producing one.
        ModelSetting::ClaudeCli { .. } => {}
    },
    validate: any_value,
};

static REASONING: Setting<Config, ReasoningLevel> = Setting {
    key: "model.reasoning",
    meta: meta(
        "models",
        None,
        "Reasoning",
        "How much the conversation model reasons on each turn.",
        Apply::NextSession,
    ),
    spec: (),
    get: |config| config.reasoning,
    set: |config, level| config.reasoning = level,
    validate: any_value,
};

static FAST_MODE: Setting<Config, bool> = Setting {
    key: "model.fast_mode",
    meta: meta(
        "models",
        None,
        "Fast mode",
        "Faster serving for models that offer it, at a higher credit rate.",
        Apply::NextSession,
    ),
    spec: (),
    get: |config| config.fast_mode,
    set: |config, enabled| config.fast_mode = enabled,
    validate: any_value,
};

static PERMISSION_MODE: Setting<Config, PermissionMode> = Setting {
    key: "behavior.permission_mode",
    meta: meta(
        "agent",
        Some("Permissions"),
        "Permission mode",
        "Which tool calls run freely, which ask, and which are denied.",
        Apply::NextSession,
    ),
    spec: (),
    get: |config| config.permission_mode,
    set: |config, mode| config.permission_mode = mode,
    validate: any_value,
};

static PERMISSION_CLASSIFIER_MODEL: Setting<Config, Option<ModelSetting>> = Setting {
    key: "internal_agents.permission-classifier",
    meta: meta(
        "agent",
        Some("Permissions"),
        "Permission classifier model",
        "Model Auto permission mode uses to review writes, processes, and reads outside the workspace.",
        Apply::NextSession,
    ),
    spec: RHO_OR_CLAUDE_CLI,
    get: |config| internal_agent_model(config, PERMISSION_CLASSIFIER_AGENT_ID),
    set: |config, model| set_internal_agent_model(config, PERMISSION_CLASSIFIER_AGENT_ID, model),
    validate: any_value,
};

static PERMISSION_CLASSIFIER_REASONING: Setting<Config, Option<ReasoningLevel>> = Setting {
    key: "internal_agents.permission-classifier.reasoning",
    meta: meta(
        "agent",
        Some("Permissions"),
        "Permission classifier reasoning",
        "How much the permission classifier model reasons; unset keeps the agent's default.",
        Apply::NextSession,
    ),
    spec: (),
    get: |config| internal_agent_reasoning(config, PERMISSION_CLASSIFIER_AGENT_ID),
    set: |config, level| {
        set_internal_agent_reasoning(config, PERMISSION_CLASSIFIER_AGENT_ID, level)
    },
    validate: any_value,
};

static ADVISOR_MODE: Setting<Config, bool> = Setting {
    key: "behavior.advisor_mode",
    meta: meta(
        "agent",
        Some("Advisor"),
        "Advisor mode",
        "Let the agent ask an advisor model to review the session. Needs an advisor model.",
        Apply::NextTurn,
    ),
    spec: (),
    get: |config| config.advisor_mode,
    set: |config, enabled| config.advisor_mode = enabled,
    validate: any_value,
};

static ADVISOR_MODEL: Setting<Config, Option<ModelSetting>> = Setting {
    key: "internal_agents.advisor",
    meta: meta(
        "agent",
        Some("Advisor"),
        "Advisor model",
        "Model the advisor tool asks.",
        Apply::NextTurn,
    ),
    spec: RHO_OR_CLAUDE_CLI,
    get: |config| internal_agent_model(config, ADVISOR_AGENT_ID),
    set: |config, model| set_internal_agent_model(config, ADVISOR_AGENT_ID, model),
    validate: any_value,
};

static ADVISOR_REASONING: Setting<Config, Option<ReasoningLevel>> = Setting {
    key: "internal_agents.advisor.reasoning",
    meta: meta(
        "agent",
        Some("Advisor"),
        "Advisor reasoning",
        "How much the advisor model reasons; unset keeps the agent's default.",
        Apply::NextTurn,
    ),
    spec: (),
    get: |config| internal_agent_reasoning(config, ADVISOR_AGENT_ID),
    set: |config, level| set_internal_agent_reasoning(config, ADVISOR_AGENT_ID, level),
    validate: any_value,
};

static ENABLE_SUBAGENTS: Setting<Config, bool> = Setting {
    key: "behavior.enable_subagents",
    meta: meta(
        "agent",
        Some("Subagents"),
        "Delegation",
        "Make agent tools available.",
        Apply::NextSession,
    ),
    spec: (),
    get: |config| config.enable_subagents,
    set: |config, enabled| config.enable_subagents = enabled,
    validate: any_value,
};

static AGENT_CONCURRENCY: Setting<Config, u64> = Setting {
    key: "behavior.agent_concurrency",
    meta: daemon_wide(meta(
        "agent",
        Some("Subagents"),
        "Concurrent agents",
        "Maximum delegated agents running at once, including background ones.",
        Apply::Immediately,
    )),
    // Receipt for the ceiling: `MAX_AGENT_CONCURRENCY`.
    spec: IntegerSpec {
        min: 1,
        max: Some(super::MAX_AGENT_CONCURRENCY as u64),
        unit: None,
    },
    get: |config| config.agent_concurrency as u64,
    set: |config, slots| config.agent_concurrency = slots as usize,
    validate: any_value,
};

static QUESTIONNAIRE_TIMEOUT: Setting<Config, Option<u64>> = Setting {
    key: "questionnaire.timeout_seconds",
    meta: meta(
        "agent",
        Some("Questions"),
        "Questionnaire timeout",
        "Seconds before a form with explicit fallback answers takes them. Unset never times out; interaction pauses the timer.",
        Apply::NextSession,
    ),
    spec: IntegerSpec {
        min: 1,
        max: None,
        unit: Some(IntegerUnit::Seconds),
    },
    get: |config| config.questionnaire.timeout_seconds.map(NonZeroU64::get),
    set: |config, seconds| config.questionnaire.timeout_seconds = seconds.and_then(NonZeroU64::new),
    validate: any_value,
};

static WORKSPACE_REWIND: Setting<Config, bool> = Setting {
    key: "behavior.workspace_rewind",
    meta: meta(
        "agent",
        Some("Workspace"),
        "Workspace rewind",
        "Capture native file-tool changes for /rewind. Checkpoints hold file contents; shell and process effects are not captured.",
        Apply::NextSession,
    ),
    spec: (),
    get: |config| config.workspace_rewind,
    set: |config, enabled| config.workspace_rewind = enabled,
    validate: any_value,
};

static KEEP_CACHE_WARM: Setting<Config, bool> = Setting {
    key: "behavior.keep_cache_warm",
    meta: meta(
        "agent",
        Some("Workspace"),
        "Keep cache warm",
        "Let the model keep the prompt cache warm while it waits on a long background process. Each warm-up re-reads the cached prompt at the provider's cache-read price.",
        Apply::NextSession,
    ),
    spec: (),
    get: |config| config.keep_cache_warm,
    set: |config, enabled| config.keep_cache_warm = enabled,
    validate: any_value,
};

static AUTO_COMPACT: Setting<Config, bool> = Setting {
    key: "compaction.auto_compact",
    meta: meta(
        "context",
        None,
        "Auto compact",
        "Summarize older context before the effective context limit.",
        Apply::NextTurn,
    ),
    spec: (),
    get: |config| config.auto_compact,
    set: |config, enabled| config.auto_compact = enabled,
    validate: any_value,
};

static COMPACT_THRESHOLD: Setting<Config, u64> = Setting {
    key: "compaction.compact_threshold_percent",
    meta: meta(
        "context",
        None,
        "Compact threshold",
        "Percent of the effective context window that triggers auto compaction.",
        Apply::NextTurn,
    ),
    spec: PERCENT,
    get: |config| u64::from(config.compact_threshold_percent),
    set: |config, percent| config.compact_threshold_percent = percent as u8,
    validate: any_value,
};

static COMPACT_TARGET: Setting<Config, u64> = Setting {
    key: "compaction.compact_target_percent",
    meta: meta(
        "context",
        None,
        "Compact target",
        "Post-compaction target percent for text-summary compaction; must be below the threshold.",
        Apply::NextTurn,
    ),
    spec: PERCENT,
    get: |config| u64::from(config.compact_target_percent),
    set: |config, percent| config.compact_target_percent = percent as u8,
    validate: any_value,
};

static MAX_OUTPUT_BYTES: Setting<Config, u64> = Setting {
    key: "output.max_output_bytes",
    meta: meta(
        "context",
        None,
        "Max output bytes",
        "Maximum tool output retained in context.",
        Apply::NextSession,
    ),
    // The settings editor never accepted less than 1.
    spec: IntegerSpec {
        min: 1,
        max: None,
        unit: Some(IntegerUnit::Bytes),
    },
    get: |config| config.max_output_bytes as u64,
    set: |config, bytes| config.max_output_bytes = bytes as usize,
    validate: any_value,
};

static INLINE_SHELL: Setting<Config, String> = Setting {
    key: "behavior.inline_shell",
    meta: meta(
        "tools",
        None,
        "Inline shell",
        "Shell used by ! and !! commands.",
        Apply::NextSession,
    ),
    spec: (),
    get: |config| config.inline_shell.clone(),
    set: |config, shell| config.inline_shell = shell,
    validate: |shell| {
        if shell.trim().is_empty() {
            Err("must name a shell".into())
        } else {
            Ok(())
        }
    },
};

static EDIT_TOOL: Setting<Config, EditTool> = Setting {
    key: "behavior.edit_tool",
    meta: meta(
        "tools",
        None,
        "Edit tool",
        "File edit format exposed to models. Auto follows the active provider.",
        Apply::NextSession,
    ),
    spec: (),
    get: |config| config.edit_tool,
    set: |config, tool| config.edit_tool = tool,
    validate: any_value,
};

static RTK: Setting<Config, bool> = Setting {
    key: "behavior.rtk",
    meta: meta(
        "tools",
        None,
        "RTK",
        "Rewrite shell commands through rtk to compact their output, when rtk is installed.",
        Apply::NextSession,
    ),
    spec: (),
    get: |config| config.rtk,
    set: |config, enabled| config.rtk = enabled,
    validate: any_value,
};

static CODEMODE: Setting<Config, CodemodeMode> = Setting {
    key: "codemode.mode",
    meta: meta(
        "tools",
        None,
        "Codemode",
        "On keeps direct tools next to codemode; only hides them behind codemode.",
        Apply::NextTurn,
    ),
    spec: (),
    get: |config| config.codemode.mode,
    set: |config, mode| config.codemode.mode = mode,
    validate: any_value,
};

static WEB_SEARCH_MODE: Setting<Config, WebSearchMode> = Setting {
    key: "web_search.mode",
    meta: meta(
        "tools",
        Some("Web search"),
        "Web search mode",
        "Auto uses the chat provider's own search when it has one, otherwise the backend.",
        Apply::NextSession,
    ),
    spec: (),
    get: |config| config.web_search.mode,
    set: |config, mode| config.web_search.mode = mode,
    validate: any_value,
};

static WEB_SEARCH_BACKEND: Setting<Config, SearchBackend> = Setting {
    key: "web_search.backend",
    meta: meta(
        "tools",
        Some("Web search"),
        "Search backend",
        "Service that answers searches Rho runs itself.",
        Apply::NextSession,
    ),
    spec: (),
    get: |config| config.web_search.backend,
    set: |config, backend| config.web_search.backend = backend,
    validate: any_value,
};

static OPENAI_SEARCH_CONNECTION: Setting<Config, OpenAiSearchConnection> = Setting {
    key: "web_search.openai.connection",
    meta: meta(
        "tools",
        Some("Web search"),
        "OpenAI search connection",
        "Reach OpenAI search through the OpenAI API or a Codex sign-in.",
        Apply::NextSession,
    ),
    spec: (),
    get: |config| config.web_search.openai.connection,
    set: |config, connection| config.web_search.openai.connection = connection,
    validate: any_value,
};

static OPENAI_SEARCH_URL: Setting<Config, Option<String>> = Setting {
    key: "web_search.openai.api_base_url",
    meta: meta(
        "tools",
        Some("Web search"),
        "OpenAI search endpoint",
        "API origin and path prefix for OpenAI search; unset uses OpenAI's.",
        Apply::NextSession,
    ),
    spec: (),
    get: |config| config.web_search.openai.api_base_url.clone(),
    set: |config, url| config.web_search.openai.api_base_url = url,
    validate: endpoint_url,
};

static EXA_SEARCH_CONNECTION: Setting<Config, ExaSearchConnection> = Setting {
    key: "web_search.exa.connection",
    meta: meta(
        "tools",
        Some("Web search"),
        "Exa search connection",
        "Reach Exa through its HTTP API or its MCP server.",
        Apply::NextSession,
    ),
    spec: (),
    get: |config| config.web_search.exa.connection,
    set: |config, connection| config.web_search.exa.connection = connection,
    validate: any_value,
};

static EXA_SEARCH_URL: Setting<Config, Option<String>> = Setting {
    key: "web_search.exa.api_base_url",
    meta: meta(
        "tools",
        Some("Web search"),
        "Exa API endpoint",
        "API origin and path prefix for Exa; unset uses Exa's.",
        Apply::NextSession,
    ),
    spec: (),
    get: |config| config.web_search.exa.api_base_url.clone(),
    set: |config, url| config.web_search.exa.api_base_url = url,
    validate: endpoint_url,
};

static EXA_MCP_URL: Setting<Config, Option<String>> = Setting {
    key: "web_search.exa.mcp_url",
    meta: meta(
        "tools",
        Some("Web search"),
        "Exa MCP endpoint",
        "MCP server URL for Exa; unset uses Exa's.",
        Apply::NextSession,
    ),
    spec: (),
    get: |config| config.web_search.exa.mcp_url.clone(),
    set: |config, url| config.web_search.exa.mcp_url = url,
    validate: endpoint_url,
};

static BRAVE_SEARCH_URL: Setting<Config, Option<String>> = Setting {
    key: "web_search.brave.api_base_url",
    meta: meta(
        "tools",
        Some("Web search"),
        "Brave API endpoint",
        "API origin and path prefix for Brave; unset uses Brave's.",
        Apply::NextSession,
    ),
    spec: (),
    get: |config| config.web_search.brave.api_base_url.clone(),
    set: |config, url| config.web_search.brave.api_base_url = url,
    validate: endpoint_url,
};

static FIRECRAWL_SEARCH_URL: Setting<Config, Option<String>> = Setting {
    key: "web_search.firecrawl.api_base_url",
    meta: meta(
        "tools",
        Some("Web search"),
        "Firecrawl API endpoint",
        "API origin and path prefix for Firecrawl; unset uses Firecrawl's.",
        Apply::NextSession,
    ),
    spec: (),
    get: |config| config.web_search.firecrawl.api_base_url.clone(),
    set: |config, url| config.web_search.firecrawl.api_base_url = url,
    validate: endpoint_url,
};

static XAI_IMAGE_GENERATION: Setting<Config, bool> = Setting {
    key: "xai.image_generation",
    meta: meta(
        "tools",
        None,
        "SpaceXAI image generation",
        "Attach SpaceXAI hosted image generation on xAI create turns.",
        Apply::NextSession,
    ),
    spec: (),
    get: |config| config.xai_image_generation,
    set: |config, enabled| config.xai_image_generation = enabled,
    validate: any_value,
};

static WORKTREE_FROM_REMOTE: Setting<Config, bool> = Setting {
    key: "git.worktree_from_remote",
    meta: meta(
        "git",
        None,
        "Start worktrees from the remote",
        "Fetch the origin remote's default branch and start each new session worktree from it, instead of from your checkout's HEAD. Falls back to HEAD when there is no remote or the fetch fails.",
        Apply::NextSession,
    ),
    spec: (),
    get: |config| config.worktree_from_remote,
    set: |config, enabled| config.worktree_from_remote = enabled,
    validate: any_value,
};

/// Changed only through `rho/auth/choose_store`, which checks the store
/// can be reached; `rho/config/set` refuses it.
pub(super) static CREDENTIAL_STORE: Setting<Config, Option<CredentialStoreBackend>> = Setting {
    key: "behavior.credential_store",
    meta: daemon_wide(meta(
        "providers",
        None,
        "Credential store",
        "Where provider credentials live. Unset uses the OS keyring.",
        Apply::Restart,
    )),
    spec: (),
    get: |config| config.credential_store,
    set: |config, backend| config.credential_store = backend,
    validate: any_value,
};

fn endpoint_url(url: &Option<String>) -> Result<(), String> {
    match url {
        Some(url) => super::parse_search_endpoint_url("endpoint", url)
            .map(|_| ())
            .map_err(|error| error.to_string()),
        None => Ok(()),
    }
}

fn internal_agent_model(config: &Config, id: &str) -> Option<ModelSetting> {
    let selection = config.internal_agents.get(id)?;
    Some(match &selection.target {
        InternalAgentTarget::Rho(rho) => ModelSetting::Rho {
            provider: rho.provider.clone(),
            model: match selection.current_alias(&config.model_aliases) {
                Some(alias) => format!("@{alias}"),
                None => rho.model.clone(),
            },
            auth: rho.auth.clone(),
        },
        InternalAgentTarget::ClaudeCli { model } => ModelSetting::ClaudeCli {
            model: model.clone(),
        },
    })
}

/// Replaces an internal agent's model, keeping its reasoning override.
fn set_internal_agent_model(config: &mut Config, id: &str, model: Option<ModelSetting>) {
    let Some(model) = model else {
        config.internal_agents.remove(id);
        return;
    };
    let reasoning = config
        .internal_agents
        .get(id)
        .and_then(|selection| selection.reasoning);
    let mut selection = match model {
        ModelSetting::Rho {
            provider,
            model,
            auth,
        } => InternalAgentModelConfig::new(provider, model, auth),
        ModelSetting::ClaudeCli { model } => InternalAgentModelConfig::claude_cli(model),
    };
    selection.reasoning = reasoning;
    config.internal_agents.insert(id.into(), selection);
}

fn internal_agent_reasoning(config: &Config, id: &str) -> Option<ReasoningLevel> {
    config.internal_agents.get(id)?.reasoning
}

/// Sets an internal agent's reasoning override. An agent without a model
/// has no entry to hold one, so the level waits for a model.
fn set_internal_agent_reasoning(config: &mut Config, id: &str, level: Option<ReasoningLevel>) {
    if let Some(selection) = config.internal_agents.get_mut(id) {
        selection.reasoning = level;
    }
}

#[cfg(test)]
#[path = "config_registry_tests.rs"]
mod tests;