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 #1738

Closed opened this
Closed without merging

scout/forge:scout/1607-a-client-s-first-screen-speaks-plain-wor → main 2 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
4 files changed +125 −1
src/web/pages/next-steps.ts +1 −1
@@ -111,7 +111,7 @@ export async function nextStepsCard(
111111 Say what you want in one sentence, in the box below; the crew takes it
112112 from there.
113113 ${btn("Tell the crew", {
114 href: "#composer",
114 href: "/?all#composer",
115115 size: "sm",
116116 ...(primary === "tell" ? { variant: "primary" as const } : {}),
117117 })}
src/web/pages/plain-home.ts added +96
@@ -0,0 +1,96 @@
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 { crewKeyNote } from "../studio/crew.ts";
18 import { nextStepsCard } from "./next-steps.ts";
19
20 export interface AgentWork {
21 readonly working: number;
22 readonly waiting: number;
23 }
24
25 /** Agent runs under way and queued, per app, from one grouped read. */
26 export function agentWork(
27 ctx: Ctx,
28 repos: readonly Repo[],
29 ): ReadonlyMap<string, AgentWork> {
30 const out = new Map<string, AgentWork>();
31 if (repos.length === 0) return out;
32 const rows = ctx.app.db
33 .query<{ repo_id: string; state: string; n: number }, string[]>(
34 `SELECT repo_id, state, COUNT(*) AS n FROM run
35 WHERE kind = 'agent' AND state IN ('running','queued')
36 AND repo_id IN (${repos.map((_, i) => `?${i + 1}`).join(",")})
37 GROUP BY repo_id, state`,
38 )
39 .all(...repos.map((r) => r.id));
40 for (const row of rows) {
41 const was = out.get(row.repo_id) ?? { working: 0, waiting: 0 };
42 out.set(
43 row.repo_id,
44 row.state === "running"
45 ? { ...was, working: row.n }
46 : { ...was, waiting: row.n },
47 );
48 }
49 return out;
50 }
51
52 const agents = (n: number): string => `${n} ${n === 1 ? "agent" : "agents"}`;
53
54 /** What the agents of one app are doing, as a sentence. */
55 export function workSentence(work: AgentWork | undefined): string {
56 if (work === undefined || (work.working === 0 && work.waiting === 0))
57 return "Its agents are waiting for something to do.";
58 const parts: string[] = [];
59 if (work.working > 0)
60 parts.push(`${agents(work.working)} ${work.working === 1 ? "is" : "are"} working on it`);
61 if (work.waiting > 0)
62 parts.push(`${agents(work.waiting)} ${work.waiting === 1 ? "is" : "are"} waiting for a turn`);
63 const text = parts.join(", ");
64 return `${text.charAt(0).toUpperCase()}${text.slice(1)}.`;
65 }
66
67 /** Whether `/` shows the plain screen: the owner of a spawned forge, who has not asked for everything. */
68 export async function wantsPlainHome(ctx: Ctx, user: User): Promise<boolean> {
69 if (ctx.url.searchParams.has("all")) return false;
70 return (await nextStepsFor(ctx.app, user)) !== undefined;
71 }
72
73 export async function plainHome(ctx: Ctx, user: User): Promise<Response> {
74 const repos = await spawnedRepos(ctx.app, user);
75 const work = agentWork(ctx, repos);
76 const steps = await nextStepsCard(ctx, user);
77 const body = html`<h1>Your apps</h1>
78 ${steps} ${crewKeyNote(ctx)}
79 ${repos.length === 0
80 ? html`<p class="muted">Your apps arrive here as the crew sets them up.</p>`
81 : html`<ul class="list plain-apps">
82 ${repos.map(
83 (repo) => html`<li class="plain-app">
84 <a href="/${repo.ownerName}/${repo.name}"><b>${repo.name}</b></a>
85 <p>
86 ${repo.description !== ""
87 ? repo.description
88 : "The crew is still describing this one."}
89 </p>
90 <p class="muted small">${workSentence(work.get(repo.id))}</p>
91 </li>`,
92 )}
93 </ul>`}
94 <p class="small"><a href="/?all">Everything</a></p>`;
95 return page({ ctx, title: "Your apps", body, bare: true });
96 }
src/web/pages/site.ts +2
@@ -32,6 +32,7 @@ import { hasAnyUser, verifyPassword, type User } from "../../core/users.ts";
3232 import { isThemeName } from "../../design/themes.ts";
3333 import { cookieValue, crossOrigin, type Ctx } from "../../http/context.ts";
3434 import { studioDoor, studioHome } from "../studio/home.ts";
35 import { plainHome, wantsPlainHome } from "./plain-home.ts";
3536 import { homeTop, onYouBulk } from "../studio/asks_page.ts";
3637 import { latestUndoable } from "../../actions/asks_bulk.ts";
3738 import { mutedRepos } from "../../core/interactions.ts";
@@ -323,6 +324,7 @@ export function terminalCard(ctx: Ctx): Html {
323324 export async function home(ctx: Ctx): Promise<Response> {
324325 const user = ctx.auth.user;
325326 if (user === undefined) return studioDoor(ctx);
327 if (await wantsPlainHome(ctx, user)) return await plainHome(ctx, user);
326328 return await studioHome(ctx, user, homeTop(ctx));
327329 }
328330
test/first-login.test.ts +26
@@ -25,6 +25,7 @@ import { repoDir } from "../src/git/repos.ts";
2525 import { serve, type Servers } from "../src/http/server.ts";
2626 import { firstBoot } from "../src/spawn/first-boot.ts";
2727 import { hostedPlacement } from "../src/spawn/placement.ts";
28 import { workSentence } from "../src/web/pages/plain-home.ts";
2829 import { quietLogs } from "./helpers/globals.ts";
2930
3031 quietLogs();
@@ -214,6 +215,31 @@ describe("the first login to a spawned forge", () => {
214215 expect(home).toContain('href="/marias/bakery"');
215216 });
216217
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
217243 test("the everyday account, made first, joins the client's org and sees the card part-way, every step one it can do", async () => {
218244 const res = await post(owner, "/settings/everyday", {
219245 username: "maria-me",

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs