Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions .claude/hooks/bench-runner.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/bin/bash
# Benchmark runner with baseline comparison for RuVector
# Integrates with criterion benchmarks and stores results

set -e

CRATE="${1:-all}"
BASELINE_DIR="/workspaces/ruvector/.claude-flow/metrics/benchmarks"
mkdir -p "$BASELINE_DIR"

cd /workspaces/ruvector

echo "📊 RuVector Benchmark Runner"
echo "============================"
echo ""

run_bench() {
local crate=$1
local bench_name=$2
local output_file="$BASELINE_DIR/${crate}-$(date +%Y%m%d-%H%M%S).json"

echo "🏃 Running: cargo bench -p $crate"

# Run benchmark and capture output
if cargo bench -p "$crate" -- --noplot 2>&1 | tee /tmp/bench-output.txt; then
# Extract timing info from criterion output
grep -E "time:" /tmp/bench-output.txt | head -10

# Store raw output
cp /tmp/bench-output.txt "$output_file.txt"
echo ""
echo "📁 Results saved to: $output_file.txt"
else
echo "⚠️ Benchmark failed for $crate"
fi
}

case "$CRATE" in
"all")
echo "Running all available benchmarks..."
echo ""

# Core benchmarks
if [ -d "crates/ruvector-bench" ]; then
run_bench "ruvector-bench" "core"
fi

# MinCut benchmarks
if [ -d "crates/ruvector-mincut" ]; then
run_bench "ruvector-mincut" "mincut"
fi

# Attention benchmarks
if [ -d "crates/ruvector-attention" ]; then
run_bench "ruvector-attention" "attention"
fi
;;

"core"|"ruvector-bench")
run_bench "ruvector-bench" "core"
;;

"mincut"|"ruvector-mincut")
run_bench "ruvector-mincut" "mincut"
;;

"attention"|"ruvector-attention")
run_bench "ruvector-attention" "attention"
;;

"graph"|"ruvector-graph")
run_bench "ruvector-graph" "graph"
;;

"quick")
echo "Running quick sanity benchmarks..."
cargo bench -p ruvector-bench -- --noplot "insert" 2>&1 | tail -10
;;

*)
echo "Usage: $0 [all|core|mincut|attention|graph|quick|<crate-name>]"
echo ""
echo "Available benchmark crates:"
echo " core/ruvector-bench - Core vector operations"
echo " mincut - Min-cut algorithms"
echo " attention - Attention mechanisms"
echo " graph - Graph operations"
echo " quick - Fast sanity check"
exit 1
;;
esac

echo ""
echo "✅ Benchmarks complete"
echo "📁 Results in: $BASELINE_DIR/"
104 changes: 104 additions & 0 deletions .claude/hooks/crate-context.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/bin/bash
# Load crate-specific context for intelligent code assistance
# Outputs relevant examples, tests, and documentation paths

set -e

FILE="$1"
if [ -z "$FILE" ]; then
echo "Usage: $0 <file_path>"
exit 1
fi

cd /workspaces/ruvector

# Detect crate from file path
CRATE_DIR=$(echo "$FILE" | grep -oP "crates/[^/]+" | head -1 || echo "")
CRATE_NAME=""

if [ -n "$CRATE_DIR" ]; then
CRATE_NAME=$(basename "$CRATE_DIR")
fi

echo "{"
echo " \"file\": \"$FILE\","
echo " \"crate\": \"$CRATE_NAME\","

# Find related test files
echo " \"tests\": ["
TESTS=$(find "$CRATE_DIR/tests" -name "*.rs" 2>/dev/null | head -5 | while read f; do echo " \"$f\","; done | sed '$ s/,$//')
echo "$TESTS"
echo " ],"

# Find related examples
echo " \"examples\": ["
EXAMPLES=$(find "$CRATE_DIR/examples" -name "*.rs" 2>/dev/null | head -5 | while read f; do echo " \"$f\","; done | sed '$ s/,$//')
if [ -z "$EXAMPLES" ]; then
# Check examples/ directory at root
case "$CRATE_NAME" in
"ruvector-core"|"ruvector-wasm")
EXAMPLES=$(find "examples/wasm" "examples/wasm-react" -name "*.ts" -o -name "*.tsx" 2>/dev/null | head -3 | while read f; do echo " \"$f\","; done | sed '$ s/,$//')
;;
"ruvector-graph"*)
EXAMPLES=$(find "examples" -path "*graph*" -name "*.rs" 2>/dev/null | head -3 | while read f; do echo " \"$f\","; done | sed '$ s/,$//')
;;
"ruvector-mincut"*)
EXAMPLES=$(find "examples/mincut" -name "*.rs" 2>/dev/null | head -3 | while read f; do echo " \"$f\","; done | sed '$ s/,$//')
;;
esac
fi
echo "$EXAMPLES"
echo " ],"

# Find related documentation
echo " \"docs\": ["
DOCS=$(find "$CRATE_DIR" -name "*.md" 2>/dev/null | head -5 | while read f; do echo " \"$f\","; done | sed '$ s/,$//')
if [ -z "$DOCS" ]; then
case "$CRATE_NAME" in
"ruvector-postgres"*)
DOCS=$(find "docs/postgres" -name "*.md" 2>/dev/null | head -5 | while read f; do echo " \"$f\","; done | sed '$ s/,$//')
;;
"rvlite")
DOCS=$(find "crates/rvlite/docs" -name "*.md" 2>/dev/null | head -5 | while read f; do echo " \"$f\","; done | sed '$ s/,$//')
;;
esac
fi
echo "$DOCS"
echo " ],"

# Key dependencies
echo " \"key_deps\": ["
if [ -f "$CRATE_DIR/Cargo.toml" ]; then
grep -E "^\[dependencies\]" -A 20 "$CRATE_DIR/Cargo.toml" 2>/dev/null | grep -E "^[a-z]" | head -5 | while read line; do
DEP=$(echo "$line" | cut -d'=' -f1 | tr -d ' ')
echo " \"$DEP\","
done | sed '$ s/,$//'
fi
echo " ],"

# Suggest related commands
echo " \"commands\": {"
case "$CRATE_NAME" in
"ruvector-core"|"ruvector-bench")
echo " \"test\": \"cargo test -p $CRATE_NAME\","
echo " \"bench\": \"cargo bench -p ruvector-bench\","
echo " \"check\": \"cargo check -p $CRATE_NAME\""
;;
"rvlite"|"ruvector-wasm"|"ruvector-graph-wasm"|"ruvector-gnn-wasm")
echo " \"build\": \"wasm-pack build --target web --release\","
echo " \"test\": \"wasm-pack test --headless --chrome\","
echo " \"size\": \".claude/hooks/wasm-size-check.sh $CRATE_NAME\""
;;
"ruvector-postgres")
echo " \"build\": \"cargo pgrx package\","
echo " \"test\": \"cargo pgrx test\","
echo " \"run\": \"cargo pgrx run\""
;;
*)
echo " \"test\": \"cargo test -p $CRATE_NAME\","
echo " \"check\": \"cargo check -p $CRATE_NAME\""
;;
esac
echo " }"

echo "}"
97 changes: 97 additions & 0 deletions .claude/hooks/post-rust-edit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/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 <file_path> [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"
97 changes: 97 additions & 0 deletions .claude/hooks/rust-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/bin/bash
# Rust-specific pre-edit hook for RuVector
# Runs cargo check, clippy hints, and detects crate context

set -e

FILE="$1"
if [ -z "$FILE" ]; then
echo "Usage: $0 <file_path>"
exit 1
fi

EXT="${FILE##*.}"
if [ "$EXT" != "rs" ]; then
exit 0 # Not a Rust file
fi

cd /workspaces/ruvector

# Detect which crate this file belongs to
CRATE_DIR=$(echo "$FILE" | grep -oP "crates/[^/]+" | head -1 || echo "")
CRATE_NAME=""

if [ -n "$CRATE_DIR" ]; then
CRATE_NAME=$(basename "$CRATE_DIR")
echo "🦀 Crate: $CRATE_NAME"

# Show crate-specific context
case "$CRATE_NAME" in
"ruvector-core")
echo " 📊 Core vector engine (HNSW, SIMD, quantization)"
echo " 📦 Key: VectorStore, HnswIndex, Distance metrics"
;;
"rvlite")
echo " 🌐 WASM standalone DB (SQL/SPARQL/Cypher)"
echo " 📦 Key: RvLite, SqlExecutor, CypherParser"
echo " ⚠️ Size target: <3MB gzipped"
;;
"ruvector-wasm")
echo " 🌐 WASM bindings for ruvector-core"
echo " 📦 Key: WasmVectorStore, IndexedDB storage"
;;
"ruvector-graph"|"ruvector-graph-wasm"|"ruvector-graph-node")
echo " 🕸️ Graph database with Cypher support"
echo " 📦 Key: GraphStore, CypherQuery, HyperEdge"
;;
"ruvector-gnn"|"ruvector-gnn-wasm"|"ruvector-gnn-node")
echo " 🧠 Graph Neural Networks (GCN, GraphSAGE, GAT)"
echo " 📦 Key: GnnLayer, MessagePassing, Aggregation"
;;
"ruvector-postgres")
echo " 🐘 PostgreSQL extension (pgvector compatible)"
echo " 📦 Key: pgrx, SQL functions, background workers"
;;
"sona")
echo " 🎓 ReasoningBank with 9 RL algorithms"
echo " 📦 Key: Trajectory, Verdict, LoRA, EWC++"
;;
"ruvector-mincut"|"ruvector-mincut-wasm"|"ruvector-mincut-node")
echo " ✂️ Subpolynomial dynamic min-cut algorithm"
echo " 📦 Key: ContractedGraph, LambdaCut, SparseCertificate"
;;
"ruvector-attention"|"ruvector-attention-wasm"|"ruvector-attention-node")
echo " 👁️ 39+ attention mechanisms"
echo " 📦 Key: MultiHeadAttention, GeometricAttention"
;;
"ruvector-tiny-dancer"|"ruvector-tiny-dancer-wasm"|"ruvector-tiny-dancer-node")
echo " 💃 FastGRNN neural router for agents"
echo " 📦 Key: Router, FastGRNN, CircuitBreaker"
;;
"ruvector-cli")
echo " ⌨️ CLI and MCP server"
echo " 📦 Key: Commands, MCP protocol, REST API"
;;
*)
echo " 📦 Crate: $CRATE_NAME"
;;
esac

# Quick cargo check for the specific crate
echo ""
echo "🔍 Running cargo check -p $CRATE_NAME..."
if cargo check -p "$CRATE_NAME" --message-format=short 2>&1 | head -10; then
echo "✅ Cargo check passed"
else
echo "⚠️ Check for warnings/errors above"
fi
fi

# Check for WASM-related files
if echo "$FILE" | grep -qE "wasm|rvlite"; then
echo ""
echo "📏 WASM file detected - size considerations apply"
echo " Target: <3MB gzipped for rvlite"
fi

echo ""
Loading