# Cloud sync

**Optional, and off by default.** The app stores everything on the device it runs on.
Cloud sync copies each logged set, each finished session, the watch scores and the
bodyweight log to a database the user owns, so their history survives a lost phone and
Claude can read it directly instead of waiting for a pasted summary.

Only set it up when the user asks for it. It needs a free Supabase account and about
ten minutes. Do not suggest it to someone who just wants to train.

## What the user does

1. Create a free project at supabase.com. Any name, any region.
2. Open the project's **SQL editor**, paste the whole of `assets/schema.sql` from this
   skill, and run it. That creates five tables, all prefixed `ironos_`.
3. In the project's **Settings, API** page, copy the **Project URL** and the
   **publishable key** (the one that is safe to ship in a browser, not the secret one).
4. Open the app, then the menu, then **Cloud sync setup**, and paste both. The sync dot
   on the menu button turns green once the first rows have gone up.

## What Claude does

1. In `build-input.js` set `cloudSync: true`, increase `configVersion`, and rebuild.
   Without the flag the app hides the sync menu and never touches the network.
2. Note the project URL in `iron-os-profile.md` under `## Decisions`, with the date.
   Never write the key into the profile; the user keeps that in the app.

## Reading their data

Once rows are syncing, Claude can read them over Supabase's REST API. The user gives the
URL and the publishable key in the conversation when they want a read; do not store
the key. Each call sends the key as both `apikey` and `Authorization: Bearer` headers.

| What | URL |
|---|---|
| Sets, newest first | `<url>/rest/v1/ironos_set_logs?order=session_date.desc,set_number.asc&limit=200` |
| One exercise's history | `<url>/rest/v1/ironos_set_logs?exercise_id=eq.<id>&order=session_date.desc` |
| Finished sessions with check in scores | `<url>/rest/v1/ironos_sessions?order=session_date.desc&limit=30` |
| Next day watch scores | `<url>/rest/v1/ironos_elbow_log?order=log_date.desc&limit=30` |
| Bodyweight | `<url>/rest/v1/ironos_bodyweight_log?order=log_date.desc&limit=60` |
| Current mode and phase | `<url>/rest/v1/ironos_app_state` |

`ironos_app_state` also carries a coach note channel: a row with key `coach_note` and
value `{"text":"..."}` is shown in the app the next time it opens. Write one when a
verdict is worth seeing at the gym, and keep it to two lines.

> [!warning] Single user by design
> The schema switches on row level security with permissive policies for the
> publishable key, which is fine for one person's training log and nothing else. Never
> point two people's apps at one project, and never put anything but training data in it.
