(
self,
*,
command: Command,
path: str,
file_text: Optional[str] = None,
view_range: Optional[List[int]] = None,
old_str: Optional[str] = None,
new_str: Optional[str] = None,
insert_line: Optional[int] = None,
**kwargs,
)
| 405 | class EditTool: |
| 406 | """ |
| 407 | An filesystem editor tool that allows the agent to view, create, and edit files. |
| 408 | The tool parameters are defined by Anthropic and are not editable. |
| 409 | """ |
| 410 | |
| 411 | name = "str_replace_editor" |
| 412 | |
| 413 | def __init__(self, REGISTRY, absolute_docs_path=None): |
| 414 | super().__init__() |
| 415 | self._encoding = None |
| 416 | self.REGISTRY = REGISTRY |
| 417 | self.logs = [] |
| 418 | self.absolute_docs_path = Path(absolute_docs_path) if absolute_docs_path else None |
| 419 | |
| 420 | def _get_display_path(self, path: Path) -> str: |
| 421 | """Get path for display purposes - relative to absolute_docs_path if available""" |
| 422 | if self.absolute_docs_path and path.is_absolute(): |
| 423 | try: |
| 424 | return str(path.relative_to(self.absolute_docs_path)) |
| 425 | except ValueError: |
| 426 | # Path is not under absolute_docs_path, return as-is |
| 427 | return str(path) |
| 428 | return str(path) |
| 429 | |
| 430 | @property |
| 431 | def _file_history(self): |
| 432 | return defaultdict(list, json.loads(self.REGISTRY.get("file_history", "{}"))) |
| 433 | |
| 434 | @_file_history.setter |
| 435 | def _file_history(self, value: dict): |
| 436 | self.REGISTRY["file_history"] = json.dumps(value) |
| 437 | |
| 438 | def __call__( |
| 439 | self, |
| 440 | *, |
| 441 | command: Command, |
| 442 | path: str, |
| 443 | file_text: str | None = None, |
| 444 | view_range: list[int] | None = None, |
| 445 | old_str: str | None = None, |
| 446 | new_str: str | None = None, |
| 447 | insert_line: int | None = None, |
| 448 | **kwargs, |
| 449 | ): |
| 450 | _path = Path(path) |
| 451 | if not self.validate_path(command, _path): |
nothing calls this directly
no test coverage detected