vtcode_core/utils/mod.rs
1//! # Utility Functions and Helpers
2//!
3//! This module provides various utility functions and helpers used throughout VT Code,
4//! including configuration management, safety utilities, and common operations.
5//!
6//! ## Modules Overview
7//!
8//! ### Configuration Management (`dot_config`)
9//! - **User Preferences**: Theme settings, UI preferences, cache configuration
10//! - **Provider Configuration**: LLM provider settings and API keys
11//! - **Dotfile Management**: `.vtcode` directory and configuration files
12//!
13//! ### Safety Utilities (`safety`)
14//! - **Path Validation**: Workspace boundary checking
15//! - **Command Sanitization**: Safe command execution
16//! - **Input Validation**: User input sanitization
17//!
18//! ### ANSI and Colors (`ansi`, `colors`)
19//! - **Terminal Colors**: ANSI color codes and styling
20//! - **Color Management**: Theme support and color schemes
21//! - **Cross-platform**: Works on different terminal types
22//!
23//! ### Git Integration (`vtcodegitignore`)
24//! - **Gitignore Management**: Automatic `.vtcodegitignore` creation
25//! - **Pattern Matching**: File exclusion patterns
26//! - **Workspace Safety**: Prevents accidental file operations
27//!
28//! ### Path Utilities (`path`)
29//! - **Path Normalization**: Resolve `.` and `..` components
30//! - **Shared Utilities**: Common path operations
31//!
32//! ## Basic Usage Examples
33//!
34//! ### Configuration Management
35//! ```rust,no_run
36//! use vtcode_core::utils::dot_config::{load_user_config, save_user_config, UserPreferences};
37//!
38//! #[tokio::main]
39//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
40//! // Load user configuration
41//! let config = load_user_config().await?;
42//!
43//! // Modify preferences
44//! let mut prefs = config.preferences;
45//! prefs.theme = "dark".to_string();
46//!
47//! // Save changes
48//! save_user_config(&prefs).await?;
49//!
50//! Ok(())
51//! }
52//! ```
53//!
54//! ### Path Safety
55//! ```rust,no_run
56//! use vtcode_core::utils::safety::validate_workspace_path;
57//! use std::path::PathBuf;
58//!
59//! let workspace = PathBuf::from("/home/user/project");
60//! let file_path = PathBuf::from("src/main.rs");
61//!
62//! // Validate path is within workspace
63//! match validate_workspace_path(&workspace, &file_path) {
64//! Ok(valid_path) => println!("Safe path: {}", valid_path.display()),
65//! Err(e) => eprintln!("Unsafe path: {}", e),
66//! }
67//! ```
68//!
69//! ### ANSI Colors
70//! ```rust,no_run
71//! use vtcode_core::utils::ansi::{colorize, Color};
72//!
73//! let message = "Hello, World!";
74//! let colored = colorize(message, Color::Green);
75//! println!("{}", colored); // Prints green text
76//!
77//! // Or use styling functions
78//! let bold_text = vtcode_core::utils::ansi::bold("Important message");
79//! let red_error = colorize("Error occurred", Color::Red);
80//! ```
81//!
82//! ### Git Integration
83//! ```rust,no_run
84//! use vtcode_core::utils::vtcodegitignore::initialize_vtcode_gitignore;
85//!
86//! #[tokio::main]
87//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
88//! let workspace = std::env::current_dir()?;
89//!
90//! // Initialize .vtcodegitignore
91//! initialize_vtcode_gitignore(&workspace).await?;
92//!
93//! println!("Git integration initialized");
94//! Ok(())
95//! }
96//! ```
97
98pub mod ansi;
99pub mod ansi_capabilities;
100pub mod ansi_codes;
101pub mod ansi_parser;
102pub mod async_line_writer;
103pub mod async_utils;
104pub mod at_pattern;
105pub mod cached_style_parser;
106pub mod colors;
107pub mod common;
108pub mod diff;
109pub mod diff_styles;
110pub mod dot_config;
111pub mod error_log_collector;
112pub mod error_messages;
113pub mod file_input;
114pub mod file_utils;
115pub mod file_workflow;
116pub mod formatting;
117pub mod gatekeeper;
118pub mod http_client;
119pub mod image_processing;
120pub mod message_style;
121pub mod migration;
122pub mod path;
123pub mod safety;
124pub mod serde_helpers;
125pub mod session_archive;
126pub mod session_debug;
127pub mod style_helpers;
128pub mod terminal_color_probe;
129pub mod tokens;
130pub mod trace_writer;
131pub mod transcript;
132pub mod tty;
133pub mod unicode_monitor;
134pub mod validation;
135pub mod vtcodegitignore;
136
137pub use cached_style_parser::CachedStyleParser;
138pub use common::{ProjectOverview, build_project_overview, current_timestamp, merge_env_patterns};
139pub use style_helpers::*;