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.