Archilyzer · Source

archilyzer

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

commit 5ca233a207f275c55a152d08295f4c4d4c95a630
parent bd45e863ce8578f1fbde5fcc2853705822168dea
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Tue, 24 Nov 2026 16:34:13 -0500

space-suggestions: the ops surface — space-scan (a job) and get space-suggestions (a read)

POST /api/ops/space-scan {compaction?} enqueues the scan; GET
/api/ops/space-suggestions[?disk=] reads its file and never computes. The CLI
getter, action, help and examples; COMMANDS.md regenerated.

Co-Authored-By: Claude <noreply@anthropic.com>

Diffstat:
MCOMMANDS.md | 11+++++++++++
Aeditor/app/api/ops/space-scan/route.test.ts | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aeditor/app/api/ops/space-scan/route.ts | 25+++++++++++++++++++++++++
Aeditor/app/api/ops/space-suggestions/route.test.ts | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aeditor/app/api/ops/space-suggestions/route.ts | 38++++++++++++++++++++++++++++++++++++++
Aeditor/app/cleanup/space/lib/loadSpace.ts | 67+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aeditor/app/cleanup/space/lib/spaceJob.ts | 18++++++++++++++++++
Mscripts/archilyzer-ops.mjs | 38++++++++++++++++++++++++++++++++++++++
Mscripts/archilyzer-ops.test.mjs | 11+++++++++++
9 files changed, 337 insertions(+), 0 deletions(-)

diff --git a/COMMANDS.md b/COMMANDS.md @@ -162,6 +162,7 @@ Drives a running editor over HTTP (`/api/ops/*`, the same actions its pages run) | `review-compacted-original` | review-compacted-original records a person's review of one compacted copy (watch it first: get compaction-review's "watch"): {"slug", "id", "note"?}. It names the copy it is for ("watched", its sha256) and counts for that copy only; it changes nothing on disk. It is what lets drop-saved-alternate ("confirmOriginal": true) drop the original of a video not freshly checked on its platform. "formerOriginal": "&lt;file&gt;" reviews the active copy that replaced a former original instead. | | | `compaction-markers` | compaction-markers lists the "being compacted" markers (.compacting.json), each live or stale and why: {}. {"clear": {"slug", "id"}} removes a stale one; a live one is refused (cancel its job). Stale ones are also swept at editor boot and at the start of every compaction run. | | | `kept-failed-encodes` | kept-failed-encodes lists the encodes kept after a failed check (in each video's .compact-scratch, never active: chunks and the joined copy, their size, what failed): {}. {"clear": {"slug", "id"}} removes one (refused while its compaction runs). compact-saved-videos "reverify": true re-checks one without encoding. | | +| `space-scan` | space-scan measures every disk the archive writes to: {"compaction"?} -&gt; {jobId}. The corpus disk, each storage location, the saved-video store's, the site builds' and umtool's reports' disks, by device: allocated bytes, each inode once, a file with other hard links never counted as freed, a tier link on its target's disk, a drive not mounted or not answering unknown (never empty). Then what would free space on each through the writers that exist — compress-text (captions, live chats), the cleanup sweeps, relocate, evict-clips, delete-file (abandoned partials), compact-saved-videos, drop-saved-alternate (compacted originals, alternates), kept-failed-encodes, live-recording-verify — with what is held (do-not-clean, a pin's copies, a live recording, a move in flight) and why. It only reads: nothing is removed, moved or fetched. Written to transcripts/.space-suggestions.json; get space-suggestions reads it. "compaction": false skips the selector's pass (one ffprobe per saved container not seen unchanged before) and keeps the last scan's rows. | `pnpm ops space-scan --json '{"compaction":false}' --wait` | | `compress-text` | compress-text stores big text files compressed (zstd, level 9): the raw live-chat replays (transcript.live\_chat.json -&gt; .zst, kind live-chat, the default) and the caption tracks (every transcript.&lt;lang&gt;.vtt -&gt; .zst, on the corpus disk: "kinds": \["captions"\], only when named). Read back by every reader as the same file, with the same times (the index sees no change): {"slugs"?: \[...\], "kinds"?: \["live-chat", "captions"\], "dryRun"?, "limit"?, "verify"?, "restore"?}. A caption's dry run also counts the en / en-orig pairs of equal size (compressed each as it is, never deduped). One file at a time: written beside the original, fsynced, read back and hashed against it, and only then the original removed; a crash at any step leaves a whole copy, and the next run finishes it (it visits every dir a stopped run left). Left alone and counted: a file written (mtime or ctime) in the last 10 minutes, one with a .part beside it, a video recording or with a job running, a drive that does not answer, a channel whose media is moving. Both forms present with different content are refused, both kept and listed once (recorded per channel; not visited again until a form changes): nothing removes a stored copy because a different one arrived. A file a writer replaces during the run is kept and read; the earlier content's stored copy is kept beside it. The dry run lists earlier chat captures a re-fetch kept (chat-capture-kept.\*.json.zst), which nothing removes automatically. "dryRun": true answers per channel and kind the files, their bytes, the stored ones, the estimate after (about 5 % for a chat, 20 % for a caption: estimates) and the free space, and writes nothing; "verify": true decodes every stored file in full and writes nothing; "limit" counts files compressed and takes exactly one channel in "slugs". One job per channel with work, on the machine-wide compress-text queue (one file at a time), waiting while render mode holds the machine and slower while a live recording runs. Started by a person only: a restart closes a queued one and resumes no interrupted one (it removes originals) -- a re-run continues. "restore": true is the rollback: every stored file of the kinds put back into its plain form, verified the same way in reverse (decoded beside, fsynced, read back against a fresh decode, the same times, then the .zst removed); with "dryRun" it answers the stored files, their plain bytes and the free space. Run it BEFORE reverting or running an older checkout, which cannot read a stored chat or caption (OPERATING.md). | | | `build-cues` | build-cues writes each video's transcript.cues.json from its raw transcript (the caption-track rule for VTTs), as the digest card's Normalize button does: {"slug"}, "ids": \[...\] for those videos only (every one held), "force": true to rewrite a fresh one. A job on the channel's queue. The file every reader without an index build wants. | `pnpm ops build-cues --json '{"slug":"demo-yt","ids":["<videoId>"]}' --wait` | | `feed-metadata` | feed-metadata completes a podcast channel's records from its RSS feed: one fetch of the channel's url, then title, date, description and duration into each record that lacks them: {"slug"}. "dryRun": true counts matched, unmatched and already complete, and writes nothing. | `pnpm ops feed-metadata --json '{"slug":"demo-podcast","dryRun":true}' --wait` | @@ -274,6 +275,7 @@ Usage: pnpm ops <action> [--json '<body>' | --file <path>] [--wait] pnpm ops get network [--probe] pnpm ops get saved-alternates [<slug>] pnpm ops get compaction-review [<slug>] + pnpm ops get space-suggestions [<disk>] pnpm ops get kept-originals [<slug>] pnpm ops get marks <slug> pnpm ops get services @@ -347,6 +349,15 @@ get compaction-review [<slug>] lists every compacted saved video and what availability and why, the original's entry, sizes, checks, the re-check, "watch" (both files and an smplayer command that plays them) and any "leftover" of an interrupted drop. +get space-suggestions [<disk>] answers the last space scan (space-scan): + every disk the archive writes to, most in need first, each with its size, + free space and how much of it is the archive's; and one disk's + suggestions (default the fullest), biggest saving first. Each says what + it frees and where (measured, or an estimate and from what), what a move + fills, what is lost, and its "actions": the existing ops call that does + it. Then what is held and why, the compaction selector's refusals by + rule, and the archive's bytes no writer here removes, with their owner. + It reads the file only: computedAt null means no scan yet. get marks <slug> lists the channel's do-not-clean marks and who set each one and when, as the video page says it ("setBy": "availability check, 3 Nov; the source was gone" | "you, 20 Nov" | "import, …" | "live diff --git a/editor/app/api/ops/space-scan/route.test.ts b/editor/app/api/ops/space-scan/route.test.ts @@ -0,0 +1,55 @@ +import test from "node:test"; +import assert from "node:assert/strict"; +import { mkdir, mkdtemp, readdir, rm, writeFile } from "node:fs/promises"; +import os from "node:os"; +import path from "node:path"; +import { setupOpsCorpus, callPost } from "../_testCorpus"; + +// Run with: +// pnpm -C editor exec tsx --test "app/api/ops/space-scan/route.test.ts" +// +// The space scan as a job: refusals before any job, then one run over a temp +// corpus that writes the result file and nothing else in the corpus. + +const corpus = await setupOpsCorpus(null); +const reports = await mkdtemp(path.join(os.tmpdir(), "space-scan-reports-")); +process.env.SPACE_SCAN_REPORTS_DIR = reports; +await corpus.writeChannelConfig("demo", { url: "https://www.youtube.com/@demo" }); +const video = path.join(corpus.transcripts, "channels", "demo", "data", "vid00000001"); +await mkdir(video, { recursive: true }); +await writeFile(path.join(video, "transcript.en.vtt"), Buffer.alloc(9_000, 65)); + +const { POST } = await import("./route"); +const { getRegistry } = await import("yt-dlp-transcript-common/jobs/registry"); +const { quiesceJobs, settleJob } = await import("yt-dlp-transcript-common/testing/jobs/quiesce.js"); +test.after(async () => { + await quiesceJobs(); + await corpus.cleanup(); + await rm(reports, { recursive: true, force: true }); +}); + +test("refusals: unknown keys and a non-boolean compaction queue nothing", async () => { + const before = await corpus.listJobIds(); + const a = await callPost(POST, { force: true }); + assert.equal(a.status, 400); + assert.match(a.body.error!, /unknown key\(s\): force/); + const b = await callPost(POST, { compaction: "no" }); + assert.equal(b.status, 400); + assert.match(b.body.error!, /"compaction" must be a boolean/); + assert.deepEqual(await corpus.listJobIds(), before); +}); + +test("a scan runs as a job and writes .space-suggestions.json", async () => { + const r = await callPost(POST, { compaction: false }); + assert.equal(r.status, 200, JSON.stringify(r.body)); + const jobId = r.body.jobId as string; + await settleJob(jobId); + assert.equal(getRegistry().get(jobId)?.status, "done"); + const names = await readdir(corpus.transcripts); + assert.ok(names.includes(".space-suggestions.json"), names.join(", ")); + const { readSpaceSuggestions } = await import("yt-dlp-transcript-common/controller/spaceScan"); + const result = await readSpaceSuggestions({ transcriptsDir: corpus.transcripts }); + assert.equal(result?.jobId, jobId); + assert.ok(result?.suggestions.some((s) => s.kind === "compress-captions" && s.slug === "demo")); + assert.equal(result?.compactionAt, null); +}); diff --git a/editor/app/api/ops/space-scan/route.ts b/editor/app/api/ops/space-scan/route.ts @@ -0,0 +1,25 @@ +import { SPACE_SCAN_BODY_KEYS } from "yt-dlp-transcript-common/controller/spaceScan"; +import { enqueueSpaceScanJob } from "../../../cleanup/space/lib/spaceJob"; +import { jobResponse, ops, optBool } from "../_lib"; + +export const dynamic = "force-dynamic"; + +// POST { compaction? } -> { ok: true, jobId } +// +// The space scan (lane space-suggestions, controller/spaceScan.ts) as a +// `space-scan` job on its own machine-wide queue: every disk the archive +// writes to — the corpus disk, each storage location, the saved-video store's, +// the site builds' and umtool's reports' — measured (allocated bytes, each +// inode once, a hard-linked file never counted as freed, an unmounted or +// unanswering drive unknown and never empty), and what would free space on +// each through the writers that already exist, into +// `transcripts/.space-suggestions.json` (`get space-suggestions` reads it). +// It only reads: nothing is removed, moved or fetched. `"compaction": false` +// skips the compaction selector's pass (one ffprobe per saved container not +// seen unchanged before) and carries the last scan's compaction rows. +export async function POST(request: Request) { + return ops(request, SPACE_SCAN_BODY_KEYS, async (body) => { + const compaction = optBool(body, "compaction"); + return jobResponse(await enqueueSpaceScanJob(compaction === false ? { compaction: false } : {})); + }); +} diff --git a/editor/app/api/ops/space-suggestions/route.test.ts b/editor/app/api/ops/space-suggestions/route.test.ts @@ -0,0 +1,74 @@ +import test from "node:test"; +import assert from "node:assert/strict"; +import { writeFile } from "node:fs/promises"; +import path from "node:path"; +import { setupOpsCorpus, callGet } from "../_testCorpus"; + +// Run with: +// pnpm -C editor exec tsx --test "app/api/ops/space-suggestions/route.test.ts" +// +// The read of the space scan's file: it never computes. No scan yet is an +// answer, not an error; a disk names whose suggestions come back. + +const corpus = await setupOpsCorpus(null); +const { GET } = await import("./route"); +test.after(() => corpus.cleanup()); + +const URL_BASE = "http://localhost/api/ops/space-suggestions"; + +test("no scan yet: computedAt null, nothing computed", async () => { + const r = await callGet(GET, URL_BASE); + assert.equal(r.status, 200, JSON.stringify(r.body)); + assert.equal(r.body.ok, true); + assert.equal(r.body.computedAt, null); +}); + +test("refusals: an unknown query key, a disk the scan does not know", async () => { + await seed(); + assert.equal((await callGet(GET, `${URL_BASE}?disc=corpus`)).status, 400); + const r = await callGet(GET, `${URL_BASE}?disk=nowhere`); + assert.equal(r.status, 400); + assert.match(r.body.error!, /no disk "nowhere".*corpus, platter/); +}); + +test("the fullest disk's suggestions by default, another disk's when named; the probe memo left out", async () => { + await seed(); + const r = await callGet(GET, URL_BASE); + assert.equal(r.status, 200, JSON.stringify(r.body)); + assert.equal(r.body.disk, "corpus"); + assert.deepEqual((r.body.disks as { id: string }[]).map((d) => d.id), ["corpus", "platter"]); + assert.deepEqual((r.body.suggestions as { kind: string }[]).map((s) => s.kind), ["compress-captions", "evict-clips"]); + assert.equal("probes" in r.body, false); + const p = await callGet(GET, `${URL_BASE}?disk=platter`); + assert.deepEqual((p.body.suggestions as { kind: string }[]).map((s) => s.kind), ["drop-original"]); + assert.ok(typeof p.body.ageSeconds === "number"); +}); + +async function seed(): Promise<void> { + const GB = 1024 ** 3; + const disk = (id: string, size: number, free: number) => ({ + id, label: id, mountpoint: `/${id}`, status: "ok", roles: [], locationIds: id === "platter" ? ["platter"] : [], + sizeBytes: size * GB, freeBytes: free * GB, archive: null, archiveBytes: null, + }); + const sug = (kind: string, disk: string, bytes: number) => ({ + key: `${kind}:${disk}`, kind, title: kind, frees: { disk, bytes: bytes * GB }, basis: "measured", basisText: "", loss: "", + }); + await writeFile( + path.join(corpus.transcripts, ".space-suggestions.json"), + JSON.stringify({ + version: 1, + computedAt: new Date().toISOString(), + tookMs: 1, + floorBytes: 0, + disks: [disk("platter", 1800, 202), disk("corpus", 1500, 24)], + suggestions: [sug("evict-clips", "corpus", 9), sug("drop-original", "platter", 30), sug("compress-captions", "corpus", 62)], + overflow: [], + held: [], + refused: [], + unmanaged: [], + notScanned: [], + compactionAt: null, + probes: { "/x": { size: 1, mtimeMs: 1, probe: null } }, + }), + ); +} diff --git a/editor/app/api/ops/space-suggestions/route.ts b/editor/app/api/ops/space-suggestions/route.ts @@ -0,0 +1,38 @@ +import { getPaths } from "yt-dlp-transcript-common/lib/paths"; +import { readSpaceSuggestions } from "yt-dlp-transcript-common/controller/spaceScan"; +import { diskNeedOrder } from "yt-dlp-transcript-common/lib/spaceSuggestions"; +import { spaceScanJob, spaceView } from "../../../cleanup/space/lib/loadSpace"; +import { readRoute } from "../_read"; +import { opsFail } from "../_lib"; + +export const dynamic = "force-dynamic"; + +// GET [?disk=<id>] +// -> { ok, computedAt, ageSeconds, tookMs, jobId?, scan: {jobId, status} | null, +// floorBytes, disks (most in need first), disk, suggestions (for `disk`, +// default the fullest, biggest saving first), overflow, held, refused, +// unmanaged, notScanned, compactionAt } +// +// /cleanup/space's list (lane space-suggestions): what the last space scan +// (`space-scan`, controller/spaceScan.ts) found — every disk the archive +// writes to, how much of it is the archive's, and what would free space on +// each, each suggestion with its `actions` (the existing ops call that does +// it: `pnpm ops <op> --json <body>`), its `basis` (measured or an estimate, +// and from what) and what it loses. It READS THE FILE ONLY; with no scan yet +// it answers `computedAt: null`. `space-scan` runs one. +export async function GET(request: Request) { + return readRoute(request, ["disk"], async (q) => { + const result = await readSpaceSuggestions(getPaths()); + const scan = spaceScanJob(); + if (!result) return { computedAt: null, scan }; + const disk = q.get("disk")?.trim() || null; + if (disk && !result.disks.some((d) => d.id === disk)) { + return opsFail(`no disk "${disk}" in the last scan — it knows ${diskNeedOrder(result.disks, result.floorBytes).map((d) => d.id).join(", ")}`); + } + return { + ...spaceView(result, disk), + ageSeconds: Math.max(0, Math.round((Date.now() - Date.parse(result.computedAt)) / 1000)), + scan, + }; + }); +} diff --git a/editor/app/cleanup/space/lib/loadSpace.ts b/editor/app/cleanup/space/lib/loadSpace.ts @@ -0,0 +1,67 @@ +import { getPaths } from "yt-dlp-transcript-common/lib/paths"; +import { getSettings } from "yt-dlp-transcript-common/lib/settings"; +import { getRegistry } from "yt-dlp-transcript-common/jobs/registry"; +import { readSpaceSuggestions } from "yt-dlp-transcript-common/controller/spaceScan"; +import { INTERNAL_LOCATION_ID, volumeFreeBytes } from "yt-dlp-transcript-common/controller/storageLocations"; +import { + SPACE_SCAN_JOB_KIND, + diskNeedOrder, + fullestDiskId, + suggestionsForDisk, + type SpaceScanResult, +} from "yt-dlp-transcript-common/lib/spaceSuggestions"; + +// WHAT /cleanup/space, its summary line and `get space-suggestions` read: the +// scan's file (never a walk, a stat of the corpus or an ffprobe), the live +// free space of each disk (two syscalls a location — tables never probe), and +// whether a scan is queued or running. + +export type SpaceScanJob = { jobId: string; status: string } | null; + +export function spaceScanJob(): SpaceScanJob { + const j = getRegistry() + .list() + .filter((r) => r.kind === SPACE_SCAN_JOB_KIND && (r.status === "queued" || r.status === "running")) + .sort((a, b) => (b.queuedAt ?? 0) - (a.queuedAt ?? 0))[0]; + return j ? { jobId: j.id, status: j.status } : null; +} + +// Free bytes now, by the scan's disk ids: `corpus` is the corpus volume, a +// location's disk takes its first location id. +export async function liveFreeByDisk(result: SpaceScanResult | null): Promise<Record<string, number | undefined>> { + if (!result) return {}; + const paths = getPaths(); + const free = await volumeFreeBytes({ paths, locations: getSettings().storage.locations }).catch( + () => ({}) as Record<string, number | undefined>, + ); + const out: Record<string, number | undefined> = {}; + for (const d of result.disks) { + if (d.status !== "ok") continue; + const v = d.id === "corpus" ? free[INTERNAL_LOCATION_ID] : d.locationIds.map((id) => free[id]).find((x) => x !== undefined); + if (v !== undefined) out[d.id] = v; + } + return out; +} + +export async function loadSpace(): Promise<{ + result: SpaceScanResult | null; + live: Record<string, number | undefined>; + job: SpaceScanJob; +}> { + const result = await readSpaceSuggestions(getPaths()); + return { result, live: await liveFreeByDisk(result), job: spaceScanJob() }; +} + +// The read the ops route answers: the file less its probe memo, the disks in +// order of need, the suggestions for one disk (default: the fullest). +export function spaceView(result: SpaceScanResult, disk: string | null) { + const { probes: _probes, ...rest } = result; + void _probes; + const id = disk ?? fullestDiskId(result.disks, result.floorBytes); + return { + ...rest, + disks: diskNeedOrder(result.disks, result.floorBytes), + disk: id, + suggestions: id ? suggestionsForDisk(result, id) : [], + }; +} diff --git a/editor/app/cleanup/space/lib/spaceJob.ts b/editor/app/cleanup/space/lib/spaceJob.ts @@ -0,0 +1,18 @@ +import { getPaths } from "yt-dlp-transcript-common/lib/paths"; +import { getSettings } from "yt-dlp-transcript-common/lib/settings"; +import type { StreamActionResult } from "yt-dlp-transcript-common/jobs/streamCommand"; +import { enqueueSpaceScan } from "yt-dlp-transcript-common/controller/spaceScan"; +import { safeRevalidate } from "../../../lib/safeRevalidate"; + +// ONE ENQUEUE OF THE SPACE SCAN, for /cleanup/space's Refresh and the +// `/api/ops/space-scan` adapter. Not in `actions.ts` ("use server": every +// export there is an endpoint), like storage/lib/evictClipsJob.ts. +export function enqueueSpaceScanJob(opts: { compaction?: boolean } = {}): Promise<StreamActionResult> { + return enqueueSpaceScan({ + paths: getPaths(), + // The settings as they are when the job STARTS (it may have queued). + settings: () => getSettings(), + ...(opts.compaction === false ? { compaction: false } : {}), + onDone: () => safeRevalidate(["/cleanup", "/cleanup/space"]), + }); +} diff --git a/scripts/archilyzer-ops.mjs b/scripts/archilyzer-ops.mjs @@ -86,6 +86,8 @@ // pnpm ops get remote-listing demo-odysee // pnpm ops build-cues --json '{"slug":"demo-yt","ids":["<videoId>"]}' --wait // pnpm ops get transcript <videoId> --slug demo-yt +// pnpm ops space-scan --json '{"compaction":false}' --wait +// pnpm ops get space-suggestions corpus // pnpm ops channel-config --json '{"slug":"x","patch":{"downloadFilterExclude":"rerun"}}' // pnpm ops channel-config --json '{"slug":"x","patch":{"downloadMode":"manual"}}' // pnpm ops channel-config --json '{"slug":"x","sites":[{"siteId":"anilyzer"}]}' @@ -339,6 +341,11 @@ const GETTERS = { // drop, nothing): the compaction review list. "compaction-review": (slug) => slug ? `/api/ops/compaction-review?slug=${encodeURIComponent(slug)}` : "/api/ops/compaction-review", + // The last space scan (lane space-suggestions): every disk the archive + // writes to, the archive's share of it, and what would free space on each + // (one disk's list when named, default the fullest). Reads the file only. + "space-suggestions": (disk) => + disk ? `/api/ops/space-suggestions?disk=${encodeURIComponent(disk)}` : "/api/ops/space-suggestions", // Every pointer that keeps an original or a former original (what an editor // rolled back past compaction would mistreat), and drops in flight. "kept-originals": (slug) => @@ -464,6 +471,7 @@ const GET_ARG_OPTIONAL = new Set([ "storage", "saved-alternates", "compaction-review", + "space-suggestions", "kept-originals", "sites", "archives", @@ -611,6 +619,10 @@ const ACTIONS = [ "compaction-markers", // The failed encodes kept for a re-verify, and clearing one ({} | {clear: {slug, id}}). "kept-failed-encodes", + // THE SPACE SCAN (lane space-suggestions): every disk the archive writes to + // measured, and what would free space on each, into + // transcripts/.space-suggestions.json ({compaction?}), as a space-scan job. + "space-scan", // The raw live chats stored zstd-compressed, one file at a time, verified // before each original goes ({slugs?, kinds?, dryRun?, limit? (one slug), verify?, restore?}). "compress-text", @@ -1438,6 +1450,7 @@ export function usage() { " pnpm ops get network [--probe]", " pnpm ops get saved-alternates [<slug>]", " pnpm ops get compaction-review [<slug>]", + " pnpm ops get space-suggestions [<disk>]", " pnpm ops get kept-originals [<slug>]", " pnpm ops get marks <slug>", " pnpm ops get services", @@ -1513,6 +1526,15 @@ export function usage() { " availability and why, the original's entry, sizes, checks, the re-check,", ' "watch" (both files and an smplayer command that plays them) and any', ' "leftover" of an interrupted drop.', + "get space-suggestions [<disk>] answers the last space scan (space-scan):", + " every disk the archive writes to, most in need first, each with its size,", + " free space and how much of it is the archive's; and one disk's", + " suggestions (default the fullest), biggest saving first. Each says what", + " it frees and where (measured, or an estimate and from what), what a move", + " fills, what is lost, and its \"actions\": the existing ops call that does", + " it. Then what is held and why, the compaction selector's refusals by", + " rule, and the archive's bytes no writer here removes, with their owner.", + " It reads the file only: computedAt null means no scan yet.", "get marks <slug> lists the channel's do-not-clean marks and who set each", ' one and when, as the video page says it ("setBy": "availability check,', ' 3 Nov; the source was gone" | "you, 20 Nov" | "import, …" | "live', @@ -3482,6 +3504,22 @@ export function usage() { " with @@mirror-scan {slug, dryRun, file?, of, missing?, window, videos,", " matched, byStatus, byPlatform, creatorRemoved: {inWindow, held, byChannel}}.", "", + 'space-scan measures every disk the archive writes to: {"compaction"?} ->', + " {jobId}. The corpus disk, each storage location, the saved-video store's,", + " the site builds' and umtool's reports' disks, by device: allocated bytes,", + " each inode once, a file with other hard links never counted as freed, a", + " tier link on its target's disk, a drive not mounted or not answering", + " unknown (never empty). Then what would free space on each through the", + " writers that exist — compress-text (captions, live chats), the cleanup", + " sweeps, relocate, evict-clips, delete-file (abandoned partials),", + " compact-saved-videos, drop-saved-alternate (compacted originals,", + " alternates), kept-failed-encodes, live-recording-verify — with what is", + " held (do-not-clean, a pin's copies, a live recording, a move in flight)", + " and why. It only reads: nothing is removed, moved or fetched. Written to", + " transcripts/.space-suggestions.json; get space-suggestions reads it.", + ' "compaction": false skips the selector\'s pass (one ffprobe per saved', + " container not seen unchanged before) and keeps the last scan's rows.", + "", 'copies-scan pairs a source group\'s channels video by video: {"group",', ' "dryRun"?} -> {jobId}. The group is settings.sourceGroups\' (an ordered', " list of channels holding the same recordings, the preferred source first;", diff --git a/scripts/archilyzer-ops.test.mjs b/scripts/archilyzer-ops.test.mjs @@ -1362,3 +1362,14 @@ test("copies-scan, copies-release, copies-confirm and copies-reject are POSTs; g assert.equal(parseArgs(["get", "copies", "stream-copies"]).path, "/api/ops/copies?group=stream-copies&pairs=1"); assert.match(usage(), /get copies \[<group>\]/); }); + +// Lane space-suggestions: the space scan is a job; its list is a read. +test("space-scan is a POST; get space-suggestions reads the last scan, one disk's list when named", () => { + const scan = parseArgs(["space-scan", "--json", '{"compaction":false}', "--wait"]); + assert.equal(scan.path, "/api/ops/space-scan"); + assert.deepEqual(scan.body, { compaction: false }); + assert.equal(parseArgs(["get", "space-suggestions"]).path, "/api/ops/space-suggestions"); + assert.equal(parseArgs(["get", "space-suggestions", "platter"]).path, "/api/ops/space-suggestions?disk=platter"); + assert.match(usage(), /get space-suggestions \[<disk>\]/); + assert.match(usage(), /space-scan measures every disk the archive writes to/); +});