@@ -102,25 +102,25 @@ func removeAmpMessageBox(msg string) string {
102102}
103103
104104func removeClaudeReportTaskToolCall (msg string ) string {
105- // Remove all tool calls that start with `● coder - coder_report_task (MCP)` and end with `}`
105+ // Remove all tool calls that start with `● coder - coder_report_task (MCP)` till we encounter the next line starting with ●
106106 lines := strings .Split (msg , "\n " )
107- toolCallEndIdx := - 1
107+
108+ toolCallStartIdx := - 1
108109
109110 // Store all tool call start and end indices [[start, end], ...]
110111 var toolCallIdxs [][]int
111112
112- // Iterate backwards to find all occurrences
113- for i := len (lines ) - 1 ; i >= 0 ; i -- {
113+ for i := 0 ; i < len (lines ); i ++ {
114114 line := strings .TrimSpace (lines [i ])
115- if line == "}" {
116- toolCallEndIdx = i
117- }
118- if toolCallEndIdx != - 1 && strings .HasPrefix (line , "● coder - coder_report_task (MCP) " ) {
115+
116+ if strings . HasPrefix ( line , "● coder - coder_report_task (MCP)" ) {
117+ toolCallStartIdx = i
118+ } else if toolCallStartIdx != - 1 && strings .HasPrefix (line , "●" ) {
119119 // Store [start, end] pair
120- toolCallIdxs = append (toolCallIdxs , []int {i , toolCallEndIdx })
120+ toolCallIdxs = append (toolCallIdxs , []int {toolCallStartIdx , i })
121121
122122 // Reset to find the next tool call
123- toolCallEndIdx = - 1
123+ toolCallStartIdx = - 1
124124 }
125125 }
126126
@@ -130,9 +130,10 @@ func removeClaudeReportTaskToolCall(msg string) string {
130130 }
131131
132132 // Remove tool calls from the message
133- for _ , idxPair := range toolCallIdxs {
133+ for i := len (toolCallIdxs ) - 1 ; i >= 0 ; i -- {
134+ idxPair := toolCallIdxs [i ]
134135 start , end := idxPair [0 ], idxPair [1 ]
135- lines = append (lines [:start ], lines [end + 1 :]... )
136+ lines = append (lines [:start ], lines [end :]... )
136137 }
137138
138139 return strings .Join (lines , "\n " )
0 commit comments