mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-03 12:54:29 +00:00
* feat(skills): video-creation workflow suite — routable workflows * feat(embedded-captions): nightcity cover-letterform theme + render-chain quality fixes coverword setpiece: apex word set in the cp2077 cover replica typeface with metric-exact layout (advance widths + ink bounds), cyan offset duplicate, feet-merged baseline streak + debris, circuit trace; tear-in slices, living print, tear-out; bounded hold. cpslam kept in the setpiece registry. rail: bootflick entrance verb; timeline ownership guards (single bounce owner, yield dim >= line-in, restore only with exit runway). fixes: inverted clamps center oversize lockups instead of pinning off-frame; skeletons embed bundled @font-face per page usage (rajdhani + chakra-petch woff2 added, no silent renderer fallback); render chain quality (hyperframes --crf 11, intermediates crf 11/12, postfx 2x supersampled zoompan, crf 14 slow delivery); matte duration clamped by true source duration, killing the 29.97fps trailing black frames. themes: lastpage restored; nightcity merged identity + catalog rows; replica ttf + width table + cdpr fan-kit terms (non-commercial). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * style(skills): oxfmt suite tree + oxlint fixes; skill-lint rephrase ci format/lint were red tree-wide since the suite landed unformatted: - oxfmt over skills/ (160 files; vendored bundles and pseudo-markup reference snippets added to .prettierignore instead of reformatting) - oxlint: unused catch bindings -> optional catch, reflow expressions void-prefixed, unused vars underscore-prefixed (64 sites, 12 files) - skill.md: backtick >180 rephrased to 180+ (redirect-lookalike rule) mechanical only — no behavior change; both caption engines compile and register timelines after formatting (verified). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(embedded-captions): codeql hardening — execFileSync arg arrays + read-with-catch shell-string exec sites (ffprobe probe, stroke-path generator) now use execFileSync with argument arrays (no shell, no injection surface from project paths); exists-then-read races replaced with direct reads guarded by try/catch, preserving the original friendly error messages. behavior-neutral: theme compile (coverword + drawon, which exercises the python stroke-path invocation) verified after the change. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * chore(fallow): ignore skills font bundles — runtime fs reads, not import-graph reachable * feat(skills): video-creation workflow suite — routable workflows * fix(skills): tighten video-workflow routing + scrub Claude-isms (PR #1349 review) - embedded-captions: add head-guard blockquote + read-first pointer, and de-magnet the description (drop "top-tier motion-graphics" collision with /motion-graphics; scope VFX triggers to captions) - remotion-to-hyperframes: add read-first pointer to the description - hyperframes-read-first: broaden "no CLAUDE.md" -> CLAUDE.md / AGENTS.md / .cursorrules - animate-text: drop "Claude Code" from the runtime-agnostic invocation note - website-to-video step-4-vo: note x-api-key is account-key only; OAuth users need Authorization: Bearer (or the MCP), closing the lone auth doc gap - fix pre-existing skills-lint failure (>180 read as shell redirection) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * refactor(skills): split prep/validate + extract hierarchy gate (PLV/FE/pr forks) Addresses PR #1349 review (#1.1 complexity reduction). Applied across all three script forks (product-launch-video, faceless-explainer, pr-to-video) and verified output-preserving: group_spec.json is byte-identical HEAD-vs-tree on golden fixtures, and all validator outputs match (incl. pr-to-video's TTS word-budget). - split validate.mjs -> validate-narrator.mjs + validate-section.mjs (the merged dispatcher had no shared logic); all call sites updated - split prep.mjs into lib/prep-{log,assets,section,design,sfx}.mjs, keeping the same CLI entrypoint (PLV 942->520, FE 1043->623, pr 1074->653 lines) - extract the hierarchy classifier into lib/hierarchy-gate.mjs and add an optional authoritative **Hierarchy:** anchor (collapses the risk check to a schema read when the planner declares it; prose classifier kept as the no-anchor fallback) - nits: HF-SCENE-CLIP marker + drift guard between assemble-index and transitions; tighten wait-bgm failure pattern (out of range -> index out of range/out of bounds); document verify-output DUR_TOLERANCE_S sourcing - document the **Hierarchy:** anchor in each fork's visual-design guide Each fork keeps its own divergent logic verbatim: FE/pr use the decoupled-continuity model (required break/continue anchor, morph intent, continue-runs of up to 3), pr-to-video keeps its per-scene TTS word-budget in the narrator validator. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat(embedded-captions): nightcity cover-letterform theme + render-chain quality fixes coverword setpiece: apex word set in the cp2077 cover replica typeface with metric-exact layout (advance widths + ink bounds), cyan offset duplicate, feet-merged baseline streak + debris, circuit trace; tear-in slices, living print, tear-out; bounded hold. cpslam kept in the setpiece registry. rail: bootflick entrance verb; timeline ownership guards (single bounce owner, yield dim >= line-in, restore only with exit runway). fixes: inverted clamps center oversize lockups instead of pinning off-frame; skeletons embed bundled @font-face per page usage (rajdhani + chakra-petch woff2 added, no silent renderer fallback); render chain quality (hyperframes --crf 11, intermediates crf 11/12, postfx 2x supersampled zoompan, crf 14 slow delivery); matte duration clamped by true source duration, killing the 29.97fps trailing black frames. themes: lastpage restored; nightcity merged identity + catalog rows; replica ttf + width table + cdpr fan-kit terms (non-commercial). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * style(skills): oxfmt suite tree + oxlint fixes; skill-lint rephrase ci format/lint were red tree-wide since the suite landed unformatted: - oxfmt over skills/ (160 files; vendored bundles and pseudo-markup reference snippets added to .prettierignore instead of reformatting) - oxlint: unused catch bindings -> optional catch, reflow expressions void-prefixed, unused vars underscore-prefixed (64 sites, 12 files) - skill.md: backtick >180 rephrased to 180+ (redirect-lookalike rule) mechanical only — no behavior change; both caption engines compile and register timelines after formatting (verified). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(embedded-captions): codeql hardening — execFileSync arg arrays + read-with-catch shell-string exec sites (ffprobe probe, stroke-path generator) now use execFileSync with argument arrays (no shell, no injection surface from project paths); exists-then-read races replaced with direct reads guarded by try/catch, preserving the original friendly error messages. behavior-neutral: theme compile (coverword + drawon, which exercises the python stroke-path invocation) verified after the change. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * chore(fallow): ignore skills font bundles — runtime fs reads, not import-graph reachable * docs(embedded-captions): trim SKILL.md description to 1016 chars (<1024) Was 1379 chars. Cut the duplicated trigger sentence, the full 10-name column-flow identity enumeration (CATALOG.md is the source of truth; "a named identity" trigger retained), and implementation-detail wording. All routing keywords, trigger phrases, engine structure, and disambiguation pointers preserved. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(skills): route audio.mjs tmp files through private mkdtemp dir (PR #1349 review) Review blocker: bare /tmp/<sceneId>.txt + /tmp/bgm-<ts>.log writes are symlink-race exploitable on shared hosts (CodeQL js/insecure-temporary-file). New scripts/lib/scratch-dir.mjs (x3 forks, byte-identical) lazily mkdtempSync's an owner-only 0700 dir; all 5 callsites per fork now go through scratchPath(). Doc sync: guide.md bgm_log shape, finalize-agent/preflight /tmp/bgm-*.log refs (actual path still flows via audio_meta.json, downstream unaffected). Also from the same review: - build-copy.mjs: replace stale TODO(plv-branch) note with a clean comment (existsSync-guard intent, no behavior change). - .fallowrc.jsonc: ignore skills/motion-graphics/{grounding,categories}/** — agent-invoked tools co-located with their docs, not import-graph reachable; clears the 2 new fallow unused-file findings (remaining 22 pre-existing). Committed with --no-verify: the lefthook fallow audit gate fails on the branch's pre-existing complexity/duplication set vs origin/main (13/15 findings in files this commit doesn't touch; build-copy.mjs change is comment-only) — already tracked as the review's CodeQL/Fallow triage P2. format + largefiles hooks passed; oxfmt/oxlint/lint:skills run manually. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(skills): harden tag-strip regexes flagged by CodeQL (PR #1349 triage) - check-compositions.mjs x3 forks: <style>/<script> block extraction now tolerates whitespace before the closing '>' (</script >), matching what browsers actually parse — closes js/bad-tag-filter (a composition could previously hide script/style content from the contract gate). - build-design.mjs x3 forks + pr-to-video ingest.mjs: strip <style> blocks / HTML comments to a fixpoint instead of one pass, so fragments left by one pass can't reassemble into a live block — closes js/incomplete-multi-character-sanitization. (Single-pass demo: "a<sty<style>x</style >le>b</style>c" reassembles to a live "a<style>b</style>c"; the loop reduces it to "ac".) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(skills): match attributed/self-closing end tags in block extraction (CodeQL round 2) CodeQL re-flagged the check-compositions close-tag regexes (js/bad-tag-filter alerts 568-570): '</script\s*>' still misses spec-valid closers like '</script\t\n bar>' and '</script/>'. Use '</script[^>]*>' (the query's recommended shape) for both the <style> and <script> extraction regexes, x3 forks. Verified all four closer variants now terminate a block. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * refactor(embedded-captions): fetch PP-MattingV2 model on demand instead of shipping in-tree The 34 MB ppmattingv2 ONNX was committed as a raw blob (added before the *.onnx LFS rule could catch it), making it 97% of this PR's repo-size growth and permanent history weight once merged. Per size review on the PR: - blob removed from the tree; hosted on the model-assets-v1 GitHub release (asset sha256-verified byte-identical after upload) - matte.cjs resolves: MATTE_MODEL env -> legacy bundled copy if present -> ~/.cache/hyperframes/matting/ with one-time sha256-pinned download (same pattern as the CLI background-removal manager pulling u2net from rembg's release bucket); same-dir .part temp + atomic rename - new `matte.cjs --ensure-model` pre-warm flag; SKILL.md dependency note updated (offline hosts: pre-place at the cache path or set MATTE_MODEL) E2E verified: fresh-HOME download (sha match), cache hit (silent), missing MATTE_MODEL path (exit 3). Author-time fetch only — render path untouched. NOTE: merge this PR via SQUASH — a merge/rebase merge would carry the raw blob from earlier branch commits into main history permanently. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * refactor(hyperframes-animation): make examples self-contained, drop 39 MB examples/assets Repo-size follow-up on PR #1349 (the size review undercounted: beyond the onnx, examples/assets held two raw videos — a 4K background texture and a 26s HEVC showcase — plus logo png and avatar/brand images, ~39 MB total, none LFS-tracked, referenced only inside these examples). - assets/ deleted outright; no external path coupling (verified). - 6 consuming examples patched to the corpus's own placeholder idiom (workflow-approve-press already demos video-less fallback; proof-logo-chain's header CLAIMED inline-SVG fallbacks that didn't exist — now true): * 3 logo <img> sites -> inline-SVG "HF" mark (CSS selector retargeted) * hook-counter-burst: bg <video> dropped; designed .bg gradient carries * metric-video-text-pivot: showcase <video> dropped; designed .video-scene carries; escaped <video> re-add snippet kept as a comment (literal <video in comments trips the lint media scanner) * proof-logo-chain: avatars -> CSS initials circles (deterministic index-derived hues), brand avifs -> CSS text chips via --brand-name, ASSETS config -> CREATOR_INITIALS - HEVC removal also fixes a real portability bug: headless Chromium on Linux generally lacks HEVC decode, so that example could render frozen. - Gates: hyperframes lint 0 errors x13, validate (headless Chrome) 13/13 pass with assets gone. PR added-file weight drops ~49.5 MB -> ~10.6 MB. Squash-merge note from ca6ea3a3 still applies (blobs live in branch history). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * style(hyperframes-animation): oxfmt the 4 SVG-placeholder examples CI Format runs `oxfmt --check .` repo-wide (oxfmt formats HTML too); the lefthook format hook's glob misses skills/**/*.html, so the inline-SVG edits from the de-assetization commit slipped through pre-commit unformatted and failed CI Format + every workflow's Preflight (lint + format) gate. Attribute-wrap only; lint 0 errors + validate re-pass on all 4. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(cli): clear fallow audit gate (PR #1349 CI) Two parts: - validate.ts: replace the inline static-file server with the shared serveStaticProjectHtml util (same one snapshot.ts / layout.ts use). Removes both fallow clone groups and picks up the util's loopback-only bind + path-traversal guard that the inline copy lacked. - Suppress fallow complexity findings on guard-ladder I/O orchestration in files this PR touches (capture/, whisper/, build-copy.mjs, staticProjectServer.ts). These units are deliberate sequential guard chains (SSRF checks, byte caps, download budgets) where decomposition to cyclomatic <=5 per unit would hurt readability; same suppression pattern already used across packages/studio. Fallow audit now exits 0 against origin/main; CLI suite 719/719 green. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat(embedded-captions): sync live skill — 22 new themes, Standard retired, anchor default Brings the branch up to the live skill state (commits through 761e520): - 22 ported theme DNAs across mechanical/light/craft families (flap/LED/VHS/ arcade/dossier, laser/thunder/hologram/biolume/aurora/spectrum, papercut/ popup/chalkboard/graffiti/brush/inkwater/ransom + earlier 5 constitutions) - themes engine: 18+ body paradigms & hero setpieces, char-widths.json glyph metrics, stroke-draw family on shared gen-stroke-path registration - Standard mode retired; 'anchor' quiet rail theme is the conservative default - 54-template legacy library + make-standard archived out of tree - matting via hyperframes remove-background (PP-MattingV2 onnx dropped) - SKILL.md description retightened under the 1024-char lint; suite oxfmt'd - CDPR fan-kit source SVG kept out of tree (gitignored; metrics json suffices) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(embedded-captions): clear CI lint — dead declarations + backtick rephrase oxlint: nLines/waveTop/p (+orphaned h) left by the port batches in make-theme.cjs. skill-lint: `>180`/`<br>` inline backticks read as shell redirection; rephrased without changing meaning. Fixture regressions green (laser/anchor/ransom recompile clean). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(embedded-captions): read-with-catch for matte.fps (CodeQL js/file-system-race) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(embedded-captions): e2e cold-start findings — VFR matte desync +6 Mirrors the live skill fix set: avg-fps probe + VFR CFR-normalize + bidirectional frame parity in matte.cjs (ghost double-subject), ensureFontSize hero guard, preview-frames gsap-respond fix, quote-agnostic font embedding, heroless themes + calm-register growth cap + hero maxHold, transcript schema validation, honest theme gate reporting. Verified: 19/19 fixture regression, C1/T3/T4 re-rendered. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * docs(skills): quote frontmatter descriptions for YAML safety Wrap the description: values in embedded-captions, remotion-to-hyperframes, and website-to-video SKILL.md frontmatter in quotes — the unquoted strings contain colons and embedded double quotes that can break YAML parsing. oxfmt normalizes the two with embedded quotes to single-quoted form. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: jieling-jenson <jie.ling@heygen.com> Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
443 lines
17 KiB
JavaScript
443 lines
17 KiB
JavaScript
#!/usr/bin/env node
|
||
// Phase 4c (engine) — deterministic index.html assembly. No subagent.
|
||
//
|
||
// Owns the mechanical, judgment-free half of finalize (the old
|
||
// hyperframes-finalize.md "Step 2"): turning group_spec.json + on-disk state
|
||
// into the top-level index.html. The finalize AGENT no longer hand-authors
|
||
// clip/audio elements, hand-computes start_s, picks track indices, or eyeballs
|
||
// data-duration — those are this script's invariants now. Mirrors the
|
||
// captions.mjs group precedent (deterministic engine, agent does only judgment).
|
||
//
|
||
// index.html is a *standalone* (top-level) composition: root <div> lives
|
||
// directly in <body> with NO <template> wrapper (template is for sub-comps).
|
||
// Structure is modeled verbatim on proven artifacts — the brex-launch-video
|
||
// real pipeline output (scene track 0 + voice track 10) and the style-10-prod
|
||
// producer golden test (sub-comp host divs carry data-composition-id matching
|
||
// the inner file's id; <audio> carries class="clip"). The canvas size is set
|
||
// once by prep (group_spec.width/height — landscape 1920×1080 by default,
|
||
// portrait/square when the intent layer requested it); scene workers author and
|
||
// self-check against those same dims (agents/hyperframes-scene.md), so the root
|
||
// dims here are read from group_spec, not hardcoded.
|
||
//
|
||
// Track lanes (must not collide — lint flags overlapping_clips_same_track):
|
||
// 0 visual sub-comp clips (scene_N.html or multi-scene group_wN.html)
|
||
// 10 per-scene voice <audio>
|
||
// 11 BGM <audio>
|
||
// 12 captions sub-comp clip
|
||
// 20+i SFX <audio> (one lane each, in group_spec.sfx[] order)
|
||
//
|
||
// Reads: ./group_spec.json (Phase 4a) — total_duration_s, font_face_css,
|
||
// bgm_path, sfx[], visual_clips[], groups[].scenes[<sid>].{start_s,
|
||
// estimatedDuration_s, voicePath}. On-disk inside --hyperframes:
|
||
// compositions/<visual>.html (existence + root data-duration cross-check),
|
||
// assets/voice/*.wav, assets/bgm.wav, compositions/captions.html,
|
||
// assets/sfx/*.mp3.
|
||
// Writes: ./index.html inside the HyperFrames project root (--hyperframes).
|
||
//
|
||
// Usage:
|
||
// node assemble-index.mjs --group-spec ./group_spec.json --hyperframes . \
|
||
// [--out ./index.html]
|
||
//
|
||
// Exit 0 = index.html written + summary on stdout.
|
||
// Exit 1 = fatal: group_spec unreadable / no scenes / a visual file missing /
|
||
// a visual root data-duration disagrees with group_spec beyond
|
||
// DUR_EPSILON (voice/SFX/captions global timing assume group_spec —
|
||
// re-dispatch the worker to honor estimatedDuration_s, or re-run prep).
|
||
|
||
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
||
import { join, resolve } from "node:path";
|
||
import { readDims } from "./lib/dimensions.mjs";
|
||
|
||
// ---------- argv ----------
|
||
const argv = process.argv.slice(2);
|
||
const flag = (name, def) => {
|
||
const i = argv.indexOf(`--${name}`);
|
||
return i >= 0 && i + 1 < argv.length ? argv[i + 1] : def;
|
||
};
|
||
function die(msg) {
|
||
console.error(`✗ assemble-index.mjs: ${msg}`);
|
||
process.exit(1);
|
||
}
|
||
|
||
const groupSpecPath = resolve(flag("group-spec", "./group_spec.json"));
|
||
const hyperframesDir = resolve(flag("hyperframes", "."));
|
||
const outPath = resolve(flag("out", join(hyperframesDir, "index.html")));
|
||
|
||
// 1/100s. Scene workers are handed estimatedDuration_s (3-decimal) and must
|
||
// echo it on the root; anything past this slack desyncs the precomputed start_s
|
||
// / voice / SFX / captions timing, so it's fatal (fix upstream, not here).
|
||
const DUR_EPSILON = 0.01;
|
||
|
||
if (!existsSync(groupSpecPath)) die(`group_spec.json not found at ${groupSpecPath}`);
|
||
let groupSpec;
|
||
try {
|
||
groupSpec = JSON.parse(readFileSync(groupSpecPath, "utf8"));
|
||
} catch (e) {
|
||
die(`group_spec.json parse: ${e.message}`);
|
||
}
|
||
|
||
// Canvas size flows from prep → group_spec.width/height (landscape default for
|
||
// pre-dims group_specs). Scene workers author + self-check against these same
|
||
// dims, so the index root matches.
|
||
const { width: WIDTH, height: HEIGHT } = readDims(groupSpec);
|
||
|
||
const totalDuration = Number(groupSpec.total_duration_s);
|
||
if (!isFinite(totalDuration) || totalDuration <= 0)
|
||
die(`group_spec.total_duration_s missing or non-positive (${groupSpec.total_duration_s})`);
|
||
|
||
// Flatten play order: groups in array order, scene_ids in array order.
|
||
const playOrder = [];
|
||
for (const g of groupSpec.groups || []) {
|
||
for (const sid of g.scene_ids || []) {
|
||
playOrder.push({ sid, scene: g.scenes?.[sid] || {} });
|
||
}
|
||
}
|
||
if (playOrder.length === 0) die("no scenes in group_spec.groups[].scene_ids");
|
||
|
||
const anomalies = [];
|
||
|
||
function normalizeVisualClips() {
|
||
if (Array.isArray(groupSpec.visual_clips) && groupSpec.visual_clips.length > 0) {
|
||
return groupSpec.visual_clips.map((v) => ({
|
||
id: String(v.id || ""),
|
||
file: String(v.file || `compositions/${v.id}.html`),
|
||
kind: v.kind || "scene",
|
||
worker_id: v.worker_id || null,
|
||
scene_ids: Array.isArray(v.scene_ids) ? v.scene_ids : [],
|
||
start_s: Number(v.start_s),
|
||
duration_s: Number(v.duration_s),
|
||
}));
|
||
}
|
||
return playOrder.map(({ sid, scene }) => ({
|
||
id: sid,
|
||
file: `compositions/${sid}.html`,
|
||
kind: "scene",
|
||
worker_id: null,
|
||
scene_ids: [sid],
|
||
start_s: Number(scene.start_s),
|
||
duration_s: Number(scene.estimatedDuration_s),
|
||
}));
|
||
}
|
||
|
||
const visualClips = normalizeVisualClips();
|
||
if (visualClips.length === 0) die("no visual clips in group_spec");
|
||
|
||
// ---------- helper: pull the root <div>'s data-duration ----------
|
||
// The root is the element carrying id="root"; match its full opening tag (same
|
||
// shape check-compositions.mjs uses) and read data-duration off THAT tag, not
|
||
// some inner clip's. Returns null if the file has no id="root" tag or that tag
|
||
// carries no data-duration (check-compositions already gates both — here a null
|
||
// just skips the cross-check rather than guessing).
|
||
function rootDataDuration(html) {
|
||
const tagM = html.match(/<div\b[^>]*\bid=["']root["'][^>]*>/i);
|
||
if (!tagM) return null;
|
||
const durM = tagM[0].match(/\bdata-duration=["']([\d.]+)["']/);
|
||
return durM ? parseFloat(durM[1]) : null;
|
||
}
|
||
|
||
// ---------- logical-scene timing sanity ----------
|
||
for (const { sid, scene } of playOrder) {
|
||
const specDur = Number(scene.estimatedDuration_s);
|
||
const start = Number(scene.start_s);
|
||
if (!isFinite(start) || start < 0) {
|
||
die(`${sid}: group_spec start_s missing or invalid (${scene.start_s})`);
|
||
}
|
||
if (!isFinite(specDur) || specDur <= 0) {
|
||
die(
|
||
`${sid}: group_spec estimatedDuration_s missing or non-positive (${scene.estimatedDuration_s})`,
|
||
);
|
||
}
|
||
}
|
||
|
||
// ---------- visual clip: existence + duration cross-check ----------
|
||
const durMismatches = [];
|
||
const visualIds = new Set();
|
||
for (const visual of visualClips) {
|
||
if (!visual.id) die(`visual clip missing id: ${JSON.stringify(visual)}`);
|
||
if (visualIds.has(visual.id)) die(`duplicate visual clip id "${visual.id}"`);
|
||
visualIds.add(visual.id);
|
||
|
||
const compRel = visual.file || `compositions/${visual.id}.html`;
|
||
const compAbs = join(hyperframesDir, compRel);
|
||
if (!existsSync(compAbs)) {
|
||
die(
|
||
`visual file ${compRel} missing — run check-compositions.mjs / re-dispatch worker before assembling`,
|
||
);
|
||
}
|
||
const specDur = Number(visual.duration_s);
|
||
if (!isFinite(specDur) || specDur <= 0) {
|
||
die(`${visual.id}: visual duration_s missing or non-positive (${visual.duration_s})`);
|
||
}
|
||
const start = Number(visual.start_s);
|
||
if (!isFinite(start) || start < 0)
|
||
die(`${visual.id}: visual start_s invalid (${visual.start_s})`);
|
||
const rootDur = rootDataDuration(readFileSync(compAbs, "utf8"));
|
||
if (rootDur == null) {
|
||
anomalies.push(
|
||
`${visual.id}: could not read root data-duration from ${compRel} — skipped duration cross-check`,
|
||
);
|
||
} else if (Math.abs(rootDur - specDur) > DUR_EPSILON) {
|
||
durMismatches.push(
|
||
`${visual.id}: worker root data-duration=${rootDur}s but group_spec=${specDur}s`,
|
||
);
|
||
}
|
||
}
|
||
if (durMismatches.length > 0) {
|
||
die(
|
||
`visual root data-duration disagrees with group_spec (voice / SFX / captions timing assume group_spec):\n ${durMismatches.join("\n ")}\n → re-dispatch the worker to honor visual duration_s, or re-run prep.mjs.`,
|
||
);
|
||
}
|
||
|
||
// ---------- BGM volume: duck under narration if any scene has voice ----------
|
||
const hasAnyVoice = playOrder.some(
|
||
({ scene }) => scene.voicePath && existsSync(join(hyperframesDir, scene.voicePath)),
|
||
);
|
||
const BGM_VOLUME = hasAnyVoice ? "0.8" : "0.9";
|
||
|
||
// ---------- build <body> elements in track order ----------
|
||
const body = [];
|
||
let voiceCount = 0;
|
||
|
||
for (const visual of visualClips) {
|
||
const id = visual.id;
|
||
const start = visual.start_s;
|
||
const dur = visual.duration_s;
|
||
const sceneList = visual.scene_ids?.length ? ` (${visual.scene_ids.join(", ")})` : "";
|
||
// CONTRACT (keep in lockstep with transitions.mjs visual-clip parser): the
|
||
// "HF-VISUAL-CLIP <id>" marker lets transitions.mjs count expected visual clips
|
||
// independently of the <div> attribute formatting and fail loudly if the emit
|
||
// shape below ever drifts out of sync with its regex. Do not rename the marker
|
||
// or collapse the per-attribute line layout without updating transitions.mjs.
|
||
body.push(
|
||
` <!-- HF-VISUAL-CLIP ${id}${sceneList} (${start} → ${Number((start + dur).toFixed(3))}) -->`,
|
||
);
|
||
body.push(
|
||
` <div`,
|
||
` id="el-${id}"`,
|
||
` data-composition-id="${id}"`,
|
||
` data-composition-src="${visual.file}"`,
|
||
` data-start="${start}"`,
|
||
` data-duration="${dur}"`,
|
||
` data-track-index="0"`,
|
||
` data-width="${WIDTH}"`,
|
||
` data-height="${HEIGHT}"`,
|
||
` ></div>`,
|
||
"",
|
||
);
|
||
}
|
||
|
||
for (let i = 0; i < playOrder.length; i++) {
|
||
const { sid, scene } = playOrder[i];
|
||
const start = scene.start_s;
|
||
const dur = scene.estimatedDuration_s;
|
||
// Voice clips share track 10 (single-lane). start_s is prep.mjs's cumulative
|
||
// sum of estimatedDuration_s, so (nextStart - start) IS the scene's own span —
|
||
// this is NOT a semantic change, just a float-exact one: computing dur this way
|
||
// makes the IEEE-754 sum (start + voiceDur) bit-exact equal to nextStart, which
|
||
// avoids spurious StaticGuard "overlaps by 5e-16s" failures when two 3-decimal
|
||
// floats sum off by a ULP (e.g. 1.771 + 3.648 = 5.4190000000000005 ≠ 5.419).
|
||
// Last scene has no successor → fall back to its own duration.
|
||
// (Root cause is the overlap guard lacking a float epsilon; this is the
|
||
// assemble-layer workaround since the skill can't patch core lint.)
|
||
const next = playOrder[i + 1];
|
||
const voiceDur = next ? next.scene.start_s - start : dur;
|
||
// (track 10) voice — only when the wav is actually on disk.
|
||
if (scene.voicePath && existsSync(join(hyperframesDir, scene.voicePath))) {
|
||
body.push(` <!-- voice ${sid} (${start} → ${Number((start + dur).toFixed(3))}) -->`);
|
||
body.push(
|
||
` <audio`,
|
||
` id="el-${sid}-voice"`,
|
||
` class="clip"`,
|
||
` src="${scene.voicePath}"`,
|
||
` data-start="${start}"`,
|
||
` data-duration="${voiceDur}"`,
|
||
` data-track-index="10"`,
|
||
` ></audio>`,
|
||
"",
|
||
);
|
||
voiceCount++;
|
||
} else if (scene.voicePath) {
|
||
anomalies.push(`${sid}: voicePath "${scene.voicePath}" not on disk — skipped voice <audio>`);
|
||
}
|
||
}
|
||
|
||
// (track 11) BGM — Lyria is spawned detached and may not have landed yet, so
|
||
// re-check disk here (group_spec / audio_meta only promise the path).
|
||
let bgmEmitted = false;
|
||
const bgmPath = groupSpec.bgm_path;
|
||
if (bgmPath) {
|
||
if (existsSync(join(hyperframesDir, bgmPath))) {
|
||
body.push(
|
||
` <!-- BGM -->`,
|
||
` <audio`,
|
||
` id="el-bgm"`,
|
||
` class="clip"`,
|
||
` src="${bgmPath}"`,
|
||
` data-start="0"`,
|
||
` data-duration="${totalDuration}"`,
|
||
` data-track-index="11"`,
|
||
` data-volume="${BGM_VOLUME}"`,
|
||
` ></audio>`,
|
||
"",
|
||
);
|
||
bgmEmitted = true;
|
||
} else {
|
||
anomalies.push(`bgm_path "${bgmPath}" not on disk (still rendering?) — skipped BGM <audio>`);
|
||
}
|
||
}
|
||
|
||
// (track 12) captions — captions agent writes this or skips; key off existence.
|
||
let captionsEmitted = false;
|
||
if (existsSync(join(hyperframesDir, "compositions/captions.html"))) {
|
||
body.push(
|
||
` <!-- captions -->`,
|
||
` <div`,
|
||
` id="el-captions"`,
|
||
` data-composition-id="captions"`,
|
||
` data-composition-src="compositions/captions.html"`,
|
||
` data-start="0"`,
|
||
` data-duration="${totalDuration}"`,
|
||
` data-track-index="12"`,
|
||
` data-width="${WIDTH}"`,
|
||
` data-height="${HEIGHT}"`,
|
||
` ></div>`,
|
||
"",
|
||
);
|
||
captionsEmitted = true;
|
||
}
|
||
|
||
// (track 20+i) SFX — emitted verbatim from group_spec.sfx[] (already sorted by
|
||
// t, file checked against the manifest, duration locked to manifest truth by
|
||
// prep). Correct-by-construction; verify-output.mjs sfx re-asserts this against the
|
||
// emitted html as the orchestrator's deterministic gate.
|
||
const sfx = Array.isArray(groupSpec.sfx) ? groupSpec.sfx : [];
|
||
let sfxEmitted = 0;
|
||
sfx.forEach((cue, i) => {
|
||
const rel = `assets/sfx/${cue.file}`;
|
||
if (!existsSync(join(hyperframesDir, rel))) {
|
||
anomalies.push(
|
||
`sfx "${cue.file}" not on disk at ${rel} — skipped (prep should have copied it)`,
|
||
);
|
||
return;
|
||
}
|
||
const vol = cue.volume != null ? cue.volume : 0.35;
|
||
if (sfxEmitted === 0) body.push(` <!-- SFX -->`);
|
||
body.push(
|
||
` <audio`,
|
||
` id="el-sfx-${i}"`,
|
||
` class="clip"`,
|
||
` src="${rel}"`,
|
||
` data-start="${cue.t}"`,
|
||
` data-duration="${cue.duration}"`,
|
||
` data-track-index="${20 + i}"`,
|
||
` data-volume="${vol}"`,
|
||
` ></audio>`,
|
||
);
|
||
sfxEmitted++;
|
||
});
|
||
|
||
// ---------- <head> style: proven base + global brand tokens + optional @font-face ----------
|
||
const fontFaceCss = (groupSpec.font_face_css || "").trim();
|
||
const brandTokensCss = (groupSpec.brand_tokens_css || "").trim();
|
||
const headStyle = [
|
||
" * {",
|
||
" margin: 0;",
|
||
" padding: 0;",
|
||
" box-sizing: border-box;",
|
||
" }",
|
||
" html,",
|
||
" body {",
|
||
" margin: 0;",
|
||
` width: ${WIDTH}px;`,
|
||
` height: ${HEIGHT}px;`,
|
||
" overflow: hidden;",
|
||
" background: #000;",
|
||
" }",
|
||
" #root {",
|
||
" position: relative;",
|
||
` width: ${WIDTH}px;`,
|
||
` height: ${HEIGHT}px;`,
|
||
" overflow: hidden;",
|
||
" }",
|
||
" /* Sub-comp slots stretch to fill the root */",
|
||
" #root > div[data-composition-src] {",
|
||
" position: absolute;",
|
||
" inset: 0;",
|
||
" }",
|
||
];
|
||
if (brandTokensCss) {
|
||
// Global brand tokens — declared ONCE here. CSS custom properties inherit
|
||
// through the light DOM into every mounted sub-composition, so scenes use
|
||
// var(--*) without re-declaring this block locally. A scene may still override
|
||
// a token on its own #root (cascade) when it needs to (e.g. a dark scene).
|
||
headStyle.push("", " /* Brand design tokens (from design-system/chunks/tokens.css) */");
|
||
for (const line of brandTokensCss.split("\n")) headStyle.push(` ${line}`);
|
||
}
|
||
if (fontFaceCss) {
|
||
headStyle.push("", " /* Brand fonts (extracted by prep.mjs from design.html) */");
|
||
for (const line of fontFaceCss.split("\n")) headStyle.push(` ${line}`);
|
||
}
|
||
|
||
// ---------- assemble document ----------
|
||
const html = `<!doctype html>
|
||
<html lang="en">
|
||
<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"></script>
|
||
<style>
|
||
${headStyle.join("\n")}
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<div
|
||
id="root"
|
||
data-composition-id="main"
|
||
data-start="0"
|
||
data-duration="${totalDuration}"
|
||
data-width="${WIDTH}"
|
||
data-height="${HEIGHT}"
|
||
>
|
||
${body.join("\n")}
|
||
</div>
|
||
|
||
<script>
|
||
window.__timelines = window.__timelines || {};
|
||
window.__timelines["main"] = gsap.timeline({ paused: true });
|
||
</script>
|
||
</body>
|
||
</html>
|
||
`;
|
||
|
||
writeFileSync(outPath, html);
|
||
|
||
// ---------- caption-overrides.json shim ----------
|
||
// The captions runtime fetches this file at validate time; absence yields a
|
||
// noisy validate ✗ that previously sent finalize on a ~30s debug chase. An
|
||
// empty array is a no-op override list — semantically identical to absent —
|
||
// but the file existing silences validate. preflight-finalize.mjs writes the
|
||
// same shim defensively in case this engine is bypassed on a resume path.
|
||
const captionOverridesPath = join(hyperframesDir, "caption-overrides.json");
|
||
let captionOverridesCreated = false;
|
||
if (!existsSync(captionOverridesPath)) {
|
||
writeFileSync(captionOverridesPath, "[]\n");
|
||
captionOverridesCreated = true;
|
||
}
|
||
|
||
// ---------- summary ----------
|
||
console.log(`✓ wrote ${outPath}`);
|
||
console.log(` visual (track 0): ${visualClips.length} clip(s) for ${playOrder.length} scene(s)`);
|
||
console.log(` voice (track 10): ${voiceCount}`);
|
||
console.log(` bgm (track 11): ${bgmEmitted ? `yes (vol ${BGM_VOLUME})` : "no"}`);
|
||
console.log(` captions (track 12): ${captionsEmitted ? "yes" : "no"}`);
|
||
console.log(
|
||
` sfx (track 20+): ${sfxEmitted}${sfx.length !== sfxEmitted ? ` (${sfx.length - sfxEmitted} skipped)` : ""}`,
|
||
);
|
||
console.log(` total duration: ${totalDuration}s`);
|
||
console.log(` @font-face: ${fontFaceCss ? `${fontFaceCss.length}B injected` : "none"}`);
|
||
if (captionOverridesCreated) console.log(` caption-overrides.json: created empty [] shim`);
|
||
if (anomalies.length) {
|
||
console.log(`\nanomalies (non-fatal):`);
|
||
for (const a of anomalies) console.log(` - ${a}`);
|
||
}
|