use serde_json::Value;
use super::secrets::mask_secrets;
use super::truncate::{truncate, MAX_CONTENT_LENGTH, NOISY_TOOL_MAX_LENGTH};
const SKIP_TOOLS: &[&str] = &["WebSearch"];
const NOISY_TOOLS: &[&str] = &["Grep", "Glob"];
pub fn should_capture_tool(tool_name: &str) -> bool {
!SKIP_TOOLS.contains(&tool_name)
}
pub fn is_noisy_tool(tool_name: &str) -> bool {
NOISY_TOOLS.contains(&tool_name)
}
pub fn filter_tool_result(tool_name: &str, result: Option<&Value>) -> Option<String> {
if !should_capture_tool(tool_name) {
return Some("[Result not captured]".to_string());
}
let result = match result {
None | Some(Value::Null) => return None,
Some(value) => value,
};
let result_str = match result {
Value::String(s) => s.clone(),
other => serde_json::to_string(other).unwrap_or_else(|_| other.to_string()),
};
let max_len = if is_noisy_tool(tool_name) {
NOISY_TOOL_MAX_LENGTH
} else {
MAX_CONTENT_LENGTH
};
Some(truncate(&mask_secrets(&result_str), max_len))
}