-
Notifications
You must be signed in to change notification settings - Fork 96
feat(claude/tool_call): add tool call logging and improve format handling #163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+164
−63
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3955c3b
feat(tool_call): implement tool call logging and improve format handling
35C4n0r 8fb27f6
wip
35C4n0r b39e96e
wip
35C4n0r d0672b2
wip
35C4n0r b4e2dfe
wip
35C4n0r 3ba427e
wip
35C4n0r 7d6fb4f
wip
35C4n0r cf6b711
wip
35C4n0r 3967dd3
wip
35C4n0r a06902b
wip
35C4n0r 8114bad
feat: assert extracted tool calls
35C4n0r File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| package msgfmt | ||
|
|
||
| import ( | ||
| "strings" | ||
| ) | ||
|
|
||
| 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)` | ||
| 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.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)}) | ||
|
|
||
| // Reset to find the next tool call | ||
| toolCallStartIdx = -1 | ||
| } | ||
| } | ||
|
|
||
| // If no tool calls found, return original message | ||
| if len(toolCallIdxs) == 0 { | ||
| return strings.TrimLeft(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.TrimLeft(strings.Join(lines, "\n"), "\n"), toolCallMessages | ||
| } | ||
|
|
||
| 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{} | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
lib/msgfmt/testdata/format/claude/remove-task-tool-call/expected_tool_calls.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| ● 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!" | ||
| } | ||
| --- | ||
| ● 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!" | ||
| } | ||
| --- | ||
| ● coder - coder_report_task (MCP)(summary: "Building a snake game | ||
| with HTML/CSS/JavaScript", link: | ||
| "", state: "working") | ||
| ⎿ { | ||
| "message": "Thanks for reporting!" | ||
| } | ||
| --- | ||
| ● 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!" | ||
| } |
8 changes: 8 additions & 0 deletions
8
lib/msgfmt/testdata/format/claude/remove-task-tool-call/msg.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On its own, adding this does not cause any test failures on
main. We should have a sample input that reproduces the issue so that we can have confidence in the fix.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was adde to verify the case where the message starts with a tool call