- Fixed all Swift test compilation errors and SwiftLint violations - Enhanced test host app with permission status display and CLI availability checking - Refactored ImageCommand.swift to improve readability and reduce function length - Updated all tests to use proper Swift Testing patterns - Added comprehensive local testing framework for screenshot functionality - Updated documentation with proper test execution instructions - Applied SwiftFormat to all Swift files and achieved zero serious linting issues 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
5.3 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
To test this project interactive we can use:
PEEKABOO_AI_PROVIDERS="ollama/llava:latest" npx @modelcontextprotocol/inspector npx -y @steipete/peekaboo-mcp@beta
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 (CI-compatible tests only)
npm run test:swift
# Run Swift tests with local-only tests (requires test host app)
cd peekaboo-cli
RUN_LOCAL_TESTS=true swift test
# Full integration test suite
npm run test:integration
Local Testing with Test Host App
For comprehensive testing including actual screenshot functionality:
-
Open the test host app:
cd peekaboo-cli/TestHost swift run -
The test host app provides:
- Real-time permission status (Screen Recording, Accessibility, CLI availability)
- Interactive permission prompts
- Test pattern windows for screenshot validation
- Log output for debugging
-
Run local-only tests with the test host running:
cd peekaboo-cli RUN_LOCAL_TESTS=true swift test --filter LocalIntegration -
Or use Xcode for better debugging:
- Open
Package.swiftin Xcode - Run the test host app target first
- Run tests with local environment variable:
RUN_LOCAL_TESTS=true
- Open
Note: Local tests require actual system permissions and are designed to work with the test host application for controlled testing scenarios.
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
# Prepare for release (comprehensive checks)
npm run prepare-release
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