Merge pull request 'skills: load ~/.agents/skills; /skills command' (#74) from skills-cmd into main
ci / check (push) Canceled after 0s

This commit was merged in pull request #74.
This commit is contained in:
hermes committed 2026-09-30 22:24:44 +00:00
commit 5b056984bf
5 files changed
+62 -7

No files matched your search

+3 -3
View File
@@ -13,7 +13,7 @@ hx -c # continue last session in this directory
```
TUI: `enter` send, `alt-enter`/`ctrl-j` newline, `esc` abort, `ctrl-o` expand tool output, `pgup`/`pgdn` scroll.
`/help` lists commands: builtins (`/model`, `/provider`, `/compact`, `/clear`, `/lsp`, `/mcp`, `/quit`), MCP
`/help` lists commands: builtins (`/model`, `/provider`, `/compact`, `/clear`, `/lsp`, `/mcp`, `/skills`, `/quit`), MCP
prompts (`/server:prompt`) and skills. Typing `/` opens a completion popup for commands and their arguments
(`up`/`down` select, `tab`/`enter` accept, `esc` close); `tab` completes `@file` (mentioned files are
attached). Messages typed while the agent works are queued.
@@ -47,8 +47,8 @@ tests = "turn_end" # affected tests: turn_end | agent_end | off
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.
`~/.agent/skills` and `~/.agents/skills` (shared with other agents), `~/.hx/skills`, then `.hx/skills` in
the project; a later directory wins when names collide. `/skills` lists what loaded and the searched dirs.
Each skill is also a command: `/<name> [args]` sends the skill file plus `args` as the prompt. Builtin
commands win when names collide.
+1
View File
@@ -59,6 +59,7 @@ pub fn builtins(models: &[&str]) -> Vec<CmdSpec> {
b("compact", "summarize old context", None),
b("clear", "start an empty session", None),
b("lsp", "language server status", None),
b("skills", "list skills and where they load from", None),
b("quit", "exit hx", None),
b("exit", "exit hx", None),
]
+6 -4
View File
@@ -42,12 +42,13 @@ pub struct Skill {
pub path: PathBuf,
}
/// Skill dirs, lowest priority first: `~/.agent/skills` (shared with other agents), `<hx home>/skills`,
/// `<project>/.hx/skills`.
/// Skill dirs, lowest priority first: `~/.agent/skills` and `~/.agents/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"))
.map(PathBuf::from)
.into_iter()
.flat_map(|h| [h.join(".agent/skills"), h.join(".agents/skills")])
.collect();
v.push(home.join("skills"));
v.push(cwd.join(".hx/skills"));
@@ -189,6 +190,7 @@ mod tests {
.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"));
assert!(d[0].ends_with(".agent/skills") && d[1].ends_with(".agents/skills"));
assert!(d[2] == Path::new("/h/skills") && d[3] == Path::new("/p/.hx/skills"));
}
}
+48
View File
@@ -459,6 +459,10 @@ async fn submit(app: &mut App, mut line: String, c: &Ctx<'_>) {
"help" => app
.t
.push(Item::Info(format!("{}\n{KEYS}", cmd::help(&app.specs)))),
"skills" => {
let dirs = hx_core::context::skill_dirs(&hx_core::context::hx_home(), cwd);
app.t.push(Item::Info(skills_list(&app.specs, &dirs)));
}
"lsp" => {
let st = lsp_status().await;
app.t.push(Item::Info(if st.is_empty() {
@@ -631,6 +635,33 @@ fn draw(f: &mut ratatui::Frame, app: &mut App) {
f.set_cursor_position((inner.x + c as u16, inner.y + r as u16 - skip));
}
/// `/skills`: each skill with its file, then the searched dirs (so a missing skill is easy to debug).
fn skills_list(specs: &[CmdSpec], dirs: &[std::path::PathBuf]) -> String {
let sk: Vec<String> = specs
.iter()
.filter_map(|s| match &s.source {
Source::Skill(p) => Some(format!("/{} — {}\n {}", s.name, s.summary, p.display())),
_ => None,
})
.collect();
let dirs: Vec<String> = dirs
.iter()
.map(|d| {
format!(
" {}{}",
d.display(),
if d.is_dir() { "" } else { " (missing)" }
)
})
.collect();
format!(
"skills ({}):\n{}\nsearched (later wins):\n{}",
sk.len(),
sk.join("\n"),
dirs.join("\n")
)
}
/// Candidates stacked just above the input box.
fn draw_popup(f: &mut ratatui::Frame, c: &Completion, sel: usize, input: Rect) {
let h = (c.items.len() as u16).min(input.y);
@@ -742,6 +773,23 @@ mod tests {
}
}
#[test]
fn skills_listing() {
let mut specs = cmd::builtins(&[]);
specs.push(CmdSpec::new(
"rev",
"review code",
Source::Skill("/s/rev/SKILL.md".into()),
cmd::ArgKind::Free,
));
let s = skills_list(&specs, &["/nonexistent-hx".into()]);
assert!(
s.starts_with("skills (1):\n/rev — review code\n /s/rev/SKILL.md"),
"{s}"
);
assert!(s.ends_with("/nonexistent-hx (missing)"), "{s}");
}
#[test]
fn popup_keys_and_render() {
let mut app = test_app();
+4
View File
@@ -8,6 +8,8 @@ tmp = tempfile.mkdtemp()
os.makedirs(f"{tmp}/home/.hx"); os.makedirs(f"{tmp}/repo")
open(f"{tmp}/home/.hx/auth.json", "w").write(json.dumps({"claude": {"access": "fake-token", "refresh": "r", "expires": 99999999999999}}))
open(f"{tmp}/repo/notes.md", "w").write("NOTES\n")
os.makedirs(f"{tmp}/home/.agents/skills/deploy")
open(f"{tmp}/home/.agents/skills/deploy/SKILL.md", "w").write("---\nname: deploy\ndescription: ship it\n---\nBODY\n")
time.sleep(0.5)
pid, fd = pty.fork()
@@ -45,6 +47,8 @@ def check(label, needle):
pump(1.5)
check("startup footer", "Claude")
send(b"/skills\r")
check("skills from ~/.agents", "/deploy — ship it")
send(b"@not"); send(b"\t")
check("tab completion", "es.md")
send(b"\x15") # ctrl-u