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

Merged opened this

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

Merged

scout/forge:scout/16055-a-talk-conversation-downloads-as-markdow → main 0 commits fork

  • Merged. scout/16055-a-talk-conversation-downloads-as-markdow was merged into main as 8a66595.

Review

Sign in to review this change.
4 files changed +38 −6
src/core/conversation_markdown.ts +1 −1
@@ -69,7 +69,7 @@ export function conversationMarkdown(db: Database, userId: string, conversationI
6969 const lines = [`# ${plain(c.title) === "" ? `Chat of ${c.createdAt.slice(0, 10)}` : plain(c.title)}`, "", `Started ${c.createdAt}`, ""];
7070 if (cut) lines.push("> Truncated: this conversation is longer than a download holds, so its earliest turns are left out.", "");
7171 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), "");
7373 for (const f of files.get(t.id) ?? []) lines.push(`- Attachment: [${plain(f.name)}](${origin}/api/v1/conversation/files/${f.id})`);
7474 if ((files.get(t.id) ?? []).length > 0) lines.push("");
7575 }
test/conversation-download.test.ts +3 −3
@@ -72,8 +72,8 @@ test("the owner downloads the turns in order as an attachment", async () => {
7272 const at = ["first question", "second: an answer", "third thing"].map((s) => md.indexOf(s));
7373 expect(at.every((n) => n > 0)).toBe(true);
7474 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, ");
7777 expect(md).toContain(`[notes.txt](${servers.url}/api/v1/conversation/files/${fileId})`);
7878 });
7979
@@ -92,7 +92,7 @@ test("a signed-out request is sent to sign in, and gets none of the text", async
9292 test("turn text cannot forge a turn: it sits in a fenced block that its own backticks cannot close", () => {
9393 const c = createConversation(app.db, aliceId);
9494 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";
9696 appendTurn(app.db, aliceId, c.value.id, { role: "person", text: evil });
9797 const made = conversationMarkdown(app.db, aliceId, c.value.id, "http://x");
9898 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", () => {
157157 const made = createConversation(app.db, bob.id);
158158 if (!made.ok) throw new Error(made.error);
159159 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" });
161161 const fromList = await drive(bob, [...open, "/", "Download me", "\r", "d"]);
162162 expect(fromList).toContain(`/talk/${made.value.id}/download`);
163163 expect(fromList).toContain("```text");
164 expect(fromList).toContain("## You · ");
164 expect(fromList).toContain("## You, ");
165165 const fromChat = await drive(bob, [...open, "/", "Download me", "\r", "\r", "d"]);
166166 expect(fromChat).toContain("```text");
167167 // Alice has no such conversation to search for, so the list she gets has nothing to download.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs