Expand description
Snapcompact — bitmap-frame context compression for vision-capable LLMs.
Ported from omp (MIT) —
packages/snapcompact/src/snapcompact.ts. See
docs/ref-porter/xai-org-grok-build.md section E2 for design rationale.
§How it works
Instead of asking an LLM to summarize discarded history, snapcompact renders discarded text as dense bitmap frames that vision-capable models read back directly. Local and deterministic — no LLM call, no API key, no latency beyond rendering.
§Scope of this crate
Shape system, conversation serialization, shape selection, and
the full text→PNG rasterizer (ported from omp’s
pi-natives/src/snapcompact.rs — see the renderer submodule).
The renderer uses bundled BDF/HEX bitmap fonts plus the bundled
Silver TrueType font for non-Latin glyphs, all under permissive
licenses (see NOTICE.md).
compact() always returns real PNG-encoded bytes — there is no
“no-op renderer” path. When a frame fails to render, the error is
logged via tracing and that frame’s bytes are empty; the caller
can decide whether to drop or surface partial results.
Modules§
- renderer
- Renderer submodule — pi-natives ported text→PNG rasterizer.
Structs§
- Bounded
Source - The minimal envelope returned by
compactwhen no renderer is available — shape chosen, text chunked into per-frame source ranges, but frame bytes are empty. - Compact
Options - Options for
compact. - Compact
Preparation - Inputs to a compaction pass.
- Compact
Result - Outcome of a compaction pass.
- Frame
Range - Per-frame source range.
- Frame
Ref - A reference to a rendered frame.
- Shape
- One eval-validated frame shape.
Enums§
Constants§
- SHAPES
- Eval-validated shape table. Names match omp’s
SHAPE_VARIANTSkeys exactly so the Rust and TS registries stay in sync.
Functions§
- compact
- Run a compaction pass — render each frame slice through the
pi-natives ported renderer (
render_snapcompact_png) so the returned bytes are real PNG-encoded image data. - normalize
- Normalize conversation text for rasterization.
- prepare
- Render the conversation text into a serializable compact envelope.
- resolve_
shape - Pick the eval-validated shape for
model_id. - serialize_
conversation - Compact conversation text to one line per turn.