Skip to content

Commit 1914add

Browse files
authored
allow absolute paths for skills directories (#524)
1 parent 594892a commit 1914add

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

src/fast_agent/skills/registry.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ def load_manifests(self) -> list[SkillManifest]:
6969
adjusted_manifest = replace(manifest, relative_path=relative_path)
7070
adjusted_manifests.append(adjusted_manifest)
7171
except ValueError:
72-
# If we can't compute relative path, keep the original
73-
adjusted_manifests.append(manifest)
72+
# Path is outside workspace - clear relative_path so absolute path is used
73+
adjusted_manifest = replace(manifest, relative_path=None)
74+
adjusted_manifests.append(adjusted_manifest)
7475

7576
return adjusted_manifests
7677

tests/unit/fast_agent/agents/test_mcp_agent_skills.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from fast_agent.agents.agent_types import AgentConfig
77
from fast_agent.agents.mcp_agent import McpAgent
88
from fast_agent.context import Context
9-
from fast_agent.skills.registry import SkillRegistry
9+
from fast_agent.skills.registry import SkillRegistry, format_skills_for_prompt
1010

1111

1212
def create_skill(directory: Path, name: str, description: str = "desc", body: str = "Body") -> None:
@@ -89,3 +89,32 @@ async def test_agent_skills_missing_placeholder_warns(tmp_path: Path) -> None:
8989

9090
mock_warning.assert_called_once()
9191
assert "system prompt does not include {{agentSkills}}" in mock_warning.call_args[0][0]
92+
93+
94+
def test_skills_absolute_dir_outside_cwd(tmp_path: Path) -> None:
95+
"""When skills dir is outside base_dir, absolute paths should be used in prompts."""
96+
# Create skills in tmp_path (simulates /tmp/foo)
97+
skills_root = tmp_path / "external_skills"
98+
create_skill(skills_root, "external", description="External skill")
99+
100+
# Use a different base_dir that doesn't contain skills_root
101+
base_dir = tmp_path / "workspace"
102+
base_dir.mkdir()
103+
104+
# Create registry with base_dir different from skills directory
105+
registry = SkillRegistry(base_dir=base_dir, override_directory=skills_root)
106+
manifests = registry.load_manifests()
107+
108+
assert len(manifests) == 1
109+
manifest = manifests[0]
110+
111+
# relative_path should be None since skills_root is outside base_dir
112+
assert manifest.relative_path is None
113+
114+
# The absolute path should still be set
115+
assert manifest.path is not None
116+
assert manifest.path.is_absolute()
117+
118+
# format_skills_for_prompt should use the absolute path
119+
prompt = format_skills_for_prompt(manifests)
120+
assert f'path="{manifest.path}"' in prompt

0 commit comments

Comments
 (0)