feat: add /new command

This commit is contained in:
worenidewen 2026-02-13 01:24:48 +08:00
parent dd4c06bea5
commit 24a90af6d3

View File

@ -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)