Skip to content

Commit f7a2863

Browse files
committed
wip
1 parent 9a6bb43 commit f7a2863

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

lib/msgfmt/message_box.go

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,24 +102,38 @@ func removeAmpMessageBox(msg string) string {
102102
}
103103

104104
func 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
}

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
● I'll build a snake game for you. Let me start by reporting my
22
progress and creating a task list.
33

4-
● coder - coder_report_task (MCP)(summary: "Building a snake game
5-
with HTML/CSS/JavaScript", link:
6-
"", state: "working")
7-
⎿ {
8-
"message": "Thanks for reporting!"
9-
}
104

115
● Now I'll create a complete snake game with HTML, CSS, and
126
JavaScript:

0 commit comments

Comments
 (0)