The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): lift a stored turn's attachment refs into the chip row
Brooklyn Nicholsoncac30a91cd99
diff --git a/apps/desktop/src/app/session/hooks/use-session-actions/utils.ts b/apps/desktop/src/app/session/hooks/use-session-actions/utils.tsindex 2dd506cc06b..9e5993de136 100644--- a/apps/desktop/src/app/session/hooks/use-session-actions/utils.ts+++ b/apps/desktop/src/app/session/hooks/use-session-actions/utils.ts@@ -1118,34 +1118,24 @@ export function appendLiveSessionProjection(messages: ChatMessage[], projection:projection[safelyPersistedInflightUser] === true || (Boolean(inflightUser) && persistedInLatestRun(inflightUser))if (inflightUser && !inflightUserAlreadyPersisted) {- // A synthetic starting prompt (process_complete, hidden, …) carries the- // display typing its persisted row will get: render it through the same- // timeline projection history uses instead of as a user bubble (#112144).- // `toChatMessages` yields nothing for `hidden`, so the prompt is omitted.+ // Project the prompt through the same conversion history uses, so the live+ // bubble matches its persisted twin: attachment refs lift into the chip row,+ // and a synthetic starting prompt (process_complete, hidden, …) takes the+ // display typing its row will get (#112144) — `hidden` yields nothing.const displayKind = projection.inflight?.display_kind- const typed = displayKind- ? toChatMessages([- {- role: 'user',- content: inflightUser,- display_kind: displayKind,- ...(projection.inflight?.display_metadata !== undefined- ? { display_metadata: projection.inflight.display_metadata }- : {})- }- ])- : null-- if (typed) {- projected.push(...typed.map(message => ({ ...message, id: `user-inflight-${sessionId}` })))- } else {- projected.push({- id: `user-inflight-${sessionId}`,+ const typed = toChatMessages([+ {role: 'user',- parts: [textPart(inflightUser)]- })- }+ content: inflightUser,+ ...(displayKind ? { display_kind: displayKind } : {}),+ ...(displayKind && projection.inflight?.display_metadata !== undefined+ ? { display_metadata: projection.inflight.display_metadata }+ : {})+ }+ ])++ projected.push(...typed.map(message => ({ ...message, id: `user-inflight-${sessionId}` })))}// Keep a pending assistant boundary even before the first delta when adiff --git a/apps/desktop/src/components/assistant-ui/reference-kinds.ts b/apps/desktop/src/components/assistant-ui/reference-kinds.tsindex 7d6c397584c..3a5113f81de 100644--- a/apps/desktop/src/components/assistant-ui/reference-kinds.ts+++ b/apps/desktop/src/components/assistant-ui/reference-kinds.ts@@ -171,3 +171,27 @@ export function textWithoutReferenceLines(text: string): string {.join('\n').trim()}++/** A composer attachment ref (`@file:`/`@folder:`), which renders as a chip, not a thumbnail. */+export const isAttachmentRef = (ref: string): boolean => /^@(?:file|folder):/.test(ref)++/**+ * Peel the attachment block off the top of a stored user prompt.+ *+ * The composer sends attachments as one `@file:`/`@folder:` line each, ahead+ * of the typed text, and keeps them out of the bubble as `attachmentRefs`. A+ * persisted turn carries that block inline, so without this a reloaded (or+ * reconciled) bubble opens with a raw path and a blank line where the live one+ * showed a chip under the prompt. Only the leading run moves: a ref typed+ * mid-prose stays where the user put it.+ */+export function splitLeadingAttachmentRefs(text: string): { refs: string[]; text: string } {+ const lines = text.split('\n')+ const refs: string[] = []++ while (lines.length && isAttachmentRef(lines[0]) && REFERENCE_LINE_RE.test(lines[0].trimEnd())) {+ refs.push(lines.shift()!.trimEnd())+ }++ return refs.length ? { refs, text: lines.join('\n').trim() } : { refs, text }+}diff --git a/apps/desktop/src/lib/chat-messages.test.ts b/apps/desktop/src/lib/chat-messages.test.tsindex a175d9a5395..eca3421954c 100644--- a/apps/desktop/src/lib/chat-messages.test.ts+++ b/apps/desktop/src/lib/chat-messages.test.ts@@ -173,7 +173,26 @@ describe('toChatMessages', () => {}])- expect(chatMessageText(message)).toBe('@file:tsconfig.tsbuildinfo\n\nwhat is this file')+ expect(chatMessageText(message)).toBe('what is this file')+ expect(message.attachmentRefs).toEqual(['@file:tsconfig.tsbuildinfo'])+ })++ it('lifts the leading attachment block into the chip row, like the live bubble (large paste)', () => {+ const paste = '@file:/home/u/.hermes/attachments/pasted_content_2026-09-27_21-33-42-827_55e028-2.txt'++ const [captioned, bare] = toChatMessages([+ {+ role: 'user',+ content: `${paste}\n@image:/tmp/shot.png\n\nfix these\n\n--- Attached Context ---\n\n📄 ${paste} (769 tokens)\n\`\`\`\nlog\n\`\`\``,+ timestamp: 1+ },+ { role: 'user', content: `${paste}\n\n--- Attached Context ---\n\n📄 ${paste} (769 tokens)`, timestamp: 2 }+ ])++ expect(chatMessageText(captioned)).toBe('fix these')+ expect(captioned.attachmentRefs).toEqual([paste, '@image:/tmp/shot.png'])+ expect(chatMessageText(bare)).toBe('')+ expect(bare.attachmentRefs).toEqual([paste])})it('hides a persisted Discord triggering-message note but keeps the reply pointer (#114719)', () => {@@ -326,7 +345,8 @@ describe('toChatMessages', () => {}])- expect(chatMessageText(message)).toBe('@file:foo.ts\n\nlook')+ expect(chatMessageText(message)).toBe('look')+ expect(message.attachmentRefs).toEqual(['@file:foo.ts'])})it('leaves an inline @ ref in place instead of hoisting a duplicate', () => {diff --git a/apps/desktop/src/lib/chat-messages/hydration.ts b/apps/desktop/src/lib/chat-messages/hydration.tsindex b01afb7a1c2..04fa5744375 100644--- a/apps/desktop/src/lib/chat-messages/hydration.ts+++ b/apps/desktop/src/lib/chat-messages/hydration.ts@@ -1,5 +1,6 @@import { skillInvocationText } from '@hermes/shared'+import { splitLeadingAttachmentRefs } from '@/components/assistant-ui/reference-kinds'import { extractImageRefs } from '@/lib/embedded-images'import { dedupeGeneratedImageEchoesInParts } from '@/lib/generated-images'import { isTodoToolName } from '@/lib/todos'@@ -434,10 +435,13 @@ export function toChatMessages(messages: SessionMessage[]): ChatMessage[] {// thumbnail pushes any caption text below the clamp's visible area — so// pull image refs out into `attachmentRefs` (same shape the local// optimistic composer already uses) and render them via the dedicated- // attachments row below the bubble instead.+ // attachments row below the bubble instead. The leading `@file:` block+ // (attached files, large pastes) moves there too, for the same parity.const imageRefExtraction = displayRole === 'user' && rawDisplayContent ? extractImageRefs(rawDisplayContent) : null- const displayContent = imageRefExtraction ? imageRefExtraction.cleanedText : rawDisplayContent- const extractedAttachmentRefs = imageRefExtraction?.refs.length ? imageRefExtraction.refs : undefined+ const fileRefExtraction = imageRefExtraction ? splitLeadingAttachmentRefs(imageRefExtraction.cleanedText) : null+ const displayContent = fileRefExtraction ? fileRefExtraction.text : rawDisplayContent+ const liftedRefs = [...(fileRefExtraction?.refs ?? []), ...(imageRefExtraction?.refs ?? [])]+ const extractedAttachmentRefs = liftedRefs.length ? liftedRefs : undefinedconst parts: ChatMessagePart[] = []const rowId = message.row_id ?? (typeof message.id === 'number' ? message.id : undefined)