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:
- Main Portal: code2prompt.dev
- Tutorials & Guides: code2prompt.dev/docs/welcome
§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
Code2PromptConfig- Configuration and builderCode2PromptSession- Main workflow orchestratortemplate- Template processing and renderingfilter- File filtering and selectiongit- Git repository integration
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
Code2PromptConfigstruct 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