Skip to main content

ane/data/
init.rs

1use std::path::Path;
2
3use anyhow::{Context, Result};
4
5use crate::data::agents::{self, AgentConfig};
6use crate::data::skill::SKILL_CONTENT;
7
8pub fn init_agent(agent_name: &str, base_dir: &Path) -> Result<&'static AgentConfig> {
9    let config = agents::find_agent(agent_name).ok_or_else(|| {
10        anyhow::anyhow!(
11            "unknown agent '{}'. Supported: {}",
12            agent_name,
13            agents::agent_names().join(", ")
14        )
15    })?;
16
17    let skill_dir = base_dir.join(config.skill_dir);
18    std::fs::create_dir_all(&skill_dir)
19        .with_context(|| format!("failed to create skill directory {}", skill_dir.display()))?;
20
21    let skill_path = skill_dir.join(config.skill_filename);
22    std::fs::write(&skill_path, SKILL_CONTENT)
23        .with_context(|| format!("failed to write skill file {}", skill_path.display()))?;
24
25    Ok(config)
26}