# CheapRetouch Constitution

**Version**: ralph-wiggum@81231ca4e7466d84e3908841e9ed3d08e8c0803e
**Created**: 2026-01-23

## Project Vision

On-device iOS photo editor for removing unwanted elements using only Apple's public frameworks and classical image processing. No custom ML models.

**Platform**: iOS 17.0+

**Core Capabilities**:
- Person removal (Vision handles this well)
- Foreground object removal (user-initiated, Vision-assisted)
- Wire/line removal (geometric contour detection)

## Core Principles

1. **Privacy-first**: All processing on-device, no network calls for core functionality, no analytics or telemetry
2. **Graceful fallbacks**: Always provide manual alternatives (brush, line brush) when auto-detection fails - the user is never stuck
3. **Performance matters**: Fast previews (<300ms), responsive UI, efficient memory management (1.5GB budget)

## Technical Stack

| Layer | Framework | Purpose |
|-------|-----------|---------|
| UI | SwiftUI + UIKit interop | Canvas, tools, state management |
| Masking | Vision | `VNGenerateForegroundInstanceMaskRequest`, `VNDetectContoursRequest` |
| Subject Interaction | VisionKit | `ImageAnalyzer`, `ImageAnalysis`, `ImageAnalysisInteraction` |
| Inpainting | Metal (custom) | Patch-based synthesis, mask feathering, blending |
| Compositing | Core Image | Color adjustments, preview pipeline |
| Fallback Processing | Accelerate/vImage | Simulator, older devices without Metal |

## Autonomy Settings

- **YOLO Mode**: ENABLED - Make implementation decisions autonomously
- **Git Autonomy**: ENABLED - Commit and push completed work automatically

## Operational Guidelines

### When Implementing Features

1. Read the spec completely before starting
2. Follow the project structure defined in the spec
3. Implement the primary path first, then fallbacks
4. Ensure all edge cases from the spec are handled
5. Write tests as specified (unit, snapshot, UI, performance, memory)

### Code Quality

- Non-destructive editing: original image never modified
- Full undo/redo support via operation stack
- All operations must be Codable for persistence
- Memory management: release intermediate textures aggressively
- Tile-based processing for images > 12MP

### User Experience

- Clear feedback states (processing, no detection, success)
- Contextual inspector panel based on active tool
- Accessibility: VoiceOver labels, Dynamic Type, Reduce Motion support

### What NOT To Do

- Do not add ML models or custom neural networks
- Do not add features explicitly marked as out of scope
- Do not make network calls for core functionality
- Do not over-engineer beyond what the spec requires

## Completion Signal

Output `<promise>DONE</promise>` only when a specification is 100% complete with all acceptance criteria met. Never output this prematurely.
