fix(cli): keep direct-call rendering compatible in tests

Only use process_direct_outbound when the agent loop actually exposes it as an async method, and otherwise fall back to the legacy process_direct path. This keeps the new CLI render-metadata flow without breaking existing test doubles or older direct-call implementations.

Made-with: Cursor
This commit is contained in:
Xubin Ren
2026-03-21 16:07:14 +00:00
parent e430b1daf5
commit a8176ef2c6

View File

@@ -2,6 +2,7 @@
import asyncio import asyncio
from contextlib import contextmanager, nullcontext from contextlib import contextmanager, nullcontext
import inspect
import os import os
import select import select
import signal import signal
@@ -767,17 +768,27 @@ def agent(
nonlocal _thinking nonlocal _thinking
_thinking = _ThinkingSpinner(enabled=not logs) _thinking = _ThinkingSpinner(enabled=not logs)
with _thinking: with _thinking:
direct_outbound = getattr(agent_loop, "process_direct_outbound", None)
if inspect.iscoroutinefunction(direct_outbound):
response = await agent_loop.process_direct_outbound( response = await agent_loop.process_direct_outbound(
message, message,
session_id, session_id,
on_progress=_cli_progress, on_progress=_cli_progress,
) )
_thinking = None response_content = response.content if response else ""
_print_agent_response( response_meta = response.metadata if response else None
response.content if response else "", else:
render_markdown=markdown, response_content = await agent_loop.process_direct(
metadata=response.metadata if response else None, message,
session_id,
on_progress=_cli_progress,
) )
response_meta = None
_thinking = None
kwargs = {"render_markdown": markdown}
if response_meta is not None:
kwargs["metadata"] = response_meta
_print_agent_response(response_content, **kwargs)
await agent_loop.close_mcp() await agent_loop.close_mcp()
asyncio.run(run_once()) asyncio.run(run_once())