feat: bare /save shows a usage card instead of exporting

Per review: /save with no arguments prints usage (formats, filename,
redact, examples) and writes nothing; the export requires an explicit
format. Unknown formats print the error plus the same usage card. One
shared SAVE_USAGE string in hermes_cli/session_export.py serves both the
CLI and gateway handlers. args_hint updated to <json|md|html> to reflect
the now-required format. Tests: bare-save and bad-format usage cases
added; location tests pass an explicit format.
This commit is contained in:
Teknium
2026-08-15 01:49:48 -07:00
parent e5a2c80c0e
commit ca5c04818b
5 changed files with 81 additions and 16 deletions
+10 -2
View File
@@ -9355,20 +9355,28 @@ class HermesCLI(CLIAgentSetupMixin, CLICommandsMixin, CLIBillingMixin):
redaction pass before writing.
"""
from hermes_cli.session_export import (
SAVE_USAGE,
normalize_save_format,
render_session_for_save,
)
parts = cmd.split()[1:]
if not parts:
print(SAVE_USAGE)
return
redact = False
if parts and parts[-1].lower() in ("redact", "--redact"):
if parts[-1].lower() in ("redact", "--redact"):
redact = True
parts = parts[:-1]
if not parts:
print(SAVE_USAGE)
return
try:
fmt = normalize_save_format(parts[0] if parts else None)
fmt = normalize_save_format(parts[0])
except ValueError as e:
print(f"(._.) {e}")
print(SAVE_USAGE)
return
filename = parts[1] if len(parts) > 1 else None
+16 -10
View File
@@ -4537,27 +4537,33 @@ class GatewaySlashCommandsMixin:
Usage: ``/save [json|md|html] [filename] [redact]``
"""
from hermes_cli.session_export import (
SAVE_USAGE,
default_save_filename,
normalize_save_format,
render_session_for_save,
)
parts = event.get_command_args().split()
if not parts:
return SAVE_USAGE
redact = False
if parts[-1].lower() in ("redact", "--redact"):
redact = True
parts = parts[:-1]
if not parts:
return SAVE_USAGE
try:
fmt = normalize_save_format(parts[0])
except ValueError as e:
return f"{e}\n\n{SAVE_USAGE}"
source = event.source
session_entry = await self.async_session_store.get_or_create_session(source)
session_id = session_entry.session_id
if not self._session_db:
return "Session database not available."
parts = event.get_command_args().split()
redact = False
if parts and parts[-1].lower() in ("redact", "--redact"):
redact = True
parts = parts[:-1]
try:
fmt = normalize_save_format(parts[0] if parts else None)
except ValueError as e:
return str(e)
filename = parts[1] if len(parts) > 1 else default_save_filename(session_id, fmt)
# The filename is echoed to the platform only — never trust path
# separators from chat input.
+2 -2
View File
@@ -154,8 +154,8 @@ COMMAND_REGISTRY: list[CommandDef] = [
cli_only=True),
CommandDef("history", "Show conversation history", "Session",
cli_only=True),
CommandDef("save", "Save/export the current conversation (json, md, or html)", "Session",
args_hint="[json|md|html] [filename] [redact]"),
CommandDef("save", "Export the current conversation (bare /save shows usage)", "Session",
args_hint="<json|md|html> [filename] [redact]"),
CommandDef("retry", "Retry the last message (resend to agent)", "Session"),
CommandDef("prompt", "Compose your next prompt in $EDITOR (markdown), then send it", "Session",
cli_only=True, args_hint="[initial text]", aliases=("compose",)),
+20
View File
@@ -323,6 +323,26 @@ def _finish_markdown(lines: List[str]) -> str:
SAVE_FORMATS = ("json", "md", "html")
SAVE_USAGE = """/save — export the current session to a file
Usage: /save <format> [filename] [redact]
Formats:
json full session snapshot (canonical export shape)
md readable Markdown transcript
html standalone single-file HTML page (shareable, no dependencies)
Options:
filename optional output name/path (default: auto-named;
CLI saves under ~/.hermes/sessions/saved/)
redact scrub API keys, tokens, and credentials before writing
Examples:
/save json
/save html
/save md notes.md
/save html session.html redact"""
def normalize_save_format(fmt: Optional[str]) -> str:
"""Map a user-typed /save format token to a canonical format."""
+33 -2
View File
@@ -61,7 +61,7 @@ def test_save_conversation_writes_under_hermes_home(hermes_home, tmp_path, monke
])
# Call the unbound method against our stub.
cli.HermesCLI.save_conversation(stub)
cli.HermesCLI.save_conversation(stub, "/save json")
# File must NOT be in CWD
cwd_leak = list(work.glob("hermes_conversation_*.json"))
@@ -95,9 +95,40 @@ def test_save_conversation_empty_history_does_nothing(hermes_home, capsys):
import cli
stub = _make_stub_cli([])
cli.HermesCLI.save_conversation(stub)
cli.HermesCLI.save_conversation(stub, "/save json")
saved_dir = hermes_home / "sessions" / "saved"
assert not saved_dir.exists() or not list(saved_dir.iterdir())
out = capsys.readouterr().out
assert "No conversation to save" in out
def test_save_conversation_bare_shows_usage(hermes_home, capsys):
"""Bare /save prints the usage card and writes nothing."""
for mod in [m for m in sys.modules if m.startswith("cli") or m == "hermes_constants"]:
sys.modules.pop(mod, None)
import cli
stub = _make_stub_cli([{"role": "user", "content": "hi"}])
cli.HermesCLI.save_conversation(stub, "/save")
saved_dir = hermes_home / "sessions" / "saved"
assert not saved_dir.exists() or not list(saved_dir.iterdir())
out = capsys.readouterr().out
# Usage card lists every format and the redact option
for token in ("json", "md", "html", "redact", "Usage:"):
assert token in out, (token, out)
def test_save_conversation_bad_format_shows_usage(hermes_home, capsys):
for mod in [m for m in sys.modules if m.startswith("cli") or m == "hermes_constants"]:
sys.modules.pop(mod, None)
import cli
stub = _make_stub_cli([{"role": "user", "content": "hi"}])
cli.HermesCLI.save_conversation(stub, "/save pdf")
saved_dir = hermes_home / "sessions" / "saved"
assert not saved_dir.exists() or not list(saved_dir.iterdir())
out = capsys.readouterr().out
assert "Usage:" in out