Hmbown/CodeWhale · error

skill name must be a single path-safe segment

Error message

skill name must be a single path-safe segment (got '{name}')

What it means

`validate_skill_name_segment` enforces that a skill name is a single, path-safe path component: non-empty, no surrounding or internal whitespace, not `.`/`..`, no path separators, and exactly one `Normal` component. This prevents skills from escaping the skills directory via crafted names (path traversal) or resolving to surprising locations.

Solutions

  1. Sanitize the name: take only the final path segment, trim whitespace, reject separators
  2. Validate the name with `validate_skill_name_segment` before calling install/uninstall/update
  3. Fix the upstream registry entry/URL parsing that produced the unsafe name

Example fix

// before
let name = "acme/skill"; // from registry entry
uninstall(name, &skills_dir)?; // bails
// after
let name = "acme/skill".rsplit('/').next().unwrap().trim();
validate_skill_name_segment(name)?;
uninstall(name, &skills_dir)?;
Defensive patterns

Strategy: validation

Validate before calling

fn safe_name(n: &str) -> Option<&str> {
    let n = n.rsplit(['/', '\\']).next().unwrap_or("").trim();
    validate_skill_name_segment(n).ok()
}

Try / catch

let name = validate_skill_name_segment(&raw_name)
    .map_err(|e| anyhow!("rejecting skill name: {e}"))?;

Prevention

When it happens

Trigger: Passing any name with `/`, `\\`, leading/trailing whitespace, internal whitespace, `.` or `..`, an empty string, or components like `..`/root prefixes to `uninstall`, `skill_target_path`, `update*`, or `validate_skill_name_segment` itself.

Common situations: Names parsed from URLs or registry entries retaining a path suffix (`"acme/skill"`); shell-quoting artifacts leaving stray spaces; malicious registry entries attempting `../` traversal; empty name from a failed parse.

Understand the failure class

Background: Path traversal blocked: "path escapes the workspace" and "outside site root" errors when a path will not stay inside its allowed directory — this error's family across 26 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/3136fc2035349d8b. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/skills/install.rs:1549

    }
    for component in path.components() {
        match component {
            Component::ParentDir => return false,
            Component::Prefix(_) | Component::RootDir => return false,
            _ => {}
        }
    }
    true
}

fn skill_target_path(name: &str, skills_dir: &Path) -> Result<PathBuf> {
    let name = validate_skill_name_segment(name)?;
    Ok(skills_dir.join(name))
}

pub(crate) fn validate_skill_name_segment(name: &str) -> Result<&str> {
    if name.is_empty() || name.trim() != name || name.chars().any(char::is_whitespace) {
        bail!("skill name must be a single path-safe segment (got '{name}')");
    }
    if name == "." || name == ".." || name.contains('/') || name.contains('\\') {
        bail!("skill name must be a single path-safe segment (got '{name}')");
    }
    let mut components = Path::new(name).components();
    if !matches!(components.next(), Some(Component::Normal(_))) || components.next().is_some() {
        bail!("skill name must be a single path-safe segment (got '{name}')");
    }
    Ok(name)
}

fn ensure_target_within_skills_dir(target: &Path, skills_dir: &Path) -> Result<()> {
    let skills_dir = fs::canonicalize(skills_dir)
        .with_context(|| format!("failed to resolve {}", skills_dir.display()))?;
    let target = fs::canonicalize(target)
        .with_context(|| format!("failed to resolve {}", target.display()))?;
    if !target.starts_with(&skills_dir) {
        bail!(

View on GitHub (pinned to 73e0f67d83)