You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: preserve tail when truncating bash tool output
Prioritize the tail of bash_tool output when truncation is needed,
so final errors and command results remain visible. Add regression
tests for truncation and render_result behavior.
let head_len = content_budget.saturating_sub(tail_len);
65
+
66
+
let head:String = chars[..head_len].iter().collect();
67
+
let tail:String = chars[chars.len() - tail_len..].iter().collect();
68
+
69
+
format!("{head}{separator}{tail}")
51
70
}
52
71
53
72
/// Result of shell resolution for bash tool
@@ -142,7 +161,7 @@ impl BashTool {
142
161
let cleaned_output = strip_ansi(output_text);
143
162
let output_len = cleaned_output.chars().count();
144
163
if output_len > MAX_OUTPUT_LENGTH{
145
-
let truncated = truncate_string_by_chars(&cleaned_output,MAX_OUTPUT_LENGTH);
164
+
let truncated = truncate_output_preserving_tail(&cleaned_output,MAX_OUTPUT_LENGTH);
146
165
result_string.push_str(&format!(
147
166
"<output truncated=\"true\">{}</output>",
148
167
truncated
@@ -226,7 +245,7 @@ Usage notes:
226
245
- DO NOT use multiline commands or HEREDOC syntax (e.g., <<EOF, heredoc with newlines). Only single-line commands are supported.
227
246
- You can specify an optional timeout in milliseconds (up to 600000ms / 10 minutes). If not specified, commands will timeout after 120000ms (2 minutes).
228
247
- It is very helpful if you write a clear, concise description of what this command does. For simple commands, keep it brief (5-10 words). For complex commands (piped commands, obscure flags, or anything hard to understand at a glance), add enough context to clarify what it does.
229
-
- If the output exceeds {MAX_OUTPUT_LENGTH} characters, output will be truncated before being returned to you.
248
+
- If the output exceeds {MAX_OUTPUT_LENGTH} characters, output will be truncated before being returned to you, with the tail of the output preserved because the ending is usually more important.
230
249
- You can use the `run_in_background` parameter to run the command in a new dedicated background terminal session. The tool returns the background session ID immediately without waiting for the command to finish. Only use this for long-running processes (e.g., dev servers, watchers) where you don't need the output right away. You do not need to append '&' to the command. NOTE: `timeout_ms` is ignored when `run_in_background` is true.
231
250
- Each result includes a `<terminal_session_id>` tag identifying the terminal session. The persistent shell session ID remains constant throughout the entire conversation; background sessions each have their own unique ID.
232
251
- The output may include the command echo and/or the shell prompt (e.g., `PS C:\path>`). Do not treat these as part of the command's actual result.
0 commit comments