Public: anyone can read this; the crew can change it.
Talk: the crew line speaks only of the conversation's own app, never another repository's runs #17582
Merged 24h 42m ago, live in production
talk-crew-line → main 0 commits 1 thread · 1 unresolved
5 files
changed +56
−20
src/web/crew_now.ts +6
| @@ -25,6 +25,12 @@ interface LiveRow { | ||
| 25 | 25 | readonly app: string; |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | /** | |
| 29 | * The live runs on one repository (`owner/name`): Talk's line speaks only of the conversation's own | |
| 30 | * app. | |
| 31 | */ | |
| 32 | export const crewOn = <R extends LiveRow>(live: readonly R[], repo: string): R[] => live.filter((r) => r.app === repo); | |
| 33 | ||
| 28 | 34 | /** Words for the live runs (`liveCrewRows`). */ |
| 29 | 35 | export function crewLine(live: readonly LiveRow[]): string { |
| 30 | 36 | const first = live[0]; |
src/web/pages/talk.ts +8 −4
| @@ -74,7 +74,7 @@ import { codePaneCss } from "../talk_code.ts"; | ||
| 74 | 74 | import { linkRefs, refTarget } from "../../text/talk_links.ts"; |
| 75 | 75 | import { appLook, linkTalk, talkLook, type TalkLook } from "../../text/talk_link_words.ts"; |
| 76 | 76 | import { liveCrewRows } from "../../actions/crew_now.ts"; |
| 77 | import { crewLine } from "../crew_now.ts"; | |
| 77 | import { crewLine, crewOn } from "../crew_now.ts"; | |
| 78 | 78 | import { agentHtml, liveHtml, voiceCss, voiceOf, type Voice } from "../talk_parts.ts"; |
| 79 | 79 | import { badge, btn, icon, iconBtn, menu, meter, row, time } from "../ui.ts"; |
| 80 | 80 | import { inlineIcons } from "../icons.ts"; |
| @@ -677,8 +677,12 @@ async function talkPage(ctx: Ctx, conversation: Conversation, before0: string | | ||
| 677 | 677 | const about = editing === undefined ? aboutLine(ctx) : null; |
| 678 | 678 | const display = talkDisplay(ctx.app.db, user.id); |
| 679 | 679 | const lines = receiptLines(ctx.app.db, ctx.app.config.dataDir, user, turns); |
| 680 | // The crew's line says something only while a run is live: idle is silence. | |
| 681 | const crew = liveCrewRows(ctx, user); | |
| 680 | // The crew's line says something only while a run is live on this conversation's own app: idle, | |
| 681 | // or another repository's work, is silence. | |
| 682 | // Only a repository the pane offers this person (one they may read), so the page never names one | |
| 683 | // they may not. | |
| 684 | const crewRepo = paneRow?.name; | |
| 685 | const crew = crewRepo === undefined ? [] : crewOn(liveCrewRows(ctx, user), crewRepo); | |
| 682 | 686 | // The model picker (`talk_model.ts`), only where a connection offers a model. |
| 683 | 687 | const pickerAt = buildMode ? null : modelPicker(ctx, user, conversation.id); |
| 684 | 688 | const picker = pickerAt === null ? null : pickerAt(); |
| @@ -699,7 +703,7 @@ async function talkPage(ctx: Ctx, conversation: Conversation, before0: string | | ||
| 699 | 703 | : foldSteps(display.steps === "open", timeGroups(turns, turns.map((t) => turnHtml(t, waiting, costs.get(t.id), acts.get(t.id), works.get(t.id), sent.get(t.id), expired, undone, refs, voice, look, lines))))} |
| 700 | 704 | ${!paged && running ? queuedTalk(ctx.app, user, conversation.id).map(queuedHtml) : null} |
| 701 | 705 | </ol> |
| 702 | <p class="talk-crew small muted" id="talk-crew" data-live="run.*" data-live-src="/live/talk-crew">${crew.length === 0 ? null : crewLine(crew)}</p> | |
| 706 | <p class="talk-crew small muted" id="talk-crew" data-live="run.*" data-live-src="/live/talk-crew${crewRepo === undefined ? "" : `?repo=${encodeURIComponent(crewRepo)}`}">${crew.length === 0 ? null : crewLine(crew)}</p> | |
| 703 | 707 | <div id="end"></div> |
| 704 | 708 | <div class="talk-keys" data-keys role="region" aria-label="Keyboard shortcuts" hidden><dl>${TALK_KEYS.map((k) => html`<dt>${k.keys}</dt><dd>${k.does}</dd>`)}</dl></div> |
| 705 | 709 | <div class="talk-base"> |
src/web/talk_lines.ts +4 −2
| @@ -15,7 +15,7 @@ import { getConversation } from "../core/conversations.ts"; | ||
| 15 | 15 | import { notePhase, takeSessionTime } from "../core/route_timing.ts"; |
| 16 | 16 | import { fragment } from "./layout.ts"; |
| 17 | 17 | import { liveCrewRows } from "../actions/crew_now.ts"; |
| 18 | import { crewLine } from "./crew_now.ts"; | |
| 18 | import { crewLine, crewOn } from "./crew_now.ts"; | |
| 19 | 19 | import { FOR_MINUTES, workLineFor, type WorkLine } from "../core/talk_work.ts"; |
| 20 | 20 | import { PEEK } from "./peek_client.ts"; |
| 21 | 21 | |
| @@ -43,7 +43,9 @@ function workFragment(ctx: Ctx): Response { | ||
| 43 | 43 | export function liveTalkCrew(ctx: Ctx): Response { |
| 44 | 44 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 45 | 45 | const rendering = performance.now(); |
| 46 | const rows = ctx.auth.user === undefined ? undefined : liveCrewRows(ctx, ctx.auth.user); | |
| 46 | // Only the conversation's own app's runs (`?repo=`); without one, nothing. | |
| 47 | const repo = ctx.url.searchParams.get("repo"); | |
| 48 | const rows = ctx.auth.user === undefined ? undefined : repo === null ? [] : crewOn(liveCrewRows(ctx, ctx.auth.user), repo); | |
| 47 | 49 | const answer = rows === undefined ? fragment(html``, { status: 404 }) : fragment(html`<p class="talk-crew small muted" id="talk-crew">${rows.length === 0 ? null : crewLine(rows)}</p>`, { request: ctx.request }); |
| 48 | 50 | notePhase(ctx.request, "render", performance.now() - rendering); |
| 49 | 51 | return answer; |
test/talk-crew-now.test.ts +37 −11
| @@ -1,6 +1,8 @@ | ||
| 1 | 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). | |
| 2 | * /talk shows the crew's live work on the conversation's own app in one server-rendered line above | |
| 3 | * the box, and nothing when no run is live there (#13970). Another repository's crew is not this | |
| 4 | * conversation's: the owner's walk (2026-12-02) found the forge's own runs named under a | |
| 5 | * conversation about trevato/hello. The terminal's `talk /crew` still asks after the whole crew. | |
| 4 | 6 | */ |
| 5 | 7 | import { setMember } from "../src/core/roles.ts"; |
| 6 | 8 | import { inviteContributor } from "../src/actions/invites.ts"; |
| @@ -15,6 +17,8 @@ import { createApp as createAppRecord } from "../src/core/apps.ts"; | ||
| 15 | 17 | import { createIssue } from "../src/core/issues.ts"; |
| 16 | 18 | import { createRun } from "../src/core/runs.ts"; |
| 17 | 19 | import { createSession } from "../src/core/sessions.ts"; |
| 20 | import { appendTurn, createConversation } from "../src/core/conversations.ts"; | |
| 21 | import { startChatBuild } from "../src/core/chat_build.ts"; | |
| 18 | 22 | import { serve, type Servers } from "../src/http/server.ts"; |
| 19 | 23 | import { crewLine, CREW_IDLE } from "../src/web/crew_now.ts"; |
| 20 | 24 | import type { SshSession } from "../src/ssh/server.ts"; |
| @@ -35,7 +39,15 @@ describe("/talk crew line", () => { | ||
| 35 | 39 | let bobCookie: string; |
| 36 | 40 | let bobId: string; |
| 37 | 41 | const talk = async (c = cookie) => (await fetch(`${servers.url}/talk`, { headers: { cookie: c } })).text(); |
| 38 | const line = (h: string) => /<p class="talk-crew[^>]*>([^<]*)<\/p>/.exec(h)?.[1]; | |
| 42 | /** A conversation of `who` building on `repo` (its own app), as `c` sees it. */ | |
| 43 | const talkOn = async (who: string, repo: string, c = cookie) => { | |
| 44 | const made = createConversation(app.db, who); | |
| 45 | if (!made.ok) throw new Error(made.error); | |
| 46 | appendTurn(app.db, who, made.value.id, { role: "person", text: "how is it going?" }); | |
| 47 | startChatBuild(app.db, made.value.id, repo, true); | |
| 48 | return (await fetch(`${servers.url}/talk/${made.value.id}`, { headers: { cookie: c } })).text(); | |
| 49 | }; | |
| 50 | const line = (h: string) => /<p [^>]*?class="talk-crew[^>]*>([^<]*)<\/p>/.exec(h)?.[1]; | |
| 39 | 51 | |
| 40 | 52 | beforeAll(async () => { |
| 41 | 53 | dir = await mkdtemp(join(tmpdir(), "forge-talk-crew-")); |
| @@ -64,6 +76,7 @@ describe("/talk crew line", () => { | ||
| 64 | 76 | |
| 65 | 77 | test("idle when nobody works: the page says nothing, so no row is spent on it", async () => { |
| 66 | 78 | expect(line(await talk())).toBe(""); |
| 79 | expect(line(await talkOn(userId, repoId))).toBe(""); | |
| 67 | 80 | }); |
| 68 | 81 | |
| 69 | 82 | test("signed out, /talk asks for sign-in and shows no crew line", async () => { |
| @@ -80,22 +93,29 @@ describe("/talk crew line", () => { | ||
| 80 | 93 | const sealed = createIssue(app.db, { repoId, authorId: userId, title: "the hole", sealed: true }); |
| 81 | 94 | if (!sealed.ok) throw new Error("issue"); |
| 82 | 95 | createRun(app.db, { repoId, kind: "agent", issueId: sealed.value.id, reason: "work" }); |
| 83 | expect(line(await talk(bobCookie))).toBe(""); | |
| 84 | expect(line(await talk())).toStartWith("The crew is working (2):"); | |
| 96 | // Bob reads hello but not its sealed report: nothing. Ada reads both, and hears only hello's. | |
| 97 | expect(line(await talkOn(bobId, repoId, bobCookie))).toBe(""); | |
| 98 | expect(line(await talkOn(userId, repoId))).toBe("The crew is working: the crew on #1 the hole."); | |
| 99 | expect(line(await talkOn(userId, secret.value.id))).toBe("The crew is working: the crew on ada/secret."); | |
| 85 | 100 | }); |
| 86 | 101 | |
| 87 | 102 | test("busy names who works on what", async () => { |
| 88 | 103 | const issue = createIssue(app.db, { repoId, authorId: userId, title: "round the corners" }); |
| 89 | 104 | if (!issue.ok) throw new Error("issue"); |
| 90 | 105 | createRun(app.db, { repoId, kind: "agent", issueId: issue.value.id, reason: "work" }); |
| 91 | const text = line(await talk()); | |
| 92 | expect(text).toStartWith("The crew is working (3):"); | |
| 106 | const text = line(await talkOn(userId, repoId)); | |
| 107 | expect(text).toStartWith("The crew is working (2):"); | |
| 108 | // A conversation with no app of its own names no crew at all, whatever runs elsewhere. | |
| 109 | const bare = createConversation(app.db, userId); | |
| 110 | if (!bare.ok) throw new Error(bare.error); | |
| 111 | appendTurn(app.db, userId, bare.value.id, { role: "person", text: "hi" }); | |
| 112 | expect(line(await (await fetch(`${servers.url}/talk/${bare.value.id}`, { headers: { cookie } })).text())).toBe(""); | |
| 93 | 113 | // A guest who can merely see the public repository hears nothing of its crew on their Talk |
| 94 | 114 | // (#16487); made a member of the forge, they follow its crew like anyone on it. |
| 95 | expect(line(await talk(bobCookie))).toBe(""); | |
| 115 | expect(line(await talkOn(bobId, repoId, bobCookie))).toBe(""); | |
| 96 | 116 | setMember(app.db, bobId, true, userId, new Date()); |
| 97 | 117 | try { |
| 98 | expect(line(await talk(bobCookie))).toBe("The crew is working: the crew on #2 round the corners."); | |
| 118 | expect(line(await talkOn(bobId, repoId, bobCookie))).toBe("The crew is working: the crew on #2 round the corners."); | |
| 99 | 119 | } finally { |
| 100 | 120 | setMember(app.db, bobId, false, userId, new Date()); |
| 101 | 121 | } |
| @@ -109,11 +129,17 @@ describe("/talk crew line", () => { | ||
| 109 | 129 | const made = createIssue(app.db, { repoId: other.value.id, authorId: userId, title: "water the beans" }); |
| 110 | 130 | if (!made.ok) throw new Error("issue"); |
| 111 | 131 | createRun(app.db, { repoId: other.value.id, kind: "agent", issueId: made.value.id, reason: "work" }); |
| 112 | expect(line(await talk(bobCookie))).toBe(""); | |
| 132 | expect(line(await talkOn(bobId, other.value.id, bobCookie))).toBe(""); | |
| 113 | 133 | const bob = getUserById(app.db, bobId)!; |
| 114 | 134 | const invited = inviteContributor(app, ada, getRepoById(app.db, other.value.id)!, bob.username); |
| 115 | 135 | if (!invited.ok) throw new Error(String(invited.error)); |
| 116 | expect(line(await talk(bobCookie))).toBe("The crew is working: the crew on #1 water the beans."); | |
| 136 | expect(line(await talkOn(bobId, other.value.id, bobCookie))).toBe("The crew is working: the crew on #1 water the beans."); | |
| 137 | // garden's crew is garden's: a conversation on hello does not name it. | |
| 138 | expect(line(await talkOn(userId, repoId))).not.toContain("water the beans"); | |
| 139 | // The live line answers the same way, for the repository it names, and nothing without one. | |
| 140 | const live = (q: string) => fetch(`${servers.url}/live/talk-crew${q}`, { headers: { cookie } }).then((r) => r.text()); | |
| 141 | expect(line(await live(`?repo=${encodeURIComponent("ada/garden")}`))).toBe("The crew is working: the crew on #1 water the beans."); | |
| 142 | expect(line(await live(""))).toBe(""); | |
| 117 | 143 | }); |
| 118 | 144 | |
| 119 | 145 | test("the terminal prints the same line: `talk /crew`", () => { |
test/talk-receipt-live.test.ts +1 −3
| @@ -176,9 +176,7 @@ test("the page draws the receipt with its live line and Reply; the line's fragme | ||
| 176 | 176 | expect(page).toContain( |
| 177 | 177 | 'href="/alice/secret/issues/1#comment-body" data-reply="/alice/secret/issues/1" data-reply-to="alice/secret#1"', |
| 178 | 178 | ); |
| 179 | expect(page).toContain( | |
| 180 | 'id="talk-crew" data-live="run.*" data-live-src="/live/talk-crew"', | |
| 181 | ); | |
| 179 | expect(page).toMatch(/id="talk-crew" data-live="run\.\*" data-live-src="\/live\/talk-crew(\?repo=[^"]*)?"/); | |
| 182 | 180 | const id = /id="(w-[0-9a-z]+)"/.exec(page)![1]!; |
| 183 | 181 | const href = `/live/talk-work?href=${encodeURIComponent("/alice/secret/issues/1")}&id=${id}`; |
| 184 | 182 | const mine = await get(href, alice); |
new above
offline
Nit: two stacked comment blocks say one thing. Merge them into one.