Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(agents): collapse queued prompts into scrollable previews (#6955)
Wolf Mermelstein5582e4f41c52
diff --git a/apps/web/src/features/agent-changes/debug/Gallery.tsx b/apps/web/src/features/agent-changes/debug/Gallery.tsxindex 23cddf27c4..d0a0349a9c 100644--- a/apps/web/src/features/agent-changes/debug/Gallery.tsx+++ b/apps/web/src/features/agent-changes/debug/Gallery.tsx@@ -6,8 +6,9 @@*/import { SAMPLE_PATCH } from '@app/components/diff-view/debug/fixtures';+import { QueuedPrompts } from '@app/features/block-agent/ui';import { Button } from '@ui';-import { createSignal, For } from 'solid-js';+import { createSignal, For, Show } from 'solid-js';import { AgentChangesControllerProvider } from '../context/agent-changes-controller';import { createPaneViewState } from '../pane-view-state';import { createAgentChanges } from '../primitives/create-agent-changes';@@ -20,6 +21,22 @@ import {} from '../views/SessionChangesControls';import { gallerySummary } from './gallery-fixture';+const GALLERY_QUEUE = Array.from({ length: 12 }, (_, index) => ({+ actionId: `gallery-queued-${index + 1}`,+ kind: 'prompt',+ prompt:+ index === 0+ ? [+ 'Add regression coverage for queued messages and review readiness.',+ ...Array.from(+ { length: 12 },+ (_, step) =>+ `Scenario ${step + 1}: queue a follow-up while the agent is working. Verify that the next prompt stays reachable and editing a queued message preserves its attachments.`+ ),+ ].join('\n\n')+ : `Queued follow-up #${index + 1}: tighten the unread rail query.`,+}));+export default function AgentChangesGallery() {const context = createMockAgentChangesContext({summary: gallerySummary(),@@ -54,6 +71,8 @@ export default function AgentChangesGallery() {);}const [transcript, setTranscript] = createSignal<string[]>([]);+ const [queued, setQueued] = createSignal(false);+ const [queueItems, setQueueItems] = createSignal(GALLERY_QUEUE);// The mock host records prompts; surface them like a transcript would.const originalSend = context.host.agent.send;context.host.agent.send = (markdown) => {@@ -76,18 +95,32 @@ export default function AgentChangesGallery() {Gallery session. Prompts sent from the Changes pane appear below;use the button below to simulate linking a pull request.</p>- <Button- variant="outline"- size="sm"- class="self-start"- onClick={() =>- context.setPullRequestUrl(- 'https://github.com/macro-inc/macro/pull/1482'- )- }- >- Simulate the agent linking PR #1482- </Button>+ <div class="flex flex-wrap gap-2">+ <Button+ variant="outline"+ size="sm"+ class="self-start"+ onClick={() =>+ context.setPullRequestUrl(+ 'https://github.com/macro-inc/macro/pull/1482'+ )+ }+ >+ Simulate the agent linking PR #1482+ </Button>+ <Button+ variant="outline"+ size="sm"+ class="self-start"+ aria-pressed={queued()}+ onClick={() => {+ setQueueItems(GALLERY_QUEUE);+ setQueued((value) => !value);+ }}+ >+ {queued() ? 'Hide queued messages' : 'Show a long queue'}+ </Button>+ </div><For each={transcript()}>{(line) => (<pre class="rounded-lg bg-surface-1 p-3 font-mono text-xs whitespace-pre-wrap text-ink-muted">@@ -99,6 +132,25 @@ export default function AgentChangesGallery() {<div class="mx-auto flex w-full max-w-4xl shrink-0 flex-col gap-2 px-4 pb-4"><ChangesHandoff /><ReviewNotesDock />+ <Show when={queued()}>+ <QueuedPrompts+ items={queueItems()}+ onEdit={(id, prompt) =>+ setQueueItems((items) =>+ items.map((item) =>+ item.actionId === id ? { ...item, prompt } : item+ )+ )+ }+ onRemove={(id) => {+ const remaining = queueItems().filter(+ (item) => item.actionId !== id+ );+ setQueueItems(remaining);+ if (remaining.length === 0) setQueued(false);+ }}+ />+ </Show><div class="rounded-2xl border border-edge px-4 py-3 text-sm text-ink-placeholder">Message the agent, @mention anything</div>diff --git a/apps/web/src/features/block-agent/ui/QueuedPrompts.test.tsx b/apps/web/src/features/block-agent/ui/QueuedPrompts.test.tsxindex 7ad35d29cd..415192fa59 100644--- a/apps/web/src/features/block-agent/ui/QueuedPrompts.test.tsx+++ b/apps/web/src/features/block-agent/ui/QueuedPrompts.test.tsx@@ -5,7 +5,9 @@ import { QueuedPrompts } from './QueuedPrompts';const editor = vi.hoisted(() => ({change: undefined as ((markdown: string) => void) | undefined,+ escape: undefined as (() => boolean) | undefined,markdown: 'Queued request',+ focus: vi.fn(),}));vi.mock('@core/component/LexicalMarkdown/builder/MarkdownConfigBuilder',@@ -19,9 +21,13 @@ vi.mock(return builder;},onFocusLeave: () => builder,+ onEscape: (callback: () => boolean) => {+ editor.escape = callback;+ return builder;+ },lexical: { getRootElement: () => null },controls: {- focus: vi.fn(),+ focus: editor.focus,getMarkdown: () => editor.markdown,setMarkdown: vi.fn(),},@@ -55,6 +61,7 @@ vi.mock('@ui', () => ({beforeEach(() => {vi.useFakeTimers();editor.markdown = 'Queued request';+ editor.focus.mockClear();});afterEach(() => {cleanup();@@ -62,6 +69,79 @@ afterEach(() => {});describe('queued prompt access', () => {+ it('collapses every message and opens only the selected editor', () => {+ render(() => (+ <QueuedPrompts+ items={[+ {+ actionId: 'first',+ kind: 'prompt',+ prompt: 'First request\nMore detail',+ },+ { actionId: 'second', kind: 'prompt', prompt: 'Second request' },+ ]}+ onEdit={vi.fn()}+ onRemove={vi.fn()}+ />+ ));+ expect(screen.queryByRole('textbox')).toBeNull();+ const first = screen.getByRole('button', {+ name: /First request\s+More detail/,+ });+ const second = screen.getByRole('button', { name: 'Second request' });+ fireEvent.click(first);+ expect(first.getAttribute('aria-expanded')).toBe('true');+ expect(screen.getAllByRole('textbox')).toHaveLength(1);+ expect(editor.focus).toHaveBeenCalledOnce();++ fireEvent.click(second);+ expect(first.getAttribute('aria-expanded')).toBe('false');+ expect(screen.getByRole('textbox').textContent).toBe('Second request');+ fireEvent.keyDown(screen.getByRole('textbox'), { key: 'Escape' });+ expect(screen.queryByRole('textbox')).toBeNull();+ expect(document.activeElement).toBe(second);+ });++ it('opens the next prompt from composer keyboard navigation', () => {+ let focusFromBelow: (() => void) | undefined;+ render(() => (+ <QueuedPrompts+ items={[+ { actionId: 'first', kind: 'prompt', prompt: 'Next to send' },+ { actionId: 'second', kind: 'prompt', prompt: 'Newest request' },+ ]}+ onEdit={vi.fn()}+ onRemove={vi.fn()}+ registerFocusFromBelow={(focus) => (focusFromBelow = focus)}+ />+ ));+ focusFromBelow?.();+ expect(screen.getByRole('textbox').textContent).toBe('Next to send');+ expect(editor.focus).toHaveBeenCalledOnce();+ });++ it('keeps the edited preview and editor mounted when collapsed', () => {+ const onEdit = vi.fn();+ render(() => (+ <QueuedPrompts+ items={[+ { actionId: 'first', kind: 'prompt', prompt: 'Queued request' },+ ]}+ onEdit={onEdit}+ onRemove={vi.fn()}+ />+ ));+ fireEvent.click(screen.getByRole('button', { name: 'Queued request' }));+ const textbox = screen.getByRole('textbox');+ editor.markdown = 'Updated request';+ editor.change?.(editor.markdown);+ expect(editor.escape?.()).toBe(true);+ expect(onEdit).toHaveBeenCalledWith('first', 'Updated request');+ expect(screen.queryByRole('textbox')).toBeNull();+ fireEvent.click(screen.getByRole('button', { name: 'Updated request' }));+ expect(screen.getByRole('textbox')).toBe(textbox);+ });+it('shows queued text without permitting edits or removal for viewers', () => {const onEdit = vi.fn();const onRemove = vi.fn();@@ -76,6 +156,7 @@ describe('queued prompt access', () => {/>));+ fireEvent.click(screen.getByRole('button', { name: 'Queued request' }));const textbox = screen.getByRole('textbox');expect(textbox.textContent).toBe('Queued request');expect(textbox.getAttribute('aria-readonly')).toBe('true');@@ -106,6 +187,7 @@ describe('queued prompt access', () => {onRemove={vi.fn()}/>));+ fireEvent.click(screen.getByRole('button', { name: 'Queued request' }));editor.markdown = 'An unsaved edit';editor.change?.(editor.markdown);@@ -127,6 +209,7 @@ describe('queued prompt access', () => {onRemove={onRemove}/>));+ fireEvent.click(screen.getByRole('button', { name: 'Queued request' }));editor.markdown = 'An edited request';editor.change?.(editor.markdown);vi.advanceTimersByTime(400);diff --git a/apps/web/src/features/block-agent/ui/QueuedPrompts.tsx b/apps/web/src/features/block-agent/ui/QueuedPrompts.tsxindex ac7254b7c4..3b61bbb93e 100644--- a/apps/web/src/features/block-agent/ui/QueuedPrompts.tsx+++ b/apps/web/src/features/block-agent/ui/QueuedPrompts.tsx@@ -6,19 +6,23 @@* the bottom, immediately above the composer, so Up from the input lands on* "the one about to be sent" and further Up presses walk toward the newest.*- * Each prompt row is a live Lexical surface, always editable in place —- * edits debounce and autosave through `onEdit`, with a flush on blur; there+ * Rows start as one-line previews. Opening a prompt reveals its scrollable+ * Lexical editor; only one row is expanded at a time.+ * Edits debounce and autosave through `onEdit`, with a flush on blur; there* are no save/cancel affordances. Non-prompt entries (compact) are* read-only text but keep their remove affordance, which is always visible.*/import { buildConfig } from '@core/component/LexicalMarkdown/builder/MarkdownConfigBuilder';import { MarkdownShell } from '@core/component/LexicalMarkdown/builder/MarkdownShell';+import CaretUpIcon from '@phosphor-icons/core/regular/caret-up.svg?component-solid';import XIcon from '@phosphor-icons/core/regular/x.svg?component-solid';import { Button, Surface } from '@ui';import {createEffect,createMemo,+ createSignal,+ createUniqueId,For,onCleanup,onMount,@@ -61,6 +65,7 @@ export interface QueuedPromptsProps {const AUTOSAVE_DEBOUNCE_MS = 400;export function QueuedPrompts(props: QueuedPromptsProps) {+ const [expandedId, setExpandedId] = createSignal<string>();// Reversed for render: newest at the top, next-to-dispatch at the bottom.// `For` keys on the id strings, so a snapshot that only re-orders or edits// never remounts a row (and never drops an editor mid-keystroke).@@ -93,34 +98,49 @@ export function QueuedPrompts(props: QueuedPromptsProps) {onCleanup(() => props.registerFocusFromBelow?.(undefined));});+ // A long queue scrolls within a capped height rather than pushing the+ // transcript away. `flex-col-reverse` around the single list anchors the+ // scroll at the bottom, so the next-to-dispatch row stays in view, without+ // reordering the DOM (focus order still runs newest to next).return (- <div class="flex flex-col gap-1" data-testid="agent-queued-prompts">- <For each={orderedIds()}>- {(id) => (- <Show when={itemById(id)}>- {(item) => (- <QueuedRow- item={item()}- disabled={props.disabled}- registerFocus={(focus) => {- if (focus) focusFns.set(id, focus);- else focusFns.delete(id);- }}- onMoveUp={() => moveFocus(id, -1)}- onMoveDown={() => moveFocus(id, 1)}- onEdit={(prompt) => props.onEdit(id, prompt)}- onRemove={() => props.onRemove(id)}- />- )}- </Show>- )}- </For>+ <div class="flex max-h-[min(40vh,24rem)] flex-col-reverse overflow-y-auto overscroll-contain">+ <div+ class="flex shrink-0 flex-col gap-1"+ data-testid="agent-queued-prompts"+ >+ <For each={orderedIds()}>+ {(id) => (+ <Show when={itemById(id)}>+ {(item) => (+ <QueuedRow+ item={item()}+ disabled={props.disabled}+ expanded={expandedId() === id}+ onExpandedChange={(expanded) =>+ setExpandedId(expanded ? id : undefined)+ }+ registerFocus={(focus) => {+ if (focus) focusFns.set(id, focus);+ else focusFns.delete(id);+ }}+ onMoveUp={() => moveFocus(id, -1)}+ onMoveDown={() => moveFocus(id, 1)}+ onEdit={(prompt) => props.onEdit(id, prompt)}+ onRemove={() => props.onRemove(id)}+ />+ )}+ </Show>+ )}+ </For>+ </div></div>);}type QueuedRowProps = {item: QueuedPromptItem;+ expanded: boolean;+ onExpandedChange: (expanded: boolean) => void;disabled?: boolean;/** Ref-style: how navigation focuses this row; `undefined` on unmount. */registerFocus: (focus: (() => void) | undefined) => void;@@ -131,48 +151,115 @@ type QueuedRowProps = {};function QueuedRow(props: QueuedRowProps) {+ const editorId = createUniqueId();+ const [draft, setDraft] = createSignal<string>();+ let toggle: HTMLButtonElement | undefined;+ let focusBody: (() => void) | undefined;+ const preview = () =>+ props.item.kind === 'prompt'+ ? (draft() ?? props.item.prompt ?? '').trim() || 'Attached files'+ : 'Compact the conversation';+ const open = () => {+ props.onExpandedChange(true);+ focusBody?.();+ };+ const close = () => {+ // Moving focus flushes the editor's pending autosave before hiding it.+ toggle?.focus();+ props.onExpandedChange(false);+ };+onMount(() => {+ props.registerFocus(open);onCleanup(() => props.registerFocus(undefined));});return (- <Surface class="rounded-lg" depth={1} solid>- <div class="flex items-start gap-2 px-3 py-1.5">- <div class="min-w-0 flex-1">- <Show- when={props.item.kind === 'prompt'}- fallback={<CompactBody {...props} />}+ <Surface class="h-auto shrink-0 rounded-lg" depth={1} solid>+ <div+ onKeyDown={(event) => {+ if (event.key === 'Escape' && !event.defaultPrevented) {+ event.preventDefault();+ event.stopPropagation();+ close();+ }+ }}+ >+ <div class="flex items-center gap-2 px-3 py-1">+ <button+ ref={toggle}+ type="button"+ class="flex min-w-0 flex-1 items-center gap-2 rounded-xs py-1 text-left text-sm text-ink outline-none focus-visible:ring-1 focus-visible:ring-accent"+ aria-expanded={props.expanded}+ aria-controls={editorId}+ title={+ props.expanded+ ? 'Collapse queued message'+ : 'Expand queued message'+ }+ onClick={() => (props.expanded ? close() : open())}>- <PromptBody {...props} />- </Show>- <div class="text-xs text-ink-extra-muted">+ <CaretUpIcon+ class="size-3 shrink-0 text-ink-muted transition-transform"+ classList={{ 'rotate-180': props.expanded }}+ />+ <span class="truncate">{preview()}</span>+ </button>+ <span class="shrink-0 text-xs text-ink-extra-muted">Queued<Show when={props.item.queuedBy}>{(name) => <> by {name()}</>}</Show>- </div>+ </span>+ <Button+ variant="ghost"+ size="icon-sm"+ label="Remove queued message"+ disabled={props.disabled}+ onClick={() => props.onRemove()}+ class="shrink-0"+ >+ <XIcon class="size-3.5" />+ </Button></div>- <Button- variant="ghost"- size="icon-sm"- label="Remove queued message"- disabled={props.disabled}- onClick={() => props.onRemove()}- class="shrink-0"+ <div+ id={editorId}+ class="max-h-[min(32vh,16rem)] overflow-y-auto overscroll-contain border-t border-edge-muted px-3 py-2"+ hidden={!props.expanded}>- <XIcon class="size-3.5" />- </Button>+ <Show+ when={props.item.kind === 'prompt'}+ fallback={+ <CompactBody+ {...props}+ registerFocus={(focus) => (focusBody = focus)}+ />+ }+ >+ <PromptBody+ {...props}+ registerFocus={(focus) => (focusBody = focus)}+ onDraftChange={setDraft}+ onCollapse={close}+ />+ </Show>+ </div></div></Surface>);}/**- * The always-editable body of a prompt row: the same Lexical markdown+ * The editable body of an expanded prompt row: the same Lexical markdown* surface as the composer's input, minus its send machinery. Edits debounce* into `onEdit` and flush when focus leaves the row.*/-function PromptBody(props: QueuedRowProps) {+function PromptBody(+ props: QueuedRowProps & {+ onDraftChange: (text: string) => void;+ onCollapse: () => void;+ }+) {// The last text this row and the server agree on: what was mounted,// applied from a server snapshot, or handed to `onEdit`. Both the autosave// and the anti-clobber check compare against it.@@ -195,6 +282,7 @@ function PromptBody(props: QueuedRowProps) {const scheduleSave = (markdown: string) => {if (props.disabled) return;+ props.onDraftChange(markdown);if (markdown === synced) return;if (saveTimer !== undefined) clearTimeout(saveTimer);saveTimer = setTimeout(flush, AUTOSAVE_DEBOUNCE_MS);@@ -204,6 +292,11 @@ function PromptBody(props: QueuedRowProps) {.namespace('agent-queued-prompt').withHistory({ timeGap: 400 }).onChange(scheduleSave)+ .onEscape(() => {+ flush();+ props.onCollapse();+ return true;+ }).onFocusLeave({onStart: (event) => {event.preventDefault();@@ -237,6 +330,7 @@ function PromptBody(props: QueuedRowProps) {saveTimer !== undefined || editor.controls.getMarkdown() !== synced;if (focused || dirty) return;editor.controls.setMarkdown(server);+ props.onDraftChange(server);synced = server;});diff --git a/docs/AGENT_GUIDE/ai-chat.md b/docs/AGENT_GUIDE/ai-chat.mdindex 8afaf90fcd..af1860ca91 100644--- a/docs/AGENT_GUIDE/ai-chat.md+++ b/docs/AGENT_GUIDE/ai-chat.md@@ -554,7 +554,7 @@ video previews that open the same lightbox as channel media; file chips thatopen the file). A prompt may be files only, including thefirst message in a new conversation. Uploading attachments survive switching theagent or opening repository settings; sending clears the attachment previews.-Queued prompts+Expanded queued promptslist their attached file names under the text; editing a queued prompt keeps them.Cursor walkthrough files the run re-hosts appear in the transcript after the@@ -855,9 +855,17 @@ must stay hidden; subsequent live messages must still appear.harness restart — they must not disappear if the managing replica drains.- Queued prompts render as a list between the transcript and the input, newest at thetop — the prompt about to be sent sits at the bottom, immediately above the input.- Each row shows a `Queued` label (with `by {user}` when someone else queued it —+ The list is capped at the smaller of 40% of the viewport height and 24rem. Past that+ it scrolls on its own and starts scrolled to the bottom, so the next-to-send row stays+ visible. Scroll up inside the list to reach newer entries; no extra count row hides+ messages. Each prompt starts as a single-line preview, including long messages.+ Click a preview (or press Enter/Space on it) to open its editor; opening another+ row collapses the previous one. The expanded editor scrolls within the smaller of+ 32% of the viewport and 16rem. Click the preview again or press Escape to collapse+ it, retaining edits and editor state. Each row shows a `Queued` label (with `by+ {user}` when someone else queued it —several users can stack prompts in one session's queue) and an always-visible remove- (`X`) button. A queued prompt's text is itself an editor: click in and type — changes+ (`X`) button. Type in the expanded editor — changesautosave (debounced, and on blur) with no save button. Editing and removal arepossible only until the entry dispatches; after that the row simply becomes the nextuser message in the transcript.