Execute write file.
(self, path: str, content: str)
| 193 | } |
| 194 | |
| 195 | async def execute(self, path: str, content: str) -> ToolResult: |
| 196 | """Execute write file.""" |
| 197 | try: |
| 198 | file_path = Path(path) |
| 199 | # Resolve relative paths relative to workspace_dir |
| 200 | if not file_path.is_absolute(): |
| 201 | file_path = self.workspace_dir / file_path |
| 202 | |
| 203 | # Create parent directories if they don't exist |
| 204 | file_path.parent.mkdir(parents=True, exist_ok=True) |
| 205 | |
| 206 | file_path.write_text(content, encoding="utf-8") |
| 207 | return ToolResult(success=True, content=f"Successfully wrote to {file_path}") |
| 208 | except Exception as e: |
| 209 | return ToolResult(success=False, content="", error=str(e)) |
| 210 | |
| 211 | |
| 212 | class EditTool(Tool): |