Explainer videos and product demos made by your AI agent. Free and open source: a local voice (Kokoro), word timing (Whisper) and a canvas renderer turn a script into a narrated MP4.
JavaScript ai-agentsanimationcanvasclaude-codecodexexplainer-videoffmpegjavascriptkokoroproduct-demotext-to-speechvideo-generationwhisper
Follow-up fixes: terminal output lines, word fades, code highlight, chart labels and bursts follow the pace; the preview server resolves symlinks before serving and refuses symlinked uploads
Vincent Schmalbachb617a7a3b5dd
diff --git a/engine/stage.js b/engine/stage.jsindex c015bde..9a7f2a5 100644--- a/engine/stage.js+++ b/engine/stage.js@@ -552,7 +552,7 @@ export class Stage {lay.lines.forEach((line) => {const lx0 = ox + lineStartX(line, lay.width, align);for (const w of line.words) {- const k = clamp((this.t - times[w.index]) / 0.22);+ const k = clamp((this.t - times[w.index]) / (0.22 / this.pace));if (k <= 0) continue;drawWord(w, lx0 + w.x, oy + line.y, ease.out(k), (1 - ease.out(k)) * 14);}@@ -1128,7 +1128,7 @@ export class Stage {if (d.label !== undefined) {const ls = o.labelSize ?? 34;ctx.save();- ctx.globalAlpha *= clamp((this.t - at) / 0.4);+ ctx.globalAlpha *= clamp((this.t - at) / (0.4 / this.pace));ctx.font = fontString(th, 'body', ls);ctx.fillStyle = colorOf(th, 'muted');ctx.textAlign = 'center';@@ -1296,7 +1296,7 @@ export class Stage {}if (o.highlight) {const hl = Array.isArray(o.highlight) ? o.highlight : [o.highlight];- const ha = clamp((this.t - this.time(o.highlightAt ?? at + 0.4)) / 0.4);+ const ha = clamp((this.t - this.time(o.highlightAt ?? at + 0.4 / this.pace)) / (0.4 / this.pace));if (ha > 0) {ctx.save();ctx.globalAlpha *= ha;@@ -1376,7 +1376,7 @@ export class Stage {this._record('terminal', r.start, r.end - r.start, { sfx: o.sfx }, { label: String(it.cmd).slice(0, 20), sustain: true });} else {r.end = r.start;- clock = r.start + (o.lineGap ?? 0.25);+ clock = r.start + (o.lineGap ?? 0.25) / this.pace;}return r;});@@ -1459,7 +1459,8 @@ export class Stage {const x = o.x ?? this.cx;const y = o.y ?? this.cy;this._record('burst', at, 0.6, o);- const k = this.t - at;+ // Particle physics run on pace-scaled time, so a faster video bursts faster.+ const k = (this.t - at) * this.pace;if (k < 0 || k > (o.life ?? 2.2)) return;const ctx = this.ctx;const count = o.count ?? 42;diff --git a/src/server.js b/src/server.jsindex 2236081..692cb95 100644--- a/src/server.js+++ b/src/server.js@@ -41,19 +41,48 @@ function safeJoin(base, rel) {// JSON, Markdown or text files, which can hold keys or private notes.const PROJECT_FILES = /\.(m?js|png|jpe?g|webp|gif|svg|wav|mp3|mp4)$/i;-function projectFile(projectDir, rel) {+function allowedName(rel) {const parts = rel.split(/[\\/]+/);- if (parts.some((x) => x.startsWith('.')) || !PROJECT_FILES.test(rel)) return null;- return safeJoin(projectDir, rel);+ return !parts.some((x) => x.startsWith('.')) && PROJECT_FILES.test(rel);+}++function realInside(base, target) {+ const root = fs.realpathSync(base);+ return target === root || target.startsWith(root + path.sep);+}++// The rules apply to where a file really is: a symlink such as+// assets/logo.png -> ../../.env is followed and then refused.+function projectFile(projectDir, rel) {+ if (!allowedName(rel)) return null;+ const file = safeJoin(projectDir, rel);+ if (!file || !fs.existsSync(file)) return null;+ const real = fs.realpathSync(file);+ if (!realInside(projectDir, real)) return null;+ const realRel = path.relative(fs.realpathSync(projectDir), real);+ return allowedName(realRel) ? real : null;}-// Uploads from the page may only land in build/ or out/, checked after the-// path is normalized so "build/../scenes.js" is refused.+// Uploads from the page may only land in build/ or out/: checked after the+// path is normalized (so "build/../scenes.js" is refused), and again on the+// real folder, and never onto a symlink.function uploadFile(projectDir, rel) {const dest = safeJoin(projectDir, rel);if (!dest) return null;- const inside = ['build', 'out'].some((d) => dest.startsWith(path.join(projectDir, d) + path.sep));- return inside ? dest : null;+ const root = ['build', 'out'].find((d) => dest.startsWith(path.join(projectDir, d) + path.sep));+ if (!root) return null;+ const realProject = fs.realpathSync(projectDir);+ const realRoot = path.join(realProject, root);+ const underRoot = (p) => p === realRoot || p.startsWith(realRoot + path.sep);+ // Check the folders that already exist before creating any.+ let probe = path.dirname(dest);+ while (!fs.existsSync(probe)) probe = path.dirname(probe);+ const realProbe = fs.realpathSync(probe);+ if (realProbe !== realProject && !underRoot(realProbe)) return null;+ fs.mkdirSync(path.dirname(dest), { recursive: true });+ if (!underRoot(fs.realpathSync(path.dirname(dest)))) return null;+ if (fs.existsSync(dest) && fs.lstatSync(dest).isSymbolicLink()) return null;+ return dest;}export function startServer({ projectDir, getState, port = 0 }) {@@ -74,7 +103,6 @@ export function startServer({ projectDir, getState, port = 0 }) {const rel = url.searchParams.get('path') || '';const dest = uploadFile(projectDir, rel);if (!dest) return send(res, 400, 'uploads go to build/ or out/');- fs.mkdirSync(path.dirname(dest), { recursive: true });const chunks = [];for await (const c of req) chunks.push(c);fs.writeFileSync(dest, Buffer.concat(chunks));diff --git a/test/server.test.js b/test/server.test.jsindex efb5105..58d3258 100644--- a/test/server.test.js+++ b/test/server.test.js@@ -42,6 +42,22 @@ test('the preview server keeps secrets and sources safe', async () => {assert.equal(fs.readFileSync(path.join(dir, 'scenes.js'), 'utf8'), 'export default {};');assert.equal((await put('out/stills/a.png')).status, 200);assert.ok(fs.existsSync(path.join(dir, 'out', 'stills', 'a.png')));++ // Symlinks do not get around the rules.+ const outside = fs.mkdtempSync(path.join(os.tmpdir(), 'explainroo-outside-'));+ fs.writeFileSync(path.join(outside, 'secret.png'), 'outside');+ fs.symlinkSync(path.join(dir, '.env'), path.join(dir, 'assets', 'alias.png'));+ fs.symlinkSync(path.join(outside, 'secret.png'), path.join(dir, 'assets', 'away.png'));+ assert.equal((await request(port, { path: '/project/assets/alias.png' })).status, 404);+ assert.equal((await request(port, { path: '/project/assets/away.png' })).status, 404);+ fs.mkdirSync(path.join(dir, 'build'), { recursive: true });+ fs.symlinkSync(path.join(dir, 'scenes.js'), path.join(dir, 'build', 'source-link.js'));+ assert.equal((await put('build/source-link.js')).status, 400);+ assert.equal(fs.readFileSync(path.join(dir, 'scenes.js'), 'utf8'), 'export default {};');+ fs.symlinkSync(outside, path.join(dir, 'out', 'elsewhere'));+ assert.equal((await put('out/elsewhere/x.png')).status, 400);+ assert.ok(!fs.existsSync(path.join(outside, 'x.png')));+ fs.rmSync(outside, { recursive: true, force: true });} finally {await server.close();fs.rmSync(dir, { recursive: true, force: true });