feat: built-in terminal output filtering to reduce LLM token usage#11472
feat: built-in terminal output filtering to reduce LLM token usage#11472roomote[bot] wants to merge 1 commit intomainfrom
Conversation
Introduces a TerminalOutputFilter module with command-aware output filtering. Built-in filters for test runners, git, package managers, and build tools strip noise while preserving actionable information. New setting terminalOutputFilterEnabled (default: true) with toggle in Terminal Settings UI. Closes #11459
Reviewed the terminal output filter implementation. Found 2 issues in
Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
|
|
||
| function isTestFailureLine(line: string): boolean { | ||
| if (/^(FAIL|✕|✗|×|✘)\s/.test(line)) return true | ||
| if (/^(\s+●\s)/.test(line)) return true // Jest failure indicator |
There was a problem hiding this comment.
isTestFailureLine is always called with the trimmed string (line 67), but this regex ^(\s+●\s) requires leading whitespace to match. A trimmed string will never have leading whitespace, so this pattern is dead code. Jest failure blocks like ● TestSuite > test name won't be detected as failure block starts, which means the test name context line and its indented block contents are lost from the filtered output. The fix is to match against ^\u25cf\s instead (no leading whitespace requirement).
| if (/^(\s+●\s)/.test(line)) return true // Jest failure indicator | |
| if (/^\u25cf\s/.test(line)) return true // Jest failure indicator |
Fix it with Roo Code or mention @roomote and request a fix.
| // Long format patterns | ||
| if (/^\s*(modified|new file|deleted|renamed|copied):\s+/.test(trimmed)) { | ||
| // Determine context from previous section headers | ||
| unstaged.push(trimmed) | ||
| } |
There was a problem hiding this comment.
The long-format parser always pushes to unstaged[] regardless of which section the line appears under. git status without flags (the default) uses long format with distinct sections: "Changes to be committed:" (staged) vs "Changes not staged for commit:" (unstaged). Since the code doesn't track which section header was last seen, staged files in long-format output get misreported as unstaged to the LLM. This could cause the model to issue incorrect git operations (e.g., re-staging files that are already staged). Consider tracking a currentSection variable by matching section header lines like /Changes to be committed/ and /Changes not staged/.
Fix it with Roo Code or mention @roomote and request a fix.
Related GitHub Issue
Closes: #11459
Description
This PR attempts to address Issue #11459 by implementing built-in CLI output filtering/compression to reduce token usage. Feedback and guidance are welcome.
Key implementation details:
New
TerminalOutputFiltermodule (src/integrations/terminal/TerminalOutputFilter.ts): A filter engine with pluggable, command-aware rules. Each rule matches against the command string and transforms the output into a compact summary while preserving actionable information (errors, failures).Built-in filters for common commands:
Integration in
ExecuteCommandTool.ts: Filter is applied at the point where output is formatted for the LLM tool result, for both inline (small) and persisted (large/truncated) output paths. A filter indicator is appended telling the LLM that filtering occurred and how to access full output viaread_command_output.New setting
terminalOutputFilterEnabled(default: true): Added toGlobalSettings,ExtensionState, and the Terminal Settings UI as a checkbox toggle.Safety mechanisms:
OutputInterceptor/read_command_output-- filtering only affects what the LLM seesTest Procedure
Added comprehensive test suite (
src/integrations/terminal/__tests__/TerminalOutputFilter.spec.ts) with 20 test cases covering:All 20 new tests pass
Existing
OutputInterceptortests (25) still passAll monorepo lint and type-check tasks pass
Pre-Submission Checklist
Documentation Updates
Additional Notes
This is Phase 1 of the implementation plan outlined in #11459. Phase 2 (user-defined custom rules, per-session toggle, more filter patterns) can follow in a future PR.
The filter only affects what the LLM sees in its context window -- the UI display and full persisted output are unchanged. Users can always toggle the feature off via the new "Smart output filtering" checkbox in Terminal Settings.