Skip to content

Phase 2: .theos v2 binary format - #4

Merged
JFrusher merged 3 commits into
phase-1-languagefrom
phase-2-binary
Oct 24, 2026
Merged

JFrusher merged 3 commits into
phase-1-languagefrom
phase-2-binary

Conversation

@JFrusher

Copy link
Copy Markdown
Owner

Stacked on #3. Implements Phase 2 of ROADMAP.md.

  • M2.1 docs/spec/theos-v2.md: PNG-style signature, CRC-protected header and chunks, critical/ancillary chunk rule, fixed-width little-endian records referencing each other by index, and an annotated hex example checked against real output.
  • M2.2 Encoder/decoder (src/core/binary.cpp): deduplicated strings, an expression DAG where children always come before parents (so decoding is one forward pass and cannot loop), plus nodes, edges, axioms, definitions, objections and proofs. Every offset and index is bounds-checked; padding must be zero; nesting depth is capped.
  • M2.3 Byte-stable golden file; libFuzzer targets for the decoder and parser, run 60 s each in a new CI job. Locally: 1.3M decoder runs and 430k parser runs, no crashes.
  • M2.4 theosc build, theosc inspect, theosc inspect --chunks (chunk table + hex view).

Tests include flipping every byte of an encoded file and checking each corruption is detected. Verified: removing the padding check makes the test fail at a padding byte. They also cover every truncation, CRLF conversion caught by the signature, and the unknown-chunk rules.

Toolchain finding: Clang 18 cannot see std::expected in libstdc++ 13 (__cpp_concepts 201907), and mixing libc++ with libFuzzer's libstdc++ runtime caused an ASan alloc-dealloc mismatch. The Clang CI job and the fuzzers therefore use Clang 19.


Generated by Claude Code

- docs/spec/theos-v2.md: signature, CRC-protected header and chunks,
  critical/ancillary chunk rule, fixed-width little-endian records,
  annotated hex example
- Encoder/decoder in src/core/binary.cpp: deduplicated string table,
  expression DAG with children-before-parents ordering, nodes, edges,
  axioms, definitions, objections and proofs
- Reader rejects any out-of-range offset or index, bad CRC, non-zero
  padding, repeated or unknown critical chunks, and over-deep nesting
- theosc build / inspect / inspect --chunks (chunk table + hex view)
- Tests: round trip of every example, byte-stable golden file, every
  single-byte corruption and every truncation detected, line-ending
  conversion caught by the signature, chunk forward-compatibility rules
- libFuzzer targets for the decoder and the parser, run 60 s each in CI
- Clang CI moves to Clang 19 (libstdc++ std::expected support)
- context.md removed (superseded by the v2 spec)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019WEmxyo9CRKSbjbEdCuJTG
@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1f1d19de-db97-4ce4-b28f-fe0783ce5af9
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@JFrusher
JFrusher marked this pull request as ready for review October 24, 2026 23:21
@JFrusher
JFrusher merged commit 8c50c8e into phase-1-language Oct 24, 2026
5 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.

2 participants