Skip to content

Commit adc5153

Browse files
committed
#40: Fix Pretty Output!
1 parent f5a5342 commit adc5153

2 files changed

Lines changed: 51 additions & 14 deletions

File tree

aider/coders/base_coder.py

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,11 @@ def get_announcements(self):
310310
else:
311311
lines.append("Repo-map: disabled")
312312

313-
if self.mcp_servers:
314-
server_names = [server.name for server in self.mcp_servers]
315-
lines.append(f"MCP servers configured: {', '.join(server_names)}")
313+
if self.mcp_tools:
314+
mcp_servers = []
315+
for server_name, server_tools in self.mcp_tools:
316+
mcp_servers.append(server_name)
317+
lines.append(f"MCP servers configured: {', '.join(mcp_servers)}")
316318

317319
for fname in self.abs_read_only_stubs_fnames:
318320
rel_fname = self.get_rel_fname(fname)
@@ -2101,12 +2103,45 @@ async def process_tool_calls(self, tool_call_response):
21012103

21022104
def _print_tool_call_info(self, server_tool_calls):
21032105
"""Print information about an MCP tool call."""
2104-
self.io.tool_output("Preparing to run MCP tools", bold=True)
2106+
self.io.tool_output("Preparing to run MCP tools", bold=False)
21052107

21062108
for server, tool_calls in server_tool_calls.items():
21072109
for tool_call in tool_calls:
21082110
self.io.tool_output(f"Tool Call: {tool_call.function.name}")
2109-
self.io.tool_output(f"Arguments: {tool_call.function.arguments}")
2111+
2112+
# Parse and format arguments as headers with values
2113+
if tool_call.function.arguments:
2114+
# Only do JSON unwrapping for tools containing "replace" in their name
2115+
if "replace" in tool_call.function.name.lower():
2116+
try:
2117+
args_dict = json.loads(tool_call.function.arguments)
2118+
first_key = True
2119+
for key, value in args_dict.items():
2120+
# Convert explicit \\n sequences to actual newlines using regex
2121+
# Only match \\n that is not preceded by any other backslashes
2122+
if isinstance(value, str):
2123+
value = re.sub(r"(?<!\\)\\n", "\n", value)
2124+
# Add extra newline before first key/header
2125+
if first_key:
2126+
self.io.tool_output("\n")
2127+
first_key = False
2128+
self.io.tool_output(f"{key}:")
2129+
# Split the value by newlines and output each line separately
2130+
if isinstance(value, str):
2131+
for line in value.split("\n"):
2132+
self.io.tool_output(f"{line}")
2133+
else:
2134+
self.io.tool_output(f"{str(value)}")
2135+
self.io.tool_output("")
2136+
except json.JSONDecodeError:
2137+
# If JSON parsing fails, show raw arguments
2138+
raw_args = tool_call.function.arguments
2139+
self.io.tool_output(f"Arguments: {raw_args}")
2140+
else:
2141+
# For non-replace tools, show raw arguments
2142+
raw_args = tool_call.function.arguments
2143+
self.io.tool_output(f"Arguments: {raw_args}")
2144+
21102145
self.io.tool_output(f"MCP Server: {server.name}")
21112146

21122147
if self.verbose:
@@ -2343,11 +2378,12 @@ async def get_all_server_tools():
23432378
tools = []
23442379

23452380
if len(tools) > 0:
2346-
self.io.tool_output("MCP servers configured:")
2347-
for server_name, server_tools in tools:
2348-
self.io.tool_output(f" - {server_name}")
2381+
if self.verbose:
2382+
self.io.tool_output("MCP servers configured:")
2383+
2384+
for server_name, server_tools in tools:
2385+
self.io.tool_output(f" - {server_name}")
23492386

2350-
if self.verbose:
23512387
for tool in server_tools:
23522388
tool_name = tool.get("function", {}).get("name", "unknown")
23532389
tool_desc = tool.get("function", {}).get("description", "").split("\n")[0]

aider/io.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,8 @@ def tool_output(self, *messages, log_only=False, bold=False):
12761276
if self.pretty:
12771277
if self.tool_output_color:
12781278
style["color"] = ensure_hash_prefix(self.tool_output_color)
1279-
style["reverse"] = bold
1279+
# if bold:
1280+
# style["bold"] = True
12801281

12811282
style = RichStyle(**style)
12821283

@@ -1311,8 +1312,8 @@ def render_markdown(self, text):
13111312

13121313
def stream_output(self, text, final=False):
13131314
"""
1314-
Simplified stream output that just prints content and lets prompt_toolkit
1315-
handle the incremental updates through its native diffing.
1315+
Stream output using Rich console to respect pretty print settings.
1316+
This preserves formatting, colors, and other Rich features during streaming.
13161317
"""
13171318
# Initialize buffer if not exists
13181319
if not hasattr(self, "_stream_buffer"):
@@ -1343,10 +1344,10 @@ def stream_output(self, text, final=False):
13431344

13441345
if not final:
13451346
if len(lines) > 1:
1346-
print(output, flush=True)
1347+
self.console.print(output)
13471348
else:
13481349
# Ensure any remaining buffered content is printed using the full response
1349-
print(output, flush=True)
1350+
self.console.print(output)
13501351
self.reset_streaming_response()
13511352

13521353
def reset_streaming_response(self):

0 commit comments

Comments
 (0)