# XCLoom Agent Setup

Give this page to Claude Code, Codex, Cursor, Gemini CLI, or any coding agent working in an Apple platform repository.

License: Fair Source ([FSL-1.1-ALv2](https://github.com/xcloom/xcloom/blob/main/docs/licensing.md)): free for individuals, internal teams, and commercial app development or CI (converts to Apache-2.0 two years after release); agent skills and manifests are Apache-2.0.

Prompt to paste into your agent:

```text
Read https://xcloom.dev/agent-setup.md and set up XCLoom for this repository:
install the CLI, register the MCP server and agent skill, verify the
environment with `xcloom doctor`, and run a first local build with
`xcloom build --local --json`. Optionally install the git merge drivers and
run `xcloom bench --repo . --json` (isolated cold xcodebuild comparison; can
take several minutes on large repositories).
```

## 1. Install the CLI

macOS (`arm64` Apple Silicon and `x86_64` Intel) or Linux (`x86_64` / `aarch64`). Local native builds, zero-`axe` native simulator automation, `xcloom matrix`, and `xcloom bench` require macOS with Xcode; Linux supports offline inspection and release tooling (`preflight`, `xray`, `car`, `sign`, `symbolicate`, `crash`, `merge`, `verify`, `repro`, `explain`, and `doctor`) plus networked commands (`upload-asc` and `cas serve`).

```sh
curl -fsSL https://xcloom.dev/install.sh | sh
```

Or with Homebrew on macOS (Apple Silicon and Intel `x86_64`):

```sh
brew install xcloom/tap/xcloom
```

Verify the binary is on `PATH`. `xcloom doctor` exits `1` when any critical check fails (such as missing `git`, missing Xcode on macOS, or an invalid `.xcloom.json`) while still emitting full JSON (`ok`, `health_status`, `failures`, `warnings`); pass `--strict` to also fail on warnings:

```sh
xcloom --version
xcloom doctor --json
xcloom doctor --strict --json
```

## 2. One-Shot Setup, MCP Registration, and Agent Skills

`xcloom init --repo .` writes `.xcloom.json` and completes one-shot repository onboarding: it installs `.pbxproj` and `.xcstrings` git merge drivers, registers the XCLoom MCP server for Claude Code plus any detected repo editors (from 7 supported editors: Claude Code, Cursor, Codex, Zed, VS Code, Antigravity, and Windsurf; override with `--mcp-clients <list|all>`), installs the bundled agent skills, and runs `xcloom doctor`. Pass `--skip-merge-drivers`, `--skip-mcp`, `--skip-skill`, or `--skip-doctor` to opt out of individual steps, or `--dry-run` to preview changes:

```sh
xcloom init --repo . --mcp-clients all
```

You can also run `xcloom skill install` and `xcloom mcp install` independently. Both default to repository-local files; pass `--all` on `xcloom mcp install` to register all 7 editors (`--claude`, `--cursor`, `--codex`, `--zed`, `--vscode`, `--antigravity`, `--windsurf`), add `--global` for user-wide configs, pass `--agents` on `skill install` for `.agents/skills/`, or pass `--dry-run` on `mcp install` to preview changes (`mcp install` backs up existing files and preserves all other entries):

```sh
xcloom skill install --claude --codex --cursor --agy
xcloom mcp install --all
```

Or configure manually:

- **Claude Code** (`~/.claude.json` or `.mcp.json`):
  ```json
  {
    "mcpServers": {
      "xcloom": {
        "command": "xcloom",
        "args": ["mcp"]
      }
    }
  }
  ```
- **Codex** (`~/.codex/config.toml`):
  ```toml
  [mcp_servers.xcloom]
  command = "xcloom"
  args = ["mcp"]
  ```
- **Cursor** (`.cursor/mcp.json`):
  ```json
  {
    "mcpServers": {
      "xcloom": {
        "command": "xcloom",
        "args": ["mcp"]
      }
    }
  }
  ```

## 3. Configure CI, Merge Drivers, and Remote Cache

Generate a keyless GitHub Actions OIDC workflow (`.github/workflows/xcloom.yml`) using `deploy/github-actions/xcloom/action.yml`, which also exposes `xray` (`auto|true|false`) and `preflight` (`auto|true|false`) inputs to upload binary size breakdowns and App Store preflight summaries to XCLoom Cloud:

```sh
xcloom init --repo . --github-actions
```

To install semantic merge drivers for `.pbxproj` and `.xcstrings` standalone (already included in default `xcloom init`):

```sh
xcloom merge install-git-driver --repo .
```

Optional: point local builds at your own S3, Cloudflare R2, or shared filesystem L2 compilation cache (zero account or cloud runner required):

```sh
xcloom build --local --remote-cas s3://my-bucket/xcloom-cas
# or Cloudflare R2 (set AWS_ENDPOINT_URL_S3 and standard S3 credentials)
# or shared volume: --remote-cas file:///mnt/shared-cache/xcloom-cas
```

## 4. Verify First Build and Optional Benchmark

Run a local Direct Engine simulator build (no signing or Keychain prompt needed):

```sh
xcloom build --local --json
```

Optional: benchmark stock `xcodebuild` against XCLoom in isolated temporary worktrees (cold empty cache, no-change rebuild, fresh worktree, 1-line Swift edit, and `xcloom hot` live patch when Direct Engine runs; cold `xcodebuild` rounds can take several minutes on large repositories):

```sh
xcloom bench --repo . --json
```

## 5. Run Tests, Simulator Verification, and TestFlight

- **Affected unit tests with automatic flake retries** (XCTest + Swift Testing):
  ```sh
  xcloom test --affected --retry-flakes 2 --json
  ```
- **Boot a slim simulator, install and launch the built `.app`, and assert UI health** using the zero-`axe` native CoreSimulator HID/accessibility stack (read `<UDID>` from `sim boot --json` and `<APP_PATH>` from `build --local --json`):
  ```sh
  xcloom sim boot --json                                                       # slim by default; pass `--for .` for app-aware slimming or `--stock` to disable
  xcloom sim install --udid <UDID> <APP_PATH> --json
  xcloom sim launch --udid <UDID> <BUNDLE_ID> --json
  # Optional (iPhone Duo foldable simulators only; fails on standard slab iPhones):
  # xcloom sim unfold --udid <UDID> --json                                     # 0..180 deg via `sim hinge`, `sim fold`, `sim rotate`
  xcloom sim assert --udid <UDID> --app <BUNDLE_ID> --no-crashes --no-truncation --json
  xcloom sim shutdown <UDID>
  ```
- **Physical device runs (`run --device physical`, `dev --device physical`)**: checks explicit `--p12`/`--cert`+`--key` and cached credentials in `~/.cache/xcloom/provisioning` first, and on local interactive macOS falls back automatically to read-only macOS Keychain development identity and local Xcode provisioning profile discovery signed via `/usr/bin/codesign` (never used in CI, Linux, or untrusted builds).
- **Binary size X-Ray and Cloud upload**:
  ```sh
  xcloom xray <APP_OR_IPA> --json
  xcloom xray <APP_OR_IPA> --upload --build-id <BUILD_ID> --base-branch main --json
  ```
- **Standalone 4-state UI trait/viewport matrix** (leases an isolated slim simulator, builds from `--repo .` or uses a prebuilt `--app`, auto-reads `CFBundleIdentifier` from `Info.plist`, captures `composite.png` + per-cell PNGs + layout findings into `.xcloom/matrix` or `--out <DIR>`, and shuts the simulator down on exit; use `xcloom canvas matrix-act` only when targeting an already booted simulator launched with `xcloom sim launch-instrumented`):
  ```sh
  # Zero-config from source (writes .xcloom/matrix/composite.png):
  xcloom matrix --repo . --json
  # Or sweep a prebuilt simulator .app into a custom directory:
  # xcloom matrix --app <APP_PATH> --out <DIR> --json
  ```
- **Offline App Store preflight and TestFlight dry-run** (read-only; makes zero App Store Connect writes):
  ```sh
  xcloom preflight <APP_OR_IPA> --method app-store --json
  xcloom testflight --local --dry-run --json
  ```
  Only when the user explicitly asks to mutate App Store Connect certificates, profiles, or upload a build to TestFlight: set `ASC_KEY_ID`, `ASC_ISSUER_ID`, and `ASC_PRIVATE_KEY_PATH` (or `~/.appstoreconnect/private_keys/AuthKey_<ID>.p8`), export a Keychain distribution identity once from an interactive terminal via `xcloom sign import-keychain --team-id <TEAM_ID> --include-distribution` (or pass `--p12`/`--profile`), and run `xcloom testflight --local --allow-asc-writes --auto-bump-closed-train --wait --json` (`--auto-bump-closed-train` bumps the patch `CFBundleShortVersionString`, re-signs, and retries once if App Store Connect rejects a closed marketing version train).

## 6. Anonymous Telemetry (Opt-Out, Disabled on First Run and in CI)

XCLoom collects minimal, strictly anonymous CLI and MCP usage telemetry by default on interactive developer machines (`enabled: true`), is **disabled by default in CI** (`CI=true`), and sends **zero** events on your first run while printing a one-line `stderr` notice (suppressed on `--json` and MCP stdio) so you can opt out before any event is transmitted (full spec: [docs/telemetry.md](https://github.com/xcloom/xcloom/blob/main/docs/telemetry.md)).

- **Read-only inspection**: `xcloom telemetry status` checks state and schema without writing `~/.config/xcloom/telemetry.json` or generating an `install_id`.
- **Strict 20-field allowlist**: random local install UUID (`install_id`), subcommand or MCP tool name, build and cache mode (`engine`, `fallback_reason_code`, `slim_mode`, `remote_cas`, `cas_hits`, `cas_misses`), wall duration, exit and structured error code, OS/architecture, Xcode major version, and CI boolean. Raw rows auto-delete after 90 days.
- **Never collected**: source code, file paths, project/scheme/target names, bundle IDs, Git URLs or commit SHAs, environment variable values, certificates/tokens, raw `stderr`, or persisted client IP addresses.
- **Disable anytime**:
  - Run `xcloom telemetry off` (writes `"enabled": false` to `~/.config/xcloom/telemetry.json` with `0600` permissions)
  - Set `DO_NOT_TRACK=1` or `XCLOOM_NO_TELEMETRY=1`
  - Re-enable anytime with `xcloom telemetry on`

## 7. Agent Rules of Thumb

- Pass `--json` to every `xcloom` command when parsing results programmatically.
- Use `xcloom explain <file> --json` (or pipe output to `xcloom explain --stdin --json`) or read structured `diagnostics` in build JSON instead of grepping raw `xcodebuild` output.
- Always shut down simulators you booted (`xcloom sim shutdown <UDID>`) when a verification pass completes on a shared machine.
- Never pass `--allow-asc-writes` unless the user explicitly asked to mutate App Store Connect certificates, profiles, or TestFlight uploads.
- Respect the user's telemetry preference; if the user asks to disable telemetry, run `xcloom telemetry off` or set `DO_NOT_TRACK=1`.
