Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1525,15 +1525,24 @@ def _cprint(text: str):
# direct prompt_toolkit print is safe and matches existing behavior
# (spinner frames, streamed tokens, tool activity prefixes, …).
if app is None or not getattr(app, "_is_running", False):
_pt_print(_PT_ANSI(text))
try:
_pt_print(_PT_ANSI(text))
except Exception:
# No Windows console available (e.g. background agent subprocess
# with TERM=xterm-256color). Fall back to plain print so the
# process doesn't crash.
print(text)
return

try:
loop = app.loop # type: ignore[attr-defined]
except Exception:
loop = None
if loop is None:
_pt_print(_PT_ANSI(text))
try:
_pt_print(_PT_ANSI(text))
except Exception:
print(text)
return

import asyncio as _asyncio
Expand All @@ -1549,7 +1558,10 @@ def _cprint(text: str):
current_loop = None
# Same thread as the app's loop → safe to print directly.
if current_loop is loop and loop.is_running():
_pt_print(_PT_ANSI(text))
try:
_pt_print(_PT_ANSI(text))
except Exception:
print(text)
return

# Cross-thread emission: ask the app's event loop to schedule a
Expand Down