Skip to content
Open
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
32 changes: 22 additions & 10 deletions src-tauri/src/services/skill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -880,25 +880,37 @@ impl SkillService {
let mut unmanaged: HashMap<String, UnmanagedSkill> = HashMap::new();

for (scan_dir, label) in &scan_sources {
let entries = match fs::read_dir(scan_dir) {
Ok(e) => e,
Err(_) => continue,
let skill_dirs = match Self::scan_skills_in_dir(scan_dir) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid recursive symlink traversal in unmanaged scan

scan_unmanaged now calls the recursive scanner for user skill roots, but the recursion follows symlinked directories (path.is_dir()) without any visited-path guard. A symlink cycle inside a skills folder (for example loop -> ..) will recurse forever and can hang or stack-overflow unmanaged scanning. Since this path is now exercised on normal app directories, the scan should skip symlink dirs or track canonicalized visited directories.

Useful? React with 👍 / 👎.

Ok(dirs) => dirs,
Err(err) => {
log::warn!("Failed to scan skills in {}: {err}", scan_dir.display());
continue;
}
};
for entry in entries.flatten() {
let path = entry.path();
if !path.is_dir() {

for skill_dir in skill_dirs {
let rel = match skill_dir.strip_prefix(scan_dir) {
Ok(path) => path,
Err(_) => continue,
};
if rel.components().next().is_none() {
continue;
}
let dir_name = entry.file_name().to_string_lossy().to_string();
let dir_name = rel.to_string_lossy().to_string();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Normalize unmanaged directory key before persisting

Using rel.to_string_lossy() as dir_name makes unmanaged nested skills keep their full relative path (for example repo/skills/foo) as InstalledSkill.directory when imported, but downstream install-state logic still compares by basename (e.g., Path::file_name() in list_skills and install). In that flow, an imported nested skill is shown as not installed and can be reinstalled under a different directory key, which desynchronizes metadata and leaves stale paths behind. Please normalize directory identity consistently (or update all consumers to treat nested keys as canonical).

Useful? React with 👍 / 👎.

if dir_name.starts_with('.') || managed_dirs.contains(&dir_name) {
continue;
}

let skill_md = path.join("SKILL.md");
let skill_md = skill_dir.join("SKILL.md");
if !skill_md.exists() {
continue;
}
let (name, description) = Self::read_skill_name_desc(&skill_md, &dir_name);

let fallback_name = skill_dir
.file_name()
.map(|name| name.to_string_lossy().to_string())
.unwrap_or_else(|| dir_name.clone());
let (name, description) = Self::read_skill_name_desc(&skill_md, &fallback_name);

unmanaged
.entry(dir_name.clone())
Expand All @@ -908,7 +920,7 @@ impl SkillService {
name,
description,
found_in: vec![label.clone()],
path: path.display().to_string(),
path: skill_dir.display().to_string(),
});
}
}
Expand Down