Skip to content

Commit 2200523

Browse files
committed
Add ability to handle and read from commands running in the background
1 parent cec0495 commit 2200523

4 files changed

Lines changed: 592 additions & 71 deletions

File tree

cecli/coders/agent_coder.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from cecli import urls, utils
1818
from cecli.change_tracker import ChangeTracker
1919
from cecli.helpers import nested
20+
from cecli.helpers.background_commands import BackgroundCommandManager
2021
from cecli.helpers.similarity import (
2122
cosine_similarity,
2223
create_bigram_vector,
@@ -596,6 +597,12 @@ def format_chat_chunks(self):
596597
write_context = self._generate_write_context()
597598
if write_context:
598599
post_message_blocks.append(write_context)
600+
601+
# Add background command output if any
602+
bg_output = self.get_background_command_output()
603+
if bg_output:
604+
post_message_blocks.append(bg_output)
605+
599606
if static_blocks:
600607
for block in static_blocks:
601608
if block:
@@ -608,6 +615,7 @@ def format_chat_chunks(self):
608615
for block in post_message_blocks:
609616
if block:
610617
chunks.post_message.append(dict(role="system", content=block))
618+
611619
base_messages = chunks.all_messages()
612620
messages_tokens = self.main_model.token_count(base_messages)
613621
reminder_tokens = self.main_model.token_count(reminder_message)
@@ -1730,6 +1738,32 @@ def get_skills_content(self):
17301738
self.io.tool_error(f"Error generating skills content context: {str(e)}")
17311739
return None
17321740

1741+
def get_background_command_output(self):
1742+
"""
1743+
Get background command output to append after the main message.
1744+
1745+
Returns:
1746+
String containing formatted background command output, or empty string if none
1747+
"""
1748+
# Get output from all running background commands
1749+
bg_outputs = BackgroundCommandManager.get_all_command_outputs(clear=True)
1750+
1751+
if not bg_outputs:
1752+
return ""
1753+
1754+
# Get command info to show actual command strings
1755+
command_info = BackgroundCommandManager.list_background_commands()
1756+
1757+
# Create formatted output for background commands
1758+
output = "--- Background Commands Output ---\n"
1759+
for command_key, cmd_output in bg_outputs.items():
1760+
if cmd_output.strip(): # Only add if there's output
1761+
# Get the actual command string if available
1762+
command_str = command_info.get(command_key, {}).get("command", command_key)
1763+
output += f"\n[bg: {command_str}]\n{cmd_output}\n"
1764+
1765+
return output
1766+
17331767
def get_git_status(self):
17341768
"""
17351769
Generate a git status context block for repository information.

0 commit comments

Comments
 (0)