The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cli): show a safe preview of each pending admission's text on resume
Teknium1d3cf529b593
diff --git a/hermes_cli/gateway_chat_view.py b/hermes_cli/gateway_chat_view.pyindex c0bd7f690a7..d8a2b2daac1 100644--- a/hermes_cli/gateway_chat_view.py+++ b/hermes_cli/gateway_chat_view.py@@ -10,6 +10,22 @@ from hermes_cli.gateway_client import GatewayClientErrorlogger = logging.getLogger(__name__)+_PREVIEW_CHARS = 80+++def _pending_preview(text):+ """One terminal-safe line of a pending admission's prompt: escape sequences removed, every+ other non-printable (C0/C1, bidi and zero-width format chars, newlines) folded to a space,+ capped at ``_PREVIEW_CHARS``. Empty when the row carries no text."""+ from tools.ansi_strip import strip_ansi+ if not isinstance(text, str):+ return ""+ line = " ".join("".join(ch if ch.isprintable() else " " for ch in strip_ansi(text)).split())+ if len(line) > _PREVIEW_CHARS:+ line = line[:_PREVIEW_CHARS - 1] + "…"+ return f": {line}" if line else ""++_BLOCKING_CONTROL_EVENTS = frozenset({"approval.request", "approval.settled", "clarify.request", "clarify.settled","session.info",@@ -59,11 +75,13 @@ class GatewayChatView:"without replaying it; queued work may then continue.", file=sys.stderr)for row in self.pending:admission = row["admission_id"]+ # A queued prompt is not in the transcript yet: show what is about to run (or was lost).+ preview = _pending_preview(row.get("text"))if row["status"] == "unknown":- print(f"Unknown admission: {admission}\n/discard {admission}", file=sys.stderr)+ print(f"Unknown admission: {admission}{preview}\n/discard {admission}", file=sys.stderr)elif row["status"] == "queued":context = "waiting behind unknown work" if unknown else "waiting to run"- print(f"Queued admission: {admission} ({context})", file=sys.stderr)+ print(f"Queued admission: {admission} ({context}){preview}", file=sys.stderr)def show_prompt(self, prompt):print(f"\n{prompt.get('description') or prompt.get('question') or 'Approval required'}", file=sys.stderr)diff --git a/tests/hermes_cli/test_gateway_chat_pending_preview.py b/tests/hermes_cli/test_gateway_chat_pending_preview.pynew file mode 100644index 00000000000..307d6e8c1a9--- /dev/null+++ b/tests/hermes_cli/test_gateway_chat_pending_preview.py@@ -0,0 +1,34 @@+"""A resumed classic CLI shows what each pending admission will run, safely, from the real snapshot."""+from dataclasses import asdict+++def test_resume_lists_pending_admission_text_capped_and_terminal_safe(capsys):+ from gateway.session_authority import SessionAuthority+ from hermes_cli.gateway_chat_view import GatewayChatView++ authority = object.__new__(SessionAuthority)+ authority.profile_id, authority.epoch = "profile", 3+ row = {"target_session_id": "stored", "outcome": None, "owner_epoch": 3}+ hostile = "\x1b]0;pwned\x07\x1b[2Jdeploy\rhidden\x08\u202e\x9b31m now " + "x" * 200+ rows = [+ {**row, "admission_id": "adm-unknown", "seq": 1, "status": "unknown", "generation": 4,+ "request_id": "in-1", "payload": {"native_text_v1": {"event": {"text": "summarise the logs"}}}},+ {**row, "admission_id": "adm-queued", "seq": 2, "status": "queued", "generation": None,+ "request_id": "in-2", "payload": {"text": hostile}},+ ]+ # The authority's own snapshot projection, exactly what session.resume ships to the CLI.+ snapshot = {"stored_session_id": "stored",+ "pending": [asdict(authority._pending_receipt(r)) for r in rows]}++ GatewayChatView(None, snapshot).show_pending()++ err = capsys.readouterr().err+ lines = err.splitlines()+ unknown = next(line for line in lines if "adm-unknown" in line and "Unknown" in line)+ queued = next(line for line in lines if "adm-queued" in line)+ assert "/discard adm-unknown" in lines+ assert "summarise the logs" in unknown+ assert "deploy hidden" in queued and "now xxx" in queued+ preview = queued.split(": ", 2)[-1]+ assert len(preview) <= 80 and preview.endswith("…")+ assert not [ch for ch in err if ch != "\n" and not ch.isprintable()], repr(err)