commit f883c93a0e0fbde96edf72ad4582ab05b3afe1fc
parent c68f1fe33d2a24ef909e4bb99b7fbf8353aad486
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Sat, 10 Oct 2026 17:28:42 -0400
editor, scripts: `pnpm ops site-config` — a site's cited-only channels and publish policy (release 24 H6)
POST /api/ops/site-config {siteId, citedChannels?: [slug…], publishAuto?:
off|build|preview|production}, behind the token like channel-config,
written through patchSite and so through writeSite, the site form's own
validation: a pooled slug is dropped, a deploying policy with no Pages
project is refused, a private site is clamped to build. Unknown keys, an
unknown site, a slug that is not a channel and a bad policy are refused
before anything is written; the answer is the saved values. The ops CLI
action, its help paragraph and header examples; COMMANDS.md regenerated;
an OPERATING.md recipe; the changelog.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
6 files changed, 227 insertions(+), 0 deletions(-)
diff --git a/COMMANDS.md b/COMMANDS.md
@@ -80,6 +80,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"}'` |
| `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/OPERATING.md b/OPERATING.md
@@ -167,6 +167,9 @@ pnpm archilyzer publish build example-site --out /srv/example-private
citation whose media is not prepared yet passes with `--allow-missing-media` (`"allowMissingMedia": true` on the
ops `build` verb).
- The publish lane: `pnpm ops lane --json '{"lane":"publish","action":"start"}'` (`"held": true` pauses it).
+- A site's policy, and the channels its reports may cite without publishing them, without the site form:
+ `pnpm ops site-config --json '{"siteId":"example-site","publishAuto":"build","citedChannels":["example-critic"]}'`
+ (`citedChannels` is the whole cited scope; `[]` clears it).
- Details, policies and the hub and homepage: [PUBLISH.md](PUBLISH.md).
## Research with the MCP
diff --git a/editor/CHANGELOG.md b/editor/CHANGELOG.md
@@ -1,6 +1,7 @@
# Changelog
## [Unreleased]
+- **`pnpm ops site-config` sets a site's cited-only channels and publish policy.** `{"siteId", "citedChannels"?: [slug…], "publishAuto"?: "off" | "build" | "preview" | "production"}` (`POST /api/ops/site-config`) writes through the site form's own validation: a slug the pool holds is dropped, a deploying policy without a Pages project is refused, and a private site is clamped to `build`. An unknown site, channel or key is refused before anything is written. The answer is the saved values.
- **"Saved." on /sites comes at once.** Saving the hub config or a site, deleting a site and migrating settings into a first site sometimes waited up to ~6 s for the page's refresh before saying anything, the button stuck on "Saving…". They now save without making the page refresh wait, show what was saved straight away, and then refresh the page.
- **A channel taken off a site, or moved to its cited scope, is withdrawn at the edge.** The next build of the site replaces every `transcripts/`, `subs/`, `posts/` and `digests/` path its last build served for that channel with an empty file of the same shape, served no-store (the way withheld X posts already are), and keeps doing so while the channel stays out. The channel's cited moments and clips still publish. A site's deploy now reads its withdrawn paths back in its live check, as the hub's does.
- **Persisting a Wayback or archive.org record no longer undoes its title and date.** A re-download that rewrites `metadata.info.json` keeps the title, upload date and other fields `archilyzer wayback refresh --titles`, `archive-org refresh` or the feed backfill set, when the source only has its placeholder for them; a value the source genuinely changed still lands. A record a persist already reverted gets them back on its next download.
diff --git a/editor/app/api/ops/site-config/route.test.ts b/editor/app/api/ops/site-config/route.test.ts
@@ -0,0 +1,100 @@
+import test from "node:test";
+import assert from "node:assert/strict";
+import { readFile } 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/site-config/route.test.ts"
+//
+// `site-config` (release 24 H6): a site's cited-only channels and its publish
+// policy, written through patchSite — so through writeSite, as the site form's
+// save is. Every refusal comes before anything is written.
+
+const corpus = await setupOpsCorpus(null);
+for (const slug of ["pooled", "critic", "other-critic"]) {
+ await corpus.writeChannelConfig(slug, { url: `https://www.youtube.com/@${slug}` });
+}
+const pool = { channels: [{ slug: "pooled", groupId: "default" }] };
+await corpus.writeSite("citing", pool);
+await corpus.writeSite("mine", { ...pool, audience: "private" });
+await corpus.writeSite("shipped", { ...pool, cloudflareProject: "shipped-pages" });
+
+const { POST } = await import("./route");
+test.after(() => corpus.cleanup());
+
+const siteFile = async (id: string) =>
+ JSON.parse(await readFile(path.join(corpus.transcripts, "sites", id, "site.json"), "utf8")) as Record<
+ string,
+ unknown
+ >;
+
+test("sets the cited scope, drops a pooled slug as the parser does, and [] clears it", async () => {
+ const set = await callPost(POST, {
+ siteId: "citing",
+ citedChannels: ["critic", "pooled", "other-critic", "critic", " "],
+ });
+ assert.equal(set.status, 200, JSON.stringify(set.body));
+ assert.deepEqual(set.body, {
+ ok: true,
+ siteId: "citing",
+ citedChannels: ["critic", "other-critic"],
+ publishAuto: "off",
+ });
+ const file = await siteFile("citing");
+ assert.deepEqual(file.citedChannels, [{ slug: "critic" }, { slug: "other-critic" }]);
+ assert.deepEqual(file.channels, [{ slug: "pooled", groupId: "default" }], "the pool is untouched");
+
+ const cleared = await callPost(POST, { siteId: "citing", citedChannels: [] });
+ assert.equal(cleared.status, 200, JSON.stringify(cleared.body));
+ assert.deepEqual(cleared.body.citedChannels, []);
+ assert.equal("citedChannels" in (await siteFile("citing")), false, "an empty scope is not written");
+});
+
+test("publishAuto round-trips; a deploying policy needs a Pages project; a private site is clamped to build", async () => {
+ for (const policy of ["build", "preview", "production", "off"]) {
+ const r = await callPost(POST, { siteId: "shipped", publishAuto: policy });
+ assert.equal(r.status, 200, JSON.stringify(r.body));
+ assert.equal(r.body.publishAuto, policy);
+ const file = await siteFile("shipped");
+ if (policy === "off") assert.equal("publish" in file, false);
+ else assert.deepEqual(file.publish, { auto: policy });
+ }
+ const before = await siteFile("citing");
+ const refused = await callPost(POST, { siteId: "citing", publishAuto: "production" });
+ assert.equal(refused.status, 400);
+ assert.match(refused.body.error ?? "", /publish\.auto "production" deploys the site, and it has no cloudflareProject/);
+ assert.deepEqual(await siteFile("citing"), before, "nothing written");
+
+ // A private site is never deployed: "production" is saved as "build".
+ const clamped = await callPost(POST, { siteId: "mine", publishAuto: "production" });
+ assert.equal(clamped.status, 200, JSON.stringify(clamped.body));
+ assert.equal(clamped.body.publishAuto, "build");
+ assert.deepEqual((await siteFile("mine")).publish, { auto: "build" });
+ // Both keys in one call.
+ const both = await callPost(POST, { siteId: "shipped", citedChannels: ["critic"], publishAuto: "build" });
+ assert.deepEqual(both.body, { ok: true, siteId: "shipped", citedChannels: ["critic"], publishAuto: "build" });
+});
+
+test("refusals, each before anything is written: keys, site, slugs, policy, nothing to change", async () => {
+ const before = await siteFile("citing");
+ const cases: [Record<string, unknown>, RegExp][] = [
+ [{ siteId: "citing", channels: ["critic"] }, /unknown key\(s\): channels — this route accepts siteId, citedChannels, publishAuto/],
+ [{ siteId: "citing", citedChannels: ["critic"], listed: false }, /unknown key\(s\): listed/],
+ [{ siteId: "no-such-site", citedChannels: ["critic"] }, /Site "no-such-site" not found/],
+ [{ siteId: "Bad Id", publishAuto: "build" }, /not a valid site id/],
+ [{ citedChannels: ["critic"] }, /"siteId" is required/],
+ [{ siteId: "citing", citedChannels: ["critic", "no-such-channel"] }, /not a channel: "no-such-channel"/],
+ [{ siteId: "citing", citedChannels: ["../etc"] }, /not a valid channel slug/],
+ [{ siteId: "citing", citedChannels: "critic" }, /"citedChannels" must be an array of channel slugs/],
+ [{ siteId: "citing", publishAuto: "sometimes" }, /"publishAuto" must be one of off, build, preview, production/],
+ [{ siteId: "citing" }, /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 siteFile("citing"), before, "nothing written by any refusal");
+ assert.equal((await callPost(POST, { siteId: "citing", publishAuto: "build" }, {})).status, 401);
+});
diff --git a/editor/app/api/ops/site-config/route.ts b/editor/app/api/ops/site-config/route.ts
@@ -0,0 +1,108 @@
+import { existsSync } from "node:fs";
+import { NextResponse } from "next/server";
+import { getPaths } from "yt-dlp-transcript-common/lib/paths";
+import {
+ isValidSiteId,
+ patchSite,
+ siteConfigFile,
+ sitePublishPolicy,
+ type Site,
+} from "yt-dlp-transcript-common/lib/site";
+import { PUBLISH_POLICIES, type PublishPolicy } from "yt-dlp-transcript-common/lib/settingsSchema";
+import { channelExists, isValidChannelSlug } from "yt-dlp-transcript-common/controller/channels";
+import { OpsInputError, ops, reqString } from "../_lib";
+
+export const dynamic = "force-dynamic";
+
+// POST {
+// siteId: string,
+// citedChannels?: string[], // the WHOLE cited scope; [] clears it
+// publishAuto?: "off" | "build" | "preview" | "production",
+// }
+// — at least one of the two. Only these keys for now (release 24 H6): a
+// session sets a site's cited-only channels, or its publish policy, without
+// the editor UI.
+//
+// THROUGH patchSite, so through writeSite: the same validation and the same
+// on-disk shape the site form's save gets. A slug the pool already holds is
+// dropped from `citedChannels`, as the parser drops it; a deploying policy
+// (`preview`, `production`) on a site with no Pages project is refused; a
+// private site's policy is clamped to `build`. The answer is what was saved.
+//
+// Every refusal is said before anything is written: an unknown key (ops()),
+// an unknown site, a slug that is not a channel, a policy that is not one.
+export async function POST(request: Request) {
+ return ops(request, ["siteId", "citedChannels", "publishAuto"], async (body) => {
+ const siteId = reqString(body, "siteId");
+ if (!isValidSiteId(siteId)) {
+ throw new OpsInputError(`"${siteId}" is not a valid site id (lowercase letters, numbers and hyphens)`);
+ }
+ const cited = readCited(body.citedChannels);
+ const publishAuto = readPolicy(body.publishAuto);
+ if (cited === undefined && publishAuto === undefined) {
+ throw new OpsInputError('nothing to change — give "citedChannels" or "publishAuto"');
+ }
+ const paths = getPaths();
+ if (!existsSync(siteConfigFile(paths, siteId))) {
+ throw new OpsInputError(`Site "${siteId}" not found`);
+ }
+ if (cited !== undefined) {
+ const missing: string[] = [];
+ for (const slug of cited) {
+ if (!(await channelExists(paths, slug))) missing.push(slug);
+ }
+ if (missing.length > 0) {
+ throw new OpsInputError(
+ `not a channel: ${missing.map((s) => `"${s}"`).join(", ")} — "citedChannels" names channel slugs`,
+ );
+ }
+ }
+ const changes: Partial<Omit<Site, "siteId">> = {};
+ if (cited !== undefined) changes.citedChannels = cited.map((slug) => ({ slug }));
+ if (publishAuto !== undefined) {
+ changes.publish = publishAuto === "off" ? undefined : { auto: publishAuto };
+ }
+ let saved: Site | null;
+ try {
+ saved = await patchSite(siteId, changes, paths);
+ } catch (err) {
+ // writeSite's refusals (a deploying policy with no Pages project) are
+ // the request's fault, said in its words.
+ throw new OpsInputError((err as Error).message);
+ }
+ if (!saved) throw new OpsInputError(`Site "${siteId}" not found`);
+ return NextResponse.json({
+ ok: true,
+ siteId,
+ citedChannels: (saved.citedChannels ?? []).map((c) => c.slug),
+ publishAuto: sitePublishPolicy(saved),
+ });
+ });
+}
+
+// `citedChannels`: absent, or an array of channel slugs (blank and repeated
+// entries are the parser's to drop; anything else is refused here).
+function readCited(raw: unknown): string[] | undefined {
+ if (raw === undefined) return undefined;
+ if (!Array.isArray(raw) || raw.some((s) => typeof s !== "string")) {
+ throw new OpsInputError('"citedChannels" must be an array of channel slugs');
+ }
+ const slugs = [...new Set((raw as string[]).map((s) => s.trim()).filter(Boolean))];
+ // A slug reaches a path.join under channelsDir: never one that traverses.
+ for (const slug of slugs) {
+ if (!isValidChannelSlug(slug)) {
+ throw new OpsInputError(
+ `"${slug}" is not a valid channel slug (letters, digits, ".", "_", "-"; must start with a letter or digit)`,
+ );
+ }
+ }
+ return slugs;
+}
+
+function readPolicy(raw: unknown): PublishPolicy | undefined {
+ if (raw === undefined) return undefined;
+ if (typeof raw !== "string" || !(PUBLISH_POLICIES as readonly string[]).includes(raw)) {
+ throw new OpsInputError(`"publishAuto" must be one of ${PUBLISH_POLICIES.join(", ")}`);
+ }
+ return raw as PublishPolicy;
+}
diff --git a/scripts/archilyzer-ops.mjs b/scripts/archilyzer-ops.mjs
@@ -51,6 +51,8 @@
// pnpm ops channel-config --json '{"slug":"x","patch":{"downloadFilterExclude":"rerun"}}'
// pnpm ops channel-config --json '{"slug":"x","sites":[{"siteId":"anilyzer"}]}'
// 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 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"}'
@@ -233,6 +235,9 @@ export const JOB_VERBS = [
const ACTIONS = [
"channel-priority",
"channel-config",
+ // A site's cited-only channels and its publish policy ({siteId,
+ // citedChannels?, publishAuto?}), through the site form's own writer.
+ "site-config",
// The channel's lifecycle: the New channel form, and the channel page's
// Danger → Rename and Danger → Delete. Synchronous; no job.
"create-channel",
@@ -866,6 +871,15 @@ export function usage() {
' recorded date: "patch": {"recordedDateTitlePattern": "<regex with named',
' groups year, month, day>"} (CHANNEL.md, recordedDate).',
"",
+ '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.',
+ "",
'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',