3131
3232from .base_coder import Coder
3333
34+ from cecli .helpers .coroutines import interruptible # isort:skip
35+
3436
3537class AgentCoder (Coder ):
3638 """Mode where the LLM autonomously manages which files are in context."""
@@ -42,6 +44,9 @@ class AgentCoder(Coder):
4244 stop_on_empty = False
4345
4446 def __init__ (self , * args , ** kwargs ):
47+ if kwargs .get ("uuid" , None ):
48+ self .uuid = kwargs .get ("uuid" )
49+
4550 self .recently_removed = {}
4651 self .tool_usage_history = []
4752 self .loaded_custom_tools = []
@@ -53,17 +58,17 @@ def __init__(self, *args, **kwargs):
5358 self .read_tools = {
5459 "command" ,
5560 "commandinteractive" ,
56- "exploresymbols " ,
61+ "explorecode " ,
5762 "ls" ,
63+ "readrange" ,
5864 "grep" ,
59- "showcontext" ,
6065 "thinking" ,
6166 "updatetodolist" ,
6267 }
6368 self .write_tools = {
64- "deletetext " ,
65- "inserttext " ,
66- "replacetext " ,
69+ "command " ,
70+ "commandinteractive " ,
71+ "edittext " ,
6772 "undochange" ,
6873 }
6974 self .edit_allowed = False
@@ -301,8 +306,23 @@ async def _execute_local_tool_calls(self, tool_calls_list):
301306 else :
302307 all_results_content .append (f"Error: Unknown tool name '{ tool_name } '" )
303308 if tasks :
304- task_results = await asyncio .gather (* tasks )
305- all_results_content .extend (str (res ) for res in task_results )
309+
310+ async def gather_and_await ():
311+ return await asyncio .gather (* tasks , return_exceptions = True )
312+
313+ task_results , interrupted = await interruptible (
314+ gather_and_await (), self .interrupt_event
315+ )
316+
317+ if interrupted :
318+ self .io .tool_warning ("Tool execution interrupted." )
319+ all_results_content .append ("Tool execution interrupted by user." )
320+ elif task_results :
321+ for res in task_results :
322+ if isinstance (res , Exception ):
323+ all_results_content .append (f"Error in tool execution: { res } " )
324+ else :
325+ all_results_content .append (str (res ))
306326
307327 if not await HookIntegration .call_post_tool_hooks (
308328 self , tool_name , args_string , "\n \n " .join (all_results_content )
@@ -393,7 +413,11 @@ async def _exec_async():
393413""" )
394414 return f"Error executing tool call { tool_name } : { e } "
395415
396- return await _exec_async ()
416+ result , interrupted = await interruptible (_exec_async (), self .interrupt_event )
417+
418+ if interrupted :
419+ return "Tool execution interrupted by user."
420+ return result
397421
398422 def _calculate_context_block_tokens (self , force = False ):
399423 """
@@ -582,6 +606,7 @@ def format_chat_chunks(self):
582606
583607 # Add post-message context blocks (priority 250 - between CUR and REMINDER)
584608 ConversationService .get_chunks (self ).add_post_message_context_blocks ()
609+ ConversationService .get_chunks (self ).add_randomized_cta ()
585610
586611 return ConversationService .get_manager (self ).get_messages_dict ()
587612
@@ -617,9 +642,7 @@ def get_context_summary(self):
617642 total_file_tokens += tokens
618643 editable_tokens += tokens
619644 size_indicator = (
620- "🔴 Large"
621- if tokens > 5000
622- else "🟡 Medium" if tokens > 1000 else "🟢 Small"
645+ "Large" if tokens > 5000 else "Medium" if tokens > 1000 else "Small"
623646 )
624647 editable_files .append (
625648 f"- { rel_fname } : { tokens :,} tokens ({ size_indicator } )"
@@ -641,9 +664,7 @@ def get_context_summary(self):
641664 total_file_tokens += tokens
642665 readonly_tokens += tokens
643666 size_indicator = (
644- "🔴 Large"
645- if tokens > 5000
646- else "🟡 Medium" if tokens > 1000 else "🟢 Small"
667+ "Large" if tokens > 5000 else "Medium" if tokens > 1000 else "Small"
647668 )
648669 readonly_files .append (
649670 f"- { rel_fname } : { tokens :,} tokens ({ size_indicator } )"
@@ -999,7 +1020,7 @@ def _generate_tool_context(self, repetitive_tools):
9991020 context_parts .append ("\n \n " )
10001021 context_parts .append ("## File Editing Tools Disabled" )
10011022 context_parts .append (
1002- "File editing tools are currently disabled.Use `ShowContext ` to determine the"
1023+ "File editing tools are currently disabled.Use `ReadRange ` to determine the"
10031024 " current hashline prefixes needed to perform an edit and activate them when you"
10041025 " are ready to edit a file."
10051026 )
0 commit comments