Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions skills/pr-to-video/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ Do not change story, script, `transition_in`, `asset_candidates`, or the PR sour

Goal: Build every storyboard frame as an HTML composition and assemble the playable video.

GSAP is bundled in this skill (`assets/vendor/gsap.min.js`) and staged into the project by `assemble-index.mjs`, so the assembled page loads no library from a CDN. A render-time network fetch is not allowed (it is also what makes a restricted network produce a silently static video). Pass `--gsap=cdn` to assemble against the CDN instead.

Wait for Step 3.1 audio to finish if audio was started. Then sync durations and fetch SFX; skip both if silent.

`node <SKILL_DIR>/scripts/audio.mjs sync-durations --audio-meta ./audio_meta.json --storyboard ./STORYBOARD.md`
Expand Down
10 changes: 10 additions & 0 deletions skills/pr-to-video/assets/vendor/gsap.min.js

Large diffs are not rendered by default.

44 changes: 42 additions & 2 deletions skills/pr-to-video/scripts/assemble-index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@
// duration, an inner data-composition-id mismatch, or a guard ② violation).
// No backstop: fix upstream.

import { existsSync, readFileSync, writeFileSync } from "node:fs";
import { copyFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
import { spawnSync } from "node:child_process";
import { basename, join, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { parseStoryboard } from "./lib/storyboard.mjs";
import { parseFormat } from "./lib/dimensions.mjs";
import { stageAssets } from "./lib/assets.mjs";
Expand All @@ -63,6 +64,9 @@ import { bgmDefaultVolume } from "./lib/bgm-volume.mjs";
// ---------- argv ----------
const argv = process.argv.slice(2);
const flag = (name, def) => {
// Both spellings: `--name value` and `--name=value`.
const inline = argv.find((a) => a.startsWith(`--${name}=`));
if (inline) return inline.slice(name.length + 3);
const i = argv.indexOf(`--${name}`);
return i >= 0 && i + 1 < argv.length ? argv[i + 1] : def;
};
Expand Down Expand Up @@ -128,6 +132,42 @@ const storyboardPath = resolve(flag("storyboard", join(hyperframesDir, "STORYBOA
const audioMetaPath = resolve(flag("audio-meta", join(hyperframesDir, "audio_meta.json")));
const outPath = resolve(flag("out", join(hyperframesDir, "index.html")));

// GSAP: stage a local copy instead of depending on a CDN. Every frame's
// composition registers its paused timeline on window.__timelines, so a GSAP
// that never loads means no frame animates - and on a network that cannot
// reach the CDN the failure surfaces three minutes later as a silent static
// render that looks like a frame bug. The CDN stays available as an explicit
// opt-in (--gsap=cdn); when neither a local copy nor the opt-in is available
// we warn instead of failing quietly.
const GSAP_CDN_TAG =
'<script src="https://cdn.jsdelivr.net/npm/gsap@3.14.2/dist/gsap.min.js" ' +
'integrity="sha384-sG0Hv1tP1lZCk9KQmrIbY/XNwi+OY84GQqhMscbnsoBFqAz8KNCil1kvfL3Hbbk2" ' +
'crossorigin="anonymous"></script>';

function localGsapSource() {
const skillDir = fileURLToPath(new URL("..", import.meta.url));
const bundled = join(skillDir, "assets", "vendor", "gsap.min.js");
if (existsSync(bundled)) return bundled;
const installed = join(skillDir, "node_modules", "gsap", "dist", "gsap.min.js");
if (existsSync(installed)) return installed;
return null;
}

function gsapScriptTag() {
if (flag("gsap", "local") === "cdn") return GSAP_CDN_TAG;
const source = localGsapSource();
if (!source) {
console.error(
" (warn: no local GSAP copy found - falling back to the jsDelivr CDN. A network that cannot reach it means no frame animates.)",
);
return GSAP_CDN_TAG;
}
const dest = join(hyperframesDir, "assets", "vendor", "gsap.min.js");
mkdirSync(join(hyperframesDir, "assets", "vendor"), { recursive: true });
copyFileSync(source, dest);
return '<script src="./assets/vendor/gsap.min.js"></script>';
}

const r3 = (x) => Math.round(x * 1000) / 1000;
const anomalies = [];
const frameErrors = []; // fatal per-frame composition violations (guard ②) — reported together
Expand Down Expand Up @@ -584,7 +624,7 @@ const html = `<!doctype html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=${WIDTH}, height=${HEIGHT}" />
<script src="https://cdn.jsdelivr.net/npm/gsap@3.14.2/dist/gsap.min.js" integrity="sha384-sG0Hv1tP1lZCk9KQmrIbY/XNwi+OY84GQqhMscbnsoBFqAz8KNCil1kvfL3Hbbk2" crossorigin="anonymous"></script>
${gsapScriptTag()}
<style>
${headStyle}
</style>
Expand Down
27 changes: 26 additions & 1 deletion skills/pr-to-video/scripts/assemble-index.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import { tmpdir } from "node:os";
import { join } from "node:path";
import { spawnSync } from "node:child_process";
import test from "node:test";
import { fileURLToPath } from "node:url";

const assembleScript = new URL("./assemble-index.mjs", import.meta.url).pathname;
const assembleScript = fileURLToPath(new URL("./assemble-index.mjs", import.meta.url));
const HAS_FFMPEG =
spawnSync("ffmpeg", ["-version"], { stdio: "ignore" }).status === 0 &&
spawnSync("ffprobe", ["-version"], { stdio: "ignore" }).status === 0;
Expand Down Expand Up @@ -128,3 +129,27 @@ test(
assert.equal(probe.stdout.trim(), "mp3");
},
);

// ── GSAP is staged locally, not fetched from a CDN ───────────────────────────
// Regression: the assembled index.html hardcoded a jsDelivr script tag, so on
// a network that cannot reach the CDN the frames never register their
// timelines and the render comes out static - three minutes later, looking
// like a frame bug rather than a missing library.
test("assembles the GSAP script from a local copy, not the CDN", () => {
const { dir, r } = assembleWith({});

assert.equal(r.status, 0, r.stderr);
const html = readFileSync(join(dir, "index.html"), "utf8");
assert.match(html, /<script src="\.\/assets\/vendor\/gsap\.min\.js"><\/script>/);
assert.doesNotMatch(html, /cdn\.jsdelivr\.net/);
// The copy the page points at is staged next to it.
assert.equal(existsSync(join(dir, "assets", "vendor", "gsap.min.js")), true);
});

test("keeps the CDN when it is asked for explicitly", () => {
const { dir, r } = assembleWith({ extraArgs: ["--gsap=cdn"] });

assert.equal(r.status, 0, r.stderr);
const html = readFileSync(join(dir, "index.html"), "utf8");
assert.match(html, /cdn\.jsdelivr\.net/);
});
23 changes: 19 additions & 4 deletions skills/pr-to-video/scripts/fetch-pr.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import { execFileSync } from "node:child_process";
import { mkdirSync, writeFileSync } from "node:fs";
import { join, resolve } from "node:path";

import { parsePrRef } from "./lib/pr-ref.mjs";

const argv = process.argv.slice(2);
const flag = (name, def) => {
const i = argv.indexOf(`--${name}`);
Expand All @@ -41,6 +43,7 @@ function die(msg) {

const prRef = flag("pr", null);
if (!prRef) die('--pr "<url | owner/repo#N | N>" is required');
const ref = parsePrRef(prRef);
const outDir = resolve(flag("out-dir", "./capture"));

// Run gh, capture stdout. Returns { ok, stdout, stderr } — never throws (callers
Expand All @@ -58,6 +61,18 @@ function ghTry(args) {
}
}

// gh resolves both the repository and the argument against the local git
// context, so `gh pr view owner/repo#N` reads the whole thing as a branch name
// and fails outright outside a git repository. Pin the repo whenever the ref
// names one, and pass the number alone so nothing is left to guess.
function prArgs(sub, ref, fallback, extra = []) {
const args = ["pr", sub];
if (ref.number != null) args.push(String(ref.number));
else args.push(fallback);
if (ref.owner && ref.repo) args.push("--repo", `${ref.owner}/${ref.repo}`);
return [...args, ...extra];
}

// ── 0. auth — fail fast with gh's own hint ───────────────────────────────────
if (!ghTry(["auth", "status"]).ok) {
die("gh is not authenticated — run: gh auth login");
Expand Down Expand Up @@ -88,7 +103,7 @@ const FIELDS = [
"mergedAt",
].join(",");

const view = ghTry(["pr", "view", prRef, "--json", FIELDS]);
const view = ghTry(prArgs("view", ref, prRef, ["--json", FIELDS]));
if (!view.ok) die(`gh pr view "${prRef}" failed (auth / not found / private?):\n${view.stderr}`);

let pr;
Expand All @@ -103,8 +118,8 @@ try {
// cap. --jq runs per page, so the output is NDJSON (one file object per line).
const number = pr.number;
const m = /github\.com\/([^/]+)\/([^/]+)\/pull\/\d+/.exec(pr.url || "");
const owner = m?.[1];
const repo = m?.[2];
const owner = m?.[1] ?? ref.owner;
const repo = m?.[2] ?? ref.repo;
let filesNote = `${Array.isArray(pr.files) ? pr.files.length : 0} (from pr view)`;
if (owner && repo && number != null) {
const apiFiles = ghTry([
Expand Down Expand Up @@ -210,7 +225,7 @@ mkdirSync(outDir, { recursive: true });
const prJsonPath = join(outDir, "pr.json");
writeFileSync(prJsonPath, JSON.stringify(pr, null, 2) + "\n");

const diff = ghTry(["pr", "diff", prRef]);
const diff = ghTry(prArgs("diff", ref, prRef));
const diffPath = join(outDir, "diff.patch");
if (diff.ok) {
writeFileSync(diffPath, diff.stdout);
Expand Down
29 changes: 29 additions & 0 deletions skills/pr-to-video/scripts/fetch-pr.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import assert from "node:assert/strict";
import test from "node:test";

import { parsePrRef } from "./lib/pr-ref.mjs";

test("parses owner/repo#N", () => {
assert.deepEqual(parsePrRef("DataLinkDC/dinky#4584"), {
owner: "DataLinkDC",
repo: "dinky",
number: 4584,
});
});

test("parses a full pull-request url", () => {
assert.deepEqual(parsePrRef("https://github.com/DataLinkDC/dinky/pull/4584"), {
owner: "DataLinkDC",
repo: "dinky",
number: 4584,
});
});

test("parses a bare number", () => {
assert.deepEqual(parsePrRef("4584"), { owner: null, repo: null, number: 4584 });
});

test("gives up on anything that names no pull request", () => {
assert.deepEqual(parsePrRef("some-branch"), { owner: null, repo: null, number: null });
assert.deepEqual(parsePrRef(""), { owner: null, repo: null, number: null });
});
22 changes: 22 additions & 0 deletions skills/pr-to-video/scripts/lib/pr-ref.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Parsing of the `--pr` argument: a full pull-request url, `owner/repo#N`, or
// a bare pull-request number.
//
// `gh pr view <ref>` resolves BOTH the repository and the argument against the
// local git context, so it fails outright outside a git repository and reads
// "owner/repo#N" as a branch name. Parsing the ref here and pinning the repo
// with --repo makes the documented forms work in any directory.

/** @returns {{ owner: string | null, repo: string | null, number: number | null }} */
export function parsePrRef(value) {
const raw = String(value ?? "").trim();

const url = /github\.com\/([^/\s]+)\/([^/\s]+)\/pull\/(\d+)/.exec(raw);
if (url) return { owner: url[1], repo: url[2], number: Number(url[3]) };

const short = /^([^/\s#]+)\/([^/\s#]+)#(\d+)$/.exec(raw);
if (short) return { owner: short[1], repo: short[2], number: Number(short[3]) };

if (/^\d+$/.test(raw)) return { owner: null, repo: null, number: Number(raw) };

return { owner: null, repo: null, number: null };
}