Skip to content

Editorial diagram design for Claude Code, Codex, GitHub Copilot, Cursor, Factory Droid, Qoder, and Pi. 45 diagram types. Self-contained HTML + SVG. No shadows. No Mermaid slop.

fix(package): give the upload ZIP a root plugin.json and proper entry types (#265)

Cathryn Laverybd4506eeef30
diff --git a/scripts/build-openai-plugin-zip.py b/scripts/build-openai-plugin-zip.py
index f444057..2c22c61 100755
--- a/scripts/build-openai-plugin-zip.py
+++ b/scripts/build-openai-plugin-zip.py
@@ -27,6 +27,7 @@ import argparse
import io
import json
import re
+import stat
import struct
import subprocess
import sys
@@ -58,7 +59,15 @@ REQUIRED_FILES = ("LICENSE",)
OPTIONAL_FILES = ("THIRD_PARTY_LICENSES.md", "PRIVACY.md")
FIXED_TIME = (1980, 1, 1, 0, 0, 0)
UNIX_HOST = 3
-SAFE_FILENAME_PART = re.compile(r"^[A-Za-z0-9][A-Za-z0-9._-]*$")
+SAFE_FILENAME_PART = re.compile(r"^[A-Za-z0-9][A-Za-z0-9._-]*\Z")
+# The upload reads package identity from a root plugin.json in the Agent Plugins
+# format, with OpenAI's listing fields under extensions["com.openai"]. That
+# schema rejects unknown top-level keys, so only these fields are copied.
+AGENT_PLUGINS_SCHEMA = "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json"
+AGENT_PLUGINS_NAME = re.compile(r"^(?!.*(?:--|\.\.))[a-z0-9](?:[a-z0-9.-]*[a-z0-9])?\Z")
+ROOT_MANIFEST_FIELDS = ("name", "version", "description", "author", "homepage", "repository", "license", "keywords")
+FILE_ATTRS = (stat.S_IFREG | 0o644) << 16
+DIR_ATTRS = (stat.S_IFDIR | 0o755) << 16 | 0x10 # 0x10 is the MS-DOS directory flag
def git(root: Path, *args: str, data: bytes | None = None) -> bytes:
@@ -218,6 +227,14 @@ def check_assets(
return assets
+def root_manifest(manifest: dict) -> bytes:
+ """The Agent Plugins plugin.json for the upload, derived from the Codex manifest."""
+ root = {"$schema": AGENT_PLUGINS_SCHEMA}
+ root.update({field: manifest[field] for field in ROOT_MANIFEST_FIELDS if field in manifest})
+ root["extensions"] = {"com.openai": {"interface": manifest["interface"]}}
+ return (json.dumps(root, indent=2, ensure_ascii=False) + "\n").encode("utf-8")
+
+
def fail(errors: list[str]) -> int:
print(f"build-openai-plugin-zip: {len(errors)} problem(s):", file=sys.stderr)
for error in errors:
@@ -253,6 +270,8 @@ def main() -> int:
if not isinstance(value, str) or not SAFE_FILENAME_PART.match(value):
errors.append(f"manifest {field} {value!r} is not a safe filename part")
+ if isinstance(manifest.get("name"), str) and not AGENT_PLUGINS_NAME.match(manifest["name"]):
+ errors.append(f"manifest name {manifest['name']!r} does not match the Agent Plugins name pattern")
check_listing(interface, errors)
asset_paths = declared_assets(interface, errors, pending)
@@ -306,15 +325,27 @@ def main() -> int:
out_dir = (args.out or root / "dist").resolve()
out_dir.mkdir(parents=True, exist_ok=True)
target = out_dir / f"{manifest['name']}-{manifest['version']}-openai.zip"
+ payload = dict(zip(files, contents))
+ payload["plugin.json"] = root_manifest(manifest)
+ directories = {
+ "/".join(path.split("/")[:depth]) + "/"
+ for path in payload
+ for depth in range(1, path.count("/") + 1)
+ }
with zipfile.ZipFile(target, "w", compression=zipfile.ZIP_DEFLATED) as archive:
- for path, data in zip(files, contents):
+ for path in sorted(set(payload) | directories):
info = zipfile.ZipInfo(path, date_time=FIXED_TIME)
- info.compress_type = zipfile.ZIP_DEFLATED
info.create_system = UNIX_HOST
- info.external_attr = 0o644 << 16
- archive.writestr(info, data)
+ if path in directories:
+ info.compress_type = zipfile.ZIP_STORED
+ info.external_attr = DIR_ATTRS
+ archive.writestr(info, b"")
+ else:
+ info.compress_type = zipfile.ZIP_DEFLATED
+ info.external_attr = FILE_ATTRS
+ archive.writestr(info, payload[path])
kind = "draft " if pending else ""
- print(f"OK built {kind}{target} ({len(files)} files, {target.stat().st_size:,} bytes)")
+ print(f"OK built {kind}{target} ({len(payload)} files, {target.stat().st_size:,} bytes)")
if pending:
print(f"Draft only: missing {', '.join(pending)}; do not submit this ZIP.")
return 0
diff --git a/scripts/test-build-openai-plugin-zip.py b/scripts/test-build-openai-plugin-zip.py
index 8fe6e3b..3a082d6 100755
--- a/scripts/test-build-openai-plugin-zip.py
+++ b/scripts/test-build-openai-plugin-zip.py
@@ -15,6 +15,7 @@ from __future__ import annotations
import hashlib
import json
import os
+import re
import struct
import subprocess
import sys
@@ -27,7 +28,8 @@ ROOT = Path(__file__).resolve().parent.parent
BUILDER = ROOT / "scripts" / "build-openai-plugin-zip.py"
ALLOWED_PREFIXES = (
- ".codex-plugin/plugin.json",
+ "plugin.json",
+ ".codex-plugin/",
"skills/",
"assets/",
"LICENSE",
@@ -165,6 +167,51 @@ def built_zip(out: Path) -> Path:
return zips[0]
+AGENT_PLUGINS_SCHEMA = "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json"
+ROOT_KEYS = {"$schema", "name", "version", "description", "author", "homepage", "repository", "license", "keywords", "extensions"}
+NAME_RE = r"^(?!.*(?:--|\.\.))[a-z0-9](?:[a-z0-9.-]*[a-z0-9])?\Z"
+
+
+def zip_structure_problems(path: Path) -> list[str]:
+ """Upload-format problems: root manifest shape, entry types, directory entries."""
+ import re
+ import stat
+
+ problems = []
+ archive = zipfile.ZipFile(path)
+ names = archive.namelist()
+ if "plugin.json" not in names:
+ return ["no root plugin.json"]
+ root = json.loads(archive.read("plugin.json"))
+ codex = json.loads(archive.read(".codex-plugin/plugin.json"))
+ if root.get("$schema") != AGENT_PLUGINS_SCHEMA:
+ problems.append("root $schema is not the Agent Plugins 1.0.0 schema")
+ extra = set(root) - ROOT_KEYS
+ if extra:
+ problems.append(f"root plugin.json has keys the schema rejects: {sorted(extra)}")
+ if not re.match(NAME_RE, root.get("name", "")):
+ problems.append("root name does not match the schema pattern")
+ for key in ("name", "version", "description", "author"):
+ if root.get(key) != codex.get(key):
+ problems.append(f"root {key} differs from the Codex manifest")
+ if root.get("extensions", {}).get("com.openai", {}).get("interface") != codex.get("interface"):
+ problems.append("root extensions.com.openai.interface differs from the Codex interface")
+ entries = set(names)
+ for info in archive.infolist():
+ mode = info.external_attr >> 16
+ if info.is_dir():
+ if not stat.S_ISDIR(mode):
+ problems.append(f"{info.filename} lacks the directory type bit")
+ elif not stat.S_ISREG(mode):
+ problems.append(f"{info.filename} lacks the regular-file type bit")
+ parts = info.filename.rstrip("/").split("/")[:-1]
+ for depth in range(1, len(parts) + 1):
+ parent = "/".join(parts[:depth]) + "/"
+ if parent not in entries:
+ problems.append(f"missing directory entry {parent}")
+ return sorted(set(problems))
+
+
def main() -> int:
failures: list[str] = []
passed = 0
@@ -192,7 +239,10 @@ def main() -> int:
if first.returncode == 0 and second.returncode == 0:
zip_a, zip_b = built_zip(out_a), built_zip(out_b)
names = zipfile.ZipFile(zip_a).namelist()
+ problems = zip_structure_problems(zip_a)
+ check("repo ZIP matches the upload format", not problems, "; ".join(problems[:5]))
for required in (
+ "plugin.json",
".codex-plugin/plugin.json",
"skills/diagram-design/SKILL.md",
"LICENSE",
@@ -238,6 +288,8 @@ def main() -> int:
check("complete fixture builds", result.returncode == 0, result.stdout + result.stderr)
if result.returncode == 0:
names = zipfile.ZipFile(built_zip(out)).namelist()
+ problems = zip_structure_problems(built_zip(out))
+ check("fixture ZIP matches the upload format", not problems, "; ".join(problems[:5]))
check("fixture ZIP has logo", "assets/logo.png" in names)
check("fixture ZIP has composer icon", "assets/icon.svg" in names)
check("fixture ZIP excludes untracked cache", not any("__pycache__" in n for n in names))
@@ -379,6 +431,14 @@ def main() -> int:
check("unsafe manifest name fails", result.returncode == 1, result.stdout + result.stderr)
check("unsafe manifest name writes nothing outside --out", not list(tmp.glob("escaped*")))
+ # Names outside the Agent Plugins pattern never reach the root manifest or the filename.
+ for label, bad_name in (("trailing-newline", "demo\n"), ("double-period", "a..b"), ("double-hyphen", "a--b"), ("uppercase", "Demo")):
+ root = fixture(tmp, f"name-{label}", interface(), logo=png(64, 64), manifest_overrides={"name": bad_name})
+ result = run("--root", str(root), "--check")
+ check(f"manifest name {label} fails", result.returncode == 1, result.stdout + result.stderr)
+ check("test name pattern rejects consecutive periods", re.match(NAME_RE, "a..b") is None)
+ check("test name pattern rejects a trailing newline", re.match(NAME_RE, "demo\n") is None)
+
# A manifest without a skills path would ship an empty plugin.
root = fixture(tmp, "no-skills", interface(), logo=png(64, 64), manifest_overrides={"skills": None})
result = run("--root", str(root), "--draft", "--out", str(tmp / "no-skills-out"))