4242
4343class NullApp (App ):
4444 CSS_PATH = "styles/main.tcss"
45- LAYERS = ["base" , "overlay" ]
45+ LAYERS : ClassVar [ list [ str ]] = ["base" , "overlay" ]
4646
4747 BINDINGS : ClassVar [list [BindingType ]] = [
4848 ("escape" , "cancel_operation" , "Cancel" ),
@@ -302,6 +302,18 @@ def action_toggle_ai_mode(self):
302302 """Toggle between CLI and AI mode."""
303303 self .query_one ("#input" , InputController ).toggle_mode ()
304304
305+ def action_toggle_agent_mode (self ):
306+ """Toggle agent mode on/off."""
307+ current = Config .get ("ai.agent_mode" ) or False
308+ new_value = not current
309+ Config .set ("ai.agent_mode" , new_value )
310+ try :
311+ status_bar = self .query_one ("#status-bar" , StatusBar )
312+ status_bar .set_agent_mode (new_value )
313+ except Exception :
314+ pass
315+ self .notify (f"Agent mode { 'enabled' if new_value else 'disabled' } " )
316+
305317 def action_cancel_operation (self ):
306318 """Cancel any running operation."""
307319 cancelled = False
@@ -588,11 +600,24 @@ def on_prompt_select(selected):
588600
589601 def action_clear_history (self ):
590602 """Clear history and context."""
603+ self .blocks = []
604+ self .current_cli_block = None
605+ self .current_cli_widget = None
606+
607+ try :
608+ history = self .query_one ("#history" )
609+ history .remove_children ()
610+ except Exception :
611+ pass
591612
592- async def do_clear ():
593- await self .command_handler .handle ("/clear" )
613+ try :
614+ status_bar = self .query_one ("#status-bar" )
615+ if hasattr (status_bar , "reset_token_usage" ):
616+ status_bar .reset_token_usage ()
617+ except Exception :
618+ pass
594619
595- self .run_worker ( do_clear () )
620+ self .notify ( "History cleared" )
596621
597622 # -------------------------------------------------------------------------
598623 # Event Handlers
@@ -619,26 +644,24 @@ def on_click(self, event) -> None:
619644 except Exception :
620645 pass # History search may not be mounted yet
621646
622- # Focus input when clicking on empty areas (history viewport background)
623647 try :
624648 history_vp = self .query_one ("#history" , HistoryViewport )
625649 input_ctrl = self .query_one ("#input" , InputController )
626650
627- # Check if click is in history viewport area
628651 if history_vp .region .contains (event .x , event .y ):
629- # Check if we clicked on actual content or empty space
630- # by seeing if any block contains the click point
631- clicked_on_block = False
652+ clicked_on_focusable = False
632653 for block in history_vp .query (BaseBlockWidget ):
633654 if block .region .contains (event .x , event .y ):
634- clicked_on_block = True
655+ for focusable in block .query ("Button, Input, TextArea" ):
656+ if focusable .region .contains (event .x , event .y ):
657+ clicked_on_focusable = True
658+ break
635659 break
636660
637- # If clicked on empty space, focus input
638- if not clicked_on_block :
661+ if not clicked_on_focusable :
639662 input_ctrl .focus ()
640663 except Exception :
641- pass # Widgets may not be mounted yet
664+ pass
642665
643666 async def on_input_controller_submitted (self , message : InputController .Submitted ):
644667 """Handle input submission."""
0 commit comments