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

Commit 08c0111

Browse files
authored
Strip attachments from copilot messages when handling the CLI commands (#1202)
Copilot sends files in the context in the following format: ``` <attachment> file <attachment> user query ``` Fixes: #1061
1 parent 417c3ea commit 08c0111

File tree

1 file changed

+21
-0
lines changed
  • src/codegate/pipeline/cli

1 file changed

+21
-0
lines changed

src/codegate/pipeline/cli/cli.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,25 @@ def _get_cli_from_continue(last_user_message_str: str) -> Optional[re.Match[str]
9595
return codegate_regex.match(last_user_message_str)
9696

9797

98+
def _get_cli_from_copilot(last_user_message_str: str) -> Optional[re.Match[str]]:
99+
"""
100+
Process Copilot-specific CLI command format.
101+
102+
Copilot sends messages in the format:
103+
<attachment>file contents</attachment>codegate command
104+
105+
Args:
106+
last_user_message_str (str): The message string from Copilot
107+
108+
Returns:
109+
Optional[re.Match[str]]: A regex match object if command is found, None otherwise
110+
"""
111+
cleaned_text = re.sub(
112+
r"<attachment>.*</attachment>", "", last_user_message_str, flags=re.DOTALL
113+
)
114+
return codegate_regex.match(cleaned_text.strip())
115+
116+
98117
class CodegateCli(PipelineStep):
99118
"""Pipeline step that handles codegate cli."""
100119

@@ -136,6 +155,8 @@ async def process(
136155
match = _get_cli_from_open_interpreter(last_user_message_str)
137156
elif context.client in [ClientType.CONTINUE]:
138157
match = _get_cli_from_continue(last_user_message_str)
158+
elif context.client in [ClientType.COPILOT]:
159+
match = _get_cli_from_copilot(last_user_message_str)
139160
else:
140161
# Check if "codegate" is the first word in the message
141162
match = codegate_regex.match(last_user_message_str)

0 commit comments

Comments
 (0)