fix(cli): the banner shows main's 8-character session label for a canonical id

The gateway names a classic CLI session by its durable id (`local-` + 64 hex), so main's
banner `Session:` line wrapped across rows where main showed a short id. session_label()
shortens only that exact shape, for the banner only (the TUI's sessionLabel rule); /resume
hints, the exit summary and every RPC keep the full id.

Test: tests/hermes_cli/test_gateway_session_store.py::test_banner_session_label_is_mains_eight_characters_for_a_canonical_id.
Harness steps 01/02/10b/11a.

(cherry picked from commit 2c113865442cbc8ac442de4d573661d5187e8e70)
This commit is contained in:
Teknium
2026-10-12 19:25:18 -07:00
parent c94f9f61ec
commit 7e93de19bd
3 changed files with 22 additions and 1 deletions

View File

@@ -130,6 +130,7 @@ class CLIInfoMixin:
gateway_inventory = getattr(getattr(self, "_session_db", None), "banner_inventory", lambda: None)()
if gateway_inventory is not None:
from hermes_cli.gateway_session_store import session_label
# The gateway session's snapshot (the TUI banner's data): the CLI enumerates nothing.
self._defer_tool_warnings = True
build_welcome_banner(
@@ -137,7 +138,8 @@ class CLIInfoMixin:
availability=gateway_inventory["availability"],
skills_by_category=gateway_inventory["skills_by_category"],
**{**banner_kw, "cwd": gateway_inventory["cwd"] or cwd,
"context_length": gateway_inventory["context_length"] or ctx_len})
"context_length": gateway_inventory["context_length"] or ctx_len,
"session_id": session_label(self.session_id)})
elif snapshot is not None:
self._defer_tool_warnings = True
toolset_map = snapshot["toolset_map"]

View File

@@ -18,6 +18,7 @@ from __future__ import annotations
import argparse
import logging
import os
import re
import uuid
from hermes_cli.gateway_client import GatewayClientError
@@ -215,6 +216,16 @@ class GatewaySessionStore:
}
_CANONICAL_LOCAL_ID = re.compile(r"^local-([0-9a-f]{8})[0-9a-f]{56}$")
def session_label(session_id):
"""Main's 8-character banner label for a canonical durable id (``local-`` + 64 hex); every other
id is shown as is. Display only: RPCs, /resume hints and the exit summary keep the full id."""
match = _CANONICAL_LOCAL_ID.match(session_id or "")
return match.group(1) if match else session_id
def _creation_policy(launch):
"""The explicit launch flags as ``session.create`` policy (the thin client's own mapping);
unset flags leave the gateway to resolve the profile default, as main's CLI did."""

View File

@@ -126,3 +126,11 @@ def test_reader_opens_once_the_gateway_created_state_db(store, tmp_path, monkeyp
from hermes_state import SessionDB
SessionDB(db_path=tmp_path / "state.db").close()
assert db.get_session("x") is None and db._reader is not None
def test_banner_session_label_is_mains_eight_characters_for_a_canonical_id():
from hermes_cli.gateway_session_store import session_label
assert session_label("local-ab12cd34" + "0" * 56) == "ab12cd34"
assert session_label("20261012_134501_abcdef") == "20261012_134501_abcdef"
assert session_label("local-abc") == "local-abc"
assert session_label(None) is None