fix(agent): expose HERMES_REAL_HOME in subprocess envs for profile isolation

When profile isolation activates ({HERMES_HOME}/home/ exists), child
processes receive HOME={HERMES_HOME}/home/ for tool config isolation
(git, ssh, gh). However, scripts using Path.home() to locate
~/.hermes/ would incorrectly resolve to the isolated profile home,
breaking helpers that rely on the real user home directory.

New get_real_home() helper in hermes_constants resolves the actual
user home independently of profile isolation. All four subprocess
spawners now inject HERMES_REAL_HOME alongside the profile HOME:

- tools/code_execution_tool.py (execute_code)
- tools/environments/local.py (terminal background, run_env)
- agent/copilot_acp_client.py (Copilot ACP)

Child scripts can now use:
  Path(os.environ.get("HERMES_REAL_HOME", os.environ.get("HOME", "")))

to reliably find the real user home regardless of profile isolation.

Closes #25114
This commit is contained in:
zccyman 2026-05-14 01:39:49 +08:00 committed by Teknium
parent 0428945b5b
commit b00060ce54
5 changed files with 191 additions and 1 deletions

View file

@ -1276,6 +1276,8 @@ def execute_code(
_profile_home = get_subprocess_home()
if _profile_home:
child_env["HOME"] = _profile_home
from hermes_constants import get_real_home
child_env["HERMES_REAL_HOME"] = get_real_home()
# Resolve interpreter + CWD based on execute_code mode.
# - strict : today's behavior (sys.executable + tmpdir CWD).