refactor: removed redundant skill name validation from has_skill function

This commit is contained in:
2026-06-04 14:58:33 -06:00
parent feef3f67b5
commit b1696c3425
4 changed files with 15 additions and 14 deletions
+4 -8
View File
@@ -282,10 +282,6 @@ pub fn list_skills() -> Vec<String> {
}
pub fn has_skill(name: &str) -> bool {
if validate_skill_name(name).is_err() {
return false;
}
skill_file(name).is_file()
}
@@ -345,11 +341,11 @@ mod tests {
}
#[test]
fn has_skill_returns_false_for_invalid_names() {
for bad in ["", "../escape", "foo/bar", ".hidden", "with space"] {
fn has_skill_returns_false_for_missing_paths() {
for absent in ["definitely-not-installed-skill-xyz", "another-missing"] {
assert!(
!has_skill(bad),
"has_skill({bad:?}) should be false for an invalid name"
!has_skill(absent),
"has_skill({absent:?}) should be false for a missing skill"
);
}
}
+2 -1
View File
@@ -1231,7 +1231,8 @@ impl RequestContext {
if let Some(ref tool_names) = role_filter {
agent_functions.retain(|v| {
tool_names.contains(&v.name)
|| v.name.starts_with(SKILL_FUNCTION_PREFIX)
|| (!matches!(agent.skills_enabled(), Some(false))
&& v.name.starts_with(SKILL_FUNCTION_PREFIX))
|| v.name.starts_with(USER_FUNCTION_PREFIX)
});
}
+8 -4
View File
@@ -197,14 +197,18 @@ async fn run(
println!("{skills}");
return Ok(());
}
if cli.skill.len() == 1 && !paths::has_skill(&cli.skill[0]) {
if cli.skill.len() == 1 {
let name = &cli.skill[0];
let app = Arc::clone(&ctx.app.config);
ctx.upsert_skill(app.as_ref(), name)?;
return Ok(());
paths::validate_skill_name(name)?;
if !paths::has_skill(name) {
let app = Arc::clone(&ctx.app.config);
ctx.upsert_skill(app.as_ref(), name)?;
return Ok(());
}
}
if cli.skill.len() > 1 {
for name in &cli.skill {
paths::validate_skill_name(name)?;
if !paths::has_skill(name) {
bail!("Skill '{name}' is not installed");
}
+1 -1
View File
@@ -13,9 +13,9 @@ use gman::providers::one_password::OnePasswordProvider;
use indoc::formatdoc;
use inquire::validator::Validation;
use inquire::{Confirm, Password, PasswordDisplayMode, Select, Text, min_length, required};
use log::debug;
use std::path::{Path, PathBuf};
use std::process::Command;
use log::debug;
pub fn ensure_password_file_initialized(local_provider: &mut LocalProvider) -> Result<()> {
let vault_password_file = local_provider