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

A person who opens a forge link for the first time sees three next steps, proven by a test with a link login #16010

Merged opened this

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

Merged

scout/forge:scout/15972-a-person-who-opens-a-forge-link-for-the → main 0 commits fork 3 threads · 3 unresolved

  • Merged. scout/15972-a-person-who-opens-a-forge-link-for-the was merged into main as 4bddee7.

Review

Sign in to review this change.
8 files changed +138 −5
docs/features/first-steps.md added +11
@@ -0,0 +1,11 @@
1 ---
2 topic: What a forge is
3 row: The steps still undone on a forge link's first page
4 ---
5 # The steps still undone on a forge link's first page
6
7 After someone opens a forge link and signs in, their first page is the one box ("What do you want built?"), then the crew at work, then **Next steps**: a plain list of links, one for each step they have not taken yet. The steps are *Make your everyday account* (`/settings/everyday`), *Open your apps* (`/apps`) and *Tell the crew something* (the box above). Each is read from what has happened, never ticked by hand, so a second visit lists only what is still undone. The list goes with the one box once the first tell exists. The heading is always "Next steps".
8
9 In the terminal, the home screen of that person shows the same heading and the same undone steps, one per line, under the first-tell line.
10
11 Code: `src/core/next-steps.ts` (the steps and their words), `src/web/pages/first_steps.ts` (the list), `src/tui/screens/dashboard.ts` (the terminal lines). Tests: `test/first-login.test.ts`, `test/next-steps-card.test.ts`.
src/core/next-steps.ts +10
@@ -36,6 +36,16 @@ export const STEP_TITLES: Record<StepKey, string> = {
3636 tell: "Tell the crew something",
3737 };
3838
39 /** The one heading of the list of steps still undone, whatever their count. */
40 export const FIRST_STEPS_HEADING = "Next steps";
41
42 /**
43 * The titles of the steps not yet taken, in order: the web list and the terminal's lines read this.
44 */
45 export function undoneTitles(steps: readonly NextStep[]): string[] {
46 return steps.filter((s) => !s.done).map((s) => STEP_TITLES[s.key]);
47 }
48
3949 /**
4050 * What the recipient of a sent forge sees first, in one line: the apps chosen, that the crew is
4151 * working, the three steps.
src/tui/screens/dashboard.ts +11 −2
@@ -27,7 +27,16 @@ import { coveredByVerdict, forgeVerdict, verdictLine } from "../../kernel/guard_
2727 import { lastChangeLine } from "../../story/last_change.ts";
2828 import { clientAppRows, clientFinished } from "../../core/client-apps.ts";
2929 import { appCrew } from "../../core/app-crew.ts";
30 import { nextStepsFor } from "../../core/next-steps.ts";
30 import { FIRST_STEPS_HEADING, nextStepsFor, undoneTitles, type NextStep } from "../../core/next-steps.ts";
31
32 /**
33 * The steps still undone, as the page lists them (`web/pages/first_steps.ts`): a heading, then one
34 * line each.
35 */
36 const firstStepLines = (steps: readonly NextStep[]): string[] => {
37 const todo = undoneTitles(steps);
38 return todo.length === 0 ? [] : [FIRST_STEPS_HEADING, ...todo.map((t) => ` ${t}`)];
39 };
3140 import { askRepos, askStatus, askStatusLine } from "../../core/ask-status.ts";
3241 import { AUTONOMY_FAILED_WORDS, firstAsk } from "../../actions/first_ask.ts";
3342 import { SAY_SOMETHING_WORDS } from "../../actions/tell_words.ts";
@@ -427,7 +436,7 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
427436 figures = [];
428437 firstTell = steps.some((s) => s.key === "tell" && !s.done);
429438 if (firstTell) {
430 clientLines = [FIRST_TELL_LINE, crewFirstText(f.app)];
439 clientLines = [FIRST_TELL_LINE, crewFirstText(f.app), ...firstStepLines(steps)];
431440 ctx.invalidate();
432441 return;
433442 }
src/web/pages/first_steps.ts added +31
@@ -0,0 +1,31 @@
1 /**
2 * The steps a person has not taken yet after a forge link's first login, under the one-box first
3 * screen: the crew working right now, then a plain list of links, one per undone step (#15972).
4 * Read from what has happened (`core/next-steps.ts`), so a later visit lists only what is still
5 * undone, and it is part of the first-screen card, so it is gone once the first tell exists. The
6 * terminal's home lists the same steps (`tui/screens/dashboard.ts`).
7 */
8
9 import { crewNow } from "../../core/crew_now.ts";
10 import { FIRST_STEPS_HEADING, STEP_TITLES, type NextStep, type StepKey } from "../../core/next-steps.ts";
11 import type { Ctx } from "../../http/context.ts";
12 import { crewNowHtml } from "../crew_now.ts";
13 import { html, type Html } from "../html.ts";
14 import { listCard, row } from "../ui.ts";
15
16 /** Where each step leads: the composer on this page, the apps list, the everyday-account form. */
17 const STEP_HREF: Record<StepKey, string> = {
18 everyday: "/settings/everyday",
19 apps: "/apps",
20 tell: "#composer",
21 };
22
23 /**
24 * The crew now, then the undone steps under one fixed heading; the crew block appears here only.
25 */
26 export function firstSteps(ctx: Ctx, steps: readonly NextStep[]): Html {
outdated

Principle 1: this repeats the steps the first-screen card already carries, and crewNowHtml may duplicate id=crew-now. Show it once.

27 const todo = steps.filter((s) => !s.done);
28 return html`${crewNowHtml(crewNow(ctx.app.db))}
outdated

Principles 7 and 8: a dl with only dt is misused markup; use a plain list of links, and a fixed heading rather than the count-dependent title.

29 <section id="first-steps" class="mt" aria-label="${FIRST_STEPS_HEADING}"><h2 class="small">${FIRST_STEPS_HEADING}</h2>
30 ${listCard(todo.map((s) => row({ href: STEP_HREF[s.key], title: html`${STEP_TITLES[s.key]}`, data: { "first-step": s.key } })))}</section>`;
31 }
src/web/pages/next-steps.ts +2 −1
@@ -22,6 +22,7 @@ import { hasPassword, type User } from "../../core/users.ts";
2222 import { passkeyIds } from "../../core/passkeys.ts";
2323 import type { Ctx } from "../../http/context.ts";
2424 import { html, type Html } from "../html.ts";
25 import { firstSteps } from "./first_steps.ts";
2526 import { btn, row } from "../ui.ts";
2627 import { askRepos, askStatus, type AskStatus } from "../../core/ask-status.ts";
2728 import { crewCanRun, crewFirstLine } from "../studio/crew_key.ts";
@@ -90,7 +91,7 @@ export async function nextStepsCard(
9091 ): Promise<Html | null> {
9192 if (!steps || steps.every((s) => s.done)) return null;
9293 const repos = await spawnedRepos(ctx.app, user);
93 if (steps.some((s) => s.key === "tell" && !s.done)) return firstTell(ctx, user);
94 if (steps.some((s) => s.key === "tell" && !s.done)) return html`${firstTell(ctx, user)}${firstSteps(ctx, steps)}`;
9495 const ask = askStatus(ctx.app.db, await askRepos(ctx.app, user), user.id, crewCanRun(ctx.app), user.isAdmin === true);
9596 // What the person made leads: the ask's state, then each app a crew member is on. An app nobody
9697 // is on says nothing here; the apps list below carries it.
test/first-login.test.ts +27 −1
@@ -28,6 +28,7 @@ import { serve, type Servers } from "../src/http/server.ts";
2828 import { firstBoot } from "../src/spawn/first-boot.ts";
2929 import { hostedPlacement } from "../src/spawn/placement.ts";
3030 import { quietLogs } from "./helpers/globals.ts";
31 import { jargonIn } from "./helpers/jargon.ts";
3132 import { passkeyFields } from "./helpers/passkey.ts";
3233
3334 quietLogs();
@@ -211,7 +212,9 @@ describe("the first login to a spawned forge", () => {
211212 expect(mainForms[0]).toContain('action="/tell"');
212213 expect(forms.some((f) => f.includes("/settings/everyday"))).toBe(false);
213214 expect(main).not.toContain("There is no password");
214 expect(main).not.toContain("Make your everyday account");
215 // The step is a link; the everyday form itself is not on the first screen.
216 expect(main).not.toContain("/settings/everyday/options");
217 expect(main).not.toContain('name="username"');
215218 expect(steps(home)).toEqual({ everyday: undefined, apps: undefined, tell: undefined });
216219 // Before the first ask: the sentence and the box, no crew rows (#13012).
217220 const card = home.slice(home.indexOf("data-first-tell"), home.indexOf("</section>", home.indexOf("data-first-tell")));
@@ -220,12 +223,33 @@ describe("the first login to a spawned forge", () => {
220223 expect(card).not.toContain("arrive here");
221224 });
222225
226 test("the first page shows the crew and the three steps as working links; none of it is jargon", async () => {
227 const home = await page(owner);
228 const main = home.slice(home.indexOf("<main"));
229 expect(main).toContain('id="crew-now"');
230 expect(main).toContain(">Next steps<");
231 expect(main.match(/id="crew-now"/g)?.length).toBe(1);
232 expect(main.match(/id="first-steps"/g)?.length).toBe(1);
233 const links = [...main.matchAll(/data-first-step="(\w+)"/g)].map((m) => m[1]);
234 expect(links).toEqual(["everyday", "apps", "tell"]);
235 expect(main).toContain(">Make your everyday account<");
236 expect(main).toContain(">Open your apps<");
237 expect(main).toContain(">Tell the crew something<");
238 expect(main).toContain('id="composer"'); // the "#composer" link has a target
239 for (const href of ["/settings/everyday", "/apps"]) {
240 expect(main).toContain(`href="${href}"`);
241 expect((await fetch(url(href), { headers: { cookie: owner }, redirect: "manual" })).status).toBe(200);
242 }
243 expect(jargonIn(main)).toEqual([]);
244 });
245
223246 test("once a tell exists the home leads with the crew's work and the ask box; the everyday account is one quiet line", async () => {
224247 const told = await post(owner, "/marias/bakery/tell", { text: "Add a weekly menu page." });
225248 expect(told.status).toBeLessThan(400);
226249 const home = await page(owner);
227250 expect(home).toContain(CARD);
228251 expect(home).not.toContain("Your next steps");
252 expect(home).not.toContain('id="first-steps"');
229253 expect(home).not.toContain("Make your everyday account");
230254 expect(home).not.toContain("can break the forge");
231255 expect(home).not.toContain("nobody is on it yet");
@@ -252,6 +276,8 @@ describe("the first login to a spawned forge", () => {
252276 expect(getUserByName(child.db, "maria-me")).toBeDefined();
253277 const home = await page(daily);
254278 expect(home).not.toContain('href="/settings/everyday"');
279 // The first ask is made by now: the steps are gone, not repeated.
280 expect([...home.matchAll(/data-first-step="(\w+)"/g)].map((m) => m[1])).toEqual([]);
255281 // It can read the client's own apps, and the crew line reads for it too.
256282 expect(home).toContain('href="/marias/bakery"');
257283 expect(home).not.toContain("Your apps arrive here");
test/first-steps.test.ts added +44
@@ -0,0 +1,44 @@
1 /**
2 * The list of steps still undone under the first-screen box (#15972): one fixed heading, a plain
3 * list of links, only the steps not yet taken; the crew block once; the terminal's lines say the
4 * same.
5 */
6 import { expect, test } from "bun:test";
7 import { mkdtempSync } from "node:fs";
8 import { tmpdir } from "node:os";
9 import { join } from "node:path";
10 import { createApp } from "../src/app.ts";
11 import { FIRST_STEPS_HEADING, undoneTitles, type NextStep } from "../src/core/next-steps.ts";
12 import type { Ctx } from "../src/http/context.ts";
13 import { firstSteps } from "../src/web/pages/first_steps.ts";
14 import { quietLogs } from "./helpers/globals.ts";
15
16 quietLogs();
17
18 const step = (key: NextStep["key"], done: boolean): NextStep => ({ key, title: key, done });
19 const app = createApp({ dataDir: mkdtempSync(join(tmpdir(), "forge-steps-")), port: 0 });
20 const ctx = { app } as unknown as Ctx;
21 const keys = (h: string) => [...h.matchAll(/data-first-step="(\w+)"/g)].map((m) => m[1]);
22
23 test("a second login, the everyday account made and nothing asked, lists only apps and tell", () => {
24 const out = String(firstSteps(ctx, [step("everyday", true), step("apps", false), step("tell", false)]));
25 expect(keys(out)).toEqual(["apps", "tell"]);
26 expect(out).not.toContain("Make your everyday account");
27 expect(out).not.toContain("/settings/everyday");
28 expect(undoneTitles([step("everyday", true), step("apps", false), step("tell", false)])).toEqual([
29 "Open your apps",
30 "Tell the crew something",
31 ]);
32 });
33
34 test("the heading is fixed whatever the count, the list is plain links, the crew block is once", () => {
35 for (const all of [[false, false, false], [true, false, false], [true, true, false]]) {
36 const out = String(firstSteps(ctx, [step("everyday", all[0]!), step("apps", all[1]!), step("tell", all[2]!)]));
37 expect(out).toContain(`<h2 class="small">${FIRST_STEPS_HEADING}</h2>`);
38 expect(out).not.toContain("<dl");
39 expect(out).toContain("<ul");
40 expect(out).not.toContain("<dt");
41 expect(out.match(/<li data-first-step="\w+">\s*<a href=/g)?.length).toBe(keys(out).length);
42 expect(out.match(/id="crew-now"/g)?.length).toBe(1);
43 }
44 });
test/next-steps-card.test.ts +2 −1
@@ -54,7 +54,8 @@ describe("the next-steps card of a spawned forge", () => {
5454 expect(forms[0]).toContain('id="composer"');
5555 expect(forms[0]).toContain('action="/tell"');
5656 expect(forms.filter((f) => f.includes('action="/tell"')).length).toBe(1);
57 expect(main).not.toContain("/settings/everyday");
57 expect(main).not.toContain("action=\"/settings/everyday\"");
58 expect(main).not.toContain("/settings/everyday/options");
5859 expect(main).not.toContain("There is no password");
5960 expect(main.match(/data-variant="primary"/g)?.length).toBe(1);
6061 expect(keys(home)).toEqual([]);

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs