Skip to main content

steer_core/tools/static_tools/
glob.rs

1use async_trait::async_trait;
2
3use super::workspace_op_error;
4use crate::tools::capability::Capabilities;
5use crate::tools::static_tool::{StaticTool, StaticToolContext, StaticToolError};
6use steer_tools::result::GlobResult;
7use steer_tools::tools::glob::{GlobError, GlobParams, GlobToolSpec};
8use steer_workspace::{GlobRequest, WorkspaceOpContext};
9
10pub struct GlobTool;
11
12#[async_trait]
13impl StaticTool for GlobTool {
14    type Params = GlobParams;
15    type Output = GlobResult;
16    type Spec = GlobToolSpec;
17
18    const DESCRIPTION: &'static str = r#"Fast file pattern matching tool that works with any codebase size.
19- Supports glob patterns like "**/*.js" or "src/**/*.ts"
20- Returns matching file paths sorted by modification time
21- Use this tool when you need to find files by name patterns"#;
22    const REQUIRES_APPROVAL: bool = false;
23    const REQUIRED_CAPABILITIES: Capabilities = Capabilities::WORKSPACE;
24
25    async fn execute(
26        &self,
27        params: Self::Params,
28        ctx: &StaticToolContext,
29    ) -> Result<Self::Output, StaticToolError<GlobError>> {
30        let request = GlobRequest {
31            pattern: params.pattern,
32            path: params.path,
33        };
34        let op_ctx =
35            WorkspaceOpContext::new(ctx.tool_call_id.0.clone(), ctx.cancellation_token.clone());
36        ctx.services
37            .workspace
38            .glob(request, &op_ctx)
39            .await
40            .map_err(|e| StaticToolError::execution(GlobError::Workspace(workspace_op_error(e))))
41    }
42}