a_agent/context/stdin.rs
1pub fn bound_stdin(input: &[u8], max_bytes: usize) -> String {
2 if input.len() <= max_bytes {
3 return String::from_utf8_lossy(input).into_owned();
4 }
5 let mut start = input.len().saturating_sub(max_bytes);
6 while start < input.len() && (input[start] & 0b1100_0000) == 0b1000_0000 {
7 start += 1;
8 }
9 format!(
10 "[stdin truncated; showing last {max_bytes} bytes]\n{}",
11 String::from_utf8_lossy(&input[start..])
12 )
13}