The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cli): -c NAME --create-if-missing creates the titled session on the gateway
Teknium4334ddddedaa
diff --git a/hermes_cli/gateway_session_store.py b/hermes_cli/gateway_session_store.pyindex bd00a3317ff..c690767dd67 100644--- a/hermes_cli/gateway_session_store.py+++ b/hermes_cli/gateway_session_store.py@@ -133,13 +133,16 @@ class GatewaySessionStore:raisereturn self.create(launch)- def create(self, launch=None):- """``session.create`` with the launch policy; adopts and returns the new session id."""+ def create(self, launch=None, title=None):+ """``session.create`` with the launch policy (and ``title``: the owner's resolve -> create ->+ title step); adopts and returns the new session id."""from agent.session_source import session_source_forparams = _creation_policy(launch or {})params["cwd"] = os.path.realpath(os.getenv("TERMINAL_CWD") or os.getcwd())# Main's row label: ``cli``, ``oneshot`` for a finite -q/-Q run, or an explicit --source.params["source"] = session_source_for("cli")+ if title:+ params["title"] = titlesnapshot = self.call("session.create", request_id=uuid.uuid4().hex, **params)return self._adopt(snapshot)@@ -379,3 +382,8 @@ def create_titled_session(title):logger.warning("Failed to create titled session %r on the gateway: %s", title, exc)return Nonereturn snapshot["stored_session_id"]++ """``chat -c NAME --create-if-missing`` (main's ``_create_titled_session``): the gateway creates the+ titled session; the CLI resumes the id it returns. Launch flags are applied by the CLI's own+ session open, as main's bare row took them at agent build."""+ return session_store().create(title=title)diff --git a/hermes_cli/main.py b/hermes_cli/main.pyindex 38415a366b8..43cb7e4a8c0 100644--- a/hermes_cli/main.py+++ b/hermes_cli/main.py@@ -1380,25 +1380,16 @@ def _resolve_session_by_name_or_id(name_or_id: str) -> Optional[str]:def _create_titled_session(title: str) -> Optional[str]:"""Create a fresh titled session (``chat -c <title> --create-if-missing``).- Same timestamp+uuid id shape the CLI uses; the title is recorded with- user provenance so auto-titling never overwrites it.+ The gateway is the single writer: it creates the session and records the title with user+ provenance, so auto-titling never overwrites it (gateway_session_store.create_titled_session).Used by ``chat -c <title> --create-if-missing`` (#86794): programmatic callers (plugins, scripts) thatwant "send to this named thread, making it if needed" get a deterministic outcome instead of a silentno-op."""- db = Nonetry:- from hermes_state_ids import new_session_id as mint_session_id- from hermes_state_registry import acquire-- new_session_id = mint_session_id()- # The CLI acquires the registry handle for this same path moments later; share it- # instead of minting a second writer for one INSERT (close() releases the refcount).- db = acquire()- db.create_session(new_session_id, source="cli")- db.set_session_title(new_session_id, title)- return new_session_id+ from hermes_cli.gateway_session_store import create_titled_session+ return create_titled_session(title)except Exception:# Programmatic callers rely on --create-if-missing being deterministic;# swallow the failure but log the cause so it lands in errors.log@@ -1406,12 +1397,6 @@ def _create_titled_session(title: str) -> Optional[str]:# See #86794.logger.exception("Failed to create titled session %r", title)return None- finally:- if db is not None:- try:- db.close()- except Exception:- passdef _resolve_continue_arg(args, *, use_tui: bool) -> None:diff --git a/tests/hermes_cli/test_chat_c_fail_loudly.py b/tests/hermes_cli/test_chat_c_fail_loudly.pyindex ee7a884f9c3..51321a4fd6e 100644--- a/tests/hermes_cli/test_chat_c_fail_loudly.py+++ b/tests/hermes_cli/test_chat_c_fail_loudly.py@@ -20,10 +20,24 @@ import pytest@pytest.fixturedef isolated_home(tmp_path, monkeypatch):- """Point HERMES_HOME at a temp dir so session creation stays isolated."""+ """Point HERMES_HOME at a temp dir so session creation stays isolated. The gateway is the single+ writer: ``session.create {title}`` is played by a stand-in that writes the row the owner would."""home = tmp_path / "hermes_home"home.mkdir()monkeypatch.setenv("HERMES_HOME", str(home))+ from hermes_cli import gateway_session_store++ def create_titled(title):+ from hermes_state import SessionDB+ db = SessionDB()+ try:+ sid = "local-" + "ab" * 32+ db.create_session(sid, source="local")+ db.set_session_title(sid, title)+ return sid+ finally:+ db.close()+ monkeypatch.setattr(gateway_session_store, "create_titled_session", create_titled)return homediff --git a/tests/hermes_cli/test_gateway_session_store.py b/tests/hermes_cli/test_gateway_session_store.pyindex 5b4f0610fff..e4dfe71e480 100644--- a/tests/hermes_cli/test_gateway_session_store.py+++ b/tests/hermes_cli/test_gateway_session_store.py@@ -326,3 +326,14 @@ def test_cli_listings_include_gateway_rows_created_by_the_cli(store, tmp_path, massert 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+++def test_create_if_missing_titles_a_gateway_created_session(store, monkeypatch):+ """``chat -c NAME --create-if-missing``: the gateway creates the titled session (its own+ resolve -> create -> title step); the CLI then resumes the id it returns. No client write."""+ db, client = store+ from hermes_cli import gateway_session_store as gss+ monkeypatch.setattr(gss, "session_store", lambda: db)+ assert gss.create_titled_session("Fresh Named") == "local-new"+ method, params = [c for c in client.calls if c[0] == "session.create"][-1]+ assert params["title"] == "Fresh Named" and params["source"] and params["cwd"]