// HTML builders used by slides.mjs. Everything here runs at build time in Node // and returns markup strings for the generated HyperFrames composition. export const html = String.raw export const TOPIC_NAMES = { search: 'search', execute: 'execute', mcp: 'MCP', cli: 'CLI', api: 'API', memory: 'memory', packages: 'packages', triggers: 'triggers', credentials: 'credentials', apps: 'apps', sharing: 'sharing', } export function esc(s) { // `{` as an entity: code samples show secret placeholders, and the literal // text in built HTML reads as a credential use to Kody's publish checks. return String(s).replace(/&/g, '&').replace(//g, '>').replace(/\{/g, '{').replace(/\}/g, '}').replace(/:/g, ':') } // Every topic gets the same mark: a disc in its hue with a drawn icon. export const TOPIC_HUES = { search: '#06b6d4', execute: '#10b981', mcp: '#6366f1', cli: '#84cc16', api: '#64748b', memory: '#ef4444', packages: '#3b82f6', triggers: '#eab308', credentials: '#22c55e', apps: '#a855f7', sharing: '#ec4899', secrets: '#14b8a6', } const ICONS = { search: '', execute: '', mcp: '', api: '', cli: '', sharing: '', memory: '', packages: '', triggers: '', credentials: '', apps: '', secrets: '', } /** A topic's mark: a disc in its hue with a white drawn icon. */ export function badge(topic, size = 96, { float = true, id = '', cls = '' } = {}) { const hue = TOPIC_HUES[topic] const r = (n) => Math.round(size * n) const inner = `${ICONS[topic]}` return `${inner}` } /** Features in a room or a list. Same mark as everywhere else. */ export const orb = (name, size = 96, opts = {}) => badge(name, size, opts) // Agents are picked at random on every load (page.js assignAgents), from the // coding agents Kody's site has logos for. export const AGENT_POOL = [ 'claudecode', 'claude', 'chatgpt', 'codex', 'cursor', 'gemini', 'goose', 'openclaw', 'zed', 'githubcopilot', 'devin', 'amp', 'warp', 'grok', 'grokbot', 'pi', ] /** * An agent logo slot. Slots in the same group get distinct agents; slots that * share a group and an index always show the same agent (so "your" agent stays * yours from slide to slide). */ export function agent(group, index, size = 56, { cls = '' } = {}) { return `` } /** A mouse pointer whose tip rests on the center of its (positioned) parent. */ export function cursor(id) { return `` } export function cfLogo(size = 34) { return `` } export function person(color = '', { id = '', name = '', style = '' } = {}) { const disc = `
` if (!name && !id && !style) return disc return `
${disc}${name ? `
${name}
` : ''}
` } export function house({ id, x, y, agent: logo = '', room = '', roomId = '', extra = '' }) { return html`
${logo}
${room}
${extra}
` } // ---------------------------------------------------------------- code const KEYWORDS = new Set([ 'import', 'from', 'export', 'default', 'async', 'function', 'await', 'const', 'return', 'let', 'new', ]) /** Minimal JS highlighter. Wrap a span of a line in ⟦…⟧ to mark it highlighted. */ export function highlight(src) { const out = [] const re = /(\/\/[^\n]*)|('(?:[^'\\]|\\.)*'|`(?:[^`\\]|\\.)*`|"(?:[^"\\]|\\.)*")|([A-Za-z_$][\w$]*)(?=\s*\()|([A-Za-z_$][\w$]*)|(⟦|⟧)|([\s\S])/g let m while ((m = re.exec(src))) { const [, com, str, fn, word, mark, other] = m if (com) out.push(`${esc(com)}`) else if (str) out.push(`${esc(str)}`) else if (fn) out.push(KEYWORDS.has(fn) ? `${fn}` : `${fn}`) else if (word) out.push(KEYWORDS.has(word) ? `${word}` : word) else if (mark) out.push(mark === '⟦' ? '' : '') else out.push(esc(other)) } return out.join('') } /** Code card. Each line gets its own span so lines can be revealed or highlighted. */ export function code(src, { id, x, y, w, size } = {}) { // ⟪ ⟫ stand in for double braces, so a credential placeholder shown on a slide // never appears as a string in this package's source (Kody's publish checks // read string literals and would treat it as a real credential use) src = src.replace(/⟪/g, '{'.repeat(2)).replace(/⟫/g, '}'.repeat(2)) const lines = src.replace(/^\n|\n\s*$/g, '').split('\n') const body = lines.map((l, i) => `${highlight(l) || ' '}`).join('\n') return `
${body}
` } export function term(lines, { id, x, y, w }) { const body = lines.map((l, i) => `
${l}
`).join('') return `
${body}
` } // ---------------------------------------------------------------- diagrams /** * Boxes plus flowing connectors. nodes: { id, x, y, w?, label, sub, cf, plain, cls }. * edges: [fromId, toId, { from: 'r'|'b'|'l'|'t', to: ..., cls, id }]. * Node heights are estimated so connector endpoints land on box edges. */ export function diagram(nodes, edges, { id = 'd' } = {}) { const byId = Object.fromEntries(nodes.map((n) => [n.id, { w: 360, h: n.sub ? 156 : 108, ...n }])) const point = (n, side) => { if (side === 'r') return [n.x + n.w, n.y + n.h / 2] if (side === 'l') return [n.x, n.y + n.h / 2] if (side === 'b') return [n.x + n.w / 2, n.y + n.h] return [n.x + n.w / 2, n.y] } const wires = edges .map(([a, b, o = {}], i) => { const A = byId[a] const B = byId[b] const fromSide = o.from ?? (B.x >= A.x + A.w ? 'r' : B.y > A.y ? 'b' : 't') const toSide = o.to ?? (fromSide === 'r' ? 'l' : fromSide === 'b' ? 't' : fromSide === 't' ? 'b' : 'r') const [x1, y1] = point(A, fromSide) const [x2r, y2r] = point(B, toSide) // stop short of the box so the arrowhead sits outside it const gap = 14 const dir = { l: [-1, 0], r: [1, 0], t: [0, -1], b: [0, 1] }[toSide] const x2 = x2r + dir[0] * gap const y2 = y2r + dir[1] * gap let d if (fromSide === 'r' && toSide === 'l' && Math.abs(y1 - y2) > 2) { const mx = (x1 + x2) / 2 d = `M${x1 + 10} ${y1} C${mx} ${y1} ${mx} ${y2} ${x2 - 6} ${y2}` } else if ((fromSide === 'b' || fromSide === 't') && toSide === 'l') { d = `M${x1} ${y1 + (fromSide === 'b' ? 10 : -10)} C${x1} ${y2} ${x1} ${y2} ${x2 - 6} ${y2}` } else { d = `M${x1 + (fromSide === 'r' ? 10 : 0)} ${y1 + (fromSide === 'b' ? 10 : fromSide === 't' ? -10 : 0)} L${x2 - dir[0] * 6} ${y2 - dir[1] * 6}` } const ang = { l: 0, r: 180, t: 90, b: 270 }[toSide] const head = `` return `${head}` }) .join('') const boxes = nodes .map((n) => { const N = byId[n.id] const cls = ['node', n.cf ? 'cf' : '', n.plain ? 'plain' : '', n.cls ?? ''].join(' ') const label = n.cf ? `${cfLogo(36)}${n.label}` : n.label return `
${label}
${n.sub ? `
${n.sub}
` : ''}
` }) .join('') return `${wires}${boxes}` } // ---------------------------------------------------------------- wayfinding export function wayfind(topic, step) { const steps = ['problem', 'solution', 'under the hood'] const i = { problem: 0, solution: 1, hood: 2 }[step] return html`
${badge(topic, 52, { float: false })}${TOPIC_NAMES[topic]}
${step ? `
${steps.map((s, j) => `${s}`).join('')}
` : ''}
` } /** Where the wayfinding badge sits, so color can collapse into it. */ export const WAYFIND_BADGE = [146, 998]