Skip to content

The agent that grows with you

fix(left-core): a TTY is no terminal front end; a foreground gateway keeps outcomes for the chat user

Teknium375ca30d0b6c
diff --git a/hermes_cli/left_core_migration.py b/hermes_cli/left_core_migration.py
index 996d97b836d..a2df0f30613 100644
--- a/hermes_cli/left_core_migration.py
+++ b/hermes_cli/left_core_migration.py
@@ -591,16 +591,18 @@ def recover_for_provider(name: Optional[str]) -> None:
"""Runtime resolution of *name*, a provider a left-core plugin supplies, in a home that uses it and lacks
the plugin: run :func:`recover_at_startup` now. The CLI and Desktop resolve the provider before the agent
(whose start runs the migration) exists, so they would otherwise stop at "unknown provider" on a home no
- ``hermes update`` migrated. Outcomes print to an interactive terminal, else wait for the home's first agent."""
+ ``hermes update`` migrated. Outcomes print in a declared terminal front end (:func:`serve_notices_on_stderr`),
+ else wait for the home's first agent."""
feature = _provider_feature(name or "")
if feature is None:
return
from hermes_constants import get_hermes_home, hermes_home_key
from providers import get_provider_profile
home = Path(get_hermes_home())
- # A terminal user sees outcomes now, also those another process (the gateway this CLI started) kept;
- # otherwise (Desktop, gateway, a detached turn) the home's first agent in any process delivers them.
- say = (lambda message: print(message, file=sys.stderr)) if _interactive() or _terminal_front_end else None
+ # A terminal front end shows outcomes now, also those another process (the gateway this CLI started) kept;
+ # otherwise (Desktop, gateway, a detached turn) the home's first agent in any process delivers them. Never
+ # inferred from a TTY: a foreground `hermes gateway run` has one, and its resolutions serve the chat user.
+ say = (lambda message: print(message, file=sys.stderr)) if _terminal_front_end else None
if say is not None:
for message in _claim_notices(home):
say(message)
@@ -617,8 +619,9 @@ _terminal_front_end = False
def serve_notices_on_stderr() -> None:
"""This process is a terminal front end (the classic CLI, whose turns run in the gateway): outcomes of
- :func:`recover_for_provider` print to its stderr even when its output is piped (``hermes chat -q``),
- since a resolution that fails before any agent exists (no credentials) leaves no agent to deliver them."""
+ :func:`recover_for_provider` print to its stderr, also when its output is piped (``hermes chat -q``),
+ since a resolution that fails before any agent exists (no credentials) leaves no agent to deliver them.
+ Only a declaration counts: a foreground gateway has a TTY too, and its outcomes belong to the chat user."""
global _terminal_front_end
_terminal_front_end = True
diff --git a/tests/hermes_cli/test_left_core_provider_runtime.py b/tests/hermes_cli/test_left_core_provider_runtime.py
index 4b89ee1fcdc..f47dfbcf9a4 100644
--- a/tests/hermes_cli/test_left_core_provider_runtime.py
+++ b/tests/hermes_cli/test_left_core_provider_runtime.py
@@ -161,13 +161,17 @@ def test_a_resolution_outcome_reaches_the_first_agent_of_any_process_once(tmp_pa
assert "moved out of core" not in second
-def test_an_interactive_terminal_sees_the_resolution_outcome_now_and_only_there(tmp_path, monkeypatch, installs_ok,
- capsys):
+def test_a_tty_without_a_declared_front_end_keeps_the_outcome_for_the_chat_agent(tmp_path, monkeypatch, installs_ok,
+ capsys):
+ """A foreground `hermes gateway run` has a TTY, but its resolutions serve the chat user: the outcome (and
+ its "run `hermes auth add copilot`" instruction) stays kept for the chat agent, not the gateway terminal."""
_copilot_home(tmp_path, monkeypatch)
monkeypatch.setattr(lcm, "_interactive", lambda: True)
lcm.recover_for_provider("copilot")
- assert capsys.readouterr().err.count("GitHub Copilot moved out of core") == 1
- assert "moved out of core" not in _agent_start_in_another_process()
+ assert installs_ok == ["github-copilot"]
+ assert capsys.readouterr().err == ""
+ chat = _agent_start_in_another_process()
+ assert chat.count("GitHub Copilot moved out of core") == 1 and "hermes auth add copilot" in chat
def test_a_piped_cli_front_end_prints_the_outcome_and_what_another_process_kept(tmp_path, monkeypatch,