Skip to main content

agentic_workflow_mcp/config/
mod.rs

1use std::path::PathBuf;
2
3use serde::{Deserialize, Serialize};
4
5/// Server configuration.
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct ServerConfig {
8    pub data_dir: PathBuf,
9    pub log_level: String,
10    pub transport: TransportConfig,
11}
12
13#[derive(Debug, Clone, Serialize, Deserialize)]
14pub enum TransportConfig {
15    Stdio,
16    Sse { host: String, port: u16 },
17}
18
19impl Default for ServerConfig {
20    fn default() -> Self {
21        let data_dir = dirs::data_dir()
22            .unwrap_or_else(|| PathBuf::from("."))
23            .join("agentic-workflow");
24
25        Self {
26            data_dir,
27            log_level: "info".to_string(),
28            transport: TransportConfig::Stdio,
29        }
30    }
31}
32
33/// Resolve the workflow data path for a project.
34pub fn resolve_data_path(project_path: Option<&str>) -> PathBuf {
35    match project_path {
36        Some(path) => {
37            let canonical = std::path::Path::new(path);
38            let hash = blake3::hash(
39                canonical
40                    .to_string_lossy()
41                    .as_bytes(),
42            );
43            let dir_name = format!("project-{}", &hash.to_hex()[..16]);
44
45            dirs::data_dir()
46                .unwrap_or_else(|| PathBuf::from("."))
47                .join("agentic-workflow")
48                .join(dir_name)
49        }
50        None => dirs::data_dir()
51            .unwrap_or_else(|| PathBuf::from("."))
52            .join("agentic-workflow")
53            .join("default"),
54    }
55}