Public: anyone can read this; the crew can change it.

A client's first login shows the crew working and three next steps, in plain words, proven by a test #14535

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/14483-a-client-s-first-login-shows-the-crew-wo → main 0 commits fork 5 threads · 5 unresolved

  • Merged. scout/14483-a-client-s-first-login-shows-the-crew-wo was merged into main as a880210.

Review

Sign in to review this change.
9 files changed +226 −20
docs/features/client-app-line.md +11
@@ -13,8 +13,19 @@ each app.
1313 developer words.
1414 - `Waiting for your answer` when the crew has finished something that waits for a person.
1515 - `About to start` when work is lined up and nothing runs yet.
16 - `Waiting for your first ask` when no run was ever made for the app, so the line is never blank.
1617 - `Nothing in progress` otherwise.
1718
19 Below the apps the first page offers buttons: Ask for a change, See what shipped, and, for a forge
20 admin only (inviting is theirs), Invite someone. One module words them for both doors
21 (`src/actions/client_next.ts`): the terminal home ends with the same steps as keys (`t`, `w`, `i`),
22 `w` opening the changelog and `i` the invite links (`test/client-first-login.test.ts`, and driven on
23 the terminal screen in `test/client-home.test.ts`).
24
25 The issue asks for three buttons; a client who is not a forge admin sees two, on purpose. Inviting
26 is a forge admin's alone (`src/actions/invites.ts`), so a third button would open a page that refuses
27 them. A real invite door for clients is its own change.
28
1829 One module words it, `src/actions/client_line.ts` (`clientLines`: three reads for any number of
1930 apps, plus the review waits); the page, the terminal and `forge_view` all call it, so they cannot
2031 disagree (`test/client-home.test.ts`, `test/client-line.test.ts`).
src/actions/client_line.ts +14 −10
@@ -14,6 +14,7 @@ import { reviewWaitsFor } from "../crew/review.ts";
1414
1515 export const IDLE_LINE = "Nothing in progress";
1616 export const WAITING_LINE = "Waiting for your answer";
17 export const FIRST_ASK_LINE = "Waiting for your first ask";
1718 export const QUEUED_LINE = "About to start";
1819
1920 /** What is in hand on an app, as counts and the running title: the sentence's whole input. */
@@ -21,6 +22,8 @@ export interface CrewState {
2122 readonly title: string | undefined;
2223 readonly waitingOnPerson: boolean;
2324 readonly queued: boolean;
25 /** No run has ever been made for the app: nothing was asked yet. */
26 readonly neverRun?: boolean;
2427 }
2528
2629 /** The sentence for one app's state; the running work comes first, then a wait on the person. */
@@ -30,7 +33,8 @@ export function lineFor(state: CrewState): string {
3033 return said === "" ? "Building something new" : `Building: ${said}`;
3134 }
3235 if (state.waitingOnPerson) return WAITING_LINE;
33 return state.queued ? QUEUED_LINE : IDLE_LINE;
36 if (state.queued) return QUEUED_LINE;
37 return state.neverRun === true ? FIRST_ASK_LINE : IDLE_LINE;
3438 }
3539
3640 /** One sentence for each of `repos`, in two reads for the whole set plus the review waits. */
@@ -40,14 +44,14 @@ export function clientLines(db: Database, repos: readonly Repo[]): Map<string, s
4044 const ids = repos.map((r) => r.id);
4145 const doing = clientDoings(db, ids);
4246 const marks = ids.map((_, i) => `?${i + 1}`).join(",");
43 const queued = new Set(
44 db
45 .query<{ repo_id: string }, string[]>(
46 `SELECT DISTINCT repo_id FROM run WHERE kind = 'agent' AND state = 'queued' AND repo_id IN (${marks})`,
47 )
48 .all(...ids)
49 .map((r) => r.repo_id),
50 );
47 // One read gives both: which apps have ever run, and which have an agent run queued.
48 const runs = db
49 .query<{ repo_id: string; queued: number }, string[]>(
50 `SELECT repo_id, MAX(kind = 'agent' AND state = 'queued') AS queued FROM run WHERE repo_id IN (${marks}) GROUP BY repo_id`,
51 )
52 .all(...ids);
53 const ran = new Set(runs.map((r) => r.repo_id));
54 const queued = new Set(runs.filter((r) => r.queued === 1).map((r) => r.repo_id));
5155 const byId = new Map(repos.map((r) => [r.id, r]));
5256 const pulls = joinMany(db, listOpenPullsOf(db, ids)).flatMap((pull) => {
5357 const repo = byId.get(pull.repoId);
@@ -58,7 +62,7 @@ export function clientLines(db: Database, repos: readonly Repo[]): Map<string, s
5862 for (const repo of repos)
5963 out.set(
6064 repo.id,
61 lineFor({ title: doing.get(repo.id)?.title, waitingOnPerson: waiting.has(repo.id), queued: queued.has(repo.id) }),
65 lineFor({ title: doing.get(repo.id)?.title, waitingOnPerson: waiting.has(repo.id), queued: queued.has(repo.id), neverRun: !ran.has(repo.id) }),
6266 );
6367 return out;
6468 }
src/actions/client_next.ts added +25
@@ -0,0 +1,25 @@
1 /**
2 * The next steps under a client's apps (#14483), worded once for both doors: the page draws them
3 * as buttons, the terminal as keys. Inviting is a forge admin's alone (`actions/invites.ts`), so
4 * anyone else is not offered it: no button that leads nowhere.
5 */
6
7 import type { User } from "../core/users.ts";
8
9 export interface NextStep {
10 readonly label: string;
11 /** The page it opens. */
12 readonly href: string;
13 /** The terminal key. */
14 readonly key: string;
15 }
16
17 export function clientNextSteps(user: User | undefined): NextStep[] {

Good shared module. Add that a client sees two steps on purpose to the feature doc, since the issue says three.

18 const steps: NextStep[] = [
19 { label: "Ask for a change", href: "/tell", key: "t" },
20 { label: "See what shipped", href: "/changelog", key: "w" },
21 ];
22 if (user?.isAdmin === true && user.kind === "user")
23 steps.push({ label: "Invite someone", href: "/admin/limits", key: "i" });
24 return steps;
25 }
src/tui/screens/dashboard.ts +30 −2
@@ -32,6 +32,9 @@ import { askRepos, askStatus, askStatusLine } from "../../core/ask-status.ts";
3232 import { AUTONOMY_FAILED_WORDS, firstAsk } from "../../actions/first_ask.ts";
3333 import { SAY_SOMETHING_WORDS } from "../../actions/tell_words.ts";
3434 import { crewCanRun, crewFirstText } from "../../web/studio/crew_key.ts";
35 import { clientNextSteps } from "../../actions/client_next.ts";
36 import { changelogScreen } from "./changelog.ts";
37 import { invitesScreen } from "./invites.ts";
3538 import { clientLines as crewSentences, IDLE_LINE } from "../../actions/client_line.ts";
3639 import { lastVisit } from "../../core/home_visit.ts";
3740 import { quietFor, quietText } from "../../web/studio/home_empty.ts";
@@ -144,12 +147,21 @@ import { repoScreen } from "./repo.ts";
144147 import { local } from "./where.ts";
145148 import { signInScreen } from "./signin.ts";
146149
147 /** Rows the list keeps under the figures strip; below it the strip shows fewer figures. */
148150 /** The first line of a new forge's home, as the page's heading and its one box. */
149151 const FIRST_TELL_LINE = "What do you want built? t says it to the crew.";
150152
153 /** Rows the list keeps under the figures strip; below it the strip shows fewer figures. */
151154 const FIGURES_ROOM = 6;
152155
156 /**
157 * The next steps as keys: `t ask for a change · w see what shipped`, plus `i invite someone` for an
158 * admin.
159 */
160 const nextStepsLine = (user: Session["user"]): string =>
161 clientNextSteps(user)
162 .map((s) => `${s.key} ${s.label.toLowerCase()}`)
163 .join(" · ");
164
153165 /**
154166 * The forge-wide daily ceiling, from config, for the spend figure; the data directory, for the
155167 * backup's age.
@@ -431,6 +443,7 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
431443 return `${line}${` ${doing}`} ${crew[0]!.toUpperCase()}${crew.slice(1)}.`;
432444 });
433445 if (asked) clientLines = [askStatusLine(asked), ...clientLines];
446 clientLines.push(nextStepsLine(f.user));
434447 ctx.invalidate();
435448 };
436449
@@ -1219,6 +1232,12 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
12191232 : clientLines.length > 0
12201233 ? [binding(["t"], "ask for something")]
12211234 : []),
1235 ...(clientLines.length > 0 && !firstTell
1236 ? [
1237 binding(["w"], "see what shipped"),
1238 ...(clientNextSteps(f.user).some((s) => s.key === "i") ? [binding(["i"], "invite someone")] : []),
1239 ]
1240 : []),
12221241 ...(clientLive.size > 0 ? [binding(["o"], "open the app")] : []),
12231242 ...(exploring() && explored?.next != null
12241243 ? [binding(["n"], "more results")]
@@ -1264,7 +1283,8 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
12641283 body = rest!;
12651284 }
12661285 if (clientLines.length > 0) {
1267 const lines = clientLines.slice(0, 5);
1286 // The next steps are the last line and always stay.
1287 const lines = clientLines.length > 5 ? [...clientLines.slice(0, 4), clientLines.at(-1)!] : clientLines;
12681288 const [strip, rest] = split(body, "v", [len(lines.length), fill(1)]);
12691289 lines.forEach((line, i) =>
12701290 s.text(
@@ -1511,6 +1531,14 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
15111531 if (repo && clientRepoIds.has(repo.id)) askForSomething(f, ctx, () => screen, repo);
15121532 return true;
15131533 }
1534 if (e.key === "w" && f.user && clientLines.length > 0 && !firstTell) {
1535 ctx.push(changelogScreen(f, ctx));
1536 return true;
1537 }
1538 if (e.key === "i" && f.user && clientLines.length > 0 && !firstTell && clientNextSteps(f.user).some((s) => s.key === "i")) {
1539 ctx.push(invitesScreen(f, ctx));
1540 return true;
1541 }
15141542 if (e.key === "o" && f.user && clientLive.size > 0) {
15151543 // The running app under the cursor, as a link the person can open or copy.
15161544 const repo = shown()[at("repos").index];
src/web/studio/client_home.ts +9
@@ -6,6 +6,7 @@
66 * stay off it; `test/client-home.test.ts` holds the list.
77 */
88
9 import { clientNextSteps as nextSteps } from "../../actions/client_next.ts";
910 import { clientLines } from "../../actions/client_line.ts";
1011 import { lastChangeLine } from "../../story/last_change.ts";
1112 import { notePhase, takeSessionTime, timePhase, timePhaseAsync } from "../../core/route_timing.ts";
@@ -68,3 +69,11 @@ export async function clientApps(ctx: Ctx, user: User): Promise<Html> {
6869 notePhase(ctx.request, "render", performance.now() - rendering);
6970 return shown;
7071 }
72
outdated

Both doors: this section has no terminal counterpart in src/tui/. A client in the terminal cannot ask, see what shipped, or invite. Add the screen entry and cover it in the test.

73 /** The next steps under the apps, as buttons; plain words, one door each, no heading. */
outdated

Principle 1: the 'What next?' heading explains what the three buttons already say; drop it or make it the single sentence of purpose.

74 export function clientNextSteps(user: User | undefined): Html {
75 const steps = nextSteps(user);
76 return html`<div id="client-next" class="bar">
77 ${steps.map((s, i) => btn(s.label, { href: s.href, variant: i === 0 ? "primary" : "outline" }))}
outdated

Invite someone -> /admin/limits is admin-only (404 for a non-admin client) and is not where invites are made. Link a door every client can use, or omit the button. Principle 1/8: a button that dead-ends is not plain.

78 </div>`;
79 }
src/web/studio/home.ts +2 −2
@@ -95,7 +95,7 @@ import { claimedDoor } from "./door_claimed.ts";
9595 import { readableNotes } from "../../actions/desk.ts";
9696 import { deskStrip } from "../desk_strip.ts";
9797 import { startedFromLine } from "../started_from.ts";
98 import { clientApps } from "./client_home.ts";
98 import { clientApps, clientNextSteps } from "./client_home.ts";
9999
100100 /** The events that can change what is on you. */
101101 const ON_YOU_LIVE =
@@ -326,7 +326,7 @@ export async function studioHome(
326326 // Before the first tell the card is the one box and carries the key line and the composer.
327327 const firstTell = steps.some((s) => s.key === "tell" && !s.done);
328328 const lean = html`<h1 class="sr-only">Home</h1>
329 ${firstSteps} ${address} ${startedFromLine(ctx.app.db, ctx.app.config.dataDir, user)} ${firstTell ? null : composer(ctx, user)} ${apps} ${firstTell ? null : crewKeyCard(ctx)} ${heldLine(ctx, user)} ${focusLine(ctx, user)} ${everydayLine(steps)}
329 ${firstSteps} ${address} ${startedFromLine(ctx.app.db, ctx.app.config.dataDir, user)} ${firstTell ? null : composer(ctx, user)} ${apps} ${firstTell ? null : clientNextSteps(user)} ${firstTell ? null : crewKeyCard(ctx)} ${heldLine(ctx, user)} ${focusLine(ctx, user)} ${everydayLine(steps)}
330330 <div class="stack">
331331 <p class="small muted">
332332 <a href="/?all=1">Show everything</a>
test/client-first-login.test.ts added +69
@@ -0,0 +1,69 @@
1 /**

The terminal door is asserted by reading dashboard.ts as text. Replace it with a screen-driven test (press w, expect the changelog; assert the steps line; assert no i for a non-admin).

2 * A client's first login (#14483): apps with a plain crew line, three next steps, no developer
3 * words, fast.
4 */
5 import { beforeEach, describe, expect, test } from "bun:test";
6 import type { Database } from "bun:sqlite";
7 import { clientLines, FIRST_ASK_LINE, IDLE_LINE } from "../src/actions/client_line.ts";
8 import type { Repo } from "../src/core/repos.ts";
9 import { migrations } from "../src/core/schema.ts";
10 import { openDb } from "../src/kernel/db.ts";
11 import { clientNextSteps as nextSteps } from "../src/actions/client_next.ts";
12 import type { User } from "../src/core/users.ts";
13 import { clientNextSteps } from "../src/web/studio/client_home.ts";
14
15 let db: Database;
16 const repo = (id: string): Repo => ({ id }) as Repo;
17
18 beforeEach(() => {
19 db = openDb(":memory:", migrations);
20 db.run("INSERT INTO user (id, username, email, password_hash) VALUES ('u','u','u@x','x')");
21 for (const r of ["fresh", "done"]) db.run("INSERT INTO repo (id, owner_id, name) VALUES (?, 'u', ?)", [r, r]);
22 });
23
24 const JARGON = /\b(pull|pulls|branch|branches|commit|commits|CI)\b/i;
25
26 describe("the crew line", () => {
27 test("an app with no run says it waits for the first ask, never blank", () => {
28 const lines = clientLines(db, [repo("fresh")]);
29 expect(lines.get("fresh")).toBe(FIRST_ASK_LINE);
30 expect(FIRST_ASK_LINE).toBe("Waiting for your first ask");
31 });
32
33 test("an app whose runs are over says nothing is in progress", () => {
34 db.run("INSERT INTO run (id, repo_id, kind, state) VALUES ('r1','done','agent','ok')");
35 expect(clientLines(db, [repo("done")]).get("done")).toBe(IDLE_LINE);
36 });
37
38 test("no line uses the jargon", () => {
39 for (const line of clientLines(db, [repo("fresh"), repo("done")]).values()) expect(line).not.toMatch(JARGON);
40 });
41 });
42
43 const person = (isAdmin: boolean) => ({ isAdmin, kind: "user" }) as User;
44
45 describe("the next steps", () => {
46 test("a client is offered two buttons, no heading, no dead end", () => {
47 const out = String(clientNextSteps(person(false)));
48 expect(out).toContain("Ask for a change");
49 expect(out).toContain("See what shipped");
50 expect(out).not.toContain("Invite");
51 expect(out).not.toContain("/admin/limits");
52 expect(out).not.toContain("What next");
53 expect(out.replace(/<[^>]*>/g, " ")).not.toMatch(JARGON);
54 });
55
56 test("an admin is also offered Invite someone", () => {
57 const out = String(clientNextSteps(person(true)));
58 expect(out).toContain("Invite someone");
59 expect(out.match(/href=/g)?.length).toBe(3);
60 });
61
62 test("the terminal is handed the same steps as keys (driven on the screen in client-home.test.ts)", () => {
63 expect(nextSteps(person(false)).map((s) => `${s.key} ${s.label}`)).toEqual([
64 "t Ask for a change",
65 "w See what shipped",
66 ]);
67 expect(nextSteps(person(true)).map((s) => s.key)).toEqual(["t", "w", "i"]);
68 });
69 });
test/client-home.test.ts +64 −4
@@ -176,7 +176,7 @@ describe("a client's first screen", () => {
176176 const home = main(await page(owner));
177177 const apps = home.slice(home.indexOf('id="client-apps"'));
178178 expect(apps).toContain('href="/marias/bakery"');
179 expect(apps).toContain('client-app-line"><b>Nothing in progress</b>');
179 expect(apps).toContain('client-app-line"><b>Waiting for your first ask</b>');
180180 expect(apps).not.toContain("agents are");
181181 expect(apps).not.toContain("Working on");
182182 expect(words(apps)).not.toMatch(/\b(pull|check|run|gate)\b/i);
@@ -302,7 +302,7 @@ describe("a client's first screen", () => {
302302 );
303303 stopped.app.start();
304304 await settleApp(stopped.app);
305 expect(stopped.app.screen.toText()).toContain("bakery: Nothing in progress");
305 expect(stopped.app.screen.toText()).toContain("bakery: Waiting for your first ask");
306306 expect(stopped.app.screen.toText()).not.toContain("running");
307307 idle.feed("o");
308308 await settleApp(stopped.app);
@@ -333,6 +333,57 @@ describe("a client's first screen", () => {
333333 app.stop();
334334 });
335335
336 test("the terminal home ends with the next steps as keys, and w opens what shipped (#14483)", async () => {
337 const maria = getUserByName(child.db, "maria")!;
338 const open = async (user: typeof maria) => {
339 const terminal = headlessTerminal(120, 30);
340 const { app } = createForgeApp(
341 child,
342 { sshUsername: "maria", remoteAddress: "127.0.0.1", fingerprint: "SHA256:t", user },
343 { terminal, exitHooks: false },
344 );
345 app.start();
346 await settleApp(app);
347 return { app, terminal };
348 };
349
350 // A client who is not a forge admin (the owner's everyday account): two steps, no `i`, and `i`
351 // does nothing.
352 const daily = await createUser(child.db, {
353 origin: "seed",
354 trusted: true,
355 username: "mariasteps",
356 email: "[email protected]",
357 password: PASSWORD,
358 });
359 if (!daily.ok) throw new Error(JSON.stringify(daily.error));
360 linkEveryday(child.db, maria, daily.value);
361 expect(daily.value.isAdmin).toBe(false);
362 const client = await open(daily.value);
363 const shown = client.app.screen.toText();
364 const steps = shown.split("\n").filter((l) => l.includes("t ask for a change"));
365 expect(steps.length).toBe(1);
366 expect(steps[0]!.trim()).toBe("t ask for a change · w see what shipped");
367 expect(shown).not.toContain("i invite someone");
368 client.terminal.feed("i");
369 await settleApp(client.app);
370 expect(client.app.screen.toText()).not.toContain("Invite links");
371 client.terminal.feed("w");
372 await settleApp(client.app);
373 expect(client.app.screen.toText()).toContain("Changelog");
374 expect(client.app.screen.toText()).not.toContain("t ask for a change");
375 client.app.stop();
376
377 // A forge admin gets the third step, and `i` opens the invite links.
378 expect(maria.isAdmin).toBe(true);
379 const admin = await open(maria);
380 expect(admin.app.screen.toText()).toContain("t ask for a change · w see what shipped · i invite someone");
381 admin.terminal.feed("i");
382 await settleApp(admin.app);
383 expect(admin.app.screen.toText()).toContain("Invite links");
384 admin.app.stop();
385 });
386
336387
337388 /**
338389 * A running agent run on an open issue of the bakery: the one thing the sentence says it builds.
@@ -379,6 +430,15 @@ describe("a client's first screen", () => {
379430 expect(text).not.toMatch(new RegExp(`\\b${word}`, "i"));
380431 });
381432
433 test("three next steps sit below the apps, and the first page has no jargon", async () => {
434 const raw = await page(owner);
435 const home = main(raw);
436 expect(home.indexOf('id="client-next"')).toBeGreaterThan(home.indexOf('id="client-apps"'));
437 const text = words(raw);
438 for (const label of ["Ask for a change", "See what shipped", "Invite someone"]) expect(text).toContain(label);
439 for (const word of ["pull", "branch", "commit", "CI"]) expect(text).not.toMatch(new RegExp(`\\b${word}`, "i"));
440 });
441
382442 test("asked for, the whole home is still there", async () => {
383443 const home = await page(owner, "/?all=1");
384444 expect(home).toContain('id="lane-building"');
@@ -472,7 +532,7 @@ describe("a client's first screen", () => {
472532 );
473533 app.start();
474534 await settleApp(app);
475 expect(app.screen.toText()).toContain("bakery: Nothing in progress.");
535 expect(app.screen.toText()).toContain("bakery: Waiting for your first ask.");
476536 expect(app.screen.toText()).toMatch(/Atlas is ready to work toward Run Maria/);
477537 expect(app.screen.toText()).not.toContain("Shipped per hour");
478538 app.stop();
@@ -554,7 +614,7 @@ describe("a client's first screen", () => {
554614
555615 test("a quiet app gets no extra line", async () => {
556616 clean();
557 expect(await row()).toContain("Nothing in progress");
617 expect(await row()).toContain("Waiting for your first ask");
558618 });
559619
560620 test("work running now reads Working on, escaped", async () => {
test/client-line.test.ts +2 −2
@@ -18,13 +18,13 @@ beforeEach(() => {
1818 });
1919
2020 describe("the sentence", () => {
21 test("a running app says Building, an idle one says Nothing in progress, in words a client reads", () => {
21 test("a running app says Building, an app never asked says Waiting for your first ask, in words a client reads", () => {
2222 db.run("INSERT INTO issue (id, repo_id, number, kind, title, author_id, state) VALUES ('i1','busy',1,'issue','the booking form (see PR #42)','u','open')");
2323 db.run("INSERT INTO run (id, repo_id, kind, state, issue_id) VALUES ('r1','busy','agent','running','i1')");
2424 db.run("INSERT INTO run (id, repo_id, kind, state) VALUES ('r2','next','agent','queued')");
2525 const lines = clientLines(db, [repo("busy"), repo("idle"), repo("next")]);
2626 expect(lines.get("busy")).toBe("Building: the booking form");
27 expect(lines.get("idle")).toBe("Nothing in progress");
27 expect(lines.get("idle")).toBe("Waiting for your first ask");
2828 expect(lines.get("next")).toBe(QUEUED_LINE);
2929 for (const line of lines.values()) expect(line).not.toMatch(/\b(pull|check|run|gate)\b/i);
3030 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs