// `umtool fallback` (release 35 O1): stand-ins for the montage clips whose // windows the editor refused (lib/report/standIns.mjs) — the clip deck's // "Use stand-in" and "Restore" from a terminal. // // umtool fallback --dry-run [--json] which clips would switch, to what, and which cannot // umtool fallback [--clip …] [--json] switch them (every candidate, or the ones named) // umtool fallback --restore put one back as it was import { REPORTS_ROOT, resolveProject } from "../projects/core.mjs"; import { editorConfig } from "./fetchWindows.mjs"; import { applyStandIns, platformName, restoreStandIn, standInPlan } from "./standIns.mjs"; export const FALLBACK_USAGE = [ "usage: umtool fallback --dry-run [--json] the refused clips, the stand-in each would take", " umtool fallback [--clip …] [--json] switch them (all candidates, or the clips named)", " umtool fallback --restore put a switched clip back as it was", "", "A candidate: its window is not on disk, a fetch run (fetch-runs.json) says the editor refused it, and its", "phrase-scan instance has a public alternate (YouTube first, then Odysee / cornbreadman). The switch is recorded", "on the clip (`fallbackFrom`); its montage ruling and voice-match row move with it. Then: umtool fetch .", ].join("\n"); class CliError extends Error {} const altLine = (a) => `${a.slug}/${a.videoId} @${Number(a.start).toFixed(2)} (${platformName(a.platform)})`; /** * @param {string[]} args the words after `fallback` * @param {{ root?: string, out?: (s: string) => void, err?: (s: string) => void, cfg?: any, cacheDir?: string }} [opts] * @returns {Promise} */ export async function fallbackCommand(args, { root = REPORTS_ROOT, out = (s) => console.log(s), err = (s) => console.error(s), cfg = editorConfig(), cacheDir } = {}) { const json = args.includes("--json"); const words = []; const clips = []; let restore = null; for (let i = 0; i < args.length; i += 1) { if (args[i] === "--clip") clips.push(args[++i] ?? ""); else if (args[i] === "--restore") restore = args[++i] ?? ""; else if (!args[i].startsWith("--")) words.push(args[i]); } try { const [projectArg] = words; if (!projectArg || args.includes("--help")) { err(FALLBACK_USAGE); return 2; } const r = await resolveProject(projectArg, root); if (r.ambiguous) throw new CliError(`"${projectArg}" is the name of ${r.ambiguous.length} projects — pass its id`); if (!r.project) throw new CliError(`no project matches "${projectArg}"`); const project = r.project; const opts = { cfg, ...(cacheDir ? { cacheDir } : {}) }; if (restore !== null) { if (!restore) throw new CliError("--restore needs a clip id"); const mv = await restoreStandIn(project, restore); if (json) out(JSON.stringify({ project: project.id, restored: mv }, null, 2)); else out(`${project.id}: ${restore} restored (${mv.to})${mv.ruling ? ", its ruling moved back" : ""}${mv.voice ? ", its voice score moved back" : ""}`); return 0; } if (args.includes("--dry-run")) { const plan = await standInPlan(project, opts); if (json) out(JSON.stringify(plan, null, 2)); else { out(`${project.id}: ${plan.candidates.length} stand-in(s), ${plan.none.length} refused with none, ${plan.switched.length} already switched${plan.source === "rescan" ? " (alternates from a fresh scan: phrase-scan.json has none)" : ""}`); for (const c of plan.candidates) out(` ${c.clipId} ${c.channel}/${c.video} refused (${c.refusal.class}) -> ${altLine(c.alternate)}`); for (const n of plan.none) out(` ${n.clipId} refused (${n.refusal.class}) — ${n.why}`); for (const s of plan.switched) out(` ${s.clipId} switched from ${s.from.channel}/${s.from.video} (restore: umtool fallback ${project.id} --restore ${s.clipId})`); } return 0; } const res = await applyStandIns(project, { ...opts, clips: clips.length ? clips : null }); if (json) out(JSON.stringify({ project: project.id, switched: res.switched, none: res.plan.none }, null, 2)); else { if (!res.switched.length) out(`${project.id}: nothing to switch (${res.plan.none.length} refused with no stand-in)`); for (const s of res.switched) out(` ${s.clipId} -> ${altLine(s.alternate)}${s.ruling ? " · ruling moved" : ""}${s.voice ? " · voice score moved" : ""}`); if (res.switched.length) out(`then fetch them: umtool fetch ${project.id} --dry-run`); } return 0; } catch (e) { if (e instanceof CliError || e instanceof Error) { err(e.message); return 1; } throw e; } }