Skip to main content

agent_air_runtime/skills/
types.rs

1//! Core types for the Agent Skills system.
2//!
3//! Skills are folders containing a SKILL.md file with YAML frontmatter and
4//! Markdown instructions. See <https://agentskills.io> for the specification.
5
6use serde::{Deserialize, Serialize};
7use std::collections::HashMap;
8use std::path::PathBuf;
9
10/// Metadata parsed from the YAML frontmatter of a SKILL.md file.
11#[derive(Debug, Clone, Serialize, Deserialize)]
12pub struct SkillMetadata {
13    /// Skill name (required). Must be 1-64 chars, lowercase with hyphens.
14    pub name: String,
15
16    /// Skill description (required). Must be 1-1024 chars.
17    pub description: String,
18
19    /// License identifier (optional).
20    #[serde(default)]
21    pub license: Option<String>,
22
23    /// Compatibility notes (optional).
24    #[serde(default)]
25    pub compatibility: Option<String>,
26
27    /// Additional metadata key-value pairs (optional).
28    #[serde(default)]
29    pub metadata: Option<HashMap<String, String>>,
30
31    /// Allowed tools specification (optional, experimental).
32    #[serde(default, rename = "allowed-tools")]
33    pub allowed_tools: Option<String>,
34}
35
36/// A discovered skill with its metadata and file paths.
37#[derive(Debug, Clone)]
38pub struct Skill {
39    /// Parsed metadata from SKILL.md frontmatter.
40    pub metadata: SkillMetadata,
41
42    /// Absolute path to the skill directory.
43    pub path: PathBuf,
44
45    /// Absolute path to the SKILL.md file.
46    pub skill_md_path: PathBuf,
47}
48
49/// Result of a skill reload operation.
50#[derive(Debug, Default)]
51pub struct SkillReloadResult {
52    /// Names of newly added skills.
53    pub added: Vec<String>,
54
55    /// Names of removed skills.
56    pub removed: Vec<String>,
57
58    /// Errors encountered during discovery.
59    pub errors: Vec<SkillDiscoveryError>,
60}
61
62/// Errors that can occur during skill discovery.
63#[derive(Debug, Clone)]
64pub struct SkillDiscoveryError {
65    /// Path where the error occurred.
66    pub path: PathBuf,
67
68    /// Description of what went wrong.
69    pub message: String,
70}
71
72impl std::fmt::Display for SkillDiscoveryError {
73    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
74        write!(f, "{}: {}", self.path.display(), self.message)
75    }
76}
77
78impl std::error::Error for SkillDiscoveryError {}
79
80impl SkillDiscoveryError {
81    pub fn new(path: PathBuf, message: impl Into<String>) -> Self {
82        Self {
83            path,
84            message: message.into(),
85        }
86    }
87}