Skip to main content

Module truncate

Module truncate 

Source
Expand description

Shared truncation utilities (core/tools/truncate.ts).

Tools return bounded output: read/write/ls use head-truncation, bash uses tail-truncation (keep the most recent output), and grep truncates long individual lines.

Structs§

TruncationResult

Constants§

DEFAULT_MAX_BYTES
Default byte cap for tool output (50 KiB). Matches pi’s core/tools/truncate.ts.
DEFAULT_MAX_LINES
Default line cap for tool output (matches Claude Code / pi).
GREP_MAX_LINE_LENGTH
Maximum length of a single grep result line. Matches pi’s GREP_MAX_LINE_LENGTH.

Functions§

format_size
Human-readable byte size, e.g. “12.3KB”.
truncate_head
Truncate from the head (keep the first lines), used by read/write/ls. Stops at whichever limit is hit first: max_lines or max_bytes.
truncate_line
Truncate a single (possibly very long) line for grep output.
truncate_tail
Truncate from the tail (keep the most recent output), used by bash.