Public: anyone can read this; the crew can change it.
A conversation on /talk can be renamed in place, and the new name shows in the list #14630
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/14578-a-conversation-on-talk-can-be-renamed-in → main 1 commit fork
3 files
changed +82
−2
docs/features/talk.md +1 −1
| @@ -36,7 +36,7 @@ The first message of a conversation opened this way also carries the subject to | ||
| 36 | 36 | |
| 37 | 37 | ## Many conversations (#8814) |
| 38 | 38 | |
| 39 | A person has any number. `/talk` is their latest, with the list above it (newest activity first), **New**, and **Archived (n)** as the one filter (`/talk?archived=1`). Each opens at `/talk/<id>`, stable across reloads; Rename and Archive/Restore are plain forms (`POST /talk/:id/rename`, `/talk/:id/archive`, `POST /talk/new`), so they work without the script. Another person's id is 404 everywhere. A message with no conversation named goes to the latest one that is not archived. | |
| 39 | A person has any number. `/talk` is their latest, with the list above it (newest activity first), **New**, and **Archived (n)** as the one filter (`/talk?archived=1`). Each opens at `/talk/<id>`, stable across reloads; Rename and Archive/Restore are plain forms (`POST /talk/:id/rename`, `/talk/:id/archive`, `POST /talk/new`), so they work without the script. The name is also the page's tab title (`<name> · Talk`); an empty name restores "Chat of <day>". Another person's id is 404 everywhere. A message with no conversation named goes to the latest one that is not archived. | |
| 40 | 40 | |
| 41 | 41 | - **Cap:** a person holds at most 100 conversations, archived ones counted; past it New is refused (page flash, API 409 `too_many`, MCP `too_many`). Stop ends every reply the person has running, in any conversation. |
| 42 | 42 | - **API:** `GET /api/v1/conversations[?archived=1]`, `POST /api/v1/conversations {title?}`, `PATCH /api/v1/conversations/:id {title?, archived?}`; `conversation` on `POST …/messages` and `GET …/turns?conversation=` picks one. |
src/web/pages/talk.ts +1 −1
| @@ -428,7 +428,7 @@ async function talkPage(ctx: Ctx, conversation: Conversation, before0: string | | ||
| 428 | 428 | ${pane.html} |
| 429 | 429 | ${panel} |
| 430 | 430 | </div>`; |
| 431 | return page({ ctx, title: "Talk", body, styleCss: panel === null && box === null ? talkCss : talkCss + buildCss, scriptJs: talkJs, description: "Talk to the forge.", ...(pane.frame === undefined ? {} : { frameSrc: pane.frame }) }); | |
| 431 | return page({ ctx, title: conversation.title === "" ? "Talk" : `${conversation.title} · Talk`, body, styleCss: panel === null && box === null ? talkCss : talkCss + buildCss, scriptJs: talkJs, description: "Talk to the forge.", ...(pane.frame === undefined ? {} : { frameSrc: pane.frame }) }); | |
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | /** |
test/talk-rename.test.ts added +80
| @@ -0,0 +1,80 @@ | ||
| 1 | /** | |
| 2 | * Renaming a conversation: the name shows in the page title and list, empty restores the derived | |
| 3 | * one. | |
| 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 { newConversation } from "../src/core/conversations.ts"; | |
| 11 | import { createSession } from "../src/core/sessions.ts"; | |
| 12 | import { createUser, type User } from "../src/core/users.ts"; | |
| 13 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 14 | import { promote } from "./helpers/members.ts"; | |
| 15 | import { quietLogs } from "./helpers/globals.ts"; | |
| 16 | ||
| 17 | quietLogs(); | |
| 18 | ||
| 19 | let dir: string; | |
| 20 | let app: App; | |
| 21 | let servers: Servers; | |
| 22 | let alice: User; | |
| 23 | let bob: User; | |
| 24 | ||
| 25 | const cookie = (u: User) => `forge_session=${createSession(app.db, u.id).token}`; | |
| 26 | const get = (path: string, u: User) => fetch(`${servers.url}${path}`, { redirect: "manual", headers: { cookie: cookie(u) } }); | |
| 27 | const post = (path: string, u: User, title: string) => | |
| 28 | fetch(`${servers.url}${path}`, { method: "POST", redirect: "manual", headers: { origin: servers.url, cookie: cookie(u) }, body: new URLSearchParams({ title }) }); | |
| 29 | const titleOf = (h: string) => /<title>([^<]*)<\/title>/.exec(h)?.[1] ?? ""; | |
| 30 | ||
| 31 | beforeAll(async () => { | |
| 32 | dir = await mkdtemp(join(tmpdir(), "forge-talk-rename-")); | |
| 33 | app = createApp({ dataDir: dir, port: 0 }); | |
| 34 | servers = await serve(app); | |
| 35 | const mk = async (username: string, first = false) => { | |
| 36 | const u = await createUser(app.db, { origin: "seed", trusted: true, username, email: `${username}@forge.local`, password: "a-good-passphrase", adminIfFirst: first }); | |
| 37 | if (!u.ok) throw new Error(u.error); | |
| 38 | promote(app.db, u.value); | |
| 39 | return u.value; | |
| 40 | }; | |
| 41 | alice = await mk("alice", true); | |
| 42 | bob = await mk("bob"); | |
| 43 | }, 30_000); | |
| 44 | ||
| 45 | afterAll(async () => { | |
| 46 | servers.stop(); | |
| 47 | app.close(); | |
| 48 | await rm(dir, { recursive: true, force: true }); | |
| 49 | }); | |
| 50 | ||
| 51 | describe("rename a conversation", () => { | |
| 52 | test("the new name shows in the page title and the list; empty restores the derived name", async () => { | |
| 53 | const c = newConversation(app.db, alice.id); | |
| 54 | expect((await post(`/talk/${c.id}/rename`, alice, " Launch plan ")).status).toBe(303); | |
| 55 | const page = await (await get(`/talk/${c.id}`, alice)).text(); | |
| 56 | expect(titleOf(page)).toContain("Launch plan"); | |
| 57 | expect(page).toContain(">Launch plan<"); | |
| 58 | await post(`/talk/${c.id}/rename`, alice, ""); | |
| 59 | const after = await (await get(`/talk/${c.id}`, alice)).text(); | |
| 60 | expect(titleOf(after)).not.toContain("Launch plan"); | |
| 61 | expect(after).toContain(`Chat of ${c.createdAt.slice(0, 10)}`); | |
| 62 | }); | |
| 63 | ||
| 64 | test("a hostile name is escaped in the title and the page, and a long one is refused", async () => { | |
| 65 | const c = newConversation(app.db, alice.id); | |
| 66 | await post(`/talk/${c.id}/rename`, alice, "<script>alert(1)</script>"); | |
| 67 | const page = await (await get(`/talk/${c.id}`, alice)).text(); | |
| 68 | expect(page).not.toContain("<script>alert(1)</script>"); | |
| 69 | expect(titleOf(page)).toContain("<script>"); | |
| 70 | await post(`/talk/${c.id}/rename`, alice, "x".repeat(81)); | |
| 71 | expect(await (await get(`/talk/${c.id}`, alice)).text()).not.toContain("x".repeat(81)); | |
| 72 | }); | |
| 73 | ||
| 74 | test("a stranger gets 404 and changes nothing", async () => { | |
| 75 | const c = newConversation(app.db, alice.id); | |
| 76 | await post(`/talk/${c.id}/rename`, alice, "Mine"); | |
| 77 | expect((await post(`/talk/${c.id}/rename`, bob, "Stolen")).status).toBe(404); | |
| 78 | expect(titleOf(await (await get(`/talk/${c.id}`, alice)).text())).toContain("Mine"); | |
| 79 | }); | |
| 80 | }); |
new above
offline