Skip to content

Commit 5b073cd

Browse files
committed
🤖 Remove decimal precision from file sizes to preserve tokens
Change formatSize() to use Math.round() instead of toFixed(1): - Before: 1.5KB, 2.3MB - After: 2KB, 2MB No decimals in file sizes preserves tokens in LLM output without sacrificing meaningful precision for directory listings. Tests still pass as they use regex patterns matching both formats.
1 parent f7ae61c commit 5b073cd

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/services/tools/file_list.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,12 @@ function formatTreeAsString(entries: FileEntry[], indent = "", isLast: boolean[]
5454

5555
/**
5656
* Format a file size in bytes to a human-readable string
57+
* No decimals to preserve tokens in LLM output
5758
*/
5859
function formatSize(bytes: number): string {
5960
if (bytes < 1024) return `${bytes}B`;
60-
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)}KB`;
61-
return `${(bytes / (1024 * 1024)).toFixed(1)}MB`;
61+
if (bytes < 1024 * 1024) return `${Math.round(bytes / 1024)}KB`;
62+
return `${Math.round(bytes / (1024 * 1024))}MB`;
6263
}
6364

6465
/**

0 commit comments

Comments
 (0)