Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit 6ea6fa0e370dbb48c304a93b81cca3972242a8cd
parent 294fd1b66236674b9c6a32c6014e41ccf6028043
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Tue, 10 Nov 2026 13:53:35 -0500

umtool: the workspace's modes -- the review pass (Keep · Fix · Note per block, the verdict at the end, a version read-only) and present (Present's own deck over it, Esc back), in the address; the readiness bar under the top bar; the piece's tabs shrink to the workspace, Sources, Deliver, History

Build and Media fold into Deliver (`?tab=build|media` 308s there); the Overview and the cut's list stay addressable views out of the tab bar (Piece ▾, ⋯). /present 308s to `?mode=present`, a take's walk to `?mode=review&take=`, a bare /play to the workspace (Play's own page is always asked for with a query: playHref writes `?cut=1`). A 9:16 cut presents tall.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Diffstat:
Aumtool/app/api/report/readiness/route.ts | 12++++++++++++
Mumtool/components/articles/ArticlePage.tsx | 2+-
Mumtool/components/projects/ProjectView.tsx | 17+++++++++++++----
Mumtool/components/projects/ReportProject.tsx | 29++++++++++++++++++++++++-----
Mumtool/components/projects/cutApp/CutApp.tsx | 4++++
Dumtool/components/projects/present/PresentPage.tsx | 36------------------------------------
Mumtool/components/projects/present/PresentView.tsx | 26++++++++++++++++++++++++--
Mumtool/components/projects/report/ReportTabBody.tsx | 23++++++++++++++++++++---
Mumtool/components/projects/workspace/BlockStrip.tsx | 11++++++++++-
Aumtool/components/projects/workspace/ReadinessBar.tsx | 111+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aumtool/components/projects/workspace/ReviewPass.tsx | 375+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/components/projects/workspace/Workspace.tsx | 253++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------
Mumtool/components/projects/workspace/WorkspacePage.tsx | 37++++++++++++++++++++++++++++++++-----
Mumtool/components/projects/workspace/WorkspaceTop.tsx | 103+++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------
Mumtool/lib/hrefs.test.mjs | 11++++++++++-
Mumtool/lib/hrefs.ts | 39+++++++++++++++++++++++++++++++++------
Mumtool/lib/inbox/projectCalls.ts | 5+++++
Aumtool/lib/inbox/readiness.mjs | 115+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aumtool/lib/inbox/readiness.ts | 58++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/lib/pieces/article.ts | 15+++++++++------
Mumtool/lib/pieces/tabs.mjs | 82+++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------
Mumtool/lib/pieces/tabs.test.mjs | 44++++++++++++++++++++++++++++++--------------
Mumtool/lib/projects/report.mjs | 5+++--
Mumtool/lib/report/present.mjs | 4+++-
Mumtool/lib/report/reviewPass.mjs | 60++++++------------------------------------------------------
Aumtool/lib/report/reviewPassModel.mjs | 59+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
26 files changed, 1323 insertions(+), 213 deletions(-)

diff --git a/umtool/app/api/report/readiness/route.ts b/umtool/app/api/report/readiness/route.ts @@ -0,0 +1,12 @@ +import { projectRef } from "@/lib/projects"; +import { readinessOf } from "@/lib/inbox/readiness"; + +export const dynamic = "force-dynamic"; + +// THE READINESS BAR as JSON (lib/inbox/readiness.ts; the workspace's row under its top bar): GET ?project=<id> -> +// { project, pills: [{ id, label, state: bad|count|ok|none, count, title, href }] }. Read-only: it writes nothing. +export async function GET(request: Request) { + const project = await projectRef(new URL(request.url).searchParams.get("project") ?? ""); + if (!project) return Response.json({ error: "no such project" }, { status: 404 }); + return Response.json(await readinessOf(project), { headers: { "cache-control": "no-store" } }); +} diff --git a/umtool/components/articles/ArticlePage.tsx b/umtool/components/articles/ArticlePage.tsx @@ -144,7 +144,7 @@ export default async function ArticlePage({ // A note: the article's own opens the reader; a note on the video project // opens where its anchor is drawn. const articleNote = !!sp.note && !!notes.doc?.notes.some((n) => n.id === sp.note); - const noteTab = sp.note && !sp.tab && !articleNote && videoRef ? await projectNoteTab(videoRef.dir, sp.note) : null; + const noteTab = sp.note && !sp.tab && !articleNote && videoRef ? await projectNoteTab(videoRef.dir, sp.note, { piece: "article" }) : null; const tab = articleTabOf(sp, { noteTab }); // `?project=` is carried from tab to tab only when it is not the article's Cut. diff --git a/umtool/components/projects/ProjectView.tsx b/umtool/components/projects/ProjectView.tsx @@ -1,4 +1,5 @@ -import { notFound } from "next/navigation"; +import { notFound, permanentRedirect } from "next/navigation"; +import { workspaceHref } from "@/lib/hrefs"; import type { ProjectRef } from "@/lib/project-types"; import SongProject from "./SongProject"; import CutPage from "./CutPage"; @@ -15,7 +16,6 @@ import VoicesPage from "./VoicesPage"; import ReviewPage from "./ReviewPage"; import ClipDeckPage from "./ClipDeckPage"; import PlayCutPage from "./PlayCutPage"; -import PresentPage from "./present/PresentPage"; import OpenInDraftPage from "./OpenInDraftPage"; import ReelPlayPage from "./reel/ReelPlayPage"; import ReelWalkPage from "./reel/ReelWalkPage"; @@ -79,7 +79,10 @@ export default async function ProjectView({ // `/projects/<project>/takes/<take>/open` -- open a saved version in the draft (it asks first, L3). // The take walk's and a take's bench's old addresses (`…/takes/<take>/walk`, `…/takes/<take>/clip/<id>`) // are that page too: every edit lands in the draft, so a version is opened in it before its clips are walked. - if (rest.length === 3 && rest[0] === "takes" && (rest[2] === "open" || rest[2] === "walk")) return <OpenInDraftPage project={project} take={rest[1]} search={search} />; + // The take walk is the version's REVIEW PASS now (umtool redesign L7b): watched block by block, read-only, + // its verdict at the end, "Open in draft" to change it. A 308: the address means that for good. + if (rest.length === 3 && rest[0] === "takes" && rest[2] === "walk" && isTakeId(rest[1])) permanentRedirect(workspaceHref(project.id, { mode: "review", take: rest[1] })); + if (rest.length === 3 && rest[0] === "takes" && rest[2] === "open") return <OpenInDraftPage project={project} take={rest[1]} search={search} />; if (rest.length === 4 && rest[0] === "takes" && rest[2] === "clip") { if (!isTakeId(rest[1])) return notFound(); return <OpenInDraftPage project={project} take={rest[1]} clip={rest[3]} search={search} />; @@ -111,7 +114,13 @@ export default async function ProjectView({ return <ReelWalkPage project={project} reel={search.reel} take={search.take} beat={search.beat} changed={search.changed === "1"} />; } // `/projects/<project>/present` (and `?take=<id>`) -- the cut as slides, navigated like a deck (present mode). - if (rest.length === 1 && rest[0] === "present") return <PresentPage project={project} take={search.take} bare={search.cut === "1"} />; + // Present mode is the workspace's (umtool redesign L7b): `?mode=present`, the take kept, the slide's `#id` kept + // by the browser across the redirect. A 308. + if (rest.length === 1 && rest[0] === "present") permanentRedirect(workspaceHref(project.id, { mode: "present", take: search.take || null })); + // A BARE `/play` is the workspace (L7b, a 308): the draft playing is its viewer. Play's own page -- its notes + // column, the reel strip's edits, the assistant -- is asked for with a query (`?cut=1`, `?take=`, `?clip=`, + // `?note=`; lib/hrefs.ts playHref writes one always) until the workspace holds all of it. + if (rest.length === 1 && rest[0] === "play" && Object.keys(search).length === 0) permanentRedirect(workspaceHref(project.id)); if (rest.length === 1 && rest[0] === "play") return <PlayCutPage project={project} take={search.take} bare={search.cut === "1"} note={search.note} clip={search.clip} at={search.at} />; return notFound(); } diff --git a/umtool/components/projects/ReportProject.tsx b/umtool/components/projects/ReportProject.tsx @@ -2,9 +2,10 @@ import AppShell from "@/components/shell/AppShell"; import PieceFrame from "@/components/piece/PieceFrame"; import { readPieceFrame } from "@/lib/pieces/frame"; import Link from "next/link"; +import { permanentRedirect } from "next/navigation"; import { projectHref, projectsHref, workspaceHref } from "@/lib/hrefs"; import { projectNoteTab } from "@/lib/pieces/article"; -import { PIECE_TABS, tabOf } from "@/lib/pieces/tabs.mjs"; +import { PIECE_FOLDED, PIECE_TABS, PIECE_VIEWS, PIECE_VIEW_IDS, tabOf } from "@/lib/pieces/tabs.mjs"; import type { ProjectRef } from "@/lib/project-types"; import DeleteProject from "./DeleteProject"; import ReportTabBody, { reportCounts, reportStatus } from "./report/ReportTabBody"; @@ -58,6 +59,17 @@ export default async function ReportProject({ } const m = detail.manifest; + // The tabs that folded (L7b: Build and Media into Deliver) and the workspace's own tab are other addresses now: + // a 308, the rest of the query kept (`note` last). + const folded = search.tab ? (PIECE_FOLDED as Record<string, string>)[search.tab] : undefined; + if (folded || search.tab === "workspace") { + const { tab: _t, note, ...rest } = search; + permanentRedirect( + folded + ? projectHref(project.id, { ...(rest as Record<string, string>), tab: folded, note: note ?? null }) + : workspaceHref(project.id), + ); + } const tab = tabOf(search, { noteTab: !search.tab ? await projectNoteTab(project.dir, search.note) : null }); const frame = await readPieceFrame(project); // The head's one primary row (lane/ui-simplify): Play the newest take, on every tab, and the status line @@ -73,9 +85,10 @@ export default async function ReportProject({ <PieceFrame crumbs={[{ href: projectsHref(), label: "Projects" }, { label: project.id }, { label: typeof m.title === "string" && m.title ? m.title : project.id }]} frame={frame} - tab={tab} - tabs={PIECE_TABS.map((t) => ({ ...t, href: projectHref(project.id, { tab: t.id }) }))} - counts={await reportCounts(detail, project.dir)} + // The Overview and the cut's list are the workspace's views (out of the tab bar): its tab is lit on them. + tab={PIECE_VIEW_IDS.includes(tab) ? "workspace" : tab} + tabs={PIECE_TABS.map((t) => ({ ...t, href: t.id === "workspace" ? workspaceHref(project.id) : projectHref(project.id, { tab: t.id }) }))} + counts={await reportCounts(detail, project.dir).then((c) => ({ workspace: c.cut, deliver: c.media, sources: c.sources }))} note={primaryStatus(working, openNotes, reportStatus(detail))} primary={<ProjectPrimary project={project.id} detail={detail} latest={working?.latest?.id ?? null} words={latestWords(working)} />} more={ @@ -86,12 +99,18 @@ export default async function ReportProject({ <Link href={workspaceHref(project.id)} prefetch={false} data-primary-workspace="" className="block rounded-[2px] px-2 py-1 text-[12.5px] text-text-2 hover:bg-panel-2 hover:text-text"> Open the workspace </Link> + {/* The views out of the tab bar (lib/pieces/tabs.mjs PIECE_VIEWS): what the workspace does not hold yet. */} + {PIECE_VIEWS.map((v) => ( + <Link key={v.id} href={projectHref(project.id, { tab: v.id })} prefetch={false} data-piece-view={v.id} className="block rounded-[2px] px-2 py-1 text-[12.5px] text-text-2 hover:bg-panel-2 hover:text-text"> + {v.label} + </Link> + ))} <DeleteProject project={project.id} /> </> } > <RememberCut project={project.id} title={typeof m.title === "string" && m.title ? m.title : project.id} /> - <ReportTabBody project={project} detail={detail} search={search} tab={tab} frame={frame} /> + <ReportTabBody project={project} detail={detail} search={search} tab={tab} frame={frame} fold /> </PieceFrame> </div> ); diff --git a/umtool/components/projects/cutApp/CutApp.tsx b/umtool/components/projects/cutApp/CutApp.tsx @@ -77,6 +77,8 @@ export default function CutApp({ const isPlay = useCallback((pathname: string) => pathname === home || pathname === playPath(project), [home, project]); const router = useRouter(); const [view, setView] = useState<View>({ kind: "play" }); + const viewKind = useRef<View["kind"]>("play"); + viewKind.current = view.kind; const [bench, setBench] = useState<{ key: string; state: "loading" | "ready" | "error"; bench?: Bench; error?: string } | null>(null); // How many entries the app pushed past Play: "Back to the cut" goes back that many. const depth = useRef(0); @@ -187,6 +189,8 @@ export default function CutApp({ const st = (window.history.state ?? {}) as { cutApp?: number }; if (isPlay(p)) { depth.current = 0; + // A history step that stays on the home view (the workspace's mode, present's slides) is not a return. + if (viewKind.current === "play") return; setView({ kind: "play" }); setBench(null); returned(); diff --git a/umtool/components/projects/present/PresentPage.tsx b/umtool/components/projects/present/PresentPage.tsx @@ -1,36 +0,0 @@ -import Link from "next/link"; -import { playHref, presentHref } from "@/lib/hrefs"; -import { pieceHrefOfProject } from "@/lib/pieces/article"; -import type { ProjectRef } from "@/lib/project-types"; -import { presentPayload } from "@/lib/report/present.mjs"; -import PresentView, { type PresentPayload } from "./PresentView"; - -// `/projects/<project>/present` (and `?take=<id>`, `?cut=1`) -- PRESENT MODE (umtool/docs/knobs.md, "Present -// mode"): the cut as slides, one at a time, navigated like a deck. lib/report/present.mjs makes the payload (Play's -// view cut into slides); PresentView.tsx shows it. umtool is the operator's, so the payload carries what the build -// censors as data the viewer can toggle (`canUncensor`). - -export default async function PresentPage({ project, take, bare = false }: { project: ProjectRef; take?: string; bare?: boolean }) { - const [payload, back] = await Promise.all([presentPayload(project, { take: take || null, bare, canUncensor: true }), pieceHrefOfProject(project.id, { tab: "cut" })]); - if ("error" in payload) { - return ( - <main data-present-error="" className="flex h-full flex-col items-start gap-2 p-6 text-[13px]"> - <p className="text-reject-text">{String(payload.error)}</p> - <p className="flex gap-3"> - {take && ( - <Link href={presentHref(project.id)} className="ink-link"> - present the latest cut instead - </Link> - )} - <Link href={playHref(project.id)} className="ink-link"> - Play the cut - </Link> - <Link href={back} className="ink-link"> - ‹ {project.id} - </Link> - </p> - </main> - ); - } - return <PresentView payload={payload as unknown as PresentPayload} back={back} playHref={playHref(project.id, { take: take || null, bare })} />; -} diff --git a/umtool/components/projects/present/PresentView.tsx b/umtool/components/projects/present/PresentView.tsx @@ -163,7 +163,18 @@ function useFitted(box: Box) { return { ref, size }; } -export default function PresentView({ payload, back, playHref }: { payload: PresentPayload; back: string; playHref: string }) { +export default function PresentView({ + payload, + back, + playHref, + onExit, +}: { + payload: PresentPayload; + back: string; + playHref: string; + /** The workspace's present mode (umtool redesign L7b): Esc (the settings closed) and ‹ Edit go back to Edit. */ + onExit?: () => void; +}) { const { slides, sections, box } = payload; const project = payload.project; const take = payload.take?.id ?? null; @@ -172,6 +183,10 @@ export default function PresentView({ payload, back, playHref }: { payload: Pres const [index, setIndex] = useState(0); const [paused, setPaused] = useState(false); const [drawer, setDrawer] = useState(false); + const drawerRef = useRef(drawer); + drawerRef.current = drawer; + const exitRef = useRef(onExit); + exitRef.current = onExit; const [settings, setSettings] = useState<PresentSettings>(payload.settings); const [loaded, setLoaded] = useState(false); const canUncensor = payload.capabilities.canUncensor; @@ -233,7 +248,9 @@ export default function PresentView({ payload, back, playHref }: { payload: Pres const typing = !!t && ((t.tagName === "INPUT" && !["checkbox", "radio", "button"].includes((t as HTMLInputElement).type)) || t.tagName === "TEXTAREA" || t.isContentEditable); if (e.key === "Escape") { if (t && t !== document.body) t.blur(); - setDrawer(false); + // The settings open: Esc closes them. Closed: back to the workspace's Edit, when presenting in it. + if (drawerRef.current || !exitRef.current) setDrawer(false); + else exitRef.current(); return; } if (typing) return; @@ -377,6 +394,11 @@ export default function PresentView({ payload, back, playHref }: { payload: Pres <button type="button" data-present-settings-open="" aria-expanded={drawer} className="ml-auto rounded px-1.5 py-0.5 text-white/60 hover:bg-white/10 hover:text-white" onClick={() => setDrawer((d) => !d)}> Settings · s </button> + {onExit && ( + <button type="button" data-present-exit="" className="rounded px-1.5 py-0.5 text-white/60 hover:bg-white/10 hover:text-white" onClick={onExit} title="back to the workspace's Edit (Esc)"> + Edit · Esc + </button> + )} </div> {drawer && ( <SettingsDrawer diff --git a/umtool/components/projects/report/ReportTabBody.tsx b/umtool/components/projects/report/ReportTabBody.tsx @@ -47,8 +47,17 @@ export function reportStatus(detail: ClipDetail): string { export default function ReportTabBody({ tab, frame, + fold = false, ...props -}: ReportTabProps & { tab: string; frame: PieceFrame }) { +}: ReportTabProps & { + tab: string; + frame: PieceFrame; + /** + * The project piece's four tabs (L7b, lib/pieces/tabs.mjs PIECE_FOLDED): Deliver draws what Build and Media + * held, above its own. An article piece keeps the seven (its Build and Media tabs are their own). + */ + fold?: boolean; +}) { const m = props.detail.manifest; return ( <NotesProvider target={{ project: props.project.id }}> @@ -56,8 +65,16 @@ export default function ReportTabBody({ <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 === "media" && !fold && <MediaTab {...props} />} + {tab === "build" && !fold && <BuildTab {...props} />} + {tab === "deliver" && fold && ( + <> + {/* What was Build: the build chain and the final mp4. */} + <BuildTab {...props} /> + {/* What was Media: the drafted fields, the upload's text, the on-screen panel. */} + <MediaTab {...props} /> + </> + )} {tab === "deliver" && <DeliverTab {...props} />} {tab === "sources" && <SourcesTab {...props} />} {tab === "history" && <HistoryTab {...props} />} diff --git a/umtool/components/projects/workspace/BlockStrip.tsx b/umtool/components/projects/workspace/BlockStrip.tsx @@ -55,6 +55,7 @@ export default function BlockStrip({ onSelect, onMove, plus, + marks = null, }: { blocks: Block[]; selected: string | null; @@ -64,8 +65,10 @@ export default function BlockStrip({ onSelect: (id: string) => void; /** Move block `id` to timeline index `to`. */ onMove: (id: string, at: number, to: number) => void; - /** The + at the end: what it opens. */ + /** The + at the end: what it opens (none outside Edit). */ plus: React.ReactNode; + /** The review pass's answers (L7b): a block kept or to fix is marked. */ + marks?: Map<string, { mark: "keep" | "fix"; note: string | null }> | null; }) { const ref = useRef<HTMLDivElement | null>(null); const [drag, setDrag] = useState<string | null>(null); @@ -102,6 +105,7 @@ export default function BlockStrip({ data-ws-block-at={b.at ?? ""} data-ws-block-now={b.id === playing ? "" : undefined} data-ws-block-rejected={b.rejected ? "" : undefined} + data-ws-block-review={marks ? (marks.get(b.id)?.mark ?? "") : undefined} draggable={movable} onDragStart={(e) => { if (!movable) return; @@ -143,6 +147,11 @@ export default function BlockStrip({ {b.id === playing && <span aria-hidden className="absolute inset-x-0 top-0 h-0.5 bg-[var(--color-signal)]" />} <span className="flex items-baseline gap-1"> <span className={cn("truncate font-mono text-[11.5px] font-medium text-text", b.rejected && "line-through")}>{b.id}</span> + {marks?.get(b.id) && ( + <span aria-label={marks.get(b.id)!.mark === "keep" ? "kept" : "to fix"} className={cn("shrink-0 text-[11px] font-semibold", marks.get(b.id)!.mark === "keep" ? "text-kept-text" : "text-doubt-text")}> + {marks.get(b.id)!.mark === "keep" ? "✓" : "✎"} + </span> + )} <span className="ml-auto shrink-0 text-[10px] uppercase tracking-[0.06em] text-muted">{TYPE_WORD[b.type] ?? b.type}</span> </span> <span className="truncate text-[11px] leading-tight text-text-2">{b.heading || " "}</span> diff --git a/umtool/components/projects/workspace/ReadinessBar.tsx b/umtool/components/projects/workspace/ReadinessBar.tsx @@ -0,0 +1,111 @@ +"use client"; + +import Link from "next/link"; +import { useCallback, useEffect, useMemo, useState } from "react"; +import { cn } from "@/lib/utils"; +import type { Readiness, ReadinessPill } from "@/lib/inbox/readiness"; +import { MANIFEST_CHANGED } from "../timelineApi"; + +export type { Readiness }; + +// --------------------------------------------------------------------------- +// THE READINESS BAR (umtool redesign L7b): under the workspace's top bar, one pill each for the quote check, the +// links, the captures, the render and X's jar -- ✓, a count, ! or — -- read from what the Inbox reads for this +// piece (GET /api/report/readiness, lib/inbox/readiness.ts) and read again after a write here. Each pill is a +// click to its fix or its page; a clip with no media fetched selects that block. Read-only. +// --------------------------------------------------------------------------- + +const GLYPH = { ok: "✓", bad: "!", none: "—" } as const; +const TONE = { + ok: "border-[color-mix(in_srgb,var(--color-good)_40%,transparent)] text-kept-text", + count: "border-[color-mix(in_srgb,var(--color-dirty)_45%,transparent)] text-doubt-text", + bad: "border-[color-mix(in_srgb,var(--color-bad)_55%,transparent)] bg-[color-mix(in_srgb,var(--color-bad)_10%,transparent)] text-reject-text", + none: "border-seam-2 text-muted", +} as const; + +export default function ReadinessBar({ + project, + initial, + missing, + onSelect, +}: { + project: string; + initial: Readiness | null; + /** The clips with no media fetched (the strip's "no media"): the captures pill counts them. */ + missing: string[]; + onSelect: (block: string) => void; +}) { + const [got, setGot] = useState<Readiness | null>(initial); + const read = useCallback(async () => { + try { + const r = await fetch(`/api/report/readiness?project=${encodeURIComponent(project)}`, { cache: "no-store" }); + if (r.ok) setGot((await r.json()) as Readiness); + } catch { + // The bar stays as it was. + } + }, [project]); + useEffect(() => { + if (!initial) void read(); + }, [initial, read]); + useEffect(() => { + let t: ReturnType<typeof setTimeout> | null = null; + const on = (e: Event) => { + if ((e as CustomEvent).detail?.project !== project) return; + if (t) clearTimeout(t); + t = setTimeout(() => void read(), 400); + }; + window.addEventListener(MANIFEST_CHANGED, on); + return () => { + window.removeEventListener(MANIFEST_CHANGED, on); + if (t) clearTimeout(t); + }; + }, [project, read]); + + const pills = useMemo<ReadinessPill[]>(() => { + const list = got?.pills ?? []; + return list.map((p) => { + if (p.id !== "captures" || !missing.length || p.state === "bad") return p; + const why = `${missing.slice(0, 6).join(", ")}${missing.length > 6 ? ` and ${missing.length - 6} more` : ""}: no media fetched`; + return { ...p, state: "count", count: (p.state === "count" ? p.count : 0) + missing.length, title: p.state === "count" ? `${p.title} · ${why}` : why, select: missing[0] }; + }); + }, [got, missing]); + if (!pills.length) return null; + return ( + <nav aria-label="Readiness" data-ws-readiness="" className="flex flex-wrap items-center gap-1.5 border-b border-seam bg-ground px-3 py-1 text-[11.5px]"> + {pills.map((p) => { + const glyph = p.state === "count" ? String(p.count) : GLYPH[p.state]; + const cls = cn("inline-flex items-center gap-1.5 rounded-full border px-2 py-[1px] leading-[18px] hover:brightness-125", TONE[p.state]); + const body = ( + <> + <span className="font-mono font-semibold tabular-nums">{glyph}</span> + <span className="text-text-2">{p.label}</span> + </> + ); + const attrs = { "data-ready-pill": p.id, "data-ready-state": p.state, "data-ready-count": String(p.count), title: p.title }; + if (p.select) { + return ( + <button key={p.id} type="button" className={cls} onClick={() => onSelect(p.select!)} {...attrs}> + {body} + </button> + ); + } + if (!p.href) { + return ( + <span key={p.id} className={cls} {...attrs}> + {body} + </span> + ); + } + return /^https?:/.test(p.href) ? ( + <a key={p.id} href={p.href} target="_blank" rel="noreferrer" className={cls} {...attrs}> + {body} + </a> + ) : ( + <Link key={p.id} href={p.href} prefetch={false} className={cls} {...attrs}> + {body} + </Link> + ); + })} + </nav> + ); +} diff --git a/umtool/components/projects/workspace/ReviewPass.tsx b/umtool/components/projects/workspace/ReviewPass.tsx @@ -0,0 +1,375 @@ +"use client"; + +import Link from "next/link"; +import { useCallback, useEffect, useMemo, useRef, useState } from "react"; +import { buttonVariants } from "@/components/ui/button"; +import { cn } from "@/lib/utils"; +import { openInDraftHref } from "@/lib/hrefs"; +import { blockAnswer, reviewProgress } from "@/lib/report/reviewPassModel.mjs"; +import AnchoredNotes from "@/components/notes/AnchoredNotes"; +import { useSharedNotes } from "@/components/notes/NotesProvider"; +import { writeWalkVerdict } from "../bench/walkVerdict"; +import { announceManifestChanged } from "../timelineApi"; +import VersionVerdict from "../review/VersionVerdict"; +import type { PlayEntry } from "../review/PlayCut"; + +// --------------------------------------------------------------------------- +// THE REVIEW PASS (umtool redesign L7b; the workspace's `?mode=review`): the inspector hidden, the viewer playing +// the draft block by block, and each block answered here -- +// +// Keep k a clip: its walk verdict `confirmed` (the bench's writer, bench/walkVerdict.ts); a post or a card: +// `keep` in review-pass.json (lib/report/reviewPass.mjs) +// Fix f says what needs fixing: a clip's `incorrect` with that correction; a post's or a card's `fix` note +// Note n the notes composer, anchored to the block (notes.json, `umtool notes`) +// +// -- then on to the next block, playing. After the last, the VERDICT for the draft (saved as a version first when +// it has edits: a verdict is a version's) or for the version being reviewed: Like · Maybe · No, L4's writer +// (takes/verdicts.json, `umtool takes verdict`). "4 / 12 reviewed"; it resumes on the first block with no answer. +// A version (`?take=`) is read-only: its blocks are watched and noted, never marked -- Open in draft to change it. +// --------------------------------------------------------------------------- + +export type Answer = { mark: "keep" | "fix"; note: string | null }; +type Mark = { mark: "keep" | "fix"; note?: string; at: string }; + +/** The pass's state: the marks (review-pass.json), each block's answer, the progress, and the writers. */ +export function useReviewPass(project: string, entries: PlayEntry[], on: boolean) { + const [marks, setMarks] = useState<Record<string, Mark>>({}); + const [loaded, setLoaded] = useState(false); + // A clip's answer as just written, until the draft is read again (MANIFEST_CHANGED) and its verdict is in it. + const [written, setWritten] = useState<Record<string, Answer>>({}); + useEffect(() => setWritten({}), [entries]); + useEffect(() => { + if (!on) return; + let live = true; + void fetch(`/api/report/review-pass?project=${encodeURIComponent(project)}`, { cache: "no-store" }) + .then((r) => r.json()) + .then((j: { marks?: Record<string, Mark> }) => { + if (!live) return; + setMarks(j.marks ?? {}); + setLoaded(true); + }) + .catch(() => live && setLoaded(true)); + return () => { + live = false; + }; + }, [project, on]); + + const seen = useMemo( + () => + entries.map((e) => { + const w = written[e.id]; + if (!w || e.type !== "clip") return e; + return { ...e, review: { verdict: w.mark === "keep" ? "confirmed" : "incorrect", reason: null, correction: w.note, rejectNote: null } }; + }), + [entries, written], + ); + const progress = useMemo(() => reviewProgress(seen, marks) as { done: number; total: number; next: string | null; ids: string[] }, [seen, marks]); + const answers = useMemo(() => { + const m = new Map<string, Answer>(); + for (const e of seen) { + const a = blockAnswer(e, marks) as Answer | null; + if (a) m.set(e.id, a); + } + return m; + }, [seen, marks]); + + /** One block answered: a clip through the walk's writer, anything else into review-pass.json. */ + const answer = useCallback( + async (e: PlayEntry, mark: "keep" | "fix", note: string | null): Promise<string | null> => { + if (e.type === "clip") { + const w = await writeWalkVerdict(project, e.id, mark === "keep" ? { verdict: "confirmed" } : { verdict: "incorrect", correction: note ?? "" }); + if (!w.ok) return w.stale ? "the draft changed since — try again" : w.error; + setWritten((x) => ({ ...x, [e.id]: { mark, note } })); + announceManifestChanged(project); + return null; + } + const r = await fetch("/api/report/review-pass", { + method: "POST", + headers: { "content-type": "application/json" }, + body: JSON.stringify({ project, block: e.id, mark, note: note ?? undefined }), + }); + const j = (await r.json().catch(() => ({}))) as { error?: string; doc?: { marks?: Record<string, Mark> } }; + if (!r.ok) return j.error ?? `HTTP ${r.status}`; + setMarks(j.doc?.marks ?? {}); + return null; + }, + [project], + ); + return { marks, loaded, progress, answers, answer }; +} + +export type ReviewPassState = ReturnType<typeof useReviewPass>; + +const VERDICTS = [ + { id: "like", label: "Like" }, + { id: "maybe", label: "Maybe" }, + { id: "no", label: "No" }, +] as const; + +/** The draft's verdict: saved as a version first (a verdict is a version's), then judged with L4's writer. */ +function DraftVerdict({ project, draft }: { project: string; draft: { line: string; parent: string | null; edits: number | null } | null }) { + const clean = !!draft?.parent && draft.edits === 0; + const [saved, setSaved] = useState<string | null>(clean ? draft!.parent : null); + const [busy, setBusy] = useState(false); + const [err, setErr] = useState<string | null>(null); + if (saved) { + return ( + <span className="inline-flex flex-wrap items-center gap-2" data-review-verdict-take={saved}> + <span className="text-[12px] text-text-2"> + {clean ? ( + <> + the draft is <span className="font-mono text-text">{saved}</span> (no edits since): + </> + ) : ( + <> + saved as <span className="font-mono text-text">{saved}</span>: + </> + )} + </span> + <VersionVerdict project={project} take={saved} /> + </span> + ); + } + const judge = async (v: (typeof VERDICTS)[number]["id"]) => { + setBusy(true); + setErr(null); + try { + const s = await fetch("/api/report/takes/save", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ project }) }); + const sj = (await s.json().catch(() => ({}))) as { id?: string; error?: string }; + if (!s.ok || !sj.id) throw new Error(sj.error ?? `HTTP ${s.status}`); + const r = await fetch("/api/report/takes/verdict", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ project, take: sj.id, verdict: v }) }); + const rj = (await r.json().catch(() => ({}))) as { error?: string }; + if (!r.ok) throw new Error(rj.error ?? `HTTP ${r.status}`); + setSaved(sj.id); + } catch (e) { + setErr(e instanceof Error ? e.message : String(e)); + } finally { + setBusy(false); + } + }; + return ( + <span className="inline-flex flex-wrap items-center gap-1.5" role="group" aria-label="the draft's verdict"> + <span className="text-[12px] text-text-2" title="a verdict is a version's: the draft is saved as the next version first (umtool takes save), then judged (umtool takes verdict)"> + {draft?.line ?? "The draft"} — saved as a version, then: + </span> + {VERDICTS.map((v) => ( + <button key={v.id} type="button" disabled={busy} onClick={() => void judge(v.id)} data-review-verdict={v.id} className={buttonVariants({ variant: "outline", size: "sm" })}> + {v.label} + </button> + ))} + {err && ( + <span role="alert" className="text-[11.5px] text-reject-text"> + {err} + </span> + )} + </span> + ); +} + +const TYPE_WORD: Record<string, string> = { clip: "Clip", post: "Post", teaser: "Card", card: "Card", video: "Video" }; + +export default function ReviewPass({ + project, + rv, + entry, + atEnd, + take, + draft, + onPrev, + onNext, + onAnswered, + onExit, +}: { + project: string; + rv: ReviewPassState; + /** The block under review (null at the end). */ + entry: PlayEntry | null; + atEnd: boolean; + /** A version reviewed read-only, or null for the draft. */ + take: { id: string; label: string } | null; + draft: { line: string; parent: string | null; edits: number | null } | null; + onPrev: () => void; + onNext: () => void; + /** A block was answered: the pass moves on (and plays the next). */ + onAnswered: () => void; + onExit: () => void; +}) { + const notes = useSharedNotes({ project }); + const [fixing, setFixing] = useState(false); + const [fixText, setFixText] = useState(""); + const [noting, setNoting] = useState(false); + const [busy, setBusy] = useState(false); + const [err, setErr] = useState<string | null>(null); + const id = entry?.id ?? null; + useEffect(() => { + setFixing(false); + setNoting(false); + setErr(null); + setFixText(""); + }, [id]); + const answer = id ? (rv.answers.get(id) ?? null) : null; + const readOnly = !!take; + + const go = useCallback( + async (mark: "keep" | "fix", note: string | null) => { + if (!entry || readOnly || busy) return; + setBusy(true); + setErr(null); + const e = await rv.answer(entry, mark, note); + setBusy(false); + if (e) return setErr(e); + setFixing(false); + onAnswered(); + }, + [entry, readOnly, busy, rv, onAnswered], + ); + const openFix = useCallback(() => { + if (!entry || readOnly) return; + setNoting(false); + setFixText(answer?.mark === "fix" ? (answer.note ?? "") : ""); + setFixing(true); + }, [entry, readOnly, answer]); + + // k / f / n: the block's answers (the workspace keeps Space and ← →). + const keys = useRef({ go, openFix, setNoting }); + keys.current = { go, openFix, setNoting }; + useEffect(() => { + const onKey = (ev: KeyboardEvent) => { + if (ev.metaKey || ev.ctrlKey || ev.altKey) return; + const t = ev.target as HTMLElement | null; + if (t?.closest("input, textarea, select, [contenteditable=true], [role=dialog]")) return; + if (ev.key === "k" || ev.key === "K") void keys.current.go("keep", null); + else if (ev.key === "f" || ev.key === "F") keys.current.openFix(); + else if (ev.key === "n" || ev.key === "N") keys.current.setNoting(true); + else return; + ev.preventDefault(); + }; + window.addEventListener("keydown", onKey); + return () => window.removeEventListener("keydown", onKey); + }, []); + + const { done, total } = rv.progress; + const btn = (variant: "go" | "outline" | "quiet") => cn(buttonVariants({ variant, size: "md" })); + return ( + <div className="flex min-h-0 flex-col" data-review-pass={take?.id ?? "draft"} data-review-progress={`${done}/${total}`} data-review-current={atEnd ? "end" : (id ?? "")}> + <div className="flex flex-wrap items-baseline gap-x-2 gap-y-1 border-b border-seam px-3 py-2"> + <span className="micro">Review pass</span> + {take && ( + <span className="font-mono text-[12px] text-text" title={take.label}> + {take.id} · read-only + </span> + )} + <span className="font-mono text-[12px] tabular-nums text-text-2" data-review-count=""> + {done} / {total} reviewed + </span> + <span className="ml-auto inline-flex items-center gap-1"> + <button type="button" className={cn(buttonVariants({ variant: "outline", size: "sm" }), "min-w-8 font-mono")} onClick={onPrev} aria-label="the block before" title="the block before (←)" data-review-prev=""> + ‹ + </button> + <button type="button" className={cn(buttonVariants({ variant: "outline", size: "sm" }), "min-w-8 font-mono")} onClick={onNext} aria-label="the block after" title="the block after (→)" data-review-next=""> + › + </button> + </span> + </div> + <div className="min-h-0 flex-1 space-y-3 overflow-y-auto px-3 py-3"> + {atEnd || !entry ? ( + <section data-review-end="" className="space-y-3"> + <h2 className="m-0 text-[14px] font-semibold text-text">{done === total ? "Every block reviewed" : `${total - done} block${total - done === 1 ? "" : "s"} not reviewed`}</h2> + <div className="flex flex-wrap items-center gap-2"> + {take ? ( + <span className="inline-flex flex-wrap items-center gap-2" data-review-verdict-take={take.id}> + <span className="text-[12px] text-text-2"> + <span className="font-mono text-text">{take.id}</span> “{take.label}”: + </span> + <VersionVerdict project={project} take={take.id} /> + </span> + ) : ( + <DraftVerdict project={project} draft={draft} /> + )} + </div> + <div className="flex flex-wrap gap-2"> + {rv.progress.next && ( + <button type="button" className={btn("outline")} onClick={onNext} data-review-resume=""> + Back to {rv.progress.next} + </button> + )} + <button type="button" className={btn("quiet")} onClick={onExit} data-review-done=""> + Done — back to Edit + </button> + </div> + </section> + ) : ( + <section data-review-block={entry.id} data-review-answer={answer?.mark ?? ""} className="space-y-2.5"> + <div className="flex flex-wrap items-baseline gap-2"> + <span className="micro">{TYPE_WORD[entry.type] ?? entry.type}</span> + <span className="font-mono text-[13px] font-medium text-text">{entry.id}</span> + {answer && ( + <span className={cn("text-[12px]", answer.mark === "keep" ? "text-kept-text" : "text-doubt-text")} data-review-said=""> + {answer.mark === "keep" ? "kept" : `fix: ${answer.note ?? ""}`} + </span> + )} + </div> + {(entry.quote || entry.heading) && <p className="m-0 font-serif text-[13.5px] leading-snug text-text-2">{entry.type === "clip" && entry.quote ? `“${entry.quote}”` : entry.heading}</p>} + <div className="flex flex-wrap items-center gap-1.5"> + <button type="button" className={btn("go")} disabled={readOnly || busy} onClick={() => void go("keep", null)} data-review-keep="" title={readOnly ? "a version is read-only: Open in draft to mark its blocks" : entry.type === "clip" ? "keep it: the walk's verdict, confirmed (k)" : "keep it (k): review-pass.json"}> + Keep <kbd>k</kbd> + </button> + <button type="button" className={btn("outline")} disabled={readOnly || busy} onClick={openFix} data-review-fix="" title={readOnly ? "a version is read-only: Open in draft to mark its blocks" : "say what needs fixing (f)"}> + Fix <kbd>f</kbd> + </button> + <button type="button" className={btn("quiet")} onClick={() => setNoting((x) => !x)} aria-pressed={noting} data-review-note="" title="a note on this block (n): notes.json, for you or an agent (umtool notes)"> + Note <kbd>n</kbd> + </button> + {readOnly && take && ( + <Link href={openInDraftHref(project, take.id)} prefetch={false} className="ink-link text-[12px]" data-review-open-draft=""> + Open in draft + </Link> + )} + </div> + {fixing && ( + <form + className="space-y-1.5" + data-review-fix-form="" + onSubmit={(e) => { + e.preventDefault(); + if (fixText.trim()) void go("fix", fixText.trim()); + }} + > + <textarea + autoFocus + value={fixText} + onChange={(e) => setFixText(e.target.value)} + onKeyDown={(e) => { + if (e.key === "Escape") setFixing(false); + if (e.key === "Enter" && !e.shiftKey) { + e.preventDefault(); + if (fixText.trim()) void go("fix", fixText.trim()); + } + }} + rows={2} + placeholder={entry.type === "clip" ? "what needs fixing (the clip's correction)" : "what needs fixing"} + data-review-fix-text="" + className="w-full rounded-[3px] border border-seam-2 bg-ground px-2 py-1 text-[12.5px] text-text outline-none focus:border-[var(--color-signal)]" + /> + <span className="flex gap-1.5"> + <button type="submit" className={cn(buttonVariants({ variant: "go", size: "sm" }))} disabled={busy || !fixText.trim()} data-review-fix-save=""> + Save the fix + </button> + <button type="button" className={cn(buttonVariants({ variant: "quiet", size: "sm" }))} onClick={() => setFixing(false)}> + Cancel + </button> + </span> + </form> + )} + {noting && <AnchoredNotes key={entry.id} notes={notes} pin={{ kind: "entry", entry: entry.id }} startOpen />} + {err && ( + <p role="alert" className="m-0 text-[12px] text-reject-text" data-review-error=""> + {err} + </p> + )} + </section> + )} + </div> + </div> + ); +} diff --git a/umtool/components/projects/workspace/Workspace.tsx b/umtool/components/projects/workspace/Workspace.tsx @@ -4,7 +4,7 @@ import { useRouter } from "next/navigation"; import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import { buttonVariants } from "@/components/ui/button"; import { cn } from "@/lib/utils"; -import { clipBenchHref, postBenchHref } from "@/lib/hrefs"; +import { clipBenchHref, isWorkspaceMode, playHref, postBenchHref, workspaceHref, type WorkspaceMode } from "@/lib/hrefs"; import { runningTime, startOf } from "@/lib/report/playCut.mjs"; import { PlayStage, usePlayCore } from "../review/playCore"; import type { PlayViewData } from "../review/PlayCut"; @@ -17,6 +17,9 @@ import BlockStrip, { type Block } from "./BlockStrip"; import WorkspaceInspector from "./WorkspaceInspector"; import WorkspaceTop, { type UndoState } from "./WorkspaceTop"; import GeneratedBanner from "@/components/notes/GeneratedBanner"; +import PresentView, { type PresentPayload } from "../present/PresentView"; +import ReviewPass, { useReviewPass } from "./ReviewPass"; +import ReadinessBar, { type Readiness } from "./ReadinessBar"; // --------------------------------------------------------------------------- // THE WORKSPACE (umtool redesign L7a): a report video's ONE screen, at its own @@ -41,6 +44,14 @@ import GeneratedBanner from "@/components/notes/GeneratedBanner"; // (cutApp/CutApp.tsx, `home` the workspace's address) -- the viewer stays // mounted, paused, everything it composed kept -- and Back returns here. // +// THE MODES (L7b), in the address (`?mode=`; Edit is the bare one), each a history entry: +// Edit the above +// Review pass the inspector's column is the pass (ReviewPass.tsx): the viewer plays the block under review and +// stops at its end; Keep · Fix · Note (k f n) answer it and move on. A version (`?take=`) is +// reviewed read-only, its verdict at the end +// Present the viewer full screen as slides (present/PresentView.tsx, Present's own deck: arrows, the +// censor toggles), Esc back to Edit; a 9:16 cut presents tall +// // THE KEYS (the inspector's bench keeps its own while the focus is in it): // Space play / pause · ← → the block before / after · Alt+← → move the // selected block · E edit it in place · Esc nothing selected (the project's @@ -61,6 +72,8 @@ const KEYS: { keys: string; what: string }[] = [ { keys: "⌘⇧Z Ctrl+Y", what: "redo" }, { keys: "⌘K", what: "the command palette" }, { keys: "?", what: "these keys" }, + { keys: "k f n", what: "review pass: keep, fix (say what), a note on the block" }, + { keys: "Esc", what: "present: back to Edit" }, ]; type Timeline = { token: string | null; ids: string[] }; @@ -68,12 +81,23 @@ type Timeline = { token: string | null; ids: string[] }; export default function Workspace({ view: served, initialBlock = null, + initialAt = null, + initialMode = "edit", + presentInitial = null, + readiness = null, introWritten = null, hasLedger = false, generatedBy = null, }: { view: PlayViewData; initialBlock?: string | null; + /** `?at=`: seconds into the selected block (the bench's Back to the cut). */ + initialAt?: number | null; + initialMode?: "edit" | WorkspaceMode; + /** Present mode's slides, when the page opened on it (else read when it is entered). */ + presentInitial?: PresentPayload | null; + /** The readiness bar's pills as the page read them (ReadinessBar reads them again after a write). */ + readiness?: Readiness | null; introWritten?: unknown; hasLedger?: boolean; /** The manifest's `generatedBy`: a rebuild overwrites edits made here, said under the top bar. */ @@ -83,17 +107,50 @@ export default function Workspace({ const [view, setView] = useState(served); useEffect(() => setView(served), [served]); const project = view.project; + // A saved version reviewed or presented (`?take=`): read-only, its own view; Edit is the draft's page. + const take = view.take ? { id: view.take.id, label: view.take.label } : null; + const takeId = take?.id ?? null; const reloadSeq = useRef(0); const reloadView = useCallback(async () => { const mine = ++reloadSeq.current; try { - const r = await fetch(`/api/report/play-view?${new URLSearchParams({ project }).toString()}`, { cache: "no-store" }); + const r = await fetch(`/api/report/play-view?${new URLSearchParams({ project, ...(takeId ? { take: takeId } : {}) }).toString()}`, { cache: "no-store" }); const j = (await r.json()) as PlayViewData & { error?: string }; if (mine === reloadSeq.current && r.ok && !j.error) setView(j); } catch { // The view stays as it was. } - }, [project]); + }, [project, takeId]); + + // ---- the mode (L7b): Edit, Review pass, Present -- in the address, a history entry each ---------------------- + const [mode, setModeState] = useState<"edit" | WorkspaceMode>(initialMode); + const modeRef = useRef(mode); + modeRef.current = mode; + const setMode = useCallback( + (next: "edit" | WorkspaceMode) => { + if (next === modeRef.current) return; + // Edit of a version is the draft's: its own page. + if (next === "edit" && takeId) { + router.push(workspaceHref(project)); + return; + } + const u = new URL(window.location.href); + if (next === "edit") u.searchParams.delete("mode"); + else u.searchParams.set("mode", next); + if (next !== "present") u.hash = ""; + window.history.pushState(window.history.state, "", `${u.pathname}${u.search}${u.hash}`); + setModeState(next); + }, + [router, project, takeId], + ); + useEffect(() => { + const onPop = () => { + const m = new URL(window.location.href).searchParams.get("mode"); + setModeState(isWorkspaceMode(m) ? m : "edit"); + }; + window.addEventListener("popstate", onPop); + return () => window.removeEventListener("popstate", onPop); + }, []); // The one app (CutApp): the bench opened in place over the workspace; the keys are the workspace's only while it shows. const app = useCutApp(); @@ -198,12 +255,13 @@ export default function Workspace({ type: e.type, heading: e.type === "clip" ? (e.quote ?? e.heading ?? "") : (e.heading ?? ""), seconds: p ? Math.max(0, p.it.to - p.it.from) : 0, - at: e.type === "intro" ? null : (at.get(e.id) ?? null), + // A version's blocks are never moved (its timeline is not the draft's). + at: e.type === "intro" || takeId ? null : (at.get(e.id) ?? null), rejected: e.rejected?.label ?? null, missing: e.type === "clip" && !e.media, }; }); - }, [view.entries, itemOf, tlIds]); + }, [view.entries, itemOf, tlIds, takeId]); const entryOf = core.entryOf; // ---- the selection (the inspector's block), kept in the URL (`?block=`) ---------------- @@ -236,8 +294,9 @@ export default function Workspace({ const p = itemOf.get(selected); if (!p) return; placed.current = true; - engine.seekTo(startOf(planRef.current, p.i)); - }, [itemOf, selected, engine, planRef]); + const into = initialAt != null && initialAt > 0 ? Math.min(initialAt, Math.max(0, p.it.to - p.it.from - 0.05)) : 0; + engine.seekTo(startOf(planRef.current, p.i) + into); + }, [itemOf, selected, engine, planRef, initialAt]); const step = useCallback( (d: 1 | -1) => { if (!blocks.length) return; @@ -248,6 +307,95 @@ export default function Workspace({ }, [blocks, selected, select], ); + // ---- the review pass (L7b): the selection is the block under review; past the last, the verdict ------------ + const rv = useReviewPass(project, view.entries, mode === "review" && !takeId); + const [atEnd, setAtEnd] = useState(false); + const reviewReady = mode === "review" && (takeId ? true : rv.loaded); + const reviewPlaced = useRef(false); + // A reload resumes on the block in its address; entering from Edit resumes on the first with no answer. + const reviewFromAddress = useRef(initialMode === "review"); + useEffect(() => { + if (mode !== "review") { + reviewPlaced.current = false; + return; + } + if (!reviewReady || reviewPlaced.current) return; + reviewPlaced.current = true; + // Where it stopped: the block in the address (a reload), else the first with no answer, else the verdict. + const ids = rv.progress.ids; + const fromAddress = reviewFromAddress.current; + reviewFromAddress.current = false; + if (fromAddress && selected && ids.includes(selected)) return; + const at = takeId ? (ids[0] ?? null) : rv.progress.next; + if (at) { + setAtEnd(false); + select(at); + } else { + setAtEnd(true); + setSelected(null); + } + }, [mode, reviewReady, rv.progress, selected, select, takeId]); + const reviewStep = useCallback( + (d: 1 | -1, play = false) => { + const ids = rv.progress.ids; + if (!ids.length) { + setAtEnd(true); + return; + } + const i = atEnd ? ids.length : selected ? ids.indexOf(selected) : -1; + const to = i + d; + if (to >= ids.length) { + setAtEnd(true); + setSelected(null); + setPlaying(false); + return; + } + setAtEnd(false); + select(ids[Math.max(0, to)]); + if (play) setPlaying(true); + }, + [rv.progress.ids, atEnd, selected, select, setPlaying], + ); + // The viewer plays block by block: it stops where the block under review ends. + const lastItem = useRef<string | null>(null); + const playingId = core.item?.id ?? null; + useEffect(() => { + const prev = lastItem.current; + lastItem.current = playingId; + if (mode !== "review" || !ui.playing) return; + if (prev && prev === selected && playingId !== selected) setPlaying(false); + }, [playingId, mode, ui.playing, selected, setPlaying]); + + // ---- present (L7b): Present's own deck over the workspace, its slides read on the way in ------------------------ + const [present, setPresent] = useState<{ state: "ready"; payload: PresentPayload } | { state: "loading" } | { state: "error"; error: string } | null>( + presentInitial ? { state: "ready", payload: presentInitial } : null, + ); + const presentRead = useRef(!!presentInitial); + useEffect(() => { + if (mode !== "present") { + presentRead.current = false; + return; + } + setPlaying(false); + if (presentRead.current) return; + presentRead.current = true; + let live = true; + setPresent({ state: "loading" }); + void (async () => { + try { + const r = await fetch(`/api/report/present?${new URLSearchParams({ project, ...(takeId ? { take: takeId } : {}) }).toString()}`, { cache: "no-store" }); + const j = (await r.json().catch(() => ({}))) as PresentPayload & { error?: string }; + if (!live) return; + setPresent(r.ok && !j.error ? { state: "ready", payload: j } : { state: "error", error: j.error ?? `HTTP ${r.status}` }); + } catch (e) { + if (live) setPresent({ state: "error", error: e instanceof Error ? e.message : String(e) }); + } + })(); + return () => { + live = false; + }; + }, [mode, project, takeId, setPlaying]); + const move = useCallback( async (id: string, at: number, to: number) => { if (to < 0 || to >= tl.current.ids.length || to === at) return; @@ -289,9 +437,13 @@ export default function Workspace({ // ---- the keys --------------------------------------------------------------------- const [help, setHelp] = useState(false); + const reviewStepRef = useRef(reviewStep); + reviewStepRef.current = reviewStep; useEffect(() => { const onKey = (ev: KeyboardEvent) => { if (!shownRef.current) return; + // Present's deck has the keys while it is up (present/PresentView.tsx; Esc is its way back to Edit). + if (modeRef.current === "present") return; const tgt = ev.target as HTMLElement | null; if (ev.key === "Escape" && help) { setHelp(false); @@ -300,6 +452,17 @@ export default function Workspace({ if (tgt?.closest("input, textarea, select, [contenteditable=true], [data-ws-own-keys], [role=dialog]")) return; const k = ev.key; const mod = ev.metaKey || ev.ctrlKey; + // The review pass: Space and ← → walk it (k f n are ReviewPass's); nothing here edits. + if (modeRef.current === "review") { + if (mod || ev.altKey) return; + if (k === " ") setPlaying(!now().playing); + else if (k === "ArrowLeft") reviewStepRef.current(-1); + else if (k === "ArrowRight") reviewStepRef.current(1); + else if (k === "?") setHelp((h) => !h); + else return; + ev.preventDefault(); + return; + } if (mod && !ev.altKey && (k === "z" || k === "Z")) { if (ev.shiftKey) { if (undoRef.current.canRedo && !undoRef.current.busy) void doRedo(); @@ -381,10 +544,14 @@ export default function Workspace({ // The draft's token as this page last read it (a spec waits on it before pressing Undo after a save). data-ws-token={tlToken ?? ""} data-ws-selected={selected ?? ""} + data-ws-mode-now={mode} className="flex min-h-0 flex-1 flex-col overflow-hidden max-[899px]:pb-[44px]" > <WorkspaceTop project={project} + mode={mode} + onMode={setMode} + version={take} title={view.title} draftLine={view.draft?.line ?? "Draft"} draftParent={view.draft?.parent ?? null} @@ -399,6 +566,9 @@ export default function Workspace({ onChanged={() => void reloadView()} help={() => setHelp(true)} /> + {/* The readiness bar (L7b): quote-check, links, captures, render, X jar -- what the Inbox would say of this + piece, each a click to its fix. Read-only. */} + {!takeId && <ReadinessBar project={project} initial={readiness} missing={blocks.filter((b) => b.missing).map((b) => b.id)} onSelect={(id) => select(id)} />} {generatedBy && ( <div className="border-b border-seam px-3 py-1"> <GeneratedBanner generatedBy={generatedBy} /> @@ -467,9 +637,13 @@ export default function Workspace({ selected={selected} playing={item?.id ?? null} busy={undo.busy} - onSelect={(id) => select(id)} + onSelect={(id) => { + if (mode === "review") setAtEnd(false); + select(id); + }} onMove={(id, at, to) => void move(id, at, to)} - plus={ + marks={mode === "review" ? rv.answers : null} + plus={mode !== "edit" || takeId ? null : ( <button type="button" onClick={() => setSelected(selected === ADD ? null : ADD)} @@ -483,14 +657,14 @@ export default function Workspace({ > + </button> - } + )} /> </section> {/* ---- the inspector (a sheet at the bottom under ~900 px) ---- */} <aside - aria-label="Inspector" - data-ws-inspector={selected === ADD ? "add" : (selEntry?.type ?? "project")} + aria-label={mode === "review" ? "Review pass" : "Inspector"} + data-ws-inspector={mode === "review" ? "review" : selected === ADD ? "add" : (selEntry?.type ?? "project")} data-ws-sheet={sheetOpen ? "open" : "closed"} className={cn( "min-h-0 min-w-0 overflow-y-auto border-seam bg-panel min-[900px]:border-l", @@ -499,20 +673,57 @@ export default function Workspace({ )} > <button type="button" className="flex w-full items-center gap-2 border-b border-seam px-3 py-2 text-left text-[12px] text-text-2 min-[900px]:hidden" onClick={() => setSheetOpen((o) => !o)} aria-expanded={sheetOpen} data-ws-sheet-toggle=""> - <span className="micro">Inspector</span> - <span className="font-mono">{selected === ADD ? "add" : (selected ?? "the project")}</span> + <span className="micro">{mode === "review" ? "Review pass" : "Inspector"}</span> + <span className="font-mono">{mode === "review" ? `${rv.progress.done} / ${rv.progress.total}` : selected === ADD ? "add" : (selected ?? "the project")}</span> <span className="ml-auto">{sheetOpen ? "▾" : "▴"}</span> </button> - <div key={`${selected ?? "-"}:${epoch}`}> - {selected === ADD ? ( - <AddPanels project={project} after={blocks.length ? blocks[blocks.length - 1].id : null} channels={postChannels} /> - ) : ( - <WorkspaceInspector project={project} entry={selEntry} hasLedger={hasLedger} hasClips={!!firstClip} introWritten={introWritten} /> - )} - </div> + {mode === "review" ? ( + // The review pass hides the inspector: its column is the pass. + <ReviewPass + project={project} + rv={rv} + entry={atEnd ? null : selEntry} + atEnd={atEnd || !selEntry} + take={take} + draft={view.draft ?? null} + onPrev={() => reviewStep(-1)} + onNext={() => reviewStep(1)} + onAnswered={() => reviewStep(1, true)} + onExit={() => setMode("edit")} + /> + ) : ( + <div key={`${selected ?? "-"}:${epoch}`}> + {selected === ADD ? ( + <AddPanels project={project} after={blocks.length ? blocks[blocks.length - 1].id : null} channels={postChannels} /> + ) : ( + <WorkspaceInspector project={project} entry={selEntry} hasLedger={hasLedger} hasClips={!!firstClip} introWritten={introWritten} /> + )} + </div> + )} </aside> </div> + {mode === "present" && ( + <div className="fixed inset-0 z-[70]" data-ws-present={present?.state ?? "loading"}> + {present?.state === "ready" ? ( + <PresentView payload={present.payload} back={workspaceHref(project)} playHref={playHref(project, { take: takeId })} onExit={() => setMode("edit")} /> + ) : ( + <div className="flex h-full flex-col items-start gap-2 bg-black p-6 text-[13px] text-white/80"> + {present?.state === "error" ? ( + <p role="alert" className="text-reject-text" data-present-error=""> + {present.error} + </p> + ) : ( + <p data-present-loading="">reading the slides…</p> + )} + <button type="button" className="ink-link text-amber-300" onClick={() => setMode("edit")} data-present-exit=""> + ‹ Back to Edit + </button> + </div> + )} + </div> + )} + {help && ( <div role="dialog" aria-modal="true" aria-label="Keys" className="fixed inset-0 z-50 flex items-center justify-center bg-black/55 p-4" onClick={() => setHelp(false)} data-ws-keys=""> <div className="w-full max-w-[440px] rounded-[3px] border border-seam-2 bg-panel p-4 text-[12.5px] text-text-2" onClick={(e) => e.stopPropagation()}> diff --git a/umtool/components/projects/workspace/WorkspacePage.tsx b/umtool/components/projects/workspace/WorkspacePage.tsx @@ -1,22 +1,45 @@ +import Link from "next/link"; import type { ProjectRef } from "@/lib/project-types"; import { readManifest } from "@/lib/projects/report.mjs"; import { playView } from "@/lib/report/playView.mjs"; -import { workspaceHref } from "@/lib/hrefs"; +import { presentPayload } from "@/lib/report/present.mjs"; +import { isWorkspaceMode, workspaceHref } from "@/lib/hrefs"; +import { readinessOf } from "@/lib/inbox/readiness"; import { NotesProvider } from "@/components/notes/NotesProvider"; import { RememberCut } from "@/components/shell/RecentCuts"; import CutApp from "../cutApp/CutApp"; import ReportProject from "../ReportProject"; import type { PlayViewData } from "../review/PlayCut"; +import type { PresentPayload } from "../present/PresentView"; import Workspace from "./Workspace"; // `/projects/<project>` for a report video -- THE WORKSPACE (umtool redesign L7a; components/projects/workspace/ // Workspace.tsx): the draft playing, its blocks, the inspector, one screen. `?block=<id>` opens with that block -// selected. A project whose draft cannot be read is the piece page, which says why. The piece page's tabs stay -// at `?tab=` (lib/projects/kinds.mjs opensWorkspace). +// selected (`&at=` seconds into it). `?mode=review` the review pass, `?mode=present` present mode (L7b), either +// with `?take=<version>` for a saved version, read-only. A project whose draft cannot be read is the piece page, +// which says why. The piece page's tabs stay at `?tab=` (lib/projects/kinds.mjs opensWorkspace). export default async function WorkspacePage({ project, search }: { project: ProjectRef; search: Record<string, string | undefined> }) { - const [view, m] = await Promise.all([playView(project, {}), readManifest(project.dir).catch(() => null)]); - if ("error" in view) return <ReportProject project={project} search={{ ...search, tab: "overview" }} />; + const mode = isWorkspaceMode(search.mode) ? search.mode : "edit"; + const take = mode !== "edit" && search.take ? search.take : null; + const [view, m, present, readiness] = await Promise.all([ + playView(project, { take }), + readManifest(project.dir).catch(() => null), + mode === "present" ? presentPayload(project, { take, canUncensor: true }) : Promise.resolve(null), + take ? Promise.resolve(null) : readinessOf(project), + ]); + if ("error" in view) { + if (!take) return <ReportProject project={project} search={{ ...search, tab: "overview" }} />; + return ( + <main data-ws-error="" className="flex h-full flex-col items-start gap-2 p-6 text-[13px]"> + <p className="text-reject-text">{String(view.error)}</p> + <Link href={workspaceHref(project.id)} className="ink-link"> + ‹ the draft + </Link> + </main> + ); + } const manifest = (m ?? {}) as { render?: { intro?: unknown }; ledger?: unknown; ledgerSchema?: unknown; generatedBy?: unknown }; + const at = Number(search.at); return ( <CutApp project={project.id} home={workspaceHref(project.id)} kind="workspace" playTop={null}> <RememberCut project={project.id} title={(view as PlayViewData).title || project.name || project.id} /> @@ -24,6 +47,10 @@ export default async function WorkspacePage({ project, search }: { project: Proj <Workspace view={view as PlayViewData} initialBlock={search.block ?? null} + initialAt={Number.isFinite(at) && at > 0 ? at : null} + initialMode={mode} + presentInitial={present && !("error" in present) ? (present as unknown as PresentPayload) : null} + readiness={readiness} introWritten={manifest.render?.intro ?? null} hasLedger={Array.isArray(manifest.ledger) || !!manifest.ledgerSchema} generatedBy={typeof manifest.generatedBy === "string" ? manifest.generatedBy : null} diff --git a/umtool/components/projects/workspace/WorkspaceTop.tsx b/umtool/components/projects/workspace/WorkspaceTop.tsx @@ -5,8 +5,8 @@ import { useCallback, useEffect, useRef, useState } from "react"; import { Mark } from "@/components/shell/Wordmark"; import { buttonVariants } from "@/components/ui/button"; import { cn } from "@/lib/utils"; -import { clipBenchHref, openInDraftHref, playHref, presentHref, projectHref, projectsHref, takesHref } from "@/lib/hrefs"; -import { PIECE_TABS } from "@/lib/pieces/tabs.mjs"; +import { openInDraftHref, playHref, projectHref, projectsHref, takesHref, versionReviewHref, workspaceHref, type WorkspaceMode } from "@/lib/hrefs"; +import { PIECE_TABS, PIECE_VIEWS } from "@/lib/pieces/tabs.mjs"; import CopyShareLine from "../CopyShareLine"; import { startTakeJob } from "../NewTakePanel"; import { announceManifestChanged } from "../timelineApi"; @@ -19,8 +19,8 @@ import { announceManifestChanged } from "../timelineApi"; // // Versions ▾ lists every saved version (and legacy take): Play it read-only, Open it in the draft (it asks // first, and saves the draft as a version when it has edits -- OpenInDraftPage), and Save version (the -// draft frozen as the next vN: `umtool takes save`). The mode switch's Review pass and Present go to -// today's walk and present pages until L7b brings them in here. Look writes render.mode (`umtool look +// draft frozen as the next vN: `umtool takes save`). The mode switch (L7b) is the workspace's own: Edit, the +// Review pass (`?mode=review`), Present (`?mode=present`) -- links, so a new tab opens each. Look writes render.mode (`umtool look // <p> mode=basic|deck`); Render queues a take of the draft (`umtool take`); Share copies the share line // of the selected clip (`umtool share`). Piece ▾ is the piece page's tabs (Sources, Deliver, History …). // --------------------------------------------------------------------------- @@ -101,6 +101,9 @@ function VersionsMenu({ project, versions, onSaved }: { project: string; version <span className="min-w-0 flex-1 truncate text-muted" title={v.label}> {v.label} </span> + <Link href={versionReviewHref(project, v.id)} prefetch={false} className="ink-link" data-ws-version-review={v.id} title="its review pass: watched block by block, read-only, its verdict at the end"> + Review + </Link> <Link href={playHref(project, { take: v.id })} prefetch={false} className="ink-link" data-ws-version-play={v.id} title="play it read-only"> Play </Link> @@ -205,8 +208,17 @@ function RenderMenu({ project }: { project: string }) { export type UndoState = { busy: boolean; said: string | null; error: boolean; canRedo: boolean }; +const MODES: { id: "edit" | WorkspaceMode; label: string; title: string }[] = [ + { id: "edit", label: "Edit", title: "the draft: its blocks, the inspector" }, + { id: "review", label: "Review pass", title: "the draft block by block: Keep · Fix · Note each (k f n), a verdict at the end" }, + { id: "present", label: "Present ⛶", title: "the cut as slides, full screen, navigated like a deck (Esc back)" }, +]; + export default function WorkspaceTop({ project, + mode = "edit", + onMode, + version = null, title, draftLine, draftParent, @@ -228,7 +240,7 @@ export default function WorkspaceTop({ draftEdits: number | null; versions: Version[]; basic: boolean; - /** The walk starts here (Review pass, until L7b). */ + /** The cut's first clip (unused since L7b's review pass; kept for callers). */ firstClip: string | null; /** The clip whose share line Share copies: the selected one, else the one on screen. */ shareClip: string | null; @@ -238,6 +250,10 @@ export default function WorkspaceTop({ /** Something the bar wrote (a version, the look): the workspace reads the draft again. */ onChanged: () => void; help: () => void; + mode?: "edit" | WorkspaceMode; + onMode?: (m: "edit" | WorkspaceMode) => void; + /** A saved version reviewed or presented read-only (`?take=`): nothing here writes the draft. */ + version?: { id: string; label: string } | null; }) { return ( <header data-app-header="workspace" data-ws-top="" className="flex flex-wrap items-center gap-x-2.5 gap-y-1 border-b border-seam bg-panel px-3 py-1.5"> @@ -253,31 +269,51 @@ export default function WorkspaceTop({ {title} </h1> </nav> - <span className="font-mono text-[11.5px] text-text-2" data-ws-draft={draftParent ?? ""} data-ws-draft-edits={draftEdits ?? ""} title="the working draft: every edit lands in it (video.manifest.json)"> - {draftLine} - </span> - <VersionsMenu project={project} versions={versions} onSaved={onChanged} /> - <nav aria-label="Mode" className="inline-flex items-center rounded-[3px] border border-seam-2 p-0.5 text-[12px]" data-ws-mode="edit"> - <span aria-current="page" className="rounded-[2px] bg-panel-2 px-2 py-0.5 font-medium text-text" data-ws-mode-edit=""> - Edit - </span> - {firstClip ? ( - <Link href={clipBenchHref(project, firstClip)} prefetch={false} className="rounded-[2px] px-2 py-0.5 text-muted-2 hover:text-text" data-ws-mode-review="" title="walk the draft's clips, a verdict each (the walk, until the review pass lands here)"> - Review pass + {version ? ( + <span className="inline-flex items-baseline gap-2 font-mono text-[11.5px] text-text-2" data-ws-version-shown={version.id} title={version.label}> + {version.id} · read-only + <Link href={openInDraftHref(project, version.id)} prefetch={false} className="ink-link font-sans" data-ws-version-open-draft=""> + Open in draft </Link> - ) : ( - <span className="px-2 py-0.5 text-seam-2" title="no clip to walk"> - Review pass - </span> - )} - <Link href={presentHref(project)} prefetch={false} className="rounded-[2px] px-2 py-0.5 text-muted-2 hover:text-text" data-ws-mode-present="" title="the cut as slides, full screen, navigated like a deck"> - Present ⛶ - </Link> + <Link href={workspaceHref(project)} prefetch={false} className="ink-link font-sans" data-ws-version-back=""> + the draft + </Link> + </span> + ) : ( + <span className="font-mono text-[11.5px] text-text-2" data-ws-draft={draftParent ?? ""} data-ws-draft-edits={draftEdits ?? ""} title="the working draft: every edit lands in it (video.manifest.json)"> + {draftLine} + </span> + )} + <VersionsMenu project={project} versions={versions} onSaved={onChanged} /> + <nav aria-label="Mode" className="inline-flex items-center rounded-[3px] border border-seam-2 p-0.5 text-[12px]" data-ws-mode={mode}> + {MODES.map((m) => { + const on = m.id === mode; + const href = m.id === "edit" ? workspaceHref(project) : workspaceHref(project, { mode: m.id, take: version?.id ?? null }); + return ( + <a + key={m.id} + href={href} + aria-current={on ? "page" : undefined} + {...{ [`data-ws-mode-${m.id}`]: "" }} + title={m.title} + onClick={(e) => { + if (!onMode || e.metaKey || e.ctrlKey || e.shiftKey || e.button !== 0) return; + e.preventDefault(); + onMode(m.id); + }} + className={on ? "rounded-[2px] bg-panel-2 px-2 py-0.5 font-medium text-text" : "rounded-[2px] px-2 py-0.5 text-muted-2 hover:text-text"} + > + {m.label} + </a> + ); + })} </nav> - <LookSwitch project={project} basic={basic} onChanged={onChanged} /> - <RenderMenu project={project} /> + {!version && <LookSwitch project={project} basic={basic} onChanged={onChanged} />} + {!version && <RenderMenu project={project} />} {shareClip && <CopyShareLine key={shareClip} project={project} clip={shareClip} testid="ws" />} <span className="ml-auto inline-flex items-center gap-1"> + {!version && ( + <> <button type="button" className={btn("quiet")} disabled={undo.busy} onClick={onUndo} data-ws-undo="" title="take back the newest edit to the draft (⌘Z / Ctrl+Z; umtool timeline <p> undo)"> Undo </button> @@ -289,16 +325,27 @@ export default function WorkspaceTop({ {undo.said} </span> )} - <Menu label="Piece ▾" testid="piece" align="right" title="the piece page's tabs"> + </> + )} + <Menu label="Piece ▾" testid="piece" align="right" title="the piece page's tabs: Sources, Deliver, History (and the views the workspace does not hold yet)"> {(close) => ( <ul className="m-0 flex list-none flex-col p-0"> - {PIECE_TABS.map((t) => ( + {/* lib/pieces/tabs.mjs PIECE_TABS: this screen is the first of them. */} + {PIECE_TABS.filter((t) => t.id !== "workspace").map((t) => ( <li key={t.id}> <Link href={projectHref(project, { tab: t.id })} prefetch={false} onClick={close} className="block rounded-[2px] px-2 py-1 text-text-2 hover:bg-panel-2 hover:text-text" data-ws-piece-tab={t.id}> {t.label} </Link> </li> ))} + <li aria-hidden className="my-1 border-t border-seam" /> + {PIECE_VIEWS.map((t) => ( + <li key={t.id}> + <Link href={projectHref(project, { tab: t.id })} prefetch={false} onClick={close} className="block rounded-[2px] px-2 py-1 text-muted-2 hover:bg-panel-2 hover:text-text" data-ws-piece-tab={t.id}> + {t.label} + </Link> + </li> + ))} </ul> )} </Menu> diff --git a/umtool/lib/hrefs.test.mjs b/umtool/lib/hrefs.test.mjs @@ -63,6 +63,13 @@ test("empty, null and false values are left out; true is 1", () => { assert.equal(H.projectHref("a/b", { tab: "overview" }), "/projects/a/b?tab=overview"); assert.equal(H.workspaceHref("a/b"), "/projects/a/b"); assert.equal(H.workspaceHref("a/b", { block: "c01" }), "/projects/a/b?block=c01"); + // L7b: the modes, a version reviewed or presented, a block and the seconds into it. + assert.equal(H.workspaceHref("a/b", { mode: "review" }), "/projects/a/b?mode=review"); + assert.equal(H.workspaceHref("a/b", { mode: "review", take: "v1" }), "/projects/a/b?mode=review&take=v1"); + assert.equal(H.workspaceHref("a/b", { take: "v1" }), "/projects/a/b"); + assert.equal(H.workspaceHref("a/b", { block: "c02", at: 1.234 }), "/projects/a/b?block=c02&at=1.23"); + assert.equal(H.presentHref("a/b", { take: "v1", slide: "c01" }), "/projects/a/b?mode=present&take=v1#c01"); + assert.equal(H.versionReviewHref("a/b", "v2"), "/projects/a/b?mode=review&take=v2"); assert.equal(H.projectHref("a/b", { tab: "cut", all: true, note: "n1" }), "/projects/a/b?tab=cut&all=1&note=n1"); assert.equal(H.projectsHref({ kind: "k1", new: false }), "/projects?kind=k1"); assert.equal(H.projectsHref({ new: true }), "/projects?new=1"); @@ -137,7 +144,9 @@ test("Play the cut ↔ the clip bench: Edit this clip carries the way back, Back assert.equal(H.playHref("a/b", { clip: "c02", at: 0.5 }), "/projects/a/b/play?clip=c02&at=0.50"); assert.equal(H.playHref("a/b", { clip: "c02", at: 0 }), "/projects/a/b/play?clip=c02"); // No clip, no offset: `at` means nothing on its own. - assert.equal(H.playHref("a/b", { at: 3 }), "/projects/a/b/play"); + assert.equal(H.playHref("a/b", { at: 3 }), "/projects/a/b/play?cut=1"); + // Play's own page always carries a query: a bare /play is the workspace's (a 308, L7b). + assert.equal(H.playHref("a/b"), "/projects/a/b/play?cut=1"); assert.equal(H.playHref("a/b", { take: "t1", note: "n" }), "/projects/a/b/play?take=t1&note=n"); }); diff --git a/umtool/lib/hrefs.ts b/umtool/lib/hrefs.ts @@ -276,12 +276,30 @@ export function projectHref(id: string, q: { tab?: string; all?: boolean } & Not return withQuery(`/projects/${encodePath(id)}`, { ...(tab ? { tab } : {}), ...rest }, note); } +/** The workspace's modes besides Edit (its bare address): the review pass and present (umtool redesign L7b). */ +export const WORKSPACE_MODES = ["review", "present"] as const; +export type WorkspaceMode = (typeof WORKSPACE_MODES)[number]; +export const isWorkspaceMode = (v: unknown): v is WorkspaceMode => typeof v === "string" && (WORKSPACE_MODES as readonly string[]).includes(v); + /** * THE WORKSPACE (umtool redesign L7a): a report video's one screen -- the draft playing, its blocks, the - * inspector. `block`: open with that block (a timeline entry's id, or `intro`) selected. + * inspector. `block`: open with that block (a timeline entry's id, or `intro`) selected; `at` seconds into it. + * `mode` (L7b): `review` the review pass (Keep · Fix · Note per block, a verdict at the end), `present` the viewer + * full screen as slides; Edit is the bare address. `take`: a saved version, reviewed or presented read-only. + * `slide`: present mode's slide (its `#<slide id>`). */ -export function workspaceHref(id: string, q: { block?: string | null } = {}): string { - return withQuery(`/projects/${encodePath(id)}`, q.block ? { block: q.block } : {}); +export function workspaceHref( + id: string, + q: { block?: string | null; at?: number | null; mode?: WorkspaceMode | null; take?: string | null; slide?: string | null } = {}, +): string { + return ( + withQuery(`/projects/${encodePath(id)}`, { + mode: q.mode ?? null, + take: q.mode ? (q.take ?? null) : null, + block: q.block ?? null, + at: q.block && q.at != null && q.at > 0 ? q.at.toFixed(2) : null, + }) + (q.mode === "present" && q.slide ? `#${q.slide}` : "") + ); } /** A project by its path, for an id that a tool page shadows at its own URL. */ @@ -367,6 +385,11 @@ export function takeWalkHref(project: string, take: string, q: NoteOpt & { all?: return withQuery(`/projects/${encodePath(project)}/takes/${encodeURIComponent(take)}/walk`, { all: q.all }, q.note); } +/** A version's review pass (umtool redesign L7b): watched block by block, read-only, its verdict at the end. */ +export function versionReviewHref(project: string, take: string): string { + return workspaceHref(project, { mode: "review", take }); +} + /** * The clip bench on one of a take's clips: its saves go into the take's patch, never the project's manifest. * `play`: opened from Play on this take (Edit this clip, on a take with its own timeline) -- the bench offers @@ -437,16 +460,19 @@ export function playHref( project: string, q: NoteOpt & { take?: string | null; - /** The project's manifest alone, no take's patch (`?cut=1`); without it and a take, the latest take plays. */ + /** The project's manifest alone, no take's patch (`?cut=1`): the draft, which is the default too. */ bare?: boolean; /** Start on this clip, `at` seconds into what the page shows of it (the bench's Back to the cut). */ clip?: string | null; at?: number | null; } = {}, ): string { + // A BARE `/play` is the workspace's now (umtool redesign L7b: a 308 to the project's own address), so Play's + // own page is always asked for with something in its query: `?cut=1` (the draft) when nothing else is. + const clip = q.clip || null; return withQuery( `/projects/${encodePath(project)}/play`, - { take: q.take, cut: !q.take && q.bare ? "1" : null, clip: q.clip, at: q.clip && q.at != null && q.at > 0 ? q.at.toFixed(2) : null }, + { take: q.take, cut: !q.take && (q.bare || (!clip && !q.note)) ? "1" : null, clip, at: clip && q.at != null && q.at > 0 ? q.at.toFixed(2) : null }, q.note, ); } @@ -457,7 +483,8 @@ export function playHref( * With no take, the latest take (the working cut), as Play. */ export function presentHref(project: string, q: { take?: string | null; bare?: boolean; slide?: string | null } = {}): string { - return withQuery(`/projects/${encodePath(project)}/present`, { take: q.take, cut: !q.take && q.bare ? "1" : null }) + (q.slide ? `#${q.slide}` : ""); + // The workspace's present mode (umtool redesign L7b); the old `/present` address 308s here. + return workspaceHref(project, { mode: "present", take: q.take ?? null, slide: q.slide ?? null }); } /** The narration script, card by card. */ diff --git a/umtool/lib/inbox/projectCalls.ts b/umtool/lib/inbox/projectCalls.ts @@ -89,6 +89,11 @@ async function callsOf(ref: ProjectRef): Promise<Decision[]> { return out; } +/** One report video's calls (the readiness bar's, umtool redesign L7b): the same memo the Inbox reads. Never throws. */ +export async function projectCallsOf(ref: ProjectRef): Promise<Decision[]> { + return projectCalls(ref).catch(() => [] as Decision[]); +} + async function projectCalls(ref: ProjectRef): Promise<Decision[]> { const sig = await signatureOf(ref.dir); const hit = memo.get(ref.id); diff --git a/umtool/lib/inbox/readiness.mjs b/umtool/lib/inbox/readiness.mjs @@ -0,0 +1,115 @@ +// THE READINESS BAR (umtool redesign L7b; the workspace's row under its top bar): one pill each for the quote +// check, the links, the captures, the render and X's jar -- ✓, a count, ! or — -- each a click to its fix or its +// page. Read-only, and derived from nothing of its own: the rows are the Inbox's (the project reducer's +// decisions, lib/projects/report.mjs; the report video's calls, lib/inbox/projectCalls.ts; X's jar, +// lib/inbox/xJar.ts), bucketed here by kind. Pure: lib/inbox/readiness.ts reads them. +// +// state "bad" a blocking row (or X's jar stale): something downstream would lie or die +// "count" rows that are open or informational, `count` of them +// "ok" none, and the check applies (it has run, or there is something for it to judge) +// "none" it does not apply here (no quote check, no clip, nothing rendered, no X post) + +/** Which pill a row of the Inbox's is. */ +export const PILL_KINDS = { + "quote-check": ["clip-quote-moved", "clip-quote-missing", "quote-check-stale"], + links: ["link-dead", "links-unverified", "links-unchecked", "site-deploy-behind", "clip-link-policy"], + captures: ["clip-unfetchable", "clip-no-cues", "clip-unchecked"], + render: ["stale-build", "version-unjudged"], + "x-jar": ["x-jar-stale"], +}; + +export const PILLS = [ + { id: "quote-check", label: "Quote check" }, + { id: "links", label: "Links" }, + { id: "captures", label: "Captures" }, + { id: "render", label: "Render" }, + { id: "x-jar", label: "X jar" }, +]; + +const pillOfKind = new Map(Object.entries(PILL_KINDS).flatMap(([pill, kinds]) => kinds.map((k) => [k, pill]))); +/** The pill a decision kind feeds, or null. */ +export const pillOf = (kind) => pillOfKind.get(kind) ?? null; + +/** + * @typedef {{ kind: string, target: string, why: string, href: string, severity: "blocking" | "open" | "info" }} Row + * @typedef {{ id: string, label: string, state: "bad" | "count" | "ok" | "none", count: number, title: string, href: string | null, select?: string | null }} Pill + */ + +/** + * The five pills. + * + * @param {{ + * rows: Row[], + * facts: { quoteCheck: boolean, linksChecked: boolean, clips: number, xPosts: number, built: boolean, rendered: boolean, missing?: string[] }, + * hrefs: { decisions: string, home: string, deliver: string, takes: string, cut: string, xSettings: string, review: (take: string) => string }, + * }} o + * @returns {Pill[]} + */ +export function readinessPills({ rows, facts, hrefs }) { + const by = new Map(PILLS.map((p) => [p.id, /** @type {Row[]} */ ([])])); + for (const r of rows ?? []) { + const p = pillOf(r?.kind); + if (p) by.get(p).push(r); + } + const words = (rs) => rs.slice(0, 4).map((r) => `${r.target}: ${r.why}`).join(" · ") + (rs.length > 4 ? ` · and ${rs.length - 4} more` : ""); + /** @returns {Pill} */ + const pill = (id, { ok, none, okTitle, noneTitle, okHref = null, badHref, countHref = badHref, extra = [] }) => { + const label = PILLS.find((p) => p.id === id).label; + const rs = by.get(id); + const bad = rs.filter((r) => r.severity === "blocking"); + if (bad.length) return { id, label, state: "bad", count: bad.length, title: words(bad), href: badHref(bad), select: null }; + const n = rs.length + extra.length; + if (n) return { id, label, state: "count", count: n, title: [rs.length ? words(rs) : null, ...extra.map((x) => x.why)].filter(Boolean).join(" · "), href: countHref(rs), select: extra[0]?.select ?? null }; + if (ok) return { id, label, state: "ok", count: 0, title: okTitle, href: okHref, select: null }; + return { id, label, state: "none", count: 0, title: noneTitle, href: okHref, select: null }; + }; + const missing = facts.missing ?? []; + return [ + pill("quote-check", { + ok: facts.quoteCheck, + okTitle: "every quoted clip heard where it plays (quote-check.json)", + noneTitle: "no quote check here yet (umtool quote-check <p>)", + okHref: hrefs.decisions, + // A failing row is the piece's own decision (its settle on the Overview); stale rows are home's one press. + badHref: () => hrefs.decisions, + countHref: (rs) => (rs.every((r) => r.kind === "quote-check-stale") ? hrefs.home : hrefs.decisions), + }), + pill("links", { + ok: facts.clips > 0 && facts.linksChecked, + okTitle: "every QR opens on its site (out/links.json)", + noneTitle: facts.clips ? "the QR links were never checked (umtool links <p>)" : "no clip, no QR link", + okHref: hrefs.decisions, + badHref: () => hrefs.decisions, + }), + pill("captures", { + ok: facts.clips > 0, + okTitle: "every clip's window is fetched and its source answers", + noneTitle: "no clip to fetch", + okHref: hrefs.cut, + badHref: () => hrefs.decisions, + countHref: (rs) => (rs.length ? hrefs.decisions : hrefs.cut), + extra: missing.map((id) => ({ why: `${id}: no media fetched`, select: id })), + }), + pill("render", { + ok: facts.built || facts.rendered, + okTitle: facts.built ? "the build is current with the draft" : "rendered; every version judged", + noneTitle: "never rendered (Render ▾)", + okHref: hrefs.takes, + badHref: () => hrefs.deliver, + countHref: (rs) => { + const v = rs.find((r) => r.kind === "version-unjudged"); + return v ? hrefs.review(v.target) : hrefs.deliver; + }, + }), + // X's jar is the machine's: stale while X work waits on it (the editor's alert), whichever piece it is for. + ((p) => (p.state === "count" ? { ...p, state: "bad" } : p))( + pill("x-jar", { + ok: facts.xPosts > 0, + okTitle: "X's cookie jar: no X work waiting on it", + noneTitle: "no X post in the cut", + okHref: hrefs.xSettings, + badHref: (rs) => rs[0]?.href ?? hrefs.xSettings, + }), + ), + ]; +} diff --git a/umtool/lib/inbox/readiness.ts b/umtool/lib/inbox/readiness.ts @@ -0,0 +1,58 @@ +import { stat } from "node:fs/promises"; +import path from "node:path"; +import type { ProjectRef } from "@/lib/project-types"; +import { decisionsForProject } from "@/lib/projects"; +import { readManifest } from "@/lib/projects/report.mjs"; +import { homeHref, projectHref, takesHref, versionReviewHref } from "@/lib/hrefs"; +import { editorUrl } from "@/lib/articles/generation"; +import { QUOTE_CHECK_FILE } from "@/lib/report/quoteCheck.mjs"; +import { projectCallsOf } from "./projectCalls"; +import { xJarDecisions } from "./xJar"; +import { readinessPills } from "./readiness.mjs"; + +// --------------------------------------------------------------------------- +// THE READINESS BAR's read (umtool redesign L7b; lib/inbox/readiness.mjs buckets): the rows the Inbox reads for +// this one piece -- the reducer's decisions (decisionsForProject, memoised on the project's files), its calls +// (projectCallsOf, the same memo) and X's jar (xJarDecisions: a minute's memo, never waited on past 0.4 s) -- +// and four stats. Never throws: a piece that cannot be read is a bar of —. SERVER ONLY. +// --------------------------------------------------------------------------- + +export type ReadinessPill = { id: string; label: string; state: "bad" | "count" | "ok" | "none"; count: number; title: string; href: string | null; select?: string | null }; +export type Readiness = { project: string; pills: ReadinessPill[] }; + +const exists = (f: string) => stat(/* turbopackIgnore: true */ f).then(() => true, () => false); + +export async function readinessOf(ref: ProjectRef): Promise<Readiness> { + try { + const [decisions, calls, xjar, manifest, quoteCheck, linksChecked] = await Promise.all([ + decisionsForProject(ref).catch(() => []), + projectCallsOf(ref), + xJarDecisions().catch(() => []), + readManifest(ref.dir).catch(() => null) as Promise<Record<string, unknown> | null>, + exists(path.join(ref.dir, QUOTE_CHECK_FILE)), + exists(path.join(ref.dir, "out", "links.json")), + ]); + const timeline = (Array.isArray(manifest?.timeline) ? manifest.timeline : []) as Record<string, unknown>[]; + const clips = timeline.filter((e) => e?.type === "clip").length; + const xPosts = timeline.filter((e) => e?.type === "post" && (e.platform === "x" || /^https?:\/\/(x|twitter)\.com\//.test(String(e.url ?? "")))).length; + const rows = [...decisions, ...calls, ...xjar]; + const built = !rows.some((r) => r.kind === "unbuilt" || r.kind === "stale-build"); + const rendered = calls.some((r) => r.kind === "version-unjudged") || (await exists(path.join(ref.dir, "takes", "verdicts.json"))); + const pills = readinessPills({ + rows: rows as never, + facts: { quoteCheck, linksChecked, clips, xPosts, built, rendered }, + hrefs: { + decisions: projectHref(ref.id, { tab: "overview" }), + home: homeHref(), + deliver: projectHref(ref.id, { tab: "deliver" }), + takes: takesHref(ref.id), + cut: projectHref(ref.id, { tab: "cut" }), + xSettings: `${editorUrl()}/settings`, + review: (take: string) => versionReviewHref(ref.id, take), + }, + }) as ReadinessPill[]; + return { project: ref.id, pills }; + } catch { + return { project: ref.id, pills: [] }; + } +} diff --git a/umtool/lib/pieces/article.ts b/umtool/lib/pieces/article.ts @@ -8,7 +8,7 @@ import { articlePieceId, readPieceGraph, type Piece, type PieceGraph, type Piece import { boardOfArticle } from "./board.mjs"; import { readCases } from "./cases"; import type { PieceFrame } from "./frame"; -import { PIECE_TAB_IDS, pieceSteps, stageOfPiece, tabOfNoteAnchor } from "./tabs.mjs"; +import { PIECE_ADDRESS_TAB_IDS, PIECE_FOLDED, pieceSteps, stageOfPiece, tabOfNoteAnchor } from "./tabs.mjs"; // --------------------------------------------------------------------------- // THE ARTICLE-ROOTED PIECE (plans/umtool-redesign.md, P4a-2): an article and @@ -68,11 +68,11 @@ export async function articleVideo(piece: Piece, graph: PieceGraph, want?: strin } /** The tab a `?note=` on a PROJECT opens: where the note's anchor is drawn (its notes.json), or null. */ -export async function projectNoteTab(dir: string, note: string | undefined): Promise<string | null> { +export async function projectNoteTab(dir: string, note: string | undefined, { piece = "project" }: { piece?: "project" | "article" } = {}): Promise<string | null> { if (!note) return null; const { doc } = await readNotes(path.join(/* turbopackIgnore: true */ 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; + return n?.anchor?.kind ? tabOfNoteAnchor(n.anchor.kind, { piece }) : null; } type TabQuery = { tab?: string; all?: boolean; note?: string | null }; @@ -85,7 +85,10 @@ type TabQuery = { tab?: string; all?: boolean; note?: string | null }; export async function pieceHrefOfProject(projectId: string, q: TabQuery = {}): Promise<string> { const graph = await readPieceGraph().catch(() => null); const piece = graph ? graph.byId.get(graph.pieceOfProject.get(projectId) ?? "") : undefined; - if (!graph || !piece || piece.kind !== "article" || !piece.site || !piece.report) return projectHref(projectId, q); + // On its own page a folded tab (L7b: Build and Media) is Deliver; an article piece keeps them. + if (!graph || !piece || piece.kind !== "article" || !piece.site || !piece.report) { + return projectHref(projectId, { ...q, tab: q.tab ? ((PIECE_FOLDED as Record<string, string>)[q.tab] ?? q.tab) : q.tab }); + } const v = await articleVideo(piece, graph, projectId); return articleHref( { site: piece.site, id: piece.report }, @@ -110,9 +113,9 @@ export async function claimedProjectRedirect( const all = one("all") === "1"; const asked = one("tab"); const tab = - asked && PIECE_TAB_IDS.includes(asked) + asked && PIECE_ADDRESS_TAB_IDS.includes(asked) ? asked - : ((note ? await projectNoteTab(project.dir, note) : null) ?? (all ? "cut" : "overview")); + : ((note ? await projectNoteTab(project.dir, note, { piece: "article" }) : null) ?? (all ? "cut" : "overview")); return pieceHrefOfProject(project.id, { tab, all, note }); } diff --git a/umtool/lib/pieces/tabs.mjs b/umtool/lib/pieces/tabs.mjs @@ -107,19 +107,44 @@ export function stepOfPiece({ kind, reached }) { return stageOfPiece({ kind, reached }); } -/** The tabs of a report-video piece, in order; the key that opens each is its position. */ +/** + * The tabs of a report-video piece, in order; the key that opens each is its position. Since the workspace + * (umtool redesign L7b) they are FOUR: the workspace itself (the project's own address: the draft playing, its + * blocks, the inspector, the review pass, present), then Sources, Deliver and History. + * + * What the seven tabs before it held, and where it is now: + * Build, Media folded into Deliver (PIECE_FOLDED): the build chain and the final mp4, the drafted fields, + * the upload's text and the on-screen panel are what ships -- `?tab=build|media` 308s there + * Overview, Cut addressable VIEWS still (PIECE_VIEWS), out of the tab bar, under the workspace: the piece's + * decisions, README and iterations, and the cut as a list with its every tool (fetch windows, + * candidates, groups, prep …) have no home in the workspace yet. The workspace's Piece ▾ and + * the piece page's ⋯ open them. + */ 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: "workspace", label: "Workspace" }, { id: "sources", label: "Sources" }, + { id: "deliver", label: "Deliver" }, { id: "history", label: "History" }, ]; export const PIECE_TAB_IDS = PIECE_TABS.map((t) => t.id); +/** The piece page's views out of the tab bar (the workspace's, until it holds them): `?tab=overview`, `?tab=cut`. */ +export const PIECE_VIEWS = [ + { id: "overview", label: "Overview" }, + { id: "cut", label: "The cut as a list" }, +]; +export const PIECE_VIEW_IDS = PIECE_VIEWS.map((t) => t.id); + +/** The tabs that folded into another (L7b): their address 308s to it, the rest of the query kept. */ +export const PIECE_FOLDED = { build: "deliver", media: "deliver" }; + +/** + * Every `?tab=` a report video's address has ever answered (the seven of P4a-1): what a claimed project's address + * carries over to its article piece, which keeps all seven (ARTICLE_PIECE_TABS). + */ +export const PIECE_ADDRESS_TAB_IDS = ["overview", "cut", "media", "build", "deliver", "sources", "history"]; + /** * 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. @@ -139,17 +164,17 @@ export const SECTION_TAB = { cut: "cut", takes: "cut", corrections: "cut", - // Media: every drafted field and each section's Draft with (P4b's one surface), + // What was Media: every drafted field and each section's Draft with (P4b's one surface), // the review and narration benches' links, the on-screen panel (moved from - // Build in P4b) and the upload's text. - drafts: "media", - review: "media", - narration: "media", - youtube: "media", - onscreen: "media", - // Build: the build chain and the final mp4. - build: "build", - final: "build", + // Build in P4b) and the upload's text -- on Deliver since L7b. + drafts: "deliver", + review: "deliver", + narration: "deliver", + youtube: "deliver", + onscreen: "deliver", + // What was Build: the build chain and the final mp4 -- on Deliver since L7b. + build: "deliver", + final: "deliver", // Deliver: the deliver panel and the exports. deliver: "deliver", exports: "deliver", @@ -170,10 +195,11 @@ export function tabOfSection(name) { } /** 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) { +export function tabOfNoteAnchor(kind, { piece = "project" } = {}) { // A Play-view note (`cut`) is reached from the Cut tab's Play the cut; its own link opens the Play view. if (kind === "entry" || kind === "edit" || kind === "cut" || kind === "reel") return "cut"; - if (kind === "moment") return "build"; + // The final video's timed notes: on Deliver since Build folded into it (L7b); an article piece keeps its Build. + if (kind === "moment") return piece === "article" ? "build" : "deliver"; return "overview"; } @@ -184,14 +210,16 @@ export function tabOfNoteAnchor(kind) { * @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 shown = (t) => (PIECE_FOLDED[t] ?? t); + const known = (t) => !!t && t !== "workspace" && (PIECE_TAB_IDS.includes(shown(t)) || PIECE_VIEW_IDS.includes(t)); 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 (known(t)) return shown(t); + if (search?.note && known(noteTab)) return shown(noteTab); if (search?.all === "1") return "cut"; return "overview"; } -/** The tab a number key opens (`1` … `7`), or null. */ +/** The tab a number key opens (`1` … `4`: the workspace, Sources, Deliver, History), 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; @@ -220,8 +248,8 @@ export const ARTICLE_PIECE_TABS = [ export const ARTICLE_PIECE_TAB_IDS = ARTICLE_PIECE_TABS.map((t) => t.id); -/** The tabs an article piece draws from its video project (every tab of a project piece but its Overview). */ -export const VIDEO_TAB_IDS = PIECE_TAB_IDS.filter((t) => t !== "overview"); +/** The tabs an article piece draws from its video project (every tab a project piece had but its Overview). */ +export const VIDEO_TAB_IDS = PIECE_ADDRESS_TAB_IDS.filter((t) => t !== "overview"); /** * The sections an article piece adds to SECTION_TAB, by the name a spec says. @@ -231,6 +259,14 @@ export const VIDEO_TAB_IDS = PIECE_TAB_IDS.filter((t) => t !== "overview"); */ export const ARTICLE_SECTION_TAB = { ...SECTION_TAB, + // An article piece keeps the video's Media and Build tabs (the project piece folded them into Deliver, L7b). + drafts: "media", + review: "media", + narration: "media", + youtube: "media", + onscreen: "media", + build: "build", + final: "build", next: "overview", sections: "overview", article: "article", diff --git a/umtool/lib/pieces/tabs.test.mjs b/umtool/lib/pieces/tabs.test.mjs @@ -6,6 +6,9 @@ import { ARTICLE_PIECE_TAB_IDS, PIECE_TABS, PIECE_TAB_IDS, + PIECE_ADDRESS_TAB_IDS, + PIECE_FOLDED, + PIECE_VIEW_IDS, SECTION_TAB, STAGE_STEPS, VIDEO_TAB_IDS, @@ -19,36 +22,49 @@ import { 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("four tabs since the workspace (L7b): the workspace, Sources, Deliver, History; keys 1–4 open them", () => { + assert.deepEqual(PIECE_TAB_IDS, ["workspace", "sources", "deliver", "history"]); + assert.equal(tabOfKey("1"), "workspace"); + assert.equal(tabOfKey("4"), "history"); + for (const k of ["0", "5", "n", "", "1.5"]) assert.equal(tabOfKey(k), null, k); + assert.equal(PIECE_TABS.length, 4); + // The seven a project's address ever answered: an article piece carries them over, and keeps them. + assert.deepEqual(PIECE_ADDRESS_TAB_IDS, ["overview", "cut", "media", "build", "deliver", "sources", "history"]); + assert.deepEqual(VIDEO_TAB_IDS, ["cut", "media", "build", "deliver", "sources", "history"]); + assert.deepEqual(PIECE_VIEW_IDS, ["overview", "cut"]); + assert.deepEqual(PIECE_FOLDED, { build: "deliver", media: "deliver" }); }); -test("the address picks the tab: ?tab= first, then a note's anchor, then ?all=1, else the Overview", () => { +test("the address picks the tab: ?tab= first (a folded one its fold), 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: "build" }), "deliver"); + assert.equal(tabOf({ tab: "media" }), "deliver"); + assert.equal(tabOf({ tab: "cut" }), "cut"); + assert.equal(tabOf({ tab: "workspace" }), "overview"); 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" }, { noteTab: "build" }), "deliver"); + assert.equal(tabOf({ note: "n1" }, { noteTab: "cut" }), "cut"); assert.equal(tabOf({ note: "n1" }), "overview"); - assert.equal(tabOf({ tab: "media", note: "n1" }, { noteTab: "cut" }), "media"); + assert.equal(tabOf({ tab: "history", note: "n1" }, { noteTab: "cut" }), "history"); }); 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("moment"), "deliver"); 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"), "media"); // moved from Build in P4b +test("every section is on a real tab or view; an unknown one throws", () => { + for (const [name, tab] of Object.entries(SECTION_TAB)) assert.ok(PIECE_TAB_IDS.includes(tab) || PIECE_VIEW_IDS.includes(tab), name); + assert.equal(tabOfSection("onscreen"), "deliver"); // Media folded into Deliver (L7b) + assert.equal(tabOfSection("final"), "deliver"); // Build too assert.equal(tabOfSection("deliver"), "deliver"); + assert.equal(tabOfSection("timeline"), "cut"); + assert.equal(articleTabOfSection("onscreen"), "media"); // an article piece keeps them + assert.equal(articleTabOfSection("final"), "build"); assert.throws(() => tabOfSection("nope"), /no section "nope"/); }); diff --git a/umtool/lib/projects/report.mjs b/umtool/lib/projects/report.mjs @@ -1134,8 +1134,9 @@ export const REPORT_DECISION_KINDS = [ * @param {string} target */ export function decisionTab(kind, target) { - if (kind === "stale-build" || kind === "unbuilt") return "build"; - if (kind === "storage-unreachable" || kind === "storage-mismatch") return target === "out" ? "build" : "deliver"; + // Build folded into Deliver (umtool redesign L7b): the build's rows are settled there. + if (kind === "stale-build" || kind === "unbuilt") return "deliver"; + if (kind === "storage-unreachable" || kind === "storage-mismatch") return "deliver"; if (kind === "manifest-invalid" && target === "storage.deliverables") return "deliver"; if (kind === "no-punctuation") return "sources"; return null; diff --git a/umtool/lib/report/present.mjs b/umtool/lib/report/present.mjs @@ -424,7 +424,9 @@ export function presentFrom({ view, manifest, red, canUncensor = true }) { title: view.title, capabilities: { canUncensor: !!canUncensor }, settings: PRESENT_DEFAULTS, - box: { width: fin(render.width) ? render.width : 1920, height: fin(render.height) ? render.height : 1080 }, + // A 9:16 cut (`render.format: "vertical"`) is built 1080x1920 whatever its width and height say + // (takePreview.mjs previewKnobs): it presents tall (umtool redesign L7b). + box: render.format === "vertical" ? { width: 1080, height: 1920 } : { width: fin(render.width) ? render.width : 1920, height: fin(render.height) ? render.height : 1080 }, zone, blurRendered: view.blurRendered !== false, sections, diff --git a/umtool/lib/report/reviewPass.mjs b/umtool/lib/report/reviewPass.mjs @@ -20,13 +20,17 @@ // Plain ESM: the CLI runs under bare node; the app reads the same functions. import { mkdir, readFile, rename, writeFile } from "node:fs/promises"; import path from "node:path"; +import { blockAnswer, reviewBlocks, reviewProgress } from "./reviewPassModel.mjs"; + +export { blockAnswer, reviewBlocks, reviewProgress }; export const REVIEW_PASS_FILE = "review-pass.json"; -export const REVIEW_MARKS = /** @type {const} */ (["keep", "fix"]); +export { REVIEW_MARKS } from "./reviewPassModel.mjs"; +import { REVIEW_MARKS } from "./reviewPassModel.mjs"; /** A Fix's note, at most (a correction is the bench's sixth field; this is its post-and-card twin). */ export const REVIEW_NOTE_LIMIT = 2000; -/** @typedef {{ mark: "keep" | "fix", note?: string, at: string }} ReviewMark */ +/** @typedef {import("./reviewPassModel.mjs").ReviewMark} ReviewMark */ /** @typedef {{ version: 1, marks: Record<string, ReviewMark> }} ReviewPassDoc */ const empty = () => /** @type {ReviewPassDoc} */ ({ version: 1, marks: {} }); @@ -100,58 +104,6 @@ export async function setReviewMark(dir, manifest, block, mark, { note, now = ne }); } -/** - * What the pass walks, from either shape of an entry: the play view's (`type`, `review.verdict`) or the - * manifest's (`type`, `verdict`). The intro and a clip rejected for a cut reason are left out. - * - * @param {Array<{ id: string, type: string, verdict?: string | null, review?: { verdict?: string | null } | null }>} entries - */ -export function reviewBlocks(entries) { - return (Array.isArray(entries) ? entries : []).filter((e) => { - if (!e || typeof e.id !== "string" || e.type === "intro") return false; - const v = e.review?.verdict ?? e.verdict ?? null; - return !(e.type === "clip" && v === "rejected"); - }); -} - -/** - * One block's answer: a clip's from its walk verdict (confirmed → keep, incorrect → fix), anything else's from - * the marks. null: not reviewed yet. - * - * @param {{ id: string, type: string, verdict?: string | null, review?: { verdict?: string | null, correction?: string | null } | null, correction?: string | null }} e - * @param {Record<string, ReviewMark>} marks - * @returns {{ mark: "keep" | "fix", note: string | null } | null} - */ -export function blockAnswer(e, marks) { - if (e.type === "clip") { - const v = e.review?.verdict ?? e.verdict ?? null; - const correction = e.review?.correction ?? e.correction ?? null; - if (v === "confirmed") return { mark: "keep", note: null }; - if (v === "incorrect") return { mark: "fix", note: typeof correction === "string" ? correction : null }; - return null; - } - const m = marks?.[e.id]; - return m ? { mark: m.mark, note: m.note ?? null } : null; -} - -/** - * The pass's progress: how many of its blocks have an answer, and where it resumes (the first with none; null when - * every block has one -- the verdict at the end). - * - * @param {Parameters<typeof reviewBlocks>[0]} entries - * @param {Record<string, ReviewMark>} marks - */ -export function reviewProgress(entries, marks) { - const blocks = reviewBlocks(entries); - let done = 0; - let next = null; - for (const b of blocks) { - if (blockAnswer(b, marks)) done += 1; - else if (next === null) next = b.id; - } - return { done, total: blocks.length, next, ids: blocks.map((b) => b.id) }; -} - export const REVIEW_PASS_USAGE = [ "umtool review-pass <project> [ls] [--json]", "umtool review-pass <project> mark <block> keep|fix|clear [--note T]", diff --git a/umtool/lib/report/reviewPassModel.mjs b/umtool/lib/report/reviewPassModel.mjs @@ -0,0 +1,59 @@ +// THE REVIEW PASS's model (lib/report/reviewPass.mjs is the store and the CLI): what the pass walks, each block's +// answer, the progress and where it resumes. Pure, no imports: the workspace's page reads it in the browser. + +export const REVIEW_MARKS = /** @type {const} */ (["keep", "fix"]); + +/** @typedef {{ mark: "keep" | "fix", note?: string, at: string }} ReviewMark */ + +/** + * What the pass walks, from either shape of an entry: the play view's (`type`, `review.verdict`) or the + * manifest's (`type`, `verdict`). The intro and a clip rejected for a cut reason are left out. + * + * @param {Array<{ id: string, type: string, verdict?: string | null, review?: { verdict?: string | null } | null }>} entries + */ +export function reviewBlocks(entries) { + return (Array.isArray(entries) ? entries : []).filter((e) => { + if (!e || typeof e.id !== "string" || e.type === "intro") return false; + const v = e.review?.verdict ?? e.verdict ?? null; + return !(e.type === "clip" && v === "rejected"); + }); +} + +/** + * One block's answer: a clip's from its walk verdict (confirmed → keep, incorrect → fix), anything else's from + * the marks. null: not reviewed yet. + * + * @param {{ id: string, type: string, verdict?: string | null, review?: { verdict?: string | null, correction?: string | null } | null, correction?: string | null }} e + * @param {Record<string, ReviewMark>} marks + * @returns {{ mark: "keep" | "fix", note: string | null } | null} + */ +export function blockAnswer(e, marks) { + if (e.type === "clip") { + const v = e.review?.verdict ?? e.verdict ?? null; + const correction = e.review?.correction ?? e.correction ?? null; + if (v === "confirmed") return { mark: "keep", note: null }; + if (v === "incorrect") return { mark: "fix", note: typeof correction === "string" ? correction : null }; + return null; + } + const m = marks?.[e.id]; + return m ? { mark: m.mark, note: m.note ?? null } : null; +} + +/** + * The pass's progress: how many of its blocks have an answer, and where it resumes (the first with none; null when + * every block has one -- the verdict at the end). + * + * @param {Parameters<typeof reviewBlocks>[0]} entries + * @param {Record<string, ReviewMark>} marks + */ +export function reviewProgress(entries, marks) { + const blocks = reviewBlocks(entries); + let done = 0; + let next = null; + for (const b of blocks) { + if (blockAnswer(b, marks)) done += 1; + else if (next === null) next = b.id; + } + return { done, total: blocks.length, next, ids: blocks.map((b) => b.id) }; +} +