codive-prompts 0.1.0

Prompt management system for Codive
Documentation
//! Embedded prompts loaded at compile time

use std::collections::HashMap;

use crate::ProviderFamily;

// Base system prompt
pub const BASE: &str = include_str!("base.txt");

// Provider-specific prompts
pub const ANTHROPIC: &str = include_str!("anthropic.txt");
pub const OPENAI: &str = include_str!("openai.txt");
pub const GEMINI: &str = include_str!("gemini.txt");
pub const GENERIC: &str = include_str!("generic.txt");

// Verification instructions
pub const VERIFICATION: &str = include_str!("verification.txt");

// Tool descriptions
pub const TOOL_BASH: &str = include_str!("tools/bash.txt");
pub const TOOL_READ_FILE: &str = include_str!("tools/read_file.txt");
pub const TOOL_WRITE_FILE: &str = include_str!("tools/write_file.txt");
pub const TOOL_EDIT_FILE: &str = include_str!("tools/edit_file.txt");
pub const TOOL_GLOB: &str = include_str!("tools/glob.txt");
pub const TOOL_GREP: &str = include_str!("tools/grep.txt");
pub const TOOL_LSP: &str = include_str!("tools/lsp.txt");

/// Embedded prompts compiled into the binary
#[derive(Debug, Clone)]
pub struct EmbeddedPrompts {
    pub base: &'static str,
    pub verification: &'static str,
    providers: HashMap<ProviderFamily, &'static str>,
    tools: HashMap<&'static str, &'static str>,
}

impl EmbeddedPrompts {
    /// Load all embedded prompts
    pub fn load() -> Self {
        let mut providers = HashMap::new();
        providers.insert(ProviderFamily::Anthropic, ANTHROPIC);
        providers.insert(ProviderFamily::OpenAI, OPENAI);
        providers.insert(ProviderFamily::Google, GEMINI);
        providers.insert(ProviderFamily::Generic, GENERIC);

        let mut tools = HashMap::new();
        tools.insert("bash", TOOL_BASH);
        tools.insert("read_file", TOOL_READ_FILE);
        tools.insert("write_file", TOOL_WRITE_FILE);
        tools.insert("edit_file", TOOL_EDIT_FILE);
        tools.insert("glob", TOOL_GLOB);
        tools.insert("grep", TOOL_GREP);
        tools.insert("lsp", TOOL_LSP);

        Self {
            base: BASE,
            verification: VERIFICATION,
            providers,
            tools,
        }
    }

    /// Get the provider-specific prompt
    pub fn provider(&self, family: ProviderFamily) -> &'static str {
        self.providers
            .get(&family)
            .copied()
            .unwrap_or(GENERIC)
    }

    /// Get a tool description by name
    pub fn tool(&self, name: &str) -> Option<&'static str> {
        self.tools.get(name).copied()
    }

    /// Get all available tool names
    pub fn tool_names(&self) -> impl Iterator<Item = &&'static str> {
        self.tools.keys()
    }
}

impl Default for EmbeddedPrompts {
    fn default() -> Self {
        Self::load()
    }
}