Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions crates/ox-core/src/skills.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ pub struct Skill {
pub model: Option<String>,
/// Optional tool allowlist for agent roles.
pub tools: Option<Vec<String>>,
/// Whether the skill can be invoked directly by the user as a `/<name>` slash command.
pub user_invocable: bool,
}

impl Skill {
Expand Down Expand Up @@ -208,6 +210,14 @@ impl SkillRegistry {
.collect()
}

/// Returns all registered skills with `user_invocable` enabled in deterministic name order.
pub fn user_invocable(&self) -> Vec<&Skill> {
self.skills
.values()
.filter(|skill| skill.user_invocable)
.collect()
}

/// Returns the number of registered skills.
pub fn len(&self) -> usize {
self.skills.len()
Expand Down Expand Up @@ -403,6 +413,18 @@ fn parse_skill_content(path: &Path, content: &str) -> Result<(Skill, String), Sk
.get("tools")
.map(parse_csv_list)
.filter(|list| !list.is_empty());
let user_invocable = match parsed.get("user_invocable") {
None => activation == SkillActivation::OnDemand,
Some("true") => true,
Some("false") => false,

Some(other) => {
return Err(SkillError::MalformedFrontmatter {
path: path.to_path_buf(),
reason: format!("invalid user_invocable `{other}`; expected `true` or `false`"),
});
}
};

let body = parsed.body.replace("\r\n", "\n");
let skill = Skill {
Expand All @@ -414,6 +436,7 @@ fn parse_skill_content(path: &Path, content: &str) -> Result<(Skill, String), Sk
on_tools,
model,
tools,
user_invocable,
};
Ok((skill, body))
}
Expand Down Expand Up @@ -639,6 +662,13 @@ mod tests {
.map(|s| s.name.as_str())
.collect();
assert_eq!(matched, vec!["edit-guard", "rust-files"]);

let invocable: Vec<&str> = registry
.user_invocable()
.iter()
.map(|s| s.name.as_str())
.collect();
assert_eq!(invocable, vec!["edit-guard", "rust-files"]);
}

#[test]
Expand All @@ -657,6 +687,7 @@ mod tests {
on_tools: Vec::new(),
model: None,
tools: None,
user_invocable: true,
}));
assert!(registry.register(Skill {
name: "alpha".into(),
Expand All @@ -667,6 +698,7 @@ mod tests {
on_tools: Vec::new(),
model: None,
tools: None,
user_invocable: true,
}));
assert!(!registry.register(Skill {
name: "alpha".into(),
Expand All @@ -677,6 +709,7 @@ mod tests {
on_tools: Vec::new(),
model: None,
tools: None,
user_invocable: true,
}));

let index = registry.prompt_index().expect("non-empty index");
Expand Down Expand Up @@ -828,6 +861,19 @@ mod tests {
),
Err(SkillError::MalformedFrontmatter { reason, .. }) if reason.contains("invalid activation")
));
assert!(matches!(
parse_skill_content(
path,
indoc! {"
---
name: bad-invocable
description: Invalid user_invocable flag
user_invocable: maybe
---
"}
),
Err(SkillError::MalformedFrontmatter { reason, .. }) if reason.contains("invalid user_invocable")
));
}

#[test]
Expand All @@ -852,6 +898,7 @@ mod tests {
.expect("parse extended frontmatter");

assert_eq!(skill.activation, SkillActivation::Always);
assert!(!skill.user_invocable);
assert_eq!(skill.on_files, vec!["*.rs", "Cargo.toml", "docs/*"]);
assert_eq!(skill.on_tools, vec!["edit", "write", "mcp__*"]);
assert_eq!(skill.model.as_deref(), Some("claude-sonnet-5-5"));
Expand All @@ -860,6 +907,37 @@ mod tests {
Some(vec!["read".into(), "grep".into(), "glob".into()])
);

let (explicit_true, _) = parse_skill_content(
path,
indoc! {"
---
name: always-invocable
description: Always active yet user-invocable
activation: always
user_invocable: true
---

Body.
"},
)
.expect("parse explicit user_invocable true");
assert!(explicit_true.user_invocable);

let (explicit_false, _) = parse_skill_content(
path,
indoc! {"
---
name: hidden-skill
description: On-demand but not user-invocable
user_invocable: false
---

Body.
"},
)
.expect("parse explicit user_invocable false");
assert!(!explicit_false.user_invocable);

assert!(skill.matches_file("src/main.rs"));
assert!(skill.matches_file("crates/ox-core/Cargo.toml"));
assert!(skill.matches_file("docs/reference/skills.md"));
Expand Down
66 changes: 66 additions & 0 deletions crates/ox-tui/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
//! Pure Elm / TEA-style state machine for the terminal UI.

use std::sync::Arc;

use crossterm::event::{KeyCode, KeyEvent, KeyEventKind, KeyModifiers};
use ox_core::agent::{AgentEvent, AgentStopReason};
use ox_core::client::Usage;
use ox_core::message::Message;
use ox_core::skills::SkillRegistry;

use crate::command::{CommandEffect, CommandRegistry};
use crate::keymap::{CommandId, Keymap};
Expand Down Expand Up @@ -151,6 +154,13 @@ impl App {
self
}

/// Registers all `user_invocable` skills from `skills` as `/<name>` slash commands.
#[must_use]
pub fn with_skills(mut self, skills: &Arc<SkillRegistry>) -> Self {
self.commands.register_skills(skills);
self
}

/// Returns the active model identifier.
pub fn model(&self) -> &str {
&self.model
Expand Down Expand Up @@ -577,6 +587,14 @@ impl App {
self.overlay = Some(overlay);
None
}

CommandEffect::SubmitPrompt(prompt) => {
if self.is_busy() {
None
} else {
Some(AppAction::Submit(prompt))
}
}
}
}

Expand Down Expand Up @@ -961,4 +979,52 @@ mod tests {
assert_eq!(app.handle_key(key(KeyCode::Enter)), Some(AppAction::Quit));
assert!(app.should_quit());
}

#[test]
fn with_skills_submits_skill_prompt_when_idle_and_ignores_when_busy() {
use std::sync::Arc;

use indoc::indoc;
use ox_core::skills::{SKILL_FILENAME, SkillRegistry};
use tempfile::TempDir;

let temp = TempDir::new().expect("tempdir");
let skill_dir = temp.path().join("review");
std::fs::create_dir_all(&skill_dir).expect("create skill dir");
std::fs::write(
skill_dir.join(SKILL_FILENAME),
indoc! {"
---
name: review
description: Review changes
---

Check error handling.
"},
)
.expect("write SKILL.md");

let skills = Arc::new(SkillRegistry::discover(&[temp.path().to_path_buf()]));
let mut app = App::new("gemini-4-neon").with_skills(&skills);

type_text(&mut app, "/review crates/ox-tui");
assert_eq!(
app.handle_key(key(KeyCode::Enter)),
Some(AppAction::Submit(
indoc! {"
<skill name=\"review\">
Check error handling.
</skill>

crates/ox-tui"
}
.into()
))
);

// Busy app ignores skill prompt submissions until the active turn completes.
app.submit_user_message("in flight".into());
type_text(&mut app, "/review");
assert_eq!(app.handle_key(key(KeyCode::Enter)), None);
}
}
Loading
Loading