Skip to main content

steer_tools/tools/
grep.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3use thiserror::Error;
4
5use crate::ToolSpec;
6use crate::error::{ToolExecutionError, WorkspaceOpError};
7use crate::result::GrepResult;
8
9pub const GREP_TOOL_NAME: &str = "grep";
10
11pub struct GrepToolSpec;
12
13impl ToolSpec for GrepToolSpec {
14    type Params = GrepParams;
15    type Result = GrepResult;
16    type Error = GrepError;
17
18    const NAME: &'static str = GREP_TOOL_NAME;
19    const DISPLAY_NAME: &'static str = "Grep";
20
21    fn execution_error(error: Self::Error) -> ToolExecutionError {
22        ToolExecutionError::Grep(error)
23    }
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, Error)]
27#[serde(tag = "code", content = "details", rename_all = "snake_case")]
28pub enum GrepError {
29    #[error("{0}")]
30    Workspace(WorkspaceOpError),
31}
32
33#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
34pub struct GrepParams {
35    /// The search pattern (regex or literal string). If invalid regex, searches for literal text
36    pub pattern: String,
37    /// Optional glob pattern to filter files by name (e.g., "*.rs", "*.{ts,tsx}")
38    pub include: Option<String>,
39    /// Optional directory to search in (defaults to current working directory)
40    pub path: Option<String>,
41}