steer_core/tools/static_tools/
ls.rs1use 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::FileListResult;
7use steer_tools::tools::ls::{LsError, LsParams, LsToolSpec};
8use steer_workspace::{ListDirectoryRequest, WorkspaceOpContext};
9
10pub struct LsTool;
11
12#[async_trait]
13impl StaticTool for LsTool {
14 type Params = LsParams;
15 type Output = FileListResult;
16 type Spec = LsToolSpec;
17
18 const DESCRIPTION: &'static str = "Lists files and directories in a given path. The path parameter must be an absolute path, not a relative path. You should generally prefer the Glob and Grep tools, if you know which directories to search.";
19 const REQUIRES_APPROVAL: bool = false;
20 const REQUIRED_CAPABILITIES: Capabilities = Capabilities::WORKSPACE;
21
22 async fn execute(
23 &self,
24 params: Self::Params,
25 ctx: &StaticToolContext,
26 ) -> Result<Self::Output, StaticToolError<LsError>> {
27 let request = ListDirectoryRequest {
28 path: params.path,
29 ignore: params.ignore,
30 };
31 let op_ctx =
32 WorkspaceOpContext::new(ctx.tool_call_id.0.clone(), ctx.cancellation_token.clone());
33 ctx.services
34 .workspace
35 .list_directory(request, &op_ctx)
36 .await
37 .map_err(|e| StaticToolError::execution(LsError::Workspace(workspace_op_error(e))))
38 }
39}