Repository navigation
Expand file tree
/
Copy pathbuild-release.py
More file actions
181 lines (159 loc) · 8.81 KB
/
Copy pathbuild-release.py
File metadata and controls
181 lines (159 loc) · 8.81 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
"""Build and check the release ZIPs, one per directory, into dist/.
python3 scripts/build-release.py [out_dir]
- ccxt-openai-<version>.zip: chatgpt/ccxt for upload at platform.openai.com/plugins. OpenAI
refuses packages with app references, and its directory turned down the coding skills
("not suitable for broad discovery"), so the ZIP leaves out .app.json, the "apps" field and
every skill but the usage skill, drops the sentence about coding skills from the description,
and uses release/openai/README.md as its README.
- ccxt-claude-<version>.zip and ccxt-local-claude-<version>.zip: the Claude plugins as they
are (Claude's "Upload plugin", or a manual install).
Fails, writing nothing it would not stand behind, when a ZIP breaks a rule we know of. The
rules are from https://developers.openai.com/plugins/deploy/submission; recheck them there.
"""
import io
import json
import os
import re
import sys
import zipfile
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
OUT = os.path.abspath(sys.argv[1] if len(sys.argv) > 1 else os.path.join(ROOT, 'dist'))
CODING_SENTENCE = re.compile(r' Plus skills for writing code with the CCXT library in [^.]*\.')
SKIP = {'.DS_Store'}
errors = []
def fail(message):
errors.append(message)
print('::error::' + message)
def files_under(directory):
for base, dirs, names in os.walk(directory):
dirs.sort()
for name in sorted(names):
if name not in SKIP:
path = os.path.join(base, name)
yield path, os.path.relpath(path, directory)
def write_zip(path, entries):
# entries: (name in zip, bytes); fixed timestamps so the same input gives the same ZIP
with zipfile.ZipFile(path, 'w', zipfile.ZIP_DEFLATED) as archive:
for name, data in sorted(entries):
info = zipfile.ZipInfo(name, date_time=(1980, 1, 1, 0, 0, 0))
info.external_attr = 0o644 << 16
info.compress_type = zipfile.ZIP_DEFLATED
archive.writestr(info, data)
print(f'{os.path.relpath(path, ROOT)}: {len(entries)} files')
for name, data in sorted(entries):
print(f' {len(data):>8} {name}')
def read(path):
with open(path, 'rb') as handle:
return handle.read()
def png_size(data):
if data[:8] != b'\x89PNG\r\n\x1a\n':
return None
return int.from_bytes(data[16:20], 'big'), int.from_bytes(data[20:24], 'big')
def check_openai(entries):
files = dict(entries)
plugin = json.loads(files['plugin.json'])
mcp = json.loads(files['mcp.json'])
try:
import jsonschema
for name, document in (('plugin', plugin), ('mcp', mcp)):
with open(os.path.join(ROOT, 'scripts', 'schemas', f'agent-plugins-1.0.0-{name}.schema.json')) as handle:
for problem in jsonschema.Draft202012Validator(json.load(handle)).iter_errors(document):
fail(f'openai {name}.json: {problem.message} at {list(problem.absolute_path)}')
except ImportError:
fail('pip install jsonschema to check the OpenAI manifests against their schemas')
if any(name in ('.app.json', 'hooks.json') or name.startswith('hooks/') for name in files):
fail('openai: app references or hooks in the ZIP')
openai = plugin.get('extensions', {}).get('com.openai', {})
if 'apps' in openai:
fail('openai: extensions.com.openai.apps is set (OpenAI refuses app references)')
if not re.fullmatch(r'[a-z0-9]+(-[a-z0-9]+)*', plugin.get('name', '')) or len(plugin['name']) > 64:
fail('openai: name must be lowercase letters, numbers and single hyphens, at most 64 characters')
if not re.fullmatch(r'\d+\.\d+\.\d+', plugin.get('version', '')):
fail('openai: version must be an explicit x.y.z')
if CODING_SENTENCE.search(plugin.get('description', '')) or 'coding skill' in plugin.get('description', ''):
fail('openai: the description still mentions the coding skills the ZIP leaves out')
if len(plugin.get('keywords', [])) > 25:
fail('openai: more than 25 keywords')
servers = mcp.get('mcpServers', {})
if len(servers) != 1:
fail(f'openai: {len(servers)} MCP servers; exactly one can be connected per plugin')
for key, server in servers.items():
if not str(server.get('url', '')).startswith('https://') or server.get('headers'):
fail(f'openai: MCP server {key} needs an https url and no headers')
interface = openai.get('interface', {})
for field, limit in (('displayName', 30), ('shortDescription', 30), ('longDescription', 4000), ('developerName', 80)):
value = interface.get(field, '')
if not value or len(value) > limit:
fail(f'openai: interface.{field} is required, at most {limit} characters (has {len(value)})')
if not interface.get('category'):
fail('openai: interface.category is required')
for field in ('websiteURL', 'supportURL', 'privacyPolicyURL', 'termsOfServiceURL'):
if not str(interface.get(field, '')).startswith('https://'):
fail(f'openai: interface.{field} must be an https URL (all four are required for MCP review)')
prompts = interface.get('defaultPrompt', [])
prompts = [prompts] if isinstance(prompts, str) else prompts
if len(prompts) > 3 or any(len(p) > 128 or '@' in p for p in prompts) or len(set(prompts)) != len(prompts):
fail('openai: at most 3 unique starter prompts, 128 characters each, without @mentions')
capabilities = interface.get('capabilities', [])
if len(capabilities) > 20 or any(len(c) > 120 for c in capabilities):
fail('openai: at most 20 capabilities of 120 characters')
for field in ('logo', 'composerIcon', 'logoDark', 'composerIconDark'):
path = interface.get(field)
if path is None:
if field == 'logo':
fail('openai: interface.logo is required for submission')
continue
name = path[2:] if path.startswith('./') else path
if name not in files:
fail(f'openai: interface.{field} points at {path}, which is not in the ZIP')
elif len(files[name]) > 5 * 1024 * 1024:
fail(f'openai: {name} is over 5 MiB')
elif name.endswith('.png'):
size = png_size(files[name])
if size is None or size[0] != size[1] or size[0] < 48 or size[0] > 4096:
fail(f'openai: {name} must be a square PNG of 48 to 4096 pixels (is {size})')
review = openai.get('review', {})
cases = review.get('test_cases', {})
positive, negative = cases.get('positive', []), cases.get('negative', [])
if len(positive) != 5 or len(negative) != 3:
fail(f'openai: initial MCP review needs exactly 5 positive and 3 negative cases (has {len(positive)} and {len(negative)})')
for case in positive:
for field in ('description', 'prompt', 'tools_triggered', 'expected_behavior'):
if not case.get(field):
fail(f'openai: positive case "{case.get("description")}" has no {field}')
for case in negative:
for field in ('description', 'prompt'):
if not case.get(field):
fail(f'openai: negative case has no {field}')
for field in ('test_credentials', 'reviewer_instructions'):
if field in review:
fail(f'openai: review.{field} is not allowed in the ZIP (use the dashboard form)')
skills = sorted({name.split('/')[1] for name in files if name.startswith('skills/')})
if skills != ['ccxt']:
fail(f'openai: expected only the ccxt usage skill, found {skills}')
def build_openai():
source = os.path.join(ROOT, 'chatgpt', 'ccxt')
plugin = json.loads(read(os.path.join(source, 'plugin.json')))
plugin['extensions']['com.openai'].pop('apps', None)
plugin['description'] = CODING_SENTENCE.sub('', plugin['description'])
entries = [('plugin.json', (json.dumps(plugin, indent=2, ensure_ascii=False) + '\n').encode())]
entries.append(('README.md', read(os.path.join(ROOT, 'release', 'openai', 'README.md'))))
for path, name in files_under(source):
if name in ('plugin.json', 'README.md', '.app.json'):
continue
if name.startswith('skills/') and not name.startswith('skills/ccxt/'):
continue
entries.append((name, read(path)))
check_openai(entries)
return f'ccxt-openai-{plugin["version"]}.zip', entries
def build_claude(directory, label):
source = os.path.join(ROOT, 'claude', directory)
version = json.loads(read(os.path.join(source, '.claude-plugin', 'plugin.json')))['version']
entries = [(name, read(path)) for path, name in files_under(source)]
return f'{label}-{version}.zip', entries
os.makedirs(OUT, exist_ok=True)
builds = [build_openai(), build_claude('ccxt', 'ccxt-claude'), build_claude('ccxt-local', 'ccxt-local-claude')]
if errors:
sys.exit(f'{len(errors)} problem(s); no ZIP written')
for name, entries in builds:
write_zip(os.path.join(OUT, name), entries)