SkillDirectory

Struct SkillDirectory 

Source
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

Source

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");
Source

pub fn path(&self) -> &Path

Returns the directory path.

Source

pub const fn skill(&self) -> &Skill

Returns the parsed skill.

Source

pub fn has_scripts(&self) -> bool

Returns true if a scripts/ directory exists.

Source

pub fn has_references(&self) -> bool

Returns true if a references/ directory exists.

Source

pub fn has_assets(&self) -> bool

Returns true if an assets/ directory exists.

Source

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.

Source

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.

Source

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.

Source

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();
Source

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.

Source

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();
Source

pub fn read_asset_string(&self, name: &str) -> Result<String, LoadError>

Reads an asset file by name as a string (UTF-8).

§Errors

Returns LoadError::FileNotFound if the file doesn’t exist. Returns LoadError::IoError if the file cannot be read or is not valid UTF-8.

Trait Implementations§

Source§

impl Clone for SkillDirectory

Source§

fn clone(&self) -> SkillDirectory

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SkillDirectory

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.