From 6b9ae7f86a162c12c87d189b0681dc8fda406505 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E6=BD=AE?= Date: Thu, 26 Mar 2026 15:47:28 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20skill=20=E5=88=A0=E9=99=A4=E6=97=B6?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E6=B8=85=E7=90=86=20robot=20=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=EF=BC=8C=E8=A7=A3=E5=8E=8B=E6=97=B6=E8=B7=B3=E8=BF=87?= =?UTF-8?q?=E5=B7=B2=E5=AD=98=E5=9C=A8=E7=9A=84=20skill?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. remove_skill 删除 uploads 下的 skill 后,同步删除 projects/robot/{bot_id}/skills/ 下的副本 2. _extract_skills_to_robot 不再每次全量清空重建,已存在的 skill 直接跳过 Co-Authored-By: Claude Opus 4.6 (1M context) --- routes/skill_manager.py | 7 ++++++- utils/multi_project_manager.py | 17 +++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/routes/skill_manager.py b/routes/skill_manager.py index 6898161..49158c4 100644 --- a/routes/skill_manager.py +++ b/routes/skill_manager.py @@ -786,9 +786,14 @@ async def remove_skill( # 使用线程池删除目录(避免阻塞事件循环) await asyncio.to_thread(shutil.rmtree, skill_dir_real) - logger.info(f"Successfully removed skill directory: {skill_dir_real}") + # 同步删除 robot 目录下的 skill 副本 + robot_skill_dir = os.path.join(base_dir, "projects", "robot", bot_id, "skills", skill_name) + if os.path.exists(robot_skill_dir): + await asyncio.to_thread(shutil.rmtree, robot_skill_dir) + logger.info(f"Also removed robot skill directory: {robot_skill_dir}") + return { "success": True, "message": f"Skill '{skill_name}' 删除成功", diff --git a/utils/multi_project_manager.py b/utils/multi_project_manager.py index 885f7d3..8fd6cda 100644 --- a/utils/multi_project_manager.py +++ b/utils/multi_project_manager.py @@ -391,16 +391,17 @@ def _extract_skills_to_robot(bot_id: str, skills: List[str], project_path: Path) Path("skills"), ] skills_target_dir = project_path / "robot" / bot_id / "skills" - - # 先清空 skills_target_dir,然后重新复制 - if skills_target_dir.exists(): - logger.info(f" Removing existing skills directory: {skills_target_dir}") - shutil.rmtree(skills_target_dir) - skills_target_dir.mkdir(parents=True, exist_ok=True) logger.info(f"Copying skills to {skills_target_dir}") for skill in skills: + target_dir = skills_target_dir / os.path.basename(skill) + + # 如果目标目录已存在,跳过复制 + if target_dir.exists(): + logger.info(f" Skill '{skill}' already exists in {target_dir}, skipping") + continue + source_dir = None # 简单名称:按优先级顺序在多个目录中查找 @@ -415,10 +416,6 @@ def _extract_skills_to_robot(bot_id: str, skills: List[str], project_path: Path) logger.warning(f" Skill directory '{skill}' not found in any source directory: {[str(d) for d in skills_source_dirs]}") continue - if not source_dir.exists(): - logger.warning(f" Skill directory not found: {source_dir}") - continue - target_dir = skills_target_dir / os.path.basename(skill) try: