Archilyzer · Source

archilyzer

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

commit ff679879b001360870172ff8d38fc94a7e3520f6
parent bd75770dd9a695f6bce08d97c5cf3470a2e1acf0
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Wed, 14 Oct 2026 10:20:30 -0400

umtool: a song is a piece page (P4a-3) — Spec → Cuts → Done, five tabs

The song page is the P4a frame (head, stepper, lifecycle chip, Next card,
keys 1–5 and n) around one of Overview · Cuts · Spec · Cover · Notes; a cut's
page is a view of the Cuts tab. SongProject's and CutPage's sections moved
unchanged into components/projects/song/*.

The song kind declares its stepper (kinds.mjs `piece.flow`, `songReached`);
pieceSteps/stageOfPiece switch on it (lib/pieces/song-tabs.mjs), so the piece
page and Work's stage facet read one rule: Spec → article, Cuts → video,
Done → deliver, and Work draws a song's own three steps. A song-wide call
links its tab (spec, cuts, cover).

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

Diffstat:
Mumtool/app/work/page.tsx | 2+-
Mumtool/components/projects/CutPage.tsx | 69++++++++++++++++++++++++++++++++++++++++++++++++---------------------
Mumtool/components/projects/ProjectView.tsx | 5+++--
Mumtool/components/projects/SongProject.tsx | 298+++++++++++++++----------------------------------------------------------------
Aumtool/components/projects/song/CoverTab.tsx | 24++++++++++++++++++++++++
Aumtool/components/projects/song/CutsTab.tsx | 174+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aumtool/components/projects/song/NotesTab.tsx | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
Aumtool/components/projects/song/OverviewTab.tsx | 189+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aumtool/components/projects/song/SongFrame.tsx | 95+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aumtool/components/projects/song/SpecTab.tsx | 57+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/lib/decisions.ts | 16++++++++++------
Mumtool/lib/pieces.ts | 28++++++++++++++++++++++++++--
Mumtool/lib/pieces/frame.ts | 25+++++++++++++++++++------
Aumtool/lib/pieces/song-tabs.mjs | 149+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aumtool/lib/pieces/song-tabs.test.mjs | 98+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/lib/pieces/tabs.mjs | 31++++++++++++++++++++++++++++---
Mumtool/lib/projects/kinds.mjs | 13++++++++++++-
Mumtool/lib/projects/song.mjs | 12++++++++++++
Mumtool/lib/work.ts | 13+++++++++----
Mumtool/lib/work/facets.mjs | 27+++++++++++++++++++++++++--
20 files changed, 1085 insertions(+), 291 deletions(-)

diff --git a/umtool/app/work/page.tsx b/umtool/app/work/page.tsx @@ -263,7 +263,7 @@ function Row({ r }: { r: WorkRow }) { </LitActions> </div> <span className="flex items-center gap-[3px]" title={r.looksDone.join("; ") || undefined}> - {[1, 2, 3, 4].map((i) => ( + {Array.from({ length: r.steps }, (_, k) => k + 1).map((i) => ( <i key={i} className={cn("h-1 w-[22px] rounded-[1px]", i < r.step ? "bg-text-2" : i === r.step ? "bg-signal" : "bg-seam-2")} diff --git a/umtool/components/projects/CutPage.tsx b/umtool/components/projects/CutPage.tsx @@ -1,6 +1,5 @@ import Link from "next/link"; import { notFound } from "next/navigation"; -import BrowseHeader from "@/components/BrowseHeader"; import CutBench from "@/components/CutBench"; import ProvenancePanel from "@/components/ProvenancePanel"; import { isCutName, probeAll, readSong } from "@/lib/browse"; @@ -13,21 +12,32 @@ import LoudnessTable from "@/components/LoudnessTable"; import { cachedLoudness } from "@/lib/loudness"; import { DEFAULT_TARGET } from "@/lib/loudness-types"; import { readSpec } from "@/lib/spec"; -import { resolveRendition } from "@/lib/browse"; +import { resolveRendition, thumbAliasesFor } from "@/lib/browse"; +import { cutHref, projectHref } from "@/lib/hrefs"; +import { thumbView } from "@/lib/thumbs"; +import type { ProjectRef } from "@/lib/project-types"; +import SongFrame, { readSongFrame, songCounts } from "./song/SongFrame"; // Moved out of app/browse/[song]/[cut]/page.tsx unchanged. `/browse/<song>/wide` // is now a project id plus a VIEW, resolved by the registry rather than by a // route segment -- the URL is byte-identical either way, which is the point. +// +// Since P4a-3 a cut's page is a view of the song piece's Cuts tab: the song's +// frame (components/projects/song/SongFrame.tsx) with Cuts current, the four +// cuts beside the title, and the bench, the loudness and the provenance under +// it, unchanged. export default async function CutPage({ - id, + project, cutName, search, }: { - id: string; + project: ProjectRef; cutName: string; search: { v?: string; plan?: string; notes?: string }; }) { + // Keyed by BASENAME, as every song route is (lib/browse.ts songDir). + const id = project.name; const { v, plan, notes: notesParam } = search; if (!isCutName(cutName)) notFound(); @@ -68,26 +78,44 @@ export default async function CutPage({ truePeak: spec.loudness?.truePeak ?? DEFAULT_TARGET.truePeak, }; + const [frame, thumbs] = await Promise.all([readSongFrame(project, song), thumbView(id, thumbAliasesFor(id))]); + return ( - <div className="flex h-full flex-col"> - <BrowseHeader - crumbs={[ - { href: "/projects", label: "songs" }, - { href: `/projects/${song.id}`, label: song.id }, - { label: cutName }, - ]} - note={ - cut.shipped - ? `${fmtDur(durations[cut.shipped.rel] ?? 0)} · ${fmtBytes(cut.shipped.size)}` - : "not built" - } - /> - <main className="deck-main flex-1"> + <SongFrame + project={project} + song={song} + frame={frame} + tab="cuts" + bare + idHref={projectHref(project.id)} + counts={songCounts(song, notes, thumbs.candidates.length)} + note={ + cut.shipped + ? `${fmtDur(durations[cut.shipped.rel] ?? 0)} · ${fmtBytes(cut.shipped.size)}` + : "not built" + } + meta={ + <span className="flex flex-wrap items-baseline gap-x-2.5" data-song-cut-picker={cutName}> + <span className="micro">cut</span> + {song.cuts.map((c) => + c.name === cutName ? ( + <span key={c.name} aria-current="page" className="font-mono text-[12.5px] font-semibold text-text"> + {c.name} + </span> + ) : ( + <Link key={c.name} href={cutHref(project.id, c.name)} prefetch={false} className="ink-link font-mono text-[12.5px]"> + {c.name} + </Link> + ), + )} + </span> + } + > {!cut.shipped && cut.variants.length === 0 ? ( <div className="p-4 text-[12px] text-[var(--color-dim)]"> Nothing here yet — no <code className="font-mono">{cutName}.mp4</code> and no variants named for it.{" "} - <Link href={`/projects/${song.id}`} className="ink-link"> + <Link href={projectHref(project.id, { tab: "cuts" })} className="ink-link"> back to {song.id} </Link> </div> @@ -119,7 +147,6 @@ export default async function CutPage({ </div> </> )} - </main> - </div> + </SongFrame> ); } diff --git a/umtool/components/projects/ProjectView.tsx b/umtool/components/projects/ProjectView.tsx @@ -36,8 +36,9 @@ export default async function ProjectView({ }) { switch (project.kind) { case "song": { - if (rest.length === 0) return <SongProject id={project.name} />; - if (rest.length === 1) return <CutPage id={project.name} cutName={rest[0]} search={search} />; + // The song piece (P4a-3), and a cut's page: a view of its Cuts tab. + if (rest.length === 0) return <SongProject project={project} search={search} />; + if (rest.length === 1) return <CutPage project={project} cutName={rest[0]} search={search} />; return notFound(); } case "report-video": { diff --git a/umtool/components/projects/SongProject.tsx b/umtool/components/projects/SongProject.tsx @@ -1,255 +1,67 @@ -import Link from "next/link"; import { notFound } from "next/navigation"; -import BrowseHeader from "@/components/BrowseHeader"; -import VerdictChip from "@/components/VerdictChip"; -import SpecSheet from "@/components/SpecSheet"; -import NoteField from "@/components/NoteField"; -import CopyButton from "@/components/CopyButton"; -import { readSong, probeAll, thumbAliasesFor, type Cut, type Song } from "@/lib/browse"; -import ThumbBench from "@/components/ThumbBench"; +import { readSong, thumbAliasesFor } from "@/lib/browse"; import { thumbView } from "@/lib/thumbs"; -import { fmtAgo, fmtBytes, fmtDur } from "@/lib/format"; -import { Markdown } from "@/lib/markdown"; -import { operationsFor, readSpec, validateSpec } from "@/lib/spec"; -import { readNotes, type NoteMap } from "@/lib/notes"; -import { TRIM_SETS } from "@/lib/trim"; +import { readNotes } from "@/lib/notes"; +import { songTabOf } from "@/lib/pieces/song-tabs.mjs"; +import type { ProjectRef } from "@/lib/project-types"; +import SongFrame, { readSongFrame, songCounts } from "./song/SongFrame"; +import OverviewTab from "./song/OverviewTab"; +import CutsTab from "./song/CutsTab"; +import SpecTab from "./song/SpecTab"; +import CoverTab from "./song/CoverTab"; +import NotesTab from "./song/NotesTab"; -// Moved out of app/browse/[song]/page.tsx unchanged, because [song] and -// [...path] cannot both be dynamic segments at the same level. The dispatcher -// in ProjectView.tsx hands it an id; nothing else about the page differs. +// --------------------------------------------------------------------------- +// A song, as a PIECE PAGE (plans/umtool-redesign.md, P4a-3). +// +// Moved out of app/browse/[song]/page.tsx unchanged in P3, because [song] and +// [...path] cannot both be dynamic segments at the same level; the dispatcher +// in ProjectView.tsx hands it the project. Since P4a-3 it is the piece frame +// (components/projects/song/SongFrame.tsx: head, Spec → Cuts → Done stepper, +// lifecycle, Next card, tabs, keys) around ONE tab, and the sections it drew in +// two columns live in the tabs (components/projects/song/*), moved unchanged: +// +// head row: the song's note → Notes; "copy this song" → Overview +// the cut cards, what matches no cut → Cuts +// the cover bench → Cover +// the spec sheet, the plans → Spec +// the README → Overview +// +// Which section is on which tab is lib/pieces/song-tabs.mjs SONG_SECTION_TAB. +// Only the tab on show is read: the Cuts tab's ffprobes and the spec's +// validation cost nothing on the Overview. +// --------------------------------------------------------------------------- -export default async function SongProject({ id }: { id: string }) { +export default async function SongProject({ + project, + search, +}: { + project: ProjectRef; + search: Record<string, string | undefined>; +}) { + // Keyed by BASENAME, as every song route is (lib/browse.ts songDir). + const id = project.name; const song = await readSong(id); if (!song) notFound(); - // Durations are worth an ffprobe HERE but not on the index: this page is a - // handful of files and "which of these is the short cut" is exactly the - // question it answers. Memoised by mtime in lib/browse.ts. - const rels = [ - ...song.cuts.flatMap((c) => [c.shipped?.rel, ...c.variants.map((v) => v.rel)]), - ...song.unattributed.map((v) => v.rel), - ].filter((r): r is string => !!r); - const info = await probeAll(id, rels); - - const spec = await readSpec(id); - const problems = await validateSpec(spec); - const notes = await readNotes(id); - // Two small JSON reads, no probing -- the bench draws what the manifests say. - const thumbs = await thumbView(id, thumbAliasesFor(id)); + const tab = songTabOf(search); + // Two small JSON reads each, no probing. + const [frame, notes, thumbs] = await Promise.all([readSongFrame(project, song), readNotes(id), thumbView(id, thumbAliasesFor(id))]); return ( - <div className="flex h-full flex-col"> - <BrowseHeader - crumbs={[{ href: "/projects", label: "songs" }, { label: song.id }]} - note={`${song.present}/${song.cuts.length} cuts · ${song.variantCount} variants`} - /> - <div className="flex flex-wrap items-start gap-3 border-b border-[var(--color-line)] px-4 py-2"> - <div className="min-w-0 flex-1"> - {/* The one obvious place to write about the song, open by default -- - everything else on the page is collapsed until asked for. */} - <NoteField song={id} target="song" initial={notes.song ?? null} label="notes on this song" /> - </div> - <CopyButton - label="copy this song" - title="this song as markdown — spec, cuts, verdicts, notes and resolved marks" - url={`/api/browse/context?song=${encodeURIComponent(id)}`} - /> - </div> - <main className="deck-main flex-1"> - <div className="grid gap-4 p-4 xl:grid-cols-[minmax(0,2fr)_minmax(0,1fr)]"> - <div className="space-y-3"> - {song.cuts.map((cut) => ( - <CutCard key={cut.name} song={song} cut={cut} info={info} notes={notes} /> - ))} - - {song.unattributed.length > 0 && ( - <section className="rounded border border-[var(--color-dirty)]/40 bg-[var(--color-panel)] p-3"> - <div className="micro mb-2"> - matches no cut name — attribute by renaming, never by guessing - </div> - <ul className="space-y-1"> - {song.unattributed.map((v) => ( - <li key={v.rel} className="num text-[12px] text-[var(--color-dim)]"> - <span className="font-mono text-[var(--color-text)]">{v.rel}</span>{" "} - {fmtBytes(v.size)} - </li> - ))} - </ul> - </section> - )} - </div> - - <aside className="space-y-4"> - <ThumbBench song={song.id} view={thumbs} notes={notes} /> - <SpecSheet - song={song.id} - initial={spec} - problems={problems} - operations={operationsFor(spec, song)} - plans={song.plans.map((p) => p.name)} - trimSets={Object.values(TRIM_SETS).map((t) => ({ id: t.id, label: t.label }))} - /> - {song.readme && ( - <section className="rounded border border-[var(--color-line)] bg-[var(--color-panel)] p-3"> - <Markdown text={song.readme} /> - </section> - )} - <section className="rounded border border-[var(--color-line)] bg-[var(--color-panel)] p-3"> - <div className="micro mb-2">plans</div> - {song.plans.length === 0 ? ( - <p className="text-[12px] text-[var(--color-dim)]">no plan/ directory</p> - ) : ( - <ul className="space-y-0.5"> - {song.plans.map((p) => ( - <li key={p.name} className="num text-[11px] text-[var(--color-dim)]"> - <span className="flex gap-2"> - <span className="truncate font-mono text-[var(--color-text)]">{p.name}</span> - <span className="ml-auto shrink-0">{fmtBytes(p.size)}</span> - </span> - <NoteField - song={song.id} - target={`plan:${p.name}`} - initial={notes[`plan:${p.name}`] ?? null} - label="what this plan is" - rows={3} - /> - </li> - ))} - </ul> - )} - {song.hasClipsCsv && <div className="micro mt-2">clips.csv present</div>} - </section> - </aside> - </div> - </main> - </div> - ); -} - -function CutCard({ - song, - cut, - info, - notes, -}: { - song: Song; - cut: Cut; - info: Record<string, { duration: number; width: number; height: number }>; - notes: NoteMap; -}) { - const shipped = cut.shipped; - const live = cut.variants.filter((v) => !v.retired); - const retired = cut.variants.filter((v) => v.retired); - - return ( - <section - data-cut={cut.name} - data-present={shipped ? "1" : "0"} - className="rounded border border-[var(--color-line)] bg-[var(--color-panel)]" + <SongFrame + project={project} + song={song} + frame={frame} + tab={tab} + counts={songCounts(song, notes, thumbs.candidates.length)} + note={`${song.present}/${song.cuts.length} cuts · ${song.variantCount} variants`} > - <div className="flex items-start gap-3 p-3"> - {shipped ? ( - /* eslint-disable-next-line @next/next/no-img-element */ - <img - src={`/api/browse/poster?song=${encodeURIComponent(song.id)}&rel=${encodeURIComponent(shipped.rel)}&w=320`} - alt="" - width={160} - height={90} - className="w-40 shrink-0 rounded bg-[var(--color-panel-2)] object-cover" - /> - ) : ( - <div className="flex h-[90px] w-40 shrink-0 items-center justify-center rounded border border-dashed border-[var(--color-line)] text-[11px] text-[var(--color-dim)]"> - not built - </div> - )} - - <div className="min-w-0 flex-1 space-y-1"> - <div className="flex flex-wrap items-baseline gap-2"> - <Link - href={`/projects/${song.id}/${cut.name}`} - className="font-mono text-[13px] text-[var(--color-text)] hover:text-[var(--color-sel)]" - > - {cut.name} - </Link> - {shipped ? ( - <span className="num text-[11px] text-[var(--color-meter)]"> - {fmtDur(info[shipped.rel]?.duration ?? 0)} - </span> - ) : ( - <span className="text-[11px] text-[var(--color-dim)]">— a hole in the set</span> - )} - {shipped && info[shipped.rel] && ( - <span className="num text-[11px] text-[var(--color-dim)]"> - {info[shipped.rel].width}×{info[shipped.rel].height} - </span> - )} - <span className="num ml-auto text-[11px] text-[var(--color-dim)]"> - {shipped ? `${fmtBytes(shipped.size)} · ${fmtAgo(shipped.mtimeMs)}` : ""} - </span> - </div> - - {shipped && ( - <VerdictChip song={song.id} rel={shipped.rel} initial={shipped.verdict} /> - )} - - {/* Two different notes, deliberately. The `cut:` one is about the SLOT - -- it survives a promote and can be written about a cut that has - not been built. The `file:` one is about these bytes. */} - <NoteField - song={song.id} - target={`cut:${cut.name}`} - initial={notes[`cut:${cut.name}`] ?? null} - label={`notes on ${cut.name}`} - rows={3} - /> - {shipped && ( - <NoteField - song={song.id} - target={`file:${shipped.rel}`} - initial={notes[`file:${shipped.rel}`] ?? null} - label="notes on this file" - rows={3} - /> - )} - - {live.length > 0 && ( - <ul className="space-y-1 pt-1"> - {live.map((v) => ( - <li - key={v.rel} - data-variant={v.rel} - data-variant-tag={v.tag} - className="flex flex-wrap items-center gap-2 rounded bg-[var(--color-panel-2)] px-2 py-1" - > - <span className="font-mono text-[12px] text-[var(--color-text)]">{v.tag}</span> - <span className="num text-[11px] text-[var(--color-meter)]"> - {fmtDur(info[v.rel]?.duration ?? 0)} - </span> - <span className="num text-[11px] text-[var(--color-dim)]">{fmtBytes(v.size)}</span> - <div className="ml-auto"> - <VerdictChip song={song.id} rel={v.rel} initial={v.verdict} /> - </div> - <div className="w-full"> - <NoteField - song={song.id} - target={`file:${v.rel}`} - initial={notes[`file:${v.rel}`] ?? null} - label={`notes on ${v.tag}`} - rows={3} - /> - </div> - </li> - ))} - </ul> - )} - - {retired.length > 0 && ( - <div className="micro pt-1" data-retired={retired.length}> - {retired.length} retired: {retired.map((v) => v.tag).join(", ")} - </div> - )} - </div> - </div> - </section> + {tab === "overview" && <OverviewTab project={project} song={song} frame={frame} covers={thumbs} />} + {tab === "cuts" && <CutsTab song={song} notes={notes} />} + {tab === "spec" && <SpecTab song={song} notes={notes} />} + {tab === "cover" && <CoverTab song={song} view={thumbs} notes={notes} />} + {tab === "notes" && <NotesTab projectId={project.id} song={song} notes={notes} />} + </SongFrame> ); } diff --git a/umtool/components/projects/song/CoverTab.tsx b/umtool/components/projects/song/CoverTab.tsx @@ -0,0 +1,24 @@ +import ThumbBench from "@/components/ThumbBench"; +import type { Song } from "@/lib/browse"; +import type { NoteMap } from "@/lib/notes"; +import type { ThumbView } from "@/lib/thumbs"; + +// The Cover tab: the cover-art bench -- the candidates, the corners each would +// spend, accepting one, the way to the face judger -- SongProject's aside, +// moved unchanged (P4a-3). The bench draws nothing when there is nothing to +// judge, so the tab says so. + +export default function CoverTab({ song, view, notes }: { song: Song; view: ThumbView; notes: NoteMap }) { + if (!view.candidates.length && !view.accepted) { + return ( + <p className="text-[12.5px] text-muted" data-song-cover-empty=""> + No cover generated for {song.id} yet — nothing in the thumb manifest names it. + </p> + ); + } + return ( + <div className="max-w-[1100px]"> + <ThumbBench song={song.id} view={view} notes={notes} /> + </div> + ); +} diff --git a/umtool/components/projects/song/CutsTab.tsx b/umtool/components/projects/song/CutsTab.tsx @@ -0,0 +1,174 @@ +import Link from "next/link"; +import VerdictChip from "@/components/VerdictChip"; +import NoteField from "@/components/NoteField"; +import { probeAll, type Cut, type Song } from "@/lib/browse"; +import { fmtAgo, fmtBytes, fmtDur } from "@/lib/format"; +import type { NoteMap } from "@/lib/notes"; + +// The Cuts tab: the four cut cards (poster, verdicts, the slot's and the +// file's notes, the variants) and what matches no cut -- SongProject's left +// column, moved unchanged (P4a-3). A cut's own page (/projects/<song>/<cut>, +// CutPage) is this tab's view of one cut. + +export default async function CutsTab({ song, notes }: { song: Song; notes: NoteMap }) { + // Durations are worth an ffprobe HERE but not on the index: this page is a + // handful of files and "which of these is the short cut" is exactly the + // question it answers. Memoised by mtime in lib/browse.ts. + const rels = [ + ...song.cuts.flatMap((c) => [c.shipped?.rel, ...c.variants.map((v) => v.rel)]), + ...song.unattributed.map((v) => v.rel), + ].filter((r): r is string => !!r); + const info = await probeAll(song.id, rels); + + return ( + <div className="max-w-[1100px] space-y-3" data-song-cuts=""> + {song.cuts.map((cut) => ( + <CutCard key={cut.name} song={song} cut={cut} info={info} notes={notes} /> + ))} + + {song.unattributed.length > 0 && ( + <section className="rounded border border-[var(--color-dirty)]/40 bg-[var(--color-panel)] p-3" data-unattributed={song.unattributed.length}> + <div className="micro mb-2"> + matches no cut name — attribute by renaming, never by guessing + </div> + <ul className="space-y-1"> + {song.unattributed.map((v) => ( + <li key={v.rel} className="num text-[12px] text-[var(--color-dim)]"> + <span className="font-mono text-[var(--color-text)]">{v.rel}</span>{" "} + {fmtBytes(v.size)} + </li> + ))} + </ul> + </section> + )} + </div> + ); +} + +function CutCard({ + song, + cut, + info, + notes, +}: { + song: Song; + cut: Cut; + info: Record<string, { duration: number; width: number; height: number }>; + notes: NoteMap; +}) { + const shipped = cut.shipped; + const live = cut.variants.filter((v) => !v.retired); + const retired = cut.variants.filter((v) => v.retired); + + return ( + <section + data-cut={cut.name} + data-present={shipped ? "1" : "0"} + className="rounded border border-[var(--color-line)] bg-[var(--color-panel)]" + > + <div className="flex items-start gap-3 p-3"> + {shipped ? ( + /* eslint-disable-next-line @next/next/no-img-element */ + <img + src={`/api/browse/poster?song=${encodeURIComponent(song.id)}&rel=${encodeURIComponent(shipped.rel)}&w=320`} + alt="" + width={160} + height={90} + className="w-40 shrink-0 rounded bg-[var(--color-panel-2)] object-cover" + /> + ) : ( + <div className="flex h-[90px] w-40 shrink-0 items-center justify-center rounded border border-dashed border-[var(--color-line)] text-[11px] text-[var(--color-dim)]"> + not built + </div> + )} + + <div className="min-w-0 flex-1 space-y-1"> + <div className="flex flex-wrap items-baseline gap-2"> + <Link + href={`/projects/${song.id}/${cut.name}`} + className="font-mono text-[13px] text-[var(--color-text)] hover:text-[var(--color-sel)]" + > + {cut.name} + </Link> + {shipped ? ( + <span className="num text-[11px] text-[var(--color-meter)]"> + {fmtDur(info[shipped.rel]?.duration ?? 0)} + </span> + ) : ( + <span className="text-[11px] text-[var(--color-dim)]">— a hole in the set</span> + )} + {shipped && info[shipped.rel] && ( + <span className="num text-[11px] text-[var(--color-dim)]"> + {info[shipped.rel].width}×{info[shipped.rel].height} + </span> + )} + <span className="num ml-auto text-[11px] text-[var(--color-dim)]"> + {shipped ? `${fmtBytes(shipped.size)} · ${fmtAgo(shipped.mtimeMs)}` : ""} + </span> + </div> + + {shipped && ( + <VerdictChip song={song.id} rel={shipped.rel} initial={shipped.verdict} /> + )} + + {/* Two different notes, deliberately. The `cut:` one is about the SLOT + -- it survives a promote and can be written about a cut that has + not been built. The `file:` one is about these bytes. */} + <NoteField + song={song.id} + target={`cut:${cut.name}`} + initial={notes[`cut:${cut.name}`] ?? null} + label={`notes on ${cut.name}`} + rows={3} + /> + {shipped && ( + <NoteField + song={song.id} + target={`file:${shipped.rel}`} + initial={notes[`file:${shipped.rel}`] ?? null} + label="notes on this file" + rows={3} + /> + )} + + {live.length > 0 && ( + <ul className="space-y-1 pt-1"> + {live.map((v) => ( + <li + key={v.rel} + data-variant={v.rel} + data-variant-tag={v.tag} + className="flex flex-wrap items-center gap-2 rounded bg-[var(--color-panel-2)] px-2 py-1" + > + <span className="font-mono text-[12px] text-[var(--color-text)]">{v.tag}</span> + <span className="num text-[11px] text-[var(--color-meter)]"> + {fmtDur(info[v.rel]?.duration ?? 0)} + </span> + <span className="num text-[11px] text-[var(--color-dim)]">{fmtBytes(v.size)}</span> + <div className="ml-auto"> + <VerdictChip song={song.id} rel={v.rel} initial={v.verdict} /> + </div> + <div className="w-full"> + <NoteField + song={song.id} + target={`file:${v.rel}`} + initial={notes[`file:${v.rel}`] ?? null} + label={`notes on ${v.tag}`} + rows={3} + /> + </div> + </li> + ))} + </ul> + )} + + {retired.length > 0 && ( + <div className="micro pt-1" data-retired={retired.length}> + {retired.length} retired: {retired.map((v) => v.tag).join(", ")} + </div> + )} + </div> + </div> + </section> + ); +} diff --git a/umtool/components/projects/song/NotesTab.tsx b/umtool/components/projects/song/NotesTab.tsx @@ -0,0 +1,51 @@ +import Link from "next/link"; +import NoteField from "@/components/NoteField"; +import type { Song } from "@/lib/browse"; +import { projectHref } from "@/lib/hrefs"; +import type { NoteMap } from "@/lib/notes"; +import { SONG_PIECE_TABS, songTabOfNote } from "@/lib/pieces/song-tabs.mjs"; + +// The Notes tab: the note on the song as a whole -- the one obvious place to +// write about it, SongProject's head row, moved unchanged (P4a-3) -- and, under +// it, every other note on the song, each linking the tab it is written on (a +// cut's, a file's or a mark's on Cuts, a plan's on Spec, a cover's on Cover). + +const TAB_LABEL = Object.fromEntries(SONG_PIECE_TABS.map((t) => [t.id, t.label])); + +export default function NotesTab({ projectId, song, notes }: { projectId: string; song: Song; notes: NoteMap }) { + const others = Object.entries(notes) + .filter(([target, n]) => target !== "song" && n && typeof n.note === "string" && n.note.trim()) + .sort(([a], [b]) => a.localeCompare(b)); + return ( + <div className="max-w-[900px] space-y-5"> + <section data-song-note=""> + <NoteField song={song.id} target="song" initial={notes.song ?? null} label="notes on this song" /> + </section> + + <section data-song-notes={others.length}> + <h2 className="micro mb-1.5"> + Every other note · <span className="font-mono text-meter">{others.length}</span> + </h2> + {others.length === 0 ? ( + <p className="text-[12.5px] text-muted">None yet. Notes on a cut, a file, a plan or a cover show here.</p> + ) : ( + <ul className="divide-y divide-seam border-y border-seam"> + {others.map(([target, n]) => { + const tab = songTabOfNote(target); + const first = n.note.split("\n").find((l) => l.trim()) ?? ""; + return ( + <li key={target} data-song-note-target={target} className="flex items-baseline gap-3 py-1.5 text-[12.5px]"> + <span className="w-[260px] shrink-0 truncate font-mono text-[11.5px] text-text-2">{target}</span> + <span className="min-w-0 flex-1 truncate text-text">{first}</span> + <Link href={projectHref(projectId, { tab })} prefetch={false} className="ink-link shrink-0 text-[12px]"> + {TAB_LABEL[tab] ?? tab} + </Link> + </li> + ); + })} + </ul> + )} + </section> + </div> + ); +} diff --git a/umtool/components/projects/song/OverviewTab.tsx b/umtool/components/projects/song/OverviewTab.tsx @@ -0,0 +1,189 @@ +import Link from "next/link"; +import { Suspense } from "react"; +import CopyButton from "@/components/CopyButton"; +import NextCard, { NextCardShell } from "@/components/piece/NextCard"; +import { ProjectDecisions } from "@/components/projects/report/OverviewTab"; +import { PILE_WHAT } from "@/components/dashboard/ToolList"; +import { CUT_NAMES, type Song } from "@/lib/browse"; +import { decisionsForProject } from "@/lib/projects"; +import { fmtBytes } from "@/lib/format"; +import { cutHref, findHref, mixHref, pileHref, projectHref, songToolsHref, sourcesHref, trimHref } from "@/lib/hrefs"; +import { Markdown } from "@/lib/markdown"; +import type { PieceFrame } from "@/lib/pieces/frame"; +import type { ProjectRef } from "@/lib/project-types"; +import { readSpec } from "@/lib/spec"; +import { MODES } from "@/lib/types"; +import type { ThumbView } from "@/lib/thumbs"; + +// The Overview tab of a song piece (P4a-3; canvas "Piece · Overview" in a +// song's words): the Next card -- the song's top Inbox call, an unjudged +// variant, a missing cut, a stale recipe -- then the song's decisions and its +// four cut slots beside what the song is, the paste ("copy this song", from +// SongProject's head row), and the song tools, which stay in Tools (the four +// judging piles, find, mix, sources, the hook trimmer). The README is +// SongProject's, unchanged. + +export default async function OverviewTab({ + project, + song, + frame, + covers, +}: { + project: ProjectRef; + song: Song; + frame: PieceFrame; + covers: ThumbView; +}) { + const [decisions, spec] = await Promise.all([decisionsForProject(project), readSpec(song.id)]); + const looksDone = (frame.piece?.looksDone ?? []).map((w) => w.replace(`${project.id}: `, "")); + if (!looksDone.length && song.present === CUT_NAMES.length) looksDone.push("every cut shipped"); + const trimSet = spec.hooks?.trimSet ?? null; + + return ( + <> + <Suspense + fallback={ + <NextCardShell pending> + <span className="text-[12.5px] text-muted">Reading the Inbox…</span> + </NextCardShell> + } + > + <NextCard pieceId={frame.pieceId} title={frame.piece?.title ?? song.title} lifecycle={frame.lifecycle} /> + </Suspense> + + <div className="grid grid-cols-1 gap-[22px] lg:grid-cols-[minmax(0,1.25fr)_minmax(0,1fr)]"> + <div className="min-w-0 space-y-4"> + {/* --- what is wrong, first ------------------------------------- */} + <ProjectDecisions project={project.id} decisions={decisions} /> + + <section data-song-slots={song.present}> + <div className="mb-1.5 flex items-baseline gap-3"> + <h2 className="micro"> + Cuts · <span className="font-mono text-meter">{song.present}</span> of {song.cuts.length} + </h2> + <Link href={projectHref(project.id, { tab: "cuts" })} prefetch={false} className="ink-link ml-auto text-[12px]"> + All cuts → + </Link> + </div> + <ul className="border-y border-seam"> + {song.cuts.map((cut) => { + const live = cut.variants.filter((v) => !v.retired).length; + return ( + <li + key={cut.name} + data-song-slot={cut.name} + data-present={cut.shipped ? "1" : "0"} + className="flex items-baseline gap-3 border-b border-seam py-1.5 text-[13px] last:border-b-0" + > + <Link href={cutHref(project.id, cut.name)} prefetch={false} className="ink-link font-mono text-[12.5px]"> + {cut.name} + </Link> + <span className="text-[12px] text-muted"> + {cut.shipped ? `built · ${fmtBytes(cut.shipped.size)}` : "a hole in the set"} + </span> + <span className="ml-auto font-mono text-[11.5px] text-meter"> + {live ? `${live} variant${live === 1 ? "" : "s"}` : ""} + </span> + </li> + ); + })} + </ul> + </section> + </div> + + <div className="min-w-0 space-y-4"> + <section data-piece-stats=""> + <div className="mb-1.5 flex items-baseline gap-3"> + <h2 className="micro">This song</h2> + <span className="ml-auto" data-song-copy=""> + <CopyButton + label="copy this song" + title="this song as markdown — spec, cuts, verdicts, notes and resolved marks" + url={`/api/browse/context?song=${encodeURIComponent(song.id)}`} + /> + </span> + </div> + <ul className="text-[13px] text-text-2"> + <li className="flex gap-2.5 border-b border-seam py-1.5"> + cuts built + <span className="ml-auto font-mono text-[11.5px] text-meter"> + {song.present} / {song.cuts.length} + {song.missing.length ? ` · no ${song.missing.join(", ")}` : ""} + </span> + </li> + <li className="flex gap-2.5 border-b border-seam py-1.5"> + variants + <span className="ml-auto font-mono text-[11.5px] text-meter">{song.variantCount}</span> + </li> + <li className="flex gap-2.5 border-b border-seam py-1.5"> + verdicts + <span className="ml-auto font-mono text-[11.5px] text-meter"> + {song.counts.keep} keep · {song.counts.reject} reject · {song.counts.undecided} undecided + </span> + </li> + <li className="flex gap-2.5 border-b border-seam py-1.5"> + plans + <span className="ml-auto font-mono text-[11.5px] text-meter">{song.plans.length}</span> + </li> + <li className="flex gap-2.5 border-b border-seam py-1.5"> + cover + <span className="ml-auto text-[12px] text-text-2"> + {covers.accepted ? `accepted · ${covers.accepted.name}` : covers.candidates.length ? `${covers.candidates.length} on offer, none accepted` : "none generated"} + </span> + </li> + {looksDone.length > 0 && frame.lifecycle === "active" && ( + <li className="flex gap-2.5 border-b border-seam py-1.5" data-song-looks-done=""> + looks done + <span className="ml-auto text-[12px] text-muted">{looksDone.join("; ")}</span> + </li> + )} + </ul> + </section> + + <section data-song-tools=""> + <h2 className="micro mb-1.5">Song tools</h2> + <ul className="text-[13px]"> + {MODES.map((m) => ( + <li key={m} className="flex gap-2.5 border-b border-seam py-1.5"> + <Link href={pileHref(m)} prefetch={false} className="ink-link" data-song-pile={m}> + {m} + </Link> + <span className="ml-auto truncate text-[12px] text-muted">{PILE_WHAT[m]}</span> + </li> + ))} + {trimSet && ( + <li className="flex gap-2.5 border-b border-seam py-1.5"> + <Link href={trimHref(trimSet)} prefetch={false} className="ink-link" data-song-trim={trimSet}> + trim {trimSet} + </Link> + <span className="ml-auto truncate text-[12px] text-muted">the hook trimmer, for the spec&apos;s hooks</span> + </li> + )} + </ul> + <p className="mt-1.5 flex flex-wrap gap-x-3 text-[12px]"> + <Link href={songToolsHref()} prefetch={false} className="ink-link"> + song piles + </Link> + <Link href={findHref()} prefetch={false} className="ink-link"> + find + </Link> + <Link href={mixHref()} prefetch={false} className="ink-link"> + mix + </Link> + <Link href={sourcesHref()} prefetch={false} className="ink-link"> + sources + </Link> + </p> + </section> + </div> + </div> + + {/* --- the song's own account of itself ---------------------------- */} + {song.readme && ( + <section data-readme="" className="rounded border border-[var(--color-line)] bg-[var(--color-panel)] p-3"> + <Markdown text={song.readme} /> + </section> + )} + </> + ); +} diff --git a/umtool/components/projects/song/SongFrame.tsx b/umtool/components/projects/song/SongFrame.tsx @@ -0,0 +1,95 @@ +import { stat } from "node:fs/promises"; +import PieceFrame from "@/components/piece/PieceFrame"; +import type { Crumb } from "@/components/shell/AppHeader"; +import { CUT_NAMES, type Song } from "@/lib/browse"; +import { projectHref, projectsHref } from "@/lib/hrefs"; +import type { NoteMap } from "@/lib/notes"; +import { readPieceFrame, type PieceFrame as Frame } from "@/lib/pieces/frame"; +import { SONG_PIECE_TABS } from "@/lib/pieces/song-tabs.mjs"; +import { specFile } from "@/lib/spec"; +import type { ProjectRef } from "@/lib/project-types"; + +// --------------------------------------------------------------------------- +// A SONG PIECE's frame (plans/umtool-redesign.md, P4a-3): the P4a frame +// (components/piece/PieceFrame.tsx -- head, stepper, lifecycle, Next, tabs, +// keys) around one of a song's five tabs, Overview · Cuts · Spec · Cover · +// Notes (lib/pieces/song-tabs.mjs). The song page and a cut's page (a view of +// the Cuts tab) both draw through it. +// +// The stepper is Spec → Cuts → Done, by the one stage rule (lib/pieces/tabs.mjs +// pieceSteps on the flow the song kind declares). The page has the song in +// hand, so the facts that light it are read fresh here (a promote shows at +// once); Work's facet reads the same facts off the pieces graph. +// --------------------------------------------------------------------------- + +/** What a song piece has reached, from the song the page already read (one stat for spec.json). */ +export async function songReachedNow(song: Song): Promise<{ spec: boolean; cuts: boolean; done: boolean }> { + const spec = await stat(specFile(song.id)).then( + () => true, + () => false, + ); + return { spec, cuts: song.present > 0, done: song.present === CUT_NAMES.length }; +} + +export async function readSongFrame(project: ProjectRef, song: Song): Promise<Frame> { + return readPieceFrame(project, { reached: await songReachedNow(song) }); +} + +/** A song tab's count, in Meter: cuts built, covers on offer, notes written. */ +export function songCounts(song: Song, notes: NoteMap, covers: number): Partial<Record<string, number>> { + const written = Object.values(notes).filter((n) => n && typeof n.note === "string" && n.note.trim()).length; + return { cuts: song.present, cover: covers, notes: written }; +} + +export default function SongFrame({ + project, + song, + frame, + tab, + counts, + note, + meta, + idHref, + bare = false, + children, +}: { + project: ProjectRef; + song: Song; + frame: Frame; + tab: string; + counts: Partial<Record<string, number>>; + /** The head's status line. */ + note?: React.ReactNode; + /** A line beside the title (a cut's page: which cut). */ + meta?: React.ReactNode; + /** Link the trail's project id (a cut's page: back to the song). */ + idHref?: string; + /** The body pads itself (a cut's page: the bench is edge to edge). */ + bare?: boolean; + children: React.ReactNode; +}) { + const title = frame.piece?.title ?? song.title; + const crumbs: Crumb[] = [ + { href: projectsHref(), label: "projects" }, + { label: project.id, ...(idHref ? { href: idHref } : {}) }, + { label: title }, + ]; + return ( + <div className="flex h-full flex-col" data-song-piece={song.id}> + <PieceFrame + crumbs={crumbs} + frame={frame} + tab={tab} + tabs={SONG_PIECE_TABS.map((t) => ({ ...t, href: projectHref(project.id, { tab: t.id }) }))} + counts={counts} + note={note} + meta={meta} + more={<span className="px-2 pb-1 pt-0.5 font-mono text-[11px] text-muted">{project.id}</span>} + > + <main className={bare ? "deck-main flex-1" : "deck-main flex-1 space-y-4 p-4"} data-piece-tab={tab}> + {children} + </main> + </PieceFrame> + </div> + ); +} diff --git a/umtool/components/projects/song/SpecTab.tsx b/umtool/components/projects/song/SpecTab.tsx @@ -0,0 +1,57 @@ +import SpecSheet from "@/components/SpecSheet"; +import NoteField from "@/components/NoteField"; +import type { Song } from "@/lib/browse"; +import { fmtBytes } from "@/lib/format"; +import type { NoteMap } from "@/lib/notes"; +import { operationsFor, readSpec, validateSpec } from "@/lib/spec"; +import { TRIM_SETS } from "@/lib/trim"; + +// The Spec tab: the spec sheet (what the song is made of, and so the +// operations it can run) and the plans in plan/ with their notes -- +// SongProject's aside, moved unchanged (P4a-3). + +export default async function SpecTab({ song, notes }: { song: Song; notes: NoteMap }) { + const spec = await readSpec(song.id); + const problems = await validateSpec(spec); + return ( + <div className="grid grid-cols-1 gap-4 lg:grid-cols-[minmax(0,1.4fr)_minmax(0,1fr)]"> + <div className="min-w-0"> + <SpecSheet + song={song.id} + initial={spec} + problems={problems} + operations={operationsFor(spec, song)} + plans={song.plans.map((p) => p.name)} + trimSets={Object.values(TRIM_SETS).map((t) => ({ id: t.id, label: t.label }))} + /> + </div> + <div className="min-w-0"> + <section className="rounded border border-[var(--color-line)] bg-[var(--color-panel)] p-3" data-song-plans={song.plans.length}> + <div className="micro mb-2">plans</div> + {song.plans.length === 0 ? ( + <p className="text-[12px] text-[var(--color-dim)]">no plan/ directory</p> + ) : ( + <ul className="space-y-0.5"> + {song.plans.map((p) => ( + <li key={p.name} className="num text-[11px] text-[var(--color-dim)]"> + <span className="flex gap-2"> + <span className="truncate font-mono text-[var(--color-text)]">{p.name}</span> + <span className="ml-auto shrink-0">{fmtBytes(p.size)}</span> + </span> + <NoteField + song={song.id} + target={`plan:${p.name}`} + initial={notes[`plan:${p.name}`] ?? null} + label="what this plan is" + rows={3} + /> + </li> + ))} + </ul> + )} + {song.hasClipsCsv && <div className="micro mt-2">clips.csv present</div>} + </section> + </div> + </div> + ); +} diff --git a/umtool/lib/decisions.ts b/umtool/lib/decisions.ts @@ -7,6 +7,7 @@ import { readNotes, type NoteMap } from "./notes"; import { listNotesFiles } from "./annotations/targets.mjs"; import { acceptedFor, readThumbAccepted, readThumbManifest, thumbNamesFor } from "./thumbs"; import { articleHrefOf } from "./articles/href"; +import { songTabOfSection } from "./pieces/song-tabs.mjs"; // --------------------------------------------------------------------------- // Everything undecided, in one worklist. @@ -135,7 +136,10 @@ export async function decisionsForSong(id: string): Promise<Decision[]> { ]); const out: Decision[] = []; - const songHref = `/projects/${id}`; + // A song-wide call opens the song piece's tab its section is on (P4a-3, + // lib/pieces/song-tabs.mjs): the spec's on Spec, a stray variant on Cuts, a + // cover on Cover. A cut's call opens the cut's page (the Cuts tab's view). + const songHref = (section: string) => `/projects/${id}?tab=${songTabOfSection(section)}`; const cutHref = (cut: string) => `/projects/${id}/${cut}`; const target = { lufs: spec.loudness?.targetLufs ?? DEFAULT_TARGET.lufs, @@ -149,7 +153,7 @@ export async function decisionsForSong(id: string): Promise<Decision[]> { project: id, target: p.where, why: p.message, - href: songHref, + href: songHref("spec"), // `pending` is the sheet being right about a file you have not rendered // yet, which is a normal state to save from -- so it is not a decision. severity: p.level === "error" ? "blocking" : "info", @@ -254,7 +258,7 @@ export async function decisionsForSong(id: string): Promise<Decision[]> { project: id, target: v.rel, why: "matches no cut name — attribute it by renaming, never by guessing", - href: songHref, + href: songHref("unattributed"), severity: "open", at: v.mtimeMs, }); @@ -268,7 +272,7 @@ export async function decisionsForSong(id: string): Promise<Decision[]> { project: id, target: named, why: `spec names plan/${named}, which is not there — provenance cannot resolve`, - href: songHref, + href: songHref("plans"), severity: "open", at: song.newestMtimeMs, }); @@ -280,7 +284,7 @@ export async function decisionsForSong(id: string): Promise<Decision[]> { why: `${song.plans.length} plan${song.plans.length > 1 ? "s" : ""} in plan/ and none named — ` + "which one shipped is not recorded, so it is not guessed", - href: songHref, + href: songHref("plans"), // Three of the five songs here have a 2-voice and a 3-voice arrangement // of the same tune. Nothing on disk says which shipped; only a person // can, and until they do every provenance figure is unattributed. @@ -297,7 +301,7 @@ export async function decisionsForSong(id: string): Promise<Decision[]> { project: id, target: candidates.join(", "), why: `${candidates.length} generated cover${candidates.length > 1 ? "s" : ""}, none accepted`, - href: songHref, + href: songHref("cover"), severity: "info", at: song.newestMtimeMs, }); diff --git a/umtool/lib/pieces.ts b/umtool/lib/pieces.ts @@ -13,6 +13,7 @@ import { lifecycleOf, readLifecycle, type LifecycleRead, type LifecycleState } f import { boardOfArticle, boardOfProject } from "./pieces/board.mjs"; import { readCases } from "./pieces/cases"; import { stageOfPiece } from "./pieces/tabs.mjs"; +import { kindById } from "./projects/kinds.mjs"; import type { Decision } from "./decisions"; export { articlePieceId, casePieceId, formatPieceId, isPieceId, parsePieceId, projectPieceId } from "./pieces/ids.mjs"; @@ -74,8 +75,14 @@ export type Piece = { * facet reads `reached` for it too. */ stage: string; + /** + * The stepper the piece walks (lib/pieces/tabs.mjs pieceSteps' `kind`): `article`, + * `project` (a report video's four stages), or the flow its project's kind + * declares (a song's Spec → Cuts → Done, lib/pieces/song-tabs.mjs). + */ + flow: string; /** What the piece has reached, the one stage rule's facts (lib/pieces/tabs.mjs pieceSteps). */ - reached: { research: boolean; article: boolean; video: boolean; deliver: boolean }; + reached: Reached; projects: PieceProject[]; /** Slug matches nobody has chosen between (link-ambiguous). */ possible: { id: string; title: string }[]; @@ -86,6 +93,17 @@ export type Piece = { newestMs: number; }; +/** The one stage rule's facts: the four stages, and a song's own three (lib/pieces/song-tabs.mjs). */ +export type Reached = { + research: boolean; + article: boolean; + video: boolean; + deliver: boolean; + spec?: boolean; + cuts?: boolean; + done?: boolean; +}; + export type PieceWithLifecycle = Piece & { lifecycle: LifecycleState; lifecycleAt: string | null; lifecycleBy: string | null }; export type PieceGraph = { @@ -292,6 +310,7 @@ async function buildGraph(): Promise<PieceGraph> { pieces.push({ id, kind: "article", + flow: "article", title: a.title, site: a.site, report: a.id, @@ -312,9 +331,14 @@ async function buildGraph(): Promise<PieceGraph> { for (const p of summaries) { if (pieceOfProject.has(p.id)) continue; const why = await looksDoneOf(p.id); + // The stepper the project's kind declares (a song's Spec → Cuts → Done) and + // the facts that light it; else a report video's four stages. + const declared = (kindById(p.kind) as { piece?: { flow: string; reached?: (s: ProjectSummary) => Promise<Partial<Reached>> } } | null)?.piece; + const own = declared?.reached ? await declared.reached(p).catch(() => ({})) : {}; pieces.push({ id: projectPieceId(p.id), kind: "project", + flow: declared?.flow ?? "project", title: p.title, site: null, report: null, @@ -323,7 +347,7 @@ async function buildGraph(): Promise<PieceGraph> { status: null, audience: null, stage: p.state, - reached: { research: !!boardOfProject(p.id, cases), article: false, video: true, deliver: !!why || p.state === "shipped" }, + reached: { research: !!boardOfProject(p.id, cases), article: false, video: true, deliver: !!why || p.state === "shipped", ...own }, projects: [], possible: [], unreachable: [], diff --git a/umtool/lib/pieces/frame.ts b/umtool/lib/pieces/frame.ts @@ -3,7 +3,9 @@ import { summarizeGroups } from "../inbox/groups.mjs"; import { whatOf } from "../inbox/what.mjs"; import { lifecycleOf, readLifecycle, type LifecycleState } from "../lifecycle"; import { projectPieceId, readPieceGraph, type Piece } from "../pieces"; -import { pieceSteps, stageOfPiece } from "./tabs.mjs"; +import { pieceSteps, stepOfPiece } from "./tabs.mjs"; +import { kindPieceFlow } from "../projects/kinds.mjs"; +import type { Reached } from "../pieces"; import { boardOfProject } from "./board.mjs"; import { readCases } from "./cases"; import type { Decision } from "../decisions"; @@ -37,7 +39,7 @@ export type PieceFrame = { steps: { label: string; state: StepState; title?: string }[]; /** The research board (R2 case) this project was scaffolded from, when a case's video hand-off names it. */ board: { id: string; title: string; at: string | null } | null; - /** The bucket the stepper lights (research … deliver). */ + /** The step the stepper has current (research … deliver; a song's spec, cuts or done). */ stage: string; }; @@ -48,7 +50,15 @@ async function boardOf(projectId: string): Promise<PieceFrame["board"]> { return boardOfProject(projectId, await readCases()); } -export async function readPieceFrame(project: { id: string; state?: string | null }): Promise<PieceFrame> { +/** + * @param project the project the page is + * @param opts.reached facts the page read fresh (a song page reads the song + * anyway), over the graph's memoised ones -- a promote shows at once + */ +export async function readPieceFrame( + project: { id: string; kind?: string; state?: string | null }, + opts: { reached?: Partial<Reached> } = {}, +): Promise<PieceFrame> { const [graph, life, board] = await Promise.all([readPieceGraph(), readLifecycle(), boardOf(project.id)]); const pieceId = graph.pieceOfProject.get(project.id) ?? projectPieceId(project.id); const piece = graph.byId.get(pieceId) ?? null; @@ -60,11 +70,14 @@ export async function readPieceFrame(project: { id: string; state?: string | nul : null; // The one stage rule (lib/pieces/tabs.mjs pieceSteps): the graph's facts, so // the stepper here and Work's stage facet read the same answer. - const kind = piece?.kind ?? "project"; + // The stepper is the piece's flow: an article's, a report video's, or the one + // its project's kind declares (a song's), also for a project the graph has + // not listed yet (one scaffolded within the memo's 15 s). + const kind = piece?.flow ?? (project.kind ? kindPieceFlow(project.kind) : null) ?? "project"; // The board is read fresh (the graph is memoised): a board's hand-off shows at once. - const reached = { ...(piece?.reached ?? { video: true }), ...(board ? { research: true } : {}) }; + const reached = { ...(piece?.reached ?? { video: true }), ...opts.reached, ...(board ? { research: true } : {}) }; const steps = pieceSteps({ kind, reached, lifecycle }) as PieceFrame["steps"]; - const stage = stageOfPiece({ kind, reached }); + const stage = stepOfPiece({ kind, reached }); return { piece, pieceId, article, board, lifecycle, lifecycleError: life.error ?? null, steps, stage }; } diff --git a/umtool/lib/pieces/song-tabs.mjs b/umtool/lib/pieces/song-tabs.mjs @@ -0,0 +1,149 @@ +// A SONG PIECE's tabs and stepper (plans/umtool-redesign.md, P4a-3). Pure, no +// imports, beside lib/pieces/tabs.mjs (the report video's and the article's): +// the page, Work's facet and an e2e spec (e2e/urls.ts `songSection`) read the +// same table. +// +// A song walks its own three stages, Spec → Cuts → Done, not the report's four. +// The registry declares which stepper a kind walks (lib/projects/kinds.mjs, the +// song kind's `piece.flow`), so nothing here branches on a kind id: the flow is +// a name the pieces graph copies onto the piece. +// +// The tab is the URL's `?tab=`, as on every piece page. A song's cut page +// (`/projects/<song>/<cut>`, the CutBench, its loudness and provenance) is a +// VIEW of the Cuts tab: the frame draws it with Cuts current. + +/** The stepper a kind declares to walk Spec → Cuts → Done. */ +export const SONG_FLOW = "song"; + +/** + * A song's three stages, each with the Work bucket (lib/work/facets.mjs STAGES) + * it stands in for, so Work's stage facet and the song's stepper agree: the + * spec is a song's written stage (a report video's article), its cuts its + * video, and a full set of cuts its delivery. + */ +export const SONG_STEPS = [ + { id: "spec", label: "Spec", bucket: "article" }, + { id: "cuts", label: "Cuts", bucket: "video" }, + { id: "done", label: "Done", bucket: "deliver" }, +]; + +const SKIPPED = { spec: "no spec.json", cuts: "no cut built" }; + +/** + * The song's stepper, by the one stage rule (lib/pieces/tabs.mjs pieceSteps): + * the furthest stage reached is current, the ones before it done (or to do with + * the reason, when skipped), a piece marked done has done them all. + * + * Spec reached with a spec.json + * Cuts reached with one cut built + * Done reached with every cut built (the song's derived `shipped`, which is + * also its looks-done suggestion, lib/pieces.ts) + * + * @param {{ reached: { spec?: boolean, cuts?: boolean, done?: boolean }, lifecycle: string }} p + * @returns {{ id: string, label: string, state: "done" | "current" | "todo", title?: string }[]} + */ +export function songSteps({ reached, lifecycle }) { + const has = reached ?? {}; + let at = 0; + SONG_STEPS.forEach((s, i) => { + if (has[s.id]) at = i; + }); + return SONG_STEPS.map((s, i) => { + if (lifecycle === "done") return { id: s.id, label: s.label, state: "done" }; + if (i === at) return { id: s.id, label: s.label, state: "current" }; + if (i < at && has[s.id]) return { id: s.id, label: s.label, state: "done" }; + if (i < at) return { id: s.id, label: s.label, state: "todo", title: SKIPPED[s.id] }; + return { id: s.id, label: s.label, state: "todo" }; + }); +} + +/** The song stage that is current (lifecycle aside): `spec`, `cuts` or `done`. */ +export function songStepOf({ reached }) { + return songSteps({ reached, lifecycle: "active" }).find((s) => s.state === "current")?.id ?? "spec"; +} + +/** The Work bucket a song stage stands in for. */ +export function bucketOfSongStep(step) { + return SONG_STEPS.find((s) => s.id === step)?.bucket ?? "video"; +} + +/** The tabs of a song piece, in order; the key that opens each is its position (`1`–`5`). */ +export const SONG_PIECE_TABS = [ + { id: "overview", label: "Overview" }, + { id: "cuts", label: "Cuts" }, + { id: "spec", label: "Spec" }, + { id: "cover", label: "Cover" }, + { id: "notes", label: "Notes" }, +]; + +export const SONG_PIECE_TAB_IDS = SONG_PIECE_TABS.map((t) => t.id); + +/** + * Every section the song page drew (components/projects/SongProject.tsx and + * CutPage.tsx before P4a-3), by the name a spec says, and the tab it is on. + */ +export const SONG_SECTION_TAB = { + // Overview: the Next card, the song's decisions, the cut set at a glance, + // the paste, the README, the song tools. + next: "overview", + decisions: "overview", + slots: "overview", + copy: "overview", + readme: "overview", + tools: "overview", + // Cuts: the four cut cards (poster, verdicts, notes, variants), what matches + // no cut, and a cut's own page (the bench, loudness, provenance). + cuts: "cuts", + variants: "cuts", + verdicts: "cuts", + unattributed: "cuts", + bench: "cuts", + loudness: "cuts", + provenance: "cuts", + // Spec: the spec sheet and its operations, the plans. + spec: "spec", + operations: "spec", + plans: "spec", + // Cover: the cover-art bench (and its way to the face judger). + cover: "cover", + thumbs: "cover", + faces: "cover", + // Notes: the note on the song as a whole, and every other note on it. + notes: "notes", +}; + +/** The tab a song section is on; throws on a name nobody declared (a spec's typo should fail loudly). */ +export function songTabOfSection(name) { + const tab = SONG_SECTION_TAB[name]; + if (!tab) throw new Error(`no section "${name}" on a song piece (lib/pieces/song-tabs.mjs SONG_SECTION_TAB)`); + return tab; +} + +/** + * Where a song note is drawn (lib/notes.ts: a song's notes are keyed by their + * TARGET): the song's own on Notes, a cut's, a file's, a mark's, a source's or + * a clip's with the cuts, a plan's on Spec, a cover's on Cover. + * + * @param {string | undefined | null} target + */ +export function songTabOfNote(target) { + const t = String(target ?? ""); + if (t === "song") return "notes"; + if (/^(cut|file|moment|source|clip):/.test(t)) return "cuts"; + if (t.startsWith("plan:")) return "spec"; + if (t.startsWith("thumb:")) return "cover"; + return "overview"; +} + +/** + * The tab a song piece's address opens: `?tab=`; else a `?note=<target>` where + * that note is drawn; else the Overview. + * + * @param {{ tab?: string, note?: string }} search + */ +export function songTabOf(search) { + const t = search?.tab; + if (t && SONG_PIECE_TAB_IDS.includes(t)) return t; + if (search?.note) return songTabOfNote(search.note); + return "overview"; +} diff --git a/umtool/lib/pieces/song-tabs.test.mjs b/umtool/lib/pieces/song-tabs.test.mjs @@ -0,0 +1,98 @@ +import test from "node:test"; +import assert from "node:assert/strict"; +import { + SONG_FLOW, + SONG_PIECE_TAB_IDS, + SONG_STEPS, + bucketOfSongStep, + songStepOf, + songSteps, + songTabOf, + songTabOfNote, + songTabOfSection, +} from "./song-tabs.mjs"; +import { STAGE_STEPS, pieceSteps, stageOfPiece, stepOfPiece } from "./tabs.mjs"; +import { STAGES, stageBar, stageOf } from "../work/facets.mjs"; + +const states = (steps) => steps.map((s) => s.state); + +test("a song piece: five tabs, Overview first; every section on one of them", () => { + assert.deepEqual(SONG_PIECE_TAB_IDS, ["overview", "cuts", "spec", "cover", "notes"]); + assert.equal(songTabOfSection("cuts"), "cuts"); + assert.equal(songTabOfSection("unattributed"), "cuts"); + assert.equal(songTabOfSection("bench"), "cuts"); + assert.equal(songTabOfSection("operations"), "spec"); + assert.equal(songTabOfSection("plans"), "spec"); + assert.equal(songTabOfSection("faces"), "cover"); + assert.equal(songTabOfSection("notes"), "notes"); + assert.equal(songTabOfSection("slots"), "overview"); + assert.equal(songTabOfSection("tools"), "overview"); + assert.throws(() => songTabOfSection("timeline"), /no section "timeline" on a song piece/); +}); + +test("a song piece's address picks the tab: ?tab=, else a note's target where it is drawn, else the Overview", () => { + assert.equal(songTabOf({}), "overview"); + assert.equal(songTabOf({ tab: "spec" }), "spec"); + assert.equal(songTabOf({ tab: "build" }), "overview"); + assert.equal(songTabOf({ tab: "cover", note: "song" }), "cover"); + assert.equal(songTabOf({ note: "song" }), "notes"); + for (const t of ["cut:vertical", "file:wide.mp4", "file:variants/wide-nokit.mp4", "moment:wide.mp4@2.00", "source:abc123", "clip:abc@1.5"]) { + assert.equal(songTabOfNote(t), "cuts", t); + assert.equal(songTabOf({ note: t }), "cuts", t); + } + assert.equal(songTabOf({ note: "plan:alpha.plan.json" }), "spec"); + assert.equal(songTabOf({ note: "thumb:alpha-1" }), "cover"); + assert.equal(songTabOf({ note: "n-1234" }), "overview"); +}); + +test("a song walks Spec → Cuts → Done by the one stage rule", () => { + assert.deepEqual(SONG_STEPS.map((s) => s.label), ["Spec", "Cuts", "Done"]); + // Scaffolded: a spec.json, no cut yet. + assert.deepEqual(states(songSteps({ reached: { spec: true }, lifecycle: "active" })), ["current", "todo", "todo"]); + // Nothing at all (a directory with only verdicts.json): the Spec is where it starts. + assert.deepEqual(states(songSteps({ reached: {}, lifecycle: "active" })), ["current", "todo", "todo"]); + // Some cuts built. + assert.deepEqual(states(songSteps({ reached: { spec: true, cuts: true }, lifecycle: "active" })), ["done", "current", "todo"]); + // Cuts with no spec.json: the Spec is to do, and says why. + const nospec = songSteps({ reached: { cuts: true }, lifecycle: "active" }); + assert.deepEqual(states(nospec), ["todo", "current", "todo"]); + assert.equal(nospec[0].title, "no spec.json"); + // Every cut built (the derived `shipped`): at Done -- a suggestion, not the lifecycle. + assert.deepEqual(states(songSteps({ reached: { spec: true, cuts: true, done: true }, lifecycle: "active" })), ["done", "done", "current"]); + // Marked done: every stage done. + assert.deepEqual(states(songSteps({ reached: { cuts: true }, lifecycle: "done" })), ["done", "done", "done"]); + // The shared rule switches on the flow the kind declares. + assert.deepEqual(pieceSteps({ kind: SONG_FLOW, reached: { spec: true, cuts: true }, lifecycle: "active" }).map((s) => s.id), ["spec", "cuts", "done"]); + // ...and the four-stage pieces are untouched by it. + assert.deepEqual(pieceSteps({ kind: "project", reached: { video: true }, lifecycle: "active" }).map((s) => s.id), STAGE_STEPS.map((s) => s.id)); +}); + +test("the song's stepper and Work's stage facet give the same answer", () => { + for (const reached of [ + { spec: true }, + { spec: true, cuts: true }, + { cuts: true }, + { spec: true, cuts: true, done: true }, + { research: false, article: false, video: true, deliver: true, spec: true, cuts: true, done: true }, + ]) { + const piece = { kind: SONG_FLOW, reached }; + const current = pieceSteps({ ...piece, lifecycle: "active" }).find((s) => s.state === "current").id; + assert.equal(songStepOf(piece), current); + assert.equal(stepOfPiece(piece), current); + // Work's bucket is the one the song's current step stands in for -- from the piece page's rule. + const bucket = stageOf({ kind: SONG_FLOW, stage: "built", looksDone: [], reached }); + assert.equal(bucket, bucketOfSongStep(current)); + assert.equal(stageOfPiece(piece), bucket); + assert.ok(STAGES.includes(bucket)); + // Work's bar is the song's own: three steps, the current one lit, its word. + const bar = stageBar(piece, bucket); + assert.equal(bar.steps, 3); + assert.equal(SONG_STEPS[bar.step - 1].id, current); + assert.equal(bar.label, SONG_STEPS[bar.step - 1].label.toLowerCase()); + } + assert.equal(stageOf({ kind: SONG_FLOW, stage: "draft", looksDone: [], reached: { spec: true } }), "article"); + assert.equal(stageOf({ kind: SONG_FLOW, stage: "built", looksDone: [], reached: { spec: true, cuts: true } }), "video"); + assert.equal(stageOf({ kind: SONG_FLOW, stage: "shipped", looksDone: ["x: every cut shipped"], reached: { cuts: true, done: true } }), "deliver"); + // A four-stage piece's bar is unchanged: four bars at its bucket, the caller's word. + assert.deepEqual(stageBar({ kind: "project", reached: { video: true } }, "video"), { step: 3, steps: 4, label: null }); +}); diff --git a/umtool/lib/pieces/tabs.mjs b/umtool/lib/pieces/tabs.mjs @@ -14,6 +14,12 @@ // answered that only make sense on one tab: `?all=1` (the cut's "show every // quote") opens the Cut, and `?note=<id>` opens the tab its anchor is drawn on // (a timeline row's note on the Cut, a timed note on the final video on Build). +// +// A SONG walks its own stepper and has its own tabs (lib/pieces/song-tabs.mjs, +// P4a-3); pieceSteps and stageOfPiece switch to it on the flow the registry +// declares, so the one stage rule stays one function. + +import { SONG_FLOW, bucketOfSongStep, songStepOf, songSteps } from "./song-tabs.mjs"; /** The stepper's four stages, by Work's buckets (lib/work/facets.mjs STAGES). */ export const STAGE_STEPS = [ @@ -45,10 +51,14 @@ export const STAGE_STEPS = [ * nor a board (a site's hand-written report) has no Research recorded here. A * piece marked done has done every stage that applies. * - * @param {{ kind: string, reached: { research?: boolean, article?: boolean, video?: boolean, deliver?: boolean }, lifecycle: string }} p + * A song (`kind` the flow its kind declares, SONG_FLOW) walks Spec → Cuts → + * Done by the same rule (lib/pieces/song-tabs.mjs songSteps). + * + * @param {{ kind: string, reached: { research?: boolean, article?: boolean, video?: boolean, deliver?: boolean, spec?: boolean, cuts?: boolean, done?: boolean }, lifecycle: string }} p * @returns {{ id: string, label: string, state: "done" | "current" | "todo" | "na", title?: string }[]} */ export function pieceSteps({ kind, reached, lifecycle }) { + if (kind === SONG_FLOW) return songSteps({ reached, lifecycle }); const project = kind !== "article"; const has = { ...reached, ...(project ? { video: true, article: false } : {}) }; const na = project @@ -74,14 +84,29 @@ export function pieceSteps({ kind, reached, lifecycle }) { /** * A piece's stage: the step that is current, by the one rule (lifecycle aside -- - * a parked or done piece keeps the stage it is at). + * a parked or done piece keeps the stage it is at). Always one of Work's four + * buckets: a song's stage is the bucket its step stands in for (Spec → article, + * Cuts → video, Done → deliver). * - * @param {{ kind: string, reached: { research?: boolean, article?: boolean, video?: boolean, deliver?: boolean } }} p + * @param {{ kind: string, reached: { research?: boolean, article?: boolean, video?: boolean, deliver?: boolean, spec?: boolean, cuts?: boolean, done?: boolean } }} p */ export function stageOfPiece({ kind, reached }) { + if (kind === SONG_FLOW) return bucketOfSongStep(songStepOf({ reached })); return pieceSteps({ kind, reached, lifecycle: "active" }).find((s) => s.state === "current")?.id ?? "video"; } +/** + * The step a piece's stepper has current, by its own ids (lifecycle aside): one + * of the four stages, or a song's `spec` / `cuts` / `done`. The piece page's + * `data-piece-stage`. + * + * @param {{ kind: string, reached: object }} p + */ +export function stepOfPiece({ kind, reached }) { + if (kind === SONG_FLOW) return songStepOf({ reached }); + return stageOfPiece({ kind, reached }); +} + /** The tabs of a report-video piece, in order; the key that opens each is its position. */ export const PIECE_TABS = [ { id: "overview", label: "Overview" }, diff --git a/umtool/lib/projects/kinds.mjs b/umtool/lib/projects/kinds.mjs @@ -16,7 +16,8 @@ // rule, and it is what stops `if (kind === "report-video")` appearing in a page. import { BRAND_CHOICES } from "umtool-report-to-video/brand-ids"; import { MANIFEST_NAME, REPORT_DECISION_KINDS, reportDecisions, reportSignature, summariseReport } from "./report.mjs"; -import { CUT_NAMES, songSignature, summariseSong } from "./song.mjs"; +import { CUT_NAMES, songReached, songSignature, summariseSong } from "./song.mjs"; +import { SONG_FLOW } from "../pieces/song-tabs.mjs"; import { sweepSignature, summariseSweep } from "./sweep.mjs"; /** @@ -143,6 +144,10 @@ export const PROJECT_KINDS = [ // `/browse/<song>/wide` -- today's cut page, unchanged. views: CUT_NAMES, scaffold: { fields: [] }, + // Its piece walks Spec → Cuts → Done, not the report's four stages + // (lib/pieces/song-tabs.mjs, P4a-3): the flow its stepper and Work's stage + // facet read, and the facts that light it, from the project's summary. + piece: { flow: SONG_FLOW, reached: songReached }, }, { id: "sweep-report", @@ -194,6 +199,12 @@ export const kindById = (id) => PROJECT_KINDS.find((k) => k.id === id) ?? null; /** Does a project of this kind keep a notes.json (lib/annotations)? Declared on the kind, never branched on its id. */ export const kindTakesNotes = (id) => kindById(id)?.notes === true; +/** + * The stepper a project piece of this kind walks (lib/pieces/tabs.mjs + * pieceSteps): its declared `piece.flow`, else a report video's. + */ +export const kindPieceFlow = (id) => kindById(id)?.piece?.flow ?? null; + /** Can a project of this kind be an article's video (lib/articles/links.mjs)? Declared on the kind. */ export const kindLinksArticles = (id) => kindById(id)?.linksArticles === true; diff --git a/umtool/lib/projects/song.mjs b/umtool/lib/projects/song.mjs @@ -105,3 +105,15 @@ export async function summariseSong(ctx) { }; } +/** + * What a song piece has reached, for its Spec → Cuts → Done stepper + * (lib/pieces/song-tabs.mjs songSteps): a spec.json (one stat), a cut built, + * every cut built (the derived `shipped`). + * + * @param {{ dir: string, state?: string | null, attrs?: Record<string, string> }} p a song's summary + */ +export async function songReached(p) { + const spec = !!(await stat0(path.join(p.dir, "spec.json"))); + const built = Number(p.attrs?.cuts ?? 0); + return { spec, cuts: built > 0 || p.state === "built" || p.state === "shipped", done: p.state === "shipped" }; +} diff --git a/umtool/lib/work.ts b/umtool/lib/work.ts @@ -2,7 +2,7 @@ import { readInbox, type Inbox } from "./inbox"; import { readLifecycle } from "./lifecycle"; import { KINDS, listProjects } from "./projects"; import { listPieces, type PieceWithLifecycle } from "./pieces"; -import { stageOf, stepOf } from "./work/facets.mjs"; +import { stageBar, stageOf } from "./work/facets.mjs"; // --------------------------------------------------------------------------- // WORK, AS DATA: every piece (lib/pieces.ts) as one row for the Work list -- @@ -32,7 +32,9 @@ export type PieceCounts = { export type WorkRow = PieceWithLifecycle & { /** research | article | video | deliver. */ bucket: string; + /** The current step on the row's stage bar, 1-based, of `steps` (four, or a song's three). */ step: number; + steps: number; /** What the stage bar says: an article's stage, a project's own state. */ stageLabel: string; /** `article` and/or project kind ids. */ @@ -89,12 +91,15 @@ export async function readWork(): Promise<{ rows: WorkRow[]; lifecycleError?: st : "article" : (projectKinds.map((k) => label.get(k) ?? k).join(", ") || "project"); const projectState = own?.state ?? null; - const bucket = stageOf({ kind: p.kind, stage: p.stage, looksDone: p.looksDone, projectState, reached: p.reached }); + // The piece's flow, so a song's bucket is its own stepper's (Spec → Cuts → Done). + const bucket = stageOf({ kind: p.flow, stage: p.stage, looksDone: p.looksDone, projectState, reached: p.reached }); + const bar = stageBar({ kind: p.flow, reached: p.reached }, bucket); return { ...p, bucket, - step: stepOf(bucket), - stageLabel: p.kind === "article" ? bucket : (projectState ?? p.stage), + step: bar.step, + steps: bar.steps, + stageLabel: bar.label ?? (p.kind === "article" ? bucket : (projectState ?? p.stage)), kinds, kindLabel, templates: [...new Set(mine.map((x) => x.template))], diff --git a/umtool/lib/work/facets.mjs b/umtool/lib/work/facets.mjs @@ -16,7 +16,8 @@ // of every project linked to it, a project piece is its project's kind. So the // old `/browse?kind=<a video kind>` still finds the article whose video it is. -import { stageOfPiece } from "../pieces/tabs.mjs"; +import { pieceSteps, stageOfPiece } from "../pieces/tabs.mjs"; +import { SONG_FLOW } from "../pieces/song-tabs.mjs"; /** The four stages a piece walks, in order (canvas "Work", the stage bar). */ export const STAGES = ["research", "article", "video", "deliver"]; @@ -31,7 +32,10 @@ export const LIFECYCLES = ["active", "parked", "done"]; * article's own stage; a project's `deliver` when it looks done (or ships), * else `video`. * - * @param {{ kind: string, stage: string, looksDone: string[], projectState?: string | null, reached?: { research: boolean, article: boolean, video: boolean, deliver: boolean } }} p + * `kind` is the piece's flow (lib/pieces.ts `flow`): `article`, `project`, or + * a song's, whose bucket is the one its current step stands in for. + * + * @param {{ kind: string, stage: string, looksDone: string[], projectState?: string | null, reached?: { research: boolean, article: boolean, video: boolean, deliver: boolean, spec?: boolean, cuts?: boolean, done?: boolean } }} p */ export function stageOf(p) { if (p.reached) return stageOfPiece({ kind: p.kind, reached: p.reached }); @@ -43,6 +47,25 @@ export function stageOf(p) { /** 1-based position on the stage bar. */ export const stepOf = (bucket) => STAGES.indexOf(bucket) + 1; +/** + * A row's stage bar: how many steps it has, which is current, and its word. A + * piece on the four stages is its bucket on four bars; a song (P4a-3) is its + * own stepper, Spec → Cuts → Done, on three -- the same steps its page draws, + * while its bucket (`stageOf`) is the one Work's stage facet files it under. + * + * @param {{ kind: string, reached?: object }} p `kind` the piece's flow + * @param {string} bucket + * @returns {{ step: number, steps: number, label: string | null }} `label` null: the caller's own word + */ +export function stageBar(p, bucket) { + if (p.kind === SONG_FLOW && p.reached) { + const steps = pieceSteps({ kind: p.kind, reached: p.reached, lifecycle: "active" }); + const at = steps.findIndex((s) => s.state === "current"); + return { step: at + 1, steps: steps.length, label: steps[at]?.label.toLowerCase() ?? null }; + } + return { step: stepOf(bucket), steps: STAGES.length, label: null }; +} + /** `life`: one of the three, `all`, or (absent) active. */ export function lifeFilter(life) { if (life === "all") return null;