From 70caaa00a090fe6a1cfcff3ff47bcb355427ff42 Mon Sep 17 00:00:00 2001 From: kaitranntt Date: Tue, 3 Feb 2026 20:58:05 -0500 Subject: [PATCH] fix(hooks): improve image analysis output format Match websearch transformer format: - Header: [Image Analysis via CLIProxy] - Metadata: File name, size in KB, model used - Separator lines for better readability - Footer instruction for Claude --- lib/hooks/image-analyzer-transformer.cjs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/hooks/image-analyzer-transformer.cjs b/lib/hooks/image-analyzer-transformer.cjs index ab7d831c..daa10782 100755 --- a/lib/hooks/image-analyzer-transformer.cjs +++ b/lib/hooks/image-analyzer-transformer.cjs @@ -209,29 +209,35 @@ function analyzeViaCliProxy(base64Data, mediaType, model, timeoutMs) { } /** - * Format analysis description for Claude + * Format analysis description for Claude (matches websearch format) */ -function formatDescription(filePath, description, model) { +function formatDescription(filePath, description, model, fileSize) { + const sizeKB = fileSize ? (fileSize / 1024).toFixed(1) : '?'; return [ - `## Image Analysis: ${path.basename(filePath)}`, + `[Image Analysis via CLIProxy]`, + '', + `File: ${path.basename(filePath)} (${sizeKB} KB)`, + `Model: ${model}`, + '', + '---', '', description, '', '---', - `*Analyzed via CLIProxy (${model})*`, + '*Use this description to understand the image content.*', ].join('\n'); } /** * Output success response and exit */ -function outputSuccess(filePath, description, model) { - const formattedDescription = formatDescription(filePath, description, model); +function outputSuccess(filePath, description, model, fileSize) { + const formattedDescription = formatDescription(filePath, description, model, fileSize); const output = { decision: 'block', reason: `Image analyzed: ${path.basename(filePath)}`, - systemMessage: `[Image Analysis] ${path.basename(filePath)} analyzed via CLIProxy`, + systemMessage: `[Image Analysis] ${path.basename(filePath)} analyzed via CLIProxy (${model})`, hookSpecificOutput: { hookEventName: 'PreToolUse', permissionDecision: 'deny', @@ -378,7 +384,7 @@ async function processHook() { const description = await analyzeViaCliProxy(base64Data, mediaType, model, timeoutMs); // Output success - outputSuccess(filePath, description, model); + outputSuccess(filePath, description, model, stats.size); } catch (err) { if (process.env.CCS_DEBUG) { console.error('[CCS Hook] Error:', err.message);