Skip to content

Commit fdfb178

Browse files
committed
feat: update logic
1 parent 0a6733a commit fdfb178

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

lib/msgfmt/message_box.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,25 +102,25 @@ func removeAmpMessageBox(msg string) string {
102102
}
103103

104104
func 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")

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +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-
54
● Now I'll create a complete snake game with HTML, CSS, and
65
JavaScript:
76

@@ -20,8 +19,6 @@
2019
padding: 0;
2120
… +334 lines (ctrl+o to expand)
2221

23-
24-
2522
● I've built a complete snake game for you! The game is saved
2623
at /home/coder/snake-game.html.
2724

0 commit comments

Comments
 (0)