ai_context_gen/
config.rs

1//! Configuration module for the AI Context Generator.
2//!
3//! This module provides configuration structures and constants for customizing
4//! the behavior of the context generation process.
5
6use serde::{Deserialize, Serialize};
7use std::path::PathBuf;
8
9/// Configuration structure for the AI Context Generator.
10///
11/// This structure holds all the configuration options that control how the
12/// context generation process behaves, including input/output paths, token limits,
13/// and scanning options.
14///
15/// # Examples
16///
17/// ```rust
18/// use ai_context_gen::Config;
19/// use std::path::PathBuf;
20///
21/// // Create a default configuration
22/// let config = Config::default();
23///
24/// // Create a custom configuration
25/// let custom_config = Config {
26///     repo_path: PathBuf::from("./my-project"),
27///     max_tokens: 100000,
28///     output_file: "custom_context.md".to_string(),
29///     include_hidden: true,
30///     include_deps: false,
31/// };
32/// ```
33#[derive(Clone, Debug, Serialize, Deserialize)]
34pub struct Config {
35    /// Path to the repository to analyze.
36    ///
37    /// This should point to the root directory of the project you want to analyze.
38    /// The scanner will recursively process all supported files within this directory.
39    pub repo_path: PathBuf,
40
41    /// Maximum number of tokens to include in the generated context.
42    ///
43    /// This limit helps ensure the generated context fits within LLM token limits.
44    /// When the limit is reached, lower priority content will be truncated.
45    /// Uses GPT-4 tokenizer for accurate counting.
46    pub max_tokens: usize,
47
48    /// Output file path for the generated context.
49    ///
50    /// The generated markdown context will be written to this file.
51    /// If the file already exists, it will be overwritten.
52    pub output_file: String,
53
54    /// Whether to include hidden files and directories in the analysis.
55    ///
56    /// When `true`, files and directories starting with `.` will be included
57    /// in the scan (except for those in [`IGNORED_DIRS`]).
58    pub include_hidden: bool,
59
60    /// Whether to include external dependency analysis.
61    ///
62    /// When `true`, the generator will attempt to analyze and include
63    /// information about external dependencies from `Cargo.toml`.
64    pub include_deps: bool,
65}
66
67impl Default for Config {
68    /// Creates a default configuration with sensible defaults.
69    ///
70    /// # Default Values
71    ///
72    /// - `repo_path`: Current directory (`.`)
73    /// - `max_tokens`: 50,000 tokens
74    /// - `output_file`: `"repo_context.md"`
75    /// - `include_hidden`: `false`
76    /// - `include_deps`: `false`
77    ///
78    /// # Examples
79    ///
80    /// ```rust
81    /// use ai_context_gen::Config;
82    ///
83    /// let config = Config::default();
84    /// assert_eq!(config.max_tokens, 50000);
85    /// assert_eq!(config.output_file, "repo_context.md");
86    /// ```
87    fn default() -> Self {
88        Self {
89            repo_path: PathBuf::from("."),
90            max_tokens: 50000,
91            output_file: "repo_context.md".to_string(),
92            include_hidden: false,
93            include_deps: false,
94        }
95    }
96}
97
98/// File extensions that are supported for analysis.
99///
100/// Currently, the generator supports:
101/// - `.rs` - Rust source files (full AST analysis)
102/// - `.md` - Markdown documentation files
103pub const SUPPORTED_EXTENSIONS: &[&str] = &[".rs", ".md"];
104
105/// Directory names that are automatically ignored during scanning.
106///
107/// These directories are commonly used for build artifacts, dependencies,
108/// or IDE-specific files that don't contain relevant source code.
109pub const IGNORED_DIRS: &[&str] = &["target", "node_modules", ".git", ".vscode", ".idea"];
110
111/// File names that are automatically ignored during scanning.
112///
113/// These files are typically metadata, configuration, or system files
114/// that don't contribute meaningful content to the context.
115pub const IGNORED_FILES: &[&str] = &["Cargo.lock", ".gitignore", ".DS_Store"];