commit d2d51b0eeee4604f8d09b8a015efb1db37088126
parent fb05feb90a584885a58eeab6e97746fc7b13bf36
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Wed, 14 Oct 2026 05:53:02 -0400
umtool: the piece page frame for a report video — head, stage stepper, lifecycle chip, ⋯, Next card, seven link tabs; ReportProject's sections moved unchanged into them
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
25 files changed, 1798 insertions(+), 853 deletions(-)
diff --git a/umtool/app/page.tsx b/umtool/app/page.tsx
@@ -11,6 +11,7 @@ import { homeHref, systemHref } from "@/lib/hrefs";
import { readInbox, type GroupCard, type GroupSummary } from "@/lib/inbox";
import { summarizeGroups } from "@/lib/inbox/groups.mjs";
import { headlineNote, inboxHeadline } from "@/lib/inbox/headline.mjs";
+import { whatOf } from "@/lib/inbox/what.mjs";
import { KINDS } from "@/lib/projects";
import type { Decision } from "@/lib/decisions";
import type { LifecycleState } from "@/lib/lifecycle";
@@ -35,47 +36,6 @@ export const dynamic = "force-dynamic";
// each with Unmute.
// ---------------------------------------------------------------------------
-/** What a decision kind is, in a few words after the piece's title. */
-const WHAT: Record<string, string> = {
- "research-proposal": "research proposal",
- "iteration-failed": "run failed",
- "iteration-ready": "iteration ready",
- "drafts-unreviewed": "drafts to review",
- "open-note": "open notes",
- "unreadable-notes": "notes.json does not read",
- "link-ambiguous": "video not linked",
- "looks-done": "looks done",
- "claim-unadjudicated": "claims never ruled",
- "claim-incoherent": "claims that don't hold together",
- "clip-no-cues": "clips with no cues",
- "clip-unfetchable": "clips can't be fetched",
- "clip-mid-sentence": "clips end mid-sentence",
- "clip-cue-gap": "clips over a cue gap",
- "clip-cut-outside": "cuts outside the window",
- "window-overlap": "windows overlap",
- "no-punctuation": "windows without punctuation",
- "manifest-invalid": "manifest invalid",
- "stale-build": "video out of date",
- unbuilt: "never built",
- "storage-unreachable": "media drive unreachable",
- "storage-mismatch": "storage disagrees",
- "unjudged-variant": "variants not judged",
- "missing-cut": "cuts missing",
- "stale-recipe": "recipes out of date",
- "no-recipe": "no recipe",
- "spec-problem": "spec problem",
- "no-plan": "plans unnamed",
- unattributed: "variants unattributed",
- "thumb-unaccepted": "no cover accepted",
- loudness: "loudness off target",
- "shadowed-name": "no address of its own",
- "unroutable-name": "no address of its own",
- "ambiguous-project": "two kinds match",
- "machine-tool": "a required tool is missing",
- "machine-disk": "disk nearly full",
-};
-const whatOf = (kind: string) => WHAT[kind] ?? kind.replace(/-/g, " ");
-
const GROUP_NOTE: Record<string, string> = {
"your-call": "spend or failed runs",
blocking: "active pieces only",
diff --git a/umtool/components/piece/LifecycleChip.tsx b/umtool/components/piece/LifecycleChip.tsx
@@ -0,0 +1,34 @@
+"use client";
+
+import { LifecycleButton, type LifecycleState } from "@/components/dashboard/Lifecycle";
+import { badgeVariants } from "@/components/ui/badge";
+import { cn } from "@/lib/utils";
+import Menu from "./Menu";
+
+// The piece's lifecycle in its head (canvas "Piece · Overview", `Active ▾`):
+// the state as a chip, and the moves out of it -- Park and Mark done while it
+// is active, Reactivate (and Mark done) while it is parked, Reactivate once it
+// is done. The same POST and Undo bar as the Inbox's (components/dashboard/
+// Lifecycle.tsx); the page re-reads on a change.
+
+const WORD: Record<LifecycleState, string> = { active: "Active", parked: "Parked", done: "Done" };
+
+export default function LifecycleChip({ piece, title, state }: { piece: string; title: string; state: LifecycleState }) {
+ return (
+ <Menu
+ data-lifecycle-chip={state}
+ data-piece={piece}
+ trigger={
+ <>
+ {WORD[state]} <span aria-hidden="true">▾</span>
+ </>
+ }
+ label={`Lifecycle: ${WORD[state]}`}
+ triggerClassName={cn(badgeVariants({ variant: state === "active" ? "neutral" : "on", size: "md" }), "cursor-pointer disabled:opacity-60")}
+ >
+ {state !== "active" && <LifecycleButton piece={piece} title={title} from={state} to="active" label="Reactivate" variant="quiet" size="md" className="justify-start" />}
+ {state === "active" && <LifecycleButton piece={piece} title={title} from={state} to="parked" label="Park" variant="quiet" size="md" className="justify-start" />}
+ {state !== "done" && <LifecycleButton piece={piece} title={title} from={state} to="done" label="Mark done" variant="quiet" size="md" className="justify-start" />}
+ </Menu>
+ );
+}
diff --git a/umtool/components/piece/Menu.tsx b/umtool/components/piece/Menu.tsx
@@ -0,0 +1,71 @@
+"use client";
+
+import { useEffect, useRef, useState } from "react";
+import { useHydrated } from "@/components/ui/use-hydrated";
+import { cn } from "@/lib/utils";
+
+// A small menu under a trigger in a piece's head: the lifecycle chip's and the
+// ⋯ menu's. A panel below the trigger, right-aligned; Escape, a click away, or
+// a lifecycle change (the `umtool:lifecycle` event a LifecycleButton sends)
+// closes it. The trigger is disabled until hydration, the house rule: a press
+// before React is listening opens nothing.
+export default function Menu({
+ trigger,
+ label,
+ className,
+ triggerClassName,
+ children,
+ ...props
+}: {
+ trigger: React.ReactNode;
+ /** The trigger's accessible name when its text is not one ("More" for ⋯). */
+ label?: string;
+ className?: string;
+ triggerClassName?: string;
+ children: React.ReactNode;
+} & Omit<React.ComponentProps<"div">, "children">) {
+ const hydrated = useHydrated();
+ const [open, setOpen] = useState(false);
+ const ref = useRef<HTMLDivElement>(null);
+ useEffect(() => {
+ if (!open) return;
+ const away = (e: MouseEvent) => {
+ if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false);
+ };
+ const key = (e: KeyboardEvent) => {
+ if (e.key === "Escape") setOpen(false);
+ };
+ const changed = () => setOpen(false);
+ document.addEventListener("mousedown", away);
+ document.addEventListener("keydown", key);
+ window.addEventListener("umtool:lifecycle", changed);
+ return () => {
+ document.removeEventListener("mousedown", away);
+ document.removeEventListener("keydown", key);
+ window.removeEventListener("umtool:lifecycle", changed);
+ };
+ }, [open]);
+ return (
+ <div ref={ref} className={cn("relative", className)} {...props}>
+ <button
+ type="button"
+ disabled={!hydrated}
+ aria-expanded={open}
+ aria-haspopup="true"
+ aria-label={label}
+ onClick={() => setOpen((v) => !v)}
+ className={triggerClassName}
+ >
+ {trigger}
+ </button>
+ {open && (
+ <div
+ data-menu-panel=""
+ className="absolute right-0 top-[calc(100%+4px)] z-30 flex min-w-[200px] flex-col items-stretch gap-0.5 rounded-[3px] border border-seam-2 bg-panel-2 p-1.5 shadow-lg"
+ >
+ {children}
+ </div>
+ )}
+ </div>
+ );
+}
diff --git a/umtool/components/piece/NextCard.tsx b/umtool/components/piece/NextCard.tsx
@@ -0,0 +1,73 @@
+import Link from "next/link";
+import { LifecycleButton } from "@/components/dashboard/Lifecycle";
+import { buttonVariants } from "@/components/ui/button";
+import { Card } from "@/components/ui/panel";
+import { readNextCall } from "@/lib/pieces/frame";
+import type { LifecycleState } from "@/lib/lifecycle";
+
+// THE NEXT CARD (canvas "Piece · Overview", `.nextcard`): the piece's top call
+// from the Inbox -- the same ranking, the same one action -- with the Signal
+// edge, and `n` runs it (components/piece/PieceKeys.tsx). A parked or done
+// piece's next move is Reactivate. Nothing waiting says so, with no button.
+//
+// Async: the Inbox is read whole (lib/inbox) and then narrowed, so the page
+// streams this in under a <Suspense> rather than waiting on it.
+
+export function NextCardShell({ children }: { children: React.ReactNode }) {
+ return (
+ <Card lit data-next="" className="grid grid-cols-[minmax(0,1fr)_auto] items-center gap-x-[18px] gap-y-1 px-4 py-3.5">
+ <span className="micro col-span-full">Next</span>
+ {children}
+ </Card>
+ );
+}
+
+export default async function NextCard({ pieceId, title, lifecycle }: { pieceId: string; title: string; lifecycle: LifecycleState }) {
+ const next = await readNextCall(pieceId, lifecycle).catch(() => null);
+ if (!next) {
+ return (
+ <NextCardShell>
+ <div data-next-kind="none">
+ <b className="text-[15px] font-semibold">Nothing waiting on you</b>
+ <small className="block text-[12.5px] text-muted">no call on this piece in the Inbox</small>
+ </div>
+ </NextCardShell>
+ );
+ }
+ return (
+ <NextCardShell>
+ <div className="min-w-0" data-next-kind={next.kind} data-next-group={next.group}>
+ <b className="text-[15px] font-semibold first-letter:uppercase inline-block">{next.what}</b>
+ {next.count > 1 && (
+ <span className="ml-2 font-mono text-[12.5px] text-meter" data-next-count={next.count}>
+ {next.count}
+ </span>
+ )}
+ <small className="block truncate text-[12.5px] text-muted">
+ {next.why}
+ {next.more > 0 && ` · then ${next.more} more call${next.more === 1 ? "" : "s"}`}
+ </small>
+ </div>
+ <span className="flex items-center gap-2.5">
+ <kbd title="runs it">n</kbd>
+ <span data-next-action="">
+ {next.lifecycleTo ? (
+ <LifecycleButton
+ piece={pieceId}
+ title={title}
+ from={lifecycle}
+ to={next.lifecycleTo}
+ label={next.action.label}
+ variant="go"
+ size="md"
+ />
+ ) : (
+ <Link href={next.action.href} prefetch={false} className={buttonVariants({ variant: "go", size: "md" })}>
+ {next.action.label}
+ </Link>
+ )}
+ </span>
+ </span>
+ </NextCardShell>
+ );
+}
diff --git a/umtool/components/piece/PieceFrame.tsx b/umtool/components/piece/PieceFrame.tsx
@@ -0,0 +1,103 @@
+import Link from "next/link";
+import { UndoBar } from "@/components/dashboard/Lifecycle";
+import AppShell from "@/components/shell/AppShell";
+import { buttonVariants } from "@/components/ui/button";
+import { Stepper } from "@/components/ui/stepper";
+import { Tabs, type TabItem } from "@/components/ui/tabs";
+import { articleHref, projectHref, projectsHref } from "@/lib/hrefs";
+import { PIECE_TABS } from "@/lib/pieces/tabs.mjs";
+import type { PieceFrame as Frame } from "@/lib/pieces/frame";
+import LifecycleChip from "./LifecycleChip";
+import Menu from "./Menu";
+import PieceKeys from "./PieceKeys";
+
+// ---------------------------------------------------------------------------
+// THE PIECE PAGE's frame (plans/umtool-redesign.md, P4a-1; canvas "Piece ·
+// Overview"): the head -- the trail, the piece's title, the lifecycle chip and
+// the ⋯ menu, the page's status line, the stage stepper -- then the tabs, as
+// links (`?tab=`, lib/pieces/tabs.mjs), then the tab's own body.
+//
+// Kind-blind: the report-video page (components/projects/ReportProject.tsx)
+// hands it the title, the counts and the body. `1`–`7` open the tabs and `n`
+// runs the Next card's action (PieceKeys).
+// ---------------------------------------------------------------------------
+
+export default function PieceFrame({
+ project,
+ title,
+ frame,
+ tab,
+ counts,
+ note,
+ more,
+ children,
+}: {
+ project: string;
+ title: string;
+ frame: Frame;
+ /** The tab on show. */
+ tab: string;
+ /** A count beside a tab's name, in Meter (Cut: clips, Media: drafted fields, Sources: recordings). */
+ counts: Partial<Record<string, number>>;
+ /** The page's one-line status, the head's last `.micro`. */
+ note?: React.ReactNode;
+ /** The ⋯ menu's items (Delete project …). */
+ more?: React.ReactNode;
+ children: React.ReactNode;
+}) {
+ const hrefs = PIECE_TABS.map((t) => projectHref(project, { tab: t.id }));
+ const items: TabItem[] = PIECE_TABS.map((t, i) => ({
+ href: hrefs[i],
+ label: t.label,
+ current: t.id === tab,
+ count: counts[t.id] ? counts[t.id] : undefined,
+ testid: `piece-tab-${t.id}`,
+ }));
+ const { article, piece } = frame;
+ return (
+ <>
+ <AppShell
+ active="work"
+ crumbs={[{ href: projectsHref(), label: "projects" }, { label: project }, { label: title }]}
+ note={note}
+ actions={
+ <>
+ {piece && <LifecycleChip piece={frame.pieceId} title={piece.title} state={frame.lifecycle} />}
+ {more && (
+ <Menu
+ data-piece-more=""
+ label="More"
+ trigger={<span aria-hidden="true">⋯</span>}
+ triggerClassName={buttonVariants({ variant: "quiet", size: "md" })}
+ >
+ {more}
+ </Menu>
+ )}
+ </>
+ }
+ below={
+ <div className="flex flex-wrap items-center gap-x-6 gap-y-2" data-piece={frame.pieceId} data-piece-stage={frame.stage} data-piece-lifecycle={frame.lifecycle}>
+ <Stepper steps={frame.steps} />
+ {article && (
+ <span className="text-[12.5px] text-muted" data-piece-article={`${article.site}/${article.report}`}>
+ a video of{" "}
+ <Link href={articleHref({ site: article.site, id: article.report })} prefetch={false} className="ink-link">
+ {article.title}
+ </Link>
+ </span>
+ )}
+ </div>
+ }
+ />
+ {frame.lifecycleError && (
+ <p role="alert" className="px-4 pt-2 text-[12.5px] text-reject-text">
+ {frame.lifecycleError} — every piece reads as active until it is fixed.
+ </p>
+ )}
+ <Tabs label="Piece" items={items} className="px-4" data-piece-tabs={tab} />
+ <PieceKeys tabs={hrefs} />
+ {children}
+ <UndoBar />
+ </>
+ );
+}
diff --git a/umtool/components/piece/PieceKeys.tsx b/umtool/components/piece/PieceKeys.tsx
@@ -0,0 +1,49 @@
+"use client";
+
+import { useRouter } from "next/navigation";
+import { useEffect, useState } from "react";
+
+// A piece page's keys: `1`–`7` open the tabs, in order; `n` runs the Next
+// card's action (the one control under `[data-next-action]`). Bound only after
+// hydration -- the house rule's "disabled until hydrated", for a key -- and
+// `data-piece-keys="ready"` says so to a spec.
+//
+// A key is the page's only when nobody else wants it: not while typing (an
+// input, a textarea, a select, anything editable), not on a focused <video>
+// (`n` there is a timed note, components/notes/TimedNotes.tsx), not inside an
+// open dialog or menu, never with a modifier, and never when a handler before
+// this one took it.
+function isOurs(e: KeyboardEvent): boolean {
+ if (e.defaultPrevented || e.metaKey || e.ctrlKey || e.altKey) return false;
+ const t = e.target as HTMLElement | null;
+ if (!t || !(t instanceof HTMLElement)) return true;
+ if (/^(INPUT|TEXTAREA|SELECT|VIDEO|AUDIO)$/.test(t.tagName) || t.isContentEditable) return false;
+ if (t.closest("dialog[open], [role=dialog], [data-menu-panel]")) return false;
+ return true;
+}
+
+export default function PieceKeys({ tabs }: { tabs: string[] }) {
+ const router = useRouter();
+ const [ready, setReady] = useState(false);
+ useEffect(() => {
+ const onKey = (e: KeyboardEvent) => {
+ if (!isOurs(e)) return;
+ const n = Number(e.key);
+ if (Number.isInteger(n) && n >= 1 && n <= tabs.length) {
+ e.preventDefault();
+ router.push(tabs[n - 1]);
+ return;
+ }
+ if (e.key === "n") {
+ const act = document.querySelector<HTMLElement>("[data-next-action] > a, [data-next-action] > button");
+ if (!act || (act instanceof HTMLButtonElement && act.disabled)) return;
+ e.preventDefault();
+ act.click();
+ }
+ };
+ document.addEventListener("keydown", onKey);
+ setReady(true);
+ return () => document.removeEventListener("keydown", onKey);
+ }, [router, tabs]);
+ return <span hidden data-piece-keys={ready ? "ready" : "waiting"} />;
+}
diff --git a/umtool/components/projects/ReportProject.tsx b/umtool/components/projects/ReportProject.tsx
@@ -1,75 +1,47 @@
-import { readdir, readFile } from "node:fs/promises";
import path from "node:path";
-import Link from "next/link";
import BrowseHeader from "@/components/BrowseHeader";
-import CopyButton from "@/components/CopyButton";
-import CheckSourcesButton from "@/components/dashboard/CheckSourcesButton";
-import { fmtAgo, fmtBytes } from "@/lib/format";
-import { Markdown } from "@/lib/markdown";
-import {
- correctionsOf,
- readClipDetail,
- reviewOf,
- sourcesOf,
- unfetchedNeedingJudgement,
- walkReadiness,
-} from "@/lib/projects/report.mjs";
-import { EXPORT_FORMATS, exportableVariants } from "@/lib/report/export.mjs";
-import { diffManifests, formatChange } from "@/lib/report/manifest-diff.mjs";
-import { listSnapshots, readSnapshot } from "@/lib/report/snapshots.mjs";
-import { listTakes } from "@/lib/report/takes.mjs";
-import { podcastFor } from "@/lib/report/serve.mjs";
-import { narrationsOf } from "umtool-report-to-video/narration";
-import { draftedFields, isCodeDraft } from "yt-dlp-transcript-common/lib/report/drafted.mjs";
-import { readAlternatives } from "@/lib/report/drafts.mjs";
-import DeliverSection from "./DeliverSection";
-import DraftPanel from "./DraftPanel";
-import { draftRowsOf, draftRuns, projectIteration } from "@/lib/articles/projectDraft";
-import FetchUnfetchedButton from "./FetchUnfetchedButton";
-import OnscreenSection from "./OnscreenSection";
-import PodcastExport from "./PodcastExport";
-import ReportBuildChain from "./ReportBuildChain";
-import SnapshotButton from "./SnapshotButton";
-import DeleteProject from "./DeleteProject";
-import TagCitedButton from "./TagCitedButton";
-import YoutubeSection from "./YoutubeSection";
-import { RowControls, RowNotes, TimelineList } from "./TimelineEditor";
import GeneratedBanner from "@/components/notes/GeneratedBanner";
import { NotesProvider } from "@/components/notes/NotesProvider";
-import { decisionsForProject } from "@/lib/projects";
-import { badgeVariants, type BadgeVariants } from "@/components/ui/badge";
-import { buttonVariants } from "@/components/ui/button";
-import type { Severity } from "@/lib/decisions";
+import PieceFrame from "@/components/piece/PieceFrame";
+import { readNotes } from "@/lib/annotations/store.mjs";
+import { readPieceFrame } from "@/lib/pieces/frame";
+import { tabOf, tabOfNoteAnchor } from "@/lib/pieces/tabs.mjs";
+import { channelFor, clipsOf, readClipDetail } from "@/lib/projects/report.mjs";
+import { draftedFields, isCodeDraft } from "yt-dlp-transcript-common/lib/report/drafted.mjs";
import type { ProjectRef } from "@/lib/project-types";
+import DeleteProject from "./DeleteProject";
+import BuildTab from "./report/BuildTab";
+import CutTab from "./report/CutTab";
+import DeliverTab from "./report/DeliverTab";
+import HistoryTab from "./report/HistoryTab";
+import MediaTab from "./report/MediaTab";
+import OverviewTab from "./report/OverviewTab";
+import SourcesTab from "./report/SourcesTab";
+import { hms } from "./report/shared";
// ---------------------------------------------------------------------------
-// A report video, as a page.
+// A report video, as a PIECE PAGE (plans/umtool-redesign.md, P4a-1).
//
// The manifest IS the cut -- array order, absolute source seconds, one entry per
// clip -- so the page is the timeline, read back. What it adds is the three
// things the JSON cannot show you: whether each clip's material is actually on
// disk, whether its window ends where a sentence does, and what the widener
// would do to it if you ran it.
+//
+// Since P4a-1 the page is the piece frame (components/piece/PieceFrame.tsx:
+// head, stage stepper, lifecycle, tabs) around ONE tab, and the sections it
+// drew top to bottom live in the tabs (components/projects/report/*), moved
+// unchanged. Which section is on which tab is lib/pieces/tabs.mjs SECTION_TAB.
+// Only the tab on show is read: the Sources tab's cue reads, the History tab's
+// snapshot diffs and the Deliver tab's exports cost nothing on the Overview.
// ---------------------------------------------------------------------------
-const hms = (t: number) => {
- const s = Math.max(0, Math.floor(t));
- const h = Math.floor(s / 3600);
- const m = Math.floor((s % 3600) / 60);
- const sec = s % 60;
- return h > 0
- ? `${h}:${String(m).padStart(2, "0")}:${String(sec).padStart(2, "0")}`
- : `${m}:${String(sec).padStart(2, "0")}`;
-};
-
-const TONE: Record<Severity, BadgeVariants["variant"]> = {
- blocking: "blocking",
- open: "open",
- info: "info",
-};
-
-function Pill({ tone, children }: { tone?: BadgeVariants["variant"]; children: React.ReactNode }) {
- return <span className={badgeVariants({ variant: tone ?? "info", size: "sm" })}>{children}</span>;
+/** The tab a `?note=` opens: where the note's anchor is drawn. */
+async function noteTab(dir: string, note: string | undefined): Promise<string | null> {
+ if (!note) return null;
+ const { doc } = await readNotes(path.join(dir, "notes.json")).catch(() => ({ doc: null }));
+ const n = doc?.notes?.find((x: { id: string }) => x.id === note) as { anchor?: { kind?: string } } | undefined;
+ return n?.anchor?.kind ? tabOfNoteAnchor(n.anchor.kind) : null;
}
export default async function ReportProject({
@@ -80,12 +52,11 @@ export default async function ReportProject({
search: Record<string, string | undefined>;
}) {
const detail = await readClipDetail(project.dir);
- const decisions = await decisionsForProject(project);
if (!detail) {
return (
<div className="flex h-full flex-col">
- <BrowseHeader crumbs={[{ href: "/browse", label: "projects" }, { label: project.id }]} />
+ <BrowseHeader crumbs={[{ href: "/projects", label: "projects" }, { label: project.id }]} />
<main className="deck-main flex-1 p-4">
<p className="text-[12px] text-[var(--color-bad)]">
<code className="font-mono">video.manifest.json</code> could not be parsed.
@@ -98,766 +69,50 @@ export default async function ReportProject({
);
}
- const { manifest: m, build, entries, channelsDir, shadowExists } = detail;
- const corrections = correctionsOf(m) as {
- id: string;
- channel: string | null;
- video: string;
- at: number;
- href: string;
- text: string;
- verdict: "confirmed" | "incorrect" | "unreviewed";
- }[];
+ const { manifest: m, build, entries } = detail;
+ const tab = tabOf(search, { noteTab: !search.tab ? await noteTab(project.dir, search.note) : null });
+ const frame = await readPieceFrame(project);
const clips = entries.filter((e) => e.kind === "clip");
- // How much of the cut has been walked. One definition, shared with the bench
- // header and `umtool corrections`.
- const review = reviewOf(m);
- // And how much of it can be walked TODAY: the walk visits the clips that
- // still need judgement and have something to play, so the gap between these
- // two numbers is what is waiting on a download rather than on somebody.
- const readiness = walkReadiness(clips);
- // What the walk is waiting on: the same clips the rows below mark "not
- // fetched yet".
- const pendingFetch = unfetchedNeedingJudgement(clips) as string[];
- const walkStart = (readiness.readyIds[0] as string | undefined) ?? clips[0]?.id;
const nonClips = entries.filter((e) => e.kind !== "clip");
const runtime = clips.reduce((n, e) => n + Math.max(0, e.end - e.start), 0);
- const showAll = search.all === "1";
- const p = (m.provenance ?? {}) as Record<string, unknown>;
-
- // ---- the long-form reads: sources, revisions, notes, exports ------------
- const sources = await sourcesOf(project.dir, { manifest: m });
- const snapshots = await listSnapshots(project.dir);
- const diffs = await Promise.all(
- snapshots.map(async (sn) => {
- try {
- return diffManifests(await readSnapshot(project.dir, sn.rel), m);
- } catch {
- return null;
- }
- }),
- );
- const readme = await readFile(path.join(project.dir, "README.md"), "utf8").catch(() => null);
- // Sibling notes: every .md that is neither the report nor the README.
- const names = await readdir(project.dir).catch(() => [] as string[]);
- const noteFiles = names.filter((n) => /\.md$/i.test(n) && !/^readme\.md$/i.test(n) && n !== "sweep-report.md").sort();
- const noteTexts = await Promise.all(noteFiles.map((n) => readFile(path.join(project.dir, n), "utf8").catch(() => "")));
- const variants = await exportableVariants(project.dir);
- // Each exportable cut's podcast files, as they are on disk (build-podcast.mjs).
- const podcastOf = async (v: string) => {
- const f = async (which: "m4a" | "mp3" | "notes") => {
- const got = await podcastFor(project, m, v, which);
- return got ? { size: got.size, mtimeMs: got.mtimeMs } : null;
- };
- return { m4a: await f("m4a"), mp3: await f("mp3"), notes: await f("notes") };
- };
- const podcasts = new Map(await Promise.all(variants.map(async (v) => [v, await podcastOf(v)] as const)));
- const takes = await listTakes(project.dir);
- const narrated = narrationsOf(m).length;
- // The drafts review (release 28): drafted fields, and alternatives kept.
- // (A field a code path made — the converter's timeline — is not a draft to review.)
- const draftedCount = draftedFields(m).filter((d) => !isCodeDraft(d.provenance)).length;
- const alternativesCount = (await readAlternatives(project.dir)).length;
- // "Draft with" (release 28 M9): the iteration the project was made from, and
- // each media task's last run here.
- const draftLink = await projectIteration(project.dir);
- const draftRunsNow = draftLink.ok ? await draftRuns(project.dir) : {};
-
- // Provenance splits by SHAPE: a scalar or a URL stays in the table; a long
- // string, or one with a newline, is prose the author wrote and reads as a
- // paragraph under Notes. No field is moved or rewritten.
- const isProse = (v: unknown) => typeof v === "string" && (v.length > 120 || v.includes("\n"));
- const scalars = Object.entries(p).filter(([, v]) => !isProse(v) && (typeof v !== "object" || v === null));
- const prose = Object.entries(p).filter(([, v]) => isProse(v)) as [string, string][];
- const structured = Object.entries(p).filter(([, v]) => typeof v === "object" && v !== null);
- const days = (ms: number) => Math.floor((Date.now() - ms) / 86_400_000);
-
- // ---- what a clip's "mix" link opens ---------------------------------------
- //
- // The widest cached RAW window, not the built segment. Three reasons: it
- // exists as soon as a clip has been fetched once (segments only exist after a
- // build), it has NO CHROME burned in -- which is what a mix is looking at --
- // and it is the file the bench already has peaks for. The built segment is the
- // fallback, and the link says which it is.
- //
- // start/end are the clip's window MINUS the file's own start, because a mix
- // spec is relative to the file it names. The arithmetic is exact and known
- // here; making the client do it would be a second place to get it wrong.
- const mixHref = (e: {
- id: string;
- start: number;
- end: number;
- widest: { name: string; path: string; from: number } | null;
- segment: string | null;
- }): string | null => {
- const q = new URLSearchParams();
- if (e.widest) {
- // The window's own path, not a rebuild of it: the editor fetches into
- // the corpus, so "out/clips-raw/<name>" is a file that is not there.
- q.set("body", e.widest.path);
- q.set("start", (e.start - e.widest.from).toFixed(2));
- q.set("end", (e.end - e.widest.from).toFixed(2));
- } else if (e.segment) {
- q.set("body", path.join(project.dir, e.segment));
- } else {
- return null;
- }
- q.set("from", project.id);
- q.set("clip", e.id);
- return `/mix?${q}`;
- };
+ // The tabs' counts: cheap, from the manifest already read.
+ const drafted = draftedFields(m).filter((d) => !isCodeDraft(d.provenance)).length;
+ const recordings = new Set(clipsOf(m).map((e: { video: string }) => `${channelFor(m, e)}/${e.video}`)).size;
+ const props = { project, detail, search };
return (
<div className="flex h-full flex-col">
- <BrowseHeader
- crumbs={[{ href: "/browse", label: "projects" }, { label: project.id }]}
+ <PieceFrame
+ project={project.id}
+ title={typeof m.title === "string" && m.title ? m.title : project.id}
+ frame={frame}
+ tab={tab}
+ counts={{ cut: clips.length, media: drafted, sources: recordings }}
note={
`${clips.length} clips` +
(nonClips.length ? ` · ${nonClips.length} other` : "") +
` · ${hms(runtime)} · ${build.built ? "built" : "not built"}`
}
- />
-
- <div className="flex flex-wrap items-start gap-3 border-b border-[var(--color-line)] px-4 py-2">
- <div className="min-w-0 flex-1">
- <h1 className="truncate text-[15px] text-[var(--color-text)]">{m.title}</h1>
- {m.subtitle && <p className="text-[12px] text-[var(--color-dim)]">{m.subtitle}</p>}
- <div className="num mt-1 flex flex-wrap items-center gap-x-3 text-[11px] text-[var(--color-dim)]">
- {typeof p.channel === "string" && p.channel && <span>{p.channel}</span>}
- {m.generatedOn && <span>generated {m.generatedOn}</span>}
- {typeof p.videosCited === "number" && <span>{p.videosCited} videos cited</span>}
- {typeof p.enumeratedMatches === "number" && (
- <span>{p.enumeratedMatches} enumerated matches</span>
- )}
- </div>
- </div>
- {/* ---- the way in ----
- Every clip row carries a bench link, which is the right control for
- "go to that one" and the wrong one for "start". Reviewing a cut is
- watching every clip in order, and the first clip is where that
- begins -- so it is a button in the title bar rather than the
- eleventh link on a page whose first screenful is decisions,
- sources and the build chain. */}
- {clips.length > 0 && (
- <div data-walk-cut="" className="flex flex-col items-start gap-1">
- {/* Where the walk STARTS is where the walk goes: the first clip
- that still needs an answer and can be played. A cut whose
- first clip is already judged (or not fetched) would otherwise
- open on a clip `n` immediately leaves. */}
- <Link
- href={`/browse/${project.id}/clip/${walkStart}`}
- data-walk-start={walkStart}
- className={buttonVariants({ variant: "primary", size: "lg" })}
- >
- Walk the cut → start at {walkStart}
- </Link>
- <span className="text-[11px] text-[var(--color-dim)]" data-walk-progress="">
- <kbd>p</kbd> / <kbd>n</kbd> move between clips · {review.reviewed} of {review.total}{" "}
- reviewed{review.incorrect > 0 ? ` · ${review.incorrect} incorrect` : ""}
- {" · "}
- <span data-ready-count="">
- ready {readiness.ready} of {readiness.needing} needing judgement
- </span>
- </span>
- </div>
- )}
- {/* Alternative renders of part of the cut, made elsewhere and judged
- on their own page. Only when there is a takes/ to look at. */}
- {/* The narration script, card by card, before synthesis -- only when
- some card carries one. */}
- {narrated > 0 && (
- <Link
- href={`/browse/${project.id}/narration`}
- data-narration-link={narrated}
- className={buttonVariants({ size: "lg" })}
- >
- Narration — {narrated}
- </Link>
- )}
- {/* Every drafted field, judged before a final build -- only when a
- draft task wrote one, or kept an alternative. */}
- {(draftedCount > 0 || alternativesCount > 0) && (
- <Link
- href={`/browse/${project.id}/review`}
- data-review-link={draftedCount}
- className={buttonVariants({ size: "lg" })}
- >
- Review drafts — {draftedCount}
- </Link>
- )}
- {takes.exists && (
- <Link
- href={`/browse/${project.id}/takes`}
- data-takes-link={takes.takes.length}
- className={buttonVariants({ size: "lg" })}
- >
- Takes — {takes.takes.length}
- </Link>
- )}
- {build.built && (
- <div className="text-right text-[11px] text-[var(--color-dim)]">
- <div className="font-mono text-[var(--color-text)]">{build.slug}.mp4</div>
- <div className="num">
- {fmtBytes(build.finalSize)} · {fmtAgo(build.finalMtimeMs)}
- </div>
- {/* No window: the whole thing is the point of a deliverable link. */}
- <Link
- href={`/mix?body=${encodeURIComponent(build.finalPath)}&from=${encodeURIComponent(project.id)}`}
- data-mix-deliverable=""
- className="text-[var(--color-sel)] hover:underline"
- >
- open in mix
- </Link>
- </div>
- )}
- <div className="flex basis-full justify-end sm:basis-auto">
- <DeleteProject project={project.id} />
- </div>
- </div>
-
- <NotesProvider target={{ project: project.id }}>
- <main className="deck-main flex-1 space-y-4 p-4">
- <GeneratedBanner generatedBy={typeof m.generatedBy === "string" ? m.generatedBy : null} />
- {/* --- the author's own account of the cut, first ------------------ */}
- {readme && (
- <section data-readme="" className="rounded border border-[var(--color-line)] bg-[var(--color-panel)] px-3 py-2">
- <div className="max-h-[40vh] overflow-y-auto">
- <Markdown text={readme} />
- </div>
- </section>
- )}
-
- {/* --- what is wrong, first ------------------------------------- */}
- {decisions.length > 0 && (
- <section data-project={project.id}>
- <h2 className="micro mb-1.5">
- {decisions.filter((d) => d.severity !== "info").length} waiting of {decisions.length}
- </h2>
- <ul className="space-y-1">
- {decisions.map((d, i) => (
- <li
- key={`${d.kind}-${d.target}-${i}`}
- data-decision={d.kind}
- data-severity={d.severity}
- data-target={d.target}
- className="flex flex-wrap items-baseline gap-2 rounded border border-[var(--color-line)] bg-[var(--color-panel)] px-3 py-1.5"
- >
- <span className={badgeVariants({ variant: TONE[d.severity], size: "sm" })}>
- {d.severity}
- </span>
- <span className="font-mono text-[12px] text-[var(--color-text)]">{d.target}</span>
- <span className="text-[12px] text-[var(--color-dim)]">{d.why}</span>
- <span className="micro ml-auto">{d.kind}</span>
- </li>
- ))}
- </ul>
- </section>
- )}
-
- {/* --- the sources ---------------------------------------------- */}
- <section data-sources="" className="rounded border border-[var(--color-line)] bg-[var(--color-panel)] px-3 py-2">
- <div className="mb-1 flex flex-wrap items-baseline gap-3">
- <h2 className="micro">
- sources — {sources.rows.length}
- </h2>
- <span className="num text-[11px] text-[var(--color-dim)]" data-sources-checked={sources.checkedAtMs ? String(Math.round(sources.checkedAtMs)) : "never"}>
- {sources.checkedAtMs
- ? `availability checked ${days(sources.checkedAtMs)} d ago`
- : "availability never checked"}
- </span>
- <span className="ml-auto">
- <CheckSourcesButton projects={[project.id]} label="re-check availability" />
- </span>
- </div>
- {/* Beside the sources, because these ARE the sources: tagging them in
- the archive is a statement about the recordings this table lists,
- and the count in the control is the count in its heading. */}
- <div className="mt-1.5">
- <TagCitedButton project={project.id} />
- </div>
- <div className="num text-[11px] text-[var(--color-dim)]">
- cues from <code className="font-mono">{channelsDir}</code>
- {shadowExists && (
- <span className="ml-2 text-[var(--color-meter)]">
- (this project’s own shadow tree)
- </span>
- )}
- {" · "}QR codes resolve to{" "}
- <code className="font-mono">{String(p.siteOrigin ?? "") || "(nothing — siteOrigin is unset)"}</code>
- </div>
- {sources.rows.length > 0 && (
- <div className="mt-2 overflow-x-auto">
- <table className="w-full border-collapse text-[11px]">
- <thead>
- <tr className="micro text-left">
- <th className="px-1.5 py-0.5">source</th>
- <th className="px-1.5 py-0.5">clips</th>
- <th className="px-1.5 py-0.5">cues</th>
- <th className="px-1.5 py-0.5">coverage</th>
- <th className="px-1.5 py-0.5">availability</th>
- <th className="px-1.5 py-0.5">cite target</th>
- </tr>
- </thead>
- <tbody>
- {sources.rows.map((r) => {
- const a = r.availability;
- return (
- <tr
- key={r.key}
- data-source={r.key}
- data-cues={r.cues}
- data-cue-gap={r.coverageGap ? r.coverageGap.clip : ""}
- data-availability={a ? a.state : "never"}
- data-cite-override={r.cite.differs ? "1" : "0"}
- className="border-t border-[var(--color-line)] align-top"
- >
- <td className="px-1.5 py-1">
- <a href={r.cite.override ?? r.cite.derived} target="_blank" rel="noreferrer" className="font-mono text-[var(--color-sel)] hover:underline">
- {r.key}
- </a>
- {r.title && <div className="truncate text-[var(--color-dim)]" style={{ maxWidth: "24rem" }}>{r.title}</div>}
- </td>
- <td className="px-1.5 py-1 font-mono">
- {r.clips.map((c, i) => (
- <span key={c}>
- {i > 0 && " "}
- <Link href={`/browse/${project.id}/clip/${c}`} className="text-[var(--color-sel)] hover:underline">
- {c}
- </Link>
- </span>
- ))}
- </td>
- <td className="px-1.5 py-1">
- {r.cues === "missing" ? (
- <Pill tone="blocking">missing</Pill>
- ) : r.cues === "no-punctuation" ? (
- <Pill>no punctuation</Pill>
- ) : (
- <span className="text-[var(--color-dim)]">present</span>
- )}
- </td>
- <td className="num px-1.5 py-1">
- {r.coverageGap ? (
- <span className="text-[var(--color-dirty)]">
- cues end {r.coverageGap.cuesEnd.toFixed(0)} s · {r.coverageGap.clip} needs {r.coverageGap.needs.toFixed(0)} s
- </span>
- ) : r.cuesEnd != null ? (
- <span className="text-[var(--color-dim)]">cues to {r.cuesEnd.toFixed(0)} s</span>
- ) : (
- <span className="text-[var(--color-dim)]">—</span>
- )}
- </td>
- <td className="num px-1.5 py-1">
- {a ? (
- <span className={a.ok ? "text-[var(--color-dim)]" : "text-[var(--color-bad)]"} title={a.error ?? undefined}>
- {a.state} · {days(a.checkedAtMs)} d ago
- </span>
- ) : (
- <span className="text-[var(--color-dim)]">never checked</span>
- )}
- </td>
- <td className="px-1.5 py-1">
- {r.cite.differs ? (
- <span className="text-[var(--color-dim)]">
- <Pill>citeUrl</Pill>{" "}
- <a href={r.cite.override!} target="_blank" rel="noreferrer" className="font-mono text-[var(--color-sel)] hover:underline">
- override
- </a>
- </span>
- ) : (
- <span className="text-[var(--color-dim)]">derived</span>
- )}
- </td>
- </tr>
- );
- })}
- </tbody>
- </table>
- </div>
- )}
- </section>
-
- {/* --- building it ---------------------------------------------- */}
- <ReportBuildChain
- project={project.id}
- entries={entries.map((e) => ({ id: e.id, kind: e.kind }))}
- />
-
- {/* --- drafting it ----------------------------------------------- */}
- {/* Each draftable section drafted by a model, as a step on the
- iteration the project was made from. After the build chain (a
- draft changes what the next build makes), before the sections it
- writes into. */}
- <DraftPanel project={project.id} link={draftLink} rows={draftRowsOf(m as Record<string, unknown>)} runs={draftRunsNow} />
-
- {/* --- what is drawn over it --------------------------------------- */}
- {/* The on-screen panel: its settings, its words and a live preview of
- both. After the build chain, because "re-render on-screen" is a run
- of that chain over segments it already built; before Deliver,
- because the panel is part of the video that gets delivered. */}
- <OnscreenSection
- project={project.id}
- generatedBy={typeof m.generatedBy === "string" ? m.generatedBy : null}
- entries={entries.map((e) => ({ id: e.id, kind: e.kind, segment: !!e.segment }))}
- built={!!build.built}
- />
-
- {/* --- delivering it --------------------------------------------- */}
- {/* After the build chain, because that is the order the work happens
- in: the video is one deliverable and the written report with its
- own clip files is the other, and both wait on the same walk. */}
- <DeliverSection project={project} manifest={m} entries={entries} />
-
- {/* --- the timeline --------------------------------------------- */}
- <section>
- <h2 className="micro mb-1.5">
- the cut — {entries.length} entries, in array order
- </h2>
- {/* The gap between "ready" and "needing", closed in one press. Every
- row below it that reads "not fetched yet" is one of these, and
- closing them one bench page at a time was the loop this replaces.
- The default pad is the fetch route's own (±20 s), so a clip
- fetched here and a clip fetched from the bench land in the same
- file. */}
- {pendingFetch.length > 0 && (
- <div className="mb-1.5">
- <FetchUnfetchedButton
- project={project.id}
- pending={pendingFetch.map((id) => ({ id, padBefore: 20, padAfter: 20 }))}
- />
- </div>
- )}
- <TimelineList project={project.id} count={entries.length}>
- {entries.map((e, at) => {
- // Anything that is not a CLIP renders generically. The timeline's
- // vocabulary is open -- one real manifest carries `scroll` and
- // `chart` beside its cards -- and a page that only knows two words
- // either crashes on the third or silently drops it.
- if (e.kind !== "clip") {
- return (
- <li
- key={`${e.id}@${at}`}
- data-entry={e.id}
- data-kind={e.kind}
- data-at={at}
- tabIndex={0}
- className="flex flex-wrap items-baseline gap-2 rounded border border-dashed border-[var(--color-line)] px-3 py-1.5 text-[12px] outline-none focus:border-[var(--color-sel)]"
- >
- <RowControls id={e.id} at={at} />
- <span className="font-mono text-[var(--color-dim)]">{e.id}</span>
- <Pill>{e.style ? `${e.kind} · ${e.style}` : e.kind}</Pill>
- <span className="text-[var(--color-text)]">
- {e.heading ?? e.title ?? e.label ?? ""}
- </span>
- {e.seconds != null && <span className="num micro ml-auto">{e.seconds}s</span>}
- <div className="basis-full">
- <RowNotes id={e.id} project={project.id} />
- </div>
- </li>
- );
- }
- // `endsSentence === null` means the source has no punctuation to
- // read, which is a different thing to say than "this cut is fine".
- const midSentence = e.endsSentence === false && !e.lockEnd && !e.lock;
- return (
- <li
- key={`${e.id}@${at}`}
- data-entry={e.id}
- data-kind="clip"
- data-at={at}
- tabIndex={0}
- data-cached={e.cached ? "1" : "0"}
- data-fetched={e.fetched ? "1" : "0"}
- data-mid-sentence={midSentence ? "1" : "0"}
- className="rounded border border-[var(--color-line)] bg-[var(--color-panel)] px-3 py-1.5 outline-none focus:border-[var(--color-sel)]"
- >
- <div className="flex flex-wrap items-baseline gap-2 text-[12px]">
- <RowControls id={e.id} at={at} />
- <span className="font-mono text-[var(--color-sel)]">{e.id}</span>
- <span className="num font-mono text-[11px] text-[var(--color-dim)]">
- {e.video} {hms(e.start)}–{hms(e.end)} ({(e.end - e.start).toFixed(1)}s)
- </span>
- {e.lock && <Pill>locked</Pill>}
- {!e.lock && e.lockStart && <Pill>start pinned</Pill>}
- {!e.lock && e.lockEnd && <Pill>end pinned</Pill>}
- {/* The PLAYER's question, and the walk's: is this clip
- watchable end to end right now. `data-cached` keeps the
- BUILD's -- the padded window it would fetch -- because
- the build chain reads it and they are different. */}
- {e.fetched ? (
- <Pill>cached</Pill>
- ) : (
- <Pill tone="open">
- not fetched yet
- </Pill>
- )}
- {e.segment && <Pill>segment built</Pill>}
- {!e.hasCues && (
- <Pill tone={TONE.blocking}>no cues</Pill>
- )}
- {midSentence && <Pill tone="open">ends mid-sentence</Pill>}
- {e.noPunctuation && <Pill>source unpunctuated</Pill>}
- {e.proposed && (
- <Pill tone="open">
- widener would move it
- </Pill>
- )}
- <span className="ml-auto flex items-center gap-2">
- {mixHref(e) ? (
- <Link
- href={mixHref(e)!}
- data-mix-link={e.id}
- className="text-[11px] text-[var(--color-sel)] hover:underline"
- >
- mix
- </Link>
- ) : (
- // Never a dead link that 400s: a clip with nothing
- // fetched has nothing to open.
- <span className="micro" data-mix-link-disabled={e.id}>
- fetch it first
- </span>
- )}
- <Link
- href={`/browse/${project.id}/clip/${e.id}`}
- data-bench-link={e.id}
- className="text-[11px] text-[var(--color-sel)] hover:underline"
- >
- bench →
- </Link>
- <span className="micro">§{e.section ?? 0}</span>
- </span>
- </div>
- {(showAll || midSentence || e.proposed) && e.quote && (
- <p className="mt-1 text-[11px] leading-snug text-[var(--color-dim)]">
- “{String(e.quote).slice(0, 240)}
- {String(e.quote).length > 240 ? "…" : ""}”
- </p>
- )}
- {midSentence && e.endCueText && (
- <p className="num mt-1 text-[11px] text-[var(--color-dirty)]">
- cut lands inside: “…{String(e.endCueText).trim().slice(-64)}”
- </p>
- )}
- {e.proposed && (
- <p className="num mt-1 text-[11px] text-[var(--color-dirty)]">
- resolve-windows would make it {hms(e.proposed.start)}–{hms(e.proposed.end)} —
- set <code className="font-mono">lock</code> if this window is deliberate
- </p>
- )}
- <RowNotes id={e.id} project={project.id} />
- </li>
- );
- })}
- </TimelineList>
- <div className="mt-2">
- <Link
- href={`/browse/${project.id}${showAll ? "" : "?all=1"}`}
- className="text-[11px] text-[var(--color-sel)] hover:underline"
- >
- {showAll ? "hide quotes" : "show every quote"}
- </Link>
- </div>
- </section>
-
- {/* --- corrections ------------------------------------------------ */}
- {/*
- Not a decision and not a defect in the CUT: a correction says the
- REPORT got something wrong -- wrong speaker, wrong addressee, wrong
- date -- and the fix belongs to the next sweep, not to this manifest.
- So it is collected here rather than filed in the inbox, in the same
- shape `umtool corrections` prints, because the list's real destination
- is somebody's next prompt.
- */}
- {corrections.length > 0 && (
- <section
- data-corrections=""
- className="rounded border border-[var(--color-line)] bg-[var(--color-panel)] px-3 py-2"
- >
- <h2 className="micro mb-1.5">
- corrections for the next pass —{" "}
- {corrections.filter((c) => c.verdict === "incorrect").length}
- {corrections.some((c) => c.verdict !== "incorrect") &&
- ` · ${corrections.filter((c) => c.verdict !== "incorrect").length} notes on confirmed clips`}
- </h2>
- <ul className="space-y-1.5">
- {corrections.map((c) => (
- <li
- key={c.id}
- data-correction={c.id}
- data-correction-verdict={c.verdict}
- className="text-[12px] leading-snug"
- >
- {/* A note on a CONFIRMED clip is not a defect, and a reader
- who cannot tell the two apart goes off to fix a clip
- nobody complained about. */}
- {c.verdict !== "incorrect" && <Pill>note · confirmed</Pill>}{" "}
- <Link
- href={`/browse/${project.id}/clip/${c.id}`}
- className="font-mono text-[11px] text-[var(--color-sel)] hover:underline"
- >
- {c.id}
- </Link>{" "}
- <span className="text-[11px] text-[var(--color-dim)]">
- {c.channel}/{c.video} @ {hms(c.at)}
- </span>{" "}
- <a
- href={c.href}
- target="_blank"
- rel="noreferrer"
- className="text-[11px] text-[var(--color-sel)] hover:underline"
- >
- the moment
- </a>
- <div className="text-[var(--color-dim)]">{c.text}</div>
- </li>
- ))}
- </ul>
- <p className="mt-2 text-[11px] text-[var(--color-dim)]">
- <code className="font-mono">umtool corrections {project.id}</code> prints the same
- list as markdown, with the moment links, ready to paste into the next sweep.
- </p>
- </section>
- )}
-
- {/* --- revisions ------------------------------------------------- */}
- <section data-revisions="" className="rounded border border-[var(--color-line)] bg-[var(--color-panel)] px-3 py-2">
- <div className="mb-1 flex flex-wrap items-baseline gap-3">
- <h2 className="micro">revisions — {snapshots.length}</h2>
- <span className="ml-auto">
- <SnapshotButton project={project.id} />
- </span>
- </div>
- {snapshots.length === 0 ? (
- <p className="text-[11px] text-[var(--color-dim)]">
- no snapshots. One copies <code className="font-mono">video.manifest.json</code> into{" "}
- <code className="font-mono">revisions/</code>; a build that stamps a deliverable aside
- takes one of the manifest that made it.
- </p>
- ) : (
- <ul className="space-y-1">
- {snapshots.map((sn, i) => {
- const d = diffs[i];
- const summary = !d
- ? "unreadable"
- : d.same
- ? "same timeline as now"
- : Object.entries(d.counts).map(([k, n]) => `${n} ${k}`).join(" · ");
- return (
- <li
- key={sn.rel}
- data-snapshot={sn.rel}
- data-legacy={sn.legacy ? "1" : "0"}
- data-diff={d ? d.changes.length : "x"}
- className="text-[11px]"
- >
- <details>
- <summary className="flex cursor-pointer flex-wrap items-baseline gap-2">
- <span className="font-mono text-[var(--color-text)]">{sn.rel}</span>
- {sn.legacy && <Pill>legacy</Pill>}
- {sn.label && !sn.legacy && <Pill>{sn.label}</Pill>}
- <span className="num text-[var(--color-dim)]">{fmtAgo(sn.mtimeMs)}</span>
- <span className={`num ml-auto ${d && !d.same ? "text-[var(--color-dirty)]" : "text-[var(--color-dim)]"}`}>
- {summary}
- </span>
- </summary>
- {d && !d.same && (
- <pre className="mt-1 max-h-56 overflow-auto rounded bg-[var(--color-ink)] p-2 font-mono text-[11px] text-[var(--color-dim)]">
- {d.changes.map((c) => formatChange(c)).join("\n")}
- </pre>
- )}
- </details>
- </li>
- );
- })}
- </ul>
- )}
- </section>
-
- {/* --- the upload's text (out/youtube.txt, or its preview) --------- */}
- <YoutubeSection dir={project.dir} manifest={m as Record<string, unknown>} />
-
- {/* --- exports --------------------------------------------------- */}
- <section data-exports="" className="rounded border border-[var(--color-line)] bg-[var(--color-panel)] px-3 py-2">
- <h2 className="micro mb-1">export</h2>
- {variants.length === 0 ? (
- <p className="text-[11px] text-[var(--color-dim)]">
- nothing built to export from — a TOC needs the build’s chapter offsets, and there is
- no <code className="font-mono">chapters.ffmeta</code> and no segments under{" "}
- <code className="font-mono">out/</code>
- </p>
- ) : (
- variants.map((v) => (
- <div key={v} className="flex flex-wrap items-center gap-1.5 text-[11px]" data-export-variant={v}>
- <span className="w-14 font-mono text-[var(--color-dim)]">{v}</span>
- {EXPORT_FORMATS.map((f) => (
- <CopyButton
- key={f}
- label={f}
- title={`copy the ${f} for the ${v} cut`}
- url={`/api/report/export?project=${encodeURIComponent(project.id)}&format=${f}&variant=${v}`}
- />
- ))}
- <PodcastExport
- project={project.id}
- variant={v}
- files={podcasts.get(v) ?? { m4a: null, mp3: null, notes: null }}
- />
- </div>
- ))
- )}
- </section>
-
- {/* --- provenance, as written; prose under notes ------------------- */}
- <section data-provenance="">
- <h2 className="micro mb-1.5">provenance</h2>
- <dl className="grid grid-cols-[max-content_1fr] gap-x-3 gap-y-0.5 rounded border border-[var(--color-line)] bg-[var(--color-panel)] px-3 py-2 text-[11px]">
- {scalars.map(([k, v]) => (
- <div key={k} className="contents">
- <dt className="micro">{k}</dt>
- <dd className="num break-all text-[var(--color-dim)]">
- {typeof v === "string" && /^https?:\/\//.test(v) ? (
- <a href={v} target="_blank" rel="noreferrer" className="text-[var(--color-sel)] hover:underline">
- {v}
- </a>
- ) : (
- String(v)
- )}
- </dd>
- </div>
- ))}
- {structured.map(([k, v]) => (
- <div key={k} className="contents">
- <dt className="micro">{k}</dt>
- <dd className="font-mono text-[var(--color-dim)]">{JSON.stringify(v).slice(0, 200)}</dd>
- </div>
- ))}
- </dl>
- </section>
-
- {(prose.length > 0 || noteFiles.length > 0) && (
- <section data-notes="">
- <h2 className="micro mb-1.5">notes</h2>
- <div className="space-y-2 rounded border border-[var(--color-line)] bg-[var(--color-panel)] px-3 py-2">
- {prose.map(([k, v]) => (
- <div key={k} data-note={k}>
- <div className="text-[12px] font-semibold text-[var(--color-text)]">{k}</div>
- <p className="whitespace-pre-wrap text-[12px] leading-relaxed text-[var(--color-dim)]">{v}</p>
- </div>
- ))}
- {noteFiles.map((n, i) => (
- <details key={n} data-note-file={n}>
- <summary className="cursor-pointer font-mono text-[12px] text-[var(--color-sel)]">{n}</summary>
- <div className="mt-1 max-h-[50vh] overflow-y-auto">
- <Markdown text={noteTexts[i]} />
- </div>
- </details>
- ))}
- </div>
- </section>
- )}
- </main>
- </NotesProvider>
+ more={
+ <>
+ <span className="px-2 pb-1 pt-0.5 font-mono text-[11px] text-muted">{project.id}</span>
+ <DeleteProject project={project.id} />
+ </>
+ }
+ >
+ <NotesProvider target={{ project: project.id }}>
+ <main className="deck-main flex-1 space-y-4 p-4" data-piece-tab={tab}>
+ <GeneratedBanner generatedBy={typeof m.generatedBy === "string" ? m.generatedBy : null} />
+ {tab === "overview" && <OverviewTab {...props} frame={frame} />}
+ {tab === "cut" && <CutTab {...props} />}
+ {tab === "media" && <MediaTab {...props} />}
+ {tab === "build" && <BuildTab {...props} />}
+ {tab === "deliver" && <DeliverTab {...props} />}
+ {tab === "sources" && <SourcesTab {...props} />}
+ {tab === "history" && <HistoryTab {...props} />}
+ </main>
+ </NotesProvider>
+ </PieceFrame>
</div>
);
}
diff --git a/umtool/components/projects/report/BuildTab.tsx b/umtool/components/projects/report/BuildTab.tsx
@@ -0,0 +1,51 @@
+import Link from "next/link";
+import { fmtAgo, fmtBytes } from "@/lib/format";
+import OnscreenSection from "../OnscreenSection";
+import ReportBuildChain from "../ReportBuildChain";
+import type { ReportTabProps } from "./shared";
+
+// The Build tab: the final video, the build chain, and the on-screen panel --
+// OnscreenSection parked here WHOLE until P4b gives on-screen its own Media
+// surface. Moved from ReportProject unchanged (P4a-1).
+
+export default function BuildTab({ project, detail }: ReportTabProps) {
+ const { manifest: m, build, entries } = detail;
+ return (
+ <>
+ {build.built && (
+ <div className="text-right text-[11px] text-[var(--color-dim)]">
+ <div className="font-mono text-[var(--color-text)]">{build.slug}.mp4</div>
+ <div className="num">
+ {fmtBytes(build.finalSize)} · {fmtAgo(build.finalMtimeMs)}
+ </div>
+ {/* No window: the whole thing is the point of a deliverable link. */}
+ <Link
+ href={`/mix?body=${encodeURIComponent(build.finalPath)}&from=${encodeURIComponent(project.id)}`}
+ data-mix-deliverable=""
+ className="text-[var(--color-sel)] hover:underline"
+ >
+ open in mix
+ </Link>
+ </div>
+ )}
+ {/* --- building it ---------------------------------------------- */}
+ <ReportBuildChain
+ project={project.id}
+ entries={entries.map((e) => ({ id: e.id, kind: e.kind }))}
+ />
+
+ {/* --- what is drawn over it --------------------------------------- */}
+ {/* The on-screen panel: its settings, its words and a live preview of
+ both. After the build chain, because "re-render on-screen" is a run
+ of that chain over segments it already built; before Deliver,
+ because the panel is part of the video that gets delivered. */}
+ <OnscreenSection
+ project={project.id}
+ generatedBy={typeof m.generatedBy === "string" ? m.generatedBy : null}
+ entries={entries.map((e) => ({ id: e.id, kind: e.kind, segment: !!e.segment }))}
+ built={!!build.built}
+ />
+
+ </>
+ );
+}
diff --git a/umtool/components/projects/report/CutTab.tsx b/umtool/components/projects/report/CutTab.tsx
@@ -0,0 +1,340 @@
+import Link from "next/link";
+import path from "node:path";
+import {
+ correctionsOf,
+ reviewOf,
+ unfetchedNeedingJudgement,
+ walkReadiness,
+} from "@/lib/projects/report.mjs";
+import { listTakes } from "@/lib/report/takes.mjs";
+import { buttonVariants } from "@/components/ui/button";
+import FetchUnfetchedButton from "../FetchUnfetchedButton";
+import { RowControls, RowNotes, TimelineList } from "../TimelineEditor";
+import { Pill, TONE, hms, type ReportTabProps } from "./shared";
+
+// The Cut tab: the timeline, read back -- the walk into it, its takes, every
+// entry with what is wrong with it, and the corrections the walk collected.
+// Moved from ReportProject unchanged (P4a-1).
+
+export default async function CutTab({ project, detail, search }: ReportTabProps) {
+ const { manifest: m, entries } = detail;
+ const corrections = correctionsOf(m) as {
+ id: string;
+ channel: string | null;
+ video: string;
+ at: number;
+ href: string;
+ text: string;
+ verdict: "confirmed" | "incorrect" | "unreviewed";
+ }[];
+ const clips = entries.filter((e) => e.kind === "clip");
+ // How much of the cut has been walked. One definition, shared with the bench
+ // header and `umtool corrections`.
+ const review = reviewOf(m);
+ // And how much of it can be walked TODAY: the walk visits the clips that
+ // still need judgement and have something to play, so the gap between these
+ // two numbers is what is waiting on a download rather than on somebody.
+ const readiness = walkReadiness(clips);
+ // What the walk is waiting on: the same clips the rows below mark "not
+ // fetched yet".
+ const pendingFetch = unfetchedNeedingJudgement(clips) as string[];
+ const walkStart = (readiness.readyIds[0] as string | undefined) ?? clips[0]?.id;
+ const showAll = search.all === "1";
+ const takes = await listTakes(project.dir);
+
+ // ---- what a clip's "mix" link opens ---------------------------------------
+ //
+ // The widest cached RAW window, not the built segment. Three reasons: it
+ // exists as soon as a clip has been fetched once (segments only exist after a
+ // build), it has NO CHROME burned in -- which is what a mix is looking at --
+ // and it is the file the bench already has peaks for. The built segment is the
+ // fallback, and the link says which it is.
+ //
+ // start/end are the clip's window MINUS the file's own start, because a mix
+ // spec is relative to the file it names. The arithmetic is exact and known
+ // here; making the client do it would be a second place to get it wrong.
+ const mixHref = (e: {
+ id: string;
+ start: number;
+ end: number;
+ widest: { name: string; path: string; from: number } | null;
+ segment: string | null;
+ }): string | null => {
+ const q = new URLSearchParams();
+ if (e.widest) {
+ // The window's own path, not a rebuild of it: the editor fetches into
+ // the corpus, so "out/clips-raw/<name>" is a file that is not there.
+ q.set("body", e.widest.path);
+ q.set("start", (e.start - e.widest.from).toFixed(2));
+ q.set("end", (e.end - e.widest.from).toFixed(2));
+ } else if (e.segment) {
+ q.set("body", path.join(project.dir, e.segment));
+ } else {
+ return null;
+ }
+ q.set("from", project.id);
+ q.set("clip", e.id);
+ return `/mix?${q}`;
+ };
+
+ return (
+ <>
+ <div className="flex flex-wrap items-start gap-3">
+ {/* ---- the way in ----
+ Every clip row carries a bench link, which is the right control for
+ "go to that one" and the wrong one for "start". Reviewing a cut is
+ watching every clip in order, and the first clip is where that
+ begins -- so it is a button in the title bar rather than the
+ eleventh link on a page whose first screenful is decisions,
+ sources and the build chain. */}
+ {clips.length > 0 && (
+ <div data-walk-cut="" className="flex flex-col items-start gap-1">
+ {/* Where the walk STARTS is where the walk goes: the first clip
+ that still needs an answer and can be played. A cut whose
+ first clip is already judged (or not fetched) would otherwise
+ open on a clip `n` immediately leaves. */}
+ <Link
+ href={`/browse/${project.id}/clip/${walkStart}`}
+ data-walk-start={walkStart}
+ className={buttonVariants({ variant: "primary", size: "lg" })}
+ >
+ Walk the cut → start at {walkStart}
+ </Link>
+ <span className="text-[11px] text-[var(--color-dim)]" data-walk-progress="">
+ <kbd>p</kbd> / <kbd>n</kbd> move between clips · {review.reviewed} of {review.total}{" "}
+ reviewed{review.incorrect > 0 ? ` · ${review.incorrect} incorrect` : ""}
+ {" · "}
+ <span data-ready-count="">
+ ready {readiness.ready} of {readiness.needing} needing judgement
+ </span>
+ </span>
+ </div>
+ )}
+ {/* Alternative renders of part of the cut, made elsewhere and judged
+ on their own page. Only when there is a takes/ to look at. */}
+ {takes.exists && (
+ <Link
+ href={`/browse/${project.id}/takes`}
+ data-takes-link={takes.takes.length}
+ className={buttonVariants({ size: "lg" })}
+ >
+ Takes — {takes.takes.length}
+ </Link>
+ )}
+ </div>
+
+ {/* --- the timeline --------------------------------------------- */}
+ <section>
+ <h2 className="micro mb-1.5">
+ the cut — {entries.length} entries, in array order
+ </h2>
+ {/* The gap between "ready" and "needing", closed in one press. Every
+ row below it that reads "not fetched yet" is one of these, and
+ closing them one bench page at a time was the loop this replaces.
+ The default pad is the fetch route's own (±20 s), so a clip
+ fetched here and a clip fetched from the bench land in the same
+ file. */}
+ {pendingFetch.length > 0 && (
+ <div className="mb-1.5">
+ <FetchUnfetchedButton
+ project={project.id}
+ pending={pendingFetch.map((id) => ({ id, padBefore: 20, padAfter: 20 }))}
+ />
+ </div>
+ )}
+ <TimelineList project={project.id} count={entries.length}>
+ {entries.map((e, at) => {
+ // Anything that is not a CLIP renders generically. The timeline's
+ // vocabulary is open -- one real manifest carries `scroll` and
+ // `chart` beside its cards -- and a page that only knows two words
+ // either crashes on the third or silently drops it.
+ if (e.kind !== "clip") {
+ return (
+ <li
+ key={`${e.id}@${at}`}
+ data-entry={e.id}
+ data-kind={e.kind}
+ data-at={at}
+ tabIndex={0}
+ className="flex flex-wrap items-baseline gap-2 rounded border border-dashed border-[var(--color-line)] px-3 py-1.5 text-[12px] outline-none focus:border-[var(--color-sel)]"
+ >
+ <RowControls id={e.id} at={at} />
+ <span className="font-mono text-[var(--color-dim)]">{e.id}</span>
+ <Pill>{e.style ? `${e.kind} · ${e.style}` : e.kind}</Pill>
+ <span className="text-[var(--color-text)]">
+ {e.heading ?? e.title ?? e.label ?? ""}
+ </span>
+ {e.seconds != null && <span className="num micro ml-auto">{e.seconds}s</span>}
+ <div className="basis-full">
+ <RowNotes id={e.id} project={project.id} />
+ </div>
+ </li>
+ );
+ }
+ // `endsSentence === null` means the source has no punctuation to
+ // read, which is a different thing to say than "this cut is fine".
+ const midSentence = e.endsSentence === false && !e.lockEnd && !e.lock;
+ return (
+ <li
+ key={`${e.id}@${at}`}
+ data-entry={e.id}
+ data-kind="clip"
+ data-at={at}
+ tabIndex={0}
+ data-cached={e.cached ? "1" : "0"}
+ data-fetched={e.fetched ? "1" : "0"}
+ data-mid-sentence={midSentence ? "1" : "0"}
+ className="rounded border border-[var(--color-line)] bg-[var(--color-panel)] px-3 py-1.5 outline-none focus:border-[var(--color-sel)]"
+ >
+ <div className="flex flex-wrap items-baseline gap-2 text-[12px]">
+ <RowControls id={e.id} at={at} />
+ <span className="font-mono text-[var(--color-sel)]">{e.id}</span>
+ <span className="num font-mono text-[11px] text-[var(--color-dim)]">
+ {e.video} {hms(e.start)}–{hms(e.end)} ({(e.end - e.start).toFixed(1)}s)
+ </span>
+ {e.lock && <Pill>locked</Pill>}
+ {!e.lock && e.lockStart && <Pill>start pinned</Pill>}
+ {!e.lock && e.lockEnd && <Pill>end pinned</Pill>}
+ {/* The PLAYER's question, and the walk's: is this clip
+ watchable end to end right now. `data-cached` keeps the
+ BUILD's -- the padded window it would fetch -- because
+ the build chain reads it and they are different. */}
+ {e.fetched ? (
+ <Pill>cached</Pill>
+ ) : (
+ <Pill tone="open">
+ not fetched yet
+ </Pill>
+ )}
+ {e.segment && <Pill>segment built</Pill>}
+ {!e.hasCues && (
+ <Pill tone={TONE.blocking}>no cues</Pill>
+ )}
+ {midSentence && <Pill tone="open">ends mid-sentence</Pill>}
+ {e.noPunctuation && <Pill>source unpunctuated</Pill>}
+ {e.proposed && (
+ <Pill tone="open">
+ widener would move it
+ </Pill>
+ )}
+ <span className="ml-auto flex items-center gap-2">
+ {mixHref(e) ? (
+ <Link
+ href={mixHref(e)!}
+ data-mix-link={e.id}
+ className="text-[11px] text-[var(--color-sel)] hover:underline"
+ >
+ mix
+ </Link>
+ ) : (
+ // Never a dead link that 400s: a clip with nothing
+ // fetched has nothing to open.
+ <span className="micro" data-mix-link-disabled={e.id}>
+ fetch it first
+ </span>
+ )}
+ <Link
+ href={`/browse/${project.id}/clip/${e.id}`}
+ data-bench-link={e.id}
+ className="text-[11px] text-[var(--color-sel)] hover:underline"
+ >
+ bench →
+ </Link>
+ <span className="micro">§{e.section ?? 0}</span>
+ </span>
+ </div>
+ {(showAll || midSentence || e.proposed) && e.quote && (
+ <p className="mt-1 text-[11px] leading-snug text-[var(--color-dim)]">
+ “{String(e.quote).slice(0, 240)}
+ {String(e.quote).length > 240 ? "…" : ""}”
+ </p>
+ )}
+ {midSentence && e.endCueText && (
+ <p className="num mt-1 text-[11px] text-[var(--color-dirty)]">
+ cut lands inside: “…{String(e.endCueText).trim().slice(-64)}”
+ </p>
+ )}
+ {e.proposed && (
+ <p className="num mt-1 text-[11px] text-[var(--color-dirty)]">
+ resolve-windows would make it {hms(e.proposed.start)}–{hms(e.proposed.end)} —
+ set <code className="font-mono">lock</code> if this window is deliberate
+ </p>
+ )}
+ <RowNotes id={e.id} project={project.id} />
+ </li>
+ );
+ })}
+ </TimelineList>
+ <div className="mt-2">
+ <Link
+ href={`/browse/${project.id}${showAll ? "" : "?all=1"}`}
+ className="text-[11px] text-[var(--color-sel)] hover:underline"
+ >
+ {showAll ? "hide quotes" : "show every quote"}
+ </Link>
+ </div>
+ </section>
+
+ {/* --- corrections ------------------------------------------------ */}
+ {/*
+ Not a decision and not a defect in the CUT: a correction says the
+ REPORT got something wrong -- wrong speaker, wrong addressee, wrong
+ date -- and the fix belongs to the next sweep, not to this manifest.
+ So it is collected here rather than filed in the inbox, in the same
+ shape `umtool corrections` prints, because the list's real destination
+ is somebody's next prompt.
+ */}
+ {corrections.length > 0 && (
+ <section
+ data-corrections=""
+ className="rounded border border-[var(--color-line)] bg-[var(--color-panel)] px-3 py-2"
+ >
+ <h2 className="micro mb-1.5">
+ corrections for the next pass —{" "}
+ {corrections.filter((c) => c.verdict === "incorrect").length}
+ {corrections.some((c) => c.verdict !== "incorrect") &&
+ ` · ${corrections.filter((c) => c.verdict !== "incorrect").length} notes on confirmed clips`}
+ </h2>
+ <ul className="space-y-1.5">
+ {corrections.map((c) => (
+ <li
+ key={c.id}
+ data-correction={c.id}
+ data-correction-verdict={c.verdict}
+ className="text-[12px] leading-snug"
+ >
+ {/* A note on a CONFIRMED clip is not a defect, and a reader
+ who cannot tell the two apart goes off to fix a clip
+ nobody complained about. */}
+ {c.verdict !== "incorrect" && <Pill>note · confirmed</Pill>}{" "}
+ <Link
+ href={`/browse/${project.id}/clip/${c.id}`}
+ className="font-mono text-[11px] text-[var(--color-sel)] hover:underline"
+ >
+ {c.id}
+ </Link>{" "}
+ <span className="text-[11px] text-[var(--color-dim)]">
+ {c.channel}/{c.video} @ {hms(c.at)}
+ </span>{" "}
+ <a
+ href={c.href}
+ target="_blank"
+ rel="noreferrer"
+ className="text-[11px] text-[var(--color-sel)] hover:underline"
+ >
+ the moment
+ </a>
+ <div className="text-[var(--color-dim)]">{c.text}</div>
+ </li>
+ ))}
+ </ul>
+ <p className="mt-2 text-[11px] text-[var(--color-dim)]">
+ <code className="font-mono">umtool corrections {project.id}</code> prints the same
+ list as markdown, with the moment links, ready to paste into the next sweep.
+ </p>
+ </section>
+ )}
+
+ </>
+ );
+}
diff --git a/umtool/components/projects/report/DeliverTab.tsx b/umtool/components/projects/report/DeliverTab.tsx
@@ -0,0 +1,65 @@
+import CopyButton from "@/components/CopyButton";
+import { EXPORT_FORMATS, exportableVariants } from "@/lib/report/export.mjs";
+import { podcastFor } from "@/lib/report/serve.mjs";
+import DeliverSection from "../DeliverSection";
+import PodcastExport from "../PodcastExport";
+import type { ReportTabProps } from "./shared";
+
+// The Deliver tab: the deliver panel (cuts, share batches, rulings applied,
+// the written report rebuilt) and the exports. Moved from ReportProject
+// unchanged (P4a-1).
+
+export default async function DeliverTab({ project, detail }: ReportTabProps) {
+ const { manifest: m, entries } = detail;
+ const variants = await exportableVariants(project.dir);
+ // Each exportable cut's podcast files, as they are on disk (build-podcast.mjs).
+ const podcastOf = async (v: string) => {
+ const f = async (which: "m4a" | "mp3" | "notes") => {
+ const got = await podcastFor(project, m, v, which);
+ return got ? { size: got.size, mtimeMs: got.mtimeMs } : null;
+ };
+ return { m4a: await f("m4a"), mp3: await f("mp3"), notes: await f("notes") };
+ };
+ const podcasts = new Map(await Promise.all(variants.map(async (v) => [v, await podcastOf(v)] as const)));
+ return (
+ <>
+ {/* --- delivering it --------------------------------------------- */}
+ {/* After the build chain, because that is the order the work happens
+ in: the video is one deliverable and the written report with its
+ own clip files is the other, and both wait on the same walk. */}
+ <DeliverSection project={project} manifest={m} entries={entries} />
+
+ {/* --- exports --------------------------------------------------- */}
+ <section data-exports="" className="rounded border border-[var(--color-line)] bg-[var(--color-panel)] px-3 py-2">
+ <h2 className="micro mb-1">export</h2>
+ {variants.length === 0 ? (
+ <p className="text-[11px] text-[var(--color-dim)]">
+ nothing built to export from — a TOC needs the build’s chapter offsets, and there is
+ no <code className="font-mono">chapters.ffmeta</code> and no segments under{" "}
+ <code className="font-mono">out/</code>
+ </p>
+ ) : (
+ variants.map((v) => (
+ <div key={v} className="flex flex-wrap items-center gap-1.5 text-[11px]" data-export-variant={v}>
+ <span className="w-14 font-mono text-[var(--color-dim)]">{v}</span>
+ {EXPORT_FORMATS.map((f) => (
+ <CopyButton
+ key={f}
+ label={f}
+ title={`copy the ${f} for the ${v} cut`}
+ url={`/api/report/export?project=${encodeURIComponent(project.id)}&format=${f}&variant=${v}`}
+ />
+ ))}
+ <PodcastExport
+ project={project.id}
+ variant={v}
+ files={podcasts.get(v) ?? { m4a: null, mp3: null, notes: null }}
+ />
+ </div>
+ ))
+ )}
+ </section>
+
+ </>
+ );
+}
diff --git a/umtool/components/projects/report/HistoryTab.tsx b/umtool/components/projects/report/HistoryTab.tsx
@@ -0,0 +1,145 @@
+import { readdir, readFile } from "node:fs/promises";
+import path from "node:path";
+import { fmtAgo } from "@/lib/format";
+import { Markdown } from "@/lib/markdown";
+import { diffManifests, formatChange } from "@/lib/report/manifest-diff.mjs";
+import { listSnapshots, readSnapshot } from "@/lib/report/snapshots.mjs";
+import SnapshotButton from "../SnapshotButton";
+import { Pill, type ReportTabProps } from "./shared";
+
+// The History tab: the manifest's revisions with what changed since each,
+// its provenance as written, and the notes beside it (prose fields and the
+// sibling .md files). Moved from ReportProject unchanged (P4a-1).
+
+export default async function HistoryTab({ project, detail }: ReportTabProps) {
+ const { manifest: m } = detail;
+ const p = (m.provenance ?? {}) as Record<string, unknown>;
+ const snapshots = await listSnapshots(project.dir);
+ const diffs = await Promise.all(
+ snapshots.map(async (sn) => {
+ try {
+ return diffManifests(await readSnapshot(project.dir, sn.rel), m);
+ } catch {
+ return null;
+ }
+ }),
+ );
+ // Sibling notes: every .md that is neither the report nor the README.
+ const names = await readdir(project.dir).catch(() => [] as string[]);
+ const noteFiles = names.filter((n) => /\.md$/i.test(n) && !/^readme\.md$/i.test(n) && n !== "sweep-report.md").sort();
+ const noteTexts = await Promise.all(noteFiles.map((n) => readFile(path.join(project.dir, n), "utf8").catch(() => "")));
+
+ // Provenance splits by SHAPE: a scalar or a URL stays in the table; a long
+ // string, or one with a newline, is prose the author wrote and reads as a
+ // paragraph under Notes. No field is moved or rewritten.
+ const isProse = (v: unknown) => typeof v === "string" && (v.length > 120 || v.includes("\n"));
+ const scalars = Object.entries(p).filter(([, v]) => !isProse(v) && (typeof v !== "object" || v === null));
+ const prose = Object.entries(p).filter(([, v]) => isProse(v)) as [string, string][];
+ const structured = Object.entries(p).filter(([, v]) => typeof v === "object" && v !== null);
+ return (
+ <>
+ {/* --- revisions ------------------------------------------------- */}
+ <section data-revisions="" className="rounded border border-[var(--color-line)] bg-[var(--color-panel)] px-3 py-2">
+ <div className="mb-1 flex flex-wrap items-baseline gap-3">
+ <h2 className="micro">revisions — {snapshots.length}</h2>
+ <span className="ml-auto">
+ <SnapshotButton project={project.id} />
+ </span>
+ </div>
+ {snapshots.length === 0 ? (
+ <p className="text-[11px] text-[var(--color-dim)]">
+ no snapshots. One copies <code className="font-mono">video.manifest.json</code> into{" "}
+ <code className="font-mono">revisions/</code>; a build that stamps a deliverable aside
+ takes one of the manifest that made it.
+ </p>
+ ) : (
+ <ul className="space-y-1">
+ {snapshots.map((sn, i) => {
+ const d = diffs[i];
+ const summary = !d
+ ? "unreadable"
+ : d.same
+ ? "same timeline as now"
+ : Object.entries(d.counts).map(([k, n]) => `${n} ${k}`).join(" · ");
+ return (
+ <li
+ key={sn.rel}
+ data-snapshot={sn.rel}
+ data-legacy={sn.legacy ? "1" : "0"}
+ data-diff={d ? d.changes.length : "x"}
+ className="text-[11px]"
+ >
+ <details>
+ <summary className="flex cursor-pointer flex-wrap items-baseline gap-2">
+ <span className="font-mono text-[var(--color-text)]">{sn.rel}</span>
+ {sn.legacy && <Pill>legacy</Pill>}
+ {sn.label && !sn.legacy && <Pill>{sn.label}</Pill>}
+ <span className="num text-[var(--color-dim)]">{fmtAgo(sn.mtimeMs)}</span>
+ <span className={`num ml-auto ${d && !d.same ? "text-[var(--color-dirty)]" : "text-[var(--color-dim)]"}`}>
+ {summary}
+ </span>
+ </summary>
+ {d && !d.same && (
+ <pre className="mt-1 max-h-56 overflow-auto rounded bg-[var(--color-ink)] p-2 font-mono text-[11px] text-[var(--color-dim)]">
+ {d.changes.map((c) => formatChange(c)).join("\n")}
+ </pre>
+ )}
+ </details>
+ </li>
+ );
+ })}
+ </ul>
+ )}
+ </section>
+
+ {/* --- provenance, as written; prose under notes ------------------- */}
+ <section data-provenance="">
+ <h2 className="micro mb-1.5">provenance</h2>
+ <dl className="grid grid-cols-[max-content_1fr] gap-x-3 gap-y-0.5 rounded border border-[var(--color-line)] bg-[var(--color-panel)] px-3 py-2 text-[11px]">
+ {scalars.map(([k, v]) => (
+ <div key={k} className="contents">
+ <dt className="micro">{k}</dt>
+ <dd className="num break-all text-[var(--color-dim)]">
+ {typeof v === "string" && /^https?:\/\//.test(v) ? (
+ <a href={v} target="_blank" rel="noreferrer" className="text-[var(--color-sel)] hover:underline">
+ {v}
+ </a>
+ ) : (
+ String(v)
+ )}
+ </dd>
+ </div>
+ ))}
+ {structured.map(([k, v]) => (
+ <div key={k} className="contents">
+ <dt className="micro">{k}</dt>
+ <dd className="font-mono text-[var(--color-dim)]">{JSON.stringify(v).slice(0, 200)}</dd>
+ </div>
+ ))}
+ </dl>
+ </section>
+
+ {(prose.length > 0 || noteFiles.length > 0) && (
+ <section data-notes="">
+ <h2 className="micro mb-1.5">notes</h2>
+ <div className="space-y-2 rounded border border-[var(--color-line)] bg-[var(--color-panel)] px-3 py-2">
+ {prose.map(([k, v]) => (
+ <div key={k} data-note={k}>
+ <div className="text-[12px] font-semibold text-[var(--color-text)]">{k}</div>
+ <p className="whitespace-pre-wrap text-[12px] leading-relaxed text-[var(--color-dim)]">{v}</p>
+ </div>
+ ))}
+ {noteFiles.map((n, i) => (
+ <details key={n} data-note-file={n}>
+ <summary className="cursor-pointer font-mono text-[12px] text-[var(--color-sel)]">{n}</summary>
+ <div className="mt-1 max-h-[50vh] overflow-y-auto">
+ <Markdown text={noteTexts[i]} />
+ </div>
+ </details>
+ ))}
+ </div>
+ </section>
+ )}
+ </>
+ );
+}
diff --git a/umtool/components/projects/report/MediaTab.tsx b/umtool/components/projects/report/MediaTab.tsx
@@ -0,0 +1,69 @@
+import Link from "next/link";
+import { narrationsOf } from "umtool-report-to-video/narration";
+import { draftedFields, isCodeDraft } from "yt-dlp-transcript-common/lib/report/drafted.mjs";
+import { readAlternatives } from "@/lib/report/drafts.mjs";
+import { draftRowsOf, draftRuns, projectIteration } from "@/lib/articles/projectDraft";
+import { buttonVariants } from "@/components/ui/button";
+import DraftPanel from "../DraftPanel";
+import YoutubeSection from "../YoutubeSection";
+import type { ReportTabProps } from "./shared";
+
+// The Media tab: release 28's drafts as they were on the project page -- the
+// narration script and the drafts review, the "Draft with" panel, the upload's
+// text. Moved from ReportProject unchanged (P4a-1); P4b absorbs them into one
+// Media surface.
+
+export default async function MediaTab({ project, detail }: ReportTabProps) {
+ const { manifest: m } = detail;
+ const narrated = narrationsOf(m).length;
+ // The drafts review (release 28): drafted fields, and alternatives kept.
+ // (A field a code path made — the converter's timeline — is not a draft to review.)
+ const draftedCount = draftedFields(m).filter((d) => !isCodeDraft(d.provenance)).length;
+ const alternativesCount = (await readAlternatives(project.dir)).length;
+ // "Draft with" (release 28 M9): the iteration the project was made from, and
+ // each media task's last run here.
+ const draftLink = await projectIteration(project.dir);
+ const draftRunsNow = draftLink.ok ? await draftRuns(project.dir) : {};
+
+ return (
+ <>
+ {(narrated > 0 || draftedCount > 0 || alternativesCount > 0) && (
+ <div className="flex flex-wrap items-start gap-3">
+ {/* The narration script, card by card, before synthesis -- only when
+ some card carries one. */}
+ {narrated > 0 && (
+ <Link
+ href={`/browse/${project.id}/narration`}
+ data-narration-link={narrated}
+ className={buttonVariants({ size: "lg" })}
+ >
+ Narration — {narrated}
+ </Link>
+ )}
+ {/* Every drafted field, judged before a final build -- only when a
+ draft task wrote one, or kept an alternative. */}
+ {(draftedCount > 0 || alternativesCount > 0) && (
+ <Link
+ href={`/browse/${project.id}/review`}
+ data-review-link={draftedCount}
+ className={buttonVariants({ size: "lg" })}
+ >
+ Review drafts — {draftedCount}
+ </Link>
+ )}
+ </div>
+ )}
+
+ {/* --- drafting it ----------------------------------------------- */}
+ {/* Each draftable section drafted by a model, as a step on the
+ iteration the project was made from. After the build chain (a
+ draft changes what the next build makes), before the sections it
+ writes into. */}
+ <DraftPanel project={project.id} link={draftLink} rows={draftRowsOf(m as Record<string, unknown>)} runs={draftRunsNow} />
+
+ {/* --- the upload's text (out/youtube.txt, or its preview) --------- */}
+ <YoutubeSection dir={project.dir} manifest={m as Record<string, unknown>} />
+
+ </>
+ );
+}
diff --git a/umtool/components/projects/report/OverviewTab.tsx b/umtool/components/projects/report/OverviewTab.tsx
@@ -0,0 +1,211 @@
+import { readFile } from "node:fs/promises";
+import path from "node:path";
+import Link from "next/link";
+import { Suspense } from "react";
+import NextCard, { NextCardShell } from "@/components/piece/NextCard";
+import { badgeVariants } from "@/components/ui/badge";
+import { Table, TD, TH } from "@/components/ui/table";
+import { ARTICLES_KEY } from "@/lib/articles/key.mjs";
+import { readArticleIterations, type IterationRow } from "@/lib/articles/generation";
+import { articleHref } from "@/lib/hrefs";
+import { Markdown } from "@/lib/markdown";
+import { decisionsForProject } from "@/lib/projects";
+import type { PieceFrame } from "@/lib/pieces/frame";
+import { TONE, hms, type ReportTabProps } from "./shared";
+
+// The Overview tab (canvas "Piece · Overview"): the Next card, then the
+// piece's decisions and -- when it is an article's video -- the article and
+// its iterations beside the stats, then the author's README. The decisions and
+// the README are ReportProject's sections, unchanged (P4a-1).
+
+const VIA: Record<string, string> = {
+ iteration: "made by its iteration",
+ manifest: "named by the manifest",
+ slug: "matched by name",
+};
+
+export default async function OverviewTab({ project, detail, frame }: ReportTabProps & { frame: PieceFrame }) {
+ const { manifest: m, build, entries } = detail;
+ const decisions = await decisionsForProject(project);
+ const readme = await readFile(path.join(project.dir, "README.md"), "utf8").catch(() => null);
+ const p = (m.provenance ?? {}) as Record<string, unknown>;
+ const clips = entries.filter((e) => e.kind === "clip");
+ const nonClips = entries.filter((e) => e.kind !== "clip");
+ const runtime = clips.reduce((n, e) => n + Math.max(0, e.end - e.start), 0);
+ const article = frame.article;
+ const iterations =
+ article && article.site === ARTICLES_KEY ? await readArticleIterations(article.report).catch(() => null) : null;
+
+ return (
+ <>
+ <Suspense
+ fallback={
+ <NextCardShell>
+ <span className="text-[12.5px] text-muted">Reading the Inbox…</span>
+ </NextCardShell>
+ }
+ >
+ <NextCard pieceId={frame.pieceId} title={frame.piece?.title ?? project.id} lifecycle={frame.lifecycle} />
+ </Suspense>
+
+ <div className="grid grid-cols-1 gap-[22px] lg:grid-cols-[minmax(0,1.25fr)_minmax(0,1fr)]">
+ <div className="min-w-0 space-y-4">
+ {/* --- what is wrong, first ------------------------------------- */}
+ {decisions.length > 0 && (
+ <section data-project={project.id}>
+ <h2 className="micro mb-1.5">
+ {decisions.filter((d) => d.severity !== "info").length} waiting of {decisions.length}
+ </h2>
+ <ul className="space-y-1">
+ {decisions.map((d, i) => (
+ <li
+ key={`${d.kind}-${d.target}-${i}`}
+ data-decision={d.kind}
+ data-severity={d.severity}
+ data-target={d.target}
+ className="flex flex-wrap items-baseline gap-2 rounded border border-[var(--color-line)] bg-[var(--color-panel)] px-3 py-1.5"
+ >
+ <span className={badgeVariants({ variant: TONE[d.severity], size: "sm" })}>
+ {d.severity}
+ </span>
+ <span className="font-mono text-[12px] text-[var(--color-text)]">{d.target}</span>
+ <span className="text-[12px] text-[var(--color-dim)]">{d.why}</span>
+ <span className="micro ml-auto">{d.kind}</span>
+ </li>
+ ))}
+ </ul>
+ </section>
+ )}
+ {decisions.length === 0 && (
+ <p data-project={project.id} className="text-[12.5px] text-muted">
+ No decisions on this project.
+ </p>
+ )}
+
+ {iterations && iterations.iterations.length > 0 && article && (
+ <section data-piece-iterations={iterations.iterations.length}>
+ <div className="mb-2 flex items-baseline gap-3">
+ <h2 className="micro">Iterations</h2>
+ <Link
+ href={articleHref({ site: article.site, id: article.report }, { tab: "iterations" })}
+ prefetch={false}
+ className="ink-link ml-auto text-[12px]"
+ >
+ All iterations →
+ </Link>
+ </div>
+ <IterationsSummary rows={iterations.iterations.slice(0, 5)} />
+ </section>
+ )}
+ </div>
+
+ <div className="min-w-0 space-y-4">
+ <section data-piece-stats="">
+ <h2 className="micro mb-1.5">This video</h2>
+ {m.subtitle && <p className="text-[13px] text-text-2">{m.subtitle}</p>}
+ <ul className="mt-1 text-[13px] text-text-2">
+ <li className="flex gap-2.5 border-b border-seam py-1.5">
+ cut
+ <span className="ml-auto font-mono text-[11.5px] text-meter">
+ {clips.length} clips{nonClips.length ? ` · ${nonClips.length} other` : ""} · {hms(runtime)}
+ </span>
+ </li>
+ <li className="flex gap-2.5 border-b border-seam py-1.5">
+ final video
+ <span className="ml-auto font-mono text-[11.5px] text-text-2">
+ {build.built ? `${build.slug}.mp4${build.stale ? " · out of date" : ""}` : "not built"}
+ </span>
+ </li>
+ {typeof p.channel === "string" && p.channel && (
+ <li className="flex gap-2.5 border-b border-seam py-1.5">
+ channel<span className="ml-auto text-text-2">{p.channel}</span>
+ </li>
+ )}
+ {m.generatedOn && (
+ <li className="flex gap-2.5 border-b border-seam py-1.5">
+ generated<span className="ml-auto font-mono text-[11.5px]">{m.generatedOn}</span>
+ </li>
+ )}
+ {typeof p.videosCited === "number" && (
+ <li className="flex gap-2.5 border-b border-seam py-1.5">
+ videos cited<span className="ml-auto font-mono text-[11.5px] text-meter">{p.videosCited}</span>
+ </li>
+ )}
+ {typeof p.enumeratedMatches === "number" && (
+ <li className="flex gap-2.5 border-b border-seam py-1.5">
+ enumerated matches<span className="ml-auto font-mono text-[11.5px] text-meter">{p.enumeratedMatches}</span>
+ </li>
+ )}
+ </ul>
+ </section>
+
+ {article && (
+ <section data-piece-linked-article={`${article.site}/${article.report}`}>
+ <h2 className="micro mb-1.5">Article</h2>
+ <Link href={articleHref({ site: article.site, id: article.report })} prefetch={false} className="ink-link text-[13px]">
+ {article.title}
+ </Link>
+ <p className="text-[12px] text-muted">
+ {article.site === ARTICLES_KEY ? "the article store" : article.site} · {VIA[article.via] ?? article.via}
+ {article.cut ? " · its Cut" : ""}
+ </p>
+ </section>
+ )}
+ </div>
+ </div>
+
+ {/* --- the author's own account of the cut ------------------------- */}
+ {readme && (
+ <section data-readme="" className="rounded border border-[var(--color-line)] bg-[var(--color-panel)] px-3 py-2">
+ <div className="max-h-[40vh] overflow-y-auto">
+ <Markdown text={readme} />
+ </div>
+ </section>
+ )}
+ </>
+ );
+}
+
+/** The article's newest iterations (canvas `.itab`): number, kind, model, spend, time, checks, current. */
+function IterationsSummary({ rows }: { rows: IterationRow[] }) {
+ return (
+ <Table>
+ <thead>
+ <tr>
+ <TH>#</TH>
+ <TH>Kind</TH>
+ <TH>Model</TH>
+ <TH className="text-right">Spend</TH>
+ <TH className="text-right">Time</TH>
+ <TH>Checks</TH>
+ <TH />
+ </tr>
+ </thead>
+ <tbody>
+ {rows.map((r) => (
+ <tr key={r.n} data-iteration={r.n}>
+ <TD numeric className="text-left">
+ {r.n}
+ </TD>
+ <TD>{r.kind}</TD>
+ <TD className="truncate">{r.model}</TD>
+ <TD numeric className="text-meter">
+ {r.usd > 0 ? `$${r.usd.toFixed(2)}` : "—"}
+ </TD>
+ <TD numeric>{r.minutes != null ? `${r.minutes.toFixed(1)} min` : "—"}</TD>
+ <TD>
+ {r.checks.length === 0
+ ? "—"
+ : r.checks.map((c) => (
+ <span key={c.name} title={c.detail ?? undefined} className={`mr-1.5 ${c.ok ? "text-kept-text" : "text-reject-text"}`}>
+ {c.ok ? "✓" : "✕"} {c.name}
+ </span>
+ ))}
+ </TD>
+ <TD className="text-text-2">{r.currentVideo || r.currentReport ? "current" : r.status}</TD>
+ </tr>
+ ))}
+ </tbody>
+ </Table>
+ );
+}
diff --git a/umtool/components/projects/report/SourcesTab.tsx b/umtool/components/projects/report/SourcesTab.tsx
@@ -0,0 +1,143 @@
+import Link from "next/link";
+import CheckSourcesButton from "@/components/dashboard/CheckSourcesButton";
+import { sourcesOf } from "@/lib/projects/report.mjs";
+import TagCitedButton from "../TagCitedButton";
+import { Pill, type ReportTabProps } from "./shared";
+
+// The Sources tab: every recording the cut cites, its cues and coverage, when
+// its availability was last checked, where its QR resolves, and tagging the
+// lot in the archive. Moved from ReportProject unchanged (P4a-1).
+
+export default async function SourcesTab({ project, detail }: ReportTabProps) {
+ const { manifest: m, channelsDir, shadowExists } = detail;
+ const p = (m.provenance ?? {}) as Record<string, unknown>;
+ const sources = await sourcesOf(project.dir, { manifest: m });
+ const days = (ms: number) => Math.floor((Date.now() - ms) / 86_400_000);
+ return (
+ <>
+ {/* --- the sources ---------------------------------------------- */}
+ <section data-sources="" className="rounded border border-[var(--color-line)] bg-[var(--color-panel)] px-3 py-2">
+ <div className="mb-1 flex flex-wrap items-baseline gap-3">
+ <h2 className="micro">
+ sources — {sources.rows.length}
+ </h2>
+ <span className="num text-[11px] text-[var(--color-dim)]" data-sources-checked={sources.checkedAtMs ? String(Math.round(sources.checkedAtMs)) : "never"}>
+ {sources.checkedAtMs
+ ? `availability checked ${days(sources.checkedAtMs)} d ago`
+ : "availability never checked"}
+ </span>
+ <span className="ml-auto">
+ <CheckSourcesButton projects={[project.id]} label="re-check availability" />
+ </span>
+ </div>
+ {/* Beside the sources, because these ARE the sources: tagging them in
+ the archive is a statement about the recordings this table lists,
+ and the count in the control is the count in its heading. */}
+ <div className="mt-1.5">
+ <TagCitedButton project={project.id} />
+ </div>
+ <div className="num text-[11px] text-[var(--color-dim)]">
+ cues from <code className="font-mono">{channelsDir}</code>
+ {shadowExists && (
+ <span className="ml-2 text-[var(--color-meter)]">
+ (this project’s own shadow tree)
+ </span>
+ )}
+ {" · "}QR codes resolve to{" "}
+ <code className="font-mono">{String(p.siteOrigin ?? "") || "(nothing — siteOrigin is unset)"}</code>
+ </div>
+ {sources.rows.length > 0 && (
+ <div className="mt-2 overflow-x-auto">
+ <table className="w-full border-collapse text-[11px]">
+ <thead>
+ <tr className="micro text-left">
+ <th className="px-1.5 py-0.5">source</th>
+ <th className="px-1.5 py-0.5">clips</th>
+ <th className="px-1.5 py-0.5">cues</th>
+ <th className="px-1.5 py-0.5">coverage</th>
+ <th className="px-1.5 py-0.5">availability</th>
+ <th className="px-1.5 py-0.5">cite target</th>
+ </tr>
+ </thead>
+ <tbody>
+ {sources.rows.map((r) => {
+ const a = r.availability;
+ return (
+ <tr
+ key={r.key}
+ data-source={r.key}
+ data-cues={r.cues}
+ data-cue-gap={r.coverageGap ? r.coverageGap.clip : ""}
+ data-availability={a ? a.state : "never"}
+ data-cite-override={r.cite.differs ? "1" : "0"}
+ className="border-t border-[var(--color-line)] align-top"
+ >
+ <td className="px-1.5 py-1">
+ <a href={r.cite.override ?? r.cite.derived} target="_blank" rel="noreferrer" className="font-mono text-[var(--color-sel)] hover:underline">
+ {r.key}
+ </a>
+ {r.title && <div className="truncate text-[var(--color-dim)]" style={{ maxWidth: "24rem" }}>{r.title}</div>}
+ </td>
+ <td className="px-1.5 py-1 font-mono">
+ {r.clips.map((c, i) => (
+ <span key={c}>
+ {i > 0 && " "}
+ <Link href={`/browse/${project.id}/clip/${c}`} className="text-[var(--color-sel)] hover:underline">
+ {c}
+ </Link>
+ </span>
+ ))}
+ </td>
+ <td className="px-1.5 py-1">
+ {r.cues === "missing" ? (
+ <Pill tone="blocking">missing</Pill>
+ ) : r.cues === "no-punctuation" ? (
+ <Pill>no punctuation</Pill>
+ ) : (
+ <span className="text-[var(--color-dim)]">present</span>
+ )}
+ </td>
+ <td className="num px-1.5 py-1">
+ {r.coverageGap ? (
+ <span className="text-[var(--color-dirty)]">
+ cues end {r.coverageGap.cuesEnd.toFixed(0)} s · {r.coverageGap.clip} needs {r.coverageGap.needs.toFixed(0)} s
+ </span>
+ ) : r.cuesEnd != null ? (
+ <span className="text-[var(--color-dim)]">cues to {r.cuesEnd.toFixed(0)} s</span>
+ ) : (
+ <span className="text-[var(--color-dim)]">—</span>
+ )}
+ </td>
+ <td className="num px-1.5 py-1">
+ {a ? (
+ <span className={a.ok ? "text-[var(--color-dim)]" : "text-[var(--color-bad)]"} title={a.error ?? undefined}>
+ {a.state} · {days(a.checkedAtMs)} d ago
+ </span>
+ ) : (
+ <span className="text-[var(--color-dim)]">never checked</span>
+ )}
+ </td>
+ <td className="px-1.5 py-1">
+ {r.cite.differs ? (
+ <span className="text-[var(--color-dim)]">
+ <Pill>citeUrl</Pill>{" "}
+ <a href={r.cite.override!} target="_blank" rel="noreferrer" className="font-mono text-[var(--color-sel)] hover:underline">
+ override
+ </a>
+ </span>
+ ) : (
+ <span className="text-[var(--color-dim)]">derived</span>
+ )}
+ </td>
+ </tr>
+ );
+ })}
+ </tbody>
+ </table>
+ </div>
+ )}
+ </section>
+
+ </>
+ );
+}
diff --git a/umtool/components/projects/report/shared.tsx b/umtool/components/projects/report/shared.tsx
@@ -0,0 +1,35 @@
+import { badgeVariants, type BadgeVariants } from "@/components/ui/badge";
+import type { readClipDetail } from "@/lib/projects/report.mjs";
+import type { Severity } from "@/lib/decisions";
+import type { ProjectRef } from "@/lib/project-types";
+
+// What every tab of a report video's piece page shares: the project, its
+// parsed detail (the one expensive read, done once by the page), and the
+// small helpers the sections were written with.
+
+export type ClipDetail = NonNullable<Awaited<ReturnType<typeof readClipDetail>>>;
+export type ReportTabProps = {
+ project: ProjectRef;
+ detail: ClipDetail;
+ search: Record<string, string | undefined>;
+};
+
+export const hms = (t: number) => {
+ const s = Math.max(0, Math.floor(t));
+ const h = Math.floor(s / 3600);
+ const m = Math.floor((s % 3600) / 60);
+ const sec = s % 60;
+ return h > 0
+ ? `${h}:${String(m).padStart(2, "0")}:${String(sec).padStart(2, "0")}`
+ : `${m}:${String(sec).padStart(2, "0")}`;
+};
+
+export const TONE: Record<Severity, BadgeVariants["variant"]> = {
+ blocking: "blocking",
+ open: "open",
+ info: "info",
+};
+
+export function Pill({ tone, children }: { tone?: BadgeVariants["variant"]; children: React.ReactNode }) {
+ return <span className={badgeVariants({ variant: tone ?? "info", size: "sm" })}>{children}</span>;
+}
diff --git a/umtool/components/shell/AppHeader.tsx b/umtool/components/shell/AppHeader.tsx
@@ -26,6 +26,7 @@ export default function AppHeader({
note,
actions,
meta,
+ below,
variant = "page",
className,
}: {
@@ -35,6 +36,8 @@ export default function AppHeader({
actions?: React.ReactNode;
/** A line under the title (counts, a hint); muted. */
meta?: React.ReactNode;
+ /** A full-width row at the foot of the head (a piece's stage stepper). */
+ below?: React.ReactNode;
variant?: "page" | "bench";
className?: string;
}) {
@@ -100,6 +103,7 @@ export default function AppHeader({
{note && <div className="micro">{note}</div>}
</div>
)}
+ {below && <div className="basis-full">{below}</div>}
</header>
);
}
diff --git a/umtool/components/shell/AppShell.tsx b/umtool/components/shell/AppShell.tsx
@@ -22,6 +22,7 @@ export default function AppShell({
note,
actions,
meta,
+ below,
rail = "open",
}: {
/** The rail entry that is lit. */
@@ -30,6 +31,8 @@ export default function AppShell({
note?: React.ReactNode;
actions?: React.ReactNode;
meta?: React.ReactNode;
+ /** A full-width row at the foot of the head (a piece's stage stepper). */
+ below?: React.ReactNode;
rail?: "open" | "collapsed";
}) {
return (
@@ -40,6 +43,7 @@ export default function AppShell({
note={note}
actions={actions}
meta={meta}
+ below={below}
variant={rail === "collapsed" ? "bench" : "page"}
/>
</>
diff --git a/umtool/components/ui/tabs.tsx b/umtool/components/ui/tabs.tsx
@@ -5,6 +5,10 @@ import { cn } from "@/lib/utils";
// bookmarkable, the back button works, and a server page renders the right one
// with no client state. The current one carries `aria-current="page"` and the
// Signal underline; a count sits beside its label in Meter.
+//
+// No prefetch: every page here is dynamic, so a prefetched tab is a full server
+// render of a page nobody asked for yet -- seven of them per piece page (P3
+// found the rail's prefetches keeping the server busy enough to fail specs).
export type TabItem = { href: string; label: React.ReactNode; current?: boolean; count?: number | string; testid?: string };
export function Tabs({
@@ -19,6 +23,7 @@ export function Tabs({
<Link
key={t.href}
href={t.href}
+ prefetch={false}
data-testid={t.testid}
aria-current={t.current ? "page" : undefined}
className={cn(
diff --git a/umtool/e2e/urls.ts b/umtool/e2e/urls.ts
@@ -7,5 +7,18 @@
//
// Assertions on hrefs (`toHaveAttribute("href", …)`) should build the expected
// value here too, so a URL change is one edit in lib/hrefs.ts.
+import { projectHref } from "../lib/hrefs";
+import { tabOfSection } from "../lib/pieces/tabs.mjs";
+
export * from "../lib/hrefs";
export { REDIRECTS } from "../redirects.mjs";
+
+/**
+ * The piece page's tab that holds `name` (lib/pieces/tabs.mjs SECTION_TAB):
+ * `section("reports/x", "deliver")` is `/projects/reports/x?tab=deliver`. A
+ * project page is tabs since P4a-1, and a spec that opened it to reach one
+ * section says which, so a section moving tab is one edit in that table.
+ */
+export function section(project: string, name: string, q: { all?: boolean; note?: string } = {}): string {
+ return projectHref(project, { tab: tabOfSection(name), ...q });
+}
diff --git a/umtool/lib/hrefs.test.mjs b/umtool/lib/hrefs.test.mjs
@@ -39,6 +39,10 @@ test("empty, null and false values are left out; true is 1", () => {
assert.equal(H.workHref({}), "/work");
assert.equal(H.workHref({ kind: "", state: undefined, q: "x y" }), "/work?q=x+y");
assert.equal(H.projectHref("p", { all: false }), "/projects/p");
+ // A piece page's tab: first, the Overview never written, a note still last.
+ assert.equal(H.projectHref("a/b", { tab: "build" }), "/projects/a/b?tab=build");
+ assert.equal(H.projectHref("a/b", { tab: "overview" }), "/projects/a/b");
+ assert.equal(H.projectHref("a/b", { tab: "cut", all: true, note: "n1" }), "/projects/a/b?tab=cut&all=1¬e=n1");
assert.equal(H.projectsHref({ kind: "k1", new: false }), "/projects?kind=k1");
assert.equal(H.projectsHref({ new: true }), "/projects?new=1");
assert.equal(H.homeHref({ hidden: true }), "/?hidden=1");
diff --git a/umtool/lib/hrefs.ts b/umtool/lib/hrefs.ts
@@ -200,10 +200,13 @@ export function articleCompareHref(id: string, q: { a?: string; b?: string } = {
// ── projects ────────────────────────────────────────────────────────────────
-/** A project's page. `all` shows every row of a long list. */
-export function projectHref(id: string, q: { all?: boolean } & NoteOpt = {}): string {
- const { note, ...rest } = q;
- return withQuery(`/projects/${encodePath(id)}`, rest, note);
+/**
+ * A project's page. `tab` opens one of the piece page's tabs (lib/pieces/tabs.mjs;
+ * absent, or `overview`, is the Overview); `all` shows every row of the cut's long list.
+ */
+export function projectHref(id: string, q: { tab?: string; all?: boolean } & NoteOpt = {}): string {
+ const { note, tab, ...rest } = q;
+ return withQuery(`/projects/${encodePath(id)}`, { ...(tab && tab !== "overview" ? { tab } : {}), ...rest }, note);
}
/** A project by its path, for an id that a tool page shadows at its own URL. */
diff --git a/umtool/lib/inbox/what.mjs b/umtool/lib/inbox/what.mjs
@@ -0,0 +1,46 @@
+// What a decision kind is, in a few words after the piece's title: the Inbox's
+// card line ("Quartering diet · claims never ruled") and a piece page's Next
+// card. Pure, browser-safe.
+
+/** @type {Record<string, string>} */
+export const WHAT = {
+ "research-proposal": "research proposal",
+ "iteration-failed": "run failed",
+ "iteration-ready": "iteration ready",
+ "drafts-unreviewed": "drafts to review",
+ "open-note": "open notes",
+ "unreadable-notes": "notes.json does not read",
+ "link-ambiguous": "video not linked",
+ "looks-done": "looks done",
+ "claim-unadjudicated": "claims never ruled",
+ "claim-incoherent": "claims that don't hold together",
+ "clip-no-cues": "clips with no cues",
+ "clip-unfetchable": "clips can't be fetched",
+ "clip-mid-sentence": "clips end mid-sentence",
+ "clip-cue-gap": "clips over a cue gap",
+ "clip-cut-outside": "cuts outside the window",
+ "window-overlap": "windows overlap",
+ "no-punctuation": "windows without punctuation",
+ "manifest-invalid": "manifest invalid",
+ "stale-build": "video out of date",
+ unbuilt: "never built",
+ "storage-unreachable": "media drive unreachable",
+ "storage-mismatch": "storage disagrees",
+ "unjudged-variant": "variants not judged",
+ "missing-cut": "cuts missing",
+ "stale-recipe": "recipes out of date",
+ "no-recipe": "no recipe",
+ "spec-problem": "spec problem",
+ "no-plan": "plans unnamed",
+ unattributed: "variants unattributed",
+ "thumb-unaccepted": "no cover accepted",
+ loudness: "loudness off target",
+ "shadowed-name": "no address of its own",
+ "unroutable-name": "no address of its own",
+ "ambiguous-project": "two kinds match",
+ "machine-tool": "a required tool is missing",
+ "machine-disk": "disk nearly full",
+};
+
+/** A kind's words; an unknown kind reads as its id with spaces. */
+export const whatOf = (kind) => WHAT[kind] ?? kind.replace(/-/g, " ");
diff --git a/umtool/lib/pieces/frame.ts b/umtool/lib/pieces/frame.ts
@@ -0,0 +1,122 @@
+import { readInbox, type GroupSummary } from "../inbox";
+import { summarizeGroups } from "../inbox/groups.mjs";
+import { whatOf } from "../inbox/what.mjs";
+import { lifecycleOf, readLifecycle, type LifecycleState } from "../lifecycle";
+import { projectPieceId, readPieceGraph, type Piece } from "../pieces";
+import { STAGES, stageOf } from "../work/facets.mjs";
+import type { Decision } from "../decisions";
+
+// ---------------------------------------------------------------------------
+// A PIECE PAGE's frame, as data (plans/umtool-redesign.md, P4a-1): which piece
+// a project page is, where it is on the four stages, its lifecycle, and its
+// Next call -- the top of the Inbox, narrowed to this piece.
+//
+// A project is the page; the PIECE is what the Inbox and Work list. A project
+// no article claims is its own piece (`p:<id>`); one an article claims (its
+// iteration's projectDir, its manifest's `article`, a unique slug) is part of
+// that article's piece, so the stage, the lifecycle and the Next call are the
+// article's. P4a-2 renders that project AS the article's piece; until then the
+// project page says whose it is and links it.
+//
+// SERVER ONLY. The graph is lib/pieces' (memoised 15 s); the lifecycle is read
+// fresh, as everywhere.
+// ---------------------------------------------------------------------------
+
+export type StepState = "done" | "current" | "todo";
+
+export type PieceFrame = {
+ /** The piece this page is part of, or null when the graph does not list it (a project the walk refused). */
+ piece: Piece | null;
+ pieceId: string;
+ /** The piece is an article's, and this project is one of its videos. */
+ article: { title: string; site: string; report: string; href: string; via: string; cut: boolean } | null;
+ lifecycle: LifecycleState;
+ lifecycleError: string | null;
+ steps: { label: string; state: StepState }[];
+ /** The bucket the stepper lights (research … deliver). */
+ stage: string;
+};
+
+const STAGE_LABEL: Record<string, string> = { research: "Research", article: "Article", video: "Video", deliver: "Deliver" };
+
+/** The four stages, lit for one bucket. A piece marked done has walked them all. */
+export function stepsFor(bucket: string, lifecycle: LifecycleState): PieceFrame["steps"] {
+ const at = STAGES.indexOf(bucket);
+ return STAGES.map((s: string, i: number) => ({
+ label: STAGE_LABEL[s] ?? s,
+ state: lifecycle === "done" || i < at ? "done" : i === at ? "current" : "todo",
+ }));
+}
+
+export async function readPieceFrame(project: { id: string; state?: string | null }): Promise<PieceFrame> {
+ const [graph, life] = await Promise.all([readPieceGraph(), readLifecycle()]);
+ const pieceId = graph.pieceOfProject.get(project.id) ?? projectPieceId(project.id);
+ const piece = graph.byId.get(pieceId) ?? null;
+ const lifecycle = lifecycleOf(life, pieceId);
+ const own = piece?.projects.find((p) => p.id === project.id) ?? null;
+ const article =
+ piece && piece.kind === "article" && piece.site && piece.report
+ ? { title: piece.title, site: piece.site, report: piece.report, href: piece.href, via: own?.via ?? "slug", cut: own?.cut ?? false }
+ : null;
+ const stage = piece
+ ? stageOf({ kind: piece.kind, stage: piece.stage, looksDone: piece.looksDone, projectState: piece.kind === "project" ? piece.stage : null })
+ : "video";
+ return { piece, pieceId, article, lifecycle, lifecycleError: life.error ?? null, steps: stepsFor(stage, lifecycle), stage };
+}
+
+export type NextCall = {
+ kind: string;
+ /** What it is, in a few words ("claims never ruled", "Narration draft · 5 fields"). */
+ what: string;
+ why: string;
+ count: number;
+ severity: string;
+ group: string;
+ action: { label: string; href: string };
+ /** The action is the lifecycle's (Mark done / Reactivate), a POST rather than a link. */
+ lifecycleTo: LifecycleState | null;
+ /** More calls on this piece after this one. */
+ more: number;
+};
+
+/**
+ * The piece's Next call: its top Inbox card (lib/inbox, ranked and grouped the
+ * Inbox's way), or -- for a parked or done piece, whose calls are hidden --
+ * the way back. Null when nothing is waiting.
+ */
+export async function readNextCall(pieceId: string, lifecycle: LifecycleState): Promise<NextCall | null> {
+ const inbox = await readInbox();
+ const mine = inbox.items.filter((d: Decision) => d.piece === pieceId);
+ if (lifecycle !== "active") {
+ const waiting = mine.filter((d) => d.hiddenBy === lifecycle).length;
+ return {
+ kind: "lifecycle",
+ what: lifecycle === "parked" ? "Parked" : "Marked done",
+ why: waiting ? `${waiting} call${waiting === 1 ? "" : "s"} hidden while it is ${lifecycle}` : "nothing hidden",
+ count: waiting,
+ severity: "info",
+ group: "hidden",
+ action: { label: "Reactivate", href: "" },
+ lifecycleTo: "active",
+ more: 0,
+ };
+ }
+ const groups = summarizeGroups(mine.filter((d) => !d.hidden)) as GroupSummary[];
+ // Quiet is facts, not calls: a Next card never offers one.
+ const cards = groups.filter((g) => g.id !== "quiet").flatMap((g) => g.cards.map((c) => ({ g, c })));
+ const top = cards[0];
+ if (!top) return null;
+ const { g, c } = top;
+ const what = c.what ?? whatOf(c.kind);
+ return {
+ kind: c.kind,
+ what,
+ why: c.what && c.why.startsWith(c.what) ? c.why.slice(c.what.length).replace(/^ · /, "") : c.why,
+ count: c.count,
+ severity: c.severity,
+ group: g.id,
+ action: c.action,
+ lifecycleTo: c.kind === "looks-done" ? "done" : null,
+ more: cards.length - 1,
+ };
+}
diff --git a/umtool/lib/pieces/tabs.mjs b/umtool/lib/pieces/tabs.mjs
@@ -0,0 +1,103 @@
+// A PIECE PAGE's tabs (plans/umtool-redesign.md, P4a): which tab a project-
+// rooted piece opens on, which section lives in which tab, and the key that
+// switches to each. Pure, no imports: the page, a client component and an e2e
+// spec (e2e/urls.ts `section`) read the same table.
+//
+// The tab is the URL's `?tab=` -- the canvas's address (`…?tab=media`) and the
+// article page's own key (`/articles/<id>?tab=iterations`), so P4a-2's merged
+// article piece keeps one spelling. Not a path segment: a project id is a path
+// resolved longest-prefix, and what is left after it is a VIEW the kind declares
+// (`clip/<id>`, `takes`, `review` …), so `/projects/a/b/build` could just as well
+// be a project called `build`.
+//
+// An address with no `tab` opens the Overview -- except the two the page always
+// answered that only make sense on one tab: `?all=1` (the cut's "show every
+// quote") opens the Cut, and `?note=<id>` opens the tab its anchor is drawn on
+// (a timeline row's note on the Cut, a timed note on the final video on Build).
+
+/** The tabs of a report-video piece, in order; the key that opens each is its position. */
+export const PIECE_TABS = [
+ { id: "overview", label: "Overview" },
+ { id: "cut", label: "Cut" },
+ { id: "media", label: "Media" },
+ { id: "build", label: "Build" },
+ { id: "deliver", label: "Deliver" },
+ { id: "sources", label: "Sources" },
+ { id: "history", label: "History" },
+];
+
+export const PIECE_TAB_IDS = PIECE_TABS.map((t) => t.id);
+
+/**
+ * Every section ReportProject draws, by the name a spec says, and the tab it
+ * is on. The names are the sections' own data attributes where they have one.
+ */
+export const SECTION_TAB = {
+ // Overview: the Next card, the piece's decisions, the stats, the linked
+ // article and its iterations, and the author's README.
+ next: "overview",
+ decisions: "overview",
+ readme: "overview",
+ stats: "overview",
+ article: "overview",
+ iterations: "overview",
+ // Cut: the timeline, the walk, takes, corrections for the next pass.
+ walk: "cut",
+ timeline: "cut",
+ cut: "cut",
+ takes: "cut",
+ corrections: "cut",
+ // Media: r28's drafts (the panel, the review and narration links) and the upload's text.
+ drafts: "media",
+ review: "media",
+ narration: "media",
+ youtube: "media",
+ // Build: the build chain, the on-screen panel (parked whole until P4b), the final mp4.
+ build: "build",
+ onscreen: "build",
+ final: "build",
+ // Deliver: the deliver panel and the exports.
+ deliver: "deliver",
+ exports: "deliver",
+ // Sources: the source table, availability, tagging the cited recordings.
+ sources: "sources",
+ tag: "sources",
+ // History: revisions, provenance, notes.
+ revisions: "history",
+ provenance: "history",
+ notes: "history",
+};
+
+/** The tab a section is on; throws on a name nobody declared (a spec's typo should fail loudly). */
+export function tabOfSection(name) {
+ const tab = SECTION_TAB[name];
+ if (!tab) throw new Error(`no section "${name}" on a piece page (lib/pieces/tabs.mjs SECTION_TAB)`);
+ return tab;
+}
+
+/** Where a note's anchor is drawn: a row's on the Cut, a timed note on the final video on Build. */
+export function tabOfNoteAnchor(kind) {
+ if (kind === "entry" || kind === "edit") return "cut";
+ if (kind === "moment") return "build";
+ return "overview";
+}
+
+/**
+ * The tab an address opens.
+ *
+ * @param {{ tab?: string, all?: string, note?: string }} search
+ * @param {{ noteTab?: string | null }} [opts] the tab the `note`'s anchor is on, when the page looked it up
+ */
+export function tabOf(search, { noteTab = null } = {}) {
+ const t = search?.tab;
+ if (t && PIECE_TAB_IDS.includes(t)) return t;
+ if (search?.note && noteTab && PIECE_TAB_IDS.includes(noteTab)) return noteTab;
+ if (search?.all === "1") return "cut";
+ return "overview";
+}
+
+/** The tab a number key opens (`1` … `7`), or null. */
+export function tabOfKey(key) {
+ const n = Number(key);
+ return Number.isInteger(n) && n >= 1 && n <= PIECE_TABS.length ? PIECE_TABS[n - 1].id : null;
+}
diff --git a/umtool/lib/pieces/tabs.test.mjs b/umtool/lib/pieces/tabs.test.mjs
@@ -0,0 +1,37 @@
+// A piece page's tabs: the address decides the tab, every section has one.
+import assert from "node:assert/strict";
+import test from "node:test";
+import { PIECE_TABS, PIECE_TAB_IDS, SECTION_TAB, tabOf, tabOfKey, tabOfNoteAnchor, tabOfSection } from "./tabs.mjs";
+
+test("seven tabs, in the canvas's order; keys 1–7 open them", () => {
+ assert.deepEqual(PIECE_TAB_IDS, ["overview", "cut", "media", "build", "deliver", "sources", "history"]);
+ assert.equal(tabOfKey("1"), "overview");
+ assert.equal(tabOfKey("7"), "history");
+ for (const k of ["0", "8", "n", "", "1.5"]) assert.equal(tabOfKey(k), null, k);
+ assert.equal(PIECE_TABS.length, 7);
+});
+
+test("the address picks the tab: ?tab= first, then a note's anchor, then ?all=1, else the Overview", () => {
+ assert.equal(tabOf({}), "overview");
+ assert.equal(tabOf({ tab: "build" }), "build");
+ assert.equal(tabOf({ tab: "nonsense" }), "overview");
+ assert.equal(tabOf({ all: "1" }), "cut");
+ assert.equal(tabOf({ tab: "sources", all: "1" }), "sources");
+ assert.equal(tabOf({ note: "n1" }, { noteTab: "build" }), "build");
+ assert.equal(tabOf({ note: "n1" }), "overview");
+ assert.equal(tabOf({ tab: "media", note: "n1" }, { noteTab: "cut" }), "media");
+});
+
+test("a note opens where its anchor is drawn", () => {
+ assert.equal(tabOfNoteAnchor("entry"), "cut");
+ assert.equal(tabOfNoteAnchor("edit"), "cut");
+ assert.equal(tabOfNoteAnchor("moment"), "build");
+ assert.equal(tabOfNoteAnchor("whole"), "overview");
+});
+
+test("every section is on a real tab; an unknown one throws", () => {
+ for (const [name, tab] of Object.entries(SECTION_TAB)) assert.ok(PIECE_TAB_IDS.includes(tab), name);
+ assert.equal(tabOfSection("onscreen"), "build");
+ assert.equal(tabOfSection("deliver"), "deliver");
+ assert.throws(() => tabOfSection("nope"), /no section "nope"/);
+});