#!/usr/bin/env node // Writes plan.json for one loading reveal: the before photo (already cropped to 9:16 by prepare-before.mjs), // what must not change (the lock), what the after shows and how it moves, copied from assets/reveals.json. // Edit any FILL: field (and anything else) by hand, then run build-requests.mjs. It calls no API. // // Usage: // node scripts/build-plan.mjs --out plan.json --kind pet|room|product|sketch|person --before before-9x16.jpg // --reveal costume|room|sketch|unbox|custom --change "what the after shows" [--lock "what must not change"] // [--refs product.jpg[,other.jpg]] [--hold 2] [--after 5] [--label loading] [--no-dots] [--no-draft] [--final kling|veo|seedance] // [--consent yes] [--force] // // --kind person needs --consent yes: your own photo or written consent from an adult, no public figure, nobody under 18. // Node 18 or newer. No npm packages. import { spawnSync } from 'node:child_process' import { existsSync, readFileSync, writeFileSync } from 'node:fs' import { dirname, extname, join, relative, resolve } from 'node:path' import { fileURLToPath } from 'node:url' const FLAGS = new Set(['out', 'kind', 'before', 'reveal', 'change', 'lock', 'refs', 'hold', 'after', 'label', 'no-dots', 'no-draft', 'final', 'consent', 'force']) const SWITCHES = new Set(['no-dots', 'no-draft', 'force']) const KINDS = ['pet', 'room', 'product', 'sketch', 'person'] const SUBJECT = { pet: 'The pet', room: 'The room', product: 'The product', sketch: 'The drawing', person: 'The person' } const FINALS = { veo: [4, 6, 8], kling: [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], seedance: [4, 5, 6, 7, 8, 9, 10, 11, 12] } const IMAGE = new Set(['.jpg', '.jpeg', '.png', '.webp']) const LOCK_HINT = { pet: 'FILL: one line from the photo: breed look, size, coat colour and pattern, markings and where they are, eye colour, ear shape, collar if any. Example: a small scruffy terrier mix about 35 cm at the shoulder, wiry tan and white coat, a black patch over the left eye, amber eyes, one ear up and one folded, a red collar.', room: 'FILL: one line from the photo: the room, the window and door positions, the floor, the walls and the camera angle that must stay. Example: a small living room seen from the doorway, a tall window on the right, light oak floor, plain white walls, a rug in the middle.', product: 'FILL: one line from the photo: the shape, proportions, colours and finish of the product, and its label area (plain, or the exact words if the user supplied the photo).', sketch: 'FILL: one line from the drawing: what it shows, its shape, proportions and colours, and where it sits on the page.', person: 'FILL: one line from the photo: face shape, skin tone, age range, hair colour and style, glasses, build. Everything here stays exactly as it is.', } const root = join(dirname(fileURLToPath(import.meta.url)), '..') function fail(message) { console.error(message) process.exit(1) } const opts = {} const argv = process.argv.slice(2) for (let i = 0; i < argv.length; i++) { const a = argv[i] if (!a.startsWith('--')) fail(`Unexpected argument "${a}". Flags look like --name value.`) const key = a.slice(2) if (!FLAGS.has(key)) fail(`Unknown flag --${key}. Allowed: ${[...FLAGS].map((f) => `--${f}`).join(', ')}`) if (SWITCHES.has(key)) { opts[key] = true continue } const value = argv[i + 1] if (value === undefined || value.startsWith('--')) fail(`--${key} needs a value.`) opts[key] = value i++ } const usage = 'Usage: node scripts/build-plan.mjs --out plan.json --kind pet|room|product|sketch|person --before before-9x16.jpg --reveal costume|room|sketch|unbox|custom --change "what the after shows" [--lock "..."] [--refs product.jpg] [--hold 2] [--after 5] [--final kling|veo|seedance] [--consent yes]' if (!opts.out || !opts.kind || !opts.before || !opts.reveal) fail(usage) if (!opts.out.endsWith('.json')) fail('--out must end in .json, for example plan.json.') if (existsSync(opts.out) && !opts.force) fail(`${opts.out} already exists. Edit it, pick another --out, or pass --force to start again.`) if (!KINDS.includes(opts.kind)) fail(`--kind must be one of ${KINDS.join(', ')}, not "${opts.kind}".`) const { reveals } = JSON.parse(readFileSync(join(root, 'assets', 'reveals.json'), 'utf8')) const reveal = reveals[opts.reveal] if (!reveal) fail(`Unknown reveal "${opts.reveal}". Use ${Object.keys(reveals).join(', ')}.`) if (!reveal.kinds.includes(opts.kind)) fail(`The "${opts.reveal}" reveal is for ${reveal.kinds.join(', ')}, not "${opts.kind}". Pick another reveal or use custom.`) const change = (opts.change ?? '').trim() if (!change && opts.reveal !== 'custom') fail('--change is required: say what the after shows, in the user\'s own words, for example "a small red hero cape and round goggles".') if (change.length > 300) fail(`--change is ${change.length} characters. Keep it to 300 or fewer.`) if (opts.kind === 'person') { if (opts.consent !== 'yes') { fail('A people reveal needs consent. Only use a photo of yourself, or of an adult who has said yes in writing to this reveal. Never a celebrity or public figure, never someone under 18, never a photo taken from the internet. Pass --consent yes once that is true (references/safety-and-likeness.md).') } if (opts.final && opts.final !== 'kling') fail('The people reveal uses Kling for the final: Seedance refuses a clearly visible realistic face and Veo drifts the face. Drop --final.') } const final = opts.final ?? 'kling' if (!FINALS[final]) fail(`--final must be veo, kling or seedance, not "${final}".`) const after = Number(opts.after ?? 5) if (!FINALS[final].includes(after)) fail(`--after ${opts.after} is not available on ${final}. Use ${FINALS[final].join(', ')} seconds (5 is the format).`) const hold = Number(opts.hold ?? 2) if (!Number.isFinite(hold) || hold < 1.5 || hold > 3) fail('--hold must be from 1.5 to 3 seconds (2 is the format).') if (hold + after < 6 || hold + after > 8.5) fail(`Hold ${hold} s + after ${after} s makes ${hold + after} s. The format is 6 to 8 s.`) const label = (opts.label ?? 'loading').trim() if (label.length > 16) fail('--label can be 16 characters at most.') const base = dirname(resolve(opts.out)) const relPath = (p) => relative(base, resolve(p)) || p if (!existsSync(opts.before)) fail(`Before photo not found: ${opts.before}`) if (!IMAGE.has(extname(opts.before).toLowerCase())) fail(`${opts.before} must be a .jpg, .png or .webp image.`) const dims = spawnSync('ffprobe', ['-v', 'error', '-select_streams', 'v:0', '-show_entries', 'stream=width,height', '-of', 'csv=p=0', opts.before], { encoding: 'utf8' }) if (!dims.error && dims.status === 0) { const [w, h] = dims.stdout.trim().split(',').map(Number) if (w && h && Math.abs(w / h - 9 / 16) > 0.03) fail(`${opts.before} is ${w}x${h}, not 9:16. Run scripts/prepare-before.mjs first: it crops the photo so the before and after frames share the same framing.`) } const refs = (opts.refs ?? '').split(',').map((p) => p.trim()).filter(Boolean) if (refs.length > 2) fail('--refs takes up to 2 extra reference photos (for example the product photo).') for (const p of refs) { if (!existsSync(p)) fail(`Reference photo not found: ${p}`) if (!IMAGE.has(extname(p).toLowerCase())) fail(`${p} must be a .jpg, .png or .webp image.`) } if (opts.reveal === 'unbox' && !refs.length) console.error('note: an unboxing reveal works best with a photo of the product itself in --refs, so its shape and colours are kept.') const subject = SUBJECT[opts.kind] const fill = (text) => text.replaceAll('{{SUBJECT}}', subject).replaceAll('{{CHANGE}}', change || 'FILL: what changes') const plan = { skill: 'loading-reveal-transition', brief: { aspect: '9:16', hold, after, flash: 0.25, label, dots: !opts['no-dots'], final_model: final, final_resolution: 'model default, scaled to 720x1280', draft: opts.kind !== 'person' && !opts['no-draft'], audio: false }, subject: { kind: opts.kind, lock: (opts.lock ?? '').trim() || LOCK_HINT[opts.kind], before: relPath(opts.before), prepared: relPath(opts.before), refs: refs.map(relPath), }, consent: opts.kind === 'person' ? { confirmed: true, own_photo_or_written_consent: true, adult: true, not_a_public_figure: true, statement: 'FILL: who the person is (first name or "me") and where the written consent is kept. No surname, no contact details.' } : null, reveal: { id: opts.reveal, label: reveal.label, change, after: fill(reveal.after), camera: reveal.camera, motion: fill(reveal.motion), hazards: reveal.hazards, tested_reveal: reveal.tested, }, files: { keyframe: '', draft: '', final: '', in: 0.1, out: after }, } writeFileSync(opts.out, `${JSON.stringify(plan, null, 2)}\n`) const fills = JSON.stringify(plan).match(/FILL:/g)?.length ?? 0 console.log(`Wrote ${opts.out}: ${opts.reveal} reveal of a ${opts.kind}, before ${hold} s + after ${after} s, final on ${final}${plan.brief.draft ? '' : opts.kind === 'person' ? ' (no Seedance draft: it refuses faces)' : ' (no draft)'}.`) if (fills) console.log(`${fills} FILL: field(s) left. Write them (subject.lock first, from the photo) before build-requests.mjs.`) if (!reveal.tested) console.log(`note: the "${opts.reveal}" reveal has not made a passing sample yet. Test it with one Kling final before promising the look.`)