Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: keep new code-video helpers reachable (#9076)
[._.]/ Adam Eivy93e48f405bed
diff --git a/server/services/musicVideo/codeComposition.js b/server/services/musicVideo/codeComposition.jsindex 4916ab246c..3e0d90737e 100644--- a/server/services/musicVideo/codeComposition.js+++ b/server/services/musicVideo/codeComposition.js@@ -61,13 +61,3 @@ try { parent.postMessage({ type: 'mv-code:ready', durationSec: ${durationSec} },return { html, song, durationSec, fps, width, height, windowStart: Number(windowStart) || 0 };}-/** The inlined song.json document, for tests that the page and the file match. */-export function embeddedSong(html) {- const marker = 'const SONG = ';- const start = html.indexOf(marker);- if (start < 0) return null;- const jsonStart = start + marker.length;- const end = html.indexOf(';\n', jsonStart);- if (end < 0) return null;- return JSON.parse(html.slice(jsonStart, end));-}diff --git a/server/services/musicVideo/codeFrame.js b/server/services/musicVideo/codeFrame.jsindex 7baa292542..9e67a60970 100644--- a/server/services/musicVideo/codeFrame.js+++ b/server/services/musicVideo/codeFrame.js@@ -22,7 +22,7 @@ export const CODE_EARLY_DIM_SEC = 0.4;const FONT_STACKS = { sans: 'sans-serif', serif: 'serif', mono: 'monospace' };/** How one lyric word looks at time `t`. The highlight never starts early. */-export function wordAppearance(word, t) {+function wordAppearance(word, t) {const start = word.startSec;const end = typeof word.endSec === 'number' && word.endSec > start ? word.endSec : start + 0.35;const dimAt = Math.max(0, start - CODE_EARLY_DIM_SEC);@@ -41,7 +41,7 @@ function lineEnd(line) {}/** A line is on screen from 0.4s before its first word through its end. */-export function lineActive(line, t) {+function lineActive(line, t) {const start = line.words?.[0]?.startSec ?? line.startSec ?? 0;return t >= start - CODE_EARLY_DIM_SEC && t < lineEnd(line);}@@ -101,7 +101,7 @@ export function drawCodeFrame({ ctx, song, palette, sources, t, width, height, fctx.fillRect(safe.x, safe.y, band, band);}paintKaraoke(ctx, { palette, safe, karaoke });- return { frame, sectionId: section.id };+ return { frame, sectionId: section.id, karaoke };}function lockClock() {@@ -153,12 +153,6 @@ function paintKaraoke(ctx, { palette, safe, karaoke }) {}}-/** A section body the tests and the fallback provider share. Color is literal. */-export function fixtureSectionSource(color) {- const ink = JSON.stringify(color);- return `function render(ctx, env) {\n ctx.fillStyle = ${ink};\n ctx.fillRect(env.safe.x, env.safe.y, 12 + (env.frame % 3), 12);\n}`;-}-function parseHex(style) {const match = /^#([0-9a-f]{6})$/i.exec(String(style || ''));if (!match) return [0, 0, 0];@@ -167,7 +161,7 @@ function parseHex(style) {}/** Canvas stand-in so a seek can be compared without a browser. */-export function createSoftwareCanvas(width, height) {+function createSoftwareCanvas(width, height) {const data = new Uint8ClampedArray(width * height * 4);const stack = [];const state = { fillStyle: '#000000', globalAlpha: 1, font: '16px sans-serif', textAlign: 'left', textBaseline: 'alphabetic' };@@ -232,8 +226,8 @@ function sandboxCompile(source) {);}-/** Paint `t` and return the pixel buffer plus the lyric placements. */-export function sampleFrame({ song, palette, sources, t, width, height, fps = CODE_FPS }) {+/** Paint `t` and return the pixel buffer plus the lyric placements. Test hook. */+export function _sampleFrame({ song, palette, sources, t, width, height, fps = CODE_FPS }) {const ctx = createSoftwareCanvas(width, height);const meta = drawCodeFrame({ ctx, song, palette, sources, t, width, height, fps, compile: sandboxCompile });return { data: ctx.data, textOps: ctx.textOps, ...meta, width, height };@@ -254,8 +248,3 @@ export function codeRuntimeSource() {].map((part) => (typeof part === 'function' ? part.toString() : part)).join('\n');}-export function samePixels(a, b) {- if (a.length !== b.length) return false;- for (let i = 0; i < a.length; i += 1) if (a[i] !== b[i]) return false;- return true;-}diff --git a/server/services/musicVideo/codeFrame.test.js b/server/services/musicVideo/codeFrame.test.jsindex b7d395305b..cdea8b9c66 100644--- a/server/services/musicVideo/codeFrame.test.js+++ b/server/services/musicVideo/codeFrame.test.js@@ -1,8 +1,24 @@import { describe, expect, it } from 'vitest';-import { buildCodeDocument, embeddedSong } from './codeComposition.js';-import { CODE_EARLY_DIM_SEC, fixtureSectionSource, lineActive, sampleFrame, samePixels, wordAppearance } from './codeFrame.js';+import { buildCodeDocument } from './codeComposition.js';+import { _sampleFrame } from './codeFrame.js';import { buildSongDocument, paletteFromProject } from './codeTimeline.js';+const fixtureSectionSource = (color) => `function render(ctx, env) {\n ctx.fillStyle = ${JSON.stringify(color)};\n ctx.fillRect(env.safe.x, env.safe.y, 12 + (env.frame % 3), 12);\n}`;++function samePixels(a, b) {+ if (a.length !== b.length) return false;+ for (let i = 0; i < a.length; i += 1) if (a[i] !== b[i]) return false;+ return true;+}++function embeddedSong(html) {+ const marker = 'const SONG = ';+ const start = html.indexOf(marker);+ const jsonStart = start + marker.length;+ const end = html.indexOf(';\n', jsonStart);+ return JSON.parse(html.slice(jsonStart, end));+}+const project = {audioAnalysis: {durationSec: 2,@@ -23,7 +39,7 @@ const project = {function frameAt(sources, t) {const song = buildSongDocument(project);- return sampleFrame({+ return _sampleFrame({song, palette: paletteFromProject(project), sources, t, width: 320, height: 180, fps: song.fps,});}@@ -47,14 +63,14 @@ describe('code frame contract (#9076)', () => {});it('highlights a word only at its start and keeps the line inside the safe area', () => {- const word = { text: 'hello', startSec: 0.2, endSec: 0.6 };- expect(wordAppearance(word, 0.2 - CODE_EARLY_DIM_SEC - 0.05).opacity).toBe(0);- expect(wordAppearance(word, 0.2 - 0.01).highlight).toBe(false);- expect(wordAppearance(word, 0.2).highlight).toBe(true);- const song = buildSongDocument(project);- const line = song.lyrics[0];- expect(lineActive(line, 0.5)).toBe(true);- const painted = frameAt({ a: fixtureSectionSource('#2244aa'), b: fixtureSectionSource('#aa4422') }, 0.5);+ const sources = { a: fixtureSectionSource('#2244aa'), b: fixtureSectionSource('#aa4422') };+ const before = frameAt(sources, 0.19);+ const helloEarly = before.karaoke.flatMap((line) => line.words).find((word) => word.text === 'hello');+ expect(helloEarly.highlight).toBe(false);+ expect(frameAt(sources, 1.7).karaoke).toEqual([]);+ const painted = frameAt(sources, 0.5);+ const hello = painted.karaoke.flatMap((line) => line.words).find((word) => word.text === 'hello');+ expect(hello.highlight).toBe(true);expect(painted.textOps.map((op) => op.text)).toEqual(expect.arrayContaining(['hello', 'there']));const safe = { x: 320 * 0.1, y: 180 * 0.1, w: 320 * 0.8, h: 180 * 0.8 };for (const op of painted.textOps) {diff --git a/server/services/musicVideo/codeGeneration.test.js b/server/services/musicVideo/codeGeneration.test.jsindex 052bb9f78b..dddb902a83 100644--- a/server/services/musicVideo/codeGeneration.test.js+++ b/server/services/musicVideo/codeGeneration.test.js@@ -1,5 +1,5 @@import { beforeEach, describe, expect, it, vi } from 'vitest';-import { fixtureSectionSource } from './codeFrame.js';+const fixtureSectionSource = (color) => `function render(ctx, env) {\n ctx.fillStyle = ${JSON.stringify(color)};\n ctx.fillRect(env.safe.x, env.safe.y, 12 + (env.frame % 3), 12);\n}`;const h = vi.hoisted(() => ({ project: null, calls: 0, response: '' }));diff --git a/server/services/musicVideo/codeRender.js b/server/services/musicVideo/codeRender.jsindex deadc7212e..068baa644b 100644--- a/server/services/musicVideo/codeRender.js+++ b/server/services/musicVideo/codeRender.js@@ -18,7 +18,7 @@ import { buildCodeTimeline, buildSongDocument, codeFrameSize, paletteFromProject// so unit tests of the footage renderer can keep a partial ffmpeg mock.const AAC_MUX_ARGS = Object.freeze(['-c:a', 'aac', '-b:a', '192k']);-export function muxExactArgs(videoPath, audioPath, outputPath, durationSec, audioStartSec = 0) {+export function _muxExactArgs(videoPath, audioPath, outputPath, durationSec, audioStartSec = 0) {const args = ['-hide_banner', '-loglevel', 'error', '-i', videoPath];if (audioStartSec > 0) args.push('-ss', String(audioStartSec));args.push(@@ -92,7 +92,7 @@ export async function encodeCodeComposition({});signal?.throwIfAborted();const mux = await runFfmpegProcess({- bin: ffmpeg, signal, args: muxExactArgs(silent, audioPath, outputPath, durationSec, audioStartSec),+ bin: ffmpeg, signal, args: _muxExactArgs(silent, audioPath, outputPath, durationSec, audioStartSec),});if (!mux.ok) {if (signal?.aborted || /cancelled/.test(mux.reason || '')) {diff --git a/server/services/musicVideo/codeRender.test.js b/server/services/musicVideo/codeRender.test.jsindex da8ee97ae3..343dd79266 100644--- a/server/services/musicVideo/codeRender.test.js+++ b/server/services/musicVideo/codeRender.test.js@@ -4,7 +4,7 @@ import { tmpdir } from 'os';import { join } from 'path';import { findFfmpeg, probeVideoDuration, runFfmpegProcess } from '../../lib/ffmpeg.js';import { pcmToWavBuffer } from '../../lib/chiptuneRender.js';-import { prepareCodeRender, muxExactArgs } from './codeRender.js';+import { prepareCodeRender, _muxExactArgs } from './codeRender.js';const ffmpeg = await findFfmpeg();@@ -50,13 +50,13 @@ describe.skipIf(!ffmpeg)('code render mux (#9076)', () => {await writeFile(wav, pcmToWavBuffer(samples, { sampleRate: rate }));const muxed = await runFfmpegProcess({bin: ffmpeg,- args: muxExactArgs(silent, wav, out, plan.durationSec, 0),+ args: _muxExactArgs(silent, wav, out, plan.durationSec, 0),});expect(muxed.ok).toBe(true);const duration = await probeVideoDuration(out);expect(Math.abs(duration - plan.durationSec)).toBeLessThan(1 / 24 + 0.02);expect(duration).toBeGreaterThanOrEqual(2.01 - 1 / 24);- const args = muxExactArgs(silent, wav, out, plan.durationSec, 0).join(' ');+ const args = _muxExactArgs(silent, wav, out, plan.durationSec, 0).join(' ');expect(args).not.toContain('afade');expect(await readFile(out)).toBeInstanceOf(Buffer);} finally {diff --git a/server/services/musicVideo/codeTimeline.test.js b/server/services/musicVideo/codeTimeline.test.jsindex 9d4386bb74..0a803e5a27 100644--- a/server/services/musicVideo/codeTimeline.test.js+++ b/server/services/musicVideo/codeTimeline.test.js@@ -2,7 +2,8 @@ import { describe, expect, it } from 'vitest';import { PORTOS_SCHEMA_VERSIONS } from '../../lib/schemaVersions.js';import { normalizeComposition } from './composition.js';import { buildCodeTimeline, buildSongDocument, quantizeSongDuration } from './codeTimeline.js';-import { fixtureSectionSource } from './codeFrame.js';++const fixtureSectionSource = (color) => `function render(ctx, env) {\n ctx.fillStyle = ${JSON.stringify(color)};\n ctx.fillRect(env.safe.x, env.safe.y, 12 + (env.frame % 3), 12);\n}`;const project = {name: 'Click',