#!/usr/bin/env zsh

# RT Fast - Ultra-fast wrapper for agent commands
# Bypasses shell initialization for 10x speed improvement

# Direct command execution without .zshrc/.npmrc loading
rt_fast() {
    local cmd="$1"
    shift
    
    case "$cmd" in
        rg|ripgrep)
            # Direct ripgrep call
            /opt/homebrew/bin/rg "$@"
            ;;
        
        fd)
            # Direct fd call
            /opt/homebrew/bin/fd "$@"
            ;;
        
        search)
            # Fast search without shell overhead
            /opt/homebrew/bin/rg -n "$@"
            ;;
        
        find-file)
            # Fast file find
            /opt/homebrew/bin/fd --type f "$@"
            ;;
        
        count)
            # Count occurrences
            /opt/homebrew/bin/rg -c "$@"
            ;;
        
        list-imports)
            # List imports from file
            local file="$1"
            /opt/homebrew/bin/rg "^import.*from" "$file" 2>/dev/null
            ;;
        
        find-usage)
            # Find where symbol is used
            local symbol="$1"
            shift
            /opt/homebrew/bin/rg -l "$symbol" "$@"
            ;;
        
        *)
            echo "Unknown command: $cmd"
            echo "Available: rg, fd, search, find-file, count, list-imports, find-usage"
            return 1
            ;;
    esac
}

# Main entry
if [[ $# -eq 0 ]]; then
    cat <<'EOF'
RT Fast - Ultra-fast agent commands (no shell init)

Usage:
  rt-fast rg <args>              # Direct ripgrep
  rt-fast fd <args>              # Direct fd
  rt-fast search <pattern> <file> # Search in file
  rt-fast find-file <pattern>    # Find files
  rt-fast count <pattern> <path> # Count matches
  rt-fast list-imports <file>    # List imports
  rt-fast find-usage <symbol>    # Find usage

Performance:
  - No .zshrc loading
  - No .npmrc warnings
  - No NVM overhead
  - Direct binary calls
  - ~10x faster than 'zsh -lc'

Example:
  # Instead of: zsh -lc 'rg "pattern" file.ts'
  # Use:        rt-fast search "pattern" file.ts
EOF
else
    rt_fast "$@"
fi
