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

selects.pyskills/reel-builder/scripts/

#!/usr/bin/env python3
"""Selects: the moments that earn a place in the reel, in story order.

Contact sheets show what is in the footage; selects record which moments
matter and why, before anything is fitted to a beat grid. A clip earns its
place by what it contributes, not by having been used less.

plan/selects.json (schema_version 1):
  {"schema_version": 1,
   "selects": [
     {"clip": "IMG_0412",           stem or path of a clip in work/clips.json
      "in": 3.2, "out": 6.8,        usable range in the SOURCE clip, seconds
      "peak": 5.0,                  optional — the instant the cut should centre on
      "what": "runner checks watch, grimaces",   what happens, concretely
      "purpose": "hook",            see PURPOSES
      "value": 5,                   1-5: how much the reel loses without it
      "concerns": "slight motion blur"}   optional
   ]}

Order IS the story. build_cut_plan.py --selects keeps that order and fits
pacing to it; the editor's judgment lives here, the arithmetic there.

This script checks shape and ranges against work/clips.json. It cannot say
whether a moment is good — that is the contact-sheet review.

Exit codes: 0 valid, 1 invalid; JSON on stdout.

Usage:
  selects.py check plan/selects.json --clips work/clips.json
"""

import argparse
import json
import sys
from pathlib import Path
from typing import TypeGuard

SCHEMA_VERSION = 1
PURPOSES = (
    "hook",
    "setup",
    "evidence",
    "demonstration",
    "reaction",
    "payoff",
    "cta",
    "texture",
    "transition",
)
CLOSERS = ("payoff", "cta", "reaction")
EPS = 0.05


def is_num(x: object) -> TypeGuard[float]:
    """A JSON number (bool is an int in Python and is refused)."""
    return isinstance(x, (int, float)) and not isinstance(x, bool)


def clip_index(clips):
    """Every way a select may name a clip -> the clip record."""
    idx = {}
    for c in clips:
        f = c.get("file", "")
        idx[f] = c
        idx[Path(f).stem] = c
        idx[Path(f).name] = c
    return idx


def validate(doc, clips):
    """(errors, warnings, selects) — selects resolved to their clip records."""
    errors, warnings, out = [], [], []
    if not isinstance(doc, dict) or doc.get("schema_version") != SCHEMA_VERSION:
        return [f"selects file must be an object with schema_version {SCHEMA_VERSION}"], [], []
    sel = doc.get("selects")
    if not isinstance(sel, list) or not sel:
        return ["selects must be a non-empty list"], [], []
    idx = clip_index(clips)
    for n, s in enumerate(sel, 1):
        where = f"select {n}"
        if not isinstance(s, dict):
            errors.append(f"{where}: must be an object")
            continue
        clip = idx.get(str(s.get("clip", "")))
        if clip is None:
            errors.append(f"{where}: clip {s.get('clip')!r} is not in clips.json")
            continue
        raw_in, raw_out = s.get("in"), s.get("out")
        if not (is_num(raw_in) and is_num(raw_out)):
            errors.append(f"{where}: in/out must be numbers of seconds")
            continue
        a, b = float(raw_in), float(raw_out)
        dur = float(clip.get("duration", 0))
        if not 0 <= a < b <= dur + EPS:
            errors.append(
                f"{where}: range {a}-{b}s is outside {Path(clip['file']).name} "
                f"(0-{dur:.2f}s) or empty"
            )
            continue
        peak = s.get("peak")
        if peak is not None and not (is_num(peak) and a <= float(peak) <= b):
            errors.append(f"{where}: peak must lie inside {a}-{b}")
        if not (isinstance(s.get("what"), str) and s["what"].strip()):
            errors.append(f'{where}: say what happens in it ("what")')
        if s.get("purpose") not in PURPOSES:
            errors.append(f"{where}: purpose must be one of {', '.join(PURPOSES)}")
        v = s.get("value")
        if not (isinstance(v, int) and not isinstance(v, bool) and 1 <= v <= 5):
            errors.append(f"{where}: value must be an integer 1-5")
        out.append({**s, "_clip": clip})
    if not errors:
        if out[0].get("purpose") != "hook":
            warnings.append("the first select is not a hook — the opening decides scroll-past")
        if out[-1].get("purpose") not in CLOSERS:
            warnings.append(
                "the last select is not a payoff, CTA or reaction — "
                "the reel may end without landing"
            )
        seen = {}
        for n, s in enumerate(out, 1):
            key = s["_clip"]["file"]
            for m, (a, b) in seen.get(key, []):
                if s["in"] < b and a < s["out"]:
                    warnings.append(f"selects {m} and {n} overlap in {Path(key).name}")
            seen.setdefault(key, []).append((n, (s["in"], s["out"])))
    return errors, warnings, out


def main():
    ap = argparse.ArgumentParser(
        description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter
    )
    sub = ap.add_subparsers(dest="cmd", required=True)
    c = sub.add_parser("check")
    c.add_argument("selects")
    c.add_argument("--clips", default="work/clips.json")
    a = ap.parse_args()
    try:
        doc = json.loads(Path(a.selects).read_text())
        clips = json.loads(Path(a.clips).read_text())["clips"]
    except (OSError, json.JSONDecodeError, KeyError) as e:
        print(json.dumps({"ok": False, "errors": [f"cannot read inputs: {e}"], "warnings": []}))
        sys.exit(1)
    errors, warnings, sel = validate(doc, [c for c in clips if "error" not in c])
    print(
        json.dumps(
            {
                "ok": not errors,
                "count": len(sel),
                "errors": errors,
                "warnings": warnings,
                "seconds": round(sum(s["out"] - s["in"] for s in sel), 2),
            }
        )
    )
    sys.exit(0 if not errors else 1)


if __name__ == "__main__":
    main()

skills

tile.json