Archilyzer · Source

archilyzer

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

commit 2efa307a6cd3becf9f0892eda8556c19aba73758
parent e28079bb6b32dd926c2de890e085774c52f2bad4
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Tue, 27 Oct 2026 17:58:47 -0400

Takes page: each take's work files, kept because ... or prunable, and Free work files

GET /api/report/takes/prune?project= is the plan with every take measured,
fetched after the page is up (a project's takes can hold hundreds of
thousands of frames). The bench's head says the takes' work in all and what
the policy would free, with Free work files for the project; each card says
its work and why it is kept, or that it is prunable and what it frees, with
its own Free work files. POST is answered as a delete (lib/delete-plan.ts),
so both buttons are components/DeletePlan.tsx: the plan first, its refusals
(a policy reason "free anyway" answers, a running build nothing does), then
"Free them" -- pruneProject, the writer `umtool prune --yes` calls.
DeletePlan takes a verb and a confirm label; its defaults are unchanged.

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

Diffstat:
Aumtool/app/api/report/takes/prune/route.ts | 50++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/components/DeletePlan.tsx | 9+++++++--
Mumtool/components/projects/TakesBench.tsx | 162++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 218 insertions(+), 3 deletions(-)

diff --git a/umtool/app/api/report/takes/prune/route.ts b/umtool/app/api/report/takes/prune/route.ts @@ -0,0 +1,50 @@ +import { answerDelete, type DeletePlanView } from "@/lib/delete-plan"; +import { projectRef } from "@/lib/projects"; +import { deleteViewOf, planPrune, planView, pruneProject } from "@/lib/report/takePrune.mjs"; +import { isTakeId } from "@/lib/report/takes.mjs"; + +export const dynamic = "force-dynamic"; + +// THE TAKES' WORK FILES (2026-10-27): lib/report/takePrune.mjs, the writer +// `umtool prune` runs. +// +// GET ?project=<id> the plan, every take measured: its work +// bytes, what freeing it gives back, kept +// because … or prunable (the Takes page) +// POST { project, take?, dryRun?, force? } "Free work files", answered as a delete +// (lib/delete-plan.ts): the project's +// prunable takes, or one take; `force` +// frees a take the policy keeps, never +// one being built or built from +export async function GET(request: Request) { + const url = new URL(request.url); + const project = await projectRef(url.searchParams.get("project") ?? ""); + if (!project) return Response.json({ error: "no such project" }, { status: 404 }); + try { + const plan = await planPrune({ id: project.id, dir: project.dir }, { measure: "all" }); + return Response.json({ plan: planView(plan) }, { headers: { "cache-control": "no-store" } }); + } catch (err) { + return Response.json({ error: err instanceof Error ? err.message : String(err) }, { status: 500 }); + } +} + +export async function POST(request: Request) { + const body = (await request.json().catch(() => ({}))) as { project?: unknown; take?: unknown; dryRun?: unknown; force?: unknown }; + if (body.take !== undefined && body.take !== null && !isTakeId(body.take)) return Response.json({ error: "take must be a take id" }, { status: 400 }); + const take = typeof body.take === "string" ? body.take : null; + const found = await projectRef(String(body.project ?? "")); + if (!found) return Response.json({ error: "no such project" }, { status: 404 }); + const project = { id: found.id, dir: found.dir }; + const force = body.force === true; + const opts = { takes: take ? [take] : null, anyway: force && !!take }; + try { + const plan = await planPrune(project, { ...opts, measure: "prunable" }); + return await answerDelete(deleteViewOf(plan, { take }) as DeletePlanView, { dryRun: body.dryRun === true, force }, async () => { + const r = await pruneProject(project, { ...opts, by: "ui" }); + return { plan: deleteViewOf(r.plan, { take }) as DeletePlanView, removed: r.removed, failed: r.failed }; + }); + } catch (err) { + const message = err instanceof Error ? err.message : String(err); + return Response.json({ error: message }, { status: /has no take/.test(message) ? 404 : 500 }); + } +} diff --git a/umtool/components/DeletePlan.tsx b/umtool/components/DeletePlan.tsx @@ -42,6 +42,8 @@ export default function DeletePlan({ endpoint, body, forceLabel = "delete anyway", + verb = "Delete", + confirmLabel = "Confirm delete", onDone, size = "sm", }: { @@ -50,6 +52,9 @@ export default function DeletePlan({ endpoint: string; body: Record<string, unknown>; forceLabel?: string; + /** The plan's first word ("Free" for the takes' work files); the region keeps its "delete <subject>" name. */ + verb?: string; + confirmLabel?: string; onDone: (answer: Extract<DeleteAnswer, { applied: true }>) => void; size?: "sm" | "md"; }) { @@ -113,7 +118,7 @@ export default function DeletePlan({ className="mt-2 basis-full rounded border border-[var(--color-bad)] bg-[var(--color-ink)] p-2 text-[12px]" > <p className="font-medium"> - Delete {subject}: {plan.remove.length} path{plan.remove.length === 1 ? "" : "s"},{" "} + {verb} {subject}: {plan.remove.length} path{plan.remove.length === 1 ? "" : "s"},{" "} <span className="num" data-delete-bytes={plan.bytes}> {fmt(plan.bytes)} </span>{" "} @@ -189,7 +194,7 @@ export default function DeletePlan({ </label> )} <Button size="sm" variant="outline" disabled={blocked.length > 0 || phase.at === "deleting"} onClick={() => void confirm(plan)}> - {phase.at === "deleting" ? "Deleting…" : "Confirm delete"} + {phase.at === "deleting" ? `${verb === "Delete" ? "Deleting" : `${verb}ing`}…` : confirmLabel} </Button> <Button size="sm" diff --git a/umtool/components/projects/TakesBench.tsx b/umtool/components/projects/TakesBench.tsx @@ -9,7 +9,7 @@ import { NotesProvider, useSharedNotes } from "@/components/notes/NotesProvider" import TimedNotes from "@/components/notes/TimedNotes"; import { badgeVariants, type BadgeVariants } from "@/components/ui/badge"; import { buttonVariants } from "@/components/ui/button"; -import { fmtAgo } from "@/lib/format"; +import { fmtAgo, fmtBytes } from "@/lib/format"; import { playHref } from "@/lib/hrefs"; import { BenchBody, VerdictBar } from "./bench/BenchShell"; import { startTakeJob } from "./NewTakePanel"; @@ -49,6 +49,27 @@ export type Take = { stale?: boolean | null; }; +/** A take's work files, as `GET /api/report/takes/prune` measures them (lib/report/takePrune.mjs). */ +export type TakeWork = { + id: string; + status: "prunable" | "kept" | "no-work"; + keep: { code: string; why: string; hard: boolean }[]; + workBytes: number | null; + freedBytes: number | null; + files: number | null; + pruned: { at: string; freedBytes: number } | null; +}; +type WorkPlan = { + takes: TakeWork[]; + policy: { keep: number; olderThanDays: number; pin: string[] }; + totals: { + takes: number; + workBytes: number | null; + prunable: { takes: number; workBytes: number; freedBytes: number; files: number }; + kept: { takes: number; workBytes: number | null }; + }; +}; + export type Verdict = "like" | "maybe" | "no"; export type TakeVerdict = { verdict: Verdict | null; note: string; at: string; picked?: true }; @@ -119,6 +140,28 @@ export default function TakesBench({ const starting = useRef(false); useEffect(() => setReady(true), []); + + // The takes' work files (lib/report/takePrune.mjs), measured after the page + // is up: a project's takes can hold hundreds of thousands of frames, so the + // page never waits on them. + const [work, setWork] = useState<WorkPlan | null>(null); + const [workError, setWorkError] = useState<string | null>(null); + const loadWork = useCallback(async () => { + try { + const r = await fetch(`/api/report/takes/prune?${new URLSearchParams({ project })}`, { cache: "no-store" }); + const j = (await r.json().catch(() => ({}))) as { plan?: WorkPlan; error?: string }; + if (!r.ok || !j.plan) throw new Error(j.error ?? `HTTP ${r.status}`); + setWork(j.plan); + setWorkError(null); + } catch (e) { + setWorkError(e instanceof Error ? e.message : String(e)); + } + }, [project]); + useEffect(() => { + void loadWork(); + }, [loadWork]); + const workOf = new Map((work?.takes ?? []).map((w) => [w.id, w])); + useEffect(() => { listenRef.current = listen; for (const [id, v] of videos.current) v.muted = id !== listen; @@ -229,6 +272,7 @@ export default function TakesBench({ <BenchBody verdict={verdictBar}> <div className="space-y-6"> {head} + <WorkSummary project={project} work={work} error={workError} ready={ready} onFreed={() => void loadWork()} /> {groups.map((g) => { const tally = VERDICTS.map((v) => [v.id, g.takes.filter((t) => verdicts[t.id]?.verdict === v.id).length] as const) .filter(([, n]) => n > 0) @@ -289,6 +333,8 @@ export default function TakesBench({ }} save={(patch) => save(t.id, patch)} onPicked={(v) => setVerdicts(v)} + work={work ? (workOf.get(t.id) ?? null) : undefined} + onFreed={() => void loadWork()} /> ))} </div> @@ -302,6 +348,114 @@ export default function TakesBench({ ); } +const days = (d: number) => (d >= 1 ? `${+d.toFixed(2)} d` : `${+(d * 24).toFixed(1)} h`); + +/** + * The takes' work files at the head of the bench: how much, how much the + * policy would free, and the project's "Free work files" (the plan, then the + * confirm: components/DeletePlan.tsx over POST /api/report/takes/prune). + */ +function WorkSummary({ + project, + work, + error, + ready, + onFreed, +}: { + project: string; + work: WorkPlan | null; + error: string | null; + ready: boolean; + onFreed: () => void; +}) { + if (error) { + return ( + <p data-takes-work="" className="text-[11.5px] text-[var(--color-bad)]"> + Work files could not be measured: {error} + </p> + ); + } + if (!work) { + return ( + <p data-takes-work="" data-state="measuring" className="text-[11.5px] text-[var(--color-dim)]"> + measuring the takes&apos; work files… + </p> + ); + } + const p = work.totals.prunable; + return ( + <section data-takes-work="" data-state="measured" className="flex flex-wrap items-center gap-2 text-[11.5px] text-[var(--color-dim)]"> + <h2 className="micro">work files</h2> + <span className="num" data-work-bytes={work.totals.workBytes ?? 0}> + {fmtBytes(work.totals.workBytes ?? 0)} in {work.takes.filter((t) => t.status !== "no-work").length} takes + </span> + <span>·</span> + <span data-work-prunable={p.takes}> + {p.takes ? ( + <> + {p.takes} prunable, frees <span className="num">{fmtBytes(p.freedBytes)}</span> + </> + ) : ( + "none prunable" + )} + </span> + <span title="lib/report/takePrune.mjs: running builds and their bases, the picked or current take, pins in takes/prune.json and the --from bases of kept takes are kept too"> + · keeps the newest {work.policy.keep} per group and anything modified within {days(work.policy.olderThanDays)} + </span> + {ready && p.takes > 0 && ( + <DeletePlan + label="Free work files" + subject={`the work files of ${project}'s prunable takes`} + endpoint="/api/report/takes/prune" + body={{ project }} + verb="Free" + confirmLabel="Free them" + onDone={onFreed} + /> + )} + </section> + ); +} + +/** One take's work files on its card: size, kept because … or prunable, and its own "Free work files". */ +function TakeWorkLine({ project, work: w, ready, onFreed }: { project: string; work: TakeWork | null | undefined; ready: boolean; onFreed: () => void }) { + if (w === undefined) return null; + if (w === null || w.status === "no-work") { + return ( + <p data-take-work="none" className="text-[11px] text-[var(--color-dim)]"> + no work files + {w?.pruned && ` · pruned ${w.pruned.at.slice(0, 10)}, ${fmtBytes(w.pruned.freedBytes)} freed`} + </p> + ); + } + const shared = w.workBytes !== null && w.freedBytes !== null && w.workBytes > w.freedBytes ? w.workBytes - w.freedBytes : 0; + return ( + <div data-take-work={w.status} className="flex flex-wrap items-center gap-1.5 text-[11px] text-[var(--color-dim)]"> + <span className="num">work {fmtBytes(w.workBytes ?? 0)}</span> + {w.status === "prunable" ? ( + <span data-take-prunable=""> + · prunable, frees <span className="num">{fmtBytes(w.freedBytes ?? 0)}</span> + {shared > 0 && ` (${fmtBytes(shared)} also linked elsewhere stays)`} + </span> + ) : ( + <span data-take-kept="">· kept because {w.keep.map((r) => r.why).join("; ")}</span> + )} + {ready && ( + <DeletePlan + label="Free work files" + subject={`the work files of take ${w.id}`} + endpoint="/api/report/takes/prune" + body={{ project, take: w.id }} + forceLabel="free anyway" + verb="Free" + confirmLabel="Free them" + onDone={onFreed} + /> + )} + </div> + ); +} + function TakeCard({ project, take: t, @@ -315,6 +469,8 @@ function TakeCard({ onUnmute, save, onPicked, + work, + onFreed, }: { project: string; take: Take; @@ -328,6 +484,9 @@ function TakeCard({ onUnmute: () => void; save: (patch: { verdict?: Verdict | null; note?: string }) => Promise<void>; onPicked: (verdicts: Record<string, TakeVerdict>) => void; + /** undefined while the work files are measured; null when the plan does not list the take. */ + work?: TakeWork | null; + onFreed: () => void; }) { const notes = useSharedNotes({ project }); const router = useRouter(); @@ -547,6 +706,7 @@ function TakeCard({ )} </p> )} + <TakeWorkLine project={project} work={work} ready={ready} onFreed={onFreed} /> <div className="flex flex-wrap"> <DeletePlan label={`Delete take ${t.id}`}