---
phase: 08-screenshot-profiles
plan: 01
subsystem: profiles
tags: [mcp-tools, profiles, persistence, crud]
dependency_graph:
  requires: []
  provides: [ProfileManager, ScreenshotProfile, save_screenshot_profile, list_screenshot_profiles, delete_screenshot_profile]
  affects: [src/server.ts]
tech_stack:
  added: []
  patterns: [singleton-factory, lazy-load, dual-key-json]
key_files:
  created:
    - src/profiles/profile-types.ts
    - src/profiles/profile-manager.ts
    - src/profiles/profile-types.test.ts
    - src/profiles/profile-manager.test.ts
  modified:
    - src/server.ts
decisions:
  - Dual-key JSON file structure (screenshot + timing) for forward compatibility with Phase 9
  - Lazy-load pattern for ProfileManager to avoid unnecessary file reads
  - saveFromSession accepts generic session manager interface for testability
metrics:
  duration: 183s
  completed: "2026-04-13T08:46:00Z"
  tasks: 2
  files_created: 4
  files_modified: 1
  tests_added: 20
  tests_passing: 20
---

# Phase 08 Plan 01: Screenshot Profile Types and CRUD Summary

ProfileManager with CRUD operations, JSON file persistence with dual-key structure, three MCP tools (save/list/delete), and 20 passing TDD tests.

## What Was Done

### Task 1: Profile types and ProfileManager with file persistence (TDD)

Created the profile subsystem foundation:

- `src/profiles/profile-types.ts`: ScreenshotProfile interface, ProfilesFileData interface, slugify() utility with empty-string validation
- `src/profiles/profile-manager.ts`: ProfileManager class with lazy-load, save/get/delete/list, saveFromSession, file persistence with dual-key JSON structure, getProfileManager() singleton factory
- 20 tests covering slugify edge cases, all CRUD operations, file persistence, timing data preservation, directory creation, and saveFromSession behavior

### Task 2: Register three profile MCP tools in server.ts

Added three new MCP tool registrations to `src/server.ts`:

- **save_screenshot_profile**: Validates required fields per target type, supports source_session to copy config from capture sessions
- **list_screenshot_profiles**: Returns all profiles with `test` liveness field (checks if windows still exist via findWindow)
- **delete_screenshot_profile**: Slugifies name, returns available profiles on not-found error

## Decisions Made

1. **Dual-key JSON structure**: `{ screenshot: {...}, timing: {...} }` preserves Phase 9 compatibility without data loss
2. **Lazy-load pattern**: Profiles only loaded from disk on first access, avoiding startup I/O
3. **Generic session manager interface**: saveFromSession accepts `{ get(id: string): { config: CaptureConfig } | undefined }` for easy unit testing without real SessionManager

## Verification Results

1. `npx tsx --test` -- 20/20 tests pass
2. `npx tsup` -- build succeeds with all new modules
3. Grep confirms all three tool registrations present in server.ts
4. Grep confirms timing key preservation in profile-manager.ts

## Deviations from Plan

None - plan executed exactly as written.

## Self-Check: PASSED

All 5 created/modified files exist. Both task commits (4e53f42, 8fe51da) verified in git log.
