Execute the str_replace_editor tool.
(self, arguments: ToolCallArguments)
| 99 | |
| 100 | @override |
| 101 | async def execute(self, arguments: ToolCallArguments) -> ToolExecResult: |
| 102 | """Execute the str_replace_editor tool.""" |
| 103 | command = str(arguments["command"]) if "command" in arguments else None |
| 104 | if command is None: |
| 105 | return ToolExecResult( |
| 106 | error=f"No command provided for the {self.get_name()} tool", |
| 107 | error_code=-1, |
| 108 | ) |
| 109 | path = str(arguments["path"]) if "path" in arguments else None |
| 110 | if path is None: |
| 111 | return ToolExecResult( |
| 112 | error=f"No path provided for the {self.get_name()} tool", error_code=-1 |
| 113 | ) |
| 114 | _path = Path(path) |
| 115 | try: |
| 116 | self.validate_path(command, _path) |
| 117 | match command: |
| 118 | case "view": |
| 119 | return await self._view_handler(arguments, _path) |
| 120 | case "create": |
| 121 | return self._create_handler(arguments, _path) |
| 122 | case "str_replace": |
| 123 | return self._str_replace_handler(arguments, _path) |
| 124 | case "insert": |
| 125 | return self._insert_handler(arguments, _path) |
| 126 | case _: |
| 127 | return ToolExecResult( |
| 128 | error=f"Unrecognized command {command}. The allowed commands for the {self.name} tool are: {', '.join(EditToolSubCommands)}", |
| 129 | error_code=-1, |
| 130 | ) |
| 131 | except ToolError as e: |
| 132 | return ToolExecResult(error=str(e), error_code=-1) |
| 133 | |
| 134 | def validate_path(self, command: str, path: Path): |
| 135 | """Validate the path for the str_replace_editor tool.""" |
nothing calls this directly
no test coverage detected