skills: also load ~/.agent/skills
ci / check (push) Canceled after 0s
ci / check (pull_request) Canceled after 0s

This commit is contained in:
hermes committed 2026-09-30 21:16:34 +00:00
1 parent 3cc2192af7
commit d993292c99
2 files changed
+53 -3

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 # 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 ## Lens
After every tool round, hx asks the language server about files the agent wrote or edited and appends 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, 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> { 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![]; let mut out: Vec<Skill> = vec![];
for dir in [home.join("skills"), cwd.join(".hx/skills")] { for dir in dirs {
let Ok(rd) = std::fs::read_dir(&dir) else { let Ok(rd) = std::fs::read_dir(dir) else {
continue; continue;
}; };
let mut paths: Vec<_> = rd let mut paths: Vec<_> = rd
@@ -148,4 +164,31 @@ mod tests {
assert!(!s.contains("BODY"), "skill body must load on demand only"); assert!(!s.contains("BODY"), "skill body must load on demand only");
assert!(system_prompt(Some("CUSTOM"), &home, &proj).starts_with("CUSTOM")); 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"));
}
} }