abom 0.0.2__tar.gz

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-0.0.2/LICENSE ADDED
@@ -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.
abom-0.0.2/PKG-INFO ADDED
@@ -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`.
abom-0.0.2/README.md ADDED
@@ -0,0 +1,104 @@
1
+ # abom
2
+
3
+ `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.
4
+
5
+ ## Package management
6
+
7
+ Homepage: <https://yanchao1999.github.io/abom/>
8
+
9
+ ```bash
10
+ pip install abom
11
+ abom recipes
12
+ ```
13
+
14
+ TestPyPI:
15
+
16
+ ```bash
17
+ pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ abom
18
+ ```
19
+
20
+ For local development:
21
+
22
+ ```bash
23
+ uv sync --extra dev
24
+ uv run abom recipes
25
+ uv run ruff format --check .
26
+ uv run ruff check .
27
+ uv run pytest
28
+ ```
29
+
30
+ 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.
31
+
32
+ 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`.
33
+
34
+ ## Recipes
35
+
36
+ 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:
37
+
38
+ ```bash
39
+ abom install anthropics-skill-creator
40
+ ```
41
+
42
+ `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.
43
+
44
+ ```json
45
+ {
46
+ "name": "anthropics-example-name",
47
+ "kind": "skill",
48
+ "description": "One line describing what this material does and when to use it.",
49
+ "homepage": "https://example.com/example-name",
50
+ "license": "Apache-2.0",
51
+ "source": {
52
+ "git": "https://github.com/org/repo.git",
53
+ "ref": "main",
54
+ "path": "path/inside/repo"
55
+ }
56
+ }
57
+ ```
58
+
59
+ The catalog ships one of each kind:
60
+
61
+ | Name | Kind | Source |
62
+ | --- | --- | --- |
63
+ | `abom-package` | package | [YanChao1999/abom](https://github.com/YanChao1999/abom) repository root |
64
+ | `abom-skill` | skill | [YanChao1999/abom](https://github.com/YanChao1999/abom) `skills/abom` |
65
+ | `abom-mcp` | mcp | [YanChao1999/abom](https://github.com/YanChao1999/abom) `mcp` |
66
+ | `anthropics-skill-creator` | skill | [anthropics/skills](https://github.com/anthropics/skills) `skills/skill-creator` |
67
+ | `f-prompts` | prompt | [f/prompts.chat](https://github.com/f/prompts.chat) `PROMPTS.md` |
68
+ | `modelcontextprotocol-filesystem` | mcp | [modelcontextprotocol/servers](https://github.com/modelcontextprotocol/servers) `src/filesystem` |
69
+ | `f-prompts-chat` | package | [f/prompts.chat](https://github.com/f/prompts.chat) `packages/prompts.chat` |
70
+
71
+ ```bash
72
+ abom recipes
73
+ abom info anthropics-skill-creator
74
+ abom check anthropics-skill-creator
75
+ abom install anthropics-skill-creator
76
+ abom show anthropics-skill-creator
77
+ abom link anthropics-skill-creator /path/to/project
78
+ ```
79
+
80
+ `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:
81
+
82
+ - a skill must be a directory with `SKILL.md` frontmatter (`name` and `description`)
83
+ - a prompt must be a text prompt file, or a directory of them
84
+ - a package must have `package.json` or `pyproject.toml`
85
+ - the checkout must contain a license file, and the recognized license must satisfy the recipe's `license` field
86
+ - an mcp must have a server manifest or entry file (`package.json`, `pyproject.toml`, `index.ts`, `index.js`, `server.py`, or `main.py`)
87
+ - clone URLs cannot use a scheme that runs a helper, such as `ext::`
88
+ - git hooks and filesystem monitors from the cloned repo are not executed
89
+ - a symlink that points outside the checkout is rejected
90
+ - a prompt, skill, or package lifecycle script that pipes a download into a shell is rejected
91
+
92
+ ## Commands
93
+
94
+ - `abom install <name>`: install the named recipe from `recipes.json` into `$ABOM_HOME/tools`.
95
+ - `abom install <name> <git_url>`: clone a git repository that is not in the catalog.
96
+ - `abom recipes [query]`: list recipes, optionally filtered by name, kind, or description.
97
+ - `abom info <name>`: print one catalog entry.
98
+ - `abom show <name>`: print the catalog entry, whether it is installed, and the check result when it is installed.
99
+ - `abom check <name>`: verify the kind and install safety. Exits with an error when the check fails.
100
+ - `abom search [query]`: list installed tools, optionally filtered by name.
101
+ - `abom remove <name>`: remove an installed tool and its receipt.
102
+ - `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.
103
+
104
+ Set `ABOM_HOME` to override `~/.abom`.
@@ -0,0 +1,49 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "abom"
7
+ version = "0.0.2"
8
+ description = "Agent bill of materials manager for skills, prompts, MCP servers, and packages."
9
+ readme = "README.md"
10
+ license = {file = "LICENSE"}
11
+ requires-python = ">=3.10"
12
+ dependencies = []
13
+
14
+ [project.urls]
15
+ Homepage = "https://yanchao1999.github.io/abom/"
16
+ Repository = "https://github.com/YanChao1999/abom"
17
+ Issues = "https://github.com/YanChao1999/abom/issues"
18
+
19
+ [project.scripts]
20
+ abom = "abom.cli:main"
21
+
22
+ [project.optional-dependencies]
23
+ dev = ["pytest>=8.0", "ruff>=0.6"]
24
+
25
+ [tool.pytest.ini_options]
26
+ addopts = "-q"
27
+ testpaths = ["tests"]
28
+
29
+ [tool.setuptools]
30
+ package-dir = {"" = "src"}
31
+
32
+ [tool.setuptools.packages.find]
33
+ where = ["src"]
34
+
35
+ [tool.setuptools.package-data]
36
+ abom = ["recipes.json"]
37
+
38
+ [tool.ruff]
39
+ target-version = "py310"
40
+ line-length = 100
41
+ src = ["src", "tests", "mcp"]
42
+
43
+ [tool.ruff.lint]
44
+ select = ["E", "F", "I"]
45
+ ignore = ["E501"]
46
+
47
+ [tool.ruff.lint.per-file-ignores]
48
+ "mcp/server.py" = ["E402"]
49
+ "scripts/check_new_recipes.py" = ["E402"]
abom-0.0.2/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,2 @@
1
+ __all__ = ["__version__"]
2
+ __version__ = "0.0.2"
@@ -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