Skip to content

feat(cli): add /exit --delete flag to remove session on quit#17665

Closed
teknium1 wants to merge 1 commit into
mainfrom
gemini-cli-port/exit-delete-session
Closed

feat(cli): add /exit --delete flag to remove session on quit#17665
teknium1 wants to merge 1 commit into
mainfrom
gemini-cli-port/exit-delete-session

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Port from google-gemini/gemini-cli#19332.

Summary

Users can now run /exit --delete (or /quit --delete, /exit -d) to permanently remove the current session's SQLite history plus on-disk transcripts in one shot — useful for privacy-sensitive workflows and one-off interactions.

Changes

File What
cli.py Parse --delete/-d after /exit or /quit → arm _delete_session_on_exit → shutdown path calls SessionDB.delete_session(session_id, sessions_dir=...) after end_session(). Unknown args are rejected (prevents typos like /exit -delete from exiting).
hermes_cli/commands.py /quit CommandDef now carries args_hint="[--delete]" so /help and autocomplete surface the flag.
tests/cli/test_exit_delete_session.py New file, 12 cases: both aliases, case-insensitivity, whitespace, short form, unknown-arg rejection, registry metadata, and the /q-is-not-quit clarification.
website/docs/reference/slash-commands.md Docs updated.

No new SQL or on-disk cleanup code — the SessionDB.delete_session(session_id, sessions_dir=...) API already existed for hermes sessions delete and handles SQLite removal (orphaning child sessions to satisfy FK constraints) plus .json / .jsonl / request_dump_* file cleanup.

Validation

  • Targeted tests: scripts/run_tests.sh tests/cli/test_exit_delete_session.py tests/cli/test_quick_commands.py tests/cli/test_cli_init.py tests/hermes_cli/test_commands.py tests/cli/test_cli_prefix_matching.py194 passed.
  • E2E (isolated HERMES_HOME): created a session row + <sid>.json + <sid>.jsonl + request_dump_<sid>_turn1.json, called the real end_session() + delete_session() path. DB row deleted, all three transcript files removed, repeat call correctly returns False.

Why this port

Gemini CLI shipped the same UX feature last week (#19332). The primitives it needs (SessionDB.delete_session(), sessions_dir cleanup) already existed in hermes-agent for hermes sessions delete; this PR just wires them into the /exit slash command. Surfacing deletion at the slash-command level is the flow a privacy-conscious user actually reaches for — having to /exithermes sessions listhermes sessions delete <id> is three steps too many.


Part of the weekly Gemini CLI PR scout. Out of 76 merged PRs in the past week, this was the cleanest self-contained port candidate — most of the rest were either TypeScript infra (ACP refactor), Google-specific (cloud-shell auth, undici timeouts, devtools logging), or duplicating features hermes already has (timeout retry classification, MCP ping handling, search tool case-sensitivity which rg already handles correctly).

Port from google-gemini/gemini-cli#19332.

Users can now exit with '/exit --delete' (or '/quit --delete', '/exit -d')
to permanently remove the current session's SQLite history plus on-disk
transcripts (*.json / *.jsonl / request_dump_*) in one shot. Useful for
privacy-sensitive workflows and one-off interactions where leaving a
session recording behind is undesirable.

Implementation:
- New HermesCLI._delete_session_on_exit one-shot flag (defaults False).
- process_command() parses --delete / -d after /exit or /quit and arms
  the flag. Unknown args print a hint and keep the CLI running (prevents
  typos like '/exit -delete' from accidentally exiting).
- Shutdown path calls SessionDB.delete_session(session_id, sessions_dir=...)
  right after end_session() when the flag is set. That API already
  existed for 'hermes sessions delete' and handles both SQLite removal
  (orphaning child sessions so FK constraints hold) and on-disk file
  cleanup.
- /quit CommandDef now advertises '[--delete]' in args_hint so /help
  and CLI autocomplete surface it.

Tests: tests/cli/test_exit_delete_session.py (12 cases covering both
aliases, case insensitivity, whitespace, short form, unknown-arg
rejection, and registry metadata).

E2E-verified with isolated HERMES_HOME: session row deleted, all three
transcript/request-dump files removed, second delete_session call
correctly returns False.
@alt-glitch alt-glitch added type/feature New feature or request comp/cli CLI entry point, hermes_cli/, setup wizard P3 Low — cosmetic, nice to have labels Apr 30, 2026
@teknium1

Copy link
Copy Markdown
Contributor Author

Closing in favor of #27101, which salvages this PR onto current main. Two conflicts resolved (main's {quit,exit} set form preserved; expanded docs description kept). 154 new tests pass, 706 regression tests pass, E2E with real SessionDB confirms DB row + 3 artifact files removed.

@teknium1 teknium1 closed this May 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard P3 Low — cosmetic, nice to have type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants