Skip to content
← Public packages

@kentcdodds/kody-connect-talk

Kent C. Dodds's Cloudflare Connect 2026 talk: why your agents' stuff needs a common house, and how Kody builds one on Cloudflare.

FollowForkOpen app

Files

build-deck.mjs

143 lines · 5.6 KB · JavaScript
// Assembles deck/slides.mjs into one HyperFrames composition at
// public/deck/index.html (the file the player loads and `hyperframes check`
// validates). Slide times are local in slides.mjs; this lays them end to end
// and writes absolute times into the scenes, the timeline, and the slideshow
// island.
import { copyFileSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
import { dirname, join } from 'node:path'
import { fileURLToPath, pathToFileURL } from 'node:url'
import { AGENT_POOL, WAYFIND_BADGE } from '../deck/lib.mjs'
import { DEFAULTS, layoutSlide, measureSteps } from '../deck/timing.mjs'

const root = join(dirname(fileURLToPath(import.meta.url)), '..')
const deckDir = join(root, 'deck')
const outDir = join(root, 'public', 'deck')

const round = (n) => Math.round(n * 1000) / 1000

function symbolFrom(file, id) {
	const svg = readFileSync(join(outDir, 'assets', 'agents', file), 'utf8')
	const viewBox = svg.match(/viewBox="([^"]+)"/)[1]
	const inner = svg
		.replace(/^[\s\S]*?<svg[^>]*>/, '')
		.replace(/<\/svg>\s*$/, '')
		.replace(/<title>[\s\S]*?<\/title>/, '')
	return `<symbol id="${id}" viewBox="${viewBox}" fill="currentColor">${inner}</symbol>`
}

export async function buildDeck() {
	// cache-bust so `vite` dev picks up edits to the slide modules
	const bust = `?t=${Date.now()}`
	const { slides } = await import(pathToFileURL(join(deckDir, 'slides.mjs')).href + bust)

	mkdirSync(join(outDir, 'vendor'), { recursive: true })
	copyFileSync(
		join(root, 'node_modules/@hyperframes/core/dist/hyperframe.runtime.iife.js'),
		join(outDir, 'vendor/hyperframe.runtime.iife.js'),
	)
	copyFileSync(join(root, 'node_modules/gsap/dist/gsap.min.js'), join(outDir, 'vendor/gsap.min.js'))

	let t = 0
	const scenes = []
	const anims = []
	const island = { slides: [] }

	for (const [i, s] of slides.entries()) {
		const T = t / 1000
		const next = slides[i + 1]
		const topicClass = s.topic ? ` t-${s.topic}` : ''
		const wipeTopic = s.exit === 'wipe' ? (s.wipeColor ?? s.nextTopic ?? next?.topic) : s.enter === 'wipe' ? s.topic : null
		const wipe = wipeTopic ? `<div class="wipe t-${wipeTopic}"></div>` : ''
		const sceneInner = (dur) => `<div class="scene${topicClass}" id="s-${s.id}" data-composition-id="${s.id}" data-start="${T}" data-duration="${dur}" data-label="${s.label.replace(/"/g, '&quot;')}" data-width="1920" data-height="1080">
<section class="clip stage${s.tinted ? ' tinted' : ''}${s.connect ? ' connect' : ''}" data-start="0" data-duration="${dur}" data-track-index="1">
<div class="inner">${s.html}</div>${wipe}
</section>
</div>`

		// Time comes from the steps themselves (see deck/timing.mjs).
		const { starts, stops, dur, exitAt } = layoutSlide(s, measureSteps(s, sceneInner(0)))
		scenes.push(`\n<!-- ${i + 1}. ${s.label} -->\n${sceneInner(dur)}`)

		s.steps.forEach((step, k) => {
			anims.push(`// ${s.id}, step ${k}\n(${step.toString()})(H.at(${round(T + starts[k])}, ${JSON.stringify(s.id)}), ${JSON.stringify(s.id)});`)
		})
		if (s.enter === 'wipe') {
			const [x, y] = s.wipeTo ?? WAYFIND_BADGE
			anims.push(`H.wipeOut(${JSON.stringify(s.id)}, ${T}, ${x}, ${y});`)
		}
		if (s.exit === 'wipe') {
			const [x, y] = s.wipeFrom ?? [960, 540]
			anims.push(`H.wipeIn(${JSON.stringify(s.id)}, ${round(T + exitAt)}, ${x}, ${y});`)
			anims.push(`H.out(${JSON.stringify(s.id)}, ${round(T + exitAt + 0.3)});`)
		} else if (s.exit !== 'none') {
			anims.push(`H.out(${JSON.stringify(s.id)}, ${round(T + exitAt)});`)
		}

		island.slides.push({
			sceneId: s.id,
			notes: s.notes,
			fragments: stops.map((h) => round(T + h)),
		})
		t += dur * 1000
	}
	const total = t / 1000

	const symbols = [
		...AGENT_POOL.map((name) => symbolFrom(`${name}.svg`, `ag-${name}`)),
		symbolFrom('cloudflare.svg', 'ag-cloudflare'),
		`<symbol id="g-person" viewBox="0 0 24 24"><circle cx="12" cy="8" r="4.2" fill="#fff"/><path d="M3.5 21c.8-4.6 4.2-7 8.5-7s7.7 2.4 8.5 7z" fill="#fff"/></symbol>`,
	].join('\n')

	const css = readFileSync(join(deckDir, 'deck.css'), 'utf8')
	const page = readFileSync(join(deckDir, 'page.js'), 'utf8')

	const out = `<!doctype html>
<!-- GENERATED by scripts/build-deck.mjs from deck/. Edit deck/slides.mjs, not this file. -->
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=1920, height=1080" />
<title>I Built Your Personal Software Ecosystem</title>
<script src="vendor/hyperframe.runtime.iife.js"></script>
<script src="vendor/gsap.min.js"></script>
<script>
// follow the presenter's theme choice before first paint
try { var th = localStorage.getItem("kody-deck-theme"); if (th === "light" || th === "dark") document.documentElement.dataset.theme = th; } catch (e) {}
</script>
<style>
${css}
</style>
</head>
<body>
<script type="application/hyperframes-slideshow+json">
${JSON.stringify(island, null, 2)}
</script>
<svg width="0" height="0" style="position:absolute" aria-hidden="true"><defs>
${symbols}
</defs></svg>
<div id="root" data-composition-id="deck" data-start="0" data-duration="${total}" data-width="1920" data-height="1080" style="position:relative;width:100%;height:100%;overflow:hidden">
${scenes.join('\n')}
</div>
<script>
const H_DEFAULTS = ${JSON.stringify(DEFAULTS)};
${page}
${anims.join('\n')}
window.__timelines = window.__timelines || {};
window.__timelines["deck"] = tl;
tl.seek(0);
startAmbient();
startWaitingRoom();
assignAgents();
startAgentSwaps();
</script>
</body>
</html>
`
	writeFileSync(join(outDir, 'index.html'), out)
	return { island, total, count: slides.length }
}

if (import.meta.url === pathToFileURL(process.argv[1]).href) {
	const { total, count } = await buildDeck()
	console.log(`deck: ${count} slides, ${total}s timeline → public/deck/index.html`)
}