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(code-animation): stage each export in its own directory and reject non-basename tracks
[._.]/ Adam Eivyc751a00918c7
diff --git a/docs/HTML_COMPOSITIONS.md b/docs/HTML_COMPOSITIONS.mdindex 67e3f32844..e337497d6e 100644--- a/docs/HTML_COMPOSITIONS.md+++ b/docs/HTML_COMPOSITIONS.md@@ -119,7 +119,7 @@ launch-video artifacts are delivered. The completed job's result carriesrelative to the data directory (never an absolute host path) and `url` servesit under `/data/`; tile *n* shows `times[n]`.Launch runs write `proofs/contact-<jobId>.png` beside the run; other-compositions write `data/composition-proofs/`. Both are excluded from backups. Code Animation exports stage `data/code-animation-exports/<job-id>/` (also excluded): the stored HTML with a shim that maps `ANIMATION_META`/`renderFrame(t)` onto `portosComposition`, stops the page's own `requestAnimationFrame` clock, and hides everything but the film canvas.+compositions write `data/composition-proofs/`. Both are excluded from backups. Code Animation exports stage `data/code-animation-exports/<job-id>/<export-id>/` (also excluded): the stored HTML with a shim that maps `ANIMATION_META`/`renderFrame(t)` onto `portosComposition`, stops the page's own `requestAnimationFrame` clock, and hides everything but the film canvas.The 202 response contains the media queue's `jobId`. Subscribe to`GET /api/html-composition/:jobId/events` for the usual queued, started, progress,diff --git a/server/services/backup.js b/server/services/backup.jsindex ada6810dd3..e8e3b5eb51 100644--- a/server/services/backup.js+++ b/server/services/backup.js@@ -171,7 +171,7 @@ export const DEFAULT_EXCLUDES = [{ path: '/cos/reference-repos/', reason: 'Reference upstream repos used by agents — re-cloneable', overridable: true },{ path: '/browser-downloads/', reason: 'Browser downloads cache — large, re-downloadable', overridable: true },{ path: '/composition-proofs/', reason: 'HTML-composition contact-sheet proofs — review stills, re-rendered from the composition source', overridable: true },- { path: '/code-animation-exports/', reason: 'Code Animation frame-exact export staging — the stored HTML plus render shim, rebuilt on every export', overridable: true },+ { path: '/code-animation-exports/', reason: 'Code Animation frame-exact export staging — the stored HTML plus render shim, staged once per export', overridable: true },{ path: '/music-video-compositions/', reason: 'In-flight music-video typography overlay scratch — removed when its render ends and swept at boot', overridable: false },{ path: '/launch-videos/*/*/proofs/', reason: 'Launch-video critique-loop contact sheets — re-rendered from the run composition', overridable: true },{ path: '/cache/', reason: 'Remote-API metadata and licensed reading caches — regenerable on demand, and stale on restore anyway', overridable: false },diff --git a/server/services/codeAnimation/export.js b/server/services/codeAnimation/export.jsindex 15965e81f0..3eb2ef1544 100644--- a/server/services/codeAnimation/export.js+++ b/server/services/codeAnimation/export.js@@ -12,8 +12,9 @@* requestAnimationFrame clock, and hides everything but the film canvas.*/+import { randomUUID } from 'crypto';import { join } from 'path';-import { mkdir, rm } from 'fs/promises';+import { mkdir } from 'fs/promises';import { ServerError } from '../../lib/errorHandler.js';import { PATHS } from '../../lib/paths.js';import { atomicWrite } from '../../lib/fileUtils.js';@@ -89,7 +90,8 @@ function injectExportShim(html, shim) {// job stored for it.function musicTrackOf(job) {const match = /^\/data\/music\/([^/]+)$/.exec(job.audioUrl || '');- return match ? decodeURIComponent(match[1]) : null;+ const name = match ? decodeURIComponent(match[1]) : null;+ return name && !/[/\\]/.test(name) && name !== '..' && name !== '.' ? name : null;}/**@@ -119,10 +121,10 @@ export async function startCodeAnimationExport(id, deps = {}) {if (job.audioUrl && !musicTrack) notes.push('Uploaded audio is not muxed; the export is silent. Attach a Music-library track to include it.');if (durationSeconds > EXPORT_MAX_DURATION_SEC) notes.push(`The export is capped at ${EXPORT_MAX_DURATION_SEC}s; this animation runs ${durationSeconds}s.`);const song = musicTrack ? await beatGrid(musicTrack) : null;- const directory = `${EXPORT_DIRECTORY_ROOT}/${id}`;+ // One staging directory per export: a queued render snapshots its directory+ // only when it starts, so a later export must never rewrite an earlier one's.+ const directory = `${EXPORT_DIRECTORY_ROOT}/${id}/${randomUUID()}`;const dir = join(PATHS.data, directory);- // Re-stage from scratch so a stale asset from an earlier export never rides along.- await rm(dir, { recursive: true, force: true });await mkdir(dir, { recursive: true });await atomicWrite(join(dir, 'index.html'), injectExportShim(html, buildExportShim({ song })));const queued = await enqueueJob({ kind: 'html-composition', params: { directory, ...(musicTrack ? { musicTrack } : {}) } });diff --git a/server/services/codeAnimation/export.test.js b/server/services/codeAnimation/export.test.jsindex f32c912516..0cbd0af887 100644--- a/server/services/codeAnimation/export.test.js+++ b/server/services/codeAnimation/export.test.js@@ -18,14 +18,16 @@ vi.mock('./jobStore.js', () => ({const { startCodeAnimationExport } = await import('./export.js');+let lastDirectory;+const enqueueDirectory = () => lastDirectory;const JOB_ID = '11111111-2222-4333-8444-555555555555';// Stage an export of `pageScript` and run the staged document's scripts, in// order, in a minimal browser-like realm.async function runPage(pageScript, { song = null } = {}) {state.html = `<html><head></head><body><script>${pageScript}</script></body></html>`;- await startCodeAnimationExport(JOB_ID, { enqueueJob: async () => ({ jobId: 'm' }), beatGrid: async () => song });- const staged = await readFile(join(state.dataRoot, 'code-animation-exports', JOB_ID, 'index.html'), 'utf8');+ await startCodeAnimationExport(JOB_ID, { enqueueJob: async ({ params }) => { lastDirectory = params.directory; return { jobId: 'm' }; }, beatGrid: async () => song });+ const staged = await readFile(join(state.dataRoot, enqueueDirectory(), 'index.html'), 'utf8');const scripts = [...staged.matchAll(/<script>([\s\S]*?)<\/script>/g)].map((match) => match[1]);const listeners = {};const canvas = { width: 1920, height: 1080, setAttribute: vi.fn() };@@ -85,7 +87,7 @@ describe('startCodeAnimationExport', () => {state.dataRoot = await mkdtemp(join(tmpdir(), 'code-animation-export-'));state.html = '<!DOCTYPE html><html><head><title>x</title></head><body><script>window.renderFrame=()=>{}</script></body></html>';state.job = { id: JOB_ID, status: 'completed', frame: { width: 1920, height: 1080, fps: 30, durationSeconds: 20 }, audioUrl: '/data/music/Song%20A.mp3' };- enqueueJob = vi.fn(async () => ({ jobId: 'media-1', position: 1, status: 'queued' }));+ enqueueJob = vi.fn(async ({ params }) => { lastDirectory = params.directory; return { jobId: 'media-1', position: 1, status: 'queued' }; });});afterEach(async () => {await rm(state.dataRoot, { recursive: true, force: true });@@ -97,8 +99,8 @@ describe('startCodeAnimationExport', () => {expect(result).toMatchObject({ jobId: 'media-1', notes: [] });expect(beatGrid).toHaveBeenCalledWith('Song A.mp3');expect(enqueueJob).toHaveBeenCalledWith({ kind: 'html-composition',- params: { directory: `code-animation-exports/${JOB_ID}`, musicTrack: 'Song A.mp3' } });- const staged = await readFile(join(state.dataRoot, 'code-animation-exports', JOB_ID, 'index.html'), 'utf8');+ params: { directory: expect.stringMatching(new RegExp(`^code-animation-exports/${JOB_ID}/[0-9a-f-]{36}$`)), musicTrack: 'Song A.mp3' } });+ const staged = await readFile(join(state.dataRoot, enqueueDirectory(), 'index.html'), 'utf8');expect(staged.indexOf('portosComposition')).toBeLessThan(staged.indexOf('window.renderFrame=()=>{}'));expect(staged).toContain('"bpm":100');});@@ -107,7 +109,7 @@ describe('startCodeAnimationExport', () => {state.job = { ...state.job, audioUrl: '/api/uploads/take.wav', frame: { ...state.job.frame, durationSeconds: 180 } };const result = await startCodeAnimationExport(JOB_ID, { enqueueJob, beatGrid: vi.fn() });expect(result.notes).toHaveLength(2);- expect(enqueueJob.mock.calls[0][0].params).toEqual({ directory: `code-animation-exports/${JOB_ID}` });+ expect(Object.keys(enqueueJob.mock.calls[0][0].params)).toEqual(['directory']);});it('refuses frame sizes the composition renderer cannot encode and unfinished jobs', async () => {diff --git a/server/services/dataManager.js b/server/services/dataManager.jsindex 5ec192940b..bd8ca147ba 100644--- a/server/services/dataManager.js+++ b/server/services/dataManager.js@@ -81,7 +81,7 @@ export const CATEGORIES = {'composition-proofs': { label: 'Composition Proofs', description: 'Contact-sheet review stills from HTML-composition proof renders — re-rendered from source, safe to purge', archivable: false, deletable: true, purgeScope: 'category' },'music-video-compositions': { label: 'Music Video Overlay Scratch', description: 'Typography overlay frames for an in-flight composed music-video render — removed when the render ends and swept at boot', archivable: false, deletable: false },'code-animations': { label: 'Code Animations', description: 'Generated animation HTML retained with its job history — the only copy of provider-generated work', archivable: true, deletable: false },- 'code-animation-exports': { label: 'Code Animation Export Staging', description: 'Animation HTML plus the frame-exact render shim, rebuilt on every MP4 export — safe to purge', archivable: false, deletable: true, purgeScope: 'category' },+ 'code-animation-exports': { label: 'Code Animation Export Staging', description: 'Animation HTML plus the frame-exact render shim, staged once per MP4 export — safe to purge', archivable: false, deletable: true, purgeScope: 'category' },'commission-feedback': { label: 'Commission Feedback', description: 'Reactions on creative commissions (file mirror of the Postgres store)', archivable: true, deletable: false },'conflict-journal': { label: 'Conflict Journal', description: 'Peer-sync conflict history — diagnostics only, safe to purge', archivable: true, deletable: true, purgeScope: 'category' },'cos': { label: 'Chief of Staff', description: 'Agent data, reports, memories', archivable: true, deletable: false },