99import pathlib
1010import requests
1111from packaging .version import parse as parse_version
12+ from .constants import DEFAULT_MAX_LINES , DEFAULT_MAX_CHARS
1213
1314
1415# Env/arg helper functions
@@ -124,10 +125,6 @@ def smooth_update(
124125
125126
126127# Other helper functions
127- DEFAULT_MAX_LINES = 50
128- DEFAULT_MAX_CHARS = 5000
129-
130-
131128def truncate_output (output : str , max_lines : int = DEFAULT_MAX_LINES , max_chars : int = DEFAULT_MAX_CHARS ) -> str :
132129 """Truncate the output to a reasonable size."""
133130 lines = output .splitlines ()
@@ -137,10 +134,21 @@ def truncate_output(output: str, max_lines: int = DEFAULT_MAX_LINES, max_chars:
137134 chars_truncated = len (output ) > max_chars
138135
139136 # Apply truncations to the original output
140- if lines_truncated :
137+ # When both limits apply, use the one that results in smaller output
138+ if lines_truncated and chars_truncated :
139+ lines_output = "\n " .join (lines [- max_lines :])
140+ chars_output = output [- max_chars :]
141+
142+ # Use whichever produces smaller result
143+ if len (lines_output ) <= len (chars_output ):
144+ output = lines_output
145+ chars_truncated = False # Only show line truncation message
146+ else :
147+ output = chars_output
148+ lines_truncated = False # Only show char truncation message
149+ elif lines_truncated :
141150 output = "\n " .join (lines [- max_lines :])
142-
143- if chars_truncated :
151+ elif chars_truncated :
144152 output = output [- max_chars :]
145153
146154 # Add prefixes for truncations that were applied
0 commit comments