优化skill覆盖逻辑

This commit is contained in:
朱潮 2026-04-17 11:43:20 +08:00
parent 9f12a633bc
commit 90229ffeaf

View File

@ -401,23 +401,30 @@ 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}")
managed_skill_names = set()
for base_dir in skills_source_dirs:
if not base_dir.exists():
continue
for item in base_dir.iterdir():
if item.is_dir():
managed_skill_names.add(item.name)
# 清理不在列表中的多余 skill 文件夹
expected_skill_names = {Path(skill.lstrip("@")).name 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}")
if not item.is_dir() or item.name in expected_skill_names:
continue
if item.name in managed_skill_names:
logger.info(f" Removing managed stale skill directory: {item}")
shutil.rmtree(item)
else:
logger.info(f" Keeping unmanaged skill directory: {item}")
for skill in skills:
skill_name = Path(skill.lstrip("@")).name
target_dir = skills_target_dir / skill_name
# 如果目标目录已存在,跳过复制
if target_dir.exists():
logger.info(f" Skill '{skill}' already exists in {target_dir}, skipping")
continue
source_dir = None
if skill.startswith("@"):
@ -440,7 +447,7 @@ def _extract_skills_to_robot(bot_id: str, skills: List[str], project_path: Path)
continue
try:
shutil.copytree(source_dir, target_dir)
logger.info(f" Copied: {source_dir} -> {target_dir}")
shutil.copytree(source_dir, target_dir, dirs_exist_ok=True)
logger.info(f" Synced: {source_dir} -> {target_dir}")
except Exception as e:
logger.error(f" Failed to copy {source_dir}: {e}")