@@ -102,24 +102,38 @@ func removeAmpMessageBox(msg string) string {
102102}
103103
104104func removeClaudeReportTaskToolCall (msg string ) string {
105- // If we encounter a line starting with `● coder - coder_report_task (MCP)` -- to }
105+ // Remove all tool calls that start with `● coder - coder_report_task (MCP)` and end with `}`
106106 lines := strings .Split (msg , "\n " )
107107 toolCallEndIdx := - 1
108- toolCallStartIdx := - 1
108+
109+ // Store all tool call start and end indices [[start, end], ...]
110+ var toolCallIdxs [][]int
111+
112+ // Iterate backwards to find all occurrences
109113 for i := len (lines ) - 1 ; i >= 0 ; i -- {
110114 line := strings .TrimSpace (lines [i ])
111- if line == "}" {
115+ if line == "}" && toolCallEndIdx == - 1 {
112116 toolCallEndIdx = i
113117 }
114118 if toolCallEndIdx != - 1 && strings .HasPrefix (line , "● coder - coder_report_task (MCP)" ) {
115- toolCallStartIdx = i
116- break
119+ // Store [start, end] pair
120+ toolCallIdxs = append (toolCallIdxs , []int {i , toolCallEndIdx })
121+ // Reset to find the next tool call
122+ toolCallEndIdx = - 1
117123 }
118124 }
119- // If we didn't find the marker, return the original message
120- if toolCallEndIdx == - 1 {
125+
126+ // If no tool calls found, return original message
127+ if len (toolCallIdxs ) == 0 {
121128 return msg
122129 }
123- // Remove from the opening brace to the marker line (inclusive)
124- return strings .Join (append (lines [:toolCallStartIdx ], lines [toolCallEndIdx + 1 :]... ), "\n " )
130+
131+ // Remove tool calls in reverse order to preserve indices
132+ // toolCallIdxs is already in reverse order from backwards iteration
133+ for _ , idxPair := range toolCallIdxs {
134+ start , end := idxPair [0 ], idxPair [1 ]
135+ lines = append (lines [:start ], lines [end + 1 :]... )
136+ }
137+
138+ return strings .Join (lines , "\n " )
125139}
0 commit comments