skills: skill tool, YAML frontmatter, disable-model-invocation, argument-hint

This commit is contained in:
hermes committed 2026-10-09 14:49:38 +00:00
1 parent 7e29515821
commit 199f337662
12 files changed
+328 -121

No files matched your search

+20 -9
View File
@@ -27,6 +27,8 @@ pub struct CmdSpec {
pub summary: String,
pub source: Source,
pub args: ArgKind,
/// `argument-hint:` of a skill, shown as `/name <hint>`.
pub hint: Option<String>,
}
impl CmdSpec {
@@ -36,6 +38,7 @@ impl CmdSpec {
summary: summary.into(),
source,
args,
hint: None,
}
}
}
@@ -108,21 +111,24 @@ pub fn skill_specs(skills: &[Skill], taken: &[CmdSpec]) -> Vec<CmdSpec> {
summary: s.description.clone(),
source: Source::Skill(s.path.clone()),
args: ArgKind::Free,
hint: s.hint.clone(),
})
.collect()
}
/// The prompt a `/<skill> args` command sends.
/// The prompt a `/<skill> args` command sends: base dir line + body (no frontmatter), then the args.
pub fn skill_prompt(name: &str, path: &std::path::Path, arg: &str) -> std::io::Result<String> {
let body = std::fs::read_to_string(path)?;
let raw = std::fs::read_to_string(path)?;
let sk = crate::context::parse_skill(path, &raw)
.map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))?;
let ask = if arg.is_empty() {
"Apply this skill."
} else {
arg
};
Ok(format!(
"<skill name=\"{name}\" path=\"{}\">\n{body}\n</skill>\n\n{ask}",
path.display()
"<skill name=\"{name}\">\n{}\n</skill>\n\n{ask}",
sk.text()
))
}
@@ -131,10 +137,11 @@ pub fn help(specs: &[CmdSpec]) -> String {
specs
.iter()
.map(|s| {
let arg = match &s.args {
ArgKind::None => "",
ArgKind::Path => " <path>",
_ => " [args]",
let arg = match (&s.hint, &s.args) {
(Some(h), _) => format!(" {h}"),
(_, ArgKind::None) => String::new(),
(_, ArgKind::Path) => " <path>".into(),
_ => " [args]".into(),
};
format!("/{}{arg} — {}", s.name, s.summary)
})
@@ -217,7 +224,10 @@ fn detail(s: &CmdSpec) -> String {
Source::Mcp => "mcp · ",
Source::Ext => "ext · ",
};
format!("{tag}{}", s.summary)
match &s.hint {
Some(h) => format!("{tag}{h} {}", s.summary),
None => format!("{tag}{}", s.summary),
}
}
fn floor_boundary(s: &str, mut i: usize) -> usize {
@@ -349,6 +359,7 @@ mod tests {
let p = skill_prompt("review", &skills[1].path, "PR 7").unwrap();
assert!(p.contains("REVIEW BODY") && p.ends_with("PR 7"), "{p}");
assert!(p.contains("Base directory for this skill:") && !p.contains("description:"));
let h = help(&specs);
assert!(h.contains("/model [args] — show or switch model") && h.contains("/review"));
}