Skip to content

The agent that grows with you

Inspired by ChatGPT Work: convert large pastes into .txt attachments in the Desktop composer

Teknium22e3888543dc
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.ts
index 986e556b63b..b8c0a2589a4 100644
--- a/apps/desktop/electron/main.ts
+++ b/apps/desktop/electron/main.ts
@@ -6298,6 +6298,20 @@ async function writeComposerImage(buffer, ext = '.png', name = '') {
return filePath
}
+// Large plain-text pastes are persisted as .txt files so the composer can
+// show them as an attachment chip instead of flooding the input (ChatGPT
+// Work-style large-paste handling). Mirrors writeComposerImage above.
+async function writeComposerPaste(text) {
+ const dir = path.join(app.getPath('userData'), 'composer-pastes')
+ await fs.promises.mkdir(dir, { recursive: true })
+ const stamp = new Date().toISOString().replace(/[:.]/g, '-').replace('T', '_').replace('Z', '')
+ const random = crypto.randomBytes(3).toString('hex')
+ const filePath = path.join(dir, `pasted_content_${stamp}_${random}.txt`)
+ await fs.promises.writeFile(filePath, text, 'utf8')
+
+ return filePath
+}
+
function previewLabelForUrl(url) {
return `${url.host}${url.pathname === '/' ? '' : url.pathname}`
}
@@ -17017,6 +17031,16 @@ ipcMain.handle('hermes:saveImageBuffer', async (_event, payload) => {
return writeComposerImage(buffer, payload?.ext || '.png', payload?.name)
})
+ipcMain.handle('hermes:savePastedText', async (_event, payload) => {
+ const text = typeof payload?.text === 'string' ? payload.text : ''
+
+ if (!text) {
+ throw new Error('savePastedText: missing text')
+ }
+
+ return writeComposerPaste(text)
+})
+
ipcMain.handle('hermes:saveClipboardImage', async () => {
const image = clipboard.readImage()
diff --git a/apps/desktop/electron/preload.ts b/apps/desktop/electron/preload.ts
index c5b29478f14..eaaab24f316 100644
--- a/apps/desktop/electron/preload.ts
+++ b/apps/desktop/electron/preload.ts
@@ -288,6 +288,7 @@ contextBridge.exposeInMainWorld('hermesDesktop', {
},
saveImageBuffer: (data, ext, name) => ipcRenderer.invoke('hermes:saveImageBuffer', { data, ext, name }),
capturePreview: payload => ipcRenderer.invoke('hermes:capturePreview', payload),
+ savePastedText: text => ipcRenderer.invoke('hermes:savePastedText', { text }),
saveClipboardImage: () => ipcRenderer.invoke('hermes:saveClipboardImage'),
getPathForFile: file => {
try {
diff --git a/apps/desktop/src/app/chat/composer/index.tsx b/apps/desktop/src/app/chat/composer/index.tsx
index ac0097a7352..1b3d31f6186 100644
--- a/apps/desktop/src/app/chat/composer/index.tsx
+++ b/apps/desktop/src/app/chat/composer/index.tsx
@@ -66,6 +66,7 @@ import { useEmojiCompletions } from './hooks/use-emoji-completions'
import { useComposerMicroActions } from './hooks/use-micro-actions'
import { useSlashCompletions } from './hooks/use-slash-completions'
import { useSessionStatusPresence } from './hooks/use-status-presence'
+import { shouldConvertPasteToAttachment } from './large-paste'
import { ActionBadges } from './micro-actions'
import { chipTypedPathOnSpace, pathifyRefs } from './path-refs'
import { QueuePanel } from './queue-panel'
@@ -105,6 +106,7 @@ export function ChatBar({
onAttachDroppedItems,
onAttachImageBlob,
onAttachPrCommentUrl,
+ onAttachPastedText,
onPasteClipboardImage,
onPickFiles,
onPickFolders,
@@ -562,6 +564,30 @@ export function ChatBar({
event.preventDefault()
+ // ChatGPT Work-style large-paste handling: a paste past the threshold
+ // becomes a `.txt` attachment chip instead of flooding the composer.
+ // The instruction the user types stays in the input; the pasted source
+ // material rides along as a file. Falls back to inline insertion if the
+ // attachment can't be created (missing bridge, write failure) so the
+ // paste is never lost.
+ if (onAttachPastedText && shouldConvertPasteToAttachment(pastedText)) {
+ const editor = event.currentTarget
+
+ void Promise.resolve(onAttachPastedText(pastedText)).then(attached => {
+ if (attached) {
+ triggerHaptic('selection')
+
+ return
+ }
+
+ recordUndoPoint()
+ insertComposerContentsAtCaret(editor, pathifyRefs(linkifyUrls(pastedText)), openDirectiveScope(editor))
+ scheduleFlushEditorToDraft(editor)
+ })
+
+ return
+ }
+
// Links in the paste land as `@url:` chips rather than a wall of URL text —
// the same reference the "Add URL" dialog inserts, parsed in place so a link
// mid-sentence keeps its position. Bare `@path` tokens promote the same way.
diff --git a/apps/desktop/src/app/chat/composer/large-paste.test.ts b/apps/desktop/src/app/chat/composer/large-paste.test.ts
new file mode 100644
index 00000000000..8d11daf27fc
--- /dev/null
+++ b/apps/desktop/src/app/chat/composer/large-paste.test.ts
@@ -0,0 +1,33 @@
+import { describe, expect, it } from 'vitest'
+
+import { LARGE_PASTE_ATTACHMENT_THRESHOLD, shouldConvertPasteToAttachment } from './large-paste'
+
+describe('shouldConvertPasteToAttachment', () => {
+ it('keeps short pastes inline', () => {
+ expect(shouldConvertPasteToAttachment('hello world')).toBe(false)
+ expect(shouldConvertPasteToAttachment('')).toBe(false)
+ })
+
+ it('keeps a paste exactly at the threshold inline', () => {
+ expect(shouldConvertPasteToAttachment('a'.repeat(LARGE_PASTE_ATTACHMENT_THRESHOLD))).toBe(false)
+ })
+
+ it('converts a paste one character past the threshold', () => {
+ expect(shouldConvertPasteToAttachment('a'.repeat(LARGE_PASTE_ATTACHMENT_THRESHOLD + 1))).toBe(true)
+ })
+
+ it('honors a custom threshold', () => {
+ expect(shouldConvertPasteToAttachment('abcdef', 5)).toBe(true)
+ expect(shouldConvertPasteToAttachment('abcde', 5)).toBe(false)
+ })
+
+ it('never converts when the threshold is disabled (non-positive)', () => {
+ expect(shouldConvertPasteToAttachment('a'.repeat(50_000), 0)).toBe(false)
+ expect(shouldConvertPasteToAttachment('a'.repeat(50_000), -1)).toBe(false)
+ })
+
+ it('rejects non-string input defensively', () => {
+ expect(shouldConvertPasteToAttachment(undefined as unknown as string)).toBe(false)
+ expect(shouldConvertPasteToAttachment(null as unknown as string)).toBe(false)
+ })
+})
diff --git a/apps/desktop/src/app/chat/composer/large-paste.ts b/apps/desktop/src/app/chat/composer/large-paste.ts
new file mode 100644
index 00000000000..01afece913e
--- /dev/null
+++ b/apps/desktop/src/app/chat/composer/large-paste.ts
@@ -0,0 +1,40 @@
+/**
+ * Large-paste-to-attachment policy.
+ *
+ * Inspired by ChatGPT Work's composer behavior (OpenAI release notes,
+ * Aug 4 2026): pasting more than ~10k characters converts the content into a
+ * text attachment instead of inserting it inline, keeping the composer clean
+ * and preventing a single paste from flooding the input. Short pastes stay
+ * inline; the threshold lives here so every paste handler shares one policy.
+ */
+
+/** Characters beyond which a plain-text paste becomes a `.txt` attachment. */
+export const LARGE_PASTE_ATTACHMENT_THRESHOLD = 10_000
+
+/**
+ * True when a plain-text paste should be converted into a text attachment
+ * rather than inserted inline. Only sheer size qualifies — rich clipboard
+ * data, images, and files never route through this path (they have their own
+ * pipelines upstream of this check).
+ */
+export function shouldConvertPasteToAttachment(
+ text: string,
+ threshold: number = LARGE_PASTE_ATTACHMENT_THRESHOLD
+): boolean {
+ return typeof text === 'string' && threshold > 0 && text.length > threshold
+}
+
+/** Human-readable size of a paste's UTF-8 bytes, for the attachment chip. */
+export function pasteSizeLabel(text: string): string {
+ const bytes = new TextEncoder().encode(text).length
+
+ if (bytes < 1024) {
+ return `${bytes} B`
+ }
+
+ if (bytes < 1024 * 1024) {
+ return `${(bytes / 1024).toFixed(1)} KB`
+ }
+
+ return `${(bytes / (1024 * 1024)).toFixed(1)} MB`
+}
diff --git a/apps/desktop/src/app/chat/composer/types.ts b/apps/desktop/src/app/chat/composer/types.ts
index 56516b558b6..dc78bf942d9 100644
--- a/apps/desktop/src/app/chat/composer/types.ts
+++ b/apps/desktop/src/app/chat/composer/types.ts
@@ -49,6 +49,7 @@ export interface ChatBarProps {
/** Pasted GitHub PR-comment deep link → structured review attachment.
* Returns true when the paste was consumed as an attachment. */
onAttachPrCommentUrl?: (url: string) => boolean
+ onAttachPastedText?: (text: string) => Promise<boolean> | boolean
onPasteClipboardImage?: (opts?: { silent?: boolean }) => Promise<boolean> | void
onPickFiles?: () => void
onPickFolders?: () => void
diff --git a/apps/desktop/src/app/chat/hooks/use-composer-actions.ts b/apps/desktop/src/app/chat/hooks/use-composer-actions.ts
index f6e47fbd785..d9260a9a37e 100644
--- a/apps/desktop/src/app/chat/hooks/use-composer-actions.ts
+++ b/apps/desktop/src/app/chat/hooks/use-composer-actions.ts
@@ -2,6 +2,7 @@ import { useCallback } from 'react'
import { requestComposerFocus, requestComposerInsert, requestComposerInsertRefs } from '@/app/chat/composer/focus'
import { droppedFileInlineRef } from '@/app/chat/composer/inline-refs'
+import { pasteSizeLabel } from '@/app/chat/composer/large-paste'
import { formatRefValue } from '@/components/assistant-ui/directive-text'
import { useI18n } from '@/i18n'
import { attachmentId, contextPath, pathLabel } from '@/lib/chat-runtime'
@@ -589,6 +590,48 @@ export function useComposerActions({
[attachImagePath, copy.clipboard, copy.clipboardPasteFailed, copy.noClipboardImage]
)
+ /**
+ * Convert a very large plain-text paste into a `.txt` attachment chip
+ * (ChatGPT Work-style). The exact pasted text is written to a
+ * Hermes-managed composer-pastes file via the main process, then attached
+ * through the same `@file:` pipeline as a manually attached text file.
+ * Returns false (paste stays inline) when the desktop bridge is missing
+ * or the write fails.
+ */
+ const attachPastedText = useCallback(
+ async (text: string) => {
+ const save = window.hermesDesktop?.savePastedText
+
+ if (!text || !save) {
+ return false
+ }
+
+ try {
+ const savedPath = await save(text)
+
+ if (!savedPath) {
+ return false
+ }
+
+ attachToMain({
+ id: attachmentId('file', savedPath),
+ kind: 'file',
+ label: `${copy.pastedContent} (${pasteSizeLabel(text)})`,
+ detail: contextPath(savedPath, currentCwd),
+ refText: `@file:${formatRefValue(savedPath)}`,
+ path: savedPath
+ })
+
+ return true
+ } catch (err) {
+ notifyError(err, copy.pasteAttachFailed)
+
+ return false
+ }
+ },
+ [attachToMain, copy.pasteAttachFailed, copy.pastedContent, currentCwd]
+ )
+
const attachContextFolderPath = useCallback(
(folderPath: string) => {
if (!folderPath) {
@@ -733,6 +776,7 @@ export function useComposerActions({
attachImageBlob,
attachImagePath,
attachPrCommentUrl,
+ attachPastedText,
insertContextPathInlineRef,
pasteClipboardImage,
pickContextPaths,
diff --git a/apps/desktop/src/app/chat/index.tsx b/apps/desktop/src/app/chat/index.tsx
index 49dd37ac0b9..ec77601993b 100644
--- a/apps/desktop/src/app/chat/index.tsx
+++ b/apps/desktop/src/app/chat/index.tsx
@@ -96,6 +96,7 @@ interface ChatViewProps extends Omit<React.ComponentProps<'div'>, 'onSubmit'> {
onAttachImageBlob: (blob: Blob) => Promise<boolean | void> | boolean | void
onAttachDroppedItems: (candidates: DroppedFile[]) => Promise<boolean | void> | boolean | void
onAttachPrCommentUrl?: (url: string) => boolean
+ onAttachPastedText?: (text: string) => Promise<boolean> | boolean
onPasteClipboardImage: (opts?: { silent?: boolean }) => Promise<boolean> | void
onPickFiles: () => void
onPickFolders: () => void
@@ -389,6 +390,7 @@ const ChatViewContent = memo(function ChatViewContent({
onAttachImageBlob,
onAttachDroppedItems,
onAttachPrCommentUrl,
+ onAttachPastedText,
onBranchInNewChat,
maxVoiceRecordingSeconds,
onPasteClipboardImage,
@@ -758,6 +760,7 @@ const ChatViewContent = memo(function ChatViewContent({
onAttachDroppedItems={onAttachDroppedItems}
onAttachImageBlob={onAttachImageBlob}
onAttachPrCommentUrl={onAttachPrCommentUrl}
+ onAttachPastedText={onAttachPastedText}
onCancel={onCancel}
onPasteClipboardImage={onPasteClipboardImage}
onPickFiles={onPickFiles}
diff --git a/apps/desktop/src/app/chat/session-tile.tsx b/apps/desktop/src/app/chat/session-tile.tsx
index 90bd7c70b27..7ad89b16100 100644
--- a/apps/desktop/src/app/chat/session-tile.tsx
+++ b/apps/desktop/src/app/chat/session-tile.tsx
@@ -308,6 +308,7 @@ function TileChat({
onAttachDroppedItems={composer.attachDroppedItems}
onAttachImageBlob={composer.attachImageBlob}
onAttachPrCommentUrl={composer.attachPrCommentUrl}
+ onAttachPastedText={composer.attachPastedText}
onCancel={actions.cancelRun}
onDeleteSelectedSession={noop}
onDismissError={actions.dismissError}
diff --git a/apps/desktop/src/app/contrib/types.ts b/apps/desktop/src/app/contrib/types.ts
index 77e853ed6e9..ddf66a4c429 100644
--- a/apps/desktop/src/app/contrib/types.ts
+++ b/apps/desktop/src/app/contrib/types.ts
@@ -32,6 +32,7 @@ export type ChatActions = Pick<
| 'onAttachDroppedItems'
| 'onAttachImageBlob'
| 'onAttachPrCommentUrl'
+ | 'onAttachPastedText'
| 'onBranchInNewChat'
| 'onCancel'
| 'onDeleteSelectedSession'
diff --git a/apps/desktop/src/app/contrib/wiring.tsx b/apps/desktop/src/app/contrib/wiring.tsx
index 185e73588ef..6e56761e252 100644
--- a/apps/desktop/src/app/contrib/wiring.tsx
+++ b/apps/desktop/src/app/contrib/wiring.tsx
@@ -1075,6 +1075,7 @@ export function ContribWiring({ children }: { children: ReactNode }) {
onAttachDroppedItems: composer.attachDroppedItems,
onAttachImageBlob: composer.attachImageBlob,
onAttachPrCommentUrl: composer.attachPrCommentUrl,
+ onAttachPastedText: composer.attachPastedText,
onBranchInNewChat: messageId => void branchInNewChat(messageId),
onBranchSession: sessionId => void branchStoredSession(sessionId),
onCancel: cancelRun,
diff --git a/apps/desktop/src/global.d.ts b/apps/desktop/src/global.d.ts
index 84192c2450b..6e4b48f7321 100644
--- a/apps/desktop/src/global.d.ts
+++ b/apps/desktop/src/global.d.ts
@@ -333,6 +333,7 @@ declare global {
viewport?: { height: number; width: number }
webContentsId: number
}) => Promise<string>
+ savePastedText: (text: string) => Promise<string>
saveClipboardImage: () => Promise<string>
getPathForFile: (file: File) => string
normalizePreviewTarget: (target: string, baseDir?: string) => Promise<HermesPreviewTarget | null>
diff --git a/apps/desktop/src/i18n/ar.ts b/apps/desktop/src/i18n/ar.ts
index 70af60713c3..63eb47db9c7 100644
--- a/apps/desktop/src/i18n/ar.ts
+++ b/apps/desktop/src/i18n/ar.ts
@@ -3136,6 +3136,8 @@ export const ar = defineLocale({
imageAttach: 'إرفاق الصورة',
imageWriteFailed: 'فشل كتابة الصورة',
imageAttachFailed: 'فشل إرفاق الصورة',
+ pastedContent: 'محتوى ملصق',
+ pasteAttachFailed: 'تعذر إرفاق النص الملصق',
attachImages: 'إرفاق الصور',
clipboard: 'الحافظة',
noClipboardImage: 'لا توجد صورة في الحافظة',
diff --git a/apps/desktop/src/i18n/en.ts b/apps/desktop/src/i18n/en.ts
index 7e82198f933..7425997b254 100644
--- a/apps/desktop/src/i18n/en.ts
+++ b/apps/desktop/src/i18n/en.ts
@@ -4103,6 +4103,8 @@ export const en: Translations = {
imageAttach: 'Image attach',
imageWriteFailed: 'Failed to write image to disk.',
imageAttachFailed: 'Image attach failed',
+ pastedContent: 'Pasted content',
+ pasteAttachFailed: 'Could not attach pasted text',
attachImages: 'Attach images',
clipboard: 'Clipboard',
noClipboardImage: 'No image found in clipboard',
diff --git a/apps/desktop/src/i18n/ja.ts b/apps/desktop/src/i18n/ja.ts
index da080dcf006..17c62deb471 100644
--- a/apps/desktop/src/i18n/ja.ts
+++ b/apps/desktop/src/i18n/ja.ts
@@ -3549,6 +3549,8 @@ export const ja = defineLocale({
imageAttach: '画像を添付',
imageWriteFailed: '画像のディスクへの書き込みに失敗しました。',
imageAttachFailed: '画像の添付に失敗しました',
+ pastedContent: '貼り付けた内容',
+ pasteAttachFailed: '貼り付けたテキストを添付できませんでした',
attachImages: '画像を添付',
clipboard: 'クリップボード',
noClipboardImage: 'クリップボードに画像が見つかりません',
diff --git a/apps/desktop/src/i18n/types.ts b/apps/desktop/src/i18n/types.ts
index 2bd34420174..d403a67998c 100644
--- a/apps/desktop/src/i18n/types.ts
+++ b/apps/desktop/src/i18n/types.ts
@@ -3589,6 +3589,8 @@ export interface Translations {
imageAttach: string
imageWriteFailed: string
imageAttachFailed: string
+ pastedContent: string
+ pasteAttachFailed: string
attachImages: string
clipboard: string
noClipboardImage: string
diff --git a/apps/desktop/src/i18n/zh-hant.ts b/apps/desktop/src/i18n/zh-hant.ts
index 0777d0936b5..28fcde5a155 100644
--- a/apps/desktop/src/i18n/zh-hant.ts
+++ b/apps/desktop/src/i18n/zh-hant.ts
@@ -3400,6 +3400,8 @@ export const zhHant = defineLocale({
imageAttach: '附加圖片',
imageWriteFailed: '無法將圖片寫入磁碟。',
imageAttachFailed: '附加圖片失敗',
+ pastedContent: '貼上內容',
+ pasteAttachFailed: '無法附加貼上的文字',
attachImages: '附加圖片',
clipboard: '剪貼簿',
noClipboardImage: '剪貼簿中沒有圖片',
diff --git a/apps/desktop/src/i18n/zh.ts b/apps/desktop/src/i18n/zh.ts
index 22c1bdd8136..6e61a61dc4c 100644
--- a/apps/desktop/src/i18n/zh.ts
+++ b/apps/desktop/src/i18n/zh.ts
@@ -4213,6 +4213,8 @@ export const zh = defineLocale({
imageAttach: '附加图片',
imageWriteFailed: '无法将图片写入磁盘。',
imageAttachFailed: '附加图片失败',
+ pastedContent: '粘贴内容',
+ pasteAttachFailed: '无法附加粘贴的文本',
attachImages: '附加图片',
clipboard: '剪贴板',
noClipboardImage: '剪贴板中没有图片',