The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(terminal): route GUI launches to the running Bot Desktop screen
liuhao102489dd61a28168
diff --git a/tests/tools/test_local_env_bot_desktop.py b/tests/tools/test_local_env_bot_desktop.pynew file mode 100644index 00000000000..ff20b4e25e0--- /dev/null+++ b/tests/tools/test_local_env_bot_desktop.py@@ -0,0 +1,54 @@+"""Terminal child envs route GUI launches to the running Bot Desktop (#125830)."""++import pytest++from tools.environments.local import _make_run_env+++def _publish(monkeypatch, value):+ monkeypatch.setattr("tools.bot_desktop.runtime.published_env", lambda: value)+++def test_running_bot_desktop_display_rides_along(monkeypatch):+ _publish(+ monkeypatch,+ {+ "DISPLAY": ":20",+ "XAUTHORITY": "/run/hermes/bot-desktop/xauth",+ "DBUS_SESSION_BUS_ADDRESS": "unix:path=/run/hermes/bot-desktop/bus",+ },+ )+ monkeypatch.setenv("DISPLAY", ":0")+ monkeypatch.setenv("WAYLAND_DISPLAY", "wayland-0")+ env = _make_run_env({})+ assert env["DISPLAY"] == ":20"+ assert env["XAUTHORITY"] == "/run/hermes/bot-desktop/xauth"+ assert env["DBUS_SESSION_BUS_ADDRESS"] == "unix:path=/run/hermes/bot-desktop/bus"+ # X11 desktop: a leaked Wayland socket flips GTK/Chromium backends+ assert "WAYLAND_DISPLAY" not in env+++def test_running_bot_desktop_beats_the_session_snapshot(monkeypatch):+ _publish(monkeypatch, {"DISPLAY": ":20"})+ monkeypatch.setenv("DISPLAY", ":0")+ env = _make_run_env({"DISPLAY": ":0"}) # login snapshot captured the seat display+ assert env["DISPLAY"] == ":20"+++def test_stopped_bot_desktop_leaves_the_seat_env_alone(monkeypatch):+ _publish(monkeypatch, {})+ monkeypatch.setenv("DISPLAY", ":0")+ env = _make_run_env({})+ assert env["DISPLAY"] == ":0"+ assert "XAUTHORITY" not in env or env.get("XAUTHORITY") == ""+++def test_routing_does_not_stamp_bot_desktop_activity(monkeypatch):+ stamps = []+ _publish(monkeypatch, {"DISPLAY": ":20"})+ monkeypatch.setattr(+ "tools.bot_desktop.runtime.touch_activity", lambda: stamps.append(1)+ )+ _make_run_env({})+ # A plain terminal command is not screen use; idle_stop_minutes must stay effective.+ assert stamps == []diff --git a/tools/environments/local.py b/tools/environments/local.pyindex c5154113040..525f71dfa3a 100644--- a/tools/environments/local.py+++ b/tools/environments/local.py@@ -684,8 +684,27 @@ def _make_run_env(env: dict) -> dict:the LAUNCH profile's; under a routed home override its ``.env`` residue is dropped first(``strip_launch_profile_env``, a no-op for the launch profile) so the backend's own ``env``and the served profile's declared passthrough names are what the child sees."""- return _scrubbed_env([(dict(strip_launch_profile_env(os.environ.copy()) | env), True)], frozenset(),- lambda p: _prepend_git_bash_dirs(_append_missing_sane_path_entries(p)))+ run_env = _scrubbed_env(+ [(dict(strip_launch_profile_env(os.environ.copy()) | env), True)],+ frozenset(),+ lambda p: _prepend_git_bash_dirs(_append_missing_sane_path_entries(p)),+ )+ # While this profile's Bot Desktop is running, its DISPLAY/XAUTHORITY/DBUS ride along so GUI+ # apps the agent launches from the terminal open on the Bot Screen the user is watching, not+ # on the user's own seat (#125830). published_env() is the pure read (no activity stamp — a+ # plain ``ls`` must not keep the screen alive past idle_stop_minutes), and it wins over the+ # login snapshot's seat DISPLAY; a user who wants their own seat uses an inline+ # ``DISPLAY=:0 cmd`` prefix, which bash applies after this env. Empty (or module missing) →+ # the seat env passes through untouched.+ try:+ from tools.bot_desktop.runtime import published_env+ published = published_env()+ except Exception:+ published = {}+ if published:+ run_env.update(published)+ run_env.pop("WAYLAND_DISPLAY", None) # X11 desktop; a leaked Wayland socket flips GTK/Chromium backends+ return run_env# --- Hermes venv / repo-root detection (module-level, computed once) ---