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: