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

Revert "A new forge's first-steps page shows the crew's first run live, with its state in plain words" #16226

opened this

Check · Review · Land · Live — Its check is red. Next: builder, its check is red.

Ready to land

revert-16149 → main 1 commit

Review

Sign in to review this change.
6 files changed +4 −167
docs/features/first-steps.md −4
@@ -9,7 +9,3 @@ After someone opens a forge link and signs in, their first page is the one box (
99 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.
1010
1111 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,54 +45,3 @@ export function firstWeekSteps(db: Database, user: User | undefined, now: number
4545 ];
4646 return steps.every((s) => s.done) ? null : steps;
4747 }
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 +1 −8
@@ -37,12 +37,7 @@ const firstStepLines = (steps: readonly NextStep[]): string[] => {
3737 const todo = undoneTitles(steps);
3838 return todo.length === 0 ? [] : [FIRST_STEPS_HEADING, ...todo.map((t) => ` ${t}`)];
3939 };
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}`;
4440 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";
4641 import { AUTONOMY_FAILED_WORDS, firstAsk } from "../../actions/first_ask.ts";
4742 import { SAY_SOMETHING_WORDS } from "../../actions/tell_words.ts";
4843 import { crewCanRun, crewFirstText } from "../../web/studio/crew_key.ts";
@@ -456,7 +451,6 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
456451 const finished = clientFinished(f.app.db, ids);
457452 const mine = await askRepos(f.app, f.user);
458453 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);
460454 clientLines =
461455 apps.length === 0
462456 ? ["Your apps will appear here."]
@@ -467,8 +461,7 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
467461 const crew = crewOf.get(a.repo.id)!.says;
468462 return `${line}${` ${doing}`} ${crew[0]!.toUpperCase()}${crew.slice(1)}.`;
469463 });
470 if (run && asked?.state !== "missing") clientLines = [firstRunLine(run), ...clientLines];
471 else if (asked) clientLines = [askStatusLine(asked), ...clientLines];
464 if (asked) clientLines = [askStatusLine(asked), ...clientLines];
472465 clientLines.push(nextStepsLine(f.user));
473466 ctx.invalidate();
474467 };
src/web/pages/first_steps.ts −6
@@ -6,7 +6,6 @@
66 * terminal's home lists the same steps (`tui/screens/dashboard.ts`).
77 */
88
9 import { FIRST_RUN_LIVE, FIRST_RUN_WORKING, type FirstRun } from "../../core/first_week.ts";
109 import { crewNow } from "../../core/crew_now.ts";
1110 import { FIRST_STEPS_HEADING, STEP_TITLES, type NextStep, type StepKey } from "../../core/next-steps.ts";
1211 import type { Ctx } from "../../http/context.ts";
@@ -21,11 +20,6 @@ const STEP_HREF: Record<StepKey, string> = {
2120 tell: "#composer",
2221 };
2322
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 }
28
2923 /**
3024 * The crew now, then the undone steps under one fixed heading; the crew block appears here only.
3125 */
src/web/pages/next-steps.ts +3 −9
@@ -22,8 +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 { firstRun } from "../../core/first_week.ts";
26 import { firstRunHtml, firstSteps } from "./first_steps.ts";
25 import { firstSteps } from "./first_steps.ts";
2726 import { btn, row } from "../ui.ts";
2827 import { askRepos, askStatus, type AskStatus } from "../../core/ask-status.ts";
2928 import { crewCanRun, crewFirstLine } from "../studio/crew_key.ts";
@@ -92,20 +91,15 @@ export async function nextStepsCard(
9291 ): Promise<Html | null> {
9392 if (!steps || steps.every((s) => s.done)) return null;
9493 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);
9794 if (steps.some((s) => s.key === "tell" && !s.done)) return html`${firstTell(ctx, user)}${firstSteps(ctx, steps)}`;
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;
95 const ask = askStatus(ctx.app.db, await askRepos(ctx.app, user), user.id, crewCanRun(ctx.app), user.isAdmin === true);
10196 // What the person made leads: the ask's state, then each app a crew member is on. An app nobody
10297 // is on says nothing here; the apps list below carries it.
10398 const rows = appCrew(ctx.app.db, ask?.state === "building" ? besideAsk(repos, ask) : repos)
10499 .filter((c) => c.who !== null)
105100 .map((c) => row({ href: `/${c.repo.ownerName}/${c.repo.name}`, title: html`${c.says}`, meta: html`${c.repo.name}` }));
106 if (!ask && !run && rows.length === 0) return null;
101 if (!ask && rows.length === 0) return null;
107102 return html`<section id="next-steps">
108 ${said}
109103 ${ask ? askBlock(ask) : null}
110104 ${rows.length > 0 ? html`<ul class="list">${rows}</ul>` : null}
111105 ${secondPasskeyLine(ctx, user)}
test/first-steps-live.test.ts deleted −89
@@ -1,89 +0,0 @@
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-");
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 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs