Skip to main content

Module compact

Module compact 

Source
Expand description

Token-savings presentation: reshape ripgrep’s path:line:text stream into a compact, paginated view for agents. This is a pure transform over already-rendered output — matching stays 100% ripgrep (see confirm). The contract is deliberately weaker than the byte-for-byte CLI: the match set is identical to rg (nothing is ever dropped — pagination is the only volume control), but the presentation differs: the path is printed once per file, results are paged, and pathologically long lines are center-truncated on the match (one Read from full content).

Structs§

CompactOpts
Page
A rendered page: surface-agnostic header + body, plus the counts and keyset state each caller (CLI / MCP) needs to mint the “next page” cursor and detect a changed result set.

Constants§

DEFAULT_MAX_COLS
Default max rendered columns per line; normal code lines pass untouched, only long/minified lines get center-truncated on the match.
DEFAULT_PAGE_SIZE
Default matches per page. Generous: an agent pulls the next page cheaply (warm index).

Functions§

format
Reshape raw (ripgrep’s path:line:text output) into a compact page. pattern/opts are used only to locate the match within long lines for centered truncation. Pagination is keyset (resume after start_after), not offset, so it stays correct when the result set shifts between calls; mode selects the matches / files (-l) / count (-c) shape.