Skip to main content

walrus_daemon/config/
mod.rs

1//! Daemon configuration loaded from TOML.
2
3use anyhow::Result;
4pub use model::{ProviderConfig, ProviderManager};
5pub use router::ChannelConfig;
6use serde::{Deserialize, Serialize};
7use std::path::PathBuf;
8
9pub use default::{DEFAULT_AGENT_MD, scaffold_config_dir};
10pub use loader::{load_agents_dir, load_cron_dir};
11
12mod default;
13mod loader;
14
15/// Agents subdirectory (contains *.md files).
16pub const AGENTS_DIR: &str = "agents";
17/// Skills subdirectory.
18pub const SKILLS_DIR: &str = "skills";
19/// Cron subdirectory (contains *.md files).
20pub const CRON_DIR: &str = "cron";
21/// Data subdirectory.
22pub const DATA_DIR: &str = "data";
23/// SQLite memory database filename.
24pub const MEMORY_DB: &str = "memory.db";
25
26/// Resolve the global configuration directory (`~/.walrus/`).
27pub fn global_config_dir() -> PathBuf {
28    dirs::home_dir().expect("no home directory").join(".walrus")
29}
30
31/// Pinned socket path (`~/.walrus/walrus.sock`).
32pub fn socket_path() -> PathBuf {
33    global_config_dir().join("walrus.sock")
34}
35
36/// Top-level daemon configuration.
37#[derive(Debug, Serialize, Deserialize)]
38pub struct DaemonConfig {
39    /// LLM provider configurations (`[[models]]` array).
40    pub models: Vec<ProviderConfig>,
41    /// Channel configurations.
42    #[serde(default)]
43    pub channels: Vec<ChannelConfig>,
44    /// MCP server configurations.
45    #[serde(default)]
46    pub mcp_servers: Vec<mcp::McpServerConfig>,
47}
48
49impl DaemonConfig {
50    /// Parse a TOML string into a `DaemonConfig`.
51    pub fn from_toml(toml_str: &str) -> Result<Self> {
52        let config: Self = toml::from_str(toml_str)?;
53        Ok(config)
54    }
55
56    /// Load configuration from a file path.
57    pub fn load(path: &std::path::Path) -> Result<Self> {
58        let content = std::fs::read_to_string(path)?;
59        Self::from_toml(&content)
60    }
61}