Repository navigation
Expand file tree
/
Copy pathvalidate-package.py
More file actions
executable file
·227 lines (204 loc) · 7.88 KB
/
Copy pathvalidate-package.py
File metadata and controls
executable file
·227 lines (204 loc) · 7.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#!/usr/bin/env python3
from __future__ import annotations
import ast
import json
import re
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
SKILL = ROOT / "SKILL.md"
REQUIRED_FILES = [
"SKILL.md",
"reference/command-protocol.md",
"reference/decomposition.md",
"reference/dashboard.md",
"reference/design-gate.md",
"reference/guide-quality.md",
"reference/pitfall-journal.md",
"reference/recovery.md",
"reference/review-rubric.md",
"reference/state-model.md",
"reference/takeover.md",
"templates/config.yaml",
"templates/design.md",
"templates/manifest.yaml",
"templates/notes.md",
"templates/pitfalls.yaml",
"templates/progress.yaml",
"templates/session-summary.md",
"templates/takeover-operation.yaml",
"schemas/README.md",
"schemas/config.schema.json",
"schemas/manifest.schema.json",
"schemas/progress.schema.json",
"schemas/pitfalls.schema.json",
"schemas/takeover-operation.schema.json",
"schemas/session.schema.json",
"examples/example-session.md",
"adapters/README.md",
"adapters/codex.md",
"adapters/claude-code.md",
"adapters/opencode.md",
"adapters/github-copilot.md",
"adapters/gemini-cli.md",
"adapters/cursor.md",
"scripts/check-guide.py",
"scripts/install.sh",
"scripts/install.ps1",
"scripts/dashboard/__init__.py",
"scripts/dashboard/main.py",
"scripts/dashboard/model.py",
"scripts/dashboard/collector.py",
"scripts/dashboard/renderer.py",
"scripts/dashboard/export.py",
"scripts/dashboard/watch.py",
"scripts/dashboard/state.py",
"scripts/dashboard/sessions.py",
"scripts/dashboard/insights.py",
"scripts/dashboard/workspace.py",
"scripts/dashboard/README.md",
"scripts/dashboard/requirements.txt",
]
COMMANDS = [
"plan", "next", "review", "hint", "explain",
"show", "take", "challenge", "status", "dashboard", "rebase-plan",
]
SCHEMA_FILES = [
"schemas/session.schema.json",
"schemas/config.schema.json",
"schemas/manifest.schema.json",
"schemas/progress.schema.json",
"schemas/pitfalls.schema.json",
"schemas/takeover-operation.schema.json",
]
VERSIONED_TEMPLATES = [
"templates/session-summary.md",
"templates/config.yaml",
"templates/manifest.yaml",
"templates/progress.yaml",
"templates/pitfalls.yaml",
"templates/takeover-operation.yaml",
]
def fail(message: str) -> None:
print(f"ERROR: {message}", file=sys.stderr)
raise SystemExit(1)
for rel in REQUIRED_FILES:
if not (ROOT / rel).is_file():
fail(f"missing required file: {rel}")
text = SKILL.read_text(encoding="utf-8")
if not text.startswith("---\n"):
fail("SKILL.md must start with YAML frontmatter")
end = text.find("\n---\n", 4)
if end < 0:
fail("SKILL.md frontmatter is not closed")
frontmatter = text[4:end]
name_match = re.search(r"(?m)^name:\s*([^\n]+)$", frontmatter)
if not name_match:
fail("frontmatter is missing name")
name = name_match.group(1).strip().strip("'\"")
if not re.fullmatch(r"[a-z0-9]+(?:-[a-z0-9]+)*", name):
fail(f"skill name is not portable kebab-case: {name}")
if name != "pair-programming":
fail(f"unexpected skill name: {name}")
version_match = re.search(r'(?m)^\s{2}version:\s*["\']?([^"\'\n]+)', frontmatter)
if not version_match:
fail("metadata.version is missing")
version = version_match.group(1).strip()
if not re.fullmatch(r"(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)", version):
fail(f"metadata.version is not MAJOR.MINOR.PATCH: {version}")
description_match = re.search(
r"(?ms)^description:\s*>\s*\n(?P<body>(?:^[ \t]+.*\n?)+)",
frontmatter,
)
if not description_match:
fail("frontmatter must contain a folded description")
description = " ".join(
line.strip() for line in description_match.group("body").splitlines()
).strip()
if not description:
fail("description is empty")
if len(description) > 1024:
fail(f"description exceeds 1024 characters: {len(description)}")
if "compatibility:" not in frontmatter:
fail("frontmatter is missing compatibility")
if 'opencode/slash: "true"' not in frontmatter:
fail('frontmatter must expose the skill in OpenCode slash catalog')
for required_reference in (
"reference/command-protocol.md",
"reference/dashboard.md",
"reference/design-gate.md",
"reference/decomposition.md",
"reference/guide-quality.md",
"reference/pitfall-journal.md",
"reference/recovery.md",
"reference/review-rubric.md",
"reference/state-model.md",
"reference/takeover.md",
".pair/operations/",
):
if required_reference not in text:
fail(f"SKILL.md is missing routed workflow reference: {required_reference}")
example = (ROOT / "examples/example-session.md").read_text(encoding="utf-8")
protocol = (ROOT / "reference/command-protocol.md").read_text(encoding="utf-8")
for command in COMMANDS:
semantic = f"/pair {command}"
if semantic not in text:
fail(f"SKILL.md is missing semantic command: {semantic}")
if semantic not in example:
fail(f"example session is missing command coverage: {semantic}")
if f"| `{semantic}` |" not in text:
fail(f"SKILL.md is missing command dispatch route: {semantic}")
if f"## `{semantic}" not in protocol:
fail(f"command protocol is missing command contract: {semantic}")
for invocation in ("$pair-programming plan", "/pair-programming plan"):
if invocation not in text:
fail(f"SKILL.md is missing host invocation example: {invocation}")
for rel in VERSIONED_TEMPLATES:
template = (ROOT / rel).read_text(encoding="utf-8")
if not re.search(r"(?m)^schema_version:\s*1\s*$", template):
fail(f"{rel} must declare schema_version: 1")
if re.search(r"(?m)^version:\s*1\s*$", template):
fail(f"{rel} still uses legacy top-level version: 1")
for rel in SCHEMA_FILES:
try:
schema = json.loads((ROOT / rel).read_text(encoding="utf-8"))
except json.JSONDecodeError as exc:
fail(f"invalid JSON schema {rel}: {exc}")
if schema.get("$schema") != "https://json-schema.org/draft/2020-12/schema":
fail(f"{rel} must use JSON Schema draft 2020-12")
if not schema.get("$id"):
fail(f"{rel} is missing $id")
properties = schema.get("properties", {})
schema_version = properties.get("schema_version", {})
if schema_version.get("const") != 1:
fail(f"{rel} must pin schema_version to 1")
for rel in ["scripts/validate-package.py", "scripts/check-guide.py"] + [
str(path.relative_to(ROOT)) for path in sorted((ROOT / "scripts/dashboard").glob("*.py"))
]:
try:
ast.parse((ROOT / rel).read_text(encoding="utf-8"), filename=rel)
except SyntaxError as exc:
fail(f"python syntax error in {rel}: {exc}")
install_sh = (ROOT / "scripts/install.sh").read_text(encoding="utf-8")
install_ps = (ROOT / "scripts/install.ps1").read_text(encoding="utf-8")
for platform in (
"portable", "codex", "cursor", "gemini-cli",
"github-copilot", "claude-code", "opencode",
):
if platform not in install_sh:
fail(f"install.sh is missing platform: {platform}")
if platform not in install_ps:
fail(f"install.ps1 is missing platform: {platform}")
for runtime_component in ("schemas", "check-guide.py", "scripts/dashboard", "requirements.txt"):
if runtime_component not in install_sh:
fail(f"install.sh does not package runtime component: {runtime_component}")
if runtime_component not in install_ps:
fail(f"install.ps1 does not package runtime component: {runtime_component}")
print("pair-programming package validation passed")
print(f" skill: {name}")
print(f" version: {version}")
print(f" description chars: {len(description)}")
print(" state schema version: 1")
print(f" schemas checked: {len(SCHEMA_FILES)}")
print(" adapters: codex, cursor, gemini-cli, github-copilot, claude-code, opencode")
print(f" semantic commands checked: {len(COMMANDS)}")