From 2a6509d93dd75edd9a26e3dacae952b2ca1e4b21 Mon Sep 17 00:00:00 2001 From: Gil Birman Date: Mon, 23 Nov 2026 12:33:23 -0600 Subject: [PATCH 1/3] Show thread-title roots as one line in the channel timeline A signer can mark a top-level kind-9 message with a signed ["thread-title", "1"] tag: the message is only its thread's title, and the content is in the replies. The channel timeline now draws such a root as one line: author, thread icon, the title, the thread's reply summary and the time. The line opens the thread, which still shows the root in full. The message menu keeps edit, delete, pin and copy link. The tag is ignored on replies, other kinds, other values and repeated tags. Clients without support show the plain message. Co-authored-by: g.s.opus <182de044fe08d24f64d005f425861956d29456fffb812544e93ed39df003b4d1@buzz.block.builderlab.xyz> Co-Authored-By: Claude Opus 5.5 Signed-off-by: Gil Birman --- src/features/messages/MessageRow.test.tsx | 34 ++++++ src/features/messages/MessageRow.tsx | 122 +++++++++++++++++++++- src/features/messages/Messages.module.css | 32 ++++++ src/features/messages/message-grouping.ts | 3 + src/features/relay/contracts.ts | 3 + src/features/relay/fold.test.ts | 25 +++++ src/features/relay/fold.ts | 2 + src/features/relay/row-identity.ts | 1 + src/features/relay/thread-title.ts | 14 +++ tests/browser/activity-groups.spec.mjs | 54 ++++++++++ tests/fixtures/activity-groups.tsx | 67 +++++++++--- 11 files changed, 339 insertions(+), 18 deletions(-) create mode 100644 src/features/relay/thread-title.ts diff --git a/src/features/messages/MessageRow.test.tsx b/src/features/messages/MessageRow.test.tsx index ed257095e4..3cfbd4b69e 100644 --- a/src/features/messages/MessageRow.test.tsx +++ b/src/features/messages/MessageRow.test.tsx @@ -656,6 +656,40 @@ it("renders the signed whole-thread total rather than only direct replies", () = expect(html).toContain('aria-label="View thread: 3 replies"'); expect(html).toContain("3 replies"); }); +it("draws a thread-title root as one line that opens its thread, and in full in the thread", async () => { + const open = vi.fn(); + const title = { + ...row, + content: "Fix the login test", + threadTitle: true as const, + }; + const props = { + profile: { name: "Alex" }, + media: () => undefined, + onOpenLink: () => false, + day: false, + retry: undefined, + onOpenThread: open, + }; + try { + const { rerender } = renderDom(); + await userEvent.click( + screen.getByRole("button", { + name: /^Thread by Alex: Fix the login test, /, + }), + ); + expect(open).toHaveBeenCalledWith("root", "root"); + // The thread's own summary stays its control, with its reply count. + expect( + screen.getByRole("button", { name: "View thread: 23 replies" }), + ).toBeInTheDocument(); + rerender(); + expect(screen.queryByRole("button", { name: /^Thread by/ })).toBeNull(); + expect(screen.getByText("Fix the login test")).toBeInTheDocument(); + } finally { + cleanup(); + } +}); it("selects this thread, adds an accessible unread cue and preserves the total reply count", () => { const { html, snapshot } = render({ observedCount: 2 }); expect(snapshot).toHaveBeenCalledExactlyOnceWith({ diff --git a/src/features/messages/MessageRow.tsx b/src/features/messages/MessageRow.tsx index 7b21fd51ba..57049a5a1b 100644 --- a/src/features/messages/MessageRow.tsx +++ b/src/features/messages/MessageRow.tsx @@ -125,6 +125,7 @@ import { FlagIcon, ListBulletsIcon, PinIcon, + ThreadIcon, } from "../../shared/design-system/icons"; import { usePinnedMessages } from "./use-pins"; import { @@ -209,6 +210,8 @@ type MessageContentProps = MessageRowProps & { renderMessage?: ( message: ReactNode, trigger: RefObject, + /** The row's thread summary control, or null when it has none. */ + summary: ReactNode, ) => ReactElement; }; @@ -1820,7 +1823,13 @@ function MessageRowContent({ ); return renderMessage ? ( <> - {messageActions(renderMessage(message, menuTrigger))} + {messageActions( + renderMessage( + message, + menuTrigger, + summaryThread ? renderMessageSummary() : null, + ), + )} {overlays} ) : row.membership || row.huddle ? ( @@ -1859,6 +1868,11 @@ export const MessageRow = memo(function AudienceMessageRow( ) ) : row.relayedFrom?.verified ? ( + ) : row.threadTitle && + !row.threadRootId && + (props.layout ?? "timeline") === "timeline" && + props.onOpenThread ? ( + ) : row.audience === "agents" ? ( ) : ( @@ -2337,6 +2351,112 @@ function RelayedMessageRow(props: MessageRowProps) { ); } +/** A top-level message whose signer marked it as only its thread's title + * reads as one line in the timeline: who started it, the title, the thread's + * summary and the time. The line opens the thread, where the root is shown in + * full; the message menu keeps its usual actions. */ +function ThreadTitleRow(props: MessageRowProps) { + const { row, session, media, agentPubkeys, onOpenThread } = props; + const references = props.references ?? session; + const resolveName = useChannelIdentityNames(references, row.channelId); + const showTime = useMessageTimeVisible(references?.channels, row.channelId); + // The button's name carries the full date, so it follows time zone changes. + useLocalDay(); + const name = resolveName( + row.authorId, + props.profile?.name ?? row.authorId.slice(0, 10), + ); + const excerpt = Array.from( + messagePreviewText(row.content).replace(/\s+/g, " ").trim(), + ); + const title = + excerpt.length > 280 + ? `${excerpt.slice(0, 279).join("")}…` + : excerpt.join(""); + return ( + ( +
+ {props.day && } +
+
+
+
+
+ )} + /> + ); +} + // Subscribe only for mounted thread buttons. Evidence and reading remain session-owned; // rendering a row must not initiate per-thread reads or acknowledge unseen replies. function useThreadUnread( diff --git a/src/features/messages/Messages.module.css b/src/features/messages/Messages.module.css index 8dcd54ffdc..2f76439e22 100644 --- a/src/features/messages/Messages.module.css +++ b/src/features/messages/Messages.module.css @@ -1010,6 +1010,24 @@ html[data-keyboard-navigation] .attachmentImage:focus-visible { margin-top: var(--space-half); padding-block: var(--space-half); } +/* The summary is the thread's own control, so it sits above + the title line's button. */ +.threadTitleSummary { + position: relative; + z-index: 1; + flex: none; + display: flex; + margin-block: calc(-1 * var(--space-half)); +} +.threadTitleSummary > [data-thread-summary] { + min-height: 0; + padding: var(--space-half) var(--space-1h) var(--space-half) var(--space-1); + font-size: var(--text-caption); + line-height: var(--text-caption--line-height); + letter-spacing: var(--text-caption--letter-spacing); + font-weight: var(--type-weight-regular); + user-select: none; +} .messageBody [data-reply-connector] { margin-inline-start: calc(var(--space-4) + var(--space-3)); max-width: calc(100% - var(--space-4) - var(--space-3)); @@ -4346,6 +4364,20 @@ html[data-keyboard-navigation] .relayedRun > .relayedHeader > .relayedTime { margin-inline-start: auto; } +/* A thread title's line: its title gives up room first, so who started it, + its summary and the time stay readable. */ +.threadTitleIcon { + flex: none; + inline-size: var(--space-4); + block-size: var(--space-4); +} +.threadTitleText { + flex: 1 1 0; + min-inline-size: 0; + overflow: hidden; + text-overflow: ellipsis; + color: var(--text-standard); +} /* Points right while closed and down while open, as other disclosures do. */ .relayedCaret { flex: none; diff --git a/src/features/messages/message-grouping.ts b/src/features/messages/message-grouping.ts index 890e4e4293..438aa60966 100644 --- a/src/features/messages/message-grouping.ts +++ b/src/features/messages/message-grouping.ts @@ -17,6 +17,9 @@ export function continuesMessageGroup( // A relayed line is another agent's, never part of its signer's group. !previous.relayedFrom?.verified && !current.relayedFrom?.verified && + // A thread title is its own line, the way its thread is its own topic. + !previous.threadTitle && + !current.threadTitle && previous.channelId === current.channelId && previous.authorId === current.authorId && (previous.audience === current.audience || current.audience === "agents") && diff --git a/src/features/relay/contracts.ts b/src/features/relay/contracts.ts index fc5b6fcc04..71d211e5cd 100644 --- a/src/features/relay/contracts.ts +++ b/src/features/relay/contracts.ts @@ -157,6 +157,9 @@ export type ChannelMessage = Readonly<{ notice?: string; verified: boolean; }>; + /** Signed `thread-title` tag on a top-level message: the signer's claim + * that it is only its thread's title. Display metadata, not authority. */ + threadTitle?: true; /** Signed `buzz:request` tag: the agent's claim of the triggering message * this update belongs to, separate from its flattened reply link. */ request?: string; diff --git a/src/features/relay/fold.test.ts b/src/features/relay/fold.test.ts index 77d031f6f6..e4c61fd85f 100644 --- a/src/features/relay/fold.test.ts +++ b/src/features/relay/fold.test.ts @@ -1520,6 +1520,31 @@ it("honours a relayed-from claim only while the author owns the named agent", () expect(fold(relayed(tags), alice.pubkey)?.relayedFrom).toBeUndefined(); }); +it("marks only a top-level message with one exact thread-title tag", () => { + const root = message(alice, channel, "Fix the login test", 10, [ + ["thread-title", "1"], + ]); + const fold = (event: ReturnType) => + foldMessages(channel, relay.pubkey, [event], { includeReplies: true })[0]; + expect(fold(root)?.threadTitle).toBe(true); + for (const tags of [ + [["thread-title", "0"]], + [["thread-title", "1", "extra"]], + [ + ["thread-title", "1"], + ["thread-title", "1"], + ], + [ + ["thread-title", "1"], + ["e", root.id, "", "reply"], + ], + ]) + expect( + fold(message(alice, channel, "Fix the login test", 11, tags)) + ?.threadTitle, + ).toBeUndefined(); +}); + it("replaces a shared row when only its relayed claim's verification changes", () => { const event = message(alice, channel, "Notice\n\nText", 10, [ ["relayed-from", bob.pubkey], diff --git a/src/features/relay/fold.ts b/src/features/relay/fold.ts index 33f6660dfc..f3f28dafaa 100644 --- a/src/features/relay/fold.ts +++ b/src/features/relay/fold.ts @@ -5,6 +5,7 @@ import { validatedBlurhash } from "./blurhash"; import { threadReference } from "./thread-reference"; import { agentAudience } from "./audience"; import { relayedFromClaim, relayNotice } from "./relayed-from"; +import { threadTitleClaim } from "./thread-title"; import { pluginRequestId } from "./plugin-request"; import { emojiTags } from "./emoji"; import { objectBody } from "./body"; @@ -484,6 +485,7 @@ export function foldMessages( }), } : {}), + ...(threadTitleClaim(event) ? { threadTitle: true as const } : {}), ...(() => { // One exact id, or none: conflicting claims bind no request. const ids = new Set( diff --git a/src/features/relay/row-identity.ts b/src/features/relay/row-identity.ts index 7d3d1d3144..42bc5fb613 100644 --- a/src/features/relay/row-identity.ts +++ b/src/features/relay/row-identity.ts @@ -33,6 +33,7 @@ function sameRow(left: ChannelMessage, right: ChannelMessage) { left.relayedFrom?.channelId === right.relayedFrom?.channelId && left.relayedFrom?.verified === right.relayedFrom?.verified && left.relayedFrom?.notice === right.relayedFrom?.notice && + left.threadTitle === right.threadTitle && left.request === right.request && !!left.diff === !!right.diff && left.diff?.filePath === right.diff?.filePath && diff --git a/src/features/relay/thread-title.ts b/src/features/relay/thread-title.ts new file mode 100644 index 0000000000..f6e99cb646 --- /dev/null +++ b/src/features/relay/thread-title.ts @@ -0,0 +1,14 @@ +import type { EventData } from "./events"; +import { threadReference } from "./thread-reference"; + +/** The signer's claim, in a signed `["thread-title", "1"]` tag, that a + * top-level message is only its thread's title: the content is in the + * replies. One well-formed claim, or none: a reply, another kind, another + * value or a repeated tag claims nothing. */ +export function threadTitleClaim( + event: Pick, +): boolean { + if (event.kind !== 9 || threadReference(event)) return false; + const claims = event.tags.filter(([name]) => name === "thread-title"); + return claims.length === 1 && claims[0]?.length === 2 && claims[0][1] === "1"; +} diff --git a/tests/browser/activity-groups.spec.mjs b/tests/browser/activity-groups.spec.mjs index 6cdcf16079..07ebff5cf3 100644 --- a/tests/browser/activity-groups.spec.mjs +++ b/tests/browser/activity-groups.spec.mjs @@ -3,6 +3,60 @@ import { createServer } from "./vite-server.mjs"; import { activate } from "./navigation.mjs"; import { clickRow, virtuaIdle } from "./timeline.mjs"; +test("a thread title reads as one line that opens its thread", async ({ + page, +}, testInfo) => { + const server = await createServer({ + configFile: false, + envFile: false, + logLevel: "error", + server: { host: "127.0.0.1", port: 0, strictPort: false }, + }); + await server.listen(); + const fixture = `http://127.0.0.1:${server.httpServer.address().port}/tests/fixtures/activity-groups.html`; + try { + await page.setViewportSize({ width: 860, height: 700 }); + await page.goto(`${fixture}?thread-title`); + const history = page.getByRole("region", { + name: "Channel message history", + }); + const line = history.getByRole("button", { + name: /^Thread by .*: Thread title fixture/, + }); + // One line, inside the chat, with the thread's summary beside its title. + const fits = () => + line.evaluate((button) => { + const header = button.parentElement.getBoundingClientRect(); + const bounds = button + .closest('[aria-label="Channel message history"]') + .getBoundingClientRect(); + return ( + header.height < 40 && + header.left >= bounds.left && + header.right <= bounds.right + ); + }); + await expect.poll(fits).toBe(true); + await expect( + history.getByRole("button", { name: "View thread: 4 replies" }), + ).toBeVisible(); + for (const colorScheme of ["light", "dark"]) { + await page.emulateMedia({ colorScheme }); + await page.screenshot({ + path: testInfo.outputPath(`thread-title-${colorScheme}.png`), + }); + } + await page.setViewportSize({ width: 420, height: 700 }); + await expect.poll(fits).toBe(true); + await line.press("Enter"); + await expect( + page.getByText(`Opened thread ${"1".repeat(64)}`), + ).toBeVisible(); + } finally { + await server.close(); + } +}); + test("a long relayed message fits the chat before and after opening", async ({ page, }) => { diff --git a/tests/fixtures/activity-groups.tsx b/tests/fixtures/activity-groups.tsx index 1cdac6e0e5..79914790b6 100644 --- a/tests/fixtures/activity-groups.tsx +++ b/tests/fixtures/activity-groups.tsx @@ -9,8 +9,12 @@ import { Button } from "../../src/shared/design-system/ui/Button"; import { useKeyboardFocusVisibility } from "../../src/shared/design-system/useKeyboardFocusVisibility"; import styles from "../../src/features/messages/Messages.module.css"; import "../../src/shared/styles/globals.css"; +import { createAppearance } from "../../src/shared/theme/service"; const relayed = new URLSearchParams(location.search).get("relayed"); +const titles = new URLSearchParams(location.search).has("thread-title"); +// Follows the system scheme, so its screenshots can show both themes. +if (titles) createAppearance(); const viewer = keypair(); const relay = keypair(); const source = "source"; @@ -49,31 +53,53 @@ const update = (index: number, activity = true): ChannelMessage => ({ const note = "The complete handoff remains readable when this preview opens."; function Fixture() { useKeyboardFocusVisibility(); + const [opened, setOpened] = useState(); const [rows, setRows] = useState( - relayed !== null + titles ? [ + { ...update(0, false), content: "Ordinary chat message" }, { - ...update(0, false), - content: "Ordinary chat message", + ...update(1, false), + // Thread read state is keyed by event ID. + id: "1".repeat(64), + authorId: owner.session.viewer, + content: `Thread title fixture. ${"A long title needs to fit the line. ".repeat(6)}`, + threadTitle: true, + replyCount: 4, + participants: [agent, owner.session.viewer], }, { - ...update(1, false), + ...update(2, false), + id: "2".repeat(64), authorId: owner.session.viewer, - content: `Relayed fixture update. ${"A long preview needs to fit the chat. ".repeat(9)}\n\n${note}`, - relayedFrom: { agent, channelId: source, verified: true }, + content: "Second thread title", + threadTitle: true, }, - ...(relayed === "group" - ? [ - { - ...update(2, false), - authorId: owner.session.viewer, - content: "Second relayed fixture update.", - relayedFrom: { agent, channelId: source, verified: true }, - }, - ] - : []), ] - : Array.from({ length: 16 }, (_, index) => update(index)), + : relayed !== null + ? [ + { + ...update(0, false), + content: "Ordinary chat message", + }, + { + ...update(1, false), + authorId: owner.session.viewer, + content: `Relayed fixture update. ${"A long preview needs to fit the chat. ".repeat(9)}\n\n${note}`, + relayedFrom: { agent, channelId: source, verified: true }, + }, + ...(relayed === "group" + ? [ + { + ...update(2, false), + authorId: owner.session.viewer, + content: "Second relayed fixture update.", + relayedFrom: { agent, channelId: source, verified: true }, + }, + ] + : []), + ] + : Array.from({ length: 16 }, (_, index) => update(index)), ); const [inlineTarget, setTarget] = useState<{ messageId: string; @@ -114,6 +140,7 @@ function Fixture() { Prepend history + {opened && Opened thread {opened}}
false} + {...(titles + ? { + onOpenThread: (_id: string, rootId: string) => + setOpened(rootId), + } + : {})} />
From 1ef487d24fea6a7024d5df319466a43081d836ce Mon Sep 17 00:00:00 2001 From: Gil Birman Date: Mon, 23 Nov 2026 12:40:37 -0600 Subject: [PATCH 2/3] Keep the full row when a thread title has more to show A failed or unknown send keeps its Retry, and rows with attachments, forwards, diffs, plugin cards, agent or workflow presentation stay as they are. A title opens as a line only where the row could open its thread. Co-authored-by: g.s.opus <182de044fe08d24f64d005f425861956d29456fffb812544e93ed39df003b4d1@buzz.block.builderlab.xyz> Co-Authored-By: Claude Opus 5.5 Signed-off-by: Gil Birman --- src/features/messages/MessageRow.test.tsx | 3 +++ src/features/messages/MessageRow.tsx | 33 ++++++++++++++++++++--- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/features/messages/MessageRow.test.tsx b/src/features/messages/MessageRow.test.tsx index 3cfbd4b69e..1c792d907e 100644 --- a/src/features/messages/MessageRow.test.tsx +++ b/src/features/messages/MessageRow.test.tsx @@ -686,6 +686,9 @@ it("draws a thread-title root as one line that opens its thread, and in full in rerender(); expect(screen.queryByRole("button", { name: /^Thread by/ })).toBeNull(); expect(screen.getByText("Fix the login test")).toBeInTheDocument(); + // A failed send keeps its full row, so its Retry stays in the timeline. + rerender(); + expect(screen.queryByRole("button", { name: /^Thread by/ })).toBeNull(); } finally { cleanup(); } diff --git a/src/features/messages/MessageRow.tsx b/src/features/messages/MessageRow.tsx index 57049a5a1b..64a6fb6c41 100644 --- a/src/features/messages/MessageRow.tsx +++ b/src/features/messages/MessageRow.tsx @@ -1868,10 +1868,7 @@ export const MessageRow = memo(function AudienceMessageRow( ) ) : row.relayedFrom?.verified ? ( - ) : row.threadTitle && - !row.threadRootId && - (props.layout ?? "timeline") === "timeline" && - props.onOpenThread ? ( + ) : titleLine(props) ? ( ) : row.audience === "agents" ? ( @@ -2351,6 +2348,34 @@ function RelayedMessageRow(props: MessageRowProps) { ); } +/** A thread title is one line only in the timeline, where it can open its + * thread, and only while the title is all there is to show: a failed send + * keeps its Retry, and attachments, forwards and agent or workflow rows keep + * their own presentation. */ +const titleLine = ({ + row, + layout = "timeline", + onOpenThread, + startsThreads = true, +}: MessageRowProps) => + !!row.threadTitle && + !row.threadRootId && + layout === "timeline" && + !!onOpenThread && + (startsThreads || row.replyCount > 0) && + row.delivery !== "failed" && + row.delivery !== "unknown" && + !!row.content.trim() && + !row.attachments.length && + !row.forward && + !row.diff && + !row.agentEnvelope && + !row.pluginRequest && + !row.audience && + !row.workflowOwnerId && + !row.membership && + !row.huddle; + /** A top-level message whose signer marked it as only its thread's title * reads as one line in the timeline: who started it, the title, the thread's * summary and the time. The line opens the thread, where the root is shown in From 4580f60f8603a675e0f93383c3e295c7526acf2c Mon Sep 17 00:00:00 2001 From: Gil Birman Date: Mon, 23 Nov 2026 13:29:43 -0600 Subject: [PATCH 3/3] Show a pin on a pinned thread title's line The line has no message body, where a pinned message shows its Pinned line, so a pinned title shows a pin beside its title. Co-authored-by: g.s.opus <182de044fe08d24f64d005f425861956d29456fffb812544e93ed39df003b4d1@buzz.block.builderlab.xyz> Co-Authored-By: Claude Opus 5.5 Signed-off-by: Gil Birman --- src/features/messages/MessageRow.tsx | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/features/messages/MessageRow.tsx b/src/features/messages/MessageRow.tsx index 64a6fb6c41..9c92e0c39f 100644 --- a/src/features/messages/MessageRow.tsx +++ b/src/features/messages/MessageRow.tsx @@ -2465,6 +2465,9 @@ function ThreadTitleRow(props: MessageRowProps) { )} + {session?.relayAuthor && ( + + )} {summary && ( {summary} )} @@ -2584,6 +2587,24 @@ function useThreadAgents( }; } +/** A thread title's line has no body for the pinned line, so a pin shows + * beside its title. */ +function PinnedLineMark({ + session, + row, +}: { + session: RelaySession; + row: ChannelMessage; +}) { + const pins = usePinnedMessages(session, row.channelId); + if (!pins.set.has(row.id)) return null; + return ( + + + ); +} + /** A quiet line on a message that is pinned in its channel. */ function PinnedMarker({ session,