Skip to content

feat(bgcode): heatshrink decompression (DD-011 phase 3) (#188) - #235

Merged
sobechestnut-dev merged 1 commit into
devfrom
feat/188-bgcode-phase3
Jul 27, 2026
Merged

feat(bgcode): heatshrink decompression (DD-011 phase 3) (#188)#235
sobechestnut-dev merged 1 commit into
devfrom
feat/188-bgcode-phase3

Conversation

@sobechestnut-dev

Copy link
Copy Markdown

Phase 3 of the #188 bgcode epic (DD-011 §14). Does not close #188 — container-adapter integration + real-file golden-equivalence (phase 4) and the §7.3 review (phase 5) remain.

What

heatshrink (LZSS) decompression — windows 11 & 12, lookahead 4. With this, all four spec compression codecs (None / DEFLATE / heatshrink-11 / heatshrink-12) and all encodings (None / MeatPack / MeatPack-comments) are decoded. A heatshrink-compressed .bgcode GCode block now decodes end-to-end to plain G-code.

Licensing — clean, attributed

A TypeScript port of the LZSS decoder from the ISC atomicobject/heatshrink (© 2013–2015 Scott Vokes) — attribution in the source header. ISC is permissive/MIT-compatible; no AGPL libbgcode (RR-003 §8).

Validation — independent oracle

Vectors are built by an independent MSB-first bit-packer from the wire format (a separate code path from the decoder's reader), so decode(pack(tokens)) === expected checks the decoder against the spec, not itself: literals, single- and multi-byte back-references, offset-2 interleaving (ABABAB), self-referential runs (copy length > offset), window 11 & 12, a realistic repeated G-code fragment, the bomb cap, and block-level integration through openBgcode. Real PrusaSlicer heatshrink files land in phase 4 for golden-equivalence.

Verification

typeCheck ✓, lint ✓ (0 errors), docs:build ✓ (3/3), CI-like test:packages ✓ (30 bgcode tests across 3 files), pack:check ✓ (additive heatshrink.* snapshot).

🤖 Generated with Claude Code

Adds heatshrink (LZSS) decompression — windows 11 & 12, lookahead 4 — to the .bgcode decoder. With
this, ALL four spec compression codecs (None/DEFLATE/heatshrink-11/heatshrink-12) and all encodings
(None/MeatPack/MeatPack-comments) are decoded; a heatshrink-compressed GCode block now decodes
end-to-end to plain G-code.

The decoder is a TS port of the LZSS decoder from the ISC atomicobject/heatshrink (© 2013-2015 Scott
Vokes), attribution preserved — no AGPL libbgcode (RR-003 §8). Wire format: MSB-first bit stream;
tag bit (1=literal 8 bits; 0=backref of windowBits index + lookaheadBits count, each value-1); a
backref copies count+1 bytes from index+1 back in a circular window, re-emitting each (self-referential
runs supported).

Validated against vectors built by an INDEPENDENT MSB-first bit-packer from the spec (literals, single
+ multi-byte backrefs, offset-2 interleaving, self-referential runs, window 11 & 12, a realistic
repeated g-code fragment) + block-level integration through openBgcode. Output bounded (bomb defense).
The stale phase-1 "heatshrink unsupported" test → an unknown-compression-id rejection. Real PrusaSlicer
heatshrink files = phase-4 golden-equivalence.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@sobechestnut-dev
sobechestnut-dev enabled auto-merge (squash) July 27, 2026 20:27
@sobechestnut-dev
sobechestnut-dev merged commit bb3085a into dev Jul 27, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

epic: Binary G-code (.bgcode) decode support

1 participant