Public: anyone can read this; the crew can change it.
Home feed you can catch up from in 15 seconds: a "since you were here" digest, honest counts, no dead buttons; validated by a cold-read agent each iteration #5736
scout/forge:scout/5735-home-feed-you-can-catch-up-from-in-15-se → main 3 commits fork 5 threads · 5 unresolved
17 files
changed +481
−44
README.md +16 −1
| @@ -346,6 +346,18 @@ or the last change landed in the past 7 days ("Last change: …, 3 days ago"); | ||
| 346 | 346 | a quiet app says nothing more. The terminal's first screen opens with the same |
| 347 | 347 | lines, from the same queries (`src/core/client-apps.ts`). |
| 348 | 348 | |
| 349 | Above the feed, home has a **Last 24 h** digest: at most three lines, one per | |
| 350 | repository, the biggest change first (`2 landed, 1 released`), each linked to | |
| 351 | its evidence. It is built from the posts the timeline already read | |
| 352 | (`src/feed/digest.ts`), over a fixed 24 hours, because the forge keeps no | |
| 353 | last-seen time. The terminal's home shows the same lines above its figures. | |
| 354 | ||
| 355 | Asks waiting over 30 days are counted apart as `N stale, archive?` and | |
| 356 | collapsed on the asks page, where Archive leads to the bulk-dismiss preview. | |
| 357 | The waiting count on home is the number of rows the asks page lists, the | |
| 358 | forge's own needs included. A feed chip with nothing to filter among the | |
| 359 | loaded posts is not drawn; one you switched off stays, so it can come back. | |
| 360 | ||
| 349 | 361 | Home shows nine figures first, from `src/flow/kpis.ts`: shipped per hour (with |
| 350 | 362 | a 24 h sparkline), the live version and since when, the median check time, the crew builders |
| 351 | 363 | running of their slots, and the crew's spend today of the forge's daily |
| @@ -353,7 +365,10 @@ ceiling (`FORGE_CREW_CEILING_USD`; without one, the spend alone and | ||
| 353 | 365 | `no ceiling`), and the age of the last off-box backup (the newer of the |
| 354 | 366 | mirror's newest snapshot, `mirror/state.json`, and the newest that landed in |
| 355 | 367 | a destination that is a bucket, `snapshot/state.json`; `src/snapshot/off_box.ts`; `3 h ago`, the exact time in its title), linking to |
| 356 | `/settings/backups`. The spend tile links to `/settings/crew`, where the meter is. | |
| 368 | `/settings/backups`. The spend tile links to `/settings/crew`, where the meter is. Once spend | |
| 369 | passes the forge's ceiling the tile turns attention-toned and says | |
| 370 | `ceiling hit 14:20Z, builders idle`; an account's own ceiling stops only | |
| 371 | that account's repositories, so it is never shown as the forge's. | |
| 357 | 372 | The backup tile past 24 hours, or with none (`never`), takes the card's existing |
| 358 | 373 | `data-tone="attn"` and says overdue in its label. |
| 359 | 374 | The last three (`src/flow/reach.ts`, the `reach` board source's rows) are |
src/feed/digest.ts added +78
| @@ -0,0 +1,78 @@ | ||
| 1 | /** | |
| 2 | * The feed's top: what happened since the viewer was last here, in at most | |
| 3 | * three lines, one per repository, the biggest change first. Built from the | |
| 4 | * posts already read for the timeline, so every line links to its evidence | |
| 5 | * and none says what the posts below do not. | |
| 6 | */ | |
| 7 | ||
| 8 | import type { FeedItem } from "./rank.ts"; | |
| 9 | ||
| 10 | /** How many posts the home and the terminal read for the timeline and the digest. */ | |
| 11 | export const FEED_FIRST_PAGE = 20; | |
| 12 | export const DIGEST_LINES = 3; | |
| 13 | export const DIGEST_WINDOW_MS = 24 * 3_600_000; | |
| 14 | ||
| 15 | /** What happened, ordered by how much it matters; the weight ranks a repository. */ | |
| 16 | const OUTCOMES = [ | |
| 17 | { word: "failed", weight: 4 }, | |
| 18 | { word: "landed", weight: 3 }, | |
| 19 | { word: "released", weight: 3 }, | |
| 20 | { word: "decided", weight: 2 }, | |
| 21 | { word: "opened", weight: 1 }, | |
| 22 | ] as const; | |
| 23 | type Outcome = (typeof OUTCOMES)[number]["word"]; | |
| 24 | ||
| 25 | export interface DigestLine { | |
| 26 | /** `owner/name`. */ | |
| 27 | readonly app: string; | |
| 28 | /** `2 landed, 1 released`. */ | |
| 29 | readonly text: string; | |
| 30 | /** The heaviest post in it: the evidence. */ | |
| 31 | readonly href: string; | |
| 32 | readonly weight: number; | |
| 33 | } | |
| 34 | ||
| 35 | function outcomeOf(item: FeedItem): Outcome | undefined { | |
| 36 | switch (item.kind) { | |
| 37 | case "run": | |
| 38 | return /\bfailed\b/.test(item.what) ? "failed" : undefined; | |
| 39 | case "pull": | |
| 40 | return item.what.startsWith("merged") ? "landed" : item.what.startsWith("opened") ? "opened" : undefined; | |
| 41 | case "release": | |
| 42 | return "released"; | |
| 43 | case "decision": | |
| 44 | case "choose": | |
| 45 | return "decided"; | |
| 46 | default: | |
| 47 | return undefined; | |
| 48 | } | |
| 49 | } | |
| 50 | ||
| 51 | const weightOf = (word: Outcome): number => OUTCOMES.find((o) => o.word === word)!.weight; | |
| 52 | ||
| 53 | /** The digest of posts newer than the window, biggest repository first. */ | |
| 54 | export function digestOf(items: readonly FeedItem[], now: Date, windowMs = DIGEST_WINDOW_MS): DigestLine[] { | |
| 55 | const since = now.getTime() - windowMs; | |
| 56 | const groups = new Map<string, { counts: Map<Outcome, number>; best: { weight: number; href: string } }>(); | |
| 57 | for (const item of items) { | |
| 58 | const word = outcomeOf(item); | |
| 59 | if (word === undefined || Date.parse(item.at) < since) continue; | |
| 60 | const g = groups.get(item.app) ?? { counts: new Map(), best: { weight: 0, href: item.link } }; | |
| 61 | g.counts.set(word, (g.counts.get(word) ?? 0) + 1); | |
| 62 | if (weightOf(word) > g.best.weight) g.best = { weight: weightOf(word), href: item.link }; | |
| 63 | groups.set(item.app, g); | |
| 64 | } | |
| 65 | return [...groups.entries()] | |
| 66 | .map(([app, g]): DigestLine => { | |
| 67 | const parts = OUTCOMES.filter((o) => g.counts.has(o.word)).map((o) => `${g.counts.get(o.word)} ${o.word}`); | |
| 68 | const weight = OUTCOMES.reduce((n, o) => n + (g.counts.get(o.word) ?? 0) * o.weight, 0); | |
| 69 | return { app, text: parts.join(", "), href: g.best.href, weight }; | |
| 70 | }) | |
| 71 | .sort((a, b) => b.weight - a.weight || a.app.localeCompare(b.app)) | |
| 72 | .slice(0, DIGEST_LINES); | |
| 73 | } | |
| 74 | ||
| 75 | /** The same lines for the terminal: `Last 24 h` first, then one line per repository. */ | |
| 76 | export function digestWords(lines: readonly DigestLine[]): string[] { | |
| 77 | return lines.length === 0 ? [] : ["Last 24 h", ...lines.map((l) => ` ${l.app}: ${l.text}`)]; | |
| 78 | } |
src/flow/ceiling.ts added +28
| @@ -0,0 +1,28 @@ | ||
| 1 | /** | |
| 2 | * Why builders are idle, for the figures. Only the forge-wide daily ceiling | |
| 3 | * (FORGE_CREW_CEILING_USD) stops every builder; an account's own ceiling | |
| 4 | * (`core/account_ceiling.ts`) stops only that account's repositories, so it | |
| 5 | * is never read as the forge's. Null: none set. | |
| 6 | */ | |
| 7 | ||
| 8 | import type { Database } from "bun:sqlite"; | |
| 9 | import { dayStart } from "../core/account_ceiling.ts"; | |
| 10 | ||
| 11 | /** | |
| 12 | * When today's (UTC) agent spend crossed the ceiling: the creation time of the | |
| 13 | * run that took the running total over it. Null while under, or with none. | |
| 14 | */ | |
| 15 | export function ceilingReachedAt(db: Database, ceilingUsd: number | null, now: Date): string | null { | |
| 16 | if (ceilingUsd === null) return null; | |
| 17 | const runs = db | |
| 18 | .query<{ at: string; cost: number | null }, [string]>( | |
| 19 | "SELECT created_at AS at, cost_usd AS cost FROM run WHERE kind = 'agent' AND created_at >= ?1 ORDER BY created_at", | |
| 20 | ) | |
| 21 | .all(dayStart(now)); | |
| 22 | let total = 0; | |
| 23 | for (const r of runs) { | |
| 24 | total += r.cost ?? 0; | |
| 25 | if (total >= ceilingUsd) return r.at; | |
| 26 | } | |
| 27 | return null; | |
| 28 | } |
src/flow/kpi_words.ts +16 −5
| @@ -45,6 +45,13 @@ export function spendValue(s: Kpis["spend"]): string { | ||
| 45 | 45 | return s.ceilingUsd === null ? whole(s.todayUsd) : `${whole(s.todayUsd)} of ${whole(s.ceilingUsd)}`; |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | /** Under the spend: the ceiling, or why the builders sit idle once it is reached. */ | |
| 49 | export function spendNote(s: Kpis["spend"]): string { | |
| 50 | if (s.ceilingUsd === null) return "no ceiling"; | |
| 51 | if (s.reachedAt) return `ceiling hit ${s.reachedAt.slice(11, 16)}Z, builders idle`; | |
| 52 | return "of the daily ceiling"; | |
| 53 | } | |
| 54 | ||
| 48 | 55 | /** The same figure to the cent, for the title. */ |
| 49 | 56 | export function spendFull(s: Kpis["spend"]): string { |
| 50 | 57 | return s.ceilingUsd === null ? cents(s.todayUsd) : `${cents(s.todayUsd)} of ${cents(s.ceilingUsd)}`; |
| @@ -99,13 +106,17 @@ export function reactNote(r: Reach): string { | ||
| 99 | 106 | return r.inpP75 === null ? "no taps measured yet" : `reacts in ${speedWords(r.inpP75)}`; |
| 100 | 107 | } |
| 101 | 108 | |
| 109 | /** Asks older than this are stale: collapsed, not counted as urgent. */ | |
| 110 | export const STALE_DAYS = 30; | |
| 111 | ||
| 102 | 112 | /** Home's one line over /review: `3 waiting on you, oldest 50 h`; null at zero, so the line is absent. */ |
| 103 | export function waitingWords(count: number, oldestAt: string | null, now: Date): string | null { | |
| 104 | if (count <= 0) return null; | |
| 113 | export function waitingWords(count: number, oldestAt: string | null, now: Date, stale = 0): string | null { | |
| 114 | const tail = stale > 0 ? `${count > 0 ? ", " : ""}${stale} stale, archive?` : ""; | |
| 115 | if (count <= 0) return stale > 0 ? tail : null; | |
| 105 | 116 | const t = oldestAt === null ? NaN : Date.parse(oldestAt); |
| 106 | if (Number.isNaN(t)) return `${count} waiting on you`; | |
| 117 | if (Number.isNaN(t)) return `${count} waiting on you${tail}`; | |
| 107 | 118 | const h = Math.max(0, Math.floor((now.getTime() - t) / 3_600_000)); |
| 108 | return `${count} waiting on you, oldest ${h < 1 ? "under 1" : h} h`; | |
| 119 | return `${count} waiting on you, oldest ${h < 1 ? "under 1" : h} h${tail}`; | |
| 109 | 120 | } |
| 110 | 121 | |
| 111 | 122 | /** |
| @@ -118,7 +129,7 @@ export function kpiLines(k: Kpis, live: { sha: string; since: string } | null, n | ||
| 118 | 129 | `Live version ${live === null ? "— nothing live yet" : `${live.sha.slice(0, 7)}, live ${live.since}`}`, |
| 119 | 130 | `Median check time ${checkTime(k.medianCheckMs)}`, |
| 120 | 131 | `Builders running ${buildersValue(k.builders)}${k.builders.slots === 0 ? ", no slots set" : ""}`, |
| 121 | `Crew spend today ${spendValue(k.spend)}${k.spend.ceilingUsd === null ? ", no ceiling" : ""}`, | |
| 132 | `Crew spend today ${spendValue(k.spend)}${k.spend.ceilingUsd === null ? ", no ceiling" : k.spend.reachedAt ? `, ${spendNote(k.spend)}` : ""}`, | |
| 122 | 133 | `Last off-box backup ${backupAge(k.backupAt, now)}${backupOverdue(k.backupAt, now) ? ", overdue" : ""}`, |
| 123 | 134 | `Visitors ${visitorsValue(k.reach)}, ${visitorsNote(k.reach)} ${trendText(k.reach.visitorDays)} 30 days`, |
| 124 | 135 | `Accounts ${usersValue(k.reach)} signed in today`, |
src/flow/kpis.ts +3 −2
| @@ -15,6 +15,7 @@ | ||
| 15 | 15 | |
| 16 | 16 | import type { Database } from "bun:sqlite"; |
| 17 | 17 | import { spentTodayEverywhere } from "../crew/autonomy.ts"; |
| 18 | import { ceilingReachedAt } from "./ceiling.ts"; | |
| 18 | 19 | import { lastOffBox } from "../snapshot/off_box.ts"; |
| 19 | 20 | import { readReach, type Reach } from "./reach.ts"; |
| 20 | 21 | import { HOURS, median } from "./throughput.ts"; |
| @@ -33,7 +34,7 @@ export interface Kpis { | ||
| 33 | 34 | /** Crew builders running now, of the slots the autonomous repositories are set to. */ |
| 34 | 35 | readonly builders: { readonly running: number; readonly slots: number }; |
| 35 | 36 | /** What the crew's runs cost since UTC midnight, and the forge's daily ceiling (null: none set). */ |
| 36 | readonly spend: { readonly todayUsd: number; readonly ceilingUsd: number | null }; | |
| 37 | readonly spend: { readonly todayUsd: number; readonly ceilingUsd: number | null; readonly reachedAt: string | null }; | |
| 37 | 38 | /** When a snapshot was last known off the machine (a bucket destination or the mirror, `off_box.ts`); null when never. */ |
| 38 | 39 | readonly backupAt: string | null; |
| 39 | 40 | /** Accounts, visitors and page speed (`reach.ts`). */ |
| @@ -100,7 +101,7 @@ export function readKpis( | ||
| 100 | 101 | backupAt, |
| 101 | 102 | builders, |
| 102 | 103 | reach: readReach(db, now), |
| 103 | spend: { todayUsd, ceilingUsd: forge.ceilingUsd }, | |
| 104 | spend: { todayUsd, ceilingUsd: forge.ceilingUsd, reachedAt: forge.ceilingUsd !== null && todayUsd >= forge.ceilingUsd ? ceilingReachedAt(db, forge.ceilingUsd, now) : null }, | |
| 104 | 105 | landedHours, |
| 105 | 106 | landed: landedHours.reduce((a, b) => a + b, 0), |
| 106 | 107 | live: live ?? null, |
src/tui/screens/dashboard.ts +13
| @@ -88,6 +88,8 @@ import { | ||
| 88 | 88 | plural, |
| 89 | 89 | linkScreen, |
| 90 | 90 | } from "./common.ts"; |
| 91 | import { digestOf, digestWords, FEED_FIRST_PAGE } from "../../feed/digest.ts"; | |
| 92 | import { readFeed } from "../../feed/feed.ts"; | |
| 91 | 93 | import { readKpis } from "../../flow/kpis.ts"; |
| 92 | 94 | import { kpiLines } from "../../flow/kpi_words.ts"; |
| 93 | 95 | import { BOOTED } from "../../release/gate.ts"; |
| @@ -179,6 +181,8 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 179 | 181 | let decider: string | null = null; |
| 180 | 182 | /** Home's three figures, as the web's row says them; empty unless an admin looks (they count every repository). */ |
| 181 | 183 | let figures: string[] = []; |
| 184 | /** The web feed's top: what happened in the last 24 h, up to three lines (`feed/digest.ts`). */ | |
| 185 | let digest: string[] = []; | |
| 182 | 186 | /** The panels this admin pinned to the web home, by title and board, in their order. */ |
| 183 | 187 | let panelLines: string[] = []; |
| 184 | 188 | const filter = new Filter(); |
| @@ -195,6 +199,7 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 195 | 199 | if (!f.user || (await nextStepsFor(f.app, f.user)) === undefined) return; |
| 196 | 200 | // A client's home never carries the forge-wide figures, on either door. |
| 197 | 201 | figures = []; |
| 202 | digest = []; | |
| 198 | 203 | const apps = await clientAppRows(f.app, f.user); |
| 199 | 204 | clientRepoIds = new Set(apps.map((a) => a.repo.id)); |
| 200 | 205 | clientLive = new Map(apps.flatMap((a) => (a.live === undefined ? [] : [[a.repo.id, a.live] as const]))); |
| @@ -253,6 +258,7 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 253 | 258 | waits = ownerWaits(f.db, all.filter((r) => facts.has(r.id))).map(waitLine); |
| 254 | 259 | lane = forgeLane(f.app, f.user); |
| 255 | 260 | decider = deciderLine(f.app, f.user); |
| 261 | digest = f.user === undefined ? [] : digestWords(digestOf(readFeed(f.db, f.user, { limit: FEED_FIRST_PAGE, withoutAsks: true }).items, now)); | |
| 256 | 262 | const commit = running().commit; |
| 257 | 263 | figures = |
| 258 | 264 | f.user?.isAdmin !== true |
| @@ -802,6 +808,13 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 802 | 808 | ); |
| 803 | 809 | body = rest!; |
| 804 | 810 | } |
| 811 | if (digest.length > 0) { | |
| 812 | const [strip, rest] = split(body, "v", [len(digest.length), fill(1)]); | |
| 813 | digest.forEach((line, i) => | |
| 814 | s.text(strip!.x, strip!.y + i, truncate(line, strip!.w), style(c.fg, c.bg), strip!.x + strip!.w), | |
| 815 | ); | |
| 816 | body = rest!; | |
| 817 | } | |
| 805 | 818 | // A short terminal drops the last figures before it drops the list. |
| 806 | 819 | const shown = figures.slice(0, Math.max(0, body.h - FIGURES_ROOM)); |
| 807 | 820 | if (shown.length > 0) { |
src/web/studio/asks.ts +15 −2
| @@ -19,6 +19,7 @@ import { lastPersonAction, recommendationsFor, waitWords, WAIT_LIMIT_MS, type Re | ||
| 19 | 19 | import { getHold, holdsFor } from "../../core/holds.ts"; |
| 20 | 20 | import { issueTitles, proposalsFor, type Proposal } from "../../core/proposals.ts"; |
| 21 | 21 | import { chipsOf, type Chips } from "../../core/feed_chips.ts"; |
| 22 | import { STALE_DAYS } from "../../flow/kpi_words.ts"; | |
| 22 | 23 | import { chipHides } from "../../feed/chips.ts"; |
| 23 | 24 | import { askDismissals, mutedRepos } from "../../core/interactions.ts"; |
| 24 | 25 | import { askMeasure, syncAskLedger, type AskEnd } from "../../core/ask_ledger.ts"; |
| @@ -138,6 +139,8 @@ export interface Decision { | ||
| 138 | 139 | readonly consequence: Consequence; |
| 139 | 140 | /** What it waits for, and on whom (`core/waiting_for.ts`). */ |
| 140 | 141 | readonly waiting: WaitingFor; |
| 142 | /** When it began to ask; past 30 days it is stale. */ | |
| 143 | readonly since: string; | |
| 141 | 144 | readonly why?: string | undefined; |
| 142 | 145 | readonly recommendation?: Recommendation | undefined; |
| 143 | 146 | } |
| @@ -1120,7 +1123,7 @@ export function decisionsFor( | ||
| 1120 | 1123 | look && lookUrl(repoBase(repo), look) |
| 1121 | 1124 | ); |
| 1122 | 1125 | }; |
| 1123 | const worded = (c: Scored): Omit<Decision, "consequence" | "waiting"> => { | |
| 1126 | const worded = (c: Scored): Omit<Decision, "consequence" | "waiting" | "since"> => { | |
| 1124 | 1127 | if (c.kind === "assigned") { |
| 1125 | 1128 | const thing = c.pull ?? c.issue!; |
| 1126 | 1129 | return { |
| @@ -1253,6 +1256,7 @@ export function decisionsFor( | ||
| 1253 | 1256 | preview: previewOf(c), |
| 1254 | 1257 | consequence: c.consequence, |
| 1255 | 1258 | waiting: c.waiting, |
| 1259 | since: c.since, | |
| 1256 | 1260 | })); |
| 1257 | 1261 | } |
| 1258 | 1262 | /** The id of the form a row's own button submits (see `decisionForm`). */ |
| @@ -1394,6 +1398,15 @@ export function forgeNeedsFor(ctx: Ctx, user: User | undefined): Degraded[] { | ||
| 1394 | 1398 | return forgeVitals(ctx.app).degraded; |
| 1395 | 1399 | } |
| 1396 | 1400 | |
| 1401 | /** Asks that have waited past `STALE_DAYS` are stale: kept apart, never counted as urgent. */ | |
| 1402 | export function splitStale<T extends { since: string }>(asks: readonly T[], now: Date = new Date()): { fresh: T[]; stale: T[] } { | |
| 1403 | const cut = now.getTime() - STALE_DAYS * 86_400_000; | |
| 1404 | const fresh: T[] = []; | |
| 1405 | const stale: T[] = []; | |
| 1406 | for (const a of asks) (Date.parse(a.since) < cut ? stale : fresh).push(a); | |
| 1407 | return { fresh, stale }; | |
| 1408 | } | |
| 1409 | ||
| 1397 | 1410 | /** |
| 1398 | 1411 | * How many things ask the viewer: the one number the studio header and the |
| 1399 | 1412 | * asks page both show. It counts the rows the cards are made into |
| @@ -1404,7 +1417,7 @@ export function askCountFor(ctx: Ctx, user: User | undefined): number { | ||
| 1404 | 1417 | if (!user) return 0; |
| 1405 | 1418 | const repos = listReposVisibleTo(ctx.app.db, user, { limit: 200, withoutArchived: true }); |
| 1406 | 1419 | return ( |
| 1407 | askRows(waitingOn(ctx.app.db, user, repos)).length + | |
| 1420 | askRows(splitStale(waitingOn(ctx.app.db, user, repos)).fresh).length + | |
| 1408 | 1421 | forgeNeedsFor(ctx, user).length |
| 1409 | 1422 | ); |
| 1410 | 1423 | } |
src/web/studio/asks_page.ts +19 −2
| @@ -46,6 +46,7 @@ import { btn, card, icon, row } from "../ui.ts"; | ||
| 46 | 46 | import { |
| 47 | 47 | askAnchor, |
| 48 | 48 | askRows, |
| 49 | splitStale, | |
| 49 | 50 | askSentence, |
| 50 | 51 | ASK_WORDS, |
| 51 | 52 | ROW_PLURAL, |
| @@ -392,7 +393,9 @@ export function needsYouSection( | ||
| 392 | 393 | // Callers that build the section outside a request have none to time against. |
| 393 | 394 | const decisions = ctx.request instanceof Request ? timePhase(ctx.request, "asks", read) : read(); |
| 394 | 395 | const needs = forgeNeedsFor(ctx, user); |
| 395 | const rows = askRows(decisions); | |
| 396 | const split = splitStale(decisions); | |
| 397 | const rows = askRows(split.fresh); | |
| 398 | const staleRows = askRows(split.stale); | |
| 396 | 399 | const silenced = silencedRepos(ctx.app.db, user); |
| 397 | 400 | const silencedNote = |
| 398 | 401 | silenced.length === 0 |
| @@ -430,7 +433,7 @@ export function needsYouSection( | ||
| 430 | 433 | <span class="muted small">kept for a day</span> |
| 431 | 434 | </form>`; |
| 432 | 435 | const count = rows.length + needs.length; |
| 433 | if (count === 0 && top === undefined) | |
| 436 | if (count === 0 && staleRows.length === 0 && top === undefined) | |
| 434 | 437 | return { |
| 435 | 438 | body: html`<h2 id="asks-sentence" class="sr-only">${askSentence(0)}</h2>${silencedNote}${asideNote}${undo}`, |
| 436 | 439 | scriptJs: "", |
| @@ -483,6 +486,20 @@ export function needsYouSection( | ||
| 483 | 486 | ${reasonInput(top?.reason)} ${btn("Preview", { size: "sm" })} |
| 484 | 487 | <span class="muted small">on the selected asks</span> |
| 485 | 488 | </form>`} |
| 489 | ${staleRows.length === 0 | |
| 490 | ? null | |
| 491 | : html`<details id="asks-stale"> | |
| 492 | <summary>${staleRows.length} stale, archive?</summary> | |
| 493 | <div class="stack mt"> | |
| 494 | <form method="post" action="/asks/bulk" class="bar"> | |
| 495 | <input type="hidden" name="action" value="dismiss" /> | |
| 496 | ${split.stale.map((d) => html`<input type="hidden" name="item" value="${d.id}" />`)} | |
| 497 | ${btn(`Archive ${staleRows.length}`, { size: "sm" })} | |
| 498 | <span class="muted small">waiting over 30 days; you see a preview first</span> | |
| 499 | </form> | |
| 500 | ${staleRows.map((r) => mutableRow(ctx, r, picked))} | |
| 501 | </div> | |
| 502 | </details>`} | |
| 486 | 503 | ${silencedNote} ${asideNote} ${undo} |
| 487 | 504 | ${decisions.map((d) => decisionForm(d, ctx.url.pathname))} |
| 488 | 505 | </section>`; |
src/web/studio/change.ts +1
| @@ -480,6 +480,7 @@ async function changeConversation( | ||
| 480 | 480 | : "This app does not wait on the check to ship. Look at the preview, then ship it or say what is off.", |
| 481 | 481 | short: word === "look" ? "the check is green" : "ready to ship", |
| 482 | 482 | consequence: KIND_TIER.look, |
| 483 | since: pull.createdAt, | |
| 483 | 484 | waiting: waitingFor({ |
| 484 | 485 | kind: "look", |
| 485 | 486 | conflicts: conflicted ? 1 : 0, |
src/web/studio/feed.ts +23 −2
| @@ -15,6 +15,8 @@ import type { Ctx } from "../../http/context.ts"; | ||
| 15 | 15 | import { notePhase, takeSessionTime, timePhase } from "../../core/route_timing.ts"; |
| 16 | 16 | import { placementsOf, type Placement } from "../../core/placements.ts"; |
| 17 | 17 | import { recentThoughts, type Thought } from "../../core/thoughts.ts"; |
| 18 | import { chipOfKind } from "../../feed/chips.ts"; | |
| 19 | import { digestOf, FEED_FIRST_PAGE } from "../../feed/digest.ts"; | |
| 18 | 20 | import { readFeed } from "../../feed/feed.ts"; |
| 19 | 21 | import type { FeedItem } from "../../feed/rank.ts"; |
| 20 | 22 | import { html, type Html } from "../html.ts"; |
| @@ -27,7 +29,6 @@ import { writableAppsOf } from "./asks.ts"; | ||
| 27 | 29 | export const FEED_LIVE = |
| 28 | 30 | "run.finished,issue.opened,issue.commented,pull.commented,pull.opened,pull.merged,pull.reviewed,pull.closed,look.taken,app.serving,issue.blocked,issue.unblocked,issue.closed,decision.*,thought.received,thought.placed"; |
| 29 | 31 | |
| 30 | export const FEED_FIRST_PAGE = 20; | |
| 31 | 32 | |
| 32 | 33 | const RUN_LINK = /^\/[^/]+\/[^/]+\/runs\/[A-Za-z0-9_-]+$/; |
| 33 | 34 | |
| @@ -233,11 +234,30 @@ function chipsBar(user: User, ctx: Ctx, items: readonly FeedItem[]): Html { | ||
| 233 | 234 | aria-pressed="${String(shown)}" |
| 234 | 235 | >${label}</button>`; |
| 235 | 236 | return html`<div class="bar feed-chips" role="group" aria-label="Filter the feed"> |
| 236 | ${KIND_CHIPS.map((k) => chip("kind", k, CHIP_LABEL[k], !chips.kinds.has(k)))} | |
| 237 | ${KIND_CHIPS.flatMap((k) => { | |
| 238 | // A chip that would change nothing is not drawn (no dead buttons); one | |
| 239 | // switched off stays, so it can come back. | |
| 240 | const shown = !chips.kinds.has(k); | |
| 241 | return shown && !items.some((i) => chipOfKind(i.kind) === k) ? [] : [chip("kind", k, CHIP_LABEL[k], shown)]; | |
| 242 | })} | |
| 237 | 243 | ${[...names].sort().map((n) => chip("person", n, n, !hiddenNames.has(n)))} |
| 238 | 244 | </div>`; |
| 239 | 245 | } |
| 240 | 246 | |
| 247 | /** The last 24 hours: at most three lines, each a repository and what happened in it, linked to the evidence. */ | |
| 248 | function digestCard(items: readonly FeedItem[]): Html | null { | |
outdated
The digest exists only on the web. Give the terminal the same three lines, and say in the README where both live. |
||
| 249 | const lines = digestOf(items, new Date()); | |
| 250 | if (lines.length === 0) return null; | |
| 251 | return html`<section class="stack stack-tight" id="digest" aria-label="What happened in the last 24 hours"> | |
| 252 | <h2 class="small muted">Last 24 h</h2> | |
| 253 | <ul class="list"> | |
| 254 | ${lines.map( | |
| 255 | (l) => html`<li class="row"><a href="${l.href}"><strong>${l.app}</strong>: ${l.text}</a></li>`, | |
| 256 | )} | |
| 257 | </ul> | |
Use |
||
| 258 | </section>`; | |
| 259 | } | |
| 260 | ||
| 241 | 261 | /** What the region shows, read: the posts, the thoughts, where they sit, who posted. */ |
| 242 | 262 | function readRegion(user: User, ctx: Ctx) { |
| 243 | 263 | // What needs you is pinned above the timeline (`needsYouSection`), so an |
| @@ -267,6 +287,7 @@ function drawRegion(user: User, ctx: Ctx, read: ReturnType<typeof readRegion>): | ||
| 267 | 287 | data-live="${FEED_LIVE}" |
| 268 | 288 | data-live-src="/live/feed" |
| 269 | 289 | > |
| 290 | ${digestCard(items)} | |
| 270 | 291 | ${chipsBar(user, ctx, items)} |
| 271 | 292 | ${thoughts.map((t) => thoughtCard(t, user.username, placed.get(t.id)))} |
| 272 | 293 | ${items.length === 0 && thoughts.length === 0 |
src/web/studio/home.ts +1 −1
| @@ -259,7 +259,7 @@ export async function studioHome( | ||
| 259 | 259 | ${ask} ${address} ${figures |
| 260 | 260 | ? timePhase(ctx.request, "kpis", () => kpiRow(ctx.app.db, kpiOpts), () => kpiCache(ctx.app.db)) |
| 261 | 261 | : liveLine(ctx)} |
| 262 | ${timePhase(ctx.request, "waiting", () => waitingLine(ctx.app.db, user))} | |
| 262 | ${timePhase(ctx.request, "waiting", () => waitingLine(ctx, user))} | |
| 263 | 263 | ${figures |
| 264 | 264 | ? await timePhaseAsync(ctx.request, "panels", () => pinnedPanels(ctx.app, user), () => panelCache(ctx.app.db)) |
| 265 | 265 | : null} |
src/web/studio/kpi_row.ts +16 −9
| @@ -8,7 +8,7 @@ | ||
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | 10 | import type { Database } from "bun:sqlite"; |
| 11 | import { backupAge, backupFull, backupOverdue, buildersValue, checkTime, reactNote, speedWords, spendFull, spendValue, usersValue, visitorsNote, visitorsValue, waitingWords } from "../../flow/kpi_words.ts"; | |
| 11 | import { backupAge, backupFull, backupOverdue, buildersValue, checkTime, spendNote, reactNote, speedWords, spendFull, spendValue, usersValue, visitorsNote, visitorsValue, waitingWords } from "../../flow/kpi_words.ts"; | |
| 12 | 12 | import type { Kpis } from "../../flow/kpis.ts"; |
| 13 | 13 | import { cachedKpis } from "./home_cache.ts"; |
| 14 | 14 | import { escapeHtml, html, raw, type Html } from "../html.ts"; |
| @@ -17,7 +17,8 @@ import { running } from "../../kernel/version.ts"; | ||
| 17 | 17 | import { sha, stat, time } from "../ui.ts"; |
| 18 | 18 | import { listReposVisibleTo } from "../../core/repos.ts"; |
| 19 | 19 | import type { User } from "../../core/users.ts"; |
| 20 | import { waitingOn } from "./asks.ts"; | |
| 20 | import type { Ctx } from "../../http/context.ts"; | |
| 21 | import { askRows, forgeNeedsFor, splitStale, waitingOn } from "./asks.ts"; | |
| 21 | 22 | |
| 22 | 23 | const W = 96; |
| 23 | 24 | const H = 24; |
| @@ -131,8 +132,10 @@ export function kpiRowFor(k: Kpis, live: { sha: string; at: string } | null, now | ||
| 131 | 132 | "/settings/crew", |
| 132 | 133 | spendValue(k.spend), |
| 133 | 134 | spendFull(k.spend), |
| 134 | k.spend.ceilingUsd === null ? "no ceiling" : "of the daily ceiling", | |
| 135 | spendNote(k.spend), | |
| 135 | 136 | k.spend.ceilingUsd === null ? "No daily ceiling is set" : "Crew spend today (UTC), of the daily ceiling", |
| 137 | null, | |
| 138 | k.spend.reachedAt ? "attn" : null, | |
| 136 | 139 | )} |
| 137 | 140 | ${tile( |
| 138 | 141 | "Last off-box backup", |
| @@ -165,13 +168,17 @@ export function kpiRow(db: Database, opts: { ceilingUsd?: number; dataDir?: stri | ||
| 165 | 168 | } |
| 166 | 169 | |
| 167 | 170 | /** |
| 168 | * One `.small .muted` line over `/review`: how many asks wait on the viewer | |
| 169 | * (the very rows /review lists) and how long the oldest has. Empty at zero. | |
| 171 | * One `.small .muted` line over `/review`: how many things wait on the viewer | |
| 172 | * (the very rows /review lists, the forge's own needs among them) and how | |
| 173 | * long the oldest has; asks past 30 days are counted apart as stale. Empty at zero. | |
| 170 | 174 | */ |
| 171 | export function waitingLine(db: Database, user: User, now: Date = new Date()): Html { | |
| 175 | export function waitingLine(ctx: Ctx, user: User, now: Date = new Date()): Html { | |
| 176 | const db = ctx.app.db; | |
| 172 | 177 | const repos = listReposVisibleTo(db, user, { limit: 200, withoutArchived: true }); |
| 173 | const asks = waitingOn(db, user, repos); | |
| 174 | const oldest = asks.reduce<string | null>((o, a) => (o === null || Date.parse(a.since) < Date.parse(o) ? a.since : o), null); | |
| 175 | const words = waitingWords(asks.length, oldest, now); | |
| 178 | const { fresh, stale: old } = splitStale(waitingOn(db, user, repos), now); | |
| 179 | const count = askRows(fresh).length + forgeNeedsFor(ctx, user).length; | |
| 180 | const stale = askRows(old).length; | |
| 181 | const oldest = fresh.reduce<string | null>((o, a) => (o === null || Date.parse(a.since) < Date.parse(o) ? a.since : o), null); | |
This runs |
||
| 182 | const words = waitingWords(count, oldest, now, stale); | |
| 176 | 183 | return words === null ? html`` : html`<p class="small muted"><a href="/review">${words}</a></p>`; |
| 177 | 184 | } |
test/feed-chips.test.ts +18
| @@ -179,6 +179,24 @@ describe("the chips of a forge", () => { | ||
| 179 | 179 | setChip(app.db, bob.id, { kind: "kind", value: "crew" }, false); |
| 180 | 180 | }); |
| 181 | 181 | |
| 182 | test("every chip drawn changes the feed: one with nothing to filter is not drawn, a switched-off one stays", async () => { | |
| 183 | const session = createSession(app.db, bob.id); | |
| 184 | const cookie = { cookie: `forge_session=${session.token}` }; | |
| 185 | const drawn = async () => | |
| 186 | [...(await (await fetch(`${servers.url}/live/feed`, { headers: cookie })).text()).matchAll(/data-chip="kind"\s+data-value="(\w+)"/g)].map((m) => m[1]); | |
| 187 | expect(await drawn()).toEqual(["reviews", "crew", "releases"]); | |
| 188 | // Pressing each one removes posts of its kind, and only drawn chips do. | |
| 189 | for (const chip of await drawn()) { | |
| 190 | const before = kinds(bob).length; | |
| 191 | await call(bobToken, "POST", "/api/v1/feed/chips", { kind: "kind", value: chip, hidden: true }); | |
| 192 | expect(kinds(bob).length).toBeLessThan(before); | |
| 193 | expect(await drawn()).toContain(chip); | |
| 194 | await call(bobToken, "POST", "/api/v1/feed/chips", { kind: "kind", value: chip, hidden: false }); | |
| 195 | } | |
| 196 | const page = await (await fetch(`${servers.url}/live/feed`, { headers: cookie })).text(); | |
| 197 | expect(page).toContain('id="digest"'); | |
| 198 | }); | |
| 199 | ||
| 182 | 200 | test("a pressed chip refreshes the region in place and says when it failed", async () => { |
| 183 | 201 | const handler = feedJs.slice(feedJs.indexOf("function chip(c)"), feedJs.indexOf("feed.addEventListener('click'")); |
| 184 | 202 | expect(handler).not.toContain("location.reload"); |
test/home-digest.test.ts added +71
| @@ -0,0 +1,71 @@ | ||
| 1 | /** | |
| 2 | * #5735: the feed's top says what happened in three lines; the spend says | |
| 3 | * why builders are idle; the waiting count matches the list and stale asks | |
| 4 | * stand apart; a chip that would change nothing is not drawn. | |
| 5 | */ | |
| 6 | import { describe, expect, test } from "bun:test"; | |
| 7 | import { digestOf, digestWords } from "../src/feed/digest.ts"; | |
| 8 | import type { FeedItem } from "../src/feed/rank.ts"; | |
| 9 | import { waitingWords } from "../src/flow/kpi_words.ts"; | |
| 10 | import { splitStale } from "../src/web/studio/asks.ts"; | |
| 11 | ||
| 12 | const now = new Date("2026-10-25T18:00:00.000Z"); | |
| 13 | const item = (app: string, kind: FeedItem["kind"], what: string, hoursAgo = 1): FeedItem => ({ | |
| 14 | id: `${app}${kind}${what}${hoursAgo}`, | |
| 15 | kind, | |
| 16 | app, | |
| 17 | actor: null, | |
| 18 | at: new Date(now.getTime() - hoursAgo * 3_600_000).toISOString(), | |
| 19 | link: `/${app}/${kind}`, | |
| 20 | what, | |
| 21 | reason: "", | |
| 22 | score: 0, | |
| 23 | }); | |
| 24 | ||
| 25 | describe("the digest", () => { | |
| 26 | test("groups by repository, biggest first, at most three lines, each linked", () => { | |
| 27 | const lines = digestOf( | |
| 28 | [ | |
| 29 | item("a/one", "pull", "merged a pull request: x"), | |
| 30 | item("b/two", "pull", "merged a pull request: y"), | |
| 31 | item("b/two", "pull", "merged a pull request: z"), | |
| 32 | item("b/two", "release", "a new version is serving"), | |
| 33 | item("c/three", "run", "a check run failed"), | |
| 34 | item("d/four", "pull", "opened a pull request: q"), | |
| 35 | item("e/five", "tell", "said hi"), | |
| 36 | ], | |
| 37 | now, | |
| 38 | ); | |
| 39 | expect(lines.map((l) => l.app)).toEqual(["b/two", "c/three", "a/one"]); | |
| 40 | expect(lines[0]!.text).toBe("2 landed, 1 released"); | |
| 41 | expect(lines[1]!.text).toBe("1 failed"); | |
| 42 | expect(lines.every((l) => l.href.startsWith("/"))).toBe(true); | |
| 43 | }); | |
| 44 | ||
| 45 | test("the terminal says the same lines", () => { | |
| 46 | const words = digestWords(digestOf([item("a/one", "pull", "merged a pull request: x")], now)); | |
| 47 | expect(words).toEqual(["Last 24 h", " a/one: 1 landed"]); | |
| 48 | expect(digestWords([])).toEqual([]); | |
| 49 | }); | |
| 50 | ||
| 51 | test("older than a day is not 'since you were here'", () => { | |
| 52 | expect(digestOf([item("a/one", "release", "a new version is serving", 30)], now)).toEqual([]); | |
| 53 | }); | |
| 54 | }); | |
| 55 | ||
| 56 | describe("waiting and stale", () => { | |
| 57 | test("30 days is the line; stale is counted apart", () => { | |
| 58 | const { fresh, stale } = splitStale( | |
| 59 | [{ since: "2026-10-20T00:00:00.000Z" }, { since: "2026-06-20T00:00:00.000Z" }], | |
| 60 | now, | |
| 61 | ); | |
| 62 | expect(fresh).toHaveLength(1); | |
| 63 | expect(stale).toHaveLength(1); | |
| 64 | }); | |
| 65 | ||
| 66 | test("the words keep stale out of the urgent count", () => { | |
| 67 | expect(waitingWords(3, "2026-10-24T10:00:00.000Z", now, 2)).toBe("3 waiting on you, oldest 32 h, 2 stale, archive?"); | |
| 68 | expect(waitingWords(0, null, now, 2)).toBe("2 stale, archive?"); | |
| 69 | expect(waitingWords(0, null, now)).toBeNull(); | |
| 70 | }); | |
| 71 | }); |
test/home-honest.test.ts added +143
| @@ -0,0 +1,143 @@ | ||
| 1 | /** | |
| 2 | * #5735, end to end: the spend never says builders are idle for a ceiling | |
| 3 | * that is not the forge's; the waiting count on home is the list's count, | |
| 4 | * the forge's own needs included; stale asks stand apart; the terminal | |
| 5 | * shows the digest; the chips drawn are chips that change something. | |
| 6 | */ | |
| 7 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 8 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 9 | import { tmpdir } from "node:os"; | |
| 10 | import { join } from "node:path"; | |
| 11 | import { createApp, type App } from "../src/app.ts"; | |
| 12 | import { setAccountCeiling } from "../src/core/account_ceiling.ts"; | |
| 13 | import { setAssignee, createIssue } from "../src/core/issues.ts"; | |
| 14 | import { createRepo, type Repo } from "../src/core/repos.ts"; | |
| 15 | import { createSession } from "../src/core/sessions.ts"; | |
| 16 | import type { User } from "../src/core/users.ts"; | |
| 17 | import { readKpis } from "../src/flow/kpis.ts"; | |
| 18 | import { ERROR_BURST } from "../src/kernel/vitals.ts"; | |
| 19 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 20 | import type { Ctx } from "../src/http/context.ts"; | |
| 21 | import { askCountFor } from "../src/web/studio/asks.ts"; | |
| 22 | import { kpiRowFor } from "../src/web/studio/kpi_row.ts"; | |
| 23 | import { createForgeApp } from "../src/tui/forge.ts"; | |
| 24 | import { headlessTerminal } from "../src/tui/term/terminal.ts"; | |
| 25 | import { quietLogs } from "./helpers/globals.ts"; | |
| 26 | import { settleApp } from "./helpers/tui.ts"; | |
| 27 | import { seedAdmin } from "./helpers/admin.ts"; | |
| 28 | ||
| 29 | quietLogs(); | |
| 30 | ||
| 31 | let dir: string; | |
| 32 | let app: App; | |
| 33 | let servers: Servers; | |
| 34 | let alice: User; | |
| 35 | let bob: User; | |
| 36 | let repo: Repo; | |
| 37 | let cookie: string; | |
| 38 | ||
| 39 | const now = new Date(); | |
| 40 | const get = async (path: string): Promise<string> => | |
| 41 | (await fetch(`${servers.url}${path}`, { headers: { cookie } })).text(); | |
| 42 | const ctxOf = (user: User) => ({ app, auth: { user }, url: new URL("http://x/") }) as unknown as Ctx; | |
| 43 | ||
| 44 | beforeAll(async () => { | |
| 45 | dir = await mkdtemp(join(tmpdir(), "forge-home-honest-")); | |
| 46 | app = createApp({ dataDir: dir, port: 0 }); | |
| 47 | servers = await serve(app); | |
| 48 | const a = await seedAdmin(app, { username: "alice", email: "[email protected]", password: "a-long-passphrase" }); | |
| 49 | const b = await seedAdmin(app, { username: "bob", email: "[email protected]", password: "a-long-passphrase" }); | |
| 50 | if (!a.ok || !b.ok) throw new Error("seed"); | |
| 51 | alice = a.value; | |
| 52 | bob = b.value; | |
| 53 | cookie = `forge_session=${createSession(app.db, alice.id).token}`; | |
| 54 | const r = await createRepo(app.db, app.reposRoot, { ownerId: bob.id, ownerName: "bob", name: "open", visibility: "public" } as never); | |
| 55 | if (!r.ok) throw new Error("repo"); | |
| 56 | repo = r.value; | |
| 57 | }, 30_000); | |
| 58 | ||
| 59 | afterAll(async () => { | |
| 60 | servers.stop(); | |
| 61 | app.close(); | |
| 62 | await rm(dir, { recursive: true, force: true }); | |
| 63 | }); | |
| 64 | ||
| 65 | const agent = (cost: number) => | |
| 66 | app.db | |
| 67 | .query("INSERT INTO run (id, repo_id, kind, state, cost_usd, created_at) VALUES (?1, ?2, 'agent', 'ok', ?3, ?4)") | |
| 68 | .run(crypto.randomUUID(), repo.id, cost, now.toISOString()); | |
| 69 | ||
| 70 | describe("the spend tile", () => { | |
| 71 | test("another account's ceiling is never the forge's: $15 spent against alice's $10 says no ceiling", async () => { | |
| 72 | expect(setAccountCeiling(app.db, alice.id, 10, 5, alice.id, now)).toBe(true); | |
| 73 | agent(15); | |
| 74 | const k = readKpis(app.db, now); | |
| 75 | expect(k.spend).toEqual({ todayUsd: 15, ceilingUsd: null, reachedAt: null }); | |
| 76 | const page = await get("/"); | |
| 77 | expect(page).toContain("no ceiling"); | |
| 78 | expect(page).not.toContain("builders idle"); | |
| 79 | }); | |
| 80 | ||
| 81 | test("the forge's own ceiling, once passed, names when and turns the tile attention-toned", () => { | |
| 82 | const k = readKpis(app.db, now, { ceilingUsd: 10 }); | |
| 83 | expect(k.spend.reachedAt).toBe(now.toISOString()); | |
| 84 | const tile = (kk: typeof k) => | |
| 85 | kpiRowFor(kk, null, now).toString().match(/<a class="stat"[^>]*Crew spend today[^>]*>[\s\S]*?<\/a>/)![0]; | |
| 86 | const hit = tile(k); | |
| 87 | expect(hit).toContain("builders idle"); | |
| 88 | expect(hit).toContain('data-tone="attn"'); | |
| 89 | const under = readKpis(app.db, now, { ceilingUsd: 100 }); | |
| 90 | expect(under.spend.reachedAt).toBeNull(); | |
| 91 | expect(tile(under)).not.toContain("builders idle"); | |
| 92 | expect(tile(under)).not.toContain("data-tone"); | |
| 93 | }); | |
| 94 | }); | |
| 95 | ||
| 96 | describe("the waiting count", () => { | |
| 97 | test("home's count is the asks page's count, the forge's own need among the rows; stale asks stand apart", async () => { | |
| 98 | for (let i = 0; i < ERROR_BURST; i++) app.signals.errors.record("test", "boom", Date.now()); | |
| 99 | const mine = createIssue(app.db, { repoId: repo.id, authorId: bob.id, title: "fresh one", body: "" }); | |
| 100 | const old = createIssue(app.db, { repoId: repo.id, authorId: bob.id, title: "old one", body: "" }); | |
| 101 | if (!mine.ok || !old.ok) throw new Error("issue"); | |
| 102 | setAssignee(app.db, mine.value.id, alice.id); | |
| 103 | setAssignee(app.db, old.value.id, alice.id); | |
| 104 | app.db.query("UPDATE issue SET updated_at = ?2 WHERE id = ?1").run(old.value.id, new Date(now.getTime() - 40 * 86_400_000).toISOString()); | |
| 105 | ||
| 106 | const count = askCountFor(ctxOf(alice), alice); | |
| 107 | expect(count).toBeGreaterThanOrEqual(2); // the fresh assignment and the degraded forge | |
| 108 | const home = await get("/"); | |
| 109 | expect(home).toContain(`${count} waiting on you`); | |
| 110 | expect(home).toContain("1 stale, archive?"); | |
| 111 | const asks = await get("/asks"); | |
| 112 | expect(asks).toContain(`${count} things need you`); | |
| 113 | // The stale one is behind the fold, with an Archive that leads to the preview. | |
| 114 | expect(asks).toContain('id="asks-stale"'); | |
| 115 | expect(asks).toMatch(/<summary>1 stale, archive\?<\/summary>/); | |
| 116 | expect(asks).toContain('name="item" value="assigned:' + old.value.id + '"'); | |
| 117 | expect(asks).toContain("Archive 1"); | |
| 118 | expect(asks).not.toContain('name="item" value="assigned:' + mine.value.id + '"'); | |
| 119 | }); | |
| 120 | }); | |
| 121 | ||
| 122 | describe("the terminal", () => { | |
| 123 | test("shows the digest above the figures, from the same posts", async () => { | |
| 124 | app.bus.append({ kind: "pull.merged", repoId: repo.id, actorId: bob.id, payload: { number: 1 } }); | |
| 125 | const terminal = headlessTerminal(200, 40); | |
| 126 | const { app: screen } = createForgeApp( | |
| 127 | app, | |
| 128 | { sshUsername: "alice", remoteAddress: "127.0.0.1", fingerprint: "SHA256:t", user: alice }, | |
| 129 | { terminal, exitHooks: false }, | |
| 130 | ); | |
| 131 | screen.start(); | |
| 132 | await settleApp(screen); | |
| 133 | const text = screen.screen.toText(); | |
| 134 | screen.stop(); | |
| 135 | expect(text).toContain("Last 24 h"); | |
| 136 | expect(text).toContain("bob/open: 1 landed"); | |
| 137 | expect(text.indexOf("Last 24 h")).toBeLessThan(text.indexOf("Shipped per hour")); | |
| 138 | }); | |
| 139 | ||
| 140 | test("the web home says the same line", async () => { | |
| 141 | expect(await get("/")).toMatch(/id="digest"[\s\S]*bob\/open<\/strong>: 1 landed/); | |
| 142 | }); | |
| 143 | }); |
test/home-kpi-row.test.ts +19 −19
| @@ -21,7 +21,7 @@ const hours = (n: number) => Array.from({ length: 24 }, (_, i) => (i === 3 ? n : | ||
| 21 | 21 | describe("home kpi row", () => { |
| 22 | 22 | test("five tiles with their links and figures", () => { |
| 23 | 23 | const out = kpiRowFor( |
| 24 | { landedHours: hours(6), landed: 6, live: null, builders: { running: 2, slots: 4 }, spend: { todayUsd: 0, ceilingUsd: null }, medianCheckMs: 185_000, backupAt: null, reach: NO_REACH }, | |
| 24 | { landedHours: hours(6), landed: 6, live: null, builders: { running: 2, slots: 4 }, spend: { todayUsd: 0, ceilingUsd: null, reachedAt: null }, medianCheckMs: 185_000, backupAt: null, reach: NO_REACH }, | |
| 25 | 25 | { sha: "abcdef0123456", at: "2026-10-19T11:00:00.000Z" }, |
| 26 | 26 | ).toString(); |
| 27 | 27 | expect(out).toContain('<span class="sha">abcdef0</span>'); |
| @@ -36,7 +36,7 @@ describe("home kpi row", () => { | ||
| 36 | 36 | |
| 37 | 37 | test("the whole figure is in the title and the link's label, rounded and in studio words", () => { |
| 38 | 38 | const out = kpiRowFor( |
| 39 | { landedHours: hours(7), landed: 7, live: null, builders: { running: 2, slots: 4 }, spend: { todayUsd: 0, ceilingUsd: null }, medianCheckMs: 185_000, backupAt: null, reach: NO_REACH }, | |
| 39 | { landedHours: hours(7), landed: 7, live: null, builders: { running: 2, slots: 4 }, spend: { todayUsd: 0, ceilingUsd: null, reachedAt: null }, medianCheckMs: 185_000, backupAt: null, reach: NO_REACH }, | |
| 40 | 40 | { sha: "abcdef0123456", at: "2026-10-19T11:00:00.000Z" }, |
| 41 | 41 | ).toString(); |
| 42 | 42 | expect(out).toContain('title="0.29"'); |
| @@ -48,13 +48,13 @@ describe("home kpi row", () => { | ||
| 48 | 48 | }); |
| 49 | 49 | |
| 50 | 50 | test("empty figures say so", () => { |
| 51 | const out = kpiRowFor({ landedHours: hours(0), landed: 0, live: null, builders: { running: 2, slots: 4 }, spend: { todayUsd: 0, ceilingUsd: null }, medianCheckMs: null, backupAt: null, reach: NO_REACH }, null).toString(); | |
| 51 | const out = kpiRowFor({ landedHours: hours(0), landed: 0, live: null, builders: { running: 2, slots: 4 }, spend: { todayUsd: 0, ceilingUsd: null, reachedAt: null }, medianCheckMs: null, backupAt: null, reach: NO_REACH }, null).toString(); | |
| 52 | 52 | expect(out).toContain("Nothing live yet"); |
| 53 | 53 | expect(out).toContain("No check finished in 24 h"); |
| 54 | 54 | }); |
| 55 | 55 | |
| 56 | 56 | test("no git words render, not even in a title or label", () => { |
| 57 | const out = kpiRowFor({ landedHours: hours(1), landed: 1, live: null, builders: { running: 2, slots: 4 }, spend: { todayUsd: 0, ceilingUsd: null }, medianCheckMs: 1000, backupAt: null, reach: NO_REACH }, null).toString(); | |
| 57 | const out = kpiRowFor({ landedHours: hours(1), landed: 1, live: null, builders: { running: 2, slots: 4 }, spend: { todayUsd: 0, ceilingUsd: null, reachedAt: null }, medianCheckMs: 1000, backupAt: null, reach: NO_REACH }, null).toString(); | |
| 58 | 58 | expect(out).not.toMatch(/commit|merge|branch|repositor|pull request|checks (passed|failed)/i); |
| 59 | 59 | }); |
| 60 | 60 | |
| @@ -78,7 +78,7 @@ describe("home kpi row", () => { | ||
| 78 | 78 | }); |
| 79 | 79 | |
| 80 | 80 | test("a truncated note carries its whole text as a title", () => { |
| 81 | const out = kpiRowFor({ landedHours: hours(0), landed: 0, live: null, builders: { running: 2, slots: 4 }, spend: { todayUsd: 0, ceilingUsd: null }, medianCheckMs: null, backupAt: null, reach: NO_REACH }, null).toString(); | |
| 81 | const out = kpiRowFor({ landedHours: hours(0), landed: 0, live: null, builders: { running: 2, slots: 4 }, spend: { todayUsd: 0, ceilingUsd: null, reachedAt: null }, medianCheckMs: null, backupAt: null, reach: NO_REACH }, null).toString(); | |
| 82 | 82 | expect(out).toContain('title="No check finished in 24 h"'); |
| 83 | 83 | }); |
| 84 | 84 | |
| @@ -91,7 +91,7 @@ describe("home kpi row", () => { | ||
| 91 | 91 | }); |
| 92 | 92 | |
| 93 | 93 | test("the builders tile says running of slots, titles it, and links to the crew", () => { |
| 94 | const out = kpiRowFor({ landedHours: hours(0), landed: 0, live: null, backupAt: null, reach: NO_REACH, medianCheckMs: null, builders: { running: 2, slots: 4 }, spend: { todayUsd: 0, ceilingUsd: null } }, null).toString(); | |
| 94 | const out = kpiRowFor({ landedHours: hours(0), landed: 0, live: null, backupAt: null, reach: NO_REACH, medianCheckMs: null, builders: { running: 2, slots: 4 }, spend: { todayUsd: 0, ceilingUsd: null, reachedAt: null } }, null).toString(); | |
| 95 | 95 | expect(out).toContain('href="/settings/crew"'); |
| 96 | 96 | expect(out).toContain('class="stat-value num" title="2 of 4">2 of 4<'); |
| 97 | 97 | expect(out).toContain('title="Crew builders running now, of 4 slots"'); |
| @@ -99,7 +99,7 @@ describe("home kpi row", () => { | ||
| 99 | 99 | }); |
| 100 | 100 | |
| 101 | 101 | test("with no slots set the builders tile shows a dash and says so", () => { |
| 102 | const out = kpiRowFor({ landedHours: hours(0), landed: 0, live: null, backupAt: null, reach: NO_REACH, medianCheckMs: null, builders: { running: 0, slots: 0 }, spend: { todayUsd: 0, ceilingUsd: null } }, null).toString(); | |
| 102 | const out = kpiRowFor({ landedHours: hours(0), landed: 0, live: null, backupAt: null, reach: NO_REACH, medianCheckMs: null, builders: { running: 0, slots: 0 }, spend: { todayUsd: 0, ceilingUsd: null, reachedAt: null } }, null).toString(); | |
| 103 | 103 | expect(out).toContain('class="stat-value num" title="—">—<'); |
| 104 | 104 | expect(out).toContain('title="No slots set">No slots set<'); |
| 105 | 105 | expect(out).toContain(`aria-label="Builders running: —, No slots set"`); |
| @@ -107,7 +107,7 @@ describe("home kpi row", () => { | ||
| 107 | 107 | }); |
| 108 | 108 | |
| 109 | 109 | test("the builders note does not repeat the value", () => { |
| 110 | const out = kpiRowFor({ landedHours: hours(0), landed: 0, live: null, backupAt: null, reach: NO_REACH, medianCheckMs: null, builders: { running: 2, slots: 4 }, spend: { todayUsd: 0, ceilingUsd: null } }, null).toString(); | |
| 110 | const out = kpiRowFor({ landedHours: hours(0), landed: 0, live: null, backupAt: null, reach: NO_REACH, medianCheckMs: null, builders: { running: 2, slots: 4 }, spend: { todayUsd: 0, ceilingUsd: null, reachedAt: null } }, null).toString(); | |
| 111 | 111 | expect(out).toContain(">running now<"); |
| 112 | 112 | }); |
| 113 | 113 | |
| @@ -135,13 +135,13 @@ describe("the builders figure from the database", () => { | ||
| 135 | 135 | }); |
| 136 | 136 | |
| 137 | 137 | describe("the terminal's figures", () => { |
| 138 | const k = { landedHours: hours(6), landed: 6, live: { sha: "abcdef0123456", at: new Date().toISOString() }, builders: { running: 2, slots: 4 }, spend: { todayUsd: 12, ceilingUsd: 40 }, medianCheckMs: 185_000, backupAt: null, reach: NO_REACH }; | |
| 138 | const k = { landedHours: hours(6), landed: 6, live: { sha: "abcdef0123456", at: new Date().toISOString() }, builders: { running: 2, slots: 4 }, spend: { todayUsd: 12, ceilingUsd: 40, reachedAt: null }, medianCheckMs: 185_000, backupAt: null, reach: NO_REACH }; | |
| 139 | 139 | test("the same nine figures in the same words", () => { |
| 140 | 140 | const lines = kpiLines(k, { sha: "abcdef0123456", since: "5m ago" }); |
| 141 | 141 | expect(lines).toHaveLength(9); |
| 142 | 142 | expect(lines).toContain("Last off-box backup never, overdue"); |
| 143 | 143 | expect(lines[4]).toBe("Crew spend today $12 of $40"); |
| 144 | expect(kpiLines({ ...k, spend: { todayUsd: 0.4, ceilingUsd: null } }, null)[4]).toBe("Crew spend today $0.40, no ceiling"); | |
| 144 | expect(kpiLines({ ...k, spend: { todayUsd: 0.4, ceilingUsd: null, reachedAt: null } }, null)[4]).toBe("Crew spend today $0.40, no ceiling"); | |
| 145 | 145 | expect(lines[3]).toBe("Builders running 2 of 4"); |
| 146 | 146 | expect(kpiLines({ ...k, builders: { running: 0, slots: 0 } }, null)[3]).toBe("Builders running —, no slots set"); |
| 147 | 147 | expect(lines[0]).toContain("Shipped per hour 0.3"); |
| @@ -158,8 +158,8 @@ describe("the terminal's figures", () => { | ||
| 158 | 158 | }); |
| 159 | 159 | |
| 160 | 160 | describe("the spend tile", () => { |
| 161 | const row = (spend: { todayUsd: number; ceilingUsd: number | null }) => | |
| 162 | kpiRowFor({ landedHours: hours(0), landed: 0, live: null, backupAt: null, reach: NO_REACH, medianCheckMs: null, builders: { running: 0, slots: 0 }, spend }, null).toString(); | |
| 161 | const row = (spend: { todayUsd: number; ceilingUsd: number | null; reachedAt?: string | null }) => | |
| 162 | kpiRowFor({ landedHours: hours(0), landed: 0, live: null, backupAt: null, reach: NO_REACH, medianCheckMs: null, builders: { running: 0, slots: 0 }, spend: { reachedAt: null, ...spend } }, null).toString(); | |
| 163 | 163 | |
| 164 | 164 | test("shows today's spend of the ceiling, the cents in the title, linking to the crew page", () => { |
| 165 | 165 | const out = row({ todayUsd: 12.34, ceilingUsd: 40 }); |
| @@ -196,8 +196,8 @@ describe("the spend figure from the database", () => { | ||
| 196 | 196 | ('1','agent',5,'2026-10-19T00:00:00.000Z'), ('2','agent',7.5,'2026-10-19T14:00:00.000Z'), |
| 197 | 197 | ('3','agent',100,'2026-10-18T23:59:59.000Z'), ('4','check',9,'2026-10-19T10:00:00.000Z')`, |
| 198 | 198 | ); |
| 199 | expect(readKpis(db, now, { ceilingUsd: 40 }).spend).toEqual({ todayUsd: 12.5, ceilingUsd: 40 }); | |
| 200 | expect(readKpis(db, now).spend).toEqual({ todayUsd: 12.5, ceilingUsd: null }); | |
| 199 | expect(readKpis(db, now, { ceilingUsd: 40 }).spend).toEqual({ todayUsd: 12.5, ceilingUsd: 40, reachedAt: null }); | |
| 200 | expect(readKpis(db, now).spend).toEqual({ todayUsd: 12.5, ceilingUsd: null, reachedAt: null }); | |
| 201 | 201 | }); |
| 202 | 202 | }); |
| 203 | 203 | |
| @@ -205,7 +205,7 @@ describe("home kpi row: the last off-box backup", () => { | ||
| 205 | 205 | const NOW = new Date("2026-10-20T12:00:00.000Z"); |
| 206 | 206 | const hoursAgo = (h: number) => new Date(NOW.getTime() - h * 3_600_000).toISOString(); |
| 207 | 207 | const row = (backupAt: string | null) => |
| 208 | kpiRowFor({ landedHours: hours(0), landed: 0, live: null, backupAt, reach: NO_REACH, builders: { running: 0, slots: 0 }, spend: { todayUsd: 0, ceilingUsd: null }, medianCheckMs: null }, null, NOW).toString(); | |
| 208 | kpiRowFor({ landedHours: hours(0), landed: 0, live: null, backupAt, reach: NO_REACH, builders: { running: 0, slots: 0 }, spend: { todayUsd: 0, ceilingUsd: null, reachedAt: null }, medianCheckMs: null }, null, NOW).toString(); | |
| 209 | 209 | const tile = (out: string) => /<a class="stat"[^>]*href="\/settings\/backups"[^>]*>/.exec(out)![0]; |
| 210 | 210 | |
| 211 | 211 | test("a backup 2 h old reads its age, with the exact time, and is not flagged", () => { |
| @@ -252,7 +252,7 @@ describe("home kpi row: the last off-box backup", () => { | ||
| 252 | 252 | describe("the reach tiles", () => { |
| 253 | 253 | test("say what they count in words, each linking to the reach board", () => { |
| 254 | 254 | const reach = { usersToday: 3, usersTotal: 12, visitorsToday: 5, visitors7d: 31, visitorDays: new Array<number>(30).fill(0), loadP75: 1250, inpP75: 180 }; |
| 255 | const out = kpiRowFor({ landedHours: hours(0), landed: 0, live: null, backupAt: null, reach, medianCheckMs: null, builders: { running: 0, slots: 0 }, spend: { todayUsd: 0, ceilingUsd: null } }, null).toString(); | |
| 255 | const out = kpiRowFor({ landedHours: hours(0), landed: 0, live: null, backupAt: null, reach, medianCheckMs: null, builders: { running: 0, slots: 0 }, spend: { todayUsd: 0, ceilingUsd: null, reachedAt: null } }, null).toString(); | |
| 256 | 256 | for (const v of ["5 today", "31 in 7 days", "3 of 12", "signed in today", "1.3 s", "reacts in 180 ms"]) expect(out).toContain(`>${v}<`); |
| 257 | 257 | expect((out.match(/class="stat" href="\/boards\/reach"/g) ?? []).length).toBe(3); |
| 258 | 258 | expect(out).not.toContain("INP"); |
| @@ -262,12 +262,12 @@ describe("the reach tiles", () => { | ||
| 262 | 262 | test("the terminal draws the 30 days as one block per day", () => { |
| 263 | 263 | const days = Array.from({ length: 30 }, (_, i) => (i === 29 ? 8 : 0)); |
| 264 | 264 | const reach = { usersToday: 0, usersTotal: 1, visitorsToday: 8, visitors7d: 8, visitorDays: days, loadP75: null, inpP75: null }; |
| 265 | const line = kpiLines({ landedHours: hours(0), landed: 0, live: null, backupAt: null, reach, medianCheckMs: null, builders: { running: 0, slots: 0 }, spend: { todayUsd: 0, ceilingUsd: null } }, null).find((l) => l.startsWith("Visitors"))!; | |
| 265 | const line = kpiLines({ landedHours: hours(0), landed: 0, live: null, backupAt: null, reach, medianCheckMs: null, builders: { running: 0, slots: 0 }, spend: { todayUsd: 0, ceilingUsd: null, reachedAt: null } }, null).find((l) => l.startsWith("Visitors"))!; | |
| 266 | 266 | expect(line).toContain("▁".repeat(29) + "█"); |
| 267 | 267 | }); |
| 268 | 268 | |
| 269 | 269 | test("the terminal says the same", () => { |
| 270 | const lines = kpiLines({ landedHours: hours(0), landed: 0, live: null, backupAt: null, reach: { usersToday: 3, usersTotal: 12, visitorsToday: 5, visitors7d: 31, visitorDays: new Array<number>(30).fill(0), loadP75: 1250, inpP75: 180 }, medianCheckMs: null, builders: { running: 0, slots: 0 }, spend: { todayUsd: 0, ceilingUsd: null } }, null); | |
| 270 | const lines = kpiLines({ landedHours: hours(0), landed: 0, live: null, backupAt: null, reach: { usersToday: 3, usersTotal: 12, visitorsToday: 5, visitors7d: 31, visitorDays: new Array<number>(30).fill(0), loadP75: 1250, inpP75: 180 }, medianCheckMs: null, builders: { running: 0, slots: 0 }, spend: { todayUsd: 0, ceilingUsd: null, reachedAt: null } }, null); | |
| 271 | 271 | expect(lines.find((l) => l.startsWith("Visitors"))).toContain("Visitors 5 today, 31 in 7 days"); |
| 272 | 272 | expect(lines).toContain("Accounts 3 of 12 signed in today"); |
| 273 | 273 | expect(lines.find((l) => l.startsWith("Visitors"))).toContain("▁".repeat(30)); |
| @@ -286,7 +286,7 @@ describe("the visitors sparkline", () => { | ||
| 286 | 286 | expect(r.visitorDays[29]).toBe(2); |
| 287 | 287 | expect(r.visitorDays[0]).toBe(1); // 2026-09-20 is 29 days back; 09-19 is out |
| 288 | 288 | expect(r.visitorDays.reduce((a, b) => a + b, 0)).toBe(3); |
| 289 | const out = kpiRowFor({ landedHours: hours(0), landed: 0, live: null, backupAt: null, reach: r, medianCheckMs: null, builders: { running: 0, slots: 0 }, spend: { todayUsd: 0, ceilingUsd: null } }, null).toString(); | |
| 289 | const out = kpiRowFor({ landedHours: hours(0), landed: 0, live: null, backupAt: null, reach: r, medianCheckMs: null, builders: { running: 0, slots: 0 }, spend: { todayUsd: 0, ceilingUsd: null, reachedAt: null } }, null).toString(); | |
| 290 | 290 | const svg = /<svg[^>]*last 30 days[^>]*><polyline points="([^"]+)"/.exec(out)!; |
| 291 | 291 | expect(svg[1]!.split(" ")).toHaveLength(30); |
| 292 | 292 | expect(out).toContain('href="/boards/reach"'); |
test/home-kpis.test.ts +1 −1
| @@ -132,7 +132,7 @@ describe("home kpis", () => { | ||
| 132 | 132 | |
| 133 | 133 | describe("home kpi row titles", () => { |
| 134 | 134 | const full = kpiRowFor( |
| 135 | { landedHours: Array.from({ length: 24 }, (_, i) => (i === 0 ? 6 : 0)), landed: 6, live: null, builders: { running: 2, slots: 4 }, spend: { todayUsd: 0, ceilingUsd: null }, medianCheckMs: 185_000, backupAt: null, reach: NO_REACH }, | |
| 135 | { landedHours: Array.from({ length: 24 }, (_, i) => (i === 0 ? 6 : 0)), landed: 6, live: null, builders: { running: 2, slots: 4 }, spend: { todayUsd: 0, ceilingUsd: null, reachedAt: null }, medianCheckMs: 185_000, backupAt: null, reach: NO_REACH }, | |
| 136 | 136 | { sha: "abcdef0123456789", at: "2026-10-19T11:00:00.000Z" }, |
| 137 | 137 | ).toString(); |
| 138 | 138 |
new above
offline
High: MAX of per-account ceilings is not a forge ceiling.
ceilingReachedAtthen sums every account's agent spend against it, so "builders idle" can show while they all run. Use only the forge cap here, or compare each account's spend with its own ceiling.