|
10 | 10 | PipelineStep,
|
11 | 11 | )
|
12 | 12 | from codegate.pipeline.cli.commands import CustomInstructions, Version, Workspace
|
| 13 | +from codegate.utils.utils import get_tool_name_from_messages |
13 | 14 |
|
14 | 15 | HELP_TEXT = """
|
15 | 16 | ## CodeGate CLI\n
|
@@ -77,27 +78,52 @@ async def process(
|
77 | 78 |
|
78 | 79 | if last_user_message is not None:
|
79 | 80 | 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" |
92 |
| - ) |
93 |
| - return PipelineResult( |
94 |
| - response=PipelineResponse( |
95 |
| - step_name=self.name, |
96 |
| - content=cmd_out, |
97 |
| - model=request["model"], |
98 |
| - ), |
99 |
| - context=context, |
| 81 | + last_user_message_str = last_user_message_str.strip() |
| 82 | + base_tool = get_tool_name_from_messages(request) |
| 83 | + codegate_regex = re.compile(r"^codegate(?:\s+(.*))?", re.IGNORECASE) |
| 84 | + |
| 85 | + if base_tool and base_tool == "cline": |
| 86 | + # Check if there are <task> or <feedback> tags |
| 87 | + tag_match = re.search( |
| 88 | + r"<(task|feedback)>(.*?)</\1>", last_user_message_str, re.DOTALL |
100 | 89 | )
|
| 90 | + if tag_match: |
| 91 | + # Extract the content between the tags |
| 92 | + stripped_message = tag_match.group(2).strip() |
| 93 | + else: |
| 94 | + # If no <task> or <feedback> tags, use the entire message |
| 95 | + stripped_message = last_user_message_str.strip() |
| 96 | + |
| 97 | + # Remove all other XML tags and trim whitespace |
| 98 | + stripped_message = re.sub(r"<[^>]+>", "", stripped_message).strip() |
| 99 | + |
| 100 | + # Check if "codegate" is the first word |
| 101 | + match = codegate_regex.match(stripped_message) |
| 102 | + else: |
| 103 | + # Check if "codegate" is the first word in the message |
| 104 | + match = codegate_regex.match(last_user_message_str) |
| 105 | + if match: |
| 106 | + command = match.group(1) or "" |
| 107 | + command = command.strip() |
| 108 | + |
| 109 | + # Process the command |
| 110 | + args = shlex.split(f"codegate {command}") |
| 111 | + if args: |
| 112 | + context.shortcut_response = True |
| 113 | + cmd_out = await codegate_cli(args[1:]) |
| 114 | + if base_tool and base_tool == "cline": |
| 115 | + cmd_out = ( |
| 116 | + f"<attempt_completion><result>{cmd_out}</result></attempt_completion>\n" |
| 117 | + ) |
| 118 | + |
| 119 | + return PipelineResult( |
| 120 | + response=PipelineResponse( |
| 121 | + step_name=self.name, |
| 122 | + content=cmd_out, |
| 123 | + model=request["model"], |
| 124 | + ), |
| 125 | + context=context, |
| 126 | + ) |
101 | 127 |
|
102 | 128 | # Fall through
|
103 | 129 | return PipelineResult(request=request, context=context)
|
0 commit comments