From 86d402585c3ed477116ec5e09d33cd9e03d671b0 Mon Sep 17 00:00:00 2001 From: Hamza Hasan Ellahie Date: Tue, 24 Feb 2026 12:54:08 +0500 Subject: [PATCH 1/3] clip lines --- flexus_client_kit/format_utils.py | 34 ++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/flexus_client_kit/format_utils.py b/flexus_client_kit/format_utils.py index a68a4715..cda0dc07 100644 --- a/flexus_client_kit/format_utils.py +++ b/flexus_client_kit/format_utils.py @@ -113,21 +113,19 @@ def format_json_output( return result, truncated -def format_text_output( - path: str, +def clip_lines( content: str, lines_range: str = ":", safety_valve: str = DEFAULT_SAFETY_VALVE, line_offset: int = 0 ) -> str: - # Please leave this function alone -- Oleg safety_valve_chars = 0 if safety_valve.lower().endswith('k'): safety_valve_chars = int(safety_valve[:-1]) * 1000 else: safety_valve_chars = int(safety_valve) safety_valve_chars = max(1000, safety_valve_chars) - header_lines = [f"📄 {path}"] + warnings = [] lines = content.splitlines() if ":" in lines_range: start_str, end_str = lines_range.split(":", 1) @@ -147,21 +145,33 @@ def format_text_output( line = lines[i] if len(line) > safety_valve_chars: if len(result) > 0: - header_lines.append(f"⚠️ A single line {i+1} is so long that it alone is bigger than `safety_valve`, call again starting with that line in lines_range to see it.") - break - else: - header_lines.append(f"⚠️ A single line {i+1} is {len(line)} characters, truncated to `safety_valve` characters, increase safety_valve to see it in full.") - result = [line[:safety_valve_chars]] + warnings.append(f"⚠️ A single line {i+1} is so long that it alone is bigger than `safety_valve`, call again starting with that line in lines_range to see it.") break + warnings.append(f"⚠️ A single line {i+1} is {len(line)} characters, truncated to `safety_valve` characters, increase safety_valve to see it in full.") + result = [line[:safety_valve_chars]] + break ctx_left -= len(line) result.append(line) if ctx_left < 0: - header_lines.append(f"⚠️ The original preview is {len(content)} chars and {len(lines)} lines, showing lines range {line_offset+start+1}:{line_offset+i+1} because `safety_valve` hit") + warnings.append(f"⚠️ The original preview is {len(content)} chars and {len(lines)} lines, showing lines range {line_offset+start+1}:{line_offset+i+1} because `safety_valve` hit") break - result = header_lines + [""] + result + if warnings: + return "\n".join(warnings + [""] + result) return "\n".join(result) +def format_text_output( + path: str, + content: str, + lines_range: str = ":", + safety_valve: str = DEFAULT_SAFETY_VALVE, + line_offset: int = 0 +) -> str: + # Please leave this function alone -- Oleg + body = clip_lines(content, lines_range, safety_valve, line_offset) + return f"📄 {path}\n{body}" + + # XXX remove @deprecated("this function is garbage, remove") def format_binary_output( @@ -198,7 +208,7 @@ def format_binary_output( try: text_content = data.decode('utf-8') - return result + format_text_output(path, text_content, lines_range, safety_valve, line_offset) + return result + clip_lines(text_content, lines_range, safety_valve, line_offset) except UnicodeDecodeError: pass From d15f40b5fddaaa6bf70cec77e14b5854379a4342 Mon Sep 17 00:00:00 2001 From: Hamza Hasan Ellahie Date: Tue, 24 Feb 2026 13:33:15 +0500 Subject: [PATCH 2/3] delete wrong image handle --- flexus_client_kit/format_utils.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/flexus_client_kit/format_utils.py b/flexus_client_kit/format_utils.py index cda0dc07..cfa7539d 100644 --- a/flexus_client_kit/format_utils.py +++ b/flexus_client_kit/format_utils.py @@ -186,12 +186,8 @@ def format_binary_output( size_bytes = len(data) size_kb = size_bytes / 1024 - file_ext = Path(path).suffix.lower() - is_image = file_ext in IMAGE_EXTENSIONS - header_lines = [ f"📄 File: {path}", - f" Type: Binary {'Image' if is_image else 'File'}", f" Size: {size_bytes:,} bytes ({size_kb:.1f} KB)", f" {extra_header}" ] @@ -199,13 +195,6 @@ def format_binary_output( result = "\n".join(header_lines) result += "\n" + "─" * 50 + "\n" - if is_image: - base64_image = process_image_to_base64(data) - if base64_image: - result += f"![Image]({path})\n" - result += f"\n{base64_image}\n" - return result - try: text_content = data.decode('utf-8') return result + clip_lines(text_content, lines_range, safety_valve, line_offset) @@ -295,4 +284,3 @@ def grep_output( print(out) print() assert "Line 50" in out and "Line 51" not in out and "Line 49" not in out - From d498316bdf430e58309fb825afe411ae28784c56 Mon Sep 17 00:00:00 2001 From: Hamza Hasan Ellahie Date: Tue, 24 Feb 2026 13:51:04 +0500 Subject: [PATCH 3/3] remove imports --- flexus_client_kit/format_utils.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/flexus_client_kit/format_utils.py b/flexus_client_kit/format_utils.py index cfa7539d..fc0a0595 100644 --- a/flexus_client_kit/format_utils.py +++ b/flexus_client_kit/format_utils.py @@ -4,9 +4,8 @@ import base64 import logging from io import BytesIO -from pathlib import Path from re import Pattern -from typing import Union, Optional, List, Dict, Any, Tuple +from typing import Union, Optional, Tuple from typing_extensions import deprecated from PIL import Image