Skip to content

Commit dafb6ab

Browse files
committed
feat(copilot): add function to remove coder_report_task tool calls for copilot
1 parent c4853a6 commit dafb6ab

File tree

5 files changed

+318
-1
lines changed

5 files changed

+318
-1
lines changed

lib/msgfmt/format_tool_call.go

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,68 @@ func removeCodexReportTaskToolCall(msg string) (string, []string) {
125125
return strings.TrimRight(strings.Join(lines, "\n"), "\n"), toolCallMessages
126126
}
127127

128+
func removeCopilotReportTaskToolCall(msg string) (string, []string) {
129+
msg = "\n" + msg // This handles the case where the message starts with a tool call
130+
131+
// Remove all tool calls that start with `● coder_report_task:`
132+
lines := strings.Split(msg, "\n")
133+
134+
toolCallStartIdx := -1
135+
newLineAfterToolCall := -1
136+
137+
// Store all tool call start and end indices [[start, end], ...]
138+
var toolCallIdxs []toolCallRange
139+
140+
for i := 0; i < len(lines); i++ {
141+
line := strings.Trim(strings.TrimSpace(lines[i]), "\n")
142+
143+
if strings.Contains(line, "● coder_report_task:") {
144+
toolCallStartIdx = i
145+
} else if toolCallStartIdx != -1 {
146+
if strings.Contains(line, "{\"message\":\"Thanks for reporting!\"}") {
147+
// Store [start, end] pair
148+
toolCallIdxs = append(toolCallIdxs, toolCallRange{toolCallStartIdx, min(len(lines), i+2), false})
149+
150+
// Reset to find the next tool call
151+
toolCallStartIdx = -1
152+
newLineAfterToolCall = -1
153+
} else if len(line) == 0 {
154+
newLineAfterToolCall = i + 1
155+
}
156+
}
157+
}
158+
159+
// Handle the malformed/partially rendered tool_calls
160+
// Note: This case has not yet been observed in Copilot
161+
if toolCallStartIdx != -1 {
162+
if newLineAfterToolCall != -1 {
163+
toolCallIdxs = append(toolCallIdxs, toolCallRange{toolCallStartIdx, newLineAfterToolCall, true})
164+
} else {
165+
toolCallIdxs = append(toolCallIdxs, toolCallRange{toolCallStartIdx, len(lines), true})
166+
}
167+
}
168+
169+
// If no tool calls found, return original message
170+
if len(toolCallIdxs) == 0 {
171+
return strings.TrimLeft(msg, "\n"), []string{}
172+
}
173+
174+
toolCallMessages := make([]string, 0)
175+
176+
// Remove tool calls from the message
177+
for i := len(toolCallIdxs) - 1; i >= 0; i-- {
178+
start, end := toolCallIdxs[i].start, toolCallIdxs[i].end
179+
180+
// If the toolCall is malformed, we don't want to log it
181+
if !toolCallIdxs[i].malformed {
182+
toolCallMessages = append(toolCallMessages, strings.Join(lines[start:end], "\n"))
183+
}
184+
185+
lines = append(lines[:start], lines[end:]...)
186+
}
187+
return strings.TrimLeft(strings.Join(lines, "\n"), "\n"), toolCallMessages
188+
}
189+
128190
func FormatToolCall(agentType AgentType, message string) (string, []string) {
129191
switch agentType {
130192
case AgentTypeClaude:
@@ -138,7 +200,7 @@ func FormatToolCall(agentType AgentType, message string) (string, []string) {
138200
case AgentTypeGemini:
139201
return message, []string{}
140202
case AgentTypeCopilot:
141-
return message, []string{}
203+
return removeCopilotReportTaskToolCall(message)
142204
case AgentTypeAmp:
143205
return message, []string{}
144206
case AgentTypeCursor:
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
◐ The user wants me to build a snake game in Python. This is a
2+
complete project that I should plan out first. Let me:
3+
4+
1. Create a plan for building the snake game
5+
2. Set up the structure
6+
3. Implement the game
7+
4. Test it
8+
9+
I should start by reporting task status and creating a plan.
10+
Since this is a new task that requires planning, I should:
11+
1. Report the task as "working"
12+
2. Create a plan.md file
13+
3. Set up todos in SQL
14+
4. Then implement
15+
16+
Let me start by reporting and exploring the current directory
17+
structure, then creating a plan.
18+
19+
● List directory .
20+
└ 1 file found
21+
22+
● Let me check if snake_game already exists:
23+
24+
● List directory snake_game
25+
└ 6 files found
26+
27+
● I see there's already a snake_game folder. Let me check the
28+
existing files:
29+
30+
● Read snake_game/README.md
31+
└ 97 lines read
32+
33+
● Read snake_game/main.py
34+
└ 229 lines read
35+
36+
● Great! A snake game already exists. Let me check the test file
37+
and game summary:
38+
39+
● Read snake_game/test_game.py
40+
└ 113 lines read
41+
42+
● Read snake_game/GAME_SUMMARY.txt
43+
└ 89 lines read
44+
45+
● Perfect! The snake game is already built and complete. Let me
46+
verify it's working by running the tests:
47+
48+
● Run snake game unit tests
49+
$ cd /home/coder/projects/snake_game && python3 test_game.py
50+
└ 7 lines...
51+
52+
● The virtual environment needs pygame installed. Let me set it
53+
up:
54+
55+
● Install pygame and run tests
56+
$ cd /home/coder/projects/snake_game && source venv/bin/activate
57+
&& pip install pygame -q && python3 test_game.py
58+
└ 16 lines...
59+
60+
● Excellent! All tests pass. Now let me verify the game can run:
61+
62+
● Verify game starts successfully
63+
$ cd /home/coder/projects/snake_game && source venv/bin/activate
64+
&& timeout 3 python3 main.py 2>&1 || true
65+
└ 3 lines...
66+
67+
● Perfect! The game initializes successfully. Let me update you
68+
on what's been completed:
69+
70+
● ✅ Snake Game Complete!
71+
72+
Your Python snake game is fully built and tested. Here's what
73+
you have:
74+
75+
🎮 Game Features
76+
77+
- Classic snake gameplay with grid-based movement
78+
- Collision detection (walls & self)
79+
- Scoring system (10 points per food)
80+
- Game over screen with restart option
81+
- Keyboard controls (arrow keys)
82+
- 10 FPS consistent gameplay speed
83+
84+
📂 Project Structure
85+
86+
snake_game/
87+
├── main.py - Full game implementation
88+
├── test_game.py - 8 passing unit tests
89+
├── README.md - Complete documentation
90+
└── venv/ - Virtual environment with pygame
91+
92+
🚀 Quick Start
93+
94+
cd /home/coder/projects/snake_game
95+
source venv/bin/activate
96+
python3 main.py
97+
98+
⌨️ Controls
99+
100+
- Arrow Keys - Move snake
101+
- R - Restart (when game over)
102+
- ESC - Quit
103+
104+
✅ Verification Status
105+
106+
- ✓ All 8 unit tests passing
107+
- ✓ Game initializes and runs successfully
108+
- ✓ Pygame installed and configured
109+
110+
Ready to play! 🐍
111+
112+
~/projects claude-haiku-4.5 (1x)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
● coder_report_task: Last Call
2+
└ {"message":"Thanks for reporting!"}
3+
4+
---
5+
● coder_report_task: Snake game built and verified - all tests
6+
passing, game runs successfully
7+
└ {"message":"Thanks for reporting!"}
8+
9+
---
10+
● coder_report_task: Starting snake game project planning and
11+
implementation
12+
└ {"message":"Thanks for reporting!"}
13+
14+
---
15+
● coder_report_task: First Call
16+
└ {"message":"Thanks for reporting!"}
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
● coder_report_task: First Call
2+
└ {"message":"Thanks for reporting!"}
3+
4+
◐ The user wants me to build a snake game in Python. This is a
5+
complete project that I should plan out first. Let me:
6+
7+
1. Create a plan for building the snake game
8+
2. Set up the structure
9+
3. Implement the game
10+
4. Test it
11+
12+
I should start by reporting task status and creating a plan.
13+
Since this is a new task that requires planning, I should:
14+
1. Report the task as "working"
15+
2. Create a plan.md file
16+
3. Set up todos in SQL
17+
4. Then implement
18+
19+
Let me start by reporting and exploring the current directory
20+
structure, then creating a plan.
21+
22+
● coder_report_task: Starting snake game project planning and
23+
implementation
24+
└ {"message":"Thanks for reporting!"}
25+
26+
● List directory .
27+
└ 1 file found
28+
29+
● Let me check if snake_game already exists:
30+
31+
● List directory snake_game
32+
└ 6 files found
33+
34+
● I see there's already a snake_game folder. Let me check the
35+
existing files:
36+
37+
● Read snake_game/README.md
38+
└ 97 lines read
39+
40+
● Read snake_game/main.py
41+
└ 229 lines read
42+
43+
● Great! A snake game already exists. Let me check the test file
44+
and game summary:
45+
46+
● Read snake_game/test_game.py
47+
└ 113 lines read
48+
49+
● Read snake_game/GAME_SUMMARY.txt
50+
└ 89 lines read
51+
52+
● Perfect! The snake game is already built and complete. Let me
53+
verify it's working by running the tests:
54+
55+
● Run snake game unit tests
56+
$ cd /home/coder/projects/snake_game && python3 test_game.py
57+
└ 7 lines...
58+
59+
● The virtual environment needs pygame installed. Let me set it
60+
up:
61+
62+
● Install pygame and run tests
63+
$ cd /home/coder/projects/snake_game && source venv/bin/activate
64+
&& pip install pygame -q && python3 test_game.py
65+
└ 16 lines...
66+
67+
● Excellent! All tests pass. Now let me verify the game can run:
68+
69+
● Verify game starts successfully
70+
$ cd /home/coder/projects/snake_game && source venv/bin/activate
71+
&& timeout 3 python3 main.py 2>&1 || true
72+
└ 3 lines...
73+
74+
● Perfect! The game initializes successfully. Let me update you
75+
on what's been completed:
76+
77+
● coder_report_task: Snake game built and verified - all tests
78+
passing, game runs successfully
79+
└ {"message":"Thanks for reporting!"}
80+
81+
● ✅ Snake Game Complete!
82+
83+
Your Python snake game is fully built and tested. Here's what
84+
you have:
85+
86+
🎮 Game Features
87+
88+
- Classic snake gameplay with grid-based movement
89+
- Collision detection (walls & self)
90+
- Scoring system (10 points per food)
91+
- Game over screen with restart option
92+
- Keyboard controls (arrow keys)
93+
- 10 FPS consistent gameplay speed
94+
95+
📂 Project Structure
96+
97+
snake_game/
98+
├── main.py - Full game implementation
99+
├── test_game.py - 8 passing unit tests
100+
├── README.md - Complete documentation
101+
└── venv/ - Virtual environment with pygame
102+
103+
🚀 Quick Start
104+
105+
cd /home/coder/projects/snake_game
106+
source venv/bin/activate
107+
python3 main.py
108+
109+
⌨️ Controls
110+
111+
- Arrow Keys - Move snake
112+
- R - Restart (when game over)
113+
- ESC - Quit
114+
115+
✅ Verification Status
116+
117+
- ✓ All 8 unit tests passing
118+
- ✓ Game initializes and runs successfully
119+
- ✓ Pygame installed and configured
120+
121+
Ready to play! 🐍
122+
123+
● coder_report_task: Last Call
124+
└ {"message":"Thanks for reporting!"}
125+
126+
~/projects claude-haiku-4.5 (1x)
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)