(
&self,
args: serde_json::Value,
ctx: ToolContext,
)
| 62 | } |
| 63 | |
| 64 | async fn execute( |
| 65 | &self, |
| 66 | args: serde_json::Value, |
| 67 | ctx: ToolContext, |
| 68 | ) -> Result<ToolResult, ToolError> { |
| 69 | let file_path: String = args["file_path"] |
| 70 | .as_str() |
| 71 | .ok_or_else(|| ToolError::InvalidArguments("file_path is required".into()))? |
| 72 | .to_string(); |
| 73 | |
| 74 | let old_string: String = args["old_string"] |
| 75 | .as_str() |
| 76 | .ok_or_else(|| ToolError::InvalidArguments("old_string is required".into()))? |
| 77 | .to_string(); |
| 78 | |
| 79 | let new_string: String = args["new_string"] |
| 80 | .as_str() |
| 81 | .ok_or_else(|| ToolError::InvalidArguments("new_string is required".into()))? |
| 82 | .to_string(); |
| 83 | |
| 84 | let replace_all = args["replace_all"].as_bool().unwrap_or(false); |
| 85 | |
| 86 | let base_dir = if ctx.directory.is_empty() { |
| 87 | &self.directory |
| 88 | } else { |
| 89 | Path::new(&ctx.directory) |
| 90 | }; |
| 91 | |
| 92 | let path = if Path::new(&file_path).is_absolute() { |
| 93 | PathBuf::from(&file_path) |
| 94 | } else { |
| 95 | base_dir.join(&file_path) |
| 96 | }; |
| 97 | |
| 98 | let path_str = path.to_string_lossy().to_string(); |
| 99 | |
| 100 | if ctx.is_external_path(&path_str) { |
| 101 | let parent = path |
| 102 | .parent() |
| 103 | .map(|p| p.to_string_lossy().to_string()) |
| 104 | .unwrap_or_else(|| path_str.clone()); |
| 105 | |
| 106 | ctx.ask_permission( |
| 107 | crate::PermissionRequest::new("external_directory") |
| 108 | .with_pattern(format!("{}/*", parent)) |
| 109 | .with_metadata("filepath", serde_json::json!(&path_str)) |
| 110 | .with_metadata("parentDir", serde_json::json!(parent)), |
| 111 | ) |
| 112 | .await?; |
| 113 | } |
| 114 | |
| 115 | let title = path |
| 116 | .strip_prefix(&ctx.worktree) |
| 117 | .unwrap_or(&path) |
| 118 | .to_string_lossy() |
| 119 | .to_string(); |
| 120 | |
| 121 | let ctx_clone = ctx.clone(); |
nothing calls this directly
no test coverage detected