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

On a client's first screen each app says in plain words what its agents are doing now, or what last changed #4005

Parked opened this
Closed without merging

scout/forge:scout/3344-on-a-client-s-first-screen-each-app-says → main 4 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
6 files changed +242 −7
README.md +6 −2
@@ -331,8 +331,12 @@ On a forge made for a client (one that was spawned, signed in by its claim
331331 link), the home is their apps, one plain sentence each and one more saying
332332 whether its agents are working, about to start, or waiting: no map, board or
333333 settings until asked. `/?all=1` is the whole home, and its "Just my apps" link
334 comes back. The terminal's first screen opens with the same lines, from the
335 same query (`src/core/client-apps.ts`).
334 comes back. A third line says "Working on: <title>" while an agent run is
335 going, else "Last change: <title>, 3 days ago" when something landed in the
336 last 7 days, else nothing (titles cut to 80 characters; `clientDoings` and
337 `doingLine` in `src/core/client-apps.ts`, one bounded read, the `doing`
338 Server-Timing phase). The terminal's first screen opens with the same lines,
339 from the same code.
336340
337341 Home shows nine figures first, from `src/flow/kpis.ts`: shipped per hour (with
338342 a 24 h sparkline), the live version and since when, the median check time, the crew builders
src/core/client-apps.ts +68
@@ -4,6 +4,7 @@
44 * The web home and the terminal both read it, so they cannot disagree.
55 */
66
7 import { ago } from "../feed/rank.ts";
78 import type { App } from "../app.ts";
89 import { spawnedRepos } from "./next-steps.ts";
910 import { withoutArchived, type Repo } from "./repos.ts";
@@ -39,3 +40,70 @@ export async function clientAppRows(
3940 return { repo, working: n("running"), queued: n("queued") };
4041 });
4142 }
43
44 /** What an app's agents are doing now, or what last landed in the past week. */
45 export interface Doing {
46 readonly kind: "working" | "landed";
47 readonly title: string;
48 /** Epoch milliseconds the work started or landed. */
49 readonly at: number;
50 }
51
52 const LANDED_WINDOW_MS = 7 * 24 * 3600 * 1000;
53
54 /**
55 * One bounded read: per app, the title of the issue a run is working on, else
56 * the newest change that landed in the last 7 days. Apps with neither are absent.
57 */
58 export function clientDoings(
59 app: App,
60 repoIds: readonly string[],
61 now: number = Date.now(),
62 ): ReadonlyMap<string, Doing> {
63 const out = new Map<string, Doing>();
64 if (repoIds.length === 0) return out;
65 const marks = repoIds.map((_, i) => `?${i + 2}`).join(",");
66 const rows = app.db
67 .query<
68 { repo_id: string; what: "working" | "landed"; title: string; at: string | null },
69 string[]
70 >(
71 `SELECT r.repo_id, 'working' AS what, i.title, COALESCE(r.started_at, r.created_at) AS at
72 FROM run r JOIN issue i ON i.id = r.issue_id
73 WHERE r.kind = 'agent' AND r.state = 'running' AND r.repo_id IN (${marks})
74 UNION ALL
75 SELECT i.repo_id, 'landed', i.title, MAX(p.merged_at)
76 FROM pull p JOIN issue i ON i.id = p.issue_id
77 WHERE p.merged_at >= ?1 AND i.repo_id IN (${marks})
78 GROUP BY i.repo_id
79 ORDER BY 4 DESC`,
80 )
81 .all(new Date(now - LANDED_WINDOW_MS).toISOString(), ...repoIds);
82 for (const row of rows) {
83 const at = Date.parse(row.at ?? "");
84 const have = out.get(row.repo_id);
85 if (have !== undefined && (have.kind === "working" || row.what === "landed")) continue;
86 out.set(row.repo_id, { kind: row.what, title: row.title, at: Number.isNaN(at) ? now : at });
87 }
88 return out;
89 }
90
91 const TITLE_MAX = 80;
92
93 /** A title cut to 80 characters at a word boundary, with an ellipsis when cut. */
94 export function trimTitle(title: string): string {
95 const t = title.replace(/\s+/g, " ").trim();
96 if (t.length <= TITLE_MAX) return t;
97 const cut = t.slice(0, TITLE_MAX);
98 const space = cut.lastIndexOf(" ");
99 return `${(space > 0 ? cut.slice(0, space) : cut).replace(/[\s.,;:!-]+$/, "")}…`;
100 }
101
102 /** The plain sentence about the work: what is going now, or what last landed; else nothing. */
103 export function doingLine(doing: Doing | undefined, now: number = Date.now()): string {
104 if (doing === undefined) return "";
105 const title = trimTitle(doing.title);
106 return doing.kind === "working"
107 ? `Working on: ${title}`
108 : `Last change: ${title}, ${ago(doing.at, now)}`;
109 }
src/tui/screens/dashboard.ts +9 −4
@@ -20,7 +20,7 @@ import { forgeLane, forgeNeeds } from "../../actions/health.ts";
2020 import { ownerWaits, waitLine, withMore } from "../../actions/owner_waits.ts";
2121 import { forgeHealth } from "../../kernel/guard.ts";
2222 import { coveredByVerdict, forgeVerdict, verdictLine } from "../../kernel/guard_verdict.ts";
23 import { clientAppRows } from "../../core/client-apps.ts";
23 import { clientAppRows, clientDoings, doingLine } from "../../core/client-apps.ts";
2424 import { nextStepsFor } from "../../core/next-steps.ts";
2525 import { agentsLine } from "../../web/studio/client_home.ts";
2626 import { mayView } from "../../core/sealed.ts";
@@ -186,12 +186,17 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
186186 // A client's home never carries the forge-wide figures, on either door.
187187 figures = [];
188188 const apps = await clientAppRows(f.app, f.user);
189 const doings = clientDoings(f.app, apps.map((a) => a.repo.id));
189190 clientLines =
190191 apps.length === 0
191192 ? ["Your apps will appear here."]
192 : apps.map(
193 (a) => `${a.repo.name}: ${agentsLine(a.working, a.queued)}`,
194 );
193 : apps.flatMap((a) => {
194 const doing = doingLine(doings.get(a.repo.id));
195 return [
196 `${a.repo.name}: ${agentsLine(a.working, a.queued)}`,
197 ...(doing === "" ? [] : [` ${doing}`]),
198 ];
199 });
195200 ctx.invalidate();
196201 };
197202
src/web/studio/client_home.ts +6 −1
@@ -7,7 +7,7 @@
77 */
88
99 import { notePhase, takeSessionTime, timePhaseAsync } from "../../core/route_timing.ts";
10 import { clientAppRows } from "../../core/client-apps.ts";
10 import { clientAppRows, clientDoings, doingLine } from "../../core/client-apps.ts";
1111 import type { User } from "../../core/users.ts";
1212 import type { Ctx } from "../../http/context.ts";
1313 import { repoBase } from "../chrome.ts";
@@ -28,15 +28,20 @@ export function agentsLine(working: number, queued: number): string {
2828 export async function clientApps(ctx: Ctx, user: User): Promise<Html> {
2929 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
3030 const apps = await timePhaseAsync(ctx.request, "apps", () => clientAppRows(ctx.app, user));
31 const doings = await timePhaseAsync(ctx.request, "doing", async () =>
32 clientDoings(ctx.app, apps.map((a) => a.repo.id)),
33 );
3134 const rendering = performance.now();
3235 const rows = apps.map(({ repo, working, queued }) => {
3336 const about = repo.description !== "" ? repo.description : "An app of yours.";
37 const doing = doingLine(doings.get(repo.id));
3438 return html`<li class="client-app">
3539 <a href="${repoBase(repo)}"><b>${repo.name}</b></a>
3640 <span class="client-app-about">${about}</span>
3741 <span class="client-app-agents muted" data-agents="${working > 0 ? "working" : "waiting"}"
3842 >${agentsLine(working, queued)}</span
3943 >
44 ${doing !== "" ? html`<span class="client-app-doing muted">${doing}</span>` : ""}
4045 </li>`;
4146 });
4247 const shown = card(
src/web/studio/style.ts +11
@@ -32,6 +32,11 @@ const wordBadges = part(/* css */ `
3232
3333 /** The phone: one document, narrower. Each rule belongs to a component above
3434 * and only ever applies at 600px and under, so nothing changes on a desktop. */
35 const clientApps = part(/* css */ `
36 .client-app { display: grid; gap: 2px; }
37 .client-app-doing { overflow-wrap: anywhere; }
38 `);
39
3540 const phone = part(/* css */ `
3641 @media (max-width: 600px) {
3742 .feed .card-head { row-gap: 2px; }
@@ -44,6 +49,12 @@ import { feedCss } from "./feed_style.ts";
4449 export const studioCss = `@layer components {\n${[
4550 justChanged,
4651 wordBadges,
52 <<<<<<< HEAD
53 rows,
54 rowActions,
55 clientApps,
56 =======
57 >>>>>>> origin/main
4758 part(feedCss),
4859 phone,
4960 ].join("\n\n")}\n}`;
test/client-home.test.ts +142
@@ -25,6 +25,8 @@ import { firstBoot } from "../src/spawn/first-boot.ts";
2525 import { hostedPlacement } from "../src/spawn/placement.ts";
2626 import { createForgeApp } from "../src/tui/forge.ts";
2727 import { headlessTerminal } from "../src/tui/term/terminal.ts";
28 import { studioCss } from "../src/web/studio/style.ts";
29 import { clientDoings, trimTitle } from "../src/core/client-apps.ts";
2830 import { quietLogs } from "./helpers/globals.ts";
2931 import { settleApp } from "./helpers/tui.ts";
3032 import { passkeyFields } from "./helpers/passkey.ts";
@@ -279,6 +281,146 @@ describe("a client's first screen", () => {
279281 expect(home).not.toContain('href="/marias/bakery"');
280282 });
281283
284 describe("what the agents are doing", () => {
285 const seed = (): { repo: string; maria: string } => ({
286 repo: child.db.query<{ id: string }, []>("SELECT id FROM repo WHERE name = 'bakery'").get()!.id,
287 maria: getUserByName(child.db, "maria")!.id,
288 });
289 const issue = (id: string, n: number, title: string, kind = "issue"): void => {
290 const { repo, maria } = seed();
291 child.db
292 .query("INSERT INTO issue (id, repo_id, number, kind, title, author_id) VALUES (?1, ?2, ?3, ?4, ?5, ?6)")
293 .run(id, repo, n, kind, title, maria);
294 };
295 const clean = (): void => {
296 child.db.query("DELETE FROM run WHERE id LIKE 'r-doing-%'").run();
297 child.db.query("DELETE FROM issue WHERE id LIKE 'i-doing-%'").run();
298 };
299
300 test("a quiet app shows neither sentence", async () => {
301 const home = await page(owner);
302 expect(home).not.toContain("Working on:");
303 expect(home).not.toContain("Last change:");
304 });
305
306 test("a working run shows its title, escaped", async () => {
307 issue("i-doing-1", 901, "Add <b>opening hours</b>");
308 child.db
309 .query("INSERT INTO run (id, repo_id, kind, state, issue_id) VALUES ('r-doing-1', ?1, 'agent', 'running', 'i-doing-1')")
310 .run(seed().repo);
311 const home = await page(owner);
312 expect(home).toContain("Working on: Add &lt;b&gt;opening hours&lt;/b&gt;");
313 expect(home).not.toContain("<b>opening hours");
314 clean();
315 });
316
317 test("a change that landed in the week shows its title and time; an old one does not", async () => {
318 issue("i-doing-2", 902, "Fix the menu", "pull");
319 const merge = (at: string): void => {
320 child.db.query("DELETE FROM pull WHERE issue_id = 'i-doing-2'").run();
321 child.db
322 .query("INSERT INTO pull (issue_id, base_branch, head_branch, base_oid, head_oid, merged_at) VALUES ('i-doing-2', 'main', 'x', 'a', 'b', ?1)")
323 .run(at);
324 };
325 merge(new Date(Date.now() - 3 * 24 * 3600 * 1000).toISOString());
326 expect(await page(owner)).toContain("Last change: Fix the menu, 3 days ago");
327 merge(new Date(Date.now() - 9 * 24 * 3600 * 1000).toISOString());
328 expect(await page(owner)).not.toContain("Last change:");
329 child.db.query("DELETE FROM pull WHERE issue_id = 'i-doing-2'").run();
330 clean();
331 });
332
333 test("work in progress wins over a landed change", async () => {
334 issue("i-doing-3", 903, "Done thing", "pull");
335 child.db
336 .query("INSERT INTO pull (issue_id, base_branch, head_branch, base_oid, head_oid, merged_at) VALUES ('i-doing-3', 'main', 'x', 'a', 'b', ?1)")
337 .run(new Date().toISOString());
338 issue("i-doing-4", 904, "Current thing");
339 child.db
340 .query("INSERT INTO run (id, repo_id, kind, state, issue_id) VALUES ('r-doing-4', ?1, 'agent', 'running', 'i-doing-4')")
341 .run(seed().repo);
342 const home = await page(owner);
343 expect(home).toContain("Working on: Current thing");
344 expect(home).not.toContain("Last change:");
345 child.db.query("DELETE FROM pull WHERE issue_id = 'i-doing-3'").run();
346 clean();
347 });
348
349 test("titles are cut to 80 characters at a word boundary", () => {
350 const long = `${"word ".repeat(30)}end`;
351 const cut = trimTitle(long);
352 expect(cut.length).toBeLessThanOrEqual(81);
353 expect(cut.endsWith("word…")).toBe(true);
354 expect(trimTitle("Short")).toBe("Short");
355 });
356
357 test("a queued or finished run, or one with no issue, shows no Working on", async () => {
358 issue("i-doing-5", 905, "Queued thing");
359 const { repo } = seed();
360 const run = (id: string, state: string, issueId: string | null): void => {
361 child.db
362 .query("INSERT INTO run (id, repo_id, kind, state, issue_id) VALUES (?1, ?2, 'agent', ?3, ?4)")
363 .run(id, repo, state, issueId);
364 };
365 run("r-doing-5", "queued", "i-doing-5");
366 run("r-doing-6", "ok", "i-doing-5");
367 run("r-doing-7", "running", null);
368 expect(await page(owner)).not.toContain("Working on:");
369 clean();
370 });
371
372 test("the terminal says the same, and the line is muted on the page", async () => {
373 issue("i-doing-6", 906, "Terminal thing");
374 child.db
375 .query("INSERT INTO run (id, repo_id, kind, state, issue_id) VALUES ('r-doing-8', ?1, 'agent', 'running', 'i-doing-6')")
376 .run(seed().repo);
377 expect(await page(owner)).toContain('class="client-app-doing muted"');
378 const maria = getUserByName(child.db, "maria")!;
379 const terminal = headlessTerminal(120, 30);
380 const { app } = createForgeApp(
381 child,
382 { sshUsername: "maria", remoteAddress: "127.0.0.1", fingerprint: "SHA256:t", user: maria },
383 { terminal, exitHooks: false },
384 );
385 app.start();
386 await settleApp(app);
387 expect(app.screen.toText()).toContain("Working on: Terminal thing");
388 app.stop();
389 clean();
390 });
391
392 test("with two runs going the newest wins; an unreadable start time falls back to now", async () => {
393 issue("i-doing-9", 909, "Older thing");
394 issue("i-doing-10", 910, "Newer thing");
395 const { repo } = seed();
396 const run = (id: string, issueId: string, at: string): void => {
397 child.db
398 .query("INSERT INTO run (id, repo_id, kind, state, issue_id, started_at) VALUES (?1, ?2, 'agent', 'running', ?3, ?4)")
399 .run(id, repo, issueId, at);
400 };
401 run("r-doing-9", "i-doing-9", "2026-01-01T00:00:00.000Z");
402 run("r-doing-10", "i-doing-10", "2026-01-02T00:00:00.000Z");
403 const home = await page(owner);
404 expect(home).toContain("Working on: Newer thing");
405 expect(home).not.toContain("Older thing");
406 child.db.query("DELETE FROM run WHERE id = 'r-doing-10'").run();
407 child.db.query("UPDATE run SET started_at = 'not a date' WHERE id = 'r-doing-9'").run();
408 const doings = clientDoings(child, [repo]);
409 expect(doings.get(repo)?.title).toBe("Older thing");
410 expect(Math.abs((doings.get(repo)?.at ?? 0) - Date.now())).toBeLessThan(5000);
411 clean();
412 });
413
414 test("each app's sentences stack, one to a line", () => {
415 expect(studioCss).toMatch(/\.client-app\s*\{[^}]*display:\s*grid/);
416 });
417
418 test("the read is its own Server-Timing phase", async () => {
419 const res = await fetch(url("/"), { headers: { cookie: owner } });
420 expect(res.headers.get("server-timing") ?? "").toContain("doing");
421 });
422 });
423
282424 test("the terminal's first screen says the same about each app", async () => {
283425 const maria = getUserByName(child.db, "maria")!;
284426 const terminal = headlessTerminal(120, 30);

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs