# store-ready: obtaining the build

Read by `/multi-agent:store-ready` for Step 3. The command file keeps the halt
and never-rules; this file holds the per-mode procedure.

## Mode B: a build you supply

- **iOS `.xcarchive`** → Gate 1 runs on it. To reach Gate 2 the archive must be
  exported, so run `ios_export_ipa` (see Mode A for the signing inputs).
- **iOS `.ipa` only** → **Gate 1 is `SKIPPED (needs .xcarchive)`.** The static audit
  reads archive structure an `.ipa` does not carry. Do not present a two-gate run as
  a full pass; say which gate did not run and why, and offer to re-run with the
  archive.
- **Android `.aab`** → Gate 1 runs in full.
- **Android `.apk` only** → Gate 1 runs the rules that do not need a bundle and
  **lists the rules it could not apply**. An `.apk` cannot answer bundle-level
  questions (per-ABI splits, dynamic features, Play App Signing expectations).

When no path is given, pick the newest artifact and print which one you picked:

```
iOS:     newest .xcarchive under ~/Library/Developer/Xcode/Archives/**
Android: newest .aab under **/build/outputs/bundle/**/*.aab
```

Never validate an artifact whose provenance you did not state. "The newest archive"
is a guess the user must be able to correct.

## Mode A: build from the branch

1. Worktree at `{projectRoot}/.worktrees/{taskId}` on the chosen branch (phase-0-init.md Step 6 convention; the `.worktrees` segment is fixed, not a preference).
   **Never under `$HOME`**, never a direct checkout of the main working tree.
2. Resolve the scheme / module and workspace / project from prefs; ask if ambiguous.
3. Build:
   - **iOS**: `ios_xcodebuild({workspace|project, scheme, action: "archive", configuration: "Release", destination: "generic/platform=iOS"})`.
     Note the destination: the simulator default would produce an archive that
     cannot be exported for distribution.
   - **Android**: `./gradlew bundleRelease` (or the release variant the module
     declares). A debug-signed bundle fails Gate 1 signing rules for the wrong
     reason  -  if no release signing config resolves, halt and say so rather than
     auditing a debug artifact.
4. **iOS export**:
   `ios_export_ipa({archive_path, output_dir, method: "app-store-connect", team_id, provisioning_profiles?, signing_style?})`.
   Leave `allow_provisioning_updates` off unless the user asks: it lets xcodebuild
   create or modify profiles in the developer account, which a validation run has no
   business doing.
5. A failed build or export halts with the parsed errors. The usual iOS causes are a
   missing distribution certificate, a profile that does not match the bundle ID, or
   `signing_style: "manual"` with no `provisioning_profiles` map.
