(
&self,
args: serde_json::Value,
ctx: ToolContext,
)
| 75 | } |
| 76 | |
| 77 | async fn execute( |
| 78 | &self, |
| 79 | args: serde_json::Value, |
| 80 | ctx: ToolContext, |
| 81 | ) -> Result<ToolResult, ToolError> { |
| 82 | let pattern: String = args["pattern"] |
| 83 | .as_str() |
| 84 | .ok_or_else(|| ToolError::InvalidArguments("pattern is required".into()))? |
| 85 | .to_string(); |
| 86 | |
| 87 | let search_path: String = args["path"] |
| 88 | .as_str() |
| 89 | .map(|s| s.to_string()) |
| 90 | .unwrap_or_else(|| ctx.directory.clone()); |
| 91 | |
| 92 | let glob_filter: Option<String> = args["glob"].as_str().map(|s| s.to_string()); |
| 93 | |
| 94 | let ignore_case: bool = args["ignore_case"].as_bool().unwrap_or(false); |
| 95 | |
| 96 | let include_hidden: bool = args["hidden"].as_bool().unwrap_or(false); |
| 97 | |
| 98 | let base_dir = if search_path.is_empty() { |
| 99 | &self.directory |
| 100 | } else { |
| 101 | Path::new(&search_path) |
| 102 | }; |
| 103 | |
| 104 | let base_dir_str = base_dir.to_string_lossy().to_string(); |
| 105 | |
| 106 | if ctx.is_external_path(&base_dir_str) { |
| 107 | ctx.ask_permission( |
| 108 | crate::PermissionRequest::new("external_directory") |
| 109 | .with_pattern(format!("{}/*", base_dir_str)) |
| 110 | .with_metadata("path", serde_json::json!(&base_dir_str)), |
| 111 | ) |
| 112 | .await?; |
| 113 | } |
| 114 | |
| 115 | ctx.ask_permission( |
| 116 | crate::PermissionRequest::new("grep") |
| 117 | .with_pattern(&pattern) |
| 118 | .always_allow() |
| 119 | .with_metadata("path", serde_json::json!(&base_dir_str)), |
| 120 | ) |
| 121 | .await?; |
| 122 | |
| 123 | let regex_pattern = if ignore_case { |
| 124 | format!("(?i){}", pattern) |
| 125 | } else { |
| 126 | pattern.clone() |
| 127 | }; |
| 128 | |
| 129 | let regex = Regex::new(®ex_pattern) |
| 130 | .map_err(|e| ToolError::InvalidArguments(format!("Invalid regex: {}", e)))?; |
| 131 | |
| 132 | let glob_pattern = glob_filter |
| 133 | .as_ref() |
| 134 | .and_then(|g| glob::Pattern::new(g).ok()); |
nothing calls this directly
no test coverage detected