commit 76411f9f08134c56322ed5ccaa49f687431328d0
parent 8fe9c6f1c65d2303ec267278847c375c5698162f
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Sun, 11 Oct 2026 13:51:56 -0400
cli: archilyzer reports prepare|export|check|verify-quotes|attach-video --article <id>
Release 26 A6. The same work as a site's, over the articles
(transcripts/reports/), staged under .export-index/articles/:
- prepare --article <id>: every published article plus that one (a draft
may be readied before it is published), so one cache serves both homepage
builds; then the export, as for a site;
- export --article <id>: that article's files, published or a draft; its
revision committed to reports/<id>/history-git as "Archilyzer
<noreply@articles.invalid>";
- check --article <id>: as the homepage's compose would (any channel of
the corpus citable);
- verify-quotes --article <id>: the article's report.json;
- attach-video --article <id> <video>: `video` written through the article
registry (patchArticle), so the write is locked and the audience kept.
publish/reportHost.ts articlesWorkHost names that set; reportExports takes a
host as reportMedia does; attachReportVideo takes a `setVideo` writer.
COMMANDS.md regenerated.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
10 files changed, 415 insertions(+), 82 deletions(-)
diff --git a/COMMANDS.md b/COMMANDS.md
@@ -29,11 +29,11 @@ Run from the repo root (in the container: `docker compose exec editor pnpm archi
| `archilyzer build all` | `[--skip-archives]` | alias: publish index + publish build all --runner auto (containers when an engine answers, else serially on the host) |
| `archilyzer build hub` | | compose:hub + INSTANCE\_MODE=hub next build into export/out — a raw build, unstamped; to deploy the hub build it with `publish hub` |
| `archilyzer build homepage` | `[--no-source]` | compose + source publish + next build in homepage/ (reads the index as it stands); --no-source removes the published source instead |
-| `archilyzer reports prepare` | `<id>` | cut every clip and copy every post capture the site's published reports cite into its report-media cache, before its build, then export the reports as files (reports export) when nothing is missing (exit 1 when a citation lacks media or an export fails; default id: SITE\_ID) |
-| `archilyzer reports export` | `<id> [--report <reportId>] [--formats html,pdf,md,slides,slides-pdf,zip] [--allow-missing-media]` | write the site's published reports as files (report.html, report.pdf, report.md, slides.html, slides.pdf, evidence-pack.zip) into its report-exports staging, where compose publishes them from (exit 1 on a problem; a PDF skipped for want of a browser is a note; default id: SITE\_ID) |
-| `archilyzer reports check` | `<id> [--reports <a,b>] [--allow-missing-media]` | what compose would say about the site's reports, with no build: each report validated, every cited quote checked against its record, every cited moment's prepared media present and current, the report video under the publish limit (exit 1 with the list; --reports checks those, drafts included; default id: SITE\_ID) |
-| `archilyzer reports verify-quotes` | `<report.json> [--json]` | every video, audio and post quote of one report against its record with compose's own check: the best score and track, and the en-orig track's score where the record has one — a quote that matches a served `en` rewrite and not en-orig is reported (exit 1 when any quote drifted) |
-| `archilyzer reports attach-video` | `<report.json> <video> [--poster <image>] [--caption <line>]` | the report's video: remuxed (an H.264 mp4 under the limit) or encoded to fit the 24 MiB publish limit, written beside report.json as video.mp4 with a poster (given, kept, or a frame of the video), and `video` set in report.json |
+| `archilyzer reports prepare` | `<id> \| --article <articleId>` | cut every clip and copy every post capture the site's published reports cite into its report-media cache, before its build, then export the reports as files (reports export) when nothing is missing (exit 1 when a citation lacks media or an export fails; default id: SITE\_ID); --article: the articles' cache (transcripts/reports/), every published article plus that one |
+| `archilyzer reports export` | `<id> [--report <reportId>] \| --article <articleId>` | \[--formats html,pdf,md,slides,slides-pdf,zip\] \[--allow-missing-media\] write the site's published reports as files (report.html, report.pdf, report.md, slides.html, slides.pdf, evidence-pack.zip) into its report-exports staging, where compose publishes them from (exit 1 on a problem; a PDF skipped for want of a browser is a note; default id: SITE\_ID); --article: one article (transcripts/reports/), published or a draft |
+| `archilyzer reports check` | `<id> [--reports <a,b>] \| --article <articleId>` | \[--allow-missing-media\] what compose would say about the site's reports, with no build: each report validated, every cited quote checked against its record, every cited moment's prepared media present and current, the report video under the publish limit (exit 1 with the list; --reports checks those, drafts included; default id: SITE\_ID); --article: one article (transcripts/reports/), published or a draft, as the homepage's compose would |
+| `archilyzer reports verify-quotes` | `<report.json> \| --article <articleId>` | \[--json\] every video, audio and post quote of one report against its record with compose's own check: the best score and track, and the en-orig track's score where the record has one — a quote that matches a served `en` rewrite and not en-orig is reported (exit 1 when any quote drifted) |
+| `archilyzer reports attach-video` | `<report.json> <video> \| --article <articleId> <video>` | \[--poster <image>\] \[--caption <line>\] the report's video: remuxed (an H.264 mp4 under the limit) or encoded to fit the 24 MiB publish limit, written beside report.json as video.mp4 with a poster (given, kept, or a frame of the video), and `video` set in report.json (an article's through the article registry) |
| `archilyzer reports convert` | `<sweep\|ask\|manifest> <in> --out <report.json> [--channels-dir <dir>] [--id <id>] [--title <title>]` | a /sweep report (markdown), an /ask answer or a report-to-video manifest as a report.json, written only when it validates (--channels-dir: widen spans from the cues, find posts' channels) |
| `archilyzer reports to-manifest` | `<report.json> --out <manifest.json> [--channels-dir <dir>] [--site-origin <url>]` | a starter report-to-video manifest from a report (a chapter card per section, a claim's still and clips stamped with its verdict, its posts) |
| `archilyzer source publish` | `[--force] [--check] [--keep-scratch]` | the scrubbed git mirror, raw tree, history pages (stagit, when installed) and tarball into homepage/public, behind the denied-literal gate (--check: audit and count, write nothing) |
diff --git a/common/bin/archilyzer.ts b/common/bin/archilyzer.ts
@@ -263,9 +263,13 @@ export const COMMANDS: Command[] = [
{
path: ["reports", "prepare"],
usage:
- "<id> cut every clip and copy every post capture the site's published reports cite into its report-media cache, before its build, then export the reports as files (reports export) when nothing is missing (exit 1 when a citation lacks media or an export fails; default id: SITE_ID)",
+ "<id> | --article <articleId> cut every clip and copy every post capture the site's published reports cite into its report-media cache, before its build, then export the reports as files (reports export) when nothing is missing (exit 1 when a citation lacks media or an export fails; default id: SITE_ID); --article: the articles' cache (transcripts/reports/), every published article plus that one",
+ flags: { article: "string" },
maxPositionals: 1,
- run: async ({ positionals, env }) => {
+ run: async ({ positionals, flags, env }) => {
+ const article = articleFrom(positionals, flags, "reports prepare");
+ if (article === null) return 2;
+ if (article) return (await import("./reports-prepare")).main({ article, signal: interrupted() });
const siteId = siteIdFrom(positionals, env, "reports prepare");
if (!siteId) return 2;
return (await import("./reports-prepare")).main({ siteId, signal: interrupted() });
@@ -274,12 +278,18 @@ export const COMMANDS: Command[] = [
{
path: ["reports", "export"],
usage:
- "<id> [--report <reportId>] [--formats html,pdf,md,slides,slides-pdf,zip] [--allow-missing-media] write the site's published reports as files (report.html, report.pdf, report.md, slides.html, slides.pdf, evidence-pack.zip) into its report-exports staging, where compose publishes them from (exit 1 on a problem; a PDF skipped for want of a browser is a note; default id: SITE_ID)",
- flags: { report: "string", formats: "string", "allow-missing-media": "boolean" },
+ "<id> [--report <reportId>] | --article <articleId> [--formats html,pdf,md,slides,slides-pdf,zip] [--allow-missing-media] write the site's published reports as files (report.html, report.pdf, report.md, slides.html, slides.pdf, evidence-pack.zip) into its report-exports staging, where compose publishes them from (exit 1 on a problem; a PDF skipped for want of a browser is a note; default id: SITE_ID); --article: one article (transcripts/reports/), published or a draft",
+ flags: { report: "string", formats: "string", "allow-missing-media": "boolean", article: "string" },
maxPositionals: 1,
run: async ({ positionals, flags, env }) => {
- const siteId = siteIdFrom(positionals, env, "reports export");
- if (!siteId) return 2;
+ const article = articleFrom(positionals, flags, "reports export");
+ if (article === null) return 2;
+ if (article && typeof flags.report === "string") {
+ console.error("reports export: --article names the report; --report is for a site's");
+ return 2;
+ }
+ const siteId = article ? undefined : siteIdFrom(positionals, env, "reports export");
+ if (!article && !siteId) return 2;
const { parseReportExportFormats } = await import("../publish/reportExports");
const formats = typeof flags.formats === "string" ? parseReportExportFormats(flags.formats) : undefined;
if (formats === null) {
@@ -287,7 +297,7 @@ export const COMMANDS: Command[] = [
return 2;
}
return (await import("./reports-export")).main({
- siteId,
+ ...(article ? { article } : { siteId: siteId! }),
signal: interrupted(),
...(typeof flags.report === "string" ? { reportId: flags.report } : {}),
...(formats ? { formats } : {}),
@@ -298,10 +308,18 @@ export const COMMANDS: Command[] = [
{
path: ["reports", "check"],
usage:
- "<id> [--reports <a,b>] [--allow-missing-media] what compose would say about the site's reports, with no build: each report validated, every cited quote checked against its record, every cited moment's prepared media present and current, the report video under the publish limit (exit 1 with the list; --reports checks those, drafts included; default id: SITE_ID)",
- flags: { reports: "string", "allow-missing-media": "boolean" },
+ "<id> [--reports <a,b>] | --article <articleId> [--allow-missing-media] what compose would say about the site's reports, with no build: each report validated, every cited quote checked against its record, every cited moment's prepared media present and current, the report video under the publish limit (exit 1 with the list; --reports checks those, drafts included; default id: SITE_ID); --article: one article (transcripts/reports/), published or a draft, as the homepage's compose would",
+ flags: { reports: "string", "allow-missing-media": "boolean", article: "string" },
maxPositionals: 1,
run: async ({ positionals, flags, env }) => {
+ const article = articleFrom(positionals, flags, "reports check");
+ if (article === null) return 2;
+ if (article) {
+ return (await import("./reports-check")).checkMain({
+ article,
+ allowMissingMedia: flags["allow-missing-media"] === true,
+ });
+ }
const siteId = siteIdFrom(positionals, env, "reports check");
if (!siteId) return 2;
const reports =
@@ -318,13 +336,15 @@ export const COMMANDS: Command[] = [
{
path: ["reports", "verify-quotes"],
usage:
- "<report.json> [--json] every video, audio and post quote of one report against its record with compose's own check: the best score and track, and the en-orig track's score where the record has one — a quote that matches a served `en` rewrite and not en-orig is reported (exit 1 when any quote drifted)",
- flags: { json: "boolean" },
+ "<report.json> | --article <articleId> [--json] every video, audio and post quote of one report against its record with compose's own check: the best score and track, and the en-orig track's score where the record has one — a quote that matches a served `en` rewrite and not en-orig is reported (exit 1 when any quote drifted)",
+ flags: { json: "boolean", article: "string" },
maxPositionals: 1,
run: async ({ positionals, flags }) => {
- const [file] = positionals;
+ const article = articleFrom(positionals, flags, "reports verify-quotes");
+ if (article === null) return 2;
+ const file = article ? await articleReportFile(article) : positionals[0];
if (!file) {
- console.error("reports verify-quotes: give <report.json>");
+ console.error("reports verify-quotes: give <report.json> or --article <id>");
return 2;
}
return (await import("./reports-check")).verifyQuotesMain({ file, json: flags.json === true });
@@ -333,17 +353,18 @@ export const COMMANDS: Command[] = [
{
path: ["reports", "attach-video"],
usage:
- "<report.json> <video> [--poster <image>] [--caption <line>] the report's video: remuxed (an H.264 mp4 under the limit) or encoded to fit the 24 MiB publish limit, written beside report.json as video.mp4 with a poster (given, kept, or a frame of the video), and `video` set in report.json",
- flags: { poster: "string", caption: "string" },
+ "<report.json> <video> | --article <articleId> <video> [--poster <image>] [--caption <line>] the report's video: remuxed (an H.264 mp4 under the limit) or encoded to fit the 24 MiB publish limit, written beside report.json as video.mp4 with a poster (given, kept, or a frame of the video), and `video` set in report.json (an article's through the article registry)",
+ flags: { poster: "string", caption: "string", article: "string" },
maxPositionals: 2,
run: async ({ positionals, flags }) => {
- const [reportFile, video] = positionals;
- if (!reportFile || !video) {
- console.error("reports attach-video: give <report.json> <video>");
+ const article = typeof flags.article === "string" ? flags.article.trim() : undefined;
+ const [reportFile, video] = article ? [undefined, positionals[0]] : positionals;
+ if ((article ? positionals.length !== 1 : !reportFile) || !video) {
+ console.error("reports attach-video: give <report.json> <video>, or --article <id> <video>");
return 2;
}
return (await import("./reports-attach-video")).attachVideoMain({
- reportFile,
+ ...(article ? { article } : { reportFile }),
video,
...(typeof flags.poster === "string" ? { poster: flags.poster } : {}),
...(typeof flags.caption === "string" ? { caption: flags.caption } : {}),
@@ -764,6 +785,33 @@ function script(path: string[], file: string, usage: string, heapMb?: number): C
// The site a site command names: its argument, else SITE_ID (which is how
// export's `build` / `deploy` scripts are called). Prints and returns null when
// there is neither.
+// `--article <id>`: the id, "" when the flag is absent, or null (after saying
+// why) when it is empty or given beside a positional site / report.json.
+function articleFrom(
+ positionals: string[],
+ flags: Record<string, unknown>,
+ name: string,
+): string | null {
+ if (flags.article === undefined) return "";
+ const id = typeof flags.article === "string" ? flags.article.trim() : "";
+ if (!id) {
+ console.error(`${name}: --article needs an article id`);
+ return null;
+ }
+ if (positionals.length > 0) {
+ console.error(`${name}: --article names the article; give no site or file beside it`);
+ return null;
+ }
+ return id;
+}
+
+// An article's report.json (transcripts/reports/<id>/report.json).
+async function articleReportFile(id: string): Promise<string> {
+ const { articleFile } = await import("../lib/report/registry");
+ const { getPaths } = await import("../lib/paths");
+ return articleFile(getPaths(), id);
+}
+
function siteIdFrom(
positionals: string[],
env: NodeJS.ProcessEnv,
diff --git a/common/bin/reports-article.test.ts b/common/bin/reports-article.test.ts
@@ -0,0 +1,168 @@
+// `archilyzer reports prepare|export|check|verify-quotes|attach-video
+// --article <id>` (release 26 A6): the same work as a site's, over the
+// ARTICLES — transcripts/reports/<id>/, staged under .export-index/articles/,
+// any channel of the corpus citable. A temp corpus only.
+//
+// Run with: pnpm --filter yt-dlp-transcript-common exec tsx --test bin/reports-article.test.ts
+
+import { after, test } from "node:test";
+import assert from "node:assert/strict";
+import { execFileSync } from "node:child_process";
+import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
+import { tmpdir } from "node:os";
+import path from "node:path";
+
+const ROOT = mkdtempSync(path.join(tmpdir(), "reports-article-"));
+Object.assign(process.env, {
+ TRANSCRIPTS_DIR: path.join(ROOT, "transcripts"),
+ SITES_DIR: path.join(ROOT, "transcripts", "sites"),
+ SETTINGS_FILE: path.join(ROOT, "settings.json"),
+ EXPORT_PUBLIC_DIR: path.join(ROOT, "public"),
+ EXPORT_INDEX_DIR: path.join(ROOT, ".export-index"),
+ EXPORT_BUILDS_DIR: path.join(ROOT, ".export-builds"),
+});
+after(() => rmSync(ROOT, { recursive: true, force: true }));
+
+const { getPaths } = await import("../lib/paths");
+const { articleFile, configureArticle, readArticlesIndex } = await import("../lib/report/registry");
+const { checkMain, verifyQuotesMain } = await import("./reports-check");
+const { main: prepareMain } = await import("./reports-prepare");
+const { main: exportMain } = await import("./reports-export");
+const { attachVideoMain } = await import("./reports-attach-video");
+const { readRevisionHead } = await import("../publish/reportHistory");
+
+const paths = getPaths();
+const CHAN = "lone";
+const STAGING = path.join(paths.exportIndexDir, "articles");
+
+const writeJson = (file: string, value: unknown) => {
+ mkdirSync(path.dirname(file), { recursive: true });
+ writeFileSync(file, JSON.stringify(value, null, 2));
+};
+const readJson = <T = Record<string, unknown>>(file: string): T => JSON.parse(readFileSync(file, "utf8")) as T;
+const ts = (s: number) => new Date(s * 1000).toISOString().slice(11, 23);
+const vtt = (cues: [number, number, string][]) =>
+ "WEBVTT\nKind: captions\nLanguage: en\n\n" +
+ cues.map(([a, b, text]) => `${ts(a)} --> ${ts(b)} align:start position:0%\n${text}<${ts(a)}><c></c>\n`).join("\n");
+
+function capture() {
+ const lines: string[] = [];
+ return { text: () => lines.join("\n"), out: { log: (s: string) => lines.push(s), error: (s: string) => lines.push(s) } };
+}
+
+const QUOTE = "The bridge opened in the spring, I was there for it.";
+function article(id: string, quote = QUOTE) {
+ return {
+ format: "archilyzer-report",
+ version: 1,
+ id,
+ kind: "sweep",
+ title: `Article ${id}`,
+ citations: { c1: { kind: "video", channel: CHAN, id: "abc1", start: 10, end: 20, quote } },
+ sections: [{ id: "s", title: "S", body: "Said [this](cite:c1)." }],
+ };
+}
+
+writeJson(paths.settingsFile, {});
+// A channel no site has.
+writeJson(path.join(paths.channelsDir, CHAN, "config.json"), { handling: "youtube", name: "Lone", url: "https://www.youtube.com/@lone/videos" });
+const rec = path.join(paths.channelsDir, CHAN, "data", "abc1");
+writeJson(path.join(rec, "metadata.info.json"), {
+ id: "abc1",
+ title: "Stream abc1",
+ channel: CHAN,
+ upload_date: "20260110",
+ duration: 600,
+ webpage_url: "https://www.youtube.com/watch?v=abc1",
+ extractor_key: "Youtube",
+});
+writeFileSync(path.join(rec, "transcript.en.vtt"), vtt([[10, 20, QUOTE]]));
+writeJson(articleFile(paths, "pub"), article("pub"));
+writeJson(articleFile(paths, "draft"), article("draft", "Words the record never had at all."));
+await configureArticle("pub", { published: true }, paths);
+
+test("check --article: as the homepage's compose would — a channel no site has is citable; a draft is checked by name", async () => {
+ const ok = capture();
+ assert.equal(await checkMain({ article: "pub", paths, allowMissingMedia: true }, ok.out), 0, ok.text());
+ assert.match(ok.text(), /reports check --article pub: 1 report\(s\), 1 moment\(s\) — compose would pass/);
+ const media = capture();
+ assert.equal(await checkMain({ article: "pub", paths }, media.out), 1);
+ assert.match(media.text(), /missing-media: lone\/abc1\/10\.00-20\.00: no prepared media/);
+ const draft = capture();
+ assert.equal(await checkMain({ article: "draft", paths, allowMissingMedia: true }, draft.out), 1);
+ assert.match(draft.text(), /quote-drift: draft#c1/);
+ const none = capture();
+ assert.equal(await checkMain({ article: "nope", paths }, none.out), 2);
+ assert.match(none.text(), /no article "nope"/);
+});
+
+test("prepare --article: the articles' cache, every published article plus the one named; a missing clip is listed", async () => {
+ const c = capture();
+ assert.equal(await prepareMain({ article: "draft", exportOptions: { paths } }, c.out), 1, c.text());
+ const index = readJson<{ siteId: string; problems: { kind: string; citations: string[] }[] }>(
+ path.join(STAGING, "report-media", "index.json"),
+ );
+ assert.equal(index.siteId, "articles");
+ assert.deepEqual(
+ index.problems.map((p) => [p.kind, p.citations]),
+ [["missing-media", ["pub#c1", "draft#c1"]]],
+ );
+ assert.match(c.text(), /reports prepare --article draft: 1 problem\(s\)/);
+ assert.equal(existsSync(path.join(paths.exportIndexDir, "sites")), false, "no site's staging touched");
+});
+
+test("export --article: one article's files under .export-index/articles/, its history in reports/<id>/history-git", async () => {
+ const c = capture();
+ assert.equal(
+ await exportMain({ article: "pub", paths, formats: ["html", "md"], allowMissingMedia: true }, c.out),
+ 0,
+ c.text(),
+ );
+ const dir = path.join(STAGING, "report-exports", "pub");
+ assert.ok(existsSync(path.join(dir, "report.html")));
+ assert.ok(existsSync(path.join(dir, "report.md")));
+ const manifest = readJson<{ siteId: string; revision?: { revision: number } }>(path.join(dir, "export.json"));
+ assert.equal(manifest.siteId, "articles");
+ assert.equal(manifest.revision?.revision, 1);
+ const head = await readRevisionHead(path.join(path.dirname(articleFile(paths, "pub")), "history-git"));
+ assert.equal(head?.revision, 1);
+ const author = execFileSync("git", ["--git-dir", path.join(path.dirname(articleFile(paths, "pub")), "history-git"), "log", "-1", "--format=%an <%ae>"], { encoding: "utf8" }).trim();
+ assert.equal(author, "Archilyzer <noreply@articles.invalid>");
+ // An article that is not there.
+ const none = capture();
+ assert.equal(await exportMain({ article: "nope", paths }, none.out), 2);
+});
+
+test("verify-quotes takes an article's file", async () => {
+ const c = capture();
+ assert.equal(await verifyQuotesMain({ file: articleFile(paths, "pub"), paths }, c.out), 0, c.text());
+});
+
+const hasFfmpeg = (() => {
+ try {
+ execFileSync("ffmpeg", ["-version"], { stdio: "ignore" });
+ return true;
+ } catch {
+ return false;
+ }
+})();
+
+test("attach-video --article: `video` written through the registry, the audience kept", { skip: !hasFfmpeg && "no ffmpeg" }, async () => {
+ await configureArticle("pub", { audience: "public" }, paths);
+ const src = path.join(ROOT, "clip.mp4");
+ execFileSync("ffmpeg", [
+ "-v", "error", "-y",
+ "-f", "lavfi", "-i", "testsrc=size=640x360:rate=25",
+ "-f", "lavfi", "-i", "sine=frequency=440:sample_rate=44100",
+ "-t", "2", "-c:v", "libx264", "-preset", "ultrafast", "-c:a", "aac", src,
+ ]);
+ const c = capture();
+ assert.equal(await attachVideoMain({ article: "pub", video: src, caption: "Cut." }, c.out), 0, c.text());
+ const doc = readJson<{ video: unknown; audience: string }>(articleFile(paths, "pub"));
+ assert.deepEqual(doc.video, { src: "video.mp4", poster: "poster.jpg", caption: "Cut." });
+ assert.equal(doc.audience, "public");
+ assert.match(c.text(), /reports attach-video: article pub video =/);
+ assert.deepEqual((await readArticlesIndex(paths)).published, ["pub"]);
+ const none = capture();
+ assert.equal(await attachVideoMain({ article: "nope", video: src }, none.out), 1);
+});
diff --git a/common/bin/reports-attach-video.ts b/common/bin/reports-attach-video.ts
@@ -3,17 +3,24 @@
// the publish limit, written beside report.json as video.mp4 with a poster,
// and `video` set in report.json (publish/reportVideo.ts).
//
+// `--article <id>` in place of <report.json> attaches to an ARTICLE
+// (transcripts/reports/<id>/, release 26), its `video` written through the
+// article registry (patchArticle: locked, and refused if it adds a problem).
+//
// Exit 0 when attached, 1 when it could not be (the reason printed: too long
// to fit, not a report, ffmpeg's error), 2 for usage.
import { getPaths } from "../lib/paths";
+import { articleFile, patchArticle } from "../lib/report/registry";
import { AttachVideoError, attachReportVideo } from "../publish/reportVideo";
type Out = { log: (s: string) => void; error: (s: string) => void };
export async function attachVideoMain(
opts: {
- reportFile: string;
+ // report.json, or `article` — an article id.
+ reportFile?: string;
+ article?: string;
video: string;
poster?: string;
caption?: string;
@@ -24,9 +31,22 @@ export async function attachVideoMain(
out: Out = console,
): Promise<number> {
const paths = getPaths();
+ const article = opts.article;
+ const reportFile = article ? articleFile(paths, article) : opts.reportFile;
+ if (!reportFile) {
+ out.error("reports attach-video: give <report.json> or --article <id>");
+ return 2;
+ }
try {
const done = await attachReportVideo({
- reportFile: opts.reportFile,
+ reportFile,
+ ...(article
+ ? {
+ setVideo: async (video) => {
+ if (!(await patchArticle(article, { video }, paths))) throw new AttachVideoError(`no article "${article}"`);
+ },
+ }
+ : {}),
video: opts.video,
...(opts.poster !== undefined ? { poster: opts.poster } : {}),
...(opts.caption !== undefined ? { caption: opts.caption } : {}),
@@ -36,7 +56,7 @@ export async function attachVideoMain(
onLog: out.log,
});
out.log(
- `reports attach-video: ${opts.reportFile} video = ${JSON.stringify(done.video)} ` +
+ `reports attach-video: ${article ? `article ${article}` : reportFile} video = ${JSON.stringify(done.video)} ` +
`(${done.mode === "remux" ? "remuxed" : `encoded, ${done.attempts} pass(es)`}, ${(done.bytes / (1024 * 1024)).toFixed(2)} MiB)`,
);
return 0;
diff --git a/common/bin/reports-check.ts b/common/bin/reports-check.ts
@@ -19,6 +19,10 @@
// `en-orig` is not what the speaker said, and is reported as such, even
// though compose (which takes the best track) would pass it.
//
+// `--article <id>` checks one ARTICLE (release 26: transcripts/reports/<id>/,
+// published or a draft) as the homepage's compose would — any channel of the
+// corpus citable, the articles' prepared media.
+//
// Exit 0 when there is nothing to report, 1 with the list, 2 for usage (an
// unknown site, an unreadable file).
@@ -39,8 +43,9 @@ import {
formatComposeReportsProblems,
quoteDriftMessage,
readCitedRecord,
- resolveSiteReports,
+ resolveReports,
} from "../publish/composeReports";
+import { articlesWorkHost, siteReportHost, type ReportHost } from "../publish/reportHost";
type Out = { log: (s: string) => void; error: (s: string) => void };
@@ -48,7 +53,9 @@ type Out = { log: (s: string) => void; error: (s: string) => void };
export async function checkMain(
opts: {
- siteId: string;
+ // The site, or `article` — one article id.
+ siteId?: string;
+ article?: string;
reports?: string[];
allowMissingMedia?: boolean;
paths?: Paths;
@@ -57,20 +64,32 @@ export async function checkMain(
out: Out = console,
): Promise<number> {
const paths = opts.paths ?? getPaths();
- if (!listSiteIds(paths).includes(opts.siteId)) {
- out.error(`reports check: no site "${opts.siteId}" (sites/${opts.siteId}/site.json)`);
- return 2;
+ const who = opts.article ? `--article ${opts.article}` : String(opts.siteId);
+ let host: ReportHost;
+ if (opts.article) {
+ try {
+ host = await articlesWorkHost(paths, [opts.article]);
+ } catch (err) {
+ out.error(`reports check: ${(err as Error).message}`);
+ return 2;
+ }
+ host = { ...host, published: [opts.article] };
+ } else {
+ if (!opts.siteId || !listSiteIds(paths).includes(opts.siteId)) {
+ out.error(`reports check: no site "${opts.siteId}" (sites/${opts.siteId}/site.json)`);
+ return 2;
+ }
+ const site = getSite(opts.siteId, paths);
+ host = siteReportHost(paths, { ...site, reports: opts.reports ?? site.reports ?? [] });
}
- const site = getSite(opts.siteId, paths);
- const ids = opts.reports ?? site.reports ?? [];
- if (ids.length === 0) {
- out.log(`reports check ${opts.siteId}: the site publishes no reports — nothing to check.`);
+ if (host.published.length === 0) {
+ out.log(`reports check ${who}: the site publishes no reports — nothing to check.`);
return 0;
}
try {
- const resolved = await resolveSiteReports({
+ const resolved = await resolveReports({
paths,
- site: { ...site, reports: ids },
+ host,
allowMissingMedia: opts.allowMissingMedia === true,
...(opts.settings ? { settings: opts.settings } : {}),
});
@@ -87,15 +106,15 @@ export async function checkMain(
);
}
out.log(
- `reports check ${opts.siteId}: ${resolved.reports.length} report(s), ${resolved.moments.length} moment(s) — compose would pass.`,
+ `reports check ${who}: ${resolved.reports.length} report(s), ${resolved.moments.length} moment(s) — compose would pass.`,
);
return 0;
} catch (err) {
if (!(err instanceof ComposeReportsError)) {
- out.error(`reports check ${opts.siteId}: ${(err as Error).message}`);
+ out.error(`reports check ${who}: ${(err as Error).message}`);
return 1;
}
- out.error(`reports check ${opts.siteId}: ${err.problems.length} problem(s) — compose would fail:`);
+ out.error(`reports check ${who}: ${err.problems.length} problem(s) — compose would fail:`);
for (const line of formatComposeReportsProblems(err.problems)) out.error(` ${line}`);
return 1;
}
diff --git a/common/bin/reports-export.ts b/common/bin/reports-export.ts
@@ -8,7 +8,12 @@
// Exit 0 when every asked-for export was written (a PDF skipped for want of a
// browser is a note, not a problem); 1 when any problem is listed; 2 for bad
// arguments or a site or report that does not exist.
+//
+// `--article <id>` exports one ARTICLE (release 26) into
+// `.export-index/articles/report-exports/<id>/`, published or a draft.
+import { getPaths } from "../lib/paths";
+import { articlesWorkHost } from "../publish/reportHost";
import {
exportSiteReports,
formatReportExportProblems,
@@ -18,12 +23,19 @@ import {
type Out = { log: (s: string) => void; error: (s: string) => void };
export async function main(
- opts: Omit<ExportSiteReportsOptions, "onLog">,
+ opts: Omit<ExportSiteReportsOptions, "onLog"> & { article?: string },
out: Out = console,
): Promise<number> {
+ const { article, ...rest } = opts;
+ const who = article ? `--article ${article}` : opts.siteId;
let result;
try {
- result = await exportSiteReports({ ...opts, onLog: out.log });
+ const host = article ? await articlesWorkHost(opts.paths ?? getPaths(), [article]) : undefined;
+ result = await exportSiteReports({
+ ...rest,
+ ...(host ? { host, reportId: article } : {}),
+ onLog: out.log,
+ });
} catch (err) {
out.error(`reports export: ${(err as Error).message}`);
return opts.signal?.aborted ? 1 : 2;
@@ -32,7 +44,7 @@ export async function main(
for (const note of r.manifest.notes) out.log(` note: ${r.reportId}: ${note}`);
}
if (result.problems.length === 0) return 0;
- out.error(`reports export ${opts.siteId}: ${result.problems.length} problem(s):`);
+ out.error(`reports export ${who}: ${result.problems.length} problem(s):`);
for (const line of formatReportExportProblems(result.problems)) out.error(` ${line}`);
return 1;
}
diff --git a/common/bin/reports-prepare.ts b/common/bin/reports-prepare.ts
@@ -1,6 +1,8 @@
// `archilyzer reports prepare <siteId>` — cut and copy the evidence media of a
// site's published reports into `.export-index/sites/<siteId>/report-media/`,
-// before the site's build. The work is publish/reportMedia.ts's, the same the
+// before the site's build. `--article <id>` does the same for the ARTICLES
+// (release 26): every published article plus that one (a draft may be
+// readied before it is published), into `.export-index/articles/report-media/`. The work is publish/reportMedia.ts's, the same the
// editor's `reports-prepare` job runs; this file prints its log and its
// problems.
//
@@ -11,42 +13,59 @@
// 1 when any problem is listed (the manifest is written either way, problems
// included); 2 for a site that does not exist.
+import { getPaths } from "../lib/paths";
import { formatReportMediaProblems, prepareReportMedia } from "../publish/reportMedia";
import { exportAfterPrepare, formatReportExportProblems, type ExportSiteReportsOptions } from "../publish/reportExports";
+import { articlesWorkHost, type ReportHost } from "../publish/reportHost";
type Out = { log: (s: string) => void; error: (s: string) => void };
export async function main(
opts: {
- siteId: string;
+ // The site, or `article` — one article id: the articles' run.
+ siteId?: string;
+ article?: string;
signal?: AbortSignal;
// Passed to the export at the end (tests inject the PDF printer and zip).
exportOptions?: Partial<Pick<ExportSiteReportsOptions, "openPdfPrinter" | "zipBin" | "paths" | "settings">>;
},
out: Out = console,
): Promise<number> {
+ const who = opts.article ? `--article ${opts.article}` : opts.siteId;
let index;
+ let host: ReportHost | undefined;
try {
- index = await prepareReportMedia({ siteId: opts.siteId, signal: opts.signal, onLog: out.log });
+ host = opts.article ? await articlesWorkHost(opts.exportOptions?.paths ?? getPaths(), [opts.article]) : undefined;
+ index = await prepareReportMedia({
+ ...(host ? { host } : { siteId: opts.siteId }),
+ ...(opts.exportOptions?.paths ? { paths: opts.exportOptions.paths } : {}),
+ signal: opts.signal,
+ onLog: out.log,
+ });
} catch (err) {
out.error(`reports prepare: ${(err as Error).message}`);
return opts.signal?.aborted ? 1 : 2;
}
if (index.problems.length > 0) {
- out.error(`reports prepare ${opts.siteId}: ${index.problems.length} problem(s):`);
+ out.error(`reports prepare ${who}: ${index.problems.length} problem(s):`);
for (const line of formatReportMediaProblems(index.problems)) out.error(` ${line}`);
out.error("reports prepare: the reports were not exported (the evidence media is not complete).");
return 1;
}
let exported;
try {
- exported = await exportAfterPrepare(index, { siteId: opts.siteId, signal: opts.signal, onLog: out.log, ...opts.exportOptions });
+ exported = await exportAfterPrepare(index, {
+ ...(host ? { host } : { siteId: opts.siteId }),
+ signal: opts.signal,
+ onLog: out.log,
+ ...opts.exportOptions,
+ });
} catch (err) {
out.error(`reports prepare: export: ${(err as Error).message}`);
return 1;
}
if (!exported || exported.problems.length === 0) return 0;
- out.error(`reports prepare ${opts.siteId}: export: ${exported.problems.length} problem(s):`);
+ out.error(`reports prepare ${who}: export: ${exported.problems.length} problem(s):`);
for (const line of formatReportExportProblems(exported.problems)) out.error(` ${line}`);
return 1;
}
diff --git a/common/publish/reportExports.ts b/common/publish/reportExports.ts
@@ -90,24 +90,26 @@ import {
clipPath,
ComposeReportsError,
formatComposeReportsProblems,
- resolveSiteReports,
+ resolveReports,
type ResolvedSiteReports,
} from "./composeReports";
import {
REPORT_EXPORT_MANIFEST_FILENAME,
REPORT_EXPORT_MANIFEST_FORMAT,
REPORT_EXPORT_MANIFEST_VERSION,
- reportExportDir,
- reportExportsDir,
+ storeExportDir,
+ storeExportsDir,
sha256Hex,
type ReportExportFileEntry,
type ReportExportManifest,
} from "./reportExportFiles";
-import { siteReportDir, siteReportFile, type ReportMediaIndex } from "./reportMedia";
+import type { ReportMediaIndex } from "./reportMedia";
+import { storeReportDir, storeReportFile } from "../lib/report/store";
+import { siteReportHost, type ReportHost } from "./reportHost";
import {
commitReportRevision,
pendingRevision,
- reportHistoryGitDir,
+ storeHistoryGitDir,
revisionExports,
} from "./reportHistory";
@@ -137,9 +139,12 @@ export type PdfPrinter = {
export type OpenPdfPrinter = () => Promise<PdfPrinter | { missing: string }>;
export type ExportSiteReportsOptions = {
- siteId: string;
+ // The site whose pages to export, or `host` (./reportHost.ts) — the
+ // articles: articlesReportHost.
+ siteId?: string;
+ host?: ReportHost;
paths?: Paths;
- // One published report; default every one.
+ // One report the host publishes; default every one.
reportId?: string;
// Default: all of REPORT_EXPORT_FORMATS.
formats?: readonly ReportExportFormat[];
@@ -314,11 +319,11 @@ function within(base: string, rel: string): string | undefined {
return f.startsWith(b + path.sep) ? f : undefined;
}
-function reportFiles(paths: Paths, siteId: string, view: ReportPageView, resolved: ResolvedSiteReports): ReportFiles {
+function reportFiles(host: ReportHost, view: ReportPageView, resolved: ResolvedSiteReports): ReportFiles {
const own = `/reports/${view.id}/`;
return {
local: (p) => {
- if (p.startsWith(own)) return within(siteReportDir(paths, siteId, view.id), p.slice(own.length));
+ if (p.startsWith(own)) return within(storeReportDir(host, view.id), p.slice(own.length));
if (p.startsWith("/media/")) return within(resolved.cacheDir, p.slice("/media/".length));
return undefined;
},
@@ -442,7 +447,7 @@ async function buildEvidencePack(o: {
async function exportOneReport(o: {
paths: Paths;
- site: Site;
+ host: ReportHost;
report: Report;
view: ReportPageView;
resolved: ResolvedSiteReports;
@@ -453,16 +458,17 @@ async function exportOneReport(o: {
log: (line: string) => void;
signal?: AbortSignal;
}): Promise<{ result?: ReportExportResult; problems: ReportExportProblem[] }> {
- const { paths, site, report, view } = o;
- const reportJson = await readFile(siteReportFile(paths, site.siteId, report.id)).catch(() => null);
+ const { paths, host, report, view } = o;
+ const reportJson = await readFile(storeReportFile(host, report.id)).catch(() => null);
if (!reportJson) return { problems: [{ report: report.id, message: "its report.json cannot be read" }] };
return writeReportExports({
...o,
- dir: reportExportDir(paths, site.siteId, report.id),
+ site: { siteId: host.id, siteUrl: host.siteUrl, siteTitle: host.title, accent: host.accent },
+ dir: storeExportDir(host, report.id),
reportSha256: sha256Hex(reportJson),
- files: reportFiles(paths, site.siteId, view, o.resolved),
+ files: reportFiles(host, view, o.resolved),
ffmpegBin: paths.ffmpegBin,
- history: { gitDir: reportHistoryGitDir(paths, site.siteId, report.id), reportJson },
+ history: { gitDir: storeHistoryGitDir(host, report.id), reportJson },
});
}
@@ -686,20 +692,29 @@ export async function writeReportExports(o: {
export async function exportSiteReports(opts: ExportSiteReportsOptions): Promise<ExportSiteReportsResult> {
const paths = opts.paths ?? getPaths();
const log = opts.onLog ?? (() => {});
- const { siteId } = opts;
- if (!listSiteIds(paths).includes(siteId)) throw new Error(`no site "${siteId}" (no sites/${siteId}/site.json)`);
- const site = getSite(siteId, paths);
- const published = site.reports ?? [];
+ let host: ReportHost;
+ if (opts.host) {
+ host = opts.host;
+ } else {
+ const siteId = opts.siteId;
+ if (!siteId || !listSiteIds(paths).includes(siteId)) throw new Error(`no site "${siteId}" (no sites/${siteId}/site.json)`);
+ host = siteReportHost(paths, getSite(siteId, paths));
+ }
+ const published = host.published;
if (opts.reportId && !published.includes(opts.reportId)) {
- throw new Error(`site "${siteId}" does not publish a report "${opts.reportId}" (only a published report is exported)`);
+ throw new Error(
+ host.kind === "site"
+ ? `site "${host.id}" does not publish a report "${opts.reportId}" (only a published report is exported)`
+ : `article "${opts.reportId}" is not one this run exports`,
+ );
}
const formats = opts.formats ?? REPORT_EXPORT_FORMATS;
let resolved: ResolvedSiteReports;
try {
- resolved = await resolveSiteReports({
+ resolved = await resolveReports({
paths,
- site,
+ host,
allowMissingMedia: opts.allowMissingMedia,
settings: opts.settings,
now: opts.now,
@@ -717,8 +732,8 @@ export async function exportSiteReports(opts: ExportSiteReportsOptions): Promise
// A report no longer published keeps no exports.
if (!opts.reportId) {
- for (const name of await readdir(reportExportsDir(paths, siteId)).catch(() => [] as string[])) {
- if (!published.includes(name)) await rm(path.join(reportExportsDir(paths, siteId), name), { recursive: true, force: true });
+ for (const name of await readdir(storeExportsDir(host)).catch(() => [] as string[])) {
+ if (!published.includes(name)) await rm(path.join(storeExportsDir(host), name), { recursive: true, force: true });
}
}
@@ -728,7 +743,7 @@ export async function exportSiteReports(opts: ExportSiteReportsOptions): Promise
const now = opts.now?.() ?? new Date();
const exported: ReportExportResult[] = [];
const problems: ReportExportProblem[] = [];
- log(`${siteId}: exporting ${opts.reportId ?? `${resolved.reports.length} report(s)`} as ${formats.join(", ")}.`);
+ log(`${host.id}: exporting ${opts.reportId ?? `${resolved.reports.length} report(s)`} as ${formats.join(", ")}.`);
try {
for (let i = 0; i < resolved.reports.length; i++) {
const report = resolved.reports[i];
@@ -736,7 +751,7 @@ export async function exportSiteReports(opts: ExportSiteReportsOptions): Promise
if (opts.signal?.aborted) throw new Error("export cancelled");
const r = await exportOneReport({
paths,
- site,
+ host,
report,
view: resolved.views[i],
resolved,
diff --git a/common/publish/reportHost.ts b/common/publish/reportHost.ts
@@ -22,7 +22,7 @@
// A host is built once per run and carries no I/O of its own but the
// articles' corpus check (a channel directory exists).
-import { statSync } from "node:fs";
+import { existsSync, statSync } from "node:fs";
import path from "node:path";
import type { Paths } from "../lib/paths";
import { PROJECT_NAME, PROJECT_URL } from "../lib/project";
@@ -36,8 +36,8 @@ import {
type Site,
} from "../lib/siteSchema";
import { publishedArticleIds } from "../lib/report/registry";
-import type { ReportAudience } from "../lib/report/schema";
-import { articleReportStore, siteReportStore, type ReportStore } from "../lib/report/store";
+import { isReportId, type ReportAudience } from "../lib/report/schema";
+import { articleReportStore, siteReportStore, storeReportFile, type ReportStore } from "../lib/report/store";
export type ReportHost = ReportStore & {
// A history commit's author (./reportHistory.ts) and an export's heading.
@@ -138,3 +138,26 @@ export function hostCorpusLink(host: ReportHost, channel: string, params: Record
if (base === null) return undefined;
return `${base}/?${new URLSearchParams(params).toString()}`;
}
+
+// The articles as the tools that WORK on them see them — prepare, export,
+// check, the editor's Articles tab: every published article (the private
+// build's set, which holds the public one's), plus each id in `include` that
+// is not published yet (a draft being readied). Its prepared media and
+// exports therefore serve both homepage builds. An included id with no
+// report.json is refused.
+export async function articlesWorkHost(
+ paths: Pick<Paths, "articlesDir" | "exportIndexDir" | "channelsDir">,
+ include: readonly string[] = [],
+): Promise<ReportHost> {
+ for (const id of include) {
+ if (!isReportId(id)) throw new Error(`"${id}" is not an article id`);
+ if (!existsSync(storeReportFile(articleReportStore(paths), id))) {
+ throw new Error(`no article "${id}" (no reports/${id}/report.json)`);
+ }
+ }
+ const published = await publishedArticleIds("private", paths);
+ return articlesReportHost(paths, {
+ audience: "private",
+ published: [...published, ...include.filter((id) => !published.includes(id))],
+ });
+}
diff --git a/common/publish/reportVideo.ts b/common/publish/reportVideo.ts
@@ -144,6 +144,11 @@ export type AttachVideoOptions = {
ffprobeBin: string;
limitBytes?: number;
onLog?: (line: string) => void;
+ // Who writes `video` into report.json, once the files are in place; default
+ // a direct atomic rewrite of `reportFile`. An ARTICLE's goes through the
+ // article registry (lib/report/registry.ts patchArticle), which refuses a
+ // write that adds a problem.
+ setVideo?: (video: AttachedVideo["video"]) => Promise<void>;
};
export type AttachedVideo = {
@@ -244,8 +249,12 @@ export async function attachReportVideo(opts: AttachVideoOptions): Promise<Attac
const first = videoProblems[0] ?? parsed.problems[0];
throw new AttachVideoError(`report.json would not validate with the video: ${first ? `${first.path}: ${first.message}` : "?"}`);
}
- const tmpJson = `${opts.reportFile}.${process.pid}.tmp`;
- await writeFile(tmpJson, `${JSON.stringify(next, null, 2)}\n`);
- await rename(tmpJson, opts.reportFile);
+ if (opts.setVideo) {
+ await opts.setVideo(video);
+ } else {
+ const tmpJson = `${opts.reportFile}.${process.pid}.tmp`;
+ await writeFile(tmpJson, `${JSON.stringify(next, null, 2)}\n`);
+ await rename(tmpJson, opts.reportFile);
+ }
return { video, bytes, mode: plan.mode, attempts };
}