#!/bin/bash # Post-edit hook for Rust files in RuVector # Runs format check, clippy, and optional benchmarks set -e FILE="$1" RUN_BENCH="${2:-false}" if [ -z "$FILE" ]; then echo "Usage: $0 [run_bench]" exit 1 fi EXT="${FILE##*.}" if [ "$EXT" != "rs" ]; then exit 0 # Not a Rust file fi cd /workspaces/ruvector # Detect crate CRATE_DIR=$(echo "$FILE" | grep -oP "crates/[^/]+" | head -1 || echo "") CRATE_NAME="" if [ -n "$CRATE_DIR" ]; then CRATE_NAME=$(basename "$CRATE_DIR") fi echo "๐Ÿฆ€ Post-edit checks for: $FILE" # 1. Format check (don't auto-fix, just report) echo "" echo "๐Ÿ“ Checking format..." if cargo fmt --check -- "$FILE" 2>/dev/null; then echo " โœ… Format OK" else echo " โš ๏ธ Format issues detected (run: cargo fmt)" fi # 2. Quick clippy check for the crate if [ -n "$CRATE_NAME" ]; then echo "" echo "๐Ÿ“Ž Running clippy for $CRATE_NAME..." CLIPPY_OUT=$(cargo clippy -p "$CRATE_NAME" --message-format=short 2>&1 | grep -E "^(warning|error)" | head -5) if [ -z "$CLIPPY_OUT" ]; then echo " โœ… No clippy warnings" else echo "$CLIPPY_OUT" fi fi # 3. Check for test file and suggest tests TEST_FILE="${FILE%.rs}_test.rs" if [ -f "$TEST_FILE" ]; then echo "" echo "๐Ÿงช Test file exists: $TEST_FILE" fi # 4. WASM size check for wasm crates if echo "$FILE" | grep -qE "wasm|rvlite"; then echo "" echo "๐Ÿ“ WASM crate modified - consider running:" echo " cd crates/rvlite && wasm-pack build --release" echo " ls -lh pkg/*.wasm" fi # 5. Optional benchmark for performance-critical crates if [ "$RUN_BENCH" = "true" ]; then case "$CRATE_NAME" in "ruvector-core"|"ruvector-bench") echo "" echo "๐Ÿ“Š Running benchmarks..." cargo bench -p ruvector-bench -- --noplot 2>&1 | tail -20 ;; "ruvector-mincut") echo "" echo "๐Ÿ“Š Running mincut benchmarks..." cargo bench -p ruvector-mincut -- --noplot 2>&1 | tail -20 ;; "ruvector-attention") echo "" echo "๐Ÿ“Š Running attention benchmarks..." cargo bench -p ruvector-attention -- --noplot 2>&1 | tail -20 ;; esac fi # Store metrics METRICS_DIR="/workspaces/ruvector/.claude-flow/metrics" mkdir -p "$METRICS_DIR" # Record edit in metrics echo "{\"file\": \"$FILE\", \"crate\": \"$CRATE_NAME\", \"timestamp\": \"$(date -Iseconds)\"}" >> "$METRICS_DIR/edit-log.jsonl" echo "" echo "โœ… Post-edit checks complete"