The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: restore canonical desktop image thumbnails safely
Teknium4d5db8201b90
diff --git a/apps/desktop/docs/canonical-gateway-protocol.md b/apps/desktop/docs/canonical-gateway-protocol.mdindex 082d4f08889..aae24e42ae5 100644--- a/apps/desktop/docs/canonical-gateway-protocol.md+++ b/apps/desktop/docs/canonical-gateway-protocol.md@@ -44,6 +44,18 @@ atomic-file journal is still written before transport admission and retired onlyafter a matching accepted receipt. An unknown receipt retains it for explicitretry. Renderer-only localStorage recovery is not native crash durability.+## Image history and recovery++Canonical native image history carries image-routing hints followed by flattened+`[screenshot]` parts. Desktop projects that complete suffix into attachment+thumbnails without rewriting stored messages or image bytes. Caption prose and+assistant text remain text; legacy `@image:` history keeps its existing rendering.++The prepared-image recovery affordance offers only ordinary unqueued drafts in+their original connection/profile/session. Slash invocations, legacy ambiguous+attempts and other recovery identities stay in the journal unchanged; they are+not offered as ordinary image drafts or automatically resubmitted by this view.+## Controls and metadataLive and replayed prompt projections retain `prompt_id` and execution generation,diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/prepared-submissions.test.ts b/apps/desktop/src/app/session/hooks/use-prompt-actions/prepared-submissions.test.tsindex 54dd1b1c1e4..e5a8663f87c 100644--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/prepared-submissions.test.ts+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/prepared-submissions.test.ts@@ -1,9 +1,28 @@import { afterEach, expect, test, vi } from 'vitest'-import { type PreparedSubmission, readPreparedSubmission, removePreparedSubmission, writePreparedSubmission } from './prepared-submissions'+import { listPreparedImageDrafts, type PreparedSubmission, preparedSubmissionKey, readPreparedSubmission, removePreparedSubmission, writePreparedSubmission } from './prepared-submissions'+import type { SubmissionDestination } from './submission-destination'afterEach(() => { vi.unstubAllGlobals(); localStorage.clear() })+test('image recovery never offers expanded slash intent as an ordinary draft and leaves its exact journal intact', async () => {+ vi.stubGlobal('hermesDesktop', undefined)+ const destination = { scopeKey: 'local::default' } as SubmissionDestination+ const attachments: PreparedSubmission['attachments'] = [{ id: '/cache/a.png', occurrenceId: 'image-occurrence', kind: 'image', label: 'a.png' }]+ const ordinary = preparedSubmissionKey('stored', destination, 'caption', attachments)+ const slash = preparedSubmissionKey('stored', destination, 'expanded skill instructions', attachments, { retryText: '/skill task', submission_id: 'skill-id' })++ for (const [key, text] of [[ordinary, 'caption'], [slash, 'expanded skill instructions']]) {+ await writePreparedSubmission(key, { id: key, text, attachments, params: { submission_id: key }, owner: { connectionId: 'local', profile: 'default' } })+ }++ const before = localStorage.getItem('hermes.desktop.preparedSubmissions.v1')+ expect((await listPreparedImageDrafts('stored', destination.scopeKey)).map(entry => entry.key)).toEqual([ordinary])+ expect(await listPreparedImageDrafts('another', destination.scopeKey)).toEqual([])+ expect(localStorage.getItem('hermes.desktop.preparedSubmissions.v1')).toBe(before)+ expect((await readPreparedSubmission(slash))?.text).toBe('expanded skill instructions')+})+test('native preparation waits for acknowledgement and never downgrades a write failure to browser storage', async () => {let ack!: () => voidconst gate = new Promise<void>(resolve => { ack = resolve })diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/prepared-submissions.ts b/apps/desktop/src/app/session/hooks/use-prompt-actions/prepared-submissions.tsindex 7896ff9e789..5268a0fbca6 100644--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/prepared-submissions.ts+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/prepared-submissions.ts@@ -57,8 +57,10 @@ export async function listPreparedImageDrafts(target: string, scopeKey: string)const [scope, session, text, , displayKind, fromQueue, submissionId] = JSON.parse(key)// Restoring an ordinary draft must recreate its exact retry key. Queue and- // slash submissions have additional intent fields and own their recovery.+ // slash submissions own their recovery. Historical slash keys intentionally+ // omit submissionId, so the retained invocation must also be excluded.return scope === scopeKey && session === target && !displayKind && !fromQueue && !submissionId &&+ !String(text).trimStart().startsWith('/') &&!entry.legacyAttempted && entry.attachments.some(attachment => attachment.kind === 'image')? [{ key, text: String(text), attachments: entry.attachments }]: []diff --git a/apps/desktop/src/lib/chat-messages.test.ts b/apps/desktop/src/lib/chat-messages.test.tsindex 0874c2a6c60..281941b80a6 100644--- a/apps/desktop/src/lib/chat-messages.test.ts+++ b/apps/desktop/src/lib/chat-messages.test.ts@@ -227,6 +227,23 @@ describe('toChatMessages', () => {expect(chatMessageText(message)).toBe('Here you go.\n\n')})+ it('hydrates canonical native image suffixes without changing durable history or caption prose', () => {+ const caption = 'Explain [Image attached at: /not/an/attachment.png] in this sentence.'+ const paths = ['/cache/native-inputs/hash/a [1].png', 'https://example.test/image.png']+ const content = `${caption}\n\n[Image attached at: ${paths[0]}]\n[Image attached: ${paths[1]}]\n[screenshot]\n[screenshot]`+ const stored = { role: 'user' as const, content, timestamp: 1, row_id: 23 }+ const [message] = toChatMessages([stored])++ expect(chatMessageText(message)).toBe(caption)+ expect(message.attachmentRefs).toEqual([`@image:\`${paths[0]}\``, `@image:${paths[1]}`])+ expect(stored.content).toBe(content)+ const [prose] = toChatMessages([{ ...stored, content: `${caption}\n\n[Image attached at: /literal.png]` }])+ expect(chatMessageText(prose)).toBe(`${caption}\n\n[Image attached at: /literal.png]`)+ expect(prose.attachmentRefs).toBeUndefined()+ const [assistant] = toChatMessages([{ ...stored, role: 'assistant' }])+ expect(chatMessageText(assistant)).toBe(content)+ })+it('lifts @image directive lines into attachmentRefs instead of inline text', () => {const [message] = toChatMessages([{diff --git a/apps/desktop/src/lib/chat-messages/hydration.ts b/apps/desktop/src/lib/chat-messages/hydration.tsindex df3b765df39..9b460d39280 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 { formatRefValue } from '@/components/assistant-ui/directive-text'import { extractImageRefs } from '@/lib/embedded-images'import { dedupeGeneratedImageEchoesInParts } from '@/lib/generated-images'import type { MessageReaction, SessionMessage } from '@/types/hermes'@@ -19,6 +20,20 @@ const ATTACHED_CONTEXT_MARKER_RE = /(?:^|\n)--- Attached Context ---\s*\n/const CONTEXT_WARNINGS_MARKER_RE = /(?:^|\n)--- Context Warnings ---[\s\S]*$/const CONTEXT_REF_RE = /@(file|folder|url|image|tool|terminal):(?:"[^"\n]+"|'[^'\n]+'|`[^`\n]+`|\S+)/g+// Native ingress persists the image-routing hints followed by one placeholder+// per flattened image part. Recognize that suffix only, not quoted caption prose.+function persistedImageRefs(text: string) {+ const suffix = /\n\n((?:\[Image attached(?: at)?: [^\n]+\]\n)+)((?:\[screenshot\](?:\n|$))+)$/.exec(text)++ if (!suffix) { return extractImageRefs(text) }+ const paths = [...suffix[1].matchAll(/^\[Image attached(?: at)?: (.+)\]$/gm)].map(match => match[1])++ if (paths.length !== suffix[2].split('[screenshot]').length - 1) { return extractImageRefs(text) }+ const extracted = extractImageRefs(text.slice(0, suffix.index))++ return { cleanedText: extracted.cleanedText, refs: [...extracted.refs, ...paths.map(path => `@image:${formatRefValue(path)}`)] }+}+/*** Reply text from a Responses-API `codex_message_items` sidecar (#68321), for rows* whose `content` persisted empty. `commentary` / `analysis` items are mid-turn@@ -310,7 +325,7 @@ export function toChatMessages(messages: SessionMessage[]): ChatMessage[] {// 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.- const imageRefExtraction = displayRole === 'user' && rawDisplayContent ? extractImageRefs(rawDisplayContent) : null+ const imageRefExtraction = displayRole === 'user' && rawDisplayContent ? persistedImageRefs(rawDisplayContent) : nullconst displayContent = imageRefExtraction ? imageRefExtraction.cleanedText : rawDisplayContentconst extractedAttachmentRefs = imageRefExtraction?.refs.length ? imageRefExtraction.refs : undefined