MCPcopy Create free account
hub / github.com/bytedance/trae-agent / execute

Method execute

trae_agent/tools/edit_tool.py:101–132  ·  view source on GitHub ↗

Execute the str_replace_editor tool.

(self, arguments: ToolCallArguments)

Source from the content-addressed store, hash-verified

99
100 @override
101 async def execute(self, arguments: ToolCallArguments) -> ToolExecResult:
102 """Execute the str_replace_editor tool."""
103 command = str(arguments["command"]) if "command" in arguments else None
104 if command is None:
105 return ToolExecResult(
106 error=f"No command provided for the {self.get_name()} tool",
107 error_code=-1,
108 )
109 path = str(arguments["path"]) if "path" in arguments else None
110 if path is None:
111 return ToolExecResult(
112 error=f"No path provided for the {self.get_name()} tool", error_code=-1
113 )
114 _path = Path(path)
115 try:
116 self.validate_path(command, _path)
117 match command:
118 case "view":
119 return await self._view_handler(arguments, _path)
120 case "create":
121 return self._create_handler(arguments, _path)
122 case "str_replace":
123 return self._str_replace_handler(arguments, _path)
124 case "insert":
125 return self._insert_handler(arguments, _path)
126 case _:
127 return ToolExecResult(
128 error=f"Unrecognized command {command}. The allowed commands for the {self.name} tool are: {', '.join(EditToolSubCommands)}",
129 error_code=-1,
130 )
131 except ToolError as e:
132 return ToolExecResult(error=str(e), error_code=-1)
133
134 def validate_path(self, command: str, path: Path):
135 """Validate the path for the str_replace_editor tool."""

Callers

nothing calls this directly

Calls 7

get_nameMethod · 0.95
validate_pathMethod · 0.95
_view_handlerMethod · 0.95
_create_handlerMethod · 0.95
_str_replace_handlerMethod · 0.95
_insert_handlerMethod · 0.95
ToolExecResultClass · 0.90

Tested by

no test coverage detected