pub struct ContextGenerator { /* private fields */ }Expand description
Context generator that creates structured markdown from repository scan results.
The generator takes scan results and creates a prioritized, token-limited markdown document suitable for consumption by LLMs and AI agents. Content is organized by priority, with metadata and documentation receiving higher priority than source code.
§Examples
use ai_context_gen::{Config, ContextGenerator, RepositoryScanner};
let config = Config::default();
let scanner = RepositoryScanner::new(config.clone());
let scan_result = scanner.scan().await?;
let generator = ContextGenerator::new(config);
generator.generate_context(scan_result).await?;Implementations§
Source§impl ContextGenerator
impl ContextGenerator
Sourcepub fn new(config: Config) -> Self
pub fn new(config: Config) -> Self
Creates a new context generator with the given configuration.
§Arguments
config- Configuration specifying output options and token limits
§Panics
Panics if the content prioritizer cannot be initialized (e.g., if the tiktoken model cannot be loaded).
§Examples
use ai_context_gen::{Config, ContextGenerator};
let config = Config::default();
let generator = ContextGenerator::new(config);Sourcepub async fn generate_context(&self, scan_result: ScanResult) -> Result<()>
pub async fn generate_context(&self, scan_result: ScanResult) -> Result<()>
Generates a complete context document from scan results.
This method creates a structured markdown document with prioritized content sections including project metadata, file structure, documentation, AST analysis, and source code. Content is prioritized and truncated based on the configured token limit.
§Arguments
scan_result- Results from repository scanning containing files and metadata
§Returns
Returns Ok(()) if the context was successfully generated and written to the
configured output file.
§Errors
Returns an error if:
- AST parsing fails for Rust files
- The output file cannot be written
- Token counting or content prioritization fails
§Examples
use ai_context_gen::{Config, ContextGenerator, RepositoryScanner};
let config = Config::default();
let scanner = RepositoryScanner::new(config.clone());
let scan_result = scanner.scan().await?;
let generator = ContextGenerator::new(config);
generator.generate_context(scan_result).await?;
println!("Context generated successfully!");