pub mod installer;
pub mod record;
pub use crate::digest::Digest;
use crate::embedded;
use crate::error::RkError;
#[derive(Debug)]
pub struct Skill {
pub name: String,
pub text: &'static str,
}
pub fn all() -> Result<Vec<Skill>, RkError> {
let mut out = Vec::new();
for dir in embedded::SKILLS.dirs() {
let name = dir.path().to_string_lossy().into_owned();
let text = dir
.get_file(format!("{name}/SKILL.md"))
.and_then(include_dir::File::contents_utf8)
.ok_or_else(|| anyhow::anyhow!("payload skill carries no UTF-8 SKILL.md: {name}"))?;
out.push(Skill { name, text });
}
out.sort_by(|a, b| a.name.cmp(&b.name));
Ok(out)
}
#[derive(Debug)]
pub struct SharedArtifact {
pub path: String,
pub bytes: &'static [u8],
}
#[must_use]
pub fn shared() -> Vec<SharedArtifact> {
embedded::walk(&embedded::SKILL_SHARED)
.into_iter()
.map(|(path, bytes)| SharedArtifact { path, bytes })
.collect()
}
#[cfg(test)]
mod tests {
#![allow(clippy::expect_used)]
use super::{all, shared};
#[test]
fn the_payload_carries_the_shared_plan_gate() {
let shared = shared();
assert!(
shared
.iter()
.any(|artifact| artifact.path == "plan-gate.md"),
"the payload carries no shared plan gate"
);
}
#[test]
fn the_payload_carries_every_authored_skill() {
let skills = all().expect("the embedded skills read");
assert!(!skills.is_empty(), "the payload carries no skills");
for skill in &skills {
assert!(
skill.text.contains(&format!("name: {}", skill.name)),
"{}: the frontmatter name differs from the directory",
skill.name
);
}
}
}