vtcode_config/constants/
output_limits.rs1pub const MAX_AGENT_MESSAGES_SIZE: usize = 4 * 1024 * 1024;
7
8pub const MAX_ALL_MESSAGES_SIZE: usize = 24 * 1024 * 1024;
10
11pub const ERROR_LOG_BUFFER_SIZE_LIMIT_BYTES: usize = 10 * 1024 * 1024;
13
14pub const MAX_LINE_LENGTH: usize = 256 * 1024;
17
18pub const DEFAULT_MESSAGE_LIMIT: usize = 4_000;
20
21pub const MAX_MESSAGE_LIMIT: usize = 20_000;
23
24pub const TRUNCATION_MARKER: &str = "\n[... content truncated due to size limit ...]";
26
27#[inline]
39pub fn collect_with_truncation(
40 output: &mut String,
41 new_content: &str,
42 max_size: usize,
43 truncated: &mut bool,
44) -> bool {
45 let new_size = output.len() + new_content.len();
46
47 if new_size > max_size {
48 if !*truncated {
49 output.push_str(TRUNCATION_MARKER);
50 *truncated = true;
51 }
52 return false;
53 }
54
55 output.push_str(new_content);
56 true
57}
58
59#[cfg(test)]
60mod tests {
61 use super::*;
62
63 #[test]
64 fn test_collect_within_limit() {
65 let mut output = String::new();
66 let mut truncated = false;
67
68 assert!(collect_with_truncation(
69 &mut output,
70 "hello",
71 100,
72 &mut truncated
73 ));
74 assert_eq!(output, "hello");
75 assert!(!truncated);
76 }
77
78 #[test]
79 fn test_collect_at_limit_triggers_truncation() {
80 let mut output = String::from("hello");
81 let mut truncated = false;
82
83 assert!(!collect_with_truncation(
84 &mut output,
85 " world that exceeds",
86 10,
87 &mut truncated
88 ));
89 assert!(output.contains(TRUNCATION_MARKER));
90 assert!(truncated);
91 }
92
93 #[test]
94 fn test_truncation_marker_appended_only_once() {
95 let mut output = String::new();
96 let mut truncated = false;
97
98 collect_with_truncation(&mut output, "first content", 5, &mut truncated);
100 let len_after_marker = output.len();
101 assert!(truncated);
102
103 collect_with_truncation(&mut output, "second content", 5, &mut truncated);
105 assert_eq!(output.len(), len_after_marker);
106 }
107}