Public: anyone can read this; the crew can change it.
A client's first page shows each of their apps with the crew's current line in plain words #14173
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/14100-a-client-s-first-page-shows-each-of-thei → main 7 commits fork 3 threads · 3 unresolved
14 files
changed +221
−83
docs/design/areas/tell.md +11 −3
| @@ -16,9 +16,17 @@ shifts and Enter sends it with the page's path as `from`. Any failure falls back | ||
| 16 | 16 | ## Client home: `client-app-finished` |
| 17 | 17 | |
| 18 | 18 | A muted line on a client's app row, `Finished <time>: <title>`, for the app's |
| 19 | newest merged pull. It sits with `client-app-about`, `client-app-agents` and | |
| 20 | `client-app-doing`; it uses `muted` and adds no colour or size. The | |
| 21 | terminal says the same words. | |
| 19 | newest merged pull. It sits with `client-app-line` and `client-app-about`; it uses `muted` and | |
| 20 | adds no colour or size. The terminal says the same words. | |
| 21 | ||
| 22 | ## Client home: `client-app-line` | |
| 23 | ||
| 24 | The one bold sentence under an app's name on a client's home: `Building: <title>`, `Waiting for your | |
| 25 | answer`, `About to start` or `Nothing in progress` (`src/actions/client_line.ts`). It replaces the | |
| 26 | former `client-app-agents` and `client-app-doing` lines, so an app row is name, sentence, about, | |
| 27 | and the muted `Finished` line: no third status line (principles 1, 7). It is a `<b>` in a span | |
| 28 | with no colour, size or margin of its own, so it adds no layout shift. The terminal says the same | |
| 29 | sentence after the app's name. | |
| 22 | 30 | |
| 23 | 31 | ## App page: the tell line |
| 24 | 32 |
docs/features/README.md +1
| @@ -345,6 +345,7 @@ Read with the guide page [Hosting forges for others, and getting paid](../guide- | ||
| 345 | 345 | - [](child-proposal-credential.md) |
| 346 | 346 | - [](forge-bill.md) |
| 347 | 347 | - [](client-forge.md) |
| 348 | - [](client-app-line.md) | |
| 348 | 349 | - [](client-link-times.md) |
| 349 | 350 | - [](lapsed-forge.md) |
| 350 | 351 | - [](forge-link-qr.md) |
docs/features/client-app-line.md added +19
| @@ -0,0 +1,19 @@ | ||
| 1 | # The sentence under each app | |
| 2 | ||
| 3 | A client's first page (`/`) shows each of their apps with one plain sentence about what its crew | |
| 4 | is doing now. The forge's terminal dashboard says the same sentence after the app's name | |
| 5 | (`bakery: Building: the booking form.`), and the MCP `forge_view` answer carries it as `line` on | |
| 6 | each app. | |
| 7 | ||
| 8 | - `Building: <title>` while the crew is running work on the app; the title is cut and cleaned of | |
| 9 | developer words. | |
| 10 | - `Waiting for your answer` when the crew has finished something that waits for a person. | |
| 11 | - `About to start` when work is lined up and nothing runs yet. | |
| 12 | - `Nothing in progress` otherwise. | |
| 13 | ||
| 14 | One module words it, `src/actions/client_line.ts` (`clientLines`: three reads for any number of | |
| 15 | apps, plus the review waits); the page, the terminal and `forge_view` all call it, so they cannot | |
| 16 | disagree (`test/client-home.test.ts`, `test/client-line.test.ts`). | |
| 17 | ||
| 18 | To try it: sign in through a client's claim link and read the line under each app; in the | |
| 19 | terminal, open the dashboard; or call `forge_view` and read `apps[].line`. |
src/actions/client_line.ts added +64
| @@ -0,0 +1,64 @@ | ||
| 1 | /** | |
| 2 | * The one plain sentence about what an app's crew is doing now, for a person who is not a | |
| 3 | * developer: "Building: the booking form", "Waiting for your answer", "About to start" or | |
| 4 | * "Nothing in progress". The client's first page and the MCP `forge_view` answer both read it, so | |
| 5 | * the two say the same thing. Plain data in, plain data out; no developer word is in the template. | |
| 6 | */ | |
| 7 | import type { Database } from "bun:sqlite"; | |
| 8 | import { plainWords } from "../core/app-crew.ts"; | |
| 9 | import { cutTitle, clientDoings } from "../core/client-apps.ts"; | |
| 10 | import { listOpenPullsOf } from "../core/issues.ts"; | |
| 11 | import { joinMany } from "../core/pulls.ts"; | |
| 12 | import type { Repo } from "../core/repos.ts"; | |
| 13 | import { reviewWaitsFor } from "../crew/review.ts"; | |
| 14 | ||
| 15 | export const IDLE_LINE = "Nothing in progress"; | |
| 16 | export const WAITING_LINE = "Waiting for your answer"; | |
| 17 | export const QUEUED_LINE = "About to start"; | |
| 18 | ||
| 19 | /** What is in hand on an app, as counts and the running title: the sentence's whole input. */ | |
| 20 | export interface CrewState { | |
| 21 | readonly title: string | undefined; | |
| 22 | readonly waitingOnPerson: boolean; | |
| 23 | readonly queued: boolean; | |
| 24 | } | |
| 25 | ||
| 26 | /** The sentence for one app's state; the running work comes first, then a wait on the person. */ | |
| 27 | export function lineFor(state: CrewState): string { | |
| 28 | if (state.title !== undefined) { | |
| 29 | const said = cutTitle(plainWords(state.title).replace(/\(\s*\)/g, "")); | |
| 30 | return said === "" ? "Building something new" : `Building: ${said}`; | |
| 31 | } | |
| 32 | if (state.waitingOnPerson) return WAITING_LINE; | |
| 33 | return state.queued ? QUEUED_LINE : IDLE_LINE; | |
| 34 | } | |
| 35 | ||
| 36 | /** One sentence for each of `repos`, in two reads for the whole set plus the review waits. */ | |
| 37 | export function clientLines(db: Database, repos: readonly Repo[]): Map<string, string> { | |
| 38 | const out = new Map<string, string>(); | |
| 39 | if (repos.length === 0) return out; | |
| 40 | const ids = repos.map((r) => r.id); | |
| 41 | const doing = clientDoings(db, ids); | |
| 42 | 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 | ); | |
| 51 | const byId = new Map(repos.map((r) => [r.id, r])); | |
| 52 | const pulls = joinMany(db, listOpenPullsOf(db, ids)).flatMap((pull) => { | |
| 53 | const repo = byId.get(pull.repoId); | |
| 54 | return repo === undefined ? [] : [{ repo, pull }]; | |
| 55 | }); | |
| 56 | const waits = reviewWaitsFor(db, pulls); | |
| 57 | const waiting = new Set(pulls.filter((p) => waits.get(p.pull.id)?.person !== undefined).map((p) => p.repo.id)); | |
| 58 | for (const repo of repos) | |
| 59 | out.set( | |
| 60 | repo.id, | |
| 61 | lineFor({ title: doing.get(repo.id)?.title, waitingOnPerson: waiting.has(repo.id), queued: queued.has(repo.id) }), | |
| 62 | ); | |
| 63 | return out; | |
| 64 | } |
src/actions/forge_view.ts +6 −3
| @@ -12,6 +12,7 @@ import type { App } from "../app.ts"; | ||
| 12 | 12 | import type { User } from "../core/users.ts"; |
| 13 | 13 | import type { Ctx } from "../http/context.ts"; |
| 14 | 14 | import { appsOf } from "../web/studio/asks.ts"; |
| 15 | import { clientLines, IDLE_LINE } from "./client_line.ts"; | |
| 15 | 16 | import { crewNow } from "./crew_now.ts"; |
| 16 | 17 | import { readHealth } from "./health.ts"; |
| 17 | 18 | |
| @@ -23,7 +24,7 @@ type Row = ReturnType<typeof crewNow>[number]; | ||
| 23 | 24 | |
| 24 | 25 | export interface ForgeView { |
| 25 | 26 | readonly counts: { apps: number; running: number; queued: number; waiting: number }; |
| 26 | readonly apps: readonly { app: string; slug: string; access: string; running: number; queued: number }[]; | |
| 27 | readonly apps: readonly { app: string; slug: string; access: string; line: string; running: number; queued: number }[]; | |
| 27 | 28 | readonly runs: readonly Row[]; |
| 28 | 29 | readonly health: unknown; |
| 29 | 30 | } |
| @@ -46,11 +47,13 @@ export function forgeView(ctx: Pick<Ctx, "app">, user: User): ForgeView { | ||
| 46 | 47 | else t.queued++; |
| 47 | 48 | tally.set(r.app, t); |
| 48 | 49 | } |
| 49 | const apps = repos.slice(0, VIEW_APPS).map((repo) => { | |
| 50 | const shown = repos.slice(0, VIEW_APPS); | |
| 51 | const lines = clientLines(ctx.app.db, shown); | |
| 52 | const apps = shown.map((repo) => { | |
| 50 | 53 | const name = `${repo.ownerName}/${repo.name}`; |
| 51 | 54 | const record = records.get(repo.id)!; |
| 52 | 55 | const t = tally.get(name) ?? { running: 0, queued: 0 }; |
| 53 | return { app: name, slug: record.slug, access: record.access, ...t }; | |
| 56 | return { app: name, slug: record.slug, access: record.access, line: lines.get(repo.id) ?? IDLE_LINE, ...t }; | |
| 54 | 57 | }); |
| 55 | 58 | return { |
| 56 | 59 | counts: { |
src/core/client-apps.ts −6
| @@ -134,12 +134,6 @@ export function cutTitle(title: string): string { | ||
| 134 | 134 | return `${(space > 0 ? head.slice(0, space) : head).trimEnd()}…`; |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | /** The sentence about what an app's agents are on, or "" when none is running. */ | |
| 138 | export function doingLine(doing: ClientDoing | undefined): string { | |
| 139 | const title = doing === undefined ? "" : cutTitle(doing.title); | |
| 140 | return title === "" ? "" : `Working on: ${title}`; | |
| 141 | } | |
| 142 | ||
| 143 | 137 | /** |
| 144 | 138 | * `Finished 3 days ago: Fix the menu`, or "" for an app with nothing finished; both doors word it |
| 145 | 139 | * so. |
src/core/issues.ts +12
| @@ -284,6 +284,18 @@ export function listOpenPullsVisibleTo( | ||
| 284 | 284 | .map(toIssue); |
| 285 | 285 | } |
| 286 | 286 | |
| 287 | /** Open pulls in the given repositories (ids already checked by the caller), lean rows. */ | |
| 288 | export function listOpenPullsOf(db: Database, repoIds: readonly string[]): Issue[] { | |
| 289 | if (repoIds.length === 0) return []; | |
| 290 | return db | |
| 291 | .query<IssueRow, string[]>( | |
| 292 | `${SELECT_LEAN} WHERE issue.kind = 'pull' AND issue.state = 'open' | |
| 293 | AND issue.repo_id IN (${repoIds.map((_, i) => `?${i + 1}`).join(",")})`, | |
| 294 | ) | |
| 295 | .all(...repoIds) | |
| 296 | .map(toIssue); | |
| 297 | } | |
| 298 | ||
| 287 | 299 | /** |
| 288 | 300 | * Open conversations assigned to one account, across every repository — |
| 289 | 301 | * the "on you" list. An assignee can always see what is assigned to them: |
src/tui/screens/dashboard.ts +5 −10
| @@ -24,14 +24,14 @@ import { forgeFlakes, forgeLane, forgeNeedList, needTermLine } from "../../actio | ||
| 24 | 24 | import { ownerWaits, waitLine, withMore } from "../../actions/owner_waits.ts"; |
| 25 | 25 | import { forgeHealth } from "../../kernel/guard.ts"; |
| 26 | 26 | import { coveredByVerdict, forgeVerdict, verdictLine } from "../../kernel/guard_verdict.ts"; |
| 27 | import { clientAppRows, clientDoings, clientFinished, doingLine, finishedLine } from "../../core/client-apps.ts"; | |
| 27 | import { clientAppRows, clientFinished, finishedLine } from "../../core/client-apps.ts"; | |
| 28 | 28 | import { appCrew } from "../../core/app-crew.ts"; |
| 29 | 29 | import { nextStepsFor } from "../../core/next-steps.ts"; |
| 30 | 30 | import { askRepos, askStatus, askStatusLine } from "../../core/ask-status.ts"; |
| 31 | 31 | import { AUTONOMY_FAILED_WORDS, firstAsk } from "../../actions/first_ask.ts"; |
| 32 | 32 | import { SAY_SOMETHING_WORDS } from "../../actions/tell_words.ts"; |
| 33 | 33 | import { crewCanRun, crewFirstText } from "../../web/studio/crew_key.ts"; |
| 34 | import { agentsLine } from "../../web/studio/client_home.ts"; | |
| 34 | import { clientLines as crewSentences, IDLE_LINE } from "../../actions/client_line.ts"; | |
| 35 | 35 | import { lastVisit } from "../../core/home_visit.ts"; |
| 36 | 36 | import { quietFor, quietText } from "../../web/studio/home_empty.ts"; |
| 37 | 37 | import { firstWeekText } from "../../web/first_week.ts"; |
| @@ -393,7 +393,7 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 393 | 393 | const now = new Date(); |
| 394 | 394 | const ids = apps.map((a) => a.repo.id); |
| 395 | 395 | const crewOf = new Map(appCrew(f.app.db, apps.map((a) => a.repo)).map((c) => [c.repo.id, c] as const)); |
| 396 | const doings = clientDoings(f.app.db, ids); | |
| 396 | const sentences = crewSentences(f.app.db, apps.map((a) => a.repo)); | |
| 397 | 397 | const finished = clientFinished(f.app.db, ids); |
| 398 | 398 | const mine = await askRepos(f.app, f.user); |
| 399 | 399 | const asked = askStatus(f.app.db, mine, f.user.id, crewCanRun(f.app), f.user.isAdmin === true); |
| @@ -401,14 +401,9 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 401 | 401 | apps.length === 0 |
| 402 | 402 | ? ["Your apps will appear here."] |
| 403 | 403 | : apps.map((a) => { |
| 404 | const doing = [ | |
| 405 | finishedLine(finished.get(a.repo.id), now.getTime()), | |
| 406 | doingLine(doings.get(a.repo.id)), | |
| 407 | ] | |
| 408 | .filter((x) => x !== "") | |
| 409 | .join(" "); | |
| 404 | const doing = finishedLine(finished.get(a.repo.id), now.getTime()); | |
| 410 | 405 | const mark = a.live === undefined ? "" : " (running, o opens it)"; |
| 411 | const line = `${a.repo.name}${mark}: ${agentsLine(a.working, a.queued)}`; | |
| 406 | const line = `${a.repo.name}${mark}: ${sentences.get(a.repo.id) ?? IDLE_LINE}.`; | |
| 412 | 407 | const crew = crewOf.get(a.repo.id)!.says; |
| 413 | 408 | return `${line}${doing === "" ? "" : ` ${doing}`} ${crew[0]!.toUpperCase()}${crew.slice(1)}.`; |
| 414 | 409 | }); |
src/web/studio/client_home.ts +7 −22
| @@ -1,13 +1,14 @@ | ||
| 1 | 1 | /** |
| 2 | 2 | * A client's first screen (#1812): signed in on a forge that was made for |
| 3 | * them, the home is their apps, each in one plain sentence and one more that | |
| 4 | * says whether its agents are working or waiting. No map, board or settings | |
| 3 | * them, the home is their apps, each with one plain sentence on what its crew is doing | |
| 4 | * (`src/actions/client_line.ts`). No map, board or settings | |
| 5 | 5 | * until asked (`/?all=1` is the whole home). Words only a developer knows |
| 6 | 6 | * stay off it; `test/client-home.test.ts` holds the list. |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | import { clientLines } from "../../actions/client_line.ts"; | |
| 9 | 10 | import { notePhase, takeSessionTime, timePhase, timePhaseAsync } from "../../core/route_timing.ts"; |
| 10 | import { clientAppRows, clientDoings, clientFinished, doingLine, finishedLine } from "../../core/client-apps.ts"; | |
| 11 | import { clientAppRows, clientFinished, finishedLine } from "../../core/client-apps.ts"; | |
| 11 | 12 | import type { User } from "../../core/users.ts"; |
| 12 | 13 | import type { Ctx } from "../../http/context.ts"; |
| 13 | 14 | import { mayDirectCrew } from "../../crew/direct.ts"; |
| @@ -15,30 +16,17 @@ import { repoBase } from "../chrome.ts"; | ||
| 15 | 16 | import { html, type Html } from "../html.ts"; |
| 16 | 17 | import { btn, card } from "../ui.ts"; |
| 17 | 18 | |
| 18 | /** The sentence about the agents, from how many are going and how many are lined up. */ | |
| 19 | export function agentsLine(working: number, queued: number): string { | |
| 20 | if (working > 0) | |
| 21 | return working === 1 | |
| 22 | ? "One agent is working on it now." | |
| 23 | : `${working} agents are working on it now.`; | |
| 24 | if (queued > 0) return "Its agents are about to start."; | |
| 25 | return "Its agents are waiting for something to do."; | |
| 26 | } | |
| 27 | ||
| 28 | 19 | /** The card of apps; an empty one says they will appear. The caller decides who is a client. */ |
| 29 | 20 | export async function clientApps(ctx: Ctx, user: User): Promise<Html> { |
| 30 | 21 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 31 | 22 | const apps = await timePhaseAsync(ctx.request, "apps", () => clientAppRows(ctx.app, user)); |
| 32 | 23 | const now = new Date(); |
| 33 | const doings = timePhase(ctx.request, "doing", () => | |
| 34 | clientDoings(ctx.app.db, apps.map((a) => a.repo.id)), | |
| 35 | ); | |
| 36 | 24 | const finished = timePhase(ctx.request, "finished", () => |
| 37 | 25 | clientFinished(ctx.app.db, apps.map((a) => a.repo.id)), |
| 38 | 26 | ); |
| 27 | const lines = timePhase(ctx.request, "line", () => clientLines(ctx.app.db, apps.map((a) => a.repo))); | |
| 39 | 28 | const rendering = performance.now(); |
| 40 | const rows = apps.map(({ repo, working, queued, live }) => { | |
| 41 | const doing = doingLine(doings.get(repo.id)); | |
| 29 | const rows = apps.map(({ repo, live }) => { | |
| 42 | 30 | const done = finishedLine(finished.get(repo.id), now.getTime()); |
| 43 | 31 | const about = repo.description !== "" ? repo.description : "An app of yours."; |
| 44 | 32 | // The tell form with this app chosen; it sends the person back to `/`. |
| @@ -59,12 +47,9 @@ export async function clientApps(ctx: Ctx, user: User): Promise<Html> { | ||
| 59 | 47 | <div class="bar"> |
| 60 | 48 | <a href="${repoBase(repo)}"><b>${repo.name}</b></a> ${open} ${ask} |
| 61 | 49 | </div> |
| 50 | <span class="client-app-line"><b>${lines.get(repo.id) ?? ""}</b></span> | |
| 62 | 51 | <span class="client-app-about">${about}</span> |
| 63 | <span class="client-app-agents muted" data-agents="${working > 0 ? "working" : "waiting"}" | |
| 64 | >${agentsLine(working, queued)}</span | |
| 65 | > | |
| 66 | 52 | ${done !== "" ? html`<span class="client-app-finished muted">${done}</span>` : ""} |
| 67 | ${doing !== "" ? html`<span class="client-app-doing muted">${doing}</span>` : ""} | |
| 68 | 53 | </li>`; |
| 69 | 54 | }); |
| 70 | 55 | const shown = card( |
test/api-forge-view.test.ts +4 −2
| @@ -153,11 +153,13 @@ describe("the forge view over the API", () => { | ||
| 153 | 153 | (app.db as unknown as { query: unknown }).query = original; |
| 154 | 154 | } |
| 155 | 155 | expect(view.counts.apps).toBe(APPS); |
| 156 | expect(view.apps.every((a) => a.line !== "")).toBe(true); | |
| 156 | 157 | expect(view.apps.length).toBeLessThanOrEqual(VIEW_APPS); |
| 157 | 158 | expect(view.runs.filter((r) => r.run !== null).length).toBeLessThanOrEqual(50); |
| 158 | 159 | // 120 apps, 960 runs. `mayReadRuns` (shared with /crew/now) reads two |
| 159 | // rows per app today; anything beyond that, or a read per run, fails. | |
| 160 | expect(selects.length).toBeLessThanOrEqual(2 * APPS + 20); | |
| 160 | // rows per app today, 20 fixed reads before the crew sentences and 3 for them (running work, | |
| 161 | // queued runs, open pulls); anything beyond that, or a read per run, fails. | |
| 162 | expect(selects.length).toBeLessThanOrEqual(2 * APPS + 23); | |
outdated
Loosened budget; comment says 5 reads, pull says 3. Tighten to the measured number. |
||
| 161 | 163 | }); |
| 162 | 164 | |
| 163 | 165 | test("foundry has a door only for an app an admin or the forge's org owns", async () => { |
test/client-apps.test.ts +1 −5
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | /** What a client's apps are doing: the work running, else what was last finished (#4007, #6091). */ |
| 2 | 2 | import { beforeEach, describe, expect, test } from "bun:test"; |
| 3 | 3 | import type { Database } from "bun:sqlite"; |
| 4 | import { clientDoings, clientFinished, doingLine, finishedLine } from "../src/core/client-apps.ts"; | |
| 4 | import { clientDoings, clientFinished, finishedLine } from "../src/core/client-apps.ts"; | |
| 5 | 5 | import { migrations } from "../src/core/schema.ts"; |
| 6 | 6 | import { openDb } from "../src/kernel/db.ts"; |
| 7 | 7 | |
| @@ -76,8 +76,4 @@ describe("the lines", () => { | ||
| 76 | 76 | expect(finishedLine(undefined, NOW.getTime())).toBe(""); |
| 77 | 77 | }); |
| 78 | 78 | |
| 79 | test("doingLine says Working on, or nothing", () => { | |
| 80 | expect(doingLine({ title: "Add rye" })).toBe("Working on: Add rye"); | |
| 81 | expect(doingLine(undefined)).toBe(""); | |
| 82 | }); | |
| 83 | 79 | }); |
test/client-home.test.ts +43 −32
| @@ -17,7 +17,8 @@ import { AppsRuntime } from "../src/apps/runtime.ts"; | ||
| 17 | 17 | import { getAppByRepo } from "../src/core/apps.ts"; |
| 18 | 18 | import { clientApps } from "../src/web/studio/client_home.ts"; |
| 19 | 19 | import type { Ctx } from "../src/http/context.ts"; |
| 20 | import { clientAppRows, cutTitle, doingLine } from "../src/core/client-apps.ts"; | |
| 20 | import { forgeView } from "../src/actions/forge_view.ts"; | |
| 21 | import { clientAppRows, cutTitle } from "../src/core/client-apps.ts"; | |
| 21 | 22 | import { addCrew, createAgentRow } from "../src/core/agents.ts"; |
| 22 | 23 | import { moveArchived } from "../src/core/repos.ts"; |
| 23 | 24 | import { createSession } from "../src/core/sessions.ts"; |
| @@ -171,12 +172,14 @@ describe("a client's first screen", () => { | ||
| 171 | 172 | .replace(/<[^>]*>/g, " ") |
| 172 | 173 | .replace(/\s+/g, " "); |
| 173 | 174 | |
| 174 | test("the home is their apps, each a sentence and a line on its agents, with no map, board or settings", async () => { | |
| 175 | test("the home is their apps, each with one sentence on its crew, with no map, board or settings", async () => { | |
| 175 | 176 | const home = main(await page(owner)); |
| 176 | 177 | const apps = home.slice(home.indexOf('id="client-apps"')); |
| 177 | 178 | expect(apps).toContain('href="/marias/bakery"'); |
| 178 | expect(apps).toMatch(/data-agents="(working|waiting)"/); | |
| 179 | expect(apps).toContain("agents are waiting"); | |
| 179 | expect(apps).toContain('client-app-line"><b>Nothing in progress</b>'); | |
| 180 | expect(apps).not.toContain("agents are"); | |
| 181 | expect(apps).not.toContain("Working on"); | |
| 182 | expect(words(apps)).not.toMatch(/\b(pull|check|run|gate)\b/i); | |
| 180 | 183 | expect(home).not.toContain('id="live-chips"'); |
| 181 | 184 | for (const gone of ['href="/map"', 'href="/board"', 'href="/audit"', 'href="/settings"']) |
| 182 | 185 | expect(home).not.toContain(gone); |
| @@ -299,7 +302,7 @@ describe("a client's first screen", () => { | ||
| 299 | 302 | ); |
| 300 | 303 | stopped.app.start(); |
| 301 | 304 | await settleApp(stopped.app); |
| 302 | expect(stopped.app.screen.toText()).toContain("bakery: Its agents"); | |
| 305 | expect(stopped.app.screen.toText()).toContain("bakery: Nothing in progress"); | |
| 303 | 306 | expect(stopped.app.screen.toText()).not.toContain("running"); |
| 304 | 307 | idle.feed("o"); |
| 305 | 308 | await settleApp(stopped.app); |
| @@ -330,31 +333,42 @@ describe("a client's first screen", () => { | ||
| 330 | 333 | app.stop(); |
| 331 | 334 | }); |
| 332 | 335 | |
| 333 | test("a running agent turns the line to working", async () => { | |
| 334 | const repo = child.db | |
| 335 | .query<{ id: string }, []>("SELECT id FROM repo WHERE name = 'bakery'") | |
| 336 | .get()!; | |
| 336 | ||
| 337 | /** | |
| 338 | * A running agent run on an open issue of the bakery: the one thing the sentence says it builds. | |
| 339 | */ | |
| 340 | const startBuilding = (runId: string): void => { | |
| 341 | const repo = child.db.query<{ id: string; owner_id: string }, []>("SELECT id, owner_id FROM repo WHERE name = 'bakery'").get()!; | |
| 337 | 342 | child.db |
| 338 | .query("INSERT INTO run (id, repo_id, kind, state) VALUES ('r-client-1', ?1, 'agent', 'running')") | |
| 339 | .run(repo.id); | |
| 343 | .query("INSERT INTO issue (id, repo_id, number, kind, title, body, author_id, state) VALUES ('i-' || ?1, ?2, 9100 + length(?1), 'issue', 'Add rye bread', '', ?3, 'open')") | |
| 344 | .run(runId, repo.id, repo.owner_id); | |
| 345 | child.db | |
| 346 | .query("INSERT INTO run (id, repo_id, kind, state, issue_id) VALUES (?1, ?2, 'agent', 'running', 'i-' || ?1)") | |
| 347 | .run(runId, repo.id); | |
| 348 | }; | |
| 349 | const stopBuilding = (runId: string): void => { | |
| 350 | child.db.query("DELETE FROM run WHERE id = ?1").run(runId); | |
| 351 | child.db.query("DELETE FROM issue WHERE id = 'i-' || ?1").run(runId); | |
| 352 | }; | |
| 353 | ||
| 354 | test("a running agent turns the line to working", async () => { | |
| 355 | startBuilding("r-client-1"); | |
| 340 | 356 | const home = await page(owner); |
| 341 | expect(home).toContain('data-agents="working"'); | |
| 342 | expect(home).toContain("One agent is working on it now."); | |
| 343 | child.db.query("DELETE FROM run WHERE id = 'r-client-1'").run(); | |
| 357 | expect(home).toContain('client-app-line"><b>Building: Add rye bread</b>'); | |
| 358 | expect(home).not.toContain("data-agents"); | |
| 359 | // The MCP door reads the same sentence for the same app. | |
| 360 | const view = forgeView({ app: child }, getUserByName(child.db, "maria")!); | |
| 361 | expect(view.apps.find((a) => a.app === "marias/bakery")?.line).toBe("Building: Add rye bread"); | |
| 362 | stopBuilding("r-client-1"); | |
| 344 | 363 | }); |
| 345 | 364 | |
| 346 | 365 | test("the card refreshes itself: /live/client-apps answers it, to a client only", async () => { |
| 347 | const repo = child.db | |
| 348 | .query<{ id: string }, []>("SELECT id FROM repo WHERE name = 'bakery'") | |
| 349 | .get()!; | |
| 350 | 366 | expect(await page(owner)).toContain('data-live-src="/live/client-apps"'); |
| 351 | child.db | |
| 352 | .query("INSERT INTO run (id, repo_id, kind, state) VALUES ('r-client-2', ?1, 'agent', 'running')") | |
| 353 | .run(repo.id); | |
| 367 | startBuilding("r-client-2"); | |
| 354 | 368 | const live = await page(owner, "/live/client-apps"); |
| 355 | 369 | expect(live).toContain('id="client-apps"'); |
| 356 | expect(live).toContain("One agent is working on it now."); | |
| 357 | child.db.query("DELETE FROM run WHERE id = 'r-client-2'").run(); | |
| 370 | expect(live).toContain('client-app-line"><b>Building: Add rye bread</b>'); | |
| 371 | stopBuilding("r-client-2"); | |
| 358 | 372 | expect((await fetch(url("/live/client-apps"))).status).toBe(404); |
| 359 | 373 | }); |
| 360 | 374 | |
| @@ -426,8 +440,7 @@ describe("a client's first screen", () => { | ||
| 426 | 440 | .query("INSERT INTO run (id, repo_id, kind, state) VALUES ('r-client-2', ?1, 'agent', 'queued')") |
| 427 | 441 | .run(repo.id); |
| 428 | 442 | const home = await page(owner); |
| 429 | expect(home).toContain("Its agents are about to start."); | |
| 430 | expect(home).toContain('data-agents="waiting"'); | |
| 443 | expect(home).toContain('client-app-line"><b>About to start</b>'); | |
| 431 | 444 | child.db.query("DELETE FROM run WHERE id = 'r-client-2'").run(); |
| 432 | 445 | }); |
| 433 | 446 | |
| @@ -459,7 +472,7 @@ describe("a client's first screen", () => { | ||
| 459 | 472 | ); |
| 460 | 473 | app.start(); |
| 461 | 474 | await settleApp(app); |
| 462 | expect(app.screen.toText()).toContain("bakery: Its agents are waiting for something to do."); | |
| 475 | expect(app.screen.toText()).toContain("bakery: Nothing in progress."); | |
| 463 | 476 | expect(app.screen.toText()).toMatch(/Atlas is ready to work toward Run Maria/); |
| 464 | 477 | expect(app.screen.toText()).not.toContain("Shipped per hour"); |
| 465 | 478 | app.stop(); |
| @@ -536,7 +549,7 @@ describe("a client's first screen", () => { | ||
| 536 | 549 | |
| 537 | 550 | test("a quiet app gets no extra line", async () => { |
| 538 | 551 | clean(); |
| 539 | expect(await row()).not.toContain("client-app-doing"); | |
| 552 | expect(await row()).toContain("Nothing in progress"); | |
| 540 | 553 | }); |
| 541 | 554 | |
| 542 | 555 | test("work running now reads Working on, escaped", async () => { |
| @@ -546,7 +559,7 @@ describe("a client's first screen", () => { | ||
| 546 | 559 | .query("INSERT INTO run (id, repo_id, kind, state, issue_id) VALUES ('r-doing-1', ?1, 'agent', 'running', 'i-doing-1')") |
| 547 | 560 | .run(ids().repo.id); |
| 548 | 561 | const r = await row(); |
| 549 | expect(r).toContain("Working on: Add <b>rye</b> bread"); | |
| 562 | expect(r).toContain("Building: Add <b>rye</b> bread"); | |
| 550 | 563 | expect(r).not.toContain("<b>rye"); |
| 551 | 564 | clean(); |
| 552 | 565 | }); |
| @@ -562,7 +575,6 @@ describe("a client's first screen", () => { | ||
| 562 | 575 | expect(r).toContain("3 days ago"); |
| 563 | 576 | expect(r).toContain("Fix the menu"); |
| 564 | 577 | expect(r).not.toContain("Last change"); |
| 565 | expect(r).not.toContain("client-app-doing"); | |
| 566 | 578 | clean(); |
| 567 | 579 | }); |
| 568 | 580 | |
| @@ -596,10 +608,10 @@ describe("a client's first screen", () => { | ||
| 596 | 608 | clean(); |
| 597 | 609 | }); |
| 598 | 610 | |
| 599 | test("the read is its own doing phase beside apps", async () => { | |
| 611 | test("the read is its own line phase beside apps", async () => { | |
| 600 | 612 | const res = await fetch(url("/"), { headers: { cookie: owner } }); |
| 601 | 613 | const timing = res.headers.get("server-timing") ?? ""; |
| 602 | expect(timing).toMatch(/\bdoing;/); | |
| 614 | expect(timing).toMatch(/\bline;/); | |
| 603 | 615 | expect(timing).toMatch(/\bapps;/); |
| 604 | 616 | }); |
| 605 | 617 | |
| @@ -617,7 +629,7 @@ describe("a client's first screen", () => { | ||
| 617 | 629 | ); |
| 618 | 630 | app.start(); |
| 619 | 631 | await settleApp(app); |
| 620 | expect(app.screen.toText()).toContain("Working on: Add rye bread"); | |
| 632 | expect(app.screen.toText()).toContain("bakery: Building: Add rye bread."); | |
| 621 | 633 | app.stop(); |
| 622 | 634 | clean(); |
| 623 | 635 | }); |
| @@ -650,7 +662,6 @@ describe("a client's first screen", () => { | ||
| 650 | 662 | expect(cut.endsWith("word…")).toBe(true); |
| 651 | 663 | expect(cutTitle("short title")).toBe("short title"); |
| 652 | 664 | expect(cutTitle("x".repeat(200))).toBe(`${"x".repeat(79)}…`); |
| 653 | expect(doingLine(undefined)).toBe(""); | |
| 654 | 665 | }); |
| 655 | 666 | }); |
| 656 | 667 | }); |
test/client-line.test.ts added +42
| @@ -0,0 +1,42 @@ | ||
| 1 | /** | |
| 2 | * The plain sentence about an app's crew (#14100): one running app, one idle, no developer words. | |
| 3 | */ | |
| 4 | import { beforeEach, describe, expect, test } from "bun:test"; | |
| 5 | import type { Database } from "bun:sqlite"; | |
| 6 | import { clientLines, IDLE_LINE, lineFor, QUEUED_LINE, WAITING_LINE } from "../src/actions/client_line.ts"; | |
| 7 | import type { Repo } from "../src/core/repos.ts"; | |
| 8 | import { migrations } from "../src/core/schema.ts"; | |
| 9 | import { openDb } from "../src/kernel/db.ts"; | |
| 10 | ||
| 11 | let db: Database; | |
| 12 | const repo = (id: string): Repo => ({ id }) as Repo; | |
| 13 | ||
| 14 | beforeEach(() => { | |
| 15 | db = openDb(":memory:", migrations); | |
| 16 | db.run("INSERT INTO user (id, username, email, password_hash) VALUES ('u','u','u@x','x')"); | |
| 17 | for (const r of ["busy", "idle", "next"]) db.run("INSERT INTO repo (id, owner_id, name) VALUES (?, 'u', ?)", [r, r]); | |
| 18 | }); | |
| 19 | ||
| 20 | describe("the sentence", () => { | |
| 21 | test("a running app says Building, an idle one says Nothing in progress, in words a client reads", () => { | |
| 22 | 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')"); | |
| 23 | db.run("INSERT INTO run (id, repo_id, kind, state, issue_id) VALUES ('r1','busy','agent','running','i1')"); | |
| 24 | db.run("INSERT INTO run (id, repo_id, kind, state) VALUES ('r2','next','agent','queued')"); | |
| 25 | const lines = clientLines(db, [repo("busy"), repo("idle"), repo("next")]); | |
| 26 | expect(lines.get("busy")).toBe("Building: the booking form"); | |
| 27 | expect(lines.get("idle")).toBe("Nothing in progress"); | |
| 28 | expect(lines.get("next")).toBe(QUEUED_LINE); | |
| 29 | for (const line of lines.values()) expect(line).not.toMatch(/\b(pull|check|run|gate)\b/i); | |
| 30 | }); | |
| 31 | ||
| 32 | test("work running wins over a wait; a wait on the person is said plainly", () => { | |
| 33 | expect(lineFor({ title: undefined, waitingOnPerson: true, queued: true })).toBe(WAITING_LINE); | |
| 34 | expect(lineFor({ title: "Menu", waitingOnPerson: true, queued: false })).toBe("Building: Menu"); | |
| 35 | expect(lineFor({ title: undefined, waitingOnPerson: false, queued: false })).toBe(IDLE_LINE); | |
| 36 | expect(lineFor({ title: "#7", waitingOnPerson: false, queued: false })).toBe("Building something new"); | |
| 37 | }); | |
| 38 | ||
| 39 | test("no apps, no sentences", () => { | |
| 40 | expect(clientLines(db, []).size).toBe(0); | |
| 41 | }); | |
| 42 | }); |
test/crew-now-review-waits.test.ts +6
| @@ -13,6 +13,7 @@ import { reviewed } from "../src/crew/autonomy.ts"; | ||
| 13 | 13 | import { reviewWaitsFor } from "../src/crew/review.ts"; |
| 14 | 14 | import { getRepoById } from "../src/core/repos.ts"; |
| 15 | 15 | import { getPull } from "../src/core/pulls.ts"; |
| 16 | import { clientLines, WAITING_LINE } from "../src/actions/client_line.ts"; | |
| 16 | 17 | import { crewNow } from "../src/actions/crew_now.ts"; |
| 17 | 18 | import { createAgent } from "../src/actions/crew.ts"; |
| 18 | 19 | import { openPull } from "../src/actions/pulls.ts"; |
| @@ -121,6 +122,11 @@ describe("crewNow's review waits", () => { | ||
| 121 | 122 | expect(nine.statements).toBe(one.statements); |
| 122 | 123 | }, 30_000); |
| 123 | 124 | |
| 125 | test("a client's sentence for the app says Waiting for your answer while a green pull waits for a person", async () => { | |
| 126 | await greenAgentPull(); | |
| 127 | expect(clientLines(app.db, [repo]).get(repo.id)).toBe(WAITING_LINE); | |
| 128 | }); | |
| 129 | ||
| 124 | 130 | test("in a repository with reviews off, a green agent pull waits on nobody and the gate passes it (#11666)", async () => { |
| 125 | 131 | const made = await createRepo(app, ada, { name: "meadow", visibility: "private" }); |
| 126 | 132 | if (!made.ok) throw new Error(String(made.error)); |
new above
offline
An empty-string fallback can ship a blank line to MCP clients; use IDLE_LINE or fail loudly.