The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: keep session lists and statistics read-only
Teknium1a1ad945981c
diff --git a/hermes_cli/sessions_cmd.py b/hermes_cli/sessions_cmd.pyindex 748c0a73e54..f992b655956 100644--- a/hermes_cli/sessions_cmd.py+++ b/hermes_cli/sessions_cmd.py@@ -954,7 +954,19 @@ def cmd_sessions(args, sessions_parser=None):return pre(args)try:from hermes_state import SessionDB- db = SessionDB()+ from hermes_constants import get_hermes_home+ path = get_hermes_home() / "state.db"+ empty_messages = {+ "list": "No sessions found.",+ "stats": "Total sessions: 0\nTotal messages: 0",+ "pinned": "[]" if getattr(args, "json", False) else+ "No pinned sessions. Pin one with: hermes sessions pin <session_id>",+ }+ read_only = action in empty_messages+ if read_only and not path.exists():+ print(empty_messages[action])+ return+ db = SessionDB(db_path=path, read_only=read_only)except Exception as e:print(f"Error: Could not open session database: {e}")return 1diff --git a/tests/hermes_cli/test_sessions_observation.py b/tests/hermes_cli/test_sessions_observation.pynew file mode 100644index 00000000000..daf85a69802--- /dev/null+++ b/tests/hermes_cli/test_sessions_observation.py@@ -0,0 +1,47 @@+"""Session listings must not initialize or migrate canonical storage."""+import os+from pathlib import Path+import subprocess+import sys++import pytest++[email protected]('populated', [False, True])+def test_session_observation_preserves_storage(tmp_path, populated):+ repo = Path(__file__).resolve().parents[2]+ env = {k: os.environ[k] for k in ('PATH', 'SYSTEMROOT', 'LANG', 'TZ') if k in os.environ}+ env.update(HOME=str(tmp_path), USERPROFILE=str(tmp_path), HERMES_HOME=str(tmp_path / 'profile'), PYTHONPATH=str(repo))+ (tmp_path / 'profile').mkdir()+ code = '''+from pathlib import Path+from types import SimpleNamespace+from contextlib import redirect_stdout+import io, os+from hermes_state import SessionDB+from hermes_cli.sessions_cmd import cmd_sessions+path = Path(os.environ['HERMES_HOME']) / 'state.db'+if POPULATED:+ with SessionDB(db_path=path) as db:+ db.create_session('observation-fixture', source='cli')+ db.append_message('observation-fixture', role='user', content='fixture')+before = path.read_bytes() if path.exists() else None+for action in ('list', 'stats', 'pinned'):+ output = io.StringIO()+ with redirect_stdout(output):+ result = cmd_sessions(SimpleNamespace(sessions_action=action, source=None, limit=20, json=True))+ text = output.getvalue()+ assert result in (None, 0), text+ assert 'Error:' not in text, text+ if action == 'list':+ assert ('observation-fixture' if POPULATED else 'No sessions found.') in text, text+ if action == 'stats':+ assert ('Total sessions: 1' if POPULATED else 'Total sessions: 0') in text, text+ if action == 'pinned':+ assert text.strip() == '[]', text+ after = path.read_bytes() if path.exists() else None+ assert after == before, action + ' created or mutated state.db'+'''.replace('POPULATED', repr(populated))+ result = subprocess.run([sys.executable, '-c', code], cwd=repo, env=env, stdin=subprocess.DEVNULL,+ capture_output=True, text=True, timeout=30)+ assert result.returncode == 0, result.stdout + result.stderr