Skip to content

Commit 2259907

Browse files
committed
feat(copilot): enhance message formatting by removing copilot footer and trimming empty lines
1 parent 1ead6cc commit 2259907

8 files changed

Lines changed: 30 additions & 15 deletions

File tree

lib/msgfmt/format_tool_call.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ func removeCopilotReportTaskToolCall(msg string) (string, []string) {
184184

185185
lines = append(lines[:start], lines[end:]...)
186186
}
187-
return strings.TrimLeft(strings.Join(lines, "\n"), "\n"), toolCallMessages
187+
return strings.Trim(strings.Join(lines, "\n"), "\n"), toolCallMessages
188188
}
189189

190190
func FormatToolCall(agentType AgentType, message string) (string, []string) {

lib/msgfmt/message_box.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,19 @@ func removeAmpMessageBox(msg string) string {
113113
}
114114
return formattedMsg
115115
}
116+
117+
func removeCopilotFooter(msg string) string {
118+
lines := strings.Split(msg, "\n")
119+
120+
firstEmptyLine := 0
121+
122+
// From the end strip until we discover an empty line
123+
for i := len(lines) - 1; i >= 0; i-- {
124+
if len(strings.TrimSpace(lines[i])) == 0 {
125+
firstEmptyLine = i
126+
break
127+
}
128+
}
129+
130+
return strings.Join(lines[:firstEmptyLine], "\n")
131+
}

lib/msgfmt/msgfmt.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,14 @@ func formatGenericMessage(message string, userInput string, agentType AgentType)
254254
return message
255255
}
256256

257+
func formatCopilotMessage(message string, userInput string) string {
258+
message = RemoveUserInput(message, userInput, AgentTypeCopilot)
259+
message = removeMessageBox(message)
260+
message = removeCopilotFooter(message)
261+
message = trimEmptyLines(message)
262+
return message
263+
}
264+
257265
func formatCodexMessage(message string, userInput string) string {
258266
message = RemoveUserInput(message, userInput, AgentTypeCodex)
259267
message = removeCodexMessageBox(message)
@@ -288,7 +296,7 @@ func FormatAgentMessage(agentType AgentType, message string, userInput string) s
288296
case AgentTypeGemini:
289297
return formatGenericMessage(message, userInput, agentType)
290298
case AgentTypeCopilot:
291-
return formatGenericMessage(message, userInput, agentType)
299+
return formatCopilotMessage(message, userInput)
292300
case AgentTypeAmp:
293301
return formatAmpMessage(message, userInput)
294302
case AgentTypeCursor:

lib/msgfmt/testdata/format/copilot/first_message/expected.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@
66

77
● Logged in with gh as user: 35C4n0r
88

9-
● Connected to GitHub MCP Server
10-
11-
~/Documents/work/.../agentapi [⎇ main*] claude-haiku-4.5 (1x)
9+
● Connected to GitHub MCP Server

lib/msgfmt/testdata/format/copilot/multi-line-input/expected.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,4 @@
104104
uses Server-Sent Events (SSE) for real-time communication instead of polling, as
105105
seen in the chat/src/components/chat-provider.tsx file where an EventSource
106106
connection is established to listen for message updates and status changes from
107-
the server.
108-
109-
~/Documents/work/agentapi [⎇ feat-github-cli*]
107+
the server.

lib/msgfmt/testdata/format/copilot/remove-task-tool-call/expected.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,4 @@
107107
- ✓ Game initializes and runs successfully
108108
- ✓ Pygame installed and configured
109109

110-
Ready to play! 🐍
111-
112-
~/projects claude-haiku-4.5 (1x)
110+
Ready to play! 🐍

lib/msgfmt/testdata/format/copilot/remove-task-tool-call/expected_tool_calls.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
● coder_report_task: Last Call
22
└ {"message":"Thanks for reporting!"}
3-
43
---
54
● coder_report_task: Snake game built and verified - all tests
65
passing, game runs successfully

lib/msgfmt/testdata/format/copilot/thinking/expected.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,4 @@
44
$ find . -type f -name "*.ts" -o -name "*.tsx" -o -name "*.js" -o -name "*.jsx" | xargs grep -l "useEffect.*checkServerStatus\|Set up polling for messages and server status" 2>/dev/null
55
↪ 1 line...
66

7-
◉ Thinking (Esc to cancel)
8-
9-
~/Documents/work/.../agentapi [⎇ main*] claude-haiku-4.5 (1x)
7+
◉ Thinking (Esc to cancel)

0 commit comments

Comments
 (0)