Skip to content

feat: ANSI escape and progress bar stripping #433

@bug-ops

Description

@bug-ops

Parent

Epic: #426

Summary

Strip ANSI escape sequences and progress bar output from all tool outputs as a baseline preprocessing step before command-specific filters.

Expected Savings

5-15% baseline on all outputs, 85-95% on progress-heavy commands (cargo build with progress, wget, pip install).

Behavior

  • Strip all ANSI escape codes: \x1b\[[0-9;]*[a-zA-Z]
  • Strip carriage return progress lines: lines ending with \r that rewrite the same terminal line
  • Collapse consecutive blank lines to max 2
  • Strip common progress patterns: [=====> ] 45%, Downloading..., Compiling N/M

Implementation

  • sanitize_output(raw: &str) -> String function in filter.rs, applied before any command-specific filter
  • Should be fast (single-pass regex or manual char iteration)
  • Already partially handled by terminal — verify what execute_bash captures vs raw PTY

Acceptance Criteria

  • ANSI codes stripped
  • Progress lines collapsed
  • Blank line normalization
  • Performance: < 1ms for 100KB output
  • Unit tests

Metadata

Metadata

Assignees

No one assigned

    Labels

    M26Milestone 26: Smart tool output filteringP1Important prioritysize/Stoken-savingsToken economy improvementstoolsTool execution and MCP integration

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions