abom 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.
- abom/__init__.py +2 -0
- abom/check.py +336 -0
- abom/cli.py +365 -0
- abom/recipe.py +236 -0
- abom/recipes.json +88 -0
- abom-0.0.2.dist-info/METADATA +141 -0
- abom-0.0.2.dist-info/RECORD +11 -0
- abom-0.0.2.dist-info/WHEEL +5 -0
- abom-0.0.2.dist-info/entry_points.txt +2 -0
- abom-0.0.2.dist-info/licenses/LICENSE +21 -0
- abom-0.0.2.dist-info/top_level.txt +1 -0
abom/__init__.py
ADDED
abom/check.py
ADDED
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
import re
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
from abom.recipe import Recipe, RecipeError, license_terms
|
|
10
|
+
|
|
11
|
+
# Commands that turn a clone or npm lifecycle script into a remote shell.
|
|
12
|
+
_REMOTE_SHELL = re.compile(
|
|
13
|
+
r"(?:curl|wget)\b[^\n|]*\|\s*(?:ba)?sh\b"
|
|
14
|
+
r"|base64\s+(?:-d|--decode)\b[^\n|]*\|\s*(?:ba)?sh\b"
|
|
15
|
+
r"|\b(?:bash|sh)\s+-c\b"
|
|
16
|
+
r"|/dev/tcp/",
|
|
17
|
+
re.IGNORECASE,
|
|
18
|
+
)
|
|
19
|
+
_LIFECYCLE_SCRIPTS = ("preinstall", "install", "postinstall", "prepare", "preprepare", "prepublish")
|
|
20
|
+
_PROMPT_SUFFIXES = {".md", ".markdown", ".txt", ".prompt"}
|
|
21
|
+
_TEXT_SCAN_BYTES = 256_000
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@dataclass(frozen=True)
|
|
25
|
+
class CheckReport:
|
|
26
|
+
ok: bool
|
|
27
|
+
findings: tuple[str, ...]
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def inspect_material(recipe: Recipe, checkout: Path) -> CheckReport:
|
|
31
|
+
material = checkout if recipe.path is None else checkout / recipe.path
|
|
32
|
+
findings: list[str] = []
|
|
33
|
+
if not material.exists() and not material.is_symlink():
|
|
34
|
+
findings.append(f"{recipe.kind} path '{recipe.path or '.'}' is missing")
|
|
35
|
+
return CheckReport(False, tuple(findings))
|
|
36
|
+
|
|
37
|
+
findings.extend(_symlink_findings(checkout, material))
|
|
38
|
+
findings.extend(_kind_findings(recipe.kind, material))
|
|
39
|
+
findings.extend(_license_findings(recipe.license, checkout, material))
|
|
40
|
+
return CheckReport(not findings, tuple(findings))
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def inspect_checkout(checkout: Path) -> CheckReport:
|
|
44
|
+
"""Scan an ad-hoc clone that has no recipe kind."""
|
|
45
|
+
findings = _symlink_findings(checkout, checkout)
|
|
46
|
+
return CheckReport(not findings, tuple(findings))
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def format_report(report: CheckReport) -> str:
|
|
50
|
+
if report.ok:
|
|
51
|
+
return "check: pass"
|
|
52
|
+
lines = ["check: fail", *(f"- {finding}" for finding in report.findings)]
|
|
53
|
+
return "\n".join(lines)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _kind_findings(kind: str, material: Path) -> list[str]:
|
|
57
|
+
if kind == "skill":
|
|
58
|
+
return _skill_findings(material)
|
|
59
|
+
if kind == "prompt":
|
|
60
|
+
return _prompt_findings(material)
|
|
61
|
+
if kind == "package":
|
|
62
|
+
return _package_findings(material)
|
|
63
|
+
if kind == "mcp":
|
|
64
|
+
return _mcp_findings(material)
|
|
65
|
+
return [f"unknown kind '{kind}'"]
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _skill_findings(material: Path) -> list[str]:
|
|
69
|
+
if not material.is_dir():
|
|
70
|
+
return ["skill must be a directory containing SKILL.md"]
|
|
71
|
+
skill_file = material / "SKILL.md"
|
|
72
|
+
if not skill_file.is_file():
|
|
73
|
+
return ["skill is missing SKILL.md"]
|
|
74
|
+
text = _read_text(skill_file)
|
|
75
|
+
if text is None:
|
|
76
|
+
return ["SKILL.md is not a text file"]
|
|
77
|
+
frontmatter = _frontmatter(text)
|
|
78
|
+
findings: list[str] = []
|
|
79
|
+
if not frontmatter.get("name") or not frontmatter.get("description"):
|
|
80
|
+
findings.append("SKILL.md frontmatter must include name and description")
|
|
81
|
+
if _REMOTE_SHELL.search(text):
|
|
82
|
+
findings.append("SKILL.md contains a remote shell command")
|
|
83
|
+
return findings
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def _prompt_findings(material: Path) -> list[str]:
|
|
87
|
+
files = _prompt_files(material)
|
|
88
|
+
if not files:
|
|
89
|
+
return ["prompt must be a text file or a directory of prompt files"]
|
|
90
|
+
findings: list[str] = []
|
|
91
|
+
for path in files:
|
|
92
|
+
text = _read_text(path)
|
|
93
|
+
if text is None:
|
|
94
|
+
findings.append(f"prompt file is not text: {path.name}")
|
|
95
|
+
continue
|
|
96
|
+
if not text.strip():
|
|
97
|
+
findings.append(f"prompt file is empty: {path.name}")
|
|
98
|
+
elif _REMOTE_SHELL.search(text):
|
|
99
|
+
findings.append(f"prompt file contains a remote shell command: {path.name}")
|
|
100
|
+
return findings
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def _package_findings(material: Path) -> list[str]:
|
|
104
|
+
if not material.is_dir():
|
|
105
|
+
return ["package must be a directory containing package.json or pyproject.toml"]
|
|
106
|
+
if (material / "package.json").is_file():
|
|
107
|
+
return _package_json_findings(material / "package.json", required=True)
|
|
108
|
+
if (material / "pyproject.toml").is_file():
|
|
109
|
+
return _pyproject_findings(material / "pyproject.toml")
|
|
110
|
+
return ["package must contain package.json or pyproject.toml"]
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def _pyproject_findings(path: Path) -> list[str]:
|
|
114
|
+
text = _read_text(path)
|
|
115
|
+
if text is None:
|
|
116
|
+
return ["pyproject.toml is not a text file"]
|
|
117
|
+
findings: list[str] = []
|
|
118
|
+
if not re.search(r'(?m)^name\s*=\s*["\'][^"\']+["\']', text):
|
|
119
|
+
findings.append("pyproject.toml is missing project name")
|
|
120
|
+
if not re.search(r"(?m)^license\s*=", text):
|
|
121
|
+
findings.append("pyproject.toml is missing license")
|
|
122
|
+
return findings
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def _mcp_findings(material: Path) -> list[str]:
|
|
126
|
+
if not material.is_dir():
|
|
127
|
+
return ["mcp must be a directory"]
|
|
128
|
+
markers = ("package.json", "pyproject.toml", "index.ts", "index.js", "server.py", "main.py")
|
|
129
|
+
if not any((material / name).is_file() for name in markers):
|
|
130
|
+
return ["mcp directory has no server manifest or entry file"]
|
|
131
|
+
package_json = material / "package.json"
|
|
132
|
+
if package_json.is_file():
|
|
133
|
+
return _package_json_findings(package_json, required=False)
|
|
134
|
+
return []
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def _package_json_findings(path: Path, *, required: bool) -> list[str]:
|
|
138
|
+
if not path.is_file():
|
|
139
|
+
return ["package.json is missing"] if required else []
|
|
140
|
+
try:
|
|
141
|
+
data = json.loads(path.read_text(encoding="utf-8"))
|
|
142
|
+
except (OSError, UnicodeError, json.JSONDecodeError):
|
|
143
|
+
return ["package.json is not valid JSON text"]
|
|
144
|
+
if not isinstance(data, dict):
|
|
145
|
+
return ["package.json must be an object"]
|
|
146
|
+
findings: list[str] = []
|
|
147
|
+
if required and (not isinstance(data.get("name"), str) or not str(data.get("name")).strip()):
|
|
148
|
+
findings.append("package.json is missing name")
|
|
149
|
+
scripts = data.get("scripts", {})
|
|
150
|
+
if scripts is None:
|
|
151
|
+
scripts = {}
|
|
152
|
+
if not isinstance(scripts, dict):
|
|
153
|
+
return [*findings, "package.json scripts must be an object"]
|
|
154
|
+
for key in _LIFECYCLE_SCRIPTS:
|
|
155
|
+
command = scripts.get(key)
|
|
156
|
+
if not isinstance(command, str) or not command.strip():
|
|
157
|
+
continue
|
|
158
|
+
if _REMOTE_SHELL.search(command):
|
|
159
|
+
findings.append(f"package.json {key} script looks like a remote shell: {command}")
|
|
160
|
+
return findings
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def _prompt_files(material: Path) -> list[Path]:
|
|
164
|
+
if material.is_file():
|
|
165
|
+
return [material] if _is_prompt_file(material) else []
|
|
166
|
+
if not material.is_dir():
|
|
167
|
+
return []
|
|
168
|
+
found: list[Path] = []
|
|
169
|
+
for dirpath, dirnames, filenames in os.walk(material, followlinks=False):
|
|
170
|
+
dirnames[:] = [
|
|
171
|
+
name
|
|
172
|
+
for name in dirnames
|
|
173
|
+
if name not in _SKIP_DIRS and not (Path(dirpath) / name).is_symlink()
|
|
174
|
+
]
|
|
175
|
+
for name in filenames:
|
|
176
|
+
path = Path(dirpath) / name
|
|
177
|
+
if path.is_symlink():
|
|
178
|
+
continue
|
|
179
|
+
if _is_prompt_file(path):
|
|
180
|
+
found.append(path)
|
|
181
|
+
return found
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def _is_prompt_file(path: Path) -> bool:
|
|
185
|
+
return path.suffix.lower() in _PROMPT_SUFFIXES or path.name.lower() in {"prompt", "prompts.md"}
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def _frontmatter(text: str) -> dict[str, str]:
|
|
189
|
+
if not text.startswith("---"):
|
|
190
|
+
return {}
|
|
191
|
+
end = text.find("\n---", 3)
|
|
192
|
+
if end == -1:
|
|
193
|
+
return {}
|
|
194
|
+
data: dict[str, str] = {}
|
|
195
|
+
for line in text[3:end].splitlines():
|
|
196
|
+
if not line.strip() or line.lstrip().startswith("#") or ":" not in line:
|
|
197
|
+
continue
|
|
198
|
+
key, _, value = line.partition(":")
|
|
199
|
+
data[key.strip()] = value.strip().strip("\"'")
|
|
200
|
+
return data
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def _read_text(path: Path) -> str | None:
|
|
204
|
+
try:
|
|
205
|
+
blob = path.read_bytes()[:_TEXT_SCAN_BYTES]
|
|
206
|
+
except OSError:
|
|
207
|
+
return None
|
|
208
|
+
if b"\x00" in blob:
|
|
209
|
+
return None
|
|
210
|
+
return blob.decode("utf-8", errors="replace")
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
_LICENSE_NAME = re.compile(r"^(?:LICENSE|LICENCE|COPYING)(?:[.-].*)?$", re.IGNORECASE)
|
|
214
|
+
_SKIP_DIRS = {".git", ".venv", "venv", "__pycache__", ".pytest_cache", ".mypy_cache", ".ruff_cache"}
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def _license_findings(declared: str, checkout: Path, material: Path) -> list[str]:
|
|
218
|
+
try:
|
|
219
|
+
operator, required = license_terms(declared)
|
|
220
|
+
except RecipeError as exc:
|
|
221
|
+
return [str(exc)]
|
|
222
|
+
files = _license_files(checkout, material)
|
|
223
|
+
if not files:
|
|
224
|
+
return ["checkout has no license file for the declared license"]
|
|
225
|
+
detected: set[str] = set()
|
|
226
|
+
for path in files:
|
|
227
|
+
text = _read_text(path)
|
|
228
|
+
if text:
|
|
229
|
+
detected.update(_detect_licenses(text))
|
|
230
|
+
if not detected:
|
|
231
|
+
names = ", ".join(path.name for path in files)
|
|
232
|
+
return [f"could not recognize a license in {names}"]
|
|
233
|
+
satisfied = (
|
|
234
|
+
all(item in detected for item in required)
|
|
235
|
+
if operator == "AND"
|
|
236
|
+
else any(item in detected for item in required)
|
|
237
|
+
)
|
|
238
|
+
if satisfied:
|
|
239
|
+
return []
|
|
240
|
+
found = ", ".join(sorted(detected))
|
|
241
|
+
return [f"declared license {declared} does not match checkout license {found}"]
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
def _license_files(checkout: Path, material: Path) -> list[Path]:
|
|
245
|
+
directories = _license_directories(checkout, material)
|
|
246
|
+
files: list[Path] = []
|
|
247
|
+
seen: set[Path] = set()
|
|
248
|
+
for directory in directories:
|
|
249
|
+
if not directory.is_dir():
|
|
250
|
+
continue
|
|
251
|
+
for child in directory.iterdir():
|
|
252
|
+
if child.is_file() and not child.is_symlink() and _LICENSE_NAME.match(child.name):
|
|
253
|
+
resolved = child.resolve(strict=False)
|
|
254
|
+
if resolved not in seen:
|
|
255
|
+
seen.add(resolved)
|
|
256
|
+
files.append(child)
|
|
257
|
+
if material.is_dir() and not material.is_symlink():
|
|
258
|
+
for dirpath, dirnames, filenames in os.walk(material, followlinks=False):
|
|
259
|
+
dirnames[:] = [
|
|
260
|
+
name
|
|
261
|
+
for name in dirnames
|
|
262
|
+
if name not in _SKIP_DIRS and not (Path(dirpath) / name).is_symlink()
|
|
263
|
+
]
|
|
264
|
+
for name in filenames:
|
|
265
|
+
path = Path(dirpath) / name
|
|
266
|
+
if path.is_symlink() or not _LICENSE_NAME.match(name):
|
|
267
|
+
continue
|
|
268
|
+
resolved = path.resolve(strict=False)
|
|
269
|
+
if resolved not in seen:
|
|
270
|
+
seen.add(resolved)
|
|
271
|
+
files.append(path)
|
|
272
|
+
return files
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
def _license_directories(checkout: Path, material: Path) -> list[Path]:
|
|
276
|
+
root = checkout.resolve(strict=False)
|
|
277
|
+
start = material.resolve(strict=False)
|
|
278
|
+
if not start.is_dir():
|
|
279
|
+
start = start.parent
|
|
280
|
+
directories: list[Path] = []
|
|
281
|
+
current = start
|
|
282
|
+
while True:
|
|
283
|
+
directories.append(current)
|
|
284
|
+
if current == root:
|
|
285
|
+
break
|
|
286
|
+
if root not in current.parents:
|
|
287
|
+
break
|
|
288
|
+
parent = current.parent
|
|
289
|
+
if parent == current:
|
|
290
|
+
break
|
|
291
|
+
current = parent
|
|
292
|
+
return directories
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
def _detect_licenses(text: str) -> set[str]:
|
|
296
|
+
lowered = text.lower()
|
|
297
|
+
detected: set[str] = set()
|
|
298
|
+
if "cc0 1.0" in lowered or "cc0-1.0" in lowered or "creative commons zero" in lowered:
|
|
299
|
+
detected.add("CC0-1.0")
|
|
300
|
+
if "apache license" in lowered and "version 2.0" in lowered:
|
|
301
|
+
detected.add("Apache-2.0")
|
|
302
|
+
if "mit license" in lowered or "permission is hereby granted, free of charge" in lowered:
|
|
303
|
+
detected.add("MIT")
|
|
304
|
+
if "mozilla public license, version 2.0" in lowered:
|
|
305
|
+
detected.add("MPL-2.0")
|
|
306
|
+
return detected
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
def _symlink_findings(checkout: Path, material: Path) -> list[str]:
|
|
310
|
+
root = checkout.resolve(strict=False)
|
|
311
|
+
findings: list[str] = []
|
|
312
|
+
for path in _symlink_candidates(material):
|
|
313
|
+
if not path.is_symlink():
|
|
314
|
+
continue
|
|
315
|
+
target = path.resolve(strict=False)
|
|
316
|
+
if not _is_inside(root, target):
|
|
317
|
+
findings.append(f"symlink escapes checkout: {path.name} -> {os.readlink(path)}")
|
|
318
|
+
return findings
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
def _symlink_candidates(material: Path) -> list[Path]:
|
|
322
|
+
candidates = [material]
|
|
323
|
+
if material.is_dir() and not material.is_symlink():
|
|
324
|
+
for dirpath, dirnames, filenames in os.walk(material, followlinks=False):
|
|
325
|
+
dirnames[:] = [name for name in dirnames if name not in _SKIP_DIRS]
|
|
326
|
+
for name in [*dirnames, *filenames]:
|
|
327
|
+
candidates.append(Path(dirpath) / name)
|
|
328
|
+
return candidates
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
def _is_inside(root: Path, candidate: Path) -> bool:
|
|
332
|
+
try:
|
|
333
|
+
candidate.relative_to(root)
|
|
334
|
+
except ValueError:
|
|
335
|
+
return False
|
|
336
|
+
return True
|
abom/cli.py
ADDED
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import json
|
|
5
|
+
import os
|
|
6
|
+
import shutil
|
|
7
|
+
import subprocess
|
|
8
|
+
import sys
|
|
9
|
+
import tempfile
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
from abom.check import format_report, inspect_checkout, inspect_material
|
|
13
|
+
from abom.recipe import (
|
|
14
|
+
Recipe,
|
|
15
|
+
RecipeError,
|
|
16
|
+
format_recipe,
|
|
17
|
+
format_recipe_line,
|
|
18
|
+
iter_recipes,
|
|
19
|
+
load_recipe,
|
|
20
|
+
validate_git_url,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class AbomError(Exception):
|
|
25
|
+
pass
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def abom_home() -> Path:
|
|
29
|
+
root = os.environ.get("ABOM_HOME")
|
|
30
|
+
return (Path(root).expanduser() if root else Path.home() / ".abom").resolve(strict=False)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def tools_dir() -> Path:
|
|
34
|
+
path = abom_home() / "tools"
|
|
35
|
+
path.mkdir(parents=True, exist_ok=True)
|
|
36
|
+
return path
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def receipts_dir() -> Path:
|
|
40
|
+
path = abom_home() / "receipts"
|
|
41
|
+
path.mkdir(parents=True, exist_ok=True)
|
|
42
|
+
return path
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def receipt_path(name: str) -> Path:
|
|
46
|
+
return abom_home() / "receipts" / f"{name}.json"
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def run_git(args: list[str], cwd: Path | None = None) -> None:
|
|
50
|
+
try:
|
|
51
|
+
subprocess.run(
|
|
52
|
+
["git", *_git_safety_args(), *args],
|
|
53
|
+
cwd=cwd,
|
|
54
|
+
check=True,
|
|
55
|
+
stdout=subprocess.PIPE,
|
|
56
|
+
stderr=subprocess.PIPE,
|
|
57
|
+
)
|
|
58
|
+
except subprocess.CalledProcessError as exc:
|
|
59
|
+
stderr = exc.stderr.decode("utf-8", errors="replace").strip()
|
|
60
|
+
raise AbomError(stderr or f"git {' '.join(args)} failed") from exc
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def git_stdout(args: list[str], cwd: Path | None = None) -> str:
|
|
64
|
+
try:
|
|
65
|
+
completed = subprocess.run(
|
|
66
|
+
["git", *_git_safety_args(), *args],
|
|
67
|
+
cwd=cwd,
|
|
68
|
+
check=True,
|
|
69
|
+
stdout=subprocess.PIPE,
|
|
70
|
+
stderr=subprocess.PIPE,
|
|
71
|
+
)
|
|
72
|
+
except subprocess.CalledProcessError as exc:
|
|
73
|
+
stderr = exc.stderr.decode("utf-8", errors="replace").strip()
|
|
74
|
+
raise AbomError(stderr or f"git {' '.join(args)} failed") from exc
|
|
75
|
+
return completed.stdout.decode("utf-8", errors="replace").strip()
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _git_safety_args() -> list[str]:
|
|
79
|
+
hooks = abom_home() / "disabled-hooks"
|
|
80
|
+
hooks.mkdir(parents=True, exist_ok=True)
|
|
81
|
+
return [
|
|
82
|
+
"-c",
|
|
83
|
+
f"core.hooksPath={hooks}",
|
|
84
|
+
"-c",
|
|
85
|
+
"core.fsmonitor=",
|
|
86
|
+
"-c",
|
|
87
|
+
"protocol.ext.allow=never",
|
|
88
|
+
"-c",
|
|
89
|
+
"protocol.fd.allow=never",
|
|
90
|
+
]
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def cmd_install(name: str, git_url: str) -> str:
|
|
94
|
+
try:
|
|
95
|
+
validate_git_url(git_url)
|
|
96
|
+
except RecipeError as exc:
|
|
97
|
+
raise AbomError(str(exc)) from exc
|
|
98
|
+
destination = tools_dir() / name
|
|
99
|
+
if destination.exists() or destination.is_symlink():
|
|
100
|
+
raise AbomError(f"tool '{name}' already installed")
|
|
101
|
+
try:
|
|
102
|
+
run_git(["clone", "--depth", "1", git_url, str(destination)])
|
|
103
|
+
report = inspect_checkout(destination)
|
|
104
|
+
if not report.ok:
|
|
105
|
+
raise AbomError(format_report(report))
|
|
106
|
+
except Exception:
|
|
107
|
+
_discard_checkout(destination)
|
|
108
|
+
raise
|
|
109
|
+
return f"installed {name} -> {destination}"
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def cmd_install_recipe(name: str) -> str:
|
|
113
|
+
recipe = _load_recipe(name)
|
|
114
|
+
destination = tools_dir() / recipe.name
|
|
115
|
+
if destination.exists() or destination.is_symlink():
|
|
116
|
+
raise AbomError(f"tool '{recipe.name}' already installed")
|
|
117
|
+
|
|
118
|
+
try:
|
|
119
|
+
_clone_recipe(recipe, destination)
|
|
120
|
+
report = inspect_material(recipe, destination)
|
|
121
|
+
if not report.ok:
|
|
122
|
+
raise AbomError(format_report(report))
|
|
123
|
+
commit = git_stdout(["rev-parse", "HEAD"], cwd=destination)
|
|
124
|
+
_write_receipt(recipe, commit)
|
|
125
|
+
except Exception:
|
|
126
|
+
_discard_checkout(destination)
|
|
127
|
+
raise
|
|
128
|
+
return f"installed {recipe.name} -> {destination}"
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def cmd_recipes(query: str | None) -> list[str]:
|
|
132
|
+
try:
|
|
133
|
+
recipes = iter_recipes(query)
|
|
134
|
+
except RecipeError as exc:
|
|
135
|
+
raise AbomError(str(exc)) from exc
|
|
136
|
+
return [format_recipe_line(recipe) for recipe in recipes]
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def cmd_info(name: str) -> str:
|
|
140
|
+
try:
|
|
141
|
+
recipe = load_recipe(name)
|
|
142
|
+
except RecipeError as exc:
|
|
143
|
+
raise AbomError(str(exc)) from exc
|
|
144
|
+
return format_recipe(recipe)
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def cmd_show(name: str) -> str:
|
|
148
|
+
recipe = _load_recipe(name)
|
|
149
|
+
lines = [format_recipe(recipe), ""]
|
|
150
|
+
checkout = tools_dir() / recipe.name
|
|
151
|
+
if not checkout.exists() and not checkout.is_symlink():
|
|
152
|
+
lines.append("installed: no")
|
|
153
|
+
lines.append("check: not run")
|
|
154
|
+
return "\n".join(lines)
|
|
155
|
+
lines.append("installed: yes")
|
|
156
|
+
receipt = _read_receipt(recipe.name)
|
|
157
|
+
if receipt and receipt.get("commit"):
|
|
158
|
+
lines.append(f"commit: {receipt['commit']}")
|
|
159
|
+
lines.append(format_report(inspect_material(recipe, checkout)))
|
|
160
|
+
return "\n".join(lines)
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def cmd_check(name: str) -> str:
|
|
164
|
+
recipe = _load_recipe(name)
|
|
165
|
+
checkout = tools_dir() / recipe.name
|
|
166
|
+
if checkout.exists() or checkout.is_symlink():
|
|
167
|
+
report = inspect_material(recipe, checkout)
|
|
168
|
+
else:
|
|
169
|
+
with tempfile.TemporaryDirectory(prefix="abom-check-") as temporary:
|
|
170
|
+
destination = Path(temporary) / recipe.name
|
|
171
|
+
_clone_recipe(recipe, destination)
|
|
172
|
+
report = inspect_material(recipe, destination)
|
|
173
|
+
text = format_report(report)
|
|
174
|
+
if not report.ok:
|
|
175
|
+
raise AbomError(text)
|
|
176
|
+
return text
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def cmd_search(query: str | None) -> list[str]:
|
|
180
|
+
installed = sorted(p.name for p in tools_dir().iterdir() if p.is_dir() or p.is_symlink())
|
|
181
|
+
if query:
|
|
182
|
+
installed = [name for name in installed if query.lower() in name.lower()]
|
|
183
|
+
return installed
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def cmd_remove(name: str) -> str:
|
|
187
|
+
destination = tools_dir() / name
|
|
188
|
+
if not destination.exists() and not destination.is_symlink():
|
|
189
|
+
raise AbomError(f"tool '{name}' is not installed")
|
|
190
|
+
if destination.is_symlink() or not destination.is_dir():
|
|
191
|
+
destination.unlink()
|
|
192
|
+
else:
|
|
193
|
+
shutil.rmtree(destination)
|
|
194
|
+
receipt = receipt_path(name)
|
|
195
|
+
if receipt.exists():
|
|
196
|
+
receipt.unlink()
|
|
197
|
+
return f"removed {name}"
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def cmd_link(name: str, target_repo: str, link_name: str | None) -> str:
|
|
201
|
+
source_entry = tools_dir() / name
|
|
202
|
+
if not source_entry.exists() and not source_entry.is_symlink():
|
|
203
|
+
raise AbomError(f"tool '{name}' is not installed")
|
|
204
|
+
source_entry = _material_root(name, source_entry)
|
|
205
|
+
|
|
206
|
+
target_root = Path(target_repo).expanduser()
|
|
207
|
+
if not target_root.exists():
|
|
208
|
+
raise AbomError(f"target repository '{target_root}' does not exist")
|
|
209
|
+
if not target_root.is_dir():
|
|
210
|
+
raise AbomError(f"target repository '{target_root}' is not a directory")
|
|
211
|
+
target_root = target_root.resolve(strict=False)
|
|
212
|
+
links_dir = target_root / ".abom"
|
|
213
|
+
links_dir.mkdir(exist_ok=True)
|
|
214
|
+
|
|
215
|
+
final_name = link_name or name
|
|
216
|
+
destination = links_dir / final_name
|
|
217
|
+
if destination.exists() or destination.is_symlink():
|
|
218
|
+
raise AbomError(f"link '{destination}' already exists")
|
|
219
|
+
|
|
220
|
+
link_target = os.path.relpath(source_entry, destination.parent)
|
|
221
|
+
target_is_directory = (
|
|
222
|
+
source_entry.resolve(strict=False).is_dir()
|
|
223
|
+
if source_entry.is_symlink()
|
|
224
|
+
else source_entry.is_dir()
|
|
225
|
+
)
|
|
226
|
+
destination.symlink_to(link_target, target_is_directory=target_is_directory)
|
|
227
|
+
return f"linked {name} -> {destination}"
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
231
|
+
parser = argparse.ArgumentParser(
|
|
232
|
+
prog="abom", description="Manage agent skills, prompts, and MCP checkouts"
|
|
233
|
+
)
|
|
234
|
+
sub = parser.add_subparsers(dest="command", required=True)
|
|
235
|
+
|
|
236
|
+
install_parser = sub.add_parser("install", help="Install a named recipe from recipes.json")
|
|
237
|
+
install_parser.add_argument("name")
|
|
238
|
+
install_parser.add_argument("git_url", nargs="?")
|
|
239
|
+
|
|
240
|
+
search_parser = sub.add_parser("search", help="Search installed tools")
|
|
241
|
+
search_parser.add_argument("query", nargs="?")
|
|
242
|
+
|
|
243
|
+
recipes_parser = sub.add_parser("recipes", help="List installable recipes")
|
|
244
|
+
recipes_parser.add_argument("query", nargs="?")
|
|
245
|
+
|
|
246
|
+
info_parser = sub.add_parser("info", help="Show a recipe from the catalog")
|
|
247
|
+
info_parser.add_argument("name")
|
|
248
|
+
|
|
249
|
+
show_parser = sub.add_parser(
|
|
250
|
+
"show", help="Show a recipe, whether it is installed, and the check result"
|
|
251
|
+
)
|
|
252
|
+
show_parser.add_argument("name")
|
|
253
|
+
|
|
254
|
+
check_parser = sub.add_parser("check", help="Verify a recipe's kind and install safety")
|
|
255
|
+
check_parser.add_argument("name")
|
|
256
|
+
|
|
257
|
+
remove_parser = sub.add_parser("remove", help="Remove an installed tool")
|
|
258
|
+
remove_parser.add_argument("name")
|
|
259
|
+
|
|
260
|
+
link_parser = sub.add_parser("link", help="Link an installed tool into a target repository")
|
|
261
|
+
link_parser.add_argument("name")
|
|
262
|
+
link_parser.add_argument("target_repo")
|
|
263
|
+
link_parser.add_argument("--link-name")
|
|
264
|
+
|
|
265
|
+
return parser
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
def main(argv: list[str] | None = None) -> int:
|
|
269
|
+
parser = build_parser()
|
|
270
|
+
args = parser.parse_args(argv)
|
|
271
|
+
|
|
272
|
+
try:
|
|
273
|
+
if args.command == "install":
|
|
274
|
+
if args.git_url:
|
|
275
|
+
print(cmd_install(args.name, args.git_url))
|
|
276
|
+
else:
|
|
277
|
+
print(cmd_install_recipe(args.name))
|
|
278
|
+
elif args.command == "search":
|
|
279
|
+
for name in cmd_search(args.query):
|
|
280
|
+
print(name)
|
|
281
|
+
elif args.command == "recipes":
|
|
282
|
+
for line in cmd_recipes(args.query):
|
|
283
|
+
print(line)
|
|
284
|
+
elif args.command == "info":
|
|
285
|
+
print(cmd_info(args.name))
|
|
286
|
+
elif args.command == "show":
|
|
287
|
+
print(cmd_show(args.name))
|
|
288
|
+
elif args.command == "check":
|
|
289
|
+
print(cmd_check(args.name))
|
|
290
|
+
elif args.command == "remove":
|
|
291
|
+
print(cmd_remove(args.name))
|
|
292
|
+
elif args.command == "link":
|
|
293
|
+
print(cmd_link(args.name, args.target_repo, args.link_name))
|
|
294
|
+
else:
|
|
295
|
+
parser.error(f"unknown command: {args.command}")
|
|
296
|
+
except AbomError as exc:
|
|
297
|
+
print(f"error: {exc}", file=sys.stderr)
|
|
298
|
+
return 1
|
|
299
|
+
|
|
300
|
+
return 0
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
def _load_recipe(name: str) -> Recipe:
|
|
304
|
+
try:
|
|
305
|
+
return load_recipe(name)
|
|
306
|
+
except RecipeError as exc:
|
|
307
|
+
raise AbomError(str(exc)) from exc
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
def _clone_recipe(recipe: Recipe, destination: Path) -> None:
|
|
311
|
+
run_git(["clone", "--depth", "1", "--branch", recipe.ref, recipe.git, str(destination)])
|
|
312
|
+
if recipe.path is not None and not (destination / recipe.path).exists():
|
|
313
|
+
raise AbomError(f"recipe '{recipe.name}' path '{recipe.path}' was not found after clone")
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
def _material_root(name: str, checkout: Path) -> Path:
|
|
317
|
+
receipt = _read_receipt(name)
|
|
318
|
+
subpath = receipt.get("path") if receipt else None
|
|
319
|
+
if not subpath:
|
|
320
|
+
return checkout
|
|
321
|
+
material = checkout / subpath
|
|
322
|
+
if not material.exists() and not material.is_symlink():
|
|
323
|
+
raise AbomError(f"installed recipe '{name}' is missing path '{subpath}'")
|
|
324
|
+
return material
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
def _write_receipt(recipe: Recipe, commit: str) -> None:
|
|
328
|
+
payload = {
|
|
329
|
+
"schema": "abom.receipt/v1",
|
|
330
|
+
"name": recipe.name,
|
|
331
|
+
"kind": recipe.kind,
|
|
332
|
+
"description": recipe.description,
|
|
333
|
+
"homepage": recipe.homepage,
|
|
334
|
+
"license": recipe.license,
|
|
335
|
+
"git": recipe.git,
|
|
336
|
+
"ref": recipe.ref,
|
|
337
|
+
"path": recipe.path,
|
|
338
|
+
"commit": commit,
|
|
339
|
+
}
|
|
340
|
+
receipt = receipts_dir() / f"{recipe.name}.json"
|
|
341
|
+
receipt.write_text(json.dumps(payload, indent=2) + "\n", encoding="utf-8")
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
def _read_receipt(name: str) -> dict | None:
|
|
345
|
+
receipt = receipt_path(name)
|
|
346
|
+
if not receipt.is_file():
|
|
347
|
+
return None
|
|
348
|
+
try:
|
|
349
|
+
data = json.loads(receipt.read_text(encoding="utf-8"))
|
|
350
|
+
except (OSError, json.JSONDecodeError) as exc:
|
|
351
|
+
raise AbomError(f"could not read receipt for '{name}': {exc}") from exc
|
|
352
|
+
if not isinstance(data, dict):
|
|
353
|
+
raise AbomError(f"receipt for '{name}' is not an object")
|
|
354
|
+
return data
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
def _discard_checkout(destination: Path) -> None:
|
|
358
|
+
if destination.is_symlink() or (destination.exists() and not destination.is_dir()):
|
|
359
|
+
destination.unlink()
|
|
360
|
+
elif destination.exists():
|
|
361
|
+
shutil.rmtree(destination)
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
if __name__ == "__main__":
|
|
365
|
+
raise SystemExit(main())
|
abom/recipe.py
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
import re
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from pathlib import Path, PurePosixPath
|
|
8
|
+
|
|
9
|
+
SCHEMA = "abom.catalog/v1"
|
|
10
|
+
KINDS = ("skill", "prompt", "mcp", "package")
|
|
11
|
+
NAME_RE = re.compile(r"^[a-z0-9]+(?:[._-][a-z0-9]+)*$")
|
|
12
|
+
ALLOWED_LICENSES = frozenset(
|
|
13
|
+
{
|
|
14
|
+
"MIT",
|
|
15
|
+
"Apache-2.0",
|
|
16
|
+
"BSD-2-Clause",
|
|
17
|
+
"BSD-3-Clause",
|
|
18
|
+
"ISC",
|
|
19
|
+
"CC0-1.0",
|
|
20
|
+
"MPL-2.0",
|
|
21
|
+
"Unlicense",
|
|
22
|
+
"0BSD",
|
|
23
|
+
}
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class RecipeError(Exception):
|
|
28
|
+
pass
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@dataclass(frozen=True)
|
|
32
|
+
class Recipe:
|
|
33
|
+
name: str
|
|
34
|
+
kind: str
|
|
35
|
+
description: str
|
|
36
|
+
homepage: str
|
|
37
|
+
license: str
|
|
38
|
+
git: str
|
|
39
|
+
ref: str
|
|
40
|
+
path: str | None
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def bundled_catalog_path() -> Path:
|
|
44
|
+
return Path(__file__).resolve().parent / "recipes.json"
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def catalog_path() -> Path:
|
|
48
|
+
override = os.environ.get("ABOM_CATALOG")
|
|
49
|
+
if override:
|
|
50
|
+
return Path(override).expanduser()
|
|
51
|
+
return bundled_catalog_path()
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def load_catalog(path: Path | None = None) -> dict[str, Recipe]:
|
|
55
|
+
catalog_file = path or catalog_path()
|
|
56
|
+
try:
|
|
57
|
+
text = catalog_file.read_text(encoding="utf-8")
|
|
58
|
+
except OSError as exc:
|
|
59
|
+
raise RecipeError(f"could not read recipe catalog '{catalog_file}': {exc}") from exc
|
|
60
|
+
recipes, _entries = parse_catalog(text, str(catalog_file))
|
|
61
|
+
return recipes
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def parse_catalog(text: str, label: str = "catalog") -> tuple[dict[str, Recipe], dict[str, dict]]:
|
|
65
|
+
try:
|
|
66
|
+
data = json.loads(text)
|
|
67
|
+
except json.JSONDecodeError as exc:
|
|
68
|
+
raise RecipeError(f"recipe catalog '{label}' is not valid JSON: {exc}") from exc
|
|
69
|
+
if not isinstance(data, dict):
|
|
70
|
+
raise RecipeError(f"recipe catalog '{label}' must be a JSON object")
|
|
71
|
+
if data.get("schema") != SCHEMA:
|
|
72
|
+
raise RecipeError(f"recipe catalog '{label}' must set schema to {SCHEMA}")
|
|
73
|
+
|
|
74
|
+
entries = data.get("recipes")
|
|
75
|
+
if not isinstance(entries, list):
|
|
76
|
+
raise RecipeError(f"recipe catalog '{label}' is missing a recipes list")
|
|
77
|
+
|
|
78
|
+
found: dict[str, Recipe] = {}
|
|
79
|
+
raw: dict[str, dict] = {}
|
|
80
|
+
for index, entry in enumerate(entries):
|
|
81
|
+
if not isinstance(entry, dict):
|
|
82
|
+
raise RecipeError(f"recipe catalog entry {index} must be an object")
|
|
83
|
+
recipe = recipe_from_mapping(entry)
|
|
84
|
+
if recipe.name in found:
|
|
85
|
+
raise RecipeError(f"duplicate recipe '{recipe.name}' in {label}")
|
|
86
|
+
found[recipe.name] = recipe
|
|
87
|
+
raw[recipe.name] = entry
|
|
88
|
+
return found, raw
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def recipe_changes(base_text: str | None, head_text: str) -> list[tuple[str, Recipe]]:
|
|
92
|
+
"""Return added or updated recipes. Both catalogs must validate when present."""
|
|
93
|
+
head, head_entries = parse_catalog(head_text, "head")
|
|
94
|
+
base_entries: dict[str, dict] = {}
|
|
95
|
+
if base_text is not None and base_text.strip():
|
|
96
|
+
_base, base_entries = parse_catalog(base_text, "base")
|
|
97
|
+
changes: list[tuple[str, Recipe]] = []
|
|
98
|
+
for name, recipe in sorted(head.items()):
|
|
99
|
+
previous = base_entries.get(name)
|
|
100
|
+
if previous is None:
|
|
101
|
+
changes.append(("added", recipe))
|
|
102
|
+
elif previous != head_entries[name]:
|
|
103
|
+
changes.append(("updated", recipe))
|
|
104
|
+
return changes
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def load_recipe(name: str, path: Path | None = None) -> Recipe:
|
|
108
|
+
catalog = load_catalog(path)
|
|
109
|
+
recipe = catalog.get(name)
|
|
110
|
+
if recipe is None:
|
|
111
|
+
raise RecipeError(f"no recipe named '{name}' in {path or catalog_path()}")
|
|
112
|
+
return recipe
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def iter_recipes(query: str | None = None, path: Path | None = None) -> list[Recipe]:
|
|
116
|
+
recipes = list(load_catalog(path).values())
|
|
117
|
+
if query:
|
|
118
|
+
needle = query.lower()
|
|
119
|
+
recipes = [
|
|
120
|
+
recipe
|
|
121
|
+
for recipe in recipes
|
|
122
|
+
if needle in f"{recipe.name} {recipe.kind} {recipe.description}".lower()
|
|
123
|
+
]
|
|
124
|
+
return sorted(recipes, key=lambda recipe: recipe.name)
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def recipe_from_mapping(data: dict) -> Recipe:
|
|
128
|
+
name = _required_string(data, "name", "recipe")
|
|
129
|
+
if not NAME_RE.fullmatch(name):
|
|
130
|
+
raise RecipeError(
|
|
131
|
+
f"recipe name '{name}' must be lowercase letters, numbers, and . _ - separators"
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
kind = _required_string(data, "kind", name)
|
|
135
|
+
if kind not in KINDS:
|
|
136
|
+
raise RecipeError(f"recipe '{name}' kind must be one of: {', '.join(KINDS)}")
|
|
137
|
+
|
|
138
|
+
source = data.get("source")
|
|
139
|
+
if not isinstance(source, dict):
|
|
140
|
+
raise RecipeError(f"recipe '{name}' is missing a source object")
|
|
141
|
+
|
|
142
|
+
git = _required_string(source, "git", name)
|
|
143
|
+
validate_git_url(git)
|
|
144
|
+
ref = source.get("ref", "main")
|
|
145
|
+
if not isinstance(ref, str) or not ref.strip():
|
|
146
|
+
raise RecipeError(f"recipe '{name}' source.ref must be a non-empty string")
|
|
147
|
+
|
|
148
|
+
raw_path = source.get("path")
|
|
149
|
+
subpath: str | None
|
|
150
|
+
if raw_path is None:
|
|
151
|
+
subpath = None
|
|
152
|
+
else:
|
|
153
|
+
if not isinstance(raw_path, str) or not raw_path.strip():
|
|
154
|
+
raise RecipeError(f"recipe '{name}' source.path must be a relative path")
|
|
155
|
+
subpath = _clean_subpath(raw_path.strip(), name)
|
|
156
|
+
|
|
157
|
+
return Recipe(
|
|
158
|
+
name=name,
|
|
159
|
+
kind=kind,
|
|
160
|
+
description=_required_string(data, "description", name),
|
|
161
|
+
homepage=_required_string(data, "homepage", name),
|
|
162
|
+
license=validate_license(_required_string(data, "license", name)),
|
|
163
|
+
git=git,
|
|
164
|
+
ref=ref.strip(),
|
|
165
|
+
path=subpath,
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def validate_license(expression: str) -> str:
|
|
170
|
+
"""Accept one SPDX id, or several joined by OR or AND."""
|
|
171
|
+
parts = re.split(r"\s+(?:OR|AND)\s+", expression.strip())
|
|
172
|
+
if not parts or any(part not in ALLOWED_LICENSES for part in parts):
|
|
173
|
+
allowed = ", ".join(sorted(ALLOWED_LICENSES))
|
|
174
|
+
raise RecipeError(f"license '{expression}' must use allowed SPDX ids: {allowed}")
|
|
175
|
+
if " OR " in expression and " AND " in expression:
|
|
176
|
+
raise RecipeError(f"license '{expression}' cannot mix OR and AND")
|
|
177
|
+
return expression.strip()
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
def license_terms(expression: str) -> tuple[str, tuple[str, ...]]:
|
|
181
|
+
expression = validate_license(expression)
|
|
182
|
+
if " OR " in expression:
|
|
183
|
+
return "OR", tuple(re.split(r"\s+OR\s+", expression))
|
|
184
|
+
if " AND " in expression:
|
|
185
|
+
return "AND", tuple(re.split(r"\s+AND\s+", expression))
|
|
186
|
+
return "SINGLE", (expression,)
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def validate_git_url(url: str) -> None:
|
|
190
|
+
"""Reject clone URLs that can execute a helper during fetch."""
|
|
191
|
+
if url != url.strip() or any(char in url for char in "\n\r\x00"):
|
|
192
|
+
raise RecipeError("git url contains whitespace or control characters")
|
|
193
|
+
lowered = url.lower()
|
|
194
|
+
if lowered.startswith(("ext::", "fd::", "-")):
|
|
195
|
+
raise RecipeError(f"git url is not allowed: {url}")
|
|
196
|
+
if "://" in url:
|
|
197
|
+
scheme = url.split("://", 1)[0].lower()
|
|
198
|
+
if scheme not in {"https", "http", "ssh", "git", "file"}:
|
|
199
|
+
raise RecipeError(f"git url scheme '{scheme}' is not allowed")
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def format_recipe(recipe: Recipe) -> str:
|
|
203
|
+
lines = [
|
|
204
|
+
f"name: {recipe.name}",
|
|
205
|
+
f"kind: {recipe.kind}",
|
|
206
|
+
f"description: {recipe.description}",
|
|
207
|
+
f"homepage: {recipe.homepage}",
|
|
208
|
+
f"license: {recipe.license}",
|
|
209
|
+
f"git: {recipe.git}",
|
|
210
|
+
f"ref: {recipe.ref}",
|
|
211
|
+
]
|
|
212
|
+
if recipe.path is not None:
|
|
213
|
+
lines.append(f"path: {recipe.path}")
|
|
214
|
+
return "\n".join(lines)
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def format_recipe_line(recipe: Recipe) -> str:
|
|
218
|
+
return f"{recipe.name} {recipe.kind} {recipe.license} {recipe.description}"
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
def _required_string(data: dict, key: str, recipe_name: str) -> str:
|
|
222
|
+
value = data.get(key)
|
|
223
|
+
if not isinstance(value, str) or not value.strip():
|
|
224
|
+
raise RecipeError(f"recipe '{recipe_name}' is missing {key}")
|
|
225
|
+
return value.strip()
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
def _clean_subpath(path: str, recipe_name: str) -> str:
|
|
229
|
+
if "\\" in path:
|
|
230
|
+
raise RecipeError(f"recipe '{recipe_name}' source.path must use '/' separators")
|
|
231
|
+
pure = PurePosixPath(path)
|
|
232
|
+
if pure.is_absolute() or not pure.parts or ".." in pure.parts:
|
|
233
|
+
raise RecipeError(
|
|
234
|
+
f"recipe '{recipe_name}' source.path must be a relative path inside the repo"
|
|
235
|
+
)
|
|
236
|
+
return pure.as_posix()
|
abom/recipes.json
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schema": "abom.catalog/v1",
|
|
3
|
+
"recipes": [
|
|
4
|
+
{
|
|
5
|
+
"name": "anthropics-skill-creator",
|
|
6
|
+
"kind": "skill",
|
|
7
|
+
"description": "Create new skills, improve existing ones, and measure how well they trigger.",
|
|
8
|
+
"homepage": "https://github.com/anthropics/skills",
|
|
9
|
+
"license": "Apache-2.0",
|
|
10
|
+
"source": {
|
|
11
|
+
"git": "https://github.com/anthropics/skills.git",
|
|
12
|
+
"ref": "main",
|
|
13
|
+
"path": "skills/skill-creator"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"name": "f-prompts",
|
|
18
|
+
"kind": "prompt",
|
|
19
|
+
"description": "Community prompt collection from prompts.chat, formerly Awesome ChatGPT Prompts.",
|
|
20
|
+
"homepage": "https://github.com/f/prompts.chat",
|
|
21
|
+
"license": "CC0-1.0",
|
|
22
|
+
"source": {
|
|
23
|
+
"git": "https://github.com/f/prompts.chat.git",
|
|
24
|
+
"ref": "main",
|
|
25
|
+
"path": "PROMPTS.md"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"name": "modelcontextprotocol-filesystem",
|
|
30
|
+
"kind": "mcp",
|
|
31
|
+
"description": "Reference MCP server for sandboxed filesystem access.",
|
|
32
|
+
"homepage": "https://github.com/modelcontextprotocol/servers",
|
|
33
|
+
"license": "Apache-2.0 OR MIT",
|
|
34
|
+
"source": {
|
|
35
|
+
"git": "https://github.com/modelcontextprotocol/servers.git",
|
|
36
|
+
"ref": "main",
|
|
37
|
+
"path": "src/filesystem"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"name": "f-prompts-chat",
|
|
42
|
+
"kind": "package",
|
|
43
|
+
"description": "prompts.chat toolkit for building, validating, and parsing prompts.",
|
|
44
|
+
"homepage": "https://github.com/f/prompts.chat",
|
|
45
|
+
"license": "MIT",
|
|
46
|
+
"source": {
|
|
47
|
+
"git": "https://github.com/f/prompts.chat.git",
|
|
48
|
+
"ref": "main",
|
|
49
|
+
"path": "packages/prompts.chat"
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"name": "abom-skill",
|
|
54
|
+
"kind": "skill",
|
|
55
|
+
"description": "Install, check, and link agent skills, prompts, MCP servers, and packages with the abom CLI.",
|
|
56
|
+
"homepage": "https://yanchao1999.github.io/abom/",
|
|
57
|
+
"license": "MIT",
|
|
58
|
+
"source": {
|
|
59
|
+
"git": "https://github.com/YanChao1999/abom.git",
|
|
60
|
+
"ref": "main",
|
|
61
|
+
"path": "skills/abom"
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"name": "abom-package",
|
|
66
|
+
"kind": "package",
|
|
67
|
+
"description": "abom CLI package from GitHub. Install it, then list the recipe catalog.",
|
|
68
|
+
"homepage": "https://yanchao1999.github.io/abom/",
|
|
69
|
+
"license": "MIT",
|
|
70
|
+
"source": {
|
|
71
|
+
"git": "https://github.com/YanChao1999/abom.git",
|
|
72
|
+
"ref": "main"
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"name": "abom-mcp",
|
|
77
|
+
"kind": "mcp",
|
|
78
|
+
"description": "MCP server that lists, checks, installs, and links abom recipes.",
|
|
79
|
+
"homepage": "https://yanchao1999.github.io/abom/",
|
|
80
|
+
"license": "MIT",
|
|
81
|
+
"source": {
|
|
82
|
+
"git": "https://github.com/YanChao1999/abom.git",
|
|
83
|
+
"ref": "main",
|
|
84
|
+
"path": "mcp"
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
]
|
|
88
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: abom
|
|
3
|
+
Version: 0.0.2
|
|
4
|
+
Summary: Agent bill of materials manager for skills, prompts, MCP servers, and packages.
|
|
5
|
+
License: MIT License
|
|
6
|
+
|
|
7
|
+
Copyright (c) 2026 YanChao1999
|
|
8
|
+
|
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
in the Software without restriction, including without limitation the rights
|
|
12
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
furnished to do so, subject to the following conditions:
|
|
15
|
+
|
|
16
|
+
The above copyright notice and this permission notice shall be included in all
|
|
17
|
+
copies or substantial portions of the Software.
|
|
18
|
+
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
|
+
SOFTWARE.
|
|
26
|
+
|
|
27
|
+
Project-URL: Homepage, https://yanchao1999.github.io/abom/
|
|
28
|
+
Project-URL: Repository, https://github.com/YanChao1999/abom
|
|
29
|
+
Project-URL: Issues, https://github.com/YanChao1999/abom/issues
|
|
30
|
+
Requires-Python: >=3.10
|
|
31
|
+
Description-Content-Type: text/markdown
|
|
32
|
+
License-File: LICENSE
|
|
33
|
+
Provides-Extra: dev
|
|
34
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
35
|
+
Requires-Dist: ruff>=0.6; extra == "dev"
|
|
36
|
+
Dynamic: license-file
|
|
37
|
+
|
|
38
|
+
# abom
|
|
39
|
+
|
|
40
|
+
`abom` is a Python CLI for managing agent materials (skills, prompts, MCP configs) as git-backed tools. The recipe list lives in the repo as `src/abom/recipes.json`. `abom install <name>` looks up that name and clones the git URL stored there.
|
|
41
|
+
|
|
42
|
+
## Package management
|
|
43
|
+
|
|
44
|
+
Homepage: <https://yanchao1999.github.io/abom/>
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pip install abom
|
|
48
|
+
abom recipes
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
TestPyPI:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ abom
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
For local development:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
uv sync --extra dev
|
|
61
|
+
uv run abom recipes
|
|
62
|
+
uv run ruff format --check .
|
|
63
|
+
uv run ruff check .
|
|
64
|
+
uv run pytest
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Version 0.0.2. GitHub Actions runs format, lint, and test on every pull request. A pull request that adds or edits `src/abom/recipes.json` also runs the recipe pull-check. Pushing a `v*` tag publishes a GitHub release, TestPyPI, and PyPI from the same build. Pushes to `main` publish the GitHub Pages site.
|
|
68
|
+
|
|
69
|
+
Trusted publishing uses the GitHub environments `testpypi` and `pypi`. On each index, add this repository as a trusted publisher: workflow `deploy.yml`, and the matching environment name. The PyPI project name is `abom`.
|
|
70
|
+
|
|
71
|
+
## Recipes
|
|
72
|
+
|
|
73
|
+
Add a material by appending an object to the `recipes` list in `src/abom/recipes.json`. Name it `<publisher>-<material>` so the source is visible in the name, then install by that name:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
abom install anthropics-skill-creator
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
`kind` is `skill`, `prompt`, `mcp`, or `package`. `source.git` is the clone URL. `source.ref` is a branch or tag (`main` when omitted). `source.path` is optional; when set, `abom link` points at that file or directory inside the checkout.
|
|
80
|
+
|
|
81
|
+
```json
|
|
82
|
+
{
|
|
83
|
+
"name": "anthropics-example-name",
|
|
84
|
+
"kind": "skill",
|
|
85
|
+
"description": "One line describing what this material does and when to use it.",
|
|
86
|
+
"homepage": "https://example.com/example-name",
|
|
87
|
+
"license": "Apache-2.0",
|
|
88
|
+
"source": {
|
|
89
|
+
"git": "https://github.com/org/repo.git",
|
|
90
|
+
"ref": "main",
|
|
91
|
+
"path": "path/inside/repo"
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
The catalog ships one of each kind:
|
|
97
|
+
|
|
98
|
+
| Name | Kind | Source |
|
|
99
|
+
| --- | --- | --- |
|
|
100
|
+
| `abom-package` | package | [YanChao1999/abom](https://github.com/YanChao1999/abom) repository root |
|
|
101
|
+
| `abom-skill` | skill | [YanChao1999/abom](https://github.com/YanChao1999/abom) `skills/abom` |
|
|
102
|
+
| `abom-mcp` | mcp | [YanChao1999/abom](https://github.com/YanChao1999/abom) `mcp` |
|
|
103
|
+
| `anthropics-skill-creator` | skill | [anthropics/skills](https://github.com/anthropics/skills) `skills/skill-creator` |
|
|
104
|
+
| `f-prompts` | prompt | [f/prompts.chat](https://github.com/f/prompts.chat) `PROMPTS.md` |
|
|
105
|
+
| `modelcontextprotocol-filesystem` | mcp | [modelcontextprotocol/servers](https://github.com/modelcontextprotocol/servers) `src/filesystem` |
|
|
106
|
+
| `f-prompts-chat` | package | [f/prompts.chat](https://github.com/f/prompts.chat) `packages/prompts.chat` |
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
abom recipes
|
|
110
|
+
abom info anthropics-skill-creator
|
|
111
|
+
abom check anthropics-skill-creator
|
|
112
|
+
abom install anthropics-skill-creator
|
|
113
|
+
abom show anthropics-skill-creator
|
|
114
|
+
abom link anthropics-skill-creator /path/to/project
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
`abom check` clones the recipe when it is not installed yet, then deletes that temporary checkout. Install runs the same check and keeps the checkout only when it passes. The check confirms the kind and blocks install-time hijacks:
|
|
118
|
+
|
|
119
|
+
- a skill must be a directory with `SKILL.md` frontmatter (`name` and `description`)
|
|
120
|
+
- a prompt must be a text prompt file, or a directory of them
|
|
121
|
+
- a package must have `package.json` or `pyproject.toml`
|
|
122
|
+
- the checkout must contain a license file, and the recognized license must satisfy the recipe's `license` field
|
|
123
|
+
- an mcp must have a server manifest or entry file (`package.json`, `pyproject.toml`, `index.ts`, `index.js`, `server.py`, or `main.py`)
|
|
124
|
+
- clone URLs cannot use a scheme that runs a helper, such as `ext::`
|
|
125
|
+
- git hooks and filesystem monitors from the cloned repo are not executed
|
|
126
|
+
- a symlink that points outside the checkout is rejected
|
|
127
|
+
- a prompt, skill, or package lifecycle script that pipes a download into a shell is rejected
|
|
128
|
+
|
|
129
|
+
## Commands
|
|
130
|
+
|
|
131
|
+
- `abom install <name>`: install the named recipe from `recipes.json` into `$ABOM_HOME/tools`.
|
|
132
|
+
- `abom install <name> <git_url>`: clone a git repository that is not in the catalog.
|
|
133
|
+
- `abom recipes [query]`: list recipes, optionally filtered by name, kind, or description.
|
|
134
|
+
- `abom info <name>`: print one catalog entry.
|
|
135
|
+
- `abom show <name>`: print the catalog entry, whether it is installed, and the check result when it is installed.
|
|
136
|
+
- `abom check <name>`: verify the kind and install safety. Exits with an error when the check fails.
|
|
137
|
+
- `abom search [query]`: list installed tools, optionally filtered by name.
|
|
138
|
+
- `abom remove <name>`: remove an installed tool and its receipt.
|
|
139
|
+
- `abom link <name> <target_repo> [--link-name <name>]`: create a symlink at `<target_repo>/.abom/<name>` pointing to the installed material. `target_repo` must already exist.
|
|
140
|
+
|
|
141
|
+
Set `ABOM_HOME` to override `~/.abom`.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
abom/__init__.py,sha256=wh3VQQH1NkSq3KyikJo_djDXp-h7OnvyoBVYOvh-2Fg,48
|
|
2
|
+
abom/check.py,sha256=v3XOFbScKuhk476r8HyHF1-aTSJg7X-ixMHDc51Jn1E,12110
|
|
3
|
+
abom/cli.py,sha256=vqaiL4KXNHr3K2Zn6EI7Ea5ajTxX0JESTli_qxd-JK8,11877
|
|
4
|
+
abom/recipe.py,sha256=caC5EIy5GLo70R5Aipv9moYDRmOxLlspSbFljK_vEgg,8024
|
|
5
|
+
abom/recipes.json,sha256=dPNL0XKyYk2jZUXkicE6CH3ErpQiYWmKe-JZ0k5lVAM,2769
|
|
6
|
+
abom-0.0.2.dist-info/licenses/LICENSE,sha256=OLiCLhGA3rKjh-Yqn0fqfoIBFlwH15jy-WS7237RgAE,1068
|
|
7
|
+
abom-0.0.2.dist-info/METADATA,sha256=yhvAVRSAzpVfABRGGoQcsgcvLxS1LcUDzzo0OO0qlVY,6726
|
|
8
|
+
abom-0.0.2.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
9
|
+
abom-0.0.2.dist-info/entry_points.txt,sha256=2yAMN3TeyDe2znTzL-zSp5RnwSXSk_me8MnGpSD9SsM,39
|
|
10
|
+
abom-0.0.2.dist-info/top_level.txt,sha256=H8lsJdZpMq7dGCSlqEOVr1MYkYLrQzk9qWl74Eq6A60,5
|
|
11
|
+
abom-0.0.2.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 YanChao1999
|
|
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.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
abom
|