AI Context Generator
A context generator for Rust repositories that creates a structured markdown file with relevant information for LLMs and AI agents.
Available as:
- 🔧 CLI Tool: Use directly from command line
- 📚 Rust Library: Integrate into your Rust application
Features
- 🔍 Complete Scanning: Analyzes all
.rsand.mdfiles in the repository - 🌳 Abstract Syntax Tree: Extracts and documents structures, functions, enums and implementations
- 📊 Token Control: Respects token limits and prioritizes important content
- 📁 Project Structure: Generates file tree visualization
- 📖 Documentation: Includes markdown files like README, documentation, etc.
- ⚡ Performance: Asynchronous and optimized processing
Installation
Prerequisites
- Rust 1.70 or higher
- Linux system (tested on Ubuntu/Debian)
Build
# Clone the repository
# Option 1: Using make (recommended)
# Option 2: Using the script directly
# Option 3: Using cargo directly
Global Installation
# Using make (recommended)
# Or using the installation script
# Or manually
Available Make Commands
# Development
# Build
# Code quality
# Installation
# Utilities
Usage
CLI Usage
Basic Usage
# Analyze current directory
# Analyze a specific directory
# Specify token limit
# Specify output file name
Available Options
Options:
-p, --path <PATH>: Path to repository (default: current directory)-m, --max-tokens <MAX_TOKENS>: Maximum number of tokens (default: 50000)-o, --output <OUTPUT>: Output file name (default: repo_context.md)--include-hidden: Include hidden files and directories--include-deps: Include external dependencies analysis
Examples
# Complete analysis with high token limit
# Analysis including hidden files
# Quick analysis with low limit
# Using make for development
# Running tests
Rust Library Usage
Add to your Cargo.toml:
[]
= "0.1.0"
Basic Example
use generate_context;
use PathBuf;
async
Advanced Example
use ;
use PathBuf;
async
Available API
generate_context(path, output): Simple function for basic casesgenerate_context_with_config(config): Function with custom configurationConfig: Configuration structureRepositoryScanner: File scanningContextGenerator: Context generationRustParser: Rust code parser
Generated File Structure
The generated file contains the following sections (in priority order):
1. Project Metadata (High Priority)
- Project name and description
- Rust version
- Main dependencies
- Project statistics
2. Project Structure (High Priority)
- File tree
- Directory organization
3. Markdown Documentation (High Priority)
- README.md
- Other .md files found
- Project documentation
4. Rust AST Analysis (Medium Priority)
- Structures (structs)
- Enumerations (enums)
- Functions
- Implementations (impls)
- Modules
- Code documentation
5. Source Code (Low Priority)
- Complete content of .rs files
- Syntax highlighting for markdown
Prioritization Algorithm
The system uses an intelligent prioritization algorithm:
- High Priority (9): Metadata, structure and documentation
- Medium Priority (5): AST analysis and code architecture
- Low Priority (1): Complete source code
When the token limit is reached, the system:
- Includes high priority sections first
- Truncates low priority sections if necessary
- Reports which sections were truncated
Ignored Files
The system automatically ignores:
Directories:
target/node_modules/.git/.vscode/.idea/
Files:
Cargo.lock.gitignore.DS_Store
Token Counting
Uses the GPT-4 tokenizer for precise token counting, ensuring compatibility with:
- OpenAI GPT-4
- Claude
- Other models based on similar tokens
Use Cases
For Developers
- Automatic project documentation
- Onboarding new team members
- Code architecture analysis
For LLMs/AI
- Structured context for code assistants
- Analysis of existing projects
- Documentation generation
- Automated code review
For Documentation
- Project wiki generation
- Architecture reports
- Technical documentation
Limitations
- Supports only Rust projects
- Analyzes only
.rsand.mdfiles - Requires Linux system for execution
- Token limit may truncate content
Contributing
Contributions are welcome! Please:
- Fork the project
- Create a branch for your feature
- Implement your changes
- Add tests if necessary
- Open a Pull Request
License
This project is licensed under the MIT license. See the LICENSE file for details.
Roadmap
- Web interface
- Git integration
- Commit history analysis
- Support for other output formats (JSON, YAML)
- Cache for better performance
Changelog
v0.1.0
- Initial implementation
- Support for Rust AST analysis
- Content prioritization system
- Token counting with tiktoken
- Structured markdown file generation