An filesystem editor tool that allows the agent to view, create, and edit files. The tool parameters are defined by Anthropic and are not editable.
| 372 | def expand_window( |
| 373 | self, lines: list[str], start: int, stop: int, max_added_lines: int |
| 374 | ) -> tuple[int, int]: |
| 375 | """ |
| 376 | |
| 377 | Args: |
| 378 | lines: All lines of the file |
| 379 | start: 1-based line number of the start of the viewport |
| 380 | stop: 1-based line number of the end of the viewport |
| 381 | max_added_lines: Maximum number of lines to extend (separately for each side) |
| 382 | |
| 383 | Returns: |
| 384 | Tuple of 1-based line numbers of the start and end of the viewport. |
| 385 | Both inclusive. |
| 386 | """ |
| 387 | # print("Input:", start, stop) |
| 388 | assert 1 <= start <= stop <= len(lines), (start, stop, len(lines)) |
| 389 | if max_added_lines <= 0: |
| 390 | # Already at max range, no expansion |
| 391 | return start, stop |
| 392 | new_start = self._find_breakpoints( |
| 393 | lines, start, direction=-1, max_added_lines=max_added_lines |
| 394 | ) |
| 395 | new_stop = self._find_breakpoints(lines, stop, direction=1, max_added_lines=max_added_lines) |
| 396 | # print(f"Expanded window is {new_start} to {new_stop}") |
| 397 | assert new_start <= new_stop, (new_start, new_stop) |
| 398 | assert new_start <= start, (new_start, start) |
| 399 | assert start - new_start <= max_added_lines, (start, new_start) |
| 400 | assert new_stop >= stop, (new_stop, stop) |
| 401 | assert new_stop - stop <= max_added_lines, (new_stop, stop) |
| 402 | return new_start, new_stop |
| 403 | |
| 404 | |
| 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): |
no outgoing calls
no test coverage detected