Public: anyone can read this; the crew can change it.
A client's first screen speaks plain words: their apps, each in a sentence, and whether its agents are working or waiting #1735
scout/forge:scout/1607-a-client-s-first-screen-speaks-plain-wor → main 1 commit fork
4 files
changed +124
−1
src/web/pages/next-steps.ts +1 −1
| @@ -111,7 +111,7 @@ export async function nextStepsCard( | ||
| 111 | 111 | Say what you want in one sentence, in the box below; the crew takes it |
| 112 | 112 | from there. |
| 113 | 113 | ${btn("Tell the crew", { |
| 114 | href: "#composer", | |
| 114 | href: "/?all#composer", | |
| 115 | 115 | size: "sm", |
| 116 | 116 | ...(primary === "tell" ? { variant: "primary" as const } : {}), |
| 117 | 117 | })} |
src/web/pages/plain-home.ts added +95
| @@ -0,0 +1,95 @@ | ||
| 1 | /** | |
| 2 | * The first screen of a person who came in through a claim link (#1607): | |
| 3 | * their apps, each in a sentence, and whether its agents are working or | |
| 4 | * waiting — in plain words. No map, no board, no settings, no menu of | |
| 5 | * the forge's parts; one link, "Everything", is the way to the full home | |
| 6 | * (`/?all`) when they ask. Only on a spawned forge, only for its owner | |
| 7 | * (`core/next-steps.ts` knows who that is). The first-steps card, while | |
| 8 | * it has steps left, sits above the apps. | |
| 9 | */ | |
| 10 | ||
| 11 | import { nextStepsFor, spawnedRepos } from "../../core/next-steps.ts"; | |
| 12 | import type { Repo } from "../../core/repos.ts"; | |
| 13 | import type { User } from "../../core/users.ts"; | |
| 14 | import type { Ctx } from "../../http/context.ts"; | |
| 15 | import { html, type Html } from "../html.ts"; | |
| 16 | import { page } from "../layout.ts"; | |
| 17 | import { nextStepsCard } from "./next-steps.ts"; | |
| 18 | ||
| 19 | export interface AgentWork { | |
| 20 | readonly working: number; | |
| 21 | readonly waiting: number; | |
| 22 | } | |
| 23 | ||
| 24 | /** Agent runs under way and queued, per app, from one grouped read. */ | |
| 25 | export function agentWork( | |
| 26 | ctx: Ctx, | |
| 27 | repos: readonly Repo[], | |
| 28 | ): ReadonlyMap<string, AgentWork> { | |
| 29 | const out = new Map<string, AgentWork>(); | |
| 30 | if (repos.length === 0) return out; | |
| 31 | const rows = ctx.app.db | |
| 32 | .query<{ repo_id: string; state: string; n: number }, string[]>( | |
| 33 | `SELECT repo_id, state, COUNT(*) AS n FROM run | |
| 34 | WHERE kind = 'agent' AND state IN ('running','queued') | |
| 35 | AND repo_id IN (${repos.map((_, i) => `?${i + 1}`).join(",")}) | |
| 36 | GROUP BY repo_id, state`, | |
| 37 | ) | |
| 38 | .all(...repos.map((r) => r.id)); | |
| 39 | for (const row of rows) { | |
| 40 | const was = out.get(row.repo_id) ?? { working: 0, waiting: 0 }; | |
| 41 | out.set( | |
| 42 | row.repo_id, | |
| 43 | row.state === "running" | |
| 44 | ? { ...was, working: row.n } | |
| 45 | : { ...was, waiting: row.n }, | |
| 46 | ); | |
| 47 | } | |
| 48 | return out; | |
| 49 | } | |
| 50 | ||
| 51 | const agents = (n: number): string => `${n} ${n === 1 ? "agent" : "agents"}`; | |
| 52 | ||
| 53 | /** What the agents of one app are doing, as a sentence. */ | |
| 54 | export function workSentence(work: AgentWork | undefined): string { | |
| 55 | if (work === undefined || (work.working === 0 && work.waiting === 0)) | |
| 56 | return "Its agents are waiting for something to do."; | |
| 57 | const parts: string[] = []; | |
| 58 | if (work.working > 0) | |
| 59 | parts.push(`${agents(work.working)} ${work.working === 1 ? "is" : "are"} working on it`); | |
| 60 | if (work.waiting > 0) | |
| 61 | parts.push(`${agents(work.waiting)} ${work.waiting === 1 ? "is" : "are"} waiting for a turn`); | |
| 62 | const text = parts.join(", "); | |
| 63 | return `${text.charAt(0).toUpperCase()}${text.slice(1)}.`; | |
| 64 | } | |
| 65 | ||
| 66 | /** Whether `/` shows the plain screen: the owner of a spawned forge, who has not asked for everything. */ | |
| 67 | export async function wantsPlainHome(ctx: Ctx, user: User): Promise<boolean> { | |
| 68 | if (ctx.url.searchParams.has("all")) return false; | |
| 69 | return (await nextStepsFor(ctx.app, user)) !== undefined; | |
| 70 | } | |
| 71 | ||
| 72 | export async function plainHome(ctx: Ctx, user: User): Promise<Response> { | |
| 73 | const repos = await spawnedRepos(ctx.app, user); | |
| 74 | const work = agentWork(ctx, repos); | |
| 75 | const steps = await nextStepsCard(ctx, user); | |
| 76 | const body = html`<h1>Your apps</h1> | |
| 77 | ${steps} | |
| 78 | ${repos.length === 0 | |
| 79 | ? html`<p class="muted">Your apps arrive here as the crew sets them up.</p>` | |
| 80 | : html`<ul class="list plain-apps"> | |
| 81 | ${repos.map( | |
| 82 | (repo) => html`<li class="plain-app"> | |
| 83 | <a href="/${repo.ownerName}/${repo.name}"><b>${repo.name}</b></a> | |
| 84 | <p> | |
| 85 | ${repo.description !== "" | |
| 86 | ? repo.description | |
| 87 | : "The crew is still describing this one."} | |
| 88 | </p> | |
| 89 | <p class="muted small">${workSentence(work.get(repo.id))}</p> | |
| 90 | </li>`, | |
| 91 | )} | |
| 92 | </ul>`} | |
| 93 | <p class="small"><a href="/?all">Everything</a></p>`; | |
| 94 | return page({ ctx, title: "Your apps", body, bare: true }); | |
| 95 | } |
src/web/pages/site.ts +2
| @@ -32,6 +32,7 @@ import { hasAnyUser, verifyPassword, type User } from "../../core/users.ts"; | ||
| 32 | 32 | import { isThemeName } from "../../design/themes.ts"; |
| 33 | 33 | import { cookieValue, crossOrigin, type Ctx } from "../../http/context.ts"; |
| 34 | 34 | import { studioDoor, studioHome } from "../studio/home.ts"; |
| 35 | import { plainHome, wantsPlainHome } from "./plain-home.ts"; | |
| 35 | 36 | import { homeTop, onYouBulk } from "../studio/asks_page.ts"; |
| 36 | 37 | import { latestUndoable } from "../../actions/asks_bulk.ts"; |
| 37 | 38 | import { mutedRepos } from "../../core/interactions.ts"; |
| @@ -323,6 +324,7 @@ export function terminalCard(ctx: Ctx): Html { | ||
| 323 | 324 | export async function home(ctx: Ctx): Promise<Response> { |
| 324 | 325 | const user = ctx.auth.user; |
| 325 | 326 | if (user === undefined) return studioDoor(ctx); |
| 327 | if (await wantsPlainHome(ctx, user)) return await plainHome(ctx, user); | |
| 326 | 328 | return await studioHome(ctx, user, homeTop(ctx)); |
| 327 | 329 | } |
| 328 | 330 |
test/first-login.test.ts +26
| @@ -25,6 +25,7 @@ import { repoDir } from "../src/git/repos.ts"; | ||
| 25 | 25 | import { serve, type Servers } from "../src/http/server.ts"; |
| 26 | 26 | import { firstBoot } from "../src/spawn/first-boot.ts"; |
| 27 | 27 | import { hostedPlacement } from "../src/spawn/placement.ts"; |
| 28 | import { workSentence } from "../src/web/pages/plain-home.ts"; | |
| 28 | 29 | import { quietLogs } from "./helpers/globals.ts"; |
| 29 | 30 | |
| 30 | 31 | quietLogs(); |
| @@ -214,6 +215,31 @@ describe("the first login to a spawned forge", () => { | ||
| 214 | 215 | expect(home).toContain('href="/marias/bakery"'); |
| 215 | 216 | }); |
| 216 | 217 | |
| 218 | test("the first screen speaks plain words: each app in a sentence, its agents working or waiting, none of the forge's parts", async () => { | |
| 219 | const raw = await (await fetch(url("/"), { headers: { cookie: owner } })).text(); | |
| 220 | const main = (/<main[\s\S]*<\/main>/.exec(raw)?.[0] ?? "") | |
| 221 | .replace(/<(script|style)[\s\S]*?<\/\1>/g, "") | |
| 222 | .replace(/<[^>]*>/g, " ") | |
| 223 | .replace(/\s+/g, " "); | |
| 224 | expect(main).toContain("bakery"); | |
| 225 | expect(main).toContain("Its agents are waiting for something to do."); | |
| 226 | for (const word of ["pull", "branch", "commit", "merge", "CI", "repository"]) | |
| 227 | expect(main).not.toMatch(new RegExp(`\\b${word}`, word === "CI" ? "" : "i")); | |
| 228 | for (const href of ['"/map"', '"/board"', '"/settings', '"/audit"']) | |
| 229 | expect(raw).not.toContain(`href=${href}`); | |
| 230 | // Asked for, the full home is still there. | |
| 231 | const all = await (await fetch(url("/?all"), { headers: { cookie: owner } })).text(); | |
| 232 | expect(all).toContain('href="/map"'); | |
| 233 | }); | |
| 234 | ||
| 235 | test("agents at work on an app are counted in a sentence", () => { | |
| 236 | expect(workSentence(undefined)).toBe("Its agents are waiting for something to do."); | |
| 237 | expect(workSentence({ working: 1, waiting: 2 })).toBe( | |
| 238 | "1 agent is working on it, 2 agents are waiting for a turn.", | |
| 239 | ); | |
| 240 | expect(workSentence({ working: 0, waiting: 1 })).toBe("1 agent is waiting for a turn."); | |
| 241 | }); | |
| 242 | ||
| 217 | 243 | test("the everyday account, made first, joins the client's org and sees the card part-way, every step one it can do", async () => { |
| 218 | 244 | const res = await post(owner, "/settings/everyday", { |
| 219 | 245 | username: "maria-me", |
new above
offline