@@ -35,6 +35,9 @@ use fancy_regex::Regex;
3535use serde:: { Deserialize , Serialize } ;
3636
3737use crate :: tools:: ToolDecision ;
38+ use crate :: tools:: {
39+ EditFileTool , FetchUrlTool , ReadFileTool , ShellTool , WebSearchTool , WriteFileTool ,
40+ } ;
3841
3942/// Filter configuration with allow and deny pattern lists
4043#[ derive( Debug , Clone , Default , Serialize , Deserialize ) ]
@@ -94,12 +97,12 @@ impl CompiledToolFilter {
9497/// Get the primary parameter name for a tool
9598fn primary_param ( tool_name : & str ) -> & ' static str {
9699 match tool_name {
97- "shell" => "command" ,
98- "read_file" => "path" ,
99- "write_file" => "path" ,
100- "edit_file" => "path" ,
101- "fetch_url" => "url" ,
102- "web_search" => "query" ,
100+ x if x == ShellTool :: NAME => "command" ,
101+ x if x == ReadFileTool :: NAME => "path" ,
102+ x if x == WriteFileTool :: NAME => "path" ,
103+ x if x == EditFileTool :: NAME => "path" ,
104+ x if x == FetchUrlTool :: NAME => "url" ,
105+ x if x == WebSearchTool :: NAME => "query" ,
103106 _ => "command" , // Default fallback
104107 }
105108}
@@ -158,7 +161,7 @@ mod tests {
158161 allow : vec ! [ r"^ls\b" . to_string( ) , r"^cat\b" . to_string( ) ] ,
159162 deny : vec ! [ ] ,
160163 } ;
161- let filter = CompiledToolFilter :: compile ( "shell" , & config) . unwrap ( ) ;
164+ let filter = CompiledToolFilter :: compile ( ShellTool :: NAME , & config) . unwrap ( ) ;
162165
163166 assert_eq ! ( filter. evaluate( "ls -la" ) , Some ( ToolDecision :: Approve ) ) ;
164167 assert_eq ! ( filter. evaluate( "cat file.txt" ) , Some ( ToolDecision :: Approve ) ) ;
@@ -171,7 +174,7 @@ mod tests {
171174 allow : vec ! [ ] ,
172175 deny : vec ! [ r"rm\s+-rf\s+/" . to_string( ) , r"sudo\s+rm" . to_string( ) ] ,
173176 } ;
174- let filter = CompiledToolFilter :: compile ( "shell" , & config) . unwrap ( ) ;
177+ let filter = CompiledToolFilter :: compile ( ShellTool :: NAME , & config) . unwrap ( ) ;
175178
176179 assert_eq ! ( filter. evaluate( "rm -rf /" ) , Some ( ToolDecision :: Deny ) ) ;
177180 assert_eq ! ( filter. evaluate( "sudo rm -rf" ) , Some ( ToolDecision :: Deny ) ) ;
@@ -184,7 +187,7 @@ mod tests {
184187 allow : vec ! [ r"^ls" . to_string( ) ] ,
185188 deny : vec ! [ r"sudo" . to_string( ) ] ,
186189 } ;
187- let filter = CompiledToolFilter :: compile ( "shell" , & config) . unwrap ( ) ;
190+ let filter = CompiledToolFilter :: compile ( ShellTool :: NAME , & config) . unwrap ( ) ;
188191
189192 // "sudo ls" matches both allow (^ls) and deny (sudo), deny wins
190193 assert_eq ! ( filter. evaluate( "sudo ls" ) , Some ( ToolDecision :: Deny ) ) ;
@@ -199,19 +202,19 @@ mod tests {
199202 } ;
200203
201204 let mut configs = HashMap :: new ( ) ;
202- configs. insert ( "shell" . to_string ( ) , config) ;
205+ configs. insert ( ShellTool :: NAME . to_string ( ) , config) ;
203206 let filters = ToolFilters :: compile ( & configs) . unwrap ( ) ;
204207
205208 assert_eq ! (
206- filters. evaluate( "shell" , & json!( { "command" : "ls -la" } ) ) ,
209+ filters. evaluate( ShellTool :: NAME , & json!( { "command" : "ls -la" } ) ) ,
207210 Some ( ToolDecision :: Approve )
208211 ) ;
209212 assert_eq ! (
210- filters. evaluate( "shell" , & json!( { "command" : "rm -rf /" } ) ) ,
213+ filters. evaluate( ShellTool :: NAME , & json!( { "command" : "rm -rf /" } ) ) ,
211214 Some ( ToolDecision :: Deny )
212215 ) ;
213216 assert_eq ! (
214- filters. evaluate( "shell" , & json!( { "command" : "echo hello" } ) ) ,
217+ filters. evaluate( ShellTool :: NAME , & json!( { "command" : "echo hello" } ) ) ,
215218 None
216219 ) ;
217220 }
@@ -224,19 +227,19 @@ mod tests {
224227 } ;
225228
226229 let mut configs = HashMap :: new ( ) ;
227- configs. insert ( "read_file" . to_string ( ) , config) ;
230+ configs. insert ( ReadFileTool :: NAME . to_string ( ) , config) ;
228231 let filters = ToolFilters :: compile ( & configs) . unwrap ( ) ;
229232
230233 assert_eq ! (
231- filters. evaluate( "read_file" , & json!( { "path" : "src/main.rs" } ) ) ,
234+ filters. evaluate( ReadFileTool :: NAME , & json!( { "path" : "src/main.rs" } ) ) ,
232235 Some ( ToolDecision :: Approve )
233236 ) ;
234237 assert_eq ! (
235- filters. evaluate( "read_file" , & json!( { "path" : ".env" } ) ) ,
238+ filters. evaluate( ReadFileTool :: NAME , & json!( { "path" : ".env" } ) ) ,
236239 Some ( ToolDecision :: Deny )
237240 ) ;
238241 assert_eq ! (
239- filters. evaluate( "read_file" , & json!( { "path" : "README.md" } ) ) ,
242+ filters. evaluate( ReadFileTool :: NAME , & json!( { "path" : "README.md" } ) ) ,
240243 None
241244 ) ;
242245 }
@@ -249,12 +252,12 @@ mod tests {
249252 } ;
250253
251254 let mut configs = HashMap :: new ( ) ;
252- configs. insert ( "shell" . to_string ( ) , config) ;
255+ configs. insert ( ShellTool :: NAME . to_string ( ) , config) ;
253256 let filters = ToolFilters :: compile ( & configs) . unwrap ( ) ;
254257
255258 // Missing "command" param should result in None
256259 assert_eq ! (
257- filters. evaluate( "shell" , & json!( { "other_param" : "value" } ) ) ,
260+ filters. evaluate( ShellTool :: NAME , & json!( { "other_param" : "value" } ) ) ,
258261 None
259262 ) ;
260263 }
@@ -265,7 +268,7 @@ mod tests {
265268 allow : vec ! [ r"[invalid" . to_string( ) ] ,
266269 deny : vec ! [ ] ,
267270 } ;
268- let result = CompiledToolFilter :: compile ( "shell" , & config) ;
271+ let result = CompiledToolFilter :: compile ( ShellTool :: NAME , & config) ;
269272 assert ! ( result. is_err( ) ) ;
270273 }
271274
@@ -277,7 +280,7 @@ mod tests {
277280 } ;
278281
279282 let mut configs = HashMap :: new ( ) ;
280- configs. insert ( "shell" . to_string ( ) , config) ;
283+ configs. insert ( ShellTool :: NAME . to_string ( ) , config) ;
281284 let filters = ToolFilters :: compile ( & configs) . unwrap ( ) ;
282285
283286 // Unknown tool returns None
@@ -290,12 +293,12 @@ mod tests {
290293 #[ test]
291294 fn test_empty_config_skipped ( ) {
292295 let mut configs = HashMap :: new ( ) ;
293- configs. insert ( "shell" . to_string ( ) , ToolFilterConfig :: default ( ) ) ;
296+ configs. insert ( ShellTool :: NAME . to_string ( ) , ToolFilterConfig :: default ( ) ) ;
294297 let filters = ToolFilters :: compile ( & configs) . unwrap ( ) ;
295298
296299 // Empty config means no filter registered
297300 assert_eq ! (
298- filters. evaluate( "shell" , & json!( { "command" : "ls" } ) ) ,
301+ filters. evaluate( ShellTool :: NAME , & json!( { "command" : "ls" } ) ) ,
299302 None
300303 ) ;
301304 }
0 commit comments