From 1ea50d2628bf407805aedd42d15697785e7a5595 Mon Sep 17 00:00:00 2001 From: Guido Vizoso Date: Tue, 1 Dec 2026 14:28:26 -0300 Subject: [PATCH 01/11] 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/11] 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/11] 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/11] 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/11] 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/11] 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/11] 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/11] 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/11] 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 5f7df6fc67511aa45ea2587a0d1b164bbeba5ff3 Mon Sep 17 00:00:00 2001 From: Sam Julien Date: Tue, 1 Dec 2026 18:02:48 -0800 Subject: [PATCH 10/11] Home and message box: greet by first name, one-line box, model by name - Home greets the person by first name, at a lighter weight on the same title step: "Hi Sam, what would you like to work on?" the first time, "Welcome back, Sam" after. With no saved name: "What would you like to work on?". The first name is the first word of the saved name. - In a conversation the message box is one row: Attach, the words, then the model, the microphone and Send. Empty it is one line tall (about 50px, was 111px) and the words grow upward as they wrap. Every control keeps its name and its place in the tab order. - The model picker in the message box shows the model's name next to the chevron, cut short when long. The thinking setting stays in the name a screen reader hears and in the tooltip. --- .../components/channels/composer/composer.tsx | 110 +++++++++--------- .../channels/composer/model-picker.tsx | 18 ++- app/src/lib/auth/greeting.ts | 30 ++++- app/src/routes/_authed/_app/index.tsx | 3 +- app/tests/composer-one-row.test.tsx | 62 ++++++++++ app/tests/first-conversation-greeting.test.ts | 21 +++- app/tests/home-holds-still.test.tsx | 6 +- app/tests/model-picker.test.tsx | 11 +- 8 files changed, 179 insertions(+), 82 deletions(-) create mode 100644 app/tests/composer-one-row.test.tsx diff --git a/app/src/components/channels/composer/composer.tsx b/app/src/components/channels/composer/composer.tsx index 9a2e62163c..6e7161b594 100644 --- a/app/src/components/channels/composer/composer.tsx +++ b/app/src/components/channels/composer/composer.tsx @@ -159,14 +159,9 @@ function stagedMimeType(attachment: Attachment): string { const MAX_HEIGHT_PX = 220; /** - * 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 = 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. + * One 24px line: a one-line box opens at this height, the compact composer's included, and grows + * as the words wrap. Given to PromptArea itself, whose own minimum (80px) is an inline style no + * class can beat. */ const ONE_LINE_HEIGHT_PX = 24; const COMPACT_MAX_HEIGHT_PX = 160; @@ -344,7 +339,7 @@ export type ComposerProps = { spinsWhileSending?: boolean; /** * True draws the words and the controls in one row, so the empty box is one line tall and grows - * as the words wrap (Routines). Only the full-size box has it; a compact box keeps its two rows. + * as the words wrap (Routines). A compact box is always one row. */ oneLine?: boolean; }; @@ -2025,10 +2020,10 @@ export function Composer({ * internally at COMPACT_MAX_HEIGHT_PX: padding inside that box would scroll away with * the text, so the first visible line would touch the top edge on a long message. * - * A column: the attachment strip across the top, the message box under it, and the - * controls row at the bottom. + * A column: the attachment strip across the top, then one row of the controls and the + * words between them. */ - "flex flex-col px-3 py-3", + "flex flex-col p-2", MESSAGE_BOX_FRAME, className, )} @@ -2042,54 +2037,55 @@ export function Composer({ onRemove={discardAttachment} /> {/* - * TWO ROWS: the message box across the full width, then the controls under it. Attach - * and the model on the left, the microphone and send on the right, so the controls - * keep their place however long the message grows. + * ONE ROW: Attach on the left, the words in the middle, the model, the microphone and + * Send on the right. Empty, the box is one line tall, as tall as its buttons. The words + * grow upward as they wrap, and the controls stay on the bottom line, where they were. */} -
- -
-
-
- {attachmentsEnabled ? ( - - ) : null} - {/* No attachments and nothing else behind a plus, so no plus: a disabled one that - explained nothing read as broken. */} - {modelPicker} +
+ {attachmentsEnabled ? ( + + ) : null} + {/* No attachments and nothing else behind a plus, so no plus: a disabled one that + explained nothing read as broken. */} + {/* The 4px above and below a 24px line make it as tall as the 32px buttons beside it. */} +
+
+ {modelPicker} {dictates ? ( - ) : ( + ) : showValue ? ( - )} - {showValue ? ( - - {shown} - ) : null} + {/* In the message box, the model by its name, cut short when long: a chip icon + alone didn't say which model the next message goes to. The thinking setting is + in the name a screen reader hears and in the tooltip. */} + + {showValue ? shown : (selected?.label ?? "Model")} + } diff --git a/app/src/lib/auth/greeting.ts b/app/src/lib/auth/greeting.ts index e0ae2d2e52..58976555b1 100644 --- a/app/src/lib/auth/greeting.ts +++ b/app/src/lib/auth/greeting.ts @@ -1,12 +1,32 @@ import type { AuthenticatedUser } from "./queries"; -/** Keep the welcome out of message history, and never guess a first name. */ +/** + * The first word of the name the person saved: "Sam Julien" is greeted as Sam. Undefined when there + * is no name to go by (none saved, one still to be asked for, or the email standing in for it): + * a first name is never guessed from an email. + */ +export function firstName( + user: AuthenticatedUser | null | undefined, +): string | undefined { + const name = user?.name?.trim(); + if (!name || user?.needsName || name === user?.email) return undefined; + return name.split(/\s+/)[0]; +} + +/** What Home says when nobody's name is known. */ +const NO_NAME = "What would you like to work on?"; + +/** + * Home's heading: the person by their first name, asked what to work on the first time, welcomed + * back after that. Kept out of message history. + */ export function firstConversationGreeting( user: AuthenticatedUser | null | undefined, noConversations: boolean, ): string { - const name = user?.name?.trim(); - if (!noConversations || !name || user?.needsName || name === user?.email) - return "Start a conversation"; - return `Hi ${name}, what would you like to work on?`; + const name = firstName(user); + if (!name) return NO_NAME; + return noConversations + ? `Hi ${name}, what would you like to work on?` + : `Welcome back, ${name}`; } diff --git a/app/src/routes/_authed/_app/index.tsx b/app/src/routes/_authed/_app/index.tsx index b436993609..3612dd72e6 100644 --- a/app/src/routes/_authed/_app/index.tsx +++ b/app/src/routes/_authed/_app/index.tsx @@ -101,7 +101,8 @@ function Greeting() { // not yet shown. if (greeting === undefined && (!channels.isPending || waited)) setGreeting(choose()); - const heading = "text-2xl font-semibold tracking-tight text-center"; + // The title step, at a lighter weight than a page title: a greeting, not a heading to scan. + const heading = "text-2xl font-medium tracking-tight text-center"; if (!waits) return

{greeting}

; const could = [ ...new Set([ diff --git a/app/tests/composer-one-row.test.tsx b/app/tests/composer-one-row.test.tsx new file mode 100644 index 0000000000..983596f570 --- /dev/null +++ b/app/tests/composer-one-row.test.tsx @@ -0,0 +1,62 @@ +import { afterAll, afterEach, beforeAll, expect, test } from "bun:test"; +import { GlobalRegistrator } from "@happy-dom/global-registrator"; +import { cleanup, render } from "@testing-library/react"; +import { Composer } from "@/components/channels/composer/composer"; +import { settleReactWork } from "./settle-react-work"; + +/** + * The message box in a conversation (the compact composer) is one row: Attach, the words, then the + * model, the microphone and Send. Empty, it is one line tall. It was two rows, the words over the + * controls, about 114px tall before anything was typed. + * + * The harness is this repository's: see composer-attachments-ui.test.tsx. + */ +const originalFetch = global.fetch; +beforeAll(() => { + GlobalRegistrator.register({ url: "http://localhost/" }); + // Nothing here reads the server: whatever the box asks for is not found. + global.fetch = (async () => + new Response("{}", { status: 404 })) as unknown as typeof fetch; +}); +afterEach(cleanup); +afterAll(async () => { + await settleReactWork(); + global.fetch = originalFetch; + GlobalRegistrator.unregister(); +}); + +test("a conversation's box is one row: Attach, the words and Send side by side", () => { + const view = render( + Model} + onSubmit={() => {}} + />, + ); + const input = view.container.querySelector("[data-slot=composer-input]"); + const row = input?.parentElement; + expect(row?.className).toContain("flex"); + // Every control keeps its name, in the same row as the words. + const attach = view.getByRole("button", { name: "Attach a file" }); + const send = view.getByRole("button", { name: "Send message" }); + const model = view.getByRole("button", { name: "Model" }); + for (const control of [attach, send, model]) + expect(row?.contains(control)).toBe(true); + expect(view.getByRole("textbox", { name: "Message" })).toBeTruthy(); + // Attach first, the words, then the model before Send. + const order = [attach, input, model, send].map((element) => + [...(row?.querySelectorAll("*") ?? [])].indexOf(element as Element), + ); + expect(order).toEqual([...order].sort((a, b) => a - b)); +}); + +test("empty, the words take one 24px line, not two", () => { + const view = render( + {}} />, + ); + const editor = view.container.querySelector( + "[data-slot=composer-input] [style*=min-height]", + ) as HTMLElement | null; + expect(editor?.style.minHeight).toBe("24px"); +}); diff --git a/app/tests/first-conversation-greeting.test.ts b/app/tests/first-conversation-greeting.test.ts index 0c5247deaf..ae6d75df79 100644 --- a/app/tests/first-conversation-greeting.test.ts +++ b/app/tests/first-conversation-greeting.test.ts @@ -1,5 +1,5 @@ import { expect, test } from "bun:test"; -import { firstConversationGreeting } from "../src/lib/auth/greeting"; +import { firstConversationGreeting, firstName } from "../src/lib/auth/greeting"; import type { AuthenticatedUser } from "../src/lib/auth/queries"; const user: AuthenticatedUser = { @@ -10,20 +10,29 @@ const user: AuthenticatedUser = { onboarding: null, needsName: false, }; -test("greets by the saved name only with a confirmed empty conversation list", () => { +test("greets by first name: asked what to work on the first time, welcomed back after", () => { expect(firstConversationGreeting(user, true)).toBe( - "Hi Sam Julien, what would you like to work on?", + "Hi Sam, what would you like to work on?", ); - expect(firstConversationGreeting(user, false)).toBe("Start a conversation"); + expect(firstConversationGreeting(user, false)).toBe("Welcome back, Sam"); }); -test("does not greet with a missing or placeholder name", () => { +test("a first name is the first word of the saved name", () => { + expect(firstName({ ...user, name: " Ana María Ruiz " })).toBe("Ana"); + expect(firstName({ ...user, name: "Cher" })).toBe("Cher"); +}); +test("with a missing or placeholder name, a neutral line", () => { for (const value of [ undefined, null, { ...user, name: "" }, + { ...user, name: " " }, { ...user, needsName: true }, { ...user, name: user.email }, ]) { - expect(firstConversationGreeting(value, true)).toBe("Start a conversation"); + for (const first of [true, false]) + expect(firstConversationGreeting(value, first)).toBe( + "What would you like to work on?", + ); + expect(firstName(value)).toBeUndefined(); } }); diff --git a/app/tests/home-holds-still.test.tsx b/app/tests/home-holds-still.test.tsx index ef278bc020..66dee7d7e6 100644 --- a/app/tests/home-holds-still.test.tsx +++ b/app/tests/home-holds-still.test.tsx @@ -48,7 +48,7 @@ const ANSWER_AFTER_MS = 400; const ANSWERED_WITHIN_MS = 10_000; /** The person the fixture signs in, and what Home says to them before their first conversation. */ const FIRST_CONVERSATION_GREETING = - "Hi Sam Rivera, what would you like to work on?"; + "Hi Sam, what would you like to work on?"; const APP = join(import.meta.dir, ".."); const ORIGIN = "http://openbot.test"; @@ -542,7 +542,7 @@ describe.skipIf(!asked)("Home while it loads", () => { } for (const engine of engines) { - test(`a conversation list that fails leaves the plain greeting, drawn once, in ${engine}`, async () => { + test(`a conversation list that fails leaves the returning greeting, drawn once, in ${engine}`, async () => { const { page, frames } = await loaded( engine, "light", @@ -551,7 +551,7 @@ describe.skipIf(!asked)("Home while it loads", () => { { bots: false, conversations: false, conversationsFail: true }, ); try { - expect(greetingsOf(frames)).toEqual(["Start a conversation"]); + expect(greetingsOf(frames)).toEqual(["Welcome back, Sam"]); } finally { await page.close(); } diff --git a/app/tests/model-picker.test.tsx b/app/tests/model-picker.test.tsx index 384e838c4a..2f1bb3e886 100644 --- a/app/tests/model-picker.test.tsx +++ b/app/tests/model-picker.test.tsx @@ -189,7 +189,7 @@ function thinking(popup: HTMLElement) { return within(popup).queryByRole("group", { name: "Thinking" }); } -test("the trigger is a CPU icon, and names a model that takes no effort on its own", () => { +test("the trigger says the model by its name, and names a model that takes no effort on its own", () => { const { getByRole } = render( , ); const trigger = getByRole("combobox", { name: "Model: GPT-4o" }); - // No name and no maker's mark in the row: the CPU icon and a chevron, named for screen readers. - expect(trigger.textContent).toBe(""); + // The model's name and a chevron, cut short when long. No maker's mark and no chip icon. + expect(trigger.textContent).toBe("GPT-4o"); expect(trigger.querySelector("img")).toBeNull(); - expect(trigger.firstElementChild?.classList.contains("icon-cpu")).toBe(true); + expect(trigger.querySelector(".icon-cpu")).toBeNull(); + expect(trigger.querySelector("span")?.classList.contains("truncate")).toBe( + true, + ); }); /** The open popup of a picker drawn on its own. */ From acde399a75a9c11b0f798d2f6e3bcfa1e9f0fcc4 Mon Sep 17 00:00:00 2001 From: Sam Julien Date: Tue, 1 Dec 2026 19:26:01 -0800 Subject: [PATCH 11/11] Home greeting test: one line, as the formatter writes it --- app/tests/home-holds-still.test.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/tests/home-holds-still.test.tsx b/app/tests/home-holds-still.test.tsx index 66dee7d7e6..b5a83093ce 100644 --- a/app/tests/home-holds-still.test.tsx +++ b/app/tests/home-holds-still.test.tsx @@ -47,8 +47,7 @@ const ANSWER_AFTER_MS = 400; /** How long a test waits for the page to ask for both lists and have them answered. */ const ANSWERED_WITHIN_MS = 10_000; /** The person the fixture signs in, and what Home says to them before their first conversation. */ -const FIRST_CONVERSATION_GREETING = - "Hi Sam, what would you like to work on?"; +const FIRST_CONVERSATION_GREETING = "Hi Sam, what would you like to work on?"; const APP = join(import.meta.dir, ".."); const ORIGIN = "http://openbot.test";