vtcode_core/prompts/
generator.rs

1use super::config::SystemPromptConfig;
2use super::context::PromptContext;
3use super::templates::PromptTemplates;
4
5/// System prompt generator
6pub struct SystemPromptGenerator {
7    config: SystemPromptConfig,
8    context: PromptContext,
9}
10
11impl SystemPromptGenerator {
12    pub fn new(config: SystemPromptConfig, context: PromptContext) -> Self {
13        Self { config, context }
14    }
15
16    /// Generate complete system prompt
17    pub fn generate(&self) -> String {
18        let mut prompt_parts = Vec::new();
19
20        // Base system prompt
21        prompt_parts.push(PromptTemplates::base_system_prompt().to_string());
22
23        // Custom instruction if provided
24        if let Some(custom) = &self.config.custom_instruction {
25            prompt_parts.push(custom.clone());
26        }
27
28        // Personality
29        prompt_parts
30            .push(PromptTemplates::personality_prompt(&self.config.personality).to_string());
31
32        // Response style
33        prompt_parts
34            .push(PromptTemplates::response_style_prompt(&self.config.response_style).to_string());
35
36        // Tool usage if enabled
37        if self.config.include_tools && !self.context.available_tools.is_empty() {
38            prompt_parts.push(PromptTemplates::tool_usage_prompt().to_string());
39            prompt_parts.push(format!(
40                "Available tools: {}",
41                self.context.available_tools.join(", ")
42            ));
43        }
44
45        // Workspace context if enabled
46        if self.config.include_workspace {
47            if let Some(workspace) = &self.context.workspace {
48                prompt_parts.push(PromptTemplates::workspace_context_prompt().to_string());
49                prompt_parts.push(format!("Current workspace: {}", workspace.display()));
50            }
51
52            if !self.context.languages.is_empty() {
53                prompt_parts.push(format!(
54                    "Detected languages: {}",
55                    self.context.languages.join(", ")
56                ));
57            }
58
59            if let Some(project_type) = &self.context.project_type {
60                prompt_parts.push(format!("Project type: {}", project_type));
61            }
62        }
63
64        // Safety guidelines
65        prompt_parts.push(PromptTemplates::safety_guidelines_prompt().to_string());
66
67        prompt_parts.join("\n\n")
68    }
69}
70
71/// Generate system instruction with configuration (backward compatibility function)
72pub fn generate_system_instruction_with_config(
73    config: &SystemPromptConfig,
74    context: &PromptContext,
75) -> String {
76    let generator = SystemPromptGenerator::new(config.clone(), context.clone());
77    generator.generate()
78}