From 7ddc9493aea69849c13f00415d233574d8bbda6a Mon Sep 17 00:00:00 2001 From: Jack Wotherspoon Date: Mon, 8 Dec 2025 21:57:11 -0500 Subject: [PATCH 1/2] fix: use Gemini API supported image formats for clipboard --- packages/cli/src/ui/utils/clipboardUtils.ts | 25 +++++++++++++-------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/packages/cli/src/ui/utils/clipboardUtils.ts b/packages/cli/src/ui/utils/clipboardUtils.ts index 86da766efaa..f45cdeb0131 100644 --- a/packages/cli/src/ui/utils/clipboardUtils.ts +++ b/packages/cli/src/ui/utils/clipboardUtils.ts @@ -8,6 +8,19 @@ import * as fs from 'node:fs/promises'; import * as path from 'node:path'; import { debugLogger, spawnAsync } from '@google/gemini-cli-core'; +/** + * Supported image file extensions based on Gemini API. + * See: https://ai.google.dev/gemini-api/docs/image-understanding + */ +export const IMAGE_EXTENSIONS = [ + '.png', + '.jpg', + '.jpeg', + '.webp', + '.heic', + '.heif', +]; + /** * Checks if the system clipboard contains an image (macOS only for now) * @returns true if clipboard contains an image @@ -51,11 +64,10 @@ export async function saveClipboardImage( const timestamp = new Date().getTime(); // Try different image formats in order of preference + // Only formats supported by Gemini API: PNG, JPEG, WEBP, HEIC, HEIF const formats = [ { class: 'PNGf', extension: 'png' }, { class: 'JPEG', extension: 'jpg' }, - { class: 'TIFF', extension: 'tiff' }, - { class: 'GIFf', extension: 'gif' }, ]; for (const format of formats) { @@ -125,13 +137,8 @@ export async function cleanupOldClipboardImages( const oneHourAgo = Date.now() - 60 * 60 * 1000; for (const file of files) { - if ( - file.startsWith('clipboard-') && - (file.endsWith('.png') || - file.endsWith('.jpg') || - file.endsWith('.tiff') || - file.endsWith('.gif')) - ) { + const ext = path.extname(file).toLowerCase(); + if (file.startsWith('clipboard-') && IMAGE_EXTENSIONS.includes(ext)) { const filePath = path.join(tempDir, file); const stats = await fs.stat(filePath); if (stats.mtimeMs < oneHourAgo) { From 2ddaecd30df66fe47a6d333bc099ba251ebac049 Mon Sep 17 00:00:00 2001 From: Jack Wotherspoon Date: Mon, 8 Dec 2025 22:33:36 -0500 Subject: [PATCH 2/2] chore: update comment --- packages/cli/src/ui/utils/clipboardUtils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/ui/utils/clipboardUtils.ts b/packages/cli/src/ui/utils/clipboardUtils.ts index f45cdeb0131..b4760ca7221 100644 --- a/packages/cli/src/ui/utils/clipboardUtils.ts +++ b/packages/cli/src/ui/utils/clipboardUtils.ts @@ -63,8 +63,8 @@ export async function saveClipboardImage( // Generate a unique filename with timestamp const timestamp = new Date().getTime(); - // Try different image formats in order of preference - // Only formats supported by Gemini API: PNG, JPEG, WEBP, HEIC, HEIF + // AppleScript clipboard classes to try, in order of preference. + // macOS converts clipboard images to these formats (WEBP/HEIC/HEIF not supported by osascript). const formats = [ { class: 'PNGf', extension: 'png' }, { class: 'JPEG', extension: 'jpg' },