Production-ready interactive loop with comprehensive error handling. Rock-solid stability for cross-platform deployment.
(orchestrator: AgentOrchestrator)
| 534 | |
| 535 | |
| 536 | def interactive_mode(orchestrator: AgentOrchestrator): |
| 537 | """ |
| 538 | Production-ready interactive loop with comprehensive error handling. |
| 539 | Rock-solid stability for cross-platform deployment. |
| 540 | """ |
| 541 | # Show banner once (only if not already shown) |
| 542 | try: |
| 543 | show_minimal_banner(orchestrator) |
| 544 | except Exception as e: |
| 545 | # Banner failed, but continue |
| 546 | pass # Silent fail - banner is not critical |
| 547 | |
| 548 | # Error recovery counters |
| 549 | consecutive_errors = 0 |
| 550 | max_consecutive_errors = 5 |
| 551 | total_errors = 0 |
| 552 | max_total_errors = 50 |
| 553 | |
| 554 | # Main loop with recovery |
| 555 | while True: |
| 556 | try: |
| 557 | # Ensure clean terminal state before input |
| 558 | try: |
| 559 | sys.stdout.flush() |
| 560 | sys.stderr.flush() |
| 561 | except: |
| 562 | pass |
| 563 | |
| 564 | # Get input with fallback |
| 565 | try: |
| 566 | user_input = get_modern_input() # Use modern input with autocomplete |
| 567 | except (KeyboardInterrupt, EOFError): |
| 568 | raise # Re-raise these for proper handling |
| 569 | except Exception as input_error: |
| 570 | # Input failed - try fallback to minimal input (no autocomplete) |
| 571 | console.print("[yellow]Autocomplete unavailable, using basic input...[/yellow]") |
| 572 | try: |
| 573 | user_input = get_minimal_input() |
| 574 | except (KeyboardInterrupt, EOFError): |
| 575 | raise |
| 576 | except: |
| 577 | # Ultimate fallback - plain input |
| 578 | try: |
| 579 | user_input = input(" > ").strip() |
| 580 | except (KeyboardInterrupt, EOFError): |
| 581 | raise |
| 582 | except: |
| 583 | consecutive_errors += 1 |
| 584 | if consecutive_errors >= max_consecutive_errors: |
| 585 | console.print("[red]Too many consecutive errors. Restarting...[/red]") |
| 586 | consecutive_errors = 0 |
| 587 | continue |
| 588 | |
| 589 | # Reset error counter on successful input |
| 590 | if user_input: |
| 591 | consecutive_errors = 0 |
| 592 | |
| 593 | # Skip empty input |
no test coverage detected