The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(ops_create): handle empty skill name in create operation
Steven Enamakel2309a2bf0d5d
diff --git a/crates/openhuman-core/src/skills/ops_create.rs b/crates/openhuman-core/src/skills/ops_create.rsindex 78811721eb..e4fbb28235 100644--- a/crates/openhuman-core/src/skills/ops_create.rs+++ b/crates/openhuman-core/src/skills/ops_create.rs@@ -3,12 +3,14 @@use serde::{Deserialize, Serialize};use std::path::{Path, PathBuf};-use super::ops_discover::{discover_workflows_inner, is_workspace_trusted};-use super::ops_types::{- Workflow, WorkflowScope, MAX_DESCRIPTION_LEN, MAX_NAME_LEN, RESOURCE_DIRS, SKILL_MD,- SKILL_TOML, WORKFLOW_MD, WORKFLOW_TOML,+use tinyskills::{+ scaffold_bundle, slugify, validate_description, validate_display_name, BundleSpec,+ ScaffoldOptions,};+use super::ops_discover::{discover_workflows_inner, is_workspace_trusted};+use super::ops_types::{Workflow, WorkflowScope, SKILL_TOML, WORKFLOW_TOML};+/// One declared `[[inputs]]` entry as supplied at create time by the/// Create-a-Workflow form.///@@ -124,50 +126,30 @@ pub fn create_workflow(create_workflow_inner(home.as_deref(), workspace_dir, params)}-/// Resolve an existing pre-rename workflow directory for `slug` under the-/// legacy compat roots discovery still scans (`<root>/skills/<slug>`), so an-/// edit can update it in place instead of failing with "does not exist".-/// Mirrors `ops_discover::user_roots` / `project_roots` (minus the primary-/// `workflows/` root, which the caller checks first). Returns the first-/// existing canonicalized `<root>/<slug>` that stays within its root; `None`-/// when no legacy copy exists.-fn legacy_workflow_dir(+/// Pre-rename compat roots (`<root>/skills`) an edit may still find a+/// workflow under; mirrors `ops_discover::user_roots` / `project_roots`+/// minus the primary `workflows/` root. Builtin/legacy/flow scopes have no+/// writable legacy location.+fn legacy_workflow_roots(home_dir: Option<&Path>,workspace_dir: &Path,scope: WorkflowScope,- slug: &str,-) -> Option<PathBuf> {- let roots: Vec<PathBuf> = match scope {- WorkflowScope::User => {- let home = home_dir?;- vec![- home.join(".openhuman").join("skills"),- home.join(".agents").join("skills"),- ]- }+) -> Vec<PathBuf> {+ match scope {+ WorkflowScope::User => home_dir+ .map(|home| {+ vec![+ home.join(".openhuman").join("skills"),+ home.join(".agents").join("skills"),+ ]+ })+ .unwrap_or_default(),WorkflowScope::Project => vec![workspace_dir.join(".openhuman").join("skills"),workspace_dir.join(".agents").join("skills"),],- // Builtin bundles come from a `const` table compiled into the- // binary; a create RPC that could write one would make that table- // remotely extensible, which is the whole thing it exists to prevent.- // Flow entries are rows in `flows.db`, not bundle directories — there- // is no path to resolve. Creating one is `save_workflow`'s job.- WorkflowScope::Builtin | WorkflowScope::Legacy | WorkflowScope::Flow => return None,- _ => return None,- };- for root in roots {- let canonical_root = match std::fs::canonicalize(&root) {- Ok(r) => r,- Err(_) => continue,- };- let candidate = canonical_root.join(slug);- if candidate.starts_with(&canonical_root) && candidate.exists() {- return Some(candidate);- }+ _ => Vec::new(),}- None}pub(crate) fn create_workflow_inner(@@ -184,25 +166,9 @@ pub(crate) fn create_workflow_inner(validate_inputs(&mut params.inputs)?;- let display_name = params.name.trim();- if display_name.is_empty() {- return Err("name must not be empty".to_string());- }- if display_name.len() > MAX_NAME_LEN {- return Err(format!("name exceeds max {MAX_NAME_LEN} chars"));- }-- let description = params.description.trim();- if description.is_empty() {- return Err("description must not be empty".to_string());- }- if description.len() > MAX_DESCRIPTION_LEN {- return Err(format!(- "description exceeds max {MAX_DESCRIPTION_LEN} chars"- ));- }-- let slug = slugify_workflow_name(display_name)?;+ let display_name = validate_display_name(¶ms.name).map_err(|e| e.to_string())?;+ let description = validate_description(¶ms.description).map_err(|e| e.to_string())?;+ let slug = slugify(display_name).map_err(|e| e.to_string())?;let scope_root = match params.scope {WorkflowScope::User => {@@ -243,115 +209,24 @@ pub(crate) fn create_workflow_inner(}};- std::fs::create_dir_all(&scope_root)- .map_err(|e| format!("failed to create skills root {}: {e}", scope_root.display()))?;-- let canonical_root = std::fs::canonicalize(&scope_root).map_err(|e| {- format!(- "failed to canonicalize skills root {}: {e}",- scope_root.display()- )- })?;-- let mut skill_dir = canonical_root.join(&slug);- if !skill_dir.starts_with(&canonical_root) {- return Err(format!(- "resolved skill dir {} escapes scope root {}",- skill_dir.display(),- canonical_root.display(),- ));- }-- // On edit (overwrite) the target may predate the skills→workflows rename and- // still live under a legacy compat root (`~/.openhuman/skills/`,- // `~/.agents/skills/`, or their project equivalents) — the same roots- // discovery scans (see ops_discover::user_roots/project_roots). When it- // isn't at the primary `workflows/` path, resolve it from those legacy- // roots and update it in place; the SKILL.md→WORKFLOW.md migration below- // converts the on-disk naming. A fresh create always writes to `workflows/`.- if params.overwrite && !skill_dir.exists() {- if let Some(legacy_dir) = legacy_workflow_dir(home_dir, workspace_dir, params.scope, &slug)- {- tracing::debug!(- slug = %slug,- from = %legacy_dir.display(),- "[skills] create_workflow: updating legacy-located workflow in place"- );- skill_dir = legacy_dir;- }- }-- let dir_exists = skill_dir.exists();- if dir_exists && !params.overwrite {- return Err(format!(- "skill '{slug}' already exists at {}",- skill_dir.display()- ));- }- if !dir_exists && params.overwrite {- return Err(format!(- "cannot update workflow '{slug}': it does not exist at {}",- skill_dir.display()- ));- }-- std::fs::create_dir_all(&skill_dir)- .map_err(|e| format!("failed to create skill dir {}: {e}", skill_dir.display()))?;-- let workflow_md_path = skill_dir.join(WORKFLOW_MD);- let legacy_md_path = skill_dir.join(SKILL_MD);- // On edit, preserve the hand-authored body (everything after the- // frontmatter) and rewrite only the frontmatter from the form fields. Read- // the body from the current WORKFLOW.md, falling back to a legacy SKILL.md.- // On create — or if neither parses — emit the full template body.- let preserved_body = if params.overwrite {- super::ops_parse::parse_workflow_md(&workflow_md_path)- .or_else(|| super::ops_parse::parse_workflow_md(&legacy_md_path))- .map(|(_, body, _)| body)- } else {- None+ // Containment, create/edit preconditions, body preservation, legacy+ // SKILL.md migration and resource dirs are owned by tinyskills.+ let spec = BundleSpec {+ slug: slug.clone(),+ description: description.to_owned(),+ license: params.license.clone(),+ author: params.author.clone(),+ tags: params.tags.clone(),+ allowed_tools: params.allowed_tools.clone(),};- let workflow_md = match preserved_body {- Some(body) => {- let mut out = render_workflow_frontmatter(- &slug,- description,- params.license.as_deref(),- params.author.as_deref(),- ¶ms.tags,- ¶ms.allowed_tools,- );- out.push('\n');- out.push_str(body.trim_start_matches('\n'));- if !out.ends_with('\n') {- out.push('\n');- }- out- }- // On edit, refuse rather than overwrite the user's instructions with- // the scaffold template when the existing body couldn't be parsed —- // silently replacing it would be data loss.- None if params.overwrite => {- return Err(format!(- "cannot update workflow '{slug}': existing markdown could not be parsed safely (refusing to overwrite the body)"- ));- }- None => render_workflow_md(- &slug,- description,- params.license.as_deref(),- params.author.as_deref(),- ¶ms.tags,- ¶ms.allowed_tools,- ),+ let options = ScaffoldOptions {+ overwrite: params.overwrite,+ legacy_roots: legacy_workflow_roots(home_dir, workspace_dir, params.scope),+ ..Default::default()};- std::fs::write(&workflow_md_path, workflow_md)- .map_err(|e| format!("failed to write {}: {e}", workflow_md_path.display()))?;- // Edit migration: if this workflow still had a legacy SKILL.md alongside the- // new WORKFLOW.md, drop it so discovery doesn't surface a duplicate.- if params.overwrite && legacy_md_path != workflow_md_path && legacy_md_path.exists() {- let _ = std::fs::remove_file(&legacy_md_path);- }+ let scaffolded = scaffold_bundle(&scope_root, &spec, &options).map_err(|e| e.to_string())?;+ let skill_dir = scaffolded.dir;+ let workflow_md_path = scaffolded.document;// Emit a sibling skill.toml when the user declared `[[inputs]]` OR gave a// distinct `when_to_use` trigger at create time. The registry reads this@@ -386,12 +261,6 @@ pub(crate) fn create_workflow_inner(}}- for sub in RESOURCE_DIRS {- let sub_path = skill_dir.join(sub);- std::fs::create_dir_all(&sub_path)- .map_err(|e| format!("failed to create {}: {e}", sub_path.display()))?;- }-tracing::info!(slug = %slug,scope = ?params.scope,@@ -438,145 +307,6 @@ fn validate_inputs(inputs: &mut [WorkflowCreateInputDef]) -> Result<(), String>Ok(())}-/// Convert a human-readable skill name to a filesystem-safe slug.-///-/// Rules:-/// * ASCII alphanumeric characters are lowercased and kept.-/// * Whitespace, `-`, and `_` collapse to a single `-`.-/// * Any other character is dropped.-/// * Leading / trailing `-` are trimmed.-/// * The empty slug (i.e. the name had no `[a-z0-9]` characters) is rejected.-pub(crate) fn slugify_workflow_name(name: &str) -> Result<String, String> {- let mut out = String::new();- let mut prev_hyphen = true;- for ch in name.chars() {- if ch.is_ascii_alphanumeric() {- out.push(ch.to_ascii_lowercase());- prev_hyphen = false;- } else if (ch == '-' || ch == '_' || ch.is_whitespace()) && !prev_hyphen {- out.push('-');- prev_hyphen = true;- }- }- while out.ends_with('-') {- out.pop();- }- if out.is_empty() {- return Err(format!(- "name '{name}' has no alphanumeric characters; cannot derive slug"- ));- }- if out.len() > MAX_NAME_LEN {- return Err(format!("slug '{out}' exceeds max {MAX_NAME_LEN} chars"));- }- Ok(out)-}--/// Render a minimal SKILL.md body for a freshly scaffolded skill.-/// Render just the YAML frontmatter block (`---\n…\n---\n`) from the form-/// fields. Split out from [`render_workflow_md`] so the update/edit path can-/// rewrite frontmatter in place while preserving the hand-authored body.-pub(crate) fn render_workflow_frontmatter(- slug: &str,- description: &str,- license: Option<&str>,- author: Option<&str>,- tags: &[String],- allowed_tools: &[String],-) -> String {- let mut out = String::new();- out.push_str("---\n");- out.push_str(&format!("name: {slug}\n"));- out.push_str(&format!("description: {}\n", yaml_scalar(description)));- if let Some(v) = license {- out.push_str(&format!("license: {}\n", yaml_scalar(v)));- }- let has_metadata = author.is_some() || !tags.is_empty();- if has_metadata {- out.push_str("metadata:\n");- if let Some(v) = author {- out.push_str(&format!(" author: {}\n", yaml_scalar(v)));- }- if !tags.is_empty() {- out.push_str(" tags:\n");- for t in tags {- out.push_str(&format!(" - {}\n", yaml_scalar(t)));- }- }- }- if !allowed_tools.is_empty() {- out.push_str("allowed-tools:\n");- for t in allowed_tools {- out.push_str(&format!(" - {}\n", yaml_scalar(t)));- }- }- out.push_str("---\n");- out-}--pub(crate) fn render_workflow_md(- slug: &str,- description: &str,- license: Option<&str>,- author: Option<&str>,- tags: &[String],- allowed_tools: &[String],-) -> String {- let mut out =- render_workflow_frontmatter(slug, description, license, author, tags, allowed_tools);- out.push('\n');- out.push_str(&format!("# {slug}\n\n"));- out.push_str(description);- if !description.ends_with('\n') {- out.push('\n');- }- out.push_str("\n## Instructions\n\n");- out.push_str("_Describe when and how this skill should be used._\n");- out-}--/// Best-effort YAML scalar encoder: pass plain-safe strings through,-/// double-quote anything with structure / whitespace / control chars.-pub(crate) fn yaml_scalar(s: &str) -> String {- let needs_quote = s.is_empty()- || s.chars().any(|c| {- matches!(- c,- ':' | '#'- | '\''- | '"'- | '\n'- | '\r'- | '\t'- | '['- | ']'- | '{'- | '}'- | ','- | '&'- | '*'- | '!'- | '|'- | '>'- | '%'- | '@'- | '`'- )- })- || s.starts_with(|c: char| c.is_ascii_whitespace() || c == '-' || c == '?')- || s.ends_with(|c: char| c.is_ascii_whitespace());- if !needs_quote {- return s.to_string();- }- let escaped = s- .replace('\\', "\\\\")- .replace('"', "\\\"")- .replace('\n', "\\n")- .replace('\r', "\\r")- .replace('\t', "\\t");- format!("\"{escaped}\"")-}-/// Render the sibling `skill.toml` next to a freshly scaffolded SKILL.md/// when the user declared `[[inputs]]` at create time. Emits the/// minimal set the registry parser needs to discover and render the