vtcode_core/prompts/
generator.rs1use super::config::SystemPromptConfig;
2use super::context::PromptContext;
3use super::templates::PromptTemplates;
4
5pub 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 pub fn generate(&self) -> String {
18 let mut prompt_parts = Vec::new();
19
20 prompt_parts.push(PromptTemplates::base_system_prompt().to_string());
22
23 if let Some(custom) = &self.config.custom_instruction {
25 prompt_parts.push(custom.clone());
26 }
27
28 prompt_parts
30 .push(PromptTemplates::personality_prompt(&self.config.personality).to_string());
31
32 prompt_parts
34 .push(PromptTemplates::response_style_prompt(&self.config.response_style).to_string());
35
36 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 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 prompt_parts.push(PromptTemplates::safety_guidelines_prompt().to_string());
66
67 prompt_parts.join("\n\n")
68 }
69}
70
71pub 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}