From ead41c01460debbf7a2ea81df063f93bceedee2b Mon Sep 17 00:00:00 2001 From: zifrz <114908186+zifrz@users.noreply.github.com> Date: Sat, 11 Apr 2026 11:24:11 +0530 Subject: [PATCH 1/5] fix(autocomplete): register /clear command to enable autocomplete suggestions (#254) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, the `/clear command was handled via an inline conditional check in the main interactive loop rather than being registered through the `@register_command decorator. Since the SlashCompleter only yields suggestions from commands returned by get_unique_commands()` (which queries the command registry), `/clear was invisible to autocomplete when typing `/cl`, while `/clipboard (properly registered) appeared correctly. This change adds the inline `/clear handler to a properly registered command in code_puppy/command_line/core_commands.py`: - Added @register_command decorator with name="clear", description, usage, and category - Implemented handle_clear_command() that preserves the original behavior: 1. Clears conversation history via agent.clear_message_history() 2. Rotates autosave session via finalize_autosave_session() 3. Clears pending clipboard images via clipboard_manager.clear_pending() 4. Emits appropriate warning/info/system messages for user feedback - The command supports both /clear and plain clear input (handled by command parser) Testing notes: - Type /cl in interactive mode → both /clear and /clipboard now appear in suggestions - Executing /clear still clears conversation history (not terminal screen) as expected - Autosave session rotation and clipboard cleanup behavior unchanged - Plain text clear (without slash) continues to work via command handler fallback Fixes #254 --- code_puppy/command_line/core_commands.py | 29 ++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/code_puppy/command_line/core_commands.py b/code_puppy/command_line/core_commands.py index afd7bdfbc..ca499777f 100644 --- a/code_puppy/command_line/core_commands.py +++ b/code_puppy/command_line/core_commands.py @@ -167,6 +167,35 @@ def handle_paste_command(command: str) -> bool: return True +@register_command( + name="clear", + description="Clear conversation history and rotate autosave session", + usage="/clear, clear", + aliases=[], + category="core", +) +def handle_clear_command(command: str) -> bool: + from code_puppy.command_line.clipboard import get_clipboard_manager + from code_puppy.messaging import emit_warning, emit_system_message, emit_info + from code_puppy.agents import get_current_agent + from code_puppy.config import finalize_autosave_session + + agent = get_current_agent() + new_session_id = finalize_autosave_session() + agent.clear_message_history() + emit_warning("Conversation history cleared!") + emit_system_message("The agent will not remember previous interactions.") + emit_info(f"Auto-save session rotated to: {new_session_id}") + + # Also clear pending clipboard images + clipboard_manager = get_clipboard_manager() + clipboard_count = clipboard_manager.get_pending_count() + clipboard_manager.clear_pending() + if clipboard_count > 0: + emit_info(f"Cleared {clipboard_count} pending clipboard image(s)") + return True + + @register_command( name="tutorial", description="Run the interactive tutorial wizard", From b9996ca2c4e85f689b94c20bd03fe1aa21a7a2c3 Mon Sep 17 00:00:00 2001 From: zifrz <114908186+zifrz@users.noreply.github.com> Date: Sat, 11 Apr 2026 12:17:42 +0530 Subject: [PATCH 2/5] docs(core_commands): add docstring to handle_clear_command --- code_puppy/command_line/core_commands.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/code_puppy/command_line/core_commands.py b/code_puppy/command_line/core_commands.py index ca499777f..c942f5064 100644 --- a/code_puppy/command_line/core_commands.py +++ b/code_puppy/command_line/core_commands.py @@ -175,6 +175,12 @@ def handle_paste_command(command: str) -> bool: category="core", ) def handle_clear_command(command: str) -> bool: + """Clear conversation history, rotate autosave session, and clear pending clipboard images. + + Resets the agent's context so it starts fresh, persists the current session + to autosave, and notifies the user of the cleanup. + """ + from code_puppy.command_line.clipboard import get_clipboard_manager from code_puppy.messaging import emit_warning, emit_system_message, emit_info from code_puppy.agents import get_current_agent From 2361733b0a23f3babcf067b8df23397804357191 Mon Sep 17 00:00:00 2001 From: zifrz <114908186+zifrz@users.noreply.github.com> Date: Sat, 11 Apr 2026 19:25:22 +0530 Subject: [PATCH 3/5] fix(core_commands): correct usage string for /clear command --- code_puppy/command_line/core_commands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code_puppy/command_line/core_commands.py b/code_puppy/command_line/core_commands.py index c942f5064..395d17713 100644 --- a/code_puppy/command_line/core_commands.py +++ b/code_puppy/command_line/core_commands.py @@ -170,7 +170,7 @@ def handle_paste_command(command: str) -> bool: @register_command( name="clear", description="Clear conversation history and rotate autosave session", - usage="/clear, clear", + usage="/clear", aliases=[], category="core", ) From 5e25e0a8562e4f7b4ea483cb313712cad6deebbb Mon Sep 17 00:00:00 2001 From: zifrz <114908186+zifrz@users.noreply.github.com> Date: Tue, 14 Apr 2026 10:36:26 +0530 Subject: [PATCH 4/5] fix(cli_runner): remove /clear from inline handler, delegate to registry --- code_puppy/cli_runner.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code_puppy/cli_runner.py b/code_puppy/cli_runner.py index 3f8d2c028..520118a1b 100644 --- a/code_puppy/cli_runner.py +++ b/code_puppy/cli_runner.py @@ -625,8 +625,8 @@ async def interactive_mode(message_renderer, initial_command: str = None) -> Non # The renderer is stopped in the finally block of main(). break - # Check for clear command (supports both `clear` and `/clear`) - if task.strip().lower() in ("clear", "/clear"): + # Check for clear command (supports only `clear`) + if task.strip().lower() in ("clear"): from code_puppy.command_line.clipboard import get_clipboard_manager from code_puppy.messaging import ( emit_info, From 91dafcb86c115c9857157bff3b6ac040a98e2e8e Mon Sep 17 00:00:00 2001 From: Zyed Mulla <114908186+zifrz@users.noreply.github.com> Date: Tue, 14 Apr 2026 10:58:53 +0530 Subject: [PATCH 5/5] fix(cli_runner): correct clear command guard to avoid unintended matches Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- code_puppy/cli_runner.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code_puppy/cli_runner.py b/code_puppy/cli_runner.py index 520118a1b..117f85f22 100644 --- a/code_puppy/cli_runner.py +++ b/code_puppy/cli_runner.py @@ -626,7 +626,7 @@ async def interactive_mode(message_renderer, initial_command: str = None) -> Non break # Check for clear command (supports only `clear`) - if task.strip().lower() in ("clear"): + if task.strip().lower() == "clear": from code_puppy.command_line.clipboard import get_clipboard_manager from code_puppy.messaging import ( emit_info,