diff --git a/src/tools/analyze.ts b/src/tools/analyze.ts index 19609ef..34940d7 100644 --- a/src/tools/analyze.ts +++ b/src/tools/analyze.ts @@ -44,7 +44,7 @@ export const analyzeToolSchema = z.object({ { message: "image_path is required", path: ["image_path"], - } + }, ); export type AnalyzeToolInput = z.infer; @@ -57,8 +57,8 @@ export async function analyzeToolHandler( try { // Determine the effective image path (prioritize image_path, fallback to path) - const effectiveImagePath = input.image_path || input.path!; - + const effectiveImagePath = input.image_path || input.path || ""; + logger.debug( { input: { ...input, effectiveImagePath: effectiveImagePath.split("/").pop() } }, "Processing peekaboo.analyze tool call", diff --git a/src/tools/image.ts b/src/tools/image.ts index 18651ae..c63483b 100644 --- a/src/tools/image.ts +++ b/src/tools/image.ts @@ -10,7 +10,6 @@ import { performAutomaticAnalysis } from "../utils/image-analysis.js"; import { buildImageSummary } from "../utils/image-summary.js"; import { buildSwiftCliArgs, resolveImagePath } from "../utils/image-cli-args.js"; import { parseAIProviders } from "../utils/ai-providers.js"; -import * as fs from "fs/promises"; export { imageToolSchema } from "../types/index.js"; @@ -19,7 +18,7 @@ export async function imageToolHandler( context: ToolContext, ): Promise { const { logger } = context; - let tempDirUsed: string | undefined = undefined; + let _tempDirUsed: string | undefined = undefined; let finalSavedFiles: SavedFile[] = []; let analysisAttempted = false; let analysisSucceeded = false; @@ -34,7 +33,7 @@ export async function imageToolHandler( // Resolve the effective path using the centralized logic const { effectivePath, tempDirUsed: tempDir } = await resolveImagePath(input, logger); - tempDirUsed = tempDir; + _tempDirUsed = tempDir; const args = buildSwiftCliArgs(input, effectivePath, swiftFormat, logger); @@ -92,7 +91,7 @@ export async function imageToolHandler( if (input.question) { analysisAttempted = true; const analysisResults: Array<{ label: string; text: string }> = []; - + const configuredProviders = parseAIProviders( process.env.PEEKABOO_AI_PROVIDERS || "", ); @@ -106,7 +105,7 @@ export async function imageToolHandler( try { const imageBase64 = await readImageAsBase64(savedFile.path); logger.debug({ path: savedFile.path }, "Image read successfully for analysis."); - + const analysisResult = await performAutomaticAnalysis( imageBase64, input.question, @@ -139,7 +138,7 @@ export async function imageToolHandler( }); } } - + // Format the analysis results if (analysisResults.length === 1) { analysisText = analysisResults[0].text; diff --git a/src/tools/list.ts b/src/tools/list.ts index 4b8ce22..33fd4d9 100644 --- a/src/tools/list.ts +++ b/src/tools/list.ts @@ -72,7 +72,7 @@ export const listToolSchema = z .refine( (data) => data.item_type !== "server_status" || - (data.app === undefined && + (data.app === undefined && (data.include_window_details === undefined || data.include_window_details.length === 0)), { message: diff --git a/src/types/index.ts b/src/types/index.ts index 549b332..a6ecfdf 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -151,8 +151,8 @@ export const imageToolSchema = z.object({ .describe( "Optional. Focus behavior. 'auto' (default): bring target to front only if not already active. " + "'background': capture without altering window focus. " + - "'foreground': always bring target to front before capture." - ) + "'foreground': always bring target to front before capture.", + ), ), }) .describe( diff --git a/src/utils/peekaboo-cli.ts b/src/utils/peekaboo-cli.ts index 3a88331..fcf1bef 100644 --- a/src/utils/peekaboo-cli.ts +++ b/src/utils/peekaboo-cli.ts @@ -58,22 +58,22 @@ function getInitializedSwiftCliPath(logger: Logger): string { function mapExitCodeToErrorMessage( exitCode: number, stderr: string, - command: 'image' | 'list', + command: "image" | "list", appTarget?: string, -): { message: string, code: string } { +): { message: string; code: string } { const defaultMessage = stderr.trim() - ? `Peekaboo CLI Error: ${stderr.trim()}` - : `Swift CLI execution failed (exit code: ${exitCode})`; - + ? "Peekaboo CLI Error: " + stderr.trim() + : "Swift CLI execution failed (exit code: " + exitCode + ")"; + // Handle exit code 18 specially with command context if (exitCode === 18) { return { - message: `The specified application ('${appTarget || 'unknown'}') is not running or could not be found.`, + message: "The specified application ('" + (appTarget || "unknown") + "') is not running or could not be found.", code: "SWIFT_CLI_APP_NOT_FOUND", }; } - - const errorCodeMap: { [key: number]: { message: string, code: string } } = { + + const errorCodeMap: { [key: number]: { message: string; code: string } } = { 1: { message: "An unknown error occurred in the Swift CLI.", code: "SWIFT_CLI_UNKNOWN_ERROR" }, 7: { message: "The specified application is running but has no capturable windows. Try setting 'capture_focus' to 'foreground' to un-hide application windows.", code: "SWIFT_CLI_NO_WINDOWS_FOUND" }, 10: { message: "No displays available for capture.", code: "SWIFT_CLI_NO_DISPLAYS" }, @@ -153,11 +153,11 @@ export async function executeSwiftCli( ); // Determine command and app target from args - const command = args[0] as 'image' | 'list'; + const command = args[0] as "image" | "list"; let appTarget: string | undefined; - + // Find app target in args - const appIndex = args.indexOf('--app'); + const appIndex = args.indexOf("--app"); if (appIndex !== -1 && appIndex < args.length - 1) { appTarget = args[appIndex + 1]; }