The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): widen the inline image preview envelope so stacked image sets stay viewable
Austin Pickett7b9ce36a2192
diff --git a/apps/desktop/src/components/assistant-ui/markdown-text.doc-attachments.test.tsx b/apps/desktop/src/components/assistant-ui/markdown-text.doc-attachments.test.tsxnew file mode 100644index 00000000000..33fc7ca5d9e--- /dev/null+++ b/apps/desktop/src/components/assistant-ui/markdown-text.doc-attachments.test.tsx@@ -0,0 +1,47 @@+import { cleanup, render, screen } from '@testing-library/react'+import { afterEach, describe, expect, it } from 'vitest'++import { mediaDisplayLabel, mediaKind, mediaMarkdownHref } from '@/lib/media'++import { MarkdownTextContent } from './markdown-text'++// Regression for #74564 (attachment-card half): gateway-local PDF/ZIP+// artifacts emitted with MEDIA: (or a plain filesystem link) must surface as+// a prominent named attachment card with a download action — not a bare+// inline "Open <name>" fallback link.+describe('document attachments delivered via MEDIA (#74564)', () => {+ afterEach(cleanup)++ it('classifies pdf/zip as document files (never as opaque non-file kinds)', () => {+ // Documents stay 'file' — but they must be DOCUMENTS, so the renderer+ // routes them to the attachment card rather than a bare open anchor.+ expect(mediaKind('/home/user/out/report.pdf')).toBe('file')+ expect(mediaKind('/home/user/out/bundle.zip')).toBe('file')+ // The display label keeps the basename for the card.+ expect(mediaDisplayLabel('/home/user/out/report.pdf')).toContain('report.pdf')+ })++ it('renders a MEDIA pdf as a prominent attachment card with a download action', async () => {+ const href = mediaMarkdownHref('/home/user/out/report.pdf')++ render(<MarkdownTextContent isRunning={false} text={`Wrote the deck: [report.pdf](${href})`} />)++ // PreviewAttachment paints the filename + Download/Open-preview buttons;+ // the degraded path was a bare "Open report.pdf" anchor with no card.+ expect((await screen.findAllByRole('button')).length).toBeGreaterThanOrEqual(2)+ expect(screen.getByText('Download')).toBeTruthy()+ expect(screen.getByText('report.pdf')).toBeTruthy()+ expect(screen.queryByText(/^Open report/)).toBeNull()+ })++ it('renders a MEDIA zip as a prominent attachment card too', async () => {+ const href = mediaMarkdownHref('/home/user/out/images.zip')++ render(<MarkdownTextContent isRunning={false} text={`[images.zip](${href})`} />)++ expect((await screen.findAllByRole('button')).length).toBeGreaterThanOrEqual(2)+ expect(screen.getByText('Download')).toBeTruthy()+ expect(screen.getByText('images.zip')).toBeTruthy()+ expect(screen.queryByText(/^Open images/)).toBeNull()+ })+})diff --git a/apps/desktop/src/components/assistant-ui/markdown-text.tsx b/apps/desktop/src/components/assistant-ui/markdown-text.tsxindex 071b2766fee..db2bcb7ae7e 100644--- a/apps/desktop/src/components/assistant-ui/markdown-text.tsx+++ b/apps/desktop/src/components/assistant-ui/markdown-text.tsx@@ -402,10 +402,10 @@ export function MarkdownImage(props: ComponentProps<'img'>) {}// A cold frame is ~4:3 because that is the envelope an image can occupy here-// (--image-preview-max-width x --image-preview-height, 34rem x 26.25rem): every-// shape, portrait included, fits at the size it would have without a reserved-// frame. A 16:9 box shrank every narrower image (a 1080x1920 portrait to-// 172x306). Warm mounts use the measured size instead.+// (--image-preview-max-width x --image-preview-height): every shape, portrait+// included, fits at the size it would have without a reserved frame. A 16:9+// box shrank every narrower image (a 1080x1920 portrait to 172x306). Warm+// mounts use the measured size instead.const COLD_IMAGE_RATIO = 4 / 3function MarkdownImageContent({diff --git a/apps/desktop/src/hooks/use-media-image.frames.test.tsx b/apps/desktop/src/hooks/use-media-image.frames.test.tsxnew file mode 100644index 00000000000..65f310f058e--- /dev/null+++ b/apps/desktop/src/hooks/use-media-image.frames.test.tsx@@ -0,0 +1,55 @@+import { readFileSync } from 'node:fs'+import { dirname, resolve } from 'node:path'+import { fileURLToPath } from 'node:url'++import { renderHook } from '@testing-library/react'+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'++import { useMediaImage } from './use-media-image'++// Regression for #74564 (aperture half): the old preview clamp+// (--image-preview-height: clamp(16.25rem, …, 26.25rem), max-width 34rem)+// meant the reserved frame for a landscape image could never span the+// preview width — a 16:9 frame was at most 26.25rem × 16/9 ≈ 46.7rem, and+// on typical windows the viewport clamp pinned it nearer 16.25rem × 16/9 ≈+// 28.9rem, so stacked landscape images showed through a small aperture+// (the reporter measured ~10% of one image's height).+//+// The envelope lives in styles.css as two custom properties; both the+// useMediaImage frame width and the unframed max-h in markdown-text.tsx+// derive from them. Pin the contract at that seam.+describe('inline image preview envelope (#74564)', () => {+ const stylesheet = readFileSync(resolve(dirname(fileURLToPath(import.meta.url)), '../styles.css'), 'utf8')++ beforeEach(() => {+ vi.stubGlobal('window', { hermesDesktop: {} })+ })++ afterEach(() => {+ vi.unstubAllGlobals()+ })++ it('guarantees a landscape frame can span the full preview width', () => {+ const maxWidth = stylesheet.match(/--image-preview-max-width:\s*([\d.]+)rem/)?.[1]+ const height = stylesheet.match(/--image-preview-height:\s*clamp\(([\d.]+)rem/)?.[1]++ expect(maxWidth).toBeDefined()+ expect(height).toBeDefined()++ // The height FLOOR must be at least maxWidth × 9/16: then a 16:9 frame+ // (width = height × 16/9) reaches the full preview width even on the+ // shortest viewport, instead of collapsing to the old 16.25rem floor.+ expect(Number(height)).toBeGreaterThanOrEqual((Number(maxWidth) * 9) / 16)+ // And the envelope actually grew from the reported 34rem/16.25rem pair.+ expect(Number(maxWidth)).toBeGreaterThan(34)+ expect(Number(height)).toBeGreaterThan(16.25)+ })++ it('keeps the natural-size cap so a small image is never upscaled', () => {+ const { result } = renderHook(() =>+ useMediaImage('/home/user/out/shot.png', 16 / 9, { width: 640, height: 360 })+ )++ expect(String(result.current.frameStyle?.width)).toContain('640px')+ })+})diff --git a/apps/desktop/src/styles.css b/apps/desktop/src/styles.cssindex 0135a891f77..efd41b2b060 100644--- a/apps/desktop/src/styles.css+++ b/apps/desktop/src/styles.css@@ -558,8 +558,17 @@calc(100% - var(--composer-measured-height) + var(--composer-surface-measured-height)));--vsq: min(0.5vh, 0.5vw);- --image-preview-max-width: 34rem;- --image-preview-height: clamp(16.25rem, calc(var(--vsq) * 100), 26.25rem);+ /* The inline image preview envelope (#74564): agent-generated image SETS+ arrive stacked in one message, and the old 34rem x ~16-26rem clamp left+ each landscape image readable only through a small letterbox (the+ lightbox existed, but inline inspection was impractical). Width now+ fills most of the ~44rem message column, and the height floor is the+ old CAP — every viewport gets at least what only tall windows got+ before, so a 16:9 landscape frame always spans the full preview width+ (floor 26.25rem × 16/9 ≥ 40rem). Images are never upscaled: the frame+ width min() still caps at the natural px size. */+ --image-preview-max-width: 40rem;+ --image-preview-height: clamp(26.25rem, calc(var(--vsq) * 140), 40rem);--sidebar-width: 14.8125rem;--chat-min-width: 28rem;