fix: 解压 skill 到 robot 目录时清理不在列表中的多余 skill 文件夹

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
朱潮 2026-03-26 15:55:06 +08:00
parent 6b9ae7f86a
commit 89b7bb9928

View File

@ -394,6 +394,14 @@ def _extract_skills_to_robot(bot_id: str, skills: List[str], project_path: Path)
skills_target_dir.mkdir(parents=True, exist_ok=True)
logger.info(f"Copying skills to {skills_target_dir}")
# 清理不在列表中的多余 skill 文件夹
expected_skill_names = {os.path.basename(skill) for skill in skills}
if skills_target_dir.exists():
for item in skills_target_dir.iterdir():
if item.is_dir() and item.name not in expected_skill_names:
logger.info(f" Removing stale skill directory: {item}")
shutil.rmtree(item)
for skill in skills:
target_dir = skills_target_dir / os.path.basename(skill)