From a34998ee2fc39ae7009abd1340082400ef21c08f Mon Sep 17 00:00:00 2001 From: helix4u <4317663+helix4u@users.noreply.github.com> Date: Tue, 12 May 2026 10:23:43 -0600 Subject: [PATCH] fix(cli): parse positional insights days --- cli.py | 3 ++ tests/cli/test_cli_insights_command.py | 43 ++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 tests/cli/test_cli_insights_command.py diff --git a/cli.py b/cli.py index ea167b6b411..0666d74ba58 100644 --- a/cli.py +++ b/cli.py @@ -8805,6 +8805,9 @@ class HermesCLI: elif parts[i] == "--source" and i + 1 < len(parts): source = parts[i + 1] i += 2 + elif parts[i].isdigit(): + days = int(parts[i]) + i += 1 else: i += 1 diff --git a/tests/cli/test_cli_insights_command.py b/tests/cli/test_cli_insights_command.py new file mode 100644 index 00000000000..66c3c73b5d8 --- /dev/null +++ b/tests/cli/test_cli_insights_command.py @@ -0,0 +1,43 @@ +from unittest.mock import MagicMock, patch + +from cli import HermesCLI + + +class _InsightsEngineStub: + calls = [] + + def __init__(self, db): + self.db = db + + def generate(self, *, days=30, source=None): + self.calls.append({"days": days, "source": source}) + return {"days": days, "source": source} + + def format_terminal(self, report): + return f"days={report['days']} source={report['source']}" + + +def _run_show_insights(command: str): + cli_obj = HermesCLI.__new__(HermesCLI) + db = MagicMock() + _InsightsEngineStub.calls = [] + with patch("hermes_state.SessionDB", return_value=db), \ + patch("agent.insights.InsightsEngine", _InsightsEngineStub): + cli_obj._show_insights(command) + return _InsightsEngineStub.calls, db + + +def test_cli_insights_accepts_positional_days(capsys): + calls, db = _run_show_insights("/insights 7") + + assert calls == [{"days": 7, "source": None}] + db.close.assert_called_once() + assert "days=7 source=None" in capsys.readouterr().out + + +def test_cli_insights_keeps_days_flag_and_source(capsys): + calls, db = _run_show_insights("/insights --days 14 --source discord") + + assert calls == [{"days": 14, "source": "discord"}] + db.close.assert_called_once() + assert "days=14 source=discord" in capsys.readouterr().out