commit 8fe9c6f1c65d2303ec267278847c375c5698162f
parent e5db73e9be670296cc9983e591dbd692c3fe2a25
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Sun, 11 Oct 2026 13:47:02 -0400
editor: pnpm ops articles-config — an article's audience and place, through the registry
Release 26 A2. POST /api/ops/articles-config {id, audience?, published?,
position?} calls configureArticle (lib/report/registry.ts): every refusal
before anything is written, the answer the article as saved. Usage in
`pnpm ops --help`, COMMANDS.md regenerated.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
4 files changed, 165 insertions(+), 0 deletions(-)
diff --git a/COMMANDS.md b/COMMANDS.md
@@ -82,6 +82,7 @@ Drives a running editor over HTTP (`/api/ops/*`, the same actions its pages run)
| `channel-priority` | channel-priority sets channels' priority, as the /channels deck's tier control does: {"slugs", "tier": "normal" \| "low" \| "paused"} sets the base tier; with "operation" (sync, transcription, download, digest, backfill) it pins that operation's tier, "tier": null clearing it back to the base; "preset": "sync-only" \| "clear" is the deck's two shortcuts and takes no tier. A manual change clears an automatic pause. | `pnpm ops channel-priority --json '{"slugs":["x"],"operation":"download","tier":"paused"}'` |
| `channel-config` | channel-config changes a channel as its Configure form does: {"slug"} and any of "patch" (form field names; "" clears one), "sites" (the WHOLE membership set: \[{"siteId", "groupId"? \| "newGroupName"?}\], \[\] = on no site; an unknown site id is refused), "excludeFromBuild" and "excludeFromCleanup" (set to the value given, not toggled). A VOD mirror's recorded date: "patch": {"recordedDateTitlePattern": "<regex with named groups year, month, day>"} (CHANNEL.md, recordedDate). | `pnpm ops channel-config --json '{"slug":"x","patch":{"downloadFilterExclude":"rerun"}}'`<br>`pnpm ops channel-config --json '{"slug":"x","sites":[{"siteId":"anilyzer"}]}'`<br>`pnpm ops channel-config --json '{"slug":"x","sites":[],"excludeFromBuild":true}'` |
| `site-config` | site-config sets two keys of a site as its form does: {"siteId"} and any of "citedChannels" (the WHOLE cited scope, channel slugs: what the site's reports may cite without publishing the channel; \[\] clears it; a slug the pool holds is dropped) and "publishAuto" ("off" \| "build" \| "preview" \| "production", the publish lane's policy; a deploying one needs a Pages project, a private site is clamped to "build"). Only those two keys; an unknown site or channel is refused before anything is written. Answers the saved values. | `pnpm ops site-config --json '{"siteId":"anilyzer","citedChannels":["critic-channel"]}'`<br>`pnpm ops site-config --json '{"siteId":"anilyzer","publishAuto":"build"}'` |
+| `articles-config` | articles-config sets an article's audience and its place in the published list (transcripts/reports/index.json), through the article registry: {"id"} and any of "audience" ("public" \| "private"; absent in report.json = private), "published" (true = listed, false = a draft) and "position" (its place in the list, 0 = first; publishing with none keeps a listed article where it is, else puts it last). Refused before anything is written: an unknown article, a position on a draft or out of range, publishing an article whose report.json has problems (listed). Answers the article as saved. | `pnpm ops articles-config --json '{"id":"demo-article","published":true}'`<br>`pnpm ops articles-config --json '{"id":"demo-article","audience":"public","position":0}'` |
| `create-channel` | create-channel is the New channel form: {"fields": {"name", "handling": "youtube"\|"transcribe", "url"?, "platform"?, "sourceKind"?, "postFetcher"?, "socialHandle"?, …}} with channel-config's patch keys; "slug"? (else derived from the name), "sites"? (absent = on no site). "fetchPlaylist", "fetchPostsNow" and "prioritizeDownload" are the form's checkboxes, OFF unless true; a job they start comes back as jobId(s), so --wait follows it. | `pnpm ops create-channel --json '{"fields":{"name":"Example (X)","handling":"transcribe","url":"https://x.com/example"}}'` |
| `rename-channel` | rename-channel moves a channel to a new slug, as Danger → Rename does: {"slug", "newSlug"}. Refused while the channel is busy (a job, a lane unit, media in transition) or when the new slug is taken. Old links break. | `pnpm ops rename-channel --json '{"slug":"old-slug","newSlug":"new-slug"}'` |
| `delete-channel` | delete-channel removes a channel's whole directory, as Danger → Delete does: {"slug", "confirm"} — "confirm" must repeat the slug. No undo outside the transcripts/ repo's own history. | `pnpm ops delete-channel --json '{"slug":"x","confirm":"x"}'` |
diff --git a/editor/app/api/ops/articles-config/route.test.ts b/editor/app/api/ops/articles-config/route.test.ts
@@ -0,0 +1,87 @@
+import test from "node:test";
+import assert from "node:assert/strict";
+import { mkdir, readFile, writeFile } from "node:fs/promises";
+import path from "node:path";
+import { setupOpsCorpus, callPost } from "../_testCorpus";
+
+// Run with:
+// pnpm -C editor exec tsx --test "app/api/ops/articles-config/route.test.ts"
+//
+// `articles-config` (release 26 A2): an article's audience and its place in
+// the published list (transcripts/reports/index.json), written through the
+// article registry. Every refusal comes before anything is written.
+
+const corpus = await setupOpsCorpus(null);
+const reports = path.join(corpus.transcripts, "reports");
+const article = (id: string, over: Record<string, unknown> = {}) => ({
+ format: "archilyzer-report",
+ version: 1,
+ id,
+ kind: "sweep",
+ title: `Article ${id}`,
+ sections: [{ id: "s1", title: "One", body: "Plain words." }],
+ ...over,
+});
+for (const id of ["first", "second"]) {
+ await mkdir(path.join(reports, id), { recursive: true });
+ await writeFile(path.join(reports, id, "report.json"), JSON.stringify(article(id), null, 2));
+}
+await mkdir(path.join(reports, "broken"), { recursive: true });
+await writeFile(
+ path.join(reports, "broken", "report.json"),
+ JSON.stringify(article("broken", { summary: "see [x](cite:nobody)" }), null, 2),
+);
+
+const { POST } = await import("./route");
+test.after(() => corpus.cleanup());
+
+const index = async () =>
+ JSON.parse(await readFile(path.join(reports, "index.json"), "utf8").catch(() => '{"published":[]}')) as {
+ published: string[];
+ };
+const reportJson = async (id: string) =>
+ JSON.parse(await readFile(path.join(reports, id, "report.json"), "utf8")) as Record<string, unknown>;
+
+test("publishes, places, makes public, moves and unpublishes — the answer is what was saved", async () => {
+ const a = await callPost(POST, { id: "first", published: true });
+ assert.equal(a.status, 200, JSON.stringify(a.body));
+ assert.deepEqual(a.body, { ok: true, id: "first", audience: "private", published: true, position: 0 });
+ const b = await callPost(POST, { id: "second", published: true, position: 0, audience: "public" });
+ assert.deepEqual(b.body, { ok: true, id: "second", audience: "public", published: true, position: 0 });
+ assert.deepEqual(await index(), { published: ["second", "first"] });
+ assert.equal((await reportJson("second")).audience, "public");
+
+ const moved = await callPost(POST, { id: "second", position: 1 });
+ assert.deepEqual(moved.body, { ok: true, id: "second", audience: "public", published: true, position: 1 });
+ assert.deepEqual(await index(), { published: ["first", "second"] });
+
+ const off = await callPost(POST, { id: "first", published: false });
+ assert.deepEqual(off.body, { ok: true, id: "first", audience: "private", published: false, position: null });
+ assert.deepEqual(await index(), { published: ["second"] });
+});
+
+test("refusals, each before anything is written", async () => {
+ const before = await index();
+ const brokenBefore = await reportJson("broken");
+ const cases: [Record<string, unknown>, RegExp][] = [
+ [{ id: "first", audience: "public", listed: true }, /unknown key\(s\): listed — this route accepts id, audience, published, position/],
+ [{ audience: "public" }, /"id" is required/],
+ [{ id: "Bad Id", published: true }, /not an article id/],
+ [{ id: "missing", published: true }, /no article "missing"/],
+ [{ id: "first", audience: "everyone" }, /"audience" must be one of public, private/],
+ [{ id: "first", published: "yes" }, /"published" must be a boolean/],
+ [{ id: "first", position: -1 }, /"position" must be a whole number, zero or above/],
+ [{ id: "first", position: 0 }, /"first" is a draft/],
+ [{ id: "second", position: 7 }, /position 7 is out of range/],
+ [{ id: "broken", published: true }, /cannot be published while report.json has problems:[\s\S]*summary/],
+ [{ id: "first" }, /nothing to change/],
+ ];
+ for (const [body, re] of cases) {
+ const r = await callPost(POST, body);
+ assert.equal(r.status, 400, JSON.stringify(body));
+ assert.match(r.body.error ?? "", re, JSON.stringify(body));
+ }
+ assert.deepEqual(await index(), before, "index.json untouched by any refusal");
+ assert.deepEqual(await reportJson("broken"), brokenBefore);
+ assert.equal((await callPost(POST, { id: "first", published: true }, {})).status, 401);
+});
diff --git a/editor/app/api/ops/articles-config/route.ts b/editor/app/api/ops/articles-config/route.ts
@@ -0,0 +1,62 @@
+import { NextResponse } from "next/server";
+import { getPaths } from "yt-dlp-transcript-common/lib/paths";
+import {
+ ArticleRegistryError,
+ configureArticle,
+ isReportAudience,
+ type ArticleConfigChange,
+} from "yt-dlp-transcript-common/lib/report/registry";
+import { REPORT_AUDIENCES } from "yt-dlp-transcript-common/lib/report/schema";
+import { OpsInputError, ops, optBool, optNonNegativeInt, reqString } from "../_lib";
+
+export const dynamic = "force-dynamic";
+
+// POST {
+// id: string, // the article: transcripts/reports/<id>/
+// audience?: "public" | "private", // report.json `audience`
+// published?: boolean, // in reports/index.json, or a draft
+// position?: number, // its place in the published list, 0 = first
+// }
+// — at least one of the three (release 26 A2). The article store's one writer
+// over HTTP: THROUGH configureArticle (lib/report/registry.ts), so locked,
+// validated and atomic, as a generator calling the registry is. Publishing
+// with no position keeps a published article where it is, else puts it last;
+// a position alone moves a published article.
+//
+// Every refusal is said before anything is written: an unknown key (ops()),
+// an id that is not one, an article that is not there, an audience that is
+// not one, a position out of range or on a draft, publishing an article whose
+// report.json has problems (each listed). The answer is the article as saved.
+export async function POST(request: Request) {
+ return ops(request, ["id", "audience", "published", "position"], async (body) => {
+ const id = reqString(body, "id");
+ const audience = body.audience;
+ if (audience !== undefined && !isReportAudience(audience)) {
+ throw new OpsInputError(`"audience" must be one of ${REPORT_AUDIENCES.join(", ")}`);
+ }
+ const published = optBool(body, "published");
+ const position = optNonNegativeInt(body, "position");
+ if (audience === undefined && published === undefined && position === undefined) {
+ throw new OpsInputError('nothing to change — give "audience", "published" or "position"');
+ }
+ const change: ArticleConfigChange = {
+ ...(audience !== undefined ? { audience } : {}),
+ ...(published !== undefined ? { published } : {}),
+ ...(position !== undefined ? { position } : {}),
+ };
+ let saved;
+ try {
+ saved = await configureArticle(id, change, getPaths());
+ } catch (err) {
+ if (err instanceof ArticleRegistryError) throw new OpsInputError(err.message);
+ throw err;
+ }
+ return NextResponse.json({
+ ok: true,
+ id: saved.id,
+ audience: saved.audience,
+ published: saved.published,
+ position: saved.position,
+ });
+ });
+}
diff --git a/scripts/archilyzer-ops.mjs b/scripts/archilyzer-ops.mjs
@@ -53,6 +53,8 @@
// pnpm ops channel-config --json '{"slug":"x","sites":[],"excludeFromBuild":true}'
// pnpm ops site-config --json '{"siteId":"anilyzer","citedChannels":["critic-channel"]}'
// pnpm ops site-config --json '{"siteId":"anilyzer","publishAuto":"build"}'
+// pnpm ops articles-config --json '{"id":"demo-article","published":true}'
+// pnpm ops articles-config --json '{"id":"demo-article","audience":"public","position":0}'
// pnpm ops create-channel --json '{"fields":{"name":"Example (X)","handling":"transcribe","url":"https://x.com/example"}}'
// pnpm ops rename-channel --json '{"slug":"old-slug","newSlug":"new-slug"}'
// pnpm ops delete-channel --json '{"slug":"x","confirm":"x"}'
@@ -240,6 +242,9 @@ const ACTIONS = [
// A site's cited-only channels and its publish policy ({siteId,
// citedChannels?, publishAuto?}), through the site form's own writer.
"site-config",
+ // An article's audience and its place in the published list ({id,
+ // audience?, published?, position?}), through the article registry.
+ "articles-config",
// The channel's lifecycle: the New channel form, and the channel page's
// Danger → Rename and Danger → Delete. Synchronous; no job.
"create-channel",
@@ -891,6 +896,16 @@ export function usage() {
' unknown site or channel is refused before anything is written. Answers',
' the saved values.',
"",
+ 'articles-config sets an article\'s audience and its place in the published',
+ ' list (transcripts/reports/index.json), through the article registry:',
+ ' {"id"} and any of "audience" ("public" | "private"; absent in report.json',
+ ' = private), "published" (true = listed, false = a draft) and "position"',
+ ' (its place in the list, 0 = first; publishing with none keeps a listed',
+ ' article where it is, else puts it last). Refused before anything is',
+ ' written: an unknown article, a position on a draft or out of range,',
+ ' publishing an article whose report.json has problems (listed). Answers',
+ ' the article as saved.',
+ "",
'create-channel is the New channel form: {"fields": {"name", "handling":',
' "youtube"|"transcribe", "url"?, "platform"?, "sourceKind"?, "postFetcher"?,',
' "socialHandle"?, …}} with channel-config\'s patch keys; "slug"? (else',