fix: preserve tool failures under noisy output
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user