code2prompt_core/configuration.rs
1//! This module defines the `Code2PromptConfig` struct and its Builder for configuring the behavior
2//! of code2prompt in a stateless manner. It includes all parameters needed for file traversal,
3//! code filtering, token counting, and more.
4
5use crate::template::OutputFormat;
6use crate::tokenizer::TokenizerType;
7use crate::{sort::FileSortMethod, tokenizer::TokenFormat};
8use derive_builder::Builder;
9use std::collections::HashMap;
10use std::path::PathBuf;
11
12/// A stateless configuration object describing all the preferences and filters
13/// applied when generating a code prompt. It does not store any mutable data,
14/// so it can be cloned freely or shared across multiple sessions.
15#[derive(Debug, Clone, Default, Builder)]
16#[builder(setter(into), default)]
17pub struct Code2PromptConfig {
18 /// Path to the root directory of the codebase.
19 pub path: PathBuf,
20
21 /// List of glob-like patterns to include.
22 #[builder(default)]
23 pub include_patterns: Vec<String>,
24
25 /// List of glob-like patterns to exclude.
26 #[builder(default)]
27 pub exclude_patterns: Vec<String>,
28
29 /// If true, code lines will be numbered in the output.
30 #[builder(default)]
31 pub line_numbers: bool,
32
33 /// If true, paths in the output will be absolute instead of relative.
34 #[builder(default)]
35 pub absolute_path: bool,
36
37 /// If true, code2prompt will generate a full directory tree, ignoring include/exclude rules.
38 #[builder(default)]
39 pub full_directory_tree: bool,
40
41 /// If true, code blocks will not be wrapped in Markdown fences (```).
42 #[builder(default)]
43 pub no_codeblock: bool,
44
45 /// If true, symbolic links will be followed during traversal.
46 #[builder(default)]
47 pub follow_symlinks: bool,
48
49 /// If true, hidden files and directories will be included.
50 #[builder(default)]
51 pub hidden: bool,
52
53 /// If true, .gitignore rules will be ignored.
54 #[builder(default)]
55 pub no_ignore: bool,
56
57 /// Defines the sorting method for files.
58 #[builder(default)]
59 pub sort_method: Option<FileSortMethod>,
60
61 /// Determines the output format of the final prompt.
62 #[builder(default)]
63 pub output_format: OutputFormat,
64
65 /// An optional custom Handlebars template string.
66 #[builder(default)]
67 pub custom_template: Option<String>,
68
69 /// The tokenizer encoding to use for counting tokens.
70 #[builder(default)]
71 pub encoding: TokenizerType,
72
73 /// The counting format to use for token counting.
74 #[builder(default)]
75 pub token_format: TokenFormat,
76
77 /// If true, the git diff between HEAD and index will be included.
78 #[builder(default)]
79 pub diff_enabled: bool,
80
81 /// If set, contains two branch names for which code2prompt will generate a git diff.
82 #[builder(default)]
83 pub diff_branches: Option<(String, String)>,
84
85 /// If set, contains two branch names for which code2prompt will retrieve the git log.
86 #[builder(default)]
87 pub log_branches: Option<(String, String)>,
88
89 /// The name of the template used.
90 #[builder(default)]
91 pub template_name: String,
92
93 /// The template string itself.
94 #[builder(default)]
95 pub template_str: String,
96
97 /// Extra template data
98 #[builder(default)]
99 pub user_variables: HashMap<String, String>,
100
101 /// If true, token counting will be performed for each file (for token map display)
102 #[builder(default)]
103 pub token_map_enabled: bool,
104}
105
106impl Code2PromptConfig {
107 pub fn builder() -> Code2PromptConfigBuilder {
108 Code2PromptConfigBuilder::default()
109 }
110}