From e2e8243c62fa38cc18b679e4bc5d9f66f1e08de1 Mon Sep 17 00:00:00 2001 From: Levi Neely Date: Mon, 1 Jun 2026 09:52:20 +0200 Subject: [PATCH] Update file_read tool and 9p permissions --- tools/file_read | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tools/file_read b/tools/file_read index 55da563..1cc84cf 100644 --- a/tools/file_read +++ b/tools/file_read @@ -61,6 +61,10 @@ with open(file_path, 'rb') as f: print("(binary file)") sys.exit(0) +# Count total lines +with open(file_path, 'r', errors='replace') as f: + total_lines = sum(1 for _ in f) + start = max(1, start) if head: end = start + head - 1 @@ -76,10 +80,10 @@ with open(file_path, 'r', errors='replace') as f: if not segment_lines: if start == 1: - print("STATUS=ok EMPTY=true") + print(f"STATUS=ok LINES=0 TOTAL_LINES={total_lines} TRUNCATED=false EMPTY=true") print("(empty file)") else: - print("STATUS=ok EMPTY=true") + print(f"STATUS=ok LINES=0 TOTAL_LINES={total_lines} TRUNCATED=false EMPTY=true") print("(no lines in range)") sys.exit(0) @@ -91,5 +95,7 @@ for i, line in enumerate(segment_lines): text = text[:MAX_LINE_LEN] + '...' out.append(f"{lineno:>6}\t{text}") -print(f"STATUS=ok LINES={len(out)}") +last_line_shown = start + len(out) - 1 +truncated = last_line_shown < total_lines +print(f"STATUS=ok LINES={len(out)} TOTAL_LINES={total_lines} TRUNCATED={str(truncated).lower()}") print('\n'.join(out))