fix: preserve tool failures under noisy output

This commit is contained in:
wuyang
2026-07-26 16:14:26 +08:00
parent af141845ed
commit 87689931b5
6 changed files with 110 additions and 4 deletions
+15
View File
@@ -0,0 +1,15 @@
from __future__ import annotations
def truncate_middle(text: str, limit: int, marker: str = "\n… middle omitted …\n") -> str:
if limit <= 0:
return ""
if len(text) <= limit:
return text
if limit <= len(marker):
return text[:limit]
remaining = limit - len(marker)
head = (remaining + 1) // 2
tail = remaining - head
suffix = text[-tail:] if tail else ""
return text[:head] + marker + suffix