Skip to content

The agent that grows with you

fix: retain explicit verified deletion after read-only export migration

Teknium23456236c8f1
diff --git a/hermes_cli/sessions_cmd.py b/hermes_cli/sessions_cmd.py
index cb000646b85..52464d59f33 100644
--- a/hermes_cli/sessions_cmd.py
+++ b/hermes_cli/sessions_cmd.py
@@ -963,11 +963,17 @@ def cmd_sessions(args, sessions_parser=None):
"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():
+ # Verified deletion is an explicit mutation, not a read-only export.
+ deleting_export = (
+ action == "export" and getattr(args, "delete_after_verified", False)
+ and getattr(args, "yes", False) and getattr(args, "session_id", None)
+ and getattr(args, "format", None) in ("md", "qmd")
+ )
+ read_only = action in empty_messages and not deleting_export
+ if action in empty_messages and not path.exists():
print(empty_messages[action])
return
- db = SessionDB(db_path=path, read_only=True) if read_only else SessionDB()
+ db = SessionDB(db_path=path, read_only=read_only) if action in empty_messages else SessionDB()
except Exception as e:
print(f"Error: Could not open session database: {e}")
return 1
diff --git a/tests/hermes_cli/test_sessions_export_md_cli.py b/tests/hermes_cli/test_sessions_export_md_cli.py
index ea610d9402d..27b5532ea00 100644
--- a/tests/hermes_cli/test_sessions_export_md_cli.py
+++ b/tests/hermes_cli/test_sessions_export_md_cli.py
@@ -34,6 +34,37 @@ def test_sessions_export_md_writes_single_session(monkeypatch, tmp_path, capsys)
assert str(files[0]) in output
+def test_sessions_export_verified_delete_keeps_file(monkeypatch, tmp_path, capsys):
+ import hermes_cli.main as main_mod
+ from hermes_cli.session_export_md import verify_export_file
+
+ monkeypatch.setenv("HERMES_HOME", str(tmp_path))
+ path = tmp_path / "state.db"
+ db = SessionDB(db_path=path)
+ db.create_session("delete-me", "cli")
+ db.append_message("delete-me", "user", "retain this exported payload")
+ original = db.export_session("delete-me")
+ assert original is not None
+ db.close()
+ monkeypatch.setattr(sys, "argv", [
+ "hermes", "sessions", "export", "--format", "md",
+ "--session-id", "delete-me", "--delete-after-verified", "--yes",
+ str(tmp_path / "exports"),
+ ])
+
+ main_mod.main()
+
+ files = list((tmp_path / "exports").glob("*.md"))
+ assert len(files) == 1
+ assert verify_export_file(files[0], original)[0]
+ db = SessionDB(db_path=path, read_only=True)
+ try:
+ assert db.get_session("delete-me") is None
+ finally:
+ db.close()
+ assert "Deleted exported session" in capsys.readouterr().out
+
+
def test_sessions_export_redact_scrubs_secrets(monkeypatch, tmp_path):
"""Redaction affects the exported file, never the stored transcript."""
import hermes_cli.main as main_mod