Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit c3bd5972a5c298d0ffd29036d8c111c51495dd12
parent aa4d0d2756b942913b9ee35499869d71e9a20bc9
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Sat, 10 Oct 2026 12:23:26 -0400

sites: the form's "Cited only" box, the list's cited count, rename and ops

A channel row outside the pool gets a "Cited only: <name>" box; the save action
reads the ticked slugs through the pure `citedChannelsFromForm` (a malformed
payload is refused, a pool slug dropped) and ticking Include clears the box.
`/sites` shows "· N cited". `renameChannel` rewrites `citedChannels` beside
`channels`, and `get sites` carries the key.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Diffstat:
MCOMMANDS.md | 3++-
Mcommon/controller/renameChannel.test.ts | 11+++++++++++
Mcommon/controller/renameChannel.ts | 13++++++++++---
Meditor/app/api/ops/_read.test.ts | 2++
Meditor/app/api/ops/sites/route.ts | 4+++-
Meditor/app/sites/actions.ts | 8++++++++
Meditor/app/sites/components/SiteForm.tsx | 35++++++++++++++++++++++++++++++++++-
Aeditor/app/sites/lib/citedChannelsFromForm.test.ts | 35+++++++++++++++++++++++++++++++++++
Aeditor/app/sites/lib/citedChannelsFromForm.ts | 36++++++++++++++++++++++++++++++++++++
Meditor/app/sites/page.tsx | 5++++-
Meditor/e2e/sites-crud.spec.ts | 43+++++++++++++++++++++++++++++++++++++++++++
Mscripts/archilyzer-ops.mjs | 3++-
12 files changed, 190 insertions(+), 8 deletions(-)

diff --git a/COMMANDS.md b/COMMANDS.md @@ -175,7 +175,8 @@ get settings [<key>] is settings.json as the editor reads it (migrated and defaulted; a secret is "<redacted>"), or one top-level key of it. get storage is /storage: each location, mounted or not, free space, tiers. get sites lists every site: id, title, siteUrl, Pages project, audience, - listed, search, publish policy, channels. (`get publish` is the status.) + listed, search, publish policy, channels, citedChannels. (`get publish` + is the status.) get workers, get auto-queue and get scheduler are /workers, the four lanes of /operations, and /operations/sync — the payloads those pages poll. get cleanup <slug> is one channel's /cleanup row: what each sweep would diff --git a/common/controller/renameChannel.test.ts b/common/controller/renameChannel.test.ts @@ -80,6 +80,12 @@ async function seedOld(paths: Paths): Promise<void> { path.join(paths.sitesDir, "mysite", "site.json"), JSON.stringify({ channels: [{ slug: "old" }] }), ); + // A site that cites the channel without publishing it (citedChannels). + await mkdir(path.join(paths.sitesDir, "citing"), { recursive: true }); + await writeFile( + path.join(paths.sitesDir, "citing", "site.json"), + JSON.stringify({ channels: [{ slug: "other" }], citedChannels: [{ slug: "keep" }, { slug: "old" }] }), + ); const state = await readSchedulerState(paths); state.channels["old"] = { ...emptyChannelSyncState(), consecutiveFailures: 5 }; @@ -114,6 +120,11 @@ test("renameChannel migrates every slug-keyed store", async () => { ["new"], ); + // The cited scope retargeted in place, the pool untouched. + const citing = getSite("citing", paths); + assert.deepEqual(citing.citedChannels, [{ slug: "keep" }, { slug: "new" }]); + assert.deepEqual(citing.channels.map((c) => c.slug), ["other"]); + // Scheduler backoff carried over under the new key. const state = await readSchedulerState(paths); assert.equal(state.channels["old"], undefined); diff --git a/common/controller/renameChannel.ts b/common/controller/renameChannel.ts @@ -246,15 +246,22 @@ export async function renameChannel( } } - // 5. Rewrite site memberships that reference the old slug. + // 5. Rewrite site memberships that reference the old slug: the pool + // (`channels`) and the cited scope (`citedChannels`). try { for (const siteId of listSiteIds(paths)) { const site = getSite(siteId, paths); - if (!site.channels.some((c) => c.slug === oldSlug)) continue; + const cited = site.citedChannels ?? []; + const inPool = site.channels.some((c) => c.slug === oldSlug); + const inCited = cited.some((c) => c.slug === oldSlug); + if (!inPool && !inCited) continue; const channels = site.channels.map((c) => c.slug === oldSlug ? { ...c, slug: newSlug } : c, ); - await writeSite({ ...site, channels }, paths); + const citedChannels = cited.map((c) => + c.slug === oldSlug ? { ...c, slug: newSlug } : c, + ); + await writeSite({ ...site, channels, citedChannels }, paths); } } catch (err) { warnings.push(`Site membership update failed: ${(err as Error).message}`); diff --git a/editor/app/api/ops/_read.test.ts b/editor/app/api/ops/_read.test.ts @@ -30,6 +30,7 @@ await corpus.writeSettings({ await corpus.writeSite("demo-site", { siteUrl: "https://demo.example", channels: [{ slug: "test-youtube", groupId: "default" }], + citedChannels: [{ slug: "demo-critic" }], }); await writeFile( path.join(corpus.transcripts, "channels", "test-youtube", "snapshot.json"), @@ -96,6 +97,7 @@ test("get sites lists each site from its site.json", async () => { search: true, publish: null, channels: ["test-youtube"], + citedChannels: ["demo-critic"], }, ]); }); diff --git a/editor/app/api/ops/sites/route.ts b/editor/app/api/ops/sites/route.ts @@ -9,7 +9,8 @@ export const dynamic = "force-dynamic"; // // Every site, one row each, from its site.json: id, title, public URL // (`siteUrl`), Pages project, audience, whether the family lists it, whether it -// publishes search, its publish policy and the channels it carries. The deep +// publishes search, its publish policy, the channels it carries (its pool) and +// the channels it cites without publishing (`citedChannels`). The deep // status of a site's builds and deploys is `get publish`. export async function GET(request: Request) { return readRoute(request, [], async () => ({ @@ -23,6 +24,7 @@ export async function GET(request: Request) { search: s.search !== false, publish: s.publish ?? null, channels: s.channels.map((c) => c.slug), + citedChannels: (s.citedChannels ?? []).map((c) => c.slug), })), })); } diff --git a/editor/app/sites/actions.ts b/editor/app/sites/actions.ts @@ -33,6 +33,7 @@ import { migrateToSites } from "yt-dlp-transcript-common/controller/migrateToSit import { socialLinksForSave } from "yt-dlp-transcript-common/lib/socialLinks"; import { formValues, type FormState } from "../lib/formState"; import { reportSiteKeysFromForm } from "./lib/reportSiteKeys"; +import { citedChannelsFromForm } from "./lib/citedChannelsFromForm"; // A failure carries what was submitted, so SiteForm keeps what was typed // (lib/formState.ts). @@ -256,6 +257,12 @@ export async function saveSiteAction( }; } const channels = parseSiteChannels(channelsInput); + // The cited scope: channels outside the pool this site's reports may cite + // without publishing them (lib/citedChannelsFromForm.ts). + const citedChannels = citedChannelsFromForm(formData, channels); + if (citedChannels === null) { + return { ok: false, error: "Cited channels payload is malformed", values }; + } const site: Site = { siteId, @@ -268,6 +275,7 @@ export async function saveSiteAction( groups, defaultGroupId, channels, + ...(citedChannels.length > 0 ? { citedChannels } : {}), ...(accent ? { accent } : {}), ...(cloudflareProject ? { cloudflareProject } : {}), ...(siteUrl ? { siteUrl } : {}), diff --git a/editor/app/sites/components/SiteForm.tsx b/editor/app/sites/components/SiteForm.tsx @@ -122,13 +122,32 @@ export function SiteForm({ initial, channels, allSites, isNew }: Props) { }), ); - const toggleMember = (slug: string, on: boolean) => + // The cited scope (site.json `citedChannels`): channels outside the pool + // this site's reports may cite without publishing them. A row in the pool + // is never cited-only, so ticking Include clears its box. + const [cited, setCited] = useState<Set<string>>( + () => new Set((initial.citedChannels ?? []).map((c) => c.slug)), + ); + const citedChannelsJson = JSON.stringify( + channels.filter((c) => cited.has(c.slug) && !members.has(c.slug)).map((c) => c.slug), + ); + const toggleCited = (slug: string, on: boolean) => + setCited((prev) => { + const next = new Set(prev); + if (on) next.add(slug); + else next.delete(slug); + return next; + }); + + const toggleMember = (slug: string, on: boolean) => { setMembers((prev) => { const next = new Map(prev); if (on) next.set(slug, prev.get(slug) ?? ""); else next.delete(slug); return next; }); + if (on) toggleCited(slug, false); + }; const setMemberGroup = (slug: string, groupId: string) => setMembers((prev) => { const next = new Map(prev); @@ -210,6 +229,7 @@ export function SiteForm({ initial, channels, allSites, isNew }: Props) { <input type="hidden" name="groupsJson" value={groupsJson} /> <input type="hidden" name="defaultGroupId" value={defaultGroupId} /> <input type="hidden" name="channelsJson" value={channelsJson} /> + <input type="hidden" name="citedChannelsJson" value={citedChannelsJson} /> <input type="hidden" name="relatedSitesJson" value={relatedSitesJson} /> {isNew ? ( @@ -539,6 +559,8 @@ export function SiteForm({ initial, channels, allSites, isNew }: Props) { <p className="text-xs text-muted-foreground"> Pick the channels this site exposes and the group each belongs to. Channels not checked here are excluded from this site&apos;s build. + &ldquo;Cited only&rdquo; lets this site&apos;s reports cite a channel + it does not expose: only the cited moments and their clips publish. </p> <div className="flex flex-col gap-1 max-h-96 overflow-y-auto"> {channels.length === 0 && ( @@ -563,6 +585,17 @@ export function SiteForm({ initial, channels, allSites, isNew }: Props) { <code className="text-xs text-muted-foreground">{c.slug}</code> </span> </label> + {!on && ( + <label className="flex items-center gap-1 text-xs text-muted-foreground shrink-0"> + <ControlledCheck + type="checkbox" + checked={cited.has(c.slug)} + onChange={(e) => toggleCited(c.slug, e.target.checked)} + aria-label={`Cited only: ${c.name || c.slug}`} + /> + cited only + </label> + )} {on && groupOptions.length > 0 && ( <ControlledSelect value={members.get(c.slug) ?? ""} diff --git a/editor/app/sites/lib/citedChannelsFromForm.test.ts b/editor/app/sites/lib/citedChannelsFromForm.test.ts @@ -0,0 +1,35 @@ +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { CITED_CHANNELS_FIELD, citedChannelsFromForm } from "./citedChannelsFromForm"; + +// Run with: pnpm -C editor exec tsx --test "app/**/*.test.ts" + +function form(value?: string): FormData { + const fd = new FormData(); + if (value !== undefined) fd.set(CITED_CHANNELS_FIELD, value); + return fd; +} + +test("the ticked slugs, trimmed, blanks and repeats dropped, in the order sent", () => { + assert.deepEqual(citedChannelsFromForm(form('["critic", " other ", "critic", "", 3]'), []), [ + { slug: "critic" }, + { slug: "other" }, + ]); + // A `{slug}` entry reads the same as a bare slug. + assert.deepEqual(citedChannelsFromForm(form('[{"slug":"critic"}]'), []), [{ slug: "critic" }]); +}); + +test("a channel the pool holds is never cited-only: the pool wins", () => { + assert.deepEqual( + citedChannelsFromForm(form('["pool", "critic"]'), [{ slug: "pool" }]), + [{ slug: "critic" }], + ); +}); + +test("no field is no cited scope; a malformed payload is refused, never read as none", () => { + assert.deepEqual(citedChannelsFromForm(form(), []), []); + assert.deepEqual(citedChannelsFromForm(form("[]"), []), []); + assert.equal(citedChannelsFromForm(form("{"), []), null); + assert.equal(citedChannelsFromForm(form('{"slug":"x"}'), []), null); + assert.equal(citedChannelsFromForm(form('"critic"'), []), null); +}); diff --git a/editor/app/sites/lib/citedChannelsFromForm.ts b/editor/app/sites/lib/citedChannelsFromForm.ts @@ -0,0 +1,36 @@ +// The site form's cited scope (site.json `citedChannels`, release 23), pure so +// the parse is tested without a server (saveSiteAction calls it). +// +// The form posts `citedChannelsJson`: the slugs whose "Cited only" box is +// ticked, a box shown only on a channel row outside the pool. A channel the +// pool holds is never cited-only (the pool wins — ticking "Include" clears the +// box, and the schema drops such a slug anyway). The Site is rebuilt from the +// form on save, so a missing field means no cited scope; a payload that is not +// a JSON array is refused (null), never read as "none". + +import { + parseSiteCitedChannels, + type SiteChannelMembership, + type SiteCitedChannel, +} from "yt-dlp-transcript-common/lib/site"; + +export const CITED_CHANNELS_FIELD = "citedChannelsJson"; + +export function citedChannelsFromForm( + formData: FormData, + pool: readonly Pick<SiteChannelMembership, "slug">[], +): SiteCitedChannel[] | null { + const raw = formData.get(CITED_CHANNELS_FIELD); + if (raw === null) return []; + let input: unknown; + try { + input = JSON.parse(String(raw)); + } catch { + return null; + } + if (!Array.isArray(input)) return null; + // The form sends bare slugs; a `{slug}` entry reads the same. + const entries = input.map((v) => (typeof v === "string" ? { slug: v } : v)); + const inPool = new Set(pool.map((c) => c.slug)); + return parseSiteCitedChannels(entries).filter((c) => !inPool.has(c.slug)); +} diff --git a/editor/app/sites/page.tsx b/editor/app/sites/page.tsx @@ -104,7 +104,10 @@ export default async function SitesPage() { <div className="font-medium">{s.siteTitle}</div> <div className="text-xs text-muted-foreground"> <code>{s.siteId}</code> · {s.channels.length} channel - {s.channels.length === 1 ? "" : "s"} · {s.groups.length} group + {s.channels.length === 1 ? "" : "s"} + {s.citedChannels?.length ? ` · ${s.citedChannels.length} cited` : ""} + {" · "} + {s.groups.length} group {s.groups.length === 1 ? "" : "s"} {s.cloudflareProject ? ` · ${s.cloudflareProject}` : ""} </div> diff --git a/editor/e2e/sites-crud.spec.ts b/editor/e2e/sites-crud.spec.ts @@ -47,6 +47,49 @@ test("create a site with channel membership via the UI", async ({ page }) => { expect(site.channels.map((c) => c.slug)).toContain("test-youtube"); }); +// The cited scope (site.json `citedChannels`, release 23): a channel outside +// the pool this site's reports may cite without publishing it. Its box is on +// rows outside the pool only, and ticking Include clears it (the pool wins). +test("a cited-only channel saves to citedChannels, shows on the list, and Include clears it", async ({ + page, +}) => { + await resetData("one-youtube-channel-with-data"); + type CitedSiteFile = SiteFile & { citedChannels?: { slug: string }[] }; + const file = "test-transcripts/sites/citing/site.json"; + const include = page.getByRole("checkbox", { name: /include test youtube channel/i }); + const citedOnly = page.getByRole("checkbox", { name: "Cited only: Test YouTube Channel" }); + const save = async (name: RegExp) => { + await page.getByRole("button", { name }).click(); + await expect(page.getByRole("status").filter({ hasText: "Saved" })).toBeVisible(); + }; + + await page.goto("/sites/new"); + await page.getByLabel(/site id/i).fill("citing"); + await page.getByLabel(/site title/i).fill("Citing"); + await page.getByLabel(/header title/i).fill("Citing"); + await citedOnly.check(); + await save(/create site/i); + await expect(async () => { + const site = await readJson<CitedSiteFile>(file); + expect(site.channels).toEqual([]); + expect(site.citedChannels).toEqual([{ slug: "test-youtube" }]); + }).toPass({ timeout: 10_000 }); + + await page.goto("/sites"); + await expect(page.getByRole("link", { name: /Citing/ })).toContainText("0 channels · 1 cited"); + + await page.goto("/sites/citing"); + await expect(citedOnly).toBeChecked(); + await include.check(); + await expect(citedOnly).toHaveCount(0); + await save(/save site/i); + await expect(async () => { + const site = await readJson<CitedSiteFile>(file); + expect(site.channels.map((c) => c.slug)).toEqual(["test-youtube"]); + expect("citedChannels" in site).toBe(false); + }).toPass({ timeout: 10_000 }); +}); + test("list shows configured sites and edit updates branding", async ({ page, }) => { diff --git a/scripts/archilyzer-ops.mjs b/scripts/archilyzer-ops.mjs @@ -688,7 +688,8 @@ export function usage() { " defaulted; a secret is \"<redacted>\"), or one top-level key of it.", "get storage is /storage: each location, mounted or not, free space, tiers.", "get sites lists every site: id, title, siteUrl, Pages project, audience,", - " listed, search, publish policy, channels. (`get publish` is the status.)", + " listed, search, publish policy, channels, citedChannels. (`get publish`", + " is the status.)", "get workers, get auto-queue and get scheduler are /workers, the four lanes", " of /operations, and /operations/sync — the payloads those pages poll.", "get cleanup <slug> is one channel's /cleanup row: what each sweep would",