skills index: cap descriptions at 100 chars; hx prefix lists skills individually
This commit is contained in:
1 parent
a179bebbc0
commit
2ed6fbc028
2 files changed
+60
-11
No files matched your search
@@ -131,6 +131,20 @@ pub fn skills_in(dirs: &[PathBuf]) -> Vec<Skill> {
|
||||
out
|
||||
}
|
||||
|
||||
/// Index descriptions are cut here; the full text stays in the skill file the model reads on demand.
|
||||
// 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.
|
||||
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())
|
||||
}
|
||||
|
||||
pub fn system_prompt(base: Option<&str>, home: &Path, cwd: &Path) -> String {
|
||||
let mut s = base.unwrap_or(DEFAULT_PROMPT).to_string();
|
||||
s.push_str(&format!("\n\nWorking directory: {}", cwd.display()));
|
||||
@@ -142,12 +156,7 @@ pub fn system_prompt(base: Option<&str>, home: &Path, cwd: &Path) -> String {
|
||||
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(&format!(
|
||||
"- {}: {} ({})\n",
|
||||
k.name,
|
||||
k.description,
|
||||
k.path.display()
|
||||
));
|
||||
s.push_str(&skill_index_line(k));
|
||||
}
|
||||
}
|
||||
for (p, c) in context_files(home, cwd) {
|
||||
@@ -195,6 +204,27 @@ mod tests {
|
||||
assert!(system_prompt(Some("CUSTOM"), &home, &proj).starts_with("CUSTOM"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn index_line_caps_description() {
|
||||
let k = Skill {
|
||||
name: "n".into(),
|
||||
description: "d".repeat(500),
|
||||
path: "/p/SKILL.md".into(),
|
||||
load: Load::Auto,
|
||||
body: String::new(),
|
||||
};
|
||||
let l = skill_index_line(&k);
|
||||
assert!(
|
||||
l.len() < 150 && l.contains('…') && l.ends_with("(/p/SKILL.md)\n"),
|
||||
"{l}"
|
||||
);
|
||||
let short = Skill {
|
||||
description: "short".into(),
|
||||
..k
|
||||
};
|
||||
assert_eq!(skill_index_line(&short), "- n: short (/p/SKILL.md)\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn skill_load_modes() {
|
||||
let t = tempfile::tempdir().unwrap();
|
||||
|
||||
Reference in new issue
Block a user