From 1d1d3815169a1fca5583e2157f5b07abf0090f1f Mon Sep 17 00:00:00 2001 From: hermes Date: Wed, 30 Sep 2026 22:24:41 +0000 Subject: [PATCH] skills: load ~/.agents/skills; /skills lists skills and searched dirs --- README.md | 6 ++--- crates/hx-core/src/command.rs | 1 + crates/hx-core/src/context.rs | 10 +++++--- crates/hx-tui/src/lib.rs | 48 +++++++++++++++++++++++++++++++++++ tests/tui_smoke.py | 4 +++ 5 files changed, 62 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 0c290df..00da884 100644 --- a/README.md +++ b/README.md @@ -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 `//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: `/ [args]` sends the skill file plus `args` as the prompt. Builtin commands win when names collide. diff --git a/crates/hx-core/src/command.rs b/crates/hx-core/src/command.rs index cfdd2c3..e95a970 100644 --- a/crates/hx-core/src/command.rs +++ b/crates/hx-core/src/command.rs @@ -59,6 +59,7 @@ pub fn builtins(models: &[&str]) -> Vec { 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), ] diff --git a/crates/hx-core/src/context.rs b/crates/hx-core/src/context.rs index 77daf4d..067d294 100644 --- a/crates/hx-core/src/context.rs +++ b/crates/hx-core/src/context.rs @@ -42,12 +42,13 @@ pub struct Skill { pub path: PathBuf, } -/// Skill dirs, lowest priority first: `~/.agent/skills` (shared with other agents), `/skills`, -/// `/.hx/skills`. +/// Skill dirs, lowest priority first: `~/.agent/skills` and `~/.agents/skills` (shared with other +/// agents), `/skills`, `/.hx/skills`. pub fn skill_dirs(home: &Path, cwd: &Path) -> Vec { let mut v: Vec = 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")); } } diff --git a/crates/hx-tui/src/lib.rs b/crates/hx-tui/src/lib.rs index 86bf8a4..4a9f5c7 100644 --- a/crates/hx-tui/src/lib.rs +++ b/crates/hx-tui/src/lib.rs @@ -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 = 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 = 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(); diff --git a/tests/tui_smoke.py b/tests/tui_smoke.py index ae758eb..82d9f68 100644 --- a/tests/tui_smoke.py +++ b/tests/tui_smoke.py @@ -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 -- 2.54.1