Skip to content

feat: command-aware output filter framework in ShellExecutor #427

@bug-ops

Description

@bug-ops

Parent

Epic: #426

Summary

Add an OutputFilter trait and registry to zeph-tools that applies command-specific filtering between execute_bash() and ToolOutput construction.

Design

pub trait OutputFilter: Send + Sync {
    /// Commands this filter handles (e.g., ["cargo test", "cargo nextest"])
    fn matches(&self, command: &str) -> bool;

    /// Filter raw output, return compressed version
    fn filter(&self, command: &str, raw_output: &str, exit_code: i32) -> FilterResult;
}

pub struct FilterResult {
    pub output: String,
    pub raw_chars: usize,
    pub filtered_chars: usize,
}

pub struct OutputFilterRegistry {
    filters: Vec<Box<dyn OutputFilter>>,
}

Implementation

  1. Define OutputFilter trait in crates/zeph-tools/src/filter.rs
  2. Add OutputFilterRegistry with register() and apply(command, output, exit_code) methods
  3. Match logic: iterate filters, first matches() wins; fallback = passthrough
  4. Integrate into ShellExecutor::execute_inner() after execute_bash() returns
  5. Add config toggle: [tools.filters] enabled = true
  6. Preserve full output in overflow file before filtering (tee pattern)

Acceptance Criteria

  • OutputFilter trait defined and documented
  • Registry with registration and matching
  • Integration point in ShellExecutor
  • Passthrough filter as default (no behavior change)
  • Config toggle
  • Unit tests for registry matching logic

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions