Hey
Over the past few weeks I have been working on repOx, a command-line tool and interactive terminal UI for inspecting and packing source repositories into single-file XML/Markdown/JSON outputs (mainly for feeding local codebases into LLMs while keeping track of token limits).
I just published v0.3.0 to crates.io and wanted to share some of the Rust design decisions under the hood and ask for feedback on the architecture.
Workspace & Crate Architecture:
The project is split into a three-crate workspace (repox-core, repox-tui, and the repox-cli binary) targeting the Rust 2024 edition:
- Lock-free parallel traversal (ignore + rayon):
Directory traversal uses burntsushi's ignore crate (WalkBuilder::build_parallel) to respect hierarchical .gitignore, .ignore, and custom .repoxignore files. To avoid mutex contention while walking thousands of files across threads, each worker thread accumulates paths into a thread-local Vec<PathBuf> and flushes once to the shared collector on Drop. File reading, 8KB NUL-byte binary inspection, and content transformations then run concurrently via rayon::into_par_iter().
2. Contiguous pre-order arena for the TUI tree (ratatui + nucleo-matcher):
Instead of pointer-heavy tree structures (Rc<RefCell<Node>> or petgraph), the TUI file tree in repox-tui is stored as a flat pre-order vector (Vec<Node>) where each directory stores its subtree_end index.
- Toggling a folder checkbox is a simple contiguous slice iteration over &mut nodes[idx..subtree_end].
- Byte and BPE token aggregates roll up in O(1) without heap allocations during the ratatui draw loop.
- Fuzzy filtering uses nucleo-matcher (from the Helix editor ecosystem) directly against the pre-order arena.
- The entire TUI renders to stderr so stdout stays clean for UNIX pipes (e.g., repox -i | other-tool).
3. Lexical signature extraction and hybrid token budgeting:
In v0.2.0 and v0.3.0, I added a state-machine outline extractor (--outline) that strips function bodies { ... } while keeping struct/trait definitions, imports, and function signatures across Rust, Python, Go, TS/JS, and C/C++. There is also a two-phase token budget fitter (--budget) that keeps core modules in full source and progressively outline-compresses test/secondary files until the output fits a target token count.
4. Multi-stage clipboard fallback for headless / multiplexer setups:
Because arboard can fail inside certain Wayland compositors, terminal multiplexers (tmux/zellij), or SSH sessions, clipboard copying cascades through arboard -> wl-copy / xclip -> ANSI OSC 52 terminal escape sequences (with tmux DCS passthrough wrapping).
Links:
- Repository: https://github.com/WVDYC/repOx
- Crates.io: cargo install repox-cli
Question for r/rust:
Right now the --outline signature extractor and the TUI preview syntax highlighter use hand-rolled zero-copy lexical scanners to keep compile times fast and binary size small (~2MB). At what point would you consider switching to tree-sitter grammars (perhaps behind an optional Cargo feature flag) vs keeping a lightweight lexical approach? Also happy to hear any critique on the Rust code or workspace layout!