Public: anyone can read this; the crew can change it.
On a client's first screen each app says in plain words what its agents are doing now, or what last changed #4005
scout/forge:scout/3344-on-a-client-s-first-screen-each-app-says → main 4 commits fork
6 files
changed +242
−7
README.md +6 −2
| @@ -331,8 +331,12 @@ On a forge made for a client (one that was spawned, signed in by its claim | ||
| 331 | 331 | link), the home is their apps, one plain sentence each and one more saying |
| 332 | 332 | whether its agents are working, about to start, or waiting: no map, board or |
| 333 | 333 | settings until asked. `/?all=1` is the whole home, and its "Just my apps" link |
| 334 | comes back. The terminal's first screen opens with the same lines, from the | |
| 335 | same query (`src/core/client-apps.ts`). | |
| 334 | comes back. A third line says "Working on: <title>" while an agent run is | |
| 335 | going, else "Last change: <title>, 3 days ago" when something landed in the | |
| 336 | last 7 days, else nothing (titles cut to 80 characters; `clientDoings` and | |
| 337 | `doingLine` in `src/core/client-apps.ts`, one bounded read, the `doing` | |
| 338 | Server-Timing phase). The terminal's first screen opens with the same lines, | |
| 339 | from the same code. | |
| 336 | 340 | |
| 337 | 341 | Home shows nine figures first, from `src/flow/kpis.ts`: shipped per hour (with |
| 338 | 342 | a 24 h sparkline), the live version and since when, the median check time, the crew builders |
src/core/client-apps.ts +68
| @@ -4,6 +4,7 @@ | ||
| 4 | 4 | * The web home and the terminal both read it, so they cannot disagree. |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | import { ago } from "../feed/rank.ts"; | |
| 7 | 8 | import type { App } from "../app.ts"; |
| 8 | 9 | import { spawnedRepos } from "./next-steps.ts"; |
| 9 | 10 | import { withoutArchived, type Repo } from "./repos.ts"; |
| @@ -39,3 +40,70 @@ export async function clientAppRows( | ||
| 39 | 40 | return { repo, working: n("running"), queued: n("queued") }; |
| 40 | 41 | }); |
| 41 | 42 | } |
| 43 | ||
| 44 | /** What an app's agents are doing now, or what last landed in the past week. */ | |
| 45 | export interface Doing { | |
| 46 | readonly kind: "working" | "landed"; | |
| 47 | readonly title: string; | |
| 48 | /** Epoch milliseconds the work started or landed. */ | |
| 49 | readonly at: number; | |
| 50 | } | |
| 51 | ||
| 52 | const LANDED_WINDOW_MS = 7 * 24 * 3600 * 1000; | |
| 53 | ||
| 54 | /** | |
| 55 | * One bounded read: per app, the title of the issue a run is working on, else | |
| 56 | * the newest change that landed in the last 7 days. Apps with neither are absent. | |
| 57 | */ | |
| 58 | export function clientDoings( | |
| 59 | app: App, | |
| 60 | repoIds: readonly string[], | |
| 61 | now: number = Date.now(), | |
| 62 | ): ReadonlyMap<string, Doing> { | |
| 63 | const out = new Map<string, Doing>(); | |
| 64 | if (repoIds.length === 0) return out; | |
| 65 | const marks = repoIds.map((_, i) => `?${i + 2}`).join(","); | |
| 66 | const rows = app.db | |
| 67 | .query< | |
| 68 | { repo_id: string; what: "working" | "landed"; title: string; at: string | null }, | |
| 69 | string[] | |
| 70 | >( | |
| 71 | `SELECT r.repo_id, 'working' AS what, i.title, COALESCE(r.started_at, r.created_at) AS at | |
| 72 | FROM run r JOIN issue i ON i.id = r.issue_id | |
| 73 | WHERE r.kind = 'agent' AND r.state = 'running' AND r.repo_id IN (${marks}) | |
| 74 | UNION ALL | |
| 75 | SELECT i.repo_id, 'landed', i.title, MAX(p.merged_at) | |
| 76 | FROM pull p JOIN issue i ON i.id = p.issue_id | |
| 77 | WHERE p.merged_at >= ?1 AND i.repo_id IN (${marks}) | |
| 78 | GROUP BY i.repo_id | |
| 79 | ORDER BY 4 DESC`, | |
| 80 | ) | |
| 81 | .all(new Date(now - LANDED_WINDOW_MS).toISOString(), ...repoIds); | |
| 82 | for (const row of rows) { | |
| 83 | const at = Date.parse(row.at ?? ""); | |
| 84 | const have = out.get(row.repo_id); | |
| 85 | if (have !== undefined && (have.kind === "working" || row.what === "landed")) continue; | |
| 86 | out.set(row.repo_id, { kind: row.what, title: row.title, at: Number.isNaN(at) ? now : at }); | |
| 87 | } | |
| 88 | return out; | |
| 89 | } | |
| 90 | ||
| 91 | const TITLE_MAX = 80; | |
| 92 | ||
| 93 | /** A title cut to 80 characters at a word boundary, with an ellipsis when cut. */ | |
| 94 | export function trimTitle(title: string): string { | |
| 95 | const t = title.replace(/\s+/g, " ").trim(); | |
| 96 | if (t.length <= TITLE_MAX) return t; | |
| 97 | const cut = t.slice(0, TITLE_MAX); | |
| 98 | const space = cut.lastIndexOf(" "); | |
| 99 | return `${(space > 0 ? cut.slice(0, space) : cut).replace(/[\s.,;:!-]+$/, "")}…`; | |
| 100 | } | |
| 101 | ||
| 102 | /** The plain sentence about the work: what is going now, or what last landed; else nothing. */ | |
| 103 | export function doingLine(doing: Doing | undefined, now: number = Date.now()): string { | |
| 104 | if (doing === undefined) return ""; | |
| 105 | const title = trimTitle(doing.title); | |
| 106 | return doing.kind === "working" | |
| 107 | ? `Working on: ${title}` | |
| 108 | : `Last change: ${title}, ${ago(doing.at, now)}`; | |
| 109 | } |
src/tui/screens/dashboard.ts +9 −4
| @@ -20,7 +20,7 @@ import { forgeLane, forgeNeeds } from "../../actions/health.ts"; | ||
| 20 | 20 | import { ownerWaits, waitLine, withMore } from "../../actions/owner_waits.ts"; |
| 21 | 21 | import { forgeHealth } from "../../kernel/guard.ts"; |
| 22 | 22 | import { coveredByVerdict, forgeVerdict, verdictLine } from "../../kernel/guard_verdict.ts"; |
| 23 | import { clientAppRows } from "../../core/client-apps.ts"; | |
| 23 | import { clientAppRows, clientDoings, doingLine } from "../../core/client-apps.ts"; | |
| 24 | 24 | import { nextStepsFor } from "../../core/next-steps.ts"; |
| 25 | 25 | import { agentsLine } from "../../web/studio/client_home.ts"; |
| 26 | 26 | import { mayView } from "../../core/sealed.ts"; |
| @@ -186,12 +186,17 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 186 | 186 | // A client's home never carries the forge-wide figures, on either door. |
| 187 | 187 | figures = []; |
| 188 | 188 | const apps = await clientAppRows(f.app, f.user); |
| 189 | const doings = clientDoings(f.app, apps.map((a) => a.repo.id)); | |
| 189 | 190 | clientLines = |
| 190 | 191 | apps.length === 0 |
| 191 | 192 | ? ["Your apps will appear here."] |
| 192 | : apps.map( | |
| 193 | (a) => `${a.repo.name}: ${agentsLine(a.working, a.queued)}`, | |
| 194 | ); | |
| 193 | : apps.flatMap((a) => { | |
| 194 | const doing = doingLine(doings.get(a.repo.id)); | |
| 195 | return [ | |
| 196 | `${a.repo.name}: ${agentsLine(a.working, a.queued)}`, | |
| 197 | ...(doing === "" ? [] : [` ${doing}`]), | |
| 198 | ]; | |
| 199 | }); | |
| 195 | 200 | ctx.invalidate(); |
| 196 | 201 | }; |
| 197 | 202 |
src/web/studio/client_home.ts +6 −1
| @@ -7,7 +7,7 @@ | ||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | import { notePhase, takeSessionTime, timePhaseAsync } from "../../core/route_timing.ts"; |
| 10 | import { clientAppRows } from "../../core/client-apps.ts"; | |
| 10 | import { clientAppRows, clientDoings, doingLine } from "../../core/client-apps.ts"; | |
| 11 | 11 | import type { User } from "../../core/users.ts"; |
| 12 | 12 | import type { Ctx } from "../../http/context.ts"; |
| 13 | 13 | import { repoBase } from "../chrome.ts"; |
| @@ -28,15 +28,20 @@ export function agentsLine(working: number, queued: number): string { | ||
| 28 | 28 | export async function clientApps(ctx: Ctx, user: User): Promise<Html> { |
| 29 | 29 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 30 | 30 | const apps = await timePhaseAsync(ctx.request, "apps", () => clientAppRows(ctx.app, user)); |
| 31 | const doings = await timePhaseAsync(ctx.request, "doing", async () => | |
| 32 | clientDoings(ctx.app, apps.map((a) => a.repo.id)), | |
| 33 | ); | |
| 31 | 34 | const rendering = performance.now(); |
| 32 | 35 | const rows = apps.map(({ repo, working, queued }) => { |
| 33 | 36 | const about = repo.description !== "" ? repo.description : "An app of yours."; |
| 37 | const doing = doingLine(doings.get(repo.id)); | |
| 34 | 38 | return html`<li class="client-app"> |
| 35 | 39 | <a href="${repoBase(repo)}"><b>${repo.name}</b></a> |
| 36 | 40 | <span class="client-app-about">${about}</span> |
| 37 | 41 | <span class="client-app-agents muted" data-agents="${working > 0 ? "working" : "waiting"}" |
| 38 | 42 | >${agentsLine(working, queued)}</span |
| 39 | 43 | > |
| 44 | ${doing !== "" ? html`<span class="client-app-doing muted">${doing}</span>` : ""} | |
| 40 | 45 | </li>`; |
| 41 | 46 | }); |
| 42 | 47 | const shown = card( |
src/web/studio/style.ts +11
| @@ -32,6 +32,11 @@ const wordBadges = part(/* css */ ` | ||
| 32 | 32 | |
| 33 | 33 | /** The phone: one document, narrower. Each rule belongs to a component above |
| 34 | 34 | * and only ever applies at 600px and under, so nothing changes on a desktop. */ |
| 35 | const clientApps = part(/* css */ ` | |
| 36 | .client-app { display: grid; gap: 2px; } | |
| 37 | .client-app-doing { overflow-wrap: anywhere; } | |
| 38 | `); | |
| 39 | ||
| 35 | 40 | const phone = part(/* css */ ` |
| 36 | 41 | @media (max-width: 600px) { |
| 37 | 42 | .feed .card-head { row-gap: 2px; } |
| @@ -44,6 +49,12 @@ import { feedCss } from "./feed_style.ts"; | ||
| 44 | 49 | export const studioCss = `@layer components {\n${[ |
| 45 | 50 | justChanged, |
| 46 | 51 | wordBadges, |
| 52 | <<<<<<< HEAD | |
| 53 | rows, | |
| 54 | rowActions, | |
| 55 | clientApps, | |
| 56 | ======= | |
| 57 | >>>>>>> origin/main | |
| 47 | 58 | part(feedCss), |
| 48 | 59 | phone, |
| 49 | 60 | ].join("\n\n")}\n}`; |
test/client-home.test.ts +142
| @@ -25,6 +25,8 @@ import { firstBoot } from "../src/spawn/first-boot.ts"; | ||
| 25 | 25 | import { hostedPlacement } from "../src/spawn/placement.ts"; |
| 26 | 26 | import { createForgeApp } from "../src/tui/forge.ts"; |
| 27 | 27 | import { headlessTerminal } from "../src/tui/term/terminal.ts"; |
| 28 | import { studioCss } from "../src/web/studio/style.ts"; | |
| 29 | import { clientDoings, trimTitle } from "../src/core/client-apps.ts"; | |
| 28 | 30 | import { quietLogs } from "./helpers/globals.ts"; |
| 29 | 31 | import { settleApp } from "./helpers/tui.ts"; |
| 30 | 32 | import { passkeyFields } from "./helpers/passkey.ts"; |
| @@ -279,6 +281,146 @@ describe("a client's first screen", () => { | ||
| 279 | 281 | expect(home).not.toContain('href="/marias/bakery"'); |
| 280 | 282 | }); |
| 281 | 283 | |
| 284 | describe("what the agents are doing", () => { | |
| 285 | const seed = (): { repo: string; maria: string } => ({ | |
| 286 | repo: child.db.query<{ id: string }, []>("SELECT id FROM repo WHERE name = 'bakery'").get()!.id, | |
| 287 | maria: getUserByName(child.db, "maria")!.id, | |
| 288 | }); | |
| 289 | const issue = (id: string, n: number, title: string, kind = "issue"): void => { | |
| 290 | const { repo, maria } = seed(); | |
| 291 | child.db | |
| 292 | .query("INSERT INTO issue (id, repo_id, number, kind, title, author_id) VALUES (?1, ?2, ?3, ?4, ?5, ?6)") | |
| 293 | .run(id, repo, n, kind, title, maria); | |
| 294 | }; | |
| 295 | const clean = (): void => { | |
| 296 | child.db.query("DELETE FROM run WHERE id LIKE 'r-doing-%'").run(); | |
| 297 | child.db.query("DELETE FROM issue WHERE id LIKE 'i-doing-%'").run(); | |
| 298 | }; | |
| 299 | ||
| 300 | test("a quiet app shows neither sentence", async () => { | |
| 301 | const home = await page(owner); | |
| 302 | expect(home).not.toContain("Working on:"); | |
| 303 | expect(home).not.toContain("Last change:"); | |
| 304 | }); | |
| 305 | ||
| 306 | test("a working run shows its title, escaped", async () => { | |
| 307 | issue("i-doing-1", 901, "Add <b>opening hours</b>"); | |
| 308 | child.db | |
| 309 | .query("INSERT INTO run (id, repo_id, kind, state, issue_id) VALUES ('r-doing-1', ?1, 'agent', 'running', 'i-doing-1')") | |
| 310 | .run(seed().repo); | |
| 311 | const home = await page(owner); | |
| 312 | expect(home).toContain("Working on: Add <b>opening hours</b>"); | |
| 313 | expect(home).not.toContain("<b>opening hours"); | |
| 314 | clean(); | |
| 315 | }); | |
| 316 | ||
| 317 | test("a change that landed in the week shows its title and time; an old one does not", async () => { | |
| 318 | issue("i-doing-2", 902, "Fix the menu", "pull"); | |
| 319 | const merge = (at: string): void => { | |
| 320 | child.db.query("DELETE FROM pull WHERE issue_id = 'i-doing-2'").run(); | |
| 321 | child.db | |
| 322 | .query("INSERT INTO pull (issue_id, base_branch, head_branch, base_oid, head_oid, merged_at) VALUES ('i-doing-2', 'main', 'x', 'a', 'b', ?1)") | |
| 323 | .run(at); | |
| 324 | }; | |
| 325 | merge(new Date(Date.now() - 3 * 24 * 3600 * 1000).toISOString()); | |
| 326 | expect(await page(owner)).toContain("Last change: Fix the menu, 3 days ago"); | |
| 327 | merge(new Date(Date.now() - 9 * 24 * 3600 * 1000).toISOString()); | |
| 328 | expect(await page(owner)).not.toContain("Last change:"); | |
| 329 | child.db.query("DELETE FROM pull WHERE issue_id = 'i-doing-2'").run(); | |
| 330 | clean(); | |
| 331 | }); | |
| 332 | ||
| 333 | test("work in progress wins over a landed change", async () => { | |
| 334 | issue("i-doing-3", 903, "Done thing", "pull"); | |
| 335 | child.db | |
| 336 | .query("INSERT INTO pull (issue_id, base_branch, head_branch, base_oid, head_oid, merged_at) VALUES ('i-doing-3', 'main', 'x', 'a', 'b', ?1)") | |
| 337 | .run(new Date().toISOString()); | |
| 338 | issue("i-doing-4", 904, "Current thing"); | |
| 339 | child.db | |
| 340 | .query("INSERT INTO run (id, repo_id, kind, state, issue_id) VALUES ('r-doing-4', ?1, 'agent', 'running', 'i-doing-4')") | |
| 341 | .run(seed().repo); | |
| 342 | const home = await page(owner); | |
| 343 | expect(home).toContain("Working on: Current thing"); | |
| 344 | expect(home).not.toContain("Last change:"); | |
| 345 | child.db.query("DELETE FROM pull WHERE issue_id = 'i-doing-3'").run(); | |
| 346 | clean(); | |
| 347 | }); | |
| 348 | ||
| 349 | test("titles are cut to 80 characters at a word boundary", () => { | |
| 350 | const long = `${"word ".repeat(30)}end`; | |
| 351 | const cut = trimTitle(long); | |
| 352 | expect(cut.length).toBeLessThanOrEqual(81); | |
| 353 | expect(cut.endsWith("word…")).toBe(true); | |
| 354 | expect(trimTitle("Short")).toBe("Short"); | |
| 355 | }); | |
| 356 | ||
| 357 | test("a queued or finished run, or one with no issue, shows no Working on", async () => { | |
| 358 | issue("i-doing-5", 905, "Queued thing"); | |
| 359 | const { repo } = seed(); | |
| 360 | const run = (id: string, state: string, issueId: string | null): void => { | |
| 361 | child.db | |
| 362 | .query("INSERT INTO run (id, repo_id, kind, state, issue_id) VALUES (?1, ?2, 'agent', ?3, ?4)") | |
| 363 | .run(id, repo, state, issueId); | |
| 364 | }; | |
| 365 | run("r-doing-5", "queued", "i-doing-5"); | |
| 366 | run("r-doing-6", "ok", "i-doing-5"); | |
| 367 | run("r-doing-7", "running", null); | |
| 368 | expect(await page(owner)).not.toContain("Working on:"); | |
| 369 | clean(); | |
| 370 | }); | |
| 371 | ||
| 372 | test("the terminal says the same, and the line is muted on the page", async () => { | |
| 373 | issue("i-doing-6", 906, "Terminal thing"); | |
| 374 | child.db | |
| 375 | .query("INSERT INTO run (id, repo_id, kind, state, issue_id) VALUES ('r-doing-8', ?1, 'agent', 'running', 'i-doing-6')") | |
| 376 | .run(seed().repo); | |
| 377 | expect(await page(owner)).toContain('class="client-app-doing muted"'); | |
| 378 | const maria = getUserByName(child.db, "maria")!; | |
| 379 | const terminal = headlessTerminal(120, 30); | |
| 380 | const { app } = createForgeApp( | |
| 381 | child, | |
| 382 | { sshUsername: "maria", remoteAddress: "127.0.0.1", fingerprint: "SHA256:t", user: maria }, | |
| 383 | { terminal, exitHooks: false }, | |
| 384 | ); | |
| 385 | app.start(); | |
| 386 | await settleApp(app); | |
| 387 | expect(app.screen.toText()).toContain("Working on: Terminal thing"); | |
| 388 | app.stop(); | |
| 389 | clean(); | |
| 390 | }); | |
| 391 | ||
| 392 | test("with two runs going the newest wins; an unreadable start time falls back to now", async () => { | |
| 393 | issue("i-doing-9", 909, "Older thing"); | |
| 394 | issue("i-doing-10", 910, "Newer thing"); | |
| 395 | const { repo } = seed(); | |
| 396 | const run = (id: string, issueId: string, at: string): void => { | |
| 397 | child.db | |
| 398 | .query("INSERT INTO run (id, repo_id, kind, state, issue_id, started_at) VALUES (?1, ?2, 'agent', 'running', ?3, ?4)") | |
| 399 | .run(id, repo, issueId, at); | |
| 400 | }; | |
| 401 | run("r-doing-9", "i-doing-9", "2026-01-01T00:00:00.000Z"); | |
| 402 | run("r-doing-10", "i-doing-10", "2026-01-02T00:00:00.000Z"); | |
| 403 | const home = await page(owner); | |
| 404 | expect(home).toContain("Working on: Newer thing"); | |
| 405 | expect(home).not.toContain("Older thing"); | |
| 406 | child.db.query("DELETE FROM run WHERE id = 'r-doing-10'").run(); | |
| 407 | child.db.query("UPDATE run SET started_at = 'not a date' WHERE id = 'r-doing-9'").run(); | |
| 408 | const doings = clientDoings(child, [repo]); | |
| 409 | expect(doings.get(repo)?.title).toBe("Older thing"); | |
| 410 | expect(Math.abs((doings.get(repo)?.at ?? 0) - Date.now())).toBeLessThan(5000); | |
| 411 | clean(); | |
| 412 | }); | |
| 413 | ||
| 414 | test("each app's sentences stack, one to a line", () => { | |
| 415 | expect(studioCss).toMatch(/\.client-app\s*\{[^}]*display:\s*grid/); | |
| 416 | }); | |
| 417 | ||
| 418 | test("the read is its own Server-Timing phase", async () => { | |
| 419 | const res = await fetch(url("/"), { headers: { cookie: owner } }); | |
| 420 | expect(res.headers.get("server-timing") ?? "").toContain("doing"); | |
| 421 | }); | |
| 422 | }); | |
| 423 | ||
| 282 | 424 | test("the terminal's first screen says the same about each app", async () => { |
| 283 | 425 | const maria = getUserByName(child.db, "maria")!; |
| 284 | 426 | const terminal = headlessTerminal(120, 30); |
new above
offline