skills: also load ~/.agent/skills #65

Merged
hermes merged 1 commits from agent-skills into main 2026-09-30 21:16:38 +00:00
2 changed files with 53 additions and 3 deletions
Showing only changes of commit d993292c99 - Show all commits

No files matched your search

+7
View File
@@ -41,6 +41,13 @@ tests = "turn_end" # affected tests: turn_end | agent_end | off
# install = ["brew", "install", "zls"] # offered by the lsp tool when `zls` is missing
```
## Skills
Skills are `<dir>/<name>/SKILL.md` files with `name:` / `description:` frontmatter. Only the name and
description go into the system prompt; the model reads the file when a task matches. Looked up in
`~/.agent/skills` (shared with other agents), `~/.hx/skills`, then `.hx/skills` in the project; a later
directory wins when names collide.
## Lens
After every tool round, hx asks the language server about files the agent wrote or edited and appends
+46 -3
View File
@@ -42,11 +42,27 @@ pub struct Skill {
pub path: PathBuf,
}
/// `<dir>/<name>/SKILL.md` with `name:` / `description:` frontmatter. Project skills override global.
/// Skill dirs, lowest priority first: `~/.agent/skills` (shared with other agents), `<hx home>/skills`,
/// `<project>/.hx/skills`.
pub fn skill_dirs(home: &Path, cwd: &Path) -> Vec<PathBuf> {
let mut v: Vec<PathBuf> = std::env::var_os("HOME")
.map(|h| PathBuf::from(h).join(".agent/skills"))
.into_iter()
.collect();
v.push(home.join("skills"));
v.push(cwd.join(".hx/skills"));
v
}
pub fn skills(home: &Path, cwd: &Path) -> Vec<Skill> {
skills_in(&skill_dirs(home, cwd))
}
/// `<dir>/<name>/SKILL.md` with `name:` / `description:` frontmatter. Later dirs override earlier ones by name.
pub fn skills_in(dirs: &[PathBuf]) -> Vec<Skill> {
let mut out: Vec<Skill> = vec![];
for dir in [home.join("skills"), cwd.join(".hx/skills")] {
let Ok(rd) = std::fs::read_dir(&dir) else {
for dir in dirs {
let Ok(rd) = std::fs::read_dir(dir) else {
continue;
};
let mut paths: Vec<_> = rd
@@ -148,4 +164,31 @@ mod tests {
assert!(!s.contains("BODY"), "skill body must load on demand only");
assert!(system_prompt(Some("CUSTOM"), &home, &proj).starts_with("CUSTOM"));
}
#[test]
fn agent_skills_dir() {
let t = tempfile::tempdir().unwrap();
let w = |p: &str, s: &str| {
let p = t.path().join(p);
std::fs::create_dir_all(p.parent().unwrap()).unwrap();
std::fs::write(p, s).unwrap();
};
w(
"agent/a/SKILL.md",
"---\nname: a\ndescription: shared\n---\n",
);
w(
"agent/g/SKILL.md",
"---\nname: g\ndescription: shared-g\n---\n",
);
w("hx/g/SKILL.md", "---\nname: g\ndescription: hx-g\n---\n");
let sk = skills_in(&[t.path().join("agent"), t.path().join("hx")]);
let got: Vec<(&str, &str)> = sk
.iter()
.map(|s| (s.name.as_str(), s.description.as_str()))
.collect();
assert_eq!(got, [("a", "shared"), ("g", "hx-g")]);
let d = skill_dirs(Path::new("/h"), Path::new("/p"));
assert!(d[0].ends_with(".agent/skills") && d[1] == Path::new("/h/skills"));
}
}