Merge pull request 'Skills index: root path once per directory instead of per line' (#104) from token-skill-paths into main
ci / check (push) Canceled after 0s

This commit was merged in pull request #104.
This commit is contained in:
hermes committed 2026-10-01 21:31:39 +00:00
commit a63a9e4f05
1 file changed
+29 -4
+29 -4
View File
@@ -135,14 +135,25 @@ pub fn skills_in(dirs: &[PathBuf]) -> Vec<Skill> {
// ponytail: fixed cap, not configurable; add a config key if someone needs longer index lines. // ponytail: fixed cap, not configurable; add a config key if someone needs longer index lines.
const INDEX_DESC_CHARS: usize = 100; const INDEX_DESC_CHARS: usize = 100;
/// One system-prompt index line for an `auto` skill. /// Skill root directory: `<root>/<dir>/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
/// `<root>/<name>/SKILL.md` (the root is stated once in the group header).
pub fn skill_index_line(k: &Skill) -> String { pub fn skill_index_line(k: &Skill) -> String {
let d = k.description.trim(); let d = k.description.trim();
let d = match d.char_indices().nth(INDEX_DESC_CHARS) { let d = match d.char_indices().nth(INDEX_DESC_CHARS) {
Some((i, _)) => format!("{}…", d[..i].trim_end()), Some((i, _)) => format!("{}…", d[..i].trim_end()),
None => d.to_string(), 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 { 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(); let auto: Vec<_> = sk.iter().filter(|k| k.load == Load::Auto).collect();
if !auto.is_empty() { if !auto.is_empty() {
s.push_str("\n\n# Skills\nRead a skill's file with `read` when the task matches it.\n"); s.push_str("\n\n# Skills\nRead a skill's file with `read` when the task matches it.\n");
for k in auto { let mut roots: Vec<&Path> = vec![];
s.push_str(&skill_index_line(k)); 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: {}/<name>/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) { for (p, c) in context_files(home, cwd) {
@@ -223,6 +243,11 @@ mod tests {
..k ..k
}; };
assert_eq!(skill_index_line(&short), "- n: short (/p/SKILL.md)\n"); 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] #[test]