commit eeef3cf3613c36145d0f6d2fdd2e504670ff829f
parent b1cbc3b4906d263db85a9401557886d02f7cf92a
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Tue, 24 Nov 2026 16:19:46 -0500
space-suggestions: the pure half — disks by need, suggestions by disk and kind, caps, refusal groups, alternates
lib/spaceSuggestions.ts is the shape of transcripts/.space-suggestions.json and
every rule that orders, groups and bounds it (lane space-suggestions).
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat:
2 files changed, 533 insertions(+), 0 deletions(-)
diff --git a/common/lib/spaceSuggestions.test.ts b/common/lib/spaceSuggestions.test.ts
@@ -0,0 +1,162 @@
+import { test } from "node:test";
+import assert from "node:assert/strict";
+import {
+ SPACE_ITEMS_PER_KIND,
+ alternateDisposition,
+ capPerKind,
+ compressSaving,
+ diskNeedOrder,
+ fullestDiskId,
+ groupSuggestions,
+ moveFit,
+ refusalGroup,
+ spaceSummaryLine,
+ suggestionsForDisk,
+ type SpaceDisk,
+ type SpaceScanResult,
+ type SpaceSuggestion,
+} from "./spaceSuggestions";
+
+const GB = 1024 ** 3;
+
+function disk(id: string, size: number, free: number, extra: Partial<SpaceDisk> = {}): SpaceDisk {
+ return {
+ id,
+ label: id,
+ mountpoint: `/${id}`,
+ status: "ok",
+ roles: [],
+ locationIds: [],
+ sizeBytes: size * GB,
+ freeBytes: free * GB,
+ archive: null,
+ archiveBytes: null,
+ ...extra,
+ };
+}
+
+function sug(kind: SpaceSuggestion["kind"], diskId: string, bytes: number | null, extra: Partial<SpaceSuggestion> = {}): SpaceSuggestion {
+ return {
+ key: `${kind}:${diskId}:${bytes}:${Math.random()}`,
+ kind,
+ title: kind,
+ frees: bytes === null ? null : { disk: diskId, bytes: bytes * GB },
+ basis: "measured",
+ basisText: "measured",
+ loss: "nothing",
+ ...extra,
+ };
+}
+
+test("disk need: below the floor first, then the smallest free share; unmounted and not answering last", () => {
+ const disks = [
+ disk("platter", 1800, 202),
+ disk("gone", 0, 0, { status: "not-mounted", sizeBytes: null, freeBytes: null }),
+ disk("corpus", 1500, 24),
+ disk("roomy", 100, 5),
+ disk("tiny", 4000, 40),
+ ];
+ // floor 30 GB: corpus (24) and roomy (5) are under it, and of those the smaller share free first.
+ const order = diskNeedOrder(disks, 30 * GB).map((d) => d.id);
+ assert.deepEqual(order, ["corpus", "roomy", "tiny", "platter", "gone"]);
+ assert.equal(fullestDiskId(disks, 30 * GB), "corpus");
+ // No floor: by share alone.
+ assert.deepEqual(diskNeedOrder(disks, 0).map((d) => d.id), ["tiny", "corpus", "roomy", "platter", "gone"]);
+});
+
+test("suggestions for a disk: only what frees bytes there, biggest first; a compaction (frees nothing now) after every saving", () => {
+ const result = {
+ suggestions: [
+ sug("evict-clips", "corpus", 9),
+ sug("compress-captions", "corpus", 62),
+ sug("compact", "platter", null, { later: { disk: "platter", low: 40 * GB, high: 60 * GB, when: "after its original is dropped" } }),
+ sug("drop-original", "platter", 30),
+ sug("move-media", "corpus", 21, { fills: { disk: "platter", bytes: 21 * GB, fits: true, freeAfter: 181 * GB } }),
+ ],
+ } as Pick<SpaceScanResult, "suggestions">;
+ assert.deepEqual(
+ suggestionsForDisk(result, "corpus").map((s) => s.kind),
+ ["compress-captions", "move-media", "evict-clips"],
+ );
+ assert.deepEqual(suggestionsForDisk(result, "platter").map((s) => s.kind), ["drop-original", "compact"]);
+});
+
+test("groups: by kind, subtotal of what each frees, the biggest group first; caption compression leads the corpus disk", () => {
+ const list = [
+ sug("clean-audio", "corpus", 10),
+ sug("clean-audio", "corpus", 11),
+ sug("compress-captions", "corpus", 30),
+ sug("compress-captions", "corpus", 32),
+ sug("unstored-container", "corpus", 23),
+ ];
+ const groups = groupSuggestions(list);
+ assert.deepEqual(groups.map((g) => g.kind), ["compress-captions", "unstored-container", "clean-audio"]);
+ assert.equal(groups[0].bytes, 62 * GB);
+ assert.equal(groups[0].rows[0].frees!.bytes, 32 * GB);
+});
+
+test("move fit: the target keeps its floor plus a margin, or the move is shown as not fitting", () => {
+ assert.deepEqual(moveFit(200 * GB, 21 * GB, 30 * GB), { fits: true, freeAfter: 179 * GB });
+ assert.equal(moveFit(40 * GB, 21 * GB, 30 * GB).fits, false);
+ assert.equal(moveFit(null, 21 * GB, 30 * GB).fits, false);
+ assert.equal(moveFit(null, 21 * GB, 30 * GB).freeAfter, null);
+});
+
+test("compress saving: what the plain files lose at the controller's ratio", () => {
+ assert.equal(compressSaving(1000, 0.2), 800);
+ assert.equal(compressSaving(0, 0.2), 0);
+});
+
+test("cap per kind and disk: at most N rows each, the rest counted exactly", () => {
+ const many = Array.from({ length: SPACE_ITEMS_PER_KIND + 7 }, (_, i) => sug("evict-clips", "corpus", i + 1));
+ const other = [sug("compress-captions", "corpus", 1)];
+ const { kept, overflow } = capPerKind([...many, ...other]);
+ assert.equal(kept.filter((s) => s.kind === "evict-clips").length, SPACE_ITEMS_PER_KIND);
+ assert.equal(kept.filter((s) => s.kind === "compress-captions").length, 1);
+ assert.equal(overflow.length, 1);
+ assert.equal(overflow[0].kind, "evict-clips");
+ assert.equal(overflow[0].count, 7);
+ // The seven smallest are the ones left out: 1..7 GB.
+ assert.equal(overflow[0].bytes, (1 + 2 + 3 + 4 + 5 + 6 + 7) * GB);
+});
+
+test("refusal groups: a selector refusal reads as its rule, numbers left out", () => {
+ assert.equal(refusalGroup("1.20 Mbit/s video is below minVideoMbps 3"), "below the bitrate floor");
+ assert.equal(refusalGroup("480p is below minHeight 720"), "below the height floor");
+ assert.equal(refusalGroup("platform youtube is not selected"), "platform not selected");
+ assert.equal(
+ refusalGroup("an automatic keep-latest container (compaction is for deliberately stored videos only)"),
+ "keep-latest (not deliberately stored)",
+ );
+ assert.equal(refusalGroup('kept as "override" with no record that a person asked for it (persist-kept…)'), "override (not known to be deliberate)");
+ assert.equal(refusalGroup("no keep reason recorded (a legacy pointer): not known to be kept on purpose"), "legacy pointer");
+ assert.equal(refusalGroup("already AV1"), "already AV1");
+ assert.equal(refusalGroup("the channel opts out (excludeFromCompaction)"), "channel opts out");
+ assert.equal(refusalGroup("its last compaction failed its checks on 2026-11-01: x"), "last compaction failed");
+ assert.equal(refusalGroup("something new"), "other");
+ assert.equal(refusalGroup("already compacted"), null);
+});
+
+test("alternates: a pin keeps every copy; a proxy is kept on purpose; an original is the compaction's; a former original needs its own word", () => {
+ const base = { storedAt: "", dir: "/s", file: "a.mp4", bytes: 1 };
+ const alt = { file: "b.mp4", bytes: 1, storedAt: "", setAsideAt: "" };
+ assert.deepEqual(alternateDisposition({ ...base, keepReason: "override" }, alt), { offer: true });
+ assert.equal(alternateDisposition({ ...base, keepReason: "pin" }, alt).offer, false);
+ assert.equal(alternateDisposition(base, { ...alt, keptAs: "proxy" }).offer, false);
+ assert.equal(alternateDisposition(base, { ...alt, keptAs: "original" }).offer, false);
+ const former = alternateDisposition(base, { ...alt, keptAs: "former-original" });
+ assert.equal(former.offer, true);
+ assert.ok(former.offer && former.confirmFormerOriginal);
+});
+
+test("summary line: the fullest disk, its free space and what the scan suggests there", () => {
+ const result = {
+ computedAt: "2026-11-24T10:00:00.000Z",
+ floorBytes: 0,
+ disks: [disk("corpus", 1500, 24, { label: "Corpus disk" }), disk("platter", 1800, 202)],
+ suggestions: [sug("compress-captions", "corpus", 62), sug("evict-clips", "corpus", 9), sug("drop-original", "platter", 30)],
+ } as unknown as SpaceScanResult;
+ const line = spaceSummaryLine(result, { corpus: 25 * GB });
+ assert.match(line!, /^Corpus disk: 25\.00 GB free \(98 % used\) · ~71\.00 GB suggested there/);
+ assert.equal(spaceSummaryLine(null, {}), null);
+});
diff --git a/common/lib/spaceSuggestions.ts b/common/lib/spaceSuggestions.ts
@@ -0,0 +1,371 @@
+// FREE UP SPACE: the pure half (lane space-suggestions). The scan
+// (controller/spaceScan.ts, the `space-scan` job) measures the disks and writes
+// `transcripts/.space-suggestions.json`; this module is the shape of that file
+// and every rule that orders, groups and bounds it. The page
+// (/cleanup/space), the ops read (`get space-suggestions`) and the /cleanup
+// summary line read the file through these functions. Pure: no fs, so a page
+// and a test call it alike.
+//
+// THE PAGE ONLY PROPOSES. Every suggestion's `actions` is the existing ops
+// call that does it (compress-text, cleanup, relocate, evict-clips,
+// delete-file, compact-saved-videos, drop-saved-alternate,
+// kept-failed-encodes, live-recording-verify) — there is no new way to delete
+// or move here, and the writer refuses whatever it refuses when it runs.
+
+import { formatBytes } from "./format";
+import type { SavedVideoAlternate, SavedVideoPointer } from "./savedVideo";
+
+export const SPACE_SCAN_VERSION = 1;
+export const SPACE_SUGGESTIONS_FILENAME = ".space-suggestions.json";
+export const SPACE_SCAN_JOB_KIND = "space-scan";
+export const SPACE_SCAN_QUEUE = "space-scan";
+// Rows kept per kind per disk; past it the file counts the rest exactly.
+export const SPACE_ITEMS_PER_KIND = 50;
+// The age past which a clip window is proposed for eviction (by age only).
+export const SPACE_CLIP_AGE_DAYS = 30;
+// The age past which a downloader's partial counts as abandoned.
+export const SPACE_PARTIAL_AGE_DAYS = 7;
+// What a move must leave on its target beyond the free-space floor.
+export const SPACE_MOVE_MARGIN_BYTES = 5 * 1024 ** 3;
+
+export type SpaceDiskStatus = "ok" | "not-mounted" | "not-answering";
+
+// What of a disk is the archive's, by what it is. Every figure is allocated
+// bytes (st_blocks × 512, what df counts), each inode once.
+export type SpaceArchiveShare = {
+ // Audio, raw live chat and kept chat captures (the media tier).
+ media: number;
+ // Transcripts, captions, metadata, sidecars: channels' text.
+ text: number;
+ // Fetched clip windows (`data/<id>/clips/`).
+ clips: number;
+ // The saved-video store (containers, alternates, staging, scratch).
+ store: number;
+ // Browser-playable copies (prepare-playable).
+ playable: number;
+ // Site builds (export/.export-builds, export/public, homepage/out).
+ builds: number;
+ // umtool's report projects (its REPORTS_DIR).
+ reports: number;
+ // Everything else under transcripts/ (index.mdb, .jobs, export, …).
+ other: number;
+};
+
+export type SpaceDisk = {
+ id: string;
+ label: string;
+ mountpoint: string | null;
+ status: SpaceDiskStatus;
+ detail?: string;
+ // "corpus disk", "location <label>", "saved-video store", "site builds", "umtool reports".
+ roles: string[];
+ locationIds: string[];
+ sizeBytes: number | null;
+ // Available to an unprivileged write (statfs bavail), at scan time.
+ freeBytes: number | null;
+ archive: SpaceArchiveShare | null;
+ archiveBytes: number | null;
+};
+
+export type SpaceKind =
+ | "compress-captions"
+ | "compress-live-chat"
+ | "clean-audio"
+ | "clean-extra-formats"
+ | "move-media"
+ | "move-store"
+ | "evict-clips"
+ | "stale-partial"
+ | "compact"
+ | "drop-original"
+ | "failed-encode"
+ | "drop-alternate"
+ | "reverify-landing"
+ | "unstored-container";
+
+export const SPACE_KIND_LABELS: Record<SpaceKind, string> = {
+ "compress-captions": "Compress caption tracks",
+ "compress-live-chat": "Compress raw live chats",
+ "clean-audio": "Clean audio of transcribed videos",
+ "clean-extra-formats": "Clean extra audio formats",
+ "move-media": "Move a channel's media to a location",
+ "move-store": "Move the saved-video store",
+ "evict-clips": "Evict old clip windows",
+ "stale-partial": "Remove abandoned partial downloads",
+ compact: "Compact saved videos",
+ "drop-original": "Drop compacted originals",
+ "failed-encode": "Clear failed encodes",
+ "drop-alternate": "Drop saved alternates",
+ "reverify-landing": "Verify live landings again",
+ "unstored-container": "Source containers not in the store",
+};
+
+// The existing ops call that does it (`pnpm ops <op> --json <body>`), which is
+// also what the page's button posts.
+export type SpaceAction = { op: string; body: Record<string, unknown> };
+export type SpaceLink = { href: string; label: string };
+
+export type SpaceSuggestion = {
+ key: string;
+ kind: SpaceKind;
+ slug?: string;
+ id?: string;
+ file?: string;
+ title: string;
+ // What it frees NOW, on which disk. Null: nothing yet (a compaction keeps
+ // its original until a separate drop).
+ frees: { disk: string; bytes: number } | null;
+ // What it may free later, and when.
+ later?: { disk: string; low: number; high: number; when: string };
+ // For a move: what it fills, and whether that leaves the target its floor.
+ fills?: { disk: string; bytes: number; fits: boolean; freeAfter: number | null };
+ basis: "measured" | "estimate";
+ basisText: string;
+ // What is lost or kept: re-fetchable? the only copy? reversible?
+ loss: string;
+ actions?: SpaceAction[];
+ link?: SpaceLink;
+ // The confirm needs this ticked (a person's word the writer asks for).
+ tick?: string;
+ // Files with other hard links: removing this name frees nothing of them.
+ shared?: { files: number; bytes: number };
+ detail?: string;
+ // Shown but not to be run (a move that does not fit): why.
+ disabled?: string;
+};
+
+// Not offered, and why.
+export type SpaceHeld = {
+ key: string;
+ what: string;
+ disk: string | null;
+ bytes: number | null;
+ count: number;
+ why: string;
+ link?: SpaceLink;
+};
+
+// Containers the compaction selector refuses, by its rule.
+export type SpaceRefused = {
+ group: string;
+ count: number;
+ bytes: number;
+ disk: string | null;
+ examples: { slug: string; id: string; bytes: number; reason: string }[];
+};
+
+// The archive's bytes nothing in the editor removes: sized, with the owner.
+export type SpaceUnmanaged = {
+ key: string;
+ what: string;
+ disk: string | null;
+ bytes: number;
+ count?: number;
+ owner: string;
+ command?: string;
+ link?: SpaceLink;
+};
+
+export type SpaceOverflow = { kind: SpaceKind; disk: string | null; count: number; bytes: number; link?: SpaceLink };
+
+export type SpaceProbeMemo = Record<string, { size: number; mtimeMs: number; probe: unknown }>;
+
+export type SpaceScanResult = {
+ version: typeof SPACE_SCAN_VERSION;
+ computedAt: string;
+ tookMs: number;
+ jobId?: string;
+ // settings.minFreeDiskGB, in bytes (0 = no floor).
+ floorBytes: number;
+ disks: SpaceDisk[];
+ suggestions: SpaceSuggestion[];
+ overflow: SpaceOverflow[];
+ held: SpaceHeld[];
+ refused: SpaceRefused[];
+ unmanaged: SpaceUnmanaged[];
+ // Channels the scan did not walk, and why (legacy, moving, inconsistent).
+ notScanned: { slug: string; why: string }[];
+ // Whether the compaction pass ran this time (false: carried from `compactionAt`).
+ compactionAt: string | null;
+ // ffprobe answers by container path, reused while size and mtime match.
+ probes: SpaceProbeMemo;
+};
+
+// --- ordering ------------------------------------------------------------------
+
+function freeShare(d: SpaceDisk): number {
+ if (!d.sizeBytes || d.freeBytes === null) return Number.POSITIVE_INFINITY;
+ return d.freeBytes / d.sizeBytes;
+}
+
+// Most in need first: a disk under the floor, then the smallest share free.
+// A disk the scan could not read (not mounted, not answering) is last.
+export function diskNeedOrder(disks: readonly SpaceDisk[], floorBytes: number): SpaceDisk[] {
+ const under = (d: SpaceDisk) => floorBytes > 0 && d.freeBytes !== null && d.freeBytes < floorBytes;
+ return [...disks].sort((a, b) => {
+ const ra = a.status === "ok" ? 0 : 1;
+ const rb = b.status === "ok" ? 0 : 1;
+ if (ra !== rb) return ra - rb;
+ const ua = under(a) ? 0 : 1;
+ const ub = under(b) ? 0 : 1;
+ if (ua !== ub) return ua - ub;
+ return freeShare(a) - freeShare(b);
+ });
+}
+
+export function fullestDiskId(disks: readonly SpaceDisk[], floorBytes: number): string | null {
+ const first = diskNeedOrder(disks, floorBytes)[0];
+ return first && first.status === "ok" ? first.id : null;
+}
+
+function freesNow(s: SpaceSuggestion): number {
+ return s.frees?.bytes ?? 0;
+}
+
+// Every suggestion that frees bytes on `diskId` (or will, for a compaction),
+// biggest first; one that frees nothing now after every one that does.
+export function suggestionsForDisk(
+ result: Pick<SpaceScanResult, "suggestions">,
+ diskId: string,
+): SpaceSuggestion[] {
+ return result.suggestions
+ .filter((s) => s.frees?.disk === diskId || (!s.frees && s.later?.disk === diskId))
+ .sort((a, b) => freesNow(b) - freesNow(a) || (b.later?.low ?? 0) - (a.later?.low ?? 0));
+}
+
+export type SpaceGroup = { kind: SpaceKind; label: string; bytes: number; laterLow: number; laterHigh: number; rows: SpaceSuggestion[] };
+
+// By kind, each with what it frees in total; the group that frees most first.
+export function groupSuggestions(list: readonly SpaceSuggestion[]): SpaceGroup[] {
+ const by = new Map<SpaceKind, SpaceGroup>();
+ for (const s of list) {
+ let g = by.get(s.kind);
+ if (!g) {
+ g = { kind: s.kind, label: SPACE_KIND_LABELS[s.kind], bytes: 0, laterLow: 0, laterHigh: 0, rows: [] };
+ by.set(s.kind, g);
+ }
+ g.rows.push(s);
+ g.bytes += freesNow(s);
+ g.laterLow += s.later?.low ?? 0;
+ g.laterHigh += s.later?.high ?? 0;
+ }
+ const groups = [...by.values()];
+ for (const g of groups) g.rows.sort((a, b) => freesNow(b) - freesNow(a) || (b.later?.low ?? 0) - (a.later?.low ?? 0));
+ return groups.sort((a, b) => b.bytes - a.bytes || b.laterLow - a.laterLow);
+}
+
+// --- bounds and rules ------------------------------------------------------------
+
+// The target keeps its floor plus a margin after the move, or it does not fit.
+export function moveFit(targetFree: number | null, bytes: number, floorBytes: number): { fits: boolean; freeAfter: number | null } {
+ if (targetFree === null) return { fits: false, freeAfter: null };
+ const freeAfter = targetFree - bytes;
+ return { fits: freeAfter >= floorBytes + SPACE_MOVE_MARGIN_BYTES, freeAfter };
+}
+
+// What compressing `plainBytes` at the controller's ratio gives back.
+export function compressSaving(plainBytes: number, ratio: number): number {
+ return Math.max(0, Math.round(plainBytes * (1 - ratio)));
+}
+
+// At most SPACE_ITEMS_PER_KIND rows per kind and disk, biggest kept; the rest
+// counted exactly so a total never shrinks.
+export function capPerKind(list: readonly SpaceSuggestion[], n = SPACE_ITEMS_PER_KIND): { kept: SpaceSuggestion[]; overflow: SpaceOverflow[] } {
+ const by = new Map<string, SpaceSuggestion[]>();
+ for (const s of list) {
+ const k = `${s.kind}\u0000${s.frees?.disk ?? s.later?.disk ?? ""}`;
+ (by.get(k) ?? by.set(k, []).get(k)!).push(s);
+ }
+ const kept: SpaceSuggestion[] = [];
+ const overflow: SpaceOverflow[] = [];
+ for (const rows of by.values()) {
+ rows.sort((a, b) => freesNow(b) - freesNow(a) || (b.later?.low ?? 0) - (a.later?.low ?? 0));
+ kept.push(...rows.slice(0, n));
+ const rest = rows.slice(n);
+ if (rest.length) {
+ overflow.push({
+ kind: rest[0].kind,
+ disk: rest[0].frees?.disk ?? rest[0].later?.disk ?? null,
+ count: rest.length,
+ bytes: rest.reduce((t, s) => t + freesNow(s), 0),
+ });
+ }
+ }
+ return { kept, overflow };
+}
+
+// The compaction selector's refusal (controller/compactSavedVideos.ts planOne)
+// as its rule, numbers left out; null for one that is not a refusal of a
+// container (already compacted: its original is a drop-original row).
+export function refusalGroup(reason: string): string | null {
+ const r = reason.toLowerCase();
+ if (r.startsWith("already compacted")) return null;
+ if (r.includes("minvideombps")) return "below the bitrate floor";
+ if (r.includes("minheight")) return "below the height floor";
+ if (/^platform .* is not selected/.test(r)) return "platform not selected";
+ if (r.includes("keep-latest")) return "keep-latest (not deliberately stored)";
+ if (r.includes('"override"')) return "override (not known to be deliberate)";
+ if (r.includes("legacy pointer")) return "legacy pointer";
+ if (r.startsWith("already av1")) return "already AV1";
+ if (r.includes("excludefromcompaction")) return "channel opts out";
+ if (r.includes("last compaction failed")) return "last compaction failed";
+ if (r.includes("keeps an original")) return "keeps an earlier original";
+ if (r.includes("not in the store")) return "container missing from the store";
+ if (r.includes("ffprobe could not read")) return "unreadable container";
+ if (r.includes("no video stream")) return "audio-only container";
+ if (r.includes("length is unknown")) return "length unknown";
+ return "other";
+}
+
+// May a non-original alternate be proposed for a drop? A pin keeps every copy
+// of its video (ruling 2, orchestrator's default 24 Nov: a pin bars removing
+// the pinned copy); a proxy is kept on purpose; an original belongs to the
+// compaction rules (drop-original rows); a former original needs the person's
+// own word (`confirmFormerOriginal`).
+export function alternateDisposition(
+ pointer: Pick<SavedVideoPointer, "keepReason">,
+ alt: Pick<SavedVideoAlternate, "keptAs">,
+): { offer: true; confirmFormerOriginal?: true } | { offer: false; why: string } {
+ if (alt.keptAs === "original") return { offer: false, why: "an original a compacted copy was made from (see Drop compacted originals)" };
+ if (alt.keptAs === "proxy") return { offer: false, why: "kept on purpose as the lower-quality proxy" };
+ if (pointer.keepReason === "pin") return { offer: false, why: "the video is pinned: its copies are kept" };
+ if (alt.keptAs === "former-original") return { offer: true, confirmFormerOriginal: true };
+ return { offer: true };
+}
+
+// --- words -----------------------------------------------------------------------
+
+export function usedPercent(d: Pick<SpaceDisk, "sizeBytes" | "freeBytes">, free = d.freeBytes): number | null {
+ if (!d.sizeBytes || free === null) return null;
+ return Math.round(((d.sizeBytes - free) / d.sizeBytes) * 100);
+}
+
+export function ageText(computedAt: string, now = Date.now()): string {
+ const s = Math.max(0, Math.round((now - Date.parse(computedAt)) / 1000));
+ if (!Number.isFinite(s)) return "at an unknown time";
+ if (s < 90) return "just now";
+ const m = Math.round(s / 60);
+ if (m < 90) return `${m} min ago`;
+ const h = Math.round(m / 60);
+ if (h < 48) return `${h} h ago`;
+ return `${Math.round(h / 24)} days ago`;
+}
+
+// The /cleanup page's one line: the fullest disk, its free space now (`live`,
+// by disk id, when the caller has it) and what the scan suggests there.
+export function spaceSummaryLine(
+ result: Pick<SpaceScanResult, "disks" | "suggestions" | "floorBytes" | "computedAt"> | null,
+ live: Record<string, number | undefined>,
+): string | null {
+ if (!result) return null;
+ const id = fullestDiskId(result.disks, result.floorBytes);
+ const d = result.disks.find((x) => x.id === id);
+ if (!d) return null;
+ const free = live[d.id] ?? d.freeBytes;
+ const pct = usedPercent(d, free ?? null);
+ const suggested = suggestionsForDisk(result, d.id).reduce((t, s) => t + freesNow(s), 0);
+ return (
+ `${d.label}: ${free === null || free === undefined ? "free space unknown" : `${formatBytes(free)} free`}` +
+ `${pct === null ? "" : ` (${pct} % used)`} · ~${formatBytes(suggested)} suggested there`
+ );
+}