Skip to main content

Crate code2prompt_core

Crate code2prompt_core 

Source
Expand description

§Code2Prompt Core Library

Pure Rust library for consolidating multi-file repositories and source trees into a single, structured, LLM-optimized prompt payload. Provides file filtering, template processing, and git integration.


§📘 Documentation & Integration Guides

For high-level concepts (Diataxis framework), step-by-step onboarding, and workflows:

§Quick Start

use code2prompt_core::{Code2PromptConfig, Code2PromptSession};
 
let config = Code2PromptConfig::builder()
    .path(&temp_dir)
    .build()?;
 
let mut session = Code2PromptSession::new(config);
let output = session.generate_prompt()?;
println!("Generated {} tokens", output.token_count);

§Main Components

Re-exports§

pub use configuration::Code2PromptConfig;
pub use configuration::Code2PromptConfigBuilder;
pub use session::Code2PromptSession;

Modules§

analysis
Analysis Engine for Codebase Statistics
builtin_templates
Built-in templates embedded as static resources.
configuration
This module defines the Code2PromptConfig struct and its Builder for configuring the behavior of code2prompt in a stateless manner. It includes all parameters needed for file traversal, code filtering, token counting, and more.
file_processor
File processor module for handling different file types intelligently.
filter
This module contains pure filtering logic for files based on glob patterns.
git
Git repository integration for diff extraction and branch operations.
path
This module contains the functions for traversing the directory and processing the files.
selection
This module contains the SelectionEngine that handles user file selection with precedence rules.
session
This module defines a Code2promptSession struct that provide a stateful interface to code2prompt-core. It allows you to load codebase data, Git info, and render prompts using a template.
sort
This module provides sorting methods for files and directory trees.
template
Template system for customizable prompt generation.
tokenizer
This module encapsulates the logic for counting the tokens in the rendered text.
util
This module contains util functions