Skip to main content

load_skill_body

Function load_skill_body 

Source
pub fn load_skill_body(
    skills_dir: &Path,
    name: &str,
    known: &[SkillMetadata],
) -> Result<String, SkillError>
Expand description

Lazily load one skill’s full Markdown body (the frontmatter stripped off).

Why: This is the “on invoke” half of progressive disclosure — the body is read from disk only when a caller (the use_skill tool, or a resolver’s resolve) actually needs it. What: Rejects any name not present in known (the cached catalog) up front — this doubles as the path-traversal guard, since the join’d path is only ever built from a name the catalog itself already discovered (on disk or embedded). Reads <skills_dir>/<name>/SKILL.md; if that read fails (the disk fallback case: known came from embedded_skill_metadata, so there is no such file) and name matches an entry in crate::assets::DEFAULT_SKILLS, returns that embedded body instead (#2895). Otherwise propagates the disk Io error. Either way, the frontmatter fence is stripped and the body trimmed. Test: load_skill_body_returns_body_without_frontmatter, load_skill_body_rejects_unknown_name, load_skill_body_falls_back_to_embedded_when_disk_read_fails.