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
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/13970-talk-shows-what-the-crew-is-doing-right → main 5 commits fork 7 threads · 7 unresolved
docs/design/areas/talk.md +1
| @@ -17,6 +17,7 @@ | ||
| 17 | 17 | - `.talk-meta` — who said it and when, with the copy button. |
| 18 | 18 | - `.talk-copy` — a quiet text button that copies a message or a code block. |
| 19 | 19 | - `.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. | |
| 20 | 21 | - `.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. |
| 21 | 22 | - `.talk-jump` — "Latest" button, shown when you have scrolled up from the end. |
| 22 | 23 | - `.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, | ||
| 20 | 20 | |
| 21 | 21 | 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. |
| 22 | 22 | |
| 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 | ||
| 23 | 27 | ## Naming the subject: `?about=` and `--about` |
| 24 | 28 | |
| 25 | 29 | `/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"; | ||
| 20 | 20 | import type { Ctx } from "../http/context.ts"; |
| 21 | 21 | import type { User } from "../core/users.ts"; |
| 22 | 22 | |
| 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) { | |
| 25 | 26 | const { repos } = appsOf(ctx, user); |
| 26 | 27 | const byId = new Map(repos.map((r) => [r.id, r])); |
| 27 | 28 | // 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) { | ||
| 36 | 37 | ctx.app.db, |
| 37 | 38 | runs.map((r) => r.actorId).filter((id): id is string => id !== null), |
| 38 | 39 | ); |
| 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}`, | |
| 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); | |
| 39 | 62 | // A planner that declined the direction is the crew waiting on you: |
| 40 | 63 | // it rides the same list, as a row with no run. |
| 41 | 64 | // 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) { | ||
| 89 | 112 | return [ |
| 90 | 113 | ...waiting, |
| 91 | 114 | ...reviewWaits, |
| 92 | ...runs.map((run) => { | |
| 93 | const repo = byId.get(run.repoId)!; | |
| 115 | ...live.map(({ run, repo, row }) => { | |
| 94 | 116 | // As this caller may read it (`runForReader`): cost and node are |
| 95 | 117 | // the owner's facts. |
| 96 | 118 | const r = runForReader(ctx.app, user, repo)(run); |
| 97 | const issue = | |
| 98 | r.issueId === null | |
| 99 | ? undefined | |
| 100 | : getIssueById(ctx.app.db, r.issueId); | |
| 101 | 119 | 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, | |
| 106 | 121 | why: r.reason, |
| 107 | 122 | state: r.state, |
| 108 | 123 | since: r.startedAt ?? r.createdAt, |
src/tui/ssh-talk.ts +10
| @@ -11,6 +11,8 @@ | ||
| 11 | 11 | * While an answer runs, `talk /queue <words>` keeps the words for after it |
| 12 | 12 | * (`talk /queued` lists what waits, `talk /unqueue <id>` takes one back) and |
| 13 | 13 | * `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). | |
| 14 | 16 | * |
| 15 | 17 | * `talk-again edit <words>`, `talk-again regenerate` and `talk-again retry` |
| 16 | 18 | * are the same three actions the page has (#8817), through `talkAgain`. |
| @@ -30,6 +32,8 @@ | ||
| 30 | 32 | import { cancelTalk, queuedTalk, TALK_WORDS, stopTalk, talk, talkAgain } from "../actions/talk.ts"; |
| 31 | 33 | import { FILE_WORDS, IMAGE_MAX, pendingAmong, removePending, storeFile } from "../core/conversation_files.ts"; |
| 32 | 34 | 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"; | |
| 33 | 37 | import { openConversation } from "../core/conversations.ts"; |
| 34 | 38 | import { aboutLine } from "../core/talk_about.ts"; |
| 35 | 39 | import type { App } from "../app.ts"; |
| @@ -121,6 +125,12 @@ export function serveTalk(app: App, session: SshSession, user: User | undefined, | ||
| 121 | 125 | session.write(waiting.length === 0 ? `nothing is waiting${CRLF}` : waiting.map((q) => `${q.id} ${q.text.slice(0, 80)}${CRLF}`).join("")); |
| 122 | 126 | return session.exit(0); |
| 123 | 127 | } |
outdated
Add |
||
| 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 | } | |
| 124 | 134 | const unqueue = /^\/unqueue[ \t]+(\S+)$/.exec(words.trim()); |
| 125 | 135 | if (unqueue !== null) { |
| 126 | 136 | 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 { | ||
| 14 | 14 | <ul class="list">${runs.map((r) => html`<li class="row"><span class="row-main"><span class="row-title">${r.what}</span> |
| 15 | 15 | <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>`; |
| 16 | 16 | } |
| 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 |
||
| 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"; | ||
| 57 | 57 | import { html, raw, type Html } from "../html.ts"; |
| 58 | 58 | import { flashTo, page, redirect } from "../layout.ts"; |
| 59 | 59 | import { linkRefs, refTarget } from "../../text/talk_links.ts"; |
| 60 | import { liveCrewRows } from "../../actions/crew_now.ts"; | |
| 61 | import { crewLineHtml } from "../crew_now.ts"; | |
| 60 | 62 | import { renderMarkdown } from "../markdown.ts"; |
| 61 | 63 | import { badge, btn, row, time } from "../ui.ts"; |
| 62 | 64 | import { buildBox, buildCss, chosenTemplate, panelFor } from "../talk_build.ts"; |
| @@ -399,6 +401,7 @@ async function talkPage(ctx: Ctx, conversation: Conversation, before0: string | | ||
| 399 | 401 | <div id="end"></div> |
| 400 | 402 | </div> |
| 401 | 403 | ${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. |
||
| 402 | 405 | <form class="talk-compose" id="compose" method="post" action="${editing === undefined ? here : `${here}/again/edit`}" ${editing === undefined ? null : html`data-edit`}> |
| 403 | 406 | ${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>`} |
| 404 | 407 | <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 */ ` | ||
| 30 | 30 | @media (max-width: 63.99rem) { |
| 31 | 31 | [data-pane]:not([data-pane="chat"]) :is(.talk, .talk-side), [data-pane="chat"] .talk-pane { display: none; } |
| 32 | 32 | } |
| 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. |
||
| 33 | 34 | .talk-log { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.625rem; min-width: 0; align-content: start; min-height: 40dvh; } |
| 34 | 35 | .talk-turn { min-width: 0; max-width: 100%; overflow-wrap: anywhere; word-break: break-word; } |
| 35 | 36 | .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 | }); |
This mapping repeats what crewNow does below (actor lookup, who/on wording). Share it so crewNow builds on liveCrewRows.