ExecuteShellCommandTool: Allow cwd to be relative to project root

This commit is contained in:
Dominik Jain authored and Dominik Jain committed 2025-09-10 14:23:24 +02:00
1 parent ba722bcad6
commit b4355df386
1 file changed
+14 -1
+14 -1
View File
@@ -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)