Interactive REPL loop.
(agent: AgentLoop)
| 54 | |
| 55 | |
| 56 | def run_interactive(agent: AgentLoop) -> None: |
| 57 | """Interactive REPL loop.""" |
| 58 | print(BANNER) |
| 59 | |
| 60 | while True: |
| 61 | try: |
| 62 | user_input = input("\n> ").strip() |
| 63 | except (EOFError, KeyboardInterrupt): |
| 64 | print("\nGoodbye!") |
| 65 | break |
| 66 | |
| 67 | if not user_input: |
| 68 | continue |
| 69 | |
| 70 | if user_input.startswith("/"): |
| 71 | cmd = user_input.lower().split()[0] |
| 72 | if cmd in ("/quit", "/exit", "/q"): |
| 73 | print("Goodbye!") |
| 74 | break |
| 75 | elif cmd == "/tools": |
| 76 | print("\nAvailable tools:") |
| 77 | for tool in agent.registry.all_tools(): |
| 78 | print(f" - {tool.name}: {tool.description}") |
| 79 | continue |
| 80 | elif cmd == "/mode": |
| 81 | parts = user_input.split() |
| 82 | if len(parts) > 1 and parts[1] in ("ask", "auto", "plan"): |
| 83 | agent.config.permission_mode = PermissionMode(parts[1]) |
| 84 | print(f"Mode changed to: {parts[1]}") |
| 85 | else: |
| 86 | print(f"Current mode: {agent.config.permission_mode.value}") |
| 87 | print("Usage: /mode [ask|auto|plan]") |
| 88 | continue |
| 89 | elif cmd == "/help": |
| 90 | print(BANNER) |
| 91 | continue |
| 92 | else: |
| 93 | print(f"Unknown command: {cmd}. Type /help for help.") |
| 94 | continue |
| 95 | |
| 96 | print() |
| 97 | try: |
| 98 | agent.run(user_input) |
| 99 | except KeyboardInterrupt: |
| 100 | print("\n(interrupted)") |
| 101 | except Exception as exc: |
| 102 | print(f"\nError: {exc}", file=sys.stderr) |
| 103 | |
| 104 | |
| 105 | def main(argv: list[str] | None = None) -> int: |
no test coverage detected