# Foundry setup: the brief for the chat that sets up a new rack

You are an AI agent (Claude Code, Codex or Cursor) on the Mac a customer's iPhones plug into. Nobody briefed you.
This file is the whole job: take them from "Foundry is installed" to "the first post went out", one step at a time.
Read any runfoundry.app page with `curl -fsSL` (our host refuses Python's default urllib user agent with 403).
The customer needs a paid Apple Developer Program team (a free Apple ID will not sign the runner for long): each
phone's runner is signed under it, and `foundry lane up` asks for its 10 character team id: ask for it at the start
(developer.apple.com/account, Membership details). Any runfoundry.app/docs page reads as Markdown at its URL plus `.md`.
Posts land at random times from 08:05 to 01:45 (the small hours after the date), this Mac's local time, unless
`foundry plan` gets `--start` and `--end`. Update Foundry by running the install line again.

0. Check Foundry is installed: `~/.local/bin/foundry license status`. If that file is missing, install first with
   the line from their welcome page or dashboard (`curl -fsSL https://runfoundry.app/install.sh | sh -s -- <key>`;
   ask them to paste the key, it starts with `fdy1.`). Every install message and its fix:
   https://runfoundry.app/docs/operations/troubleshooting/#install
1. Get the first run tool and run it:
   `mkdir -p ~/.local/bin && curl -fsSL https://runfoundry.app/foundry_onboard.py -o ~/.local/bin/foundry_onboard.py && /usr/bin/python3 ~/.local/bin/foundry_onboard.py --json`.
   It finds every iPhone this Mac knows and reads each phone's state over the cable. It reads the license key that
   `install.sh` activated from the Mac by itself. A phone this Mac has met before but that is not on the cable now
   comes back at `plug`; if they don't mean to use that phone, leave it. `--phone <UDID>` (or the iPhone's own name from Settings, General, About, but many phones are just "iPhone":
   a name that matches more than one phone stops the run and lists each UDID; not the short name it gets at
   `foundry enroll`, which does not exist yet) limits the run to
   one phone (matched before any other phone is asked anything), and adding `scan` (with or without `--json`) only
   reads: it starts nothing on a phone and never starts the 15 minute map in step 4. If this Mac lists phones that
   are not theirs (a shared Mac), never run it without `--phone`, or first put each of those phones' UDIDs, one a line,
   in `~/.foundry-agent/never-touch`: the tool then never asks those phones anything, and `foundry doctor` skips them.
   With no iPhone on the cable, `phones` is empty and the top level `next` says to plug one in: that is the first step.
2. Each phone in `phones[]` has a `step`:
   - `ready`: nothing to do.
   - otherwise `next.say` (the one thing to do) and `next.path` (where to tap). `then` is the follow-up if the
     first thing does not stick.
   Tell the person **one** step for **one** phone, in those words, and wait until they say it's done. Never paste the
   whole list at them.
   Two steps come from the runner itself: `verify` means iOS has not checked the runner with Apple yet (the phone
   needs Wi-Fi or SIM data for a minute; the rerun finishes the check by itself), and `automation` means the runner
   is trusted but the passcode is on or UI Automation is off.
3. Run it again after every step. The state comes from the phone, so trust the rerun over what the person says.
4. When a phone is `ready` and its model has never been mapped (`mapped: false`), the run maps it by itself (about 15
   minutes, it changes no setting) and uploads the map. Every other Foundry rack with that model then starts from it.
   Tell them that's what is happening so they don't unplug the phone. A phone the rack is using says `busy`; run
   it again later.
5. Once every phone is `ready`, finish from this Mac, one command at a time, and run `foundry doctor` at the end (it reads `ready` when done):
   - `foundry lane enable <phone>` for each phone, once `foundry lane up <phone> --team <team id>` has answered ready
     (the `runner` step runs it; `foundry doctor` shows the lane `ready`). Skip any phone doctor lists as
     `(unenrolled)` that is not theirs: their plan counts only the phones they enroll, and theirs is the one on the
     cable now (its step is past `plug`; other phones this Mac has met read `plug` or `state=unavailable`).
   - Ask for each account's handle (no @), then
     `foundry accounts add --id instagram-<handle> --platform instagram --phone <phone> --handle <handle> --posts 2 --warms 2,3`
     (`tiktok` the same way; `<phone>` is the short name the phone was enrolled under: a phone that is not enrolled yet gets `foundry enroll --udid <udid> --name <short name>` in its `runner` step, and that name is its lane). Accounts live on the Mac; the dashboard Accounts tab only shows them. `accounts add` needs the phone enrolled first, so until the phone reaches this step only the clips and `videos.json` can be got ready.
   - `foundry warm-plan --days 7` and `foundry install-agents`, so the phones warm and post on their own. The
     post-runner it loads wakes every minute and posts only a slot planned for that minute (nothing until a plan is written).
   - Ask whether posts should land in a set window (default: random times 08:05 to 01:45, this Mac's local time);
     if so, add `--start HH:MM --end HH:MM` to the plan line below.
   - Their clips go in one folder with a `videos.json` beside them (runfoundry.app/docs/operations/videos; clip
     paths are relative to `videos.json`). Then `foundry plan --date YYYY-MM-DD --videos videos.json --write`.
     It prints each scheduled post and its time (this Mac's local time); "nothing to schedule" names the account and what it is missing.
     Then it lists anything still needed before those slots post (`foundry install-agents`, `foundry lane up` when no signing profile
     exists yet, a phone to plug back in); do each, then run `foundry doctor`.
     To redo a day already written, add `--force`. The plan keeps the clips' full paths: tell them not to move the
     clips before they post, and to keep the Mac awake, logged in and the phone plugged in at post time.
   - The slot shows on runfoundry.app/account under Queue from the day before it posts, and goes out at that time.

Rules: never change a phone setting yourself, never ask for a password or a 2FA code, and never run a posting script
during setup beyond the commands above. The agents `foundry install-agents` set up post each planned slot by themselves;
to plan another day, follow runfoundry.app/docs/operations/videos. Footage for us to cut goes up on their workspace's
Formats page (runfoundry.app/docs/operations/send-content).
If the run errors with a license message, have them run `foundry license activate <key>` (the key is on their
welcome page).

6. Last, offer support access, once: "If something ever breaks that I can't fix, Foundry support can fix it on this
   Mac and see your phones' screens. It stays off unless you turn it on, and one double-click turns it off. Want it?"
   Only on a yes: show them runfoundry.app/docs/operations/support-access, have them install Tailscale and turn on
   Remote Login themselves, and ask support for their line on runfoundry.app/support. They run that line and type
   `yes` to the consent text themselves; you never answer it for them. On a no, drop it.
