Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(agent): allow heredoc commands in the bash tool on posix hosts

Lanre Shittuc4e1e42f475b
diff --git a/agent/src/tools/bash_tool.py b/agent/src/tools/bash_tool.py
index a46686683..6a93a4aae 100644
--- a/agent/src/tools/bash_tool.py
+++ b/agent/src/tools/bash_tool.py
@@ -99,8 +99,9 @@ class BashTool(BaseTool):
# cmd.exe has no heredocs; return a clear message instead of the
# cryptic "<< was unexpected at this time." stderr. Only multi-line
# commands with a heredoc delimiter are flagged, so a single-line
- # bit shift (python -c "print(1 << 2)") is unaffected.
- if "\n" in command and re.search(
+ # bit shift (python -c "print(1 << 2)") is unaffected. POSIX shells
+ # support heredocs natively, so this only applies on Windows.
+ if os.name == "nt" and "\n" in command and re.search(
r"<<\s*['\"]?[A-Za-z_][A-Za-z0-9_]*", command
):
return json.dumps(
diff --git a/agent/tests/test_bash_tool.py b/agent/tests/test_bash_tool.py
index c1c7623ce..5273e1e10 100644
--- a/agent/tests/test_bash_tool.py
+++ b/agent/tests/test_bash_tool.py
@@ -131,7 +131,8 @@ def test_timeout_kills_process_tree(monkeypatch: pytest.MonkeyPatch) -> None:
assert len(kills) == 1
-def test_heredoc_unsupported(monkeypatch: pytest.MonkeyPatch) -> None:
+def test_heredoc_unsupported_on_windows(monkeypatch: pytest.MonkeyPatch) -> None:
+ monkeypatch.setattr(bash_tool.os, "name", "nt")
popen = MagicMock(side_effect=AssertionError("heredoc reached subprocess"))
monkeypatch.setattr(bash_tool.subprocess, "Popen", popen)
@@ -140,3 +141,16 @@ def test_heredoc_unsupported(monkeypatch: pytest.MonkeyPatch) -> None:
assert result["status"] == "error"
assert result["error_code"] == "heredoc_unsupported"
popen.assert_not_called()
+
+
+def test_heredoc_allowed_on_posix(monkeypatch: pytest.MonkeyPatch) -> None:
+ """POSIX shells support heredocs natively; the command must reach the
+ real shell instead of being rejected with a Windows-only error.
+ """
+ monkeypatch.setattr(bash_tool.os, "name", "posix")
+ fake = _FakePopen()
+ _install_fake_popen(monkeypatch, fake)
+
+ result = json.loads(BashTool().execute(command="cat <<EOF\nhello\nEOF"))
+
+ assert result["status"] == "ok"