Archilyzer · Source

archilyzer

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

commit 2be56688c02771648c2e346a049e7266fe75da3c
parent aad26e6376302f43224a8009f9ee5c14c4e1f6a0
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Mon,  9 Nov 2026 19:45:45 -0500

channels: deleting a channel takes it off every site that names it

9 Nov: deleting mooler left it in efapalyzer's site.json, fixed by hand.
deleteChannelFromForm (Danger -> Delete, pnpm ops delete-channel) now rewrites
every site whose pool or cited scope names the slug, through writeSite
(common/controller/siteMemberships.ts dropChannelFromSites), as a rename
re-points them; the ops answer names them in sitesUpdated, a refused site
write is a warnings line. A site not naming it is not written.

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

Diffstat:
MCOMMANDS.md | 2+-
MOPERATING.md | 3++-
Acommon/controller/siteMemberships.test.ts | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Acommon/controller/siteMemberships.ts | 41+++++++++++++++++++++++++++++++++++++++++
Meditor/CHANGELOG.md | 1+
Meditor/app/api/ops/delete-channel/route.ts | 12+++++++++++-
Meditor/app/channels/actions.ts | 18+++++++++++++++++-
Meditor/e2e/ops-api.spec.ts | 10++++++++++
Mscripts/archilyzer-ops.mjs | 6++++--
9 files changed, 143 insertions(+), 6 deletions(-)

diff --git a/COMMANDS.md b/COMMANDS.md @@ -133,7 +133,7 @@ Drives a running editor over HTTP (`/api/ops/*`, the same actions its pages run) | `delete-site` | delete-site deletes a site, plan first: {"id"}, "dryRun"? (answer the plan — every path with its size, what is kept and why — and write nothing), "force"? It removes sites/&lt;id&gt;/ (site.json, its pool and pages, tags, charts, its reports), its publish state and last bundle (export/.export-builds/&lt;id&gt;/) and compose's staging for it (export/.export-index/sites/&lt;id&gt;/). Channel data is never touched; the Pages project, what was deployed and a deployed hub are kept (a delete does not undeploy). Refused with the plan (409) unless "force": a deploy target (cloudflareProject), a deploy in its publish state, reports of its own. Refused, force or not: no such site (404), a site dir that is a link, a publish stage running. | `pnpm ops delete-site --json '{"id":"demo-site","dryRun":true}'` | | `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. An X search page URL (x.com/search?q=…), or "platform": "x-search" with "xSearchQuery" (and "xSearchSince"?, "xSearchUntil"?, "xSearchWindowMonths"?, "xSearchLang"?), makes an X SEARCH channel: the matching posts from any account, walked by fetch-posts in search windows; never on a site (sites refused). | `pnpm ops create-channel --json '{"fields":{"name":"Example (X)","handling":"transcribe","url":"https://x.com/example"}}'`<br>`pnpm ops create-channel --json '{"fields":{"name":"Demo search","handling":"transcribe","url":"https://x.com/search?q=%22demo%20phrase%22"}}'` | | `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"}'` | +| `delete-channel` | delete-channel removes a channel's whole directory, as Danger → Delete does: {"slug", "confirm"} — "confirm" must repeat the slug. Every site whose pool or cited scope names it is rewritten without it (answered as "sitesUpdated"; a site whose write is refused is a "warnings" line). No undo outside the transcripts/ repo's own history. | `pnpm ops delete-channel --json '{"slug":"x","confirm":"x"}'` | | `metadata-scan` | metadata-scan reads every listed video's title, date and description into the channel's scan file, fetching no media: {"slug"}. Not held by the download pause and needs no disk floor; one request per video, so it respects the platform's cooldown and records one when pushed back. | `pnpm ops metadata-scan --json '{"slug":"the-quartering"}'` | | `refresh-metadata` | refresh-metadata re-reads ONE video's metadata.info.json from its source (no subtitles, no media) on the platform's queue: {"slug", "id"}. The job's log ends with what the source now says — live\_status, formats, audio-only formats and whether any is non-fragmented, English captions, the keys that changed. An id with no data/&lt;id&gt;/ is refused (a refresh re-reads a video already archived), as are archive.org and Wayback records. | `pnpm ops refresh-metadata --json '{"slug":"the-quartering","id":"<videoId>"}' --wait` | | `browser-lookup` | browser-lookup reads Odysee records from their pages in a headless browser, for when yt-dlp's lookup answers 429: {"slug", "ids": \[...\]} (at most 50) writes each record (none yet: whole, `_source: "browser"`) or completes it (the keys it lacks, and the one media file the page's player asked for); "listing": true (with "scrolls", default 5, at most 40) adds the uploads the channel page shows to the playlist, newest first, through the title match filter. One page a minute; not refused for a held platform. The log ends with a `summary: {...}` line. | `pnpm ops browser-lookup --json '{"slug":"demo-odysee","ids":["<claimId>"]}' --wait`<br>`pnpm ops browser-lookup --json '{"slug":"demo-odysee","listing":true,"scrolls":5}' --wait` | diff --git a/OPERATING.md b/OPERATING.md @@ -60,7 +60,8 @@ pnpm ops get channel example stops the listing but not the backlog, and a `paused` tier stops every lane, transcription too. - `"fetchPlaylist": true` on `create-channel` stores the playlist at once (the form's "Fetch playlist now"); a social channel's is `"fetchPostsNow": true`. - Rename or delete: `pnpm ops rename-channel --json '{"slug":"old","newSlug":"new"}'`, - `pnpm ops delete-channel --json '{"slug":"x","confirm":"x"}'` — both refused while the channel is busy. + `pnpm ops delete-channel --json '{"slug":"x","confirm":"x"}'` — both refused while the channel is busy. A delete + takes the channel off every site that names it (pool and cited scope) and says which (`sitesUpdated`). - A site for it: `pnpm ops create-site --json '{"siteId":"example","siteTitle":"Examplealyzer","channels":["example"]}'` — the New site form, private and unlisted unless `"audience": "public"` / `"listed": true`. An existing id is refused; `"update": true` is the site page's Save with the keys given changed, every other key kept. diff --git a/common/controller/siteMemberships.test.ts b/common/controller/siteMemberships.test.ts @@ -0,0 +1,56 @@ +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { mkdtemp, readFile, rm, stat } from "node:fs/promises"; +import { tmpdir } from "node:os"; +import path from "node:path"; +import type { Paths } from "../lib/paths"; +import { writeSite, type Site } from "../lib/site"; +import { dropChannelFromSites } from "./siteMemberships"; + +// Run with: +// pnpm --filter yt-dlp-transcript-common exec tsx --test controller/siteMemberships.test.ts +// +// A deleted channel leaves no site naming it (9 Nov: `mooler` stayed in +// efapalyzer's pool): the pool and the cited scope drop it, through writeSite; +// a site that does not name it is not written. + +const site = (siteId: string, extra: Partial<Site> = {}): Site => ({ + siteId, + siteTitle: siteId, + siteDescription: "", + headerTitle: siteId, + homeTagline: "", + groups: [{ id: "default", name: "All", selectedByDefault: true }], + defaultGroupId: "default", + channels: [], + ...extra, +}); + +test("drops the slug from every pool and cited scope; leaves other sites unwritten", async () => { + const dir = await mkdtemp(path.join(tmpdir(), "ttb-site-drop-")); + const paths = { sitesDir: path.join(dir, "sites"), channelsDir: path.join(dir, "channels") } as Paths; + const file = (id: string) => path.join(paths.sitesDir, id, "site.json"); + const read = async (id: string) => JSON.parse(await readFile(file(id), "utf8")) as Site; + try { + await writeSite(site("pool", { channels: [{ slug: "gone", order: 0 }, { slug: "kept", groupId: "default", order: 1 }] }), paths); + await writeSite(site("cites", { citedChannels: [{ slug: "gone" }, { slug: "other" }] }), paths); + await writeSite(site("only-cites", { citedChannels: [{ slug: "gone" }] }), paths); + await writeSite(site("untouched", { channels: [{ slug: "kept", order: 0 }] }), paths); + const untouchedAt = (await stat(file("untouched"))).mtimeMs; + + const r = await dropChannelFromSites(paths, "gone"); + assert.deepEqual(r, { updated: ["cites", "only-cites", "pool"], failed: [] }); + assert.deepEqual((await read("pool")).channels, [{ slug: "kept", groupId: "default", order: 1 }]); + assert.deepEqual((await read("cites")).citedChannels, [{ slug: "other" }]); + assert.equal("citedChannels" in (await read("only-cites")), false, "an empty scope is not written"); + assert.equal((await stat(file("untouched"))).mtimeMs, untouchedAt, "a site not naming it is not written"); + + assert.deepEqual(await dropChannelFromSites(paths, "gone"), { updated: [], failed: [] }, "a second pass finds none"); + assert.deepEqual(await dropChannelFromSites({ ...paths, sitesDir: path.join(dir, "none") }, "gone"), { + updated: [], + failed: [], + }); + } finally { + await rm(dir, { recursive: true, force: true }); + } +}); diff --git a/common/controller/siteMemberships.ts b/common/controller/siteMemberships.ts @@ -0,0 +1,41 @@ +import type { Paths } from "../lib/paths"; +import { getSite, listSiteIds, writeSite } from "../lib/site"; + +// A DELETED CHANNEL LEAVES NO SITE NAMING IT (lane editor-gaps; 9 Nov: +// deleting `mooler` left it in efapalyzer's site.json, fixed by hand). Every +// site's pool (`channels`) and cited scope (`citedChannels`) drop the slug, +// through the one site writer (writeSite), the way a rename re-points them +// (renameChannel.ts, step 5). A site that does not name it is not written. +// +// Best-effort per site, because the channel is already gone: a site whose +// write is refused (its own file no longer valid) is named in `failed` with +// the writer's sentence and the others still go through. +export type SiteDropResult = { + updated: string[]; + failed: { siteId: string; error: string }[]; +}; + +export async function dropChannelFromSites(paths: Paths, slug: string): Promise<SiteDropResult> { + const result: SiteDropResult = { updated: [], failed: [] }; + for (const siteId of [...listSiteIds(paths)].sort()) { + try { + const site = getSite(siteId, paths); + const cited = site.citedChannels ?? []; + const inPool = site.channels.some((c) => c.slug === slug); + const inCited = cited.some((c) => c.slug === slug); + if (!inPool && !inCited) continue; + await writeSite( + { + ...site, + channels: site.channels.filter((c) => c.slug !== slug), + citedChannels: cited.filter((c) => c.slug !== slug), + }, + paths, + ); + result.updated.push(siteId); + } catch (err) { + result.failed.push({ siteId, error: (err as Error).message }); + } + } + return result; +} diff --git a/editor/CHANGELOG.md b/editor/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog ## [Unreleased] +- **Deleting a channel takes it off every site.** On 9 Nov, deleting `mooler` left it in efapalyzer's `site.json`, and the site had to be fixed by hand. Danger → Delete and `pnpm ops delete-channel` now rewrite every site whose pool (`channels`) or cited scope (`citedChannels`) names the deleted channel, through the one site writer (`writeSite`), as a rename already re-points them. The ops answer names those sites in `sitesUpdated`. A site whose write is refused shows up as a `warnings` line, and the delete still stands. Sites that never named the channel are not written (`common/controller/siteMemberships.ts`). - **`pnpm ops create-site` is the New site form, without a browser.** On 9 Nov an agent had to call `writeSite` from a tsx script to make `efapalyzer`. `create-site` takes `{"siteId", "siteTitle"}` and any of the form's fields: header title (default the title), description, tagline, wordmark lead, accent, public URL, Pages project, hub URL, audience, listed, publish policy, search, archives, duplicates, transcript downloads, PWA, archive cap, groups, default group, channels, cited channels, social links and related sites. It builds the FormData the form posts and saves it through the form's own action (`saveSiteAction` → `writeSite`), so you get the same validation and the same sentences. A new site is **private and unlisted** unless the body says `"audience": "public"` / `"listed": true`. An existing id is refused (409) unless `"update": true`, which is the site page's Save with only the given keys changed; every other key, and the published page list, is kept. Unknown channels, unknown keys and keys of the wrong type are refused before anything is written. It answers the saved site. - **`pnpm ops channel-rank` places one channel in the order the lanes follow.** Before this, only /channels' "Add to top" moved a channel, and it also sets the tier to normal and turns the download lane on. `channel-rank` moves the rank alone: `{"slug"}` plus exactly one of `"rank": <n>` (or `null` to unrank), `"top": true`, `"bottom": true`, `"before": "<slug>"` or `"after": "<slug>"`. Every other channel keeps its order: if the rank is already taken, that channel and every one below it shift down one. It goes through the deck's one writer, so the four lane roots are recompiled in the same write. Refused before any write: an unknown channel or anchor, an anchor with no rank, a rank that is not a whole number ≥ 0, and a channel paused for every operation (its rank would not be kept). It answers the saved rank and the whole ranked order (`common/lib/channelPriority.ts` `placeChannelRank`). - **Configure's Caption languages field (`subLangs`) is checked when you save.** Before, any text was saved, and a value yt-dlp's `--sub-langs` cannot use failed every caption download on the channel at the moment it ran. Configure and `pnpm ops channel-config` (`patch.subLangs`) now refuse it, in the field's words, with what you typed kept. Refused: an empty entry (two commas, or one at an end), a space inside an entry, a bare `-`, an entry that is not a regular expression, or a value over 200 characters. Spaces around an entry are dropped (`en.* , es` saves as `en.*,es`). `all` and `-<lang>` exclusions are accepted as before (`common/lib/channelConfig.ts` `subLangsProblem`). diff --git a/editor/app/api/ops/delete-channel/route.ts b/editor/app/api/ops/delete-channel/route.ts @@ -12,6 +12,10 @@ export const dynamic = "force-dynamic"; // compares them, and refuses in the form's own sentence. Every other refusal is // the form's too: a busy channel, media in transition. // +// Every site whose pool or cited scope named the channel is rewritten without +// it (through writeSite) and named in `sitesUpdated`; a site whose write is +// refused is a `warnings` line. +// // There is no undo, and transcripts/ is its own git repo — the only way back // is a commit there. export async function POST(request: Request) { @@ -21,6 +25,12 @@ export async function POST(request: Request) { fd.set("confirmSlug", reqString(body, "confirm")); const result = await deleteChannelFromForm(slug, fd); if (!result.ok) return opsFail(result.error); - return NextResponse.json({ ok: true, slug: result.slug, deleted: true }); + return NextResponse.json({ + ok: true, + slug: result.slug, + deleted: true, + sitesUpdated: result.sitesUpdated ?? [], + ...(result.warnings.length > 0 ? { warnings: result.warnings } : {}), + }); }); } diff --git a/editor/app/channels/actions.ts b/editor/app/channels/actions.ts @@ -22,6 +22,7 @@ import { readChannelConfig, } from "yt-dlp-transcript-common/controller/channels"; import { renameChannel } from "yt-dlp-transcript-common/controller/renameChannel"; +import { dropChannelFromSites } from "yt-dlp-transcript-common/controller/siteMemberships"; import { inspectChannelMedia } from "yt-dlp-transcript-common/lib/channelMedia"; import { channelMediaBusyReason } from "./lib/mediaBusy"; import { @@ -218,6 +219,9 @@ export type ChannelLifecycleResult = jobIds: string[]; // Non-fatal problems after the move (rename's metadata migration). warnings: string[]; + // Delete: the sites whose pool or cited scope named the channel and + // were rewritten without it. + sitesUpdated?: string[]; } | ({ ok: false } & NonNullable<FormErrorState>); @@ -694,6 +698,17 @@ export async function deleteChannelFromForm( } catch (e) { return fail((e as Error).message); } + // NO SITE GOES ON NAMING IT (9 Nov: a deleted channel stayed in a site's + // pool). Each site that names it is rewritten through writeSite; one whose + // write is refused is a warning — the channel is gone either way. + const sites = await dropChannelFromSites(getPaths(), slug).catch((e: Error) => ({ + updated: [] as string[], + failed: [{ siteId: "*", error: e.message }], + })); + const warnings = sites.failed.map( + (f) => `Site "${f.siteId}" still names "${slug}": its update was refused: ${f.error}`, + ); + if (warnings.length > 0) console.warn(`Channel delete ${slug}:`, warnings.join("; ")); // Same reason as createChannelAction: the deleted channel keeps a leaf in // every compiled tree until something recompiles. A leaf matching nothing is // harmless to dispatch and confusing to read. @@ -704,7 +719,8 @@ export async function deleteChannelFromForm( } revalidatePath("/channels"); revalidatePath("/"); - return { ok: true, slug, jobIds: [], warnings: [] }; + if (sites.updated.length > 0) revalidatePath("/sites"); + return { ok: true, slug, jobIds: [], warnings, sitesUpdated: sites.updated }; } // Change a channel's slug (its on-disk directory name). High-friction: the diff --git a/editor/e2e/ops-api.spec.ts b/editor/e2e/ops-api.spec.ts @@ -144,12 +144,22 @@ test("a channel's lifecycle over ops: create on a site, list, re-site, rename, d expect(refused.body.error).toBe( 'Type the channel slug "made-renamed-x" exactly to confirm deletion', ); + // A deleted channel leaves no site naming it (lane editor-gaps, 9 Nov): back + // in mysite's pool, and in another site's cited scope. + expect( + (await ops(request, "channel-config", { slug: "made-renamed-x", sites: [{ siteId: "mysite" }] })).body, + ).toEqual({ ok: true }); + await writeSite("citer", { channels: [], citedChannels: [{ slug: "made-renamed-x" }] }); + const CITER = `${testPaths().transcriptsDir}/sites/citer/site.json`; const gone = await ops(request, "delete-channel", { slug: "made-renamed-x", confirm: "made-renamed-x", }); expect(gone.status).toBe(200); + expect(gone.body).toEqual({ ok: true, slug: "made-renamed-x", deleted: true, sitesUpdated: ["citer", "mysite"] }); expect(await list()).toEqual([]); + expect((await readJson<{ channels: unknown[] }>(SITE)).channels).toEqual([]); + expect((await readJson<{ citedChannels?: unknown[] }>(CITER)).citedChannels).toBeUndefined(); }); test("channel-config round-trips a download filter and refuses a bad regex", async ({ diff --git a/scripts/archilyzer-ops.mjs b/scripts/archilyzer-ops.mjs @@ -1522,8 +1522,10 @@ export function usage() { ' media in transition) or when the new slug is taken. Old links break.', "", '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.', + ' {"slug", "confirm"} — "confirm" must repeat the slug. Every site whose', + ' pool or cited scope names it is rewritten without it (answered as', + ' "sitesUpdated"; a site whose write is refused is a "warnings" line). No', + ' undo outside the transcripts/ repo\'s own history.', "", 'fetch-chat fetches ONE video\'s live chat replay and nothing else: {"slug",', ' "id"} — the chat-only yt-dlp pass (the channel\'s cookies, the platform\'s',