AI Context Generator
[![Crates.i```toml
Cargo.toml
[dependencies] ai-context-gen = "0.1.2"
[](https://docs.rs/ai-context-gen)
[](LICENSE-MIT)
[](https://www.rust-lang.org)
[](https://github.com/brbtavares/ai-context-gen/actions)
[](https://crates.io/crates/ai-context-gen)
A context generator for Rust repositories that creates a structured markdown file with relevant information for LLMs and AI agents.
## ๐ฏ Quick Start
**Choose your preferred way to use AI Context Generator:**
| Usage Mode | When to Use | Quick Start |
|------------|-------------|-------------|
| ๐ง **CLI Tool** | Interactive use, one-time analysis, scripts | `ai-context-gen --path ./my-project` |
| ๐ **Rust Library** | Integrate into Rust apps, custom workflows | `cargo add ai-context-gen` |
---
### ๐ CLI Quick Start
```bash
# Install globally
git clone https://github.com/brbtavares/ai-context-gen
cd ai-context-gen && make install
# Use anywhere
ai-context-gen --path /path/to/project
๐ฆ Library Quick Start
# Cargo.toml
[]
= "0.1.1"
use generate_context;
use PathBuf;
async
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
๐ง CLI Tool Usage
The AI Context Generator CLI is perfect for interactive use, one-time analysis, and shell scripts.
Installation
Prerequisites
- Rust 1.76 or higher
- Linux system (tested on Ubuntu/Debian)
Build and Install
# Clone the repository
# Build and install globally (recommended)
# Alternative: step by step
Verify Installation
# Check if installed correctly
# Should work from any directory
&&
Developer Commands (Make)
# Development & Testing
# Build & Installation
# Utilities
CLI Commands
Basic Usage
# Analyze current directory (interactive mode)
# Analyze specific directory
# Custom output file
# High token limit for large projects
All CLI Options
)
)
)
CLI Examples
# Complete analysis with all options
# Quick summary
# Analyze remote/different project
๐ Rust Library Usage
The AI Context Generator library is perfect for integrating context generation into your Rust applications.
Installation
Add to your Cargo.toml:
[]
= "0.1.2"
Library Examples
Simple Usage
use generate_context;
use PathBuf;
async
Advanced Usage with Custom Configuration
use ;
use PathBuf;
async
Using with Custom Configuration Function
use ;
use PathBuf;
async
Available Library API
generate_context(path, output): Simple function for basic casesgenerate_context_with_config(config): Function with custom configurationConfig: Configuration structureRepositoryScanner: File scanning and analysisContextGenerator: Context generation with prioritiesRustParser: Rust code AST 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
Development Setup
Release Process
For maintainers, releases are automated. See RELEASE.md for details.
# Update version and changelog, then:
# GitHub Actions handles the rest!
๐ 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.2
- ๐ง MSRV Compatibility: Updated MSRV to Rust 1.76 to support Cargo lock file version 4
- ๐ Workflow Improvements: Modernized GitHub Actions workflows with updated actions
- ๐ ๏ธ CI Fixes: Fixed MSRV check to handle newer lock file formats correctly
- ๐ฆ Release Automation: Enhanced release workflow with better asset handling
- ๐ Better Error Handling: Improved release workflow with proper secret handling
v0.1.1
- โจ Documentation Improvements: Completely restructured README.md and lib.rs documentation
- ๐ง Clear CLI/Library Separation: Added clear distinction between CLI and library usage
- ๐ Enhanced Library Examples: Added multiple usage patterns and integration examples
- ๐ฏ Quick Start Guide: Added comparison table and clear guidance on when to use each mode
- ๐ ๏ธ Better Error Handling: Improved CLI output messages and error reporting
- ๐ API Documentation: Enhanced rustdoc comments with comprehensive examples
- ๐งน Code Organization: Improved module structure and exports
v0.1.0
- Initial implementation
- Support for Rust AST analysis
- Content prioritization system
- Token counting with tiktoken
- Structured markdown file generation
๐ง Troubleshooting
CLI Installation Issues
Command not found after installation
# Check if /usr/local/bin is in your PATH
|
# If not found, add to your shell profile
# Verify installation
Permission denied during installation
# Make sure you have sudo privileges
# Or install manually
Old version conflicts
# Remove old installations
# Reinstall fresh
Library Usage Issues
Tokio runtime errors
Make sure you're using #[tokio::main] or initializing a runtime:
// Option 1: Use tokio::main
async
// Option 2: Manual runtime
File permission errors
use ;
use PathBuf;
// Make sure output directory is writable
let config = Config ;
General Issues
Large projects hitting token limits
# Use higher token limits for large projects
# Or focus on specific parts
Including/excluding files
# Include hidden files
# For library usage, modify Config
};