skills: load ~/.agents/skills; /skills lists skills and searched dirs
This commit is contained in:
1 parent
35037caa2c
commit
1d1d381516
5 files changed
+62
-7
No files matched your search
@@ -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),
|
||||
]
|
||||
|
||||
@@ -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"));
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
Reference in new issue
Block a user