From d51f9c846430fccc5a54393458747f402aaf2ccb Mon Sep 17 00:00:00 2001 From: teknium1 <127238744+teknium1@users.noreply.github.com> Date: Sat, 19 Sep 2026 01:41:11 -0700 Subject: [PATCH] refactor: real-home and terminal temp-dir fallbacks stop naming /tmp get_real_home() fell back to a literal /tmp when no OS home could be found, and LocalEnvironment.get_temp_dir() probed /tmp by hand before consulting tempfile.gettempdir(), whose own candidate walk already covers the system temp dir (and honours the scratch TMPDIR Hermes now exports). Both defer to tempfile.gettempdir(); a relative gettempdir() result is made absolute instead of being swapped for /tmp. --- hermes_constants.py | 3 ++- tools/environments/local.py | 9 ++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/hermes_constants.py b/hermes_constants.py index 0fc075adb6..37aac23580 100644 --- a/hermes_constants.py +++ b/hermes_constants.py @@ -921,7 +921,8 @@ def get_real_home(env: dict[str, str] | None = None) -> str: seen.add(key) if not _is_profile_home(candidate, profile_home): return candidate - return "/tmp" + import tempfile + return tempfile.gettempdir() _HOME_MODE_ALIASES = {"isolated": "profile", "profile_home": "profile", "profile-home": "profile", diff --git a/tools/environments/local.py b/tools/environments/local.py index a83e256d8d..f75bcabc75 100644 --- a/tools/environments/local.py +++ b/tools/environments/local.py @@ -826,8 +826,8 @@ class LocalEnvironment(BaseEnvironment): def get_temp_dir(self) -> str: """Shell-safe writable temp dir. Precedence: ``TERMINAL_TEMP_DIR``, TMPDIR/TMP/TEMP - (Termux has no /tmp), ``HERMES_HOME/cache/terminal`` (real storage: tmpfs /tmp - fills under Hermes load; pruned by ``cleanup_terminal_temp_cache``), /tmp, + (Termux has no system temp dir), ``HERMES_HOME/cache/terminal`` (real storage: a + tmpfs system temp dir fills under Hermes load; pruned by ``cleanup_terminal_temp_cache``), ``tempfile.gettempdir()``; backend env before process env so terminal.env overrides work. Windows: ``%TEMP%`` often has spaces that break unquoted bash, so always the HERMES_HOME cache dir with forward slashes (bash- and Python-valid).""" @@ -853,10 +853,9 @@ class LocalEnvironment(BaseEnvironment): return _posix(resolved) except Exception: pass - if os.path.isdir("/tmp") and os.access("/tmp", os.W_OK | os.X_OK): - return "/tmp" + # tempfile's own candidate walk already covers the system temp dir. fallback = tempfile.gettempdir() - return _posix(fallback) if fallback.startswith("/") else "/tmp" + return _posix(fallback if fallback.startswith("/") else os.path.abspath(fallback)) @staticmethod def _quote_cwd_for_cd(cwd: str) -> str: