# HealthProbe iOS – Specification (MVP)

## Overview
HealthProbe is an iOS application designed to **audit and monitor the integrity of HealthKit data**.  
It detects anomalies such as:
- unexpected historical insertions
- silent deletions of past data
- duplicate records
- divergence trends over time

The application operates as a **local audit agent** and optionally synchronizes **aggregated snapshots (digests)** via CloudKit.

⚠️ This document describes ONLY the iOS application (MVP phase).  
A future macOS application will act as a visualization/analysis layer.

---

## Core Principles

1. **Read-only with respect to HealthKit**
   - Never modify or delete HealthKit data
   - Only observe and audit

2. **Local-first architecture**
   - All detection must work without network access

3. **Incremental observation**
   - Use anchored queries to track changes

4. **Minimal data exfiltration**
   - Only aggregated digests are synced (no raw Health data)

5. **Forward compatibility**
   - CloudKit schema must be shared with a future macOS application

---

## Features (MVP)

### 1. HealthKit Monitoring
Use:
- `HKAnchoredObjectQuery`
- `HKObserverQuery`

Track:
- Workouts (`HKWorkoutType`)
- Heart Rate (`HKQuantityTypeIdentifierHeartRate`)
- High Heart Rate Events
- Other relevant samples (extensible)

---

### 2. Anomaly Detection

#### A. Historical Insertions
Detect samples where:
- `startDate << now`
- AND `firstSeenAt ≈ now`

#### B. Deletions
Detect via:
- `HKDeletedObject`
- Compare with previously stored snapshot

#### C. Duplicate Detection
Fingerprint:
