Files
pxpipe/scripts
teamchong 482c967270 Add Rust port of proxy (unproven, not wired up)
Functional reimplementation in Rust with the same render_chunks/transform
public surface as src/proxy.py. Compiles clean on darwin-arm64, smoke-
tested but NOT YET battle-tested against real Claude Code sessions.

Layout:
  src/rust/
    Cargo.toml         hyper + tokio + reqwest + ab_glyph + png + clap
    Cargo.lock         committed (application crate, deterministic builds)
    src/main.rs        clap CLI matching bin/cli.js flags
    src/lib.rs         module roots
    src/font.rs        ab_glyph rasterization of bundled JetBrains Mono
    src/render.rs      newspaper-column text -> PNG (matches Python algo)
    src/transform.rs   request body transformation (system prompt -> image)
    src/proxy.rs       hyper HTTP server, upstream forwarding
    src/stats.rs       persisted savings counters mirroring proxy.py
    assets/JetBrainsMono-Regular.ttf  OFL-licensed, legally embeddable
    examples/render_sample.rs   smoke test: render fibonacci snippet
    examples/diff_render.rs     diff harness companion (paired with
                                scripts/diff_render.py)

Diff harness:
  scripts/diff_render.py   feeds same text through Python and Rust
                           render_chunks, decodes both PNGs, compares
                           pixel-by-pixel. First run found two divergences:

  1. Rust font.rs:43 uses ab_glyph h_advance which returns ~3.4px ceiled
     to 4 for Menlo-5pt 'M'; PIL's getlength('M') returns 3.0 exactly.
     Every Rust column is 33% wider than Python's.
  2. Python proxy.py:125 pads every single-column image to MAX_EDGE=1568
     height regardless of content (already noted in baseline commit).

Neither is fixed yet — surfacing the divergences before any swap. Next:
visual inspect both PNGs to confirm Rust output is at least OCR-readable,
then decide whether to fix bug-for-bug compat or correct both sides.

bin/cli.js still spawns Python; this commit only adds the Rust tree, it
does NOT change runtime behavior. The live proxy at :47821 is unaffected.
2026-05-18 11:52:32 -04:00
..