mirror of
https://github.com/tiennm99/ccs.git
synced 2026-08-21 02:23: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 [
|
return [
|
||||||
`## Image Analysis: ${path.basename(filePath)}`,
|
`[Image Analysis via CLIProxy]`,
|
||||||
|
'',
|
||||||
|
`File: ${path.basename(filePath)} (${sizeKB} KB)`,
|
||||||
|
`Model: ${model}`,
|
||||||
|
'',
|
||||||
|
'---',
|
||||||
'',
|
'',
|
||||||
description,
|
description,
|
||||||
'',
|
'',
|
||||||
'---',
|
'---',
|
||||||
`*Analyzed via CLIProxy (${model})*`,
|
'*Use this description to understand the image content.*',
|
||||||
].join('\n');
|
].join('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Output success response and exit
|
* Output success response and exit
|
||||||
*/
|
*/
|
||||||
function outputSuccess(filePath, description, model) {
|
function outputSuccess(filePath, description, model, fileSize) {
|
||||||
const formattedDescription = formatDescription(filePath, description, model);
|
const formattedDescription = formatDescription(filePath, description, model, fileSize);
|
||||||
|
|
||||||
const output = {
|
const output = {
|
||||||
decision: 'block',
|
decision: 'block',
|
||||||
reason: `Image analyzed: ${path.basename(filePath)}`,
|
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: {
|
hookSpecificOutput: {
|
||||||
hookEventName: 'PreToolUse',
|
hookEventName: 'PreToolUse',
|
||||||
permissionDecision: 'deny',
|
permissionDecision: 'deny',
|
||||||
@@ -378,7 +384,7 @@ async function processHook() {
|
|||||||
const description = await analyzeViaCliProxy(base64Data, mediaType, model, timeoutMs);
|
const description = await analyzeViaCliProxy(base64Data, mediaType, model, timeoutMs);
|
||||||
|
|
||||||
// Output success
|
// Output success
|
||||||
outputSuccess(filePath, description, model);
|
outputSuccess(filePath, description, model, stats.size);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (process.env.CCS_DEBUG) {
|
if (process.env.CCS_DEBUG) {
|
||||||
console.error('[CCS Hook] Error:', err.message);
|
console.error('[CCS Hook] Error:', err.message);
|
||||||
|
|||||||
Reference in New Issue
Block a user