Skip to main content

Crate ctx_exec

Crate ctx_exec 

Source
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§

CompressOptions
Tuning knobs for compress.
CompressResult
The result of a compression pass: the rendered text plus its statistics.
CompressStats
Deterministic statistics about a compression pass.
StreamCompressor
Streaming compressor: feed raw output bytes incrementally (as a command produces them) and render the same compressed view as compress on 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§

ExecError
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.