The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cli): /resume picker, /sessions and /history list the sessions the CLI created
Tekniume623faaef289
diff --git a/hermes_cli/gateway_session_store.py b/hermes_cli/gateway_session_store.pyindex 955334bbc43..bd00a3317ff 100644--- a/hermes_cli/gateway_session_store.py+++ b/hermes_cli/gateway_session_store.py@@ -77,7 +77,7 @@ class GatewaySessionStore:return Nonetry:from hermes_state import SessionDB- self._reader = SessionDB(db_path=path, read_only=True)+ self._reader = SurfaceLabelReader(SessionDB(db_path=path, read_only=True))except Exception as exc: # health: allow BLE001 -- reads find nothing; retried on the next readlogger.debug("read-only state.db unavailable: %s", exc)return self._reader@@ -299,6 +299,44 @@ class GatewaySessionStore:}+# Interactive surfaces whose gateway rows are labelled ``local`` (``created_source`` keeps the surface;+# gateway/session_a2a.storage_source). Producer labels (oneshot, tool, kanban, ...) are stored as is.+_LOCAL_LABELLED = frozenset({"cli", "tui", "gui"})+++class SurfaceLabelReader:+ """A read-only ``SessionDB`` whose source-filtered listings read main's labels: ``source='cli'``+ also matches a gateway row labelled ``local`` that the CLI created (``created_source='cli'``), so+ main's /resume picker, /sessions, /history and bare ``-c`` find the sessions the CLI made."""++ def __init__(self, db):+ self._wrapped = db++ def __getattr__(self, name):+ return getattr(self._wrapped, name)++ def _labelled(self, method, requested, limit, offset, call):+ wanted = {requested} if isinstance(requested, str) else set(requested or ())+ surfaces = wanted & _LOCAL_LABELLED+ if not surfaces:+ return call(requested, limit, offset)+ # Over-fetch, then keep only the local rows those surfaces created (ordering is the reader's own).+ rows = call(sorted(wanted | {"local"}), (limit + offset) * 3 + 50, 0)+ kept = [row for row in rows if row.get("source") != "local" or row.get("created_source") in surfaces]+ return kept[offset:offset + limit]++ def search_sessions(self, source=None, limit=20, offset=0, **kw):+ return self._labelled("search_sessions", source, limit, offset,+ lambda src, lim, off: self._wrapped.search_sessions(source=src, limit=lim, offset=off, **kw))++ def list_sessions_rich(self, source=None, sources=None, limit=20, offset=0, **kw):+ requested = sources if sources else ([source] if source else None)+ if not requested:+ return self._wrapped.list_sessions_rich(limit=limit, offset=offset, **kw)+ return self._labelled("list_sessions_rich", requested, limit, offset,+ lambda src, lim, off: self._wrapped.list_sessions_rich(sources=src, limit=lim, offset=off, **kw))++_CANONICAL_LOCAL_ID = re.compile(r"^local-([0-9a-f]{8})[0-9a-f]{56}$")diff --git a/tests/hermes_cli/test_gateway_session_store.py b/tests/hermes_cli/test_gateway_session_store.pyindex cf637b0cca7..5b4f0610fff 100644--- a/tests/hermes_cli/test_gateway_session_store.py+++ b/tests/hermes_cli/test_gateway_session_store.py@@ -299,3 +299,30 @@ def test_new_session_id_off_the_gateway_is_mains_mint():host = types.SimpleNamespace(_session_db=None)from datetime import datetimeassert CLIInitMixin._new_session_id(host, datetime(2026, 10, 12, 1, 2, 3)).startswith("20261012_010203_")+++def test_cli_listings_include_gateway_rows_created_by_the_cli(store, tmp_path, monkeypatch):+ """The gateway labels an interactive local row ``local`` (``created_source`` keeps the surface), so+ main's ``source='cli'`` listings (/resume picker, /sessions, /history, bare -c) read both labels."""+ import sqlite3+ db, _ = store+ monkeypatch.setattr("hermes_constants.get_hermes_home", lambda: tmp_path)+ from hermes_state import SessionDB+ writer = SessionDB(db_path=tmp_path / "state.db")+ rows = (("local-cli", "local", "cli"), ("local-tui", "local", "tui"), ("legacy", "cli", "cli"),+ ("one", "oneshot", "oneshot"))+ for sid, source, _created in rows:+ writer.create_session(sid, source=source)+ writer.append_message(sid, "user", "hi " + sid)+ writer.close()+ conn = sqlite3.connect(tmp_path / "state.db")+ conn.executemany("UPDATE sessions SET created_source=? WHERE id=?", [(c, sid) for sid, _s, c in rows])+ conn.commit()+ conn.close()+ from hermes_cli.session_listing import query_session_listing+ listed = query_session_listing(db, source="cli", include_unnamed=True, limit=10)+ assert sorted(r["id"] for r in listed) == ["legacy", "local-cli"]+ found = db.search_sessions(source=["cli", "oneshot"], limit=10)+ assert sorted(r["id"] for r in found) == ["legacy", "local-cli", "one"]+ assert [r["id"] for r in db.search_sessions(source="tui", limit=10)] == ["local-tui"]+ assert len(db.list_sessions_rich(limit=10)) == 4