Expand description
ctx-exec — token-efficient command output compression.
Compresses captured command output while keeping the signal: lines that
match critical patterns (error, warning, failed, panic, …) or user-supplied
--keep patterns survive verbatim, the first/last few lines form a summary
head/tail, and everything in between folds into a single deterministic
marker: ... [N lines omitted].
Matching is rule-driven with the regex crate — the same engine ripgrep
uses — so patterns follow rg’s default regex syntax (case-insensitive by
default, matching rg’s default behavior).
Byte-stable by design: output is a pure function of the input text and the options. No timestamps, no counters, no environment dependence.
Structs§
- Compress
Options - Tuning knobs for
compress. - Compress
Result - The result of a compression pass: the rendered text plus its statistics.
- Compress
Stats - Deterministic statistics about a compression pass.
- Stream
Compressor - Streaming compressor: feed raw output bytes incrementally (as a command
produces them) and render the same compressed view as
compresson finish. Memory stays bounded by the head/tail windows and the lines that match keep patterns — the mass of uninteresting middle lines is only counted, never stored, so a command emitting gigabytes cannot exhaust memory.
Enums§
- Exec
Error - Errors produced by the compression engine.
Constants§
- DEFAULT_
COLLAPSE_ THRESHOLD - Outputs at or below this many lines are passed through uncompressed.
- DEFAULT_
HEAD_ LINES - Default number of leading lines kept verbatim as the head summary.
- DEFAULT_
KEEP_ PATTERNS - Default keep patterns (cli-contract.md §7). Lines matching any of these (case-insensitive) are always kept, wherever they appear in the output.
- DEFAULT_
TAIL_ LINES - Default number of trailing lines kept verbatim as the tail summary.
Functions§
- compress
- Compress command output.
- estimate_
tokens - Real token count via the cl100k_base BPE tokenizer (GPT-4-class; see cli-contract.md §8). A deterministic function of the text, so byte stability is unaffected. The bundled encoding is parsed once and cached.