Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Strip attachments from copilot messages when handling the CLI commands #1202

Merged
merged 1 commit into from
Mar 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/codegate/pipeline/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,25 @@ def _get_cli_from_continue(last_user_message_str: str) -> Optional[re.Match[str]
return codegate_regex.match(last_user_message_str)


def _get_cli_from_copilot(last_user_message_str: str) -> Optional[re.Match[str]]:
"""
Process Copilot-specific CLI command format.

Copilot sends messages in the format:
<attachment>file contents</attachment>codegate command

Args:
last_user_message_str (str): The message string from Copilot

Returns:
Optional[re.Match[str]]: A regex match object if command is found, None otherwise
"""
cleaned_text = re.sub(
r"<attachment>.*</attachment>", "", last_user_message_str, flags=re.DOTALL
)
return codegate_regex.match(cleaned_text.strip())


class CodegateCli(PipelineStep):
"""Pipeline step that handles codegate cli."""

Expand Down Expand Up @@ -136,6 +155,8 @@ async def process(
match = _get_cli_from_open_interpreter(last_user_message_str)
elif context.client in [ClientType.CONTINUE]:
match = _get_cli_from_continue(last_user_message_str)
elif context.client in [ClientType.COPILOT]:
match = _get_cli_from_copilot(last_user_message_str)
else:
# Check if "codegate" is the first word in the message
match = codegate_regex.match(last_user_message_str)
Expand Down