Skip to content

WIP: BibTeX engine (KC-108 r2, paused) - #97

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

jay3332 merged 2 commits into
mainfrom
agent/kabir-claude/bibtex-r2

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

WIP and paused by the coordinator. This supersedes #91 and changes only crates/bibtex-bst/**.

Done (commit 3157147)

  • Engine (src/engine.rs, bst.rs, bib.rs, exec.rs, names.rs): a port of bibtex.web 0.99e plus TeX Live's bibtex.ch. The code comments cite section numbers. It covers:
    • .aux reading, including \@input, \citation{*} and all the error messages.
    • .bst parsing, with the same error recovery as BibTeX.
    • All 37 built-in functions, including format.name$, change.case$, purify$ and width$.
    • .bib parsing: @string, @preamble, # concatenation, crossref with min_crossrefs, and duplicate or missing entries.
    • Sorting, 79-column .bbl line breaking, and the .blg messages, history line and usage statistics.
    • web2c eof/eoln behaviour: CR counts as a line end, so CRLF yields an extra blank line. This was checked against the oracle.
  • API (src/lib.rs):
    • run(aux, &dyn FileSource, &Options) -> Output {bbl, blg, history, err_count}
    • DirSource
    • Output::diagnostics() / warnings()
    • Session, which reuses the cached result when every file the last run looked up still has the same hash.
  • Oracle:
    • tests/oracle/generate.py runs MacTeX bibtex (BibTeX 0.99e, TeX Live 2026) and is the only thing that does.
    • It covers 95 cases: 11 styles × 5 databases, the error database × 4 styles, and cases for explicit and missing cites, case mismatches, several .bib files, \@input, missing style or bib, .aux errors, crossref min/nested/case, tricky .bib syntax, CRLF and CR-only files, and two original test styles (builtins.bst, badstyle.bst).
    • Inputs are in tests/data/cases/ and expected output in tests/data/expected/.
    • tests/oracle.rs never runs bibtex.

Oracle status (measured at 3157147)

  • .bbl byte-identical: 95/95.
  • .blg identical, ignoring only the banner, the Capacity: line and the statistics block: 89/95.
  • .blg byte-identical: 89/95.
  • The 6 failures (badstyle, builtins-*) all first differ at a web2c log line the engine does not emit yet: Reallocated singl_function (elt_size=4) to 100 items from 50.

Not done / exact resume steps

  1. git fetch origin && git checkout agent/kabir-claude/bibtex-r2
  2. Emulate the web2c BIB_XRETALLOC log lines (Reallocated %s (elt_size=%ld) to %ld items from %ld., written to the log only), as specified in bibtex.ch:
    • singl_function: starts at 50 and grows by 50. It is local to each scan_fn_def call, and the check runs after the item is stored, when single_ptr == space ([188]).
    • wiz_functions: starts at 3000 and grows by 3000 at §200.
    • field_info: starts at 5000. It grows to total + 5000 when total > max ([226]/[265]).
    • cite_list, type_list, entry_exists, cite_info: start at 750 and grow by 750 ([138]).
    • bib_list, bib_file, s_preamble: start at 20 and grow by 20 ([123]/[242]).
    • lit_stack, lit_stk_type: start at 50 and grow by 50 ([307]).
    • glb_str_ptr, global_strs, glb_str_end: start at 10 and grow by 10 ([216]). global_strs has elt_size = glob_str_size + 1.
    • str_pool: starts at 65000 and grows by 65000 ([53]). Simulate pool_ptr as the permanent pool characters plus the temporary strings on the literal stack, and check it at each str_room site.
    • The six buffers: start at 20000 and grow by 20000 (buffer_overflow [46]). The copy_char message Field filled up at N, reallocating. comes with it ([251]).
    • Unverified element sizes: boolean, alpha_file and stk_type. Confirm them with new oracle cases (planned: 800 entries, 760 explicit cites, 22 bib files with preambles, a capacity-stressing style, and a field over 20000 characters).
  3. Regenerate the expected files: python3 crates/bibtex-bst/tests/oracle/generate.py.
  4. Run the tests:
    CARGO_BUILD_JOBS=3 ORACLE_VERBOSE=1 cargo test --manifest-path crates/bibtex-bst/Cargo.toml --test oracle -- --nocapture
  5. Write unit tests for the Session API. Write CONTRACT.md: the adoption plan for crates/compiler and crates/bibliography, where a .bst fallback replaces the hard-coded plain/unsrt/alpha styles.
  6. Known edge cases that are deliberately not emulated, to document:
    • Hash-probe coincidences in §259, when macro_name_loc is not found.
    • Uninitialized-memory reads on malformed format.name$ input.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

GoKubar and others added 2 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
@GoKubar

GoKubar commented Sep 13, 2026

Copy link
Copy Markdown
Contributor Author

Resumed and finished in #100 (oracle now 99/99 .bbl/.blg; Session tests; CONTRACT.md). Superseded by that PR.

@jay3332
jay3332 merged commit 3157147 into main Sep 13, 2026
14 of 18 checks passed
@GoKubar
GoKubar deleted the agent/kabir-claude/bibtex-r2 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