A motion design studio on your own machine: Claude makes the video step by step, you approve every stage. Bring your own Claude Code or API key.
// mortiflix: the command line. Everything the web UI does, in a terminal.
import { createInterface } from 'node:readline';
import { existsSync, createReadStream, statSync, writeFileSync, readFileSync } from 'node:fs';
import { join, basename, resolve } from 'node:path';
import { spawnSync, spawn } from 'node:child_process';
import { studioRoot, ensureStudio, loadConfig, saveConfig, paths, readJson } from './studio.mjs';
import { listPipelines, findPipeline, exportPipeline, addPipeline } from './pipelines.mjs';
import { record, ttsCredits } from './svc/ledger.mjs';
import { createProject, addIntakeFile, startProject, listProjects, loadProject, projectPaths, projectPipeline, readEvents } from './projects.mjs';
import * as gates from './gates.mjs';
import { Runner, BACKENDS } from './runner.mjs';
import * as voice from './voice/index.mjs';
import * as keys from './keys.mjs';
import * as setup from './setup.mjs';
import { costText } from './usage.mjs';
import * as booth from './booth.mjs';
import * as rec from './record.mjs';
import * as music from './music.mjs';
import * as plat from './platform.mjs';
import * as pub from './publish.mjs';
import * as craft from './craft.mjs';
const C = process.stdout.isTTY && !process.env.NO_COLOR
? { b: (s) => `\x1b[1m${s}\x1b[0m`, dim: (s) => `\x1b[2m${s}\x1b[0m`, acc: (s) => `\x1b[38;5;208m${s}\x1b[0m`, red: (s) => `\x1b[31m${s}\x1b[0m`, green: (s) => `\x1b[32m${s}\x1b[0m` }
: { b: (s) => s, dim: (s) => s, acc: (s) => s, red: (s) => s, green: (s) => s };
export const HELP = `${C.b('mortiflix')}: a motion design studio on your machine. Claude makes the video, you approve every stage.
${C.b('Getting started')}
mortiflix init [--backend claude-code|anthropic-api|demo] set up the studio (~/Mortiflix, or $MORTIFLIX_STUDIO)
mortiflix setup the walkthrough: Claude, transitions, narration, music, your DAW, sound engine, assets, 3D, Craft apps
mortiflix setup <claude|transitions|narration|music|daw|daw-engine|assets|publish|3d|craft> one part (mortiflix setup status: where things stand)
mortiflix keys add or change your keys (Anthropic, ElevenLabs, others)
mortiflix doctor check the tools a pipeline needs
mortiflix demo a full walk-through with placeholder work (free)
${C.b('Making videos')}
mortiflix pipelines what the studio can make
mortiflix pipelines export <slug> [--out file.zip] one shareable zip: the pipeline and every skill it uses
mortiflix pipelines add <file.zip | https://…> [--replace] add someone's pipeline to your studio
mortiflix new <pipeline> [--title "…"] [--set key=value]… [--file key=path]… [--backend demo]
mortiflix run [--watch] run sessions until everything waits on you
mortiflix list your projects
mortiflix status <project> steps, versions, the log
mortiflix review [<project>] review what's waiting (approve, notes, answers)
mortiflix respond <project> <step> --approve|--changes [--note "…"]… [--overall "…"] [--answer id=value]…
mortiflix answer <project> <question-id> [answer] answer a question the session asked
mortiflix reopen <project> <step> "what to change" send an approved step back (you changed your mind)
mortiflix pause|resume|cancel <project>
${C.b('Publishing')}
mortiflix publish <project> [--to tiktok,instagram,youtube] [--profile <name>] [--title "…"] [--description "…"]
[--at 2026-10-20T18:00 [--timezone Europe/Madrid]] [--yes] [--again]
post a delivered video through Upload-Post (asks first)
mortiflix publish <project> --status how it went, per platform, with the links
${C.b('The web studio')}
mortiflix serve [--port 4646] [--host 127.0.0.1] the studio in your browser, with the runner
${C.b('Narration')}
mortiflix voice what narrates your videos (ElevenLabs, your own voice, or none)
mortiflix voice elevenlabs set up ElevenLabs (key, voice, model)
mortiflix voice own narrate in your own voice, recorded in the booth
mortiflix voice none no narration (on-screen text and music)
mortiflix voice test ["a line to speak"] hear the current voice
mortiflix record [<project>] [--device <mic>] the recording booth in this terminal: read each line, keep the best take
mortiflix record <project> --import <folder> use files you recorded elsewhere, named after the lines (b01-1.wav…)
mortiflix record --list-devices the microphones ffmpeg can record from
${C.b('Music')}
mortiflix music [<project>] where its music stands: the MIDI pack, your master, the music sheet
mortiflix music <project> --midi <file.zip> save the MIDI pack (every channel, the arrangement, the cue sheet)
mortiflix music <project> --import <file> your own master, made from the MIDI pack in your DAW (exported from bar 1)
mortiflix music <project> --song the mini DAW's song from the checked score (music/song.json + song.strudel.js)
${C.b('3D')}
mortiflix blender [file.blend] open the studio's Blender, with its toolkits and Camera Flight
${C.b('Craft apps')} (open-source remakes of the Adobe apps, each with an MCP server)
mortiflix craft which are installed, and what each one is for
mortiflix craft install [all | <app>…] pull the official builds (checked against their SHA256SUMS)
mortiflix craft remove <app> delete one from the studio
mortiflix craft open <app> [file] open one (e.g. a PSD a session made, in PhotoCraft)
mortiflix craft register add their MCP servers to your own Claude Code (user scope)
mortiflix craft mcp-config print their MCP servers as JSON (.mcp.json format)
${C.b('Settings')}
mortiflix config [key [value]] show or change settings
mortiflix keys set <anthropic|elevenlabs|uploadpost|NAME> set one key (typed hidden, or piped on stdin)
mortiflix keys remove <anthropic|elevenlabs|uploadpost|NAME>
mortiflix checks [approve|reject <id>] the error checklist sessions proposed
--studio <dir> works with every command. --json prints what pipelines, list, status, review, keys and
setup status show as JSON, for scripts and for Claude Code (/mortiflix).
${C.b('Without a terminal')} (scripts, Claude Code)
mortiflix setup install <${setup.TOOLS.join('|')}>
mortiflix setup music <strudel|none> [--midi|--no-midi]
mortiflix setup daw <${Object.keys(setup.DAWS).join('|')}|none>
mortiflix setup browser [http://127.0.0.1:PORT|none] [--start "command"] the studio browser sessions drive
mortiflix setup assets <url>… | --clear
mortiflix setup publish <uploadpost|none> [--profile <Upload-Post profile>]`;
const LISTS = ['set', 'file', 'note', 'answer'];
function parse(argv) {
const out = { _: [], set: [], file: [], note: [], answer: [] };
for (let i = 0; i < argv.length; i++) {
const a = argv[i];
if (!a.startsWith('--')) { out._.push(a); continue; }
const [k, inline] = a.slice(2).split(/=(.*)/s);
const v = inline !== undefined ? inline : (argv[i + 1] !== undefined && !argv[i + 1].startsWith('--') ? argv[++i] : true);
if (LISTS.includes(k)) out[k].push(v); else out[k] = v;
}
return out;
}
export async function run(argv = process.argv.slice(2)) {
const a = parse(argv);
const root = studioRoot(typeof a.studio === 'string' ? a.studio : undefined);
const [cmd, ...rest] = a._;
// `await` the command: a bare `return promise` inside try would let its rejection escape the catch.
const dispatch = async () => {
// `--help` anywhere prints help: it never runs the command (`serve --help` used to start a server).
if (a.help || a.h) return console.log(HELP);
switch (cmd) {
case 'init': return init(root, a);
case 'keys': return a.json ? (needStudio(root), json({ keys: keys.keyStatus(root), session_keys: keys.sessionKeyNames(root) })) : keysCmd(root, rest);
case 'setup': return setupCmd(root, rest, a);
case 'blender': needStudio(root); return console.log(`Opening ${setup.openBlender(root, rest)} with the studio's profile (Camera Flight: 3D Viewport › N › Flight).`);
case 'craft': return craftCmd(root, rest, a);
case 'doctor': return doctor(root);
case 'demo': return demo(root);
case 'pipelines': return a.json ? json(pipelinesView(root)) : pipelines(root, rest, a);
case 'new': return newProject(root, rest[0], a);
case 'run': return runLoop(root, a);
case 'list': case 'ls': return list(root, a);
case 'status': return a.json ? json(statusView(root, pick(root, rest[0]))) : status(root, pick(root, rest[0]));
case 'review': return a.json ? reviewJson(root, rest[0]) : (ownerOnly(), review(root, rest[0]));
case 'respond': ownerOnly(); return respondCmd(root, rest, a);
case 'answer': ownerOnly(); return answerCmd(root, rest);
case 'pause': ownerOnly(); gates.pause(root, pick(root, rest[0])); return console.log('Paused.');
case 'reopen': {
ownerOnly();
const [proj, step, ...words] = rest;
if (!step || !words.length) throw new Error('mortiflix reopen <project> <step> "what to change"');
gates.reopen(root, pick(root, proj), step, { overall: words.join(' ') });
return console.log(`${C.acc('↺')} ${step} goes back for changes. ${C.b('mortiflix run')} makes the next version.`);
}
case 'resume': ownerOnly(); gates.resume(root, pick(root, rest[0])); return console.log('Resumed: it will run on the next `mortiflix run` (or right away under `serve`).');
case 'cancel': ownerOnly(); gates.cancel(root, pick(root, rest[0])); return console.log('Cancelled.');
case 'publish': ownerOnly(); return publishCmd(root, rest[0], a);
case 'serve': return serve(root, a);
case 'config': return config(root, rest);
case 'checks': return checks(root, rest);
case 'voice': return voiceCmd(root, rest);
case 'record': return recordCmd(root, rest, a);
case 'music': return musicCmd(root, rest, a);
case undefined: case 'help': return console.log(HELP);
default: throw new Error(`unknown command "${cmd}" (mortiflix help)`);
}
};
try {
await dispatch();
} catch (e) {
console.error(C.red(`✖ ${e.message}`));
process.exitCode = 1;
}
}
// Questions in the terminal. Lines are queued, so piped answers (scripts, tests) work as well as typing.
function prompter() {
const rl = createInterface({ input: process.stdin, output: process.stdout, terminal: Boolean(process.stdin.isTTY) });
const queue = [];
const waiters = [];
let closed = false;
rl.on('line', (l) => (waiters.length ? waiters.shift()(l) : queue.push(l)));
rl.on('close', () => { closed = true; while (waiters.length) waiters.shift()(null); });
return {
question(q) {
process.stdout.write(q);
const echo = (l) => { if (!process.stdin.isTTY && l !== null) process.stdout.write(`${l}\n`); return l; };
if (queue.length) return Promise.resolve(echo(queue.shift()));
if (closed) throw new Error('input ended');
return new Promise((ok, fail) => waiters.push((l) => (l === null ? fail(new Error('input ended')) : ok(echo(l)))));
},
close: () => rl.close(),
};
}
function needStudio(root) {
if (!existsSync(paths(root).config)) throw new Error(`no studio at ${root}: run \`mortiflix init\` first`);
}
const json = (v) => console.log(JSON.stringify(v, null, 2));
// What only the owner does (approve, ask for changes, answer, reopen, pause…) is refused inside a studio session,
// so a session that finds the CLI on its PATH can't review its own work by accident. A guard, not a wall: the
// sandbox is the wall (docs/SECURITY.md).
function ownerOnly() {
if (process.env.MFX_TOKEN) throw new Error('only the owner does that: a Mortiflix session can\'t review, answer or reopen its own work (submit with mfx instead)');
}
// A text item's paragraphs, numbered the way the web studio numbers them (notes point at them by index).
export const paragraphs = (text) => String(text || '').split(/\n\s*\n/).filter((x) => x.trim()).map((x) => x.trim());
// A project id, or a unique prefix of one, or (when there's only one) none at all.
function pick(root, given) {
needStudio(root);
const all = listProjects(root);
if (!given) {
const live = all.filter((p) => !['delivered', 'cancelled'].includes(p.state));
if (live.length === 1) return live[0].id;
if (!live.length && all.length === 1) return all[0].id;
throw new Error('which project? (mortiflix list)');
}
const hits = all.filter((p) => p.id === given || p.id.startsWith(given) || p.id.includes(given));
if (hits.length === 1) return hits[0].id;
throw new Error(hits.length ? `"${given}" matches ${hits.length} projects: be more specific` : `no project "${given}"`);
}
function detectBackend(root) {
const config = loadConfig(root);
if (BACKENDS['claude-code'].available(config).ok) return 'claude-code';
if (BACKENDS['anthropic-api'].available(config, root).ok) return 'anthropic-api';
return 'demo';
}
async function init(root, a) {
const fresh = !existsSync(paths(root).config);
ensureStudio(root);
const backend = typeof a.backend === 'string' ? a.backend : (fresh ? detectBackend(root) : loadConfig(root).backend);
if (!BACKENDS[backend]) throw new Error('backend must be claude-code, anthropic-api or demo');
saveConfig(root, { backend });
console.log(`${C.green('✔')} Studio ready at ${C.b(root)}`);
console.log(` Backend: ${C.b(backend)} ${C.dim(BACKENDS[backend].available(loadConfig(root), root).detail)}`);
if (backend === 'demo') console.log(C.dim(' (No Claude Code login or API key found: the demo backend makes placeholder work. Install Claude Code, or add an API key with `mortiflix keys`.)'));
if (process.stdin.isTTY && !a.yes) {
console.log(`\n Next, the setup walkthrough: what Mortiflix uses (Claude, transitions, narration, music, assets, 3D, Craft apps), why, and what it would`);
console.log(' install. Nothing installs without asking, and you can skip any part.');
if (await confirm(' Set it up now?', true)) await setupWalk(root);
else console.log(` Any time: ${C.b('mortiflix setup')}`);
} else console.log(`\n Next: ${C.b('mortiflix setup')} walks through Claude, rendering, transitions, narration, music, assets, 3D and the Craft apps.`);
console.log(`\n Then: ${C.b('mortiflix demo')} for a free walk-through, or ${C.b('mortiflix serve')} to open the studio in your browser.`);
}
// What to install a missing tool with on Windows (doctor's hint).
const WINGET = process.platform === 'win32' ? { ffmpeg: 'Gyan.FFmpeg', ffprobe: 'Gyan.FFmpeg', npx: 'OpenJS.NodeJS.LTS', git: 'Git.Git' } : {};
function doctor(root) {
const config = existsSync(paths(root).config) ? loadConfig(root) : null;
const row = (ok, name, detail) => console.log(`${ok ? C.green('✔') : C.red('✖')} ${name.padEnd(14)} ${C.dim(detail)}`);
row(Number(process.versions.node.split('.')[0]) >= 20, 'node', process.version);
row(Boolean(config), 'studio', config ? root : `none at ${root} (mortiflix init)`);
for (const [name, b] of Object.entries(BACKENDS)) {
if (!b.available) continue;
const r = b.available(config || loadConfig(root), root);
row(r.ok, name, `${r.detail}${config?.backend === name ? ' ← in use' : ''}`);
}
for (const [bin, why] of [['ffmpeg', 'renders, checks, the demo'], ['ffprobe', 'the final pass'], ['git', 'installs the 3D toolkits and local narration']]) {
const found = plat.which(bin);
row(Boolean(found) || bin === 'git', bin, found ? why : `${why}: not found${WINGET[bin] ? ` (winget install ${WINGET[bin]})` : ''}`);
}
if (process.platform === 'win32') {
const bash = plat.findGitBash();
row(Boolean(bash), 'git bash', bash || 'sessions run shell commands in Git Bash: install Git for Windows (winget install Git.Git)');
}
if (process.platform === 'linux') row(spawnSync('bwrap', ['--version']).status === 0, 'bwrap', `optional session sandbox (${config?.sandbox ? 'on' : 'off'})`);
for (const k of keys.keyStatus(root)) {
row(Boolean(k.source) || !k.in_use, k.id, k.source ? `${k.name}: ${k.source}${k.in_use ? ' ← in use' : ''}` : k.in_use ? `${k.name} missing: mortiflix keys` : `${k.name}: not set (optional)`);
}
const tools = setup.setupStatusSync(root);
row(tools.kinetograph.ok, 'kinetograph', tools.kinetograph.ok ? `${tools.kinetograph.detail}: renders every 2D shot, still and animatic` : `${tools.kinetograph.detail} (mortiflix setup rendering)`);
for (const id of ['strudel', 'chrome', 'browser-harness', 'blender', 'blender-addons']) row(tools[id].ok || !['strudel', 'chrome'].includes(id) || tools.music.engine === 'none', id, tools[id].ok ? tools[id].detail : `${tools[id].detail} (mortiflix setup)`);
const extra = keys.sessionKeyNames(root);
row(true, 'session.env', extra.length ? `other keys for sessions: ${extra.join(', ')}` : 'no other keys (optional: mortiflix keys)');
}
async function pipelines(root, [sub, arg] = [], a = {}) {
if (sub === 'export') {
if (!arg) throw new Error('mortiflix pipelines export <slug> [--out file.zip]');
const x = exportPipeline(existsSync(paths(root).config) ? root : null, arg);
const file = typeof a.out === 'string' ? a.out : `${x.slug}.mortiflix-pipeline.zip`;
writeFileSync(file, x.zip);
return console.log(`${C.green('✔')} ${file}: ${x.name}, with every skill it uses (${(x.zip.length / 1024).toFixed(0)} KB, version ${x.hash}). Share it; anyone adds it with ${C.b('mortiflix pipelines add <file>')}.`);
}
if (sub === 'add') {
needStudio(root);
if (!arg) throw new Error('mortiflix pipelines add <file.zip | https://…> [--replace]');
let buf;
if (/^https:\/\//.test(arg)) {
const res = await fetch(arg, { redirect: 'follow' });
if (!res.ok) throw new Error(`couldn't download it: HTTP ${res.status}`);
buf = Buffer.from(await res.arrayBuffer());
} else if (/^[a-z]+:\/\//i.test(arg)) throw new Error('only https links (or a file on this computer)');
else buf = readFileSync(arg);
const r = addPipeline(root, buf, { replace: Boolean(a.replace) });
console.log(`${C.green('✔')} ${r.name} (${r.slug}) is in your studio: ${r.files.length} files${r.replaced ? ', replacing your earlier copy' : ''}${r.overrides_built_in ? ', in place of the built-in one' : ''}.`);
if (r.scripts.length) console.log(` ${C.acc('!')} It brings scripts its sessions will run (${r.scripts.join(', ')}). Read them before you start a project with it: ${paths(root).pipelines}/${r.slug}`);
return;
}
if (sub) throw new Error('mortiflix pipelines [export <slug> | add <file|url>]');
for (const p of listPipelines(existsSync(paths(root).config) ? root : null)) {
if (p.error) { console.log(`${C.red('✖')} ${p.slug}: ${p.error}`); continue; }
console.log(`${C.b(p.slug.padEnd(14))} ${p.name} ${C.dim(`(${p.source})`)}`);
console.log(`${' '.repeat(15)}${C.dim(p.description)}`);
console.log(`${' '.repeat(15)}${p.steps.map((s) => (s.review === 'internal' ? C.dim(s.name) : s.name)).join(' → ')}\n`);
}
}
async function newProject(root, slug, a) {
needStudio(root);
if (!slug) throw new Error('mortiflix new <pipeline> (see: mortiflix pipelines)');
const pipeline = findPipeline(root, slug);
const answers = {};
for (const kv of a.set) { const [k, ...v] = String(kv).split('='); answers[k] = v.join('='); }
const files = a.file.map((kv) => { const [k, ...v] = String(kv).split('='); return { field: k, path: resolve(v.join('=')) }; });
const tty = process.stdin.isTTY && !a.yes;
let title = typeof a.title === 'string' ? a.title : '';
if (tty) {
const rl = prompter();
try {
console.log(`${C.b(pipeline.name)} ${C.dim(pipeline.description)}\n`);
if (!title) title = (await rl.question(`${C.b('Title')}: `)).trim();
for (const q of pipeline.intake) {
if (q.type === 'files' ? files.some((f) => f.field === q.id) : answers[q.id] !== undefined) continue;
const label = `${C.b(q.label || q.id)}${q.required ? '' : C.dim(' (optional)')}`;
if (q.help) console.log(C.dim(` ${q.help}`));
if (q.type === 'files') {
const v = (await rl.question(`${label} ${C.dim('file paths, comma separated')}: `)).trim();
for (const f of v.split(',').map((s) => s.trim()).filter(Boolean)) files.push({ field: q.id, path: resolve(f.replace(/^~(?=\/)/, process.env.HOME)) });
} else if (q.type === 'choice') {
q.choices.forEach((c, i) => console.log(` ${i + 1}. ${c}${c === q.default ? C.dim(' (default)') : ''}`));
const v = (await rl.question(`${label} [${q.default ? q.choices.indexOf(q.default) + 1 : 1}]: `)).trim();
answers[q.id] = q.choices[Number(v) - 1] || q.default || q.choices[0];
} else {
const v = (await rl.question(`${label}: `)).trim();
if (v) answers[q.id] = v;
}
}
} finally {
rl.close();
}
}
for (const q of pipeline.intake) if (q.type === 'choice' && answers[q.id] === undefined && q.default) answers[q.id] = q.default;
// Before anything is made: the keys this project will need, asked for here instead of failing mid-project.
const missing = keys.missingKeys(root, { backend: typeof a.backend === 'string' ? a.backend : null, pipeline });
if (missing.length) {
if (!tty) throw new Error(keys.missingKeysText(missing, 'run this again'));
console.log(`\n${C.acc('●')} Before it starts: this project needs your ${missing.map((id) => keys.KEYS[id].name).join(' and ')}.`);
for (const id of missing) if (!(await askKey(root, id, { required: true }))) throw new Error(`no ${keys.KEYS[id].name}: nothing was created`);
}
const p = createProject(root, { pipeline: slug, title, answers, backend: typeof a.backend === 'string' ? a.backend : null });
for (const f of files) {
if (!existsSync(f.path) || !statSync(f.path).isFile()) throw new Error(`no file ${f.path}`);
await addIntakeFile(root, p.id, { field: f.field, name: basename(f.path), stream: createReadStream(f.path) });
}
startProject(root, p.id);
console.log(`\n${C.green('✔')} ${C.b(p.title)} is queued as ${C.b(p.id)}`);
console.log(` ${C.b('mortiflix run')} starts it (or it starts by itself under ${C.b('mortiflix serve')}).`);
return p.id;
}
async function runLoop(root, a) {
needStudio(root);
const runner = new Runner(root, { log: (line) => console.log(C.dim(line)) });
runner.acquire();
let lastProject = null;
runner.on('activity', (x) => {
if (x.project !== lastProject) { console.log(`\n${C.b(x.project)}`); lastProject = x.project; }
const mark = { text: '│', tool: C.dim('›'), error: C.red('!'), info: C.acc('●') }[x.kind] || ' ';
console.log(`${mark} ${x.kind === 'tool' ? C.dim(x.text) : x.text.split('\n').join('\n ')}`);
});
const stop = async () => { console.log(C.dim('\nStopping the current session…')); await runner.stop(); runner.release(); process.exit(130); };
process.once('SIGINT', stop);
try {
await runner.loop({ watch: Boolean(a.watch) });
} finally {
runner.release();
}
const waiting = listProjects(root).filter((p) => p.state === 'waiting' || p.state === 'paused');
if (waiting.length) {
console.log(`\n${C.acc('●')} Your turn:`);
for (const p of waiting) console.log(` ${C.b(p.id)} ${p.state === 'paused' ? C.red(`needs you: ${p.needs_you?.text}`) : 'ready to review'} → mortiflix review ${p.id}`);
} else console.log(C.dim('\nNothing left to run.'));
}
const STATE_LABEL = { draft: 'draft', queued: 'in production', waiting: 'your turn', paused: 'needs you', delivered: 'delivered', cancelled: 'cancelled' };
async function list(root, a = {}) {
needStudio(root);
const all = listProjects(root);
if (a.json) return json(await studioView(root, all));
if (!all.length) return console.log(`No projects yet: ${C.b('mortiflix new <pipeline>')} or ${C.b('mortiflix demo')}.`);
for (const p of all) {
const label = STATE_LABEL[p.state];
const tag = p.state === 'waiting' || p.state === 'paused' ? C.acc(label) : C.dim(label);
console.log(`${C.b(p.id.padEnd(34))} ${p.title.slice(0, 40).padEnd(40)} ${tag}${p.session?.running ? C.dim(' · working now') : ''}`);
}
}
function status(root, id) {
const p = loadProject(root, id);
const pipeline = projectPipeline(root, id);
console.log(`${C.b(p.title)} ${C.dim(`${pipeline.name} · ${p.id}`)}`);
console.log(`${STATE_LABEL[p.state]}${p.status ? ` · ${p.status.text}` : ''}${p.needs_you ? `\n${C.red(`needs you: ${p.needs_you.text}`)}` : ''}\n`);
for (const s of gates.stepView(p, pipeline)) {
const icon = { approved: C.green('✔'), done: C.green('✔'), skipped: C.dim('–'), in_review: C.acc('●'), changes: C.red('↺'), working: '…', ready: '○', blocked: C.dim('·') }[s.state];
console.log(`${icon} ${s.name.padEnd(16)} ${C.dim(s.state.replace('_', ' '))}${s.version ? C.dim(` v${s.version}`) : ''}`);
}
const usage = p.usage;
console.log(C.dim(`\n${usage.sessions} session(s)${usage.output_tokens ? ` · ${usage.output_tokens.toLocaleString()} output tokens` : ''}`));
if (costText(usage)) console.log(C.dim(costText(usage)));
console.log(C.dim('\nLog:'));
for (const e of readEvents(root, id, { limit: 12 })) console.log(C.dim(` ${e.t.slice(5, 16).replace('T', ' ')} ${e.event}${e.step ? ` ${e.step}${e.version ? ` v${e.version}` : ''}` : ''} ${e.details ? `· ${e.details.slice(0, 80)}` : ''}`));
}
// Publishing: shows exactly what goes where, asks, then sends. Never runs on its own.
async function publishCmd(root, given, a) {
const id = pick(root, given);
const opt = (k) => (typeof a[k] === 'string' ? a[k] : undefined);
if (a.status) {
const st = await pub.publishStatus(root, id);
console.log(`${C.b(st.status)}${st.message ? C.dim(` · ${st.message}`) : ''} ${C.dim(st.ref)}`);
for (const r of st.results) {
const icon = { completed: C.green('✔'), failed: C.red('✖') }[r.state] || C.acc('●');
console.log(` ${icon} ${String(r.platform || '?').padEnd(10)} ${r.url || C.dim(r.message || r.state)}`);
}
if (!st.results.length) console.log(C.dim(st.scheduled_for ? ` Scheduled for ${st.scheduled_for}.` : ' Nothing back from the platforms yet.'));
return;
}
const plan = pub.publishPlan(root, id, { to: opt('to'), profile: opt('profile'), title: opt('title'), description: opt('description'), at: opt('at'), timezone: opt('timezone'), again: Boolean(a.again) });
console.log(`\n${C.b(plan.project)} ${C.dim(`${(plan.size / 1024 ** 2).toFixed(1)} MB`)}`);
console.log(` Via ${pub.SERVICES[plan.service].name}`);
console.log(` To ${plan.platforms.join(', ')}${plan.from_brief ? C.dim(' (from the brief; --to changes it)') : ''}`);
if (plan.profile) console.log(` Profile ${plan.profile}`);
console.log(` Title ${plan.title}`);
if (plan.description) console.log(` Text ${plan.description.slice(0, 200)}`);
console.log(` When ${plan.at ? `${plan.at} ${plan.timezone || 'UTC'}` : 'now'}\n`);
if (!a.yes && !process.stdin.isTTY) throw new Error('nothing sent: add --yes to post without being asked');
if (!a.yes && !(await confirm(`Post it${plan.at ? ' at that time' : ' now'}?`))) return console.log('Nothing sent.');
const sent = await pub.publish(root, plan);
console.log(`${C.green('✔')} ${plan.at ? 'Scheduled' : 'Sent'}. ${C.b(`mortiflix publish ${id} --status`)} shows how it went.`);
console.log(C.dim(` ${sent.job_id ? `job ${sent.job_id}` : `request ${sent.request_id}`} · also at https://app.upload-post.com`));
}
// Review in the terminal: what was sent, then answers, notes and a decision.
async function review(root, given) {
needStudio(root);
const ids = given ? [pick(root, given)] : listProjects(root).filter((p) => p.state === 'waiting').map((p) => p.id);
if (!ids.length) return console.log('Nothing is waiting for you.');
const rl = prompter();
try {
for (const id of ids) {
const p = loadProject(root, id);
const pipeline = projectPipeline(root, id);
console.log(`\n${C.b(p.title)} ${C.dim(p.id)}`);
for (const q of p.questions.filter((x) => !x.answered_at)) {
console.log(`\n${C.acc('?')} ${q.text}${q.choices ? C.dim(` (${q.choices.join(' / ')})`) : ''}`);
const v = (await rl.question(` Answer${q.default ? C.dim(` [${q.default}]`) : ''}: `)).trim();
gates.answerQuestion(root, id, q.id, v || null);
}
for (const s of gates.stepView(loadProject(root, id), pipeline).filter((x) => x.state === 'in_review')) {
const sub = gates.submissions(root, id).filter((x) => x.step === s.key).at(-1);
console.log(`\n${C.acc('●')} ${C.b(`${s.name} v${sub.version}`)}\n\n${sub.note}\n`);
if (sub.pin_changes.length) {
console.log(C.b('What changed for your notes:'));
for (const c of sub.pin_changes) console.log(` ${c.note}. ${c.change} ${C.dim(`(${c.status.replace('_', ' ')})`)}`);
console.log();
}
sub.items.forEach((it, i) => {
if (it.kind === 'text') {
console.log(`${C.b(`[${i}] ${it.label}`)}`);
paragraphs(it.text).forEach((para, n) => console.log(` ${C.dim(`¶${n}`)} ${para.split('\n').join('\n ')}`));
} else console.log(`${C.b(`[${i}] ${it.label}`)} ${C.dim(it.kind)} ${join(projectPaths(root, id).state, it.file)}`);
});
const files = sub.items.filter((it) => it.file);
if (files.length && (await rl.question(C.dim('\nOpen the files? [y/N] '))).toLowerCase() === 'y') {
for (const it of files) {
const o = plat.openCommand(join(projectPaths(root, id).state, it.file));
spawn(o.file, o.args, { ...o.options, detached: true, stdio: 'ignore' }).on('error', () => {}).unref();
}
}
const answers = {};
for (const q of sub.questions) {
console.log(`\n${C.acc('?')} ${q.text}${q.choices ? C.dim(` (${q.choices.join(' / ')})`) : ''}`);
const v = (await rl.question(` Answer${q.default !== null ? C.dim(` [${q.default}]`) : ''}: `)).trim();
answers[q.id] = v || null;
}
let choice = '';
while (!['a', 'c', 's'].includes(choice)) choice = (await rl.question(`\n${C.b('[a]')}pprove, ask for ${C.b('[c]')}hanges, or ${C.b('[s]')}kip? `)).trim().toLowerCase()[0] || '';
if (choice === 's') continue;
if (choice === 'a') {
gates.respond(root, id, s.key, sub.version, { verdict: 'approve', answers });
console.log(C.green(`✔ ${s.name} approved.`));
continue;
}
console.log(C.dim('Notes, one per line, blank line to finish. Point at things with a prefix:\n 2: text item 2\n [email protected],0.3: … a spot on item 2 (fractions across, down)\n [email protected]: … 12.5 s into item 1\n 0¶3: … paragraph 3 of item 0'));
const notes = [];
for (;;) {
const line = (await rl.question(` ${notes.length + 1}. `)).trim();
if (!line) break;
notes.push(parseNote(line));
}
const overall = (await rl.question('Overall comment (optional): ')).trim();
gates.respond(root, id, s.key, sub.version, { verdict: 'changes', notes, overall, answers });
console.log(C.acc(`↺ Changes sent. ${C.b('mortiflix run')} makes the next version.`));
}
}
} finally {
rl.close();
}
}
// ---- for scripts and Claude Code: the same views and decisions, without a terminal ----
// The studio at a glance: the backend, whether a runner (`run` or `serve`) holds it, and every project.
async function studioView(root, all = listProjects(root)) {
const config = loadConfig(root);
const lock = join(paths(root).run, 'runner.pid');
const pid = existsSync(lock) ? Number(readFileSync(lock, 'utf8')) : 0;
let running = false;
if (pid) { try { process.kill(pid, 0); running = true; } catch (e) { running = e.code === 'EPERM'; } }
const web = `http://127.0.0.1:${config.port}/`;
let up = false;
if (running) { try { await fetch(web, { signal: AbortSignal.timeout(800) }); up = true; } catch { /* not serving here */ } }
return {
studio: root,
backend: config.backend,
runner: running ? { pid, web: up ? web : null } : null,
projects: all.map((p) => ({
id: p.id, title: p.title, pipeline: p.pipeline.slug, state: p.state, label: STATE_LABEL[p.state],
status: p.status?.text || null, needs_you: p.needs_you?.text || null, working: Boolean(p.session?.running),
in_review: gates.stepView(p, projectPipeline(root, p.id)).filter((s) => s.state === 'in_review').map((s) => s.key),
unanswered: p.questions.filter((q) => !q.answered_at).length,
})),
};
}
// Every pipeline with its steps and the brief's questions (what `mortiflix new` asks).
function pipelinesView(root) {
return listPipelines(existsSync(paths(root).config) ? root : null).map((p) => (p.error ? { slug: p.slug, source: p.source, error: p.error } : {
slug: p.slug, name: p.name, description: p.description, source: p.source,
steps: p.steps.map((s) => ({ key: s.key, name: s.name, review: s.review, after: s.after })),
intake: p.intake,
}));
}
function statusView(root, id) {
const p = loadProject(root, id);
const pipeline = projectPipeline(root, id);
return {
id: p.id, title: p.title, pipeline: pipeline.slug, state: p.state, label: STATE_LABEL[p.state],
status: p.status?.text || null, needs_you: p.needs_you?.text || null, working: Boolean(p.session?.running),
steps: gates.stepView(p, pipeline).map((s) => ({ key: s.key, name: s.name, review: s.review, state: s.state, version: s.version })),
deliverables: p.deliverables.map((d) => ({ ...d, path: join(projectPaths(root, id).state, d.file) })),
usage: p.usage, cost: costText(p.usage) || null,
log: readEvents(root, id, { limit: 20 }),
};
}
// Everything waiting on the owner in one project: questions, and each step in review with what was sent.
function reviewView(root, id) {
const p = loadProject(root, id);
const pipeline = projectPipeline(root, id);
const dir = projectPaths(root, id).state;
const subs = gates.submissions(root, id);
return {
id: p.id, title: p.title, pipeline: pipeline.slug, state: p.state, needs_you: p.needs_you?.text || null,
questions: p.questions.filter((q) => !q.answered_at).map((q) => ({ id: q.id, step: q.step, text: q.text, choices: q.choices, default: q.default })),
reviews: gates.stepView(p, pipeline).filter((s) => s.state === 'in_review').map((s) => {
const sub = subs.filter((x) => x.step === s.key).at(-1);
return {
step: s.key, name: s.name, review: s.review, version: sub.version, note: sub.note, pin_changes: sub.pin_changes, questions: sub.questions,
items: sub.items.map((it, index) => (it.kind === 'text'
? { index, label: it.label, section: it.section, kind: 'text', paragraphs: paragraphs(it.text) }
: { index, label: it.label, section: it.section, kind: it.kind, path: join(dir, it.file), size: it.size })),
web: `#/p/${p.id}/review/${s.key}`,
};
}),
};
}
function reviewJson(root, given) {
needStudio(root);
const ids = given ? [pick(root, given)] : listProjects(root).filter((p) => ['waiting', 'paused'].includes(p.state)).map((p) => p.id);
return json(ids.map((id) => reviewView(root, id)));
}
// `mortiflix respond <project> <step> --approve | --changes --note "[email protected],0.3: …" --overall "…" --answer q1=…`
function respondCmd(root, [given, stepKey], a) {
const id = pick(root, given);
if (!stepKey || Boolean(a.approve) === Boolean(a.changes)) throw new Error('mortiflix respond <project> <step> --approve | --changes [--note "…"]… [--overall "…"] [--answer id=value]…');
const view = gates.stepView(loadProject(root, id), projectPipeline(root, id)).find((s) => s.key === stepKey);
const version = a.version !== undefined ? Number(a.version) : view?.version ?? 0;
const answers = {};
for (const kv of a.answer) { const [k, ...v] = String(kv).split('='); answers[k] = v.join('='); }
const notes = a.note.map((n) => parseNote(String(n)));
const r = gates.respond(root, id, stepKey, version, { verdict: a.approve ? 'approve' : 'changes', notes, overall: typeof a.overall === 'string' ? a.overall : '', answers });
if (r.verdict === 'approve') console.log(C.green(`✔ ${view.name} v${version} approved.${r.project_state === 'delivered' ? ' Delivered.' : ''}`));
else console.log(C.acc(`↺ Changes sent for ${view.name} v${version} (${notes.length} note${notes.length === 1 ? '' : 's'}). ${C.b('mortiflix run')} makes the next version.`));
}
function answerCmd(root, [given, qid, ...words]) {
if (!qid) throw new Error('mortiflix answer <project> <question-id> [answer] (no answer takes the default)');
const id = pick(root, given);
gates.answerQuestion(root, id, qid, words.join(' ') || null);
const q = loadProject(root, id).questions.find((x) => x.id === qid);
console.log(`${C.green('✔')} ${q.text} → ${q.answer}`);
}
export function parseNote(line) {
const m = line.match(/^(\d+)(?:@([\d.]+),([\d.]+)|@([\d.]+)s|¶(\d+))?:\s*(.+)$/);
if (!m) return { text: line };
const note = { item: Number(m[1]), text: m[6] };
if (m[2] !== undefined) Object.assign(note, { x: Number(m[2]), y: Number(m[3]) });
if (m[4] !== undefined) note.time_sec = Number(m[4]);
if (m[5] !== undefined) note.paragraph = Number(m[5]);
return note;
}
async function serve(root, a) {
ensureStudio(root);
const { startServer } = await import('./web/server.mjs');
const config = loadConfig(root);
await startServer(root, { port: Number(a.port || config.port), host: typeof a.host === 'string' ? a.host : config.host });
}
async function config(root, [key, value]) {
needStudio(root);
if (key === 'api-key') return keysCmd(root, ['set', 'anthropic']); // older spelling of `mortiflix keys set anthropic`
const cur = loadConfig(root);
if (!key) {
for (const [k, v] of Object.entries(cur)) console.log(`${k.padEnd(18)} ${JSON.stringify(v)}`);
return undefined;
}
if (!(key in cur)) throw new Error(`unknown setting "${key}"`);
if (value === undefined) return console.log(JSON.stringify(cur[key]));
let v = value;
if (['true', 'false'].includes(value)) v = value === 'true';
else if (value === 'null') v = null;
else if (/^\d+$/.test(value)) v = Number(value);
if (key === 'backend' && !BACKENDS[v]) throw new Error('backend must be claude-code, anthropic-api or demo');
saveConfig(root, { [key]: v });
console.log(`${C.green('✔')} ${key} = ${JSON.stringify(v)}`);
}
// A prompt that doesn't echo what's typed (for keys).
function hiddenPrompt(question) {
process.stdout.write(question);
const stdin = process.stdin;
if (!stdin.isTTY) {
return new Promise((ok) => { let buf = ''; stdin.setEncoding('utf8'); stdin.on('data', (d) => { buf += d; }); stdin.on('end', () => ok(buf.split('\n')[0])); });
}
return new Promise((ok) => {
let buf = '';
stdin.setRawMode(true);
stdin.resume();
stdin.setEncoding('utf8');
const onData = (chunk) => {
for (const ch of chunk) {
if (ch === '\r' || ch === '\n') { stdin.setRawMode(false); stdin.pause(); stdin.off('data', onData); process.stdout.write('\n'); return ok(buf); }
if (ch === '\u0003') { stdin.setRawMode(false); process.stdout.write('\n'); process.exit(130); }
if (ch === '\u007f' || ch === '\b') buf = buf.slice(0, -1);
else buf += ch;
}
};
stdin.on('data', onData);
});
}
// ---- keys ----
const SOURCE_WORDS = { saved: 'saved in this studio', 'session.env': 'from session.env', environment: 'from your environment' };
function showKeys(root) {
console.log(`${C.b('Your keys')} ${C.dim(`(in ${paths(root).secrets} and session.env, readable by you alone; never shown)`)}`);
for (const k of keys.keyStatus(root)) {
const mark = k.source ? C.green('✔') : k.in_use ? C.red('✖') : C.dim('·');
console.log(` ${mark} ${k.name.padEnd(20)} ${k.source ? SOURCE_WORDS[k.source] : k.in_use ? C.red('missing: your studio uses it') : C.dim('not set')}${k.source && k.in_use ? C.dim(' ← in use') : ''}`);
}
const extra = keys.sessionKeyNames(root);
console.log(` ${C.dim('·')} ${'Other keys'.padEnd(20)} ${extra.length ? extra.join(', ') : C.dim('none')} ${C.dim('(handed to every session)')}`);
}
// Ask for one key without echoing it, check it with a free call, and save it. Returns where the key now comes from
// (null if there's none). Enter keeps what's there (or skips), "-" removes a saved key.
async function askKey(root, id, { required = false } = {}) {
const k = keys.KEYS[id];
const source = keys.keySource(root, id);
console.log(`\n${C.b(k.name)} ${C.dim(`For ${k.for}`)}`);
console.log(C.dim(` Get one at ${k.get}`));
const hint = source ? `Enter keeps the one ${SOURCE_WORDS[source].replace(/^saved /, '')}${source === 'saved' ? ', - removes it' : ''}` : required ? 'Enter to stop' : 'Enter skips';
for (;;) {
const v = (await hiddenPrompt(` Paste it ${C.dim(`(hidden; ${hint})`)}: `)).trim();
if (!v) return source;
if (v === '-') { keys.saveKey(root, id, null); console.log(' Removed.'); return keys.keySource(root, id); }
process.stdout.write(C.dim(' Checking… '));
const r = await keys.verifyKey(root, id, v);
if (r.ok === false) { console.log(C.red(`✖ ${r.detail}. Try again.`)); continue; }
keys.saveKey(root, id, v);
if (r.tier) voice.saveVoice(root, { elevenlabs: { tier: r.tier } });
console.log(r.ok ? `${C.green('✔')} ${r.detail}. Saved.` : `${C.acc('●')} Saved, but ${r.detail}.`);
return 'saved';
}
}
// The walk-through: every key in turn, then any others sessions should get.
async function keysWalk(root) {
for (const id of Object.keys(keys.KEYS)) await askKey(root, id);
console.log(`\n${C.b('Other keys for sessions')} ${C.dim('Anything a pipeline\'s tools read from the environment, e.g. GEMINI_API_KEY.')}`);
for (;;) {
const name = (await prompterOnce(` Name ${C.dim('(Enter when done)')}: `)).trim().toUpperCase();
if (!name) break;
const value = (await hiddenPrompt(` ${name} ${C.dim('(hidden; Enter removes it)')}: `)).trim();
try { keys.setSessionKey(root, name, value); console.log(value ? ` ${C.green('✔')} Saved.` : ' Removed.'); } catch (e) { console.log(C.red(` ✖ ${e.message}`)); }
}
console.log();
showKeys(root);
const v = voice.voiceConfig(root);
if (keys.keySource(root, 'elevenlabs') && v.engine !== 'elevenlabs') console.log(`\n To narrate with it: ${C.b('mortiflix voice elevenlabs')} (pick a voice and model).`);
}
async function keysCmd(root, [sub, name]) {
needStudio(root);
if (sub === 'set' || sub === 'remove') {
if (!name) throw new Error(`mortiflix keys ${sub} <${Object.keys(keys.KEYS).join('|')}|NAME>`);
const id = keys.KEYS[name.toLowerCase()] ? name.toLowerCase() : null;
if (sub === 'remove') {
if (id) keys.saveKey(root, id, null); else keys.setSessionKey(root, name, null);
return console.log('Removed.');
}
if (id && process.stdin.isTTY) return askKey(root, id);
const value = (await hiddenPrompt(process.stdin.isTTY ? `${name} ${C.dim('(hidden)')}: ` : '')).trim();
if (!value) throw new Error('no key given');
if (!id) { keys.setSessionKey(root, name, value); return console.log(`${C.green('✔')} ${name} saved in session.env.`); }
const r = await keys.verifyKey(root, id, value);
if (r.ok === false) throw new Error(r.detail);
keys.saveKey(root, id, value);
if (r.tier) voice.saveVoice(root, { elevenlabs: { tier: r.tier } });
return console.log(`${C.green('✔')} ${keys.KEYS[id].name} saved${r.ok ? ` (${r.detail})` : `, but ${r.detail}`}.`);
}
if (sub) throw new Error('mortiflix keys [set|remove <name>]');
if (!process.stdin.isTTY) return showKeys(root);
return keysWalk(root);
}
// ---- setup ----
async function confirm(question, yes = false) {
const v = (await prompterOnce(`${question} ${C.dim(yes ? '[Y/n]' : '[y/N]')} `)).trim().toLowerCase();
return v ? v.startsWith('y') : yes;
}
const PART_IDS = setup.PARTS.map((p) => p.id);
function partHeader(part, i) {
console.log(`\n${C.acc(`${i + 1}/${setup.PARTS.length}`)} ${C.b(part.title)}`);
console.log(` ${part.why}`);
console.log(C.dim(` Needs: ${part.needs}`));
}
// Installs one tool after saying what it is, where it goes and how big it is.
async function offerInstall(root, id, { ask = true, build = false } = {}) {
const info = setup.TOOL_INFO[id];
console.log(` ${C.b(info.name)}: ${info.what}. Goes to ${info.where} (${info.size}).`);
if (ask && !(await confirm(' Install it now?', true))) { console.log(C.dim(' Skipped.')); return false; }
const started = Date.now();
try {
const r = await setup.installTool(root, id, { build, log: (l) => console.log(C.dim(` ${l}`)) });
console.log(` ${r.problems ? C.acc('●') : C.green('✔')} ${info.name}: ${r.detail || 'installed'}${r.problems ? ` (${r.problems})` : ''} ${C.dim(`${Math.round((Date.now() - started) / 1000)} s`)}`);
return true;
} catch (e) {
console.log(C.red(` ✖ ${info.name}: ${e.message}`));
return false;
}
}
const mark = (ok) => (ok ? C.green('✔') : C.dim('·'));
async function setupPart(root, id, st) {
if (id === 'claude') {
const config = loadConfig(root);
const cc = BACKENDS['claude-code'].available(config, root);
console.log(` ${mark(cc.ok)} Claude Code: ${cc.detail}`);
console.log(` ${mark(Boolean(keys.keySource(root, 'anthropic')))} Anthropic API key: ${keys.keySource(root, 'anthropic') || 'not set'}`);
console.log(` In use: ${C.b(config.backend)}`);
if (cc.ok && config.backend !== 'claude-code' && await confirm(' Use your Claude Code login (your plan pays)?', true)) saveConfig(root, { backend: 'claude-code' });
if (!cc.ok) {
console.log(C.dim(' Claude Code isn\'t installed: https://claude.com/claude-code (then run this again), or use an API key.'));
if (await confirm(' Use an Anthropic API key instead (you pay per token)?', true) && await askKey(root, 'anthropic', { required: true })) saveConfig(root, { backend: 'anthropic-api' });
}
return;
}
if (id === 'rendering') {
if (st.kinetograph.ok) {
console.log(` ${mark(true)} ${st.kinetograph.detail} (${st.kinetograph.path})`);
// Installing again puts back the pinned version when another one is there.
} else await offerInstall(root, 'kinetograph', { ask: false });
return;
}
if (id === 'transitions') {
if (st.transitions.ok) {
console.log(` ${mark(true)} ${st.transitions.detail} (${st.transitions.path})`);
if (await confirm(' Update the library to its latest version?', false)) await offerInstall(root, 'transitions', { ask: false });
} else await offerInstall(root, 'transitions', { ask: false });
return;
}
if (id === 'narration') {
const v = voice.voiceConfig(root);
console.log(` Now: ${C.b({ none: 'no narration', elevenlabs: 'ElevenLabs', own: 'your own voice' }[v.engine])}`);
console.log(` 1. ElevenLabs: their voices, paid per character. Needs an API key. The default, and the only voice the studio generates.`);
console.log(' 2. No narration: on-screen text, music and sound.');
console.log(' 3. Your own voice: you read the script line by line in the recording booth (web studio or terminal), or import files.');
const pick = (await prompterOnce(` Which? ${C.dim(`[Enter keeps ${v.engine}]`)} `)).trim();
if (pick === '1') { await voiceCmd(root, ['elevenlabs']); }
else if (pick === '2') { voice.saveVoice(root, { engine: 'none' }); console.log(' Narration off.'); }
else if (pick === '3') await voiceCmd(root, ['own']);
return;
}
if (id === 'music') {
const m = setup.musicConfig(loadConfig(root));
if (!(await confirm(' Score your videos with original music (Strudel)?', m.engine !== 'none'))) { setup.saveMusic(root, { engine: 'none' }); return console.log(' No music: music steps are skipped.'); }
if (!st.strudel.ok) await offerInstall(root, 'strudel', { ask: false });
else console.log(` ${mark(true)} Strudel ${st.strudel.version}`);
if (!st.chrome.ok) await offerInstall(root, 'chrome');
else { console.log(` ${mark(true)} Renders in ${st.chrome.path}`); await setup.installTool(root, 'chrome'); }
console.log(C.dim(' The score is always rendered by Strudel and used in the video. A MIDI pack adds every part as MIDI, the stems'));
console.log(C.dim(' and a cue sheet (tempo, sections, hit points), for remaking the music in your own DAW.'));
const midi = await confirm(' Also deliver a MIDI pack with each video?', m.midi);
setup.saveMusic(root, { engine: 'strudel', midi });
return console.log(` ${C.green('✔')} Music: Strudel${midi ? ' + MIDI pack' : ''}.`);
}
if (id === 'daw') {
const ids = Object.keys(setup.DAWS);
ids.forEach((d, i) => console.log(` ${String(i + 1).padStart(2)}. ${setup.DAWS[d]}`));
console.log(' 0. None: general steps for any DAW');
const v = (await prompterOnce(` Which DAW do you finish music in? ${C.dim(`[Enter keeps ${st.daw.name || 'none'}]`)} `)).trim();
if (!v) return undefined;
const d = setup.saveDaw(root, v === '0' ? null : ids[Number(v) - 1] || v);
return console.log(` ${C.green('✔')} ${d.id ? `${d.name}: every MIDI pack comes with its import steps.` : 'No DAW named: the import steps are general.'}`);
}
if (id === 'daw-engine') {
const e = st['daw-engine'];
console.log(` ${mark(e.ok)} Sound engine: ${e.detail}${e.path ? ` (${e.path})` : ''}`);
if (e.ok) return undefined;
const missing = setup.engineBuildMissing();
if (missing.length) return console.log(C.dim(` To build it, first: sudo pacman -S --needed ${missing.join(' ')} (then mortiflix setup daw-engine --build)`));
return offerInstall(root, 'daw-engine', { build: true });
}
if (id === 'assets') {
const cur = setup.assetsConfig(loadConfig(root)).sites;
if (cur.length) console.log(` Your sites now: ${cur.map((x) => x.url).join(', ')}`);
console.log(' If you have a website you use for assets, list it here, one per line (Enter when done).');
console.log(C.dim(' Without one, you won\'t get stock assets: sessions make every visual themselves.'));
const sites = [];
for (;;) {
const v = (await prompterOnce(` Site ${sites.length + 1}${cur.length && !sites.length ? C.dim(' (Enter keeps your list, - clears it)') : ''}: `)).trim();
if (!v) break;
if (v === '-') { sites.length = 0; setup.saveAssetSites(root, []); console.log(' Cleared.'); break; }
sites.push(v);
}
if (sites.length) {
try { setup.saveAssetSites(root, sites); } catch (e) { return console.log(C.red(` ✖ ${e.message}`)); }
}
const now = setup.assetsConfig(loadConfig(root)).sites;
if (!now.length) return console.log(' No asset sites.');
if (!st['browser-harness'].ok) { if (!(await offerInstall(root, 'browser-harness'))) return; }
else console.log(` ${mark(true)} browser-harness ${st['browser-harness'].detail}`);
const rec = setup.browserHarnessRecordings();
if (rec && /default/.test(rec)) {
console.log(C.dim(' browser-harness can save screenshots and action traces of what sessions do in the browser, on this machine'));
console.log(C.dim(' only (they may include what\'s on those pages), so you can see what happened later.'));
setup.browserHarnessRecordings(await confirm(' Keep local browser recordings?', false));
}
console.log(` ${C.green('✔')} Sessions will use ${now.map((x) => x.url).join(', ')} in your own Chrome.`);
console.log(C.dim(' Sign in to them in Chrome. The first time, Chrome may ask to allow remote debugging: chrome://inspect/#remote-debugging'));
return;
}
if (id === 'publish') {
const cur = pub.publishConfig(loadConfig(root));
console.log(` Now: ${C.b(cur.service === 'none' ? 'not set up' : `Upload-Post${cur.profile ? ` (profile ${cur.profile})` : ''}`)}`);
console.log(' 1. Upload-Post: a hosted service with a free plan (10 uploads/mo) and paid plans. You connect your accounts on upload-post.com. Needs its API key.');
console.log(' 2. Don\'t publish from the studio: you download finals and post them yourself.');
const choice = (await prompterOnce(` Which? ${C.dim(`[Enter keeps ${cur.service}]`)} `)).trim();
if (choice === '2') { pub.savePublish(root, { service: 'none' }); return console.log(' Publishing off.'); }
if (choice === '1' || (!choice && cur.service === 'uploadpost')) {
pub.savePublish(root, { service: 'uploadpost' });
await askKey(root, 'uploadpost');
const profile = (await prompterOnce(` Upload-Post profile your accounts are connected under${cur.profile ? C.dim(` (Enter keeps ${cur.profile})`) : ''}: `)).trim();
if (profile) pub.savePublish(root, { profile });
return console.log(` ${C.green('✔')} Publishing through Upload-Post. Post a delivered video with ${C.b('mortiflix publish <project>')}.`);
}
return undefined;
}
if (id === '3d') {
if (!(await confirm(' Set up 3D (Blender and the toolkits)?', st.blender.ok))) return console.log(C.dim(' Skipped: 2D only.'));
if (!st.blender.ok) { if (!(await offerInstall(root, 'blender'))) return; }
else { console.log(` ${mark(true)} ${st.blender.detail} (${st.blender.path})`); await setup.installTool(root, 'blender'); }
console.log(C.dim(' The toolkits go into the studio\'s own Blender profile: your personal Blender setup is never changed.'));
for (const t of setup.ADDONS) console.log(C.dim(` ${t.name}: ${t.about}`));
console.log(C.dim(' Nova FX, Mortiflix\'s own particle engine, builds on Linux only for now (it compiles its core with gcc).'));
if (st['blender-addons'].ok && !(await confirm(' They\'re installed. Update them?', false))) return;
await offerInstall(root, 'blender-addons', { ask: !st['blender-addons'].ok });
console.log(` Open it yourself with ${C.b('mortiflix blender')} (Camera Flight is in the 3D Viewport › N › Flight).`);
}
if (id === 'craft') {
showCraft(st.craft);
const have = st.craft.apps.filter((x) => x.installed).map((x) => x.id);
console.log(C.dim(` Each is an open-source remake by the ArtCraft team (github.com/${craft.OWNER}), MIT or Apache-2.0, with its own MCP server.`));
const pick = (await prompterOnce(` Which? ${C.dim(`all, none, or names (e.g. effectcraft photocraft)${have.length ? '; Enter keeps what\'s installed' : ''}`)} `)).trim().toLowerCase();
if (pick === 'none' || (!pick && !have.length)) return console.log(C.dim(' None: sessions work without them.'));
const apps = !pick ? have : pick === 'all' ? craft.APP_IDS : pick.split(/[\s,]+/).filter(Boolean);
craft.saveCraftApps(root, apps);
await offerInstall(root, 'craft', { ask: false });
console.log(` Sessions get their MCP servers. For your own Claude Code: ${C.b('mortiflix craft register')}`);
}
}
// ---- the Craft apps ----
function showCraft(st) {
for (const x of st.apps) {
console.log(` ${x.installed ? C.green('✔') : C.dim('·')} ${x.name.padEnd(12)} ${C.dim(`${x.replaces}:`.padEnd(15))} ${x.use}${x.installed ? C.dim(` (${x.version})`) : ''}`);
}
}
async function craftCmd(root, [sub, ...args], a) {
needStudio(root);
if (!sub || sub === 'status') {
const st = craft.craftStatus(root);
if (a.json) return json(st);
console.log(C.b('The Craft apps'), C.dim(`(github.com/${craft.OWNER}, MIT or Apache-2.0)`));
showCraft(st);
return console.log(C.dim(`\n Install: mortiflix craft install [all | ${craft.APP_IDS.slice(0, 3).join(' ')} …]`));
}
if (sub === 'install') {
ownerOnly();
const apps = !args.length ? craft.craftConfig(loadConfig(root)).apps : args.includes('all') ? craft.APP_IDS : args;
for (const id of apps) if (!craft.APP_IDS.includes(id)) throw new Error(`unknown app "${id}" (${craft.APP_IDS.join(', ')})`);
craft.saveCraftApps(root, [...new Set([...craft.APPS.filter((x) => craft.installed(root, x.id)).map((x) => x.id), ...apps])]);
const r = await craft.installCraft(root, { apps, log: (l) => console.log(C.dim(` ${l}`)) });
console.log();
showCraft(r);
if (r.problems) console.log(C.red(`\n ✖ ${r.problems}`));
return console.log(C.dim('\n Sessions get their MCP servers. For your own Claude Code: mortiflix craft register'));
}
if (sub === 'remove') {
ownerOnly();
if (!args.length) throw new Error('mortiflix craft remove <app>…');
for (const id of args) craft.removeApp(root, id);
return console.log(`Removed ${args.join(', ')}.`);
}
if (sub === 'open') {
ownerOnly();
if (!args[0]) throw new Error('mortiflix craft open <app> [file]');
return console.log(`Opening ${craft.openApp(root, args[0], args[1] ? resolve(args[1]) : undefined)}`);
}
if (sub === 'register') {
ownerOnly();
const r = craft.registerWithClaude(root, { claudeBin: loadConfig(root).claudeBin || 'claude', apps: args.length ? args : undefined, log: (l) => console.log(l) });
return console.log(`\n${C.green('✔')} ${r.added.length} added, ${r.updated.length} updated${r.kept.length ? `, ${r.kept.length} left alone` : ''}. Restart Claude Code to load them; files go in the folder you start it in.`);
}
if (sub === 'mcp-config') return json(craft.mcpServers(root));
throw new Error('mortiflix craft [status|install|remove|open|register|mcp-config]');
}
async function showSetup(root) {
const st = await setup.setupStatus(root);
const v = voice.voiceConfig(root);
const config = loadConfig(root);
const row = (ok, name, detail) => console.log(` ${ok === null ? C.dim('·') : ok ? C.green('✔') : C.red('✖')} ${name.padEnd(12)} ${detail}`);
console.log(C.b('Your studio'));
row(BACKENDS[config.backend].available(config, root).ok, 'Claude', `${config.backend}: ${BACKENDS[config.backend].available(config, root).detail}`);
row(v.engine === 'none' ? null : v.engine === 'elevenlabs' ? Boolean(voice.elevenKey(root)) && Boolean(v.elevenlabs.voice_id) : null, 'Narration',
v.engine === 'none' ? 'none' : v.engine === 'elevenlabs' ? `ElevenLabs: ${v.elevenlabs.voice_name || 'no voice chosen'} on ${v.elevenlabs.model_id}${voice.elevenKey(root) ? '' : ', key missing'}` : 'your own voice (the recording booth)');
row(st.kinetograph.ok, 'Rendering', st.kinetograph.ok ? st.kinetograph.detail : `${st.kinetograph.detail} (mortiflix setup rendering)`);
row(st.transitions.ok, 'Transitions', st.transitions.ok ? `remotion-transitions: ${st.transitions.detail}` : 'library not installed (mortiflix setup transitions)');
row(st.music.engine === 'none' ? null : st.strudel.ok && st.chrome.ok, 'Music', st.music.engine === 'none' ? 'none' : `Strudel: ${st.strudel.detail}; Chrome: ${st.chrome.ok ? 'found' : 'missing'}${st.music.midi ? '; MIDI pack on' : ''}`);
row(st.daw.id ? true : null, 'Your DAW', st.daw.name || 'not named: general import steps');
row(st['daw-engine'].path ? st['daw-engine'].ok : null, 'Sound engine', st['daw-engine'].ok ? st['daw-engine'].detail : `${st['daw-engine'].detail}: mortiflix setup daw-engine --build`);
row(st.assets.sites.length ? st['browser-harness'].ok : null, 'Assets', st.assets.sites.length ? `${st.assets.sites.map((x) => x.url).join(', ')} (browser-harness ${st['browser-harness'].ok ? st['browser-harness'].detail : 'missing'})` : 'no sites: sessions make every visual themselves');
const pubCfg = st.publish;
row(pubCfg.service === 'none' ? null : Boolean(pubCfg.key), 'Publishing', pubCfg.service === 'none' ? 'off: you post finals yourself'
: `${pub.SERVICES[pubCfg.service].name}${pubCfg.profile ? `, profile ${pubCfg.profile}` : ''}${pubCfg.key ? '' : ', key missing'}`);
row(st.blender.ok ? st['blender-addons'].ok : null, '3D', st.blender.ok ? `${st.blender.detail}; ${st['blender-addons'].detail}` : 'not set up');
row(st.craft.apps.some((x) => x.installed) ? st.craft.ok : null, 'Craft apps', st.craft.detail);
}
async function setupView(root) {
const config = loadConfig(root);
const backend = BACKENDS[config.backend].available(config, root);
const { presets, output_formats, servers, ...narration } = voice.voiceOverview(root);
return {
backend: { name: config.backend, ...backend },
backends: Object.fromEntries(Object.entries(BACKENDS).map(([name, b]) => [name, b.available(config, root)])),
narration,
tools: await setup.setupStatus(root),
parts: setup.PARTS,
tool_info: setup.TOOL_INFO,
};
}
async function setupWalk(root, only = null) {
ensureStudio(root);
const parts = only ? setup.PARTS.filter((p) => p.id === only) : setup.PARTS;
for (const part of parts) {
partHeader(part, setup.PARTS.indexOf(part));
if (!only && !(await confirm(` Set up ${part.title.toLowerCase()} now?`, true))) { console.log(C.dim(' Skipped.')); continue; }
// One part failing (a service down, a refused key) never ends the whole walkthrough.
try { await setupPart(root, part.id, await setup.setupStatus(root)); }
catch (e) { console.log(C.red(` ✖ ${part.title}: ${e.message}`)); console.log(C.dim(` Try this part again with: mortiflix setup ${part.id}`)); }
}
console.log();
await showSetup(root);
}
async function setupCmd(root, [part, ...args], a) {
needStudio(root);
if (part === 'install') {
if (!args.length) throw new Error(`mortiflix setup install <${setup.TOOLS.join('|')}>…`);
for (const id of args) if (!setup.TOOLS.includes(id)) throw new Error(`unknown tool "${id}" (${setup.TOOLS.join(', ')})`);
for (const id of args) await offerInstall(root, id, { ask: false });
return undefined;
}
if (part === 'daw-engine' && a.build) { if (!(await offerInstall(root, 'daw-engine', { ask: false, build: true }))) process.exitCode = 1; return undefined; }
if (part === 'music' && args.length) {
const m = setup.saveMusic(root, { engine: args[0], midi: a.midi ? true : a['no-midi'] ? false : undefined });
return console.log(`${C.green('✔')} Music: ${m.engine === 'none' ? 'none (music steps are skipped)' : `Strudel${m.midi ? ' + MIDI pack' : ''}`}.`);
}
if (part === 'browser') {
if (args.length || a.start !== undefined) setup.saveBrowser(root, { cdpUrl: args[0] === 'none' ? null : args[0], start: typeof a.start === 'string' ? a.start : undefined });
const b = setup.browserConfig(loadConfig(root));
const st = await setup.browserCheck(root);
return console.log(`${st.ok ? C.green('✔') : C.dim('·')} Studio browser: ${st.detail}${b.start ? `\n Started when needed with: ${b.start}` : ''}`);
}
if (part === 'daw' && args.length) {
const d = setup.saveDaw(root, args[0]);
return console.log(`${C.green('✔')} ${d.id ? `Your DAW: ${d.name}. Every MIDI pack comes with its import steps.` : 'No DAW named: the import steps are general.'}`);
}
if (part === 'assets' && (args.length || a.clear)) {
setup.saveAssetSites(root, a.clear ? [] : args);
const now = setup.assetsConfig(loadConfig(root)).sites;
return console.log(now.length ? `${C.green('✔')} Asset sites: ${now.map((x) => x.url).join(', ')}` : 'No asset sites.');
}
if (part === 'publish' && args.length) {
const c = pub.savePublish(root, { service: args[0], profile: typeof a.profile === 'string' ? a.profile : undefined });
return console.log(c.service === 'none' ? 'Publishing off.' : `${C.green('✔')} Publishing through ${pub.SERVICES[c.service].name}. Its key: mortiflix keys set ${c.service}`);
}
if (part === 'status' && a.json) return json(await setupView(root));
if (part === 'status' || !process.stdin.isTTY) return showSetup(root);
if (part && !PART_IDS.includes(part)) throw new Error(`mortiflix setup [${PART_IDS.join('|')}|status]`);
return setupWalk(root, part || null);
}
// One visible line from the terminal (a fresh readline each time, so it can take turns with hiddenPrompt).
async function prompterOnce(question) {
const rl = prompter();
try { return (await rl.question(question)) ?? ''; } catch { return ''; } finally { rl.close(); }
}
function checks(root, [action, id]) {
needStudio(root);
if (action === 'approve' || action === 'reject') {
ownerOnly();
const c = gates.decideCheck(root, id, action === 'approve');
return console.log(`${action === 'approve' ? C.green('✔ Added to the checklist') : 'Rejected'}: ${c.title}`);
}
const all = readJson(paths(root).checks);
console.log(C.b('Proposed by sessions (waiting for you):'));
for (const c of all.proposed) console.log(` ${C.acc(c.id)} ${c.title}\n ${C.dim(c.how)}${c.example ? `\n ${C.dim(`e.g. ${c.example}`)}` : ''}`);
if (!all.proposed.length) console.log(C.dim(' none'));
console.log(C.b('\nYour checklist (on top of each pipeline\'s own):'));
for (const c of all.active) console.log(` ${c.id} ${c.title}`);
if (!all.active.length) console.log(C.dim(' none yet'));
}
// The narration offer: ElevenLabs (the only generated voice since 2026-11-01).
function voiceOffer() {
return `${C.b('mortiflix voice elevenlabs')} for ElevenLabs voices (a key from elevenlabs.io), ${C.b('mortiflix voice own')} or ${C.b('mortiflix voice none')}.`;
}
// The recording booth (src/booth.mjs) from a terminal, or importing takes recorded elsewhere.
async function recordCmd(root, rest, a) {
if (a['list-devices']) {
const args = rec.listDevicesArgs();
if (!args) return console.log('Linux: `pactl list short sources` (PipeWire/PulseAudio) or `arecord -l` (ALSA). Pass one with --device pulse:<name> or --device alsa:hw:1.');
spawnSync('ffmpeg', args, { stdio: 'inherit' });
return;
}
const id = pick(root, rest[0]);
if (typeof a.import === 'string') {
const r = booth.importFolder(root, id, a.import);
for (const t of r.imported) console.log(` ${C.green('✔')} ${t.line} ${t.file} ${(t.duration_ms / 1000).toFixed(1)} s${t.flags.length ? C.red(` · ${booth.FLAG_ADVICE[t.flags[0]]}`) : ''}`);
if (r.missing.length) console.log(` ${C.red(`${r.missing.length} line(s) had no file`)}: ${r.missing.join(', ')}`);
return recordDone(root, id);
}
await rec.terminalBooth(root, id, { device: typeof a.device === 'string' ? a.device : null });
return recordDone(root, id);
}
async function recordDone(root, id) {
const st = booth.boothStatus(root, id);
if (st.missing.length) return console.log(`\n${st.kept} of ${st.lines.length} lines kept. Carry on any time: ${C.b(`mortiflix record ${id}`)}`);
console.log(`\n${C.green('✔')} Every line has a kept take.`);
const p = loadProject(root, id);
if (p.state === 'paused' && process.stdin.isTTY && !/^n/i.test((await prompterOnce('Give it to the studio now? [Y/n] ')).trim())) {
gates.resume(root, id);
console.log('Resumed: the studio builds the narration from your takes.');
}
}
// Music the owner finishes in their own DAW (src/music.mjs): the MIDI pack out, the master in.
async function musicCmd(root, rest, a) {
const id = pick(root, rest[0]);
if (typeof a.midi === 'string') {
writeFileSync(a.midi, music.midiPack(root, id));
return console.log(`${C.green('✔')} ${a.midi}: every channel, the whole arrangement, the cue sheet (tempo, sections and hits are markers)`);
}
if (a.song) {
const { importProjectSong } = await import('./song-store.mjs');
const r = await importProjectSong(root, id);
const notes = r.song.patterns.reduce((s, p) => s + Object.values(p.notes).reduce((x, ns) => x + ns.length, 0), 0);
for (const w of r.warnings) console.log(` ${C.acc('!')} ${w}`);
console.log(`${C.green('✔')} Song: ${r.song.patterns.length} sections × ${r.song.channels.length} parts, ${notes} notes, the same as the score note for note.`);
console.log(` ${r.paths.strudel} (plain Strudel: paste it into the Strudel REPL and it plays)`);
console.log(` ${r.paths.song} (rev ${r.rev})`);
return;
}
if (typeof a.import === 'string') {
const r = await music.importMaster(root, id, { file: a.import });
for (const w of r.warnings) console.log(` ${C.acc('!')} ${w}`);
if (!r.ok) { for (const e of r.errors) console.log(` ${C.red('✖')} ${e}`); throw new Error('the master was not imported'); }
console.log(`${C.green('✔')} Imported ${r.source}: ${r.measured.seconds} s, ${r.measured.lufs} LUFS, true peak ${r.measured.true_peak} dBTP. The studio uses it as the music.`);
const p = loadProject(root, id);
if (p.state === 'paused' && !p.needs_you?.by_you) { gates.resume(root, id); console.log('Resumed: the studio carries on with your master.'); }
return;
}
const st = music.musicStatus(root, id);
if (!st.expect) return console.log('No score yet: the MIDI pack comes once the studio has written the score and it passes its check.');
const e = st.expect;
console.log(`${C.b(e.title || id)}: ${e.bars} bars at ${e.bpm} BPM (${e.meter}) = ${e.seconds} s${e.first_note_sec ? `, first note at ${e.first_note_sec} s` : ''}`);
console.log(`Finishing: ${st.finish === 'own' ? 'you, from the MIDI pack in your own DAW' : 'Strudel renders it (instruments chosen by the studio)'}`);
console.log(st.midi.length ? `MIDI pack: ${st.midi.length} files. Save it with ${C.b(`mortiflix music ${id} --midi pack.zip`)}` : 'MIDI pack: not yet (it comes with a score that passes its check)');
if (st.own) console.log(`Your master: ${st.own.source}, ${st.own.measured.seconds} s, imported ${st.own.imported_at}${st.own.warnings.length ? C.acc(` · ${st.own.warnings.length} warning(s)`) : ''}`);
else if (st.finish === 'own') console.log(`Your master: not yet. Export from bar 1 and run ${C.b(`mortiflix music ${id} --import <file>`)}`);
}
async function voiceCmd(root, [sub, ...words]) {
needStudio(root);
const v = voice.voiceConfig(root);
if (!sub) {
const o = voice.voiceOverview(root);
console.log(`Narration: ${C.b({ none: 'none', elevenlabs: 'ElevenLabs', own: 'your own voice (the recording booth)' }[o.engine])}`);
if (o.engine === 'elevenlabs') console.log(` voice ${o.elevenlabs.voice_name || C.red('not chosen')} · model ${o.elevenlabs.model_id} · key ${o.elevenlabs_key || C.red('missing')}`);
if (o.needs_key) console.log(` ${C.red(o.needs_key)}`);
console.log(`\nOptions: ${voiceOffer()}`);
return;
}
if (sub === 'none') { voice.saveVoice(root, { engine: 'none' }); return console.log('Narration off: videos use on-screen text, music and sound.'); }
if (sub === 'own') {
voice.saveVoice(root, { engine: 'own' });
console.log(`${C.green('✔')} Narration: your own voice. When a video reaches its narration, the studio writes the script as short lines and asks you to record them:`);
console.log(` in the web studio (the project's ${C.b('Record narration')} button), in a terminal (${C.b('mortiflix record <project>')}),`);
console.log(` or from files you recorded elsewhere (${C.b('mortiflix record <project> --import <folder>')}).`);
return;
}
if (sub === 'test') return voiceTest(root, words.join(' '));
const rl = prompter();
try {
if (sub === 'elevenlabs') {
if (!voice.elevenKey(root)) {
rl.close();
if (!(await askKey(root, 'elevenlabs', { required: true }))) throw new Error('no key given');
return voiceCmd(root, ['elevenlabs']);
}
const el = new voice.eleven.ElevenLabs({ key: voice.elevenKey(root), server: v.elevenlabs.server });
const a = await el.account();
voice.saveVoice(root, { engine: 'elevenlabs', elevenlabs: { tier: a.tier } });
console.log(`${C.green('✔')} ${a.tier} plan · ${a.characters_left.toLocaleString()} credits left${a.commercial_use ? ' · commercial use' : C.red(' · free plan: non-commercial, credit ElevenLabs')}`);
const search = (await rl.question(`Find a voice (e.g. "warm narrator", blank for all)${v.elevenlabs.voice_name ? C.dim(` [keep ${v.elevenlabs.voice_name}]`) : ''}: `)).trim();
if (search || !v.elevenlabs.voice_id) {
let { voices: list } = await el.voices({ search, page_size: 15 });
let fromLibrary = false;
if (!list.length) { list = (await el.library({ search, page_size: 15 })).voices; fromLibrary = true; }
if (!list.length) throw new Error('no voices match');
list.forEach((x, i) => console.log(` ${String(i + 1).padStart(2)}. ${C.b(x.name)} ${C.dim(Object.values(x.labels || {}).filter(Boolean).join(' · '))}${fromLibrary ? C.dim(' (Voice Library)') : ''}`));
const pick = list[Number((await rl.question('Number: ')).trim()) - 1];
if (!pick) throw new Error('no voice picked');
const id = fromLibrary ? (await el.addFromLibrary(pick.owner, pick.id, pick.name)).id : pick.id;
voice.saveVoice(root, { elevenlabs: { voice_id: id, voice_name: pick.name } });
}
const models = await el.models();
console.log(`Model: ${models.map((m, i) => `${i + 1}. ${m.id}${m.recommended ? C.dim(' (recommended)') : ''}`).join(' ')}`);
const m = models[Number((await rl.question(`Number ${C.dim(`[${v.elevenlabs.model_id}]`)}: `)).trim()) - 1];
if (m) voice.saveVoice(root, { elevenlabs: { model_id: m.id } });
const now = voice.voiceConfig(root).elevenlabs;
console.log(`${C.green('✔')} ElevenLabs: ${now.voice_name} on ${now.model_id}. Every other option (stability, format, dictionaries, sound effects, music) is in the web studio's Settings.`);
console.log(` Hear it: ${C.b('mortiflix voice test')}`);
return;
}
if (sub === 'local') throw new Error('the local voice (Qwen3-TTS) was removed: the studio narrates with ElevenLabs (mortiflix voice elevenlabs)');
throw new Error('mortiflix voice [elevenlabs|own|none|test]');
} finally {
rl.close();
}
}
async function voiceTest(root, text) {
const v = voice.voiceConfig(root);
const line = text || 'Every city has a heartbeat. Ours runs on bikes.';
let out;
if (v.engine === 'elevenlabs') out = { ...(await new voice.eleven.ElevenLabs({ key: voice.elevenKey(root), server: v.elevenlabs.server }).sample(v.elevenlabs, line)), format: 'mp3' };
else throw new Error('no generated voice set up (mortiflix voice elevenlabs)');
record(root, { provider: 'elevenlabs', kind: 'tts sample', stage: 'voice', model: v.elevenlabs.model_id, credits: ttsCredits(v.elevenlabs.model_id, out.characters) });
const file = join(paths(root).run, `voice-test.${out.format}`);
writeFileSync(file, out.audio);
console.log(`${C.green('✔')} ${file}`);
if (spawnSync('ffplay', ['-version']).status === 0) spawnSync('ffplay', ['-nodisp', '-autoexit', '-loglevel', 'error', file], { stdio: 'inherit' });
}
// The walk-through: a logo sting made by the demo backend, so the whole loop can be tried for free.
async function demo(root) {
if (!existsSync(paths(root).config)) await init(root, { yes: true });
const logo = join(paths(root).run, 'demo-logo.svg');
writeFileSync(logo, '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200"><circle cx="100" cy="100" r="80" fill="#f97316"/><text x="100" y="118" text-anchor="middle" font-size="56" font-family="sans-serif" fill="#fff">M</text></svg>');
const id = await newProject(root, 'logo-sting', { _: [], set: ['mood=calm and premium'], file: [`logo=${logo}`], title: 'Demo sting', backend: 'demo', yes: true });
console.log(`\nThis project uses the ${C.b('demo')} backend (placeholder work, no Claude). Running it now…`);
await runLoop(root, {});
console.log(`\nNext: ${C.b(`mortiflix review ${id}`)} in the terminal, or ${C.b('mortiflix serve')} to review in the browser.`);
}