rho-coding-agent 3.6.0

A fast Rust agent harness with a small footprint and opinionated defaults
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
use std::collections::BTreeMap;

use pretty_assertions::assert_eq;
use rho_protocol::{
    Applies, ClaudeCliModel, ConfigCategory, ConfigChangedParams, ConfigError, ConfigNamespace,
    ConfigRevision, ConfigSchema, IntegerUnit, ModelChoice, ModelList, ModelRef, ModelRuntime,
    ModelSelection, SettingChoice, SettingEntry, SettingKey, SettingKind, SettingSpec,
    SettingValue, ValueSource,
};

use super::{Applied, DaemonSettings, ListedModels, NamespaceValues, SettingsNamespace};
use crate::tui::config_row::ConfigRow;
use crate::tui::{picker::PickerDetail, PickerItem};

fn spec(key: &str, label: &str, kind: SettingKind, applies: Applies) -> SettingSpec {
    SettingSpec {
        key: SettingKey::new(key),
        kind,
        default: None,
        category: "agent".into(),
        section: Some("Advisor".into()),
        label: label.into(),
        help: format!("{label} help."),
        applies,
        overridable_per_project: false,
    }
}

fn entry(value: Option<SettingValue>, source: ValueSource) -> SettingEntry {
    SettingEntry { value, source }
}

fn values(
    revision: &str,
    entries: Vec<(&str, SettingEntry)>,
    errors: Vec<ConfigError>,
) -> NamespaceValues {
    NamespaceValues {
        revision: ConfigRevision::new(revision),
        values: entries
            .into_iter()
            .map(|(key, entry)| (SettingKey::new(key), entry))
            .collect(),
        errors,
    }
}

/// The daemon's model list: one model rho runs, and Claude Code's default.
fn models() -> ModelList {
    ModelList {
        models: vec![ModelChoice {
            model: ModelRef {
                provider: "openai".into(),
                model: "gpt-5.5".into(),
            },
            label: "GPT-5.5".into(),
        }],
        claude_cli: vec![ClaudeCliModel {
            model: None,
            label: "claude-code/default".into(),
            detail: "Set no model and use whichever model Claude Code selects.".into(),
        }],
    }
}

/// One kind of each, as the daemon would serve them.
/// Settings with the advisor on with `openai/gpt-5.5`, and the `tui`
/// client's `output_streaming` at `live`.
pub(in crate::tui) fn settings() -> DaemonSettings {
    let mode = spec(
        "behavior.advisor_mode",
        "Advisor mode",
        SettingKind::Bool,
        Applies::NextTurn,
    );
    let model = spec(
        "internal_agents.advisor",
        "Advisor model",
        SettingKind::Model {
            runtimes: vec![ModelRuntime::Rho, ModelRuntime::ClaudeCli],
        },
        Applies::NextTurn,
    );
    let shell = SettingSpec {
        default: Some(SettingValue::Text("bash".into())),
        ..spec(
            "behavior.inline_shell",
            "Inline shell",
            SettingKind::Choice {
                choices: vec![
                    SettingChoice {
                        value: "bash".into(),
                        label: "Bash".into(),
                        help: None,
                    },
                    SettingChoice {
                        value: "zsh".into(),
                        label: "Zsh".into(),
                        help: None,
                    },
                ],
            },
            Applies::Immediately,
        )
    };
    let threshold = SettingSpec {
        section: None,
        category: "context".into(),
        ..spec(
            "compaction.compact_threshold_percent",
            "Compact threshold",
            SettingKind::Integer {
                min: 1,
                max: Some(100),
                unit: Some(IntegerUnit::Percent),
            },
            Applies::NextTurn,
        )
    };
    let zen = SettingSpec {
        category: "display".into(),
        section: None,
        ..spec(
            "zen_mode",
            "Zen mode",
            SettingKind::Bool,
            Applies::Immediately,
        )
    };
    // The daemon changes it only through `rho/auth/choose_store`.
    let store = SettingSpec {
        category: "providers".into(),
        section: None,
        ..spec(
            "behavior.credential_store",
            "Credential store",
            SettingKind::Text,
            Applies::Restart,
        )
    };
    let schema = ConfigSchema {
        categories: vec![
            ConfigCategory {
                id: "agent".into(),
                label: "Agent".into(),
            },
            ConfigCategory {
                id: "context".into(),
                label: "Context".into(),
            },
            // No setting sits here, so the root leaves it out.
            ConfigCategory {
                id: "tools".into(),
                label: "Tools".into(),
            },
            ConfigCategory {
                id: "providers".into(),
                label: "Providers".into(),
            },
        ],
        settings: vec![mode, model, shell, threshold, store],
        file_only: Vec::new(),
    };
    let agent = values(
        "a1",
        vec![
            (
                "behavior.advisor_mode",
                entry(Some(SettingValue::Bool(true)), ValueSource::Global),
            ),
            (
                "internal_agents.advisor",
                entry(
                    Some(SettingValue::Model(ModelSelection::Rho {
                        provider: "openai".into(),
                        model: "gpt-5.5".into(),
                    })),
                    ValueSource::Global,
                ),
            ),
            (
                "behavior.inline_shell",
                entry(
                    Some(SettingValue::Text("bash".into())),
                    ValueSource::Default,
                ),
            ),
            (
                "compaction.compact_threshold_percent",
                entry(Some(SettingValue::Integer(80)), ValueSource::Global),
            ),
        ],
        vec![ConfigError {
            key: Some(SettingKey::new("compaction.compact_threshold_percent")),
            message: "must be at most 100, not 140".into(),
        }],
    );
    let tui = values(
        "t1",
        vec![
            (
                "zen_mode",
                entry(Some(SettingValue::Bool(false)), ValueSource::Default),
            ),
            (
                "output_streaming",
                entry(
                    Some(SettingValue::Text("live".into())),
                    ValueSource::Default,
                ),
            ),
        ],
        Vec::new(),
    );
    DaemonSettings::new(
        schema,
        vec![zen],
        agent,
        tui,
        ListedModels::Listed(models()),
    )
}

/// What a row shows and does, compared whole.
#[derive(Debug, PartialEq)]
struct Row {
    section: Option<String>,
    label: String,
    badge: Option<String>,
    detail: Option<String>,
    does: Option<ConfigRow>,
}

fn rows(items: Vec<PickerItem>) -> Vec<Row> {
    items
        .into_iter()
        .map(|item| Row {
            section: item.section,
            label: item.label,
            badge: item.badge.map(|badge| badge.text),
            detail: match item.detail {
                Some(PickerDetail::Text(text)) => Some(text),
                _ => None,
            },
            does: ConfigRow::parse(&item.value),
        })
        .collect()
}

fn setting(namespace: SettingsNamespace, key: &str) -> Option<ConfigRow> {
    Some(ConfigRow::Setting {
        namespace,
        key: SettingKey::new(key),
    })
}

// Covers: the root lists each agent category that has settings, in schema
// order, then the `tui` client's; an empty category would open a blank page.
// The credential store, which only `rho/auth/choose_store` changes, is left
// out, and its category with it.
// Owner: daemon settings schema → `/config` rows (pure).
#[test]
fn root_rows_list_every_category_with_settings() {
    let category = |namespace, id: &str| {
        Some(ConfigRow::Category {
            namespace,
            id: id.into(),
        })
    };
    assert_eq!(
        rows(settings().category_rows()),
        vec![
            Row {
                section: Some("Settings".into()),
                label: "Agent".into(),
                badge: None,
                detail: Some("Advisor mode, Advisor model, Inline shell.".into()),
                does: category(SettingsNamespace::Agent, "agent"),
            },
            Row {
                section: Some("Settings".into()),
                label: "Context".into(),
                badge: None,
                detail: Some("Compact threshold.".into()),
                does: category(SettingsNamespace::Agent, "context"),
            },
            Row {
                section: Some("Settings".into()),
                label: "Display".into(),
                badge: None,
                detail: Some("Zen mode.".into()),
                does: category(SettingsNamespace::Tui, "display"),
            },
        ]
    );
}

// Covers: a category page shows each setting's current value by kind (bool,
// model by its catalog label, choice by its label, integer with its unit),
// when a change applies, and the file's problem with a setting.
// Owner: daemon settings schema → `/config` rows (pure).
#[test]
fn setting_rows_show_values_applies_and_problems() {
    let settings = settings();
    let agent = SettingsNamespace::Agent;
    assert_eq!(
        rows(settings.setting_rows(agent, "agent")),
        vec![
            Row {
                section: Some("Advisor".into()),
                label: "Advisor mode".into(),
                badge: Some("on".into()),
                detail: Some("Advisor mode help. Applies from the next turn.".into()),
                does: setting(agent, "behavior.advisor_mode"),
            },
            Row {
                section: Some("Advisor".into()),
                label: "Advisor model".into(),
                badge: Some("GPT-5.5".into()),
                detail: Some("Advisor model help. Applies from the next turn.".into()),
                does: setting(agent, "internal_agents.advisor"),
            },
            Row {
                section: Some("Advisor".into()),
                label: "Inline shell".into(),
                badge: Some("Bash".into()),
                detail: Some("Inline shell help.".into()),
                does: setting(agent, "behavior.inline_shell"),
            },
        ]
    );
    assert_eq!(
        rows(settings.setting_rows(agent, "context")),
        vec![Row {
            section: None,
            label: "Compact threshold".into(),
            badge: Some("80%".into()),
            detail: Some(
                "Compact threshold help. Applies from the next turn.\n\nThe file's value is not used: must be at most 100, not 140"
                    .into()
            ),
            does: setting(agent, "compaction.compact_threshold_percent"),
        }]
    );
}

// Covers: a model setting's page offers the daemon's models and Claude Code's
// rows as its runtimes allow, marks the current one, and offers a reset once the
// file sets it; a choice left at its default offers no reset.
// Owner: daemon settings schema → `/config` rows (pure).
#[test]
fn value_rows_offer_each_value_and_a_reset_once_set() {
    let settings = settings();
    let agent = SettingsNamespace::Agent;
    let set = |key: &str, value| {
        Some(ConfigRow::Set {
            namespace: agent,
            key: SettingKey::new(key),
            value,
        })
    };
    let model_key = SettingKey::new("internal_agents.advisor");
    assert_eq!(
        rows(settings.value_rows(agent, &model_key).unwrap()),
        vec![
            Row {
                section: None,
                label: "GPT-5.5".into(),
                badge: Some("current".into()),
                detail: Some("openai/gpt-5.5".into()),
                does: set(
                    "internal_agents.advisor",
                    SettingValue::Model(ModelSelection::Rho {
                        provider: "openai".into(),
                        model: "gpt-5.5".into(),
                    }),
                ),
            },
            Row {
                section: None,
                label: "claude-code/default".into(),
                badge: None,
                detail: Some("Set no model and use whichever model Claude Code selects.".into()),
                does: set(
                    "internal_agents.advisor",
                    SettingValue::Model(ModelSelection::ClaudeCli { model: None }),
                ),
            },
            Row {
                section: None,
                label: "Default (not set)".into(),
                badge: None,
                detail: Some("Remove the setting from the file, so its default applies.".into()),
                does: Some(ConfigRow::Reset {
                    namespace: agent,
                    key: model_key.clone(),
                }),
            },
        ]
    );
    let shell = SettingKey::new("behavior.inline_shell");
    assert_eq!(
        rows(settings.value_rows(agent, &shell).unwrap())
            .into_iter()
            .map(|row| (row.label, row.badge))
            .collect::<Vec<_>>(),
        vec![
            ("Bash".to_owned(), Some("current".to_owned())),
            ("Zsh".to_owned(), None),
        ]
    );
    let mode = SettingKey::new("behavior.advisor_mode");
    assert!(settings.value_rows(agent, &mode).is_none());
}

// Covers: a change notification carries only changed entries, so the cache
// merges them and hands on just those, leaving a value the TUI changed for
// itself alone; its problems show once when they change, not on every
// change after; another client's namespace is ignored.
// Owner: daemon settings cache (pure).
#[test]
fn changes_merge_and_report_new_problems_once() {
    let mut settings = settings();
    let problem = ConfigError {
        key: Some(SettingKey::new("zen_mode")),
        message: "expected a boolean".into(),
    };
    let changed = |revision: &str, value: bool, errors: Vec<ConfigError>| ConfigChangedParams {
        namespace: SettingsNamespace::Tui.wire(),
        revision: ConfigRevision::new(revision),
        values: BTreeMap::from([(
            SettingKey::new("zen_mode"),
            entry(Some(SettingValue::Bool(value)), ValueSource::Global),
        )]),
        errors,
    };

    let first = settings.apply(changed("t2", true, vec![problem.clone()]));
    let second = settings.apply(changed("t3", false, vec![problem.clone()]));
    let fixed = settings.apply(changed("t4", true, Vec::new()));
    let other = settings.apply(ConfigChangedParams {
        namespace: ConfigNamespace::Client {
            name: rho_protocol::ClientName::new("other").unwrap(),
        },
        ..changed("o1", false, Vec::new())
    });

    assert_eq!(
        (first, second, fixed, other),
        (
            Some(Applied {
                namespace: SettingsNamespace::Tui,
                changed: BTreeMap::from([(
                    SettingKey::new("zen_mode"),
                    entry(Some(SettingValue::Bool(true)), ValueSource::Global)
                )]),
                new_problems: vec![problem],
            }),
            Some(Applied {
                namespace: SettingsNamespace::Tui,
                changed: BTreeMap::from([(
                    SettingKey::new("zen_mode"),
                    entry(Some(SettingValue::Bool(false)), ValueSource::Global)
                )]),
                new_problems: Vec::new(),
            }),
            Some(Applied {
                namespace: SettingsNamespace::Tui,
                changed: BTreeMap::from([(
                    SettingKey::new("zen_mode"),
                    entry(Some(SettingValue::Bool(true)), ValueSource::Global)
                )]),
                new_problems: Vec::new(),
            }),
            None,
        )
    );
    assert_eq!(
        settings.values(SettingsNamespace::Tui),
        &values(
            "t4",
            vec![
                (
                    "zen_mode",
                    entry(Some(SettingValue::Bool(true)), ValueSource::Global)
                ),
                (
                    "output_streaming",
                    entry(
                        Some(SettingValue::Text("live".into())),
                        ValueSource::Default
                    )
                ),
            ],
            Vec::new(),
        )
    );
}