fix: path_append must not clobber login shell PATH

Seeding PATH in the env before bash -l caused /etc/profile
to skip its default PATH setup, breaking standard commands.
Move path_append to an inline export so the login shell
establishes a proper base PATH first.

Add regression test: ls still works when path_append is set.

Made-with: Cursor
This commit is contained in:
Xubin Ren
2026-04-06 13:20:53 +08:00
committed by Xubin Ren
parent be6063a142
commit 28e0a76b80
2 changed files with 12 additions and 5 deletions
+4 -5
View File
@@ -96,6 +96,9 @@ class ExecTool(Tool):
env = self._build_env()
if self.path_append:
command = f'export PATH="$PATH:{self.path_append}"; {command}'
bash = shutil.which("bash") or "/bin/bash"
try:
@@ -164,15 +167,11 @@ class ExecTool(Tool):
secrets in env vars from leaking to LLM-generated commands.
"""
home = os.environ.get("HOME", "/tmp")
env: dict[str, str] = {
return {
"HOME": home,
"LANG": os.environ.get("LANG", "C.UTF-8"),
"TERM": os.environ.get("TERM", "dumb"),
}
if self.path_append:
# Seed PATH so the login shell can append to it.
env["PATH"] = self.path_append
return env
def _guard_command(self, command: str, cwd: str) -> str | None:
"""Best-effort safety guard for potentially destructive commands."""