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

/talk shows what the crew is doing right now in one line above the box #13981

Merged opened this

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

Merged

scout/forge:scout/13970-talk-shows-what-the-crew-is-doing-right → main 5 commits fork 7 threads · 7 unresolved

  • Merged. scout/13970-talk-shows-what-the-crew-is-doing-right was merged into main as bf4e71b.

Review

Sign in to review this change.
8 files changed +197 −12
docs/design/areas/talk.md +1
@@ -17,6 +17,7 @@
1717 - `.talk-meta` — who said it and when, with the copy button.
1818 - `.talk-copy` — a quiet text button that copies a message or a code block.
1919 - `.talk-suggest` — the starter questions on an empty chat; each fills the composer.
20 - `.talk-crew` — the one line of the crew's live work (or "The crew is idle."), above the composer; a fixed one-line height that clips with an ellipsis, so it never shifts the page.
2021 - `.talk-about` — the one line naming the subject (`?about=`), above the composer; no rule of its own: it is plain `small muted` text that wraps like any paragraph.
2122 - `.talk-jump` — "Latest" button, shown when you have scrolled up from the end.
2223 - `.talk-chats` — the conversations list above the chat (#8814): New, the person's conversations newest first, and the Archived filter link.
docs/features/talk.md +4
@@ -20,6 +20,10 @@ A reply streams in over `GET /talk/stream?after=<turn id>` (server-sent events,
2020
2121 When the agent asks first (`needs_confirm`), the turn draws **Confirm** (the existing yes) and **Cancel** (a no: the confirm is spent, nothing runs, a turn says it was cancelled). A result shown once (an invite link) is drawn by Settings → Confirms instead, where Confirm leads.
2222
23 ## The crew's line
24
25 `/talk` shows one line above the composer from the live runs only (`liveCrewRows` in `src/actions/crew_now.ts`, with `crewNow`'s visibility filters but none of its planner or review-wait reads, so the common request stays fast): "The crew is working: <who> on <what>" (with the count first when several, "(3)") while an agent run is live, else "The crew is idle." It is rendered with the page, never polled, and holds a fixed one-line height so nothing shifts. The terminal twin is `ssh <forge> talk /crew`, which prints the same line (`crewLine()` in `src/web/crew_now.ts`); signed out it says the crew is idle.
26
2327 ## Naming the subject: `?about=` and `--about`
2428
2529 `/talk?about=owner/repo` or `/talk?about=owner/repo#N` (an issue or pull) puts one plain line above the composer: "About owner/repo" or "About owner/repo#N: <title>". The terminal twin is `ssh <forge> talk --about owner/repo[#N] [words]`: it prints the same line first, and with no words prints only that line. Both read one lookup, `aboutLine()` in `src/core/talk_about.ts`. A value that is malformed, names something unknown, or names something you cannot read (a private repository, a sealed issue, signed out) shows nothing and the page is byte-identical to plain `/talk`, so a private repository's existence is not revealed.
src/actions/crew_now.ts +27 −12
@@ -20,8 +20,9 @@ import { placementWords } from "../checks/placement.ts";
2020 import type { Ctx } from "../http/context.ts";
2121 import type { User } from "../core/users.ts";
2222
23 /** Rows of the crew's work as `user` may see them (none for no one). */
24 export function crewNow(ctx: Pick<Ctx, "app">, user: User) {
23 /** The live runs as `user` may see them, worded once (who, on what): no waits are read, so the
24 * /talk line costs one visibility-checked read of active runs. */
25 function liveRuns(ctx: Pick<Ctx, "app">, user: User) {
2526 const { repos } = appsOf(ctx, user);
2627 const byId = new Map(repos.map((r) => [r.id, r]));
2728 // A private app's runs are for those who may enter it (`mayReadRuns`).
@@ -36,6 +37,28 @@ export function crewNow(ctx: Pick<Ctx, "app">, user: User) {
3637 ctx.app.db,
3738 runs.map((r) => r.actorId).filter((id): id is string => id !== null),
3839 );
40 const live = runs.map((run) => {
41 const repo = byId.get(run.repoId)!;
42 const issue = run.issueId === null ? undefined : getIssueById(ctx.app.db, run.issueId);
43 const row = {
44 run: run.id,
45 app: `${repo.ownerName}/${repo.name}`,
46 who: (run.actorId && actors.get(run.actorId)?.username) || "the crew",
47 on: issue === undefined ? null : `#${issue.number} ${issue.title}`,
outdated

This mapping repeats what crewNow does below (actor lookup, who/on wording). Share it so crewNow builds on liveCrewRows.

48 };
49 return { run, repo, row };
50 });
51 return { repos, byId, live };
52 }
53
54 /** Who works on what, for the live runs only: the rows `crewLine` words. */
55 export function liveCrewRows(ctx: Pick<Ctx, "app">, user: User) {
56 return liveRuns(ctx, user).live.map((l) => l.row);
57 }
58
59 /** Rows of the crew's work as `user` may see them (none for no one). */
60 export function crewNow(ctx: Pick<Ctx, "app">, user: User) {
61 const { repos, byId, live } = liveRuns(ctx, user);
3962 // A planner that declined the direction is the crew waiting on you:
4063 // it rides the same list, as a row with no run.
4164 // Owner facts only: a stranger's public app never shows its planner here.
@@ -89,20 +112,12 @@ export function crewNow(ctx: Pick<Ctx, "app">, user: User) {
89112 return [
90113 ...waiting,
91114 ...reviewWaits,
92 ...runs.map((run) => {
93 const repo = byId.get(run.repoId)!;
115 ...live.map(({ run, repo, row }) => {
94116 // As this caller may read it (`runForReader`): cost and node are
95117 // the owner's facts.
96118 const r = runForReader(ctx.app, user, repo)(run);
97 const issue =
98 r.issueId === null
99 ? undefined
100 : getIssueById(ctx.app.db, r.issueId);
101119 return {
102 run: r.id,
103 app: `${repo.ownerName}/${repo.name}`,
104 who: (r.actorId && actors.get(r.actorId)?.username) || "the crew",
105 on: issue === undefined ? null : `#${issue.number} ${issue.title}`,
120 ...row,
106121 why: r.reason,
107122 state: r.state,
108123 since: r.startedAt ?? r.createdAt,
src/tui/ssh-talk.ts +10
@@ -11,6 +11,8 @@
1111 * While an answer runs, `talk /queue <words>` keeps the words for after it
1212 * (`talk /queued` lists what waits, `talk /unqueue <id>` takes one back) and
1313 * `talk /steer <words>` stops the answer and sends them at once (#8819).
14 * `talk /crew` prints the one line /talk shows above its box: the crew's
15 * live work, or that it is idle (#13970).
1416 *
1517 * `talk-again edit <words>`, `talk-again regenerate` and `talk-again retry`
1618 * are the same three actions the page has (#8817), through `talkAgain`.
@@ -30,6 +32,8 @@
3032 import { cancelTalk, queuedTalk, TALK_WORDS, stopTalk, talk, talkAgain } from "../actions/talk.ts";
3133 import { FILE_WORDS, IMAGE_MAX, pendingAmong, removePending, storeFile } from "../core/conversation_files.ts";
3234 import { contextOf, contextText, conversationTotal, dollars, spendWords, totalText, turnSpend, type Spend } from "../core/conversation_cost.ts";
35 import { liveCrewRows } from "../actions/crew_now.ts";
36 import { crewLine } from "../web/crew_now.ts";
3337 import { openConversation } from "../core/conversations.ts";
3438 import { aboutLine } from "../core/talk_about.ts";
3539 import type { App } from "../app.ts";
@@ -121,6 +125,12 @@ export function serveTalk(app: App, session: SshSession, user: User | undefined,
121125 session.write(waiting.length === 0 ? `nothing is waiting${CRLF}` : waiting.map((q) => `${q.id} ${q.text.slice(0, 80)}${CRLF}`).join(""));
122126 return session.exit(0);
123127 }
outdated

Add /crew to the command list in this file's header comment next to /queue, /queued, /unqueue.

128 // `/crew` prints the one line /talk shows above its box: the crew's live work, or that it is
129 // idle.
130 if (words.trim() === "/crew") {
131 session.write(`${crewLine(user === undefined ? [] : liveCrewRows({ app }, user))}${CRLF}`);
132 return session.exit(0);
133 }
124134 const unqueue = /^\/unqueue[ \t]+(\S+)$/.exec(words.trim());
125135 if (unqueue !== null) {
126136 if (!cancelTalk(app, user, unqueue[1]!)) return refuse("that message already went, or was never waiting");
src/web/crew_now.ts +24
@@ -14,3 +14,27 @@ export function crewNowHtml(runs: readonly CrewRun[]): Html {
1414 <ul class="list">${runs.map((r) => html`<li class="row"><span class="row-main"><span class="row-title">${r.what}</span>
1515 <span class="row-meta">${r.who} on ${r.repo}</span></span><span class="row-trail muted small">${STATE_WORDS[r.state]}</span></li>`)}</ul></section>`;
1616 }
17
18 /** The one line /talk shows above its box: the crew's live work, or that it is idle. */
19 export const CREW_IDLE = "The crew is idle.";
20
21 interface LiveRow {
22 readonly run: string;
23 readonly who: string;
24 readonly on: string | null;
25 readonly app: string;
26 }
27
28 /** Words for the live runs (`liveCrewRows`). */
29 export function crewLine(live: readonly LiveRow[]): string {
30 const first = live[0];
31 if (first === undefined) return CREW_IDLE;
outdated

Dead filter: liveCrewRows never returns run null. Remove it and make run non-null in LiveRow (#8 plain, no code for a case that cannot occur).

32 // The count comes first so a clipped tail never hides it.
33 const count = live.length > 1 ? ` (${live.length})` : "";
34 return `The crew is working${count}: ${first.who} on ${first.on ?? first.app}.`;
outdated

Principle 8 / correctness: put the count first ("The crew is working (3): ada on #3 ...") or truncate only the title, so the ellipsis never clips "and N more". Add a test with a long title and several runs.

35 }
36
37 /** Always one line of fixed height, so the words arriving move nothing. */
38 export function crewLineHtml(rows: readonly LiveRow[]): Html {
39 return html`<p class="talk-crew small muted" data-crew-now>${crewLine(rows)}</p>`;
40 }
src/web/pages/talk.ts +3
@@ -57,6 +57,8 @@ import { readForm } from "../form.ts";
5757 import { html, raw, type Html } from "../html.ts";
5858 import { flashTo, page, redirect } from "../layout.ts";
5959 import { linkRefs, refTarget } from "../../text/talk_links.ts";
60 import { liveCrewRows } from "../../actions/crew_now.ts";
61 import { crewLineHtml } from "../crew_now.ts";
6062 import { renderMarkdown } from "../markdown.ts";
6163 import { badge, btn, row, time } from "../ui.ts";
6264 import { buildBox, buildCss, chosenTemplate, panelFor } from "../talk_build.ts";
@@ -399,6 +401,7 @@ async function talkPage(ctx: Ctx, conversation: Conversation, before0: string |
399401 <div id="end"></div>
400402 </div>
401403 ${aboutLine(ctx)}
404 ${crewLineHtml(liveCrewRows(ctx, user))}
outdated

crewNow computes planner declines and review waits for every /talk render and crewLine discards them. Read only live runs (extract the listActiveRuns part of crewNow, or add a runs-only export in src/actions/crew_now.ts) and keep the same visibility filters. Keep the 50 ms common request.

402405 <form class="talk-compose" id="compose" method="post" action="${editing === undefined ? here : `${here}/again/edit`}" ${editing === undefined ? null : html`data-edit`}>
403406 ${conversation.archivedAt === null ? null : html`<p class="small muted" data-archived-note>Archived: sending here keeps it archived; Restore puts it back in the list.</p>`}
404407 <p class="talk-status small muted" role="status">${running ? "The forge is answering…" : ""}</p>
src/web/pages/talk_client.ts +1
@@ -30,6 +30,7 @@ export const talkCss = /* css */ `
3030 @media (max-width: 63.99rem) {
3131 [data-pane]:not([data-pane="chat"]) :is(.talk, .talk-side), [data-pane="chat"] .talk-pane { display: none; }
3232 }
33 .talk-crew { margin: 0.625rem 0; height: 1.5em; line-height: 1.5em; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
outdated

Principle 3: margin:0 with a fixed 1.5em height leaves the line tight against .talk-about and the composer; give it the same rhythm gap as its neighbours (use the spacing token) while keeping the fixed height so nothing shifts.

3334 .talk-log { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.625rem; min-width: 0; align-content: start; min-height: 40dvh; }
3435 .talk-turn { min-width: 0; max-width: 100%; overflow-wrap: anywhere; word-break: break-word; }
3536 .talk-turn p { margin: 0 0 8px; }
test/talk-crew-now.test.ts added +127
@@ -0,0 +1,127 @@
1 /**
2 * /talk shows the crew's live work in one server-rendered line above the box, and says the crew
3 * is idle when no run is live (#13970).
4 */
5 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
6 import { mkdtemp, rm } from "node:fs/promises";
7 import { tmpdir } from "node:os";
8 import { join } from "node:path";
9 import { createApp, type App } from "../src/app.ts";
10 import { createRepo } from "../src/actions/repos.ts";
11 import { createApp as createAppRecord } from "../src/core/apps.ts";
12 import { createIssue } from "../src/core/issues.ts";
13 import { createRun } from "../src/core/runs.ts";
14 import { createSession } from "../src/core/sessions.ts";
15 import { serve, type Servers } from "../src/http/server.ts";
16 import { crewLine, CREW_IDLE } from "../src/web/crew_now.ts";
17 import type { SshSession } from "../src/ssh/server.ts";
18 import { serveTalk } from "../src/tui/ssh-talk.ts";
19 import { createUser, getUserById } from "../src/core/users.ts";
20 import { seedAdmin } from "./helpers/admin.ts";
21 import { quietLogs } from "./helpers/globals.ts";
22
23 quietLogs();
24
25 describe("/talk crew line", () => {
26 let dir: string;
27 let app: App;
28 let servers: Servers;
29 let cookie: string;
30 let repoId: string;
31 let userId: string;
32 let bobCookie: string;
33 const talk = async (c = cookie) => (await fetch(`${servers.url}/talk`, { headers: { cookie: c } })).text();
34 const line = (h: string) => /<p class="talk-crew[^>]*>([^<]*)<\/p>/.exec(h)?.[1];
35
36 beforeAll(async () => {
37 dir = await mkdtemp(join(tmpdir(), "forge-talk-crew-"));
38 app = createApp({ dataDir: dir, port: 0 });
39 servers = await serve(app);
40 const a = await seedAdmin(app, { username: "ada", email: "[email protected]" });
41 if (!a.ok) throw new Error(a.error);
42 userId = a.value.id;
43 cookie = `forge_session=${createSession(app.db, userId).token}`;
44 const repo = await createRepo(app, a.value, { name: "hello", visibility: "public" });
45 if (!repo.ok) throw new Error(String(repo.error));
46 repoId = repo.value.id;
47 createAppRecord(app.db, { repoId, slug: "hello", access: "public" });
48 const bob = await createUser(app.db, {
49 origin: "seed", trusted: true, username: "bob", email: "[email protected]", password: "a-good-passphrase",
50 });
51 if (!bob.ok) throw new Error(bob.error);
52 bobCookie = `forge_session=${createSession(app.db, bob.value.id).token}`;
53 });
54 afterAll(async () => {
55 await servers.stop();
56 app.close();
57 await rm(dir, { recursive: true, force: true });
58 });
59
60 test("idle when nobody works", async () => {
outdated

Add a visibility test: a live run on a private app or sealed issue must not show for a guest/non-member on /talk (it says idle). That is the security claim of the pull and no test would fail if the filter were dropped.

61 expect(line(await talk())).toBe(CREW_IDLE);
62 });
63
64 test("signed out, /talk asks for sign-in and shows no crew line", async () => {
65 const h = await (await fetch(`${servers.url}/talk`)).text();
66 expect(line(h)).toBeUndefined();
67 });
68
69 test("a private app's run and a sealed report's run show only to who may see them", async () => {
70 const ada = getUserById(app.db, userId)!;
71 const secret = await createRepo(app, ada, { name: "secret", visibility: "private" });
72 if (!secret.ok) throw new Error(String(secret.error));
73 createAppRecord(app.db, { repoId: secret.value.id, slug: "secret", access: "private" });
74 createRun(app.db, { repoId: secret.value.id, kind: "agent", reason: "work" });
75 const sealed = createIssue(app.db, { repoId, authorId: userId, title: "the hole", sealed: true });
76 if (!sealed.ok) throw new Error("issue");
77 createRun(app.db, { repoId, kind: "agent", issueId: sealed.value.id, reason: "work" });
78 expect(line(await talk(bobCookie))).toBe(CREW_IDLE);
79 expect(line(await talk())).toStartWith("The crew is working (2):");
80 });
81
82 test("busy names who works on what", async () => {
83 const issue = createIssue(app.db, { repoId, authorId: userId, title: "round the corners" });
84 if (!issue.ok) throw new Error("issue");
85 createRun(app.db, { repoId, kind: "agent", issueId: issue.value.id, reason: "work" });
86 const text = line(await talk());
87 expect(text).toStartWith("The crew is working (3):");
88 // A public app's run on a plain issue is the non-member's to see.
89 expect(line(await talk(bobCookie))).toBe("The crew is working: the crew on #2 round the corners.");
90 });
91
92 test("the terminal prints the same line: `talk /crew`", () => {
93 const run = (user: Parameters<typeof serveTalk>[2]) => {
94 let out = "";
95 const session: SshSession = {
96 key: { algo: "ssh-ed25519", blob: new Uint8Array(), fingerprint: "", line: "" },
97 username: "ada", remoteAddress: "203.0.113.9", kind: "exec", command: "talk /crew", term: undefined, env: {},
98 cols: 0, rows: 0, widthPx: 0, heightPx: 0, ended: false, pending: 0,
99 write: (d: Uint8Array | string) => void (out += typeof d === "string" ? d : Buffer.from(d).toString()),
100 writeStderr() {}, onData() {}, onResize() {}, onEof() {}, onClose() {}, exit() {}, drain: async () => {},
101 };
102 serveTalk(app, session, user, "/crew");
103 return out;
104 };
105 const ada = getUserById(app.db, userId);
106 expect(run(ada)).toStartWith("The crew is working (3):");
107 expect(run(undefined)).toBe(`${CREW_IDLE}\r\n`);
108 });
109
110 test("the line is plain words", () => {
111 expect(crewLine([])).toBe(CREW_IDLE);
112 expect(crewLine([{ run: "r", who: "the crew", on: null, app: "a/b" }, { run: "s", who: "x", on: null, app: "a/c" }])).toBe(
113 "The crew is working (2): the crew on a/b.",
114 );
115 });
116
117 test("the count leads, so a long title clipped by the ellipsis never hides it", () => {
118 const long = `#1 ${"very long title ".repeat(20)}`;
119 const w = crewLine([
120 { run: "a", who: "ada", on: long, app: "a/b" },
121 { run: "b", who: "x", on: null, app: "a/c" },
122 { run: "c", who: "y", on: null, app: "a/d" },
123 ]);
124 expect(w.startsWith("The crew is working (3): ada on #1 ")).toBe(true);
125 expect(w).not.toContain("more");
126 });
127 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs