Public: anyone can read this; the crew can change it.
The data volume's free space is a calm line on the maintenance page that turns amber under 15 percent #16018
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/15999-the-data-volume-s-free-space-is-a-calm-l → main 0 commits fork 3 threads · 3 unresolved
8 files
changed +191
−21
docs/design/areas/disk-line.md added +3
| @@ -0,0 +1,3 @@ | ||
| 1 | # Disk line | |
| 2 | ||
| 3 | `.disk-line` is the one line on /maintenance giving the data volume's free space (src/maintenance/disk_line.ts). Plain muted text above 15% free; under it `data-tone="attn"` turns it amber, with the one sentence on what to do. No banner elsewhere. |
docs/design/size-budget.json +18 −18
| @@ -1,31 +1,31 @@ | ||
| 1 | 1 | { |
| 2 | 2 | "/": { |
| 3 | 3 | "js": 22016, |
| 4 | "css": 47616 | |
| 4 | "css": 48384 | |
| 5 | 5 | }, |
| 6 | 6 | "/explore": { |
| 7 | 7 | "js": 21760, |
| 8 | "css": 47616 | |
| 8 | "css": 48384 | |
| 9 | 9 | }, |
| 10 | 10 | "/map": { |
| 11 | 11 | "js": 28672, |
| 12 | "css": 49152 | |
| 12 | "css": 50176 | |
| 13 | 13 | }, |
| 14 | 14 | "/:owner/:name": { |
| 15 | 15 | "js": 38400, |
| 16 | "css": 47616 | |
| 16 | "css": 48384 | |
| 17 | 17 | }, |
| 18 | 18 | "/changelog": { |
| 19 | 19 | "js": 26880, |
| 20 | "css": 47616 | |
| 20 | "css": 48384 | |
| 21 | 21 | }, |
| 22 | 22 | "/:owner/:name/next": { |
| 23 | 23 | "js": 23296, |
| 24 | "css": 47872 | |
| 24 | "css": 48896 | |
| 25 | 25 | }, |
| 26 | 26 | "/:owner/:name/space": { |
| 27 | 27 | "js": 30208, |
| 28 | "css": 48640 | |
| 28 | "css": 49664 | |
| 29 | 29 | }, |
| 30 | 30 | "/:owner/:name/space.json": { |
| 31 | 31 | "js": 0, |
| @@ -33,46 +33,46 @@ | ||
| 33 | 33 | }, |
| 34 | 34 | "/maintenance": { |
| 35 | 35 | "js": 21760, |
| 36 | "css": 47616 | |
| 36 | "css": 48384 | |
| 37 | 37 | }, |
| 38 | 38 | "/pricing": { |
| 39 | 39 | "js": 21760, |
| 40 | "css": 47616 | |
| 40 | "css": 48384 | |
| 41 | 41 | }, |
| 42 | 42 | "/forges/new": { |
| 43 | 43 | "js": 21760, |
| 44 | "css": 47616 | |
| 44 | "css": 48384 | |
| 45 | 45 | }, |
| 46 | 46 | "/claim": { |
| 47 | 47 | "js": 24320, |
| 48 | "css": 47616 | |
| 48 | "css": 48384 | |
| 49 | 49 | }, |
| 50 | 50 | "/templates": { |
| 51 | 51 | "js": 21760, |
| 52 | "css": 47616 | |
| 52 | "css": 48384 | |
| 53 | 53 | }, |
| 54 | 54 | "/system": { |
| 55 | 55 | "js": 23808, |
| 56 | "css": 48128 | |
| 56 | "css": 48384 | |
| 57 | 57 | }, |
| 58 | 58 | "/feed": { |
| 59 | 59 | "js": 36352, |
| 60 | "css": 48128 | |
| 60 | "css": 48384 | |
| 61 | 61 | }, |
| 62 | 62 | "/board": { |
| 63 | 63 | "js": 26880, |
| 64 | "css": 48128 | |
| 64 | "css": 48384 | |
| 65 | 65 | }, |
| 66 | 66 | "/fleet": { |
| 67 | 67 | "js": 21760, |
| 68 | "css": 48128 | |
| 68 | "css": 48384 | |
| 69 | 69 | }, |
| 70 | 70 | "/talk": { |
| 71 | 71 | "js": 27392, |
| 72 | "css": 49920 | |
| 72 | "css": 50432 | |
| 73 | 73 | }, |
| 74 | 74 | "/:owner/:name/pulls/:number": { |
| 75 | 75 | "js": 32000, |
| 76 | "css": 48128 | |
| 76 | "css": 48384 | |
| 77 | 77 | } |
| 78 | 78 | } |
docs/features/maintenance.md +2
| @@ -29,6 +29,8 @@ count, only when there are some; /system keeps them as a section under its own h | ||
| 29 | 29 | on, "End maintenance now" sits under the status line. The forge's looks picture it as the owner (the slot was |
| 30 | 30 | /repos'). Tests: `test/maintenance-calm.test.ts`, `test/maintain-stale-web.test.ts`. |
| 31 | 31 | |
| 32 | **Disk line (#15999).** Under the heading `/maintenance` and the terminal's Maintenance screen say "Disk: N percent free" for the data volume (`diskLine()` in `src/maintenance/disk_line.ts`, one function for both; N is the share rounded down, and the same figure is compared). Under 15 percent the page turns the line amber with an alert icon and adds what to do: remove old backups, previews and merged branches, or grow the volume; the terminal says the same sentence and lists it under "Needs you" (`l`), and plain under "For information". Nothing is filed and nothing alarms; a volume that reports no size shows no line. To read it, open `/maintenance` as an admin. Tests: `test/maintenance-disk-line.test.ts`. | |
| 33 | ||
| 32 | 34 | **Duties.** `/maintenance`, the terminal's Maintenance screen and the `duties` of MCP `maintenance {action: "status"}` |
| 33 | 35 | list each nightly job and the radar in one line (`src/maintenance/duties.ts`, one function for all three doors): |
| 34 | 36 | when it last ran (UTC), what it found: each issue or pull it filed is a link on the page (plain `owner/name#N` in the terminal), a finding that names none ends "nothing filed", and a reference to a repository you cannot read reads "something you cannot read", never its name, and "overdue". A duty is |
src/maintenance/disk_line.ts added +35
| @@ -0,0 +1,35 @@ | ||
| 1 | /** | |
| 2 | * The data volume's free space as one line for the maintenance page: plain | |
| 3 | * above the line, amber under it with the one thing to do. Reads the figure | |
| 4 | * the forge already has (`DiskReading`); it files and alarms nothing. | |
| 5 | */ | |
| 6 | ||
| 7 | import type { DiskReading } from "../kernel/disk_reading.ts"; | |
| 8 | ||
| 9 | /** Free space under this share of the volume turns the line amber. */ | |
| 10 | export const DISK_LINE_UNDER = 0.15; | |
| 11 | ||
| 12 | export interface DiskLine { | |
| 13 | readonly text: string; | |
| 14 | readonly low: boolean; | |
| 15 | /** The sentence on what to do; empty when not low. */ | |
| 16 | readonly todo: string; | |
| 17 | } | |
| 18 | ||
| 19 | /** Null when the volume reports no size (nothing true to say). */ | |
| 20 | export function diskLine(d: DiskReading): DiskLine | null { | |
| 21 | if (!(d.totalBytes > 0) || !(d.freeBytes >= 0)) return null; | |
| 22 | // One figure, floored, for the words and the comparison: 14.6% prints 14 and is low. | |
| 23 | const percent = Math.floor((d.freeBytes * 100) / d.totalBytes); | |
| 24 | const low = percent < DISK_LINE_UNDER * 100; | |
| 25 | return { | |
| 26 | text: `Disk: ${String(percent)} percent free`, | |
| 27 | low, | |
| 28 | todo: low ? "Free space by removing old backups, previews and merged branches, or grow the volume." : "", | |
| 29 | }; | |
| 30 | } | |
| 31 | ||
| 32 | /** The line as one plain sentence, for the terminal: the same words the page sets in markup. */ | |
| 33 | export function diskSentence(line: DiskLine): string { | |
| 34 | return line.low ? `${line.text}. ${line.todo}` : line.text; | |
| 35 | } |
src/tui/screens/maintenance.ts +9 −3
| @@ -7,6 +7,8 @@ | ||
| 7 | 7 | * refused by the service. Enter, Esc or q closes it. |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | import { diskLine, diskSentence } from "../../maintenance/disk_line.ts"; | |
| 11 | import { readDisk } from "../../kernel/disk_reading.ts"; | |
| 10 | 12 | import { filedText } from "../../maintenance/filed.ts"; |
| 11 | 13 | import { findingLines } from "../../maintenance/findings.ts"; |
| 12 | 14 | import { LEVEL_WORDS, nextLevel, returnLevel, stateLevel, type Level } from "../../maintenance/level.ts"; |
| @@ -65,15 +67,19 @@ export function maintenanceLines(f: Session, standby?: Standby, level?: Level): | ||
| 65 | 67 | const hiddenText = hidden.length === 0 ? [] : ["", ...hidden]; |
| 66 | 68 | // A paused duty waits on a person to resume it, as on the page. |
| 67 | 69 | const paused = dutyStates(f.app.db).filter((d) => d.paused).flatMap((d) => wrap(d.says, INNER)); |
| 68 | if (level === undefined) return [...stalled, ...lead, "", ...facts, ...checks, "", ...dutyText(loud), ...paused, ...quietText, ...findings, ...hiddenText]; | |
| 70 | // The data volume's free space, as on the page (#15999): amber there, so it waits on a person | |
| 71 | // here. | |
| 72 | const disk = diskLine((f.app.config.disk ?? readDisk)(f.app.config.dataDir)); | |
| 73 | const diskText = disk === null ? [] : [...wrap(diskSentence(disk), INNER), ""]; | |
| 74 | if (level === undefined) return [...diskText, ...stalled, ...lead, "", ...facts, ...checks, "", ...dutyText(loud), ...paused, ...quietText, ...findings, ...hiddenText]; | |
| 69 | 75 | // The same split as the page, by the same rule (maintenance/level.ts): what waits on a person, |
| 70 | 76 | // and what is only to read. |
| 71 | 77 | const needs = stateLevel(s.phase) === "needs-you" || returnLevel(last?.healthy) === "needs-you"; |
| 72 | 78 | const overdue = loud.filter((d) => d.overdue); |
| 73 | 79 | const out = |
| 74 | 80 | level === "needs-you" |
| 75 | ? [...stalled, ...(needs ? [...lead, "", ...facts, ...checks, ""] : []), ...dutyText(overdue), ...paused] | |
| 76 | : [...(needs ? [] : [...lead, "", ...facts, ...checks, ""]), ...dutyText(loud.filter((d) => !d.overdue)), ...quietText, ...findings, ...hiddenText]; | |
| 81 | ? [...(disk?.low === true ? diskText : []), ...stalled, ...(needs ? [...lead, "", ...facts, ...checks, ""] : []), ...dutyText(overdue), ...paused] | |
| 82 | : [...(disk?.low === false ? diskText : []), ...(needs ? [] : [...lead, "", ...facts, ...checks, ""]), ...dutyText(loud.filter((d) => !d.overdue)), ...quietText, ...findings, ...hiddenText]; | |
| 77 | 83 | return out.length === 0 ? [level === "needs-you" ? "Nothing here needs you." : "Nothing here to read."] : out; |
| 78 | 84 | } |
| 79 | 85 |
src/web/pages/maintenance.ts +8
| @@ -32,6 +32,8 @@ import { liveLabel } from "../../maintenance/quiet_live.ts"; | ||
| 32 | 32 | import { writePauseFold } from "./maintenance_pause.ts"; |
| 33 | 33 | import { budgetRows } from "./maintenance_budgets.ts"; |
| 34 | 34 | import { statusRow } from "./security.ts"; |
| 35 | import { diskLine } from "../../maintenance/disk_line.ts"; | |
| 36 | import { readDisk } from "../../kernel/disk_reading.ts"; | |
| 35 | 37 | |
| 36 | 38 | function admin(ctx: Ctx): Response | undefined { |
| 37 | 39 | if (!ctx.auth.user) return signInFirst(ctx); |
| @@ -215,7 +217,13 @@ async function maintenanceAnswer(ctx: Ctx): Promise<Response> { | ||
| 215 | 217 | : null; |
| 216 | 218 | // Maintenance being on waits on a person: its sentence and button stay off the calm view. |
| 217 | 219 | const calm = asked === "fyi"; |
| 220 | const disk = diskLine((ctx.app.config.disk ?? readDisk)(ctx.app.config.dataDir)); | |
| 221 | const diskRow = disk === null ? null | |
| 222 | : disk.low | |
The page and the terminal should share one renderer of diskLine(). The terminal screen src/tui/screens/maintenance.ts has no disk line, which breaks the both-doors rule. |
||
| 223 | ? html`<p id="maintenance-disk" class="disk-line mb" data-tone="attn">${icon("alert")} <strong>${disk.text}.</strong> ${disk.todo}</p>` | |
| 224 | : html`<p id="maintenance-disk" class="muted mb">${disk.text}</p>`; | |
| 218 | 225 | const body = html`<div class="page-head"><h1>Maintenance</h1></div> |
| 226 | ${diskRow} | |
| 219 | 227 | ${calm ? null : statusLine} |
| 220 | 228 | ${calm ? null : stalledCard(stalledStep(stalePending), ctx.auth.user!.kind !== "agent")} |
| 221 | 229 | ${idle || calm ? null : html`<p id="maintenance-says" class="muted">${s.says}</p> |
src/web/style/components.ts +3
| @@ -457,6 +457,9 @@ a.sha:hover { color: var(--accent); } | ||
| 457 | 457 | .card[data-tone="danger"] { border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); } |
| 458 | 458 | .card[data-tone="merged"] { border-color: color-mix(in srgb, var(--merged) 40%, var(--border)); } |
| 459 | 459 | .card[data-tone="attn"] { border-color: color-mix(in srgb, var(--attn) 40%, var(--border)); } |
| 460 | /* --attn is under 4.5:1 on the light themes' --bg; mixed toward --fg the words pass AA in all six (the icon keeps the amber). */ | |
| 461 | .disk-line[data-tone="attn"] { color: color-mix(in srgb, var(--attn) 30%, var(--fg)); } | |
| 462 | .disk-line[data-tone="attn"] svg { color: var(--attn); } | |
| 460 | 463 | |
| 461 | 464 | /* ---- look: a picture the forge took, in a hairline frame ---- |
| 462 | 465 | A strip sets a phone beside a desktop: the phone keeps a phone's |
test/maintenance-disk-line.test.ts added +113
| @@ -0,0 +1,113 @@ | ||
| 1 | /** | |
| 2 | * The maintenance page's disk line (#15999): plain at 40%, plain at exactly 15%, amber at 9%; no | |
| 3 | * other page has it. | |
| 4 | */ | |
| 5 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 6 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 7 | import { tmpdir } from "node:os"; | |
| 8 | import { join } from "node:path"; | |
| 9 | import { createApp, type App } from "../src/app.ts"; | |
| 10 | import { createUser, type User } from "../src/core/users.ts"; | |
| 11 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 12 | import { diskLine } from "../src/maintenance/disk_line.ts"; | |
| 13 | import { contrast } from "../src/design/contrast.ts"; | |
| 14 | import { THEMES } from "../src/design/themes.ts"; | |
| 15 | import { createForgeApp } from "../src/tui/forge.ts"; | |
| 16 | import { headlessTerminal } from "../src/tui/term/terminal.ts"; | |
| 17 | import { maintenanceLines } from "../src/tui/screens/maintenance.ts"; | |
| 18 | import { quietLogs } from "./helpers/globals.ts"; | |
| 19 | ||
| 20 | quietLogs(); | |
| 21 | let admin: User, dir = "", app: App, servers: Servers, cookie = ""; | |
| 22 | let pct = 40; | |
| 23 | beforeAll(async () => { | |
| 24 | dir = await mkdtemp(join(tmpdir(), "forge-diskline-")); | |
| 25 | app = createApp({ dataDir: dir, port: 0, disk: () => ({ freeBytes: pct * 1e9, totalBytes: 100e9 }) }); | |
| 26 | servers = await serve(app); | |
| 27 | const made = await createUser(app.db, { username: "boss", email: "[email protected]", password: "a-good-passphrase", origin: "seed", trusted: true, isAdmin: true }); | |
| 28 | if (!made.ok) throw new Error("user"); | |
| 29 | admin = made.value; | |
| 30 | const res = await fetch(`${servers.url}/signin`, { | |
| 31 | method: "POST", redirect: "manual", | |
| 32 | headers: { "content-type": "application/x-www-form-urlencoded", origin: servers.url }, | |
| 33 | body: new URLSearchParams({ username: "boss", password: "a-good-passphrase" }), | |
| 34 | }); | |
| 35 | cookie = (res.headers.get("set-cookie") ?? "").split(";")[0] ?? ""; | |
| 36 | }); | |
| 37 | afterAll(async () => { | |
| 38 | servers.stop(); | |
| 39 | app.close(); | |
| 40 | await rm(dir, { recursive: true, force: true }); | |
| 41 | }); | |
| 42 | const get = async (path = "/maintenance"): Promise<string> => (await fetch(`${servers.url}${path}`, { headers: { cookie } })).text(); | |
| 43 | ||
| 44 | test("40% free is plain text", async () => { | |
| 45 | pct = 40; | |
| 46 | const html = await get(); | |
outdated
This only checks that one exact class string is absent. Assert not.toContain(data-tone="attn") and that the todo sentence is absent. |
||
| 47 | expect(html).toContain("Disk: 40 percent free"); | |
| 48 | expect(html).toMatch(/<p id="maintenance-disk" class="muted mb">/); | |
| 49 | expect(html).not.toContain('data-tone="attn"'); | |
| 50 | }); | |
| 51 | ||
| 52 | test("exactly 15% free is still plain", async () => { | |
| 53 | pct = 15; | |
| 54 | const html = await get(); | |
| 55 | expect(html).toContain("Disk: 15 percent free"); | |
| 56 | expect(html).not.toContain('data-tone="attn"'); | |
| 57 | expect(html).not.toContain("disk-line"); | |
| 58 | expect(html).not.toContain("Free space by removing"); | |
| 59 | expect(html).toMatch(/<p id="maintenance-disk" class="muted mb">/); | |
| 60 | }); | |
| 61 | ||
| 62 | test("14.6% free prints 14 and is amber: the figure shown is the one compared", async () => { | |
| 63 | const l = diskLine({ freeBytes: 14.6e9, totalBytes: 100e9 }); | |
| 64 | expect(l?.text).toBe("Disk: 14 percent free"); | |
| 65 | expect(l?.low).toBe(true); | |
| 66 | pct = 14.6; | |
| 67 | const html = await get(); | |
| 68 | expect(html).toContain("Disk: 14 percent free."); | |
| 69 | expect(html).toMatch(/id="maintenance-disk"[^>]*data-tone="attn"/); | |
| 70 | expect(diskLine({ freeBytes: 15e9, totalBytes: 100e9 })?.low).toBe(false); | |
| 71 | }); | |
| 72 | ||
| 73 | test("the terminal screen has the same line and sentence", () => { | |
| 74 | const { session: f } = createForgeApp(app, { sshUsername: admin.username, remoteAddress: "127.0.0.1", fingerprint: "SHA256:t", user: admin }, { terminal: headlessTerminal(120, 40), exitHooks: false }); | |
| 75 | pct = 40; | |
| 76 | expect(maintenanceLines(f).join("\n")).toContain("Disk: 40 percent free"); | |
| 77 | expect(maintenanceLines(f).join("\n")).not.toContain("Free space by removing"); | |
| 78 | pct = 9; | |
| 79 | const all = maintenanceLines(f).join("\n"); | |
| 80 | expect(all).toContain("Disk: 9 percent free."); | |
| 81 | expect(all).toContain("Free space by removing old backups"); | |
| 82 | expect(maintenanceLines(f, undefined, "needs-you").join("\n")).toContain("Disk: 9 percent free"); | |
| 83 | expect(maintenanceLines(f, undefined, "fyi").join("\n")).not.toContain("Disk:"); | |
| 84 | pct = 40; | |
| 85 | expect(maintenanceLines(f, undefined, "fyi").join("\n")).toContain("Disk: 40 percent free"); | |
| 86 | expect(maintenanceLines(f, undefined, "needs-you").join("\n")).not.toContain("Disk:"); | |
| 87 | }); | |
| 88 | ||
| 89 | test("the amber text passes AA on --bg in every theme", () => { | |
| 90 | const mix = (a: string, b: string): string => | |
| 91 | "#" + [1, 3, 5].map((i) => Math.round(parseInt(a.slice(i, i + 2), 16) * 0.3 + parseInt(b.slice(i, i + 2), 16) * 0.7).toString(16).padStart(2, "0")).join(""); | |
| 92 | for (const [name, t] of Object.entries(THEMES)) { | |
| 93 | const k = t.tokens as Record<string, string>; | |
| 94 | expect(contrast(mix(k["attn"]!, k["fg"]!), k["bg"]!), name).toBeGreaterThanOrEqual(4.5); | |
| 95 | } | |
| 96 | }); | |
| 97 | ||
| 98 | test("9% free is amber and says what to do", async () => { | |
| 99 | pct = 9; | |
| 100 | const html = await get(); | |
| 101 | expect(html).toMatch(/id="maintenance-disk"[^>]*data-tone="attn"/); | |
| 102 | expect(html).toContain("Disk: 9 percent free."); | |
| 103 | expect(html).toContain("Free space by removing old backups"); | |
| 104 | }); | |
| 105 | ||
| 106 | test("no other page carries the line", async () => { | |
| 107 | pct = 9; | |
| 108 | expect(await get("/")).not.toContain("maintenance-disk"); | |
| 109 | }); | |
| 110 | ||
| 111 | test("a volume with no size says nothing", () => { | |
| 112 | expect(diskLine({ freeBytes: 0, totalBytes: 0 })).toBeNull(); | |
| 113 | }); |
new above
offline
Math.round shows 15 for 14.6% while low is true. Use the same figure for both (Math.floor, or compare the rounded share).