mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-15 22:21:20 +00:00
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
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user