Skip to main content

steer_tools/tools/
astgrep.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3use thiserror::Error;
4
5use crate::ToolSpec;
6use crate::error::{ToolExecutionError, WorkspaceOpError};
7use crate::result::AstGrepResult;
8
9pub const AST_GREP_TOOL_NAME: &str = "astgrep";
10
11pub struct AstGrepToolSpec;
12
13impl ToolSpec for AstGrepToolSpec {
14    type Params = AstGrepParams;
15    type Result = AstGrepResult;
16    type Error = AstGrepError;
17
18    const NAME: &'static str = AST_GREP_TOOL_NAME;
19    const DISPLAY_NAME: &'static str = "AST Grep";
20
21    fn execution_error(error: Self::Error) -> ToolExecutionError {
22        ToolExecutionError::AstGrep(error)
23    }
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, Error)]
27#[serde(tag = "code", content = "details", rename_all = "snake_case")]
28pub enum AstGrepError {
29    #[error("{0}")]
30    Workspace(WorkspaceOpError),
31}
32
33#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
34pub struct AstGrepParams {
35    /// The search pattern (code pattern with $METAVAR placeholders)
36    pub pattern: String,
37    /// Language (rust, tsx, python, etc.)
38    pub lang: Option<String>,
39    /// Optional glob pattern to filter files by name (e.g., "*.rs", "*.{ts,tsx}")
40    pub include: Option<String>,
41    /// Optional glob pattern to exclude files
42    pub exclude: Option<String>,
43    /// Optional directory to search in (defaults to current working directory)
44    pub path: Option<String>,
45}