Skip to content

diff_context schema is hand-written three times; the Rust copy is the one that never runs #229

Description

@nikolay-e

The diff_context document shape exists in three independent
hand-maintained copies:

  1. crates/diffctx-native/src/render.rs:46-77 — the serde structs, consumed by
    main.rs:322-326;
  2. crates/diffctx-native/src/pybridge.rs:207-303 — ~97 lines of set_item;
  3. src/diffctx/writer.py — four emitters plus _has_diff_metadata enumerating
    the key set a fourth time.

On every diffctx . --diff from the installed wheel, copies 2 and 3 run and
copy 1 does not.
pybridge.rs:195-206 already documents this exact shape
losing pre_phase_ms at two call sites at once (#183) — the fork was closed
inside Rust and left open across the language boundary.

Observed drift today, and it is user-visible rather than cosmetic:
main.rs:322-327 hard-errors on anything but json/yaml
("unsupported --format (native binary: yaml, json)"). So cargo install diffctx gets no md — the documented default output — no txt, no graph
subcommand, and none of -o/-c/-i/-w
, because all of that lives only in the
Python layer. raw_diff exists in copies 2 and 3 only, injected Python-side at
_native/pipeline.py:183, so --with-raw-diff is likewise wheel-only.

Two things worth separating:

  • the duplication (collapsing copy 3 onto copy 1 is roughly −320 Python /
    −97 Rust, the largest single reduction found in the audit), and
  • the product question the duplication hides: is the crates.io binary meant
    to be a second-class surface? If yes, say so in the README, because today it
    advertises the Python feature set. If no, markdown rendering has to move into
    the engine.

Medium risk: tree mode still needs a dict path, so this is not a mechanical
collapse. Gate: scripts/bitcheck.sh covers the native side only, so the
Python emitters need their own byte-diff through the installed wheel (3 ranges x
{yaml,json,txt,md}) on top of the corpus run.

Found during the code-cleanliness tournament (2026-08-20); protocol in
ANALYSIS_code_cleanliness_refactoring.md §F11.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions