From 2ed6fbc02812f8f851136e4d6806307587f0a0ea Mon Sep 17 00:00:00 2001 From: hermes Date: Thu, 1 Oct 2026 21:21:34 +0000 Subject: [PATCH] skills index: cap descriptions at 100 chars; hx prefix lists skills individually --- crates/hx-cli/src/main.rs | 29 +++++++++++++++++++----- crates/hx-core/src/context.rs | 42 ++++++++++++++++++++++++++++++----- 2 files changed, 60 insertions(+), 11 deletions(-) diff --git a/crates/hx-cli/src/main.rs b/crates/hx-cli/src/main.rs index f154dd9..cea51c9 100644 --- a/crates/hx-cli/src/main.rs +++ b/crates/hx-cli/src/main.rs @@ -311,13 +311,34 @@ async fn main() -> Result<()> { .map(|f| f.1.len()) .sum(); let idx = hub.system_prompt(); - let skills = full.len().saturating_sub(base.len() + files); + let sk = context::skills(&home, &cwd); + let always: usize = sk + .iter() + .filter(|k| k.load == context::Load::Always) + .map(|k| k.body.len()) + .sum(); + let mut skill_rows: Vec<(String, usize)> = sk + .iter() + .filter(|k| k.load == context::Load::Auto) + .map(|k| { + ( + format!("skill: {}", k.name), + context::skill_index_line(k).len(), + ) + }) + .collect(); + skill_rows.sort_by_key(|r| std::cmp::Reverse(r.1)); + let other = full.len().saturating_sub( + base.len() + files + always + skill_rows.iter().map(|r| r.1).sum::(), + ); let mut rows: Vec<(String, usize)> = vec![ ("system: base prompt".into(), base.len()), ("system: AGENTS.md/CLAUDE.md files".into(), files), - ("system: skills + cwd line".into(), skills), + ("system: always-skill bodies".into(), always), + ("system: cwd line + headings".into(), other), ("system: MCP index".into(), idx.len()), ]; + rows.extend(skill_rows); let mut specs = reg.specs(); specs.sort_by_key(|t| { std::cmp::Reverse(serde_json::to_string(t).map_or(0, |s| s.len())) @@ -332,9 +353,7 @@ async fn main() -> Result<()> { for (k, n) in rows { println!("{:>7} tok {k}", n / 4); } - println!( - "{total:>7} tok total (bytes/4; skills row = remainder of the system prompt)" - ); + println!("{total:>7} tok total (bytes/4)"); mgr.shutdown().await; return Ok(()); } diff --git a/crates/hx-core/src/context.rs b/crates/hx-core/src/context.rs index 3fb97b4..1fc8230 100644 --- a/crates/hx-core/src/context.rs +++ b/crates/hx-core/src/context.rs @@ -131,6 +131,20 @@ pub fn skills_in(dirs: &[PathBuf]) -> Vec { 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();