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