Skip to main content

Crate sephera_compression

Crate sephera_compression 

Source
Expand description

Tree-sitter based code compression for LLM context packs.

This module provides AST-aware compression that extracts structurally significant parts of source files — function signatures, type definitions, imports, and optionally top-level control flow — while discarding implementation bodies.

The result is a dramatically smaller representation (typically 50–70 % fewer tokens) that still preserves the full API surface and architectural overview of the original source.

§Supported languages

Sephera embeds Tree-sitter grammars for: Rust, Python, TypeScript, JavaScript, Go, Java, C++, and C.

Files in unsupported languages fall back to uncompressed head-excerpt behaviour automatically.

§Example

use sephera_compression::{
    CompressionMode, SupportedLanguage, compress_source,
};

let source = b"fn add(a: i32, b: i32) -> i32 {\n    a + b\n}\n";
let result = compress_source(source, SupportedLanguage::Rust, CompressionMode::Signatures);
assert!(result.is_ok());
let output = result.unwrap();
assert!(output.content.contains("fn add("));
assert!(output.content.contains("{ … }"));

Re-exports§

pub use parser::SupportedLanguage;
pub use parser::new_parser;
pub use parser::with_parser;
pub use types::CompressedOutput;
pub use types::CompressionMode;

Modules§

parser
Tree-sitter parser management.
types

Functions§

compress_source
Compresses a source file using Tree-sitter AST extraction.
extract_compressed
Extracts a compressed representation from a fully parsed Tree-sitter tree.