vtcode_core/config/
constants.rs

1/// Prompt path constants to avoid hardcoding throughout the codebase
2pub mod prompts {
3    pub const DEFAULT_SYSTEM_PROMPT_PATH: &str = "prompts/system.md";
4    pub const CODER_SYSTEM_PROMPT_PATH: &str = "prompts/coder_system.md";
5}
6
7/// Model ID constants to sync with docs/models.json
8pub mod models {
9    // Google/Gemini models
10    pub mod google {
11        pub const DEFAULT_MODEL: &str = "gemini-2.5-flash-preview-05-20";
12        pub const SUPPORTED_MODELS: &[&str] = &[
13            "gemini-2.5-flash-preview-05-20",
14            "gemini-2.5-pro",
15            "gemini-2.5-flash",
16            "gemini-2.5-flash-lite",
17        ];
18
19        // Convenience constants for commonly used models
20        pub const GEMINI_2_5_FLASH_PREVIEW: &str = "gemini-2.5-flash-preview-05-20";
21        pub const GEMINI_2_5_PRO: &str = "gemini-2.5-pro";
22        pub const GEMINI_2_5_FLASH: &str = "gemini-2.5-flash";
23        pub const GEMINI_2_5_FLASH_LITE: &str = "gemini-2.5-flash-lite";
24    }
25
26    // OpenAI models (from docs/models.json)
27    pub mod openai {
28        pub const DEFAULT_MODEL: &str = "gpt-5";
29        pub const SUPPORTED_MODELS: &[&str] = &[
30            "gpt-5",
31            "gpt-5-codex",
32            "gpt-5-mini",
33            "gpt-5-nano",
34            "codex-mini-latest",
35            "o4-mini",
36            "o4-mini-deep-research",
37            "o3",
38            "o1",
39            "o1-mini",
40            "o1-preview",
41            "o1-pro",
42        ];
43
44        /// Models that support the OpenAI reasoning API extensions
45        pub const REASONING_MODELS: &[&str] = &[
46            O4_MINI,
47            O4_MINI_DEEP_RESEARCH,
48            O3,
49            O1,
50            O1_PRO,
51            O1_PREVIEW,
52            O1_MINI,
53        ];
54
55        // Convenience constants for commonly used models
56        pub const GPT_5: &str = "gpt-5";
57        pub const GPT_5_CODEX: &str = "gpt-5-codex";
58        pub const GPT_5_MINI: &str = "gpt-5-mini";
59        pub const GPT_5_NANO: &str = "gpt-5-nano";
60        pub const CODEX_MINI_LATEST: &str = "codex-mini-latest";
61        pub const CODEX_MINI: &str = "codex-mini";
62        pub const O4_MINI: &str = "o4-mini";
63        pub const O4_MINI_DEEP_RESEARCH: &str = "o4-mini-deep-research";
64        pub const O3: &str = "o3";
65        pub const O1: &str = "o1";
66        pub const O1_PRO: &str = "o1-pro";
67        pub const O1_PREVIEW: &str = "o1-preview";
68        pub const O1_MINI: &str = "o1-mini";
69    }
70
71    // OpenRouter models (extensible via vtcode.toml)
72    pub mod openrouter {
73        pub const DEFAULT_MODEL: &str = "x-ai/grok-code-fast-1";
74        pub const SUPPORTED_MODELS: &[&str] = &[
75            "x-ai/grok-code-fast-1",
76            "x-ai/grok-4-fast:free",
77            "qwen/qwen3-coder",
78            "deepseek/deepseek-chat-v3.1",
79            "openai/gpt-5",
80            "openai/gpt-5-codex",
81            "anthropic/claude-sonnet-4",
82        ];
83
84        /// Models that expose reasoning traces via OpenRouter APIs
85        pub const REASONING_MODELS: &[&str] = &[
86            X_AI_GROK_4_FAST_FREE,
87            OPENAI_GPT_5,
88            OPENAI_GPT_5_CODEX,
89            ANTHROPIC_CLAUDE_SONNET_4,
90        ];
91
92        pub const X_AI_GROK_CODE_FAST_1: &str = "x-ai/grok-code-fast-1";
93        pub const X_AI_GROK_4_FAST_FREE: &str = "x-ai/grok-4-fast:free";
94        pub const QWEN3_CODER: &str = "qwen/qwen3-coder";
95        pub const DEEPSEEK_DEEPSEEK_CHAT_V3_1: &str = "deepseek/deepseek-chat-v3.1";
96        pub const OPENAI_GPT_5: &str = "openai/gpt-5";
97        pub const OPENAI_GPT_5_CODEX: &str = "openai/gpt-5-codex";
98        pub const ANTHROPIC_CLAUDE_SONNET_4: &str = "anthropic/claude-sonnet-4";
99    }
100
101    // Anthropic models (from docs/models.json) - Updated for tool use best practices
102    pub mod anthropic {
103        // Standard model for straightforward tools - Sonnet 4 preferred for most use cases
104        pub const DEFAULT_MODEL: &str = "claude-sonnet-4-20250514";
105        pub const SUPPORTED_MODELS: &[&str] = &[
106            "claude-opus-4-1-20250805", // Latest: Opus 4.1 (2025-08-05)
107            "claude-sonnet-4-20250514", // Latest: Sonnet 4 (2025-05-14)
108        ];
109
110        // Convenience constants for commonly used models
111        pub const CLAUDE_OPUS_4_1_20250805: &str = "claude-opus-4-1-20250805";
112        pub const CLAUDE_SONNET_4_20250514: &str = "claude-sonnet-4-20250514";
113    }
114
115    // xAI models
116    pub mod xai {
117        pub const DEFAULT_MODEL: &str = "grok-2-latest";
118        pub const SUPPORTED_MODELS: &[&str] = &[
119            "grok-2-latest",
120            "grok-2",
121            "grok-2-mini",
122            "grok-2-reasoning",
123            "grok-2-vision",
124        ];
125
126        pub const GROK_2_LATEST: &str = "grok-2-latest";
127        pub const GROK_2: &str = "grok-2";
128        pub const GROK_2_MINI: &str = "grok-2-mini";
129        pub const GROK_2_REASONING: &str = "grok-2-reasoning";
130        pub const GROK_2_VISION: &str = "grok-2-vision";
131    }
132
133    // Backwards compatibility - keep old constants working
134    pub const GEMINI_2_5_FLASH_PREVIEW: &str = google::GEMINI_2_5_FLASH_PREVIEW;
135    pub const GEMINI_2_5_FLASH: &str = google::GEMINI_2_5_FLASH;
136    pub const GEMINI_2_5_PRO: &str = google::GEMINI_2_5_PRO;
137    pub const GEMINI_2_5_FLASH_LITE: &str = google::GEMINI_2_5_FLASH_LITE;
138    pub const GPT_5: &str = openai::GPT_5;
139    pub const GPT_5_CODEX: &str = openai::GPT_5_CODEX;
140    pub const GPT_5_MINI: &str = openai::GPT_5_MINI;
141    pub const GPT_5_NANO: &str = openai::GPT_5_NANO;
142    pub const CODEX_MINI: &str = openai::CODEX_MINI;
143    pub const CODEX_MINI_LATEST: &str = openai::CODEX_MINI_LATEST;
144    pub const CLAUDE_OPUS_4_1_20250805: &str = anthropic::CLAUDE_OPUS_4_1_20250805;
145    pub const CLAUDE_SONNET_4_20250514: &str = anthropic::CLAUDE_SONNET_4_20250514;
146    pub const OPENROUTER_X_AI_GROK_CODE_FAST_1: &str = openrouter::X_AI_GROK_CODE_FAST_1;
147    pub const OPENROUTER_X_AI_GROK_4_FAST_FREE: &str = openrouter::X_AI_GROK_4_FAST_FREE;
148    pub const OPENROUTER_QWEN3_CODER: &str = openrouter::QWEN3_CODER;
149    pub const OPENROUTER_DEEPSEEK_CHAT_V3_1: &str = openrouter::DEEPSEEK_DEEPSEEK_CHAT_V3_1;
150    pub const OPENROUTER_OPENAI_GPT_5: &str = openrouter::OPENAI_GPT_5;
151    pub const OPENROUTER_OPENAI_GPT_5_CODEX: &str = openrouter::OPENAI_GPT_5_CODEX;
152    pub const OPENROUTER_ANTHROPIC_CLAUDE_SONNET_4: &str = openrouter::ANTHROPIC_CLAUDE_SONNET_4;
153    pub const XAI_GROK_2_LATEST: &str = xai::GROK_2_LATEST;
154    pub const XAI_GROK_2: &str = xai::GROK_2;
155    pub const XAI_GROK_2_MINI: &str = xai::GROK_2_MINI;
156    pub const XAI_GROK_2_REASONING: &str = xai::GROK_2_REASONING;
157    pub const XAI_GROK_2_VISION: &str = xai::GROK_2_VISION;
158}
159
160/// Prompt caching defaults shared across features and providers
161pub mod prompt_cache {
162    pub const DEFAULT_ENABLED: bool = true;
163    pub const DEFAULT_CACHE_DIR: &str = ".vtcode/cache/prompts";
164    pub const DEFAULT_MAX_ENTRIES: usize = 1_000;
165    pub const DEFAULT_MAX_AGE_DAYS: u64 = 30;
166    pub const DEFAULT_AUTO_CLEANUP: bool = true;
167    pub const DEFAULT_MIN_QUALITY_THRESHOLD: f64 = 0.7;
168
169    pub const OPENAI_MIN_PREFIX_TOKENS: u32 = 1_024;
170    pub const OPENAI_IDLE_EXPIRATION_SECONDS: u64 = 60 * 60; // 1 hour max reuse window
171
172    pub const ANTHROPIC_DEFAULT_TTL_SECONDS: u64 = 5 * 60; // 5 minutes
173    pub const ANTHROPIC_EXTENDED_TTL_SECONDS: u64 = 60 * 60; // 1 hour option
174    pub const ANTHROPIC_MAX_BREAKPOINTS: u8 = 4;
175
176    pub const GEMINI_MIN_PREFIX_TOKENS: u32 = 1_024;
177    pub const GEMINI_EXPLICIT_DEFAULT_TTL_SECONDS: u64 = 60 * 60; // 1 hour default for explicit caches
178
179    pub const OPENROUTER_CACHE_DISCOUNT_ENABLED: bool = true;
180    pub const XAI_CACHE_ENABLED: bool = true;
181    pub const DEEPSEEK_CACHE_ENABLED: bool = true;
182}
183
184/// Model validation and helper functions
185pub mod model_helpers {
186    use super::models;
187
188    /// Get supported models for a provider
189    pub fn supported_for(provider: &str) -> Option<&'static [&'static str]> {
190        match provider {
191            "google" | "gemini" => Some(models::google::SUPPORTED_MODELS),
192            "openai" => Some(models::openai::SUPPORTED_MODELS),
193            "anthropic" => Some(models::anthropic::SUPPORTED_MODELS),
194            "openrouter" => Some(models::openrouter::SUPPORTED_MODELS),
195            "xai" => Some(models::xai::SUPPORTED_MODELS),
196            _ => None,
197        }
198    }
199
200    /// Get default model for a provider
201    pub fn default_for(provider: &str) -> Option<&'static str> {
202        match provider {
203            "google" | "gemini" => Some(models::google::DEFAULT_MODEL),
204            "openai" => Some(models::openai::DEFAULT_MODEL),
205            "anthropic" => Some(models::anthropic::DEFAULT_MODEL),
206            "openrouter" => Some(models::openrouter::DEFAULT_MODEL),
207            "xai" => Some(models::xai::DEFAULT_MODEL),
208            _ => None,
209        }
210    }
211
212    /// Validate if a model is supported by a provider
213    pub fn is_valid(provider: &str, model: &str) -> bool {
214        supported_for(provider)
215            .map(|list| list.iter().any(|m| *m == model))
216            .unwrap_or(false)
217    }
218}
219
220/// Environment variable names shared across the application.
221pub mod env {
222    /// Toggle automatic update checks in the onboarding banner.
223    pub const UPDATE_CHECK: &str = "VT_UPDATE_CHECK";
224}
225
226/// Default configuration values
227pub mod defaults {
228    use super::{models, ui};
229
230    pub const DEFAULT_MODEL: &str = models::google::GEMINI_2_5_FLASH_PREVIEW;
231    pub const DEFAULT_CLI_MODEL: &str = models::google::GEMINI_2_5_FLASH_PREVIEW;
232    pub const DEFAULT_PROVIDER: &str = "gemini";
233    pub const DEFAULT_API_KEY_ENV: &str = "GEMINI_API_KEY";
234    pub const DEFAULT_THEME: &str = "ciapre-dark";
235    pub const DEFAULT_MAX_TOOL_LOOPS: usize = 100;
236    pub const ANTHROPIC_DEFAULT_MAX_TOKENS: u32 = 4_096;
237    pub const DEFAULT_PTY_STDOUT_TAIL_LINES: usize = 20;
238    pub const DEFAULT_TOOL_OUTPUT_MODE: &str = ui::TOOL_OUTPUT_MODE_COMPACT;
239}
240
241pub mod ui {
242    pub const TOOL_OUTPUT_MODE_COMPACT: &str = "compact";
243    pub const TOOL_OUTPUT_MODE_FULL: &str = "full";
244    pub const DEFAULT_INLINE_VIEWPORT_ROWS: u16 = 16;
245    pub const SLASH_SUGGESTION_LIMIT: usize = 6;
246}
247
248/// Reasoning effort configuration constants
249pub mod reasoning {
250    pub const LOW: &str = "low";
251    pub const MEDIUM: &str = "medium";
252    pub const HIGH: &str = "high";
253    pub const ALLOWED_LEVELS: &[&str] = &[LOW, MEDIUM, HIGH];
254}
255
256/// Message role constants to avoid hardcoding strings
257pub mod message_roles {
258    pub const SYSTEM: &str = "system";
259    pub const USER: &str = "user";
260    pub const ASSISTANT: &str = "assistant";
261    pub const TOOL: &str = "tool";
262}
263
264/// URL constants for API endpoints
265pub mod urls {
266    pub const GEMINI_API_BASE: &str = "https://generativelanguage.googleapis.com/v1beta";
267    pub const OPENAI_API_BASE: &str = "https://api.openai.com/v1";
268    pub const ANTHROPIC_API_BASE: &str = "https://api.anthropic.com/v1";
269    pub const ANTHROPIC_API_VERSION: &str = "2023-06-01";
270    pub const OPENROUTER_API_BASE: &str = "https://openrouter.ai/api/v1";
271    pub const XAI_API_BASE: &str = "https://api.x.ai/v1";
272}
273
274/// Tool name constants to avoid hardcoding strings throughout the codebase
275pub mod tools {
276    pub const GREP_SEARCH: &str = "grep_search";
277    pub const LIST_FILES: &str = "list_files";
278    pub const RUN_TERMINAL_CMD: &str = "run_terminal_cmd";
279    pub const READ_FILE: &str = "read_file";
280    pub const WRITE_FILE: &str = "write_file";
281    pub const EDIT_FILE: &str = "edit_file";
282    pub const DELETE_FILE: &str = "delete_file";
283    pub const CREATE_FILE: &str = "create_file";
284    pub const AST_GREP_SEARCH: &str = "ast_grep_search";
285    pub const SIMPLE_SEARCH: &str = "simple_search";
286    pub const BASH: &str = "bash";
287    pub const APPLY_PATCH: &str = "apply_patch";
288    pub const SRGN: &str = "srgn";
289    pub const CURL: &str = "curl";
290    pub const UPDATE_PLAN: &str = "update_plan";
291
292    // Explorer-specific tools
293    pub const FILE_METADATA: &str = "file_metadata";
294    pub const PROJECT_OVERVIEW: &str = "project_overview";
295    pub const TREE_SITTER_ANALYZE: &str = "tree_sitter_analyze";
296
297    // Special wildcard for full access
298    pub const WILDCARD_ALL: &str = "*";
299}
300
301pub mod project_doc {
302    pub const DEFAULT_MAX_BYTES: usize = 16 * 1024;
303}
304
305/// Context window management defaults
306pub mod context {
307    /// Approximate character count per token when estimating context size
308    pub const CHAR_PER_TOKEN_APPROX: usize = 3;
309
310    /// Default maximum context window (in approximate tokens)
311    pub const DEFAULT_MAX_TOKENS: usize = 90_000;
312
313    /// Trim target as a percentage of the maximum token budget
314    pub const DEFAULT_TRIM_TO_PERCENT: u8 = 80;
315
316    /// Minimum allowed trim percentage (prevents overly aggressive retention)
317    pub const MIN_TRIM_RATIO_PERCENT: u8 = 60;
318
319    /// Maximum allowed trim percentage (prevents minimal trimming)
320    pub const MAX_TRIM_RATIO_PERCENT: u8 = 90;
321
322    /// Default number of recent turns to preserve verbatim
323    pub const DEFAULT_PRESERVE_RECENT_TURNS: usize = 12;
324
325    /// Minimum number of recent turns that must remain after trimming
326    pub const MIN_PRESERVE_RECENT_TURNS: usize = 6;
327
328    /// Maximum number of recent turns to keep when aggressively reducing context
329    pub const AGGRESSIVE_PRESERVE_RECENT_TURNS: usize = 8;
330
331    /// Maximum number of retry attempts when the provider signals context overflow
332    pub const CONTEXT_ERROR_RETRY_LIMIT: usize = 2;
333}
334
335/// Chunking constants for large file handling
336pub mod chunking {
337    /// Maximum lines before triggering chunking for read_file
338    pub const MAX_LINES_THRESHOLD: usize = 2_000;
339
340    /// Number of lines to read from start of file when chunking
341    pub const CHUNK_START_LINES: usize = 800;
342
343    /// Number of lines to read from end of file when chunking
344    pub const CHUNK_END_LINES: usize = 800;
345
346    /// Maximum lines for terminal command output before truncation
347    pub const MAX_TERMINAL_OUTPUT_LINES: usize = 3_000;
348
349    /// Number of lines to show from start of terminal output when truncating
350    pub const TERMINAL_OUTPUT_START_LINES: usize = 1_000;
351
352    /// Number of lines to show from end of terminal output when truncating
353    pub const TERMINAL_OUTPUT_END_LINES: usize = 1_000;
354
355    /// Maximum content size for write_file before chunking (in bytes)
356    pub const MAX_WRITE_CONTENT_SIZE: usize = 500_000; // 500KB
357
358    /// Chunk size for write operations (in bytes)
359    pub const WRITE_CHUNK_SIZE: usize = 50_000; // 50KB chunks
360}