Text to vertical video in 100+ styles: AI codes each scene (HTML/SVG/WebGL), renders a 9:16 MP4 with music and English/Vietnamese voice. MCP, CLI and REST for AI agents.
// Kho job + pipeline: tạo job → (hẹn giờ) → sinh cảnh (api | claude | manual) → preview → render → chép ra OUTPUT_DIR.
// Dùng chung cho CLI, REST server và MCP server.
import fs from 'node:fs';
import path from 'node:path';
import crypto from 'node:crypto';
import { fileURLToPath } from 'node:url';
import { config, resolveModel } from './config.mjs';
import { buildPrompt } from './prompt.mjs';
import { runClaude, findClaude } from './claude.mjs';
import { runApi, authMessage } from './api.mjs';
import { cachedCheck } from './user-key.mjs';
import { preview } from '../engine/preview.mjs';
import { render } from '../engine/render.mjs';
import { lintScene, syncLib } from '../engine/lib.mjs';
import { normalizeAudioPrefs, styleFromGuidance } from '../engine/audio/prefs.mjs';
import { isRestrictedSource } from '../engine/sandbox.mjs';
import { resolveTemplate, readGuidance } from '../packs/registry.mjs';
import { normRatio, dimsOf } from '../engine/ratio.mjs';
export const ROOT = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
export const JOBS = path.join(ROOT, 'jobs');
export const TEMPLATES = path.join(ROOT, 'templates');
// Trạng thái: scheduled → queued → generating → (waiting_agent) → previewing → rendering → done | error
export const STATUS = ['scheduled', 'queued', 'generating', 'waiting_agent', 'previewing', 'rendering', 'done', 'error'];
// Chế độ: auto (api → claude → manual) | api | claude | manual (= agent: agent bên ngoài tự viết cảnh)
export const MODES = ['auto', 'api', 'claude', 'manual'];
/** Danh mục mẫu công khai: [{id, name, blurb, category, genre, technique[], difficulty, narration}]. */
export function loadCatalog() {
return JSON.parse(fs.readFileSync(path.join(TEMPLATES, 'catalog.json'), 'utf8'));
}
/** Ảnh lưới 4×4 của video tham chiếu (chỉ có trên máy đã chạy tools/fetch_refs.py; repo không kèm). */
export function refSheetPath(id) { return path.join(TEMPLATES, 'ref', id, 'sheet.jpg'); }
/** Tên phong cách hiện tại của mẫu (job cũ có thể còn lưu tên cũ trong templateTitle). id = mã tham chiếu (gốc hoặc gói). */
export function templateName(id) {
try { return resolveTemplate(id)?.meta.name || null; } catch { return null; }
}
/** File guidance của mẫu (qua packs/registry.mjs: gốc hoặc gói đã cài); mẫu gốc chưa có file vẫn trả đường dẫn cũ. */
export function guidancePath(id) {
const t = resolveTemplate(id);
return t?.file || path.join(TEMPLATES, 'guidance', `${id}.md`);
}
export function hasGuidance(id) { return !!resolveTemplate(id)?.file; }
/** Thư mục job, chặn path traversal: id chỉ gồm chữ/số/_/-, kết quả phải nằm trong jobs/. */
export function jobDir(id) {
if (typeof id !== 'string' || !/^[\w-]{1,80}$/.test(id)) throw new Error('jobId không hợp lệ');
const d = path.resolve(JOBS, id);
if (path.dirname(d) !== path.resolve(JOBS)) throw new Error('jobId không hợp lệ');
return d;
}
const jobFile = (id) => path.join(jobDir(id), 'job.json');
export function readJob(id) {
try { return JSON.parse(fs.readFileSync(jobFile(id), 'utf8')); } catch { return null; }
}
function writeJob(job) {
job.updatedAt = new Date().toISOString();
fs.writeFileSync(jobFile(job.id), JSON.stringify(job, null, 2));
return job;
}
export function listJobs() {
if (!fs.existsSync(JOBS)) return [];
return fs.readdirSync(JOBS).filter((d) => /^[\w-]+$/.test(d)).map(readJob).filter(Boolean)
.sort((a, b) => (a.createdAt < b.createdAt ? 1 : -1));
}
export function logTo(job) {
const f = path.join(jobDir(job.id), 'log.txt');
return (line) => fs.appendFileSync(f, `[${new Date().toISOString().slice(11, 19)}] ${line}\n`);
}
export function readLog(id, max = 200) {
try { return fs.readFileSync(path.join(jobDir(id), 'log.txt'), 'utf8').split('\n').filter(Boolean).slice(-max); } catch { return []; }
}
function update(id, patch) {
const cur = readJob(id);
Object.assign(cur, patch);
return writeJob(cur);
}
function setStatus(job, status, extra = {}) {
const cur = readJob(job.id) || job;
Object.assign(cur, extra, { status });
if (status !== 'error') delete cur.error;
writeJob(cur);
logTo(cur)(`trạng thái → ${status}${extra.error ? ': ' + extra.error : ''}`);
return cur;
}
/** Đổi chuỗi giờ (ISO, hoặc "2026-11-28T07:00" = giờ máy) thành ISO UTC. */
export function parseRunAt(v) {
if (v === undefined || v === null || v === '') return null;
const d = new Date(v);
if (Number.isNaN(d.getTime())) throw new Error(`Giờ hẹn không hiểu được: ${v} (dùng dạng 2026-11-28T07:00)`);
return d.toISOString();
}
// Thời lượng: 3 giây → 10 phút. Nhận số giây (8, 90) hoặc chuỗi "90", "90s", "1:30", "10:00".
export const MIN_DURATION_S = 3;
export const MAX_DURATION_S = 600;
/** Đổi thời lượng người dùng gõ thành số giây nguyên. Trống → mặc định (8). Sai dạng / ngoài 3s–10 phút → lỗi. */
export function parseDuration(v, fallback = 8) {
if (v === undefined || v === null || v === '') return fallback;
let s;
if (typeof v === 'number') s = v;
else {
const t = String(v).trim().toLowerCase().replace(/\s+/g, '');
let m;
if ((m = /^(\d{1,4})(?:s|giây|giay)?$/.exec(t))) s = Number(m[1]);
else if ((m = /^(\d{1,2}):([0-5]\d)$/.exec(t))) s = Number(m[1]) * 60 + Number(m[2]);
else if ((m = /^(\d{1,2})(?:m|p|phút|phut)$/.exec(t))) s = Number(m[1]) * 60;
else throw new Error(`Thời lượng không hiểu được: "${v}" (gõ số giây như 90, hoặc phút:giây như 1:30)`);
}
if (!Number.isFinite(s)) throw new Error(`Thời lượng không hợp lệ: ${v}`);
s = Math.round(s);
if (s < MIN_DURATION_S || s > MAX_DURATION_S) throw new Error(`Thời lượng ${s}s ngoài giới hạn ${MIN_DURATION_S} giây – 10 phút`);
return s;
}
/** 90 → "1:30"; 8 → "8s". */
export function fmtDuration(s) {
return s < 60 ? `${s}s` : `${Math.floor(s / 60)}:${String(s % 60).padStart(2, '0')}`;
}
/** Tạo job. input = {templateId, content, durationS=8, aspect='9:16' (| ratio: 9:16 · 16:9 · 4:3 · 3:4), mode, runAt?, source?} */
export function createJob(input) {
const raw = String(input.templateId || '').trim();
const t = resolveTemplate(raw);
if (!t) throw new Error(`Không có mẫu ${raw}`);
const templateId = t.ref;
if (!t.file) throw new Error(`Mẫu ${templateId} chưa có guidance`);
const tpl = { name: t.meta.name, technique: t.meta.technique };
const content = String(input.content || '').trim();
if (!content) throw new Error('Thiếu nội dung');
if (content.length > 4000) throw new Error('Nội dung quá dài (tối đa 4000 ký tự)');
const durationS = parseDuration(input.durationS);
const aspect = normRatio(input.aspect ?? input.ratio);
const { width, height } = dimsOf(aspect);
let mode = input.mode === 'agent' ? 'manual' : (input.mode || 'manual');
if (!MODES.includes(mode)) throw new Error(`Chế độ không hợp lệ: ${mode} (auto|api|claude|manual|agent)`);
const runAt = parseRunAt(input.runAt);
const audio = normalizeAudioPrefs(input.audio); // {music, voice, sfx} — xem engine/audio/prefs.mjs
const model = resolveModel(input.model, tpl.technique); // auto → Opus (3D/shader) | Sonnet (2D)
const stamp = new Date().toISOString().replace(/[-:T]/g, '').slice(2, 14);
// mẫu gói: mã tham chiếu có "." và "/" → id job dùng 6 hex đầu sha256(mã), vẫn khớp ^[\w-]{1,80}$
const tag = t.source === 'builtin' ? templateId : 'p' + crypto.createHash('sha256').update(templateId).digest('hex').slice(0, 6);
const id = `${stamp}-${tag}-${crypto.randomBytes(2).toString('hex')}`;
const dir = path.join(JOBS, id);
fs.mkdirSync(path.join(dir, 'scene'), { recursive: true });
const sheet = t.source === 'builtin' ? refSheetPath(templateId) : null; // L10: không đưa ảnh của gói cho AI
const hasRef = !!sheet && fs.existsSync(sheet);
if (hasRef) fs.copyFileSync(sheet, path.join(dir, 'ref-sheet.jpg'));
const job = {
id, templateId, templateTitle: tpl.name, templateSource: t.source, ...(t.packId ? { packId: t.packId } : {}), restricted: isRestrictedSource(t.source),
content, durationS, aspect, width, height, mode, hasRef, audio, model,
status: runAt && new Date(runAt) > new Date() ? 'scheduled' : 'queued',
runAt, source: input.source || 'api', createdAt: new Date().toISOString(),
};
fs.writeFileSync(path.join(dir, 'PROMPT.md'), buildPrompt(job));
writeJob(job);
logTo(job)(`tạo job: mẫu ${templateId} "${tpl.name}", ${durationS}s, khung ${aspect} (${width}×${height}), chế độ ${mode}, model ${model.alias} (${model.why})${runAt ? ', hẹn ' + runAt : ''} (từ ${job.source})`);
return job;
}
/** Tối đa số mẫu trong 1 lô (chọn nhiều mẫu cùng lúc). */
export const MAX_BATCH = 12;
/** "009,45, 062" | ['009', 45] → ['009','045','062'] (bỏ trùng, giữ thứ tự). */
export function parseTemplateIds(v) {
const raw = Array.isArray(v) ? v : String(v ?? '').split(/[\s,;]+/);
const ids = [];
for (const x of raw) {
const s = String(x ?? '').trim();
if (!s) continue;
const id = /^\d{1,3}$/.test(s) ? s.padStart(3, '0') : s;
if (!ids.includes(id)) ids.push(id);
}
return ids;
}
/**
* Kiểm cả lô TRƯỚC khi tạo (sai 1 thì từ chối cả lô, không tạo job nào): id phải có trong catalog + có guidance,
* và các trường chung (nội dung, thời lượng, chế độ, model, giờ hẹn, âm thanh) phải hợp lệ. Trả danh sách id đã chuẩn hoá.
*/
export function validateBatch(input) {
const ids = parseTemplateIds(input.templateIds);
if (!ids.length) throw new Error('Thiếu templateIds (chọn ít nhất 1 mẫu)');
if (ids.length > MAX_BATCH) throw new Error(`Tối đa ${MAX_BATCH} mẫu mỗi lô (đang có ${ids.length})`);
const cat = new Map(ids.map((id) => [id, resolveTemplate(id)]).filter(([, t]) => t).map(([id, t]) => [id, { technique: t.meta.technique, file: t.file }]));
const unknown = ids.filter((id) => !cat.has(id));
const noGuide = ids.filter((id) => cat.has(id) && !cat.get(id).file);
if (unknown.length || noGuide.length) {
const parts = [];
if (unknown.length) parts.push(`không có mẫu ${unknown.join(', ')}`);
if (noGuide.length) parts.push(`mẫu ${noGuide.join(', ')} chưa có guidance`);
const err = new Error(`Từ chối cả lô: ${parts.join('; ')}`);
err.badIds = [...unknown, ...noGuide];
throw err;
}
const content = String(input.content || '').trim();
if (!content) throw new Error('Thiếu nội dung');
if (content.length > 4000) throw new Error('Nội dung quá dài (tối đa 4000 ký tự)');
parseDuration(input.durationS);
normRatio(input.aspect ?? input.ratio);
const mode = input.mode === 'agent' ? 'manual' : (input.mode || 'manual');
if (!MODES.includes(mode)) throw new Error(`Chế độ không hợp lệ: ${mode} (auto|api|claude|manual|agent)`);
parseRunAt(input.runAt);
normalizeAudioPrefs(input.audio && typeof input.audio === 'object' ? { ...input.audio } : input.audio);
for (const id of ids) resolveModel(input.model, cat.get(id).technique);
return ids;
}
/** Tạo 1 job cho mỗi mẫu (cùng nội dung/thời lượng/âm thanh/chế độ/model). Kiểm hết trước (validateBatch). Trả mảng job. */
export function createJobs(input) {
const ids = validateBatch(input);
const { templateIds: _ignored, ...common } = input;
return ids.map((templateId) => createJob({ ...common, templateId }));
}
/** Kích thước khung của job (job cũ không có aspect → 9:16). */
export function jobDims(job) { return dimsOf(job?.aspect || '9:16'); }
/** Job có chạy khoá không (L1–L4): mẫu không phải gốc luôn khoá; mẫu gốc theo cờ LUMREELS_RESTRICT (tính lúc chạy). */
export function jobRestricted(job) {
return isRestrictedSource(job?.templateSource || 'builtin');
}
/** auto → api (có ANTHROPIC_API_KEY) → claude (có lệnh claude) → manual. */
export function resolveMode(mode) {
if (mode !== 'auto') return mode;
// khoá đã biết là sai (401/403 gần đây) mà máy có Claude Code → đi thẳng Claude Code, khỏi gọi API ăn 401 trước
if (config.hasApiKey() && !(cachedCheck(process.env.ANTHROPIC_API_KEY)?.valid === false && findClaude())) return 'api';
if (findClaude()) return 'claude';
return 'manual';
}
/** Thời gian tối đa cho Claude Code viết cảnh: 25 phút, video dài thêm 5 phút mỗi phút video (trần 90 phút). */
function claudeTimeoutMs(durationS = 8) {
return Math.min(90, 25 + Math.ceil(Math.max(0, durationS - 60) / 60) * 5) * 60 * 1000;
}
/** Giành quyền chạy 1 job (chống 2 tiến trình cùng chạy: server + `cli run-due`). */
function claim(id) {
const f = path.join(jobDir(id), '.claim');
for (let i = 0; i < 2; i++) {
try { fs.writeFileSync(f, String(process.pid), { flag: 'wx' }); return true; } catch { /* đã có người giữ */ }
try { // người giữ đã chết → thu hồi rồi thử lại
const pid = Number(fs.readFileSync(f, 'utf8'));
let alive = false;
try { process.kill(pid, 0); alive = true; } catch (e) { alive = e.code === 'EPERM'; }
if (alive) return false;
fs.rmSync(f, { force: true });
} catch { return false; }
}
return false;
}
/** Job có tiến trình nào đang thực sự chạy không (file .claim của 1 tiến trình còn sống). */
export function jobActive(id) {
try {
const pid = Number(fs.readFileSync(path.join(jobDir(id), '.claim'), 'utf8'));
try { process.kill(pid, 0); return true; } catch (e) { return e.code === 'EPERM'; }
} catch { return false; }
}
function release(id) { try { fs.rmSync(path.join(jobDir(id), '.claim'), { force: true }); } catch { /* bỏ qua */ } }
/** Chạy job: sinh cảnh theo chế độ rồi render; manual → dừng ở waiting_agent; hẹn giờ chưa tới → giữ scheduled. */
export async function runJob(id, { force = false } = {}) {
let job = readJob(id);
if (!job) throw new Error('Không thấy job ' + id);
if (job.status === 'scheduled' && !force && job.runAt && new Date(job.runAt) > new Date()) return job;
const engine = resolveMode(job.mode);
if (engine === 'manual') {
// Agent đã nộp cảnh trước rồi hẹn giờ → tới giờ thì render luôn.
if (job.runAt && fs.existsSync(path.join(jobDir(id), 'scene', 'index.html'))) return renderJob(id);
return setStatus(job, 'waiting_agent', { engine });
}
if (!claim(id)) return readJob(id);
try {
const restricted = jobRestricted(job);
job = setStatus(job, 'generating', { engine, restricted });
const log = logTo(job);
const prompt = fs.readFileSync(path.join(jobDir(id), 'PROMPT.md'), 'utf8');
const viaClaude = () => runClaude(jobDir(id), prompt, log, { timeoutMs: claudeTimeoutMs(job.durationS), model: job.model?.alias || job.model?.id, restricted }); // Claude Code nhận alias (opus/sonnet/haiku = bản mới nhất)
let r = engine === 'api' ? await runApi(job, jobDir(id), prompt, log, (usage) => update(id, { usage })) : await viaClaude();
if (!r.ok && r.authError) {
// Khoá sai/thu hồi (401/403): chế độ Tự động + máy có Claude Code → dựng bằng Claude Code (giống rewrite.mjs)
const claudeOk = !!findClaude();
if (job.mode === 'auto' && claudeOk) {
log(`api lỗi ${r.status} (khoá Anthropic không hợp lệ) → chuyển sang Claude Code`);
job = setStatus(readJob(id), 'generating', { engine: 'claude', fallbackFrom: `api lỗi ${r.status}` });
r = await viaClaude();
} else r = { ...r, error: authMessage(r.status, { claudeAvailable: claudeOk }) };
}
if (!r.ok) return setStatus(job, 'error', { error: r.error });
return await renderJob(id, { claimed: true });
} finally {
release(id);
}
}
/** Job đã hẹn mà tới giờ → chạy (lần lượt). Trả danh sách id đã chạy. */
export async function runDue({ log = () => {} } = {}) {
const now = new Date();
const due = listJobs().filter((j) => j.status === 'scheduled' && j.runAt && new Date(j.runAt) <= now)
.sort((a, b) => (a.runAt < b.runAt ? -1 : 1));
const done = [];
for (const j of due) {
log(`chạy job hẹn giờ ${j.id} (hẹn ${j.runAt})`);
const r = await runJob(j.id, { force: true });
done.push({ id: j.id, status: r.status, error: r.error });
}
return done;
}
export function dueJobs() {
const now = new Date();
return listJobs().filter((j) => j.status === 'scheduled' && j.runAt && new Date(j.runAt) <= now);
}
/** Agent ngoài nộp cảnh: ghi scene/index.html, kiểm tĩnh như engine. Lỗi → giữ bản cũ. */
export function submitScene(id, html, brief) {
const job = readJob(id);
if (!job) throw new Error('Không thấy job ' + id);
if (typeof html !== 'string' || html.length < 50) throw new Error('html rỗng');
if (html.length > 2_000_000) throw new Error('html quá lớn (> 2 MB)');
const sceneDir = path.join(jobDir(id), 'scene');
fs.mkdirSync(sceneDir, { recursive: true });
const file = path.join(sceneDir, 'index.html');
const prev = fs.existsSync(file) ? fs.readFileSync(file) : null;
fs.writeFileSync(file, html);
syncLib(sceneDir);
const lint = lintScene(sceneDir, { restricted: jobRestricted(job), expect: jobDims(job) });
if (lint.errors.length) {
if (prev) fs.writeFileSync(file, prev); else fs.rmSync(file);
return { ok: false, errors: lint.errors, warnings: lint.warnings };
}
if (brief !== undefined && brief !== null) {
const text = typeof brief === 'string' ? brief : JSON.stringify(brief, null, 2);
fs.writeFileSync(path.join(jobDir(id), 'brief.json'), text);
}
logTo(job)(`nhận scene/index.html (${html.length} ký tự)${lint.warnings.length ? ', cảnh báo: ' + lint.warnings.join('; ') : ''}`);
return { ok: true, errors: [], warnings: lint.warnings, meta: lint.meta };
}
/** Chỉ preview (không render). */
export async function previewJob(id) {
const job = readJob(id);
if (!job) throw new Error('Không thấy job ' + id);
const dir = jobDir(id);
if (!fs.existsSync(path.join(dir, 'scene', 'index.html'))) return { ok: false, errors: ['chưa có scene/index.html'] };
return preview(path.join(dir, 'scene'), path.join(dir, 'preview.jpg'), logTo(job), { restricted: jobRestricted(job), expect: jobDims(job) });
}
/** Preview + render một job đã có scene/index.html. */
export async function renderJob(id, { quality = 'looks', audio, claimed = false } = {}) {
let job = readJob(id);
if (!job) throw new Error('Không thấy job ' + id);
if (!claimed && !claim(id)) return job;
try {
const dir = jobDir(id);
const log = logTo(job);
if (!fs.existsSync(path.join(dir, 'scene', 'index.html'))) return setStatus(job, 'error', { error: 'chưa có scene/index.html' });
const restricted = jobRestricted(job);
job = setStatus(job, 'previewing');
const pv = await preview(path.join(dir, 'scene'), path.join(dir, 'preview.jpg'), log, { restricted, expect: jobDims(job) });
if (!pv.ok) return setStatus(job, 'error', { error: pv.errors.join('; ') });
job = setStatus(job, 'rendering');
// job.audio: chuỗi = file âm thanh ghép thẳng (cũ); object = tuỳ chọn {music, voice, sfx} áp lên scene/audio.json
const audioFile = audio || (typeof job.audio === 'string' ? path.join(dir, job.audio) : undefined);
// gói đã gỡ: không đọc được guidance nữa → bỏ fallbackStyle (cảnh + PROMPT.md đã có sẵn trong job)
const g = readGuidance(job.templateId);
const audioPrefs = job.audio && typeof job.audio === 'object' ? { ...job.audio, ...(g ? { fallbackStyle: styleFromGuidance(g) } : {}) } : undefined;
const rr = await render(path.join(dir, 'scene'), path.join(dir, 'out.mp4'), { quality, audio: audioFile, audioPrefs, log, restricted, expect: jobDims(job) });
if (!rr.ok) return setStatus(job, 'error', { error: rr.errors.join('; ') });
const v = rr.probe?.streams?.find((s) => s.width) || {};
const output = { mp4: 'out.mp4', preview: 'preview.jpg', width: v.width, height: v.height, fps: v.r_frame_rate, duration: Number(rr.probe?.format?.duration) };
const exported = exportOutput(job, log);
if (exported) output.exported = exported;
return setStatus(job, 'done', { output });
} finally {
if (!claimed) release(id);
}
}
function slugify(s, max = 40) {
return String(s).normalize('NFD').replace(/[̀-ͯ]/g, '').replace(/[đĐ]/g, 'd')
.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '').slice(0, max).replace(/-+$/, '') || 'video';
}
function localDate(d = new Date()) {
const p = (n) => String(n).padStart(2, '0');
return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())}`;
}
/** Chép out.mp4 sang OUTPUT_DIR (vd thư mục Google Drive for Desktop). Không có OUTPUT_DIR → bỏ qua. */
export function exportOutput(job, log = () => {}) {
const outDir = config.outputDir();
if (!outDir) return null;
try {
fs.mkdirSync(outDir, { recursive: true });
const base = `${localDate()}-${String(job.templateId).replace(/[^\w-]+/g, '-')}-${slugify(job.content)}`;
let name = `${base}.mp4`;
for (let i = 2; fs.existsSync(path.join(outDir, name)); i++) name = `${base}-${i}.mp4`;
fs.copyFileSync(path.join(jobDir(job.id), 'out.mp4'), path.join(outDir, name));
log(`đã chép ra OUTPUT_DIR: ${path.join(outDir, name)}`);
return path.join(outDir, name);
} catch (e) {
log(`chép ra OUTPUT_DIR lỗi: ${e.message}`);
return null;
}
}
/** Khi server khởi động lại: job đang chạy dở (không còn ai giữ) thì đánh lỗi. Job hẹn giờ giữ nguyên. */
export function markStale() {
for (const j of listJobs()) {
if (!['queued', 'generating', 'previewing', 'rendering'].includes(j.status)) continue;
const lock = path.join(jobDir(j.id), '.claim');
if (fs.existsSync(lock)) {
const pid = Number(fs.readFileSync(lock, 'utf8'));
let alive = false;
try { process.kill(pid, 0); alive = true; } catch { /* chết rồi */ }
if (alive) continue;
release(j.id);
} else if (j.status === 'queued') continue; // queued không ai giữ: để scheduler chạy lại
setStatus(j, 'error', { error: 'server khởi động lại khi job đang chạy' });
}
}
export function jobPaths(id) {
const dir = jobDir(id);
return { dir, scene: path.join(dir, 'scene'), sceneHtml: path.join(dir, 'scene', 'index.html'), mp4: path.join(dir, 'out.mp4'), preview: path.join(dir, 'preview.jpg'), prompt: path.join(dir, 'PROMPT.md') };
}