fix(shell-output): 🐛 Strip ANSI escape sequences from tool output - #111
Conversation
AI Code Review SummaryPR: #111 (fix(shell-output): 🐛 Strip ANSI escape sequences from tool output) Overall AssessmentDetected 1 actionable findings, prioritize CRITICAL/HIGH before merge. Major Findings by Severity
Actionable Suggestions
Potential Risks
Test Suggestions
File-Level Coverage Notes
Inline Downgraded Items (processed but not inline)
Coverage Status
Uncovered list:
No-patch covered list:
Runtime/Budget
|
|
|
||
| while index < chars.len() { | ||
| match chars[index] { | ||
| '\u{1b}' => { |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
| /// The sanitizer removes CSI/OSC/DCS/APC-style sequences, applies backspaces, | ||
| /// drops carriage returns, and preserves printable text plus `\n` / `\t`. | ||
| pub fn sanitize_terminal_output(raw: &str) -> String { | ||
| let chars: Vec<char> = raw.chars().collect(); |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
| } | ||
| } | ||
| } | ||
| 'P' | 'X' | '^' | '_' => { |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
| /// | ||
| /// The sanitizer removes CSI/OSC/DCS/APC-style sequences, applies backspaces, | ||
| /// drops carriage returns, and preserves printable text plus `\n` / `\t`. | ||
| pub fn sanitize_terminal_output(raw: &str) -> String { |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
| @@ -1,6 +1,7 @@ | |||
| pub mod edit; | |||
There was a problem hiding this comment.
Automated review completed for this PR diff. No concrete inline issue was selected after aggregation.
| output.pop(); | ||
| index += 1; | ||
| } | ||
| '\r' => { |
There was a problem hiding this comment.
[LOW] Carriage return handling drops character instead of simulating overwrite
The sanitizer simply drops the \r character. In terminal semantics, \r moves the cursor to the beginning of the line, and subsequent characters overwrite the existing line. Dropping it can result in duplicated text for outputs with progress bars or carriage returns.
Suggestion: Consider maintaining line-level context to handle carriage returns by truncating the current line back to the beginning, or at least document this limitation.
Risk: Agent may receive duplicated text if a process uses \r to overwrite the current line (e.g., progress bars).
Confidence: 0.85
Summary
shelltool stdout/stderr before truncation so tool cards no longer show raw escape-code mojibake.Test Plan
cargo fmt --manifest-path src-tauri/Cargo.toml --checkcargo test --manifest-path src-tauri/Cargo.toml output_sanitizer -- --nocapturecargo test --manifest-path src-tauri/Cargo.toml truncation -- --nocapture🤖 Generated with TiyCode