feat(chat): collapse large pastes into cards in the composer
Links
- Linear: SUPER-2734
Summary
- A paste of 25+ lines or 4,000+ chars in the v2 chat composer becomes a card in the attachment row (first line as title, "Show in text field · N lines", ×) instead of inline text, so a long log no longer pushes the draft out of view.
- On send, each card goes to the agent as a trailing
<pasted_text lines="N">block; the transcript parses it back into the same card with a "Show text · N lines" toggle that expands a read-only mono block. - Copy message still returns the full text as typed (typed text, then each paste), never the markup.
Why / Context
Today ComposerBody's paste handler only takes files, so text goes straight into the Lexical editor (max-height 40vh) and a stack trace buries the question. UserMessageRow then renders the whole paste in the bubble, so one paste can fill the transcript.
How It Works
- Wire format (
chat-ui/utils/pastedText):appendPastedText(prompt, pastes)/parsePastedText(message). Thelines="N"count bounds each block, so a paste that itself contains</pasted_text>still round-trips. Only a well-formed run of blocks at the end of the message is parsed; anything else stays plain text. - Composer (
usePastedTexts, opt-in via a newcollapseLargePastesprop onPromptInput, set only by the chatComposer): aPASTE_COMMANDhandler at NORMAL priority (below the file handler, above the plain-text paste) turns large text into a card.UNDO_COMMAND/REDO_COMMANDhandlers run ahead ofHistoryPlugin: a card step applies only while the editor text matches what it was right after (undo) or before (redo) it, so card steps and typing undo in the order they happened. "Show in text field" inserts at the last cursor withHISTORY_PUSH_TAG, so Cmd+Z moves it back into a card. - Drafts:
onChangeemits editor text + card blocks, anddefaultValue/appendTextturn trailing blocks back into cards. That covers tab switches, failed sends, unsent prompts (prependToDraftnow merges paste-aware), and editing a queued prompt. - Transcript:
parseAttachmentTagsstrips trailing paste blocks first (so a tag inside a paste stays in it) and returnspastedTexts. Rail, prompt history and find therefore see only the typed text;UserMessageRowrenders aPastedTextBlockper paste above the bubble. The card carriesdata-source-textso a selection across it copies the paste. - Shared card:
@superset/chat-ui/PastedTextCard, used by the composer row and the sent message.
Manual QA Checklist
Verified end to end in this branch's dev app over CDP (signed in, local workspace, Claude chat):
- Real Cmd+V of a 48-line stack trace after typing a question → one card, question stays in the editor, draft in localStorage holds the block
- A 3-line paste stays inline
- Cmd+Z removes the inline paste, Cmd+Z again removes the card, Cmd+Shift+Z brings the card back
- "Show in text field" puts all 48 lines at the cursor and removes the card; Cmd+Z turns it back into a card
- Switching to another workspace and back restores the card from the draft
- Enter sends; composer and draft clear; the message item text ends with the
<pasted_text lines="48">block and the agent replied - Sent message shows card ("Show text · 48 lines") above the typed bubble; "Show text" expands a 320px scrolling mono block; "Hide text" folds it
- Copy message → system clipboard (
pbpaste) is exactly the typed text, a blank line, then the log; no markup
Not checked live: a queued prompt with a card, the failed-send restore path, light theme (unit-covered where applicable).
Testing
tsc --noEmitinapps/desktopandpackages/chat-ui(exit 0)bun test --isolateonChatSession/(270 pass),packages/chat-ui(37 pass),packages/i18n(164 pass)- New tests: threshold + wire format + parse-back (
pastedText.test.ts), undo stack (pasteUndo.test.ts), paste/undo/redo/Show in text field against a real Lexical editor withHistoryPlugin(usePastedTexts.test.tsx), transcript card + expand + Copy message + selection copy (UserMessageRow.test.tsx), tags-inside-a-paste (attachmentTags.test.ts), paste-aware draft merge (useComposerDraft.test.tsx) bun run check:i18n(exit 0); 5 new strings hand-translated in all 16 locales
Design Decisions
- New
PastedTextCardinstead ofAttachmentCard: the existingAttachmentCardis the new-workspace modal's 64px tile with no size variant, so the card follows the composer's file-card styling at a compact size (max-w-[16rem],size-6tile). - Opt-in prop: the new-workspace composer (also a
PromptInput) keeps today's behavior. - Copy order: Copy message gives typed text then pastes (the order the agent receives); a drag-selection copies in screen order (card first).
Known Limitations
- Drafts with cards live in the existing
chat-v3-draft:*localStorage key, same as an inline paste of the same size today; no new bound was added. - Prompt history (Up arrow) recalls only the typed text of a message, not its pastes.
Summary by cubic
Large pastes (25+ lines or 4,000+ chars) in the v2 chat composer now become cards in the attachment row instead of inline text, so a stack trace no longer pushes the draft out of view or fills the transcript bubble.
Each card shows the paste's first line as its title, with a "Show in text field" action and a remove button; small pastes stay inline. "Show in text field" starts the paste on its own line when the cursor is mid-line. On send, cards go to the agent as trailing <pasted_text lines="N"> blocks, with the line count bounding each block so pastes that contain the markup still round-trip. The transcript parses those blocks back into the same card, with a "Show text" toggle expanding a read-only mono view that can be copied. Copy message returns the typed text plus the pastes without any markup. Cards and typing undo and redo in the order they happened; a new edit drops the card redo, and cards restored from a draft or returned prompt survive undoing earlier steps. Drafts and unsent prompts keep their cards, and the behavior is opt-in via a new collapseLargePastes prop on PromptInput that only the chat Composer sets.
Notes
- The wire format and parser live in
@superset/chat/core, shared by desktop and mobile. - Mobile renders sent pastes as a tap-to-expand card and queued prompts with pastes as typed text plus a line count, instead of raw markup.
Summary by CodeRabbit
- New Features
- Large pasted text appears in compact cards in chat composers and message history, with line counts and controls to view, restore to the text field, or remove it.
- Pasted text can be submitted alone or alongside a message and attachments. Unsent prompts and pasted text are preserved for recovery.
- Undo and redo support pasted-text card changes, and paste-only messages can be copied.
- Large-paste handling is available in desktop and mobile chat, with translations across supported languages.
- Bug Fixes
- Failed attachment uploads restore pasted text to the input.
- Queued prompts and message previews retain pasted content.