Skip to content

relayburn-reader: port Claude Code parser (#255)#293

Merged
willwashburn merged 1 commit intomainfrom
claude/close-issue-255-claude-parser
May 5, 2026
Merged

relayburn-reader: port Claude Code parser (#255)#293
willwashburn merged 1 commit intomainfrom
claude/close-issue-255-claude-parser

Conversation

@willwashburn
Copy link
Copy Markdown
Member

Summary

  • The synchronous parser, incremental parser, and cross-file reconciler shipped in PRs relayburn-reader: port Claude Code parser core (#255) #262 and relayburn-reader: port parseClaudeSessionIncremental to Rust (#255) #265 (both merged); this PR ports the remaining packages/reader/src/claude.test.ts cases into native cargo test assertions so the Rust port now gates on the same shared tests/fixtures/claude/ JSONL inputs as the TS suite.
  • Adds 35 new conformance tests covering tool-call back-population, fidelity coverage, compaction events, user-turn block sizing, content capture, and the full fork / continuation relationship suite — including in-memory evidence pairs that exercise the dedup paths in reconcile_claude_session_relationships.
  • Two judgment calls (also documented inline): user-turn token counts assert the heuristic shape because cl100k is not wired in Rust yet (tracked in [Rust port] relayburn-sdk: embedding API mirroring TS surface #246), and the relationship dedup test reproduces the canonical key inline rather than crossing the reader/ledger crate boundary, matching the TS test's own workaround.

Test plan

  • cargo test -p relayburn-reader (199 pass; 51 in claude::)
  • cargo build --workspace clean
  • cargo test --workspace green
  • pnpm run build && pnpm run test (873 TS tests still pass)
  • cargo fmt --check and cargo clippy --tests clean on the new code (pre-existing warnings on this file untouched)

Closes #255.

PRs #262 and #265 already landed `parse_claude_session`,
`parse_claude_session_incremental`, and
`reconcile_claude_session_relationships`. This commit closes out the
issue's acceptance gate by porting the remaining `claude.test.ts` cases
into Rust so the suite gates on the same shared fixtures the TS reader
gates on.

Adds 35 new lib tests under `mod tests` in `crates/relayburn-reader/src/claude.rs`,
covering the rest of the top `describe('parseClaudeSession', ...)`
block, the user-turn block sizing tests (issue #2), the content-capture
matrix, and the full fork / continuation reconciliation suite (#112) —
including in-memory evidence pairs that exercise the
`reconcile_claude_session_relationships` dedup paths.

Two judgment calls:

- The TS user-turn cases assert exact cl100k token counts (e.g. 4 for
  "please fix the build"). The Rust port has not wired cl100k yet
  (#246 tracks it; `HeuristicCounter` is the default), so the Rust
  test asserts the heuristic shape (`ceil(byte_len/4)`) plus the
  positive-on-both-sides invariant from the ±5% cl100k reconciliation
  test, with comments pointing at the cl100k follow-up.
- The TS dedup test imports a hash builder from `@relayburn/ledger`
  via a comment workaround. The Rust test reproduces the canonical
  key inline (source + sessionId + relationshipType + relatedSessionId
  + agentId + parentToolUseId) — exactly what the TS test does — to
  avoid a cross-crate test dependency.

`cargo test -p relayburn-reader` passes 199 tests (51 in `claude::`).
`cargo test --workspace` and `pnpm run build && pnpm run test`
(873 TS tests) both green; clippy + fmt clean on the new code.

Closes #255.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 5, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1a0d1e23-4fda-4b0e-a9df-d97f4644c546

📥 Commits

Reviewing files that changed from the base of the PR and between 7c7ce35 and 0150288.

📒 Files selected for processing (1)
  • crates/relayburn-reader/src/claude.rs

📝 Walkthrough

Walkthrough

This PR adds 1,160 lines of conformance test cases to the Claude session parser (claude.rs), validating synchronous and incremental parsing, content capture modes, token sizing heuristics, tool-call metadata backfilling, fidelity classification, relationship emission (root/subagent), system notifications, fork/continuation logic, and cross-file reconciliation with deduplication.

Changes

Claude Parser Conformance Tests

Layer / File(s) Summary
Test Imports
crates/relayburn-reader/src/claude.rs (lines 3042)
Expanded imports to include FidelityClass and UserTurnBlockKind for test assertions.
Synchronous Parsing & Metadata
crates/relayburn-reader/src/claude.rs (lines 3704–4033)
Added tests validating project/usage surface parsing, multi-block deduplication, stable args_hash, tool-call error backfilling, replacement metadata propagation, edit hash extraction, tool-result event chronology, root/subagent relationship emission, system subagent notifications, and fidelity/compaction event behavior.
Token Sizing & Heuristics
crates/relayburn-reader/src/claude.rs (lines 4035–4177)
Added tests for user-turn block sizing, token heuristics (including cl100k non-wired expectations), explicit heuristic tokenizer opt-in, and user-turn record emission for text sessions.
Content Capture Modes
crates/relayburn-reader/src/claude.rs (lines 4179–4315)
Added tests for content mode defaults, hash-only behavior, full content capture for user/assistant text, chronological interleaving preservation, and tool_use block surfacing in assistant content.
Fork & Continuation Relationships
crates/relayburn-reader/src/claude.rs (lines 4328–4525)
Added tests for resume marker relationships, provenance with differing basenames vs. in-log IDs, explicit continuedFrom/fork session ID handling, reconciliation edge skipping, first_parent_uuid gating, and cross-file evidence requirements.
Cross-File Reconciliation
crates/relayburn-reader/src/claude.rs (lines 4557–4683)
Added tests validating parent UUID evidence spanning files, continuation emission for cross-file parent matches, fork row emission when files share a source session ID, and strict continuation case handling without fork emission.
Deduplication & Stability
crates/relayburn-reader/src/claude.rs (lines 4729–4861)
Added tests ensuring relationship dedup keys remain stable across re-parses, reconciliation avoids duplicate continuation edges for local /resume references, and subagent rows carry provenance when basename differs from in-log session ID.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30 minutes

Possibly related issues

  • [Rust port] relayburn-reader: Claude Code parser (claude.rs) #255 — [Rust port] relayburn-reader: Claude Code parser (claude.rs): This PR fulfills the conformance gate requirement by implementing the full test suite that validates parseClaudeSession, parseClaudeSessionIncremental, and reconcileClaudeSessionRelationships against all expected scenarios from the original TypeScript test suite.
  • [Rust port] relayburn-reader: parsers + classifier #242 — Rust port foundation: This PR builds on the foundational port infrastructure (types, hash, classifier modules) to deliver the complete Claude parser conformance validation.

Poem

🐰 Hippity-hop through test forests so green,
Each assertion a carrot, each fixture pristine,
From forks to continuations, the parser now gleams—
A warren of tests fulfilling our schemes!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'relayburn-reader: port Claude Code parser (#255)' clearly and specifically summarizes the main objective—porting the Claude Code parser to Rust—matching the changeset's focus on adding test coverage for the claude.rs module.
Description check ✅ Passed The description comprehensively documents the porting effort, listing specific test categories added, documented trade-offs, test results, and issue closure, all directly relevant to the changeset of extending claude.rs test coverage.
Linked Issues check ✅ Passed The PR fulfills issue #255 acceptance criteria: it expands claude.rs test coverage to match packages/reader/src/claude.test.ts, implements 35 new conformance tests covering tool-call, fidelity, relationships and other specified domains, and reports passing the full test suite against shared fixtures.
Out of Scope Changes check ✅ Passed All changes are scoped to extending claude.rs test coverage (imports, conformance tests) directly addressing issue #255's requirement to port test cases and achieve byte-identical output on shared fixtures.
Docstring Coverage ✅ Passed Docstring coverage is 94.74% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/close-issue-255-claude-parser

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

@willwashburn willwashburn merged commit 146bf7b into main May 5, 2026
3 checks passed
@willwashburn willwashburn deleted the claude/close-issue-255-claude-parser branch May 5, 2026 15:07
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.

[Rust port] relayburn-reader: Claude Code parser (claude.rs)

1 participant