Skip to content
Merged
Show file tree
Hide file tree
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
17 changes: 11 additions & 6 deletions cecli/coders/base_coder.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,8 @@ def __init__(
uuid: str = "",
parent_uuid: str = "",
):
from cecli.helpers.agents.service import AgentService

# initialize from args.map_cache_dir
self.coroutines = coroutines
# Per-instance tool and server filtering dictionaries
Expand Down Expand Up @@ -544,8 +546,10 @@ def __init__(

self.show_diffs = show_diffs

# Initialize conversation system if enabled
# Initialize all registry sub systems
AgentService.get_instance(self)
ConversationService.get_chunks(self).initialize_conversation_system()
ObservationService.get_instance(self)

self.commands = commands or Commands(self.io, self, args=args)
self.commands.coder = self
Expand Down Expand Up @@ -3675,10 +3679,11 @@ def consolidate_chunks(self):
func_err = None
content_err = None

last_chunk = self.partial_response_chunks[len(self.partial_response_chunks) - 1]
if last_chunk:
if getattr(last_chunk, "usage", None):
response.usage = last_chunk.usage
if len(self.partial_response_chunks):
last_chunk = self.partial_response_chunks[len(self.partial_response_chunks) - 1]
if last_chunk:
if getattr(last_chunk, "usage", None):
response.usage = last_chunk.usage

# Collect provider-specific fields from chunks to preserve them
# We need to track both by ID (primary) and index (fallback) since
Expand Down Expand Up @@ -4487,7 +4492,7 @@ async def handle_shell_commands(self, commands_str, group):
if output:
accumulated_output += f"Output from {command}\n{output}\n"

print(accumulated_output)
self.io.tool_output(accumulated_output)

if accumulated_output.strip() and await self.io.confirm_ask(
"Add command output to the chat?", allow_never=True
Expand Down
2 changes: 1 addition & 1 deletion cecli/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async def execute(cls, io, coder, args, **kwargs):
)

if coder.args.tui:
print(combined_output)
coder.io.tool_warning(combined_output)
else:
# This print statement, for whatever reason,
# allows the thread to properly yield control of the terminal
Expand Down
13 changes: 12 additions & 1 deletion cecli/helpers/agents/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,11 +571,13 @@ def start_generate_task(self, info: SubAgentInfo, user_message: str) -> asyncio.
Returns:
The ``asyncio.Task`` wrapping ``generate()``.
"""
from cecli.commands import SwitchCoderSignal

async def _run_generate():
info.status = SubAgentStatus.RUNNING
try:
await info.coder.generate(user_message=user_message, preproc=True)

if info.status == SubAgentStatus.RUNNING:
info.status = SubAgentStatus.FINISHED
info.summary = info.summary or DEFAULT_SUMMARY_COMPLETED
Expand All @@ -597,15 +599,24 @@ async def _run_generate():
)
await self._inject_sub_agent_result(info)
raise
except SwitchCoderSignal:
raise

# Cancel any previous generate task to prevent duplicate concurrent generates
if info.generate_task is not None and not info.generate_task.done():
info.generate_task.cancel()

task = asyncio.create_task(_run_generate())
info.generate_task = task

def _raise_if_signal(exc):
if isinstance(exc, SwitchCoderSignal):
raise exc

# Suppress "Task exception was never retrieved" for fire-and-forget tasks
task.add_done_callback(lambda t: t.exception() if not t.cancelled() else None)
task.add_done_callback(
lambda t: _raise_if_signal(t.exception()) if not t.cancelled() else None
)
return task

async def _inject_sub_agent_result(self, info: SubAgentInfo) -> None:
Expand Down
Loading
Loading