From 4c5a0152ceeb7d2f28f675bdd49f0af860a3a483 Mon Sep 17 00:00:00 2001 From: hermes Date: Thu, 1 Oct 2026 21:31:03 +0000 Subject: [PATCH] skills index: state skill root once per directory, drop per-line paths --- crates/hx-core/src/context.rs | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/crates/hx-core/src/context.rs b/crates/hx-core/src/context.rs index 1fc8230..ea20271 100644 --- a/crates/hx-core/src/context.rs +++ b/crates/hx-core/src/context.rs @@ -135,14 +135,25 @@ pub fn skills_in(dirs: &[PathBuf]) -> Vec { // ponytail: fixed cap, not configurable; add a config key if someone needs longer index lines. const INDEX_DESC_CHARS: usize = 100; -/// One system-prompt index line for an `auto` skill. +/// Skill root directory: `//SKILL.md`. +fn skill_root(k: &Skill) -> Option<&Path> { + k.path.parent()?.parent() +} + +/// One system-prompt index line for an `auto` skill. The path is omitted when it is +/// `//SKILL.md` (the root is stated once in the group header). pub fn skill_index_line(k: &Skill) -> String { let d = k.description.trim(); let d = match d.char_indices().nth(INDEX_DESC_CHARS) { Some((i, _)) => format!("{}…", d[..i].trim_end()), None => d.to_string(), }; - format!("- {}: {d} ({})\n", k.name, k.path.display()) + let regular = skill_root(k).is_some_and(|r| k.path == r.join(&k.name).join("SKILL.md")); + if regular { + format!("- {}: {d}\n", k.name) + } else { + format!("- {}: {d} ({})\n", k.name, k.path.display()) + } } pub fn system_prompt(base: Option<&str>, home: &Path, cwd: &Path) -> String { @@ -155,8 +166,17 @@ pub fn system_prompt(base: Option<&str>, home: &Path, cwd: &Path) -> String { let auto: Vec<_> = sk.iter().filter(|k| k.load == Load::Auto).collect(); if !auto.is_empty() { s.push_str("\n\n# Skills\nRead a skill's file with `read` when the task matches it.\n"); - for k in auto { - s.push_str(&skill_index_line(k)); + let mut roots: Vec<&Path> = vec![]; + for r in auto.iter().filter_map(|k| skill_root(k)) { + if !roots.contains(&r) { + roots.push(r); + } + } + for r in roots { + s.push_str(&format!("Skill file: {}//SKILL.md\n", r.display())); + for k in auto.iter().filter(|k| skill_root(k) == Some(r)) { + s.push_str(&skill_index_line(k)); + } } } for (p, c) in context_files(home, cwd) { @@ -223,6 +243,11 @@ mod tests { ..k }; assert_eq!(skill_index_line(&short), "- n: short (/p/SKILL.md)\n"); + let short = Skill { + path: "/r/n/SKILL.md".into(), + ..short + }; + assert_eq!(skill_index_line(&short), "- n: short\n"); } #[test] -- 2.54.1