Skip to content

Commit 94b29ec

Browse files
jgarzikclaude
andcommitted
Add Search tool for regex content search
Implements a new Search tool matching Claude Code's interface with: - pattern (required): regex pattern to search for - path: directory to search recursively (default: project root) - output_mode: files_with_matches, content, or count - glob: filter files by pattern (e.g., "*.rs") - case_insensitive: case-insensitive matching - context_before/after: lines of context (content mode) - max_results: limit results (default: 100) Includes 10 unit tests covering all functionality. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 53ae092 commit 94b29ec

5 files changed

Lines changed: 509 additions & 3 deletions

File tree

Cargo.lock

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@ uuid = { version = "1", features = ["v4"] }
2828
wait-timeout = "0.2"
2929
walkdir = "2"
3030
shell-words = "1.1"
31+
32+
[dev-dependencies]
33+
tempfile = "3"

src/policy.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl ToolCategory {
3030
/// Determine the category of a tool by name
3131
pub fn from_tool_name(name: &str) -> Self {
3232
match name {
33-
"Read" | "Grep" | "Glob" => ToolCategory::ReadOnly,
33+
"Read" | "Grep" | "Glob" | "Search" => ToolCategory::ReadOnly,
3434
"Write" | "Edit" => ToolCategory::Mutation,
3535
"Bash" => ToolCategory::Execution,
3636
_ if name.starts_with("mcp.") => ToolCategory::Execution, // MCP tools require permission
@@ -82,7 +82,7 @@ impl PolicyEngine {
8282
/// Extract the primary argument for rule matching from tool args
8383
/// For Bash: the command string
8484
/// For Write/Edit/Read: the path
85-
/// For Grep/Glob: the pattern
85+
/// For Grep/Glob/Search: the pattern
8686
fn extract_tool_arg(tool: &str, args: &Value) -> Option<String> {
8787
match tool {
8888
"Bash" => args
@@ -92,7 +92,7 @@ impl PolicyEngine {
9292
"Write" | "Edit" | "Read" => {
9393
args.get("path").and_then(|v| v.as_str()).map(String::from)
9494
}
95-
"Grep" | "Glob" => args
95+
"Grep" | "Glob" | "Search" => args
9696
.get("pattern")
9797
.and_then(|v| v.as_str())
9898
.map(String::from),

src/tools/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ mod glob;
55
mod grep;
66
pub mod mcp_dispatch;
77
mod read;
8+
mod search;
89
pub mod task;
910
mod write;
1011

@@ -34,6 +35,7 @@ pub fn schemas(opts: &SchemaOptions) -> Vec<Value> {
3435
edit::schema(opts),
3536
grep::schema(opts),
3637
glob::schema(opts),
38+
search::schema(opts),
3739
bash::schema(opts),
3840
]
3941
}
@@ -46,6 +48,7 @@ pub fn schemas_with_task(opts: &SchemaOptions) -> Vec<Value> {
4648
edit::schema(opts),
4749
grep::schema(opts),
4850
glob::schema(opts),
51+
search::schema(opts),
4952
bash::schema(opts),
5053
task::schema(opts),
5154
activate_skill::schema(opts),
@@ -61,6 +64,7 @@ pub fn execute(name: &str, args: Value, root: &Path, bash_config: &BashConfig) -
6164
"Edit" => edit::execute(args, root),
6265
"Grep" => grep::execute(args, root),
6366
"Glob" => glob::execute(args, root),
67+
"Search" => search::execute(args, root),
6468
"Bash" => bash::execute(args, root, bash_config),
6569
_ => Ok(
6670
json!({ "error": { "code": "unknown_tool", "message": format!("Unknown tool: {}", name) } }),

0 commit comments

Comments
 (0)