aboutsummaryrefslogtreecommitdiff
path: root/src/util/truncate.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/truncate.ts')
-rw-r--r--src/util/truncate.ts6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/util/truncate.ts b/src/util/truncate.ts
index 2bf0600..7a1fa02 100644
--- a/src/util/truncate.ts
+++ b/src/util/truncate.ts
@@ -33,3 +33,9 @@ export const applyTruncation = async (output: string, prefix: string): Promise<T
const text = `${t.content}\n\n[Output truncated: ${t.outputLines} of ${t.totalLines} lines (${formatSize(t.outputBytes)} of ${formatSize(t.totalBytes)}). ${formatSize(omitted)} omitted. Full output: ${file}]`;
return { text, fullOutputPath: file, wasTruncated: true };
};
+
+export const formatBytes = (n: number): string => {
+ if (n >= 1_048_576) return `${(n / 1_048_576).toFixed(1)} MB`;
+ if (n >= 1024) return `${(n / 1024).toFixed(1)} KB`;
+ return `${n} B`;
+};