diff --git a/src/serena/tools/cmd_tools.py b/src/serena/tools/cmd_tools.py index ccacd122..077a1978 100644 --- a/src/serena/tools/cmd_tools.py +++ b/src/serena/tools/cmd_tools.py @@ -2,6 +2,8 @@ Tools supporting the execution of (external) commands """ +import os.path + from serena.tools import Tool, ToolMarkerCanEdit from serena.util.shell import execute_shell_command @@ -30,7 +32,18 @@ class ExecuteShellCommandTool(Tool, ToolMarkerCanEdit): required for the task. :return: a JSON object containing the command's stdout and optionally stderr output """ - _cwd = cwd or self.get_project_root() + if cwd is None: + _cwd = self.get_project_root() + else: + if os.path.isabs(cwd): + _cwd = cwd + else: + _cwd = os.path.join(self.get_project_root(), cwd) + if not os.path.isdir(_cwd): + raise FileNotFoundError( + f"Specified a relative working directory ({cwd}), but the resulting path is not a directory: {_cwd}" + ) + result = execute_shell_command(command, cwd=_cwd, capture_stderr=capture_stderr) result = result.json() return self._limit_length(result, max_answer_chars)