Skip to main content

ralph_workflow/config/
truncation.rs

1//! Truncation limits for verbosity levels.
2//!
3//! This module defines the character limits for different content types
4//! at each verbosity level. These limits control how much output is displayed
5//! in the terminal to balance usability with information density.
6//!
7//! # Content Types
8//!
9//! - `text`: Assistant text output
10//! - `tool_result`: Tool execution results
11//! - `tool_input`: Tool input parameters
12//! - `user`: User messages
13//! - `result`: Final result summaries
14//! - `command`: Command execution strings
15//! - `agent_msg`: Agent messages/thinking
16
17/// Maximum number of lines to show for multi-line tool output.
18pub const MAX_OUTPUT_LINES: usize = 5;
19
20/// Truncation limits for Quiet verbosity mode.
21///
22/// Quiet mode uses aggressive truncation to minimize output noise.
23pub mod quiet {
24    pub const TEXT: usize = 80;
25    pub const TOOL_RESULT: usize = 60;
26    pub const TOOL_INPUT: usize = 40;
27    pub const USER: usize = 40;
28    pub const RESULT: usize = 300;
29    pub const COMMAND: usize = 60;
30    pub const AGENT_MSG: usize = 80;
31    pub const DEFAULT: usize = 60;
32}
33
34/// Truncation limits for Normal verbosity mode.
35///
36/// Normal mode provides balanced output with moderate truncation
37/// for better usability while still keeping output manageable.
38pub mod normal {
39    pub const TEXT: usize = 1000;
40    pub const TOOL_RESULT: usize = 500;
41    pub const TOOL_INPUT: usize = 300;
42    pub const USER: usize = 200;
43    pub const RESULT: usize = 3000;
44    pub const COMMAND: usize = 400;
45    pub const AGENT_MSG: usize = 1000;
46    pub const DEFAULT: usize = 500;
47}
48
49/// Truncation limits for Verbose verbosity mode.
50///
51/// Verbose is the default mode, providing reasonable limits to help
52/// users understand agent behavior without overwhelming output.
53pub mod verbose {
54    pub const TEXT: usize = 2000;
55    pub const TOOL_RESULT: usize = 500;
56    pub const TOOL_INPUT: usize = 300;
57    pub const USER: usize = 400;
58    pub const RESULT: usize = 5000;
59    pub const COMMAND: usize = 400;
60    pub const AGENT_MSG: usize = 2000;
61    pub const DEFAULT: usize = 1000;
62}
63
64/// Effectively unlimited output for Full/Debug modes.
65pub const UNLIMITED: usize = 999_999;
66
67/// Returns the truncation limit for a content type at a given verbosity level.
68///
69/// # Arguments
70///
71/// * `level` - The verbosity level (0=Quiet, 1=Normal, 2=Verbose, 3+=Full/Debug)
72/// * `content_type` - The type of content being truncated
73///
74/// # Returns
75///
76/// The maximum number of characters to display for the given content type.
77pub fn get_limit(level: u8, content_type: &str) -> usize {
78    match level {
79        0 => match content_type {
80            "text" => quiet::TEXT,
81            "tool_result" => quiet::TOOL_RESULT,
82            "tool_input" => quiet::TOOL_INPUT,
83            "user" => quiet::USER,
84            "result" => quiet::RESULT,
85            "command" => quiet::COMMAND,
86            "agent_msg" => quiet::AGENT_MSG,
87            _ => quiet::DEFAULT,
88        },
89        1 => match content_type {
90            "text" => normal::TEXT,
91            "tool_result" => normal::TOOL_RESULT,
92            "tool_input" => normal::TOOL_INPUT,
93            "user" => normal::USER,
94            "result" => normal::RESULT,
95            "command" => normal::COMMAND,
96            "agent_msg" => normal::AGENT_MSG,
97            _ => normal::DEFAULT,
98        },
99        2 => match content_type {
100            "text" => verbose::TEXT,
101            "tool_result" => verbose::TOOL_RESULT,
102            "tool_input" => verbose::TOOL_INPUT,
103            "user" => verbose::USER,
104            "result" => verbose::RESULT,
105            "command" => verbose::COMMAND,
106            "agent_msg" => verbose::AGENT_MSG,
107            _ => verbose::DEFAULT,
108        },
109        _ => UNLIMITED,
110    }
111}