systemprompt_sync/export/
skills.rs1use super::escape_yaml;
2use anyhow::Result;
3use std::fs;
4use std::path::Path;
5use systemprompt_agent::models::Skill;
6
7pub fn generate_skill_markdown(skill: &Skill) -> String {
8 format!(
9 "---\ndescription: \"{}\"\n---\n\n{}",
10 escape_yaml(&skill.description),
11 &skill.instructions
12 )
13}
14
15pub fn generate_skill_config(skill: &Skill) -> String {
16 let tags_yaml = if skill.tags.is_empty() {
17 "[]".to_string()
18 } else {
19 skill
20 .tags
21 .iter()
22 .map(|t| format!(" - {}", t))
23 .collect::<Vec<_>>()
24 .join("\n")
25 };
26
27 format!(
28 r#"id: {}
29name: "{}"
30description: "{}"
31enabled: {}
32version: "1.0.0"
33file: "SKILL.md"
34assigned_agents:
35 - content
36tags:
37{}"#,
38 skill.skill_id.as_str(),
39 escape_yaml(&skill.name),
40 escape_yaml(&skill.description),
41 skill.enabled,
42 tags_yaml
43 )
44}
45
46pub fn export_skill_to_disk(skill: &Skill, base_path: &Path) -> Result<()> {
47 let skill_dir_name = skill.skill_id.as_str().replace('_', "-");
48 let skill_dir = base_path.join(&skill_dir_name);
49 fs::create_dir_all(&skill_dir)?;
50
51 let skill_content = generate_skill_markdown(skill);
52 fs::write(skill_dir.join("SKILL.md"), skill_content)?;
53
54 let config_content = generate_skill_config(skill);
55 fs::write(skill_dir.join("config.yaml"), config_content)?;
56
57 Ok(())
58}