From e9d949688719399ce6a91b0d4fd9edb62f65b1e5 Mon Sep 17 00:00:00 2001 From: Gil Birman Date: Mon, 23 Nov 2026 16:56:10 -0600 Subject: [PATCH 1/2] feat(conversation): let a workspace show a card over the channel's latest message A plugin page that shows a channel through `ui.Workspace` can pass `trailing: { restHeight, content({ expanded, toggle }) }` to show a card, such as a decision to make, over the end of the channel timeline. The host advertises the slot with `ctx.conversation.workspaceSlots.trailing`; a thread target and older hosts ignore it. The card scrolls in its own sheet over the history. At rest its first `restHeight` pixels sit below the latest message, which a box of that height keeps above it. A wheel or touch over the card grows it, then slides it up off the view's top; the history never moves. Over the history above a grown card, the history scrolls as usual. `toggle()` grows the card to 60px below the view's top, re-aiming if the layout settles mid-scroll, and back. Jump to latest and a send return the card to rest. Jump to latest stays above the card's visible top, and rows under the card aren't marked read. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Gil Birman --- docs/plugin-authoring-guide.md | 10 + src/bundled/channels/ChannelBody.tsx | 3 + src/bundled/channels/ConversationTab.test.tsx | 25 ++ src/bundled/channels/ConversationTab.tsx | 9 +- src/bundled/channels/PageTabs.test.tsx | 20 + src/bundled/channels/PageTabs.tsx | 1 + src/bundled/channels/index.test.tsx | 14 +- src/bundled/channels/index.tsx | 2 +- src/features/conversation/contracts.ts | 10 + .../messages/ChannelTimeline.test.tsx | 12 +- src/features/messages/ChannelTimeline.tsx | 202 ++++++++- .../ChannelTimeline.viewport.test.tsx | 22 + src/features/messages/Messages.module.css | 55 ++- src/features/messages/use-reading.test.ts | 32 ++ src/features/messages/use-reading.ts | 29 +- tests/browser/conversation-workspace.spec.mjs | 418 ++++++++++++++++++ tests/browser/plugin-fixtures.tsx | 36 +- tests/browser/trailing-fixture.tsx | 88 ++++ 18 files changed, 958 insertions(+), 30 deletions(-) create mode 100644 tests/browser/trailing-fixture.tsx diff --git a/docs/plugin-authoring-guide.md b/docs/plugin-authoring-guide.md index b270017200..570c7f4183 100644 --- a/docs/plugin-authoring-guide.md +++ b/docs/plugin-authoring-guide.md @@ -96,6 +96,16 @@ then. Use compact icon buttons with an `aria-label` and `title`, and set workspace with `registerWorkspace(component, { slots })` names the optional props its component renders. +Check `ctx.conversation.workspaceSlots?.trailing === true` in the same way +before passing `trailing` to `ui.Workspace`. The Channels workspace shows that +content as a card over the +bottom of the channel timeline, in its own scroll layer: scrolling over the +card grows it, then slides it up. Render the whole card at rest too, since +growing scrolls it into view: let `expanded` change labels, not what the card +holds. Keep its controls in view with `position: sticky; bottom: 0` and an +opaque background, and draw its outline with a box shadow rather than a bottom +border. + For `ctx.agents.ui.Transcript`, give each turn a unique `turnId` that stays the same across reads. Return a new turn when it changes. Leave previously returned turns and their items untouched. ## Migration writes diff --git a/src/bundled/channels/ChannelBody.tsx b/src/bundled/channels/ChannelBody.tsx index 19cf1189c2..58502008c1 100644 --- a/src/bundled/channels/ChannelBody.tsx +++ b/src/bundled/channels/ChannelBody.tsx @@ -16,6 +16,7 @@ import styles from "./Channels.module.css"; export const ChannelBody = memo(function ChannelBody({ cached, intro, + trailing, latestRequest, viewer, revealMessageId, @@ -30,6 +31,7 @@ export const ChannelBody = memo(function ChannelBody({ onContentReady?(channelId: string): void; cached: boolean; intro?: ReactNode; + trailing?: ChannelTimelineProps["trailing"]; latestRequest?: AbortSignal | undefined; viewer?: string | undefined; navigation?: PageNavigation | undefined; @@ -127,6 +129,7 @@ export const ChannelBody = memo(function ChannelBody({ ({ inlineTarget, marksRead, onOpenThread, + trailing, }: { holding?: boolean; inlineTarget?: { messageId: string }; marksRead?: boolean; onOpenThread(id: string, root: string, intent?: "reply"): void; + trailing?: { content(state: object): import("react").ReactNode }; }) => { threadOpeners.push(onOpenThread); return ( @@ -79,6 +81,7 @@ vi.mock("./ChannelBody", () => ({ data-marks-read={marksRead} > Conversation content + {trailing?.content({ expanded: false, toggle() {} })} ); }, @@ -641,6 +644,28 @@ it("a conversation tab opens a reply at its message as the thread", () => { expect(screen.queryByText("Conversation content")).toBeNull(); }); +it.each(["conversation", "thread"] as const)( + "only a channel timeline shows the workspace's trailing content (%s)", + (kind) => { + const c = openingAt([]); + render( +

Decision card

}} + />, + ); + c.settle(); + expect(screen.queryByText("Decision card") !== null).toBe( + kind === "conversation", + ); + }, +); + it("a thread tab asks its reader to reveal for each open at a message, not on restore", () => { const c = openingAt([]); const tab = { diff --git a/src/bundled/channels/ConversationTab.tsx b/src/bundled/channels/ConversationTab.tsx index 7221945b4e..a88612dfd4 100644 --- a/src/bundled/channels/ConversationTab.tsx +++ b/src/bundled/channels/ConversationTab.tsx @@ -8,7 +8,10 @@ import { } from "react"; import type { ChannelSummary } from "../../features/relay/contracts"; import type { RelaySession } from "../../features/relay/session"; -import type { ConversationExtensions } from "../../features/conversation/contracts"; +import type { + ConversationExtensions, + ConversationWorkspaceProps, +} from "../../features/conversation/contracts"; import { ConversationChannel, ConversationComposer, @@ -29,6 +32,8 @@ import styles from "./ChannelTabs.module.css"; type ConversationTabProps = { tab: Tab; intro?: ReactNode; + /** Only the channel timeline shows it, not a thread. */ + trailing?: ConversationWorkspaceProps["trailing"]; subthreadId?: string | undefined; latestRequest?: AbortSignal | undefined; active: boolean; @@ -57,6 +62,7 @@ type ConversationTabProps = { export function ConversationTab({ tab, intro, + trailing, subthreadId, latestRequest, active, @@ -208,6 +214,7 @@ export function ConversationTab({ ({ onResolvedRoot, parent, intro, + trailing, }: { intro?: import("react").ReactNode; + trailing?: { content(state: object): import("react").ReactNode }; tab: Tab; channel: { name: string }; visit: boolean; @@ -52,6 +54,7 @@ vi.mock("./ConversationTab", () => ({ > {intro} {tab.kind} in {channel.name} + {trailing?.content({ expanded: false, toggle() {} })} {!visit && " unvisited"} {onResolvedRoot && ( + + + + ), + }; +} From b42554207a5befd517c32959af45af8ea4782893 Mon Sep 17 00:00:00 2001 From: Gil Birman Date: Mon, 23 Nov 2026 17:18:45 -0600 Subject: [PATCH 2/2] Keep the trailing card clear of focus and the latest message A retained transcript's fresh latestRequest now returns a grown card to Rest, as Jump to latest and a send do, so the latest message isn't left under it. The history's scroll padding follows the card's visible top, so keyboard selection scrolls a row above the card rather than behind it. When the history can't scroll a focused row clear of a grown card, the card returns to Rest. The sheet renders after the history, so Tab reaches the card between the history and the composer. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Gil Birman --- .../messages/ChannelTimeline.test.tsx | 6 +- src/features/messages/ChannelTimeline.tsx | 29 ++++- src/features/messages/Messages.module.css | 4 +- tests/browser/conversation-workspace.spec.mjs | 102 ++++++++++++++++++ 4 files changed, 136 insertions(+), 5 deletions(-) diff --git a/src/features/messages/ChannelTimeline.test.tsx b/src/features/messages/ChannelTimeline.test.tsx index 8f85d07671..71acb34e4d 100644 --- a/src/features/messages/ChannelTimeline.test.tsx +++ b/src/features/messages/ChannelTimeline.test.tsx @@ -353,11 +353,11 @@ function setup({ }); } key = scoped.key; - // The feed renders inside the list's message context menu host, after + // The feed renders inside the list's message context menu host, before // the trailing sheet. - const [, menus] = ( + const [menus] = ( scoped.type as (props: typeof scoped.props) => ReactElement<{ - children: [unknown, ReactElement<{ children: Section }>]; + children: [ReactElement<{ children: Section }>, unknown]; }> )(scoped.props).props.children; section = menus.props.children; diff --git a/src/features/messages/ChannelTimeline.tsx b/src/features/messages/ChannelTimeline.tsx index 04fa4861f1..1dc6f2dc89 100644 --- a/src/features/messages/ChannelTimeline.tsx +++ b/src/features/messages/ChannelTimeline.tsx @@ -2076,6 +2076,7 @@ function Timeline({ latest.intent === scheduledIntent ) { scheduledIntent = ++intent.current; + restSheet(); endIndex = rows.length - 1; restore = null; pendingRestore.current = undefined; @@ -2477,6 +2478,30 @@ function Timeline({ event.target.closest("[data-message-id]")?.dataset .messageId, ); + // The scroll padding keeps keyboard focus in the history above the + // card's visible top. When the history can't scroll it clear of a grown + // card, the card returns to Rest. This runs after the focus's own scroll + // into view; a click never needs it, since the card takes the pointer. + const focused = event.target; + if ( + !sheet.current?.scrollTop || + focused === event.currentTarget || + !(focused instanceof HTMLElement) || + !focused.matches(":focus-visible") + ) + return; + queueMicrotask(() => { + const cardTop = + sheet.current?.firstElementChild?.getBoundingClientRect().bottom; + if ( + cardTop === undefined || + focused.getBoundingClientRect().bottom <= cardTop + 1 + ) + return; + restSheet(); + placeJumpToLatest(); + focused.scrollIntoView({ block: "nearest" }); + }); }} onBlur={(event) => { if (!event.currentTarget.contains(event.relatedTarget)) { @@ -2803,6 +2828,9 @@ function Timeline({ ); return ( <> + {feed} + {/* After the history, so keyboard order follows the card's place + between the history and the composer. */} {trailing && (
)} - {feed} ); } diff --git a/src/features/messages/Messages.module.css b/src/features/messages/Messages.module.css index 4e3522b8af..a2d84d0044 100644 --- a/src/features/messages/Messages.module.css +++ b/src/features/messages/Messages.module.css @@ -93,9 +93,11 @@ } /* A workspace's trailing card covers the end of the history, and a box of its rest height ends the scroll range so the latest message stays above it. - The history inset would only add a gap between the two. */ + The history inset would only add a gap between the two. Focus scrolls into + view above the card's visible top. */ .feed[data-trailing] { --history-bottom-inset: 0px; + scroll-padding-bottom: var(--timeline-trailing-rest, 0px); } /* ChannelTimeline places the sheet over the history's scrollport with the history's inline padding and measure. Only the card takes pointer input, so diff --git a/tests/browser/conversation-workspace.spec.mjs b/tests/browser/conversation-workspace.spec.mjs index ccb95e8b5f..dbfb2b5413 100644 --- a/tests/browser/conversation-workspace.spec.mjs +++ b/tests/browser/conversation-workspace.spec.mjs @@ -560,6 +560,90 @@ test.describe("trailing card", () => { await expect(toggle(page)).toHaveAttribute("aria-expanded", "false"); }); + test("keyboard selection stays above the card, and a grown card rests to show it", async ({ + page, + app, + }) => { + await open(page, app); + const region = history(page); + const focusedBottom = () => + page.evaluate( + () => document.activeElement.getBoundingClientRect().bottom, + ); + const focusedRow = () => + page.evaluate( + () => + document.activeElement.closest("[data-message-id]")?.dataset + .messageId, + ); + await select(page, { channelId: "alpha", trailing: "long" }); + await expect(toggle(page)).toHaveText("Full brief"); + await expectRest(page, region); + + // The history can't scroll the newest message above a grown card. + await toggle(page).press("Enter"); + await expect(toggle(page)).toHaveText("Hide brief"); + await settle(page, sheet(page)); + const input = page.getByRole("textbox", { name: "Message #Alpha" }); + await input.focus(); + await input.press("ArrowUp"); + await expect.poll(focusedRow).toBeTruthy(); + const rested = await expectRest(page, region); + expect(await focusedBottom()).toBeLessThanOrEqual(rested.cardScreenTop + 1); + + // At Rest above the end, Arrow Down onto a row behind the card scrolls it + // above the card. + await readEarlier(page, region); + await settle(page, region); + const { cardScreenTop } = await place(page); + const above = await region.evaluate((element, top) => { + const rows = [...element.querySelectorAll("[data-message-id]")]; + const index = rows.findIndex( + (row) => row.getBoundingClientRect().bottom > top + 1, + ); + const row = rows[index - 1]; + const target = row.querySelector(":scope > [data-layout]") ?? row; + target.tabIndex = -1; + target.focus(); + return row.dataset.messageId; + }, cardScreenTop); + expect(await focusedRow()).toBe(above); + await page.keyboard.press("ArrowDown"); + await expect.poll(focusedRow).not.toBe(above); + await settle(page, region); + expect(await focusedBottom()).toBeLessThanOrEqual(cardScreenTop + 1); + expect((await place(page)).sheetTop).toBe(0); + }); + + test("the card's controls follow the history in keyboard order", async ({ + page, + app, + browserName, + }) => { + // macOS WebKit follows the host preference: Option-Tab includes every control. + const back = + browserName === "webkit" && process.platform === "darwin" + ? "Shift+Alt+Tab" + : "Shift+Tab"; + await open(page, app); + const region = history(page); + await select(page, { channelId: "alpha", trailing: "short" }); + await expect(toggle(page)).toHaveText("Full brief"); + await page.getByRole("textbox", { name: "Message #Alpha" }).focus(); + await page.keyboard.press(back); + await expect( + card(page).getByRole("button", { name: "Approve" }), + ).toBeFocused(); + await page.keyboard.press(back); + await expect(toggle(page)).toBeFocused(); + await page.keyboard.press(back); + expect( + await region.evaluate((element) => + element.contains(document.activeElement), + ), + ).toBe(true); + }); + test.describe(() => { // Without thread fixtures, the latest row is a top-level message. test.use({ threadUnread: false }); @@ -589,6 +673,24 @@ test.describe("trailing card", () => { ).toBeInViewport(); await expectRest(page, region); }); + + test("a retained transcript's jump returns a grown card to Rest below the latest message", async ({ + page, + app, + }) => { + await open(page, app); + const region = history(page); + await select(page, { channelId: "alpha", trailing: "long" }); + await expect(toggle(page)).toHaveText("Full brief"); + await expectRest(page, region); + await readEarlier(page, region); + await overCard(page); + await wheel(page, 150, sheet(page)); + await expect(toggle(page)).toHaveText("Hide brief"); + + await jump(page).click(); + await expectRest(page, region); + }); }); test.describe(() => {