From 1ea50d2628bf407805aedd42d15697785e7a5595 Mon Sep 17 00:00:00 2001 From: Guido Vizoso Date: Tue, 1 Dec 2026 14:28:26 -0300 Subject: [PATCH 01/12] Answers set with shadcn/typeset: more room between paragraphs and headings, a longer line, plain quotes A Bot's reply, and the Markdown in an interface it draws, take typeset's spacing and type. typeset.css is shadcn's file unchanged; the conversation's tuning is .typeset-reply in styles.css. Streamdown's own utilities on headings, lists, quotes, rules and bold outrank typeset, so a reply draws those elements bare (replyMarkdownComponents). Code blocks and tables keep #2582's rules. --- .../components/channels/chat-transcript.tsx | 8 +- app/src/lib/copilot/a2ui-markdown.tsx | 12 +- app/src/lib/markdown.tsx | 76 ++- app/src/styles.css | 85 ++- app/src/typeset.css | 506 ++++++++++++++++++ biome.json | 3 +- 6 files changed, 653 insertions(+), 37 deletions(-) create mode 100644 app/src/typeset.css diff --git a/app/src/components/channels/chat-transcript.tsx b/app/src/components/channels/chat-transcript.tsx index 9cdce4bed0..70446e9243 100644 --- a/app/src/components/channels/chat-transcript.tsx +++ b/app/src/components/channels/chat-transcript.tsx @@ -136,6 +136,8 @@ import { type LinkedFile, markdownComponents, markdownPlugins, + REPLY_TYPESET_CLASS, + replyMarkdownComponents, replyRemarkPluginsFor, SentFilesContext, } from "@/lib/markdown"; @@ -1301,7 +1303,8 @@ const TranscriptMessage = memo(function TranscriptMessage({ words={text} > ) : ( `. @@ -35,7 +36,8 @@ function ReplyMarkdown({ return (
(Tag: Tag, slot: string) { + return function Bare({ + node: _node, + ...props + }: ComponentProps & { node?: unknown }) { + const Element = Tag as "div"; + return ( + )} data-streamdown={slot} /> + ); + }; +} + +/** + * A Bot's reply in a conversation, set by shadcn/typeset (`typeset.css`, tuned by `.typeset-reply` + * in styles.css). Pass both to `BotMarkdown`. + * + * WHY THE BARE ELEMENTS. Streamdown dresses its headings, lists, list items, quotes and rules in + * Tailwind utilities (`mt-6 mb-2 text-2xl`, `list-inside`, `py-1 [&>p]:inline`, an italic muted + * quote), and utilities outrank typeset, which keeps to the components layer so a component can + * always win. Drawn bare, they take typeset's spacing and type instead. Each keeps the + * `data-streamdown` name Streamdown gives it, and its own class from the markdown (a task list's + * `contains-task-list`), which typeset reads. Links, tables and code are the app's or Streamdown's + * components and keep their own styles: typeset leaves anything with `data-slot` alone. + * + * Streamdown spaces its blocks with `space-y-4`, a utility too; `.typeset-reply` in styles.css + * hands that spacing back to typeset. + */ +export const replyMarkdownComponents = { + ...markdownComponents, + h1: bare("h1", "heading-1"), + h2: bare("h2", "heading-2"), + h3: bare("h3", "heading-3"), + h4: bare("h4", "heading-4"), + h5: bare("h5", "heading-5"), + h6: bare("h6", "heading-6"), + ul: bare("ul", "unordered-list"), + ol: bare("ol", "ordered-list"), + li: bare("li", "list-item"), + blockquote: bare("blockquote", "blockquote"), + hr: bare("hr", "horizontal-rule"), + strong: bare("strong", "strong"), +}; + +export const REPLY_TYPESET_CLASS = "typeset typeset-reply"; + type Highlighted = Parameters< NonNullable[1]> >[0]; diff --git a/app/src/styles.css b/app/src/styles.css index c67b2cbbd8..591dad6cad 100644 --- a/app/src/styles.css +++ b/app/src/styles.css @@ -6,6 +6,12 @@ @import "@fontsource-variable/figtree"; @import "./theme.css"; @import "./skins/skins.css"; +/* + * shadcn/typeset, for a Bot's reply in a conversation: shadcn's file as published at + * https://ui.shadcn.com/typeset.css. Replace it whole with a newer copy and never edit it; the + * conversation's tuning is `.typeset-reply` below. + */ +@import "./typeset.css"; /* * Streamdown draws a Bot's prose, and Tailwind only ships classes it can see used. Its markup lives @@ -18,37 +24,72 @@ /* And its maths plugin, likewise. */ @source "../node_modules/@streamdown/math/dist/*.js"; -/* Conversation prose uses the chat type scale and keeps embedded code in one surface. */ -[data-reply-prose] [data-streamdown^="heading-"] { - margin-block: 1.2em 0.35em; - line-height: 1.3; -} +/* + * A Bot's reply in a conversation, set by shadcn/typeset (`replyMarkdownComponents` in + * lib/markdown.tsx draws the prose bare so typeset reaches it). Tuned for a chat column: the + * conversation's size, the one its messages and the composer use, on every window (typeset would set + * it 1.125 times larger on a narrow one, an article's choice that a phone's chat does not need), the + * leading and paragraph spacing of a long read, and headings on the chat's own smaller scale rather + * than an article's. + */ +@layer components { + .typeset-reply { + --typeset-size: var(--text-conversation); + --typeset-leading: 1.7; + --typeset-flow: 1em; + font-size: var(--typeset-size); + } -[data-reply-prose] > :first-child > [data-streamdown^="heading-"]:first-child { - margin-block-start: 0; -} + .typeset-reply :where(h1) { + font-size: 1.35em; + } -[data-reply-prose] [data-streamdown="heading-1"] { - font-size: 1.35em; -} + .typeset-reply :where(h2) { + font-size: 1.2em; + } -[data-reply-prose] [data-streamdown="heading-2"] { - font-size: 1.2em; -} + .typeset-reply :where(h3) { + font-size: 1.08em; + } -[data-reply-prose] [data-streamdown="heading-3"] { - font-size: 1.08em; -} + /* + * Blocks Streamdown draws as components of its own, which typeset does not know: the same space + * above as a paragraph. + */ + .typeset-reply + > :where( + [data-streamdown="code-block"], + [data-streamdown="table-wrapper"], + [data-streamdown="mermaid-block"], + .katex-display + ) { + margin-block-start: var(--typeset-flow); + } -[data-reply-prose] [data-streamdown="list-item"] { - padding-block: 0.125em; + /* + * Streamdown's code block is a component with its own `pre`, and typeset's code rules (a muted + * ground, padding, a smaller size) would set what its utilities leave unset. Inside one, code is + * drawn as if typeset were not there. + */ + .typeset-reply + :is([data-streamdown="code-block"], [data-streamdown="mermaid-block"]) + :is(pre, code) { + all: revert-layer; + } } -[data-reply-prose] [data-streamdown="blockquote"] { - border-inline-start: 1px solid var(--border); - font-style: normal; +/* + * Streamdown spaces a reply's blocks with `space-y-4` and the like, utilities, which outrank typeset. + * The blocks' margins go back to what the layers below give them: typeset's, and the block rule just + * above. A first block still starts flush (Streamdown's `[&>*:first-child]:mt-0` is more specific). + */ +@layer utilities { + .typeset-reply > * { + margin-block: revert-layer; + } } +/* Embedded code and tables keep to one surface in a conversation's reply. */ [data-reply-prose] [data-streamdown="code-block"] { background: var(--card); gap: 0; diff --git a/app/src/typeset.css b/app/src/typeset.css new file mode 100644 index 0000000000..5c44d33523 --- /dev/null +++ b/app/src/typeset.css @@ -0,0 +1,506 @@ +/* + * shadcn/typeset + * https://ui.shadcn.com/docs/typeset. + */ + +@layer components { + .typeset { + --typeset-font-body: inherit; + --typeset-font-heading: var(--font-heading); + --typeset-font-mono: var(--font-mono); + --typeset-size: 1em; + --typeset-leading: 1.75; + --typeset-flow: 1.25em; + } +} + +@layer components { + .typeset { + font-family: var(--typeset-font-body); + font-size: calc(var(--typeset-size) * 1.125); + line-height: var(--typeset-leading); + color: var(--color-foreground, currentColor); + overflow-wrap: break-word; + margin-trim: block-start; + + @media (min-width: 48rem), print { + font-size: var(--typeset-size); + } + + --typeset-muted: var( + --color-muted-foreground, + color-mix(in oklab, currentColor 60%, transparent) + ); + --typeset-rule: var( + --color-border, + color-mix(in oklab, currentColor 20%, transparent) + ); + } + + .typeset + *:not( + :where( + .not-typeset, + [data-not-typeset], + .not-typeset *, + [data-not-typeset] *, + .typeset [data-slot], + .typeset [data-slot] * + ) + ) { + /* Paragraphs. */ + &:where(p) { + margin-block-start: var(--typeset-flow); + margin-block-end: 0; + } + + /* Headings. */ + &:where(h1, h2, h3, h4, h5, h6) { + color: var(--color-foreground, currentColor); + font-family: var(--typeset-font-heading); + font-weight: 600; + margin-block-end: 0; + } + &:where(h1) { + font-size: 1.75em; + line-height: 1.3; + margin-block-start: var(--typeset-flow); + } + &:where(h2) { + font-size: 1.25em; + line-height: 1.4; + margin-block-start: calc(var(--typeset-flow) * 1.4); + } + &:where(h3) { + font-size: 1.125em; + line-height: 1.45; + margin-block-start: var(--typeset-flow); + } + &:where(h4) { + font-size: 1em; + line-height: 1.5; + margin-block-start: var(--typeset-flow); + } + &:where(h5) { + font-size: 0.875em; + line-height: 1.5; + font-weight: 500; + color: var(--typeset-muted); + margin-block-start: calc(var(--typeset-flow) / 0.875); + } + &:where(h6) { + font-size: 0.8125em; + line-height: 1.5; + font-weight: 500; + letter-spacing: 0.08em; + text-transform: uppercase; + color: var(--typeset-muted); + margin-block-start: calc(var(--typeset-flow) / 0.8125); + } + /* Anchors. */ + &:where([id]) { + scroll-margin-block-start: var(--typeset-flow); + } + + /* Headings own the space below them. */ + &:where(h1 + *, h2 + *, h3 + *, h4 + *, h5 + *, h6 + *) { + margin-block-start: 1em; + } + &:where(:is(h1, h2, h3, h4) :is(code)) { + font-size: 0.9em; + } + + /* Links. */ + &:where(a) { + color: inherit; + font-weight: 500; + text-decoration-line: underline; + text-decoration-color: color-mix(in oklab, currentColor 30%, transparent); + } + &:where(a:hover) { + text-decoration-color: currentColor; + } + &:where(a:focus-visible) { + outline: 2px solid var(--color-ring, currentColor); + outline-offset: 2px; + border-radius: 0.125em; + } + &:where(:is(h1, h2, h3, h4, h5, h6) :is(a)) { + font-weight: inherit; + } + + /* Inline semantics. */ + &:where(strong, b) { + font-weight: 600; + } + &:where(:is(h1, h2, h3, h4) :is(strong, b)) { + font-weight: 600; + } + &:where(mark) { + background-color: color-mix( + in oklab, + oklch(0.86 0.17 95) 40%, + transparent + ); + color: inherit; + padding: 0.05em 0.15em; + border-radius: 0.2em; + } + &:where(abbr[title]) { + text-decoration-line: underline; + text-decoration-style: dotted; + text-underline-offset: 0.2em; + cursor: help; + } + &:where(del, s) { + color: var(--typeset-muted); + text-decoration-line: line-through; + } + &:where(sup, sub) { + font-size: 0.75em; + line-height: 0; + position: relative; + vertical-align: baseline; + } + &:where(sup) { + top: -0.5em; + } + &:where(sub) { + bottom: -0.25em; + } + &:where(sup a) { + text-decoration-line: none; + font-weight: 500; + } + + /* Lists. */ + &:where(ul) { + list-style-type: disc; + } + &:where(ol) { + list-style-type: decimal; + } + &:where(ul ul) { + list-style-type: circle; + } + &:where(ul ul ul) { + list-style-type: square; + } + &:where(ol[type="a" i]) { + list-style-type: lower-alpha; + } + &:where(ol[type="i" i]) { + list-style-type: lower-roman; + } + &:where(ol[type="A" s]) { + list-style-type: upper-alpha; + } + &:where(ol[type="I" s]) { + list-style-type: upper-roman; + } + &:where(ul, ol) { + margin-block-start: var(--typeset-flow); + margin-block-end: 0; + padding-inline-start: 1.5em; + } + &:where(li) { + margin-block-start: 0.5em; + padding-inline-start: 0.4em; + } + &:where(li > p, li > ul, li > ol) { + margin-block-start: 0.5em; + } + &:where(ul > li)::marker { + color: var(--typeset-muted); + } + &:where(ol > li)::marker { + color: var(--typeset-muted); + } + + /* GFM task lists. */ + &:where(ul.contains-task-list) { + list-style-type: none; + padding-inline-start: 0.25em; + } + &:where(li.task-list-item > input[type="checkbox"]) { + margin-inline-end: 0.5em; + vertical-align: -0.1em; + accent-color: var(--color-primary, currentColor); + } + + /* Disclosures. */ + &:where(details) { + margin-block-start: var(--typeset-flow); + margin-block-end: 0; + } + &:where(summary) { + cursor: pointer; + font-weight: 500; + } + &:where(summary)::marker { + color: var(--typeset-muted); + } + + /* Keyboard keys. */ + &:where(kbd) { + font-family: inherit; + font-size: 0.85em; + font-weight: 500; + border: 1px solid var(--typeset-rule); + border-block-end-width: 2px; + border-radius: min(calc(var(--radius, 0.5em) * 0.6), 0.35em); + padding: 0.0625em 0.35em; + } + + /* Definition lists. */ + &:where(dl) { + margin-block-start: var(--typeset-flow); + margin-block-end: 0; + } + &:where(dt) { + font-weight: 500; + margin-block-start: 1em; + } + &:where(dt + dt) { + margin-block-start: 0.25em; + } + &:where(dd) { + margin-block-start: 0.25em; + margin-inline-start: 0; + padding-inline-start: 1em; + color: var(--typeset-muted); + } + + /* Inline code. */ + &:where(:not(pre) > code) { + background-color: var( + --color-muted, + color-mix(in oklab, currentColor 8%, transparent) + ); + font-family: var(--typeset-font-mono); + font-size: 0.85em; + border-radius: min(calc(var(--radius, 0.5em) * 0.6), 0.35em); + padding: 0.125em 0.3em; + } + + /* Code blocks. */ + &:where(pre) { + background-color: var( + --color-muted, + color-mix(in oklab, currentColor 8%, transparent) + ); + font-family: var(--typeset-font-mono); + font-size: 0.875em; + line-height: 1.5; + tab-size: 2; + direction: ltr; + border-radius: var(--radius, 0.5em); + padding: 0.75em 1em; + overflow-x: auto; + margin-block-start: calc(var(--typeset-flow) / 0.875); + margin-block-end: 0; + } + &:where(pre code) { + background-color: transparent; + font-family: inherit; + font-size: inherit; + padding: 0; + border-radius: 0; + } + + /* Blockquote. */ + &:where(blockquote) { + border-inline-start: 2px solid var(--typeset-rule); + padding-inline-start: 1em; + margin-block-start: var(--typeset-flow); + margin-block-end: 0; + margin-inline: 0; + } + + /* Dividers. */ + &:where(hr) { + border: 0; + border-block-start: 1px solid var(--typeset-rule); + margin-block-start: calc(var(--typeset-flow) * 2.4); + margin-block-end: 0; + } + &:where(hr + h1, hr + h2, hr + h3, hr + h4) { + margin-block-start: var(--typeset-flow); + } + + /* GFM footnotes. */ + &:where(.footnotes, [data-footnotes]) { + margin-block-start: calc(var(--typeset-flow) * 2); + border-block-start: 1px solid var(--typeset-rule); + padding-block-start: var(--typeset-flow); + font-size: 0.875em; + color: var(--typeset-muted); + } + + /* Math. */ + &:where(math[display="block"]) { + margin-block-start: var(--typeset-flow); + margin-block-end: 0; + overflow-x: auto; + overflow-y: hidden; + padding-block: 0.25em; + } + + /* Media. */ + &:where(img, video) { + border-radius: var(--radius, 0.5em); + max-width: 100%; + height: auto; + margin-block-start: var(--typeset-flow); + margin-block-end: 0; + } + &:where(p img) { + margin-block-start: 0; + } + &:where(figure) { + margin-block-start: var(--typeset-flow); + margin-block-end: 0; + margin-inline: 0; + } + &:where(figcaption, caption) { + color: var(--typeset-muted); + font-size: 0.875em; + text-align: center; + margin-block-start: calc(0.75em / 0.875); + } + &:where(caption) { + caption-side: bottom; + } + + /* Tables. Separators sit on cells, not tr:last-child: append-safe. + Bare tables stay real tables (keep their semantics) and wrap to fit. */ + &:where(table) { + max-width: 100%; + font-size: 1em; + line-height: 1.5; + font-variant-numeric: tabular-nums; + border-collapse: separate; + border-spacing: 0; + border-block-end: 1px solid var(--typeset-rule); + margin-block-start: var(--typeset-flow); + margin-block-end: 0; + } + + /* Horizontal scroll for any wide block. Wrap it and the wrapper owns the + flow margin. Tables shrink to fit, so widen the table to make it scroll + instead of compress. */ + &:where(.typeset-scroll) { + overflow-x: auto; + margin-block-start: var(--typeset-flow); + } + &:where(.typeset-scroll > *) { + margin-block-start: 0; + } + &:where(.typeset-scroll table) { + width: max-content; + max-width: none; + } + &:where(thead th) { + font-weight: 500; + text-align: start; + white-space: nowrap; + padding: 0.65em 1em; + } + &:where(:is(tbody, tfoot) :is(td, th)) { + padding: 0.75em 1em; + text-align: start; + vertical-align: top; + border-block-start: 1px solid var(--typeset-rule); + } + &:where(tbody th, tfoot th) { + font-weight: 500; + } + &:where(th:first-child, td:first-child) { + padding-inline-start: 0; + } + &:where(th[align="center"], td[align="center"]) { + text-align: center; + } + &:where(th[align="right"], td[align="right"]) { + text-align: end; + } + + /* Blocks inside list items keep the list's tighter rhythm. */ + &:where(li > blockquote, li > table, li > figure) { + margin-block-start: 0.5em; + } + &:where(li > pre) { + margin-block-start: calc(0.5em / 0.875); + } + + @media print { + &:where(pre, table, blockquote, figure) { + break-inside: avoid; + } + &:where(h1, h2, h3, h4) { + break-after: avoid; + } + } + + /* Forced colors strips the code background, so give it a border. */ + @media (forced-colors: active) { + &:where(:not(pre) > code) { + border: 1px solid; + } + } + } + + /* Components (anything with data-slot) keep their own styles. A component + placed directly in the flow gets the same space above as a paragraph. */ + .typeset + > :where([data-slot]):not( + :where( + .not-typeset, + [data-not-typeset], + .not-typeset *, + [data-not-typeset] * + ) + ) { + margin-block-start: var(--typeset-flow); + } + + /* First child adds no space above. Last so it wins ties. */ + .typeset + > :where(:first-child):not( + :where( + .not-typeset, + [data-not-typeset], + .not-typeset *, + [data-not-typeset] * + ) + ), + .typeset + > :where(:first-child) + > :where(:first-child):not( + :where( + .not-typeset, + [data-not-typeset], + .not-typeset *, + [data-not-typeset] * + ) + ), + .typeset + :where( + li > :first-child, + blockquote > :first-child, + td > :first-child, + th > :first-child, + dd > :first-child, + figure > :first-child, + figure > picture > img + ):not( + :where( + .not-typeset, + [data-not-typeset], + .not-typeset *, + [data-not-typeset] * + ) + ) { + margin-block-start: 0; + } +} diff --git a/biome.json b/biome.json index 8161850081..065927a01d 100644 --- a/biome.json +++ b/biome.json @@ -12,7 +12,8 @@ "!app/src/routeTree.gen.ts", "!desktop/src-tauri/gen", "!**/target", - "!app/tests/fixtures/arcade-catalogue.json" + "!app/tests/fixtures/arcade-catalogue.json", + "!app/src/typeset.css" ] }, "formatter": { From ff72c78074b9794e6f735d9d3f5364aa47aeb22b Mon Sep 17 00:00:00 2001 From: Guido Vizoso Date: Tue, 1 Dec 2026 14:28:26 -0300 Subject: [PATCH 02/12] A document a Bot cites is a link at the size of the sentence, with a glyph for its kind It was a bordered pill in smaller type. Now it is underlined like any link, with a muted glyph in front; its kind is still said to screen readers and left out of a table's copy. Nothing in it is taller than the text, so the line keeps its height. --- app/src/lib/markdown.tsx | 31 +++++++++++++++---------------- app/tests/a2ui-markdown.test.tsx | 4 ++-- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/app/src/lib/markdown.tsx b/app/src/lib/markdown.tsx index d96ac07ef8..d8a171add8 100644 --- a/app/src/lib/markdown.tsx +++ b/app/src/lib/markdown.tsx @@ -380,29 +380,28 @@ export const markdownComponents = { - - {/* Truncated rather than wrapped: a long file name should not reflow the sentence around it. */} - {children} + + {children} {/* - * The type, after the name. It answers "can I open this, and with what" without the reader - * hovering to read a URL, and it is the part a file name often leaves out. + * The type, for a screen reader and nobody else: the glyph says it to the eye. Left out of + * a table's copy, as before. */} - - {kind.label} + + , {kind.label} ); diff --git a/app/tests/a2ui-markdown.test.tsx b/app/tests/a2ui-markdown.test.tsx index a9b85f5a0a..016828426d 100644 --- a/app/tests/a2ui-markdown.test.tsx +++ b/app/tests/a2ui-markdown.test.tsx @@ -306,11 +306,11 @@ test("links in a Markdown component open the way a reply's do", async () => { const rel = (link: HTMLAnchorElement | undefined) => (link?.getAttribute("rel") ?? "").split(/\s+/).sort(); expect(rel(reference)).toEqual(["noopener", "noreferrer"]); - // A document in a connected system is the reply's chip, with its type after its name. + // A document in a connected system is the reply's document link, its type said after its name. const spec = links.find((link) => link.getAttribute("href")?.startsWith("https://docs.google.com/"), ); - expect(spec?.textContent).toBe("specDoc"); + expect(spec?.textContent).toBe("spec, Doc"); expect(rel(spec)).toEqual(["noopener", "noreferrer"]); // A script URL a model wrote never becomes a link that runs it. for (const link of links) From 16e9e829470b8c04dd95c5292367d2bfdbcddcfc Mon Sep 17 00:00:00 2001 From: Guido Vizoso Date: Tue, 1 Dec 2026 14:28:26 -0300 Subject: [PATCH 03/12] A conversation's text is 15px: messages, the message box and replies --text-conversation goes from 16px to the app's base 15px. The message box still opens two lines tall, now 45px. --- app/src/components/channels/composer/composer.tsx | 4 ++-- app/src/theme.css | 2 +- app/tests/composer-dictation-notice-layout.test.tsx | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/src/components/channels/composer/composer.tsx b/app/src/components/channels/composer/composer.tsx index e19f5b264b..63309db608 100644 --- a/app/src/components/channels/composer/composer.tsx +++ b/app/src/components/channels/composer/composer.tsx @@ -159,9 +159,9 @@ function stagedMimeType(attachment: Attachment): string { const MAX_HEIGHT_PX = 220; /** - * Two 24px lines: the compact composer's message box opens two lines tall and grows from there. + * Two 22.5px lines: the compact composer's message box opens two lines tall and grows from there. */ -const COMPACT_MIN_HEIGHT_PX = 48; +const COMPACT_MIN_HEIGHT_PX = 45; /** * One 24px line: a one-line box opens at this height. Given to PromptArea itself, whose own * minimum (80px) is an inline style no class can beat. diff --git a/app/src/theme.css b/app/src/theme.css index 9044e1dcb9..d3b5ef0896 100644 --- a/app/src/theme.css +++ b/app/src/theme.css @@ -150,7 +150,7 @@ body { --text-xs: 0.703125rem; /* 11.25px */ --text-sm: 0.8203125rem; /* 13.125px */ --text-base: 0.9375rem; /* 15px */ - --text-conversation: 1rem; + --text-conversation: 0.9375rem; /* 15px */ --text-conversation--line-height: 1.5; --text-lg: 1.0546875rem; /* 16.875px */ --text-xl: 1.171875rem; /* 18.75px */ diff --git a/app/tests/composer-dictation-notice-layout.test.tsx b/app/tests/composer-dictation-notice-layout.test.tsx index 7a4c3b524c..fd6da81305 100644 --- a/app/tests/composer-dictation-notice-layout.test.tsx +++ b/app/tests/composer-dictation-notice-layout.test.tsx @@ -279,10 +279,10 @@ describe.skipIf(!asked)("composer text at zoom", () => { }; }); expect(wrapped.overflowX).toBe("hidden"); - expect(wrapped.font).toBe("16px"); - expect(wrapped.line).toBe("24px"); + expect(wrapped.font).toBe("15px"); + expect(wrapped.line).toBe("22.5px"); expect(wrapped.overflowWidth).toBeLessThanOrEqual(1); - expect(wrapped.height).toBeGreaterThan(48); + expect(wrapped.height).toBeGreaterThan(45); await editor.fill("A line in a long draft.\n".repeat(40)); expect( From 2f448776963e20837beebaf467b7fe09cfe9385a Mon Sep 17 00:00:00 2001 From: Guido Vizoso Date: Tue, 1 Dec 2026 14:28:26 -0300 Subject: [PATCH 04/12] A Bot's plan for a long job, filling in as it works shared/plan.ts defines update_plan: the whole list each time, 2 to 8 steps, each pending, in progress, done or failed, and a description that keeps it to jobs of three or more steps. The app draws one plan per turn as a quiet list where it first appeared, in view while the turn runs and folded with the work once it is answered. --- .../components/channels/chat-transcript.tsx | 6 +- app/src/components/channels/plan-turns.ts | 68 ++++++++ app/src/components/tasks/turn-work.ts | 9 +- app/src/lib/copilot/plan-tool.tsx | 118 +++++++++++++ app/src/lib/copilot/provider.tsx | 3 + app/tests/plan-turns.test.ts | 161 ++++++++++++++++++ shared/plan.ts | 107 ++++++++++++ 7 files changed, 469 insertions(+), 3 deletions(-) create mode 100644 app/src/components/channels/plan-turns.ts create mode 100644 app/src/lib/copilot/plan-tool.tsx create mode 100644 app/tests/plan-turns.test.ts create mode 100644 shared/plan.ts diff --git a/app/src/components/channels/chat-transcript.tsx b/app/src/components/channels/chat-transcript.tsx index 70446e9243..9d699da9da 100644 --- a/app/src/components/channels/chat-transcript.tsx +++ b/app/src/components/channels/chat-transcript.tsx @@ -189,6 +189,7 @@ import { FileTypeIcon } from "./file-icon"; import { FollowScroll, RESUME_PX, useFollowIntent } from "./follow-intent"; import { LateRenderersContext, LateRenderersWatch } from "./late-renderers"; import { usePacedReveal } from "./paced-reveal"; +import { latestPlanPerTurn } from "./plan-turns"; import { ResearchResults } from "./research-results"; import { TeamBotConsentCard } from "./team-bot-consent"; import { ReplyToolbar } from "./telemetry-assistant-message"; @@ -2578,8 +2579,9 @@ export function ChatTranscript({ */ /* Which row each tool step was drawn in, so a row keeps its key; see `groupToolSteps`. */ const rowIdsRef = useRef(new Map()); - const visible = dropRepeatedAppCards( - toVisibleChatItems(messages, isComponent), + // One plan per turn, filling in where it first appeared (`latestPlanPerTurn`). + const visible = latestPlanPerTurn( + dropRepeatedAppCards(toVisibleChatItems(messages, isComponent)), ); const items = groupToolSteps(visible, isDrawn, rowIdsRef.current); // Task threads fold narration too. Regular conversation only folds completed tool work. diff --git a/app/src/components/channels/plan-turns.ts b/app/src/components/channels/plan-turns.ts new file mode 100644 index 0000000000..a7cabbe73e --- /dev/null +++ b/app/src/components/channels/plan-turns.ts @@ -0,0 +1,68 @@ +import { PLAN_SAVED, UPDATE_PLAN_TOOL } from "@openbot/shared/plan"; +import type { VisibleChatItem } from "./chat-messages"; +import { isPersonSentMessage } from "./transcript-turns"; + +type ToolItem = Extract; + +/** Whether a row is a Bot's plan (`update_plan`, shared/plan.ts). */ +export function isPlanStep(item: { + kind: string; + toolCall?: { function: { name: string } }; +}) { + return ( + item.kind === "tool" && item.toolCall?.function.name === UPDATE_PLAN_TOOL + ); +} + +/** + * One plan per turn: the first plan call keeps its place and shows the steps of the latest one. + * + * A Bot sends its whole plan on every update, so a long job holds five or six calls. Drawn each in + * its place, the checklist moved down the conversation with every update and the old ones stayed + * behind it. Drawn once, where the plan first appeared, it fills in where the person is already + * looking, under the same row key, so nothing is torn down and drawn again. + * + * An update the server refused (its answer is not `PLAN_SAVED`) is passed over: the checklist keeps + * the last plan that was taken. An update still arriving counts, so the list fills in as it is + * written. A turn starts at what the person sent, as the rest of the transcript reads turns. + */ +export function latestPlanPerTurn( + items: readonly VisibleChatItem[], +): VisibleChatItem[] { + const out: VisibleChatItem[] = []; + let firstAt = -1; + for (const item of items) { + if ( + item.kind === "attachments" || + (item.kind === "text" && isPersonSentMessage(item.role, item.text)) + ) { + firstAt = -1; + out.push(item); + continue; + } + if (item.kind !== "tool" || !isPlanStep(item)) { + out.push(item); + continue; + } + if (firstAt === -1) { + firstAt = out.length; + out.push(item); + continue; + } + if (item.result !== undefined && !item.result.includes(PLAN_SAVED)) + continue; + const { result: _earlier, ...first } = out[firstAt] as ToolItem; + out[firstAt] = { + ...first, + toolCall: { + ...first.toolCall, + function: { + ...first.toolCall.function, + arguments: item.toolCall.function.arguments, + }, + }, + ...(item.result === undefined ? {} : { result: item.result }), + }; + } + return out; +} diff --git a/app/src/components/tasks/turn-work.ts b/app/src/components/tasks/turn-work.ts index ddde625f65..221d92c0d1 100644 --- a/app/src/components/tasks/turn-work.ts +++ b/app/src/components/tasks/turn-work.ts @@ -1,5 +1,6 @@ import { SEND_FILE_TOOL } from "@openbot/shared/send-file"; import { SUBAGENT_TOOL } from "@openbot/shared/subagent"; +import { isPlanStep } from "@/components/channels/plan-turns"; import { asksThePerson, type TranscriptItem, @@ -66,6 +67,8 @@ function isWorkStep(item: Extract): boolean { if (name === SEND_FILE_TOOL && sentFileOf(readOutcome(item.result))) return false; if (name.startsWith("mcp__") || name === SUBAGENT_TOOL) return true; + // A Bot's plan is how the work went, folded with it once the answer is in. + if (isPlanStep(item)) return true; if (name.startsWith("computer_")) return !name.startsWith("computer_request_"); return claudeCodeCall(name, args); @@ -162,6 +165,8 @@ export function foldTurnWork( for (let index = start.from; index < end; index += 1) { const item = items[index]; if (!item || index === answer) continue; + // The plan stays in view while its turn runs: it is how the person sees how far along it is. + if (inFlight && isPlanStep(item)) continue; // Keep existing refusal and issue notices at their original place in conversation replies. if (scope === "conversation" && hasVisibleOutcome(item)) continue; if ( @@ -193,7 +198,9 @@ export function stepsIn(work: TurnWork): number { (item.kind === "tools" ? item.steps.length : item.kind === "tool" - ? 1 + ? isPlanStep(item) + ? 0 + : 1 : 0), 0, ); diff --git a/app/src/lib/copilot/plan-tool.tsx b/app/src/lib/copilot/plan-tool.tsx new file mode 100644 index 0000000000..90e3657308 --- /dev/null +++ b/app/src/lib/copilot/plan-tool.tsx @@ -0,0 +1,118 @@ +import { useRenderTool } from "@copilotkit/react-core/v2"; +import { + type PlanStep, + type PlanStepStatus, + readPlan, + UPDATE_PLAN_TOOL, +} from "@openbot/shared/plan"; +import { z } from "zod"; +import { IconCheck, IconListCheck, IconX } from "@/components/icons"; +import { cn } from "@/lib/utils"; + +/** + * A Bot's plan for a long job (`update_plan`, shared/plan.ts): the checklist the person watches fill + * in while the job runs. + * + * RENDER ONLY. The server answers the call and writes nothing; the plan is the call's arguments. + * + * ONE CHECKLIST PER TURN. A Bot sends the whole list on each update, so a turn holds several calls; + * the transcript keeps one, at the first call's place with the latest call's steps + * (`latestPlanPerTurn`), so the checklist fills in where it first appeared instead of moving down + * the conversation with every update. Open while the turn runs; folded with the rest of the turn's + * work once the answer is in. + * + * DRAWN AS A STEP ROW IS, NOT AS A CARD. A line in the work's own muted type ("Plan ยท 1 of 4 done"), + * and the steps hung under it on the rule a line's opened part hangs on (tool-line.tsx), one short + * line each. A boxed checklist stood out above the work it was only keeping track of. + * + * THE STEP UNDER WAY IS MARKED, NOT ANIMATED. The step row the Bot is running already shimmers, and + * a plan cannot tell when its turn ends: a step left in progress would have shimmered on for ever. + * + * Drawn as its arguments arrive, so a plan still being written fills in a step at a time. + */ +const parameters = z.object({ + steps: z + .array( + z.object({ step: z.string().optional(), status: z.string().optional() }), + ) + .optional(), +}); + +const SAID: Record = { + completed: "done", + in_progress: "in progress", + pending: "not started", + failed: "couldn't be done", +}; + +function Mark({ status }: { status: PlanStepStatus }) { + if (status === "completed") + return ; + if (status === "failed") + return ; + return ( + + {status === "in_progress" ? ( + + ) : null} + + ); +} + +export function PlanList({ steps }: { steps: readonly PlanStep[] }) { + const done = steps.filter((step) => step.status === "completed").length; + return ( +
+
+ + Plan + + {done} of {steps.length} done + +
+
    + {steps.map(({ step, status }, index) => ( +
  1. + + + + + {step} + , {SAID[status]} + +
  2. + ))} +
+
+ ); +} + +export function PlanTool() { + useRenderTool({ + name: UPDATE_PLAN_TOOL, + parameters, + render: ({ parameters: given }) => { + const steps = readPlan(given); + return steps && steps.length > 0 ? : null; + }, + }); + return null; +} diff --git a/app/src/lib/copilot/provider.tsx b/app/src/lib/copilot/provider.tsx index ee9ed61a5b..0be7ef50b8 100644 --- a/app/src/lib/copilot/provider.tsx +++ b/app/src/lib/copilot/provider.tsx @@ -26,6 +26,7 @@ import { GenerateImageTool } from "./generate-image-tool"; import { GENERATIVE_UI_DESIGN_SKILL } from "./generative-ui"; import { HandoffTool } from "./handoff-tool"; import { OrchestrationTools } from "./orchestration-tools"; +import { PlanTool } from "./plan-tool"; import { SandboxedTools } from "./sandboxed-tools"; import { SignInTool } from "./sign-in-tool"; import { SkillTools } from "./skill-tools"; @@ -107,6 +108,8 @@ export function CopilotProvider({ children }: { children: ReactNode }) { {/* A Bot making a picture: its card, from the call and its stored answer. Runs on the server. */} + {/* A Bot's checklist of a long job, open while it runs. Answered on the server. */} + {/* A Bot reading, answering and resolving comments on an artifact. Runs on the server. */} {/* A coding harness Bot's own tools, which it runs itself: commands, diffs and its plan. */} diff --git a/app/tests/plan-turns.test.ts b/app/tests/plan-turns.test.ts new file mode 100644 index 0000000000..c199bbf62f --- /dev/null +++ b/app/tests/plan-turns.test.ts @@ -0,0 +1,161 @@ +import { describe, expect, test } from "bun:test"; +import { PLAN_SAVED, readPlan, UPDATE_PLAN_TOOL } from "@openbot/shared/plan"; +import type { VisibleChatItem } from "@/components/channels/chat-messages"; +import { latestPlanPerTurn } from "@/components/channels/plan-turns"; +import { foldTurnWork, stepsIn } from "@/components/tasks/turn-work"; + +/** + * A Bot's plan (`update_plan`) is one checklist per turn: it fills in where it first appeared, and + * stays in view while the turn runs. + */ + +const asked = (id: string): VisibleChatItem => ({ + kind: "text", + id, + role: "user", + text: "Draft replies to the customer emails", +}); + +const said = (id: string, text: string): VisibleChatItem => ({ + kind: "text", + id, + role: "assistant", + text, +}); + +function plan( + id: string, + statuses: string[], + /** `null`: its answer has not come back yet. */ + result: string | null = PLAN_SAVED, +): VisibleChatItem { + return { + kind: "tool", + id, + toolCall: { + id: `call-${id}`, + type: "function", + function: { + name: UPDATE_PLAN_TOOL, + arguments: JSON.stringify({ + steps: statuses.map((status, index) => ({ + step: `Step ${index + 1}`, + status, + })), + }), + }, + }, + ...(result === null ? {} : { result }), + }; +} + +function gmail(id: string): VisibleChatItem { + return { + kind: "tool", + id, + toolCall: { + id: `call-${id}`, + type: "function", + function: { + name: "mcp__composio-gmail__GMAIL_FETCH_EMAILS", + arguments: "{}", + }, + }, + result: '{"messages":[]}', + }; +} + +const statusesOf = (item: VisibleChatItem | undefined) => + item?.kind === "tool" + ? readPlan(item.toolCall.function.arguments)?.map((step) => step.status) + : undefined; + +describe("one plan per turn", () => { + test("the first plan keeps its place and shows the latest steps", () => { + const items = latestPlanPerTurn([ + asked("u1"), + plan("p1", ["in_progress", "pending", "pending"]), + gmail("g1"), + plan("p2", ["completed", "in_progress", "pending"]), + gmail("g2"), + plan("p3", ["completed", "completed", "in_progress"]), + ]); + expect(items.map((item) => item.id)).toEqual(["u1", "p1", "g1", "g2"]); + expect(statusesOf(items[1])).toEqual([ + "completed", + "completed", + "in_progress", + ]); + }); + + test("an update still arriving fills the checklist in as it is written", () => { + const items = latestPlanPerTurn([ + asked("u1"), + plan("p1", ["in_progress", "pending"]), + plan("p2", ["completed", "in_progress"], null), + ]); + expect(statusesOf(items[1])).toEqual(["completed", "in_progress"]); + expect(items[1]?.kind === "tool" && items[1].result).toBeUndefined(); + }); + + test("an update the server refused leaves the last plan it took", () => { + const items = latestPlanPerTurn([ + asked("u1"), + plan("p1", ["in_progress", "pending"]), + plan("p2", ["completed"], "Send the whole plan: 2 to 8 steps."), + ]); + expect(statusesOf(items[1])).toEqual(["in_progress", "pending"]); + }); + + test("each turn has a plan of its own", () => { + const items = latestPlanPerTurn([ + asked("u1"), + plan("p1", ["completed", "completed"]), + said("a1", "Done."), + asked("u2"), + plan("p2", ["in_progress", "pending"]), + ]); + expect(items.map((item) => item.id)).toEqual([ + "u1", + "p1", + "a1", + "u2", + "p2", + ]); + }); +}); + +describe("the plan in a turn's fold", () => { + test("stays in view while a task's turn runs", () => { + const items = latestPlanPerTurn([ + asked("u1"), + plan("p1", ["completed", "in_progress"]), + gmail("g1"), + ]); + const folds = foldTurnWork(items, true); + expect(folds.inside.has("p1")).toBe(false); + expect(folds.inside.has("g1")).toBe(true); + }); + + test("folds with the work once the answer is in, and is not counted as a step", () => { + const items = latestPlanPerTurn([ + asked("u1"), + plan("p1", ["completed", "completed"]), + gmail("g1"), + said("a1", "Four drafts are in Gmail."), + ]); + const folds = foldTurnWork(items, false, new Set(), "conversation"); + expect(folds.inside.has("p1")).toBe(true); + const work = folds.at.get("p1"); + expect(work && stepsIn(work)).toBe(1); + }); +}); + +describe("reading a plan", () => { + test("is tolerant of a plan still arriving", () => { + expect(readPlan('{"steps":[{"step":"Read')).toBeNull(); + expect( + readPlan({ steps: [{ step: "Read the emails" }, { status: "pending" }] }), + ).toEqual([{ step: "Read the emails", status: "pending" }]); + }); +}); diff --git a/shared/plan.ts b/shared/plan.ts new file mode 100644 index 0000000000..d1d7c453c4 --- /dev/null +++ b/shared/plan.ts @@ -0,0 +1,107 @@ +import { z } from "zod"; + +/** + * The checklist a Bot keeps of a long job, which the person watches fill in as the job runs. + * + * The server holds the tool and answers it at once, writing nothing: the plan lives in the + * conversation's own messages, as each call's arguments. The app draws the turn's latest plan as one + * checklist, open while the turn runs and folded with the rest of the work once the answer is in + * (app/src/lib/copilot/plan-tool.tsx). + * + * WHY A TOOL. A Bot that writes its steps down and ticks them off keeps track of a long job: it does + * not stop at step three of five and say it is done. And the person sees where it is, rather than a + * column of steps with no end in sight. + * + * WHAT IT COSTS, AND THE RULES THAT KEEP IT SMALL. Its description rides on every request, and each + * update is a call the model writes. So the description keeps it to jobs of three or more steps, a + * short list in a few words a step, the whole list on each update, and updates made beside the + * job's next call rather than as a step of their own. + */ +export const UPDATE_PLAN_TOOL = "update_plan"; + +export const PLAN_STEP_STATUSES = [ + "pending", + "in_progress", + "completed", + "failed", +] as const; + +export type PlanStepStatus = (typeof PLAN_STEP_STATUSES)[number]; + +export type PlanStep = { step: string; status: PlanStepStatus }; + +/** The most steps a plan holds: a longer list is a job to break up, not a checklist to read. */ +export const MAX_PLAN_STEPS = 8; + +/** What the Bot sends. Strict, so a misspelt field is refused and the Bot says it again properly. */ +export const planParameters = z + .object({ + steps: z + .array( + z + .object({ + step: z + .string() + .trim() + .min(1) + .max(120) + .describe( + 'The step, in a few words the person would use: "Read the customer emails", "Draft a reply to each".', + ), + status: z + .enum(PLAN_STEP_STATUSES) + .describe( + "pending: not started. in_progress: the one you are on. completed: done. failed: you could not do it.", + ), + }) + .strict(), + ) + .min(2) + .max(MAX_PLAN_STEPS) + .describe("The whole plan, in order, every time: not only what changed."), + }) + .strict(); + +export const UPDATE_PLAN_TOOL_DESCRIPTION = [ + "Keep a short checklist of a long job, which the person sees fill in while you work.", + "Use it only for a job of three or more distinct steps, such as reading several things and then writing from them. Never for a question you can answer in one or two steps.", + "Send the whole list each time, 2 to 8 steps of a few words each. Mark the step you are on in_progress, one at a time; each finished step completed; and a step you could not do failed, then say why in your answer.", + "Write the plan before the first step. Then update it in the same step as your next call, not as a step of its own.", + "Mark the last step completed only once it is really done, checked where it can be.", + "Do not repeat the list in your words: the person can see it.", +].join(" "); + +/** The answer to an accepted plan: short, since it is read back on every later step of the run. */ +export const PLAN_SAVED = "Plan updated. Carry on."; + +/** + * A plan's steps, from a call's arguments as the conversation keeps them: an object, or its JSON as + * text. Tolerant, for a plan still arriving: a step with no words yet is left out, an unknown status + * reads as pending. Null when there is no list at all. + */ +export function readPlan(args: unknown): PlanStep[] | null { + let value = args; + if (typeof value === "string") { + try { + value = JSON.parse(value); + } catch { + return null; + } + } + if (typeof value !== "object" || value === null) return null; + const steps = (value as { steps?: unknown }).steps; + if (!Array.isArray(steps)) return null; + const read: PlanStep[] = []; + for (const entry of steps) { + if (typeof entry !== "object" || entry === null) continue; + const { step, status } = entry as { step?: unknown; status?: unknown }; + if (typeof step !== "string" || step.trim() === "") continue; + read.push({ + step: step.trim(), + status: (PLAN_STEP_STATUSES as readonly unknown[]).includes(status) + ? (status as PlanStepStatus) + : "pending", + }); + } + return read; +} From 3a35dc7ccfa4d642f242e72930bce7b4a90c5fb2 Mon Sep 17 00:00:00 2001 From: Guido Vizoso Date: Tue, 1 Dec 2026 14:28:26 -0300 Subject: [PATCH 05/12] Changelog: easier long answers, document links, 15px conversation text, a Bot's plan --- CHANGELOG.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 838e1d80f8..242c92be50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,24 @@ Newest first. `Unreleased` is what is on `main` and not yet tagged. ## Unreleased +**Conversations.** + +- **Long answers are easier to read.** A Bot's reply, and the Markdown in an interface it draws, + are set with shadcn/typeset: more space between paragraphs and above headings, a longer line + height, list markers outside the text, and a quote as a plain rule instead of grey italics. + Tables, code blocks and formulas are drawn as before. +- **A document a Bot cites is a link at the size of the sentence.** A Google Doc, Sheet, Slides, + Drive file or Notion page was a small bordered pill; it is now underlined like any other link, + with a small glyph for its kind in front. Screen readers still hear its kind. +- **A conversation's text is 15px.** The person's messages, the message box and the Bot's replies + are set at the size the rest of the app's text uses, down from 16px. The message box still opens + two lines tall. +- **A Bot keeps a plan on a long job, and the person watches it fill in.** On a job of three or more + steps, a Bot whose server offers the `update_plan` tool writes a short checklist and ticks it off + as it goes. It is drawn as a quiet list under the question while the job runs, and folds with the + rest of the work once the answer is in. An app from before this release shows the plan's calls + as ordinary steps. + ## 1.2.5 **Before upgrading.** From 3e3f8d85fd4c747f9322ec269466e4369adf763e Mon Sep 17 00:00:00 2001 From: Guido Vizoso Date: Tue, 1 Dec 2026 16:44:27 -0300 Subject: [PATCH 06/12] A Bot's plan starts again at each routine firing, carries on past the person's answer to its question, and keeps its last whole plan while an update is written --- app/src/components/channels/plan-turns.ts | 52 +++++++++-- .../components/channels/transcript-turns.ts | 6 +- app/tests/plan-turns.test.ts | 92 ++++++++++++++++++- 3 files changed, 138 insertions(+), 12 deletions(-) diff --git a/app/src/components/channels/plan-turns.ts b/app/src/components/channels/plan-turns.ts index a7cabbe73e..d9e1d22781 100644 --- a/app/src/components/channels/plan-turns.ts +++ b/app/src/components/channels/plan-turns.ts @@ -1,6 +1,11 @@ -import { PLAN_SAVED, UPDATE_PLAN_TOOL } from "@openbot/shared/plan"; +import { + PLAN_SAVED, + planParameters, + UPDATE_PLAN_TOOL, +} from "@openbot/shared/plan"; +import { readFiring } from "@/lib/channels/routine-firing"; import type { VisibleChatItem } from "./chat-messages"; -import { isPersonSentMessage } from "./transcript-turns"; +import { isPersons } from "./transcript-turns"; type ToolItem = Extract; @@ -15,16 +20,45 @@ export function isPlanStep(item: { } /** - * One plan per turn: the first plan call keeps its place and shows the steps of the latest one. + * Where one job's plan ends and the next one's begins: where a turn starts (`isPersons`, as + * `turnsOf` reads turns), and where a routine fires. Each firing is a run of its own, so its plan is + * a checklist of its own, though no turn starts there. The person's answer to a question the Bot + * asked starts nothing: the job carries on, and so does its plan. + */ +function startsAPlan(item: VisibleChatItem): boolean { + return ( + isPersons(item) || + (item.kind === "text" && + item.role === "user" && + readFiring(item.text) !== null) + ); +} + +/** + * Whether a call's arguments are a whole plan the server would take. An update still arriving is + * JSON cut off part way: drawn as it came, the checklist dropped to its first step and its done + * steps went back to not started, on every update. + */ +function isWholePlan(args: string): boolean { + try { + return planParameters.safeParse(JSON.parse(args)).success; + } catch { + return false; + } +} + +/** + * One plan per job: the first plan call keeps its place and shows the steps of the latest one. * * A Bot sends its whole plan on every update, so a long job holds five or six calls. Drawn each in * its place, the checklist moved down the conversation with every update and the old ones stayed * behind it. Drawn once, where the plan first appeared, it fills in where the person is already * looking, under the same row key, so nothing is torn down and drawn again. * - * An update the server refused (its answer is not `PLAN_SAVED`) is passed over: the checklist keeps - * the last plan that was taken. An update still arriving counts, so the list fills in as it is - * written. A turn starts at what the person sent, as the rest of the transcript reads turns. + * An update is taken once its arguments are a whole plan: until then the checklist keeps the last + * one, so it never blanks or steps back while the next is written. An update the server refused (its + * answer is not `PLAN_SAVED`) is passed over too. The job's first plan is drawn as it arrives, so the + * list fills in a step at a time the first time. A job starts where `startsAPlan` says. */ export function latestPlanPerTurn( items: readonly VisibleChatItem[], @@ -32,10 +66,7 @@ export function latestPlanPerTurn( const out: VisibleChatItem[] = []; let firstAt = -1; for (const item of items) { - if ( - item.kind === "attachments" || - (item.kind === "text" && isPersonSentMessage(item.role, item.text)) - ) { + if (startsAPlan(item)) { firstAt = -1; out.push(item); continue; @@ -51,6 +82,7 @@ export function latestPlanPerTurn( } if (item.result !== undefined && !item.result.includes(PLAN_SAVED)) continue; + if (!isWholePlan(item.toolCall.function.arguments)) continue; const { result: _earlier, ...first } = out[firstAt] as ToolItem; out[firstAt] = { ...first, diff --git a/app/src/components/channels/transcript-turns.ts b/app/src/components/channels/transcript-turns.ts index 8cfd827266..b0caa5e43d 100644 --- a/app/src/components/channels/transcript-turns.ts +++ b/app/src/components/channels/transcript-turns.ts @@ -32,7 +32,11 @@ export type Turn = { reply: string; }; -function isPersons(item: TranscriptItem): boolean { +/** + * Whether a row is the person sending something that starts a turn (`turnsOf`): their text or files, + * not a routine firing, and not their answer to a question the Bot asked. + */ +export function isPersons(item: TranscriptItem): boolean { return ( (item.kind === "text" && isPersonSentMessage(item.role, item.text) && diff --git a/app/tests/plan-turns.test.ts b/app/tests/plan-turns.test.ts index c199bbf62f..cc2d8cb3fb 100644 --- a/app/tests/plan-turns.test.ts +++ b/app/tests/plan-turns.test.ts @@ -1,5 +1,6 @@ import { describe, expect, test } from "bun:test"; import { PLAN_SAVED, readPlan, UPDATE_PLAN_TOOL } from "@openbot/shared/plan"; +import { frameFiring } from "@openbot/shared/routine-firing"; import type { VisibleChatItem } from "@/components/channels/chat-messages"; import { latestPlanPerTurn } from "@/components/channels/plan-turns"; import { foldTurnWork, stepsIn } from "@/components/tasks/turn-work"; @@ -16,6 +17,21 @@ const asked = (id: string): VisibleChatItem => ({ text: "Draft replies to the customer emails", }); +const fired = (id: string): VisibleChatItem => ({ + kind: "text", + id, + role: "user", + text: frameFiring("Draft replies to today's customer emails"), +}); + +/** The person answering a question the Bot asked: stored as `person-response:`. */ +const answered = (id: string): VisibleChatItem => ({ + kind: "text", + id: `person-response:${id}`, + role: "user", + text: "The formal tone", +}); + const said = (id: string, text: string): VisibleChatItem => ({ kind: "text", id, @@ -88,7 +104,7 @@ describe("one plan per turn", () => { ]); }); - test("an update still arriving fills the checklist in as it is written", () => { + test("an update whose arguments are whole is taken before its answer comes back", () => { const items = latestPlanPerTurn([ asked("u1"), plan("p1", ["in_progress", "pending"]), @@ -98,6 +114,38 @@ describe("one plan per turn", () => { expect(items[1]?.kind === "tool" && items[1].result).toBeUndefined(); }); + test("an update still being written leaves the last whole plan in place", () => { + const whole = plan("p2", ["completed", "completed", "in_progress"], null); + const args = whole.kind === "tool" ? whole.toolCall.function.arguments : ""; + // Every cut of the arguments as they stream in, from no steps yet to all but the closing brace. + for (const cut of [12, 40, args.length - 30, args.length - 1]) { + const streaming = + whole.kind === "tool" + ? { + ...whole, + toolCall: { + ...whole.toolCall, + function: { + ...whole.toolCall.function, + arguments: args.slice(0, cut), + }, + }, + } + : whole; + const items = latestPlanPerTurn([ + asked("u1"), + plan("p1", ["completed", "in_progress", "pending"]), + streaming, + ]); + expect(statusesOf(items[1])).toEqual([ + "completed", + "in_progress", + "pending", + ]); + expect(items[1]?.kind === "tool" && items[1].result).toBe(PLAN_SAVED); + } + }); + test("an update the server refused leaves the last plan it took", () => { const items = latestPlanPerTurn([ asked("u1"), @@ -125,6 +173,48 @@ describe("one plan per turn", () => { }); }); +describe("where a job's plan starts", () => { + test("each firing of a routine has a plan of its own", () => { + const items = latestPlanPerTurn([ + fired("f1"), + plan("p1", ["completed", "completed"]), + said("a1", "Four drafts are in Gmail."), + fired("f2"), + plan("p2", ["in_progress", "pending"]), + ]); + expect(items.map((item) => item.id)).toEqual([ + "f1", + "p1", + "a1", + "f2", + "p2", + ]); + expect(statusesOf(items[1])).toEqual(["completed", "completed"]); + expect(statusesOf(items[4])).toEqual(["in_progress", "pending"]); + }); + + test("the person's answer to the Bot's question carries the same plan on", () => { + const items = latestPlanPerTurn([ + asked("u1"), + plan("p1", ["completed", "in_progress", "pending"]), + said("q1", "Formal or casual?"), + answered("q1"), + plan("p2", ["completed", "completed", "in_progress"]), + ]); + expect(items.map((item) => item.id)).toEqual([ + "u1", + "p1", + "q1", + "person-response:q1", + ]); + expect(statusesOf(items[1])).toEqual([ + "completed", + "completed", + "in_progress", + ]); + }); +}); + describe("the plan in a turn's fold", () => { test("stays in view while a task's turn runs", () => { const items = latestPlanPerTurn([ From b8eaa7698ff45306c9e1d1c5477ee5231b5c98cf Mon Sep 17 00:00:00 2001 From: Guido Vizoso Date: Tue, 1 Dec 2026 16:44:27 -0300 Subject: [PATCH 07/12] The message box stays at 16px, so iPhone Safari doesn't zoom the page when it's tapped --- .../components/channels/composer/composer.tsx | 23 ++++++++++--------- app/src/theme.css | 3 +++ .../composer-dictation-notice-layout.test.tsx | 6 ++--- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/app/src/components/channels/composer/composer.tsx b/app/src/components/channels/composer/composer.tsx index 63309db608..1d5126185f 100644 --- a/app/src/components/channels/composer/composer.tsx +++ b/app/src/components/channels/composer/composer.tsx @@ -3,12 +3,6 @@ import { type AttachmentsConfig, useAttachments, } from "@copilotkit/react-core/v2"; -import { - IconArrowUp, - IconLoader2, - IconPlayerStopFilled, - IconPlus, -} from "@/components/icons"; import { PromptArea, type PromptAreaHandle } from "prompt-area"; import { isSegmentsEmpty, @@ -29,6 +23,12 @@ import { useState, } from "react"; import { attachmentModality } from "@/components/channels/chat-messages"; +import { + IconArrowUp, + IconLoader2, + IconPlayerStopFilled, + IconPlus, +} from "@/components/icons"; import { IconWaveform } from "@/components/icons/waveform"; import { useTouchTyping } from "@/hooks/use-touch-typing"; import { @@ -159,9 +159,9 @@ function stagedMimeType(attachment: Attachment): string { const MAX_HEIGHT_PX = 220; /** - * Two 22.5px lines: the compact composer's message box opens two lines tall and grows from there. + * Two 24px lines: the compact composer's message box opens two lines tall and grows from there. */ -const COMPACT_MIN_HEIGHT_PX = 45; +const COMPACT_MIN_HEIGHT_PX = 48; /** * One 24px line: a one-line box opens at this height. Given to PromptArea itself, whose own * minimum (80px) is an inline style no class can beat. @@ -1984,10 +1984,11 @@ export function Composer({

) : null; - // Match the transcript. At fractional zoom, WebKit can report a pixel of horizontal overflow - // even when the text wraps. Keep PromptArea's vertical scrolling for long drafts. + // 16px, a pixel over the transcript's 15: iPhone Safari zooms the page into a field set any + // smaller. At fractional zoom, WebKit can report a pixel of horizontal overflow even when the + // text wraps. Keep PromptArea's vertical scrolling for long drafts. const inputClassName = cn( - "w-full border-0 bg-transparent p-0 text-(length:--text-conversation)/(--text-conversation--line-height) shadow-none [&_.prompt-area-editor]:overflow-x-hidden", + "w-full border-0 bg-transparent p-0 text-(length:--text-composer)/(--text-composer--line-height) shadow-none [&_.prompt-area-editor]:overflow-x-hidden", editorClassName, ); diff --git a/app/src/theme.css b/app/src/theme.css index d3b5ef0896..d000e947ca 100644 --- a/app/src/theme.css +++ b/app/src/theme.css @@ -152,6 +152,9 @@ body { --text-base: 0.9375rem; /* 15px */ --text-conversation: 0.9375rem; /* 15px */ --text-conversation--line-height: 1.5; + /* The message box stays at 16px: iPhone Safari zooms the page into a field set any smaller. */ + --text-composer: 1rem; /* 16px */ + --text-composer--line-height: 1.5; --text-lg: 1.0546875rem; /* 16.875px */ --text-xl: 1.171875rem; /* 18.75px */ --text-2xl: 1.40625rem; /* 22.5px */ diff --git a/app/tests/composer-dictation-notice-layout.test.tsx b/app/tests/composer-dictation-notice-layout.test.tsx index fd6da81305..7a4c3b524c 100644 --- a/app/tests/composer-dictation-notice-layout.test.tsx +++ b/app/tests/composer-dictation-notice-layout.test.tsx @@ -279,10 +279,10 @@ describe.skipIf(!asked)("composer text at zoom", () => { }; }); expect(wrapped.overflowX).toBe("hidden"); - expect(wrapped.font).toBe("15px"); - expect(wrapped.line).toBe("22.5px"); + expect(wrapped.font).toBe("16px"); + expect(wrapped.line).toBe("24px"); expect(wrapped.overflowWidth).toBeLessThanOrEqual(1); - expect(wrapped.height).toBeGreaterThan(45); + expect(wrapped.height).toBeGreaterThan(48); await editor.fill("A line in a long draft.\n".repeat(40)); expect( From 8402ec5c081222cb6c5945553a3897dd1b8941bc Mon Sep 17 00:00:00 2001 From: Guido Vizoso Date: Tue, 1 Dec 2026 16:44:27 -0300 Subject: [PATCH 08/12] update_plan has its step words: Updating the plan, Updated the plan --- shared/tool-name.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/shared/tool-name.ts b/shared/tool-name.ts index 6d093f0d9e..352c878e5d 100644 --- a/shared/tool-name.ts +++ b/shared/tool-name.ts @@ -28,6 +28,7 @@ import { REACT_TOOL, STOP_TOOL, } from "./orchestration"; +import { UPDATE_PLAN_TOOL } from "./plan"; import { READ_RESULT_PART } from "./read-result-part"; import { RECALL_EARLIER_RESULTS } from "./recall-earlier-results"; import { RESEARCH_ROLE_LABELS, researchRoleOfTool } from "./research"; @@ -997,6 +998,13 @@ const OWN_TOOLS: Record = { attempted: "Send a file", subject: "path", }, + // A Bot's checklist of a long job. The app draws it as one (plan-tool.tsx); where it does not, a + // line. Its answer is a note for the model. + [UPDATE_PLAN_TOOL]: { + running: "Updating the plan", + done: "Updated the plan", + answersTheModel: true, + }, [GENERATE_IMAGE_TOOL]: { running: "Making an image", done: "Made an image", From d015198b0b17cf2d584a885726f4187e47d4d6d1 Mon Sep 17 00:00:00 2001 From: Guido Vizoso Date: Tue, 1 Dec 2026 16:57:47 -0300 Subject: [PATCH 09/12] The message box is 15px at a computer, like the conversation, and 16px on a touch screen, where Safari would zoom into it --- CHANGELOG.md | 5 ++- .../components/channels/composer/composer.tsx | 23 +++++++--- app/src/theme.css | 6 +-- .../composer-dictation-notice-layout.test.tsx | 43 ++++++++++++++++--- 4 files changed, 58 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f81b89c69..c434ae006c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -59,8 +59,9 @@ Newest first. `Unreleased` is what is on `main` and not yet tagged. Drive file or Notion page was a small bordered pill; it is now underlined like any other link, with a small glyph for its kind in front. Screen readers still hear its kind. - **A conversation's text is 15px.** The person's messages and the Bot's replies are set at the - size the rest of the app's text uses, down from 16px. The message box stays at 16px, so an iPhone - doesn't zoom the page when it's tapped. + size the rest of the app's text uses, down from 16px, and so is the message box on a computer. On + a phone or a tablet the message box stays at 16px, so Safari doesn't zoom the page when it's + tapped. - **A Bot keeps a plan on a long job, and the person watches it fill in.** On a job of three or more steps, a Bot whose server offers the `update_plan` tool writes a short checklist and ticks it off as it goes. It is drawn as a quiet list under the question while the job runs, and folds with the diff --git a/app/src/components/channels/composer/composer.tsx b/app/src/components/channels/composer/composer.tsx index 1d5126185f..9a2e62163c 100644 --- a/app/src/components/channels/composer/composer.tsx +++ b/app/src/components/channels/composer/composer.tsx @@ -159,9 +159,11 @@ function stagedMimeType(attachment: Attachment): string { const MAX_HEIGHT_PX = 220; /** - * Two 24px lines: the compact composer's message box opens two lines tall and grows from there. + * Two lines: the compact composer's message box opens two lines tall and grows from there. 22.5px + * lines at 15px; 24px lines at the 16px a touch screen gets (see `inputClassName`). */ -const COMPACT_MIN_HEIGHT_PX = 48; +const COMPACT_MIN_HEIGHT_PX = 45; +const COMPACT_TOUCH_MIN_HEIGHT_PX = 48; /** * One 24px line: a one-line box opens at this height. Given to PromptArea itself, whose own * minimum (80px) is an inline style no class can beat. @@ -1984,11 +1986,14 @@ export function Composer({

) : null; - // 16px, a pixel over the transcript's 15: iPhone Safari zooms the page into a field set any - // smaller. At fractional zoom, WebKit can report a pixel of horizontal overflow even when the - // text wraps. Keep PromptArea's vertical scrolling for long drafts. + // The transcript's 15px at a computer. On a touch screen 16px: iPhone Safari zooms the page into + // a field set any smaller. At fractional zoom, WebKit can report a pixel of horizontal overflow + // even when the text wraps. Keep PromptArea's vertical scrolling for long drafts. const inputClassName = cn( - "w-full border-0 bg-transparent p-0 text-(length:--text-composer)/(--text-composer--line-height) shadow-none [&_.prompt-area-editor]:overflow-x-hidden", + "w-full border-0 bg-transparent p-0 shadow-none [&_.prompt-area-editor]:overflow-x-hidden", + touchTyping + ? "text-(length:--text-composer-touch)/(--text-composer-touch--line-height)" + : "text-(length:--text-conversation)/(--text-conversation--line-height)", editorClassName, ); @@ -2047,7 +2052,11 @@ export function Composer({ className={inputClassName} disabled={disabled} maxHeight={COMPACT_MAX_HEIGHT_PX} - minHeight={COMPACT_MIN_HEIGHT_PX} + minHeight={ + touchTyping + ? COMPACT_TOUCH_MIN_HEIGHT_PX + : COMPACT_MIN_HEIGHT_PX + } onChange={handleChange} onImagePaste={canAttach ? stagePastedImage : undefined} onKeyDown={handleEditorKeyDown} diff --git a/app/src/theme.css b/app/src/theme.css index d000e947ca..2b5f87dfa7 100644 --- a/app/src/theme.css +++ b/app/src/theme.css @@ -152,9 +152,9 @@ body { --text-base: 0.9375rem; /* 15px */ --text-conversation: 0.9375rem; /* 15px */ --text-conversation--line-height: 1.5; - /* The message box stays at 16px: iPhone Safari zooms the page into a field set any smaller. */ - --text-composer: 1rem; /* 16px */ - --text-composer--line-height: 1.5; + /* The message box on a touch screen: iPhone Safari zooms the page into a field under 16px. */ + --text-composer-touch: 1rem; /* 16px */ + --text-composer-touch--line-height: 1.5; --text-lg: 1.0546875rem; /* 16.875px */ --text-xl: 1.171875rem; /* 18.75px */ --text-2xl: 1.40625rem; /* 22.5px */ diff --git a/app/tests/composer-dictation-notice-layout.test.tsx b/app/tests/composer-dictation-notice-layout.test.tsx index 7a4c3b524c..4e055e6a9c 100644 --- a/app/tests/composer-dictation-notice-layout.test.tsx +++ b/app/tests/composer-dictation-notice-layout.test.tsx @@ -32,6 +32,8 @@ const NOTICE = /** The desktop app's dictation runs on macOS and Windows; Chromium on Linux CI says it is a Mac. */ const MAC = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36"; +const IPHONE = + "Mozilla/5.0 (iPhone; CPU iPhone OS 18_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.0 Mobile/15E148 Safari/604.1"; async function bundle(): Promise { const built = await Bun.build({ @@ -122,11 +124,19 @@ async function open( layout: "home" | "thread", theme: "light" | "dark", chips = false, + /** A phone: a finger is the only pointer. */ + touch = false, ) { - const page = await browser.newPage({ - viewport: { width: 1000, height: 760 }, - userAgent: MAC, - }); + const page = await browser.newPage( + touch + ? { + viewport: { width: 390, height: 760 }, + userAgent: IPHONE, + hasTouch: true, + isMobile: true, + } + : { viewport: { width: 1000, height: 760 }, userAgent: MAC }, + ); page.on("pageerror", (error) => console.error(error)); await page.route(`${ORIGIN}/**`, (route) => { const path = new URL(route.request().url()).pathname; @@ -256,6 +266,25 @@ describe.skipIf(!asked)("the microphone's notice", () => { }, 60_000); }); +describe.skipIf(!asked)("composer text on a phone", () => { + // iPhone Safari zooms the page into a field set under 16px, so a touch screen gets 16px. + for (const layout of ["thread", "home"] as const) { + test(`${layout}: the message box is 16px`, async () => { + const page = await open(layout, "light", false, true); + try { + const editor = page.getByRole("textbox", { name: "Message" }); + const set = await editor.evaluate((element) => { + const style = getComputedStyle(element); + return { font: style.fontSize, line: style.lineHeight }; + }); + expect(set).toEqual({ font: "16px", line: "24px" }); + } finally { + await page.close(); + } + }, 60_000); + } +}); + describe.skipIf(!asked)("composer text at zoom", () => { for (const layout of ["thread", "home"] as const) { test(`${layout}: drafts wrap and scroll vertically`, async () => { @@ -279,10 +308,10 @@ describe.skipIf(!asked)("composer text at zoom", () => { }; }); expect(wrapped.overflowX).toBe("hidden"); - expect(wrapped.font).toBe("16px"); - expect(wrapped.line).toBe("24px"); + expect(wrapped.font).toBe("15px"); + expect(wrapped.line).toBe("22.5px"); expect(wrapped.overflowWidth).toBeLessThanOrEqual(1); - expect(wrapped.height).toBeGreaterThan(48); + expect(wrapped.height).toBeGreaterThan(45); await editor.fill("A line in a long draft.\n".repeat(40)); expect( From 6f7afc9aec2f0dbe12919406ab66a36f45b7b998 Mon Sep 17 00:00:00 2001 From: Sam Julien Date: Tue, 1 Dec 2026 17:59:10 -0800 Subject: [PATCH 10/12] Reading a conversation: fold a long message, show a table's buttons on hover - A person's message longer than about ten lines folds to its first eight, with a Show more / Show less button (aria-expanded, aria-controls). The text is clipped, not removed (max-h 8lh), so a screen reader, Copy and the browser's find still reach it; a scroll of the folded box, which is how find shows a match there, unfolds it. Measured by height, again when the width changes. - Copy, Download and Full screen above a table in a reply fade in on hover or focus within the table, and stay shown where there is no hover. Their row keeps its room, so nothing moves. No size or spacing from the typeset change is touched. --- CHANGELOG.md | 5 + .../components/channels/chat-transcript.tsx | 50 +++-- .../components/channels/folded-message.tsx | 105 +++++++++ app/src/lib/markdown-table.tsx | 17 +- app/tests/conversation-reading.test.tsx | 199 ++++++++++++++++++ 5 files changed, 351 insertions(+), 25 deletions(-) create mode 100644 app/src/components/channels/folded-message.tsx create mode 100644 app/tests/conversation-reading.test.tsx diff --git a/CHANGELOG.md b/CHANGELOG.md index c434ae006c..768e8fcb72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -68,6 +68,11 @@ Newest first. `Unreleased` is what is on `main` and not yet tagged. rest of the work once the answer is in. Each firing of a routine keeps a plan of its own, and answering a question the Bot asks mid-way carries the same plan on. An app from before this release shows the plan's calls as ordinary steps. +- **A long message folds, and a table's buttons wait for the pointer.** A message of yours longer + than about ten lines shows its first eight, with Show more and Show less, so a pasted prompt no + longer pushes the answer off the screen. Copy and find still reach all of it. Copy, Download and + Full screen above a table in a reply show when you point at the table or tab into it, and always + on a touch screen. - **A long conversation opens at its newest message.** Opened again, it could show its history partway up, with the scroll-to-end button showing, when its newest turn arrived a moment after the rest: a read of its history a moment behind, or a turn asked from another device while it was diff --git a/app/src/components/channels/chat-transcript.tsx b/app/src/components/channels/chat-transcript.tsx index 9d699da9da..c8a85fdaf0 100644 --- a/app/src/components/channels/chat-transcript.tsx +++ b/app/src/components/channels/chat-transcript.tsx @@ -186,6 +186,7 @@ import { splitChatOrigin } from "./chat-origin"; import type { QueuedMessage } from "./composer"; import { transcriptColumn } from "./conversation-columns"; import { FileTypeIcon } from "./file-icon"; +import { FoldedMessage } from "./folded-message"; import { FollowScroll, RESUME_PX, useFollowIntent } from "./follow-intent"; import { LateRenderersContext, LateRenderersWatch } from "./late-renderers"; import { usePacedReveal } from "./paced-reveal"; @@ -1257,30 +1258,33 @@ const TranscriptMessage = memo(function TranscriptMessage({ // emphasis. The chip is the one exception, and it is not reformatting: it is drawing // the thing that was already a chip in the composer as a chip here too, so the // transcript shows a skill was used rather than a slash that was typed. - - {origin && ( - - via {origin.via} - - )} - {invoked ? ( - <> - {/* - * The same icon the sidebar uses for Skills, so the badge says WHAT KIND of - * thing was invoked before it says which one. `inline-flex` with - * `align-middle` rather than a block: this sits mid-sentence, and a badge that - * breaks the line it is in reads as a separate message. - */} - - - {invoked.chip} + // A long one folds to its first lines (see `FoldedMessage`). + + + {origin && ( + + via {origin.via} - {invoked.rest} - - ) : ( - said - )} - + )} + {invoked ? ( + <> + {/* + * The same icon the sidebar uses for Skills, so the badge says WHAT KIND of + * thing was invoked before it says which one. `inline-flex` with + * `align-middle` rather than a block: this sits mid-sentence, and a badge that + * breaks the line it is in reads as a separate message. + */} + + + {invoked.chip} + + {invoked.rest} + + ) : ( + said + )} + + ) : ( /* * A Bot's prose is markdown, and it arrives in pieces. diff --git a/app/src/components/channels/folded-message.tsx b/app/src/components/channels/folded-message.tsx new file mode 100644 index 0000000000..98c11cb5f9 --- /dev/null +++ b/app/src/components/channels/folded-message.tsx @@ -0,0 +1,105 @@ +import { + type ReactNode, + useId, + useLayoutEffect, + useRef, + useState, +} from "react"; +import { Button } from "@/components/ui/button"; +import { cn } from "@/lib/utils"; + +/** How many lines of a long message show while it is folded. */ +export const FOLD_LINES = 8; + +/** + * How many lines more than `FOLD_LINES` a message needs before it folds. A message one line too long + * would fold to hide that one line, and "Show more" would cost more room than it saves. + */ +export const FOLD_SLACK_LINES = 2; + +/** Used when the browser gives no line height to measure with, as in a test's DOM. */ +const FALLBACK_LINE_HEIGHT = 24; + +/** + * A person's message, folded to its first lines when it is long, with Show more and Show less. + * + * A pasted prompt of forty lines pushed the Bot's answer below the screen, and the person scrolled + * past their own words to read it every time. Claude and ChatGPT fold a long message the same way. + * + * WHAT IS LONG is measured, not counted: lines are what the screen draws, so a message is long by its + * height at the width it has, and is measured again when that width changes. The text is all there + * while folded, only clipped (`max-h-[8lh]`, eight of its own lines), so a screen reader reads it + * all, Copy copies it all, and the browser's find reaches it: find scrolls the clipped box to show a + * match, and a scroll of a folded box unfolds it. The button is a real button and says, with + * `aria-expanded`, which way it went. + */ +export function FoldedMessage({ children }: { children: ReactNode }) { + const id = useId(); + const body = useRef(null); + const toggle = useRef(null); + const [long, setLong] = useState(false); + const [open, setOpen] = useState(false); + + // Before paint, so a long message never shows whole for a frame and then jumps. + useLayoutEffect(() => { + const element = body.current; + if (!element) return; + const measure = () => { + const line = Number.parseFloat(getComputedStyle(element).lineHeight); + const lineHeight = line > 0 ? line : FALLBACK_LINE_HEIGHT; + // The whole text's height, folded or not: clipping leaves `scrollHeight` alone. + setLong( + element.scrollHeight > lineHeight * (FOLD_LINES + FOLD_SLACK_LINES), + ); + }; + measure(); + if (typeof ResizeObserver === "undefined") return; + const observer = new ResizeObserver(measure); + observer.observe(element); + return () => observer.disconnect(); + }, []); + + const folded = long && !open; + + return ( + <> +
{ + // The browser's find scrolled the clipped text to a match: show the whole message. + if (!folded) return; + event.currentTarget.scrollTop = 0; + setOpen(true); + }} + ref={body} + > + {children} +
+ {long ? ( + + ) : null} + + ); +} diff --git a/app/src/lib/markdown-table.tsx b/app/src/lib/markdown-table.tsx index 64f98d00d5..2b6b21b8b3 100644 --- a/app/src/lib/markdown-table.tsx +++ b/app/src/lib/markdown-table.tsx @@ -241,6 +241,16 @@ const MENU_ITEM = */ const CELLS_AT_TOP = "[&_td]:align-top"; +/* + * The second change: Copy, Download and Full screen show while the pointer is on the table or focus + * is in it, as a reply's own Copy shows on hover, so a reply with three tables isn't nine icons at + * rest. Where there is no hover (a touch screen), they always show. They fade rather than leave, so + * their row keeps its room and the table doesn't move when they appear, and they stay in the tab + * order: focus on one shows them all. An open menu keeps focus inside, so it keeps them shown. + */ +const ACTIONS_ON_HOVER = + "transition-opacity focus-within:opacity-100 motion-reduce:transition-none [@media(hover:hover)]:opacity-0 [@media(hover:hover)]:group-hover/table:opacity-100"; + function Icon({ d, ...props }: SVGProps & { d: string }) { return ( {showCopy || showDownload || showFullscreen ? (
{showCopy ? : null} diff --git a/app/tests/conversation-reading.test.tsx b/app/tests/conversation-reading.test.tsx new file mode 100644 index 0000000000..29044449b2 --- /dev/null +++ b/app/tests/conversation-reading.test.tsx @@ -0,0 +1,199 @@ +import { + afterAll, + afterEach, + beforeAll, + beforeEach, + expect, + test, +} from "bun:test"; +import type { Message } from "@ag-ui/core"; +import { GlobalRegistrator } from "@happy-dom/global-registrator"; +import { + cleanup, + fireEvent, + render, + waitFor, + within, +} from "@testing-library/react"; +import { ChatTranscript } from "@/components/channels/chat-transcript"; +import { + FOLD_LINES, + FOLD_SLACK_LINES, + FoldedMessage, +} from "@/components/channels/folded-message"; +import { settleReactWork } from "./settle-react-work"; + +/** + * READING A CONVERSATION: a long message folds, and a table's buttons wait for the pointer. + * + * 1. A person's long message, a pasted prompt, was shown whole and pushed the Bot's answer below the + * screen. It now folds to its first eight lines, with a Show more / Show less button that says + * with `aria-expanded` which way it went. The whole text stays in the page while folded, so a + * screen reader, Copy and the browser's find still reach it. + * 2. Copy, Download and Full screen sat above every table in a reply at rest. They now show while + * the pointer is on the table or focus is in it, and always where there is no hover. + * + * The test DOM draws nothing, so a message's height is set here (`scrollHeight`), as a browser would + * measure it with no line height to read: 24px a line (`FALLBACK_LINE_HEIGHT`). + */ + +const LINE = 24; +let height = 0; +let scrollHeight: PropertyDescriptor | undefined; + +beforeAll(() => { + GlobalRegistrator.register({ url: "http://localhost/" }); + scrollHeight = Object.getOwnPropertyDescriptor( + HTMLElement.prototype, + "scrollHeight", + ); + Object.defineProperty(HTMLElement.prototype, "scrollHeight", { + configurable: true, + get() { + return (this as HTMLElement).dataset.slot === "folded-message" + ? height + : 0; + }, + }); + Object.defineProperty(navigator, "clipboard", { + configurable: true, + value: { writeText: async () => {}, write: async () => {} }, + }); +}); +beforeEach(() => { + height = 0; +}); +afterEach(cleanup); +afterAll(async () => { + await settleReactWork(); + if (scrollHeight) + Object.defineProperty(HTMLElement.prototype, "scrollHeight", scrollHeight); + GlobalRegistrator.unregister(); +}); + +function folded(view: ReturnType) { + const body = view.container.querySelector('[data-slot="folded-message"]'); + if (!body) throw new Error("No folded-message body"); + return body as HTMLElement; +} + +test("a long message folds to its first lines, and Show more and Show less unfold and fold it", () => { + height = LINE * 40; + const view = render( + Forty lines of a pasted prompt, + ); + const body = folded(view); + const more = view.getByRole("button", { name: "Show more" }); + expect(more.getAttribute("aria-expanded")).toBe("false"); + expect(more.getAttribute("aria-controls")).toBe(body.id); + expect(body.hasAttribute("data-folded")).toBe(true); + expect(body.className).toContain("max-h-[8lh]"); + expect(body.className).toContain("overflow-hidden"); + // Clipped, not removed: a screen reader and find still have every word. + expect(body.textContent).toBe("Forty lines of a pasted prompt"); + + fireEvent.click(more); + const less = view.getByRole("button", { name: "Show less" }); + expect(less).toBe(more); + expect(less.getAttribute("aria-expanded")).toBe("true"); + expect(body.hasAttribute("data-folded")).toBe(false); + expect(body.className).not.toContain("max-h-[8lh]"); + + fireEvent.click(less); + expect( + view + .getByRole("button", { name: "Show more" }) + .getAttribute("aria-expanded"), + ).toBe("false"); + expect(body.hasAttribute("data-folded")).toBe(true); +}); + +test("a message only a line or two past the fold is shown whole, with no button", () => { + height = LINE * (FOLD_LINES + FOLD_SLACK_LINES); + const view = render(Ten lines); + expect(view.queryByRole("button")).toBeNull(); + expect(folded(view).hasAttribute("data-folded")).toBe(false); + cleanup(); + height = LINE * 3; + const short = render(Three lines); + expect(short.queryByRole("button")).toBeNull(); +}); + +test("find scrolling the folded text to a match unfolds the message", () => { + height = LINE * 40; + const view = render(Confluence is on line 30); + const body = folded(view); + body.scrollTop = 200; + fireEvent.scroll(body); + expect(body.hasAttribute("data-folded")).toBe(false); + expect( + view + .getByRole("button", { name: "Show less" }) + .getAttribute("aria-expanded"), + ).toBe("true"); +}); + +test("in a conversation, the person's long message folds and the Bot's reply does not", async () => { + height = LINE * 40; + const prompt = Array.from({ length: 40 }, (_, i) => `Line ${i + 1}`).join( + "\n", + ); + const messages: Message[] = [ + { id: "u1", role: "user", content: prompt }, + { id: "a1", role: "assistant", content: "Here is the answer." }, + ]; + const view = render(); + await view.findByText("Here is the answer."); + const bodies = view.container.querySelectorAll( + '[data-slot="folded-message"]', + ); + expect(bodies).toHaveLength(1); + const mine = view.container.querySelector('[data-message-id="u1"]'); + expect(mine?.contains(bodies[0] as Node)).toBe(true); + expect( + within(mine as HTMLElement).getByRole("button", { name: "Show more" }), + ).toBeTruthy(); + // Every line is still in the page, the folded ones included. + expect(bodies[0]?.textContent).toContain("Line 40"); +}); + +const TABLE_REPLY = [ + "Three options.", + "", + "| App | Price |", + "| --- | --- |", + "| Notion | $10/month |", + "| Obsidian | Free |", +].join("\n"); + +test("a table's Copy, Download and Full screen show on hover or focus, and at rest where there is no hover", async () => { + const messages: Message[] = [ + { id: "u1", role: "user", content: "Compare them." }, + { id: "a1", role: "assistant", content: TABLE_REPLY }, + ]; + const view = render(); + await waitFor(() => + expect(view.container.querySelectorAll("tbody tr")).toHaveLength(2), + ); + const wrapper = view.container.querySelector( + '[data-streamdown="table-wrapper"]', + ); + const actions = view.container.querySelector( + '[data-slot="markdown-table-actions"]', + ); + if (!wrapper || !actions) throw new Error("No table or no table actions"); + expect(wrapper.classList.contains("group/table")).toBe(true); + const names = actions.className.split(" "); + // Hidden at rest only where the device can hover, and shown by hover on the table or focus in it. + expect(names).toContain("[@media(hover:hover)]:opacity-0"); + expect(names).toContain( + "[@media(hover:hover)]:group-hover/table:opacity-100", + ); + expect(names).toContain("focus-within:opacity-100"); + // Faded, not removed: their row keeps its room and each stays a button with its name. + expect(names).not.toContain("hidden"); + for (const title of ["Copy table", "Download table", "View fullscreen"]) { + const button = within(actions as HTMLElement).getByTitle(title); + expect(button.tagName).toBe("BUTTON"); + } +}); From 69b2c579249d004b91396f4578fa5918a7c9c63c Mon Sep 17 00:00:00 2001 From: Sam Julien Date: Tue, 1 Dec 2026 18:02:26 -0800 Subject: [PATCH 11/12] Release note goes in the PR description, not CHANGELOG.md --- CHANGELOG.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 768e8fcb72..c434ae006c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -68,11 +68,6 @@ Newest first. `Unreleased` is what is on `main` and not yet tagged. rest of the work once the answer is in. Each firing of a routine keeps a plan of its own, and answering a question the Bot asks mid-way carries the same plan on. An app from before this release shows the plan's calls as ordinary steps. -- **A long message folds, and a table's buttons wait for the pointer.** A message of yours longer - than about ten lines shows its first eight, with Show more and Show less, so a pasted prompt no - longer pushes the answer off the screen. Copy and find still reach all of it. Copy, Download and - Full screen above a table in a reply show when you point at the table or tab into it, and always - on a touch screen. - **A long conversation opens at its newest message.** Opened again, it could show its history partway up, with the scroll-to-end button showing, when its newest turn arrived a moment after the rest: a read of its history a moment behind, or a turn asked from another device while it was From c16d26c23cd329f41669be8e21fc9fe0ca921688 Mon Sep 17 00:00:00 2001 From: Sam Julien Date: Tue, 1 Dec 2026 19:08:53 -0800 Subject: [PATCH 12/12] Table buttons stay shown while a menu is open; compare the table with Streamdown's with the pointer on it Safari doesn't focus a button on a click, so an open Copy or Download menu faded away with its buttons once the pointer left the table. An open menu now keeps them shown. The browser test compared the table at rest, where ours now hides its buttons on purpose. It compares with the pointer on the table, and a new test holds that the buttons are hidden at rest and shown on hover, on focus and while a menu is open, in Chromium and WebKit. --- app/src/lib/markdown-table.tsx | 12 ++++-- app/tests/conversation-reading.test.tsx | 6 +++ app/tests/table-export-browser.test.tsx | 56 ++++++++++++++++++++++++- 3 files changed, 68 insertions(+), 6 deletions(-) diff --git a/app/src/lib/markdown-table.tsx b/app/src/lib/markdown-table.tsx index 2b6b21b8b3..f974b6d146 100644 --- a/app/src/lib/markdown-table.tsx +++ b/app/src/lib/markdown-table.tsx @@ -246,10 +246,14 @@ const CELLS_AT_TOP = "[&_td]:align-top"; * is in it, as a reply's own Copy shows on hover, so a reply with three tables isn't nine icons at * rest. Where there is no hover (a touch screen), they always show. They fade rather than leave, so * their row keeps its room and the table doesn't move when they appear, and they stay in the tab - * order: focus on one shows them all. An open menu keeps focus inside, so it keeps them shown. + * order: focus on one shows them all. + * + * An open Copy or Download menu keeps them shown (`has-[[data-slot=markdown-table-menu]]`), with the + * pointer anywhere. Focus alone doesn't: Safari doesn't focus a button on a click, so there the menu + * faded away with its buttons as soon as the pointer left the table. */ const ACTIONS_ON_HOVER = - "transition-opacity focus-within:opacity-100 motion-reduce:transition-none [@media(hover:hover)]:opacity-0 [@media(hover:hover)]:group-hover/table:opacity-100"; + "transition-opacity focus-within:opacity-100 motion-reduce:transition-none [@media(hover:hover)]:opacity-0 [@media(hover:hover)]:group-hover/table:opacity-100 has-[[data-slot=markdown-table-menu]]:opacity-100"; function Icon({ d, ...props }: SVGProps & { d: string }) { return ( @@ -318,7 +322,7 @@ function CopyMenu() { {open ? ( -
+
{open ? ( -
+