Skip to content

Commit 952d767

Browse files
authored
feat: format report_task tool call for codex (#167)
1 parent 0154403 commit 952d767

File tree

5 files changed

+110
-1
lines changed

5 files changed

+110
-1
lines changed

lib/msgfmt/format_tool_call.go

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,58 @@ func removeClaudeReportTaskToolCall(msg string) (string, []string) {
5050
return strings.TrimLeft(strings.Join(lines, "\n"), "\n"), toolCallMessages
5151
}
5252

53+
func removeCodexReportTaskToolCall(msg string) (string, []string) {
54+
lines := strings.Split(msg, "\n")
55+
56+
toolCallStartIdx := -1
57+
58+
// Store all tool call start and end indices [[start, end], ...]
59+
var toolCallIdxs [][]int
60+
61+
for idx := 0; idx < len(lines); idx++ {
62+
line := strings.TrimSpace(lines[idx])
63+
64+
// Check for tool call start (requires looking at next line)
65+
if idx+1 < len(lines) {
66+
nextLine := strings.TrimSpace(lines[idx+1])
67+
if strings.Replace(line, " ", "", -1) == "•Called" && strings.Contains(nextLine, "Coder.coder_report_task") {
68+
toolCallStartIdx = idx
69+
}
70+
}
71+
72+
// Check for tool call end
73+
if toolCallStartIdx != -1 && line == "{\"message\": \"Thanks for reporting!\"}" {
74+
// Find the end of trailing empty lines after tool call
75+
endIdx := idx + 1
76+
for endIdx < len(lines) && strings.TrimSpace(lines[endIdx]) == "" {
77+
endIdx++
78+
}
79+
toolCallIdxs = append(toolCallIdxs, []int{toolCallStartIdx, endIdx})
80+
81+
// Reset to find the next tool call
82+
toolCallStartIdx = -1
83+
}
84+
}
85+
86+
// If no tool calls found, return original message
87+
if len(toolCallIdxs) == 0 {
88+
return strings.TrimRight(msg, "\n"), []string{}
89+
}
90+
91+
toolCallMessages := make([]string, 0)
92+
93+
// Remove tool calls from the message
94+
for i := len(toolCallIdxs) - 1; i >= 0; i-- {
95+
idxPair := toolCallIdxs[i]
96+
start, end := idxPair[0], idxPair[1]
97+
98+
toolCallMessages = append(toolCallMessages, strings.Join(lines[start:end], "\n"))
99+
100+
lines = append(lines[:start], lines[end:]...)
101+
}
102+
return strings.TrimRight(strings.Join(lines, "\n"), "\n"), toolCallMessages
103+
}
104+
53105
func FormatToolCall(agentType AgentType, message string) (string, []string) {
54106
switch agentType {
55107
case AgentTypeClaude:
@@ -59,7 +111,7 @@ func FormatToolCall(agentType AgentType, message string) (string, []string) {
59111
case AgentTypeAider:
60112
return message, []string{}
61113
case AgentTypeCodex:
62-
return message, []string{}
114+
return removeCodexReportTaskToolCall(message)
63115
case AgentTypeGemini:
64116
return message, []string{}
65117
case AgentTypeCopilot:
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
• Codex says: I'm starting by reporting the task as working with a
2+
summary about reviewing the repository structure to gather
3+
information for planning the snake game implementation. Next,
4+
I'll inspect the repository files.
5+
6+
• I'm drafting a concise final message starting with "Codex says:"
7+
that briefly explains adding a terminal-based snake game in
8+
snake.py, highlights key features like controls and scoring,
9+
notes the need to run with python3 due to missing python alias,
10+
includes usage instructions, and suggests next steps—all
11+
formatted as short bullet points with a simple optional header.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
• Called
2+
└ Coder.coder_report_task({"link":"snake-
3+
game","state":"working","summary":"Reviewing repository
4+
structure before coding"})
5+
{"message": "Thanks for reporting!"}
6+
---
7+
• Called
8+
└ Coder.coder_report_task({"link":"snake-
9+
game","state":"working","summary":"Status 2"})
10+
{"message": "Thanks for reporting!"}
11+
12+
---
13+
• Called
14+
└ Coder.coder_report_task({"link":"snake-
15+
game","state":"working","summary":"Status 1"})
16+
{"message": "Thanks for reporting!"}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
› Build a snake game
2+
3+
• Called
4+
└ Coder.coder_report_task({"link":"snake-
5+
game","state":"working","summary":"Status 1"})
6+
{"message": "Thanks for reporting!"}
7+
8+
• Codex says: I'm starting by reporting the task as working with a
9+
summary about reviewing the repository structure to gather
10+
information for planning the snake game implementation. Next,
11+
I'll inspect the repository files.
12+
13+
• Called
14+
└ Coder.coder_report_task({"link":"snake-
15+
game","state":"working","summary":"Status 2"})
16+
{"message": "Thanks for reporting!"}
17+
18+
• I'm drafting a concise final message starting with "Codex says:"
19+
that briefly explains adding a terminal-based snake game in
20+
snake.py, highlights key features like controls and scoring,
21+
notes the need to run with python3 due to missing python alias,
22+
includes usage instructions, and suggests next steps—all
23+
formatted as short bullet points with a simple optional header.
24+
25+
• Called
26+
└ Coder.coder_report_task({"link":"snake-
27+
game","state":"working","summary":"Reviewing repository
28+
structure before coding"})
29+
{"message": "Thanks for reporting!"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Build a snake game

0 commit comments

Comments
 (0)