From 97586e0b108c97985c72157fe72839a929323b70 Mon Sep 17 00:00:00 2001 From: chmod777john Date: Mon, 12 Jan 2026 11:16:22 +0800 Subject: [PATCH] feat(skill): inject skill root directory path into prompt Inject the absolute path of the skill root directory into the prompt when loading a skill. This allows AI to: 1. Always know the base location of skill files 2. Debug path issues even when skill authors mix absolute/relative paths 3. Use find/glob tools to locate files dynamically The previous approach of only converting specific directory patterns (scripts/, references/, etc.) was too limited and didn't account for the variety of ways skill authors might structure their content. Related: Improve skill path resolution --- mini_agent/tools/skill_loader.py | 7 +++++++ tests/test_skill_loader.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/mini_agent/tools/skill_loader.py b/mini_agent/tools/skill_loader.py index fde62b4..3eb5484 100644 --- a/mini_agent/tools/skill_loader.py +++ b/mini_agent/tools/skill_loader.py @@ -26,11 +26,18 @@ class Skill: def to_prompt(self) -> str: """Convert skill to prompt format""" + # Inject skill root directory path for context + skill_root = str(self.skill_path.parent) if self.skill_path else "unknown" + return f""" # Skill: {self.name} {self.description} +**Skill Root Directory:** `{skill_root}` + +All files and references in this skill are relative to this directory. + --- {self.content} diff --git a/tests/test_skill_loader.py b/tests/test_skill_loader.py index 874a52e..fac153c 100644 --- a/tests/test_skill_loader.py +++ b/tests/test_skill_loader.py @@ -244,3 +244,31 @@ def test_script_path_processing(): # Check that script path is converted to absolute assert str(skill_dir / "scripts" / "test_script.py") in skill.content + + +def test_skill_to_prompt_includes_root_directory(): + """Test that to_prompt includes skill root directory path""" + with tempfile.TemporaryDirectory() as tmpdir: + skill_dir = Path(tmpdir) / "test-skill" + skill_dir.mkdir() + + skill_file = skill_dir / "SKILL.md" + skill_content = """--- +name: test-skill +description: A test skill +--- + +Skill content here. +""" + skill_file.write_text(skill_content, encoding="utf-8") + + loader = SkillLoader(tmpdir) + skill = loader.load_skill(skill_file) + + assert skill is not None + + # Test to_prompt includes root directory + prompt = skill.to_prompt() + assert "Skill Root Directory" in prompt + assert str(skill_dir) in prompt + assert "All files and references in this skill are relative to this directory" in prompt