@bbcsoftwarefactory/skills 0.1.1 → 1.1.3
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.
- package/dist/index.json +2 -3
- package/dist/skills/code-quality-gate/SKILL.md +4 -5
- package/dist/skills/code-quality-gate/references/gate-bigo.md +1 -1
- package/dist/skills/delivery-coordinator/SKILL.md +7 -8
- package/dist/skills/delivery-coordinator/references/hud-output.md +1 -1
- package/dist/skills/delivery-coordinator/references/issue-claim.md +5 -5
- package/dist/skills/delivery-coordinator/references/issue-dedup.md +1 -1
- package/dist/skills/delivery-coordinator/references/worktree-isolation.md +2 -2
- package/dist/skills/greptile-review-loop/SKILL.md +3 -4
- package/dist/skills/greptile-review-loop/references/review-protocol.md +1 -1
- package/dist/skills/issue-reviewer/SKILL.md +10 -13
- package/dist/skills/issue-reviewer/references/review-format.md +1 -1
- package/dist/skills/issue-reviewer/references/triage.md +6 -6
- package/dist/skills/question-gate/SKILL.md +6 -8
- package/dist/skills/question-gate/references/client-hooks.md +10 -10
- package/dist/skills/question-gate/references/diagram-routing.md +3 -3
- package/dist/skills/skill-clean-architecture/SKILL.md +2 -3
- package/dist/skills/skill-clean-architecture/references/source-headers.md +2 -3
- package/dist/skills/tool-depot/references/readonly-access.md +1 -1
- package/dist/skills/tool-depot/references/tool-catalog.json +2 -2
- package/dist/skills/watcher-observability/SKILL.md +3 -4
- package/dist/skills/watcher-observability/references/batch-protocol.md +6 -6
- package/dist/skills/watcher-observability/references/configuration.md +1 -1
- package/dist/skills/watcher-observability/references/error-scan.md +1 -1
- package/dist/skills/watcher-observability/references/live-protocol.md +8 -8
- package/dist/skills/watcher-observability/references/server-account.md +8 -8
- package/dist/skills/watcher-observability/server/watcher-gate.sh +1 -1
- package/dist/skills/watcher-observability/tests/watcher-gate.test.sh +10 -7
- package/dist/skills/workflow-auditor/SKILL.md +3 -5
- package/dist/skills/workflow-auditor/references/audit-protocol.md +3 -3
- package/dist/skills/workflow-auditor/references/ledger.md +1 -1
- package/package.json +26 -27
- package/dist/skills/code-quality-gate/scripts/extract-diff-scope.py +0 -225
- package/dist/skills/code-quality-gate/tests/extract-diff-scope.test.sh +0 -200
- package/dist/skills/delivery-coordinator/scripts/check-issue-claim.py +0 -363
- package/dist/skills/delivery-coordinator/scripts/check-worktree-guard.py +0 -220
- package/dist/skills/delivery-coordinator/scripts/classify-change-lane.py +0 -263
- package/dist/skills/delivery-coordinator/tests/check-issue-claim.test.sh +0 -221
- package/dist/skills/delivery-coordinator/tests/check-worktree-guard.test.sh +0 -123
- package/dist/skills/delivery-coordinator/tests/classify-change-lane.test.sh +0 -124
- package/dist/skills/greptile-review-loop/scripts/review-loop.py +0 -435
- package/dist/skills/greptile-review-loop/tests/review-loop.test.sh +0 -331
- package/dist/skills/issue-reviewer/scripts/fetch-issue-attachments.py +0 -239
- package/dist/skills/issue-reviewer/scripts/plan-issue-triage.py +0 -311
- package/dist/skills/issue-reviewer/tests/fetch-issue-attachments.test.sh +0 -90
- package/dist/skills/issue-reviewer/tests/plan-issue-triage.test.sh +0 -168
- package/dist/skills/question-gate/scripts/triage-question.py +0 -713
- package/dist/skills/question-gate/tests/question-corpus.test.sh +0 -32
- package/dist/skills/question-gate/tests/triage-question.test.sh +0 -441
- package/dist/skills/skill-clean-architecture/scripts/measure-bigo.py +0 -427
- package/dist/skills/skill-clean-architecture/tests/measure-bigo.test.sh +0 -222
- package/dist/skills/watcher-observability/scripts/error-scan.py +0 -318
- package/dist/skills/watcher-observability/scripts/resolve-containers.py +0 -155
- package/dist/skills/watcher-observability/scripts/save-counts.py +0 -381
- package/dist/skills/watcher-observability/scripts/summarize-logs.py +0 -113
- package/dist/skills/watcher-observability/scripts/watch-live.py +0 -606
- package/dist/skills/watcher-observability/tests/error-scan.test.sh +0 -257
- package/dist/skills/watcher-observability/tests/live-windows.test.sh +0 -177
- package/dist/skills/watcher-observability/tests/resolve-containers.test.sh +0 -87
- package/dist/skills/watcher-observability/tests/save-counts.test.sh +0 -338
- package/dist/skills/watcher-observability/tests/sleuth.test.sh +0 -176
- package/dist/skills/watcher-observability/tests/summarize-logs.test.sh +0 -105
- package/dist/skills/watcher-observability/tests/watcher-config.test.sh +0 -70
- package/dist/skills/workflow-auditor/scripts/audit-ledger.py +0 -624
- package/dist/skills/workflow-auditor/scripts/list-zed-commands.py +0 -183
- package/dist/skills/workflow-auditor/scripts/render-workflow.py +0 -201
- package/dist/skills/workflow-auditor/scripts/validate-skills.py +0 -444
- package/dist/skills/workflow-auditor/tests/audit-ledger.test.sh +0 -660
- package/dist/skills/workflow-auditor/tests/list-zed-commands.test.sh +0 -93
- package/dist/skills/workflow-auditor/tests/render-workflow.test.sh +0 -135
- package/dist/skills/workflow-auditor/tests/validate-skills.test.sh +0 -190
|
@@ -1,444 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""Validate SKILL.md frontmatter, scripts/adapters references, and Zed 50 KB budget."""
|
|
3
|
-
|
|
4
|
-
import html
|
|
5
|
-
import json
|
|
6
|
-
from pathlib import Path
|
|
7
|
-
import re
|
|
8
|
-
import sys
|
|
9
|
-
|
|
10
|
-
ZED_CATALOG_LIMIT_BYTES = 50 * 1024
|
|
11
|
-
# The only metadata keys the collection uses. A new key is a deliberate decision:
|
|
12
|
-
# add it here with its meaning, so a typo like `hooks:` cannot survive silently.
|
|
13
|
-
METADATA_KEYS = frozenset({
|
|
14
|
-
'author', 'version', 'pre_hook', 'post_hook', 'post_install', 'scripts', 'adapters',
|
|
15
|
-
})
|
|
16
|
-
HELP = (
|
|
17
|
-
'Usage: python3 -I -B scripts/validate-skills.py [repo-root] [--release-tag v<VERSION>]\n'
|
|
18
|
-
'Checks skills/*/SKILL.md and commands/*/SKILL.md frontmatter, referenced '
|
|
19
|
-
'scripts/adapters, compatibility on scripted skills, aggregate frontmatter size, '
|
|
20
|
-
'relative Markdown links, the Tool Depot catalog shape and protocol paths, and '
|
|
21
|
-
'that every cited catalog purpose exists.'
|
|
22
|
-
)
|
|
23
|
-
CATALOG = Path('skills/tool-depot/references/tool-catalog.json')
|
|
24
|
-
MD_LINK = re.compile(r'\]\(([^)\s]+)\)')
|
|
25
|
-
HOOK_FILE = re.compile(r'\b((?:scripts|references|adapters)/[A-Za-z0-9_.-]+\.[A-Za-z0-9]+)')
|
|
26
|
-
# A cited purpose is a backticked kebab-case ID with 3+ segments whose first word
|
|
27
|
-
# is a catalog verb (`check-duplicate-issues`); 2-segment words like `read-only`
|
|
28
|
-
# are ordinary prose.
|
|
29
|
-
CITED_ID = re.compile(r'`([a-z]+(?:-[a-z0-9]+){2,})`')
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
def markdown_files(root):
|
|
33
|
-
files = [root / name for name in ('README.md', 'AGENTS.md', 'INSTALLATION.md')]
|
|
34
|
-
for pattern in ('skills/**/*.md', 'commands/**/*.md', 'docs/**/*.md'):
|
|
35
|
-
files.extend(sorted(root.glob(pattern)))
|
|
36
|
-
return [path for path in files if path.is_file()]
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
def check_links(root, errors):
|
|
40
|
-
for md in markdown_files(root):
|
|
41
|
-
for match in MD_LINK.finditer(md.read_text(encoding='utf-8')):
|
|
42
|
-
target = match.group(1)
|
|
43
|
-
if re.match(r'^[a-z][a-z0-9+.-]*:', target) or target.startswith('#') or '<' in target:
|
|
44
|
-
continue
|
|
45
|
-
path = target.split('#', 1)[0]
|
|
46
|
-
if not path or set(path) <= {'.', '…'}: # anchors and template placeholders like (...)
|
|
47
|
-
continue
|
|
48
|
-
if not (md.parent / path).exists():
|
|
49
|
-
errors.append(f'{md.relative_to(root)}: broken link {target}')
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
# The workflow is drawn four times (README Mermaid, AGENTS.md handoffs, SVG export and
|
|
53
|
-
# Excalidraw source) and kept in sync by hand (#47). Every skill must appear in each.
|
|
54
|
-
DIAGRAM_ALIASES = {'watcher-observability': ('Sleuth',)}
|
|
55
|
-
# Gaps already tracked by an issue. Remove an entry when its fix lands: a listed gap
|
|
56
|
-
# that is no longer missing fails as stale, so the exception cannot outlive the fix.
|
|
57
|
-
KNOWN_DIAGRAM_GAPS = {} # #38 closed: Issue Reviewer is in the SVG and the Excalidraw source.
|
|
58
|
-
SKILL_ROW = re.compile(r'^\| \[([^\]]+)\]\(skills/([^/]+)/SKILL\.md\)', re.M)
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
def diagram_sources(root):
|
|
62
|
-
readme, agents = root / 'README.md', root / 'AGENTS.md'
|
|
63
|
-
svg = root / 'docs/diagrams/skill-workflow.svg'
|
|
64
|
-
excalidraw = root / 'docs/diagrams/skill-workflow.excalidraw'
|
|
65
|
-
if not all(path.is_file() for path in (readme, agents, svg, excalidraw)):
|
|
66
|
-
return None
|
|
67
|
-
readme_text = readme.read_text(encoding='utf-8')
|
|
68
|
-
mermaid = re.search(r'```mermaid\n(.*?)```', readme_text, re.S)
|
|
69
|
-
handoffs = re.search(r'## Skill handoffs\s+```text\n(.*?)```', agents.read_text(encoding='utf-8'), re.S)
|
|
70
|
-
svg_text = html.unescape(' '.join(re.findall(r'>([^<>]+)<', svg.read_text(encoding='utf-8'))))
|
|
71
|
-
try:
|
|
72
|
-
elements = json.loads(excalidraw.read_text(encoding='utf-8')).get('elements', [])
|
|
73
|
-
except ValueError:
|
|
74
|
-
elements = []
|
|
75
|
-
ex_text = ' '.join(e.get('text', '') for e in elements if isinstance(e, dict) and e.get('type') == 'text')
|
|
76
|
-
return readme_text, {
|
|
77
|
-
'mermaid': mermaid.group(1) if mermaid else '',
|
|
78
|
-
'agents': handoffs.group(1) if handoffs else '',
|
|
79
|
-
'svg': svg_text,
|
|
80
|
-
'excalidraw': ex_text,
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
def check_diagram(root, errors):
|
|
85
|
-
loaded = diagram_sources(root)
|
|
86
|
-
if loaded is None:
|
|
87
|
-
return
|
|
88
|
-
readme_text, sources = loaded
|
|
89
|
-
names = {slug: name for name, slug in SKILL_ROW.findall(readme_text)}
|
|
90
|
-
skills_dir = root / 'skills'
|
|
91
|
-
for entry in sorted(p for p in skills_dir.iterdir() if (p / 'SKILL.md').is_file()):
|
|
92
|
-
slug = entry.name
|
|
93
|
-
if slug not in names:
|
|
94
|
-
errors.append(f'README.md: skill {slug} is missing from the skill table')
|
|
95
|
-
continue
|
|
96
|
-
labels = (names[slug].lower(), slug, *(a.lower() for a in DIAGRAM_ALIASES.get(slug, ())))
|
|
97
|
-
for source, text in sources.items():
|
|
98
|
-
found = any(label in text.lower() for label in labels)
|
|
99
|
-
gap = KNOWN_DIAGRAM_GAPS.get((slug, source))
|
|
100
|
-
if not found and not gap:
|
|
101
|
-
errors.append(f'diagram drift: {slug} ({names[slug]}) is missing from the {source} workflow')
|
|
102
|
-
elif found and gap:
|
|
103
|
-
errors.append(f'diagram drift: stale known gap {slug}/{source} ({gap}); remove it from KNOWN_DIAGRAM_GAPS')
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
def check_catalog(root, errors):
|
|
107
|
-
"""Validate catalog shape and protocol paths; return its purposes (or None if absent)."""
|
|
108
|
-
path = root / CATALOG
|
|
109
|
-
if not path.is_file():
|
|
110
|
-
return None
|
|
111
|
-
try:
|
|
112
|
-
catalog = json.loads(path.read_text(encoding='utf-8'))
|
|
113
|
-
except ValueError as exc:
|
|
114
|
-
errors.append(f'{CATALOG}: invalid JSON ({exc})')
|
|
115
|
-
return set()
|
|
116
|
-
tools = catalog.get('tools') if isinstance(catalog, dict) else None
|
|
117
|
-
if not isinstance(tools, list) or not tools:
|
|
118
|
-
errors.append(f'{CATALOG}: "tools" must be a non-empty array')
|
|
119
|
-
return set()
|
|
120
|
-
purposes, ids = set(), set()
|
|
121
|
-
for index, tool in enumerate(tools):
|
|
122
|
-
where = f'{CATALOG}: tools[{index}]'
|
|
123
|
-
if not isinstance(tool, dict) or not isinstance(tool.get('id'), str) or not tool['id']:
|
|
124
|
-
errors.append(f'{where}: missing string id')
|
|
125
|
-
continue
|
|
126
|
-
if tool['id'] in ids:
|
|
127
|
-
errors.append(f'{where}: duplicate tool id {tool["id"]}')
|
|
128
|
-
ids.add(tool['id'])
|
|
129
|
-
listed = tool.get('purposes')
|
|
130
|
-
if not isinstance(listed, list) or not listed or not all(isinstance(p, str) and p for p in listed):
|
|
131
|
-
errors.append(f'{where}: purposes must be a non-empty array of strings')
|
|
132
|
-
listed = []
|
|
133
|
-
for purpose in listed:
|
|
134
|
-
if purpose in purposes:
|
|
135
|
-
errors.append(f'{where}: purpose {purpose} is listed more than once')
|
|
136
|
-
purposes.add(purpose)
|
|
137
|
-
if not isinstance(tool.get('scope'), str) or not tool['scope'].strip():
|
|
138
|
-
errors.append(f'{where}: missing scope')
|
|
139
|
-
for proto in tool.get('protocols') or []:
|
|
140
|
-
if not (path.parent / proto).is_file():
|
|
141
|
-
errors.append(f'{where}: protocol {proto} does not resolve')
|
|
142
|
-
return purposes
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
def check_cited_purposes(root, purposes, errors):
|
|
146
|
-
verbs = {purpose.split('-', 1)[0] for purpose in purposes}
|
|
147
|
-
for md in markdown_files(root):
|
|
148
|
-
for match in CITED_ID.finditer(md.read_text(encoding='utf-8')):
|
|
149
|
-
cited = match.group(1)
|
|
150
|
-
if cited.split('-', 1)[0] in verbs and cited not in purposes:
|
|
151
|
-
errors.append(f'{md.relative_to(root)}: purpose `{cited}` is not in the Tool Depot catalog')
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
def parse_frontmatter(text):
|
|
155
|
-
lines = text.splitlines()
|
|
156
|
-
if not lines or lines[0].strip() != '---':
|
|
157
|
-
return None, 0, 'Missing opening --- frontmatter fence'
|
|
158
|
-
end_idx = None
|
|
159
|
-
for idx in range(1, len(lines)):
|
|
160
|
-
if lines[idx].strip() == '---':
|
|
161
|
-
end_idx = idx
|
|
162
|
-
break
|
|
163
|
-
if end_idx is None:
|
|
164
|
-
return None, 0, 'Missing closing --- frontmatter fence'
|
|
165
|
-
|
|
166
|
-
raw_block = '\n'.join(lines[1:end_idx])
|
|
167
|
-
frontmatter = {}
|
|
168
|
-
current_map = None
|
|
169
|
-
for line in lines[1:end_idx]:
|
|
170
|
-
if not line.strip() or line.lstrip().startswith('#'):
|
|
171
|
-
continue
|
|
172
|
-
if line.startswith(' ') and current_map is not None:
|
|
173
|
-
sub = line.strip()
|
|
174
|
-
if ':' not in sub:
|
|
175
|
-
return None, len(raw_block.encode('utf-8')), f'Invalid metadata entry: {sub}'
|
|
176
|
-
k, v = sub.split(':', 1)
|
|
177
|
-
frontmatter[current_map][k.strip()] = _unquote(v.strip())
|
|
178
|
-
continue
|
|
179
|
-
current_map = None
|
|
180
|
-
if ':' not in line:
|
|
181
|
-
return None, len(raw_block.encode('utf-8')), f'Invalid frontmatter line: {line}'
|
|
182
|
-
k, v = line.split(':', 1)
|
|
183
|
-
key = k.strip()
|
|
184
|
-
val = v.strip()
|
|
185
|
-
if val == '':
|
|
186
|
-
frontmatter[key] = {}
|
|
187
|
-
current_map = key
|
|
188
|
-
else:
|
|
189
|
-
frontmatter[key] = _unquote(val)
|
|
190
|
-
return frontmatter, len(raw_block.encode('utf-8')), None
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
def _unquote(val):
|
|
194
|
-
if len(val) >= 2 and ((val[0] == '"' and val[-1] == '"') or (val[0] == "'" and val[-1] == "'")):
|
|
195
|
-
return val[1:-1]
|
|
196
|
-
return val
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
def _csv_items(value):
|
|
200
|
-
if not isinstance(value, str) or not value.strip():
|
|
201
|
-
return []
|
|
202
|
-
return [item.strip() for item in value.split(',') if item.strip()]
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
def license_spdx(root):
|
|
206
|
-
"""SPDX id of the root LICENSE: None if there is none, '' if it is not recognised."""
|
|
207
|
-
path = Path(root) / 'LICENSE'
|
|
208
|
-
if not path.is_file():
|
|
209
|
-
return None
|
|
210
|
-
text = path.read_text(encoding='utf-8', errors='replace')
|
|
211
|
-
if 'Apache License' in text and 'Version 2.0' in text:
|
|
212
|
-
return 'Apache-2.0'
|
|
213
|
-
if 'MIT License' in text or 'Permission is hereby granted, free of charge' in text:
|
|
214
|
-
return 'MIT'
|
|
215
|
-
return ''
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
GOVERNANCE_DOCS = ('SECURITY.md', 'SUPPORT.md', 'CONTRIBUTING.md')
|
|
219
|
-
EMAIL = re.compile(r'[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}')
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
def profile_identifiers(root):
|
|
223
|
-
"""Map each identifier declared by a profile (commands/<name>/profile-identifiers.txt) to its profile."""
|
|
224
|
-
found = {}
|
|
225
|
-
for path in sorted((Path(root) / 'commands').glob('*/profile-identifiers.txt')):
|
|
226
|
-
for line in path.read_text(encoding='utf-8').splitlines():
|
|
227
|
-
word = line.split('#', 1)[0].strip()
|
|
228
|
-
if word:
|
|
229
|
-
found[word.lower()] = path.parent.name
|
|
230
|
-
return found
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
def core_files(root):
|
|
234
|
-
"""skills/ and every command that is not a profile (no profile-identifiers.txt)."""
|
|
235
|
-
root = Path(root)
|
|
236
|
-
bases = [root / 'skills']
|
|
237
|
-
commands_dir = root / 'commands'
|
|
238
|
-
if commands_dir.is_dir():
|
|
239
|
-
for entry in sorted(commands_dir.iterdir()):
|
|
240
|
-
if entry.is_dir() and not (entry / 'profile-identifiers.txt').is_file():
|
|
241
|
-
bases.append(entry)
|
|
242
|
-
for base in bases:
|
|
243
|
-
for path in sorted(base.rglob('*')) if base.is_dir() else ():
|
|
244
|
-
if path.is_file():
|
|
245
|
-
yield path
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
def check_core_generic(root, errors):
|
|
249
|
-
"""#61: profile identifiers never appear in the core. One regex pass per file: O(total bytes)."""
|
|
250
|
-
ids = profile_identifiers(root)
|
|
251
|
-
if not ids:
|
|
252
|
-
return
|
|
253
|
-
words = '|'.join(re.escape(w) for w in sorted(ids, key=len, reverse=True))
|
|
254
|
-
leak = re.compile(rf'(?<![A-Za-z0-9])(?:{words})(?![A-Za-z0-9])', re.I)
|
|
255
|
-
for path in core_files(root):
|
|
256
|
-
text = path.read_text(encoding='utf-8', errors='replace')
|
|
257
|
-
for hit in sorted({m.group(0).lower() for m in leak.finditer(text)}):
|
|
258
|
-
errors.append(f'{path.relative_to(root).as_posix()}: contains {hit!r}, an identifier of the '
|
|
259
|
-
f'{ids[hit]} profile; the core must stay generic')
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
SEMVER = re.compile(r'(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)'
|
|
263
|
-
r'(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?', re.ASCII)
|
|
264
|
-
CHANGELOG_ENTRY = re.compile(r'^## \[([^\]]+)\]', re.M)
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
def package_version(root):
|
|
268
|
-
path = Path(root) / 'VERSION'
|
|
269
|
-
return path.read_text(encoding='utf-8').strip() if path.is_file() else None
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
def check_version(root, errors):
|
|
273
|
-
"""#62: VERSION is SemVer and the newest CHANGELOG entry (after Unreleased) is that version."""
|
|
274
|
-
version = package_version(root)
|
|
275
|
-
if version is None:
|
|
276
|
-
errors.append('VERSION: missing; a licensed package declares its SemVer version')
|
|
277
|
-
return
|
|
278
|
-
if not SEMVER.fullmatch(version):
|
|
279
|
-
errors.append(f'VERSION: {version!r} is not SemVer (MAJOR.MINOR.PATCH)')
|
|
280
|
-
changelog = Path(root) / 'CHANGELOG.md'
|
|
281
|
-
if not changelog.is_file():
|
|
282
|
-
errors.append('CHANGELOG.md: missing; every version needs a changelog entry')
|
|
283
|
-
return
|
|
284
|
-
entries = [e for e in CHANGELOG_ENTRY.findall(changelog.read_text(encoding='utf-8'))
|
|
285
|
-
if e.lower() != 'unreleased']
|
|
286
|
-
if not entries or entries[0] != version:
|
|
287
|
-
newest = entries[0] if entries else 'none'
|
|
288
|
-
errors.append(f'CHANGELOG.md: newest entry is {newest!r}, but VERSION is {version!r}')
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
def check_governance(root, spdx, errors):
|
|
292
|
-
"""#63: a licensed (distributed) package ships its policies, without personal contacts."""
|
|
293
|
-
if spdx is None:
|
|
294
|
-
return
|
|
295
|
-
for name in GOVERNANCE_DOCS:
|
|
296
|
-
path = Path(root) / name
|
|
297
|
-
if not path.is_file():
|
|
298
|
-
errors.append(f'{name}: missing; a licensed package must ship it')
|
|
299
|
-
elif EMAIL.search(path.read_text(encoding='utf-8', errors='replace')):
|
|
300
|
-
errors.append(f'{name}: contains an e-mail address; use the GitHub channels, no personal contact data')
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
def validate_repo(root):
|
|
304
|
-
root = Path(root)
|
|
305
|
-
errors = []
|
|
306
|
-
spdx = license_spdx(root)
|
|
307
|
-
checked = 0
|
|
308
|
-
total_frontmatter_bytes = 0
|
|
309
|
-
|
|
310
|
-
for group in ('skills', 'commands'):
|
|
311
|
-
group_dir = root / group
|
|
312
|
-
if not group_dir.is_dir():
|
|
313
|
-
continue
|
|
314
|
-
for entry in sorted(group_dir.iterdir()):
|
|
315
|
-
if not entry.is_dir():
|
|
316
|
-
continue
|
|
317
|
-
skill_md = entry / 'SKILL.md'
|
|
318
|
-
if not skill_md.is_file():
|
|
319
|
-
errors.append(f'{group}/{entry.name}: missing SKILL.md')
|
|
320
|
-
continue
|
|
321
|
-
checked += 1
|
|
322
|
-
fm, fm_bytes, parse_err = parse_frontmatter(skill_md.read_text(encoding='utf-8'))
|
|
323
|
-
total_frontmatter_bytes += fm_bytes
|
|
324
|
-
if parse_err:
|
|
325
|
-
errors.append(f'{group}/{entry.name}: {parse_err}')
|
|
326
|
-
continue
|
|
327
|
-
|
|
328
|
-
# #59: every skill carries the package licence, matching LICENSE.
|
|
329
|
-
license_id = fm.get('license')
|
|
330
|
-
if spdx is not None and not license_id:
|
|
331
|
-
errors.append(f'{group}/{entry.name}: missing license (LICENSE is {spdx})')
|
|
332
|
-
elif spdx and license_id != spdx:
|
|
333
|
-
errors.append(f'{group}/{entry.name}: license {license_id!r} != LICENSE ({spdx})')
|
|
334
|
-
|
|
335
|
-
name = fm.get('name')
|
|
336
|
-
if name != entry.name:
|
|
337
|
-
errors.append(f'{group}/{entry.name}: frontmatter name {name!r} != folder name')
|
|
338
|
-
if not isinstance(fm.get('description'), str) or not fm['description'].strip():
|
|
339
|
-
errors.append(f'{group}/{entry.name}: missing description')
|
|
340
|
-
|
|
341
|
-
meta = fm.get('metadata')
|
|
342
|
-
if not isinstance(meta, dict):
|
|
343
|
-
errors.append(f'{group}/{entry.name}: metadata must be a YAML mapping')
|
|
344
|
-
continue
|
|
345
|
-
if not meta.get('author') or not meta.get('version'):
|
|
346
|
-
errors.append(f'{group}/{entry.name}: metadata requires author and version')
|
|
347
|
-
unknown = sorted(set(meta) - METADATA_KEYS)
|
|
348
|
-
if unknown:
|
|
349
|
-
errors.append(
|
|
350
|
-
f'{group}/{entry.name}: unknown metadata key(s) {unknown}; '
|
|
351
|
-
f'allowed: {sorted(METADATA_KEYS)}'
|
|
352
|
-
)
|
|
353
|
-
|
|
354
|
-
scripts_dir = entry / 'scripts'
|
|
355
|
-
actual_scripts = sorted(
|
|
356
|
-
f'scripts/{p.name}' for p in scripts_dir.iterdir() if p.is_file()
|
|
357
|
-
) if scripts_dir.is_dir() else []
|
|
358
|
-
declared_scripts = _csv_items(meta.get('scripts', ''))
|
|
359
|
-
|
|
360
|
-
if actual_scripts:
|
|
361
|
-
if not fm.get('compatibility'):
|
|
362
|
-
errors.append(f'{group}/{entry.name}: scripted skill missing compatibility field')
|
|
363
|
-
if sorted(declared_scripts) != actual_scripts:
|
|
364
|
-
errors.append(
|
|
365
|
-
f'{group}/{entry.name}: metadata.scripts {declared_scripts} != disk {actual_scripts}'
|
|
366
|
-
)
|
|
367
|
-
elif declared_scripts:
|
|
368
|
-
errors.append(f'{group}/{entry.name}: metadata.scripts declared without scripts/ files')
|
|
369
|
-
|
|
370
|
-
for rel in declared_scripts:
|
|
371
|
-
if not (entry / rel).is_file():
|
|
372
|
-
errors.append(f'{group}/{entry.name}: missing declared script {rel}')
|
|
373
|
-
|
|
374
|
-
adapters_dir = entry / 'adapters'
|
|
375
|
-
actual_adapters = sorted(
|
|
376
|
-
f'adapters/{p.name}' for p in adapters_dir.iterdir() if p.is_file()
|
|
377
|
-
) if adapters_dir.is_dir() else []
|
|
378
|
-
declared_adapters = _csv_items(meta.get('adapters', ''))
|
|
379
|
-
|
|
380
|
-
if actual_adapters:
|
|
381
|
-
if sorted(declared_adapters) != actual_adapters:
|
|
382
|
-
errors.append(
|
|
383
|
-
f'{group}/{entry.name}: metadata.adapters {declared_adapters} != disk {actual_adapters}'
|
|
384
|
-
)
|
|
385
|
-
if not meta.get('post_install'):
|
|
386
|
-
errors.append(f'{group}/{entry.name}: command with adapters missing metadata.post_install')
|
|
387
|
-
elif declared_adapters:
|
|
388
|
-
errors.append(f'{group}/{entry.name}: metadata.adapters declared without adapters/ files')
|
|
389
|
-
|
|
390
|
-
# Hooks are instructions, not executed code; the least CI can do is make
|
|
391
|
-
# sure every bundled file they name exists (#40).
|
|
392
|
-
for key in ('pre_hook', 'post_hook', 'post_install'):
|
|
393
|
-
for rel in HOOK_FILE.findall(str(meta.get(key) or '')):
|
|
394
|
-
if not (entry / rel).is_file():
|
|
395
|
-
errors.append(f'{group}/{entry.name}: metadata.{key} names missing file {rel}')
|
|
396
|
-
|
|
397
|
-
if group == 'skills' and entry.name == 'question-gate':
|
|
398
|
-
if not meta.get('pre_hook') or not meta.get('post_hook'):
|
|
399
|
-
errors.append('skills/question-gate: must declare metadata.pre_hook and metadata.post_hook')
|
|
400
|
-
|
|
401
|
-
check_governance(root, spdx, errors)
|
|
402
|
-
check_core_generic(root, errors)
|
|
403
|
-
if spdx is not None:
|
|
404
|
-
check_version(root, errors)
|
|
405
|
-
check_links(root, errors)
|
|
406
|
-
check_diagram(root, errors)
|
|
407
|
-
purposes = check_catalog(root, errors)
|
|
408
|
-
if purposes:
|
|
409
|
-
check_cited_purposes(root, purposes, errors)
|
|
410
|
-
|
|
411
|
-
if total_frontmatter_bytes > ZED_CATALOG_LIMIT_BYTES:
|
|
412
|
-
errors.append(
|
|
413
|
-
f'Aggregate frontmatter {total_frontmatter_bytes} bytes exceeds Zed {ZED_CATALOG_LIMIT_BYTES} byte limit'
|
|
414
|
-
)
|
|
415
|
-
|
|
416
|
-
return {
|
|
417
|
-
'verdict': 'pass' if not errors else 'fail',
|
|
418
|
-
'checked': checked,
|
|
419
|
-
'frontmatter_bytes': total_frontmatter_bytes,
|
|
420
|
-
'errors': errors,
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
def main(argv):
|
|
425
|
-
if argv and argv[0] in ('-h', '--help'):
|
|
426
|
-
print(HELP)
|
|
427
|
-
return 0
|
|
428
|
-
tag = None
|
|
429
|
-
if len(argv) >= 2 and argv[-2] == '--release-tag':
|
|
430
|
-
tag, argv = argv[-1], argv[:-2]
|
|
431
|
-
root = Path(argv[0]) if argv else Path(__file__).resolve().parents[3]
|
|
432
|
-
report = validate_repo(root)
|
|
433
|
-
if tag is not None:
|
|
434
|
-
# #62: a release tag must name exactly the version the package declares.
|
|
435
|
-
version = package_version(root)
|
|
436
|
-
if version is None or tag != f'v{version}':
|
|
437
|
-
report['errors'].append(f'release tag {tag!r} does not match VERSION {version!r} (expected v<VERSION>)')
|
|
438
|
-
report['verdict'] = 'fail'
|
|
439
|
-
print(json.dumps(report, indent=2))
|
|
440
|
-
return 0 if report['verdict'] == 'pass' else 1
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
if __name__ == '__main__':
|
|
444
|
-
sys.exit(main(sys.argv[1:]))
|