xdev 0.1.1

xdev - iOS/macOS development CLI
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Build Commands

```bash
# Build (debug)
cargo build

# Build (release with optimizations)
cargo build --release

# Check without building (faster feedback)
cargo check

# Auto-fix lints
cargo fix

# Install locally
cargo install --path .
```

## Architecture

xdev is a Rust CLI that wraps Apple's development tools (`xcodebuild`, `simctl`, `devicectl`) into a unified interface.

### Layer Overview

```
CLI (clap)  →  Config  →  Tool Wrappers  →  Output
   ↓             ↓            ↓               ↓
src/cli.rs   config/     xcode/          output/
             mod.rs      simulator/      mod.rs
                         device/
                         ui/
```

### Key Modules

- **src/cli.rs** - clap-based argument parsing with global `--json` and `--config` flags
- **src/config/mod.rs** - Loads/saves `.xdev.json`, merges CLI args with saved config, auto-discovers workspaces
- **src/xcode/mod.rs** - `XcodeBuildCommand` builder pattern for constructing xcodebuild invocations
- **src/xcode/build.rs** - `BuildOutputParser` with regex-based parsing of xcodebuild output
- **src/simulator/mod.rs** - Wraps `xcrun simctl` for simulator management
- **src/device/mod.rs** - Wraps `xcrun devicectl` for physical device management
- **src/ui/mod.rs** - UI automation via `simctl io booted` (tap, swipe, screenshot)
- **src/output/mod.rs** - Dual output modes: Human (colored + spinners) and JSON (NDJSON streaming)

### Data Flow

1. CLI args parsed → merged with `.xdev.json` config (args take precedence)
2. Workspace/scheme auto-detected if not specified
3. Tool commands built using builder pattern
4. Async execution with `tokio::select!` for stdout/stderr streaming
5. Output formatted based on `--json` flag

### Output Modes

All commands support `--json` for NDJSON streaming output. The `OutputFormat` enum and `StreamEvent` in `output/mod.rs` define structured events like `BuildStart`, `BuildProgress`, `BuildComplete`, `TestCase`, etc.

### Error Handling

Uses `anyhow::Result<T>` throughout with `.context()` for error chains. Errors display nicely in human mode and as structured JSON in JSON mode.

## Configuration

Project settings persist in `.xdev.json`:

```json
{
  "workspace": "MyApp.xcworkspace",
  "scheme": "MyApp",
  "configuration": "Debug",
  "simulator": "iPhone 16"
}
```

Config discovery walks up the directory tree looking for `.xcworkspace` or `.xcodeproj` files.

## Command Structure

Commands live in `src/commands/`. Each follows the pattern:
1. Define `Args` struct with clap derives
2. `pub async fn run(args: Args, output_format: OutputFormat) -> Result<()>`
3. Load config, validate, execute tool, format output