@@ -77,27 +77,47 @@ async def process(
7777
7878 if last_user_message is not None :
7979 last_user_message_str , _ = last_user_message
80- cleaned_message_str = re .sub (r"<.*?>" , "" , last_user_message_str ).strip ()
81- splitted_message = cleaned_message_str .lower ().split (" " )
82- # We expect codegate as the first word in the message
83- if splitted_message [0 ] == "codegate" :
84- context .shortcut_response = True
85- args = shlex .split (cleaned_message_str )
86- cmd_out = await codegate_cli (args [1 :])
87-
88- if cleaned_message_str != last_user_message_str :
89- # it came from Cline, need to wrap into tags
90- cmd_out = (
91- f"<attempt_completion><result>{ cmd_out } </result></attempt_completion>\n "
80+ last_user_message_str = last_user_message_str .strip ()
81+ is_cline_client = any (
82+ "Cline" in str (message .get ("content" , "" )) for message in request .get ("messages" ,
83+ [])
84+ )
85+ if not is_cline_client :
86+ # Check if "codegate" is the first word in the message
87+ match = re .match (r"^codegate(?:\s+(\S+))?" , last_user_message_str , re .IGNORECASE )
88+ else :
89+ # Check if "codegate" is the first word after the first XML tag
90+ xml_start = re .search (r"<[^>]+>" , last_user_message_str )
91+ if xml_start :
92+ # Start processing only from the first XML tag
93+ relevant_message = last_user_message_str [xml_start .start ():]
94+ # Remove all XML tags and trim whitespace
95+ stripped_message = re .sub (r"<[^>]+>" , "" , relevant_message ).strip ()
96+ # Check if "codegate" is the first word
97+ match = re .match (r"^codegate(?:\s+(\S+))?" , stripped_message , re .IGNORECASE )
98+ else :
99+ match = None
100+ if match :
101+ command = match .group (1 ) # Extract the second word
102+ command = command .strip ()
103+
104+ # Process the command
105+ args = shlex .split (f"codegate { command } " )
106+ if args :
107+ cmd_out = await codegate_cli (args [1 :])
108+
109+ if is_cline_client :
110+ cmd_out = (
111+ f"<attempt_completion><result>{ cmd_out } </result></attempt_completion>\n "
112+ )
113+ return PipelineResult (
114+ response = PipelineResponse (
115+ step_name = self .name ,
116+ content = cmd_out ,
117+ model = request ["model" ],
118+ ),
119+ context = context ,
92120 )
93- return PipelineResult (
94- response = PipelineResponse (
95- step_name = self .name ,
96- content = cmd_out ,
97- model = request ["model" ],
98- ),
99- context = context ,
100- )
101121
102122 # Fall through
103123 return PipelineResult (request = request , context = context )
0 commit comments