Archilyzer · Source

archilyzer

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

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

common: `archilyzer reports delete <id> [--iteration n] [--apply] [--force]` — a dry run printing the plan unless --apply

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

Diffstat:
MCOMMANDS.md | 1+
Mcommon/bin/archilyzer.ts | 15+++++++++++++++
Acommon/bin/reports-delete.test.ts | 105+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Acommon/bin/reports-delete.ts | 146+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 267 insertions(+), 0 deletions(-)

diff --git a/COMMANDS.md b/COMMANDS.md @@ -35,6 +35,7 @@ Run from the repo root (in the container: `docker compose exec editor pnpm archi | `archilyzer reports verify-quotes` | `<report.json> \| --article <articleId>` | \[--json\] every video, audio and post quote of one report against its record with compose's own check: the best score and track, and the en-orig track's score where the record has one — a quote that matches a served `en` rewrite and not en-orig is reported (exit 1 when any quote drifted) | | `archilyzer reports attach-video` | `<report.json> <video> \| --article <articleId> <video>` | \[--poster &lt;image&gt;\] \[--caption &lt;line&gt;\] the report's video: remuxed (an H.264 mp4 under the limit) or encoded to fit the 24 MiB publish limit, written beside report.json as video.mp4 with a poster (given, kept, or a frame of the video), and `video` set in report.json (an article's through the article registry) | | `archilyzer reports iterations` | `<articleId> [--json]` | an article's iterations (transcripts/reports/&lt;id&gt;/iterations/): each one's kind, model, status, cost, lineage and what it revised or copied, the current article and current video marked (exit 1 when an iteration.json is unsound; 2 for no such article) | +| `archilyzer reports delete` | `<articleId> [--iteration <n>] [--apply] [--force] [--json]` | delete an article — its directory (report, video, history, notes, iterations), its iterations' video projects under settings.generation.projectsRoot and its staged exports — or, with --iteration, one iteration and its project, through the article registry. A dry run printing the plan (every path with its size, what is kept and why, what refuses) unless --apply. Refused: 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; an iteration that is current (article, its report's source, video) or that another revises or copies (exit 1 when refused; 2 for no such article or iteration) | | `archilyzer reports import-local-runs` | `[--apply] [--runs <dir>] [--only <run,…>] [--move-projects] [--generation <file>]` | ONE-OFF (release 27): the stopgap's kept runs (--runs: its directory, default ~/reports/local-reports; --only: those runs, default piratesoftware-ai-friends and api-shondo-recent) become i1 of their article through the iterations store — made current only when the run's report.json is the article's; a run with no article becomes an article in the making — and each video project is copied (--move-projects: moved) to the generation projects root; ~/.config/archilyzer/generation.json, when there is one, becomes settings.generation's routes and models. Lists the stopgap's test runs, projects and drafts to delete after the operator's OK (deletes nothing). A dry run printing the plan unless --apply (exit 1 when a run is refused) | | `archilyzer gen policy` | `[--json]` | the generation policy: where each task runs (code = Claude Code, api = the Claude API, local = the local model), the models, the caps and the day's Claude API spend — from the editor, or settings.json when none answers | | `archilyzer gen preset` | `<code\|balanced\|api\|local>` | route every generation task by a preset (its routes are written; settings.generation.routes) | diff --git a/common/bin/archilyzer.ts b/common/bin/archilyzer.ts @@ -399,6 +399,21 @@ export const COMMANDS: Command[] = [ }, }, { + path: ["reports", "delete"], + usage: + "<articleId> [--iteration <n>] [--apply] [--force] [--json] delete an article — its directory (report, video, history, notes, iterations), its iterations' video projects under settings.generation.projectsRoot and its staged exports — or, with --iteration, one iteration and its project, through the article registry. A dry run printing the plan (every path with its size, what is kept and why, what refuses) unless --apply. Refused: 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; an iteration that is current (article, its report's source, video) or that another revises or copies (exit 1 when refused; 2 for no such article or iteration)", + flags: { iteration: "string", apply: "boolean", force: "boolean", json: "boolean" }, + maxPositionals: 1, + run: async ({ positionals, flags }) => { + const [article] = positionals; + if (!article) { + console.error("reports delete: give <articleId>"); + return 2; + } + return (await import("./reports-delete")).deleteRow(article, flags as Parameters<typeof import("./reports-delete").deleteRow>[1]); + }, + }, + { path: ["reports", "import-local-runs"], usage: "[--apply] [--runs <dir>] [--only <run,…>] [--move-projects] [--generation <file>] ONE-OFF (release 27): the stopgap's kept runs (--runs: its directory, default ~/reports/local-reports; --only: those runs, default piratesoftware-ai-friends and api-shondo-recent) become i1 of their article through the iterations store — made current only when the run's report.json is the article's; a run with no article becomes an article in the making — and each video project is copied (--move-projects: moved) to the generation projects root; ~/.config/archilyzer/generation.json, when there is one, becomes settings.generation's routes and models. Lists the stopgap's test runs, projects and drafts to delete after the operator's OK (deletes nothing). A dry run printing the plan unless --apply (exit 1 when a run is refused)", diff --git a/common/bin/reports-delete.test.ts b/common/bin/reports-delete.test.ts @@ -0,0 +1,105 @@ +// `archilyzer reports delete` (release 27 follow-up): a dry run by default, +// --apply deletes, --force answers a published article, exit codes. Temp +// stores only. +// +// Run with: node_modules/.bin/tsx --test bin/reports-delete.test.ts + +import { after, test } from "node:test"; +import assert from "node:assert/strict"; +import { existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import path from "node:path"; +import { configureArticle, writeArticle } from "../lib/report/registry"; +import { createIteration, updateIteration } from "../lib/report/iterations"; +import { deleteMain, mediaFromEnv } from "./reports-delete"; + +const ROOTS: string[] = []; +after(() => { + for (const r of ROOTS) rmSync(r, { recursive: true, force: true }); +}); + +function setup() { + const root = mkdtempSync(path.join(tmpdir(), "reports-delete-")); + ROOTS.push(root); + const paths = { + articlesDir: path.join(root, "reports"), + exportIndexDir: path.join(root, ".export-index"), + sitesDir: path.join(root, "sites"), + }; + mkdirSync(paths.sitesDir, { recursive: true }); + return { paths, projectsRoot: path.join(root, "projects") }; +} + +const doc = (id: string) => ({ + format: "archilyzer-report", + version: 1, + id, + kind: "sweep", + title: `Article ${id}`, + sections: [{ id: "s1", title: "One", body: "Plain words." }], +}); + +function capture() { + const lines: string[] = []; + const errors: string[] = []; + return { out: { log: (s: string) => lines.push(s), error: (s: string) => errors.push(s) }, lines, errors }; +} + +test("dry by default; --apply deletes; a published article is refused until --force", async () => { + const s = setup(); + await writeArticle(doc("pub"), { paths: s.paths }); + await configureArticle("pub", { published: true }, s.paths); + const base = { article: "pub", projectsRoot: s.projectsRoot, paths: s.paths }; + + const dry = capture(); + assert.equal(await deleteMain({ ...base, force: true }, dry.out), 0); + assert.ok(dry.lines.some((l) => /dry run: nothing deleted/.test(l))); + assert.ok(existsSync(path.join(s.paths.articlesDir, "pub"))); + + const refused = capture(); + assert.equal(await deleteMain({ ...base, apply: true }, refused.out), 1); + assert.ok(refused.lines.some((l) => /refused \(unless --force\): "pub" is published/.test(l))); + assert.ok(existsSync(path.join(s.paths.articlesDir, "pub"))); + + const forced = capture(); + assert.equal(await deleteMain({ ...base, apply: true, force: true }, forced.out), 0); + assert.ok(forced.lines.some((l) => /"pub": deleted/.test(l))); + assert.equal(existsSync(path.join(s.paths.articlesDir, "pub")), false); + + const gone = capture(); + assert.equal(await deleteMain(base, gone.out), 2); + assert.match(gone.errors.join("\n"), /no article "pub"/); +}); + +test("--iteration plans and deletes one iteration; --json carries the plan", async () => { + const s = setup(); + await createIteration("mk", { kind: "sweep", model: "qwen3:8b", question: "Q?" }, s.paths); + await updateIteration("mk", 1, { status: "done" }, s.paths); + await createIteration("mk", { kind: "sweep", model: "qwen3:8b", question: "Q?" }, s.paths); + await updateIteration("mk", 2, { status: "running" }, s.paths); + mkdirSync(path.join(s.projectsRoot, "mk", "i1"), { recursive: true }); + writeFileSync(path.join(s.projectsRoot, "mk", "i1", "video.manifest.json"), "{}"); + const base = { article: "mk", projectsRoot: s.projectsRoot, paths: s.paths }; + + const busy = capture(); + assert.equal(await deleteMain({ ...base, iteration: 2, apply: true }, busy.out), 1); + assert.ok(busy.lines.some((l) => /i2 is running/.test(l))); + + const json = capture(); + assert.equal(await deleteMain({ ...base, iteration: 1, json: true }, json.out), 0); + const parsed = JSON.parse(json.lines.join("\n")) as { applied: boolean; plan: { remove: { label: string }[] } }; + assert.equal(parsed.applied, false); + assert.equal(parsed.plan.remove.length, 2); + + assert.equal(await deleteMain({ ...base, iteration: 1, apply: true }, capture().out), 0); + assert.equal(existsSync(path.join(s.paths.articlesDir, "mk", "iterations", "1")), false); + assert.equal(existsSync(path.join(s.projectsRoot, "mk", "i1")), false); + assert.equal(await deleteMain({ ...base, iteration: 1 }, capture().out), 2); +}); + +test("the media root comes from umtool's environment, and only when it is its own", () => { + assert.equal(mediaFromEnv({}), null); + assert.deepEqual(mediaFromEnv({ UMTOOL_MEDIA_DIR: "/m", REPORTS_DIR: "/r" }), { reportsRoot: "/r", mediaRoot: "/m" }); + assert.equal(mediaFromEnv({ UMTOOL_MEDIA_DIR: "/r", REPORTS_DIR: "/r" }), null); + assert.deepEqual(mediaFromEnv({ UMTOOL_MEDIA_DIR: "/m", SONG_REPORTS_DIR: "/x/reports" }), { reportsRoot: "/x", mediaRoot: "/m" }); +}); diff --git a/common/bin/reports-delete.ts b/common/bin/reports-delete.ts @@ -0,0 +1,146 @@ +// `archilyzer reports delete <id> [--iteration <n>] [--apply] [--force] [--json]` +// (release 27 follow-up) — delete an article, or one of its iterations, through +// the registry (lib/report/delete.ts). +// +// DRY RUN BY DEFAULT: it prints the plan — every path that would go, with its +// size, what is kept and why, and what refuses — and writes nothing. `--apply` +// deletes. `--force` (an article only) unpublishes it and drops a site page +// that names it with no report of its own, first; it never overrides a running +// iteration. +// +// The projects root is settings.generation.projectsRoot (`~` expanded; blank = +// ~/reports/articles). umtool's media root, when UMTOOL_MEDIA_DIR is set here, +// is where a tiered project's `out/` link points (its reports root REPORTS_DIR, +// else ~/reports, as umtool/lib/paths.mjs reads them): such a link's target +// goes with the project. Without it, the target is kept and named. +// +// Exit 0 when the plan is clean (and applied, with --apply); 1 when it is +// refused, or a path could not be removed; 2 for usage, or no such article or +// iteration. + +import os from "node:os"; +import path from "node:path"; +import type { GenerationSettings } from "../lib/generationSettings"; +import type { Paths } from "../lib/paths"; +import { + deleteArticle, + deleteBlocked, + deleteIteration, + DeleteRefusedError, + formatDeletePlan, + planArticleDelete, + planIterationDelete, + type DeleteMedia, + type DeletePaths, + type DeletePlan, + type DeleteResult, +} from "../lib/report/delete"; +import { ArticleRegistryError } from "../lib/report/registry"; + +type Out = { log: (s: string) => void; error: (s: string) => void }; + +export type DeleteMainOptions = { + article: string; + iteration?: number; + apply?: boolean; + force?: boolean; + json?: boolean; + projectsRoot: string; + media?: DeleteMedia | null; + paths: DeletePaths; +}; + +export async function deleteMain(o: DeleteMainOptions, out: Out = console): Promise<number> { + const opts = { projectsRoot: o.projectsRoot, media: o.media ?? null, paths: o.paths, force: o.force === true }; + const name = o.iteration !== undefined ? `"${o.article}" i${o.iteration}` : `"${o.article}"`; + let plan: DeletePlan; + try { + plan = o.iteration !== undefined ? await planIterationDelete(o.article, o.iteration, opts) : await planArticleDelete(o.article, opts); + } catch (err) { + if (err instanceof ArticleRegistryError) { + out.error(`reports delete: ${err.message}`); + return 2; + } + throw err; + } + const blocked = deleteBlocked(plan, opts.force); + if (!o.apply || blocked) { + if (o.json) out.log(JSON.stringify({ applied: false, blocked, plan }, null, 2)); + else { + for (const l of formatDeletePlan(plan, { force: opts.force })) out.log(l); + out.log(blocked ? `nothing deleted: ${name} is refused` : `dry run: nothing deleted — run again with --apply to delete ${name}`); + } + return blocked ? 1 : 0; + } + let result: DeleteResult; + try { + result = o.iteration !== undefined ? await deleteIteration(o.article, o.iteration, opts) : await deleteArticle(o.article, opts); + } catch (err) { + if (err instanceof DeleteRefusedError) { + // Something changed between the plan and the lock. + if (o.json) out.log(JSON.stringify({ applied: false, blocked: true, plan: err.plan }, null, 2)); + else for (const l of formatDeletePlan(err.plan, { force: opts.force })) out.log(l); + out.error(`reports delete: ${err.message}`); + return 1; + } + throw err; + } + if (o.json) out.log(JSON.stringify({ applied: true, ...result }, null, 2)); + else { + for (const l of formatDeletePlan(result.plan, { force: opts.force })) out.log(l); + for (const p of result.removed) out.log(`removed ${p}`); + for (const f of result.failed) out.error(`NOT removed ${f.path}: ${f.error}`); + out.log(result.failed.length ? `${name}: deleted, ${result.failed.length} path(s) left (above)` : `${name}: deleted`); + } + return result.failed.length ? 1 : 0; +} + +const expandHome = (p: string) => (p === "~" ? os.homedir() : p.startsWith("~/") ? path.join(os.homedir(), p.slice(2)) : p); + +// settings.generation.projectsRoot, `~` expanded; blank = ~/reports/articles +// (controller/reportDraft.ts projectsRootOf, which a bin does not import). +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, + flags: { iteration?: string; apply?: boolean; force?: boolean; json?: boolean }, +): Promise<number> { + let iteration: number | undefined; + if (flags.iteration !== undefined) { + iteration = Number(flags.iteration); + if (!Number.isInteger(iteration) || iteration < 1) { + console.error(`reports delete: --iteration takes an iteration number (1, 2, …), not "${flags.iteration}"`); + return 2; + } + if (flags.force) { + console.error("reports delete: --force is for an article (unpublish, site pages); an iteration's refusals have no override"); + return 2; + } + } + const { getPaths } = await import("../lib/paths"); + const { getSettings } = await import("../lib/settings"); + const paths: Paths = getPaths(); + return deleteMain({ + article, + ...(iteration !== undefined ? { iteration } : {}), + apply: flags.apply === true, + force: flags.force === true, + json: flags.json === true, + projectsRoot: projectsRootOf(getSettings().generation), + media: mediaFromEnv(), + paths, + }); +}