MCPcopy Create free account
hub / github.com/FSoft-AI4Code/CodeWiki / __call__

Method __call__

codewiki/src/be/agent_tools/str_replace_editor.py:407–448  ·  view source on GitHub ↗
(
        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,
    )

Source from the content-addressed store, hash-verified

405 assert new_start <= start, (new_start, start)
406 assert start - new_start <= max_added_lines, (start, new_start)
407 assert new_stop >= stop, (new_stop, stop)
408 assert new_stop - stop <= max_added_lines, (new_stop, stop)
409 return new_start, new_stop
410
411
412class EditTool:
413 """
414 An filesystem editor tool that allows the agent to view, create, and edit files.
415 The tool parameters are defined by Anthropic and are not editable.
416 """
417
418 name = "str_replace_editor"
419
420 def __init__(self, REGISTRY, absolute_docs_path=None):
421 super().__init__()
422 self._encoding = None
423 self.REGISTRY = REGISTRY
424 self.logs = []
425 self.did_write = False
426 self.absolute_docs_path = Path(absolute_docs_path) if absolute_docs_path else None
427
428 def _get_display_path(self, path: Path) -> str:
429 """Get path for display purposes - relative to absolute_docs_path if available"""
430 if self.absolute_docs_path and path.is_absolute():
431 try:
432 return str(path.relative_to(self.absolute_docs_path))
433 except ValueError:
434 # Path is not under absolute_docs_path, return as-is
435 return str(path)
436 return str(path)
437
438 @property
439 def _file_history(self):
440 stored = self.REGISTRY.get("file_history", "{}")
441 stored = json.loads(stored) if isinstance(stored, str) else stored
442 return defaultdict(list, {Path(key): value for key, value in stored.items()})
443
444 @_file_history.setter
445 def _file_history(self, value: dict):
446 self.REGISTRY["file_history"] = json.dumps(
447 {str(key): items for key, items in value.items()}
448 )
449
450 def _remember(self, path: Path, content: str) -> None:
451 history = self._file_history

Callers

nothing calls this directly

Calls 6

validate_pathMethod · 0.95
viewMethod · 0.95
create_fileMethod · 0.95
str_replaceMethod · 0.95
insertMethod · 0.95
undo_editMethod · 0.95

Tested by

no test coverage detected