@@ -125,6 +125,68 @@ func removeCodexReportTaskToolCall(msg string) (string, []string) {
125125 return strings .TrimRight (strings .Join (lines , "\n " ), "\n " ), toolCallMessages
126126}
127127
128+ func removeCopilotReportTaskToolCall (msg string ) (string , []string ) {
129+ msg = "\n " + msg // This handles the case where the message starts with a tool call
130+
131+ // Remove all tool calls that start with `● coder_report_task:`
132+ lines := strings .Split (msg , "\n " )
133+
134+ toolCallStartIdx := - 1
135+ newLineAfterToolCall := - 1
136+
137+ // Store all tool call start and end indices [[start, end], ...]
138+ var toolCallIdxs []toolCallRange
139+
140+ for i := 0 ; i < len (lines ); i ++ {
141+ line := strings .Trim (strings .TrimSpace (lines [i ]), "\n " )
142+
143+ if strings .Contains (line , "● coder_report_task:" ) {
144+ toolCallStartIdx = i
145+ } else if toolCallStartIdx != - 1 {
146+ if strings .Contains (line , "{\" message\" :\" Thanks for reporting!\" }" ) {
147+ // Store [start, end] pair
148+ toolCallIdxs = append (toolCallIdxs , toolCallRange {toolCallStartIdx , min (len (lines ), i + 2 ), false })
149+
150+ // Reset to find the next tool call
151+ toolCallStartIdx = - 1
152+ newLineAfterToolCall = - 1
153+ } else if len (line ) == 0 {
154+ newLineAfterToolCall = i + 1
155+ }
156+ }
157+ }
158+
159+ // Handle the malformed/partially rendered tool_calls
160+ // Note: This case has not yet been observed in Copilot
161+ if toolCallStartIdx != - 1 {
162+ if newLineAfterToolCall != - 1 {
163+ toolCallIdxs = append (toolCallIdxs , toolCallRange {toolCallStartIdx , newLineAfterToolCall , true })
164+ } else {
165+ toolCallIdxs = append (toolCallIdxs , toolCallRange {toolCallStartIdx , len (lines ), true })
166+ }
167+ }
168+
169+ // If no tool calls found, return original message
170+ if len (toolCallIdxs ) == 0 {
171+ return strings .TrimLeft (msg , "\n " ), []string {}
172+ }
173+
174+ toolCallMessages := make ([]string , 0 )
175+
176+ // Remove tool calls from the message
177+ for i := len (toolCallIdxs ) - 1 ; i >= 0 ; i -- {
178+ start , end := toolCallIdxs [i ].start , toolCallIdxs [i ].end
179+
180+ // If the toolCall is malformed, we don't want to log it
181+ if ! toolCallIdxs [i ].malformed {
182+ toolCallMessages = append (toolCallMessages , strings .Join (lines [start :end ], "\n " ))
183+ }
184+
185+ lines = append (lines [:start ], lines [end :]... )
186+ }
187+ return strings .TrimLeft (strings .Join (lines , "\n " ), "\n " ), toolCallMessages
188+ }
189+
128190func FormatToolCall (agentType AgentType , message string ) (string , []string ) {
129191 switch agentType {
130192 case AgentTypeClaude :
@@ -138,7 +200,7 @@ func FormatToolCall(agentType AgentType, message string) (string, []string) {
138200 case AgentTypeGemini :
139201 return message , []string {}
140202 case AgentTypeCopilot :
141- return message , [] string {}
203+ return removeCopilotReportTaskToolCall ( message )
142204 case AgentTypeAmp :
143205 return message , []string {}
144206 case AgentTypeCursor :
0 commit comments