pub struct SkillDirectory { /* private fields */ }Expand description
A loaded skill directory containing the skill and its files.
Provides access to the parsed SKILL.md as well as optional directories (scripts/, references/, assets/).
§Examples
use agent_skills::SkillDirectory;
use std::path::Path;
let dir = SkillDirectory::load(Path::new("./my-skill")).unwrap();
println!("Loaded skill: {}", dir.skill().name());
// Check for optional directories
if dir.has_scripts() {
for script in dir.scripts().unwrap() {
println!("Found script: {}", script.display());
}
}Implementations§
Source§impl SkillDirectory
impl SkillDirectory
Sourcepub fn load(path: impl AsRef<Path>) -> Result<Self, LoadError>
pub fn load(path: impl AsRef<Path>) -> Result<Self, LoadError>
Loads a skill from a directory path.
The directory must contain a SKILL.md file. The skill name in the frontmatter must match the directory name (per the specification).
§Errors
Returns LoadError if:
- The directory doesn’t exist
- SKILL.md is missing
- SKILL.md cannot be read
- SKILL.md cannot be parsed
- The skill name doesn’t match the directory name
§Examples
use agent_skills::SkillDirectory;
use std::path::Path;
let dir = SkillDirectory::load(Path::new("./my-skill")).unwrap();
assert_eq!(dir.skill().name().as_str(), "my-skill");Sourcepub fn has_scripts(&self) -> bool
pub fn has_scripts(&self) -> bool
Returns true if a scripts/ directory exists.
Sourcepub fn has_references(&self) -> bool
pub fn has_references(&self) -> bool
Returns true if a references/ directory exists.
Sourcepub fn has_assets(&self) -> bool
pub fn has_assets(&self) -> bool
Returns true if an assets/ directory exists.
Sourcepub fn scripts(&self) -> Result<Vec<PathBuf>, LoadError>
pub fn scripts(&self) -> Result<Vec<PathBuf>, LoadError>
Lists files in the scripts/ directory.
Returns an empty vector if the scripts/ directory doesn’t exist.
§Errors
Returns LoadError::IoError if the directory cannot be read.
Sourcepub fn references(&self) -> Result<Vec<PathBuf>, LoadError>
pub fn references(&self) -> Result<Vec<PathBuf>, LoadError>
Lists files in the references/ directory.
Returns an empty vector if the references/ directory doesn’t exist.
§Errors
Returns LoadError::IoError if the directory cannot be read.
Sourcepub fn assets(&self) -> Result<Vec<PathBuf>, LoadError>
pub fn assets(&self) -> Result<Vec<PathBuf>, LoadError>
Lists files in the assets/ directory.
Returns an empty vector if the assets/ directory doesn’t exist.
§Errors
Returns LoadError::IoError if the directory cannot be read.
Sourcepub fn read_reference(&self, name: &str) -> Result<String, LoadError>
pub fn read_reference(&self, name: &str) -> Result<String, LoadError>
Reads a reference file by name.
The name is relative to the references/ directory.
§Errors
Returns LoadError::FileNotFound if the file doesn’t exist.
Returns LoadError::IoError if the file cannot be read.
§Examples
use agent_skills::SkillDirectory;
use std::path::Path;
let dir = SkillDirectory::load(Path::new("./my-skill")).unwrap();
let content = dir.read_reference("REFERENCE.md").unwrap();Sourcepub fn read_script(&self, name: &str) -> Result<String, LoadError>
pub fn read_script(&self, name: &str) -> Result<String, LoadError>
Reads a script file by name.
The name is relative to the scripts/ directory.
§Errors
Returns LoadError::FileNotFound if the file doesn’t exist.
Returns LoadError::IoError if the file cannot be read.
Sourcepub fn read_asset(&self, name: &str) -> Result<Vec<u8>, LoadError>
pub fn read_asset(&self, name: &str) -> Result<Vec<u8>, LoadError>
Reads an asset file by name as bytes.
The name is relative to the assets/ directory.
§Errors
Returns LoadError::FileNotFound if the file doesn’t exist.
Returns LoadError::IoError if the file cannot be read.
§Examples
use agent_skills::SkillDirectory;
use std::path::Path;
let dir = SkillDirectory::load(Path::new("./my-skill")).unwrap();
let bytes = dir.read_asset("template.txt").unwrap();Trait Implementations§
Source§impl Clone for SkillDirectory
impl Clone for SkillDirectory
Source§fn clone(&self) -> SkillDirectory
fn clone(&self) -> SkillDirectory
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more