From 3955c3bda1ab3c8324919ddc5f0f687184830568 Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Tue, 16 Dec 2025 14:48:51 +0530 Subject: [PATCH 01/10] feat(tool_call): implement tool call logging and improve format handling --- lib/httpapi/server.go | 6 ++ lib/msgfmt/format_tool_call.go | 58 +++++++++++++++++++ lib/msgfmt/message_box.go | 50 ---------------- lib/msgfmt/msgfmt.go | 16 ++--- lib/msgfmt/msgfmt_test.go | 3 +- .../claude/remove-task-tool-call/expected.txt | 5 +- lib/screentracker/conversation.go | 22 +++++++ 7 files changed, 100 insertions(+), 60 deletions(-) create mode 100644 lib/msgfmt/format_tool_call.go diff --git a/lib/httpapi/server.go b/lib/httpapi/server.go index 18f2bf40..59497873 100644 --- a/lib/httpapi/server.go +++ b/lib/httpapi/server.go @@ -233,6 +233,10 @@ func NewServer(ctx context.Context, config ServerConfig) (*Server, error) { return mf.IsAgentReadyForInitialPrompt(config.AgentType, message) } + formatToolCall := func(message string) (string, []string) { + return mf.FormatToolCall(config.AgentType, message) + } + conversation := st.NewConversation(ctx, st.ConversationConfig{ AgentType: config.AgentType, AgentIO: config.Process, @@ -243,6 +247,8 @@ func NewServer(ctx context.Context, config ServerConfig) (*Server, error) { ScreenStabilityLength: 2 * time.Second, FormatMessage: formatMessage, ReadyForInitialPrompt: isAgentReadyForInitialPrompt, + FormatToolCall: formatToolCall, + Logger: logger, }, config.InitialPrompt) emitter := NewEventEmitter(1024) diff --git a/lib/msgfmt/format_tool_call.go b/lib/msgfmt/format_tool_call.go new file mode 100644 index 00000000..8e204791 --- /dev/null +++ b/lib/msgfmt/format_tool_call.go @@ -0,0 +1,58 @@ +package msgfmt + +import ( + "strings" +) + +func removeClaudeReportTaskToolCall(msg string) (string, []string) { + // Remove all tool calls that start with `● coder - coder_report_task (MCP)` till we encounter the next line starting with ● + lines := strings.Split(msg, "\n") + + toolCallStartIdx := -1 + + // Store all tool call start and end indices [[start, end], ...] + var toolCallIdxs [][]int + + for i := 1; i < len(lines)-1; i++ { + prevLine := strings.TrimSpace(lines[i-1]) + line := strings.TrimSpace(lines[i]) + nextLine := strings.TrimSpace(lines[i+1]) + + if strings.HasPrefix(line, "● coder - coder_report_task (MCP)") { + toolCallStartIdx = i + } else if toolCallStartIdx != -1 && line == "\"message\": \"Thanks for reporting!\"" && nextLine == "}" && strings.Replace(prevLine, " ", "", -1) == "⎿{" { + // Store [start, end] pair + toolCallIdxs = append(toolCallIdxs, []int{toolCallStartIdx, min(len(lines), i+2)}) + + // Reset to find the next tool call + toolCallStartIdx = -1 + } + } + + // If no tool calls found, return original message + if len(toolCallIdxs) == 0 { + return strings.TrimSuffix(msg, "\n"), []string{} + } + + toolCallMessages := make([]string, 0) + + // Remove tool calls from the message + for i := len(toolCallIdxs) - 1; i >= 0; i-- { + idxPair := toolCallIdxs[i] + start, end := idxPair[0], idxPair[1] + + toolCallMessages = append(toolCallMessages, strings.Join(lines[start:end], "\n")) + + lines = append(lines[:start], lines[end:]...) + } + return strings.TrimSuffix(strings.Join(lines, "\n"), "\n\n"), toolCallMessages +} + +func FormatToolCall(agentType AgentType, message string) (string, []string) { + switch agentType { + case AgentTypeClaude: + return removeClaudeReportTaskToolCall(message) + default: + return message, []string{} + } +} diff --git a/lib/msgfmt/message_box.go b/lib/msgfmt/message_box.go index d7370c60..13efaf11 100644 --- a/lib/msgfmt/message_box.go +++ b/lib/msgfmt/message_box.go @@ -100,53 +100,3 @@ func removeAmpMessageBox(msg string) string { } return formattedMsg } - -func removeClaudeReportTaskToolCall(msg string) string { - // Remove all tool calls that start with `● coder - coder_report_task (MCP)` till we encounter the next line starting with ● - lines := strings.Split(msg, "\n") - - toolCallStartIdx := -1 - newLineAfterToolCallIdx := -1 - - // Store all tool call start and end indices [[start, end], ...] - var toolCallIdxs [][]int - - for i := 0; i < len(lines); i++ { - line := strings.TrimSpace(lines[i]) - - if strings.HasPrefix(line, "● coder - coder_report_task (MCP)") { - toolCallStartIdx = i - } else if toolCallStartIdx != -1 && strings.HasPrefix(line, "●") { - // Store [start, end] pair - toolCallIdxs = append(toolCallIdxs, []int{toolCallStartIdx, i}) - - // Reset to find the next tool call - toolCallStartIdx = -1 - newLineAfterToolCallIdx = -1 - } - if len(line) == 0 && toolCallStartIdx != -1 && newLineAfterToolCallIdx == -1 { - newLineAfterToolCallIdx = i - } - } - - // Handle the case where the last tool call goes till the end of the message - // And a failsafe when the next message is not prefixed with ● - if toolCallStartIdx != -1 && newLineAfterToolCallIdx != -1 { - toolCallIdxs = append(toolCallIdxs, []int{toolCallStartIdx, newLineAfterToolCallIdx}) - } - - // If no tool calls found, return original message - if len(toolCallIdxs) == 0 { - return msg - } - - // Remove tool calls from the message - for i := len(toolCallIdxs) - 1; i >= 0; i-- { - idxPair := toolCallIdxs[i] - start, end := idxPair[0], idxPair[1] - - lines = append(lines[:start], lines[end:]...) - } - - return strings.Join(lines, "\n") -} diff --git a/lib/msgfmt/msgfmt.go b/lib/msgfmt/msgfmt.go index 975dc7f6..d6ac7c07 100644 --- a/lib/msgfmt/msgfmt.go +++ b/lib/msgfmt/msgfmt.go @@ -254,13 +254,13 @@ func formatGenericMessage(message string, userInput string, agentType AgentType) return message } -func formatClaudeMessage(message string, userInput string) string { - message = RemoveUserInput(message, userInput, AgentTypeClaude) - message = removeMessageBox(message) - message = removeClaudeReportTaskToolCall(message) - message = trimEmptyLines(message) - return message -} +//func formatClaudeMessage(message string, userInput string) string { +// message = RemoveUserInput(message, userInput, AgentTypeClaude) +// message = removeMessageBox(message) +// message = removeClaudeReportTaskToolCall(message) +// message = trimEmptyLines(message) +// return message +//} func formatCodexMessage(message string, userInput string) string { message = RemoveUserInput(message, userInput, AgentTypeCodex) @@ -286,7 +286,7 @@ func formatAmpMessage(message string, userInput string) string { func FormatAgentMessage(agentType AgentType, message string, userInput string) string { switch agentType { case AgentTypeClaude: - return formatClaudeMessage(message, userInput) + return formatGenericMessage(message, userInput, agentType) case AgentTypeGoose: return formatGenericMessage(message, userInput, agentType) case AgentTypeAider: diff --git a/lib/msgfmt/msgfmt_test.go b/lib/msgfmt/msgfmt_test.go index 780a3954..37c3d6a2 100644 --- a/lib/msgfmt/msgfmt_test.go +++ b/lib/msgfmt/msgfmt_test.go @@ -233,7 +233,8 @@ func TestFormatAgentMessage(t *testing.T) { assert.NoError(t, err) expected, err := testdataDir.ReadFile(path.Join(dir, string(agentType), c.Name(), "expected.txt")) assert.NoError(t, err) - assert.Equal(t, string(expected), FormatAgentMessage(agentType, string(msg), string(userInput))) + output, _ := FormatToolCall(agentType, FormatAgentMessage(agentType, string(msg), string(userInput))) + assert.Equal(t, string(expected), output) }) } }) diff --git a/lib/msgfmt/testdata/format/claude/remove-task-tool-call/expected.txt b/lib/msgfmt/testdata/format/claude/remove-task-tool-call/expected.txt index f06f58f6..caef0663 100644 --- a/lib/msgfmt/testdata/format/claude/remove-task-tool-call/expected.txt +++ b/lib/msgfmt/testdata/format/claude/remove-task-tool-call/expected.txt @@ -1,6 +1,7 @@ ● I'll build a snake game for you. Let me start by reporting my progress and creating a task list. + ● Now I'll create a complete snake game with HTML, CSS, and JavaScript: @@ -19,6 +20,8 @@ padding: 0; … +334 lines (ctrl+o to expand) + + ● I've built a complete snake game for you! The game is saved at /home/coder/snake-game.html. @@ -36,4 +39,4 @@ How to play: Open the HTML file in your web browser and use the arrow keys to move the snake. Collect the red food to grow and increase - your score! \ No newline at end of file + your score! diff --git a/lib/screentracker/conversation.go b/lib/screentracker/conversation.go index 043f4409..8de11047 100644 --- a/lib/screentracker/conversation.go +++ b/lib/screentracker/conversation.go @@ -3,6 +3,7 @@ package screentracker import ( "context" "fmt" + "log/slog" "strings" "sync" "time" @@ -43,6 +44,9 @@ type ConversationConfig struct { SkipSendMessageStatusCheck bool // ReadyForInitialPrompt detects whether the agent has initialized and is ready to accept the initial prompt ReadyForInitialPrompt func(message string) bool + FormatToolCall func(message string) (string, []string) + // Logger for logging tool calls and other events + Logger *slog.Logger } type ConversationRole string @@ -82,6 +86,8 @@ type Conversation struct { InitialPromptSent bool // ReadyForInitialPrompt keeps track if the agent is ready to accept the initial prompt ReadyForInitialPrompt bool + // + toolCallMessageSet map[string]bool } type ConversationStatus string @@ -205,9 +211,18 @@ func (c *Conversation) lastMessage(role ConversationRole) ConversationMessage { func (c *Conversation) updateLastAgentMessage(screen string, timestamp time.Time) { agentMessage := FindNewMessage(c.screenBeforeLastUserMessage, screen, c.cfg.AgentType) lastUserMessage := c.lastMessage(ConversationRoleUser) + var toolCalls []string if c.cfg.FormatMessage != nil { agentMessage = c.cfg.FormatMessage(agentMessage, lastUserMessage.Message) } + if c.cfg.FormatToolCall != nil { + agentMessage, toolCalls = c.cfg.FormatToolCall(agentMessage) + } + for _, toolCall := range toolCalls { + if c.toolCallMessageSet[toolCall] == false { + c.toolCallMessageSet[toolCall] = true + } + } shouldCreateNewMessage := len(c.messages) == 0 || c.messages[len(c.messages)-1].Role == ConversationRoleUser lastAgentMessage := c.lastMessage(ConversationRoleAgent) if lastAgentMessage.Message == agentMessage { @@ -220,6 +235,13 @@ func (c *Conversation) updateLastAgentMessage(screen string, timestamp time.Time } if shouldCreateNewMessage { c.messages = append(c.messages, conversationMessage) + // Logging all the tool calls till now + for toolCall := range c.toolCallMessageSet { + c.cfg.Logger.Info("Tool call detected", "toolCall", toolCall) + } + // Cleanup + c.toolCallMessageSet = make(map[string]bool) + } else { c.messages[len(c.messages)-1] = conversationMessage } From 8fb27f6e98c0a948278c1d2c05284e59d208a2f6 Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Tue, 16 Dec 2025 15:18:46 +0530 Subject: [PATCH 02/10] wip --- lib/msgfmt/format_tool_call.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/msgfmt/format_tool_call.go b/lib/msgfmt/format_tool_call.go index 8e204791..f71f1ffd 100644 --- a/lib/msgfmt/format_tool_call.go +++ b/lib/msgfmt/format_tool_call.go @@ -1,6 +1,7 @@ package msgfmt import ( + "fmt" "strings" ) @@ -29,6 +30,8 @@ func removeClaudeReportTaskToolCall(msg string) (string, []string) { } } + fmt.Println("ToolCallIdxs:", toolCallIdxs) + // If no tool calls found, return original message if len(toolCallIdxs) == 0 { return strings.TrimSuffix(msg, "\n"), []string{} @@ -45,7 +48,7 @@ func removeClaudeReportTaskToolCall(msg string) (string, []string) { lines = append(lines[:start], lines[end:]...) } - return strings.TrimSuffix(strings.Join(lines, "\n"), "\n\n"), toolCallMessages + return strings.Join(lines, "\n"), toolCallMessages } func FormatToolCall(agentType AgentType, message string) (string, []string) { From b39e96ef052d7ccedf02954203f566adeb3e29be Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Tue, 16 Dec 2025 16:56:05 +0530 Subject: [PATCH 03/10] wip --- lib/msgfmt/format_tool_call.go | 3 --- lib/screentracker/conversation.go | 5 +++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/msgfmt/format_tool_call.go b/lib/msgfmt/format_tool_call.go index f71f1ffd..dde811a4 100644 --- a/lib/msgfmt/format_tool_call.go +++ b/lib/msgfmt/format_tool_call.go @@ -1,7 +1,6 @@ package msgfmt import ( - "fmt" "strings" ) @@ -30,8 +29,6 @@ func removeClaudeReportTaskToolCall(msg string) (string, []string) { } } - fmt.Println("ToolCallIdxs:", toolCallIdxs) - // If no tool calls found, return original message if len(toolCallIdxs) == 0 { return strings.TrimSuffix(msg, "\n"), []string{} diff --git a/lib/screentracker/conversation.go b/lib/screentracker/conversation.go index 8de11047..29984cb7 100644 --- a/lib/screentracker/conversation.go +++ b/lib/screentracker/conversation.go @@ -121,8 +121,9 @@ func NewConversation(ctx context.Context, cfg ConversationConfig, initialPrompt Time: cfg.GetTime(), }, }, - InitialPrompt: initialPrompt, - InitialPromptSent: len(initialPrompt) == 0, + InitialPrompt: initialPrompt, + InitialPromptSent: len(initialPrompt) == 0, + toolCallMessageSet: make(map[string]bool), } return c } From d0672b276ad9bd5ca0eba1944b15cea79b372cd6 Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Tue, 16 Dec 2025 17:00:37 +0530 Subject: [PATCH 04/10] wip --- lib/msgfmt/format_tool_call.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/msgfmt/format_tool_call.go b/lib/msgfmt/format_tool_call.go index dde811a4..7f73e9a8 100644 --- a/lib/msgfmt/format_tool_call.go +++ b/lib/msgfmt/format_tool_call.go @@ -18,7 +18,7 @@ func removeClaudeReportTaskToolCall(msg string) (string, []string) { line := strings.TrimSpace(lines[i]) nextLine := strings.TrimSpace(lines[i+1]) - if strings.HasPrefix(line, "● coder - coder_report_task (MCP)") { + if strings.HasPrefix(prevLine, "● coder - coder_report_task (MCP)") { toolCallStartIdx = i } else if toolCallStartIdx != -1 && line == "\"message\": \"Thanks for reporting!\"" && nextLine == "}" && strings.Replace(prevLine, " ", "", -1) == "⎿{" { // Store [start, end] pair From b4e2dfe6bb01cfa23b1a76d9be8dabe906950b8c Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Tue, 16 Dec 2025 17:04:01 +0530 Subject: [PATCH 05/10] wip --- lib/msgfmt/format_tool_call.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/msgfmt/format_tool_call.go b/lib/msgfmt/format_tool_call.go index 7f73e9a8..f0ba79d6 100644 --- a/lib/msgfmt/format_tool_call.go +++ b/lib/msgfmt/format_tool_call.go @@ -18,7 +18,7 @@ func removeClaudeReportTaskToolCall(msg string) (string, []string) { line := strings.TrimSpace(lines[i]) nextLine := strings.TrimSpace(lines[i+1]) - if strings.HasPrefix(prevLine, "● coder - coder_report_task (MCP)") { + if strings.Contains(prevLine, "coder - coder_report_task (MCP)") { toolCallStartIdx = i } else if toolCallStartIdx != -1 && line == "\"message\": \"Thanks for reporting!\"" && nextLine == "}" && strings.Replace(prevLine, " ", "", -1) == "⎿{" { // Store [start, end] pair From 3ba427e843205d8c561bf2fdd5a26ef2c6eec3c9 Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Tue, 16 Dec 2025 17:06:09 +0530 Subject: [PATCH 06/10] wip --- lib/msgfmt/format_tool_call.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/msgfmt/format_tool_call.go b/lib/msgfmt/format_tool_call.go index f0ba79d6..079ffa21 100644 --- a/lib/msgfmt/format_tool_call.go +++ b/lib/msgfmt/format_tool_call.go @@ -19,7 +19,7 @@ func removeClaudeReportTaskToolCall(msg string) (string, []string) { nextLine := strings.TrimSpace(lines[i+1]) if strings.Contains(prevLine, "coder - coder_report_task (MCP)") { - toolCallStartIdx = i + toolCallStartIdx = i - 1 } else if toolCallStartIdx != -1 && line == "\"message\": \"Thanks for reporting!\"" && nextLine == "}" && strings.Replace(prevLine, " ", "", -1) == "⎿{" { // Store [start, end] pair toolCallIdxs = append(toolCallIdxs, []int{toolCallStartIdx, min(len(lines), i+2)}) From 7d6fb4f1b03f990c3956c5194788e5d449799066 Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Tue, 16 Dec 2025 18:31:54 +0530 Subject: [PATCH 07/10] wip --- lib/msgfmt/format_tool_call.go | 12 +++++++----- .../format/claude/remove-task-tool-call/msg.txt | 8 ++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/msgfmt/format_tool_call.go b/lib/msgfmt/format_tool_call.go index 079ffa21..c8c1950d 100644 --- a/lib/msgfmt/format_tool_call.go +++ b/lib/msgfmt/format_tool_call.go @@ -5,6 +5,8 @@ import ( ) func removeClaudeReportTaskToolCall(msg string) (string, []string) { + msg = "\n" + msg // This handles the case where the message starts with a tool call + // Remove all tool calls that start with `● coder - coder_report_task (MCP)` till we encounter the next line starting with ● lines := strings.Split(msg, "\n") @@ -18,9 +20,9 @@ func removeClaudeReportTaskToolCall(msg string) (string, []string) { line := strings.TrimSpace(lines[i]) nextLine := strings.TrimSpace(lines[i+1]) - if strings.Contains(prevLine, "coder - coder_report_task (MCP)") { - toolCallStartIdx = i - 1 - } else if toolCallStartIdx != -1 && line == "\"message\": \"Thanks for reporting!\"" && nextLine == "}" && strings.Replace(prevLine, " ", "", -1) == "⎿{" { + if strings.Contains(line, "coder - coder_report_task (MCP)") { + toolCallStartIdx = i + } else if toolCallStartIdx != -1 && line == "\"message\": \"Thanks for reporting!\"" && nextLine == "}" && strings.HasSuffix(prevLine, "{") { // Store [start, end] pair toolCallIdxs = append(toolCallIdxs, []int{toolCallStartIdx, min(len(lines), i+2)}) @@ -31,7 +33,7 @@ func removeClaudeReportTaskToolCall(msg string) (string, []string) { // If no tool calls found, return original message if len(toolCallIdxs) == 0 { - return strings.TrimSuffix(msg, "\n"), []string{} + return strings.TrimLeft(msg, "\n"), []string{} } toolCallMessages := make([]string, 0) @@ -45,7 +47,7 @@ func removeClaudeReportTaskToolCall(msg string) (string, []string) { lines = append(lines[:start], lines[end:]...) } - return strings.Join(lines, "\n"), toolCallMessages + return strings.TrimLeft(strings.Join(lines, "\n"), "\n"), toolCallMessages } func FormatToolCall(agentType AgentType, message string) (string, []string) { diff --git a/lib/msgfmt/testdata/format/claude/remove-task-tool-call/msg.txt b/lib/msgfmt/testdata/format/claude/remove-task-tool-call/msg.txt index 384e1094..6c8a0acd 100644 --- a/lib/msgfmt/testdata/format/claude/remove-task-tool-call/msg.txt +++ b/lib/msgfmt/testdata/format/claude/remove-task-tool-call/msg.txt @@ -1,5 +1,13 @@ > Build a snake game +● coder - coder_report_task (MCP)(summary: "Snake game created + successfully at snake-game.html", + link: "file:///home/coder/snake-ga + me.html", state: "working") + ⎿ { + "message": "Thanks for reporting!" + } + ● I'll build a snake game for you. Let me start by reporting my progress and creating a task list. From cf6b711a3585354196519305653e69861e07950f Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Tue, 16 Dec 2025 18:49:37 +0530 Subject: [PATCH 08/10] wip --- lib/screentracker/conversation.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/screentracker/conversation.go b/lib/screentracker/conversation.go index 29984cb7..3f90d14d 100644 --- a/lib/screentracker/conversation.go +++ b/lib/screentracker/conversation.go @@ -222,6 +222,7 @@ func (c *Conversation) updateLastAgentMessage(screen string, timestamp time.Time for _, toolCall := range toolCalls { if c.toolCallMessageSet[toolCall] == false { c.toolCallMessageSet[toolCall] = true + c.cfg.Logger.Info("Tool call detected", "toolCall", toolCall) } } shouldCreateNewMessage := len(c.messages) == 0 || c.messages[len(c.messages)-1].Role == ConversationRoleUser @@ -236,10 +237,7 @@ func (c *Conversation) updateLastAgentMessage(screen string, timestamp time.Time } if shouldCreateNewMessage { c.messages = append(c.messages, conversationMessage) - // Logging all the tool calls till now - for toolCall := range c.toolCallMessageSet { - c.cfg.Logger.Info("Tool call detected", "toolCall", toolCall) - } + // Cleanup c.toolCallMessageSet = make(map[string]bool) From 3967dd301d3a79f884fcb43f7d61a63f8396b438 Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Tue, 16 Dec 2025 19:01:39 +0530 Subject: [PATCH 09/10] wip --- lib/msgfmt/format_tool_call.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/msgfmt/format_tool_call.go b/lib/msgfmt/format_tool_call.go index c8c1950d..8a6482bc 100644 --- a/lib/msgfmt/format_tool_call.go +++ b/lib/msgfmt/format_tool_call.go @@ -54,6 +54,28 @@ func FormatToolCall(agentType AgentType, message string) (string, []string) { switch agentType { case AgentTypeClaude: return removeClaudeReportTaskToolCall(message) + case AgentTypeGoose: + return message, []string{} + case AgentTypeAider: + return message, []string{} + case AgentTypeCodex: + return message, []string{} + case AgentTypeGemini: + return message, []string{} + case AgentTypeCopilot: + return message, []string{} + case AgentTypeAmp: + return message, []string{} + case AgentTypeCursor: + return message, []string{} + case AgentTypeAuggie: + return message, []string{} + case AgentTypeAmazonQ: + return message, []string{} + case AgentTypeOpencode: + return message, []string{} + case AgentTypeCustom: + return message, []string{} default: return message, []string{} } From a06902bb27a67c4183858f873175855af565b513 Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Tue, 16 Dec 2025 19:08:42 +0530 Subject: [PATCH 10/10] wip --- lib/msgfmt/format_tool_call.go | 2 +- lib/msgfmt/msgfmt.go | 8 -------- lib/screentracker/conversation.go | 8 ++++---- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/lib/msgfmt/format_tool_call.go b/lib/msgfmt/format_tool_call.go index 8a6482bc..8af1fdca 100644 --- a/lib/msgfmt/format_tool_call.go +++ b/lib/msgfmt/format_tool_call.go @@ -7,7 +7,7 @@ import ( func removeClaudeReportTaskToolCall(msg string) (string, []string) { msg = "\n" + msg // This handles the case where the message starts with a tool call - // Remove all tool calls that start with `● coder - coder_report_task (MCP)` till we encounter the next line starting with ● + // Remove all tool calls that start with `● coder - coder_report_task (MCP)` lines := strings.Split(msg, "\n") toolCallStartIdx := -1 diff --git a/lib/msgfmt/msgfmt.go b/lib/msgfmt/msgfmt.go index d6ac7c07..3fccc2c3 100644 --- a/lib/msgfmt/msgfmt.go +++ b/lib/msgfmt/msgfmt.go @@ -254,14 +254,6 @@ func formatGenericMessage(message string, userInput string, agentType AgentType) return message } -//func formatClaudeMessage(message string, userInput string) string { -// message = RemoveUserInput(message, userInput, AgentTypeClaude) -// message = removeMessageBox(message) -// message = removeClaudeReportTaskToolCall(message) -// message = trimEmptyLines(message) -// return message -//} - func formatCodexMessage(message string, userInput string) string { message = RemoveUserInput(message, userInput, AgentTypeCodex) message = removeCodexInputBox(message) diff --git a/lib/screentracker/conversation.go b/lib/screentracker/conversation.go index 3f90d14d..97a74722 100644 --- a/lib/screentracker/conversation.go +++ b/lib/screentracker/conversation.go @@ -44,9 +44,9 @@ type ConversationConfig struct { SkipSendMessageStatusCheck bool // ReadyForInitialPrompt detects whether the agent has initialized and is ready to accept the initial prompt ReadyForInitialPrompt func(message string) bool - FormatToolCall func(message string) (string, []string) - // Logger for logging tool calls and other events - Logger *slog.Logger + // FormatToolCall removes the coder report_task tool call from the agent message and also returns the array of removed tool calls + FormatToolCall func(message string) (string, []string) + Logger *slog.Logger } type ConversationRole string @@ -86,7 +86,7 @@ type Conversation struct { InitialPromptSent bool // ReadyForInitialPrompt keeps track if the agent is ready to accept the initial prompt ReadyForInitialPrompt bool - // + // toolCallMessageSet keeps track of the tool calls that have been detected & logged in the current agent message toolCallMessageSet map[string]bool }