rho-coding-agent 1.18.0

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
use super::*;
use ratatui::style::{Color, Style};

fn line_text(line: &Line<'_>) -> String {
    line.spans
        .iter()
        .map(|span| span.content.as_ref())
        .collect()
}

fn line_styles(line: &Line<'_>) -> Vec<Style> {
    line.spans.iter().map(|span| span.style).collect()
}

#[test]
fn reasoning_entry_renders_inline_markdown_with_dim_foreground() {
    let rendered = render_entry(
        &Entry::Reasoning("thinking with **bold** and *emphasis*".into()),
        80,
        10,
    );
    let content_line = rendered
        .lines
        .iter()
        .find(|line| line_text(line).contains("thinking with"))
        .expect("reasoning content line");

    assert_eq!(
        line_text(content_line).trim(),
        "thinking with bold and emphasis"
    );
    let bold = content_line
        .spans
        .iter()
        .find(|span| span.content == "bold")
        .expect("bold span");
    let italic = content_line
        .spans
        .iter()
        .find(|span| span.content == "emphasis")
        .expect("italic span");
    assert!(bold.style.add_modifier.contains(Modifier::BOLD));
    assert!(italic.style.add_modifier.contains(Modifier::ITALIC));
    for span in [bold, italic] {
        assert_eq!(span.style.fg, Some(Color::DarkGray));
        assert!(!(span.style.add_modifier - span.style.sub_modifier).contains(Modifier::DIM));
    }
}

#[test]
fn reasoning_entry_renders_thought_duration_footer() {
    let rendered = render_entry(
        &Entry::Reasoning(super::super::ReasoningEntry {
            text: "because reasons".into(),
            thought_for: Some(std::time::Duration::from_millis(3_200)),
        }),
        80,
        10,
    );
    let footer = rendered
        .lines
        .iter()
        .find(|line| line_text(line).contains("Thought for 3.2s"))
        .expect("thought footer");
    assert!(footer.spans.iter().any(|span| {
        span.style.add_modifier.contains(Modifier::DIM) && span.content.contains("Thought for 3.2s")
    }));

    let summary_only = render_entry(
        &Entry::Reasoning(super::super::ReasoningEntry::summary_only(
            std::time::Duration::from_secs(65),
        )),
        80,
        10,
    );
    assert!(summary_only
        .lines
        .iter()
        .any(|line| line_text(line).contains("Thought for 1m 5s")));
}

#[test]
fn user_message_trailing_spacer_has_no_background() {
    let rendered = render_entry(&Entry::User("hello there".into()), 40, 10);
    assert!(
        rendered.lines.len() >= 2,
        "user entry should keep content plus a trailing spacer"
    );

    let spacer = rendered.lines.last().expect("trailing spacer");
    assert!(line_text(spacer).trim().is_empty());
    assert!(
        spacer.spans.iter().all(|span| span.style.bg.is_none()),
        "trailing spacer must not inherit the user-message background: {spacer:?}"
    );

    let content = rendered
        .lines
        .iter()
        .find(|line| line_text(line).contains("hello there"))
        .expect("user content line");
    assert!(
        content.spans.iter().any(|span| span.style.bg.is_some()),
        "content rows should keep the user-message background: {content:?}"
    );
    assert_eq!(
        rendered
            .lines
            .first()
            .map(line_text)
            .as_deref()
            .map(str::trim),
        Some("hello there"),
        "user entry should not keep a leading spacer"
    );
}

#[test]
fn display_width_ignores_control_characters_filtered_by_ratatui() {
    assert_eq!(display_width("left\tright"), 9);
    assert_eq!(display_width("left\rright"), 9);
    assert_eq!(display_width("left\u{1b}right"), 9);
}

#[test]
fn narrow_picker_rows_do_not_exceed_width() {
    let picker = UiPicker::new(
        "models",
        "enter confirm",
        vec![PickerItem {
            section: None,
            label: "very-wide-model-name".into(),
            detail: Some("very wide detail".into()),
            preview: Some("wide preview".into()),
            badge: Some(crate::tui::PickerBadge {
                text: "selected".into(),
                tone: PickerBadgeTone::Selected,
            }),
            value: "very-wide-model-name".into(),
        }],
        crate::tui::PickerAction::SelectModel,
    );

    let lines = picker_lines(&picker, 4);

    assert!(
        lines
            .iter()
            .all(|line| display_width(&line_text(line)) <= 4),
        "{:#?}",
        lines.iter().map(line_text).collect::<Vec<_>>()
    );
}

#[test]
fn list_picker_value_badges_use_available_width() {
    let badge = "bash shell · search disabled";
    let picker = UiPicker::new(
        "Config · saves automatically",
        "type to search settings",
        vec![PickerItem {
            section: None,
            label: "Tools".into(),
            detail: Some("Inline shell and web search.".into()),
            preview: None,
            badge: Some(crate::tui::PickerBadge {
                text: badge.into(),
                tone: PickerBadgeTone::Selected,
            }),
            value: "config_category:tools".into(),
        }],
        crate::tui::PickerAction::Config,
    );

    let row = picker_lines(&picker, 100)
        .into_iter()
        .map(|line| line_text(&line))
        .find(|line| line.contains("Tools"))
        .expect("tools row");

    assert!(
        row.contains(badge),
        "badge should not truncate while free columns remain: {row}"
    );
    assert!(!row.contains(''), "{row}");
}

#[test]
fn list_picker_height_stays_stable_when_selected_detail_is_missing() {
    let mut picker = UiPicker::new(
        "models",
        "enter confirm",
        vec![
            PickerItem {
                section: None,
                label: "plain".into(),
                detail: None,
                preview: None,
                badge: None,
                value: "plain".into(),
            },
            PickerItem {
                section: None,
                label: "detailed".into(),
                detail: Some("extra context".into()),
                preview: None,
                badge: None,
                value: "detailed".into(),
            },
        ],
        crate::tui::PickerAction::SelectModel,
    );

    let first_height = picker_lines(&picker, 80).len();
    picker.select_next();

    assert_eq!(picker_lines(&picker, 80).len(), first_height);
}

#[test]
fn assistant_markdown_styles_inline_code_bold_and_italic() {
    let lines = entry_lines(
        &Entry::Assistant("use `cargo test`, then **ship** the *fix*".into()),
        80,
        10,
    );

    let content = &lines[0];
    assert_eq!(line_text(content), " use cargo test, then ship the fix ");
    let styles = line_styles(content);
    assert!(styles.contains(&Theme::markdown_inline_code()));
    assert!(styles.contains(&Theme::markdown_bold()));
    assert!(styles.contains(&Theme::markdown_italic()));
    assert_eq!(Theme::markdown_bold().fg, None);
    assert_eq!(Theme::markdown_italic().fg, None);
}

#[test]
fn assistant_markdown_styles_code_blocks() {
    let lines = entry_lines(&Entry::Assistant("```rust\nlet x = 1;\n```".into()), 80, 10);

    assert!(line_text(&lines[0]).contains(""));
    assert!(line_text(&lines[1]).contains("│ let x = 1;"));
    assert!(line_text(&lines[2]).contains(""));
    assert_eq!(lines[1].spans[1].style, Theme::markdown_code_block());
}

#[test]
fn assistant_markdown_renders_divider_lines() {
    let lines = entry_lines(&Entry::Assistant("before\n---\nafter".into()), 20, 10);

    assert_eq!(line_text(&lines[0]), " before ");
    assert_eq!(line_text(&lines[1]), format!(" {} ", "".repeat(18)));
    assert_eq!(lines[1].spans[1].style, Theme::dim());
    assert_eq!(line_text(&lines[2]), " after ");
}

#[test]
fn complete_visual_prefix_preserves_trailing_newline_state() {
    assert_eq!(complete_visual_prefix_byte_index("a\n", 10), "a\n".len());
    assert_eq!(
        complete_visual_prefix_byte_index("a\n\n", 10),
        "a\n\n".len()
    );
    assert_eq!(complete_visual_prefix_byte_index("a\nb", 10), "a\n".len());
}

#[test]
fn complete_visual_prefix_keeps_multibyte_boundaries() {
    assert_eq!(complete_visual_prefix_byte_index("éa", 2), "éa".len());
    assert_eq!(complete_visual_prefix_byte_index("éab", 2), "éa".len());
}

#[test]
fn complete_visual_prefix_wraps_at_exact_width() {
    assert_eq!(complete_visual_prefix_byte_index("abc", 3), 3);
    assert_eq!(complete_visual_prefix_byte_index("abcd", 3), 3);
    assert_eq!(complete_visual_prefix_byte_index("abcdef", 3), 6);
}

#[test]
fn wrapped_text_prefers_whitespace_boundaries() {
    let mut lines = Vec::new();
    push_wrapped_text(
        &mut lines,
        "hello wide world",
        10,
        Style::default(),
        LineFill::Natural,
    );

    let rendered = lines.iter().map(line_text).collect::<Vec<_>>();
    assert_eq!(
        rendered,
        vec!["hello wide".to_string(), " world".to_string()]
    );
}

#[test]
fn complete_visual_prefix_prefers_whitespace_boundaries() {
    assert_eq!(
        complete_visual_prefix_byte_index("hello wide", 8),
        "hello ".len()
    );
    assert_eq!(
        complete_visual_prefix_byte_index("hello wide", 10),
        "hello wide".len()
    );
}

#[test]
fn wrapped_text_preserves_leading_repeated_and_trailing_whitespace() {
    let mut lines = Vec::new();
    push_wrapped_text(
        &mut lines,
        "  indented\na  b\ntrail  ",
        20,
        Style::default(),
        LineFill::Natural,
    );

    let rendered = lines.iter().map(line_text).collect::<Vec<_>>();
    assert_eq!(
        rendered,
        vec![
            "  indented".to_string(),
            "a  b".to_string(),
            "trail  ".to_string()
        ]
    );
}

#[test]
fn wrapped_text_preserves_tabs_and_whitespace_only_lines() {
    let mut lines = Vec::new();
    push_wrapped_text(
        &mut lines,
        "\tindented\n   ",
        20,
        Style::default(),
        LineFill::Natural,
    );

    let rendered = lines.iter().map(line_text).collect::<Vec<_>>();
    assert_eq!(rendered, vec!["\tindented".to_string(), "   ".to_string()]);
}

#[test]
fn wrapped_text_preserves_whitespace_when_breaking_at_boundary() {
    let mut lines = Vec::new();
    push_wrapped_text(
        &mut lines,
        "hello   wide",
        8,
        Style::default(),
        LineFill::Natural,
    );

    let rendered = lines.iter().map(line_text).collect::<Vec<_>>();
    assert_eq!(rendered, vec!["hello   ".to_string(), "wide".to_string()]);
}

#[test]
fn complete_visual_prefix_and_rendering_agree_on_whitespace_boundary() {
    let text = "hello   wide";
    let split = complete_visual_prefix_byte_index(text, 8);
    let mut lines = Vec::new();
    push_wrapped_text(&mut lines, text, 8, Style::default(), LineFill::Natural);

    assert_eq!(&text[..split], "hello   ");
    assert_eq!(line_text(&lines[0]), "hello   ");
}

#[test]
fn complete_visual_prefix_and_rendering_agree_on_exact_width_trailing_space() {
    let text = "abc ";
    let split = complete_visual_prefix_byte_index(text, 3);
    let mut lines = Vec::new();
    push_wrapped_text(&mut lines, text, 3, Style::default(), LineFill::Natural);

    assert_eq!(&text[..split], "abc");
    assert_eq!(
        lines.iter().map(line_text).collect::<Vec<_>>(),
        vec!["abc".to_string(), " ".to_string()]
    );
}

#[test]
fn wrapped_text_handles_wide_chars_in_narrow_width() {
    let mut lines = Vec::new();
    push_wrapped_text(&mut lines, "你a", 1, Style::default(), LineFill::Natural);

    let rendered = lines.iter().map(line_text).collect::<Vec<_>>();
    assert_eq!(rendered, vec!["".to_string(), "a".to_string()]);
}

#[test]
fn long_words_still_hard_wrap() {
    let mut lines = Vec::new();
    push_wrapped_text(
        &mut lines,
        "abcdefghijk",
        5,
        Style::default(),
        LineFill::Natural,
    );

    let rendered = lines.iter().map(line_text).collect::<Vec<_>>();
    assert_eq!(
        rendered,
        vec!["abcde".to_string(), "fghij".to_string(), "k".to_string()]
    );
}

#[test]
fn stream_fragment_rendering_preserves_blank_lines() {
    let mut lines = Vec::new();
    push_wrapped_text(&mut lines, "a\n\n", 10, Style::default(), LineFill::Natural);

    let rendered = lines.iter().map(line_text).collect::<Vec<_>>();
    assert_eq!(rendered, vec!["a".to_string(), String::new()]);
}

#[test]
fn visual_cursor_movement_clamps_to_shorter_explicit_line() {
    let input = "ab\ncdef";
    let lines = input_visual_lines(input, 80);

    assert_eq!(input_cursor_index_on_visual_line(input, &lines, 0, 4), 2);
}

#[test]
fn visual_cursor_movement_uses_wide_character_columns() {
    let input = "界a界b";
    let lines = input_visual_lines(input, 3);

    assert_eq!(lines, vec!["界a", "界b"]);
    assert_eq!(input_cursor_index_on_visual_line(input, &lines, 0, 2), 1);
}

#[test]
fn visual_cursor_movement_preserves_ascii_wrapped_column() {
    let input = "abcdef";
    let lines = input_visual_lines(input, 4);

    assert_eq!(input_cursor_index_on_visual_line(input, &lines, 0, 2), 2);
}

#[test]
fn session_header_lists_dim_control_hints() {
    let lines = session_header_lines(None, 80);
    let version = env!("CARGO_PKG_VERSION");
    let hint_lines = [
        " shift+tab    Cycle reasoning level",
        " ctrl+c       Clear the composer",
        " /            Show available commands",
        " !            Run a shell command",
    ];

    assert_eq!(
        lines.iter().map(line_text).collect::<Vec<_>>(),
        vec![
            String::new(),
            format!(" rho  v{version}"),
            String::new(),
            hint_lines[0].into(),
            hint_lines[1].into(),
            hint_lines[2].into(),
            hint_lines[3].into(),
            String::new(),
        ]
    );
    for hint in hint_lines {
        let line = lines
            .iter()
            .find(|line| line_text(line) == hint)
            .expect("hint line");
        assert!(line
            .spans
            .iter()
            .all(|span| span.style == Theme::dim() || span.content.is_empty()));
    }
}

#[test]
fn session_header_update_notice_aligns_under_brand_without_label() {
    let notice = "update available: v1.11.0 (current v1.10.0)";
    let lines = session_header_lines(Some(notice), 80);
    let version = env!("CARGO_PKG_VERSION");

    assert_eq!(
        lines.iter().map(line_text).collect::<Vec<_>>(),
        vec![
            String::new(),
            format!(" rho  v{version}"),
            format!(" {notice}"),
            String::new(),
            " shift+tab    Cycle reasoning level".into(),
            " ctrl+c       Clear the composer".into(),
            " /            Show available commands".into(),
            " !            Run a shell command".into(),
            String::new(),
        ]
    );
}