File size: 2,660 Bytes
d90101d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | use std::path::PathBuf;
use derive_setters::Setters;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
/// Represents a reusable skill with a name, file path, and prompt content
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Setters, JsonSchema)]
#[setters(strip_option, into)]
pub struct Skill {
/// Name of the skill
pub name: String,
/// File path to the skill markdown file
pub path: Option<PathBuf>,
/// Content/prompt loaded from the markdown file
pub command: String,
/// Description of the skill
pub description: String,
/// List of resource files in the skill directory
pub resources: Vec<PathBuf>,
}
impl Skill {
/// Creates a new Skill with required fields
///
/// # Arguments
///
/// * `name` - The name identifier for the skill
/// * `prompt` - The skill prompt content
/// * `description` - A brief description of the skill
pub fn new(
name: impl Into<String>,
prompt: impl Into<String>,
description: impl Into<String>,
) -> Self {
Self {
name: name.into(),
path: None,
command: prompt.into(),
description: description.into(),
resources: Vec::new(),
}
}
}
#[cfg(test)]
mod tests {
use pretty_assertions::assert_eq;
use super::*;
#[test]
fn test_skill_creation() {
// Fixture
let fixture = Skill::new(
"code_review",
"Review this code",
"A skill for reviewing code quality",
)
.path("/skills/code_review.md");
// Act
let actual = (
fixture.name.clone(),
fixture.path.clone(),
fixture.command.clone(),
fixture.description.clone(),
);
// Assert
let expected = (
"code_review".to_string(),
Some("/skills/code_review.md".into()),
"Review this code".to_string(),
"A skill for reviewing code quality".to_string(),
);
assert_eq!(actual, expected);
}
#[test]
fn test_skill_with_setters() {
// Fixture
let fixture = Skill::new("test", "prompt", "desc")
.path("/path")
.name("updated_name")
.path("/updated/path")
.command("updated prompt")
.description("updated description");
// Act
let actual = fixture;
// Assert
let expected = Skill::new("updated_name", "updated prompt", "updated description")
.path("/updated/path");
assert_eq!(actual, expected);
}
}
|