Public: anyone can read this; the crew can change it.
A new forge's first-steps page shows the crew's first run live, with its state in plain words #16149
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/16134-a-new-forge-s-first-steps-page-shows-the → main 0 commits fork 4 threads · 4 unresolved
docs/features/first-steps.md +4
| @@ -9,3 +9,7 @@ After someone opens a forge link and signs in, their first page is the one box ( | ||
| 9 | 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 | 10 | |
| 11 | 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`. |
| 12 | ||
| 13 | ## The crew's first run | |
| 14 | ||
| 15 | Once someone has told the crew something, the same page says what became of that first ask in plain words: "The crew is working on your first ask" (linking the ask) while an agent run on it is queued or running, then "Your first change is live" (linking the merged pull) once the change is live. The terminal home shows the same sentence with the path of the link after a colon, in the place of the ask's status line. Read from stored runs and pulls (`firstRun` in `src/core/first_week.ts`); nothing is stored. Test: `test/first-steps-live.test.ts`. |
src/core/first_week.ts +51
| @@ -45,3 +45,54 @@ export function firstWeekSteps(db: Database, user: User | undefined, now: number | ||
| 45 | 45 | ]; |
| 46 | 46 | return steps.every((s) => s.done) ? null : steps; |
| 47 | 47 | } |
| 48 | ||
| 49 | /** The crew's first run for a person, in two states a page can say in plain words. */ | |
| 50 | export interface FirstRun { | |
| 51 | readonly state: "working" | "live"; | |
| 52 | /** The merged pull's page when it is live; the ask's issue while the crew works. */ | |
| 53 | readonly href: string; | |
| 54 | } | |
| 55 | ||
| 56 | export const FIRST_RUN_WORKING = "The crew is working on your first ask"; | |
| 57 | export const FIRST_RUN_LIVE = "Your first change is live"; | |
| 58 | ||
| 59 | /** | |
| 60 | * What became of `askerId`'s first ask on `repos` (their oldest issue there, an app's direction is | |
| 61 | * no ask): "working" while an agent run on it is queued or running, "live" once a pull its run | |
| 62 | * pushed has merged, else null. Read from stored runs and pulls; nothing is stored. | |
| 63 | */ | |
| 64 | export function firstRun( | |
| 65 | db: Database, | |
| 66 | repos: readonly { readonly id: string; readonly ownerName: string; readonly name: string }[], | |
| 67 | askerId: string, | |
| 68 | ): FirstRun | null { | |
| 69 | if (repos.length === 0) return null; | |
| 70 | const ids = repos.map((r) => r.id); | |
| 71 | const marks = ids.map(() => "?").join(","); | |
| 72 | const ask = db | |
| 73 | .query<{ id: string; repo_id: string; number: number }, string[]>( | |
| 74 | `SELECT id, repo_id, number FROM issue | |
| 75 | WHERE kind = 'issue' AND author_id = ? AND repo_id IN (${marks}) | |
| 76 | AND id NOT IN (SELECT direction_issue_id FROM repo WHERE direction_issue_id IS NOT NULL) | |
| 77 | ORDER BY created_at ASC, number ASC LIMIT 1`, | |
| 78 | ) | |
| 79 | .get(askerId, ...ids); | |
| 80 | const repo = repos.find((r) => r.id === ask?.repo_id); | |
| 81 | if (!ask || !repo) return null; | |
| 82 | const merged = db | |
| 83 | .query<{ number: number }, [string, string]>( | |
| 84 | `SELECT i.number AS number FROM run r | |
| 85 | JOIN pull p ON r.branch != '' AND p.head_branch = r.branch AND p.merged_at IS NOT NULL | |
| 86 | JOIN issue i ON i.id = p.issue_id AND i.repo_id = ?2 | |
| 87 | WHERE r.issue_id = ?1 AND r.kind = 'agent' ORDER BY p.merged_at LIMIT 1`, | |
| 88 | ) | |
| 89 | .get(ask.id, repo.id); | |
| 90 | const base = `/${repo.ownerName}/${repo.name}`; | |
| 91 | if (merged) return { state: "live", href: `${base}/pulls/${merged.number}` }; | |
| 92 | const active = db | |
| 93 | .query<{ n: number }, [string]>( | |
| 94 | "SELECT 1 AS n FROM run WHERE issue_id = ?1 AND kind = 'agent' AND state IN ('queued','running') LIMIT 1", | |
| 95 | ) | |
| 96 | .get(ask.id); | |
| 97 | return active ? { state: "working", href: `${base}/issues/${ask.number}` } : null; | |
| 98 | } |
src/tui/screens/dashboard.ts +8 −1
| @@ -37,7 +37,12 @@ const firstStepLines = (steps: readonly NextStep[]): string[] => { | ||
| 37 | 37 | const todo = undoneTitles(steps); |
| 38 | 38 | return todo.length === 0 ? [] : [FIRST_STEPS_HEADING, ...todo.map((t) => ` ${t}`)]; |
| 39 | 39 | }; |
| 40 | ||
| 41 | /** The first run in the page's words (`web/pages/first_steps.ts`), with where its link goes. */ | |
| 42 | const firstRunLine = (run: FirstRun): string => | |
| 43 | `${run.state === "live" ? FIRST_RUN_LIVE : FIRST_RUN_WORKING}: ${run.href}`; | |
| 40 | 44 | import { askRepos, askStatus, askStatusLine } from "../../core/ask-status.ts"; |
| 45 | import { FIRST_RUN_LIVE, FIRST_RUN_WORKING, firstRun, type FirstRun } from "../../core/first_week.ts"; | |
| 41 | 46 | import { AUTONOMY_FAILED_WORDS, firstAsk } from "../../actions/first_ask.ts"; |
| 42 | 47 | import { SAY_SOMETHING_WORDS } from "../../actions/tell_words.ts"; |
| 43 | 48 | import { crewCanRun, crewFirstText } from "../../web/studio/crew_key.ts"; |
| @@ -451,6 +456,7 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 451 | 456 | const finished = clientFinished(f.app.db, ids); |
| 452 | 457 | const mine = await askRepos(f.app, f.user); |
| 453 | 458 | const asked = askStatus(f.app.db, mine, f.user.id, crewCanRun(f.app), f.user.isAdmin === true); |
| 459 | const run = firstRun(f.app.db, mine, f.user.id); | |
| 454 | 460 | clientLines = |
| 455 | 461 | apps.length === 0 |
| 456 | 462 | ? ["Your apps will appear here."] |
| @@ -461,7 +467,8 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 461 | 467 | const crew = crewOf.get(a.repo.id)!.says; |
| 462 | 468 | return `${line}${` ${doing}`} ${crew[0]!.toUpperCase()}${crew.slice(1)}.`; |
| 463 | 469 | }); |
| 464 | if (asked) clientLines = [askStatusLine(asked), ...clientLines]; | |
| 470 | if (run && asked?.state !== "missing") clientLines = [firstRunLine(run), ...clientLines]; | |
| 471 | else if (asked) clientLines = [askStatusLine(asked), ...clientLines]; | |
| 465 | 472 | clientLines.push(nextStepsLine(f.user)); |
| 466 | 473 | ctx.invalidate(); |
| 467 | 474 | }; |
src/web/pages/first_steps.ts +6
| @@ -6,6 +6,7 @@ | ||
| 6 | 6 | * terminal's home lists the same steps (`tui/screens/dashboard.ts`). |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | import { FIRST_RUN_LIVE, FIRST_RUN_WORKING, type FirstRun } from "../../core/first_week.ts"; | |
| 9 | 10 | import { crewNow } from "../../core/crew_now.ts"; |
| 10 | 11 | import { FIRST_STEPS_HEADING, STEP_TITLES, type NextStep, type StepKey } from "../../core/next-steps.ts"; |
| 11 | 12 | import type { Ctx } from "../../http/context.ts"; |
| @@ -20,6 +21,11 @@ const STEP_HREF: Record<StepKey, string> = { | ||
| 20 | 21 | tell: "#composer", |
| 21 | 22 | }; |
| 22 | 23 | |
| 24 | /** The first run in plain words: working while it runs, a link once its change is live. */ | |
| 25 | export function firstRunHtml(run: FirstRun): Html { | |
| 26 | return html`<div id="first-run" class="mt" data-first-run="${run.state}" aria-live="polite"><p><a href="${run.href}">${run.state === "live" ? FIRST_RUN_LIVE : FIRST_RUN_WORKING}</a></p></div>`; | |
| 27 | } | |
outdated
Principle 1, nothing says itself twice: both ternary branches are the same markup and differ only in the sentence. Write one |
||
| 28 | ||
| 23 | 29 | /** |
| 24 | 30 | * The crew now, then the undone steps under one fixed heading; the crew block appears here only. |
| 25 | 31 | */ |
src/web/pages/next-steps.ts +9 −3
| @@ -22,7 +22,8 @@ import { hasPassword, type User } from "../../core/users.ts"; | ||
| 22 | 22 | import { passkeyIds } from "../../core/passkeys.ts"; |
| 23 | 23 | import type { Ctx } from "../../http/context.ts"; |
| 24 | 24 | import { html, type Html } from "../html.ts"; |
| 25 | import { firstSteps } from "./first_steps.ts"; | |
| 25 | import { firstRun } from "../../core/first_week.ts"; | |
| 26 | import { firstRunHtml, firstSteps } from "./first_steps.ts"; | |
| 26 | 27 | import { btn, row } from "../ui.ts"; |
| 27 | 28 | import { askRepos, askStatus, type AskStatus } from "../../core/ask-status.ts"; |
| 28 | 29 | import { crewCanRun, crewFirstLine } from "../studio/crew_key.ts"; |
| @@ -91,15 +92,20 @@ export async function nextStepsCard( | ||
| 91 | 92 | ): Promise<Html | null> { |
| 92 | 93 | if (!steps || steps.every((s) => s.done)) return null; |
| 93 | 94 | const repos = await spawnedRepos(ctx.app, user); |
| 95 | const asked = await askRepos(ctx.app, user); | |
| 96 | const run = firstRun(ctx.app.db, asked, user.id); | |
| 94 | 97 | if (steps.some((s) => s.key === "tell" && !s.done)) return html`${firstTell(ctx, user)}${firstSteps(ctx, steps)}`; |
| 95 | const ask = askStatus(ctx.app.db, await askRepos(ctx.app, user), user.id, crewCanRun(ctx.app), user.isAdmin === true); | |
| 98 | const ask = askStatus(ctx.app.db, asked, user.id, crewCanRun(ctx.app), user.isAdmin === true); | |
| 99 | // The first run says itself in plain words; the ask block stays beside it for who is on it. | |
| 100 | const said = run !== null && ask?.state !== "missing" ? firstRunHtml(run) : null; | |
| 96 | 101 | // What the person made leads: the ask's state, then each app a crew member is on. An app nobody |
| 97 | 102 | // is on says nothing here; the apps list below carries it. |
| 98 | 103 | const rows = appCrew(ctx.app.db, ask?.state === "building" ? besideAsk(repos, ask) : repos) |
| 99 | 104 | .filter((c) => c.who !== null) |
| 100 | 105 | .map((c) => row({ href: `/${c.repo.ownerName}/${c.repo.name}`, title: html`${c.says}`, meta: html`${c.repo.name}` })); |
| 101 | if (!ask && rows.length === 0) return null; | |
| 106 | if (!ask && !run && rows.length === 0) return null; | |
| 102 | 107 | return html`<section id="next-steps"> |
| 108 | ${said} | |
| 103 | 109 | ${ask ? askBlock(ask) : null} |
| 104 | 110 | ${rows.length > 0 ? html`<ul class="list">${rows}</ul>` : null} |
| 105 | 111 | ${secondPasskeyLine(ctx, user)} |
test/first-steps-live.test.ts added +89
| @@ -0,0 +1,89 @@ | ||
| 1 | /** | |
| 2 | * The first-steps page shows the crew's first run live (#16134): "working" while a run on the first | |
| 3 | * ask is active, "live" with a link once its pull merges, in plain words with no state names. | |
| 4 | */ | |
| 5 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 6 | import { openPull } from "../src/actions/pulls.ts"; | |
| 7 | import { commitToBranch } from "../src/actions/repos.ts"; | |
| 8 | import { FIRST_RUN_LIVE, FIRST_RUN_WORKING, firstRun } from "../src/core/first_week.ts"; | |
| 9 | import { listReposOwnedBy } from "../src/core/repos.ts"; | |
| 10 | import { claimRun, createRun, finishRun } from "../src/core/runs.ts"; | |
| 11 | import { getUserByName } from "../src/core/users.ts"; | |
| 12 | import { createForgeApp } from "../src/tui/forge.ts"; | |
| 13 | import { dashboardScreen } from "../src/tui/screens/dashboard.ts"; | |
| 14 | import { headlessTerminal } from "../src/tui/term/terminal.ts"; | |
| 15 | import { settleApp } from "./helpers/tui.ts"; | |
| 16 | import { claimedForge, type ClaimedForge } from "./helpers/claimed-forge.ts"; | |
| 17 | import { quietLogs } from "./helpers/globals.ts"; | |
| 18 | ||
| 19 | quietLogs(); | |
| 20 | ||
| 21 | let forge: ClaimedForge; | |
| 22 | beforeAll(async () => { | |
| 23 | forge = await claimedForge("forge-steps-live-"); | |
outdated
This test only covers the web door. Add the terminal home as well. The BAD check also runs on a block cut at the first </section>, which reaches into the crew block and the steps list. Scope it to the |
||
| 24 | }, 60_000); | |
| 25 | afterAll(() => forge.stop()); | |
| 26 | ||
| 27 | const home = async () => (await fetch(`${forge.base}/`, { headers: { cookie: forge.owner } })).text(); | |
| 28 | /** The terminal's home for `user`, as one line of text. */ | |
| 29 | async function terminalHome(user: NonNullable<ReturnType<typeof getUserByName>>): Promise<string> { | |
| 30 | const { app: tui, session } = createForgeApp( | |
| 31 | forge.child, | |
| 32 | { sshUsername: user.username, remoteAddress: "127.0.0.1", fingerprint: "SHA256:test", user }, | |
| 33 | { terminal: headlessTerminal(400, 60), exitHooks: false }, | |
| 34 | ); | |
| 35 | tui.start(); | |
| 36 | tui.ctx.push(dashboardScreen(session, tui.ctx)); | |
| 37 | await settleApp(tui); | |
| 38 | const text = tui.screen.toText().replace(/\s+/g, " "); | |
| 39 | tui.stop?.(); | |
| 40 | return text; | |
| 41 | } | |
| 42 | const BAD = /\b(queued|running|ok|failed|cancelled|merged)\b/i; | |
| 43 | ||
| 44 | test("the home says the crew is working while the first ask's run is active, then that the change is live", async () => { | |
| 45 | const db = forge.child.db; | |
| 46 | const maria = getUserByName(db, "maria")!; | |
| 47 | expect(firstRun(db, [], maria.id)).toBeNull(); | |
| 48 | await forge.post(forge.owner, "/tell", { app: "new-app", text: "A weekly menu page for the bakery" }); | |
| 49 | const repo = listReposOwnedBy(db, maria.id).find((r) => r.name.includes("menu"))!; | |
| 50 | const issue = db.query<{ id: string }, [string]>("SELECT id FROM issue WHERE repo_id = ?1 AND number = 1").get(repo.id)!; | |
| 51 | db.query("DELETE FROM run WHERE issue_id = ?1").run(issue.id); | |
| 52 | expect(firstRun(db, [repo], maria.id)).toBeNull(); | |
| 53 | expect(await home()).not.toContain("data-first-run"); | |
| 54 | ||
| 55 | const run = createRun(db, { repoId: repo.id, kind: "agent", issueId: issue.id, branch: "agent/first", reason: "issue" }); | |
| 56 | const working = await home(); | |
| 57 | expect(firstRun(db, [repo], maria.id)?.state).toBe("working"); | |
| 58 | expect(working).toContain(FIRST_RUN_WORKING); | |
| 59 | expect(working).toContain('data-first-run="working"'); | |
| 60 | expect(await terminalHome(maria)).toContain(`${FIRST_RUN_WORKING}: /${repo.ownerName}/${repo.name}/issues/1`); | |
| 61 | claimRun(db, run.id); | |
| 62 | expect(await home()).toContain(FIRST_RUN_WORKING); | |
| 63 | const block = (await home()).split('id="first-run"')[1]!.split("</div>")[0]!; | |
| 64 | expect(block).not.toMatch(BAD); | |
| 65 | ||
| 66 | finishRun(db, run.id, { state: "ok", summary: "done" }); | |
| 67 | expect(await home()).not.toContain(FIRST_RUN_WORKING); | |
| 68 | ||
| 69 | const author = getUserByName(db, "maria")!; | |
| 70 | const branch = await commitToBranch(forge.child, author, repo, { | |
| 71 | branch: "agent/first", | |
| 72 | base: "main", | |
| 73 | message: "first", | |
| 74 | files: [{ path: "first.txt", content: "hi\n" }], | |
| 75 | }); | |
| 76 | if (!branch.ok) throw new Error(JSON.stringify(branch.error)); | |
| 77 | const pull = await openPull(forge.child, author, repo, { title: "first", baseBranch: "main", headBranch: "agent/first" }); | |
| 78 | if (!pull.ok) throw new Error(String(pull.error)); | |
| 79 | expect(firstRun(db, [repo], maria.id)).toBeNull(); | |
| 80 | db.query("UPDATE pull SET merged_at = strftime('%Y-%m-%dT%H:%M:%fZ','now') WHERE issue_id = ?1").run(pull.value.id); | |
| 81 | const live = firstRun(db, [repo], maria.id)!; | |
| 82 | expect(live.state).toBe("live"); | |
| 83 | expect(live.href).toBe(`/${repo.ownerName}/${repo.name}/pulls/${pull.value.number}`); | |
| 84 | const page = await home(); | |
| 85 | expect(page).toContain(FIRST_RUN_LIVE); | |
| 86 | expect(page).toContain(`href="${live.href}"`); | |
| 87 | expect(page).not.toContain(FIRST_RUN_WORKING); | |
| 88 | expect((await terminalHome(maria)).includes(`${FIRST_RUN_LIVE}: ${live.href}`)).toBe(true); | |
| 89 | }); |
This import sits in the middle of the file, after a const, between two other imports. Move it up to the import block. The new terminal branches (the first-tell screen and the later home) also have no test. Add one that fails without them.