Skip to content

BibTeX engine (KC-108) - #100

Merged
jay3332 merged 3 commits into
mainfrom
agent/kabir-claude/bibtex-r3
Sep 13, 2026
Merged

jay3332 merged 3 commits into
mainfrom
agent/kabir-claude/bibtex-r3

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Finishes KC-108, resuming from #97 (draft, superseded by this PR). Owns
crates/bibtex-bst/** only.

Summary

  • A from-scratch Rust port of BibTeX 0.99e (bibtex.web + TeX Live's
    bibtex.ch): .aux/.bst/.bib reading, all 37 built-ins, crossrefs,
    sorting, 79-column .bbl line breaking, and .blg messages/history/usage
    statistics.
  • run() API (Output { bbl, blg, history, err_count }), DirSource, and
    Session (reuses the cached result when every file the previous run looked
    up is unchanged).
  • This revision emulates TeX Live's web2c array-reallocation log lines
    (Reallocated <name> (elt_size=N) to M items from K.) for
    singl_function, wiz_functions, cite_list/type_list/entry_exists/
    cite_info, field_info, bib_list/bib_file/s_preamble, and
    glb_str_ptr/global_strs/glb_str_end/lit_stack/lit_stk_type —
    fixing all 6 previously-failing .blg oracle cases. Growth rules and
    elt_size values are taken from bibtex.ch/bibtex.web and cross-checked
    against the installed TeX Live bibtex binary; str_pool and the
    buffer group are deliberately left unemulated (documented in
    CONTRACT.md, with reasoning).
  • 4 new oracle cases exercising these reallocations.
  • 6 Session unit tests (cache hit, rerun on .aux/.bib/.bst change,
    invalidate, distinct Options not conflated).
  • CONTRACT.md: an adoption proposal for crates/compiler and
    crates/bibliography (owner mac-bibliography), describing how
    \bibliography/\bibliographystyle/\cite would flow through this
    engine in place of the hard-coded plain/unsrt/alpha styles, and
    Session's incremental-recompile behavior.

Oracle status

  • 99 cases (95 original + 4 new capacity-limit cases).
  • .bbl byte-identical: 99/99.
  • .blg byte-identical: 99/99.

Test plan

  • cargo test --manifest-path crates/bibtex-bst/Cargo.toml (oracle: 99/99
    .bbl and .blg; 6 Session unit tests; doctest) — all green.
  • cargo clippy --manifest-path crates/bibtex-bst/Cargo.toml --all-targets -- -D warnings — 5 pre-existing findings from before this revision
    (unrelated to these changes; not introduced here), no new ones.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

GoKubar and others added 3 commits September 13, 2026 02:24
…8, paused)

New crate crates/bibtex-bst (not yet buildable: src/lib.rs and engine
modules not written). Contains the bibtex.web character classes and cmr10
width table, six tricky .bib fixture databases, and unmodified copies of
the 11 TeX Live styles used as oracle inputs. No expected outputs yet.

Implementation-Agent: Claude Opus 5 (subagent kabir-claude KC-108, mac-m5pro-kabir)
Commit-Executor: Claude Code direct Git
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
…used)

WIP (paused by coordinator). Engine is a faithful port of bibtex.web 0.99e
plus TeX Live bibtex.ch: .aux reading, .bst parsing/execution with all 37
built-ins, .bib parsing, crossrefs, sorting, 79-column .bbl output, .blg
messages and usage statistics. Oracle: 95 cases generated with TeX Live
bibtex; .bbl byte-identical 95/95, .blg identical 89/95. The 6 .blg
mismatches are the missing web2c "Reallocated ..." log lines (not yet
emulated).

Implementation-Agent: Claude Opus 5 (subagent kabir-claude KC-108 r2, mac-m5pro-kabir)
Commit-Executor: Claude Code direct Git
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
…ONTRACT.md (KC-108)

Fixes the 6 remaining .blg oracle mismatches (badstyle, builtins-*), which all
first differed at TeX Live's `Reallocated singl_function ...` log line: BibTeX's
originally fixed-size Pascal arrays are dynamically grown by web2c's
BIB_XRETALLOC, which also writes one `.blg` line per growth. This emulates that
growth and logging for singl_function, wiz_functions, cite_list/type_list/
entry_exists/cite_info, field_info, bib_list/bib_file/s_preamble, and
glb_str_ptr/global_strs/glb_str_end/lit_stack/lit_stk_type, with every growth
rule, elt_size and log format taken from bibtex.ch/bibtex.web and cross-checked
against the installed TeX Live bibtex binary.

Adds 4 new oracle cases exercising these reallocations (cite-overflow,
bib-files-overflow, glob-str-overflow, lit-stack-overflow) plus two supporting
.bst fixtures; oracle is now 99/99 for both .bbl and .blg, byte-identical.

Adds 6 Session unit tests (cache hit on unchanged inputs, rerun on .aux/.bib/
.bst changes, invalidate, distinct Options are not conflated).

Adds CONTRACT.md: an adoption proposal for crates/compiler and
crates/bibliography describing how \bibliography/\bibliographystyle/\cite
would flow through this engine (replacing the hard-coded plain/unsrt/alpha
styles with real .bst execution), Session's incremental-recompile behavior,
and what's verified vs. believed — including the two reallocation types
(str_pool, the buffer group) deliberately left unemulated with the reasoning
for why, confirmed empirically but not wired in.

Implementation-Agent: Claude Sonnet 5 (subagent kabir-claude KC-108 r3, mac-m5pro-kabir)
Commit-Executor: Claude Code direct Git
Co-Authored-By: Claude Sonnet 5 <[email protected]>
@jay3332
jay3332 merged commit fe864d9 into main Sep 13, 2026
12 of 18 checks passed
@jay3332

jay3332 commented Sep 13, 2026

Copy link
Copy Markdown
Member

Merged to main via integration/2026-09-13e (Commander).

@GoKubar
GoKubar deleted the agent/kabir-claude/bibtex-r3 branch September 13, 2026 18:12
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