commit acbc3fe1aab51df2a58bc1668d1b4f7dedd0aa7c parent 034e5c0cfccfebe049b5330033230ac2fdc7295e Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st> Date: Thu, 5 Nov 2026 01:50:17 -0500 umtool: Add a clip as one flow -- find the moment (the words in the recordings the cut draws on, /api/report/find-moment; the archive's search; or a pasted link with a time), set its in and out on the moment's cues (click: start here, shift-click: end here, ±0.5 s), placed after a row (by date when the cut is in date order, else after the item it was opened from), added through the timeline's insert and its window fetched through the editor's paced fetch (POST /api/report/fetch, state inline, Retry); from the Cut tab (+ Add a clip, the head's ?add=1), from Play at the playhead's item (+ Add a clip here) and from a take (+ Add a clip to <take> only: takeEdit.mjs insertTakeEntry, the take timeline route's insert, `umtool timeline <p> --take <t> insert <spec> --after <id>`); the old spec form is "Add by spec". The Cut tab's one primary row (Walk, Play the cut, + Add a clip, Takes) with the rest folded into Options (clip editor, trailer, walk a take, fetch windows) and Advanced (voices, tight windows, bench prep): components/ui/disclosure.tsx, open state remembered per viewer; e2e/panels.ts openPanel for the specs that click a folded control (operator, 5 Nov: "adding new clips to a cut really sucks") Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Diffstat:
20 files changed, 920 insertions(+), 67 deletions(-)
diff --git a/umtool/app/api/report/find-moment/route.ts b/umtool/app/api/report/find-moment/route.ts @@ -0,0 +1,47 @@ +import { resolveReport } from "@/lib/report/serve.mjs"; +import { cuesForSource } from "@/lib/projects/report.mjs"; + +export const dynamic = "force-dynamic"; + +// ADD A CLIP's "find the moment" in the recordings the cut already draws on +// (lane/ui-simplify, 5 Nov): every word of `q` (any order, any case) in one +// cue of a recording a clip of the cut is on, read from the cue files the cut +// reads (cuesForSource, lib/projects/report.mjs), never the network. The +// archive-wide search is /api/research/search; a pasted link needs neither. +// +// GET ?project&q -> { recordings, hits: [{ channel, video, title, date, t, end, text }] } (at most 80) +export async function GET(request: Request) { + const url = new URL(request.url); + const r = await resolveReport(url.searchParams.get("project") ?? ""); + if ("error" in r) return Response.json({ error: r.error }, { status: r.status }); + const words = (url.searchParams.get("q") ?? "") + .toLowerCase() + .split(/\s+/) + .map((w) => w.replace(/[^\p{L}\p{N}'-]/gu, "")) + .filter((w) => w.length > 0); + if (!words.length) return Response.json({ error: "type a word or two to find" }, { status: 400 }); + type Rec = { channel: string | null; video: string; title: string | null; date: string | null }; + const recs = new Map<string, Rec>(); + for (const e of (r.manifest.timeline ?? []) as Record<string, unknown>[]) { + if (e?.type !== "clip" || typeof e.video !== "string") continue; + const channel = typeof e.channel === "string" && e.channel ? e.channel : null; + const key = `${channel ?? ""}/${e.video}`; + if (recs.has(key)) continue; + const onscreen = (e.onscreen ?? null) as { title?: unknown } | null; + const title = typeof e.streamTitle === "string" ? e.streamTitle : typeof onscreen?.title === "string" ? onscreen.title : typeof e.title === "string" ? e.title : null; + recs.set(key, { channel, video: e.video, title, date: typeof e.date === "string" ? e.date.slice(0, 10) : null }); + } + const hits: (Rec & { t: number; end: number; text: string })[] = []; + for (const rec of recs.values()) { + if (hits.length >= 80) break; + const got = await cuesForSource(r.project.dir, { video: rec.video, channel: rec.channel }, 0, Number.MAX_SAFE_INTEGER).catch(() => null); + for (const c of got?.cues ?? []) { + const text = String(c.text ?? "").toLowerCase(); + if (words.every((w) => text.includes(w))) { + hits.push({ ...rec, t: c.start, end: c.end, text: String(c.text ?? "").replace(/\s+/g, " ").trim() }); + if (hits.length >= 80) break; + } + } + } + return Response.json({ recordings: recs.size, hits }, { headers: { "cache-control": "no-store" } }); +} diff --git a/umtool/app/api/report/takes/timeline/route.ts b/umtool/app/api/report/takes/timeline/route.ts @@ -1,7 +1,8 @@ import { projectRef } from "@/lib/projects"; import { refuseCaller } from "@/lib/report/caller"; import { StaleToken, StructureRefused } from "@/lib/report/manifest.mjs"; -import { moveTakeEntry, removeTakeEntry, undoTakeEdit } from "@/lib/report/takeEdit.mjs"; +import { insertTakeEntry, moveTakeEntry, removeTakeEntry, takeToken, undoTakeEdit } from "@/lib/report/takeEdit.mjs"; +import { resolveTakeManifest } from "@/lib/report/takeManifest.mjs"; import { isTakeId } from "@/lib/report/takes.mjs"; export const dynamic = "force-dynamic"; @@ -15,8 +16,36 @@ export const dynamic = "force-dynamic"; // move { id, toIndex, at? } toIndex is the index AFTER the move // remove { id, at? } // undo {} the take's newest edit taken back +// insert { afterId: id | null, entry: "<channel>/<video>@<start>-<end>" | { type, … } } "add to this take only" +// +// GET ?project&take -> { token, timeline: [{ id, type, date, video, channel, words }] }: the take's resolved +// timeline, as the project's GET /api/report/timeline lists it (Add a clip's place picker, on a take). // // A stale token is a 409; a structure the build would refuse is a 400 with its sentences. +export async function GET(request: Request) { + const url = new URL(request.url); + const take = url.searchParams.get("take"); + if (!isTakeId(take)) return Response.json({ error: "take must be a take id" }, { status: 400 }); + const project = await projectRef(url.searchParams.get("project") ?? ""); + if (!project) return Response.json({ error: "no such project" }, { status: 404 }); + try { + const { manifest } = await resolveTakeManifest(project.dir, take); + const str = (v: unknown) => (typeof v === "string" && v ? v : null); + const timeline = ((manifest.timeline ?? []) as Record<string, unknown>[]).map((e) => ({ + id: String(e.id), + type: String(e.type ?? "entry"), + date: str(e.date)?.slice(0, 10) ?? null, + video: str(e.video), + channel: str(e.channel), + words: (str(e.quote) ?? str(e.text) ?? str(e.title) ?? "").replace(/\s+/g, " ").slice(0, 60), + })); + return Response.json({ take, token: await takeToken(project.dir, take), timeline }, { headers: { "cache-control": "no-store" } }); + } catch (e) { + const message = e instanceof Error ? e.message : String(e); + return Response.json({ error: message }, { status: /^no take /.test(message) ? 404 : 400 }); + } +} + export async function POST(request: Request) { const refused = refuseCaller(request, "/api/report/takes/timeline"); if (refused) return refused; @@ -39,8 +68,11 @@ export async function POST(request: Request) { r = await removeTakeEntry(project.dir, take, id, { token, at }); } else if (body.op === "undo") { r = await undoTakeEdit(project.dir, take, { token }); + } else if (body.op === "insert") { + if (!body.entry) return Response.json({ error: "insert needs an entry" }, { status: 400 }); + r = await insertTakeEntry(project.dir, take, typeof body.afterId === "string" && body.afterId ? body.afterId : null, body.entry, { token, at }); } else { - return Response.json({ error: "op must be move, remove or undo" }, { status: 400 }); + return Response.json({ error: "op must be move, remove, undo or insert" }, { status: 400 }); } return Response.json({ ok: true, op: body.op, take, ...r }, { headers: { "cache-control": "no-store" } }); } catch (e) { diff --git a/umtool/app/api/report/timeline/route.ts b/umtool/app/api/report/timeline/route.ts @@ -86,7 +86,16 @@ export async function GET(request: Request) { const r = await resolveReport(url.searchParams.get("project") ?? ""); if ("error" in r) return Response.json({ error: r.error }, { status: r.status }); const entries = (r.manifest.timeline ?? []) as Record<string, unknown>[]; - const timeline = entries.map((e) => ({ id: String(e.id), type: String(e.type ?? "entry") })); + // Each entry's day, recording and first words too: Add a clip's place picker (after <row>, the date order). + const str = (v: unknown) => (typeof v === "string" && v ? v : null); + const timeline = entries.map((e) => ({ + id: String(e.id), + type: String(e.type ?? "entry"), + date: str(e.date)?.slice(0, 10) ?? null, + video: str(e.video), + channel: str(e.channel), + words: (str(e.quote) ?? str(e.text) ?? str(e.title) ?? str(e.heading) ?? "").replace(/\s+/g, " ").slice(0, 60), + })); // What the structure editors edit: each teaser as written, the posts, and // the fact-check block with every default filled (the form's placeholders). const teasers = entries diff --git a/umtool/components/projects/AddClip.tsx b/umtool/components/projects/AddClip.tsx @@ -0,0 +1,542 @@ +"use client"; + +import { useRouter } from "next/navigation"; +import { useCallback, useEffect, useMemo, useRef, useState } from "react"; +import { buttonVariants } from "@/components/ui/button"; +import { newClipEntry, quoteFromCues } from "@/lib/report/clipEditorModel.mjs"; +import { cn } from "@/lib/utils"; +import { announceManifestChanged, refusalOf, timelineOp, type TimelineResult } from "./timelineApi"; + +// --------------------------------------------------------------------------- +// ADD A CLIP, AS ONE FLOW (lane/ui-simplify, 5 Nov; the operator: "adding new +// clips to a cut really sucks"). +// +// 1 Find the words, in the recordings the cut already draws on +// (/api/report/find-moment) or across the archive +// (/api/research/search); or paste a link with a time +// 2 In/out on the moment's cues: click a line to start there, shift-click +// to end there; nudge ±0.5 s; the quote is read from the cues +// 3 Place after <row> -- by default where the clip's date falls when the +// cut is in date order, else after the row it was opened from +// 4 Add the timeline's own insert (the project's, or with `take` the +// take's patch only: "add to this take only"), then the clip's +// window fetched through the editor's paced fetch +// (POST /api/report/fetch) -- never yt-dlp by hand +// +// Opened from the Cut tab, from Play at the playhead's item ("Add a clip +// here") and from a take. The old one-line spec form stays as the Cut +// tab's "Add by spec". +// --------------------------------------------------------------------------- + +type Entry = { id: string; type: string; date?: string | null; video?: string | null; channel?: string | null; words?: string }; +type Moment = { channel: string | null; video: string; title: string | null; date: string | null; t: number; text?: string }; +type Cue = { start: number; end: number; text: string; endsSentence?: boolean }; +type FetchState = { state: "idle" } | { state: "running"; msg: string } | { state: "done"; msg: string } | { state: "failed"; msg: string }; + +const r2 = (n: number) => Math.round(n * 100) / 100; +const clock = (s: number) => { + const h = Math.floor(s / 3600); + const m = Math.floor((s % 3600) / 60); + const sec = Math.floor(s % 60); + return h ? `${h}:${String(m).padStart(2, "0")}:${String(sec).padStart(2, "0")}` : `${m}:${String(sec).padStart(2, "0")}`; +}; + +/** `1:02:32`, `62m32s`, `3752`, `1h2m32s` → seconds; null when it is not a time. */ +export function parseTime(v: string | null | undefined): number | null { + const s = String(v ?? "").trim(); + if (!s) return null; + if (/^\d+(\.\d+)?s?$/.test(s)) return Number(s.replace(/s$/, "")); + const hms = /^(?:(\d+)h)?(?:(\d+)m)?(?:(\d+(?:\.\d+)?)s)?$/.exec(s); + if (hms && (hms[1] || hms[2] || hms[3])) return Number(hms[1] ?? 0) * 3600 + Number(hms[2] ?? 0) * 60 + Number(hms[3] ?? 0); + const parts = s.split(":").map(Number); + if (parts.length >= 2 && parts.length <= 3 && parts.every((n) => Number.isFinite(n))) return parts.reduce((a, n) => a * 60 + n, 0); + return null; +} + +/** A pasted link or a short form → `{ video, t, channel? }`: a YouTube link (`v=`, youtu.be, /live/, /shorts/) with t= or start=, `<channel>/<video>@<time>`, `<video>@<time>`. */ +export function parseMomentLink(raw: string): { video: string; t: number; channel: string | null } | null { + const s = raw.trim(); + const short = /^(?:([A-Za-z0-9][A-Za-z0-9._-]*)\/)?([A-Za-z0-9_-]{6,})@([0-9:hms.]+)$/.exec(s); + if (short) { + const t = parseTime(short[3]); + return t === null ? null : { channel: short[1] ?? null, video: short[2], t }; + } + let u: URL; + try { + u = new URL(/^https?:\/\//.test(s) ? s : `https://${s}`); + } catch { + return null; + } + let video: string | null = u.searchParams.get("v"); + if (!video && /youtu\.be$/.test(u.hostname)) video = u.pathname.slice(1).split("/")[0] || null; + if (!video) { + const m = /\/(?:live|shorts|embed|v)\/([A-Za-z0-9_-]{6,})/.exec(u.pathname); + video = m ? m[1] : null; + } + if (!video) return null; + const t = parseTime(u.searchParams.get("t") ?? u.searchParams.get("start") ?? (u.hash.match(/t=([0-9hms:.]+)/)?.[1] ?? "0")) ?? 0; + return { video, t, channel: null }; +} + +/** Where a clip of `date` goes in a cut in date order: after the last dated entry on or before it; null when the cut is not in date order. */ +export function dateOrderAfter(entries: Entry[], date: string | null): string | null | undefined { + if (!date) return undefined; + const dated = entries.filter((e) => e.date); + if (dated.length < 2) return undefined; + for (let i = 1; i < dated.length; i++) if (String(dated[i].date) < String(dated[i - 1].date)) return undefined; + let after: string | null = null; + for (const e of entries) if (e.date && String(e.date) <= date) after = e.id; + return after; +} + +export default function AddClip({ + project, + take = null, + after: afterProp = null, + onClose, + onAdded, + className, +}: { + project: string; + /** "Add to this take only": the take's patch, never the project's manifest. */ + take?: string | null; + /** The row it was opened from (Play's playhead item): the default place when the cut is not in date order. */ + after?: string | null; + onClose?: () => void; + onAdded?: (id: string) => void; + className?: string; +}) { + const router = useRouter(); + const [entries, setEntries] = useState<Entry[]>([]); + const [token, setToken] = useState<string | null>(null); + const [mode, setMode] = useState<"cut" | "archive" | "link">("cut"); + const [q, setQ] = useState(""); + const [busy, setBusy] = useState(false); + const [error, setError] = useState<string | null>(null); + const [hits, setHits] = useState<Moment[] | null>(null); + const [link, setLink] = useState(""); + const [moment, setMoment] = useState<Moment | null>(null); + const [cues, setCues] = useState<Cue[] | null>(null); + const [cueNote, setCueNote] = useState<string | null>(null); + const [start, setStart] = useState<number | null>(null); + const [end, setEnd] = useState<number | null>(null); + const [quote, setQuote] = useState(""); + const [quoteTyped, setQuoteTyped] = useState(false); + const [after, setAfter] = useState<string>(""); + const [placeWhy, setPlaceWhy] = useState<string>(""); + const [added, setAdded] = useState<string | null>(null); + const [fetchState, setFetchState] = useState<FetchState>({ state: "idle" }); + const cueList = useRef<HTMLOListElement | null>(null); + // The moment's line in view when its cues arrive (the list opens 40 s before it). + useEffect(() => { + const box = cueList.current; + const first = box?.querySelector("[data-inside]") as HTMLElement | null; + if (box && first) box.scrollTop = Math.max(0, first.offsetTop - box.offsetTop - 24); + }, [cues]); + + const loadEntries = useCallback(async () => { + const url = take + ? `/api/report/takes/timeline?project=${encodeURIComponent(project)}&take=${encodeURIComponent(take)}` + : `/api/report/timeline?project=${encodeURIComponent(project)}`; + const r = await fetch(url, { cache: "no-store" }); + const j = await r.json().catch(() => ({})); + if (!r.ok) { + setError(String(j.error ?? `HTTP ${r.status}`)); + return null; + } + setEntries(Array.isArray(j.timeline) ? j.timeline : []); + setToken(typeof j.token === "string" ? j.token : null); + return j as { token?: string }; + }, [project, take]); + useEffect(() => { + void loadEntries(); + }, [loadEntries]); + + const channels = useMemo(() => [...new Set(entries.map((e) => e.channel).filter((c): c is string => !!c))], [entries]); + + // ---- 1 find ------------------------------------------------------------- + const find = async () => { + if (!q.trim()) return; + setBusy(true); + setError(null); + setHits(null); + try { + if (mode === "cut") { + const r = await fetch(`/api/report/find-moment?project=${encodeURIComponent(project)}&q=${encodeURIComponent(q)}`, { cache: "no-store" }); + const j = await r.json().catch(() => ({})); + if (!r.ok) throw new Error(String(j.error ?? `HTTP ${r.status}`)); + setHits(j.hits ?? []); + } else { + const sr = await fetch("/api/research/sources", { cache: "no-store" }); + const sj = await sr.json().catch(() => ({})); + const source = (sj.sources ?? [])[0]?.handle; + if (!source) throw new Error("no archive to search: set up a source on Research"); + const r = await fetch("/api/research/search", { + method: "POST", + headers: { "content-type": "application/json" }, + body: JSON.stringify({ q, source, ...(channels.length ? { channels } : {}) }), + }); + const j = await r.json().catch(() => ({})); + if (!r.ok) throw new Error(String(j.error ?? `HTTP ${r.status}`)); + const out: Moment[] = []; + for (const h of (j.hits ?? []) as { kind: string; videoId: string; channelSlug: string; title: string; uploadDate: string; snippets: { t: number; text: string }[] }[]) { + if (h.kind !== "video") continue; + for (const s of h.snippets ?? []) if (Number.isFinite(s.t)) out.push({ channel: h.channelSlug, video: h.videoId, title: h.title, date: h.uploadDate?.slice(0, 10) ?? null, t: s.t, text: s.text }); + if (out.length > 80) break; + } + setHits(out); + } + } catch (e) { + setError(e instanceof Error ? e.message : String(e)); + } finally { + setBusy(false); + } + }; + + const fromLink = () => { + const p = parseMomentLink(link); + if (!p) { + setError("not a link with a video and a time (a YouTube link with t=, or <channel>/<video>@1:02:32)"); + return; + } + const known = entries.find((e) => e.video === p.video); + setError(null); + pick({ channel: p.channel ?? known?.channel ?? channels[0] ?? null, video: p.video, title: null, date: known?.date ?? null, t: p.t }); + }; + + // ---- 2 in/out ----------------------------------------------------------- + const pick = (m: Moment) => { + setMoment(m); + setAdded(null); + setFetchState({ state: "idle" }); + setQuoteTyped(false); + setCues(null); + setCueNote(null); + const from = Math.max(0, m.t - 40); + const to = m.t + 50; + const qs = new URLSearchParams({ project, video: m.video, from: String(from), to: String(to) }); + if (m.channel) qs.set("channel", m.channel); + void fetch(`/api/report/cues?${qs}`, { cache: "no-store" }) + .then(async (r) => { + if (!r.ok) { + setCueNote("no transcript for this recording here: set the in and out by number, and type the quote"); + setStart(r2(m.t)); + setEnd(r2(m.t + 8)); + return; + } + const j = (await r.json()) as { cues?: Cue[] }; + const list = j.cues ?? []; + setCues(list); + const at = list.find((c) => c.end > m.t) ?? list[0]; + setStart(r2(at ? at.start : m.t)); + // To the end of the sentence the moment is in (the first cue that closes one), at most ~20 s on. + const i = at ? list.indexOf(at) : -1; + const close = i >= 0 ? list.slice(i).find((c, k) => c.endsSentence || k >= 4) : null; + setEnd(r2(close ? close.end : m.t + 8)); + }) + .catch(() => setCueNote("the cues could not be read")); + // 3 place: by date when the cut is in date order, else after the row it was opened from, else the end. + const byDate = dateOrderAfter(entries, m.date); + if (byDate !== undefined) { + setAfter(byDate ?? ""); + setPlaceWhy(`by date (${m.date}): the cut is in date order`); + } else { + setAfter(afterProp ?? entries[entries.length - 1]?.id ?? ""); + setPlaceWhy(afterProp ? "after the item playing" : "at the end"); + } + }; + useEffect(() => { + if (quoteTyped || !cues || start === null || end === null) return; + setQuote(quoteFromCues(cues, start, end)); + }, [cues, start, end, quoteTyped]); + + // Click: start on this line. Shift-click: end on it (or, above the start, start there and keep the end). + const onCue = (c: Cue, e: React.MouseEvent) => { + if (e.shiftKey && start !== null) { + if (c.end > start + 0.05) setEnd(r2(c.end)); + else setStart(r2(c.start)); + return; + } + setStart(r2(c.start)); + if (end === null || end <= c.start + 0.05) setEnd(r2(c.end)); + }; + + // ---- 4 add, then fetch -------------------------------------------------- + const valid = moment && start !== null && end !== null && end - start >= 0.5; + const add = async () => { + if (!moment || !valid || start === null || end === null) return; + setBusy(true); + setError(null); + const entry: Record<string, unknown> = newClipEntry({ video: moment.video, ownChannel: moment.channel }, { start, end, quote }); + if (moment.date) entry.date = moment.date; + let res: TimelineResult; + if (take) { + const r = await fetch("/api/report/takes/timeline", { + method: "POST", + headers: { "content-type": "application/json" }, + body: JSON.stringify({ project, take, token, op: "insert", afterId: after || null, entry }), + }); + res = { ok: r.ok, status: r.status, json: await r.json().catch(() => ({ error: `HTTP ${r.status}` })) }; + } else { + res = await timelineOp(project, token ?? ((await loadEntries())?.token ?? null), "insert", { afterId: after || null, entry }); + } + setBusy(false); + if (!res.ok) { + setError(refusalOf(res)); + if (res.json.stale) await loadEntries(); + return; + } + const id = typeof res.json.id === "string" ? res.json.id : null; + setAdded(id); + if (!take) announceManifestChanged(project); + await loadEntries(); + router.refresh(); + if (id) { + onAdded?.(id); + void fetchWindow(id); + } + }; + const fetchWindow = async (id: string) => { + setFetchState({ state: "running", msg: `fetching ${id}'s window through the editor…` }); + try { + const r = await fetch("/api/report/fetch", { + method: "POST", + headers: { "content-type": "application/json" }, + body: JSON.stringify({ project, clip: id, padBefore: 20, padAfter: 20, ...(take ? { take } : {}) }), + }); + const j = (await r.json().catch(() => ({}))) as { error?: string; job?: { id: string }; cachedBefore?: number; cachedPad?: number }; + if (r.status === 409 && (j.cachedBefore !== undefined || j.cachedPad !== undefined)) return setFetchState({ state: "done", msg: "already fetched" }); + if (!r.ok || !j.job?.id) throw new Error(j.error ?? `HTTP ${r.status}`); + for (;;) { + await new Promise((ok) => setTimeout(ok, 1000)); + const pr = await fetch(`/api/report/fetch?job=${encodeURIComponent(j.job.id)}`, { cache: "no-store" }); + const pj = (await pr.json().catch(() => ({}))) as { job: { state: string; error?: string | null; progress?: string | null } | null }; + if (!pj.job) throw new Error("the fetch job was forgotten"); + if (pj.job.state === "running") { + setFetchState({ state: "running", msg: `fetching ${id}… ${pj.job.progress ?? ""}` }); + continue; + } + if (pj.job.state === "done") { + setFetchState({ state: "done", msg: `${id} fetched` }); + router.refresh(); + return; + } + throw new Error(pj.job.error ?? `the fetch ${pj.job.state}`); + } + } catch (e) { + setFetchState({ state: "failed", msg: e instanceof Error ? e.message : String(e) }); + } + }; + + const input = "rounded-[3px] border border-seam-2 bg-ground px-1.5 py-[3px] text-[12px] text-text outline-none focus:border-signal"; + const tab = (m: typeof mode, label: string) => ( + <button type="button" data-add-clip-mode={m} aria-pressed={mode === m} onClick={() => (setMode(m), setHits(null), setError(null))} className={buttonVariants({ variant: mode === m ? "pressed" : "quiet", size: "sm" })}> + {label} + </button> + ); + const nudge = (which: "in" | "out", d: number) => (which === "in" ? setStart((s) => (s === null ? s : r2(Math.max(0, s + d)))) : setEnd((s) => (s === null ? s : r2(s + d)))); + + return ( + <section data-add-clip={take ?? "cut"} className={cn("space-y-2 rounded border border-seam bg-panel p-3 text-[12px]", className)}> + <div className="flex flex-wrap items-center gap-2"> + <h2 className="micro m-0">{take ? `Add a clip to take ${take} only` : "Add a clip"}</h2> + <span className="text-muted">1 find · 2 in/out · 3 place · 4 add</span> + {onClose && ( + <button type="button" data-add-clip-close="" onClick={onClose} className={cn(buttonVariants({ variant: "quiet", size: "sm" }), "ml-auto")}> + Close + </button> + )} + </div> + + {/* 1 FIND */} + <div className="flex flex-wrap items-center gap-1.5"> + {tab("cut", "In this cut's recordings")} + {tab("archive", "The archive")} + {tab("link", "Paste a link")} + </div> + {mode === "link" ? ( + <div className="flex flex-wrap items-center gap-2"> + <input data-add-clip-link="" value={link} onChange={(e) => setLink(e.target.value)} onKeyDown={(e) => e.key === "Enter" && fromLink()} placeholder="https://youtu.be/<id>?t=3752 · <channel>/<video>@1:02:32" className={cn(input, "w-[28rem] max-w-full font-mono")} /> + <button type="button" data-add-clip-open-link="" onClick={fromLink} className={buttonVariants({ variant: "outline", size: "sm" })}> + Open the moment + </button> + </div> + ) : ( + <div className="flex flex-wrap items-center gap-2"> + <input data-add-clip-q="" value={q} onChange={(e) => setQ(e.target.value)} onKeyDown={(e) => e.key === "Enter" && void find()} placeholder={mode === "cut" ? "words said in a recording this cut uses" : "words, across the archive (this cut's channels)"} className={cn(input, "w-[24rem] max-w-full")} /> + <button type="button" data-add-clip-find="" disabled={busy || !q.trim()} onClick={() => void find()} className={buttonVariants({ variant: "outline", size: "sm" })}> + Find + </button> + {hits && <span className="text-muted" data-add-clip-hits={hits.length}>{hits.length ? `${hits.length} moment${hits.length === 1 ? "" : "s"}` : "nothing found"}</span>} + </div> + )} + {hits && hits.length > 0 && !moment && ( + <ol className="m-0 max-h-56 list-none space-y-0.5 overflow-auto p-0" data-add-clip-results=""> + {hits.map((h, i) => ( + <li key={`${h.video}@${h.t}:${i}`}> + <button type="button" data-add-clip-hit={`${h.video}@${h.t}`} onClick={() => pick(h)} className="flex w-full items-baseline gap-2 rounded-[2px] px-1.5 py-0.5 text-left hover:bg-panel-2"> + <span className="shrink-0 font-mono text-[11px] text-signal-text">{clock(h.t)}</span> + <span className="shrink-0 font-mono text-[11px] text-muted">{h.date ?? ""} {h.video}</span> + <span className="min-w-0 truncate text-text-2">{h.text}</span> + </button> + </li> + ))} + </ol> + )} + + {/* 2 IN / OUT */} + {moment && ( + <div className="space-y-1.5" data-add-clip-moment={`${moment.channel ?? ""}/${moment.video}@${moment.t}`}> + <div className="flex flex-wrap items-center gap-2"> + <span className="font-mono text-[11.5px] text-text"> + {moment.channel ? `${moment.channel}/` : ""} + {moment.video} + </span> + {moment.title && <span className="text-text-2">{moment.title}</span>} + {moment.date && <span className="font-mono text-[11px] text-muted">{moment.date}</span>} + {!moment.channel && ( + <label className="inline-flex items-center gap-1"> + channel + <input data-add-clip-channel="" value={moment.channel ?? ""} onChange={(e) => setMoment({ ...moment, channel: e.target.value || null })} className={cn(input, "w-36 font-mono")} /> + </label> + )} + <button type="button" onClick={() => (setMoment(null), setCues(null))} className={buttonVariants({ variant: "quiet", size: "sm" })}> + another moment + </button> + </div> + {cues && cues.length > 0 && ( + <ol ref={cueList} className="m-0 max-h-52 list-none overflow-auto rounded-[2px] border border-seam bg-ground p-1 font-serif text-[13px] leading-snug" data-add-clip-cues={cues.length}> + {cues.map((c) => { + const inside = start !== null && end !== null && c.end > start + 0.05 && c.start < end - 0.05; + return ( + <li key={c.start}> + <button + type="button" + data-add-clip-cue={c.start} + data-inside={inside ? "" : undefined} + onClick={(e) => onCue(c, e)} + title="click: start here · shift-click: end here" + className={cn("flex w-full gap-2 rounded-[2px] px-1 text-left", inside ? "bg-panel-2 text-text" : "text-muted hover:text-text")} + > + <span className="shrink-0 font-mono text-[10.5px] leading-[20px] text-muted">{clock(c.start)}</span> + <span>{c.text}</span> + </button> + </li> + ); + })} + </ol> + )} + {cueNote && <p className="m-0 text-muted">{cueNote}</p>} + <div className="flex flex-wrap items-center gap-2"> + {(["in", "out"] as const).map((w) => ( + <span key={w} className="inline-flex items-center gap-1"> + <span className="micro">{w}</span> + <button type="button" onClick={() => nudge(w, -0.5)} className={buttonVariants({ variant: "quiet", size: "sm" })} aria-label={`${w} 0.5 s earlier`}> + − + </button> + <input + data-add-clip-edge={w} + value={w === "in" ? (start ?? "") : (end ?? "")} + onChange={(e) => { + const v = parseTime(e.target.value); + if (v !== null) (w === "in" ? setStart : setEnd)(r2(v)); + }} + className={cn(input, "w-20 font-mono")} + /> + <button type="button" onClick={() => nudge(w, 0.5)} className={buttonVariants({ variant: "quiet", size: "sm" })} aria-label={`${w} 0.5 s later`}> + + + </button> + </span> + ))} + {start !== null && end !== null && ( + <span className="font-mono text-[11px] text-muted" data-add-clip-span=""> + {clock(start)}–{clock(end)} · {(end - start).toFixed(1)} s + </span> + )} + </div> + <textarea + data-add-clip-quote="" + value={quote} + rows={2} + placeholder="the quote (read from the cues)" + onChange={(e) => (setQuoteTyped(true), setQuote(e.target.value))} + className={cn(input, "w-full")} + /> + + {/* 3 PLACE + 4 ADD */} + <div className="flex flex-wrap items-center gap-2"> + <label className="inline-flex items-center gap-1"> + after + <select data-add-clip-after="" value={after} onChange={(e) => (setAfter(e.target.value), setPlaceWhy("picked"))} className={cn(input, "max-w-[26rem]")}> + <option value="">(the start)</option> + {entries.map((e, i) => ( + <option key={`${e.id}:${i}`} value={e.id}> + {i + 1}. {e.id} + {e.date ? ` · ${e.date}` : ""} + {e.words ? ` · ${e.words.slice(0, 40)}` : ""} + </option> + ))} + </select> + </label> + {placeWhy && <span className="text-muted" data-add-clip-place-why="">{placeWhy}</span>} + <button type="button" data-add-clip-submit="" disabled={busy || !valid} onClick={() => void add()} className={buttonVariants({ variant: "go", size: "sm" })}> + {take ? `Add to ${take} only` : "Add to the cut"} + </button> + </div> + </div> + )} + + {error && ( + <p role="alert" className="m-0 text-reject-text" data-add-clip-error=""> + {error} + </p> + )} + {added && ( + <p className="m-0 flex flex-wrap items-center gap-2 text-text-2" data-add-clip-added={added} data-add-clip-fetch={fetchState.state}> + <span> + Added <b className="font-mono">{added}</b> + {take ? ` to take ${take}` : ""}. + </span> + {fetchState.state !== "idle" && <span className={fetchState.state === "failed" ? "text-reject-text" : "text-muted"}>{fetchState.msg}</span>} + {fetchState.state === "failed" && ( + <button type="button" data-add-clip-refetch="" onClick={() => void fetchWindow(added)} className={buttonVariants({ variant: "outline", size: "sm" })}> + Retry the fetch + </button> + )} + </p> + )} + </section> + ); +} + +/** "+ Add a clip": the button and, pressed, the panel (open from the start with `open`, e.g. the head's `?add=1`). */ +export function AddClipToggle({ + project, + take = null, + after = null, + open: initiallyOpen = false, + label, + where, + onAdded, + className, +}: { + project: string; + take?: string | null; + after?: string | null; + onAdded?: (id: string) => void; + open?: boolean; + label?: string; + /** The surface: `data-add-clip-open="<where>"`. */ + where: string; + className?: string; +}) { + const [open, setOpen] = useState(initiallyOpen); + return ( + <> + <button type="button" data-add-clip-open={where} aria-expanded={open} onClick={() => setOpen((o) => !o)} className={cn(buttonVariants({ variant: open ? "pressed" : "outline", size: "sm" }), className)}> + {label ?? (take ? `+ Add a clip to ${take} only` : "+ Add a clip")} + </button> + {open && <AddClip project={project} take={take} after={after} onAdded={onAdded} onClose={() => setOpen(false)} className="basis-full" />} + </> + ); +} diff --git a/umtool/components/projects/TakeWalkPage.tsx b/umtool/components/projects/TakeWalkPage.tsx @@ -9,6 +9,7 @@ import { walkOf } from "@/lib/report/walkData.mjs"; import type { ProjectRef } from "@/lib/project-types"; import { BenchBody, BenchFrame, BenchTop } from "./bench/BenchShell"; import PlayLink from "./PlayLink"; +import { AddClipToggle } from "./AddClip"; import TakeActions from "./TakeActions"; import BenchPrepPanel from "./report/BenchPrepPanel"; @@ -82,6 +83,11 @@ export default async function TakeWalkPage({ {all ? "walk only the clips needing a verdict" : "walk every clip (judged ones too)"} </Link> </div> + {w.take?.editable && ( + <div className="flex flex-wrap items-start gap-2"> + <AddClipToggle project={project.id} take={take} where="take" /> + </div> + )} {/* The take's own prep: its clips' excerpts and waveforms made before the walk opens them. */} <BenchPrepPanel project={project.id} take={take} /> {w.take?.editable && ( diff --git a/umtool/components/projects/TimelineEditor.tsx b/umtool/components/projects/TimelineEditor.tsx @@ -141,8 +141,8 @@ export function TimelineList({ project, count, groupCount = 0, children }: { pro <button type="button" data-testid="timeline-undo" disabled={busy} onClick={() => void run("undo", {})} className={buttonVariants({ size: "sm" })}> Undo last edit </button> - <button type="button" data-testid="timeline-add-clip" aria-expanded={adding} disabled={busy} onClick={() => setAdding((a) => !a)} className={buttonVariants({ size: "sm" })}> - Add clip + <button type="button" data-testid="timeline-add-clip" aria-expanded={adding} disabled={busy} onClick={() => setAdding((a) => !a)} className={buttonVariants({ variant: "quiet", size: "sm" })} title="type a clip as <channel>/<video>@<start>-<end> (+ Add a clip above finds the moment for you)"> + Add by spec </button> <span className="text-[var(--color-dim)]"> drag ⠿ or <kbd>alt</kbd>+<kbd>↑</kbd>/<kbd>↓</kbd> to move{sections.length > 1 ? "; drag a section bar onto a clip to move its boundary, a clip onto a bar to move it into that section" : ""} diff --git a/umtool/components/projects/report/CutTab.tsx b/umtool/components/projects/report/CutTab.tsx @@ -13,6 +13,8 @@ import { readTrailerBeats } from "@/lib/report/trailerBeats.mjs"; import { montageClipsOf, momentKeysOf, readRulingsState } from "@/lib/report/montageRulings.mjs"; import FetchUnfetchedButton from "../FetchUnfetchedButton"; import PlayLink from "../PlayLink"; +import { AddClipToggle } from "../AddClip"; +import { Advanced, Options } from "@/components/ui/disclosure"; import TightWindowsPanel from "./TightWindowsPanel"; import { clipRecord, storedUrlOf } from "@/lib/clips/stored"; import { Fragment } from "react"; @@ -402,9 +404,6 @@ export default async function CutTab({ project, detail, search, tabHref }: Repor ready {readiness.ready} of {readiness.needing} needing judgement </span> </span> - {/* The bench's first-open work (a long recording's excerpt, the - waveform), made ahead in the background (lib/report/benchPrep.mjs). */} - <BenchPrepPanel project={project.id} /> </div> )} {/* The whole cut played in the browser in its final look, no render (the Play view). */} @@ -413,27 +412,8 @@ export default async function CutTab({ project, detail, search, tabHref }: Repor Play the cut </Link> )} - {/* A montage's instances, ruled by ear before a render (release 34). */} - {montage.length > 0 && ( - <Link - href={clipDeckHref(project.id)} - data-clip-deck-link={unruled} - className={buttonVariants({ size: "lg" })} - > - Clips — {unruled ? `${unruled} of ${montage.length} to rule` : `${montage.length} ruled`} - </Link> - )} - {/* Any other cut's clips -- an assistant's above all -- adjusted by a person (release 35 C2). */} - {montage.length === 0 && clips.length > 0 && ( - <Link - href={clipEditorHref(project.id)} - data-clip-editor-link={assisted.length} - className={buttonVariants({ size: "lg" })} - > - Clip editor — {clips.length} clip{clips.length === 1 ? "" : "s"} - {assisted.length ? ` · ${assisted.length} by the assistant${assistedByYou ? `, ${assistedByYou} edited by you` : ""}` : ""} - </Link> - )} + {/* Add a clip, as one flow (lane/ui-simplify): find, in/out on the cues, place, add, fetched. */} + <AddClipToggle project={project.id} where="cut" open={search.add === "1"} className="self-center" /> {/* Alternative renders of part of the cut, judged on their own page -- where the first one is made, too (release 33's take maker). */} {takes.exists ? ( @@ -449,40 +429,75 @@ export default async function CutTab({ project, detail, search, tabHref }: Repor Make takes </Link> )} - {/* The trailer's beats: the running length against the platform's limit (UI notes item 11). */} - {clips.length > 0 && ( - <Link href={trailerHref(project.id)} data-trailer-link={trailerBeats ?? ""} className={buttonVariants({ variant: trailerBeats ? "outline" : "quiet", size: trailerBeats ? "lg" : "sm" })}> - {trailerBeats ? `Trailer — ${trailerBeats} beat${trailerBeats === 1 ? "" : "s"}` : trailerBeats === null ? "Trailer (beats file unreadable)" : "Trailer beats"} - </Link> - )} - {/* Walk a take: the drafts first -- a draft exists to be walked before it is rendered. */} - {takes.takes.some((t: { draft?: boolean; baseHash?: string | null }) => t.draft || t.baseHash) && ( - <span data-walk-takes="" className="flex flex-wrap items-center gap-1.5 text-[11.5px]"> - <span className="micro">walk a take</span> - {[...takes.takes] - .filter((t: { draft?: boolean; baseHash?: string | null }) => t.draft || t.baseHash) - .sort((a: { draft?: boolean }, b: { draft?: boolean }) => Number(!!b.draft) - Number(!!a.draft)) - .slice(0, 6) - .map((t: { id: string; label: string; draft?: boolean }) => ( - <span key={t.id} className="inline-flex items-center"> - <Link href={takeWalkHref(project.id, t.id)} data-walk-take={t.id} className="ink-link" title={t.label}> - {t.id} - {t.draft ? " (draft)" : ""} - </Link> - <PlayLink project={project.id} take={t.id} where="walk-chip" variant="icon" /> - </span> - ))} - </span> - )} - {clips.length > 0 && ( - <VoiceMatchPanel - project={project.id} - summary={voiceMatchSummary(voices)} - /> - )} - {fetchBody && <FetchWindowsPanel project={project.id} items={fetchBody.items} skipped={fetchBody.skipped} lastRun={fetchBody.lastRun} />} - {/* Tight windows: each clip to its sentence, for review (UI notes item 4) -- a button until pressed. */} - {clips.length > 0 && <TightWindowsPanel project={project.id} />} + </div> + {/* Everything else, folded (lane/ui-simplify): Options the common, Advanced the rare; open state remembered per viewer. */} + <div className="flex flex-wrap items-start gap-x-4 gap-y-1.5" data-cut-panels=""> + <Options id="cut" hint="clip editor · trailer · walk a take · fetch"> + {/* A montage's instances, ruled by ear before a render (release 34). */} + {montage.length > 0 && ( + <Link + href={clipDeckHref(project.id)} + data-clip-deck-link={unruled} + className={buttonVariants({ size: "lg" })} + > + Clips — {unruled ? `${unruled} of ${montage.length} to rule` : `${montage.length} ruled`} + </Link> + )} + {/* Any other cut's clips -- an assistant's above all -- adjusted by a person (release 35 C2). */} + {montage.length === 0 && clips.length > 0 && ( + <Link + href={clipEditorHref(project.id)} + data-clip-editor-link={assisted.length} + className={buttonVariants({ size: "lg" })} + > + Clip editor — {clips.length} clip{clips.length === 1 ? "" : "s"} + {assisted.length ? ` · ${assisted.length} by the assistant${assistedByYou ? `, ${assistedByYou} edited by you` : ""}` : ""} + </Link> + )} + {/* The trailer's beats: the running length against the platform's limit (UI notes item 11). */} + {clips.length > 0 && ( + <Link href={trailerHref(project.id)} data-trailer-link={trailerBeats ?? ""} className={buttonVariants({ variant: trailerBeats ? "outline" : "quiet", size: trailerBeats ? "lg" : "sm" })}> + {trailerBeats ? `Trailer — ${trailerBeats} beat${trailerBeats === 1 ? "" : "s"}` : trailerBeats === null ? "Trailer (beats file unreadable)" : "Trailer beats"} + </Link> + )} + {/* Walk a take: the drafts first -- a draft exists to be walked before it is rendered. */} + {takes.takes.some((t: { draft?: boolean; baseHash?: string | null }) => t.draft || t.baseHash) && ( + <span data-walk-takes="" className="flex flex-wrap items-center gap-1.5 text-[11.5px]"> + <span className="micro">walk a take</span> + {[...takes.takes] + .filter((t: { draft?: boolean; baseHash?: string | null }) => t.draft || t.baseHash) + .sort((a: { draft?: boolean }, b: { draft?: boolean }) => Number(!!b.draft) - Number(!!a.draft)) + .slice(0, 6) + .map((t: { id: string; label: string; draft?: boolean }) => ( + <span key={t.id} className="inline-flex items-center"> + <Link href={takeWalkHref(project.id, t.id)} data-walk-take={t.id} className="ink-link" title={t.label}> + {t.id} + {t.draft ? " (draft)" : ""} + </Link> + <PlayLink project={project.id} take={t.id} where="walk-chip" variant="icon" /> + </span> + ))} + </span> + )} + {fetchBody && <FetchWindowsPanel project={project.id} items={fetchBody.items} skipped={fetchBody.skipped} lastRun={fetchBody.lastRun} />} + </Options> + <Advanced id="cut" hint="voices · tight windows · bench prep"> + {clips.length > 0 && ( + <VoiceMatchPanel + project={project.id} + summary={voiceMatchSummary(voices)} + /> + )} + {/* Tight windows: each clip to its sentence, for review (UI notes item 4) -- a button until pressed. */} + {clips.length > 0 && <TightWindowsPanel project={project.id} />} + {clips.length > 0 && ( + <div className="basis-full"> + {/* The bench's first-open work (a long recording's excerpt, the + waveform), made ahead in the background (lib/report/benchPrep.mjs). */} + <BenchPrepPanel project={project.id} /> + </div> + )} + </Advanced> </div> {/* --- the timeline --------------------------------------------- */} diff --git a/umtool/components/projects/review/PlayCut.tsx b/umtool/components/projects/review/PlayCut.tsx @@ -28,6 +28,7 @@ import WhatPlays, { type WorkingCut } from "./WhatPlays"; import { useCutApp } from "../cutApp/CutApp"; import { ClipExportButtons, ClipExportStatus, useClipExport } from "../ClipExport"; import AddPost from "./AddPost"; +import { AddClipToggle } from "../AddClip"; import PostItemPlayer, { postItemAssets, type PostPlan } from "./PostItemPlayer"; import ComboBadge, { type ComboInfo } from "./ComboBadge"; @@ -1290,6 +1291,21 @@ export default function PlayCut({ }} /> )} + {/* Add a clip here (lane/ui-simplify): find a moment, in/out on its cues, placed after the item on screen; the + cut's, or this take's only when the take keeps its own timeline. */} + <div className="flex flex-wrap items-center gap-1.5 text-[12px]" data-play-add-clip=""> + <AddClipToggle + project={project} + take={editable ? null : take} + after={item?.id ?? null} + where="play" + label={editable ? "+ Add a clip here" : `+ Add a clip here (${take} only)`} + onAdded={() => { + setPlaying(false); + void reloadView(); + }} + /> + </div> {/* Reject ▾ (x): the clip on screen out of the cut for a reason, on record, with an undo (the project's cut: not on a take). */} {editable && ( <RejectClip diff --git a/umtool/components/ui/disclosure.tsx b/umtool/components/ui/disclosure.tsx @@ -0,0 +1,104 @@ +"use client"; + +import { useEffect, useState } from "react"; +import { cn } from "@/lib/utils"; + +// --------------------------------------------------------------------------- +// OPTIONS / ADVANCED (lane/ui-simplify, 5 Nov; the operator: "focus on the +// happy path and have options/advanced panels for everything else, keeping all +// current features exposed"). +// +// A page shows ONE primary row for the happy path's next step; everything else +// sits in an Options disclosure (common, secondary) or an Advanced one (rare, +// expert). One shell for every page, so they look and behave the same: +// +// <Options id="cut">…</Options> <Advanced id="cut">…</Advanced> +// +// A `<details>`: what is inside stays in the page (a link keeps its address, a +// spec finds it by its data-*), only folded. Whether it is open is remembered +// per viewer and per panel (`umtool.panel.<id>.<kind>` in localStorage, +// wrapped: a private window just starts folded). e2e opens one through +// e2e/panels.ts openPanel(page, kind, id). +// --------------------------------------------------------------------------- + +export type PanelKind = "options" | "advanced"; + +const keyOf = (id: string, kind: PanelKind) => `umtool.panel.${id}.${kind}`; + +export function Disclosure({ + kind, + id, + label, + hint, + defaultOpen = false, + className, + bodyClassName, + children, +}: { + kind: PanelKind; + /** The page or panel this belongs to (`cut`, `take-card`, `play`): the remembered state's key. */ + id: string; + label?: React.ReactNode; + /** A few words after the label, folded or not (what is inside: "voices · fetch · tighten"). */ + hint?: React.ReactNode; + defaultOpen?: boolean; + className?: string; + bodyClassName?: string; + children: React.ReactNode; +}) { + const [open, setOpen] = useState(defaultOpen); + useEffect(() => { + try { + const v = window.localStorage.getItem(keyOf(id, kind)); + if (v === "1" || v === "0") setOpen(v === "1"); + } catch { + // storage refused: folded as the page drew it + } + }, [id, kind]); + return ( + <details + open={open} + data-panel-disclosure={kind} + data-panel-id={id} + onToggle={(e) => { + const now = (e.currentTarget as HTMLDetailsElement).open; + setOpen(now); + try { + window.localStorage.setItem(keyOf(id, kind), now ? "1" : "0"); + } catch { + // not remembered; still toggles + } + }} + className={cn("group/disclosure min-w-0", className)} + > + <summary + data-panel-summary={kind} + className={cn( + "inline-flex cursor-pointer select-none list-none items-center gap-1.5 rounded-[3px] px-1.5 py-0.5 text-[11.5px] text-muted-2 hover:bg-panel-2 hover:text-text [&::-webkit-details-marker]:hidden", + kind === "advanced" && "text-muted", + )} + > + <span aria-hidden className="inline-block transition-transform group-open/disclosure:rotate-90">▸</span> + <span className="font-medium">{label ?? (kind === "options" ? "Options" : "Advanced")}</span> + {hint && <span className="text-muted">{hint}</span>} + </summary> + <div className={cn("mt-1.5 flex flex-wrap items-start gap-2", bodyClassName)}>{children}</div> + </details> + ); +} + +export function Options(props: Omit<React.ComponentProps<typeof Disclosure>, "kind">) { + return <Disclosure kind="options" {...props} />; +} + +export function Advanced(props: Omit<React.ComponentProps<typeof Disclosure>, "kind">) { + return <Disclosure kind="advanced" {...props} />; +} + +/** + * A marked place for a control another lane owns (lane/vertical's vertical and side-tweet knobs): empty + * here, `data-panel-slot="<name>"` so it is found and filled there. + */ +export function PanelSlot({ name }: { name: string }) { + return <span data-panel-slot={name} hidden />; +} diff --git a/umtool/docs/cli.md b/umtool/docs/cli.md @@ -81,7 +81,7 @@ Inbox cannot disagree about what is wrong with one. | `timeline <project> insert (--to-section N \| --group G) <channel>/<video>@<start>-<end> [--id ID] [--lock] [--title T] [--stream-title T] [--date YYYY-MM-DD] [--quote Q] [--cite S] [--cite-url U]` | a clip at the **end of section N**, or **after group G's last clip and one of its clips** (the run stays together): one write, the marker that followed that last clip re-anchored after the new one, so the clip lands in the section and every other clip keeps its own; the attribution as `insert --after`'s. The Candidates panel's Insert is this ([knobs.md](knobs.md#the-candidates-inbox-proposed-clips-picked-by-a-press)) | | `candidates <project> [ls] [--all] [--json]` · `candidates <project> import <sweep.md> [--dry-run] [--json]` · `candidates <project> add <json\|@file> [--json]` | the **candidates inbox** (`<project>/candidates.json`): proposals only — `import` reads a sweep's bullets (`- [verdict] [title @ time](link) (date) "quote" — why`, under their headings; a Top N section marks what it restates; a bullet with no verdict or link is skipped and said), `add` an agent's (`{channel?, video, t, quote?, why?, verdict?, score?, section?}` or `{link, …}`); the same moment again changes nothing it holds. Insert and Not this are the Cut tab's Candidates panel's ([knobs.md](knobs.md#the-candidates-inbox-proposed-clips-picked-by-a-press)) | | `timeline <project> groups [ls] [--json]` · `groups import <file> [--skip-missing] [--drop-empty]` · `groups set <gid\|-> <id…> [--claim C]` · `groups move <gid> --to <index>` · `groups move <gid> --to after <gid>` · `groups label <gid> <claim…>` · `groups promote <gid> [--label L]` · `groups remove <gid>` · `order <file\|@file\|id…>` | **claim groups** (`groups` beside the timeline; the Cut tab's group bars): runs of clips inside one section making one claim — `ls` by section, each group's id, claim and clips (`--json` with the token); `import` a claim-groups file (`{sections: [{label, groups: [{claim, ids}]}]}`) in ONE write — the cut re-ordered to it, its groups the cut's, the markers following; a file section is the deck section of its name, else the one most of its clips are in; **exit 1** for an id the cut lacks (`--skip-missing`) or a section left with no clip (`--drop-empty` removes its marker); `set` (the clips already together), `label`, `remove` (ungroup), `move` the whole group (before the group at that index, or after one, in its section), `promote` (a level-2 marker at its first clip titled with its claim — the one group edit the render sees; `--label` when the claim is over 24); `order` the named entries in the places they hold (every clip keeping its section). A clip moved out of its group's run leaves it; moved alone into the middle of one, it joins. Every write an undo point (`undo`) ([knobs.md](knobs.md#claim-groups-runs-of-clips-that-make-one-claim)) | -| `timeline <project> --take <take> [ls \| move <id> --to <index> \| remove <id> \| undo]` | a **take's** timeline (walk a take): the same structure checks, written into the take's patch, each write with an undo point of the take's own (`takes/<take>/revisions/`); `undo` takes the take's newest edit back, whichever writer made it | +| `timeline <project> --take <take> [ls \| move <id> --to <index> \| remove <id> \| undo \| insert <spec> --after <id>\|-]` | a **take's** timeline (walk a take): the same structure checks, written into the take's patch, each write with an undo point of the take's own (`takes/<take>/revisions/`); `undo` takes the take's newest edit back, whichever writer made it. `insert` puts a clip (`<channel>/<video>@<start>-<end>`) into the take only (`takeEdit.mjs insertTakeEntry`) -- the app's **+ Add a clip to <take> only** on the take walk page, and Play's **+ Add a clip here** on a take with its own timeline | | `timeline <project> sections [--json]` · `section-move <id>… --to-section N [--start]` · `section-add --after <id> [--label L] [--color C]` · `section-boundary <marker> --after <id>` · `section-remove <marker>` · `section-set <marker> [--label L] [--color C]` · `split <id> <second>` · `flash-forward <id> <from>-<to> (--after <id\|-> \| --to-section N [--start]) [--move] [--quote Q] [--id ID]` | **sections as sections** (the deck's markers; the Cut tab's section bars and row menus): clips moved to a section with every marker following, a section opened, a boundary moved, relabelled, removed — no section emptied, no boundary crossed (**exit 1**) — and every take patch in step synced; **split** (each half's quote from the words, the second half's cite and QR at its second, a marker after the clip following its second half); **flash-forward** a tight copy of a span elsewhere with the clip's attribution and locks, as `repeatOf` the clip (`--move`: out of the clip) ([knobs.md](knobs.md#sections-split-and-flash-forward-editing-the-cut)) | | `scenes <project> <clip> [--black-min 0.05] [--threshold 8] [--pix-th 0.10] [--pad 30 \| --from S --to S] [--json]` | the picture's **scene cuts** (ffmpeg `scdet`, score ≥ threshold) and **black spans** (`blackdetect`) in the clip's fetched window, in SOURCE seconds — for `blur.from`/`blur.to` and trims ([knobs.md](knobs.md#a-clips-picture-blurred)). The window is the one the build would cut from (the project's `out/clips-raw`, the editor's `channels/<slug>/data/<id>/clips/`, a saved source); the extent ± `--pad` inside it is scanned. Nothing is fetched: **exit 1** with no window on disk (`fetch` first) | | `posts set <project> <post> thread=on\|off [hide=on\|off] [attach=<clipId>\|auto] [crop=<px>\|off] [--json]` | the Posts table's writer (`updatePosts`, `PUT /api/report/posts`) from a terminal: `<post>` is the manifest's id (`x-<postId>`) or the bare `<postId>`; `thread=on` draws a reply with the post it answers above it (`shot-thread.png` beside its `shot`, taken by `capture-posts` `"thread": true`; its own shot while there is none), `off` removes the key.; `crop=<px>` the post's own crop of its screenshot (`shotMaxHeight`, 120–1080: its top that tall, never panned; `off` removes it) ([knobs.md](knobs.md#add-post-a-post-card-from-play-the-cut)). Refused in the build's words (a post with no `shot`, an `attach` that is not a clip) — **exit 1** | diff --git a/umtool/e2e/bench-prep.spec.ts b/umtool/e2e/bench-prep.spec.ts @@ -3,6 +3,7 @@ import { copyFileSync, existsSync, mkdirSync, rmSync, writeFileSync } from "node import path from "node:path"; import { fileURLToPath } from "node:url"; import * as urls from "./urls"; +import { openPanel } from "./panels"; // --------------------------------------------------------------------------- // Preparing the walk (lib/report/benchPrep.mjs): the Cut tab's "Prepare clips @@ -58,6 +59,8 @@ test("Prepare clips for the walk makes the excerpt and the waveforms, and the be // ...which is made a moment later, and opened at once. makeProject(); await page.goto(urls.section(PROJECT, "timeline")); + await openPanel(page, "options", "cut"); + await openPanel(page, "advanced", "cut"); const panel = page.locator("[data-bench-prep]"); await expect(panel.locator("[data-bench-prep-status]")).toHaveText("0 of 2 ready to open · 2 to prepare"); expect(existsSync(EXCERPT)).toBe(false); diff --git a/umtool/e2e/clip-deck.spec.ts b/umtool/e2e/clip-deck.spec.ts @@ -3,6 +3,7 @@ import { existsSync, readFileSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import * as urls from "./urls"; +import { openPanel } from "./panels"; // --------------------------------------------------------------------------- // The montage clip deck (release 34 N1): every instance ruled by ear. The @@ -45,6 +46,8 @@ test("the clip deck: import, doubtful first, swipe keep, cut + undo, not him, re // The Cut tab says the montage has clips to rule and links the deck. await page.goto(urls.section(PROJECT, "cut")); + await openPanel(page, "options", "cut"); + await openPanel(page, "advanced", "cut"); const link = page.locator("[data-clip-deck-link]"); await expect(link).toHaveAttribute("data-clip-deck-link", "6"); await expect(link).toHaveAttribute("href", urls.clipDeckHref(PROJECT)); @@ -142,6 +145,8 @@ test("the clip deck: import, doubtful first, swipe keep, cut + undo, not him, re // The Cut tab counts them ruled. await page.goto(urls.section(PROJECT, "cut")); + await openPanel(page, "options", "cut"); + await openPanel(page, "advanced", "cut"); await expect(page.locator("[data-clip-deck-link]")).toHaveText("Clips — 6 ruled"); }); diff --git a/umtool/e2e/clip-editor.spec.ts b/umtool/e2e/clip-editor.spec.ts @@ -3,6 +3,7 @@ import { readFileSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import * as urls from "./urls"; +import { openPanel } from "./panels"; // --------------------------------------------------------------------------- // The clip editor (release 35 C2): a person hops in on an assistant's clips. @@ -39,6 +40,8 @@ test("the clip editor: trim, keep (the ruling follows), split, merge, restore, c // The Cut tab links the editor for a cut that is not a montage. await page.goto(urls.section(PROJECT, "cut")); + await openPanel(page, "options", "cut"); + await openPanel(page, "advanced", "cut"); const link = page.locator("[data-clip-editor-link]"); await expect(link).toHaveAttribute("data-clip-editor-link", "3"); await expect(link).toContainText("Clip editor — 3 clips · 3 by the assistant"); diff --git a/umtool/e2e/panels.ts b/umtool/e2e/panels.ts @@ -0,0 +1,14 @@ +import type { Page } from "@playwright/test"; + +// The Options / Advanced disclosures (components/ui/disclosure.tsx, lane/ui-simplify): a control +// folded into one is clicked after the panel is opened. `id` narrows to one page's panel ("cut", +// "take-card", "play"); without it every folded panel of that kind on the page opens. +export async function openPanel(page: Page, kind: "options" | "advanced", id?: string) { + const sel = `details[data-panel-disclosure="${kind}"]${id ? `[data-panel-id="${id}"]` : ""}`; + await page.locator(sel).first().waitFor({ state: "attached" }); + const n = await page.locator(sel).count(); + for (let i = 0; i < n; i++) { + const d = page.locator(sel).nth(i); + if (!(await d.evaluate((el) => (el as HTMLDetailsElement).open))) await d.locator(":scope > summary").click(); + } +} diff --git a/umtool/e2e/tighten.spec.ts b/umtool/e2e/tighten.spec.ts @@ -3,6 +3,7 @@ import { readFileSync, writeFileSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import * as urls from "./urls"; +import { openPanel } from "./panels"; // --------------------------------------------------------------------------- // Tighten to the sentence, snap an edge to its pause, and Propose tight @@ -95,6 +96,8 @@ test("Snap edge: the start, then the end, each to the middle of its nearest paus test("Propose tight windows: a review list, nothing written until Apply; Apply and Undo per row", async ({ page }) => { await page.setViewportSize({ width: 1440, height: 1100 }); await page.goto(urls.section(PROJECT, "cut")); + await openPanel(page, "options", "cut"); + await openPanel(page, "advanced", "cut"); const panel = page.locator("[data-tight-windows]"); await panel.scrollIntoViewIfNeeded(); await panel.locator("[data-action='propose-tight']").click(); diff --git a/umtool/e2e/trailer-beats.spec.ts b/umtool/e2e/trailer-beats.spec.ts @@ -3,6 +3,7 @@ import { copyFileSync, existsSync, readFileSync, rmSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import * as urls from "./urls"; +import { openPanel } from "./panels"; // --------------------------------------------------------------------------- // The Trailer page (UI notes 2026-10-30, item 11): @@ -44,6 +45,8 @@ async function open(page: Page) { test("the Cut tab links the Trailer page; it says the running length, the limit and the beat to fix", async ({ page }) => { await page.goto(urls.section(PROJECT, "timeline")); + await openPanel(page, "options", "cut"); + await openPanel(page, "advanced", "cut"); await expect(page.locator("[data-trailer-link]")).toHaveText("Trailer — 3 beats"); await page.locator("[data-trailer-link]").click(); await expect(page.getByTestId("trailer-editor")).toBeVisible(); diff --git a/umtool/e2e/voice-match.spec.ts b/umtool/e2e/voice-match.spec.ts @@ -3,6 +3,7 @@ import { readFileSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import * as urls from "./urls"; +import { openPanel } from "./panels"; // --------------------------------------------------------------------------- // Who is speaking, per montage clip (release 34): the Cut tab's "Score the @@ -21,6 +22,8 @@ const FILE = path.join(HERE, "..", ".e2e-song", "reports", "voice-fixture", "voi test("Score the voices: a job writes voice-match.json and each clip row shows its score", async ({ page }) => { await page.goto(urls.section(PROJECT, "cut")); + await openPanel(page, "options", "cut"); + await openPanel(page, "advanced", "cut"); const panel = page.locator("[data-voice-match-panel]"); await expect(panel).toBeVisible(); await expect(page.locator("[data-voice-summary]")).toHaveCount(0); diff --git a/umtool/lib/report/takeEdit.mjs b/umtool/lib/report/takeEdit.mjs @@ -40,6 +40,8 @@ import path from "node:path"; import { StaleToken, applyStructural, + entryFromSpec, + entryIndex, moveIn, patchClipEntry, removeIn, @@ -316,6 +318,35 @@ export async function removeTakeEntry(projectDir, id, entryId, { token = null, a return editTakeTimeline(projectDir, id, "remove", token, (m) => applyStructural(m, (x) => removeIn(x, entryId, at, { reanchor: false })), { now }); } +/** + * INSERT an entry into ONE TAKE's timeline (lane/ui-simplify, 5 Nov: "add to this take only"): a clip + * `<channel>/<video>@<start>-<end>` or an entry object, as the project's insertEntry takes it + * (manifest.mjs entryFromSpec: a fresh id unless it names one), after `afterId` (null: at the start). + * Written into the take's patch with an undo point of the take's own; the project's manifest is untouched. + * The CLI twin is `umtool timeline <p> --take <id> insert <spec> --after <id>`. + * @param {string} projectDir + * @param {string} id the take + * @param {string | null} afterId + * @param {unknown} spec + * @param {{ token?: string | null, at?: number | null, now?: Date }} [opts] + */ +export async function insertTakeEntry(projectDir, id, afterId, spec, { token = null, at = null, now = new Date() } = {}) { + return editTakeTimeline( + projectDir, + id, + "insert", + token, + (m) => + applyStructural(m, (x) => { + const i = afterId ? entryIndex(x.timeline, afterId, at) + 1 : 0; + const entry = entryFromSpec(x.timeline, spec); + x.timeline.splice(i, 0, entry); + return { id: entry.id, at: i, entry }; + }), + { now }, + ); +} + /** A take's label: one line, at most this long. */ export const TAKE_LABEL_MAX = 200; diff --git a/umtool/lib/report/takeEdit.test.mjs b/umtool/lib/report/takeEdit.test.mjs @@ -304,7 +304,17 @@ test("the CLI twins: umtool walk --take, umtool timeline --take, umtool take --p assert.equal(await timelineCommand(["proj", "--take", "tight", "move", "t03a", "--to", "0"], io), 0, err.join("\n")); assert.match(out.join("\n"), /take tight: moved t03a: 3 -> 0/); assert.equal(await timelineCommand(["proj", "--take", "tight", "undo"], io), 0, err.join("\n")); - assert.equal(await timelineCommand(["proj", "--take", "tight", "insert", "--after", "-", "chan/vid@1-5"], io), 2, "only ls, move, remove, undo on a take"); + // "Add to this take only" (lane/ui-simplify): a clip into the take's timeline, never the project's. + const masterBefore = await masterText(dir); + out.length = 0; + assert.equal(await timelineCommand(["proj", "--take", "tight", "insert", "--after", "-", "chan/vid@1-5"], io), 0, err.join("\n")); + assert.match(out.join("\n"), /take tight: inserted/); + assert.equal(await masterText(dir), masterBefore, "the project's manifest is untouched"); + out.length = 0; + assert.equal(await timelineCommand(["proj", "--take", "tight", "ls"], io), 0, err.join("\n")); + assert.match(out.join("\n"), /5 entries in take tight of proj/); + assert.equal(await timelineCommand(["proj", "--take", "tight", "undo"], io), 0, err.join("\n")); + assert.equal(await timelineCommand(["proj", "--take", "tight", "insert", "chan/vid@1-5"], io), 2, "insert needs --after"); out.length = 0; assert.equal(await timelineCommand(["proj", "--take", "tight", "ls"], io), 0, err.join("\n")); assert.match(out.join("\n"), /4 entries in take tight of proj$/, "the move was undone: nothing left to undo"); diff --git a/umtool/lib/report/timelineCli.mjs b/umtool/lib/report/timelineCli.mjs @@ -165,7 +165,7 @@ export const TIMELINE_USAGE = [ " umtool timeline <project> groups promote <gid> [--label L] the group opens a subsection: a level-2 marker at", " its first clip titled with its claim (--label when it is over 24); the render sees only this", " A clip moved out of its group's run leaves the group; moved alone into the middle of a run, it joins it", - " umtool timeline <project> --take <id> [ls | move <id> --to <index> | remove <id> | undo]", + " umtool timeline <project> --take <id> [ls | move <id> --to <index> | remove <id> | undo | insert <spec> --after <id>|-]", " a take's timeline (walk a take): written into the take's patch (takes/<id>/take.json),", " each write with an undo point of the take's own; the project's manifest is untouched", "", @@ -178,7 +178,7 @@ const VERBS = ["ls", "insert", "move", "place", "remove", "reject", "wrong-speak const GROUP_VERBS = ["ls", "import", "set", "move", "label", "promote", "remove"]; const VALUED = new Set(["--group", "--after", "--before", "--to", "--at", "--id", "--section", "--title", "--stream-title", "--date", "--quote", "--cite", "--cite-url", "--take", "--correction", "--note", "--to-section", "--label", "--color", "--level", "--claim", "--conversation"]); /** What `--take <id>` does on a take's timeline (takeEdit.mjs): the walk's structure and its undo. */ -const TAKE_VERBS = ["ls", "move", "remove", "undo"]; +const TAKE_VERBS = ["ls", "move", "remove", "undo", "insert"]; class CliError extends Error {} @@ -888,6 +888,13 @@ async function takeTimeline(project, take, verb, rest, flags, { out, json }) { const id = rest[0]; if (!id) throw new CliError("remove needs an entry id"); result = await edit.removeTakeEntry(project.dir, take, id, { token, at }); + } else if (verb === "insert") { + // "Add to this take only" (the Add a clip panel on a take): a clip spec into the take's timeline. + const spec = rest[0]; + if (!spec) throw new CliError("insert needs a clip: <channel>/<video>@<start>-<end>"); + if (!flags.has("--after")) throw new CliError("insert needs --after <id> (or --after - for the start)"); + const afterArg = String(flags.get("--after")); + result = await edit.insertTakeEntry(project.dir, take, afterArg === "-" || afterArg === "" ? null : afterArg, spec, { token, at }); } else { result = await edit.undoTakeEdit(project.dir, take, { token }); }