#!/usr/bin/env python3 """Write manifest.json: every skill (a SKILL.md and the files beside it, plus the shared rules and steering) with its frontmatter and a sha256 digest and size per file, in the shape SEP-2640 `skills/list` returns. Servers (solnix.io/mcp) and clients can check a skill's files against it. tools/manifest.py # writes manifest.json at the repo root tools/manifest.py --check # exit 1 if manifest.json is stale The shared files include the data tables the MCP verbs read (solnix/rules/*.tsv). The manifest itself is not a signature: tools/sign-manifest signs it (manifest.json.sig) at release time, with a key only infra holds. Stdlib only. """ import hashlib, json, os, re, sys REPO = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) OUT = os.path.join(REPO, "manifest.json") def fm(text): head = text[4:].split("\n---\n", 1)[0] if text.startswith("---\n") else "" out, key = {}, None for line in head.splitlines(): m = re.match(r"^([a-zA-Z][\w-]*):\s*(.*)$", line) if m: key, v = m.group(1), m.group(2).strip() out[key] = "" if v in (">", "|", ">-", "|-") else v.strip("\"'") elif key and line.startswith(" ") and key in ("description",): out[key] = (out[key] + " " + line.strip()).strip() return {k: out[k] for k in ("name", "description") if k in out} def entry(path): b = open(path, "rb").read() return {"path": os.path.relpath(path, REPO), "digest": "sha256:" + hashlib.sha256(b).hexdigest(), "size": len(b)} def build(): skills = [] for root, _, files in sorted(os.walk(REPO)): if "/.git" in root or "/site" in root: continue if "SKILL.md" in files: p = os.path.join(root, "SKILL.md") meta = fm(open(p, encoding="utf-8").read()) rel = os.path.relpath(root, REPO) fs = [entry(os.path.join(root, f)) for f in sorted(files) if f.endswith(".md")] skills.append({"name": meta.get("name"), "description": meta.get("description"), "dir": rel, "files": fs}) shared = [] for d in ("solnix/rules", "steering", "workflows"): full = os.path.join(REPO, d) if os.path.isdir(full): shared += [entry(os.path.join(full, f)) for f in sorted(os.listdir(full)) if f.endswith((".md", ".tsv"))] return {"version": 1, "repo": "https://codeberg.org/solnix/skills", "skills": skills, "shared": shared} def main(): m = json.dumps(build(), indent=1, ensure_ascii=False) + "\n" if "--check" in sys.argv: cur = open(OUT, encoding="utf-8").read() if os.path.exists(OUT) else "" if cur != m: print("manifest.json is stale: run tools/manifest.py") sys.exit(1) print("manifest.json is current") return open(OUT, "w", encoding="utf-8").write(m) d = json.loads(m) print(f"wrote manifest.json: {len(d['skills'])} skills, {len(d['shared'])} shared files") if __name__ == "__main__": main()