Public: anyone can read this; the crew can change it.
The home page shows the forge's KPIs, never a to-do list for the owner; the owner pins board panels to it #2671
scout/forge:scout/2665-the-home-page-shows-the-forge-s-kpis-nev → main 1 commit fork
22 files
changed +542
−41
README.md +1
| @@ -1434,6 +1434,7 @@ work here. | ||
| 1434 | 1434 | A board with a refresh redraws its grid on that beat through the live-region swap |
| 1435 | 1435 | (`/boards/:slug/live`, etag'd). The same doors are in the API: `GET /api/v1/boards`, `GET|PUT|DELETE /api/v1/boards/:slug` |
| 1436 | 1436 | (an agent or anyone but an admin is 403; a panel whose query cannot run is refused with 422). The same four doors are MCP tools (`boards`, `board_write`, `board_delete`; `boards` with a `slug` reads one) and, for the same person, a **Boards** screen in the terminal that lists boards and shows a board's panels as text. No dependency was added. |
| 1437 | **The owner's home** (a person who is an admin) is the forge's vital signs, never a list of what waits on them: landings per hour (merged pulls into a default branch, last 24 h, as a sparkline), the live version and when it went live, median check time, builders at work of slots, today's spend of the daily ceiling, and the age of the last off-box backup, each linking to the board or page it comes from, and wrapping at 360 px. Every panel on a board has **Pin to home**; pinned panels draw under the KPIs, with Up/Down/Unpin, in the owner's order (`POST /home/panels`; one `user_setting` row of `board:place` pairs, so at most about five pins). What waits on the owner is on `/asks`, reached on purpose. | |
| 1437 | 1438 | - **Issues** — labels, threaded comments, close/reopen, markdown. |
| 1438 | 1439 | - **Pull requests** — open from a branch, a **beautiful diff viewer** (syntax |
| 1439 | 1440 | highlighting composed with intra-line word highlighting, mobile-first, |
src/core/home_panels.ts added +57
| @@ -0,0 +1,57 @@ | ||
| 1 | /** | |
| 2 | * The board panels an owner pinned to their home, in their order. One | |
| 3 | * `user_setting` row of `slug:index` pairs: a pin names a panel by its board | |
| 4 | * and place, and a pin whose panel is gone is skipped when drawn, never an | |
| 5 | * error. The row is bounded (`setUserSetting` keeps 200 characters), so a pin | |
| 6 | * that would not fit is refused. | |
| 7 | */ | |
| 8 | import type { Database } from "bun:sqlite"; | |
| 9 | import { isSlug } from "../boards/store.ts"; | |
| 10 | import { getUserSetting, setUserSetting } from "./settings.ts"; | |
| 11 | ||
| 12 | const KEY = "home_panels"; | |
| 13 | const MAX_LEN = 200; | |
| 14 | ||
| 15 | export interface PanelPin { | |
| 16 | readonly slug: string; | |
| 17 | readonly index: number; | |
| 18 | } | |
| 19 | ||
| 20 | export const samePin = (a: PanelPin, b: PanelPin): boolean => a.slug === b.slug && a.index === b.index; | |
| 21 | ||
| 22 | export function pinsOf(db: Database, userId: string): PanelPin[] { | |
| 23 | const out: PanelPin[] = []; | |
| 24 | for (const part of (getUserSetting(db, userId, KEY) ?? "").split(";")) { | |
| 25 | const [slug = "", n = ""] = part.split(":"); | |
| 26 | const index = /^\d{1,2}$/.test(n) ? Number(n) : -1; | |
| 27 | if (isSlug(slug) && index >= 0) out.push({ slug, index }); | |
| 28 | } | |
| 29 | return out; | |
| 30 | } | |
| 31 | ||
| 32 | const save = (db: Database, userId: string, pins: readonly PanelPin[]): boolean => { | |
| 33 | const value = pins.map((p) => `${p.slug}:${p.index}`).join(";"); | |
| 34 | if (value.length > MAX_LEN) return false; | |
| 35 | setUserSetting(db, userId, KEY, value); | |
| 36 | return true; | |
| 37 | }; | |
| 38 | ||
| 39 | /** Pin (idempotent, at the end); false when it does not fit. */ | |
| 40 | export function pinPanel(db: Database, userId: string, pin: PanelPin): boolean { | |
| 41 | const pins = pinsOf(db, userId); | |
| 42 | return pins.some((p) => samePin(p, pin)) || save(db, userId, [...pins, pin]); | |
| 43 | } | |
| 44 | ||
| 45 | export function unpinPanel(db: Database, userId: string, pin: PanelPin): void { | |
| 46 | save(db, userId, pinsOf(db, userId).filter((p) => !samePin(p, pin))); | |
| 47 | } | |
| 48 | ||
| 49 | /** Move a pin one place earlier (-1) or later (1) in the owner's order. */ | |
| 50 | export function movePin(db: Database, userId: string, pin: PanelPin, by: -1 | 1): void { | |
| 51 | const pins = pinsOf(db, userId); | |
| 52 | const at = pins.findIndex((p) => samePin(p, pin)); | |
| 53 | const to = at + by; | |
| 54 | if (at < 0 || to < 0 || to >= pins.length) return; | |
| 55 | [pins[at], pins[to]] = [pins[to]!, pins[at]!]; | |
| 56 | save(db, userId, pins); | |
| 57 | } |
src/core/kpis.ts added +148
| @@ -0,0 +1,148 @@ | ||
| 1 | /** | |
| 2 | * The forge's vital signs, read live for the owner's home: real landings per | |
| 3 | * hour, the live version, median check time, builders at work, today's spend, | |
| 4 | * the age of the last off-box backup. Plain data out — a label, a value, a | |
| 5 | * note, the page it comes from — so the page only draws. A handful of grouped | |
| 6 | * queries and two small files; nothing is cached or shelled out. | |
| 7 | */ | |
| 8 | import type { Database } from "bun:sqlite"; | |
| 9 | import { dayStart, getAccountCeiling } from "./account_ceiling.ts"; | |
| 10 | import { lastMirror } from "../snapshot/mirror.ts"; | |
| 11 | import { running } from "../kernel/version.ts"; | |
| 12 | ||
| 13 | export interface Kpi { | |
| 14 | readonly key: string; | |
| 15 | readonly label: string; | |
| 16 | readonly value: string; | |
| 17 | readonly note: string; | |
| 18 | /** The board or page this number comes from. */ | |
| 19 | readonly href: string; | |
| 20 | /** Twenty-four hourly counts, oldest first, for a sparkline. */ | |
| 21 | readonly spark?: readonly number[]; | |
| 22 | } | |
| 23 | ||
| 24 | const HOUR = 3_600_000; | |
| 25 | ||
| 26 | /** Merged pulls into a default branch, by hour for the last 24 h, oldest first. */ | |
| 27 | export function landingsByHour(db: Database, now: number): number[] { | |
| 28 | const first = Math.floor(now / HOUR) * HOUR - 23 * HOUR; | |
| 29 | const rows = db | |
| 30 | .query<{ at: string }, [string]>( | |
| 31 | `SELECT p.merged_at AS at FROM pull p | |
| 32 | JOIN issue i ON i.id = p.issue_id JOIN repo r ON r.id = i.repo_id | |
| 33 | WHERE p.merged_at >= ?1 AND p.base_branch = r.default_branch`, | |
| 34 | ) | |
| 35 | .all(new Date(first).toISOString()); | |
| 36 | const counts = new Array<number>(24).fill(0); | |
| 37 | for (const { at } of rows) { | |
| 38 | const slot = Math.floor((Date.parse(at) - first) / HOUR); | |
| 39 | if (slot >= 0 && slot < 24) counts[slot] = (counts[slot] ?? 0) + 1; | |
| 40 | } | |
| 41 | return counts; | |
| 42 | } | |
| 43 | ||
| 44 | /** The median of finished checks' wall time over the last day, in ms, or undefined. */ | |
| 45 | export function medianCheckMs(db: Database, now: number): number | undefined { | |
| 46 | const rows = db | |
| 47 | .query<{ started_at: string; finished_at: string }, [string]>( | |
| 48 | `SELECT started_at, finished_at FROM run | |
| 49 | WHERE kind = 'check' AND started_at IS NOT NULL AND finished_at >= ?1 | |
| 50 | ORDER BY finished_at DESC LIMIT 500`, | |
| 51 | ) | |
| 52 | .all(new Date(now - 24 * HOUR).toISOString()); | |
| 53 | const spans = rows | |
| 54 | .map((r) => Date.parse(r.finished_at) - Date.parse(r.started_at)) | |
| 55 | .filter((n) => Number.isFinite(n) && n >= 0) | |
| 56 | .sort((a, b) => a - b); | |
| 57 | if (spans.length === 0) return undefined; | |
| 58 | const mid = Math.floor(spans.length / 2); | |
| 59 | return spans.length % 2 === 1 ? spans[mid]! : (spans[mid - 1]! + spans[mid]!) / 2; | |
| 60 | } | |
| 61 | ||
| 62 | const span = (ms: number): string => { | |
| 63 | const s = Math.round(ms / 1000); | |
| 64 | if (s < 90) return `${s}s`; | |
| 65 | const m = Math.round(s / 60); | |
| 66 | return m < 90 ? `${m} min` : `${(m / 60).toFixed(1)} h`; | |
| 67 | }; | |
| 68 | ||
| 69 | const age = (iso: string, now: number): string => { | |
| 70 | const ms = now - Date.parse(iso); | |
| 71 | return Number.isFinite(ms) ? `${span(Math.max(0, ms))} ago` : "unknown"; | |
| 72 | }; | |
| 73 | ||
| 74 | const usd = (n: number): string => `$${n.toFixed(n < 100 ? 2 : 0)}`; | |
| 75 | ||
| 76 | export function readKpis( | |
| 77 | db: Database, | |
| 78 | dataDir: string, | |
| 79 | userId: string, | |
| 80 | booted: string, | |
| 81 | now = Date.now(), | |
| 82 | ): Kpi[] { | |
| 83 | const spark = landingsByHour(db, now); | |
| 84 | const total = spark.reduce((a, b) => a + b, 0); | |
| 85 | const live = running(); | |
| 86 | const check = medianCheckMs(db, now); | |
| 87 | const busy = | |
| 88 | db.query<{ n: number }, []>("SELECT COUNT(*) AS n FROM run WHERE kind = 'agent' AND state = 'running'").get()?.n ?? 0; | |
| 89 | const slots = | |
| 90 | db | |
| 91 | .query<{ n: number | null }, []>("SELECT SUM(autonomy_slots) AS n FROM repo WHERE autonomy != 'off'") | |
| 92 | .get()?.n ?? 0; | |
| 93 | const spent = | |
| 94 | db | |
| 95 | .query<{ n: number }, [string, string]>( | |
| 96 | `SELECT COALESCE(SUM(u.cost_usd), 0) AS n FROM usage u JOIN repo r ON r.id = u.repo_id | |
| 97 | WHERE r.owner_id = ?1 AND u.at >= ?2`, | |
| 98 | ) | |
| 99 | .get(userId, dayStart(new Date(now)))?.n ?? 0; | |
| 100 | const ceiling = getAccountCeiling(db, userId); | |
| 101 | const mirror = lastMirror(dataDir); | |
| 102 | const synced = mirror?.syncedAt; | |
| 103 | return [ | |
| 104 | { | |
| 105 | key: "landings", | |
| 106 | label: "Landings per hour", | |
| 107 | value: (total / 24).toFixed(1), | |
| 108 | note: `${total} in the last 24 h`, | |
| 109 | href: "/boards/data?source=stages&fcolumn=stage&fop=eq&fvalue=4+merged&by=hour&chart=bar", | |
| 110 | spark, | |
| 111 | }, | |
| 112 | { | |
| 113 | key: "live", | |
| 114 | label: "Live version", | |
| 115 | value: live.version, | |
| 116 | note: `live ${age(booted, now)}`, | |
| 117 | href: "/releases", | |
| 118 | }, | |
| 119 | { | |
| 120 | key: "check", | |
| 121 | label: "Median check", | |
| 122 | value: check === undefined ? "none" : span(check), | |
| 123 | note: "finished in the last 24 h", | |
| 124 | href: "/boards/data?source=runs&fcolumn=kind&fop=eq&fvalue=check&by=day&chart=bar", | |
| 125 | }, | |
| 126 | { | |
| 127 | key: "builders", | |
| 128 | label: "Builders at work", | |
| 129 | value: `${busy} of ${slots}`, | |
| 130 | note: "running now, of slots", | |
| 131 | href: "/flow", | |
| 132 | }, | |
| 133 | { | |
| 134 | key: "spend", | |
| 135 | label: "Spent today", | |
| 136 | value: ceiling === undefined ? usd(spent) : `${usd(spent)} of ${usd(ceiling.dailyUsd)}`, | |
| 137 | note: ceiling === undefined ? "no daily ceiling set" : "of today's ceiling", | |
| 138 | href: "/boards/data?source=spend&aggregate=sum&column=cost_usd&by=day&chart=bar", | |
| 139 | }, | |
| 140 | { | |
| 141 | key: "backup", | |
| 142 | label: "Off-box backup", | |
| 143 | value: synced === undefined ? "none" : age(synced, now), | |
| 144 | note: synced === undefined ? "no copy kept elsewhere" : "last confirmed good", | |
| 145 | href: "/settings/backups", | |
| 146 | }, | |
| 147 | ]; | |
| 148 | } |
src/http/server.ts +2
| @@ -23,6 +23,7 @@ import { usagePage } from "../web/pages/usage.ts"; | ||
| 23 | 23 | import { domainsPage } from "../web/pages/domains.ts"; |
| 24 | 24 | import { resiliencePage } from "../web/pages/resilience.ts"; |
| 25 | 25 | import { limitsPage, limitsSet, quotasSet, signupSet, inviteMint, inviteRevoke } from "../web/pages/admin-limits.ts"; |
| 26 | import { homePanels } from "../web/studio/home_owner.ts"; | |
| 26 | 27 | import { boardsPage } from "../web/pages/boards.ts"; |
| 27 | 28 | import { boardNew, boardPin, boardPost } from "../web/pages/boards-edit.ts"; |
| 28 | 29 | import { boardLive, boardShow, boardsList } from "../web/pages/boards-view.ts"; |
| @@ -810,6 +811,7 @@ export function buildRouter(): Router<Handler> { | ||
| 810 | 811 | router.add("GET", "/boards", boardsList); |
| 811 | 812 | router.add("GET", "/boards/data", boardsPage); |
| 812 | 813 | router.add("POST", "/boards/new", boardNew); |
| 814 | router.add("POST", "/home/panels", homePanels); | |
| 813 | 815 | router.add("POST", "/boards/pin", boardPin); |
| 814 | 816 | router.add("GET", "/boards/:slug", boardShow); |
| 815 | 817 | router.add("GET", "/boards/:slug/live", boardLive); |
src/web/pages/board.ts +2 −2
| @@ -394,7 +394,7 @@ function reviewStrip(ctx: Ctx, scope: BoardScope): Html | null { | ||
| 394 | 394 | if (!none && waits.length === 0) return []; |
| 395 | 395 | const oldest = waits.map((w) => w.since).sort()[0]; |
| 396 | 396 | return [ |
| 397 | html`<a class="board-asks" href="/#needs-you" | |
| 397 | html`<a class="board-asks" href="/asks" | |
| 398 | 398 | ><b>${repo.name}</b>: ${none ? "No reviewer: agent pulls wait for you" : "agent pulls wait for your review"}${waits.length === 0 |
| 399 | 399 | ? null |
| 400 | 400 | : html` · <b>${waits.length}</b> waiting since ${oldest!.slice(0, 10)}`}</a |
| @@ -421,7 +421,7 @@ function asksStrip(ctx: Ctx): Html | null { | ||
| 421 | 421 | const since = new Date(Date.now() - ASKS_WINDOW_DAYS * 86_400_000).toISOString(); |
| 422 | 422 | const m = askMeasure(ctx.app.db, user.id, since); |
| 423 | 423 | if (m.raised + m.acted + m.dismissed + m.expired === 0) return null; |
| 424 | return html`<a class="board-asks" id="asks-measure" href="/#needs-you" | |
| 424 | return html`<a class="board-asks" id="asks-measure" href="/asks" | |
| 425 | 425 | >Asks, ${ASKS_WINDOW_DAYS} days: <b>${m.raised}</b> raised · <b>${m.acted}</b> acted |
| 426 | 426 | on · <b>${m.dismissed}</b> dismissed · <b>${m.expired}</b> went by themselves</a |
| 427 | 427 | >`; |
src/web/pages/boards-view.ts +18 −6
| @@ -7,6 +7,7 @@ | ||
| 7 | 7 | * the same swap the wall uses, no client framework. Every form posts to |
| 8 | 8 | * `boards-edit.ts`. Anyone but a person who is an admin gets the not-found page. |
| 9 | 9 | */ |
| 10 | import { pinsOf, samePin, type PanelPin } from "../../core/home_panels.ts"; | |
| 10 | 11 | import { listAllBoards, showBoard } from "../../actions/boards.ts"; |
| 11 | 12 | import { CHART_NAMES } from "../../boards/chart.ts"; |
| 12 | 13 | import { MAX_H, MAX_PANELS, MAX_TITLE, MAX_W, RANGES, REFRESHES, type Board, type Panel } from "../../boards/store.ts"; |
| @@ -31,7 +32,8 @@ function ranged(query: Record<string, unknown>, range: Board["range"]): Record<s | ||
| 31 | 32 | return { ...query, from: new Date(Date.now() - RANGE_MS[range]).toISOString() }; |
| 32 | 33 | } |
| 33 | 34 | |
| 34 | function drawPanel(app: App, board: Board, panel: Panel): Html { | |
| 35 | /** One panel's card; `controls` sit in its head beside "explore". */ | |
| 36 | export function drawPanel(app: App, board: Board, panel: Panel, controls: Html | null = null): Html { | |
| 35 | 37 | const answer = runFor(app.db, panel.chart, ranged(panel.query, board.range)); |
| 36 | 38 | const q = paramsOf(panel.query, panel.chart); |
| 37 | 39 | const body = !answer.ok |
| @@ -40,13 +42,13 @@ function drawPanel(app: App, board: Board, panel: Panel): Html { | ||
| 40 | 42 | const explore = new URLSearchParams(Object.entries(q).filter(([k, v]) => v !== "" && k !== "rows")); |
| 41 | 43 | return html`<div class="card bp-w${String(panel.w)} bp-h${String(panel.h)}"> |
| 42 | 44 | <div class="card-head"><h2>${panel.title}</h2> |
| 43 | <a class="muted small" href="/boards/data?${explore.toString()}">explore</a></div> | |
| 45 | <a class="muted small" href="/boards/data?${explore.toString()}">explore</a>${controls}</div> | |
| 44 | 46 | <div class="card-body">${body}</div> |
| 45 | 47 | </div>`; |
| 46 | 48 | } |
| 47 | 49 | |
| 48 | 50 | /** The grid alone: what the page shows and what the live address answers with. */ |
| 49 | function grid(app: App, slug: string, board: Board): Html { | |
| 51 | function grid(app: App, slug: string, board: Board, pins: readonly PanelPin[]): Html { | |
| 50 | 52 | const every = board.refresh === "off" ? null : EVERY[board.refresh]; |
| 51 | 53 | return html`<section |
| 52 | 54 | class="bgrid" |
| @@ -57,10 +59,20 @@ function grid(app: App, slug: string, board: Board): Html { | ||
| 57 | 59 | > |
| 58 | 60 | ${board.panels.length === 0 |
| 59 | 61 | ? html`<p class="muted">No panels yet. Add one below.</p>` |
| 60 | : board.panels.map((p) => drawPanel(app, board, p))} | |
| 62 | : board.panels.map((p, index) => { | |
| 63 | const pinned = pins.some((x) => samePin(x, { slug, index })); | |
| 64 | return drawPanel(app, board, p, html`<form method="post" action="/home/panels" class="inline"> | |
| 65 | <input type="hidden" name="slug" value="${slug}" /><input type="hidden" name="index" value="${String(index)}" /> | |
| 66 | <input type="hidden" name="back" value="/boards/${slug}" /> | |
| 67 | <button class="btn btn-sm btn-ghost" name="action" value="${pinned ? "unpin" : "pin"}" | |
| 68 | >${pinned ? "Unpin from home" : "Pin to home"}</button> | |
| 69 | </form>`); | |
| 70 | })} | |
| 61 | 71 | </section>`; |
| 62 | 72 | } |
| 63 | 73 | |
| 74 | const pinsFor = (ctx: Ctx): PanelPin[] => (ctx.auth.user ? pinsOf(ctx.app.db, ctx.auth.user.id) : []); | |
| 75 | ||
| 64 | 76 | const denied = (ctx: Ctx) => { |
| 65 | 77 | const u = ctx.auth.user; |
| 66 | 78 | return u?.isAdmin !== true || u.kind === "agent"; |
| @@ -163,7 +175,7 @@ export async function boardShow(ctx: Ctx): Promise<Response> { | ||
| 163 | 175 | title: board.title, |
| 164 | 176 | body: html`<div class="page-head"><h1>${board.title}</h1> |
| 165 | 177 | ${btn("All boards", { href: "/boards", variant: "ghost" })}</div> |
| 166 | ${grid(ctx.app, slug, board)} | |
| 178 | ${grid(ctx.app, slug, board, pinsFor(ctx))} | |
| 167 | 179 | ${manage(slug, board, queryFields(readParams(ctx.url.searchParams)))}`, |
| 168 | 180 | scriptJs: liveRegionsJs, |
| 169 | 181 | }); |
| @@ -175,5 +187,5 @@ export async function boardLive(ctx: Ctx): Promise<Response> { | ||
| 175 | 187 | const slug = ctx.params.slug ?? ""; |
| 176 | 188 | const shown = await showBoard(ctx.app, ctx.auth.user, slug); |
| 177 | 189 | if (!shown.ok) return fragment(html``, { status: 404 }); |
| 178 | return fragment(grid(ctx.app, slug, shown.value), { request: ctx.request }); | |
| 190 | return fragment(grid(ctx.app, slug, shown.value, pinsFor(ctx)), { request: ctx.request }); | |
| 179 | 191 | } |
src/web/pages/site.ts +4
| @@ -24,6 +24,7 @@ import { hasAnyUser, verifyPasswordThrottled, type User } from "../../core/users | ||
| 24 | 24 | import { isThemeName } from "../../design/themes.ts"; |
| 25 | 25 | import { cookieValue, crossOrigin, type Ctx } from "../../http/context.ts"; |
| 26 | 26 | import { studioDoor, studioHome } from "../studio/home.ts"; |
| 27 | import { isOwner } from "../studio/home_owner.ts"; | |
| 27 | 28 | import { homeTop } from "../studio/asks_page.ts"; |
| 28 | 29 | import { edgeLoginUrl } from "../../http/edge.ts"; |
| 29 | 30 | import { sshCommand } from "../../ssh/command.ts"; |
| @@ -208,6 +209,9 @@ export function terminalCard(ctx: Ctx): Html { | ||
| 208 | 209 | export async function home(ctx: Ctx): Promise<Response> { |
| 209 | 210 | const user = ctx.auth.user; |
| 210 | 211 | if (user === undefined) return studioDoor(ctx); |
| 212 | // A bulk step's receipt belongs to the asks, which the owner's home leaves out. | |
| 213 | if (isOwner(user) && (ctx.url.searchParams.has("op") || ctx.url.searchParams.has("decided"))) | |
| 214 | return redirect(`/asks${ctx.url.search}`); | |
| 211 | 215 | return await studioHome(ctx, user, homeTop(ctx)); |
| 212 | 216 | } |
| 213 | 217 |
src/web/studio/asks_page.ts +7 −2
| @@ -28,6 +28,7 @@ import type { Degraded } from "../../kernel/vitals.ts"; | ||
| 28 | 28 | import type { Ctx } from "../../http/context.ts"; |
| 29 | 29 | import type { User } from "../../core/users.ts"; |
| 30 | 30 | import { onYouAnswer, studioHome } from "./home.ts"; |
| 31 | import { isOwner } from "./home_owner.ts"; | |
| 31 | 32 | import { notFoundPage, repoBase, signInFirst } from "../chrome.ts"; |
| 32 | 33 | import { backTo, field, readForm } from "../form.ts"; |
| 33 | 34 | import { MAX_BODY } from "../../core/issues.ts"; |
| @@ -334,7 +335,11 @@ export interface AsksTop { | ||
| 334 | 335 | |
| 335 | 336 | /** GET /asks — the home, scrolled to what needs you; `?op=<id>` (a bulk |
| 336 | 337 | * action's receipt) rides along. */ |
| 337 | export function asksPage(ctx: Ctx): Response { | |
| 338 | export async function asksPage(ctx: Ctx): Promise<Response> { | |
| 339 | const user = ctx.auth.user; | |
| 340 | // The owner's home shows no list; their asks are here, on request. | |
| 341 | if (user !== undefined && isOwner(user)) | |
| 342 | return await studioHome(ctx, user, homeTop(ctx), true); | |
| 338 | 343 | const op = ctx.url.searchParams.get("op"); |
| 339 | 344 | return redirect( |
| 340 | 345 | op === null |
| @@ -492,7 +497,7 @@ export function needsYouSection( | ||
| 492 | 497 | async function asksScreen(ctx: Ctx, top: AsksTop): Promise<Response> { |
| 493 | 498 | const user = ctx.auth.user; |
| 494 | 499 | if (!user) return signInFirst(ctx); |
| 495 | return await studioHome(ctx, user, top); | |
| 500 | return await studioHome(ctx, user, top, isOwner(user)); | |
| 496 | 501 | } |
| 497 | 502 | |
| 498 | 503 | // ---- many at once: select, preview, do it, undo — all on this screen ---- |
src/web/studio/home.ts +16 −2
| @@ -46,6 +46,7 @@ import { | ||
| 46 | 46 | } from "../pages/site.ts"; |
| 47 | 47 | import { writableAppsOf } from "./asks.ts"; |
| 48 | 48 | import { needsYouSection, type AsksTop } from "./asks_page.ts"; |
| 49 | import { isOwner, kpiRow, pinnedPanels } from "./home_owner.ts"; | |
| 49 | 50 | import { flowCards } from "./flow_card.ts"; |
| 50 | 51 | import { composer, feedJs, feedNote, feedRegion } from "./feed.ts"; |
| 51 | 52 | import { homeTabs } from "./home_tabs.ts"; |
| @@ -206,8 +207,20 @@ export async function studioHome( | ||
| 206 | 207 | ctx: Ctx, |
| 207 | 208 | user: User, |
| 208 | 209 | top?: AsksTop, |
| 210 | onlyAsks = false, | |
| 209 | 211 | ): Promise<Response> { |
| 210 | const needsYou = needsYouSection(ctx, user, top); | |
| 212 | const owner = isOwner(user); | |
| 213 | // The owner's home never lists what waits on them; `/asks` does, on purpose. | |
| 214 | if (owner && onlyAsks) { | |
| 215 | const needs = needsYouSection(ctx, user, top); | |
| 216 | return page({ | |
| 217 | ctx, | |
| 218 | title: "Asks", | |
| 219 | body: html`<h1>Asks</h1>${onYouRegion(ctx, user, undefined, needs.body)}`, | |
| 220 | scriptJs: `${liveClientJs}\n${liveRegionsJs}\n${needs.scriptJs}`, | |
| 221 | }); | |
| 222 | } | |
| 223 | const needsYou = owner ? { body: html``, scriptJs: "" } : needsYouSection(ctx, user, top); | |
| 211 | 224 | const { repos: appRepos } = writableAppsOf(ctx, user); |
| 212 | 225 | // A spawned forge says where it lives: the address its person shares. |
| 213 | 226 | const spawned = await spawnedOrg(ctx.app); |
| @@ -253,10 +266,11 @@ export async function studioHome( | ||
| 253 | 266 | <a href="/">Just my apps</a> |
| 254 | 267 | </p>`, |
| 255 | 268 | )} |
| 269 | ${owner ? kpiRow(ctx, user) : null} ${owner ? await pinnedPanels(ctx, user) : null} | |
| 256 | 270 | ${homeTabs("feed")} |
| 257 | 271 | <div class="dash"> |
| 258 | 272 | <div class="dash-main stack"> |
| 259 | ${onYouRegion(ctx, user, undefined, needsYou.body)} ${composer(ctx, user)} | |
| 273 | ${owner ? null : onYouRegion(ctx, user, undefined, needsYou.body)} ${composer(ctx, user)} | |
| 260 | 274 | <div class="bar feed-head"> |
| 261 | 275 | <span class="spacer"></span> |
| 262 | 276 | <a class="small muted" href="/asked">What you asked for</a> |
src/web/studio/home_owner.ts added +94
| @@ -0,0 +1,94 @@ | ||
| 1 | /** | |
| 2 | * The owner's home: the forge's vital signs, then the board panels the owner | |
| 3 | * pinned, in their order. Never a list of what waits on the owner — that | |
| 4 | * list is `/asks`, reached on purpose. The owner is a person who administers | |
| 5 | * the forge (boards are theirs alone). `POST /home/panels` pins, unpins and | |
| 6 | * moves a pinned panel; same-origin checked by `readForm`. | |
| 7 | */ | |
| 8 | import { showBoard } from "../../actions/boards.ts"; | |
| 9 | import { movePin, pinPanel, pinsOf, unpinPanel } from "../../core/home_panels.ts"; | |
| 10 | import { readKpis, type Kpi } from "../../core/kpis.ts"; | |
| 11 | import type { User } from "../../core/users.ts"; | |
| 12 | import type { Ctx } from "../../http/context.ts"; | |
| 13 | import { BOOTED } from "../../release/gate.ts"; | |
| 14 | import { notFoundPage } from "../chrome.ts"; | |
| 15 | import { isLocalPath } from "../flash.ts"; | |
| 16 | import { field, readForm } from "../form.ts"; | |
| 17 | import { html, type Html } from "../html.ts"; | |
| 18 | import { flashTo } from "../layout.ts"; | |
| 19 | import { drawPanel } from "../pages/boards-view.ts"; | |
| 20 | import { isSlug } from "../../boards/store.ts"; | |
| 21 | ||
| 22 | /** A person who administers the forge: the one whose home is the vital signs. */ | |
| 23 | export const isOwner = (user: User): boolean => user.isAdmin && user.kind !== "agent"; | |
| 24 | ||
| 25 | function spark(counts: readonly number[]): Html { | |
| 26 | const top = Math.max(1, ...counts); | |
| 27 | const pts = counts.map((n, i) => `${((i / (counts.length - 1)) * 100).toFixed(1)},${(18 - (n / top) * 16 - 1).toFixed(1)}`); | |
| 28 | return html`<svg viewBox="0 0 100 18" preserveAspectRatio="none" aria-hidden="true"><polyline points="${pts.join(" ")}" /></svg>`; | |
| 29 | } | |
| 30 | ||
| 31 | function tile(k: Kpi): Html { | |
| 32 | return html`<li><a class="kpi" id="kpi-${k.key}" href="${k.href}"> | |
| 33 | <span class="kpi-label">${k.label}</span> | |
| 34 | <span class="kpi-value">${k.value}</span> | |
| 35 | ${k.spark ? spark(k.spark) : null} | |
| 36 | <span class="kpi-note">${k.note}</span> | |
| 37 | </a></li>`; | |
| 38 | } | |
| 39 | ||
| 40 | export function kpiRow(ctx: Ctx, user: User): Html { | |
| 41 | const kpis = readKpis(ctx.app.db, ctx.app.config.dataDir, user.id, BOOTED); | |
| 42 | return html`<ul class="kpis" aria-label="How the forge is">${kpis.map(tile)}</ul>`; | |
| 43 | } | |
| 44 | ||
| 45 | const IDX = /^\d{1,2}$/; | |
| 46 | ||
| 47 | /** The pinned panels, drawn; a pin whose board or panel is gone is skipped. */ | |
| 48 | export async function pinnedPanels(ctx: Ctx, user: User): Promise<Html | null> { | |
| 49 | const pins = pinsOf(ctx.app.db, user.id); | |
| 50 | const cards: Html[] = []; | |
| 51 | for (const pin of pins) { | |
| 52 | const shown = await showBoard(ctx.app, user, pin.slug); | |
| 53 | const panel = shown.ok ? shown.value.panels[pin.index] : undefined; | |
| 54 | if (!shown.ok || panel === undefined) continue; | |
| 55 | const act = (action: string, label: string) => | |
| 56 | html`<button class="btn btn-sm btn-ghost" name="action" value="${action}">${label}</button>`; | |
| 57 | cards.push( | |
| 58 | drawPanel(ctx.app, shown.value, panel, html`<form method="post" action="/home/panels" class="inline"> | |
| 59 | <input type="hidden" name="slug" value="${pin.slug}" /><input type="hidden" name="index" value="${String(pin.index)}" /> | |
| 60 | <input type="hidden" name="back" value="/" /> | |
| 61 | ${act("up", "Up")} ${act("down", "Down")} ${act("unpin", "Unpin")} | |
| 62 | </form>`), | |
| 63 | ); | |
| 64 | } | |
| 65 | return cards.length === 0 ? null : html`<section class="bgrid home-pins" aria-label="Pinned panels">${cards}</section>`; | |
| 66 | } | |
| 67 | ||
| 68 | // POST /home/panels | |
| 69 | export async function homePanels(ctx: Ctx): Promise<Response> { | |
| 70 | const form = await readForm(ctx, "admin"); | |
| 71 | if (form instanceof Response) return form; | |
| 72 | const user = ctx.auth.user; | |
| 73 | if (user === undefined || !isOwner(user)) return notFoundPage(ctx); | |
| 74 | const slug = field(form, "slug"); | |
| 75 | const index = field(form, "index"); | |
| 76 | const action = field(form, "action"); | |
| 77 | const asked = field(form, "back"); | |
| 78 | const back = isLocalPath(asked) ? asked : "/"; | |
| 79 | if (!isSlug(slug) || !IDX.test(index)) return notFoundPage(ctx); | |
| 80 | const pin = { slug, index: Number(index) }; | |
| 81 | const db = ctx.app.db; | |
| 82 | if (action === "pin") { | |
| 83 | const shown = await showBoard(ctx.app, user, slug); | |
| 84 | if (!shown.ok || shown.value.panels[pin.index] === undefined) return notFoundPage(ctx); | |
| 85 | return pinPanel(db, user.id, pin) | |
| 86 | ? flashTo(ctx, back, { message: "Pinned to home." }) | |
| 87 | : flashTo(ctx, back, { tone: "danger", message: "Too many pins; unpin one first." }); | |
| 88 | } | |
| 89 | if (action === "unpin") unpinPanel(db, user.id, pin); | |
| 90 | else if (action === "up") movePin(db, user.id, pin, -1); | |
| 91 | else if (action === "down") movePin(db, user.id, pin, 1); | |
| 92 | else return notFoundPage(ctx); | |
| 93 | return flashTo(ctx, back, { message: action === "unpin" ? "Unpinned." : "Moved." }); | |
| 94 | } |
src/web/style/content.ts +11
| @@ -1311,4 +1311,15 @@ textarea.editor:focus { outline: none; } | ||
| 1311 | 1311 | .ask-more-acts[open] > summary { display: none; } |
| 1312 | 1312 | .ask-more-acts > .btn { min-height: 44px; flex: 1 1 auto; } |
| 1313 | 1313 | } |
| 1314 | ||
| 1315 | /* The owner's home: a row of vital signs that wraps, then pinned panels. */ | |
| 1316 | .kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 0 0 16px; padding: 0; list-style: none; } | |
| 1317 | .kpi { display: block; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; color: inherit; text-decoration: none; min-width: 0; min-height: 84px; } | |
| 1318 | .kpi:hover { border-color: var(--border-strong); } | |
| 1319 | .kpi-label { display: block; font-size: 12px; color: var(--muted-fg); } | |
| 1320 | .kpi-value { display: block; font-size: 20px; font-weight: 600; overflow-wrap: anywhere; } | |
| 1321 | .kpi-note { display: block; font-size: 12px; color: var(--muted-fg); } | |
| 1322 | .kpi svg { display: block; width: 100%; height: 18px; } | |
| 1323 | .kpi polyline { fill: none; stroke: currentColor; stroke-width: 1.5; vector-effect: non-scaling-stroke; } | |
| 1324 | .home-pins { margin-bottom: 16px; } | |
| 1314 | 1325 | `; |
test/asks-bulk.test.ts +1 −1
| @@ -77,7 +77,7 @@ describe("acting on many asks at once", () => { | ||
| 77 | 77 | const location = res.headers.get("location"); |
| 78 | 78 | if (res.status === 303 && location !== null) { |
| 79 | 79 | expect(location).toStartWith("/?op="); |
| 80 | const next = await fetch(`${servers.url}${location}`, { headers, redirect: "manual" }); | |
| 80 | const next = await fetch(`${servers.url}${location}`, { headers, redirect: "follow" }); | |
| 81 | 81 | expect(next.status).toBe(200); |
| 82 | 82 | return (await next.text()).replace(/\s+/g, " "); |
| 83 | 83 | } |
test/asks-expiry.test.ts +7 −7
| @@ -126,7 +126,7 @@ describe("asks that expire, hold and collapse", () => { | ||
| 126 | 126 | pears = await botPull("pears", [{ path: "PEARS.md", content: "pears\n" }]); |
| 127 | 127 | green(apples); |
| 128 | 128 | green(pears); |
| 129 | const page = await get("/"); | |
| 129 | const page = await get("/asks"); | |
| 130 | 130 | expect(sentence(page)).toBe("1 thing needs you"); |
| 131 | 131 | expect(headerCount(page)).toBe(1); |
| 132 | 132 | expect(page).toContain("2 green changes wait for your look"); |
| @@ -152,7 +152,7 @@ describe("asks that expire, hold and collapse", () => { | ||
| 152 | 152 | // card at all, so there is nothing to mute. |
| 153 | 153 | const fragment = await get("/live/feed"); |
| 154 | 154 | expect(fragment).not.toContain('data-kind="ask"'); |
| 155 | const home = await get("/"); | |
| 155 | const home = await get("/asks"); | |
| 156 | 156 | expect(home).toContain('<section id="needs-you"'); |
| 157 | 157 | const at = home.indexOf('<section id="needs-you"'); |
| 158 | 158 | expect(home.slice(at, home.indexOf("</section>", at))).not.toContain( |
| @@ -169,7 +169,7 @@ describe("asks that expire, hold and collapse", () => { | ||
| 169 | 169 | repoId: repo.id, |
| 170 | 170 | actorId: null, |
| 171 | 171 | }); |
| 172 | let page = await get("/"); | |
| 172 | let page = await get("/asks"); | |
| 173 | 173 | expect(sentence(page)).toBe("All fine"); |
| 174 | 174 | expect(headerCount(page)).toBe(0); |
| 175 | 175 | expect(askLinesFor(app.db, aliceUser)).toHaveLength(0); |
| @@ -179,7 +179,7 @@ describe("asks that expire, hold and collapse", () => { | ||
| 179 | 179 | // A new check on one of them: that one asks again, on its own. |
| 180 | 180 | await tick(); |
| 181 | 181 | green(apples); |
| 182 | page = await get("/"); | |
| 182 | page = await get("/asks"); | |
| 183 | 183 | expect(sentence(page)).toBe("1 thing needs you"); |
| 184 | 184 | const pinned = page.slice( |
| 185 | 185 | page.indexOf('<section id="needs-you"'), |
| @@ -203,7 +203,7 @@ describe("asks that expire, hold and collapse", () => { | ||
| 203 | 203 | repoId: repo.id, |
| 204 | 204 | actorId: null, |
| 205 | 205 | }); |
| 206 | expect(sentence(await get("/"))).toBe("All fine"); | |
| 206 | expect(sentence(await get("/asks"))).toBe("All fine"); | |
| 207 | 207 | // The merge box is the change's Files step (#628). |
| 208 | 208 | const change = await get( |
| 209 | 209 | `/${repo.ownerName}/${repo.name}/pulls/${apples.number}/files`, |
| @@ -231,7 +231,7 @@ describe("asks that expire, hold and collapse", () => { | ||
| 231 | 231 | }); |
| 232 | 232 | await sweepStaleAsks(app); |
| 233 | 233 | expect(askLinesFor(app.db, aliceUser)).toHaveLength(0); |
| 234 | expect(sentence(await get("/"))).toBe("All fine"); | |
| 234 | expect(sentence(await get("/asks"))).toBe("All fine"); | |
| 235 | 235 | // The feed and the MCP's asks carry no green line for it either. |
| 236 | 236 | expect( |
| 237 | 237 | readFeed(app.db, aliceUser, { limit: 50 }).items.some( |
| @@ -241,7 +241,7 @@ describe("asks that expire, hold and collapse", () => { | ||
| 241 | 241 | expect(JSON.stringify(asksAnswer({ app, auth: { user: aliceUser } } as never, aliceUser))).not.toContain("is green"); |
| 242 | 242 | // Assigned to alice, the home's one list says it conflicts, never ready. |
| 243 | 243 | setAssignee(app.db, plums.id, aliceUser.id); |
| 244 | const home = await get("/"); | |
| 244 | const home = await get("/asks"); | |
| 245 | 245 | expect(home).toContain("conflicts with main"); |
| 246 | 246 | expect(askLinesFor(app.db, aliceUser).map((l) => l.waitingFor.word)).toEqual(["conflicts with main"]); |
| 247 | 247 | // Its own page still says why it cannot ship. |
test/asks-mute.test.ts +1 −1
| @@ -60,7 +60,7 @@ describe("muting a repository's asks", () => { | ||
| 60 | 60 | return ((await res.json()) as { rows: unknown[] }).rows; |
| 61 | 61 | }; |
| 62 | 62 | const home = async () => |
| 63 | await fetch(`${servers.url}/`, { headers: headers(cookie) }).then((r) => r.text()); | |
| 63 | await fetch(`${servers.url}/asks`, { headers: headers(cookie) }).then((r) => r.text()); | |
| 64 | 64 | |
| 65 | 65 | const signIn = async (username: string) => { |
| 66 | 66 | const res = await fetch(`${servers.url}/signin`, { |
test/asks-rank.test.ts +4 −4
| @@ -204,7 +204,7 @@ describe("asks that earn their place", () => { | ||
| 204 | 204 | expect(row.words).toEqual(ASK_WORDS.look); |
| 205 | 205 | expect(row.words.options.length).toBeGreaterThan(0); |
| 206 | 206 | } |
| 207 | const asks = await page("/"); | |
| 207 | const asks = await page("/asks"); | |
| 208 | 208 | expect(asks).toContain("If nobody acts, it waits; nothing ships."); |
| 209 | 209 | expect(asks).toContain("<b>security</b>"); |
| 210 | 210 | // The long sentence the card used to repeat is gone. |
| @@ -236,7 +236,7 @@ describe("asks that earn their place", () => { | ||
| 236 | 236 | for (const name of ["r4", "r5", "r6"]) |
| 237 | 237 | await greenPull(name, `Work in ${name}`); |
| 238 | 238 | // What needs you is pinned on the home (#634): count its own cards. |
| 239 | const home = await page("/"); | |
| 239 | const home = await page("/asks"); | |
| 240 | 240 | const asks = home.slice(home.indexOf('<section id="needs-you"')); |
| 241 | 241 | const cards = (s: string) => (s.match(/class="card[" ]/g) ?? []).length; |
| 242 | 242 | // Two before the phone's "more", three more inside it before the wide |
| @@ -340,7 +340,7 @@ describe("asks that earn their place", () => { | ||
| 340 | 340 | expect((await mcpAsks()).measure.raised).toBe(6); |
| 341 | 341 | }); |
| 342 | 342 | test("a phone's ask is a full-width row: kind and repo on one line, the decider apart, the rest behind More", async () => { |
| 343 | const home = await page("/"); | |
| 343 | const home = await page("/asks"); | |
| 344 | 344 | const asks = home.slice(home.indexOf('<section id="needs-you"')); |
| 345 | 345 | expect(asks).toContain("ask-card"); |
| 346 | 346 | expect(asks).toContain('<b class="ask-kind">'); |
| @@ -357,7 +357,7 @@ describe("asks that earn their place", () => { | ||
| 357 | 357 | // The security pull went red above; a new green one joins it in a row of two. |
| 358 | 358 | check(security, "ok"); |
| 359 | 359 | await greenPull("security", "Another change here"); |
| 360 | const asks = await page("/"); | |
| 360 | const asks = await page("/asks"); | |
| 361 | 361 | expect(asks).toContain("2 green changes wait for your look"); |
| 362 | 362 | expect(asks).toContain("<b>security</b>: \u201cWiden the board id\u201d"); |
| 363 | 363 | // On a phone the row is its head line, its two asks one tap away; a |
test/asks-waiting-for.test.ts +1 −1
| @@ -150,7 +150,7 @@ describe("the word on a row", () => { | ||
| 150 | 150 | expect(text).toContain("ready to land"); |
| 151 | 151 | expect(text).toContain("waitingFor"); |
| 152 | 152 | |
| 153 | const page = await (await fetch(`${servers.url}/`, { headers: { cookie } })).text(); | |
| 153 | const page = await (await fetch(`${servers.url}/asks`, { headers: { cookie } })).text(); | |
| 154 | 154 | expect(page).toContain('data-waiting="ready to land"'); |
| 155 | 155 | expect(page).toContain('<span class="sr-only">waiting for </span>ready to land'); |
| 156 | 156 | expect(page).toContain("ready to land · on you"); |
test/asks.test.ts +10 −10
| @@ -104,10 +104,10 @@ describe("the asks page", () => { | ||
| 104 | 104 | }); |
| 105 | 105 | |
| 106 | 106 | test("when nothing asks, it says All fine, and so does the header", async () => { |
| 107 | const page = await get(alice, "/"); | |
| 107 | const page = await get(alice, "/asks"); | |
| 108 | 108 | expect(sentence(page)).toBe("All fine"); |
| 109 | 109 | expect(headerCount(page)).toBe(0); |
| 110 | expect(await get(alice, "/")).not.toContain('<section id="needs-you"'); | |
| 110 | expect(await get(alice, "/asks")).not.toContain('<section id="needs-you"'); | |
| 111 | 111 | }); |
| 112 | 112 | |
| 113 | 113 | test("/asks lands on the home's pinned needs-you, and a signed-out reader there gets the door, no asks", async () => { |
| @@ -146,7 +146,7 @@ describe("the asks page", () => { | ||
| 146 | 146 | claimRun(app.db, run.id); |
| 147 | 147 | finishRun(app.db, run.id, { state: "failed", summary: "red" }); |
| 148 | 148 | // Failed but the crew is still trying: that is working, not an ask. |
| 149 | expect(sentence(await get(alice, "/"))).toBe("All fine"); | |
| 149 | expect(sentence(await get(alice, "/asks"))).toBe("All fine"); | |
| 150 | 150 | recordDecision(app.db, { |
| 151 | 151 | kind: "retry", |
| 152 | 152 | repoId: repo.id, |
| @@ -157,13 +157,13 @@ describe("the asks page", () => { | ||
| 157 | 157 | by: "rule", |
| 158 | 158 | ms: 1, |
| 159 | 159 | }); |
| 160 | const page = await get(alice, "/"); | |
| 160 | const page = await get(alice, "/asks"); | |
| 161 | 161 | expect(sentence(page)).toBe("1 thing needs you"); |
| 162 | 162 | expect(page).toContain("Bot did a thing"); |
| 163 | 163 | expect(headerCount(page)).toBe(1); |
| 164 | 164 | // The home counts it in the header's Asks link; the dev dashboard's |
| 165 | 165 | // own "needs you" line went with the dashboard (#625). |
| 166 | const home = await get(alice, "/"); | |
| 166 | const home = await get(alice, "/asks"); | |
| 167 | 167 | expect(headerCount(home)).toBe(1); |
| 168 | 168 | // Bob can read the public repository but cannot write it: not his ask. |
| 169 | 169 | expect(sentence(await get(bob, "/"))).toBe("All fine"); |
| @@ -174,7 +174,7 @@ describe("the asks page", () => { | ||
| 174 | 174 | app.db |
| 175 | 175 | .query("UPDATE run SET created_at = ?1 WHERE state = 'queued'") |
| 176 | 176 | .run(new Date(Date.now() - 3 * 3_600_000).toISOString()); |
| 177 | const admin = await get(alice, "/"); | |
| 177 | const admin = await get(alice, "/asks"); | |
| 178 | 178 | expect(admin).toContain("behind one lane"); |
| 179 | 179 | expect(sentence(admin)).toBe("2 things need you"); |
| 180 | 180 | expect(headerCount(admin)).toBe(2); |
| @@ -224,17 +224,17 @@ describe("the asks page", () => { | ||
| 224 | 224 | ms: 1, |
| 225 | 225 | }); |
| 226 | 226 | const card = `id="ask-stopped:${pull.id}"`; |
| 227 | expect(await get(alice, "/")).toContain(card); | |
| 227 | expect(await get(alice, "/asks")).toContain(card); | |
| 228 | 228 | // The re-run passes: the stop is answered, and the pull is green. |
| 229 | 229 | check("ok"); |
| 230 | 230 | resolveOpen(app.db, pull.id, "retry", "green"); |
| 231 | const green = await get(alice, "/"); | |
| 231 | const green = await get(alice, "/asks"); | |
| 232 | 232 | expect(green).not.toContain(card); |
| 233 | 233 | expect(green).toContain(`id="ask-look:${pull.id}"`); |
| 234 | 234 | // Red again, before anything new is decided: the old stop is spent, and |
| 235 | 235 | // the crew's tries are what the card is counted from. |
| 236 | 236 | check("failed"); |
| 237 | expect(await get(alice, "/")).not.toContain(card); | |
| 237 | expect(await get(alice, "/asks")).not.toContain(card); | |
| 238 | 238 | }); |
| 239 | 239 | |
| 240 | 240 | test("a green change's card says what its tests did", async () => { |
| @@ -309,7 +309,7 @@ describe("the asks page", () => { | ||
| 309 | 309 | expect(card.says).toContain("alice"); |
| 310 | 310 | expect(card.says).toContain("checks.concurrency"); |
| 311 | 311 | expect(ASK_WORDS.setting.options).toEqual(["Keep", "Put back"]); |
| 312 | const page = await get(alice, "/"); | |
| 312 | const page = await get(alice, "/asks"); | |
| 313 | 313 | expect(page).toContain("Keep"); |
| 314 | 314 | expect(page).toContain("Put back"); |
| 315 | 315 | // not for a person who cannot put it back |
test/holds.test.ts +1 −1
| @@ -741,7 +741,7 @@ describe("a hold is set, shown and lifted", () => { | ||
| 741 | 741 | // What needs you, pinned on the home (#634), is the part to read: the |
| 742 | 742 | // feed below it may well mention the change as news. |
| 743 | 743 | const asks = async (cookie: string) => { |
| 744 | const home = await page("/", cookie); | |
| 744 | const home = await page("/asks", cookie); | |
| 745 | 745 | const at = home.indexOf('<section id="needs-you"'); |
| 746 | 746 | return at === -1 ? "" : home.slice(at, home.indexOf("</section>", at)); |
| 747 | 747 | }; |
test/home-kpis.test.ts added +149
| @@ -0,0 +1,149 @@ | ||
| 1 | /** | |
| 2 | * The owner's home (#2665): KPIs read live, never a to-do list; a board | |
| 3 | * panel pinned to it appears under them in order, and unpinning removes it. | |
| 4 | * The asks stay one deliberate step away, on /asks. | |
| 5 | */ | |
| 6 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 7 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 8 | import { tmpdir } from "node:os"; | |
| 9 | import { join } from "node:path"; | |
| 10 | import { createApp } from "../src/app.ts"; | |
| 11 | import { makeBoard, changeBoard } from "../src/actions/boards.ts"; | |
| 12 | import { landingsByHour, medianCheckMs, readKpis } from "../src/core/kpis.ts"; | |
| 13 | import { movePin, pinPanel, pinsOf, unpinPanel } from "../src/core/home_panels.ts"; | |
| 14 | import { createToken } from "../src/core/tokens.ts"; | |
| 15 | import { createUser } from "../src/core/users.ts"; | |
| 16 | import { serve } from "../src/http/server.ts"; | |
| 17 | ||
| 18 | let dir: string; | |
| 19 | let app: ReturnType<typeof createApp>; | |
| 20 | let servers: Awaited<ReturnType<typeof serve>>; | |
| 21 | let admin: { id: string }; | |
| 22 | const tok: Record<string, string> = {}; | |
| 23 | const get = (path: string, who: string) => | |
| 24 | fetch(servers.url + path, { headers: { authorization: `Bearer ${tok[who]}` }, redirect: "manual" }); | |
| 25 | const post = (path: string, who: string, body: Record<string, string>) => | |
| 26 | fetch(servers.url + path, { | |
| 27 | method: "POST", | |
| 28 | headers: { authorization: `Bearer ${tok[who]}`, "content-type": "application/x-www-form-urlencoded" }, | |
| 29 | body: new URLSearchParams(body), | |
| 30 | redirect: "manual", | |
| 31 | }); | |
| 32 | ||
| 33 | beforeAll(async () => { | |
| 34 | dir = await mkdtemp(join(tmpdir(), "forge-home-kpis-")); | |
| 35 | app = createApp({ dataDir: dir, port: 0 }); | |
| 36 | servers = await serve(app); | |
| 37 | const mk = async (username: string, adminIfFirst?: boolean) => { | |
| 38 | const r = await createUser(app.db, { | |
| 39 | origin: "seed", trusted: true, username, email: `${username}@forge.local`, | |
| 40 | password: "a-good-passphrase", ...(adminIfFirst ? { adminIfFirst } : {}), | |
| 41 | }); | |
| 42 | if (!r.ok) throw new Error(r.error); | |
| 43 | return r.value; | |
| 44 | }; | |
| 45 | const alice = await mk("alice", true); | |
| 46 | const bob = await mk("bob"); | |
| 47 | admin = alice; | |
| 48 | tok.admin = createToken(app.db, alice.id, "t", "admin").token; | |
| 49 | tok.bob = createToken(app.db, bob.id, "t", "admin").token; | |
| 50 | const made = await makeBoard(app, alice, "Speed"); | |
| 51 | if (!made.ok) throw new Error(String(made.error)); | |
| 52 | const added = await changeBoard(app, alice, made.value, { | |
| 53 | kind: "add", | |
| 54 | panel: { title: "Runs a day", chart: "bar", query: { source: "runs", aggregate: "count", groupBy: { bucket: "day" } }, w: 1, h: 1 }, | |
| 55 | }); | |
| 56 | if (!added.ok) throw new Error(String(added.error)); | |
| 57 | }); | |
| 58 | ||
| 59 | afterAll(async () => { | |
| 60 | servers.stop(); | |
| 61 | app.close(); | |
| 62 | await rm(dir, { recursive: true, force: true }); | |
| 63 | }); | |
| 64 | ||
| 65 | describe("the owner's home", () => { | |
| 66 | test("shows the six KPIs, each linking to where it comes from, and no asks list", async () => { | |
| 67 | const res = await get("/", "admin"); | |
| 68 | expect(res.status).toBe(200); | |
| 69 | const body = await res.text(); | |
| 70 | for (const k of ["landings", "live", "check", "builders", "spend", "backup"]) | |
| 71 | expect(body).toMatch(new RegExp(`id="kpi-${k}" href="/[^"]+"`)); | |
| 72 | expect(body).not.toContain('id="needs-you"'); | |
| 73 | expect(body).not.toContain('id="live-on-you"'); | |
| 74 | expect(body).not.toContain("asks-sentence"); | |
| 75 | }); | |
| 76 | ||
| 77 | test("the asks stay reachable on /asks, and a receipt on / goes there", async () => { | |
| 78 | const asks = await get("/asks", "admin"); | |
| 79 | expect(asks.status).toBe(200); | |
| 80 | expect(await asks.text()).toContain("asks-sentence"); | |
| 81 | const receipt = await get("/?op=x", "admin"); | |
| 82 | expect(receipt.status).toBe(303); | |
| 83 | expect(receipt.headers.get("location")).toBe("/asks?op=x"); | |
| 84 | }); | |
| 85 | ||
| 86 | test("another person's home keeps its asks list region", async () => { | |
| 87 | expect(await (await get("/", "bob")).text()).toContain('id="live-on-you"'); | |
| 88 | }); | |
| 89 | ||
| 90 | test("a pinned panel appears on home, in order, and unpinning removes it", async () => { | |
| 91 | const board = await (await get("/boards/speed", "admin")).text(); | |
| 92 | expect(board).toContain("Pin to home"); | |
| 93 | const pinned = await post("/home/panels", "admin", { slug: "speed", index: "0", action: "pin", back: "/boards/speed" }); | |
| 94 | expect(pinned.status).toBe(303); | |
| 95 | expect(pinned.headers.get("location")).toStartWith("/boards/speed"); | |
| 96 | expect(await (await get("/boards/speed", "admin")).text()).toContain("Unpin from home"); | |
| 97 | const home = await (await get("/", "admin")).text(); | |
| 98 | expect(home).toContain("Runs a day"); | |
| 99 | expect(home).toContain('aria-label="Pinned panels"'); | |
| 100 | await post("/home/panels", "admin", { slug: "speed", index: "0", action: "unpin" }); | |
| 101 | expect(await (await get("/", "admin")).text()).not.toContain("Runs a day"); | |
| 102 | }); | |
| 103 | ||
| 104 | test("pinning is the owner's alone, same-origin only, and names a real panel", async () => { | |
| 105 | expect((await post("/home/panels", "bob", { slug: "speed", index: "0", action: "pin" })).status).toBe(404); | |
| 106 | expect((await post("/home/panels", "admin", { slug: "speed", index: "7", action: "pin" })).status).toBe(404); | |
| 107 | expect((await post("/home/panels", "admin", { slug: "../x", index: "0", action: "pin" })).status).toBe(404); | |
| 108 | const cross = await fetch(servers.url + "/home/panels", { | |
| 109 | method: "POST", | |
| 110 | headers: { authorization: `Bearer ${tok.admin}`, origin: "https://evil.example", "content-type": "application/x-www-form-urlencoded" }, | |
| 111 | body: new URLSearchParams({ slug: "speed", index: "0", action: "pin" }), | |
| 112 | }); | |
| 113 | expect(cross.status).toBe(403); | |
| 114 | expect(pinsOf(app.db, admin.id)).toEqual([]); | |
| 115 | const off = await post("/home/panels", "admin", { slug: "speed", index: "0", action: "pin", back: "//evil.example" }); | |
| 116 | expect(off.headers.get("location")).toStartWith("/"); | |
| 117 | expect(off.headers.get("location")).not.toStartWith("//"); | |
| 118 | unpinPanel(app.db, admin.id, { slug: "speed", index: 0 }); | |
| 119 | }); | |
| 120 | ||
| 121 | test("pins keep the owner's order and a pin that does not fit is refused", () => { | |
| 122 | expect(pinPanel(app.db, admin.id, { slug: "a", index: 0 })).toBe(true); | |
| 123 | expect(pinPanel(app.db, admin.id, { slug: "b", index: 1 })).toBe(true); | |
| 124 | movePin(app.db, admin.id, { slug: "b", index: 1 }, -1); | |
| 125 | expect(pinsOf(app.db, admin.id).map((p) => p.slug)).toEqual(["b", "a"]); | |
| 126 | const fits = ["x", "y", "z", "w", "v"].map((c) => pinPanel(app.db, admin.id, { slug: c.repeat(40), index: 0 })); | |
| 127 | expect(fits).toContain(false); | |
| 128 | expect(fits[0]).toBe(true); | |
| 129 | }); | |
| 130 | }); | |
| 131 | ||
| 132 | describe("the KPIs", () => { | |
| 133 | test("landings count merged pulls by hour; the median check is of finished checks", () => { | |
| 134 | const now = Date.parse("2026-10-19T12:30:00Z"); | |
| 135 | app.db.run("INSERT INTO repo (id, owner_id, name) VALUES ('rk', ?, 'k')", [admin.id]); | |
| 136 | const run = app.db.prepare( | |
| 137 | "INSERT INTO run (id, repo_id, kind, state, created_at, started_at, finished_at) VALUES (?1, 'rk', 'check', 'ok', ?2, ?2, ?3)", | |
| 138 | ); | |
| 139 | run.run("c1", "2026-10-19T11:00:00.000Z", "2026-10-19T11:00:10.000Z"); | |
| 140 | run.run("c2", "2026-10-19T11:10:00.000Z", "2026-10-19T11:10:30.000Z"); | |
| 141 | run.run("c3", "2026-10-19T11:20:00.000Z", "2026-10-19T11:21:00.000Z"); | |
| 142 | expect(medianCheckMs(app.db, now)).toBe(30_000); | |
| 143 | expect(landingsByHour(app.db, now)).toHaveLength(24); | |
| 144 | const kpis = readKpis(app.db, dir, admin.id, "2026-10-19T12:00:00.000Z", now); | |
| 145 | expect(kpis.find((k) => k.key === "check")?.value).toBe("30s"); | |
| 146 | expect(kpis.find((k) => k.key === "backup")?.value).toBe("none"); | |
| 147 | expect(kpis.find((k) => k.key === "live")?.note).toBe("live 30 min ago"); | |
| 148 | }); | |
| 149 | }); |
test/review-wait.test.ts +1 −1
| @@ -34,7 +34,7 @@ describe("a green agent pull and its reviewer", () => { | ||
| 34 | 34 | |
| 35 | 35 | const home = async (): Promise<string> => |
| 36 | 36 | ( |
| 37 | await (await fetch(`${servers.url}/`, { headers: { cookie } })).text() | |
| 37 | await (await fetch(`${servers.url}/asks`, { headers: { cookie } })).text() | |
| 38 | 38 | ).replace(/\s+/g, " "); |
| 39 | 39 | const wordCtx = (): WordCtx => ({ db: app.db }) as unknown as WordCtx; |
| 40 | 40 |
test/studio-door.test.ts +6 −2
| @@ -613,7 +613,10 @@ describe("the studio home keeps itself current", () => { | ||
| 613 | 613 | expect(res.headers.get("referrer-policy")).toBe("same-origin"); |
| 614 | 614 | const home = await res.text(); |
| 615 | 615 | expect(home).toMatch(/id="live-apps"\s*\n?\s*data-live="/); |
| 616 | expect(home).toMatch(/id="live-on-you"\s*\n?\s*data-live="/); | |
| 616 | // The owner's home lists nothing that waits on them; /asks does. | |
| 617 | expect(home).not.toContain('id="live-on-you"'); | |
| 618 | const asks = await (await fetch(`${base}/asks`, { headers: { cookie: `${cookie}; forge_mode=studio` } })).text(); | |
| 619 | expect(asks).toMatch(/id="live-on-you"\s*\n?\s*data-live="/); | |
| 617 | 620 | expect(home).toContain("new EventSource('/events')"); |
| 618 | 621 | expect(home).toContain("Write the README"); |
| 619 | 622 | }); |
| @@ -628,7 +631,8 @@ describe("the studio home keeps itself current", () => { | ||
| 628 | 631 | test("each region on the home has an address of its own, answering with that region alone and 304 when it has not changed", async () => { |
| 629 | 632 | const page = await (await get()).text(); |
| 630 | 633 | expect(page).toContain('data-live-src="/live/apps"'); |
| 631 | expect(page).toContain('data-live-src="/live/on-you"'); | |
| 634 | const asks = await (await fetch(`${base}/asks`, { headers: { cookie: `${cookie}; forge_mode=studio` } })).text(); | |
| 635 | expect(asks).toContain('data-live-src="/live/on-you"'); | |
| 632 | 636 | |
| 633 | 637 | const headers = { cookie: `${cookie}; forge_mode=studio` }; |
| 634 | 638 | const apps = await fetch(`${base}/live/apps`, { headers }); |
test/web-apps.test.ts +1 −1
| @@ -824,7 +824,7 @@ describe("apps, runs and the crew on the web", () => { | ||
| 824 | 824 | form: { assignee: "alice" }, |
| 825 | 825 | }); |
| 826 | 826 | expect(assigned.status).toBe(303); |
| 827 | const dash = await bodyOf(alice, "/"); | |
| 827 | const dash = await bodyOf(alice, "/asks"); | |
| 828 | 828 | expect(dash).toContain('<section id="needs-you"'); |
| 829 | 829 | expect(dash).toMatch(/<h2 id="asks-sentence">\d+ things? needs? you<\/h2>/); |
| 830 | 830 | expect(dash).toContain("Say hello"); |
new above
offline