- Add SwiftLint and SwiftFormat configuration with npm scripts - Refactor Swift code to comply with linting rules: - Fix identifier naming (x/y → xCoordinate/yCoordinate) - Extract long functions into smaller methods - Fix code style violations - Enhance image capture tool: - Add blur detection parameter - Support custom image formats and quality - Add flexible naming patterns for saved files - Add comprehensive integration tests for image tool - Update documentation with new linting commands 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
4 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Common Commands
Building
# Build TypeScript server
npm run build
# Build Swift CLI only
npm run build:swift
# Build everything (Swift CLI + TypeScript)
npm run build:all
# Build universal Swift binary with optimizations
./scripts/build-swift-universal.sh
Testing
# Run all tests
npm test
# Run tests with coverage
npm run test:coverage
# Run tests in watch mode
npm run test:watch
# Run Swift tests
npm run test:swift
# Full integration test suite
npm run test:integration
Development
# Start TypeScript compilation in watch mode
npm run dev
# Run the server directly
npm start
# Clean build artifacts
npm run clean
# Lint Swift code
npm run lint:swift
# Format Swift code
npm run format:swift
Testing the MCP server
# Test with a simple JSON-RPC request
echo '{"jsonrpc": "2.0", "id": 1, "method": "tools/list"}' | node dist/index.js
# Run the MCP server (after building)
peekaboo-mcp
Code Architecture
Project Structure
-
Node.js MCP Server (
src/): TypeScript implementation of the Model Context Protocol serverindex.ts: Main server entry point with MCP initializationtools/: Tool implementations (image.ts,analyze.ts,list.ts)utils/: Utilities for Swift CLI integration, AI providers, and server statustypes/: Shared TypeScript type definitions
-
Swift CLI (
peekaboo-cli/): Native macOS binary for system interactions- Handles all screen capture, window management, and application listing
- Outputs structured JSON when called with
--json-output - Does NOT interact with AI providers directly
Key Design Patterns
-
Tool Handler Pattern: Each MCP tool follows a consistent pattern:
- Validate input with Zod schema
- Construct Swift CLI command
- Execute Swift CLI and capture JSON output
- Parse response and handle errors
- Return MCP-formatted response
-
AI Provider Abstraction: The
analyzetool supports multiple AI providers:- Configured via
PEEKABOO_AI_PROVIDERSenvironment variable - Format:
provider/model,provider/model(e.g.,ollama/llava:latest,openai/gpt-4-vision-preview) - Auto-selection tries providers in order until one is available
- Configured via
-
Error Handling: Standardized error codes from Swift CLI:
PERMISSION_DENIED_SCREEN_RECORDINGPERMISSION_DENIED_ACCESSIBILITYAPP_NOT_FOUNDAMBIGUOUS_APP_IDENTIFIERWINDOW_NOT_FOUNDCAPTURE_FAILEDFILE_IO_ERROR
-
Logging Strategy:
- Uses Pino logger to file (default:
/tmp/peekaboo-mcp.log) - No stdout logging to avoid interfering with MCP protocol
- Debug logs from Swift CLI captured in JSON
debug_logsarray
- Uses Pino logger to file (default:
Important Implementation Details
-
Universal Binary: The Swift CLI is built as a universal binary (arm64 + x86_64) for maximum compatibility
-
Permissions:
- Screen Recording permission required for all capture operations
- Accessibility permission only needed for foreground window focus
-
Image Capture: Always excludes window shadows/frames using
CGWindowImageOption.boundsIgnoreFraming -
Fuzzy App Matching: Swift CLI implements intelligent fuzzy matching for application names
-
Environment Variables:
PEEKABOO_AI_PROVIDERS: Configure AI backends for analysisPEEKABOO_LOG_LEVEL: Control logging verbosity (trace, debug, info, warn, error, fatal)PEEKABOO_DEFAULT_SAVE_PATH: Default location for captured imagesPEEKABOO_CLI_PATH: Override bundled Swift CLI path
Common Development Tasks
- When modifying tool schemas, update both the Zod schema in TypeScript and ensure the Swift CLI output matches
- After Swift CLI changes, rebuild with
npm run build:swiftand test JSON output manually - Use
PEEKABOO_LOG_LEVEL=debugfor detailed debugging during development - Test permissions by running
./peekaboo list server_status --json-output