feat(terminal): add agent streaming UX with reasoning/tool-call rendering

This commit is contained in:
zhayujie
2026-05-30 19:10:56 +08:00
parent c5b8e06891
commit 29c4be6a3a
3 changed files with 315 additions and 28 deletions

View File

@@ -8,11 +8,28 @@ from typing import Optional
import click
from cli.utils import get_project_root
from cli.utils import get_project_root, load_config_json
_IS_WIN = sys.platform == "win32"
def _is_terminal_only() -> bool:
"""Whether terminal is the only configured channel.
Terminal needs an interactive stdin/tty, which is incompatible with the
background daemon mode (stdout/stdin detached). When terminal is the only
channel, `start` must run in the foreground so it can own the tty.
"""
channel = load_config_json().get("channel_type", "")
if isinstance(channel, str):
names = [c.strip() for c in channel.split(",") if c.strip()]
elif isinstance(channel, (list, tuple)):
names = [str(c).strip() for c in channel if str(c).strip()]
else:
names = []
return names == ["terminal"]
def _get_pid_file():
return os.path.join(get_project_root(), ".cow.pid")
@@ -103,6 +120,12 @@ def start(foreground, no_logs):
python = sys.executable
# Terminal-only setups need an interactive tty; force foreground so the
# terminal channel can read stdin instead of fighting the shell over the tty.
if not foreground and _is_terminal_only():
foreground = True
click.echo("Detected terminal-only channel, starting in foreground...")
if foreground:
click.echo("Starting CowAgent in foreground...")
if _IS_WIN: