commit 3f75e01bffe2f0a81e406671b27abba49cfed8c9
parent ba8c08403fa5e07d893ddd693130bf0dabce7e99
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Sun, 11 Oct 2026 14:14:44 -0400
cli: archilyzer reports move-to-articles — release 26 A7's one-off move, a dry run by default
Every report a site lists, but the pages named by --keep <site>/<id> (D5),
moves to transcripts/reports/<id>/ whole (history-git and notes.json with
it), gets audience "private" (D2) and is published in reports/index.json in
the sites' order — all through the article registry, which publishes only a
sound article (one with problems moves as a draft, the plan says so) — and
leaves its site's list (patchSite). --drafts moves unlisted ones too. Every
refusal (an id two sites share, one reports/ already holds, a --keep that
names nothing, a report.json that does not parse) comes before anything
moves. A search-off site left empty is named, to be retired.
Written and tested on a temp corpus only; not run against the real one (the
orchestrator's A7, dry run first, with the operator's go).
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
4 files changed, 347 insertions(+), 3 deletions(-)
diff --git a/COMMANDS.md b/COMMANDS.md
@@ -34,6 +34,7 @@ Run from the repo root (in the container: `docker compose exec editor pnpm archi
| `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 move-to-articles` | `[--keep <site>/<id>,…] [--drafts] [--apply]` | ONE-OFF (release 26): every report a site lists, but the pages named by --keep, moved to transcripts/reports/ as an article — audience private, published in reports/index.json in the sites' order (a report with problems as a draft), dropped from its site; --drafts moves unlisted ones too. A dry run printing the plan unless --apply *(passthrough)* |
| `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
@@ -371,6 +371,8 @@ export const COMMANDS: Command[] = [
});
},
},
+ script(["reports", "move-to-articles"], "move-reports-to-articles.ts",
+ "[--keep <site>/<id>,…] [--drafts] [--apply] ONE-OFF (release 26): every report a site lists, but the pages named by --keep, moved to transcripts/reports/ as an article — audience private, published in reports/index.json in the sites' order (a report with problems as a draft), dropped from its site; --drafts moves unlisted ones too. A dry run printing the plan unless --apply"),
{
path: ["reports", "convert"],
usage:
@@ -782,9 +784,6 @@ 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(
@@ -812,6 +811,9 @@ async function articleReportFile(id: string): Promise<string> {
return articleFile(getPaths(), id);
}
+// 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.
function siteIdFrom(
positionals: string[],
env: NodeJS.ProcessEnv,
diff --git a/common/bin/move-reports-to-articles.test.ts b/common/bin/move-reports-to-articles.test.ts
@@ -0,0 +1,133 @@
+// `archilyzer reports move-to-articles` (release 26 A7's script), over a temp
+// corpus only: a dry run writes nothing; --apply moves each listed report
+// (history-git and notes.json with it) to reports/<id>/, private, published in
+// the sites' order (one with problems as a draft), off its site; a kept page
+// stays; refusals come before anything moves.
+//
+// Run with: pnpm --filter yt-dlp-transcript-common exec tsx --test bin/move-reports-to-articles.test.ts
+
+import { after, test } from "node:test";
+import assert from "node:assert/strict";
+import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
+import { tmpdir } from "node:os";
+import path from "node:path";
+
+const ROOT = mkdtempSync(path.join(tmpdir(), "move-to-articles-"));
+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"),
+});
+delete process.env.ARTICLES_DIR;
+after(() => rmSync(ROOT, { recursive: true, force: true }));
+
+const { getPaths } = await import("../lib/paths");
+const { main } = await import("./move-reports-to-articles");
+
+const paths = getPaths();
+const put = (file: string, value: unknown) => {
+ mkdirSync(path.dirname(file), { recursive: true });
+ writeFileSync(file, typeof value === "string" ? value : JSON.stringify(value, null, 2));
+};
+const readJson = <T = Record<string, unknown>>(file: string): T => JSON.parse(readFileSync(file, "utf8")) as T;
+const doc = (id: string, over: Record<string, unknown> = {}) => ({
+ format: "archilyzer-report",
+ version: 1,
+ id,
+ kind: "sweep",
+ title: `Fixture ${id}`,
+ sections: [{ id: "s", title: "S", body: "Words." }],
+ ...over,
+});
+function site(id: string, reports: string[], extra: Record<string, unknown> = {}) {
+ put(path.join(paths.sitesDir, id, "site.json"), {
+ siteId: id,
+ siteTitle: id,
+ groups: [{ id: "default", name: "All", selectedByDefault: true }],
+ defaultGroupId: "default",
+ channels: [],
+ reports,
+ ...extra,
+ });
+}
+const reportDir = (s: string, id: string) => path.join(paths.sitesDir, s, "reports", id);
+function capture() {
+ const lines: string[] = [];
+ return { text: () => lines.join("\n"), out: { log: (s: string) => lines.push(s), error: (s: string) => lines.push(s) } } as const;
+}
+
+// Two sites: a report-only private one with two listed reports (one with a
+// problem) and a draft; a full one with a page it keeps and one to move.
+site("site-a", ["alpha", "beta"], { search: false, audience: "private" });
+put(path.join(reportDir("site-a", "alpha"), "report.json"), doc("alpha"));
+put(path.join(reportDir("site-a", "alpha"), "notes.json"), { format: "umtool-notes", version: 1, notes: [] });
+put(path.join(reportDir("site-a", "alpha"), "history-git", "HEAD"), "ref: refs/heads/main\n");
+put(path.join(reportDir("site-a", "alpha"), "stills", "a.png"), "png");
+put(path.join(reportDir("site-a", "beta"), "report.json"), doc("beta", { summary: "see [x](cite:nobody)" }));
+put(path.join(reportDir("site-a", "draft-one"), "report.json"), doc("draft-one"));
+site("site-b", ["page-kept", "gamma"]);
+put(path.join(reportDir("site-b", "page-kept"), "report.json"), doc("page-kept"));
+put(path.join(reportDir("site-b", "gamma"), "report.json"), doc("gamma", { audience: "public" }));
+
+const snapshot = () => {
+ const out: string[] = [];
+ const walk = (d: string, rel: string) => {
+ for (const e of readdirSync(d, { withFileTypes: true })) {
+ const r = `${rel}/${e.name}`;
+ if (e.isDirectory()) walk(path.join(d, e.name), r);
+ else out.push(`${r}:${readFileSync(path.join(d, e.name), "utf8")}`);
+ }
+ };
+ walk(paths.transcriptsDir, "");
+ return out.sort().join("\n");
+};
+
+test("refusals before anything moves: a --keep that names nothing, an id reports/ already holds", async () => {
+ const before = snapshot();
+ const c = capture();
+ assert.equal(await main(["--keep", "site-b/nope", "--apply"], paths, c.out), 1);
+ assert.match(c.text(), /REFUSED --keep site-b\/nope: no site lists that report/);
+ put(path.join(paths.articlesDir, "gamma", "report.json"), doc("gamma"));
+ const c2 = capture();
+ assert.equal(await main(["--keep", "site-b/page-kept", "--apply"], paths, c2.out), 1);
+ assert.match(c2.text(), /REFUSED site-b\/gamma: reports\/gamma\/ already exists/);
+ rmSync(path.join(paths.articlesDir, "gamma"), { recursive: true });
+ assert.equal(snapshot(), before, "nothing written");
+});
+
+test("a dry run prints the plan and writes nothing", async () => {
+ const before = snapshot();
+ const c = capture();
+ assert.equal(await main(["--keep", "site-b/page-kept"], paths, c.out), 0);
+ const text = c.text();
+ assert.match(text, /move {3}site-a\/alpha → reports\/alpha\/ {2}published, audience private/);
+ assert.match(text, /move {3}site-a\/beta → reports\/beta\/ {2}draft \(1 problem\(s\) in report\.json\)/);
+ assert.match(text, /keep {3}site-b\/page-kept/);
+ assert.match(text, /retire site-a: search off and no reports left/);
+ assert.match(text, /3 to move \(2 published\), 1 kept, 0 refusal/);
+ assert.match(text, /dry run: nothing moved/);
+ assert.equal(snapshot(), before);
+});
+
+test("--apply: moved whole, private, published in the sites' order, off the site; the kept page stays", async () => {
+ const c = capture();
+ assert.equal(await main(["--keep", "site-b/page-kept", "--apply"], paths, c.out), 0, c.text());
+ const art = (id: string, ...p: string[]) => path.join(paths.articlesDir, id, ...p);
+ for (const f of ["report.json", "notes.json", "history-git/HEAD", "stills/a.png"]) assert.ok(existsSync(art("alpha", f)), f);
+ assert.equal(existsSync(reportDir("site-a", "alpha")), false);
+ assert.deepEqual(readJson(path.join(paths.articlesDir, "index.json")), { published: ["alpha", "gamma"] });
+ for (const id of ["alpha", "beta", "gamma"]) assert.equal(readJson(art(id, "report.json")).audience, "private", id);
+ assert.deepEqual(readJson(path.join(paths.sitesDir, "site-a", "site.json")).reports ?? [], []);
+ assert.deepEqual(readJson(path.join(paths.sitesDir, "site-b", "site.json")).reports, ["page-kept"]);
+ assert.ok(existsSync(path.join(reportDir("site-b", "page-kept"), "report.json")));
+ // The unlisted draft stays without --drafts.
+ assert.ok(existsSync(path.join(reportDir("site-a", "draft-one"), "report.json")));
+
+ // Again: nothing left to move but with --drafts the draft.
+ const again = capture();
+ assert.equal(await main(["--keep", "site-b/page-kept", "--drafts", "--apply"], paths, again.out), 0, again.text());
+ assert.match(again.text(), /moved site-a\/draft-one → reports\/draft-one\/ \(draft\)/);
+ assert.deepEqual(readJson(path.join(paths.articlesDir, "index.json")), { published: ["alpha", "gamma"] });
+});
diff --git a/common/bin/move-reports-to-articles.ts b/common/bin/move-reports-to-articles.ts
@@ -0,0 +1,208 @@
+// `archilyzer reports move-to-articles [--keep <site>/<id>,…] [--drafts] [--apply]`
+// — release 26 A7, ONE-OFF: a site's published reports become ARTICLES
+// (plans/reports-on-homepage.md, "A7 — move the data").
+//
+// DRY RUN BY DEFAULT: it prints the plan and writes nothing. `--apply` does it.
+//
+// For every site (by id), every report its site.json lists, in the site's
+// order — except each `--keep <site>/<id>` (a page the site keeps, D5):
+// 1. its directory `sites/<site>/reports/<id>/` moves to `reports/<id>/`
+// whole — report.json, stills, sources, video, history-git/ and
+// notes.json with it (a rename; a copy then a removal across devices);
+// 2. report.json gets `audience: "private"` (D2), through the article
+// registry (lib/report/registry.ts patchArticle);
+// 3. it is published in reports/index.json, after what is there, sites in
+// id order, each site's reports in its order — through the registry
+// (configureArticle), which publishes only a sound article: one with
+// problems is moved as a DRAFT, and the plan says so;
+// 4. the site's list drops it (patchSite).
+// `--drafts` moves the sites' unlisted report directories too, as drafts.
+//
+// REFUSED BEFORE ANYTHING MOVES: an id two sites both use, an id that
+// `reports/<id>/` already holds, a `--keep` that names no listed report, a
+// site whose reports cannot be read. Nothing is half-done by a refusal.
+//
+// Not moved: the staging a site's prepare and export wrote
+// (`.export-index/sites/<site>/report-{media,exports}/`) — run
+// `archilyzer reports prepare --article <id>` for the articles afterwards. A
+// search-off site left with no reports is named in the plan, to be retired.
+//
+// Stop the editor's report jobs first (a prepare reads these directories).
+// Exit 0 when the plan is clean (and applied, with --apply); 1 when it was
+// refused; 2 for usage.
+
+import { cp, mkdir, rename, rm, stat } from "node:fs/promises";
+import path from "node:path";
+import { getPaths, type Paths } from "../lib/paths";
+import { getSite, listSiteIds, patchSite, type Site } from "../lib/site";
+import { isCitedSite } from "../lib/siteSchema";
+import { readJsonFile } from "../lib/jsonFile-server";
+import { isReportId } from "../lib/report/schema";
+import { parseReport } from "../lib/report/validate";
+import { articleDir, configureArticle, patchArticle, readArticlesIndex } from "../lib/report/registry";
+import { listReportDirs, siteReportDir } from "../publish/reportMedia";
+import { parseArgv } from "./_parseFlags";
+import { runIfEntryPoint } from "./_cli";
+
+export type MoveItem = {
+ site: string;
+ id: string;
+ // Listed by its site (published there), or a draft (--drafts).
+ listed: boolean;
+ from: string;
+ to: string;
+ // Whether it will be published in reports/index.json (a sound, listed report).
+ publish: boolean;
+ // Why it moves as a draft although its site listed it.
+ draftBecause?: string;
+};
+
+export type MovePlan = {
+ moves: MoveItem[];
+ // Kept on their sites, as pages.
+ kept: string[];
+ // Search-off sites left with no reports.
+ emptied: string[];
+ refusals: string[];
+};
+
+// THE PLAN — read only.
+export async function planMove(
+ paths: Paths,
+ opts: { keep?: readonly string[]; drafts?: boolean } = {},
+): Promise<MovePlan> {
+ const keep = new Set(opts.keep ?? []);
+ const plan: MovePlan = { moves: [], kept: [], emptied: [], refusals: [] };
+ try {
+ await readArticlesIndex(paths);
+ } catch (e) {
+ plan.refusals.push((e as Error).message);
+ return plan;
+ }
+ const seen = new Map<string, string>();
+ const sites: Site[] = listSiteIds(paths).map((id) => getSite(id, paths));
+ const known = new Set<string>();
+ for (const site of sites) {
+ const listed = siteList(site);
+ for (const id of listed) known.add(`${site.siteId}/${id}`);
+ const drafts = opts.drafts ? (await listReportDirs(paths, site.siteId)).filter((d) => !listed.includes(d)) : [];
+ let left = 0;
+ for (const [id, isListed] of [...listed.map((id) => [id, true] as const), ...drafts.map((id) => [id, false] as const)]) {
+ const key = `${site.siteId}/${id}`;
+ if (keep.has(key)) {
+ plan.kept.push(key);
+ if (isListed) left++;
+ continue;
+ }
+ if (!isReportId(id)) {
+ plan.refusals.push(`${key}: "${id}" is not a report id`);
+ continue;
+ }
+ const from = siteReportDir(paths, site.siteId, id);
+ const to = articleDir(paths, id);
+ if (seen.has(id)) plan.refusals.push(`${key}: "${id}" is also ${seen.get(id)} — two articles cannot share an id`);
+ seen.set(id, key);
+ if (await exists(to)) plan.refusals.push(`${key}: reports/${id}/ already exists`);
+ const read = await readJsonFile(path.join(from, "report.json"));
+ if (!read.ok) {
+ plan.refusals.push(`${key}: its report.json is ${read.reason}`);
+ continue;
+ }
+ const parsed = parseReport(read.value, { id });
+ if (!parsed.ok) {
+ plan.refusals.push(`${key}: its report.json does not parse as a report (archilyzer reports check)`);
+ continue;
+ }
+ const sound = parsed.problems.length === 0;
+ plan.moves.push({
+ site: site.siteId,
+ id,
+ listed: isListed,
+ from,
+ to,
+ publish: isListed && sound,
+ ...(isListed && !sound ? { draftBecause: `${parsed.problems.length} problem(s) in report.json` } : {}),
+ });
+ }
+ if (isCitedSite(site) && listed.length > 0 && left === 0) plan.emptied.push(site.siteId);
+ }
+ for (const k of keep) if (!known.has(k)) plan.refusals.push(`--keep ${k}: no site lists that report`);
+ return plan;
+}
+
+// APPLY a clean plan: move, mark private, publish, drop from the site.
+export async function applyMove(paths: Paths, plan: MovePlan, log: (line: string) => void = console.log): Promise<void> {
+ if (plan.refusals.length > 0) throw new Error("the plan has refusals; nothing is moved");
+ for (const m of plan.moves) {
+ await moveDir(m.from, m.to);
+ await patchArticle(m.id, { audience: "private" }, paths);
+ if (m.publish) await configureArticle(m.id, { published: true }, paths);
+ if (m.listed) await patchSite(m.site, (cur) => ({ reports: siteList(cur).filter((x) => x !== m.id) }), paths);
+ log(`moved ${m.site}/${m.id} → reports/${m.id}/${m.publish ? " (published)" : " (draft)"}`);
+ }
+}
+
+export function formatPlan(plan: MovePlan): string[] {
+ const out: string[] = [];
+ for (const m of plan.moves) {
+ out.push(
+ `move ${m.site}/${m.id} → reports/${m.id}/ ${m.publish ? "published" : "draft"}${m.draftBecause ? ` (${m.draftBecause})` : ""}, audience private`,
+ );
+ }
+ for (const k of plan.kept) out.push(`keep ${k} (a page of its site)`);
+ for (const s of plan.emptied) out.push(`retire ${s}: search off and no reports left`);
+ for (const r of plan.refusals) out.push(`REFUSED ${r}`);
+ out.push(
+ `${plan.moves.length} to move (${plan.moves.filter((m) => m.publish).length} published), ${plan.kept.length} kept, ${plan.refusals.length} refusal(s).`,
+ );
+ return out;
+}
+
+// A site's published list. Release 26 A5 renames site.json `reports` to
+// `pages`; this reads either until the two branches meet.
+function siteList(site: Site): string[] {
+ return (site as Site & { pages?: string[] }).pages ?? site.reports ?? [];
+}
+
+const exists = async (p: string) => !!(await stat(p).catch(() => null));
+
+async function moveDir(from: string, to: string): Promise<void> {
+ await mkdir(path.dirname(to), { recursive: true });
+ try {
+ await rename(from, to);
+ } catch (e) {
+ if ((e as NodeJS.ErrnoException).code !== "EXDEV") throw e;
+ await cp(from, to, { recursive: true, errorOnExist: true, force: false, preserveTimestamps: true });
+ await rm(from, { recursive: true, force: true });
+ }
+}
+
+const USAGE = "usage: archilyzer reports move-to-articles [--keep <site>/<id>,…] [--drafts] [--apply]";
+
+export async function main(
+ argv: string[],
+ paths: Paths = getPaths(),
+ out: { log: (line: string) => void } = console,
+): Promise<number> {
+ const { positionals, flags } = parseArgv(argv, ["drafts", "apply", "help"]);
+ if (flags.help || positionals.length > 0) {
+ out.log(USAGE);
+ return flags.help ? 0 : 2;
+ }
+ const keep =
+ typeof flags.keep === "string"
+ ? flags.keep.split(",").map((k) => k.trim()).filter(Boolean)
+ : [];
+ const plan = await planMove(paths, { keep, drafts: flags.drafts === true });
+ for (const line of formatPlan(plan)) out.log(line);
+ if (plan.refusals.length > 0) return 1;
+ if (flags.apply !== true) {
+ out.log("dry run: nothing moved (--apply to move).");
+ return 0;
+ }
+ await applyMove(paths, plan, (l) => out.log(l));
+ out.log("done. Prepare and export the articles: archilyzer reports prepare --article <id>.");
+ return 0;
+}
+
+runIfEntryPoint(import.meta.url, () => main(process.argv.slice(2)));