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

+3
View File
@@ -412,6 +412,9 @@ mod tests {
d.contains("tools.bash({command: string, timeout?: integer})"),
"{d}"
);
assert!(d.contains("tools.skill({name: string})"), "{d}");
assert!(crate::registry().get("skill").is_some());
assert!(hx_core::subagent::EXPLORE_TOOLS.contains(&"skill"));
assert_eq!(ident("mcp__dev-radius__search"), "mcp__dev_radius__search");
}
}
+4 -2
View File
@@ -1,6 +1,7 @@
//! Built-in tools: read, write, edit, bash.
pub mod codemode;
pub mod skill;
use async_trait::async_trait;
use hx_ai::ToolSpec;
@@ -14,7 +15,7 @@ const MAX_BYTES: usize = 20_000;
/// bash keeps this much of the start (command echo, first errors) and the rest from the end.
const HEAD_BYTES: usize = 4_000;
fn spec(name: &str, desc: &str, schema: Value) -> ToolSpec {
pub(crate) fn spec(name: &str, desc: &str, schema: Value) -> ToolSpec {
ToolSpec {
name: name.into(),
description: desc.into(),
@@ -65,7 +66,8 @@ pub fn registry() -> Registry {
.add(Bash)
.add(AskUser)
.add(MemoryWrite)
.add(MemoryForget);
.add(MemoryForget)
.add(skill::Skill);
r
}
+75
View File
@@ -0,0 +1,75 @@
//! `skill` tool: the model loads a skill body by name (no paths, so no traversal).
use crate::spec;
use async_trait::async_trait;
use hx_ai::ToolSpec;
use hx_core::context;
use hx_core::tool::{Tool, ToolCtx, ToolResult};
use serde_json::{Value, json};
pub struct Skill;
#[async_trait]
impl Tool for Skill {
fn spec(&self) -> ToolSpec {
spec(
"skill",
"Load a skill by name from the Skills list in the system prompt. Returns its instructions.",
json!({"type":"object","properties":{"name":{"type":"string"}},"required":["name"]}),
)
}
async fn call(&self, a: Value, cx: &ToolCtx) -> ToolResult {
let name = a["name"]
.as_str()
.unwrap_or_default()
.trim_start_matches('/');
let all = context::skills(&context::hx_home(), &cx.cwd);
match all.iter().find(|k| k.name == name) {
None => ToolResult::err(format!("no skill `{name}`")),
Some(k) if !k.model_invocable => {
ToolResult::err(format!("skill {name} is user-invoked only"))
}
Some(k) => ToolResult::ok(k.text()),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[tokio::test]
async fn loads_by_name_and_refuses_user_only() {
let t = tempfile::tempdir().unwrap();
let cwd = t.path().join("proj");
for (n, extra) in [("a", ""), ("u", "disable-model-invocation: true\n")] {
let d = cwd.join(".hx/skills").join(n);
std::fs::create_dir_all(&d).unwrap();
std::fs::write(
d.join("SKILL.md"),
format!("---\nname: {n}\ndescription: x\n{extra}---\nBODY-{n}\n"),
)
.unwrap();
}
let cx = ToolCtx {
cwd: cwd.clone(),
state: Default::default(),
};
let r = Skill.call(json!({"name": "a"}), &cx).await;
assert!(!r.is_error, "{}", r.content);
let dir = cwd.join(".hx/skills/a");
assert!(
r.content
.starts_with(&format!("Base directory for this skill: {}", dir.display()))
);
assert!(r.content.contains("BODY-a") && !r.content.contains("description:"));
let r = Skill.call(json!({"name": "u"}), &cx).await;
assert!(
r.is_error && r.content.contains("user-invoked only"),
"{}",
r.content
);
let r = Skill.call(json!({"name": "../../etc/passwd"}), &cx).await;
assert!(r.is_error);
}
}