Crate ai_context_gen

Source
Expand description

§AI Context Generator

A Rust library for generating structured context from code repositories, especially useful for LLMs and AI agents.

§Features

  • 🔍 Complete Scanning: Analyzes all .rs and .md files 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

§Usage Example

use ai_context_gen::{Config, ContextGenerator, RepositoryScanner};
use std::path::PathBuf;

let config = Config {
    repo_path: PathBuf::from("."),
    max_tokens: 50000,
    output_file: "repo_context.md".to_string(),
    include_hidden: false,
    include_deps: false,
};

let scanner = RepositoryScanner::new(config.clone());
let scan_result = scanner.scan().await?;

let generator = ContextGenerator::new(config);
generator.generate_context(scan_result).await?;

Re-exports§

pub use config::Config;
pub use generator::ContextGenerator;
pub use parser::EnumInfo;
pub use parser::FunctionInfo;
pub use parser::ImplInfo;
pub use parser::RustAnalysis;
pub use parser::RustParser;
pub use parser::StructInfo;
pub use scanner::FileInfo;
pub use scanner::FileType;
pub use scanner::RepositoryScanner;
pub use scanner::ScanResult;
pub use token_counter::ContentPrioritizer;
pub use token_counter::ContentSection;
pub use token_counter::TokenCounter;

Modules§

config
Configuration module for the AI Context Generator.
generator
Context generation module for the AI Context Generator.
parser
Rust AST parsing module for the AI Context Generator.
scanner
Repository scanning module for the AI Context Generator.
token_counter
Token counting and content prioritization module.

Functions§

generate_context
Generates repository context with default configuration
generate_context_with_config
Generates repository context with custom configuration

Type Aliases§

Result
Default Result type used by the library