Skip to content

Commit 372c138

Browse files
committed
feat: add logging
1 parent c2313e0 commit 372c138

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

lib/httpapi/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ func NewServer(ctx context.Context, config ServerConfig) (*Server, error) {
226226
humaConfig.Info.Description = "HTTP API for Claude Code, Goose, and Aider.\n\nhttps://github.com/coder/agentapi"
227227
api := humachi.New(router, humaConfig)
228228
formatMessage := func(message string, userInput string) string {
229-
return mf.FormatAgentMessage(config.AgentType, message, userInput)
229+
return mf.FormatAgentMessage(config.AgentType, message, userInput, logger)
230230
}
231231

232232
isAgentReadyForInitialPrompt := func(message string) bool {

lib/msgfmt/message_box.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package msgfmt
22

33
import (
4+
"log/slog"
45
"strings"
56
)
67

@@ -101,7 +102,7 @@ func removeAmpMessageBox(msg string) string {
101102
return formattedMsg
102103
}
103104

104-
func removeClaudeReportTaskToolCall(msg string) string {
105+
func removeClaudeReportTaskToolCall(msg string, logger *slog.Logger) string {
105106
// Remove all tool calls that start with `● coder - coder_report_task (MCP)` till we encounter the next line starting with ●
106107
lines := strings.Split(msg, "\n")
107108

@@ -144,6 +145,11 @@ func removeClaudeReportTaskToolCall(msg string) string {
144145
for i := len(toolCallIdxs) - 1; i >= 0; i-- {
145146
idxPair := toolCallIdxs[i]
146147
start, end := idxPair[0], idxPair[1]
148+
149+
// Capture the tool call content before removing it
150+
toolCallContent := strings.Join(lines[start:end], "\n")
151+
logger.Info("Removing tool call", "content", toolCallContent)
152+
147153
lines = append(lines[:start], lines[end:]...)
148154
}
149155

lib/msgfmt/msgfmt.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package msgfmt
22

33
import (
4+
"log/slog"
45
"strings"
56
)
67

@@ -254,10 +255,10 @@ func formatGenericMessage(message string, userInput string, agentType AgentType)
254255
return message
255256
}
256257

257-
func formatClaudeMessage(message string, userInput string) string {
258+
func formatClaudeMessage(message string, userInput string, logger *slog.Logger) string {
258259
message = RemoveUserInput(message, userInput, AgentTypeClaude)
259260
message = removeMessageBox(message)
260-
message = removeClaudeReportTaskToolCall(message)
261+
message = removeClaudeReportTaskToolCall(message, logger)
261262
message = trimEmptyLines(message)
262263
return message
263264
}
@@ -283,10 +284,10 @@ func formatAmpMessage(message string, userInput string) string {
283284
return message
284285
}
285286

286-
func FormatAgentMessage(agentType AgentType, message string, userInput string) string {
287+
func FormatAgentMessage(agentType AgentType, message string, userInput string, logger *slog.Logger) string {
287288
switch agentType {
288289
case AgentTypeClaude:
289-
return formatClaudeMessage(message, userInput)
290+
return formatClaudeMessage(message, userInput, logger)
290291
case AgentTypeGoose:
291292
return formatGenericMessage(message, userInput, agentType)
292293
case AgentTypeAider:

lib/msgfmt/msgfmt_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package msgfmt
22

33
import (
44
"embed"
5+
"log/slog"
56
"path"
67
"strings"
78
"testing"
@@ -233,7 +234,7 @@ func TestFormatAgentMessage(t *testing.T) {
233234
assert.NoError(t, err)
234235
expected, err := testdataDir.ReadFile(path.Join(dir, string(agentType), c.Name(), "expected.txt"))
235236
assert.NoError(t, err)
236-
assert.Equal(t, string(expected), FormatAgentMessage(agentType, string(msg), string(userInput)))
237+
assert.Equal(t, string(expected), FormatAgentMessage(agentType, string(msg), string(userInput), slog.Default()))
237238
})
238239
}
239240
})

0 commit comments

Comments
 (0)