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(
` `,
);
body.push(
`
`,
"",
);
}
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(` `);
body.push(
`
`,
"",
);
voiceCount++;
} else if (scene.voicePath) {
anomalies.push(`${sid}: voicePath "${scene.voicePath}" not on disk — skipped voice
`);
}
}
// (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(
` `,
` `,
"",
);
bgmEmitted = true;
} else {
anomalies.push(`bgm_path "${bgmPath}" not on disk (still rendering?) — skipped BGM `);
}
}
// (track 12) captions — captions agent writes this or skips; key off existence.
let captionsEmitted = false;
if (existsSync(join(hyperframesDir, "compositions/captions.html"))) {
body.push(
` `,
`
`,
"",
);
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(` `);
body.push(
` `,
);
sfxEmitted++;
});
// ---------- 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 = `
${body.join("\n")}
`;
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}`);
}