commit f8dba78c577dc829f48ff0d06e4128c388c5708e
parent f9d4bff7e04eb1c77bdb91cdc4d89356cbfdbb7b
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Wed, 14 Oct 2026 07:17:04 -0400
umtool: the article-rooted piece — an article and its video as one page (P4a-2)
- /articles/<id> and /sites/<site>/<report> are the piece frame with nine
tabs: Overview · Article · Iterations · Cut · Media · Build · Deliver ·
Sources · History. Article and Iterations are the old page's views, moved
in; the video tabs render the claimed project's P4a-1 tabs
(ReportTabBody, shared with ReportProject): current.video's project, else
the article's Cut (lib/pieces/article.ts); one outside REPORTS_ROOT is
"not reachable here". `?project=` picks another project the piece owns.
- A project an article claims redirects (307) from /projects/<path> and
/projects/at to the article piece on the same tab (a note's tab when
?note= names one, ?all=1's Cut); the benches and kind views stay and link
back to the piece (pieceHrefOfProject).
- The stepper by what exists (articleSteps): Research (iterations or a
board), Article (a report), Video (a claimed project), Deliver (looks
done); a board's article hand-off shows the board in the head and on the
Overview (boardOfArticle).
- The generation policy as a chip in the head (PolicyChip, a Meter dot)
linking /settings/generation; PolicyPanel stays on the new-article form.
- The Next card: the piece's top Inbox call, across the article and its
projects; Delete article in ⋯ beside the video's Delete project.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
25 files changed, 1195 insertions(+), 268 deletions(-)
diff --git a/umtool/app/projects/[...path]/page.tsx b/umtool/app/projects/[...path]/page.tsx
@@ -1,9 +1,10 @@
import Link from "next/link";
-import { notFound } from "next/navigation";
+import { notFound, redirect } from "next/navigation";
import BrowseHeader from "@/components/BrowseHeader";
import ProjectView from "@/components/projects/ProjectView";
import ProjectGrid from "@/components/projects/ProjectGrid";
import { listProjects, resolveProjectPath } from "@/lib/projects";
+import { claimedProjectRedirect } from "@/lib/pieces/article";
export const dynamic = "force-dynamic";
@@ -34,6 +35,13 @@ export default async function BrowsePathPage({
if (!resolved) notFound();
if (resolved.project) {
+ // A project an article claims IS that article's piece (P4a-2): its own
+ // address lands there, on the same tab. The benches and kind views
+ // (`clip/<id>`, `claim/<id>`, `review`, `narration`, `takes`) stay here.
+ if (resolved.rest.length === 0) {
+ const to = await claimedProjectRedirect(resolved.project, search);
+ if (to) redirect(to);
+ }
return <ProjectView project={resolved.project} rest={resolved.rest} search={search} />;
}
diff --git a/umtool/app/projects/at/page.tsx b/umtool/app/projects/at/page.tsx
@@ -1,7 +1,8 @@
import Link from "next/link";
-import { notFound } from "next/navigation";
+import { notFound, redirect } from "next/navigation";
import ProjectView from "@/components/projects/ProjectView";
import { projectRefs } from "@/lib/projects";
+import { claimedProjectRedirect } from "@/lib/pieces/article";
export const dynamic = "force-dynamic";
@@ -31,6 +32,9 @@ export default async function AtPage({
const wanted = search.path;
const project = wanted ? (await projectRefs()).find((p) => p.id === wanted) : null;
if (!project) notFound();
+ // A project an article claims is that article's piece (P4a-2), here too.
+ const to = await claimedProjectRedirect(project, search);
+ if (to) redirect(to);
const why =
project.routing === "shadowed"
diff --git a/umtool/components/articles/ArticleOverview.tsx b/umtool/components/articles/ArticleOverview.tsx
@@ -0,0 +1,201 @@
+import Link from "next/link";
+import { Suspense } from "react";
+import NextCard, { NextCardShell } from "@/components/piece/NextCard";
+import { IterationsSummary, ProjectDecisions } from "@/components/projects/report/OverviewTab";
+import { hms, type ClipDetail } from "@/components/projects/report/shared";
+import { readArticleIterations } from "@/lib/articles/generation";
+import { ARTICLES_KEY } from "@/lib/articles/key.mjs";
+import { projectHref } from "@/lib/hrefs";
+import { decisionsForProject } from "@/lib/projects";
+import type { ArticlePieceFrame, ArticleVideo } from "@/lib/pieces/article";
+import type { ProjectRef } from "@/lib/project-types";
+import { researchCaseHref } from "@/lib/research/hrefs";
+
+// An ARTICLE PIECE's Overview (P4a-2; canvas "Piece · Overview"): the Next
+// card -- the top Inbox call across the article and its video project(s) --
+// then the iterations (the article store's) and the video's decisions beside
+// the article's sections, the Cut on show, and the board that seeded it.
+// Each summary links the tab that holds the whole.
+
+type Href = (tab: string, q?: { project?: string }) => string;
+
+export default async function ArticleOverview({
+ site,
+ title,
+ sections,
+ frame,
+ video,
+ videoRef,
+ detail,
+ tabHref,
+}: {
+ site: string;
+ title: string;
+ /** The current report's section titles, or null when there is no report yet. */
+ sections: string[] | null;
+ frame: ArticlePieceFrame;
+ video: ArticleVideo | null;
+ videoRef: ProjectRef | null;
+ detail: ClipDetail | null;
+ tabHref: Href;
+}) {
+ const store = site === ARTICLES_KEY;
+ const [iterations, decisions] = await Promise.all([
+ store ? readArticleIterations(frame.report).catch(() => null) : Promise.resolve(null),
+ videoRef ? decisionsForProject(videoRef).catch(() => []) : Promise.resolve([]),
+ ]);
+ const rows = iterations?.iterations ?? [];
+ const asked = rows.find((r) => r.currentReport && r.question) ?? rows.find((r) => r.question) ?? null;
+ const clips = detail ? detail.entries.filter((e) => e.kind === "clip") : [];
+ const runtime = clips.reduce((n, e) => n + Math.max(0, e.end - e.start), 0);
+ const shown = video?.project ?? null;
+ const madeBy = shown ? video?.iterationOf.get(shown.id) : undefined;
+
+ return (
+ <main className="deck-main flex-1 space-y-4 p-4" data-piece-tab="overview">
+ <Suspense
+ fallback={
+ <NextCardShell pending>
+ <span className="text-[12.5px] text-muted">Reading the Inbox…</span>
+ </NextCardShell>
+ }
+ >
+ <NextCard pieceId={frame.pieceId} title={frame.piece?.title ?? 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">
+ {store && (
+ <section data-piece-iterations={rows.length}>
+ <div className="mb-2 flex items-baseline gap-3">
+ <h2 className="micro">Iterations</h2>
+ <Link href={tabHref("iterations")} prefetch={false} className="ink-link ml-auto text-[12px]">
+ All iterations →
+ </Link>
+ </div>
+ {rows.length > 0 ? (
+ <IterationsSummary rows={rows.slice(0, 5)} />
+ ) : (
+ <p className="text-[12.5px] text-muted">No iterations.</p>
+ )}
+ {asked && (
+ <p data-piece-question="" className="mt-2.5 text-[12.5px] text-muted">
+ Question: {asked.question}
+ {asked.scope?.channels?.length ? ` · scope ${asked.scope.channels.join(", ")}` : ""}
+ </p>
+ )}
+ </section>
+ )}
+ {videoRef && <ProjectDecisions project={videoRef.id} decisions={decisions} />}
+ </div>
+
+ <div className="min-w-0 space-y-4">
+ <section data-piece-sections={sections?.length ?? 0}>
+ <div className="mb-1.5 flex items-baseline gap-3">
+ <h2 className="micro">{sections ? `Article · ${sections.length} section${sections.length === 1 ? "" : "s"}` : "Article"}</h2>
+ <Link href={tabHref("article")} prefetch={false} className="ink-link ml-auto text-[12px]">
+ Read →
+ </Link>
+ </div>
+ {sections ? (
+ <ul className="text-[13px] text-text-2">
+ {sections.map((s, i) => (
+ <li key={`${s}-${i}`} className="border-b border-seam py-1.5">
+ {s}
+ </li>
+ ))}
+ </ul>
+ ) : (
+ <p className="text-[12.5px] text-muted">No report yet.</p>
+ )}
+ </section>
+
+ <section data-piece-cut={shown?.id ?? ""}>
+ <div className="mb-1.5 flex items-baseline gap-3">
+ <h2 className="micro">{shown ? `Cut · ${madeBy ? `i${madeBy}` : shown.id}` : "Cut"}</h2>
+ {shown && (
+ <Link href={tabHref("cut")} prefetch={false} className="ink-link ml-auto text-[12px]">
+ Open the cut →
+ </Link>
+ )}
+ </div>
+ {shown && detail && (
+ <ul className="text-[13px] text-text-2">
+ <li className="flex gap-2.5 border-b border-seam py-1.5">
+ {detail.build.built ? "final video built" : "final video not built"}
+ <span className="ml-auto font-mono text-[11.5px] text-text-2">
+ {detail.build.built ? `${detail.build.slug}.mp4${detail.build.stale ? " · out of date" : ""}` : ""}
+ </span>
+ </li>
+ <li className="flex gap-2.5 border-b border-seam py-1.5">
+ cut
+ <span className="ml-auto font-mono text-[11.5px] text-meter">
+ {clips.length} clips · {hms(runtime)}
+ </span>
+ </li>
+ <li className="flex gap-2.5 border-b border-seam py-1.5">
+ project
+ <span className="ml-auto font-mono text-[11.5px] text-text-2">{shown.id}</span>
+ </li>
+ </ul>
+ )}
+ {shown && !detail && (
+ <p className="text-[12.5px] text-reject-text">
+ <code className="font-mono">video.manifest.json</code> could not be parsed.
+ </p>
+ )}
+ {!shown && video?.unreachable && (
+ <p data-piece-unreachable={video.unreachable.n} className="text-[12.5px] text-muted">
+ i{video.unreachable.n}'s project is not reachable here:{" "}
+ <code className="font-mono text-[11.5px]">{video.unreachable.dir}</code>
+ </p>
+ )}
+ {!shown && !video?.unreachable && <p className="text-[12.5px] text-muted">No video project yet.</p>}
+ {video && video.owned.length > 1 && (
+ <ul className="mt-1.5 text-[12.5px]" data-piece-videos={video.owned.length}>
+ {video.owned
+ .filter((p) => p.id !== shown?.id)
+ .map((p) => (
+ <li key={p.id} className="py-0.5">
+ <Link href={tabHref("cut", { project: p.id })} prefetch={false} className="ink-link font-mono text-[12px]">
+ {video.iterationOf.has(p.id) ? `i${video.iterationOf.get(p.id)}` : p.id}
+ </Link>
+ <span className="ml-2 text-muted">another cut · {p.id}</span>
+ </li>
+ ))}
+ </ul>
+ )}
+ </section>
+
+ {frame.board && (
+ <section data-piece-board={frame.board.id}>
+ <h2 className="micro mb-1.5">Research board</h2>
+ <Link href={researchCaseHref(frame.board.id)} prefetch={false} className="ink-link text-[13px]">
+ {frame.board.title}
+ </Link>
+ <p className="text-[12px] text-muted">
+ its quotes seeded this article{frame.board.at ? ` · ${frame.board.at.slice(0, 10)}` : ""}
+ </p>
+ </section>
+ )}
+
+ {(frame.piece?.possible.length ?? 0) > 0 && (
+ <section data-piece-possible={frame.piece!.possible.length}>
+ <h2 className="micro mb-1.5">Possible videos</h2>
+ <ul className="text-[12.5px]">
+ {frame.piece!.possible.map((p) => (
+ <li key={p.id} className="py-0.5">
+ <Link href={projectHref(p.id)} prefetch={false} className="ink-link font-mono text-[12px]" title="shares the slug; not linked">
+ {p.id}
+ </Link>
+ <span className="ml-2 text-muted">shares the slug; not linked</span>
+ </li>
+ ))}
+ </ul>
+ </section>
+ )}
+ </div>
+ </div>
+ </main>
+ );
+}
diff --git a/umtool/components/articles/ArticlePage.tsx b/umtool/components/articles/ArticlePage.tsx
@@ -1,42 +1,86 @@
-import { stat } from "node:fs/promises";
+import { readdir } from "node:fs/promises";
import path from "node:path";
import Link from "next/link";
import { notFound } from "next/navigation";
+import { Suspense } from "react";
import { readRevisionHead, REPORT_HISTORY_GIT_DIRNAME } from "yt-dlp-transcript-common/publish/reportHistory";
import { hasSlides, slideLint } from "yt-dlp-transcript-common/lib/report/slides";
-import BrowseHeader, { type Crumb } from "@/components/BrowseHeader";
+import type { Crumb } from "@/components/shell/AppHeader";
import DeleteArticle from "@/components/articles/DeleteArticle";
+import ArticleOverview from "@/components/articles/ArticleOverview";
import ArticleReader from "@/components/articles/ArticleReader";
import WorkspacePanel from "@/components/articles/WorkspacePanel";
import IterationsView from "@/components/articles/IterationsView";
+import PieceFrame from "@/components/piece/PieceFrame";
+import PolicyChip, { PolicyChipShell } from "@/components/piece/PolicyChip";
+import DeleteProject from "@/components/projects/DeleteProject";
+import ReportTabBody, { reportCounts } from "@/components/projects/report/ReportTabBody";
import { badgeVariants } from "@/components/ui/badge";
+import { EmptyState } from "@/components/ui/empty-state";
import { Tabs } from "@/components/ui/tabs";
import { articleView } from "@/lib/articles/article";
-import { articleHref } from "@/lib/articles/href";
import { articleWorkspaceListing, openWorkspaceFile } from "@/lib/articles/files";
import { linkedProjects } from "@/lib/articles/links.mjs";
import { readArticleNotes, readReportFile, reportDirFor } from "@/lib/articles/sites";
import { sourceFor } from "@/lib/articles/sources.mjs";
+import { articleEvidenceHref, articleHref, projectHref } from "@/lib/hrefs";
import { ARTICLES_KEY, corpusNotesFile } from "@/lib/paths";
+import { readPieceGraph } from "@/lib/pieces";
+import { articleVideo, projectNoteTab, readArticlePieceFrame, type ArticleVideo } from "@/lib/pieces/article";
+import { ARTICLE_PIECE_TABS, VIDEO_TAB_IDS, articleTabOf } from "@/lib/pieces/tabs.mjs";
+import { projectRef } from "@/lib/projects";
+import { readClipDetail } from "@/lib/projects/report.mjs";
import type { NotesRead } from "@/lib/annotations/types";
-// ONE ARTICLE's page, wherever it lives: a site's report
+// ONE ARTICLE PIECE, wherever the article lives: a site's report
// (/sites/<site>/<report>) or one of the article store's (/articles/<id>,
-// release 26) -- `site` is the site's id or ARTICLES_KEY. The reader with its
-// notes (default), or `?tab=source` -- the workspace files it was written
-// from, its draft marked, and what would make its slides read badly
-// (lib/report/slides.ts slideLint, and the validator's slide problems).
+// release 26) -- `site` is the site's id or ARTICLES_KEY. Since P4a-2
+// (plans/umtool-redesign.md) the article and the video project it claims are
+// ONE page: the piece frame (components/piece/PieceFrame.tsx) around one of
+// nine tabs.
//
+// Overview the Next card, the iterations, the article's sections, the Cut
+// Article the reader with its notes; `?tab=source` its workspace
+// files, its draft marked, and what would make its slides
+// read badly (the old page's three views, unchanged)
+// Iterations the article store's iterations (IterationsView, release 27/28)
+// Cut … History the claimed video project's P4a-1 tabs (ReportTabBody):
+// current.video's project, else the article's Cut
+// (lib/pieces/article.ts); one outside REPORTS_ROOT is "not
+// reachable here"
+//
+// ?tab=<id> the tab (absent: the Overview)
// ?rv=slides|iso the article as slides, or the overview (the
// reader's own switch; the place is the hash)
// ?status=open|resolved|all the notes filter it opens with
-// ?note=<id> the note it opens on (the decisions inbox links here)
-// ?ws=&rel= a workspace file open on the source tab
-// ?tab=iterations the article store's only (release 27 S8): its
-// iterations (IterationsView). An article in the
-// making — iterations, no report.json — opens here.
+// ?note=<id> the note it opens on: an article note on the
+// Article tab, a video note where its anchor is
+// ?ws=&rel= a workspace file open on the source view
+// ?project=<id> another video project the article owns
+// ?all=1 the cut's every quote
+
+export type ArticleSearch = {
+ tab?: string;
+ status?: string;
+ note?: string;
+ ws?: string;
+ rel?: string;
+ rv?: string;
+ all?: string;
+ project?: string;
+};
+
+type TabHref = (t: string, q?: { all?: boolean; project?: string }) => string;
-export type ArticleSearch = { tab?: string; status?: string; note?: string; ws?: string; rel?: string };
+const NUMERIC = /^[1-9][0-9]*$/;
+
+/** How many iterations the store holds for an article (a readdir; the tab reads them whole). */
+async function iterationCount(site: string, report: string): Promise<number> {
+ if (site !== ARTICLES_KEY) return 0;
+ const dir = path.join(/* turbopackIgnore: true */ reportDirFor(site, report), "iterations");
+ const names = await readdir(/* turbopackIgnore: true */ dir).catch(() => [] as string[]);
+ return names.filter((n) => NUMERIC.test(n)).length;
+}
export default async function ArticlePage({
site,
@@ -50,66 +94,236 @@ export default async function ArticlePage({
site: string;
reportId: string;
sp: ArticleSearch;
- // The meta line's first link: the site, or the article list.
+ // The head's meta line's first link: the site, or the article list.
home: { href: string; label: string };
- // The header's crumbs before the article's own.
+ // The trail before the article's own crumbs.
crumbs: Crumb[];
published: boolean;
}) {
const read = await readReportFile(site, reportId);
const store = site === ARTICLES_KEY;
- const hasIterations =
- store && (await stat(/* turbopackIgnore: true */ path.join(reportDirFor(site, reportId), "iterations")).then((s) => s.isDirectory(), () => false));
+ const iterations = await iterationCount(site, reportId);
+ const hasIterations = iterations > 0;
const missing = !read.report && read.problems[0]?.message === "no report.json";
if (missing && !hasIterations) notFound();
+ const r = read.report;
+ const a = { site, id: reportId };
- const [notes, source] = await Promise.all([readArticleNotes(site, reportId), sourceFor(site, reportId)]);
- const links = await linkedProjects(site, reportId, { workspace: source?.workspace ?? null });
+ const [notes, source, frame, graph] = await Promise.all([
+ readArticleNotes(site, reportId),
+ sourceFor(site, reportId),
+ readArticlePieceFrame(site, reportId, { hasIterations, hasReport: !!r }),
+ readPieceGraph(),
+ ]);
+ const video = frame.piece ? await articleVideo(frame.piece, graph, sp.project ?? null) : null;
+ const videoRef = video?.project ? await projectRef(video.project.id) : null;
+ const detail = videoRef ? await readClipDetail(videoRef.dir) : null;
+
+ // 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 tab = articleTabOf(sp, { noteTab });
+
+ // `?project=` is carried from tab to tab only when it is not the article's Cut.
+ const project = video?.project && video.project.id !== video.cut ? video.project.id : undefined;
+ const tabHref: TabHref = (t, q = {}) =>
+ articleHref(a, { tab: t, all: q.all, project: q.project === undefined ? project : q.project || undefined });
+ const title = r?.title || frame.piece?.title || reportId;
+ const counts = { ...(detail ? reportCounts(detail) : {}), ...(iterations ? { iterations } : {}) };
+ const openNotes = notes.doc?.notes.filter((n) => n.status === "open").length ?? 0;
const gitDir = path.join(/* turbopackIgnore: true */ reportDirFor(site, reportId), REPORT_HISTORY_GIT_DIRNAME);
const head = await readRevisionHead(gitDir).catch(() => null);
- const r = read.report;
- const tab = missing || (store && sp.tab === "iterations") ? "iterations" : sp.tab === "source" ? "source" : "article";
- const base = articleHref({ site, id: reportId });
- const media = (file: string) =>
- `/api/sites/media?site=${encodeURIComponent(site)}&report=${encodeURIComponent(reportId)}&file=${encodeURIComponent(file)}`;
const meta = (
<div data-article-meta className="flex flex-wrap items-center gap-x-3 gap-y-1 text-[12px] text-[var(--color-dim)]">
<Link href={home.href} className="hover:text-[var(--color-text)]">
{home.label}
</Link>
- <span data-status={missing ? "pending" : published ? "published" : "draft"} className={badgeVariants({ variant: published ? "on" : missing ? "open" : "neutral", size: "sm" })}>
+ <span
+ data-status={missing ? "pending" : published ? "published" : "draft"}
+ className={badgeVariants({ variant: published ? "on" : missing ? "open" : "neutral", size: "sm" })}
+ >
{missing ? "in the making" : published ? "published" : "draft"}
</span>
{r?.published && <span>published {r.published}</span>}
{r?.updated && <span>updated {r.updated}</span>}
{head && <span data-revisions={head.revision}>{head.revision} revision{head.revision === 1 ? "" : "s"}</span>}
+ </div>
+ );
+
+ return (
+ <div className="flex h-full flex-col">
+ <PieceFrame
+ crumbs={[...crumbs, ...(title !== reportId ? [{ label: reportId }] : []), { label: title }]}
+ frame={frame}
+ tab={tab}
+ tabs={ARTICLE_PIECE_TABS.map((t) => ({ ...t, href: tabHref(t.id) }))}
+ counts={counts}
+ meta={meta}
+ note={`${openNotes} open notes`}
+ head={
+ <Suspense
+ fallback={
+ <PolicyChipShell>
+ <span className="text-muted-2">…</span>
+ </PolicyChipShell>
+ }
+ >
+ <PolicyChip />
+ </Suspense>
+ }
+ more={
+ <>
+ <span className="px-2 pb-1 pt-0.5 font-mono text-[11px] text-muted">{frame.pieceId}</span>
+ {store && <DeleteArticle article={reportId} published={published} />}
+ {videoRef && (
+ <>
+ <span className="px-2 pb-1 pt-1.5 font-mono text-[11px] text-muted" data-piece-more-project={videoRef.id}>
+ {videoRef.id}
+ </span>
+ <DeleteProject project={videoRef.id} />
+ </>
+ )}
+ </>
+ }
+ >
+ {tab === "overview" && (
+ <ArticleOverview
+ site={site}
+ title={title}
+ sections={r ? (r.sections ?? []).map((s: { title?: string }, i: number) => s.title || `Section ${i + 1}`) : null}
+ frame={frame}
+ video={video}
+ videoRef={videoRef}
+ detail={detail}
+ tabHref={tabHref}
+ />
+ )}
+ {tab === "article" && (
+ <ArticleTab
+ site={site}
+ reportId={reportId}
+ sp={sp}
+ read={read}
+ missing={missing}
+ notes={notes}
+ source={source}
+ tabHref={tabHref}
+ cut={video?.cut ?? null}
+ />
+ )}
+ {tab === "iterations" && (
+ <main className="deck-main flex-1 p-4" data-piece-tab="iterations">
+ <div className="mx-auto max-w-5xl space-y-4">
+ {store ? (
+ <IterationsView article={reportId} />
+ ) : (
+ <EmptyState title="A site's report has no iterations here">Iterations are the article store's.</EmptyState>
+ )}
+ </div>
+ </main>
+ )}
+ {VIDEO_TAB_IDS.includes(tab) &&
+ (videoRef && detail ? (
+ <ReportTabBody project={videoRef} detail={detail} search={sp} tab={tab} frame={frame} tabHref={tabHref} />
+ ) : (
+ <main className="deck-main flex-1 p-4" data-piece-tab={tab}>
+ <NoVideo video={video} unparsed={videoRef && !detail ? videoRef.id : null} iterationsHref={store ? tabHref("iterations") : null} />
+ </main>
+ ))}
+ </PieceFrame>
+ </div>
+ );
+}
+
+/** The video tabs of an article with no video on show: none yet, not reachable here, or a manifest that does not parse. */
+function NoVideo({ video, unparsed, iterationsHref }: { video: ArticleVideo | null; unparsed: string | null; iterationsHref: string | null }) {
+ if (unparsed) {
+ return (
+ <p data-video-unparsed={unparsed} className="text-[12px] text-[var(--color-bad)]">
+ <code className="font-mono">{unparsed}/video.manifest.json</code> could not be parsed.
+ </p>
+ );
+ }
+ if (video?.unreachable) {
+ return (
+ <EmptyState data-video-unreachable={video.unreachable.n} title={`i${video.unreachable.n}'s video project is not reachable here`}>
+ <code className="font-mono text-[11.5px]">{video.unreachable.dir}</code> is outside this umtool's reports root.
+ </EmptyState>
+ );
+ }
+ return (
+ <EmptyState
+ data-video-none=""
+ title="No video project yet"
+ action={
+ iterationsHref ? (
+ <Link href={iterationsHref} prefetch={false} className="ink-link">
+ Make the video from an iteration
+ </Link>
+ ) : undefined
+ }
+ />
+ );
+}
+
+/**
+ * The Article tab: the old article page's views, moved in unchanged -- the
+ * reader with its notes, the workspace source (`?tab=source`), and the
+ * report's problems when it does not read. Its first line is the views'
+ * switch (article · source · evidence) and the projects linked to it.
+ */
+async function ArticleTab({
+ site,
+ reportId,
+ sp,
+ read,
+ missing,
+ notes,
+ source,
+ tabHref,
+ cut,
+}: {
+ site: string;
+ reportId: string;
+ sp: ArticleSearch;
+ read: Awaited<ReturnType<typeof readReportFile>>;
+ missing: boolean;
+ notes: Awaited<ReturnType<typeof readArticleNotes>>;
+ source: Awaited<ReturnType<typeof sourceFor>>;
+ tabHref: TabHref;
+ cut: string | null;
+}) {
+ const a = { site, id: reportId };
+ const r = read.report;
+ const view = sp.tab === "source" ? "source" : "article";
+ const links = await linkedProjects(site, reportId, { workspace: source?.workspace ?? null });
+ const media = (file: string) =>
+ `/api/sites/media?site=${encodeURIComponent(site)}&report=${encodeURIComponent(reportId)}&file=${encodeURIComponent(file)}`;
+
+ const line = (
+ <div data-article-line className="flex flex-wrap items-center gap-x-3 gap-y-1 text-[12px] text-[var(--color-dim)]">
+ {/* The article's views as link tabs: each an address, the current one lit. */}
+ <Tabs
+ label="article views"
+ className="w-full"
+ items={[
+ { href: articleHref(a, { tab: "article" }), label: "article", current: view === "article" },
+ { href: articleHref(a, { tab: "source" }), label: "source", current: view === "source" },
+ { href: articleEvidenceHref(a), label: "evidence" },
+ ]}
+ />
{links.linked.map((p: { id: string }) => (
- <Link key={p.id} href={`/projects/${p.id}`} data-project-link={p.id} className="font-mono ink-link">
+ <Link key={p.id} href={tabHref("cut", { project: p.id === cut ? "" : p.id })} data-project-link={p.id} className="font-mono ink-link">
{p.id}
</Link>
))}
{links.possible.map((p: { id: string }) => (
- <Link key={p.id} href={`/projects/${p.id}`} className="font-mono hover:underline" title="shares the slug; not linked">
+ <Link key={p.id} href={projectHref(p.id)} className="font-mono hover:underline" title="shares the slug; not linked">
{p.id} (possible)
</Link>
))}
- {/* The article's views as link tabs: each an address, the current one lit. */}
- <Tabs
- label="article views"
- className="order-last w-full"
- items={[
- { href: base, label: "article", current: tab === "article" },
- { href: `${base}?tab=source`, label: "source", current: tab === "source" },
- { href: `${base}/evidence`, label: "evidence" },
- ...(store ? [{ href: `${base}?tab=iterations`, label: "iterations", current: tab === "iterations" }] : []),
- ]}
- />
- {store && (
- <span className="ml-auto">
- <DeleteArticle article={reportId} published={published} />
- </span>
- )}
{source && (
<div className="w-full font-mono text-[11px]" title={source.how}>
{source.draft && <span>draft {source.draft}</span>}
@@ -119,48 +333,37 @@ export default async function ArticlePage({
</div>
);
- const header = (
- <BrowseHeader
- active="articles"
- crumbs={[...crumbs, { label: reportId }]}
- note={`${notes.doc?.notes.filter((n) => n.status === "open").length ?? 0} open notes`}
- />
- );
-
- if (tab === "iterations") {
- return (
- <div className="flex h-full flex-col">
- {header}
- <main className="deck-main flex-1 p-4">
- <div className="mx-auto max-w-5xl space-y-4">
- {meta}
- <IterationsView article={reportId} />
- </div>
- </main>
- </div>
- );
- }
-
if (!r) {
return (
- <div className="flex h-full flex-col">
- {header}
- <main className="deck-main flex-1 p-4">
- <div className="mx-auto max-w-[72ch] space-y-3">
- {meta}
- <p className="text-[13px] text-[var(--color-bad)]">report.json does not read as a report:</p>
- <ul className="list-disc pl-5 text-[12px] text-[var(--color-dim)]">
- {read.problems.slice(0, 20).map((p, i) => (
- <li key={i}>{p.message}</li>
- ))}
- </ul>
- </div>
- </main>
- </div>
+ <main className="deck-main flex-1 p-4" data-piece-tab="article">
+ <div className="mx-auto max-w-[72ch] space-y-3">
+ {line}
+ {missing ? (
+ <EmptyState
+ data-report-missing=""
+ title="No report yet"
+ action={
+ <Link href={tabHref("iterations")} prefetch={false} className="ink-link">
+ Its iterations
+ </Link>
+ }
+ />
+ ) : (
+ <>
+ <p className="text-[13px] text-[var(--color-bad)]">report.json does not read as a report:</p>
+ <ul className="list-disc pl-5 text-[12px] text-[var(--color-dim)]">
+ {read.problems.slice(0, 20).map((p, i) => (
+ <li key={i}>{p.message}</li>
+ ))}
+ </ul>
+ </>
+ )}
+ </div>
+ </main>
);
}
- if (tab === "source") {
+ if (view === "source") {
const ws = await articleWorkspaceListing(source?.workspace);
const opened =
sp.ws && sp.rel
@@ -172,49 +375,47 @@ export default async function ArticlePage({
const { view: slideView } = await articleView(r);
const lint = hasSlides(slideView) ? slideLint(slideView) : [];
const slideProblems = read.problems.filter((p) => /(^|\.)slides?(\.|\[|$)/.test(p.path ?? ""));
+ const base = articleHref(a);
return (
- <div className="flex h-full flex-col">
- {header}
- <main className="deck-main flex-1 p-4">
- <div className="space-y-4">
- {meta}
- {hasSlides(slideView) && (
- <section data-slide-lint={lint.length + slideProblems.length} className="rounded-[3px] border border-seam bg-panel px-4 py-3 text-[12px]">
- <div className="micro">slides</div>
- {lint.length + slideProblems.length === 0 ? (
- <p className="mt-1 text-[var(--color-dim)]">nothing to fix</p>
- ) : (
- <ul className="mt-1 space-y-1">
- {slideProblems.map((p, i) => (
- <li key={`p${i}`} data-lint="problem" className="text-[var(--color-bad)]">
- <code className="font-mono text-[11px]">{p.path}</code> {p.message}
- </li>
- ))}
- {lint.map((l, i) => (
- <li key={`l${i}`} data-lint={l.key}>
- <Link href={`${base}?rv=slides#${l.anchorId}`} className="font-mono text-[11px] ink-link">
- {l.key}
- </Link>{" "}
- <span className="text-[var(--color-text)]">{l.message}</span>
- </li>
- ))}
- </ul>
- )}
- </section>
- )}
- <WorkspacePanel
- workspaces={ws ? [ws] : []}
- opened={opened}
- highlight={draftRel}
- hrefFor={(w, rel) => `${base}?${new URLSearchParams({ tab: "source", ws: w, rel })}`}
- />
- </div>
- </main>
- </div>
+ <main className="deck-main flex-1 p-4" data-piece-tab="article">
+ <div className="space-y-4">
+ {line}
+ {hasSlides(slideView) && (
+ <section data-slide-lint={lint.length + slideProblems.length} className="rounded-[3px] border border-seam bg-panel px-4 py-3 text-[12px]">
+ <div className="micro">slides</div>
+ {lint.length + slideProblems.length === 0 ? (
+ <p className="mt-1 text-[var(--color-dim)]">nothing to fix</p>
+ ) : (
+ <ul className="mt-1 space-y-1">
+ {slideProblems.map((p, i) => (
+ <li key={`p${i}`} data-lint="problem" className="text-[var(--color-bad)]">
+ <code className="font-mono text-[11px]">{p.path}</code> {p.message}
+ </li>
+ ))}
+ {lint.map((l, i) => (
+ <li key={`l${i}`} data-lint={l.key}>
+ <Link href={`${base}?rv=slides#${l.anchorId}`} className="font-mono text-[11px] ink-link">
+ {l.key}
+ </Link>{" "}
+ <span className="text-[var(--color-text)]">{l.message}</span>
+ </li>
+ ))}
+ </ul>
+ )}
+ </section>
+ )}
+ <WorkspacePanel
+ workspaces={ws ? [ws] : []}
+ opened={opened}
+ highlight={draftRel}
+ hrefFor={(w, rel) => articleHref(a, { tab: "source", ws: w, rel })}
+ />
+ </div>
+ </main>
);
}
- const { view, error } = await articleView(r);
+ const { view: readerView, error } = await articleView(r);
const initialNotes: NotesRead = {
subject: { kind: "article", site: site, report: reportId },
file: corpusNotesFile(site, reportId) ?? "",
@@ -224,25 +425,22 @@ export default async function ArticlePage({
...(notes.error ? { error: notes.error } : {}),
};
const status = sp.status === "resolved" || sp.status === "all" ? sp.status : "open";
- const video = r.video
+ const videoSlot = r.video
? { file: r.video.src, src: media(r.video.src), poster: r.video.poster ? media(r.video.poster) : undefined, caption: r.video.caption }
: null;
return (
- <div className="flex h-full flex-col">
- {header}
- <ArticleReader
- site={site}
- report={reportId}
- view={view}
- viewError={error}
- initialNotes={initialNotes}
- initialFilter={status}
- initialNote={sp.note ?? null}
- meta={meta}
- video={video}
- videoProjects={links.linked.map((p: { id: string; title: string; generatedBy: string | null }) => ({ id: p.id, title: p.title, generatedBy: p.generatedBy }))}
- />
- </div>
+ <ArticleReader
+ site={site}
+ report={reportId}
+ view={readerView}
+ viewError={error}
+ initialNotes={initialNotes}
+ initialFilter={status}
+ initialNote={sp.note ?? null}
+ meta={line}
+ video={videoSlot}
+ videoProjects={links.linked.map((p: { id: string; title: string; generatedBy: string | null }) => ({ id: p.id, title: p.title, generatedBy: p.generatedBy }))}
+ />
);
}
diff --git a/umtool/components/piece/PieceFrame.tsx b/umtool/components/piece/PieceFrame.tsx
@@ -4,8 +4,8 @@ import AppShell from "@/components/shell/AppShell";
import { buttonVariants } from "@/components/ui/button";
import { Stepper } from "@/components/ui/stepper";
import { Tabs, type TabItem } from "@/components/ui/tabs";
-import { articleHref, projectHref, projectsHref } from "@/lib/hrefs";
-import { PIECE_TABS } from "@/lib/pieces/tabs.mjs";
+import type { Crumb } from "@/components/shell/AppHeader";
+import { articleHref } from "@/lib/hrefs";
import { researchCaseHref } from "@/lib/research/hrefs";
import type { PieceFrame as Frame } from "@/lib/pieces/frame";
import LifecycleChip from "./LifecycleChip";
@@ -19,25 +19,36 @@ import PieceKeys from "./PieceKeys";
// links (`?tab=`, lib/pieces/tabs.mjs), then the tab's own body.
//
// Kind-blind: the report-video page (components/projects/ReportProject.tsx)
-// hands it the title, the counts and the body. `1`–`7` open the tabs and `n`
-// runs the Next card's action (PieceKeys).
+// and the article piece (components/articles/ArticlePage.tsx, P4a-2) hand it
+// the trail, the tabs and their addresses, the counts and the body. `1`–`9`
+// open the tabs, in order, and `n` runs the Next card's action (PieceKeys).
// ---------------------------------------------------------------------------
+export type FrameTab = { id: string; label: string; href: string };
+
export default function PieceFrame({
- project,
- title,
+ crumbs,
frame,
tab,
+ tabs,
counts,
note,
+ meta,
+ head,
more,
children,
}: {
- project: string;
- title: string;
+ /** The trail, its last crumb the piece's title (the head's `<h1>`). */
+ crumbs: Crumb[];
frame: Frame;
/** The tab on show. */
tab: string;
+ /** Every tab, in order, with its address. */
+ tabs: FrameTab[];
+ /** A line beside the title (an article's status, dates, revisions). */
+ meta?: React.ReactNode;
+ /** More of the head's foot row, after the stepper (the policy chip). */
+ head?: React.ReactNode;
/** A count beside a tab's name, in Meter (Cut: clips, Media: drafted fields, Sources: recordings). */
counts: Partial<Record<string, number>>;
/** The page's one-line status, the head's last `.micro`. */
@@ -46,9 +57,9 @@ export default function PieceFrame({
more?: React.ReactNode;
children: React.ReactNode;
}) {
- const hrefs = PIECE_TABS.map((t) => projectHref(project, { tab: t.id }));
- const items: TabItem[] = PIECE_TABS.map((t, i) => ({
- href: hrefs[i],
+ const hrefs = tabs.map((t) => t.href);
+ const items: TabItem[] = tabs.map((t) => ({
+ href: t.href,
label: t.label,
current: t.id === tab,
count: counts[t.id] ? counts[t.id] : undefined,
@@ -59,8 +70,9 @@ export default function PieceFrame({
<>
<AppShell
active="work"
- crumbs={[{ href: projectsHref(), label: "projects" }, { label: project }, { label: title }]}
+ crumbs={crumbs}
note={note}
+ meta={meta}
actions={
<>
{piece && <LifecycleChip piece={frame.pieceId} title={piece.title} state={frame.lifecycle} />}
@@ -95,6 +107,7 @@ export default function PieceFrame({
</Link>
</span>
)}
+ {head}
</div>
}
/>
diff --git a/umtool/components/piece/PieceKeys.tsx b/umtool/components/piece/PieceKeys.tsx
@@ -3,7 +3,7 @@
import { useRouter } from "next/navigation";
import { useEffect, useState } from "react";
-// A piece page's keys: `1`–`7` open the tabs, in order; `n` runs the Next
+// A piece page's keys: `1`–`9` open the tabs, in order (seven on a project piece, nine on an article piece); `n` runs the Next
// card's action (the one control under `[data-next-action]`). Bound only after
// hydration -- the house rule's "disabled until hydrated", for a key -- and
// `data-piece-keys="ready"` says so to a spec.
diff --git a/umtool/components/piece/PolicyChip.tsx b/umtool/components/piece/PolicyChip.tsx
@@ -0,0 +1,58 @@
+import Link from "next/link";
+import { badgeVariants } from "@/components/ui/badge";
+import { readPolicy, readToday } from "@/lib/articles/generation";
+import { generationSettingsHref } from "@/lib/hrefs";
+import { cn } from "@/lib/utils";
+
+// THE GENERATION POLICY, as a chip (P4a-2; canvas "Create": "Policy shown as a
+// chip"): the policy's one line -- its preset, the API model, the day's spend
+// against the daily cap -- with a Meter dot, linking to where it is set
+// (/settings/generation, P5's page). The panel itself (PolicyPanel) is not on
+// the article piece; it stays on the new-article form until P5 moves it.
+//
+// Async: the policy is the editor's (askEditor), so the frame streams this in
+// under a <Suspense>; an editor that does not answer is said, not hidden.
+
+const usd = (v: number) => `$${v.toFixed(2)}`;
+const shortModel = (m: string) => m.replace(/^claude-/, "");
+
+export function PolicyChipShell({ children, preset }: { children: React.ReactNode; preset?: string }) {
+ return (
+ <Link
+ href={generationSettingsHref()}
+ prefetch={false}
+ data-policy-chip={preset ?? ""}
+ title="Generation policy: routes, models, caps"
+ className={cn(badgeVariants({ variant: "neutral", size: "md" }), "no-underline")}
+ >
+ <i aria-hidden="true" className="inline-block size-[7px] rounded-full bg-meter" />
+ <span className="text-muted">policy</span>
+ {children}
+ </Link>
+ );
+}
+
+export default async function PolicyChip() {
+ const policy = await readPolicy().catch(() => null);
+ if (!policy) {
+ return (
+ <PolicyChipShell preset="unknown">
+ <span className="text-muted-2">editor not answering</span>
+ </PolicyChipShell>
+ );
+ }
+ const g = policy.generation;
+ const today = await readToday(g.caps.daily).catch(() => null);
+ return (
+ <PolicyChipShell preset={g.preset}>
+ <span>{g.preset}</span>
+ <span className="font-mono text-[11px] text-muted">{shortModel(g.models.api)}</span>
+ {today && (
+ <span className="font-mono text-[11px] text-meter" data-policy-today={today.usd.toFixed(2)}>
+ today {usd(today.usd)}
+ {today.daily > 0 ? ` of ${usd(today.daily)}` : ""}
+ </span>
+ )}
+ </PolicyChipShell>
+ );
+}
diff --git a/umtool/components/projects/ClaimBenchPage.tsx b/umtool/components/projects/ClaimBenchPage.tsx
@@ -1,10 +1,11 @@
import { notFound } from "next/navigation";
import AppShell from "@/components/shell/AppShell";
-import { browseHref, projectHref } from "@/lib/hrefs";
+import { browseHref } from "@/lib/hrefs";
import ClaimBench, { type ClaimBenchData } from "./ClaimBench";
import { manifestToken } from "@/lib/report/manifest.mjs";
import { readClaimDetail, readManifest } from "@/lib/projects/report.mjs";
import { ledgerTotals } from "umtool-report-to-video/ledger-totals";
+import { pieceHrefOfProject } from "@/lib/pieces/article";
import type { ProjectRef } from "@/lib/project-types";
// The server half of the claim bench.
@@ -84,6 +85,8 @@ export default async function ClaimBenchPage({
(e) => !e.scope || !e.scopeBasis || !e.scopeConfidence || !e.population || !e.valueKind || !Array.isArray(e.flags),
).length;
+ // The piece this view belongs to: the article's when an article claims the project (P4a-2).
+ const back = await pieceHrefOfProject(project.id, { tab: "cut" });
return (
<div className="flex h-full flex-col">
{/* A bench: the rail collapses and the work takes the width. */}
@@ -92,7 +95,7 @@ export default async function ClaimBenchPage({
rail="collapsed"
crumbs={[
{ href: browseHref(), label: "projects" },
- { href: projectHref(project.id, { tab: "cut" }), label: project.name },
+ { href: back, label: project.name },
{ label: claimId },
]}
note={`claim ${i + 1} of ${ledger.length} · ${outstanding} unadjudicated`}
diff --git a/umtool/components/projects/ClipBenchPage.tsx b/umtool/components/projects/ClipBenchPage.tsx
@@ -1,6 +1,6 @@
import { notFound } from "next/navigation";
import AppShell from "@/components/shell/AppShell";
-import { browseHref, projectHref } from "@/lib/hrefs";
+import { browseHref } from "@/lib/hrefs";
import ClipBench, { type ClipBenchData } from "./ClipBench";
import { manifestToken } from "@/lib/report/manifest.mjs";
import {
@@ -14,6 +14,7 @@ import {
import { projectCache, segmentFor, windowsFor } from "@/lib/report/serve.mjs";
import { FETCH_MAX_PAD } from "@/lib/report/driver.mjs";
import { deckOn } from "umtool-report-to-video/deck";
+import { pieceHrefOfProject } from "@/lib/pieces/article";
import type { ProjectRef } from "@/lib/project-types";
// The server half of the bench: resolve the clip, read what it needs, and hand
@@ -164,6 +165,8 @@ export default async function ClipBenchPage({
: null,
};
+ // The piece this view belongs to: the article's when an article claims the project (P4a-2).
+ const back = await pieceHrefOfProject(project.id, { tab: "cut" });
return (
<div className="flex h-full flex-col">
{/* A bench: the rail collapses and the work takes the width. */}
@@ -172,7 +175,7 @@ export default async function ClipBenchPage({
rail="collapsed"
crumbs={[
{ href: browseHref(), label: "projects" },
- { href: projectHref(project.id, { tab: "cut" }), label: project.name },
+ { href: back, label: project.name },
{ label: clipId },
]}
// The progress reading moved INTO the bench, where pressing `y` can
diff --git a/umtool/components/projects/NarrationPage.tsx b/umtool/components/projects/NarrationPage.tsx
@@ -1,9 +1,10 @@
import Link from "next/link";
import BrowseHeader from "@/components/BrowseHeader";
-import { projectHref, projectsHref } from "@/lib/hrefs";
+import { projectsHref } from "@/lib/hrefs";
import { readManifest } from "@/lib/projects/report.mjs";
import { manifestToken } from "@/lib/report/manifest.mjs";
import { narrationReviewView } from "@/lib/report/narration-review.mjs";
+import { pieceHrefOfProject } from "@/lib/pieces/article";
import type { ProjectRef } from "@/lib/project-types";
import NarrationReview, { type NarrationView } from "./NarrationReview";
@@ -18,12 +19,14 @@ export default async function NarrationPage({ project }: { project: ProjectRef }
const view = (await narrationReviewView(project.dir, manifest ?? {})) as NarrationView;
const token = await manifestToken(project.dir);
const { counts } = view;
+ // The piece this view belongs to: the article's when an article claims the project (P4a-2).
+ const [back, media] = await Promise.all([pieceHrefOfProject(project.id), pieceHrefOfProject(project.id, { tab: "media" })]);
return (
<div className="flex h-full flex-col">
<BrowseHeader
crumbs={[
{ href: projectsHref(), label: "projects" },
- { href: projectHref(project.id), label: project.id },
+ { href: back, label: project.id },
{ label: "narration" },
]}
note={
@@ -38,7 +41,7 @@ export default async function NarrationPage({ project }: { project: ProjectRef }
{view.rows.length === 0 ? (
<p data-narration-empty="" className="text-[12px] text-[var(--color-dim)]">
No card in this cut carries a narration.{" "}
- <Link href={projectHref(project.id, { tab: "media" })} className="ink-link">
+ <Link href={media} className="ink-link">
back to {project.id}
</Link>
</p>
diff --git a/umtool/components/projects/ReportProject.tsx b/umtool/components/projects/ReportProject.tsx
@@ -1,23 +1,13 @@
-import path from "node:path";
import BrowseHeader from "@/components/BrowseHeader";
-import GeneratedBanner from "@/components/notes/GeneratedBanner";
-import { NotesProvider } from "@/components/notes/NotesProvider";
import PieceFrame from "@/components/piece/PieceFrame";
-import { readNotes } from "@/lib/annotations/store.mjs";
import { readPieceFrame } from "@/lib/pieces/frame";
-import { tabOf, tabOfNoteAnchor } from "@/lib/pieces/tabs.mjs";
-import { channelFor, clipsOf, readClipDetail } from "@/lib/projects/report.mjs";
-import { draftedFields, isCodeDraft } from "yt-dlp-transcript-common/lib/report/drafted.mjs";
+import { projectHref, projectsHref } from "@/lib/hrefs";
+import { projectNoteTab } from "@/lib/pieces/article";
+import { PIECE_TABS, tabOf } from "@/lib/pieces/tabs.mjs";
import type { ProjectRef } from "@/lib/project-types";
import DeleteProject from "./DeleteProject";
-import BuildTab from "./report/BuildTab";
-import CutTab from "./report/CutTab";
-import DeliverTab from "./report/DeliverTab";
-import HistoryTab from "./report/HistoryTab";
-import MediaTab from "./report/MediaTab";
-import OverviewTab from "./report/OverviewTab";
-import SourcesTab from "./report/SourcesTab";
-import { hms } from "./report/shared";
+import ReportTabBody, { reportCounts, reportStatus } from "./report/ReportTabBody";
+import { readClipDetail } from "@/lib/projects/report.mjs";
// ---------------------------------------------------------------------------
// A report video, as a PIECE PAGE (plans/umtool-redesign.md, P4a-1).
@@ -36,14 +26,6 @@ import { hms } from "./report/shared";
// snapshot diffs and the Deliver tab's exports cost nothing on the Overview.
// ---------------------------------------------------------------------------
-/** The tab a `?note=` opens: where the note's anchor is drawn. */
-async function noteTab(dir: string, note: string | undefined): Promise<string | null> {
- if (!note) return null;
- const { doc } = await readNotes(path.join(dir, "notes.json")).catch(() => ({ doc: null }));
- const n = doc?.notes?.find((x: { id: string }) => x.id === note) as { anchor?: { kind?: string } } | undefined;
- return n?.anchor?.kind ? tabOfNoteAnchor(n.anchor.kind) : null;
-}
-
export default async function ReportProject({
project,
search,
@@ -69,30 +51,19 @@ export default async function ReportProject({
);
}
- const { manifest: m, build, entries } = detail;
- const tab = tabOf(search, { noteTab: !search.tab ? await noteTab(project.dir, search.note) : null });
+ const m = detail.manifest;
+ const tab = tabOf(search, { noteTab: !search.tab ? await projectNoteTab(project.dir, search.note) : null });
const frame = await readPieceFrame(project);
- const clips = entries.filter((e) => e.kind === "clip");
- const nonClips = entries.filter((e) => e.kind !== "clip");
- const runtime = clips.reduce((n, e) => n + Math.max(0, e.end - e.start), 0);
- // The tabs' counts: cheap, from the manifest already read.
- const drafted = draftedFields(m).filter((d) => !isCodeDraft(d.provenance)).length;
- const recordings = new Set(clipsOf(m).map((e: { video: string }) => `${channelFor(m, e)}/${e.video}`)).size;
- const props = { project, detail, search };
return (
<div className="flex h-full flex-col">
<PieceFrame
- project={project.id}
- title={typeof m.title === "string" && m.title ? m.title : project.id}
+ crumbs={[{ href: projectsHref(), label: "projects" }, { label: project.id }, { label: typeof m.title === "string" && m.title ? m.title : project.id }]}
frame={frame}
tab={tab}
- counts={{ cut: clips.length, media: drafted, sources: recordings }}
- note={
- `${clips.length} clips` +
- (nonClips.length ? ` · ${nonClips.length} other` : "") +
- ` · ${hms(runtime)} · ${build.built ? "built" : "not built"}`
- }
+ tabs={PIECE_TABS.map((t) => ({ ...t, href: projectHref(project.id, { tab: t.id }) }))}
+ counts={reportCounts(detail)}
+ note={reportStatus(detail)}
more={
<>
<span className="px-2 pb-1 pt-0.5 font-mono text-[11px] text-muted">{project.id}</span>
@@ -100,18 +71,7 @@ export default async function ReportProject({
</>
}
>
- <NotesProvider target={{ project: project.id }}>
- <main className="deck-main flex-1 space-y-4 p-4" data-piece-tab={tab}>
- <GeneratedBanner generatedBy={typeof m.generatedBy === "string" ? m.generatedBy : null} />
- {tab === "overview" && <OverviewTab {...props} frame={frame} />}
- {tab === "cut" && <CutTab {...props} />}
- {tab === "media" && <MediaTab {...props} />}
- {tab === "build" && <BuildTab {...props} />}
- {tab === "deliver" && <DeliverTab {...props} />}
- {tab === "sources" && <SourcesTab {...props} />}
- {tab === "history" && <HistoryTab {...props} />}
- </main>
- </NotesProvider>
+ <ReportTabBody project={project} detail={detail} search={search} tab={tab} frame={frame} />
</PieceFrame>
</div>
);
diff --git a/umtool/components/projects/ReviewPage.tsx b/umtool/components/projects/ReviewPage.tsx
@@ -1,8 +1,9 @@
import BrowseHeader from "@/components/BrowseHeader";
-import { projectHref, projectsHref } from "@/lib/hrefs";
+import { projectsHref } from "@/lib/hrefs";
import { readManifest } from "@/lib/projects/report.mjs";
import { manifestToken } from "@/lib/report/manifest.mjs";
import { draftsView } from "@/lib/report/drafts.mjs";
+import { pieceHrefOfProject } from "@/lib/pieces/article";
import type { ProjectRef } from "@/lib/project-types";
import DraftsReview from "./DraftsReview";
import type { DraftsView } from "./drafts";
@@ -16,12 +17,14 @@ export default async function ReviewPage({ project }: { project: ProjectRef }) {
const manifest = await readManifest(project.dir);
const view = { ...((await draftsView(project.dir, manifest ?? {})) as DraftsView), token: await manifestToken(project.dir) };
const { counts } = view;
+ // The piece this view belongs to: the article's when an article claims the project (P4a-2).
+ const back = await pieceHrefOfProject(project.id);
return (
<div className="flex h-full flex-col">
<BrowseHeader
crumbs={[
{ href: projectsHref(), label: "projects" },
- { href: projectHref(project.id), label: project.id },
+ { href: back, label: project.id },
{ label: "review" },
]}
note={
diff --git a/umtool/components/projects/TakesPage.tsx b/umtool/components/projects/TakesPage.tsx
@@ -1,7 +1,8 @@
import Link from "next/link";
import AppShell from "@/components/shell/AppShell";
-import { browseHref, projectHref } from "@/lib/hrefs";
+import { browseHref } from "@/lib/hrefs";
import { listTakes, readVerdicts } from "@/lib/report/takes.mjs";
+import { pieceHrefOfProject } from "@/lib/pieces/article";
import type { ProjectRef } from "@/lib/project-types";
import TakesBench, { type Take, type TakeVerdict } from "./TakesBench";
@@ -16,6 +17,8 @@ export default async function TakesPage({ project }: { project: ProjectRef }) {
const takes = listing.takes as Take[];
const judged = takes.filter((t) => verdicts[t.id]?.verdict).length;
+ // The piece this view belongs to: the article's when an article claims the project (P4a-2).
+ const back = await pieceHrefOfProject(project.id, { tab: "cut" });
return (
<div className="flex h-full flex-col">
{/* A bench: the rail collapses and the work takes the width. */}
@@ -24,7 +27,7 @@ export default async function TakesPage({ project }: { project: ProjectRef }) {
rail="collapsed"
crumbs={[
{ href: browseHref(), label: "projects" },
- { href: projectHref(project.id, { tab: "cut" }), label: project.id },
+ { href: back, label: project.id },
{ label: "takes" },
]}
note={takes.length ? `${takes.length} takes · ${judged} judged` : undefined}
@@ -33,7 +36,7 @@ export default async function TakesPage({ project }: { project: ProjectRef }) {
{takes.length === 0 ? (
<p data-takes-empty="" className="text-[12px] text-[var(--color-dim)]">
No takes yet.{" "}
- <Link href={projectHref(project.id, { tab: "cut" })} className="ink-link">
+ <Link href={back} className="ink-link">
back to {project.id}
</Link>
</p>
diff --git a/umtool/components/projects/report/CutTab.tsx b/umtool/components/projects/report/CutTab.tsx
@@ -17,7 +17,7 @@ import { Pill, TONE, hms, type ReportTabProps } from "./shared";
// entry with what is wrong with it, and the corrections the walk collected.
// Moved from ReportProject unchanged (P4a-1).
-export default async function CutTab({ project, detail, search }: ReportTabProps) {
+export default async function CutTab({ project, detail, search, tabHref }: ReportTabProps) {
const { manifest: m, entries } = detail;
const corrections = correctionsOf(m) as {
id: string;
@@ -268,7 +268,7 @@ export default async function CutTab({ project, detail, search }: ReportTabProps
</TimelineList>
<div className="mt-2">
<Link
- href={projectHref(project.id, { tab: "cut", all: !showAll })}
+ href={tabHref ? tabHref("cut", { all: !showAll }) : projectHref(project.id, { tab: "cut", all: !showAll })}
className="ink-link text-[11px]"
>
{showAll ? "hide quotes" : "show every quote"}
diff --git a/umtool/components/projects/report/OverviewTab.tsx b/umtool/components/projects/report/OverviewTab.tsx
@@ -11,6 +11,7 @@ import { articleHref } from "@/lib/hrefs";
import { researchCaseHref } from "@/lib/research/hrefs";
import { Markdown } from "@/lib/markdown";
import { decisionsForProject } from "@/lib/projects";
+import type { Decision } from "@/lib/decisions";
import type { PieceFrame } from "@/lib/pieces/frame";
import { TONE, hms, type ReportTabProps } from "./shared";
@@ -52,36 +53,7 @@ export default async function OverviewTab({ project, detail, frame }: ReportTabP
<div className="grid grid-cols-1 gap-[22px] lg:grid-cols-[minmax(0,1.25fr)_minmax(0,1fr)]">
<div className="min-w-0 space-y-4">
{/* --- what is wrong, first ------------------------------------- */}
- {decisions.length > 0 && (
- <section data-project={project.id}>
- <h2 className="micro mb-1.5">
- {decisions.filter((d) => d.severity !== "info").length} waiting of {decisions.length}
- </h2>
- <ul className="space-y-1">
- {decisions.map((d, i) => (
- <li
- key={`${d.kind}-${d.target}-${i}`}
- data-decision={d.kind}
- data-severity={d.severity}
- data-target={d.target}
- className="flex flex-wrap items-baseline gap-2 rounded border border-[var(--color-line)] bg-[var(--color-panel)] px-3 py-1.5"
- >
- <span className={badgeVariants({ variant: TONE[d.severity], size: "sm" })}>
- {d.severity}
- </span>
- <span className="font-mono text-[12px] text-[var(--color-text)]">{d.target}</span>
- <span className="text-[12px] text-[var(--color-dim)]">{d.why}</span>
- <span className="micro ml-auto">{d.kind}</span>
- </li>
- ))}
- </ul>
- </section>
- )}
- {decisions.length === 0 && (
- <p data-project-empty="" className="text-[12.5px] text-muted">
- No decisions on this project.
- </p>
- )}
+ <ProjectDecisions project={project.id} decisions={decisions} />
{iterations && iterations.iterations.length > 0 && article && (
<section data-piece-iterations={iterations.iterations.length}>
@@ -179,8 +151,46 @@ export default async function OverviewTab({ project, detail, frame }: ReportTabP
);
}
+/** A project's decisions, what is waiting first (ReportProject's section, unchanged). */
+export function ProjectDecisions({ project, decisions }: { project: string; decisions: Decision[] }) {
+ return (
+ <>
+ {decisions.length > 0 && (
+ <section data-project={project}>
+ <h2 className="micro mb-1.5">
+ {decisions.filter((d) => d.severity !== "info").length} waiting of {decisions.length}
+ </h2>
+ <ul className="space-y-1">
+ {decisions.map((d, i) => (
+ <li
+ key={`${d.kind}-${d.target}-${i}`}
+ data-decision={d.kind}
+ data-severity={d.severity}
+ data-target={d.target}
+ className="flex flex-wrap items-baseline gap-2 rounded border border-[var(--color-line)] bg-[var(--color-panel)] px-3 py-1.5"
+ >
+ <span className={badgeVariants({ variant: TONE[d.severity], size: "sm" })}>
+ {d.severity}
+ </span>
+ <span className="font-mono text-[12px] text-[var(--color-text)]">{d.target}</span>
+ <span className="text-[12px] text-[var(--color-dim)]">{d.why}</span>
+ <span className="micro ml-auto">{d.kind}</span>
+ </li>
+ ))}
+ </ul>
+ </section>
+ )}
+ {decisions.length === 0 && (
+ <p data-project-empty="" className="text-[12.5px] text-muted">
+ No decisions on this project.
+ </p>
+ )}
+ </>
+ );
+}
+
/** The article's newest iterations (canvas `.itab`): number, kind, model, spend, time, checks, current. */
-function IterationsSummary({ rows }: { rows: IterationRow[] }) {
+export function IterationsSummary({ rows }: { rows: IterationRow[] }) {
return (
<Table>
<thead>
diff --git a/umtool/components/projects/report/ReportTabBody.tsx b/umtool/components/projects/report/ReportTabBody.tsx
@@ -0,0 +1,61 @@
+import GeneratedBanner from "@/components/notes/GeneratedBanner";
+import { NotesProvider } from "@/components/notes/NotesProvider";
+import { channelFor, clipsOf } from "@/lib/projects/report.mjs";
+import type { PieceFrame } from "@/lib/pieces/frame";
+import { draftedFields, isCodeDraft } from "yt-dlp-transcript-common/lib/report/drafted.mjs";
+import BuildTab from "./BuildTab";
+import CutTab from "./CutTab";
+import DeliverTab from "./DeliverTab";
+import HistoryTab from "./HistoryTab";
+import MediaTab from "./MediaTab";
+import OverviewTab from "./OverviewTab";
+import SourcesTab from "./SourcesTab";
+import { hms, type ClipDetail, type ReportTabProps } from "./shared";
+
+// ONE TAB of a report video's sections (P4a-1), wherever the video is drawn:
+// its own piece page (ReportProject) or, since P4a-2, the video tabs of the
+// article piece that claims it (components/articles/ArticlePage.tsx). The
+// project's notes are the target of everything under it.
+
+/** The tabs' counts: cheap, from the manifest already read (Cut: clips, Media: drafted fields, Sources: recordings). */
+export function reportCounts(detail: ClipDetail): { cut: number; media: number; sources: number } {
+ const m = detail.manifest;
+ const clips = detail.entries.filter((e) => e.kind === "clip").length;
+ const media = draftedFields(m).filter((d) => !isCodeDraft(d.provenance)).length;
+ const sources = new Set(clipsOf(m).map((e: { video: string }) => `${channelFor(m, e)}/${e.video}`)).size;
+ return { cut: clips, media, sources };
+}
+
+/** The page's one-line status: `4 clips · 2 other · 0:12 · not built`. */
+export function reportStatus(detail: ClipDetail): string {
+ const clips = detail.entries.filter((e) => e.kind === "clip");
+ const nonClips = detail.entries.filter((e) => e.kind !== "clip");
+ const runtime = clips.reduce((n, e) => n + Math.max(0, e.end - e.start), 0);
+ return (
+ `${clips.length} clips` +
+ (nonClips.length ? ` · ${nonClips.length} other` : "") +
+ ` · ${hms(runtime)} · ${detail.build.built ? "built" : "not built"}`
+ );
+}
+
+export default function ReportTabBody({
+ tab,
+ frame,
+ ...props
+}: ReportTabProps & { tab: string; frame: PieceFrame }) {
+ const m = props.detail.manifest;
+ return (
+ <NotesProvider target={{ project: props.project.id }}>
+ <main className="deck-main flex-1 space-y-4 p-4" data-piece-tab={tab}>
+ <GeneratedBanner generatedBy={typeof m.generatedBy === "string" ? m.generatedBy : null} />
+ {tab === "overview" && <OverviewTab {...props} frame={frame} />}
+ {tab === "cut" && <CutTab {...props} />}
+ {tab === "media" && <MediaTab {...props} />}
+ {tab === "build" && <BuildTab {...props} />}
+ {tab === "deliver" && <DeliverTab {...props} />}
+ {tab === "sources" && <SourcesTab {...props} />}
+ {tab === "history" && <HistoryTab {...props} />}
+ </main>
+ </NotesProvider>
+ );
+}
diff --git a/umtool/components/projects/report/shared.tsx b/umtool/components/projects/report/shared.tsx
@@ -12,6 +12,12 @@ export type ReportTabProps = {
project: ProjectRef;
detail: ClipDetail;
search: Record<string, string | undefined>;
+ /**
+ * The address of one of the piece's tabs: the project's own page, or -- when
+ * an article claims the project (P4a-2) -- the article piece's. Absent is the
+ * project's (lib/hrefs projectHref).
+ */
+ tabHref?: (tab: string, q?: { all?: boolean }) => string;
};
export const hms = (t: number) => {
diff --git a/umtool/lib/hrefs.test.mjs b/umtool/lib/hrefs.test.mjs
@@ -54,6 +54,13 @@ test("articles open in the store or on their site", () => {
assert.equal(H.articleEvidenceHref({ site: "jeralyzer", id: "poker" }, { c: "3" }), "/sites/jeralyzer/poker/evidence?c=3");
assert.equal(H.articleCompareHref("poker", { a: "1", b: "2" }), "/articles/poker/compare?a=1&b=2");
assert.equal(H.newArticleHref(), "/articles/new");
+ // An article piece's tabs (P4a-2): the Overview is never written; another video project, the cut's every quote.
+ assert.equal(H.articleHref({ site: "articles", id: "poker" }, { tab: "overview" }), "/articles/poker");
+ assert.equal(
+ H.articleHref({ site: "articles", id: "poker" }, { note: "n", all: true, project: "gen/poker/i1", tab: "cut" }),
+ "/articles/poker?tab=cut&all=1&project=gen%2Fpoker%2Fi1¬e=n",
+ );
+ assert.equal(H.generationSettingsHref(), "/settings/generation");
});
test("the places: Inbox, Work (and the lists it replaced), Settings", () => {
diff --git a/umtool/lib/hrefs.ts b/umtool/lib/hrefs.ts
@@ -154,6 +154,15 @@ export function generationPolicyHref(): string {
return "/articles/new";
}
+/**
+ * The generation policy's own page (P5 builds it). The article piece's policy
+ * chip links here from P4a-2 on; generationPolicyHref keeps the page that
+ * holds the panel today until P5 lands.
+ */
+export function generationSettingsHref(): string {
+ return "/settings/generation";
+}
+
/** Settings: the machine -- tools, disk, index, sources, deliverables, recent jobs. */
export function systemHref(): string {
return "/settings/system";
@@ -174,7 +183,13 @@ export function siteHref(site: string, q: { ws?: string; rel?: string } = {}): s
// ── articles ────────────────────────────────────────────────────────────────
export type ArticleRef = { site: string; id: string };
-export type ArticleQuery = { tab?: string; status?: string; ws?: string; rel?: string } & NoteOpt;
+/**
+ * An article piece's address (P4a-2): `tab` one of its nine tabs (absent, or
+ * `overview`, is the Overview; `source` is the Article tab's workspace view);
+ * `project` the video project the video tabs show when it is not the one the
+ * article's Cut opens (an article that claims two); `all` the cut's every quote.
+ */
+export type ArticleQuery = { tab?: string; status?: string; ws?: string; rel?: string; project?: string; all?: boolean } & NoteOpt;
function articleBase(a: ArticleRef): string {
return a.site === ARTICLES_KEY
@@ -184,8 +199,8 @@ function articleBase(a: ArticleRef): string {
/** An article's page: `/articles/<id>` in the store, `/sites/<site>/<id>` on a site. */
export function articleHref(a: ArticleRef, q: ArticleQuery = {}): string {
- const { note, ...rest } = q;
- return withQuery(articleBase(a), rest, note);
+ const { note, tab, ...rest } = q;
+ return withQuery(articleBase(a), { ...(tab && tab !== "overview" ? { tab } : {}), ...rest }, note);
}
/** The evidence walk of one article. */
diff --git a/umtool/lib/pieces/article.ts b/umtool/lib/pieces/article.ts
@@ -0,0 +1,159 @@
+import path from "node:path";
+import { readNotes } from "../annotations/store.mjs";
+import { ARTICLES_KEY } from "../articles/key.mjs";
+import { iterationProjects } from "../articles/links.mjs";
+import { articleHref, projectHref } from "../hrefs";
+import { lifecycleOf, readLifecycle } from "../lifecycle";
+import { articlePieceId, readPieceGraph, type Piece, type PieceGraph, type PieceProject } from "../pieces";
+import { boardOfArticle } from "./board.mjs";
+import { readCases, type PieceFrame } from "./frame";
+import { PIECE_TAB_IDS, articleStageOf, articleSteps, tabOfNoteAnchor } from "./tabs.mjs";
+
+// ---------------------------------------------------------------------------
+// THE ARTICLE-ROOTED PIECE (plans/umtool-redesign.md, P4a-2): an article and
+// the video project(s) it claims are one piece, at the article's address.
+//
+// Which project the video tabs show (the plan's linking order): the project
+// of the iteration `current.video` names; else the article's Cut as
+// lib/articles/links.mjs picks it (its first linked: iterations newest first,
+// then a manifest that names it, then a unique slug). Only a project this
+// piece OWNS counts -- one two articles link belongs to the first that claims
+// it (lib/pieces.ts). A current video whose projectDir is outside REPORTS_ROOT
+// is "not reachable here": the video tabs say so rather than show another.
+//
+// A project an article claims renders as that article's piece: its own address
+// (`/projects/<id>`) redirects here with the same `?tab=` (claimedProjectRedirect),
+// and the benches and kind views that stay at project addresses link back here
+// (pieceHrefOfProject). `?project=<id>` picks another of the piece's projects
+// (an article whose iterations made two); it is written only when the project
+// is not the article's Cut, so the common case keeps the bare address.
+//
+// SERVER ONLY.
+// ---------------------------------------------------------------------------
+
+export type ArticleVideo = {
+ /** The project the video tabs show, or null (none, or not reachable here). */
+ project: PieceProject | null;
+ /** The current video's iteration when its projectDir is outside REPORTS_ROOT, or the only ones there are. */
+ unreachable: { n: number; dir: string } | null;
+ /** Every project this piece owns, the one on show among them. */
+ owned: PieceProject[];
+ /** The project the article's Cut opens with no `?project=`. */
+ cut: string | null;
+ /** The iteration that made each project, when one did. */
+ iterationOf: Map<string, number>;
+};
+
+type IterationProject = { n: number; dir: string; current: boolean; reachable: boolean; projectId: string | null };
+
+/**
+ * The article piece's video projects and the one on show (`want`, when the
+ * piece owns it, else the article's Cut).
+ */
+export async function articleVideo(piece: Piece, graph: PieceGraph, want?: string | null): Promise<ArticleVideo> {
+ const owned = piece.projects.filter((p) => graph.pieceOfProject.get(p.id) === piece.id);
+ const its: IterationProject[] =
+ piece.site === ARTICLES_KEY && piece.report ? ((await iterationProjects().catch(() => new Map())).get(piece.report) ?? []) : [];
+ const iterationOf = new Map<string, number>();
+ for (const x of [...its].reverse()) if (x.projectId && !iterationOf.has(x.projectId)) iterationOf.set(x.projectId, x.n);
+ const current = its.find((x) => x.current) ?? null;
+ const currentGone = current && !current.reachable ? { n: current.n, dir: current.dir } : null;
+ const currentOwned = current?.projectId ? owned.find((p) => p.id === current.projectId) : undefined;
+ const cut = currentGone ? null : (currentOwned ?? owned.find((p) => p.cut) ?? owned[0] ?? null)?.id ?? null;
+ const chosen = want && owned.some((p) => p.id === want) ? want : cut;
+ const project = owned.find((p) => p.id === chosen) ?? null;
+ const unreachable = project ? null : (currentGone ?? (owned.length === 0 ? (piece.unreachable[0] ?? null) : null));
+ return { project, unreachable, owned, cut, iterationOf };
+}
+
+/** 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> {
+ 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;
+}
+
+type TabQuery = { tab?: string; all?: boolean; note?: string | null };
+
+/**
+ * Where a project's tab lives: inside its article's piece when an article
+ * claims it, else on its own page. The benches and kind views link back with
+ * this.
+ */
+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);
+ const v = await articleVideo(piece, graph, projectId);
+ return articleHref(
+ { site: piece.site, id: piece.report },
+ { tab: q.tab, all: q.all, project: v.cut === projectId ? undefined : projectId, note: q.note },
+ );
+}
+
+/**
+ * The article piece a claimed project's own address redirects to, with the
+ * same tab (`?tab=`, else the tab its `?note=` is drawn on, else `?all=1`'s
+ * Cut), or null when no article claims it.
+ */
+export async function claimedProjectRedirect(
+ project: { id: string; dir: string },
+ search: Record<string, string | string[] | undefined>,
+): Promise<string | null> {
+ const graph = await readPieceGraph().catch(() => null);
+ const piece = graph ? graph.byId.get(graph.pieceOfProject.get(project.id) ?? "") : undefined;
+ if (!piece || piece.kind !== "article") return null;
+ const one = (k: string) => (typeof search[k] === "string" ? (search[k] as string) : undefined);
+ const note = one("note");
+ const all = one("all") === "1";
+ const asked = one("tab");
+ const tab =
+ asked && PIECE_TAB_IDS.includes(asked)
+ ? asked
+ : ((note ? await projectNoteTab(project.dir, note) : null) ?? (all ? "cut" : "overview"));
+ return pieceHrefOfProject(project.id, { tab, all, note });
+}
+
+export type ArticlePieceFrame = PieceFrame & {
+ /** Where the piece lives in the graph's terms (the piece's site and report). */
+ site: string;
+ report: string;
+};
+
+/**
+ * An article piece's frame: the piece, its lifecycle, the board that seeded
+ * it, and the stepper by what is on disk (lib/pieces/tabs.mjs articleSteps).
+ */
+export async function readArticlePieceFrame(
+ site: string,
+ report: string,
+ { hasIterations, hasReport }: { hasIterations: boolean; hasReport: boolean },
+): Promise<ArticlePieceFrame> {
+ const [graph, life, cases] = await Promise.all([readPieceGraph(), readLifecycle(), readCases()]);
+ const pieceId = articlePieceId(site, report);
+ const piece = graph.byId.get(pieceId) ?? null;
+ const lifecycle = lifecycleOf(life, pieceId);
+ const board = boardOfArticle(articleHref({ site, id: report }), cases);
+ const owned = piece ? piece.projects.filter((p) => graph.pieceOfProject.get(p.id) === pieceId) : [];
+ const steps = articleSteps({
+ research: hasIterations || !!board,
+ article: hasReport,
+ video: owned.length > 0 || (piece?.unreachable.length ?? 0) > 0,
+ deliver: (piece?.looksDone.length ?? 0) > 0,
+ lifecycle,
+ researchNa: "no iterations or research board",
+ }) as PieceFrame["steps"];
+ return {
+ piece,
+ pieceId,
+ article: null,
+ board,
+ lifecycle,
+ lifecycleError: life.error ?? null,
+ steps,
+ stage: articleStageOf(steps),
+ site,
+ report,
+ };
+}
diff --git a/umtool/lib/pieces/board.mjs b/umtool/lib/pieces/board.mjs
@@ -1,4 +1,4 @@
-// Which research board a project was scaffolded from (R2's "Start a video from
+// Which research board a project was scaffolded from -- or an article seeded from (R2's "Start a video from
// this board"). The hand-off is recorded on the CASE, not the project: the
// confirm writes `{ to: "video", href: /projects/<slug>, at, what }` into the
// case's `handoffs` (lib/research/handoff.ts confirmVideo). So the board of a
@@ -16,19 +16,43 @@ function pathOf(href) {
}
/**
- * @param {string} projectId
+ * The newest case whose `to` hand-off's href has the path `want`.
+ *
+ * @param {"video" | "article"} to
+ * @param {string} want a decoded path
* @param {{ id: string, title: string, handoffs?: { to: string, href: string, at?: string }[] }[]} cases
* @returns {{ id: string, title: string, at: string | null } | null}
*/
-export function boardOfProject(projectId, cases) {
- const want = `/projects/${projectId}`;
+function boardOf(to, want, cases) {
let best = null;
for (const c of cases) {
for (const h of c.handoffs ?? []) {
- if (h.to !== "video" || pathOf(h.href) !== want) continue;
+ if (h.to !== to || pathOf(h.href) !== want) continue;
const at = h.at ?? null;
if (!best || (at ?? "") > (best.at ?? "")) best = { id: c.id, title: c.title, at };
}
}
return best;
}
+
+/**
+ * @param {string} projectId
+ * @param {{ id: string, title: string, handoffs?: { to: string, href: string, at?: string }[] }[]} cases
+ * @returns {{ id: string, title: string, at: string | null } | null}
+ */
+export function boardOfProject(projectId, cases) {
+ return boardOf("video", `/projects/${projectId}`, cases);
+}
+
+/**
+ * The board an article was seeded from (R2's "Draft an article from this
+ * board"): the case whose ARTICLE hand-off names the article's page --
+ * `{ to: "article", href: /articles/<id> }` (lib/research/handoff.ts
+ * confirmArticle; the store's address, the only one a hand-off makes).
+ *
+ * @param {string} articlePath the article's page path (`/articles/<id>`, `/sites/<site>/<report>`)
+ * @param {{ id: string, title: string, handoffs?: { to: string, href: string, at?: string }[] }[]} cases
+ */
+export function boardOfArticle(articlePath, cases) {
+ return boardOf("article", pathOf(articlePath), cases);
+}
diff --git a/umtool/lib/pieces/board.test.mjs b/umtool/lib/pieces/board.test.mjs
@@ -1,7 +1,7 @@
// The board a project was scaffolded from: the case whose video hand-off names it.
import assert from "node:assert/strict";
import test from "node:test";
-import { boardOfProject } from "./board.mjs";
+import { boardOfArticle, boardOfProject } from "./board.mjs";
test("a project's board is the case whose video hand-off names it, the newest when two do", () => {
const cases = [
@@ -15,3 +15,13 @@ test("a project's board is the case whose video hand-off names it, the newest wh
// Encoded segments and a query on the href still match.
assert.equal(boardOfProject("a b", [{ id: "c", title: "C", handoffs: [{ to: "video", href: "/projects/a%20b?tab=cut" }] }])?.id, "c");
});
+
+test("an article's board is the case whose ARTICLE hand-off names its page", () => {
+ const cases = [
+ { id: "ferret", title: "Ferret sanctuary", handoffs: [{ to: "article", href: "/articles/ferret", at: "2026-10-14T09:00:00Z" }] },
+ { id: "permit", title: "The permit", handoffs: [{ to: "video", href: "/articles/ferret", at: "2026-10-14T10:00:00Z" }] },
+ ];
+ assert.deepEqual(boardOfArticle("/articles/ferret", cases), { id: "ferret", title: "Ferret sanctuary", at: "2026-10-14T09:00:00Z" });
+ assert.equal(boardOfArticle("/articles/other", cases), null);
+ assert.equal(boardOfProject("ferret", cases), null);
+});
diff --git a/umtool/lib/pieces/frame.ts b/umtool/lib/pieces/frame.ts
@@ -43,17 +43,18 @@ export type PieceFrame = {
stage: string;
};
-/**
- * The research board a project was scaffolded from: the case whose video
- * hand-off names it (lib/pieces/board.mjs). Cases are few; a case that does not
- * read is skipped, never an error on the project page.
- */
-async function boardOf(projectId: string): Promise<PieceFrame["board"]> {
+type CaseDoc = { id: string; title: string; handoffs?: { to: string; href: string; at?: string }[] };
+
+/** Every research case that reads (R2). Cases are few; one that does not read is skipped, never an error on a piece page. */
+export async function readCases(): Promise<CaseDoc[]> {
const list = (await listCases(REPORTS_ROOT).catch(() => [])) as { id: string; error?: string }[];
- const cases = await Promise.all(
- list.filter((c) => !c.error).map((c) => readCase(REPORTS_ROOT, c.id).catch(() => null)),
- );
- return boardOfProject(projectId, cases.filter(Boolean) as { id: string; title: string; handoffs?: { to: string; href: string; at?: string }[] }[]);
+ const cases = await Promise.all(list.filter((c) => !c.error).map((c) => readCase(REPORTS_ROOT, c.id).catch(() => null)));
+ return cases.filter(Boolean) as CaseDoc[];
+}
+
+/** The research board a project was scaffolded from: the case whose video hand-off names it (lib/pieces/board.mjs). */
+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> {
diff --git a/umtool/lib/pieces/tabs.mjs b/umtool/lib/pieces/tabs.mjs
@@ -145,3 +145,113 @@ export function tabOfKey(key) {
const n = Number(key);
return Number.isInteger(n) && n >= 1 && n <= PIECE_TABS.length ? PIECE_TABS[n - 1].id : null;
}
+
+// ── the article-rooted piece (P4a-2) ────────────────────────────────────────
+//
+// An article and the video project it claims are ONE piece, at the article's
+// address (`/articles/<id>`, `/sites/<site>/<report>`). Its tabs are the
+// article's two (the reader, the iterations) set into the video's seven: the
+// video tabs render the claimed project's P4a-1 tabs. Same `?tab=` ids, so a
+// project tab maps to the article piece's tab of the same name.
+
+/** The tabs of an article piece, in order; the key that opens each is its position (`1`–`9`). */
+export const ARTICLE_PIECE_TABS = [
+ { id: "overview", label: "Overview" },
+ { id: "article", label: "Article" },
+ { id: "iterations", label: "Iterations" },
+ { id: "cut", label: "Cut" },
+ { id: "media", label: "Media" },
+ { id: "build", label: "Build" },
+ { id: "deliver", label: "Deliver" },
+ { id: "sources", label: "Sources" },
+ { id: "history", label: "History" },
+];
+
+export const 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 sections an article piece adds to SECTION_TAB, by the name a spec says.
+ * The video's sections keep the tab they have on a project piece, except the
+ * two a project's Overview summarised (the article, its iterations): here they
+ * are tabs of their own.
+ */
+export const ARTICLE_SECTION_TAB = {
+ ...SECTION_TAB,
+ next: "overview",
+ sections: "overview",
+ article: "article",
+ reader: "article",
+ // The article's workspace files: the Article tab's `source` view (`?tab=source`).
+ source: "article",
+ iterations: "iterations",
+};
+
+/** The tab a section is on in an article piece; throws on a name nobody declared. */
+export function articleTabOfSection(name) {
+ const tab = ARTICLE_SECTION_TAB[name];
+ if (!tab) throw new Error(`no section "${name}" on an article piece (lib/pieces/tabs.mjs ARTICLE_SECTION_TAB)`);
+ return tab;
+}
+
+/**
+ * The tab an article piece's address opens. `?tab=` first (`source` is the
+ * Article tab's workspace view, the old article page's own key); then a note --
+ * the article's own notes are drawn on the Article tab, a note on the video
+ * project where its anchor is (the page looks it up and passes `noteTab`);
+ * then the reader's own keys (`rv` the slides/overview switch, `status` the
+ * notes filter, `ws`/`rel` a workspace file) open the Article tab, `?all=1` the
+ * Cut; else the Overview.
+ *
+ * @param {{ tab?: string, note?: string, rv?: string, status?: string, ws?: string, rel?: string, all?: string }} search
+ * @param {{ noteTab?: string | null }} [opts]
+ */
+export function articleTabOf(search, { noteTab = null } = {}) {
+ const t = search?.tab;
+ if (t === "source") return "article";
+ if (t && ARTICLE_PIECE_TAB_IDS.includes(t)) return t;
+ if (search?.note) return noteTab && ARTICLE_PIECE_TAB_IDS.includes(noteTab) ? noteTab : "article";
+ if (search?.rv || search?.status || search?.ws || search?.rel) return "article";
+ if (search?.all === "1") return "cut";
+ return "overview";
+}
+
+/**
+ * An article piece's stepper, each stage by what is on disk rather than one
+ * bucket walked (P4a-2):
+ *
+ * Research done when iterations exist or a research board seeded it; `na`
+ * (with `researchNa` as the reason) when the article has neither
+ * -- a site's hand-written report has no research recorded here
+ * Article done when a report is current (report.json reads)
+ * Video done when it claims a video project
+ * Deliver done when it looks done (a final video and a share batch, or
+ * published with its video)
+ *
+ * The first stage not done is current; the rest not done are to do. A piece
+ * marked done has done every stage that applies.
+ *
+ * @param {{ research: boolean, article: boolean, video: boolean, deliver: boolean, lifecycle: string, researchNa?: string | null }} p
+ * @returns {{ label: string, state: "done" | "current" | "todo" | "na", title?: string }[]}
+ */
+export function articleSteps({ research, article, video, deliver, lifecycle, researchNa = null }) {
+ const done = { research, article, video, deliver };
+ let current = false;
+ return STAGE_STEPS.map((s) => {
+ if (s.id === "research" && !research && researchNa) return { label: s.label, state: "na", title: researchNa };
+ if (lifecycle === "done" || done[s.id]) return { label: s.label, state: "done" };
+ if (!current) {
+ current = true;
+ return { label: s.label, state: "current" };
+ }
+ return { label: s.label, state: "todo" };
+ });
+}
+
+/** The stage id an article piece's stepper has lit (its current step), else `deliver` when every stage is done. */
+export function articleStageOf(steps) {
+ const i = steps.findIndex((s) => s.state === "current");
+ return i >= 0 ? STAGE_STEPS[i].id : "deliver";
+}
diff --git a/umtool/lib/pieces/tabs.test.mjs b/umtool/lib/pieces/tabs.test.mjs
@@ -2,7 +2,24 @@
import assert from "node:assert/strict";
import test from "node:test";
import { STAGES } from "../work/facets.mjs";
-import { PIECE_TABS, PIECE_TAB_IDS, SECTION_TAB, STAGE_STEPS, pieceSteps, stepsOf, tabOf, tabOfKey, tabOfNoteAnchor, tabOfSection } from "./tabs.mjs";
+import {
+ ARTICLE_PIECE_TAB_IDS,
+ PIECE_TABS,
+ PIECE_TAB_IDS,
+ SECTION_TAB,
+ STAGE_STEPS,
+ VIDEO_TAB_IDS,
+ articleStageOf,
+ articleSteps,
+ articleTabOf,
+ articleTabOfSection,
+ pieceSteps,
+ stepsOf,
+ tabOf,
+ tabOfKey,
+ tabOfNoteAnchor,
+ tabOfSection,
+} from "./tabs.mjs";
test("seven tabs, in the canvas's order; keys 1–7 open them", () => {
assert.deepEqual(PIECE_TAB_IDS, ["overview", "cut", "media", "build", "deliver", "sources", "history"]);
@@ -61,3 +78,53 @@ test("a piece's stepper: an article walks all four; a standalone video has no Re
// Marked done: every stage it has is done; the ones it never had stay not applicable.
assert.deepEqual(states(pieceSteps({ kind: "project", bucket: "deliver", lifecycle: "done" })), ["na", "na", "done", "done"]);
});
+
+test("an article piece: nine tabs, the video's seven around the article's two", () => {
+ assert.deepEqual(ARTICLE_PIECE_TAB_IDS, ["overview", "article", "iterations", "cut", "media", "build", "deliver", "sources", "history"]);
+ assert.deepEqual(VIDEO_TAB_IDS, ["cut", "media", "build", "deliver", "sources", "history"]);
+ assert.equal(articleTabOfSection("reader"), "article");
+ assert.equal(articleTabOfSection("source"), "article");
+ assert.equal(articleTabOfSection("iterations"), "iterations");
+ assert.equal(articleTabOfSection("timeline"), "cut");
+ assert.equal(articleTabOfSection("drafts"), "media");
+ assert.throws(() => articleTabOfSection("nope"));
+});
+
+test("an article piece's address picks the tab: the reader's keys open the Article, a note where it is drawn", () => {
+ assert.equal(articleTabOf({}), "overview");
+ assert.equal(articleTabOf({ tab: "iterations" }), "iterations");
+ assert.equal(articleTabOf({ tab: "source" }), "article");
+ assert.equal(articleTabOf({ tab: "cut" }), "cut");
+ assert.equal(articleTabOf({ tab: "nonsense" }), "overview");
+ // A note: the article's own on the reader, a video's where its anchor is.
+ assert.equal(articleTabOf({ note: "n1" }), "article");
+ assert.equal(articleTabOf({ note: "n1" }, { noteTab: "cut" }), "cut");
+ assert.equal(articleTabOf({ tab: "history", note: "n1" }, { noteTab: "cut" }), "history");
+ assert.equal(articleTabOf({ rv: "slides" }), "article");
+ assert.equal(articleTabOf({ status: "resolved" }), "article");
+ assert.equal(articleTabOf({ all: "1" }), "cut");
+});
+
+test("an article piece's stepper: each stage by what exists, the first missing one current", () => {
+ const st = (s) => s.map((x) => x.state);
+ // Iterations, a report, a video: at Deliver.
+ let s = articleSteps({ research: true, article: true, video: true, deliver: false, lifecycle: "active" });
+ assert.deepEqual(st(s), ["done", "done", "done", "current"]);
+ assert.equal(articleStageOf(s), "deliver");
+ // In the making: research done, the article current.
+ s = articleSteps({ research: true, article: false, video: false, deliver: false, lifecycle: "active" });
+ assert.deepEqual(st(s), ["done", "current", "todo", "todo"]);
+ assert.equal(articleStageOf(s), "article");
+ // A site's hand-written report: no research recorded, at Video.
+ s = articleSteps({ research: false, article: true, video: false, deliver: false, lifecycle: "active", researchNa: "no iterations or board" });
+ assert.deepEqual(st(s), ["na", "done", "current", "todo"]);
+ assert.equal(s[0].title, "no iterations or board");
+ assert.equal(articleStageOf(s), "video");
+ // Published with its video: every stage done.
+ s = articleSteps({ research: true, article: true, video: true, deliver: true, lifecycle: "active" });
+ assert.deepEqual(st(s), ["done", "done", "done", "done"]);
+ assert.equal(articleStageOf(s), "deliver");
+ // Marked done: every stage that applies is done; `na` stays.
+ s = articleSteps({ research: false, article: true, video: false, deliver: false, lifecycle: "done", researchNa: "none" });
+ assert.deepEqual(st(s), ["na", "done", "done", "done"]);
+});