Merge pull request 'Skills index: cap descriptions at 100 chars; hx prefix lists skills per skill' (#103) from token-skills-index into main
ci / check (push) Canceled after 0s
ci / check (push) Canceled after 0s
This commit was merged in pull request #103.
This commit is contained in:
commit
f1a83e6cb1
2 files changed
+60
-11
No files matched your search
@@ -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::<usize>(),
|
||||
);
|
||||
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(());
|
||||
}
|
||||
|
||||
@@ -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