diff --git a/agentserver/console/tui_console.py b/agentserver/console/tui_console.py index 847fbe4..20a0851 100644 --- a/agentserver/console/tui_console.py +++ b/agentserver/console/tui_console.py @@ -313,8 +313,12 @@ class TUIConsole: self.print_raw(f"Type /help for commands, @listener message to chat", "output.dim") self.print_raw("", "output") + # Patch stdout so any external prints go to our output area + from prompt_toolkit.patch_stdout import patch_stdout + try: - await self.app.run_async() + with patch_stdout(raw=True): + await self.app.run_async() except Exception as e: print(f"Console error: {e}") finally: diff --git a/handlers/hello.py b/handlers/hello.py index 4f734b9..9265627 100644 --- a/handlers/hello.py +++ b/handlers/hello.py @@ -125,23 +125,18 @@ async def handle_response_print(payload: ShoutedResponse, metadata: HandlerMetad Print the final response to the console. Routes output to the TUI console if available, otherwise prints to stdout. + With TUI, stdout is patched so prints appear in the output area. """ console = None try: from run_organism import get_console console = get_console() - except ImportError as e: - console = None + except ImportError: + pass - if console is not None: - if hasattr(console, 'on_response'): - try: - console.on_response("shouter", payload) - return # Success - exit without fallback print - except Exception as e: - pass # Fall through to fallback - # Console exists but no on_response - shouldn't happen - - # Fallback only runs if console is None - # This should NOT print if TUI is running - return None + if console is not None and hasattr(console, 'on_response'): + # Use TUI's output buffer directly (preferred) + console.on_response("shouter", payload) + else: + # Print to stdout (TUI patches this, simple mode shows directly) + print(f"\033[36m[response] {payload.message}\033[0m")