Compare commits

...

2 Commits

Author SHA1 Message Date
朱潮
6ecb0d70e3 Merge branch 'developing' into bot_manager 2026-03-26 15:47:42 +08:00
朱潮
6b9ae7f86a fix: skill 删除时同步清理 robot 目录,解压时跳过已存在的 skill
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) <noreply@anthropic.com>
2026-03-26 15:47:28 +08:00
2 changed files with 13 additions and 11 deletions

View File

@ -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}' 删除成功",

View File

@ -392,16 +392,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
# 简单名称:按优先级顺序在多个目录中查找
@ -416,10 +417,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: