-
Notifications
You must be signed in to change notification settings - Fork 800
feat(skills): support loading skills from URLs #2091
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mkmeral
merged 9 commits into
strands-agents:main
from
dgallitelli:feat/skills-github-url-loading
Apr 15, 2026
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a7bddae
feat(skills): support loading skills from GitHub/Git URLs
83966f6
feat(skills): support GitHub /tree/ URLs for nested skills
7f89fd8
fix(skills): address review feedback on URL loading
393dcd7
refactor(skills): replace git clone with HTTPS-only fetch
d049e09
fix(skills): address v2 review feedback
bfa2951
simplify(skills): remove GitHub URL resolution per maintainer feedback
b11b4e3
simplify(skills): inline URL fetch into Skill, remove _url_loader.py
8db72a7
fix(skills): fix stale docstring, add invalid content test
759d822
fix(skills): update set_available_skills docstring, add duplicate URL…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| """Utilities for loading skills from HTTPS URLs. | ||
|
|
||
| This module provides functions to detect URL-type skill sources and | ||
| fetch SKILL.md content over HTTPS. No git dependency, local caching, | ||
| or URL resolution is required — callers provide a direct URL to the | ||
| raw SKILL.md content. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import logging | ||
| import urllib.error | ||
| import urllib.request | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def is_url(source: str) -> bool: | ||
| """Check whether a skill source string looks like an HTTPS URL. | ||
|
|
||
| Only ``https://`` URLs are supported; plaintext ``http://`` is rejected | ||
| for security (MITM risk). | ||
|
|
||
| Args: | ||
| source: The skill source string to check. | ||
|
|
||
| Returns: | ||
| True if the source is an ``https://`` URL. | ||
| """ | ||
| return source.startswith("https://") | ||
|
|
||
|
|
||
| def fetch_skill_content(url: str) -> str: | ||
| """Fetch SKILL.md content from an HTTPS URL. | ||
|
|
||
| Uses ``urllib.request`` (stdlib) so no additional dependencies are needed. | ||
|
|
||
| Args: | ||
| url: The HTTPS URL to fetch. Must point directly to the raw | ||
| SKILL.md content (for example, | ||
| ``https://raw.githubusercontent.com/org/repo/main/SKILL.md``). | ||
|
|
||
| Returns: | ||
| The response body as a string. | ||
|
|
||
| Raises: | ||
| ValueError: If ``url`` is not an ``https://`` URL. | ||
| RuntimeError: If the fetch fails (network error, 404, etc.). | ||
| """ | ||
| if not url.startswith("https://"): | ||
| raise ValueError(f"url=<{url}> | only https:// URLs are supported") | ||
|
|
||
| logger.info("url=<%s> | fetching skill content", url) | ||
|
|
||
| try: | ||
| req = urllib.request.Request(url, headers={"User-Agent": "strands-agents-sdk"}) # noqa: S310 | ||
| with urllib.request.urlopen(req, timeout=30) as response: # noqa: S310 | ||
| content: str = response.read().decode("utf-8") | ||
| return content | ||
| except urllib.error.HTTPError as e: | ||
| raise RuntimeError(f"url=<{url}> | HTTP {e.code}: {e.reason}") from e | ||
| except urllib.error.URLError as e: | ||
| raise RuntimeError(f"url=<{url}> | failed to fetch skill: {e.reason}") from e | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| """Tests for the _url_loader module.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import urllib.error | ||
| from unittest.mock import MagicMock, patch | ||
|
|
||
| import pytest | ||
|
|
||
| from strands.vended_plugins.skills._url_loader import ( | ||
| fetch_skill_content, | ||
| is_url, | ||
| ) | ||
|
|
||
|
|
||
| class TestIsUrl: | ||
| """Tests for is_url.""" | ||
|
|
||
| def test_https_url(self): | ||
| assert is_url("https://example.com/SKILL.md") is True | ||
|
|
||
| def test_https_raw_github_url(self): | ||
| assert is_url("https://raw.githubusercontent.com/org/repo/main/SKILL.md") is True | ||
|
|
||
| def test_http_rejected(self): | ||
| """Plaintext http:// is rejected for security.""" | ||
| assert is_url("http://example.com/SKILL.md") is False | ||
|
|
||
| def test_ssh_rejected(self): | ||
| assert is_url("ssh://git@github.com/org/repo") is False | ||
|
|
||
| def test_git_at_rejected(self): | ||
| assert is_url("git@github.com:org/repo.git") is False | ||
|
|
||
| def test_local_relative_path(self): | ||
| assert is_url("./skills/my-skill") is False | ||
|
|
||
| def test_local_absolute_path(self): | ||
| assert is_url("/home/user/skills/my-skill") is False | ||
|
|
||
| def test_plain_directory_name(self): | ||
| assert is_url("my-skill") is False | ||
|
|
||
| def test_empty_string(self): | ||
| assert is_url("") is False | ||
|
|
||
|
|
||
| class TestFetchSkillContent: | ||
| """Tests for fetch_skill_content.""" | ||
|
|
||
| _LOADER = "strands.vended_plugins.skills._url_loader" | ||
|
|
||
| def test_fetch_success(self): | ||
| """Test successful content fetch.""" | ||
| skill_content = "---\nname: test-skill\ndescription: A test\n---\n# Instructions\n" | ||
|
|
||
| mock_response = MagicMock() | ||
| mock_response.read.return_value = skill_content.encode("utf-8") | ||
| mock_response.__enter__ = MagicMock(return_value=mock_response) | ||
| mock_response.__exit__ = MagicMock(return_value=False) | ||
|
|
||
| with patch(f"{self._LOADER}.urllib.request.urlopen", return_value=mock_response): | ||
| result = fetch_skill_content("https://raw.githubusercontent.com/org/repo/main/SKILL.md") | ||
|
|
||
| assert result == skill_content | ||
|
|
||
| def test_fetch_uses_url_directly(self): | ||
| """Test that the URL is used as-is with no resolution.""" | ||
| url = "https://raw.githubusercontent.com/org/repo/main/skills/my-skill/SKILL.md" | ||
|
|
||
| mock_response = MagicMock() | ||
| mock_response.read.return_value = b"---\nname: t\ndescription: t\n---\n" | ||
| mock_response.__enter__ = MagicMock(return_value=mock_response) | ||
| mock_response.__exit__ = MagicMock(return_value=False) | ||
|
|
||
| with patch(f"{self._LOADER}.urllib.request.urlopen", return_value=mock_response) as mock_urlopen: | ||
| fetch_skill_content(url) | ||
|
|
||
| request_obj = mock_urlopen.call_args[0][0] | ||
| assert request_obj.full_url == url | ||
|
|
||
| def test_fetch_sets_user_agent(self): | ||
| """Test that requests include a User-Agent header.""" | ||
| mock_response = MagicMock() | ||
| mock_response.read.return_value = b"---\nname: t\ndescription: t\n---\n" | ||
| mock_response.__enter__ = MagicMock(return_value=mock_response) | ||
| mock_response.__exit__ = MagicMock(return_value=False) | ||
|
|
||
| with patch(f"{self._LOADER}.urllib.request.urlopen", return_value=mock_response) as mock_urlopen: | ||
| fetch_skill_content("https://example.com/SKILL.md") | ||
|
|
||
| request_obj = mock_urlopen.call_args[0][0] | ||
| assert request_obj.get_header("User-agent") == "strands-agents-sdk" | ||
|
|
||
| def test_fetch_http_error(self): | ||
| """Test that HTTP errors raise RuntimeError.""" | ||
| with patch( | ||
| f"{self._LOADER}.urllib.request.urlopen", | ||
| side_effect=urllib.error.HTTPError( | ||
| url="https://example.com", code=404, msg="Not Found", hdrs=None, fp=None | ||
| ), | ||
| ): | ||
| with pytest.raises(RuntimeError, match="HTTP 404"): | ||
| fetch_skill_content("https://example.com/SKILL.md") | ||
|
|
||
| def test_fetch_url_error(self): | ||
| """Test that network errors raise RuntimeError.""" | ||
| with patch( | ||
| f"{self._LOADER}.urllib.request.urlopen", | ||
| side_effect=urllib.error.URLError("Connection refused"), | ||
| ): | ||
| with pytest.raises(RuntimeError, match="failed to fetch"): | ||
| fetch_skill_content("https://example.com/SKILL.md") | ||
|
|
||
| def test_fetch_rejects_non_https(self): | ||
| """Test that non-https URLs are rejected.""" | ||
| with pytest.raises(ValueError, match="only https://"): | ||
| fetch_skill_content("http://example.com/SKILL.md") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.