Public: anyone can read this; the crew can change it.
The atlas of abstractions: the forge as one typed object graph; see each abstraction's lifecycle, merge apps (schema + data), an idea garden for demos, one shell for all apps #16939
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/6002-the-atlas-of-abstractions-the-forge-as-o → main 0 commits fork 3 threads · 3 unresolved
16 files
changed +806
−134
- docs/design/attention-budget.json
- docs/design/audit.md
- docs/features/abstractions.md
- src/actions/abstractions.ts
- src/core/abstractions.ts
- src/generated/screens.ts
- src/http/marks/admin.json
- src/http/server.ts
- src/tui/screens/abstractions.ts
- src/tui/screens/system.ts
- src/view/abstraction_words.ts
- src/web/pages/abstractions.ts
- src/web/pages/origins.ts
- test/abstractions.test.ts
- test/forge-looks.test.ts
- test/palette-roster.test.ts
docs/design/attention-budget.json +3 −3
| @@ -113,16 +113,16 @@ | ||
| 113 | 113 | }, |
| 114 | 114 | "settings": { |
| 115 | 115 | "390": { |
| 116 | "words": 147, | |
| 116 | "words": 148, | |
| 117 | 117 | "blocks": 32, |
| 118 | 118 | "colours": 1 |
| 119 | 119 | }, |
| 120 | 120 | "1280": { |
| 121 | "words": 147, | |
| 121 | "words": 148, | |
| 122 | 122 | "blocks": 32, |
| 123 | 123 | "colours": 1 |
| 124 | 124 | }, |
| 125 | "note": "146 words since #13308 (2026-11-15, Settings \u203a Connected agents): its side-nav entry added two words to the 144 main had; 147 since the forge dataset (Settings \u203a Dataset), one word." | |
| 125 | "note": "146 words since #13308 (2026-11-15, Settings \u203a Connected agents): its side-nav entry added two words to the 144 main had; 147 since the forge dataset (Settings \u203a Dataset), one word; 148 since the Tables page (#6002), one word." | |
| 126 | 126 | }, |
| 127 | 127 | "search": { |
| 128 | 128 | "390": { |
docs/design/audit.md +1
| @@ -126,6 +126,7 @@ Machine routes are not pages and have no entry: `/audit.csv`, | ||
| 126 | 126 | - `/maintenance` — `pages/maintenance.ts` · prepare the forge for a power-off and end it · `/resilience`, `/settings/backups` · none seen. |
| 127 | 127 | - `/admin/limits` — `pages/admin-limits.ts` · every limit with value, default and reason · `/settings/capacity` (also a numbers-you-can-change page) · none seen. |
| 128 | 128 | - `/admin/flows` — `pages/flows-all.ts` · every repository's flow lines with state and last moved, by kind and stale · `/:owner/:name/flows` · none seen. |
| 129 | - `/admin/abstractions` — `pages/abstractions.ts` · the forge's tables, one row each: stage, rows, first and last row, use in 28 days, what builds on what · Settings › Tables (This forge) · none seen. | |
| 129 | 130 | - `/admin/data` — `pages/data.ts` · the forge's own database: tables, rows, read-only SQL, secrets masked · `/data` (the Forge data button) · none seen; shares its body (`pages/data_view.ts`) with `/data` and `/:owner/:name/data`. |
| 130 | 131 | - `/settings/appearance` — `pages/account.ts` · every theme as a card that wears its own colours · the Theme row of the account menu (Auto, Light, Dark only) · none seen. |
| 131 | 132 | - `/settings/everyday` — `pages/everyday.ts` · an admin makes the everyday account with a passkey, or keeps working as admin · `/settings` (the pair, once made) · none seen. |
docs/features/abstractions.md added +24
| @@ -0,0 +1,24 @@ | ||
| 1 | --- | |
| 2 | topic: Every setting, by topic | |
| 3 | row: The forge's tables: its own tables, how much each is used, what builds on what | |
| 4 | --- | |
| 5 | # The forge's tables (#6002) | |
| 6 | ||
| 7 | A forge admin's read-only map of the forge's own tables, one row each, under | |
| 8 | **This forge** in settings (`/admin/abstractions`). The terminal shows the same | |
| 9 | rows: palette, **Tables**, or `a` on System (`readAbstractions`, | |
| 10 | `src/core/abstractions.ts`). | |
| 11 | ||
| 12 | - **Stage**: growing, stable, fading, dormant or unused, from events in the last | |
| 13 | 14 days against the 14 before. Fading means less than half as many. | |
| 14 | - **Rows**: counted up to 10000 per table (`10000+` past it), so a big forge | |
| 15 | answers as fast as a small one. **Show sizes** adds bytes; it scans the whole | |
| 16 | database file, so it is asked for. | |
| 17 | - **First row, last row**: the `created_at` of the first and last row written. | |
| 18 | - **Last 28 days**: events whose kind starts `<table>.`, counted as added, | |
| 19 | changed or removed by the verb after the dot. | |
| 20 | - **Builds on, used by**: foreign keys, both ways. | |
| 21 | ||
| 22 | Two lines above the rows name what was used most and what fell away. The atlas | |
| 23 | is read at most once a minute. Anyone who is not an admin, and every agent, gets | |
| 24 | the not-found page. Not yet: apps' own schemas, the graph view, merging. |
src/actions/abstractions.ts added +35
| @@ -0,0 +1,35 @@ | ||
| 1 | /** | |
| 2 | * The atlas of the forge's own abstractions (`core/abstractions.ts`), for a forge admin. Never | |
| 3 | * an agent: the table list and its use say how the forge is run. Everyone else is told `not_found`. | |
| 4 | * | |
| 5 | * Reading it walks 28 days of events and counts every table, so the whole atlas is kept for | |
| 6 | * `ATLAS_TTL_MS` per database; sizes (a scan of the database file) are read only when asked. | |
| 7 | */ | |
| 8 | ||
| 9 | import type { Database } from "bun:sqlite"; | |
| 10 | import type { App } from "../app.ts"; | |
| 11 | import { readAbstractions, type AbstractionAtlas } from "../core/abstractions.ts"; | |
| 12 | import type { User } from "../core/users.ts"; | |
| 13 | import { err, ok, type Result } from "../kernel/result.ts"; | |
| 14 | ||
| 15 | export const ATLAS_TTL_MS = 60_000; | |
| 16 | ||
| 17 | const kept = new WeakMap<Database, { at: number; sized: boolean; atlas: AbstractionAtlas }>(); | |
| 18 | ||
| 19 | /** One rule for every door to the atlas: a forge admin who is not an agent. */ | |
| 20 | export const mayReadAtlas = (user: User | undefined): boolean => user?.isAdmin === true && user.kind !== "agent"; | |
| 21 | ||
| 22 | export function listAbstractions( | |
| 23 | app: App, | |
| 24 | actor: User | undefined, | |
| 25 | o: { sizes?: boolean; now?: Date; clock?: number } = {}, | |
| 26 | ): Result<AbstractionAtlas, "not_found"> { | |
| 27 | if (!mayReadAtlas(actor)) return err("not_found"); | |
| 28 | const clock = o.clock ?? Date.now(); | |
| 29 | const sized = o.sizes === true; | |
| 30 | const hit = kept.get(app.db); | |
| 31 | if (hit !== undefined && clock - hit.at < ATLAS_TTL_MS && (hit.sized || !sized)) return ok(hit.atlas); | |
| 32 | const atlas = readAbstractions(app.db, o.now, sized); | |
| 33 | kept.set(app.db, { at: clock, sized, atlas }); | |
| 34 | return ok(atlas); | |
| 35 | } |
src/core/abstractions.ts added +221
| @@ -0,0 +1,221 @@ | ||
| 1 | /** | |
| 2 | * The forge's abstractions, read from its own database (#6002): one per table | |
| 3 | * in `sqlite_master`, with when its first row was written, its last, how many | |
| 4 | * rows and bytes it holds, which types it references (foreign keys) and which | |
| 5 | * reference it, and how often it was used, counted from the event outbox. | |
| 6 | * | |
| 7 | * A type's use is the events whose kind starts `<table>.` (`pull.opened` is the | |
| 8 | * `pull` table's): created, updated or deleted by the verb after the dot, per | |
| 9 | * day for `WINDOW_DAYS`. Compared half against half, that gives a stage in its | |
| 10 | * life: growing, stable, fading or dormant. Read-only: nothing here writes. | |
| 11 | */ | |
| 12 | ||
| 13 | import type { Database } from "bun:sqlite"; | |
| 14 | ||
| 15 | export const WINDOW_DAYS = 28; | |
| 16 | const HALF = WINDOW_DAYS / 2; | |
| 17 | /** | |
| 18 | * Rows counted per table: past this the count stops, so a huge table costs the same as a small one. | |
| 19 | */ | |
| 20 | export const ROW_CAP = 10_000; | |
| 21 | const DAY_MS = 86_400_000; | |
| 22 | ||
| 23 | export type Stage = "unused" | "growing" | "stable" | "fading" | "dormant"; | |
| 24 | ||
| 25 | export interface Abstraction { | |
| 26 | readonly name: string; | |
| 27 | /** Rows counted up to `ROW_CAP`; `rowsCapped` says the table holds at least that many. */ | |
| 28 | readonly rows: number; | |
| 29 | readonly rowsCapped: boolean; | |
| 30 | /** Bytes the table and its indexes occupy; null where this build cannot say. */ | |
| 31 | readonly bytes: number | null; | |
| 32 | /** `created_at` of the first and the last row written; null without rows or the column. */ | |
| 33 | readonly born: string | null; | |
| 34 | readonly lastTouched: string | null; | |
| 35 | /** Types this one points at, by foreign key. */ | |
| 36 | readonly references: readonly string[]; | |
| 37 | /** Types that point at this one. */ | |
| 38 | readonly usedBy: readonly string[]; | |
| 39 | /** Events per day, oldest first, `WINDOW_DAYS` long. */ | |
| 40 | readonly perDay: readonly number[]; | |
| 41 | readonly created: number; | |
| 42 | readonly updated: number; | |
| 43 | readonly deleted: number; | |
| 44 | /** Events in the later half of the window, and in the earlier half. */ | |
| 45 | readonly recent: number; | |
| 46 | readonly before: number; | |
| 47 | readonly stage: Stage; | |
| 48 | } | |
| 49 | ||
| 50 | export interface AbstractionAtlas { | |
| 51 | readonly types: readonly Abstraction[]; | |
| 52 | /** The three with most events in the later half, busiest first. */ | |
| 53 | readonly busiest: readonly string[]; | |
| 54 | /** The three that fell furthest from the earlier half to the later, most fallen first. */ | |
| 55 | readonly fading: readonly string[]; | |
| 56 | } | |
| 57 | ||
| 58 | const quote = (name: string): string => `"${name.replace(/"/g, '""')}"`; | |
| 59 | ||
| 60 | /** Where a verb falls: the `kind` after the dot, `created`/`opened`/`added`... → create. */ | |
| 61 | export function crudOf(verb: string): "created" | "updated" | "deleted" | null { | |
| 62 | if (/(^|_)(deleted|removed|revoked|closed|ended)$/.test(verb)) return "deleted"; | |
| 63 | if (/(^|_)(updated|set|changed|edited|steered|renamed|transferred)$/.test(verb)) return "updated"; | |
| 64 | if (/(^|_)(created|opened|added|forked|connected|started|minted|registered)$/.test(verb)) return "created"; | |
| 65 | return null; | |
| 66 | } | |
| 67 | ||
| 68 | /** A stage from the two halves of the window (and whether the type holds anything at all). */ | |
| 69 | export function stageOf(recent: number, before: number, rows: number): Stage { | |
| 70 | if (recent === 0 && before === 0) return rows === 0 ? "unused" : "dormant"; | |
| 71 | if (recent > before * 1.5) return "growing"; | |
| 72 | if (recent * 2 < before) return "fading"; | |
| 73 | return "stable"; | |
| 74 | } | |
| 75 | ||
| 76 | function tableNames(db: Database): string[] { | |
| 77 | return ( | |
| 78 | db | |
| 79 | .query<{ name: string }, []>( | |
| 80 | "SELECT name FROM sqlite_master WHERE type = 'table' AND name NOT LIKE 'sqlite\\_%' ESCAPE '\\' ORDER BY name", | |
| 81 | ) | |
| 82 | .all() | |
| 83 | ).map((r) => r.name); | |
| 84 | } | |
| 85 | ||
| 86 | function oneOf<T>(fn: () => T): T | null { | |
| 87 | try { | |
| 88 | return fn(); | |
| 89 | } catch { | |
| 90 | return null; | |
| 91 | } | |
| 92 | } | |
| 93 | ||
| 94 | const CHUNK = 100; | |
| 95 | ||
| 96 | /** One compound statement per chunk of tables, so the cost is not one statement per table. */ | |
| 97 | function perTable<T>(db: Database, names: readonly string[], part: (quoted: string, literal: string) => string, read: (row: Record<string, unknown>) => T): T[] { | |
| 98 | const out: T[] = []; | |
| 99 | for (let i = 0; i < names.length; i += CHUNK) { | |
| 100 | const sql = names | |
| 101 | .slice(i, i + CHUNK) | |
| 102 | .map((n) => part(quote(n), `'${n.replace(/'/g, "''")}'`)) | |
| 103 | .join(" UNION ALL "); | |
| 104 | const rows = oneOf(() => db.query<Record<string, unknown>, []>(sql).all()); | |
| 105 | if (rows) for (const r of rows) out.push(read(r)); | |
| 106 | } | |
| 107 | return out; | |
| 108 | } | |
| 109 | ||
| 110 | /** | |
| 111 | * Every table the database holds, as an abstraction, with use counted to `now`. Sizes come from | |
| 112 | * a scan of the whole database file, so they are read only with `withSizes`. | |
| 113 | */ | |
| 114 | export function readAbstractions(db: Database, now: Date = new Date(), withSizes = false): AbstractionAtlas { | |
| 115 | const names = tableNames(db); | |
| 116 | const known = new Set(names); | |
| 117 | const today = Math.floor(now.getTime() / DAY_MS); | |
| 118 | const first = today - WINDOW_DAYS + 1; | |
| 119 | const since = new Date(first * DAY_MS).toISOString(); | |
| 120 | ||
| 121 | const use = new Map<string, { perDay: number[]; created: number; updated: number; deleted: number }>(); | |
| 122 | const events = db | |
| 123 | .query<{ kind: string; day: string; n: number }, [string]>( | |
| 124 | "SELECT kind, substr(created_at, 1, 10) AS day, COUNT(*) AS n FROM event WHERE created_at >= ? GROUP BY kind, day", | |
| 125 | ) | |
| 126 | .all(since); | |
| 127 | for (const e of events) { | |
| 128 | const dot = e.kind.indexOf("."); | |
| 129 | const type = dot > 0 ? e.kind.slice(0, dot) : ""; | |
| 130 | if (!known.has(type)) continue; | |
| 131 | const u = use.get(type) ?? { perDay: new Array<number>(WINDOW_DAYS).fill(0), created: 0, updated: 0, deleted: 0 }; | |
| 132 | const index = Math.floor(Date.parse(`${e.day}T00:00:00Z`) / DAY_MS) - first; | |
| 133 | if (index >= 0 && index < WINDOW_DAYS) u.perDay[index]! += e.n; | |
| 134 | const crud = crudOf(e.kind.slice(dot + 1)); | |
| 135 | if (crud !== null) u[crud] += e.n; | |
| 136 | use.set(type, u); | |
| 137 | } | |
| 138 | ||
| 139 | const pointsAt = new Map<string, Set<string>>(); | |
| 140 | const referencedBy = new Map<string, Set<string>>(); | |
| 141 | for (const name of names) pointsAt.set(name, new Set()); | |
| 142 | for (const fk of db | |
| 143 | .query<{ from: string; to: string }, []>( | |
| 144 | "SELECT m.name AS \"from\", f.\"table\" AS \"to\" FROM sqlite_master m, pragma_foreign_key_list(m.name) f WHERE m.type = 'table'", | |
| 145 | ) | |
| 146 | .all()) { | |
| 147 | if (fk.from === fk.to || !known.has(fk.from) || !known.has(fk.to)) continue; | |
| 148 | pointsAt.get(fk.from)!.add(fk.to); | |
| 149 | referencedBy.set(fk.to, (referencedBy.get(fk.to) ?? new Set()).add(fk.from)); | |
| 150 | } | |
| 151 | ||
| 152 | const counts = new Map(perTable(db, names, (q, lit) => `SELECT ${lit} AS t, COUNT(*) AS n FROM (SELECT 1 FROM ${q} LIMIT ${ROW_CAP + 1})`, (r) => [r.t as string, Number(r.n)] as const)); | |
| 153 | const dated = new Set( | |
| 154 | db | |
| 155 | .query<{ name: string }, []>( | |
| 156 | "SELECT m.name AS name FROM sqlite_master m, pragma_table_info(m.name) c WHERE m.type = 'table' AND c.name = 'created_at'", | |
| 157 | ) | |
| 158 | .all() | |
| 159 | .map((r) => r.name), | |
| 160 | ); | |
| 161 | const str = (v: unknown): string | null => (typeof v === "string" ? v : null); | |
| 162 | const edges = new Map( | |
| 163 | perTable( | |
| 164 | db, | |
| 165 | names.filter((n) => dated.has(n)), | |
| 166 | (q, lit) => | |
| 167 | `SELECT ${lit} AS t, (SELECT created_at FROM ${q} ORDER BY rowid ASC LIMIT 1) AS born, (SELECT created_at FROM ${q} ORDER BY rowid DESC LIMIT 1) AS last`, | |
| 168 | (r) => [r.t as string, { born: str(r.born), last: str(r.last) }] as const, | |
| 169 | ), | |
| 170 | ); | |
| 171 | ||
| 172 | const sizes = new Map<string, number>(); | |
| 173 | if (withSizes) oneOf(() => { | |
| 174 | for (const r of db | |
| 175 | .query<{ t: string; s: number }, []>( | |
| 176 | "SELECT m.tbl_name AS t, SUM(d.pgsize) AS s FROM dbstat d JOIN sqlite_master m ON m.name = d.name GROUP BY m.tbl_name", | |
| 177 | ) | |
| 178 | .all()) | |
| 179 | sizes.set(r.t, r.s); | |
| 180 | }); | |
| 181 | ||
| 182 | const types = names.map((name): Abstraction => { | |
| 183 | const u = use.get(name); | |
| 184 | const perDay = u?.perDay ?? new Array<number>(WINDOW_DAYS).fill(0); | |
| 185 | const before = perDay.slice(0, HALF).reduce((a, b) => a + b, 0); | |
| 186 | const recent = perDay.slice(HALF).reduce((a, b) => a + b, 0); | |
| 187 | const counted = counts.get(name) ?? 0; | |
| 188 | const rows = Math.min(counted, ROW_CAP); | |
| 189 | const bytes = sizes.get(name) ?? null; | |
| 190 | const { born, last } = edges.get(name) ?? { born: null, last: null }; | |
| 191 | return { | |
| 192 | name, | |
| 193 | rows, | |
| 194 | rowsCapped: counted > ROW_CAP, | |
| 195 | bytes, | |
| 196 | born, | |
| 197 | lastTouched: last, | |
| 198 | references: [...(pointsAt.get(name) ?? [])].sort(), | |
| 199 | usedBy: [...(referencedBy.get(name) ?? [])].sort(), | |
| 200 | perDay, | |
| 201 | created: u?.created ?? 0, | |
| 202 | updated: u?.updated ?? 0, | |
| 203 | deleted: u?.deleted ?? 0, | |
| 204 | recent, | |
| 205 | before, | |
| 206 | stage: stageOf(recent, before, rows), | |
| 207 | }; | |
| 208 | }); | |
| 209 | ||
| 210 | const busiest = types | |
| 211 | .filter((t) => t.recent > 0) | |
| 212 | .sort((a, b) => b.recent - a.recent || a.name.localeCompare(b.name)) | |
| 213 | .slice(0, 3) | |
| 214 | .map((t) => t.name); | |
| 215 | const fading = types | |
| 216 | .filter((t) => t.stage === "fading") | |
| 217 | .sort((a, b) => b.before - b.recent - (a.before - a.recent) || a.name.localeCompare(b.name)) | |
| 218 | .slice(0, 3) | |
| 219 | .map((t) => t.name); | |
| 220 | return { types, busiest, fading }; | |
| 221 | } |
src/generated/screens.ts +131 −129
| @@ -1,129 +1,130 @@ | ||
| 1 | 1 | // Generated by `bun scripts/own-source.ts`; do not edit. `test/own-source.test.ts` fails when it is |
| 2 | 2 | // stale. |
| 3 | 3 | |
| 4 | import * as s0 from "../tui/screens/access.ts"; | |
| 5 | import * as s1 from "../tui/screens/account_access.ts"; | |
| 6 | import * as s2 from "../tui/screens/agents.ts"; | |
| 7 | import * as s3 from "../tui/screens/app_templates.ts"; | |
| 8 | import * as s4 from "../tui/screens/apps_crew.ts"; | |
| 9 | import * as s5 from "../tui/screens/archived.ts"; | |
| 10 | import * as s6 from "../tui/screens/ask_data.ts"; | |
| 11 | import * as s7 from "../tui/screens/audit.ts"; | |
| 12 | import * as s8 from "../tui/screens/bets.ts"; | |
| 13 | import * as s9 from "../tui/screens/billing.ts"; | |
| 14 | import * as s10 from "../tui/screens/billinglinks.ts"; | |
| 15 | import * as s11 from "../tui/screens/bills.ts"; | |
| 16 | import * as s12 from "../tui/screens/boards.ts"; | |
| 17 | import * as s13 from "../tui/screens/bottleneck.ts"; | |
| 18 | import * as s14 from "../tui/screens/bugs.ts"; | |
| 19 | import * as s15 from "../tui/screens/bulk.ts"; | |
| 20 | import * as s16 from "../tui/screens/captain.ts"; | |
| 21 | import * as s17 from "../tui/screens/childcredit.ts"; | |
| 22 | import * as s18 from "../tui/screens/claim_link.ts"; | |
| 23 | import * as s19 from "../tui/screens/claim_start.ts"; | |
| 24 | import * as s20 from "../tui/screens/cloud.ts"; | |
| 25 | import * as s21 from "../tui/screens/codes.ts"; | |
| 26 | import * as s22 from "../tui/screens/connections.ts"; | |
| 27 | import * as s23 from "../tui/screens/controls.ts"; | |
| 28 | import * as s24 from "../tui/screens/cores.ts"; | |
| 29 | import * as s25 from "../tui/screens/crewbudgets.ts"; | |
| 30 | import * as s26 from "../tui/screens/crewhandover.ts"; | |
| 31 | import * as s27 from "../tui/screens/crewkey.ts"; | |
| 32 | import * as s28 from "../tui/screens/crewsplits.ts"; | |
| 33 | import * as s29 from "../tui/screens/crewtop.ts"; | |
| 34 | import * as s30 from "../tui/screens/dataset.ts"; | |
| 35 | import * as s31 from "../tui/screens/design.ts"; | |
| 36 | import * as s32 from "../tui/screens/design_gallery.ts"; | |
| 37 | import * as s33 from "../tui/screens/devices.ts"; | |
| 38 | import * as s34 from "../tui/screens/disks.ts"; | |
| 39 | import * as s35 from "../tui/screens/displays.ts"; | |
| 40 | import * as s36 from "../tui/screens/domains.ts"; | |
| 41 | import * as s37 from "../tui/screens/dotfiles.ts"; | |
| 42 | import * as s38 from "../tui/screens/drift.ts"; | |
| 43 | import * as s39 from "../tui/screens/dutybudgets.ts"; | |
| 44 | import * as s40 from "../tui/screens/dutyswitch.ts"; | |
| 45 | import * as s41 from "../tui/screens/economics.ts"; | |
| 46 | import * as s42 from "../tui/screens/edgeonly.ts"; | |
| 47 | import * as s43 from "../tui/screens/experiments.ts"; | |
| 48 | import * as s44 from "../tui/screens/featurefeed.ts"; | |
| 49 | import * as s45 from "../tui/screens/features.ts"; | |
| 50 | import * as s46 from "../tui/screens/featureswitch.ts"; | |
| 51 | import * as s47 from "../tui/screens/feed.ts"; | |
| 52 | import * as s48 from "../tui/screens/flowsall.ts"; | |
| 53 | import * as s49 from "../tui/screens/footing.ts"; | |
| 54 | import * as s50 from "../tui/screens/forgeready.ts"; | |
| 55 | import * as s51 from "../tui/screens/forges.ts"; | |
| 56 | import * as s52 from "../tui/screens/forgeview.ts"; | |
| 57 | import * as s53 from "../tui/screens/front.ts"; | |
| 58 | import * as s54 from "../tui/screens/frontms.ts"; | |
| 59 | import * as s55 from "../tui/screens/funnel.ts"; | |
| 60 | import * as s56 from "../tui/screens/games.ts"; | |
| 61 | import * as s57 from "../tui/screens/gifts.ts"; | |
| 62 | import * as s58 from "../tui/screens/health_voice.ts"; | |
| 63 | import * as s59 from "../tui/screens/home_pins.ts"; | |
| 64 | import * as s60 from "../tui/screens/hostreach.ts"; | |
| 65 | import * as s61 from "../tui/screens/infra.ts"; | |
| 66 | import * as s62 from "../tui/screens/inventory.ts"; | |
| 67 | import * as s63 from "../tui/screens/invites.ts"; | |
| 68 | import * as s64 from "../tui/screens/knobs.ts"; | |
| 69 | import * as s65 from "../tui/screens/lapsed.ts"; | |
| 70 | import * as s66 from "../tui/screens/limits.ts"; | |
| 71 | import * as s67 from "../tui/screens/loopstalls.ts"; | |
| 72 | import * as s68 from "../tui/screens/madefrom.ts"; | |
| 73 | import * as s69 from "../tui/screens/maintainruns.ts"; | |
| 74 | import * as s70 from "../tui/screens/maintenance.ts"; | |
| 75 | import * as s71 from "../tui/screens/maintenanceweek.ts"; | |
| 76 | import * as s72 from "../tui/screens/mergedbranches.ts"; | |
| 77 | import * as s73 from "../tui/screens/mirrorpacks.ts"; | |
| 78 | import * as s74 from "../tui/screens/model.ts"; | |
| 79 | import * as s75 from "../tui/screens/money.ts"; | |
| 80 | import * as s76 from "../tui/screens/newissue.ts"; | |
| 81 | import * as s77 from "../tui/screens/next.ts"; | |
| 82 | import * as s78 from "../tui/screens/nowlist.ts"; | |
| 83 | import * as s79 from "../tui/screens/offers.ts"; | |
| 84 | import * as s80 from "../tui/screens/offsite.ts"; | |
| 85 | import * as s81 from "../tui/screens/orggrants.ts"; | |
| 86 | import * as s82 from "../tui/screens/orgteams.ts"; | |
| 87 | import * as s83 from "../tui/screens/originahead.ts"; | |
| 88 | import * as s84 from "../tui/screens/owner.ts"; | |
| 89 | import * as s85 from "../tui/screens/packrepos.ts"; | |
| 90 | import * as s86 from "../tui/screens/payments.ts"; | |
| 91 | import * as s87 from "../tui/screens/people.ts"; | |
| 92 | import * as s88 from "../tui/screens/pinned.ts"; | |
| 93 | import * as s89 from "../tui/screens/planner.ts"; | |
| 94 | import * as s90 from "../tui/screens/planrow.ts"; | |
| 95 | import * as s91 from "../tui/screens/plans.ts"; | |
| 96 | import * as s92 from "../tui/screens/previewdirs.ts"; | |
| 97 | import * as s93 from "../tui/screens/profile.ts"; | |
| 98 | import * as s94 from "../tui/screens/quotas.ts"; | |
| 99 | import * as s95 from "../tui/screens/recoverykit.ts"; | |
| 100 | import * as s96 from "../tui/screens/refused.ts"; | |
| 101 | import * as s97 from "../tui/screens/repolist.ts"; | |
| 102 | import * as s98 from "../tui/screens/requests.ts"; | |
| 103 | import * as s99 from "../tui/screens/resilience.ts"; | |
| 104 | import * as s100 from "../tui/screens/returning.ts"; | |
| 105 | import * as s101 from "../tui/screens/returns.ts"; | |
| 106 | import * as s102 from "../tui/screens/scorecard.ts"; | |
| 107 | import * as s103 from "../tui/screens/scrapes.ts"; | |
| 108 | import * as s104 from "../tui/screens/secrets.ts"; | |
| 109 | import * as s105 from "../tui/screens/sentinel.ts"; | |
| 110 | import * as s106 from "../tui/screens/ship_time.ts"; | |
| 111 | import * as s107 from "../tui/screens/slowpages.ts"; | |
| 112 | import * as s108 from "../tui/screens/sold.ts"; | |
| 113 | import * as s109 from "../tui/screens/spend.ts"; | |
| 114 | import * as s110 from "../tui/screens/stalepulls.ts"; | |
| 115 | import * as s111 from "../tui/screens/subscriptions.ts"; | |
| 116 | import * as s112 from "../tui/screens/system.ts"; | |
| 117 | import * as s113 from "../tui/screens/teams.ts"; | |
| 118 | import * as s114 from "../tui/screens/telemetry.ts"; | |
| 119 | import * as s115 from "../tui/screens/tell_undo.ts"; | |
| 120 | import * as s116 from "../tui/screens/traffic.ts"; | |
| 121 | import * as s117 from "../tui/screens/trafficview.ts"; | |
| 122 | import * as s118 from "../tui/screens/valves.ts"; | |
| 123 | import * as s119 from "../tui/screens/waiting.ts"; | |
| 124 | import * as s120 from "../tui/screens/waiting_for_me.ts"; | |
| 125 | import * as s121 from "../tui/screens/wayback.ts"; | |
| 126 | import * as s122 from "../tui/screens/weekcard.ts"; | |
| 4 | import * as s0 from "../tui/screens/abstractions.ts"; | |
| 5 | import * as s1 from "../tui/screens/access.ts"; | |
| 6 | import * as s2 from "../tui/screens/account_access.ts"; | |
| 7 | import * as s3 from "../tui/screens/agents.ts"; | |
| 8 | import * as s4 from "../tui/screens/app_templates.ts"; | |
| 9 | import * as s5 from "../tui/screens/apps_crew.ts"; | |
| 10 | import * as s6 from "../tui/screens/archived.ts"; | |
| 11 | import * as s7 from "../tui/screens/ask_data.ts"; | |
| 12 | import * as s8 from "../tui/screens/audit.ts"; | |
| 13 | import * as s9 from "../tui/screens/bets.ts"; | |
| 14 | import * as s10 from "../tui/screens/billing.ts"; | |
| 15 | import * as s11 from "../tui/screens/billinglinks.ts"; | |
| 16 | import * as s12 from "../tui/screens/bills.ts"; | |
| 17 | import * as s13 from "../tui/screens/boards.ts"; | |
| 18 | import * as s14 from "../tui/screens/bottleneck.ts"; | |
| 19 | import * as s15 from "../tui/screens/bugs.ts"; | |
| 20 | import * as s16 from "../tui/screens/bulk.ts"; | |
| 21 | import * as s17 from "../tui/screens/captain.ts"; | |
| 22 | import * as s18 from "../tui/screens/childcredit.ts"; | |
| 23 | import * as s19 from "../tui/screens/claim_link.ts"; | |
| 24 | import * as s20 from "../tui/screens/claim_start.ts"; | |
| 25 | import * as s21 from "../tui/screens/cloud.ts"; | |
| 26 | import * as s22 from "../tui/screens/codes.ts"; | |
| 27 | import * as s23 from "../tui/screens/connections.ts"; | |
| 28 | import * as s24 from "../tui/screens/controls.ts"; | |
| 29 | import * as s25 from "../tui/screens/cores.ts"; | |
| 30 | import * as s26 from "../tui/screens/crewbudgets.ts"; | |
| 31 | import * as s27 from "../tui/screens/crewhandover.ts"; | |
| 32 | import * as s28 from "../tui/screens/crewkey.ts"; | |
| 33 | import * as s29 from "../tui/screens/crewsplits.ts"; | |
| 34 | import * as s30 from "../tui/screens/crewtop.ts"; | |
| 35 | import * as s31 from "../tui/screens/dataset.ts"; | |
| 36 | import * as s32 from "../tui/screens/design.ts"; | |
| 37 | import * as s33 from "../tui/screens/design_gallery.ts"; | |
| 38 | import * as s34 from "../tui/screens/devices.ts"; | |
| 39 | import * as s35 from "../tui/screens/disks.ts"; | |
| 40 | import * as s36 from "../tui/screens/displays.ts"; | |
| 41 | import * as s37 from "../tui/screens/domains.ts"; | |
| 42 | import * as s38 from "../tui/screens/dotfiles.ts"; | |
| 43 | import * as s39 from "../tui/screens/drift.ts"; | |
| 44 | import * as s40 from "../tui/screens/dutybudgets.ts"; | |
| 45 | import * as s41 from "../tui/screens/dutyswitch.ts"; | |
| 46 | import * as s42 from "../tui/screens/economics.ts"; | |
| 47 | import * as s43 from "../tui/screens/edgeonly.ts"; | |
| 48 | import * as s44 from "../tui/screens/experiments.ts"; | |
| 49 | import * as s45 from "../tui/screens/featurefeed.ts"; | |
| 50 | import * as s46 from "../tui/screens/features.ts"; | |
| 51 | import * as s47 from "../tui/screens/featureswitch.ts"; | |
| 52 | import * as s48 from "../tui/screens/feed.ts"; | |
| 53 | import * as s49 from "../tui/screens/flowsall.ts"; | |
| 54 | import * as s50 from "../tui/screens/footing.ts"; | |
| 55 | import * as s51 from "../tui/screens/forgeready.ts"; | |
| 56 | import * as s52 from "../tui/screens/forges.ts"; | |
| 57 | import * as s53 from "../tui/screens/forgeview.ts"; | |
| 58 | import * as s54 from "../tui/screens/front.ts"; | |
| 59 | import * as s55 from "../tui/screens/frontms.ts"; | |
| 60 | import * as s56 from "../tui/screens/funnel.ts"; | |
| 61 | import * as s57 from "../tui/screens/games.ts"; | |
| 62 | import * as s58 from "../tui/screens/gifts.ts"; | |
| 63 | import * as s59 from "../tui/screens/health_voice.ts"; | |
| 64 | import * as s60 from "../tui/screens/home_pins.ts"; | |
| 65 | import * as s61 from "../tui/screens/hostreach.ts"; | |
| 66 | import * as s62 from "../tui/screens/infra.ts"; | |
| 67 | import * as s63 from "../tui/screens/inventory.ts"; | |
| 68 | import * as s64 from "../tui/screens/invites.ts"; | |
| 69 | import * as s65 from "../tui/screens/knobs.ts"; | |
| 70 | import * as s66 from "../tui/screens/lapsed.ts"; | |
| 71 | import * as s67 from "../tui/screens/limits.ts"; | |
| 72 | import * as s68 from "../tui/screens/loopstalls.ts"; | |
| 73 | import * as s69 from "../tui/screens/madefrom.ts"; | |
| 74 | import * as s70 from "../tui/screens/maintainruns.ts"; | |
| 75 | import * as s71 from "../tui/screens/maintenance.ts"; | |
| 76 | import * as s72 from "../tui/screens/maintenanceweek.ts"; | |
| 77 | import * as s73 from "../tui/screens/mergedbranches.ts"; | |
| 78 | import * as s74 from "../tui/screens/mirrorpacks.ts"; | |
| 79 | import * as s75 from "../tui/screens/model.ts"; | |
| 80 | import * as s76 from "../tui/screens/money.ts"; | |
| 81 | import * as s77 from "../tui/screens/newissue.ts"; | |
| 82 | import * as s78 from "../tui/screens/next.ts"; | |
| 83 | import * as s79 from "../tui/screens/nowlist.ts"; | |
| 84 | import * as s80 from "../tui/screens/offers.ts"; | |
| 85 | import * as s81 from "../tui/screens/offsite.ts"; | |
| 86 | import * as s82 from "../tui/screens/orggrants.ts"; | |
| 87 | import * as s83 from "../tui/screens/orgteams.ts"; | |
| 88 | import * as s84 from "../tui/screens/originahead.ts"; | |
| 89 | import * as s85 from "../tui/screens/owner.ts"; | |
| 90 | import * as s86 from "../tui/screens/packrepos.ts"; | |
| 91 | import * as s87 from "../tui/screens/payments.ts"; | |
| 92 | import * as s88 from "../tui/screens/people.ts"; | |
| 93 | import * as s89 from "../tui/screens/pinned.ts"; | |
| 94 | import * as s90 from "../tui/screens/planner.ts"; | |
| 95 | import * as s91 from "../tui/screens/planrow.ts"; | |
| 96 | import * as s92 from "../tui/screens/plans.ts"; | |
| 97 | import * as s93 from "../tui/screens/previewdirs.ts"; | |
| 98 | import * as s94 from "../tui/screens/profile.ts"; | |
| 99 | import * as s95 from "../tui/screens/quotas.ts"; | |
| 100 | import * as s96 from "../tui/screens/recoverykit.ts"; | |
| 101 | import * as s97 from "../tui/screens/refused.ts"; | |
| 102 | import * as s98 from "../tui/screens/repolist.ts"; | |
| 103 | import * as s99 from "../tui/screens/requests.ts"; | |
| 104 | import * as s100 from "../tui/screens/resilience.ts"; | |
| 105 | import * as s101 from "../tui/screens/returning.ts"; | |
| 106 | import * as s102 from "../tui/screens/returns.ts"; | |
| 107 | import * as s103 from "../tui/screens/scorecard.ts"; | |
| 108 | import * as s104 from "../tui/screens/scrapes.ts"; | |
| 109 | import * as s105 from "../tui/screens/secrets.ts"; | |
| 110 | import * as s106 from "../tui/screens/sentinel.ts"; | |
| 111 | import * as s107 from "../tui/screens/ship_time.ts"; | |
| 112 | import * as s108 from "../tui/screens/slowpages.ts"; | |
| 113 | import * as s109 from "../tui/screens/sold.ts"; | |
| 114 | import * as s110 from "../tui/screens/spend.ts"; | |
| 115 | import * as s111 from "../tui/screens/stalepulls.ts"; | |
| 116 | import * as s112 from "../tui/screens/subscriptions.ts"; | |
| 117 | import * as s113 from "../tui/screens/system.ts"; | |
| 118 | import * as s114 from "../tui/screens/teams.ts"; | |
| 119 | import * as s115 from "../tui/screens/telemetry.ts"; | |
| 120 | import * as s116 from "../tui/screens/tell_undo.ts"; | |
| 121 | import * as s117 from "../tui/screens/traffic.ts"; | |
| 122 | import * as s118 from "../tui/screens/trafficview.ts"; | |
| 123 | import * as s119 from "../tui/screens/valves.ts"; | |
| 124 | import * as s120 from "../tui/screens/waiting.ts"; | |
| 125 | import * as s121 from "../tui/screens/waiting_for_me.ts"; | |
| 126 | import * as s122 from "../tui/screens/wayback.ts"; | |
| 127 | import * as s123 from "../tui/screens/weekcard.ts"; | |
| 127 | 128 | |
| 128 | 129 | /** Each screen file that declares palette entries: its module and the export names. */ |
| 129 | 130 | export const SCREEN_MODULES: readonly (readonly [Record<string, unknown>, readonly string[]])[] = [ |
| @@ -145,8 +146,8 @@ export const SCREEN_MODULES: readonly (readonly [Record<string, unknown>, readon | ||
| 145 | 146 | [s15, ["entry"]], |
| 146 | 147 | [s16, ["entry"]], |
| 147 | 148 | [s17, ["entry"]], |
| 148 | [s18, ["entry","recoveryEntry"]], | |
| 149 | [s19, ["entry"]], | |
| 149 | [s18, ["entry"]], | |
| 150 | [s19, ["entry","recoveryEntry"]], | |
| 150 | 151 | [s20, ["entry"]], |
| 151 | 152 | [s21, ["entry"]], |
| 152 | 153 | [s22, ["entry"]], |
| @@ -201,11 +202,11 @@ export const SCREEN_MODULES: readonly (readonly [Record<string, unknown>, readon | ||
| 201 | 202 | [s71, ["entry"]], |
| 202 | 203 | [s72, ["entry"]], |
| 203 | 204 | [s73, ["entry"]], |
| 204 | [s74, ["modelGrantEntry","modelCeilingEntry"]], | |
| 205 | [s75, ["entry"]], | |
| 205 | [s74, ["entry"]], | |
| 206 | [s75, ["modelGrantEntry","modelCeilingEntry"]], | |
| 206 | 207 | [s76, ["entry"]], |
| 207 | [s77, ["nextAllEntry"]], | |
| 208 | [s78, ["entry"]], | |
| 208 | [s77, ["entry"]], | |
| 209 | [s78, ["nextAllEntry"]], | |
| 209 | 210 | [s79, ["entry"]], |
| 210 | 211 | [s80, ["entry"]], |
| 211 | 212 | [s81, ["entry"]], |
| @@ -250,4 +251,5 @@ export const SCREEN_MODULES: readonly (readonly [Record<string, unknown>, readon | ||
| 250 | 251 | [s120, ["entry"]], |
| 251 | 252 | [s121, ["entry"]], |
| 252 | 253 | [s122, ["entry"]], |
| 254 | [s123, ["entry"]], | |
| 253 | 255 | ]; |
src/http/marks/admin.json +1
src/http/server.ts +2
| @@ -208,6 +208,7 @@ import { followingSubmit } from "../web/pages/following.ts"; | ||
| 208 | 208 | import { reconnectSubmit } from "../web/pages/frozen.ts"; |
| 209 | 209 | import { activityAtom, changelogAtom, exploreAtom, feedJson } from "../web/feeds.ts"; |
| 210 | 210 | import { auditCsv, auditPage, auditProbeSubmit } from "../web/pages/audit.ts"; |
| 211 | import { abstractionsPage } from "../web/pages/abstractions.ts"; | |
| 211 | 212 | import { apiPage, appApiPage } from "../web/pages/api.ts"; |
| 212 | 213 | import { flowsCheck, flowsMap, flowsPage, flowsProbe, flowsUpdate } from "../web/pages/flows.ts"; |
| 213 | 214 | import { findingAccept, findingsPage } from "../web/pages/findings.ts"; |
| @@ -1303,6 +1304,7 @@ export function buildRouter(): Router<Handler> { | ||
| 1303 | 1304 | router.add("GET", "/design/gallery", designComponentsPage); |
| 1304 | 1305 | router.add("GET", "/admin/data", adminDataPage); |
| 1305 | 1306 | router.add("GET", "/admin/limits", limitsPage); |
| 1307 | router.add("GET", "/admin/abstractions", abstractionsPage); | |
| 1306 | 1308 | router.add("GET", "/admin/flows", allFlowsPage); |
| 1307 | 1309 | router.add("POST", "/admin/limits", limitsSet); |
| 1308 | 1310 | router.add("POST", "/admin/quotas", quotasSet); |
src/tui/screens/abstractions.ts added +64
| @@ -0,0 +1,64 @@ | ||
| 1 | /** | |
| 2 | * The forge's abstractions in the terminal, a forge admin's, as /admin/abstractions lists them | |
| 3 | * (#6002): one row per type with its stage and rows; under the list, the selected type's facts. | |
| 4 | * Anyone else sees nothing: the gate is the action's. | |
| 5 | */ | |
| 6 | ||
| 7 | import { listAbstractions, mayReadAtlas } from "../../actions/abstractions.ts"; | |
| 8 | import type { Abstraction } from "../../core/abstractions.ts"; | |
| 9 | import { abstractionFacts, atlasSummary, rowWords } from "../../view/abstraction_words.ts"; | |
| 10 | import type { Ctx, Screen } from "../app/app.ts"; | |
| 11 | import { binding } from "../app/keys.ts"; | |
| 12 | import { style } from "../term/style.ts"; | |
| 13 | import { truncate } from "../term/width.ts"; | |
| 14 | import type { Session } from "../session.ts"; | |
| 15 | import { emptyState } from "../ui/widgets.ts"; | |
| 16 | import { ListState, drawFacts, drawList, type ListRow } from "./common.ts"; | |
| 17 | import type { PaletteEntry } from "./entries.ts"; | |
| 18 | ||
| 19 | export function abstractionRows(types: readonly Abstraction[]): ListRow[] { | |
| 20 | return types.map((t) => ({ title: t.name, secondary: t.stage, meta: rowWords(t) })); | |
| 21 | } | |
| 22 | ||
| 23 | export function abstractionsScreen(f: Session, ctx: Ctx): Screen { | |
| 24 | const state = new ListState(); | |
| 25 | // Read once: counting every table is not a per-frame cost. | |
| 26 | const read = listAbstractions(f.app, f.user); | |
| 27 | return { | |
| 28 | title: "Tables", | |
| 29 | keys: [binding(["j", "k"], "move cursor"), binding(["esc", "q"], "close")], | |
| 30 | render(area, s) { | |
| 31 | const c = ctx.theme.c; | |
| 32 | if (!read.ok) { | |
| 33 | emptyState(s, area, c, { title: "Nothing here", body: "This is a forge admin's." }); | |
| 34 | return; | |
| 35 | } | |
| 36 | const { types } = read.value; | |
| 37 | const summary = atlasSummary(read.value); | |
| 38 | summary.forEach((line, i) => s.text(area.x, area.y + i, truncate(line, area.w), style(c.mutedFg, c.bg), area.x + area.w)); | |
| 39 | const top = area.y + summary.length + 1; | |
| 40 | const rows = abstractionRows(types); | |
| 41 | const listH = Math.max(1, Math.min(rows.length, (area.h - summary.length) >> 1)); | |
| 42 | drawList(s, { x: area.x, y: top, w: area.w, h: listH }, c, state, rows); | |
| 43 | const selected = types[state.index]; | |
| 44 | if (selected === undefined) return; | |
| 45 | const y = top + listH + 1; | |
| 46 | drawFacts(s, { x: area.x + 1, y, w: Math.max(0, area.w - 1), h: Math.max(0, area.y + area.h - y) }, c, abstractionFacts(selected)); | |
| 47 | }, | |
| 48 | key(e) { | |
| 49 | if (e.key === "esc" || e.key === "q") ctx.pop(); | |
| 50 | else state.key(e, read.ok ? read.value.types.length : 0); | |
| 51 | return true; | |
| 52 | }, | |
| 53 | }; | |
| 54 | } | |
| 55 | ||
| 56 | /** The atlas, offered to a forge admin who is not an agent. */ | |
| 57 | export const entry: PaletteEntry = { | |
| 58 | rank: 410, | |
| 59 | id: "abstractions", | |
| 60 | title: "Tables", | |
| 61 | hint: "the forge's tables: how much each is used, and what builds on what", | |
| 62 | offered: (session) => mayReadAtlas(session.user), | |
| 63 | run: (session, ctx) => ctx.push(abstractionsScreen(session, ctx)), | |
| 64 | }; |
src/tui/screens/system.ts +4 −1
| @@ -62,6 +62,8 @@ import { slowestRoutes } from "../../perf/history.ts"; | ||
| 62 | 62 | import { budgetFor } from "../../perf/budgets.ts"; |
| 63 | 63 | import { knownPatterns } from "../../http/server.ts"; |
| 64 | 64 | import type { PaletteEntry } from "./entries.ts"; |
| 65 | import { abstractionsScreen } from "./abstractions.ts"; | |
| 66 | import { mayReadAtlas } from "../../actions/abstractions.ts"; | |
| 65 | 67 | import { shapeWords } from "../../engine/mode.ts"; |
| 66 | 68 | import { readHealth } from "../../actions/health.ts"; |
| 67 | 69 | import { egressReportedLine } from "../../system/egress_line.ts"; |
| @@ -437,7 +439,7 @@ export function systemScreen(ctx: Ctx, lines: readonly string[], session: Sessio | ||
| 437 | 439 | }; |
| 438 | 440 | const screen: Screen = { |
| 439 | 441 | title: "System", |
| 440 | keys: [binding(["h"], "window"), ...(reads ? [binding(["d"], "database size")] : []), ...(offered ? [binding(["g"], "grant or take back telemetry")] : []), binding(["enter", "esc", "q"], "close")], | |
| 442 | keys: [binding(["h"], "window"), ...(reads ? [binding(["d"], "database size")] : []), ...(mayReadAtlas(session?.user) ? [binding(["a"], "tables")] : []), ...(offered ? [binding(["g"], "grant or take back telemetry")] : []), binding(["enter", "esc", "q"], "close")], | |
| 441 | 443 | render(area, s) { |
| 442 | 444 | const features = featuresLines(session); |
| 443 | 445 | // Never waits on the walk: the last measurement, a new one started behind it when stale. |
| @@ -478,6 +480,7 @@ export function systemScreen(ctx: Ctx, lines: readonly string[], session: Sessio | ||
| 478 | 480 | history = historyLines(session, WINDOWS[span]!); |
| 479 | 481 | } else if (e.key === "g") askGrant(); |
| 480 | 482 | else if (e.key === "d" && reads) later(ctx, () => dbSizeScreen(session, ctx)); |
| 483 | else if (e.key === "a" && mayReadAtlas(session.user)) later(ctx, () => abstractionsScreen(session, ctx)); | |
| 481 | 484 | else if (e.key === "enter" || e.key === "esc" || e.key === "q") ctx.pop(); |
| 482 | 485 | return true; |
| 483 | 486 | }, |
src/view/abstraction_words.ts added +37
| @@ -0,0 +1,37 @@ | ||
| 1 | /** | |
| 2 | * The atlas of abstractions in plain words (#6002), one place for the page and the terminal screen. | |
| 3 | */ | |
| 4 | ||
| 5 | import type { Abstraction, AbstractionAtlas } from "../core/abstractions.ts"; | |
| 6 | import { WINDOW_DAYS } from "../core/abstractions.ts"; | |
| 7 | import { formatBytes } from "../core/storage.ts"; | |
| 8 | ||
| 9 | const day = (iso: string | null): string => (iso === null ? "never" : iso.slice(0, 10)); | |
| 10 | const none = (names: readonly string[]): string => (names.length === 0 ? "nothing" : names.join(", ")); | |
| 11 | ||
| 12 | /** The two findings: what was used most lately, and what fell away. */ | |
| 13 | export function atlasSummary(atlas: AbstractionAtlas): string[] { | |
| 14 | const half = WINDOW_DAYS / 2; | |
| 15 | const list = (names: readonly string[], empty: string): string => (names.length === 0 ? empty : names.join(", ")); | |
| 16 | return [ | |
| 17 | `Used most in the last ${half} days: ${list(atlas.busiest, "nothing was used")}.`, | |
| 18 | `Used less than half as much as the ${half} days before: ${list(atlas.fading, "nothing")}.`, | |
| 19 | ]; | |
| 20 | } | |
| 21 | ||
| 22 | /** "120 rows", "10000+ rows" (the count stops there), with the size when it was read. */ | |
| 23 | export function rowWords(t: Abstraction): string { | |
| 24 | const n = `${t.rows}${t.rowsCapped ? "+" : ""} ${t.rows === 1 && !t.rowsCapped ? "row" : "rows"}`; | |
| 25 | return t.bytes === null ? n : `${n}, ${formatBytes(t.bytes)}`; | |
| 26 | } | |
| 27 | ||
| 28 | /** One type's facts as [label, value] pairs. */ | |
| 29 | export function abstractionFacts(t: Abstraction): [string, string][] { | |
| 30 | return [ | |
| 31 | ["first row", day(t.born)], | |
| 32 | ["last row", day(t.lastTouched)], | |
| 33 | [`last ${WINDOW_DAYS} days`, `${t.created} added · ${t.updated} changed · ${t.deleted} removed`], | |
| 34 | ["builds on", none(t.references)], | |
| 35 | ["used by", none(t.usedBy)], | |
| 36 | ]; | |
| 37 | } |
src/web/pages/abstractions.ts added +45
| @@ -0,0 +1,45 @@ | ||
| 1 | /** | |
| 2 | * The forge's tables (#6002), for a forge admin: each as one row with its stage | |
| 3 | * and size, the first and last row, the lately added, changed and removed, and what builds on | |
| 4 | * what (`core/abstractions.ts`), under the two findings. Anyone else gets the not-found page. | |
| 5 | * Sizes scan the whole database file, so they come only with `?sizes`. | |
| 6 | */ | |
| 7 | ||
| 8 | import { listAbstractions } from "../../actions/abstractions.ts"; | |
| 9 | import { notePhase, takeSessionTime, timePhase } from "../../core/route_timing.ts"; | |
| 10 | import type { Ctx } from "../../http/context.ts"; | |
| 11 | import { abstractionFacts, atlasSummary, rowWords } from "../../view/abstraction_words.ts"; | |
| 12 | import { sshOn } from "../../settings/ssh.ts"; | |
| 13 | import { notFoundPage, pageHead, settingsLayout } from "../chrome.ts"; | |
| 14 | import { html } from "../html.ts"; | |
| 15 | import { page } from "../layout.ts"; | |
| 16 | import { accountSections } from "./origins.ts"; | |
| 17 | import { row, rowList } from "../ui.ts"; | |
| 18 | ||
| 19 | // GET /admin/abstractions | |
| 20 | export function abstractionsPage(ctx: Ctx): Response { | |
| 21 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); | |
| 22 | const sizes = ctx.url.searchParams.has("sizes"); | |
| 23 | const read = timePhase(ctx.request, "atlas", () => listAbstractions(ctx.app, ctx.auth.user, { sizes })); | |
| 24 | if (!read.ok) return notFoundPage(ctx); | |
| 25 | const atlas = read.value; | |
| 26 | const rendering = performance.now(); | |
| 27 | const rows = atlas.types.map((t) => | |
| 28 | row({ | |
| 29 | title: html`<span class="mono">${t.name}</span>`, | |
| 30 | meta: html`${t.stage} · ${rowWords(t)}`, | |
| 31 | facts: abstractionFacts(t).map(([label, value]) => ({ label, value })), | |
| 32 | }), | |
| 33 | ); | |
| 34 | const body = html`${atlasSummary(atlas).map((line) => html`<p class="small muted mb">${line}</p>`)} | |
| 35 | ${rowList(rows, { bare: true, label: "Tables" })} | |
| 36 | ${sizes ? null : html`<p class="small muted mt"><a href="/admin/abstractions?sizes">Show sizes</a></p>`}`; | |
| 37 | const response = page({ | |
| 38 | ctx, | |
| 39 | title: "Tables", | |
| 40 | body: html`${pageHead("Tables", { sub: "How much each of the forge's tables is used, and which build on which." })} | |
| 41 | ${settingsLayout(accountSections("abstractions", { admin: true, ssh: sshOn(ctx.app.db) }), body, "Account settings")}`, | |
| 42 | }); | |
| 43 | notePhase(ctx.request, "render", performance.now() - rendering); | |
| 44 | return response; | |
| 45 | } |
src/web/pages/origins.ts +2
| @@ -130,6 +130,7 @@ export type AccountSection = | ||
| 130 | 130 | | "telemetry" |
| 131 | 131 | | "access" |
| 132 | 132 | | "limits" |
| 133 | | "abstractions" | |
| 133 | 134 | | "economics" |
| 134 | 135 | | "flags" |
| 135 | 136 | | "templates" |
| @@ -185,6 +186,7 @@ const SECTION_ROWS: readonly (readonly [ | ||
| 185 | 186 | ["This forge", "People", "/settings/people", "users", (c) => c === "people", true], |
| 186 | 187 | ["This forge", "Hosted forges", "/settings/hosted-forges", "fork", (c) => c === "hosted", true], |
| 187 | 188 | ["This forge", "Limits", "/admin/limits", "activity", (c) => c === "limits", true], |
| 189 | ["This forge", "Tables", "/admin/abstractions", "activity", (c) => c === "abstractions", true], | |
| 188 | 190 | ["This forge", "Economics", "/settings/economics", "activity", (c) => c === "economics", true], |
| 189 | 191 | ["This forge", "Billing", "/settings/billing", "activity", (c) => c === "billing", true], |
| 190 | 192 | ["This forge", "Runners", "/settings/runners", "activity", (c) => c === "runners", true], |
test/abstractions.test.ts added +234
| @@ -0,0 +1,234 @@ | ||
| 1 | /** | |
| 2 | * The atlas of the forge's own abstractions (#6002): each table is a type with its references, | |
| 3 | * size, first and last row and use from the event outbox, a stage from the two halves of the | |
| 4 | * window, the busiest and the fading named, and the page is a forge admin's alone. | |
| 5 | */ | |
| 6 | ||
| 7 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 8 | import { Database } from "bun:sqlite"; | |
| 9 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 10 | import { tmpdir } from "node:os"; | |
| 11 | import { join } from "node:path"; | |
| 12 | import { createApp, type App } from "../src/app.ts"; | |
| 13 | import { ATLAS_TTL_MS, listAbstractions } from "../src/actions/abstractions.ts"; | |
| 14 | import { createAgent } from "../src/actions/crew.ts"; | |
| 15 | import { ROW_CAP, crudOf, readAbstractions, stageOf } from "../src/core/abstractions.ts"; | |
| 16 | import { createUser, type User } from "../src/core/users.ts"; | |
| 17 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 18 | import { abstractionsScreen } from "../src/tui/screens/abstractions.ts"; | |
| 19 | import { createForgeApp } from "../src/tui/forge.ts"; | |
| 20 | import { headlessTerminal } from "../src/tui/term/terminal.ts"; | |
| 21 | import { adminCookie } from "./helpers/admin.ts"; | |
| 22 | import { settleApp } from "./helpers/tui.ts"; | |
| 23 | ||
| 24 | const NOW = new Date("2026-12-01T12:00:00Z"); | |
| 25 | const ago = (days: number): string => new Date(NOW.getTime() - days * 86_400_000).toISOString(); | |
| 26 | ||
| 27 | function seeded(): Database { | |
| 28 | const db = new Database(":memory:"); | |
| 29 | db.run("CREATE TABLE repo (id TEXT PRIMARY KEY, created_at TEXT)"); | |
| 30 | db.run("CREATE TABLE pull (id TEXT PRIMARY KEY, repo_id TEXT REFERENCES repo(id), created_at TEXT)"); | |
| 31 | db.run("CREATE TABLE flag (id TEXT PRIMARY KEY, created_at TEXT)"); | |
| 32 | db.run("CREATE TABLE note (id TEXT PRIMARY KEY)"); | |
| 33 | db.run("CREATE TABLE event (id TEXT PRIMARY KEY, kind TEXT, created_at TEXT)"); | |
| 34 | db.run("INSERT INTO repo VALUES ('r1', ?), ('r2', ?)", [ago(300), ago(2)]); | |
| 35 | db.run("INSERT INTO pull VALUES ('p1', 'r1', ?)", [ago(5)]); | |
| 36 | db.run("INSERT INTO flag VALUES ('f1', ?)", [ago(40)]); | |
| 37 | let n = 0; | |
| 38 | const event = (kind: string, days: number, times = 1) => { | |
| 39 | for (let i = 0; i < times; i++) db.run("INSERT INTO event VALUES (?, ?, ?)", [`e${n++}`, kind, ago(days)]); | |
| 40 | }; | |
| 41 | event("pull.opened", 1, 6); // pull: busy lately | |
| 42 | event("pull.merged", 2, 1); | |
| 43 | event("pull.updated", 3, 1); | |
| 44 | event("repo.deleted", 20, 1); | |
| 45 | event("flag.set", 25, 5); // flag: was used, then stopped | |
| 46 | event("flag.set", 3, 1); | |
| 47 | event("ghost.opened", 1, 9); // no such table: not counted | |
| 48 | event("pull.opened", 90, 4); // outside the window | |
| 49 | return db; | |
| 50 | } | |
| 51 | ||
| 52 | describe("abstractions", () => { | |
| 53 | test("every table is a type, with its references both ways, and no sqlite_ table", () => { | |
| 54 | const { types } = readAbstractions(seeded(), NOW); | |
| 55 | expect(types.map((t) => t.name)).toEqual(["event", "flag", "note", "pull", "repo"]); | |
| 56 | const pull = types.find((t) => t.name === "pull")!; | |
| 57 | const repo = types.find((t) => t.name === "repo")!; | |
| 58 | expect(pull.references).toEqual(["repo"]); | |
| 59 | expect(repo.usedBy).toEqual(["pull"]); | |
| 60 | expect(repo.rows).toBe(2); | |
| 61 | expect(repo.born).toBe(ago(300)); | |
| 62 | expect(repo.lastTouched).toBe(ago(2)); | |
| 63 | }); | |
| 64 | ||
| 65 | test("a table without created_at has no birth, and one without rows is unused", () => { | |
| 66 | const note = readAbstractions(seeded(), NOW).types.find((t) => t.name === "note")!; | |
| 67 | expect(note.born).toBeNull(); | |
| 68 | expect(note.lastTouched).toBeNull(); | |
| 69 | expect(note.stage).toBe("unused"); | |
| 70 | }); | |
| 71 | ||
| 72 | test("use is counted by the verb, per day, inside the window, for tables that exist", () => { | |
| 73 | const pull = readAbstractions(seeded(), NOW).types.find((t) => t.name === "pull")!; | |
| 74 | expect([pull.created, pull.updated, pull.deleted]).toEqual([6, 1, 0]); | |
| 75 | expect(pull.recent).toBe(8); | |
| 76 | expect(pull.perDay).toHaveLength(28); | |
| 77 | expect(pull.perDay[26]).toBe(6); // yesterday | |
| 78 | expect(pull.perDay.reduce((a, b) => a + b, 0)).toBe(8); // the 90-day-old events are out | |
| 79 | const repo = readAbstractions(seeded(), NOW).types.find((t) => t.name === "repo")!; | |
| 80 | expect(repo.deleted).toBe(1); | |
| 81 | }); | |
| 82 | ||
| 83 | test("the busiest and the fading are named", () => { | |
| 84 | const atlas = readAbstractions(seeded(), NOW); | |
| 85 | expect(atlas.busiest).toEqual(["pull", "flag"]); | |
| 86 | expect(atlas.fading).toEqual(["flag", "repo"]); | |
| 87 | expect(atlas.types.find((t) => t.name === "flag")!.stage).toBe("fading"); | |
| 88 | expect(atlas.types.find((t) => t.name === "pull")!.stage).toBe("growing"); | |
| 89 | }); | |
| 90 | ||
| 91 | test("verbs and stages", () => { | |
| 92 | expect(crudOf("opened")).toBe("created"); | |
| 93 | expect(crudOf("settings_updated")).toBe("updated"); | |
| 94 | expect(crudOf("deleted")).toBe("deleted"); | |
| 95 | expect(crudOf("reviewed")).toBeNull(); | |
| 96 | expect(stageOf(0, 0, 3)).toBe("dormant"); | |
| 97 | expect(stageOf(2, 2, 3)).toBe("stable"); | |
| 98 | expect(stageOf(0, 4, 3)).toBe("fading"); | |
| 99 | }); | |
| 100 | }); | |
| 101 | ||
| 102 | describe("the cost on a big table", () => { | |
| 103 | test("a large table is counted only up to the cap, and sizes are read only when asked", () => { | |
| 104 | const db = new Database(":memory:"); | |
| 105 | db.run("CREATE TABLE event (id INTEGER PRIMARY KEY, kind TEXT, created_at TEXT)"); | |
| 106 | db.run("CREATE TABLE big (id INTEGER PRIMARY KEY, created_at TEXT)"); | |
| 107 | db.run("WITH RECURSIVE n(i) AS (SELECT 1 UNION ALL SELECT i + 1 FROM n WHERE i < 300000) INSERT INTO big SELECT i, '2026-11-30T00:00:00.000Z' FROM n"); | |
| 108 | const started = performance.now(); | |
| 109 | const big = readAbstractions(db, NOW).types.find((t) => t.name === "big")!; | |
| 110 | const took = performance.now() - started; | |
| 111 | expect(big.rows).toBe(ROW_CAP); | |
| 112 | expect(big.rowsCapped).toBe(true); | |
| 113 | expect(big.bytes).toBeNull(); | |
| 114 | expect(took).toBeLessThan(500); | |
| 115 | expect(readAbstractions(seeded(), NOW, true).types.find((t) => t.name === "repo")!.rowsCapped).toBe(false); | |
| 116 | }); | |
| 117 | }); | |
| 118 | ||
| 119 | describe("the atlas for a person, and the cache", () => { | |
| 120 | let dir: string; | |
| 121 | let app: App; | |
| 122 | let admin: User; | |
| 123 | let member: User; | |
| 124 | let bot: User; | |
| 125 | beforeAll(async () => { | |
| 126 | dir = await mkdtemp(join(tmpdir(), "forge-abstractions-act-")); | |
| 127 | app = createApp({ dataDir: dir, port: 0 }); | |
| 128 | const mk = async (username: string, first: boolean) => { | |
| 129 | const r = await createUser(app.db, { origin: "seed", trusted: true, username, email: `${username}@forge.local`, password: "a-good-passphrase", adminIfFirst: first }); | |
| 130 | if (!r.ok) throw new Error(r.error); | |
| 131 | return r.value; | |
| 132 | }; | |
| 133 | admin = await mk("alice", true); | |
| 134 | member = await mk("bob", false); | |
| 135 | const made = await createAgent(app, admin, { username: "atlasbot", brief: "x" }); | |
| 136 | if (!made.ok) throw new Error(String(made.error)); | |
| 137 | app.db.query("UPDATE user SET is_admin = 1 WHERE id = ?1").run(made.value.user.id); | |
| 138 | bot = { ...made.value.user, isAdmin: true }; | |
| 139 | }, 30_000); | |
| 140 | afterAll(async () => { | |
| 141 | app.close(); | |
| 142 | await rm(dir, { recursive: true, force: true }); | |
| 143 | }); | |
| 144 | ||
| 145 | test("only an admin who is a person is given the atlas; a guest, a member and an agent are not_found", () => { | |
| 146 | expect(listAbstractions(app, admin).ok).toBe(true); | |
| 147 | for (const who of [undefined, member, bot]) { | |
| 148 | const read = listAbstractions(app, who); | |
| 149 | expect(read.ok).toBe(false); | |
| 150 | if (!read.ok) expect(read.error).toBe("not_found"); | |
| 151 | } | |
| 152 | }); | |
| 153 | ||
| 154 | test("the atlas is read once a minute: a second ask returns the same read, an ask after the minute a new one", () => { | |
| 155 | const t0 = Date.now() + 10 * ATLAS_TTL_MS; | |
| 156 | const first = listAbstractions(app, admin, { clock: t0 }); | |
| 157 | const again = listAbstractions(app, admin, { clock: t0 + ATLAS_TTL_MS - 1 }); | |
| 158 | const later = listAbstractions(app, admin, { clock: t0 + ATLAS_TTL_MS }); | |
| 159 | if (!first.ok || !again.ok || !later.ok) throw new Error("not read"); | |
| 160 | expect(again.value).toBe(first.value); | |
| 161 | expect(later.value).not.toBe(first.value); | |
| 162 | }); | |
| 163 | ||
| 164 | test("sizes ask for a new read, and an unsized ask reuses a sized one", () => { | |
| 165 | const t0 = Date.now() + 100 * ATLAS_TTL_MS; | |
| 166 | const plain = listAbstractions(app, admin, { clock: t0 }); | |
| 167 | const sized = listAbstractions(app, admin, { clock: t0 + 1, sizes: true }); | |
| 168 | const after = listAbstractions(app, admin, { clock: t0 + 2 }); | |
| 169 | if (!plain.ok || !sized.ok || !after.ok) throw new Error("not read"); | |
| 170 | expect(plain.value.types.every((t) => t.bytes === null)).toBe(true); | |
| 171 | expect(sized.value).not.toBe(plain.value); | |
| 172 | expect(after.value).toBe(sized.value); | |
| 173 | }); | |
| 174 | ||
| 175 | async function screenText(user: User): Promise<string> { | |
| 176 | const { app: tui, session } = createForgeApp(app, { sshUsername: user.username, remoteAddress: "127.0.0.1", fingerprint: "SHA256:test", user }, { terminal: headlessTerminal(120, 40), exitHooks: false }); | |
| 177 | tui.start(); | |
| 178 | tui.ctx.push(abstractionsScreen(session, tui.ctx)); | |
| 179 | await settleApp(tui); | |
| 180 | const text = tui.screen.toText(); | |
| 181 | tui.stop?.(); | |
| 182 | return text; | |
| 183 | } | |
| 184 | ||
| 185 | test("in the terminal an admin sees the rows; a member and an agent see nothing", async () => { | |
| 186 | const seen = await screenText(admin); | |
| 187 | expect(seen).toContain("access_link"); | |
| 188 | expect(seen).toContain("Used most in the last 14 days"); | |
| 189 | for (const who of [member, bot]) { | |
| 190 | const text = await screenText(who); | |
| 191 | expect(text).toContain("Nothing here"); | |
| 192 | expect(text).not.toContain("Used most in"); | |
| 193 | } | |
| 194 | }); | |
| 195 | }); | |
| 196 | ||
| 197 | describe("/admin/abstractions", () => { | |
| 198 | let dataDir: string; | |
| 199 | let app: App; | |
| 200 | let servers: Servers; | |
| 201 | ||
| 202 | beforeAll(async () => { | |
| 203 | dataDir = await mkdtemp(join(tmpdir(), "forge-abstractions-")); | |
| 204 | app = createApp({ dataDir, port: 0 }); | |
| 205 | servers = await serve(app); | |
| 206 | }); | |
| 207 | afterAll(async () => { | |
| 208 | await servers.stop(); | |
| 209 | await rm(dataDir, { recursive: true, force: true }); | |
| 210 | }); | |
| 211 | ||
| 212 | test("an admin reads the rows and the two findings, sizes only when asked; anyone else is refused", async () => { | |
| 213 | const admin = await adminCookie(app, { username: "alice", email: "[email protected]" }); | |
| 214 | const res = await fetch(`${servers.url}/admin/abstractions`, { headers: { cookie: admin } }); | |
| 215 | expect(res.status).toBe(200); | |
| 216 | const text = await res.text(); | |
| 217 | expect(text).toContain("Used most in the last 14 days"); | |
| 218 | expect(text).toContain('<span class="mono">repo</span>'); | |
| 219 | expect(text).not.toContain("<table"); | |
| 220 | expect(text).toContain("first row"); | |
| 221 | expect(text).toContain("used by"); | |
| 222 | expect(text).toContain('href="/admin/abstractions?sizes"'); | |
| 223 | const sized = await fetch(`${servers.url}/admin/abstractions?sizes`, { headers: { cookie: admin } }); | |
| 224 | expect(await sized.text()).not.toContain('href="/admin/abstractions?sizes"'); | |
| 225 | const settings = await fetch(`${servers.url}/admin/limits`, { headers: { cookie: admin } }); | |
| 226 | expect(await settings.text()).toContain('href="/admin/abstractions"'); | |
| 227 | const made = await createUser(app.db, { origin: "seed", trusted: true, username: "bob", email: "[email protected]", password: "a-good-passphrase" }); | |
| 228 | if (!made.ok) throw new Error(made.error); | |
| 229 | const { createSession } = await import("../src/core/sessions.ts"); | |
| 230 | const bob = `forge_session=${createSession(app.db, made.value.id).token}`; | |
| 231 | expect((await fetch(`${servers.url}/admin/abstractions`, { headers: { cookie: bob } })).status).toBe(403); | |
| 232 | expect((await fetch(`${servers.url}/admin/abstractions`)).status).toBe(404); | |
| 233 | }); | |
| 234 | }); |
test/forge-looks.test.ts +1 −1
| @@ -206,7 +206,7 @@ test("`/` signed out is its own look at phone and desktop, taken with no session | ||
| 206 | 206 | test("a look below the top level is the preview seed's, taken as the owner", () => { |
| 207 | 207 | const { looks, looksAsOwner } = manifest(); |
| 208 | 208 | for (const p of looks.filter((p) => !isTopLevel(p))) { |
| 209 | expect(p.startsWith("/preview-admin/sample") || p === "/settings/crew" || p === "/settings/captain" || p === "/settings/security/controls" || p === "/settings/grants" || p === "/admin/limits" || p === "/looks/missing" || p === "/looks/failed" || p === "/nope/nothing" || isHelpLook(p)).toBe(true); | |
| 209 | expect(p.startsWith("/preview-admin/sample") || p === "/settings/crew" || p === "/settings/captain" || p === "/settings/security/controls" || p === "/settings/grants" || p === "/admin/limits" || p === "/admin/abstractions" || p === "/looks/missing" || p === "/looks/failed" || p === "/nope/nothing" || isHelpLook(p)).toBe(true); | |
| 210 | 210 | // the not-found and failed pages are the same page to everyone: no owner needed |
| 211 | 211 | if (!p.startsWith("/looks/") && p !== "/nope/nothing") expect(looksAsOwner).toContain(p); |
| 212 | 212 | } |
test/palette-roster.test.ts +1
| @@ -218,6 +218,7 @@ test("a site-admin person is offered the whole roster", () => { | ||
| 218 | 218 | ["traffic-sources", "Traffic sources", "where people come from and where they go, for the forge"], |
| 219 | 219 | ["from-visit-to-paid", "From visit to paid", "the last 7 days: home visits, plans seen, plan clicks, forges made, paid"], |
| 220 | 220 | ["audit", "Who can do what", "each app's doors from its contract.json: yes, own or no"], |
| 221 | ["abstractions", "Tables", "the forge's tables: how much each is used, and what builds on what"], | |
| 221 | 222 | ["security-controls", "Security controls", "each safeguard, its state, and when it was last checked"], |
| 222 | 223 | ["billing", "Billing", "each forge's plan, and grant one by hand"], |
| 223 | 224 | ["lapsed", "Lapsed forges", "forges asleep until paid, when their data goes, pay again"], |
new above
offline
HIGH: this runs a COUNT(*) on every table and a full dbstat scan synchronously per request. On a multi-GB forge that blocks the event loop for seconds, which is the forge locking up. Cache the atlas for a minute and use a cheap row estimate; read dbstat on demand only.