From edc71efe4c44b66f1d597d1028cf56a08ed2e522 Mon Sep 17 00:00:00 2001 From: YoVinchen Date: Sun, 23 Nov 2025 16:25:55 +0800 Subject: [PATCH] fix(skills): auto-sync locally installed skills to database Add automatic synchronization in get_skills command: - Detect locally installed skills in ~/.claude/skills/ - Auto-add to database if not already tracked - Ensures existing skills are recognized on first launch This fixes the issue where user's existing skills were not imported into the database on initial application run. --- src-tauri/src/commands/skill.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src-tauri/src/commands/skill.rs b/src-tauri/src/commands/skill.rs index d9731c0..64ea950 100644 --- a/src-tauri/src/commands/skill.rs +++ b/src-tauri/src/commands/skill.rs @@ -15,11 +15,32 @@ pub async fn get_skills( ) -> Result, String> { let repos = app_state.db.get_skill_repos().map_err(|e| e.to_string())?; - service + let skills = service .0 .list_skills(repos) .await - .map_err(|e| e.to_string()) + .map_err(|e| e.to_string())?; + + // 自动同步本地已安装的 skills 到数据库 + // 这样用户在首次运行时,已有的 skills 会被自动记录 + let existing_states = app_state.db.get_skills().unwrap_or_default(); + + for skill in &skills { + if skill.installed && !existing_states.contains_key(&skill.directory) { + // 本地有该 skill,但数据库中没有记录,自动添加 + if let Err(e) = app_state.db.update_skill_state( + &skill.directory, + &SkillState { + installed: true, + installed_at: Utc::now(), + }, + ) { + log::warn!("同步本地 skill {} 状态到数据库失败: {}", skill.directory, e); + } + } + } + + Ok(skills) } #[tauri::command]