collet 0.1.0

Relentless agentic coding orchestrator with zero-drop agent loops
Documentation
use serde::{Deserialize, Serialize};

/// `[rag]` section — retrieval-augmented generation settings.
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct RagSection {
    /// Master switch. Default: true.
    pub enabled: Option<bool>,
    /// Approximate token budget for injected RAG context. Default: 2000.
    pub max_tokens: Option<usize>,
    /// alcove built-in adapter settings.
    #[serde(default)]
    pub alcove: AlcoveRagSection,
    /// HTTP bridge adapter for user-supplied RAG backends.
    pub bridge: Option<BridgeRagSection>,
}

/// `[rag.alcove]` — alcove built-in RAG adapter.
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct AlcoveRagSection {
    /// Enable alcove RAG. Default: true (if alcove docs_root exists).
    pub enabled: Option<bool>,
    /// Path to alcove docs root. Defaults to alcove's own default location.
    pub docs_root: Option<String>,
    /// Max results per query. Default: 5.
    pub max_results: Option<usize>,
}

/// `[rag.bridge]` — HTTP bridge to user-supplied RAG server.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BridgeRagSection {
    /// Enable the bridge adapter. Default: true when url is set.
    pub enabled: Option<bool>,
    /// Base URL of the RAG server (e.g. "http://localhost:8080").
    pub url: String,
    /// Bearer token. Supports `${ENV_VAR}` expansion.
    pub token: Option<String>,
    /// Max results per query. Default: 5.
    pub max_results: Option<usize>,
}

/// Resolved RAG configuration (used at runtime).
#[derive(Debug, Clone)]
pub struct RagConfig {
    pub max_tokens: Option<usize>,
    pub alcove: Option<AlcoveRagConfig>,
    pub bridge: Option<BridgeRagConfig>,
}

#[derive(Debug, Clone)]
pub struct AlcoveRagConfig {
    pub enabled: bool,
    pub docs_root: Option<String>,
    pub max_results: Option<usize>,
}

#[derive(Debug, Clone)]
pub struct BridgeRagConfig {
    pub enabled: bool,
    pub url: String,
    pub token: Option<String>,
    pub max_results: Option<usize>,
}

impl RagConfig {
    pub fn from_section(section: &RagSection) -> Option<Self> {
        if !section.enabled.unwrap_or(true) {
            return None;
        }
        Some(Self {
            max_tokens: section.max_tokens,
            alcove: Some(AlcoveRagConfig {
                enabled: section.alcove.enabled.unwrap_or(true),
                docs_root: section.alcove.docs_root.clone(),
                max_results: section.alcove.max_results,
            }),
            bridge: section.bridge.as_ref().map(|b| BridgeRagConfig {
                enabled: b.enabled.unwrap_or(true),
                url: b.url.clone(),
                token: b.token.clone(),
                max_results: b.max_results,
            }),
        })
    }
}