Skip to content

feat(bgcode): MeatPack G-code decoder (DD-011 phase 2) (#188) - #234

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

feat(bgcode): MeatPack G-code decoder (DD-011 phase 2) (#188)#234
sobechestnut-dev merged 1 commit into
devfrom
feat/188-bgcode-phase2

Conversation

@sobechestnut-dev

Copy link
Copy Markdown

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

What

The MeatPack G-code encoding (both variants — MeatPack and MeatPack (comments preserved)). A .bgcode GCode block encoded with MeatPack now decodes end-to-end (optionally after DEFLATE) to plain G-code.

Licensing — clean, and attributed

The decoder is a faithful TypeScript port of the MIT jamesgopsill/meatpack unpacker (© 2025 James Gopsill), which is itself derived from the published Prusa spec — attribution preserved in the source header. No AGPL libbgcode/OctoPrint-MeatPack code (RR-003 §8: port only from MIT/BSD/ISC with attribution).

Validation — independent oracle, not just round-trip

RR-003 flagged that the MeatPack table "must be reconstructed and validated, not lifted." Rather than a self-consistent round-trip (which shares the table's blind spot), the tests use hand-computed vectors — each expected byte stream is assembled by applying the published nibble table by hand, so a wrong table/order/escape is caught:

  • a realistic packable line G1 X2.5\n, left/right/double full-width escapes, the (\n,\n)→single-newline special case, the no-spaces and disable-packing commands, and invalid-command rejection;
  • plus block-level integration through openBgcode (None + DEFLATE × MeatPack/MeatPack-comments).

Output is bounded (decompression-bomb defense). Real PrusaSlicer meatpack files land in phase 4 for golden-equivalence.

Also: fixes a docs-build regression

bgcode.ts's {@link ContainerError} — an unresolvable cross-package typedoc link — landed in dev when #233's phase-1 fix was dropped in the squash-merge, pushing the API-docs warning budget to 4 > 3. This PR downgrades it to a code span, restoring 3/3.

Verification

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

🤖 Generated with Claude Code

Adds the MeatPack encoding (both variants) to the .bgcode decoder: a GCode block encoded with
MeatPack now decodes end-to-end (optionally after DEFLATE) to plain G-code.

The decoder is a faithful TS port of the MIT jamesgopsill/meatpack unpacker (© 2025 James Gopsill;
derived from the published Prusa spec), attribution preserved — NO AGPL libbgcode/OctoPrint-MeatPack
code (RR-003 §8). MeatPack packs the 15 most common g-code chars into 4-bit nibbles (first char =
low nibble); nibble 0xF escapes a full literal byte; FF FF <cmd> toggles packing/no-spaces; the
stream starts disabled (FF FF FB enables it).

Validated by HAND-COMPUTED vectors (the nibble table applied by hand as an oracle independent of the
decoder's own table): packable line, left/right/double full-width escapes, the (\n,\n)→single-newline
special case, no-spaces + disable-packing commands, invalid-command rejection — plus block-level
integration through openBgcode (None + DEFLATE × MeatPack/MeatPack-comments). Output is bounded
(bomb defense). Real PrusaSlicer meatpack files = phase-4 golden-equivalence.

Also fixes a docs-build regression: bgcode.ts's `{@link ContainerError}` (an unresolvable
cross-package typedoc link that landed in dev via #233's squash) → a code span, restoring the
API-docs warning budget to 3/3.

heatshrink compression remains phase 3.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@sobechestnut-dev
sobechestnut-dev enabled auto-merge (squash) July 27, 2026 20:12
@sobechestnut-dev
sobechestnut-dev merged commit 8c0ee6e 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