Skip to main content

zig_core/
prompt.rs

1use std::collections::HashMap;
2
3/// Prompt templates are embedded at compile time from `prompts/`.
4pub mod templates {
5    /// System prompt for `zig create` — the interactive workflow design agent.
6    pub const CREATE: &str = include_str!("../prompts/create/1_0.md");
7
8    /// .zug format specification — injected as a reference sidecar into prompts
9    /// that need to produce or reason about `.zug` files.
10    pub const CONFIG_SIDECAR: &str = include_str!("../prompts/config-sidecar/1_0.md");
11}
12
13/// Render a prompt template by replacing `{{variable}}` placeholders with
14/// values from the provided map.
15///
16/// Unknown variables are left as-is so callers can detect missing bindings.
17pub fn render(template: &str, vars: &HashMap<&str, &str>) -> String {
18    let mut result = template.to_string();
19    for (&key, &value) in vars {
20        let placeholder = format!("{{{{{key}}}}}");
21        result = result.replace(&placeholder, value);
22    }
23    result
24}
25
26#[cfg(test)]
27#[path = "prompt_tests.rs"]
28mod tests;