steer_core/tools/static_tools/
replace.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::ReplaceResult;
7use steer_tools::tools::replace::{ReplaceError, ReplaceParams, ReplaceToolSpec};
8use steer_workspace::{WorkspaceOpContext, WriteFileRequest};
9
10pub struct ReplaceTool;
11
12#[async_trait]
13impl StaticTool for ReplaceTool {
14 type Params = ReplaceParams;
15 type Output = ReplaceResult;
16 type Spec = ReplaceToolSpec;
17
18 const DESCRIPTION: &'static str = r"Writes a file to the local filesystem.
19
20Before using this tool:
21
221. Use the read_file tool to understand the file's contents and context
23
242. Directory Verification (only applicable when creating new files):
25 - Use the ls tool to verify the parent directory exists and is the correct location";
26 const REQUIRES_APPROVAL: bool = true;
27 const REQUIRED_CAPABILITIES: Capabilities = Capabilities::WORKSPACE;
28
29 async fn execute(
30 &self,
31 params: Self::Params,
32 ctx: &StaticToolContext,
33 ) -> Result<Self::Output, StaticToolError<ReplaceError>> {
34 let request = WriteFileRequest {
35 file_path: params.file_path,
36 content: params.content,
37 };
38 let op_ctx =
39 WorkspaceOpContext::new(ctx.tool_call_id.0.clone(), ctx.cancellation_token.clone());
40 let result = ctx
41 .services
42 .workspace
43 .write_file(request, &op_ctx)
44 .await
45 .map_err(|e| {
46 StaticToolError::execution(ReplaceError::Workspace(workspace_op_error(e)))
47 })?;
48 Ok(ReplaceResult(result))
49 }
50}