INNER CODE UNIT · Python
_get_cli_from_cline
stacklok/codegate · src/codegate/pipeline/cli/cli.py:51
def _get_cli_from_cline(
codegate_regex: re.Pattern[str], last_user_message_str: str
) -> Optional[re.Match[str]]:
# Check if there are <task> or <feedback> tags
tag_match = re.search(r"<(task|feedback)>(.*?)</\1>", last_user_message_str, re.DOTALL)
if tag_match:
# Extract the content between the tags
stripped_message = tag_match.group(2).strip()
else:
# If no <task> or <feedback> tags, use the entire message
stripped_message = last_user_message_str.strip()
# Remove all other XML tags and trim whitespace
stripped_message = re.sub(r"<[^>]+>", "", stripped_message).strip()
# Check if "codegate" is the first word
match = codegate_regex.match(stripped_message)