The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(insights): short-circuit before opening when state.db is absent
yoniebans9d75f20630b4
diff --git a/hermes_cli/cli_info_mixin.py b/hermes_cli/cli_info_mixin.pyindex afd9d6a75aa..3f5c253b02c 100644--- a/hermes_cli/cli_info_mixin.py+++ b/hermes_cli/cli_info_mixin.py@@ -772,8 +772,11 @@ class CLIInfoMixin:i += 1try:- from hermes_state import SessionDB+ from hermes_state import SessionDB, _default_db_pathfrom agent.insights import InsightsEngine+ if not _default_db_path().exists():+ print(" No session data yet.")+ returndb = SessionDB(read_only=True)try:engine = InsightsEngine(db)diff --git a/hermes_cli/main_agent_cmds.py b/hermes_cli/main_agent_cmds.pyindex 3239a4e570d..4efc80e597a 100644--- a/hermes_cli/main_agent_cmds.py+++ b/hermes_cli/main_agent_cmds.py@@ -105,8 +105,11 @@ def cmd_tools(args):def cmd_insights(args):db = Nonetry:- from hermes_state import SessionDB+ from hermes_state import SessionDB, _default_db_pathfrom agent.insights import InsightsEngine+ if not _default_db_path().exists():+ print("No session data yet.")+ returndb = SessionDB(read_only=True)engine = InsightsEngine(db)report = engine.generate(days=args.days, source=args.source)diff --git a/tests/hermes_cli/test_cli_insights_command.py b/tests/hermes_cli/test_cli_insights_command.pyindex dfdfa1d67ee..33098e76533 100644--- a/tests/hermes_cli/test_cli_insights_command.py+++ b/tests/hermes_cli/test_cli_insights_command.py@@ -1,8 +1,18 @@from unittest.mock import MagicMock, patchfrom types import SimpleNamespace+import pytest+from cli import HermesCLIfrom hermes_cli.main_agent_cmds import cmd_insights+from hermes_state import _default_db_path++[email protected](autouse=True)+def _state_db_exists():+ # insights short-circuits before opening when state.db is absent (fresh install).+ _default_db_path().parent.mkdir(parents=True, exist_ok=True)+ _default_db_path().touch()class _InsightsEngineStub:@@ -45,6 +55,17 @@ def test_cli_insights_keeps_days_flag_and_source(capsys):assert "days=14 source=discord" in capsys.readouterr().out+def test_insights_skips_open_when_store_missing(capsys):+ # Fresh install: no state.db yet → no open at all (a read-only open needs an existing file).+ _default_db_path().unlink()+ for run in (lambda: HermesCLI.__new__(HermesCLI)._show_insights("/insights 7"),+ lambda: cmd_insights(SimpleNamespace(days=30, source=None))):+ with patch("hermes_state.SessionDB") as ctor:+ run()+ ctor.assert_not_called()+ assert "No session data yet." in capsys.readouterr().out++def test_show_insights_opens_read_only():cli_obj = HermesCLI.__new__(HermesCLI)db = MagicMock()