From fe7280d2acc1b68f601b1b4c491a8b8d11754fdb Mon Sep 17 00:00:00 2001 From: Lovelace <61972457+Lovlace777@users.noreply.github.com> Date: Tue, 23 Jun 2026 23:13:05 +0800 Subject: [PATCH] Python: Stop skill discovery at skill boundaries --- python/packages/core/agent_framework/_skills.py | 1 + python/packages/core/tests/core/test_skills.py | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/python/packages/core/agent_framework/_skills.py b/python/packages/core/agent_framework/_skills.py index 91bdb619143..e863ada3ecd 100644 --- a/python/packages/core/agent_framework/_skills.py +++ b/python/packages/core/agent_framework/_skills.py @@ -3092,6 +3092,7 @@ def _search(directory: str, current_depth: int) -> None: dir_path = Path(directory) if (dir_path / SKILL_FILE_NAME).is_file(): discovered.append(str(dir_path.absolute())) + return if current_depth >= MAX_SEARCH_DEPTH: return diff --git a/python/packages/core/tests/core/test_skills.py b/python/packages/core/tests/core/test_skills.py index 12d636ef414..43211e5f15d 100644 --- a/python/packages/core/tests/core/test_skills.py +++ b/python/packages/core/tests/core/test_skills.py @@ -1917,6 +1917,19 @@ def test_finds_nested_skill(self, tmp_path: Path) -> None: assert len(dirs) == 1 assert str(sub.absolute()) in dirs[0] + def test_stops_searching_below_skill_boundary(self, tmp_path: Path) -> None: + skill_dir = tmp_path / "parent-skill" + nested_skill_dir = skill_dir / "nested-skill" + nested_skill_dir.mkdir(parents=True) + (skill_dir / "SKILL.md").write_text("---\nname: parent-skill\ndescription: d\n---\n", encoding="utf-8") + (nested_skill_dir / "SKILL.md").write_text( + "---\nname: nested-skill\ndescription: d\n---\n", encoding="utf-8" + ) + + dirs = FileSkillsSource._discover_skill_directories([str(tmp_path)]) + + assert dirs == [str(skill_dir.absolute())] + def test_skips_empty_path_string(self) -> None: dirs = FileSkillsSource._discover_skill_directories(["", " "]) assert dirs == []