@@ -20,6 +20,7 @@ use crate::state::{Mode, UIState};
2020// Event type constants moved to UI layer
2121pub const EVENT_USER_TASK_INIT : & str = "user_task_init" ;
2222pub const EVENT_USER_TASK_UPDATE : & str = "user_task_update" ;
23+ pub const EVENT_USER_HELP_QUERY : & str = "user_help_query" ;
2324pub const EVENT_TITLE : & str = "title" ;
2425
2526lazy_static ! {
@@ -43,21 +44,28 @@ impl<F: API> UI<F> {
4344 self . state . mode = mode;
4445
4546 // Show message that mode changed
46- let mode = self . state . mode . to_string ( ) ;
47+ let mode_str = self . state . mode . to_string ( ) ;
4748
4849 // Set the mode variable in the conversation if a conversation exists
4950 let conversation_id = self . init_conversation ( ) . await ?;
5051 self . api
5152 . set_variable (
5253 & conversation_id,
5354 "mode" . to_string ( ) ,
54- Value :: from ( mode . as_str ( ) ) ,
55+ Value :: from ( mode_str . as_str ( ) ) ,
5556 )
5657 . await ?;
5758
59+ // Print a mode-specific message
60+ let mode_message = match self . state . mode {
61+ Mode :: Act => "mode - executes commands and makes file changes" ,
62+ Mode :: Plan => "mode - plans actions without making changes" ,
63+ Mode :: Help => "mode - answers questions (type /act or /plan to switch back)" ,
64+ } ;
65+
5866 CONSOLE . write (
59- TitleFormat :: success ( & mode )
60- . sub_title ( "mode activated" )
67+ TitleFormat :: success ( & mode_str )
68+ . sub_title ( mode_message )
6169 . format ( ) ,
6270 ) ?;
6371
@@ -71,6 +79,9 @@ impl<F: API> UI<F> {
7179 fn create_task_update_event ( content : impl ToString ) -> Event {
7280 Event :: new ( EVENT_USER_TASK_UPDATE , content)
7381 }
82+ fn create_user_help_query_event ( content : impl ToString ) -> Event {
83+ Event :: new ( EVENT_USER_HELP_QUERY , content)
84+ }
7485
7586 pub fn init ( cli : Cli , api : Arc < F > ) -> Result < Self > {
7687 // Parse CLI arguments first to get flags
@@ -129,7 +140,10 @@ impl<F: API> UI<F> {
129140 continue ;
130141 }
131142 Command :: Message ( ref content) => {
132- let chat_result = self . chat ( content. clone ( ) ) . await ;
143+ let chat_result = match self . state . mode {
144+ Mode :: Help => self . help_chat ( content. clone ( ) ) . await ,
145+ _ => self . chat ( content. clone ( ) ) . await ,
146+ } ;
133147 if let Err ( err) = chat_result {
134148 CONSOLE . writeln ( TitleFormat :: failed ( format ! ( "{:?}" , err) ) . format ( ) ) ?;
135149 }
@@ -150,6 +164,13 @@ impl<F: API> UI<F> {
150164 input = self . console . prompt ( prompt_input) . await ?;
151165 continue ;
152166 }
167+ Command :: Help => {
168+ self . handle_mode_change ( Mode :: Help ) . await ?;
169+
170+ let prompt_input = Some ( ( & self . state ) . into ( ) ) ;
171+ input = self . console . prompt ( prompt_input) . await ?;
172+ continue ;
173+ }
153174 Command :: Exit => {
154175 break ;
155176 }
@@ -311,5 +332,21 @@ impl<F: API> UI<F> {
311332 }
312333 }
313334 Ok ( ( ) )
335+ } // Handle help chat in HELP mode
336+ async fn help_chat ( & mut self , content : String ) -> Result < ( ) > {
337+ let conversation_id = self . init_conversation ( ) . await ?;
338+
339+ // Create a help query event
340+ let event = Self :: create_user_help_query_event ( content. clone ( ) ) ;
341+
342+ // Create the chat request with the help query event
343+ let chat = ChatRequest :: new ( event, conversation_id) ;
344+
345+ tokio:: spawn ( TRACKER . dispatch ( EventKind :: Prompt ( content) ) ) ;
346+
347+ match self . api . chat ( chat) . await {
348+ Ok ( mut stream) => self . handle_chat_stream ( & mut stream) . await ,
349+ Err ( err) => Err ( err) ,
350+ }
314351 }
315352}
0 commit comments