Skip to content

The agent that grows with you

fix: generate CLI insights without initializing session storage

Teknium680937a6e768
diff --git a/hermes_cli/main_agent_cmds.py b/hermes_cli/main_agent_cmds.py
index 1b5264703b4..a768f47d846 100644
--- a/hermes_cli/main_agent_cmds.py
+++ b/hermes_cli/main_agent_cmds.py
@@ -107,7 +107,13 @@ def cmd_insights(args):
try:
from hermes_state import SessionDB
from agent.insights import InsightsEngine
- db = SessionDB()
+ from hermes_cli.config import get_hermes_home
+ path = get_hermes_home() / "state.db"
+ if not path.exists():
+ source = f" (source: {args.source})" if args.source else ""
+ print(f" No sessions found in the last {args.days} days{source}.")
+ return
+ db = SessionDB(db_path=path, read_only=True)
engine = InsightsEngine(db)
report = engine.generate(days=args.days, source=args.source)
print(engine.format_terminal(report))
diff --git a/tests/hermes_cli/test_launch_readonly.py b/tests/hermes_cli/test_launch_readonly.py
index b02068df112..aa7f644d60a 100644
--- a/tests/hermes_cli/test_launch_readonly.py
+++ b/tests/hermes_cli/test_launch_readonly.py
@@ -32,12 +32,19 @@ before = path.read_bytes() if path.exists() else None
assert _resolve_last_session(source='tui') == ('reader-fixture' if populated else None)
assert _resolve_session_by_name_or_id('reader-fixture') == ('reader-fixture' if populated else None)
_print_tui_exit_summary('reader-fixture')
+from hermes_cli.main_agent_cmds import cmd_insights
+from types import SimpleNamespace
+cmd_insights(SimpleNamespace(days=30, source='tui'))
after = path.read_bytes() if path.exists() else None
assert after == before, 'launch reader 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
+ assert 'Error generating insights:' not in result.stdout
if populated:
+ assert 'Hermes Insights' in result.stdout
assert 'Resume this session with:' in result.stdout
assert 'Reader fixture' in result.stdout
+ else:
+ assert 'No sessions found in the last 30 days (source: tui).' in result.stdout