MCPcopy Index your code
hub / github.com/FSoft-AI4Code/CodeWiki / EditTool

Class EditTool

codewiki/src/be/agent_tools/str_replace_editor.py:374–733  ·  view source on GitHub ↗

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.

Source from the content-addressed store, hash-verified

372
373
374class EditTool:
375 """
376 An filesystem editor tool that allows the agent to view, create, and edit files.
377 The tool parameters are defined by Anthropic and are not editable.
378 """
379
380 name = "str_replace_editor"
381
382 def __init__(self, REGISTRY, absolute_docs_path=None):
383 super().__init__()
384 self._encoding = None
385 self.REGISTRY = REGISTRY
386 self.logs = []
387 self.absolute_docs_path = Path(absolute_docs_path) if absolute_docs_path else None
388
389 def _get_display_path(self, path: Path) -> str:
390 """Get path for display purposes - relative to absolute_docs_path if available"""
391 if self.absolute_docs_path and path.is_absolute():
392 try:
393 return str(path.relative_to(self.absolute_docs_path))
394 except ValueError:
395 # Path is not under absolute_docs_path, return as-is
396 return str(path)
397 return str(path)
398
399 @property
400 def _file_history(self):
401 return defaultdict(list, json.loads(self.REGISTRY.get("file_history", "{}")))
402
403 @_file_history.setter
404 def _file_history(self, value: dict):
405 self.REGISTRY["file_history"] = json.dumps(value)
406
407 def __call__(
408 self,
409 *,
410 command: Command,
411 path: str,
412 file_text: Optional[str] = None,
413 view_range: Optional[List[int]] = None,
414 old_str: Optional[str] = None,
415 new_str: Optional[str] = None,
416 insert_line: Optional[int] = None,
417 **kwargs,
418 ):
419 _path = Path(path)
420 if not self.validate_path(command, _path):
421 return
422 if command == "view":
423 return self.view(_path, view_range)
424 elif command == "create":
425 if file_text is None:
426 self.logs.append("Parameter `file_text` is required for command: create")
427 return
428 self.create_file(_path, file_text)
429 return None
430 elif command == "str_replace":
431 if old_str is None:

Callers 2

str_replace_editorMethod · 0.90
str_replace_editorFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected