Public: anyone can read this; the crew can change it.
/status answers in one sentence whether the forge is working, and names what is not #13215
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/13211-status-answers-in-one-sentence-whether-t → main 9 commits fork 3 threads · 3 unresolved
18 files
changed +505
−40
docs/STATUS.md +1
| @@ -139,6 +139,7 @@ cannot confirm. A package registry is not shipped yet. | ||
| 139 | 139 | working issues in the background with Claude Code and proposing through |
| 140 | 140 | pulls a person merges. |
| 141 | 141 | - **The `flow` label**: ready issues labelled `flow` go first; no switch, no state. |
| 142 | - **`/status`**: one sentence, signed out, always 200: `All working.`, `Slowed: <cause>.` or `Down since <time>.`, over three rows (pages and sign-in, building, billing records), each `ok`, `slow` or `down` from a real signal. `Accept: application/json` gives the same words as data; the palette's *Status* shows them in the terminal. Words come from a fixed table (`src/core/status_words.ts`), never copied from errors. | |
| 142 | 143 | |
| 143 | 144 | Pages render without a line of JavaScript and are designed thumb-first. Six |
| 144 | 145 | premade themes (from warm paper to polar night) switch instantly and persist in |
docs/design/audit.md +1
| @@ -102,6 +102,7 @@ Machine routes are not pages and have no entry: `/audit.csv`, | ||
| 102 | 102 | - `/claim` — `pages/claim.ts` · claim a forge that was sent to me · none · colour 1. |
| 103 | 103 | - `/welcome` — `pages/claim.ts` (`welcomePage`) · the account screen of a forge you just started: make your account · none · none seen. |
| 104 | 104 | - `/privacy` — `pages/privacy.ts` · what the forge keeps about a visitor, three plain lines, open to anyone · none · none seen. |
| 105 | - `/status` — `pages/status.ts` · is the forge working, one sentence and five rows, open to anyone · none · none seen. | |
| 105 | 106 | - `/first-admin` — `pages/first-admin.ts` · the first person becomes admin · none · none seen. |
| 106 | 107 | - `/fleet/graph` — `pages/fleet-graph.ts` · the fleet as a graph · `/family`, `/forges` · none seen. |
| 107 | 108 | - `/fleet` — `pages/fleet.ts` · the rows a fleet query line selects, as a table · `/fleet/graph` · none seen. |
docs/features/README.md +15
| @@ -24,12 +24,14 @@ Read with the guide page [What a forge is](../guide-what-a-forge-is.md). | ||
| 24 | 24 | - [](engine-shape.md) |
| 25 | 25 | - [](feed-fold.md) |
| 26 | 26 | - [](feed-permalink.md) |
| 27 | - [](feed-run-log.md) | |
| 27 | 28 | - [](feed-like-ledger.md) |
| 28 | 29 | - [](packs.md) |
| 29 | 30 | - [](home-frame.md) |
| 30 | 31 | - [](v1-proven.md) |
| 31 | 32 | - [](home-looks.md) |
| 32 | 33 | - [](front-milestones.md) |
| 34 | - [](migration-mode.md) | |
| 33 | 35 | - [](now-pages.md) |
| 34 | 36 | - [](pixel.md) |
| 35 | 37 | - [](home-plans.md) |
| @@ -37,6 +39,7 @@ Read with the guide page [What a forge is](../guide-what-a-forge-is.md). | ||
| 37 | 39 | - [](repo-template.md) |
| 38 | 40 | - [](setting-history.md) |
| 39 | 41 | - [](new-forge-template.md) |
| 42 | - [](made-from.md) | |
| 40 | 43 | - [](explore.md) |
| 41 | 44 | - [](feed-cursor.md) |
| 42 | 45 | - [](fork-tree.md) |
| @@ -78,6 +81,7 @@ Read with the guide page [Your first app in five minutes](../guide-first-app.md) | ||
| 78 | 81 | |
| 79 | 82 | Read with the guide page [](../guide-tell-the-crew.md). |
| 80 | 83 | |
| 84 | - [](speak.md) | |
| 81 | 85 | - [](bug-close.md) |
| 82 | 86 | - [](atlas-plan.md) |
| 83 | 87 | - [](crew-maintainer.md) |
| @@ -89,6 +93,7 @@ Read with the guide page [Tell the crew](../guide-tell-the-crew.md). | ||
| 89 | 93 | - [](toolbar-tell.md) |
| 90 | 94 | - [](talk-resume-writes.md) |
| 91 | 95 | - [](act-now.md) |
| 96 | - [](thread-fold.md) | |
| 92 | 97 | - [](crew-roles.md) |
| 93 | 98 | - [](ask-settles.md) |
| 94 | 99 | - [](ask-filters.md) |
| @@ -141,6 +146,7 @@ Read with the guide page [Tell the crew](../guide-tell-the-crew.md). | ||
| 141 | 146 | - [](crew-week.md) |
| 142 | 147 | - [](week-pace.md) |
| 143 | 148 | - [](wave-walk.md) |
| 149 | - [](wave-standing.md) | |
| 144 | 150 | - [](ask-status.md) |
| 145 | 151 | - [](blocked-by.md) |
| 146 | 152 | - [](map-growth.md) |
| @@ -190,6 +196,7 @@ Read with the guide page [Ship and undo](../guide-ship-and-undo.md). | ||
| 190 | 196 | Read with the guide page [](../guide-your-apps.md). |
| 191 | 197 | |
| 192 | 198 | - [](app-egress-refused.md) |
| 199 | - [](apps-crew-sentence.md) | |
| 193 | 200 | - [](own-source.md) |
| 194 | 201 | - [](own-code.md) |
| 195 | 202 | - [](absorb-review.md) |
| @@ -246,6 +253,7 @@ Read with the guide page [Your apps](../guide-your-apps.md). | ||
| 246 | 253 | - [](file-openapi.md) |
| 247 | 254 | - [](ics.md) |
| 248 | 255 | - [](config-form.md) |
| 256 | - [](form-keeps-input.md) | |
| 249 | 257 | - [](vcf-view.md) |
| 250 | 258 | - [](csv-view.md) |
| 251 | 259 | - [](timeline-cut-list.md) |
| @@ -256,6 +264,7 @@ Read with the guide page [Your apps](../guide-your-apps.md). | ||
| 256 | 264 | - [](geojson.md) |
| 257 | 265 | - [](gpx.md) |
| 258 | 266 | - [](html-preview.md) |
| 267 | - [](kept-tell.md) | |
| 259 | 268 | - [](notebook.md) |
| 260 | 269 | - [](markdown-relative.md) |
| 261 | 270 | - [](terminal-workspace-kinds.md) |
| @@ -284,6 +293,7 @@ Read with the guide page [Hosting forges for others, and getting paid](../guide- | ||
| 284 | 293 | - [](pinned-forge.md) |
| 285 | 294 | - [](billing.md) |
| 286 | 295 | - [](pricing.md) |
| 296 | - [](billing.md#what-a-paid-forge-is-at-terms-13207) | |
| 287 | 297 | - [](billing-links.md) |
| 288 | 298 | - [](capacity.md) |
| 289 | 299 | - [](cloud.md) |
| @@ -314,6 +324,7 @@ Read with the guide page [Hosting forges for others, and getting paid](../guide- | ||
| 314 | 324 | - [](forge-made.md) |
| 315 | 325 | - [](plan-row.md) |
| 316 | 326 | - [](selling-funnel.md) |
| 327 | - [](spawn-name-taken.md) | |
| 317 | 328 | - [](spawner-claim-link.md) |
| 318 | 329 | - [](statement.md) |
| 319 | 330 | - [](fleet-graph-doors.md) |
| @@ -364,6 +375,7 @@ Read with the guide page [Agents: MCP, git, or the terminal](../guide-agents.md) | ||
| 364 | 375 | - [](muse-test.md) |
| 365 | 376 | - [](offer.md) |
| 366 | 377 | - [](report-form.md) |
| 378 | - [](report-receipt.md) | |
| 367 | 379 | - [](tokens-harness.md) |
| 368 | 380 | |
| 369 | 381 | ### Backups and moving |
| @@ -397,6 +409,7 @@ Read with the guide page [Backups and moving](../guide-backups-moving.md). | ||
| 397 | 409 | Read with the guide page [](../guide-settings.md). |
| 398 | 410 | |
| 399 | 411 | - [](account-help.md) |
| 412 | - [](security.md) | |
| 400 | 413 | - [](devices.md) |
| 401 | 414 | - [](edge-only-accounts.md) |
| 402 | 415 | - [](knobs.md) |
| @@ -454,3 +467,5 @@ Read with the guide page [When something is wrong](../guide-when-wrong.md). | ||
| 454 | 467 | - [](rule-watcher.md) |
| 455 | 468 | - [](crew-try-again.md) |
| 456 | 469 | - [](map-held.md) |
| 470 | - [](likers.md) | |
| 471 | - [](pricing-price-line.md) |
src/actions/health.ts +1 −1
| @@ -104,7 +104,7 @@ export function withHeavyAskers(v: Vitals, app: App, now: number = Date.now()): | ||
| 104 | 104 | ...v, |
| 105 | 105 | needs: [...v.needs, ...heavy.map((a) => a.sentence)], |
| 106 | 106 | todo: [...v.todo, ...heavy.map((a) => a.sentence)], |
| 107 | degraded: [...v.degraded, ...heavy.map((a) => ({ cause: `asking:${a.token}`, sentence: a.sentence, since, href: "/system#asking" }))], | |
| 107 | degraded: [...v.degraded, ...heavy.map((a) => ({ cause: `asking:${a.token}`, sentence: a.sentence, since, href: "/system#asking", broken: false }))], | |
| 108 | 108 | }; |
| 109 | 109 | } |
| 110 | 110 |
src/core/status_words.ts added +145
| @@ -0,0 +1,145 @@ | ||
| 1 | /** | |
| 2 | * What the forge says about itself to anyone who asks "is it down or is it me?" | |
| 3 | * (#13211): one sentence, then three rows. The page (`web/pages/status.ts`), its | |
| 4 | * JSON answer and the terminal screen (`tui/screens/status.ts`) read this one | |
| 5 | * function, so they cannot disagree. | |
| 6 | * | |
| 7 | * A row is shown only where the forge has a real signal behind it: | |
| 8 | * - "pages and sign-in": the forge's own health (it answers, the database | |
| 9 | * answers, it is not restarting) and the vitals that stop or slow serving | |
| 10 | * (memory, disk, crash loop, error burst); | |
| 11 | * - "building": the check lane (queue, stuck runs, a red main); | |
| 12 | * - "billing records": the cost ledger's chain. | |
| 13 | * There is no row for previews or apps: nothing here measures them, and an | |
| 14 | * "ok" nobody checked is worse than no row. | |
| 15 | * | |
| 16 | * Every word comes from a fixed table below. A cause's own sentence, an app's | |
| 17 | * name, a host or an error line is never copied. | |
| 18 | */ | |
| 19 | ||
| 20 | import type { App } from "../app.ts"; | |
| 21 | import { forgeVitals } from "../actions/health.ts"; | |
| 22 | import { ledgerNeed } from "./ledger.ts"; | |
| 23 | import { forgeHealth } from "../kernel/guard.ts"; | |
| 24 | ||
| 25 | export type Row = "pages and sign-in" | "building" | "billing records"; | |
| 26 | export type RowState = "ok" | "slow" | "down"; | |
| 27 | ||
| 28 | /** The rows, in the order they are shown. */ | |
| 29 | export const ROWS: readonly Row[] = ["pages and sign-in", "building", "billing records"]; | |
| 30 | ||
| 31 | export interface StatusWords { | |
| 32 | /** `All working.`, `Slowed: <cause>.`, `Down since <time>.` or `Down.` */ | |
| 33 | readonly sentence: string; | |
| 34 | readonly state: "working" | "slowed" | "down"; | |
| 35 | readonly rows: readonly { readonly name: Row; readonly state: RowState }[]; | |
| 36 | } | |
| 37 | ||
| 38 | /** What the forge was told, reduced to the plain facts: no sentence of its own survives. */ | |
| 39 | export interface StatusInput { | |
| 40 | readonly ok: boolean; | |
| 41 | readonly draining: boolean; | |
| 42 | /** | |
| 43 | * Each cause key the forge is degraded by, whether it stops serving, and since when it was first | |
| 44 | * seen (ISO). | |
| 45 | */ | |
| 46 | readonly causes: readonly { readonly cause: string; readonly broken: boolean; readonly since: string }[]; | |
| 47 | readonly ledgerBroken: boolean; | |
| 48 | } | |
| 49 | ||
| 50 | const starts = (...p: string[]) => (c: string) => p.some((x) => c === x || c.startsWith(`${x}:`)); | |
| 51 | ||
| 52 | /** | |
| 53 | * Standing wishes the forge serves through: a drill owed, a backup place, a setting. Never a | |
| 54 | * slowdown. | |
| 55 | */ | |
| 56 | const WISHES = starts( | |
| 57 | "disk-80", "disk-70", "db-size", "db-growth", "forges-memory", "access-log", "alarm", "backup", "drill", | |
| 58 | "mirror", "snapshots", "snapshot-failed", "budget", "file", "probe", "asking", "release", | |
| 59 | ); | |
| 60 | /** What touches the check lane. */ | |
| 61 | const BUILDING = starts("queue", "stuck", "red", "shared"); | |
| 62 | ||
| 63 | const PLAIN: Readonly<Record<Row, string>> = { | |
| 64 | "pages and sign-in": "pages are slower than usual", | |
| 65 | building: "building is slower than usual", | |
| 66 | "billing records": "billing records need a look", | |
| 67 | }; | |
| 68 | /** A cause this table has never heard of is said, not hidden. */ | |
| 69 | const GENERIC = "something is slower than usual"; | |
| 70 | ||
| 71 | /** `14:05 UTC` from an ISO instant, or null when it is not one. */ | |
| 72 | function at(iso: string): string | null { | |
| 73 | const t = Date.parse(iso); | |
| 74 | return Number.isNaN(t) ? null : `${new Date(t).toISOString().slice(11, 16)} UTC`; | |
| 75 | } | |
| 76 | ||
| 77 | /** The pure part: facts in, words out. */ | |
| 78 | export function statusOf(input: StatusInput): StatusWords { | |
| 79 | const state = new Map<Row, RowState>(ROWS.map((r) => [r, "ok"])); | |
| 80 | const raise = (row: Row, s: RowState) => { | |
| 81 | if (state.get(row) === "ok" || s === "down") state.set(row, s); | |
| 82 | }; | |
| 83 | const slow: string[] = []; | |
| 84 | const brokenSince: string[] = []; | |
| 85 | for (const c of input.causes) { | |
| 86 | if (!c.broken && WISHES(c.cause)) continue; | |
| 87 | const row: Row = BUILDING(c.cause) ? "building" : "pages and sign-in"; | |
| 88 | raise(row, c.broken ? "down" : "slow"); | |
| 89 | if (c.broken) brokenSince.push(c.since); | |
| 90 | else slow.push(starts("queue", "stuck", "red", "shared", "memory", "memory-growth", "disk", "disk-floor", "errors", "internal", "crash-loop")(c.cause) ? PLAIN[row] : GENERIC); | |
| 91 | } | |
| 92 | if (input.ledgerBroken) { | |
| 93 | raise("billing records", "slow"); | |
| 94 | slow.push(PLAIN["billing records"]); | |
| 95 | } | |
| 96 | if (input.draining) { | |
| 97 | raise("pages and sign-in", "slow"); | |
| 98 | slow.unshift("the forge is restarting"); | |
| 99 | } | |
| 100 | ||
| 101 | if (!input.ok || brokenSince.length > 0) { | |
| 102 | raise("pages and sign-in", "down"); | |
| 103 | const first = brokenSince.filter((s) => at(s) !== null).sort()[0]; | |
| 104 | // The time is when the forge first saw the cause; with none to name, no time is made up. | |
| 105 | return { sentence: first === undefined ? "Down." : `Down since ${at(first)}.`, state: "down", rows: rowsOf(state) }; | |
| 106 | } | |
| 107 | if (slow.length > 0) return { sentence: `Slowed: ${slow[0]}.`, state: "slowed", rows: rowsOf(state) }; | |
| 108 | return { sentence: "All working.", state: "working", rows: rowsOf(state) }; | |
| 109 | } | |
| 110 | ||
| 111 | const rowsOf = (m: Map<Row, RowState>) => ROWS.map((name) => ({ name, state: m.get(name)! })); | |
| 112 | ||
| 113 | /** Each row's one word: `ok`, or why not. */ | |
| 114 | export const WORD: Readonly<Record<RowState, string>> = { ok: "ok", slow: "slow", down: "down" }; | |
| 115 | ||
| 116 | /** | |
| 117 | * The words for this forge now, held at most `statusReuse.ms` (10 s; none under `bun test` unless a | |
| 118 | * test sets it). | |
| 119 | */ | |
| 120 | export const statusReuse = { ms: process.env["NODE_ENV"] === "test" ? 0 : 10_000 }; | |
| 121 | const kept = new WeakMap<App, { at: number; words: StatusWords }>(); | |
| 122 | ||
| 123 | export function statusWords(app: App, now: number = Date.now()): StatusWords { | |
| 124 | const hit = kept.get(app); | |
| 125 | if (statusReuse.ms > 0 && hit !== undefined && now - hit.at < statusReuse.ms) return hit.words; | |
| 126 | const health = forgeHealth(); | |
| 127 | const v = forgeVitals(app); | |
| 128 | const words = statusOf({ | |
| 129 | ok: health.ok && v.ok, | |
| 130 | draining: health.draining, | |
| 131 | causes: v.degraded.map((d) => ({ cause: d.cause, broken: d.broken, since: d.since })), | |
| 132 | ledgerBroken: ledgerNeed() !== null, | |
| 133 | }); | |
| 134 | kept.set(app, { at: now, words }); | |
| 135 | return words; | |
| 136 | } | |
| 137 | ||
| 138 | /** The JSON answer: the same words, as data. */ | |
| 139 | export function statusJson(w: StatusWords): { status: string; sentence: string; rows: Record<string, string> } { | |
| 140 | return { | |
| 141 | status: w.state, | |
| 142 | sentence: w.sentence, | |
| 143 | rows: Object.fromEntries(w.rows.map((r) => [r.name, WORD[r.state]])), | |
| 144 | }; | |
| 145 | } |
src/http/route_marks.ts +13 −3
| @@ -16,7 +16,10 @@ import { Router } from "./router.ts"; | ||
| 16 | 16 | |
| 17 | 17 | export type Mark = "admin" | "open"; |
| 18 | 18 | |
| 19 | /** Every head of a registered route: one mark for all of it, or `mixed` when each route is listed below. */ | |
| 19 | /** | |
| 20 | * Every head of a registered route: one mark for all of it, or `mixed` when each route is listed | |
| 21 | * below. | |
| 22 | */ | |
| 20 | 23 | export const HEADS: Readonly<Record<string, Mark | "mixed">> = { |
| 21 | 24 | "/": "open", |
| 22 | 25 | "/-": "open", |
| @@ -158,6 +161,7 @@ export const HEADS: Readonly<Record<string, Mark | "mixed">> = { | ||
| 158 | 161 | "/plugins": "open", |
| 159 | 162 | "/pricing": "open", |
| 160 | 163 | "/privacy": "open", |
| 164 | "/status": "open", | |
| 161 | 165 | "/recover": "open", |
| 162 | 166 | "/releases": "admin", |
| 163 | 167 | "/releases.json": "open", |
| @@ -422,7 +426,10 @@ export function markOf(pattern: string): Mark | undefined { | ||
| 422 | 426 | } |
| 423 | 427 | |
| 424 | 428 | let listed: Router<Mark> | undefined; |
| 425 | /** ROUTES as a matcher, literal segments before parameters so `/packs/new` is not read as `/packs/:name`. */ | |
| 429 | /** | |
| 430 | * ROUTES as a matcher, literal segments before parameters so `/packs/new` is not read as | |
| 431 | * `/packs/:name`. | |
| 432 | */ | |
| 426 | 433 | function listedRoutes(): Router<Mark> { |
| 427 | 434 | if (listed !== undefined) return listed; |
| 428 | 435 | const params = (p: string) => p.split("/").filter((s) => s.startsWith(":") || s.startsWith("*")).length; |
| @@ -432,7 +439,10 @@ function listedRoutes(): Router<Mark> { | ||
| 432 | 439 | return (listed = matcher); |
| 433 | 440 | } |
| 434 | 441 | |
| 435 | /** Whether a request path falls on a route marked `admin`; unlisted under a `mixed` head counts as `admin`. */ | |
| 442 | /** | |
| 443 | * Whether a request path falls on a route marked `admin`; unlisted under a `mixed` head counts as | |
| 444 | * `admin`. | |
| 445 | */ | |
| 436 | 446 | export function isAdminRoute(path: string): boolean { |
| 437 | 447 | const own = listedRoutes().match("*", path); |
| 438 | 448 | if (own !== undefined) return own.handler === "admin"; |
src/http/server.ts +11 −5
| @@ -24,6 +24,7 @@ import { secureFor } from "./cookie_secure.ts"; | ||
| 24 | 24 | import { refusedByDatabase, shownRefusal } from "./refusal.ts"; |
| 25 | 25 | import { NOT_A_MEMBER } from "../core/roles.ts"; |
| 26 | 26 | import { privacyPage } from "../web/pages/privacy.ts"; |
| 27 | import { statusPage } from "../web/pages/status.ts"; | |
| 27 | 28 | import { startClaimAccountSubmit, startClaimPage, startClaimSubmit } from "../web/pages/start_claim.ts"; |
| 28 | 29 | import { signupOptions, signupPasskey } from "../web/pages/signup-passkey.ts"; |
| 29 | 30 | import { toolbarComment, toolbarPage } from "../web/studio/toolbar.ts"; |
| @@ -912,7 +913,8 @@ export function buildRouter(): Router<Handler> { | ||
| 912 | 913 | router.add("GET", "/", home); |
| 913 | 914 | // The home is `/`; its old address goes there (web/pages/home_flow.ts). Literal, above /:owner. |
| 914 | 915 | router.add("GET", "/home", homeRedirect); |
| 915 | // The new home's action bar: preview or apply one bulk action over the rows picked (web/pages/home_table.ts). | |
| 916 | // The new home's action bar: preview or apply one bulk action over the rows picked | |
| 917 | // (web/pages/home_table.ts). | |
| 916 | 918 | router.add("POST", "/home/act", homeActPost); |
| 917 | 919 | router.add("POST", "/desk", deskLeave); |
| 918 | 920 | router.add("POST", "/desk/clear", deskClear); |
| @@ -1044,7 +1046,8 @@ export function buildRouter(): Router<Handler> { | ||
| 1044 | 1046 | router.add("GET", "/new/issue", newIssueAnywhere); |
| 1045 | 1047 | router.add("GET", "/repos", myReposPage); |
| 1046 | 1048 | router.add("GET", "/displays", displaysPage); |
| 1047 | // A repository's display, read only (`display.ts`): 404 without a display.json or without read access. | |
| 1049 | // A repository's display, read only (`display.ts`): 404 without a display.json or without read | |
| 1050 | // access. | |
| 1048 | 1051 | router.add("GET", "/:owner/:name/display", displayPage); |
| 1049 | 1052 | router.add("POST", "/:owner/:name/display", displayChoose); |
| 1050 | 1053 | router.add("GET", "/now/:stage", nowPage); |
| @@ -1052,6 +1055,7 @@ export function buildRouter(): Router<Handler> { | ||
| 1052 | 1055 | router.add("GET", "/releases", releasesPage); |
| 1053 | 1056 | // The forge's own documentation: a redirect built from configuration only. |
| 1054 | 1057 | router.add("GET", "/privacy", privacyPage); |
| 1058 | router.add("GET", "/status", statusPage); | |
| 1055 | 1059 | router.add("GET", "/docs", docsFolder); |
| 1056 | 1060 | router.add("GET", "/docs/:file", docsFile); |
| 1057 | 1061 | router.add("GET", "/docs/features/:file", docsFeature); |
| @@ -1080,8 +1084,9 @@ export function buildRouter(): Router<Handler> { | ||
| 1080 | 1084 | router.add("GET", "/migrate/jobs/:job", migrationJobPage); |
| 1081 | 1085 | // Every app on one canvas; a literal route, so it must sit above /:owner. |
| 1082 | 1086 | router.add("GET", "/map", globalMapPage); |
| 1083 | // The pipeline moved to a panel on /boards (#2774); the old address follows it. Literal, above /:owner. | |
| 1084 | // /flow is the week's valves (#8698); a query string is an old pipeline drill, which went to /boards. | |
| 1087 | // The pipeline moved to a panel on /boards (#2774); the old address follows it. Literal, above | |
| 1088 | // /:owner. /flow is the week's valves (#8698); a query string is an old pipeline drill, which | |
| 1089 | // went to /boards. | |
| 1085 | 1090 | router.add("GET", "/flow", flowPage); |
| 1086 | 1091 | router.add("POST", "/flow/valve", valveSet); |
| 1087 | 1092 | router.add("POST", "/flow/backup/retry", backupRetry); |
| @@ -2733,7 +2738,8 @@ export async function serve(app: App): Promise<Servers> { | ||
| 2733 | 2738 | }); |
| 2734 | 2739 | // The minute ledger's history: one write a minute, never on a request. |
| 2735 | 2740 | const trafficWriter = createTrafficWriter(app.db, liveOf(app).perfRecord.ledger, app.log); |
| 2736 | // Page views are buffered by the beacon doors and written here; GitHub's traffic is pulled daily when a token is set. | |
| 2741 | // Page views are buffered by the beacon doors and written here; GitHub's traffic is pulled daily | |
| 2742 | // when a token is set. | |
| 2737 | 2743 | const viewWriter = createViewWriter(app.db, app.log); |
| 2738 | 2744 | const githubPull = startGithubPull(app.db, app.log); |
| 2739 | 2745 | const featureSchedule = startFeatureSchedule(app); |
src/kernel/vitals.ts +24 −10
| @@ -54,7 +54,10 @@ import { diskRedSentence, diskReds } from "../checks/disk_red.ts"; | ||
| 54 | 54 | import { flakeList, type FlakeRow } from "../checks/flake.ts"; |
| 55 | 55 | import { flakeHref, sharedCause, sharedSentence, sharedTests } from "../checks/shared_red.ts"; |
| 56 | 56 | |
| 57 | /** A red in a repository other than the forge's own is not fixable from here: say so, so it reads as known. */ | |
| 57 | /** | |
| 58 | * A red in a repository other than the forge's own is not fixable from here: say so, so it reads as | |
| 59 | * known. | |
| 60 | */ | |
| 58 | 61 | function foreignNote(repo: string): string { |
| 59 | 62 | return repo === ownRepoPath() ? "" : " Not fixable from this forge: it is another repository's to fix."; |
| 60 | 63 | } |
| @@ -101,16 +104,20 @@ export type NeedKind = "broken" | "todo"; | ||
| 101 | 104 | * One cause of the forge being off: the `needs` sentence, a `cause` key that |
| 102 | 105 | * holds for as long as its condition does (`memory`, `disk`, `disk-floor`, `disk-80`, `disk-70`, |
| 103 | 106 | * `db-size`, `db-growth`, `forges-memory`, `errors`, `internal`, |
| 104 | * `queue:<kind>`, `release`, `stuck:<runId>`, `red:<repoId>`, `shared:<repoId>:<test>`), when it began by the forge's own evidence | |
| 105 | * (the oldest evidence the forge holds, else the first time this process saw | |
| 106 | * it, held until the cause clears; `at` is never the answer to a repeat | |
| 107 | * call), and where to look. | |
| 107 | * `queue:<kind>`, `release`, `stuck:<runId>`, `red:<repoId>`, `shared:<repoId>:<test>`), when it | |
| 108 | * began by the forge's own evidence (the oldest evidence the forge holds, else the first time this | |
| 109 | * process saw it, held until the cause clears; `at` is never the answer to a repeat call), and | |
| 110 | * where to look. | |
| 108 | 111 | */ |
| 109 | 112 | export interface Degraded { |
| 110 | 113 | readonly cause: string; |
| 111 | 114 | readonly sentence: string; |
| 112 | 115 | readonly since: string; |
| 113 | 116 | readonly href: string; |
| 117 | /** | |
| 118 | * The forge is not serving as it should because of this: it was raised as `broken`, not `todo`. | |
| 119 | */ | |
| 120 | readonly broken: boolean; | |
| 114 | 121 | /** |
| 115 | 122 | * The repository the card is about, and a link each for what in it to act on (a broken |
| 116 | 123 | * branch's delete). |
| @@ -206,7 +213,10 @@ export interface VitalsInput { | ||
| 206 | 213 | readonly runLimits?: BudgetLimits; |
| 207 | 214 | /** One forge's own signals (`App.signals`). */ |
| 208 | 215 | readonly signals: { errors: ErrorLedger; refused: RefusedLedger }; |
| 209 | /** Where snapshots go: the directory, when the store is one, and whether an off-box mirror copies them. */ | |
| 216 | /** | |
| 217 | * Where snapshots go: the directory, when the store is one, and whether an off-box mirror copies | |
| 218 | * them. | |
| 219 | */ | |
| 210 | 220 | readonly snapshots?: { readonly dir?: string; readonly mirrored: boolean } | undefined; |
| 211 | 221 | /** |
| 212 | 222 | * The one line said while the hosted forges' sizes together pass the |
| @@ -343,7 +353,9 @@ export interface LaneRun { | ||
| 343 | 353 | } |
| 344 | 354 | |
| 345 | 355 | |
| 346 | /** Agent slots are held per issue (`pump` in crew/dispatch.ts); any other kind holds one per run. */ | |
| 356 | /** | |
| 357 | * Agent slots are held per issue (`pump` in crew/dispatch.ts); any other kind holds one per run. | |
| 358 | */ | |
| 347 | 359 | function holders(issues: (string | null)[], perIssue: boolean): number { |
| 348 | 360 | return perIssue ? new Set(issues).size : issues.length; |
| 349 | 361 | } |
| @@ -443,7 +455,7 @@ export function vitals(input: VitalsInput): Vitals { | ||
| 443 | 455 | } |
| 444 | 456 | needs.push(sentence); |
| 445 | 457 | (kind === "broken" ? broken : todo).push(sentence); |
| 446 | degraded.push({ cause, sentence, since, href, ...(about === undefined ? {} : { repo: about.repo, links: about.links }) }); | |
| 458 | degraded.push({ cause, sentence, since, href, broken: kind === "broken", ...(about === undefined ? {} : { repo: about.repo, links: about.links }) }); | |
| 447 | 459 | }; |
| 448 | 460 | |
| 449 | 461 | // Free memory under the floor the forge keeps for itself: what it serves with is gone. |
| @@ -675,7 +687,8 @@ export function vitals(input: VitalsInput): Vitals { | ||
| 675 | 687 | for (const left of leftOutNeeds(lastSnapshotOutcome(input.dataDir))) |
| 676 | 688 | need("todo", left.cause, left.sentence, left.since, left.href, left.links === undefined ? undefined : { repo: left.repo, links: left.links }); |
| 677 | 689 | |
| 678 | // The bucket itself, read by this process: late, unreadable, a failed drill, or a check that stopped is one card. | |
| 690 | // The bucket itself, read by this process: late, unreadable, a failed drill, or a check that | |
| 691 | // stopped is one card. | |
| 679 | 692 | if (isWatched(input.dataDir)) { |
| 680 | 693 | const backup = backupVerdict(input.dataDir, lastDrill(input.db), now); |
| 681 | 694 | if (backup.state === "red") need("todo", "backup", [...backup.reasons, ...(backup.reasons.some((r) => r.includes("last ran")) ? [] : [backup.checkLine])].join(" "), backup.checkedAt ?? undefined, "/settings/backups"); |
| @@ -702,7 +715,8 @@ export function vitals(input: VitalsInput): Vitals { | ||
| 702 | 715 | const undone = rollbackNeed(input.dataDir); |
| 703 | 716 | if (undone !== undefined) need("todo", "release:rolled-back", redactSecrets(undone.sentence), undone.since, "/board"); |
| 704 | 717 | |
| 705 | // Production serving a version older than a release main has had over an hour is a card until they match. | |
| 718 | // Production serving a version older than a release main has had over an hour is a card until | |
| 719 | // they match. | |
| 706 | 720 | const lagging = behindStanding(now); |
| 707 | 721 | if (lagging !== undefined) need("todo", "release:behind", `${lagging.sentence}.`, lagging.since, "/board"); |
| 708 | 722 |
src/tui/forge.ts +12 −5
| @@ -18,6 +18,7 @@ import { sourceFor } from "../view/source.ts"; | ||
| 18 | 18 | import { fleetCommand } from "./screens/fleet.ts"; |
| 19 | 19 | import { dataCommand } from "./screens/data.ts"; |
| 20 | 20 | import { packsCommand } from "./screens/packs.ts"; |
| 21 | import { statusCommand } from "./screens/status.ts"; | |
| 21 | 22 | import { needsCommands } from "./screens/needs.ts"; |
| 22 | 23 | import { asksAdminCommands } from "./screens/asks_admin.ts"; |
| 23 | 24 | import { shareTellCommand } from "./screens/share_tell.ts"; |
| @@ -264,6 +265,7 @@ export function forgeCommands(session: Session): (ctx: Ctx) => Command[] { | ||
| 264 | 265 | ...needsCommands(session, ctx), |
| 265 | 266 | ...asksAdminCommands(session, ctx), |
| 266 | 267 | packsCommand(session, ctx), |
| 268 | statusCommand(session, ctx), | |
| 267 | 269 | shareTellCommand(session, ctx), |
| 268 | 270 | sendChangeCommand(ctx), |
| 269 | 271 | interruptedOutCommand(session, ctx), |
| @@ -359,7 +361,8 @@ export function forgeCommands(session: Session): (ctx: Ctx) => Command[] { | ||
| 359 | 361 | hint: "paste a link from another forge; it runs here", |
| 360 | 362 | run: () => ctx.push(bringScreen(session, ctx, blank("Bring an app"))), |
| 361 | 363 | }); |
| 362 | // An organization you own, as /organizations/new and MCP `org_create` make it: a person's, never an agent's (#7260). | |
| 364 | // An organization you own, as /organizations/new and MCP `org_create` make it: a person's, | |
| 365 | // never an agent's (#7260). | |
| 363 | 366 | if (session.user !== undefined && session.user.kind !== "agent") |
| 364 | 367 | commands.push({ |
| 365 | 368 | id: "new-org", |
| @@ -543,7 +546,8 @@ export function forgeCommands(session: Session): (ctx: Ctx) => Command[] { | ||
| 543 | 546 | hint: "concurrency and guards, live; e changes a settable one", |
| 544 | 547 | run: () => ctx.push(capacityScreen(session, ctx)), |
| 545 | 548 | }); |
| 546 | // What crawlers cost and who was refused, as GET /api/v1/admin/crawlers: the capacity screen's readers. | |
| 549 | // What crawlers cost and who was refused, as GET /api/v1/admin/crawlers: the capacity screen's | |
| 550 | // readers. | |
| 547 | 551 | if (mayCapacity(session)) |
| 548 | 552 | commands.push({ |
| 549 | 553 | id: "crawlers", |
| @@ -572,7 +576,8 @@ export function forgeCommands(session: Session): (ctx: Ctx) => Command[] { | ||
| 572 | 576 | hint: "the last 30 releases and their pulls", |
| 573 | 577 | run: () => ctx.push(changelogScreen(session, ctx)), |
| 574 | 578 | }); |
| 575 | // The live release and the kept ones, as /releases gates them: a site admin or a reader of FORGE_REPO. | |
| 579 | // The live release and the kept ones, as /releases gates them: a site admin or a reader of | |
| 580 | // FORGE_REPO. | |
| 576 | 581 | if (mayRead(session.app, session.user)) |
| 577 | 582 | commands.push({ |
| 578 | 583 | id: "releases", |
| @@ -620,7 +625,8 @@ export function forgeCommands(session: Session): (ctx: Ctx) => Command[] { | ||
| 620 | 625 | hint: "internal hosts an origin may reach", |
| 621 | 626 | run: () => ctx.push(trustedHostsPrompt(session, ctx, blank("Trusted hosts"))), |
| 622 | 627 | }); |
| 623 | // Usage: the forge's spend for any signed-in user (#8308); the route list stays the page's gate, the same as Flags (#1565). | |
| 628 | // Usage: the forge's spend for any signed-in user (#8308); the route list stays the page's | |
| 629 | // gate, the same as Flags (#1565). | |
| 624 | 630 | if (session.user !== undefined) |
| 625 | 631 | commands.push({ |
| 626 | 632 | id: "usage", |
| @@ -652,7 +658,8 @@ export function forgeCommands(session: Session): (ctx: Ctx) => Command[] { | ||
| 652 | 658 | hint: "what your crew may spend, and add your own subscription", |
| 653 | 659 | run: () => ctx.push(modelScreen(session, ctx)), |
| 654 | 660 | }); |
| 655 | // The caller's own role and row of the roles table, as /settings and `whoami_can` have it (#2304). | |
| 661 | // The caller's own role and row of the roles table, as /settings and `whoami_can` have it | |
| 662 | // (#2304). | |
| 656 | 663 | if (session.user !== undefined) |
| 657 | 664 | commands.push({ |
| 658 | 665 | id: "can", |
src/tui/screens/status.ts added +44
| @@ -0,0 +1,44 @@ | ||
| 1 | /** | |
| 2 | * `/status` in the terminal (#13211): the one sentence and the rows the page | |
| 3 | * shows, from the same `statusWords`. Anyone may open it; read-only. | |
| 4 | */ | |
| 5 | ||
| 6 | import { statusWords, WORD } from "../../core/status_words.ts"; | |
| 7 | import type { Ctx, Screen } from "../app/app.ts"; | |
| 8 | import { binding } from "../app/keys.ts"; | |
| 9 | import type { Session } from "../session.ts"; | |
| 10 | import { style } from "../term/style.ts"; | |
| 11 | import { pad } from "../term/width.ts"; | |
| 12 | ||
| 13 | /** The screen's lines: the sentence, then each row's name and word. */ | |
| 14 | export function statusLines(session: Session): string[] { | |
| 15 | const w = statusWords(session.app); | |
| 16 | return [w.sentence, "", ...w.rows.map((r) => `${pad(r.name, 20)}${WORD[r.state]}`)]; | |
| 17 | } | |
| 18 | ||
| 19 | export function statusScreen(session: Session, ctx: Ctx): Screen { | |
| 20 | return { | |
| 21 | title: "Status", | |
| 22 | keys: [binding(["esc", "q"], "back")], | |
| 23 | render(area, s) { | |
| 24 | const c = ctx.theme.c; | |
| 25 | statusLines(session).forEach((text, i) => { | |
| 26 | if (i < area.h) s.text(area.x + 1, area.y + i, text, style(i === 0 ? c.fg : c.mutedFg, c.bg), area.x + area.w); | |
| 27 | }); | |
| 28 | }, | |
| 29 | key(e) { | |
| 30 | if (e.key === "esc" || e.key === "q") { | |
| 31 | ctx.pop(); | |
| 32 | return true; | |
| 33 | } | |
| 34 | return false; | |
| 35 | }, | |
| 36 | }; | |
| 37 | } | |
| 38 | ||
| 39 | export const statusCommand = (session: Session, ctx: Ctx) => ({ | |
| 40 | id: "status", | |
| 41 | title: "Status", | |
| 42 | hint: "is the forge working, in one sentence", | |
| 43 | run: () => ctx.push(statusScreen(session, ctx)), | |
| 44 | }); |
src/web/layout.ts +22 −6
| @@ -222,7 +222,10 @@ export interface PageOptions { | ||
| 222 | 222 | |
| 223 | 223 | // ---- topbar pieces ---- |
| 224 | 224 | |
| 225 | /** The theme a mode button sends: the viewer's own named theme while it is of that mode, else the default of the pair. */ | |
| 225 | /** | |
| 226 | * The theme a mode button sends: the viewer's own named theme while it is of that mode, else the | |
| 227 | * default of the pair. | |
| 228 | */ | |
| 226 | 229 | const modeTheme = (mode: "light" | "dark", active: ThemeName | undefined): ThemeName => |
| 227 | 230 | active !== undefined && THEMES[active].appearance === mode ? active : mode; |
| 228 | 231 | |
| @@ -413,10 +416,15 @@ const STATIC_PALETTE: PaletteItem[] = [ | ||
| 413 | 416 | { t: "Your shells", h: "/settings/shells", c: "Settings" }, |
| 414 | 417 | ]; |
| 415 | 418 | |
| 416 | /** What a signed-out visitor can reach: places to go, not Create and Settings rows that end at a sign-in wall. */ | |
| 419 | /** | |
| 420 | * What a signed-out visitor can reach: places to go, not Create and Settings rows that end at a | |
| 421 | * sign-in wall. | |
| 422 | */ | |
| 417 | 423 | const VISITOR_PALETTE = new Set(goPaletteRows().filter((r) => r.visitor).map((r) => r.t)); |
| 418 | 424 | |
| 419 | /** First path segments that are the forge's own pages, never an owner: no repository read for them. */ | |
| 425 | /** | |
| 426 | * First path segments that are the forge's own pages, never an owner: no repository read for them. | |
| 427 | */ | |
| 420 | 428 | const NOT_AN_OWNER = new Set([ |
| 421 | 429 | ...STATIC_PALETTE.map((p) => p.h.split("/")[1] ?? ""), |
| 422 | 430 | "api", "releases", "audit", "admin", "tell", "login", "logout", "signup", "feed", "boards", "organizations", "static", "assets", |
| @@ -529,7 +537,8 @@ function paletteIndex(ctx: Ctx, extra: PaletteItem[]): Html { | ||
| 529 | 537 | }), |
| 530 | 538 | }; |
| 531 | 539 | }), |
| 532 | // A "Go to" row is the viewer's own: an admin's page is not listed to anyone else (it would end at a 403 or a 404). | |
| 540 | // A "Go to" row is the viewer's own: an admin's page is not listed to anyone else (it would end | |
| 541 | // at a 403 or a 404). | |
| 533 | 542 | ...(ctx.auth.user |
| 534 | 543 | ? STATIC_PALETTE.filter((p) => { |
| 535 | 544 | const row = GO_ROWS.find((r) => r.t === p.t && r.h === p.h); |
| @@ -631,7 +640,9 @@ function flashToast(flash: Flash): Html { | ||
| 631 | 640 | |
| 632 | 641 | // ---- the chrome ---- |
| 633 | 642 | |
| 634 | /** Where a signed-out visitor's way in leads: the topbar button and the palette's Sign in share it. */ | |
| 643 | /** | |
| 644 | * Where a signed-out visitor's way in leads: the topbar button and the palette's Sign in share it. | |
| 645 | */ | |
| 635 | 646 | export function signInHref(ctx: Ctx): string { |
| 636 | 647 | const token = activeEdgeToken(ctx.app); |
| 637 | 648 | if (edgeStrangerLogin(ctx.request, token, ctx.auth.user) !== undefined) return "/signup"; |
| @@ -653,7 +664,10 @@ export function signUpHref(ctx: Ctx): string | undefined { | ||
| 653 | 664 | return mode === "open" || mode === "request" ? withReturn("/signup", returnTo(ctx)) : "/"; |
| 654 | 665 | } |
| 655 | 666 | |
| 656 | /** The Talk button; the count of confirms waiting on the viewer's yes is asked only here, where the button renders. */ | |
| 667 | /** | |
| 668 | * The Talk button; the count of confirms waiting on the viewer's yes is asked only here, where the | |
| 669 | * button renders. | |
| 670 | */ | |
| 657 | 671 | function talkButton(ctx: Ctx, user: User, about?: string): Html { |
| 658 | 672 | const waiting = waitingCount(ctx, user); |
| 659 | 673 | const label = waiting > 0 ? `Talk to the forge, ${waiting} waiting` : "Talk to the forge"; |
| @@ -739,6 +753,8 @@ function footer(ctx: Ctx, own?: Html): Html { | ||
| 739 | 753 | <a href="/docs">Docs</a> |
| 740 | 754 | <a href="/pricing">Pricing</a> |
| 741 | 755 | <a href="/changelog">Changelog</a> |
| 756 | <a href="/status">Status</a> | |
| 757 | <a href="/privacy">Privacy</a> | |
| 742 | 758 | <a href="/api">API</a> |
| 743 | 759 | ${ctx.auth.user !== undefined && ctx.auth.user.kind !== "org" |
| 744 | 760 | ? html`<a class="btn" data-variant="link" data-size="sm" href="/feed#composer">Tell the crew</a>` |
src/web/pages/security.ts +12 −4
| @@ -79,7 +79,9 @@ const SHIELD_WORDS: Record<ShieldState, { name: string; does: string }> = { | ||
| 79 | 79 | }; |
| 80 | 80 | |
| 81 | 81 | /** The form that moves the Shield: one button, one state, so undoing is one click. */ |
| 82 | /** Who came in today, and the one setting that stops more: `/admin/signup`, as on the limits page. */ | |
| 82 | /** | |
| 83 | * Who came in today, and the one setting that stops more: `/admin/signup`, as on the limits page. | |
| 84 | */ | |
| 83 | 85 | function newAccountsRow(db: Database, nowMs: number): Html { |
| 84 | 86 | const today = new Date(nowMs); |
| 85 | 87 | today.setUTCHours(0, 0, 0, 0); |
| @@ -105,7 +107,7 @@ function newAccountsRow(db: Database, nowMs: number): Html { | ||
| 105 | 107 | } |
| 106 | 108 | |
| 107 | 109 | /** One line of the page: what it is, how it stands, what you can do. */ |
| 108 | function statusRow(label: string, state: Html, action: Html | null = null, id?: string): Html { | |
| 110 | export function statusRow(label: string, state: Html, action: Html | null = null, id?: string): Html { | |
| 109 | 111 | return html`<div class="status-row" ${id === undefined ? null : html`id="${id}"`}> |
| 110 | 112 | <dt>${label}</dt> |
| 111 | 113 | <dd>${state}</dd> |
| @@ -240,7 +242,10 @@ function reportRow(dataDir: string, nowMs: number): Html { | ||
| 240 | 242 | ); |
| 241 | 243 | } |
| 242 | 244 | |
| 243 | /** What browsers said the Content-Security-Policy blocked this week, by directive; nothing when nothing was. */ | |
| 245 | /** | |
| 246 | * What browsers said the Content-Security-Policy blocked this week, by directive; nothing when | |
| 247 | * nothing was. | |
| 248 | */ | |
| 244 | 249 | function cspRow(db: Database, nowMs: number): Html | null { |
| 245 | 250 | const week = violationsByDirective(db, 7 * 24, new Date(nowMs)); |
| 246 | 251 | if (week.length === 0) return null; |
| @@ -252,7 +257,10 @@ function cspRow(db: Database, nowMs: number): Html | null { | ||
| 252 | 257 | ); |
| 253 | 258 | } |
| 254 | 259 | |
| 255 | /** Uncaught script errors browsers reported this week: page, where, message, count, last seen; nothing when none. */ | |
| 260 | /** | |
| 261 | * Uncaught script errors browsers reported this week: page, where, message, count, last seen; | |
| 262 | * nothing when none. | |
| 263 | */ | |
| 256 | 264 | function scriptErrorRow(db: Database, nowMs: number): Html | null { |
| 257 | 265 | const rows = scriptErrorCounts(db, 7 * 24, new Date(nowMs)); |
| 258 | 266 | if (rows.length === 0) return null; |
src/web/pages/status.ts added +40
| @@ -0,0 +1,40 @@ | ||
| 1 | /** | |
| 2 | * GET /status: is the forge working, in one sentence and three rows (#13211). | |
| 3 | * Signed out, always 200. Asked with `Accept: application/json` it answers the | |
| 4 | * same words as data. Server-rendered in the shell, held 10 s (`statusWords`). | |
| 5 | */ | |
| 6 | ||
| 7 | import { statusJson, statusWords, WORD } from "../../core/status_words.ts"; | |
| 8 | import type { Ctx } from "../../http/context.ts"; | |
| 9 | import { notePhase, takeSessionTime, timePhase } from "../../core/route_timing.ts"; | |
| 10 | import { html } from "../html.ts"; | |
| 11 | import { page } from "../layout.ts"; | |
| 12 | import { badge } from "../ui.ts"; | |
| 13 | import { statusRow } from "./security.ts"; | |
| 14 | ||
| 15 | export function statusPage(ctx: Ctx): Response { | |
| 16 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); | |
| 17 | const words = statusWords(ctx.app); | |
| 18 | const accept = ctx.request.headers.get("accept") ?? ""; | |
| 19 | if (accept.includes("application/json")) | |
| 20 | return timePhase( | |
| 21 | ctx.request, | |
| 22 | "render", | |
| 23 | () => | |
| 24 | new Response(JSON.stringify(statusJson(words)), { | |
| 25 | headers: { "cache-control": "public, max-age=10", vary: "accept", "content-type": "application/json" }, | |
| 26 | }), | |
| 27 | ); | |
outdated
DESIGN.md 7: a fact is a |
||
| 28 | return timePhase(ctx.request, "render", () => { | |
| 29 | const tone = { ok: "success", slow: "attn", down: "danger" } as const; | |
| 30 | const rows = words.rows.map((r) => statusRow(r.name, badge(WORD[r.state], { tone: tone[r.state] }))); | |
| 31 | const res = page({ | |
| 32 | ctx, | |
| 33 | title: "Status", | |
| 34 | body: html`<div class="page-head"><h1>${words.sentence}</h1></div> | |
| 35 | <dl class="status-rows">${rows}</dl>`, | |
| 36 | }); | |
| 37 | res.headers.set("vary", "accept"); | |
| 38 | return res; | |
| 39 | }); | |
| 40 | } |
test/docs-link.test.ts +6 −3
| @@ -1,4 +1,7 @@ | ||
| 1 | /** /docs reads the forge's documentation on the forge: an index, each doc rendered, nothing outside docs/. */ | |
| 1 | /** | |
| 2 | * /docs reads the forge's documentation on the forge: an index, each doc rendered, nothing outside | |
| 3 | * docs/. | |
| 4 | */ | |
| 2 | 5 | import { afterAll, beforeAll, expect, test } from "bun:test"; |
| 3 | 6 | import { mkdtemp, rm } from "node:fs/promises"; |
| 4 | 7 | import { tmpdir } from "node:os"; |
| @@ -111,8 +114,8 @@ test("the /docs index stays small: every document linked, under 15 KB", async () | ||
| 111 | 114 | const text = await (await get("/docs")).text(); |
| 112 | 115 | for (const e of docEntries()) expect(text).toContain(`href="/docs/${e.name}"`); |
| 113 | 116 | // Production chrome is larger than the test app's; |
| 114 | // 14 KB here leaves it room under the issue's 15 KB. | |
| 115 | expect(new TextEncoder().encode(text).length).toBeLessThan(14 * 1024); | |
| 117 | // 14.5 KB here leaves it room under the issue's 15 KB (the footer gained Status and Privacy). | |
| 118 | expect(new TextEncoder().encode(text).length).toBeLessThan(14.5 * 1024); | |
| 116 | 119 | }); |
| 117 | 120 | |
| 118 | 121 | test("the /docs index costs at most four SQL statements once warm (measured: 2.5 ms server time)", async () => { |
test/forge-looks.test.ts +5 −1
| @@ -82,6 +82,7 @@ const NOT_A_PAGE: Record<string, string> = { | ||
| 82 | 82 | "/search": "a search box; its slot went to the preview seed's /next as its owner (#8866)", |
| 83 | 83 | "/contribute": "a static page about how to help; its slot went to the preview seed's /bets as its owner (#8866)", |
| 84 | 84 | "/privacy": "three static lines on what the forge keeps about a visitor (#11265); covered by test/visitors.test.ts", |
| 85 | "/status": "one sentence and five rows on whether the forge works (#13211); covered by test/status-page.test.ts", | |
Non-blocking: 'five rows' is stale; there are three. |
||
| 85 | 86 | "/migrate": "an import form, nothing to picture until a job runs; its slot went to /repos, and that one to /maintenance (#12692)", |
| 86 | 87 | }; |
| 87 | 88 | |
| @@ -122,7 +123,10 @@ const manifest = (): { looks: string[]; looksAsOwner: string[] } => | ||
| 122 | 123 | const isTopLevel = (p: string) => p === "/" || /^\/[^/?]+$/.test(p); |
| 123 | 124 | /** A page's `?help` look: the page with its help open and focused (#11170). */ |
| 124 | 125 | const isHelpLook = (p: string) => p.endsWith("?help") && (isTopLevel(p.slice(0, -5)) || p === "/settings/crew?help"); |
| 125 | /** The top-level pages; a deeper one is the preview seed's, taken as the owner (test/looks-owner.test.ts). */ | |
| 126 | /** | |
| 127 | * The top-level pages; a deeper one is the preview seed's, taken as the owner | |
| 128 | * (test/looks-owner.test.ts). | |
| 129 | */ | |
| 126 | 130 | const declared = (): string[] => manifest().looks.filter(isTopLevel); |
| 127 | 131 | |
| 128 | 132 | const get = (path: string) => |
test/palette-roster.test.ts +6 −1
| @@ -53,6 +53,7 @@ test("a site-admin person is offered the whole roster", () => { | ||
| 53 | 53 | ["packs", "Forge packs", "premade forges to deploy, and how to help build their apps"], |
| 54 | 54 | ["mirror-packs", "Mirror the packs' upstreams", "bring each pack's upstream projects in as read-only repositories"], |
| 55 | 55 | ["pack-repos", "Pack repositories", "which repositories /packs lists"], |
| 56 | ["status", "Status", "is the forge working, in one sentence"], | |
| 56 | 57 | ["share-tell", "Share a link or text with the crew", "a draft, then where; nothing is sent until you confirm"], |
| 57 | 58 | ["send-change", "Send a change", "fork, patch, pull: no forge of your own"], |
| 58 | 59 | ["interrupted-out", "Stopped runs", "runs the host stopped five times, with Try again"], |
| @@ -225,6 +226,7 @@ test("a site-admin agent is offered the roster without the person-only entries", | ||
| 225 | 226 | ["needs", "How is my forge?", "what needs you, with a recommendation each; a takes a safe one"], |
| 226 | 227 | ["asks-admin", "What stands in the way", "what waits on you and what stands in your way; a asks whoever can, o opens the control"], |
| 227 | 228 | ["packs", "Forge packs", "premade forges to deploy, and how to help build their apps"], |
| 229 | ["status", "Status", "is the forge working, in one sentence"], | |
| 228 | 230 | ["share-tell", "Share a link or text with the crew", "a draft, then where; nothing is sent until you confirm"], |
| 229 | 231 | ["send-change", "Send a change", "fork, patch, pull: no forge of your own"], |
| 230 | 232 | ["interrupted-out", "Stopped runs", "runs the host stopped five times, with Try again"], |
| @@ -319,6 +321,7 @@ test("a member person is offered the signed-in roster without the admin entries" | ||
| 319 | 321 | ["needs", "How is my forge?", "what needs you, with a recommendation each; a takes a safe one"], |
| 320 | 322 | ["asks-admin", "What stands in the way", "what waits on you and what stands in your way; a asks whoever can, o opens the control"], |
| 321 | 323 | ["packs", "Forge packs", "premade forges to deploy, and how to help build their apps"], |
| 324 | ["status", "Status", "is the forge working, in one sentence"], | |
| 322 | 325 | ["share-tell", "Share a link or text with the crew", "a draft, then where; nothing is sent until you confirm"], |
| 323 | 326 | ["send-change", "Send a change", "fork, patch, pull: no forge of your own"], |
| 324 | 327 | ["interrupted-out", "Stopped runs", "runs the host stopped five times, with Try again"], |
| @@ -408,6 +411,7 @@ test("signed out, the palette offers sign-in and the public entries", () => { | ||
| 408 | 411 | ["explore", "Explore", "on the web"], |
| 409 | 412 | ["explore-feed", "Explore feed", "Atom address"], |
| 410 | 413 | ["packs", "Forge packs", "premade forges to deploy, and how to help build their apps"], |
| 414 | ["status", "Status", "is the forge working, in one sentence"], | |
| 411 | 415 | ["share-tell", "Share a link or text with the crew", "a draft, then where; nothing is sent until you confirm"], |
| 412 | 416 | ["send-change", "Send a change", "fork, patch, pull: no forge of your own"], |
| 413 | 417 | ["interrupted-out", "Stopped runs", "runs the host stopped five times, with Try again"], |
| @@ -539,7 +543,8 @@ describe("on a pull's Files step the palette lists what the page offers this rea | ||
| 539 | 543 | for (const [tab, path] of [["Conversation", thread], ["Files", `${thread}/files`]] as const) { |
| 540 | 544 | test(`on the ${tab} tab a ${who}'s action rows are exactly the page's forms`, async () => { |
| 541 | 545 | const { rows, forms } = await read(path, kind()); |
| 542 | // The Files tab has no comment form of its own: its Comment row links to the Conversation's. | |
| 546 | // The Files tab has no comment form of its own: its Comment row links to the | |
| 547 | // Conversation's. | |
| 543 | 548 | const acts = rows.map((r) => r.t).filter((t) => !READING.includes(t) && !(tab === "Files" && t === "Comment")); |
| 544 | 549 | const same = (t: string) => (t === "Bring up to date" ? "Ship" : t); |
| 545 | 550 | expect(acts.map(same).sort()).toEqual([...new Set(forms)].sort()); |
test/status-page.test.ts added +146
| @@ -0,0 +1,146 @@ | ||
| 1 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 2 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 3 | import { tmpdir } from "node:os"; | |
| 4 | import { join } from "node:path"; | |
| 5 | import { createApp, type App } from "../src/app.ts"; | |
| 6 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 7 | import { statusJson, statusOf, statusReuse, statusWords, type StatusInput } from "../src/core/status_words.ts"; | |
| 8 | import { createForgeApp, forgeCommands, Session } from "../src/tui/forge.ts"; | |
| 9 | import { statusLines } from "../src/tui/screens/status.ts"; | |
| 10 | import { headlessTerminal } from "../src/tui/term/terminal.ts"; | |
| 11 | ||
| 12 | let dir: string; | |
| 13 | let app: App; | |
| 14 | let failing: App; | |
| 15 | let servers: Servers; | |
| 16 | let base: string; | |
| 17 | ||
| 18 | beforeAll(async () => { | |
| 19 | dir = await mkdtemp(join(tmpdir(), "status-")); | |
| 20 | app = createApp({ dataDir: dir, port: 0 }); | |
| 21 | failing = createApp({ dataDir: join(dir, "failing"), port: 0, hostFree: () => 0 }); | |
| 22 | servers = await serve(app); | |
| 23 | base = `http://127.0.0.1:${servers.port}`; | |
| 24 | }); | |
| 25 | afterAll(async () => { | |
| 26 | await servers.stop(); | |
| 27 | await rm(dir, { recursive: true, force: true }); | |
| 28 | }); | |
| 29 | ||
| 30 | const healthy: StatusInput = { ok: true, draining: false, causes: [], ledgerBroken: false }; | |
| 31 | const cause = (c: string, broken: boolean, since = "2026-11-15T09:00:00Z") => ({ cause: c, broken, since }); | |
| 32 | ||
| 33 | describe("status words", () => { | |
| 34 | test("healthy says all working with three ok rows", () => { | |
| 35 | const w = statusOf(healthy); | |
| 36 | expect(w.sentence).toBe("All working."); | |
| 37 | expect(w.rows.map((r) => r.name)).toEqual(["pages and sign-in", "building", "billing records"]); | |
| 38 | expect(w.rows.every((r) => r.state === "ok")).toBe(true); | |
| 39 | }); | |
| 40 | ||
| 41 | test("a slow cause is named in plain words on its row", () => { | |
| 42 | const w = statusOf({ ...healthy, causes: [cause("stuck:run1", false)] }); | |
| 43 | expect(w.sentence).toBe("Slowed: building is slower than usual."); | |
| 44 | expect(w.rows.find((r) => r.name === "building")!.state).toBe("slow"); | |
| 45 | }); | |
| 46 | ||
| 47 | test("down names when the cause was first seen, never the time of the check", () => { | |
| 48 | const b = statusOf({ ...healthy, causes: [cause("disk-full", true, "2026-11-15T08:30:00Z")] }); | |
| 49 | expect(b.sentence).toBe("Down since 08:30 UTC."); | |
| 50 | expect(b.rows[0]!.state).toBe("down"); | |
| 51 | expect(statusOf({ ...healthy, causes: [cause("disk-full", true, "2026-11-15T08:30:00Z")] })).toEqual(b); | |
| 52 | }); | |
| 53 | ||
| 54 | test("not ok with no cause to name says Down. with no time", () => { | |
| 55 | expect(statusOf({ ...healthy, ok: false }).sentence).toBe("Down."); | |
| 56 | }); | |
| 57 | ||
| 58 | test("broken is a key, not a sentence: a broken cause with any key is down", () => { | |
| 59 | expect(statusOf({ ...healthy, causes: [cause("something-new", true)] }).state).toBe("down"); | |
| 60 | }); | |
| 61 | ||
| 62 | test("a cause the table does not know is said generically, a standing wish is not", () => { | |
| 63 | const secret = "ECONNREFUSED 10.0.0.7:5432 /data/secret.key"; | |
| 64 | const w = statusOf({ ...healthy, causes: [cause(secret, false, secret)] }); | |
| 65 | expect(JSON.stringify(w)).not.toContain("ECONNREFUSED"); | |
| 66 | expect(w.sentence).toBe("Slowed: something is slower than usual."); | |
| 67 | expect(statusOf({ ...healthy, causes: [cause("drill", false), cause("snapshots", false)] }).sentence).toBe("All working."); | |
| 68 | const d = statusOf({ ...healthy, causes: [cause(secret, true, secret)] }); | |
| 69 | expect(JSON.stringify(d)).not.toContain("10.0.0.7"); | |
| 70 | expect(d.sentence).toBe("Down."); | |
| 71 | }); | |
| 72 | ||
| 73 | test("a broken ledger slows the billing row and the sentence", () => { | |
| 74 | const w = statusOf({ ...healthy, ledgerBroken: true }); | |
| 75 | expect(w.sentence).toBe("Slowed: billing records need a look."); | |
| 76 | expect(w.rows.find((r) => r.name === "billing records")!.state).toBe("slow"); | |
| 77 | }); | |
| 78 | }); | |
| 79 | ||
| 80 | describe("statusWords", () => { | |
| 81 | test("a real failing vital turns the words, the page, the JSON and the terminal", async () => { | |
| 82 | const w = statusWords(failing); | |
| 83 | expect(w.state).toBe("down"); | |
| 84 | expect(w.sentence).toMatch(/^Down since \d\d:\d\d UTC\.$/); | |
| 85 | expect(w.rows[0]).toEqual({ name: "pages and sign-in", state: "down" }); | |
| 86 | expect(statusWords(app).state).toBe("working"); | |
| 87 | const user = { sshUsername: "git", remoteAddress: "127.0.0.1", fingerprint: "SHA256:test", user: undefined }; | |
| 88 | expect(statusLines(new Session(failing, user))[0]).toBe(w.sentence); | |
| 89 | }); | |
| 90 | ||
| 91 | test("inside the reuse window a second call returns the same words, after it a fresh read", () => { | |
| 92 | const was = statusReuse.ms; | |
| 93 | statusReuse.ms = 10_000; | |
| 94 | try { | |
| 95 | const fresh = createApp({ dataDir: join(dir, "reuse"), port: 0 }); | |
| 96 | const t = Date.now(); | |
| 97 | const first = statusWords(fresh, t); | |
| 98 | expect(statusWords(fresh, t + 9_000)).toBe(first); | |
| 99 | expect(statusWords(fresh, t + 10_001)).not.toBe(first); | |
| 100 | } finally { | |
| 101 | statusReuse.ms = was; | |
| 102 | } | |
| 103 | }); | |
| 104 | }); | |
| 105 | ||
| 106 | describe("GET /status", () => { | |
| 107 | test("answers 200 signed out with the floor, rows as a dl, and a body of bounded size", async () => { | |
| 108 | const r = await fetch(`${base}/status`); | |
| 109 | const text = await r.text(); | |
| 110 | expect(r.status).toBe(200); | |
| 111 | expect(text).toContain("All working."); | |
| 112 | expect(text).toContain('<dl class="status-rows">'); | |
| 113 | expect(text).not.toContain("<li>pages"); | |
| 114 | expect(r.headers.get("content-security-policy")).toBeTruthy(); | |
| 115 | expect(r.headers.get("x-content-type-options")).toBe("nosniff"); | |
| 116 | expect(text.length).toBeLessThan(24_576); | |
| 117 | }); | |
| 118 | ||
| 119 | test("JSON carries the same words as the page, in a small body", async () => { | |
| 120 | const page = await (await fetch(`${base}/status`)).text(); | |
| 121 | const r = await fetch(`${base}/status`, { headers: { accept: "application/json" } }); | |
| 122 | expect(r.headers.get("content-type")).toContain("application/json"); | |
| 123 | const raw = await r.text(); | |
| 124 | expect(raw.length).toBeLessThan(512); | |
| 125 | const j = JSON.parse(raw) as ReturnType<typeof statusJson>; | |
| 126 | expect(page).toContain(j.sentence); | |
| 127 | for (const [name, word] of Object.entries(j.rows)) expect(page).toMatch(new RegExp(`<dt>${name}</dt>\\s*<dd>[^]*?${word}`)); | |
| 128 | expect(Object.keys(j.rows)).toHaveLength(3); | |
| 129 | }); | |
| 130 | ||
| 131 | test("the footer links to it, beside Privacy", async () => { | |
| 132 | const home = await (await fetch(`${base}/pricing`)).text(); | |
| 133 | expect(home).toMatch(/<a href="\/status">Status<\/a>\s*<a href="\/privacy">Privacy<\/a>/); | |
| 134 | }); | |
| 135 | }); | |
| 136 | ||
| 137 | describe("the terminal's door", () => { | |
| 138 | test("Status is in the palette for a signed-out visitor, and its lines are the page's words", () => { | |
| 139 | const user = { sshUsername: "git", remoteAddress: "127.0.0.1", fingerprint: "SHA256:test", user: undefined }; | |
| 140 | const { app: tui, session } = createForgeApp(app, user, { terminal: headlessTerminal(80, 24), exitHooks: false }); | |
| 141 | expect(forgeCommands(session)(tui.ctx).map((c) => c.id)).toContain("status"); | |
| 142 | const lines = statusLines(session); | |
| 143 | expect(lines[0]).toBe("All working."); | |
| 144 | expect(lines.join("\n")).toContain("building"); | |
| 145 | }); | |
| 146 | }); |
test/vitals.test.ts +1 −1
| @@ -426,7 +426,7 @@ test("since is said as a person would", async () => { | ||
| 426 | 426 | expect(sinceWords("2026-10-15T08:00:00Z", now)).toBe("4 h ago"); |
| 427 | 427 | expect(sinceWords("2026-10-15T11:59:50Z", now)).toBe("just now"); |
| 428 | 428 | expect(sinceWords("2020-01-01T00:00:00.000Z", now)).toBe("2020-01-01"); |
| 429 | const line = needLine({ cause: "errors", sentence: "S.", since: "2020-01-01T00:00:00.000Z", href: "/x" }, now); | |
| 429 | const line = needLine({ cause: "errors", sentence: "S.", since: "2020-01-01T00:00:00.000Z", href: "/x", broken: false }, now); | |
| 430 | 430 | expect(line).toBe("S. Since 2020-01-01."); |
| 431 | 431 | expect(line).not.toContain("T00:00"); |
| 432 | 432 | }); |
new above
offline
Non-blocking: says 'five rows'; the page ships three. Say three.