handleAgentEvents processes agent events and displays them
(ctx context.Context, eventCh <-chan types.AgentEventEnvelope, useColor bool)
| 259 | |
| 260 | // handleAgentEvents processes agent events and displays them |
| 261 | func handleAgentEvents(ctx context.Context, eventCh <-chan types.AgentEventEnvelope, useColor bool) { |
| 262 | for { |
| 263 | select { |
| 264 | case <-ctx.Done(): |
| 265 | return |
| 266 | case envelope, ok := <-eventCh: |
| 267 | if !ok { |
| 268 | return |
| 269 | } |
| 270 | |
| 271 | switch e := envelope.Event.(type) { |
| 272 | case *types.ProgressTextChunkEvent: |
| 273 | fmt.Print(e.Delta) |
| 274 | |
| 275 | case *types.ProgressToolStartEvent: |
| 276 | printColored(useColor, colorGray, "\n🔧 %s", e.Call.Name) |
| 277 | if len(e.Call.Arguments) > 0 { |
| 278 | // Show truncated input |
| 279 | inputStr := fmt.Sprintf("%v", e.Call.Arguments) |
| 280 | if len(inputStr) > 80 { |
| 281 | inputStr = inputStr[:77] + "..." |
| 282 | } |
| 283 | printColored(useColor, colorGray, " (%s)", inputStr) |
| 284 | } |
| 285 | fmt.Println() |
| 286 | |
| 287 | case *types.ProgressToolEndEvent: |
| 288 | if e.Call.Error == "" { |
| 289 | printColored(useColor, colorGreen, "✓ ") |
| 290 | } else { |
| 291 | printColored(useColor, colorYellow, "✗ ") |
| 292 | } |
| 293 | // Show truncated output |
| 294 | outputStr := fmt.Sprintf("%v", e.Call.Result) |
| 295 | if len(outputStr) > 100 { |
| 296 | outputStr = outputStr[:97] + "..." |
| 297 | } |
| 298 | printColored(useColor, colorGray, "%s\n", outputStr) |
| 299 | |
| 300 | case *types.ProgressThinkChunkStartEvent: |
| 301 | printColored(useColor, colorGray, "💭 Thinking...\n") |
| 302 | |
| 303 | case *types.ControlPermissionRequiredEvent: |
| 304 | // Handle permission request |
| 305 | printColored(useColor, colorYellow, "\n⚠️ Tool requires approval: %s\n", e.Call.Name) |
| 306 | printColored(useColor, colorGray, " Input: %v\n", e.Call.Arguments) |
| 307 | fmt.Print(" Approve? [y/N]: ") |
| 308 | // Note: In a real implementation, we'd wait for user input |
| 309 | // and send the decision back to the agent via e.Respond |
| 310 | |
| 311 | case *types.MonitorErrorEvent: |
| 312 | printColored(useColor, colorYellow, "\n❌ Error: %s\n", e.Message) |
| 313 | } |
| 314 | } |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | // runREPL runs the read-eval-print loop |
no test coverage detected