Skip to main content

soothe_client/
verbosity.rs

1//! Verbosity levels and tiers for event filtering.
2
3/// Quiet verbosity.
4pub const VERBOSITY_QUIET: &str = "quiet";
5/// Normal verbosity.
6pub const VERBOSITY_NORMAL: &str = "normal";
7/// Debug verbosity.
8pub const VERBOSITY_DEBUG: &str = "debug";
9
10/// Minimum verbosity level at which content is visible.
11#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
12#[repr(u8)]
13pub enum VerbosityTier {
14    /// Always visible (errors, assistant text, final reports).
15    Quiet = 0,
16    /// Standard progress (plan updates, milestones, agentic loop).
17    Normal = 1,
18    /// Detailed internals (protocol events, tool calls, subagent activity).
19    Detailed = 2,
20    /// Everything including internals (thinking, heartbeats).
21    Debug = 3,
22    /// Never shown at any level (implementation details).
23    Internal = 99,
24}
25
26fn verbosity_level_value(verbosity: &str) -> i32 {
27    match verbosity {
28        VERBOSITY_QUIET => 0,
29        VERBOSITY_NORMAL => 1,
30        VERBOSITY_DEBUG => 3,
31        _ => 1,
32    }
33}
34
35/// Returns true if content at `tier` is visible at `verbosity`.
36pub fn should_show(tier: VerbosityTier, verbosity: &str) -> bool {
37    if tier == VerbosityTier::Internal {
38        return false;
39    }
40    (tier as i32) <= verbosity_level_value(verbosity)
41}
42
43/// Whether `s` is a valid verbosity level string.
44pub fn is_valid_verbosity_level(s: &str) -> bool {
45    matches!(s, VERBOSITY_QUIET | VERBOSITY_NORMAL | VERBOSITY_DEBUG)
46}
47
48#[cfg(test)]
49mod tests {
50    use super::*;
51
52    #[test]
53    fn quiet_always_shows_quiet_tier() {
54        assert!(should_show(VerbosityTier::Quiet, VERBOSITY_QUIET));
55        assert!(!should_show(VerbosityTier::Normal, VERBOSITY_QUIET));
56    }
57
58    #[test]
59    fn internal_never_shows() {
60        assert!(!should_show(VerbosityTier::Internal, VERBOSITY_DEBUG));
61    }
62
63    #[test]
64    fn valid_levels() {
65        assert!(is_valid_verbosity_level("normal"));
66        assert!(!is_valid_verbosity_level("loud"));
67    }
68}