Skip to main content

Module truncate

Module truncate 

Source
Expand description

Output truncation helpers. Output truncation utilities for tool results Limits tool output by two independent limits (lines + bytes), whichever hits first. UTF-8 safe: truncates at valid character boundaries.

Structs§

TruncationOptions
Options for truncation
TruncationResult
Result of a truncation operation

Enums§

TruncatedBy
How truncation was applied

Constants§

DEFAULT_MAX_BYTES
Default max output bytes (50KB)
DEFAULT_MAX_LINES
Default max output lines
GREP_MAX_LINE_LENGTH
Max line length for grep output

Functions§

format_bytes
Format bytes for human-readable display
truncate_head
Truncate content from the head (keep first N lines/bytes). Never produces partial lines unless the first line itself exceeds byte limit.
truncate_line
Truncate a single line to a maximum character length. Appends “… [truncated]” if truncated.
truncate_tail
Truncate content from the tail (keep last N lines/bytes). May produce a partial first line if the last line of original exceeds byte limit.