diff --git a/agent_loop.py b/agent_loop.py
index 4f1a3947..d6cc3854 100644
--- a/agent_loop.py
+++ b/agent_loop.py
@@ -106,8 +106,8 @@ def _shrink_code(m):
preview = '\n'.join(body[:5])
return f'```{lang}\n{preview}\n ... ({len(body)} lines)\n```'
text = re.sub(r'```[\s\S]*?```', _shrink_code, text)
- for p in [r'[\s\S]*?', r'[\s\S]*?', r'(\r?\n){3,}']:
- text = re.sub(p, '\n\n' if '\\n' in p else '', text)
+ for p, repl in [(r'[\s\S]*?', ''), (r'[\s\S]*?', ''), (r'(\r?\n){3,}', '\n\n')]:
+ text = re.sub(p, repl, text)
return text.strip()
def _compact_tool_args(name, args):