Archilyzer · Source

archilyzer

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

commit d9fc2ca3578853b48ee59cf65b4fff6dbe0134a7
parent 242b8f4290afea6af5973c879193fbe8215b8c70
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Tue, 13 Oct 2026 16:42:54 -0400

editor: ops delete-article {id, force?, dryRun?} and delete-iteration {id, n, dryRun?} — adapters over the registry's delete

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

Diffstat:
MCOMMANDS.md | 2++
Mcommon/bin/reports-delete.ts | 16++++------------
Mcommon/lib/report/delete.ts | 14++++++++++++++
Aeditor/app/api/ops/_articleDelete.test.ts | 99+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aeditor/app/api/ops/_articleDelete.ts | 50++++++++++++++++++++++++++++++++++++++++++++++++++
Aeditor/app/api/ops/delete-article/route.ts | 29+++++++++++++++++++++++++++++
Aeditor/app/api/ops/delete-iteration/route.ts | 25+++++++++++++++++++++++++
Mscripts/archilyzer-ops.mjs | 23+++++++++++++++++++++++
8 files changed, 246 insertions(+), 12 deletions(-)

diff --git a/COMMANDS.md b/COMMANDS.md @@ -91,6 +91,8 @@ Drives a running editor over HTTP (`/api/ops/*`, the same actions its pages run) | `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": "&lt;regex with named groups year, month, day&gt;"} (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}'` | +| `delete-article` | delete-article deletes an article, as `archilyzer reports delete <id>` does: {"id"}, "dryRun"? (answer the plan — every path with its size, what is kept and why — and write nothing), "force"? (unpublish it, and drop a site page naming it with no report of its own, first). It removes the article's directory (report, video, history, notes, iterations), each iteration's video project under settings.generation.projectsRoot and its staged exports. Refused with the plan (409): a published article or such a site page without "force"; a queued or running iteration, force or not. | `pnpm ops delete-article --json '{"id":"demo-article","dryRun":true}'`<br>`pnpm ops delete-article --json '{"id":"demo-article","force":true}'` | +| `delete-iteration` | delete-iteration deletes one iteration and its video project: {"id", "n"}, "dryRun"?. Its number is never given again. Refused with the plan (409), no override: the current article, the iteration its report.json came from, the current video, a queued or running one, one another revises or copies. | `pnpm ops delete-iteration --json '{"id":"demo-article","n":3}'` | | `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/common/bin/reports-delete.ts b/common/bin/reports-delete.ts @@ -30,6 +30,7 @@ import { formatDeletePlan, planArticleDelete, planIterationDelete, + deleteMediaFromEnv, type DeleteMedia, type DeletePaths, type DeletePlan, @@ -37,6 +38,8 @@ import { } from "../lib/report/delete"; import { ArticleRegistryError } from "../lib/report/registry"; +export { deleteMediaFromEnv as mediaFromEnv }; + type Out = { log: (s: string) => void; error: (s: string) => void }; export type DeleteMainOptions = { @@ -102,17 +105,6 @@ const expandHome = (p: string) => (p === "~" ? os.homedir() : p.startsWith("~/") export const projectsRootOf = (gen: Pick<GenerationSettings, "projectsRoot">): string => gen.projectsRoot ? expandHome(gen.projectsRoot) : path.join(os.homedir(), "reports", "articles"); -// umtool's reports and media roots from this process's environment, as -// umtool/lib/paths.mjs reads them; null when no media root is set. -export function mediaFromEnv(env: NodeJS.ProcessEnv = process.env): DeleteMedia | null { - const mediaRoot = env.UMTOOL_MEDIA_DIR; - if (!mediaRoot) return null; - const reportsRoot = env.REPORTS_DIR ?? (env.SONG_REPORTS_DIR ? path.dirname(path.resolve(env.SONG_REPORTS_DIR)) : path.join(os.homedir(), "reports")); - const r = path.resolve(reportsRoot); - const m = path.resolve(mediaRoot); - return r === m ? null : { reportsRoot: r, mediaRoot: m }; -} - // The CLI row's options, from the flags and the settings. export async function deleteRow( article: string, @@ -140,7 +132,7 @@ export async function deleteRow( force: flags.force === true, json: flags.json === true, projectsRoot: projectsRootOf(getSettings().generation), - media: mediaFromEnv(), + media: deleteMediaFromEnv(), paths, }); } diff --git a/common/lib/report/delete.ts b/common/lib/report/delete.ts @@ -63,6 +63,7 @@ import type { Dirent } from "node:fs"; import { lstat, readdir, readlink, realpath, rm, rmdir, stat } from "node:fs/promises"; +import os from "node:os"; import path from "node:path"; import { getPaths, type Paths } from "../paths"; import { getSite, listSiteIds, patchSite } from "../site"; @@ -168,6 +169,19 @@ export function deleteBlocked(plan: Pick<DeletePlan, "refusals">, force = false) return plan.refusals.some((r) => !force || !r.forceable); } +// umtool's reports and media roots from this process's environment, as +// umtool/lib/paths.mjs reads them (REPORTS_DIR, else dirname of +// SONG_REPORTS_DIR, else ~/reports; UMTOOL_MEDIA_DIR); null when no media root +// of its own is set. +export function deleteMediaFromEnv(env: NodeJS.ProcessEnv = process.env): DeleteMedia | null { + const mediaRoot = env.UMTOOL_MEDIA_DIR; + if (!mediaRoot) return null; + const reportsRoot = env.REPORTS_DIR ?? (env.SONG_REPORTS_DIR ? path.dirname(path.resolve(env.SONG_REPORTS_DIR)) : path.join(os.homedir(), "reports")); + const r = path.resolve(reportsRoot); + const m = path.resolve(mediaRoot); + return r === m ? null : { reportsRoot: r, mediaRoot: m }; +} + // ─── Paths ─── const inside = (root: string, p: string) => p === root || p.startsWith(root + path.sep); diff --git a/editor/app/api/ops/_articleDelete.test.ts b/editor/app/api/ops/_articleDelete.test.ts @@ -0,0 +1,99 @@ +import test from "node:test"; +import assert from "node:assert/strict"; +import { existsSync } from "node:fs"; +import { mkdir, writeFile } from "node:fs/promises"; +import path from "node:path"; +import { callPost, setupOpsCorpus } from "./_testCorpus"; + +// Run with: +// pnpm -C editor exec tsx --test "app/api/ops/_articleDelete.test.ts" +// +// delete-article and delete-iteration (release 27 follow-up): adapters over +// lib/report/delete.ts — behind the token, a dry run that writes nothing, a +// refusal that is a 409 carrying the plan, and the projects root read from +// settings.generation. + +const corpus = await setupOpsCorpus(null); +const projectsRoot = path.join(corpus.root, "projects"); +await corpus.writeSettings({ minFreeDiskGB: 0, generation: { projectsRoot } }); +test.after(() => corpus.cleanup()); + +type Post = Parameters<typeof callPost>[0]; +const route = async (name: string) => (await import(`./${name}/route`)).POST as Post; +const articles = path.join(corpus.transcripts, "reports"); + +const doc = (id: string) => ({ + format: "archilyzer-report", + version: 1, + id, + kind: "sweep", + title: `Article ${id}`, + sections: [{ id: "s1", title: "One", body: "Plain words." }], +}); + +test("both routes are behind the token and refuse unknown keys", async () => { + for (const name of ["delete-article", "delete-iteration"]) { + const res = await callPost(await route(name), { id: "a" }, {}); + assert.equal(res.status, 401, name); + } + const stray = await callPost(await route("delete-article"), { id: "a", confirm: "a" }); + assert.equal(stray.status, 400); + const badN = await callPost(await route("delete-iteration"), { id: "a", n: "1" }); + assert.equal(badN.status, 400); + assert.match(String(badN.body.error), /iteration number/); +}); + +test("delete-article: a dry run plans, a published one is a 409 with its plan, force deletes", async () => { + const { writeArticle, configureArticle } = await import("yt-dlp-transcript-common/lib/report/registry"); + const { createIteration, updateIteration } = await import("yt-dlp-transcript-common/lib/report/iterations"); + await writeArticle(doc("gone")); + await configureArticle("gone", { published: true }); + await createIteration("gone", { kind: "sweep", model: "qwen3:8b", question: "Q?" }); + await updateIteration("gone", 1, { status: "done" }); + await mkdir(path.join(projectsRoot, "gone", "i1"), { recursive: true }); + await writeFile(path.join(projectsRoot, "gone", "i1", "video.manifest.json"), "{}"); + const post = await route("delete-article"); + + const missing = await callPost(post, { id: "nope", dryRun: true }); + assert.equal(missing.status, 400); + assert.match(String(missing.body.error), /no article "nope"/); + + const refused = await callPost(post, { id: "gone", dryRun: true }); + assert.equal(refused.status, 409); + assert.match(String(refused.body.error), /is published/); + assert.ok((refused.body.plan as { remove: unknown[] }).remove.length >= 2); + + const dry = await callPost(post, { id: "gone", dryRun: true, force: true }); + assert.equal(dry.status, 200); + assert.equal(dry.body.applied, false); + const labels = (dry.body.plan as { remove: { label: string }[] }).remove.map((e) => e.label); + assert.deepEqual(labels, ["reports/gone/", "projects/gone/i1/"]); + assert.ok(existsSync(path.join(articles, "gone", "report.json")), "a dry run writes nothing"); + + const done = await callPost(post, { id: "gone", force: true }); + assert.equal(done.status, 200); + assert.equal(done.body.applied, true); + assert.deepEqual(done.body.failed, []); + assert.equal(existsSync(path.join(articles, "gone")), false); + assert.equal(existsSync(path.join(projectsRoot, "gone")), false); +}); + +test("delete-iteration: a parent is refused with its children named; a leaf goes", async () => { + const { createIteration, updateIteration } = await import("yt-dlp-transcript-common/lib/report/iterations"); + await createIteration("its", { kind: "sweep", model: "qwen3:8b", question: "Q?" }); + await updateIteration("its", 1, { status: "done" }); + await createIteration("its", { kind: "sweep", model: "claude-sonnet-5-5", copyOf: 1 }); + await updateIteration("its", 2, { status: "done" }); + const post = await route("delete-iteration"); + + const parent = await callPost(post, { id: "its", n: 1 }); + assert.equal(parent.status, 409); + assert.match(String(parent.body.error), /i2 is a copy of it/); + + const leaf = await callPost(post, { id: "its", n: 2 }); + assert.equal(leaf.status, 200); + assert.equal(existsSync(path.join(articles, "its", "iterations", "2")), false); + const none = await callPost(post, { id: "its", n: 2, dryRun: true }); + assert.equal(none.status, 400); + assert.match(String(none.body.error), /has no iteration i2/); +}); diff --git a/editor/app/api/ops/_articleDelete.ts b/editor/app/api/ops/_articleDelete.ts @@ -0,0 +1,50 @@ +import { NextResponse } from "next/server"; +import { getPaths } from "yt-dlp-transcript-common/lib/paths"; +import { getSettings } from "yt-dlp-transcript-common/lib/settings"; +import { projectsRootOf } from "yt-dlp-transcript-common/controller/reportDraft"; +import { + DeleteRefusedError, + deleteBlocked, + deleteMediaFromEnv, + type DeleteOptions, + type DeletePlan, + type DeleteResult, +} from "yt-dlp-transcript-common/lib/report/delete"; +import { ArticleRegistryError } from "yt-dlp-transcript-common/lib/report/registry"; +import { OpsInputError, opsFail } from "./_lib"; + +// The two delete routes' shared half (delete-article, delete-iteration): the +// options every generation path resolves the same way, and the one answer +// shape. The rules are lib/report/delete.ts's; nothing here decides. + +export function articleDeleteOptions(force?: boolean): DeleteOptions { + return { + paths: getPaths(), + projectsRoot: projectsRootOf(getSettings().generation), + media: deleteMediaFromEnv(), + ...(force ? { force: true } : {}), + }; +} + +// A dry run answers the plan; a delete the plan and what it removed. A plan +// with a refusal is a 409 carrying the plan, so a caller can say why. +export async function articleDeleteAnswer( + dryRun: boolean, + force: boolean, + plan: () => Promise<DeletePlan>, + apply: () => Promise<DeleteResult>, +): Promise<NextResponse> { + try { + const p = await plan(); + if (deleteBlocked(p, force)) { + return opsFail(`refused: ${p.refusals.filter((r) => !force || !r.forceable).map((r) => r.reason).join("; ")}`, 409, { plan: p }); + } + if (dryRun) return NextResponse.json({ ok: true, applied: false, plan: p }); + const r = await apply(); + return NextResponse.json({ ok: r.failed.length === 0, applied: true, plan: r.plan, removed: r.removed, failed: r.failed }); + } catch (err) { + if (err instanceof DeleteRefusedError) return opsFail(`refused: ${err.problems.join("; ")}`, 409, { plan: err.plan }); + if (err instanceof ArticleRegistryError) throw new OpsInputError(err.message); + throw err; + } +} diff --git a/editor/app/api/ops/delete-article/route.ts b/editor/app/api/ops/delete-article/route.ts @@ -0,0 +1,29 @@ +import { deleteArticle, planArticleDelete } from "yt-dlp-transcript-common/lib/report/delete"; +import { ops, optBool, reqString } from "../_lib"; +import { articleDeleteAnswer, articleDeleteOptions } from "../_articleDelete"; + +export const dynamic = "force-dynamic"; + +// POST { id: string, force?: boolean, dryRun?: boolean } +// -> { ok, applied, plan, removed?, failed? } +// +// DELETE AN ARTICLE (release 27 follow-up), as `archilyzer reports delete` +// does: its directory under transcripts/reports/ (report, video, history, +// notes, iterations), each iteration's video project under +// settings.generation.projectsRoot, and its staged exports — through +// lib/report/delete.ts, under the article registry's lock. `dryRun` answers +// the plan (every path with its size, what is kept and why) and writes +// nothing. Refused (409, with the plan): a published article, or a site page +// naming it with no report of its own — `force` unpublishes it and drops the +// page first; a queued or running iteration, force or not. +// +// 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) { + return ops(request, ["id", "force", "dryRun"], async (body) => { + const id = reqString(body, "id"); + const force = optBool(body, "force") === true; + const opts = articleDeleteOptions(force); + return articleDeleteAnswer(optBool(body, "dryRun") === true, force, () => planArticleDelete(id, opts), () => deleteArticle(id, opts)); + }); +} diff --git a/editor/app/api/ops/delete-iteration/route.ts b/editor/app/api/ops/delete-iteration/route.ts @@ -0,0 +1,25 @@ +import { deleteIteration, planIterationDelete } from "yt-dlp-transcript-common/lib/report/delete"; +import { OpsInputError, ops, optBool, reqString } from "../_lib"; +import { articleDeleteAnswer, articleDeleteOptions } from "../_articleDelete"; + +export const dynamic = "force-dynamic"; + +// POST { id: string, n: number, dryRun?: boolean } +// -> { ok, applied, plan, removed?, failed? } +// +// DELETE ONE ITERATION of an article (release 27 follow-up), as `archilyzer +// reports delete <id> --iteration <n>` does: `iterations/<n>/` and its video +// project, through lib/report/delete.ts under the article registry's lock; its +// number is retired. `dryRun` answers the plan and writes nothing. Refused +// (409, with the plan; no override): the current article, the iteration its +// report.json came from, the current video, a queued or running one, and one +// another iteration revises or copies. +export async function POST(request: Request) { + return ops(request, ["id", "n", "dryRun"], async (body) => { + const id = reqString(body, "id"); + const n = body.n; + if (typeof n !== "number" || !Number.isInteger(n) || n < 1) throw new OpsInputError('"n" is an iteration number (1, 2, …)'); + const opts = articleDeleteOptions(); + return articleDeleteAnswer(optBool(body, "dryRun") === true, false, () => planIterationDelete(id, n, opts), () => deleteIteration(id, n, opts)); + }); +} diff --git a/scripts/archilyzer-ops.mjs b/scripts/archilyzer-ops.mjs @@ -55,6 +55,9 @@ // 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 delete-article --json '{"id":"demo-article","dryRun":true}' +// pnpm ops delete-article --json '{"id":"demo-article","force":true}' +// pnpm ops delete-iteration --json '{"id":"demo-article","n":3}' // 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"}' @@ -262,6 +265,11 @@ const ACTIONS = [ // An article's audience and its place in the published list ({id, // audience?, published?, position?}), through the article registry. "articles-config", + // Delete an article ({id, force?, dryRun?}) or one of its iterations ({id, + // n, dryRun?}) through the article registry: the plan, then the delete. + // Synchronous; no job. + "delete-article", + "delete-iteration", // The channel's lifecycle: the New channel form, and the channel page's // Danger → Rename and Danger → Delete. Synchronous; no job. "create-channel", @@ -957,6 +965,21 @@ export function usage() { ' publishing an article whose report.json has problems (listed). Answers', ' the article as saved.', "", + 'delete-article deletes an article, as `archilyzer reports delete <id>`', + ' does: {"id"}, "dryRun"? (answer the plan — every path with its size, what', + ' is kept and why — and write nothing), "force"? (unpublish it, and drop a', + ' site page naming it with no report of its own, first). It removes the', + ' article\'s directory (report, video, history, notes, iterations), each', + ' iteration\'s video project under settings.generation.projectsRoot and its', + ' staged exports. Refused with the plan (409): a published article or such', + ' a site page without "force"; a queued or running iteration, force or not.', + '', + 'delete-iteration deletes one iteration and its video project: {"id", "n"},', + ' "dryRun"?. Its number is never given again. Refused with the plan (409),', + ' no override: the current article, the iteration its report.json came', + ' from, the current video, a queued or running one, one another revises', + ' or copies.', + "", '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',