CtrlK
BlogDocsLog inGet started
Tessl Logo
PluginPublic

gamussa/reels-producer-skill

Write talking-head scripts and produce Instagram reels and YouTube shorts

1.07x
Quality

96%

Does it follow best practices?

Impact

98%

1.07x

Average score across 8 eval scenarios

SecuritybySnyk

Low

Low-risk findings worth noting

Overview
Quality
Evals
Security
Files

series.pyskills/reel-builder/scripts/

#!/usr/bin/env python3
"""Reusable series formats: a recurring kind of reel, with its structure,
beats, visual conventions and audience assumptions as defaults.

Formats are defaults with justified exceptions, never rules. Bundled formats
live in assets/series/; a series folder may add its own in ../series/*.json
(same shape), which win over a bundled format of the same name.

Format (schema_version 1): {"name", "title", "structure", "audience": [..],
"beats": [{"purpose", "job"}], "visual": {..}, "defaults": {"duration",
"platform", "aspect"}}

  list           every available format
  show NAME      one format in full
  apply NAME     fill plan/brief.json's structure, platform and duration from
                 the format (empty fields only — an answer already given wins)
                 and record the choice in plan/series.json, with any
                 --exception "field: reason" the editor is taking
  check-selects  which of the format's beats plan/selects.json does not cover
                 yet (by purpose) — a prompt, not a gate

Exit codes: 0 ok; 1 unknown format or bad input. JSON on stdout.

Usage:
  series.py list
  series.py apply race-recap --exception "duration: two crashes, needs 60s"
  series.py check-selects
"""

import argparse
import json
import sys
from pathlib import Path

SCHEMA_VERSION = 1
BUNDLED = Path(__file__).resolve().parent.parent / "assets" / "series"
LOCAL = Path("..") / "series"
SERIES = Path("plan/series.json")
BRIEF = Path("plan/brief.json")


class Refused(Exception):
    pass


def formats():
    found = {}
    for folder in (BUNDLED, LOCAL):
        if not folder.is_dir():
            continue
        for p in sorted(folder.glob("*.json")):
            try:
                f = json.loads(p.read_text())
            except json.JSONDecodeError as e:
                raise Refused(f"{p} is not valid JSON: {e}") from None
            if f.get("schema_version") == SCHEMA_VERSION and f.get("name"):
                found[f["name"]] = {**f, "_from": str(p)}
    return found


def get(name):
    fs = formats()
    if name not in fs:
        raise Refused(f"no format {name!r} — available: {', '.join(sorted(fs))}")
    return fs[name]


def parse_exceptions(items):
    out = {}
    for item in items or []:
        field, sep, reason = item.partition(":")
        if not sep or not field.strip() or not reason.strip():
            raise Refused(f"exception {item!r} must read 'field: reason'")
        out[field.strip()] = reason.strip()
    return out


def apply(fmt, brief, exceptions):
    """Fill only the brief fields still empty; return the fields filled."""
    filled = []
    d = fmt.get("defaults") or {}
    if not brief.get("structure") and "structure" not in exceptions:
        brief["structure"] = fmt["structure"]
        filled.append("structure")
    if not brief.get("platform") and d.get("platform") and "platform" not in exceptions:
        brief["platform"] = d["platform"]
        filled.append("platform")
    dur = brief.setdefault("duration", {"target": None, "basis": ""})
    if dur.get("target") is None and d.get("duration") and "duration" not in exceptions:
        dur["target"] = d["duration"]
        dur["basis"] = dur.get("basis") or f"{fmt['title']} series default"
        filled.append("duration")
    return filled


def uncovered(fmt, selects_doc):
    have = {s.get("purpose") for s in selects_doc.get("selects", [])}
    return [b for b in fmt.get("beats", []) if b["purpose"] not in have]


def main():
    ap = argparse.ArgumentParser(
        description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter
    )
    sub = ap.add_subparsers(dest="cmd", required=True)
    sub.add_parser("list")
    sub.add_parser("show").add_argument("name")
    a_apply = sub.add_parser("apply")
    a_apply.add_argument("name")
    a_apply.add_argument(
        "--exception",
        action="append",
        help="'field: reason' — a default this reel deliberately departs from",
    )
    sub.add_parser("check-selects")
    a = ap.parse_args()
    try:
        if a.cmd == "list":
            print(
                json.dumps(
                    {
                        "ok": True,
                        "formats": [
                            {
                                "name": n,
                                "title": f["title"],
                                "structure": f["structure"],
                                "from": f["_from"],
                            }
                            for n, f in sorted(formats().items())
                        ],
                    },
                    indent=1,
                )
            )
            return
        if a.cmd == "show":
            print(json.dumps({"ok": True, "format": get(a.name)}, indent=1))
            return
        if a.cmd == "apply":
            fmt = get(a.name)
            exceptions = parse_exceptions(a.exception)
            brief = json.loads(BRIEF.read_text()) if BRIEF.exists() else {"schema_version": 1}
            filled = apply(fmt, brief, exceptions)
            BRIEF.parent.mkdir(parents=True, exist_ok=True)
            BRIEF.write_text(json.dumps(brief, indent=2) + "\n")
            SERIES.write_text(
                json.dumps(
                    {
                        "schema_version": SCHEMA_VERSION,
                        "format": fmt["name"],
                        "exceptions": exceptions,
                    },
                    indent=2,
                )
                + "\n"
            )
            print(
                json.dumps(
                    {
                        "ok": True,
                        "format": fmt["name"],
                        "filled": filled,
                        "exceptions": exceptions,
                        "beats": fmt["beats"],
                        "visual": fmt.get("visual"),
                        "audience": fmt.get("audience"),
                    },
                    indent=1,
                )
            )
            return
        if not SERIES.exists():
            raise Refused("no plan/series.json — apply a format first")
        fmt = get(json.loads(SERIES.read_text())["format"])
        sel = Path("plan/selects.json")
        doc = json.loads(sel.read_text()) if sel.exists() else {"selects": []}
        missing = uncovered(fmt, doc)
        print(json.dumps({"ok": True, "format": fmt["name"], "uncovered": missing}))
    except (Refused, OSError, json.JSONDecodeError, KeyError) as e:
        print(json.dumps({"ok": False, "error": str(e)}))
        sys.exit(1)


if __name__ == "__main__":
    main()

skills

tile.json