mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-06-20 10:11:58 +00:00
fix(cli): handle EOFError in sessions delete/prune confirmation prompts (#3101)
sessions delete and prune call input() for confirmation without catching EOFError. When stdin isn't a TTY (piped input, CI/CD, cron), input() throws EOFError and the command crashes. Extract a _confirm_prompt() helper that handles EOFError and KeyboardInterrupt, defaulting to cancel. Both call sites now use it. Salvaged from PR #2622 by dieutx (improved from duplicated try/except to shared helper). Closes #2565.
This commit is contained in:
parent
432ba3b709
commit
bd43a43f07
2 changed files with 62 additions and 4 deletions
|
|
@ -3844,6 +3844,13 @@ For more help on a command:
|
|||
sessions_browse.add_argument("--source", help="Filter by source (cli, telegram, discord, etc.)")
|
||||
sessions_browse.add_argument("--limit", type=int, default=50, help="Max sessions to load (default: 50)")
|
||||
|
||||
def _confirm_prompt(prompt: str) -> bool:
|
||||
"""Prompt for y/N confirmation, safe against non-TTY environments."""
|
||||
try:
|
||||
return input(prompt).strip().lower() in ("y", "yes")
|
||||
except (EOFError, KeyboardInterrupt):
|
||||
return False
|
||||
|
||||
def cmd_sessions(args):
|
||||
import json as _json
|
||||
try:
|
||||
|
|
@ -3904,8 +3911,7 @@ For more help on a command:
|
|||
print(f"Session '{args.session_id}' not found.")
|
||||
return
|
||||
if not args.yes:
|
||||
confirm = input(f"Delete session '{resolved_session_id}' and all its messages? [y/N] ")
|
||||
if confirm.lower() not in ("y", "yes"):
|
||||
if not _confirm_prompt(f"Delete session '{resolved_session_id}' and all its messages? [y/N] "):
|
||||
print("Cancelled.")
|
||||
return
|
||||
if db.delete_session(resolved_session_id):
|
||||
|
|
@ -3917,8 +3923,7 @@ For more help on a command:
|
|||
days = args.older_than
|
||||
source_msg = f" from '{args.source}'" if args.source else ""
|
||||
if not args.yes:
|
||||
confirm = input(f"Delete all ended sessions older than {days} days{source_msg}? [y/N] ")
|
||||
if confirm.lower() not in ("y", "yes"):
|
||||
if not _confirm_prompt(f"Delete all ended sessions older than {days} days{source_msg}? [y/N] "):
|
||||
print("Cancelled.")
|
||||
return
|
||||
count = db.prune_sessions(older_than_days=days, source=args.source)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue