commit cbe7cb2f08415a39266dfd5ec12cdd238d1bf78e
parent 69d936f0cfc73ed94bde451245bce6fd8a310740
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Mon, 19 Oct 2026 00:21:01 -0400
umtool: the clip editor at /projects/<id>/clips for a cut that is not a montage (release 35 C2)
A player looping the clip's cut, the strip of its neighbourhood (speaker
turns by role, laughs, word ticks, the other clips, the cut with drag
handles, a selection to add), the words, edges with nudges and Snap, Keep /
Cut, Split here, Merge with next, Restore the assistant's version, Bring in
an unused proposal, This is the host, comments anchored to the clip, the
edit history, and Render a take. Keys: Space, J/L, I/O, S, M, K, X, arrows.
The montage deck is unchanged; `?mode=edit` opens the editor on a montage.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
5 files changed, 1099 insertions(+), 3 deletions(-)
diff --git a/umtool/components/projects/ClipDeckPage.tsx b/umtool/components/projects/ClipDeckPage.tsx
@@ -9,6 +9,9 @@ import VoiceMatchPanel from "./report/VoiceMatchPanel";
import FetchWindowsPanel from "./report/FetchWindowsPanel";
import { lastStartedRun, projectFetchBody, readFetchRuns } from "@/lib/report/fetchWindows.mjs";
import { readVoiceMatch, voiceMatchSummary } from "yt-dlp-transcript-common/lib/montage/voiceMatch.mjs";
+import { readManifest } from "@/lib/projects/report.mjs";
+import { hasMontageClips } from "@/lib/report/montageRulings.mjs";
+import ClipEditorPage from "./ClipEditorPage";
// `/projects/<project>/clips` -- THE CLIP DECK (release 34 N1): a montage's
// every instance, one card at a time, its cut playing, ruled by ear: keep, cut,
@@ -18,7 +21,12 @@ import { readVoiceMatch, voiceMatchSummary } from "yt-dlp-transcript-common/lib/
// here calls a model; release 34 N2's voice-match.json, when it is there,
// only orders the doubtful first and shows its score.
-export default async function ClipDeckPage({ project, show }: { project: ProjectRef; show?: string }) {
+export default async function ClipDeckPage({ project, show, mode, clip }: { project: ProjectRef; show?: string; mode?: string; clip?: string }) {
+ // A cut that is not a montage -- an assistant's clips, any report video's --
+ // gets the clip editor (release 35 C2); `?mode=edit` opens it on a montage.
+ // The montage deck below is unchanged.
+ const manifest = await readManifest(project.dir);
+ if (mode === "edit" || (manifest && !hasMontageClips(manifest))) return <ClipEditorPage project={project} clip={clip} />;
const view = await clipDeckView(project);
const back = await pieceHrefOfProject(project.id, { tab: "cut" });
const top = <BenchTop trail={[{ href: projectsHref(), label: "Projects" }]} back={{ href: back, label: project.id }} kind="Clip deck" here="clips" />;
diff --git a/umtool/components/projects/ClipEditorPage.tsx b/umtool/components/projects/ClipEditorPage.tsx
@@ -0,0 +1,58 @@
+import Link from "next/link";
+import { projectsHref, takesHref } from "@/lib/hrefs";
+import { clipDeckView } from "@/lib/report/clipDeck";
+import { clipEditorView } from "@/lib/report/clipEditor.mjs";
+import type { EditorView } from "@/lib/report/clipEditorTypes";
+import { pieceHrefOfProject } from "@/lib/pieces/article";
+import type { ProjectRef } from "@/lib/project-types";
+import { NotesProvider } from "@/components/notes/NotesProvider";
+import { BenchBody, BenchFrame, BenchTop } from "./bench/BenchShell";
+import ClipEditor from "./review/ClipEditor";
+
+// `/projects/<project>/clips` on a cut that is not a montage -- THE CLIP
+// EDITOR (release 35 C2): a person hops in on the clips an assistant made
+// (the clip finder's, `assist` on each) or on any report video's clips, and
+// trims, splits, merges, adds, restores, keeps or cuts them, comments on
+// them (notes.json, anchored to the clip) and says which voice is the host.
+// lib/report/clipEditor.mjs is every write. Nothing here calls a model.
+
+const KEYS = [
+ { keys: ["Space"], label: "play" },
+ { keys: ["J", "L"], label: "∓2 s" },
+ { keys: ["I", "O"], label: "in / out" },
+ { keys: ["S"], label: "split" },
+ { keys: ["M"], label: "merge" },
+ { keys: ["K", "X"], label: "keep / cut" },
+ { keys: ["←", "→"], label: "clip" },
+];
+
+export default async function ClipEditorPage({ project, clip }: { project: ProjectRef; clip?: string }) {
+ const [view, deck, back] = await Promise.all([
+ clipEditorView(project) as Promise<EditorView | null>,
+ clipDeckView(project).catch(() => null),
+ pieceHrefOfProject(project.id, { tab: "cut" }),
+ ]);
+ const top = <BenchTop trail={[{ href: projectsHref(), label: "Projects" }]} back={{ href: back, label: project.id }} kind="Clip editor" here="clips" keys={KEYS} />;
+ if (!view || !view.clips.length) {
+ return (
+ <BenchFrame kind="clip-editor" top={top}>
+ <BenchBody workClassName="space-y-3">
+ <p data-clip-editor-empty="" className="text-[12px] text-muted">
+ No clips in this cut.{" "}
+ <Link href={back} className="ink-link">
+ back to {project.id}
+ </Link>
+ </p>
+ </BenchBody>
+ </BenchFrame>
+ );
+ }
+ const initial = view.clips.some((c) => c.id === clip) ? (clip as string) : view.clips[0].id;
+ return (
+ <BenchFrame kind="clip-editor" top={top}>
+ <NotesProvider target={{ project: project.id }}>
+ <ClipEditor project={project.id} initialView={view} initialClip={initial} takesHref={takesHref(project.id)} render={deck?.rerender ?? null} takes={deck?.takes ?? 0} />
+ </NotesProvider>
+ </BenchFrame>
+ );
+}
diff --git a/umtool/components/projects/ProjectView.tsx b/umtool/components/projects/ProjectView.tsx
@@ -64,8 +64,9 @@ export default async function ProjectView({
// before a final build, and the alternatives a draft task kept.
if (rest.length === 1 && rest[0] === "review") return <ReviewPage project={project} view={search.view} />;
// `/projects/<project>/clips` -- the montage's instances, ruled by ear
- // keep / cut / not him / read aloud (release 34), applied at render.
- if (rest.length === 1 && rest[0] === "clips") return <ClipDeckPage project={project} show={search.show} />;
+ // keep / cut / not him / read aloud (release 34), applied at render;
+ // on a cut that is not a montage, the clip editor (release 35 C2).
+ if (rest.length === 1 && rest[0] === "clips") return <ClipDeckPage project={project} show={search.show} mode={search.mode} clip={search.clip} />;
return notFound();
}
case "sweep-report": {
diff --git a/umtool/components/projects/review/ClipEditor.tsx b/umtool/components/projects/review/ClipEditor.tsx
@@ -0,0 +1,1020 @@
+"use client";
+
+import Link from "next/link";
+import { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react";
+import { badgeVariants } from "@/components/ui/badge";
+import { buttonVariants } from "@/components/ui/button";
+import { useSharedNotes } from "@/components/notes/NotesProvider";
+import { notesOn } from "@/components/notes/AnchoredNotes";
+import { NoteThread } from "@/components/notes/NoteThread";
+import type { CitedPlay } from "@/lib/clips/types";
+import { edgeClock, provenanceWords, quoteBetween, roleOf, snapCut, snapPoints } from "@/lib/report/clipEditorModel.mjs";
+import type { EditorClip, EditorView, Neighbourhood, Proposal, RenderTarget, Speaker, Turn } from "@/lib/report/clipEditorTypes";
+import { cn } from "@/lib/utils";
+import { startTakeJob } from "../NewTakePanel";
+
+// ---------------------------------------------------------------------------
+// THE CLIP EDITOR (release 35 C2): a person hops in on an assistant's clips.
+//
+// the player loops the selected clip's cut (a saved video, a clip
+// window, or audio -- what /api/cited/play finds)
+// the strip the clip's neighbourhood (± 60 s, or closer): the speaker
+// turns coloured by role (host / subject, reactions.json),
+// laugh marks, the words, the other clips, the cut with drag
+// handles; a drag on the strip selects a span to add
+// the edges numeric fields, nudges ±0.1 / ±0.5 / ±2 s, Snap to the
+// nearest word gap or silence
+// the decisions Keep / Cut (montage-rulings.json, keyed by the moment),
+// Split here, Merge with next, Restore the assistant's
+// version, Add a clip from the selection, Bring in a proposal
+// the comments a note on the clip (notes.json, anchored to it), its thread
+// and an agent's replies, resolve / reopen
+//
+// Every write is one POST to /api/report/clip-editor; the answer is the whole
+// view again, so the page never guesses what the server did. Edge edits are
+// drafted locally and written after a short pause, so a run of nudges is one
+// edit. Nothing here calls a model.
+// ---------------------------------------------------------------------------
+
+const REACHES = [60, 20, 6] as const;
+const NUDGES = [-2, -0.5, -0.1, 0.1, 0.5, 2] as const;
+const COMMIT_MS = 450;
+const TYPING = "input, textarea, select, [contenteditable=''], [contenteditable='true']";
+const ROLE_FILL: Record<string, string> = { host: "bg-signal", subject: "bg-meter", other: "bg-muted" };
+const ROLE_WORD: Record<string, string> = { host: "host", subject: "subject", other: "other" };
+const r2 = (n: number) => Math.round(n * 100) / 100;
+const cutOf = (c: EditorClip) => ({ cutStart: c.cutStart ?? c.start, cutEnd: c.cutEnd ?? c.end });
+const rulingBadge = (r: string) => (r === "keep" ? cn(badgeVariants({ variant: "neutral", size: "sm" }), "border-kept-text text-kept-text") : badgeVariants({ variant: "blocking", size: "sm" }));
+const plural = (n: number, w: string) => `${n} ${w}${n === 1 ? "" : "s"}`;
+
+type Cut = { cutStart: number; cutEnd: number };
+
+async function post(body: Record<string, unknown>): Promise<{ ok: boolean; status: number; json: Record<string, unknown> }> {
+ const r = await fetch("/api/report/clip-editor", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(body) });
+ const json = (await r.json().catch(() => ({}))) as Record<string, unknown>;
+ return { ok: r.ok, status: r.status, json };
+}
+
+export default function ClipEditor({
+ project,
+ initialView,
+ initialClip,
+ takesHref,
+ render,
+ takes,
+}: {
+ project: string;
+ initialView: EditorView;
+ initialClip: string;
+ takesHref: string;
+ render: RenderTarget;
+ takes: number;
+}) {
+ const [view, setView] = useState<EditorView>(initialView);
+ const [selected, setSelected] = useState(initialClip);
+ const [draft, setDraft] = useState<Cut | null>(null);
+ const [reach, setReach] = useState<number>(REACHES[0]);
+ const [hood, setHood] = useState<Neighbourhood | null>(null);
+ const [playhead, setPlayhead] = useState<number | null>(null);
+ const [playing, setPlaying] = useState(false);
+ const [selection, setSelection] = useState<Cut | null>(null);
+ const [speakerPick, setSpeakerPick] = useState<number | null>(null);
+ const [rolesChanged, setRolesChanged] = useState(false);
+ const [busy, setBusy] = useState(false);
+ const [error, setError] = useState<string | null>(null);
+ const [status, setStatus] = useState<string | null>(null);
+ const token = useRef<string | null>(initialView.token);
+ const chain = useRef<Promise<unknown>>(Promise.resolve());
+ const timer = useRef<ReturnType<typeof setTimeout> | null>(null);
+ const pending = useRef<{ clip: string; cut: Cut } | null>(null);
+ const player = useRef<PlayerHandle | null>(null);
+
+ const clips = view.clips;
+ const index = Math.max(0, clips.findIndex((c) => c.id === selected));
+ const clip = clips[index] ?? clips[0];
+ const committed = cutOf(clip);
+ const cut = draft ?? committed;
+ const speakers = view.reactions?.speakers ?? [];
+
+ // The page's address names the clip, so a reload (or a link) lands on it.
+ useEffect(() => {
+ const u = new URL(window.location.href);
+ if (u.searchParams.get("clip") === clip.id) return;
+ u.searchParams.set("clip", clip.id);
+ window.history.replaceState(null, "", u.toString());
+ }, [clip.id]);
+
+ // ---- writes ---------------------------------------------------------------
+ const reload = useCallback(async () => {
+ const r = await fetch(`/api/report/clip-editor?project=${encodeURIComponent(project)}`, { cache: "no-store" });
+ const j = (await r.json()) as EditorView & { error?: string };
+ if (!r.ok) throw new Error(j.error ?? `HTTP ${r.status}`);
+ token.current = j.token;
+ setView(j);
+ }, [project]);
+
+ const write = useCallback(
+ (body: Record<string, unknown>, done?: string) => {
+ const run = async () => {
+ setBusy(true);
+ try {
+ const r = await post({ project, token: token.current, ...body });
+ if (r.status === 409) {
+ await reload();
+ setError(`${String(r.json.error ?? "the cut changed")} — reloaded; check and try again`);
+ return null;
+ }
+ if (!r.ok) {
+ setError(String(r.json.error ?? `HTTP ${r.status}`));
+ return null;
+ }
+ const next = r.json.view as EditorView;
+ token.current = next.token;
+ setView(next);
+ setError(null);
+ if (done) setStatus(done);
+ return r.json;
+ } catch (e) {
+ setError(e instanceof Error ? e.message : String(e));
+ return null;
+ } finally {
+ setBusy(false);
+ }
+ };
+ const p = chain.current.then(run, run);
+ chain.current = p;
+ return p;
+ },
+ [project, reload],
+ );
+
+ const flush = useCallback(() => {
+ if (timer.current) clearTimeout(timer.current);
+ timer.current = null;
+ const p = pending.current;
+ pending.current = null;
+ if (!p) return chain.current;
+ return write({ op: "trim", clip: p.clip, cutStart: p.cut.cutStart, cutEnd: p.cut.cutEnd }, "Saved the edges").then(() => setDraft(null));
+ }, [write]);
+
+ /** Move the edges now; write them after a short pause (a run of nudges is one edit). */
+ const setEdges = useCallback(
+ (next: Cut, { now = false }: { now?: boolean } = {}) => {
+ const a = r2(Math.max(0, next.cutStart));
+ const b = r2(next.cutEnd);
+ if (b - a < 0.5) {
+ setError("a clip must be at least half a second");
+ return;
+ }
+ setError(null);
+ setDraft({ cutStart: a, cutEnd: b });
+ pending.current = { clip: clip.id, cut: { cutStart: a, cutEnd: b } };
+ if (timer.current) clearTimeout(timer.current);
+ if (now) void flush();
+ else timer.current = setTimeout(() => void flush(), COMMIT_MS);
+ },
+ [clip.id, flush],
+ );
+
+ const choose = useCallback(
+ (id: string) => {
+ void flush();
+ setSelected(id);
+ setDraft(null);
+ setSelection(null);
+ setSpeakerPick(null);
+ setPlayhead(null);
+ setStatus(null);
+ },
+ [flush],
+ );
+ useEffect(() => () => {
+ if (timer.current) clearTimeout(timer.current);
+ }, []);
+
+ // ---- the neighbourhood ----------------------------------------------------
+ const duration = hood?.duration ?? view.reactions?.source?.duration ?? null;
+ const viewFrom = Math.max(0, Math.floor(committed.cutStart - reach));
+ const viewTo = Math.ceil(duration ? Math.min(duration, committed.cutEnd + reach) : committed.cutEnd + reach);
+ useEffect(() => {
+ let live = true;
+ const q = new URLSearchParams({ project, clip: clip.id, from: String(viewFrom), to: String(viewTo) });
+ void fetch(`/api/report/clip-editor?${q}`, { cache: "no-store" })
+ .then(async (r) => {
+ const j = await r.json();
+ if (!r.ok) throw new Error(j.error ?? `HTTP ${r.status}`);
+ if (live) setHood(j as Neighbourhood);
+ })
+ .catch((e) => live && setError(e instanceof Error ? e.message : String(e)));
+ return () => {
+ live = false;
+ };
+ }, [project, clip.id, viewFrom, viewTo]);
+ const hoodHere = hood && hood.from === viewFrom && hood.to === viewTo ? hood : null;
+ const points = useMemo(() => (hoodHere ? snapPoints({ words: hoodHere.words, turns: hoodHere.turns, cues: hoodHere.cues }) : []), [hoodHere]);
+
+ // ---- decisions ------------------------------------------------------------
+ const rule = (verdict: "keep" | "cut" | null) => {
+ void flush().then(() => write({ op: "ruling", clip: clip.id, verdict }, verdict ? `Ruled ${verdict}` : "Ruling cleared"));
+ };
+ const splitHere = () => {
+ const at = playhead;
+ if (at === null || at - cut.cutStart < 0.5 || cut.cutEnd - at < 0.5) {
+ setError("put the playhead inside the cut (half a second from either edge) to split there");
+ return;
+ }
+ void flush().then(() => write({ op: "split", clip: clip.id, at: r2(at) }, `Split at ${edgeClock(at)}`));
+ };
+ const next = clips[index + 1] ?? null;
+ const mergeNext = () => {
+ if (!next) return;
+ void flush().then(() => write({ op: "merge", clip: clip.id }, `Merged ${next.id} into ${clip.id}`));
+ };
+ const restore = () => {
+ void flush().then(() => write({ op: "restore", clip: clip.id }, "Restored the assistant's version"));
+ };
+ const addSelection = () => {
+ if (!selection) return;
+ void flush()
+ .then(() => write({ op: "add", clip: clip.id, cutStart: r2(selection.cutStart), cutEnd: r2(selection.cutEnd) }, "Added a clip"))
+ .then((j) => {
+ const id = (j?.result as { id?: string } | undefined)?.id;
+ setSelection(null);
+ if (id) choose(id);
+ });
+ };
+ const bringIn = (p: Proposal) => {
+ void flush()
+ .then(() => write({ op: "bring-in", proposal: p.id }, `Brought in ${p.id}`))
+ .then((j) => {
+ const id = (j?.result as { id?: string } | undefined)?.id;
+ if (id) choose(id);
+ });
+ };
+ const setRole = (speaker: number, role: "host" | "subject" | "other") => {
+ void write({ op: "role", speaker, role }, `Speaker ${speaker} is the ${ROLE_WORD[role]}`).then((j) => {
+ if (j) setRolesChanged(true);
+ });
+ };
+ const snap = () => {
+ if (!points.length) {
+ setError("nothing to snap to here: no words, cues or turns in this span");
+ return;
+ }
+ const s = snapCut(cut, points);
+ setEdges(s, { now: true });
+ };
+ const nudge = (edge: "in" | "out", d: number) => setEdges(edge === "in" ? { cutStart: cut.cutStart + d, cutEnd: cut.cutEnd } : { cutStart: cut.cutStart, cutEnd: cut.cutEnd + d });
+ const setAtPlayhead = (edge: "in" | "out") => {
+ if (playhead === null) return;
+ nudge(edge, playhead - (edge === "in" ? cut.cutStart : cut.cutEnd));
+ };
+ const seek = (t: number) => {
+ setPlayhead(t);
+ player.current?.seek(t);
+ };
+
+ // ---- keys -----------------------------------------------------------------
+ const keyRef = useRef<(e: KeyboardEvent) => void>(() => {});
+ keyRef.current = (e: KeyboardEvent) => {
+ if (e.defaultPrevented || e.metaKey || e.ctrlKey || e.altKey) return;
+ const t = e.target as HTMLElement | null;
+ if (t?.closest?.(TYPING) || t?.closest?.("dialog[open]")) return;
+ const k = e.key.length === 1 ? e.key.toLowerCase() : e.key;
+ const act: Record<string, () => void> = {
+ " ": () => player.current?.toggle(),
+ j: () => seek(Math.max(0, (playhead ?? cut.cutStart) - 2)),
+ l: () => seek((playhead ?? cut.cutStart) + 2),
+ i: () => setAtPlayhead("in"),
+ o: () => setAtPlayhead("out"),
+ s: splitHere,
+ m: mergeNext,
+ k: () => rule("keep"),
+ x: () => rule("cut"),
+ ArrowLeft: () => index > 0 && choose(clips[index - 1].id),
+ ArrowRight: () => index + 1 < clips.length && choose(clips[index + 1].id),
+ };
+ const f = act[k];
+ if (!f) return;
+ e.preventDefault();
+ f();
+ };
+ useEffect(() => {
+ const on = (e: KeyboardEvent) => keyRef.current(e);
+ document.addEventListener("keydown", on);
+ return () => document.removeEventListener("keydown", on);
+ }, []);
+
+ // ---- what plays -----------------------------------------------------------
+ const targets = useMemo(() => {
+ if (!clip.channel) return [];
+ const base = { channel: clip.channel, video: clip.video, project, clip: clip.id };
+ const spans: [number, number][] = [
+ [viewFrom, viewTo],
+ [clip.start, clip.end],
+ [committed.cutStart, committed.cutEnd],
+ ];
+ return spans.filter(([a, b], i) => b > a && spans.findIndex(([x, y]) => x === a && y === b) === i).map(([from, to]) => ({ ...base, from, to }));
+ }, [clip.channel, clip.video, clip.id, clip.start, clip.end, committed.cutStart, committed.cutEnd, project, viewFrom, viewTo]);
+
+ const assist = clip.assist;
+ const prov = provenanceWords(assist);
+ const canRestore = !!assist?.original && (assist.original.cutStart ?? assist.original.start) !== undefined;
+ const edits = assist?.edits ?? [];
+ const quoteNow = hoodHere ? quoteBetween({ words: hoodHere.words, cues: hoodHere.cues }, cut.cutStart, cut.cutEnd) : null;
+ const pickRole = speakerPick !== null ? roleOf(speakers, speakerPick) : null;
+
+ return (
+ <div data-clip-editor={clip.id} data-clip-editor-busy={busy ? "" : undefined} className="flex min-h-0 flex-1 flex-col lg:grid lg:grid-cols-[minmax(0,1fr)_minmax(300px,26%)]">
+ <main data-bench-work="" className="deck-main min-h-0 space-y-3 overflow-auto p-4">
+ {/* ---- the clip ---------------------------------------------------- */}
+ <div className="flex flex-wrap items-baseline gap-x-3 gap-y-1">
+ <h1 className="m-0 font-mono text-[15px] font-semibold text-text" data-editor-clip-id="">
+ {clip.id}
+ </h1>
+ <span className="num font-mono text-[12.5px] text-text-2" data-editor-cut={`${cut.cutStart}-${cut.cutEnd}`}>
+ {edgeClock(cut.cutStart)} – {edgeClock(cut.cutEnd)} · {(cut.cutEnd - cut.cutStart).toFixed(1)} s
+ </span>
+ {draft && <span className="micro" data-editor-unsaved="">unsaved</span>}
+ {clip.ruling && (
+ <span data-editor-ruling={clip.ruling} className={rulingBadge(clip.ruling)}>
+ {clip.ruling === "keep" ? "kept" : "cut"}
+ </span>
+ )}
+ <span className="text-[12px] text-muted">
+ {index + 1} of {clips.length}
+ </span>
+ </div>
+ {prov && (
+ <p data-editor-provenance={assist?.by ?? ""} className="m-0 text-[12.5px] text-text-2">
+ {prov}
+ </p>
+ )}
+ {(quoteNow ?? clip.quote) && (
+ <p data-editor-quote="" className="m-0 max-w-[70ch] text-[13px] leading-snug text-text">
+ {quoteNow || clip.quote}
+ </p>
+ )}
+
+ <Player ref={player} targets={targets} cut={cut} onTime={setPlayhead} onPlaying={setPlaying} />
+
+ {/* ---- the strip --------------------------------------------------- */}
+ <div className="space-y-1">
+ <div className="flex flex-wrap items-center gap-2 text-[11.5px] text-muted">
+ <span className="micro">around the clip</span>
+ {REACHES.map((r) => (
+ <button
+ key={r}
+ type="button"
+ data-reach={r}
+ aria-pressed={reach === r}
+ onClick={() => setReach(r)}
+ className={buttonVariants({ variant: reach === r ? "pressed" : "quiet", size: "sm" })}
+ >
+ ± {r} s
+ </button>
+ ))}
+ {speakers.length > 0 ? (
+ <span className="flex flex-wrap items-center gap-2" data-strip-legend="">
+ <span className="inline-flex items-center gap-1">
+ <span className="inline-block h-2 w-3 rounded-[1px] bg-signal" /> host
+ </span>
+ <span className="inline-flex items-center gap-1">
+ <span className="inline-block h-2 w-3 rounded-[1px] bg-meter" /> subject
+ </span>
+ <span className="inline-flex items-center gap-1">
+ <span className="inline-block h-2 w-1 rounded-[1px] bg-doubt" /> laugh
+ </span>
+ </span>
+ ) : (
+ <span data-strip-no-speakers="">no speakers for this cut (no reactions.json)</span>
+ )}
+ {playhead !== null && <span className="num ml-auto font-mono">{edgeClock(playhead)}{playing ? " ▶" : ""}</span>}
+ </div>
+ <Strip
+ from={viewFrom}
+ to={viewTo}
+ cut={cut}
+ hood={hoodHere}
+ speakers={speakers}
+ others={clips.filter((c) => c.id !== clip.id && c.video === clip.video && c.channel === clip.channel)}
+ playhead={playhead}
+ selection={selection}
+ speakerPick={speakerPick}
+ onSeek={seek}
+ onEdge={(edge, t, done) => {
+ const nextCut = edge === "in" ? { cutStart: t, cutEnd: cut.cutEnd } : { cutStart: cut.cutStart, cutEnd: t };
+ if (done) setEdges(nextCut, { now: true });
+ else if (nextCut.cutEnd - nextCut.cutStart >= 0.5) setDraft({ cutStart: r2(nextCut.cutStart), cutEnd: r2(nextCut.cutEnd) });
+ }}
+ onSelect={setSelection}
+ onTurn={(t) => setSpeakerPick(t.speaker)}
+ onOther={choose}
+ />
+ {speakerPick !== null && (
+ <div data-speaker-pick={speakerPick} className="flex flex-wrap items-center gap-2 text-[12px] text-text-2">
+ <span>
+ Speaker {speakerPick} · {pickRole ? ROLE_WORD[pickRole] ?? pickRole : "no role"}
+ {speakers.find((s) => s.index === speakerPick)?.how === "operator" ? " (you said)" : ""}
+ </span>
+ {pickRole !== "host" && (
+ <button type="button" data-set-host={speakerPick} disabled={busy} onClick={() => setRole(speakerPick, "host")} className={buttonVariants({ size: "sm" })}>
+ This is the host
+ </button>
+ )}
+ {pickRole === "host" && (
+ <button type="button" data-set-subject={speakerPick} disabled={busy} onClick={() => setRole(speakerPick, "subject")} className={buttonVariants({ size: "sm" })}>
+ Not the host
+ </button>
+ )}
+ <button type="button" onClick={() => setSpeakerPick(null)} className={buttonVariants({ variant: "quiet", size: "sm" })}>
+ Close
+ </button>
+ </div>
+ )}
+ {rolesChanged && (
+ <div data-repropose="" className="flex flex-wrap items-center gap-2 text-[12px] text-text-2">
+ <span>The roles changed: the proposals were made with the old ones.</span>
+ <button type="button" data-repropose-button="" disabled={!view.repropose.available} title={view.repropose.why ?? undefined} className={buttonVariants({ size: "sm" })}>
+ Re-propose
+ </button>
+ {!view.repropose.available && view.repropose.why && <span className="text-muted" data-repropose-why="">{view.repropose.why}</span>}
+ </div>
+ )}
+ <Words hood={hoodHere} cut={cut} playhead={playhead} onSeek={seek} />
+ </div>
+
+ {/* ---- the edges --------------------------------------------------- */}
+ <div className="grid gap-2 sm:grid-cols-2" data-editor-edges="">
+ {(["in", "out"] as const).map((edge) => (
+ <EdgeControl key={edge} edge={edge} value={edge === "in" ? cut.cutStart : cut.cutEnd} onNudge={(d) => nudge(edge, d)} onSet={(v) => nudge(edge, v - (edge === "in" ? cut.cutStart : cut.cutEnd))} onPlayhead={playhead === null ? null : () => setAtPlayhead(edge)} />
+ ))}
+ </div>
+
+ {/* ---- the decisions ----------------------------------------------- */}
+ <div className="flex flex-wrap items-center gap-2" data-editor-actions="">
+ <button type="button" data-rule="keep" aria-pressed={clip.ruling === "keep"} disabled={busy} onClick={() => rule(clip.ruling === "keep" ? null : "keep")} className={buttonVariants({ variant: clip.ruling === "keep" ? "pressed" : "outline", size: "md" })}>
+ Keep <kbd>K</kbd>
+ </button>
+ <button type="button" data-rule="cut" aria-pressed={clip.ruling === "cut"} disabled={busy} onClick={() => rule(clip.ruling === "cut" ? null : "cut")} className={buttonVariants({ variant: clip.ruling === "cut" ? "pressed" : "outline", size: "md" })}>
+ Cut <kbd>X</kbd>
+ </button>
+ <button type="button" data-action="snap" disabled={busy} onClick={snap} className={buttonVariants({ size: "md" })}>
+ Snap to words
+ </button>
+ <button type="button" data-action="split" disabled={busy} onClick={splitHere} className={buttonVariants({ size: "md" })}>
+ Split here <kbd>S</kbd>
+ </button>
+ <button type="button" data-action="merge" disabled={busy || !next} onClick={mergeNext} className={buttonVariants({ size: "md" })} title={next ? `merge with ${next.id}` : "the last clip"}>
+ Merge with next <kbd>M</kbd>
+ </button>
+ {canRestore && (
+ <button type="button" data-action="restore" disabled={busy || assist?.by === "assistant"} onClick={restore} className={buttonVariants({ size: "md" })}>
+ Restore the assistant’s version
+ </button>
+ )}
+ {selection && (
+ <button type="button" data-action="add" disabled={busy} onClick={addSelection} className={buttonVariants({ variant: "go", size: "md" })}>
+ Add a clip {edgeClock(selection.cutStart)}–{edgeClock(selection.cutEnd)}
+ </button>
+ )}
+ </div>
+ <div aria-live="polite" className="min-h-[1.2em] text-[12px]">
+ {error ? (
+ <span role="alert" data-editor-error="" className="text-reject-text">
+ {error}
+ </span>
+ ) : status ? (
+ <span data-editor-status="" className="text-muted">
+ {status}
+ </span>
+ ) : null}
+ </div>
+
+ {/* ---- comments and history ---------------------------------------- */}
+ <ClipNotes project={project} clipId={clip.id} />
+ {edits.length > 0 && (
+ <details data-editor-history={edits.length} className="text-[12px] text-text-2">
+ <summary className="cursor-pointer text-muted">{plural(edits.length, "edit")} to this clip</summary>
+ <ol className="m-0 mt-1 space-y-0.5 pl-5">
+ {edits.map((e, i) => (
+ <li key={i} data-edit={e.what} className="num font-mono text-[11.5px]">
+ {e.what} · {e.from ? `${edgeClock(e.from.cutStart)}–${edgeClock(e.from.cutEnd)} → ` : ""}
+ {edgeClock(e.to.cutStart)}–{edgeClock(e.to.cutEnd)} · {new Date(e.at).toLocaleString()}
+ </li>
+ ))}
+ </ol>
+ </details>
+ )}
+ </main>
+
+ {/* ---- the list, the proposals, the speakers, the take --------------- */}
+ <aside className="flex min-h-0 flex-col gap-3 overflow-auto border-t border-seam bg-panel p-3 lg:border-l lg:border-t-0" data-editor-side="">
+ <section>
+ <h2 className="micro mb-1">
+ {plural(clips.length, "clip")} · {clips.filter((c) => c.ruling === "keep").length} kept · {clips.filter((c) => c.ruling === "cut").length} cut
+ </h2>
+ <ol className="m-0 list-none space-y-0.5 p-0" data-editor-list="">
+ {clips.map((c) => {
+ const cc = cutOf(c);
+ return (
+ <li key={c.id}>
+ <button
+ type="button"
+ data-editor-row={c.id}
+ aria-current={c.id === clip.id ? "true" : undefined}
+ onClick={() => choose(c.id)}
+ className={cn("flex w-full items-baseline gap-2 rounded-[3px] px-1.5 py-1 text-left text-[12px]", c.id === clip.id ? "bg-panel-2 text-text" : "text-text-2 hover:bg-panel-2")}
+ >
+ <span className="font-mono text-[11.5px]">{c.id}</span>
+ <span className="num font-mono text-[11px] text-muted">
+ {edgeClock(cc.cutStart)} · {(cc.cutEnd - cc.cutStart).toFixed(0)} s
+ </span>
+ <span className="ml-auto flex gap-1">
+ {c.assist?.by === "operator" && <span className={badgeVariants({ variant: "info", size: "sm" })}>you</span>}
+ {c.ruling && <span className={rulingBadge(c.ruling)}>{c.ruling}</span>}
+ </span>
+ </button>
+ </li>
+ );
+ })}
+ </ol>
+ </section>
+
+ {view.reactions && (
+ <section data-editor-proposals={view.reactions.proposals.length}>
+ <h2 className="micro mb-1">
+ Not in the cut — {plural(view.reactions.proposals.length, "proposal")} of {view.reactions.proposalCount}
+ </h2>
+ {view.reactions.proposals.length === 0 ? (
+ <p className="m-0 text-[12px] text-muted">Every proposal is in the cut.</p>
+ ) : (
+ <ul className="m-0 list-none space-y-1 p-0">
+ {view.reactions.proposals.map((p) => (
+ <li key={p.id} data-proposal={p.id} className="flex items-baseline gap-2 text-[12px] text-text-2">
+ <span className="font-mono text-[11.5px]">{p.id}</span>
+ <span className="num font-mono text-[11px] text-muted">
+ {edgeClock(p.start)} · {(p.end - p.start).toFixed(0)} s{typeof p.score === "number" ? ` · ${p.score.toFixed(2)}` : ""}
+ </span>
+ <span className="min-w-0 flex-1 truncate" title={p.why}>
+ {p.why}
+ </span>
+ <button type="button" data-bring-in={p.id} disabled={busy} onClick={() => bringIn(p)} className={buttonVariants({ size: "sm" })}>
+ Bring in
+ </button>
+ </li>
+ ))}
+ </ul>
+ )}
+ </section>
+ )}
+
+ {speakers.length > 0 && (
+ <section data-editor-speakers="">
+ <h2 className="micro mb-1">Speakers</h2>
+ <ul className="m-0 list-none space-y-1 p-0">
+ {speakers.map((s) => (
+ <li key={s.index} data-speaker={s.index} data-speaker-role={s.role ?? ""} className="flex items-center gap-2 text-[12px] text-text-2">
+ <span className={cn("inline-block h-2 w-3 rounded-[1px]", ROLE_FILL[s.role ?? "other"] ?? "bg-muted")} />
+ <span>
+ {s.index} · {s.role ? ROLE_WORD[s.role] : "no role"}
+ {s.how === "operator" ? " (you said)" : s.how === "auto" ? " (auto)" : ""}
+ </span>
+ <span className="num font-mono text-[11px] text-muted">{typeof s.seconds === "number" ? `${Math.round(s.seconds)} s` : ""}</span>
+ {s.role !== "host" && (
+ <button type="button" data-speaker-host={s.index} disabled={busy} onClick={() => setRole(s.index, "host")} className={cn(buttonVariants({ variant: "quiet", size: "sm" }), "ml-auto")}>
+ This is the host
+ </button>
+ )}
+ </li>
+ ))}
+ </ul>
+ </section>
+ )}
+ {view.reactionsError && <p className="m-0 text-[12px] text-reject-text">{view.reactionsError}</p>}
+ {view.rulingsError && <p className="m-0 text-[12px] text-reject-text">{view.rulingsError}</p>}
+
+ <RenderTake project={project} render={render} takes={takes} takesHref={takesHref} />
+ </aside>
+ </div>
+ );
+}
+
+// ---------------------------------------------------------------------------
+// The player: what /api/cited/play finds for the neighbourhood, else the
+// clip's extent, else its cut; loops the cut.
+// ---------------------------------------------------------------------------
+
+type PlayerHandle = { toggle: () => void; seek: (t: number) => void };
+type Target = { channel: string; video: string; from: number; to: number; project: string; clip: string };
+
+
+const Player = forwardRef<PlayerHandle, { targets: Target[]; cut: Cut; onTime: (t: number) => void; onPlaying: (p: boolean) => void }>(function Player({ targets, cut, onTime, onPlaying }, ref) {
+ const [found, setFound] = useState<{ play: CitedPlay; from: number } | null | undefined>(undefined);
+ const media = useRef<HTMLMediaElement | null>(null);
+ const cutRef = useRef(cut);
+ cutRef.current = cut;
+ const key = targets.map((t) => `${t.clip}|${t.from}|${t.to}`).join(",");
+
+ useEffect(() => {
+ let live = true;
+ setFound(undefined);
+ (async () => {
+ for (const t of targets) {
+ const q = new URLSearchParams({ channel: t.channel, video: t.video, from: String(t.from), to: String(t.to), project: t.project, clip: t.clip });
+ const r = await fetch(`/api/cited/play?${q}`, { cache: "no-store" }).catch(() => null);
+ const j = r?.ok ? ((await r.json()) as { play: CitedPlay | null }) : null;
+ if (j?.play) {
+ if (live) setFound({ play: j.play, from: t.from });
+ return;
+ }
+ }
+ if (live) setFound(null);
+ })();
+ return () => {
+ live = false;
+ };
+ // `targets` is named by its key.
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [key]);
+
+ const fileT = (t: number) => (found ? Math.max(0, t - found.from + found.play.offset) : 0);
+ const sourceT = (ft: number) => (found ? ft - found.play.offset + found.from : 0);
+
+ useImperativeHandle(ref, () => ({
+ toggle: () => {
+ const m = media.current;
+ if (!m) return;
+ if (!m.paused) return m.pause();
+ const t = sourceT(m.currentTime);
+ if (t < cutRef.current.cutStart - 0.05 || t >= cutRef.current.cutEnd - 0.05) m.currentTime = fileT(cutRef.current.cutStart);
+ void m.play().catch(() => {});
+ },
+ seek: (t: number) => {
+ const m = media.current;
+ if (m) m.currentTime = fileT(t);
+ },
+ }));
+
+ if (found === undefined) return <div data-editor-player="looking" className="flex aspect-video w-full max-w-[720px] items-center justify-center rounded-[3px] bg-panel-2 text-[12px] text-muted">looking for the clip…</div>;
+ if (found === null)
+ return (
+ <div data-editor-player="none" className="flex aspect-video w-full max-w-[720px] flex-col items-center justify-center gap-1 rounded-[3px] bg-panel-2 text-center text-[12px] text-muted">
+ <span>Nothing on disk plays this clip.</span>
+ <span>Fetch its window from the Cut tab (Fetch windows), then come back.</span>
+ </div>
+ );
+ const props = {
+ ref: (el: HTMLMediaElement | null) => {
+ media.current = el;
+ },
+ src: found.play.url,
+ preload: "auto",
+ "data-player": "",
+ tabIndex: -1,
+ controls: true,
+ onLoadedMetadata: (e: React.SyntheticEvent<HTMLMediaElement>) => {
+ e.currentTarget.currentTime = fileT(cutRef.current.cutStart);
+ },
+ onTimeUpdate: (e: React.SyntheticEvent<HTMLMediaElement>) => {
+ const t = sourceT(e.currentTarget.currentTime);
+ onTime(t);
+ // Loop the cut while it plays inside it.
+ if (!e.currentTarget.paused && t >= cutRef.current.cutEnd && t < cutRef.current.cutEnd + 0.6) e.currentTarget.currentTime = fileT(cutRef.current.cutStart);
+ },
+ onPlay: () => onPlaying(true),
+ onPause: () => onPlaying(false),
+ onFocus: (e: React.FocusEvent<HTMLMediaElement>) => e.currentTarget.blur(),
+ };
+ return (
+ <div data-editor-player={found.play.kind} className="w-full max-w-[720px]">
+ {found.play.audio ? <audio {...props} className="w-full" /> : <video {...props} playsInline className="aspect-video w-full rounded-[3px] bg-black" />}
+ <span className="micro">{found.play.label}</span>
+ </div>
+ );
+});
+
+// ---------------------------------------------------------------------------
+// The strip: [from, to] across the width. Turns by role, laughs, word ticks,
+// the other clips, the cut with two handles, the playhead, a selection.
+// ---------------------------------------------------------------------------
+
+function Strip({
+ from,
+ to,
+ cut,
+ hood,
+ speakers,
+ others,
+ playhead,
+ selection,
+ speakerPick,
+ onSeek,
+ onEdge,
+ onSelect,
+ onTurn,
+ onOther,
+}: {
+ from: number;
+ to: number;
+ cut: Cut;
+ hood: Neighbourhood | null;
+ speakers: Speaker[];
+ others: EditorClip[];
+ playhead: number | null;
+ selection: Cut | null;
+ speakerPick: number | null;
+ onSeek: (t: number) => void;
+ onEdge: (edge: "in" | "out", t: number, done: boolean) => void;
+ onSelect: (s: Cut | null) => void;
+ onTurn: (t: Turn) => void;
+ onOther: (id: string) => void;
+}) {
+ const box = useRef<HTMLDivElement | null>(null);
+ const span = Math.max(0.001, to - from);
+ const pct = (t: number) => `${(Math.min(Math.max(t, from), to) - from) / span * 100}%`;
+ const width = (a: number, b: number) => `${Math.max(0, Math.min(b, to) - Math.max(a, from)) / span * 100}%`;
+ const tAt = (clientX: number) => {
+ const r = box.current!.getBoundingClientRect();
+ return r2(from + ((clientX - r.left) / Math.max(1, r.width)) * span);
+ };
+ const drag = useRef<{ kind: "in" | "out" | "select"; x0: number; t0: number } | null>(null);
+
+ const down = (kind: "in" | "out" | "select") => (e: React.PointerEvent) => {
+ if (e.button !== 0) return;
+ e.stopPropagation();
+ (e.currentTarget as HTMLElement).setPointerCapture(e.pointerId);
+ drag.current = { kind, x0: e.clientX, t0: tAt(e.clientX) };
+ };
+ const move = (e: React.PointerEvent) => {
+ const d = drag.current;
+ if (!d) return;
+ const t = tAt(e.clientX);
+ if (d.kind === "select") {
+ if (Math.abs(e.clientX - d.x0) > 4) onSelect({ cutStart: Math.min(d.t0, t), cutEnd: Math.max(d.t0, t) });
+ } else onEdge(d.kind, t, false);
+ };
+ const up = (e: React.PointerEvent) => {
+ const d = drag.current;
+ drag.current = null;
+ if (!d) return;
+ const t = tAt(e.clientX);
+ if (d.kind === "select") {
+ if (Math.abs(e.clientX - d.x0) <= 4) {
+ onSelect(null);
+ onSeek(t);
+ } else if (Math.abs(t - d.t0) < 0.5) onSelect(null);
+ } else onEdge(d.kind, t, true);
+ };
+
+ const turns = hood?.turns ?? [];
+ const role = (sp: number) => roleOf(speakers, sp);
+ return (
+ <div
+ ref={box}
+ data-strip={`${from}-${to}`}
+ onPointerDown={down("select")}
+ onPointerMove={move}
+ onPointerUp={up}
+ className="relative h-[86px] w-full touch-none select-none overflow-hidden rounded-[3px] border border-seam bg-panel-2"
+ >
+ {/* turns, top lane */}
+ {turns.map((t, i) => {
+ const r = role(t.speaker);
+ return (
+ <button
+ key={i}
+ type="button"
+ data-turn={i}
+ data-turn-speaker={t.speaker}
+ data-turn-role={r ?? ""}
+ title={`speaker ${t.speaker}${r ? ` · ${ROLE_WORD[r] ?? r}` : ""} · ${edgeClock(t.start)}–${edgeClock(t.end)}`}
+ onPointerDown={(e) => e.stopPropagation()}
+ onClick={() => onTurn(t)}
+ style={{ left: pct(t.start), width: width(t.start, t.end) }}
+ className={cn(
+ "absolute top-1 h-4 rounded-[1px] opacity-80 hover:opacity-100",
+ r ? ROLE_FILL[r] ?? "bg-muted" : "bg-muted",
+ speakerPick === t.speaker && "outline outline-1 outline-text",
+ r === "subject" && "top-6",
+ )}
+ />
+ );
+ })}
+ {/* laughs */}
+ {(hood?.laughs ?? []).map((l, i) => (
+ <span key={i} data-laugh={i} title={`laugh${l.score !== null ? ` · ${l.score.toFixed(2)}` : ""}`} style={{ left: pct(l.start), width: width(l.start, l.end) }} className="pointer-events-none absolute top-[44px] h-2 min-w-[3px] rounded-[1px] bg-doubt" />
+ ))}
+ {/* word ticks */}
+ {(hood?.words ?? hood?.cues ?? []).map((w, i) => (
+ <span key={i} style={{ left: pct(w.start) }} className="pointer-events-none absolute bottom-1 h-2 w-px bg-muted-2 opacity-60" />
+ ))}
+ {/* the other clips */}
+ {others.map((c) => {
+ const cc = cutOf(c);
+ if (cc.cutEnd < from || cc.cutStart > to) return null;
+ return (
+ <button
+ key={c.id}
+ type="button"
+ data-other-clip={c.id}
+ title={`${c.id} — open it`}
+ onPointerDown={(e) => e.stopPropagation()}
+ onClick={() => onOther(c.id)}
+ style={{ left: pct(cc.cutStart), width: width(cc.cutStart, cc.cutEnd) }}
+ className="absolute bottom-0 h-[14px] rounded-t-[2px] border border-b-0 border-seam-2 bg-[color-mix(in_srgb,var(--text)_8%,transparent)] font-mono text-[9px] text-muted"
+ >
+ {c.id}
+ </button>
+ );
+ })}
+ {/* the selection to add */}
+ {selection && <span data-selection={`${selection.cutStart}-${selection.cutEnd}`} style={{ left: pct(selection.cutStart), width: width(selection.cutStart, selection.cutEnd) }} className="pointer-events-none absolute inset-y-0 border-x border-dashed border-text bg-[color-mix(in_srgb,var(--text)_10%,transparent)]" />}
+ {/* the cut */}
+ <span data-strip-cut="" style={{ left: pct(cut.cutStart), width: width(cut.cutStart, cut.cutEnd) }} className="pointer-events-none absolute inset-y-0 border-y-2 border-signal bg-[color-mix(in_srgb,var(--signal)_14%,transparent)]" />
+ {(["in", "out"] as const).map((edge) => (
+ <span
+ key={edge}
+ role="slider"
+ aria-label={edge === "in" ? "In point" : "Out point"}
+ aria-valuemin={from}
+ aria-valuemax={to}
+ aria-valuenow={edge === "in" ? cut.cutStart : cut.cutEnd}
+ data-handle={edge}
+ onPointerDown={down(edge)}
+ style={{ left: pct(edge === "in" ? cut.cutStart : cut.cutEnd) }}
+ className="absolute inset-y-0 z-10 w-3 -translate-x-1/2 cursor-ew-resize"
+ >
+ <span className="absolute inset-y-0 left-1/2 w-[3px] -translate-x-1/2 rounded bg-signal" />
+ </span>
+ ))}
+ {playhead !== null && playhead >= from && playhead <= to && <span data-playhead={playhead} style={{ left: pct(playhead) }} className="pointer-events-none absolute inset-y-0 w-px bg-text" />}
+ </div>
+ );
+}
+
+/** The words of the neighbourhood as text: the cut's lit, the one playing marked; a click seeks there. */
+function Words({ hood, cut, playhead, onSeek }: { hood: Neighbourhood | null; cut: Cut; playhead: number | null; onSeek: (t: number) => void }) {
+ if (!hood) return <p className="m-0 text-[12px] text-muted">reading the words…</p>;
+ const list = hood.words?.length ? hood.words.map((w) => ({ text: w.w, start: w.start, end: w.end })) : (hood.cues ?? []).map((c) => ({ text: c.text, start: c.start, end: c.end }));
+ if (!list.length) return <p className="m-0 text-[12px] text-muted">No words or cues for this span.</p>;
+ return (
+ <p data-editor-words={hood.words?.length ? "words" : "cues"} className="m-0 max-h-[9.5em] overflow-auto text-[13px] leading-relaxed text-muted">
+ {list.map((w, i) => {
+ const mid = (w.start + w.end) / 2;
+ const inCut = mid >= cut.cutStart && mid <= cut.cutEnd;
+ const now = playhead !== null && playhead >= w.start && playhead < w.end;
+ return (
+ <span key={i}>
+ <button
+ type="button"
+ data-word={i}
+ data-word-t={w.start}
+ data-in-cut={inCut ? "" : undefined}
+ onMouseDown={(e) => e.preventDefault()}
+ onClick={() => onSeek(w.start)}
+ className={cn("rounded-[2px] px-[1px] hover:bg-panel-2", inCut && "text-text", now && "bg-[color-mix(in_srgb,var(--signal)_30%,transparent)]")}
+ >
+ {w.text}
+ </button>{" "}
+ </span>
+ );
+ })}
+ </p>
+ );
+}
+
+function EdgeControl({ edge, value, onNudge, onSet, onPlayhead }: { edge: "in" | "out"; value: number; onNudge: (d: number) => void; onSet: (v: number) => void; onPlayhead: (() => void) | null }) {
+ const [text, setText] = useState(String(value));
+ useEffect(() => setText(String(value)), [value]);
+ const commit = () => {
+ const v = Number(text);
+ if (Number.isFinite(v) && v !== value) onSet(v);
+ else setText(String(value));
+ };
+ return (
+ <div data-edge={edge} className="flex flex-wrap items-center gap-1 rounded-[3px] border border-seam bg-panel p-2">
+ <label className="micro mr-1" htmlFor={`edge-${edge}`}>
+ {edge === "in" ? "In" : "Out"}
+ </label>
+ <input
+ id={`edge-${edge}`}
+ data-edge-input={edge}
+ type="number"
+ step={0.01}
+ min={0}
+ value={text}
+ onChange={(e) => setText(e.target.value)}
+ onBlur={commit}
+ onKeyDown={(e) => {
+ if (e.key === "Enter") {
+ commit();
+ (e.target as HTMLInputElement).blur();
+ }
+ if (e.key === "Escape") {
+ setText(String(value));
+ (e.target as HTMLInputElement).blur();
+ }
+ }}
+ className="num w-[6.5em] rounded border border-seam-2 bg-ground px-1.5 py-0.5 font-mono text-[12px] text-text outline-none focus:border-signal"
+ />
+ {NUDGES.map((d) => (
+ <button key={d} type="button" data-nudge={`${edge}:${d}`} onMouseDown={(e) => e.preventDefault()} onClick={() => onNudge(d)} className={buttonVariants({ variant: "quiet", size: "sm" })}>
+ {d > 0 ? `+${d}` : `−${Math.abs(d)}`}
+ </button>
+ ))}
+ <button type="button" data-edge-playhead={edge} disabled={!onPlayhead} onMouseDown={(e) => e.preventDefault()} onClick={() => onPlayhead?.()} className={buttonVariants({ variant: "quiet", size: "sm" })} title="set at the playhead">
+ at playhead <kbd>{edge === "in" ? "I" : "O"}</kbd>
+ </button>
+ </div>
+ );
+}
+
+/** The notes on one clip: its thread (an agent's replies too), resolve / reopen, a box for another. */
+function ClipNotes({ project, clipId }: { project: string; clipId: string }) {
+ const notes = useSharedNotes({ project });
+ const [text, setText] = useState("");
+ const mine = notesOn(notes.notes, { kind: "entry", entry: clipId }).filter((n) => n.anchor.kind !== "moment");
+ const open = mine.filter((n) => n.status === "open").length;
+ const add = async () => {
+ if (!text.trim()) return;
+ const n = await notes.write({ op: "add", text, anchor: { kind: "entry", entry: clipId } });
+ if (n) setText("");
+ };
+ return (
+ <section data-clip-notes={clipId} data-open-notes={open} className="space-y-1.5 rounded-[3px] border border-seam bg-panel p-2.5">
+ <h2 className="micro m-0">Comments{mine.length ? ` — ${open} open of ${mine.length}` : ""}</h2>
+ {mine.map((n) => (
+ <NoteThread key={n.id} note={n} write={notes.write} busy={notes.busy} head={n.anchor.kind === "edit" ? <span className={badgeVariants({ variant: "info", size: "sm" })}>edit · {n.anchor.field}</span> : null} />
+ ))}
+ <div className="flex flex-wrap items-start gap-2">
+ <textarea
+ data-clip-note-input=""
+ value={text}
+ rows={2}
+ onChange={(e) => setText(e.target.value)}
+ onKeyDown={(e) => {
+ if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) void add();
+ if (e.key === "Escape") (e.target as HTMLTextAreaElement).blur();
+ }}
+ placeholder={`a comment on ${clipId} — for you or the assistant`}
+ className="min-w-[16rem] flex-1 resize-y rounded border border-seam-2 bg-ground px-1.5 py-1 text-[12.5px] text-text outline-none focus:border-signal"
+ />
+ <button type="button" data-clip-note-add="" disabled={notes.busy || !text.trim()} onClick={() => void add()} className={buttonVariants({ size: "md" })}>
+ Add comment
+ </button>
+ </div>
+ {notes.error && <div className="text-[12px] text-reject-text">{notes.error}</div>}
+ </section>
+ );
+}
+
+/** Render a take: the picked (or the whole-cut) take made again, else the Takes page. */
+function RenderTake({ project, render, takes, takesHref }: { project: string; render: RenderTarget; takes: number; takesHref: string }) {
+ const [job, setJob] = useState<{ id: string; state: string; error: string | null } | null>(null);
+ const [err, setErr] = useState<string | null>(null);
+ useEffect(() => {
+ if (!job || job.state !== "running") return;
+ const t = setInterval(async () => {
+ const r = await fetch(`/api/report/takes/make?job=${job.id}`, { cache: "no-store" }).catch(() => null);
+ if (!r?.ok) return;
+ const j = (await r.json()) as { id: string; state: string; error: string | null };
+ setJob({ id: j.id, state: j.state, error: j.error });
+ }, 1500);
+ return () => clearInterval(t);
+ }, [job]);
+ const remake = async () => {
+ if (!render) return;
+ setErr(null);
+ const r = await startTakeJob({ project, rebuild: render.take });
+ if (r.error || !r.job) setErr(r.error ?? "the take did not start");
+ else setJob({ id: r.job.id, state: r.job.state, error: r.job.error });
+ };
+ return (
+ <section data-editor-render="" className="space-y-1.5">
+ <h2 className="micro m-0">Render</h2>
+ {render ? (
+ <button type="button" data-render-take={render.take} disabled={job?.state === "running"} onClick={() => void remake()} className={buttonVariants({ variant: "go", size: "md" })}>
+ Render the take again — {render.label}
+ </button>
+ ) : (
+ <Link href={takesHref} prefetch={false} data-render-takes="" className={buttonVariants({ variant: "go", size: "md" })}>
+ {takes ? "Choose a take to render" : "Make a take"}
+ </Link>
+ )}
+ {job && (
+ <p data-render-job={job.state} className="m-0 text-[12px] text-text-2">
+ {job.state === "running" ? "Rendering" : job.state === "done" ? "Rendered" : `Failed${job.error ? `: ${job.error}` : ""}`} —{" "}
+ <Link href={takesHref} prefetch={false} className="ink-link">
+ the Takes page
+ </Link>
+ </p>
+ )}
+ {err && (
+ <p role="alert" className="m-0 text-[12px] text-reject-text">
+ {err}
+ </p>
+ )}
+ </section>
+ );
+}
diff --git a/umtool/lib/hrefs.ts b/umtool/lib/hrefs.ts
@@ -287,6 +287,15 @@ export function clipDeckHref(project: string, q: NoteOpt & { show?: ClipDeckShow
return withQuery(`/projects/${encodePath(project)}/clips`, q.show ? { show: q.show } : {}, q.note);
}
+/**
+ * The clip editor (release 35 C2): the same address as the deck. A cut with
+ * no montage opens it; `mode: "edit"` opens it on a montage too; `clip`
+ * selects one clip.
+ */
+export function clipEditorHref(project: string, q: NoteOpt & { clip?: string; mode?: "edit" } = {}): string {
+ return withQuery(`/projects/${encodePath(project)}/clips`, { ...(q.mode ? { mode: q.mode } : {}), ...(q.clip ? { clip: q.clip } : {}) }, q.note);
+}
+
/** The narration script, card by card. */
export function narrationHref(project: string, q: NoteOpt = {}): string {
return withQuery(`/projects/${encodePath(project)}/narration`, {}, q.note);