The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(sessions): keep /undo and rewind rows out of /save json
kshitijk4poorb42984652ca9
diff --git a/gateway/slash_commands_session.py b/gateway/slash_commands_session.pyindex 10f5c8308f3..e98bbfa602e 100644--- a/gateway/slash_commands_session.py+++ b/gateway/slash_commands_session.py@@ -747,6 +747,9 @@ class GatewaySessionCommandsMixin:export_data = await self._session_db.export_session(session_id, **export_projection(fmt in SAVE_TRANSCRIPT_FORMATS))if not export_data:return t("gateway.save.no_messages", session_id=session_id)+ if fmt not in SAVE_TRANSCRIPT_FORMATS:+ # Turns removed by /undo, rewind or edit stay out of a file sent into the chat (archived turns are kept).+ export_data["messages"] = [m for m in export_data["messages"] if m["active"] or m["compacted"]]if redact:from hermes_cli.session_export_md import redact_session_dataexport_data = redact_session_data(export_data)diff --git a/hermes_cli/cli_session_mixin.py b/hermes_cli/cli_session_mixin.pyindex 3624085bd21..088fdedc16d 100644--- a/hermes_cli/cli_session_mixin.py+++ b/hermes_cli/cli_session_mixin.py@@ -665,6 +665,9 @@ class CLISessionMixin:session_data = _db.export_session(_sid, **export_projection(fmt in SAVE_TRANSCRIPT_FORMATS))except Exception:session_data = None+ if session_data and fmt not in SAVE_TRANSCRIPT_FORMATS:+ # Turns removed by /undo, rewind or edit stay out of a /save file (archived turns are kept).+ session_data["messages"] = [m for m in session_data["messages"] if m["active"] or m["compacted"]]if not session_data:if not self.conversation_history:print(t("cli.session.save_nothing"))diff --git a/tests/hermes_cli/test_save_transcript_history.py b/tests/hermes_cli/test_save_transcript_history.pyindex 17f3d04a1cc..419f5c367b2 100644--- a/tests/hermes_cli/test_save_transcript_history.py+++ b/tests/hermes_cli/test_save_transcript_history.py@@ -81,6 +81,8 @@ def test_save_json_restores_compacted_history_as_archived(tmp_path, monkeypatch,monkeypatch.setenv("HERMES_HOME", str(tmp_path))db = _compacted_store(tmp_path / "state.db")+ db.append_message("s1", "user", "undone secret")+ db.rewind_to_message("s1", db.get_messages("s1")[-1]["id"])def shape(store, **flags):return [(m["role"], m["content"]) for m in store.get_messages("s1", **flags)]@@ -88,6 +90,7 @@ def test_save_json_restores_compacted_history_as_archived(tmp_path, monkeypatch,try:shown, live = shape(db, include_compacted=True), shape(db)snapshot = json.loads(save(db, "json", tmp_path / "saved.json"))+ assert "undone secret" not in [m["content"] for m in snapshot["messages"]]# Like `hermes sessions export`, the in-memory backup is capped per session (sessions.max_export_messages).monkeypatch.setattr("hermes_state.resolved_max_export_messages", lambda: 5)assert "max_export_messages" in save(db, "json", tmp_path / "capped.json")