Skip to content

The agent that grows with you

fix(cli): `hermes -z` writes nothing to stderr on success, as on main

Tekniumb38552098faa
diff --git a/hermes_cli/gateway_chat.py b/hermes_cli/gateway_chat.py
index 8f2f6238dcd..0333d868020 100644
--- a/hermes_cli/gateway_chat.py
+++ b/hermes_cli/gateway_chat.py
@@ -201,7 +201,8 @@ async def run_gateway_chat(args, emitter=None):
if missing:
raise GatewayClientError("Gateway does not support creation options: " + ", ".join(missing))
snapshot = await client.rpc("session.create", request_id=uuid.uuid4().hex, source=source, **policy)
- print("Session: " + snapshot["stored_session_id"], file=sys.stderr, flush=True)
+ if not isinstance(oneshot_prompt, str): # main's -z writes nothing to stderr on success
+ print("Session: " + snapshot["stored_session_id"], file=sys.stderr, flush=True)
if not oneshot:
from hermes_cli.terminal_breadcrumbs import write_breadcrumb
await asyncio.to_thread(write_breadcrumb, snapshot["stored_session_id"])
diff --git a/hermes_cli/gateway_chat_view.py b/hermes_cli/gateway_chat_view.py
index d0a22d7edb0..1f216a9b7d9 100644
--- a/hermes_cli/gateway_chat_view.py
+++ b/hermes_cli/gateway_chat_view.py
@@ -375,8 +375,10 @@ class GatewayChatView:
def _print_exit_ids(self):
"""The finite run's durable id on stderr (automation wrappers parse it; it names the
- physical row a compaction may have advanced) and, for `chat -q`, main's resume block."""
- print(f"\nsession_id: {self.session_id}", file=sys.stderr, flush=True)
+ physical row a compaction may have advanced) and, for `chat -q`, main's resume block. Main's
+ `-z` (unattended) printed only the reply: no id line."""
+ if not self.unattended:
+ print(f"\nsession_id: {self.session_id}", file=sys.stderr, flush=True)
if self.resume_footer:
print(resume_footer(self.session_id), flush=True)
diff --git a/tests/hermes_cli/test_gateway_chat.py b/tests/hermes_cli/test_gateway_chat.py
index 3f52e8940a3..2815671315f 100644
--- a/tests/hermes_cli/test_gateway_chat.py
+++ b/tests/hermes_cli/test_gateway_chat.py
@@ -312,3 +312,35 @@ async def test_new_and_branch_move_the_terminal_continue_pointer(monkeypatch, tm
else:
assert await view.command(command) is True
assert terminal_breadcrumbs.read_breadcrumb()["session_id"] == "moved"
+
+
+async def test_oneshot_z_writes_no_session_lines_to_stderr_like_main(monkeypatch, tmp_path, capsys):
+ """Main's ``hermes -z`` printed the reply on stdout and nothing on stderr; ``-q -Q`` keeps the
+ ``Session:`` / ``session_id:`` lines automation wrappers read."""
+ from contextlib import asynccontextmanager
+ from hermes_cli import gateway_chat
+ from hermes_cli.gateway_chat_view import GatewayChatView
+
+ class Peer:
+ async def rpc(self, method, **params):
+ if method == "runtime.describe":
+ return {"session_create": {"sources": ["cli", "oneshot"], "parameters": ["cwd", "request_id", "source"]}}
+ return {"stored_session_id": "stored-z"}
+
+ @asynccontextmanager
+ async def connected():
+ yield Peer()
+
+ async def rendered(self, query, *, oneshot):
+ self._print_exit_ids()
+ return 0
+
+ monkeypatch.setattr(gateway_chat, "connect_gateway", connected)
+ monkeypatch.setattr(GatewayChatView, "run", rendered)
+ monkeypatch.chdir(tmp_path)
+ assert await gateway_chat.run_gateway_chat(argparse.Namespace(oneshot="z")) == 0
+ assert "stored-z" not in capsys.readouterr().err
+ assert await gateway_chat.run_gateway_chat(argparse.Namespace(query="q", quiet=True)) == 0
+ err = capsys.readouterr().err
+ assert "Session: stored-z" in err and "session_id: stored-z" in err