Skip to main content

vtcode_core/prompts/
render.rs

1//! Prompt environment and interaction rendering helpers.
2
3use crate::config::VTCodeConfig;
4use crate::prompts::context::PromptContext;
5use crate::prompts::temporal::generate_temporal_date_context;
6
7/// Assemble the environment addenda section for the system prompt.
8pub fn render_environment_addenda(
9    vtcode_config: Option<&VTCodeConfig>,
10    prompt_context: Option<&PromptContext>,
11) -> Option<String> {
12    let mut lines = Vec::new();
13
14    if let Some(ctx) = prompt_context
15        && !ctx.languages.is_empty()
16    {
17        // The language list tells the model which languages the workspace
18        // uses. The `code_search` schema owns the filter parameter, so this
19        // line names the languages and not the parameter.
20        lines.push(format!("- Languages: {}.", ctx.languages.join(", ")));
21    }
22
23    if let Some(cfg) = vtcode_config {
24        if let Some(interaction_line) = render_interaction_addendum(cfg) {
25            lines.push(interaction_line);
26        }
27
28        if cfg.mcp.enabled {
29            lines.push(
30                "- Sources: prefer MCP (including Agent Plugin servers) before external fetches when available."
31                    .to_string(),
32            );
33        }
34
35        // The system-prompt cache freezes this value at segment/session start.
36        // Do not move temporal context into a per-turn runtime appendix: doing
37        // so changes the cache prefix on every request. Date-only (no clock
38        // time) keeps the cached prefix stable all day; precise time belongs
39        // in a `<system-reminder>` history message when a task needs it.
40        if cfg.agent.include_temporal_context {
41            let date_context = generate_temporal_date_context(cfg.agent.temporal_context_use_utc);
42            let trimmed = date_context.trim();
43            let line = if let Some(rest) = trimmed.strip_prefix("Current date (UTC):") {
44                format!("- Date (UTC): {}", rest.trim())
45            } else {
46                trimmed.replacen("Current date:", "- Date:", 1).to_string()
47            };
48            lines.push(line);
49        }
50
51        if cfg.agent.include_working_directory
52            && let Some(ctx) = prompt_context
53            && let Some(cwd) = &ctx.current_directory
54        {
55            lines.push(format!("- Working directory: {}", cwd.display()));
56        }
57    }
58
59    if lines.is_empty() {
60        None
61    } else {
62        Some(format!("## Environment\n{}", lines.join("\n")))
63    }
64}
65
66/// Render the interaction addendum line based on HITL and ask_questions config.
67fn render_interaction_addendum(cfg: &VTCodeConfig) -> Option<String> {
68    match cfg.chat.ask_questions.enabled {
69        true => None,
70        false => Some(
71            "- Interaction: no `request_user_input`; make reasonable assumptions unless Planning workflow needs follow-up."
72                .to_string(),
73        ),
74    }
75}