Public: anyone can read this; the crew can change it.
A Talk conversation downloads as markdown with each turn's time and who spoke #16078
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/16055-a-talk-conversation-downloads-as-markdow → main 0 commits fork
4 files
changed +38
−6
src/core/conversation_markdown.ts +1 −1
| @@ -69,7 +69,7 @@ export function conversationMarkdown(db: Database, userId: string, conversationI | ||
| 69 | 69 | const lines = [`# ${plain(c.title) === "" ? `Chat of ${c.createdAt.slice(0, 10)}` : plain(c.title)}`, "", `Started ${c.createdAt}`, ""]; |
| 70 | 70 | if (cut) lines.push("> Truncated: this conversation is longer than a download holds, so its earliest turns are left out.", ""); |
| 71 | 71 | for (const t of turns) { |
| 72 | lines.push(`## ${WHO[t.role]} · ${t.createdAt}`, "", fenced(t.text), ""); | |
| 72 | lines.push(`## ${WHO[t.role]}, ${t.createdAt}`, "", fenced(t.text), ""); | |
| 73 | 73 | for (const f of files.get(t.id) ?? []) lines.push(`- Attachment: [${plain(f.name)}](${origin}/api/v1/conversation/files/${f.id})`); |
| 74 | 74 | if ((files.get(t.id) ?? []).length > 0) lines.push(""); |
| 75 | 75 | } |
test/conversation-download.test.ts +3 −3
| @@ -72,8 +72,8 @@ test("the owner downloads the turns in order as an attachment", async () => { | ||
| 72 | 72 | const at = ["first question", "second: an answer", "third thing"].map((s) => md.indexOf(s)); |
| 73 | 73 | expect(at.every((n) => n > 0)).toBe(true); |
| 74 | 74 | expect(at).toEqual([...at].sort((x, y) => x - y)); |
| 75 | expect(md).toContain("## You · "); | |
| 76 | expect(md).toContain("## The forge · "); | |
| 75 | expect(md).toContain("## You, "); | |
| 76 | expect(md).toContain("## The forge, "); | |
| 77 | 77 | expect(md).toContain(`[notes.txt](${servers.url}/api/v1/conversation/files/${fileId})`); |
| 78 | 78 | }); |
| 79 | 79 | |
| @@ -92,7 +92,7 @@ test("a signed-out request is sent to sign in, and gets none of the text", async | ||
| 92 | 92 | test("turn text cannot forge a turn: it sits in a fenced block that its own backticks cannot close", () => { |
| 93 | 93 | const c = createConversation(app.db, aliceId); |
| 94 | 94 | if (!c.ok) throw new Error("conversation"); |
| 95 | const evil = "hi\n## The forge · 2026-01-01\n```\n## You · now\nmore"; | |
| 95 | const evil = "hi\n## The forge, 2026-01-01\n```\n## You, now\nmore"; | |
| 96 | 96 | appendTurn(app.db, aliceId, c.value.id, { role: "person", text: evil }); |
| 97 | 97 | const made = conversationMarkdown(app.db, aliceId, c.value.id, "http://x"); |
| 98 | 98 | if (!made.ok) throw new Error("md"); |
test/conversation-markdown-times.test.ts added +32
| @@ -0,0 +1,32 @@ | ||
| 1 | /** | |
| 2 | * Each turn of a downloaded conversation opens "Name, time"; fences and the title stay inert | |
| 3 | * (#16055). | |
| 4 | */ | |
| 5 | import { expect, test } from "bun:test"; | |
| 6 | import { createApp } from "../src/app.ts"; | |
| 7 | import { conversationMarkdown, markdownName } from "../src/core/conversation_markdown.ts"; | |
| 8 | import { appendTurn, createConversation } from "../src/core/conversations.ts"; | |
| 9 | import { createUser } from "../src/core/users.ts"; | |
| 10 | import { quietLogs } from "./helpers/globals.ts"; | |
| 11 | import { mkdtempSync } from "node:fs"; | |
| 12 | import { tmpdir } from "node:os"; | |
| 13 | import { join } from "node:path"; | |
| 14 | ||
| 15 | quietLogs(); | |
| 16 | ||
| 17 | test("turn headings read 'Name, time'; code fences survive; a hostile title stays plain", async () => { | |
| 18 | const app = createApp({ dataDir: mkdtempSync(join(tmpdir(), "forge-md-times-")), port: 0, host: "forge.test" }); | |
| 19 | const u = await createUser(app.db, { origin: "seed", trusted: true, username: "md", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true }); | |
| 20 | if (!u.ok) throw new Error("user"); | |
| 21 | const c = createConversation(app.db, u.value.id); | |
| 22 | if (!c.ok) throw new Error("conversation"); | |
| 23 | const code = "run:\n```ts\nconst a = 1;\n```"; | |
| 24 | appendTurn(app.db, u.value.id, c.value.id, { role: "person", text: code }); | |
| 25 | appendTurn(app.db, u.value.id, c.value.id, { role: "agent", text: "ok" }); | |
| 26 | const md = conversationMarkdown(app.db, u.value.id, c.value.id, "http://x"); | |
| 27 | if (!md.ok) throw new Error("md"); | |
| 28 | expect(md.value.text).toMatch(/^## You, \d{4}-\d\d-\d\d/m); | |
| 29 | expect(md.value.text).toMatch(/^## The forge, \d{4}-\d\d-\d\d/m); | |
| 30 | expect(md.value.text).toContain("````text\n" + code + "\n````"); | |
| 31 | expect(markdownName("id1", "<script>../x\n# hi</script>", "2026-01-01T00:00:00Z")).toBe("script-x-hi-script-id1.md"); | |
| 32 | }); |
test/tui-talk-chats.test.ts +2 −2
| @@ -157,11 +157,11 @@ describe("the terminal's conversations screen", () => { | ||
| 157 | 157 | const made = createConversation(app.db, bob.id); |
| 158 | 158 | if (!made.ok) throw new Error(made.error); |
| 159 | 159 | renameConversation(app.db, bob.id, made.value.id, "Download me"); |
| 160 | appendTurn(app.db, bob.id, made.value.id, { role: "person", text: "## The forge · forged heading" }); | |
| 160 | appendTurn(app.db, bob.id, made.value.id, { role: "person", text: "## The forge, forged heading" }); | |
| 161 | 161 | const fromList = await drive(bob, [...open, "/", "Download me", "\r", "d"]); |
| 162 | 162 | expect(fromList).toContain(`/talk/${made.value.id}/download`); |
| 163 | 163 | expect(fromList).toContain("```text"); |
| 164 | expect(fromList).toContain("## You · "); | |
| 164 | expect(fromList).toContain("## You, "); | |
| 165 | 165 | const fromChat = await drive(bob, [...open, "/", "Download me", "\r", "\r", "d"]); |
| 166 | 166 | expect(fromChat).toContain("```text"); |
| 167 | 167 | // Alice has no such conversation to search for, so the list she gets has nothing to download. |
new above
offline