rho-coding-agent 1.8.2

A lightweight agent harness inspired by Pi
Documentation
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
use super::{
    model_picker, provider_picker, App, Entry, PickerAction, PickerBadge, PickerBadgeTone,
    PickerItem, UiPicker,
};
use {
    crate::config::Config,
    crate::permission::PermissionMode,
    rho_providers::credentials::{
        load_web_search_api_key, CredentialResult, CredentialStore, WebSearchCredential,
    },
};
pub(super) const CONVERSATION_MODEL_VALUE: &str = "conversation_model";
pub(super) const TITLE_MODEL_VALUE: &str = "title_model";
pub(super) const REFRESH_MODEL_LIST_VALUE: &str = "refresh_model_list";
pub(super) const PROVIDER_LOGIN_VALUE: &str = "provider_login";
pub(super) const PROVIDER_LOGOUT_VALUE: &str = "provider_logout";
pub(super) const PERMISSION_MODE_VALUE: &str = "permission_mode";
pub(super) const PERMISSION_MODE_PREFIX: &str = "permission_mode:";
pub(super) const REASONING_VALUE: &str = "reasoning";
pub(super) const SHOW_REASONING_OUTPUT_VALUE: &str = "show_reasoning_output";
pub(super) const CHECK_FOR_UPDATES_VALUE: &str = "check_for_updates";
pub(super) const ENABLE_SUBAGENTS_VALUE: &str = "enable_subagents";
pub(super) const AUTO_COMPACT_VALUE: &str = "auto_compact";
pub(super) const COMPACT_THRESHOLD_PERCENT_VALUE: &str = "compact_threshold_percent";
pub(super) const COMPACT_TARGET_PERCENT_VALUE: &str = "compact_target_percent";
pub(super) const MAX_OUTPUT_BYTES_VALUE: &str = "max_output_bytes";
pub(super) const MAX_TOOL_OUTPUT_LINES_VALUE: &str = "max_tool_output_lines";
pub(super) const WEB_SEARCH_VALUE: &str = "web_search";
pub(super) const INLINE_SHELL_VALUE: &str = "inline_shell";
pub(super) const INLINE_SHELL_PREFIX: &str = "inline_shell:";
pub(super) const WEB_SEARCH_BACK_VALUE: &str = "web_search_back";
pub(super) const WEB_SEARCH_PROVIDER_VALUE: &str = "web_search_provider";
pub(super) const WEB_SEARCH_OPENAI_KEY_VALUE: &str = "web_search_openai_api_key";
pub(super) const WEB_SEARCH_EXA_KEY_VALUE: &str = "web_search_exa_api_key";
pub(super) const WEB_SEARCH_BRAVE_KEY_VALUE: &str = "web_search_brave_api_key";

/// Badge for the conversation model, shown as `alias → provider/model` when
/// the selection came from a user-defined alias so the mapping is never hidden.
fn conversation_model_badge(info: &super::RuntimeModelView, config: &Config) -> String {
    let current = format!("{}/{}", info.provider, info.model);
    match config.current_model_alias() {
        Some(alias) if config.provider == info.provider && config.model == info.model => {
            format!("{alias} → {current}")
        }
        _ => current,
    }
}

pub(super) fn config_picker(info: &super::RuntimeModelView, config: &Config) -> UiPicker {
    let reasoning_capabilities = rho_providers::model::models_dev::current_reasoning_capabilities(
        &info.provider,
        &info.model,
    );
    let mut items = vec![
            PickerItem {
                label: "Conversation model".into(),
                detail: Some("Model used for conversation turns. Enter to choose a model.".into()),
                preview: None,
                badge: Some(PickerBadge {
                    text: conversation_model_badge(info, config),
                    tone: PickerBadgeTone::Selected,
                }),
                value: CONVERSATION_MODEL_VALUE.into(),
            },
            PickerItem {
                label: "Session title model".into(),
                detail: Some("Model used to generate session titles. Enter to choose a model.".into()),
                preview: None,
                badge: Some(PickerBadge {
                    text: format!(
                        "{}/{}",
                        info.title_provider.as_deref().unwrap_or(&info.provider),
                        info.title_model.as_deref().unwrap_or(&info.model)
                    ),
                    tone: PickerBadgeTone::Selected,
                }),
                value: TITLE_MODEL_VALUE.into(),
            },
            PickerItem {
                label: "Refresh model lists".into(),
                detail: Some("Refresh cached models from configured API providers.".into()),
                preview: None,
                badge: None,
                value: REFRESH_MODEL_LIST_VALUE.into(),
            },
            PickerItem {
                label: "Log in to provider".into(),
                detail: Some("Add or replace provider credentials.".into()),
                preview: None,
                badge: None,
                value: PROVIDER_LOGIN_VALUE.into(),
            },
            PickerItem {
                label: "Log out of provider".into(),
                detail: Some("Delete stored provider credentials.".into()),
                preview: None,
                badge: None,
                value: PROVIDER_LOGOUT_VALUE.into(),
            },
            PickerItem {
                label: "Permission mode".into(),
                detail: Some(permission_mode_description(info.permission_mode).into()),
                preview: None,
                badge: Some(PickerBadge {
                    text: info.permission_mode.label().into(),
                    tone: PickerBadgeTone::Selected,
                }),
                value: PERMISSION_MODE_VALUE.into(),
            },
            PickerItem {
                label: "Reasoning".into(),
                detail: Some(format!(
                    "Controls model reasoning. Current: {}; Enter cycles to {}.",
                    info.reasoning,
                    reasoning_capabilities.next_level(info.reasoning)
                )),
                preview: None,
                badge: Some(PickerBadge {
                    text: info.reasoning.to_string(),
                    tone: PickerBadgeTone::Selected,
                }),
                value: REASONING_VALUE.into(),
            },
            PickerItem {
                label: "Show reasoning output".into(),
                detail: Some(
                    "Controls whether model reasoning text is shown in the TUI. Applies next turn."
                        .into(),
                ),
                preview: None,
                badge: Some(PickerBadge {
                    text: if info.show_reasoning_output {
                        "shown".into()
                    } else {
                        "hidden".into()
                    },
                    tone: PickerBadgeTone::Selected,
                }),
                value: SHOW_REASONING_OUTPUT_VALUE.into(),
            },
            PickerItem {
                label: "Check for updates".into(),
                detail: Some("Checks GitHub releases at startup and shows an update notice in the header when available.".into()),
                preview: None,
                badge: Some(PickerBadge {
                    text: if config.check_for_updates {
                        "on".into()
                    } else {
                        "off".into()
                    },
                    tone: PickerBadgeTone::Selected,
                }),
                value: CHECK_FOR_UPDATES_VALUE.into(),
            },
            PickerItem {
                label: "Enable delegation".into(),
                detail: Some(
                    "Controls whether agent tools are available. Applies next session.".into(),
                ),
                preview: None,
                badge: Some(PickerBadge {
                    text: if config.enable_subagents {
                        "on".into()
                    } else {
                        "off".into()
                    },
                    tone: PickerBadgeTone::Selected,
                }),
                value: ENABLE_SUBAGENTS_VALUE.into(),
            },
            PickerItem {
                label: "Auto compact".into(),
                detail: Some(
                    "Summarizes older model context before the effective context limit. Transcript history is preserved."
                        .into(),
                ),
                preview: None,
                badge: Some(PickerBadge {
                    text: if config.auto_compact {
                        "on".into()
                    } else {
                        "off".into()
                    },
                    tone: PickerBadgeTone::Selected,
                }),
                value: AUTO_COMPACT_VALUE.into(),
            },
            PickerItem {
                label: "Compact threshold".into(),
                detail: Some(
                    "Percent of the effective context window that triggers auto compaction."
                        .into(),
                ),
                preview: None,
                badge: Some(PickerBadge {
                    text: format!("{}%", config.compact_threshold_percent),
                    tone: PickerBadgeTone::Selected,
                }),
                value: COMPACT_THRESHOLD_PERCENT_VALUE.into(),
            },
            PickerItem {
                label: "Compact target".into(),
                detail: Some(
                    "Post-compaction target percent. The recent verbatim tail is chosen by token budget."
                        .into(),
                ),
                preview: None,
                badge: Some(PickerBadge {
                    text: format!("{}%", config.compact_target_percent),
                    tone: PickerBadgeTone::Selected,
                }),
                value: COMPACT_TARGET_PERCENT_VALUE.into(),
            },
            PickerItem {
                label: "Max output bytes".into(),
                detail: Some(
                    "Maximum tool output retained in context. Saved for next session.".into(),
                ),
                preview: None,
                badge: Some(PickerBadge {
                    text: config.max_output_bytes.to_string(),
                    tone: PickerBadgeTone::Selected,
                }),
                value: MAX_OUTPUT_BYTES_VALUE.into(),
            },
            PickerItem {
                label: "Max tool output lines".into(),
                detail: Some("Maximum collapsed tool output lines shown in the TUI.".into()),
                preview: None,
                badge: Some(PickerBadge {
                    text: config.max_tool_output_lines.to_string(),
                    tone: PickerBadgeTone::Selected,
                }),
                value: MAX_TOOL_OUTPUT_LINES_VALUE.into(),
            },
            PickerItem {
                label: "Inline shell".into(),
                detail: Some("Shell used by ! and !! commands. Enter to choose from shells available on PATH.".into()),
                preview: None,
                badge: Some(PickerBadge {
                    text: config.inline_shell.clone(),
                    tone: PickerBadgeTone::Selected,
                }),
                value: INLINE_SHELL_VALUE.into(),
            },
            PickerItem {
                label: "Web search".into(),
                detail: Some("Configure web_search backend and API keys.".into()),
                preview: None,
                badge: Some(PickerBadge {
                    text: config.web_search_provider.to_string(),
                    tone: PickerBadgeTone::Selected,
                }),
                value: WEB_SEARCH_VALUE.into(),
            },
        ];
    if reasoning_capabilities == rho_providers::model::ReasoningCapabilities::NotConfigurable {
        items.retain(|item| item.value != REASONING_VALUE);
    }
    UiPicker::new(
        "Config",
        "type regex filter, enter change, esc cancel",
        items,
        PickerAction::Config,
    )
}

pub(super) fn permission_mode_picker(mode: PermissionMode) -> UiPicker {
    UiPicker::new(
        "Permission mode",
        "enter select, esc back",
        [
            PermissionMode::Auto,
            PermissionMode::Plan,
            PermissionMode::Supervised,
        ]
        .into_iter()
        .map(|candidate| PickerItem {
            label: candidate.label().into(),
            detail: Some(permission_mode_description(candidate).into()),
            preview: None,
            badge: (candidate == mode).then_some(PickerBadge {
                text: "selected".into(),
                tone: PickerBadgeTone::Selected,
            }),
            value: format!("{PERMISSION_MODE_PREFIX}{}", candidate.as_str()),
        })
        .collect(),
        PickerAction::Config,
    )
}

fn permission_mode_description(mode: PermissionMode) -> &'static str {
    match mode {
        PermissionMode::Auto => "No permission checks.",
        PermissionMode::Plan => "Investigate only; writes and processes are denied.",
        PermissionMode::Supervised => "Ask before writes and processes.",
    }
}

pub(super) fn inline_shell_picker(config: &Config) -> UiPicker {
    UiPicker::new(
        "Inline shell",
        "enter select, esc back",
        super::inline_shell::available_shells(&config.inline_shell)
            .into_iter()
            .map(|shell| PickerItem {
                label: shell.clone(),
                detail: Some("Use this shell for inline ! and !! commands.".into()),
                preview: None,
                badge: (shell == config.inline_shell).then_some(PickerBadge {
                    text: "selected".into(),
                    tone: PickerBadgeTone::Selected,
                }),
                value: format!("{INLINE_SHELL_PREFIX}{shell}"),
            })
            .collect(),
        PickerAction::Config,
    )
}

pub(super) fn web_search_config_picker(
    config: &Config,
    credential_store: &dyn CredentialStore,
) -> UiPicker {
    UiPicker::new(
        "Web search config",
        "type regex filter, enter change, esc back",
        vec![
            PickerItem {
                label: "Back to config".into(),
                detail: Some("Return to the main config menu.".into()),
                preview: None,
                badge: None,
                value: WEB_SEARCH_BACK_VALUE.into(),
            },
            PickerItem {
                label: "Provider".into(),
                detail: Some(format!(
                    "Backend for web_search. Current: {}; Enter cycles to {}.",
                    config.web_search_provider,
                    config.web_search_provider.next_configurable()
                )),
                preview: None,
                badge: Some(PickerBadge {
                    text: config.web_search_provider.to_string(),
                    tone: PickerBadgeTone::Selected,
                }),
                value: WEB_SEARCH_PROVIDER_VALUE.into(),
            },
            PickerItem {
                label: "OpenAI API key".into(),
                detail: Some("Optional key for OpenAI web search. Codex login is used automatically when available.".into()),
                preview: None,
                badge: Some(credential_badge(
                    config,
                    credential_store,
                    WebSearchCredential::OpenAi,
                )),
                value: WEB_SEARCH_OPENAI_KEY_VALUE.into(),
            },
            PickerItem {
                label: "Exa API key".into(),
                detail: Some("Optional Exa API key. Without one, Exa hosted MCP is used.".into()),
                preview: None,
                badge: Some(credential_badge(
                    config,
                    credential_store,
                    WebSearchCredential::Exa,
                )),
                value: WEB_SEARCH_EXA_KEY_VALUE.into(),
            },
            PickerItem {
                label: "Brave API key".into(),
                detail: Some("Optional Brave Search API key used by the brave backend.".into()),
                preview: None,
                badge: Some(credential_badge(
                    config,
                    credential_store,
                    WebSearchCredential::Brave,
                )),
                value: WEB_SEARCH_BRAVE_KEY_VALUE.into(),
            },
        ],
        PickerAction::Config,
    )
}

fn credential_badge(
    config: &Config,
    credential_store: &dyn CredentialStore,
    credential: WebSearchCredential,
) -> PickerBadge {
    let configured = web_search_api_key_is_set(
        load_web_search_api_key(credential_store, credential),
        config.legacy_web_search_api_key(credential),
    );
    PickerBadge {
        text: if configured {
            "set".into()
        } else {
            "unset".into()
        },
        tone: PickerBadgeTone::Selected,
    }
}

fn web_search_api_key_is_set(
    stored: CredentialResult<Option<String>>,
    legacy: Option<&str>,
) -> bool {
    let stored = stored.ok().flatten();
    stored
        .as_deref()
        .or(legacy)
        .is_some_and(|value| !value.trim().is_empty())
}

impl App {
    pub(super) fn open_config_conversation_model_picker(&mut self) {
        self.refresh_available_auths();
        let picker = model_picker::model_picker(&self.info.runtime, &self.available_auths);
        if picker.items.is_empty() {
            self.insert_entry(&Entry::Notice(
                "no cached API models. use Config > Refresh model lists after signing in.".into(),
            ));
            self.status = "config".into();
        } else {
            self.open_child_picker(picker);
            self.status = "select model".into();
        }
    }

    pub(super) fn open_config_conversation_model_picker_during_turn(&mut self) {
        self.refresh_available_auths();
        let picker = model_picker::model_picker_during_run(
            &self.info.runtime,
            self.pending_model_selection.as_ref(),
            &self.available_auths,
        );
        if picker.items.is_empty() {
            self.insert_entry(&Entry::Notice(
                "no cached API models. refresh model lists after the current turn ends.".into(),
            ));
            self.status = "running".into();
        } else {
            self.open_child_picker(picker);
            self.status = "select model for next turn".into();
        }
    }

    pub(super) fn open_config_title_model_picker(&mut self) {
        self.refresh_available_auths();
        let (provider, model, _auth) = self.title_model_selection();
        let picker = model_picker::title_model_picker(
            &provider,
            &model,
            &self.info.runtime.favorite_models,
            &self.available_auths,
        );
        if picker.items.is_empty() {
            self.insert_entry(&Entry::Notice(
                "no cached API models. use Config > Refresh model lists after signing in.".into(),
            ));
            self.status = if self.running { "running" } else { "config" }.into();
        } else {
            self.open_child_picker(picker);
            self.status = "select title model".into();
        }
    }

    pub(super) fn open_config_refresh_model_picker(&mut self) {
        self.refresh_available_auths();
        let picker = provider_picker::refresh_model_list_picker(&self.available_auths);
        self.open_child_picker(picker);
        self.status = "select provider to refresh".into();
    }

    pub(super) fn open_config_login_picker(&mut self) {
        self.open_child_picker(provider_picker::login_group_picker());
        self.status = "select provider to login".into();
    }

    pub(super) fn open_config_logout_picker(&mut self) {
        match provider_picker::logout_provider_picker(self.credential_store.as_ref()) {
            Ok(picker) if picker.items.is_empty() => {
                self.insert_entry(&Entry::Notice(
                    "no stored provider credentials to delete".into(),
                ));
                self.status = "config".into();
            }
            Ok(picker) => {
                self.open_child_picker(picker);
                self.status = "select provider to logout".into();
            }
            Err(err) => {
                self.insert_entry(&Entry::Error(err.to_string()));
                self.status = "provider credentials unavailable".into();
            }
        }
    }
}

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