iphone-opt-mcp
# iphone-optimizer
**Data-driven iPhone Home Screen optimizer for macOS.** Reads your local synced Screen Time (`Biome`) launch-friction telemetry, designs an optimal Page 1 + Dock + Smart Stacks + folder layout, and applies it **wirelessly without requiring a USB cable** (with automatic Wi-Fi/USB `setIconState` acceleration when available).
Works both as a **standalone CLI** (`iphone-opt`) and as a **standard MCP stdio server** (`iphone-opt-mcp`) compatible with Devin, Claude Code, Claude Desktop, Codex, Cursor, Windsurf, VS Code Copilot, Zed, Cline, and any other MCP harness.
---
## Why This Exists
Most iPhone layout tools either require plugging in a USB cable, only count page-to-page swipes for apps already on your Home Screen, or cannot create widgets/Smart Stacks and hide pages.
`iphone-optimizer` combines two complementary channels and automatically picks the best one available:
```
~/Library/Biome/.../App.InFocus (SEGB v2, synced locally on Mac)
│
▼
[Biome Telemetry Engine] ──► Launch-surface friction (transitionReason),
│ <15s glance scores, 45s co-usage pairs, drift audit
▼
[Optimizer Engine] ────────► Dock (4 core loop), Page 1 apps, semantic folders,
│ Smart Stacks, reserved grid gaps (fixedLocations),
│ App Library exclusions, hidden Original Page 1
▼
[Transport Negotiator] (zero USB cable required)
├── Wi-Fi/USB Lockdown + Mirroring ──► HYBRID
│ 1. Backup + atomic setIconState (<2s apps/Dock/folders/gaps)
│ 2. iPhone Mirroring ONLY for new Smart Stacks & hiding pages
├── iPhone Mirroring only (default) ─► MIRROR (100% wireless)
└── Lockdown only ───────────────────► LOCKDOWN + manual widget checklist
│
▼
[Checkpointed Executor] ───► Persists every step to ~/.iphone-optimizer/runs/
└─ Pauses cleanly on Touch ID / focus switch -> `iphone-opt resume <id>`
```
---
## What Data Is Used (Apple Biome Explained)
### What is Apple Biome?
**Biome** is Apple's on-device behavioral event store introduced in iOS 15 / macOS 12 (`~/Library/Biome/streams/`). When you turn on **Screen Time -> Share Across Devices** on both your iPhone and Mac, iCloud syncs your iPhone's `App.InFocus` focus stream to your Mac at:
```
~/Library/Biome/streams/restricted/App.InFocus/remote/<device-uuid>/
```
These files use Apple's **SEGB v2** binary segment format containing compact protobuf records (typically ~28–30 days of rolling history). `iphone-optimizer` includes a native, zero-external-dependency Python SEGB v2 parser.
### Exact Fields Read (and What Is Never Read)
From each live `App.InFocus` record (`state == 1`), `iphone-optimizer` reads **only 4 fields**:
| Field | Example | Why It Matters |
| :--- | :--- | :--- |
| `bundleID` | `com.google.Gmail` | Identifies which app was opened. |
| `starting` | `true` / `false` | Pairs focus start and end timestamps to compute exact session duration. |
| `absoluteTimestamp` | `815591087.5` | Computes time-of-day patterns, weekday vs. weekend skew, and app-to-app switch intervals. |
| `launchReason` (`transitionReason`) | `com.apple.SpringBoard.transitionReason.appLibrarySearch` | Reveals **how** you launched the app — Home Screen, Widget, App Switcher, Notification, Spotlight, App Library Category, or App Library Search. |
**Privacy guarantees:**
- **100% local on your Mac.** Zero telemetry, analytics, or layout data is sent to any external server.
- **Never reads** Messages, Photos, Contacts, Emails, Notifications content, keystrokes, or screen contents (other than local OCR during active iPhone Mirroring edits).
### How Those Signals Optimize Your Home Screen
1. **Launch-Surface Friction Score:** Instead of treating every app open equally, each launch is weighted by effort:
- Widget (`0.5`) / Home Screen (`1.0`) < App Switcher (`1.5`) < App Library Suggested/Recents (`2.5`) < App Library Category (`3.5`) < Spotlight (`4.0`) < App Library Search (`5.0`).
- Apps you repeatedly swipe to App Library or type into Search to open bubble straight to the Dock and Page 1.
2. **Core Loop Dock Selection (4 slots):** Combines manual opens, high-friction opens, and **co-usage transitions** (app pairs switched within 45 seconds, e.g., `Messages <-> Gmail <-> Slack <-> Chrome`).
3. **Glance / Smart Stack Widget Candidates:** Apps with high open frequency, median session duration `<= 15s`, and `>= 50%` of opens under 15 seconds (e.g., Weather, Clock/Timer, WHOOP, Calendar, Gmail) are prime widget candidates so you can glance without launching.
4. **Intentional-Friction Exclusions:** High-dwell apps (e.g., Reddit, Hinge, Instagram, TikTok, X) stay in the App Library by default so you don't accidentally put distractions on Page 1.
5. **Focus Mode Skew Hints:** Compares normalized weekday vs. weekend launch rates to surface Work Focus vs. Weekend Focus page candidates.
6. **Before/After Drift Audit (`iphone-opt audit`):** Splits your Biome history into baseline vs. recent windows to verify your real-world drop in App Library/Search launches after changing your layout.
---
## Requirements & Setup
### Requirements
- **macOS 15+** (Apple Silicon or Intel) with **Python 3.11+** (or `uv`)
- An iPhone signed into the same Apple Account
- **No USB cable required** (uses macOS iPhone Mirroring by default; optionally accelerates via Wi-Fi Sync / USB `setIconState` if paired)
### 1. Install
With **`uv`** (recommended):
```bash
uv tool install git+https://github.com/bhavey05/iphone-optimizer
```
Or with **`pipx`**:
```bash
pipx install git+https://github.com/bhavey05/iphone-optimizer
```
Or with **optional Wi-Fi/USB Lockdown fast-path** (`pymobiledevice3`):
```bash
uv tool install "iphone-optimizer[lockdown] @ git+https://github.com/bhavey05/iphone-optimizer"
```
### 2. Guided Setup (`iphone-opt setup`)
Run the built-in onboarding checker:
```bash
iphone-opt setup
```
To jump directly to the macOS Privacy & Security toggles:
```bash
iphone-opt setup --open-settings
```
Complete these one-time macOS permissions:
1. **Screen Time -> Share Across Devices:** Enable on both iPhone (*Settings -> Screen Time*) and Mac (*System Settings -> Screen Time*).
2. **Full Disk Access:** Toggle **on** for your terminal (or the app running `iphone-opt`) in *System Settings -> Privacy & Security -> Full Disk Access*, then restart the terminal.
3. **iPhone Mirroring driver (`mirroir-mcp`):**
- Install `mirroir-mcp` (`brew install jfarcand/tap/mirroir-mcp` or `npm install -g mirroir-mcp`).
- Grant **Screen Recording** and **Accessibility** to your terminal.
- Open macOS **iPhone Mirroring**, connect your iPhone, and verify with `mirroir doctor`.
4. *(Optional fast-path)* **Wi-Fi Lockdown (`setIconState`):** If you enable *Finder -> Show this iPhone when on Wi-Fi* (or run `pymobiledevice3 lockdown wifi-connections on` once), `iphone-optimizer` automatically upgrades bulk app/Dock/folder/grid-gap moves to `<2s` atomic writes over Wi-Fi while still using iPhone Mirroring for Smart Stacks and hiding pages.
Verify everything is ready:
```bash
iphone-opt doctor
```
---
## Using Standalone (No AI Harness Needed)
```bash
# 1. Inspect your last 30 days of launch-surface friction & widget candidates
iphone-opt analyze --days 30
# 2. Generate and preview a data-driven layout (with ASCII diagram + savings estimate)
iphone-opt plan --days 30 --exclude-dock com.apple.mobilephone
# 3. Preview exact execution steps (dry-run by default — touches nothing on your phone)
iphone-opt apply --days 30 --exclude-dock com.apple.mobilephone
# 4. Execute live (creates backup + checkpoints every step)
iphone-opt apply --days 30 --exclude-dock com.apple.mobilephone --confirm
# 5. If paused by Mac Touch ID or window focus, resume cleanly from the exact next step
iphone-opt resume <run-id>
# 6. Check backups, restore, or audit real before/after friction drift a week later
iphone-opt backups
iphone-opt restore <backup-id>
iphone-opt audit --recent-days 7
```
---
## Using With Any AI Harness (MCP)
`iphone-opt-mcp` speaks standard **Model Context Protocol (stdio)**, so it works out of the box with any MCP-compatible coding or desktop agent. Generate the exact config for your client with:
```bash
iphone-opt setup --client claude-code # Claude Code CLI
iphone-opt setup --client claude-desktop # Claude Desktop
iphone-opt setup --client codex # OpenAI Codex CLI
iphone-opt setup --client devin # Devin CLI
iphone-opt setup --client cursor # Cursor
iphone-opt setup --client windsurf # Windsurf
iphone-opt setup --client vscode # VS Code Copilot
iphone-opt setup --client generic # Zed, Cline, Goose, or any stdio MCP client
```
### Exposed MCP Tools
| Tool | Description |
| :--- | :--- |
| `doctor` | Checks Biome readability, Wi-Fi/USB Lockdown devices, `mirroir-mcp` health, and auto-selected mode. |
| `analyze_usage` | Returns launch surfaces, top friction apps, `<15s` glance widget candidates, co-usage transitions, and Focus skew. |
| `generate_plan` | Produces a full `OptimizationPlan` with ASCII preview and estimated monthly/daily swipe reduction. |
| `apply_plan` | Runs dry-run by default (`confirm=false`); executes live with backup + checkpoints when `confirm=true`. |
| `resume_run` | Resumes a checkpointed run after Touch ID or window-focus pause without repeating completed steps. |
| `list_backups` | Lists saved pre-apply backups under `~/.iphone-optimizer/backups/`. |
| `restore_backup` | Restores a Lockdown archive or returns the 10-second Edit Pages revert steps. |
| `audit_drift` | Compares recent `N` days against your earlier baseline window in Biome. |
---
## Safety & 10-Second Revert
- **Dry-run by default:** Neither `iphone-opt apply` nor the MCP `apply_plan` tool touches your iPhone unless you explicitly pass `--confirm` / `confirm=true`.
- **Backup before write:** Every run saves a pre-change backup and plan manifest under `~/.iphone-optimizer/backups/<run-id>/`.
- **Preserved Original Page 1:** When hiding pages, your original Page 1 stays intact (unchecked in iOS *Edit Pages*) rather than deleted. To revert manually anytime in ~10 seconds: long-press empty Home Screen space -> tap the page dots -> uncheck Optimized Page 1 and re-check your original Page 1.
- **App Library & Widget Protection (Lockdown mode):** Writes SpringBoard's root-archive dict with an explicit `ignored` list (so App Library apps never spill onto pages) and restores each widget's `uniqueIdentifier` from `userSelectedElementIdentifier` (so configured widgets keep their settings).
---
## Development
```bash
git clone https://github.com/bhavey05/iphone-optimizer.git
cd iphone-optimizer
uv sync --extra dev --extra lockdown
uv run pytest -v
```
TDQS
Scored across 8 tools
Each tool maps to a distinct stage of the workflow (diagnose, analyze, plan, apply, backup, restore, audit, resume), so misselection is unlikely. The only mild overlap is between analyze_usage and audit_drift, since both consume Biome telemetry, though their goals (exploratory analysis vs. before/after delta) are stated clearly enough to separate them.
Seven of eight names follow a clean verb_noun snake_case pattern (analyze_usage, generate_plan, apply_plan, list_backups, restore_backup, audit_drift, resume_run). The lone outlier, 'doctor', is a bare noun and breaks the verb-first convention, but it is a recognizable idiom that doesn't impede comprehension.
Eight tools is squarely in the sweet spot, and every tool corresponds to a real step in the optimize-measure-restore loop rather than being redundant filler. Nothing feels padded or conspicuously missing at the count level.
The surface covers the full loop: health check, telemetry analysis, plan generation, apply with dry-run, backup list/restore, drift auditing, and resuming interrupted runs — a genuinely complete lifecycle. Minor gaps remain: no explicit cancel/abort for an in-flight run, no retrieval or inspection of a previously generated plan, and no deletion/pruning of backups.