dpc-tau-cli 0.2.1

A minimal Unix-first coding agent.
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
use std::os::unix::net as path_std_os_unix_net;

use tau_config::settings as path_tau_config_settings;

use super::*;

/// The active composer must use the configured hollow prompt-state marker.
#[test]
fn active_prompt_uses_composing_marker() {
    let theme = select_theme_with_env_override(
        &path_tau_config_settings::TauDirs::default(),
        CliTheme::default(),
        None,
    )
    .expect("default theme loads");
    let settings = path_tau_config_settings::CliSettings::built_in();

    let prompt = active_prompt_marker(&theme, &settings.prompt_symbol, None);

    assert_eq!(prompt.spans()[0].text, "◯ ");
}

/// Ensures CLI and environment theme names share the same normalization path,
/// including external names that must not be rejected during parsing.
#[test]
fn parses_theme_env_values() {
    assert_eq!(
        parse_theme_name(" tau-plain-dark "),
        Some(CliTheme::Named("tau-plain-dark".to_owned()))
    );
    assert_eq!(
        parse_theme_name("solarized"),
        Some(CliTheme::Named("solarized".to_owned()))
    );
    assert_eq!(parse_theme_name("   "), None);
}

/// Ensures built-in theme file names remain selectable without requiring a Tau
/// config directory. This intentionally avoids asserting built-in palette
/// details so theme tuning does not churn selector tests.
#[test]
fn selected_named_builtin_theme() {
    let dirs = tau_config::settings::TauDirs {
        config_dir: None,
        state_dir: None,
    };

    let theme = select_theme_with_env_override(&dirs, CliTheme::Named("tau-dpc".to_owned()), None)
        .expect("built-in theme loads without config dir");
    let prompt = right_prompt_context(&theme, Path::new("/tmp/project"), None, "session-1");

    assert_eq!(prompt.spans()[0].text, "/tmp/project &session-1");
}

/// Ensures explicitly named built-ins accept documented case-insensitive input.
#[test]
fn selected_named_builtin_theme_case_insensitively() {
    let dirs = tau_config::settings::TauDirs {
        config_dir: None,
        state_dir: None,
    };

    select_theme_for_command(&dirs, "TAU-DPC").expect("case-insensitive built-in loads");
    select_theme_for_command(&dirs, "TAU-PLAIN-LIGHT").expect("case-insensitive built-in loads");
    select_theme_for_command(&dirs, "Tau-Plain-Dark").expect("case-insensitive built-in loads");
}

/// Ensures the runtime `:theme` selection helper honors the user's explicit
/// argument instead of applying the startup-only `TAU_THEME` override.
#[test]
fn command_theme_selection_ignores_env_override() {
    let temp = tempfile::TempDir::new().expect("tempdir");
    let themes = temp.path().join("themes");
    std::fs::create_dir(&themes).expect("themes dir");
    std::fs::write(
        themes.join("custom.json5"),
        r##"{ styles: { "prompt.cwd": { fg: "red" } } }"##,
    )
    .expect("write theme");
    let dirs = tau_config::settings::TauDirs {
        config_dir: Some(temp.path().to_owned()),
        state_dir: None,
    };
    let startup = select_theme_with_env_override(
        &dirs,
        CliTheme::Named("tau-dpc".to_owned()),
        Some(CliTheme::Named("custom".to_owned())),
    )
    .expect("env theme loads");
    let command = select_theme_for_command(&dirs, "tau-dpc").expect("command theme loads");

    let startup_prompt =
        right_prompt_context(&startup, Path::new("/tmp/project"), None, "session-1");
    let command_prompt =
        right_prompt_context(&command, Path::new("/tmp/project"), None, "session-1");
    assert_eq!(
        startup_prompt.spans()[0].style.fg,
        Some(tau_cli_term::Color::Red)
    );
    assert_ne!(
        startup_prompt.spans()[0].style,
        command_prompt.spans()[0].style
    );
}

/// Ensures external theme names resolve to `themes/<name>.json5` under Tau's
/// config directory and affect normal terminal style resolution.
#[test]
fn selected_external_theme_from_config_themes_dir() {
    let temp = tempfile::TempDir::new().expect("tempdir");
    let themes = temp.path().join("themes");
    std::fs::create_dir(&themes).expect("themes dir");
    std::fs::write(
        themes.join("custom.json5"),
        r##"{ styles: { "prompt.cwd": { fg: "red", bold: true } } }"##,
    )
    .expect("write theme");
    let dirs = tau_config::settings::TauDirs {
        config_dir: Some(temp.path().to_owned()),
        state_dir: None,
    };

    let theme = select_theme_with_env_override(&dirs, CliTheme::Named("custom".to_owned()), None)
        .expect("theme loads");
    let prompt = right_prompt_context(&theme, Path::new("/tmp/project"), None, "session-1");

    assert_eq!(prompt.spans()[0].style.fg, Some(tau_cli_term::Color::Red));
    assert!(prompt.spans()[0].style.bold);
}

/// Ensures `:theme` completion/listing can show descriptions for built-in
/// selectors and valid user theme files without exposing path-like or duplicate
/// external names.
#[test]
fn available_theme_choices_include_builtins_and_user_themes() {
    let temp = tempfile::TempDir::new().expect("tempdir");
    let themes = temp.path().join("themes");
    std::fs::create_dir(&themes).expect("themes dir");
    std::fs::write(
        themes.join("custom.json5"),
        r#"{ description: "Custom theme from disk", styles: {} }"#,
    )
    .expect("write custom theme");
    std::fs::write(themes.join("tau-dpc.json5"), "{ styles: {} }").expect("write shadowed theme");
    std::fs::write(themes.join("TAU-DPC.json5"), "{ styles: {} }").expect("write shadowed theme");
    std::fs::write(themes.join("not-a-theme.txt"), "ignored").expect("write ignored file");
    let dirs = tau_config::settings::TauDirs {
        config_dir: Some(temp.path().to_owned()),
        state_dir: None,
    };

    let choices = available_theme_choices(&dirs);
    let names: Vec<String> = choices.iter().map(|choice| choice.name.clone()).collect();

    for name in tau_themes::theme::BUILTIN_THEME_NAMES
        .iter()
        .copied()
        .chain(["custom"])
    {
        assert!(names.iter().any(|choice| choice == name), "missing {name}");
    }
    assert_eq!(
        names
            .iter()
            .filter(|choice| choice.as_str() == "tau-dpc")
            .count(),
        1
    );
    assert!(!names.iter().any(|choice| choice == "TAU-DPC"));
    for removed_alias in ["auto", "dark", "light", "default", "dpc", "tau-light"] {
        assert!(!names.iter().any(|choice| choice == removed_alias));
    }
    assert!(!names.iter().any(|choice| choice == "not-a-theme"));
    assert!(
        choices
            .iter()
            .any(|choice| choice.name == "custom"
                && choice.description == "Custom theme from disk")
    );
    assert!(choices.iter().any(|choice| {
        choice.name == "tau-dpc"
            && choice
                .description
                .contains("rad:z66La5YXmV5jbW77ByXvoeTs1c5n")
    }));
}

/// Ensures no-argument `:theme` listings include descriptions when available,
/// while preserving compact name-only output for themes without metadata.
#[test]
fn theme_listing_formats_descriptions_when_present() {
    assert_eq!(
        ThemeChoice {
            name: "custom".to_owned(),
            description: "Custom theme".to_owned(),
        }
        .into_listing_text(),
        "custom — Custom theme"
    );
    assert_eq!(
        ThemeChoice {
            name: "old".to_owned(),
            description: String::new(),
        }
        .into_listing_text(),
        "old"
    );
}

/// Ensures completion/listing metadata extraction remains bounded: oversized
/// external theme files still appear by name but do not block on full parsing
/// or allocation just to discover an optional description.
#[test]
fn available_theme_choices_omit_description_for_oversized_theme_files() {
    let temp = tempfile::TempDir::new().expect("tempdir");
    let themes = temp.path().join("themes");
    std::fs::create_dir(&themes).expect("themes dir");
    let mut contents = String::from(r#"{ description: "Too large", styles: {}"#);
    contents.extend(std::iter::repeat_n(' ', 70 * 1024));
    contents.push('}');
    std::fs::write(themes.join("huge.json5"), contents).expect("write oversized theme");
    let dirs = tau_config::settings::TauDirs {
        config_dir: Some(temp.path().to_owned()),
        state_dir: None,
    };

    let huge = available_theme_choices(&dirs)
        .into_iter()
        .find(|choice| choice.name == "huge")
        .expect("oversized theme is still listed");

    assert_eq!(huge.description, "");
}

/// Ensures completion/listing metadata extraction does not open non-regular
/// theme entries. They remain visible by name, but with empty descriptions so
/// special files cannot wedge prompt completion or no-argument `:theme` output.
#[test]
fn available_theme_choices_omit_description_for_non_regular_entries() {
    let temp = tempfile::TempDir::new().expect("tempdir");
    let themes = temp.path().join("themes");
    std::fs::create_dir(&themes).expect("themes dir");
    std::fs::create_dir(themes.join("directory.json5")).expect("write directory theme entry");
    #[cfg(unix)]
    let special_name = {
        let socket = themes.join("socket.json5");
        let _listener =
            path_std_os_unix_net::UnixListener::bind(&socket).expect("bind socket theme");
        "socket"
    };
    #[cfg(not(unix))]
    let special_name = "directory";
    let dirs = tau_config::settings::TauDirs {
        config_dir: Some(temp.path().to_owned()),
        state_dir: None,
    };

    let choices = available_theme_choices(&dirs);

    let directory = choices
        .iter()
        .find(|choice| choice.name == "directory")
        .expect("directory theme entry is still listed");
    assert_eq!(directory.description, "");
    let special = choices
        .iter()
        .find(|choice| choice.name == special_name)
        .expect("special theme entry is still listed");
    assert_eq!(special.description, "");
}

/// Ensures malformed external theme files remain available by name for
/// completion/listing even though their optional descriptions cannot be parsed.
#[test]
fn available_theme_choices_omit_description_for_invalid_theme_files() {
    let temp = tempfile::TempDir::new().expect("tempdir");
    let themes = temp.path().join("themes");
    std::fs::create_dir(&themes).expect("themes dir");
    std::fs::write(themes.join("invalid.json5"), "{ description: ").expect("write invalid theme");
    let dirs = tau_config::settings::TauDirs {
        config_dir: Some(temp.path().to_owned()),
        state_dir: None,
    };

    let invalid = available_theme_choices(&dirs)
        .into_iter()
        .find(|choice| choice.name == "invalid")
        .expect("invalid theme is still listed");

    assert_eq!(invalid.description, "");
}

/// Ensures invalid external names fail visibly instead of escaping the themes
/// directory or silently falling back to a built-in theme.
#[test]
fn selected_external_theme_rejects_path_components() {
    let dirs = tau_config::settings::TauDirs {
        config_dir: Some(Path::new("/tmp/tau-test").to_owned()),
        state_dir: None,
    };

    let err = select_theme_with_env_override(&dirs, CliTheme::Named("../bad".to_owned()), None)
        .expect_err("rejects name");

    assert!(err.to_string().contains("invalid theme name"));
}

#[test]
fn display_cwd_replaces_home_prefix() {
    assert_eq!(
        display_cwd(
            Path::new("/home/alice/project"),
            Some(Path::new("/home/alice"))
        ),
        "~/project"
    );
    assert_eq!(
        display_cwd(Path::new("/home/alice"), Some(Path::new("/home/alice"))),
        "~"
    );
    assert_eq!(
        display_cwd(
            Path::new("/home/alice2/project"),
            Some(Path::new("/home/alice"))
        ),
        "/home/alice2/project"
    );
}

/// Creation and existing-agent placeholders preserve nested role styling.
#[test]
fn prompt_input_placeholder_keeps_placeholder_style_around_role_style() {
    let theme = tau_themes::Theme::parse(
        r##"
            {
                styles: {
                    "prompt.placeholder": { fg: "dark_grey", italic: true },
                    "status.role": { fg: "cyan", bold: true },
                }
            }
            "##,
    )
    .expect("test theme parses");
    let prompt =
        prompt_input_placeholder(&theme, Some("engineer"), PromptInputTarget::Creating, None);
    let spans = prompt.spans();

    assert_eq!(spans.len(), 3);
    assert_eq!(spans[0].text, "Write a message to start a new ");
    assert_eq!(spans[0].style.fg, Some(tau_cli_term::Color::DarkGrey));
    assert!(spans[0].style.italic);
    assert_eq!(spans[1].text, "engineer");
    assert_eq!(spans[1].style.fg, Some(tau_cli_term::Color::Cyan));
    assert!(spans[1].style.bold);
    assert!(spans[1].style.italic);
    assert_eq!(spans[2].text, " agent...");
    assert_eq!(spans[2].style.fg, Some(tau_cli_term::Color::DarkGrey));
    assert!(spans[2].style.italic);

    let prompt = prompt_input_placeholder(
        &theme,
        Some("engineer"),
        PromptInputTarget::Agent("engineer_abc".to_owned()),
        Some((AgentNavigationState::Active, true)),
    );
    let spans = prompt.spans();
    assert_eq!(spans[0].text, "Write a message to ");
    assert_eq!(spans[1].text, "engineer_abc");
    assert_eq!(spans[2].text, "...");
    assert_eq!(spans[2].style.fg, Some(tau_cli_term::Color::DarkGrey));
    assert!(spans[2].style.italic);
}

/// Suspended-agent placeholder copy points to the explicit resume action.
#[test]
fn suspended_prompt_input_placeholder_explains_explicit_resume() {
    let theme = tau_themes::Theme::new();
    let prompt = prompt_input_placeholder(
        &theme,
        Some("engineer"),
        PromptInputTarget::Agent("engineer_abc".to_owned()),
        Some((AgentNavigationState::Suspended, false)),
    );
    let text: String = prompt
        .spans()
        .iter()
        .map(|span| span.text.as_str())
        .collect();

    assert_eq!(
        text,
        "This agent is suspended. Use :resume to include it in navigation."
    );
}

/// The directory and session id form one prompt-context span so theme changes
/// cannot style or hide either half independently.
#[test]
fn right_prompt_context_uses_prompt_cwd_style() {
    let theme = tau_themes::Theme::parse(r##"{ styles: { "prompt.cwd": { fg: "dark_grey" } } }"##)
        .expect("test theme parses");
    let prompt = right_prompt_context(&theme, Path::new("/tmp/project"), None, "session-1");

    assert_eq!(prompt.spans()[0].text, "/tmp/project &session-1");
    assert_eq!(prompt.spans().len(), 1);
    assert_eq!(
        prompt.spans()[0].style.fg,
        Some(tau_cli_term::Color::DarkGrey)
    );
}