Loregrep
AI-Powered Code Analysis and Search Tool
Loregrep is a modern command-line tool that combines traditional code analysis with AI-powered natural language queries. It helps developers understand, search, and analyze codebases using both structured commands and conversational queries.
Features
Core Capabilities
- Repository Scanning: Fast analysis of entire codebases with support for multiple languages
- AI-Powered Queries: Ask questions about your code in natural language
- Code Search: Find functions, structs, and other code elements with pattern matching
- Dependency Analysis: Understand import/export relationships and function call graphs
- Interactive CLI: Beautiful, responsive command-line interface with progress indicators
Supported Languages
- Rust (full support)
- Python, TypeScript, JavaScript, Go (planned)
AI Integration
- Natural Language Queries: "What functions handle authentication?" or "Show me all public structs"
- Code Relationship Analysis: "Find all callers of parse_config" or "What would break if I change this function?"
- Contextual Understanding: AI maintains conversation context for follow-up questions
Installation
Prerequisites
- Rust 1.70 or later
- An Anthropic API key (for AI features)
From Source
The binary will be available at target/release/loregrep
.
Configuration
Create a configuration file or set environment variables:
# Set API key
# Or create a config file
Quick Start
Command Line Tool
# Scan and analyze current directory
# Analyze a specific file
# Search for functions
Library Usage
LoreGrep can also be used as a library in your Rust projects for code analysis and LLM integration:
use ;
use json;
async
Add to your Cargo.toml
:
[]
= "0.1.0"
= { = "1.0", = ["full"] }
= "1.0"
AI-Powered Queries
# Ask questions about your code
# Analyze dependencies
Configuration Management
# View current configuration
# Scan with specific patterns
Command Reference
Repository Operations
loregrep scan <path>
- Scan and analyze a directoryloregrep analyze <file>
- Analyze a specific fileloregrep search <pattern>
- Search for code patterns
AI Queries
loregrep "<natural language query>"
- Ask questions about your code- Use quotes around natural language queries to distinguish from commands
Configuration
loregrep config
- Show current configurationloregrep --help
- Display help information
Search Options
--type function|struct|import
- Filter by code element type--language rust|python|typescript
- Filter by programming language--limit <number>
- Limit number of results--include <pattern>
- Include file patterns--exclude <pattern>
- Exclude file patterns
Configuration
Loregrep supports multiple configuration methods:
Environment Variables
Configuration File
Create loregrep.toml
in your project root or home directory:
[]
= ["*.rs", "*.py"]
= ["target/", "node_modules/", "*.test.js"]
= 1048576 # 1MB
= false
[]
= ["rust", "python"]
= true
= ".loregrep/cache"
[]
= true
= false
= 100
[]
= "your-key-here" # Better to use env var
= 10
Command Line Arguments
All configuration options can be overridden via command line:
Examples
Code Discovery
# Find all public functions
# Find specific struct patterns
# Find error handling patterns
Dependency Analysis
# Find function callers
# Analyze imports
# Impact analysis
Code Understanding
# Get overview
# Find entry points
# Understand architecture
Library API
LLM Integration
LoreGrep provides a tool-based interface designed for seamless LLM integration:
use ;
// Get tool definitions for your LLM
let tools: = get_tool_definitions;
// Send tools to your LLM as available functions
// When LLM wants to call a tool:
let result = loregrep.execute_tool.await?;
Available Tools
- search_functions - Search for functions by pattern
- search_structs - Search for structs/classes by pattern
- analyze_file - Analyze a specific file for functions, structs, imports
- get_dependencies - Get import/export dependencies for a file
- find_callers - Find all locations where a function is called
- get_repository_tree - Get complete repository structure
Builder Configuration
let loregrep = builder
.with_rust_analyzer // Enable Rust support
.max_files // Limit files to scan
.cache_ttl // Cache timeout in seconds
.include_patterns
.exclude_patterns
.max_file_size // 1MB max file size
.follow_symlinks
.build?;
Coding Assistant Integration
See examples/coding_assistant.rs
for a complete example of building a coding assistant with LoreGrep.
Examples
The examples/
directory contains complete integration examples:
- basic_scan.rs - Simple repository scanning
- tool_execution.rs - LLM tool integration patterns
- file_watcher.rs - Automatic re-indexing on file changes
- coding_assistant.rs - Complete coding assistant implementation
Architecture
Loregrep is built with a modular architecture:
- Analyzers: Language-specific code analysis using Tree-sitter
- Storage: In-memory repository maps with fast indexing
- Scanner: File discovery with gitignore support
- AI Tools: Local analysis tools that work with Anthropic's Claude
- CLI: Command-line interface with enhanced user experience
- Public API: Clean library interface for external integration
Performance
Typical performance characteristics:
- Small repos (100 files): <1 second analysis, <1MB memory
- Medium repos (1,000 files): <10 seconds analysis, <10MB memory
- Large repos (10,000 files): <60 seconds analysis, <100MB memory
Contributing
We welcome contributions! Areas where help is needed:
- Language Support: Adding analyzers for Python, TypeScript, JavaScript, Go
- Performance: Optimizing analysis speed and memory usage
- Features: Advanced dependency analysis, code metrics, refactoring suggestions
- Testing: Expanding test coverage and edge case handling
Development Setup
License
This project is licensed under the MIT License - see the LICENSE file for details.
Upcoming Features
- Multi-language support (Python, TypeScript, JavaScript, Go)
- Advanced dependency analysis and call graph visualization
- Performance optimizations for large repositories
- Integration with popular editors and IDEs
- Web interface for team collaboration
Support
- Issues: Report bugs and request features on GitHub Issues
- Discussions: Join conversations on GitHub Discussions
- Documentation: Full documentation available in the
docs/
directory
Note: This project is under active development. APIs and command syntax may change between versions. Please check the changelog for breaking changes.