From 24a90af6d32f8fa3e630ea40d0a234b335cf30b9 Mon Sep 17 00:00:00 2001 From: worenidewen Date: Fri, 13 Feb 2026 01:24:48 +0800 Subject: [PATCH] feat: add /new command --- nanobot/cli/commands.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/nanobot/cli/commands.py b/nanobot/cli/commands.py index 2aa5688..eb16782 100644 --- a/nanobot/cli/commands.py +++ b/nanobot/cli/commands.py @@ -28,6 +28,7 @@ app = typer.Typer( console = Console() EXIT_COMMANDS = {"exit", "quit", "/exit", "/quit", ":q"} +NEW_SESSION_COMMANDS = {"/new", "/reset"} # --------------------------------------------------------------------------- # CLI input: prompt_toolkit for editing, paste, history, and display @@ -111,6 +112,11 @@ def _is_exit_command(command: str) -> bool: return command.lower() in EXIT_COMMANDS +def _is_new_session_command(command: str) -> bool: + """Return True when input should clear the session history.""" + return command.lower() in NEW_SESSION_COMMANDS + + async def _read_interactive_input_async() -> str: """Read user input using prompt_toolkit (handles paste, history, display). @@ -484,6 +490,15 @@ def agent( console.print("\nGoodbye!") break + if _is_new_session_command(command): + session = agent_loop.sessions.get_or_create(session_id) + session.clear() + agent_loop.sessions.save(session) + console.print( + f"\n[green]{__logo__} Started new session. History cleared.[/green]\n" + ) + continue + with _thinking_ctx(): response = await agent_loop.process_direct(user_input, session_id) _print_agent_response(response, render_markdown=markdown)