skilly 0.0.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- skilly/__init__.py +7 -0
- skilly/cli/__init__.py +0 -0
- skilly/cli/root.py +22 -0
- skilly/cli/util.py +32 -0
- skilly/filesystem.py +35 -0
- skilly/parsers.py +54 -0
- skilly/skills.py +431 -0
- skilly/util.py +17 -0
- skilly-0.0.2.dist-info/METADATA +21 -0
- skilly-0.0.2.dist-info/RECORD +13 -0
- skilly-0.0.2.dist-info/WHEEL +4 -0
- skilly-0.0.2.dist-info/entry_points.txt +2 -0
- skilly-0.0.2.dist-info/licenses/LICENSE +21 -0
skilly/__init__.py
ADDED
skilly/cli/__init__.py
ADDED
|
File without changes
|
skilly/cli/root.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
|
|
3
|
+
from cyclopts import App
|
|
4
|
+
from skilly.cli.util import util_cli
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
cli = App()
|
|
8
|
+
|
|
9
|
+
cli.command(util_cli)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@cli.command()
|
|
13
|
+
def list() -> None:
|
|
14
|
+
from skilly.parsers import parse_toml
|
|
15
|
+
from skilly.parsers import PyProjectInfo
|
|
16
|
+
from skilly.skills import VenvSkills
|
|
17
|
+
|
|
18
|
+
toml = parse_toml(Path("pyproject.toml"))
|
|
19
|
+
info = PyProjectInfo.from_pyproject_toml(toml)
|
|
20
|
+
venv_skills = VenvSkills.from_dir(Path(".venv"))
|
|
21
|
+
for skill in venv_skills.filter_skills(info.dependencies):
|
|
22
|
+
print(f"{skill.skill.name}: {skill.skill.description}")
|
skilly/cli/util.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from typing import Sequence
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from cyclopts import App
|
|
4
|
+
|
|
5
|
+
util_cli = App("util")
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@util_cli.command()
|
|
9
|
+
def dependencies(
|
|
10
|
+
file: Path = Path("pyproject.toml"), dev: bool = False, extras: Sequence[str] = ()
|
|
11
|
+
) -> None:
|
|
12
|
+
# Todo: Sequence[str] might be wrong here for now
|
|
13
|
+
from skilly.parsers import parse_toml, PyProjectInfo
|
|
14
|
+
|
|
15
|
+
toml = parse_toml(file)
|
|
16
|
+
info = PyProjectInfo.from_pyproject_toml(
|
|
17
|
+
toml, include_dev=dev, include_extras=extras
|
|
18
|
+
)
|
|
19
|
+
for dep in info.dependencies:
|
|
20
|
+
print(dep.name)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@util_cli.command()
|
|
24
|
+
def venv(path: Path = Path(".venv")) -> None:
|
|
25
|
+
|
|
26
|
+
from skilly.skills import VenvSkills
|
|
27
|
+
|
|
28
|
+
skills = VenvSkills.from_dir(path)
|
|
29
|
+
for skill in skills.skills:
|
|
30
|
+
print(
|
|
31
|
+
f"{skill.skill.name}[{skill.package_name}=={skill.package_version}]: {skill.skill.description}"
|
|
32
|
+
)
|
skilly/filesystem.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from typing import Protocol, Sequence, Final
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class FileSystem(Protocol):
|
|
7
|
+
def read_file(self, path: Path) -> str:
|
|
8
|
+
"""Read a file and return its contents."""
|
|
9
|
+
|
|
10
|
+
def list_files(self, path: Path) -> Sequence[str]:
|
|
11
|
+
"""List child entry names in a directory."""
|
|
12
|
+
|
|
13
|
+
def is_dir(self, path: Path) -> bool:
|
|
14
|
+
"""Return whether the path is a directory."""
|
|
15
|
+
|
|
16
|
+
def resolve(self, path: Path) -> Path:
|
|
17
|
+
"""Return a normalized absolute path."""
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class DefaultFileSystem(FileSystem):
|
|
21
|
+
def read_file(self, path: Path) -> str:
|
|
22
|
+
with open(path, encoding="utf-8") as file_handle:
|
|
23
|
+
return file_handle.read()
|
|
24
|
+
|
|
25
|
+
def list_files(self, path: Path) -> Sequence[str]:
|
|
26
|
+
return os.listdir(path)
|
|
27
|
+
|
|
28
|
+
def is_dir(self, path: Path) -> bool:
|
|
29
|
+
return os.path.isdir(path)
|
|
30
|
+
|
|
31
|
+
def resolve(self, path: Path) -> Path:
|
|
32
|
+
return path.resolve()
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
DEFAULT_FILE_SYSTEM: Final[FileSystem] = DefaultFileSystem()
|
skilly/parsers.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import tomllib
|
|
2
|
+
from dataclasses import dataclass
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Any, Sequence
|
|
5
|
+
|
|
6
|
+
from packaging.requirements import Requirement
|
|
7
|
+
|
|
8
|
+
from .filesystem import DEFAULT_FILE_SYSTEM, FileSystem
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass(frozen=True)
|
|
12
|
+
class PyProjectInfo:
|
|
13
|
+
dependencies: list[Requirement]
|
|
14
|
+
|
|
15
|
+
@classmethod
|
|
16
|
+
def _get_extra_requirements(
|
|
17
|
+
cls,
|
|
18
|
+
toml: dict[str, Any],
|
|
19
|
+
extras: Sequence[str],
|
|
20
|
+
) -> list[Requirement]:
|
|
21
|
+
dependency_groups = toml.get("dependency-groups", {})
|
|
22
|
+
extra_requirements = []
|
|
23
|
+
for extra in dependency_groups.keys():
|
|
24
|
+
if extra in extras:
|
|
25
|
+
for dep in dependency_groups[extra]:
|
|
26
|
+
extra_requirements.append(Requirement(dep))
|
|
27
|
+
|
|
28
|
+
return extra_requirements
|
|
29
|
+
|
|
30
|
+
@classmethod
|
|
31
|
+
def from_pyproject_toml(
|
|
32
|
+
cls,
|
|
33
|
+
toml: dict[str, Any],
|
|
34
|
+
include_dev: bool = False,
|
|
35
|
+
include_extras: Sequence[str] = (),
|
|
36
|
+
) -> "PyProjectInfo":
|
|
37
|
+
dependencies = []
|
|
38
|
+
for dep in toml.get("project", {}).get("dependencies", []):
|
|
39
|
+
dependencies.append(Requirement(dep))
|
|
40
|
+
|
|
41
|
+
extras = set(include_extras)
|
|
42
|
+
if include_dev:
|
|
43
|
+
extras.add("dev")
|
|
44
|
+
|
|
45
|
+
dependencies.extend(cls._get_extra_requirements(toml, extras))
|
|
46
|
+
return cls(dependencies=dependencies)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def parse_toml(
|
|
50
|
+
path: Path,
|
|
51
|
+
file_system: FileSystem = DEFAULT_FILE_SYSTEM,
|
|
52
|
+
) -> dict[str, Any]:
|
|
53
|
+
data = file_system.read_file(path)
|
|
54
|
+
return tomllib.loads(data)
|
skilly/skills.py
ADDED
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
import csv
|
|
2
|
+
from dataclasses import dataclass, field
|
|
3
|
+
from email.parser import Parser
|
|
4
|
+
from pathlib import Path, PurePosixPath
|
|
5
|
+
from typing import Sequence
|
|
6
|
+
|
|
7
|
+
from packaging.requirements import Requirement
|
|
8
|
+
|
|
9
|
+
from .filesystem import DEFAULT_FILE_SYSTEM, FileSystem
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass(frozen=True)
|
|
13
|
+
class Skill:
|
|
14
|
+
name: str
|
|
15
|
+
description: str
|
|
16
|
+
path: Path
|
|
17
|
+
body: str = ""
|
|
18
|
+
license: str | None = None
|
|
19
|
+
compatibility: str | None = None
|
|
20
|
+
metadata: dict[str, str] = field(default_factory=dict)
|
|
21
|
+
allowed_tools: str | None = None
|
|
22
|
+
|
|
23
|
+
@classmethod
|
|
24
|
+
def from_text(
|
|
25
|
+
cls,
|
|
26
|
+
text: str,
|
|
27
|
+
*,
|
|
28
|
+
path: Path | None = None,
|
|
29
|
+
file_system: FileSystem = DEFAULT_FILE_SYSTEM,
|
|
30
|
+
) -> "Skill":
|
|
31
|
+
if path is None:
|
|
32
|
+
skill_path = Path("SKILL.md")
|
|
33
|
+
else:
|
|
34
|
+
skill_path = file_system.resolve(path)
|
|
35
|
+
|
|
36
|
+
frontmatter, body = _split_frontmatter(text)
|
|
37
|
+
raw_metadata = _parse_frontmatter(frontmatter)
|
|
38
|
+
|
|
39
|
+
raw_skill_metadata = raw_metadata.get("metadata")
|
|
40
|
+
if isinstance(raw_skill_metadata, dict):
|
|
41
|
+
skill_metadata = {
|
|
42
|
+
str(key): value
|
|
43
|
+
for key, value in raw_skill_metadata.items()
|
|
44
|
+
if isinstance(value, str)
|
|
45
|
+
}
|
|
46
|
+
else:
|
|
47
|
+
skill_metadata = {}
|
|
48
|
+
|
|
49
|
+
return cls(
|
|
50
|
+
name=raw_metadata.get("name")
|
|
51
|
+
if isinstance(raw_metadata.get("name"), str)
|
|
52
|
+
else "",
|
|
53
|
+
description=raw_metadata.get("description")
|
|
54
|
+
if isinstance(raw_metadata.get("description"), str)
|
|
55
|
+
else "",
|
|
56
|
+
path=skill_path,
|
|
57
|
+
body=body,
|
|
58
|
+
license=raw_metadata.get("license")
|
|
59
|
+
if isinstance(raw_metadata.get("license"), str)
|
|
60
|
+
else None,
|
|
61
|
+
compatibility=raw_metadata.get("compatibility")
|
|
62
|
+
if isinstance(raw_metadata.get("compatibility"), str)
|
|
63
|
+
else None,
|
|
64
|
+
metadata=skill_metadata,
|
|
65
|
+
allowed_tools=raw_metadata.get("allowed-tools")
|
|
66
|
+
if isinstance(raw_metadata.get("allowed-tools"), str)
|
|
67
|
+
else None,
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
@classmethod
|
|
71
|
+
def from_file(
|
|
72
|
+
cls,
|
|
73
|
+
path: Path,
|
|
74
|
+
*,
|
|
75
|
+
file_system: FileSystem = DEFAULT_FILE_SYSTEM,
|
|
76
|
+
) -> "Skill":
|
|
77
|
+
text = file_system.read_file(path)
|
|
78
|
+
return cls.from_text(text, path=path, file_system=file_system)
|
|
79
|
+
|
|
80
|
+
@classmethod
|
|
81
|
+
def from_dir(
|
|
82
|
+
cls,
|
|
83
|
+
path: Path,
|
|
84
|
+
*,
|
|
85
|
+
file_system: FileSystem = DEFAULT_FILE_SYSTEM,
|
|
86
|
+
) -> "Skill":
|
|
87
|
+
return cls.from_file(path / "SKILL.md", file_system=file_system)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
@dataclass(frozen=True)
|
|
91
|
+
class DiscoveredSkill:
|
|
92
|
+
package_name: str
|
|
93
|
+
skill: Skill
|
|
94
|
+
package_version: str = ""
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
@dataclass(frozen=True)
|
|
98
|
+
class VenvSkills:
|
|
99
|
+
skills: list[DiscoveredSkill]
|
|
100
|
+
path: Path
|
|
101
|
+
site_packages_dir: Path | None = None
|
|
102
|
+
warnings: list[str] = field(default_factory=list)
|
|
103
|
+
|
|
104
|
+
def filter_skills(self, packages: Sequence[Requirement]) -> list[DiscoveredSkill]:
|
|
105
|
+
package_names = [p.name for p in packages]
|
|
106
|
+
return [skill for skill in self.skills if skill.package_name in package_names]
|
|
107
|
+
|
|
108
|
+
@classmethod
|
|
109
|
+
def from_dir(
|
|
110
|
+
cls,
|
|
111
|
+
path: Path = Path(".venv"),
|
|
112
|
+
*,
|
|
113
|
+
file_system: FileSystem = DEFAULT_FILE_SYSTEM,
|
|
114
|
+
) -> "VenvSkills":
|
|
115
|
+
venv_path = file_system.resolve(path)
|
|
116
|
+
site_packages_dir = _get_site_packages_dir(venv_path, file_system=file_system)
|
|
117
|
+
warnings: list[str] = []
|
|
118
|
+
skills: list[DiscoveredSkill] = []
|
|
119
|
+
seen_skill_dirs: set[Path] = set()
|
|
120
|
+
|
|
121
|
+
if site_packages_dir is None or not file_system.is_dir(site_packages_dir):
|
|
122
|
+
warnings.append(f"Site-packages directory not found for virtualenv: {path}")
|
|
123
|
+
return cls(
|
|
124
|
+
skills=[],
|
|
125
|
+
path=venv_path,
|
|
126
|
+
site_packages_dir=site_packages_dir,
|
|
127
|
+
warnings=warnings,
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
for dist_info in _find_dist_info_dirs(
|
|
131
|
+
site_packages_dir, file_system=file_system
|
|
132
|
+
):
|
|
133
|
+
distribution = _read_distribution_info(dist_info, file_system=file_system)
|
|
134
|
+
if distribution is None:
|
|
135
|
+
warnings.append(f"Skipping invalid distribution metadata: {dist_info}")
|
|
136
|
+
continue
|
|
137
|
+
|
|
138
|
+
found = _scan_distribution_records(
|
|
139
|
+
site_packages_dir=site_packages_dir,
|
|
140
|
+
dist_info=dist_info,
|
|
141
|
+
package_name=distribution.name,
|
|
142
|
+
package_version=distribution.version,
|
|
143
|
+
seen_skill_dirs=seen_skill_dirs,
|
|
144
|
+
file_system=file_system,
|
|
145
|
+
)
|
|
146
|
+
skills.extend(found.skills)
|
|
147
|
+
warnings.extend(found.warnings)
|
|
148
|
+
|
|
149
|
+
skills.sort(
|
|
150
|
+
key=lambda item: (item.package_name, item.package_version, item.skill.name)
|
|
151
|
+
)
|
|
152
|
+
warnings.sort()
|
|
153
|
+
return cls(
|
|
154
|
+
skills=skills,
|
|
155
|
+
path=venv_path,
|
|
156
|
+
site_packages_dir=site_packages_dir,
|
|
157
|
+
warnings=warnings,
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
@dataclass(frozen=True)
|
|
162
|
+
class _DistributionInfo:
|
|
163
|
+
name: str
|
|
164
|
+
version: str
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
@dataclass(frozen=True)
|
|
168
|
+
class _ScanResult:
|
|
169
|
+
skills: list[DiscoveredSkill] = field(default_factory=list)
|
|
170
|
+
warnings: list[str] = field(default_factory=list)
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def _get_site_packages_dir(venv_path: Path, *, file_system: FileSystem) -> Path | None:
|
|
174
|
+
windows_site_packages = venv_path / "Lib" / "site-packages"
|
|
175
|
+
if file_system.is_dir(windows_site_packages):
|
|
176
|
+
return windows_site_packages
|
|
177
|
+
|
|
178
|
+
for lib_name in ("lib", "lib64"):
|
|
179
|
+
lib_dir = venv_path / lib_name
|
|
180
|
+
if not file_system.is_dir(lib_dir):
|
|
181
|
+
continue
|
|
182
|
+
for child in _child_paths(lib_dir, file_system=file_system, reverse=True):
|
|
183
|
+
site_packages = child / "site-packages"
|
|
184
|
+
if (
|
|
185
|
+
child.name.startswith("python")
|
|
186
|
+
and file_system.is_dir(child)
|
|
187
|
+
and file_system.is_dir(site_packages)
|
|
188
|
+
):
|
|
189
|
+
return site_packages
|
|
190
|
+
|
|
191
|
+
return None
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def _read_distribution_info(
|
|
195
|
+
dist_info: Path,
|
|
196
|
+
*,
|
|
197
|
+
file_system: FileSystem,
|
|
198
|
+
) -> _DistributionInfo | None:
|
|
199
|
+
metadata_path = dist_info / "METADATA"
|
|
200
|
+
try:
|
|
201
|
+
metadata_text = file_system.read_file(metadata_path)
|
|
202
|
+
except OSError:
|
|
203
|
+
return None
|
|
204
|
+
|
|
205
|
+
metadata = Parser().parsestr(metadata_text)
|
|
206
|
+
name = metadata.get("Name")
|
|
207
|
+
if not isinstance(name, str) or not name:
|
|
208
|
+
return None
|
|
209
|
+
|
|
210
|
+
version = metadata.get("Version", "")
|
|
211
|
+
return _DistributionInfo(
|
|
212
|
+
name=name, version=version if isinstance(version, str) else ""
|
|
213
|
+
)
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def _scan_distribution_records(
|
|
217
|
+
*,
|
|
218
|
+
site_packages_dir: Path,
|
|
219
|
+
dist_info: Path,
|
|
220
|
+
package_name: str,
|
|
221
|
+
package_version: str,
|
|
222
|
+
seen_skill_dirs: set[Path],
|
|
223
|
+
file_system: FileSystem,
|
|
224
|
+
) -> _ScanResult:
|
|
225
|
+
record_path = dist_info / "RECORD"
|
|
226
|
+
try:
|
|
227
|
+
record_text = file_system.read_file(record_path)
|
|
228
|
+
except OSError:
|
|
229
|
+
return _ScanResult()
|
|
230
|
+
|
|
231
|
+
skills: list[DiscoveredSkill] = []
|
|
232
|
+
warnings: list[str] = []
|
|
233
|
+
for row in csv.reader(record_text.splitlines()):
|
|
234
|
+
if not row:
|
|
235
|
+
continue
|
|
236
|
+
|
|
237
|
+
installed_path = row[0]
|
|
238
|
+
if not _is_skill_file_record(installed_path):
|
|
239
|
+
continue
|
|
240
|
+
|
|
241
|
+
skill_path = _resolve_record_path(
|
|
242
|
+
site_packages_dir,
|
|
243
|
+
installed_path,
|
|
244
|
+
file_system=file_system,
|
|
245
|
+
)
|
|
246
|
+
skill_dir = skill_path.parent
|
|
247
|
+
if skill_dir in seen_skill_dirs:
|
|
248
|
+
continue
|
|
249
|
+
seen_skill_dirs.add(skill_dir)
|
|
250
|
+
|
|
251
|
+
discovered_skill, warning = _load_discovered_skill(
|
|
252
|
+
skill_path=skill_path,
|
|
253
|
+
package_name=package_name,
|
|
254
|
+
package_version=package_version,
|
|
255
|
+
file_system=file_system,
|
|
256
|
+
)
|
|
257
|
+
if discovered_skill is not None:
|
|
258
|
+
skills.append(discovered_skill)
|
|
259
|
+
elif warning is not None:
|
|
260
|
+
warnings.append(warning)
|
|
261
|
+
|
|
262
|
+
return _ScanResult(skills=skills, warnings=warnings)
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
def _is_skill_file_record(installed_path: str) -> bool:
|
|
266
|
+
parts = PurePosixPath(installed_path).parts
|
|
267
|
+
for index, part in enumerate(parts):
|
|
268
|
+
if part != ".agents":
|
|
269
|
+
continue
|
|
270
|
+
if (
|
|
271
|
+
len(parts) > index + 3
|
|
272
|
+
and parts[index + 1] == "skills"
|
|
273
|
+
and parts[-1] == "SKILL.md"
|
|
274
|
+
):
|
|
275
|
+
return True
|
|
276
|
+
return False
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
def _load_discovered_skill(
|
|
280
|
+
*,
|
|
281
|
+
skill_path: Path,
|
|
282
|
+
package_name: str,
|
|
283
|
+
package_version: str,
|
|
284
|
+
file_system: FileSystem,
|
|
285
|
+
) -> tuple[DiscoveredSkill | None, str | None]:
|
|
286
|
+
try:
|
|
287
|
+
skill = Skill.from_file(skill_path, file_system=file_system)
|
|
288
|
+
except (OSError, UnicodeDecodeError) as exc:
|
|
289
|
+
return None, f"{skill_path}: could not read SKILL.md ({exc})"
|
|
290
|
+
except ValueError as exc:
|
|
291
|
+
return None, f"{skill_path}: {exc}"
|
|
292
|
+
|
|
293
|
+
return (
|
|
294
|
+
DiscoveredSkill(
|
|
295
|
+
package_name=package_name,
|
|
296
|
+
package_version=package_version,
|
|
297
|
+
skill=skill,
|
|
298
|
+
),
|
|
299
|
+
None,
|
|
300
|
+
)
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
def _split_frontmatter(text: str) -> tuple[list[str], str]:
|
|
304
|
+
lines = text.splitlines()
|
|
305
|
+
if not lines or lines[0].strip() != "---":
|
|
306
|
+
raise ValueError("missing YAML frontmatter")
|
|
307
|
+
|
|
308
|
+
for index, line in enumerate(lines[1:], start=1):
|
|
309
|
+
if line.strip() == "---":
|
|
310
|
+
return lines[1:index], "\n".join(lines[index + 1 :])
|
|
311
|
+
|
|
312
|
+
raise ValueError("unterminated YAML frontmatter")
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
def _parse_frontmatter(lines: list[str]) -> dict[str, object]:
|
|
316
|
+
metadata: dict[str, object] = {}
|
|
317
|
+
line_index = 0
|
|
318
|
+
while line_index < len(lines):
|
|
319
|
+
line = lines[line_index]
|
|
320
|
+
stripped = line.strip()
|
|
321
|
+
if not stripped or stripped.startswith("#"):
|
|
322
|
+
line_index += 1
|
|
323
|
+
continue
|
|
324
|
+
if line[:1].isspace():
|
|
325
|
+
raise ValueError("top-level frontmatter fields must not be indented")
|
|
326
|
+
|
|
327
|
+
key, separator, raw_value = line.partition(":")
|
|
328
|
+
if not separator:
|
|
329
|
+
raise ValueError(f"invalid frontmatter line: {line}")
|
|
330
|
+
|
|
331
|
+
key = key.strip()
|
|
332
|
+
value = raw_value.lstrip()
|
|
333
|
+
if key == "metadata" and not value:
|
|
334
|
+
parsed_metadata, line_index = _parse_metadata_block(
|
|
335
|
+
lines,
|
|
336
|
+
start_index=line_index + 1,
|
|
337
|
+
)
|
|
338
|
+
metadata[key] = parsed_metadata
|
|
339
|
+
continue
|
|
340
|
+
|
|
341
|
+
parsed_value = _parse_scalar(value)
|
|
342
|
+
if not isinstance(parsed_value, str):
|
|
343
|
+
raise ValueError(f"{key} must be a string")
|
|
344
|
+
metadata[key] = parsed_value
|
|
345
|
+
line_index += 1
|
|
346
|
+
|
|
347
|
+
return metadata
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
def _parse_metadata_block(
|
|
351
|
+
lines: list[str],
|
|
352
|
+
*,
|
|
353
|
+
start_index: int,
|
|
354
|
+
) -> tuple[dict[str, str], int]:
|
|
355
|
+
metadata: dict[str, str] = {}
|
|
356
|
+
line_index = start_index
|
|
357
|
+
|
|
358
|
+
while line_index < len(lines):
|
|
359
|
+
line = lines[line_index]
|
|
360
|
+
stripped = line.strip()
|
|
361
|
+
if not stripped or stripped.startswith("#"):
|
|
362
|
+
line_index += 1
|
|
363
|
+
continue
|
|
364
|
+
if not line.startswith((" ", "\t")):
|
|
365
|
+
break
|
|
366
|
+
if line.startswith("\t"):
|
|
367
|
+
raise ValueError("metadata entries must be indented with spaces")
|
|
368
|
+
|
|
369
|
+
indentation = len(line) - len(line.lstrip(" "))
|
|
370
|
+
if indentation < 2:
|
|
371
|
+
raise ValueError("metadata entries must be indented by at least two spaces")
|
|
372
|
+
|
|
373
|
+
key, separator, raw_value = line[indentation:].partition(":")
|
|
374
|
+
if not separator:
|
|
375
|
+
raise ValueError(f"invalid metadata line: {line.strip()}")
|
|
376
|
+
|
|
377
|
+
parsed_value = _parse_scalar(raw_value.lstrip())
|
|
378
|
+
if not isinstance(parsed_value, str):
|
|
379
|
+
raise ValueError("metadata values must be strings")
|
|
380
|
+
metadata[key.strip()] = parsed_value
|
|
381
|
+
line_index += 1
|
|
382
|
+
|
|
383
|
+
return metadata, line_index
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
def _parse_scalar(value: str) -> str | None:
|
|
387
|
+
value = value.strip()
|
|
388
|
+
if value == "null":
|
|
389
|
+
return None
|
|
390
|
+
if value.startswith("'") and value.endswith("'") and len(value) >= 2:
|
|
391
|
+
return value[1:-1].replace("''", "'")
|
|
392
|
+
if value.startswith('"') and value.endswith('"') and len(value) >= 2:
|
|
393
|
+
return bytes(value[1:-1], "utf-8").decode("unicode_escape")
|
|
394
|
+
return value
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
def _find_dist_info_dirs(
|
|
398
|
+
site_packages_dir: Path,
|
|
399
|
+
*,
|
|
400
|
+
file_system: FileSystem,
|
|
401
|
+
) -> list[Path]:
|
|
402
|
+
return [
|
|
403
|
+
child
|
|
404
|
+
for child in _child_paths(site_packages_dir, file_system=file_system)
|
|
405
|
+
if child.name.endswith(".dist-info") and file_system.is_dir(child)
|
|
406
|
+
]
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
def _child_paths(
|
|
410
|
+
path: Path,
|
|
411
|
+
*,
|
|
412
|
+
file_system: FileSystem,
|
|
413
|
+
reverse: bool = False,
|
|
414
|
+
) -> list[Path]:
|
|
415
|
+
try:
|
|
416
|
+
names = sorted(file_system.list_files(path), reverse=reverse)
|
|
417
|
+
except OSError:
|
|
418
|
+
return []
|
|
419
|
+
return [path / name for name in names]
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
def _resolve_record_path(
|
|
423
|
+
site_packages_dir: Path,
|
|
424
|
+
installed_path: str,
|
|
425
|
+
*,
|
|
426
|
+
file_system: FileSystem,
|
|
427
|
+
) -> Path:
|
|
428
|
+
path = site_packages_dir
|
|
429
|
+
for part in PurePosixPath(installed_path).parts:
|
|
430
|
+
path /= part
|
|
431
|
+
return file_system.resolve(path)
|
skilly/util.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
from typing import List
|
|
3
|
+
|
|
4
|
+
from skilly.filesystem import FileSystem, DEFAULT_FILE_SYSTEM
|
|
5
|
+
from skilly.parsers import parse_toml, PyProjectInfo
|
|
6
|
+
from skilly.skills import Skill, VenvSkills
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def get_project_skills(
|
|
10
|
+
pyproject_toml_path: Path = Path("pyproject.toml"),
|
|
11
|
+
venv_path: Path = Path(".venv"),
|
|
12
|
+
file_system: FileSystem = DEFAULT_FILE_SYSTEM,
|
|
13
|
+
) -> List[Skill]:
|
|
14
|
+
toml = parse_toml(pyproject_toml_path, file_system=file_system)
|
|
15
|
+
info = PyProjectInfo.from_pyproject_toml(toml)
|
|
16
|
+
venv_skills = VenvSkills.from_dir(venv_path, file_system=file_system)
|
|
17
|
+
return [s.skill for s in venv_skills.filter_skills(info.dependencies)]
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: skilly
|
|
3
|
+
Version: 0.0.2
|
|
4
|
+
Summary: Load skills from dependencies.
|
|
5
|
+
License-File: LICENSE
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
Requires-Dist: cyclopts>=4
|
|
8
|
+
Requires-Dist: niquests>=3
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
|
|
11
|
+
# skilly
|
|
12
|
+
|
|
13
|
+
Read agent skills from dependencies.
|
|
14
|
+
|
|
15
|
+
# Development Status
|
|
16
|
+
|
|
17
|
+
Alpha
|
|
18
|
+
|
|
19
|
+
# License
|
|
20
|
+
|
|
21
|
+
[MIT](LICENSE)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
skilly/__init__.py,sha256=fiamy7aTVhTj3BE4S6wp7xZ-eQ-fGN8zvrytSBOHY2Q,129
|
|
2
|
+
skilly/filesystem.py,sha256=yKlF26UFs_NzAhfghahvYGG5srTXO1D84IhXM36cp1U,986
|
|
3
|
+
skilly/parsers.py,sha256=FbG47j96r6xEn4VVRnh4zwhGypL7lyB6pVdXVDvKHJA,1498
|
|
4
|
+
skilly/skills.py,sha256=YMmMv7K_yQKsH_2XyDJ9S06sSFiRAmuGVvNFv-bAmtQ,12895
|
|
5
|
+
skilly/util.py,sha256=XckNuSlbM2iFPn9gcLqQzG1BE_qMVtSlY71kcnszxD0,665
|
|
6
|
+
skilly/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
+
skilly/cli/root.py,sha256=3QEkcJr_pkTc_up50ymAnWukXxk0q0GQuIiU5K7JSqw,568
|
|
8
|
+
skilly/cli/util.py,sha256=3J3Nxi_MnNSGM0c3GVsOOaxmvKN3RjUgCJNRVoVyTQ8,858
|
|
9
|
+
skilly-0.0.2.dist-info/METADATA,sha256=0gBYX7dS2wFbeUnGav5VlMSln2h2kJ5mpU5L70aIn9w,334
|
|
10
|
+
skilly-0.0.2.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
|
|
11
|
+
skilly-0.0.2.dist-info/entry_points.txt,sha256=u0AaCWJ7HB8ZtEP_1e6bXC-Yui210-eO4xxfeWgSbXE,47
|
|
12
|
+
skilly-0.0.2.dist-info/licenses/LICENSE,sha256=nEknAHlknpylAXhQcGx8e20-VchzUfUNs0PJz4o5R6w,1061
|
|
13
|
+
skilly-0.0.2.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Alex
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|