| 182 | |
| 183 | // Listen for messages |
| 184 | const messageHandler = ({ message }: { message: ClineMessage }) => { |
| 185 | messages.push(message) |
| 186 | |
| 187 | // Check for tool execution and capture results |
| 188 | if (message.type === "say" && message.say === "api_req_started") { |
| 189 | const text = message.text || "" |
| 190 | if (text.includes("list_files")) { |
| 191 | toolExecuted = true |
| 192 | console.log("list_files tool executed:", text.substring(0, 200)) |
| 193 | |
| 194 | // Extract list results from the tool execution |
| 195 | try { |
| 196 | const jsonMatch = text.match(/\{"request":".*?"\}/) |
| 197 | if (jsonMatch) { |
| 198 | const requestData = JSON.parse(jsonMatch[0]) |
| 199 | if (requestData.request && requestData.request.includes("Result:")) { |
| 200 | listResults = requestData.request |
| 201 | console.log("Captured list results:", listResults?.substring(0, 300)) |
| 202 | } |
| 203 | } |
| 204 | } catch (e) { |
| 205 | console.log("Failed to parse list results:", e) |
| 206 | } |
| 207 | } |
| 208 | } |
| 209 | } |
| 210 | api.on(RooCodeEventName.Message, messageHandler) |
| 211 | |
| 212 | // Listen for task completion |