Skip to main content

Module code

Module code 

Source
Expand description

Source-code compressor — keep signatures, collapse bodies.

Inspired by Headroom’s CodeCompressor. The goal is to keep the structural skeleton an agent needs to navigate a file — imports, type/function/class signatures, top-level constants — while collapsing the deep bodies that dominate byte count.

This module currently ships the language-agnostic brace-depth heuristic: lines at brace nesting depth 0–1 are kept; deeper bodies collapse to a { … N lines … } placeholder. Lines carrying error/TODO markers are always kept. A higher-fidelity tree-sitter path (Rust/TS/Python) is layered on in a follow-up slice and selected by language; until then every language uses the heuristic. The router offloads the original to CCR for exact recovery.

Structs§

CodeCompressor

Constants§

MIN_BODY_LINES_TO_COLLAPSE
Bodies with more than this many collapsed lines get a placeholder; shorter ones are kept verbatim (collapsing tiny bodies isn’t worth the marker).

Functions§

compress_heuristic
Language-agnostic brace-depth compressor. Keeps lines at depth ≤ 1, collapses deeper runs. Returns None if it wouldn’t shrink the content.