#!/usr/bin/env node // Writes plan.json for one to three pet clips: the pet lock, the pet photos and, per clip, the scene, // action and sound copied from assets/scenarios.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 dog|cat|other --photos pet1.jpg[,pet2.jpg,pet3.jpg] // --scenarios barista[,video-call,...] [--pet "lock text"] [--room-photo kitchen.jpg] // [--final veo|kling|seedance] [--duration 8] [--caption "exact caption"] [--force] // // Scenarios: barista, video-call, fridge-raid, chef, dj, piano, custom (see assets/scenarios.json). // Node 18 or newer. No npm packages. 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', 'photos', 'scenarios', 'pet', 'room-photo', 'final', 'duration', 'caption', 'force']) const SWITCHES = new Set(['force']) const KINDS = ['dog', 'cat', 'other'] 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 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 dog|cat|other --photos pet1.jpg[,pet2.jpg] --scenarios barista[,video-call] [--pet "lock"] [--room-photo room.jpg] [--final veo|kling|seedance] [--duration 8] [--caption "..."]' if (!opts.out || !opts.kind || !opts.photos || !opts.scenarios) 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 dog, cat or other, not "${opts.kind}". Rabbits, guinea pigs and birds are "other": results vary more.`) const final = opts.final ?? 'kling' if (!FINALS[final]) fail(`--final must be veo, kling or seedance, not "${final}".`) const duration = Number(opts.duration ?? 8) if (!FINALS[final].includes(duration)) fail(`--duration ${opts.duration} is not available on ${final}. Use ${FINALS[final].join(', ')} seconds (8 is the format).`) const base = dirname(resolve(opts.out)) const relPath = (p) => relative(base, resolve(p)) || p const photos = opts.photos.split(',').map((p) => p.trim()).filter(Boolean) if (photos.length < 1 || photos.length > 3) fail(`--photos takes 1 to 3 photos of the pet, comma-separated, not ${photos.length}.`) for (const p of photos) { if (!existsSync(p)) fail(`Pet photo not found: ${p}`) if (!IMAGE.has(extname(p).toLowerCase())) fail(`${p} must be a .jpg, .png or .webp photo.`) } if (opts['room-photo']) { if (!existsSync(opts['room-photo'])) fail(`Room photo not found: ${opts['room-photo']}`) if (!IMAGE.has(extname(opts['room-photo']).toLowerCase())) fail(`${opts['room-photo']} must be a .jpg, .png or .webp photo.`) } const caption = (opts.caption ?? '').trim() if (caption.length > 56) fail(`--caption is ${caption.length} characters. Keep it to 56 or fewer (two short lines).`) if (/\p{Extended_Pictographic}/u.test(caption)) fail('--caption cannot hold emoji: they do not render reliably. Use words, or add emoji in the app.') const { scenarios } = JSON.parse(readFileSync(join(root, 'assets', 'scenarios.json'), 'utf8')) const picked = opts.scenarios.split(',').map((s) => s.trim()).filter(Boolean) if (picked.length < 1 || picked.length > 3) fail(`--scenarios takes 1 to 3 scenarios, not ${picked.length}.`) for (const s of picked) if (!scenarios[s]) fail(`Unknown scenario "${s}". Use ${Object.keys(scenarios).join(', ')}.`) if (new Set(picked).size !== picked.length) fail('Each scenario can appear once per plan. Re-roll a clip instead of listing it twice.') const clips = picked.map((name, i) => { const s = scenarios[name] const pose = s.pose[opts.kind] ?? s.pose.other return { n: i + 1, id: `clip-${i + 1}-${name}`, scenario: name, label: s.label, person: s.person, music: s.music, scene: s.scene.replace('{{POSE}}', pose), action: s.action, sound: s.sound, hazards: s.hazards, caption, keyframe: '', draft: '', final: '', tested_scenario: s.tested, } }) const plan = { skill: 'pet-what-if-clip', brief: { aspect: '9:16', duration, final_model: final, final_resolution: '720p', audio: true }, pet: { kind: opts.kind, lock: (opts.pet ?? '').trim() || 'FILL: one line from the photos: 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.', photos: photos.map(relPath), }, references: { room: opts['room-photo'] ? relPath(opts['room-photo']) : '' }, clips, } writeFileSync(opts.out, `${JSON.stringify(plan, null, 2)}\n`) const fills = JSON.stringify(plan).match(/FILL:/g)?.length ?? 0 console.log(`Wrote ${opts.out}: ${clips.length} clip(s) (${picked.join(', ')}), ${opts.kind}, ${photos.length} photo(s), final on ${final}, ${duration} s.`) if (fills) console.log(`${fills} FILL: field(s) left. Write them (pet.lock first, from the photos) before build-requests.mjs.`) for (const c of clips) if (!c.tested_scenario) console.log(`note: "${c.scenario}" has not made a passing sample yet. Draft it before promising the look.`)