|
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 |
@@ -78,35 +79,38 @@ async def process( |
78 | 79 | if last_user_message is not None: |
79 | 80 | last_user_message_str, _ = last_user_message |
80 | 81 | last_user_message_str = last_user_message_str.strip() |
81 | | - is_cline_client = any( |
82 | | - "Cline" in str(message.get("content", "")) |
83 | | - for message in request.get("messages", []) |
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) |
| 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 |
| 89 | + ) |
| 90 | + if tag_match: |
| 91 | + # Extract the content between the tags |
| 92 | + stripped_message = tag_match.group(2).strip() |
98 | 93 | else: |
99 | | - match = None |
| 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) |
100 | 105 | if match: |
101 | | - command = match.group(1) # Extract the second word |
| 106 | + command = match.group(1) or "" |
102 | 107 | command = command.strip() |
103 | 108 |
|
104 | 109 | # Process the command |
105 | 110 | args = shlex.split(f"codegate {command}") |
106 | 111 | if args: |
107 | 112 | cmd_out = await codegate_cli(args[1:]) |
108 | | - |
109 | | - if is_cline_client: |
| 113 | + if base_tool and base_tool == "cline": |
110 | 114 | cmd_out = ( |
111 | 115 | f"<attempt_completion><result>{cmd_out}</result></attempt_completion>\n" |
112 | 116 | ) |
|
0 commit comments